From b0dd10f8171945e0c1f3527dd1e9d18b043e01a7 Mon Sep 17 00:00:00 2001 From: admin Date: Fri, 25 Aug 2006 17:25:49 +0000 Subject: Initial Import --- system/application/config/autoload.php | 101 ++ system/application/config/config.php | 244 ++++ system/application/config/database.php | 57 + system/application/config/index.html | 15 + system/application/config/mimes.php | 103 ++ system/application/config/routes.php | 49 + system/application/controllers/index.html | 15 + system/application/controllers/welcome.php | 15 + system/application/errors/error_404.php | 35 + system/application/errors/error_db.php | 34 + system/application/errors/error_general.php | 34 + system/application/errors/error_php.php | 10 + system/application/errors/index.html | 15 + system/application/models/index.html | 15 + system/application/scripts/index.html | 15 + system/application/views/index.html | 15 + system/application/views/welcome_message.php | 62 + system/cache/index.html | 15 + system/codeigniter/Base4.php | 58 + system/codeigniter/Base5.php | 62 + system/codeigniter/CodeIgniter.php | 256 ++++ system/codeigniter/Common.php | 238 ++++ system/codeigniter/index.html | 15 + system/drivers/DB_active_record.php | 875 +++++++++++++ system/drivers/DB_driver.php | 948 ++++++++++++++ system/drivers/DB_mssql.php | 472 +++++++ system/drivers/DB_mysql.php | 495 ++++++++ system/drivers/DB_mysqli.php | 496 ++++++++ system/drivers/DB_odbc.php | 468 +++++++ system/drivers/DB_postgre.php | 476 +++++++ system/drivers/DB_sqlite.php | 501 ++++++++ system/drivers/index.html | 15 + system/fonts/index.html | 15 + system/fonts/texb.ttf | Bin 0 -> 143830 bytes system/helpers/array_helper.php | 47 + system/helpers/cookie_helper.php | 77 ++ system/helpers/date_helper.php | 530 ++++++++ system/helpers/directory_helper.php | 69 + system/helpers/file_helper.php | 139 ++ system/helpers/form_helper.php | 382 ++++++ system/helpers/html_helper.php | 76 ++ system/helpers/index.html | 15 + system/helpers/security_helper.php | 112 ++ system/helpers/string_helper.php | 154 +++ system/helpers/text_helper.php | 386 ++++++ system/helpers/typography_helper.php | 490 ++++++++ system/helpers/url_helper.php | 487 +++++++ system/helpers/xml_helper.php | 55 + system/init/index.html | 15 + system/init/init_calendar.php | 19 + system/init/init_email.php | 24 + system/init/init_encrypt.php | 18 + system/init/init_image_lib.php | 24 + system/init/init_pagination.php | 24 + system/init/init_parser.php | 19 + system/init/init_session.php | 18 + system/init/init_trackback.php | 18 + system/init/init_unit_test.php | 18 + system/init/init_upload.php | 24 + system/init/init_validation.php | 18 + system/init/init_xmlrpc.php | 24 + system/init/init_xmlrpcs.php | 27 + system/language/english/calendar_lang.php | 49 + system/language/english/date_lang.php | 49 + system/language/english/db_lang.php | 15 + system/language/english/email_lang.php | 21 + system/language/english/imglib_lang.php | 21 + system/language/english/index.html | 15 + system/language/english/scaffolding_lang.php | 15 + system/language/english/unit_test_lang.php | 22 + system/language/english/upload_lang.php | 16 + system/language/english/validation_lang.php | 15 + system/language/index.html | 15 + system/libraries/Benchmark.php | 117 ++ system/libraries/Calendar.php | 473 +++++++ system/libraries/Config.php | 181 +++ system/libraries/Controller.php | 445 +++++++ system/libraries/Email.php | 1740 ++++++++++++++++++++++++++ system/libraries/Encrypt.php | 378 ++++++ system/libraries/Exceptions.php | 165 +++ system/libraries/Hooks.php | 237 ++++ system/libraries/Image_lib.php | 1550 +++++++++++++++++++++++ system/libraries/Input.php | 585 +++++++++ system/libraries/Language.php | 113 ++ system/libraries/Loader.php | 611 +++++++++ system/libraries/Log.php | 117 ++ system/libraries/Model.php | 72 ++ system/libraries/Output.php | 241 ++++ system/libraries/Pagination.php | 207 +++ system/libraries/Parser.php | 178 +++ system/libraries/Router.php | 318 +++++ system/libraries/Session.php | 499 ++++++++ system/libraries/Sha1.php | 254 ++++ system/libraries/Trackback.php | 561 +++++++++ system/libraries/URI.php | 243 ++++ system/libraries/Unit_test.php | 331 +++++ system/libraries/Upload.php | 775 ++++++++++++ system/libraries/Validation.php | 692 ++++++++++ system/libraries/Xmlrpc.php | 1409 +++++++++++++++++++++ system/libraries/Xmlrpcs.php | 492 ++++++++ system/libraries/index.html | 15 + system/logs/index.html | 15 + system/plugins/captcha_pi.php | 346 +++++ system/plugins/index.html | 15 + system/plugins/js_calendar_pi.php | 604 +++++++++ system/scaffolding/Scaffolding.php | 285 +++++ system/scaffolding/images/background.jpg | Bin 0 -> 410 bytes system/scaffolding/images/index.html | 15 + system/scaffolding/images/logo.jpg | Bin 0 -> 4518 bytes system/scaffolding/index.html | 15 + system/scaffolding/views/add.php | 30 + system/scaffolding/views/delete.php | 7 + system/scaffolding/views/edit.php | 31 + system/scaffolding/views/footer.php | 10 + system/scaffolding/views/header.php | 31 + system/scaffolding/views/index.html | 15 + system/scaffolding/views/no_data.php | 6 + system/scaffolding/views/stylesheet.css | 143 +++ system/scaffolding/views/view.php | 25 + 119 files changed, 24393 insertions(+) create mode 100644 system/application/config/autoload.php create mode 100644 system/application/config/config.php create mode 100644 system/application/config/database.php create mode 100644 system/application/config/index.html create mode 100644 system/application/config/mimes.php create mode 100644 system/application/config/routes.php create mode 100644 system/application/controllers/index.html create mode 100644 system/application/controllers/welcome.php create mode 100644 system/application/errors/error_404.php create mode 100644 system/application/errors/error_db.php create mode 100644 system/application/errors/error_general.php create mode 100644 system/application/errors/error_php.php create mode 100644 system/application/errors/index.html create mode 100644 system/application/models/index.html create mode 100644 system/application/scripts/index.html create mode 100644 system/application/views/index.html create mode 100644 system/application/views/welcome_message.php create mode 100644 system/cache/index.html create mode 100644 system/codeigniter/Base4.php create mode 100644 system/codeigniter/Base5.php create mode 100644 system/codeigniter/CodeIgniter.php create mode 100644 system/codeigniter/Common.php create mode 100644 system/codeigniter/index.html create mode 100644 system/drivers/DB_active_record.php create mode 100644 system/drivers/DB_driver.php create mode 100644 system/drivers/DB_mssql.php create mode 100644 system/drivers/DB_mysql.php create mode 100644 system/drivers/DB_mysqli.php create mode 100644 system/drivers/DB_odbc.php create mode 100644 system/drivers/DB_postgre.php create mode 100644 system/drivers/DB_sqlite.php create mode 100644 system/drivers/index.html create mode 100644 system/fonts/index.html create mode 100644 system/fonts/texb.ttf create mode 100644 system/helpers/array_helper.php create mode 100644 system/helpers/cookie_helper.php create mode 100644 system/helpers/date_helper.php create mode 100644 system/helpers/directory_helper.php create mode 100644 system/helpers/file_helper.php create mode 100644 system/helpers/form_helper.php create mode 100644 system/helpers/html_helper.php create mode 100644 system/helpers/index.html create mode 100644 system/helpers/security_helper.php create mode 100644 system/helpers/string_helper.php create mode 100644 system/helpers/text_helper.php create mode 100644 system/helpers/typography_helper.php create mode 100644 system/helpers/url_helper.php create mode 100644 system/helpers/xml_helper.php create mode 100644 system/init/index.html create mode 100644 system/init/init_calendar.php create mode 100644 system/init/init_email.php create mode 100644 system/init/init_encrypt.php create mode 100644 system/init/init_image_lib.php create mode 100644 system/init/init_pagination.php create mode 100644 system/init/init_parser.php create mode 100644 system/init/init_session.php create mode 100644 system/init/init_trackback.php create mode 100644 system/init/init_unit_test.php create mode 100644 system/init/init_upload.php create mode 100644 system/init/init_validation.php create mode 100644 system/init/init_xmlrpc.php create mode 100644 system/init/init_xmlrpcs.php create mode 100644 system/language/english/calendar_lang.php create mode 100644 system/language/english/date_lang.php create mode 100644 system/language/english/db_lang.php create mode 100644 system/language/english/email_lang.php create mode 100644 system/language/english/imglib_lang.php create mode 100644 system/language/english/index.html create mode 100644 system/language/english/scaffolding_lang.php create mode 100644 system/language/english/unit_test_lang.php create mode 100644 system/language/english/upload_lang.php create mode 100644 system/language/english/validation_lang.php create mode 100644 system/language/index.html create mode 100644 system/libraries/Benchmark.php create mode 100644 system/libraries/Calendar.php create mode 100644 system/libraries/Config.php create mode 100644 system/libraries/Controller.php create mode 100644 system/libraries/Email.php create mode 100644 system/libraries/Encrypt.php create mode 100644 system/libraries/Exceptions.php create mode 100644 system/libraries/Hooks.php create mode 100644 system/libraries/Image_lib.php create mode 100644 system/libraries/Input.php create mode 100644 system/libraries/Language.php create mode 100644 system/libraries/Loader.php create mode 100644 system/libraries/Log.php create mode 100644 system/libraries/Model.php create mode 100644 system/libraries/Output.php create mode 100644 system/libraries/Pagination.php create mode 100644 system/libraries/Parser.php create mode 100644 system/libraries/Router.php create mode 100644 system/libraries/Session.php create mode 100644 system/libraries/Sha1.php create mode 100644 system/libraries/Trackback.php create mode 100644 system/libraries/URI.php create mode 100644 system/libraries/Unit_test.php create mode 100644 system/libraries/Upload.php create mode 100644 system/libraries/Validation.php create mode 100644 system/libraries/Xmlrpc.php create mode 100644 system/libraries/Xmlrpcs.php create mode 100644 system/libraries/index.html create mode 100644 system/logs/index.html create mode 100644 system/plugins/captcha_pi.php create mode 100644 system/plugins/index.html create mode 100644 system/plugins/js_calendar_pi.php create mode 100644 system/scaffolding/Scaffolding.php create mode 100644 system/scaffolding/images/background.jpg create mode 100644 system/scaffolding/images/index.html create mode 100644 system/scaffolding/images/logo.jpg create mode 100644 system/scaffolding/index.html create mode 100644 system/scaffolding/views/add.php create mode 100644 system/scaffolding/views/delete.php create mode 100644 system/scaffolding/views/edit.php create mode 100644 system/scaffolding/views/footer.php create mode 100644 system/scaffolding/views/header.php create mode 100644 system/scaffolding/views/index.html create mode 100644 system/scaffolding/views/no_data.php create mode 100644 system/scaffolding/views/stylesheet.css create mode 100644 system/scaffolding/views/view.php (limited to 'system') diff --git a/system/application/config/autoload.php b/system/application/config/autoload.php new file mode 100644 index 000000000..a3ce4108e --- /dev/null +++ b/system/application/config/autoload.php @@ -0,0 +1,101 @@ + \ No newline at end of file diff --git a/system/application/config/config.php b/system/application/config/config.php new file mode 100644 index 000000000..0b4f33f41 --- /dev/null +++ b/system/application/config/config.php @@ -0,0 +1,244 @@ + \ No newline at end of file diff --git a/system/application/config/database.php b/system/application/config/database.php new file mode 100644 index 000000000..610f6081d --- /dev/null +++ b/system/application/config/database.php @@ -0,0 +1,57 @@ + \ No newline at end of file diff --git a/system/application/config/index.html b/system/application/config/index.html new file mode 100644 index 000000000..5a1f5d6ae --- /dev/null +++ b/system/application/config/index.html @@ -0,0 +1,15 @@ + + + + +403 Forbidden + + + + + +

Directory access is forbidden.

+ + + + \ No newline at end of file diff --git a/system/application/config/mimes.php b/system/application/config/mimes.php new file mode 100644 index 000000000..06bfcc67b --- /dev/null +++ b/system/application/config/mimes.php @@ -0,0 +1,103 @@ + 'application/mac-binhex40', + 'cpt' => 'application/mac-compactpro', + 'csv' => array('text/x-comma-separated-values', 'application/vnd.ms-excel'), + 'doc' => 'application/msword', + 'bin' => 'application/macbinary', + 'dms' => 'application/octet-stream', + 'lha' => 'application/octet-stream', + 'lzh' => 'application/octet-stream', + 'exe' => 'application/octet-stream', + 'class' => 'application/octet-stream', + 'psd' => 'application/x-photoshop', + 'so' => 'application/octet-stream', + 'sea' => 'application/octet-stream', + 'dll' => 'application/octet-stream', + 'oda' => 'application/oda', + 'pdf' => 'application/pdf', + 'ai' => 'application/postscript', + 'eps' => 'application/postscript', + 'ps' => 'application/postscript', + 'smi' => 'application/smil', + 'smil' => 'application/smil', + 'mif' => 'application/vnd.mif', + 'xls' => array('application/excel', 'application/vnd.ms-excel'), + 'ppt' => 'application/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', + 'php' => 'application/x-httpd-php', + 'php4' => 'application/x-httpd-php', + 'php3' => 'application/x-httpd-php', + 'phtml' => 'application/x-httpd-php', + 'phps' => 'application/x-httpd-php-source', + 'js' => 'application/x-javascript', + 'swf' => 'application/x-shockwave-flash', + 'sit' => 'application/x-stuffit', + 'tar' => 'application/x-tar', + 'tgz' => 'application/x-tar', + 'xhtml' => 'application/xhtml+xml', + 'xht' => 'application/xhtml+xml', + 'zip' => array('application/zip', 'application/x-zip-compressed'), + 'zip' => 'application/zip', + 'mid' => 'audio/midi', + 'midi' => 'audio/midi', + 'mpga' => 'audio/mpeg', + 'mp2' => 'audio/mpeg', + 'mp3' => 'audio/mpeg', + 'aif' => 'audio/x-aiff', + 'aiff' => 'audio/x-aiff', + 'aifc' => 'audio/x-aiff', + 'ram' => 'audio/x-pn-realaudio', + 'rm' => 'audio/x-pn-realaudio', + 'rpm' => 'audio/x-pn-realaudio-plugin', + 'ra' => 'audio/x-realaudio', + 'rv' => 'video/vnd.rn-realvideo', + 'wav' => 'audio/x-wav', + 'bmp' => 'image/bmp', + 'gif' => 'image/gif', + 'jpeg' => 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', + 'word' => 'application/msword', + 'xl' => 'application/excel', + 'eml' => 'message/rfc822' + ); + + +?> \ No newline at end of file diff --git a/system/application/config/routes.php b/system/application/config/routes.php new file mode 100644 index 000000000..622bf88e6 --- /dev/null +++ b/system/application/config/routes.php @@ -0,0 +1,49 @@ + \ No newline at end of file diff --git a/system/application/controllers/index.html b/system/application/controllers/index.html new file mode 100644 index 000000000..5a1f5d6ae --- /dev/null +++ b/system/application/controllers/index.html @@ -0,0 +1,15 @@ + + + + +403 Forbidden + + + + + +

Directory access is forbidden.

+ + + + \ No newline at end of file diff --git a/system/application/controllers/welcome.php b/system/application/controllers/welcome.php new file mode 100644 index 000000000..7f7296d81 --- /dev/null +++ b/system/application/controllers/welcome.php @@ -0,0 +1,15 @@ +load->view('welcome_message'); + } +} +?> \ No newline at end of file diff --git a/system/application/errors/error_404.php b/system/application/errors/error_404.php new file mode 100644 index 000000000..e5fa8f9db --- /dev/null +++ b/system/application/errors/error_404.php @@ -0,0 +1,35 @@ + + + +404 Page Not Found + + + +

+

+ +
+ + \ No newline at end of file diff --git a/system/application/errors/error_db.php b/system/application/errors/error_db.php new file mode 100644 index 000000000..5aab89074 --- /dev/null +++ b/system/application/errors/error_db.php @@ -0,0 +1,34 @@ + + +Database Error + + + +
+

+ +
+ + \ No newline at end of file diff --git a/system/application/errors/error_general.php b/system/application/errors/error_general.php new file mode 100644 index 000000000..213b8353a --- /dev/null +++ b/system/application/errors/error_general.php @@ -0,0 +1,34 @@ + + +Error + + + +
+

+ +
+ + \ No newline at end of file diff --git a/system/application/errors/error_php.php b/system/application/errors/error_php.php new file mode 100644 index 000000000..2fb3f2b2e --- /dev/null +++ b/system/application/errors/error_php.php @@ -0,0 +1,10 @@ +
+ +

A PHP Error was encountered

+ +

Severity:

+

Message:

+

Filename:

+

Line Number:

+ +
diff --git a/system/application/errors/index.html b/system/application/errors/index.html new file mode 100644 index 000000000..5a1f5d6ae --- /dev/null +++ b/system/application/errors/index.html @@ -0,0 +1,15 @@ + + + + +403 Forbidden + + + + + +

Directory access is forbidden.

+ + + + \ No newline at end of file diff --git a/system/application/models/index.html b/system/application/models/index.html new file mode 100644 index 000000000..5a1f5d6ae --- /dev/null +++ b/system/application/models/index.html @@ -0,0 +1,15 @@ + + + + +403 Forbidden + + + + + +

Directory access is forbidden.

+ + + + \ No newline at end of file diff --git a/system/application/scripts/index.html b/system/application/scripts/index.html new file mode 100644 index 000000000..5a1f5d6ae --- /dev/null +++ b/system/application/scripts/index.html @@ -0,0 +1,15 @@ + + + + +403 Forbidden + + + + + +

Directory access is forbidden.

+ + + + \ No newline at end of file diff --git a/system/application/views/index.html b/system/application/views/index.html new file mode 100644 index 000000000..5a1f5d6ae --- /dev/null +++ b/system/application/views/index.html @@ -0,0 +1,15 @@ + + + + +403 Forbidden + + + + + +

Directory access is forbidden.

+ + + + \ No newline at end of file diff --git a/system/application/views/welcome_message.php b/system/application/views/welcome_message.php new file mode 100644 index 000000000..815bef4db --- /dev/null +++ b/system/application/views/welcome_message.php @@ -0,0 +1,62 @@ + + +Welcome to Code Igniter + + + + + +

Welcome to Code Igniter!

+ +

The page you are looking at is being generated dynamically by Code Igniter.

+ +

If you would like to edit this page you'll find it located at:

+system/application/views/welcome_message.php + +

The corresponding controller for this page is found at:

+system/application/controllers/welcome.php + +

If you are exploring Code Igniter for the very first time, you should start by reading the User Guide.

+ + +


Page rendered in {elapsed_time} seconds

+ + + \ No newline at end of file diff --git a/system/cache/index.html b/system/cache/index.html new file mode 100644 index 000000000..5a1f5d6ae --- /dev/null +++ b/system/cache/index.html @@ -0,0 +1,15 @@ + + + + +403 Forbidden + + + + + +

Directory access is forbidden.

+ + + + \ No newline at end of file diff --git a/system/codeigniter/Base4.php b/system/codeigniter/Base4.php new file mode 100644 index 000000000..5d945c26a --- /dev/null +++ b/system/codeigniter/Base4.php @@ -0,0 +1,58 @@ +load =& $this; + $OBJ = $this->load; + } +} + +function &get_instance() +{ + global $OBJ, $CI; + + if (is_object($CI)) + { + return $CI; + } + else + { + return $OBJ->load; + } +} + +?> \ No newline at end of file diff --git a/system/codeigniter/Base5.php b/system/codeigniter/Base5.php new file mode 100644 index 000000000..ef3fc67f4 --- /dev/null +++ b/system/codeigniter/Base5.php @@ -0,0 +1,62 @@ +set_instance($this); + } +} + +class Instance { + public static $instance; + + public function set_instance(&$object) + { + self::$instance =& $object; + } + + public function &get_instance() + { + return self::$instance; + } +} + +function &get_instance() +{ + $instance =& _load_class('Instance'); + return $instance->get_instance(); +} + +?> \ No newline at end of file diff --git a/system/codeigniter/CodeIgniter.php b/system/codeigniter/CodeIgniter.php new file mode 100644 index 000000000..aef7618e9 --- /dev/null +++ b/system/codeigniter/CodeIgniter.php @@ -0,0 +1,256 @@ +mark('code_igniter_start'); + +/* + * ------------------------------------------------------ + * Instantiate the hooks classe + * ------------------------------------------------------ + */ + +$EXT =& _load_class('CI_Hooks'); + +/* + * ------------------------------------------------------ + * Is there a "pre_system" hook? + * ------------------------------------------------------ + */ +if ($EXT->_hook_exists('pre_system')) +{ + $EXT->_call_hook('pre_system'); +} + +/* + * ------------------------------------------------------ + * Instantiate the base classes + * ------------------------------------------------------ + */ + +$CFG =& _load_class('CI_Config'); +$RTR =& _load_class('CI_Router'); +$OUT =& _load_class('CI_Output'); + +/* + * ------------------------------------------------------ + * Is there a valid cache file? If so, we're done... + * ------------------------------------------------------ + */ + +if ($EXT->_hook_exists('cache_override')) +{ + $EXT->_call_hook('cache_override'); +} +else +{ + if ($OUT->_display_cache() == TRUE) + { + exit; + } +} + +/* + * ------------------------------------------------------ + * Does the requested controller exist? + * ------------------------------------------------------ + */ +if ( ! file_exists(APPPATH.'controllers/'.$RTR->fetch_class().EXT)) +{ + show_404(); +} + +/* + * ------------------------------------------------------ + * Load the remaining base classes + * ------------------------------------------------------ + */ + +$IN =& _load_class('CI_Input'); +$URI =& _load_class('CI_URI'); +$LANG =& _load_class('CI_Language'); + +/* + * ------------------------------------------------------ + * Load the app controller and local controller + * ------------------------------------------------------ + * + * Note: Due to the poor object handling in PHP 4 we'll + * contditionally load different versions of the base + * class. Retaining PHP 4 compatibility requires a bit of a hack. + * + * Note: The Loader class needs to be included first + * + */ + + +_load_class('CI_Loader'); + +if (floor(phpversion()) < 5) +{ + require(BASEPATH.'codeigniter/Base4'.EXT); +} +else +{ + require(BASEPATH.'codeigniter/Base5'.EXT); +} + +_load_class('CI_Controller'); + +require(APPPATH.'controllers/'.$RTR->fetch_class().EXT); + +/* + * ------------------------------------------------------ + * Security check + * ------------------------------------------------------ + * + * 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 $method == 'controller' + OR substr($method, 0, 1) == '_' + OR in_array($method, get_class_methods('Controller')) + ) +{ + show_404(); +} + +/* + * ------------------------------------------------------ + * Is there a "pre_controller" hook? + * ------------------------------------------------------ + */ +if ($EXT->_hook_exists('pre_controller')) +{ + $EXT->_call_hook('pre_controller'); +} + +/* + * ------------------------------------------------------ + * Instantiate the controller and call requested method + * ------------------------------------------------------ + */ +$CI = new $class(); + +if ($RTR->scaffolding_request === TRUE) +{ + if ($EXT->_hook_exists('scaffolding_override')) + { + $EXT->_call_hook('scaffolding_override'); + } + else + { + $CI->_ci_scaffolding(); + } +} +else +{ + if ( ! method_exists($CI, $method)) + { + show_404(); + } + + $CI->$method(); +} + +/* + * ------------------------------------------------------ + * Is there a "post_controller" hook? + * ------------------------------------------------------ + */ +if ($EXT->_hook_exists('post_controller')) +{ + $EXT->_call_hook('post_controller'); +} + +/* + * ------------------------------------------------------ + * Send the final rendered output to the browser + * ------------------------------------------------------ + */ + +if ($EXT->_hook_exists('display_override')) +{ + $EXT->_call_hook('display_override'); +} +else +{ + $OUT->_display(); +} + +/* + * ------------------------------------------------------ + * Is there a "post_system" hook? + * ------------------------------------------------------ + */ +if ($EXT->_hook_exists('post_system')) +{ + $EXT->_call_hook('post_system'); +} + +/* + * ------------------------------------------------------ + * Close the DB connection of one exists + * ------------------------------------------------------ + */ +if ($CI->_ci_is_loaded('db')) +{ + $CI->db->close(); +} + + +?> \ No newline at end of file diff --git a/system/codeigniter/Common.php b/system/codeigniter/Common.php new file mode 100644 index 000000000..2ec1c3d38 --- /dev/null +++ b/system/codeigniter/Common.php @@ -0,0 +1,238 @@ +show_error('An Error Was Encountered', $message); + 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. +* +* @access public +* @return void +*/ +function show_404($page = '') +{ + if ( ! class_exists('CI_Exceptions')) + { + include_once(BASEPATH.'libraries/Exceptions.php'); + } + + $error = new CI_Exceptions(); + $error->show_404($page); + exit; +} + + +/** +* 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 +*/ +function log_message($level = 2, $message, $php_error = FALSE) +{ + $config =& _get_config(); + if ($config['log_errors'] === FALSE) + { + return; + } + + if ( ! class_exists('CI_Log')) + { + include_once(BASEPATH.'libraries/Log.php'); + } + + if ( ! isset($LOG)) + { + $LOG = new CI_Log( + $config['log_path'], + $config['log_threshold'], + $config['log_date_format'] + ); + } + + $LOG->write_log($level, $message, $php_error); +} + + +/** +* Exception Handler +* +* This is the custom exception handler we defined at the +* top of this file. The main reason we use this is permit +* PHP errors to be logged in our own log files since we 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 +*/ +function _exception_handler($severity, $message, $filepath, $line) +{ + // We don't bother with "strict" notices since they will fill up + // the log file with information that isn't normally very + // helpful. For example, if you are running PHP 5 and you + // use version 4 style class functions (without prefixes + // like "public", "private", etc.) you'll get notices telling + // you that these have been deprecated. + + if ($severity == E_STRICT) + { + return; + } + + // Send the PHP error to the log file... + if ( ! class_exists('CI_Exceptions')) + { + include_once(BASEPATH.'libraries/Exceptions.php'); + } + $error = new CI_Exceptions(); + + // 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... + $config =& _get_config(); + if ($config['log_errors'] === FALSE) + { + return; + } + + $error->log_exception($severity, $message, $filepath, $line); +} + + +?> \ No newline at end of file diff --git a/system/codeigniter/index.html b/system/codeigniter/index.html new file mode 100644 index 000000000..5a1f5d6ae --- /dev/null +++ b/system/codeigniter/index.html @@ -0,0 +1,15 @@ + + + + +403 Forbidden + + + + + +

Directory access is forbidden.

+ + + + \ No newline at end of file diff --git a/system/drivers/DB_active_record.php b/system/drivers/DB_active_record.php new file mode 100644 index 000000000..373c0f626 --- /dev/null +++ b/system/drivers/DB_active_record.php @@ -0,0 +1,875 @@ +ar_select[] = $val; + } + return $this; + } + + // -------------------------------------------------------------------- + + /** + * DISTINCT + * + * Sets a flag which tells the query string compiler to add DISTINCT + * + * @access public + * @param bool + * @return object + */ + function distinct($val = TRUE) + { + $this->ar_distinct = (is_bool($val)) ? $val : TRUE; + return $this; + } + + // -------------------------------------------------------------------- + + /** + * From + * + * Generates the FROM portion of the query + * + * @access public + * @param mixed can be a string or array + * @return object + */ + function from($from) + { + foreach ((array)$from as $val) + { + $this->ar_from[] = $this->dbprefix.$val; + } + return $this; + } + + // -------------------------------------------------------------------- + + /** + * Join + * + * Generates the JOIN portion of the query + * + * @access public + * @param string + * @param string the join condition + * @param string the type of join + * @return object + */ + 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 .= ' '; + } + } + + $this->ar_join[] = $type.'JOIN '.$table.' ON '.$cond; + return $this; + } + + // -------------------------------------------------------------------- + + /** + * Where + * + * Generates the WHERE portion of the query. Separates + * multiple calls with AND + * + * @access public + * @param mixed + * @param mixed + * @return object + */ + function where($key, $value = NULL) + { + return $this->_where($key, $value, 'AND '); + } + + // -------------------------------------------------------------------- + + /** + * OR Where + * + * Generates the WHERE portion of the query. Separates + * multiple calls with OR + * + * @access public + * @param mixed + * @param mixed + * @return object + */ + function orwhere($key, $value = NULL) + { + return $this->_where($key, $value, 'OR '); + } + + // -------------------------------------------------------------------- + + /** + * Where + * + * Called by where() or orwhere() + * + * @access private + * @param mixed + * @param mixed + * @param string + * @return object + */ + function _where($key, $value = NULL, $type = 'AND ') + { + if ( ! is_array($key)) + { + $key = array($key => $value); + } + + foreach ($key as $k => $v) + { + $prefix = (count($this->ar_where) == 0) ? '' : $type; + + if ( ! is_null($v)) + { + if ( ! $this->_has_operator($k)) + { + $k .= ' ='; + } + + $v = ' '.$this->escape($v); + } + + $this->ar_where[] = $prefix.$k.$v; + } + return $this; + } + + + + // -------------------------------------------------------------------- + + /** + * Like + * + * Generates a %LIKE% portion of the query. Separates + * multiple calls with AND + * + * @access public + * @param mixed + * @param mixed + * @return object + */ + function like($field, $match = '') + { + return $this->_like($field, $match, 'AND '); + } + + // -------------------------------------------------------------------- + + /** + * OR Like + * + * Generates a %LIKE% portion of the query. Separates + * multiple calls with OR + * + * @access public + * @param mixed + * @param mixed + * @return object + */ + function orlike($field, $match = '') + { + return $this->_like($field, $match, 'OR '); + } + + // -------------------------------------------------------------------- + + /** + * Like + * + * Called by like() or olike() + * + * @access private + * @param mixed + * @param mixed + * @param string + * @return object + */ + function _like($field, $match = '', $type = 'AND ') + { + if ( ! is_array($field)) + { + $field = array($field => $match); + } + + foreach ($field as $k => $v) + { + $prefix = (count($this->ar_like) == 0) ? '' : $type; + + $v = $this->escape_str($v); + + $this->ar_like[] = $prefix." $k LIKE '%{$v}%'"; + } + return $this; + } + + // -------------------------------------------------------------------- + + /** + * GROUP BY + * + * @access public + * @param string + * @return object + */ + function groupby($by) + { + if (is_string($by)) + { + $by = explode(',', $by); + } + + foreach ($by as $val) + { + $val = trim($val); + + if ($val != '') + $this->ar_groupby[] = $val; + } + return $this; + } + + // -------------------------------------------------------------------- + + /** + * Sets the HAVING value + * + * Separates multiple calls with AND + * + * @access public + * @param string + * @param string + * @return object + */ + function having($key, $value = '') + { + return $this->_having($key, $value, 'AND '); + } + + // -------------------------------------------------------------------- + + /** + * Sets the OR HAVING value + * + * Separates multiple calls with OR + * + * @access public + * @param string + * @param string + * @return object + */ + function orhaving($key, $value = '') + { + return $this->_having($key, $value, 'OR '); + } + + // -------------------------------------------------------------------- + + /** + * Sets the OR HAVING value + * + * Called by having() or orhaving() + * + * @access private + * @param string + * @param string + * @return object + */ + function _having($key, $value = '', $type = 'AND ') + { + if ( ! is_array($key)) + { + $key = array($key => $value); + } + + foreach ($key as $k => $v) + { + $prefix = (count($this->ar_having) == 0) ? '' : $type; + + if ($v != '') + { + $v = ' '.$this->escape($v); + } + + $this->ar_having[] = $prefix.$k.$v; + } + return $this; + } + + // -------------------------------------------------------------------- + + /** + * Sets the ORDER BY value + * + * @access public + * @param string + * @param string direction: asc or desc + * @return object + */ + function orderby($orderby, $direction = '') + { + if (trim($direction) != '') + { + $direction = (in_array(strtoupper(trim($direction)), array('ASC', 'DESC'))) ? ' '.$direction : ' ASC'; + } + + $this->ar_orderby[] = $orderby.$direction; + return $this; + } + + // -------------------------------------------------------------------- + + /** + * Sets the LIMIT value + * + * @access public + * @param integer the limit value + * @param integer the offset value + * @return object + */ + function limit($value, $offset = '') + { + $this->ar_limit = $value; + + if ($offset != '') + $this->ar_offset = $offset; + + return $this; + } + + // -------------------------------------------------------------------- + + /** + * Sets the OFFSET value + * + * @access public + * @param integer the offset value + * @return object + */ + function offset($value) + { + $this->ar_offset = $value; + return $this; + } + + // -------------------------------------------------------------------- + + /** + * The "set" function. Allows key/value pairs to be set for inserting or updating + * + * @access public + * @param mixed + * @param string + * @return object + */ + function set($key, $value = '') + { + $key = $this->_object_to_array($key); + + if ( ! is_array($key)) + { + $key = array($key => $value); + } + + foreach ($key as $k => $v) + { + $this->ar_set[$k] = $this->escape($v); + } + + return $this; + } + + // -------------------------------------------------------------------- + + /** + * Get + * + * Compiles the select statement based on the other functions called + * and runs the query + * + * @access public + * @param string the limit clause + * @param string the offset clause + * @return object + */ + function get($table = '', $limit = null, $offset = null) + { + if ($table != '') + { + $this->from($table); + } + + if ( ! is_null($limit)) + { + $this->limit($limit, $offset); + } + + $sql = $this->_compile_select(); + + $this->_reset_select(); + return $this->query($sql); + } + + // -------------------------------------------------------------------- + + /** + * GetWhere + * + * Allows the where clause, limit and offset to be added directly + * + * @access public + * @param string the where clause + * @param string the limit clause + * @param string the offset clause + * @return object + */ + function getwhere($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(); + + $this->_reset_select(); + return $this->query($sql); + } + + // -------------------------------------------------------------------- + + /** + * Insert + * + * Compiles an insert string and runs the query + * + * @access public + * @param string the table to retrieve the results from + * @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->dbprefix.$table, 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 + * + * @access public + * @param string the table to retrieve the results from + * @param array an associative array of update values + * @param mixed the where clause + * @return object + */ + function update($table = '', $set = NULL, $where = 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]; + } + + if ($where != null) + { + $this->where($where); + } + + $sql = $this->_update($this->dbprefix.$table, $this->ar_set, $this->ar_where); + + $this->_reset_write(); + return $this->query($sql); + } + + // -------------------------------------------------------------------- + + /** + * Delete + * + * Compiles a delete string and runs the query + * + * @access public + * @param string the table to retrieve the results from + * @param mixed the where clause + * @return object + */ + function delete($table = '', $where = '') + { + 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 != '') + { + $this->where($where); + } + + if (count($this->ar_where) == 0) + { + if ($this->debug) + { + return $this->display_error('db_del_must_use_where'); + } + return FALSE; + } + + $sql = $this->_delete($this->dbprefix.$table, $this->ar_where); + + $this->_reset_write(); + return $this->query($sql); + } + + // -------------------------------------------------------------------- + + /** + * Use Table - DEPRECATED + * + * @deprecated use $this->db->from instead + */ + function use_table($table) + { + return $this->from($table); + return $this; + } + + // -------------------------------------------------------------------- + + /** + * ORDER BY - DEPRECATED + * + * @deprecated use $this->db->orderby() instead + */ + function order_by($orderby, $direction = '') + { + return $this->orderby($orderby, $direction); + } + + // -------------------------------------------------------------------- + + /** + * 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; + } + + // -------------------------------------------------------------------- + + /** + * Compile the SELECT statement + * + * Generates a query string based on which functions were used. + * Should not be called directly. The get() function calls it. + * + * @access private + * @return string + */ + function _compile_select() + { + $sql = ( ! $this->ar_distinct) ? 'SELECT ' : 'SELECT DISTINCT '; + + $sql .= (count($this->ar_select) == 0) ? '*' : implode(', ', $this->ar_select); + + if (count($this->ar_from) > 0) + { + $sql .= "\nFROM "; + $sql .= implode(', ', $this->ar_from); + } + + if (count($this->ar_join) > 0) + { + $sql .= "\n"; + $sql .= implode("\n", $this->ar_join); + } + + if (count($this->ar_where) > 0 OR count($this->ar_like) > 0) + { + $sql .= "\nWHERE "; + } + + $sql .= implode("\n", $this->ar_where); + + if (count($this->ar_like) > 0) + { + if (count($this->ar_where) > 0) + { + $sql .= " AND "; + } + + $sql .= implode("\n", $this->ar_like); + } + + if (count($this->ar_groupby) > 0) + { + $sql .= "\nGROUP BY "; + $sql .= implode(', ', $this->ar_groupby); + } + + if (count($this->ar_having) > 0) + { + $sql .= "\nHAVING "; + $sql .= implode("\n", $this->ar_having); + } + + 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'; + } + } + + if (ctype_digit($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 convers the class variables to array key/vals + * + * @access public + * @param object + * @return array + */ + function _object_to_array($object) + { + if ( ! is_object($object)) + { + return $object; + } + + $array = array(); + foreach (get_object_vars($object) as $key => $val) + { + if ( ! is_object($val) AND ! is_array($val)) + { + $array[$key] = $val; + } + } + + return $array; + } + + // -------------------------------------------------------------------- + + /** + * Resets the active record values. Called by the get() function + * + * @access private + * @return void + */ + function _reset_select() + { + $this->ar_select = array(); + $this->ar_distinct = FALSE; + $this->ar_from = array(); + $this->ar_join = array(); + $this->ar_where = array(); + $this->ar_like = array(); + $this->ar_groupby = array(); + $this->ar_having = array(); + $this->ar_limit = FALSE; + $this->ar_offset = FALSE; + $this->ar_order = FALSE; + $this->ar_orderby = array(); + } + + // -------------------------------------------------------------------- + + /** + * Resets the active record "write" values. + * + * Called by the insert() or update() functions + * + * @access private + * @return void + */ + function _reset_write() + { + $this->ar_set = array(); + $this->ar_from = array(); + $this->ar_where = array(); + } + +} + +?> \ No newline at end of file diff --git a/system/drivers/DB_driver.php b/system/drivers/DB_driver.php new file mode 100644 index 000000000..ed18d54e5 --- /dev/null +++ b/system/drivers/DB_driver.php @@ -0,0 +1,948 @@ +initialize($params); + log_message('debug', 'Database Driver Class Initialized'); + } + + // -------------------------------------------------------------------- + + /** + * Initialize Database Settings + * + * @access private Called by the constructor + * @param mixed + * @return void + */ + function initialize($params = '') + { + if (is_array($params)) + { + foreach (array('hostname' => '', 'username' => '', 'password' => '', 'database' => '', 'dbdriver' => 'mysql', 'dbprefix' => '', 'pconnect' => FALSE, 'db_debug' => FALSE) as $key => $val) + { + $this->$key = ( ! isset($params[$key])) ? $val : $params[$key]; + } + } + elseif (strpos($params, '://')) + { + if (FALSE === ($dsn = @parse_url($params))) + { + log_message('error', 'Invalid DB Connection String'); + + if ($this->debug) + { + return $this->display_error('db_invalid_connection_str'); + } + return FALSE; + } + + $this->hostname = ( ! isset($dsn['host'])) ? '' : rawurldecode($dsn['host']); + $this->username = ( ! isset($dsn['user'])) ? '' : rawurldecode($dsn['user']); + $this->password = ( ! isset($dsn['pass'])) ? '' : rawurldecode($dsn['pass']); + $this->database = ( ! isset($dsn['path'])) ? '' : rawurldecode(substr($dsn['path'], 1)); + } + + if ($this->pconnect == FALSE) + { + $this->conn_id = $this->db_connect(); + } + else + { + $this->conn_id = $this->db_pconnect(); + } + + if ( ! $this->conn_id) + { + log_message('error', 'Unable to connect to the database'); + + if ($this->db_debug) + { + $this->display_error('db_unable_to_connect'); + } + } + else + { + 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); + } + } + } + } + + // -------------------------------------------------------------------- + + /** + * 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; + } + + $query = $this->query($sql); + $row = $query->row(); + return $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) + { + if ( ! $this->conn_id) + { + $this->initialize(); + } + + if ($sql == '') + { + if ($this->db_debug) + { + log_message('error', 'Invalid query: '.$sql); + return $this->display_error('db_invalid_query'); + } + return FALSE; + } + + // Compile binds if needed + if ($binds !== FALSE) + { + $sql = $this->compile_binds($sql, $binds); + } + + // Start the Query Timer + $time_start = list($sm, $ss) = explode(' ', microtime()); + + // Save the query for debugging + $this->queries[] = $sql; + + // Run the Query + if (FALSE === ($this->result_id = $this->execute($sql, $this->conn_id))) + { + if ($this->db_debug) + { + log_message('error', 'Query error: '.$this->error_message()); + return $this->display_error( + array( + 'Error Number: '.$this->error_number(), + $this->error_message(), + $sql + ) + ); + } + + return FALSE; + } + + // Stop and aggregate the query time results + $time_end = list($em, $es) = explode(' ', microtime()); + $this->benchmark += ($em + $es) - ($sm + $ss); + + // Increment the query counter + $this->query_count++; + + // Was the query a "write" type? + // If so we'll return simply return true + if ($this->is_write_type($sql) === TRUE) + { + return TRUE; + } + + // Instantiate and return the DB result object + $result = 'CI_DB_'.$this->dbdriver.'_result'; + + $RES = new $result(); + $RES->conn_id = $this->conn_id; + $RES->db_debug = $this->db_debug; + $RES->result_id = $this->result_id; + + return $RES; + } + + // -------------------------------------------------------------------- + + /** + * 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->debug) + { + return $this->display_error('db_unsupported_function'); + } + return FALSE; + } + else + { + $args = (func_num_args() > 1) ? array_shift(func_get_args()) : null; + + return call_user_func_array($function, $args); + } + } + + // -------------------------------------------------------------------- + + /** + * 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*"?(INSERT|UPDATE|DELETE|REPLACE|CREATE|DROP|LOAD DATA|COPY|ALTER|GRANT|REVOKE|LOCK|UNLOCK)\s+/i', $sql)) + { + return FALSE; + } + return TRUE; + } + + // -------------------------------------------------------------------- + + /** + * Calculate the aggregate query elapsed time + * + * @access public + * @param intiger 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 integer + */ + function escape($str) + { + if ( ! ctype_digit($str)) // bug fix to ensure that numbers are not treated as strings. + { + switch (gettype($str)) + { + case 'string' : $str = "'".$this->escape_str($str)."'"; + break; + case 'boolean' : $str = ($str === FALSE) ? 0 : 1; + break; + default : $str = ($str === NULL) ? 'NULL' : $str; + break; + } + } + + return $str; + } + + // -------------------------------------------------------------------- + + /** + * Returns an array of table names + * + * @access public + * @return array + */ + function tables() + { + if (FALSE === ($sql = $this->_show_tables())) + { + 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) + { + $retval[] = array_shift($row); + } + } + + return $retval; + } + + // -------------------------------------------------------------------- + + /** + * Determine if a particular table exists + * @access public + * @return boolean + */ + function table_exists($table_name) + { + return ( ! in_array($this->dbprefix.$table_name, $this->tables())) ? FALSE : TRUE; + } + + // -------------------------------------------------------------------- + + /** + * Fetch MySQL Field Names + * + * @access public + * @param string the table name + * @return array + */ + function field_names($table = '') + { + if ($table == '') + { + if ($this->debug) + { + return $this->display_error('db_field_param_missing'); + } + return FALSE; + } + + if (FALSE === ($sql = $this->_show_columns($this->dbprefix.$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 ($this->dbdriver == 'mssql' AND isset($row['COLUMN_NAME'])) + { + $retval[] = $row['COLUMN_NAME']; + } + else + { + $retval[] = current($row); + } + } + + return $retval; + } + + // -------------------------------------------------------------------- + + /** + * Returns an object with field data + * + * @access public + * @param string the table name + * @return object + */ + function field_data($table = '') + { + if ($table == '') + { + if ($this->debug) + { + return $this->display_error('db_field_param_missing'); + } + return FALSE; + } + + return $this->_field_data($this->dbprefix.$table); + } + + // -------------------------------------------------------------------- + + /** + * 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->field_names($table); + + if ( ! is_array($fields)) + { + return FALSE; + } + + return current($fields); + } + + // -------------------------------------------------------------------- + + /** + * Compile Bindings + * + * @access public + * @param string the sql statement + * @param array an array of bind data + * @return string + */ + function compile_binds($sql, $binds) + { + if (FALSE === strpos($sql, $this->bind_marker)) + { + return $sql; + } + + if ( ! is_array($binds)) + { + $binds = array($binds); + } + + foreach ($binds as $val) + { + $val = $this->escape($val); + + // Just in case the replacement string contains the bind + // character we'll temporarily replace it with a marker + $val = str_replace($this->bind_marker, '{%bind_marker%}', $val); + $sql = preg_replace("#".preg_quote($this->bind_marker)."#", $val, $sql, 1); + } + + return str_replace('{%bind_marker%}', $this->bind_marker, $sql); + } + + // -------------------------------------------------------------------- + + /** + * 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[] = $key; + $values[] = $this->escape($val); + } + + return $this->_insert($this->dbprefix.$table, $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[$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->dbprefix.$table, $fields, $dest); + } + + // -------------------------------------------------------------------- + + /** + * Close DB Connection + * + * @access public + * @return void + */ + function close() + { + if (is_resource($this->conn_id)) + { + $this->destroy($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/errror_db.php template + */ + function display_error($error = '', $swap = '', $native = FALSE) + { + $LANG = new CI_Language(); + $LANG->load('db'); + + $heading = 'MySQL Error'; + + if ($native == TRUE) + { + $message = $error; + } + else + { + $message = ( ! is_array($error)) ? array(str_replace('%s', $swap, $LANG->line($error))) : $error; + } + + if ( ! class_exists('CI_Exceptions')) + { + include_once(BASEPATH.'libraries/Exceptions.php'); + } + + $error = new CI_Exceptions(); + echo $error->show_error('An Error Was Encountered', $message, 'error_db'); + exit; + + } + + // -------------------------------------------------------------------- + + /** + * Field Data - old version - DEPRECATED + * + * @deprecated use $this->db->field_data() instead + */ + function fields($table = '') + { + return $this->field_data($table); + } + + // -------------------------------------------------------------------- + + /** + * Smart Escape String - old version - DEPRECATED + * + * @deprecated use $this->db->escape() instead + */ + function smart_escape_str($str) + { + return $this->escape($str); + } +} + + +/** + * Database Result Class + * + * This is the platform-independent result class. + * This class will not be called directly. Rather, the adapter + * class for the specific database will extend and instantiate it. + * + * @category Database + * @author Rick Ellis + * @link http://www.codeigniter.com/user_guide/libraries/database/ + */ +class CI_DB_result { + + var $conn_id = FALSE; + var $result_id = FALSE; + var $db_debug = FALSE; + var $result_array = array(); + var $result_object = array(); + var $current_row = 0; + + /** + * Query result. Acts as a wrapper function for the following functions. + * + * @access public + * @param string can be "object" or "array" + * @return mixed either a result object or array + */ + function result($type = 'object') + { + return ($type == 'object') ? $this->result_object() : $this->result_array(); + } + + // -------------------------------------------------------------------- + + /** + * Query result. "object" version. + * + * @access public + * @return object + */ + function result_object() + { + if (count($this->result_object) > 0) + { + return $this->result_object; + } + + while ($row = $this->_fetch_object()) + { + $this->result_object[] = $row; + } + + if (count($this->result_object) == 0) + { + return FALSE; + } + + return $this->result_object; + } + + // -------------------------------------------------------------------- + + /** + * Query result. "array" version. + * + * @access public + * @return array + */ + function result_array() + { + if (count($this->result_array) > 0) + { + return $this->result_array; + } + + while ($row = $this->_fetch_assoc()) + { + $this->result_array[] = $row; + } + + if (count($this->result_array) == 0) + { + return FALSE; + } + + return $this->result_array; + } + + // -------------------------------------------------------------------- + + /** + * Query result. Acts as a wrapper function for the following functions. + * + * @access public + * @param string can be "object" or "array" + * @return mixed either a result object or array + */ + function row($n = 0, $type = 'object') + { + return ($type == 'object') ? $this->row_object($n) : $this->row_array($n); + } + + // -------------------------------------------------------------------- + + /** + * Returns a single result row - object version + * + * @access public + * @return object + */ + function row_object($n = 0) + { + if (FALSE === ($result = $this->result_object())) + { + return FALSE; + } + + 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 + */ + function row_array($n = 0) + { + if (FALSE === ($result = $this->result_array())) + { + return FALSE; + } + + if ($n != $this->current_row AND isset($result[$n])) + { + $this->current_row = $n; + } + + return $result[$this->current_row]; + } + + // -------------------------------------------------------------------- + + /** + * Returns the "next" row + * + * @access public + * @return object + */ + function next_row($type = 'object') + { + if (FALSE === ($result = $this->result($type))) + { + return FALSE; + } + + if (isset($result[$this->current_row + 1])) + { + ++$this->current_row; + } + + return $result[$this->current_row]; + } + + // -------------------------------------------------------------------- + + /** + * Returns the "previous" row + * + * @access public + * @return object + */ + function previous_row($type = 'object') + { + if (FALSE === ($result = $this->result($type))) + { + return FALSE; + } + + if (isset($result[$this->current_row - 1])) + { + --$this->current_row; + } + return $result[$this->current_row]; + } + + // -------------------------------------------------------------------- + + /** + * Returns the "first" row + * + * @access public + * @return object + */ + function first_row($type = 'object') + { + if (FALSE === ($result = $this->result($type))) + { + return FALSE; + } + return $result[0]; + } + + // -------------------------------------------------------------------- + + /** + * Returns the "last" row + * + * @access public + * @return object + */ + function last_row($type = 'object') + { + if (FALSE === ($result = $this->result($type))) + { + return FALSE; + } + return $result[count($result) -1]; + } + +} + + + +/** + * Database Field Class + * + * This class will contain the field meta-data. It + * is called by one of the field result functions + * + * @category Database + * @author Rick Ellis + * @link http://www.codeigniter.com/user_guide/libraries/database/ + */ +class CI_DB_field { + var $name; + var $type; + var $default; + var $max_length; + var $primary_key; +} + +?> \ No newline at end of file diff --git a/system/drivers/DB_mssql.php b/system/drivers/DB_mssql.php new file mode 100644 index 000000000..6156ec3c9 --- /dev/null +++ b/system/drivers/DB_mssql.php @@ -0,0 +1,472 @@ +hostname, $this->username, $this->password); + } + + // -------------------------------------------------------------------- + + /** + * Persistent database connection + * + * @access private called by the base class + * @return resource + */ + function db_pconnect() + { + return mssql_pconnect($this->hostname, $this->username, $this->password); + } + + // -------------------------------------------------------------------- + + /** + * Select the database + * + * @access private called by the base class + * @return resource + */ + function db_select() + { + return @mssql_select_db($this->database, $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 @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; + } + + // -------------------------------------------------------------------- + + /** + * Escape String + * + * @access public + * @param string + * @return string + */ + function escape_str($str) + { + // MS SQL doesn't require escaping + return $str; + } + + // -------------------------------------------------------------------- + + /** + * Close DB Connection + * + * @access public + * @param resource + * @return void + */ + function destroy($conn_id) + { + mssql_close($conn_id); + } + + // -------------------------------------------------------------------- + + /** + * Affected Rows + * + * @access public + * @return integer + */ + function affected_rows() + { + return @mssql_rows_affected($this->conn_id); + } + + // -------------------------------------------------------------------- + + /** + * Insert ID + * + * @access public + * @return integer + */ + function insert_id() + { + // Not supported in MS SQL? + return 0; + } + + // -------------------------------------------------------------------- + + /** + * "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("SELECT COUNT(*) AS numrows FROM `".$this->dbprefix.$table."`"); + + if ($query->num_rows() == 0) + return '0'; + + $row = $query->row(); + return $row->numrows; + } + + // -------------------------------------------------------------------- + + /** + * The error message string + * + * @access public + * @return string + */ + function error_message() + { + // Are errros even supported in MS SQL? + return ''; + } + + // -------------------------------------------------------------------- + + /** + * The error message number + * + * @access public + * @return integer + */ + function error_number() + { + // Are error numbers supported? + return ''; + } + + // -------------------------------------------------------------------- + + /** + * 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 public + * @param string the table name + * @return string + */ + function escape_table($table) + { + if (stristr($table, '.')) + { + $table = preg_replace("/\./", "`.`", $table); + } + + return $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) + { + $sql = "SELECT TOP 1 FROM ".$this->escape_table($table); + $query = $this->query($sql); + return $query->field_data(); + } + + // -------------------------------------------------------------------- + + /** + * 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 + * @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); + } + + // -------------------------------------------------------------------- + + /** + * Delete statement + * + * Generates a platform-specific delete string from the supplied data + * + * @access public + * @param string the table name + * @param array the where clause + * @return string + */ + function _delete($table, $where) + { + return "DELETE FROM ".$this->escape_table($table)." WHERE ".implode(" ", $where); + } + + // -------------------------------------------------------------------- + + /** + * Version number query string + * + * @access public + * @return string + */ + function _version() + { + return "SELECT version() AS ver"; + } + + // -------------------------------------------------------------------- + + /** + * Show table query + * + * Generates a platform-specific query string so that the table names can be fetched + * + * @access public + * @return string + */ + function _show_tables() + { + return "SELECT name FROM sysobjects WHERE type = 'U' ORDER BY name"; + } + + // -------------------------------------------------------------------- + + /** + * Show columnn 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 _show_columns($table = '') + { + return "SELECT * FROM INFORMATION_SCHEMA.Columns WHERE TABLE_NAME = '".$this->escape_table($table)."'"; + } + + // -------------------------------------------------------------------- + + /** + * 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); + } + +} + + + +/** + * MS SQL Result Class + * + * This class extends the parent result class: CI_DB_result + * + * @category Database + * @author Rick Ellis + * @link http://www.codeigniter.com/user_guide/libraries/database/ + */ +class CI_DB_mssql_result extends CI_DB_result { + + /** + * Number of rows in the result set + * + * @access public + * @return integer + */ + function num_rows() + { + return @mssql_num_rows($this->result_id); + } + + // -------------------------------------------------------------------- + + /** + * Number of fields in the result set + * + * @access public + * @return integer + */ + function num_fields() + { + return @mssql_num_fields($this->result_id); + } + + // -------------------------------------------------------------------- + + /** + * 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 CI_DB_field(); + $F->name = $field->name; + $F->type = $field->type; + $F->max_length = $field->max_length; + $F->primary_key = 0; + $F->default = ''; + + $retval[] = $F; + } + + return $retval; + } + + // -------------------------------------------------------------------- + + /** + * 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); + } + +} + +?> \ No newline at end of file diff --git a/system/drivers/DB_mysql.php b/system/drivers/DB_mysql.php new file mode 100644 index 000000000..18c080b21 --- /dev/null +++ b/system/drivers/DB_mysql.php @@ -0,0 +1,495 @@ +hostname, $this->username, $this->password, TRUE); + } + + // -------------------------------------------------------------------- + + /** + * Persistent database connection + * + * @access private called by the base class + * @return resource + */ + function db_pconnect() + { + return mysql_pconnect($this->hostname, $this->username, $this->password); + } + + // -------------------------------------------------------------------- + + /** + * Select the database + * + * @access private called by the base class + * @return resource + */ + function db_select() + { + return @mysql_select_db($this->database, $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 @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; + } + + // -------------------------------------------------------------------- + + /** + * Escape String + * + * @access public + * @param string + * @return string + */ + function escape_str($str) + { + if (get_magic_quotes_gpc()) + { + $str = stripslashes($str); + } + return mysql_real_escape_string($str); + } + + // -------------------------------------------------------------------- + + /** + * Close DB Connection + * + * @access public + * @param resource + * @return void + */ + function destroy($conn_id) + { + mysql_close($conn_id); + } + + // -------------------------------------------------------------------- + + /** + * 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("SELECT COUNT(*) AS numrows FROM `".$this->dbprefix.$table."`"); + + if ($query->num_rows() == 0) + return '0'; + + $row = $query->row(); + return $row->numrows; + } + + // -------------------------------------------------------------------- + + /** + * The error message string + * + * @access public + * @return string + */ + function error_message() + { + return mysql_error($this->conn_id); + } + + // -------------------------------------------------------------------- + + /** + * The error message number + * + * @access public + * @return integer + */ + function error_number() + { + return mysql_errno($this->conn_id); + } + + // -------------------------------------------------------------------- + + /** + * 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 public + * @param string the table name + * @return string + */ + function escape_table($table) + { + if (stristr($table, '.')) + { + $table = preg_replace("/\./", "`.`", $table); + } + + return $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) + { + $sql = "SELECT * FROM ".$this->escape_table($table)." LIMIT 1"; + $query = $this->query($sql); + return $query->field_data(); + } + + // -------------------------------------------------------------------- + + /** + * 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 + * @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); + } + + // -------------------------------------------------------------------- + + /** + * Delete statement + * + * Generates a platform-specific delete string from the supplied data + * + * @access public + * @param string the table name + * @param array the where clause + * @return string + */ + function _delete($table, $where) + { + return "DELETE FROM ".$this->escape_table($table)." WHERE ".implode(" ", $where); + } + + // -------------------------------------------------------------------- + + /** + * Version number query string + * + * @access public + * @return string + */ + function _version() + { + return "SELECT version() AS ver"; + } + + // -------------------------------------------------------------------- + + /** + * Show table query + * + * Generates a platform-specific query string so that the table names can be fetched + * + * @access public + * @return string + */ + function _show_tables() + { + return "SHOW TABLES FROM `".$this->database."`"; + } + + // -------------------------------------------------------------------- + + /** + * Show columnn 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 _show_columns($table = '') + { + return "SHOW COLUMNS FROM ".$this->escape_table($table); + } + + // -------------------------------------------------------------------- + + /** + * 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; + } + +} + + +/** + * MySQL Result Class + * + * This class extends the parent result class: CI_DB_result + * + * @category Database + * @author Rick Ellis + * @link http://www.codeigniter.com/user_guide/libraries/database/ + */ +class CI_DB_mysql_result extends CI_DB_result { + + /** + * Number of rows in the result set + * + * @access public + * @return integer + */ + function num_rows() + { + return @mysql_num_rows($this->result_id); + } + + // -------------------------------------------------------------------- + + /** + * Number of fields in the result set + * + * @access public + * @return integer + */ + function num_fields() + { + return @mysql_num_fields($this->result_id); + } + + // -------------------------------------------------------------------- + + /** + * Field data + * + * Generates an array of objects containing field meta-data + * + * @access public + * @return array + */ + function field_data() + { + $retval = array(); + while ($field = mysql_fetch_field($this->result_id)) + { + $F = new CI_DB_field(); + $F->name = $field->name; + $F->type = $field->type; + $F->default = $field->def; + $F->max_length = $field->max_length; + $F->primary_key = $field->primary_key; + + $retval[] = $F; + } + + return $retval; + } + + // -------------------------------------------------------------------- + + /** + * 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); + } + +} + +?> \ No newline at end of file diff --git a/system/drivers/DB_mysqli.php b/system/drivers/DB_mysqli.php new file mode 100644 index 000000000..f8cb19dbe --- /dev/null +++ b/system/drivers/DB_mysqli.php @@ -0,0 +1,496 @@ +hostname, $this->username, $this->password); + } + + // -------------------------------------------------------------------- + + /** + * Persistent database connection + * + * @access private called by the base class + * @return resource + */ + function db_pconnect() + { + return $this->db_connect(); + } + + // -------------------------------------------------------------------- + + /** + * Select the database + * + * @access private called by the base class + * @return resource + */ + function db_select() + { + return @mysqli_select_db($this->conn_id, $this->database); + } + + // -------------------------------------------------------------------- + + /** + * 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 @mysqli_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) + { + // "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; + } + + // -------------------------------------------------------------------- + + /** + * Escape String + * + * @access public + * @param string + * @return string + */ + function escape_str($str) + { + if (get_magic_quotes_gpc()) + { + $str = stripslashes($str); + } + return mysqli_real_escape_string($this->conn_id, $str); + } + + // -------------------------------------------------------------------- + + /** + * Close DB Connection + * + * @access public + * @param resource + * @return void + */ + function destroy($conn_id) + { + mysqli_close($conn_id); + } + + // -------------------------------------------------------------------- + + /** + * 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("SELECT COUNT(*) AS numrows FROM `".$this->dbprefix.$table."`"); + + if ($query->num_rows() == 0) + return '0'; + + $row = $query->row(); + return $row->numrows; + } + + // -------------------------------------------------------------------- + + /** + * The error message string + * + * @access public + * @return string + */ + function error_message() + { + return mysqli_error($this->conn_id); + } + + // -------------------------------------------------------------------- + + /** + * The error message number + * + * @access public + * @return integer + */ + function error_number() + { + return mysqli_errno($this->conn_id); + } + + // -------------------------------------------------------------------- + + /** + * 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 public + * @param string the table name + * @return string + */ + function escape_table($table) + { + if (stristr($table, '.')) + { + $table = preg_replace("/\./", "`.`", $table); + } + + return $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) + { + $sql = "SELECT * FROM ".$this->escape_table($table)." LIMIT 1"; + $query = $this->query($sql); + return $query->field_data(); + } + + // -------------------------------------------------------------------- + + /** + * 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 + * @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); + } + + // -------------------------------------------------------------------- + + /** + * Delete statement + * + * Generates a platform-specific delete string from the supplied data + * + * @access public + * @param string the table name + * @param array the where clause + * @return string + */ + function _delete($table, $where) + { + return "DELETE FROM ".$this->escape_table($table)." WHERE ".implode(" ", $where); + } + + // -------------------------------------------------------------------- + + /** + * Version number query string + * + * @access public + * @return string + */ + function _version() + { + return "SELECT version() AS ver"; + } + + // -------------------------------------------------------------------- + + /** + * Show table query + * + * Generates a platform-specific query string so that the table names can be fetched + * + * @access public + * @return string + */ + function _show_tables() + { + return "SHOW TABLES FROM `".$this->database."`"; + } + + // -------------------------------------------------------------------- + + /** + * Show columnn 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 _show_columns($table = '') + { + return "SHOW COLUMNS FROM ".$this->escape_table($table); + } + + // -------------------------------------------------------------------- + + /** + * 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; + } + +} + + + +/** + * MySQLi Result Class + * + * This class extends the parent result class: CI_DB_result + * + * @category Database + * @author Rick Ellis + * @link http://www.codeigniter.com/user_guide/libraries/database/ + */ +class CI_DB_mysqli_result extends CI_DB_result { + + /** + * Number of rows in the result set + * + * @access public + * @return integer + */ + function num_rows() + { + return @mysqli_num_rows($this->result_id); + } + + // -------------------------------------------------------------------- + + /** + * Number of fields in the result set + * + * @access public + * @return integer + */ + function num_fields() + { + return @mysqli_num_fields($this->result_id); + } + + // -------------------------------------------------------------------- + + /** + * Field data + * + * Generates an array of objects containing field meta-data + * + * @access public + * @return array + */ + function field_data() + { + $retval = array(); + while ($field = mysqli_fetch_field($this->result_id)) + { + $F = new CI_DB_field(); + $F->name = $field->name; + $F->type = $field->type; + $F->default = $field->def; + $F->max_length = $field->max_length; + $F->primary_key = 0; + + $retval[] = $F; + } + + return $retval; + } + + // -------------------------------------------------------------------- + + /** + * 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); + } + +} + +?> \ No newline at end of file diff --git a/system/drivers/DB_odbc.php b/system/drivers/DB_odbc.php new file mode 100644 index 000000000..fac44904b --- /dev/null +++ b/system/drivers/DB_odbc.php @@ -0,0 +1,468 @@ +database, $this->username, $this->password); + } + + // -------------------------------------------------------------------- + + /** + * Persistent database connection + * + * @access private called by the base class + * @return resource + */ + function db_pconnect() + { + return odbc_pconnect($this->database, $this->username, $this->password); + } + + // -------------------------------------------------------------------- + + /** + * Select the database + * + * @access private called by the base class + * @return resource + */ + function db_select() + { + // Not needed for ODBC + 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 @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; + } + + // -------------------------------------------------------------------- + + /** + * Escape String + * + * @access public + * @param string + * @return string + */ + function escape_str($str) + { + // ODBC doesn't require escaping + return $str; + } + + // -------------------------------------------------------------------- + + /** + * Close DB Connection + * + * @access public + * @param resource + * @return void + */ + function destroy($conn_id) + { + odbc_close($conn_id); + } + + // -------------------------------------------------------------------- + + /** + * 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("SELECT COUNT(*) AS numrows FROM `".$this->dbprefix.$table."`"); + + if ($query->num_rows() == 0) + return '0'; + + $row = $query->row(); + return $row->numrows; + } + + // -------------------------------------------------------------------- + + /** + * The error message string + * + * @access public + * @return string + */ + function error_message() + { + return odbc_errormsg($this->conn_id); + } + + // -------------------------------------------------------------------- + + /** + * The error message number + * + * @access public + * @return integer + */ + function error_number() + { + return odbc_error($this->conn_id); + } + + // -------------------------------------------------------------------- + + /** + * 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 public + * @param string the table name + * @return string + */ + function escape_table($table) + { + if (stristr($table, '.')) + { + $table = preg_replace("/\./", "`.`", $table); + } + + return $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) + { + $sql = "SELECT TOP 1 FROM ".$this->escape_table($table); + $query = $this->query($sql); + return $query->field_data(); + } + + // -------------------------------------------------------------------- + + /** + * 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 + * @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); + } + + // -------------------------------------------------------------------- + + /** + * Delete statement + * + * Generates a platform-specific delete string from the supplied data + * + * @access public + * @param string the table name + * @param array the where clause + * @return string + */ + function _delete($table, $where) + { + return "DELETE FROM ".$this->escape_table($table)." WHERE ".implode(" ", $where); + } + + // -------------------------------------------------------------------- + + /** + * Version number query string + * + * @access public + * @return string + */ + function _version() + { + return "SELECT version() AS ver"; + } + + // -------------------------------------------------------------------- + + /** + * Show table query + * + * Generates a platform-specific query string so that the table names can be fetched + * + * @access public + * @return string + */ + function _show_tables() + { + return "SHOW TABLES FROM `".$this->database."`"; + } + + // -------------------------------------------------------------------- + + /** + * Show columnn 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 _show_columns($table = '') + { + return "SHOW COLUMNS FROM ".$this->escape_table($table); + } + + // -------------------------------------------------------------------- + + /** + * 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; + } + +} + + +/** + * ODBC Result Class + * + * This class extends the parent result class: CI_DB_result + * + * @category Database + * @author Rick Ellis + * @link http://www.codeigniter.com/user_guide/libraries/database/ + */ +class CI_DB_odbc_result extends CI_DB_result { + + /** + * Number of rows in the result set + * + * @access public + * @return integer + */ + function num_rows() + { + return @odbc_num_rows($this->result_id); + } + + // -------------------------------------------------------------------- + + /** + * Number of fields in the result set + * + * @access public + * @return integer + */ + function num_fields() + { + return @odbc_num_fields($this->result_id); + } + + // -------------------------------------------------------------------- + + /** + * 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 CI_DB_field(); + $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; + } + + // -------------------------------------------------------------------- + + /** + * Result - associative array + * + * Returns the result set as an array + * + * @access private + * @return array + */ + function _fetch_assoc() + { + return odbc_fetch_array($this->result_id); + } + + // -------------------------------------------------------------------- + + /** + * Result - object + * + * Returns the result set as an object + * + * @access private + * @return object + */ + function _fetch_object() + { + return odbc_fetch_object($this->result_id); + } + +} + +?> \ No newline at end of file diff --git a/system/drivers/DB_postgre.php b/system/drivers/DB_postgre.php new file mode 100644 index 000000000..01d4b3df0 --- /dev/null +++ b/system/drivers/DB_postgre.php @@ -0,0 +1,476 @@ +hostname." dbname=".$this->database." user=".$this->username." password=".$this->password); + } + + // -------------------------------------------------------------------- + + /** + * Persistent database connection + * + * @access private called by the base class + * @return resource + */ + function db_pconnect() + { + return pg_pconnect("host=".$this->hostname." dbname=".$this->database." user=".$this->username." password=".$this->password); + } + + // -------------------------------------------------------------------- + + /** + * 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; + } + + // -------------------------------------------------------------------- + + /** + * 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; + } + + // -------------------------------------------------------------------- + + /** + * Escape String + * + * @access public + * @param string + * @return string + */ + function escape_str($str) + { + if (get_magic_quotes_gpc()) + { + $str = stripslashes($str); + } + return pg_escape_string($str); + } + + // -------------------------------------------------------------------- + + /** + * Close DB Connection + * + * @access public + * @param resource + * @return void + */ + function destroy($conn_id) + { + pg_close($conn_id); + } + + // -------------------------------------------------------------------- + + /** + * 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() + { + return pg_last_oid($this->result_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("SELECT COUNT(*) AS numrows FROM `".$this->dbprefix.$table."`"); + + if ($query->num_rows() == 0) + return '0'; + + $row = $query->row(); + return $row->numrows; + } + + // -------------------------------------------------------------------- + + /** + * The error message string + * + * @access public + * @return string + */ + function error_message() + { + return pg_last_error($this->conn_id); + } + + // -------------------------------------------------------------------- + + /** + * The error message number + * + * @access public + * @return integer + */ + function error_number() + { + return ''; + } + + // -------------------------------------------------------------------- + + /** + * 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 public + * @param string the table name + * @return string + */ + function escape_table($table) + { + if (stristr($table, '.')) + { + $table = preg_replace("/\./", "`.`", $table); + } + + return $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) + { + $sql = "SELECT * FROM ".$this->escape_table($table)." LIMIT 1"; + $query = $this->query($sql); + return $query->field_data(); + } + + // -------------------------------------------------------------------- + + /** + * 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 + * @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); + } + + // -------------------------------------------------------------------- + + /** + * Delete statement + * + * Generates a platform-specific delete string from the supplied data + * + * @access public + * @param string the table name + * @param array the where clause + * @return string + */ + function _delete($table, $where) + { + return "DELETE FROM ".$this->escape_table($table)." WHERE ".implode(" ", $where); + } + + // -------------------------------------------------------------------- + + /** + * Version number query string + * + * @access public + * @return string + */ + function _version() + { + return "SELECT version() AS ver"; + } + + /** + * Show table query + * + * Generates a platform-specific query string so that the table names can be fetched + * + * @access public + * @return string + */ + function _show_tables() + { + return "SELECT table_name FROM information_schema.tables WHERE table_schema = 'public'"; + } + + // -------------------------------------------------------------------- + + /** + * Show columnn 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 _show_columns($table = '') + { + return "SELECT column_name FROM information_schema.columns WHERE table_name ='".$this->escape_table($table)."'"; + } + + // -------------------------------------------------------------------- + + /** + * 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; + } + +} + + + +/** + * Postgres Result Class + * + * This class extends the parent result class: CI_DB_result + * + * @category Database + * @author Rick Ellis + * @link http://www.codeigniter.com/user_guide/libraries/database/ + */ +class CI_DB_postgre_result extends CI_DB_result { + + /** + * Number of rows in the result set + * + * @access public + * @return integer + */ + function num_rows() + { + return @pg_num_rows($this->result_id); + } + + // -------------------------------------------------------------------- + + /** + * Number of fields in the result set + * + * @access public + * @return integer + */ + function num_fields() + { + return @pg_num_fields($this->result_id); + } + + // -------------------------------------------------------------------- + + /** + * 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 CI_DB_field(); + $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; + } + + // -------------------------------------------------------------------- + + /** + * 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); + } + +} + +?> \ No newline at end of file diff --git a/system/drivers/DB_sqlite.php b/system/drivers/DB_sqlite.php new file mode 100644 index 000000000..6428dd5bb --- /dev/null +++ b/system/drivers/DB_sqlite.php @@ -0,0 +1,501 @@ +database, 0666, $error)) + { + log_message('error', $error); + + if ($this->db_debug) + { + $this->display_error($error, '', TRUE); + } + } + + 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, 0666, $error)) + { + log_message('error', $error); + + if ($this->db_debug) + { + $this->display_error($error, '', TRUE); + } + } + + return $conn_id; + } + + // -------------------------------------------------------------------- + + /** + * Select the database + * + * @access private called by the base class + * @return resource + */ + function db_select() + { + 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 @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; + } + + // -------------------------------------------------------------------- + + /** + * Escape String + * + * @access public + * @param string + * @return string + */ + function escape_str($str) + { + if (get_magic_quotes_gpc()) + { + $str = stripslashes($str); + } + return sqlite_escape_string($str); + } + + // -------------------------------------------------------------------- + + /** + * Close DB Connection + * + * @access public + * @param resource + * @return void + */ + function destroy($conn_id) + { + sqlite_close($conn_id); + } + + // -------------------------------------------------------------------- + + /** + * 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("SELECT COUNT(*) AS numrows FROM `".$this->dbprefix.$table."`"); + + if ($query->num_rows() == 0) + return '0'; + + $row = $query->row(); + return $row->numrows; + } + + // -------------------------------------------------------------------- + + /** + * The error message string + * + * @access public + * @return string + */ + function error_message() + { + return sqlite_error_string(sqlite_last_error($this->conn_id)); + } + + // -------------------------------------------------------------------- + + /** + * The error message number + * + * @access public + * @return integer + */ + function error_number() + { + return sqlite_last_error($this->conn_id); + } + + // -------------------------------------------------------------------- + + /** + * Version number query string + * + * @access public + * @return string + */ + function version() + { + return sqlite_libversion(); + } + + // -------------------------------------------------------------------- + + /** + * 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 public + * @param string the table name + * @return string + */ + function escape_table($table) + { + if (stristr($table, '.')) + { + $table = preg_replace("/\./", "`.`", $table); + } + + return $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) + { + $sql = "SELECT * FROM ".$this->escape_table($table)." LIMIT 1"; + $query = $this->query($sql); + return $query->field_data(); + } + + // -------------------------------------------------------------------- + + /** + * 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 + * @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); + } + + // -------------------------------------------------------------------- + + /** + * Delete statement + * + * Generates a platform-specific delete string from the supplied data + * + * @access public + * @param string the table name + * @param array the where clause + * @return string + */ + function _delete($table, $where) + { + return "DELETE FROM ".$this->escape_table($table)." WHERE ".implode(" ", $where); + } + + // -------------------------------------------------------------------- + + /** + * Show table query + * + * Generates a platform-specific query string so that the table names can be fetched + * + * @access public + * @return string + */ + function _show_tables() + { + return "SELECT name from sqlite_master WHERE type='table'"; + } + + // -------------------------------------------------------------------- + + /** + * Show columnn 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 _show_columns($table = '') + { + // Not supported + return FALSE; + } + + // -------------------------------------------------------------------- + + /** + * 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; + } + +} + + +/** + * SQLite Result Class + * + * This class extends the parent result class: CI_DB_result + * + * @category Database + * @author Rick Ellis + * @link http://www.codeigniter.com/user_guide/libraries/database/ + */ +class CI_DB_sqlite_result extends CI_DB_result { + + /** + * Number of rows in the result set + * + * @access public + * @return integer + */ + function num_rows() + { + return @sqlite_num_rows($this->result_id); + } + + // -------------------------------------------------------------------- + + /** + * Number of fields in the result set + * + * @access public + * @return integer + */ + function num_fields() + { + return @sqlite_num_fields($this->result_id); + } + + // -------------------------------------------------------------------- + + /** + * 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 CI_DB_field(); + $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; + } + + // -------------------------------------------------------------------- + + /** + * 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() + { + return sqlite_fetch_object($this->result_id); + } + +} + +?> \ No newline at end of file diff --git a/system/drivers/index.html b/system/drivers/index.html new file mode 100644 index 000000000..5a1f5d6ae --- /dev/null +++ b/system/drivers/index.html @@ -0,0 +1,15 @@ + + + + +403 Forbidden + + + + + +

Directory access is forbidden.

+ + + + \ No newline at end of file diff --git a/system/fonts/index.html b/system/fonts/index.html new file mode 100644 index 000000000..5a1f5d6ae --- /dev/null +++ b/system/fonts/index.html @@ -0,0 +1,15 @@ + + + + +403 Forbidden + + + + + +

Directory access is forbidden.

+ + + + \ No newline at end of file diff --git a/system/fonts/texb.ttf b/system/fonts/texb.ttf new file mode 100644 index 000000000..383c88b86 Binary files /dev/null and b/system/fonts/texb.ttf differ diff --git a/system/helpers/array_helper.php b/system/helpers/array_helper.php new file mode 100644 index 000000000..cccde1fc4 --- /dev/null +++ b/system/helpers/array_helper.php @@ -0,0 +1,47 @@ + \ No newline at end of file diff --git a/system/helpers/cookie_helper.php b/system/helpers/cookie_helper.php new file mode 100644 index 000000000..24e243ddd --- /dev/null +++ b/system/helpers/cookie_helper.php @@ -0,0 +1,77 @@ + 0) + { + $expire = time() + $expire; + } + else + { + $expire = 0; + } + } + + setcookie($prefix.$name, $value, $expire, $path, $domain, 0); +} + +?> \ No newline at end of file diff --git a/system/helpers/date_helper.php b/system/helpers/date_helper.php new file mode 100644 index 000000000..2a3d50859 --- /dev/null +++ b/system/helpers/date_helper.php @@ -0,0 +1,530 @@ +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(); + } +} + +// ------------------------------------------------------------------------ + +/** + * 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 + */ +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 + * + * 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 + */ +function timespan($seconds = 1, $time = '') +{ + $obj =& get_instance(); + $obj->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.' '.$obj->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.' '.$obj->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.' '.$obj->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.' '.$obj->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.' '.$obj->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.' '.$obj->lang->line((($minutes > 1) ? 'date_minutes' : 'date_minutes')).', '; + } + + $seconds -= $minutes * 60; + } + + if ($str == '') + { + $str .= $seconds.' '.$obj->lang->line((($seconds > 1) ? 'date_seconds' : 'date_second')).', '; + } + + return substr(trim($str), 0, -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. + * + * @access public + * @param integer a numeric month + * @param integer a numeric year + * @return integer + */ +function days_in_month($month = 0, $year = '') +{ + if ($month < 1 OR $month > 12) + { + return 0; + } + + if ( ! ctype_digit($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]; +} + +// ------------------------------------------------------------------------ + +/** + * Converts a local Unix timestamp to GMT + * + * @access public + * @param integer Unix timestamp + * @return integer + */ +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 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 + */ +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 a MySQL Timestamp to Unix + * + * @access public + * @param integer Unix timestamp + * @return integer + */ +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) + ); +} + +// ------------------------------------------------------------------------ + +/** + * 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 + */ +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; +} + +// ------------------------------------------------------------------------ + +/** + * Convert "human" date to GMT + * + * Reverses the above process + * + * @access public + * @param string format: us or euro + * @return integer + */ +function human_to_unix($datestr = '') +{ + if ($datestr == '') + { + return FALSE; + } + + $datestr = trim($datestr); + $datestr = preg_replace("/\040+/", "\040", $datestr); + + if ( ! ereg("^[0-9]{2,4}\-[0-9]{1,2}\-[0-9]{1,2}\040[0-9]{1,2}:[0-9]{1,2}.*$", $datestr)) + { + return FALSE; + } + + $split = preg_split("/\040/", $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']) AND ereg("[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'; + + if (strlen($hour) == 1) + $hour = '0'.$hour; + } + + return mktime($hour, $min, $sec, $month, $day, $year); +} + +// ------------------------------------------------------------------------ + +/** + * Timezone Menu + * + * Generates a drop-down menu of timezones. + * + * @access public + * @param string timezone + * @param string classname + * @param string menu name + * @return string + */ +function timezone_menu($default = 'UTC', $class = "", $name = 'timezones') +{ + $obj =& get_instance(); + $obj->lang->load('date'); + + if ($default == 'GMT') + $default = 'UTC'; + + $menu = '"; + + return $menu; +} + +// ------------------------------------------------------------------------ + +/** + * Timezones + * + * Returns an array of timezones. This is a helper function + * for varios other ones in this library + * + * @access public + * @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, + 'UM9' => -9, + 'UM8' => -8, + 'UM7' => -7, + 'UM6' => -6, + 'UM5' => -5, + 'UM4' => -4, + 'UM25' => -2.5, + 'UM3' => -3, + 'UM2' => -2, + 'UM1' => -1, + 'UTC' => 0, + 'UP1' => +1, + 'UP2' => +2, + 'UP3' => +3, + 'UP25' => +2.5, + 'UP4' => +4, + 'UP35' => +3.5, + 'UP5' => +5, + 'UP45' => +4.5, + 'UP6' => +6, + 'UP7' => +7, + 'UP8' => +8, + 'UP9' => +9, + 'UP85' => +8.5, + 'UP10' => +10, + 'UP11' => +11, + 'UP12' => +12 + ); + + if ($tz == '') + { + return $zones; + } + + if ($tz == 'GMT') + $tz = 'UTC'; + + return ( ! isset($zones[$tz])) ? 0 : $zones[$tz]; +} + + +?> \ No newline at end of file diff --git a/system/helpers/directory_helper.php b/system/helpers/directory_helper.php new file mode 100644 index 000000000..69eb13d11 --- /dev/null +++ b/system/helpers/directory_helper.php @@ -0,0 +1,69 @@ + \ No newline at end of file diff --git a/system/helpers/file_helper.php b/system/helpers/file_helper.php new file mode 100644 index 000000000..93bddb029 --- /dev/null +++ b/system/helpers/file_helper.php @@ -0,0 +1,139 @@ + 0) + { + $data = fread($fp, filesize($file)); + } + + flock($fp, LOCK_UN); + fclose($fp); + + return $data; +} + +// ------------------------------------------------------------------------ + +/** + * Write File + * + * Writes data to the file specified in the path. + * Creats a new file if non-existant. + * + * @access public + * @param string path to file + * @param string file data + * @return bool + */ +function write_file($path, $data) +{ + if ( ! $fp = @fopen($path, 'wb')) + { + return FALSE; + } + + flock($fp, LOCK_EX); + fwrite($fp, $data); + flock($fp, LOCK_UN); + fclose($fp); + + 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 direcotries 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 + */ +function delete_files($path, $del_dir = FALSE) +{ + // Trim the trailing slahs + $path = preg_replace("|^(.+?)/*$|", "\\1", $path); + + if ( ! $current_dir = @opendir($path)) + return; + + while(FALSE !== ($filename = @readdir($current_dir))) + { + if ($filename != "." and $filename != "..") + { + if (is_dir($path.'/'.$filename)) + { + delete_files($path.'/'.$filename, $del_dir); + } + else + { + unlink($path.'/'.$filename); + } + } + } + @closedir($current_dir); + + if ($del_dir == TRUE) + { + @rmdir($path); + } +} + + +?> \ No newline at end of file diff --git a/system/helpers/form_helper.php b/system/helpers/form_helper.php new file mode 100644 index 000000000..f82ad01a0 --- /dev/null +++ b/system/helpers/form_helper.php @@ -0,0 +1,382 @@ +config->site_url($action).'"'; + + if (is_array($attributes) AND count($attributes) > 0) + { + foreach ($attributes as $key => $val) + { + $form .= ' '.$key.'="'.$val.'"'; + } + } + + $form .= '>'; + + if (is_array($hidden) AND count($hidden > 0)) + { + $form .= form_hidden($hidden); + } + + 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 + */ +function form_open_multipart($action, $attributes = array(), $hidden = array()) +{ + $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 + */ +function form_hidden($name, $value = '') +{ + if ( ! is_array($name)) + { + return ''; + } + + $form = ''; + foreach ($name as $name => $value) + { + $form .= ''; + } + + return $form; +} + +// ------------------------------------------------------------------------ + +/** + * Text Input Field + * + * @access public + * @param mixed + * @param string + * @param string + * @return string + */ +function form_input($data = '', $value = '', $extra = '') +{ + $defaults = array('type' => 'text', 'name' => (( ! is_array($data)) ? $data : ''), 'value' => $value, 'maxlength' => '500', 'size' => '50'); + + return "\n"; +} + +// ------------------------------------------------------------------------ + +/** + * Password Field + * + * Identical to the input function but adds the "password" type + * + * @access public + * @param mixed + * @param string + * @param string + * @return string + */ +function form_password($data = '', $value = '', $extra = '') +{ + if ( ! is_array($data)) + { + $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 + */ +function form_upload($data = '', $value = '', $extra = '') +{ + if ( ! is_array($data)) + { + $data = array('name' => $data); + } + + $data['type'] = 'file'; + return form_input($data, $value, $extra); +} + +// ------------------------------------------------------------------------ + +/** + * Textarea field + * + * @access public + * @param mixed + * @param string + * @param string + * @return string + */ +function form_textarea($data = '', $value = '', $extra = '') +{ + $defaults = array('name' => (( ! is_array($data)) ? $data : ''), 'cols' => '90', 'rows' => '12'); + + $val = (( ! is_array($data) OR ! isset($data['value'])) ? $value : $data['value']); + + return "\n"; +} + +// ------------------------------------------------------------------------ + +/** + * Dropdown Menu + * + * @access public + * @param string + * @param array + * @param string + * @param string + * @return string + */ +function form_dropdown($name = '', $options = array(), $selected = '', $extra = '') +{ + if ($extra != '') $extra = ' '.$extra; + + $form = ''; + + return $form; +} + +// ------------------------------------------------------------------------ + +/** + * Checkbox Field + * + * @access public + * @param mixed + * @param string + * @param bool + * @param string + * @return string + */ +function form_checkbox($data = '', $value = '', $checked = TRUE, $extra = '') +{ + $defaults = array('type' => 'checkbox', 'name' => (( ! is_array($data)) ? $data : ''), 'value' => $value); + + if (isset($data['checked'])) + { + $checked = $data['checked']; + + if ($checked == FALSE) + unset($data['checked']); + } + + if ($checked == TRUE) + $defaults['checked'] = ' checked="checked"'; + else + unset($defaults['checked']); + + return "\n"; +} + +// ------------------------------------------------------------------------ + +/** + * Radio Button + * + * @access public + * @param mixed + * @param string + * @param bool + * @param string + * @return string + */ +function form_radio($data = '', $value = '', $checked = TRUE, $extra = '') +{ + if ( ! is_array($data)) + { + $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 + */ +function form_submit($data = '', $value = '', $extra = '') +{ + $defaults = array('type' => 'submit', 'name' => (( ! is_array($data)) ? $data : ''), 'value' => $value); + + return "\n"; +} + +// ------------------------------------------------------------------------ + +/** + * Form Close Tag + * + * @access public + * @param string + * @return string + */ +function form_close($extra = '') +{ + return "\n".$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 + */ +function form_prep($str = '') +{ + if ($str == '') + { + return ''; + } + + return str_replace(array("'", '"'), array("'", """), htmlspecialchars($str)); +} + +// ------------------------------------------------------------------------ + +/** + * Parse the form attributes + * + * Helper function used by some of the form helpers + * + * @access private + * @param array + * @parm array + * @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 = form_prep($val); + } + + $att .= $key . '="' . $val . '" '; + } + + return $att; +} + +?> \ No newline at end of file diff --git a/system/helpers/html_helper.php b/system/helpers/html_helper.php new file mode 100644 index 000000000..1c97dda53 --- /dev/null +++ b/system/helpers/html_helper.php @@ -0,0 +1,76 @@ +".$data.""; +} + +// ------------------------------------------------------------------------ + +/** + * Generates HTML BR tags based on number supplied + * + * @access public + * @param integer + * @return string + */ +function br($num = 1) +{ + return str_repeat("
", $num); +} + +// ------------------------------------------------------------------------ + +/** + * Generates non-breaking space entities based on number supplied + * + * @access public + * @param integer + * @return string + */ +function nbs($num = 1) +{ + return str_repeat(" ", $num); +} + + + +?> \ No newline at end of file diff --git a/system/helpers/index.html b/system/helpers/index.html new file mode 100644 index 000000000..5a1f5d6ae --- /dev/null +++ b/system/helpers/index.html @@ -0,0 +1,15 @@ + + + + +403 Forbidden + + + + + +

Directory access is forbidden.

+ + + + \ No newline at end of file diff --git a/system/helpers/security_helper.php b/system/helpers/security_helper.php new file mode 100644 index 000000000..918e4ae90 --- /dev/null +++ b/system/helpers/security_helper.php @@ -0,0 +1,112 @@ +input->xss_clean($str, $charset); +} + +// -------------------------------------------------------------------- + +/** + * Hash encode a string + * + * @access public + * @param string + * @return string + */ +function hash($str, $type = 'sha1') +{ + if ($type == 'sha1') + { + if ( ! function_exists('sha1')) + { + if ( ! function_exists('mhash')) + { + require_once(BASEPATH.'libraries/Sha1'.EXT); + $SH = new CI_SHA; + return $SH->generate($str); + } + else + { + return bin2hex(mhash(MHASH_SHA1, $str)); + } + } + else + { + return sha1($str); + } + } + else + { + return md5($str); + } +} + +// ------------------------------------------------------------------------ + +/** + * Strip Image Tags + * + * @access public + * @parm string + * @return string + */ +function strip_image_tags($str) +{ + $str = preg_replace("##", "\\1", $str); + $str = preg_replace("##", "\\1", $str); + + return $str; +} + +// ------------------------------------------------------------------------ + +/** + * Convert PHP tags to entities + * + * @access public + * @parm string + * @return string + */ +function encode_php_tags($str) +{ + return str_replace(array(''), array('<?php', '<?PHP', '<?', '?>'), $str); +} + +?> \ No newline at end of file diff --git a/system/helpers/string_helper.php b/system/helpers/string_helper.php new file mode 100644 index 000000000..d5a3591f9 --- /dev/null +++ b/system/helpers/string_helper.php @@ -0,0 +1,154 @@ + \ No newline at end of file diff --git a/system/helpers/text_helper.php b/system/helpers/text_helper.php new file mode 100644 index 000000000..15b5573bf --- /dev/null +++ b/system/helpers/text_helper.php @@ -0,0 +1,386 @@ += $n) + { + return trim($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 + */ +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) + { + $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; +} + +// ------------------------------------------------------------------------ + +/** + * Entities to ASCII + * + * Converts character entities back to ASCII + * + * @access public + * @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)); + $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; +} + +// ------------------------------------------------------------------------ + +/** + * 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 + */ +function word_censor($str, $censored, $replacement = '') +{ + if ( ! is_array($censored)) + { + return $str; + } + + $str = ' '.$str.' '; + foreach ($censored as $badword) + { + if ($replacement != '') + { + $str = preg_replace("/\b(".str_replace('\*', '\w*?', preg_quote($badword)).")\b/i", $replacement, $str); + } + else + { + $str = preg_replace("/\b(".str_replace('\*', '\w*?', preg_quote($badword)).")\b/ie", "str_repeat('#', strlen('\\1'))", $str); + } + } + + return trim($str); +} + +// ------------------------------------------------------------------------ + +/** + * Code Highlighter + * + * Colorizes code strings + * + * @access public + * @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 + $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('<?php', '?>', '\\'), array('phptagopen', 'phptagclose', 'backslashtmp'), $str); + + // The highlight_string function requires that the text be surrounded + // by PHP tags. Since we don't know if A) the submitted text has PHP tags, + // or B) whether the PHP tags enclose the entire string, we will add our + // own PHP tags around the string along with some markers to make replacement easier later + + $str = ''; // '), array(''), $str); + $str = preg_replace('#color="(.*?)"#', 'style="color: \\1"', $str); + } + + // Remove our artificially added PHP + $str = preg_replace("#\.+?//tempstart\
\#is", "\n", $str); + $str = preg_replace("#\.+?//tempstart\
#is", "\n", $str); + $str = preg_replace("#//tempend.+#is", "
\n", $str); + + // Replace our markers back to PHP tags. + $str = str_replace(array('phptagopen', 'phptagclose', 'backslashtmp'), array('<?php', '?>', '\\'), $str); //', $tag_close = '') +{ + if ($str == '') + { + return ''; + } + + if ($phrase != '') + { + return preg_replace('/('.preg_quote($phrase).')/i', $tag_open."\\1".$tag_close, $str); + } + + return $str; +} + +// ------------------------------------------------------------------------ + +/** + * Word Wrap + * + * Wraps text at the specified character. Maintains the integrity of words. + * + * @access public + * @param string the text string + * @param integer the number of characters to wrap at + * @return string + */ +function word_wrap($str, $chars = '76') +{ + if ( ! ctype_digit($chars)) + $chars = 76; + + $str = preg_replace("/(\r\n|\r|\n)/", "\n", $str); + $lines = split("\n", $str); + + $output = ""; + while (list(, $thisline) = each($lines)) + { + if (strlen($thisline) > $chars) + { + $line = ""; + $words = split(" ", $thisline); + while(list(, $thisword) = each($words)) + { + while((strlen($thisword)) > $chars) + { + $cur_pos = 0; + for($i=0; $i < $chars - 1; $i++) + { + $output .= $thisword[$i]; + $cur_pos++; + } + + $output .= "\n"; + $thisword = substr($thisword, $cur_pos, (strlen($thisword) - $cur_pos)); + } + + if ((strlen($line) + strlen($thisword)) > $chars) + { + $output .= $line."\n"; + $line = $thisword." "; + } + else + { + $line .= $thisword." "; + } + } + + $output .= $line."\n"; + } + else + { + $output .= $thisline."\n"; + } + } + + return $output; +} + +?> \ No newline at end of file diff --git a/system/helpers/typography_helper.php b/system/helpers/typography_helper.php new file mode 100644 index 000000000..6a5495239 --- /dev/null +++ b/system/helpers/typography_helper.php @@ -0,0 +1,490 @@ +",$str); + $ct = count($ex); + + $newstr = ""; + for ($i = 0; $i < $ct; $i++) + { + if (($i % 2) == 0) + { + $newstr .= nl2br($ex[$i]); + } + else + { + $newstr .= $ex[$i]; + } + + if ($ct - 1 != $i) + $newstr .= "pre>"; + } + + return $newstr; +} + +// ------------------------------------------------------------------------ + +/** + * Auto Typography Wrapper Function + * + * + * @access public + * @parm string + * @return string + */ +function auto_typography($str) +{ + $TYPE = new Auto_typography(); + return $TYPE->convert($str); +} + +// ------------------------------------------------------------------------ + +/** + * Auto Typography Class + * + * + * @access private + * @category Helpers + * @author Rick Ellis + * @author Paul Burdick + * @link http://www.codeigniter.com/user_guide/helpers/ + */ +class Auto_typography { + + // Block level elements that should not be wrapped inside

tags + var $block_elements = 'div|blockquote|pre|code|h\d|script|ol|un'; + + // Elements that should not have

and
tags within them. + var $skip_elements = 'pre|ol|ul'; + + // Tags we want the parser to completely ignore when splitting the string. + var $ignore_elements = 'a|b|i|em|strong|span|img|li'; + + + /** + * Main Processing Function + * + */ + function convert($str) + { + if ($str == '') + { + return ''; + } + + $str = ' '.$str.' '; + + // Standardize Newlines to make matching easier + $str = preg_replace("/(\r\n|\r)/", "\n", $str); + + /* + * Reduce line breaks + * + * If there are more than two consecutive line + * breaks we'll compress them down to a maximum + * of two since there's no benefit to more. + * + */ + $str = preg_replace("/\n\n+/", "\n\n", $str); + + /* + * Convert quotes within tags to tempoarary marker + * + * We don't want quotes converted within + * tags so we'll temporarily convert them to + * {{{DQ}}} and {{{SQ}}} + * + */ + if (preg_match_all("#\<.+?>#si", $str, $matches)) + { + for ($i = 0; $i < count($matches['0']); $i++) + { + $str = str_replace($matches['0'][$i], + str_replace(array("'",'"'), array('{{{SQ}}}', '{{{DQ}}}'), $matches['0'][$i]), + $str); + } + } + + /* + * Convert "ignore" tags to tempoarary marker + * + * The parser splits out the string at every tag + * it encounters. Certain inline tags, like image + * tags, links, span tags, etc. will be adversely + * affected if they are split out so we'll convert + * the opening < temporarily to: {{{tag}}} + * + */ + $str = preg_replace("#<(/*)(".$this->ignore_elements.")#i", "{{{tag}}}\\1\\2", $str); + + /* + * Split the string at every tag + * + * This creates an array with this prototype: + * + * [array] + * { + * [0] = + * [1] = Content contained between the tags + * [2] = + * Etc... + * } + * + */ + $chunks = preg_split('/(<(?:[^<>]+(?:"[^"]*"|\'[^\']*\')?)+>)/', $str, -1, PREG_SPLIT_DELIM_CAPTURE|PREG_SPLIT_NO_EMPTY); + + /* + * Build our finalized string + * + * We'll cycle through the array, skipping tags, + * and processing the contained text + * + */ + $str = ''; + $process = TRUE; + foreach ($chunks as $chunk) + { + /* + * Are we dealing with a tag? + * + * If so, we'll skip the processing for this cycle. + * Well also set the "process" flag which allows us + * to skip

 tags and a few other things.
+			 *
+			 */			
+			if (preg_match("#<(/*)(".$this->block_elements.").*?\>#", $chunk, $match)) 
+			{
+				if (preg_match("#".$this->skip_elements."#", $match['2']))
+				{
+					$process =  ($match['1'] == '/') ? TRUE : FALSE;		
+				}
+		
+				$str .= $chunk;
+				continue;
+			}
+		
+			if ($process == FALSE)
+			{
+				$str .= $chunk;
+				continue;
+			}
+			
+			//  Convert Newlines into 

and
tags + $str .= $this->format_newlines($chunk); + } + + // Convert Quotes and other characters + $str = $this->format_characters($str); + + // We'll swap our temporary markers back and do some clean up. + $str = preg_replace('#(

\n*

)#', '', $str); + $str = preg_replace('#()

#', "\\1", $str); + + $str = str_replace( + array('

', '

', '{{{tag}}}', '{{{DQ}}}', '{{{SQ}}}'), + array('

', '

', '<', '"', "'"), + $str + ); + + return trim($str); + } + + // -------------------------------------------------------------------- + + /** + * Format Characters + * + * This function mainly converts double and single quotes + * to entities, but since these are directional, it does + * it based on some rules. It also converts em-dashes + * and a couple other things. + */ + function format_characters($str) + { + $table = array( + ' "' => " “", + '" ' => "” ", + " '" => " ‘", + "' " => "’ ", + + '>"' => ">“", + '"<' => "”<", + ">'" => ">‘", + "'<" => "’<", + + "\"." => "”.", + "\"," => "”,", + "\";" => "”;", + "\":" => "”:", + "\"!" => "”!", + "\"?" => "”?", + + ". " => ".  ", + "? " => "?  ", + "! " => "!  ", + ": " => ":  ", + ); + + // These deal with quotes within quotes, like: "'hi here'" + $start = 0; + $space = array("\n", "\t", " "); + + while(TRUE) + { + $current = strpos(substr($str, $start), "\"'"); + + if ($current === FALSE) break; + + $one_before = substr($str, $start+$current-1, 1); + $one_after = substr($str, $start+$current+2, 1); + + if ( ! in_array($one_after, $space) && $one_after != "<") + { + $str = str_replace( $one_before."\"'".$one_after, + $one_before."“‘".$one_after, + $str); + } + elseif ( ! in_array($one_before, $space) && (in_array($one_after, $space) OR $one_after == '<')) + { + $str = str_replace( $one_before."\"'".$one_after, + $one_before."”’".$one_after, + $str); + } + + $start = $start+$current+2; + } + + $start = 0; + + while(TRUE) + { + $current = strpos(substr($str, $start), "'\""); + + if ($current === FALSE) break; + + $one_before = substr($str, $start+$current-1, 1); + $one_after = substr($str, $start+$current+2, 1); + + if ( in_array($one_before, $space) && ! in_array($one_after, $space) && $one_after != "<") + { + $str = str_replace( $one_before."'\"".$one_after, + $one_before."‘“".$one_after, + $str); + } + elseif ( ! in_array($one_before, $space) && $one_before != ">") + { + $str = str_replace( $one_before."'\"".$one_after, + $one_before."’”".$one_after, + $str); + } + + $start = $start+$current+2; + } + + // Are there quotes within a word, as in: ("something") + if (preg_match_all("/(.)\"(\S+?)\"(.)/", $str, $matches)) + { + for ($i=0, $s=sizeof($matches['0']); $i < $s; ++$i) + { + if ( ! in_array($matches['1'][$i], $space) && ! in_array($matches['3'][$i], $space)) + { + $str = str_replace( $matches['0'][$i], + $matches['1'][$i]."“".$matches['2'][$i]."”".$matches['3'][$i], + $str); + } + } + } + + if (preg_match_all("/(.)\'(\S+?)\'(.)/", $str, $matches)) + { + for ($i=0, $s=sizeof($matches['0']); $i < $s; ++$i) + { + if ( ! in_array($matches['1'][$i], $space) && ! in_array($matches['3'][$i], $space)) + { + $str = str_replace( $matches['0'][$i], + $matches['1'][$i]."‘".$matches['2'][$i]."’".$matches['3'][$i], + $str); + } + } + } + + // How about one apostrophe, as in Rick's + $start = 0; + + while(TRUE) + { + $current = strpos(substr($str, $start), "'"); + + if ($current === FALSE) break; + + $one_before = substr($str, $start+$current-1, 1); + $one_after = substr($str, $start+$current+1, 1); + + if ( ! in_array($one_before, $space) && ! in_array($one_after, $space)) + { + $str = str_replace( $one_before."'".$one_after, + $one_before."’".$one_after, + $str); + } + + $start = $start+$current+2; + } + + // Em-dashes + $start = 0; + while(TRUE) + { + $current = strpos(substr($str, $start), "--"); + + if ($current === FALSE) break; + + $one_before = substr($str, $start+$current-1, 1); + $one_after = substr($str, $start+$current+2, 1); + $two_before = substr($str, $start+$current-2, 1); + $two_after = substr($str, $start+$current+3, 1); + + if (( ! in_array($one_before, $space) && ! in_array($one_after, $space)) + OR + ( ! in_array($two_before, $space) && ! in_array($two_after, $space) && $one_before == ' ' && $one_after == ' ') + ) + { + $str = str_replace( $two_before.$one_before."--".$one_after.$two_after, + $two_before.trim($one_before)."—".trim($one_after).$two_after, + $str); + } + + $start = $start+$current+2; + } + + // Ellipsis + $str = preg_replace("#(\w)\.\.\.(\s|
|

)#", "\\1…\\2", $str); + $str = preg_replace("#(\s|
|

)\.\.\.(\w)#", "\\1…\\2", $str); + + // Run the translation array we defined above + $str = str_replace(array_keys($table), array_values($table), $str); + + // If there are any stray double quotes we'll catch them here + + $start = 0; + + while(TRUE) + { + $current = strpos(substr($str, $start), '"'); + + if ($current === FALSE) break; + + $one_before = substr($str, $start+$current-1, 1); + $one_after = substr($str, $start+$current+1, 1); + + if ( ! in_array($one_after, $space)) + { + $str = str_replace( $one_before.'"'.$one_after, + $one_before."“".$one_after, + $str); + } + elseif( ! in_array($one_before, $space)) + { + $str = str_replace( $one_before."'".$one_after, + $one_before."”".$one_after, + $str); + } + + $start = $start+$current+2; + } + + $start = 0; + + while(TRUE) + { + $current = strpos(substr($str, $start), "'"); + + if ($current === FALSE) break; + + $one_before = substr($str, $start+$current-1, 1); + $one_after = substr($str, $start+$current+1, 1); + + if ( ! in_array($one_after, $space)) + { + $str = str_replace( $one_before."'".$one_after, + $one_before."‘".$one_after, + $str); + } + elseif( ! in_array($one_before, $space)) + { + $str = str_replace( $one_before."'".$one_after, + $one_before."’".$one_after, + $str); + } + + $start = $start+$current+2; + } + + return $str; + } + + // -------------------------------------------------------------------- + + /** + * Format Newlines + * + * Converts newline characters into either

tags or
+ * + */ + function format_newlines($str) + { + if ($str == '') + { + return $str; + } + + if (strpos($str, "\n") === FALSE) + { + return '

'.$str.'

'; + } + + $str = str_replace("\n\n", "

\n\n

", $str); + $str = preg_replace("/([^\n])(\n)([^\n])/", "\\1
\\2\\3", $str); + + return '

'.$str.'

'; + } +} + + +?> \ No newline at end of file diff --git a/system/helpers/url_helper.php b/system/helpers/url_helper.php new file mode 100644 index 000000000..d2d2a5985 --- /dev/null +++ b/system/helpers/url_helper.php @@ -0,0 +1,487 @@ +config->site_url($uri); +} + +// ------------------------------------------------------------------------ + +/** + * Base URL + * + * Returns the "base_url" item from your config file + * + * @access public + * @return string + */ +function base_url() +{ + $obj =& get_instance(); + return $obj->config->item('base_url', 1); +} + +// ------------------------------------------------------------------------ + +/** + * Index page + * + * Returns the "index_page" from your config file + * + * @access public + * @return string + */ +function index_page() +{ + $obj =& get_instance(); + return $obj->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 + */ +function anchor($uri = '', $title = '', $attributes = '') +{ + $site_url = site_url($uri); + + if ($title == '') + { + $title = $site_url; + } + + if ($attributes == '') + { + $attributes = ' title="'.$title.'"'; + } + else + { + if (is_array($attributes)) + { + $attributes = parse_url_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 + */ +function anchor_popup($uri = '', $title = '', $attributes = FALSE) +{ + $site_url = site_url($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]; + } + + return "".$title.""; +} + +// ------------------------------------------------------------------------ + +/** + * Mailto Link + * + * @access public + * @param string the email address + * @param string the link title + * @param mixed any attributes + * @return string + */ +function mailto($email, $title = '', $attributes = '') +{ + if ($title == "") + { + $title = $email; + } + + if (is_array($attributes)) + { + $attributes = parse_url_attributes($attributes); + } + + 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 + */ +function safe_mailto($email, $title = '', $attributes = '') +{ + 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(); + +?>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 < sizeof($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; +} + +// ------------------------------------------------------------------------ + +/** + * Prep URL + * + * Simply adds the http:// part if missing + * + * @access public + * @param string the URL + * @return string + */ +function prep_url($str = '') +{ + if ($str == 'http://' OR $str == '') + { + return ''; + } + + if (substr($str, 0, 7) != 'http://' && substr($str, 0, 8) != 'https://') + { + $str = 'http://'.$str; + } + + return $str; +} + +// ------------------------------------------------------------------------ + +/** + * Create URL Title + * + * Takes a "title" string as input and creates a + * human-friendly URL string with either a dash + * or an underscore as the word separator. + * + * @access public + * @param string the string + * @param string the separator: dash, or underscore + * @return string + */ +function url_title($str, $separator = 'dash') +{ + if ($separator == 'dash') + { + $search = '_'; + $replace = '-'; + } + else + { + $search = '-'; + $replace = '_'; + } + + $trans = array( + $search => $replace, + "\s+" => $replace, + "[^a-z0-9".$replace."]" => '', + $replace."+" => $replace, + $replace."$" => '', + "^".$replace => '' + ); + + $str = strip_tags(strtolower($str)); + + foreach ($trans as $key => $val) + { + $str = preg_replace("#".$key."#", $val, $str); + } + + return trim(stripslashes($str)); +} + +// ------------------------------------------------------------------------ + +/** + * Header Redirect + * + * Header redirect in two flavors + * + * @access public + * @param string the URL + * @param string the method: location or redirect + * @return string + */ +function redirect($uri = '', $method = 'location') +{ + switch($method) + { + case 'refresh' : header("Refresh:0;url=".site_url($uri)); + break; + default : header("location:".site_url($uri)); + break; + } + exit; +} + +// ------------------------------------------------------------------------ + +/** + * Parse out the attributes + * + * Some of the functions use this + * + * @access private + * @param array + * @param bool + * @return string + */ +function parse_url_attributes($attributes, $javascript = FALSE) +{ + $att = ''; + foreach ($attributes as $key => $val) + { + if ($javascript == TRUE) + { + $att .= $key . '=' . $val . ','; + } + else + { + $att .= ' ' . $key . '="' . $val . '"'; + } + } + + if ($javascript == TRUE) + { + $att = substr($att, 0, -1); + } + + return $att; +} + +?> \ No newline at end of file diff --git a/system/helpers/xml_helper.php b/system/helpers/xml_helper.php new file mode 100644 index 000000000..ee3fc289b --- /dev/null +++ b/system/helpers/xml_helper.php @@ -0,0 +1,55 @@ +","\"", "'", "-"), + array("&", "<", ">", """, "'", "-"), + $str); + + $str = preg_replace("/$temp(\d+);/","&#\\1;",$str); + $str = preg_replace("/$temp(\w+);/","&\\1;", $str); + + return $str; +} + + +?> \ No newline at end of file diff --git a/system/init/index.html b/system/init/index.html new file mode 100644 index 000000000..5a1f5d6ae --- /dev/null +++ b/system/init/index.html @@ -0,0 +1,15 @@ + + + + +403 Forbidden + + + + + +

Directory access is forbidden.

+ + + + \ No newline at end of file diff --git a/system/init/init_calendar.php b/system/init/init_calendar.php new file mode 100644 index 000000000..5cf663725 --- /dev/null +++ b/system/init/init_calendar.php @@ -0,0 +1,19 @@ +calendar = new CI_Calendar(); +$obj->ci_is_loaded[] = 'calendar'; + +?> \ No newline at end of file diff --git a/system/init/init_email.php b/system/init/init_email.php new file mode 100644 index 000000000..6782310ef --- /dev/null +++ b/system/init/init_email.php @@ -0,0 +1,24 @@ +email = new CI_Email($config); +$obj->ci_is_loaded[] = 'email'; + +?> \ No newline at end of file diff --git a/system/init/init_encrypt.php b/system/init/init_encrypt.php new file mode 100644 index 000000000..5eae533ba --- /dev/null +++ b/system/init/init_encrypt.php @@ -0,0 +1,18 @@ +encrypt = new CI_Encrypt(); +$obj->ci_is_loaded[] = 'encrypt'; + +?> \ No newline at end of file diff --git a/system/init/init_image_lib.php b/system/init/init_image_lib.php new file mode 100644 index 000000000..dcd702f0d --- /dev/null +++ b/system/init/init_image_lib.php @@ -0,0 +1,24 @@ +image_lib = new CI_Image_lib($config); +$obj->ci_is_loaded[] = 'image_lib'; + +?> \ No newline at end of file diff --git a/system/init/init_pagination.php b/system/init/init_pagination.php new file mode 100644 index 000000000..3a7d9361c --- /dev/null +++ b/system/init/init_pagination.php @@ -0,0 +1,24 @@ +pagination = new CI_Pagination($config); +$obj->ci_is_loaded[] = 'pagination'; + +?> \ No newline at end of file diff --git a/system/init/init_parser.php b/system/init/init_parser.php new file mode 100644 index 000000000..17824b566 --- /dev/null +++ b/system/init/init_parser.php @@ -0,0 +1,19 @@ +parser = new CI_Parser(); +$obj->ci_is_loaded[] = 'parser'; + + +?> \ No newline at end of file diff --git a/system/init/init_session.php b/system/init/init_session.php new file mode 100644 index 000000000..cf493e53c --- /dev/null +++ b/system/init/init_session.php @@ -0,0 +1,18 @@ +session = new CI_Session(); +$obj->ci_is_loaded[] = 'session'; + +?> \ No newline at end of file diff --git a/system/init/init_trackback.php b/system/init/init_trackback.php new file mode 100644 index 000000000..6a3778bcc --- /dev/null +++ b/system/init/init_trackback.php @@ -0,0 +1,18 @@ +trackback = new CI_Trackback(); +$obj->ci_is_loaded[] = 'trackback'; + +?> \ No newline at end of file diff --git a/system/init/init_unit_test.php b/system/init/init_unit_test.php new file mode 100644 index 000000000..61d5350b6 --- /dev/null +++ b/system/init/init_unit_test.php @@ -0,0 +1,18 @@ +unit = new CI_Unit_test(); +$obj->ci_is_loaded[] = 'unit'; + +?> \ No newline at end of file diff --git a/system/init/init_upload.php b/system/init/init_upload.php new file mode 100644 index 000000000..495975c7a --- /dev/null +++ b/system/init/init_upload.php @@ -0,0 +1,24 @@ +upload = new CI_Upload($config); +$obj->ci_is_loaded[] = 'upload'; + +?> \ No newline at end of file diff --git a/system/init/init_validation.php b/system/init/init_validation.php new file mode 100644 index 000000000..a320c3e5b --- /dev/null +++ b/system/init/init_validation.php @@ -0,0 +1,18 @@ +validation = new CI_Validation(); +$obj->ci_is_loaded[] = 'validation'; + +?> \ No newline at end of file diff --git a/system/init/init_xmlrpc.php b/system/init/init_xmlrpc.php new file mode 100644 index 000000000..b75e9aad7 --- /dev/null +++ b/system/init/init_xmlrpc.php @@ -0,0 +1,24 @@ +xmlrpc = new CI_XML_RPC($config); +$obj->ci_is_loaded[] = 'xmlrpc'; + +?> \ No newline at end of file diff --git a/system/init/init_xmlrpcs.php b/system/init/init_xmlrpcs.php new file mode 100644 index 000000000..7566e3826 --- /dev/null +++ b/system/init/init_xmlrpcs.php @@ -0,0 +1,27 @@ +xmlrpc = new CI_XML_RPC(); +$obj->xmlrpcs = new CI_XML_RPC_Server($config); +$obj->ci_is_loaded[] = 'xmlrpc'; +$obj->ci_is_loaded[] = 'xmlrpcs'; + +?> \ No newline at end of file diff --git a/system/language/english/calendar_lang.php b/system/language/english/calendar_lang.php new file mode 100644 index 000000000..4a399af8b --- /dev/null +++ b/system/language/english/calendar_lang.php @@ -0,0 +1,49 @@ + \ No newline at end of file diff --git a/system/language/english/date_lang.php b/system/language/english/date_lang.php new file mode 100644 index 000000000..02ebe7386 --- /dev/null +++ b/system/language/english/date_lang.php @@ -0,0 +1,49 @@ + \ No newline at end of file diff --git a/system/language/english/db_lang.php b/system/language/english/db_lang.php new file mode 100644 index 000000000..b210b61ba --- /dev/null +++ b/system/language/english/db_lang.php @@ -0,0 +1,15 @@ + \ No newline at end of file diff --git a/system/language/english/email_lang.php b/system/language/english/email_lang.php new file mode 100644 index 000000000..430ae4ab2 --- /dev/null +++ b/system/language/english/email_lang.php @@ -0,0 +1,21 @@ + \ No newline at end of file diff --git a/system/language/english/imglib_lang.php b/system/language/english/imglib_lang.php new file mode 100644 index 000000000..68c5804a3 --- /dev/null +++ b/system/language/english/imglib_lang.php @@ -0,0 +1,21 @@ + \ No newline at end of file diff --git a/system/language/english/index.html b/system/language/english/index.html new file mode 100644 index 000000000..5a1f5d6ae --- /dev/null +++ b/system/language/english/index.html @@ -0,0 +1,15 @@ + + + + +403 Forbidden + + + + + +

Directory access is forbidden.

+ + + + \ No newline at end of file diff --git a/system/language/english/scaffolding_lang.php b/system/language/english/scaffolding_lang.php new file mode 100644 index 000000000..96fe167e5 --- /dev/null +++ b/system/language/english/scaffolding_lang.php @@ -0,0 +1,15 @@ + \ No newline at end of file diff --git a/system/language/english/unit_test_lang.php b/system/language/english/unit_test_lang.php new file mode 100644 index 000000000..b64ea6de9 --- /dev/null +++ b/system/language/english/unit_test_lang.php @@ -0,0 +1,22 @@ + \ No newline at end of file diff --git a/system/language/english/upload_lang.php b/system/language/english/upload_lang.php new file mode 100644 index 000000000..6837c8acf --- /dev/null +++ b/system/language/english/upload_lang.php @@ -0,0 +1,16 @@ + \ No newline at end of file diff --git a/system/language/english/validation_lang.php b/system/language/english/validation_lang.php new file mode 100644 index 000000000..326fe5579 --- /dev/null +++ b/system/language/english/validation_lang.php @@ -0,0 +1,15 @@ + \ No newline at end of file diff --git a/system/language/index.html b/system/language/index.html new file mode 100644 index 000000000..5a1f5d6ae --- /dev/null +++ b/system/language/index.html @@ -0,0 +1,15 @@ + + + + +403 Forbidden + + + + + +

Directory access is forbidden.

+ + + + \ No newline at end of file diff --git a/system/libraries/Benchmark.php b/system/libraries/Benchmark.php new file mode 100644 index 000000000..9dd9d4ac4 --- /dev/null +++ b/system/libraries/Benchmark.php @@ -0,0 +1,117 @@ +marker[$name] = microtime(); + } + // END mark() + + // -------------------------------------------------------------------- + + /** + * 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 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 paricular marked point + * @param string a paricular 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[$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); + } + // END elapsed_time() + + // -------------------------------------------------------------------- + + /** + * 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}'; + } + // END memory_usage() + +} + +// END CI_Benchmark class +?> \ No newline at end of file diff --git a/system/libraries/Calendar.php b/system/libraries/Calendar.php new file mode 100644 index 000000000..013f06796 --- /dev/null +++ b/system/libraries/Calendar.php @@ -0,0 +1,473 @@ +obj =& get_instance(); + if ( ! in_array('calendar_lang'.EXT, $this->obj->lang->is_loaded)) + { + $this->obj->lang->load('calendar'); + } + + $this->local_time = time(); + log_message('debug', "Calendar Class Initialized"); + } + // END CI_Calendar() + + // -------------------------------------------------------------------- + + /** + * 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; + } + } + } + // END initialize() + + // -------------------------------------------------------------------- + + /** + * 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) + { + $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; + } + // END generate() + + // -------------------------------------------------------------------- + + /** + * Get Month Name + * + * Generates a texual month name based on the numeric + * month provided. + * + * @access public + * @parm 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_novermber', '12' => 'cal_december'); + } + + $month = $month_names[$month]; + + if ($this->obj->lang->line($month) === FALSE) + { + return ucfirst(str_replace('cal_', '', $month)); + } + + return $this->obj->lang->line($month); + } + // END get_month_name() + + // -------------------------------------------------------------------- + + /** + * 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->obj->lang->line('cal_'.$val) === FALSE) ? ucfirst($val) : $this->obj->lang->line('cal_'.$val); + } + + return $days; + } + // END get_day_names() + + // -------------------------------------------------------------------- + + /** + * 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; + } + // END adjust_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; + } + + if ($month == 2) + { + if ($year % 400 == 0 OR ($year % 4 == 0 AND $year % 100 != 0)) + { + return 29; + } + } + + return $days_in_month[$month - 1]; + } + // END get_total_days() + + // -------------------------------------------------------------------- + + /** + * 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' => '
' + ); + } + // END default_template() + + // -------------------------------------------------------------------- + + /** + * 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)) + { + $this->temp[$val] = $this->temp[str_replace('_today', '', $val)]; + } + } + } + } + // END parse_template() + +} + +// END CI_Calendar class +?> \ No newline at end of file diff --git a/system/libraries/Config.php b/system/libraries/Config.php new file mode 100644 index 000000000..85b295796 --- /dev/null +++ b/system/libraries/Config.php @@ -0,0 +1,181 @@ +config =& _get_config(); + log_message('debug', "Config Class Initialized"); + } + // END CI_Config() + + + // -------------------------------------------------------------------- + + /** + * Load Config File + * + * @access public + * @param string the config file name + * @return void + */ + function load($file = '') + { + $file = ($file == '') ? 'config' : str_replace(EXT, '', $file); + + if (in_array($file, $this->is_loaded)) + { + return; + } + + include_once(APPPATH.'config/'.$file.EXT); + + if ( ! isset($config) OR ! is_array($config)) + { + show_error('Your '.$file.EXT.' file does not appear to contain a valid configuration array.'); + } + + $this->config = array_merge($this->config, $config); + + $this->is_loaded[] = $file; + unset($config); + + log_message('debug', 'Config file loaded: config/'.$file.EXT); + } + // END load() + + // -------------------------------------------------------------------- + + /** + * Fetch a config file item + * + * The second parameter allows a slash to be added to the end of + * the item, in the case of a path. + * + * @access public + * @param string the config item name + * @param bool + * @return string + */ + function item($item, $slash = FALSE) + { + if ( ! isset($this->config[$item])) + { + return FALSE; + } + + $pref = $this->config[$item]; + + if ($pref == '') + { + return $pref; + } + + if ($slash !== FALSE AND ereg("/$", $pref) === FALSE) + { + $pref .= '/'; + } + + return $pref; + } + // END item() + + // -------------------------------------------------------------------- + + /** + * Site URL + * + * @access public + * @param string the URI string + * @return string + */ + function site_url($uri = '') + { + if (is_array($uri)) + { + $uri = implode('/', $uri); + } + + if ($uri == '') + { + return $this->item('base_url', 1).$this->item('index_page'); + } + else + { + $suffix = ($this->item('url_suffix') == FALSE) ? '' : $this->item('url_suffix'); + return $this->item('base_url', 1).$this->item('index_page', 1).preg_replace("|^/*(.+?)/*$|", "\\1", $uri).$suffix; + } + } + // END site_url() + + // -------------------------------------------------------------------- + + /** + * System URL + * + * @access public + * @return string + */ + function system_url() + { + $x = explode("/", preg_replace("|/*(.+?)/*$|", "\\1", BASEPATH)); + return $this->item('base_url', 1).end($x).'/'; + } + // END system_url() + + // -------------------------------------------------------------------- + + /** + * 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; + } + // END set_item() + +} + +// END CI_Config class +?> \ No newline at end of file diff --git a/system/libraries/Controller.php b/system/libraries/Controller.php new file mode 100644 index 000000000..ec21f8d66 --- /dev/null +++ b/system/libraries/Controller.php @@ -0,0 +1,445 @@ +_ci_assign_core(); + + // Load everything specified in the autoload.php file + $this->load->_ci_autoloader($this->_ci_autoload()); + + // This allows anything loaded using $this->load (viwes, files, etc.) + // to become accessible from within the Controller class functions. + foreach ($this->ci_is_loaded as $val) + { + $this->load->$val =& $this->$val; + } + + log_message('debug', "Controller Class Initialized"); + } + // END Controller() + + // -------------------------------------------------------------------- + + /** + * Initialization Handler + * + * Looks for the existence of a handler method and calls it + * + * @access private + * @param string the item that is being loaded + * @param mixed any additional parameters + * @return void + */ + function _ci_initialize($what, $params = FALSE) + { + $method = '_ci_init_'.strtolower(str_replace(EXT, '', $what)); + + if ( ! method_exists($this, $method)) + { + $method = substr($method, 4); + + if ( ! file_exists(APPPATH.'init/'.$method.EXT)) + { + if ( ! file_exists(BASEPATH.'init/'.$method.EXT)) + { + log_message('error', "Unable to load the requested class: ".$what); + show_error("Unable to load the class: ".$what); + } + + include(BASEPATH.'init/'.$method.EXT); + } + else + { + include(APPPATH.'init/'.$method.EXT); + } + } + else + { + if ($params === FALSE) + { + $this->$method(); + } + else + { + $this->$method($params); + } + } + } + // END _ci_initialize() + + // -------------------------------------------------------------------- + + /** + * Loads and instantiates the requested model class + * + * @access private + * @param string + * @return array + */ + function _ci_load_model($model, $name = '', $db_conn = FALSE) + { + if ($name == '') + { + $name = $model; + } + + if (isset($this->$name)) + { + show_error('The model name you are loading is the name of a resource that is already being used: '.$name); + } + + $model = strtolower($model); + + if ( ! file_exists(APPPATH.'models/'.$model.EXT)) + { + show_error('Unable to locate the model you have specified: '.$model); + } + + if ($db_conn !== FALSE) + { + if ($db_conn === TRUE) + $db_conn = ''; + + $this->_ci_init_database($db_conn, FALSE, TRUE); + } + + if ( ! class_exists('Model')) + { + require_once(BASEPATH.'libraries/Model'.EXT); + } + + require_once(APPPATH.'models/'.$model.EXT); + + $model = ucfirst($model); + $this->$name = new $model(); + $this->_ci_models[] = $name; + $this->_ci_assign_to_models(); + } + // END _ci_load_model() + + + // -------------------------------------------------------------------- + + /** + * Assign to Models + * + * Makes sure that anything loaded by the loader class (libraries, plugins, etc.) + * will be available to modles, if any exist. + * + * @access public + * @param object + * @return array + */ + function _ci_assign_to_models() + { + $obj =& get_instance(); + if (count($obj->_ci_models) == 0) + { + return; + } + foreach ($obj->_ci_models as $model) + { + $obj->$model->_assign_libraries(); + } + } + // END _ci_assign_to_models() + + + // -------------------------------------------------------------------- + + /** + * Auto-initialize Core Classes + * + * This initializes the core systems that are specified in the + * libraries/autoload.php file, as well as the systems specified in + * the $autoload class array above. + * + * It returns the "autoload" array so we can pass it to the Loader + * class since it needs to autoload plugins and helper files + * + * The config/autoload.php file contains an array that permits + * sub-systems to be loaded automatically. + * + * @access private + * @return array + */ + function _ci_autoload() + { + include_once(APPPATH.'config/autoload'.EXT); + + if ( ! isset($autoload)) + { + return FALSE; + } + + if (count($autoload['config']) > 0) + { + foreach ($autoload['config'] as $key => $val) + { + $this->config->load($val); + } + } + unset($autoload['config']); + + if ( ! is_array($autoload['core'])) + { + $autoload['core'] = array($autoload['core']); + } + + foreach ($autoload['core'] as $item) + { + $this->_ci_initialize($item); + } + + return $autoload; + } + // END _ci_autoload() + + // -------------------------------------------------------------------- + + /** + * Assign the core classes to the global $CI object + * + * By assigning all the classes instantiated by the front controller + * local class variables we enable everything to be accessible using + * $this->class->function() + * + * @access private + * @return void + */ + function _ci_assign_core() + { + foreach (array('Config', 'Input', 'Benchmark', 'URI', 'Output') as $val) + { + $class = strtolower($val); + $this->$class =& _load_class('CI_'.$val); + $this->ci_is_loaded[] = $class; + } + + $this->lang =& _load_class('CI_Language'); + $this->ci_is_loaded[] = 'lang'; + + // In PHP 4 the Controller class is a child of CI_Loader. + // In PHP 5 we run it as its own class. + if (floor(phpversion()) >= 5) + { + $this->load = new CI_Loader(); + } + + $this->ci_is_loaded[] = 'load'; + } + // END _ci_assign_core() + + // -------------------------------------------------------------------- + + /** + * Initialize Scaffolding + * + * This initializing function works a bit different than the + * others. It doesn't load the class. Instead, it simply + * sets a flag indicating that scaffolding is allowed to be + * used. The actual scaffolding function below is + * called by the front controller based on whether the + * second segment of the URL matches the "secret" scaffolding + * word stored in the application/config/routes.php + * + * @access private + * @param string the table to scaffold + * @return void + */ + function _ci_init_scaffolding($table = FALSE) + { + if ($table === FALSE) + { + show_error('You must include the name of the table you would like access when you initialize scaffolding'); + } + + $this->_ci_scaffolding = TRUE; + $this->_ci_scaff_table = $table; + } + // END _ci_init_scaffolding() + + // -------------------------------------------------------------------- + + /** + * Initialize Database + * + * @access private + * @param mixed database connection values + * @param bool whether to return the object for multiple connections + * @return void + */ + function _ci_init_database($params = '', $return = FALSE, $active_record = FALSE) + { + if ($this->_ci_is_loaded('db') == TRUE AND $return == FALSE AND $active_record == FALSE) + { + return; + } + + // Load the DB config file if needed + if (is_string($params) AND strpos($params, '://') === FALSE) + { + include(APPPATH.'config/database'.EXT); + + $group = ($params == '') ? $active_group : $params; + + if ( ! isset($db[$group])) + { + show_error('You have specified an invalid database connection group: '.$group); + } + + $params = $db[$group]; + } + + // 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 == TRUE) + { + $params['active_r'] = TRUE; + } + + require_once(BASEPATH.'drivers/DB_driver'.EXT); + + if ( ! isset($params['active_r']) OR $params['active_r'] == TRUE) + { + require_once(BASEPATH.'drivers/DB_active_record'.EXT); + + 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.'drivers/DB_'.$params['dbdriver'].EXT); + + // Instantiate the DB adapter + $driver = 'CI_DB_'. $params['dbdriver']; + $DB = new $driver($params); + + if ($return === TRUE) + { + return $DB; + } + + $obj =& get_instance(); + $obj->ci_is_loaded[] = 'db'; + $obj->db =& $DB; + } + // END _ci_init_database() + + // -------------------------------------------------------------------- + + /** + * Returns TRUE if a class is loaded, FALSE if not + * + * @access public + * @param string the class name + * @return bool + */ + function _ci_is_loaded($class) + { + return ( ! in_array($class, $this->ci_is_loaded)) ? FALSE : TRUE; + } + // END _ci_is_loaded() + + // -------------------------------------------------------------------- + + /** + * Scaffolding + * + * Initializes the scaffolding. + * + * @access private + * @return void + */ + function _ci_scaffolding() + { + if ($this->_ci_scaffolding === FALSE OR $this->_ci_scaff_table === FALSE) + { + show_404('Scaffolding unavailable'); + } + + if (class_exists('Scaffolding')) return; + + if ( ! in_array($this->uri->segment(3), array('add', 'insert', 'edit', 'update', 'view', 'delete', 'do_delete'))) + { + $method = 'view'; + } + else + { + $method = $this->uri->segment(3); + } + + $this->_ci_init_database("", FALSE, TRUE); + + $this->_ci_initialize('pagination'); + require_once(BASEPATH.'scaffolding/Scaffolding'.EXT); + $this->scaff = new Scaffolding($this->_ci_scaff_table); + $this->scaff->$method(); + } + // END _ci_scaffolding() + +} +// END _Controller class +?> \ No newline at end of file diff --git a/system/libraries/Email.php b/system/libraries/Email.php new file mode 100644 index 000000000..96dc0014d --- /dev/null +++ b/system/libraries/Email.php @@ -0,0 +1,1740 @@ + 0) + { + $this->initialize($config); + } + + log_message('debug', "Email Class Initialized"); + } + // END CI_Email() + + // -------------------------------------------------------------------- + + /** + * Initialize preferences + * + * @access public + * @param array + * @return void + */ + function initialize($config = array()) + { + $this->clear(); + 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->_smtp_auth = ($this->smtp_user == '' AND $this->smtp_pass == '') ? FALSE : TRUE; + $this->_safe_mode = (@ini_get("safe_mode") == 0) ? FALSE : TRUE; + } + // END initialize() + + // -------------------------------------------------------------------- + + /** + * Initialize the Email Data + * + * @access public + * @return void + */ + function clear() + { + $this->_subject = ""; + $this->_body = ""; + $this->_finalbody = ""; + $this->_header_str = ""; + $this->_replyto_flag = FALSE; + $this->_recipients = array(); + $this->_headers = array(); + $this->_debug_msg = array(); + + $this->_set_header('User-Agent', $this->useragent); + $this->_set_header('Date', $this->_set_date()); + } + // END clear() + + // -------------------------------------------------------------------- + + /** + * Set FROM + * + * @access public + * @param string + * @param string + * @return void + */ + function from($from, $name = '') + { + if (preg_match( '/\<(.*)\>/', $from, $match)) + $from = $match['1']; + + if ($this->validate) + $this->validate_email($this->_str_to_array($from)); + + if ($name != '' && substr($name, 0, 1) != '"') + { + $name = '"'.$name.'"'; + } + + $this->_set_header('From', $name.' <'.$from.'>'); + $this->_set_header('Return-Path', '<'.$from.'>'); + } + // END from() + + // -------------------------------------------------------------------- + + /** + * Set Reply-to + * + * @access public + * @param string + * @param string + * @return void + */ + 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 (substr($name, 0, 1) != '"') + { + $name = '"'.$name.'"'; + } + + $this->_set_header('Reply-To', $name.' <'.$replyto.'>'); + $this->_replyto_flag = TRUE; + } + // END reply_to() + + // -------------------------------------------------------------------- + + /** + * Set Recipients + * + * @access public + * @param string + * @return void + */ + 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' : $this->_recipients = implode(", ", $to); + break; + case 'mail' : $this->_recipients = implode(", ", $to); + break; + } + } + // END to() + + // -------------------------------------------------------------------- + + /** + * Set CC + * + * @access public + * @param string + * @return void + */ + 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; + } + // END cc() + + // -------------------------------------------------------------------- + + /** + * Set BCC + * + * @access public + * @param string + * @param string + * @return void + */ + function bcc($bcc, $limit = '') + { + if ($limit != '' && ctype_digit($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)); + } + // END bcc() + + // -------------------------------------------------------------------- + + /** + * Set Email Subject + * + * @access public + * @param string + * @return void + */ + function subject($subject) + { + $subject = preg_replace("/(\r\n)|(\r)|(\n)/", "", $subject); + $subject = preg_replace("/(\t)/", " ", $subject); + + $this->_set_header('Subject', trim($subject)); + } + // END subject() + + // -------------------------------------------------------------------- + + /** + * Set Body + * + * @access public + * @param string + * @return void + */ + function message($body) + { + $body = rtrim(str_replace("\r", "", $body)); + + if ($this->wordwrap === TRUE AND $this->mailtype != 'html') + $this->_body = $this->word_wrap($body); + else + $this->_body = $body; + + $this->_body = stripslashes($this->_body); + } + // END message() + + // -------------------------------------------------------------------- + + /** + * Assign file attachments + * + * @access public + * @param string + * @return string + */ + function attach($filename, $disposition = 'attachment') + { + $this->_attach_name[] = $filename; + $this->_attach_type[] = $this->_mime_types(next(explode('.', basename($filename)))); + $this->_attach_disp[] = $disposition; // Can also be 'inline' Not sure if it matters + } + // END attach() + + // -------------------------------------------------------------------- + + /** + * Add a Header Item + * + * @access public + * @param string + * @param string + * @return void + */ + function _set_header($header, $value) + { + $this->_headers[$header] = $value; + } + // END _set_header() + + // -------------------------------------------------------------------- + + /** + * Convert a String to an Array + * + * @access public + * @param string + * @return array + */ + function _str_to_array($email) + { + if ( ! is_array($email)) + { + if (ereg(',$', $email)) + $email = substr($email, 0, -1); + + if (ereg('^,', $email)) + $email = substr($email, 1); + + if (ereg(',', $email)) + { + $x = explode(',', $email); + $email = array(); + + for ($i = 0; $i < count($x); $i ++) + $email[] = trim($x[$i]); + } + else + { + $email = trim($email); + settype($email, "array"); + } + } + return $email; + } + // END _str_to_array() + + // -------------------------------------------------------------------- + + /** + * Set Multipart Value + * + * @access public + * @param string + * @return void + */ + function set_alt_message($str = '') + { + $this->alt_message = ($str == '') ? '' : $str; + } + // END set_alt_message() + + // -------------------------------------------------------------------- + + /** + * Set Mailtype + * + * @access public + * @param string + * @return void + */ + function set_mailtype($type = 'text') + { + $this->mailtype = ($type == 'html') ? 'html' : 'text'; + } + // END set_mailtype() + + // -------------------------------------------------------------------- + + /** + * Set Wordwrap + * + * @access public + * @param string + * @return void + */ + function set_wordwrap($wordwrap = TRUE) + { + $this->wordwrap = ($wordwrap === FALSE) ? FALSE : TRUE; + } + // END set_wordwrap() + + // -------------------------------------------------------------------- + + /** + * Set Protocal + * + * @access public + * @param string + * @return void + */ + function set_protocol($protocol = 'mail') + { + $this->protocol = ( ! in_array($protocol, $this->_protocols)) ? 'mail' : strtolower($protocol); + } + // END set_protocol() + + // -------------------------------------------------------------------- + + /** + * Set Priority + * + * @access public + * @param integer + * @return void + */ + function set_priority($n = 3) + { + if ( ! ctype_digit($n)) + { + $this->priority = 3; + return; + } + + if ($n < 1 OR $n > 5) + { + $this->priority = 3; + return; + } + + $this->priority = $n; + } + // END set_priority() + + // -------------------------------------------------------------------- + + /** + * Set Newline Character + * + * @access public + * @param string + * @return void + */ + function set_newline($newline = "\n") + { + if ($newline != "\n" OR $newline != "\r\n" OR $newline != "\r") + { + $this->newline = "\n"; + return; + } + + $this->newline = $newline; + } + // END set_newline() + + // -------------------------------------------------------------------- + + /** + * Set Message Boundry + * + * @access private + * @return void + */ + function _set_boundaries() + { + $this->_alt_boundary = "B_ALT_".uniqid(''); // mulipart/alternative + $this->_atc_boundary = "B_ATC_".uniqid(''); // attachment boundary + } + // END _set_boundaries() + + // -------------------------------------------------------------------- + + /** + * Get the Message ID + * + * @access private + * @return string + */ + function _get_message_id() + { + $from = $this->_headers['Return-Path']; + $from = str_replace(">", "", $from); + $from = str_replace("<", "", $from); + + return "<".uniqid('').strstr($from, '@').">"; + } + // END _get_message_id() + + // -------------------------------------------------------------------- + + /** + * Get Mail Protocol + * + * @access private + * @param bool + * @return string + */ + function _get_protocol($return = true) + { + $this->protocol = strtolower($this->protocol); + $this->protocol = ( ! in_array($this->protocol, $this->_protocols)) ? 'mail' : $this->protocol; + + if ($return == true) + return $this->protocol; + } + // END _get_protocol() + + // -------------------------------------------------------------------- + + /** + * Get Mail Encoding + * + * @access private + * @param bool + * @return string + */ + function _get_encoding($return = true) + { + $this->_encoding = ( ! in_array($this->_encoding, $this->_bit_depths)) ? '7bit' : $this->_encoding; + + if ( ! in_array($this->charset, $this->_base_charsets)) + $this->_encoding = "8bit"; + + if ($return == true) + return $this->_encoding; + } + // END _get_encoding() + + // -------------------------------------------------------------------- + + /** + * Get content type (text/html/attachment) + * + * @access private + * @return string + */ + 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'; + } + // END _get_content_type() + + // -------------------------------------------------------------------- + + /** + * Set RFC 822 Date + * + * @access public + * @return string + */ + function _set_date() + { + $timezone = date("Z"); + $operator = (substr($timezone, 0, 1) == '-') ? '-' : '+'; + $timezone = abs($timezone); + $timezone = ($timezone/3600) * 100 + ($timezone % 3600) /60; + + return sprintf("%s %s%04d", date("D, j M Y H:i:s"), $operator, $timezone); + } + // END _set_date() + + // -------------------------------------------------------------------- + + /** + * Mime message + * + * @access private + * @return string + */ + function _get_mime_message() + { + return "This is a multi-part message in MIME format.".$this->newline."Your email application may not support this format."; + } + // END _get_mime_message() + + // -------------------------------------------------------------------- + + /** + * Validate Email Address + * + * @access public + * @param string + * @return bool + */ + function validate_email($email) + { + if ( ! is_array($email)) + { + $this->_set_error_message('email_must_be_array'); + return FALSE; + } + + foreach ($email as $val) + { + if ( ! $this->valid_email($val)) + { + $this->_set_error_message('email_invalid_address', $val); + return FALSE; + } + } + } + // END validate_email() + + // -------------------------------------------------------------------- + + /** + * Email Validation + * + * @access public + * @param string + * @return bool + */ + function valid_email($address) + { + if ( ! preg_match("/^([a-z0-9\+_\-]+)(\.[a-z0-9\+_\-]+)*@([a-z0-9\-]+\.)+[a-z]{2,6}$/ix", $address)) + return FALSE; + else + return TRUE; + } + // END valid_email() + + // -------------------------------------------------------------------- + + /** + * Clean Extended Email Address: Joe Smith + * + * @access public + * @param string + * @return string + */ + function clean_email($email) + { + if ( ! is_array($email)) + { + if (preg_match('/\<(.*)\>/', $email, $match)) + return $match['1']; + else + return $email; + } + + $clean_email = array(); + + for ($i=0; $i < count($email); $i++) + { + if (preg_match( '/\<(.*)\>/', $email[$i], $match)) + $clean_email[] = $match['1']; + else + $clean_email[] = $email[$i]; + } + + return $clean_email; + } + // END clean_email() + + // -------------------------------------------------------------------- + + /** + * Build alternative plain text message + * + * This 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 private + * @return string + */ + function _get_alt_message() + { + if (eregi( '\', $this->_body, $match)) + { + $body = $match['1']; + $body = substr($body, strpos($body, ">") + 1); + } + else + { + $body = $this->_body; + } + + $body = trim(strip_tags($body)); + $body = preg_replace( '# '.$message. ' '.$filepath.' '.$line, TRUE); + } + // END log_exception() + + // -------------------------------------------------------------------- + + /** + * 404 Page Not Found Handler + * + * @access private + * @param string + * @return string + */ + function show_404($page = '') + { + $heading = "404 Page Not Found"; + $message = "The page you requested was not found."; + + log_message('error', '404 Page Not Found --> '.$page); + echo $this->show_error($heading, $message, 'error_404'); + exit; + } + // END show_404() + + // -------------------------------------------------------------------- + + /** + * General Error Page + * + * This function takes an error message as input + * (either as a string or an array) and displayes + * it using the specified template. + * + * @access private + * @param string the heading + * @param string the message + * @param string the template name + * @return string + */ + function show_error($heading, $message, $template = 'error_general') + { + $message = '

'.implode('

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

'; + + ob_start(); + include_once(APPPATH.'errors/'.$template.EXT); + $buffer = ob_get_contents(); + ob_end_clean(); + return $buffer; + } + // END show_error() + + + // -------------------------------------------------------------------- + + /** + * 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); + } + + ob_start(); + include_once(APPPATH.'errors/error_php'.EXT); + $buffer = ob_get_contents(); + ob_end_clean(); + echo $buffer; + } + // END show_php_error() + +// END Exceptions Class +} +?> \ No newline at end of file diff --git a/system/libraries/Hooks.php b/system/libraries/Hooks.php new file mode 100644 index 000000000..389e7ac14 --- /dev/null +++ b/system/libraries/Hooks.php @@ -0,0 +1,237 @@ +item('enable_hooks') == FALSE) + { + return; + } + + // Grab the "hooks" definition file. + // If there are no hooks, we're done. + + @include(APPPATH.'config/hooks'.EXT); + + if ( ! isset($hook) OR ! is_array($hook)) + { + return; + } + + $this->hooks =& $hook; + $this->enabled = TRUE; + } + // END CI_Hooks() + + // -------------------------------------------------------------------- + + /** + * Does a given hook exist? + * + * Returns TRUE/FALSE based on whether a given hook exists + * + * @access private + * @param string + * @return bool + */ + function _hook_exists($which = '') + { + if ( ! $this->enabled) + { + return FALSE; + } + + if ( ! isset($this->hooks[$which])) + { + return FALSE; + } + + return TRUE; + } + // END hook_exists() + + + // -------------------------------------------------------------------- + + /** + * Call Hook + * + * Calls a particular hook + * + * @access private + * @param string the hook name + * @return mixed + */ + function _call_hook($which = '') + { + 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]); + } + } + // END hook_exists() + + // -------------------------------------------------------------------- + + /** + * 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 + // extension 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; + } + // END _run_hook() + + +} + +// END CI_Hooks class +?> \ No newline at end of file diff --git a/system/libraries/Image_lib.php b/system/libraries/Image_lib.php new file mode 100644 index 000000000..854f0484b --- /dev/null +++ b/system/libraries/Image_lib.php @@ -0,0 +1,1550 @@ + 0) + { + $this->initialize($props); + } + + log_message('debug', "Image Lib Class Initialized"); + } + // END CI_Image_lib() + + // -------------------------------------------------------------------- + + /** + * Initialize image properties + * + * Resets values in case this class is used in a loop + * + * @access public + * @return void + */ + function clear() + { + $props = array('source_folder', 'dest_folder', 'source_image', 'full_src_path', 'full_dst_path', 'new_image', 'image_type', 'size_str', 'quality', 'orig_width', 'orig_height', 'rotation_angle', 'x_axis', 'y_axis', 'create_fnc', 'copy_fnc', 'wm_overlay_path', 'wm_use_truetype', 'dynamic_output', 'wm_font_size', 'wm_text', 'wm_vrt_alignment', 'wm_hor_alignment', 'wm_padding', 'wm_hor_offset', 'wm_vrt_offset', 'wm_font_color', 'wm_use_drop_shadow', 'wm_shadow_color', 'wm_shadow_distance', 'wm_opacity'); + + foreach ($props as $val) + { + $this->$val = ''; + } + } + // END clear() + + // -------------------------------------------------------------------- + + /** + * initialize image preferences + * + * @access public + * @param array + * @return void + */ + function initialize($props = array()) + { + /* + * Convert array elements into class variables + */ + if (count($props) > 0) + { + foreach ($props as $key => $val) + { + $this->$key = $val; + } + } + + /* + * Is there a source image? + * + * If not, there's no reason to continue + * + */ + if ($this->source_image == '') + { + $this->set_error('imglib_source_image_required'); + return FALSE; + } + /* + * Is getimagesize() Available? + * + * We use it to determine the image properties (width/height). + * Note: We need to figure out how to determine image + * properties using ImageMagick and NetPBM + * + */ + if ( ! function_exists('getimagesize')) + { + $this->set_error('imglib_gd_required_for_props'); + return FALSE; + } + + $this->image_library = strtolower($this->image_library); + + /* + * Set the full server path + * + * The source image may or may not contain a path. + * Either way, we'll try use realpath to generate the + * full server path in order to more reliably read it. + * + */ + if (function_exists('realpath') AND @realpath($this->source_image) !== FALSE) + { + $full_source_path = str_replace("\\", "/", realpath($this->source_image)); + } + else + { + $full_source_path = $this->source_image; + } + + $x = explode('/', $full_source_path); + $this->source_image = end($x); + $this->source_folder = str_replace($this->source_image, '', $full_source_path); + + // Set the Image Propterties + if ( ! $this->get_image_properties($this->source_folder.$this->source_image)) + { + return FALSE; + } + + /* + * Assign the "new" image name/path + * + * If the user has set a "new_image" name it means + * we are making a copy of the source image. If not + * it means we are altering the original. We'll + * set the destination filename and path accordingly. + * + */ + if ($this->new_image == '') + { + $this->dest_image = $this->source_image; + $this->dest_folder = $this->source_folder; + } + else + { + if (strpos($this->new_image, '/') === FALSE) + { + $this->dest_folder = $this->source_folder; + $this->dest_image = $this->new_image; + } + else + { + if (function_exists('realpath') AND @realpath($this->new_image) !== FALSE) + { + $full_dest_path = str_replace("\\", "/", realpath($this->new_image)); + } + else + { + $full_dest_path = $this->new_image; + } + + // Is there a file name? + if ( ! preg_match("#[\.jpg|\.jpeg|\.gif|\.png]$#i", $full_dest_path)) + { + $this->dest_folder = $full_dest_path.'/'; + $this->dest_image = $this->source_image; + } + else + { + $x = explode('/', $full_dest_path); + $this->dest_image = end($x); + $this->dest_folder = str_replace($this->dest_image, '', $full_dest_path); + } + } + } + + /* + * Compile the finalized filenames/paths + * + * We'll create two master strings containing the + * full server path to the source image and the + * full server path to the destination image. + * We'll also split the destination image name + * so we can insert the thumbnail marker if needed. + * + */ + if ($this->create_thumb === FALSE OR $this->thumb_marker == '') + { + $this->thumb_marker = ''; + } + + $xp = $this->explode_name($this->dest_image); + + $filename = $xp['name']; + $file_ext = $xp['ext']; + + $this->full_src_path = $this->source_folder.$this->source_image; + $this->full_dst_path = $this->dest_folder.$filename.$this->thumb_marker.$file_ext; + + /* + * Should we maintain image proportions? + * + * When creating thumbs or copies, the target width/height + * might not be in correct proportion with the source + * image's width/height. We'll recalculate it here. + * + */ + if ($this->maintain_ratio === TRUE && ($this->width != '' AND $this->height != '')) + { + $this->image_reproportion(); + } + + /* + * Was a width and height specified? + * + * If the destination width/height was + * not submitted we will use the values + * from the actual file + * + */ + if ($this->width == '') + $this->width = $this->orig_width; + + if ($this->height == '') + $this->height = $this->orig_height; + + // Set the quality + $this->quality = trim(str_replace("%", "", $this->quality)); + + if ($this->quality == '' OR $this->quality == 0 OR ! ctype_digit($this->quality)) + $this->quality = 90; + + // Set the x/y coordinates + $this->x_axis = ($this->x_axis == '' OR ! is_numeric($this->x_axis)) ? 0 : $this->x_axis; + $this->y_axis = ($this->y_axis == '' OR ! is_numeric($this->y_axis)) ? 0 : $this->y_axis; + + // Watermark-related Stuff... + if ($this->wm_font_color != '') + { + if (strlen($this->wm_font_color) == 6) + { + $this->wm_font_color = '#'.$this->wm_font_color; + } + } + + if ($this->wm_shadow_color != '') + { + if (strlen($this->wm_shadow_color) == 6) + { + $this->wm_shadow_color = '#'.$this->wm_shadow_color; + } + } + + if ($this->wm_overlay_path != '') + { + $this->wm_overlay_path = str_replace("\\", "/", realpath($this->wm_overlay_path)); + } + + if ($this->wm_shadow_color != '') + { + $this->wm_use_drop_shadow = TRUE; + } + + if ($this->wm_font_path != '') + { + $this->wm_use_truetype = TRUE; + } + + return TRUE; + } + // END initialize() + + // -------------------------------------------------------------------- + + /** + * Image Resize + * + * This is a wrapper function that chooses the proper + * resize function based on the protocol specified + * + * @access public + * @return bool + */ + function resize() + { + $protocol = 'image_process_'.$this->image_library; + + if (eregi("gd2$", $protocol)) + { + $protocol = 'image_process_gd'; + } + + return $this->$protocol('resize'); + } + // END resize() + + // -------------------------------------------------------------------- + + /** + * Image Crop + * + * This is a wrapper function that chooses the proper + * cropping function based on the protocol specified + * + * @access public + * @return bool + */ + function crop() + { + $protocol = 'image_process_'.$this->image_library; + + if (eregi("gd2$", $protocol)) + { + $protocol = 'image_process_gd'; + } + + return $this->$protocol('crop'); + } + // END crop() + + // -------------------------------------------------------------------- + + /** + * Image Rotate + * + * This is a wrapper function that chooses the proper + * rotation function based on the protocol specified + * + * @access public + * @return bool + */ + function rotate() + { + // Allowed rotation values + $degs = array(90, 180, 270, 'vrt', 'hor'); + + if ($this->rotation_angle == '' OR ! in_array($this->rotation_angle, $degs)) + { + $this->set_error('imglib_rotation_angle_required'); + return FALSE; + } + + // Reassign the width and height + if ($this->rotation_angle == 90 OR $this->rotation_angle == 270) + { + $this->width = $this->orig_height; + $this->height = $this->orig_width; + } + else + { + $this->width = $this->orig_width; + $this->height = $this->orig_height; + } + + + // Choose resizing function + if ($this->image_library == 'imagemagick' OR $this->image_library == 'netpbm') + { + $protocol = 'image_process_'.$this->image_library; + + return $this->$protocol('rotate'); + } + + if ($this->rotation_angle == 'hor' OR $this->rotation_angle == 'vrt') + { + return $this->image_mirror_gd(); + } + else + { + return $this->image_rotate_gd(); + } + } + // END rotate() + + // -------------------------------------------------------------------- + + /** + * Image Process Using GD/GD2 + * + * This function will resize or crop + * + * @access public + * @param string + * @return bool + */ + function image_process_gd($action = 'resize') + { + $v2_override = FALSE; + + if ($action == 'crop') + { + // If the target width/height match the source then it's pointless to crop, right? + if ($this->width >= $this->orig_width AND $this->height >= $this->orig_width) + { + // We'll return true so the user thinks the process succeeded. + // It'll be our little secret... + + return TRUE; + } + + // Reassign the source width/height if cropping + $this->orig_width = $this->width; + $this->orig_height = $this->height; + + // GD 2.0 has a cropping bug so we'll test for it + if ($this->gd_version() !== FALSE) + { + $gd_version = str_replace('0', '', $this->gd_version()); + $v2_override = ($gd_version == 2) ? TRUE : FALSE; + } + } + else + { + // If the target width/height match the source, AND if + // the new file name is not equal to the old file name + // we'll simply make a copy of the original with the new name + if (($this->orig_width == $this->width AND $this->orig_height == $this->height) AND ($this->source_image != $this->dest_image)) + { + if ( ! @copy($this->full_src_path, $this->full_dst_path)) + { + $this->set_error('imglib_copy_failed'); + return FALSE; + } + + @chmod($this->full_dst_path, 0777); + return TRUE; + } + + // If resizing the x/y axis must be zero + $this->x_axis = 0; + $this->y_axis = 0; + } + + // Create the image handle + if ( ! ($src_img = $this->image_create_gd())) + { + return FALSE; + } + + // Create The Image + if ($this->image_library == 'gd2' AND function_exists('imagecreatetruecolor') AND $v2_override == FALSE) + { + $create = 'imagecreatetruecolor'; + $copy = 'imagecopyresampled'; + } + else + { + $create = 'imagecreate'; + $copy = 'imagecopyresized'; + } + + $dst_img = $create($this->width, $this->height); + $copy($dst_img, $src_img, 0, 0, $this->x_axis, $this->y_axis, $this->width, $this->height, $this->orig_width, $this->orig_height); + + // Show the image + if ($this->dynamic_output == TRUE) + { + $this->image_display_gd($dst_img); + } + else + { + // Or save it + if ( ! $this->image_save_gd($dst_img)) + { + return FALSE; + } + } + + // Kill the file handles + imagedestroy($dst_img); + imagedestroy($src_img); + + // Set the file to 777 + @chmod($this->full_dst_path, 0777); + + return TRUE; + } + // END image_process_gd() + + // -------------------------------------------------------------------- + + /** + * Image Process Using ImageMagick + * + * This function will resize, crop or rotate + * + * @access public + * @param string + * @return bool + */ + function image_process_imagemagick($action = 'resize') + { + // Do we have a vaild library path? + if ($this->library_path == '') + { + $this->set_error('imglib_libpath_invalid'); + return FALSE; + } + + if ( ! eregi("convert$", $this->library_path)) + { + if ( ! eregi("/$", $this->library_path)) $this->library_path .= "/"; + + $this->library_path .= 'convert'; + } + + // Execute the command + $cmd = $this->library_path." -quality ".$this->quality; + + if ($action == 'crop') + { + $cmd .= " -crop ".$this->width."x".$this->height."+".$this->x_axis."+".$this->y_axis." \"$this->full_src_path\" \"$this->full_dst_path\" 2>&1"; + } + elseif ($action == 'rotate') + { + switch ($this->rotation_angle) + { + case 'hor' : $angle = '-flop'; + break; + case 'vrt' : $angle = '-flip'; + break; + default : $angle = '-rotate '.$this->rotation_angle; + break; + } + + $cmd .= " ".$angle." \"$this->full_src_path\" \"$this->full_dst_path\" 2>&1"; + } + else // Resize + { + $cmd .= " -resize ".$this->width."x".$this->height." \"$this->full_src_path\" \"$this->full_dst_path\" 2>&1"; + } + + $retval = 1; + + @exec($cmd, $output, $retval); + + // Did it work? + if ($retval > 0) + { + $this->set_error('imglib_image_process_failed'); + return FALSE; + } + + // Set the file to 777 + @chmod($this->full_dst_path, 0777); + + return TRUE; + } + // END image_process_imagemagick() + + // -------------------------------------------------------------------- + + /** + * Image Process Using NetPBM + * + * This function will resize, crop or rotate + * + * @access public + * @param string + * @return bool + */ + function image_process_netpbm($action = 'resize') + { + if ($this->library_path == '') + { + $this->set_error('imglib_libpath_invalid'); + return FALSE; + } + + // Build the resizing command + switch ($this->image_type) + { + case 1 : + $cmd_in = 'giftopnm'; + $cmd_out = 'ppmtogif'; + break; + case 2 : + $cmd_in = 'jpegtopnm'; + $cmd_out = 'ppmtojpeg'; + break; + case 3 : + $cmd_in = 'pngtopnm'; + $cmd_out = 'ppmtopng'; + break; + } + + if ($action == 'crop') + { + $cmd_inner = 'pnmcut -left '.$this->x_axis.' -top '.$this->y_axis.' -width '.$this->width.' -height '.$this->height; + } + elseif ($action == 'rotate') + { + switch ($this->rotation_angle) + { + case 90 : $angle = 'r270'; + break; + case 180 : $angle = 'r180'; + break; + case 270 : $angle = 'r90'; + break; + case 'vrt' : $angle = 'tb'; + break; + case 'hor' : $angle = 'lr'; + break; + } + + $cmd_inner = 'pnmflip -'.$angle.' '; + } + else // Resize + { + $cmd_inner = 'pnmscale -xysize '.$this->width.' '.$this->height; + } + + $cmd = $this->library_path.$cmd_in.' '.$this->full_src_path.' | '.$cmd_inner.' | '.$cmd_out.' > '.$this->dest_folder.'netpbm.tmp'; + + $retval = 1; + + @exec($cmd, $output, $retval); + + // Did it work? + if ($retval > 0) + { + $this->set_error('imglib_image_process_failed'); + return FALSE; + } + + // With NetPBM we have to create a temporary image. + // If you try manipulating the original it fails so + // we have to rename the temp file. + copy ($this->dest_folder.'netpbm.tmp', $this->full_dst_path); + unlink ($this->dest_folder.'netpbm.tmp'); + @chmod($dst_image, 0777); + + return TRUE; + } + // END image_process_netpbm() + + // -------------------------------------------------------------------- + + /** + * Image Rotate Using GD + * + * @access public + * @return bool + */ + function image_rotate_gd() + { + // Is Image Rotation Supported? + // this function is only supported as of PHP 4.3 + if ( ! function_exists('imagerotate')) + { + $this->set_error('imglib_rotate_unsupported'); + return FALSE; + } + + // Create the image handle + if ( ! ($src_img = $this->image_create_gd())) + { + return FALSE; + } + + // Set the background color + // This won't work with transparent PNG files so we are + // going to have to figure out how to determine the color + // of the alpha channel in a future release. + + $white = imagecolorallocate($src_img, 255, 255, 255); + + // Rotate it! + $dst_img = imagerotate($src_img, $this->rotation_angle, $white); + + // Save the Image + if ($this->dynamic_output == TRUE) + { + $this->image_display_gd($dst_img); + } + else + { + // Or save it + if ( ! $this->image_save_gd($dst_img)) + { + return FALSE; + } + } + + // Kill the file handles + imagedestroy($dst_img); + imagedestroy($src_img); + + // Set the file to 777 + + @chmod($this->full_dst_path, 0777); + + return true; + } + // END image_rotate_gd() + + // -------------------------------------------------------------------- + + /** + * Create Mirror Image using GD + * + * This function will flip horizontal or vertical + * + * @access public + * @return bool + */ + function image_mirror_gd() + { + if ( ! $src_img = $this->image_create_gd()) + { + return FALSE; + } + + $width = $this->orig_width; + $height = $this->orig_height; + + if ($this->rotation_angle == 'hor') + { + for ($i = 0; $i < $height; $i++) + { + $left = 0; + $right = $width-1; + + while ($left < $right) + { + $cl = imagecolorat($src_img, $left, $i); + $cr = imagecolorat($src_img, $right, $i); + + imagesetpixel($src_img, $left, $i, $cr); + imagesetpixel($src_img, $right, $i, $cl); + + $left++; + $right--; + } + } + } + else + { + for ($i = 0; $i < $width; $i++) + { + $top = 0; + $bot = $height-1; + + while ($top < $bot) + { + $ct = imagecolorat($src_img, $i, $top); + $cb = imagecolorat($src_img, $i, $bot); + + imagesetpixel($src_img, $i, $top, $cb); + imagesetpixel($src_img, $i, $bot, $ct); + + $top++; + $bot--; + } + } + } + + // Show the image + if ($this->dynamic_output == TRUE) + { + $this->image_display_gd($src_img); + } + else + { + // Or save it + if ( ! $this->image_save_gd($src_img)) + { + return FALSE; + } + } + + // Kill the file handles + imagedestroy($src_img); + + // Set the file to 777 + @chmod($this->full_dst_path, 0777); + + return TRUE; + } + // END image_mirror_gd() + + // -------------------------------------------------------------------- + + /** + * Image Watermark + * + * This is a wrapper function that chooses the type + * of watermarking based on the specified preference. + * + * @access public + * @param string + * @return bool + */ + function watermark() + { + if ($this->wm_type == 'overlay') + { + return $this->overlay_watermark(); + } + else + { + return $this->text_watermark(); + } + } + // END image_mirror_gd() + + // -------------------------------------------------------------------- + + /** + * Watermark - Graphic Version + * + * @access public + * @return bool + */ + function overlay_watermark() + { + if ( ! function_exists('imagecolortransparent')) + { + $this->set_error('imglib_gd_required'); + return FALSE; + } + + // Fetch source image properties + $this->get_image_properties(); + + // Fetch watermark image properties + $props = $this->get_image_properties($this->wm_overlay_path, TRUE); + $wm_img_type = $props['image_type']; + $wm_width = $props['width']; + $wm_height = $props['height']; + + // Create two image resources + $wm_img = $this->image_create_gd($this->wm_overlay_path, $wm_img_type); + $src_img = $this->image_create_gd($this->full_src_path); + + // Reverse the offset if necessary + // When the image is positioned at the bottom + // we don't want the vertical offset to push it + // further down. We want the reverse, so we'll + // invert the offset. Same with the horizontal + // offset when the image is at the right + + $this->wm_vrt_alignment = strtoupper(substr($this->wm_vrt_alignment, 0, 1)); + $this->wm_hor_alignment = strtoupper(substr($this->wm_hor_alignment, 0, 1)); + + if ($this->wm_vrt_alignment == 'B') + $this->wm_vrt_offset = $this->wm_vrt_offset * -1; + + if ($this->wm_hor_alignment == 'R') + $this->wm_hor_offset = $this->wm_hor_offset * -1; + + // Set the base x and y axis values + $x_axis = $this->wm_hor_offset + $this->wm_padding; + $y_axis = $this->wm_vrt_offset + $this->wm_padding; + + // Set the vertical position + switch ($this->wm_vrt_alignment) + { + case 'T': + break; + case 'M': $y_axis += ($this->orig_height / 2) - ($wm_height / 2); + break; + case 'B': $y_axis += $this->orig_height - $wm_height; + break; + } + + // Set the horizontal position + switch ($this->wm_hor_alignment) + { + case 'L': + break; + case 'C': $x_axis += ($this->orig_width / 2) - ($wm_width / 2); + break; + case 'R': $x_axis += $this->orig_width - $wm_width; + break; + } + + // Build the finalized image + if ($wm_img_type == 3 AND function_exists('imagealphablending')) + { + @imagealphablending($src_img, TRUE); + } + + // Set RGB values for text and shadow + imagecolortransparent($wm_img, imagecolorat($wm_img, $this->wm_x_transp, $this->wm_y_transp)); + imagecopymerge($src_img, $wm_img, $x_axis, $y_axis, 0, 0, $wm_width, $wm_height, $this->wm_opacity); + + // Output the image + if ($this->dynamic_output == TRUE) + { + $this->image_display_gd($src_img); + } + else + { + if ( ! $this->image_save_gd($src_img)) + { + return FALSE; + } + } + + imagedestroy($src_img); + imagedestroy($wm_img); + + return TRUE; + } + // END overlay_watermark() + + // -------------------------------------------------------------------- + + /** + * Watermark - Text Version + * + * @access public + * @return bool + */ + function text_watermark() + { + if ( ! ($src_img = $this->image_create_gd())) + { + return FALSE; + } + + if ($this->wm_use_truetype == TRUE AND ! file_exists($this->wm_font_path)) + { + $this->set_error('imglib_missing_font'); + return FALSE; + } + + // Fetch source image properties + $this->get_image_properties(); + + // Set RGB values for text and shadow + $this->wm_font_color = str_replace('#', '', $this->wm_font_color); + $this->wm_shadow_color = str_replace('#', '', $this->wm_shadow_color); + + $R1 = hexdec(substr($this->wm_font_color, 0, 2)); + $G1 = hexdec(substr($this->wm_font_color, 2, 2)); + $B1 = hexdec(substr($this->wm_font_color, 4, 2)); + + $R2 = hexdec(substr($this->wm_shadow_color, 0, 2)); + $G2 = hexdec(substr($this->wm_shadow_color, 2, 2)); + $B2 = hexdec(substr($this->wm_shadow_color, 4, 2)); + + $txt_color = imagecolorclosest($src_img, $R1, $G1, $B1); + $drp_color = imagecolorclosest($src_img, $R2, $G2, $B2); + + // Reverse the vertical offset + // When the image is positioned at the bottom + // we don't want the vertical offset to push it + // further down. We want the reverse, so we'll + // invert the offset. Note: The horizontal + // offset flips itself automatically + + if ($this->wm_vrt_alignment == 'B') + $this->wm_vrt_offset = $this->wm_vrt_offset * -1; + + if ($this->wm_hor_alignment == 'R') + $this->wm_hor_offset = $this->wm_hor_offset * -1; + + // Set font width and height + // These are calculated differently depending on + // whether we are using the true type font or not + if ($this->wm_use_truetype == TRUE) + { + if ($this->wm_font_size == '') + $this->wm_font_size = '17'; + + $fontwidth = $this->wm_font_size-($this->wm_font_size/4); + $fontheight = $this->wm_font_size; + $this->wm_vrt_offset += $this->wm_font_size; + } + else + { + $fontwidth = imagefontwidth($this->wm_font_size); + $fontheight = imagefontheight($this->wm_font_size); + } + + // Set base X and Y axis values + $x_axis = $this->wm_hor_offset + $this->wm_padding; + $y_axis = $this->wm_vrt_offset + $this->wm_padding; + + // Set verticle alignment + if ($this->wm_use_drop_shadow == FALSE) + $this->wm_shadow_distance = 0; + + $this->wm_vrt_alignment = strtoupper(substr($this->wm_vrt_alignment, 0, 1)); + $this->wm_hor_alignment = strtoupper(substr($this->wm_hor_alignment, 0, 1)); + + switch ($this->wm_vrt_alignment) + { + case "T" : + break; + case "M": $y_axis += ($this->orig_height/2)+($fontheight/2); + break; + case "B": $y_axis += ($this->orig_height - $fontheight - $this->wm_shadow_distance - ($fontheight/2)); + break; + } + + $x_shad = $x_axis + $this->wm_shadow_distance; + $y_shad = $y_axis + $this->wm_shadow_distance; + + // Set horizontal alignment + switch ($this->wm_hor_alignment) + { + case "L": + break; + case "R": + if ($this->wm_use_drop_shadow) + $x_shad += ($this->orig_width - $fontwidth*strlen($this->wm_text)); + $x_axis += ($this->orig_width - $fontwidth*strlen($this->wm_text)); + break; + case "C": + if ($this->wm_use_drop_shadow) + $x_shad += floor(($this->orig_width - $fontwidth*strlen($this->wm_text))/2); + $x_axis += floor(($this->orig_width -$fontwidth*strlen($this->wm_text))/2); + break; + } + + // Add the text to the source image + if ($this->wm_use_truetype) + { + if ($this->wm_use_drop_shadow) + imagettftext($src_img, $this->wm_font_size, 0, $x_shad, $y_shad, $drp_color, $this->wm_font_path, $this->wm_text); + imagettftext($src_img, $this->wm_font_size, 0, $x_axis, $y_axis, $txt_color, $this->wm_font_path, $this->wm_text); + } + else + { + if ($this->wm_use_drop_shadow) + imagestring($src_img, $this->wm_font_size, $x_shad, $y_shad, $this->wm_text, $drp_color); + imagestring($src_img, $this->wm_font_size, $x_axis, $y_axis, $this->wm_text, $txt_color); + } + + // Output the final image + if ($this->dynamic_output == TRUE) + { + $this->image_display_gd($src_img); + } + else + { + $this->image_save_gd($src_img); + } + + imagedestroy($src_img); + + return TRUE; + } + // END text_watermark() + + // -------------------------------------------------------------------- + + /** + * Create Image - GD + * + * This simply creates an image resource handle + * based on the type of image being processed + * + * @access public + * @param string + * @return resource + */ + function image_create_gd($path = '', $image_type = '') + { + if ($path == '') + $path = $this->full_src_path; + + if ($image_type == '') + $image_type = $this->image_type; + + + switch ($image_type) + { + case 1 : + if ( ! function_exists('imagecreatefromgif')) + { + $this->set_error(array('imglib_unsupported_imagecreate', 'imglib_gif_not_supported')); + return FALSE; + } + + return imagecreatefromgif($path); + break; + case 2 : + if ( ! function_exists('imagecreatefromjpeg')) + { + $this->set_error(array('imglib_unsupported_imagecreate', 'imglib_jpg_not_supported')); + return FALSE; + } + + return imagecreatefromjpeg($path); + break; + case 3 : + if ( ! function_exists('imagecreatefrompng')) + { + $this->set_error(array('imglib_unsupported_imagecreate', 'imglib_png_not_supported')); + return FALSE; + } + + return imagecreatefrompng($path); + break; + + } + + $this->set_error(array('imglib_unsupported_imagecreate')); + return FALSE; + } + // END image_create_gd() + + // -------------------------------------------------------------------- + + /** + * Write imge file to disk - GD + * + * Takes an image resource as input and writes the file + * to the specified destination + * + * @access public + * @param resource + * @return bool + */ + function image_save_gd($resource) + { + switch ($this->image_type) + { + case 1 : + if ( ! function_exists('imagegif')) + { + $this->set_error(array('imglib_unsupported_imagecreate', 'imglib_gif_not_supported')); + return FALSE; + } + + @imagegif($resource, $this->full_dst_path); + break; + case 2 : + if ( ! function_exists('imagejpeg')) + { + $this->set_error(array('imglib_unsupported_imagecreate', 'imglib_jpg_not_supported')); + return FALSE; + } + + if (phpversion() == '4.4.1') + { + @touch($this->full_dst_path); // PHP 4.4.1 bug #35060 - workaround + } + + @imagejpeg($resource, $this->full_dst_path, $this->quality); + break; + case 3 : + if ( ! function_exists('imagepng')) + { + $this->set_error(array('imglib_unsupported_imagecreate', 'imglib_png_not_supported')); + return FALSE; + } + + @imagepng($resource, $this->full_dst_path); + break; + default : + $this->set_error(array('imglib_unsupported_imagecreate')); + return FALSE; + break; + } + + return TRUE; + } + // END image_save_gd() + + // -------------------------------------------------------------------- + + /** + * Dynamically ouputs an image + * + * @access public + * @param resource + * @return void + */ + function image_display_gd($resource) + { + header("Content-Disposition: filename={$this->source_image};"); + header("Content-Type: {$this->mime_type}"); + header('Content-Transfer-Encoding: binary'); + header('Last-Modified: '.gmdate('D, d M Y H:i:s', time()).' GMT'); + + switch ($this->image_type) + { + case 1 : imagegif($resource); + break; + case 2 : imagejpeg($resource, '', $this->quality); + break; + case 3 : imagepng($resource); + break; + default : echo 'Unable to display the image'; + break; + } + } + // END image_display_gd() + + // -------------------------------------------------------------------- + + /** + * Reproportion Image Width/Height + * + * When creating thumbs, the desired width/height + * can end up warping the image due to an incorrect + * ratio between the full-sized image and the thumb. + * + * This function lets us reproportion the width/height + * if users choose to maintain the aspect ratio when resizing. + * + * @access public + * @return void + */ + function image_reproportion() + { + if ( ! is_numeric($this->width) OR ! is_numeric($this->height) OR $this->width == 0 OR $this->height == 0) + return; + + if ( ! is_numeric($this->orig_width) OR ! is_numeric($this->orig_height) OR $this->orig_width == 0 OR $this->orig_height == 0) + return; + + $new_width = ceil($this->orig_width*$this->height/$this->orig_height); + $new_height = ceil($this->width*$this->orig_height/$this->orig_width); + + $ratio = (($this->orig_height/$this->orig_width) - ($this->height/$this->width)); + + if ($this->master_dim != 'width' AND $this->master_dim != 'height') + { + $this->master_dim = ($ratio < 0) ? 'width' : 'height'; + } + + if (($this->width != $new_width) AND ($this->height != $new_height)) + { + if ($this->master_dim == 'height') + { + $this->width = $new_width; + } + else + { + $this->height = $new_height; + } + } + } + // END image_reproportion() + + // -------------------------------------------------------------------- + + /** + * Get image properties + * + * A helper function that gets info about the file + * + * @access public + * @param string + * @return mixed + */ + function get_image_properties($path = '', $return = FALSE) + { + // For now we require GD but we should + // find a way to determine this using IM or NetPBM + + if ($path == '') + $path = $this->full_src_path; + + if ( ! file_exists($path)) + { + $this->set_error('imglib_invalid_path'); + return FALSE; + } + + $vals = @getimagesize($path); + + $types = array(1 => 'gif', 2 => 'jpeg', 3 => 'png'); + + $mime = (isset($types[$vals['2']])) ? 'image/'.$types[$vals['2']] : 'image/jpg'; + + if ($return == TRUE) + { + $v['width'] = $vals['0']; + $v['height'] = $vals['1']; + $v['image_type'] = $vals['2']; + $v['size_str'] = $vals['3']; + $v['mime_type'] = $mime; + + return $v; + } + + $this->orig_width = $vals['0']; + $this->orig_height = $vals['1']; + $this->image_type = $vals['2']; + $this->size_str = $vals['3']; + $this->mime_type = $mime; + + return TRUE; + } + // END get_image_properties() + + // -------------------------------------------------------------------- + + /** + * Size calculator + * + * This function takes a known width x height and + * recalculates it to a new size. Only one + * new variable needs to be known + * + * $props = array( + * 'width' => $width, + * 'height' => $height, + * 'new_width' => 40, + * 'new_height' => '' + * ); + * + * @access public + * @param array + * @return array + */ + function size_calculator($vals) + { + if ( ! is_array($vals)) + return; + + $allowed = array('new_width', 'new_height', 'width', 'height'); + + foreach ($allowed as $item) + { + if ( ! isset($vals[$item]) OR $vals[$item] == '') + $vals[$item] = 0; + } + + if ($vals['width'] == 0 OR $vals['height'] == 0) + { + return $vals; + } + + if ($vals['new_width'] == 0) + { + $vals['new_width'] = ceil($vals['width']*$vals['new_height']/$vals['height']); + } + elseif ($vals['new_height'] == 0) + { + $vals['new_height'] = ceil($vals['new_width']*$vals['height']/$vals['width']); + } + + return $vals; + } + // END size_calculator() + + // -------------------------------------------------------------------- + + /** + * Explode source_image + * + * This is a helper function that extracts the extension + * from the source_image. This function lets us deal with + * source_images with multiple periods, like: my.cool.jpg + * It returns an associative array with two elements: + * $array['ext'] = '.jpg'; + * $array['name'] = 'my.cool'; + * + * @access public + * @param array + * @return array + */ + function explode_name($source_image) + { + $x = explode('.', $source_image); + $ret['ext'] = '.'.end($x); + + $name = ''; + + $ct = count($x)-1; + + for ($i = 0; $i < $ct; $i++) + { + $name .= $x[$i]; + + if ($i < ($ct - 1)) + { + $name .= '.'; + } + } + + $ret['name'] = $name; + + return $ret; + } + // END explode_name() + + // -------------------------------------------------------------------- + + /** + * Is GD Installed? + * + * @access public + * @return bool + */ + function gd_loaded() + { + if ( ! extension_loaded('gd')) + { + if ( ! dl('gd.so')) + { + return FALSE; + } + } + + return TRUE; + } + // END gd_loaded() + + // -------------------------------------------------------------------- + + /** + * Get GD version + * + * @access public + * @return mixed + */ + function gd_version() + { + if (function_exists('gd_info')) + { + $gd_version = @gd_info(); + $gd_version = preg_replace("/\D/", "", $gd_version['GD Version']); + + return $gd_version; + } + + return FALSE; + } + // END gd_version() + + // -------------------------------------------------------------------- + + /** + * Set error message + * + * @access public + * @param string + * @return void + */ + function set_error($msg) + { + $obj =& get_instance(); + $obj->lang->load('imglib'); + + if (is_array($msg)) + { + foreach ($msg as $val) + { + + $msg = ($obj->lang->line($val) == FALSE) ? $val : $obj->lang->line($val); + $this->error_msg[] = $msg; + log_message('error', $msg); + } + } + else + { + $msg = ($obj->lang->line($msg) == FALSE) ? $msg : $obj->lang->line($msg); + $this->error_msg[] = $msg; + log_message('error', $msg); + } + } + // END set_error() + + // -------------------------------------------------------------------- + + /** + * Show error messages + * + * @access public + * @param string + * @return string + */ + function display_errors($open = '

', $close = '

') + { + $str = ''; + foreach ($this->error_msg as $val) + { + $str .= $open.$val.$close; + } + + return $str; + } + // END display_errors() +} +// END Image_lib Class +?> \ No newline at end of file diff --git a/system/libraries/Input.php b/system/libraries/Input.php new file mode 100644 index 000000000..6aba5dd43 --- /dev/null +++ b/system/libraries/Input.php @@ -0,0 +1,585 @@ +use_xss_clean = ($CFG->item('global_xss_filtering') === TRUE) ? TRUE : FALSE; + $this->allow_get_array = ($CFG->item('enable_query_strings') === TRUE) ? TRUE : FALSE; + + log_message('debug', "Input Class Initialized"); + $this->_sanitize_globals(); + } + // END CI_Input() + + // -------------------------------------------------------------------- + + /** + * Sanitize Globals + * + * This function does the folowing: + * + * 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() + { + // Unset globals. This is effectively the same as register_globals = off + foreach (array($_GET, $_POST, $_COOKIE) as $global) + { + if ( ! is_array($global)) + { + unset($$global); + } + else + { + foreach ($global as $key => $val) + { + unset($$key); + } + } + } + + // Is $_GET data allowed? + if ($this->allow_get_array == FALSE) + { + $_GET = array(); + } + + // Clean $_POST Data + if (is_array($_POST) AND count($_POST) > 0) + { + foreach($_POST as $key => $val) + { + if (is_array($val)) + { + foreach($val as $k => $v) + { + $_POST[$this->_clean_input_keys($key)][$this->_clean_input_keys($k)] = $this->_clean_input_data($v); + } + } + else + { + $_POST[$this->_clean_input_keys($key)] = $this->_clean_input_data($val); + } + } + } + + // Clean $_COOKIE Data + if (is_array($_COOKIE) AND count($_COOKIE) > 0) + { + foreach($_COOKIE as $key => $val) + { + $_COOKIE[$this->_clean_input_keys($key)] = $this->_clean_input_data($val); + } + } + + log_message('debug', "Global POST and COOKIE data sanitized"); + } + // END _sanitize_globals() + + // -------------------------------------------------------------------- + + /** + * Clean Intput 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[$key] = $this->_clean_input_data($val); + } + return $new_array; + } + + if ($this->use_xss_clean === TRUE) + { + $str = $this->xss_clean($str); + } + + return preg_replace("/\015\012|\015|\012/", "\n", $str); + } + // END _clean_input_data() + + // -------------------------------------------------------------------- + + /** + * 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: '.$str); + } + + if ( ! get_magic_quotes_gpc()) + { + return addslashes($str); + } + + return $str; + } + // END _clean_input_keys() + + // -------------------------------------------------------------------- + + /** + * Fetch an item from the POST array + * + * @access public + * @param string + * @return string + */ + function post($index = '', $xss_clean = FALSE) + { + if ( ! isset($_POST[$index])) + { + return FALSE; + } + else + { + if ($xss_clean === TRUE) + { + return $this->xss_clean($_POST[$index]); + } + else + { + return $_POST[$index]; + } + } + } + // END post() + + // -------------------------------------------------------------------- + + /** + * Fetch an item from the COOKIE array + * + * @access public + * @param string + * @return string + */ + function cookie($index = '', $xss_clean = FALSE) + { + if ( ! isset($_COOKIE[$index])) + { + return FALSE; + } + else + { + if ($xss_clean === TRUE) + { + return $this->xss_clean($_COOKIE[$index]); + } + else + { + return $_COOKIE[$index]; + } + } + } + // END cookie() + + // -------------------------------------------------------------------- + + /** + * Fetch the IP Address + * + * @access public + * @return string + */ + function ip_address() + { + if ($this->ip_address !== FALSE) + { + return $this->ip_address; + } + + $cip = (isset($_SERVER['HTTP_CLIENT_IP']) AND $_SERVER['HTTP_CLIENT_IP'] != "") ? $_SERVER['HTTP_CLIENT_IP'] : FALSE; + $rip = (isset($_SERVER['REMOTE_ADDR']) AND $_SERVER['REMOTE_ADDR'] != "") ? $_SERVER['REMOTE_ADDR'] : FALSE; + $fip = (isset($_SERVER['HTTP_X_FORWARDED_FOR']) AND $_SERVER['HTTP_X_FORWARDED_FOR'] != "") ? $_SERVER['HTTP_X_FORWARDED_FOR'] : FALSE; + + if ($cip && $rip) $this->ip_address = $cip; + elseif ($rip) $this->ip_address = $rip; + elseif ($cip) $this->ip_address = $cip; + elseif ($fip) $this->ip_address = $fip; + + if (strstr($this->ip_address, ',')) + { + $x = explode(',', $this->ip_address); + $this->ip_address = end($x); + } + + if ( ! $this->valid_ip($this->ip_address)) + { + $this->ip_address = '0.0.0.0'; + } + + unset($cip); + unset($rip); + unset($fip); + + return $this->ip_address; + } + // END ip_address() + + // -------------------------------------------------------------------- + + /** + * Validate IP Address + * + * @access public + * @param string + * @return string + */ + function valid_ip($ip) + { + return ( ! preg_match( "/^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$/", $ip)) ? FALSE : TRUE; + } + // END valid_ip() + + // -------------------------------------------------------------------- + + /** + * 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; + } + // END user_agent() + + // -------------------------------------------------------------------- + + /** + * 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://blog.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 + * + * @access public + * @param string + * @return string + */ + function xss_clean($str, $charset = 'ISO-8859-1') + { + /* + * Remove Null Characters + * + * This prevents sandwiching null characters + * between ascii characters, like Java\0script. + * + */ + $str = preg_replace('/\0+/', '', $str); + $str = preg_replace('/(\\\\0)+/', '', $str); + + /* + * Validate standard character entites + * + * Add a semicolon if missing. We do this to enable + * the conversion of entities to ASCII later. + * + */ + $str = preg_replace('#(&\#*\w+)[\x00-\x20]+;#u',"\\1;",$str); + + /* + * Validate UTF16 two byte encodeing (x00) + * + * Just as above, adds a semicolon if missing. + * + */ + $str = preg_replace('#(&\#x*)([0-9A-F]+);*#iu',"\\1\\2;",$str); + + /* + * URL Decode + * + * Just in case stuff like this is submitted: + * + * Google + * + * Note: Normally urldecode() would be easier but it removes plus signs + * + */ + $str = preg_replace("/%u0([a-z0-9]{3})/i", "&#x\\1;", $str); + $str = preg_replace("/%([a-z0-9]{2})/i", "&#x\\1;", $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. + * + */ + + if (preg_match_all("/<(.+?)>/si", $str, $matches)) + { + for ($i = 0; $i < count($matches['0']); $i++) + { + $str = str_replace($matches['1'][$i], + $this->_html_entity_decode($matches['1'][$i], $charset), + $str); + } + } + + /* + * Convert all tabs to spaces + * + * This prevents strings like this: ja vascript + * Note: we deal with spaces between characters later. + * + */ + $str = preg_replace("#\t+#", " ", $str); + + /* + * Makes PHP tags safe + * + * Note: XML tags are inadvertently replaced too: + * + * '), array('<?php', '<?PHP', '<?', '?>'), $str); // .*?#si", "", $str); + $str = preg_replace("##si", "", $str); + $str = preg_replace("#<(script|xss).*?\>#si", "", $str); + + /* + * Remove JavaScript Event Handlers + * + * Note: This code is a little blunt. It removes + * the event handler and anything up to the closing >, + * but it's unlkely to be a problem. + * + */ + $str = preg_replace('#(<[^>]+.*?)(onblur|onchange|onclick|onfocus|onload|onmouseover|onmouseup|onmousedown|onselect|onsubmit|onunload|onkeypress|onkeydown|onkeyup|onresize)[^>]*>#iU',"\\1>",$str); + + /* + * 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> + * + */ + $str = preg_replace('#<(/*\s*)(alert|applet|basefont|base|behavior|bgsound|blink|body|embed|expression|form|frameset|frame|head|html|ilayer|iframe|input|layer|link|meta|object|plaintext|style|script|textarea|title|xml|xss)([^>]*)>#is', "<\\1\\2\\3>", $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 unexecutable. + * + * For example: eval('some code') + * Becomes: eval('some code') + * + */ + $str = preg_replace('#(alert|cmd|passthru|eval|exec|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 + * + */ + $bad = array( + 'document.cookie' => '', + 'document.write' => '', + 'window.location' => '', + "javascript\s*:" => '', + "Redirect\s+302" => '', + '' => '-->' + ); + + foreach ($bad as $key => $val) + { + $str = preg_replace("#".$key."#i", $val, $str); + } + + + log_message('debug', "XSS Filtering completed"); + return $str; + } + // END xss_clean() + + + /** + * HTML Entities Decode + * + * This function is a replacement for html_entity_decode() + * + * In some versions of PHP the native function does not work + * when UTF-8 is the specified character set, so this gives us + * a work-around. More info here: + * http://bugs.php.net/bug.php?id=25670 + * + * @access private + * @param string + * @param string + * @return string + */ + /* ------------------------------------------------- + /* Replacement for html_entity_decode() + /* -------------------------------------------------*/ + + /* + NOTE: html_entity_decode() has a bug in some PHP versions when UTF-8 is the + character set, and the PHP developers said they were not back porting the + fix to versions other than PHP 5.x. + */ + function _html_entity_decode($str, $charset='ISO-8859-1') + { + if (stristr($str, '&') === FALSE) return $str; + + // 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. + + if (function_exists('html_entity_decode') && (strtolower($charset) != 'utf-8' OR version_compare(phpversion(), '5.0.0', '>='))) + { + $str = html_entity_decode($str, ENT_COMPAT, $charset); + $str = preg_replace('~&#x([0-9a-f]{2,5})~ei', 'chr(hexdec("\\1"))', $str); + return preg_replace('~&#([0-9]{2,4})~e', 'chr(\\1)', $str); + } + + // Numeric Entities + $str = preg_replace('~&#x([0-9a-f]{2,5});{0,1}~ei', 'chr(hexdec("\\1"))', $str); + $str = preg_replace('~&#([0-9]{2,4});{0,1}~e', 'chr(\\1)', $str); + + // Literal Entities - Slightly slow so we do another check + if (stristr($str, '&') === FALSE) + { + $str = strtr($str, array_flip(get_html_translation_table(HTML_ENTITIES))); + } + + return $str; + } + +} +// END Input class +?> \ No newline at end of file diff --git a/system/libraries/Language.php b/system/libraries/Language.php new file mode 100644 index 000000000..b668aa060 --- /dev/null +++ b/system/libraries/Language.php @@ -0,0 +1,113 @@ +is_loaded)) + { + return; + } + + if ($idiom == '') + { + $obj =& get_instance(); + $deft_lang = $obj->config->item('language'); + $idiom = ($deft_lang == '') ? 'english' : $deft_lang; + } + + if ( ! file_exists(BASEPATH.'language/'.$idiom.'/'.$langfile)) + { + show_error('Unable to load the requested language file: language/'.$langfile.EXT); + } + + include_once(BASEPATH.'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; + } + // END load() + + // -------------------------------------------------------------------- + + /** + * Fetch a single line of text from the language array + * + * @access public + * @param string the language line + * @return string + */ + function line($line = '') + { + return ($line == '' OR ! isset($this->language[$line])) ? FALSE : $this->language[$line]; + } + // END line() + +} +// END Language Class +?> \ No newline at end of file diff --git a/system/libraries/Loader.php b/system/libraries/Loader.php new file mode 100644 index 000000000..e2467fa64 --- /dev/null +++ b/system/libraries/Loader.php @@ -0,0 +1,611 @@ +view_path = APPPATH.'views/'; + $this->ob_level = ob_get_level(); + + log_message('debug', "Loader Class Initialized"); + } + // END CI_Loader() + + // -------------------------------------------------------------------- + + /** + * Class Loader + * + * This function lets users load and instantiate classes. + * It is designed to be called from a user's app controllers. + * + * @access public + * @param string the name of the class + * @param mixed any initialization parameters + * @return void + */ + function library($class, $param = FALSE) + { + if ($class == '') + return; + + $obj =& get_instance(); + $obj->_ci_initialize($class, $param); + $obj->_ci_assign_to_models(); + } + // END library() + + // -------------------------------------------------------------------- + + /** + * Model Loader + * + * This function lets users load and instantiate models. + * + * @access public + * @param string the name of the class + * @param mixed any initialization parameters + * @return void + */ + function model($model, $name = '', $db_conn = FALSE) + { + if ($model == '') + return; + + $obj =& get_instance(); + $obj->_ci_load_model($model, $name, $db_conn); + } + // END library() + + // -------------------------------------------------------------------- + + /** + * Database Loader + * + * @access public + * @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 mixed + */ + function database($db = '', $return = FALSE, $active_record = FALSE) + { + $obj =& get_instance(); + + if ($return === TRUE) + { + return $obj->_ci_init_database($db, TRUE, $active_record); + } + else + { + $obj->_ci_init_database($db, FALSE, $active_record); + $obj->_ci_assign_to_models(); + } + } + // END database() + + // -------------------------------------------------------------------- + + /** + * Scaffolding Loader + * + * @access public + * @param string + * @return void + */ + function scaffolding($table = '') + { + if ($table == FALSE) + { + show_error('You must include the name of the table you would like access when you initialize scaffolding'); + } + + $obj =& get_instance(); + $obj->_ci_init_scaffolding($table); + } + // END scaffolding() + + // -------------------------------------------------------------------- + + /** + * 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 retun data so that + * a developer can process it in some way. + * + * @access public + * @param string + * @param array + * @param bool + * @return void + */ + function view($view, $vars = array(), $return = FALSE) + { + return $this->_ci_load(array('view' => $view, 'vars' => $this->_ci_object_to_array($vars), 'return' => $return)); + } + // END view() + + // -------------------------------------------------------------------- + + /** + * Load File + * + * This is a generic file loader + * + * @access public + * @param string + * @param bool + * @return string + */ + function file($path, $return = FALSE) + { + return $this->_ci_load(array('path' => $path, 'return' => $return)); + } + // END file() + + // -------------------------------------------------------------------- + + /** + * Set Variables + * + * Once variables are set they become availabe within + * the controller class and its "view" files. + * + * @access public + * @param array + * @return void + */ + function vars($vars = array()) + { + $vars = $this->_ci_object_to_array($vars); + + if (is_array($vars) AND count($vars) > 0) + { + foreach ($vars as $key => $val) + { + $this->cached_vars[$key] = $val; + } + } + } + // END vars() + + // -------------------------------------------------------------------- + + /** + * Load Helper + * + * This function loads the specified helper file. + * + * @access public + * @param mixed + * @return void + */ + function helper($helpers = array()) + { + if ( ! is_array($helpers)) + { + $helpers = array($helpers); + } + + foreach ($helpers as $helper) + { + if (isset($this->helpers[$helper])) + { + continue; + } + + $helper = strtolower(str_replace(EXT, '', str_replace('_helper', '', $helper)).'_helper'); + + if ( ! file_exists(BASEPATH.'helpers/'.$helper.EXT)) + { + show_error('Unable to load the requested file: helpers/'.$helper.EXT); + } + + include_once(BASEPATH.'helpers/'.$helper.EXT); + + $this->helpers[$helper] = TRUE; + } + + log_message('debug', 'Helpers loaded: '.implode(', ', $helpers)); + } + // END helper() + + // -------------------------------------------------------------------- + + /** + * Load Helpers + * + * This is simply an alias to the above function in case the + * user has written the plural form of this function. + * + * @access public + * @param array + * @return void + */ + function helpers($helpers = array()) + { + $this->helper($helpers); + } + // END helpers() + + // -------------------------------------------------------------------- + + /** + * Load Plugin + * + * This function loads the specified plugin. + * + * @access public + * @param array + * @return void + */ + function plugin($plugins = array()) + { + if ( ! is_array($plugins)) + { + $plugins = array($plugins); + } + + foreach ($plugins as $plugin) + { + if (isset($this->plugins[$plugin])) + { + continue; + } + + $plugin = strtolower(str_replace(EXT, '', str_replace('_plugin.', '', $plugin)).'_pi'); + + if ( ! file_exists(BASEPATH.'plugins/'.$plugin.EXT)) + { + show_error('Unable to load the requested file: plugins/'.$plugin.EXT); + } + + include_once(BASEPATH.'plugins/'.$plugin.EXT); + + $this->plugins[$plugin] = TRUE; + } + + log_message('debug', 'Plugins loaded: '.implode(', ', $plugins)); + } + // END plugin() + + // -------------------------------------------------------------------- + + /** + * Load Script + * + * This function loads the specified include file from the + * application/scripts/ folder + * + * @access public + * @param array + * @return void + */ + function script($scripts = array()) + { + if ( ! is_array($scripts)) + { + $scripts = array($scripts); + } + + foreach ($scripts as $script) + { + if (isset($this->scripts[$script])) + { + continue; + } + + $script = strtolower(str_replace(EXT, '', $script)); + + if ( ! file_exists(APPPATH.'scripts/'.$script.EXT)) + { + show_error('Unable to load the requested script: scripts/'.$script.EXT); + } + + include_once(APPPATH.'scripts/'.$script.EXT); + + $this->scripts[$script] = TRUE; + } + + log_message('debug', 'Scripts loaded: '.implode(', ', $scripts)); + } + // END script() + + // -------------------------------------------------------------------- + + /** + * Load Plugins + * + * This is simply an alias to the above function in case the + * user has written the plural form of this function. + * + * @access public + * @param array + * @return void + */ + function plugins($plugins = array()) + { + $this->plugin($plugins); + } + // END plugins() + + // -------------------------------------------------------------------- + + /** + * Loads a language file + * + * @access public + * @param string + * @return void + */ + function language($file = '', $lang = '', $return = FALSE) + { + $obj =& get_instance(); + return $obj->lang->load($file, $lang, $return); + } + // END language() + + // -------------------------------------------------------------------- + + /** + * Loads a config file + * + * @access public + * @param string + * @return void + */ + function config($file = '') + { + $obj =& get_instance(); + $obj->config->load($file); + } + // END config() + + // -------------------------------------------------------------------- + + /** + * Set the Path to the "views" folder + * + * @access private + * @param string + * @return void + */ + function _ci_set_view_path($path) + { + $this->view_path = $path; + } + // END _ci_set_view_path() + + // -------------------------------------------------------------------- + + /** + * Loader + * + * This function isn't called directly. It's called from + * the two functions above. It's used to load views and files + * + * @access private + * @param array + * @return void + */ + function _ci_load($data) + { + $OUT =& _load_class('CI_Output'); + + // This allows anything loaded using $this->load (viwes, files, etc.) + // to become accessible from within the Controller and Model functions. + $obj =& get_instance(); + foreach ($obj->ci_is_loaded as $val) + { + if ( ! isset($this->$val)) + { + $this->$val =& $obj->$val; + } + } + + // Set the default data variables + foreach (array('view', 'vars', 'path', 'return') as $val) + { + $$val = ( ! isset($data[$val])) ? FALSE : $data[$val]; + } + + /* + * Extract and cached 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($vars)) + { + $this->cached_vars = array_merge($this->cached_vars, $vars); + } + extract($this->cached_vars); + + // Set the path to the requested file + if ($path == '') + { + $ext = pathinfo($view, PATHINFO_EXTENSION); + $file = ($ext == '') ? $view.EXT : $view; + $path = $this->view_path.$file; + } + else + { + $x = explode('/', $path); + $file = end($x); + } + + /* + * 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 acurate. + * + */ + + if ( ! file_exists($path)) + { + show_error('Unable to load the requested file: '.$file); + } + + ob_start(); + + include($path); + log_message('debug', 'File loaded: '.$path); + + // Return the file data if requested to + if ($return === TRUE) + { + $buffer = ob_get_contents(); + ob_end_clean(); + + return $buffer; + } + + /* + * Flush the buffer... or buff the flusher? + * + * In order to permit templates (views) to be nested within + * other views, we need to flush the content back out whenever + * we are beyond the first level of output buffering so that + * it can be seen and included properly by the first included + * template and any subsequent ones. Oy! + * + */ + if (ob_get_level() > $this->ob_level + 1) + { + ob_end_flush(); + } + else + { + $OUT->set_output(ob_get_contents()); + ob_end_clean(); + } + } + // END _load() + + // -------------------------------------------------------------------- + + /** + * Autoloader + * + * The config/autoload.php file contains an array that permits sub-systems, + * plugins, and helpers to be loaded automatically. + * + * @access private + * @param array + * @return void + */ + function _ci_autoloader($autoload) + { + if ($autoload === FALSE) + { + return; + } + + foreach (array('helper', 'plugin', 'script') as $type) + { + if (isset($autoload[$type])) + { + if ( ! is_array($autoload[$type])) + { + $autoload[$type] = array($autoload[$type]); + } + + foreach ($autoload[$type] as $item) + { + $this->$type($item); + } + } + } + } + // END _ci_autoloader() + + // -------------------------------------------------------------------- + + /** + * Object to Array + * + * Takes an object as input and convers the class variables to array key/vals + * + * @access public + * @param object + * @return array + */ + function _ci_object_to_array($object) + { + if ( ! is_object($object)) + { + return $object; + } + + $array = array(); + foreach (get_object_vars($object) as $key => $val) + { + $array[$key] = $val; + } + + return $array; + } + +} +// END Loader Class +?> \ No newline at end of file diff --git a/system/libraries/Log.php b/system/libraries/Log.php new file mode 100644 index 000000000..35e30b64c --- /dev/null +++ b/system/libraries/Log.php @@ -0,0 +1,117 @@ + '1', 'DEBUG' => '2', 'INFO' => '3', 'ALL' => '4'); + + /** + * Constructor + * + * @access public + * @param string the log file path + * @param string the error threshold + * @param string the date formatting codes + */ + function CI_Log($path = '', $threshold = '', $date_fmt = '') + { + $this->log_path = ($path != '') ? $path : BASEPATH.'logs/'; + + if ( ! is_dir($this->log_path) OR ! is_writable($this->log_path)) + { + $this->_enabled = FALSE; + } + + if (ctype_digit($threshold)) + { + $this->_threshold = $threshold; + } + + if ($date_fmt != '') + { + $this->_date_fmt = $date_fmt; + } + } + // END CI_Log() + + // -------------------------------------------------------------------- + + /** + * Write Log File + * + * Generally this function will be called using the global log_message() function + * + * @access public + * @param string the error level + * @param string the error message + * @param bool whether the error is a native PHP error + * @return bool + */ + function write_log($level = 'error', $msg, $php_error = FALSE) + { + if ($this->_enabled === FALSE) + { + return FALSE; + } + + $level = strtoupper($level); + + if ( ! isset($this->_levels[$level]) OR ($this->_levels[$level] > $this->_threshold)) + { + return FALSE; + } + + $filepath = $this->log_path.'log-'.date('Y-m-d').'.php'; + $message = ''; + + if ( ! file_exists($filepath)) + { + $message .= "<"."?php if (!defined('BASEPATH')) exit('No direct script access allowed'); ?".">\n\n"; + } + + if ( ! $fp = @fopen($filepath, "a")) + { + return FALSE; + } + + $message .= $level.' '.(($level == 'INFO') ? ' -' : '-').' '.date($this->_date_fmt). ' --> '.$msg."\n"; + + flock($fp, LOCK_EX); + fwrite($fp, $message); + flock($fp, LOCK_UN); + fclose($fp); + + @chmod($filepath, 0666); + return TRUE; + } + // END write_log() +} +// END Log Class +?> \ No newline at end of file diff --git a/system/libraries/Model.php b/system/libraries/Model.php new file mode 100644 index 000000000..9834f8278 --- /dev/null +++ b/system/libraries/Model.php @@ -0,0 +1,72 @@ +_assign_libraries(FALSE); + log_message('debug', "Model Class Initialized"); + } + // END Model() + + /** + * Assign Libraries + * + * Creates local references to all currently instantiated objects + * so that any syntax that can be legally used in a controller + * can be used within models. + * + * @access private + */ + function _assign_libraries($use_reference = TRUE) + { + $obj =& get_instance(); + foreach ($obj->ci_is_loaded as $val) + { + if ( ! isset($this->$val)) + { + if ($use_reference === TRUE) + { + $this->$val =& $obj->$val; + } + else + { + $this->$val = $obj->$val; + } + } + } + } + // END _assign_libraries() + +} +// END Model Class +?> \ No newline at end of file diff --git a/system/libraries/Output.php b/system/libraries/Output.php new file mode 100644 index 000000000..f5db3e0d0 --- /dev/null +++ b/system/libraries/Output.php @@ -0,0 +1,241 @@ +final_output; + } + + // -------------------------------------------------------------------- + + /** + * Set Output + * + * Sets the output string + * + * @access public + * @param string + * @return void + */ + function set_output($output) + { + $this->final_output = $output; + } + + // -------------------------------------------------------------------- + + /** + * Set Cache + * + * @access public + * @param integer + * @return void + */ + function cache($time) + { + $this->cache_expiration = ( ! ctype_digit($time)) ? 0 : $time; + } + + // -------------------------------------------------------------------- + + /** + * Display Output + * + * All "view" data is automatically put into this variable + * by the controller class: + * + * $this->final_output + * + * This function simply echos the variable out. It also does the following: + * + * Stops the benchmark timer so the page rendering speed can be shown. + * + * Determines if the "memory_get_usage' function is available so that + * the memory usage can be shown. + * + * @access public + * @return void + */ + function _display($output = '') + { + $BM =& _load_class('CI_Benchmark'); + + if ($output == '') + { + $output =& $this->final_output; + } + + if ($this->cache_expiration > 0) + { + $this->_write_cache($output); + } + + $elapsed = $BM->elapsed_time('code_igniter_start', 'code_igniter_end'); + $memory = ( ! function_exists('memory_get_usage')) ? '0' : round(memory_get_usage()/1024/1024, 2).'MB'; + + $output = str_replace('{memory_usage}', $memory, $output); + $output = str_replace('{elapsed_time}', $elapsed, $output); + + echo $output; + + log_message('debug', "Final output sent to browser"); + log_message('debug', "Total execution time: ".$elapsed); + } + + // -------------------------------------------------------------------- + + /** + * Write a Cache File + * + * @access public + * @return void + */ + function _write_cache($output) + { + $obj =& get_instance(); + $path = $obj->config->item('cache_path'); + + $cache_path = ($path == '') ? BASEPATH.'cache/' : $path; + + if ( ! is_dir($cache_path) OR ! is_writable($cache_path)) + { + return; + } + + $uri = $obj->config->item('base_url', 1). + $obj->config->item('index_page'). + $obj->uri->uri_string(); + + $cache_path .= md5($uri); + + if ( ! $fp = @fopen($cache_path, 'wb')) + { + log_message('error', "Unable to write ache file: ".$cache_path); + return; + } + + $expire = time() + ($this->cache_expiration * 60); + + flock($fp, LOCK_EX); + fwrite($fp, $expire.'TS--->'.$output); + flock($fp, LOCK_UN); + fclose($fp); + @chmod($cache_path, 0777); + + log_message('debug', "Cache file written: ".$cache_path); + } + + // -------------------------------------------------------------------- + + /** + * Update/serve a cached file + * + * @access public + * @return void + */ + function _display_cache() + { + $CFG =& _load_class('CI_Config'); + $RTR =& _load_class('CI_Router'); + + $cache_path = ($CFG->item('cache_path') == '') ? BASEPATH.'cache/' : $CFG->item('cache_path'); + + if ( ! is_dir($cache_path) OR ! is_writable($cache_path)) + { + return FALSE; + } + + // Build the file path. The file name is an MD5 hash of the full URI + $uri = $CFG->item('base_url', 1).$CFG->item('index_page').$RTR->uri_string; + + $filepath = $cache_path.md5($uri); + + if ( ! @file_exists($filepath)) + { + return FALSE; + } + + if ( ! $fp = @fopen($filepath, 'rb')) + { + 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']))) + { + @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; + } + +} +// END Output Class +?> \ No newline at end of file diff --git a/system/libraries/Pagination.php b/system/libraries/Pagination.php new file mode 100644 index 000000000..0bbb577a3 --- /dev/null +++ b/system/libraries/Pagination.php @@ -0,0 +1,207 @@ +'; + 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 = ''; + + /** + * Constructor + * + * @access public + * @param array initialization parameters + */ + function CI_Pagination($params = array()) + { + if (count($params) > 0) + { + $this->initialize($params); + } + + 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 = intval($this->total_rows / $this->per_page); + + // Use modulus to see if our division has a remainder.If so, add one to our page number. + if ($this->total_rows % $this->per_page) + { + $num_pages++; + } + + // Is there only one page? Hm... nothing more to do here then. + if ($num_pages == 1) + { + return ''; + } + + // Determine the current page number. + $obj =& get_instance(); + if ($obj->uri->segment($this->uri_segment) != 0) + { + $this->cur_page = $obj->uri->segment($this->uri_segment); + } + + if ( ! ctype_digit($this->cur_page)) + { + $this->cur_page = 0; + } + + $uri_page_number = $this->cur_page; + $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; + + // Add a trailing slash to the base URL if needed + $this->base_url = preg_replace("/(.+?)\/*$/", "\\1/", $this->base_url); + + // And here we go... + $output = ''; + + // Render the "First" link + if ($this->cur_page > $this->num_links) + { + $output .= $this->first_tag_open.''.$this->first_link.''.$this->first_tag_close; + } + + // Render the "previous" link + if (($this->cur_page - $this->num_links) >= 0) + { + $i = $uri_page_number - $this->per_page; + if ($i == 0) $i = ''; + $output .= $this->prev_tag_open.''.$this->prev_link.''.$this->prev_tag_close; + } + + // Write the digit links + for ($loop = $start -1; $loop <= $end; $loop++) + { + $i = ($loop * $this->per_page) - $this->per_page; + + if ($i >= 0) + { + if ($this->cur_page == $loop) + { + $output .= $this->cur_tag_open.$loop.$this->cur_tag_close; // Current page + } + else + { + $n = ($i == 0) ? '' : $i; + $output .= $this->num_tag_open.''.$loop.''.$this->num_tag_close; + } + } + } + + // Render the "next" link + if ($this->cur_page < $num_pages) + { + $output .= $this->next_tag_open.''.$this->next_link.''.$this->next_tag_close; + } + + // Render the "Last" link + if (($this->cur_page + $this->num_links) < $num_pages) + { + $i = (($num_pages * $this->per_page) - $this->per_page); + $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 shashes. + $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 +?> \ No newline at end of file diff --git a/system/libraries/Parser.php b/system/libraries/Parser.php new file mode 100644 index 000000000..9f6a814ae --- /dev/null +++ b/system/libraries/Parser.php @@ -0,0 +1,178 @@ +load->view($template, '', TRUE); + + if ($template == '') + { + return FALSE; + } + + foreach ($data as $key => $val) + { + if ( ! is_array($val)) + { + $template = $this->_parse_single($key, $val, $template); + } + else + { + $template = $this->_parse_pair($key, $val, $template); + } + } + + if ($return == FALSE) + { + $OUT->final_output = $template; + } + + return $template; + } + // END set_method() + + // -------------------------------------------------------------------- + + /** + * 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; + } + // END set_method() + + // -------------------------------------------------------------------- + + /** + * 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); + } + // END set_method() + + // -------------------------------------------------------------------- + + /** + * 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); + } + // END set_method() + + // -------------------------------------------------------------------- + + /** + * Matches a variable pair + * + * @access private + * @param string + * @param string + * @return mixed + */ + function _match_pair($string, $variable) + { + if ( ! preg_match("|".$this->l_delim . $variable . $this->r_delim."(.+)".$this->l_delim . '/' . $variable . $this->r_delim."|s", $string, $match)) + { + return FALSE; + } + + return $match; + } + // END _match_pair() + +} +// END Parser Class +?> \ No newline at end of file diff --git a/system/libraries/Router.php b/system/libraries/Router.php new file mode 100644 index 000000000..abc253eff --- /dev/null +++ b/system/libraries/Router.php @@ -0,0 +1,318 @@ +config =& _load_class('CI_Config'); + $this->_set_route_mapping(); + log_message('debug', "Router Class Initialized"); + } + + // -------------------------------------------------------------------- + + /** + * Set the route mapping + * + * This function determies 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_route_mapping() + { + // Are query strings enabled? If so we're done... + if ($this->config->item('enable_query_strings') === TRUE AND isset($_GET[$this->config->item('controller_trigger')])) + { + $this->set_class($_GET[$this->config->item('controller_trigger')]); + + if (isset($_GET[$this->config->item('function_trigger')])) + { + $this->set_method($_GET[$this->config->item('function_trigger')]); + } + + return; + } + + // Load the routes.php file + include_once(APPPATH.'config/routes'.EXT); + $this->routes = ( ! isset($route) OR ! is_array($route)) ? array() : $route; + unset($route); + + // Set the default controller + $this->default_controller = ( ! isset($this->routes['default_controller']) OR $this->routes['default_controller'] == '') ? FALSE : strtolower($this->routes['default_controller']); + + // Fetch the URI string Depending on the server, + // the URI will be available in one of two globals + switch ($this->config->item('uri_protocol')) + { + case 'path_info' : $this->uri_string = (isset($_SERVER['PATH_INFO'])) ? $_SERVER['PATH_INFO'] : @getenv('PATH_INFO'); + break; + case 'query_string' : $this->uri_string = (isset($_SERVER['QUERY_STRING'])) ? $_SERVER['QUERY_STRING'] : @getenv('QUERY_STRING'); + break; + default : + $path_info = (isset($_SERVER['PATH_INFO'])) ? $_SERVER['PATH_INFO'] : @getenv('PATH_INFO'); + + if ($path_info != '' AND $path_info != "/".SELF) + { + $this->uri_string = $path_info; + } + else + { + $this->uri_string = (isset($_SERVER['QUERY_STRING'])) ? $_SERVER['QUERY_STRING'] : @getenv('QUERY_STRING'); + } + break; + } + + // Is there a URI string? If not, the default controller specified + // by the admin in the "routes" file will be shown. + if ($this->uri_string == '') + { + 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."); + } + + $this->set_class($this->default_controller); + $this->set_method('index'); + + log_message('debug', "No URI present. Default controller set."); + return; + } + + // Do we need to remove the suffix specified in the config file? + 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. + $this->_compile_segments(explode("/", preg_replace("|/*(.+?)/*$|", "\\1", $this->uri_string))); + + + // Remap the class/method if a route exists + unset($this->routes['default_controller']); + + if (count($this->routes) > 0) + { + $this->_parse_routes(); + } + } + // END _set_route_mapping() + + // -------------------------------------------------------------------- + + /** + * Compile Segments + * + * This function takes an array of URI segments as + * input, and puts it into the $this->segments array. + * It also sets the current class/method + * + * @access private + * @param array + * @param bool + * @return void + */ + function _compile_segments($segs, $route = FALSE) + { + $segments = array(); + + $i = 1; + foreach($segs as $val) + { + $val = trim($this->_filter_uri($val)); + + if ($val != '') + $segments[$i++] = $val; + } + + $this->set_class($segments['1']); + + if (isset($segments['2'])) + { + // A scaffolding request. No funny business with the URL + if ($this->routes['scaffolding_trigger'] == $segments['2'] AND $segments['2'] != '_ci_scaffolding') + { + $this->scaffolding_request = TRUE; + unset($this->routes['scaffolding_trigger']); + } + else + { + // A standard method request + $this->set_method($segments['2']); + } + } + + if ($route == FALSE) + { + $this->segments = $segments; + } + + unset($segments); + } + // END _compile_segments() + + // -------------------------------------------------------------------- + + /** + * Filter segments for malicious characters + * + * @access private + * @param string + * @return string + */ + function _filter_uri($str) + { + if ( ! preg_match("/^[a-z0-9~\s\%\.:_-]+$/i", $str)) + { + exit('The URI you submitted has disallowed characters: '.$str); + } + + return $str; + } + // END _filter_uri() + + // -------------------------------------------------------------------- + + /** + * Set the class name + * + * @access public + * @param string + * @return void + */ + function set_class($class) + { + $this->class = $class; + } + // END _filter_uri() + + // -------------------------------------------------------------------- + + /** + * Fetch the current class + * + * @access public + * @return string + */ + function fetch_class() + { + return $this->class; + } + // END _filter_uri() + + // -------------------------------------------------------------------- + + /** + * Set the method name + * + * @access public + * @param string + * @return void + */ + function set_method($method) + { + $this->method = $method; + } + // END set_method() + + // -------------------------------------------------------------------- + + /** + * Fetch the current method + * + * @access public + * @return string + */ + function fetch_method() + { + return $this->method; + } + // END set_method() + + // -------------------------------------------------------------------- + + /** + * 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->segments); + $num = count($this->segments); + + // Is there a literal match? If so we're done + if (isset($this->routes[$uri])) + { + $this->_compile_segments(explode('/', $this->routes[$uri]), TRUE); + return; + } + + // Loop through the route array looking for wildcards + foreach ($this->routes as $key => $val) + { + if (count(explode('/', $key)) != $num) + continue; + + if (preg_match("|".str_replace(':any', '.+', str_replace(':num', '[0-9]+', $key))."$|", $uri)) + { + $this->_compile_segments(explode('/', $val), TRUE); + break; + } + } + } + // END set_method() +} +// END Router Class +?> \ No newline at end of file diff --git a/system/libraries/Session.php b/system/libraries/Session.php new file mode 100644 index 000000000..4f08cf692 --- /dev/null +++ b/system/libraries/Session.php @@ -0,0 +1,499 @@ +object =& get_instance(); + + log_message('debug', "Session Class Initialized"); + $this->sess_run(); + } + // END display_errors() + + // -------------------------------------------------------------------- + + /** + * Run the session routines + * + * @access public + * @return void + */ + function sess_run() + { + /* + * Set the "now" time + * + * It can either set to GMT or time(). The pref + * is set in the config file. If the developer + * is doing any sort of time localization they + * might want to set the session time to GMT so + * they can offset the "last_activity" and + * "last_visit" times based on each user's locale. + * + */ + if (strtolower($this->object->config->item('time_reference')) == 'gmt') + { + $now = time(); + $this->now = mktime(gmdate("H", $now), gmdate("i", $now), gmdate("s", $now), gmdate("m", $now), gmdate("d", $now), gmdate("Y", $now)); + + if (strlen($this->now) < 10) + { + $this->now = time(); + log_message('error', 'The session class could not set a proper GMT timestamp so the local time() value was used.'); + } + } + else + { + $this->now = time(); + } + + /* + * Set the session length + * + * If the session expiration is set to zero in + * the config file we'll set the expiration + * two years from now. + * + */ + $expiration = $this->object->config->item('sess_expiration'); + + if (ctype_digit($expiration)) + { + if ($expiration > 0) + { + $this->sess_length = $this->object->config->item('sess_expiration'); + } + else + { + $this->sess_length = (60*60*24*365*2); + } + } + + // Do we need encryption? + $this->encryption = $this->object->config->item('sess_encrypt_cookie'); + + if ($this->encryption == TRUE) + { + $this->object->load->library('encrypt'); + } + + // Are we using a database? + if ($this->object->config->item('sess_use_database') === TRUE AND $this->object->config->item('sess_table_name') != '') + { + $this->use_database = TRUE; + $this->session_table = $this->object->config->item('sess_table_name'); + $this->object->load->database(); + } + + // Set the cookie name + if ($this->object->config->item('sess_cookie_name') != FALSE) + { + $this->sess_cookie = $this->object->config->item('cookie_prefix').$this->object->config->item('sess_cookie_name'); + } + + /* + * Fetch the current session + * + * 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 + { + // We only update the session every five minutes + if (($this->userdata['last_activity'] + 300) < $this->now) + { + $this->sess_update(); + } + } + + // Delete expired sessions if necessary + if ($this->use_database === TRUE) + { + $this->sess_gc(); + } + } + // END sess_run() + + // -------------------------------------------------------------------- + + /** + * Fetch the current session data if it exists + * + * @access public + * @return void + */ + function sess_read() + { + // Fetch the cookie + $session = $this->object->input->cookie($this->sess_cookie); + + if ($session === FALSE) + { + log_message('debug', 'A session cookie was not found.'); + return FALSE; + } + + // Decrypt and unserialize the data + if ($this->encryption == TRUE) + { + $session = $this->object->encrypt->decode($session); + } + + $session = @unserialize($this->strip_slashes($session)); + + if ( ! is_array($session) OR ! isset($session['last_activity'])) + { + log_message('error', 'The session cookie data did not contain a valid array. This could be a possible hacking attempt.'); + return FALSE; + } + + // Is the session current? + if (($session['last_activity'] + $this->sess_length) < $this->now) + { + $this->sess_destroy(); + return FALSE; + } + + // Does the IP Match? + if ($this->object->config->item('sess_match_ip') == TRUE AND $session['ip_address'] != $this->object->input->ip_address()) + { + $this->sess_destroy(); + return FALSE; + } + + // Does the User Agent Match? + if ($this->object->config->item('sess_match_useragent') == TRUE AND $session['user_agent'] != substr($this->object->input->user_agent(), 0, 50)) + { + $this->sess_destroy(); + return FALSE; + } + + // Is there a corresponding session in the DB? + if ($this->use_database === TRUE) + { + $this->object->db->where('session_id', $session['session_id']); + + if ($this->object->config->item('sess_match_ip') == TRUE) + { + $this->object->db->where('ip_address', $session['ip_address']); + } + + if ($this->object->config->item('sess_match_useragent') == TRUE) + { + $this->object->db->where('user_agent', $session['user_agent']); + } + + $query = $this->object->db->get($this->session_table); + + if ($query->num_rows() == 0) + { + $this->sess_destroy(); + return FALSE; + } + else + { + $row = $query->row(); + if (($row->last_activity + $this->sess_length) < $this->now) + { + $this->object->db->where('session_id', $session['session_id']); + $this->object->db->delete($this->session_table); + $this->sess_destroy(); + return FALSE; + } + } + } + + // Session is valid! + $this->userdata = $session; + unset($session); + + return TRUE; + } + // END sess_read() + + // -------------------------------------------------------------------- + + /** + * Write the session cookie + * + * @access public + * @return void + */ + function sess_write() + { + $cookie_data = serialize($this->userdata); + + if ($this->encryption == TRUE) + { + $cookie_data = $this->object->encrypt->encode($cookie_data); + } + + setcookie( + $this->sess_cookie, + $cookie_data, + $this->sess_length + $this->now, + $this->object->config->item('cookie_path'), + $this->object->config->item('cookie_domain'), + 0 + ); + } + // END sess_read() + + // -------------------------------------------------------------------- + + /** + * Create a new session + * + * @access public + * @return void + */ + function sess_create() + { + $sessid = ''; + while (strlen($sessid) < 32) + { + $sessid .= mt_rand(0, mt_getrandmax()); + } + + $this->userdata = array( + 'session_id' => md5(uniqid($sessid, TRUE)), + 'ip_address' => $this->object->input->ip_address(), + 'user_agent' => substr($this->object->input->user_agent(), 0, 50), + 'last_activity' => $this->now + ); + + + // Save the session in the DB if needed + if ($this->use_database === TRUE) + { + $this->object->db->query($this->object->db->insert_string($this->session_table, $this->userdata)); + } + + // Write the cookie + $this->userdata['last_visit'] = 0; + $this->sess_write(); + } + // END sess_read() + + // -------------------------------------------------------------------- + + /** + * Update an existing session + * + * @access public + * @return void + */ + function sess_update() + { + if (($this->userdata['last_activity'] + $this->sess_length) < $this->now) + { + $this->userdata['last_visit'] = $this->userdata['last_activity']; + } + + $this->userdata['last_activity'] = $this->now; + + // Update the session in the DB if needed + if ($this->use_database === TRUE) + { + $this->object->db->query($this->object->db->update_string($this->session_table, array('last_activity' => $this->now), array('session_id' => $this->userdata['session_id']))); + } + + // Write the cookie + $this->sess_write(); + } + // END sess_update() + + // -------------------------------------------------------------------- + + /** + * Destroy the current session + * + * @access public + * @return void + */ + function sess_destroy() + { + setcookie( + $this->sess_cookie, + addslashes(serialize(array())), + ($this->now - 31500000), + $this->object->config->item('cookie_path'), + $this->object->config->item('cookie_domain'), + 0 + ); + } + // END sess_destroy() + + // -------------------------------------------------------------------- + + /** + * Garbage collection + * + * This deletes expired session rows from database + * if the probability percentage is met + * + * @access public + * @return void + */ + function sess_gc() + { + srand(time()); + if ((rand() % 100) < $this->gc_probability) + { + $expire = $this->now - $this->sess_length; + + $this->object->db->where("last_activity < {$expire}"); + $this->object->db->delete($this->session_table); + + log_message('debug', 'Session garbage collection performed.'); + } + } + // END sess_destroy() + + // -------------------------------------------------------------------- + + /** + * Fetch a specific item form the session array + * + * @access public + * @param string + * @return string + */ + function userdata($item) + { + return ( ! isset($this->userdata[$item])) ? FALSE : $this->userdata[$item]; + } + // END sess_destroy() + + // -------------------------------------------------------------------- + + /** + * 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(); + } + // END set_userdata() + + // -------------------------------------------------------------------- + + /** + * 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(); + } + // END set_userdata() + + // -------------------------------------------------------------------- + + /** + * Strip slashes + * + * @access public + * @param mixed + * @return mixed + */ + function strip_slashes($vals) + { + if (is_array($vals)) + { + foreach ($vals as $key=>$val) + { + $vals[$key] = $this->strip_slashes($val); + } + } + else + { + $vals = stripslashes($vals); + } + + return $vals; + } + // END strip_slashes() +} +// END Session Class +?> \ No newline at end of file diff --git a/system/libraries/Sha1.php b/system/libraries/Sha1.php new file mode 100644 index 000000000..13196eb69 --- /dev/null +++ b/system/libraries/Sha1.php @@ -0,0 +1,254 @@ +> 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 < sizeof($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); + } + // END generate() + + // -------------------------------------------------------------------- + + /** + * 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; + } + // END _hex() + + // -------------------------------------------------------------------- + + /** + * 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; + } + // END _ft() + + // -------------------------------------------------------------------- + + /** + * 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; + } + } + // END _kt() + + // -------------------------------------------------------------------- + + /** + * 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); + } + // END _safe_add() + + // -------------------------------------------------------------------- + + /** + * 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 +?> \ No newline at end of file diff --git a/system/libraries/Trackback.php b/system/libraries/Trackback.php new file mode 100644 index 000000000..583c6d28d --- /dev/null +++ b/system/libraries/Trackback.php @@ -0,0 +1,561 @@ + '', 'title' => '', 'excerpt' => '', 'blog_name' => '', 'charset' => ''); + var $convert_ascii = TRUE; + var $response = ''; + var $error_msg = array(); + + /** + * Constructor + * + * @access public + */ + function CI_Trackback() + { + 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; + } + // END send() + + // -------------------------------------------------------------------- + + /** + * 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; + } + // END receive() + + // -------------------------------------------------------------------- + + /** + * Send Trackback Error Message + * + * Allows custom errros 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; + } + // END send_error() + + // -------------------------------------------------------------------- + + /** + * 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; + } + // END send_success() + + // -------------------------------------------------------------------- + + /** + * Fetch a particular item + * + * @access public + * @param string + * @return string + */ + function data($item) + { + return ( ! isset($this->data[$item])) ? '' : $this->data[$item]; + } + // END data() + + // -------------------------------------------------------------------- + + /** + * 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 ( ! eregi("0", $this->response)) + { + $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; + } + // END process() + + // -------------------------------------------------------------------- + + /** + * 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; + } + // END extract_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; + } + } + // END validate_url() + + // -------------------------------------------------------------------- + + /** + * Find the Trackback URL's ID + * + * @access public + * @param string + * @return string + */ + function get_id($url) + { + $tb_id = ""; + + if (strstr($url, '?')) + { + $tb_array = explode('/', $url); + $tb_end = $tb_array[count($tb_array)-1]; + + if ( ! ctype_digit($tb_end)) + { + $tb_end = $tb_array[count($tb_array)-2]; + } + + $tb_array = explode('=', $tb_end); + $tb_id = $tb_array[count($tb_array)-1]; + } + else + { + if (ereg("/$", $url)) + { + $url = substr($url, 0, -1); + } + + $tb_array = explode('/', $url); + $tb_id = $tb_array[count($tb_array)-1]; + + if ( ! ctype_digit($tb_id)) + { + $tb_id = $tb_array[count($tb_array)-2]; + } + } + + if ( ! preg_match ("/^([0-9]+)$/", $tb_id)) + { + return false; + } + else + { + return $tb_id; + } + } + // END get_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; + } + // END get_id() + + // -------------------------------------------------------------------- + + /** + * 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+/", ' ', preg_replace("/(\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; + } + } + } + // END get_id() + + // -------------------------------------------------------------------- + + /** + * 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; + } + // END convert_ascii() + + // -------------------------------------------------------------------- + + /** + * Set error message + * + * @access public + * @param string + * @return void + */ + function set_error($msg) + { + log_message('error', $msg); + $this->error_msg[] = $msg; + } + // END convert_ascii() + + // -------------------------------------------------------------------- + + /** + * 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; + } + // END display_errors() +} +// END Trackback Class +?> \ No newline at end of file diff --git a/system/libraries/URI.php b/system/libraries/URI.php new file mode 100644 index 000000000..4c2fa9c7f --- /dev/null +++ b/system/libraries/URI.php @@ -0,0 +1,243 @@ +uri =& _load_class('CI_Router'); + log_message('debug', "URI Class Initialized"); + } + + // -------------------------------------------------------------------- + + /** + * 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->uri->segments[$n])) ? $no_result : $this->uri->segments[$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: + * + * www.your-site.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()) + { + if ( ! ctype_digit($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 $default; + } + + $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') + { + if ($where == 'trailing') + { + $trailing = '/'; + $leading = ''; + } + elseif ($where == 'leading') + { + $leading = '/'; + $trailing = ''; + } + else + { + $leading = '/'; + $trailing = '/'; + } + return ( ! isset($this->uri->segments[$n])) ? '' : $leading.$this->uri->segments[$n].$trailing; + } + + // -------------------------------------------------------------------- + + /** + * Segment Array + * + * @access public + * @return array + */ + function segment_array() + { + return $this->uri->segments; + } + + // -------------------------------------------------------------------- + + /** + * Total number of segments + * + * @access public + * @return integer + */ + function total_segments() + { + return count($this->uri->segments); + } + + // -------------------------------------------------------------------- + + /** + * Fetch the entire URI string + * + * @access public + * @return string + */ + function uri_string() + { + return $this->uri->uri_string; + } + +} +// END URI Class +?> \ No newline at end of file diff --git a/system/libraries/Unit_test.php b/system/libraries/Unit_test.php new file mode 100644 index 000000000..bf50350ae --- /dev/null +++ b/system/libraries/Unit_test.php @@ -0,0 +1,331 @@ +active == FALSE) + return; + + if (in_array($expected, array('is_string', 'is_bool', 'is_true', 'is_false', 'is_int', 'is_numeric', 'is_float', 'is_double', 'is_array', 'is_null'))) + { + $expected = str_replace('is_float', 'is_double', $expected); + $result = ($expected($test)) ? TRUE : FALSE; + $extype = str_replace(array('true', 'false'), 'bool', str_replace('is_', '', $expected)); + } + else + { + if ($this->strict == TRUE) + $result = ($test === $expected) ? TRUE : FALSE; + else + $result = ($test == $expected) ? TRUE : FALSE; + + $extype = gettype($expected); + } + + $back = $this->_backtrace(); + + $report[] = array ( + 'test_name' => $test_name, + 'test_datatype' => gettype($test), + 'res_datatype' => $extype, + 'result' => ($result === TRUE) ? 'passed' : 'failed', + 'file' => $back['file'], + 'line' => $back['line'] + ); + + $this->results[] = $report; + + return($this->report($this->result($report))); + } + + // -------------------------------------------------------------------- + + /** + * Generate a report + * + * Displays a table with the test data + * + * @access public + * @return string + */ + function report($result = array()) + { + if (count($result) == 0) + { + $result = $this->result(); + } + + $this->_parse_template(); + + $r = ''; + foreach ($result as $res) + { + $table = ''; + + foreach ($res as $key => $val) + { + $temp = $this->_template_rows; + $temp = str_replace('{item}', $key, $temp); + $temp = str_replace('{result}', $val, $temp); + $table .= $temp; + } + + $r .= str_replace('{rows}', $table, $this->_template); + } + + return $r; + } + + // -------------------------------------------------------------------- + + /** + * Use strict comparison + * + * Causes the evaluation to use === rather then == + * + * @access public + * @param bool + * @return null + */ + function use_strict($state = TRUE) + { + $this->strict = ($state == FALSE) ? FALSE : TRUE; + } + + // -------------------------------------------------------------------- + + /** + * Make Unit testing active + * + * Enables/disables unit testing + * + * @access public + * @param bool + * @return null + */ + function active($state = TRUE) + { + $this->active = ($state == FALSE) ? FALSE : TRUE; + } + + // -------------------------------------------------------------------- + + /** + * Result Array + * + * Returns the raw result data + * + * @access public + * @return array + */ + function result($results = array()) + { + $obj =& get_instance(); + $obj->load->language('unit_test'); + + if (count($results) == 0) + { + $results = $this->results; + } + + $retval = array(); + foreach ($results as $result) + { + $temp = array(); + foreach ($result as $key => $val) + { + if (is_array($val)) + { + foreach ($val as $k => $v) + { + if (FALSE !== ($line = $obj->lang->line(strtolower('ut_'.$v)))) + { + $v = $line; + } + $temp[$obj->lang->line('ut_'.$k)] = $v; + } + } + else + { + if (FALSE !== ($line = $obj->lang->line(strtolower('ut_'.$val)))) + { + $val = $line; + } + $temp[$obj->lang->line('ut_'.$key)] = $val; + } + } + + $retval[] = $temp; + } + + return $retval; + } + + // -------------------------------------------------------------------- + + /** + * Set the template + * + * This lets us set the template to be used to display results + * + * @access public + * @params string + * @return void + */ + function set_template($tempalte) + { + $this->_template = $tempalte; + } + + // -------------------------------------------------------------------- + + /** + * Generate a backtrace + * + * This lets us show file names and line numbers + * + * @access private + * @return array + */ + function _backtrace() + { + if (function_exists('debug_backtrace')) + { + $back = debug_backtrace(); + + $file = ( ! isset($back['1']['file'])) ? '' : $back['1']['file']; + $line = ( ! isset($back['1']['line'])) ? '' : $back['1']['line']; + + return array('file' => $file, 'line' => $line); + } + return array('file' => 'Unknown', 'line' => 'Unknown'); + } + + // -------------------------------------------------------------------- + + /** + * Get Default Template + * + * @access private + * @return string + */ + function _default_template() + { + $this->_template = ' +
+ + {rows} +
'; + + $this->_template_rows = ' + + {item} + {result} + + '; + } + + // -------------------------------------------------------------------- + + /** + * Parse Template + * + * Harvests the data within the template {pseudo-variables} + * + * @access private + * @return void + */ + function _parse_template() + { + if ( ! is_null($this->_template_rows)) + { + return; + } + + if (is_null($this->_template)) + { + $this->_default_template(); + return; + } + + if ( ! preg_match("/\{rows\}(.*?)\{\/rows\}/si", $this->_template, $match)) + { + $this->_default_template(); + return; + } + + $this->_template_rows = $match['1']; + $this->_template = str_replace($match['0'], '{rows}', $this->_template); + } + +} +// END Unit_test Class + +/** + * Helper functions to test boolean true/false + * + * + * @access private + * @return bool + */ +function is_true($test) +{ + return (is_bool($test) AND $test === TRUE) ? TRUE : FALSE; +} +function is_false($test) +{ + return (is_bool($test) AND $test === FALSE) ? TRUE : FALSE; +} + +?> \ No newline at end of file diff --git a/system/libraries/Upload.php b/system/libraries/Upload.php new file mode 100644 index 000000000..6d12dbcd7 --- /dev/null +++ b/system/libraries/Upload.php @@ -0,0 +1,775 @@ + 0) + { + $this->initialize($props); + } + + log_message('debug', "Upload Class Initialized"); + } + + // -------------------------------------------------------------------- + + /** + * Initialize preferences + * + * @access public + * @param array + * @return void + */ + function initialize($config = array()) + { + foreach ($config as $key => $val) + { + $method = 'set_'.$key; + if (method_exists($this, $method)) + { + $this->$method($val); + } + else + { + $this->$key = $val; + } + } + } + + // -------------------------------------------------------------------- + + /** + * Perform the file upload + * + * @access public + * @return bool + */ + function do_upload() + { + // Is $_FILES['userfile'] set? If not, no reason to continue. + if ( ! isset($_FILES['userfile'])) + { + $this->set_error('upload_userfile_not_set'); + return FALSE; + } + + // Is the upload path valid? + if ( ! $this->validate_upload_path()) + { + return FALSE; + } + + // Was the file able to be uploaded? If not, determine the reason why. + if ( ! is_uploaded_file($_FILES['userfile']['tmp_name'])) + { + $error = ( ! isset($_FILES['userfile']['error'])) ? 4 : $_FILES['userfile']['error']; + + switch($error) + { + case 1 : $this->set_error('upload_file_exceeds_limit'); + break; + case 3 : $this->set_error('upload_file_partial'); + break; + case 4 : $this->set_error('upload_no_file_selected'); + break; + default : $this->set_error('upload_no_file_selected'); + break; + } + + return FALSE; + } + + // Set the uploaded data as class variables + $this->file_temp = $_FILES['userfile']['tmp_name']; + $this->file_name = $_FILES['userfile']['name']; + $this->file_size = $_FILES['userfile']['size']; + $this->file_type = preg_replace("/^(.+?);.*$/", "\\1", $_FILES['userfile']['type']); + $this->file_type = strtolower($this->file_type); + $this->file_ext = $this->get_extension($_FILES['userfile']['name']); + + // Convert the file size to kilobytes + if ($this->file_size > 0) + { + $this->file_size = round($this->file_size/1024, 2); + } + + // Is the file type allowed to be uploaded? + if ( ! $this->is_allowed_filetype()) + { + $this->set_error('upload_invalid_filetype'); + return FALSE; + } + + // Is the file size within the allowed maximum? + if ( ! $this->is_allowed_filesize()) + { + $this->set_error('upload_invalid_filesize'); + return FALSE; + } + + // Are the image dimensions within the allowed size? + // Note: This can fail if the server has an open_basdir restriction. + if ( ! $this->is_allowed_dimensions()) + { + $this->set_error('upload_invalid_dimensions'); + return FALSE; + } + + // Sanitize the file name for security + $this->file_name = $this->clean_file_name($this->file_name); + + // Remove white spaces in the name + if ($this->remove_spaces == TRUE) + { + $this->file_name = preg_replace("/\s+/", "_", $this->file_name); + } + + /* + * Validate the file name + * This function appends an number onto the end of + * the file if one with the same name already exists. + * If it returns false there was a problem. + */ + $this->orig_name = $this->file_name; + + if ($this->overwrite == FALSE) + { + $this->file_name = $this->set_filename($this->file_path, $this->file_name); + + if ($this->file_name === FALSE) + { + return FALSE; + } + } + + /* + * Move the file to the final destination + * To deal with different server configurations + * we'll attempt to use copy() first. If that fails + * we'll use move_uploaded_file(). One of the two should + * reliably work in most environments + */ + if ( ! @copy($this->file_temp, $this->file_path.$this->file_name)) + { + if ( ! @move_uploaded_file($this->file_temp, $this->file_path.$this->file_name)) + { + $this->set_error('upload_destination_error'); + return FALSE; + } + } + + /* + * Run the file through the XSS hacking filter + * This helps prevent malicious code from being + * embedded within a file. Scripts can easily + * be disguised as images or other file types. + */ + if ($this->xss_clean == TRUE) + { + $this->do_xss_clean(); + } + + /* + * Set the finalized image dimensions + * This sets the image width/height (assuming the + * file was an image). We use this information + * in the "data" function. + */ + $this->set_image_properties($this->file_path.$this->file_name); + + return TRUE; + } + + // -------------------------------------------------------------------- + + /** + * Finalized Data Array + * + * Returns an associative array containing all of the information + * related to the upload, allowing the developer easy access in one array. + * + * @access public + * @return array + */ + function data() + { + return array ( + 'file_name' => $this->file_name, + 'file_type' => $this->file_type, + 'file_path' => $this->file_path, + 'full_path' => $this->file_path.$this->file_name, + 'raw_name' => str_replace($this->file_ext, '', $this->file_name), + 'orig_name' => $this->orig_name, + 'file_ext' => $this->file_ext, + 'file_size' => $this->file_size, + 'is_image' => $this->is_image(), + 'image_width' => $this->image_width, + 'image_height' => $this->image_height, + 'image_type' => $this->image_type, + 'image_size_str' => $this->image_size_str, + ); + } + + // -------------------------------------------------------------------- + + /** + * Set Upload Path + * + * @access public + * @param string + * @return void + */ + function set_upload_path($path) + { + $this->file_path = $path; + } + + // -------------------------------------------------------------------- + + /** + * Set the file name + * + * This function takes a filename/path as input and looks for the + * existnace of a file with the same name. If found, it will append a + * number to the end of the filename to avoid overwritting a pre-existing file. + * + * @access public + * @param string + * @param string + * @return string + */ + function set_filename($path, $filename) + { + if ($this->encrypt_name == TRUE) + { + mt_srand(); + $filename = md5(uniqid(mt_rand())).$this->file_ext; + } + + if ( ! file_exists($path.$filename)) + { + return $filename; + } + + $filename = str_replace($this->file_ext, '', $filename); + + $new_filename = ''; + for ($i = 1; $i < 100; $i++) + { + if ( ! file_exists($path.$filename.$i.$this->file_ext)) + { + $new_filename = $filename.$i.$this->file_ext; + break; + } + } + + if ($new_filename == '') + { + $this->set_error('upload_bad_filename'); + return FALSE; + } + else + { + return $new_filename; + } + } + + // -------------------------------------------------------------------- + + /** + * Set Maximum File Size + * + * @access public + * @param integer + * @return void + */ + function set_max_filesize($n) + { + $this->max_size = ( ! eregi("^[[:digit:]]+$", $n)) ? 0 : $n; + } + + // -------------------------------------------------------------------- + + /** + * Set Maximum Image Width + * + * @access public + * @param integer + * @return void + */ + function set_max_width($n) + { + $this->max_width = ( ! eregi("^[[:digit:]]+$", $n)) ? 0 : $n; + } + + // -------------------------------------------------------------------- + + /** + * Set Maximum Image Height + * + * @access public + * @param integer + * @return void + */ + function set_max_height($n) + { + $this->max_height = ( ! eregi("^[[:digit:]]+$", $n)) ? 0 : $n; + } + + // -------------------------------------------------------------------- + + /** + * Set Allowed File Types + * + * @access public + * @param string + * @return void + */ + function set_allowed_types($types) + { + $this->allowed_types = explode('|', $types); + } + + // -------------------------------------------------------------------- + + /** + * Set Image Properties + * + * Uses GD to determine the width/height/type of image + * + * @access public + * @param string + * @return void + */ + function set_image_properties($path = '') + { + if ( ! $this->is_image()) + { + return; + } + + if (function_exists('getimagesize')) + { + if (FALSE !== ($D = @getimagesize($path))) + { + $types = array(1 => 'gif', 2 => 'jpeg', 3 => 'png'); + + $this->image_width = $D['0']; + $this->image_height = $D['1']; + $this->image_type = ( ! isset($types[$D['2']])) ? 'unknown' : $types[$D['2']]; + $this->image_size_str = $D['3']; // string containing height and width + } + } + } + + // -------------------------------------------------------------------- + + /** + * Set XSS Clean + * + * Enables the XSS flag so that the file that was uploaded + * will be run through the XSS filter. + * + * @access public + * @param bool + * @return void + */ + function set_xss_clean($flag = FALSE) + { + $this->xss_clean = ($flag == TRUE) ? TRUE : FALSE; + } + + // -------------------------------------------------------------------- + + /** + * Validate the image + * + * @access public + * @return bool + */ + function is_image() + { + $img_mimes = array( + 'image/gif', + 'image/jpg', + 'image/jpe', + 'image/jpeg', + 'image/pjpeg', + 'image/png', + 'image/x-png' + ); + + + return (in_array($this->file_type, $img_mimes)) ? TRUE : FALSE; + } + + // -------------------------------------------------------------------- + + /** + * Verify that the filetype is allowed + * + * @access public + * @return bool + */ + function is_allowed_filetype() + { + if (count($this->allowed_types) == 0) + { + $this->set_error('upload_no_file_types'); + return FALSE; + } + + foreach ($this->allowed_types as $val) + { + $mime = $this->mimes_types(strtolower($val)); + + if (is_array($mime)) + { + if (in_array($this->file_type, $mime)) + { + return TRUE; + } + } + else + { + if ($mime == $this->file_type) + { + return TRUE; + } + } + } + + return FALSE; + } + + // -------------------------------------------------------------------- + + /** + * Verify that the file is within the allowed size + * + * @access public + * @return bool + */ + function is_allowed_filesize() + { + if ($this->max_size != 0 AND $this->file_size > $this->max_size) + { + return FALSE; + } + else + { + return TRUE; + } + } + + // -------------------------------------------------------------------- + + /** + * Verify that the image is within the allowed width/height + * + * @access public + * @return bool + */ + function is_allowed_dimensions() + { + if ( ! $this->is_image()) + { + return TRUE; + } + + if (function_exists('getimagesize')) + { + $D = @getimagesize($this->file_temp); + + if ($this->max_width > 0 AND $D['0'] > $this->max_width) + { + return FALSE; + } + + if ($this->max_height > 0 AND $D['1'] > $this->max_height) + { + return FALSE; + } + + return TRUE; + } + + return TRUE; + } + + // -------------------------------------------------------------------- + + /** + * VAlidate Upload Path + * + * Verifies that it is a valid upload path with proper permissions. + * + * + * @access public + * @return bool + */ + function validate_upload_path() + { + if ($this->file_path == '') + { + $this->set_error('upload_no_filepath'); + return FALSE; + } + + if (function_exists('realpath') AND @realpath($this->file_path) !== FALSE) + { + $this->file_path = str_replace("\\", "/", realpath($this->file_path)); + } + + if ( ! @is_dir($this->file_path)) + { + $this->set_error('upload_no_filepath'); + return FALSE; + } + + if ( ! is_writable($this->file_path)) + { + $this->set_error('upload_not_writable'); + return FALSE; + } + + $this->file_path = preg_replace("/(.+?)\/*$/", "\\1/", $this->file_path); + return TRUE; + } + + // -------------------------------------------------------------------- + + /** + * Extract the file extension + * + * @access public + * @param string + * @return string + */ + function get_extension($filename) + { + $x = explode('.', $filename); + return '.'.end($x); + } + + // -------------------------------------------------------------------- + + /** + * Clean the file name for security + * + * @access public + * @param string + * @return string + */ + function clean_file_name($filename) + { + $bad = array( + "", + "'", + "<", + ">", + '"', + '&', + '$', + '=', + ';', + '?', + '/', + "%20", + "%22", + "%3c", // < + "%253c", // < + "%3e", // > + "%0e", // > + "%28", // ( + "%29", // ) + "%2528", // ( + "%26", // & + "%24", // $ + "%3f", // ? + "%3b", // ; + "%3d" // = + ); + + foreach ($bad as $val) + { + $filename = str_replace($val, '', $filename); + } + + return $filename; + } + + // -------------------------------------------------------------------- + + /** + * Runs the file through the XSS clean function + * + * This prevents people from embedding malicious code in their files. + * I'm not sure that it won't negatively affect certain files in unexpected ways, + * but so far I haven't found that it causes trouble. + * + * @access public + * @return void + */ + function do_xss_clean() + { + $file = $this->file_path.$this->file_name; + + if (filesize($file) == 0) + { + return FALSE; + } + + if ( ! $fp = @fopen($file, 'rb')) + { + return FALSE; + } + + flock($fp, LOCK_EX); + + $data = fread($fp, filesize($file)); + + $obj =& get_instance(); + $data = $obj->input->xss_clean($data); + + fwrite($fp, $data); + flock($fp, LOCK_UN); + fclose($fp); + } + + // -------------------------------------------------------------------- + + /** + * Set an error message + * + * @access public + * @param string + * @return void + */ + function set_error($msg) + { + $obj =& get_instance(); + $obj->lang->load('upload'); + + if (is_array($msg)) + { + foreach ($msg as $val) + { + $msg = ($obj->lang->line($val) == FALSE) ? $val : $obj->lang->line($val); + $this->error_msg[] = $msg; + log_message('error', $msg); + } + } + else + { + $msg = ($obj->lang->line($msg) == FALSE) ? $msg : $obj->lang->line($msg); + $this->error_msg[] = $msg; + log_message('error', $msg); + } + } + + // -------------------------------------------------------------------- + + /** + * Display the error message + * + * @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; + } + + // -------------------------------------------------------------------- + + /** + * List of Mime Types + * + * This is a list of mime types. We use it to validate + * the "allowed types" set by the developer + * + * @access public + * @param string + * @return string + */ + function mimes_types($mime) + { + if (count($this->mimes) == 0) + { + if (@include(APPPATH.'config/mimes'.EXT)) + { + $this->mimes = $mimes; + unset($mimes); + } + } + + return ( ! isset($this->mimes[$mime])) ? FALSE : $this->mimes[$mime]; + } + +} +// END Upload Class +?> \ No newline at end of file diff --git a/system/libraries/Validation.php b/system/libraries/Validation.php new file mode 100644 index 000000000..df8c70ee8 --- /dev/null +++ b/system/libraries/Validation.php @@ -0,0 +1,692 @@ +'; + var $_error_suffix = '

'; + var $obj; + + + /** + * Constructor + * + */ + function CI_Validation() + { + $this->obj =& get_instance(); + log_message('debug', "Validation Class Initialized"); + } + + // -------------------------------------------------------------------- + + /** + * Set Fields + * + * This function takes an array of field names as input + * and generates class variables with the same name, which will + * either be blank or contain the $_POST value corresponding to it + * + * @access public + * @param string + * @param string + * @return void + */ + function set_fields($data = '', $field = '') + { + if ($data == '') + return; + + if ( ! is_array($data)) + { + if ($field == '') + return; + + $data = array($data => $field); + } + + $this->_fields = $data; + + foreach($this->_fields as $key => $val) + { + $this->$key = ( ! isset($_POST[$key]) OR is_array($_POST[$key])) ? '' : $this->prep_for_form($_POST[$key]); + + $error = $key.'_error'; + if ( ! isset($this->$error)) + { + $this->$error = ''; + } + } + } + + // -------------------------------------------------------------------- + + /** + * Set Rules + * + * This function takes an array of field names and validation + * rules as input ad simply stores is for use later. + * + * @access public + * @param mixed + * @param string + * @return void + */ + function set_rules($data, $rules = '') + { + if ( ! is_array($data)) + { + if ($rules == '') + return; + + $data[$data] = $rules; + } + + foreach ($data as $key => $val) + { + $this->_rules[$key] = $val; + } + } + + // -------------------------------------------------------------------- + + /** + * Set Error Message + * + * Lets users set their own error messages on the fly. Note: The key + * name has to match the function name that it corresponds to. + * + * @access public + * @param string + * @param string + * @return string + */ + function set_message($lang, $val = '') + { + if ( ! is_array($lang)) + { + $lang = array($lang => $val); + } + + $this->_error_messages = array_merge($this->_error_messages, $lang); + } + + // -------------------------------------------------------------------- + + /** + * Set The Error Delimiter + * + * Permits a prefix/suffix to be added to each error message + * + * @access public + * @param string + * @param string + * @return void + */ + function set_error_delimiters($prefix = '

', $suffix = '

') + { + $this->_error_prefix = $prefix; + $this->_error_suffix = $suffix; + } + + // -------------------------------------------------------------------- + + /** + * Run the Validator + * + * This function does all the work. + * + * @access public + * @return bool + */ + function run() + { + // Do we even have any data to process? Mm? + if (count($_POST) == 0 OR count($this->_rules) == 0) + { + return FALSE; + } + + // Load the language file containing error messages + $this->obj->lang->load('validation'); + + // Cycle through the rules and test for errors + foreach ($this->_rules as $field => $rules) + { + //Explode out the rules! + $ex = explode('|', $rules); + + // Is the field required? If not, if the field is blank we'll move on to the next text + if ( ! in_array('required', $ex)) + { + if ( ! isset($_POST[$field]) OR $_POST[$field] == '') + { + continue; + } + } + + /* + * Are we dealing with an "isset" rule? + * + * Before going further, we'll see if one of the rules + * is to check whether the item is set (typically this + * applies only to checkboxes). If so, we'll + * test for it here since there's not reason to go + * further + */ + if ( ! isset($_POST[$field])) + { + if (in_array('isset', $ex) OR in_array('required', $ex)) + { + if ( ! isset($this->messages['isset'])) + { + if (FALSE === ($line = $this->obj->lang->line('isset'))) + { + $line = 'The field was not set'; + } + } + else + { + $line = $this->_error_messages['isset']; + } + + $field = ( ! isset($this->_fields[$field])) ? $field : $this->_fields[$field]; + $this->_error_array[] = sprintf($line, $field); + } + + continue; + } + + /* + * Set the current field + * + * The various prepping functions need to know the + * current field name so they can do this: + * + * $_POST[$this->_current_field] == 'bla bla'; + */ + $this->_current_field = $field; + + // Cycle through the rules! + foreach ($ex As $rule) + { + + // Is the rule a callback? + $callback = FALSE; + if (substr($rule, 0, 9) == 'callback_') + { + $rule = substr($rule, 9); + $callback = TRUE; + } + + // Strip the parameter (if exists) from the rule + // Rules can contain a parameter: max_length[5] + $param = FALSE; + if (preg_match("/.*?(\[.*?\]).*/", $rule, $match)) + { + $param = substr(substr($match['1'], 1), 0, -1); + $rule = str_replace($match['1'], '', $rule); + } + + // Call the function that corresponds to the rule + if ($callback === TRUE) + { + if ( ! method_exists($this->obj, $rule)) + { + continue; + } + + $result = $this->obj->$rule($_POST[$field], $param); + } + else + { + if ( ! method_exists($this, $rule)) + { + /* + * Run the native PHP function if called for + * + * If our own wrapper function doesn't exist we see + * if a native PHP function does. Users can use + * any native PHP function call that has one param. + */ + if (function_exists($rule)) + { + $_POST[$field] = $rule($_POST[$field]); + $this->$field = $_POST[$field]; + } + + continue; + } + + $result = $this->$rule($_POST[$field], $param); + } + + // Did the rule test negatively? If so, grab the error. + if ($result === FALSE) + { + if ( ! isset($this->_error_messages[$rule])) + { + if (FALSE === ($line = $this->obj->lang->line($rule))) + { + $line = 'Unable to access an error message corresponding to your field name.'; + } + } + else + { + $line = $this->_error_messages[$rule];; + } + + // Build the error message + $mfield = ( ! isset($this->_fields[$field])) ? $field : $this->_fields[$field]; + $mparam = ( ! isset($this->_fields[$param])) ? $param : $this->_fields[$param]; + $message = sprintf($line, $mfield, $mparam); + + // Set the error variable. Example: $this->username_error + $error = $field.'_error'; + $this->$error = $this->_error_prefix.$message.$this->_error_suffix; + + // Add the error to the error array + $this->_error_array[] = $message; + continue 2; + } + } + } + + $total_errors = count($this->_error_array); + + /* + * Recompile the class variables + * + * If any prepping functions were called the $_POST data + * might now be different then the corresponding class + * variables so we'll set them anew. + */ + if ($total_errors > 0) + { + $this->_safe_form_data = TRUE; + } + + $this->set_fields(); + + // Did we end up with any errors? + if ($total_errors == 0) + { + return TRUE; + } + + // Generate the error string + foreach ($this->_error_array as $val) + { + $this->error_string .= $this->_error_prefix.$val.$this->_error_suffix."\n"; + } + + return FALSE; + } + + // -------------------------------------------------------------------- + + /** + * Required + * + * @access public + * @param string + * @return bool + */ + function required($str) + { + if ( ! is_array($str)) + { + return (trim($str) == '') ? FALSE : TRUE; + } + else + { + return ( ! empty($str)); + } + } + + // -------------------------------------------------------------------- + + /** + * Match one field to another + * + * @access public + * @param string + * @return bool + */ + function matches($str, $field) + { + if ( ! isset($_POST[$field])) + { + return FALSE; + } + + return ($str !== $_POST[$field]) ? FALSE : TRUE; + } + + // -------------------------------------------------------------------- + + /** + * Minimum Length + * + * @access public + * @param string + * @return bool + */ + function min_length($str, $val) + { + if ( ! ctype_digit($val)) + { + return FALSE; + } + + return (strlen($str) < $val) ? FALSE : TRUE; + } + + // -------------------------------------------------------------------- + + /** + * Max Length + * + * @access public + * @param string + * @return bool + */ + function max_length($str, $val) + { + if ( ! ctype_digit($val)) + { + return FALSE; + } + + return (strlen($str) > $val) ? FALSE : TRUE; + } + + // -------------------------------------------------------------------- + + /** + * Exact Length + * + * @access public + * @param string + * @return bool + */ + function exact_length($str, $val) + { + if ( ! ctype_digit($val)) + { + return FALSE; + } + + return (strlen($str) != $val) ? FALSE : TRUE; + } + + // -------------------------------------------------------------------- + + /** + * Valid Email + * + * @access public + * @param string + * @return bool + */ + function valid_email($str) + { + return ( ! preg_match("/^([a-z0-9\+_\-]+)(\.[a-z0-9\+_\-]+)*@([a-z0-9\-]+\.)+[a-z]{2,6}$/ix", $str)) ? FALSE : TRUE; + } + + // -------------------------------------------------------------------- + + /** + * Alpha + * + * @access public + * @param string + * @return bool + */ + function alpha($str) + { + return ( ! preg_match("/^([-a-z])+$/i", $str)) ? FALSE : TRUE; + } + + // -------------------------------------------------------------------- + + /** + * Alpha-numeric + * + * @access public + * @param string + * @return bool + */ + function alpha_numeric($str) + { + return ( ! preg_match("/^([-a-z0-9])+$/i", $str)) ? FALSE : TRUE; + } + + // -------------------------------------------------------------------- + + /** + * Alpha-numeric with underscores and dashes + * + * @access public + * @param string + * @return bool + */ + function alpha_dash($str) + { + return ( ! preg_match("/^([-a-z0-9_-])+$/i", $str)) ? FALSE : TRUE; + } + + // -------------------------------------------------------------------- + + /** + * Numeric + * + * @access public + * @param string + * @return bool + */ + function numeric($str) + { + return ( ! ctype_digit($str)) ? FALSE : TRUE; + } + + // -------------------------------------------------------------------- + + /** + * Set Select + * + * Enables pull-down lists to be set to the value the user + * selected in the event of an error + * + * @access public + * @param string + * @param string + * @return string + */ + function set_select($field = '', $value = '') + { + if ($field == '' OR $value == '' OR ! isset($_POST[$field])) + { + return ''; + } + + if ($_POST[$field] == $value) + { + return ' selected="selected"'; + } + } + + // -------------------------------------------------------------------- + + /** + * Set Radio + * + * Enables radio buttons to be set to the value the user + * selected in the event of an error + * + * @access public + * @param string + * @param string + * @return string + */ + function set_radio($field = '', $value = '') + { + if ($field == '' OR $value == '' OR ! isset($_POST[$field])) + { + return ''; + } + + if ($_POST[$field] == $value) + { + return ' checked="checked"'; + } + } + + // -------------------------------------------------------------------- + + /** + * Set Checkbox + * + * Enables checkboxes to be set to the value the user + * selected in the event of an error + * + * @access public + * @param string + * @param string + * @return string + */ + function set_checkbox($field = '', $value = '') + { + if ($field == '' OR $value == '' OR ! isset($_POST[$field])) + { + return ''; + } + + if ($_POST[$field] == $value) + { + return ' checked="checked"'; + } + } + + // -------------------------------------------------------------------- + + /** + * Prep data for form + * + * This function allows HTML to be safely shown in a form. + * Special characters are converted. + * + * @access public + * @param string + * @return string + */ + function prep_for_form($str = '') + { + if ($this->_safe_form_data == FALSE OR $str == '') + { + return $str; + } + + return str_replace(array("'", '"', '<', '>'), array("'", """, '<', '>'), stripslashes($str)); + } + + // -------------------------------------------------------------------- + + /** + * Prep URL + * + * @access public + * @param string + * @return string + */ + function prep_url($str = '') + { + if ($str == 'http://' OR $str == '') + { + $_POST[$this->_current_field] = ''; + return; + } + + if (substr($str, 0, 7) != 'http://' && substr($str, 0, 8) != 'https://') + { + $str = 'http://'.$str; + } + + $_POST[$this->_current_field] = $str; + } + + // -------------------------------------------------------------------- + + /** + * Strip Image Tags + * + * @access public + * @param string + * @return string + */ + function strip_image_tags($str) + { + $_POST[$this->_current_field] = $this->input->strip_image_tags($str); + } + + // -------------------------------------------------------------------- + + /** + * XSS Clean + * + * @access public + * @param string + * @return string + */ + function xss_clean($str) + { + $_POST[$this->_current_field] = $this->obj->input->xss_clean($str); + } + + // -------------------------------------------------------------------- + + /** + * Convert PHP tags to entities + * + * @access public + * @param string + * @return string + */ + function encode_php_tags($str) + { + $_POST[$this->_current_field] = str_replace(array(''), array('<?php', '<?PHP', '<?', '?>'), $str); + } + +} +// END Validation Class +?> \ No newline at end of file diff --git a/system/libraries/Xmlrpc.php b/system/libraries/Xmlrpc.php new file mode 100644 index 000000000..9eeb46a15 --- /dev/null +++ b/system/libraries/Xmlrpc.php @@ -0,0 +1,1409 @@ +xmlrpcName = $this->xmlrpcName; + $this->xmlrpc_backslash = chr(92).chr(92); + + // Types for info sent back and forth + $this->xmlrpcTypes = array( + $this->xmlrpcI4 => '1', + $this->xmlrpcInt => '1', + $this->xmlrpcBoolean => '1', + $this->xmlrpcString => '1', + $this->xmlrpcDouble => '1', + $this->xmlrpcDateTime => '1', + $this->xmlrpcBase64 => '1', + $this->xmlrpcArray => '2', + $this->xmlrpcStruct => '3' + ); + + // Array of Valid Parents for Various XML-RPC elements + $this->valid_parents = array('BOOLEAN' => array('VALUE'), + 'I4' => array('VALUE'), + 'INT' => array('VALUE'), + 'STRING' => array('VALUE'), + 'DOUBLE' => array('VALUE'), + 'DATETIME.ISO8601' => array('VALUE'), + 'BASE64' => array('VALUE'), + 'ARRAY' => array('VALUE'), + 'STRUCT' => array('VALUE'), + 'PARAM' => array('PARAMS'), + 'METHODNAME' => array('METHODCALL'), + 'PARAMS' => array('METHODCALL', 'METHODRESPONSE'), + 'MEMBER' => array('STRUCT'), + 'NAME' => array('MEMBER'), + 'DATA' => array('ARRAY'), + 'FAULT' => array('METHODRESPONSE'), + 'VALUE' => array('MEMBER', 'DATA', 'PARAM', 'FAULT') + ); + + + // XML-RPC Responses + $this->xmlrpcerr['unknown_method'] = '1'; + $this->xmlrpcstr['unknown_method'] = 'This is not a known method for this XML-RPC Server'; + $this->xmlrpcerr['invalid_return'] = '2'; + $this->xmlrpcstr['invalid_return'] = 'The XML data receieved was either invalid or not in the correct form for XML-RPC. Turn on debugging to examine the XML data further.'; + $this->xmlrpcerr['incorrect_params'] = '3'; + $this->xmlrpcstr['incorrect_params'] = 'Incorrect parameters were passed to method'; + $this->xmlrpcerr['introspect_unknown'] = '4'; + $this->xmlrpcstr['introspect_unknown'] = "Cannot inspect signature for request: method unknown"; + $this->xmlrpcerr['http_error'] = '5'; + $this->xmlrpcstr['http_error'] = "Did not receive a '200 OK' response from remote server."; + $this->xmlrpcerr['no_data'] = '6'; + $this->xmlrpcstr['no_data'] ='No data received from server.'; + + $this->initialize($config); + + log_message('debug', "XML-RPC Class Initialized"); + } + + + //------------------------------------- + // Initialize Prefs + //------------------------------------- + + function initialize($config = array()) + { + if (sizeof($config) > 0) + { + foreach ($config as $key => $val) + { + if (isset($this->$key)) + { + $this->$key = $val; + } + } + } + } + // END + + //------------------------------------- + // Take URL and parse it + //------------------------------------- + + function server($url, $port=80) + { + if (substr($url, 0, 4) != "http") + { + $url = "http://".$url; + } + + $parts = parse_url($url); + + $path = (!isset($parts['path'])) ? '/' : $parts['path']; + + if (isset($parts['query']) && $parts['query'] != '') + { + $path .= '?'.$parts['query']; + } + + $this->client = new XML_RPC_Client($path, $parts['host'], $port); + } + // END + + //------------------------------------- + // Set Timeout + //------------------------------------- + + function timeout($seconds=5) + { + if ( ! is_null($this->client) && is_int($seconds)) + { + $this->client->timeout = $seconds; + } + } + // END + + //------------------------------------- + // Set Methods + //------------------------------------- + + function method($function) + { + $this->method = $function; + } + // END + + //------------------------------------- + // Take Array of Data and Create Objects + //------------------------------------- + + function request($incoming) + { + if ( ! is_array($incoming)) + { + // Send Error + } + + foreach($incoming as $key => $value) + { + $this->data[$key] = $this->values_parsing($value); + } + } + // END + + + //------------------------------------- + // Set Debug + //------------------------------------- + + function set_debug($flag = TRUE) + { + $this->debug = ($flag == TRUE) ? TRUE : FALSE; + } + + //------------------------------------- + // Values Parsing + //------------------------------------- + + function values_parsing($value, $return = FALSE) + { + if (is_array($value) && isset($value['0'])) + { + if ( ! isset($value['1']) OR ! isset($this->xmlrpcTypes[strtolower($value['1'])])) + { + $temp = new XML_RPC_Values($value['0'], 'string'); + } + elseif(is_array($value['0']) && ($value['1'] == 'struct' OR $value['1'] == 'array')) + { + while (list($k) = each($value['0'])) + { + $value['0'][$k] = $this->values_parsing($value['0'][$k], TRUE); + } + + $temp = new XML_RPC_Values($value['0'], $value['1']); + } + else + { + $temp = new XML_RPC_Values($value['0'], $value['1']); + } + } + else + { + $temp = new XML_RPC_Values($value, 'string'); + } + + return $temp; + } + // END + + + //------------------------------------- + // Sends XML-RPC Request + //------------------------------------- + + function send_request() + { + $this->message = new XML_RPC_Message($this->method,$this->data); + $this->message->debug = $this->debug; + + if ( ! $this->result = $this->client->send($this->message)) + { + $this->error = $this->result->errstr; + return FALSE; + } + elseif( ! is_object($this->result->val)) + { + $this->error = $this->result->errstr; + return FALSE; + } + + $this->response = $this->result->decode(); + + return TRUE; + } + // END + + //------------------------------------- + // Returns Error + //------------------------------------- + + function display_error() + { + return $this->error; + } + // END + + //------------------------------------- + // Returns Remote Server Response + //------------------------------------- + + function display_response() + { + return $this->response; + } + // END + + //------------------------------------- + // Sends an Error Message for Server Request + //------------------------------------- + + function send_error_message($number, $message) + { + return new XML_RPC_Response('0',$number, $message); + } + // END + + + //------------------------------------- + // Send Response for Server Request + //------------------------------------- + + function send_response($response) + { + // $response should be array of values, which will be parsed + // based on their data and type into a valid group of XML-RPC values + + $response = $this->values_parsing($response); + + return new XML_RPC_Response($response); + } + // END + +} // END XML_RPC Class + + + +/** + * XML-RPC Client class + * + * @category XML-RPC + * @author Paul Burdick + * @link http://www.codeigniter.com/user_guide/libraries/xmlrpc.html + */ +class XML_RPC_Client extends CI_XML_RPC +{ + var $path = ''; + var $server = ''; + var $port = 80; + var $errno = ''; + var $errstring = ''; + var $timeout = 5; + var $no_multicall = false; + + function XML_RPC_Client($path, $server, $port=80) + { + parent::CI_XML_RPC(); + + $this->port = $port; + $this->server = $server; + $this->path = $path; + } + + function send($msg) + { + if (is_array($msg)) + { + // Multi-call disabled + $r = new XML_RPC_Response(0, $this->xmlrpcerr['multicall_recursion'],$this->xmlrpcstr['multicall_recursion']); + return $r; + } + + return $this->sendPayload($msg); + } + + function sendPayload($msg) + { + $fp = @fsockopen($this->server, $this->port,$this->errno, $this->errstr, $this->timeout); + + if (! is_resource($fp)) + { + error_log($this->xmlrpcstr['http_error']); + $r = new XML_RPC_Response(0, $this->xmlrpcerr['http_error'],$this->xmlrpcstr['http_error']); + return $r; + } + + if(empty($msg->payload)) + { + // $msg = XML_RPC_Messages + $msg->createPayload(); + } + + $r = "\r\n"; + $op = "POST {$this->path} HTTP/1.0$r"; + $op .= "Host: {$this->server}$r"; + $op .= "Content-Type: text/xml$r"; + $op .= "User-Agent: {$this->xmlrpcName}$r"; + $op .= "Content-Length: ".strlen($msg->payload). "$r$r"; + $op .= $msg->payload; + + + if (!fputs($fp, $op, strlen($op))) + { + error_log($this->xmlrpcstr['http_error']); + $r = new XML_RPC_Response(0, $this->xmlrpcerr['http_error'], $this->xmlrpcstr['http_error']); + return $r; + } + $resp = $msg->parseResponse($fp); + fclose($fp); + return $resp; + } + +} // end class XML_RPC_Client + + +/** + * XML-RPC Response class + * + * @category XML-RPC + * @author Paul Burdick + * @link http://www.codeigniter.com/user_guide/libraries/xmlrpc.html + */ +class XML_RPC_Response +{ + var $val = 0; + var $errno = 0; + var $errstr = ''; + var $headers = array(); + + function XML_RPC_Response($val, $code = 0, $fstr = '') + { + if ($code != 0) + { + // error + $this->errno = $code; + $this->errstr = htmlentities($fstr); + } + else if (!is_object($val)) + { + // programmer error, not an object + error_log("Invalid type '" . gettype($val) . "' (value: $val) passed to XML_RPC_Response. Defaulting to empty value."); + $this->val = new XML_RPC_Values(); + } + else + { + $this->val = $val; + } + } + + function faultCode() + { + return $this->errno; + } + + function faultString() + { + return $this->errstr; + } + + function value() + { + return $this->val; + } + + function prepare_response() + { + $result = "\n"; + if ($this->errno) + { + $result .= ' + + + + faultCode + ' . $this->errno . ' + + + faultString + ' . $this->errstr . ' + + + +'; + } + else + { + $result .= "\n\n" . + $this->val->serialize_class() . + "\n"; + } + $result .= "\n"; + return $result; + } + + function decode($array=FALSE) + { + $obj =& get_instance(); + + if ($array !== FALSE && is_array($array)) + { + while (list($key) = each($array)) + { + if (is_array($array[$key])) + { + $array[$key] = $this->decode($array[$key]); + } + else + { + $array[$key] = $obj->input->xss_clean($array[$key]); + } + } + + $result = $array; + } + else + { + $result = $this->xmlrpc_decoder($this->val); + + if (is_array($result)) + { + $result = $this->decode($result); + } + else + { + $result = $obj->input->xss_clean($result); + } + } + + return $result; + } + + + + //------------------------------------- + // XML-RPC Object to PHP Types + //------------------------------------- + + function xmlrpc_decoder($xmlrpc_val) + { + $kind = $xmlrpc_val->kindOf(); + + if($kind == 'scalar') + { + return $xmlrpc_val->scalarval(); + } + elseif($kind == 'array') + { + reset($xmlrpc_val->me); + list($a,$b) = each($xmlrpc_val->me); + $size = sizeof($b); + + $arr = array(); + + for($i = 0; $i < $size; $i++) + { + $arr[] = $this->xmlrpc_decoder($xmlrpc_val->me['array'][$i]); + } + return $arr; + } + elseif($kind == 'struct') + { + reset($xmlrpc_val->me['struct']); + $arr = array(); + + while(list($key,$value) = each($xmlrpc_val->me['struct'])) + { + $arr[$key] = $this->xmlrpc_decoder($value); + } + return $arr; + } + } + + + //------------------------------------- + // ISO-8601 time to server or UTC time + //------------------------------------- + + function iso8601_decode($time, $utc=0) + { + // return a timet in the localtime, or UTC + $t = 0; + if (ereg("([0-9]{4})([0-9]{2})([0-9]{2})T([0-9]{2}):([0-9]{2}):([0-9]{2})", $time, $regs)) + { + if ($utc == 1) + $t = gmmktime($regs[4], $regs[5], $regs[6], $regs[2], $regs[3], $regs[1]); + else + $t = mktime($regs[4], $regs[5], $regs[6], $regs[2], $regs[3], $regs[1]); + } + return $t; + } + +} // End Response Class + + + +/** + * XML-RPC Message class + * + * @category XML-RPC + * @author Paul Burdick + * @link http://www.codeigniter.com/user_guide/libraries/xmlrpc.html + */ +class XML_RPC_Message extends CI_XML_RPC +{ + var $payload; + var $method_name; + var $params = array(); + var $xh = array(); + + function XML_RPC_Message($method, $pars=0) + { + parent::CI_XML_RPC(); + + $this->method_name = $method; + if (is_array($pars) && sizeof($pars) > 0) + { + for($i=0; $iparams[] = $pars[$i]; + } + } + } + + //------------------------------------- + // Create Payload to Send + //------------------------------------- + + function createPayload() + { + $this->payload = "\r\n\r\n"; + $this->payload .= '' . $this->method_name . "\r\n"; + $this->payload .= "\r\n"; + + for($i=0; $iparams); $i++) + { + // $p = XML_RPC_Values + $p = $this->params[$i]; + $this->payload .= "\r\n".$p->serialize_class()."\r\n"; + } + + $this->payload .= "\r\n\r\n"; + } + + //------------------------------------- + // Parse External XML-RPC Server's Response + //------------------------------------- + + function parseResponse($fp) + { + $data = ''; + + while($datum = fread($fp, 4096)) + { + $data .= $datum; + } + + //------------------------------------- + // DISPLAY HTTP CONTENT for DEBUGGING + //------------------------------------- + + if ($this->debug === TRUE) + { + echo "
";
+			echo "---DATA---\n" . htmlspecialchars($data) . "\n---END DATA---\n\n";
+			echo "
"; + } + + //------------------------------------- + // Check for data + //------------------------------------- + + if($data == "") + { + error_log($this->xmlrpcstr['no_data']); + $r = new XML_RPC_Response(0, $this->xmlrpcerr['no_data'], $this->xmlrpcstr['no_data']); + return $r; + } + + + //------------------------------------- + // Check for HTTP 200 Response + //------------------------------------- + + if(ereg("^HTTP",$data) && !ereg("^HTTP/[0-9\.]+ 200 ", $data)) + { + $errstr= substr($data, 0, strpos($data, "\n")-1); + $r = new XML_RPC_Response(0, $this->xmlrpcerr['http_error'], $this->xmlrpcstr['http_error']. ' (' . $errstr . ')'); + return $r; + } + + //------------------------------------- + // Create and Set Up XML Parser + //------------------------------------- + + $parser = xml_parser_create($this->xmlrpc_defencoding); + + $this->xh[$parser] = array(); + $this->xh[$parser]['isf'] = 0; + $this->xh[$parser]['ac'] = ''; + $this->xh[$parser]['headers'] = array(); + $this->xh[$parser]['stack'] = array(); + $this->xh[$parser]['valuestack'] = array(); + $this->xh[$parser]['isf_reason'] = 0; + + xml_set_object($parser, $this); + 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'); + + + //------------------------------------- + // GET HEADERS + //------------------------------------- + + $lines = explode("\r\n", $data); + while (($line = array_shift($lines))) + { + if (strlen($line) < 1) + { + break; + } + $this->xh[$parser]['headers'][] = $line; + } + $data = implode("\r\n", $lines); + + + //------------------------------------- + // PARSE XML DATA + //------------------------------------- + + if (!xml_parse($parser, $data, sizeof($data))) + { + $errstr = sprintf('XML error: %s at line %d', + xml_error_string(xml_get_error_code($parser)), + xml_get_current_line_number($parser)); + //error_log($errstr); + $r = new XML_RPC_Response(0, $this->xmlrpcerr['invalid_return'], $this->xmlrpcstr['invalid_return']); + xml_parser_free($parser); + return $r; + } + xml_parser_free($parser); + + // --------------------------------------- + // Got Ourselves Some Badness, It Seems + // --------------------------------------- + + if ($this->xh[$parser]['isf'] > 1) + { + if ($this->debug === TRUE) + { + echo "---Invalid Return---\n"; + echo $this->xh[$parser]['isf_reason']; + echo "---Invalid Return---\n\n"; + } + + $r = new XML_RPC_Response(0, $this->xmlrpcerr['invalid_return'],$this->xmlrpcstr['invalid_return'].' '.$this->xh[$parser]['isf_reason']); + return $r; + } + elseif ( ! is_object($this->xh[$parser]['value'])) + { + $r = new XML_RPC_Response(0, $this->xmlrpcerr['invalid_return'],$this->xmlrpcstr['invalid_return'].' '.$this->xh[$parser]['isf_reason']); + return $r; + } + + //------------------------------------- + // DISPLAY XML CONTENT for DEBUGGING + //------------------------------------- + + if ($this->debug === TRUE) + { + echo "
";
+			
+			if (count($this->xh[$parser]['headers'] > 0))
+			{
+				echo "---HEADERS---\n";
+				foreach ($this->xh[$parser]['headers'] as $header)
+				{
+					echo "$header\n";
+				}
+				echo "---END HEADERS---\n\n";
+			}
+			
+			echo "---DATA---\n" . htmlspecialchars($data) . "\n---END DATA---\n\n";
+			
+			echo "---PARSED---\n" ;
+			var_dump($this->xh[$parser]['value']);
+			echo "\n---END PARSED---
"; + } + + //------------------------------------- + // SEND RESPONSE + //------------------------------------- + + $v = $this->xh[$parser]['value']; + + if ($this->xh[$parser]['isf']) + { + $errno_v = $v->me['struct']['faultCode']; + $errstr_v = $v->me['struct']['faultString']; + $errno = $errno_v->scalarval(); + + if ($errno == 0) + { + // FAULT returned, errno needs to reflect that + $errno = -1; + } + + $r = new XML_RPC_Response($v, $errno, $errstr_v->scalarval()); + } + else + { + $r = new XML_RPC_Response($v); + } + + $r->headers = $this->xh[$parser]['headers']; + return $r; + } + + // ------------------------------------ + // Begin Return Message Parsing section + // ------------------------------------ + + // quick explanation of components: + // ac - used to accumulate values + // isf - used to indicate a fault + // lv - used to indicate "looking for a value": implements + // the logic to allow values with no types to be strings + // params - used to store parameters in method calls + // method - used to store method name + // stack - array with parent tree of the xml element, + // used to validate the nesting of elements + + //------------------------------------- + // Start Element Handler + //------------------------------------- + + function open_tag($the_parser, $name, $attrs) + { + // If invalid nesting, then return + if ($this->xh[$the_parser]['isf'] > 1) return; + + // Evaluate and check for correct nesting of XML elements + + if (count($this->xh[$the_parser]['stack']) == 0) + { + if ($name != 'METHODRESPONSE' && $name != 'METHODCALL') + { + $this->xh[$the_parser]['isf'] = 2; + $this->xh[$the_parser]['isf_reason'] = 'Top level XML-RPC element is missing'; + return; + } + } + else + { + // not top level element: see if parent is OK + if (!in_array($this->xh[$the_parser]['stack'][0], $this->valid_parents[$name])) + { + $this->xh[$the_parser]['isf'] = 2; + $this->xh[$the_parser]['isf_reason'] = "XML-RPC element $name cannot be child of ".$this->xh[$the_parser]['stack'][0]; + return; + } + } + + switch($name) + { + case 'STRUCT': + case 'ARRAY': + // Creates array for child elements + + $cur_val = array('value' => array(), + 'type' => $name); + + array_unshift($this->xh[$the_parser]['valuestack'], $cur_val); + break; + case 'METHODNAME': + case 'NAME': + $this->xh[$the_parser]['ac'] = ''; + break; + case 'FAULT': + $this->xh[$the_parser]['isf'] = 1; + break; + case 'PARAM': + $this->xh[$the_parser]['value'] = null; + break; + case 'VALUE': + $this->xh[$the_parser]['vt'] = 'value'; + $this->xh[$the_parser]['ac'] = ''; + $this->xh[$the_parser]['lv'] = 1; + break; + case 'I4': + case 'INT': + case 'STRING': + case 'BOOLEAN': + case 'DOUBLE': + case 'DATETIME.ISO8601': + case 'BASE64': + if ($this->xh[$the_parser]['vt'] != 'value') + { + //two data elements inside a value: an error occurred! + $this->xh[$the_parser]['isf'] = 2; + $this->xh[$the_parser]['isf_reason'] = "'Twas a $name element following a ".$this->xh[$the_parser]['vt']." element inside a single value"; + return; + } + + $this->xh[$the_parser]['ac'] = ''; + break; + case 'MEMBER': + // Set name of to nothing to prevent errors later if no is found + $this->xh[$the_parser]['valuestack'][0]['name'] = ''; + + // Set NULL value to check to see if value passed for this param/member + $this->xh[$the_parser]['value'] = null; + break; + case 'DATA': + case 'METHODCALL': + case 'METHODRESPONSE': + case 'PARAMS': + // valid elements that add little to processing + break; + default: + /// An Invalid Element is Found, so we have trouble + $this->xh[$the_parser]['isf'] = 2; + $this->xh[$the_parser]['isf_reason'] = "Invalid XML-RPC element found: $name"; + break; + } + + // Add current element name to stack, to allow validation of nesting + array_unshift($this->xh[$the_parser]['stack'], $name); + + if ($name != 'VALUE') $this->xh[$the_parser]['lv'] = 0; + } + // END + + + //------------------------------------- + // End Element Handler + //------------------------------------- + + function closing_tag($the_parser, $name) + { + if ($this->xh[$the_parser]['isf'] > 1) return; + + // Remove current element from stack and set variable + // NOTE: If the XML validates, then we do not have to worry about + // the opening and closing of elements. Nesting is checked on the opening + // tag so we be safe there as well. + + $curr_elem = array_shift($this->xh[$the_parser]['stack']); + + switch($name) + { + case 'STRUCT': + case 'ARRAY': + $cur_val = array_shift($this->xh[$the_parser]['valuestack']); + $this->xh[$the_parser]['value'] = ( ! isset($cur_val['values'])) ? array() : $cur_val['values']; + $this->xh[$the_parser]['vt'] = strtolower($name); + break; + case 'NAME': + $this->xh[$the_parser]['valuestack'][0]['name'] = $this->xh[$the_parser]['ac']; + break; + case 'BOOLEAN': + case 'I4': + case 'INT': + case 'STRING': + case 'DOUBLE': + case 'DATETIME.ISO8601': + case 'BASE64': + $this->xh[$the_parser]['vt'] = strtolower($name); + + if ($name == 'STRING') + { + $this->xh[$the_parser]['value'] = $this->xh[$the_parser]['ac']; + } + elseif ($name=='DATETIME.ISO8601') + { + $this->xh[$the_parser]['vt'] = $this->xmlrpcDateTime; + $this->xh[$the_parser]['value'] = $this->xh[$the_parser]['ac']; + } + elseif ($name=='BASE64') + { + $this->xh[$the_parser]['value'] = base64_decode($this->xh[$the_parser]['ac']); + } + elseif ($name=='BOOLEAN') + { + // Translated BOOLEAN values to TRUE AND FALSE + if ($this->xh[$the_parser]['ac'] == '1') + { + $this->xh[$the_parser]['value'] = TRUE; + } + else + { + $this->xh[$the_parser]['value'] = FALSE; + } + } + elseif ($name=='DOUBLE') + { + // we have a DOUBLE + // we must check that only 0123456789-. are characters here + if (!ereg("^[+-]?[eE0123456789 \\t\\.]+$", $this->xh[$the_parser]['ac'])) + { + $this->xh[$the_parser]['value'] = 'ERROR_NON_NUMERIC_FOUND'; + } + else + { + $this->xh[$the_parser]['value'] = (double)$this->xh[$the_parser]['ac']; + } + } + else + { + // we have an I4/INT + // we must check that only 0123456789- are characters here + if (!ereg("^[+-]?[0123456789 \\t]+$", $this->xh[$the_parser]['ac'])) + { + $this->xh[$the_parser]['value'] = 'ERROR_NON_NUMERIC_FOUND'; + } + else + { + $this->xh[$the_parser]['value'] = (int)$this->xh[$the_parser]['ac']; + } + } + $this->xh[$the_parser]['ac'] = ''; + $this->xh[$the_parser]['lv'] = 3; // indicate we've found a value + break; + case 'VALUE': + // This if() detects if no scalar was inside + if ($this->xh[$the_parser]['vt']=='value') + { + $this->xh[$the_parser]['value'] = $this->xh[$the_parser]['ac']; + $this->xh[$the_parser]['vt'] = $this->xmlrpcString; + } + + // build the XML-RPC value out of the data received, and substitute it + $temp = new XML_RPC_Values($this->xh[$the_parser]['value'], $this->xh[$the_parser]['vt']); + + if (count($this->xh[$the_parser]['valuestack']) && $this->xh[$the_parser]['valuestack'][0]['type'] == 'ARRAY') + { + // Array + $this->xh[$the_parser]['valuestack'][0]['values'][] = $temp; + } + else + { + // Struct + $this->xh[$the_parser]['value'] = $temp; + } + break; + case 'MEMBER': + $this->xh[$the_parser]['ac']=''; + + // If value add to array in the stack for the last element built + if ($this->xh[$the_parser]['value']) + { + $this->xh[$the_parser]['valuestack'][0]['values'][$this->xh[$the_parser]['valuestack'][0]['name']] = $this->xh[$the_parser]['value']; + } + break; + case 'DATA': + $this->xh[$the_parser]['ac']=''; + break; + case 'PARAM': + if ($this->xh[$the_parser]['value']) + { + $this->xh[$the_parser]['params'][] = $this->xh[$the_parser]['value']; + } + break; + case 'METHODNAME': + $this->xh[$the_parser]['method'] = ereg_replace("^[\n\r\t ]+", '', $this->xh[$the_parser]['ac']); + break; + case 'PARAMS': + case 'FAULT': + case 'METHODCALL': + case 'METHORESPONSE': + // We're all good kids with nuthin' to do + break; + default: + // End of an Invalid Element. Taken care of during the opening tag though + break; + } + } + + //------------------------------------- + // Parses Character Data + //------------------------------------- + + function character_data($the_parser, $data) + { + if ($this->xh[$the_parser]['isf'] > 1) return; // XML Fault found already + + // If a value has not been found + if ($this->xh[$the_parser]['lv'] != 3) + { + if ($this->xh[$the_parser]['lv'] == 1) + { + $this->xh[$the_parser]['lv'] = 2; // Found a value + } + + if( ! @isset($this->xh[$the_parser]['ac'])) + { + $this->xh[$the_parser]['ac'] = ''; + } + + $this->xh[$the_parser]['ac'] .= $data; + } + } + + + function addParam($par) { $this->params[]=$par; } + + function output_parameters($array=FALSE) + { + $obj =& get_instance(); + + if ($array !== FALSE && is_array($array)) + { + while (list($key) = each($array)) + { + if (is_array($array[$key])) + { + $array[$key] = $this->output_parameters($array[$key]); + } + else + { + $array[$key] = $obj->input->xss_clean($array[$key]); + } + } + + $parameters = $array; + } + else + { + $parameters = array(); + + for ($i = 0; $i < sizeof($this->params); $i++) + { + $a_param = $this->decode_message($this->params[$i]); + + if (is_array($a_param)) + { + $parameters[] = $this->output_parameters($a_param); + } + else + { + $parameters[] = $obj->input->xss_clean($a_param); + } + } + } + + return $parameters; + } + + + function decode_message($param) + { + $kind = $param->kindOf(); + + if($kind == 'scalar') + { + return $param->scalarval(); + } + elseif($kind == 'array') + { + reset($param->me); + list($a,$b) = each($param->me); + + $arr = array(); + + for($i = 0; $i < sizeof($b); $i++) + { + $arr[] = $this->decode_message($param->me['array'][$i]); + } + + return $arr; + } + elseif($kind == 'struct') + { + reset($param->me['struct']); + + $arr = array(); + + while(list($key,$value) = each($param->me['struct'])) + { + $arr[$key] = $this->decode_message($value); + } + + return $arr; + } + } + +} // End XML_RPC_Messages class + + + +/** + * XML-RPC Values class + * + * @category XML-RPC + * @author Paul Burdick + * @link http://www.codeigniter.com/user_guide/libraries/xmlrpc.html + */ +class XML_RPC_Values extends CI_XML_RPC +{ + var $me = array(); + var $mytype = 0; + + function XML_RPC_Values($val=-1, $type='') + { + parent::CI_XML_RPC(); + + if ($val != -1 || $type != '') + { + $type = $type == '' ? 'string' : $type; + + if ($this->xmlrpcTypes[$type] == 1) + { + $this->addScalar($val,$type); + } + elseif ($this->xmlrpcTypes[$type] == 2) + { + $this->addArray($val); + } + elseif ($this->xmlrpcTypes[$type] == 3) + { + $this->addStruct($val); + } + } + } + + function addScalar($val, $type='string') + { + $typeof = $this->xmlrpcTypes[$type]; + + if ($this->mytype==1) + { + echo 'XML_RPC_Values: scalar can have only one value
'; + return 0; + } + + if ($typeof != 1) + { + echo 'XML_RPC_Values: not a scalar type (${typeof})
'; + return 0; + } + + if ($type == $this->xmlrpcBoolean) + { + if (strcasecmp($val,'true')==0 || $val==1 || ($val==true && strcasecmp($val,'false'))) + { + $val = 1; + } + else + { + $val=0; + } + } + + if ($this->mytype == 2) + { + // adding to an array here + $ar = $this->me['array']; + $ar[] = new XML_RPC_Values($val, $type); + $this->me['array'] = $ar; + } + else + { + // a scalar, so set the value and remember we're scalar + $this->me[$type] = $val; + $this->mytype = $typeof; + } + return 1; + } + + function addArray($vals) + { + if ($this->mytype != 0) + { + echo 'XML_RPC_Values: already initialized as a [' . $this->kindOf() . ']
'; + return 0; + } + + $this->mytype = $this->xmlrpcTypes['array']; + $this->me['array'] = $vals; + return 1; + } + + function addStruct($vals) + { + if ($this->mytype != 0) + { + echo 'XML_RPC_Values: already initialized as a [' . $this->kindOf() . ']
'; + return 0; + } + $this->mytype = $this->xmlrpcTypes['struct']; + $this->me['struct'] = $vals; + return 1; + } + + function kindOf() + { + switch($this->mytype) + { + case 3: + return 'struct'; + break; + case 2: + return 'array'; + break; + case 1: + return 'scalar'; + break; + default: + return 'undef'; + } + } + + function serializedata($typ, $val) + { + $rs = ''; + + switch($this->xmlrpcTypes[$typ]) + { + case 3: + // struct + $rs .= "\n"; + reset($val); + while(list($key2, $val2) = each($val)) + { + $rs .= "\n{$key2}\n"; + $rs .= $this->serializeval($val2); + $rs .= "\n"; + } + $rs .= ''; + break; + case 2: + // array + $rs .= "\n\n"; + for($i=0; $i < sizeof($val); $i++) + { + $rs .= $this->serializeval($val[$i]); + } + $rs.="\n\n"; + break; + case 1: + // others + switch ($typ) + { + case $this->xmlrpcBase64: + $rs .= "<{$typ}>" . base64_encode($val) . "\n"; + break; + case $this->xmlrpcBoolean: + $rs .= "<{$typ}>" . ($val ? '1' : '0') . "\n"; + break; + case $this->xmlrpcString: + $rs .= "<{$typ}>" . htmlspecialchars($val). "\n"; + break; + default: + $rs .= "<{$typ}>{$val}\n"; + break; + } + default: + break; + } + return $rs; + } + + function serialize_class() + { + return $this->serializeval($this); + } + + function serializeval($o) + { + + $ar = $o->me; + reset($ar); + + list($typ, $val) = each($ar); + $rs = "\n".$this->serializedata($typ, $val)."\n"; + return $rs; + } + + function scalarval() + { + reset($this->me); + list($a,$b) = each($this->me); + return $b; + } + + + //------------------------------------- + // Encode time in ISO-8601 form. + //------------------------------------- + + // Useful for sending time in XML-RPC + + function iso8601_encode($time, $utc=0) + { + if ($utc == 1) + { + $t = strftime("%Y%m%dT%H:%M:%S", $time); + } + else + { + if (function_exists('gmstrftime')) + $t = gmstrftime("%Y%m%dT%H:%M:%S", $time); + else + $t = strftime("%Y%m%dT%H:%M:%S", $time - date('Z')); + } + return $t; + } + +} +// END XML_RPC_Values Class +?> \ No newline at end of file diff --git a/system/libraries/Xmlrpcs.php b/system/libraries/Xmlrpcs.php new file mode 100644 index 000000000..eaec87a6d --- /dev/null +++ b/system/libraries/Xmlrpcs.php @@ -0,0 +1,492 @@ +set_system_methods(); + + if (isset($config['functions']) && is_array($config['functions'])) + { + $this->methods = $config['functions']; + } + + log_message('debug', "XML-RPC Server Class Initialized"); + } + + //------------------------------------- + // Initialize Prefs and Serve + //------------------------------------- + + function initialize($config=array()) + { + if (isset($config['functions']) && is_array($config['functions'])) + { + $this->methods = $config['functions']; + } + + if (isset($config['debug'])) + { + $this->debug = $config['debug']; + } + } + + //------------------------------------- + // Setting of System Methods + //------------------------------------- + + function set_system_methods () + { + $system_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 + //------------------------------------- + + function serve() + { + $r = $this->parseRequest(); + $payload = 'xmlrpc_defencoding.'"?'.'>'."\n"; + $payload .= $this->debug_msg; + $payload .= $r->prepare_response(); + + header("Content-Type: text/xml"); + header("Content-Length: ".strlen($payload)); + echo $payload; + } + + //------------------------------------- + // Add Method to Class + //------------------------------------- + + function add_to_map($methodname,$function,$sig,$doc) + { + $this->methods[$methodname] = array( + 'function' => $function, + 'signature' => $sig, + 'docstring' => $doc + ); + } + + + //------------------------------------- + // Parse Server Request + //------------------------------------- + + function parseRequest($data='') + { + global $HTTP_RAW_POST_DATA; + + //------------------------------------- + // Get Data + //------------------------------------- + + if ($data == '') + { + $data = $HTTP_RAW_POST_DATA; + } + + + //------------------------------------- + // Set up XML Parser + //------------------------------------- + + $parser = xml_parser_create($this->xmlrpc_defencoding); + $parser_object = new XML_RPC_Message("filler"); + + $parser_object->xh[$parser] = array(); + $parser_object->xh[$parser]['isf'] = 0; + $parser_object->xh[$parser]['isf_reason'] = ''; + $parser_object->xh[$parser]['params'] = array(); + $parser_object->xh[$parser]['stack'] = array(); + $parser_object->xh[$parser]['valuestack'] = array(); + $parser_object->xh[$parser]['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[$parser]['isf']) + { + return new XML_RPC_Response(0, + $this->xmlrpcerr['invalid_return'], + $this->xmlrpcstr['invalid_retrun']); + } + else + { + xml_parser_free($parser); + + $m = new XML_RPC_Message($parser_object->xh[$parser]['method']); + $plist=''; + + for($i=0; $i < sizeof($parser_object->xh[$parser]['params']); $i++) + { + $plist .= "$i - " . print_r(get_object_vars($parser_object->xh[$parser]['params'][$i]), TRUE). ";\n"; + + $m->addParam($parser_object->xh[$parser]['params'][$i]); + } + + if ($this->debug === TRUE) + { + echo "
";
+				echo "---PLIST---\n" . $plist . "\n---PLIST END---\n\n";
+				echo "
"; + } + + $r = $this->execute($m); + } + + //------------------------------------- + // SET DEBUGGING MESSAGE + //------------------------------------- + + if ($this->debug === TRUE) + { + $this->debug_msg = "\n"; + } + + return $r; + } + + //------------------------------------- + // Executes the Method + //------------------------------------- + + function execute($m) + { + $methName = $m->method_name; + + // Check to see if it is a system call + // If so, load the system_methods + $sysCall = ereg("^system\.", $methName); + $methods = $sysCall ? $this->system_methods : $this->methods; + + //------------------------------------- + // Check for Function + //------------------------------------- + + if (!isset($methods[$methName]['function'])) + { + return new XML_RPC_Response(0, + $this->xmlrpcerr['unknown_method'], + $this->xmlrpcstr['unknown_method']); + } + else + { + // See if we are calling function in an object + + $method_parts = explode(".",$methods[$methName]['function']); + $objectCall = (isset($method_parts['1']) && $method_parts['1'] != "") ? true : false; + + 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($methods[$methName]['function'])) + { + return new XML_RPC_Response(0, + $this->xmlrpcerr['unknown_method'], + $this->xmlrpcstr['unknown_method']); + } + } + + //------------------------------------- + // Checking Methods Signature + //------------------------------------- + + if (isset($methods[$methName]['signature'])) + { + $sig = $methods[$methName]['signature']; + for($i=0; $iparams)+1) + { + for($n=0; $n < sizeof($m->params); $n++) + { + $p = $m->params[$n]; + $pt = ($p->kindOf() == 'scalar') ? $p->scalartyp() : $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) + { + if ($method_parts['1'] == "this") + { + return call_user_func(array($this, $method_parts['0']), $m); + } + else + { + $obj =& get_instance(); + return $obj->$method_parts['1']($m); + //$class = new $method_parts['0']; + //return $class->$method_parts['1']($m); + //return call_user_func(array(&$method_parts['0'],$method_parts['1']), $m); + } + } + else + { + return call_user_func($methods[$methName]['function'], $m); + } + } + + + //------------------------------------- + // Server Function: List Methods + //------------------------------------- + + 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 + //------------------------------------- + + function methodSignature($m) + { + $methName = $m->getParam(0); + $method_name = $methName->scalarval(); + + $methods = ereg("^system\.", $method_name) ? $this->system_methods : $this->methods; + + if (isset($methods[$method_name])) + { + if ($methods[$method_name]['signature']) + { + $sigs = array(); + $signature = $methods[$method_name]['signature']; + + for($i=0; $i < sizeof($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 + //------------------------------------- + + function methodHelp($m) + { + $methName = $m->getParam(0); + $method_name = $methName->scalarval(); + + $methods = ereg("^system\.", $method_name) ? $this->system_methods : $this->methods; + + if (isset($methods[$methName])) + { + $docstring = isset($methods[$method_name]['docstring']) ? $methods[$method_name]['docstring'] : ''; + $r = new XML_RPC_Response(new XML_RPC_Values($docstring, 'string')); + } + else + { + $r = new XML_RPC_Response(0, $this->xmlrpcerr['introspect_unknown'], $this->xmlrpcstr['introspect_unknown']); + } + return $r; + } + + //------------------------------------- + // Server Function: Multi-call + //------------------------------------- + + function multicall($m) + { + $calls = $m->getParam(0); + list($a,$b)=each($calls->me); + $result = array(); + + for ($i = 0; $i < sizeof($b); $i++) + { + $call = $calls->me['array'][$i]; + $result[$i] = $this->do_multicall($call); + } + + return new XML_RPC_Response(new XML_RPC_Values($result, 'array')); + } + + + //------------------------------------- + // Multi-call Function: Error Handling + //------------------------------------- + + 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 + //------------------------------------- + + 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' || $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 = sizeof($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'); + } + +} +// END XML_RPC_Server class +?> \ No newline at end of file diff --git a/system/libraries/index.html b/system/libraries/index.html new file mode 100644 index 000000000..5a1f5d6ae --- /dev/null +++ b/system/libraries/index.html @@ -0,0 +1,15 @@ + + + + +403 Forbidden + + + + + +

Directory access is forbidden.

+ + + + \ No newline at end of file diff --git a/system/logs/index.html b/system/logs/index.html new file mode 100644 index 000000000..5a1f5d6ae --- /dev/null +++ b/system/logs/index.html @@ -0,0 +1,15 @@ + + + + +403 Forbidden + + + + + +

Directory access is forbidden.

+ + + + \ No newline at end of file diff --git a/system/plugins/captcha_pi.php b/system/plugins/captcha_pi.php new file mode 100644 index 000000000..54944b823 --- /dev/null +++ b/system/plugins/captcha_pi.php @@ -0,0 +1,346 @@ +load->plugin('captcha'); + +Once loaded you can generate a captcha like this: + + $vals = array( + 'word' => 'Random word', + 'img_path' => './captcha/', + 'img_url' => 'http://www.your-site.com/captcha/', + 'font_path' => './system/texb.ttf', + 'img_width' => '150', + 'img_height' => 30, + 'expiration' => 7200 + ); + + $cap = create_captcha($vals); + echo $cap['image']; + + +NOTES: + + The captcha function requires the GD image library. + + Only the img_path and img_url are required. + + If a "word" is not supplied, the function will generate a random + ASCII string. You might put together your own word library that + you can draw randomly from. + + If you do not specify a path to a TRUE TYPE font, the native ugly GD + font will be used. + + The "captcha" folder must be writable (666, or 777) + + The "expiration" (in seconds) signifies how long an image will + remain in the captcha folder before it will be deleted. The default + is two hours. + +RETURNED DATA + +The create_captcha() function returns an associative array with this data: + + [array] + ( + 'image' => IMAGE TAG + 'time' => TIMESTAMP (in microtime) + 'word' => CAPTCHA WORD + ) + +The "image" is the actual image tag: + + +The "time" is the micro timestamp used as the image name without the file +extension. It will be a number like this: 1139612155.3422 + +The "word" is the word that appears in the captcha image, which if not +supplied to the function, will be a random string. + + +ADDING A DATABASE + +In order for the captcha function to prevent someone from posting, you will need +to add the information returned from create_captcha() function to your database. +Then, when the data from the form is submitted by the user you will need to verify +that the data exists in the database and has not expired. + +Here is a table prototype: + + CREATE TABLE captcha ( + captcha_id bigint(13) unsigned NOT NULL auto_increment, + captcha_time int(10) unsigned NOT NULL, + ip_address varchar(16) default '0' NOT NULL, + word varchar(20) NOT NULL, + PRIMARY KEY (captcha_id), + KEY (word) + ) + + +Here is an example of usage with a DB. + +On the page where the captcha will be shown you'll have something like this: + + $this->load->plugin('captcha'); + $vals = array( + 'img_path' => './captcha/', + 'img_url' => 'http://www.your-site.com/captcha/' + ); + + $cap = create_captcha($vals); + + $data = array( + 'captcha_id' => '', + 'captcha_time' => $cap['time'], + 'ip_address' => $this->input->ip_address(), + 'word' => $cap['word'] + ); + + $query = $this->db->insert_string('captcha', $data); + $this->db->query($query); + + echo 'Submit the word you see below:'; + echo $cap['image']; + echo ''; + + +Then, on the page that accepts the submission you'll have something like this: + + // First, delete old captchas + $expiration = time()-7200; // Two hour limit + $DB->query("DELETE FROM captcha WHERE captcha_time < ".$expiration); + + // Then see if a captcha exists: + $sql = "SELECT COUNT(*) AS count FROM captcha WHERE word = ? AND ip_address = ? AND date > ?"; + $binds = array($_POST['captcha'], $this->input->ip_address(), $expiration); + $query = $this->db->query($sql, $binds); + $row = $query->row(); + + if ($row->count == 0) + { + echo "You must submit the word that appears in the image"; + } + +*/ + + + +/** +|========================================================== +| Create Captcha +|========================================================== +| +*/ +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); + + 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 + // ----------------------------------- + + $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); +} + +?> \ No newline at end of file diff --git a/system/plugins/index.html b/system/plugins/index.html new file mode 100644 index 000000000..5a1f5d6ae --- /dev/null +++ b/system/plugins/index.html @@ -0,0 +1,15 @@ + + + + +403 Forbidden + + + + + +

Directory access is forbidden.

+ + + + \ No newline at end of file diff --git a/system/plugins/js_calendar_pi.php b/system/plugins/js_calendar_pi.php new file mode 100644 index 000000000..16c3f4136 --- /dev/null +++ b/system/plugins/js_calendar_pi.php @@ -0,0 +1,604 @@ +load->plugin('js_calendar'); + +Once loaded you'll add the calendar script to the of your page like this: + + + +The above function will be passed the name of your form. + +Then to show the actual calendar you'll do this: + + +

+ +

Today

+
+ + +Note: The first parameter is the name of the field containing your date, the second parameter contains the "now" time, +and the third tells the calendar whether to highlight the current day or not. + +Lastly, you'll need some CSS for your calendar: + +.calendar { + border: 1px #6975A3 solid; + background-color: transparent; +} +.calheading { + background-color: #7C8BC0; + color: #fff; + font-family: Lucida Grande, Verdana, Geneva, Sans-serif; + font-size: 11px; + font-weight: bold; + text-align: center; +} +.calnavleft { + background-color: #7C8BC0; + font-family: Lucida Grande, Verdana, Geneva, Sans-serif; + font-size: 10px; + font-weight: bold; + color: #fff; + padding: 4px; + cursor: pointer; +} +.calnavright { + background-color: #7C8BC0; + font-family: Lucida Grande, Verdana, Geneva, Sans-serif; + font-size: 10px; + font-weight: bold; + color: #fff; + text-align: right; + padding: 4px; + cursor: pointer; +} +.caldayheading { + background-color: #000; + color: #fff; + font-family: Lucida Grande, Verdana, Geneva, Sans-serif; + font-size: 10px; + text-align: center; + padding: 6px 2px 6px 2px; +} +.caldaycells{ + color: #000; + background-color: #D1D7E6; + font-family: Lucida Grande, Verdana, Geneva, Sans-serif; + font-size: 11px; + text-align: center; + padding: 4px; + border: 1px #E0E5F1 solid; + cursor: pointer; +} +.caldaycellhover{ + color: #fff; + background-color: #B3BCD4; + font-family: Lucida Grande, Verdana, Geneva, Sans-serif; + font-size: 11px; + text-align: center; + padding: 4px; + border: 1px #B3BCD4 solid; + cursor: pointer; +} +.caldayselected{ + background-color: #737FAC; + color: #fff; + font-family: Lucida Grande, Verdana, Geneva, Sans-serif; + font-size: 11px; + font-weight: bold; + text-align: center; + border: 1px #566188 solid; + padding: 3px; + cursor: pointer; +} +.calblanktop { + background-color: #fff; + padding: 4px; +} +.calblankbot { + background-color: #fff; + padding: 4px; +} + + +*/ + +function js_calendar_script($form_name = 'entryform') +{ + +ob_start(); +?> + + + var '.$field_id.' = new calendar("'.$field_id.'", '.$time.', '.(($highlight == TRUE) ? 'true' : 'false').'); + document.write('.$field_id.'.write()); + '; +} + +?> \ No newline at end of file diff --git a/system/scaffolding/Scaffolding.php b/system/scaffolding/Scaffolding.php new file mode 100644 index 000000000..4b6ebeed5 --- /dev/null +++ b/system/scaffolding/Scaffolding.php @@ -0,0 +1,285 @@ +ci_is_loaded as $val) + { + $this->$val =& $obj->$val; + } + + /** + * Set the current table name + * This is done when initializing scaffolding: + * $this->_ci_init_scaffolding('table_name') + * + */ + $this->current_table = $db_table; + + /** + * Set the path to the "view" files + * We'll manually override the "view" path so that + * the load->view function knows where to look. + */ + $this->load->_ci_set_view_path(BASEPATH.'scaffolding/views/'); + + // Set the base URL + $this->base_url = $this->config->site_url().'/'.$this->uri->segment(1).$this->uri->slash_segment(2, 'both'); + $this->base_uri = $this->uri->segment(1).$this->uri->slash_segment(2, 'leading'); + + // Set a few globals + $data = array( + 'image_url' => $this->config->system_url().'scaffolding/images/', + 'base_uri' => $this->base_uri, + 'base_url' => $this->base_url, + 'title' => $this->current_table + ); + + $this->load->vars($data); + + // Load the language file and create variables + $this->lang = $this->load->language('scaffolding', '', TRUE); + $this->load->vars($this->lang); + + // Load the helper files we plan to use + $this->load->helper(array('url', 'form')); + + + log_message('debug', 'Scaffolding Class Initialized'); + } + + // -------------------------------------------------------------------- + + /** + * "Add" Page + * + * Shows a form representing the currently selected DB + * so that data can be inserted + * + * @access public + * @return string the HTML "add" page + */ + function add() + { + $data = array( + 'title' => ( ! isset($this->lang['scaff_add'])) ? 'Add Data' : $this->lang['scaff_add'], + 'fields' => $this->db->field_data($this->current_table), + 'action' => $this->base_uri.'/insert' + ); + + $this->load->view('add', $data); + } + + // -------------------------------------------------------------------- + + /** + * Insert the data + * + * @access public + * @return void redirects to the view page + */ + function insert() + { + if ($this->db->insert($this->current_table, $_POST) === FALSE) + { + $this->add(); + } + else + { + redirect($this->base_uri.'/view/'); + } + } + + // -------------------------------------------------------------------- + + /** + * "View" Page + * + * Shows a table containing the data in the currently + * selected DB + * + * @access public + * @return string the HTML "view" page + */ + function view() + { + // Fetch the total number of DB rows + $total_rows = $this->db->count_all($this->current_table); + + if ($total_rows < 1) + { + return $this->load->view('no_data'); + } + + // Set the query limit/offset + $per_page = 20; + $offset = $this->uri->segment(4, 0); + + // Run the query + $query = $this->db->get($this->current_table, $per_page, $offset); + + // Now let's get the field names + $fields = $this->db->field_names($this->current_table); + + // We assume that the column in the first position is the primary field. + $primary = current($fields); + + // Pagination! + $this->pagination->initialize( + array( + 'base_url' => $this->base_url.'/view', + 'total_rows' => $total_rows, + 'per_page' => $per_page, + 'uri_segment' => 4, + 'full_tag_open' => '

', + 'full_tag_close' => '

' + ) + ); + + $data = array( + 'title' => ( ! isset($this->lang['scaff_view'])) ? 'View Data' : $this->lang['scaff_view'], + 'query' => $query, + 'fields' => $fields, + 'primary' => $primary, + 'paginate' => $this->pagination->create_links() + ); + + $this->load->view('view', $data); + } + + // -------------------------------------------------------------------- + + /** + * "Edit" Page + * + * Shows a form representing the currently selected DB + * so that data can be edited + * + * @access public + * @return string the HTML "edit" page + */ + function edit() + { + if (FALSE === ($id = $this->uri->segment(4))) + { + return $this->view(); + } + + // Fetch the primary field name + $primary = $this->db->primary($this->current_table); + + // Run the query + $query = $this->db->getwhere($this->current_table, array($primary => $id)); + + $data = array( + 'title' => ( ! isset($this->lang['scaff_edit'])) ? 'Edit Data' : $this->lang['scaff_edit'], + 'fields' => $query->field_data(), + 'query' => $query->row(), + 'action' => $this->base_uri.'/update/'.$this->uri->segment(4) + ); + + $this->load->view('edit', $data); + } + + // -------------------------------------------------------------------- + + /** + * Update + * + * @access public + * @return void redirects to the view page + */ + function update() + { + // Fetch the primary key + $primary = $this->db->primary($this->current_table); + + // Now do the query + $this->db->update($this->current_table, $_POST, array($primary => $this->uri->segment(4))); + + redirect($this->base_uri.'/view/'); + } + + // -------------------------------------------------------------------- + + /** + * Delete Confirmation + * + * @access public + * @return string the HTML "delete confirm" page + */ + function delete() + { + if ( ! isset($this->lang['scaff_del_confirm'])) + { + $message = 'Are you sure you want to delete the following row: '.$this->uri->segment(4); + } + else + { + $message = $this->lang['scaff_del_confirm'].' '.$this->uri->segment(4); + } + + $data = array( + 'title' => ( ! isset($this->lang['scaff_delete'])) ? 'Delete Data' : $this->lang['scaff_delete'], + 'message' => $message, + 'no' => anchor(array($this->base_uri, 'view'), ( ! isset($this->lang['scaff_no'])) ? 'No' : $this->lang['scaff_no']), + 'yes' => anchor(array($this->base_uri, 'do_delete', $this->uri->segment(4)), ( ! isset($this->lang['scaff_yes'])) ? 'Yes' : $this->lang['scaff_yes']) + ); + + $this->load->view('delete', $data); + } + + // -------------------------------------------------------------------- + + /** + * Delete + * + * @access public + * @return void redirects to the view page + */ + function do_delete() + { + // Fetch the primary key + $primary = $this->db->primary($this->current_table); + + // Now do the query + $this->db->where($primary, $this->uri->segment(4)); + $this->db->delete($this->current_table); + + header("Refresh:0;url=".site_url(array($this->base_uri, 'view'))); + exit; + } + +} +?> \ No newline at end of file diff --git a/system/scaffolding/images/background.jpg b/system/scaffolding/images/background.jpg new file mode 100644 index 000000000..9d5bdcea1 Binary files /dev/null and b/system/scaffolding/images/background.jpg differ diff --git a/system/scaffolding/images/index.html b/system/scaffolding/images/index.html new file mode 100644 index 000000000..5a1f5d6ae --- /dev/null +++ b/system/scaffolding/images/index.html @@ -0,0 +1,15 @@ + + + + +403 Forbidden + + + + + +

Directory access is forbidden.

+ + + + \ No newline at end of file diff --git a/system/scaffolding/images/logo.jpg b/system/scaffolding/images/logo.jpg new file mode 100644 index 000000000..d6cc9a76d Binary files /dev/null and b/system/scaffolding/images/logo.jpg differ diff --git a/system/scaffolding/index.html b/system/scaffolding/index.html new file mode 100644 index 000000000..5a1f5d6ae --- /dev/null +++ b/system/scaffolding/index.html @@ -0,0 +1,15 @@ + + + + +403 Forbidden + + + + + +

Directory access is forbidden.

+ + + + \ No newline at end of file diff --git a/system/scaffolding/views/add.php b/system/scaffolding/views/add.php new file mode 100644 index 000000000..a65e3d745 --- /dev/null +++ b/system/scaffolding/views/add.php @@ -0,0 +1,30 @@ +load->view('header'); ?> + +

+ + + + + + + +primary_key == 1) continue; ?> + + + + + type == 'blob'): ?> + + + + + + + +
name; echo ' '.$field->default; ?>
+ + + + + +load->view('footer'); ?> diff --git a/system/scaffolding/views/delete.php b/system/scaffolding/views/delete.php new file mode 100644 index 000000000..75a5c21b8 --- /dev/null +++ b/system/scaffolding/views/delete.php @@ -0,0 +1,7 @@ +load->view('header'); ?> + +

+ +

  |   + +load->view('footer'); ?> diff --git a/system/scaffolding/views/edit.php b/system/scaffolding/views/edit.php new file mode 100644 index 000000000..a7d65c619 --- /dev/null +++ b/system/scaffolding/views/edit.php @@ -0,0 +1,31 @@ +load->view('header'); ?> + + +

+ + + + + + + +primary_key == 1) continue; ?> + + + + + type == 'blob'): ?> + + + + + + + +
name; ?>
+ + + + + +load->view('footer'); ?> \ No newline at end of file diff --git a/system/scaffolding/views/footer.php b/system/scaffolding/views/footer.php new file mode 100644 index 000000000..36b29d1cd --- /dev/null +++ b/system/scaffolding/views/footer.php @@ -0,0 +1,10 @@ + + + + + + + \ No newline at end of file diff --git a/system/scaffolding/views/header.php b/system/scaffolding/views/header.php new file mode 100644 index 000000000..7ab60fd81 --- /dev/null +++ b/system/scaffolding/views/header.php @@ -0,0 +1,31 @@ + + + + +<?php echo $title; ?> + + + + + + + + + + + + + + +
+
\ No newline at end of file diff --git a/system/scaffolding/views/index.html b/system/scaffolding/views/index.html new file mode 100644 index 000000000..5a1f5d6ae --- /dev/null +++ b/system/scaffolding/views/index.html @@ -0,0 +1,15 @@ + + + + +403 Forbidden + + + + + +

Directory access is forbidden.

+ + + + \ No newline at end of file diff --git a/system/scaffolding/views/no_data.php b/system/scaffolding/views/no_data.php new file mode 100644 index 000000000..dca477e2d --- /dev/null +++ b/system/scaffolding/views/no_data.php @@ -0,0 +1,6 @@ +load->view('header'); ?> + +

+

+ +load->view('footer'); ?> \ No newline at end of file diff --git a/system/scaffolding/views/stylesheet.css b/system/scaffolding/views/stylesheet.css new file mode 100644 index 000000000..55c8d9e59 --- /dev/null +++ b/system/scaffolding/views/stylesheet.css @@ -0,0 +1,143 @@ +body { + margin: 0; + padding: 0; + font-family: Lucida Grande, Verdana, Geneva, Sans-serif; + font-size: 11px; + color: #4F5155; + background: #fff url(background.jpg) repeat-x left top; +} + +a { + color: #8B0D00; + background-color: transparent; + text-decoration: none; + font-weight: bold; +} + +a:visited { + color: #8B0D00; + background-color: transparent; + text-decoration: none; +} + +a:hover { + color: #000; + text-decoration: none; + background-color: transparent; +} + + +#header { + margin: 0; + padding: 0; +} + +#header_left { + background-color: transparent; + float: left; + padding: 21px 0 0 32px; + margin: 0 +} + +#header_right { + background-color: transparent; + float: right; + text-align: right; + padding: 35px 50px 20px 0; + margin: 0 +} + +#footer { + margin: 20px 0 15px 0; + padding: 0; +} + +#footer p { + font-size: 10px; + color: #999; + text-align: center; +} + +#outer { + margin: 30px 40px 0 40px; +} + +img { + padding:0; + border: 0; + margin: 0; +} + +.nopad { + padding:0; + border: 0; + margin: 0; +} + +table { + background-color: #efefef; +} + +th { + background-color: #eee; + font-weight: bold; + padding: 6px; + text-align: left; +} + +td { + background-color: #fff; + padding: 6px; +} + + +form { + margin: 0; + padding: 0; +} + +.input { + font-family: Lucida Grande, Verdana, Geneva, Sans-serif; + font-size: 11px; + width: 600px; + color: #333; + border: 1px solid #B3B4BD; + font-size: 11px; + height: 2em; + padding: 0; + margin: 0; +} + +.textarea { + font-family: Lucida Grande, Verdana, Geneva, Sans-serif; + font-size: 12px; + width: 600px; + color: #333; + border: 1px solid #B3B4BD; + padding: 0; + margin: 0; +} + +.select { + background-color: #fff; + font-size: 11px; + font-weight: normal; + color: #333; + padding: 0; + margin: 0 0 3px 0; +} + +.checkbox { + background-color: transparent; + padding: 0; + border: 0; +} + +.submit { + background-color: #8B0D00; + color: transparent; + font-weight: normal; + border: 1px solid #000; + margin: 6px 0 0 0; + padding: 1px 5px 1px 5px; +} diff --git a/system/scaffolding/views/view.php b/system/scaffolding/views/view.php new file mode 100644 index 000000000..fd20a174d --- /dev/null +++ b/system/scaffolding/views/view.php @@ -0,0 +1,25 @@ +load->view('header'); ?> + + + + + + + + + + +result() as $row): ?> + + + + + + + + +
EditDelete
 $primary), $scaff_edit); ?> $primary), $scaff_delete); ?>$field);?>
+ + + +load->view('footer'); ?> \ No newline at end of file -- cgit v1.2.3-24-g4f1b From d4e95072203a5cf4f1d50d16fe3e490f275a4307 Mon Sep 17 00:00:00 2001 From: admin Date: Sat, 26 Aug 2006 01:15:06 +0000 Subject: --- system/application/config/routes.php | 2 ++ system/libraries/Router.php | 19 +++++++++++++++---- 2 files changed, 17 insertions(+), 4 deletions(-) (limited to 'system') diff --git a/system/application/config/routes.php b/system/application/config/routes.php index 622bf88e6..5167f7569 100644 --- a/system/application/config/routes.php +++ b/system/application/config/routes.php @@ -46,4 +46,6 @@ $route['scaffolding_trigger'] = "scaffolding"; // Define your own routes below ------------------------------------------- +$route['products\/([a-z]+)\/(\d+)'] = "$1/a$2"; + ?> \ No newline at end of file diff --git a/system/libraries/Router.php b/system/libraries/Router.php index abc253eff..b61dfb79c 100644 --- a/system/libraries/Router.php +++ b/system/libraries/Router.php @@ -300,16 +300,27 @@ class CI_Router { } // Loop through the route array looking for wildcards - foreach ($this->routes as $key => $val) + foreach (array_slice($this->routes, 1) as $key => $val) { if (count(explode('/', $key)) != $num) continue; - - if (preg_match("|".str_replace(':any', '.+', str_replace(':num', '[0-9]+', $key))."$|", $uri)) - { + + // Convert wildcards to RegEx + $key = str_replace(':any', '.+', str_replace(':num', '[0-9]+', $key)); + + // Does the regex match this URI ? + if (preg_match('|^'.$key.'$|', $uri)) + { + // Do we have a replacemnt? + if (strpos($val, '$') !== FALSE AND strpos($key, '(') !== FALSE) + { + $val = preg_replace('|^'.$key.'$|', $val, $uri); + } + $this->_compile_segments(explode('/', $val), TRUE); break; } + } } // END set_method() -- cgit v1.2.3-24-g4f1b From 45c872b0ac215d590e785fe393241a06facd7e05 Mon Sep 17 00:00:00 2001 From: admin Date: Sat, 26 Aug 2006 04:51:38 +0000 Subject: --- system/codeigniter/CodeIgniter.php | 13 +-- system/libraries/Router.php | 211 +++++++++++++++++++++++++------------ 2 files changed, 143 insertions(+), 81 deletions(-) (limited to 'system') diff --git a/system/codeigniter/CodeIgniter.php b/system/codeigniter/CodeIgniter.php index aef7618e9..de7f89af2 100644 --- a/system/codeigniter/CodeIgniter.php +++ b/system/codeigniter/CodeIgniter.php @@ -99,16 +99,6 @@ else } } -/* - * ------------------------------------------------------ - * Does the requested controller exist? - * ------------------------------------------------------ - */ -if ( ! file_exists(APPPATH.'controllers/'.$RTR->fetch_class().EXT)) -{ - show_404(); -} - /* * ------------------------------------------------------ * Load the remaining base classes @@ -132,7 +122,6 @@ $LANG =& _load_class('CI_Language'); * */ - _load_class('CI_Loader'); if (floor(phpversion()) < 5) @@ -146,7 +135,7 @@ else _load_class('CI_Controller'); -require(APPPATH.'controllers/'.$RTR->fetch_class().EXT); +require(APPPATH.'controllers/'.$RTR->fetch_directory().$RTR->fetch_class().EXT); /* * ------------------------------------------------------ diff --git a/system/libraries/Router.php b/system/libraries/Router.php index b61dfb79c..7839de2d9 100644 --- a/system/libraries/Router.php +++ b/system/libraries/Router.php @@ -34,6 +34,7 @@ class CI_Router { var $routes = array(); var $class = ''; var $method = 'index'; + var $directory = ''; var $uri_protocol = 'auto'; var $default_controller; var $scaffolding_request = FALSE; // Must be set to FALSE @@ -121,6 +122,7 @@ class CI_Router { log_message('debug', "No URI present. Default controller set."); return; } + unset($this->routes['default_controller']); // Do we need to remove the suffix specified in the config file? if ($this->config->item('url_suffix') != "") @@ -129,13 +131,20 @@ class CI_Router { } // Explode the URI Segments. The individual segments will - // be stored in the $this->segments array. - $this->_compile_segments(explode("/", preg_replace("|/*(.+?)/*$|", "\\1", $this->uri_string))); - - - // Remap the class/method if a route exists - unset($this->routes['default_controller']); + // be stored in the $this->segments array. + $i = 1; + foreach(explode("/", preg_replace("|/*(.+?)/*$|", "\\1", $this->uri_string)) as $val) + { + // Filter segments for security + $val = trim($this->_filter_uri($val)); + + if ($val != '') + $this->segments[$i++] = $val; + } + $this->_compile_segments($this->segments); + + // Do we have any custom routing to deal with? if (count($this->routes) > 0) { $this->_parse_routes(); @@ -157,19 +166,15 @@ class CI_Router { * @param bool * @return void */ - function _compile_segments($segs, $route = FALSE) - { - $segments = array(); - - $i = 1; - foreach($segs as $val) + function _compile_segments($segments = array()) + { + $segments = $this->_validate_segments($segments); + + if (count($segments) == 0) { - $val = trim($this->_filter_uri($val)); - - if ($val != '') - $segments[$i++] = $val; + return; } - + $this->set_class($segments['1']); if (isset($segments['2'])) @@ -186,15 +191,54 @@ class CI_Router { $this->set_method($segments['2']); } } - - if ($route == FALSE) + } + // END _compile_segments() + + // -------------------------------------------------------------------- + + /** + * Validates the supplied segments. Attempts to determine the path to + * the controller. + * + * @access private + * @param array + * @return array + */ + function _validate_segments($segments) + { + // Does the requested controller exist? + if ( ! file_exists(APPPATH.'controllers/'.$segments['1'].EXT)) { - $this->segments = $segments; + // Is it a directory? No? Smite them! + if ( ! is_dir(APPPATH.'controllers/'.$segments['1'])) + { + show_404(); + } + else + { + $this->set_directory($segments['1']); + $segs = array_slice($segments, 1); + + if (count($segs) == 0) + { + $this->set_class($this->default_controller); + $this->set_method('index'); + $this->directory = ''; + return array(); + } + + $i = 1; + $segments = array(); + foreach ($segs as $val) + { + $segments[$i++] = $val; + } + } } - unset($segments); + return $segments; } - // END _compile_segments() + // END _validate_segments() // -------------------------------------------------------------------- @@ -218,6 +262,56 @@ class CI_Router { // -------------------------------------------------------------------- + /** + * 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->segments); + $num = count($this->segments); + + // Is there a literal match? If so we're done + if (isset($this->routes[$uri])) + { + $this->_compile_segments(explode('/', $this->routes[$uri])); + return; + } + + // Loop through the route array looking for wildcards + foreach (array_slice($this->routes, 1) as $key => $val) + { + if (count(explode('/', $key)) != $num) + continue; + + // Convert wildcards 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); + } + + $this->_compile_segments(explode('/', $val)); + return; + } + } + } + // END set_method() + + // -------------------------------------------------------------------- + /** * Set the class name * @@ -229,7 +323,7 @@ class CI_Router { { $this->class = $class; } - // END _filter_uri() + // END set_class() // -------------------------------------------------------------------- @@ -243,7 +337,7 @@ class CI_Router { { return $this->class; } - // END _filter_uri() + // END fetch_class() // -------------------------------------------------------------------- @@ -259,7 +353,7 @@ class CI_Router { $this->method = $method; } // END set_method() - + // -------------------------------------------------------------------- /** @@ -272,58 +366,37 @@ class CI_Router { { return $this->method; } - // END set_method() - + // END fetch_method() + // -------------------------------------------------------------------- /** - * Parse Routes + * Set the directory name * - * 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 + * @access public + * @param string * @return void - */ - function _parse_routes() + */ + function set_directory($dir) { - // Turn the segment array into a URI string - $uri = implode('/', $this->segments); - $num = count($this->segments); + $this->directory = $dir.'/'; + } + // END set_directory() - // Is there a literal match? If so we're done - if (isset($this->routes[$uri])) - { - $this->_compile_segments(explode('/', $this->routes[$uri]), TRUE); - return; - } - - // Loop through the route array looking for wildcards - foreach (array_slice($this->routes, 1) as $key => $val) - { - if (count(explode('/', $key)) != $num) - continue; - - // Convert wildcards to RegEx - $key = str_replace(':any', '.+', str_replace(':num', '[0-9]+', $key)); - - // Does the regex match this URI ? - if (preg_match('|^'.$key.'$|', $uri)) - { - // Do we have a replacemnt? - if (strpos($val, '$') !== FALSE AND strpos($key, '(') !== FALSE) - { - $val = preg_replace('|^'.$key.'$|', $val, $uri); - } - - $this->_compile_segments(explode('/', $val), TRUE); - break; - } - - } + // -------------------------------------------------------------------- + + /** + * Fetch the sub-directory (if any) that contains the requested controller class + * + * @access public + * @return string + */ + function fetch_directory() + { + return $this->directory; } - // END set_method() + // END fetch_directory() + } // END Router Class ?> \ No newline at end of file -- cgit v1.2.3-24-g4f1b From e07fbb376a741e21e69a182eada322c4d3b7e62e Mon Sep 17 00:00:00 2001 From: admin Date: Sat, 26 Aug 2006 17:11:01 +0000 Subject: --- system/libraries/Router.php | 84 +++++++++++++++++++++++++-------------------- 1 file changed, 46 insertions(+), 38 deletions(-) (limited to 'system') diff --git a/system/libraries/Router.php b/system/libraries/Router.php index 7839de2d9..678145458 100644 --- a/system/libraries/Router.php +++ b/system/libraries/Router.php @@ -132,23 +132,25 @@ class CI_Router { // Explode the URI Segments. The individual segments will // be stored in the $this->segments array. - $i = 1; foreach(explode("/", preg_replace("|/*(.+?)/*$|", "\\1", $this->uri_string)) as $val) { // Filter segments for security $val = trim($this->_filter_uri($val)); if ($val != '') - $this->segments[$i++] = $val; + $this->segments[] = $val; } - $this->_compile_segments($this->segments); + // Parse any custom routing that may exist + $this->_parse_routes(); - // Do we have any custom routing to deal with? - if (count($this->routes) > 0) + // Re-index the segment array so that it starts with 1 rather than 0 + $i = 1; + foreach ($this->segments as $val) { - $this->_parse_routes(); + $this->segments[$i++] = $val; } + unset($this->segments['0']); } // END _set_route_mapping() @@ -175,12 +177,12 @@ class CI_Router { return; } - $this->set_class($segments['1']); + $this->set_class($segments['0']); - if (isset($segments['2'])) + if (isset($segments['1'])) { // A scaffolding request. No funny business with the URL - if ($this->routes['scaffolding_trigger'] == $segments['2'] AND $segments['2'] != '_ci_scaffolding') + if ($this->routes['scaffolding_trigger'] == $segments['1'] AND $segments['1'] != '_ci_scaffolding') { $this->scaffolding_request = TRUE; unset($this->routes['scaffolding_trigger']); @@ -188,7 +190,7 @@ class CI_Router { else { // A standard method request - $this->set_method($segments['2']); + $this->set_method($segments['1']); } } } @@ -206,37 +208,32 @@ class CI_Router { */ function _validate_segments($segments) { - // Does the requested controller exist? - if ( ! file_exists(APPPATH.'controllers/'.$segments['1'].EXT)) + // Does the requested controller exist in the root folder? + if (file_exists(APPPATH.'controllers/'.$segments['0'].EXT)) { - // Is it a directory? No? Smite them! - if ( ! is_dir(APPPATH.'controllers/'.$segments['1'])) + 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) { - show_404(); + $this->set_class($this->default_controller); + $this->set_method('index'); + $this->directory = ''; + return array(); } - else - { - $this->set_directory($segments['1']); - $segs = array_slice($segments, 1); - if (count($segs) == 0) - { - $this->set_class($this->default_controller); - $this->set_method('index'); - $this->directory = ''; - return array(); - } - - $i = 1; - $segments = array(); - foreach ($segs as $val) - { - $segments[$i++] = $val; - } - } + return $segments; } - - return $segments; + + // Can't find the requested controller... + show_404(); } // END _validate_segments() @@ -274,6 +271,13 @@ class CI_Router { */ function _parse_routes() { + // Do we even have any custom routing to deal with? + if (count($this->routes) == 0) + { + $this->_compile_segments($this->segments); + return; + } + // Turn the segment array into a URI string $uri = implode('/', $this->segments); $num = count($this->segments); @@ -284,7 +288,7 @@ class CI_Router { $this->_compile_segments(explode('/', $this->routes[$uri])); return; } - + // Loop through the route array looking for wildcards foreach (array_slice($this->routes, 1) as $key => $val) { @@ -306,7 +310,11 @@ class CI_Router { $this->_compile_segments(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->_compile_segments($this->segments); } // END set_method() -- cgit v1.2.3-24-g4f1b From b071bb5a92aade551345a495fb13f5678f3978d0 Mon Sep 17 00:00:00 2001 From: admin Date: Sat, 26 Aug 2006 19:28:37 +0000 Subject: --- system/application/config/config.php | 2 ++ system/application/config/routes.php | 3 ++- system/codeigniter/CodeIgniter.php | 6 ++--- system/codeigniter/Common.php | 3 +-- system/drivers/DB_mssql.php | 2 +- system/drivers/DB_mysql.php | 2 +- system/drivers/DB_mysqli.php | 2 +- system/drivers/DB_odbc.php | 2 +- system/drivers/DB_postgre.php | 8 +++---- system/drivers/DB_sqlite.php | 2 +- system/helpers/form_helper.php | 2 +- system/helpers/url_helper.php | 4 ++-- system/libraries/Calendar.php | 2 +- system/libraries/Loader.php | 2 +- system/libraries/Router.php | 45 +++++++++++++++++++----------------- system/libraries/URI.php | 14 +++++------ 16 files changed, 53 insertions(+), 48 deletions(-) (limited to 'system') diff --git a/system/application/config/config.php b/system/application/config/config.php index 0b4f33f41..c33bda37c 100644 --- a/system/application/config/config.php +++ b/system/application/config/config.php @@ -37,6 +37,8 @@ $config['index_page'] = "index.php"; | 'auto' Default - auto detects | 'path_info' Uses the PATH_INFO | 'query_string' Uses the QUERY_STRING +| 'orig_path_info' Uses the ORIG_PATH_INFO +| 'request_uri' Uses the REQUEST_URI | */ $config['uri_protocol'] = "auto"; diff --git a/system/application/config/routes.php b/system/application/config/routes.php index 5167f7569..dc8a32d01 100644 --- a/system/application/config/routes.php +++ b/system/application/config/routes.php @@ -45,7 +45,8 @@ $route['scaffolding_trigger'] = "scaffolding"; // Define your own routes below ------------------------------------------- +$route['products/([a-z]+)/(\d+)'] = "bamo/$1/a$2"; + -$route['products\/([a-z]+)\/(\d+)'] = "$1/a$2"; ?> \ No newline at end of file diff --git a/system/codeigniter/CodeIgniter.php b/system/codeigniter/CodeIgniter.php index de7f89af2..872f4c049 100644 --- a/system/codeigniter/CodeIgniter.php +++ b/system/codeigniter/CodeIgniter.php @@ -27,7 +27,7 @@ * @link http://www.codeigniter.com/user_guide/ */ -define('APPVER', '1.4'); +define('APPVER', '1.4.0'); /* * ------------------------------------------------------ @@ -122,7 +122,7 @@ $LANG =& _load_class('CI_Language'); * */ -_load_class('CI_Loader'); +_load_class('CI_Loader', FALSE); if (floor(phpversion()) < 5) { @@ -133,7 +133,7 @@ else require(BASEPATH.'codeigniter/Base5'.EXT); } -_load_class('CI_Controller'); +_load_class('CI_Controller', FALSE); require(APPPATH.'controllers/'.$RTR->fetch_directory().$RTR->fetch_class().EXT); diff --git a/system/codeigniter/Common.php b/system/codeigniter/Common.php index 2ec1c3d38..4879e7099 100644 --- a/system/codeigniter/Common.php +++ b/system/codeigniter/Common.php @@ -63,11 +63,10 @@ function &_load_class($class, $instantiate = TRUE) } else { - $objects[$class] = TRUE; + $objects[$class] = FALSE; } } - return $objects[$class]; } diff --git a/system/drivers/DB_mssql.php b/system/drivers/DB_mssql.php index 6156ec3c9..48d1929e3 100644 --- a/system/drivers/DB_mssql.php +++ b/system/drivers/DB_mssql.php @@ -93,7 +93,7 @@ class CI_DB_mssql extends CI_DB { * @param string an SQL query * @return string */ - function &_prep_query($sql) + function _prep_query($sql) { return $sql; } diff --git a/system/drivers/DB_mysql.php b/system/drivers/DB_mysql.php index 18c080b21..82e677a1a 100644 --- a/system/drivers/DB_mysql.php +++ b/system/drivers/DB_mysql.php @@ -100,7 +100,7 @@ class CI_DB_mysql extends CI_DB { * @param string an SQL query * @return string */ - function &_prep_query($sql) + 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 diff --git a/system/drivers/DB_mysqli.php b/system/drivers/DB_mysqli.php index f8cb19dbe..32c4c0f89 100644 --- a/system/drivers/DB_mysqli.php +++ b/system/drivers/DB_mysqli.php @@ -102,7 +102,7 @@ class CI_DB_mysqli extends CI_DB { * @param string an SQL query * @return string */ - function &_prep_query($sql) + 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 diff --git a/system/drivers/DB_odbc.php b/system/drivers/DB_odbc.php index fac44904b..50f39accd 100644 --- a/system/drivers/DB_odbc.php +++ b/system/drivers/DB_odbc.php @@ -94,7 +94,7 @@ class CI_DB_odbc extends CI_DB { * @param string an SQL query * @return string */ - function &_prep_query($sql) + function _prep_query($sql) { return $sql; } diff --git a/system/drivers/DB_postgre.php b/system/drivers/DB_postgre.php index 01d4b3df0..3829b04af 100644 --- a/system/drivers/DB_postgre.php +++ b/system/drivers/DB_postgre.php @@ -94,7 +94,7 @@ class CI_DB_postgre extends CI_DB { * @param string an SQL query * @return string */ - function &_prep_query($sql) + function _prep_query($sql) { return $sql; } @@ -174,7 +174,7 @@ class CI_DB_postgre extends CI_DB { if ($table == '') return '0'; - $query = $this->query("SELECT COUNT(*) AS numrows FROM `".$this->dbprefix.$table."`"); + $query = $this->query("SELECT COUNT(*) AS numrows FROM ".$this->dbprefix.$table.""); if ($query->num_rows() == 0) return '0'; @@ -225,7 +225,7 @@ class CI_DB_postgre extends CI_DB { { if (stristr($table, '.')) { - $table = preg_replace("/\./", "`.`", $table); + $table = preg_replace("/\./", ".", $table); } return $table; @@ -432,7 +432,7 @@ class CI_DB_postgre_result extends CI_DB_result { $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->primary_key = $i == 0; $F->default = ''; $retval[] = $F; diff --git a/system/drivers/DB_sqlite.php b/system/drivers/DB_sqlite.php index 6428dd5bb..1192e6dc7 100644 --- a/system/drivers/DB_sqlite.php +++ b/system/drivers/DB_sqlite.php @@ -115,7 +115,7 @@ class CI_DB_sqlite extends CI_DB { * @param string an SQL query * @return string */ - function &_prep_query($sql) + function _prep_query($sql) { return $sql; } diff --git a/system/helpers/form_helper.php b/system/helpers/form_helper.php index f82ad01a0..d4e45a0af 100644 --- a/system/helpers/form_helper.php +++ b/system/helpers/form_helper.php @@ -326,7 +326,7 @@ function form_close($extra = '') */ function form_prep($str = '') { - if ($str == '') + if ($str === '') { return ''; } diff --git a/system/helpers/url_helper.php b/system/helpers/url_helper.php index d2d2a5985..03d6c3b2c 100644 --- a/system/helpers/url_helper.php +++ b/system/helpers/url_helper.php @@ -90,7 +90,7 @@ function index_page() */ function anchor($uri = '', $title = '', $attributes = '') { - $site_url = site_url($uri); + $site_url = ( ! preg_match('!^\w+://!i', $uri)) ? site_url($uri) : $uri; if ($title == '') { @@ -128,7 +128,7 @@ function anchor($uri = '', $title = '', $attributes = '') */ function anchor_popup($uri = '', $title = '', $attributes = FALSE) { - $site_url = site_url($uri); + $site_url = ( ! preg_match('!^\w+://!i', $uri)) ? site_url($uri) : $uri; if ($title == '') { diff --git a/system/libraries/Calendar.php b/system/libraries/Calendar.php index 013f06796..b77dd1b6f 100644 --- a/system/libraries/Calendar.php +++ b/system/libraries/Calendar.php @@ -263,7 +263,7 @@ class CI_Calendar { } 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_novermber', '12' => 'cal_december'); + $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]; diff --git a/system/libraries/Loader.php b/system/libraries/Loader.php index e2467fa64..3d2501fc0 100644 --- a/system/libraries/Loader.php +++ b/system/libraries/Loader.php @@ -478,7 +478,7 @@ class CI_Loader { if ($path == '') { $ext = pathinfo($view, PATHINFO_EXTENSION); - $file = ($ext == '') ? $view.EXT : $view; + $file = ($ext != EXT) ? $view.EXT : $view; $path = $this->view_path.$file; } else diff --git a/system/libraries/Router.php b/system/libraries/Router.php index 678145458..b28ead953 100644 --- a/system/libraries/Router.php +++ b/system/libraries/Router.php @@ -87,25 +87,31 @@ class CI_Router { // Fetch the URI string Depending on the server, // the URI will be available in one of two globals - switch ($this->config->item('uri_protocol')) + if ($this->config->item('uri_protocol') == 'auto') { - case 'path_info' : $this->uri_string = (isset($_SERVER['PATH_INFO'])) ? $_SERVER['PATH_INFO'] : @getenv('PATH_INFO'); - break; - case 'query_string' : $this->uri_string = (isset($_SERVER['QUERY_STRING'])) ? $_SERVER['QUERY_STRING'] : @getenv('QUERY_STRING'); - break; - default : - $path_info = (isset($_SERVER['PATH_INFO'])) ? $_SERVER['PATH_INFO'] : @getenv('PATH_INFO'); - - if ($path_info != '' AND $path_info != "/".SELF) - { - $this->uri_string = $path_info; - } - else - { - $this->uri_string = (isset($_SERVER['QUERY_STRING'])) ? $_SERVER['QUERY_STRING'] : @getenv('QUERY_STRING'); - } - break; + $path_info = getenv('PATH_INFO'); + if ($path_info != '' AND $path_info != "/".SELF) + { + $this->uri_string = $path_info; + } + else + { + $path_info = getenv('ORIG_PATH_INFO'); + if ($path_info != '' AND $path_info != "/".SELF) + { + $this->uri_string = $path_info; + } + else + { + $this->uri_string = getenv('QUERY_STRING'); + } + } + } + else + { + $this->uri_string = getenv(strtoupper($this->config->item('uri_protocol'))); } + // Is there a URI string? If not, the default controller specified // by the admin in the "routes" file will be shown. @@ -291,10 +297,7 @@ class CI_Router { // Loop through the route array looking for wildcards foreach (array_slice($this->routes, 1) as $key => $val) - { - if (count(explode('/', $key)) != $num) - continue; - + { // Convert wildcards to RegEx $key = str_replace(':any', '.+', str_replace(':num', '[0-9]+', $key)); diff --git a/system/libraries/URI.php b/system/libraries/URI.php index 4c2fa9c7f..c5fd4625b 100644 --- a/system/libraries/URI.php +++ b/system/libraries/URI.php @@ -28,7 +28,7 @@ */ class CI_URI { - var $uri; + var $router; var $keyval = array(); /** @@ -42,7 +42,7 @@ class CI_URI { */ function CI_URI() { - $this->uri =& _load_class('CI_Router'); + $this->router =& _load_class('CI_Router'); log_message('debug', "URI Class Initialized"); } @@ -60,7 +60,7 @@ class CI_URI { */ function segment($n, $no_result = FALSE) { - return ( ! isset($this->uri->segments[$n])) ? $no_result : $this->uri->segments[$n]; + return ( ! isset($this->router->segments[$n])) ? $no_result : $this->router->segments[$n]; } // -------------------------------------------------------------------- @@ -196,7 +196,7 @@ class CI_URI { $leading = '/'; $trailing = '/'; } - return ( ! isset($this->uri->segments[$n])) ? '' : $leading.$this->uri->segments[$n].$trailing; + return ( ! isset($this->router->segments[$n])) ? '' : $leading.$this->router->segments[$n].$trailing; } // -------------------------------------------------------------------- @@ -209,7 +209,7 @@ class CI_URI { */ function segment_array() { - return $this->uri->segments; + return $this->router->segments; } // -------------------------------------------------------------------- @@ -222,7 +222,7 @@ class CI_URI { */ function total_segments() { - return count($this->uri->segments); + return count($this->router->segments); } // -------------------------------------------------------------------- @@ -235,7 +235,7 @@ class CI_URI { */ function uri_string() { - return $this->uri->uri_string; + return $this->router->uri_string; } } -- cgit v1.2.3-24-g4f1b From 141808ad31d4eefad4c6c3dbaf8306fac2342668 Mon Sep 17 00:00:00 2001 From: admin Date: Sun, 27 Aug 2006 01:52:51 +0000 Subject: --- system/drivers/DB_mysql.php | 4 ---- system/drivers/DB_mysqli.php | 4 ---- system/drivers/DB_postgre.php | 4 ---- system/drivers/DB_sqlite.php | 4 ---- system/helpers/form_helper.php | 9 +++++++-- system/libraries/Encrypt.php | 2 +- system/libraries/Language.php | 2 +- system/libraries/Log.php | 2 +- system/libraries/Validation.php | 8 ++++---- 9 files changed, 14 insertions(+), 25 deletions(-) (limited to 'system') diff --git a/system/drivers/DB_mysql.php b/system/drivers/DB_mysql.php index 82e677a1a..a90d84268 100644 --- a/system/drivers/DB_mysql.php +++ b/system/drivers/DB_mysql.php @@ -126,10 +126,6 @@ class CI_DB_mysql extends CI_DB { */ function escape_str($str) { - if (get_magic_quotes_gpc()) - { - $str = stripslashes($str); - } return mysql_real_escape_string($str); } diff --git a/system/drivers/DB_mysqli.php b/system/drivers/DB_mysqli.php index 32c4c0f89..75c01e7f8 100644 --- a/system/drivers/DB_mysqli.php +++ b/system/drivers/DB_mysqli.php @@ -128,10 +128,6 @@ class CI_DB_mysqli extends CI_DB { */ function escape_str($str) { - if (get_magic_quotes_gpc()) - { - $str = stripslashes($str); - } return mysqli_real_escape_string($this->conn_id, $str); } diff --git a/system/drivers/DB_postgre.php b/system/drivers/DB_postgre.php index 3829b04af..cf59f0fdc 100644 --- a/system/drivers/DB_postgre.php +++ b/system/drivers/DB_postgre.php @@ -110,10 +110,6 @@ class CI_DB_postgre extends CI_DB { */ function escape_str($str) { - if (get_magic_quotes_gpc()) - { - $str = stripslashes($str); - } return pg_escape_string($str); } diff --git a/system/drivers/DB_sqlite.php b/system/drivers/DB_sqlite.php index 1192e6dc7..b2c31a8ba 100644 --- a/system/drivers/DB_sqlite.php +++ b/system/drivers/DB_sqlite.php @@ -131,10 +131,6 @@ class CI_DB_sqlite extends CI_DB { */ function escape_str($str) { - if (get_magic_quotes_gpc()) - { - $str = stripslashes($str); - } return sqlite_escape_string($str); } diff --git a/system/helpers/form_helper.php b/system/helpers/form_helper.php index d4e45a0af..069101063 100644 --- a/system/helpers/form_helper.php +++ b/system/helpers/form_helper.php @@ -38,11 +38,16 @@ * @param array a key/value pair hidden data * @return string */ -function form_open($action, $attributes = array(), $hidden = array()) +function form_open($action = '', $attributes = array(), $hidden = array()) { $obj =& get_instance(); - $form = '
config->site_url($action).'"'; + + if ( ! isset($attributes['method'])) + { + $form .= ' method="post"'; + } if (is_array($attributes) AND count($attributes) > 0) { diff --git a/system/libraries/Encrypt.php b/system/libraries/Encrypt.php index 532bfe1f1..bcffdf1ab 100644 --- a/system/libraries/Encrypt.php +++ b/system/libraries/Encrypt.php @@ -322,7 +322,7 @@ class CI_Encrypt { */ function set_hash($type = 'sha1') { - $this->_hash_type = ($type != 'sha1' OR $type != 'md5') ? 'sha1' : $type; + $this->_hash_type = ($type != 'sha1' AND $type != 'md5') ? 'sha1' : $type; } // END set_hash() diff --git a/system/libraries/Language.php b/system/libraries/Language.php index b668aa060..328d53e46 100644 --- a/system/libraries/Language.php +++ b/system/libraries/Language.php @@ -68,7 +68,7 @@ class CI_Language { if ( ! file_exists(BASEPATH.'language/'.$idiom.'/'.$langfile)) { - show_error('Unable to load the requested language file: language/'.$langfile.EXT); + show_error('Unable to load the requested language file: language/'.$langfile); } include_once(BASEPATH.'language/'.$idiom.'/'.$langfile); diff --git a/system/libraries/Log.php b/system/libraries/Log.php index 35e30b64c..17b96b2c2 100644 --- a/system/libraries/Log.php +++ b/system/libraries/Log.php @@ -88,7 +88,7 @@ class CI_Log { return FALSE; } - $filepath = $this->log_path.'log-'.date('Y-m-d').'.php'; + $filepath = $this->log_path.'log-'.date('Y-m-d').EXT; $message = ''; if ( ! file_exists($filepath)) diff --git a/system/libraries/Validation.php b/system/libraries/Validation.php index df8c70ee8..e037e69c5 100644 --- a/system/libraries/Validation.php +++ b/system/libraries/Validation.php @@ -252,12 +252,12 @@ class CI_Validation { // Strip the parameter (if exists) from the rule // Rules can contain a parameter: max_length[5] $param = FALSE; - if (preg_match("/.*?(\[.*?\]).*/", $rule, $match)) + if (preg_match("/(.*?)\[(.*?)\]/", $rule, $match)) { - $param = substr(substr($match['1'], 1), 0, -1); - $rule = str_replace($match['1'], '', $rule); + $rule = $match[1]; + $param = $match[2]; } - + // Call the function that corresponds to the rule if ($callback === TRUE) { -- cgit v1.2.3-24-g4f1b From 57b3d39cb79bb3b8d193e0e345a62e3396e519f2 Mon Sep 17 00:00:00 2001 From: admin Date: Sun, 27 Aug 2006 15:28:31 +0000 Subject: --- system/codeigniter/Common.php | 6 ++++-- system/drivers/DB_active_record.php | 2 +- system/drivers/DB_driver.php | 10 +++++----- system/helpers/form_helper.php | 4 ++-- system/libraries/Log.php | 2 +- 5 files changed, 13 insertions(+), 11 deletions(-) (limited to 'system') diff --git a/system/codeigniter/Common.php b/system/codeigniter/Common.php index 4879e7099..d5bec77fe 100644 --- a/system/codeigniter/Common.php +++ b/system/codeigniter/Common.php @@ -153,8 +153,10 @@ function show_404($page = '') * @access public * @return void */ -function log_message($level = 2, $message, $php_error = FALSE) +function log_message($level = 'error', $message, $php_error = FALSE) { + static $LOG; + $config =& _get_config(); if ($config['log_errors'] === FALSE) { @@ -166,7 +168,7 @@ function log_message($level = 2, $message, $php_error = FALSE) include_once(BASEPATH.'libraries/Log.php'); } - if ( ! isset($LOG)) + if ( ! is_object($LOG)) { $LOG = new CI_Log( $config['log_path'], diff --git a/system/drivers/DB_active_record.php b/system/drivers/DB_active_record.php index 373c0f626..f1995c807 100644 --- a/system/drivers/DB_active_record.php +++ b/system/drivers/DB_active_record.php @@ -663,7 +663,7 @@ class CI_DB_active_record extends CI_DB_driver { if (count($this->ar_where) == 0) { - if ($this->debug) + if ($this->db_debug) { return $this->display_error('db_del_must_use_where'); } diff --git a/system/drivers/DB_driver.php b/system/drivers/DB_driver.php index ed18d54e5..3a2a5e9bc 100644 --- a/system/drivers/DB_driver.php +++ b/system/drivers/DB_driver.php @@ -86,7 +86,7 @@ class CI_DB_driver { { log_message('error', 'Invalid DB Connection String'); - if ($this->debug) + if ($this->db_debug) { return $this->display_error('db_invalid_connection_str'); } @@ -265,7 +265,7 @@ class CI_DB_driver { if ( ! function_exists($function)) { - if ($this->debug) + if ($this->db_debug) { return $this->display_error('db_unsupported_function'); } @@ -425,7 +425,7 @@ class CI_DB_driver { { if ($table == '') { - if ($this->debug) + if ($this->db_debug) { return $this->display_error('db_field_param_missing'); } @@ -472,7 +472,7 @@ class CI_DB_driver { { if ($table == '') { - if ($this->debug) + if ($this->db_debug) { return $this->display_error('db_field_param_missing'); } @@ -535,7 +535,7 @@ class CI_DB_driver { // Just in case the replacement string contains the bind // character we'll temporarily replace it with a marker $val = str_replace($this->bind_marker, '{%bind_marker%}', $val); - $sql = preg_replace("#".preg_quote($this->bind_marker)."#", $val, $sql, 1); + $sql = preg_replace("#".preg_quote($this->bind_marker, '#')."#", str_replace('$', '\$', $val), $sql, 1); } return str_replace('{%bind_marker%}', $this->bind_marker, $sql); diff --git a/system/helpers/form_helper.php b/system/helpers/form_helper.php index 069101063..eb97913f1 100644 --- a/system/helpers/form_helper.php +++ b/system/helpers/form_helper.php @@ -247,7 +247,7 @@ function form_checkbox($data = '', $value = '', $checked = TRUE, $extra = '') { $defaults = array('type' => 'checkbox', 'name' => (( ! is_array($data)) ? $data : ''), 'value' => $value); - if (isset($data['checked'])) + if (is_array($data) AND array_key_exists('checked', $data)) { $checked = $data['checked']; @@ -256,7 +256,7 @@ function form_checkbox($data = '', $value = '', $checked = TRUE, $extra = '') } if ($checked == TRUE) - $defaults['checked'] = ' checked="checked"'; + $defaults['checked'] = 'checked'; else unset($defaults['checked']); diff --git a/system/libraries/Log.php b/system/libraries/Log.php index 17b96b2c2..de5a9b836 100644 --- a/system/libraries/Log.php +++ b/system/libraries/Log.php @@ -40,7 +40,7 @@ class CI_Log { * @param string the error threshold * @param string the date formatting codes */ - function CI_Log($path = '', $threshold = '', $date_fmt = '') + function CI_Log($path = '', $threshold = 4, $date_fmt = '') { $this->log_path = ($path != '') ? $path : BASEPATH.'logs/'; -- cgit v1.2.3-24-g4f1b From b4473d4407311cc5e4b2306cf5fa51221d5826f8 Mon Sep 17 00:00:00 2001 From: admin Date: Sun, 27 Aug 2006 15:46:31 +0000 Subject: --- system/libraries/Controller.php | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'system') diff --git a/system/libraries/Controller.php b/system/libraries/Controller.php index ec21f8d66..06e54b2d1 100644 --- a/system/libraries/Controller.php +++ b/system/libraries/Controller.php @@ -127,7 +127,12 @@ class Controller extends CI_Base { { $name = $model; } - + + if (in_array($name, $this->_ci_models)) + { + return; + } + if (isset($this->$name)) { show_error('The model name you are loading is the name of a resource that is already being used: '.$name); -- cgit v1.2.3-24-g4f1b From 0d29605b1e774efd57ffd8f5ccc8eaec1e9ca576 Mon Sep 17 00:00:00 2001 From: admin Date: Sun, 27 Aug 2006 15:48:38 +0000 Subject: --- system/libraries/Controller.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'system') diff --git a/system/libraries/Controller.php b/system/libraries/Controller.php index 06e54b2d1..768b154e8 100644 --- a/system/libraries/Controller.php +++ b/system/libraries/Controller.php @@ -128,7 +128,8 @@ class Controller extends CI_Base { $name = $model; } - if (in_array($name, $this->_ci_models)) + $obj =& get_instance(); + if (in_array($name, $obj->_ci_models)) { return; } -- cgit v1.2.3-24-g4f1b From 1082bddc0c065895a3b39607cb930f5a101f54fb Mon Sep 17 00:00:00 2001 From: admin Date: Sun, 27 Aug 2006 19:32:02 +0000 Subject: --- system/application/config/config.php | 20 ++++++++++++++++++++ system/drivers/DB_mssql.php | 4 ++-- system/drivers/DB_mysqli.php | 4 +++- system/libraries/Config.php | 5 +++-- system/libraries/Router.php | 14 ++++++++------ 5 files changed, 36 insertions(+), 11 deletions(-) (limited to 'system') diff --git a/system/application/config/config.php b/system/application/config/config.php index c33bda37c..c19fabf44 100644 --- a/system/application/config/config.php +++ b/system/application/config/config.php @@ -81,6 +81,26 @@ $config['language'] = "english"; $config['enable_hooks'] = TRUE; +/* +|-------------------------------------------------------------------------- +| Allowed URL Characters +|-------------------------------------------------------------------------- +| +| This lets you specify which characters are permitted within your URLs. +| When someone tries to submit a URL with disallowed characters they will +| get a warning message. +| +| As a security measure you are STRONGLY encouraged to restrict URLs to +| as few characters as possible. By default only these are allowed: a-z 0-9~%.:_- +| +| Leave blank to allow all characters -- but only if you are insane. +| +| DO NOT CHANGE THIS UNLESS YOU FULLY UNDERSTAND THE REPERCUSSIONS!! +| +*/ +$config['permitted_uri_chars'] = 'a-z 0-9~%.:_-'; + + /* |-------------------------------------------------------------------------- | Enable Query Strings diff --git a/system/drivers/DB_mssql.php b/system/drivers/DB_mssql.php index 48d1929e3..f6e672b94 100644 --- a/system/drivers/DB_mssql.php +++ b/system/drivers/DB_mssql.php @@ -109,8 +109,8 @@ class CI_DB_mssql extends CI_DB { */ function escape_str($str) { - // MS SQL doesn't require escaping - return $str; + // Escape single quotes + return str_replace("'", "''", $str); } // -------------------------------------------------------------------- diff --git a/system/drivers/DB_mysqli.php b/system/drivers/DB_mysqli.php index 75c01e7f8..fadcdd3c4 100644 --- a/system/drivers/DB_mysqli.php +++ b/system/drivers/DB_mysqli.php @@ -88,7 +88,9 @@ class CI_DB_mysqli extends CI_DB { function execute($sql) { $sql = $this->_prep_query($sql); - return @mysqli_query($this->conn_id, $sql); + $result = @mysqli_query($this->conn_id, $sql); + mysqli_next_result($this->conn_id); + return $result; } // -------------------------------------------------------------------- diff --git a/system/libraries/Config.php b/system/libraries/Config.php index 85b295796..bd138331f 100644 --- a/system/libraries/Config.php +++ b/system/libraries/Config.php @@ -53,7 +53,7 @@ class CI_Config { * * @access public * @param string the config file name - * @return void + * @return boolean if the file was loaded correctly */ function load($file = '') { @@ -61,7 +61,7 @@ class CI_Config { if (in_array($file, $this->is_loaded)) { - return; + return TRUE; } include_once(APPPATH.'config/'.$file.EXT); @@ -77,6 +77,7 @@ class CI_Config { unset($config); log_message('debug', 'Config file loaded: config/'.$file.EXT); + return TRUE; } // END load() diff --git a/system/libraries/Router.php b/system/libraries/Router.php index b28ead953..2219f5739 100644 --- a/system/libraries/Router.php +++ b/system/libraries/Router.php @@ -254,12 +254,14 @@ class CI_Router { */ function _filter_uri($str) { - if ( ! preg_match("/^[a-z0-9~\s\%\.:_-]+$/i", $str)) - { - exit('The URI you submitted has disallowed characters: '.$str); - } - - return $str; + if ($this->config->item('permitted_uri_chars') != '') + { + if ( ! preg_match("|^[".preg_quote($this->config->item('permitted_uri_chars'))."]+$|i", $str)) + { + exit('The URI you submitted has disallowed characters: '.$str); + } + } + return $str; } // END _filter_uri() -- cgit v1.2.3-24-g4f1b From 6a285fb39f5fce271dc23e13bafdb414502c9ecb Mon Sep 17 00:00:00 2001 From: admin Date: Sun, 27 Aug 2006 19:54:10 +0000 Subject: --- system/drivers/DB_sqlite.php | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) (limited to 'system') diff --git a/system/drivers/DB_sqlite.php b/system/drivers/DB_sqlite.php index b2c31a8ba..71d2561dc 100644 --- a/system/drivers/DB_sqlite.php +++ b/system/drivers/DB_sqlite.php @@ -489,7 +489,14 @@ class CI_DB_sqlite_result extends CI_DB_result { */ function _fetch_object() { - return sqlite_fetch_object($this->result_id); + if (function_exists('sqlite_fetch_object')) + { + return sqlite_fetch_object($this->result_id); + } + else + { + return $this->_fetch_assoc(); + } } } -- cgit v1.2.3-24-g4f1b From 671dc754ef954eecf4c2e8301dde5b3aba6bfedc Mon Sep 17 00:00:00 2001 From: admin Date: Sat, 2 Sep 2006 02:36:03 +0000 Subject: --- system/libraries/Config.php | 99 +++++++++++++++++++++++++++++++++++++++------ 1 file changed, 86 insertions(+), 13 deletions(-) (limited to 'system') diff --git a/system/libraries/Config.php b/system/libraries/Config.php index bd138331f..f7f813f86 100644 --- a/system/libraries/Config.php +++ b/system/libraries/Config.php @@ -36,8 +36,12 @@ class CI_Config { * * Sets the $config data from the primary config.php file as a class variable * - * @access public - */ + * @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 successfully loaded or not + */ function CI_Config() { $this->config =& _get_config(); @@ -55,7 +59,7 @@ class CI_Config { * @param string the config file name * @return boolean if the file was loaded correctly */ - function load($file = '') + function load($file = '', $use_sections = FALSE, $fail_gracefully = FALSE) { $file = ($file == '') ? 'config' : str_replace(EXT, '', $file); @@ -63,15 +67,42 @@ class CI_Config { { return TRUE; } + + if ( ! file_exists(APPPATH.'config/'.$file.EXT)) + { + if ($fail_gracefully === TRUE) + { + return FALSE; + } + show_error('The configuration file '.$file.EXT.' does not exist.'); + } include_once(APPPATH.'config/'.$file.EXT); if ( ! isset($config) OR ! is_array($config)) { + if ($fail_gracefully === TRUE) + { + return FALSE; + } show_error('Your '.$file.EXT.' file does not appear to contain a valid configuration array.'); } - $this->config = array_merge($this->config, $config); + 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; unset($config); @@ -86,6 +117,48 @@ class CI_Config { /** * 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; + } + // END item() + + // -------------------------------------------------------------------- + + /** + * Fetch a config file item - adds slash after item + * * The second parameter allows a slash to be added to the end of * the item, in the case of a path. * @@ -94,7 +167,7 @@ class CI_Config { * @param bool * @return string */ - function item($item, $slash = FALSE) + function slash_item($item) { if ( ! isset($this->config[$item])) { @@ -103,20 +176,20 @@ class CI_Config { $pref = $this->config[$item]; - if ($pref == '') - { - return $pref; + if ($pref != '') + { + if (ereg("/$", $pref) === FALSE) + { + $pref .= '/'; + } } - - if ($slash !== FALSE AND ereg("/$", $pref) === FALSE) - { - $pref .= '/'; - } return $pref; } // END item() + + // -------------------------------------------------------------------- /** -- cgit v1.2.3-24-g4f1b From eb6db84333c40ed8d15dec5014564120ee0c60e6 Mon Sep 17 00:00:00 2001 From: admin Date: Sat, 2 Sep 2006 02:39:45 +0000 Subject: --- system/codeigniter/CodeIgniter.php | 5 +++++ system/drivers/DB_postgre.php | 7 +++++-- system/helpers/date_helper.php | 2 +- system/libraries/Validation.php | 2 +- 4 files changed, 12 insertions(+), 4 deletions(-) (limited to 'system') diff --git a/system/codeigniter/CodeIgniter.php b/system/codeigniter/CodeIgniter.php index 872f4c049..1f7850ecf 100644 --- a/system/codeigniter/CodeIgniter.php +++ b/system/codeigniter/CodeIgniter.php @@ -188,6 +188,11 @@ if ($RTR->scaffolding_request === TRUE) } else { + if ($method == $class) + { + $method = 'index'; + } + if ( ! method_exists($CI, $method)) { show_404(); diff --git a/system/drivers/DB_postgre.php b/system/drivers/DB_postgre.php index cf59f0fdc..fd98ec78b 100644 --- a/system/drivers/DB_postgre.php +++ b/system/drivers/DB_postgre.php @@ -211,7 +211,8 @@ class CI_DB_postgre extends CI_DB { * 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 + * in it. Some DBs will get cranky unless periods are escaped. + * NOT NEEDED FOR POSTGRE * * @access public * @param string the table name @@ -219,10 +220,12 @@ class CI_DB_postgre extends CI_DB { */ function escape_table($table) { + /* if (stristr($table, '.')) { - $table = preg_replace("/\./", ".", $table); + $table = preg_replace("/\./", "`.`", $table); } + */ return $table; } diff --git a/system/helpers/date_helper.php b/system/helpers/date_helper.php index 2a3d50859..c8205bb7d 100644 --- a/system/helpers/date_helper.php +++ b/system/helpers/date_helper.php @@ -189,7 +189,7 @@ function timespan($seconds = 1, $time = '') { if ($minutes > 0) { - $str .= $minutes.' '.$obj->lang->line((($minutes > 1) ? 'date_minutes' : 'date_minutes')).', '; + $str .= $minutes.' '.$obj->lang->line((($minutes > 1) ? 'date_minutes' : 'date_minute')).', '; } $seconds -= $minutes * 60; diff --git a/system/libraries/Validation.php b/system/libraries/Validation.php index e037e69c5..30faa85ed 100644 --- a/system/libraries/Validation.php +++ b/system/libraries/Validation.php @@ -208,7 +208,7 @@ class CI_Validation { { if (in_array('isset', $ex) OR in_array('required', $ex)) { - if ( ! isset($this->messages['isset'])) + if ( ! isset($this->_error_messages['isset'])) { if (FALSE === ($line = $this->obj->lang->line('isset'))) { -- cgit v1.2.3-24-g4f1b From 7530d50cd01c6cde8eabe6c62c180fe13a917f76 Mon Sep 17 00:00:00 2001 From: admin Date: Sat, 2 Sep 2006 02:50:23 +0000 Subject: --- system/application/config/autoload.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system') diff --git a/system/application/config/autoload.php b/system/application/config/autoload.php index a3ce4108e..1ed6f1757 100644 --- a/system/application/config/autoload.php +++ b/system/application/config/autoload.php @@ -39,7 +39,7 @@ | $autoload['core'] = array('database', 'session', 'xmlrpc'); */ -$autoload['core'] = array('session'); +$autoload['core'] = array(); /* -- cgit v1.2.3-24-g4f1b From e0d85bf837a59e74054260346867aec8329565c0 Mon Sep 17 00:00:00 2001 From: admin Date: Sat, 2 Sep 2006 03:59:48 +0000 Subject: --- system/application/config/hooks.php | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 system/application/config/hooks.php (limited to 'system') diff --git a/system/application/config/hooks.php b/system/application/config/hooks.php new file mode 100644 index 000000000..8ebb236d8 --- /dev/null +++ b/system/application/config/hooks.php @@ -0,0 +1,12 @@ + \ No newline at end of file -- cgit v1.2.3-24-g4f1b From 2ed76d5ac89ec7869dcb64c050360fb2f99e9326 Mon Sep 17 00:00:00 2001 From: admin Date: Sat, 2 Sep 2006 17:34:52 +0000 Subject: --- system/application/config/config.php | 2 +- system/drivers/DB_driver.php | 3 ++- system/drivers/DB_postgre.php | 10 +++++++--- system/helpers/file_helper.php | 4 ++-- system/helpers/url_helper.php | 2 +- system/libraries/Output.php | 2 +- 6 files changed, 14 insertions(+), 9 deletions(-) (limited to 'system') diff --git a/system/application/config/config.php b/system/application/config/config.php index c19fabf44..7b19b83b5 100644 --- a/system/application/config/config.php +++ b/system/application/config/config.php @@ -78,7 +78,7 @@ $config['language'] = "english"; | setting this variable to TRUE (boolean). See the user guide for details. | */ -$config['enable_hooks'] = TRUE; +$config['enable_hooks'] = FALSE; /* diff --git a/system/drivers/DB_driver.php b/system/drivers/DB_driver.php index 3a2a5e9bc..0c2084ad8 100644 --- a/system/drivers/DB_driver.php +++ b/system/drivers/DB_driver.php @@ -36,6 +36,7 @@ class CI_DB_driver { var $database; var $dbdriver = 'mysql'; var $dbprefix = ''; + var $port = ''; var $pconnect = FALSE; var $conn_id = FALSE; var $result_id = FALSE; @@ -75,7 +76,7 @@ class CI_DB_driver { { if (is_array($params)) { - foreach (array('hostname' => '', 'username' => '', 'password' => '', 'database' => '', 'dbdriver' => 'mysql', 'dbprefix' => '', 'pconnect' => FALSE, 'db_debug' => FALSE) as $key => $val) + foreach (array('hostname' => '', 'username' => '', 'password' => '', 'database' => '', 'dbdriver' => 'mysql', 'dbprefix' => '', 'port' => '', 'pconnect' => FALSE, 'db_debug' => FALSE) as $key => $val) { $this->$key = ( ! isset($params[$key])) ? $val : $params[$key]; } diff --git a/system/drivers/DB_postgre.php b/system/drivers/DB_postgre.php index fd98ec78b..673dea335 100644 --- a/system/drivers/DB_postgre.php +++ b/system/drivers/DB_postgre.php @@ -38,9 +38,11 @@ class CI_DB_postgre extends CI_DB { */ function db_connect() { - return pg_connect("host=".$this->hostname." dbname=".$this->database." user=".$this->username." password=".$this->password); + $port = ($this->port == '') ? '' : " port=".$this->port; + + return pg_connect("host=".$this->hostname.$port." dbname=".$this->database." user=".$this->username." password=".$this->password); } - + // -------------------------------------------------------------------- /** @@ -51,7 +53,9 @@ class CI_DB_postgre extends CI_DB { */ function db_pconnect() { - return pg_pconnect("host=".$this->hostname." dbname=".$this->database." user=".$this->username." password=".$this->password); + $port = ($this->port == '') ? '' : " port=".$this->port; + + return pg_pconnect("host=".$this->hostname.$port." dbname=".$this->database." user=".$this->username." password=".$this->password); } // -------------------------------------------------------------------- diff --git a/system/helpers/file_helper.php b/system/helpers/file_helper.php index 93bddb029..32c0b2cdc 100644 --- a/system/helpers/file_helper.php +++ b/system/helpers/file_helper.php @@ -75,9 +75,9 @@ function read_file($file) * @param string file data * @return bool */ -function write_file($path, $data) +function write_file($path, $data, $mode = 'wb') { - if ( ! $fp = @fopen($path, 'wb')) + if ( ! $fp = @fopen($path, $mode)) { return FALSE; } diff --git a/system/helpers/url_helper.php b/system/helpers/url_helper.php index 03d6c3b2c..09169e32e 100644 --- a/system/helpers/url_helper.php +++ b/system/helpers/url_helper.php @@ -56,7 +56,7 @@ function site_url($uri = '') function base_url() { $obj =& get_instance(); - return $obj->config->item('base_url', 1); + return $obj->config->slash_item('base_url'); } // ------------------------------------------------------------------------ diff --git a/system/libraries/Output.php b/system/libraries/Output.php index f5db3e0d0..73f03863e 100644 --- a/system/libraries/Output.php +++ b/system/libraries/Output.php @@ -147,7 +147,7 @@ class CI_Output { return; } - $uri = $obj->config->item('base_url', 1). + $uri = $obj->config->slash_item('base_url'). $obj->config->item('index_page'). $obj->uri->uri_string(); -- cgit v1.2.3-24-g4f1b From 337b270b6e566e81d3ee3b5575a3f274c000b459 Mon Sep 17 00:00:00 2001 From: admin Date: Sat, 2 Sep 2006 17:43:16 +0000 Subject: --- system/libraries/Loader.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system') diff --git a/system/libraries/Loader.php b/system/libraries/Loader.php index 3d2501fc0..f005adcf0 100644 --- a/system/libraries/Loader.php +++ b/system/libraries/Loader.php @@ -478,7 +478,7 @@ class CI_Loader { if ($path == '') { $ext = pathinfo($view, PATHINFO_EXTENSION); - $file = ($ext != EXT) ? $view.EXT : $view; + $file = ($ext != '') ? $view.EXT : $view; $path = $this->view_path.$file; } else -- cgit v1.2.3-24-g4f1b From 6ac4bea2da9e64fb0b434f52177353f6bd65b8e6 Mon Sep 17 00:00:00 2001 From: admin Date: Sat, 2 Sep 2006 17:46:15 +0000 Subject: --- system/libraries/Loader.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system') diff --git a/system/libraries/Loader.php b/system/libraries/Loader.php index f005adcf0..e2467fa64 100644 --- a/system/libraries/Loader.php +++ b/system/libraries/Loader.php @@ -478,7 +478,7 @@ class CI_Loader { if ($path == '') { $ext = pathinfo($view, PATHINFO_EXTENSION); - $file = ($ext != '') ? $view.EXT : $view; + $file = ($ext == '') ? $view.EXT : $view; $path = $this->view_path.$file; } else -- cgit v1.2.3-24-g4f1b From 1cf89aab5fff8c8068cbf0ed18038b6e4fd4f605 Mon Sep 17 00:00:00 2001 From: admin Date: Sun, 3 Sep 2006 18:24:39 +0000 Subject: --- system/codeigniter/CodeIgniter.php | 15 +++++++++++---- system/codeigniter/Common.php | 2 +- system/drivers/DB_active_record.php | 2 +- system/drivers/DB_driver.php | 2 +- system/helpers/date_helper.php | 2 +- system/helpers/text_helper.php | 2 +- system/libraries/Email.php | 4 ++-- system/libraries/Image_lib.php | 2 +- system/libraries/Log.php | 6 +++--- system/libraries/Output.php | 2 +- system/libraries/Pagination.php | 2 +- system/libraries/Router.php | 14 +++++++++++--- system/libraries/Session.php | 2 +- system/libraries/Trackback.php | 4 ++-- system/libraries/URI.php | 4 ++-- system/libraries/Validation.php | 8 ++++---- 16 files changed, 44 insertions(+), 29 deletions(-) (limited to 'system') diff --git a/system/codeigniter/CodeIgniter.php b/system/codeigniter/CodeIgniter.php index 1f7850ecf..5c3d19b76 100644 --- a/system/codeigniter/CodeIgniter.php +++ b/system/codeigniter/CodeIgniter.php @@ -192,13 +192,20 @@ else { $method = 'index'; } - - if ( ! method_exists($CI, $method)) + + if (method_exists($CI, '_remap')) { - show_404(); + $CI->_remap($method); } + else + { + if ( ! method_exists($CI, $method)) + { + show_404(); + } - $CI->$method(); + $CI->$method(); + } } /* diff --git a/system/codeigniter/Common.php b/system/codeigniter/Common.php index d5bec77fe..1b190e201 100644 --- a/system/codeigniter/Common.php +++ b/system/codeigniter/Common.php @@ -175,7 +175,7 @@ function log_message($level = 'error', $message, $php_error = FALSE) $config['log_threshold'], $config['log_date_format'] ); - } + } $LOG->write_log($level, $message, $php_error); } diff --git a/system/drivers/DB_active_record.php b/system/drivers/DB_active_record.php index f1995c807..1320af9ed 100644 --- a/system/drivers/DB_active_record.php +++ b/system/drivers/DB_active_record.php @@ -790,7 +790,7 @@ class CI_DB_active_record extends CI_DB_driver { } } - if (ctype_digit($this->ar_limit)) + if (is_numeric($this->ar_limit)) { $sql .= "\n"; $sql = $this->_limit($sql, $this->ar_limit, $this->ar_offset); diff --git a/system/drivers/DB_driver.php b/system/drivers/DB_driver.php index 0c2084ad8..5fcb04a00 100644 --- a/system/drivers/DB_driver.php +++ b/system/drivers/DB_driver.php @@ -352,7 +352,7 @@ class CI_DB_driver { */ function escape($str) { - if ( ! ctype_digit($str)) // bug fix to ensure that numbers are not treated as strings. + if ( ! is_numeric($str)) // bug fix to ensure that numbers are not treated as strings. { switch (gettype($str)) { diff --git a/system/helpers/date_helper.php b/system/helpers/date_helper.php index c8205bb7d..ab3a31867 100644 --- a/system/helpers/date_helper.php +++ b/system/helpers/date_helper.php @@ -223,7 +223,7 @@ function days_in_month($month = 0, $year = '') return 0; } - if ( ! ctype_digit($year) OR strlen($year) != 4) + if ( ! is_numeric($year) OR strlen($year) != 4) { $year = date('Y'); } diff --git a/system/helpers/text_helper.php b/system/helpers/text_helper.php index 15b5573bf..e4f816eb1 100644 --- a/system/helpers/text_helper.php +++ b/system/helpers/text_helper.php @@ -333,7 +333,7 @@ function highlight_phrase($str, $phrase, $tag_open = '', $tag_close = '< */ function word_wrap($str, $chars = '76') { - if ( ! ctype_digit($chars)) + if ( ! is_numeric($chars)) $chars = 76; $str = preg_replace("/(\r\n|\r|\n)/", "\n", $str); diff --git a/system/libraries/Email.php b/system/libraries/Email.php index 96dc0014d..abc77a54d 100644 --- a/system/libraries/Email.php +++ b/system/libraries/Email.php @@ -275,7 +275,7 @@ class CI_Email { */ function bcc($bcc, $limit = '') { - if ($limit != '' && ctype_digit($limit)) + if ($limit != '' && is_numeric($limit)) { $this->bcc_batch_mode = true; $this->bcc_batch_size = $limit; @@ -475,7 +475,7 @@ class CI_Email { */ function set_priority($n = 3) { - if ( ! ctype_digit($n)) + if ( ! is_numeric($n)) { $this->priority = 3; return; diff --git a/system/libraries/Image_lib.php b/system/libraries/Image_lib.php index 854f0484b..18e3253f7 100644 --- a/system/libraries/Image_lib.php +++ b/system/libraries/Image_lib.php @@ -291,7 +291,7 @@ class CI_Image_lib { // Set the quality $this->quality = trim(str_replace("%", "", $this->quality)); - if ($this->quality == '' OR $this->quality == 0 OR ! ctype_digit($this->quality)) + if ($this->quality == '' OR $this->quality == 0 OR ! is_numeric($this->quality)) $this->quality = 90; // Set the x/y coordinates diff --git a/system/libraries/Log.php b/system/libraries/Log.php index de5a9b836..6c78316f1 100644 --- a/system/libraries/Log.php +++ b/system/libraries/Log.php @@ -43,13 +43,13 @@ class CI_Log { function CI_Log($path = '', $threshold = 4, $date_fmt = '') { $this->log_path = ($path != '') ? $path : BASEPATH.'logs/'; - + if ( ! is_dir($this->log_path) OR ! is_writable($this->log_path)) { $this->_enabled = FALSE; } - if (ctype_digit($threshold)) + if (is_numeric($threshold)) { $this->_threshold = $threshold; } @@ -77,7 +77,7 @@ class CI_Log { function write_log($level = 'error', $msg, $php_error = FALSE) { if ($this->_enabled === FALSE) - { + { return FALSE; } diff --git a/system/libraries/Output.php b/system/libraries/Output.php index 73f03863e..7a03cf9c7 100644 --- a/system/libraries/Output.php +++ b/system/libraries/Output.php @@ -78,7 +78,7 @@ class CI_Output { */ function cache($time) { - $this->cache_expiration = ( ! ctype_digit($time)) ? 0 : $time; + $this->cache_expiration = ( ! is_numeric($time)) ? 0 : $time; } // -------------------------------------------------------------------- diff --git a/system/libraries/Pagination.php b/system/libraries/Pagination.php index 0bbb577a3..9d558f00a 100644 --- a/system/libraries/Pagination.php +++ b/system/libraries/Pagination.php @@ -128,7 +128,7 @@ class CI_Pagination { $this->cur_page = $obj->uri->segment($this->uri_segment); } - if ( ! ctype_digit($this->cur_page)) + if ( ! is_numeric($this->cur_page)) { $this->cur_page = 0; } diff --git a/system/libraries/Router.php b/system/libraries/Router.php index 2219f5739..1c67113f6 100644 --- a/system/libraries/Router.php +++ b/system/libraries/Router.php @@ -219,15 +219,23 @@ class CI_Router { { 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) + if (count($segments) > 0) + { + // Does the requested controller exist in the sub-folder? + if ( ! file_exists(APPPATH.'controllers/'.$this->fetch_directory().$segments['0'].EXT)) + { + show_404(); + } + } + else { $this->set_class($this->default_controller); $this->set_method('index'); diff --git a/system/libraries/Session.php b/system/libraries/Session.php index 4f08cf692..94efee55c 100644 --- a/system/libraries/Session.php +++ b/system/libraries/Session.php @@ -99,7 +99,7 @@ class CI_Session { */ $expiration = $this->object->config->item('sess_expiration'); - if (ctype_digit($expiration)) + if (is_numeric($expiration)) { if ($expiration > 0) { diff --git a/system/libraries/Trackback.php b/system/libraries/Trackback.php index 583c6d28d..8f9680d44 100644 --- a/system/libraries/Trackback.php +++ b/system/libraries/Trackback.php @@ -368,7 +368,7 @@ class CI_Trackback { $tb_array = explode('/', $url); $tb_end = $tb_array[count($tb_array)-1]; - if ( ! ctype_digit($tb_end)) + if ( ! is_numeric($tb_end)) { $tb_end = $tb_array[count($tb_array)-2]; } @@ -386,7 +386,7 @@ class CI_Trackback { $tb_array = explode('/', $url); $tb_id = $tb_array[count($tb_array)-1]; - if ( ! ctype_digit($tb_id)) + if ( ! is_numeric($tb_id)) { $tb_id = $tb_array[count($tb_array)-2]; } diff --git a/system/libraries/URI.php b/system/libraries/URI.php index c5fd4625b..ba6279e88 100644 --- a/system/libraries/URI.php +++ b/system/libraries/URI.php @@ -88,7 +88,7 @@ class CI_URI { */ function uri_to_assoc($n = 3, $default = array()) { - if ( ! ctype_digit($n)) + if ( ! is_numeric($n)) { return $default; } @@ -110,7 +110,7 @@ class CI_URI { { $retval[$val] = FALSE; } - return $default; + return $retval; } $segments = array_slice($this->segment_array(), ($n - 1)); diff --git a/system/libraries/Validation.php b/system/libraries/Validation.php index 30faa85ed..44f49ff62 100644 --- a/system/libraries/Validation.php +++ b/system/libraries/Validation.php @@ -404,7 +404,7 @@ class CI_Validation { */ function min_length($str, $val) { - if ( ! ctype_digit($val)) + if ( ! is_numeric($val)) { return FALSE; } @@ -423,7 +423,7 @@ class CI_Validation { */ function max_length($str, $val) { - if ( ! ctype_digit($val)) + if ( ! is_numeric($val)) { return FALSE; } @@ -442,7 +442,7 @@ class CI_Validation { */ function exact_length($str, $val) { - if ( ! ctype_digit($val)) + if ( ! is_numeric($val)) { return FALSE; } @@ -517,7 +517,7 @@ class CI_Validation { */ function numeric($str) { - return ( ! ctype_digit($str)) ? FALSE : TRUE; + return ( ! is_numeric($str)) ? FALSE : TRUE; } // -------------------------------------------------------------------- -- cgit v1.2.3-24-g4f1b From 5e7ac0e9a4319d29fd23b5525aef05ad28ff0706 Mon Sep 17 00:00:00 2001 From: admin Date: Sun, 3 Sep 2006 18:29:51 +0000 Subject: --- system/drivers/DB_postgre.php | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) (limited to 'system') diff --git a/system/drivers/DB_postgre.php b/system/drivers/DB_postgre.php index 673dea335..f0be3c0b1 100644 --- a/system/drivers/DB_postgre.php +++ b/system/drivers/DB_postgre.php @@ -174,7 +174,7 @@ class CI_DB_postgre extends CI_DB { if ($table == '') return '0'; - $query = $this->query("SELECT COUNT(*) AS numrows FROM ".$this->dbprefix.$table.""); + $query = $this->query('SELECT COUNT(*) AS numrows FROM "'.$this->dbprefix.$table.'"'); if ($query->num_rows() == 0) return '0'; @@ -216,7 +216,6 @@ class CI_DB_postgre extends CI_DB { * * This function adds backticks if the table name has a period * in it. Some DBs will get cranky unless periods are escaped. - * NOT NEEDED FOR POSTGRE * * @access public * @param string the table name @@ -224,12 +223,10 @@ class CI_DB_postgre extends CI_DB { */ function escape_table($table) { - /* if (stristr($table, '.')) { - $table = preg_replace("/\./", "`.`", $table); + $table = '"'.preg_replace("/\./", '"."', $table).'"'; } - */ return $table; } -- cgit v1.2.3-24-g4f1b From e6ed3d965a3148327302e6f6a22ea38a141d4be9 Mon Sep 17 00:00:00 2001 From: admin Date: Sun, 3 Sep 2006 18:38:18 +0000 Subject: --- system/application/config/database.php | 19 +++---------------- 1 file changed, 3 insertions(+), 16 deletions(-) (limited to 'system') diff --git a/system/application/config/database.php b/system/application/config/database.php index 610f6081d..cf91844d1 100644 --- a/system/application/config/database.php +++ b/system/application/config/database.php @@ -29,29 +29,16 @@ | */ -$active_group = "test"; +$active_group = "default"; $db['default']['hostname'] = "localhost"; -$db['default']['username'] = "root"; +$db['default']['username'] = ""; $db['default']['password'] = ""; -$db['default']['database'] = "ellislab"; +$db['default']['database'] = ""; $db['default']['dbdriver'] = "mysql"; $db['default']['dbprefix'] = ""; $db['default']['active_r'] = TRUE; $db['default']['pconnect'] = FALSE; $db['default']['db_debug'] = TRUE; - - -$db['test']['hostname'] = "localhost"; -$db['test']['username'] = "root"; -$db['test']['password'] = ""; -$db['test']['database'] = "tester"; -$db['test']['dbdriver'] = "mysql"; -$db['test']['dbprefix'] = ""; -$db['test']['active_r'] = TRUE; -$db['test']['pconnect'] = FALSE; -$db['test']['db_debug'] = TRUE; - - ?> \ No newline at end of file -- cgit v1.2.3-24-g4f1b From 6cd2ee9a7aa926b607922d933abc3f21b9e3868e Mon Sep 17 00:00:00 2001 From: admin Date: Mon, 4 Sep 2006 07:11:16 +0000 Subject: --- system/libraries/Config.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'system') diff --git a/system/libraries/Config.php b/system/libraries/Config.php index f7f813f86..532f70d42 100644 --- a/system/libraries/Config.php +++ b/system/libraries/Config.php @@ -208,12 +208,12 @@ class CI_Config { if ($uri == '') { - return $this->item('base_url', 1).$this->item('index_page'); + return $this->slash_item('base_url').$this->item('index_page'); } else { $suffix = ($this->item('url_suffix') == FALSE) ? '' : $this->item('url_suffix'); - return $this->item('base_url', 1).$this->item('index_page', 1).preg_replace("|^/*(.+?)/*$|", "\\1", $uri).$suffix; + return $this->slash_item('base_url').$this->slash_item('index_page').preg_replace("|^/*(.+?)/*$|", "\\1", $uri).$suffix; } } // END site_url() -- cgit v1.2.3-24-g4f1b From d7bb13b67294da6f0e0accccf6f992465665c149 Mon Sep 17 00:00:00 2001 From: admin Date: Mon, 4 Sep 2006 07:13:05 +0000 Subject: --- system/language/english/validation_lang.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'system') diff --git a/system/language/english/validation_lang.php b/system/language/english/validation_lang.php index 326fe5579..580ce2975 100644 --- a/system/language/english/validation_lang.php +++ b/system/language/english/validation_lang.php @@ -7,7 +7,8 @@ $lang['valid_url'] = "The %s field must contain a valid URL."; $lang['min_length'] = "The %s field must be at least %s characters in length."; $lang['max_length'] = "The %s field can not exceed %s characters in length."; $lang['exact_length'] = "The %s field must be exactly %s characters in length."; -$lang['alpha'] = "The %s field may only contain alpha-numeric characters."; +$lang['alpha'] = "The %s field may only contain alphabetical characters."; +$lang['alpha_numeric'] = "The %s field may only contain alpha-numeric characters."; $lang['alpha_dash'] = "The %s field may only contain alpha-numeric characters, underscores, and dashes."; $lang['numeric'] = "The %s field must contain a number."; $lang['matches'] = "The %s field does not match the %s field."; -- cgit v1.2.3-24-g4f1b From 813711e6ddfa347fd0d74c109c14fe10a919f668 Mon Sep 17 00:00:00 2001 From: admin Date: Mon, 4 Sep 2006 07:13:57 +0000 Subject: --- system/libraries/Config.php | 2 +- system/libraries/Router.php | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) (limited to 'system') diff --git a/system/libraries/Config.php b/system/libraries/Config.php index 532f70d42..108c94ab7 100644 --- a/system/libraries/Config.php +++ b/system/libraries/Config.php @@ -229,7 +229,7 @@ class CI_Config { function system_url() { $x = explode("/", preg_replace("|/*(.+?)/*$|", "\\1", BASEPATH)); - return $this->item('base_url', 1).end($x).'/'; + return $this->slash_item('base_url').end($x).'/'; } // END system_url() diff --git a/system/libraries/Router.php b/system/libraries/Router.php index 1c67113f6..c7e855a78 100644 --- a/system/libraries/Router.php +++ b/system/libraries/Router.php @@ -312,12 +312,12 @@ class CI_Router { $key = str_replace(':any', '.+', str_replace(':num', '[0-9]+', $key)); // Does the RegEx match? - if (preg_match('|^'.$key.'$|', $uri)) + if (preg_match('#^'.preg_quote($key).'$#', $uri)) { // Do we have a back-reference? if (strpos($val, '$') !== FALSE AND strpos($key, '(') !== FALSE) { - $val = preg_replace('|^'.$key.'$|', $val, $uri); + $val = preg_replace('#^'.preg_quote($key).'$#', $val, $uri); } $this->_compile_segments(explode('/', $val)); -- cgit v1.2.3-24-g4f1b From 27818494dca469e96709fd9c54ba8f8461d88714 Mon Sep 17 00:00:00 2001 From: admin Date: Tue, 5 Sep 2006 03:31:28 +0000 Subject: --- system/libraries/Router.php | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) (limited to 'system') diff --git a/system/libraries/Router.php b/system/libraries/Router.php index c7e855a78..de1a6e9a8 100644 --- a/system/libraries/Router.php +++ b/system/libraries/Router.php @@ -239,8 +239,14 @@ class CI_Router { { $this->set_class($this->default_controller); $this->set_method('index'); - $this->directory = ''; - return array(); + + // Does the default controller exist in the sub-folder? + if ( ! file_exists(APPPATH.'controllers/'.$this->fetch_directory().$this->default_controller.EXT)) + { + $this->directory = ''; + return array(); + } + } return $segments; -- cgit v1.2.3-24-g4f1b From 73e582fbd7d7f6cdcf7f18b31b4b96ecb7c4141f Mon Sep 17 00:00:00 2001 From: admin Date: Wed, 6 Sep 2006 01:36:34 +0000 Subject: --- system/helpers/security_helper.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system') diff --git a/system/helpers/security_helper.php b/system/helpers/security_helper.php index 918e4ae90..f14ba72a0 100644 --- a/system/helpers/security_helper.php +++ b/system/helpers/security_helper.php @@ -50,7 +50,7 @@ function xss_clean($str, $charset = 'ISO-8859-1') * @param string * @return string */ -function hash($str, $type = 'sha1') +function dohash($str, $type = 'sha1') { if ($type == 'sha1') { -- cgit v1.2.3-24-g4f1b From 1066dcb279e26de29fd663d61957dfcd1f939f9a Mon Sep 17 00:00:00 2001 From: admin Date: Wed, 6 Sep 2006 01:55:56 +0000 Subject: --- system/drivers/DB_postgre.php | 30 +++++++++++++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) (limited to 'system') diff --git a/system/drivers/DB_postgre.php b/system/drivers/DB_postgre.php index f0be3c0b1..aa7ec7020 100644 --- a/system/drivers/DB_postgre.php +++ b/system/drivers/DB_postgre.php @@ -154,7 +154,35 @@ class CI_DB_postgre extends CI_DB { */ function insert_id() { - return pg_last_oid($this->result_id); + $v = pg_version($this->conn_id); + $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; } // -------------------------------------------------------------------- -- cgit v1.2.3-24-g4f1b From fdd928182d6691ed2073f6f3a90427157007f54b Mon Sep 17 00:00:00 2001 From: admin Date: Wed, 6 Sep 2006 01:57:41 +0000 Subject: --- system/drivers/DB_odbc.php | 69 +++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 65 insertions(+), 4 deletions(-) (limited to 'system') diff --git a/system/drivers/DB_odbc.php b/system/drivers/DB_odbc.php index 50f39accd..a5a8db64d 100644 --- a/system/drivers/DB_odbc.php +++ b/system/drivers/DB_odbc.php @@ -445,9 +445,16 @@ class CI_DB_odbc_result extends CI_DB_result { */ function _fetch_assoc() { - return odbc_fetch_array($this->result_id); + if (function_exists('odbc_fetch_object')) + { + return odbc_fetch_array($this->result_id); + } + else + { + return $this->_odbc_fetch_array($this->result_id); + } } - + // -------------------------------------------------------------------- /** @@ -460,9 +467,63 @@ class CI_DB_odbc_result extends CI_DB_result { */ function _fetch_object() { - return odbc_fetch_object($this->result_id); + 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; + } + } ?> \ No newline at end of file -- cgit v1.2.3-24-g4f1b From 4d07c1528873d70efcb6fbf305a8ab930a9bc758 Mon Sep 17 00:00:00 2001 From: admin Date: Wed, 6 Sep 2006 02:14:53 +0000 Subject: --- system/helpers/url_helper.php | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) (limited to 'system') diff --git a/system/helpers/url_helper.php b/system/helpers/url_helper.php index 09169e32e..6e2f7f452 100644 --- a/system/helpers/url_helper.php +++ b/system/helpers/url_helper.php @@ -90,7 +90,14 @@ function index_page() */ function anchor($uri = '', $title = '', $attributes = '') { - $site_url = ( ! preg_match('!^\w+://!i', $uri)) ? site_url($uri) : $uri; + if ( ! is_array($uri)) + { + $site_url = ( ! preg_match('!^\w+://!i', $uri)) ? site_url($uri) : $uri; + } + else + { + $site_url = site_url($uri); + } if ($title == '') { -- cgit v1.2.3-24-g4f1b From 2e5872ac0527c342e066bdc2e8facf452858dd39 Mon Sep 17 00:00:00 2001 From: admin Date: Wed, 6 Sep 2006 02:32:55 +0000 Subject: --- system/libraries/Loader.php | 25 +++---------------------- 1 file changed, 3 insertions(+), 22 deletions(-) (limited to 'system') diff --git a/system/libraries/Loader.php b/system/libraries/Loader.php index e2467fa64..a140fb5a2 100644 --- a/system/libraries/Loader.php +++ b/system/libraries/Loader.php @@ -565,15 +565,7 @@ class CI_Loader { { if (isset($autoload[$type])) { - if ( ! is_array($autoload[$type])) - { - $autoload[$type] = array($autoload[$type]); - } - - foreach ($autoload[$type] as $item) - { - $this->$type($item); - } + $this->$type($autoload[$type]); } } } @@ -592,20 +584,9 @@ class CI_Loader { */ function _ci_object_to_array($object) { - if ( ! is_object($object)) - { - return $object; - } - - $array = array(); - foreach (get_object_vars($object) as $key => $val) - { - $array[$key] = $val; - } - - return $array; + return (is_object($object)) ? get_object_vars($object) : $object; } + // END _ci_object_to_array() } -// END Loader Class ?> \ No newline at end of file -- cgit v1.2.3-24-g4f1b From eb567c702cda744b53be22206c55a960a36cb678 Mon Sep 17 00:00:00 2001 From: admin Date: Wed, 6 Sep 2006 02:48:47 +0000 Subject: --- system/codeigniter/CodeIgniter.php | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'system') diff --git a/system/codeigniter/CodeIgniter.php b/system/codeigniter/CodeIgniter.php index 5c3d19b76..e09bf3deb 100644 --- a/system/codeigniter/CodeIgniter.php +++ b/system/codeigniter/CodeIgniter.php @@ -188,6 +188,16 @@ if ($RTR->scaffolding_request === TRUE) } else { + /* + * ------------------------------------------------------ + * Is there a "post_controller_constructor" hook? + * ------------------------------------------------------ + */ + if ($EXT->_hook_exists('post_controller_constructor')) + { + $EXT->_call_hook('post_controller_constructor'); + } + if ($method == $class) { $method = 'index'; -- cgit v1.2.3-24-g4f1b From 764672b45108814fc643be65b53b18f0b6507112 Mon Sep 17 00:00:00 2001 From: admin Date: Fri, 15 Sep 2006 20:02:05 +0000 Subject: --- system/libraries/Hooks.php | 37 ++++++++----------------------------- 1 file changed, 8 insertions(+), 29 deletions(-) (limited to 'system') diff --git a/system/libraries/Hooks.php b/system/libraries/Hooks.php index 389e7ac14..7ff0592ff 100644 --- a/system/libraries/Hooks.php +++ b/system/libraries/Hooks.php @@ -66,34 +66,6 @@ class CI_Hooks { } // END CI_Hooks() - // -------------------------------------------------------------------- - - /** - * Does a given hook exist? - * - * Returns TRUE/FALSE based on whether a given hook exists - * - * @access private - * @param string - * @return bool - */ - function _hook_exists($which = '') - { - if ( ! $this->enabled) - { - return FALSE; - } - - if ( ! isset($this->hooks[$which])) - { - return FALSE; - } - - return TRUE; - } - // END hook_exists() - - // -------------------------------------------------------------------- /** @@ -107,6 +79,11 @@ class CI_Hooks { */ 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) @@ -118,6 +95,8 @@ class CI_Hooks { { $this->_run_hook($this->hooks[$which]); } + + return TRUE; } // END hook_exists() @@ -144,7 +123,7 @@ class CI_Hooks { // ----------------------------------- // If the script being called happens to have the same - // extension call within it a loop can happen + // hook call within it a loop can happen if ($this->in_progress == TRUE) { -- cgit v1.2.3-24-g4f1b From af436d7ceb4ea5afb96e3cbe1545ba9ace3d062a Mon Sep 17 00:00:00 2001 From: admin Date: Fri, 15 Sep 2006 20:02:14 +0000 Subject: --- system/codeigniter/CodeIgniter.php | 43 +++++++------------------------------- 1 file changed, 8 insertions(+), 35 deletions(-) (limited to 'system') diff --git a/system/codeigniter/CodeIgniter.php b/system/codeigniter/CodeIgniter.php index e09bf3deb..09cdcbfba 100644 --- a/system/codeigniter/CodeIgniter.php +++ b/system/codeigniter/CodeIgniter.php @@ -66,10 +66,7 @@ $EXT =& _load_class('CI_Hooks'); * Is there a "pre_system" hook? * ------------------------------------------------------ */ -if ($EXT->_hook_exists('pre_system')) -{ - $EXT->_call_hook('pre_system'); -} +$EXT->_call_hook('pre_system'); /* * ------------------------------------------------------ @@ -87,11 +84,7 @@ $OUT =& _load_class('CI_Output'); * ------------------------------------------------------ */ -if ($EXT->_hook_exists('cache_override')) -{ - $EXT->_call_hook('cache_override'); -} -else +if ($EXT->_call_hook('cache_override') === FALSE) { if ($OUT->_display_cache() == TRUE) { @@ -163,10 +156,7 @@ if ( ! class_exists($class) * Is there a "pre_controller" hook? * ------------------------------------------------------ */ -if ($EXT->_hook_exists('pre_controller')) -{ - $EXT->_call_hook('pre_controller'); -} +$EXT->_call_hook('pre_controller'); /* * ------------------------------------------------------ @@ -177,11 +167,7 @@ $CI = new $class(); if ($RTR->scaffolding_request === TRUE) { - if ($EXT->_hook_exists('scaffolding_override')) - { - $EXT->_call_hook('scaffolding_override'); - } - else + if ($EXT->_call_hook('scaffolding_override') === FALSE) { $CI->_ci_scaffolding(); } @@ -193,10 +179,7 @@ else * Is there a "post_controller_constructor" hook? * ------------------------------------------------------ */ - if ($EXT->_hook_exists('post_controller_constructor')) - { - $EXT->_call_hook('post_controller_constructor'); - } + $EXT->_call_hook('post_controller_constructor'); if ($method == $class) { @@ -223,10 +206,7 @@ else * Is there a "post_controller" hook? * ------------------------------------------------------ */ -if ($EXT->_hook_exists('post_controller')) -{ - $EXT->_call_hook('post_controller'); -} +$EXT->_call_hook('post_controller'); /* * ------------------------------------------------------ @@ -234,11 +214,7 @@ if ($EXT->_hook_exists('post_controller')) * ------------------------------------------------------ */ -if ($EXT->_hook_exists('display_override')) -{ - $EXT->_call_hook('display_override'); -} -else +if ($EXT->_call_hook('display_override') === FALSE) { $OUT->_display(); } @@ -248,10 +224,7 @@ else * Is there a "post_system" hook? * ------------------------------------------------------ */ -if ($EXT->_hook_exists('post_system')) -{ - $EXT->_call_hook('post_system'); -} +$EXT->_call_hook('post_system'); /* * ------------------------------------------------------ -- cgit v1.2.3-24-g4f1b From 349b09c2af14c79c332a6b7d5e3b653a8ad527b7 Mon Sep 17 00:00:00 2001 From: admin Date: Fri, 15 Sep 2006 20:07:00 +0000 Subject: --- system/codeigniter/Common.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'system') diff --git a/system/codeigniter/Common.php b/system/codeigniter/Common.php index 1b190e201..6d76fb098 100644 --- a/system/codeigniter/Common.php +++ b/system/codeigniter/Common.php @@ -38,7 +38,7 @@ */ function &_load_class($class, $instantiate = TRUE) { - static $objects; + static $objects = array(); if ( ! isset($objects[$class])) { @@ -63,7 +63,7 @@ function &_load_class($class, $instantiate = TRUE) } else { - $objects[$class] = FALSE; + $objects[$class] = TRUE; } } -- cgit v1.2.3-24-g4f1b From 71430b4c30f01c861abe379becc670748e3b4a19 Mon Sep 17 00:00:00 2001 From: admin Date: Fri, 15 Sep 2006 20:29:25 +0000 Subject: --- system/libraries/Router.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'system') diff --git a/system/libraries/Router.php b/system/libraries/Router.php index de1a6e9a8..1dd1e5426 100644 --- a/system/libraries/Router.php +++ b/system/libraries/Router.php @@ -318,12 +318,12 @@ class CI_Router { $key = str_replace(':any', '.+', str_replace(':num', '[0-9]+', $key)); // Does the RegEx match? - if (preg_match('#^'.preg_quote($key).'$#', $uri)) + if (preg_match('#^'.$key.'$#', $uri)) { // Do we have a back-reference? if (strpos($val, '$') !== FALSE AND strpos($key, '(') !== FALSE) { - $val = preg_replace('#^'.preg_quote($key).'$#', $val, $uri); + $val = preg_replace('#^'.$key.'$#', $val, $uri); } $this->_compile_segments(explode('/', $val)); -- cgit v1.2.3-24-g4f1b From 633ec3758910482863299c7122dda3c15d9758a8 Mon Sep 17 00:00:00 2001 From: admin Date: Fri, 15 Sep 2006 20:43:32 +0000 Subject: --- system/libraries/Log.php | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) (limited to 'system') diff --git a/system/libraries/Log.php b/system/libraries/Log.php index 6c78316f1..392742584 100644 --- a/system/libraries/Log.php +++ b/system/libraries/Log.php @@ -40,23 +40,25 @@ class CI_Log { * @param string the error threshold * @param string the date formatting codes */ - function CI_Log($path = '', $threshold = 4, $date_fmt = '') - { - $this->log_path = ($path != '') ? $path : BASEPATH.'logs/'; + function CI_Log() + { + $config =& _get_config(); + + $this->log_path = ($config['log_path'] != '') ? $config['log_path'] : BASEPATH.'logs/'; if ( ! is_dir($this->log_path) OR ! is_writable($this->log_path)) { $this->_enabled = FALSE; } - if (is_numeric($threshold)) + if (is_numeric($config['log_threshold'])) { - $this->_threshold = $threshold; + $this->_threshold = $config['log_threshold']; } - if ($date_fmt != '') + if ($config['log_date_format'] != '') { - $this->_date_fmt = $date_fmt; + $this->_date_fmt = $config['log_date_format']; } } // END CI_Log() -- cgit v1.2.3-24-g4f1b From 43a46cc3d3d485a50c287d33ad94f044f8a6c46c Mon Sep 17 00:00:00 2001 From: admin Date: Fri, 15 Sep 2006 20:44:52 +0000 Subject: --- system/codeigniter/Common.php | 36 ++++-------------------------------- 1 file changed, 4 insertions(+), 32 deletions(-) (limited to 'system') diff --git a/system/codeigniter/Common.php b/system/codeigniter/Common.php index 6d76fb098..a4531a7d0 100644 --- a/system/codeigniter/Common.php +++ b/system/codeigniter/Common.php @@ -110,12 +110,7 @@ function &_get_config() */ function show_error($message) { - if ( ! class_exists('CI_Exceptions')) - { - include_once(BASEPATH.'libraries/Exceptions.php'); - } - - $error = new CI_Exceptions(); + $error =& _load_class('CI_Exceptions'); echo $error->show_error('An Error Was Encountered', $message); exit; } @@ -133,12 +128,7 @@ function show_error($message) */ function show_404($page = '') { - if ( ! class_exists('CI_Exceptions')) - { - include_once(BASEPATH.'libraries/Exceptions.php'); - } - - $error = new CI_Exceptions(); + $error =& _load_class('CI_Exceptions'); $error->show_404($page); exit; } @@ -163,20 +153,7 @@ function log_message($level = 'error', $message, $php_error = FALSE) return; } - if ( ! class_exists('CI_Log')) - { - include_once(BASEPATH.'libraries/Log.php'); - } - - if ( ! is_object($LOG)) - { - $LOG = new CI_Log( - $config['log_path'], - $config['log_threshold'], - $config['log_date_format'] - ); - } - + $LOG =& _load_class('CI_Log'); $LOG->write_log($level, $message, $php_error); } @@ -209,12 +186,7 @@ function _exception_handler($severity, $message, $filepath, $line) return; } - // Send the PHP error to the log file... - if ( ! class_exists('CI_Exceptions')) - { - include_once(BASEPATH.'libraries/Exceptions.php'); - } - $error = new CI_Exceptions(); + $error =& _load_class('CI_Exceptions'); // Should we display the error? // We'll get the current error_reporting level and add its bits -- cgit v1.2.3-24-g4f1b From 1856f58a16da54f12414350f2e2a833d0cdd7d45 Mon Sep 17 00:00:00 2001 From: admin Date: Fri, 15 Sep 2006 20:48:15 +0000 Subject: --- system/libraries/Output.php | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) (limited to 'system') diff --git a/system/libraries/Output.php b/system/libraries/Output.php index 7a03cf9c7..9523599e7 100644 --- a/system/libraries/Output.php +++ b/system/libraries/Output.php @@ -147,7 +147,7 @@ class CI_Output { return; } - $uri = $obj->config->slash_item('base_url'). + $uri = $obj->config->item('base_url'). $obj->config->item('index_page'). $obj->uri->uri_string(); @@ -191,8 +191,10 @@ class CI_Output { } // Build the file path. The file name is an MD5 hash of the full URI - $uri = $CFG->item('base_url', 1).$CFG->item('index_page').$RTR->uri_string; - + $uri = $obj->config->item('base_url'). + $obj->config->item('index_page'). + $obj->uri->uri_string(); + $filepath = $cache_path.md5($uri); if ( ! @file_exists($filepath)) -- cgit v1.2.3-24-g4f1b From 55c11e03927b371f895d98a0b533f69cac246b07 Mon Sep 17 00:00:00 2001 From: admin Date: Fri, 15 Sep 2006 20:50:51 +0000 Subject: --- system/application/config/mimes.php | 1 - 1 file changed, 1 deletion(-) (limited to 'system') diff --git a/system/application/config/mimes.php b/system/application/config/mimes.php index 06bfcc67b..b09cc1963 100644 --- a/system/application/config/mimes.php +++ b/system/application/config/mimes.php @@ -52,7 +52,6 @@ $mimes = array( 'hqx' => 'application/mac-binhex40', 'xhtml' => 'application/xhtml+xml', 'xht' => 'application/xhtml+xml', 'zip' => array('application/zip', 'application/x-zip-compressed'), - 'zip' => 'application/zip', 'mid' => 'audio/midi', 'midi' => 'audio/midi', 'mpga' => 'audio/mpeg', -- cgit v1.2.3-24-g4f1b From dac65764e5ead0bcc9e7fcb2477926d7a2c1dc95 Mon Sep 17 00:00:00 2001 From: admin Date: Sun, 17 Sep 2006 18:05:43 +0000 Subject: --- system/libraries/Validation.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system') diff --git a/system/libraries/Validation.php b/system/libraries/Validation.php index 44f49ff62..e4fd36698 100644 --- a/system/libraries/Validation.php +++ b/system/libraries/Validation.php @@ -187,7 +187,7 @@ class CI_Validation { $ex = explode('|', $rules); // Is the field required? If not, if the field is blank we'll move on to the next text - if ( ! in_array('required', $ex)) + if ( ! in_array('required', $ex) AND strpos($rules, 'callback_') === FALSE) { if ( ! isset($_POST[$field]) OR $_POST[$field] == '') { -- cgit v1.2.3-24-g4f1b From f6d823ee041caab303a7aba6ecd8c358c6970113 Mon Sep 17 00:00:00 2001 From: admin Date: Sun, 17 Sep 2006 18:10:57 +0000 Subject: --- system/libraries/Unit_test.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'system') diff --git a/system/libraries/Unit_test.php b/system/libraries/Unit_test.php index bf50350ae..b2f4bf8cd 100644 --- a/system/libraries/Unit_test.php +++ b/system/libraries/Unit_test.php @@ -223,9 +223,9 @@ class CI_Unit_test { * @params string * @return void */ - function set_template($tempalte) + function set_template($template) { - $this->_template = $tempalte; + $this->_template = $template; } // -------------------------------------------------------------------- -- cgit v1.2.3-24-g4f1b From b68745e494773bce023c9a7eaca672e32beb1a47 Mon Sep 17 00:00:00 2001 From: admin Date: Sun, 17 Sep 2006 18:13:34 +0000 Subject: --- system/drivers/DB_mysqli.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system') diff --git a/system/drivers/DB_mysqli.php b/system/drivers/DB_mysqli.php index fadcdd3c4..8bea60444 100644 --- a/system/drivers/DB_mysqli.php +++ b/system/drivers/DB_mysqli.php @@ -451,7 +451,7 @@ class CI_DB_mysqli_result extends CI_DB_result { $F->type = $field->type; $F->default = $field->def; $F->max_length = $field->max_length; - $F->primary_key = 0; + $F->primary_key = ($field->flags & MYSQLI_PRI_KEY_FLAG) ? 1 : 0; $retval[] = $F; } -- cgit v1.2.3-24-g4f1b From f69581c381ab01d58c24701aea77b2b091d754a3 Mon Sep 17 00:00:00 2001 From: admin Date: Sun, 17 Sep 2006 22:10:16 +0000 Subject: --- system/application/config/hooks.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'system') diff --git a/system/application/config/hooks.php b/system/application/config/hooks.php index 8ebb236d8..95e74cbf4 100644 --- a/system/application/config/hooks.php +++ b/system/application/config/hooks.php @@ -4,7 +4,9 @@ | Hooks | ------------------------------------------------------------------------- | This file lets you define "hooks" to extend CI without hacking the core -| files. Please see the user guide for info... +| files. Please see the user guide for info: +| +| http://www.codeigniter.com/user_guide/general/hooks.html | */ -- cgit v1.2.3-24-g4f1b From fd77f5eca4226d608b372e2edc11d7b39b439205 Mon Sep 17 00:00:00 2001 From: admin Date: Sun, 17 Sep 2006 22:12:26 +0000 Subject: --- system/application/config/routes.php | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) (limited to 'system') diff --git a/system/application/config/routes.php b/system/application/config/routes.php index dc8a32d01..b86cf9182 100644 --- a/system/application/config/routes.php +++ b/system/application/config/routes.php @@ -41,12 +41,10 @@ $route['default_controller'] = "welcome"; -$route['scaffolding_trigger'] = "scaffolding"; +$route['scaffolding_trigger'] = ""; // Define your own routes below ------------------------------------------- -$route['products/([a-z]+)/(\d+)'] = "bamo/$1/a$2"; - ?> \ No newline at end of file -- cgit v1.2.3-24-g4f1b From c55b02bcee63c0ea4563583e54959b9f068ea9e9 Mon Sep 17 00:00:00 2001 From: admin Date: Mon, 18 Sep 2006 07:44:58 +0000 Subject: --- system/libraries/Output.php | 1 + 1 file changed, 1 insertion(+) (limited to 'system') diff --git a/system/libraries/Output.php b/system/libraries/Output.php index 9523599e7..c5a9a6281 100644 --- a/system/libraries/Output.php +++ b/system/libraries/Output.php @@ -191,6 +191,7 @@ class CI_Output { } // Build the file path. The file name is an MD5 hash of the full URI + $obj =& get_instance(); $uri = $obj->config->item('base_url'). $obj->config->item('index_page'). $obj->uri->uri_string(); -- cgit v1.2.3-24-g4f1b From 15c2bcc24c4b4f4999c5dc73eab57b9b3a6f942e Mon Sep 17 00:00:00 2001 From: admin Date: Mon, 18 Sep 2006 08:17:56 +0000 Subject: --- system/libraries/Output.php | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) (limited to 'system') diff --git a/system/libraries/Output.php b/system/libraries/Output.php index c5a9a6281..fd07a9f6e 100644 --- a/system/libraries/Output.php +++ b/system/libraries/Output.php @@ -178,7 +178,7 @@ class CI_Output { * @access public * @return void */ - function _display_cache() + function _display_cache(&$CFG, &$RTR) { $CFG =& _load_class('CI_Config'); $RTR =& _load_class('CI_Router'); @@ -191,10 +191,9 @@ class CI_Output { } // Build the file path. The file name is an MD5 hash of the full URI - $obj =& get_instance(); - $uri = $obj->config->item('base_url'). - $obj->config->item('index_page'). - $obj->uri->uri_string(); + $uri = $CFG->item('base_url'). + $CFG->item('index_page'). + $RTR->uri_string; $filepath = $cache_path.md5($uri); -- cgit v1.2.3-24-g4f1b From 06508c43fbf5764755ca3a00e64e141a20d9ddff Mon Sep 17 00:00:00 2001 From: admin Date: Mon, 18 Sep 2006 08:18:08 +0000 Subject: --- system/codeigniter/CodeIgniter.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system') diff --git a/system/codeigniter/CodeIgniter.php b/system/codeigniter/CodeIgniter.php index 09cdcbfba..5146c807d 100644 --- a/system/codeigniter/CodeIgniter.php +++ b/system/codeigniter/CodeIgniter.php @@ -86,7 +86,7 @@ $OUT =& _load_class('CI_Output'); if ($EXT->_call_hook('cache_override') === FALSE) { - if ($OUT->_display_cache() == TRUE) + if ($OUT->_display_cache($CFG, $RTR) == TRUE) { exit; } -- cgit v1.2.3-24-g4f1b From 89a8b9700cd8b27da1f27a18ab5f9d4c5ca2cef4 Mon Sep 17 00:00:00 2001 From: admin Date: Mon, 18 Sep 2006 15:46:28 +0000 Subject: --- system/libraries/Validation.php | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'system') diff --git a/system/libraries/Validation.php b/system/libraries/Validation.php index e4fd36698..227cf9f9a 100644 --- a/system/libraries/Validation.php +++ b/system/libraries/Validation.php @@ -240,7 +240,6 @@ class CI_Validation { // Cycle through the rules! foreach ($ex As $rule) { - // Is the rule a callback? $callback = FALSE; if (substr($rule, 0, 9) == 'callback_') @@ -267,6 +266,12 @@ class CI_Validation { } $result = $this->obj->$rule($_POST[$field], $param); + + // If the field isn't requires we'll move on... + if ( ! in_array('required', $ex)) + { + continue; + } } else { -- cgit v1.2.3-24-g4f1b From 46402b00b8b67c2bd1de380ca14a411118b6f0ff Mon Sep 17 00:00:00 2001 From: admin Date: Tue, 19 Sep 2006 04:56:14 +0000 Subject: --- system/drivers/DB_mysqli.php | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'system') diff --git a/system/drivers/DB_mysqli.php b/system/drivers/DB_mysqli.php index 8bea60444..49adb5cc3 100644 --- a/system/drivers/DB_mysqli.php +++ b/system/drivers/DB_mysqli.php @@ -89,7 +89,12 @@ class CI_DB_mysqli extends CI_DB { { $sql = $this->_prep_query($sql); $result = @mysqli_query($this->conn_id, $sql); - mysqli_next_result($this->conn_id); + + // We only advance the result pointer if there isn't an error + if (mysqli_errno($this->conn_id) == 0) + { + mysqli_next_result($this->conn_id); + } return $result; } -- cgit v1.2.3-24-g4f1b From 402ddf4859c4e0691aa3eed7d57ad6d1b0a21a9b Mon Sep 17 00:00:00 2001 From: admin Date: Wed, 20 Sep 2006 18:57:05 +0000 Subject: --- system/helpers/array_helper.php | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) (limited to 'system') diff --git a/system/helpers/array_helper.php b/system/helpers/array_helper.php index cccde1fc4..de0faeeff 100644 --- a/system/helpers/array_helper.php +++ b/system/helpers/array_helper.php @@ -27,6 +27,30 @@ // ------------------------------------------------------------------------ +/** + * Element + * + * Lets you determine whether an array index is set and whether it has a value. + * If the element is empty it returns FALSE (or whater you specify as the default value.) + * + * @access public + * @param string + * @param array + * @param mixed + * @return mixed depends on what the array contains + */ +function element($item, $array, $default = FALSE) +{ + if ( ! isset($array[$item]) OR $array[$item] == "") + { + return $default; + } + + return $array[$item]; +} + +// ------------------------------------------------------------------------ + /** * Random Element - Takes an array as input and returns a random element * -- cgit v1.2.3-24-g4f1b From d183cb5255817dc431196964becef0db037f0620 Mon Sep 17 00:00:00 2001 From: admin Date: Wed, 20 Sep 2006 21:06:32 +0000 Subject: --- system/libraries/Language.php | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) (limited to 'system') diff --git a/system/libraries/Language.php b/system/libraries/Language.php index 328d53e46..41dab46f4 100644 --- a/system/libraries/Language.php +++ b/system/libraries/Language.php @@ -66,12 +66,24 @@ class CI_Language { $idiom = ($deft_lang == '') ? 'english' : $deft_lang; } - if ( ! file_exists(BASEPATH.'language/'.$idiom.'/'.$langfile)) + // Determine where the language file is and load it + + if (file_exists(APPPATH.'language/'.$idiom.'/'.$langfile)) { - show_error('Unable to load the requested language file: language/'.$langfile); + include_once(APPPATH.'language/'.$idiom.'/'.$langfile); + } + else + { + if (file_exists(BASEPATH.'language/'.$idiom.'/'.$langfile)) + { + include_once(BASEPATH.'language/'.$idiom.'/'.$langfile); + } + else + { + show_error('Unable to load the requested language file: language/'.$langfile); + } } - include_once(BASEPATH.'language/'.$idiom.'/'.$langfile); if ( ! isset($lang)) { -- cgit v1.2.3-24-g4f1b From 480da81d6111a5c1faf4433707ee8d3b3de8031e Mon Sep 17 00:00:00 2001 From: admin Date: Wed, 20 Sep 2006 21:11:04 +0000 Subject: --- system/libraries/Loader.php | 36 +++++++++++++++++++++++++++--------- 1 file changed, 27 insertions(+), 9 deletions(-) (limited to 'system') diff --git a/system/libraries/Loader.php b/system/libraries/Loader.php index a140fb5a2..ead55dff7 100644 --- a/system/libraries/Loader.php +++ b/system/libraries/Loader.php @@ -243,12 +243,21 @@ class CI_Loader { $helper = strtolower(str_replace(EXT, '', str_replace('_helper', '', $helper)).'_helper'); - if ( ! file_exists(BASEPATH.'helpers/'.$helper.EXT)) + if (file_exists(APPPATH.'helpers/'.$helper.EXT)) { - show_error('Unable to load the requested file: helpers/'.$helper.EXT); + include_once(APPPATH.'helpers/'.$helper.EXT); + } + else + { + if (file_exists(BASEPATH.'helpers/'.$helper.EXT)) + { + include_once(BASEPATH.'helpers/'.$helper.EXT); + } + else + { + show_error('Unable to load the requested file: helpers/'.$helper.EXT); + } } - - include_once(BASEPATH.'helpers/'.$helper.EXT); $this->helpers[$helper] = TRUE; } @@ -300,14 +309,23 @@ class CI_Loader { continue; } - $plugin = strtolower(str_replace(EXT, '', str_replace('_plugin.', '', $plugin)).'_pi'); + $plugin = strtolower(str_replace(EXT, '', str_replace('_plugin.', '', $plugin)).'_pi'); - if ( ! file_exists(BASEPATH.'plugins/'.$plugin.EXT)) + if (file_exists(APPPATH.'plugins/'.$plugin.EXT)) { - show_error('Unable to load the requested file: plugins/'.$plugin.EXT); + include_once(APPPATH.'plugins/'.$plugin.EXT); + } + else + { + if (file_exists(BASEPATH.'plugins/'.$plugin.EXT)) + { + include_once(BASEPATH.'plugins/'.$plugin.EXT); + } + else + { + show_error('Unable to load the requested file: plugins/'.$plugin.EXT); + } } - - include_once(BASEPATH.'plugins/'.$plugin.EXT); $this->plugins[$plugin] = TRUE; } -- cgit v1.2.3-24-g4f1b From e348efb92de213fcfbc312993d8b21a30eb280c0 Mon Sep 17 00:00:00 2001 From: admin Date: Wed, 20 Sep 2006 21:13:26 +0000 Subject: --- system/drivers/DB_active_record.php | 4 +- system/drivers/DB_driver.php | 107 ++++++++++++++++-------------------- system/drivers/DB_mssql.php | 2 +- system/drivers/DB_mysql.php | 2 +- system/drivers/DB_mysqli.php | 2 +- system/drivers/DB_odbc.php | 2 +- system/drivers/DB_postgre.php | 2 +- system/drivers/DB_sqlite.php | 2 +- system/libraries/Validation.php | 18 +++--- 9 files changed, 65 insertions(+), 76 deletions(-) (limited to 'system') diff --git a/system/drivers/DB_active_record.php b/system/drivers/DB_active_record.php index 1320af9ed..c7e4f096c 100644 --- a/system/drivers/DB_active_record.php +++ b/system/drivers/DB_active_record.php @@ -257,7 +257,7 @@ class CI_DB_active_record extends CI_DB_driver { /** * Like * - * Called by like() or olike() + * Called by like() or orlike() * * @access private * @param mixed @@ -346,7 +346,7 @@ class CI_DB_active_record extends CI_DB_driver { // -------------------------------------------------------------------- /** - * Sets the OR HAVING value + * Sets the HAVING values * * Called by having() or orhaving() * diff --git a/system/drivers/DB_driver.php b/system/drivers/DB_driver.php index 5fcb04a00..2d1232d7b 100644 --- a/system/drivers/DB_driver.php +++ b/system/drivers/DB_driver.php @@ -46,6 +46,12 @@ class CI_DB_driver { var $bind_marker = '?'; var $queries = array(); + // These are use with Oracle + var $stmt_id; + var $curs_id; + var $limit_used; + + /** * Constructor. Accepts one parameter containing the database * connection settings. @@ -151,6 +157,11 @@ class CI_DB_driver { } return FALSE; } + + if ($this->dbdriver == 'oci8') + { + return $sql; + } $query = $this->query($sql); $row = $query->row(); @@ -173,7 +184,7 @@ class CI_DB_driver { * @param array An array of binding data * @return mixed */ - function query($sql, $binds = FALSE) + function query($sql, $binds = FALSE, $return_object = TRUE) { if ( ! $this->conn_id) { @@ -228,11 +239,19 @@ class CI_DB_driver { $this->query_count++; // Was the query a "write" type? - // If so we'll return simply return true + // If so we'll simply return true if ($this->is_write_type($sql) === TRUE) { 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; + } // Instantiate and return the DB result object $result = 'CI_DB_'.$this->dbdriver.'_result'; @@ -241,6 +260,13 @@ class CI_DB_driver { $RES->conn_id = $this->conn_id; $RES->db_debug = $this->db_debug; $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; + } return $RES; } @@ -352,19 +378,16 @@ class CI_DB_driver { */ function escape($str) { - if ( ! is_numeric($str)) // bug fix to ensure that numbers are not treated as strings. - { - switch (gettype($str)) - { - case 'string' : $str = "'".$this->escape_str($str)."'"; - break; - case 'boolean' : $str = ($str === FALSE) ? 0 : 1; - break; - default : $str = ($str === NULL) ? 'NULL' : $str; - break; - } - } - + switch (gettype($str)) + { + case 'string' : $str = "'".$this->escape_str($str)."'"; + break; + case 'boolean' : $str = ($str === FALSE) ? 0 : 1; + break; + default : $str = ($str === NULL) ? 'NULL' : $str; + break; + } + return $str; } @@ -394,7 +417,14 @@ class CI_DB_driver { { foreach($query->result_array() as $row) { - $retval[] = array_shift($row); + if (isset($row['TABLE_NAME'])) + { + $retval[] = $row['TABLE_NAME']; + } + else + { + $retval[] = array_shift($row); + } } } @@ -447,7 +477,7 @@ class CI_DB_driver { $retval = array(); foreach($query->result_array() as $row) { - if ($this->dbdriver == 'mssql' AND isset($row['COLUMN_NAME'])) + if (isset($row['COLUMN_NAME'])) { $retval[] = $row['COLUMN_NAME']; } @@ -671,29 +701,6 @@ class CI_DB_driver { } - // -------------------------------------------------------------------- - - /** - * Field Data - old version - DEPRECATED - * - * @deprecated use $this->db->field_data() instead - */ - function fields($table = '') - { - return $this->field_data($table); - } - - // -------------------------------------------------------------------- - - /** - * Smart Escape String - old version - DEPRECATED - * - * @deprecated use $this->db->escape() instead - */ - function smart_escape_str($str) - { - return $this->escape($str); - } } @@ -926,24 +933,4 @@ class CI_DB_result { } - - -/** - * Database Field Class - * - * This class will contain the field meta-data. It - * is called by one of the field result functions - * - * @category Database - * @author Rick Ellis - * @link http://www.codeigniter.com/user_guide/libraries/database/ - */ -class CI_DB_field { - var $name; - var $type; - var $default; - var $max_length; - var $primary_key; -} - ?> \ No newline at end of file diff --git a/system/drivers/DB_mssql.php b/system/drivers/DB_mssql.php index f6e672b94..c84247641 100644 --- a/system/drivers/DB_mssql.php +++ b/system/drivers/DB_mssql.php @@ -424,7 +424,7 @@ class CI_DB_mssql_result extends CI_DB_result { $retval = array(); while ($field = mssql_fetch_field($this->result_id)) { - $F = new CI_DB_field(); + $F = new stdClass(); $F->name = $field->name; $F->type = $field->type; $F->max_length = $field->max_length; diff --git a/system/drivers/DB_mysql.php b/system/drivers/DB_mysql.php index a90d84268..72790976e 100644 --- a/system/drivers/DB_mysql.php +++ b/system/drivers/DB_mysql.php @@ -443,7 +443,7 @@ class CI_DB_mysql_result extends CI_DB_result { $retval = array(); while ($field = mysql_fetch_field($this->result_id)) { - $F = new CI_DB_field(); + $F = new stdClass(); $F->name = $field->name; $F->type = $field->type; $F->default = $field->def; diff --git a/system/drivers/DB_mysqli.php b/system/drivers/DB_mysqli.php index 49adb5cc3..d2a3140c2 100644 --- a/system/drivers/DB_mysqli.php +++ b/system/drivers/DB_mysqli.php @@ -451,7 +451,7 @@ class CI_DB_mysqli_result extends CI_DB_result { $retval = array(); while ($field = mysqli_fetch_field($this->result_id)) { - $F = new CI_DB_field(); + $F = new stdClass(); $F->name = $field->name; $F->type = $field->type; $F->default = $field->def; diff --git a/system/drivers/DB_odbc.php b/system/drivers/DB_odbc.php index a5a8db64d..57cdbced8 100644 --- a/system/drivers/DB_odbc.php +++ b/system/drivers/DB_odbc.php @@ -420,7 +420,7 @@ class CI_DB_odbc_result extends CI_DB_result { $retval = array(); for ($i = 0; $i < $this->num_fields(); $i++) { - $F = new CI_DB_field(); + $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); diff --git a/system/drivers/DB_postgre.php b/system/drivers/DB_postgre.php index aa7ec7020..57ef179d9 100644 --- a/system/drivers/DB_postgre.php +++ b/system/drivers/DB_postgre.php @@ -456,7 +456,7 @@ class CI_DB_postgre_result extends CI_DB_result { $retval = array(); for ($i = 0; $i < $this->num_fields(); $i++) { - $F = new CI_DB_field(); + $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); diff --git a/system/drivers/DB_sqlite.php b/system/drivers/DB_sqlite.php index 71d2561dc..48e2c8714 100644 --- a/system/drivers/DB_sqlite.php +++ b/system/drivers/DB_sqlite.php @@ -449,7 +449,7 @@ class CI_DB_sqlite_result extends CI_DB_result { $retval = array(); for ($i = 0; $i < $this->num_fields(); $i++) { - $F = new CI_DB_field(); + $F = new stdClass(); $F->name = sqlite_field_name($this->result_id, $i); $F->type = 'varchar'; $F->max_length = 0; diff --git a/system/libraries/Validation.php b/system/libraries/Validation.php index 227cf9f9a..065e7a2d5 100644 --- a/system/libraries/Validation.php +++ b/system/libraries/Validation.php @@ -246,8 +246,8 @@ class CI_Validation { { $rule = substr($rule, 9); $callback = TRUE; - } - + } + // Strip the parameter (if exists) from the rule // Rules can contain a parameter: max_length[5] $param = FALSE; @@ -265,13 +265,14 @@ class CI_Validation { continue; } - $result = $this->obj->$rule($_POST[$field], $param); + $result = $this->obj->$rule($_POST[$field], $param); - // If the field isn't requires we'll move on... - if ( ! in_array('required', $ex)) + // If the field isn't required and we just processed a callback we'll move on... + if ( ! in_array('required', $ex) AND $result !== FALSE) { - continue; + continue 2; } + } else { @@ -295,7 +296,7 @@ class CI_Validation { $result = $this->$rule($_POST[$field], $param); } - + // Did the rule test negatively? If so, grab the error. if ($result === FALSE) { @@ -323,8 +324,9 @@ class CI_Validation { // Add the error to the error array $this->_error_array[] = $message; continue 2; - } + } } + } $total_errors = count($this->_error_array); -- cgit v1.2.3-24-g4f1b From 0fce0f2fcf04db02a1633c155f9d6af3a95c5aa6 Mon Sep 17 00:00:00 2001 From: admin Date: Wed, 20 Sep 2006 21:13:41 +0000 Subject: --- system/drivers/DB_oci8.php | 696 +++++++++++++++++++++++++++++++++++++++++ system/libraries/Inflector.php | 160 ++++++++++ 2 files changed, 856 insertions(+) create mode 100644 system/drivers/DB_oci8.php create mode 100644 system/libraries/Inflector.php (limited to 'system') diff --git a/system/drivers/DB_oci8.php b/system/drivers/DB_oci8.php new file mode 100644 index 000000000..06426dcac --- /dev/null +++ b/system/drivers/DB_oci8.php @@ -0,0 +1,696 @@ +username, $this->password, $this->hostname); + } + + // -------------------------------------------------------------------- + + /** + * Persistent database connection + * + * @access private called by the base class + * @return resource + */ + function db_pconnect() + { + return ociplogon($this->username, $this->password, $this->hostname); + } + + // -------------------------------------------------------------------- + + /** + * Select the database + * + * @access private called by the base class + * @return resource + */ + function db_select() + { + return TRUE; + } + + // -------------------------------------------------------------------- + + /** + * Execute the query + * + * @access private called by the base class + * @param string an SQL query + * @return resource + */ + function execute($sql) + { + // oracle must parse the query before it + // is run, all of the actions with + // the query are based off the statement id + // returned by ociparse + $this->_set_stmt_id($sql); + ocisetprefetch($this->stmt_id, 1000); + return @ociexecute($this->stmt_id); + } + + /** + * Generate a statement ID + * + * @access private + * @param string an SQL query + * @return none + */ + function _set_stmt_id($sql) + { + if ( ! is_resource($this->stmt_id)) + { + $this->stmt_id = ociparse($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 + */ + function _prep_query($sql) + { + return $sql; + } + + // -------------------------------------------------------------------- + + /** + * getCursor. Returns a cursor from the datbase + * + * @access public + * @return cursor id + */ + function get_cursor() + { + return $this->curs_id = ocinewcursor($this->conn_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 + */ + 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 + */ + 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] = ''; + } + } + + ocibindbyname($this->stmt_id, $param['name'], $param['value'], $param['length'], $param['type']); + } + } + + // -------------------------------------------------------------------- + + /** + * Escape String + * + * @access public + * @param string + * @return string + */ + function escape_str($str) + { + return $str; + } + + // -------------------------------------------------------------------- + + /** + * Close DB Connection + * + * @access public + * @param resource + * @return void + */ + function destroy($conn_id) + { + ocilogoff($conn_id); + } + + // -------------------------------------------------------------------- + + /** + * Affected Rows + * + * @access public + * @return integer + */ + function affected_rows() + { + return @ocirowcount($this->stmt_id); + } + + // -------------------------------------------------------------------- + + /** + * Insert ID + * + * @access public + * @return integer + */ + function insert_id() + { + // not supported in oracle + return 0; + } + + // -------------------------------------------------------------------- + + /** + * "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("SELECT COUNT(1) AS numrows FROM ".$table); + + if ($query == FALSE) + { + return 0; + } + + $row = $query->row(); + return $row->NUMROWS; + } + + // -------------------------------------------------------------------- + + /** + * The error message string + * + * @access public + * @return string + */ + function error_message() + { + $error = ocierror($this->conn_id); + return $error['message']; + } + + // -------------------------------------------------------------------- + + /** + * The error message number + * + * @access public + * @return integer + */ + function error_number() + { + $error = ocierror($this->conn_id); + return $error['code']; + } + + // -------------------------------------------------------------------- + + /** + * 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 public + * @param string the table name + * @return string + */ + function escape_table($table) + { + if (stristr($table, '.')) + { + $table = preg_replace("/\./", "`.`", $table); + } + + return $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) + { + $sql = "SELECT * FROM ".$this->escape_table($table)." where rownum = 1"; + $query = $this->query($sql); + return $query->field_data(); + } + + // -------------------------------------------------------------------- + + /** + * 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 + * @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); + } + + // -------------------------------------------------------------------- + + /** + * Delete statement + * + * Generates a platform-specific delete string from the supplied data + * + * @access public + * @param string the table name + * @param array the where clause + * @return string + */ + function _delete($table, $where) + { + return "DELETE FROM ".$this->escape_table($table)." WHERE ".implode(" ", $where); + } + + // -------------------------------------------------------------------- + + /** + * Version number query string + * + * @access public + * @return string + */ + function _version() + { + $ver = ociserverversion($this->conn_id); + return $ver; + } + + // -------------------------------------------------------------------- + + /** + * Show table query + * + * Generates a platform-specific query string so that the table names can be fetched + * + * @access public + * @return string + */ + function _show_tables() + { + return "select TABLE_NAME FROM ALL_TABLES"; + } + + // -------------------------------------------------------------------- + + /** + * Show columnn 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 _show_columns($table = '') + { + return "SELECT COLUMN_NAME FROM all_tab_columns WHERE table_name = '$table'"; + } + + // -------------------------------------------------------------------- + + /** + * 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) + { + $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; + } + +} + + +/** + * oci8 Result Class + * + * This class extends the parent result class: CI_DB_result + * + * @category Database + * @author Rick Ellis + * @link http://www.codeigniter.com/user_guide/libraries/database/ + */ +class CI_DB_oci8_result extends CI_DB_result { + + var $stmt_id; + var $curs_id; + var $limit_used; + + /** + * Number of rows in the result set + * + * @access public + * @return integer + */ + function num_rows() + { + // get the results, count them, + // rerun query - otherwise we + // won't have data after calling + // num_rows() + $this->result_array(); + $rowcount = count($this->result_array); + @ociexecute($this->stmt_id); + if ($this->curs_id) + { + @ociexecute($this->curs_id); + } + return $rowcount; + } + + // -------------------------------------------------------------------- + + /** + * Number of fields in the result set + * + * @access public + * @return integer + */ + function num_fields() + { + $count = @ocinumcols($this->stmt_id); + + // if we used a limit, we added a field, + // subtract it out + if ($this->limit_used) + { + $count = $count - 1; + } + + return $count; + } + + // -------------------------------------------------------------------- + + /** + * Field data + * + * Generates an array of objects containing field meta-data + * + * @access public + * @return array + */ + function field_data() + { + $retval = array(); + $fieldCount = $this->num_fields(); + for ($c = 1; $c <= $fieldCount; $c++) + { + $F = new stdClass(); + $F->name = ocicolumnname($this->stmt_id, $c); + $F->type = ocicolumntype($this->stmt_id, $c); + $F->max_length = ocicolumnsize($this->stmt_id, $c); + + $retval[] = $F; + } + + return $retval; + } + + // -------------------------------------------------------------------- + + /** + * Result - associative array + * + * Returns the result set as an array + * + * @access private + * @return array + */ + function _fetch_assoc(&$row) + { + // if pulling from a cursor, use curs_id + if ($this->curs_id) + { + return ocifetchinto($this->curs_id, $row, OCI_ASSOC + OCI_RETURN_NULLS); + } + else + { + return ocifetchinto($this->stmt_id, $row, OCI_ASSOC + OCI_RETURN_NULLS); + } + } + + // -------------------------------------------------------------------- + + /** + * Result - object + * + * Returns the result set as an object + * + * @access private + * @return object + */ + function _fetch_object() + { + // the PHP 4 version of the oracle functions do not + // have a fetch method so we call the array version + // and build an object from that + + $row = array(); + $res = $this->_fetch_assoc($row); + if ($res != FALSE) + { + $obj = new stdClass(); + foreach ($row as $key => $value) + { + $obj->{$key} = $value; + } + + $res = $obj; + } + return $res; + } + + /** + * Query result. "array" version. + * + * @access public + * @return array + */ + function result_array() + { + if (count($this->result_array) > 0) + { + return $this->result_array; + } + + // oracle's fetch functions do not + // return arrays, the information + // is returned in reference parameters + // + $row = NULL; + while ($this->_fetch_assoc($row)) + { + $this->result_array[] = $row; + } + + if (count($this->result_array) == 0) + { + return FALSE; + } + + return $this->result_array; + } + +} + +?> \ No newline at end of file diff --git a/system/libraries/Inflector.php b/system/libraries/Inflector.php new file mode 100644 index 000000000..b27228a54 --- /dev/null +++ b/system/libraries/Inflector.php @@ -0,0 +1,160 @@ + \ No newline at end of file -- cgit v1.2.3-24-g4f1b From 5b179b55d389282e5097451e6b6a707baee0522c Mon Sep 17 00:00:00 2001 From: admin Date: Wed, 20 Sep 2006 23:44:53 +0000 Subject: --- system/helpers/inflector_helper.php | 140 ++++++++++++++++++++++++++++++++++++ 1 file changed, 140 insertions(+) create mode 100644 system/helpers/inflector_helper.php (limited to 'system') diff --git a/system/helpers/inflector_helper.php b/system/helpers/inflector_helper.php new file mode 100644 index 000000000..3bded708e --- /dev/null +++ b/system/helpers/inflector_helper.php @@ -0,0 +1,140 @@ + \ No newline at end of file -- cgit v1.2.3-24-g4f1b From 1610a26f1530869541dd70036243c89b343e0e1e Mon Sep 17 00:00:00 2001 From: admin Date: Wed, 20 Sep 2006 23:45:05 +0000 Subject: --- system/application/errors/error_php.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system') diff --git a/system/application/errors/error_php.php b/system/application/errors/error_php.php index 2fb3f2b2e..9bba5b8cb 100644 --- a/system/application/errors/error_php.php +++ b/system/application/errors/error_php.php @@ -1,4 +1,4 @@ -
+

A PHP Error was encountered

-- cgit v1.2.3-24-g4f1b From f9e890c755a414496930a3a6ff37ad75815e8a48 Mon Sep 17 00:00:00 2001 From: admin Date: Wed, 20 Sep 2006 23:59:14 +0000 Subject: --- system/libraries/Inflector.php | 160 ----------------------------------------- 1 file changed, 160 deletions(-) delete mode 100644 system/libraries/Inflector.php (limited to 'system') diff --git a/system/libraries/Inflector.php b/system/libraries/Inflector.php deleted file mode 100644 index b27228a54..000000000 --- a/system/libraries/Inflector.php +++ /dev/null @@ -1,160 +0,0 @@ - \ No newline at end of file -- cgit v1.2.3-24-g4f1b From d16d6c2055f119a4df9812548ed13449f6c806f9 Mon Sep 17 00:00:00 2001 From: admin Date: Thu, 21 Sep 2006 00:45:12 +0000 Subject: --- system/libraries/Email.php | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) (limited to 'system') diff --git a/system/libraries/Email.php b/system/libraries/Email.php index abc77a54d..5b991d1fa 100644 --- a/system/libraries/Email.php +++ b/system/libraries/Email.php @@ -130,7 +130,7 @@ class CI_Email { * @access public * @return void */ - function clear() + function clear($clear_attachments = FALSE) { $this->_subject = ""; $this->_body = ""; @@ -143,6 +143,13 @@ class CI_Email { $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(); + } } // END clear() @@ -735,6 +742,11 @@ class CI_Email { */ function _get_alt_message() { + if ($this->alt_message != "") + { + return $this->word_wrap($this->alt_message, '76'); + } + if (eregi( '\', $this->_body, $match)) { $body = $match['1']; -- cgit v1.2.3-24-g4f1b From 460f2678d1ba46f231466232cf1352353d62d598 Mon Sep 17 00:00:00 2001 From: admin Date: Thu, 21 Sep 2006 02:41:37 +0000 Subject: --- system/libraries/Output.php | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) (limited to 'system') diff --git a/system/libraries/Output.php b/system/libraries/Output.php index fd07a9f6e..b09bf2a53 100644 --- a/system/libraries/Output.php +++ b/system/libraries/Output.php @@ -30,6 +30,7 @@ class CI_Output { var $final_output; var $cache_expiration = 0; + var $headers = array(); function CI_Output() { @@ -66,6 +67,26 @@ class CI_Output { { $this->final_output = $output; } + + // -------------------------------------------------------------------- + + /** + * 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 + * @return void + */ + function set_header($header) + { + $this->headers[] = $header; + } + // -------------------------------------------------------------------- @@ -110,17 +131,30 @@ class CI_Output { $output =& $this->final_output; } + // Do we need to write a cache file? if ($this->cache_expiration > 0) { $this->_write_cache($output); } + // Parse out the elapsed time and memory usage, and + // swap the pseudo-variables with the data $elapsed = $BM->elapsed_time('code_igniter_start', 'code_igniter_end'); $memory = ( ! function_exists('memory_get_usage')) ? '0' : round(memory_get_usage()/1024/1024, 2).'MB'; $output = str_replace('{memory_usage}', $memory, $output); $output = str_replace('{elapsed_time}', $elapsed, $output); + // Are there any server headers to send? + if (count($this->headers) > 0) + { + foreach ($this->headers as $header) + { + @header($header); + } + } + + // Send it to the browser! echo $output; log_message('debug', "Final output sent to browser"); -- cgit v1.2.3-24-g4f1b From bc042dd0692a6b4b89f11f88e6e3763162ce8048 Mon Sep 17 00:00:00 2001 From: admin Date: Thu, 21 Sep 2006 02:46:59 +0000 Subject: --- system/codeigniter/Common.php | 15 ++++++++++----- system/helpers/text_helper.php | 2 +- system/libraries/Exceptions.php | 2 +- system/libraries/Input.php | 2 +- 4 files changed, 13 insertions(+), 8 deletions(-) (limited to 'system') diff --git a/system/codeigniter/Common.php b/system/codeigniter/Common.php index a4531a7d0..885cca2f5 100644 --- a/system/codeigniter/Common.php +++ b/system/codeigniter/Common.php @@ -79,10 +79,15 @@ function &_load_class($class, $instantiate = TRUE) */ function &_get_config() { - static $conf; - - if ( ! isset($conf)) + static $main_conf; + + if ( ! isset($main_conf)) { + if ( ! file_exists(APPPATH.'config/config'.EXT)) + { + show_error('The configuration file config'.EXT.' does not exist.'); + } + require(APPPATH.'config/config'.EXT); if ( ! isset($config) OR ! is_array($config)) @@ -90,9 +95,9 @@ function &_get_config() show_error('Your config file does not appear to be formatted correctly.'); } - $conf[0] =& $config; + $main_conf[0] =& $config; } - return $conf[0]; + return $main_conf[0]; } diff --git a/system/helpers/text_helper.php b/system/helpers/text_helper.php index e4f816eb1..e2da32746 100644 --- a/system/helpers/text_helper.php +++ b/system/helpers/text_helper.php @@ -266,7 +266,7 @@ function highlight_code($str) // or B) whether the PHP tags enclose the entire string, we will add our // own PHP tags around the string along with some markers to make replacement easier later - $str = ''; // '; // All the magic happens here, baby! $str = highlight_string($str, TRUE); diff --git a/system/libraries/Exceptions.php b/system/libraries/Exceptions.php index a72dbf841..c3af801ae 100644 --- a/system/libraries/Exceptions.php +++ b/system/libraries/Exceptions.php @@ -53,7 +53,7 @@ class CI_Exceptions { */ function CI_Exceptions() { - log_message('debug', "Output Class Initialized"); + // Note: Do not log messages from this constructor. } // END CI_Exceptions() diff --git a/system/libraries/Input.php b/system/libraries/Input.php index 6aba5dd43..dbf939b18 100644 --- a/system/libraries/Input.php +++ b/system/libraries/Input.php @@ -430,7 +430,7 @@ class CI_Input { * But it doesn't seem to pose a problem. * */ - $str = str_replace(array(''), array('<?php', '<?PHP', '<?', '?>'), $str); // '), array('<?php', '<?PHP', '<?', '?>'), $str); /* * Compact any exploded words -- cgit v1.2.3-24-g4f1b From 03152efb757866c6a2aac6ecfbeb551444f7af78 Mon Sep 17 00:00:00 2001 From: admin Date: Thu, 21 Sep 2006 04:09:28 +0000 Subject: --- system/drivers/DB_mysqli.php | 6 ------ 1 file changed, 6 deletions(-) (limited to 'system') diff --git a/system/drivers/DB_mysqli.php b/system/drivers/DB_mysqli.php index d2a3140c2..4b9685799 100644 --- a/system/drivers/DB_mysqli.php +++ b/system/drivers/DB_mysqli.php @@ -89,12 +89,6 @@ class CI_DB_mysqli extends CI_DB { { $sql = $this->_prep_query($sql); $result = @mysqli_query($this->conn_id, $sql); - - // We only advance the result pointer if there isn't an error - if (mysqli_errno($this->conn_id) == 0) - { - mysqli_next_result($this->conn_id); - } return $result; } -- cgit v1.2.3-24-g4f1b From 9aaa75ed7cd7b2a95cff5b8a52a59c1e6dcf9da6 Mon Sep 17 00:00:00 2001 From: admin Date: Thu, 21 Sep 2006 04:45:20 +0000 Subject: --- system/application/config/config.php | 22 +++++++++++++++++++--- system/libraries/Output.php | 14 +++++++++++++- 2 files changed, 32 insertions(+), 4 deletions(-) (limited to 'system') diff --git a/system/application/config/config.php b/system/application/config/config.php index 7b19b83b5..e88abd9f9 100644 --- a/system/application/config/config.php +++ b/system/application/config/config.php @@ -204,7 +204,6 @@ $config['log_date_format'] = 'Y-m-d H:i:s'; */ $config['cache_path'] = ''; - /* |-------------------------------------------------------------------------- | Encryption Key @@ -216,7 +215,6 @@ $config['cache_path'] = ''; */ $config['encryption_key'] = ""; - /* |-------------------------------------------------------------------------- | Session Variables @@ -236,7 +234,6 @@ $config['sess_table_name'] = ''; $config['sess_match_ip'] = TRUE; $config['sess_match_useragent'] = TRUE; - /* |-------------------------------------------------------------------------- | Cookie Related Variables @@ -262,5 +259,24 @@ $config['cookie_path'] = "/"; */ $config['global_xss_filtering'] = FALSE; +/* +|-------------------------------------------------------------------------- +| Output Compression +|-------------------------------------------------------------------------- +| +| Enables output compression using Gzip for faster page loads. When enabled, +| the output class will test whether the server your site is running on +| supports Gzip. Even if it does, however, not all browsers support compression +| so enable only if you are reasonably sure your visitors can handle it. +| +| VERY IMPORTANT: If you are getting a blank page when this is enabled it +| means you are prematurely outputing something to your browser. It could +| even be a line of whitespace at the end of one of your scripts. For +| compression to work, nothing can be sent before the output buffer is called +| by the output class. +| +*/ +$config['compress_output'] = TRUE; + ?> \ No newline at end of file diff --git a/system/libraries/Output.php b/system/libraries/Output.php index b09bf2a53..4a3adb858 100644 --- a/system/libraries/Output.php +++ b/system/libraries/Output.php @@ -86,7 +86,6 @@ class CI_Output { { $this->headers[] = $header; } - // -------------------------------------------------------------------- @@ -145,6 +144,19 @@ class CI_Output { $output = str_replace('{memory_usage}', $memory, $output); $output = str_replace('{elapsed_time}', $elapsed, $output); + // Is compression requested? + $CFG =& _load_class('CI_Config'); + if ($CFG->item('compress_output') === TRUE) + { + 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) { -- cgit v1.2.3-24-g4f1b From cfc1fb38f0d7cd49c735730a603f7ca5a98a664d Mon Sep 17 00:00:00 2001 From: admin Date: Thu, 21 Sep 2006 04:47:01 +0000 Subject: Adding deutsch folder --- system/language/deutsch/calendar_lang.php | 49 ++++++++++++++++++++++++++++ system/language/deutsch/date_lang.php | 49 ++++++++++++++++++++++++++++ system/language/deutsch/db_lang.php | 15 +++++++++ system/language/deutsch/email_lang.php | 21 ++++++++++++ system/language/deutsch/imglib_lang.php | 21 ++++++++++++ system/language/deutsch/index.html | 15 +++++++++ system/language/deutsch/scaffolding_lang.php | 15 +++++++++ system/language/deutsch/unit_test_lang.php | 22 +++++++++++++ system/language/deutsch/upload_lang.php | 16 +++++++++ system/language/deutsch/valldation_lang.php | 15 +++++++++ 10 files changed, 238 insertions(+) create mode 100644 system/language/deutsch/calendar_lang.php create mode 100644 system/language/deutsch/date_lang.php create mode 100644 system/language/deutsch/db_lang.php create mode 100644 system/language/deutsch/email_lang.php create mode 100644 system/language/deutsch/imglib_lang.php create mode 100644 system/language/deutsch/index.html create mode 100644 system/language/deutsch/scaffolding_lang.php create mode 100644 system/language/deutsch/unit_test_lang.php create mode 100644 system/language/deutsch/upload_lang.php create mode 100644 system/language/deutsch/valldation_lang.php (limited to 'system') diff --git a/system/language/deutsch/calendar_lang.php b/system/language/deutsch/calendar_lang.php new file mode 100644 index 000000000..73ed0c4f6 --- /dev/null +++ b/system/language/deutsch/calendar_lang.php @@ -0,0 +1,49 @@ + \ No newline at end of file diff --git a/system/language/deutsch/date_lang.php b/system/language/deutsch/date_lang.php new file mode 100644 index 000000000..28c1acffe --- /dev/null +++ b/system/language/deutsch/date_lang.php @@ -0,0 +1,49 @@ + \ No newline at end of file diff --git a/system/language/deutsch/db_lang.php b/system/language/deutsch/db_lang.php new file mode 100644 index 000000000..0e4905014 --- /dev/null +++ b/system/language/deutsch/db_lang.php @@ -0,0 +1,15 @@ + \ No newline at end of file diff --git a/system/language/deutsch/email_lang.php b/system/language/deutsch/email_lang.php new file mode 100644 index 000000000..a93befc72 --- /dev/null +++ b/system/language/deutsch/email_lang.php @@ -0,0 +1,21 @@ + \ No newline at end of file diff --git a/system/language/deutsch/imglib_lang.php b/system/language/deutsch/imglib_lang.php new file mode 100644 index 000000000..a9303ab6f --- /dev/null +++ b/system/language/deutsch/imglib_lang.php @@ -0,0 +1,21 @@ + \ No newline at end of file diff --git a/system/language/deutsch/index.html b/system/language/deutsch/index.html new file mode 100644 index 000000000..5a1f5d6ae --- /dev/null +++ b/system/language/deutsch/index.html @@ -0,0 +1,15 @@ + + + + +403 Forbidden + + + + + +

Directory access is forbidden.

+ + + + \ No newline at end of file diff --git a/system/language/deutsch/scaffolding_lang.php b/system/language/deutsch/scaffolding_lang.php new file mode 100644 index 000000000..ab2e62957 --- /dev/null +++ b/system/language/deutsch/scaffolding_lang.php @@ -0,0 +1,15 @@ + \ No newline at end of file diff --git a/system/language/deutsch/unit_test_lang.php b/system/language/deutsch/unit_test_lang.php new file mode 100644 index 000000000..5728bf567 --- /dev/null +++ b/system/language/deutsch/unit_test_lang.php @@ -0,0 +1,22 @@ + \ No newline at end of file diff --git a/system/language/deutsch/upload_lang.php b/system/language/deutsch/upload_lang.php new file mode 100644 index 000000000..57583ad07 --- /dev/null +++ b/system/language/deutsch/upload_lang.php @@ -0,0 +1,16 @@ + \ No newline at end of file diff --git a/system/language/deutsch/valldation_lang.php b/system/language/deutsch/valldation_lang.php new file mode 100644 index 000000000..688af05de --- /dev/null +++ b/system/language/deutsch/valldation_lang.php @@ -0,0 +1,15 @@ + \ No newline at end of file -- cgit v1.2.3-24-g4f1b From 885b0343036695ad673fc24ba7682fc155c54036 Mon Sep 17 00:00:00 2001 From: admin Date: Thu, 21 Sep 2006 05:36:15 +0000 Subject: --- system/drivers/DB_active_record.php | 2 +- system/helpers/cookie_helper.php | 49 +++++++++++++++++++++++++++++++++++++ system/libraries/Validation.php | 2 +- 3 files changed, 51 insertions(+), 2 deletions(-) (limited to 'system') diff --git a/system/drivers/DB_active_record.php b/system/drivers/DB_active_record.php index c7e4f096c..af12d9d27 100644 --- a/system/drivers/DB_active_record.php +++ b/system/drivers/DB_active_record.php @@ -390,7 +390,7 @@ class CI_DB_active_record extends CI_DB_driver { { if (trim($direction) != '') { - $direction = (in_array(strtoupper(trim($direction)), array('ASC', 'DESC'))) ? ' '.$direction : ' ASC'; + $direction = (in_array(strtoupper(trim($direction)), array('ASC', 'DESC', 'RAND()'))) ? ' '.$direction : ' ASC'; } $this->ar_orderby[] = $orderby.$direction; diff --git a/system/helpers/cookie_helper.php b/system/helpers/cookie_helper.php index 24e243ddd..fc5920f25 100644 --- a/system/helpers/cookie_helper.php +++ b/system/helpers/cookie_helper.php @@ -55,6 +55,22 @@ function set_cookie($name = '', $value = '', $expire = '', $domain = '', $path = } } + // Set the config file options + $obj =& get_instance(); + + if ($prefix == '' AND $obj->config->item('cookie_prefix') != '') + { + $obj->config->item('cookie_prefix'); + } + if ($domain == '' AND $obj->config->item('cookie_domain') != '') + { + $obj->config->item('cookie_domain'); + } + if ($prefix == '/' AND $obj->config->item('cookie_path') != '/') + { + $obj->config->item('cookie_path'); + } + if ( ! is_numeric($expire)) { $expire = time() - 86500; @@ -73,5 +89,38 @@ function set_cookie($name = '', $value = '', $expire = '', $domain = '', $path = setcookie($prefix.$name, $value, $expire, $path, $domain, 0); } + +// -------------------------------------------------------------------- + +/** + * Fetch an item from the COOKIE array + * + * @access public + * @param string + * @param bool + * @return mixed + */ +function get_cookie($index = '', $xss_clean = FALSE) +{ + $obj =& get_instance(); + return $obj->input->cookie($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 + */ +function delete_cookie($name = '', $domain = '', $path = '/', $prefix = '') +{ + set_cookie($name, '', '', $domain, $path, $prefix); +} + ?> \ No newline at end of file diff --git a/system/libraries/Validation.php b/system/libraries/Validation.php index 065e7a2d5..f9b51d778 100644 --- a/system/libraries/Validation.php +++ b/system/libraries/Validation.php @@ -524,7 +524,7 @@ class CI_Validation { */ function numeric($str) { - return ( ! is_numeric($str)) ? FALSE : TRUE; + return ( ! ereg("^[0-9]+$", $str)) ? FALSE : TRUE; } // -------------------------------------------------------------------- -- cgit v1.2.3-24-g4f1b From 0d9c2087818d82798b7f9c65a1226317a7cc6d68 Mon Sep 17 00:00:00 2001 From: admin Date: Thu, 21 Sep 2006 06:20:32 +0000 Subject: Adding hooks folder --- system/application/hooks/index.html | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 system/application/hooks/index.html (limited to 'system') diff --git a/system/application/hooks/index.html b/system/application/hooks/index.html new file mode 100644 index 000000000..5a1f5d6ae --- /dev/null +++ b/system/application/hooks/index.html @@ -0,0 +1,15 @@ + + + + +403 Forbidden + + + + + +

Directory access is forbidden.

+ + + + \ No newline at end of file -- cgit v1.2.3-24-g4f1b From d70d8293bb086a3db104e886f8ad37aea871d024 Mon Sep 17 00:00:00 2001 From: admin Date: Thu, 21 Sep 2006 06:20:58 +0000 Subject: Adding libraries folder --- system/application/libraries/index.html | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 system/application/libraries/index.html (limited to 'system') diff --git a/system/application/libraries/index.html b/system/application/libraries/index.html new file mode 100644 index 000000000..5a1f5d6ae --- /dev/null +++ b/system/application/libraries/index.html @@ -0,0 +1,15 @@ + + + + +403 Forbidden + + + + + +

Directory access is forbidden.

+ + + + \ No newline at end of file -- cgit v1.2.3-24-g4f1b From 1a3ffb457fc1f0fc248d8178b228e9a2c8569445 Mon Sep 17 00:00:00 2001 From: admin Date: Thu, 21 Sep 2006 06:21:22 +0000 Subject: Adding init folder --- system/application/init/index.html | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 system/application/init/index.html (limited to 'system') diff --git a/system/application/init/index.html b/system/application/init/index.html new file mode 100644 index 000000000..5a1f5d6ae --- /dev/null +++ b/system/application/init/index.html @@ -0,0 +1,15 @@ + + + + +403 Forbidden + + + + + +

Directory access is forbidden.

+ + + + \ No newline at end of file -- cgit v1.2.3-24-g4f1b From d48ef1c8e2e84067a58818291935593d70e491f8 Mon Sep 17 00:00:00 2001 From: admin Date: Thu, 21 Sep 2006 06:22:05 +0000 Subject: --- system/application/config/autoload.php | 27 ++++++++++++++++++--------- system/libraries/Controller.php | 12 ++++++++---- 2 files changed, 26 insertions(+), 13 deletions(-) (limited to 'system') diff --git a/system/application/config/autoload.php b/system/application/config/autoload.php index 1ed6f1757..4efe3be41 100644 --- a/system/application/config/autoload.php +++ b/system/application/config/autoload.php @@ -10,8 +10,7 @@ | the database is not connected to automatically since no assumption | is made regarding whether you intend to use it. This file lets | you globally define which systems you would like loaded with every -| request. In addition to core systems you can auto-load plugins, -| helper files, config files, and your own scripts. +| request. | | ------------------------------------------------------------------- | Instructions @@ -19,27 +18,27 @@ | | These are the things you can load automatically: | -| 1. Core classes +| 1. Libraries | 2. Helper files | 3. Plugins | 4. Scripts | 5. Custom config files | -| Note: The items will be loaded in the order that they are defined -| -| Please read the user guide for more detailed information */ /* | ------------------------------------------------------------------- -| Auto-load Core Classes +| Auto-load Libraries | ------------------------------------------------------------------- +| These are the classes located in the system/libraries folder +| or in your system/application/libraries folder. +| | Prototype: | -| $autoload['core'] = array('database', 'session', 'xmlrpc'); +| $autoload['libraries'] = array('database', 'session', 'xmlrpc'); */ -$autoload['core'] = array(); +$autoload['libraries'] = array(); /* @@ -97,5 +96,15 @@ $autoload['script'] = array(); $autoload['config'] = array(); +/* +| ------------------------------------------------------------------- +| Auto-load Core Libraries +| ------------------------------------------------------------------- +| +| DEPRECATED: Use $autoload $autoload['libraries'] instead. +| +*/ +// $autoload['core'] = array(); + ?> \ No newline at end of file diff --git a/system/libraries/Controller.php b/system/libraries/Controller.php index 768b154e8..5a32e65c0 100644 --- a/system/libraries/Controller.php +++ b/system/libraries/Controller.php @@ -232,16 +232,20 @@ class Controller extends CI_Base { } unset($autoload['config']); - if ( ! is_array($autoload['core'])) + // A little tweak to remain backward compatible + // The $autoload['core'] item was deprecated + if ( ! isset($autoload['libraries'])) { - $autoload['core'] = array($autoload['core']); + $autoload['libraries'] = $autoload['core']; + } - foreach ($autoload['core'] as $item) + foreach ($autoload['libraries'] as $item) { $this->_ci_initialize($item); } - + unset($autoload['libraries']); + return $autoload; } // END _ci_autoload() -- cgit v1.2.3-24-g4f1b From bc4fffbc55d7d04a98a50f1aefa414f965d90644 Mon Sep 17 00:00:00 2001 From: admin Date: Thu, 21 Sep 2006 15:30:56 +0000 Subject: --- system/libraries/Upload.php | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) (limited to 'system') diff --git a/system/libraries/Upload.php b/system/libraries/Upload.php index 6d12dbcd7..98edd654f 100644 --- a/system/libraries/Upload.php +++ b/system/libraries/Upload.php @@ -98,10 +98,10 @@ class CI_Upload { * @access public * @return bool */ - function do_upload() + function do_upload($field = 'userfile') { - // Is $_FILES['userfile'] set? If not, no reason to continue. - if ( ! isset($_FILES['userfile'])) + // Is $_FILES[$field] set? If not, no reason to continue. + if ( ! isset($_FILES[$field])) { $this->set_error('upload_userfile_not_set'); return FALSE; @@ -114,9 +114,9 @@ class CI_Upload { } // Was the file able to be uploaded? If not, determine the reason why. - if ( ! is_uploaded_file($_FILES['userfile']['tmp_name'])) + if ( ! is_uploaded_file($_FILES[$field]['tmp_name'])) { - $error = ( ! isset($_FILES['userfile']['error'])) ? 4 : $_FILES['userfile']['error']; + $error = ( ! isset($_FILES[$field]['error'])) ? 4 : $_FILES[$field]['error']; switch($error) { @@ -134,12 +134,12 @@ class CI_Upload { } // Set the uploaded data as class variables - $this->file_temp = $_FILES['userfile']['tmp_name']; - $this->file_name = $_FILES['userfile']['name']; - $this->file_size = $_FILES['userfile']['size']; - $this->file_type = preg_replace("/^(.+?);.*$/", "\\1", $_FILES['userfile']['type']); + $this->file_temp = $_FILES[$field]['tmp_name']; + $this->file_name = $_FILES[$field]['name']; + $this->file_size = $_FILES[$field]['size']; + $this->file_type = preg_replace("/^(.+?);.*$/", "\\1", $_FILES[$field]['type']); $this->file_type = strtolower($this->file_type); - $this->file_ext = $this->get_extension($_FILES['userfile']['name']); + $this->file_ext = $this->get_extension($_FILES[$field]['name']); // Convert the file size to kilobytes if ($this->file_size > 0) -- cgit v1.2.3-24-g4f1b From daf454dabe983f621570bcef10d6d8babedfb8a8 Mon Sep 17 00:00:00 2001 From: admin Date: Thu, 21 Sep 2006 17:01:27 +0000 Subject: --- system/libraries/URI.php | 93 ++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 91 insertions(+), 2 deletions(-) (limited to 'system') diff --git a/system/libraries/URI.php b/system/libraries/URI.php index ba6279e88..11562eb29 100644 --- a/system/libraries/URI.php +++ b/system/libraries/URI.php @@ -65,6 +65,25 @@ class CI_URI { // -------------------------------------------------------------------- + /** + * Fetch a URI "routed" Segment + * + * This function returns the re-routed URI segment (assuming routing rules are used) + * based on the number provided. If there is no routing this function returns the + * same result as $this->segment() + * + * @access public + * @param integer + * @param bool + * @return string + */ + function rsegment($n, $no_result = FALSE) + { + return ( ! isset($this->router->rsegments[$n])) ? $no_result : $this->router->rsegments[$n]; + } + + // -------------------------------------------------------------------- + /** * Generate a key value pair from the URI string * @@ -168,7 +187,6 @@ class CI_URI { return implode('/', $temp); } - // -------------------------------------------------------------------- /** @@ -180,6 +198,37 @@ class CI_URI { * @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') { if ($where == 'trailing') { @@ -196,7 +245,7 @@ class CI_URI { $leading = '/'; $trailing = '/'; } - return ( ! isset($this->router->segments[$n])) ? '' : $leading.$this->router->segments[$n].$trailing; + return ( ! isset($this->router->$which[$n])) ? '' : $leading.$this->router->$which[$n].$trailing; } // -------------------------------------------------------------------- @@ -211,6 +260,19 @@ class CI_URI { { return $this->router->segments; } + + // -------------------------------------------------------------------- + + /** + * Routed Segment Array + * + * @access public + * @return array + */ + function rsegment_array() + { + return $this->router->rsegments; + } // -------------------------------------------------------------------- @@ -224,6 +286,19 @@ class CI_URI { { return count($this->router->segments); } + + // -------------------------------------------------------------------- + + /** + * Total number of routed segments + * + * @access public + * @return integer + */ + function total_rsegments() + { + return count($this->router->rsegments); + } // -------------------------------------------------------------------- @@ -238,6 +313,20 @@ class CI_URI { return $this->router->uri_string; } + + // -------------------------------------------------------------------- + + /** + * Fetch the entire Re-routed URI string + * + * @access public + * @return string + */ + function uri_rstring() + { + return '/'.implode('/', $this->rsegment_array()).'/'; + } + } // END URI Class ?> \ No newline at end of file -- cgit v1.2.3-24-g4f1b From 99bccd6aea613901d7eaf74f141f78342e2ec333 Mon Sep 17 00:00:00 2001 From: admin Date: Thu, 21 Sep 2006 17:05:40 +0000 Subject: --- system/libraries/Router.php | 55 +++++++++++++++++++++++++++++++++++++++------ 1 file changed, 48 insertions(+), 7 deletions(-) (limited to 'system') diff --git a/system/libraries/Router.php b/system/libraries/Router.php index 1dd1e5426..868fd909e 100644 --- a/system/libraries/Router.php +++ b/system/libraries/Router.php @@ -31,6 +31,7 @@ class CI_Router { var $config; var $uri_string = ''; var $segments = array(); + var $rsegments = array(); var $routes = array(); var $class = ''; var $method = 'index'; @@ -78,7 +79,7 @@ class CI_Router { } // Load the routes.php file - include_once(APPPATH.'config/routes'.EXT); + @include_once(APPPATH.'config/routes'.EXT); $this->routes = ( ! isset($route) OR ! is_array($route)) ? array() : $route; unset($route); @@ -151,12 +152,7 @@ class CI_Router { $this->_parse_routes(); // Re-index the segment array so that it starts with 1 rather than 0 - $i = 1; - foreach ($this->segments as $val) - { - $this->segments[$i++] = $val; - } - unset($this->segments['0']); + $this->_reindex_segments(); } // END _set_route_mapping() @@ -199,6 +195,11 @@ class CI_Router { $this->set_method($segments['1']); } } + + // Update our "routed" segment array to contain the segments. + // Note: If there is no custom routing, this array will be + // identical to $this->segments + $this->rsegments = $segments; } // END _compile_segments() @@ -256,6 +257,46 @@ class CI_Router { show_404(); } // END _validate_segments() + + // -------------------------------------------------------------------- + /** + * Re-index Segments + * + * This function re-indexes the $this->segment array so that it + * starts at 1 rather then 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() + { + // Is the routed segment array different then the main segment array? + $diff = (count(array_diff($this->rsegments, $this->segments)) == 0) ? FALSE : TRUE; + + $i = 1; + foreach ($this->segments as $val) + { + $this->segments[$i++] = $val; + } + unset($this->segments['0']); + + if ($diff == FALSE) + { + $this->rsegments = $this->segments; + } + else + { + $i = 1; + foreach ($this->rsegments as $val) + { + $this->rsegments[$i++] = $val; + } + unset($this->rsegments['0']); + } + } + // END _reindex_segments() // -------------------------------------------------------------------- -- cgit v1.2.3-24-g4f1b From a4d35347327c1e9a464696d153ad6f2ec4510283 Mon Sep 17 00:00:00 2001 From: admin Date: Thu, 21 Sep 2006 17:21:57 +0000 Subject: --- system/application/config/config.php | 4 ++-- system/application/config/routes.php | 2 -- system/codeigniter/CodeIgniter.php | 6 ++++-- 3 files changed, 6 insertions(+), 6 deletions(-) (limited to 'system') diff --git a/system/application/config/config.php b/system/application/config/config.php index e88abd9f9..eba2ec271 100644 --- a/system/application/config/config.php +++ b/system/application/config/config.php @@ -273,10 +273,10 @@ $config['global_xss_filtering'] = FALSE; | means you are prematurely outputing something to your browser. It could | even be a line of whitespace at the end of one of your scripts. For | compression to work, nothing can be sent before the output buffer is called -| by the output class. +| by the output class. Do not "echo" any values with compression enabled. | */ -$config['compress_output'] = TRUE; +$config['compress_output'] = FALSE; ?> \ No newline at end of file diff --git a/system/application/config/routes.php b/system/application/config/routes.php index b86cf9182..473704c6d 100644 --- a/system/application/config/routes.php +++ b/system/application/config/routes.php @@ -45,6 +45,4 @@ $route['scaffolding_trigger'] = ""; // Define your own routes below ------------------------------------------- - - ?> \ No newline at end of file diff --git a/system/codeigniter/CodeIgniter.php b/system/codeigniter/CodeIgniter.php index 5146c807d..de1e91095 100644 --- a/system/codeigniter/CodeIgniter.php +++ b/system/codeigniter/CodeIgniter.php @@ -196,8 +196,10 @@ else { show_404(); } - - $CI->$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($RTR->rsegments, 2)); } } -- cgit v1.2.3-24-g4f1b From 05633d7348b85147a46a7396c3bee1928335fa7a Mon Sep 17 00:00:00 2001 From: admin Date: Thu, 21 Sep 2006 17:22:21 +0000 Subject: --- system/libraries/Parser.php | 2 +- system/libraries/URI.php | 41 ++++++++++++++++++++++++++++++++++++++--- 2 files changed, 39 insertions(+), 4 deletions(-) (limited to 'system') diff --git a/system/libraries/Parser.php b/system/libraries/Parser.php index 9f6a814ae..b07b64fdd 100644 --- a/system/libraries/Parser.php +++ b/system/libraries/Parser.php @@ -47,7 +47,7 @@ class CI_Parser { $OUT =& _load_class('CI_Output'); $obj =& get_instance(); - $template = $obj->load->view($template, '', TRUE); + $template = $obj->load->view($template, $data, TRUE); if ($template == '') { diff --git a/system/libraries/URI.php b/system/libraries/URI.php index 11562eb29..e831d9526 100644 --- a/system/libraries/URI.php +++ b/system/libraries/URI.php @@ -107,6 +107,41 @@ class CI_URI { */ 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 + * + */ + 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; @@ -117,7 +152,7 @@ class CI_URI { return $this->keyval[$n]; } - if ($this->total_segments() < $n) + if ($this->$total_segments() < $n) { if (count($default) == 0) { @@ -132,7 +167,7 @@ class CI_URI { return $retval; } - $segments = array_slice($this->segment_array(), ($n - 1)); + $segments = array_slice($this->$segment_array(), ($n - 1)); $i = 0; $lastval = ''; @@ -322,7 +357,7 @@ class CI_URI { * @access public * @return string */ - function uri_rstring() + function ruri_string() { return '/'.implode('/', $this->rsegment_array()).'/'; } -- cgit v1.2.3-24-g4f1b From e9635566c72105b090a8eed0ef300b85ea4d5b24 Mon Sep 17 00:00:00 2001 From: admin Date: Thu, 21 Sep 2006 17:24:29 +0000 Subject: Deleting scripts folder --- system/application/scripts/index.html | 15 --------------- 1 file changed, 15 deletions(-) delete mode 100644 system/application/scripts/index.html (limited to 'system') diff --git a/system/application/scripts/index.html b/system/application/scripts/index.html deleted file mode 100644 index 5a1f5d6ae..000000000 --- a/system/application/scripts/index.html +++ /dev/null @@ -1,15 +0,0 @@ - - - - -403 Forbidden - - - - - -

Directory access is forbidden.

- - - - \ No newline at end of file -- cgit v1.2.3-24-g4f1b From fc6d9079f9f47d7474c65d6bec2aa7305a35df64 Mon Sep 17 00:00:00 2001 From: admin Date: Thu, 21 Sep 2006 22:55:47 +0000 Subject: Deleting deutsch folder --- system/language/deutsch/calendar_lang.php | 49 ---------------------------- system/language/deutsch/date_lang.php | 49 ---------------------------- system/language/deutsch/db_lang.php | 15 --------- system/language/deutsch/email_lang.php | 21 ------------ system/language/deutsch/imglib_lang.php | 21 ------------ system/language/deutsch/index.html | 15 --------- system/language/deutsch/scaffolding_lang.php | 15 --------- system/language/deutsch/unit_test_lang.php | 22 ------------- system/language/deutsch/upload_lang.php | 16 --------- system/language/deutsch/valldation_lang.php | 15 --------- 10 files changed, 238 deletions(-) delete mode 100644 system/language/deutsch/calendar_lang.php delete mode 100644 system/language/deutsch/date_lang.php delete mode 100644 system/language/deutsch/db_lang.php delete mode 100644 system/language/deutsch/email_lang.php delete mode 100644 system/language/deutsch/imglib_lang.php delete mode 100644 system/language/deutsch/index.html delete mode 100644 system/language/deutsch/scaffolding_lang.php delete mode 100644 system/language/deutsch/unit_test_lang.php delete mode 100644 system/language/deutsch/upload_lang.php delete mode 100644 system/language/deutsch/valldation_lang.php (limited to 'system') diff --git a/system/language/deutsch/calendar_lang.php b/system/language/deutsch/calendar_lang.php deleted file mode 100644 index 73ed0c4f6..000000000 --- a/system/language/deutsch/calendar_lang.php +++ /dev/null @@ -1,49 +0,0 @@ - \ No newline at end of file diff --git a/system/language/deutsch/date_lang.php b/system/language/deutsch/date_lang.php deleted file mode 100644 index 28c1acffe..000000000 --- a/system/language/deutsch/date_lang.php +++ /dev/null @@ -1,49 +0,0 @@ - \ No newline at end of file diff --git a/system/language/deutsch/db_lang.php b/system/language/deutsch/db_lang.php deleted file mode 100644 index 0e4905014..000000000 --- a/system/language/deutsch/db_lang.php +++ /dev/null @@ -1,15 +0,0 @@ - \ No newline at end of file diff --git a/system/language/deutsch/email_lang.php b/system/language/deutsch/email_lang.php deleted file mode 100644 index a93befc72..000000000 --- a/system/language/deutsch/email_lang.php +++ /dev/null @@ -1,21 +0,0 @@ - \ No newline at end of file diff --git a/system/language/deutsch/imglib_lang.php b/system/language/deutsch/imglib_lang.php deleted file mode 100644 index a9303ab6f..000000000 --- a/system/language/deutsch/imglib_lang.php +++ /dev/null @@ -1,21 +0,0 @@ - \ No newline at end of file diff --git a/system/language/deutsch/index.html b/system/language/deutsch/index.html deleted file mode 100644 index 5a1f5d6ae..000000000 --- a/system/language/deutsch/index.html +++ /dev/null @@ -1,15 +0,0 @@ - - - - -403 Forbidden - - - - - -

Directory access is forbidden.

- - - - \ No newline at end of file diff --git a/system/language/deutsch/scaffolding_lang.php b/system/language/deutsch/scaffolding_lang.php deleted file mode 100644 index ab2e62957..000000000 --- a/system/language/deutsch/scaffolding_lang.php +++ /dev/null @@ -1,15 +0,0 @@ - \ No newline at end of file diff --git a/system/language/deutsch/unit_test_lang.php b/system/language/deutsch/unit_test_lang.php deleted file mode 100644 index 5728bf567..000000000 --- a/system/language/deutsch/unit_test_lang.php +++ /dev/null @@ -1,22 +0,0 @@ - \ No newline at end of file diff --git a/system/language/deutsch/upload_lang.php b/system/language/deutsch/upload_lang.php deleted file mode 100644 index 57583ad07..000000000 --- a/system/language/deutsch/upload_lang.php +++ /dev/null @@ -1,16 +0,0 @@ - \ No newline at end of file diff --git a/system/language/deutsch/valldation_lang.php b/system/language/deutsch/valldation_lang.php deleted file mode 100644 index 688af05de..000000000 --- a/system/language/deutsch/valldation_lang.php +++ /dev/null @@ -1,15 +0,0 @@ - \ No newline at end of file -- cgit v1.2.3-24-g4f1b From c1fa07415179d63762f1a22f0f74660a8034707f Mon Sep 17 00:00:00 2001 From: admin Date: Thu, 21 Sep 2006 23:50:23 +0000 Subject: --- system/libraries/Controller.php | 2 +- system/libraries/Output.php | 22 +++++++++++++++------- system/libraries/URI.php | 2 +- 3 files changed, 17 insertions(+), 9 deletions(-) (limited to 'system') diff --git a/system/libraries/Controller.php b/system/libraries/Controller.php index 5a32e65c0..0dd6ee6a4 100644 --- a/system/libraries/Controller.php +++ b/system/libraries/Controller.php @@ -380,7 +380,7 @@ class Controller extends CI_Base { eval('class CI_DB extends CI_DB_driver { }'); } } - + require_once(BASEPATH.'drivers/DB_'.$params['dbdriver'].EXT); // Instantiate the DB adapter diff --git a/system/libraries/Output.php b/system/libraries/Output.php index 4a3adb858..ec3660c6c 100644 --- a/system/libraries/Output.php +++ b/system/libraries/Output.php @@ -123,8 +123,8 @@ class CI_Output { */ function _display($output = '') { - $BM =& _load_class('CI_Benchmark'); - + $obj =& get_instance(); + if ($output == '') { $output =& $this->final_output; @@ -138,15 +138,14 @@ class CI_Output { // Parse out the elapsed time and memory usage, and // swap the pseudo-variables with the data - $elapsed = $BM->elapsed_time('code_igniter_start', 'code_igniter_end'); + $elapsed = $obj->benchmark->elapsed_time('code_igniter_start', 'code_igniter_end'); $memory = ( ! function_exists('memory_get_usage')) ? '0' : round(memory_get_usage()/1024/1024, 2).'MB'; $output = str_replace('{memory_usage}', $memory, $output); $output = str_replace('{elapsed_time}', $elapsed, $output); // Is compression requested? - $CFG =& _load_class('CI_Config'); - if ($CFG->item('compress_output') === TRUE) + if ($obj->config->item('compress_output') === TRUE) { if (extension_loaded('zlib')) { @@ -166,8 +165,17 @@ class CI_Output { } } - // Send it to the browser! - echo $output; + // Send the finalized output either directly + // to the browser or to the user's _output() + // function if it exists + if (method_exists($obj, '_output')) + { + $obj->_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); diff --git a/system/libraries/URI.php b/system/libraries/URI.php index e831d9526..89ca42e44 100644 --- a/system/libraries/URI.php +++ b/system/libraries/URI.php @@ -280,7 +280,7 @@ class CI_URI { $leading = '/'; $trailing = '/'; } - return ( ! isset($this->router->$which[$n])) ? '' : $leading.$this->router->$which[$n].$trailing; + return $leading.$this->$which($n).$trailing; } // -------------------------------------------------------------------- -- cgit v1.2.3-24-g4f1b From 6bd915cdc10877cc235a3e71f126523921407df5 Mon Sep 17 00:00:00 2001 From: admin Date: Fri, 22 Sep 2006 00:12:23 +0000 Subject: --- system/application/config/config.php | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'system') diff --git a/system/application/config/config.php b/system/application/config/config.php index eba2ec271..a7b3204cc 100644 --- a/system/application/config/config.php +++ b/system/application/config/config.php @@ -264,13 +264,13 @@ $config['global_xss_filtering'] = FALSE; | Output Compression |-------------------------------------------------------------------------- | -| Enables output compression using Gzip for faster page loads. When enabled, -| the output class will test whether the server your site is running on -| supports Gzip. Even if it does, however, not all browsers support compression +| Enables Gzip output compression for faster page loads. When enabled, +| the output class will test whether your server supports Gzip. +| Even if it does, however, not all browsers support compression | so enable only if you are reasonably sure your visitors can handle it. | -| VERY IMPORTANT: If you are getting a blank page when this is enabled it -| means you are prematurely outputing something to your browser. It could +| VERY IMPORTANT: If you are getting a blank page when compression is enabled it +| means you are prematurely outputting something to your browser. It could | even be a line of whitespace at the end of one of your scripts. For | compression to work, nothing can be sent before the output buffer is called | by the output class. Do not "echo" any values with compression enabled. -- cgit v1.2.3-24-g4f1b From abe1482d7b005fa1d5a188d03a9147e7c4691f59 Mon Sep 17 00:00:00 2001 From: admin Date: Fri, 22 Sep 2006 00:14:38 +0000 Subject: --- system/application/config/autoload.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system') diff --git a/system/application/config/autoload.php b/system/application/config/autoload.php index 4efe3be41..915dcee12 100644 --- a/system/application/config/autoload.php +++ b/system/application/config/autoload.php @@ -101,7 +101,7 @@ $autoload['config'] = array(); | Auto-load Core Libraries | ------------------------------------------------------------------- | -| DEPRECATED: Use $autoload $autoload['libraries'] instead. +| DEPRECATED: Use $autoload['libraries'] above instead. | */ // $autoload['core'] = array(); -- cgit v1.2.3-24-g4f1b From 6df261fe1918e15611cf7c3fad8175f7cec35cca Mon Sep 17 00:00:00 2001 From: admin Date: Fri, 22 Sep 2006 00:15:07 +0000 Subject: --- system/application/config/routes.php | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'system') diff --git a/system/application/config/routes.php b/system/application/config/routes.php index 473704c6d..8a1f8b166 100644 --- a/system/application/config/routes.php +++ b/system/application/config/routes.php @@ -40,9 +40,12 @@ */ $route['default_controller'] = "welcome"; - $route['scaffolding_trigger'] = ""; // Define your own routes below ------------------------------------------- + + + + ?> \ No newline at end of file -- cgit v1.2.3-24-g4f1b From b22ecd73e345d843baf9f17ec1ffedca0aa62e8a Mon Sep 17 00:00:00 2001 From: admin Date: Fri, 22 Sep 2006 00:15:43 +0000 Subject: --- system/codeigniter/CodeIgniter.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system') diff --git a/system/codeigniter/CodeIgniter.php b/system/codeigniter/CodeIgniter.php index de1e91095..e169be0b1 100644 --- a/system/codeigniter/CodeIgniter.php +++ b/system/codeigniter/CodeIgniter.php @@ -27,7 +27,7 @@ * @link http://www.codeigniter.com/user_guide/ */ -define('APPVER', '1.4.0'); +define('APPVER', '1.4.1'); /* * ------------------------------------------------------ -- cgit v1.2.3-24-g4f1b From 592cdcbc58963f0cf811aea59db9907943460770 Mon Sep 17 00:00:00 2001 From: admin Date: Fri, 22 Sep 2006 18:45:42 +0000 Subject: --- system/helpers/inflector_helper.php | 4 +- system/libraries/Router.php | 138 +++++++++++++++++++++++++++--------- 2 files changed, 106 insertions(+), 36 deletions(-) (limited to 'system') diff --git a/system/helpers/inflector_helper.php b/system/helpers/inflector_helper.php index 3bded708e..3d8d3e0ca 100644 --- a/system/helpers/inflector_helper.php +++ b/system/helpers/inflector_helper.php @@ -31,7 +31,7 @@ /** * Singular * - * Takes a plural word and makes it singular + * Takes a singular word and makes it plural * * @access public * @param string @@ -64,7 +64,7 @@ function singular($str) /** * Plural * - * Takes a singular word and makes it plural + * Takes a plural word and makes it singular * * @access public * @param string diff --git a/system/libraries/Router.php b/system/libraries/Router.php index 868fd909e..5bbf9e6ca 100644 --- a/system/libraries/Router.php +++ b/system/libraries/Router.php @@ -77,45 +77,18 @@ class CI_Router { return; } - - // Load the routes.php file + + // Load the routes.php file and set the default controller @include_once(APPPATH.'config/routes'.EXT); $this->routes = ( ! isset($route) OR ! is_array($route)) ? array() : $route; unset($route); - // Set the default controller - $this->default_controller = ( ! isset($this->routes['default_controller']) OR $this->routes['default_controller'] == '') ? FALSE : strtolower($this->routes['default_controller']); - - // Fetch the URI string Depending on the server, - // the URI will be available in one of two globals - if ($this->config->item('uri_protocol') == 'auto') - { - $path_info = getenv('PATH_INFO'); - if ($path_info != '' AND $path_info != "/".SELF) - { - $this->uri_string = $path_info; - } - else - { - $path_info = getenv('ORIG_PATH_INFO'); - if ($path_info != '' AND $path_info != "/".SELF) - { - $this->uri_string = $path_info; - } - else - { - $this->uri_string = getenv('QUERY_STRING'); - } - } - } - else - { - $this->uri_string = getenv(strtoupper($this->config->item('uri_protocol'))); - } - + $this->default_controller = ( ! isset($this->routes['default_controller']) OR $this->routes['default_controller'] == '') ? FALSE : strtolower($this->routes['default_controller']); - // Is there a URI string? If not, the default controller specified - // by the admin in the "routes" file will be shown. + // Get the URI string + $this->uri_string = $this->_get_uri_string(); + + // Is there a URI string? If not, the default controller specified in the "routes" file will be shown. if ($this->uri_string == '') { if ($this->default_controller === FALSE) @@ -300,6 +273,103 @@ class CI_Router { // -------------------------------------------------------------------- + /** + * Get the URI String + * + * @access private + * @return string + */ + function _get_uri_string() + { + if (strtoupper($this->config->item('uri_protocol')) == 'AUTO') + { + $path_info = getenv('PATH_INFO'); + if ($path_info != '' AND $path_info != "/".SELF) + { + return $path_info; + } + else + { + $req_uri = $this->_parse_request_uri(); + + if ($req_uri != "") + { + return $req_uri; + } + else + { + $path_info = getenv('ORIG_PATH_INFO'); + if ($path_info != '' AND $path_info != "/".SELF) + { + return $path_info; + } + else + { + return getenv('QUERY_STRING'); + } + } + } + } + else + { + $uri = strtoupper($this->config->item('uri_protocol')); + + if ($uri == 'REQUEST_URI') + { + return $this->_parse_request_uri(); + } + + return getenv($uri); + } + } + // END _get_uri_string() + + // -------------------------------------------------------------------- + + /** + * Parse the REQUEST_URI + * + * Due to the way REQUEST_URI works it usually contains path info + * that makes it unusable as URI data. We'll trim off the unnecessary + * data, hopefully arriving at a valid URI that we can use. + * + * @access private + * @return string + */ + function _parse_request_uri() + { + $request_uri = getenv('REQUEST_URI'); + $fc_path = FCPATH; + + if (strpos($request_uri, '?') !== FALSE) + { + $fc_path .= '?'; + } + + $parsed_uri = explode("/", preg_replace("|/(.*)|", "\\1", str_replace("\\", "/", $request_uri))); + + $i = 0; + foreach(explode("/", $fc_path) as $segment) + { + if ($segment == $parsed_uri[$i]) + { + $i++; + } + } + + $parsed_uri = implode("/", array_slice($parsed_uri, $i)); + + if ($parsed_uri != '') + { + $parsed_uri = '/'.$parsed_uri; + } + + return $parsed_uri; + } + // END _parse_request_uri() + + // -------------------------------------------------------------------- + /** * Filter segments for malicious characters * -- cgit v1.2.3-24-g4f1b From dbd8aec6121f1d0a295031c268964357ebcc84e0 Mon Sep 17 00:00:00 2001 From: admin Date: Fri, 22 Sep 2006 19:20:09 +0000 Subject: --- system/libraries/Router.php | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) (limited to 'system') diff --git a/system/libraries/Router.php b/system/libraries/Router.php index 5bbf9e6ca..d1751a0e9 100644 --- a/system/libraries/Router.php +++ b/system/libraries/Router.php @@ -85,11 +85,8 @@ class CI_Router { $this->default_controller = ( ! isset($this->routes['default_controller']) OR $this->routes['default_controller'] == '') ? FALSE : strtolower($this->routes['default_controller']); - // Get the URI string - $this->uri_string = $this->_get_uri_string(); - // Is there a URI string? If not, the default controller specified in the "routes" file will be shown. - if ($this->uri_string == '') + if (($this->uri_string = $this->_get_uri_string()) == '') { if ($this->default_controller === FALSE) { @@ -338,7 +335,11 @@ class CI_Router { */ function _parse_request_uri() { - $request_uri = getenv('REQUEST_URI'); + if (($request_uri = getenv('REQUEST_URI')) == '') + { + return ''; + } + $fc_path = FCPATH; if (strpos($request_uri, '?') !== FALSE) -- cgit v1.2.3-24-g4f1b From 8407ccaa1162df0addf49d50a9a0b6e9a4151804 Mon Sep 17 00:00:00 2001 From: admin Date: Sat, 23 Sep 2006 01:22:56 +0000 Subject: --- system/codeigniter/CodeIgniter.php | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) (limited to 'system') diff --git a/system/codeigniter/CodeIgniter.php b/system/codeigniter/CodeIgniter.php index e169be0b1..b055d3b1e 100644 --- a/system/codeigniter/CodeIgniter.php +++ b/system/codeigniter/CodeIgniter.php @@ -198,8 +198,16 @@ else } // 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($RTR->rsegments, 2)); + // will be passed to the method for convenience, either as an array or discreet params + + if (isset($CI->_uri_as_array) AND $CI->_uri_as_array === TRUE) + { + $CI->$method(array_slice($RTR->rsegments, 2)); + } + else + { + call_user_func_array(array(&$CI, $method), array_slice($RTR->rsegments, 2)); + } } } -- cgit v1.2.3-24-g4f1b From 212a3fa070a02c812b84ca937c5cb411400e6f3d Mon Sep 17 00:00:00 2001 From: admin Date: Sat, 23 Sep 2006 04:22:39 +0000 Subject: --- system/libraries/Loader.php | 24 ++++++++---------------- system/libraries/Parser.php | 4 +--- 2 files changed, 9 insertions(+), 19 deletions(-) (limited to 'system') diff --git a/system/libraries/Loader.php b/system/libraries/Loader.php index ead55dff7..d966e2862 100644 --- a/system/libraries/Loader.php +++ b/system/libraries/Loader.php @@ -454,9 +454,7 @@ class CI_Loader { * @return void */ function _ci_load($data) - { - $OUT =& _load_class('CI_Output'); - + { // This allows anything loaded using $this->load (viwes, files, etc.) // to become accessible from within the Controller and Model functions. $obj =& get_instance(); @@ -477,15 +475,11 @@ class CI_Loader { /* * Extract and cached 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. - * + * 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($vars)) { $this->cached_vars = array_merge($this->cached_vars, $vars); @@ -515,10 +509,8 @@ class CI_Loader { * 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 acurate. - * + * the browser and then stop the timer it won't be acurate. */ - if ( ! file_exists($path)) { show_error('Unable to load the requested file: '.$file); @@ -541,7 +533,7 @@ class CI_Loader { /* * Flush the buffer... or buff the flusher? * - * In order to permit templates (views) to be nested within + * In order to permit views to be nested within * other views, we need to flush the content back out whenever * we are beyond the first level of output buffering so that * it can be seen and included properly by the first included @@ -554,7 +546,7 @@ class CI_Loader { } else { - $OUT->set_output(ob_get_contents()); + $obj->output->set_output(ob_get_contents()); ob_end_clean(); } } diff --git a/system/libraries/Parser.php b/system/libraries/Parser.php index b07b64fdd..17a985fd7 100644 --- a/system/libraries/Parser.php +++ b/system/libraries/Parser.php @@ -44,8 +44,6 @@ class CI_Parser { */ function parse($template, $data, $return = FALSE) { - $OUT =& _load_class('CI_Output'); - $obj =& get_instance(); $template = $obj->load->view($template, $data, TRUE); @@ -68,7 +66,7 @@ class CI_Parser { if ($return == FALSE) { - $OUT->final_output = $template; + $obj->output->final_output = $template; } return $template; -- cgit v1.2.3-24-g4f1b From 4e9f3f90ed26a0dc4bcacf106d6421bf725b5ae3 Mon Sep 17 00:00:00 2001 From: admin Date: Sat, 23 Sep 2006 17:39:20 +0000 Subject: --- system/libraries/Parser.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'system') diff --git a/system/libraries/Parser.php b/system/libraries/Parser.php index 17a985fd7..63dc023a2 100644 --- a/system/libraries/Parser.php +++ b/system/libraries/Parser.php @@ -54,11 +54,11 @@ class CI_Parser { foreach ($data as $key => $val) { - if ( ! is_array($val)) + if (is_string($val)) { $template = $this->_parse_single($key, $val, $template); } - else + elseif (is_array($val)) { $template = $this->_parse_pair($key, $val, $template); } -- cgit v1.2.3-24-g4f1b From b5a651cd710f7454425b9b94ff4a44fc4edacaba Mon Sep 17 00:00:00 2001 From: admin Date: Sat, 23 Sep 2006 17:39:41 +0000 Subject: --- system/codeigniter/CodeIgniter.php | 14 +++----------- system/libraries/Output.php | 11 +++++++---- 2 files changed, 10 insertions(+), 15 deletions(-) (limited to 'system') diff --git a/system/codeigniter/CodeIgniter.php b/system/codeigniter/CodeIgniter.php index b055d3b1e..0078b4596 100644 --- a/system/codeigniter/CodeIgniter.php +++ b/system/codeigniter/CodeIgniter.php @@ -196,18 +196,10 @@ else { show_404(); } - - // Call the requested method. Any URI segments present (besides the class/function) - // will be passed to the method for convenience, either as an array or discreet params - if (isset($CI->_uri_as_array) AND $CI->_uri_as_array === TRUE) - { - $CI->$method(array_slice($RTR->rsegments, 2)); - } - else - { - call_user_func_array(array(&$CI, $method), array_slice($RTR->rsegments, 2)); - } + // 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($RTR->rsegments, 2)); } } diff --git a/system/libraries/Output.php b/system/libraries/Output.php index ec3660c6c..5a158245f 100644 --- a/system/libraries/Output.php +++ b/system/libraries/Output.php @@ -123,7 +123,10 @@ class CI_Output { */ function _display($output = '') { - $obj =& get_instance(); + // Note: We can't use $obj =& _get_instance() since this function + // is sometimes called by the caching mechanism, which happens before + // it's available. Instead we'll use globals... + global $BM, $CFG; if ($output == '') { @@ -138,14 +141,14 @@ class CI_Output { // Parse out the elapsed time and memory usage, and // swap the pseudo-variables with the data - $elapsed = $obj->benchmark->elapsed_time('code_igniter_start', 'code_igniter_end'); + $elapsed = $BM->elapsed_time('code_igniter_start', 'code_igniter_end'); $memory = ( ! function_exists('memory_get_usage')) ? '0' : round(memory_get_usage()/1024/1024, 2).'MB'; $output = str_replace('{memory_usage}', $memory, $output); $output = str_replace('{elapsed_time}', $elapsed, $output); // Is compression requested? - if ($obj->config->item('compress_output') === TRUE) + if ($CFG->item('compress_output') === TRUE) { if (extension_loaded('zlib')) { @@ -168,7 +171,7 @@ class CI_Output { // Send the finalized output either directly // to the browser or to the user's _output() // function if it exists - if (method_exists($obj, '_output')) + if (function_exists('_get_instance') AND method_exists($obj, '_output')) { $obj->_output($output); } -- cgit v1.2.3-24-g4f1b From f5ea6653153ea8e78f347b7a552ff9049cc47caf Mon Sep 17 00:00:00 2001 From: admin Date: Sat, 23 Sep 2006 19:58:47 +0000 Subject: --- system/drivers/DB_mysql.php | 80 ++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 79 insertions(+), 1 deletion(-) (limited to 'system') diff --git a/system/drivers/DB_mysql.php b/system/drivers/DB_mysql.php index 72790976e..69a6db0eb 100644 --- a/system/drivers/DB_mysql.php +++ b/system/drivers/DB_mysql.php @@ -83,7 +83,7 @@ class CI_DB_mysql extends CI_DB { * @param string an SQL query * @return resource */ - function execute($sql) + function _execute($sql) { $sql = $this->_prep_query($sql); return @mysql_query($sql, $this->conn_id); @@ -114,6 +114,84 @@ class CI_DB_mysql extends CI_DB { return $sql; } + + // -------------------------------------------------------------------- + + /** + * Begin Transaction + * + * @access public + * @return bool + */ + function trans_begin() + { + 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('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; + } // -------------------------------------------------------------------- -- cgit v1.2.3-24-g4f1b From 66530a809018c2ba39d9adb5b2cf21640969e472 Mon Sep 17 00:00:00 2001 From: admin Date: Sat, 23 Sep 2006 19:58:55 +0000 Subject: --- system/drivers/DB_driver.php | 126 ++++++++++++++++++++++++++++++++++++++----- 1 file changed, 114 insertions(+), 12 deletions(-) (limited to 'system') diff --git a/system/drivers/DB_driver.php b/system/drivers/DB_driver.php index 2d1232d7b..b05cd7c5b 100644 --- a/system/drivers/DB_driver.php +++ b/system/drivers/DB_driver.php @@ -45,12 +45,15 @@ class CI_DB_driver { var $query_count = 0; var $bind_marker = '?'; var $queries = array(); - + var $trans_enabled = TRUE; + var $_trans_depth = 0; + var $_trans_failure = FALSE; // Used with transactions to determine if a rollback should occur + // These are use with Oracle var $stmt_id; var $curs_id; var $limit_used; - + /** * Constructor. Accepts one parameter containing the database @@ -186,11 +189,6 @@ class CI_DB_driver { */ function query($sql, $binds = FALSE, $return_object = TRUE) { - if ( ! $this->conn_id) - { - $this->initialize(); - } - if ($sql == '') { if ($this->db_debug) @@ -207,15 +205,18 @@ class CI_DB_driver { $sql = $this->compile_binds($sql, $binds); } - // Start the Query Timer - $time_start = list($sm, $ss) = explode(' ', microtime()); - // Save the query for debugging $this->queries[] = $sql; - + + // Start the Query Timer + $time_start = list($sm, $ss) = explode(' ', microtime()); + // Run the Query - if (FALSE === ($this->result_id = $this->execute($sql, $this->conn_id))) + if (FALSE === ($this->result_id = $this->simple_query($sql))) { + // This will trigger a rollback if transactions are being used + $this->_trans_failure = TRUE; + if ($this->db_debug) { log_message('error', 'Query error: '.$this->error_message()); @@ -273,6 +274,107 @@ class CI_DB_driver { // -------------------------------------------------------------------- + /** + * Simple Query + * This is a simiplified 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, $this->conn_id); + } + + // -------------------------------------------------------------------- + + /** + * Disable Transactions + * This permits transactions to be disabled at run-time. + * + * @access public + * @return void + */ + function trans_off() + { + $this->trans_enabled = FALSE; + } + + // -------------------------------------------------------------------- + + /** + * Start Transaction + * + * @access public + * @return void + */ + function trans_start() + { + 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; + } + + // Reset the transaction failure flag + $this->_trans_failure = FALSE; + $this->trans_begin(); + } + + // -------------------------------------------------------------------- + + /** + * 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 TRUE in the event that a query failed + if ($this->_trans_failure === TRUE) + { + $this->trans_rollback(); + + if ($this->db_debug) + { + return $this->display_error('db_transaction_failure'); + } + return FALSE; + } + + $this->trans_commit(); + return TRUE; + } + + // -------------------------------------------------------------------- + /** * Enables a native PHP function to be run, using a platform agnostic wrapper. * -- cgit v1.2.3-24-g4f1b From e885d787cde65d9ab003426bf79047de57c83ebe Mon Sep 17 00:00:00 2001 From: admin Date: Sat, 23 Sep 2006 20:25:05 +0000 Subject: --- system/drivers/DB_mssql.php | 77 ++++++++++++++++++++++++++++++++- system/drivers/DB_mysqli.php | 83 ++++++++++++++++++++++++++++++++++- system/drivers/DB_oci8.php | 86 +++++++++++++++++++++++++++++++++++-- system/drivers/DB_odbc.php | 80 +++++++++++++++++++++++++++++++++- system/drivers/DB_postgre.php | 76 +++++++++++++++++++++++++++++++- system/drivers/DB_sqlite.php | 77 ++++++++++++++++++++++++++++++++- system/language/english/db_lang.php | 2 + system/libraries/Xmlrpcs.php | 2 +- 8 files changed, 471 insertions(+), 12 deletions(-) (limited to 'system') diff --git a/system/drivers/DB_mssql.php b/system/drivers/DB_mssql.php index c84247641..3fbfa6a3f 100644 --- a/system/drivers/DB_mssql.php +++ b/system/drivers/DB_mssql.php @@ -76,7 +76,7 @@ class CI_DB_mssql extends CI_DB { * @param string an SQL query * @return resource */ - function execute($sql) + function _execute($sql) { $sql = $this->_prep_query($sql); return @mssql_query($sql, $this->conn_id); @@ -97,6 +97,81 @@ class CI_DB_mssql extends CI_DB { { return $sql; } + + // -------------------------------------------------------------------- + + /** + * Begin Transaction + * + * @access public + * @return bool + */ + function trans_begin() + { + 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('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; + } // -------------------------------------------------------------------- diff --git a/system/drivers/DB_mysqli.php b/system/drivers/DB_mysqli.php index 4b9685799..a5237c832 100644 --- a/system/drivers/DB_mysqli.php +++ b/system/drivers/DB_mysqli.php @@ -85,7 +85,7 @@ class CI_DB_mysqli extends CI_DB { * @param string an SQL query * @return resource */ - function execute($sql) + function _execute($sql) { $sql = $this->_prep_query($sql); $result = @mysqli_query($this->conn_id, $sql); @@ -117,7 +117,86 @@ class CI_DB_mysqli extends CI_DB { return $sql; } - + + + // -------------------------------------------------------------------- + + /** + * Begin Transaction + * + * @access public + * @return bool + */ + function trans_begin() + { + 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('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; + } + // -------------------------------------------------------------------- /** diff --git a/system/drivers/DB_oci8.php b/system/drivers/DB_oci8.php index 06426dcac..2f936da12 100644 --- a/system/drivers/DB_oci8.php +++ b/system/drivers/DB_oci8.php @@ -43,6 +43,9 @@ class CI_DB_oci8 extends CI_DB { + // Set "auto commit" by default + var $_commit = OCI_COMMIT_ON_SUCCESS; + // need to track statement id and cursor id var $stmt_id; var $curs_id; @@ -50,7 +53,7 @@ class CI_DB_oci8 extends CI_DB { // if we use a limit, we will add a field that will // throw off num_fields later var $limit_used; - + /** * Non-persistent database connection * @@ -97,7 +100,7 @@ class CI_DB_oci8 extends CI_DB { * @param string an SQL query * @return resource */ - function execute($sql) + function _execute($sql) { // oracle must parse the query before it // is run, all of the actions with @@ -105,7 +108,7 @@ class CI_DB_oci8 extends CI_DB { // returned by ociparse $this->_set_stmt_id($sql); ocisetprefetch($this->stmt_id, 1000); - return @ociexecute($this->stmt_id); + return @ociexecute($this->stmt_id, $this->_commit); } /** @@ -234,6 +237,83 @@ class CI_DB_oci8 extends CI_DB { } } + // -------------------------------------------------------------------- + + /** + * Begin Transaction + * + * @access public + * @return bool + */ + function trans_begin() + { + 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->_commit = OCI_DEFAULT; + 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; + } + + $ret = OCIcommit($this->conn_id); + $this->_commit = OCI_COMMIT_ON_SUCCESS; + 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 = OCIrollback($this->conn_id); + $this->_commit = OCI_COMMIT_ON_SUCCESS; + return $ret; + } + // -------------------------------------------------------------------- /** diff --git a/system/drivers/DB_odbc.php b/system/drivers/DB_odbc.php index 57cdbced8..a32e9e072 100644 --- a/system/drivers/DB_odbc.php +++ b/system/drivers/DB_odbc.php @@ -77,7 +77,7 @@ class CI_DB_odbc extends CI_DB { * @param string an SQL query * @return resource */ - function execute($sql) + function _execute($sql) { $sql = $this->_prep_query($sql); return @odbc_exec($this->conn_id, $sql); @@ -98,7 +98,83 @@ class CI_DB_odbc extends CI_DB { { return $sql; } - + + // -------------------------------------------------------------------- + + /** + * Begin Transaction + * + * @access public + * @return bool + */ + function trans_begin() + { + 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 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; + } + // -------------------------------------------------------------------- /** diff --git a/system/drivers/DB_postgre.php b/system/drivers/DB_postgre.php index 57ef179d9..fe7c704f9 100644 --- a/system/drivers/DB_postgre.php +++ b/system/drivers/DB_postgre.php @@ -81,7 +81,7 @@ class CI_DB_postgre extends CI_DB { * @param string an SQL query * @return resource */ - function execute($sql) + function _execute($sql) { $sql = $this->_prep_query($sql); return @pg_query($this->conn_id, $sql); @@ -102,7 +102,79 @@ class CI_DB_postgre extends CI_DB { { return $sql; } - + + // -------------------------------------------------------------------- + + /** + * Begin Transaction + * + * @access public + * @return bool + */ + function trans_begin() + { + 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, "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"); + } + // -------------------------------------------------------------------- /** diff --git a/system/drivers/DB_sqlite.php b/system/drivers/DB_sqlite.php index 48e2c8714..6d7b4294a 100644 --- a/system/drivers/DB_sqlite.php +++ b/system/drivers/DB_sqlite.php @@ -98,7 +98,7 @@ class CI_DB_sqlite extends CI_DB { * @param string an SQL query * @return resource */ - function execute($sql) + function _execute($sql) { $sql = $this->_prep_query($sql); return @sqlite_query($this->conn_id, $sql); @@ -119,6 +119,81 @@ class CI_DB_sqlite extends CI_DB { { return $sql; } + + // -------------------------------------------------------------------- + + /** + * Begin Transaction + * + * @access public + * @return bool + */ + function trans_begin() + { + 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('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; + } // -------------------------------------------------------------------- diff --git a/system/language/english/db_lang.php b/system/language/english/db_lang.php index b210b61ba..d51bb6dce 100644 --- a/system/language/english/db_lang.php +++ b/system/language/english/db_lang.php @@ -11,5 +11,7 @@ $lang['db_must_use_where'] = 'Updates are not allowed unless they contain a "whe $lang['db_del_must_use_where'] = 'Deletes are not allowed unless they contain a "where" clause.'; $lang['db_field_param_missing'] = 'To fetch fields requires the name of the table as a parameter.'; $lang['db_unsupported_function'] = 'This feature is not available for the database you are using.'; +$lang['db_transaction_failure'] = 'Transaction failure: Rollback performed'; + ?> \ No newline at end of file diff --git a/system/libraries/Xmlrpcs.php b/system/libraries/Xmlrpcs.php index eaec87a6d..0543c3b78 100644 --- a/system/libraries/Xmlrpcs.php +++ b/system/libraries/Xmlrpcs.php @@ -223,7 +223,7 @@ class CI_XML_RPC_Server extends CI_XML_RPC // Executes the Method //------------------------------------- - function execute($m) + function _execute($m) { $methName = $m->method_name; -- cgit v1.2.3-24-g4f1b From 8b180be71430efa5726389ee03107d1cadd52626 Mon Sep 17 00:00:00 2001 From: admin Date: Sun, 24 Sep 2006 01:12:22 +0000 Subject: --- system/drivers/DB_driver.php | 20 ++++++++++++++++---- system/drivers/DB_mssql.php | 7 ++++++- system/drivers/DB_mysql.php | 7 ++++++- system/drivers/DB_mysqli.php | 7 ++++++- system/drivers/DB_oci8.php | 7 ++++++- system/drivers/DB_odbc.php | 7 ++++++- system/drivers/DB_postgre.php | 7 ++++++- system/drivers/DB_sqlite.php | 7 ++++++- 8 files changed, 58 insertions(+), 11 deletions(-) (limited to 'system') diff --git a/system/drivers/DB_driver.php b/system/drivers/DB_driver.php index b05cd7c5b..a1ec14b06 100644 --- a/system/drivers/DB_driver.php +++ b/system/drivers/DB_driver.php @@ -316,7 +316,7 @@ class CI_DB_driver { * @access public * @return void */ - function trans_start() + function trans_start($test_mode = FALSE) { if ( ! $this->trans_enabled) { @@ -330,9 +330,7 @@ class CI_DB_driver { return; } - // Reset the transaction failure flag - $this->_trans_failure = FALSE; - $this->trans_begin(); + $this->trans_begin($test_mode); } // -------------------------------------------------------------------- @@ -373,6 +371,20 @@ class CI_DB_driver { return TRUE; } + // -------------------------------------------------------------------- + + /** + * Lets you retrieve the transaction flag to determine if it has failed + * + * @access public + * @return bool + */ + function trans_status() + { + return $this->_trans_failure; + } + + // -------------------------------------------------------------------- /** diff --git a/system/drivers/DB_mssql.php b/system/drivers/DB_mssql.php index 3fbfa6a3f..32c0537c3 100644 --- a/system/drivers/DB_mssql.php +++ b/system/drivers/DB_mssql.php @@ -106,7 +106,7 @@ class CI_DB_mssql extends CI_DB { * @access public * @return bool */ - function trans_begin() + function trans_begin($test_mode = FALSE) { if ( ! $this->trans_enabled) { @@ -119,6 +119,11 @@ class CI_DB_mssql extends CI_DB { 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; } diff --git a/system/drivers/DB_mysql.php b/system/drivers/DB_mysql.php index 69a6db0eb..208f09c25 100644 --- a/system/drivers/DB_mysql.php +++ b/system/drivers/DB_mysql.php @@ -123,7 +123,7 @@ class CI_DB_mysql extends CI_DB { * @access public * @return bool */ - function trans_begin() + function trans_begin($test_mode = FALSE) { if ( ! $this->trans_enabled) { @@ -136,6 +136,11 @@ class CI_DB_mysql extends CI_DB { 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; diff --git a/system/drivers/DB_mysqli.php b/system/drivers/DB_mysqli.php index a5237c832..288f552dd 100644 --- a/system/drivers/DB_mysqli.php +++ b/system/drivers/DB_mysqli.php @@ -127,7 +127,7 @@ class CI_DB_mysqli extends CI_DB { * @access public * @return bool */ - function trans_begin() + function trans_begin($test_mode = FALSE) { if ( ! $this->trans_enabled) { @@ -140,6 +140,11 @@ class CI_DB_mysqli extends CI_DB { 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; diff --git a/system/drivers/DB_oci8.php b/system/drivers/DB_oci8.php index 2f936da12..a88b474bd 100644 --- a/system/drivers/DB_oci8.php +++ b/system/drivers/DB_oci8.php @@ -245,7 +245,7 @@ class CI_DB_oci8 extends CI_DB { * @access public * @return bool */ - function trans_begin() + function trans_begin($test_mode = FALSE) { if ( ! $this->trans_enabled) { @@ -258,6 +258,11 @@ class CI_DB_oci8 extends CI_DB { 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; } diff --git a/system/drivers/DB_odbc.php b/system/drivers/DB_odbc.php index a32e9e072..cdd2f4513 100644 --- a/system/drivers/DB_odbc.php +++ b/system/drivers/DB_odbc.php @@ -107,7 +107,7 @@ class CI_DB_odbc extends CI_DB { * @access public * @return bool */ - function trans_begin() + function trans_begin($test_mode = FALSE) { if ( ! $this->trans_enabled) { @@ -120,6 +120,11 @@ class CI_DB_odbc extends CI_DB { 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); } diff --git a/system/drivers/DB_postgre.php b/system/drivers/DB_postgre.php index fe7c704f9..bd5fbac24 100644 --- a/system/drivers/DB_postgre.php +++ b/system/drivers/DB_postgre.php @@ -111,7 +111,7 @@ class CI_DB_postgre extends CI_DB { * @access public * @return bool */ - function trans_begin() + function trans_begin($test_mode = FALSE) { if ( ! $this->trans_enabled) { @@ -124,6 +124,11 @@ class CI_DB_postgre extends CI_DB { 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"); } diff --git a/system/drivers/DB_sqlite.php b/system/drivers/DB_sqlite.php index 6d7b4294a..b21241a1f 100644 --- a/system/drivers/DB_sqlite.php +++ b/system/drivers/DB_sqlite.php @@ -128,7 +128,7 @@ class CI_DB_sqlite extends CI_DB { * @access public * @return bool */ - function trans_begin() + function trans_begin($test_mode = FALSE) { if ( ! $this->trans_enabled) { @@ -141,6 +141,11 @@ class CI_DB_sqlite extends CI_DB { 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; } -- cgit v1.2.3-24-g4f1b From 7d85288f06b977a2e86477d989b9fb7a5611bd0a Mon Sep 17 00:00:00 2001 From: admin Date: Sun, 24 Sep 2006 01:33:56 +0000 Subject: --- system/codeigniter/CodeIgniter.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'system') diff --git a/system/codeigniter/CodeIgniter.php b/system/codeigniter/CodeIgniter.php index 0078b4596..434602742 100644 --- a/system/codeigniter/CodeIgniter.php +++ b/system/codeigniter/CodeIgniter.php @@ -198,8 +198,8 @@ else } // 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($RTR->rsegments, 2)); + // will be passed to the method for convenience + call_user_func_array(array(&$CI, $method), array_slice($RTR->rsegments, (($RTR->fetch_directory() == '') ? 2 : 3))); } } -- cgit v1.2.3-24-g4f1b From 3c023b12c3d27f0e2773e671b854e52e2dc0d1d6 Mon Sep 17 00:00:00 2001 From: admin Date: Sun, 24 Sep 2006 03:04:10 +0000 Subject: --- system/libraries/Validation.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system') diff --git a/system/libraries/Validation.php b/system/libraries/Validation.php index f9b51d778..153657e31 100644 --- a/system/libraries/Validation.php +++ b/system/libraries/Validation.php @@ -524,7 +524,7 @@ class CI_Validation { */ function numeric($str) { - return ( ! ereg("^[0-9]+$", $str)) ? FALSE : TRUE; + return ( ! ereg("^[0-9\.]+$", $str)) ? FALSE : TRUE; } // -------------------------------------------------------------------- -- cgit v1.2.3-24-g4f1b From 5808346898ec9c602893fc54540958a8c556be29 Mon Sep 17 00:00:00 2001 From: admin Date: Sun, 24 Sep 2006 17:58:27 +0000 Subject: --- system/drivers/DB_active_record.php | 2 +- system/drivers/DB_driver.php | 8 ++++---- system/libraries/Controller.php | 6 +++--- 3 files changed, 8 insertions(+), 8 deletions(-) (limited to 'system') diff --git a/system/drivers/DB_active_record.php b/system/drivers/DB_active_record.php index af12d9d27..c038185bc 100644 --- a/system/drivers/DB_active_record.php +++ b/system/drivers/DB_active_record.php @@ -24,7 +24,7 @@ * @subpackage Drivers * @category Database * @author Rick Ellis - * @link http://www.codeigniter.com/user_guide/libraries/database/ + * @link http://www.codeigniter.com/user_guide/database/ */ class CI_DB_active_record extends CI_DB_driver { diff --git a/system/drivers/DB_driver.php b/system/drivers/DB_driver.php index a1ec14b06..48f7c4a9a 100644 --- a/system/drivers/DB_driver.php +++ b/system/drivers/DB_driver.php @@ -26,7 +26,7 @@ * @subpackage Drivers * @category Database * @author Rick Ellis - * @link http://www.codeigniter.com/user_guide/libraries/database/ + * @link http://www.codeigniter.com/user_guide/database/ */ class CI_DB_driver { @@ -625,7 +625,7 @@ class CI_DB_driver { } return $this->_field_data($this->dbprefix.$table); - } + } // -------------------------------------------------------------------- @@ -806,7 +806,7 @@ class CI_DB_driver { if ( ! class_exists('CI_Exceptions')) { - include_once(BASEPATH.'libraries/Exceptions.php'); + include_once(BASEPATH.'libraries/Exceptions'.EXT); } $error = new CI_Exceptions(); @@ -827,7 +827,7 @@ class CI_DB_driver { * * @category Database * @author Rick Ellis - * @link http://www.codeigniter.com/user_guide/libraries/database/ + * @link http://www.codeigniter.com/user_guide/database/ */ class CI_DB_result { diff --git a/system/libraries/Controller.php b/system/libraries/Controller.php index 0dd6ee6a4..5be10500b 100644 --- a/system/libraries/Controller.php +++ b/system/libraries/Controller.php @@ -362,11 +362,11 @@ class Controller extends CI_Base { $params['active_r'] = TRUE; } - require_once(BASEPATH.'drivers/DB_driver'.EXT); + require_once(BASEPATH.'database/DB_driver'.EXT); if ( ! isset($params['active_r']) OR $params['active_r'] == TRUE) { - require_once(BASEPATH.'drivers/DB_active_record'.EXT); + require_once(BASEPATH.'database/DB_active_record'.EXT); if ( ! class_exists('CI_DB')) { @@ -381,7 +381,7 @@ class Controller extends CI_Base { } } - require_once(BASEPATH.'drivers/DB_'.$params['dbdriver'].EXT); + require_once(BASEPATH.'database/drivers/'.$params['dbdriver'].'/'.$params['dbdriver'].EXT); // Instantiate the DB adapter $driver = 'CI_DB_'. $params['dbdriver']; -- cgit v1.2.3-24-g4f1b From 7b613c7000a496fe0e4f9152ee8937d06eba2301 Mon Sep 17 00:00:00 2001 From: admin Date: Sun, 24 Sep 2006 18:05:17 +0000 Subject: Adding database folder --- system/database/DB_active_record.php | 875 +++++++++++++++++++++ system/database/DB_driver.php | 578 ++++++++++++++ system/database/DB_result.php | 286 +++++++ system/database/DB_utility.php | 282 +++++++ system/database/drivers/index.html | 15 + system/database/drivers/mssql/mssql.php | 457 +++++++++++ system/database/drivers/mssql/mssql_result.php | 129 +++ system/database/drivers/mssql/mssql_utility.php | 41 + system/database/drivers/mysql/mysql.php | 478 +++++++++++ system/database/drivers/mysql/mysql_result.php | 129 +++ system/database/drivers/mysql/mysql_utility.php | 41 + system/database/drivers/mysqli/mysqli.php | 479 +++++++++++ system/database/drivers/mysqli/mysqli_result.php | 129 +++ system/database/drivers/mysqli/mysqli_utility.php | 41 + system/database/drivers/oci8/oci8.php | 608 ++++++++++++++ system/database/drivers/oci8/oci8_result.php | 207 +++++ system/database/drivers/oci8/oci8_utility.php | 41 + system/database/drivers/odbc/odbc.php | 454 +++++++++++ system/database/drivers/odbc/odbc_result.php | 190 +++++ system/database/drivers/odbc/odbc_utility.php | 41 + system/database/drivers/postgre/postgre.php | 484 ++++++++++++ system/database/drivers/postgre/postgre_result.php | 129 +++ .../database/drivers/postgre/postgre_utility.php | 41 + system/database/drivers/sqlite/sqlite.php | 481 +++++++++++ system/database/drivers/sqlite/sqlite_result.php | 132 ++++ system/database/drivers/sqlite/sqlite_utility.php | 41 + system/database/index.html | 15 + 27 files changed, 6824 insertions(+) create mode 100644 system/database/DB_active_record.php create mode 100644 system/database/DB_driver.php create mode 100644 system/database/DB_result.php create mode 100644 system/database/DB_utility.php create mode 100644 system/database/drivers/index.html create mode 100644 system/database/drivers/mssql/mssql.php create mode 100644 system/database/drivers/mssql/mssql_result.php create mode 100644 system/database/drivers/mssql/mssql_utility.php create mode 100644 system/database/drivers/mysql/mysql.php create mode 100644 system/database/drivers/mysql/mysql_result.php create mode 100644 system/database/drivers/mysql/mysql_utility.php create mode 100644 system/database/drivers/mysqli/mysqli.php create mode 100644 system/database/drivers/mysqli/mysqli_result.php create mode 100644 system/database/drivers/mysqli/mysqli_utility.php create mode 100644 system/database/drivers/oci8/oci8.php create mode 100644 system/database/drivers/oci8/oci8_result.php create mode 100644 system/database/drivers/oci8/oci8_utility.php create mode 100644 system/database/drivers/odbc/odbc.php create mode 100644 system/database/drivers/odbc/odbc_result.php create mode 100644 system/database/drivers/odbc/odbc_utility.php create mode 100644 system/database/drivers/postgre/postgre.php create mode 100644 system/database/drivers/postgre/postgre_result.php create mode 100644 system/database/drivers/postgre/postgre_utility.php create mode 100644 system/database/drivers/sqlite/sqlite.php create mode 100644 system/database/drivers/sqlite/sqlite_result.php create mode 100644 system/database/drivers/sqlite/sqlite_utility.php create mode 100644 system/database/index.html (limited to 'system') diff --git a/system/database/DB_active_record.php b/system/database/DB_active_record.php new file mode 100644 index 000000000..c038185bc --- /dev/null +++ b/system/database/DB_active_record.php @@ -0,0 +1,875 @@ +ar_select[] = $val; + } + return $this; + } + + // -------------------------------------------------------------------- + + /** + * DISTINCT + * + * Sets a flag which tells the query string compiler to add DISTINCT + * + * @access public + * @param bool + * @return object + */ + function distinct($val = TRUE) + { + $this->ar_distinct = (is_bool($val)) ? $val : TRUE; + return $this; + } + + // -------------------------------------------------------------------- + + /** + * From + * + * Generates the FROM portion of the query + * + * @access public + * @param mixed can be a string or array + * @return object + */ + function from($from) + { + foreach ((array)$from as $val) + { + $this->ar_from[] = $this->dbprefix.$val; + } + return $this; + } + + // -------------------------------------------------------------------- + + /** + * Join + * + * Generates the JOIN portion of the query + * + * @access public + * @param string + * @param string the join condition + * @param string the type of join + * @return object + */ + 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 .= ' '; + } + } + + $this->ar_join[] = $type.'JOIN '.$table.' ON '.$cond; + return $this; + } + + // -------------------------------------------------------------------- + + /** + * Where + * + * Generates the WHERE portion of the query. Separates + * multiple calls with AND + * + * @access public + * @param mixed + * @param mixed + * @return object + */ + function where($key, $value = NULL) + { + return $this->_where($key, $value, 'AND '); + } + + // -------------------------------------------------------------------- + + /** + * OR Where + * + * Generates the WHERE portion of the query. Separates + * multiple calls with OR + * + * @access public + * @param mixed + * @param mixed + * @return object + */ + function orwhere($key, $value = NULL) + { + return $this->_where($key, $value, 'OR '); + } + + // -------------------------------------------------------------------- + + /** + * Where + * + * Called by where() or orwhere() + * + * @access private + * @param mixed + * @param mixed + * @param string + * @return object + */ + function _where($key, $value = NULL, $type = 'AND ') + { + if ( ! is_array($key)) + { + $key = array($key => $value); + } + + foreach ($key as $k => $v) + { + $prefix = (count($this->ar_where) == 0) ? '' : $type; + + if ( ! is_null($v)) + { + if ( ! $this->_has_operator($k)) + { + $k .= ' ='; + } + + $v = ' '.$this->escape($v); + } + + $this->ar_where[] = $prefix.$k.$v; + } + return $this; + } + + + + // -------------------------------------------------------------------- + + /** + * Like + * + * Generates a %LIKE% portion of the query. Separates + * multiple calls with AND + * + * @access public + * @param mixed + * @param mixed + * @return object + */ + function like($field, $match = '') + { + return $this->_like($field, $match, 'AND '); + } + + // -------------------------------------------------------------------- + + /** + * OR Like + * + * Generates a %LIKE% portion of the query. Separates + * multiple calls with OR + * + * @access public + * @param mixed + * @param mixed + * @return object + */ + function orlike($field, $match = '') + { + return $this->_like($field, $match, 'OR '); + } + + // -------------------------------------------------------------------- + + /** + * Like + * + * Called by like() or orlike() + * + * @access private + * @param mixed + * @param mixed + * @param string + * @return object + */ + function _like($field, $match = '', $type = 'AND ') + { + if ( ! is_array($field)) + { + $field = array($field => $match); + } + + foreach ($field as $k => $v) + { + $prefix = (count($this->ar_like) == 0) ? '' : $type; + + $v = $this->escape_str($v); + + $this->ar_like[] = $prefix." $k LIKE '%{$v}%'"; + } + return $this; + } + + // -------------------------------------------------------------------- + + /** + * GROUP BY + * + * @access public + * @param string + * @return object + */ + function groupby($by) + { + if (is_string($by)) + { + $by = explode(',', $by); + } + + foreach ($by as $val) + { + $val = trim($val); + + if ($val != '') + $this->ar_groupby[] = $val; + } + return $this; + } + + // -------------------------------------------------------------------- + + /** + * Sets the HAVING value + * + * Separates multiple calls with AND + * + * @access public + * @param string + * @param string + * @return object + */ + function having($key, $value = '') + { + return $this->_having($key, $value, 'AND '); + } + + // -------------------------------------------------------------------- + + /** + * Sets the OR HAVING value + * + * Separates multiple calls with OR + * + * @access public + * @param string + * @param string + * @return object + */ + function orhaving($key, $value = '') + { + return $this->_having($key, $value, 'OR '); + } + + // -------------------------------------------------------------------- + + /** + * Sets the HAVING values + * + * Called by having() or orhaving() + * + * @access private + * @param string + * @param string + * @return object + */ + function _having($key, $value = '', $type = 'AND ') + { + if ( ! is_array($key)) + { + $key = array($key => $value); + } + + foreach ($key as $k => $v) + { + $prefix = (count($this->ar_having) == 0) ? '' : $type; + + if ($v != '') + { + $v = ' '.$this->escape($v); + } + + $this->ar_having[] = $prefix.$k.$v; + } + return $this; + } + + // -------------------------------------------------------------------- + + /** + * Sets the ORDER BY value + * + * @access public + * @param string + * @param string direction: asc or desc + * @return object + */ + function orderby($orderby, $direction = '') + { + if (trim($direction) != '') + { + $direction = (in_array(strtoupper(trim($direction)), array('ASC', 'DESC', 'RAND()'))) ? ' '.$direction : ' ASC'; + } + + $this->ar_orderby[] = $orderby.$direction; + return $this; + } + + // -------------------------------------------------------------------- + + /** + * Sets the LIMIT value + * + * @access public + * @param integer the limit value + * @param integer the offset value + * @return object + */ + function limit($value, $offset = '') + { + $this->ar_limit = $value; + + if ($offset != '') + $this->ar_offset = $offset; + + return $this; + } + + // -------------------------------------------------------------------- + + /** + * Sets the OFFSET value + * + * @access public + * @param integer the offset value + * @return object + */ + function offset($value) + { + $this->ar_offset = $value; + return $this; + } + + // -------------------------------------------------------------------- + + /** + * The "set" function. Allows key/value pairs to be set for inserting or updating + * + * @access public + * @param mixed + * @param string + * @return object + */ + function set($key, $value = '') + { + $key = $this->_object_to_array($key); + + if ( ! is_array($key)) + { + $key = array($key => $value); + } + + foreach ($key as $k => $v) + { + $this->ar_set[$k] = $this->escape($v); + } + + return $this; + } + + // -------------------------------------------------------------------- + + /** + * Get + * + * Compiles the select statement based on the other functions called + * and runs the query + * + * @access public + * @param string the limit clause + * @param string the offset clause + * @return object + */ + function get($table = '', $limit = null, $offset = null) + { + if ($table != '') + { + $this->from($table); + } + + if ( ! is_null($limit)) + { + $this->limit($limit, $offset); + } + + $sql = $this->_compile_select(); + + $this->_reset_select(); + return $this->query($sql); + } + + // -------------------------------------------------------------------- + + /** + * GetWhere + * + * Allows the where clause, limit and offset to be added directly + * + * @access public + * @param string the where clause + * @param string the limit clause + * @param string the offset clause + * @return object + */ + function getwhere($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(); + + $this->_reset_select(); + return $this->query($sql); + } + + // -------------------------------------------------------------------- + + /** + * Insert + * + * Compiles an insert string and runs the query + * + * @access public + * @param string the table to retrieve the results from + * @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->dbprefix.$table, 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 + * + * @access public + * @param string the table to retrieve the results from + * @param array an associative array of update values + * @param mixed the where clause + * @return object + */ + function update($table = '', $set = NULL, $where = 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]; + } + + if ($where != null) + { + $this->where($where); + } + + $sql = $this->_update($this->dbprefix.$table, $this->ar_set, $this->ar_where); + + $this->_reset_write(); + return $this->query($sql); + } + + // -------------------------------------------------------------------- + + /** + * Delete + * + * Compiles a delete string and runs the query + * + * @access public + * @param string the table to retrieve the results from + * @param mixed the where clause + * @return object + */ + function delete($table = '', $where = '') + { + 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 != '') + { + $this->where($where); + } + + if (count($this->ar_where) == 0) + { + if ($this->db_debug) + { + return $this->display_error('db_del_must_use_where'); + } + return FALSE; + } + + $sql = $this->_delete($this->dbprefix.$table, $this->ar_where); + + $this->_reset_write(); + return $this->query($sql); + } + + // -------------------------------------------------------------------- + + /** + * Use Table - DEPRECATED + * + * @deprecated use $this->db->from instead + */ + function use_table($table) + { + return $this->from($table); + return $this; + } + + // -------------------------------------------------------------------- + + /** + * ORDER BY - DEPRECATED + * + * @deprecated use $this->db->orderby() instead + */ + function order_by($orderby, $direction = '') + { + return $this->orderby($orderby, $direction); + } + + // -------------------------------------------------------------------- + + /** + * 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; + } + + // -------------------------------------------------------------------- + + /** + * Compile the SELECT statement + * + * Generates a query string based on which functions were used. + * Should not be called directly. The get() function calls it. + * + * @access private + * @return string + */ + function _compile_select() + { + $sql = ( ! $this->ar_distinct) ? 'SELECT ' : 'SELECT DISTINCT '; + + $sql .= (count($this->ar_select) == 0) ? '*' : implode(', ', $this->ar_select); + + if (count($this->ar_from) > 0) + { + $sql .= "\nFROM "; + $sql .= implode(', ', $this->ar_from); + } + + if (count($this->ar_join) > 0) + { + $sql .= "\n"; + $sql .= implode("\n", $this->ar_join); + } + + if (count($this->ar_where) > 0 OR count($this->ar_like) > 0) + { + $sql .= "\nWHERE "; + } + + $sql .= implode("\n", $this->ar_where); + + if (count($this->ar_like) > 0) + { + if (count($this->ar_where) > 0) + { + $sql .= " AND "; + } + + $sql .= implode("\n", $this->ar_like); + } + + if (count($this->ar_groupby) > 0) + { + $sql .= "\nGROUP BY "; + $sql .= implode(', ', $this->ar_groupby); + } + + if (count($this->ar_having) > 0) + { + $sql .= "\nHAVING "; + $sql .= implode("\n", $this->ar_having); + } + + 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'; + } + } + + 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 convers the class variables to array key/vals + * + * @access public + * @param object + * @return array + */ + function _object_to_array($object) + { + if ( ! is_object($object)) + { + return $object; + } + + $array = array(); + foreach (get_object_vars($object) as $key => $val) + { + if ( ! is_object($val) AND ! is_array($val)) + { + $array[$key] = $val; + } + } + + return $array; + } + + // -------------------------------------------------------------------- + + /** + * Resets the active record values. Called by the get() function + * + * @access private + * @return void + */ + function _reset_select() + { + $this->ar_select = array(); + $this->ar_distinct = FALSE; + $this->ar_from = array(); + $this->ar_join = array(); + $this->ar_where = array(); + $this->ar_like = array(); + $this->ar_groupby = array(); + $this->ar_having = array(); + $this->ar_limit = FALSE; + $this->ar_offset = FALSE; + $this->ar_order = FALSE; + $this->ar_orderby = array(); + } + + // -------------------------------------------------------------------- + + /** + * Resets the active record "write" values. + * + * Called by the insert() or update() functions + * + * @access private + * @return void + */ + function _reset_write() + { + $this->ar_set = array(); + $this->ar_from = array(); + $this->ar_where = array(); + } + +} + +?> \ No newline at end of file diff --git a/system/database/DB_driver.php b/system/database/DB_driver.php new file mode 100644 index 000000000..ef37967dc --- /dev/null +++ b/system/database/DB_driver.php @@ -0,0 +1,578 @@ +initialize($params); + log_message('debug', 'Database Driver Class Initialized'); + } + + // -------------------------------------------------------------------- + + /** + * Initialize Database Settings + * + * @access private Called by the constructor + * @param mixed + * @return void + */ + function initialize($params = '') + { + if (is_array($params)) + { + foreach (array('hostname' => '', 'username' => '', 'password' => '', 'database' => '', 'dbdriver' => 'mysql', 'dbprefix' => '', 'port' => '', 'pconnect' => FALSE, 'db_debug' => FALSE) as $key => $val) + { + $this->$key = ( ! isset($params[$key])) ? $val : $params[$key]; + } + } + elseif (strpos($params, '://')) + { + if (FALSE === ($dsn = @parse_url($params))) + { + log_message('error', 'Invalid DB Connection String'); + + if ($this->db_debug) + { + return $this->display_error('db_invalid_connection_str'); + } + return FALSE; + } + + $this->hostname = ( ! isset($dsn['host'])) ? '' : rawurldecode($dsn['host']); + $this->username = ( ! isset($dsn['user'])) ? '' : rawurldecode($dsn['user']); + $this->password = ( ! isset($dsn['pass'])) ? '' : rawurldecode($dsn['pass']); + $this->database = ( ! isset($dsn['path'])) ? '' : rawurldecode(substr($dsn['path'], 1)); + } + + if ($this->pconnect == FALSE) + { + $this->conn_id = $this->db_connect(); + } + else + { + $this->conn_id = $this->db_pconnect(); + } + + if ( ! $this->conn_id) + { + log_message('error', 'Unable to connect to the database'); + + if ($this->db_debug) + { + $this->display_error('db_unable_to_connect'); + } + } + else + { + 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); + } + } + } + } + + + // -------------------------------------------------------------------- + + /** + * 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; + } + + // Compile binds if needed + if ($binds !== FALSE) + { + $sql = $this->compile_binds($sql, $binds); + } + + // Save the query for debugging + $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))) + { + // This will trigger a rollback if transactions are being used + $this->_trans_failure = TRUE; + + if ($this->db_debug) + { + log_message('error', 'Query error: '.$this->error_message()); + return $this->display_error( + array( + 'Error Number: '.$this->error_number(), + $this->error_message(), + $sql + ) + ); + } + + return FALSE; + } + + // Stop and aggregate the query time results + $time_end = list($em, $es) = explode(' ', microtime()); + $this->benchmark += ($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) + { + 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; + } + + // Define the result driver name + $result = 'CI_DB_'.$this->dbdriver.'_result'; + + // Load the result classes + if ( ! class_exists($result)) + { + include_once(BASEPATH.'database/DB_result'.EXT); + include_once(BASEPATH.'database/drivers/'.$this->dbdriver.'/'.$this->dbdriver.'_result'.EXT); + } + + // Instantiate the result object + $RES = new $result(); + $RES->conn_id = $this->conn_id; + $RES->db_debug = $this->db_debug; + $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; + } + + return $RES; + } + + // -------------------------------------------------------------------- + + /** + * Simple Query + * This is a simiplified 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, $this->conn_id); + } + + // -------------------------------------------------------------------- + + /** + * Disable Transactions + * This permits transactions to be disabled at run-time. + * + * @access public + * @return void + */ + function trans_off() + { + $this->trans_enabled = FALSE; + } + + // -------------------------------------------------------------------- + + /** + * 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 TRUE in the event that a query failed + if ($this->_trans_failure === TRUE) + { + $this->trans_rollback(); + + if ($this->db_debug) + { + return $this->display_error('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_failure; + } + + // -------------------------------------------------------------------- + + /** + * Compile Bindings + * + * @access public + * @param string the sql statement + * @param array an array of bind data + * @return string + */ + function compile_binds($sql, $binds) + { + if (FALSE === strpos($sql, $this->bind_marker)) + { + return $sql; + } + + if ( ! is_array($binds)) + { + $binds = array($binds); + } + + foreach ($binds as $val) + { + $val = $this->escape($val); + + // Just in case the replacement string contains the bind + // character we'll temporarily replace it with a marker + $val = str_replace($this->bind_marker, '{%bind_marker%}', $val); + $sql = preg_replace("#".preg_quote($this->bind_marker, '#')."#", str_replace('$', '\$', $val), $sql, 1); + } + + return str_replace('{%bind_marker%}', $this->bind_marker, $sql); + } + + // -------------------------------------------------------------------- + + /** + * 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*"?(INSERT|UPDATE|DELETE|REPLACE|CREATE|DROP|LOAD DATA|COPY|ALTER|GRANT|REVOKE|LOCK|UNLOCK)\s+/i', $sql)) + { + return FALSE; + } + return TRUE; + } + + // -------------------------------------------------------------------- + + /** + * Calculate the aggregate query elapsed time + * + * @access public + * @param intiger 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 integer + */ + function escape($str) + { + switch (gettype($str)) + { + case 'string' : $str = "'".$this->escape_str($str)."'"; + break; + case 'boolean' : $str = ($str === FALSE) ? 0 : 1; + break; + default : $str = ($str === NULL) ? 'NULL' : $str; + break; + } + + return $str; + } + + // -------------------------------------------------------------------- + + /** + * 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_shift(func_get_args()) : null; + + return call_user_func_array($function, $args); + } + } + + // -------------------------------------------------------------------- + + /** + * Close DB Connection + * + * @access public + * @return void + */ + function close() + { + if (is_resource($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/errror_db.php template + */ + function display_error($error = '', $swap = '', $native = FALSE) + { + $LANG = new CI_Language(); + $LANG->load('db'); + + $heading = 'MySQL Error'; + + if ($native == TRUE) + { + $message = $error; + } + else + { + $message = ( ! is_array($error)) ? array(str_replace('%s', $swap, $LANG->line($error))) : $error; + } + + if ( ! class_exists('CI_Exceptions')) + { + include_once(BASEPATH.'libraries/Exceptions'.EXT); + } + + $error = new CI_Exceptions(); + echo $error->show_error('An Error Was Encountered', $message, 'error_db'); + exit; + + } + +} + +?> \ No newline at end of file diff --git a/system/database/DB_result.php b/system/database/DB_result.php new file mode 100644 index 000000000..abb6b588b --- /dev/null +++ b/system/database/DB_result.php @@ -0,0 +1,286 @@ +result_object() : $this->result_array(); + } + + // -------------------------------------------------------------------- + + /** + * Query result. "object" version. + * + * @access public + * @return object + */ + function result_object() + { + if (count($this->result_object) > 0) + { + return $this->result_object; + } + + while ($row = $this->_fetch_object()) + { + $this->result_object[] = $row; + } + + if (count($this->result_object) == 0) + { + return FALSE; + } + + return $this->result_object; + } + + // -------------------------------------------------------------------- + + /** + * Query result. "array" version. + * + * @access public + * @return array + */ + function result_array() + { + if (count($this->result_array) > 0) + { + return $this->result_array; + } + + while ($row = $this->_fetch_assoc()) + { + $this->result_array[] = $row; + } + + if (count($this->result_array) == 0) + { + return FALSE; + } + + return $this->result_array; + } + + // -------------------------------------------------------------------- + + /** + * Query result. Acts as a wrapper function for the following functions. + * + * @access public + * @param string can be "object" or "array" + * @return mixed either a result object or array + */ + function row($n = 0, $type = 'object') + { + return ($type == 'object') ? $this->row_object($n) : $this->row_array($n); + } + + // -------------------------------------------------------------------- + + /** + * Returns a single result row - object version + * + * @access public + * @return object + */ + function row_object($n = 0) + { + if (FALSE === ($result = $this->result_object())) + { + return FALSE; + } + + 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 + */ + function row_array($n = 0) + { + if (FALSE === ($result = $this->result_array())) + { + return FALSE; + } + + 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 + */ + function first_row($type = 'object') + { + if (FALSE === ($result = $this->result($type))) + { + return FALSE; + } + return $result[0]; + } + + // -------------------------------------------------------------------- + + /** + * Returns the "last" row + * + * @access public + * @return object + */ + function last_row($type = 'object') + { + if (FALSE === ($result = $this->result($type))) + { + return FALSE; + } + return $result[count($result) -1]; + } + + // -------------------------------------------------------------------- + + /** + * Returns the "next" row + * + * @access public + * @return object + */ + function next_row($type = 'object') + { + if (FALSE === ($result = $this->result($type))) + { + return FALSE; + } + + if (isset($result[$this->current_row + 1])) + { + ++$this->current_row; + } + + return $result[$this->current_row]; + } + + // -------------------------------------------------------------------- + + /** + * Returns the "previous" row + * + * @access public + * @return object + */ + function previous_row($type = 'object') + { + if (FALSE === ($result = $this->result($type))) + { + return FALSE; + } + + if (isset($result[$this->current_row - 1])) + { + --$this->current_row; + } + return $result[$this->current_row]; + } + + /** + * Number of rows in the result set + * + * @access public + * @return integer + */ + function num_rows() + { + // Result supplied by the result adaptor class + } + + // -------------------------------------------------------------------- + + /** + * Number of fields in the result set + * + * @access public + * @return integer + */ + function num_fields() + { + // Result supplied by the result adaptor class + } + + // -------------------------------------------------------------------- + + /** + * Field data + * + * Generates an array of objects containing field meta-data + * + * @access public + * @return array + */ + function field_data() + { + // Result supplied by the result adaptor class + } +} + +?> \ No newline at end of file diff --git a/system/database/DB_utility.php b/system/database/DB_utility.php new file mode 100644 index 000000000..a4d4eb0d1 --- /dev/null +++ b/system/database/DB_utility.php @@ -0,0 +1,282 @@ +_version())) + { + if ($this->db_debug) + { + return $this->display_error('db_unsupported_function'); + } + return FALSE; + } + + if ($this->dbdriver == 'oci8') + { + return $sql; + } + + $query = $this->query($sql); + $row = $query->row(); + return $row->ver; + } + + // -------------------------------------------------------------------- + + /** + * Returns an array of table names + * + * @access public + * @return array + */ + function tables() + { + if (FALSE === ($sql = $this->_show_tables())) + { + 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); + } + } + } + + return $retval; + } + + // -------------------------------------------------------------------- + + /** + * Determine if a particular table exists + * @access public + * @return boolean + */ + function table_exists($table_name) + { + return ( ! in_array($this->dbprefix.$table_name, $this->tables())) ? FALSE : TRUE; + } + + // -------------------------------------------------------------------- + + /** + * Fetch MySQL Field Names + * + * @access public + * @param string the table name + * @return array + */ + function field_names($table = '') + { + if ($table == '') + { + if ($this->db_debug) + { + return $this->display_error('db_field_param_missing'); + } + return FALSE; + } + + if (FALSE === ($sql = $this->_show_columns($this->dbprefix.$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); + } + } + + return $retval; + } + + // -------------------------------------------------------------------- + + /** + * 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; + } + + return $this->_field_data($this->dbprefix.$table); + } + + // -------------------------------------------------------------------- + + /** + * 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->field_names($table); + + if ( ! is_array($fields)) + { + return FALSE; + } + + return current($fields); + } + + // -------------------------------------------------------------------- + + /** + * 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[] = $key; + $values[] = $this->escape($val); + } + + return $this->_insert($this->dbprefix.$table, $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[$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->dbprefix.$table, $fields, $dest); + } + + +} + +?> \ No newline at end of file diff --git a/system/database/drivers/index.html b/system/database/drivers/index.html new file mode 100644 index 000000000..5a1f5d6ae --- /dev/null +++ b/system/database/drivers/index.html @@ -0,0 +1,15 @@ + + + + +403 Forbidden + + + + + +

Directory access is forbidden.

+ + + + \ No newline at end of file diff --git a/system/database/drivers/mssql/mssql.php b/system/database/drivers/mssql/mssql.php new file mode 100644 index 000000000..5f30bf905 --- /dev/null +++ b/system/database/drivers/mssql/mssql.php @@ -0,0 +1,457 @@ +hostname, $this->username, $this->password); + } + + // -------------------------------------------------------------------- + + /** + * Persistent database connection + * + * @access private called by the base class + * @return resource + */ + function db_pconnect() + { + return mssql_pconnect($this->hostname, $this->username, $this->password); + } + + // -------------------------------------------------------------------- + + /** + * Select the database + * + * @access private called by the base class + * @return resource + */ + function db_select() + { + return @mssql_select_db($this->database, $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 @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 + * @return string + */ + function escape_str($str) + { + // Escape single quotes + return str_replace("'", "''", $str); + } + + // -------------------------------------------------------------------- + + /** + * Affected Rows + * + * @access public + * @return integer + */ + function affected_rows() + { + return @mssql_rows_affected($this->conn_id); + } + + // -------------------------------------------------------------------- + + /** + * Insert ID + * + * @access public + * @return integer + */ + function insert_id() + { + // Not supported in MS SQL? + return 0; + } + + // -------------------------------------------------------------------- + + /** + * "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("SELECT COUNT(*) AS numrows FROM `".$this->dbprefix.$table."`"); + + if ($query->num_rows() == 0) + return '0'; + + $row = $query->row(); + return $row->numrows; + } + + // -------------------------------------------------------------------- + + /** + * The error message string + * + * @access public + * @return string + */ + function error_message() + { + // Are errros even supported in MS SQL? + return ''; + } + + // -------------------------------------------------------------------- + + /** + * The error message number + * + * @access public + * @return integer + */ + function error_number() + { + // Are error numbers supported? + return ''; + } + + // -------------------------------------------------------------------- + + /** + * 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 public + * @param string the table name + * @return string + */ + function escape_table($table) + { + if (stristr($table, '.')) + { + $table = preg_replace("/\./", "`.`", $table); + } + + return $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) + { + $sql = "SELECT TOP 1 FROM ".$this->escape_table($table); + $query = $this->query($sql); + return $query->field_data(); + } + + // -------------------------------------------------------------------- + + /** + * 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 + * @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); + } + + // -------------------------------------------------------------------- + + /** + * Delete statement + * + * Generates a platform-specific delete string from the supplied data + * + * @access public + * @param string the table name + * @param array the where clause + * @return string + */ + function _delete($table, $where) + { + return "DELETE FROM ".$this->escape_table($table)." WHERE ".implode(" ", $where); + } + + // -------------------------------------------------------------------- + + /** + * Version number query string + * + * @access public + * @return string + */ + function _version() + { + return "SELECT version() AS ver"; + } + + // -------------------------------------------------------------------- + + /** + * Show table query + * + * Generates a platform-specific query string so that the table names can be fetched + * + * @access public + * @return string + */ + function _show_tables() + { + return "SELECT name FROM sysobjects WHERE type = 'U' ORDER BY name"; + } + + // -------------------------------------------------------------------- + + /** + * Show columnn 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 _show_columns($table = '') + { + return "SELECT * FROM INFORMATION_SCHEMA.Columns WHERE TABLE_NAME = '".$this->escape_table($table)."'"; + } + + // -------------------------------------------------------------------- + + /** + * 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); + } + + +} + + +?> \ No newline at end of file diff --git a/system/database/drivers/mssql/mssql_result.php b/system/database/drivers/mssql/mssql_result.php new file mode 100644 index 000000000..a8a8e2006 --- /dev/null +++ b/system/database/drivers/mssql/mssql_result.php @@ -0,0 +1,129 @@ +result_id); + } + + // -------------------------------------------------------------------- + + /** + * Number of fields in the result set + * + * @access public + * @return integer + */ + function num_fields() + { + return @mssql_num_fields($this->result_id); + } + + // -------------------------------------------------------------------- + + /** + * 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; + } + } + + // -------------------------------------------------------------------- + + /** + * 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); + } + +} + +?> \ No newline at end of file diff --git a/system/database/drivers/mssql/mssql_utility.php b/system/database/drivers/mssql/mssql_utility.php new file mode 100644 index 000000000..a76e1f14f --- /dev/null +++ b/system/database/drivers/mssql/mssql_utility.php @@ -0,0 +1,41 @@ + \ No newline at end of file diff --git a/system/database/drivers/mysql/mysql.php b/system/database/drivers/mysql/mysql.php new file mode 100644 index 000000000..4d59f784d --- /dev/null +++ b/system/database/drivers/mysql/mysql.php @@ -0,0 +1,478 @@ +hostname, $this->username, $this->password, TRUE); + } + + // -------------------------------------------------------------------- + + /** + * Persistent database connection + * + * @access private called by the base class + * @return resource + */ + function db_pconnect() + { + return mysql_pconnect($this->hostname, $this->username, $this->password); + } + + // -------------------------------------------------------------------- + + /** + * Select the database + * + * @access private called by the base class + * @return resource + */ + function db_select() + { + return @mysql_select_db($this->database, $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 @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 + * @return string + */ + function escape_str($str) + { + return mysql_real_escape_string($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("SELECT COUNT(*) AS numrows FROM `".$this->dbprefix.$table."`"); + + if ($query->num_rows() == 0) + return '0'; + + $row = $query->row(); + return $row->numrows; + } + + // -------------------------------------------------------------------- + + /** + * The error message string + * + * @access public + * @return string + */ + function error_message() + { + return mysql_error($this->conn_id); + } + + // -------------------------------------------------------------------- + + /** + * The error message number + * + * @access public + * @return integer + */ + function error_number() + { + return mysql_errno($this->conn_id); + } + + // -------------------------------------------------------------------- + + /** + * 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 public + * @param string the table name + * @return string + */ + function escape_table($table) + { + if (stristr($table, '.')) + { + $table = preg_replace("/\./", "`.`", $table); + } + + return $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) + { + $sql = "SELECT * FROM ".$this->escape_table($table)." LIMIT 1"; + $query = $this->query($sql); + return $query->field_data(); + } + + // -------------------------------------------------------------------- + + /** + * 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 + * @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); + } + + // -------------------------------------------------------------------- + + /** + * Delete statement + * + * Generates a platform-specific delete string from the supplied data + * + * @access public + * @param string the table name + * @param array the where clause + * @return string + */ + function _delete($table, $where) + { + return "DELETE FROM ".$this->escape_table($table)." WHERE ".implode(" ", $where); + } + + // -------------------------------------------------------------------- + + /** + * Version number query string + * + * @access public + * @return string + */ + function _version() + { + return "SELECT version() AS ver"; + } + + // -------------------------------------------------------------------- + + /** + * Show table query + * + * Generates a platform-specific query string so that the table names can be fetched + * + * @access public + * @return string + */ + function _show_tables() + { + return "SHOW TABLES FROM `".$this->database."`"; + } + + // -------------------------------------------------------------------- + + /** + * Show columnn 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 _show_columns($table = '') + { + return "SHOW COLUMNS FROM ".$this->escape_table($table); + } + + // -------------------------------------------------------------------- + + /** + * 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); + } + +} + +?> \ No newline at end of file diff --git a/system/database/drivers/mysql/mysql_result.php b/system/database/drivers/mysql/mysql_result.php new file mode 100644 index 000000000..e540489bb --- /dev/null +++ b/system/database/drivers/mysql/mysql_result.php @@ -0,0 +1,129 @@ +result_id); + } + + // -------------------------------------------------------------------- + + /** + * Number of fields in the result set + * + * @access public + * @return integer + */ + function num_fields() + { + return @mysql_num_fields($this->result_id); + } + + // -------------------------------------------------------------------- + + /** + * Field data + * + * Generates an array of objects containing field meta-data + * + * @access public + * @return array + */ + function field_data() + { + $retval = array(); + while ($field = mysql_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; + $F->primary_key = $field->primary_key; + + $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; + } + } + + // -------------------------------------------------------------------- + + /** + * 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); + } + +} + +?> \ No newline at end of file diff --git a/system/database/drivers/mysql/mysql_utility.php b/system/database/drivers/mysql/mysql_utility.php new file mode 100644 index 000000000..8dd764888 --- /dev/null +++ b/system/database/drivers/mysql/mysql_utility.php @@ -0,0 +1,41 @@ + \ No newline at end of file diff --git a/system/database/drivers/mysqli/mysqli.php b/system/database/drivers/mysqli/mysqli.php new file mode 100644 index 000000000..6ca21c976 --- /dev/null +++ b/system/database/drivers/mysqli/mysqli.php @@ -0,0 +1,479 @@ +hostname, $this->username, $this->password); + } + + // -------------------------------------------------------------------- + + /** + * Persistent database connection + * + * @access private called by the base class + * @return resource + */ + function db_pconnect() + { + return $this->db_connect(); + } + + // -------------------------------------------------------------------- + + /** + * Select the database + * + * @access private called by the base class + * @return resource + */ + function db_select() + { + return @mysqli_select_db($this->conn_id, $this->database); + } + + // -------------------------------------------------------------------- + + /** + * 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 + * @return string + */ + function escape_str($str) + { + return mysqli_real_escape_string($this->conn_id, $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("SELECT COUNT(*) AS numrows FROM `".$this->dbprefix.$table."`"); + + if ($query->num_rows() == 0) + return '0'; + + $row = $query->row(); + return $row->numrows; + } + + // -------------------------------------------------------------------- + + /** + * The error message string + * + * @access public + * @return string + */ + function error_message() + { + return mysqli_error($this->conn_id); + } + + // -------------------------------------------------------------------- + + /** + * The error message number + * + * @access public + * @return integer + */ + function error_number() + { + return mysqli_errno($this->conn_id); + } + + // -------------------------------------------------------------------- + + /** + * 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 public + * @param string the table name + * @return string + */ + function escape_table($table) + { + if (stristr($table, '.')) + { + $table = preg_replace("/\./", "`.`", $table); + } + + return $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) + { + $sql = "SELECT * FROM ".$this->escape_table($table)." LIMIT 1"; + $query = $this->query($sql); + return $query->field_data(); + } + + // -------------------------------------------------------------------- + + /** + * 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 + * @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); + } + + // -------------------------------------------------------------------- + + /** + * Delete statement + * + * Generates a platform-specific delete string from the supplied data + * + * @access public + * @param string the table name + * @param array the where clause + * @return string + */ + function _delete($table, $where) + { + return "DELETE FROM ".$this->escape_table($table)." WHERE ".implode(" ", $where); + } + + // -------------------------------------------------------------------- + + /** + * Version number query string + * + * @access public + * @return string + */ + function _version() + { + return "SELECT version() AS ver"; + } + + // -------------------------------------------------------------------- + + /** + * Show table query + * + * Generates a platform-specific query string so that the table names can be fetched + * + * @access public + * @return string + */ + function _show_tables() + { + return "SHOW TABLES FROM `".$this->database."`"; + } + + // -------------------------------------------------------------------- + + /** + * Show columnn 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 _show_columns($table = '') + { + return "SHOW COLUMNS FROM ".$this->escape_table($table); + } + + // -------------------------------------------------------------------- + + /** + * 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); + } + +} + +?> \ No newline at end of file diff --git a/system/database/drivers/mysqli/mysqli_result.php b/system/database/drivers/mysqli/mysqli_result.php new file mode 100644 index 000000000..b0db6c106 --- /dev/null +++ b/system/database/drivers/mysqli/mysqli_result.php @@ -0,0 +1,129 @@ +result_id); + } + + // -------------------------------------------------------------------- + + /** + * Number of fields in the result set + * + * @access public + * @return integer + */ + function num_fields() + { + return @mysqli_num_fields($this->result_id); + } + + // -------------------------------------------------------------------- + + /** + * Field data + * + * Generates an array of objects containing field meta-data + * + * @access public + * @return array + */ + function field_data() + { + $retval = array(); + while ($field = mysqli_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; + $F->primary_key = ($field->flags & MYSQLI_PRI_KEY_FLAG) ? 1 : 0; + + $retval[] = $F; + } + + return $retval; + } + + // -------------------------------------------------------------------- + + /** + * Free the result + * + * @return null + */ + function free_result() + { + if (is_resource($this->result_id)) + { + mysqli_free_result($this->result_id); + $this->result_id = FALSE; + } + } + + // -------------------------------------------------------------------- + + /** + * 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); + } + +} + +?> \ No newline at end of file diff --git a/system/database/drivers/mysqli/mysqli_utility.php b/system/database/drivers/mysqli/mysqli_utility.php new file mode 100644 index 000000000..02b423c30 --- /dev/null +++ b/system/database/drivers/mysqli/mysqli_utility.php @@ -0,0 +1,41 @@ + \ No newline at end of file diff --git a/system/database/drivers/oci8/oci8.php b/system/database/drivers/oci8/oci8.php new file mode 100644 index 000000000..40aabcea7 --- /dev/null +++ b/system/database/drivers/oci8/oci8.php @@ -0,0 +1,608 @@ +username, $this->password, $this->hostname); + } + + // -------------------------------------------------------------------- + + /** + * Persistent database connection + * + * @access private called by the base class + * @return resource + */ + function db_pconnect() + { + return ociplogon($this->username, $this->password, $this->hostname); + } + + // -------------------------------------------------------------------- + + /** + * Select the database + * + * @access private called by the base class + * @return resource + */ + function db_select() + { + return TRUE; + } + + // -------------------------------------------------------------------- + + /** + * Execute the query + * + * @access private called by the base class + * @param string an SQL query + * @return resource + */ + function _execute($sql) + { + // oracle must parse the query before it + // is run, all of the actions with + // the query are based off the statement id + // returned by ociparse + $this->_set_stmt_id($sql); + ocisetprefetch($this->stmt_id, 1000); + return @ociexecute($this->stmt_id, $this->_commit); + } + + /** + * Generate a statement ID + * + * @access private + * @param string an SQL query + * @return none + */ + function _set_stmt_id($sql) + { + if ( ! is_resource($this->stmt_id)) + { + $this->stmt_id = ociparse($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 + */ + function _prep_query($sql) + { + return $sql; + } + + // -------------------------------------------------------------------- + + /** + * getCursor. Returns a cursor from the datbase + * + * @access public + * @return cursor id + */ + function get_cursor() + { + return $this->curs_id = ocinewcursor($this->conn_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 + */ + 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 + */ + 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] = ''; + } + } + + ocibindbyname($this->stmt_id, $param['name'], $param['value'], $param['length'], $param['type']); + } + } + + // -------------------------------------------------------------------- + + /** + * 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->_commit = OCI_DEFAULT; + 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; + } + + $ret = OCIcommit($this->conn_id); + $this->_commit = OCI_COMMIT_ON_SUCCESS; + 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 = OCIrollback($this->conn_id); + $this->_commit = OCI_COMMIT_ON_SUCCESS; + return $ret; + } + + // -------------------------------------------------------------------- + + /** + * Escape String + * + * @access public + * @param string + * @return string + */ + function escape_str($str) + { + return $str; + } + + // -------------------------------------------------------------------- + + /** + * Affected Rows + * + * @access public + * @return integer + */ + function affected_rows() + { + return @ocirowcount($this->stmt_id); + } + + // -------------------------------------------------------------------- + + /** + * Insert ID + * + * @access public + * @return integer + */ + function insert_id() + { + // not supported in oracle + return 0; + } + + // -------------------------------------------------------------------- + + /** + * "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("SELECT COUNT(1) AS numrows FROM ".$table); + + if ($query == FALSE) + { + return 0; + } + + $row = $query->row(); + return $row->NUMROWS; + } + + // -------------------------------------------------------------------- + + /** + * The error message string + * + * @access public + * @return string + */ + function error_message() + { + $error = ocierror($this->conn_id); + return $error['message']; + } + + // -------------------------------------------------------------------- + + /** + * The error message number + * + * @access public + * @return integer + */ + function error_number() + { + $error = ocierror($this->conn_id); + return $error['code']; + } + + // -------------------------------------------------------------------- + + /** + * 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 public + * @param string the table name + * @return string + */ + function escape_table($table) + { + if (stristr($table, '.')) + { + $table = preg_replace("/\./", "`.`", $table); + } + + return $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) + { + $sql = "SELECT * FROM ".$this->escape_table($table)." where rownum = 1"; + $query = $this->query($sql); + return $query->field_data(); + } + + // -------------------------------------------------------------------- + + /** + * 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 + * @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); + } + + // -------------------------------------------------------------------- + + /** + * Delete statement + * + * Generates a platform-specific delete string from the supplied data + * + * @access public + * @param string the table name + * @param array the where clause + * @return string + */ + function _delete($table, $where) + { + return "DELETE FROM ".$this->escape_table($table)." WHERE ".implode(" ", $where); + } + + // -------------------------------------------------------------------- + + /** + * Version number query string + * + * @access public + * @return string + */ + function _version() + { + $ver = ociserverversion($this->conn_id); + return $ver; + } + + // -------------------------------------------------------------------- + + /** + * Show table query + * + * Generates a platform-specific query string so that the table names can be fetched + * + * @access public + * @return string + */ + function _show_tables() + { + return "select TABLE_NAME FROM ALL_TABLES"; + } + + // -------------------------------------------------------------------- + + /** + * Show columnn 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 _show_columns($table = '') + { + return "SELECT COLUMN_NAME FROM all_tab_columns WHERE table_name = '$table'"; + } + + // -------------------------------------------------------------------- + + /** + * 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) + { + $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 public + * @param resource + * @return void + */ + function _close($conn_id) + { + ocilogoff($conn_id); + } + +} + + +?> \ No newline at end of file diff --git a/system/database/drivers/oci8/oci8_result.php b/system/database/drivers/oci8/oci8_result.php new file mode 100644 index 000000000..d2354a1c6 --- /dev/null +++ b/system/database/drivers/oci8/oci8_result.php @@ -0,0 +1,207 @@ +result_array(); + $rowcount = count($this->result_array); + @ociexecute($this->stmt_id); + if ($this->curs_id) + { + @ociexecute($this->curs_id); + } + return $rowcount; + } + + // -------------------------------------------------------------------- + + /** + * Number of fields in the result set + * + * @access public + * @return integer + */ + function num_fields() + { + $count = @ocinumcols($this->stmt_id); + + // if we used a limit, we added a field, + // subtract it out + if ($this->limit_used) + { + $count = $count - 1; + } + + return $count; + } + + // -------------------------------------------------------------------- + + /** + * Field data + * + * Generates an array of objects containing field meta-data + * + * @access public + * @return array + */ + function field_data() + { + $retval = array(); + $fieldCount = $this->num_fields(); + for ($c = 1; $c <= $fieldCount; $c++) + { + $F = new stdClass(); + $F->name = ocicolumnname($this->stmt_id, $c); + $F->type = ocicolumntype($this->stmt_id, $c); + $F->max_length = ocicolumnsize($this->stmt_id, $c); + + $retval[] = $F; + } + + return $retval; + } + + // -------------------------------------------------------------------- + + /** + * Free the result + * + * @return null + */ + function free_result() + { + if (is_resource($this->result_id)) + { + OCIFreeStatement($this->result_id); + $this->result_id = FALSE; + } + } + + // -------------------------------------------------------------------- + + /** + * Result - associative array + * + * Returns the result set as an array + * + * @access private + * @return array + */ + function _fetch_assoc(&$row) + { + // if pulling from a cursor, use curs_id + if ($this->curs_id) + { + return ocifetchinto($this->curs_id, $row, OCI_ASSOC + OCI_RETURN_NULLS); + } + else + { + return ocifetchinto($this->stmt_id, $row, OCI_ASSOC + OCI_RETURN_NULLS); + } + } + + // -------------------------------------------------------------------- + + /** + * Result - object + * + * Returns the result set as an object + * + * @access private + * @return object + */ + function _fetch_object() + { + // the PHP 4 version of the oracle functions do not + // have a fetch method so we call the array version + // and build an object from that + + $row = array(); + $res = $this->_fetch_assoc($row); + if ($res != FALSE) + { + $obj = new stdClass(); + foreach ($row as $key => $value) + { + $obj->{$key} = $value; + } + + $res = $obj; + } + return $res; + } + + /** + * Query result. "array" version. + * + * @access public + * @return array + */ + function result_array() + { + if (count($this->result_array) > 0) + { + return $this->result_array; + } + + // oracle's fetch functions do not + // return arrays, the information + // is returned in reference parameters + // + $row = NULL; + while ($this->_fetch_assoc($row)) + { + $this->result_array[] = $row; + } + + if (count($this->result_array) == 0) + { + return FALSE; + } + + return $this->result_array; + } + +} + +?> \ No newline at end of file diff --git a/system/database/drivers/oci8/oci8_utility.php b/system/database/drivers/oci8/oci8_utility.php new file mode 100644 index 000000000..f1e327a3e --- /dev/null +++ b/system/database/drivers/oci8/oci8_utility.php @@ -0,0 +1,41 @@ + \ No newline at end of file diff --git a/system/database/drivers/odbc/odbc.php b/system/database/drivers/odbc/odbc.php new file mode 100644 index 000000000..ea311e590 --- /dev/null +++ b/system/database/drivers/odbc/odbc.php @@ -0,0 +1,454 @@ +database, $this->username, $this->password); + } + + // -------------------------------------------------------------------- + + /** + * Persistent database connection + * + * @access private called by the base class + * @return resource + */ + function db_pconnect() + { + return odbc_pconnect($this->database, $this->username, $this->password); + } + + // -------------------------------------------------------------------- + + /** + * Select the database + * + * @access private called by the base class + * @return resource + */ + function db_select() + { + // Not needed for ODBC + 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 @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 + * @return string + */ + function escape_str($str) + { + // ODBC doesn't require escaping + 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("SELECT COUNT(*) AS numrows FROM `".$this->dbprefix.$table."`"); + + if ($query->num_rows() == 0) + return '0'; + + $row = $query->row(); + return $row->numrows; + } + + // -------------------------------------------------------------------- + + /** + * The error message string + * + * @access public + * @return string + */ + function error_message() + { + return odbc_errormsg($this->conn_id); + } + + // -------------------------------------------------------------------- + + /** + * The error message number + * + * @access public + * @return integer + */ + function error_number() + { + return odbc_error($this->conn_id); + } + + // -------------------------------------------------------------------- + + /** + * 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 public + * @param string the table name + * @return string + */ + function escape_table($table) + { + if (stristr($table, '.')) + { + $table = preg_replace("/\./", "`.`", $table); + } + + return $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) + { + $sql = "SELECT TOP 1 FROM ".$this->escape_table($table); + $query = $this->query($sql); + return $query->field_data(); + } + + // -------------------------------------------------------------------- + + /** + * 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 + * @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); + } + + // -------------------------------------------------------------------- + + /** + * Delete statement + * + * Generates a platform-specific delete string from the supplied data + * + * @access public + * @param string the table name + * @param array the where clause + * @return string + */ + function _delete($table, $where) + { + return "DELETE FROM ".$this->escape_table($table)." WHERE ".implode(" ", $where); + } + + // -------------------------------------------------------------------- + + /** + * Version number query string + * + * @access public + * @return string + */ + function _version() + { + return "SELECT version() AS ver"; + } + + // -------------------------------------------------------------------- + + /** + * Show table query + * + * Generates a platform-specific query string so that the table names can be fetched + * + * @access public + * @return string + */ + function _show_tables() + { + return "SHOW TABLES FROM `".$this->database."`"; + } + + // -------------------------------------------------------------------- + + /** + * Show columnn 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 _show_columns($table = '') + { + return "SHOW COLUMNS FROM ".$this->escape_table($table); + } + + // -------------------------------------------------------------------- + + /** + * 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); + } + +} + + +?> \ No newline at end of file diff --git a/system/database/drivers/odbc/odbc_result.php b/system/database/drivers/odbc/odbc_result.php new file mode 100644 index 000000000..49e5e9012 --- /dev/null +++ b/system/database/drivers/odbc/odbc_result.php @@ -0,0 +1,190 @@ +result_id); + } + + // -------------------------------------------------------------------- + + /** + * Number of fields in the result set + * + * @access public + * @return integer + */ + function num_fields() + { + return @odbc_num_fields($this->result_id); + } + + // -------------------------------------------------------------------- + + /** + * 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; + } + } + + // -------------------------------------------------------------------- + + /** + * 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; + } + +} + +?> \ No newline at end of file diff --git a/system/database/drivers/odbc/odbc_utility.php b/system/database/drivers/odbc/odbc_utility.php new file mode 100644 index 000000000..f2b5602cc --- /dev/null +++ b/system/database/drivers/odbc/odbc_utility.php @@ -0,0 +1,41 @@ + \ No newline at end of file diff --git a/system/database/drivers/postgre/postgre.php b/system/database/drivers/postgre/postgre.php new file mode 100644 index 000000000..317df37d1 --- /dev/null +++ b/system/database/drivers/postgre/postgre.php @@ -0,0 +1,484 @@ +port == '') ? '' : " port=".$this->port; + + return pg_connect("host=".$this->hostname.$port." dbname=".$this->database." user=".$this->username." password=".$this->password); + } + + // -------------------------------------------------------------------- + + /** + * Persistent database connection + * + * @access private called by the base class + * @return resource + */ + function db_pconnect() + { + $port = ($this->port == '') ? '' : " port=".$this->port; + + return pg_pconnect("host=".$this->hostname.$port." dbname=".$this->database." user=".$this->username." password=".$this->password); + } + + // -------------------------------------------------------------------- + + /** + * 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; + } + + // -------------------------------------------------------------------- + + /** + * 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 + * @return string + */ + function escape_str($str) + { + return pg_escape_string($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 = pg_version($this->conn_id); + $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('SELECT COUNT(*) AS numrows FROM "'.$this->dbprefix.$table.'"'); + + if ($query->num_rows() == 0) + return '0'; + + $row = $query->row(); + return $row->numrows; + } + + // -------------------------------------------------------------------- + + /** + * The error message string + * + * @access public + * @return string + */ + function error_message() + { + return pg_last_error($this->conn_id); + } + + // -------------------------------------------------------------------- + + /** + * The error message number + * + * @access public + * @return integer + */ + function error_number() + { + return ''; + } + + // -------------------------------------------------------------------- + + /** + * 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 public + * @param string the table name + * @return string + */ + function escape_table($table) + { + if (stristr($table, '.')) + { + $table = '"'.preg_replace("/\./", '"."', $table).'"'; + } + + return $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) + { + $sql = "SELECT * FROM ".$this->escape_table($table)." LIMIT 1"; + $query = $this->query($sql); + return $query->field_data(); + } + + // -------------------------------------------------------------------- + + /** + * 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 + * @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); + } + + // -------------------------------------------------------------------- + + /** + * Delete statement + * + * Generates a platform-specific delete string from the supplied data + * + * @access public + * @param string the table name + * @param array the where clause + * @return string + */ + function _delete($table, $where) + { + return "DELETE FROM ".$this->escape_table($table)." WHERE ".implode(" ", $where); + } + + // -------------------------------------------------------------------- + + /** + * Version number query string + * + * @access public + * @return string + */ + function _version() + { + return "SELECT version() AS ver"; + } + + /** + * Show table query + * + * Generates a platform-specific query string so that the table names can be fetched + * + * @access public + * @return string + */ + function _show_tables() + { + return "SELECT table_name FROM information_schema.tables WHERE table_schema = 'public'"; + } + + // -------------------------------------------------------------------- + + /** + * Show columnn 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 _show_columns($table = '') + { + return "SELECT column_name FROM information_schema.columns WHERE table_name ='".$this->escape_table($table)."'"; + } + + // -------------------------------------------------------------------- + + /** + * 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); + } + +} + +?> \ No newline at end of file diff --git a/system/database/drivers/postgre/postgre_result.php b/system/database/drivers/postgre/postgre_result.php new file mode 100644 index 000000000..6af7f94f2 --- /dev/null +++ b/system/database/drivers/postgre/postgre_result.php @@ -0,0 +1,129 @@ +result_id); + } + + // -------------------------------------------------------------------- + + /** + * Number of fields in the result set + * + * @access public + * @return integer + */ + function num_fields() + { + return @pg_num_fields($this->result_id); + } + + // -------------------------------------------------------------------- + + /** + * 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 = $i == 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; + } + } + + // -------------------------------------------------------------------- + + /** + * 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); + } + +} + +?> \ No newline at end of file diff --git a/system/database/drivers/postgre/postgre_utility.php b/system/database/drivers/postgre/postgre_utility.php new file mode 100644 index 000000000..760be81a0 --- /dev/null +++ b/system/database/drivers/postgre/postgre_utility.php @@ -0,0 +1,41 @@ + \ No newline at end of file diff --git a/system/database/drivers/sqlite/sqlite.php b/system/database/drivers/sqlite/sqlite.php new file mode 100644 index 000000000..6116a84ab --- /dev/null +++ b/system/database/drivers/sqlite/sqlite.php @@ -0,0 +1,481 @@ +database, 0666, $error)) + { + log_message('error', $error); + + if ($this->db_debug) + { + $this->display_error($error, '', TRUE); + } + } + + 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, 0666, $error)) + { + log_message('error', $error); + + if ($this->db_debug) + { + $this->display_error($error, '', TRUE); + } + } + + return $conn_id; + } + + // -------------------------------------------------------------------- + + /** + * Select the database + * + * @access private called by the base class + * @return resource + */ + function db_select() + { + 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 @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 + * @return string + */ + function escape_str($str) + { + return sqlite_escape_string($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("SELECT COUNT(*) AS numrows FROM `".$this->dbprefix.$table."`"); + + if ($query->num_rows() == 0) + return '0'; + + $row = $query->row(); + return $row->numrows; + } + + // -------------------------------------------------------------------- + + /** + * The error message string + * + * @access public + * @return string + */ + function error_message() + { + return sqlite_error_string(sqlite_last_error($this->conn_id)); + } + + // -------------------------------------------------------------------- + + /** + * The error message number + * + * @access public + * @return integer + */ + function error_number() + { + return sqlite_last_error($this->conn_id); + } + + // -------------------------------------------------------------------- + + /** + * Version number query string + * + * @access public + * @return string + */ + function version() + { + return sqlite_libversion(); + } + + // -------------------------------------------------------------------- + + /** + * 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 public + * @param string the table name + * @return string + */ + function escape_table($table) + { + if (stristr($table, '.')) + { + $table = preg_replace("/\./", "`.`", $table); + } + + return $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) + { + $sql = "SELECT * FROM ".$this->escape_table($table)." LIMIT 1"; + $query = $this->query($sql); + return $query->field_data(); + } + + // -------------------------------------------------------------------- + + /** + * 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 + * @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); + } + + // -------------------------------------------------------------------- + + /** + * Delete statement + * + * Generates a platform-specific delete string from the supplied data + * + * @access public + * @param string the table name + * @param array the where clause + * @return string + */ + function _delete($table, $where) + { + return "DELETE FROM ".$this->escape_table($table)." WHERE ".implode(" ", $where); + } + + // -------------------------------------------------------------------- + + /** + * Show table query + * + * Generates a platform-specific query string so that the table names can be fetched + * + * @access public + * @return string + */ + function _show_tables() + { + return "SELECT name from sqlite_master WHERE type='table'"; + } + + // -------------------------------------------------------------------- + + /** + * Show columnn 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 _show_columns($table = '') + { + // Not supported + return FALSE; + } + + // -------------------------------------------------------------------- + + /** + * 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); + } + +} + +?> \ No newline at end of file diff --git a/system/database/drivers/sqlite/sqlite_result.php b/system/database/drivers/sqlite/sqlite_result.php new file mode 100644 index 000000000..f30a8cfdf --- /dev/null +++ b/system/database/drivers/sqlite/sqlite_result.php @@ -0,0 +1,132 @@ +result_id); + } + + // -------------------------------------------------------------------- + + /** + * Number of fields in the result set + * + * @access public + * @return integer + */ + function num_fields() + { + return @sqlite_num_fields($this->result_id); + } + + // -------------------------------------------------------------------- + + /** + * 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 + } + + // -------------------------------------------------------------------- + + /** + * 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 + { + return $this->_fetch_assoc(); + } + } + +} + +?> \ No newline at end of file diff --git a/system/database/drivers/sqlite/sqlite_utility.php b/system/database/drivers/sqlite/sqlite_utility.php new file mode 100644 index 000000000..3cbec6f14 --- /dev/null +++ b/system/database/drivers/sqlite/sqlite_utility.php @@ -0,0 +1,41 @@ + \ No newline at end of file diff --git a/system/database/index.html b/system/database/index.html new file mode 100644 index 000000000..5a1f5d6ae --- /dev/null +++ b/system/database/index.html @@ -0,0 +1,15 @@ + + + + +403 Forbidden + + + + + +

Directory access is forbidden.

+ + + + \ No newline at end of file -- cgit v1.2.3-24-g4f1b From 687816a697d84faf6cd7f1f810fb748a04ad5662 Mon Sep 17 00:00:00 2001 From: admin Date: Sun, 24 Sep 2006 18:06:50 +0000 Subject: Deleting drivers folder --- system/drivers/DB_active_record.php | 875 ----------------------------- system/drivers/DB_driver.php | 1050 ----------------------------------- system/drivers/DB_mssql.php | 552 ------------------ system/drivers/DB_mysql.php | 574 ------------------- system/drivers/DB_mysqli.php | 577 ------------------- system/drivers/DB_oci8.php | 781 -------------------------- system/drivers/DB_odbc.php | 610 -------------------- system/drivers/DB_postgre.php | 581 ------------------- system/drivers/DB_sqlite.php | 584 ------------------- system/drivers/index.html | 15 - 10 files changed, 6199 deletions(-) delete mode 100644 system/drivers/DB_active_record.php delete mode 100644 system/drivers/DB_driver.php delete mode 100644 system/drivers/DB_mssql.php delete mode 100644 system/drivers/DB_mysql.php delete mode 100644 system/drivers/DB_mysqli.php delete mode 100644 system/drivers/DB_oci8.php delete mode 100644 system/drivers/DB_odbc.php delete mode 100644 system/drivers/DB_postgre.php delete mode 100644 system/drivers/DB_sqlite.php delete mode 100644 system/drivers/index.html (limited to 'system') diff --git a/system/drivers/DB_active_record.php b/system/drivers/DB_active_record.php deleted file mode 100644 index c038185bc..000000000 --- a/system/drivers/DB_active_record.php +++ /dev/null @@ -1,875 +0,0 @@ -ar_select[] = $val; - } - return $this; - } - - // -------------------------------------------------------------------- - - /** - * DISTINCT - * - * Sets a flag which tells the query string compiler to add DISTINCT - * - * @access public - * @param bool - * @return object - */ - function distinct($val = TRUE) - { - $this->ar_distinct = (is_bool($val)) ? $val : TRUE; - return $this; - } - - // -------------------------------------------------------------------- - - /** - * From - * - * Generates the FROM portion of the query - * - * @access public - * @param mixed can be a string or array - * @return object - */ - function from($from) - { - foreach ((array)$from as $val) - { - $this->ar_from[] = $this->dbprefix.$val; - } - return $this; - } - - // -------------------------------------------------------------------- - - /** - * Join - * - * Generates the JOIN portion of the query - * - * @access public - * @param string - * @param string the join condition - * @param string the type of join - * @return object - */ - 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 .= ' '; - } - } - - $this->ar_join[] = $type.'JOIN '.$table.' ON '.$cond; - return $this; - } - - // -------------------------------------------------------------------- - - /** - * Where - * - * Generates the WHERE portion of the query. Separates - * multiple calls with AND - * - * @access public - * @param mixed - * @param mixed - * @return object - */ - function where($key, $value = NULL) - { - return $this->_where($key, $value, 'AND '); - } - - // -------------------------------------------------------------------- - - /** - * OR Where - * - * Generates the WHERE portion of the query. Separates - * multiple calls with OR - * - * @access public - * @param mixed - * @param mixed - * @return object - */ - function orwhere($key, $value = NULL) - { - return $this->_where($key, $value, 'OR '); - } - - // -------------------------------------------------------------------- - - /** - * Where - * - * Called by where() or orwhere() - * - * @access private - * @param mixed - * @param mixed - * @param string - * @return object - */ - function _where($key, $value = NULL, $type = 'AND ') - { - if ( ! is_array($key)) - { - $key = array($key => $value); - } - - foreach ($key as $k => $v) - { - $prefix = (count($this->ar_where) == 0) ? '' : $type; - - if ( ! is_null($v)) - { - if ( ! $this->_has_operator($k)) - { - $k .= ' ='; - } - - $v = ' '.$this->escape($v); - } - - $this->ar_where[] = $prefix.$k.$v; - } - return $this; - } - - - - // -------------------------------------------------------------------- - - /** - * Like - * - * Generates a %LIKE% portion of the query. Separates - * multiple calls with AND - * - * @access public - * @param mixed - * @param mixed - * @return object - */ - function like($field, $match = '') - { - return $this->_like($field, $match, 'AND '); - } - - // -------------------------------------------------------------------- - - /** - * OR Like - * - * Generates a %LIKE% portion of the query. Separates - * multiple calls with OR - * - * @access public - * @param mixed - * @param mixed - * @return object - */ - function orlike($field, $match = '') - { - return $this->_like($field, $match, 'OR '); - } - - // -------------------------------------------------------------------- - - /** - * Like - * - * Called by like() or orlike() - * - * @access private - * @param mixed - * @param mixed - * @param string - * @return object - */ - function _like($field, $match = '', $type = 'AND ') - { - if ( ! is_array($field)) - { - $field = array($field => $match); - } - - foreach ($field as $k => $v) - { - $prefix = (count($this->ar_like) == 0) ? '' : $type; - - $v = $this->escape_str($v); - - $this->ar_like[] = $prefix." $k LIKE '%{$v}%'"; - } - return $this; - } - - // -------------------------------------------------------------------- - - /** - * GROUP BY - * - * @access public - * @param string - * @return object - */ - function groupby($by) - { - if (is_string($by)) - { - $by = explode(',', $by); - } - - foreach ($by as $val) - { - $val = trim($val); - - if ($val != '') - $this->ar_groupby[] = $val; - } - return $this; - } - - // -------------------------------------------------------------------- - - /** - * Sets the HAVING value - * - * Separates multiple calls with AND - * - * @access public - * @param string - * @param string - * @return object - */ - function having($key, $value = '') - { - return $this->_having($key, $value, 'AND '); - } - - // -------------------------------------------------------------------- - - /** - * Sets the OR HAVING value - * - * Separates multiple calls with OR - * - * @access public - * @param string - * @param string - * @return object - */ - function orhaving($key, $value = '') - { - return $this->_having($key, $value, 'OR '); - } - - // -------------------------------------------------------------------- - - /** - * Sets the HAVING values - * - * Called by having() or orhaving() - * - * @access private - * @param string - * @param string - * @return object - */ - function _having($key, $value = '', $type = 'AND ') - { - if ( ! is_array($key)) - { - $key = array($key => $value); - } - - foreach ($key as $k => $v) - { - $prefix = (count($this->ar_having) == 0) ? '' : $type; - - if ($v != '') - { - $v = ' '.$this->escape($v); - } - - $this->ar_having[] = $prefix.$k.$v; - } - return $this; - } - - // -------------------------------------------------------------------- - - /** - * Sets the ORDER BY value - * - * @access public - * @param string - * @param string direction: asc or desc - * @return object - */ - function orderby($orderby, $direction = '') - { - if (trim($direction) != '') - { - $direction = (in_array(strtoupper(trim($direction)), array('ASC', 'DESC', 'RAND()'))) ? ' '.$direction : ' ASC'; - } - - $this->ar_orderby[] = $orderby.$direction; - return $this; - } - - // -------------------------------------------------------------------- - - /** - * Sets the LIMIT value - * - * @access public - * @param integer the limit value - * @param integer the offset value - * @return object - */ - function limit($value, $offset = '') - { - $this->ar_limit = $value; - - if ($offset != '') - $this->ar_offset = $offset; - - return $this; - } - - // -------------------------------------------------------------------- - - /** - * Sets the OFFSET value - * - * @access public - * @param integer the offset value - * @return object - */ - function offset($value) - { - $this->ar_offset = $value; - return $this; - } - - // -------------------------------------------------------------------- - - /** - * The "set" function. Allows key/value pairs to be set for inserting or updating - * - * @access public - * @param mixed - * @param string - * @return object - */ - function set($key, $value = '') - { - $key = $this->_object_to_array($key); - - if ( ! is_array($key)) - { - $key = array($key => $value); - } - - foreach ($key as $k => $v) - { - $this->ar_set[$k] = $this->escape($v); - } - - return $this; - } - - // -------------------------------------------------------------------- - - /** - * Get - * - * Compiles the select statement based on the other functions called - * and runs the query - * - * @access public - * @param string the limit clause - * @param string the offset clause - * @return object - */ - function get($table = '', $limit = null, $offset = null) - { - if ($table != '') - { - $this->from($table); - } - - if ( ! is_null($limit)) - { - $this->limit($limit, $offset); - } - - $sql = $this->_compile_select(); - - $this->_reset_select(); - return $this->query($sql); - } - - // -------------------------------------------------------------------- - - /** - * GetWhere - * - * Allows the where clause, limit and offset to be added directly - * - * @access public - * @param string the where clause - * @param string the limit clause - * @param string the offset clause - * @return object - */ - function getwhere($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(); - - $this->_reset_select(); - return $this->query($sql); - } - - // -------------------------------------------------------------------- - - /** - * Insert - * - * Compiles an insert string and runs the query - * - * @access public - * @param string the table to retrieve the results from - * @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->dbprefix.$table, 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 - * - * @access public - * @param string the table to retrieve the results from - * @param array an associative array of update values - * @param mixed the where clause - * @return object - */ - function update($table = '', $set = NULL, $where = 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]; - } - - if ($where != null) - { - $this->where($where); - } - - $sql = $this->_update($this->dbprefix.$table, $this->ar_set, $this->ar_where); - - $this->_reset_write(); - return $this->query($sql); - } - - // -------------------------------------------------------------------- - - /** - * Delete - * - * Compiles a delete string and runs the query - * - * @access public - * @param string the table to retrieve the results from - * @param mixed the where clause - * @return object - */ - function delete($table = '', $where = '') - { - 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 != '') - { - $this->where($where); - } - - if (count($this->ar_where) == 0) - { - if ($this->db_debug) - { - return $this->display_error('db_del_must_use_where'); - } - return FALSE; - } - - $sql = $this->_delete($this->dbprefix.$table, $this->ar_where); - - $this->_reset_write(); - return $this->query($sql); - } - - // -------------------------------------------------------------------- - - /** - * Use Table - DEPRECATED - * - * @deprecated use $this->db->from instead - */ - function use_table($table) - { - return $this->from($table); - return $this; - } - - // -------------------------------------------------------------------- - - /** - * ORDER BY - DEPRECATED - * - * @deprecated use $this->db->orderby() instead - */ - function order_by($orderby, $direction = '') - { - return $this->orderby($orderby, $direction); - } - - // -------------------------------------------------------------------- - - /** - * 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; - } - - // -------------------------------------------------------------------- - - /** - * Compile the SELECT statement - * - * Generates a query string based on which functions were used. - * Should not be called directly. The get() function calls it. - * - * @access private - * @return string - */ - function _compile_select() - { - $sql = ( ! $this->ar_distinct) ? 'SELECT ' : 'SELECT DISTINCT '; - - $sql .= (count($this->ar_select) == 0) ? '*' : implode(', ', $this->ar_select); - - if (count($this->ar_from) > 0) - { - $sql .= "\nFROM "; - $sql .= implode(', ', $this->ar_from); - } - - if (count($this->ar_join) > 0) - { - $sql .= "\n"; - $sql .= implode("\n", $this->ar_join); - } - - if (count($this->ar_where) > 0 OR count($this->ar_like) > 0) - { - $sql .= "\nWHERE "; - } - - $sql .= implode("\n", $this->ar_where); - - if (count($this->ar_like) > 0) - { - if (count($this->ar_where) > 0) - { - $sql .= " AND "; - } - - $sql .= implode("\n", $this->ar_like); - } - - if (count($this->ar_groupby) > 0) - { - $sql .= "\nGROUP BY "; - $sql .= implode(', ', $this->ar_groupby); - } - - if (count($this->ar_having) > 0) - { - $sql .= "\nHAVING "; - $sql .= implode("\n", $this->ar_having); - } - - 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'; - } - } - - 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 convers the class variables to array key/vals - * - * @access public - * @param object - * @return array - */ - function _object_to_array($object) - { - if ( ! is_object($object)) - { - return $object; - } - - $array = array(); - foreach (get_object_vars($object) as $key => $val) - { - if ( ! is_object($val) AND ! is_array($val)) - { - $array[$key] = $val; - } - } - - return $array; - } - - // -------------------------------------------------------------------- - - /** - * Resets the active record values. Called by the get() function - * - * @access private - * @return void - */ - function _reset_select() - { - $this->ar_select = array(); - $this->ar_distinct = FALSE; - $this->ar_from = array(); - $this->ar_join = array(); - $this->ar_where = array(); - $this->ar_like = array(); - $this->ar_groupby = array(); - $this->ar_having = array(); - $this->ar_limit = FALSE; - $this->ar_offset = FALSE; - $this->ar_order = FALSE; - $this->ar_orderby = array(); - } - - // -------------------------------------------------------------------- - - /** - * Resets the active record "write" values. - * - * Called by the insert() or update() functions - * - * @access private - * @return void - */ - function _reset_write() - { - $this->ar_set = array(); - $this->ar_from = array(); - $this->ar_where = array(); - } - -} - -?> \ No newline at end of file diff --git a/system/drivers/DB_driver.php b/system/drivers/DB_driver.php deleted file mode 100644 index 48f7c4a9a..000000000 --- a/system/drivers/DB_driver.php +++ /dev/null @@ -1,1050 +0,0 @@ -initialize($params); - log_message('debug', 'Database Driver Class Initialized'); - } - - // -------------------------------------------------------------------- - - /** - * Initialize Database Settings - * - * @access private Called by the constructor - * @param mixed - * @return void - */ - function initialize($params = '') - { - if (is_array($params)) - { - foreach (array('hostname' => '', 'username' => '', 'password' => '', 'database' => '', 'dbdriver' => 'mysql', 'dbprefix' => '', 'port' => '', 'pconnect' => FALSE, 'db_debug' => FALSE) as $key => $val) - { - $this->$key = ( ! isset($params[$key])) ? $val : $params[$key]; - } - } - elseif (strpos($params, '://')) - { - if (FALSE === ($dsn = @parse_url($params))) - { - log_message('error', 'Invalid DB Connection String'); - - if ($this->db_debug) - { - return $this->display_error('db_invalid_connection_str'); - } - return FALSE; - } - - $this->hostname = ( ! isset($dsn['host'])) ? '' : rawurldecode($dsn['host']); - $this->username = ( ! isset($dsn['user'])) ? '' : rawurldecode($dsn['user']); - $this->password = ( ! isset($dsn['pass'])) ? '' : rawurldecode($dsn['pass']); - $this->database = ( ! isset($dsn['path'])) ? '' : rawurldecode(substr($dsn['path'], 1)); - } - - if ($this->pconnect == FALSE) - { - $this->conn_id = $this->db_connect(); - } - else - { - $this->conn_id = $this->db_pconnect(); - } - - if ( ! $this->conn_id) - { - log_message('error', 'Unable to connect to the database'); - - if ($this->db_debug) - { - $this->display_error('db_unable_to_connect'); - } - } - else - { - 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); - } - } - } - } - - // -------------------------------------------------------------------- - - /** - * 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; - } - - if ($this->dbdriver == 'oci8') - { - return $sql; - } - - $query = $this->query($sql); - $row = $query->row(); - return $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; - } - - // Compile binds if needed - if ($binds !== FALSE) - { - $sql = $this->compile_binds($sql, $binds); - } - - // Save the query for debugging - $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))) - { - // This will trigger a rollback if transactions are being used - $this->_trans_failure = TRUE; - - if ($this->db_debug) - { - log_message('error', 'Query error: '.$this->error_message()); - return $this->display_error( - array( - 'Error Number: '.$this->error_number(), - $this->error_message(), - $sql - ) - ); - } - - return FALSE; - } - - // Stop and aggregate the query time results - $time_end = list($em, $es) = explode(' ', microtime()); - $this->benchmark += ($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) - { - 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; - } - - // Instantiate and return the DB result object - $result = 'CI_DB_'.$this->dbdriver.'_result'; - - $RES = new $result(); - $RES->conn_id = $this->conn_id; - $RES->db_debug = $this->db_debug; - $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; - } - - return $RES; - } - - // -------------------------------------------------------------------- - - /** - * Simple Query - * This is a simiplified 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, $this->conn_id); - } - - // -------------------------------------------------------------------- - - /** - * Disable Transactions - * This permits transactions to be disabled at run-time. - * - * @access public - * @return void - */ - function trans_off() - { - $this->trans_enabled = FALSE; - } - - // -------------------------------------------------------------------- - - /** - * 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 TRUE in the event that a query failed - if ($this->_trans_failure === TRUE) - { - $this->trans_rollback(); - - if ($this->db_debug) - { - return $this->display_error('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_failure; - } - - - // -------------------------------------------------------------------- - - /** - * 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_shift(func_get_args()) : null; - - return call_user_func_array($function, $args); - } - } - - // -------------------------------------------------------------------- - - /** - * 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*"?(INSERT|UPDATE|DELETE|REPLACE|CREATE|DROP|LOAD DATA|COPY|ALTER|GRANT|REVOKE|LOCK|UNLOCK)\s+/i', $sql)) - { - return FALSE; - } - return TRUE; - } - - // -------------------------------------------------------------------- - - /** - * Calculate the aggregate query elapsed time - * - * @access public - * @param intiger 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 integer - */ - function escape($str) - { - switch (gettype($str)) - { - case 'string' : $str = "'".$this->escape_str($str)."'"; - break; - case 'boolean' : $str = ($str === FALSE) ? 0 : 1; - break; - default : $str = ($str === NULL) ? 'NULL' : $str; - break; - } - - return $str; - } - - // -------------------------------------------------------------------- - - /** - * Returns an array of table names - * - * @access public - * @return array - */ - function tables() - { - if (FALSE === ($sql = $this->_show_tables())) - { - 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); - } - } - } - - return $retval; - } - - // -------------------------------------------------------------------- - - /** - * Determine if a particular table exists - * @access public - * @return boolean - */ - function table_exists($table_name) - { - return ( ! in_array($this->dbprefix.$table_name, $this->tables())) ? FALSE : TRUE; - } - - // -------------------------------------------------------------------- - - /** - * Fetch MySQL Field Names - * - * @access public - * @param string the table name - * @return array - */ - function field_names($table = '') - { - if ($table == '') - { - if ($this->db_debug) - { - return $this->display_error('db_field_param_missing'); - } - return FALSE; - } - - if (FALSE === ($sql = $this->_show_columns($this->dbprefix.$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); - } - } - - return $retval; - } - - // -------------------------------------------------------------------- - - /** - * 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; - } - - return $this->_field_data($this->dbprefix.$table); - } - - // -------------------------------------------------------------------- - - /** - * 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->field_names($table); - - if ( ! is_array($fields)) - { - return FALSE; - } - - return current($fields); - } - - // -------------------------------------------------------------------- - - /** - * Compile Bindings - * - * @access public - * @param string the sql statement - * @param array an array of bind data - * @return string - */ - function compile_binds($sql, $binds) - { - if (FALSE === strpos($sql, $this->bind_marker)) - { - return $sql; - } - - if ( ! is_array($binds)) - { - $binds = array($binds); - } - - foreach ($binds as $val) - { - $val = $this->escape($val); - - // Just in case the replacement string contains the bind - // character we'll temporarily replace it with a marker - $val = str_replace($this->bind_marker, '{%bind_marker%}', $val); - $sql = preg_replace("#".preg_quote($this->bind_marker, '#')."#", str_replace('$', '\$', $val), $sql, 1); - } - - return str_replace('{%bind_marker%}', $this->bind_marker, $sql); - } - - // -------------------------------------------------------------------- - - /** - * 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[] = $key; - $values[] = $this->escape($val); - } - - return $this->_insert($this->dbprefix.$table, $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[$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->dbprefix.$table, $fields, $dest); - } - - // -------------------------------------------------------------------- - - /** - * Close DB Connection - * - * @access public - * @return void - */ - function close() - { - if (is_resource($this->conn_id)) - { - $this->destroy($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/errror_db.php template - */ - function display_error($error = '', $swap = '', $native = FALSE) - { - $LANG = new CI_Language(); - $LANG->load('db'); - - $heading = 'MySQL Error'; - - if ($native == TRUE) - { - $message = $error; - } - else - { - $message = ( ! is_array($error)) ? array(str_replace('%s', $swap, $LANG->line($error))) : $error; - } - - if ( ! class_exists('CI_Exceptions')) - { - include_once(BASEPATH.'libraries/Exceptions'.EXT); - } - - $error = new CI_Exceptions(); - echo $error->show_error('An Error Was Encountered', $message, 'error_db'); - exit; - - } - -} - - -/** - * Database Result Class - * - * This is the platform-independent result class. - * This class will not be called directly. Rather, the adapter - * class for the specific database will extend and instantiate it. - * - * @category Database - * @author Rick Ellis - * @link http://www.codeigniter.com/user_guide/database/ - */ -class CI_DB_result { - - var $conn_id = FALSE; - var $result_id = FALSE; - var $db_debug = FALSE; - var $result_array = array(); - var $result_object = array(); - var $current_row = 0; - - /** - * Query result. Acts as a wrapper function for the following functions. - * - * @access public - * @param string can be "object" or "array" - * @return mixed either a result object or array - */ - function result($type = 'object') - { - return ($type == 'object') ? $this->result_object() : $this->result_array(); - } - - // -------------------------------------------------------------------- - - /** - * Query result. "object" version. - * - * @access public - * @return object - */ - function result_object() - { - if (count($this->result_object) > 0) - { - return $this->result_object; - } - - while ($row = $this->_fetch_object()) - { - $this->result_object[] = $row; - } - - if (count($this->result_object) == 0) - { - return FALSE; - } - - return $this->result_object; - } - - // -------------------------------------------------------------------- - - /** - * Query result. "array" version. - * - * @access public - * @return array - */ - function result_array() - { - if (count($this->result_array) > 0) - { - return $this->result_array; - } - - while ($row = $this->_fetch_assoc()) - { - $this->result_array[] = $row; - } - - if (count($this->result_array) == 0) - { - return FALSE; - } - - return $this->result_array; - } - - // -------------------------------------------------------------------- - - /** - * Query result. Acts as a wrapper function for the following functions. - * - * @access public - * @param string can be "object" or "array" - * @return mixed either a result object or array - */ - function row($n = 0, $type = 'object') - { - return ($type == 'object') ? $this->row_object($n) : $this->row_array($n); - } - - // -------------------------------------------------------------------- - - /** - * Returns a single result row - object version - * - * @access public - * @return object - */ - function row_object($n = 0) - { - if (FALSE === ($result = $this->result_object())) - { - return FALSE; - } - - 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 - */ - function row_array($n = 0) - { - if (FALSE === ($result = $this->result_array())) - { - return FALSE; - } - - if ($n != $this->current_row AND isset($result[$n])) - { - $this->current_row = $n; - } - - return $result[$this->current_row]; - } - - // -------------------------------------------------------------------- - - /** - * Returns the "next" row - * - * @access public - * @return object - */ - function next_row($type = 'object') - { - if (FALSE === ($result = $this->result($type))) - { - return FALSE; - } - - if (isset($result[$this->current_row + 1])) - { - ++$this->current_row; - } - - return $result[$this->current_row]; - } - - // -------------------------------------------------------------------- - - /** - * Returns the "previous" row - * - * @access public - * @return object - */ - function previous_row($type = 'object') - { - if (FALSE === ($result = $this->result($type))) - { - return FALSE; - } - - if (isset($result[$this->current_row - 1])) - { - --$this->current_row; - } - return $result[$this->current_row]; - } - - // -------------------------------------------------------------------- - - /** - * Returns the "first" row - * - * @access public - * @return object - */ - function first_row($type = 'object') - { - if (FALSE === ($result = $this->result($type))) - { - return FALSE; - } - return $result[0]; - } - - // -------------------------------------------------------------------- - - /** - * Returns the "last" row - * - * @access public - * @return object - */ - function last_row($type = 'object') - { - if (FALSE === ($result = $this->result($type))) - { - return FALSE; - } - return $result[count($result) -1]; - } - -} - -?> \ No newline at end of file diff --git a/system/drivers/DB_mssql.php b/system/drivers/DB_mssql.php deleted file mode 100644 index 32c0537c3..000000000 --- a/system/drivers/DB_mssql.php +++ /dev/null @@ -1,552 +0,0 @@ -hostname, $this->username, $this->password); - } - - // -------------------------------------------------------------------- - - /** - * Persistent database connection - * - * @access private called by the base class - * @return resource - */ - function db_pconnect() - { - return mssql_pconnect($this->hostname, $this->username, $this->password); - } - - // -------------------------------------------------------------------- - - /** - * Select the database - * - * @access private called by the base class - * @return resource - */ - function db_select() - { - return @mssql_select_db($this->database, $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 @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 - * @return string - */ - function escape_str($str) - { - // Escape single quotes - return str_replace("'", "''", $str); - } - - // -------------------------------------------------------------------- - - /** - * Close DB Connection - * - * @access public - * @param resource - * @return void - */ - function destroy($conn_id) - { - mssql_close($conn_id); - } - - // -------------------------------------------------------------------- - - /** - * Affected Rows - * - * @access public - * @return integer - */ - function affected_rows() - { - return @mssql_rows_affected($this->conn_id); - } - - // -------------------------------------------------------------------- - - /** - * Insert ID - * - * @access public - * @return integer - */ - function insert_id() - { - // Not supported in MS SQL? - return 0; - } - - // -------------------------------------------------------------------- - - /** - * "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("SELECT COUNT(*) AS numrows FROM `".$this->dbprefix.$table."`"); - - if ($query->num_rows() == 0) - return '0'; - - $row = $query->row(); - return $row->numrows; - } - - // -------------------------------------------------------------------- - - /** - * The error message string - * - * @access public - * @return string - */ - function error_message() - { - // Are errros even supported in MS SQL? - return ''; - } - - // -------------------------------------------------------------------- - - /** - * The error message number - * - * @access public - * @return integer - */ - function error_number() - { - // Are error numbers supported? - return ''; - } - - // -------------------------------------------------------------------- - - /** - * 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 public - * @param string the table name - * @return string - */ - function escape_table($table) - { - if (stristr($table, '.')) - { - $table = preg_replace("/\./", "`.`", $table); - } - - return $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) - { - $sql = "SELECT TOP 1 FROM ".$this->escape_table($table); - $query = $this->query($sql); - return $query->field_data(); - } - - // -------------------------------------------------------------------- - - /** - * 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 - * @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); - } - - // -------------------------------------------------------------------- - - /** - * Delete statement - * - * Generates a platform-specific delete string from the supplied data - * - * @access public - * @param string the table name - * @param array the where clause - * @return string - */ - function _delete($table, $where) - { - return "DELETE FROM ".$this->escape_table($table)." WHERE ".implode(" ", $where); - } - - // -------------------------------------------------------------------- - - /** - * Version number query string - * - * @access public - * @return string - */ - function _version() - { - return "SELECT version() AS ver"; - } - - // -------------------------------------------------------------------- - - /** - * Show table query - * - * Generates a platform-specific query string so that the table names can be fetched - * - * @access public - * @return string - */ - function _show_tables() - { - return "SELECT name FROM sysobjects WHERE type = 'U' ORDER BY name"; - } - - // -------------------------------------------------------------------- - - /** - * Show columnn 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 _show_columns($table = '') - { - return "SELECT * FROM INFORMATION_SCHEMA.Columns WHERE TABLE_NAME = '".$this->escape_table($table)."'"; - } - - // -------------------------------------------------------------------- - - /** - * 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); - } - -} - - - -/** - * MS SQL Result Class - * - * This class extends the parent result class: CI_DB_result - * - * @category Database - * @author Rick Ellis - * @link http://www.codeigniter.com/user_guide/libraries/database/ - */ -class CI_DB_mssql_result extends CI_DB_result { - - /** - * Number of rows in the result set - * - * @access public - * @return integer - */ - function num_rows() - { - return @mssql_num_rows($this->result_id); - } - - // -------------------------------------------------------------------- - - /** - * Number of fields in the result set - * - * @access public - * @return integer - */ - function num_fields() - { - return @mssql_num_fields($this->result_id); - } - - // -------------------------------------------------------------------- - - /** - * 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; - } - - // -------------------------------------------------------------------- - - /** - * 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); - } - -} - -?> \ No newline at end of file diff --git a/system/drivers/DB_mysql.php b/system/drivers/DB_mysql.php deleted file mode 100644 index 208f09c25..000000000 --- a/system/drivers/DB_mysql.php +++ /dev/null @@ -1,574 +0,0 @@ -hostname, $this->username, $this->password, TRUE); - } - - // -------------------------------------------------------------------- - - /** - * Persistent database connection - * - * @access private called by the base class - * @return resource - */ - function db_pconnect() - { - return mysql_pconnect($this->hostname, $this->username, $this->password); - } - - // -------------------------------------------------------------------- - - /** - * Select the database - * - * @access private called by the base class - * @return resource - */ - function db_select() - { - return @mysql_select_db($this->database, $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 @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 - * @return string - */ - function escape_str($str) - { - return mysql_real_escape_string($str); - } - - // -------------------------------------------------------------------- - - /** - * Close DB Connection - * - * @access public - * @param resource - * @return void - */ - function destroy($conn_id) - { - mysql_close($conn_id); - } - - // -------------------------------------------------------------------- - - /** - * 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("SELECT COUNT(*) AS numrows FROM `".$this->dbprefix.$table."`"); - - if ($query->num_rows() == 0) - return '0'; - - $row = $query->row(); - return $row->numrows; - } - - // -------------------------------------------------------------------- - - /** - * The error message string - * - * @access public - * @return string - */ - function error_message() - { - return mysql_error($this->conn_id); - } - - // -------------------------------------------------------------------- - - /** - * The error message number - * - * @access public - * @return integer - */ - function error_number() - { - return mysql_errno($this->conn_id); - } - - // -------------------------------------------------------------------- - - /** - * 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 public - * @param string the table name - * @return string - */ - function escape_table($table) - { - if (stristr($table, '.')) - { - $table = preg_replace("/\./", "`.`", $table); - } - - return $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) - { - $sql = "SELECT * FROM ".$this->escape_table($table)." LIMIT 1"; - $query = $this->query($sql); - return $query->field_data(); - } - - // -------------------------------------------------------------------- - - /** - * 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 - * @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); - } - - // -------------------------------------------------------------------- - - /** - * Delete statement - * - * Generates a platform-specific delete string from the supplied data - * - * @access public - * @param string the table name - * @param array the where clause - * @return string - */ - function _delete($table, $where) - { - return "DELETE FROM ".$this->escape_table($table)." WHERE ".implode(" ", $where); - } - - // -------------------------------------------------------------------- - - /** - * Version number query string - * - * @access public - * @return string - */ - function _version() - { - return "SELECT version() AS ver"; - } - - // -------------------------------------------------------------------- - - /** - * Show table query - * - * Generates a platform-specific query string so that the table names can be fetched - * - * @access public - * @return string - */ - function _show_tables() - { - return "SHOW TABLES FROM `".$this->database."`"; - } - - // -------------------------------------------------------------------- - - /** - * Show columnn 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 _show_columns($table = '') - { - return "SHOW COLUMNS FROM ".$this->escape_table($table); - } - - // -------------------------------------------------------------------- - - /** - * 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; - } - -} - - -/** - * MySQL Result Class - * - * This class extends the parent result class: CI_DB_result - * - * @category Database - * @author Rick Ellis - * @link http://www.codeigniter.com/user_guide/libraries/database/ - */ -class CI_DB_mysql_result extends CI_DB_result { - - /** - * Number of rows in the result set - * - * @access public - * @return integer - */ - function num_rows() - { - return @mysql_num_rows($this->result_id); - } - - // -------------------------------------------------------------------- - - /** - * Number of fields in the result set - * - * @access public - * @return integer - */ - function num_fields() - { - return @mysql_num_fields($this->result_id); - } - - // -------------------------------------------------------------------- - - /** - * Field data - * - * Generates an array of objects containing field meta-data - * - * @access public - * @return array - */ - function field_data() - { - $retval = array(); - while ($field = mysql_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; - $F->primary_key = $field->primary_key; - - $retval[] = $F; - } - - return $retval; - } - - // -------------------------------------------------------------------- - - /** - * 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); - } - -} - -?> \ No newline at end of file diff --git a/system/drivers/DB_mysqli.php b/system/drivers/DB_mysqli.php deleted file mode 100644 index 288f552dd..000000000 --- a/system/drivers/DB_mysqli.php +++ /dev/null @@ -1,577 +0,0 @@ -hostname, $this->username, $this->password); - } - - // -------------------------------------------------------------------- - - /** - * Persistent database connection - * - * @access private called by the base class - * @return resource - */ - function db_pconnect() - { - return $this->db_connect(); - } - - // -------------------------------------------------------------------- - - /** - * Select the database - * - * @access private called by the base class - * @return resource - */ - function db_select() - { - return @mysqli_select_db($this->conn_id, $this->database); - } - - // -------------------------------------------------------------------- - - /** - * 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 - * @return string - */ - function escape_str($str) - { - return mysqli_real_escape_string($this->conn_id, $str); - } - - // -------------------------------------------------------------------- - - /** - * Close DB Connection - * - * @access public - * @param resource - * @return void - */ - function destroy($conn_id) - { - mysqli_close($conn_id); - } - - // -------------------------------------------------------------------- - - /** - * 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("SELECT COUNT(*) AS numrows FROM `".$this->dbprefix.$table."`"); - - if ($query->num_rows() == 0) - return '0'; - - $row = $query->row(); - return $row->numrows; - } - - // -------------------------------------------------------------------- - - /** - * The error message string - * - * @access public - * @return string - */ - function error_message() - { - return mysqli_error($this->conn_id); - } - - // -------------------------------------------------------------------- - - /** - * The error message number - * - * @access public - * @return integer - */ - function error_number() - { - return mysqli_errno($this->conn_id); - } - - // -------------------------------------------------------------------- - - /** - * 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 public - * @param string the table name - * @return string - */ - function escape_table($table) - { - if (stristr($table, '.')) - { - $table = preg_replace("/\./", "`.`", $table); - } - - return $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) - { - $sql = "SELECT * FROM ".$this->escape_table($table)." LIMIT 1"; - $query = $this->query($sql); - return $query->field_data(); - } - - // -------------------------------------------------------------------- - - /** - * 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 - * @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); - } - - // -------------------------------------------------------------------- - - /** - * Delete statement - * - * Generates a platform-specific delete string from the supplied data - * - * @access public - * @param string the table name - * @param array the where clause - * @return string - */ - function _delete($table, $where) - { - return "DELETE FROM ".$this->escape_table($table)." WHERE ".implode(" ", $where); - } - - // -------------------------------------------------------------------- - - /** - * Version number query string - * - * @access public - * @return string - */ - function _version() - { - return "SELECT version() AS ver"; - } - - // -------------------------------------------------------------------- - - /** - * Show table query - * - * Generates a platform-specific query string so that the table names can be fetched - * - * @access public - * @return string - */ - function _show_tables() - { - return "SHOW TABLES FROM `".$this->database."`"; - } - - // -------------------------------------------------------------------- - - /** - * Show columnn 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 _show_columns($table = '') - { - return "SHOW COLUMNS FROM ".$this->escape_table($table); - } - - // -------------------------------------------------------------------- - - /** - * 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; - } - -} - - - -/** - * MySQLi Result Class - * - * This class extends the parent result class: CI_DB_result - * - * @category Database - * @author Rick Ellis - * @link http://www.codeigniter.com/user_guide/libraries/database/ - */ -class CI_DB_mysqli_result extends CI_DB_result { - - /** - * Number of rows in the result set - * - * @access public - * @return integer - */ - function num_rows() - { - return @mysqli_num_rows($this->result_id); - } - - // -------------------------------------------------------------------- - - /** - * Number of fields in the result set - * - * @access public - * @return integer - */ - function num_fields() - { - return @mysqli_num_fields($this->result_id); - } - - // -------------------------------------------------------------------- - - /** - * Field data - * - * Generates an array of objects containing field meta-data - * - * @access public - * @return array - */ - function field_data() - { - $retval = array(); - while ($field = mysqli_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; - $F->primary_key = ($field->flags & MYSQLI_PRI_KEY_FLAG) ? 1 : 0; - - $retval[] = $F; - } - - return $retval; - } - - // -------------------------------------------------------------------- - - /** - * 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); - } - -} - -?> \ No newline at end of file diff --git a/system/drivers/DB_oci8.php b/system/drivers/DB_oci8.php deleted file mode 100644 index a88b474bd..000000000 --- a/system/drivers/DB_oci8.php +++ /dev/null @@ -1,781 +0,0 @@ -username, $this->password, $this->hostname); - } - - // -------------------------------------------------------------------- - - /** - * Persistent database connection - * - * @access private called by the base class - * @return resource - */ - function db_pconnect() - { - return ociplogon($this->username, $this->password, $this->hostname); - } - - // -------------------------------------------------------------------- - - /** - * Select the database - * - * @access private called by the base class - * @return resource - */ - function db_select() - { - return TRUE; - } - - // -------------------------------------------------------------------- - - /** - * Execute the query - * - * @access private called by the base class - * @param string an SQL query - * @return resource - */ - function _execute($sql) - { - // oracle must parse the query before it - // is run, all of the actions with - // the query are based off the statement id - // returned by ociparse - $this->_set_stmt_id($sql); - ocisetprefetch($this->stmt_id, 1000); - return @ociexecute($this->stmt_id, $this->_commit); - } - - /** - * Generate a statement ID - * - * @access private - * @param string an SQL query - * @return none - */ - function _set_stmt_id($sql) - { - if ( ! is_resource($this->stmt_id)) - { - $this->stmt_id = ociparse($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 - */ - function _prep_query($sql) - { - return $sql; - } - - // -------------------------------------------------------------------- - - /** - * getCursor. Returns a cursor from the datbase - * - * @access public - * @return cursor id - */ - function get_cursor() - { - return $this->curs_id = ocinewcursor($this->conn_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 - */ - 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 - */ - 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] = ''; - } - } - - ocibindbyname($this->stmt_id, $param['name'], $param['value'], $param['length'], $param['type']); - } - } - - // -------------------------------------------------------------------- - - /** - * 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->_commit = OCI_DEFAULT; - 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; - } - - $ret = OCIcommit($this->conn_id); - $this->_commit = OCI_COMMIT_ON_SUCCESS; - 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 = OCIrollback($this->conn_id); - $this->_commit = OCI_COMMIT_ON_SUCCESS; - return $ret; - } - - // -------------------------------------------------------------------- - - /** - * Escape String - * - * @access public - * @param string - * @return string - */ - function escape_str($str) - { - return $str; - } - - // -------------------------------------------------------------------- - - /** - * Close DB Connection - * - * @access public - * @param resource - * @return void - */ - function destroy($conn_id) - { - ocilogoff($conn_id); - } - - // -------------------------------------------------------------------- - - /** - * Affected Rows - * - * @access public - * @return integer - */ - function affected_rows() - { - return @ocirowcount($this->stmt_id); - } - - // -------------------------------------------------------------------- - - /** - * Insert ID - * - * @access public - * @return integer - */ - function insert_id() - { - // not supported in oracle - return 0; - } - - // -------------------------------------------------------------------- - - /** - * "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("SELECT COUNT(1) AS numrows FROM ".$table); - - if ($query == FALSE) - { - return 0; - } - - $row = $query->row(); - return $row->NUMROWS; - } - - // -------------------------------------------------------------------- - - /** - * The error message string - * - * @access public - * @return string - */ - function error_message() - { - $error = ocierror($this->conn_id); - return $error['message']; - } - - // -------------------------------------------------------------------- - - /** - * The error message number - * - * @access public - * @return integer - */ - function error_number() - { - $error = ocierror($this->conn_id); - return $error['code']; - } - - // -------------------------------------------------------------------- - - /** - * 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 public - * @param string the table name - * @return string - */ - function escape_table($table) - { - if (stristr($table, '.')) - { - $table = preg_replace("/\./", "`.`", $table); - } - - return $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) - { - $sql = "SELECT * FROM ".$this->escape_table($table)." where rownum = 1"; - $query = $this->query($sql); - return $query->field_data(); - } - - // -------------------------------------------------------------------- - - /** - * 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 - * @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); - } - - // -------------------------------------------------------------------- - - /** - * Delete statement - * - * Generates a platform-specific delete string from the supplied data - * - * @access public - * @param string the table name - * @param array the where clause - * @return string - */ - function _delete($table, $where) - { - return "DELETE FROM ".$this->escape_table($table)." WHERE ".implode(" ", $where); - } - - // -------------------------------------------------------------------- - - /** - * Version number query string - * - * @access public - * @return string - */ - function _version() - { - $ver = ociserverversion($this->conn_id); - return $ver; - } - - // -------------------------------------------------------------------- - - /** - * Show table query - * - * Generates a platform-specific query string so that the table names can be fetched - * - * @access public - * @return string - */ - function _show_tables() - { - return "select TABLE_NAME FROM ALL_TABLES"; - } - - // -------------------------------------------------------------------- - - /** - * Show columnn 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 _show_columns($table = '') - { - return "SELECT COLUMN_NAME FROM all_tab_columns WHERE table_name = '$table'"; - } - - // -------------------------------------------------------------------- - - /** - * 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) - { - $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; - } - -} - - -/** - * oci8 Result Class - * - * This class extends the parent result class: CI_DB_result - * - * @category Database - * @author Rick Ellis - * @link http://www.codeigniter.com/user_guide/libraries/database/ - */ -class CI_DB_oci8_result extends CI_DB_result { - - var $stmt_id; - var $curs_id; - var $limit_used; - - /** - * Number of rows in the result set - * - * @access public - * @return integer - */ - function num_rows() - { - // get the results, count them, - // rerun query - otherwise we - // won't have data after calling - // num_rows() - $this->result_array(); - $rowcount = count($this->result_array); - @ociexecute($this->stmt_id); - if ($this->curs_id) - { - @ociexecute($this->curs_id); - } - return $rowcount; - } - - // -------------------------------------------------------------------- - - /** - * Number of fields in the result set - * - * @access public - * @return integer - */ - function num_fields() - { - $count = @ocinumcols($this->stmt_id); - - // if we used a limit, we added a field, - // subtract it out - if ($this->limit_used) - { - $count = $count - 1; - } - - return $count; - } - - // -------------------------------------------------------------------- - - /** - * Field data - * - * Generates an array of objects containing field meta-data - * - * @access public - * @return array - */ - function field_data() - { - $retval = array(); - $fieldCount = $this->num_fields(); - for ($c = 1; $c <= $fieldCount; $c++) - { - $F = new stdClass(); - $F->name = ocicolumnname($this->stmt_id, $c); - $F->type = ocicolumntype($this->stmt_id, $c); - $F->max_length = ocicolumnsize($this->stmt_id, $c); - - $retval[] = $F; - } - - return $retval; - } - - // -------------------------------------------------------------------- - - /** - * Result - associative array - * - * Returns the result set as an array - * - * @access private - * @return array - */ - function _fetch_assoc(&$row) - { - // if pulling from a cursor, use curs_id - if ($this->curs_id) - { - return ocifetchinto($this->curs_id, $row, OCI_ASSOC + OCI_RETURN_NULLS); - } - else - { - return ocifetchinto($this->stmt_id, $row, OCI_ASSOC + OCI_RETURN_NULLS); - } - } - - // -------------------------------------------------------------------- - - /** - * Result - object - * - * Returns the result set as an object - * - * @access private - * @return object - */ - function _fetch_object() - { - // the PHP 4 version of the oracle functions do not - // have a fetch method so we call the array version - // and build an object from that - - $row = array(); - $res = $this->_fetch_assoc($row); - if ($res != FALSE) - { - $obj = new stdClass(); - foreach ($row as $key => $value) - { - $obj->{$key} = $value; - } - - $res = $obj; - } - return $res; - } - - /** - * Query result. "array" version. - * - * @access public - * @return array - */ - function result_array() - { - if (count($this->result_array) > 0) - { - return $this->result_array; - } - - // oracle's fetch functions do not - // return arrays, the information - // is returned in reference parameters - // - $row = NULL; - while ($this->_fetch_assoc($row)) - { - $this->result_array[] = $row; - } - - if (count($this->result_array) == 0) - { - return FALSE; - } - - return $this->result_array; - } - -} - -?> \ No newline at end of file diff --git a/system/drivers/DB_odbc.php b/system/drivers/DB_odbc.php deleted file mode 100644 index cdd2f4513..000000000 --- a/system/drivers/DB_odbc.php +++ /dev/null @@ -1,610 +0,0 @@ -database, $this->username, $this->password); - } - - // -------------------------------------------------------------------- - - /** - * Persistent database connection - * - * @access private called by the base class - * @return resource - */ - function db_pconnect() - { - return odbc_pconnect($this->database, $this->username, $this->password); - } - - // -------------------------------------------------------------------- - - /** - * Select the database - * - * @access private called by the base class - * @return resource - */ - function db_select() - { - // Not needed for ODBC - 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 @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 - * @return string - */ - function escape_str($str) - { - // ODBC doesn't require escaping - return $str; - } - - // -------------------------------------------------------------------- - - /** - * Close DB Connection - * - * @access public - * @param resource - * @return void - */ - function destroy($conn_id) - { - odbc_close($conn_id); - } - - // -------------------------------------------------------------------- - - /** - * 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("SELECT COUNT(*) AS numrows FROM `".$this->dbprefix.$table."`"); - - if ($query->num_rows() == 0) - return '0'; - - $row = $query->row(); - return $row->numrows; - } - - // -------------------------------------------------------------------- - - /** - * The error message string - * - * @access public - * @return string - */ - function error_message() - { - return odbc_errormsg($this->conn_id); - } - - // -------------------------------------------------------------------- - - /** - * The error message number - * - * @access public - * @return integer - */ - function error_number() - { - return odbc_error($this->conn_id); - } - - // -------------------------------------------------------------------- - - /** - * 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 public - * @param string the table name - * @return string - */ - function escape_table($table) - { - if (stristr($table, '.')) - { - $table = preg_replace("/\./", "`.`", $table); - } - - return $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) - { - $sql = "SELECT TOP 1 FROM ".$this->escape_table($table); - $query = $this->query($sql); - return $query->field_data(); - } - - // -------------------------------------------------------------------- - - /** - * 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 - * @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); - } - - // -------------------------------------------------------------------- - - /** - * Delete statement - * - * Generates a platform-specific delete string from the supplied data - * - * @access public - * @param string the table name - * @param array the where clause - * @return string - */ - function _delete($table, $where) - { - return "DELETE FROM ".$this->escape_table($table)." WHERE ".implode(" ", $where); - } - - // -------------------------------------------------------------------- - - /** - * Version number query string - * - * @access public - * @return string - */ - function _version() - { - return "SELECT version() AS ver"; - } - - // -------------------------------------------------------------------- - - /** - * Show table query - * - * Generates a platform-specific query string so that the table names can be fetched - * - * @access public - * @return string - */ - function _show_tables() - { - return "SHOW TABLES FROM `".$this->database."`"; - } - - // -------------------------------------------------------------------- - - /** - * Show columnn 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 _show_columns($table = '') - { - return "SHOW COLUMNS FROM ".$this->escape_table($table); - } - - // -------------------------------------------------------------------- - - /** - * 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; - } - -} - - -/** - * ODBC Result Class - * - * This class extends the parent result class: CI_DB_result - * - * @category Database - * @author Rick Ellis - * @link http://www.codeigniter.com/user_guide/libraries/database/ - */ -class CI_DB_odbc_result extends CI_DB_result { - - /** - * Number of rows in the result set - * - * @access public - * @return integer - */ - function num_rows() - { - return @odbc_num_rows($this->result_id); - } - - // -------------------------------------------------------------------- - - /** - * Number of fields in the result set - * - * @access public - * @return integer - */ - function num_fields() - { - return @odbc_num_fields($this->result_id); - } - - // -------------------------------------------------------------------- - - /** - * 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; - } - - // -------------------------------------------------------------------- - - /** - * 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; - } - -} - -?> \ No newline at end of file diff --git a/system/drivers/DB_postgre.php b/system/drivers/DB_postgre.php deleted file mode 100644 index bd5fbac24..000000000 --- a/system/drivers/DB_postgre.php +++ /dev/null @@ -1,581 +0,0 @@ -port == '') ? '' : " port=".$this->port; - - return pg_connect("host=".$this->hostname.$port." dbname=".$this->database." user=".$this->username." password=".$this->password); - } - - // -------------------------------------------------------------------- - - /** - * Persistent database connection - * - * @access private called by the base class - * @return resource - */ - function db_pconnect() - { - $port = ($this->port == '') ? '' : " port=".$this->port; - - return pg_pconnect("host=".$this->hostname.$port." dbname=".$this->database." user=".$this->username." password=".$this->password); - } - - // -------------------------------------------------------------------- - - /** - * 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; - } - - // -------------------------------------------------------------------- - - /** - * 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 - * @return string - */ - function escape_str($str) - { - return pg_escape_string($str); - } - - // -------------------------------------------------------------------- - - /** - * Close DB Connection - * - * @access public - * @param resource - * @return void - */ - function destroy($conn_id) - { - pg_close($conn_id); - } - - // -------------------------------------------------------------------- - - /** - * 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 = pg_version($this->conn_id); - $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('SELECT COUNT(*) AS numrows FROM "'.$this->dbprefix.$table.'"'); - - if ($query->num_rows() == 0) - return '0'; - - $row = $query->row(); - return $row->numrows; - } - - // -------------------------------------------------------------------- - - /** - * The error message string - * - * @access public - * @return string - */ - function error_message() - { - return pg_last_error($this->conn_id); - } - - // -------------------------------------------------------------------- - - /** - * The error message number - * - * @access public - * @return integer - */ - function error_number() - { - return ''; - } - - // -------------------------------------------------------------------- - - /** - * 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 public - * @param string the table name - * @return string - */ - function escape_table($table) - { - if (stristr($table, '.')) - { - $table = '"'.preg_replace("/\./", '"."', $table).'"'; - } - - return $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) - { - $sql = "SELECT * FROM ".$this->escape_table($table)." LIMIT 1"; - $query = $this->query($sql); - return $query->field_data(); - } - - // -------------------------------------------------------------------- - - /** - * 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 - * @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); - } - - // -------------------------------------------------------------------- - - /** - * Delete statement - * - * Generates a platform-specific delete string from the supplied data - * - * @access public - * @param string the table name - * @param array the where clause - * @return string - */ - function _delete($table, $where) - { - return "DELETE FROM ".$this->escape_table($table)." WHERE ".implode(" ", $where); - } - - // -------------------------------------------------------------------- - - /** - * Version number query string - * - * @access public - * @return string - */ - function _version() - { - return "SELECT version() AS ver"; - } - - /** - * Show table query - * - * Generates a platform-specific query string so that the table names can be fetched - * - * @access public - * @return string - */ - function _show_tables() - { - return "SELECT table_name FROM information_schema.tables WHERE table_schema = 'public'"; - } - - // -------------------------------------------------------------------- - - /** - * Show columnn 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 _show_columns($table = '') - { - return "SELECT column_name FROM information_schema.columns WHERE table_name ='".$this->escape_table($table)."'"; - } - - // -------------------------------------------------------------------- - - /** - * 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; - } - -} - - - -/** - * Postgres Result Class - * - * This class extends the parent result class: CI_DB_result - * - * @category Database - * @author Rick Ellis - * @link http://www.codeigniter.com/user_guide/libraries/database/ - */ -class CI_DB_postgre_result extends CI_DB_result { - - /** - * Number of rows in the result set - * - * @access public - * @return integer - */ - function num_rows() - { - return @pg_num_rows($this->result_id); - } - - // -------------------------------------------------------------------- - - /** - * Number of fields in the result set - * - * @access public - * @return integer - */ - function num_fields() - { - return @pg_num_fields($this->result_id); - } - - // -------------------------------------------------------------------- - - /** - * 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 = $i == 0; - $F->default = ''; - - $retval[] = $F; - } - - return $retval; - } - - // -------------------------------------------------------------------- - - /** - * 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); - } - -} - -?> \ No newline at end of file diff --git a/system/drivers/DB_sqlite.php b/system/drivers/DB_sqlite.php deleted file mode 100644 index b21241a1f..000000000 --- a/system/drivers/DB_sqlite.php +++ /dev/null @@ -1,584 +0,0 @@ -database, 0666, $error)) - { - log_message('error', $error); - - if ($this->db_debug) - { - $this->display_error($error, '', TRUE); - } - } - - 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, 0666, $error)) - { - log_message('error', $error); - - if ($this->db_debug) - { - $this->display_error($error, '', TRUE); - } - } - - return $conn_id; - } - - // -------------------------------------------------------------------- - - /** - * Select the database - * - * @access private called by the base class - * @return resource - */ - function db_select() - { - 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 @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 - * @return string - */ - function escape_str($str) - { - return sqlite_escape_string($str); - } - - // -------------------------------------------------------------------- - - /** - * Close DB Connection - * - * @access public - * @param resource - * @return void - */ - function destroy($conn_id) - { - sqlite_close($conn_id); - } - - // -------------------------------------------------------------------- - - /** - * 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("SELECT COUNT(*) AS numrows FROM `".$this->dbprefix.$table."`"); - - if ($query->num_rows() == 0) - return '0'; - - $row = $query->row(); - return $row->numrows; - } - - // -------------------------------------------------------------------- - - /** - * The error message string - * - * @access public - * @return string - */ - function error_message() - { - return sqlite_error_string(sqlite_last_error($this->conn_id)); - } - - // -------------------------------------------------------------------- - - /** - * The error message number - * - * @access public - * @return integer - */ - function error_number() - { - return sqlite_last_error($this->conn_id); - } - - // -------------------------------------------------------------------- - - /** - * Version number query string - * - * @access public - * @return string - */ - function version() - { - return sqlite_libversion(); - } - - // -------------------------------------------------------------------- - - /** - * 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 public - * @param string the table name - * @return string - */ - function escape_table($table) - { - if (stristr($table, '.')) - { - $table = preg_replace("/\./", "`.`", $table); - } - - return $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) - { - $sql = "SELECT * FROM ".$this->escape_table($table)." LIMIT 1"; - $query = $this->query($sql); - return $query->field_data(); - } - - // -------------------------------------------------------------------- - - /** - * 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 - * @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); - } - - // -------------------------------------------------------------------- - - /** - * Delete statement - * - * Generates a platform-specific delete string from the supplied data - * - * @access public - * @param string the table name - * @param array the where clause - * @return string - */ - function _delete($table, $where) - { - return "DELETE FROM ".$this->escape_table($table)." WHERE ".implode(" ", $where); - } - - // -------------------------------------------------------------------- - - /** - * Show table query - * - * Generates a platform-specific query string so that the table names can be fetched - * - * @access public - * @return string - */ - function _show_tables() - { - return "SELECT name from sqlite_master WHERE type='table'"; - } - - // -------------------------------------------------------------------- - - /** - * Show columnn 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 _show_columns($table = '') - { - // Not supported - return FALSE; - } - - // -------------------------------------------------------------------- - - /** - * 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; - } - -} - - -/** - * SQLite Result Class - * - * This class extends the parent result class: CI_DB_result - * - * @category Database - * @author Rick Ellis - * @link http://www.codeigniter.com/user_guide/libraries/database/ - */ -class CI_DB_sqlite_result extends CI_DB_result { - - /** - * Number of rows in the result set - * - * @access public - * @return integer - */ - function num_rows() - { - return @sqlite_num_rows($this->result_id); - } - - // -------------------------------------------------------------------- - - /** - * Number of fields in the result set - * - * @access public - * @return integer - */ - function num_fields() - { - return @sqlite_num_fields($this->result_id); - } - - // -------------------------------------------------------------------- - - /** - * 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; - } - - // -------------------------------------------------------------------- - - /** - * 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 - { - return $this->_fetch_assoc(); - } - } - -} - -?> \ No newline at end of file diff --git a/system/drivers/index.html b/system/drivers/index.html deleted file mode 100644 index 5a1f5d6ae..000000000 --- a/system/drivers/index.html +++ /dev/null @@ -1,15 +0,0 @@ - - - - -403 Forbidden - - - - - -

Directory access is forbidden.

- - - - \ No newline at end of file -- cgit v1.2.3-24-g4f1b From ea8ca450f5fad9cf3820a6a63cb9a5cc53a357ef Mon Sep 17 00:00:00 2001 From: admin Date: Sun, 24 Sep 2006 18:11:44 +0000 Subject: --- system/database/drivers/mssql/mssql_driver.php | 457 +++++++++++++++++++++++++ 1 file changed, 457 insertions(+) create mode 100644 system/database/drivers/mssql/mssql_driver.php (limited to 'system') diff --git a/system/database/drivers/mssql/mssql_driver.php b/system/database/drivers/mssql/mssql_driver.php new file mode 100644 index 000000000..4f668f282 --- /dev/null +++ b/system/database/drivers/mssql/mssql_driver.php @@ -0,0 +1,457 @@ +hostname, $this->username, $this->password); + } + + // -------------------------------------------------------------------- + + /** + * Persistent database connection + * + * @access private called by the base class + * @return resource + */ + function db_pconnect() + { + return mssql_pconnect($this->hostname, $this->username, $this->password); + } + + // -------------------------------------------------------------------- + + /** + * Select the database + * + * @access private called by the base class + * @return resource + */ + function db_select() + { + return @mssql_select_db($this->database, $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 @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 + * @return string + */ + function escape_str($str) + { + // Escape single quotes + return str_replace("'", "''", $str); + } + + // -------------------------------------------------------------------- + + /** + * Affected Rows + * + * @access public + * @return integer + */ + function affected_rows() + { + return @mssql_rows_affected($this->conn_id); + } + + // -------------------------------------------------------------------- + + /** + * Insert ID + * + * @access public + * @return integer + */ + function insert_id() + { + // Not supported in MS SQL? + return 0; + } + + // -------------------------------------------------------------------- + + /** + * "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("SELECT COUNT(*) AS numrows FROM `".$this->dbprefix.$table."`"); + + if ($query->num_rows() == 0) + return '0'; + + $row = $query->row(); + return $row->numrows; + } + + // -------------------------------------------------------------------- + + /** + * The error message string + * + * @access public + * @return string + */ + function error_message() + { + // Are errros even supported in MS SQL? + return ''; + } + + // -------------------------------------------------------------------- + + /** + * The error message number + * + * @access public + * @return integer + */ + function error_number() + { + // Are error numbers supported? + return ''; + } + + // -------------------------------------------------------------------- + + /** + * 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 public + * @param string the table name + * @return string + */ + function escape_table($table) + { + if (stristr($table, '.')) + { + $table = preg_replace("/\./", "`.`", $table); + } + + return $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) + { + $sql = "SELECT TOP 1 FROM ".$this->escape_table($table); + $query = $this->query($sql); + return $query->field_data(); + } + + // -------------------------------------------------------------------- + + /** + * 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 + * @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); + } + + // -------------------------------------------------------------------- + + /** + * Delete statement + * + * Generates a platform-specific delete string from the supplied data + * + * @access public + * @param string the table name + * @param array the where clause + * @return string + */ + function _delete($table, $where) + { + return "DELETE FROM ".$this->escape_table($table)." WHERE ".implode(" ", $where); + } + + // -------------------------------------------------------------------- + + /** + * Version number query string + * + * @access public + * @return string + */ + function _version() + { + return "SELECT version() AS ver"; + } + + // -------------------------------------------------------------------- + + /** + * Show table query + * + * Generates a platform-specific query string so that the table names can be fetched + * + * @access public + * @return string + */ + function _show_tables() + { + return "SELECT name FROM sysobjects WHERE type = 'U' ORDER BY name"; + } + + // -------------------------------------------------------------------- + + /** + * Show columnn 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 _show_columns($table = '') + { + return "SELECT * FROM INFORMATION_SCHEMA.Columns WHERE TABLE_NAME = '".$this->escape_table($table)."'"; + } + + // -------------------------------------------------------------------- + + /** + * 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); + } + + +} + + +?> \ No newline at end of file -- cgit v1.2.3-24-g4f1b From 046000bed008ff2031414aba71741595f808cf1e Mon Sep 17 00:00:00 2001 From: admin Date: Sun, 24 Sep 2006 18:12:07 +0000 Subject: --- system/database/drivers/mysql/mysql_driver.php | 478 +++++++++++++++++++++++++ 1 file changed, 478 insertions(+) create mode 100644 system/database/drivers/mysql/mysql_driver.php (limited to 'system') diff --git a/system/database/drivers/mysql/mysql_driver.php b/system/database/drivers/mysql/mysql_driver.php new file mode 100644 index 000000000..8aa82da72 --- /dev/null +++ b/system/database/drivers/mysql/mysql_driver.php @@ -0,0 +1,478 @@ +hostname, $this->username, $this->password, TRUE); + } + + // -------------------------------------------------------------------- + + /** + * Persistent database connection + * + * @access private called by the base class + * @return resource + */ + function db_pconnect() + { + return mysql_pconnect($this->hostname, $this->username, $this->password); + } + + // -------------------------------------------------------------------- + + /** + * Select the database + * + * @access private called by the base class + * @return resource + */ + function db_select() + { + return @mysql_select_db($this->database, $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 @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 + * @return string + */ + function escape_str($str) + { + return mysql_real_escape_string($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("SELECT COUNT(*) AS numrows FROM `".$this->dbprefix.$table."`"); + + if ($query->num_rows() == 0) + return '0'; + + $row = $query->row(); + return $row->numrows; + } + + // -------------------------------------------------------------------- + + /** + * The error message string + * + * @access public + * @return string + */ + function error_message() + { + return mysql_error($this->conn_id); + } + + // -------------------------------------------------------------------- + + /** + * The error message number + * + * @access public + * @return integer + */ + function error_number() + { + return mysql_errno($this->conn_id); + } + + // -------------------------------------------------------------------- + + /** + * 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 public + * @param string the table name + * @return string + */ + function escape_table($table) + { + if (stristr($table, '.')) + { + $table = preg_replace("/\./", "`.`", $table); + } + + return $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) + { + $sql = "SELECT * FROM ".$this->escape_table($table)." LIMIT 1"; + $query = $this->query($sql); + return $query->field_data(); + } + + // -------------------------------------------------------------------- + + /** + * 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 + * @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); + } + + // -------------------------------------------------------------------- + + /** + * Delete statement + * + * Generates a platform-specific delete string from the supplied data + * + * @access public + * @param string the table name + * @param array the where clause + * @return string + */ + function _delete($table, $where) + { + return "DELETE FROM ".$this->escape_table($table)." WHERE ".implode(" ", $where); + } + + // -------------------------------------------------------------------- + + /** + * Version number query string + * + * @access public + * @return string + */ + function _version() + { + return "SELECT version() AS ver"; + } + + // -------------------------------------------------------------------- + + /** + * Show table query + * + * Generates a platform-specific query string so that the table names can be fetched + * + * @access public + * @return string + */ + function _show_tables() + { + return "SHOW TABLES FROM `".$this->database."`"; + } + + // -------------------------------------------------------------------- + + /** + * Show columnn 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 _show_columns($table = '') + { + return "SHOW COLUMNS FROM ".$this->escape_table($table); + } + + // -------------------------------------------------------------------- + + /** + * 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); + } + +} + +?> \ No newline at end of file -- cgit v1.2.3-24-g4f1b From ff2d2514937ee2a153ebcc26acfc00d44ba4d7ce Mon Sep 17 00:00:00 2001 From: admin Date: Sun, 24 Sep 2006 18:12:18 +0000 Subject: --- system/database/drivers/mysqli/mysqli_driver.php | 479 +++++++++++++++++++++++ 1 file changed, 479 insertions(+) create mode 100644 system/database/drivers/mysqli/mysqli_driver.php (limited to 'system') diff --git a/system/database/drivers/mysqli/mysqli_driver.php b/system/database/drivers/mysqli/mysqli_driver.php new file mode 100644 index 000000000..8d28c2c5f --- /dev/null +++ b/system/database/drivers/mysqli/mysqli_driver.php @@ -0,0 +1,479 @@ +hostname, $this->username, $this->password); + } + + // -------------------------------------------------------------------- + + /** + * Persistent database connection + * + * @access private called by the base class + * @return resource + */ + function db_pconnect() + { + return $this->db_connect(); + } + + // -------------------------------------------------------------------- + + /** + * Select the database + * + * @access private called by the base class + * @return resource + */ + function db_select() + { + return @mysqli_select_db($this->conn_id, $this->database); + } + + // -------------------------------------------------------------------- + + /** + * 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 + * @return string + */ + function escape_str($str) + { + return mysqli_real_escape_string($this->conn_id, $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("SELECT COUNT(*) AS numrows FROM `".$this->dbprefix.$table."`"); + + if ($query->num_rows() == 0) + return '0'; + + $row = $query->row(); + return $row->numrows; + } + + // -------------------------------------------------------------------- + + /** + * The error message string + * + * @access public + * @return string + */ + function error_message() + { + return mysqli_error($this->conn_id); + } + + // -------------------------------------------------------------------- + + /** + * The error message number + * + * @access public + * @return integer + */ + function error_number() + { + return mysqli_errno($this->conn_id); + } + + // -------------------------------------------------------------------- + + /** + * 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 public + * @param string the table name + * @return string + */ + function escape_table($table) + { + if (stristr($table, '.')) + { + $table = preg_replace("/\./", "`.`", $table); + } + + return $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) + { + $sql = "SELECT * FROM ".$this->escape_table($table)." LIMIT 1"; + $query = $this->query($sql); + return $query->field_data(); + } + + // -------------------------------------------------------------------- + + /** + * 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 + * @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); + } + + // -------------------------------------------------------------------- + + /** + * Delete statement + * + * Generates a platform-specific delete string from the supplied data + * + * @access public + * @param string the table name + * @param array the where clause + * @return string + */ + function _delete($table, $where) + { + return "DELETE FROM ".$this->escape_table($table)." WHERE ".implode(" ", $where); + } + + // -------------------------------------------------------------------- + + /** + * Version number query string + * + * @access public + * @return string + */ + function _version() + { + return "SELECT version() AS ver"; + } + + // -------------------------------------------------------------------- + + /** + * Show table query + * + * Generates a platform-specific query string so that the table names can be fetched + * + * @access public + * @return string + */ + function _show_tables() + { + return "SHOW TABLES FROM `".$this->database."`"; + } + + // -------------------------------------------------------------------- + + /** + * Show columnn 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 _show_columns($table = '') + { + return "SHOW COLUMNS FROM ".$this->escape_table($table); + } + + // -------------------------------------------------------------------- + + /** + * 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); + } + +} + +?> \ No newline at end of file -- cgit v1.2.3-24-g4f1b From 99e1b29f1308e8d6c5faa84246e5be5fa93ef5aa Mon Sep 17 00:00:00 2001 From: admin Date: Sun, 24 Sep 2006 18:12:43 +0000 Subject: --- system/database/drivers/oci8/oci8_driver.php | 608 +++++++++++++++++++++++++++ 1 file changed, 608 insertions(+) create mode 100644 system/database/drivers/oci8/oci8_driver.php (limited to 'system') diff --git a/system/database/drivers/oci8/oci8_driver.php b/system/database/drivers/oci8/oci8_driver.php new file mode 100644 index 000000000..707394d53 --- /dev/null +++ b/system/database/drivers/oci8/oci8_driver.php @@ -0,0 +1,608 @@ +username, $this->password, $this->hostname); + } + + // -------------------------------------------------------------------- + + /** + * Persistent database connection + * + * @access private called by the base class + * @return resource + */ + function db_pconnect() + { + return ociplogon($this->username, $this->password, $this->hostname); + } + + // -------------------------------------------------------------------- + + /** + * Select the database + * + * @access private called by the base class + * @return resource + */ + function db_select() + { + return TRUE; + } + + // -------------------------------------------------------------------- + + /** + * Execute the query + * + * @access private called by the base class + * @param string an SQL query + * @return resource + */ + function _execute($sql) + { + // oracle must parse the query before it + // is run, all of the actions with + // the query are based off the statement id + // returned by ociparse + $this->_set_stmt_id($sql); + ocisetprefetch($this->stmt_id, 1000); + return @ociexecute($this->stmt_id, $this->_commit); + } + + /** + * Generate a statement ID + * + * @access private + * @param string an SQL query + * @return none + */ + function _set_stmt_id($sql) + { + if ( ! is_resource($this->stmt_id)) + { + $this->stmt_id = ociparse($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 + */ + function _prep_query($sql) + { + return $sql; + } + + // -------------------------------------------------------------------- + + /** + * getCursor. Returns a cursor from the datbase + * + * @access public + * @return cursor id + */ + function get_cursor() + { + return $this->curs_id = ocinewcursor($this->conn_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 + */ + 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 + */ + 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] = ''; + } + } + + ocibindbyname($this->stmt_id, $param['name'], $param['value'], $param['length'], $param['type']); + } + } + + // -------------------------------------------------------------------- + + /** + * 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->_commit = OCI_DEFAULT; + 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; + } + + $ret = OCIcommit($this->conn_id); + $this->_commit = OCI_COMMIT_ON_SUCCESS; + 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 = OCIrollback($this->conn_id); + $this->_commit = OCI_COMMIT_ON_SUCCESS; + return $ret; + } + + // -------------------------------------------------------------------- + + /** + * Escape String + * + * @access public + * @param string + * @return string + */ + function escape_str($str) + { + return $str; + } + + // -------------------------------------------------------------------- + + /** + * Affected Rows + * + * @access public + * @return integer + */ + function affected_rows() + { + return @ocirowcount($this->stmt_id); + } + + // -------------------------------------------------------------------- + + /** + * Insert ID + * + * @access public + * @return integer + */ + function insert_id() + { + // not supported in oracle + return 0; + } + + // -------------------------------------------------------------------- + + /** + * "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("SELECT COUNT(1) AS numrows FROM ".$table); + + if ($query == FALSE) + { + return 0; + } + + $row = $query->row(); + return $row->NUMROWS; + } + + // -------------------------------------------------------------------- + + /** + * The error message string + * + * @access public + * @return string + */ + function error_message() + { + $error = ocierror($this->conn_id); + return $error['message']; + } + + // -------------------------------------------------------------------- + + /** + * The error message number + * + * @access public + * @return integer + */ + function error_number() + { + $error = ocierror($this->conn_id); + return $error['code']; + } + + // -------------------------------------------------------------------- + + /** + * 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 public + * @param string the table name + * @return string + */ + function escape_table($table) + { + if (stristr($table, '.')) + { + $table = preg_replace("/\./", "`.`", $table); + } + + return $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) + { + $sql = "SELECT * FROM ".$this->escape_table($table)." where rownum = 1"; + $query = $this->query($sql); + return $query->field_data(); + } + + // -------------------------------------------------------------------- + + /** + * 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 + * @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); + } + + // -------------------------------------------------------------------- + + /** + * Delete statement + * + * Generates a platform-specific delete string from the supplied data + * + * @access public + * @param string the table name + * @param array the where clause + * @return string + */ + function _delete($table, $where) + { + return "DELETE FROM ".$this->escape_table($table)." WHERE ".implode(" ", $where); + } + + // -------------------------------------------------------------------- + + /** + * Version number query string + * + * @access public + * @return string + */ + function _version() + { + $ver = ociserverversion($this->conn_id); + return $ver; + } + + // -------------------------------------------------------------------- + + /** + * Show table query + * + * Generates a platform-specific query string so that the table names can be fetched + * + * @access public + * @return string + */ + function _show_tables() + { + return "select TABLE_NAME FROM ALL_TABLES"; + } + + // -------------------------------------------------------------------- + + /** + * Show columnn 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 _show_columns($table = '') + { + return "SELECT COLUMN_NAME FROM all_tab_columns WHERE table_name = '$table'"; + } + + // -------------------------------------------------------------------- + + /** + * 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) + { + $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 public + * @param resource + * @return void + */ + function _close($conn_id) + { + ocilogoff($conn_id); + } + +} + + +?> \ No newline at end of file -- cgit v1.2.3-24-g4f1b From 0d0116910ea060f08f69db4af0c474d7fcbf9802 Mon Sep 17 00:00:00 2001 From: admin Date: Sun, 24 Sep 2006 18:12:58 +0000 Subject: --- system/database/drivers/odbc/odbc_driver.php | 454 +++++++++++++++++++++++++++ 1 file changed, 454 insertions(+) create mode 100644 system/database/drivers/odbc/odbc_driver.php (limited to 'system') diff --git a/system/database/drivers/odbc/odbc_driver.php b/system/database/drivers/odbc/odbc_driver.php new file mode 100644 index 000000000..1725ed743 --- /dev/null +++ b/system/database/drivers/odbc/odbc_driver.php @@ -0,0 +1,454 @@ +database, $this->username, $this->password); + } + + // -------------------------------------------------------------------- + + /** + * Persistent database connection + * + * @access private called by the base class + * @return resource + */ + function db_pconnect() + { + return odbc_pconnect($this->database, $this->username, $this->password); + } + + // -------------------------------------------------------------------- + + /** + * Select the database + * + * @access private called by the base class + * @return resource + */ + function db_select() + { + // Not needed for ODBC + 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 @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 + * @return string + */ + function escape_str($str) + { + // ODBC doesn't require escaping + 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("SELECT COUNT(*) AS numrows FROM `".$this->dbprefix.$table."`"); + + if ($query->num_rows() == 0) + return '0'; + + $row = $query->row(); + return $row->numrows; + } + + // -------------------------------------------------------------------- + + /** + * The error message string + * + * @access public + * @return string + */ + function error_message() + { + return odbc_errormsg($this->conn_id); + } + + // -------------------------------------------------------------------- + + /** + * The error message number + * + * @access public + * @return integer + */ + function error_number() + { + return odbc_error($this->conn_id); + } + + // -------------------------------------------------------------------- + + /** + * 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 public + * @param string the table name + * @return string + */ + function escape_table($table) + { + if (stristr($table, '.')) + { + $table = preg_replace("/\./", "`.`", $table); + } + + return $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) + { + $sql = "SELECT TOP 1 FROM ".$this->escape_table($table); + $query = $this->query($sql); + return $query->field_data(); + } + + // -------------------------------------------------------------------- + + /** + * 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 + * @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); + } + + // -------------------------------------------------------------------- + + /** + * Delete statement + * + * Generates a platform-specific delete string from the supplied data + * + * @access public + * @param string the table name + * @param array the where clause + * @return string + */ + function _delete($table, $where) + { + return "DELETE FROM ".$this->escape_table($table)." WHERE ".implode(" ", $where); + } + + // -------------------------------------------------------------------- + + /** + * Version number query string + * + * @access public + * @return string + */ + function _version() + { + return "SELECT version() AS ver"; + } + + // -------------------------------------------------------------------- + + /** + * Show table query + * + * Generates a platform-specific query string so that the table names can be fetched + * + * @access public + * @return string + */ + function _show_tables() + { + return "SHOW TABLES FROM `".$this->database."`"; + } + + // -------------------------------------------------------------------- + + /** + * Show columnn 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 _show_columns($table = '') + { + return "SHOW COLUMNS FROM ".$this->escape_table($table); + } + + // -------------------------------------------------------------------- + + /** + * 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); + } + +} + + +?> \ No newline at end of file -- cgit v1.2.3-24-g4f1b From 7eea4f8906c21c1061cc9f21100e5597aae648b9 Mon Sep 17 00:00:00 2001 From: admin Date: Sun, 24 Sep 2006 18:13:17 +0000 Subject: --- system/database/drivers/postgre/postgre_driver.php | 484 +++++++++++++++++++++ 1 file changed, 484 insertions(+) create mode 100644 system/database/drivers/postgre/postgre_driver.php (limited to 'system') diff --git a/system/database/drivers/postgre/postgre_driver.php b/system/database/drivers/postgre/postgre_driver.php new file mode 100644 index 000000000..92767c42b --- /dev/null +++ b/system/database/drivers/postgre/postgre_driver.php @@ -0,0 +1,484 @@ +port == '') ? '' : " port=".$this->port; + + return pg_connect("host=".$this->hostname.$port." dbname=".$this->database." user=".$this->username." password=".$this->password); + } + + // -------------------------------------------------------------------- + + /** + * Persistent database connection + * + * @access private called by the base class + * @return resource + */ + function db_pconnect() + { + $port = ($this->port == '') ? '' : " port=".$this->port; + + return pg_pconnect("host=".$this->hostname.$port." dbname=".$this->database." user=".$this->username." password=".$this->password); + } + + // -------------------------------------------------------------------- + + /** + * 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; + } + + // -------------------------------------------------------------------- + + /** + * 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 + * @return string + */ + function escape_str($str) + { + return pg_escape_string($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 = pg_version($this->conn_id); + $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('SELECT COUNT(*) AS numrows FROM "'.$this->dbprefix.$table.'"'); + + if ($query->num_rows() == 0) + return '0'; + + $row = $query->row(); + return $row->numrows; + } + + // -------------------------------------------------------------------- + + /** + * The error message string + * + * @access public + * @return string + */ + function error_message() + { + return pg_last_error($this->conn_id); + } + + // -------------------------------------------------------------------- + + /** + * The error message number + * + * @access public + * @return integer + */ + function error_number() + { + return ''; + } + + // -------------------------------------------------------------------- + + /** + * 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 public + * @param string the table name + * @return string + */ + function escape_table($table) + { + if (stristr($table, '.')) + { + $table = '"'.preg_replace("/\./", '"."', $table).'"'; + } + + return $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) + { + $sql = "SELECT * FROM ".$this->escape_table($table)." LIMIT 1"; + $query = $this->query($sql); + return $query->field_data(); + } + + // -------------------------------------------------------------------- + + /** + * 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 + * @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); + } + + // -------------------------------------------------------------------- + + /** + * Delete statement + * + * Generates a platform-specific delete string from the supplied data + * + * @access public + * @param string the table name + * @param array the where clause + * @return string + */ + function _delete($table, $where) + { + return "DELETE FROM ".$this->escape_table($table)." WHERE ".implode(" ", $where); + } + + // -------------------------------------------------------------------- + + /** + * Version number query string + * + * @access public + * @return string + */ + function _version() + { + return "SELECT version() AS ver"; + } + + /** + * Show table query + * + * Generates a platform-specific query string so that the table names can be fetched + * + * @access public + * @return string + */ + function _show_tables() + { + return "SELECT table_name FROM information_schema.tables WHERE table_schema = 'public'"; + } + + // -------------------------------------------------------------------- + + /** + * Show columnn 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 _show_columns($table = '') + { + return "SELECT column_name FROM information_schema.columns WHERE table_name ='".$this->escape_table($table)."'"; + } + + // -------------------------------------------------------------------- + + /** + * 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); + } + +} + +?> \ No newline at end of file -- cgit v1.2.3-24-g4f1b From 46537628a0b319387367fc661478740a7393be8d Mon Sep 17 00:00:00 2001 From: admin Date: Sun, 24 Sep 2006 18:13:49 +0000 Subject: --- system/database/drivers/sqlite/sqlite_driver.php | 481 +++++++++++++++++++++++ 1 file changed, 481 insertions(+) create mode 100644 system/database/drivers/sqlite/sqlite_driver.php (limited to 'system') diff --git a/system/database/drivers/sqlite/sqlite_driver.php b/system/database/drivers/sqlite/sqlite_driver.php new file mode 100644 index 000000000..634b72ed4 --- /dev/null +++ b/system/database/drivers/sqlite/sqlite_driver.php @@ -0,0 +1,481 @@ +database, 0666, $error)) + { + log_message('error', $error); + + if ($this->db_debug) + { + $this->display_error($error, '', TRUE); + } + } + + 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, 0666, $error)) + { + log_message('error', $error); + + if ($this->db_debug) + { + $this->display_error($error, '', TRUE); + } + } + + return $conn_id; + } + + // -------------------------------------------------------------------- + + /** + * Select the database + * + * @access private called by the base class + * @return resource + */ + function db_select() + { + 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 @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 + * @return string + */ + function escape_str($str) + { + return sqlite_escape_string($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("SELECT COUNT(*) AS numrows FROM `".$this->dbprefix.$table."`"); + + if ($query->num_rows() == 0) + return '0'; + + $row = $query->row(); + return $row->numrows; + } + + // -------------------------------------------------------------------- + + /** + * The error message string + * + * @access public + * @return string + */ + function error_message() + { + return sqlite_error_string(sqlite_last_error($this->conn_id)); + } + + // -------------------------------------------------------------------- + + /** + * The error message number + * + * @access public + * @return integer + */ + function error_number() + { + return sqlite_last_error($this->conn_id); + } + + // -------------------------------------------------------------------- + + /** + * Version number query string + * + * @access public + * @return string + */ + function version() + { + return sqlite_libversion(); + } + + // -------------------------------------------------------------------- + + /** + * 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 public + * @param string the table name + * @return string + */ + function escape_table($table) + { + if (stristr($table, '.')) + { + $table = preg_replace("/\./", "`.`", $table); + } + + return $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) + { + $sql = "SELECT * FROM ".$this->escape_table($table)." LIMIT 1"; + $query = $this->query($sql); + return $query->field_data(); + } + + // -------------------------------------------------------------------- + + /** + * 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 + * @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); + } + + // -------------------------------------------------------------------- + + /** + * Delete statement + * + * Generates a platform-specific delete string from the supplied data + * + * @access public + * @param string the table name + * @param array the where clause + * @return string + */ + function _delete($table, $where) + { + return "DELETE FROM ".$this->escape_table($table)." WHERE ".implode(" ", $where); + } + + // -------------------------------------------------------------------- + + /** + * Show table query + * + * Generates a platform-specific query string so that the table names can be fetched + * + * @access public + * @return string + */ + function _show_tables() + { + return "SELECT name from sqlite_master WHERE type='table'"; + } + + // -------------------------------------------------------------------- + + /** + * Show columnn 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 _show_columns($table = '') + { + // Not supported + return FALSE; + } + + // -------------------------------------------------------------------- + + /** + * 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); + } + +} + +?> \ No newline at end of file -- cgit v1.2.3-24-g4f1b From 46563d570944d6c5af8b4f46ba1eeca111eabaa4 Mon Sep 17 00:00:00 2001 From: admin Date: Sun, 24 Sep 2006 18:14:22 +0000 Subject: --- system/database/drivers/mssql/mssql.php | 457 --------------------- system/database/drivers/mysql/mysql.php | 478 ---------------------- system/database/drivers/mysqli/mysqli.php | 479 ---------------------- system/database/drivers/oci8/oci8.php | 608 ---------------------------- system/database/drivers/odbc/odbc.php | 454 --------------------- system/database/drivers/postgre/postgre.php | 484 ---------------------- system/database/drivers/sqlite/sqlite.php | 481 ---------------------- system/libraries/Controller.php | 4 +- 8 files changed, 2 insertions(+), 3443 deletions(-) delete mode 100644 system/database/drivers/mssql/mssql.php delete mode 100644 system/database/drivers/mysql/mysql.php delete mode 100644 system/database/drivers/mysqli/mysqli.php delete mode 100644 system/database/drivers/oci8/oci8.php delete mode 100644 system/database/drivers/odbc/odbc.php delete mode 100644 system/database/drivers/postgre/postgre.php delete mode 100644 system/database/drivers/sqlite/sqlite.php (limited to 'system') diff --git a/system/database/drivers/mssql/mssql.php b/system/database/drivers/mssql/mssql.php deleted file mode 100644 index 5f30bf905..000000000 --- a/system/database/drivers/mssql/mssql.php +++ /dev/null @@ -1,457 +0,0 @@ -hostname, $this->username, $this->password); - } - - // -------------------------------------------------------------------- - - /** - * Persistent database connection - * - * @access private called by the base class - * @return resource - */ - function db_pconnect() - { - return mssql_pconnect($this->hostname, $this->username, $this->password); - } - - // -------------------------------------------------------------------- - - /** - * Select the database - * - * @access private called by the base class - * @return resource - */ - function db_select() - { - return @mssql_select_db($this->database, $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 @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 - * @return string - */ - function escape_str($str) - { - // Escape single quotes - return str_replace("'", "''", $str); - } - - // -------------------------------------------------------------------- - - /** - * Affected Rows - * - * @access public - * @return integer - */ - function affected_rows() - { - return @mssql_rows_affected($this->conn_id); - } - - // -------------------------------------------------------------------- - - /** - * Insert ID - * - * @access public - * @return integer - */ - function insert_id() - { - // Not supported in MS SQL? - return 0; - } - - // -------------------------------------------------------------------- - - /** - * "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("SELECT COUNT(*) AS numrows FROM `".$this->dbprefix.$table."`"); - - if ($query->num_rows() == 0) - return '0'; - - $row = $query->row(); - return $row->numrows; - } - - // -------------------------------------------------------------------- - - /** - * The error message string - * - * @access public - * @return string - */ - function error_message() - { - // Are errros even supported in MS SQL? - return ''; - } - - // -------------------------------------------------------------------- - - /** - * The error message number - * - * @access public - * @return integer - */ - function error_number() - { - // Are error numbers supported? - return ''; - } - - // -------------------------------------------------------------------- - - /** - * 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 public - * @param string the table name - * @return string - */ - function escape_table($table) - { - if (stristr($table, '.')) - { - $table = preg_replace("/\./", "`.`", $table); - } - - return $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) - { - $sql = "SELECT TOP 1 FROM ".$this->escape_table($table); - $query = $this->query($sql); - return $query->field_data(); - } - - // -------------------------------------------------------------------- - - /** - * 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 - * @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); - } - - // -------------------------------------------------------------------- - - /** - * Delete statement - * - * Generates a platform-specific delete string from the supplied data - * - * @access public - * @param string the table name - * @param array the where clause - * @return string - */ - function _delete($table, $where) - { - return "DELETE FROM ".$this->escape_table($table)." WHERE ".implode(" ", $where); - } - - // -------------------------------------------------------------------- - - /** - * Version number query string - * - * @access public - * @return string - */ - function _version() - { - return "SELECT version() AS ver"; - } - - // -------------------------------------------------------------------- - - /** - * Show table query - * - * Generates a platform-specific query string so that the table names can be fetched - * - * @access public - * @return string - */ - function _show_tables() - { - return "SELECT name FROM sysobjects WHERE type = 'U' ORDER BY name"; - } - - // -------------------------------------------------------------------- - - /** - * Show columnn 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 _show_columns($table = '') - { - return "SELECT * FROM INFORMATION_SCHEMA.Columns WHERE TABLE_NAME = '".$this->escape_table($table)."'"; - } - - // -------------------------------------------------------------------- - - /** - * 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); - } - - -} - - -?> \ No newline at end of file diff --git a/system/database/drivers/mysql/mysql.php b/system/database/drivers/mysql/mysql.php deleted file mode 100644 index 4d59f784d..000000000 --- a/system/database/drivers/mysql/mysql.php +++ /dev/null @@ -1,478 +0,0 @@ -hostname, $this->username, $this->password, TRUE); - } - - // -------------------------------------------------------------------- - - /** - * Persistent database connection - * - * @access private called by the base class - * @return resource - */ - function db_pconnect() - { - return mysql_pconnect($this->hostname, $this->username, $this->password); - } - - // -------------------------------------------------------------------- - - /** - * Select the database - * - * @access private called by the base class - * @return resource - */ - function db_select() - { - return @mysql_select_db($this->database, $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 @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 - * @return string - */ - function escape_str($str) - { - return mysql_real_escape_string($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("SELECT COUNT(*) AS numrows FROM `".$this->dbprefix.$table."`"); - - if ($query->num_rows() == 0) - return '0'; - - $row = $query->row(); - return $row->numrows; - } - - // -------------------------------------------------------------------- - - /** - * The error message string - * - * @access public - * @return string - */ - function error_message() - { - return mysql_error($this->conn_id); - } - - // -------------------------------------------------------------------- - - /** - * The error message number - * - * @access public - * @return integer - */ - function error_number() - { - return mysql_errno($this->conn_id); - } - - // -------------------------------------------------------------------- - - /** - * 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 public - * @param string the table name - * @return string - */ - function escape_table($table) - { - if (stristr($table, '.')) - { - $table = preg_replace("/\./", "`.`", $table); - } - - return $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) - { - $sql = "SELECT * FROM ".$this->escape_table($table)." LIMIT 1"; - $query = $this->query($sql); - return $query->field_data(); - } - - // -------------------------------------------------------------------- - - /** - * 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 - * @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); - } - - // -------------------------------------------------------------------- - - /** - * Delete statement - * - * Generates a platform-specific delete string from the supplied data - * - * @access public - * @param string the table name - * @param array the where clause - * @return string - */ - function _delete($table, $where) - { - return "DELETE FROM ".$this->escape_table($table)." WHERE ".implode(" ", $where); - } - - // -------------------------------------------------------------------- - - /** - * Version number query string - * - * @access public - * @return string - */ - function _version() - { - return "SELECT version() AS ver"; - } - - // -------------------------------------------------------------------- - - /** - * Show table query - * - * Generates a platform-specific query string so that the table names can be fetched - * - * @access public - * @return string - */ - function _show_tables() - { - return "SHOW TABLES FROM `".$this->database."`"; - } - - // -------------------------------------------------------------------- - - /** - * Show columnn 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 _show_columns($table = '') - { - return "SHOW COLUMNS FROM ".$this->escape_table($table); - } - - // -------------------------------------------------------------------- - - /** - * 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); - } - -} - -?> \ No newline at end of file diff --git a/system/database/drivers/mysqli/mysqli.php b/system/database/drivers/mysqli/mysqli.php deleted file mode 100644 index 6ca21c976..000000000 --- a/system/database/drivers/mysqli/mysqli.php +++ /dev/null @@ -1,479 +0,0 @@ -hostname, $this->username, $this->password); - } - - // -------------------------------------------------------------------- - - /** - * Persistent database connection - * - * @access private called by the base class - * @return resource - */ - function db_pconnect() - { - return $this->db_connect(); - } - - // -------------------------------------------------------------------- - - /** - * Select the database - * - * @access private called by the base class - * @return resource - */ - function db_select() - { - return @mysqli_select_db($this->conn_id, $this->database); - } - - // -------------------------------------------------------------------- - - /** - * 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 - * @return string - */ - function escape_str($str) - { - return mysqli_real_escape_string($this->conn_id, $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("SELECT COUNT(*) AS numrows FROM `".$this->dbprefix.$table."`"); - - if ($query->num_rows() == 0) - return '0'; - - $row = $query->row(); - return $row->numrows; - } - - // -------------------------------------------------------------------- - - /** - * The error message string - * - * @access public - * @return string - */ - function error_message() - { - return mysqli_error($this->conn_id); - } - - // -------------------------------------------------------------------- - - /** - * The error message number - * - * @access public - * @return integer - */ - function error_number() - { - return mysqli_errno($this->conn_id); - } - - // -------------------------------------------------------------------- - - /** - * 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 public - * @param string the table name - * @return string - */ - function escape_table($table) - { - if (stristr($table, '.')) - { - $table = preg_replace("/\./", "`.`", $table); - } - - return $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) - { - $sql = "SELECT * FROM ".$this->escape_table($table)." LIMIT 1"; - $query = $this->query($sql); - return $query->field_data(); - } - - // -------------------------------------------------------------------- - - /** - * 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 - * @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); - } - - // -------------------------------------------------------------------- - - /** - * Delete statement - * - * Generates a platform-specific delete string from the supplied data - * - * @access public - * @param string the table name - * @param array the where clause - * @return string - */ - function _delete($table, $where) - { - return "DELETE FROM ".$this->escape_table($table)." WHERE ".implode(" ", $where); - } - - // -------------------------------------------------------------------- - - /** - * Version number query string - * - * @access public - * @return string - */ - function _version() - { - return "SELECT version() AS ver"; - } - - // -------------------------------------------------------------------- - - /** - * Show table query - * - * Generates a platform-specific query string so that the table names can be fetched - * - * @access public - * @return string - */ - function _show_tables() - { - return "SHOW TABLES FROM `".$this->database."`"; - } - - // -------------------------------------------------------------------- - - /** - * Show columnn 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 _show_columns($table = '') - { - return "SHOW COLUMNS FROM ".$this->escape_table($table); - } - - // -------------------------------------------------------------------- - - /** - * 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); - } - -} - -?> \ No newline at end of file diff --git a/system/database/drivers/oci8/oci8.php b/system/database/drivers/oci8/oci8.php deleted file mode 100644 index 40aabcea7..000000000 --- a/system/database/drivers/oci8/oci8.php +++ /dev/null @@ -1,608 +0,0 @@ -username, $this->password, $this->hostname); - } - - // -------------------------------------------------------------------- - - /** - * Persistent database connection - * - * @access private called by the base class - * @return resource - */ - function db_pconnect() - { - return ociplogon($this->username, $this->password, $this->hostname); - } - - // -------------------------------------------------------------------- - - /** - * Select the database - * - * @access private called by the base class - * @return resource - */ - function db_select() - { - return TRUE; - } - - // -------------------------------------------------------------------- - - /** - * Execute the query - * - * @access private called by the base class - * @param string an SQL query - * @return resource - */ - function _execute($sql) - { - // oracle must parse the query before it - // is run, all of the actions with - // the query are based off the statement id - // returned by ociparse - $this->_set_stmt_id($sql); - ocisetprefetch($this->stmt_id, 1000); - return @ociexecute($this->stmt_id, $this->_commit); - } - - /** - * Generate a statement ID - * - * @access private - * @param string an SQL query - * @return none - */ - function _set_stmt_id($sql) - { - if ( ! is_resource($this->stmt_id)) - { - $this->stmt_id = ociparse($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 - */ - function _prep_query($sql) - { - return $sql; - } - - // -------------------------------------------------------------------- - - /** - * getCursor. Returns a cursor from the datbase - * - * @access public - * @return cursor id - */ - function get_cursor() - { - return $this->curs_id = ocinewcursor($this->conn_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 - */ - 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 - */ - 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] = ''; - } - } - - ocibindbyname($this->stmt_id, $param['name'], $param['value'], $param['length'], $param['type']); - } - } - - // -------------------------------------------------------------------- - - /** - * 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->_commit = OCI_DEFAULT; - 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; - } - - $ret = OCIcommit($this->conn_id); - $this->_commit = OCI_COMMIT_ON_SUCCESS; - 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 = OCIrollback($this->conn_id); - $this->_commit = OCI_COMMIT_ON_SUCCESS; - return $ret; - } - - // -------------------------------------------------------------------- - - /** - * Escape String - * - * @access public - * @param string - * @return string - */ - function escape_str($str) - { - return $str; - } - - // -------------------------------------------------------------------- - - /** - * Affected Rows - * - * @access public - * @return integer - */ - function affected_rows() - { - return @ocirowcount($this->stmt_id); - } - - // -------------------------------------------------------------------- - - /** - * Insert ID - * - * @access public - * @return integer - */ - function insert_id() - { - // not supported in oracle - return 0; - } - - // -------------------------------------------------------------------- - - /** - * "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("SELECT COUNT(1) AS numrows FROM ".$table); - - if ($query == FALSE) - { - return 0; - } - - $row = $query->row(); - return $row->NUMROWS; - } - - // -------------------------------------------------------------------- - - /** - * The error message string - * - * @access public - * @return string - */ - function error_message() - { - $error = ocierror($this->conn_id); - return $error['message']; - } - - // -------------------------------------------------------------------- - - /** - * The error message number - * - * @access public - * @return integer - */ - function error_number() - { - $error = ocierror($this->conn_id); - return $error['code']; - } - - // -------------------------------------------------------------------- - - /** - * 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 public - * @param string the table name - * @return string - */ - function escape_table($table) - { - if (stristr($table, '.')) - { - $table = preg_replace("/\./", "`.`", $table); - } - - return $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) - { - $sql = "SELECT * FROM ".$this->escape_table($table)." where rownum = 1"; - $query = $this->query($sql); - return $query->field_data(); - } - - // -------------------------------------------------------------------- - - /** - * 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 - * @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); - } - - // -------------------------------------------------------------------- - - /** - * Delete statement - * - * Generates a platform-specific delete string from the supplied data - * - * @access public - * @param string the table name - * @param array the where clause - * @return string - */ - function _delete($table, $where) - { - return "DELETE FROM ".$this->escape_table($table)." WHERE ".implode(" ", $where); - } - - // -------------------------------------------------------------------- - - /** - * Version number query string - * - * @access public - * @return string - */ - function _version() - { - $ver = ociserverversion($this->conn_id); - return $ver; - } - - // -------------------------------------------------------------------- - - /** - * Show table query - * - * Generates a platform-specific query string so that the table names can be fetched - * - * @access public - * @return string - */ - function _show_tables() - { - return "select TABLE_NAME FROM ALL_TABLES"; - } - - // -------------------------------------------------------------------- - - /** - * Show columnn 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 _show_columns($table = '') - { - return "SELECT COLUMN_NAME FROM all_tab_columns WHERE table_name = '$table'"; - } - - // -------------------------------------------------------------------- - - /** - * 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) - { - $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 public - * @param resource - * @return void - */ - function _close($conn_id) - { - ocilogoff($conn_id); - } - -} - - -?> \ No newline at end of file diff --git a/system/database/drivers/odbc/odbc.php b/system/database/drivers/odbc/odbc.php deleted file mode 100644 index ea311e590..000000000 --- a/system/database/drivers/odbc/odbc.php +++ /dev/null @@ -1,454 +0,0 @@ -database, $this->username, $this->password); - } - - // -------------------------------------------------------------------- - - /** - * Persistent database connection - * - * @access private called by the base class - * @return resource - */ - function db_pconnect() - { - return odbc_pconnect($this->database, $this->username, $this->password); - } - - // -------------------------------------------------------------------- - - /** - * Select the database - * - * @access private called by the base class - * @return resource - */ - function db_select() - { - // Not needed for ODBC - 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 @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 - * @return string - */ - function escape_str($str) - { - // ODBC doesn't require escaping - 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("SELECT COUNT(*) AS numrows FROM `".$this->dbprefix.$table."`"); - - if ($query->num_rows() == 0) - return '0'; - - $row = $query->row(); - return $row->numrows; - } - - // -------------------------------------------------------------------- - - /** - * The error message string - * - * @access public - * @return string - */ - function error_message() - { - return odbc_errormsg($this->conn_id); - } - - // -------------------------------------------------------------------- - - /** - * The error message number - * - * @access public - * @return integer - */ - function error_number() - { - return odbc_error($this->conn_id); - } - - // -------------------------------------------------------------------- - - /** - * 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 public - * @param string the table name - * @return string - */ - function escape_table($table) - { - if (stristr($table, '.')) - { - $table = preg_replace("/\./", "`.`", $table); - } - - return $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) - { - $sql = "SELECT TOP 1 FROM ".$this->escape_table($table); - $query = $this->query($sql); - return $query->field_data(); - } - - // -------------------------------------------------------------------- - - /** - * 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 - * @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); - } - - // -------------------------------------------------------------------- - - /** - * Delete statement - * - * Generates a platform-specific delete string from the supplied data - * - * @access public - * @param string the table name - * @param array the where clause - * @return string - */ - function _delete($table, $where) - { - return "DELETE FROM ".$this->escape_table($table)." WHERE ".implode(" ", $where); - } - - // -------------------------------------------------------------------- - - /** - * Version number query string - * - * @access public - * @return string - */ - function _version() - { - return "SELECT version() AS ver"; - } - - // -------------------------------------------------------------------- - - /** - * Show table query - * - * Generates a platform-specific query string so that the table names can be fetched - * - * @access public - * @return string - */ - function _show_tables() - { - return "SHOW TABLES FROM `".$this->database."`"; - } - - // -------------------------------------------------------------------- - - /** - * Show columnn 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 _show_columns($table = '') - { - return "SHOW COLUMNS FROM ".$this->escape_table($table); - } - - // -------------------------------------------------------------------- - - /** - * 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); - } - -} - - -?> \ No newline at end of file diff --git a/system/database/drivers/postgre/postgre.php b/system/database/drivers/postgre/postgre.php deleted file mode 100644 index 317df37d1..000000000 --- a/system/database/drivers/postgre/postgre.php +++ /dev/null @@ -1,484 +0,0 @@ -port == '') ? '' : " port=".$this->port; - - return pg_connect("host=".$this->hostname.$port." dbname=".$this->database." user=".$this->username." password=".$this->password); - } - - // -------------------------------------------------------------------- - - /** - * Persistent database connection - * - * @access private called by the base class - * @return resource - */ - function db_pconnect() - { - $port = ($this->port == '') ? '' : " port=".$this->port; - - return pg_pconnect("host=".$this->hostname.$port." dbname=".$this->database." user=".$this->username." password=".$this->password); - } - - // -------------------------------------------------------------------- - - /** - * 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; - } - - // -------------------------------------------------------------------- - - /** - * 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 - * @return string - */ - function escape_str($str) - { - return pg_escape_string($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 = pg_version($this->conn_id); - $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('SELECT COUNT(*) AS numrows FROM "'.$this->dbprefix.$table.'"'); - - if ($query->num_rows() == 0) - return '0'; - - $row = $query->row(); - return $row->numrows; - } - - // -------------------------------------------------------------------- - - /** - * The error message string - * - * @access public - * @return string - */ - function error_message() - { - return pg_last_error($this->conn_id); - } - - // -------------------------------------------------------------------- - - /** - * The error message number - * - * @access public - * @return integer - */ - function error_number() - { - return ''; - } - - // -------------------------------------------------------------------- - - /** - * 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 public - * @param string the table name - * @return string - */ - function escape_table($table) - { - if (stristr($table, '.')) - { - $table = '"'.preg_replace("/\./", '"."', $table).'"'; - } - - return $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) - { - $sql = "SELECT * FROM ".$this->escape_table($table)." LIMIT 1"; - $query = $this->query($sql); - return $query->field_data(); - } - - // -------------------------------------------------------------------- - - /** - * 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 - * @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); - } - - // -------------------------------------------------------------------- - - /** - * Delete statement - * - * Generates a platform-specific delete string from the supplied data - * - * @access public - * @param string the table name - * @param array the where clause - * @return string - */ - function _delete($table, $where) - { - return "DELETE FROM ".$this->escape_table($table)." WHERE ".implode(" ", $where); - } - - // -------------------------------------------------------------------- - - /** - * Version number query string - * - * @access public - * @return string - */ - function _version() - { - return "SELECT version() AS ver"; - } - - /** - * Show table query - * - * Generates a platform-specific query string so that the table names can be fetched - * - * @access public - * @return string - */ - function _show_tables() - { - return "SELECT table_name FROM information_schema.tables WHERE table_schema = 'public'"; - } - - // -------------------------------------------------------------------- - - /** - * Show columnn 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 _show_columns($table = '') - { - return "SELECT column_name FROM information_schema.columns WHERE table_name ='".$this->escape_table($table)."'"; - } - - // -------------------------------------------------------------------- - - /** - * 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); - } - -} - -?> \ No newline at end of file diff --git a/system/database/drivers/sqlite/sqlite.php b/system/database/drivers/sqlite/sqlite.php deleted file mode 100644 index 6116a84ab..000000000 --- a/system/database/drivers/sqlite/sqlite.php +++ /dev/null @@ -1,481 +0,0 @@ -database, 0666, $error)) - { - log_message('error', $error); - - if ($this->db_debug) - { - $this->display_error($error, '', TRUE); - } - } - - 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, 0666, $error)) - { - log_message('error', $error); - - if ($this->db_debug) - { - $this->display_error($error, '', TRUE); - } - } - - return $conn_id; - } - - // -------------------------------------------------------------------- - - /** - * Select the database - * - * @access private called by the base class - * @return resource - */ - function db_select() - { - 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 @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 - * @return string - */ - function escape_str($str) - { - return sqlite_escape_string($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("SELECT COUNT(*) AS numrows FROM `".$this->dbprefix.$table."`"); - - if ($query->num_rows() == 0) - return '0'; - - $row = $query->row(); - return $row->numrows; - } - - // -------------------------------------------------------------------- - - /** - * The error message string - * - * @access public - * @return string - */ - function error_message() - { - return sqlite_error_string(sqlite_last_error($this->conn_id)); - } - - // -------------------------------------------------------------------- - - /** - * The error message number - * - * @access public - * @return integer - */ - function error_number() - { - return sqlite_last_error($this->conn_id); - } - - // -------------------------------------------------------------------- - - /** - * Version number query string - * - * @access public - * @return string - */ - function version() - { - return sqlite_libversion(); - } - - // -------------------------------------------------------------------- - - /** - * 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 public - * @param string the table name - * @return string - */ - function escape_table($table) - { - if (stristr($table, '.')) - { - $table = preg_replace("/\./", "`.`", $table); - } - - return $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) - { - $sql = "SELECT * FROM ".$this->escape_table($table)." LIMIT 1"; - $query = $this->query($sql); - return $query->field_data(); - } - - // -------------------------------------------------------------------- - - /** - * 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 - * @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); - } - - // -------------------------------------------------------------------- - - /** - * Delete statement - * - * Generates a platform-specific delete string from the supplied data - * - * @access public - * @param string the table name - * @param array the where clause - * @return string - */ - function _delete($table, $where) - { - return "DELETE FROM ".$this->escape_table($table)." WHERE ".implode(" ", $where); - } - - // -------------------------------------------------------------------- - - /** - * Show table query - * - * Generates a platform-specific query string so that the table names can be fetched - * - * @access public - * @return string - */ - function _show_tables() - { - return "SELECT name from sqlite_master WHERE type='table'"; - } - - // -------------------------------------------------------------------- - - /** - * Show columnn 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 _show_columns($table = '') - { - // Not supported - return FALSE; - } - - // -------------------------------------------------------------------- - - /** - * 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); - } - -} - -?> \ No newline at end of file diff --git a/system/libraries/Controller.php b/system/libraries/Controller.php index 5be10500b..61c8363fa 100644 --- a/system/libraries/Controller.php +++ b/system/libraries/Controller.php @@ -381,10 +381,10 @@ class Controller extends CI_Base { } } - require_once(BASEPATH.'database/drivers/'.$params['dbdriver'].'/'.$params['dbdriver'].EXT); + require_once(BASEPATH.'database/drivers/'.$params['dbdriver'].'/'.$params['dbdriver'].'_driver'.EXT); // Instantiate the DB adapter - $driver = 'CI_DB_'. $params['dbdriver']; + $driver = 'CI_DB_'. $params['dbdriver'].'_driver'; $DB = new $driver($params); if ($return === TRUE) -- cgit v1.2.3-24-g4f1b From bb1d439a981023415569549d8b8c4987fa5b9b51 Mon Sep 17 00:00:00 2001 From: admin Date: Sun, 24 Sep 2006 20:14:38 +0000 Subject: --- system/database/DB_driver.php | 82 +++++++++++- system/database/DB_utility.php | 95 ++++--------- system/database/drivers/mssql/mssql_driver.php | 109 +++++++-------- system/database/drivers/mysql/mysql_driver.php | 124 ++++++++--------- system/database/drivers/mysqli/mysqli_driver.php | 119 ++++++++-------- system/database/drivers/oci8/oci8_driver.php | 121 ++++++++--------- system/database/drivers/odbc/odbc_driver.php | 107 +++++++-------- system/database/drivers/postgre/postgre_driver.php | 117 ++++++++-------- system/database/drivers/sqlite/sqlite_driver.php | 149 +++++++++++---------- 9 files changed, 533 insertions(+), 490 deletions(-) (limited to 'system') diff --git a/system/database/DB_driver.php b/system/database/DB_driver.php index ef37967dc..3f7c82627 100644 --- a/system/database/DB_driver.php +++ b/system/database/DB_driver.php @@ -190,11 +190,11 @@ class CI_DB_driver { if ($this->db_debug) { - log_message('error', 'Query error: '.$this->error_message()); + log_message('error', 'Query error: '.$this->_error_message()); return $this->display_error( array( - 'Error Number: '.$this->error_number(), - $this->error_message(), + 'Error Number: '.$this->_error_number(), + $this->_error_message(), $sql ) ); @@ -481,7 +481,81 @@ class CI_DB_driver { } return $str; - } + } + + // -------------------------------------------------------------------- + + /** + * 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[] = $key; + $values[] = $this->escape($val); + } + + return $this->_insert($this->dbprefix.$table, $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[$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->dbprefix.$table, $fields, $dest); + } // -------------------------------------------------------------------- diff --git a/system/database/DB_utility.php b/system/database/DB_utility.php index a4d4eb0d1..39dc2cca2 100644 --- a/system/database/DB_utility.php +++ b/system/database/DB_utility.php @@ -202,79 +202,42 @@ class CI_DB_utility { return current($fields); } - // -------------------------------------------------------------------- - /** - * 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[] = $key; - $values[] = $this->escape($val); - } - return $this->_insert($this->dbprefix.$table, $fields, $values); + + + function create_database() + { } - // -------------------------------------------------------------------- - - /** - * 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) + function drop_database() { - if ($where == '') - return false; - - $fields = array(); - foreach($data as $key => $val) - { - $fields[$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; - } - } + function show_databases() + { + } + + function create_table() + { + } + + function alter_table() + { + } + + function create_index() + { + } + + function drop_index() + { + } + + function optimize() + { + } - return $this->_update($this->dbprefix.$table, $fields, $dest); - } } diff --git a/system/database/drivers/mssql/mssql_driver.php b/system/database/drivers/mssql/mssql_driver.php index 4f668f282..cd808da46 100644 --- a/system/database/drivers/mssql/mssql_driver.php +++ b/system/database/drivers/mssql/mssql_driver.php @@ -251,10 +251,10 @@ class CI_DB_mssql_driver extends CI_DB { /** * The error message string * - * @access public + * @access private * @return string */ - function error_message() + function _error_message() { // Are errros even supported in MS SQL? return ''; @@ -265,10 +265,10 @@ class CI_DB_mssql_driver extends CI_DB { /** * The error message number * - * @access public + * @access private * @return integer */ - function error_number() + function _error_number() { // Are error numbers supported? return ''; @@ -282,11 +282,11 @@ class CI_DB_mssql_driver extends CI_DB { * This function adds backticks if the table name has a period * in it. Some DBs will get cranky unless periods are escaped * - * @access public + * @access private * @param string the table name * @return string */ - function escape_table($table) + function _escape_table($table) { if (stristr($table, '.')) { @@ -294,25 +294,7 @@ class CI_DB_mssql_driver extends CI_DB { } return $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) - { - $sql = "SELECT TOP 1 FROM ".$this->escape_table($table); - $query = $this->query($sql); - return $query->field_data(); - } + } // -------------------------------------------------------------------- @@ -329,7 +311,7 @@ class CI_DB_mssql_driver extends CI_DB { */ function _insert($table, $keys, $values) { - return "INSERT INTO ".$this->escape_table($table)." (".implode(', ', $keys).") VALUES (".implode(', ', $values).")"; + return "INSERT INTO ".$this->_escape_table($table)." (".implode(', ', $keys).") VALUES (".implode(', ', $values).")"; } // -------------------------------------------------------------------- @@ -352,7 +334,7 @@ class CI_DB_mssql_driver extends CI_DB { $valstr[] = $key." = ".$val; } - return "UPDATE ".$this->escape_table($table)." SET ".implode(', ', $valstr)." WHERE ".implode(" ", $where); + return "UPDATE ".$this->_escape_table($table)." SET ".implode(', ', $valstr)." WHERE ".implode(" ", $where); } // -------------------------------------------------------------------- @@ -369,9 +351,43 @@ class CI_DB_mssql_driver extends CI_DB { */ function _delete($table, $where) { - return "DELETE FROM ".$this->escape_table($table)." WHERE ".implode(" ", $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) + { + mssql_close($conn_id); + } + // -------------------------------------------------------------------- /** @@ -413,43 +429,28 @@ class CI_DB_mssql_driver extends CI_DB { */ function _show_columns($table = '') { - return "SELECT * FROM INFORMATION_SCHEMA.Columns WHERE TABLE_NAME = '".$this->escape_table($table)."'"; - } - - // -------------------------------------------------------------------- - - /** - * 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); + return "SELECT * FROM INFORMATION_SCHEMA.Columns WHERE TABLE_NAME = '".$this->_escape_table($table)."'"; } // -------------------------------------------------------------------- /** - * Close DB Connection + * Field data query + * + * Generates a platform-specific query so that the column data can be retrieved * * @access public - * @param resource - * @return void + * @param string the table name + * @return object */ - function _close($conn_id) + function _field_data($table) { - mssql_close($conn_id); + $sql = "SELECT TOP 1 FROM ".$this->_escape_table($table); + $query = $this->query($sql); + return $query->field_data(); } + } diff --git a/system/database/drivers/mysql/mysql_driver.php b/system/database/drivers/mysql/mysql_driver.php index 8aa82da72..fc7f6780b 100644 --- a/system/database/drivers/mysql/mysql_driver.php +++ b/system/database/drivers/mysql/mysql_driver.php @@ -269,10 +269,10 @@ class CI_DB_mysql_driver extends CI_DB { /** * The error message string * - * @access public + * @access private * @return string */ - function error_message() + function _error_message() { return mysql_error($this->conn_id); } @@ -282,10 +282,10 @@ class CI_DB_mysql_driver extends CI_DB { /** * The error message number * - * @access public + * @access private * @return integer */ - function error_number() + function _error_number() { return mysql_errno($this->conn_id); } @@ -298,11 +298,11 @@ class CI_DB_mysql_driver extends CI_DB { * This function adds backticks if the table name has a period * in it. Some DBs will get cranky unless periods are escaped * - * @access public + * @access private * @param string the table name * @return string */ - function escape_table($table) + function _escape_table($table) { if (stristr($table, '.')) { @@ -311,25 +311,7 @@ class CI_DB_mysql_driver extends CI_DB { return $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) - { - $sql = "SELECT * FROM ".$this->escape_table($table)." LIMIT 1"; - $query = $this->query($sql); - return $query->field_data(); - } - + // -------------------------------------------------------------------- /** @@ -345,7 +327,7 @@ class CI_DB_mysql_driver extends CI_DB { */ function _insert($table, $keys, $values) { - return "INSERT INTO ".$this->escape_table($table)." (".implode(', ', $keys).") VALUES (".implode(', ', $values).")"; + return "INSERT INTO ".$this->_escape_table($table)." (".implode(', ', $keys).") VALUES (".implode(', ', $values).")"; } // -------------------------------------------------------------------- @@ -368,7 +350,7 @@ class CI_DB_mysql_driver extends CI_DB { $valstr[] = $key." = ".$val; } - return "UPDATE ".$this->escape_table($table)." SET ".implode(', ', $valstr)." WHERE ".implode(" ", $where); + return "UPDATE ".$this->_escape_table($table)." SET ".implode(', ', $valstr)." WHERE ".implode(" ", $where); } // -------------------------------------------------------------------- @@ -385,9 +367,50 @@ class CI_DB_mysql_driver extends CI_DB { */ function _delete($table, $where) { - return "DELETE FROM ".$this->escape_table($table)." WHERE ".implode(" ", $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) + { + 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); + } + // -------------------------------------------------------------------- /** @@ -429,48 +452,25 @@ class CI_DB_mysql_driver extends CI_DB { */ function _show_columns($table = '') { - return "SHOW COLUMNS FROM ".$this->escape_table($table); - } - - // -------------------------------------------------------------------- - - /** - * 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; + return "SHOW COLUMNS FROM ".$this->_escape_table($table); } // -------------------------------------------------------------------- /** - * Close DB Connection + * Field data query + * + * Generates a platform-specific query so that the column data can be retrieved * * @access public - * @param resource - * @return void + * @param string the table name + * @return object */ - function _close($conn_id) + function _field_data($table) { - mysql_close($conn_id); + $sql = "SELECT * FROM ".$this->_escape_table($table)." LIMIT 1"; + $query = $this->query($sql); + return $query->field_data(); } } diff --git a/system/database/drivers/mysqli/mysqli_driver.php b/system/database/drivers/mysqli/mysqli_driver.php index 8d28c2c5f..959384164 100644 --- a/system/database/drivers/mysqli/mysqli_driver.php +++ b/system/database/drivers/mysqli/mysqli_driver.php @@ -272,10 +272,10 @@ class CI_DB_mysqli_driver extends CI_DB { /** * The error message string * - * @access public + * @access private * @return string */ - function error_message() + function _error_message() { return mysqli_error($this->conn_id); } @@ -285,10 +285,10 @@ class CI_DB_mysqli_driver extends CI_DB { /** * The error message number * - * @access public + * @access private * @return integer */ - function error_number() + function _error_number() { return mysqli_errno($this->conn_id); } @@ -301,11 +301,11 @@ class CI_DB_mysqli_driver extends CI_DB { * This function adds backticks if the table name has a period * in it. Some DBs will get cranky unless periods are escaped * - * @access public + * @access private * @param string the table name * @return string */ - function escape_table($table) + function _escape_table($table) { if (stristr($table, '.')) { @@ -314,25 +314,7 @@ class CI_DB_mysqli_driver extends CI_DB { return $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) - { - $sql = "SELECT * FROM ".$this->escape_table($table)." LIMIT 1"; - $query = $this->query($sql); - return $query->field_data(); - } - + // -------------------------------------------------------------------- /** @@ -348,7 +330,7 @@ class CI_DB_mysqli_driver extends CI_DB { */ function _insert($table, $keys, $values) { - return "INSERT INTO ".$this->escape_table($table)." (".implode(', ', $keys).") VALUES (".implode(', ', $values).")"; + return "INSERT INTO ".$this->_escape_table($table)." (".implode(', ', $keys).") VALUES (".implode(', ', $values).")"; } // -------------------------------------------------------------------- @@ -371,7 +353,7 @@ class CI_DB_mysqli_driver extends CI_DB { $valstr[] = $key." = ".$val; } - return "UPDATE ".$this->escape_table($table)." SET ".implode(', ', $valstr)." WHERE ".implode(" ", $where); + return "UPDATE ".$this->_escape_table($table)." SET ".implode(', ', $valstr)." WHERE ".implode(" ", $where); } // -------------------------------------------------------------------- @@ -388,9 +370,48 @@ class CI_DB_mysqli_driver extends CI_DB { */ function _delete($table, $where) { - return "DELETE FROM ".$this->escape_table($table)." WHERE ".implode(" ", $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) + { + $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); + } + // -------------------------------------------------------------------- /** @@ -432,47 +453,27 @@ class CI_DB_mysqli_driver extends CI_DB { */ function _show_columns($table = '') { - return "SHOW COLUMNS FROM ".$this->escape_table($table); - } - - // -------------------------------------------------------------------- - - /** - * 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; + return "SHOW COLUMNS FROM ".$this->_escape_table($table); } // -------------------------------------------------------------------- /** - * Close DB Connection + * Field data query + * + * Generates a platform-specific query so that the column data can be retrieved * * @access public - * @param resource - * @return void + * @param string the table name + * @return object */ - function _close($conn_id) + function _field_data($table) { - mysqli_close($conn_id); + $sql = "SELECT * FROM ".$this->_escape_table($table)." LIMIT 1"; + $query = $this->query($sql); + return $query->field_data(); } + } diff --git a/system/database/drivers/oci8/oci8_driver.php b/system/database/drivers/oci8/oci8_driver.php index 707394d53..bfc38a435 100644 --- a/system/database/drivers/oci8/oci8_driver.php +++ b/system/database/drivers/oci8/oci8_driver.php @@ -393,10 +393,10 @@ class CI_DB_oci8_driver extends CI_DB { /** * The error message string * - * @access public + * @access private * @return string */ - function error_message() + function _error_message() { $error = ocierror($this->conn_id); return $error['message']; @@ -407,10 +407,10 @@ class CI_DB_oci8_driver extends CI_DB { /** * The error message number * - * @access public + * @access private * @return integer */ - function error_number() + function _error_number() { $error = ocierror($this->conn_id); return $error['code']; @@ -424,11 +424,11 @@ class CI_DB_oci8_driver extends CI_DB { * This function adds backticks if the table name has a period * in it. Some DBs will get cranky unless periods are escaped * - * @access public + * @access private * @param string the table name * @return string */ - function escape_table($table) + function _escape_table($table) { if (stristr($table, '.')) { @@ -440,24 +440,6 @@ class CI_DB_oci8_driver extends CI_DB { // -------------------------------------------------------------------- - /** - * 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) - { - $sql = "SELECT * FROM ".$this->escape_table($table)." where rownum = 1"; - $query = $this->query($sql); - return $query->field_data(); - } - - // -------------------------------------------------------------------- - /** * Insert statement * @@ -471,7 +453,7 @@ class CI_DB_oci8_driver extends CI_DB { */ function _insert($table, $keys, $values) { - return "INSERT INTO ".$this->escape_table($table)." (".implode(', ', $keys).") VALUES (".implode(', ', $values).")"; + return "INSERT INTO ".$this->_escape_table($table)." (".implode(', ', $keys).") VALUES (".implode(', ', $values).")"; } // -------------------------------------------------------------------- @@ -494,7 +476,7 @@ class CI_DB_oci8_driver extends CI_DB { $valstr[] = $key." = ".$val; } - return "UPDATE ".$this->escape_table($table)." SET ".implode(', ', $valstr)." WHERE ".implode(" ", $where); + return "UPDATE ".$this->_escape_table($table)." SET ".implode(', ', $valstr)." WHERE ".implode(" ", $where); } // -------------------------------------------------------------------- @@ -511,7 +493,50 @@ class CI_DB_oci8_driver extends CI_DB { */ function _delete($table, $where) { - return "DELETE FROM ".$this->escape_table($table)." WHERE ".implode(" ", $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) + { + $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 public + * @param resource + * @return void + */ + function _close($conn_id) + { + ocilogoff($conn_id); } // -------------------------------------------------------------------- @@ -562,46 +587,22 @@ class CI_DB_oci8_driver extends CI_DB { // -------------------------------------------------------------------- /** - * Limit string - * - * Generates a platform-specific LIMIT clause + * Field data query * - * @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) - { - $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 + * Generates a platform-specific query so that the column data can be retrieved * * @access public - * @param resource - * @return void + * @param string the table name + * @return object */ - function _close($conn_id) + function _field_data($table) { - ocilogoff($conn_id); + $sql = "SELECT * FROM ".$this->_escape_table($table)." where rownum = 1"; + $query = $this->query($sql); + return $query->field_data(); } + } diff --git a/system/database/drivers/odbc/odbc_driver.php b/system/database/drivers/odbc/odbc_driver.php index 1725ed743..c05abd082 100644 --- a/system/database/drivers/odbc/odbc_driver.php +++ b/system/database/drivers/odbc/odbc_driver.php @@ -252,10 +252,10 @@ class CI_DB_odbc_driver extends CI_DB { /** * The error message string * - * @access public + * @access private * @return string */ - function error_message() + function _error_message() { return odbc_errormsg($this->conn_id); } @@ -265,10 +265,10 @@ class CI_DB_odbc_driver extends CI_DB { /** * The error message number * - * @access public + * @access private * @return integer */ - function error_number() + function _error_number() { return odbc_error($this->conn_id); } @@ -281,11 +281,11 @@ class CI_DB_odbc_driver extends CI_DB { * This function adds backticks if the table name has a period * in it. Some DBs will get cranky unless periods are escaped * - * @access public + * @access private * @param string the table name * @return string */ - function escape_table($table) + function _escape_table($table) { if (stristr($table, '.')) { @@ -294,25 +294,7 @@ class CI_DB_odbc_driver extends CI_DB { return $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) - { - $sql = "SELECT TOP 1 FROM ".$this->escape_table($table); - $query = $this->query($sql); - return $query->field_data(); - } - + // -------------------------------------------------------------------- /** @@ -328,7 +310,7 @@ class CI_DB_odbc_driver extends CI_DB { */ function _insert($table, $keys, $values) { - return "INSERT INTO ".$this->escape_table($table)." (".implode(', ', $keys).") VALUES (".implode(', ', $values).")"; + return "INSERT INTO ".$this->_escape_table($table)." (".implode(', ', $keys).") VALUES (".implode(', ', $values).")"; } // -------------------------------------------------------------------- @@ -351,7 +333,7 @@ class CI_DB_odbc_driver extends CI_DB { $valstr[] = $key." = ".$val; } - return "UPDATE ".$this->escape_table($table)." SET ".implode(', ', $valstr)." WHERE ".implode(" ", $where); + return "UPDATE ".$this->_escape_table($table)." SET ".implode(', ', $valstr)." WHERE ".implode(" ", $where); } // -------------------------------------------------------------------- @@ -368,9 +350,42 @@ class CI_DB_odbc_driver extends CI_DB { */ function _delete($table, $where) { - return "DELETE FROM ".$this->escape_table($table)." WHERE ".implode(" ", $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) + { + // 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); + } + // -------------------------------------------------------------------- /** @@ -412,41 +427,27 @@ class CI_DB_odbc_driver extends CI_DB { */ function _show_columns($table = '') { - return "SHOW COLUMNS FROM ".$this->escape_table($table); + return "SHOW COLUMNS FROM ".$this->_escape_table($table); } - + // -------------------------------------------------------------------- /** - * Limit string + * Field data query * - * Generates a platform-specific LIMIT clause + * Generates a platform-specific query so that the column data can be retrieved * * @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 + * @param string the table name + * @return object */ - function _limit($sql, $limit, $offset) + function _field_data($table) { - // Does ODBC doesn't use the LIMIT clause? - return $sql; + $sql = "SELECT TOP 1 FROM ".$this->_escape_table($table); + $query = $this->query($sql); + return $query->field_data(); } - // -------------------------------------------------------------------- - - /** - * Close DB Connection - * - * @access public - * @param resource - * @return void - */ - function _close($conn_id) - { - odbc_close($conn_id); - } } diff --git a/system/database/drivers/postgre/postgre_driver.php b/system/database/drivers/postgre/postgre_driver.php index 92767c42b..03817188f 100644 --- a/system/database/drivers/postgre/postgre_driver.php +++ b/system/database/drivers/postgre/postgre_driver.php @@ -279,10 +279,10 @@ class CI_DB_postgre_driver extends CI_DB { /** * The error message string * - * @access public + * @access private * @return string */ - function error_message() + function _error_message() { return pg_last_error($this->conn_id); } @@ -292,10 +292,10 @@ class CI_DB_postgre_driver extends CI_DB { /** * The error message number * - * @access public + * @access private * @return integer */ - function error_number() + function _error_number() { return ''; } @@ -308,11 +308,11 @@ class CI_DB_postgre_driver extends CI_DB { * This function adds backticks if the table name has a period * in it. Some DBs will get cranky unless periods are escaped. * - * @access public + * @access private * @param string the table name * @return string */ - function escape_table($table) + function _escape_table($table) { if (stristr($table, '.')) { @@ -324,24 +324,6 @@ class CI_DB_postgre_driver extends CI_DB { // -------------------------------------------------------------------- - /** - * 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) - { - $sql = "SELECT * FROM ".$this->escape_table($table)." LIMIT 1"; - $query = $this->query($sql); - return $query->field_data(); - } - - // -------------------------------------------------------------------- - /** * Insert statement * @@ -355,7 +337,7 @@ class CI_DB_postgre_driver extends CI_DB { */ function _insert($table, $keys, $values) { - return "INSERT INTO ".$this->escape_table($table)." (".implode(', ', $keys).") VALUES (".implode(', ', $values).")"; + return "INSERT INTO ".$this->_escape_table($table)." (".implode(', ', $keys).") VALUES (".implode(', ', $values).")"; } // -------------------------------------------------------------------- @@ -378,7 +360,7 @@ class CI_DB_postgre_driver extends CI_DB { $valstr[] = $key." = ".$val; } - return "UPDATE ".$this->escape_table($table)." SET ".implode(', ', $valstr)." WHERE ".implode(" ", $where); + return "UPDATE ".$this->_escape_table($table)." SET ".implode(', ', $valstr)." WHERE ".implode(" ", $where); } // -------------------------------------------------------------------- @@ -395,9 +377,48 @@ class CI_DB_postgre_driver extends CI_DB { */ function _delete($table, $where) { - return "DELETE FROM ".$this->escape_table($table)." WHERE ".implode(" ", $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) + { + $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); + } + // -------------------------------------------------------------------- /** @@ -437,48 +458,28 @@ class CI_DB_postgre_driver extends CI_DB { */ function _show_columns($table = '') { - return "SELECT column_name FROM information_schema.columns WHERE table_name ='".$this->escape_table($table)."'"; - } - - // -------------------------------------------------------------------- - - /** - * 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; + return "SELECT column_name FROM information_schema.columns WHERE table_name ='".$this->_escape_table($table)."'"; } // -------------------------------------------------------------------- /** - * Close DB Connection + * Field data query + * + * Generates a platform-specific query so that the column data can be retrieved * * @access public - * @param resource - * @return void + * @param string the table name + * @return object */ - function _close($conn_id) + function _field_data($table) { - pg_close($conn_id); + $sql = "SELECT * FROM ".$this->_escape_table($table)." LIMIT 1"; + $query = $this->query($sql); + return $query->field_data(); } + } ?> \ No newline at end of file diff --git a/system/database/drivers/sqlite/sqlite_driver.php b/system/database/drivers/sqlite/sqlite_driver.php index 634b72ed4..f8318b814 100644 --- a/system/database/drivers/sqlite/sqlite_driver.php +++ b/system/database/drivers/sqlite/sqlite_driver.php @@ -271,10 +271,10 @@ class CI_DB_sqlite_driver extends CI_DB { /** * The error message string * - * @access public + * @access private * @return string */ - function error_message() + function _error_message() { return sqlite_error_string(sqlite_last_error($this->conn_id)); } @@ -284,27 +284,14 @@ class CI_DB_sqlite_driver extends CI_DB { /** * The error message number * - * @access public + * @access private * @return integer */ - function error_number() + function _error_number() { return sqlite_last_error($this->conn_id); } - - // -------------------------------------------------------------------- - - /** - * Version number query string - * - * @access public - * @return string - */ - function version() - { - return sqlite_libversion(); - } - + // -------------------------------------------------------------------- /** @@ -313,11 +300,11 @@ class CI_DB_sqlite_driver extends CI_DB { * This function adds backticks if the table name has a period * in it. Some DBs will get cranky unless periods are escaped * - * @access public + * @access private * @param string the table name * @return string */ - function escape_table($table) + function _escape_table($table) { if (stristr($table, '.')) { @@ -326,25 +313,7 @@ class CI_DB_sqlite_driver extends CI_DB { return $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) - { - $sql = "SELECT * FROM ".$this->escape_table($table)." LIMIT 1"; - $query = $this->query($sql); - return $query->field_data(); - } - + // -------------------------------------------------------------------- /** @@ -360,7 +329,7 @@ class CI_DB_sqlite_driver extends CI_DB { */ function _insert($table, $keys, $values) { - return "INSERT INTO ".$this->escape_table($table)." (".implode(', ', $keys).") VALUES (".implode(', ', $values).")"; + return "INSERT INTO ".$this->_escape_table($table)." (".implode(', ', $keys).") VALUES (".implode(', ', $values).")"; } // -------------------------------------------------------------------- @@ -383,7 +352,7 @@ class CI_DB_sqlite_driver extends CI_DB { $valstr[] = $key." = ".$val; } - return "UPDATE ".$this->escape_table($table)." SET ".implode(', ', $valstr)." WHERE ".implode(" ", $where); + return "UPDATE ".$this->_escape_table($table)." SET ".implode(', ', $valstr)." WHERE ".implode(" ", $where); } // -------------------------------------------------------------------- @@ -400,41 +369,9 @@ class CI_DB_sqlite_driver extends CI_DB { */ function _delete($table, $where) { - return "DELETE FROM ".$this->escape_table($table)." WHERE ".implode(" ", $where); - } - - // -------------------------------------------------------------------- - - /** - * Show table query - * - * Generates a platform-specific query string so that the table names can be fetched - * - * @access public - * @return string - */ - function _show_tables() - { - return "SELECT name from sqlite_master WHERE type='table'"; + return "DELETE FROM ".$this->_escape_table($table)." WHERE ".implode(" ", $where); } - - // -------------------------------------------------------------------- - /** - * Show columnn 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 _show_columns($table = '') - { - // Not supported - return FALSE; - } - // -------------------------------------------------------------------- /** @@ -476,6 +413,70 @@ class CI_DB_sqlite_driver extends CI_DB { sqlite_close($conn_id); } + // -------------------------------------------------------------------- + + /** + * Version number query string + * + * @access public + * @return string + */ + function _version() + { + return sqlite_libversion(); + } + + // -------------------------------------------------------------------- + + /** + * Show table query + * + * Generates a platform-specific query string so that the table names can be fetched + * + * @access public + * @return string + */ + function _show_tables() + { + return "SELECT name from sqlite_master WHERE type='table'"; + } + + // -------------------------------------------------------------------- + + /** + * Show columnn 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 _show_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) + { + $sql = "SELECT * FROM ".$this->_escape_table($table)." LIMIT 1"; + $query = $this->query($sql); + return $query->field_data(); + } + + } ?> \ No newline at end of file -- cgit v1.2.3-24-g4f1b From 1716d5880b5b8d26db5608922f88adcf1ff8077c Mon Sep 17 00:00:00 2001 From: admin Date: Sun, 24 Sep 2006 20:15:03 +0000 Subject: --- system/database/DB_export.php | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 system/database/DB_export.php (limited to 'system') diff --git a/system/database/DB_export.php b/system/database/DB_export.php new file mode 100644 index 000000000..195510d9d --- /dev/null +++ b/system/database/DB_export.php @@ -0,0 +1,41 @@ + \ No newline at end of file -- cgit v1.2.3-24-g4f1b From ac94f38e9f501721d3148c94b3962a529f646e20 Mon Sep 17 00:00:00 2001 From: admin Date: Sun, 24 Sep 2006 20:28:12 +0000 Subject: --- system/database/DB_active_rec.php | 875 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 875 insertions(+) create mode 100644 system/database/DB_active_rec.php (limited to 'system') diff --git a/system/database/DB_active_rec.php b/system/database/DB_active_rec.php new file mode 100644 index 000000000..c038185bc --- /dev/null +++ b/system/database/DB_active_rec.php @@ -0,0 +1,875 @@ +ar_select[] = $val; + } + return $this; + } + + // -------------------------------------------------------------------- + + /** + * DISTINCT + * + * Sets a flag which tells the query string compiler to add DISTINCT + * + * @access public + * @param bool + * @return object + */ + function distinct($val = TRUE) + { + $this->ar_distinct = (is_bool($val)) ? $val : TRUE; + return $this; + } + + // -------------------------------------------------------------------- + + /** + * From + * + * Generates the FROM portion of the query + * + * @access public + * @param mixed can be a string or array + * @return object + */ + function from($from) + { + foreach ((array)$from as $val) + { + $this->ar_from[] = $this->dbprefix.$val; + } + return $this; + } + + // -------------------------------------------------------------------- + + /** + * Join + * + * Generates the JOIN portion of the query + * + * @access public + * @param string + * @param string the join condition + * @param string the type of join + * @return object + */ + 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 .= ' '; + } + } + + $this->ar_join[] = $type.'JOIN '.$table.' ON '.$cond; + return $this; + } + + // -------------------------------------------------------------------- + + /** + * Where + * + * Generates the WHERE portion of the query. Separates + * multiple calls with AND + * + * @access public + * @param mixed + * @param mixed + * @return object + */ + function where($key, $value = NULL) + { + return $this->_where($key, $value, 'AND '); + } + + // -------------------------------------------------------------------- + + /** + * OR Where + * + * Generates the WHERE portion of the query. Separates + * multiple calls with OR + * + * @access public + * @param mixed + * @param mixed + * @return object + */ + function orwhere($key, $value = NULL) + { + return $this->_where($key, $value, 'OR '); + } + + // -------------------------------------------------------------------- + + /** + * Where + * + * Called by where() or orwhere() + * + * @access private + * @param mixed + * @param mixed + * @param string + * @return object + */ + function _where($key, $value = NULL, $type = 'AND ') + { + if ( ! is_array($key)) + { + $key = array($key => $value); + } + + foreach ($key as $k => $v) + { + $prefix = (count($this->ar_where) == 0) ? '' : $type; + + if ( ! is_null($v)) + { + if ( ! $this->_has_operator($k)) + { + $k .= ' ='; + } + + $v = ' '.$this->escape($v); + } + + $this->ar_where[] = $prefix.$k.$v; + } + return $this; + } + + + + // -------------------------------------------------------------------- + + /** + * Like + * + * Generates a %LIKE% portion of the query. Separates + * multiple calls with AND + * + * @access public + * @param mixed + * @param mixed + * @return object + */ + function like($field, $match = '') + { + return $this->_like($field, $match, 'AND '); + } + + // -------------------------------------------------------------------- + + /** + * OR Like + * + * Generates a %LIKE% portion of the query. Separates + * multiple calls with OR + * + * @access public + * @param mixed + * @param mixed + * @return object + */ + function orlike($field, $match = '') + { + return $this->_like($field, $match, 'OR '); + } + + // -------------------------------------------------------------------- + + /** + * Like + * + * Called by like() or orlike() + * + * @access private + * @param mixed + * @param mixed + * @param string + * @return object + */ + function _like($field, $match = '', $type = 'AND ') + { + if ( ! is_array($field)) + { + $field = array($field => $match); + } + + foreach ($field as $k => $v) + { + $prefix = (count($this->ar_like) == 0) ? '' : $type; + + $v = $this->escape_str($v); + + $this->ar_like[] = $prefix." $k LIKE '%{$v}%'"; + } + return $this; + } + + // -------------------------------------------------------------------- + + /** + * GROUP BY + * + * @access public + * @param string + * @return object + */ + function groupby($by) + { + if (is_string($by)) + { + $by = explode(',', $by); + } + + foreach ($by as $val) + { + $val = trim($val); + + if ($val != '') + $this->ar_groupby[] = $val; + } + return $this; + } + + // -------------------------------------------------------------------- + + /** + * Sets the HAVING value + * + * Separates multiple calls with AND + * + * @access public + * @param string + * @param string + * @return object + */ + function having($key, $value = '') + { + return $this->_having($key, $value, 'AND '); + } + + // -------------------------------------------------------------------- + + /** + * Sets the OR HAVING value + * + * Separates multiple calls with OR + * + * @access public + * @param string + * @param string + * @return object + */ + function orhaving($key, $value = '') + { + return $this->_having($key, $value, 'OR '); + } + + // -------------------------------------------------------------------- + + /** + * Sets the HAVING values + * + * Called by having() or orhaving() + * + * @access private + * @param string + * @param string + * @return object + */ + function _having($key, $value = '', $type = 'AND ') + { + if ( ! is_array($key)) + { + $key = array($key => $value); + } + + foreach ($key as $k => $v) + { + $prefix = (count($this->ar_having) == 0) ? '' : $type; + + if ($v != '') + { + $v = ' '.$this->escape($v); + } + + $this->ar_having[] = $prefix.$k.$v; + } + return $this; + } + + // -------------------------------------------------------------------- + + /** + * Sets the ORDER BY value + * + * @access public + * @param string + * @param string direction: asc or desc + * @return object + */ + function orderby($orderby, $direction = '') + { + if (trim($direction) != '') + { + $direction = (in_array(strtoupper(trim($direction)), array('ASC', 'DESC', 'RAND()'))) ? ' '.$direction : ' ASC'; + } + + $this->ar_orderby[] = $orderby.$direction; + return $this; + } + + // -------------------------------------------------------------------- + + /** + * Sets the LIMIT value + * + * @access public + * @param integer the limit value + * @param integer the offset value + * @return object + */ + function limit($value, $offset = '') + { + $this->ar_limit = $value; + + if ($offset != '') + $this->ar_offset = $offset; + + return $this; + } + + // -------------------------------------------------------------------- + + /** + * Sets the OFFSET value + * + * @access public + * @param integer the offset value + * @return object + */ + function offset($value) + { + $this->ar_offset = $value; + return $this; + } + + // -------------------------------------------------------------------- + + /** + * The "set" function. Allows key/value pairs to be set for inserting or updating + * + * @access public + * @param mixed + * @param string + * @return object + */ + function set($key, $value = '') + { + $key = $this->_object_to_array($key); + + if ( ! is_array($key)) + { + $key = array($key => $value); + } + + foreach ($key as $k => $v) + { + $this->ar_set[$k] = $this->escape($v); + } + + return $this; + } + + // -------------------------------------------------------------------- + + /** + * Get + * + * Compiles the select statement based on the other functions called + * and runs the query + * + * @access public + * @param string the limit clause + * @param string the offset clause + * @return object + */ + function get($table = '', $limit = null, $offset = null) + { + if ($table != '') + { + $this->from($table); + } + + if ( ! is_null($limit)) + { + $this->limit($limit, $offset); + } + + $sql = $this->_compile_select(); + + $this->_reset_select(); + return $this->query($sql); + } + + // -------------------------------------------------------------------- + + /** + * GetWhere + * + * Allows the where clause, limit and offset to be added directly + * + * @access public + * @param string the where clause + * @param string the limit clause + * @param string the offset clause + * @return object + */ + function getwhere($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(); + + $this->_reset_select(); + return $this->query($sql); + } + + // -------------------------------------------------------------------- + + /** + * Insert + * + * Compiles an insert string and runs the query + * + * @access public + * @param string the table to retrieve the results from + * @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->dbprefix.$table, 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 + * + * @access public + * @param string the table to retrieve the results from + * @param array an associative array of update values + * @param mixed the where clause + * @return object + */ + function update($table = '', $set = NULL, $where = 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]; + } + + if ($where != null) + { + $this->where($where); + } + + $sql = $this->_update($this->dbprefix.$table, $this->ar_set, $this->ar_where); + + $this->_reset_write(); + return $this->query($sql); + } + + // -------------------------------------------------------------------- + + /** + * Delete + * + * Compiles a delete string and runs the query + * + * @access public + * @param string the table to retrieve the results from + * @param mixed the where clause + * @return object + */ + function delete($table = '', $where = '') + { + 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 != '') + { + $this->where($where); + } + + if (count($this->ar_where) == 0) + { + if ($this->db_debug) + { + return $this->display_error('db_del_must_use_where'); + } + return FALSE; + } + + $sql = $this->_delete($this->dbprefix.$table, $this->ar_where); + + $this->_reset_write(); + return $this->query($sql); + } + + // -------------------------------------------------------------------- + + /** + * Use Table - DEPRECATED + * + * @deprecated use $this->db->from instead + */ + function use_table($table) + { + return $this->from($table); + return $this; + } + + // -------------------------------------------------------------------- + + /** + * ORDER BY - DEPRECATED + * + * @deprecated use $this->db->orderby() instead + */ + function order_by($orderby, $direction = '') + { + return $this->orderby($orderby, $direction); + } + + // -------------------------------------------------------------------- + + /** + * 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; + } + + // -------------------------------------------------------------------- + + /** + * Compile the SELECT statement + * + * Generates a query string based on which functions were used. + * Should not be called directly. The get() function calls it. + * + * @access private + * @return string + */ + function _compile_select() + { + $sql = ( ! $this->ar_distinct) ? 'SELECT ' : 'SELECT DISTINCT '; + + $sql .= (count($this->ar_select) == 0) ? '*' : implode(', ', $this->ar_select); + + if (count($this->ar_from) > 0) + { + $sql .= "\nFROM "; + $sql .= implode(', ', $this->ar_from); + } + + if (count($this->ar_join) > 0) + { + $sql .= "\n"; + $sql .= implode("\n", $this->ar_join); + } + + if (count($this->ar_where) > 0 OR count($this->ar_like) > 0) + { + $sql .= "\nWHERE "; + } + + $sql .= implode("\n", $this->ar_where); + + if (count($this->ar_like) > 0) + { + if (count($this->ar_where) > 0) + { + $sql .= " AND "; + } + + $sql .= implode("\n", $this->ar_like); + } + + if (count($this->ar_groupby) > 0) + { + $sql .= "\nGROUP BY "; + $sql .= implode(', ', $this->ar_groupby); + } + + if (count($this->ar_having) > 0) + { + $sql .= "\nHAVING "; + $sql .= implode("\n", $this->ar_having); + } + + 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'; + } + } + + 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 convers the class variables to array key/vals + * + * @access public + * @param object + * @return array + */ + function _object_to_array($object) + { + if ( ! is_object($object)) + { + return $object; + } + + $array = array(); + foreach (get_object_vars($object) as $key => $val) + { + if ( ! is_object($val) AND ! is_array($val)) + { + $array[$key] = $val; + } + } + + return $array; + } + + // -------------------------------------------------------------------- + + /** + * Resets the active record values. Called by the get() function + * + * @access private + * @return void + */ + function _reset_select() + { + $this->ar_select = array(); + $this->ar_distinct = FALSE; + $this->ar_from = array(); + $this->ar_join = array(); + $this->ar_where = array(); + $this->ar_like = array(); + $this->ar_groupby = array(); + $this->ar_having = array(); + $this->ar_limit = FALSE; + $this->ar_offset = FALSE; + $this->ar_order = FALSE; + $this->ar_orderby = array(); + } + + // -------------------------------------------------------------------- + + /** + * Resets the active record "write" values. + * + * Called by the insert() or update() functions + * + * @access private + * @return void + */ + function _reset_write() + { + $this->ar_set = array(); + $this->ar_from = array(); + $this->ar_where = array(); + } + +} + +?> \ No newline at end of file -- cgit v1.2.3-24-g4f1b From c9a8bab572388bbba541f1cf8f12a46e2103e447 Mon Sep 17 00:00:00 2001 From: admin Date: Sun, 24 Sep 2006 20:28:33 +0000 Subject: --- system/database/DB_active_record.php | 875 ----------------------------------- system/libraries/Controller.php | 2 +- 2 files changed, 1 insertion(+), 876 deletions(-) delete mode 100644 system/database/DB_active_record.php (limited to 'system') diff --git a/system/database/DB_active_record.php b/system/database/DB_active_record.php deleted file mode 100644 index c038185bc..000000000 --- a/system/database/DB_active_record.php +++ /dev/null @@ -1,875 +0,0 @@ -ar_select[] = $val; - } - return $this; - } - - // -------------------------------------------------------------------- - - /** - * DISTINCT - * - * Sets a flag which tells the query string compiler to add DISTINCT - * - * @access public - * @param bool - * @return object - */ - function distinct($val = TRUE) - { - $this->ar_distinct = (is_bool($val)) ? $val : TRUE; - return $this; - } - - // -------------------------------------------------------------------- - - /** - * From - * - * Generates the FROM portion of the query - * - * @access public - * @param mixed can be a string or array - * @return object - */ - function from($from) - { - foreach ((array)$from as $val) - { - $this->ar_from[] = $this->dbprefix.$val; - } - return $this; - } - - // -------------------------------------------------------------------- - - /** - * Join - * - * Generates the JOIN portion of the query - * - * @access public - * @param string - * @param string the join condition - * @param string the type of join - * @return object - */ - 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 .= ' '; - } - } - - $this->ar_join[] = $type.'JOIN '.$table.' ON '.$cond; - return $this; - } - - // -------------------------------------------------------------------- - - /** - * Where - * - * Generates the WHERE portion of the query. Separates - * multiple calls with AND - * - * @access public - * @param mixed - * @param mixed - * @return object - */ - function where($key, $value = NULL) - { - return $this->_where($key, $value, 'AND '); - } - - // -------------------------------------------------------------------- - - /** - * OR Where - * - * Generates the WHERE portion of the query. Separates - * multiple calls with OR - * - * @access public - * @param mixed - * @param mixed - * @return object - */ - function orwhere($key, $value = NULL) - { - return $this->_where($key, $value, 'OR '); - } - - // -------------------------------------------------------------------- - - /** - * Where - * - * Called by where() or orwhere() - * - * @access private - * @param mixed - * @param mixed - * @param string - * @return object - */ - function _where($key, $value = NULL, $type = 'AND ') - { - if ( ! is_array($key)) - { - $key = array($key => $value); - } - - foreach ($key as $k => $v) - { - $prefix = (count($this->ar_where) == 0) ? '' : $type; - - if ( ! is_null($v)) - { - if ( ! $this->_has_operator($k)) - { - $k .= ' ='; - } - - $v = ' '.$this->escape($v); - } - - $this->ar_where[] = $prefix.$k.$v; - } - return $this; - } - - - - // -------------------------------------------------------------------- - - /** - * Like - * - * Generates a %LIKE% portion of the query. Separates - * multiple calls with AND - * - * @access public - * @param mixed - * @param mixed - * @return object - */ - function like($field, $match = '') - { - return $this->_like($field, $match, 'AND '); - } - - // -------------------------------------------------------------------- - - /** - * OR Like - * - * Generates a %LIKE% portion of the query. Separates - * multiple calls with OR - * - * @access public - * @param mixed - * @param mixed - * @return object - */ - function orlike($field, $match = '') - { - return $this->_like($field, $match, 'OR '); - } - - // -------------------------------------------------------------------- - - /** - * Like - * - * Called by like() or orlike() - * - * @access private - * @param mixed - * @param mixed - * @param string - * @return object - */ - function _like($field, $match = '', $type = 'AND ') - { - if ( ! is_array($field)) - { - $field = array($field => $match); - } - - foreach ($field as $k => $v) - { - $prefix = (count($this->ar_like) == 0) ? '' : $type; - - $v = $this->escape_str($v); - - $this->ar_like[] = $prefix." $k LIKE '%{$v}%'"; - } - return $this; - } - - // -------------------------------------------------------------------- - - /** - * GROUP BY - * - * @access public - * @param string - * @return object - */ - function groupby($by) - { - if (is_string($by)) - { - $by = explode(',', $by); - } - - foreach ($by as $val) - { - $val = trim($val); - - if ($val != '') - $this->ar_groupby[] = $val; - } - return $this; - } - - // -------------------------------------------------------------------- - - /** - * Sets the HAVING value - * - * Separates multiple calls with AND - * - * @access public - * @param string - * @param string - * @return object - */ - function having($key, $value = '') - { - return $this->_having($key, $value, 'AND '); - } - - // -------------------------------------------------------------------- - - /** - * Sets the OR HAVING value - * - * Separates multiple calls with OR - * - * @access public - * @param string - * @param string - * @return object - */ - function orhaving($key, $value = '') - { - return $this->_having($key, $value, 'OR '); - } - - // -------------------------------------------------------------------- - - /** - * Sets the HAVING values - * - * Called by having() or orhaving() - * - * @access private - * @param string - * @param string - * @return object - */ - function _having($key, $value = '', $type = 'AND ') - { - if ( ! is_array($key)) - { - $key = array($key => $value); - } - - foreach ($key as $k => $v) - { - $prefix = (count($this->ar_having) == 0) ? '' : $type; - - if ($v != '') - { - $v = ' '.$this->escape($v); - } - - $this->ar_having[] = $prefix.$k.$v; - } - return $this; - } - - // -------------------------------------------------------------------- - - /** - * Sets the ORDER BY value - * - * @access public - * @param string - * @param string direction: asc or desc - * @return object - */ - function orderby($orderby, $direction = '') - { - if (trim($direction) != '') - { - $direction = (in_array(strtoupper(trim($direction)), array('ASC', 'DESC', 'RAND()'))) ? ' '.$direction : ' ASC'; - } - - $this->ar_orderby[] = $orderby.$direction; - return $this; - } - - // -------------------------------------------------------------------- - - /** - * Sets the LIMIT value - * - * @access public - * @param integer the limit value - * @param integer the offset value - * @return object - */ - function limit($value, $offset = '') - { - $this->ar_limit = $value; - - if ($offset != '') - $this->ar_offset = $offset; - - return $this; - } - - // -------------------------------------------------------------------- - - /** - * Sets the OFFSET value - * - * @access public - * @param integer the offset value - * @return object - */ - function offset($value) - { - $this->ar_offset = $value; - return $this; - } - - // -------------------------------------------------------------------- - - /** - * The "set" function. Allows key/value pairs to be set for inserting or updating - * - * @access public - * @param mixed - * @param string - * @return object - */ - function set($key, $value = '') - { - $key = $this->_object_to_array($key); - - if ( ! is_array($key)) - { - $key = array($key => $value); - } - - foreach ($key as $k => $v) - { - $this->ar_set[$k] = $this->escape($v); - } - - return $this; - } - - // -------------------------------------------------------------------- - - /** - * Get - * - * Compiles the select statement based on the other functions called - * and runs the query - * - * @access public - * @param string the limit clause - * @param string the offset clause - * @return object - */ - function get($table = '', $limit = null, $offset = null) - { - if ($table != '') - { - $this->from($table); - } - - if ( ! is_null($limit)) - { - $this->limit($limit, $offset); - } - - $sql = $this->_compile_select(); - - $this->_reset_select(); - return $this->query($sql); - } - - // -------------------------------------------------------------------- - - /** - * GetWhere - * - * Allows the where clause, limit and offset to be added directly - * - * @access public - * @param string the where clause - * @param string the limit clause - * @param string the offset clause - * @return object - */ - function getwhere($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(); - - $this->_reset_select(); - return $this->query($sql); - } - - // -------------------------------------------------------------------- - - /** - * Insert - * - * Compiles an insert string and runs the query - * - * @access public - * @param string the table to retrieve the results from - * @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->dbprefix.$table, 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 - * - * @access public - * @param string the table to retrieve the results from - * @param array an associative array of update values - * @param mixed the where clause - * @return object - */ - function update($table = '', $set = NULL, $where = 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]; - } - - if ($where != null) - { - $this->where($where); - } - - $sql = $this->_update($this->dbprefix.$table, $this->ar_set, $this->ar_where); - - $this->_reset_write(); - return $this->query($sql); - } - - // -------------------------------------------------------------------- - - /** - * Delete - * - * Compiles a delete string and runs the query - * - * @access public - * @param string the table to retrieve the results from - * @param mixed the where clause - * @return object - */ - function delete($table = '', $where = '') - { - 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 != '') - { - $this->where($where); - } - - if (count($this->ar_where) == 0) - { - if ($this->db_debug) - { - return $this->display_error('db_del_must_use_where'); - } - return FALSE; - } - - $sql = $this->_delete($this->dbprefix.$table, $this->ar_where); - - $this->_reset_write(); - return $this->query($sql); - } - - // -------------------------------------------------------------------- - - /** - * Use Table - DEPRECATED - * - * @deprecated use $this->db->from instead - */ - function use_table($table) - { - return $this->from($table); - return $this; - } - - // -------------------------------------------------------------------- - - /** - * ORDER BY - DEPRECATED - * - * @deprecated use $this->db->orderby() instead - */ - function order_by($orderby, $direction = '') - { - return $this->orderby($orderby, $direction); - } - - // -------------------------------------------------------------------- - - /** - * 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; - } - - // -------------------------------------------------------------------- - - /** - * Compile the SELECT statement - * - * Generates a query string based on which functions were used. - * Should not be called directly. The get() function calls it. - * - * @access private - * @return string - */ - function _compile_select() - { - $sql = ( ! $this->ar_distinct) ? 'SELECT ' : 'SELECT DISTINCT '; - - $sql .= (count($this->ar_select) == 0) ? '*' : implode(', ', $this->ar_select); - - if (count($this->ar_from) > 0) - { - $sql .= "\nFROM "; - $sql .= implode(', ', $this->ar_from); - } - - if (count($this->ar_join) > 0) - { - $sql .= "\n"; - $sql .= implode("\n", $this->ar_join); - } - - if (count($this->ar_where) > 0 OR count($this->ar_like) > 0) - { - $sql .= "\nWHERE "; - } - - $sql .= implode("\n", $this->ar_where); - - if (count($this->ar_like) > 0) - { - if (count($this->ar_where) > 0) - { - $sql .= " AND "; - } - - $sql .= implode("\n", $this->ar_like); - } - - if (count($this->ar_groupby) > 0) - { - $sql .= "\nGROUP BY "; - $sql .= implode(', ', $this->ar_groupby); - } - - if (count($this->ar_having) > 0) - { - $sql .= "\nHAVING "; - $sql .= implode("\n", $this->ar_having); - } - - 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'; - } - } - - 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 convers the class variables to array key/vals - * - * @access public - * @param object - * @return array - */ - function _object_to_array($object) - { - if ( ! is_object($object)) - { - return $object; - } - - $array = array(); - foreach (get_object_vars($object) as $key => $val) - { - if ( ! is_object($val) AND ! is_array($val)) - { - $array[$key] = $val; - } - } - - return $array; - } - - // -------------------------------------------------------------------- - - /** - * Resets the active record values. Called by the get() function - * - * @access private - * @return void - */ - function _reset_select() - { - $this->ar_select = array(); - $this->ar_distinct = FALSE; - $this->ar_from = array(); - $this->ar_join = array(); - $this->ar_where = array(); - $this->ar_like = array(); - $this->ar_groupby = array(); - $this->ar_having = array(); - $this->ar_limit = FALSE; - $this->ar_offset = FALSE; - $this->ar_order = FALSE; - $this->ar_orderby = array(); - } - - // -------------------------------------------------------------------- - - /** - * Resets the active record "write" values. - * - * Called by the insert() or update() functions - * - * @access private - * @return void - */ - function _reset_write() - { - $this->ar_set = array(); - $this->ar_from = array(); - $this->ar_where = array(); - } - -} - -?> \ No newline at end of file diff --git a/system/libraries/Controller.php b/system/libraries/Controller.php index 61c8363fa..b91cf3b07 100644 --- a/system/libraries/Controller.php +++ b/system/libraries/Controller.php @@ -366,7 +366,7 @@ class Controller extends CI_Base { if ( ! isset($params['active_r']) OR $params['active_r'] == TRUE) { - require_once(BASEPATH.'database/DB_active_record'.EXT); + require_once(BASEPATH.'database/DB_active_rec'.EXT); if ( ! class_exists('CI_DB')) { -- cgit v1.2.3-24-g4f1b From a5e812c007b8dfbc4c117df379d63060f08b096a Mon Sep 17 00:00:00 2001 From: admin Date: Mon, 25 Sep 2006 02:17:30 +0000 Subject: --- system/database/DB_result.php | 38 ----------- system/database/DB_utility.php | 50 +++++++------- system/database/drivers/mssql/mssql_driver.php | 66 +------------------ system/database/drivers/mssql/mssql_utility.php | 59 +++++++++++++++-- system/database/drivers/mysql/mysql_driver.php | 62 ----------------- system/database/drivers/mysql/mysql_utility.php | 58 ++++++++++++++-- system/database/drivers/mysqli/mysqli_driver.php | 62 ----------------- system/database/drivers/mysqli/mysqli_utility.php | 58 ++++++++++++++-- system/database/drivers/oci8/oci8_driver.php | 63 ------------------ system/database/drivers/oci8/oci8_utility.php | 77 ++++++++++++++++++---- system/database/drivers/odbc/odbc_driver.php | 62 ----------------- system/database/drivers/odbc/odbc_utility.php | 58 ++++++++++++++-- system/database/drivers/postgre/postgre_driver.php | 60 ----------------- .../database/drivers/postgre/postgre_utility.php | 58 ++++++++++++++-- system/database/drivers/sqlite/sqlite_driver.php | 63 ------------------ system/database/drivers/sqlite/sqlite_utility.php | 61 +++++++++++++++-- system/libraries/Controller.php | 46 ++++++++++++- system/libraries/Loader.php | 25 ++++++- 18 files changed, 488 insertions(+), 538 deletions(-) (limited to 'system') diff --git a/system/database/DB_result.php b/system/database/DB_result.php index abb6b588b..970a0db68 100644 --- a/system/database/DB_result.php +++ b/system/database/DB_result.php @@ -243,44 +243,6 @@ class CI_DB_result { return $result[$this->current_row]; } - /** - * Number of rows in the result set - * - * @access public - * @return integer - */ - function num_rows() - { - // Result supplied by the result adaptor class - } - - // -------------------------------------------------------------------- - - /** - * Number of fields in the result set - * - * @access public - * @return integer - */ - function num_fields() - { - // Result supplied by the result adaptor class - } - - // -------------------------------------------------------------------- - - /** - * Field data - * - * Generates an array of objects containing field meta-data - * - * @access public - * @return array - */ - function field_data() - { - // Result supplied by the result adaptor class - } } ?> \ No newline at end of file diff --git a/system/database/DB_utility.php b/system/database/DB_utility.php index 39dc2cca2..c43b39950 100644 --- a/system/database/DB_utility.php +++ b/system/database/DB_utility.php @@ -24,9 +24,15 @@ */ class CI_DB_utility { + var $db; + + function CI_DB_utility() + { + // Assign the main database object to $this->db + $obj =& get_instance(); + $this->db =& $obj->db; + } - - // -------------------------------------------------------------------- /** * Database Version Number. Returns a string containing the @@ -39,19 +45,19 @@ class CI_DB_utility { { if (FALSE === ($sql = $this->_version())) { - if ($this->db_debug) + if ($this->db->db_debug) { - return $this->display_error('db_unsupported_function'); + return $this->db->display_error('db_unsupported_function'); } return FALSE; } - if ($this->dbdriver == 'oci8') + if ($this->db->dbdriver == 'oci8') { return $sql; - } + } - $query = $this->query($sql); + $query = $this->db->query($sql); $row = $query->row(); return $row->ver; } @@ -65,18 +71,18 @@ class CI_DB_utility { * @return array */ function tables() - { + { if (FALSE === ($sql = $this->_show_tables())) { - if ($this->db_debug) + if ($this->db->db_debug) { - return $this->display_error('db_unsupported_function'); + return $this->db->display_error('db_unsupported_function'); } return FALSE; } $retval = array(); - $query = $this->query($sql); + $query = $this->db->query($sql); if ($query->num_rows() > 0) { @@ -104,8 +110,8 @@ class CI_DB_utility { * @return boolean */ function table_exists($table_name) - { - return ( ! in_array($this->dbprefix.$table_name, $this->tables())) ? FALSE : TRUE; + { + return ( ! in_array($this->db->dbprefix.$table_name, $this->tables())) ? FALSE : TRUE; } // -------------------------------------------------------------------- @@ -121,23 +127,23 @@ class CI_DB_utility { { if ($table == '') { - if ($this->db_debug) + if ($this->db->db_debug) { - return $this->display_error('db_field_param_missing'); + return $this->db->display_error('db_field_param_missing'); } return FALSE; } - if (FALSE === ($sql = $this->_show_columns($this->dbprefix.$table))) + if (FALSE === ($sql = $this->_show_columns($this->db->dbprefix.$table))) { - if ($this->db_debug) + if ($this->db->db_debug) { - return $this->display_error('db_unsupported_function'); + return $this->db->display_error('db_unsupported_function'); } return FALSE; } - $query = $this->query($sql); + $query = $this->db->query($sql); $retval = array(); foreach($query->result_array() as $row) @@ -168,14 +174,14 @@ class CI_DB_utility { { if ($table == '') { - if ($this->db_debug) + if ($this->db->db_debug) { - return $this->display_error('db_field_param_missing'); + return $this->db->display_error('db_field_param_missing'); } return FALSE; } - return $this->_field_data($this->dbprefix.$table); + return $this->_field_data($this->db->dbprefix.$table); } // -------------------------------------------------------------------- diff --git a/system/database/drivers/mssql/mssql_driver.php b/system/database/drivers/mssql/mssql_driver.php index cd808da46..38fce1134 100644 --- a/system/database/drivers/mssql/mssql_driver.php +++ b/system/database/drivers/mssql/mssql_driver.php @@ -386,71 +386,7 @@ class CI_DB_mssql_driver extends CI_DB { function _close($conn_id) { mssql_close($conn_id); - } - - // -------------------------------------------------------------------- - - /** - * Version number query string - * - * @access public - * @return string - */ - function _version() - { - return "SELECT version() AS ver"; - } - - // -------------------------------------------------------------------- - - /** - * Show table query - * - * Generates a platform-specific query string so that the table names can be fetched - * - * @access public - * @return string - */ - function _show_tables() - { - return "SELECT name FROM sysobjects WHERE type = 'U' ORDER BY name"; - } - - // -------------------------------------------------------------------- - - /** - * Show columnn 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 _show_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) - { - $sql = "SELECT TOP 1 FROM ".$this->_escape_table($table); - $query = $this->query($sql); - return $query->field_data(); - } - - + } } diff --git a/system/database/drivers/mssql/mssql_utility.php b/system/database/drivers/mssql/mssql_utility.php index a76e1f14f..96d112805 100644 --- a/system/database/drivers/mssql/mssql_utility.php +++ b/system/database/drivers/mssql/mssql_utility.php @@ -22,20 +22,71 @@ * @author Rick Ellis * @link http://www.codeigniter.com/user_guide/database/ */ -class CI_DB_mssql_utility { +class CI_DB_mssql_utility extends CI_DB_utility { + + + /** + * Version number query string + * + * @access public + * @return string + */ + function _version() + { + return "SELECT version() AS ver"; + } + // -------------------------------------------------------------------- + /** - * Some function + * Show table query + * + * Generates a platform-specific query string so that the table names can be fetched * * @access public - * @return integer + * @return string */ - function something() + function _show_tables() { + return "SELECT name FROM sysobjects WHERE type = 'U' ORDER BY name"; } // -------------------------------------------------------------------- + /** + * Show columnn 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 _show_columns($table = '') + { + return "SELECT * FROM INFORMATION_SCHEMA.Columns WHERE TABLE_NAME = '".$this->db->_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) + { + $sql = "SELECT TOP 1 FROM ".$this->db->_escape_table($table); + $query = $this->db->query($sql); + return $query->field_data(); + } + + + } ?> \ No newline at end of file diff --git a/system/database/drivers/mysql/mysql_driver.php b/system/database/drivers/mysql/mysql_driver.php index fc7f6780b..545ac1986 100644 --- a/system/database/drivers/mysql/mysql_driver.php +++ b/system/database/drivers/mysql/mysql_driver.php @@ -410,69 +410,7 @@ class CI_DB_mysql_driver extends CI_DB { { mysql_close($conn_id); } - - // -------------------------------------------------------------------- - - /** - * Version number query string - * - * @access public - * @return string - */ - function _version() - { - return "SELECT version() AS ver"; - } - - // -------------------------------------------------------------------- - - /** - * Show table query - * - * Generates a platform-specific query string so that the table names can be fetched - * - * @access public - * @return string - */ - function _show_tables() - { - return "SHOW TABLES FROM `".$this->database."`"; - } - // -------------------------------------------------------------------- - - /** - * Show columnn 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 _show_columns($table = '') - { - return "SHOW COLUMNS FROM ".$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) - { - $sql = "SELECT * FROM ".$this->_escape_table($table)." LIMIT 1"; - $query = $this->query($sql); - return $query->field_data(); - } - } ?> \ No newline at end of file diff --git a/system/database/drivers/mysql/mysql_utility.php b/system/database/drivers/mysql/mysql_utility.php index 8dd764888..9bf2f5aa9 100644 --- a/system/database/drivers/mysql/mysql_utility.php +++ b/system/database/drivers/mysql/mysql_utility.php @@ -22,20 +22,70 @@ * @author Rick Ellis * @link http://www.codeigniter.com/user_guide/database/ */ -class CI_DB_mysql_utility { +class CI_DB_mysql_utility extends CI_DB_utility { + /** - * Some function + * Version number query string * * @access public - * @return integer + * @return string */ - function something() + function _version() { + return "SELECT version() AS ver"; + } + + // -------------------------------------------------------------------- + + /** + * Show table query + * + * Generates a platform-specific query string so that the table names can be fetched + * + * @access public + * @return string + */ + function _show_tables() + { + return "SHOW TABLES FROM `".$this->db->database."`"; } // -------------------------------------------------------------------- + /** + * Show columnn 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 _show_columns($table = '') + { + return "SHOW COLUMNS FROM ".$this->db->_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) + { + $sql = "SELECT * FROM ".$this->db->_escape_table($table)." LIMIT 1"; + $query = $this->db->query($sql); + return $query->field_data(); + } + + } ?> \ No newline at end of file diff --git a/system/database/drivers/mysqli/mysqli_driver.php b/system/database/drivers/mysqli/mysqli_driver.php index 959384164..adc482dfe 100644 --- a/system/database/drivers/mysqli/mysqli_driver.php +++ b/system/database/drivers/mysqli/mysqli_driver.php @@ -412,68 +412,6 @@ class CI_DB_mysqli_driver extends CI_DB { mysqli_close($conn_id); } - // -------------------------------------------------------------------- - - /** - * Version number query string - * - * @access public - * @return string - */ - function _version() - { - return "SELECT version() AS ver"; - } - - // -------------------------------------------------------------------- - - /** - * Show table query - * - * Generates a platform-specific query string so that the table names can be fetched - * - * @access public - * @return string - */ - function _show_tables() - { - return "SHOW TABLES FROM `".$this->database."`"; - } - - // -------------------------------------------------------------------- - - /** - * Show columnn 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 _show_columns($table = '') - { - return "SHOW COLUMNS FROM ".$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) - { - $sql = "SELECT * FROM ".$this->_escape_table($table)." LIMIT 1"; - $query = $this->query($sql); - return $query->field_data(); - } - } diff --git a/system/database/drivers/mysqli/mysqli_utility.php b/system/database/drivers/mysqli/mysqli_utility.php index 02b423c30..a1498a33d 100644 --- a/system/database/drivers/mysqli/mysqli_utility.php +++ b/system/database/drivers/mysqli/mysqli_utility.php @@ -22,20 +22,70 @@ * @author Rick Ellis * @link http://www.codeigniter.com/user_guide/database/ */ -class CI_DB_mysqli_utility { +class CI_DB_mysqli_utility extends CI_DB_utility { /** - * Some function + * Version number query string * * @access public - * @return integer + * @return string */ - function something() + function _version() { + return "SELECT version() AS ver"; } // -------------------------------------------------------------------- + /** + * Show table query + * + * Generates a platform-specific query string so that the table names can be fetched + * + * @access public + * @return string + */ + function _show_tables() + { + return "SHOW TABLES FROM `".$this->db->database."`"; + } + + // -------------------------------------------------------------------- + + /** + * Show columnn 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 _show_columns($table = '') + { + return "SHOW COLUMNS FROM ".$this->db->_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) + { + $sql = "SELECT * FROM ".$this->db->_escape_table($table)." LIMIT 1"; + $query = $this->db->query($sql); + return $query->field_data(); + } + + + } ?> \ No newline at end of file diff --git a/system/database/drivers/oci8/oci8_driver.php b/system/database/drivers/oci8/oci8_driver.php index bfc38a435..f7f4bd143 100644 --- a/system/database/drivers/oci8/oci8_driver.php +++ b/system/database/drivers/oci8/oci8_driver.php @@ -539,69 +539,6 @@ class CI_DB_oci8_driver extends CI_DB { ocilogoff($conn_id); } - // -------------------------------------------------------------------- - - /** - * Version number query string - * - * @access public - * @return string - */ - function _version() - { - $ver = ociserverversion($this->conn_id); - return $ver; - } - - // -------------------------------------------------------------------- - - /** - * Show table query - * - * Generates a platform-specific query string so that the table names can be fetched - * - * @access public - * @return string - */ - function _show_tables() - { - return "select TABLE_NAME FROM ALL_TABLES"; - } - - // -------------------------------------------------------------------- - - /** - * Show columnn 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 _show_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 - */ - function _field_data($table) - { - $sql = "SELECT * FROM ".$this->_escape_table($table)." where rownum = 1"; - $query = $this->query($sql); - return $query->field_data(); - } - } diff --git a/system/database/drivers/oci8/oci8_utility.php b/system/database/drivers/oci8/oci8_utility.php index f1e327a3e..fdd585d98 100644 --- a/system/database/drivers/oci8/oci8_utility.php +++ b/system/database/drivers/oci8/oci8_utility.php @@ -22,19 +22,70 @@ * @author Rick Ellis * @link http://www.codeigniter.com/user_guide/database/ */ -class CI_DB_oci8_utility { - - /** - * Some function - * - * @access public - * @return integer - */ - function something() - { - } - - // -------------------------------------------------------------------- +class CI_DB_oci8_utility extends CI_DB_utility { + + + + /** + * Version number query string + * + * @access public + * @return string + */ + function _version() + { + return ociserverversion($this->conn_id); + } + + // -------------------------------------------------------------------- + + /** + * Show table query + * + * Generates a platform-specific query string so that the table names can be fetched + * + * @access public + * @return string + */ + function _show_tables() + { + return "select TABLE_NAME FROM ALL_TABLES"; + } + + // -------------------------------------------------------------------- + + /** + * Show columnn 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 _show_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 + */ + function _field_data($table) + { + $sql = "SELECT * FROM ".$this->db->_escape_table($table)." where rownum = 1"; + $query = $this->db->query($sql); + return $query->field_data(); + } + } diff --git a/system/database/drivers/odbc/odbc_driver.php b/system/database/drivers/odbc/odbc_driver.php index c05abd082..bef6258de 100644 --- a/system/database/drivers/odbc/odbc_driver.php +++ b/system/database/drivers/odbc/odbc_driver.php @@ -386,68 +386,6 @@ class CI_DB_odbc_driver extends CI_DB { odbc_close($conn_id); } - // -------------------------------------------------------------------- - - /** - * Version number query string - * - * @access public - * @return string - */ - function _version() - { - return "SELECT version() AS ver"; - } - - // -------------------------------------------------------------------- - - /** - * Show table query - * - * Generates a platform-specific query string so that the table names can be fetched - * - * @access public - * @return string - */ - function _show_tables() - { - return "SHOW TABLES FROM `".$this->database."`"; - } - - // -------------------------------------------------------------------- - - /** - * Show columnn 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 _show_columns($table = '') - { - return "SHOW COLUMNS FROM ".$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) - { - $sql = "SELECT TOP 1 FROM ".$this->_escape_table($table); - $query = $this->query($sql); - return $query->field_data(); - } - } diff --git a/system/database/drivers/odbc/odbc_utility.php b/system/database/drivers/odbc/odbc_utility.php index f2b5602cc..837c8c881 100644 --- a/system/database/drivers/odbc/odbc_utility.php +++ b/system/database/drivers/odbc/odbc_utility.php @@ -22,20 +22,70 @@ * @author Rick Ellis * @link http://www.codeigniter.com/database/ */ -class CI_DB_odbc_utility { +class CI_DB_odbc_utility extends CI_DB_utility { + + /** + * Version number query string + * + * @access public + * @return string + */ + function _version() + { + return "SELECT version() AS ver"; + } + // -------------------------------------------------------------------- + /** - * Some function + * Show table query + * + * Generates a platform-specific query string so that the table names can be fetched * * @access public - * @return integer + * @return string */ - function something() + function _show_tables() { + return "SHOW TABLES FROM `".$this->db->database."`"; } // -------------------------------------------------------------------- + /** + * Show columnn 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 _show_columns($table = '') + { + return "SHOW COLUMNS FROM ".$this->db->_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) + { + $sql = "SELECT TOP 1 FROM ".$this->db->_escape_table($table); + $query = $this->db->query($sql); + return $query->field_data(); + } + + + } ?> \ No newline at end of file diff --git a/system/database/drivers/postgre/postgre_driver.php b/system/database/drivers/postgre/postgre_driver.php index 03817188f..9c8a18eb5 100644 --- a/system/database/drivers/postgre/postgre_driver.php +++ b/system/database/drivers/postgre/postgre_driver.php @@ -419,66 +419,6 @@ class CI_DB_postgre_driver extends CI_DB { pg_close($conn_id); } - // -------------------------------------------------------------------- - - /** - * Version number query string - * - * @access public - * @return string - */ - function _version() - { - return "SELECT version() AS ver"; - } - - /** - * Show table query - * - * Generates a platform-specific query string so that the table names can be fetched - * - * @access public - * @return string - */ - function _show_tables() - { - return "SELECT table_name FROM information_schema.tables WHERE table_schema = 'public'"; - } - - // -------------------------------------------------------------------- - - /** - * Show columnn 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 _show_columns($table = '') - { - return "SELECT column_name 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) - { - $sql = "SELECT * FROM ".$this->_escape_table($table)." LIMIT 1"; - $query = $this->query($sql); - return $query->field_data(); - } - } diff --git a/system/database/drivers/postgre/postgre_utility.php b/system/database/drivers/postgre/postgre_utility.php index 760be81a0..cfc475f6b 100644 --- a/system/database/drivers/postgre/postgre_utility.php +++ b/system/database/drivers/postgre/postgre_utility.php @@ -22,20 +22,70 @@ * @author Rick Ellis * @link http://www.codeigniter.com/user_guide/database/ */ -class CI_DB_postgre_utility { +class CI_DB_postgre_utility extends CI_DB_utility { + /** - * Some function + * Version number query string * * @access public - * @return integer + * @return string */ - function something() + function _version() { + return "SELECT version() AS ver"; + } + + // -------------------------------------------------------------------- + + /** + * Show table query + * + * Generates a platform-specific query string so that the table names can be fetched + * + * @access public + * @return string + */ + function _show_tables() + { + return "SELECT table_name FROM information_schema.tables WHERE table_schema = 'public'"; } // -------------------------------------------------------------------- + /** + * Show columnn 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 _show_columns($table = '') + { + return "SELECT column_name FROM information_schema.columns WHERE table_name ='".$this->db->_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) + { + $sql = "SELECT * FROM ".$this->db->_escape_table($table)." LIMIT 1"; + $query = $this->db->query($sql); + return $query->field_data(); + } + + } ?> \ No newline at end of file diff --git a/system/database/drivers/sqlite/sqlite_driver.php b/system/database/drivers/sqlite/sqlite_driver.php index f8318b814..603984575 100644 --- a/system/database/drivers/sqlite/sqlite_driver.php +++ b/system/database/drivers/sqlite/sqlite_driver.php @@ -413,69 +413,6 @@ class CI_DB_sqlite_driver extends CI_DB { sqlite_close($conn_id); } - // -------------------------------------------------------------------- - - /** - * Version number query string - * - * @access public - * @return string - */ - function _version() - { - return sqlite_libversion(); - } - - // -------------------------------------------------------------------- - - /** - * Show table query - * - * Generates a platform-specific query string so that the table names can be fetched - * - * @access public - * @return string - */ - function _show_tables() - { - return "SELECT name from sqlite_master WHERE type='table'"; - } - - // -------------------------------------------------------------------- - - /** - * Show columnn 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 _show_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) - { - $sql = "SELECT * FROM ".$this->_escape_table($table)." LIMIT 1"; - $query = $this->query($sql); - return $query->field_data(); - } - } diff --git a/system/database/drivers/sqlite/sqlite_utility.php b/system/database/drivers/sqlite/sqlite_utility.php index 3cbec6f14..2b99df907 100644 --- a/system/database/drivers/sqlite/sqlite_utility.php +++ b/system/database/drivers/sqlite/sqlite_utility.php @@ -22,20 +22,71 @@ * @author Rick Ellis * @link http://www.codeigniter.com/user_guide/database/ */ -class CI_DB_sqlite_utility { - +class CI_DB_sqlite_utility extends CI_DB_utility { + + /** + * Version number query string + * + * @access public + * @return string + */ + function _version() + { + return sqlite_libversion(); + } + + // -------------------------------------------------------------------- + /** - * Some function + * Show table query + * + * Generates a platform-specific query string so that the table names can be fetched * * @access public - * @return integer + * @return string */ - function something() + function _show_tables() { + return "SELECT name from sqlite_master WHERE type='table'"; } // -------------------------------------------------------------------- + /** + * Show columnn 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 _show_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) + { + $sql = "SELECT * FROM ".$this->db->_escape_table($table)." LIMIT 1"; + $query = $this->db->query($sql); + return $query->field_data(); + } + + + } ?> \ No newline at end of file diff --git a/system/libraries/Controller.php b/system/libraries/Controller.php index b91cf3b07..5fdbd9f9f 100644 --- a/system/libraries/Controller.php +++ b/system/libraries/Controller.php @@ -384,7 +384,7 @@ class Controller extends CI_Base { require_once(BASEPATH.'database/drivers/'.$params['dbdriver'].'/'.$params['dbdriver'].'_driver'.EXT); // Instantiate the DB adapter - $driver = 'CI_DB_'. $params['dbdriver'].'_driver'; + $driver = 'CI_DB_'.$params['dbdriver'].'_driver'; $DB = new $driver($params); if ($return === TRUE) @@ -397,7 +397,49 @@ class Controller extends CI_Base { $obj->db =& $DB; } // END _ci_init_database() - + + + // -------------------------------------------------------------------- + + /** + * Initialize Database Utilities Class + * + * @access private + * @param mixed database platform + * @param bool whether to return the object + * @return void + */ + function _ci_init_dbutils($db = '', $return = FALSE) + { + if ($this->_ci_is_loaded('dbutils') == TRUE AND $return == FALSE) + { + return; + } + + if ($this->_ci_is_loaded('db') == FALSE) + { + $this->_ci_init_database(); + } + + require_once(BASEPATH.'database/DB_utility'.EXT); + require_once(BASEPATH.'database/drivers/'.$this->db->dbdriver.'/'.$this->db->dbdriver.'_utility'.EXT); + + + // Instantiate the DB adapter + $driver = 'CI_DB_'.$this->db->dbdriver.'_utility'; + $DB = new $driver(); + + if ($return === TRUE) + { + return $DB; + } + + $obj =& get_instance(); + $obj->ci_is_loaded[] = 'dbutils'; + $obj->dbutil =& $DB; + } + // END _ci_init_database() + // -------------------------------------------------------------------- /** diff --git a/system/libraries/Loader.php b/system/libraries/Loader.php index d966e2862..f4a9f821d 100644 --- a/system/libraries/Loader.php +++ b/system/libraries/Loader.php @@ -108,7 +108,7 @@ class CI_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 mixed + * @return object */ function database($db = '', $return = FALSE, $active_record = FALSE) { @@ -125,6 +125,29 @@ class CI_Loader { } } // END database() + + // -------------------------------------------------------------------- + + /** + * Database Utilities Loader + * + * @access public + * @param string the DB platform + * @param bool whether to return the DB object + * @return object + */ + function dbutils($db = '', $return = FALSE) + { + $obj =& get_instance(); + + if ( ! is_bool($return)) + { + $return = FALSE; + } + + return $obj->_ci_init_dbutils($db, $return); + } + // END dbutils() // -------------------------------------------------------------------- -- cgit v1.2.3-24-g4f1b From 6ca6f9471ba31f7cba9054d075b4f90382b2d410 Mon Sep 17 00:00:00 2001 From: admin Date: Mon, 25 Sep 2006 02:51:08 +0000 Subject: --- system/database/DB_utility.php | 6 ---- system/database/drivers/mssql/mssql_utility.php | 28 ++++++++++++++++ system/database/drivers/mysql/mysql_utility.php | 28 ++++++++++++++++ system/database/drivers/mysqli/mysqli_utility.php | 28 ++++++++++++++++ system/database/drivers/oci8/oci8_utility.php | 27 +++++++++++++++ system/database/drivers/odbc/odbc_utility.php | 33 +++++++++++++++++++ .../database/drivers/postgre/postgre_utility.php | 28 ++++++++++++++++ system/database/drivers/sqlite/sqlite_utility.php | 38 ++++++++++++++++++++++ system/language/english/db_lang.php | 1 + 9 files changed, 211 insertions(+), 6 deletions(-) (limited to 'system') diff --git a/system/database/DB_utility.php b/system/database/DB_utility.php index c43b39950..d96fffa04 100644 --- a/system/database/DB_utility.php +++ b/system/database/DB_utility.php @@ -212,13 +212,7 @@ class CI_DB_utility { - function create_database() - { - } - function drop_database() - { - } function show_databases() { diff --git a/system/database/drivers/mssql/mssql_utility.php b/system/database/drivers/mssql/mssql_utility.php index 96d112805..9ff92d41b 100644 --- a/system/database/drivers/mssql/mssql_utility.php +++ b/system/database/drivers/mssql/mssql_utility.php @@ -24,6 +24,34 @@ */ class CI_DB_mssql_utility extends CI_DB_utility { + + /** + * Create database + * + * @access public + * @param string the database name + * @return bool + */ + function create_database($name) + { + return $this->db->query("CREATE DATABASE ".$this->db->_escape_table($name)); + } + + // -------------------------------------------------------------------- + + /** + * Drop database + * + * @access public + * @param string the database name + * @return bool + */ + function drop_database($name) + { + return $this->db->query("DROP DATABASE ".$this->db->_escape_table($name)); + } + + // -------------------------------------------------------------------- /** * Version number query string diff --git a/system/database/drivers/mysql/mysql_utility.php b/system/database/drivers/mysql/mysql_utility.php index 9bf2f5aa9..d4e97867a 100644 --- a/system/database/drivers/mysql/mysql_utility.php +++ b/system/database/drivers/mysql/mysql_utility.php @@ -24,6 +24,33 @@ */ class CI_DB_mysql_utility extends CI_DB_utility { + /** + * Create database + * + * @access public + * @param string the database name + * @return bool + */ + function create_database($name) + { + return $this->db->query("CREATE DATABASE ".$this->db->_escape_table($name)); + } + + // -------------------------------------------------------------------- + + /** + * Drop database + * + * @access public + * @param string the database name + * @return bool + */ + function drop_database($name) + { + return $this->db->query("DROP DATABASE ".$this->db->_escape_table($name)); + } + + // -------------------------------------------------------------------- /** * Version number query string @@ -86,6 +113,7 @@ class CI_DB_mysql_utility extends CI_DB_utility { } + } ?> \ No newline at end of file diff --git a/system/database/drivers/mysqli/mysqli_utility.php b/system/database/drivers/mysqli/mysqli_utility.php index a1498a33d..9c773b4b9 100644 --- a/system/database/drivers/mysqli/mysqli_utility.php +++ b/system/database/drivers/mysqli/mysqli_utility.php @@ -24,6 +24,34 @@ */ class CI_DB_mysqli_utility extends CI_DB_utility { + /** + * Create database + * + * @access public + * @param string the database name + * @return bool + */ + function create_database($name) + { + return $this->db->query("CREATE DATABASE ".$this->db->_escape_table($name)); + } + + // -------------------------------------------------------------------- + + /** + * Drop database + * + * @access public + * @param string the database name + * @return bool + */ + function drop_database($name) + { + return $this->db->query("DROP DATABASE ".$this->db->_escape_table($name)); + } + + // -------------------------------------------------------------------- + /** * Version number query string * diff --git a/system/database/drivers/oci8/oci8_utility.php b/system/database/drivers/oci8/oci8_utility.php index fdd585d98..35b753ec6 100644 --- a/system/database/drivers/oci8/oci8_utility.php +++ b/system/database/drivers/oci8/oci8_utility.php @@ -25,6 +25,33 @@ class CI_DB_oci8_utility extends CI_DB_utility { + /** + * Create database + * + * @access public + * @param string the database name + * @return bool + */ + function create_database($name) + { + + } + + // -------------------------------------------------------------------- + + /** + * Drop database + * + * @access public + * @param string the database name + * @return bool + */ + function drop_database($name) + { + + } + + // -------------------------------------------------------------------- /** * Version number query string diff --git a/system/database/drivers/odbc/odbc_utility.php b/system/database/drivers/odbc/odbc_utility.php index 837c8c881..51fec8eed 100644 --- a/system/database/drivers/odbc/odbc_utility.php +++ b/system/database/drivers/odbc/odbc_utility.php @@ -24,6 +24,39 @@ */ class CI_DB_odbc_utility extends CI_DB_utility { + + /** + * Create database + * + * @access public + * @param string the database name + * @return bool + */ + function create_database($name) + { + // ODBC has no "create database" command since it's + // designed to connect to an existing database + return FALSE; + } + + // -------------------------------------------------------------------- + + /** + * Drop database + * + * @access public + * @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 + return FALSE; + } + + // -------------------------------------------------------------------- + /** * Version number query string * diff --git a/system/database/drivers/postgre/postgre_utility.php b/system/database/drivers/postgre/postgre_utility.php index cfc475f6b..c38cf6e69 100644 --- a/system/database/drivers/postgre/postgre_utility.php +++ b/system/database/drivers/postgre/postgre_utility.php @@ -25,6 +25,34 @@ class CI_DB_postgre_utility extends CI_DB_utility { + /** + * Create database + * + * @access public + * @param string the database name + * @return bool + */ + function create_database($name) + { + return $this->db->query("CREATE DATABASE ".$this->db->_escape_table($name)); + } + + // -------------------------------------------------------------------- + + /** + * Drop database + * + * @access public + * @param string the database name + * @return bool + */ + function drop_database($name) + { + return $this->db->query("DROP DATABASE ".$this->db->_escape_table($name)); + } + + // -------------------------------------------------------------------- + /** * Version number query string * diff --git a/system/database/drivers/sqlite/sqlite_utility.php b/system/database/drivers/sqlite/sqlite_utility.php index 2b99df907..8cbf0d56d 100644 --- a/system/database/drivers/sqlite/sqlite_utility.php +++ b/system/database/drivers/sqlite/sqlite_utility.php @@ -24,6 +24,44 @@ */ class CI_DB_sqlite_utility extends CI_DB_utility { + + /** + * Create database + * + * @access public + * @param string the database name + * @return bool + */ + function create_database() + { + // In SQLite, a database is created when you connect to the database + return TRUE; + } + + // -------------------------------------------------------------------- + + /** + * Drop database + * + * @access public + * @param string the database name + * @return bool + */ + function drop_database($name) + { + if ( ! @file_exists($this->db->database) OR ! @unlink($this->db->database)) + { + if ($this->db_debug) + { + return $this->display_error('db_unable_to_drop'); + } + return FALSE; + } + return TRUE; + } + + // -------------------------------------------------------------------- + /** * Version number query string * diff --git a/system/language/english/db_lang.php b/system/language/english/db_lang.php index d51bb6dce..a3d0900d0 100644 --- a/system/language/english/db_lang.php +++ b/system/language/english/db_lang.php @@ -12,6 +12,7 @@ $lang['db_del_must_use_where'] = 'Deletes are not allowed unless they contain a $lang['db_field_param_missing'] = 'To fetch fields requires the name of the table as a parameter.'; $lang['db_unsupported_function'] = 'This feature is not available for the database you are using.'; $lang['db_transaction_failure'] = 'Transaction failure: Rollback performed'; +$lang['db_unable_to_drop'] = 'Unable to drop the specified database.'; ?> \ No newline at end of file -- cgit v1.2.3-24-g4f1b From 72496373008b263e098cf6082cdce1d47d01d3f1 Mon Sep 17 00:00:00 2001 From: admin Date: Mon, 25 Sep 2006 03:44:04 +0000 Subject: --- system/database/DB_utility.php | 7 ------ system/database/drivers/mssql/mssql_utility.php | 23 ++++++++++++++++++ system/database/drivers/mysql/mysql_utility.php | 23 ++++++++++++++++++ system/database/drivers/mysqli/mysqli_utility.php | 23 ++++++++++++++++++ system/database/drivers/oci8/oci8_utility.php | 12 +++++++++- system/database/drivers/odbc/odbc_utility.php | 28 +++++++++++++++++++++- .../database/drivers/postgre/postgre_utility.php | 23 ++++++++++++++++++ system/database/drivers/sqlite/sqlite_utility.php | 17 +++++++++++++ system/language/english/db_lang.php | 1 + 9 files changed, 148 insertions(+), 9 deletions(-) (limited to 'system') diff --git a/system/database/DB_utility.php b/system/database/DB_utility.php index d96fffa04..b17b3d51c 100644 --- a/system/database/DB_utility.php +++ b/system/database/DB_utility.php @@ -211,13 +211,6 @@ class CI_DB_utility { - - - - function show_databases() - { - } - function create_table() { } diff --git a/system/database/drivers/mssql/mssql_utility.php b/system/database/drivers/mssql/mssql_utility.php index 9ff92d41b..bc398e7f7 100644 --- a/system/database/drivers/mssql/mssql_utility.php +++ b/system/database/drivers/mssql/mssql_utility.php @@ -51,6 +51,29 @@ class CI_DB_mssql_utility extends CI_DB_utility { return $this->db->query("DROP DATABASE ".$this->db->_escape_table($name)); } + // -------------------------------------------------------------------- + + /** + * List databases + * + * @access public + * @return bool + */ + function list_databases() + { + $query = $this->db->query("EXEC sp_helpdb"); // Can also be: EXEC sp_databases + $dbs = array(); + if ($query->num_rows() > 0) + { + foreach ($query->result_array() as $row) + { + $dbs[] = current($row); + } + } + + return $dbs; + } + // -------------------------------------------------------------------- /** diff --git a/system/database/drivers/mysql/mysql_utility.php b/system/database/drivers/mysql/mysql_utility.php index d4e97867a..5bbf46810 100644 --- a/system/database/drivers/mysql/mysql_utility.php +++ b/system/database/drivers/mysql/mysql_utility.php @@ -52,6 +52,29 @@ class CI_DB_mysql_utility extends CI_DB_utility { // -------------------------------------------------------------------- + /** + * List databases + * + * @access public + * @return bool + */ + function list_databases() + { + $query = $this->db->query("SHOW DATABASES"); + $dbs = array(); + if ($query->num_rows() > 0) + { + foreach ($query->result_array() as $row) + { + $dbs[] = current($row); + } + } + + return $dbs; + } + + // -------------------------------------------------------------------- + /** * Version number query string * diff --git a/system/database/drivers/mysqli/mysqli_utility.php b/system/database/drivers/mysqli/mysqli_utility.php index 9c773b4b9..14a6ef8cf 100644 --- a/system/database/drivers/mysqli/mysqli_utility.php +++ b/system/database/drivers/mysqli/mysqli_utility.php @@ -52,6 +52,29 @@ class CI_DB_mysqli_utility extends CI_DB_utility { // -------------------------------------------------------------------- + /** + * List databases + * + * @access public + * @return bool + */ + function list_databases() + { + $query = $this->db->query("SHOW DATABASES"); + $dbs = array(); + if ($query->num_rows() > 0) + { + foreach ($query->result_array() as $row) + { + $dbs[] = current($row); + } + } + + return $dbs; + } + + // -------------------------------------------------------------------- + /** * Version number query string * diff --git a/system/database/drivers/oci8/oci8_utility.php b/system/database/drivers/oci8/oci8_utility.php index 35b753ec6..03edcb2c8 100644 --- a/system/database/drivers/oci8/oci8_utility.php +++ b/system/database/drivers/oci8/oci8_utility.php @@ -34,7 +34,6 @@ class CI_DB_oci8_utility extends CI_DB_utility { */ function create_database($name) { - } // -------------------------------------------------------------------- @@ -48,7 +47,18 @@ class CI_DB_oci8_utility extends CI_DB_utility { */ function drop_database($name) { + } + // -------------------------------------------------------------------- + + /** + * List databases + * + * @access public + * @return bool + */ + function list_databases() + { } // -------------------------------------------------------------------- diff --git a/system/database/drivers/odbc/odbc_utility.php b/system/database/drivers/odbc/odbc_utility.php index 51fec8eed..42537de70 100644 --- a/system/database/drivers/odbc/odbc_utility.php +++ b/system/database/drivers/odbc/odbc_utility.php @@ -36,6 +36,10 @@ class CI_DB_odbc_utility extends CI_DB_utility { { // ODBC has no "create database" command since it's // designed to connect to an existing database + if ($this->db_debug) + { + return $this->display_error('db_unsuported_feature'); + } return FALSE; } @@ -51,7 +55,29 @@ class CI_DB_odbc_utility extends CI_DB_utility { function drop_database($name) { // ODBC has no "drop database" command since it's - // designed to connect to an existing database + // designed to connect to an existing database + if ($this->db_debug) + { + return $this->display_error('db_unsuported_feature'); + } + return FALSE; + } + + // -------------------------------------------------------------------- + + /** + * List databases + * + * @access public + * @return bool + */ + function list_databases() + { + // Not sure if ODBC lets you list all databases... + if ($this->db_debug) + { + return $this->display_error('db_unsuported_feature'); + } return FALSE; } diff --git a/system/database/drivers/postgre/postgre_utility.php b/system/database/drivers/postgre/postgre_utility.php index c38cf6e69..103f8d553 100644 --- a/system/database/drivers/postgre/postgre_utility.php +++ b/system/database/drivers/postgre/postgre_utility.php @@ -53,6 +53,29 @@ class CI_DB_postgre_utility extends CI_DB_utility { // -------------------------------------------------------------------- + /** + * List databases + * + * @access public + * @return bool + */ + function list_databases() + { + $query = $this->db->query("SELECT datname FROM pg_database"); + $dbs = array(); + if ($query->num_rows() > 0) + { + foreach ($query->result_array() as $row) + { + $dbs[] = current($row); + } + } + + return $dbs; + } + + // -------------------------------------------------------------------- + /** * Version number query string * diff --git a/system/database/drivers/sqlite/sqlite_utility.php b/system/database/drivers/sqlite/sqlite_utility.php index 8cbf0d56d..5f1f02eab 100644 --- a/system/database/drivers/sqlite/sqlite_utility.php +++ b/system/database/drivers/sqlite/sqlite_utility.php @@ -62,6 +62,23 @@ class CI_DB_sqlite_utility extends CI_DB_utility { // -------------------------------------------------------------------- + /** + * List databases + * + * @access public + * @return bool + */ + function list_databases() + { + if ($this->db_debug) + { + return $this->display_error('db_unsuported_feature'); + } + return array(); + } + + // -------------------------------------------------------------------- + /** * Version number query string * diff --git a/system/language/english/db_lang.php b/system/language/english/db_lang.php index a3d0900d0..5be7d6efb 100644 --- a/system/language/english/db_lang.php +++ b/system/language/english/db_lang.php @@ -13,6 +13,7 @@ $lang['db_field_param_missing'] = 'To fetch fields requires the name of the tabl $lang['db_unsupported_function'] = 'This feature is not available for the database you are using.'; $lang['db_transaction_failure'] = 'Transaction failure: Rollback performed'; $lang['db_unable_to_drop'] = 'Unable to drop the specified database.'; +$lang['db_unsuported_feature'] = 'Unsupported feature of the database platform you are using.'; ?> \ No newline at end of file -- cgit v1.2.3-24-g4f1b From 4ceac2d4efa5a16486b6e97911bb32e261b9d648 Mon Sep 17 00:00:00 2001 From: admin Date: Mon, 25 Sep 2006 06:40:16 +0000 Subject: --- system/database/DB_utility.php | 1 - system/database/drivers/mssql/mssql_utility.php | 17 +++++++++++++++-- system/database/drivers/mysql/mysql_utility.php | 17 +++++++++++++++-- system/database/drivers/mysqli/mysqli_utility.php | 17 +++++++++++++++-- system/database/drivers/oci8/oci8_utility.php | 12 ++++++++++++ system/database/drivers/odbc/odbc_utility.php | 18 ++++++++++++++++++ system/database/drivers/postgre/postgre_utility.php | 17 +++++++++++++++-- system/database/drivers/sqlite/sqlite_utility.php | 17 +++++++++++++++++ 8 files changed, 107 insertions(+), 9 deletions(-) (limited to 'system') diff --git a/system/database/DB_utility.php b/system/database/DB_utility.php index b17b3d51c..8e1921dbc 100644 --- a/system/database/DB_utility.php +++ b/system/database/DB_utility.php @@ -210,7 +210,6 @@ class CI_DB_utility { - function create_table() { } diff --git a/system/database/drivers/mssql/mssql_utility.php b/system/database/drivers/mssql/mssql_utility.php index bc398e7f7..61fe5fcbc 100644 --- a/system/database/drivers/mssql/mssql_utility.php +++ b/system/database/drivers/mssql/mssql_utility.php @@ -34,7 +34,7 @@ class CI_DB_mssql_utility extends CI_DB_utility { */ function create_database($name) { - return $this->db->query("CREATE DATABASE ".$this->db->_escape_table($name)); + return $this->db->query("CREATE DATABASE ".$name); } // -------------------------------------------------------------------- @@ -48,7 +48,7 @@ class CI_DB_mssql_utility extends CI_DB_utility { */ function drop_database($name) { - return $this->db->query("DROP DATABASE ".$this->db->_escape_table($name)); + return $this->db->query("DROP DATABASE ".$name); } // -------------------------------------------------------------------- @@ -74,6 +74,19 @@ class CI_DB_mssql_utility extends CI_DB_utility { return $dbs; } + // -------------------------------------------------------------------- + + /** + * Drop Table + * + * @access public + * @return bool + */ + function drop_table($table) + { + "DROP TABLE ".$this->db->_escape_table($name); + } + // -------------------------------------------------------------------- /** diff --git a/system/database/drivers/mysql/mysql_utility.php b/system/database/drivers/mysql/mysql_utility.php index 5bbf46810..23c4e094d 100644 --- a/system/database/drivers/mysql/mysql_utility.php +++ b/system/database/drivers/mysql/mysql_utility.php @@ -33,7 +33,7 @@ class CI_DB_mysql_utility extends CI_DB_utility { */ function create_database($name) { - return $this->db->query("CREATE DATABASE ".$this->db->_escape_table($name)); + return $this->db->query("CREATE DATABASE ".$name); } // -------------------------------------------------------------------- @@ -47,7 +47,7 @@ class CI_DB_mysql_utility extends CI_DB_utility { */ function drop_database($name) { - return $this->db->query("DROP DATABASE ".$this->db->_escape_table($name)); + return $this->db->query("DROP DATABASE ".$name); } // -------------------------------------------------------------------- @@ -75,6 +75,19 @@ class CI_DB_mysql_utility extends CI_DB_utility { // -------------------------------------------------------------------- + /** + * Drop Table + * + * @access public + * @return bool + */ + function drop_table($table) + { + "DROP TABLE IF EXISTS ".$this->db->_escape_table($name); + } + + // -------------------------------------------------------------------- + /** * Version number query string * diff --git a/system/database/drivers/mysqli/mysqli_utility.php b/system/database/drivers/mysqli/mysqli_utility.php index 14a6ef8cf..ca8f3fe34 100644 --- a/system/database/drivers/mysqli/mysqli_utility.php +++ b/system/database/drivers/mysqli/mysqli_utility.php @@ -33,7 +33,7 @@ class CI_DB_mysqli_utility extends CI_DB_utility { */ function create_database($name) { - return $this->db->query("CREATE DATABASE ".$this->db->_escape_table($name)); + return $this->db->query("CREATE DATABASE ".$name); } // -------------------------------------------------------------------- @@ -47,7 +47,7 @@ class CI_DB_mysqli_utility extends CI_DB_utility { */ function drop_database($name) { - return $this->db->query("DROP DATABASE ".$this->db->_escape_table($name)); + return $this->db->query("DROP DATABASE ".$name); } // -------------------------------------------------------------------- @@ -72,6 +72,19 @@ class CI_DB_mysqli_utility extends CI_DB_utility { return $dbs; } + + // -------------------------------------------------------------------- + + /** + * Drop Table + * + * @access public + * @return bool + */ + function drop_table($table) + { + "DROP TABLE IF EXISTS ".$this->db->_escape_table($name); + } // -------------------------------------------------------------------- diff --git a/system/database/drivers/oci8/oci8_utility.php b/system/database/drivers/oci8/oci8_utility.php index 03edcb2c8..7e3ee7285 100644 --- a/system/database/drivers/oci8/oci8_utility.php +++ b/system/database/drivers/oci8/oci8_utility.php @@ -63,6 +63,18 @@ class CI_DB_oci8_utility extends CI_DB_utility { // -------------------------------------------------------------------- + /** + * Drop Table + * + * @access public + * @return bool + */ + function drop_table($table) + { + } + + // -------------------------------------------------------------------- + /** * Version number query string * diff --git a/system/database/drivers/odbc/odbc_utility.php b/system/database/drivers/odbc/odbc_utility.php index 42537de70..cfd829cb6 100644 --- a/system/database/drivers/odbc/odbc_utility.php +++ b/system/database/drivers/odbc/odbc_utility.php @@ -83,6 +83,24 @@ class CI_DB_odbc_utility extends CI_DB_utility { // -------------------------------------------------------------------- + /** + * Drop Table + * + * @access public + * @return bool + */ + function drop_table($table) + { + // Not a supported ODBC feature + if ($this->db_debug) + { + return $this->display_error('db_unsuported_feature'); + } + return FALSE; + } + + // -------------------------------------------------------------------- + /** * Version number query string * diff --git a/system/database/drivers/postgre/postgre_utility.php b/system/database/drivers/postgre/postgre_utility.php index 103f8d553..7bb210ab7 100644 --- a/system/database/drivers/postgre/postgre_utility.php +++ b/system/database/drivers/postgre/postgre_utility.php @@ -34,7 +34,7 @@ class CI_DB_postgre_utility extends CI_DB_utility { */ function create_database($name) { - return $this->db->query("CREATE DATABASE ".$this->db->_escape_table($name)); + return $this->db->query("CREATE DATABASE ".$name); } // -------------------------------------------------------------------- @@ -48,7 +48,7 @@ class CI_DB_postgre_utility extends CI_DB_utility { */ function drop_database($name) { - return $this->db->query("DROP DATABASE ".$this->db->_escape_table($name)); + return $this->db->query("DROP DATABASE ".$name); } // -------------------------------------------------------------------- @@ -73,6 +73,19 @@ class CI_DB_postgre_utility extends CI_DB_utility { return $dbs; } + + // -------------------------------------------------------------------- + + /** + * Drop Table + * + * @access public + * @return bool + */ + function drop_table($table) + { + "DROP TABLE ".$this->db->_escape_table($name)." CASCADE"; + } // -------------------------------------------------------------------- diff --git a/system/database/drivers/sqlite/sqlite_utility.php b/system/database/drivers/sqlite/sqlite_utility.php index 5f1f02eab..744ca3f37 100644 --- a/system/database/drivers/sqlite/sqlite_utility.php +++ b/system/database/drivers/sqlite/sqlite_utility.php @@ -79,6 +79,23 @@ class CI_DB_sqlite_utility extends CI_DB_utility { // -------------------------------------------------------------------- + /** + * Drop Table + * + * @access public + * @return bool + */ + function drop_table($table) + { + if ($this->db_debug) + { + return $this->display_error('db_unsuported_feature'); + } + return array(); + } + + // -------------------------------------------------------------------- + /** * Version number query string * -- cgit v1.2.3-24-g4f1b From 6cec6a58d993fb0b1beb5fac7ea0d1cb9769c0a4 Mon Sep 17 00:00:00 2001 From: admin Date: Mon, 25 Sep 2006 06:56:49 +0000 Subject: --- system/database/DB_utility.php | 29 +++++++++++++++++++++- system/database/drivers/mssql/mssql_utility.php | 12 ++++----- system/database/drivers/mysql/mysql_utility.php | 12 ++++----- system/database/drivers/mysqli/mysqli_utility.php | 12 ++++----- system/database/drivers/oci8/oci8_utility.php | 6 ++--- system/database/drivers/odbc/odbc_utility.php | 8 +++--- .../database/drivers/postgre/postgre_utility.php | 12 ++++----- system/database/drivers/sqlite/sqlite_utility.php | 6 ++--- 8 files changed, 55 insertions(+), 42 deletions(-) (limited to 'system') diff --git a/system/database/DB_utility.php b/system/database/DB_utility.php index 8e1921dbc..128984d4f 100644 --- a/system/database/DB_utility.php +++ b/system/database/DB_utility.php @@ -181,7 +181,8 @@ class CI_DB_utility { return FALSE; } - return $this->_field_data($this->db->dbprefix.$table); + $query = $this->db->query($this->_field_data($this->db->dbprefix.$table)); + return $query->field_data(); } // -------------------------------------------------------------------- @@ -208,6 +209,32 @@ class CI_DB_utility { return current($fields); } + // -------------------------------------------------------------------- + + /** + * Create database + * + * @access public + * @param string the database name + * @return bool + */ + function create_database($name) + { + $sql = $this->_create_database($name); + + if (is_bool($sql)) + { + return $sql; + } + + return $this->db->query($sql); + } + + // -------------------------------------------------------------------- + + + + function create_table() diff --git a/system/database/drivers/mssql/mssql_utility.php b/system/database/drivers/mssql/mssql_utility.php index 61fe5fcbc..49b63b7d0 100644 --- a/system/database/drivers/mssql/mssql_utility.php +++ b/system/database/drivers/mssql/mssql_utility.php @@ -28,13 +28,13 @@ class CI_DB_mssql_utility extends CI_DB_utility { /** * Create database * - * @access public + * @access private * @param string the database name * @return bool */ - function create_database($name) + function _create_database($name) { - return $this->db->query("CREATE DATABASE ".$name); + return "CREATE DATABASE ".$name; } // -------------------------------------------------------------------- @@ -84,7 +84,7 @@ class CI_DB_mssql_utility extends CI_DB_utility { */ function drop_table($table) { - "DROP TABLE ".$this->db->_escape_table($name); + return $this->db->query("DROP TABLE ".$this->db->_escape_table($name)); } // -------------------------------------------------------------------- @@ -144,9 +144,7 @@ class CI_DB_mssql_utility extends CI_DB_utility { */ function _field_data($table) { - $sql = "SELECT TOP 1 FROM ".$this->db->_escape_table($table); - $query = $this->db->query($sql); - return $query->field_data(); + return "SELECT TOP 1 FROM ".$this->db->_escape_table($table); } diff --git a/system/database/drivers/mysql/mysql_utility.php b/system/database/drivers/mysql/mysql_utility.php index 23c4e094d..e5f8e850d 100644 --- a/system/database/drivers/mysql/mysql_utility.php +++ b/system/database/drivers/mysql/mysql_utility.php @@ -27,13 +27,13 @@ class CI_DB_mysql_utility extends CI_DB_utility { /** * Create database * - * @access public + * @access private * @param string the database name * @return bool */ - function create_database($name) + function _create_database($name) { - return $this->db->query("CREATE DATABASE ".$name); + return "CREATE DATABASE ".$name; } // -------------------------------------------------------------------- @@ -83,7 +83,7 @@ class CI_DB_mysql_utility extends CI_DB_utility { */ function drop_table($table) { - "DROP TABLE IF EXISTS ".$this->db->_escape_table($name); + return $this->db->query("DROP TABLE IF EXISTS ".$this->db->_escape_table($name)); } // -------------------------------------------------------------------- @@ -143,9 +143,7 @@ class CI_DB_mysql_utility extends CI_DB_utility { */ function _field_data($table) { - $sql = "SELECT * FROM ".$this->db->_escape_table($table)." LIMIT 1"; - $query = $this->db->query($sql); - return $query->field_data(); + return "SELECT * FROM ".$this->db->_escape_table($table)." LIMIT 1"; } diff --git a/system/database/drivers/mysqli/mysqli_utility.php b/system/database/drivers/mysqli/mysqli_utility.php index ca8f3fe34..1775047ca 100644 --- a/system/database/drivers/mysqli/mysqli_utility.php +++ b/system/database/drivers/mysqli/mysqli_utility.php @@ -27,13 +27,13 @@ class CI_DB_mysqli_utility extends CI_DB_utility { /** * Create database * - * @access public + * @access private * @param string the database name * @return bool */ - function create_database($name) + function _create_database($name) { - return $this->db->query("CREATE DATABASE ".$name); + return "CREATE DATABASE ".$name; } // -------------------------------------------------------------------- @@ -83,7 +83,7 @@ class CI_DB_mysqli_utility extends CI_DB_utility { */ function drop_table($table) { - "DROP TABLE IF EXISTS ".$this->db->_escape_table($name); + return $this->db->query("DROP TABLE IF EXISTS ".$this->db->_escape_table($name)); } // -------------------------------------------------------------------- @@ -143,9 +143,7 @@ class CI_DB_mysqli_utility extends CI_DB_utility { */ function _field_data($table) { - $sql = "SELECT * FROM ".$this->db->_escape_table($table)." LIMIT 1"; - $query = $this->db->query($sql); - return $query->field_data(); + return "SELECT * FROM ".$this->db->_escape_table($table)." LIMIT 1"; } diff --git a/system/database/drivers/oci8/oci8_utility.php b/system/database/drivers/oci8/oci8_utility.php index 7e3ee7285..74b0165cb 100644 --- a/system/database/drivers/oci8/oci8_utility.php +++ b/system/database/drivers/oci8/oci8_utility.php @@ -32,7 +32,7 @@ class CI_DB_oci8_utility extends CI_DB_utility { * @param string the database name * @return bool */ - function create_database($name) + function _create_database($name) { } @@ -130,9 +130,7 @@ class CI_DB_oci8_utility extends CI_DB_utility { */ function _field_data($table) { - $sql = "SELECT * FROM ".$this->db->_escape_table($table)." where rownum = 1"; - $query = $this->db->query($sql); - return $query->field_data(); + return "SELECT * FROM ".$this->db->_escape_table($table)." where rownum = 1"; } diff --git a/system/database/drivers/odbc/odbc_utility.php b/system/database/drivers/odbc/odbc_utility.php index cfd829cb6..74f8d3905 100644 --- a/system/database/drivers/odbc/odbc_utility.php +++ b/system/database/drivers/odbc/odbc_utility.php @@ -28,11 +28,11 @@ class CI_DB_odbc_utility extends CI_DB_utility { /** * Create database * - * @access public + * @access private * @param string the database name * @return bool */ - function create_database($name) + function _create_database() { // ODBC has no "create database" command since it's // designed to connect to an existing database @@ -156,9 +156,7 @@ class CI_DB_odbc_utility extends CI_DB_utility { */ function _field_data($table) { - $sql = "SELECT TOP 1 FROM ".$this->db->_escape_table($table); - $query = $this->db->query($sql); - return $query->field_data(); + return "SELECT TOP 1 FROM ".$this->db->_escape_table($table); } diff --git a/system/database/drivers/postgre/postgre_utility.php b/system/database/drivers/postgre/postgre_utility.php index 7bb210ab7..8e51623be 100644 --- a/system/database/drivers/postgre/postgre_utility.php +++ b/system/database/drivers/postgre/postgre_utility.php @@ -28,13 +28,13 @@ class CI_DB_postgre_utility extends CI_DB_utility { /** * Create database * - * @access public + * @access private * @param string the database name * @return bool */ - function create_database($name) + function _create_database($name) { - return $this->db->query("CREATE DATABASE ".$name); + return "CREATE DATABASE ".$name; } // -------------------------------------------------------------------- @@ -84,7 +84,7 @@ class CI_DB_postgre_utility extends CI_DB_utility { */ function drop_table($table) { - "DROP TABLE ".$this->db->_escape_table($name)." CASCADE"; + return $this->db->query("DROP TABLE ".$this->db->_escape_table($name)." CASCADE"); } // -------------------------------------------------------------------- @@ -144,9 +144,7 @@ class CI_DB_postgre_utility extends CI_DB_utility { */ function _field_data($table) { - $sql = "SELECT * FROM ".$this->db->_escape_table($table)." LIMIT 1"; - $query = $this->db->query($sql); - return $query->field_data(); + return "SELECT * FROM ".$this->db->_escape_table($table)." LIMIT 1"; } diff --git a/system/database/drivers/sqlite/sqlite_utility.php b/system/database/drivers/sqlite/sqlite_utility.php index 744ca3f37..14b406a5c 100644 --- a/system/database/drivers/sqlite/sqlite_utility.php +++ b/system/database/drivers/sqlite/sqlite_utility.php @@ -32,7 +32,7 @@ class CI_DB_sqlite_utility extends CI_DB_utility { * @param string the database name * @return bool */ - function create_database() + function _create_database() { // In SQLite, a database is created when you connect to the database return TRUE; @@ -152,9 +152,7 @@ class CI_DB_sqlite_utility extends CI_DB_utility { */ function _field_data($table) { - $sql = "SELECT * FROM ".$this->db->_escape_table($table)." LIMIT 1"; - $query = $this->db->query($sql); - return $query->field_data(); + return "SELECT * FROM ".$this->db->_escape_table($table)." LIMIT 1"; } -- cgit v1.2.3-24-g4f1b From 83b05a860a5f208d15942b517385848cfe4887bb Mon Sep 17 00:00:00 2001 From: admin Date: Mon, 25 Sep 2006 21:06:46 +0000 Subject: --- system/codeigniter/CodeIgniter.php | 4 +- system/database/DB_utility.php | 60 +++++++++++++++++++++- system/database/drivers/mssql/mssql_utility.php | 28 ++++------ system/database/drivers/mysql/mysql_utility.php | 28 ++++------ system/database/drivers/mysqli/mysqli_utility.php | 28 ++++------ system/database/drivers/oci8/oci8_utility.php | 16 +++--- system/database/drivers/odbc/odbc_utility.php | 12 ++--- .../database/drivers/postgre/postgre_utility.php | 28 ++++------ system/database/drivers/sqlite/sqlite_utility.php | 12 ++--- system/libraries/Loader.php | 7 ++- system/libraries/Router.php | 20 ++++---- system/libraries/Validation.php | 16 +++++- 12 files changed, 148 insertions(+), 111 deletions(-) (limited to 'system') diff --git a/system/codeigniter/CodeIgniter.php b/system/codeigniter/CodeIgniter.php index 434602742..a227066fc 100644 --- a/system/codeigniter/CodeIgniter.php +++ b/system/codeigniter/CodeIgniter.php @@ -197,8 +197,8 @@ else show_404(); } - // Call the requested method. Any URI segments present (besides the class/function) - // will be passed to the method for convenience + // 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($RTR->rsegments, (($RTR->fetch_directory() == '') ? 2 : 3))); } } diff --git a/system/database/DB_utility.php b/system/database/DB_utility.php index 128984d4f..36d74c5b3 100644 --- a/system/database/DB_utility.php +++ b/system/database/DB_utility.php @@ -232,14 +232,70 @@ class CI_DB_utility { // -------------------------------------------------------------------- + /** + * Drop database + * + * @access public + * @param string the database name + * @return bool + */ + function drop_database($name) + { + $sql = $this->_drop_database($name); + + if (is_bool($sql)) + { + return $sql; + } + + return $this->db->query($sql); + } + // -------------------------------------------------------------------- + /** + * List databases + * + * @access public + * @return bool + */ + function list_databases() + { + $query = $this->db->query($this->_list_database()); + $dbs = array(); + if ($query->num_rows() > 0) + { + foreach ($query->result_array() as $row) + { + $dbs[] = current($row); + } + } + + return $dbs; + } + // -------------------------------------------------------------------- - - function create_table() + /** + * Drop Table + * + * @access public + * @param string the table name + * @return bool + */ + function drop_table($name) { + $sql = $this->_drop_table($name); + + if (is_bool($sql)) + { + return $sql; + } + + return $this->db->query($sql); } + + function alter_table() { diff --git a/system/database/drivers/mssql/mssql_utility.php b/system/database/drivers/mssql/mssql_utility.php index 49b63b7d0..b85a420e7 100644 --- a/system/database/drivers/mssql/mssql_utility.php +++ b/system/database/drivers/mssql/mssql_utility.php @@ -42,13 +42,13 @@ class CI_DB_mssql_utility extends CI_DB_utility { /** * Drop database * - * @access public + * @access private * @param string the database name * @return bool */ - function drop_database($name) + function _drop_database($name) { - return $this->db->query("DROP DATABASE ".$name); + return "DROP DATABASE ".$name; } // -------------------------------------------------------------------- @@ -56,22 +56,12 @@ class CI_DB_mssql_utility extends CI_DB_utility { /** * List databases * - * @access public + * @access private * @return bool */ - function list_databases() + function _list_databases() { - $query = $this->db->query("EXEC sp_helpdb"); // Can also be: EXEC sp_databases - $dbs = array(); - if ($query->num_rows() > 0) - { - foreach ($query->result_array() as $row) - { - $dbs[] = current($row); - } - } - - return $dbs; + return "EXEC sp_helpdb"; // Can also be: EXEC sp_databases } // -------------------------------------------------------------------- @@ -79,12 +69,12 @@ class CI_DB_mssql_utility extends CI_DB_utility { /** * Drop Table * - * @access public + * @access private * @return bool */ - function drop_table($table) + function _drop_table($table) { - return $this->db->query("DROP TABLE ".$this->db->_escape_table($name)); + return "DROP TABLE ".$this->db->_escape_table($name); } // -------------------------------------------------------------------- diff --git a/system/database/drivers/mysql/mysql_utility.php b/system/database/drivers/mysql/mysql_utility.php index e5f8e850d..a0c746207 100644 --- a/system/database/drivers/mysql/mysql_utility.php +++ b/system/database/drivers/mysql/mysql_utility.php @@ -41,13 +41,13 @@ class CI_DB_mysql_utility extends CI_DB_utility { /** * Drop database * - * @access public + * @access private * @param string the database name * @return bool */ - function drop_database($name) + function _drop_database($name) { - return $this->db->query("DROP DATABASE ".$name); + return "DROP DATABASE ".$name; } // -------------------------------------------------------------------- @@ -55,22 +55,12 @@ class CI_DB_mysql_utility extends CI_DB_utility { /** * List databases * - * @access public + * @access private * @return bool */ - function list_databases() + function _list_databases() { - $query = $this->db->query("SHOW DATABASES"); - $dbs = array(); - if ($query->num_rows() > 0) - { - foreach ($query->result_array() as $row) - { - $dbs[] = current($row); - } - } - - return $dbs; + return "SHOW DATABASES"; } // -------------------------------------------------------------------- @@ -78,12 +68,12 @@ class CI_DB_mysql_utility extends CI_DB_utility { /** * Drop Table * - * @access public + * @access private * @return bool */ - function drop_table($table) + function _drop_table($table) { - return $this->db->query("DROP TABLE IF EXISTS ".$this->db->_escape_table($name)); + return "DROP TABLE IF EXISTS ".$this->db->_escape_table($name); } // -------------------------------------------------------------------- diff --git a/system/database/drivers/mysqli/mysqli_utility.php b/system/database/drivers/mysqli/mysqli_utility.php index 1775047ca..328661866 100644 --- a/system/database/drivers/mysqli/mysqli_utility.php +++ b/system/database/drivers/mysqli/mysqli_utility.php @@ -41,13 +41,13 @@ class CI_DB_mysqli_utility extends CI_DB_utility { /** * Drop database * - * @access public + * @access private * @param string the database name * @return bool */ - function drop_database($name) + function _drop_database($name) { - return $this->db->query("DROP DATABASE ".$name); + return "DROP DATABASE ".$name; } // -------------------------------------------------------------------- @@ -55,22 +55,12 @@ class CI_DB_mysqli_utility extends CI_DB_utility { /** * List databases * - * @access public + * @access private * @return bool */ - function list_databases() + function _list_databases() { - $query = $this->db->query("SHOW DATABASES"); - $dbs = array(); - if ($query->num_rows() > 0) - { - foreach ($query->result_array() as $row) - { - $dbs[] = current($row); - } - } - - return $dbs; + return "SHOW DATABASES"; } // -------------------------------------------------------------------- @@ -78,12 +68,12 @@ class CI_DB_mysqli_utility extends CI_DB_utility { /** * Drop Table * - * @access public + * @access private * @return bool */ - function drop_table($table) + function _drop_table($table) { - return $this->db->query("DROP TABLE IF EXISTS ".$this->db->_escape_table($name)); + return "DROP TABLE IF EXISTS ".$this->db->_escape_table($name); } // -------------------------------------------------------------------- diff --git a/system/database/drivers/oci8/oci8_utility.php b/system/database/drivers/oci8/oci8_utility.php index 74b0165cb..9c3059f41 100644 --- a/system/database/drivers/oci8/oci8_utility.php +++ b/system/database/drivers/oci8/oci8_utility.php @@ -34,6 +34,7 @@ class CI_DB_oci8_utility extends CI_DB_utility { */ function _create_database($name) { + return FALSE; } // -------------------------------------------------------------------- @@ -41,12 +42,13 @@ class CI_DB_oci8_utility extends CI_DB_utility { /** * Drop database * - * @access public + * @access private * @param string the database name * @return bool */ - function drop_database($name) + function _drop_database($name) { + return FALSE; } // -------------------------------------------------------------------- @@ -54,11 +56,12 @@ class CI_DB_oci8_utility extends CI_DB_utility { /** * List databases * - * @access public + * @access private * @return bool */ - function list_databases() + function _list_databases() { + return FALSE; } // -------------------------------------------------------------------- @@ -66,11 +69,12 @@ class CI_DB_oci8_utility extends CI_DB_utility { /** * Drop Table * - * @access public + * @access private * @return bool */ - function drop_table($table) + function _drop_table($table) { + return FALSE; } // -------------------------------------------------------------------- diff --git a/system/database/drivers/odbc/odbc_utility.php b/system/database/drivers/odbc/odbc_utility.php index 74f8d3905..5b4558f68 100644 --- a/system/database/drivers/odbc/odbc_utility.php +++ b/system/database/drivers/odbc/odbc_utility.php @@ -48,11 +48,11 @@ class CI_DB_odbc_utility extends CI_DB_utility { /** * Drop database * - * @access public + * @access private * @param string the database name * @return bool */ - function drop_database($name) + function _drop_database($name) { // ODBC has no "drop database" command since it's // designed to connect to an existing database @@ -68,10 +68,10 @@ class CI_DB_odbc_utility extends CI_DB_utility { /** * List databases * - * @access public + * @access private * @return bool */ - function list_databases() + function _list_databases() { // Not sure if ODBC lets you list all databases... if ($this->db_debug) @@ -86,10 +86,10 @@ class CI_DB_odbc_utility extends CI_DB_utility { /** * Drop Table * - * @access public + * @access private * @return bool */ - function drop_table($table) + function _drop_table($table) { // Not a supported ODBC feature if ($this->db_debug) diff --git a/system/database/drivers/postgre/postgre_utility.php b/system/database/drivers/postgre/postgre_utility.php index 8e51623be..b31609aea 100644 --- a/system/database/drivers/postgre/postgre_utility.php +++ b/system/database/drivers/postgre/postgre_utility.php @@ -42,13 +42,13 @@ class CI_DB_postgre_utility extends CI_DB_utility { /** * Drop database * - * @access public + * @access private * @param string the database name * @return bool */ - function drop_database($name) + function _drop_database($name) { - return $this->db->query("DROP DATABASE ".$name); + return "DROP DATABASE ".$name; } // -------------------------------------------------------------------- @@ -56,22 +56,12 @@ class CI_DB_postgre_utility extends CI_DB_utility { /** * List databases * - * @access public + * @access private * @return bool */ - function list_databases() + function _list_databases() { - $query = $this->db->query("SELECT datname FROM pg_database"); - $dbs = array(); - if ($query->num_rows() > 0) - { - foreach ($query->result_array() as $row) - { - $dbs[] = current($row); - } - } - - return $dbs; + return "SELECT datname FROM pg_database"; } // -------------------------------------------------------------------- @@ -79,12 +69,12 @@ class CI_DB_postgre_utility extends CI_DB_utility { /** * Drop Table * - * @access public + * @access private * @return bool */ - function drop_table($table) + function _drop_table($table) { - return $this->db->query("DROP TABLE ".$this->db->_escape_table($name)." CASCADE"); + return "DROP TABLE ".$this->db->_escape_table($name)." CASCADE"; } // -------------------------------------------------------------------- diff --git a/system/database/drivers/sqlite/sqlite_utility.php b/system/database/drivers/sqlite/sqlite_utility.php index 14b406a5c..754a755e4 100644 --- a/system/database/drivers/sqlite/sqlite_utility.php +++ b/system/database/drivers/sqlite/sqlite_utility.php @@ -43,11 +43,11 @@ class CI_DB_sqlite_utility extends CI_DB_utility { /** * Drop database * - * @access public + * @access private * @param string the database name * @return bool */ - function drop_database($name) + function _drop_database($name) { if ( ! @file_exists($this->db->database) OR ! @unlink($this->db->database)) { @@ -65,10 +65,10 @@ class CI_DB_sqlite_utility extends CI_DB_utility { /** * List databases * - * @access public + * @access private * @return bool */ - function list_databases() + function _list_databases() { if ($this->db_debug) { @@ -82,10 +82,10 @@ class CI_DB_sqlite_utility extends CI_DB_utility { /** * Drop Table * - * @access public + * @access private * @return bool */ - function drop_table($table) + function _drop_table($table) { if ($this->db_debug) { diff --git a/system/libraries/Loader.php b/system/libraries/Loader.php index f4a9f821d..b69d3f049 100644 --- a/system/libraries/Loader.php +++ b/system/libraries/Loader.php @@ -363,7 +363,10 @@ class CI_Loader { * Load Script * * This function loads the specified include file from the - * application/scripts/ folder + * application/scripts/ folder. + * + * NOTE: This feature has been deprecated but it will remain available + * for legacy users. * * @access public * @param array @@ -496,7 +499,7 @@ class CI_Loader { } /* - * Extract and cached variables + * 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 diff --git a/system/libraries/Router.php b/system/libraries/Router.php index d1751a0e9..d7740f5f3 100644 --- a/system/libraries/Router.php +++ b/system/libraries/Router.php @@ -149,12 +149,12 @@ class CI_Router { return; } - $this->set_class($segments['0']); + $this->set_class($segments[0]); - if (isset($segments['1'])) + if (isset($segments[1])) { // A scaffolding request. No funny business with the URL - if ($this->routes['scaffolding_trigger'] == $segments['1'] AND $segments['1'] != '_ci_scaffolding') + if ($this->routes['scaffolding_trigger'] == $segments[1] AND $segments[1] != '_ci_scaffolding') { $this->scaffolding_request = TRUE; unset($this->routes['scaffolding_trigger']); @@ -162,7 +162,7 @@ class CI_Router { else { // A standard method request - $this->set_method($segments['1']); + $this->set_method($segments[1]); } } @@ -186,22 +186,22 @@ class CI_Router { function _validate_segments($segments) { // Does the requested controller exist in the root folder? - if (file_exists(APPPATH.'controllers/'.$segments['0'].EXT)) + if (file_exists(APPPATH.'controllers/'.$segments[0].EXT)) { return $segments; } // Is the controller in a sub-folder? - if (is_dir(APPPATH.'controllers/'.$segments['0'])) + if (is_dir(APPPATH.'controllers/'.$segments[0])) { // Set the directory and remove it from the segment array - $this->set_directory($segments['0']); + $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'].EXT)) + if ( ! file_exists(APPPATH.'controllers/'.$this->fetch_directory().$segments[0].EXT)) { show_404(); } @@ -250,7 +250,7 @@ class CI_Router { { $this->segments[$i++] = $val; } - unset($this->segments['0']); + unset($this->segments[0]); if ($diff == FALSE) { @@ -263,7 +263,7 @@ class CI_Router { { $this->rsegments[$i++] = $val; } - unset($this->rsegments['0']); + unset($this->rsegments[0]); } } // END _reindex_segments() diff --git a/system/libraries/Validation.php b/system/libraries/Validation.php index 153657e31..b65b9be52 100644 --- a/system/libraries/Validation.php +++ b/system/libraries/Validation.php @@ -519,13 +519,27 @@ class CI_Validation { * Numeric * * @access public - * @param string + * @param int * @return bool */ function numeric($str) { return ( ! ereg("^[0-9\.]+$", $str)) ? FALSE : TRUE; } + + // -------------------------------------------------------------------- + + /** + * Is Numeric + * + * @access public + * @param string + * @return bool + */ + function is_numeric($str) + { + return ( ! is_numeric($str)) ? FALSE : TRUE; + } // -------------------------------------------------------------------- -- cgit v1.2.3-24-g4f1b From e106318c19938c621198924ab5d292592dbb4477 Mon Sep 17 00:00:00 2001 From: admin Date: Mon, 25 Sep 2006 22:12:16 +0000 Subject: --- system/database/DB_result.php | 72 ++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 71 insertions(+), 1 deletion(-) (limited to 'system') diff --git a/system/database/DB_result.php b/system/database/DB_result.php index 970a0db68..32c51e07b 100644 --- a/system/database/DB_result.php +++ b/system/database/DB_result.php @@ -35,6 +35,7 @@ class CI_DB_result { var $result_object = array(); var $current_row = 0; + /** * Query result. Acts as a wrapper function for the following functions. * @@ -46,7 +47,7 @@ class CI_DB_result { { return ($type == 'object') ? $this->result_object() : $this->result_array(); } - + // -------------------------------------------------------------------- /** @@ -243,6 +244,75 @@ class CI_DB_result { return $result[$this->current_row]; } + // -------------------------------------------------------------------- + + /** + * Number of rows in the result set + * + * @access public + * @return integer + */ + function num_rows() + { + // Implemented in the platform-specific result adapter + } + + // -------------------------------------------------------------------- + + /** + * Number of fields in the result set + * + * @access public + * @return integer + */ + function num_fields() + { + // Implemented in the platform-specific result adapter + } + + // -------------------------------------------------------------------- + + /** + * Fetch Field Names + * + * Generates an array of column names + * + * @access public + * @return array + */ + function field_names() + { + // Implemented in the platform-specific result adapter + } + + // -------------------------------------------------------------------- + + /** + * Field data + * + * Generates an array of objects containing field meta-data + * + * @access public + * @return array + */ + function field_data() + { + // Implemented in the platform-specific result adapter + } + + // -------------------------------------------------------------------- + + /** + * Free the result + * + * @return null + */ + function free_result() + { + // Implemented in the platform-specific result adapter + } + + } ?> \ No newline at end of file -- cgit v1.2.3-24-g4f1b From ab4f61bacfa022c0c7238e9661ad9cb2ac440d95 Mon Sep 17 00:00:00 2001 From: admin Date: Mon, 25 Sep 2006 22:12:32 +0000 Subject: --- system/database/DB_utility.php | 114 +++++++++++++-------- system/database/drivers/mssql/mssql_result.php | 23 ++++- system/database/drivers/mssql/mssql_utility.php | 31 ++++++ system/database/drivers/mysql/mysql_result.php | 21 ++++ system/database/drivers/mysql/mysql_utility.php | 33 ++++++ system/database/drivers/mysqli/mysqli_result.php | 23 ++++- system/database/drivers/mysqli/mysqli_utility.php | 31 ++++++ system/database/drivers/oci8/oci8_result.php | 21 ++++ system/database/drivers/oci8/oci8_utility.php | 32 ++++++ system/database/drivers/odbc/odbc_result.php | 23 ++++- system/database/drivers/odbc/odbc_utility.php | 41 ++++++++ system/database/drivers/postgre/postgre_result.php | 23 ++++- .../database/drivers/postgre/postgre_utility.php | 32 ++++++ system/database/drivers/sqlite/sqlite_result.php | 23 ++++- system/database/drivers/sqlite/sqlite_utility.php | 31 ++++++ 15 files changed, 454 insertions(+), 48 deletions(-) (limited to 'system') diff --git a/system/database/DB_utility.php b/system/database/DB_utility.php index 36d74c5b3..950db7dfd 100644 --- a/system/database/DB_utility.php +++ b/system/database/DB_utility.php @@ -64,6 +64,30 @@ class CI_DB_utility { // -------------------------------------------------------------------- + /** + * 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->field_names($table); + + if ( ! is_array($fields)) + { + return FALSE; + } + + return current($fields); + } + + // -------------------------------------------------------------------- + /** * Returns an array of table names * @@ -187,30 +211,6 @@ class CI_DB_utility { // -------------------------------------------------------------------- - /** - * 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->field_names($table); - - if ( ! is_array($fields)) - { - return FALSE; - } - - return current($fields); - } - - // -------------------------------------------------------------------- - /** * Create database * @@ -218,9 +218,9 @@ class CI_DB_utility { * @param string the database name * @return bool */ - function create_database($name) + function create_database($db_name) { - $sql = $this->_create_database($name); + $sql = $this->_create_database($db_name); if (is_bool($sql)) { @@ -239,9 +239,9 @@ class CI_DB_utility { * @param string the database name * @return bool */ - function drop_database($name) + function drop_database($db_name) { - $sql = $this->_drop_database($name); + $sql = $this->_drop_database($db_name); if (is_bool($sql)) { @@ -273,48 +273,76 @@ class CI_DB_utility { return $dbs; } - + // -------------------------------------------------------------------- /** - * Drop Table + * Optimize Table * * @access public * @param string the table name * @return bool */ - function drop_table($name) + function optimize_table($table_name) { - $sql = $this->_drop_table($name); + $sql = $this->_optimize_table($table_name); if (is_bool($sql)) { return $sql; } - return $this->db->query($sql); + $query = $this->db->query($sql); + return current($query->result_array()); } + // -------------------------------------------------------------------- - - function alter_table() + /** + * Optimize 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; + } - function create_index() - { + $query = $this->db->query($sql); + return current($query->result_array()); } - - function drop_index() + + // -------------------------------------------------------------------- + + /** + * Drop Table + * + * @access public + * @param string the table name + * @return bool + */ + function drop_table($table_name) { - } + $sql = $this->_drop_table($table_name); + + if (is_bool($sql)) + { + return $sql; + } - function optimize() - { + return $this->db->query($sql); } + } ?> \ No newline at end of file diff --git a/system/database/drivers/mssql/mssql_result.php b/system/database/drivers/mssql/mssql_result.php index a8a8e2006..53b7832d9 100644 --- a/system/database/drivers/mssql/mssql_result.php +++ b/system/database/drivers/mssql/mssql_result.php @@ -49,7 +49,28 @@ class CI_DB_mssql_result extends CI_DB_result { { return @mssql_num_fields($this->result_id); } - + + // -------------------------------------------------------------------- + + /** + * Fetch Field Names + * + * Generates an array of column names + * + * @access public + * @return array + */ + function field_names() + { + $field_names = array(); + while ($field = mssql_fetch_field($this->result_id)) + { + $field_names[] = $field->name; + } + + return $field_names; + } + // -------------------------------------------------------------------- /** diff --git a/system/database/drivers/mssql/mssql_utility.php b/system/database/drivers/mssql/mssql_utility.php index b85a420e7..cf15104c6 100644 --- a/system/database/drivers/mssql/mssql_utility.php +++ b/system/database/drivers/mssql/mssql_utility.php @@ -138,6 +138,37 @@ class CI_DB_mssql_utility extends CI_DB_utility { } + // -------------------------------------------------------------------- + + /** + * 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 MS SQL? + } + + // -------------------------------------------------------------------- + + /** + * 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 return FALSE; // Is this supported in MS SQL? + } } diff --git a/system/database/drivers/mysql/mysql_result.php b/system/database/drivers/mysql/mysql_result.php index e540489bb..91c4af12c 100644 --- a/system/database/drivers/mysql/mysql_result.php +++ b/system/database/drivers/mysql/mysql_result.php @@ -52,6 +52,27 @@ class CI_DB_mysql_result extends CI_DB_result { // -------------------------------------------------------------------- + /** + * Fetch Field Names + * + * Generates an array of column names + * + * @access public + * @return array + */ + function field_names() + { + $field_names = array(); + while ($field = mysql_fetch_field($this->result_id)) + { + $field_names[] = $field->name; + } + + return $field_names; + } + + // -------------------------------------------------------------------- + /** * Field data * diff --git a/system/database/drivers/mysql/mysql_utility.php b/system/database/drivers/mysql/mysql_utility.php index a0c746207..800a90c7a 100644 --- a/system/database/drivers/mysql/mysql_utility.php +++ b/system/database/drivers/mysql/mysql_utility.php @@ -136,6 +136,39 @@ class CI_DB_mysql_utility extends CI_DB_utility { return "SELECT * FROM ".$this->db->_escape_table($table)." LIMIT 1"; } + // -------------------------------------------------------------------- + + /** + * 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 "OPTIMIZE TABLE ".$this->db->_escape_table($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_table($table); + } + + } diff --git a/system/database/drivers/mysqli/mysqli_result.php b/system/database/drivers/mysqli/mysqli_result.php index b0db6c106..2eca68ff5 100644 --- a/system/database/drivers/mysqli/mysqli_result.php +++ b/system/database/drivers/mysqli/mysqli_result.php @@ -49,7 +49,28 @@ class CI_DB_mysqli_result extends CI_DB_result { { return @mysqli_num_fields($this->result_id); } - + + // -------------------------------------------------------------------- + + /** + * Fetch Field Names + * + * Generates an array of column names + * + * @access public + * @return array + */ + function field_names() + { + $field_names = array(); + while ($field = mysql_fetch_field($this->result_id)) + { + $field_names[] = $field->name; + } + + return $field_names; + } + // -------------------------------------------------------------------- /** diff --git a/system/database/drivers/mysqli/mysqli_utility.php b/system/database/drivers/mysqli/mysqli_utility.php index 328661866..8c9e1e960 100644 --- a/system/database/drivers/mysqli/mysqli_utility.php +++ b/system/database/drivers/mysqli/mysqli_utility.php @@ -136,6 +136,37 @@ class CI_DB_mysqli_utility extends CI_DB_utility { return "SELECT * FROM ".$this->db->_escape_table($table)." LIMIT 1"; } + // -------------------------------------------------------------------- + + /** + * 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 "OPTIMIZE TABLE ".$this->db->_escape_table($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_table($table); + } } diff --git a/system/database/drivers/oci8/oci8_result.php b/system/database/drivers/oci8/oci8_result.php index d2354a1c6..59adda76b 100644 --- a/system/database/drivers/oci8/oci8_result.php +++ b/system/database/drivers/oci8/oci8_result.php @@ -74,6 +74,27 @@ class CI_DB_oci8_result extends CI_DB_result { return $count; } + // -------------------------------------------------------------------- + + /** + * Fetch Field Names + * + * Generates an array of column names + * + * @access public + * @return array + */ + function field_names() + { + $field_names = array(); + $fieldCount = $this->num_fields(); + for ($c = 1; $c <= $fieldCount; $c++) + { + $field_names[] = ocicolumnname($this->stmt_id, $c); + } + return $field_names; + } + // -------------------------------------------------------------------- /** diff --git a/system/database/drivers/oci8/oci8_utility.php b/system/database/drivers/oci8/oci8_utility.php index 9c3059f41..011e971d9 100644 --- a/system/database/drivers/oci8/oci8_utility.php +++ b/system/database/drivers/oci8/oci8_utility.php @@ -138,6 +138,38 @@ class CI_DB_oci8_utility extends CI_DB_utility { } + // -------------------------------------------------------------------- + + /** + * 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 return FALSE; // Is this supported in Oracle? + } + } ?> \ No newline at end of file diff --git a/system/database/drivers/odbc/odbc_result.php b/system/database/drivers/odbc/odbc_result.php index 49e5e9012..385209c56 100644 --- a/system/database/drivers/odbc/odbc_result.php +++ b/system/database/drivers/odbc/odbc_result.php @@ -49,7 +49,28 @@ class CI_DB_odbc_result extends CI_DB_result { { return @odbc_num_fields($this->result_id); } - + + // -------------------------------------------------------------------- + + /** + * Fetch Field Names + * + * Generates an array of column names + * + * @access public + * @return array + */ + function field_names() + { + $field_names = array(); + for ($i = 0; $i < $this->num_fields(); $i++) + { + $field_names[] = odbc_field_name($this->result_id, $i); + } + + return $field_names; + } + // -------------------------------------------------------------------- /** diff --git a/system/database/drivers/odbc/odbc_utility.php b/system/database/drivers/odbc/odbc_utility.php index 5b4558f68..2932da874 100644 --- a/system/database/drivers/odbc/odbc_utility.php +++ b/system/database/drivers/odbc/odbc_utility.php @@ -159,6 +159,47 @@ class CI_DB_odbc_utility extends CI_DB_utility { return "SELECT TOP 1 FROM ".$this->db->_escape_table($table); } + // -------------------------------------------------------------------- + + /** + * 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_debug) + { + return $this->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_debug) + { + return $this->display_error('db_unsuported_feature'); + } + return FALSE; + } } diff --git a/system/database/drivers/postgre/postgre_result.php b/system/database/drivers/postgre/postgre_result.php index 6af7f94f2..ee838b450 100644 --- a/system/database/drivers/postgre/postgre_result.php +++ b/system/database/drivers/postgre/postgre_result.php @@ -49,7 +49,28 @@ class CI_DB_postgre_result extends CI_DB_result { { return @pg_num_fields($this->result_id); } - + + // -------------------------------------------------------------------- + + /** + * Fetch Field Names + * + * Generates an array of column names + * + * @access public + * @return array + */ + function field_names() + { + $field_names = array(); + for ($i = 0; $i < $this->num_fields(); $i++) + { + $Ffield_names[] = pg_field_name($this->result_id, $i); + } + + return $field_names; + } + // -------------------------------------------------------------------- /** diff --git a/system/database/drivers/postgre/postgre_utility.php b/system/database/drivers/postgre/postgre_utility.php index b31609aea..b2fdd5fd4 100644 --- a/system/database/drivers/postgre/postgre_utility.php +++ b/system/database/drivers/postgre/postgre_utility.php @@ -137,6 +137,38 @@ class CI_DB_postgre_utility extends CI_DB_utility { return "SELECT * FROM ".$this->db->_escape_table($table)." LIMIT 1"; } + // -------------------------------------------------------------------- + + /** + * 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 Postgre? + } + + // -------------------------------------------------------------------- + + /** + * 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 return FALSE; // Is this supported in Postgre? + } + } diff --git a/system/database/drivers/sqlite/sqlite_result.php b/system/database/drivers/sqlite/sqlite_result.php index f30a8cfdf..7f48ce8aa 100644 --- a/system/database/drivers/sqlite/sqlite_result.php +++ b/system/database/drivers/sqlite/sqlite_result.php @@ -49,7 +49,28 @@ class CI_DB_sqlite_result extends CI_DB_result { { return @sqlite_num_fields($this->result_id); } - + + // -------------------------------------------------------------------- + + /** + * Fetch Field Names + * + * Generates an array of column names + * + * @access public + * @return array + */ + function field_names() + { + $field_names = array(); + for ($i = 0; $i < $this->num_fields(); $i++) + { + $Ffield_names[] = sqlite_field_name($this->result_id, $i); + } + + return $field_names; + } + // -------------------------------------------------------------------- /** diff --git a/system/database/drivers/sqlite/sqlite_utility.php b/system/database/drivers/sqlite/sqlite_utility.php index 754a755e4..e9f4eb64e 100644 --- a/system/database/drivers/sqlite/sqlite_utility.php +++ b/system/database/drivers/sqlite/sqlite_utility.php @@ -155,6 +155,37 @@ class CI_DB_sqlite_utility extends CI_DB_utility { return "SELECT * FROM ".$this->db->_escape_table($table)." LIMIT 1"; } + // -------------------------------------------------------------------- + + /** + * 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 SQLite? + } + + // -------------------------------------------------------------------- + + /** + * 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 return FALSE; // Is this supported in SQLite? + } } -- cgit v1.2.3-24-g4f1b From 9cd4e8e639a1a09fd6ca426f1af94586f30d4a80 Mon Sep 17 00:00:00 2001 From: admin Date: Mon, 25 Sep 2006 23:26:25 +0000 Subject: --- system/database/DB_driver.php | 140 ++++++++++++++ system/database/DB_utility.php | 214 +++++---------------- system/database/drivers/mssql/mssql_driver.php | 45 +++++ system/database/drivers/mssql/mssql_utility.php | 62 +----- system/database/drivers/mysql/mysql_driver.php | 47 ++++- system/database/drivers/mysql/mysql_utility.php | 59 +----- system/database/drivers/mysqli/mysqli_driver.php | 47 ++++- system/database/drivers/mysqli/mysqli_utility.php | 59 +----- system/database/drivers/oci8/oci8_driver.php | 51 ++++- system/database/drivers/oci8/oci8_utility.php | 72 ++----- system/database/drivers/odbc/odbc_driver.php | 47 ++++- system/database/drivers/odbc/odbc_utility.php | 69 ++----- system/database/drivers/postgre/postgre_driver.php | 47 ++++- .../database/drivers/postgre/postgre_utility.php | 59 +----- system/database/drivers/sqlite/sqlite_driver.php | 46 +++++ system/database/drivers/sqlite/sqlite_utility.php | 68 ++----- system/libraries/Controller.php | 2 +- system/libraries/Loader.php | 4 +- 18 files changed, 575 insertions(+), 563 deletions(-) (limited to 'system') diff --git a/system/database/DB_driver.php b/system/database/DB_driver.php index 3f7c82627..d25135ea6 100644 --- a/system/database/DB_driver.php +++ b/system/database/DB_driver.php @@ -142,6 +142,49 @@ class CI_DB_driver { } + // -------------------------------------------------------------------- + + /** + * 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; + } + + if ($this->dbdriver == 'oci8') + { + return $sql; + } + + $query = $this->query($sql); + $row = $query->row(); + return $row->ver; + } + // -------------------------------------------------------------------- /** @@ -483,6 +526,103 @@ class CI_DB_driver { return $str; } + + + // -------------------------------------------------------------------- + + /** + * 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->field_names($table); + + if ( ! is_array($fields)) + { + return FALSE; + } + + return current($fields); + } + + // -------------------------------------------------------------------- + + /** + * Fetch MySQL Field Names + * + * @access public + * @param string the table name + * @return array + */ + function 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($this->dbprefix.$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); + } + } + + return $retval; + } + + // -------------------------------------------------------------------- + + /** + * 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->dbprefix.$table)); + return $query->field_data(); + } + // -------------------------------------------------------------------- /** diff --git a/system/database/DB_utility.php b/system/database/DB_utility.php index 950db7dfd..f98448adf 100644 --- a/system/database/DB_utility.php +++ b/system/database/DB_utility.php @@ -33,57 +33,69 @@ class CI_DB_utility { $this->db =& $obj->db; } + // -------------------------------------------------------------------- /** - * Database Version Number. Returns a string containing the - * version of the database being used + * Create database * * @access public - * @return string - */ - function version() + * @param string the database name + * @return bool + */ + function create_database($db_name) { - if (FALSE === ($sql = $this->_version())) + $sql = $this->_create_database($db_name); + + if (is_bool($sql)) { - if ($this->db->db_debug) - { - return $this->db->display_error('db_unsupported_function'); - } - return FALSE; + 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 ($this->db->dbdriver == 'oci8') - { + if (is_bool($sql)) + { return $sql; } - $query = $this->db->query($sql); - $row = $query->row(); - return $row->ver; + return $this->db->query($sql); } // -------------------------------------------------------------------- /** - * Primary + * List databases * - * 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 = '') + * @return bool + */ + function list_databases() { - $fields = $this->field_names($table); - - if ( ! is_array($fields)) + $query = $this->db->query($this->_list_database()); + $dbs = array(); + if ($query->num_rows() > 0) { - return FALSE; + foreach ($query->result_array() as $row) + { + $dbs[] = current($row); + } } - - return current($fields); + + return $dbs; } // -------------------------------------------------------------------- @@ -94,9 +106,9 @@ class CI_DB_utility { * @access public * @return array */ - function tables() + function list_tables() { - if (FALSE === ($sql = $this->_show_tables())) + if (FALSE === ($sql = $this->_list_tables())) { if ($this->db->db_debug) { @@ -135,143 +147,7 @@ class CI_DB_utility { */ function table_exists($table_name) { - return ( ! in_array($this->db->dbprefix.$table_name, $this->tables())) ? FALSE : TRUE; - } - - // -------------------------------------------------------------------- - - /** - * Fetch MySQL Field Names - * - * @access public - * @param string the table name - * @return array - */ - function field_names($table = '') - { - if ($table == '') - { - if ($this->db->db_debug) - { - return $this->db->display_error('db_field_param_missing'); - } - return FALSE; - } - - if (FALSE === ($sql = $this->_show_columns($this->db->dbprefix.$table))) - { - if ($this->db->db_debug) - { - return $this->db->display_error('db_unsupported_function'); - } - return FALSE; - } - - $query = $this->db->query($sql); - - $retval = array(); - foreach($query->result_array() as $row) - { - if (isset($row['COLUMN_NAME'])) - { - $retval[] = $row['COLUMN_NAME']; - } - else - { - $retval[] = current($row); - } - } - - return $retval; - } - - // -------------------------------------------------------------------- - - /** - * Returns an object with field data - * - * @access public - * @param string the table name - * @return object - */ - function field_data($table = '') - { - if ($table == '') - { - if ($this->db->db_debug) - { - return $this->db->display_error('db_field_param_missing'); - } - return FALSE; - } - - $query = $this->db->query($this->_field_data($this->db->dbprefix.$table)); - return $query->field_data(); - } - - // -------------------------------------------------------------------- - - /** - * 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); - } - - // -------------------------------------------------------------------- - - /** - * List databases - * - * @access public - * @return bool - */ - function list_databases() - { - $query = $this->db->query($this->_list_database()); - $dbs = array(); - if ($query->num_rows() > 0) - { - foreach ($query->result_array() as $row) - { - $dbs[] = current($row); - } - } - - return $dbs; + return ( ! in_array($this->db->dbprefix.$table_name, $this->list_tables())) ? FALSE : TRUE; } // -------------------------------------------------------------------- diff --git a/system/database/drivers/mssql/mssql_driver.php b/system/database/drivers/mssql/mssql_driver.php index 38fce1134..3f5e53345 100644 --- a/system/database/drivers/mssql/mssql_driver.php +++ b/system/database/drivers/mssql/mssql_driver.php @@ -66,6 +66,19 @@ class CI_DB_mssql_driver extends CI_DB { { return @mssql_select_db($this->database, $this->conn_id); } + + // -------------------------------------------------------------------- + + /** + * Version number query string + * + * @access public + * @return string + */ + function _version() + { + return "SELECT version() AS ver"; + } // -------------------------------------------------------------------- @@ -248,6 +261,38 @@ class CI_DB_mssql_driver extends CI_DB { // -------------------------------------------------------------------- + /** + * List columnn 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 * diff --git a/system/database/drivers/mssql/mssql_utility.php b/system/database/drivers/mssql/mssql_utility.php index cf15104c6..96b8180b8 100644 --- a/system/database/drivers/mssql/mssql_utility.php +++ b/system/database/drivers/mssql/mssql_utility.php @@ -67,76 +67,30 @@ class CI_DB_mssql_utility extends CI_DB_utility { // -------------------------------------------------------------------- /** - * Drop Table - * - * @access private - * @return bool - */ - function _drop_table($table) - { - return "DROP TABLE ".$this->db->_escape_table($name); - } - - // -------------------------------------------------------------------- - - /** - * Version number query string - * - * @access public - * @return string - */ - function _version() - { - return "SELECT version() AS ver"; - } - - // -------------------------------------------------------------------- - - /** - * Show table query + * List table query * * Generates a platform-specific query string so that the table names can be fetched * - * @access public + * @access private * @return string */ - function _show_tables() + function _list_tables() { return "SELECT name FROM sysobjects WHERE type = 'U' ORDER BY name"; } - - // -------------------------------------------------------------------- - - /** - * Show columnn 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 _show_columns($table = '') - { - return "SELECT * FROM INFORMATION_SCHEMA.Columns WHERE TABLE_NAME = '".$this->db->_escape_table($table)."'"; - } // -------------------------------------------------------------------- /** - * Field data query - * - * Generates a platform-specific query so that the column data can be retrieved + * Drop Table * - * @access public - * @param string the table name - * @return object + * @access private + * @return bool */ - function _field_data($table) + function _drop_table($table) { - return "SELECT TOP 1 FROM ".$this->db->_escape_table($table); + return "DROP TABLE ".$this->db->_escape_table($name); } - // -------------------------------------------------------------------- diff --git a/system/database/drivers/mysql/mysql_driver.php b/system/database/drivers/mysql/mysql_driver.php index 545ac1986..b6c4eb7ea 100644 --- a/system/database/drivers/mysql/mysql_driver.php +++ b/system/database/drivers/mysql/mysql_driver.php @@ -73,7 +73,20 @@ class CI_DB_mysql_driver extends CI_DB { { return @mysql_select_db($this->database, $this->conn_id); } - + + // -------------------------------------------------------------------- + + /** + * Version number query string + * + * @access public + * @return string + */ + function _version() + { + return "SELECT version() AS ver"; + } + // -------------------------------------------------------------------- /** @@ -266,6 +279,38 @@ class CI_DB_mysql_driver extends CI_DB { // -------------------------------------------------------------------- + /** + * Show columnn 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->_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 * FROM ".$this->_escape_table($table)." LIMIT 1"; + } + + // -------------------------------------------------------------------- + /** * The error message string * diff --git a/system/database/drivers/mysql/mysql_utility.php b/system/database/drivers/mysql/mysql_utility.php index 800a90c7a..9ba4a79c5 100644 --- a/system/database/drivers/mysql/mysql_utility.php +++ b/system/database/drivers/mysql/mysql_utility.php @@ -65,75 +65,30 @@ class CI_DB_mysql_utility extends CI_DB_utility { // -------------------------------------------------------------------- - /** - * Drop Table - * - * @access private - * @return bool - */ - function _drop_table($table) - { - return "DROP TABLE IF EXISTS ".$this->db->_escape_table($name); - } - - // -------------------------------------------------------------------- - - /** - * Version number query string - * - * @access public - * @return string - */ - function _version() - { - return "SELECT version() AS ver"; - } - - // -------------------------------------------------------------------- - /** * Show table query * * Generates a platform-specific query string so that the table names can be fetched * - * @access public + * @access private * @return string */ - function _show_tables() + function _list_tables() { return "SHOW TABLES FROM `".$this->db->database."`"; } - - // -------------------------------------------------------------------- - - /** - * Show columnn 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 _show_columns($table = '') - { - return "SHOW COLUMNS FROM ".$this->db->_escape_table($table); - } // -------------------------------------------------------------------- /** - * Field data query - * - * Generates a platform-specific query so that the column data can be retrieved + * Drop Table * - * @access public - * @param string the table name - * @return object + * @access private + * @return bool */ - function _field_data($table) + function _drop_table($table) { - return "SELECT * FROM ".$this->db->_escape_table($table)." LIMIT 1"; + return "DROP TABLE IF EXISTS ".$this->db->_escape_table($name); } // -------------------------------------------------------------------- diff --git a/system/database/drivers/mysqli/mysqli_driver.php b/system/database/drivers/mysqli/mysqli_driver.php index adc482dfe..d6e967498 100644 --- a/system/database/drivers/mysqli/mysqli_driver.php +++ b/system/database/drivers/mysqli/mysqli_driver.php @@ -75,7 +75,20 @@ class CI_DB_mysqli_driver extends CI_DB { { return @mysqli_select_db($this->conn_id, $this->database); } - + + // -------------------------------------------------------------------- + + /** + * Version number query string + * + * @access public + * @return string + */ + function _version() + { + return "SELECT version() AS ver"; + } + // -------------------------------------------------------------------- /** @@ -269,6 +282,38 @@ class CI_DB_mysqli_driver extends CI_DB { // -------------------------------------------------------------------- + /** + * Show columnn 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->_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 * FROM ".$this->_escape_table($table)." LIMIT 1"; + } + + // -------------------------------------------------------------------- + /** * The error message string * diff --git a/system/database/drivers/mysqli/mysqli_utility.php b/system/database/drivers/mysqli/mysqli_utility.php index 8c9e1e960..754ffbda2 100644 --- a/system/database/drivers/mysqli/mysqli_utility.php +++ b/system/database/drivers/mysqli/mysqli_utility.php @@ -62,33 +62,7 @@ class CI_DB_mysqli_utility extends CI_DB_utility { { return "SHOW DATABASES"; } - - // -------------------------------------------------------------------- - /** - * Drop Table - * - * @access private - * @return bool - */ - function _drop_table($table) - { - return "DROP TABLE IF EXISTS ".$this->db->_escape_table($name); - } - - // -------------------------------------------------------------------- - - /** - * Version number query string - * - * @access public - * @return string - */ - function _version() - { - return "SELECT version() AS ver"; - } - // -------------------------------------------------------------------- /** @@ -96,44 +70,25 @@ class CI_DB_mysqli_utility extends CI_DB_utility { * * Generates a platform-specific query string so that the table names can be fetched * - * @access public + * @access private * @return string */ - function _show_tables() + function _list_tables() { return "SHOW TABLES FROM `".$this->db->database."`"; } - - // -------------------------------------------------------------------- - - /** - * Show columnn 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 _show_columns($table = '') - { - return "SHOW COLUMNS FROM ".$this->db->_escape_table($table); - } // -------------------------------------------------------------------- /** - * Field data query - * - * Generates a platform-specific query so that the column data can be retrieved + * Drop Table * - * @access public - * @param string the table name - * @return object + * @access private + * @return bool */ - function _field_data($table) + function _drop_table($table) { - return "SELECT * FROM ".$this->db->_escape_table($table)." LIMIT 1"; + return "DROP TABLE IF EXISTS ".$this->db->_escape_table($name); } // -------------------------------------------------------------------- diff --git a/system/database/drivers/oci8/oci8_driver.php b/system/database/drivers/oci8/oci8_driver.php index f7f4bd143..bc0a100c2 100644 --- a/system/database/drivers/oci8/oci8_driver.php +++ b/system/database/drivers/oci8/oci8_driver.php @@ -91,6 +91,19 @@ class CI_DB_oci8_driver extends CI_DB { return TRUE; } + // -------------------------------------------------------------------- + + /** + * Version number query string + * + * @access public + * @return string + */ + function _version() + { + return ociserverversion($this->conn_id); + } + // -------------------------------------------------------------------- /** @@ -102,10 +115,8 @@ class CI_DB_oci8_driver extends CI_DB { */ function _execute($sql) { - // oracle must parse the query before it - // is run, all of the actions with - // the query are based off the statement id - // returned by ociparse + // 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->_set_stmt_id($sql); ocisetprefetch($this->stmt_id, 1000); return @ociexecute($this->stmt_id, $this->_commit); @@ -390,6 +401,38 @@ class CI_DB_oci8_driver extends CI_DB { // -------------------------------------------------------------------- + /** + * Show columnn 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 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 + */ + function _field_data($table) + { + return "SELECT * FROM ".$this->_escape_table($table)." where rownum = 1"; + } + + // -------------------------------------------------------------------- + /** * The error message string * diff --git a/system/database/drivers/oci8/oci8_utility.php b/system/database/drivers/oci8/oci8_utility.php index 011e971d9..dc259ac39 100644 --- a/system/database/drivers/oci8/oci8_utility.php +++ b/system/database/drivers/oci8/oci8_utility.php @@ -64,32 +64,6 @@ class CI_DB_oci8_utility extends CI_DB_utility { return FALSE; } - // -------------------------------------------------------------------- - - /** - * Drop Table - * - * @access private - * @return bool - */ - function _drop_table($table) - { - return FALSE; - } - - // -------------------------------------------------------------------- - - /** - * Version number query string - * - * @access public - * @return string - */ - function _version() - { - return ociserverversion($this->conn_id); - } - // -------------------------------------------------------------------- /** @@ -97,46 +71,26 @@ class CI_DB_oci8_utility extends CI_DB_utility { * * Generates a platform-specific query string so that the table names can be fetched * - * @access public + * @access private * @return string */ - function _show_tables() + function _list_tables() { return "select TABLE_NAME FROM ALL_TABLES"; } - // -------------------------------------------------------------------- - - /** - * Show columnn 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 _show_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 - */ - function _field_data($table) - { - return "SELECT * FROM ".$this->db->_escape_table($table)." where rownum = 1"; - } + // -------------------------------------------------------------------- + /** + * Drop Table + * + * @access private + * @return bool + */ + function _drop_table($table) + { + return FALSE; + } // -------------------------------------------------------------------- diff --git a/system/database/drivers/odbc/odbc_driver.php b/system/database/drivers/odbc/odbc_driver.php index bef6258de..cdde2e2ea 100644 --- a/system/database/drivers/odbc/odbc_driver.php +++ b/system/database/drivers/odbc/odbc_driver.php @@ -67,7 +67,20 @@ class CI_DB_odbc_driver extends CI_DB { // Not needed for ODBC return TRUE; } - + + // -------------------------------------------------------------------- + + /** + * Version number query string + * + * @access public + * @return string + */ + function _version() + { + return "SELECT version() AS ver"; + } + // -------------------------------------------------------------------- /** @@ -249,6 +262,38 @@ class CI_DB_odbc_driver extends CI_DB { // -------------------------------------------------------------------- + /** + * Show columnn 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->_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 * diff --git a/system/database/drivers/odbc/odbc_utility.php b/system/database/drivers/odbc/odbc_utility.php index 2932da874..3d420f69d 100644 --- a/system/database/drivers/odbc/odbc_utility.php +++ b/system/database/drivers/odbc/odbc_utility.php @@ -83,80 +83,35 @@ class CI_DB_odbc_utility extends CI_DB_utility { // -------------------------------------------------------------------- - /** - * Drop Table - * - * @access private - * @return bool - */ - function _drop_table($table) - { - // Not a supported ODBC feature - if ($this->db_debug) - { - return $this->display_error('db_unsuported_feature'); - } - return FALSE; - } - - // -------------------------------------------------------------------- - - /** - * Version number query string - * - * @access public - * @return string - */ - function _version() - { - return "SELECT version() AS ver"; - } - - // -------------------------------------------------------------------- - /** * Show table query * * Generates a platform-specific query string so that the table names can be fetched * - * @access public + * @access private * @return string */ - function _show_tables() + function _list_tables() { return "SHOW TABLES FROM `".$this->db->database."`"; } - - // -------------------------------------------------------------------- - - /** - * Show columnn 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 _show_columns($table = '') - { - return "SHOW COLUMNS FROM ".$this->db->_escape_table($table); - } // -------------------------------------------------------------------- /** - * Field data query - * - * Generates a platform-specific query so that the column data can be retrieved + * Drop Table * - * @access public - * @param string the table name - * @return object + * @access private + * @return bool */ - function _field_data($table) + function _drop_table($table) { - return "SELECT TOP 1 FROM ".$this->db->_escape_table($table); + // Not a supported ODBC feature + if ($this->db_debug) + { + return $this->display_error('db_unsuported_feature'); + } + return FALSE; } // -------------------------------------------------------------------- diff --git a/system/database/drivers/postgre/postgre_driver.php b/system/database/drivers/postgre/postgre_driver.php index 9c8a18eb5..026284118 100644 --- a/system/database/drivers/postgre/postgre_driver.php +++ b/system/database/drivers/postgre/postgre_driver.php @@ -71,7 +71,20 @@ class CI_DB_postgre_driver extends CI_DB { // Not needed for Postgre so we'll return TRUE return TRUE; } - + + // -------------------------------------------------------------------- + + /** + * Version number query string + * + * @access public + * @return string + */ + function _version() + { + return "SELECT version() AS ver"; + } + // -------------------------------------------------------------------- /** @@ -276,6 +289,38 @@ class CI_DB_postgre_driver extends CI_DB { // -------------------------------------------------------------------- + /** + * Show columnn 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 ='".$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 * FROM ".$this->_escape_table($table)." LIMIT 1"; + } + + // -------------------------------------------------------------------- + /** * The error message string * diff --git a/system/database/drivers/postgre/postgre_utility.php b/system/database/drivers/postgre/postgre_utility.php index b2fdd5fd4..0ee448f9e 100644 --- a/system/database/drivers/postgre/postgre_utility.php +++ b/system/database/drivers/postgre/postgre_utility.php @@ -63,32 +63,6 @@ class CI_DB_postgre_utility extends CI_DB_utility { { return "SELECT datname FROM pg_database"; } - - // -------------------------------------------------------------------- - - /** - * Drop Table - * - * @access private - * @return bool - */ - function _drop_table($table) - { - return "DROP TABLE ".$this->db->_escape_table($name)." CASCADE"; - } - - // -------------------------------------------------------------------- - - /** - * Version number query string - * - * @access public - * @return string - */ - function _version() - { - return "SELECT version() AS ver"; - } // -------------------------------------------------------------------- @@ -97,44 +71,25 @@ class CI_DB_postgre_utility extends CI_DB_utility { * * Generates a platform-specific query string so that the table names can be fetched * - * @access public + * @access private * @return string */ - function _show_tables() + function _list_tables() { return "SELECT table_name FROM information_schema.tables WHERE table_schema = 'public'"; } - - // -------------------------------------------------------------------- - - /** - * Show columnn 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 _show_columns($table = '') - { - return "SELECT column_name FROM information_schema.columns WHERE table_name ='".$this->db->_escape_table($table)."'"; - } // -------------------------------------------------------------------- /** - * Field data query - * - * Generates a platform-specific query so that the column data can be retrieved + * Drop Table * - * @access public - * @param string the table name - * @return object + * @access private + * @return bool */ - function _field_data($table) + function _drop_table($table) { - return "SELECT * FROM ".$this->db->_escape_table($table)." LIMIT 1"; + return "DROP TABLE ".$this->db->_escape_table($name)." CASCADE"; } // -------------------------------------------------------------------- diff --git a/system/database/drivers/sqlite/sqlite_driver.php b/system/database/drivers/sqlite/sqlite_driver.php index 603984575..45dd7a892 100644 --- a/system/database/drivers/sqlite/sqlite_driver.php +++ b/system/database/drivers/sqlite/sqlite_driver.php @@ -88,6 +88,19 @@ class CI_DB_sqlite_driver extends CI_DB { { return TRUE; } + + // -------------------------------------------------------------------- + + /** + * Version number query string + * + * @access public + * @return string + */ + function _version() + { + return sqlite_libversion(); + } // -------------------------------------------------------------------- @@ -268,6 +281,39 @@ class CI_DB_sqlite_driver extends CI_DB { // -------------------------------------------------------------------- + /** + * Show columnn 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 ".$this->_escape_table($table)." LIMIT 1"; + } + + // -------------------------------------------------------------------- + /** * The error message string * diff --git a/system/database/drivers/sqlite/sqlite_utility.php b/system/database/drivers/sqlite/sqlite_utility.php index e9f4eb64e..43c43e03c 100644 --- a/system/database/drivers/sqlite/sqlite_utility.php +++ b/system/database/drivers/sqlite/sqlite_utility.php @@ -79,80 +79,34 @@ class CI_DB_sqlite_utility extends CI_DB_utility { // -------------------------------------------------------------------- - /** - * Drop Table - * - * @access private - * @return bool - */ - function _drop_table($table) - { - if ($this->db_debug) - { - return $this->display_error('db_unsuported_feature'); - } - return array(); - } - - // -------------------------------------------------------------------- - - /** - * Version number query string - * - * @access public - * @return string - */ - function _version() - { - return sqlite_libversion(); - } - - // -------------------------------------------------------------------- - /** * Show table query * * Generates a platform-specific query string so that the table names can be fetched * - * @access public + * @access private * @return string */ - function _show_tables() + function _list_tables() { return "SELECT name from sqlite_master WHERE type='table'"; } - - // -------------------------------------------------------------------- - - /** - * Show columnn 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 _show_columns($table = '') - { - // Not supported - return FALSE; - } // -------------------------------------------------------------------- /** - * Field data query - * - * Generates a platform-specific query so that the column data can be retrieved + * Drop Table * - * @access public - * @param string the table name - * @return object + * @access private + * @return bool */ - function _field_data($table) + function _drop_table($table) { - return "SELECT * FROM ".$this->db->_escape_table($table)." LIMIT 1"; + if ($this->db_debug) + { + return $this->display_error('db_unsuported_feature'); + } + return array(); } // -------------------------------------------------------------------- diff --git a/system/libraries/Controller.php b/system/libraries/Controller.php index 5fdbd9f9f..da5f2e072 100644 --- a/system/libraries/Controller.php +++ b/system/libraries/Controller.php @@ -409,7 +409,7 @@ class Controller extends CI_Base { * @param bool whether to return the object * @return void */ - function _ci_init_dbutils($db = '', $return = FALSE) + function _ci_init_dbutil($db = '', $return = FALSE) { if ($this->_ci_is_loaded('dbutils') == TRUE AND $return == FALSE) { diff --git a/system/libraries/Loader.php b/system/libraries/Loader.php index b69d3f049..833e37640 100644 --- a/system/libraries/Loader.php +++ b/system/libraries/Loader.php @@ -136,7 +136,7 @@ class CI_Loader { * @param bool whether to return the DB object * @return object */ - function dbutils($db = '', $return = FALSE) + function dbutil($db = '', $return = FALSE) { $obj =& get_instance(); @@ -145,7 +145,7 @@ class CI_Loader { $return = FALSE; } - return $obj->_ci_init_dbutils($db, $return); + return $obj->_ci_init_dbutil($db, $return); } // END dbutils() -- cgit v1.2.3-24-g4f1b From 910d8620519d777ab45bdad5fb6dc9f05c6b2869 Mon Sep 17 00:00:00 2001 From: admin Date: Tue, 26 Sep 2006 02:09:05 +0000 Subject: --- system/database/DB_export.php | 38 +++++++++++++++++++++++++++++++++++--- system/database/DB_utility.php | 2 ++ 2 files changed, 37 insertions(+), 3 deletions(-) (limited to 'system') diff --git a/system/database/DB_export.php b/system/database/DB_export.php index 195510d9d..1e94c6c97 100644 --- a/system/database/DB_export.php +++ b/system/database/DB_export.php @@ -23,19 +23,51 @@ * @link http://www.codeigniter.com/user_guide/database/ */ class CI_DB_export { - + + + function CI_DB_export() + { + log_message('debug', "Database Export Class Initialized"); + } + /** - * Some function + * Generate CVS * * @access public * @return integer */ - function something() + function generate_cvs($query, $delim = "\t", $newline = "\n") { + if ( ! is_object($query) OR ! method_exists($query, 'field_names')) + { + show_error('You must submit a valid result object'); + } + + $out = ''; + foreach ($query->field_names() as $name) + { + $out .= $name.$delim; + } + + $out .= $newline; + + foreach ($query->result_array() as $row) + { + foreach ($row as $item) + { + $out .= $item.$delim; + } + + $out .= $newline; + } + + + return $out; } // -------------------------------------------------------------------- + } ?> \ No newline at end of file diff --git a/system/database/DB_utility.php b/system/database/DB_utility.php index f98448adf..41941ae35 100644 --- a/system/database/DB_utility.php +++ b/system/database/DB_utility.php @@ -31,6 +31,8 @@ class CI_DB_utility { // Assign the main database object to $this->db $obj =& get_instance(); $this->db =& $obj->db; + + log_message('debug', "Database Utility Class Initialized"); } // -------------------------------------------------------------------- -- cgit v1.2.3-24-g4f1b From 30c3b9709a12b7346c7057e656a491ffb9168f55 Mon Sep 17 00:00:00 2001 From: admin Date: Tue, 26 Sep 2006 02:09:47 +0000 Subject: --- system/libraries/Controller.php | 42 ----------------------------------------- 1 file changed, 42 deletions(-) (limited to 'system') diff --git a/system/libraries/Controller.php b/system/libraries/Controller.php index da5f2e072..afd963a7a 100644 --- a/system/libraries/Controller.php +++ b/system/libraries/Controller.php @@ -397,49 +397,7 @@ class Controller extends CI_Base { $obj->db =& $DB; } // END _ci_init_database() - - - // -------------------------------------------------------------------- - - /** - * Initialize Database Utilities Class - * - * @access private - * @param mixed database platform - * @param bool whether to return the object - * @return void - */ - function _ci_init_dbutil($db = '', $return = FALSE) - { - if ($this->_ci_is_loaded('dbutils') == TRUE AND $return == FALSE) - { - return; - } - - if ($this->_ci_is_loaded('db') == FALSE) - { - $this->_ci_init_database(); - } - - require_once(BASEPATH.'database/DB_utility'.EXT); - require_once(BASEPATH.'database/drivers/'.$this->db->dbdriver.'/'.$this->db->dbdriver.'_utility'.EXT); - - // Instantiate the DB adapter - $driver = 'CI_DB_'.$this->db->dbdriver.'_utility'; - $DB = new $driver(); - - if ($return === TRUE) - { - return $DB; - } - - $obj =& get_instance(); - $obj->ci_is_loaded[] = 'dbutils'; - $obj->dbutil =& $DB; - } - // END _ci_init_database() - // -------------------------------------------------------------------- /** -- cgit v1.2.3-24-g4f1b From e79dc7130a0003a07833609487b8ebb5ebcf31c8 Mon Sep 17 00:00:00 2001 From: admin Date: Tue, 26 Sep 2006 03:52:45 +0000 Subject: --- system/database/DB_export.php | 7 +++++++ system/database/DB_utility.php | 5 +++++ system/init/init_calendar.php | 1 - system/init/init_xmlrpcs.php | 6 ++++++ system/libraries/Calendar.php | 7 ++++++- system/libraries/Controller.php | 42 ++++++++++++++++++++--------------------- system/libraries/Email.php | 5 +++++ system/libraries/Encrypt.php | 5 +++++ system/libraries/Image_lib.php | 11 +++++++++++ system/libraries/Loader.php | 20 +++++++------------- system/libraries/Model.php | 9 +++++---- system/libraries/Pagination.php | 11 +++++++++++ system/libraries/Parser.php | 5 +++++ system/libraries/Session.php | 5 +++++ system/libraries/Trackback.php | 5 +++++ system/libraries/Unit_test.php | 5 +++++ system/libraries/Upload.php | 11 +++++++++++ system/libraries/Validation.php | 5 +++++ system/libraries/Xmlrpc.php | 13 +++++++++++++ system/libraries/Xmlrpcs.php | 33 +++++++++++++++++++++++++++++++- 20 files changed, 169 insertions(+), 42 deletions(-) (limited to 'system') diff --git a/system/database/DB_export.php b/system/database/DB_export.php index 1e94c6c97..8194cb9b1 100644 --- a/system/database/DB_export.php +++ b/system/database/DB_export.php @@ -13,6 +13,13 @@ * @filesource */ + + +// INITIALIZE THE CLASS --------------------------------------------------- + +$obj =& get_instance(); +$obj->dbexport =& new CI_DB_export(); + // ------------------------------------------------------------------------ /** diff --git a/system/database/DB_utility.php b/system/database/DB_utility.php index 41941ae35..e4ae0c5df 100644 --- a/system/database/DB_utility.php +++ b/system/database/DB_utility.php @@ -13,6 +13,11 @@ * @filesource */ +// INITIALIZE THE CLASS --------------------------------------------------- + +$obj =& get_instance(); +$obj->dbutility =& new CI_DB_utility(); + // ------------------------------------------------------------------------ /** diff --git a/system/init/init_calendar.php b/system/init/init_calendar.php index 5cf663725..390b44007 100644 --- a/system/init/init_calendar.php +++ b/system/init/init_calendar.php @@ -12,7 +12,6 @@ if ( ! class_exists('CI_Calendar')) } $obj =& get_instance(); - $obj->calendar = new CI_Calendar(); $obj->ci_is_loaded[] = 'calendar'; diff --git a/system/init/init_xmlrpcs.php b/system/init/init_xmlrpcs.php index 7566e3826..a900894aa 100644 --- a/system/init/init_xmlrpcs.php +++ b/system/init/init_xmlrpcs.php @@ -18,10 +18,16 @@ if ( ! class_exists('CI_XML_RPC_Server')) require_once(BASEPATH.'libraries/Xmlrpcs'.EXT); } + + +// INITIALIZE THE CLASS --------------------------------------------------- + $obj =& get_instance(); $obj->xmlrpc = new CI_XML_RPC(); $obj->xmlrpcs = new CI_XML_RPC_Server($config); $obj->ci_is_loaded[] = 'xmlrpc'; $obj->ci_is_loaded[] = 'xmlrpcs'; +// ------------------------------------------------------------------------ + ?> \ No newline at end of file diff --git a/system/libraries/Calendar.php b/system/libraries/Calendar.php index b77dd1b6f..a3c070390 100644 --- a/system/libraries/Calendar.php +++ b/system/libraries/Calendar.php @@ -13,6 +13,11 @@ * @filesource */ +// INITIALIZE THE CLASS --------------------------------------------------- + +$obj =& get_instance(); +$obj->calendar =& new CI_Calendar(); + // ------------------------------------------------------------------------ /** @@ -25,7 +30,7 @@ * @category Libraries * @author Rick Ellis * @link http://www.codeigniter.com/user_guide/libraries/calendar.html - */ + */ class CI_Calendar { var $lang; diff --git a/system/libraries/Controller.php b/system/libraries/Controller.php index afd963a7a..97aa4b789 100644 --- a/system/libraries/Controller.php +++ b/system/libraries/Controller.php @@ -29,7 +29,6 @@ */ class Controller extends CI_Base { - var $ci_is_loaded = array(); var $_ci_models = array(); var $_ci_scaffolding = FALSE; var $_ci_scaff_table = FALSE; @@ -54,15 +53,18 @@ class Controller extends CI_Base { // This allows anything loaded using $this->load (viwes, files, etc.) // to become accessible from within the Controller class functions. - foreach ($this->ci_is_loaded as $val) + foreach (get_object_vars($this) as $key => $var) { - $this->load->$val =& $this->$val; + if (is_object($var)) + { + $this->load->$key =& $this->$key; + } } - + log_message('debug', "Controller Class Initialized"); } // END Controller() - + // -------------------------------------------------------------------- /** @@ -75,27 +77,28 @@ class Controller extends CI_Base { * @param mixed any additional parameters * @return void */ - function _ci_initialize($what, $params = FALSE) + function _ci_initialize($class, $params = FALSE) { - $method = '_ci_init_'.strtolower(str_replace(EXT, '', $what)); + $class = strtolower(str_replace(EXT, '', $class)); + $method = '_ci_init_'.$class; if ( ! method_exists($this, $method)) - { - $method = substr($method, 4); + { + $class = ucfirst($class); - if ( ! file_exists(APPPATH.'init/'.$method.EXT)) + if ( ! file_exists(APPPATH.'libraries/'.$class.EXT)) { - if ( ! file_exists(BASEPATH.'init/'.$method.EXT)) + if ( ! file_exists(BASEPATH.'libraries/'.$class.EXT)) { - log_message('error', "Unable to load the requested class: ".$what); - show_error("Unable to load the class: ".$what); + log_message('error', "Unable to load the requested class: ".$class); + show_error("Unable to load the class: ".$class); } - include(BASEPATH.'init/'.$method.EXT); + include_once(BASEPATH.'libraries/'.$class.EXT); } else { - include(APPPATH.'init/'.$method.EXT); + include_once(APPPATH.'libraries/'.$class.EXT); } } else @@ -268,11 +271,9 @@ class Controller extends CI_Base { { $class = strtolower($val); $this->$class =& _load_class('CI_'.$val); - $this->ci_is_loaded[] = $class; } $this->lang =& _load_class('CI_Language'); - $this->ci_is_loaded[] = 'lang'; // In PHP 4 the Controller class is a child of CI_Loader. // In PHP 5 we run it as its own class. @@ -280,8 +281,6 @@ class Controller extends CI_Base { { $this->load = new CI_Loader(); } - - $this->ci_is_loaded[] = 'load'; } // END _ci_assign_core() @@ -393,7 +392,6 @@ class Controller extends CI_Base { } $obj =& get_instance(); - $obj->ci_is_loaded[] = 'db'; $obj->db =& $DB; } // END _ci_init_database() @@ -409,10 +407,10 @@ class Controller extends CI_Base { */ function _ci_is_loaded($class) { - return ( ! in_array($class, $this->ci_is_loaded)) ? FALSE : TRUE; + return ( ! isset($this->$class) OR ! is_object($this->$class)) ? FALSE : TRUE; } // END _ci_is_loaded() - + // -------------------------------------------------------------------- /** diff --git a/system/libraries/Email.php b/system/libraries/Email.php index 5b991d1fa..c153043d9 100644 --- a/system/libraries/Email.php +++ b/system/libraries/Email.php @@ -13,6 +13,11 @@ * @filesource */ +// INITIALIZE THE CLASS --------------------------------------------------- + +$obj =& get_instance(); +$obj->email =& new CI_Email(); + // ------------------------------------------------------------------------ /** diff --git a/system/libraries/Encrypt.php b/system/libraries/Encrypt.php index bcffdf1ab..446f64aa6 100644 --- a/system/libraries/Encrypt.php +++ b/system/libraries/Encrypt.php @@ -13,6 +13,11 @@ * @filesource */ +// INITIALIZE THE CLASS --------------------------------------------------- + +$obj =& get_instance(); +$obj->encrypt =& new CI_Encrypt(); + // ------------------------------------------------------------------------ /** diff --git a/system/libraries/Image_lib.php b/system/libraries/Image_lib.php index 18e3253f7..86ed05943 100644 --- a/system/libraries/Image_lib.php +++ b/system/libraries/Image_lib.php @@ -13,6 +13,17 @@ * @filesource */ +// INITIALIZE THE CLASS --------------------------------------------------- + +$config = array(); +if (file_exists(APPPATH.'config/image_lib'.EXT)) +{ + include_once(APPPATH.'config/image_lib'.EXT); +} + +$obj =& get_instance(); +$obj->image_lib =& new CI_Image_lib($config); + // ------------------------------------------------------------------------ /** diff --git a/system/libraries/Loader.php b/system/libraries/Loader.php index 833e37640..7449fa34a 100644 --- a/system/libraries/Loader.php +++ b/system/libraries/Loader.php @@ -136,15 +136,9 @@ class CI_Loader { * @param bool whether to return the DB object * @return object */ - function dbutil($db = '', $return = FALSE) + function dbutil() { $obj =& get_instance(); - - if ( ! is_bool($return)) - { - $return = FALSE; - } - return $obj->_ci_init_dbutil($db, $return); } // END dbutils() @@ -484,14 +478,14 @@ class CI_Loader { // This allows anything loaded using $this->load (viwes, files, etc.) // to become accessible from within the Controller and Model functions. $obj =& get_instance(); - foreach ($obj->ci_is_loaded as $val) + foreach (get_object_vars($obj) as $key => $var) { - if ( ! isset($this->$val)) + if (is_object($var)) { - $this->$val =& $obj->$val; - } - } - + $this->$key =& $obj->$key; + } + } + // Set the default data variables foreach (array('view', 'vars', 'path', 'return') as $val) { diff --git a/system/libraries/Model.php b/system/libraries/Model.php index 9834f8278..55c995636 100644 --- a/system/libraries/Model.php +++ b/system/libraries/Model.php @@ -50,20 +50,21 @@ class Model { function _assign_libraries($use_reference = TRUE) { $obj =& get_instance(); - foreach ($obj->ci_is_loaded as $val) + foreach (get_object_vars($obj) as $key => $var) { - if ( ! isset($this->$val)) + if (is_object($var) AND ! isset($this->$key)) { if ($use_reference === TRUE) { - $this->$val =& $obj->$val; + $this->$key =& $obj->$key; } else { - $this->$val = $obj->$val; + $this->$key = $obj->$key; } } } + } // END _assign_libraries() diff --git a/system/libraries/Pagination.php b/system/libraries/Pagination.php index 9d558f00a..d83a2bd0f 100644 --- a/system/libraries/Pagination.php +++ b/system/libraries/Pagination.php @@ -13,6 +13,17 @@ * @filesource */ +// INITIALIZE THE CLASS --------------------------------------------------- + +$config = array(); +if (file_exists(APPPATH.'config/pagination'.EXT)) +{ + include_once(APPPATH.'config/pagination'.EXT); +} + +$obj =& get_instance(); +$obj->pagination =& new CI_Pagination($config); + // ------------------------------------------------------------------------ /** diff --git a/system/libraries/Parser.php b/system/libraries/Parser.php index 63dc023a2..5bc2eb5a3 100644 --- a/system/libraries/Parser.php +++ b/system/libraries/Parser.php @@ -13,6 +13,11 @@ * @filesource */ +// INITIALIZE THE CLASS --------------------------------------------------- + +$obj =& get_instance(); +$obj->parser =& new CI_Parser(); + // ------------------------------------------------------------------------ /** diff --git a/system/libraries/Session.php b/system/libraries/Session.php index 94efee55c..bcd2e4d7e 100644 --- a/system/libraries/Session.php +++ b/system/libraries/Session.php @@ -13,6 +13,11 @@ * @filesource */ +// INITIALIZE THE CLASS --------------------------------------------------- + +$obj =& get_instance(); +$obj->session =& new CI_Session(); + // ------------------------------------------------------------------------ /** diff --git a/system/libraries/Trackback.php b/system/libraries/Trackback.php index 8f9680d44..9b6138453 100644 --- a/system/libraries/Trackback.php +++ b/system/libraries/Trackback.php @@ -13,6 +13,11 @@ * @filesource */ +// INITIALIZE THE CLASS --------------------------------------------------- + +$obj =& get_instance(); +$obj->trackback =& new CI_Trackback(); + // ------------------------------------------------------------------------ /** diff --git a/system/libraries/Unit_test.php b/system/libraries/Unit_test.php index b2f4bf8cd..19fac79a7 100644 --- a/system/libraries/Unit_test.php +++ b/system/libraries/Unit_test.php @@ -13,6 +13,11 @@ * @filesource */ +// INITIALIZE THE CLASS --------------------------------------------------- + +$obj =& get_instance(); +$obj->unit =& new CI_Unit_test(); + // ------------------------------------------------------------------------ /** diff --git a/system/libraries/Upload.php b/system/libraries/Upload.php index 98edd654f..26f216544 100644 --- a/system/libraries/Upload.php +++ b/system/libraries/Upload.php @@ -13,6 +13,17 @@ * @filesource */ +// INITIALIZE THE CLASS --------------------------------------------------- + +$config = array(); +if (file_exists(APPPATH.'config/upload'.EXT)) +{ + include_once(APPPATH.'config/upload'.EXT); +} + +$obj =& get_instance(); +$obj->upload = new CI_Upload($config); + // ------------------------------------------------------------------------ /** diff --git a/system/libraries/Validation.php b/system/libraries/Validation.php index b65b9be52..6c755a991 100644 --- a/system/libraries/Validation.php +++ b/system/libraries/Validation.php @@ -13,6 +13,11 @@ * @filesource */ +// INITIALIZE THE CLASS --------------------------------------------------- + +$obj =& get_instance(); +$obj->validation =& new CI_Validation(); + // ------------------------------------------------------------------------ /** diff --git a/system/libraries/Xmlrpc.php b/system/libraries/Xmlrpc.php index 9eeb46a15..b470f720a 100644 --- a/system/libraries/Xmlrpc.php +++ b/system/libraries/Xmlrpc.php @@ -18,6 +18,19 @@ if ( ! function_exists('xml_parser_create')) show_error('Your PHP installation does not support XML'); } +// INITIALIZE THE CLASS --------------------------------------------------- + +$config = array(); +if (file_exists(APPPATH.'config/xmlrpc'.EXT)) +{ + include_once(APPPATH.'config/xmlrpc'.EXT); +} + +$obj =& get_instance(); +$obj->xmlrpc = new CI_XML_RPC($config); + +// ------------------------------------------------------------------------ + /** * XML-RPC request handler class * diff --git a/system/libraries/Xmlrpcs.php b/system/libraries/Xmlrpcs.php index 0543c3b78..4d50dfb96 100644 --- a/system/libraries/Xmlrpcs.php +++ b/system/libraries/Xmlrpcs.php @@ -12,7 +12,38 @@ * @since Version 1.0 * @filesource */ - + + +// INITIALIZE THE CLASS --------------------------------------------------- + +$config = array(); +if (file_exists(APPPATH.'config/xmlrpcs'.EXT)) +{ + include_once(APPPATH.'config/xmlrpcs'.EXT); +} + +if ( ! class_exists('CI_XML_RPC')) +{ + if ( ! file_exists(BASEPATH.'libraries/Xmlrpc'.EXT)) + { + if ( ! file_exists(APPPATH.'libraries/Xmlrpc'.EXT)) + { + show_error('Unable to locate the Xmlrpc class'); + } + else + { + require_once(APPPATH.'libraries/Xmlrpc'.EXT); + } + } + else + { + require_once(BASEPATH.'libraries/Xmlrpc'.EXT); + } +} + +$obj =& get_instance(); +$obj->xmlrpcs = new CI_XML_RPC_Server($config); + // ------------------------------------------------------------------------ /** -- cgit v1.2.3-24-g4f1b From cd67756a4a30115822dabda422f3e0feee49e6cf Mon Sep 17 00:00:00 2001 From: admin Date: Tue, 26 Sep 2006 03:53:54 +0000 Subject: Deleting init folder --- system/init/index.html | 15 --------------- system/init/init_calendar.php | 18 ------------------ system/init/init_email.php | 24 ------------------------ system/init/init_encrypt.php | 18 ------------------ system/init/init_image_lib.php | 24 ------------------------ system/init/init_pagination.php | 24 ------------------------ system/init/init_parser.php | 19 ------------------- system/init/init_session.php | 18 ------------------ system/init/init_trackback.php | 18 ------------------ system/init/init_unit_test.php | 18 ------------------ system/init/init_upload.php | 24 ------------------------ system/init/init_validation.php | 18 ------------------ system/init/init_xmlrpc.php | 24 ------------------------ system/init/init_xmlrpcs.php | 33 --------------------------------- 14 files changed, 295 deletions(-) delete mode 100644 system/init/index.html delete mode 100644 system/init/init_calendar.php delete mode 100644 system/init/init_email.php delete mode 100644 system/init/init_encrypt.php delete mode 100644 system/init/init_image_lib.php delete mode 100644 system/init/init_pagination.php delete mode 100644 system/init/init_parser.php delete mode 100644 system/init/init_session.php delete mode 100644 system/init/init_trackback.php delete mode 100644 system/init/init_unit_test.php delete mode 100644 system/init/init_upload.php delete mode 100644 system/init/init_validation.php delete mode 100644 system/init/init_xmlrpc.php delete mode 100644 system/init/init_xmlrpcs.php (limited to 'system') diff --git a/system/init/index.html b/system/init/index.html deleted file mode 100644 index 5a1f5d6ae..000000000 --- a/system/init/index.html +++ /dev/null @@ -1,15 +0,0 @@ - - - - -403 Forbidden - - - - - -

Directory access is forbidden.

- - - - \ No newline at end of file diff --git a/system/init/init_calendar.php b/system/init/init_calendar.php deleted file mode 100644 index 390b44007..000000000 --- a/system/init/init_calendar.php +++ /dev/null @@ -1,18 +0,0 @@ -calendar = new CI_Calendar(); -$obj->ci_is_loaded[] = 'calendar'; - -?> \ No newline at end of file diff --git a/system/init/init_email.php b/system/init/init_email.php deleted file mode 100644 index 6782310ef..000000000 --- a/system/init/init_email.php +++ /dev/null @@ -1,24 +0,0 @@ -email = new CI_Email($config); -$obj->ci_is_loaded[] = 'email'; - -?> \ No newline at end of file diff --git a/system/init/init_encrypt.php b/system/init/init_encrypt.php deleted file mode 100644 index 5eae533ba..000000000 --- a/system/init/init_encrypt.php +++ /dev/null @@ -1,18 +0,0 @@ -encrypt = new CI_Encrypt(); -$obj->ci_is_loaded[] = 'encrypt'; - -?> \ No newline at end of file diff --git a/system/init/init_image_lib.php b/system/init/init_image_lib.php deleted file mode 100644 index dcd702f0d..000000000 --- a/system/init/init_image_lib.php +++ /dev/null @@ -1,24 +0,0 @@ -image_lib = new CI_Image_lib($config); -$obj->ci_is_loaded[] = 'image_lib'; - -?> \ No newline at end of file diff --git a/system/init/init_pagination.php b/system/init/init_pagination.php deleted file mode 100644 index 3a7d9361c..000000000 --- a/system/init/init_pagination.php +++ /dev/null @@ -1,24 +0,0 @@ -pagination = new CI_Pagination($config); -$obj->ci_is_loaded[] = 'pagination'; - -?> \ No newline at end of file diff --git a/system/init/init_parser.php b/system/init/init_parser.php deleted file mode 100644 index 17824b566..000000000 --- a/system/init/init_parser.php +++ /dev/null @@ -1,19 +0,0 @@ -parser = new CI_Parser(); -$obj->ci_is_loaded[] = 'parser'; - - -?> \ No newline at end of file diff --git a/system/init/init_session.php b/system/init/init_session.php deleted file mode 100644 index cf493e53c..000000000 --- a/system/init/init_session.php +++ /dev/null @@ -1,18 +0,0 @@ -session = new CI_Session(); -$obj->ci_is_loaded[] = 'session'; - -?> \ No newline at end of file diff --git a/system/init/init_trackback.php b/system/init/init_trackback.php deleted file mode 100644 index 6a3778bcc..000000000 --- a/system/init/init_trackback.php +++ /dev/null @@ -1,18 +0,0 @@ -trackback = new CI_Trackback(); -$obj->ci_is_loaded[] = 'trackback'; - -?> \ No newline at end of file diff --git a/system/init/init_unit_test.php b/system/init/init_unit_test.php deleted file mode 100644 index 61d5350b6..000000000 --- a/system/init/init_unit_test.php +++ /dev/null @@ -1,18 +0,0 @@ -unit = new CI_Unit_test(); -$obj->ci_is_loaded[] = 'unit'; - -?> \ No newline at end of file diff --git a/system/init/init_upload.php b/system/init/init_upload.php deleted file mode 100644 index 495975c7a..000000000 --- a/system/init/init_upload.php +++ /dev/null @@ -1,24 +0,0 @@ -upload = new CI_Upload($config); -$obj->ci_is_loaded[] = 'upload'; - -?> \ No newline at end of file diff --git a/system/init/init_validation.php b/system/init/init_validation.php deleted file mode 100644 index a320c3e5b..000000000 --- a/system/init/init_validation.php +++ /dev/null @@ -1,18 +0,0 @@ -validation = new CI_Validation(); -$obj->ci_is_loaded[] = 'validation'; - -?> \ No newline at end of file diff --git a/system/init/init_xmlrpc.php b/system/init/init_xmlrpc.php deleted file mode 100644 index b75e9aad7..000000000 --- a/system/init/init_xmlrpc.php +++ /dev/null @@ -1,24 +0,0 @@ -xmlrpc = new CI_XML_RPC($config); -$obj->ci_is_loaded[] = 'xmlrpc'; - -?> \ No newline at end of file diff --git a/system/init/init_xmlrpcs.php b/system/init/init_xmlrpcs.php deleted file mode 100644 index a900894aa..000000000 --- a/system/init/init_xmlrpcs.php +++ /dev/null @@ -1,33 +0,0 @@ -xmlrpc = new CI_XML_RPC(); -$obj->xmlrpcs = new CI_XML_RPC_Server($config); -$obj->ci_is_loaded[] = 'xmlrpc'; -$obj->ci_is_loaded[] = 'xmlrpcs'; - -// ------------------------------------------------------------------------ - -?> \ No newline at end of file -- cgit v1.2.3-24-g4f1b From 0e6c836a485133a776737a91da4408fcbe894fcc Mon Sep 17 00:00:00 2001 From: admin Date: Tue, 26 Sep 2006 03:55:30 +0000 Subject: Deleting init folder --- system/application/init/index.html | 15 --------------- 1 file changed, 15 deletions(-) delete mode 100644 system/application/init/index.html (limited to 'system') diff --git a/system/application/init/index.html b/system/application/init/index.html deleted file mode 100644 index 5a1f5d6ae..000000000 --- a/system/application/init/index.html +++ /dev/null @@ -1,15 +0,0 @@ - - - - -403 Forbidden - - - - - -

Directory access is forbidden.

- - - - \ No newline at end of file -- cgit v1.2.3-24-g4f1b From 7981a9a752c339611ae10a252469f9dbc266fb96 Mon Sep 17 00:00:00 2001 From: admin Date: Tue, 26 Sep 2006 07:52:09 +0000 Subject: --- system/database/DB_export.php | 2 +- system/database/DB_utility.php | 2 +- system/libraries/Calendar.php | 2 +- system/libraries/Controller.php | 137 +++++++++++++++++++++++++++------------- system/libraries/Email.php | 2 +- system/libraries/Encrypt.php | 2 +- system/libraries/Image_lib.php | 2 +- system/libraries/Loader.php | 23 +------ system/libraries/Pagination.php | 2 +- system/libraries/Parser.php | 2 +- system/libraries/Session.php | 2 +- system/libraries/Unit_test.php | 2 +- system/libraries/Upload.php | 2 +- system/libraries/Validation.php | 2 +- system/libraries/Xmlrpc.php | 26 +++----- system/libraries/Xmlrpcs.php | 57 ++++++++--------- 16 files changed, 144 insertions(+), 123 deletions(-) (limited to 'system') diff --git a/system/database/DB_export.php b/system/database/DB_export.php index 8194cb9b1..14e7af68b 100644 --- a/system/database/DB_export.php +++ b/system/database/DB_export.php @@ -18,7 +18,7 @@ // INITIALIZE THE CLASS --------------------------------------------------- $obj =& get_instance(); -$obj->dbexport =& new CI_DB_export(); +$obj->init_class('CI_DB_export', 'dbexport'); // ------------------------------------------------------------------------ diff --git a/system/database/DB_utility.php b/system/database/DB_utility.php index e4ae0c5df..3b4b09d6e 100644 --- a/system/database/DB_utility.php +++ b/system/database/DB_utility.php @@ -16,7 +16,7 @@ // INITIALIZE THE CLASS --------------------------------------------------- $obj =& get_instance(); -$obj->dbutility =& new CI_DB_utility(); +$obj->init_class('CI_DB_utility', 'dbutility'); // ------------------------------------------------------------------------ diff --git a/system/libraries/Calendar.php b/system/libraries/Calendar.php index a3c070390..bde98113a 100644 --- a/system/libraries/Calendar.php +++ b/system/libraries/Calendar.php @@ -16,7 +16,7 @@ // INITIALIZE THE CLASS --------------------------------------------------- $obj =& get_instance(); -$obj->calendar =& new CI_Calendar(); +$obj->init_class('CI_Calendar'); // ------------------------------------------------------------------------ diff --git a/system/libraries/Controller.php b/system/libraries/Controller.php index 97aa4b789..74b233ef3 100644 --- a/system/libraries/Controller.php +++ b/system/libraries/Controller.php @@ -32,6 +32,8 @@ class Controller extends CI_Base { var $_ci_models = array(); var $_ci_scaffolding = FALSE; var $_ci_scaff_table = FALSE; + var $_ci_last_handle = NULL; + var $_ci_last_params = NULL; /** * Constructor @@ -63,57 +65,117 @@ class Controller extends CI_Base { log_message('debug', "Controller Class Initialized"); } - // END Controller() // -------------------------------------------------------------------- /** * Initialization Handler * - * Looks for the existence of a handler method and calls it + * Designed to be called from the class files themselves. + * See: http://www.codeigniter.com/user_guide/general/creating_libraries.html + * + * @access public + * @param string class name + * @param string variable name + * @param mixed any additional parameters + * @return void + */ + function init_class($class, $varname = '', $params = NULL) + { + // First figure out what variable we're going to + // use to instantiate the class to + if ($varname == '') + { + $varname = ( ! is_null($this->_ci_last_handle)) ? $this->_ci_last_handle : strtolower(str_replace('CI_', '', $class)); + } + + // Are there any parameters? + if ($params === NULL AND $this->_ci_last_params !== NULL) + { + $params = $this->_ci_last_params; + } + + // Instantiate the class + if ( ! is_null($params)) + { + $this->$varname = new $class($params); + } + else + { + $this->$varname = new $class; + } + + $this->_ci_last_params = NULL; + $this->_ci_last_handle = NULL; + } + + // -------------------------------------------------------------------- + + /** + * Initialization Handler + * + * This function loads the requested class. * * @access private * @param string the item that is being loaded * @param mixed any additional parameters * @return void */ - function _ci_initialize($class, $params = FALSE) - { + function _ci_init_class($class, $params = NULL) + { + // Prep the class name $class = strtolower(str_replace(EXT, '', $class)); + + // These are used by $this->init_class() above. + // They lets us dynamically set the object name and pass parameters + $this->_ci_last_handle = $class; + $this->_ci_last_params = $params; + + // Does THIS file (Controller.php) contain an initialization + // function that maps to the requested class? + $method = '_ci_init_'.$class; - - if ( ! method_exists($this, $method)) - { - $class = ucfirst($class); - if ( ! file_exists(APPPATH.'libraries/'.$class.EXT)) + if (method_exists($this, $method)) + { + if (is_null($params)) { - if ( ! file_exists(BASEPATH.'libraries/'.$class.EXT)) - { - log_message('error', "Unable to load the requested class: ".$class); - show_error("Unable to load the class: ".$class); - } - - include_once(BASEPATH.'libraries/'.$class.EXT); + $this->$method(); } else { - include_once(APPPATH.'libraries/'.$class.EXT); - } + $this->$method($params); + } + + // We're done... + return TRUE; } - else + + // Lets search for the requested library file and load it. + // We'll assume that the file we load contains a call to + // $obj->init_class() so that the class can get instantiated. + // For backward compatibility we'll test for filenames that are + // both uppercase and lower. + + foreach (array(ucfirst($class), $class) as $filename) { - if ($params === FALSE) + for ($i = 1; $i < 3; $i++) { - $this->$method(); - } - else - { - $this->$method($params); + $path = ($i % 2) ? APPPATH : BASEPATH; + + if (file_exists($path.'libraries/'.$filename.EXT)) + { + include_once($path.'libraries/'.$filename.EXT); + return TRUE; + } } + } + + // 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 class: ".$class); } - // END _ci_initialize() // -------------------------------------------------------------------- @@ -124,7 +186,7 @@ class Controller extends CI_Base { * @param string * @return array */ - function _ci_load_model($model, $name = '', $db_conn = FALSE) + function _ci_init_model($model, $name = '', $db_conn = FALSE) { if ($name == '') { @@ -168,9 +230,7 @@ class Controller extends CI_Base { $this->$name = new $model(); $this->_ci_models[] = $name; $this->_ci_assign_to_models(); - } - // END _ci_load_model() - + } // -------------------------------------------------------------------- @@ -195,9 +255,7 @@ class Controller extends CI_Base { { $obj->$model->_assign_libraries(); } - } - // END _ci_assign_to_models() - + } // -------------------------------------------------------------------- @@ -245,13 +303,12 @@ class Controller extends CI_Base { foreach ($autoload['libraries'] as $item) { - $this->_ci_initialize($item); + $this->_ci_init_class($item); } unset($autoload['libraries']); return $autoload; } - // END _ci_autoload() // -------------------------------------------------------------------- @@ -282,7 +339,6 @@ class Controller extends CI_Base { $this->load = new CI_Loader(); } } - // END _ci_assign_core() // -------------------------------------------------------------------- @@ -311,7 +367,6 @@ class Controller extends CI_Base { $this->_ci_scaffolding = TRUE; $this->_ci_scaff_table = $table; } - // END _ci_init_scaffolding() // -------------------------------------------------------------------- @@ -324,7 +379,7 @@ class Controller extends CI_Base { * @return void */ function _ci_init_database($params = '', $return = FALSE, $active_record = FALSE) - { + { if ($this->_ci_is_loaded('db') == TRUE AND $return == FALSE AND $active_record == FALSE) { return; @@ -394,7 +449,6 @@ class Controller extends CI_Base { $obj =& get_instance(); $obj->db =& $DB; } - // END _ci_init_database() // -------------------------------------------------------------------- @@ -409,7 +463,6 @@ class Controller extends CI_Base { { return ( ! isset($this->$class) OR ! is_object($this->$class)) ? FALSE : TRUE; } - // END _ci_is_loaded() // -------------------------------------------------------------------- @@ -440,13 +493,11 @@ class Controller extends CI_Base { } $this->_ci_init_database("", FALSE, TRUE); - - $this->_ci_initialize('pagination'); + $this->_ci_init_class('pagination'); require_once(BASEPATH.'scaffolding/Scaffolding'.EXT); $this->scaff = new Scaffolding($this->_ci_scaff_table); $this->scaff->$method(); } - // END _ci_scaffolding() } // END _Controller class diff --git a/system/libraries/Email.php b/system/libraries/Email.php index c153043d9..c9b9365ec 100644 --- a/system/libraries/Email.php +++ b/system/libraries/Email.php @@ -16,7 +16,7 @@ // INITIALIZE THE CLASS --------------------------------------------------- $obj =& get_instance(); -$obj->email =& new CI_Email(); +$obj->init_class('CI_Email'); // ------------------------------------------------------------------------ diff --git a/system/libraries/Encrypt.php b/system/libraries/Encrypt.php index 446f64aa6..6a3ca17b0 100644 --- a/system/libraries/Encrypt.php +++ b/system/libraries/Encrypt.php @@ -16,7 +16,7 @@ // INITIALIZE THE CLASS --------------------------------------------------- $obj =& get_instance(); -$obj->encrypt =& new CI_Encrypt(); +$obj->init_class('CI_Encrypt'); // ------------------------------------------------------------------------ diff --git a/system/libraries/Image_lib.php b/system/libraries/Image_lib.php index 86ed05943..4962760eb 100644 --- a/system/libraries/Image_lib.php +++ b/system/libraries/Image_lib.php @@ -22,7 +22,7 @@ if (file_exists(APPPATH.'config/image_lib'.EXT)) } $obj =& get_instance(); -$obj->image_lib =& new CI_Image_lib($config); +$obj->init_class('CI_Image_lib', '', $config); // ------------------------------------------------------------------------ diff --git a/system/libraries/Loader.php b/system/libraries/Loader.php index 7449fa34a..df067cbc1 100644 --- a/system/libraries/Loader.php +++ b/system/libraries/Loader.php @@ -66,13 +66,13 @@ class CI_Loader { * @param mixed any initialization parameters * @return void */ - function library($class, $param = FALSE) + function library($class, $param = NULL) { if ($class == '') return; $obj =& get_instance(); - $obj->_ci_initialize($class, $param); + $obj->_ci_init_class($class, $param); $obj->_ci_assign_to_models(); } // END library() @@ -95,7 +95,7 @@ class CI_Loader { return; $obj =& get_instance(); - $obj->_ci_load_model($model, $name, $db_conn); + $obj->_ci_init_model($model, $name, $db_conn); } // END library() @@ -125,23 +125,6 @@ class CI_Loader { } } // END database() - - // -------------------------------------------------------------------- - - /** - * Database Utilities Loader - * - * @access public - * @param string the DB platform - * @param bool whether to return the DB object - * @return object - */ - function dbutil() - { - $obj =& get_instance(); - return $obj->_ci_init_dbutil($db, $return); - } - // END dbutils() // -------------------------------------------------------------------- diff --git a/system/libraries/Pagination.php b/system/libraries/Pagination.php index d83a2bd0f..cd55d56e0 100644 --- a/system/libraries/Pagination.php +++ b/system/libraries/Pagination.php @@ -22,7 +22,7 @@ if (file_exists(APPPATH.'config/pagination'.EXT)) } $obj =& get_instance(); -$obj->pagination =& new CI_Pagination($config); +$obj->init_class('CI_Pagination', '', $config); // ------------------------------------------------------------------------ diff --git a/system/libraries/Parser.php b/system/libraries/Parser.php index 5bc2eb5a3..76182271f 100644 --- a/system/libraries/Parser.php +++ b/system/libraries/Parser.php @@ -16,7 +16,7 @@ // INITIALIZE THE CLASS --------------------------------------------------- $obj =& get_instance(); -$obj->parser =& new CI_Parser(); +$obj->init_class('CI_Parser'); // ------------------------------------------------------------------------ diff --git a/system/libraries/Session.php b/system/libraries/Session.php index bcd2e4d7e..76acbfea9 100644 --- a/system/libraries/Session.php +++ b/system/libraries/Session.php @@ -16,7 +16,7 @@ // INITIALIZE THE CLASS --------------------------------------------------- $obj =& get_instance(); -$obj->session =& new CI_Session(); +$obj->init_class('CI_Session'); // ------------------------------------------------------------------------ diff --git a/system/libraries/Unit_test.php b/system/libraries/Unit_test.php index 19fac79a7..04c3c199b 100644 --- a/system/libraries/Unit_test.php +++ b/system/libraries/Unit_test.php @@ -16,7 +16,7 @@ // INITIALIZE THE CLASS --------------------------------------------------- $obj =& get_instance(); -$obj->unit =& new CI_Unit_test(); +$obj->init_class('CI_Unit_test'); // ------------------------------------------------------------------------ diff --git a/system/libraries/Upload.php b/system/libraries/Upload.php index 26f216544..3a6a6fc34 100644 --- a/system/libraries/Upload.php +++ b/system/libraries/Upload.php @@ -22,7 +22,7 @@ if (file_exists(APPPATH.'config/upload'.EXT)) } $obj =& get_instance(); -$obj->upload = new CI_Upload($config); +$obj->init_class('CI_Upload', '', $config); // ------------------------------------------------------------------------ diff --git a/system/libraries/Validation.php b/system/libraries/Validation.php index 6c755a991..34cacd5d8 100644 --- a/system/libraries/Validation.php +++ b/system/libraries/Validation.php @@ -16,7 +16,7 @@ // INITIALIZE THE CLASS --------------------------------------------------- $obj =& get_instance(); -$obj->validation =& new CI_Validation(); +$obj->init_class('CI_Validation'); // ------------------------------------------------------------------------ diff --git a/system/libraries/Xmlrpc.php b/system/libraries/Xmlrpc.php index b470f720a..24f79f2ba 100644 --- a/system/libraries/Xmlrpc.php +++ b/system/libraries/Xmlrpc.php @@ -5,7 +5,7 @@ * An open source application development framework for PHP 4.3.2 or newer * * @package CodeIgniter - * @author Rick Ellis + * @author Rick Ellis, Paul Burdick * @copyright Copyright (c) 2006, pMachine, Inc. * @license http://www.codeignitor.com/user_guide/license.html * @link http://www.codeigniter.com @@ -20,14 +20,8 @@ if ( ! function_exists('xml_parser_create')) // INITIALIZE THE CLASS --------------------------------------------------- -$config = array(); -if (file_exists(APPPATH.'config/xmlrpc'.EXT)) -{ - include_once(APPPATH.'config/xmlrpc'.EXT); -} - $obj =& get_instance(); -$obj->xmlrpc = new CI_XML_RPC($config); +$obj->init_class('CI_Xmlrpc'); // ------------------------------------------------------------------------ @@ -40,7 +34,7 @@ $obj->xmlrpc = new CI_XML_RPC($config); * @author Paul Burdick * @link http://www.codeigniter.com/user_guide/libraries/xmlrpc.html */ -class CI_XML_RPC { +class CI_Xmlrpc { var $debug = FALSE; // Debugging on or off var $xmlrpcI4 = 'i4'; @@ -78,7 +72,7 @@ class CI_XML_RPC { // VALUES THAT MULTIPLE CLASSES NEED //------------------------------------- - function CI_XML_RPC ($config = array()) + function CI_Xmlrpc ($config = array()) { $this->xmlrpcName = $this->xmlrpcName; @@ -351,7 +345,7 @@ class CI_XML_RPC { * @author Paul Burdick * @link http://www.codeigniter.com/user_guide/libraries/xmlrpc.html */ -class XML_RPC_Client extends CI_XML_RPC +class XML_RPC_Client extends CI_Xmlrpc { var $path = ''; var $server = ''; @@ -363,7 +357,7 @@ class XML_RPC_Client extends CI_XML_RPC function XML_RPC_Client($path, $server, $port=80) { - parent::CI_XML_RPC(); + parent::CI_Xmlrpc(); $this->port = $port; $this->server = $server; @@ -609,7 +603,7 @@ class XML_RPC_Response * @author Paul Burdick * @link http://www.codeigniter.com/user_guide/libraries/xmlrpc.html */ -class XML_RPC_Message extends CI_XML_RPC +class XML_RPC_Message extends CI_Xmlrpc { var $payload; var $method_name; @@ -618,7 +612,7 @@ class XML_RPC_Message extends CI_XML_RPC function XML_RPC_Message($method, $pars=0) { - parent::CI_XML_RPC(); + parent::CI_Xmlrpc(); $this->method_name = $method; if (is_array($pars) && sizeof($pars) > 0) @@ -1206,14 +1200,14 @@ class XML_RPC_Message extends CI_XML_RPC * @author Paul Burdick * @link http://www.codeigniter.com/user_guide/libraries/xmlrpc.html */ -class XML_RPC_Values extends CI_XML_RPC +class XML_RPC_Values extends CI_Xmlrpc { var $me = array(); var $mytype = 0; function XML_RPC_Values($val=-1, $type='') { - parent::CI_XML_RPC(); + parent::CI_Xmlrpc(); if ($val != -1 || $type != '') { diff --git a/system/libraries/Xmlrpcs.php b/system/libraries/Xmlrpcs.php index 4d50dfb96..a95764a98 100644 --- a/system/libraries/Xmlrpcs.php +++ b/system/libraries/Xmlrpcs.php @@ -5,7 +5,7 @@ * An open source application development framework for PHP 4.3.2 or newer * * @package CodeIgniter - * @author Rick Ellis + * @author Rick Ellis, Paul Burdick * @copyright Copyright (c) 2006, pMachine, Inc. * @license http://www.codeignitor.com/user_guide/license.html * @link http://www.codeigniter.com @@ -13,36 +13,18 @@ * @filesource */ +if ( ! function_exists('xml_parser_create')) +{ + show_error('Your PHP installation does not support XML'); +} + // INITIALIZE THE CLASS --------------------------------------------------- -$config = array(); -if (file_exists(APPPATH.'config/xmlrpcs'.EXT)) -{ - include_once(APPPATH.'config/xmlrpcs'.EXT); -} +require_once(BASEPATH.'libraries/Xmlrpc'.EXT); -if ( ! class_exists('CI_XML_RPC')) -{ - if ( ! file_exists(BASEPATH.'libraries/Xmlrpc'.EXT)) - { - if ( ! file_exists(APPPATH.'libraries/Xmlrpc'.EXT)) - { - show_error('Unable to locate the Xmlrpc class'); - } - else - { - require_once(APPPATH.'libraries/Xmlrpc'.EXT); - } - } - else - { - require_once(BASEPATH.'libraries/Xmlrpc'.EXT); - } -} - -$obj =& get_instance(); -$obj->xmlrpcs = new CI_XML_RPC_Server($config); +// The initialization code is at the bottom of this file. It seems to +// cause an error to have it at the top // ------------------------------------------------------------------------ @@ -55,7 +37,7 @@ $obj->xmlrpcs = new CI_XML_RPC_Server($config); * @author Paul Burdick * @link http://www.codeigniter.com/user_guide/libraries/xmlrpc.html */ -class CI_XML_RPC_Server extends CI_XML_RPC +class CI_Xmlrpcs extends CI_Xmlrpc { var $methods = array(); //array of methods mapped to function names and signatures var $debug_msg = ''; // Debug Message @@ -67,9 +49,9 @@ class CI_XML_RPC_Server extends CI_XML_RPC // Constructor, more or less //------------------------------------- - function CI_XML_RPC_Server($config=array()) + function CI_Xmlrpcs($config=array()) { - parent::CI_XML_RPC(); + parent::CI_Xmlrpc(); $this->set_system_methods(); if (isset($config['functions']) && is_array($config['functions'])) @@ -235,7 +217,7 @@ class CI_XML_RPC_Server extends CI_XML_RPC echo "

"; } - $r = $this->execute($m); + $r = $this->_execute($m); } //------------------------------------- @@ -508,7 +490,7 @@ class CI_XML_RPC_Server extends CI_XML_RPC $msg->params[] = $params->me['array'][$i]; } - $result = $this->execute($msg); + $result = $this->_execute($msg); if ($result->faultCode() != 0) { @@ -520,4 +502,15 @@ class CI_XML_RPC_Server extends CI_XML_RPC } // END XML_RPC_Server class + + +// INITIALIZE THE CLASS --------------------------------------------------- + +$obj =& get_instance(); +$obj->init_class('CI_Xmlrpc'); +$obj->init_class('CI_Xmlrpcs'); + +// ------------------------------------------------------------------------ + + ?> \ No newline at end of file -- cgit v1.2.3-24-g4f1b From 954246e23f7bc01d0c8d7b72e81e9ea4b376fd0c Mon Sep 17 00:00:00 2001 From: admin Date: Tue, 26 Sep 2006 07:52:22 +0000 Subject: --- system/scaffolding/Scaffolding.php | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) (limited to 'system') diff --git a/system/scaffolding/Scaffolding.php b/system/scaffolding/Scaffolding.php index 4b6ebeed5..9059ec15a 100644 --- a/system/scaffolding/Scaffolding.php +++ b/system/scaffolding/Scaffolding.php @@ -34,9 +34,12 @@ class Scaffolding { function Scaffolding($db_table) { $obj =& get_instance(); - foreach ($obj->ci_is_loaded as $val) + foreach (get_object_vars($obj) as $key => $var) { - $this->$val =& $obj->$val; + if (is_object($var)) + { + $this->$key =& $obj->$key; + } } /** -- cgit v1.2.3-24-g4f1b From 6e00bab0ecfbbdd35d135a297d54a4989a44e500 Mon Sep 17 00:00:00 2001 From: admin Date: Tue, 26 Sep 2006 08:13:06 +0000 Subject: --- system/libraries/Controller.php | 28 +++++++++++++++++++++++- system/libraries/Loader.php | 47 ++++++++++++++++++++++++----------------- 2 files changed, 55 insertions(+), 20 deletions(-) (limited to 'system') diff --git a/system/libraries/Controller.php b/system/libraries/Controller.php index 74b233ef3..9d858e6c2 100644 --- a/system/libraries/Controller.php +++ b/system/libraries/Controller.php @@ -301,9 +301,18 @@ class Controller extends CI_Base { } + $exceptions = array('dbutil', 'dbexport'); + foreach ($autoload['libraries'] as $item) { - $this->_ci_init_class($item); + if ( ! in_array($item, $exceptions)) + { + $this->_ci_init_class($item); + } + else + { + $this->_ci_init_dbextra($item); + } } unset($autoload['libraries']); @@ -452,6 +461,23 @@ class Controller extends CI_Base { // -------------------------------------------------------------------- + /** + * Initialize Database Ancillary Classes + * + * @access private + * @param str class name + * @return void + */ + function _ci_init_dbextra($class) + { + $map = array('dbutil' => 'DB_utility', 'dbexport' => 'DB_export'); + require_once(BASEPATH.'database/'.$map[$class].EXT); + + $this->init_class('CI_'.$map[$class], $class); + } + + // -------------------------------------------------------------------- + /** * Returns TRUE if a class is loaded, FALSE if not * diff --git a/system/libraries/Loader.php b/system/libraries/Loader.php index df067cbc1..90d824049 100644 --- a/system/libraries/Loader.php +++ b/system/libraries/Loader.php @@ -51,7 +51,6 @@ class CI_Loader { log_message('debug', "Loader Class Initialized"); } - // END CI_Loader() // -------------------------------------------------------------------- @@ -75,7 +74,6 @@ class CI_Loader { $obj->_ci_init_class($class, $param); $obj->_ci_assign_to_models(); } - // END library() // -------------------------------------------------------------------- @@ -97,7 +95,6 @@ class CI_Loader { $obj =& get_instance(); $obj->_ci_init_model($model, $name, $db_conn); } - // END library() // -------------------------------------------------------------------- @@ -124,10 +121,37 @@ class CI_Loader { $obj->_ci_assign_to_models(); } } - // END database() // -------------------------------------------------------------------- + /** + * Database Utiliy Loader + * + * @access public + * @return object + */ + function dbutil() + { + $obj =& get_instance(); + $obj->_ci_init_dbextra('dbutil'); + } + + // -------------------------------------------------------------------- + + /** + * Database Export Loader + * + * @access public + * @return object + */ + function dbexport() + { + $obj =& get_instance(); + $obj->_ci_init_dbextra('dbexport'); + } + + // -------------------------------------------------------------------- + /** * Scaffolding Loader * @@ -145,7 +169,6 @@ class CI_Loader { $obj =& get_instance(); $obj->_ci_init_scaffolding($table); } - // END scaffolding() // -------------------------------------------------------------------- @@ -170,7 +193,6 @@ class CI_Loader { { return $this->_ci_load(array('view' => $view, 'vars' => $this->_ci_object_to_array($vars), 'return' => $return)); } - // END view() // -------------------------------------------------------------------- @@ -188,7 +210,6 @@ class CI_Loader { { return $this->_ci_load(array('path' => $path, 'return' => $return)); } - // END file() // -------------------------------------------------------------------- @@ -214,7 +235,6 @@ class CI_Loader { } } } - // END vars() // -------------------------------------------------------------------- @@ -264,7 +284,6 @@ class CI_Loader { log_message('debug', 'Helpers loaded: '.implode(', ', $helpers)); } - // END helper() // -------------------------------------------------------------------- @@ -282,7 +301,6 @@ class CI_Loader { { $this->helper($helpers); } - // END helpers() // -------------------------------------------------------------------- @@ -332,7 +350,6 @@ class CI_Loader { log_message('debug', 'Plugins loaded: '.implode(', ', $plugins)); } - // END plugin() // -------------------------------------------------------------------- @@ -377,7 +394,6 @@ class CI_Loader { log_message('debug', 'Scripts loaded: '.implode(', ', $scripts)); } - // END script() // -------------------------------------------------------------------- @@ -395,7 +411,6 @@ class CI_Loader { { $this->plugin($plugins); } - // END plugins() // -------------------------------------------------------------------- @@ -411,7 +426,6 @@ class CI_Loader { $obj =& get_instance(); return $obj->lang->load($file, $lang, $return); } - // END language() // -------------------------------------------------------------------- @@ -427,7 +441,6 @@ class CI_Loader { $obj =& get_instance(); $obj->config->load($file); } - // END config() // -------------------------------------------------------------------- @@ -442,7 +455,6 @@ class CI_Loader { { $this->view_path = $path; } - // END _ci_set_view_path() // -------------------------------------------------------------------- @@ -553,7 +565,6 @@ class CI_Loader { ob_end_clean(); } } - // END _load() // -------------------------------------------------------------------- @@ -582,7 +593,6 @@ class CI_Loader { } } } - // END _ci_autoloader() // -------------------------------------------------------------------- @@ -599,7 +609,6 @@ class CI_Loader { { return (is_object($object)) ? get_object_vars($object) : $object; } - // END _ci_object_to_array() } ?> \ No newline at end of file -- cgit v1.2.3-24-g4f1b From b63ac845de0c7c57c7db755de9af36ce34b67426 Mon Sep 17 00:00:00 2001 From: admin Date: Tue, 26 Sep 2006 18:14:43 +0000 Subject: --- system/database/DB_export.php | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) (limited to 'system') diff --git a/system/database/DB_export.php b/system/database/DB_export.php index 14e7af68b..02b4b42ad 100644 --- a/system/database/DB_export.php +++ b/system/database/DB_export.php @@ -12,7 +12,6 @@ * @since Version 1.0 * @filesource */ - // INITIALIZE THE CLASS --------------------------------------------------- @@ -38,10 +37,13 @@ class CI_DB_export { } /** - * Generate CVS + * Generate CVS from a query result object * * @access public - * @return integer + * @param object The query result object + * @param string The delimiter - tab by default + * @param string The newline character - \n by default + * @return string */ function generate_cvs($query, $delim = "\t", $newline = "\n") { @@ -51,13 +53,15 @@ class CI_DB_export { } $out = ''; + + // First generate the headings from the table column names foreach ($query->field_names() as $name) { $out .= $name.$delim; } - $out .= $newline; + // Next blast through the result array and build out the rows foreach ($query->result_array() as $row) { foreach ($row as $item) @@ -67,7 +71,6 @@ class CI_DB_export { $out .= $newline; } - return $out; } -- cgit v1.2.3-24-g4f1b From f0839f3bb0fc8b13a1d9b64ed4a7ff86147be9ae Mon Sep 17 00:00:00 2001 From: admin Date: Tue, 26 Sep 2006 18:16:01 +0000 Subject: --- system/database/DB_export.php | 3 +++ 1 file changed, 3 insertions(+) (limited to 'system') diff --git a/system/database/DB_export.php b/system/database/DB_export.php index 02b4b42ad..a217ad138 100644 --- a/system/database/DB_export.php +++ b/system/database/DB_export.php @@ -31,6 +31,9 @@ $obj->init_class('CI_DB_export', 'dbexport'); class CI_DB_export { + /** + * Constructor. Simply calls the log function + */ function CI_DB_export() { log_message('debug', "Database Export Class Initialized"); -- cgit v1.2.3-24-g4f1b From 41a1685573aa0ede15a9bf7b373c36a0406fb19d Mon Sep 17 00:00:00 2001 From: admin Date: Tue, 26 Sep 2006 18:17:19 +0000 Subject: --- system/application/config/autoload.php | 2 +- system/application/config/config.php | 12 ++++++------ system/application/config/database.php | 4 ++-- system/codeigniter/CodeIgniter.php | 2 +- system/database/DB_utility.php | 6 ++++++ system/libraries/Controller.php | 4 +--- system/libraries/Email.php | 8 +++++++- 7 files changed, 24 insertions(+), 14 deletions(-) (limited to 'system') diff --git a/system/application/config/autoload.php b/system/application/config/autoload.php index 915dcee12..fc9d43fb6 100644 --- a/system/application/config/autoload.php +++ b/system/application/config/autoload.php @@ -38,7 +38,7 @@ | $autoload['libraries'] = array('database', 'session', 'xmlrpc'); */ -$autoload['libraries'] = array(); +$autoload['libraries'] = array('database', 'calendar', 'dbutil', 'dbexport'); /* diff --git a/system/application/config/config.php b/system/application/config/config.php index a7b3204cc..12501e684 100644 --- a/system/application/config/config.php +++ b/system/application/config/config.php @@ -34,14 +34,14 @@ $config['index_page'] = "index.php"; | URI string. The default setting of "auto" works for most servers. | If your links do not seem to work, try one of the other delicious flavors: | -| 'auto' Default - auto detects -| 'path_info' Uses the PATH_INFO -| 'query_string' Uses the QUERY_STRING -| 'orig_path_info' Uses the ORIG_PATH_INFO -| 'request_uri' Uses the REQUEST_URI +| 'AUTO' Default - auto detects +| 'PATH_INFO' Uses the PATH_INFO +| 'QUERY_STRING' Uses the QUERY_STRING +| 'REQUEST_URI' Uses the REQUEST_URI +| 'ORIG_PATH_INFO' Uses the ORIG_PATH_INFO | */ -$config['uri_protocol'] = "auto"; +$config['uri_protocol'] = "AUTO"; /* |-------------------------------------------------------------------------- diff --git a/system/application/config/database.php b/system/application/config/database.php index cf91844d1..204ef6894 100644 --- a/system/application/config/database.php +++ b/system/application/config/database.php @@ -32,9 +32,9 @@ $active_group = "default"; $db['default']['hostname'] = "localhost"; -$db['default']['username'] = ""; +$db['default']['username'] = "root"; $db['default']['password'] = ""; -$db['default']['database'] = ""; +$db['default']['database'] = "test"; $db['default']['dbdriver'] = "mysql"; $db['default']['dbprefix'] = ""; $db['default']['active_r'] = TRUE; diff --git a/system/codeigniter/CodeIgniter.php b/system/codeigniter/CodeIgniter.php index a227066fc..05194503f 100644 --- a/system/codeigniter/CodeIgniter.php +++ b/system/codeigniter/CodeIgniter.php @@ -27,7 +27,7 @@ * @link http://www.codeigniter.com/user_guide/ */ -define('APPVER', '1.4.1'); +define('APPVER', '1.5.0'); /* * ------------------------------------------------------ diff --git a/system/database/DB_utility.php b/system/database/DB_utility.php index 3b4b09d6e..00e20c6c6 100644 --- a/system/database/DB_utility.php +++ b/system/database/DB_utility.php @@ -31,6 +31,12 @@ class CI_DB_utility { var $db; + /** + * Constructor + * + * Grabs the CI super object instance so we can access it. + * + */ function CI_DB_utility() { // Assign the main database object to $this->db diff --git a/system/libraries/Controller.php b/system/libraries/Controller.php index 9d858e6c2..23c050e18 100644 --- a/system/libraries/Controller.php +++ b/system/libraries/Controller.php @@ -82,8 +82,7 @@ class Controller extends CI_Base { */ function init_class($class, $varname = '', $params = NULL) { - // First figure out what variable we're going to - // use to instantiate the class to + // First figure out what variable we're going to assign the class to if ($varname == '') { $varname = ( ! is_null($this->_ci_last_handle)) ? $this->_ci_last_handle : strtolower(str_replace('CI_', '', $class)); @@ -156,7 +155,6 @@ class Controller extends CI_Base { // $obj->init_class() so that the class can get instantiated. // For backward compatibility we'll test for filenames that are // both uppercase and lower. - foreach (array(ucfirst($class), $class) as $filename) { for ($i = 1; $i < 3; $i++) diff --git a/system/libraries/Email.php b/system/libraries/Email.php index c9b9365ec..fd3fb8f17 100644 --- a/system/libraries/Email.php +++ b/system/libraries/Email.php @@ -15,8 +15,14 @@ // INITIALIZE THE CLASS --------------------------------------------------- +$config = array(); +if (file_exists(APPPATH.'config/email'.EXT)) +{ + include_once(APPPATH.'config/email'.EXT); +} + $obj =& get_instance(); -$obj->init_class('CI_Email'); +$obj->init_class('CI_Email', 'email', $config); // ------------------------------------------------------------------------ -- cgit v1.2.3-24-g4f1b From 31075cf97ac386686e679eb7b8aaf852fd12d838 Mon Sep 17 00:00:00 2001 From: admin Date: Tue, 26 Sep 2006 18:50:02 +0000 Subject: --- system/database/DB_utility.php | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) (limited to 'system') diff --git a/system/database/DB_utility.php b/system/database/DB_utility.php index 00e20c6c6..281a3b87d 100644 --- a/system/database/DB_utility.php +++ b/system/database/DB_utility.php @@ -187,6 +187,39 @@ class CI_DB_utility { // -------------------------------------------------------------------- + /** + * Optimize Database + * + * @access public + * @param string the table name + * @return bool + */ + function optimize_database() + { + $result = array(); + foreach ($this->list_tables() as $table_name) + { + $sql = $this->_optimize_table($table_name); + + if (is_bool($sql)) + { + return $sql; + } + + $query = $this->db->query($sql); + $res = current($query->result_array()); + $key = str_replace($this->db->database.'.', '', current($res)); + $keys = array_keys($res); + unset($res[$keys[0]]); + + $result[$key] = $res; + } + + return $result; + } + + // -------------------------------------------------------------------- + /** * Optimize Table * -- cgit v1.2.3-24-g4f1b From eb13db750ac04921774b8bc7d8b26f343195061a Mon Sep 17 00:00:00 2001 From: admin Date: Wed, 27 Sep 2006 00:30:48 +0000 Subject: --- system/database/DB_export.php | 80 +++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 78 insertions(+), 2 deletions(-) (limited to 'system') diff --git a/system/database/DB_export.php b/system/database/DB_export.php index a217ad138..8d6446cb6 100644 --- a/system/database/DB_export.php +++ b/system/database/DB_export.php @@ -39,6 +39,8 @@ class CI_DB_export { log_message('debug', "Database Export Class Initialized"); } + // -------------------------------------------------------------------- + /** * Generate CVS from a query result object * @@ -48,7 +50,7 @@ class CI_DB_export { * @param string The newline character - \n by default * @return string */ - function generate_cvs($query, $delim = "\t", $newline = "\n") + function cvs_from_result($query, $delim = "\t", $newline = "\n") { if ( ! is_object($query) OR ! method_exists($query, 'field_names')) { @@ -62,6 +64,8 @@ class CI_DB_export { { $out .= $name.$delim; } + + $out = rtrim($out); $out .= $newline; // Next blast through the result array and build out the rows @@ -71,7 +75,7 @@ class CI_DB_export { { $out .= $item.$delim; } - + $out = rtrim($out); $out .= $newline; } @@ -81,6 +85,78 @@ class CI_DB_export { // -------------------------------------------------------------------- + /** + * 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, 'field_names')) + { + 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); + + // 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}>".$this->_xml_convert($val)."".$newline; + } + $xml .= $tab."".$newline; + } + $xml .= "".$newline; + + return $xml; + } + + + // ------------------------------------------------------------------------ + + /** + * Convert Reserved XML characters to Entities + * + * @access public + * @param string + * @return string + */ + function _xml_convert($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; + } + } ?> \ No newline at end of file -- cgit v1.2.3-24-g4f1b From e5bb936f808bfd39a6ba8cbe1fc2ddbcf9bf502f Mon Sep 17 00:00:00 2001 From: admin Date: Wed, 27 Sep 2006 00:31:22 +0000 Subject: --- system/database/DB_utility.php | 5 +++-- system/database/drivers/mysql/mysql_utility.php | 2 +- system/libraries/Controller.php | 20 ++++++++++++++++---- system/libraries/Xmlrpcs.php | 20 ++++++-------------- 4 files changed, 26 insertions(+), 21 deletions(-) (limited to 'system') diff --git a/system/database/DB_utility.php b/system/database/DB_utility.php index 281a3b87d..a2469d059 100644 --- a/system/database/DB_utility.php +++ b/system/database/DB_utility.php @@ -191,8 +191,7 @@ class CI_DB_utility { * Optimize Database * * @access public - * @param string the table name - * @return bool + * @return array */ function optimize_database() { @@ -207,6 +206,8 @@ class CI_DB_utility { } $query = $this->db->query($sql); + + // Build the result array... $res = current($query->result_array()); $key = str_replace($this->db->database.'.', '', current($res)); $keys = array_keys($res); diff --git a/system/database/drivers/mysql/mysql_utility.php b/system/database/drivers/mysql/mysql_utility.php index 9ba4a79c5..a81936c56 100644 --- a/system/database/drivers/mysql/mysql_utility.php +++ b/system/database/drivers/mysql/mysql_utility.php @@ -12,7 +12,7 @@ * @since Version 1.0 * @filesource */ - + // ------------------------------------------------------------------------ /** diff --git a/system/libraries/Controller.php b/system/libraries/Controller.php index 23c050e18..56b4d6f90 100644 --- a/system/libraries/Controller.php +++ b/system/libraries/Controller.php @@ -468,10 +468,22 @@ class Controller extends CI_Base { */ function _ci_init_dbextra($class) { - $map = array('dbutil' => 'DB_utility', 'dbexport' => 'DB_export'); - require_once(BASEPATH.'database/'.$map[$class].EXT); - - $this->init_class('CI_'.$map[$class], $class); + if ( ! $this->_ci_is_loaded('db')) + { + $this->_init_database(); + } + + if ($class == 'dbutil') + { + require_once(BASEPATH.'database/DB_utility'.EXT); + require_once(BASEPATH.'database/drivers/'.$this->db->dbdriver.'/'.$this->db->dbdriver.'_utility'.EXT); + $this->init_class('CI_DB_'.$this->db->dbdriver.'_utility', 'dbutil'); + } + elseif ($class == 'dbexport') + { + require_once(BASEPATH.'database/DB_export'.EXT); + $this->init_class('CI_DB_export', 'dbexport'); + } } // -------------------------------------------------------------------- diff --git a/system/libraries/Xmlrpcs.php b/system/libraries/Xmlrpcs.php index a95764a98..f41437342 100644 --- a/system/libraries/Xmlrpcs.php +++ b/system/libraries/Xmlrpcs.php @@ -18,13 +18,15 @@ if ( ! function_exists('xml_parser_create')) show_error('Your PHP installation does not support XML'); } +if ( ! class_exists('CI_Xmlrpc')) +{ + show_error('You must load the Xmlrpc class before loading the Xmlrpcs class in order to create a server.'); +} // INITIALIZE THE CLASS --------------------------------------------------- -require_once(BASEPATH.'libraries/Xmlrpc'.EXT); - -// The initialization code is at the bottom of this file. It seems to -// cause an error to have it at the top +$obj =& get_instance(); +$obj->init_class('CI_Xmlrpcs'); // ------------------------------------------------------------------------ @@ -503,14 +505,4 @@ class CI_Xmlrpcs extends CI_Xmlrpc } // END XML_RPC_Server class - -// INITIALIZE THE CLASS --------------------------------------------------- - -$obj =& get_instance(); -$obj->init_class('CI_Xmlrpc'); -$obj->init_class('CI_Xmlrpcs'); - -// ------------------------------------------------------------------------ - - ?> \ No newline at end of file -- cgit v1.2.3-24-g4f1b From 913ffb7af39d07eefb887e1c8faaf25e0ae79097 Mon Sep 17 00:00:00 2001 From: admin Date: Wed, 27 Sep 2006 00:36:28 +0000 Subject: --- system/database/DB_cache.php | 44 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 system/database/DB_cache.php (limited to 'system') diff --git a/system/database/DB_cache.php b/system/database/DB_cache.php new file mode 100644 index 000000000..ca3bba2eb --- /dev/null +++ b/system/database/DB_cache.php @@ -0,0 +1,44 @@ + \ No newline at end of file -- cgit v1.2.3-24-g4f1b From 5abd04902b11472cd8243280f0c08687325c5e90 Mon Sep 17 00:00:00 2001 From: admin Date: Wed, 27 Sep 2006 01:54:01 +0000 Subject: --- system/database/DB_export.php | 34 +++++----------------------------- 1 file changed, 5 insertions(+), 29 deletions(-) (limited to 'system') diff --git a/system/database/DB_export.php b/system/database/DB_export.php index 8d6446cb6..a2e3e3e4c 100644 --- a/system/database/DB_export.php +++ b/system/database/DB_export.php @@ -112,8 +112,11 @@ class CI_DB_export { // Create variables for convenience extract($params); + // Load the xml helper + $obj =& get_instance(); + $obj->load->helper('xml'); + // Generate the result - $xml = "<{$root}/>".$newline; foreach ($query->result_array() as $row) { @@ -121,7 +124,7 @@ class CI_DB_export { foreach ($row as $key => $val) { - $xml .= $tab.$tab."<{$key}>".$this->_xml_convert($val)."".$newline; + $xml .= $tab.$tab."<{$key}>".xml_convert($val)."".$newline; } $xml .= $tab."".$newline; } @@ -130,33 +133,6 @@ class CI_DB_export { return $xml; } - - // ------------------------------------------------------------------------ - - /** - * Convert Reserved XML characters to Entities - * - * @access public - * @param string - * @return string - */ - function _xml_convert($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; - } - } ?> \ No newline at end of file -- cgit v1.2.3-24-g4f1b From 402d1d511d79b4e6d760dc3c88b4fe80a53a8a56 Mon Sep 17 00:00:00 2001 From: admin Date: Wed, 27 Sep 2006 01:54:14 +0000 Subject: --- system/database/DB_active_rec.php | 2 +- system/database/DB_cache.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'system') diff --git a/system/database/DB_active_rec.php b/system/database/DB_active_rec.php index c038185bc..eb9f14a92 100644 --- a/system/database/DB_active_rec.php +++ b/system/database/DB_active_rec.php @@ -135,7 +135,7 @@ class CI_DB_active_record extends CI_DB_driver { } } - $this->ar_join[] = $type.'JOIN '.$table.' ON '.$cond; + $this->ar_join[] = $type.'JOIN '.$this->dbprefix.$table.' ON '.$cond; return $this; } diff --git a/system/database/DB_cache.php b/system/database/DB_cache.php index ca3bba2eb..086958d3d 100644 --- a/system/database/DB_cache.php +++ b/system/database/DB_cache.php @@ -27,7 +27,7 @@ class CI_DB_cache { /** - * Generate CVS from a query result object + * Cache it! * * @access public * @return string -- cgit v1.2.3-24-g4f1b From 17a890df20b56c8d82812f365f27bc590be009f3 Mon Sep 17 00:00:00 2001 From: admin Date: Wed, 27 Sep 2006 20:42:42 +0000 Subject: --- system/application/config/autoload.php | 16 ---------------- system/application/config/database.php | 2 +- system/database/drivers/mysql/mysql_driver.php | 14 +++++++++++++- system/database/drivers/mysqli/mysqli_driver.php | 14 +++++++++++++- system/libraries/Router.php | 20 +++++++++++++++++--- 5 files changed, 44 insertions(+), 22 deletions(-) (limited to 'system') diff --git a/system/application/config/autoload.php b/system/application/config/autoload.php index fc9d43fb6..245d36a7c 100644 --- a/system/application/config/autoload.php +++ b/system/application/config/autoload.php @@ -21,7 +21,6 @@ | 1. Libraries | 2. Helper files | 3. Plugins -| 4. Scripts | 5. Custom config files | */ @@ -65,21 +64,6 @@ $autoload['helper'] = array(); $autoload['plugin'] = array(); -/* -| ------------------------------------------------------------------- -| Auto-load Scripts -| ------------------------------------------------------------------- -| The term "scripts" refers to you own PHP scripts that you've -| placed in the application/scripts/ folder -| -| Prototype: -| -| $autoload['script'] = array('my_script1', 'my_script2'); -*/ - -$autoload['script'] = array(); - - /* | ------------------------------------------------------------------- | Auto-load Config files diff --git a/system/application/config/database.php b/system/application/config/database.php index 204ef6894..5e6420831 100644 --- a/system/application/config/database.php +++ b/system/application/config/database.php @@ -34,7 +34,7 @@ $active_group = "default"; $db['default']['hostname'] = "localhost"; $db['default']['username'] = "root"; $db['default']['password'] = ""; -$db['default']['database'] = "test"; +$db['default']['database'] = "tester"; $db['default']['dbdriver'] = "mysql"; $db['default']['dbprefix'] = ""; $db['default']['active_r'] = TRUE; diff --git a/system/database/drivers/mysql/mysql_driver.php b/system/database/drivers/mysql/mysql_driver.php index b6c4eb7ea..d4f322d5f 100644 --- a/system/database/drivers/mysql/mysql_driver.php +++ b/system/database/drivers/mysql/mysql_driver.php @@ -222,7 +222,19 @@ class CI_DB_mysql_driver extends CI_DB { */ function escape_str($str) { - return mysql_real_escape_string($str); + if (get_magic_quotes_gpc()) + { + return $str; + } + + if (function_exists('mysql_escape_string')) + { + return mysql_real_escape_string($str); + } + else + { + return addslashes($str); + } } // -------------------------------------------------------------------- diff --git a/system/database/drivers/mysqli/mysqli_driver.php b/system/database/drivers/mysqli/mysqli_driver.php index d6e967498..63df0fe6f 100644 --- a/system/database/drivers/mysqli/mysqli_driver.php +++ b/system/database/drivers/mysqli/mysqli_driver.php @@ -225,7 +225,19 @@ class CI_DB_mysqli_driver extends CI_DB { */ function escape_str($str) { - return mysqli_real_escape_string($this->conn_id, $str); + if (get_magic_quotes_gpc()) + { + return $str; + } + + if (function_exists('mysql_escape_string')) + { + return mysqli_real_escape_string($this->conn_id, $str); + } + else + { + return addslashes($str); + } } // -------------------------------------------------------------------- diff --git a/system/libraries/Router.php b/system/libraries/Router.php index d7740f5f3..34a2512a6 100644 --- a/system/libraries/Router.php +++ b/system/libraries/Router.php @@ -65,7 +65,9 @@ class CI_Router { */ function _set_route_mapping() { - // Are query strings enabled? If so we're done... + + // Are query strings enabled in the config file? + // If so, we're done since segment based URIs are not used with query strings. if ($this->config->item('enable_query_strings') === TRUE AND isset($_GET[$this->config->item('controller_trigger')])) { $this->set_class($_GET[$this->config->item('controller_trigger')]); @@ -78,15 +80,26 @@ class CI_Router { return; } - // Load the routes.php file and set the default controller + // Load the routes.php file. @include_once(APPPATH.'config/routes'.EXT); $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']); + // Fetch the complete URI string + $this->uri_string = $this->_get_uri_string(); + + // If the URI contains only a slash we'll kill it + if ($this->uri_string == '/') + { + $this->uri_string = ''; + } + // Is there a URI string? If not, the default controller specified in the "routes" file will be shown. - if (($this->uri_string = $this->_get_uri_string()) == '') + if ($this->uri_string == '') { if ($this->default_controller === FALSE) { @@ -107,6 +120,7 @@ class CI_Router { $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. foreach(explode("/", preg_replace("|/*(.+?)/*$|", "\\1", $this->uri_string)) as $val) -- cgit v1.2.3-24-g4f1b From 33de9a144aad28763405f8ae2d5c59df5e929b4f Mon Sep 17 00:00:00 2001 From: admin Date: Thu, 28 Sep 2006 06:50:16 +0000 Subject: --- system/application/config/autoload.php | 2 +- system/application/config/routes.php | 2 +- system/codeigniter/CodeIgniter.php | 20 +-- system/codeigniter/Common.php | 89 ++++++++---- system/database/DB_export.php | 6 - system/database/DB_utility.php | 5 - system/database/drivers/mysql/mysql_driver.php | 8 +- system/database/drivers/mysqli/mysqli_driver.php | 9 +- system/libraries/Benchmark.php | 9 -- system/libraries/Calendar.php | 5 - system/libraries/Controller.php | 165 ++++++++++++++--------- system/libraries/Email.php | 11 -- system/libraries/Encrypt.php | 5 - system/libraries/Hooks.php | 2 +- system/libraries/Image_lib.php | 11 -- system/libraries/Input.php | 2 +- system/libraries/Loader.php | 2 +- system/libraries/Output.php | 4 +- system/libraries/Pagination.php | 11 -- system/libraries/Parser.php | 5 - system/libraries/Router.php | 21 +-- system/libraries/Session.php | 5 - system/libraries/Trackback.php | 5 - system/libraries/URI.php | 2 +- system/libraries/Unit_test.php | 5 - system/libraries/Upload.php | 11 -- system/libraries/Validation.php | 5 - system/libraries/Xmlrpc.php | 4 - system/libraries/Xmlrpcs.php | 5 - 29 files changed, 192 insertions(+), 244 deletions(-) (limited to 'system') diff --git a/system/application/config/autoload.php b/system/application/config/autoload.php index 245d36a7c..6a62cd652 100644 --- a/system/application/config/autoload.php +++ b/system/application/config/autoload.php @@ -37,7 +37,7 @@ | $autoload['libraries'] = array('database', 'session', 'xmlrpc'); */ -$autoload['libraries'] = array('database', 'calendar', 'dbutil', 'dbexport'); +$autoload['libraries'] = array('database', 'calendar'); /* diff --git a/system/application/config/routes.php b/system/application/config/routes.php index 8a1f8b166..468ff0ab5 100644 --- a/system/application/config/routes.php +++ b/system/application/config/routes.php @@ -33,7 +33,7 @@ | | $route['scaffolding_trigger'] = 'scaffolding'; | -| This route lets you set a "secret" word that will trigger the +| This route lets you se t a "secret" word that will trigger the | scaffolding feature for added security. Note: Scaffolding must be | enabled in the controller in which you intend to use it. | diff --git a/system/codeigniter/CodeIgniter.php b/system/codeigniter/CodeIgniter.php index 05194503f..4ac03820a 100644 --- a/system/codeigniter/CodeIgniter.php +++ b/system/codeigniter/CodeIgniter.php @@ -50,7 +50,7 @@ set_magic_quotes_runtime(0); // Kill magic quotes * ------------------------------------------------------ */ -$BM =& _load_class('CI_Benchmark'); +$BM =& _load_class('Benchmark'); $BM->mark('code_igniter_start'); /* @@ -59,7 +59,7 @@ $BM->mark('code_igniter_start'); * ------------------------------------------------------ */ -$EXT =& _load_class('CI_Hooks'); +$EXT =& _load_class('Hooks'); /* * ------------------------------------------------------ @@ -74,9 +74,9 @@ $EXT->_call_hook('pre_system'); * ------------------------------------------------------ */ -$CFG =& _load_class('CI_Config'); -$RTR =& _load_class('CI_Router'); -$OUT =& _load_class('CI_Output'); +$CFG =& _load_class('Config'); +$RTR =& _load_class('Router'); +$OUT =& _load_class('Output'); /* * ------------------------------------------------------ @@ -98,9 +98,9 @@ if ($EXT->_call_hook('cache_override') === FALSE) * ------------------------------------------------------ */ -$IN =& _load_class('CI_Input'); -$URI =& _load_class('CI_URI'); -$LANG =& _load_class('CI_Language'); +$IN =& _load_class('Input'); +$URI =& _load_class('URI'); +$LANG =& _load_class('Language'); /* * ------------------------------------------------------ @@ -115,7 +115,7 @@ $LANG =& _load_class('CI_Language'); * */ -_load_class('CI_Loader', FALSE); +_load_class('Loader', FALSE); if (floor(phpversion()) < 5) { @@ -126,7 +126,7 @@ else require(BASEPATH.'codeigniter/Base5'.EXT); } -_load_class('CI_Controller', FALSE); +_load_class('Controller', FALSE); require(APPPATH.'controllers/'.$RTR->fetch_directory().$RTR->fetch_class().EXT); diff --git a/system/codeigniter/Common.php b/system/codeigniter/Common.php index 885cca2f5..24e6042cc 100644 --- a/system/codeigniter/Common.php +++ b/system/codeigniter/Common.php @@ -32,42 +32,81 @@ /** * 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 * @return object */ function &_load_class($class, $instantiate = TRUE) { static $objects = array(); - - if ( ! isset($objects[$class])) + + // Does the class exist? If so, we're done... + if (isset($objects[$class])) { - if (FALSE !== strpos($class, 'CI_')) - { - if (file_exists(APPPATH.'libraries/'.str_replace('CI_', '', $class).EXT)) - { - require(APPPATH.'libraries/'.str_replace('CI_', '', $class).EXT); - } - else - { - require(BASEPATH.'libraries/'.str_replace('CI_', '', $class).EXT); - } - } + return $objects[$class]; + } - if ($instantiate == TRUE) + // This is a special case. It's a class in the Base5.php file + // which we don't need to load. We only instantiate it. + if ($class == 'Instance') + { + return $objects[$class] =& new $class(); + } + + // If the requested class does not exist in the application/libraries + // folder we'll load the native class from the system/libraries folder. + + $is_subclass = FALSE; + if ( ! file_exists(APPPATH.'libraries/'.$class.EXT)) + { + require(BASEPATH.'libraries/'.$class.EXT); + } + else + { + // A core class can either be extended or replaced by putting an + // identially named file in the application/libraries folder. + // We need to need to determine if the class being requested is + // a sub-class or an independent instance so we'll open the file, + // read the top portion of it. If the class extends the base class + // we need to load it's parent. If it doesn't extend the base we'll + // only load the requested class. + + // Note: I'm not thrilled with this approach since it requires us to + // read the file, but I can't think of any other way to allow classes + // to be extended on-the-fly. I did benchmark the difference with and + // without the file reading and I'm not seeing a perceptable difference. + + $fp = fopen(APPPATH.'libraries/'.$class.EXT, "rb"); + if (preg_match("/MY_".$class."\s+extends\s+CI_".$class."/", fread($fp, '8000'))) { - if ($class == 'CI_Controller') - $class = 'Controller'; - - $objects[$class] =& new $class(); + require(BASEPATH.'libraries/'.$class.EXT); + require(APPPATH.'libraries/'.$class.EXT); + $is_subclass = TRUE; } else { - $objects[$class] = TRUE; + require(APPPATH.'libraries/'.$class.EXT); } + fclose($fp); } + + if ($instantiate == FALSE) + { + return $objects[$class] = TRUE; + } + + if ($is_subclass == TRUE) + { + $name = 'MY_'.$class; + return $objects[$class] =& new $name(); + } + + $name = ($class != 'Controller') ? 'CI_'.$class : $class; - return $objects[$class]; + return $objects[$class] =& new $name(); } /** @@ -115,7 +154,7 @@ function &_get_config() */ function show_error($message) { - $error =& _load_class('CI_Exceptions'); + $error =& _load_class('Exceptions'); echo $error->show_error('An Error Was Encountered', $message); exit; } @@ -133,7 +172,7 @@ function show_error($message) */ function show_404($page = '') { - $error =& _load_class('CI_Exceptions'); + $error =& _load_class('Exceptions'); $error->show_404($page); exit; } @@ -158,7 +197,7 @@ function log_message($level = 'error', $message, $php_error = FALSE) return; } - $LOG =& _load_class('CI_Log'); + $LOG =& _load_class('Log'); $LOG->write_log($level, $message, $php_error); } @@ -191,7 +230,7 @@ function _exception_handler($severity, $message, $filepath, $line) return; } - $error =& _load_class('CI_Exceptions'); + $error =& _load_class('Exceptions'); // Should we display the error? // We'll get the current error_reporting level and add its bits diff --git a/system/database/DB_export.php b/system/database/DB_export.php index a2e3e3e4c..1704f0dfd 100644 --- a/system/database/DB_export.php +++ b/system/database/DB_export.php @@ -13,12 +13,6 @@ * @filesource */ - -// INITIALIZE THE CLASS --------------------------------------------------- - -$obj =& get_instance(); -$obj->init_class('CI_DB_export', 'dbexport'); - // ------------------------------------------------------------------------ /** diff --git a/system/database/DB_utility.php b/system/database/DB_utility.php index a2469d059..764f10cb7 100644 --- a/system/database/DB_utility.php +++ b/system/database/DB_utility.php @@ -12,11 +12,6 @@ * @since Version 1.0 * @filesource */ - -// INITIALIZE THE CLASS --------------------------------------------------- - -$obj =& get_instance(); -$obj->init_class('CI_DB_utility', 'dbutility'); // ------------------------------------------------------------------------ diff --git a/system/database/drivers/mysql/mysql_driver.php b/system/database/drivers/mysql/mysql_driver.php index d4f322d5f..792e023a8 100644 --- a/system/database/drivers/mysql/mysql_driver.php +++ b/system/database/drivers/mysql/mysql_driver.php @@ -227,9 +227,13 @@ class CI_DB_mysql_driver extends CI_DB { return $str; } - if (function_exists('mysql_escape_string')) + if (function_exists('mysql_real_escape_string')) { - return mysql_real_escape_string($str); + return mysql_real_escape_string($str, $this->conn_id); + } + elseif (function_exists('mysql_escape_string')) + { + return mysql_escape_string($str); } else { diff --git a/system/database/drivers/mysqli/mysqli_driver.php b/system/database/drivers/mysqli/mysqli_driver.php index 63df0fe6f..b158cfefe 100644 --- a/system/database/drivers/mysqli/mysqli_driver.php +++ b/system/database/drivers/mysqli/mysqli_driver.php @@ -230,14 +230,7 @@ class CI_DB_mysqli_driver extends CI_DB { return $str; } - if (function_exists('mysql_escape_string')) - { - return mysqli_real_escape_string($this->conn_id, $str); - } - else - { - return addslashes($str); - } + return mysqli_real_escape_string($this->conn_id, $str); } // -------------------------------------------------------------------- diff --git a/system/libraries/Benchmark.php b/system/libraries/Benchmark.php index 9dd9d4ac4..d8dd903e7 100644 --- a/system/libraries/Benchmark.php +++ b/system/libraries/Benchmark.php @@ -31,15 +31,6 @@ class CI_Benchmark { var $marker = array(); - /** - * Constructor - * - * @access public - */ - function CI_Benchmark() - { - } - // END CI_Benchmark() // -------------------------------------------------------------------- diff --git a/system/libraries/Calendar.php b/system/libraries/Calendar.php index bde98113a..8c7d95aa5 100644 --- a/system/libraries/Calendar.php +++ b/system/libraries/Calendar.php @@ -13,11 +13,6 @@ * @filesource */ -// INITIALIZE THE CLASS --------------------------------------------------- - -$obj =& get_instance(); -$obj->init_class('CI_Calendar'); - // ------------------------------------------------------------------------ /** diff --git a/system/libraries/Controller.php b/system/libraries/Controller.php index 56b4d6f90..aa7b87b00 100644 --- a/system/libraries/Controller.php +++ b/system/libraries/Controller.php @@ -32,8 +32,6 @@ class Controller extends CI_Base { var $_ci_models = array(); var $_ci_scaffolding = FALSE; var $_ci_scaff_table = FALSE; - var $_ci_last_handle = NULL; - var $_ci_last_params = NULL; /** * Constructor @@ -68,48 +66,6 @@ class Controller extends CI_Base { // -------------------------------------------------------------------- - /** - * Initialization Handler - * - * Designed to be called from the class files themselves. - * See: http://www.codeigniter.com/user_guide/general/creating_libraries.html - * - * @access public - * @param string class name - * @param string variable name - * @param mixed any additional parameters - * @return void - */ - function init_class($class, $varname = '', $params = NULL) - { - // First figure out what variable we're going to assign the class to - if ($varname == '') - { - $varname = ( ! is_null($this->_ci_last_handle)) ? $this->_ci_last_handle : strtolower(str_replace('CI_', '', $class)); - } - - // Are there any parameters? - if ($params === NULL AND $this->_ci_last_params !== NULL) - { - $params = $this->_ci_last_params; - } - - // Instantiate the class - if ( ! is_null($params)) - { - $this->$varname = new $class($params); - } - else - { - $this->$varname = new $class; - } - - $this->_ci_last_params = NULL; - $this->_ci_last_handle = NULL; - } - - // -------------------------------------------------------------------- - /** * Initialization Handler * @@ -120,15 +76,21 @@ class Controller extends CI_Base { * @param mixed any additional parameters * @return void */ - function _ci_init_class($class, $params = NULL) + function _ci_load_class($class, $params = NULL) { // Prep the class name $class = strtolower(str_replace(EXT, '', $class)); - - // These are used by $this->init_class() above. - // They lets us dynamically set the object name and pass parameters - $this->_ci_last_handle = $class; - $this->_ci_last_params = $params; + + // Is this a class extension request? + if (substr($class, 0, 3) == 'my_') + { + $class = preg_replace("/my_(.+)/", "\\1", $class); + $extend = TRUE; + } + else + { + $extend = FALSE; + } // Does THIS file (Controller.php) contain an initialization // function that maps to the requested class? @@ -150,30 +112,101 @@ class Controller extends CI_Base { return TRUE; } - // Lets search for the requested library file and load it. - // We'll assume that the file we load contains a call to - // $obj->init_class() so that the class can get instantiated. - // For backward compatibility we'll test for filenames that are - // both uppercase and lower. - foreach (array(ucfirst($class), $class) as $filename) + // Are we extending one of the base classes? + if ($extend == TRUE) { - for ($i = 1; $i < 3; $i++) + // Load the requested library from the main system/libraries folder + if (file_exists(BASEPATH.'libraries/'.ucfirst($class).EXT)) { - $path = ($i % 2) ? APPPATH : BASEPATH; + include_once(BASEPATH.'libraries/'.ucfirst($class).EXT); + } - if (file_exists($path.'libraries/'.$filename.EXT)) + // Now look for a matching library + foreach (array(ucfirst($class), $class) as $filename) + { + if (file_exists(APPPATH.'libraries/'.$filename.EXT)) { - include_once($path.'libraries/'.$filename.EXT); - return TRUE; + include_once(APPPATH.'libraries/'.$filename.EXT); + } + } + + return $this->_ci_init_class($filename, 'MY_', $params); + } + else + { + // Lets search for the requested library file and load it. + // For backward compatibility we'll test for filenames that are + // both uppercase and lower. + foreach (array(ucfirst($class), $class) as $filename) + { + for ($i = 1; $i < 3; $i++) + { + $path = ($i % 2) ? APPPATH : BASEPATH; + + if (file_exists($path.'libraries/'.$filename.EXT)) + { + include_once($path.'libraries/'.$filename.EXT); + return $this->_ci_init_class($filename, '', $params); + } } } - } // 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 class: ".$class); } + + // -------------------------------------------------------------------- + + /** + * Instantiates a class + * + * @access private + * @param string + * @param string + * @return null + */ + function _ci_init_class($class, $prefix = '', $config = NULL) + { + // Is there an associated config file for this class? + + if ($config == NULL) + { + if (file_exists(APPPATH.'config/'.$class.EXT)) + { + include_once(APPPATH.'config/'.$class.EXT); + } + } + + if ($prefix == '') + { + $name = ( ! class_exists($class)) ? 'CI_'.$class : $class; + } + else + { + $name = $prefix.ucfirst($class); + } + + $remap = array( + 'DB_export' => 'dbexport', + 'DB_utility' => 'dbutility', + 'Encryption' => 'encrypt', + 'Unit_test' => 'unit' + ); + + $varname = ( ! isset($remap[$class])) ? $class : $remap[$class]; + + // Instantiate the class + if ($config !== NULL) + { + $this->$varname = new $name($config); + } + else + { + $this->$varname = new $name; + } + } // -------------------------------------------------------------------- @@ -305,7 +338,7 @@ class Controller extends CI_Base { { if ( ! in_array($item, $exceptions)) { - $this->_ci_init_class($item); + $this->_ci_load_class($item); } else { @@ -334,10 +367,10 @@ class Controller extends CI_Base { foreach (array('Config', 'Input', 'Benchmark', 'URI', 'Output') as $val) { $class = strtolower($val); - $this->$class =& _load_class('CI_'.$val); + $this->$class =& _load_class($val); } - $this->lang =& _load_class('CI_Language'); + $this->lang =& _load_class('Language'); // In PHP 4 the Controller class is a child of CI_Loader. // In PHP 5 we run it as its own class. @@ -529,7 +562,7 @@ class Controller extends CI_Base { } $this->_ci_init_database("", FALSE, TRUE); - $this->_ci_init_class('pagination'); + $this->_ci_load_class('pagination'); require_once(BASEPATH.'scaffolding/Scaffolding'.EXT); $this->scaff = new Scaffolding($this->_ci_scaff_table); $this->scaff->$method(); diff --git a/system/libraries/Email.php b/system/libraries/Email.php index fd3fb8f17..5b991d1fa 100644 --- a/system/libraries/Email.php +++ b/system/libraries/Email.php @@ -13,17 +13,6 @@ * @filesource */ -// INITIALIZE THE CLASS --------------------------------------------------- - -$config = array(); -if (file_exists(APPPATH.'config/email'.EXT)) -{ - include_once(APPPATH.'config/email'.EXT); -} - -$obj =& get_instance(); -$obj->init_class('CI_Email', 'email', $config); - // ------------------------------------------------------------------------ /** diff --git a/system/libraries/Encrypt.php b/system/libraries/Encrypt.php index 6a3ca17b0..abc769460 100644 --- a/system/libraries/Encrypt.php +++ b/system/libraries/Encrypt.php @@ -12,11 +12,6 @@ * @since Version 1.0 * @filesource */ - -// INITIALIZE THE CLASS --------------------------------------------------- - -$obj =& get_instance(); -$obj->init_class('CI_Encrypt'); // ------------------------------------------------------------------------ diff --git a/system/libraries/Hooks.php b/system/libraries/Hooks.php index 7ff0592ff..69ca1a9f1 100644 --- a/system/libraries/Hooks.php +++ b/system/libraries/Hooks.php @@ -41,7 +41,7 @@ class CI_Hooks { { log_message('debug', "Hooks Class Initialized"); - $CFG =& _load_class('CI_Config'); + $CFG =& _load_class('Config'); // If hooks are not enabled in the config file // there is nothing else to do diff --git a/system/libraries/Image_lib.php b/system/libraries/Image_lib.php index 4962760eb..18e3253f7 100644 --- a/system/libraries/Image_lib.php +++ b/system/libraries/Image_lib.php @@ -13,17 +13,6 @@ * @filesource */ -// INITIALIZE THE CLASS --------------------------------------------------- - -$config = array(); -if (file_exists(APPPATH.'config/image_lib'.EXT)) -{ - include_once(APPPATH.'config/image_lib'.EXT); -} - -$obj =& get_instance(); -$obj->init_class('CI_Image_lib', '', $config); - // ------------------------------------------------------------------------ /** diff --git a/system/libraries/Input.php b/system/libraries/Input.php index dbf939b18..ad7b0c571 100644 --- a/system/libraries/Input.php +++ b/system/libraries/Input.php @@ -42,7 +42,7 @@ class CI_Input { */ function CI_Input() { - $CFG =& _load_class('CI_Config'); + $CFG =& _load_class('Config'); $this->use_xss_clean = ($CFG->item('global_xss_filtering') === TRUE) ? TRUE : FALSE; $this->allow_get_array = ($CFG->item('enable_query_strings') === TRUE) ? TRUE : FALSE; diff --git a/system/libraries/Loader.php b/system/libraries/Loader.php index 90d824049..fff9e78d3 100644 --- a/system/libraries/Loader.php +++ b/system/libraries/Loader.php @@ -71,7 +71,7 @@ class CI_Loader { return; $obj =& get_instance(); - $obj->_ci_init_class($class, $param); + $obj->_ci_load_class($class, $param); $obj->_ci_assign_to_models(); } diff --git a/system/libraries/Output.php b/system/libraries/Output.php index 5a158245f..1c3f0d604 100644 --- a/system/libraries/Output.php +++ b/system/libraries/Output.php @@ -237,8 +237,8 @@ class CI_Output { */ function _display_cache(&$CFG, &$RTR) { - $CFG =& _load_class('CI_Config'); - $RTR =& _load_class('CI_Router'); + $CFG =& _load_class('Config'); + $RTR =& _load_class('Router'); $cache_path = ($CFG->item('cache_path') == '') ? BASEPATH.'cache/' : $CFG->item('cache_path'); diff --git a/system/libraries/Pagination.php b/system/libraries/Pagination.php index cd55d56e0..867d214fc 100644 --- a/system/libraries/Pagination.php +++ b/system/libraries/Pagination.php @@ -12,17 +12,6 @@ * @since Version 1.0 * @filesource */ - -// INITIALIZE THE CLASS --------------------------------------------------- - -$config = array(); -if (file_exists(APPPATH.'config/pagination'.EXT)) -{ - include_once(APPPATH.'config/pagination'.EXT); -} - -$obj =& get_instance(); -$obj->init_class('CI_Pagination', '', $config); // ------------------------------------------------------------------------ diff --git a/system/libraries/Parser.php b/system/libraries/Parser.php index 76182271f..42e78b0ee 100644 --- a/system/libraries/Parser.php +++ b/system/libraries/Parser.php @@ -12,11 +12,6 @@ * @since Version 1.0 * @filesource */ - -// INITIALIZE THE CLASS --------------------------------------------------- - -$obj =& get_instance(); -$obj->init_class('CI_Parser'); // ------------------------------------------------------------------------ diff --git a/system/libraries/Router.php b/system/libraries/Router.php index 34a2512a6..c056530a3 100644 --- a/system/libraries/Router.php +++ b/system/libraries/Router.php @@ -33,6 +33,7 @@ class CI_Router { var $segments = array(); var $rsegments = array(); var $routes = array(); + var $error_routes = array(); var $class = ''; var $method = 'index'; var $directory = ''; @@ -47,7 +48,7 @@ class CI_Router { */ function CI_Router() { - $this->config =& _load_class('CI_Config'); + $this->config =& _load_class('Config'); $this->_set_route_mapping(); log_message('debug', "Router Class Initialized"); } @@ -87,8 +88,8 @@ class CI_Router { // 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']); - + $this->default_controller = ( ! isset($this->routes['default_controller']) OR $this->routes['default_controller'] == '') ? FALSE : strtolower($this->routes['default_controller']); + // Fetch the complete URI string $this->uri_string = $this->_get_uri_string(); @@ -138,7 +139,6 @@ class CI_Router { // Re-index the segment array so that it starts with 1 rather than 0 $this->_reindex_segments(); } - // END _set_route_mapping() // -------------------------------------------------------------------- @@ -185,7 +185,6 @@ class CI_Router { // identical to $this->segments $this->rsegments = $segments; } - // END _compile_segments() // -------------------------------------------------------------------- @@ -240,7 +239,6 @@ class CI_Router { // Can't find the requested controller... show_404(); } - // END _validate_segments() // -------------------------------------------------------------------- /** @@ -280,7 +278,6 @@ class CI_Router { unset($this->rsegments[0]); } } - // END _reindex_segments() // -------------------------------------------------------------------- @@ -333,7 +330,6 @@ class CI_Router { return getenv($uri); } } - // END _get_uri_string() // -------------------------------------------------------------------- @@ -381,7 +377,6 @@ class CI_Router { return $parsed_uri; } - // END _parse_request_uri() // -------------------------------------------------------------------- @@ -403,7 +398,6 @@ class CI_Router { } return $str; } - // END _filter_uri() // -------------------------------------------------------------------- @@ -461,7 +455,6 @@ class CI_Router { // matching route so we'll set the site default route $this->_compile_segments($this->segments); } - // END set_method() // -------------------------------------------------------------------- @@ -476,7 +469,6 @@ class CI_Router { { $this->class = $class; } - // END set_class() // -------------------------------------------------------------------- @@ -490,7 +482,6 @@ class CI_Router { { return $this->class; } - // END fetch_class() // -------------------------------------------------------------------- @@ -505,7 +496,6 @@ class CI_Router { { $this->method = $method; } - // END set_method() // -------------------------------------------------------------------- @@ -519,7 +509,6 @@ class CI_Router { { return $this->method; } - // END fetch_method() // -------------------------------------------------------------------- @@ -534,7 +523,6 @@ class CI_Router { { $this->directory = $dir.'/'; } - // END set_directory() // -------------------------------------------------------------------- @@ -548,7 +536,6 @@ class CI_Router { { return $this->directory; } - // END fetch_directory() } // END Router Class diff --git a/system/libraries/Session.php b/system/libraries/Session.php index 76acbfea9..28e469da7 100644 --- a/system/libraries/Session.php +++ b/system/libraries/Session.php @@ -12,11 +12,6 @@ * @since Version 1.0 * @filesource */ - -// INITIALIZE THE CLASS --------------------------------------------------- - -$obj =& get_instance(); -$obj->init_class('CI_Session'); // ------------------------------------------------------------------------ diff --git a/system/libraries/Trackback.php b/system/libraries/Trackback.php index 9b6138453..8b6cce16d 100644 --- a/system/libraries/Trackback.php +++ b/system/libraries/Trackback.php @@ -12,11 +12,6 @@ * @since Version 1.0 * @filesource */ - -// INITIALIZE THE CLASS --------------------------------------------------- - -$obj =& get_instance(); -$obj->trackback =& new CI_Trackback(); // ------------------------------------------------------------------------ diff --git a/system/libraries/URI.php b/system/libraries/URI.php index 89ca42e44..80b112660 100644 --- a/system/libraries/URI.php +++ b/system/libraries/URI.php @@ -42,7 +42,7 @@ class CI_URI { */ function CI_URI() { - $this->router =& _load_class('CI_Router'); + $this->router =& _load_class('Router'); log_message('debug', "URI Class Initialized"); } diff --git a/system/libraries/Unit_test.php b/system/libraries/Unit_test.php index 04c3c199b..b2f4bf8cd 100644 --- a/system/libraries/Unit_test.php +++ b/system/libraries/Unit_test.php @@ -13,11 +13,6 @@ * @filesource */ -// INITIALIZE THE CLASS --------------------------------------------------- - -$obj =& get_instance(); -$obj->init_class('CI_Unit_test'); - // ------------------------------------------------------------------------ /** diff --git a/system/libraries/Upload.php b/system/libraries/Upload.php index 3a6a6fc34..091c6c30d 100644 --- a/system/libraries/Upload.php +++ b/system/libraries/Upload.php @@ -12,17 +12,6 @@ * @since Version 1.0 * @filesource */ - -// INITIALIZE THE CLASS --------------------------------------------------- - -$config = array(); -if (file_exists(APPPATH.'config/upload'.EXT)) -{ - include_once(APPPATH.'config/upload'.EXT); -} - -$obj =& get_instance(); -$obj->init_class('CI_Upload', '', $config); // ------------------------------------------------------------------------ diff --git a/system/libraries/Validation.php b/system/libraries/Validation.php index 34cacd5d8..80ee6a533 100644 --- a/system/libraries/Validation.php +++ b/system/libraries/Validation.php @@ -12,11 +12,6 @@ * @since Version 1.0 * @filesource */ - -// INITIALIZE THE CLASS --------------------------------------------------- - -$obj =& get_instance(); -$obj->init_class('CI_Validation'); // ------------------------------------------------------------------------ diff --git a/system/libraries/Xmlrpc.php b/system/libraries/Xmlrpc.php index 24f79f2ba..f90785430 100644 --- a/system/libraries/Xmlrpc.php +++ b/system/libraries/Xmlrpc.php @@ -18,10 +18,6 @@ if ( ! function_exists('xml_parser_create')) show_error('Your PHP installation does not support XML'); } -// INITIALIZE THE CLASS --------------------------------------------------- - -$obj =& get_instance(); -$obj->init_class('CI_Xmlrpc'); // ------------------------------------------------------------------------ diff --git a/system/libraries/Xmlrpcs.php b/system/libraries/Xmlrpcs.php index f41437342..b47104857 100644 --- a/system/libraries/Xmlrpcs.php +++ b/system/libraries/Xmlrpcs.php @@ -23,11 +23,6 @@ if ( ! class_exists('CI_Xmlrpc')) show_error('You must load the Xmlrpc class before loading the Xmlrpcs class in order to create a server.'); } -// INITIALIZE THE CLASS --------------------------------------------------- - -$obj =& get_instance(); -$obj->init_class('CI_Xmlrpcs'); - // ------------------------------------------------------------------------ /** -- cgit v1.2.3-24-g4f1b From 4ce59da7905eca21a6cc3be04adfbcab672a9969 Mon Sep 17 00:00:00 2001 From: admin Date: Thu, 28 Sep 2006 07:45:59 +0000 Subject: --- system/libraries/Controller.php | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) (limited to 'system') diff --git a/system/libraries/Controller.php b/system/libraries/Controller.php index aa7b87b00..f00a7262b 100644 --- a/system/libraries/Controller.php +++ b/system/libraries/Controller.php @@ -219,6 +219,20 @@ class Controller extends CI_Base { */ function _ci_init_model($model, $name = '', $db_conn = FALSE) { + // Is the model in a sub-folder? + // If so, parse out the filename and path. + if (strpos($model, '/') === FALSE) + { + $path = ''; + } + else + { + $x = explode('/', $model); + $model = end($x); + unset($x[count($x)-1]); + $path = implode('/', $x).'/'; + } + if ($name == '') { $name = $model; @@ -237,11 +251,11 @@ class Controller extends CI_Base { $model = strtolower($model); - if ( ! file_exists(APPPATH.'models/'.$model.EXT)) + if ( ! file_exists(APPPATH.'models/'.$path.$model.EXT)) { show_error('Unable to locate the model you have specified: '.$model); } - + if ($db_conn !== FALSE) { if ($db_conn === TRUE) @@ -255,7 +269,7 @@ class Controller extends CI_Base { require_once(BASEPATH.'libraries/Model'.EXT); } - require_once(APPPATH.'models/'.$model.EXT); + require_once(APPPATH.'models/'.$path.$model.EXT); $model = ucfirst($model); $this->$name = new $model(); -- cgit v1.2.3-24-g4f1b From e721cc7c81af84dcabce2992fa693ce36b605a19 Mon Sep 17 00:00:00 2001 From: admin Date: Thu, 28 Sep 2006 16:47:05 +0000 Subject: --- system/libraries/Unit_test.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'system') diff --git a/system/libraries/Unit_test.php b/system/libraries/Unit_test.php index b2f4bf8cd..d3e151328 100644 --- a/system/libraries/Unit_test.php +++ b/system/libraries/Unit_test.php @@ -57,8 +57,8 @@ class CI_Unit_test { if ($this->active == FALSE) return; - if (in_array($expected, array('is_string', 'is_bool', 'is_true', 'is_false', 'is_int', 'is_numeric', 'is_float', 'is_double', 'is_array', 'is_null'))) - { + if ($expected !== 0 AND in_array($expected, array('is_string', 'is_bool', 'is_true', 'is_false', 'is_int', 'is_numeric', 'is_float', 'is_double', 'is_array', 'is_null'))) + { $expected = str_replace('is_float', 'is_double', $expected); $result = ($expected($test)) ? TRUE : FALSE; $extype = str_replace(array('true', 'false'), 'bool', str_replace('is_', '', $expected)); -- cgit v1.2.3-24-g4f1b From ee54c112bfb488f833fa032758b817e1bb2c1d7d Mon Sep 17 00:00:00 2001 From: admin Date: Thu, 28 Sep 2006 17:13:38 +0000 Subject: --- system/codeigniter/CodeIgniter.php | 2 +- system/database/DB_active_rec.php | 4 ++-- system/database/DB_driver.php | 4 ++-- system/helpers/typography_helper.php | 26 +++++++++++++------------- system/libraries/Calendar.php | 4 ++-- system/libraries/Config.php | 2 +- system/libraries/Controller.php | 6 +++--- system/libraries/Email.php | 6 +++--- system/libraries/Image_lib.php | 2 +- system/libraries/Language.php | 2 +- system/libraries/Unit_test.php | 2 +- system/libraries/Upload.php | 4 ++-- system/libraries/Validation.php | 6 +++--- system/libraries/Xmlrpc.php | 2 +- 14 files changed, 36 insertions(+), 36 deletions(-) (limited to 'system') diff --git a/system/codeigniter/CodeIgniter.php b/system/codeigniter/CodeIgniter.php index 4ac03820a..a4f18b0e1 100644 --- a/system/codeigniter/CodeIgniter.php +++ b/system/codeigniter/CodeIgniter.php @@ -145,7 +145,7 @@ $method = $RTR->fetch_method(); if ( ! class_exists($class) OR $method == 'controller' OR substr($method, 0, 1) == '_' - OR in_array($method, get_class_methods('Controller')) + OR in_array($method, get_class_methods('Controller'), TRUE) ) { show_404(); diff --git a/system/database/DB_active_rec.php b/system/database/DB_active_rec.php index eb9f14a92..1fa4f9557 100644 --- a/system/database/DB_active_rec.php +++ b/system/database/DB_active_rec.php @@ -125,7 +125,7 @@ class CI_DB_active_record extends CI_DB_driver { { $type = strtoupper(trim($type)); - if ( ! in_array($type, array('LEFT', 'RIGHT', 'OUTER', 'INNER', 'LEFT OUTER', 'RIGHT OUTER'))) + if ( ! in_array($type, array('LEFT', 'RIGHT', 'OUTER', 'INNER', 'LEFT OUTER', 'RIGHT OUTER'), TRUE)) { $type = ''; } @@ -390,7 +390,7 @@ class CI_DB_active_record extends CI_DB_driver { { if (trim($direction) != '') { - $direction = (in_array(strtoupper(trim($direction)), array('ASC', 'DESC', 'RAND()'))) ? ' '.$direction : ' ASC'; + $direction = (in_array(strtoupper(trim($direction)), array('ASC', 'DESC', 'RAND()'), TRUE)) ? ' '.$direction : ' ASC'; } $this->ar_orderby[] = $orderby.$direction; diff --git a/system/database/DB_driver.php b/system/database/DB_driver.php index d25135ea6..94db84bbf 100644 --- a/system/database/DB_driver.php +++ b/system/database/DB_driver.php @@ -726,8 +726,8 @@ class CI_DB_driver { } else { - $args = (func_num_args() > 1) ? array_shift(func_get_args()) : null; - + $args = (func_num_args() > 1) ? array_splice(func_get_args(), 1) : null; + return call_user_func_array($function, $args); } } diff --git a/system/helpers/typography_helper.php b/system/helpers/typography_helper.php index 6a5495239..65924f911 100644 --- a/system/helpers/typography_helper.php +++ b/system/helpers/typography_helper.php @@ -275,13 +275,13 @@ class Auto_typography { $one_before = substr($str, $start+$current-1, 1); $one_after = substr($str, $start+$current+2, 1); - if ( ! in_array($one_after, $space) && $one_after != "<") + if ( ! in_array($one_after, $space, TRUE) && $one_after != "<") { $str = str_replace( $one_before."\"'".$one_after, $one_before."“‘".$one_after, $str); } - elseif ( ! in_array($one_before, $space) && (in_array($one_after, $space) OR $one_after == '<')) + elseif ( ! in_array($one_before, $space, TRUE) && (in_array($one_after, $space, TRUE) OR $one_after == '<')) { $str = str_replace( $one_before."\"'".$one_after, $one_before."”’".$one_after, @@ -302,13 +302,13 @@ class Auto_typography { $one_before = substr($str, $start+$current-1, 1); $one_after = substr($str, $start+$current+2, 1); - if ( in_array($one_before, $space) && ! in_array($one_after, $space) && $one_after != "<") + if ( in_array($one_before, $space, TRUE) && ! in_array($one_after, $space, TRUE) && $one_after != "<") { $str = str_replace( $one_before."'\"".$one_after, $one_before."‘“".$one_after, $str); } - elseif ( ! in_array($one_before, $space) && $one_before != ">") + elseif ( ! in_array($one_before, $space, TRUE) && $one_before != ">") { $str = str_replace( $one_before."'\"".$one_after, $one_before."’”".$one_after, @@ -323,7 +323,7 @@ class Auto_typography { { for ($i=0, $s=sizeof($matches['0']); $i < $s; ++$i) { - if ( ! in_array($matches['1'][$i], $space) && ! in_array($matches['3'][$i], $space)) + if ( ! in_array($matches['1'][$i], $space, TRUE) && ! in_array($matches['3'][$i], $space, TRUE)) { $str = str_replace( $matches['0'][$i], $matches['1'][$i]."“".$matches['2'][$i]."”".$matches['3'][$i], @@ -336,7 +336,7 @@ class Auto_typography { { for ($i=0, $s=sizeof($matches['0']); $i < $s; ++$i) { - if ( ! in_array($matches['1'][$i], $space) && ! in_array($matches['3'][$i], $space)) + if ( ! in_array($matches['1'][$i], $space, TRUE) && ! in_array($matches['3'][$i], $space, TRUE)) { $str = str_replace( $matches['0'][$i], $matches['1'][$i]."‘".$matches['2'][$i]."’".$matches['3'][$i], @@ -357,7 +357,7 @@ class Auto_typography { $one_before = substr($str, $start+$current-1, 1); $one_after = substr($str, $start+$current+1, 1); - if ( ! in_array($one_before, $space) && ! in_array($one_after, $space)) + if ( ! in_array($one_before, $space, TRUE) && ! in_array($one_after, $space, TRUE)) { $str = str_replace( $one_before."'".$one_after, $one_before."’".$one_after, @@ -380,9 +380,9 @@ class Auto_typography { $two_before = substr($str, $start+$current-2, 1); $two_after = substr($str, $start+$current+3, 1); - if (( ! in_array($one_before, $space) && ! in_array($one_after, $space)) + if (( ! in_array($one_before, $space, TRUE) && ! in_array($one_after, $space, TRUE)) OR - ( ! in_array($two_before, $space) && ! in_array($two_after, $space) && $one_before == ' ' && $one_after == ' ') + ( ! in_array($two_before, $space, TRUE) && ! in_array($two_after, $space, TRUE) && $one_before == ' ' && $one_after == ' ') ) { $str = str_replace( $two_before.$one_before."--".$one_after.$two_after, @@ -413,13 +413,13 @@ class Auto_typography { $one_before = substr($str, $start+$current-1, 1); $one_after = substr($str, $start+$current+1, 1); - if ( ! in_array($one_after, $space)) + if ( ! in_array($one_after, $space, TRUE)) { $str = str_replace( $one_before.'"'.$one_after, $one_before."“".$one_after, $str); } - elseif( ! in_array($one_before, $space)) + elseif( ! in_array($one_before, $space, TRUE)) { $str = str_replace( $one_before."'".$one_after, $one_before."”".$one_after, @@ -440,13 +440,13 @@ class Auto_typography { $one_before = substr($str, $start+$current-1, 1); $one_after = substr($str, $start+$current+1, 1); - if ( ! in_array($one_after, $space)) + if ( ! in_array($one_after, $space, TRUE)) { $str = str_replace( $one_before."'".$one_after, $one_before."‘".$one_after, $str); } - elseif( ! in_array($one_before, $space)) + elseif( ! in_array($one_before, $space, TRUE)) { $str = str_replace( $one_before."'".$one_after, $one_before."’".$one_after, diff --git a/system/libraries/Calendar.php b/system/libraries/Calendar.php index 8c7d95aa5..8cf151703 100644 --- a/system/libraries/Calendar.php +++ b/system/libraries/Calendar.php @@ -48,7 +48,7 @@ class CI_Calendar { function CI_Calendar() { $this->obj =& get_instance(); - if ( ! in_array('calendar_lang'.EXT, $this->obj->lang->is_loaded)) + if ( ! in_array('calendar_lang'.EXT, $this->obj->lang->is_loaded, TRUE)) { $this->obj->lang->load('calendar'); } @@ -458,7 +458,7 @@ class CI_Calendar { } else { - if (in_array($val, $today)) + if (in_array($val, $today, TRUE)) { $this->temp[$val] = $this->temp[str_replace('_today', '', $val)]; } diff --git a/system/libraries/Config.php b/system/libraries/Config.php index 108c94ab7..26770cc4f 100644 --- a/system/libraries/Config.php +++ b/system/libraries/Config.php @@ -63,7 +63,7 @@ class CI_Config { { $file = ($file == '') ? 'config' : str_replace(EXT, '', $file); - if (in_array($file, $this->is_loaded)) + if (in_array($file, $this->is_loaded, TRUE)) { return TRUE; } diff --git a/system/libraries/Controller.php b/system/libraries/Controller.php index f00a7262b..ff914d131 100644 --- a/system/libraries/Controller.php +++ b/system/libraries/Controller.php @@ -239,7 +239,7 @@ class Controller extends CI_Base { } $obj =& get_instance(); - if (in_array($name, $obj->_ci_models)) + if (in_array($name, $obj->_ci_models, TRUE)) { return; } @@ -350,7 +350,7 @@ class Controller extends CI_Base { foreach ($autoload['libraries'] as $item) { - if ( ! in_array($item, $exceptions)) + if ( ! in_array($item, $exceptions, TRUE)) { $this->_ci_load_class($item); } @@ -566,7 +566,7 @@ class Controller extends CI_Base { if (class_exists('Scaffolding')) return; - if ( ! in_array($this->uri->segment(3), array('add', 'insert', 'edit', 'update', 'view', 'delete', 'do_delete'))) + if ( ! in_array($this->uri->segment(3), array('add', 'insert', 'edit', 'update', 'view', 'delete', 'do_delete'), TRUE)) { $method = 'view'; } diff --git a/system/libraries/Email.php b/system/libraries/Email.php index 5b991d1fa..55edd6216 100644 --- a/system/libraries/Email.php +++ b/system/libraries/Email.php @@ -467,7 +467,7 @@ class CI_Email { */ function set_protocol($protocol = 'mail') { - $this->protocol = ( ! in_array($protocol, $this->_protocols)) ? 'mail' : strtolower($protocol); + $this->protocol = ( ! in_array($protocol, $this->_protocols, TRUE)) ? 'mail' : strtolower($protocol); } // END set_protocol() @@ -564,7 +564,7 @@ class CI_Email { function _get_protocol($return = true) { $this->protocol = strtolower($this->protocol); - $this->protocol = ( ! in_array($this->protocol, $this->_protocols)) ? 'mail' : $this->protocol; + $this->protocol = ( ! in_array($this->protocol, $this->_protocols, TRUE)) ? 'mail' : $this->protocol; if ($return == true) return $this->protocol; @@ -584,7 +584,7 @@ class CI_Email { { $this->_encoding = ( ! in_array($this->_encoding, $this->_bit_depths)) ? '7bit' : $this->_encoding; - if ( ! in_array($this->charset, $this->_base_charsets)) + if ( ! in_array($this->charset, $this->_base_charsets, TRUE)) $this->_encoding = "8bit"; if ($return == true) diff --git a/system/libraries/Image_lib.php b/system/libraries/Image_lib.php index 18e3253f7..ca1d7478b 100644 --- a/system/libraries/Image_lib.php +++ b/system/libraries/Image_lib.php @@ -398,7 +398,7 @@ class CI_Image_lib { // Allowed rotation values $degs = array(90, 180, 270, 'vrt', 'hor'); - if ($this->rotation_angle == '' OR ! in_array($this->rotation_angle, $degs)) + if ($this->rotation_angle == '' OR ! in_array($this->rotation_angle, $degs, TRUE)) { $this->set_error('imglib_rotation_angle_required'); return FALSE; diff --git a/system/libraries/Language.php b/system/libraries/Language.php index 41dab46f4..dabfd4145 100644 --- a/system/libraries/Language.php +++ b/system/libraries/Language.php @@ -54,7 +54,7 @@ class CI_Language { { $langfile = str_replace(EXT, '', str_replace('_lang.', '', $langfile)).'_lang'.EXT; - if (in_array($langfile, $this->is_loaded)) + if (in_array($langfile, $this->is_loaded, TRUE)) { return; } diff --git a/system/libraries/Unit_test.php b/system/libraries/Unit_test.php index d3e151328..78b92edb2 100644 --- a/system/libraries/Unit_test.php +++ b/system/libraries/Unit_test.php @@ -57,7 +57,7 @@ class CI_Unit_test { if ($this->active == FALSE) return; - if ($expected !== 0 AND in_array($expected, array('is_string', 'is_bool', 'is_true', 'is_false', 'is_int', 'is_numeric', 'is_float', 'is_double', 'is_array', 'is_null'))) + if (in_array($expected, array('is_string', 'is_bool', 'is_true', 'is_false', 'is_int', 'is_numeric', 'is_float', 'is_double', 'is_array', 'is_null'), TRUE)) { $expected = str_replace('is_float', 'is_double', $expected); $result = ($expected($test)) ? TRUE : FALSE; diff --git a/system/libraries/Upload.php b/system/libraries/Upload.php index 091c6c30d..37fccdfd8 100644 --- a/system/libraries/Upload.php +++ b/system/libraries/Upload.php @@ -454,7 +454,7 @@ class CI_Upload { ); - return (in_array($this->file_type, $img_mimes)) ? TRUE : FALSE; + return (in_array($this->file_type, $img_mimes, TRUE)) ? TRUE : FALSE; } // -------------------------------------------------------------------- @@ -479,7 +479,7 @@ class CI_Upload { if (is_array($mime)) { - if (in_array($this->file_type, $mime)) + if (in_array($this->file_type, $mime, TRUE)) { return TRUE; } diff --git a/system/libraries/Validation.php b/system/libraries/Validation.php index 80ee6a533..7db67a3e1 100644 --- a/system/libraries/Validation.php +++ b/system/libraries/Validation.php @@ -187,7 +187,7 @@ class CI_Validation { $ex = explode('|', $rules); // Is the field required? If not, if the field is blank we'll move on to the next text - if ( ! in_array('required', $ex) AND strpos($rules, 'callback_') === FALSE) + if ( ! in_array('required', $ex, TRUE) AND strpos($rules, 'callback_') === FALSE) { if ( ! isset($_POST[$field]) OR $_POST[$field] == '') { @@ -206,7 +206,7 @@ class CI_Validation { */ if ( ! isset($_POST[$field])) { - if (in_array('isset', $ex) OR in_array('required', $ex)) + if (in_array('isset', $ex, TRUE) OR in_array('required', $ex)) { if ( ! isset($this->_error_messages['isset'])) { @@ -268,7 +268,7 @@ class CI_Validation { $result = $this->obj->$rule($_POST[$field], $param); // If the field isn't required and we just processed a callback we'll move on... - if ( ! in_array('required', $ex) AND $result !== FALSE) + if ( ! in_array('required', $ex, TRUE) AND $result !== FALSE) { continue 2; } diff --git a/system/libraries/Xmlrpc.php b/system/libraries/Xmlrpc.php index f90785430..4cb16f74e 100644 --- a/system/libraries/Xmlrpc.php +++ b/system/libraries/Xmlrpc.php @@ -854,7 +854,7 @@ class XML_RPC_Message extends CI_Xmlrpc else { // not top level element: see if parent is OK - if (!in_array($this->xh[$the_parser]['stack'][0], $this->valid_parents[$name])) + if (!in_array($this->xh[$the_parser]['stack'][0], $this->valid_parents[$name], TRUE)) { $this->xh[$the_parser]['isf'] = 2; $this->xh[$the_parser]['isf_reason'] = "XML-RPC element $name cannot be child of ".$this->xh[$the_parser]['stack'][0]; -- cgit v1.2.3-24-g4f1b From 4a2ed69c3af500ca51bddcc9b6c54bebb2bfeae8 Mon Sep 17 00:00:00 2001 From: admin Date: Fri, 29 Sep 2006 01:14:52 +0000 Subject: --- system/codeigniter/Common.php | 31 ++++++++++++++-------- system/database/drivers/oci8/oci8_utility.php | 2 +- .../database/drivers/postgre/postgre_utility.php | 8 +++--- system/database/drivers/sqlite/sqlite_utility.php | 19 +++++++++---- system/libraries/Controller.php | 1 - 5 files changed, 39 insertions(+), 22 deletions(-) (limited to 'system') diff --git a/system/codeigniter/Common.php b/system/codeigniter/Common.php index 24e6042cc..124ad9a38 100644 --- a/system/codeigniter/Common.php +++ b/system/codeigniter/Common.php @@ -37,6 +37,8 @@ * previously been instantiated the variable is returned. * * @access public +* @param string the class name being requested +* @param bool optional flag that lets classes get loaded but not instantiated * @return object */ function &_load_class($class, $instantiate = TRUE) @@ -58,7 +60,7 @@ function &_load_class($class, $instantiate = TRUE) // If the requested class does not exist in the application/libraries // folder we'll load the native class from the system/libraries folder. - + $is_subclass = FALSE; if ( ! file_exists(APPPATH.'libraries/'.$class.EXT)) { @@ -67,20 +69,27 @@ function &_load_class($class, $instantiate = TRUE) else { // A core class can either be extended or replaced by putting an - // identially named file in the application/libraries folder. - // We need to need to determine if the class being requested is - // a sub-class or an independent instance so we'll open the file, - // read the top portion of it. If the class extends the base class - // we need to load it's parent. If it doesn't extend the base we'll - // only load the requested class. + // identically named file in the application/libraries folder.  + // We need to determine, however, if the class being requested is + // a sub-class of an existing library or an independent instance + // since each needs to be handled slightly differently.  + // To do this we'll open the requested class and read the top portion + // of it. If the class extends a base class we will load the base first. + // If it doesn't extend the base we'll only load the requested class. // Note: I'm not thrilled with this approach since it requires us to - // read the file, but I can't think of any other way to allow classes - // to be extended on-the-fly. I did benchmark the difference with and - // without the file reading and I'm not seeing a perceptable difference. + // read the top part of the file (I set a character limit of 5000 bytes, + // which correlates to roughly the first 100 lines of code), but + // I can't think of a better way to allow classes to be extended or + // replaced on-the-fly with nothing required for the user to do + // except write the declaration.  Fortunately PHP is ridiculously fast + // at file reading operations so I'm not able to discern a performance + // hit based on my benchmarks, assuming a reasonable number of core + // files are being extended, which will usually be the case. $fp = fopen(APPPATH.'libraries/'.$class.EXT, "rb"); - if (preg_match("/MY_".$class."\s+extends\s+CI_".$class."/", fread($fp, '8000'))) + + if (preg_match("/MY_".$class."\s+extends\s+CI_".$class."/", fread($fp, '6000'))) { require(BASEPATH.'libraries/'.$class.EXT); require(APPPATH.'libraries/'.$class.EXT); diff --git a/system/database/drivers/oci8/oci8_utility.php b/system/database/drivers/oci8/oci8_utility.php index dc259ac39..4d267dc6a 100644 --- a/system/database/drivers/oci8/oci8_utility.php +++ b/system/database/drivers/oci8/oci8_utility.php @@ -76,7 +76,7 @@ class CI_DB_oci8_utility extends CI_DB_utility { */ function _list_tables() { - return "select TABLE_NAME FROM ALL_TABLES"; + return "SELECT TABLE_NAME FROM ALL_TABLES"; } // -------------------------------------------------------------------- diff --git a/system/database/drivers/postgre/postgre_utility.php b/system/database/drivers/postgre/postgre_utility.php index 0ee448f9e..7b51c3fe7 100644 --- a/system/database/drivers/postgre/postgre_utility.php +++ b/system/database/drivers/postgre/postgre_utility.php @@ -97,7 +97,7 @@ class CI_DB_postgre_utility extends CI_DB_utility { /** * Optimize table query * - * Generates a platform-specific query so that a table can be optimized + * Is table optimization supported in Postgre? * * @access private * @param string the table name @@ -105,7 +105,7 @@ class CI_DB_postgre_utility extends CI_DB_utility { */ function _optimize_table($table) { - return FALSE; // Is this supported in Postgre? + return FALSE; } // -------------------------------------------------------------------- @@ -113,7 +113,7 @@ class CI_DB_postgre_utility extends CI_DB_utility { /** * Repair table query * - * Generates a platform-specific query so that a table can be repaired + * Are table repairs supported in Postgre? * * @access private * @param string the table name @@ -121,7 +121,7 @@ class CI_DB_postgre_utility extends CI_DB_utility { */ function _repair_table($table) { - return return FALSE; // Is this supported in Postgre? + return return FALSE; } diff --git a/system/database/drivers/sqlite/sqlite_utility.php b/system/database/drivers/sqlite/sqlite_utility.php index 43c43e03c..ae241db87 100644 --- a/system/database/drivers/sqlite/sqlite_utility.php +++ b/system/database/drivers/sqlite/sqlite_utility.php @@ -34,7 +34,8 @@ class CI_DB_sqlite_utility extends CI_DB_utility { */ function _create_database() { - // In SQLite, a database is created when you connect to the database + // 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; } @@ -65,11 +66,17 @@ class CI_DB_sqlite_utility extends CI_DB_utility { /** * List databases * + * I don't believe you can do a database listing with SQLite + * since each database is its own file. I suppose we could + * try reading a directory looking for SQLite files, but + * that doesn't seem like a terribly good idea + * * @access private * @return bool */ function _list_databases() { + if ($this->db_debug) { return $this->display_error('db_unsuported_feature'); @@ -97,6 +104,8 @@ class CI_DB_sqlite_utility extends CI_DB_utility { /** * Drop Table * + * Unsupported feature in SQLite + * * @access private * @return bool */ @@ -114,7 +123,7 @@ class CI_DB_sqlite_utility extends CI_DB_utility { /** * Optimize table query * - * Generates a platform-specific query so that a table can be optimized + * Is optimization even supported in SQLite? * * @access private * @param string the table name @@ -122,7 +131,7 @@ class CI_DB_sqlite_utility extends CI_DB_utility { */ function _optimize_table($table) { - return FALSE; // Is this supported SQLite? + return FALSE; } // -------------------------------------------------------------------- @@ -130,7 +139,7 @@ class CI_DB_sqlite_utility extends CI_DB_utility { /** * Repair table query * - * Generates a platform-specific query so that a table can be repaired + * Are table repairs even supported in SQLite? * * @access private * @param string the table name @@ -138,7 +147,7 @@ class CI_DB_sqlite_utility extends CI_DB_utility { */ function _repair_table($table) { - return return FALSE; // Is this supported in SQLite? + return return FALSE; } diff --git a/system/libraries/Controller.php b/system/libraries/Controller.php index ff914d131..be66b19b7 100644 --- a/system/libraries/Controller.php +++ b/system/libraries/Controller.php @@ -191,7 +191,6 @@ class Controller extends CI_Base { $remap = array( 'DB_export' => 'dbexport', 'DB_utility' => 'dbutility', - 'Encryption' => 'encrypt', 'Unit_test' => 'unit' ); -- cgit v1.2.3-24-g4f1b From 051402b4c281cf125c9b369b682128aaefb587cd Mon Sep 17 00:00:00 2001 From: admin Date: Fri, 29 Sep 2006 23:11:40 +0000 Subject: --- system/database/drivers/mysql/mysql_utility.php | 170 ++++++++++++++++++++++++ 1 file changed, 170 insertions(+) (limited to 'system') diff --git a/system/database/drivers/mysql/mysql_utility.php b/system/database/drivers/mysql/mysql_utility.php index a81936c56..65fb87f92 100644 --- a/system/database/drivers/mysql/mysql_utility.php +++ b/system/database/drivers/mysql/mysql_utility.php @@ -123,7 +123,177 @@ class CI_DB_mysql_utility extends CI_DB_utility { return "REPAIR TABLE ".$this->db->_escape_table($table); } + // -------------------------------------------------------------------- + + /** + * MySQL Export + * + * @access public + * @param object The query result object + * @param array Any preferences + * @return string + */ + function export($params = array()) + { + // Set up our default preferences + $prefs = array( + 'tables' => array(), + 'ignore' => array(), + 'format' => 'gzip', + 'download' => TRUE, + 'filename' => date('Y-m-d-H:i', time()), + 'filepath' => '', + 'add_drop' => TRUE, + 'add_insert' => TRUE, + 'newline' => "\n" + ); + + // Did the user submit any preference overrides? If so set them.... + if (count($params) > 0) + { + foreach ($prefs as $key => $val) + { + if (isset($params[$key])) + { + $prefs[$key] = $params[$key]; + } + } + } + + // Extract the prefs for simplicity + extract($prefs); + + // Are we backing up a complete database or individual tables? + if (count($tables) == 0) + { + $tables = $this->list_tables(); + } + + + + // Start buffering the output + ob_start(); + + // Build the output + foreach ($tables as $table) + { + // Is the table in the "ignore" list? + if (in_array($table, $ignore)) + { + 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 + + echo $newline.$newline.'#'.$newline.'# TABLE STRUCTURE FOR: '.$table.$newline.'#'.$newline.$newline; + + if ($add_drop == TRUE) + { + echo 'DROP TABLE IF EXISTS '.$table.';'.$newline.$newline; + } + + $i = 0; + $result = $query->result_array(); + foreach ($result[0] as $val) + { + if ($i++ % 2) + { + echo $val.';'.$newline.$newline; + } + } + + // Build the insert statements + + if ($add_insert == FALSE) + { + continue; + } + + $query = $this->db->query("SELECT * FROM $table"); + + if ($query->num_rows() == 0) + { + continue; + } + + // Grab 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; + $fields = ''; + $is_int = array(); + while ($field = mysql_fetch_field($query->result_id)) + { + $is_int[$i] = (in_array( + mysql_field_type($query->result_id, $i), + array('tinyint', 'smallint', 'mediumint', 'int', 'bigint', 'timestamp'), + TRUE) + ) ? TRUE : FALSE; + + // Create a string of field names + $fields .= $field->name.', '; + $i++; + } + + $fields = preg_replace( "/, $/" , "" , $fields); + + + // Build the inserts + foreach ($query->result_array() as $row) + { + $values = ''; + + $i = 0; + foreach ($row as $v) + { + $v = str_replace(array("\x00", "\x0a", "\x0d", "\x1a"), array('\0', '\n', '\r', '\Z'), $v); + $v = str_replace(array("\n", "\r", "\t"), array('\n', '\r', '\t'), $v); + $v = str_replace('\\', '\\\\', $v); + $v = str_replace('\'', '\\\'', $v); + $v = str_replace('\\\n', '\n', $v); + $v = str_replace('\\\r', '\r', $v); + $v = str_replace('\\\t', '\t', $v); + + // Escape the data if it's not an integer type + $values .= ($is_int[$i] == FALSE) ? $this->db->escape($v) : $v; + $values .= ', '; + + $i++; + } + + $values = preg_replace( "/, $/" , "" , $values); + + if ($download == FALSE) + { + $values = htmlspecialchars($values); + } + + // Build the INSERT string + echo 'INSERT INTO '.$table.' ('.$fields.') VALUES ('.$values.');'.$newline; + + } + + + + $buffer = ob_get_contents(); + @ob_end_clean(); + + echo $buffer; + + } + + + } } -- cgit v1.2.3-24-g4f1b From 3ed8c51254a5b26d951fa675802fcf69adf9638e Mon Sep 17 00:00:00 2001 From: admin Date: Fri, 29 Sep 2006 23:26:28 +0000 Subject: --- system/database/DB_driver.php | 9 +- system/database/DB_export.php | 132 ------------------------ system/database/DB_utility.php | 121 +++++++++++++++++++++- system/database/drivers/mysql/mysql_utility.php | 48 +++++---- system/libraries/Controller.php | 12 +-- system/libraries/Encrypt.php | 35 ++++--- system/libraries/Loader.php | 14 --- 7 files changed, 173 insertions(+), 198 deletions(-) delete mode 100644 system/database/DB_export.php (limited to 'system') diff --git a/system/database/DB_driver.php b/system/database/DB_driver.php index 94db84bbf..275d51c53 100644 --- a/system/database/DB_driver.php +++ b/system/database/DB_driver.php @@ -45,6 +45,7 @@ class CI_DB_driver { var $query_count = 0; var $bind_marker = '?'; var $queries = array(); + var $cache = array(); var $trans_enabled = TRUE; var $_trans_depth = 0; var $_trans_failure = FALSE; // Used with transactions to determine if a rollback should occur @@ -563,6 +564,12 @@ class CI_DB_driver { */ function field_names($table = '') { + // Is there a cached result? + if (isset($this->cache['field_names'][$table])) + { + return $this->cache['field_names'][$table]; + } + if ($table == '') { if ($this->db_debug) @@ -596,7 +603,7 @@ class CI_DB_driver { } } - return $retval; + return $this->cache['field_names'][$table] =& $retval; } // -------------------------------------------------------------------- diff --git a/system/database/DB_export.php b/system/database/DB_export.php deleted file mode 100644 index 1704f0dfd..000000000 --- a/system/database/DB_export.php +++ /dev/null @@ -1,132 +0,0 @@ -field_names() as $name) - { - $out .= $name.$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 .= $item.$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, 'field_names')) - { - 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 - $obj =& get_instance(); - $obj->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; - } - -} - -?> \ No newline at end of file diff --git a/system/database/DB_utility.php b/system/database/DB_utility.php index 764f10cb7..ff9407ebd 100644 --- a/system/database/DB_utility.php +++ b/system/database/DB_utility.php @@ -25,6 +25,7 @@ class CI_DB_utility { var $db; + var $cache = array(); /** * Constructor @@ -93,6 +94,12 @@ class CI_DB_utility { */ function list_databases() { + // Is there a cached result? + if (isset($this->cache['db_names'])) + { + return $this->cache['db_names']; + } + $query = $this->db->query($this->_list_database()); $dbs = array(); if ($query->num_rows() > 0) @@ -103,7 +110,7 @@ class CI_DB_utility { } } - return $dbs; + return $this->cache['db_names'] =& $dbs; } // -------------------------------------------------------------------- @@ -116,6 +123,12 @@ class CI_DB_utility { */ function list_tables() { + // Is there a cached result? + if (isset($this->cache['table_names'])) + { + return $this->cache['table_names']; + } + if (FALSE === ($sql = $this->_list_tables())) { if ($this->db->db_debug) @@ -143,7 +156,7 @@ class CI_DB_utility { } } - return $retval; + return $this->cache['table_names'] =& $retval; } // -------------------------------------------------------------------- @@ -258,7 +271,111 @@ class CI_DB_utility { return $this->db->query($sql); } + // -------------------------------------------------------------------- + + /** + * Generate CVS from a query result object + * + * @access public + * @param object The query result object + * @param string The delimiter - tab by default + * @param string The newline character - \n by default + * @return string + */ + function cvs_from_result($query, $delim = "\t", $newline = "\n") + { + if ( ! is_object($query) OR ! method_exists($query, 'field_names')) + { + show_error('You must submit a valid result object'); + } + + $out = ''; + + // First generate the headings from the table column names + foreach ($query->field_names() as $name) + { + $out .= $name.$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 .= $item.$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, 'field_names')) + { + 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 + $obj =& get_instance(); + $obj->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 export() + { + // The individual driver overloads this method + } } diff --git a/system/database/drivers/mysql/mysql_utility.php b/system/database/drivers/mysql/mysql_utility.php index 65fb87f92..f43299382 100644 --- a/system/database/drivers/mysql/mysql_utility.php +++ b/system/database/drivers/mysql/mysql_utility.php @@ -128,19 +128,18 @@ class CI_DB_mysql_utility extends CI_DB_utility { /** * MySQL Export * - * @access public - * @param object The query result object + * @access private * @param array Any preferences - * @return string + * @return mixed */ - function export($params = array()) + function _export($params = array()) { // Set up our default preferences $prefs = array( 'tables' => array(), 'ignore' => array(), 'format' => 'gzip', - 'download' => TRUE, + 'action' => 'download', // download, archive, echo, return 'filename' => date('Y-m-d-H:i', time()), 'filepath' => '', 'add_drop' => TRUE, @@ -169,8 +168,6 @@ class CI_DB_mysql_utility extends CI_DB_utility { $tables = $this->list_tables(); } - - // Start buffering the output ob_start(); @@ -193,7 +190,6 @@ class CI_DB_mysql_utility extends CI_DB_utility { } // Write out the table schema - echo $newline.$newline.'#'.$newline.'# TABLE STRUCTURE FOR: '.$table.$newline.'#'.$newline.$newline; if ($add_drop == TRUE) @@ -211,13 +207,13 @@ class CI_DB_mysql_utility extends CI_DB_utility { } } - // Build the insert statements - + // 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) @@ -225,37 +221,39 @@ class CI_DB_mysql_utility extends CI_DB_utility { continue; } - // Grab the field names and determine if the field is an + // 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; - $fields = ''; + $field_str = ''; $is_int = array(); while ($field = mysql_fetch_field($query->result_id)) { $is_int[$i] = (in_array( - mysql_field_type($query->result_id, $i), + strtolower(mysql_field_type($query->result_id, $i)), array('tinyint', 'smallint', 'mediumint', 'int', 'bigint', 'timestamp'), TRUE) ) ? TRUE : FALSE; // Create a string of field names - $fields .= $field->name.', '; + $field_str .= $field->name.', '; $i++; } - - $fields = preg_replace( "/, $/" , "" , $fields); + + // Trim off the end comma + $field_str = preg_replace( "/, $/" , "" , $field_str); - // Build the inserts + // Build the insert string foreach ($query->result_array() as $row) { - $values = ''; + $val_str = ''; $i = 0; foreach ($row as $v) { + // Do a little formatting... $v = str_replace(array("\x00", "\x0a", "\x0d", "\x1a"), array('\0', '\n', '\r', '\Z'), $v); $v = str_replace(array("\n", "\r", "\t"), array('\n', '\r', '\t'), $v); $v = str_replace('\\', '\\\\', $v); @@ -265,21 +263,21 @@ class CI_DB_mysql_utility extends CI_DB_utility { $v = str_replace('\\\t', '\t', $v); // Escape the data if it's not an integer type - $values .= ($is_int[$i] == FALSE) ? $this->db->escape($v) : $v; - $values .= ', '; + $val_str .= ($is_int[$i] == FALSE) ? $this->db->escape($v) : $v; + $val_str .= ', '; $i++; } - $values = preg_replace( "/, $/" , "" , $values); + $val_str = preg_replace( "/, $/" , "" , $val_str); - if ($download == FALSE) + if ($action == 'echo') { - $values = htmlspecialchars($values); + $val_str = htmlspecialchars($val_str); } // Build the INSERT string - echo 'INSERT INTO '.$table.' ('.$fields.') VALUES ('.$values.');'.$newline; + echo 'INSERT INTO '.$table.' ('.$field_str.') VALUES ('.$val_str.');'.$newline; } diff --git a/system/libraries/Controller.php b/system/libraries/Controller.php index be66b19b7..51f455023 100644 --- a/system/libraries/Controller.php +++ b/system/libraries/Controller.php @@ -189,8 +189,6 @@ class Controller extends CI_Base { } $remap = array( - 'DB_export' => 'dbexport', - 'DB_utility' => 'dbutility', 'Unit_test' => 'unit' ); @@ -516,19 +514,15 @@ class Controller extends CI_Base { { if ( ! $this->_ci_is_loaded('db')) { - $this->_init_database(); + $this->_ci_init_database(); } if ($class == 'dbutil') { require_once(BASEPATH.'database/DB_utility'.EXT); require_once(BASEPATH.'database/drivers/'.$this->db->dbdriver.'/'.$this->db->dbdriver.'_utility'.EXT); - $this->init_class('CI_DB_'.$this->db->dbdriver.'_utility', 'dbutil'); - } - elseif ($class == 'dbexport') - { - require_once(BASEPATH.'database/DB_export'.EXT); - $this->init_class('CI_DB_export', 'dbexport'); + $class = 'CI_DB_'.$this->db->dbdriver.'_utility'; + $this->dbutil = new $class(); } } diff --git a/system/libraries/Encrypt.php b/system/libraries/Encrypt.php index abc769460..537b1ab20 100644 --- a/system/libraries/Encrypt.php +++ b/system/libraries/Encrypt.php @@ -27,6 +27,7 @@ * @link http://www.codeigniter.com/user_guide/libraries/encryption.html */ class CI_Encrypt { + var $encryption_key = ''; var $_hash_type = 'sha1'; var $_mcrypt_exists = FALSE; var $_mcrypt_cipher; @@ -43,7 +44,6 @@ class CI_Encrypt { $this->_mcrypt_exists = ( ! function_exists('mcrypt_encrypt')) ? FALSE : TRUE; log_message('debug', "Encrypt Class Initialized"); } - // END CI_Encrypt() // -------------------------------------------------------------------- @@ -61,6 +61,11 @@ class CI_Encrypt { { if ($key == '') { + if ($this->encryption_key != '') + { + return $this->encryption_key; + } + $obj =& get_instance(); $key = $obj->config->item('encryption_key'); @@ -72,7 +77,20 @@ class CI_Encrypt { return md5($key); } - // END get_key() + + // -------------------------------------------------------------------- + + /** + * Set the encryption key + * + * @access public + * @param string + * @return void + */ + function set_key($key = '') + { + $this->encryption_key = $key; + } // -------------------------------------------------------------------- @@ -103,7 +121,6 @@ class CI_Encrypt { } return base64_encode($enc); } - // END encode() // -------------------------------------------------------------------- @@ -134,7 +151,6 @@ class CI_Encrypt { return $this->_xor_decode($dec, $key); } - // END decode() // -------------------------------------------------------------------- @@ -167,7 +183,6 @@ class CI_Encrypt { return $this->_xor_merge($enc, $key); } - // END _xor_encode() // -------------------------------------------------------------------- @@ -194,7 +209,6 @@ class CI_Encrypt { return $dec; } - // END _xor_decode() // -------------------------------------------------------------------- @@ -219,7 +233,6 @@ class CI_Encrypt { return $str; } - // END _xor_merge() // -------------------------------------------------------------------- @@ -238,7 +251,6 @@ class CI_Encrypt { $init_vect = mcrypt_create_iv($init_size, MCRYPT_RAND); return mcrypt_encrypt($this->_mcrypt_cipher, $key, $data, $this->_mcrypt_mode, $init_vect); } - // END mcrypt_encode() // -------------------------------------------------------------------- @@ -257,7 +269,6 @@ class CI_Encrypt { $init_vect = mcrypt_create_iv($init_size, MCRYPT_RAND); return rtrim(mcrypt_decrypt($this->_mcrypt_cipher, $key, $data, $this->_mcrypt_mode, $init_vect), "\0"); } - // END mcrypt_decode() // -------------------------------------------------------------------- @@ -272,7 +283,6 @@ class CI_Encrypt { { $this->_mcrypt_cipher = $cypher; } - // END set_cypher() // -------------------------------------------------------------------- @@ -287,7 +297,6 @@ class CI_Encrypt { { $this->_mcrypt_mode = $mode; } - // END set_mode() // -------------------------------------------------------------------- @@ -309,7 +318,6 @@ class CI_Encrypt { $this->_mcrypt_mode = MCRYPT_MODE_ECB; } } - // END _get_mcrypt() // -------------------------------------------------------------------- @@ -324,7 +332,6 @@ class CI_Encrypt { { $this->_hash_type = ($type != 'sha1' AND $type != 'md5') ? 'sha1' : $type; } - // END set_hash() // -------------------------------------------------------------------- @@ -339,7 +346,6 @@ class CI_Encrypt { { return ($this->_hash_type == 'sha1') ? $this->sha1($str) : md5($str); } - // END hash() // -------------------------------------------------------------------- @@ -370,7 +376,6 @@ class CI_Encrypt { return sha1($str); } } - // END sha1() } diff --git a/system/libraries/Loader.php b/system/libraries/Loader.php index fff9e78d3..2534e6965 100644 --- a/system/libraries/Loader.php +++ b/system/libraries/Loader.php @@ -135,20 +135,6 @@ class CI_Loader { $obj =& get_instance(); $obj->_ci_init_dbextra('dbutil'); } - - // -------------------------------------------------------------------- - - /** - * Database Export Loader - * - * @access public - * @return object - */ - function dbexport() - { - $obj =& get_instance(); - $obj->_ci_init_dbextra('dbexport'); - } // -------------------------------------------------------------------- -- cgit v1.2.3-24-g4f1b From 3dd978f680076be842bfcb5c9e2cbf35b926373b Mon Sep 17 00:00:00 2001 From: admin Date: Sat, 30 Sep 2006 19:24:45 +0000 Subject: --- system/database/DB_driver.php | 101 ++++++- system/database/DB_utility.php | 310 +++++++++++++++------ system/database/drivers/mssql/mssql_driver.php | 28 ++ system/database/drivers/mssql/mssql_utility.php | 28 -- system/database/drivers/mysql/mysql_driver.php | 28 ++ system/database/drivers/mysql/mysql_utility.php | 95 +------ system/database/drivers/mysqli/mysqli_driver.php | 30 +- system/database/drivers/mysqli/mysqli_utility.php | 28 -- system/database/drivers/oci8/oci8_driver.php | 28 ++ system/database/drivers/oci8/oci8_utility.php | 28 -- system/database/drivers/odbc/odbc_driver.php | 33 +++ system/database/drivers/odbc/odbc_utility.php | 53 +--- system/database/drivers/postgre/postgre_driver.php | 28 ++ .../database/drivers/postgre/postgre_utility.php | 28 -- system/database/drivers/sqlite/sqlite_driver.php | 39 ++- system/database/drivers/sqlite/sqlite_utility.php | 46 +-- system/language/english/db_lang.php | 3 + 17 files changed, 564 insertions(+), 370 deletions(-) (limited to 'system') diff --git a/system/database/DB_driver.php b/system/database/DB_driver.php index 275d51c53..5102cc74c 100644 --- a/system/database/DB_driver.php +++ b/system/database/DB_driver.php @@ -555,6 +555,95 @@ class CI_DB_driver { // -------------------------------------------------------------------- + // -------------------------------------------------------------------- + + /** + * List databases + * + * @access public + * @return bool + */ + function list_databases() + { + // Is there a cached result? + if (isset($this->cache['db_names'])) + { + return $this->cache['db_names']; + } + + $query = $this->query($this->_list_database()); + $dbs = array(); + if ($query->num_rows() > 0) + { + foreach ($query->result_array() as $row) + { + $dbs[] = current($row); + } + } + + return $this->cache['db_names'] =& $dbs; + } + + // -------------------------------------------------------------------- + + /** + * Returns an array of table names + * + * @access public + * @return array + */ + function list_tables() + { + // Is there a cached result? + if (isset($this->cache['table_names'])) + { + return $this->cache['table_names']; + } + + if (FALSE === ($sql = $this->_list_tables())) + { + 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); + } + } + } + + return $this->cache['table_names'] =& $retval; + } + + // -------------------------------------------------------------------- + + /** + * Determine if a particular table exists + * @access public + * @return boolean + */ + function table_exists($table_name) + { + return ( ! in_array($this->dbprefix.$table_name, $this->list_tables())) ? FALSE : TRUE; + } + + // -------------------------------------------------------------------- + /** * Fetch MySQL Field Names * @@ -562,7 +651,7 @@ class CI_DB_driver { * @param string the table name * @return array */ - function field_names($table = '') + function list_fields($table = '') { // Is there a cached result? if (isset($this->cache['field_names'][$table])) @@ -605,6 +694,16 @@ class CI_DB_driver { return $this->cache['field_names'][$table] =& $retval; } + + // -------------------------------------------------------------------- + + /** + * DEPRECATED - use list_fields() + */ + function field_names($table = '') + { + return $this->list_fields($table); + } // -------------------------------------------------------------------- diff --git a/system/database/DB_utility.php b/system/database/DB_utility.php index ff9407ebd..dc56d6524 100644 --- a/system/database/DB_utility.php +++ b/system/database/DB_utility.php @@ -86,93 +86,6 @@ class CI_DB_utility { // -------------------------------------------------------------------- - /** - * List databases - * - * @access public - * @return bool - */ - function list_databases() - { - // Is there a cached result? - if (isset($this->cache['db_names'])) - { - return $this->cache['db_names']; - } - - $query = $this->db->query($this->_list_database()); - $dbs = array(); - if ($query->num_rows() > 0) - { - foreach ($query->result_array() as $row) - { - $dbs[] = current($row); - } - } - - return $this->cache['db_names'] =& $dbs; - } - - // -------------------------------------------------------------------- - - /** - * Returns an array of table names - * - * @access public - * @return array - */ - function list_tables() - { - // Is there a cached result? - if (isset($this->cache['table_names'])) - { - return $this->cache['table_names']; - } - - if (FALSE === ($sql = $this->_list_tables())) - { - if ($this->db->db_debug) - { - return $this->db->display_error('db_unsupported_function'); - } - return FALSE; - } - - $retval = array(); - $query = $this->db->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); - } - } - } - - return $this->cache['table_names'] =& $retval; - } - - // -------------------------------------------------------------------- - - /** - * Determine if a particular table exists - * @access public - * @return boolean - */ - function table_exists($table_name) - { - return ( ! in_array($this->db->dbprefix.$table_name, $this->list_tables())) ? FALSE : TRUE; - } - - // -------------------------------------------------------------------- - /** * Optimize Table * @@ -372,12 +285,231 @@ class CI_DB_utility { * @access public * @return void */ - function export() + function backup($params = array()) { - // The individual driver overloads this method + // 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(), + 'format' => 'gzip', // gzip, zip, txt + 'action' => 'download', // download, archive, echo, return + 'filename' => '', + 'filepath' => '', + '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->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 + if ($prefs['filename'] == '') + { + $prefs['filename'] = (count($prefs['tables']) == 1) ? $prefs['tables'] : $this->db->database; + $prefs['filename'] .= '_'.date('Y-m-d_H-i', time()); + } + + // ------------------------------------------------------ + + // If we are archiving the export, does this filepath exist + // and resolve to a writable directory + if ($prefs['action'] == 'archive') + { + if ($prefs['filepath'] == '' OR ! is_writable($prefs['filepath'])) + { + if ($this->db->db_debug) + { + return $this->db->display_error('db_filepath_error'); + } + + $prefs['action'] = 'download'; + } + } + + // ------------------------------------------------------ + + // Are we returning the backup data? If so, we're done... + if ($prefs['action'] == 'return') + { + return $this->_backup($prefs); + } + + // ------------------------------------------------------ + + // Are we echoing the backup? If so, format the data and spit it at the screen... + if ($prefs['action'] == 'echo') + { + echo '
';
+			echo htmlspecialchars($this->_backup($prefs));
+			echo '
'; + + return TRUE; + } + + // ------------------------------------------------------ + + // Are we archiving the data to the server? + if ($prefs['action'] == 'archive') + { + // Make sure the filepath has a trailing slash + if (ereg("/$", $prefs['filepath']) === FALSE) + { + $prefs['filepath'] .= '/'; + } + + // Assemble the path and tack on the file extension + $ext = array('gzip' => 'gz', 'zip' => 'zip', 'txt' => 'sql'); + $path = $prefs['filepath'].$prefs['filename'].$ext[$prefs['format']]; + + // Load the file helper + $obj =& get_instance(); + $obj->load->helper('file'); + + // Write the file based on type + switch ($prefs['format']) + { + case 'gzip' : + write_file($path, gzencode($this->_backup($prefs))); + return TRUE; + break; + case 'txt' : + write_file($path, $this->_backup($prefs)); + return TRUE; + break; + default : + require BASEPATH.'libraries/Zip.php'; + $zip = new Zip; + $zip->add_file($this->_backup($prefs), $prefs['filename'].'.sql'); + write_file($path, $zip->output_zipfile()); + return TRUE; + break; + } + + } + + // ------------------------------------------------------ + + // Set the mime type used in the server header + switch ($prefs['format']) + { + case 'zip' : $mime = 'application/x-zip'; + break; + case 'gzip' : $mime = 'application/x-gzip'; + break; + default : + if (strstr($_SERVER['HTTP_USER_AGENT'], "MSIE") || strstr($_SERVER['HTTP_USER_AGENT'], "OPERA")) + { + $mime = 'application/octetstream'; + } + else + { + $mime = 'application/octet-stream'; + } + break; + } + + // Grab the super object + $obj =& get_instance(); + + // Remap the file extensions + $ext = array('gzip' => 'gz', 'zip' => 'zip', 'txt' => 'sql'); + + // Send headers + if (strstr($_SERVER['HTTP_USER_AGENT'], "MSIE")) + { + $obj->output->set_header('Content-Type: '.$mime); + $obj->output->set_header('Content-Disposition: inline; filename="'.$prefs['filename'].'.'.$ext[$prefs['format']].'"'); + $obj->output->set_header('Expires: 0'); + $obj->output->set_header('Cache-Control: must-revalidate, post-check=0, pre-check=0'); + $obj->output->set_header('Pragma: public'); + } + else + { + $obj->output->set_header('Content-Type: '.$mime); + $obj->output->set_header('Content-Disposition: attachment; filename="'.$prefs['filename'].'.'.$ext[$prefs['format']].'"'); + $obj->output->set_header('Expires: 0'); + $obj->output->set_header('Pragma: no-cache'); + } + + + // Write the file based on type + switch ($prefs['format']) + { + case 'gzip' : $obj->output->set_output(gzencode($this->_backup($prefs))); + break; + case 'txt' : $obj->output->set_output($this->_backup($prefs)); + break; + default : + require BASEPATH.'libraries/Zip.php'; + + $zip = new Zip; + $zip->add_file($this->_backup($prefs), $prefs['filename'].'.sql'); + $obj->output->set_output($zip->output_zipfile()); + break; + } + + return TRUE; } + + + + } ?> \ No newline at end of file diff --git a/system/database/drivers/mssql/mssql_driver.php b/system/database/drivers/mssql/mssql_driver.php index 3f5e53345..8b82ee314 100644 --- a/system/database/drivers/mssql/mssql_driver.php +++ b/system/database/drivers/mssql/mssql_driver.php @@ -261,6 +261,34 @@ class CI_DB_mssql_driver extends CI_DB { // -------------------------------------------------------------------- + /** + * List databases + * + * @access private + * @return bool + */ + function _list_databases() + { + return "EXEC sp_helpdb"; // Can also be: EXEC sp_databases + } + + // -------------------------------------------------------------------- + + /** + * List table query + * + * Generates a platform-specific query string so that the table names can be fetched + * + * @access private + * @return string + */ + function _list_tables() + { + return "SELECT name FROM sysobjects WHERE type = 'U' ORDER BY name"; + } + + // -------------------------------------------------------------------- + /** * List columnn query * diff --git a/system/database/drivers/mssql/mssql_utility.php b/system/database/drivers/mssql/mssql_utility.php index 96b8180b8..ad13167cd 100644 --- a/system/database/drivers/mssql/mssql_utility.php +++ b/system/database/drivers/mssql/mssql_utility.php @@ -53,34 +53,6 @@ class CI_DB_mssql_utility extends CI_DB_utility { // -------------------------------------------------------------------- - /** - * List databases - * - * @access private - * @return bool - */ - function _list_databases() - { - return "EXEC sp_helpdb"; // Can also be: EXEC sp_databases - } - - // -------------------------------------------------------------------- - - /** - * List table query - * - * Generates a platform-specific query string so that the table names can be fetched - * - * @access private - * @return string - */ - function _list_tables() - { - return "SELECT name FROM sysobjects WHERE type = 'U' ORDER BY name"; - } - - // -------------------------------------------------------------------- - /** * Drop Table * diff --git a/system/database/drivers/mysql/mysql_driver.php b/system/database/drivers/mysql/mysql_driver.php index 792e023a8..ecab648d4 100644 --- a/system/database/drivers/mysql/mysql_driver.php +++ b/system/database/drivers/mysql/mysql_driver.php @@ -292,6 +292,34 @@ class CI_DB_mysql_driver extends CI_DB { $row = $query->row(); return $row->numrows; } + + // -------------------------------------------------------------------- + + /** + * List databases + * + * @access private + * @return bool + */ + function _list_databases() + { + return "SHOW DATABASES"; + } + + // -------------------------------------------------------------------- + + /** + * List table query + * + * Generates a platform-specific query string so that the table names can be fetched + * + * @access private + * @return string + */ + function _list_tables() + { + return "SHOW TABLES FROM `".$this->database."`"; + } // -------------------------------------------------------------------- diff --git a/system/database/drivers/mysql/mysql_utility.php b/system/database/drivers/mysql/mysql_utility.php index f43299382..a81c915f6 100644 --- a/system/database/drivers/mysql/mysql_utility.php +++ b/system/database/drivers/mysql/mysql_utility.php @@ -52,34 +52,6 @@ class CI_DB_mysql_utility extends CI_DB_utility { // -------------------------------------------------------------------- - /** - * List databases - * - * @access private - * @return bool - */ - function _list_databases() - { - return "SHOW DATABASES"; - } - - // -------------------------------------------------------------------- - - /** - * Show table query - * - * Generates a platform-specific query string so that the table names can be fetched - * - * @access private - * @return string - */ - function _list_tables() - { - return "SHOW TABLES FROM `".$this->db->database."`"; - } - - // -------------------------------------------------------------------- - /** * Drop Table * @@ -132,50 +104,22 @@ class CI_DB_mysql_utility extends CI_DB_utility { * @param array Any preferences * @return mixed */ - function _export($params = array()) + function _backup($params = array()) { - // Set up our default preferences - $prefs = array( - 'tables' => array(), - 'ignore' => array(), - 'format' => 'gzip', - 'action' => 'download', // download, archive, echo, return - 'filename' => date('Y-m-d-H:i', time()), - 'filepath' => '', - 'add_drop' => TRUE, - 'add_insert' => TRUE, - 'newline' => "\n" - ); - - // Did the user submit any preference overrides? If so set them.... - if (count($params) > 0) + if (count($params) == 0) { - foreach ($prefs as $key => $val) - { - if (isset($params[$key])) - { - $prefs[$key] = $params[$key]; - } - } + return FALSE; } // Extract the prefs for simplicity - extract($prefs); - - // Are we backing up a complete database or individual tables? - if (count($tables) == 0) - { - $tables = $this->list_tables(); - } - - // Start buffering the output - ob_start(); + extract($params); // Build the output - foreach ($tables as $table) + $output = ''; + foreach ((array)$tables as $table) { // Is the table in the "ignore" list? - if (in_array($table, $ignore)) + if (in_array($table, (array)$ignore, TRUE)) { continue; } @@ -190,11 +134,11 @@ class CI_DB_mysql_utility extends CI_DB_utility { } // Write out the table schema - echo $newline.$newline.'#'.$newline.'# TABLE STRUCTURE FOR: '.$table.$newline.'#'.$newline.$newline; + $output .= '#'.$newline.'# TABLE STRUCTURE FOR: '.$table.$newline.'#'.$newline.$newline; if ($add_drop == TRUE) { - echo 'DROP TABLE IF EXISTS '.$table.';'.$newline.$newline; + $output .= 'DROP TABLE IF EXISTS '.$table.';'.$newline.$newline; } $i = 0; @@ -203,7 +147,7 @@ class CI_DB_mysql_utility extends CI_DB_utility { { if ($i++ % 2) { - echo $val.';'.$newline.$newline; + $output .= $val.';'.$newline.$newline; } } @@ -270,27 +214,16 @@ class CI_DB_mysql_utility extends CI_DB_utility { } $val_str = preg_replace( "/, $/" , "" , $val_str); - - if ($action == 'echo') - { - $val_str = htmlspecialchars($val_str); - } - + // Build the INSERT string - echo 'INSERT INTO '.$table.' ('.$field_str.') VALUES ('.$val_str.');'.$newline; + $output .= 'INSERT INTO '.$table.' ('.$field_str.') VALUES ('.$val_str.');'.$newline; } - - - $buffer = ob_get_contents(); - @ob_end_clean(); - - echo $buffer; - + $output .= $newline.$newline; } - + return $output; } diff --git a/system/database/drivers/mysqli/mysqli_driver.php b/system/database/drivers/mysqli/mysqli_driver.php index b158cfefe..a2c380355 100644 --- a/system/database/drivers/mysqli/mysqli_driver.php +++ b/system/database/drivers/mysqli/mysqli_driver.php @@ -284,7 +284,35 @@ class CI_DB_mysqli_driver extends CI_DB { $row = $query->row(); return $row->numrows; } - + + // -------------------------------------------------------------------- + + /** + * List databases + * + * @access private + * @return bool + */ + function _list_databases() + { + return "SHOW DATABASES"; + } + + // -------------------------------------------------------------------- + + /** + * List table query + * + * Generates a platform-specific query string so that the table names can be fetched + * + * @access private + * @return string + */ + function _list_tables() + { + return "SHOW TABLES FROM `".$this->database."`"; + } + // -------------------------------------------------------------------- /** diff --git a/system/database/drivers/mysqli/mysqli_utility.php b/system/database/drivers/mysqli/mysqli_utility.php index 754ffbda2..f5b98b11f 100644 --- a/system/database/drivers/mysqli/mysqli_utility.php +++ b/system/database/drivers/mysqli/mysqli_utility.php @@ -52,34 +52,6 @@ class CI_DB_mysqli_utility extends CI_DB_utility { // -------------------------------------------------------------------- - /** - * List databases - * - * @access private - * @return bool - */ - function _list_databases() - { - return "SHOW DATABASES"; - } - - // -------------------------------------------------------------------- - - /** - * Show table query - * - * Generates a platform-specific query string so that the table names can be fetched - * - * @access private - * @return string - */ - function _list_tables() - { - return "SHOW TABLES FROM `".$this->db->database."`"; - } - - // -------------------------------------------------------------------- - /** * Drop Table * diff --git a/system/database/drivers/oci8/oci8_driver.php b/system/database/drivers/oci8/oci8_driver.php index bc0a100c2..b43b4c41f 100644 --- a/system/database/drivers/oci8/oci8_driver.php +++ b/system/database/drivers/oci8/oci8_driver.php @@ -399,6 +399,34 @@ class CI_DB_oci8_driver extends CI_DB { return $row->NUMROWS; } + // -------------------------------------------------------------------- + + /** + * List databases + * + * @access private + * @return bool + */ + function _list_databases() + { + return FALSE; + } + + // -------------------------------------------------------------------- + + /** + * Show table query + * + * Generates a platform-specific query string so that the table names can be fetched + * + * @access private + * @return string + */ + function _list_tables() + { + return "SELECT TABLE_NAME FROM ALL_TABLES"; + } + // -------------------------------------------------------------------- /** diff --git a/system/database/drivers/oci8/oci8_utility.php b/system/database/drivers/oci8/oci8_utility.php index 4d267dc6a..b6503de63 100644 --- a/system/database/drivers/oci8/oci8_utility.php +++ b/system/database/drivers/oci8/oci8_utility.php @@ -53,34 +53,6 @@ class CI_DB_oci8_utility extends CI_DB_utility { // -------------------------------------------------------------------- - /** - * List databases - * - * @access private - * @return bool - */ - function _list_databases() - { - return FALSE; - } - - // -------------------------------------------------------------------- - - /** - * Show table query - * - * Generates a platform-specific query string so that the table names can be fetched - * - * @access private - * @return string - */ - function _list_tables() - { - return "SELECT TABLE_NAME FROM ALL_TABLES"; - } - - // -------------------------------------------------------------------- - /** * Drop Table * diff --git a/system/database/drivers/odbc/odbc_driver.php b/system/database/drivers/odbc/odbc_driver.php index cdde2e2ea..0f002cc1b 100644 --- a/system/database/drivers/odbc/odbc_driver.php +++ b/system/database/drivers/odbc/odbc_driver.php @@ -259,6 +259,39 @@ class CI_DB_odbc_driver extends CI_DB { $row = $query->row(); return $row->numrows; } + + // -------------------------------------------------------------------- + + /** + * List databases + * + * @access private + * @return bool + */ + function _list_databases() + { + // Not sure if ODBC lets you list all databases... + if ($this->db_debug) + { + return $this->display_error('db_unsuported_feature'); + } + return FALSE; + } + + // -------------------------------------------------------------------- + + /** + * Show table query + * + * Generates a platform-specific query string so that the table names can be fetched + * + * @access private + * @return string + */ + function _list_tables() + { + return "SHOW TABLES FROM `".$this->database."`"; + } // -------------------------------------------------------------------- diff --git a/system/database/drivers/odbc/odbc_utility.php b/system/database/drivers/odbc/odbc_utility.php index 3d420f69d..6d0fb79f1 100644 --- a/system/database/drivers/odbc/odbc_utility.php +++ b/system/database/drivers/odbc/odbc_utility.php @@ -36,9 +36,9 @@ class CI_DB_odbc_utility extends CI_DB_utility { { // ODBC has no "create database" command since it's // designed to connect to an existing database - if ($this->db_debug) + if ($this->db->db_debug) { - return $this->display_error('db_unsuported_feature'); + return $this->db->display_error('db_unsuported_feature'); } return FALSE; } @@ -56,48 +56,15 @@ class CI_DB_odbc_utility extends CI_DB_utility { { // ODBC has no "drop database" command since it's // designed to connect to an existing database - if ($this->db_debug) + if ($this->db->db_debug) { - return $this->display_error('db_unsuported_feature'); + return $this->db->display_error('db_unsuported_feature'); } return FALSE; } // -------------------------------------------------------------------- - /** - * List databases - * - * @access private - * @return bool - */ - function _list_databases() - { - // Not sure if ODBC lets you list all databases... - if ($this->db_debug) - { - return $this->display_error('db_unsuported_feature'); - } - return FALSE; - } - - // -------------------------------------------------------------------- - - /** - * Show table query - * - * Generates a platform-specific query string so that the table names can be fetched - * - * @access private - * @return string - */ - function _list_tables() - { - return "SHOW TABLES FROM `".$this->db->database."`"; - } - - // -------------------------------------------------------------------- - /** * Drop Table * @@ -107,9 +74,9 @@ class CI_DB_odbc_utility extends CI_DB_utility { function _drop_table($table) { // Not a supported ODBC feature - if ($this->db_debug) + if ($this->db->db_debug) { - return $this->display_error('db_unsuported_feature'); + return $this->db->display_error('db_unsuported_feature'); } return FALSE; } @@ -128,9 +95,9 @@ class CI_DB_odbc_utility extends CI_DB_utility { function _optimize_table($table) { // Not a supported ODBC feature - if ($this->db_debug) + if ($this->db->db_debug) { - return $this->display_error('db_unsuported_feature'); + return $this->db->display_error('db_unsuported_feature'); } return FALSE; } @@ -149,9 +116,9 @@ class CI_DB_odbc_utility extends CI_DB_utility { function _repair_table($table) { // Not a supported ODBC feature - if ($this->db_debug) + if ($this->db->db_debug) { - return $this->display_error('db_unsuported_feature'); + return $this->db->display_error('db_unsuported_feature'); } return FALSE; } diff --git a/system/database/drivers/postgre/postgre_driver.php b/system/database/drivers/postgre/postgre_driver.php index 026284118..f14395638 100644 --- a/system/database/drivers/postgre/postgre_driver.php +++ b/system/database/drivers/postgre/postgre_driver.php @@ -286,6 +286,34 @@ class CI_DB_postgre_driver extends CI_DB { $row = $query->row(); return $row->numrows; } + + // -------------------------------------------------------------------- + + /** + * List databases + * + * @access private + * @return bool + */ + function _list_databases() + { + return "SELECT datname FROM pg_database"; + } + + // -------------------------------------------------------------------- + + /** + * Show table query + * + * Generates a platform-specific query string so that the table names can be fetched + * + * @access private + * @return string + */ + function _list_tables() + { + return "SELECT table_name FROM information_schema.tables WHERE table_schema = 'public'"; + } // -------------------------------------------------------------------- diff --git a/system/database/drivers/postgre/postgre_utility.php b/system/database/drivers/postgre/postgre_utility.php index 7b51c3fe7..46c98cc7d 100644 --- a/system/database/drivers/postgre/postgre_utility.php +++ b/system/database/drivers/postgre/postgre_utility.php @@ -53,34 +53,6 @@ class CI_DB_postgre_utility extends CI_DB_utility { // -------------------------------------------------------------------- - /** - * List databases - * - * @access private - * @return bool - */ - function _list_databases() - { - return "SELECT datname FROM pg_database"; - } - - // -------------------------------------------------------------------- - - /** - * Show table query - * - * Generates a platform-specific query string so that the table names can be fetched - * - * @access private - * @return string - */ - function _list_tables() - { - return "SELECT table_name FROM information_schema.tables WHERE table_schema = 'public'"; - } - - // -------------------------------------------------------------------- - /** * Drop Table * diff --git a/system/database/drivers/sqlite/sqlite_driver.php b/system/database/drivers/sqlite/sqlite_driver.php index 45dd7a892..f57c4b8c8 100644 --- a/system/database/drivers/sqlite/sqlite_driver.php +++ b/system/database/drivers/sqlite/sqlite_driver.php @@ -278,7 +278,44 @@ class CI_DB_sqlite_driver extends CI_DB { $row = $query->row(); return $row->numrows; } - + + // -------------------------------------------------------------------- + + /** + * List databases + * + * I don't believe you can do a database listing with SQLite + * since each database is its own file. I suppose we could + * try reading a directory looking for SQLite files, but + * that doesn't seem like a terribly good idea + * + * @access private + * @return bool + */ + function _list_databases() + { + if ($this->db_debug) + { + return $this->display_error('db_unsuported_feature'); + } + return array(); + } + + // -------------------------------------------------------------------- + + /** + * List table query + * + * Generates a platform-specific query string so that the table names can be fetched + * + * @access private + * @return string + */ + function _list_tables() + { + return "SELECT name from sqlite_master WHERE type='table'"; + } + // -------------------------------------------------------------------- /** diff --git a/system/database/drivers/sqlite/sqlite_utility.php b/system/database/drivers/sqlite/sqlite_utility.php index ae241db87..801660d94 100644 --- a/system/database/drivers/sqlite/sqlite_utility.php +++ b/system/database/drivers/sqlite/sqlite_utility.php @@ -52,9 +52,9 @@ class CI_DB_sqlite_utility extends CI_DB_utility { { if ( ! @file_exists($this->db->database) OR ! @unlink($this->db->database)) { - if ($this->db_debug) + if ($this->db->db_debug) { - return $this->display_error('db_unable_to_drop'); + return $this->db->display_error('db_unable_to_drop'); } return FALSE; } @@ -63,44 +63,6 @@ class CI_DB_sqlite_utility extends CI_DB_utility { // -------------------------------------------------------------------- - /** - * List databases - * - * I don't believe you can do a database listing with SQLite - * since each database is its own file. I suppose we could - * try reading a directory looking for SQLite files, but - * that doesn't seem like a terribly good idea - * - * @access private - * @return bool - */ - function _list_databases() - { - - if ($this->db_debug) - { - return $this->display_error('db_unsuported_feature'); - } - return array(); - } - - // -------------------------------------------------------------------- - - /** - * Show table query - * - * Generates a platform-specific query string so that the table names can be fetched - * - * @access private - * @return string - */ - function _list_tables() - { - return "SELECT name from sqlite_master WHERE type='table'"; - } - - // -------------------------------------------------------------------- - /** * Drop Table * @@ -111,9 +73,9 @@ class CI_DB_sqlite_utility extends CI_DB_utility { */ function _drop_table($table) { - if ($this->db_debug) + if ($this->db->db_debug) { - return $this->display_error('db_unsuported_feature'); + return $this->db->display_error('db_unsuported_feature'); } return array(); } diff --git a/system/language/english/db_lang.php b/system/language/english/db_lang.php index 5be7d6efb..392990120 100644 --- a/system/language/english/db_lang.php +++ b/system/language/english/db_lang.php @@ -14,6 +14,9 @@ $lang['db_unsupported_function'] = 'This feature is not available for the databa $lang['db_transaction_failure'] = 'Transaction failure: Rollback performed'; $lang['db_unable_to_drop'] = 'Unable to drop the specified database.'; $lang['db_unsuported_feature'] = 'Unsupported feature of the database platform you are using.'; +$lang['db_unsuported_compression'] = 'The file compression format you chose is not supported by your server.'; +$lang['db_filepath_error'] = 'Unable to write data to the file path you have submitted.'; + ?> \ No newline at end of file -- cgit v1.2.3-24-g4f1b From ae58a5de4fc040847c43209173dbc7f1193f6c53 Mon Sep 17 00:00:00 2001 From: admin Date: Sat, 30 Sep 2006 19:25:07 +0000 Subject: --- system/libraries/Zip.php | 154 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 154 insertions(+) create mode 100644 system/libraries/Zip.php (limited to 'system') diff --git a/system/libraries/Zip.php b/system/libraries/Zip.php new file mode 100644 index 000000000..9cfe9593d --- /dev/null +++ b/system/libraries/Zip.php @@ -0,0 +1,154 @@ +cdata[] = $fd; + + $cd = "\x50\x4b\x01\x02\x00\x00\x0a\x00\x00\x00\x00\x00\x00\x00\x00\x00" + .pack("V", 0) + .pack("V", 0) + .pack("V", 0) + .pack("v", strlen ($name)) + .pack("v", 0) + .pack("v", 0) + .pack("v", 0) + .pack("v", 0) + .pack("V", 16) + .pack("V", $this->offset) + .$name; + + $this->offset = strlen(implode('', $this->cdata)); + + $this->cdir[] = $cd; + } + + // -------------------------------------------------------------------- + + /** + * Add a File + * + * @access public + * @param string + * @return void + */ + function add_file($data, $name) + { + $name = str_replace("\\", "/", $name); + + $u_len = strlen($data); + $crc = crc32($data); + $data = gzcompress($data); + $data = substr(substr($data, 0,strlen ($data) - 4), 2); + $c_len = strlen($data); + + $fd = "\x50\x4b\x03\x04\x14\x00\x00\x00\x08\x00\x00\x00\x00\x00" + .pack("V", $crc) + .pack("V", $c_len) + .pack("V", $u_len) + .pack("v", strlen($name)) + .pack("v", 0) + .$name + .$data + .pack("V", $crc) + .pack("V", $c_len) + .pack("V", $u_len); + + $this->zdata[] = $fd; + + $cd = "\x50\x4b\x01\x02\x00\x00\x14\x00\x00\x00\x08\x00\x00\x00\x00\x00" + .pack("V", $crc) + .pack("V", $c_len) + .pack("V", $u_len) + .pack("v", strlen ($name)) + .pack("v", 0) + .pack("v", 0) + .pack("v", 0) + .pack("v", 0) + .pack("V", 32 ) + .pack("V", $this->offset) + .$name; + + $this->offset = strlen(implode('', $this->zdata)); + + $this->cdir[] = $cd; + } + + // -------------------------------------------------------------------- + + /** + * Output the zip file + * + * @access public + * @return string + */ + function output_zipfile() + { + $data = implode("", $this->zdata); + $cdir = implode("", $this->cdir); + + return $data + .$cdir + ."\x50\x4b\x05\x06\x00\x00\x00\x00" + .pack("v", sizeof($this->cdir)) + .pack("v", sizeof($this->cdir)) + .pack("V", strlen($cdir)) + .pack("V", strlen($data)) + ."\x00\x00"; + } + +} +// END CLASS +?> \ No newline at end of file -- cgit v1.2.3-24-g4f1b From c8b7bdab0d17319c4f4c7860c7d41bb6efcf17c1 Mon Sep 17 00:00:00 2001 From: admin Date: Sat, 30 Sep 2006 19:26:08 +0000 Subject: --- system/libraries/Zip.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'system') diff --git a/system/libraries/Zip.php b/system/libraries/Zip.php index 9cfe9593d..1fd0e7059 100644 --- a/system/libraries/Zip.php +++ b/system/libraries/Zip.php @@ -21,7 +21,8 @@ * This class is based on a library aquired at Zend: * http://www.zend.com/codex.php?id=696&single=1 * - * I'm not sure this library is all that reliable, but it's the only + * I'm not sure this library is all that reliable, and the + * directory feature doesn't seem to work right, but it's the only * zip compressor I'm aware of -- Rick Ellis * * @package CodeIgniter -- cgit v1.2.3-24-g4f1b From b2a9ceccdb85050cb494e6d0a98b0a49495d29bb Mon Sep 17 00:00:00 2001 From: admin Date: Sun, 1 Oct 2006 03:38:04 +0000 Subject: --- system/codeigniter/Common.php | 6 +-- system/database/DB_driver.php | 45 +++++++--------------- system/database/DB_utility.php | 29 ++++++++++++++ system/database/drivers/mssql/mssql_driver.php | 13 ------- system/database/drivers/mssql/mssql_utility.php | 13 +++++++ system/database/drivers/mysql/mysql_driver.php | 13 ------- system/database/drivers/mysql/mysql_utility.php | 16 +++++++- system/database/drivers/mysqli/mysqli_driver.php | 13 ------- system/database/drivers/mysqli/mysqli_utility.php | 13 +++++++ system/database/drivers/oci8/oci8_driver.php | 13 ------- system/database/drivers/oci8/oci8_utility.php | 13 +++++++ system/database/drivers/odbc/odbc_driver.php | 18 --------- system/database/drivers/odbc/odbc_utility.php | 18 +++++++++ system/database/drivers/postgre/postgre_driver.php | 13 ------- .../database/drivers/postgre/postgre_utility.php | 13 +++++++ system/database/drivers/sqlite/sqlite_driver.php | 22 ----------- system/database/drivers/sqlite/sqlite_utility.php | 22 +++++++++++ 17 files changed, 152 insertions(+), 141 deletions(-) (limited to 'system') diff --git a/system/codeigniter/Common.php b/system/codeigniter/Common.php index 124ad9a38..d2342de42 100644 --- a/system/codeigniter/Common.php +++ b/system/codeigniter/Common.php @@ -72,7 +72,7 @@ function &_load_class($class, $instantiate = TRUE) // identically named file in the application/libraries folder.  // We need to determine, however, if the class being requested is // a sub-class of an existing library or an independent instance - // since each needs to be handled slightly differently.  + // since each needs to be handled slightly different.  // To do this we'll open the requested class and read the top portion // of it. If the class extends a base class we will load the base first. // If it doesn't extend the base we'll only load the requested class. @@ -84,12 +84,12 @@ function &_load_class($class, $instantiate = TRUE) // replaced on-the-fly with nothing required for the user to do // except write the declaration.  Fortunately PHP is ridiculously fast // at file reading operations so I'm not able to discern a performance - // hit based on my benchmarks, assuming a reasonable number of core + // hit based on my benchmarks, assuming only a small number of core // files are being extended, which will usually be the case. $fp = fopen(APPPATH.'libraries/'.$class.EXT, "rb"); - if (preg_match("/MY_".$class."\s+extends\s+CI_".$class."/", fread($fp, '6000'))) + if (preg_match("/MY_".$class."\s+extends\s+CI_".$class."/i", fread($fp, '6000'))) { require(BASEPATH.'libraries/'.$class.EXT); require(APPPATH.'libraries/'.$class.EXT); diff --git a/system/database/DB_driver.php b/system/database/DB_driver.php index 5102cc74c..81af466ef 100644 --- a/system/database/DB_driver.php +++ b/system/database/DB_driver.php @@ -555,37 +555,6 @@ class CI_DB_driver { // -------------------------------------------------------------------- - // -------------------------------------------------------------------- - - /** - * List databases - * - * @access public - * @return bool - */ - function list_databases() - { - // Is there a cached result? - if (isset($this->cache['db_names'])) - { - return $this->cache['db_names']; - } - - $query = $this->query($this->_list_database()); - $dbs = array(); - if ($query->num_rows() > 0) - { - foreach ($query->result_array() as $row) - { - $dbs[] = current($row); - } - } - - return $this->cache['db_names'] =& $dbs; - } - - // -------------------------------------------------------------------- - /** * Returns an array of table names * @@ -694,6 +663,20 @@ class CI_DB_driver { return $this->cache['field_names'][$table] =& $retval; } + + // -------------------------------------------------------------------- + + /** + * 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; + } // -------------------------------------------------------------------- diff --git a/system/database/DB_utility.php b/system/database/DB_utility.php index dc56d6524..e568bce02 100644 --- a/system/database/DB_utility.php +++ b/system/database/DB_utility.php @@ -86,6 +86,35 @@ class CI_DB_utility { // -------------------------------------------------------------------- + /** + * List databases + * + * @access public + * @return bool + */ + function list_databases() + { + // Is there a cached result? + if (isset($this->cache['db_names'])) + { + return $this->cache['db_names']; + } + + $query = $this->db->query($this->_list_database()); + $dbs = array(); + if ($query->num_rows() > 0) + { + foreach ($query->result_array() as $row) + { + $dbs[] = current($row); + } + } + + return $this->cache['db_names'] =& $dbs; + } + + // -------------------------------------------------------------------- + /** * Optimize Table * diff --git a/system/database/drivers/mssql/mssql_driver.php b/system/database/drivers/mssql/mssql_driver.php index 8b82ee314..cb2f48dc3 100644 --- a/system/database/drivers/mssql/mssql_driver.php +++ b/system/database/drivers/mssql/mssql_driver.php @@ -258,19 +258,6 @@ class CI_DB_mssql_driver extends CI_DB { $row = $query->row(); return $row->numrows; } - - // -------------------------------------------------------------------- - - /** - * List databases - * - * @access private - * @return bool - */ - function _list_databases() - { - return "EXEC sp_helpdb"; // Can also be: EXEC sp_databases - } // -------------------------------------------------------------------- diff --git a/system/database/drivers/mssql/mssql_utility.php b/system/database/drivers/mssql/mssql_utility.php index ad13167cd..388dbe1c2 100644 --- a/system/database/drivers/mssql/mssql_utility.php +++ b/system/database/drivers/mssql/mssql_utility.php @@ -66,6 +66,19 @@ class CI_DB_mssql_utility extends CI_DB_utility { // -------------------------------------------------------------------- + /** + * List databases + * + * @access private + * @return bool + */ + function _list_databases() + { + return "EXEC sp_helpdb"; // Can also be: EXEC sp_databases + } + + // -------------------------------------------------------------------- + /** * Optimize table query * diff --git a/system/database/drivers/mysql/mysql_driver.php b/system/database/drivers/mysql/mysql_driver.php index ecab648d4..253627cd9 100644 --- a/system/database/drivers/mysql/mysql_driver.php +++ b/system/database/drivers/mysql/mysql_driver.php @@ -295,19 +295,6 @@ class CI_DB_mysql_driver extends CI_DB { // -------------------------------------------------------------------- - /** - * List databases - * - * @access private - * @return bool - */ - function _list_databases() - { - return "SHOW DATABASES"; - } - - // -------------------------------------------------------------------- - /** * List table query * diff --git a/system/database/drivers/mysql/mysql_utility.php b/system/database/drivers/mysql/mysql_utility.php index a81c915f6..b387ace9e 100644 --- a/system/database/drivers/mysql/mysql_utility.php +++ b/system/database/drivers/mysql/mysql_utility.php @@ -52,6 +52,19 @@ class CI_DB_mysql_utility extends CI_DB_utility { // -------------------------------------------------------------------- + /** + * List databases + * + * @access private + * @return bool + */ + function _list_databases() + { + return "SHOW DATABASES"; + } + + // -------------------------------------------------------------------- + /** * Drop Table * @@ -101,7 +114,7 @@ class CI_DB_mysql_utility extends CI_DB_utility { * MySQL Export * * @access private - * @param array Any preferences + * @param array Preferences * @return mixed */ function _backup($params = array()) @@ -217,7 +230,6 @@ class CI_DB_mysql_utility extends CI_DB_utility { // Build the INSERT string $output .= 'INSERT INTO '.$table.' ('.$field_str.') VALUES ('.$val_str.');'.$newline; - } $output .= $newline.$newline; diff --git a/system/database/drivers/mysqli/mysqli_driver.php b/system/database/drivers/mysqli/mysqli_driver.php index a2c380355..4fd9f3aaa 100644 --- a/system/database/drivers/mysqli/mysqli_driver.php +++ b/system/database/drivers/mysqli/mysqli_driver.php @@ -287,19 +287,6 @@ class CI_DB_mysqli_driver extends CI_DB { // -------------------------------------------------------------------- - /** - * List databases - * - * @access private - * @return bool - */ - function _list_databases() - { - return "SHOW DATABASES"; - } - - // -------------------------------------------------------------------- - /** * List table query * diff --git a/system/database/drivers/mysqli/mysqli_utility.php b/system/database/drivers/mysqli/mysqli_utility.php index f5b98b11f..a40441d20 100644 --- a/system/database/drivers/mysqli/mysqli_utility.php +++ b/system/database/drivers/mysqli/mysqli_utility.php @@ -62,6 +62,19 @@ class CI_DB_mysqli_utility extends CI_DB_utility { { return "DROP TABLE IF EXISTS ".$this->db->_escape_table($name); } + + // -------------------------------------------------------------------- + + /** + * List databases + * + * @access private + * @return bool + */ + function _list_databases() + { + return "SHOW DATABASES"; + } // -------------------------------------------------------------------- diff --git a/system/database/drivers/oci8/oci8_driver.php b/system/database/drivers/oci8/oci8_driver.php index b43b4c41f..e83c640bd 100644 --- a/system/database/drivers/oci8/oci8_driver.php +++ b/system/database/drivers/oci8/oci8_driver.php @@ -399,19 +399,6 @@ class CI_DB_oci8_driver extends CI_DB { return $row->NUMROWS; } - // -------------------------------------------------------------------- - - /** - * List databases - * - * @access private - * @return bool - */ - function _list_databases() - { - return FALSE; - } - // -------------------------------------------------------------------- /** diff --git a/system/database/drivers/oci8/oci8_utility.php b/system/database/drivers/oci8/oci8_utility.php index b6503de63..b1d539ad6 100644 --- a/system/database/drivers/oci8/oci8_utility.php +++ b/system/database/drivers/oci8/oci8_utility.php @@ -53,6 +53,19 @@ class CI_DB_oci8_utility extends CI_DB_utility { // -------------------------------------------------------------------- + /** + * List databases + * + * @access private + * @return bool + */ + function _list_databases() + { + return FALSE; + } + + // -------------------------------------------------------------------- + /** * Drop Table * diff --git a/system/database/drivers/odbc/odbc_driver.php b/system/database/drivers/odbc/odbc_driver.php index 0f002cc1b..4bd6e1106 100644 --- a/system/database/drivers/odbc/odbc_driver.php +++ b/system/database/drivers/odbc/odbc_driver.php @@ -262,24 +262,6 @@ class CI_DB_odbc_driver extends CI_DB { // -------------------------------------------------------------------- - /** - * List databases - * - * @access private - * @return bool - */ - function _list_databases() - { - // Not sure if ODBC lets you list all databases... - if ($this->db_debug) - { - return $this->display_error('db_unsuported_feature'); - } - return FALSE; - } - - // -------------------------------------------------------------------- - /** * Show table query * diff --git a/system/database/drivers/odbc/odbc_utility.php b/system/database/drivers/odbc/odbc_utility.php index 6d0fb79f1..5a0e365ef 100644 --- a/system/database/drivers/odbc/odbc_utility.php +++ b/system/database/drivers/odbc/odbc_utility.php @@ -65,6 +65,24 @@ class CI_DB_odbc_utility extends CI_DB_utility { // -------------------------------------------------------------------- + /** + * List databases + * + * @access private + * @return bool + */ + function _list_databases() + { + // Not sure if ODBC lets you list all databases... + if ($this->db->db_debug) + { + return $this->db->display_error('db_unsuported_feature'); + } + return FALSE; + } + + // -------------------------------------------------------------------- + /** * Drop Table * diff --git a/system/database/drivers/postgre/postgre_driver.php b/system/database/drivers/postgre/postgre_driver.php index f14395638..340d65046 100644 --- a/system/database/drivers/postgre/postgre_driver.php +++ b/system/database/drivers/postgre/postgre_driver.php @@ -289,19 +289,6 @@ class CI_DB_postgre_driver extends CI_DB { // -------------------------------------------------------------------- - /** - * List databases - * - * @access private - * @return bool - */ - function _list_databases() - { - return "SELECT datname FROM pg_database"; - } - - // -------------------------------------------------------------------- - /** * Show table query * diff --git a/system/database/drivers/postgre/postgre_utility.php b/system/database/drivers/postgre/postgre_utility.php index 46c98cc7d..038aa26cd 100644 --- a/system/database/drivers/postgre/postgre_utility.php +++ b/system/database/drivers/postgre/postgre_utility.php @@ -53,6 +53,19 @@ class CI_DB_postgre_utility extends CI_DB_utility { // -------------------------------------------------------------------- + /** + * List databases + * + * @access private + * @return bool + */ + function _list_databases() + { + return "SELECT datname FROM pg_database"; + } + + // -------------------------------------------------------------------- + /** * Drop Table * diff --git a/system/database/drivers/sqlite/sqlite_driver.php b/system/database/drivers/sqlite/sqlite_driver.php index f57c4b8c8..9da50b676 100644 --- a/system/database/drivers/sqlite/sqlite_driver.php +++ b/system/database/drivers/sqlite/sqlite_driver.php @@ -281,28 +281,6 @@ class CI_DB_sqlite_driver extends CI_DB { // -------------------------------------------------------------------- - /** - * List databases - * - * I don't believe you can do a database listing with SQLite - * since each database is its own file. I suppose we could - * try reading a directory looking for SQLite files, but - * that doesn't seem like a terribly good idea - * - * @access private - * @return bool - */ - function _list_databases() - { - if ($this->db_debug) - { - return $this->display_error('db_unsuported_feature'); - } - return array(); - } - - // -------------------------------------------------------------------- - /** * List table query * diff --git a/system/database/drivers/sqlite/sqlite_utility.php b/system/database/drivers/sqlite/sqlite_utility.php index 801660d94..19b06bd6d 100644 --- a/system/database/drivers/sqlite/sqlite_utility.php +++ b/system/database/drivers/sqlite/sqlite_utility.php @@ -63,6 +63,28 @@ class CI_DB_sqlite_utility extends CI_DB_utility { // -------------------------------------------------------------------- + /** + * List databases + * + * I don't believe you can do a database listing with SQLite + * since each database is its own file. I suppose we could + * try reading a directory looking for SQLite files, but + * that doesn't seem like a terribly good idea + * + * @access private + * @return bool + */ + function _list_databases() + { + if ($this->db_debug) + { + return $this->display_error('db_unsuported_feature'); + } + return array(); + } + + // -------------------------------------------------------------------- + /** * Drop Table * -- cgit v1.2.3-24-g4f1b From 6ae57e09a1c9570a6d1f4b2410313715095a7e62 Mon Sep 17 00:00:00 2001 From: admin Date: Sun, 1 Oct 2006 07:59:45 +0000 Subject: --- system/libraries/Zip.php | 296 +++++++++++++++++++++++++++++++---------------- 1 file changed, 196 insertions(+), 100 deletions(-) (limited to 'system') diff --git a/system/libraries/Zip.php b/system/libraries/Zip.php index 1fd0e7059..aa264386d 100644 --- a/system/libraries/Zip.php +++ b/system/libraries/Zip.php @@ -21,9 +21,6 @@ * This class is based on a library aquired at Zend: * http://www.zend.com/codex.php?id=696&single=1 * - * I'm not sure this library is all that reliable, and the - * directory feature doesn't seem to work right, but it's the only - * zip compressor I'm aware of -- Rick Ellis * * @package CodeIgniter * @subpackage Libraries @@ -31,125 +28,224 @@ * @author Rick Ellis * @link http://www.codeigniter.com/user_guide/general/encryption.html */ -class Zip { - - var $zdata = array(); - var $cdir = array(); - var $offset = 0; +class Zip { + + var $zipdata = array(); + var $directory = array(); + var $offset = 0; + var $zipfile = ''; /** - * Add a Directory + * Add Directory + * + * Lets you add a virtual directory into which you can place files. * * @access public - * @param string + * @param string the directory name * @return void - */ - function add_dir($name) - { - $name =str_replace ("\\", "/", $name); - - $fd = "\x50\x4b\x03\x04\x0a\x00\x00\x00\x00\x00\x00\x00\x00\x00" - .pack("V", 0) - .pack("V", 0) - .pack("V", 0) - .pack("v", strlen($name)) - .pack("v", 0) - .$name; - - $this->cdata[] = $fd; - - $cd = "\x50\x4b\x01\x02\x00\x00\x0a\x00\x00\x00\x00\x00\x00\x00\x00\x00" - .pack("V", 0) - .pack("V", 0) - .pack("V", 0) - .pack("v", strlen ($name)) - .pack("v", 0) - .pack("v", 0) - .pack("v", 0) - .pack("v", 0) - .pack("V", 16) - .pack("V", $this->offset) - .$name; - - $this->offset = strlen(implode('', $this->cdata)); - - $this->cdir[] = $cd; - } + */ + function add_dir($dir) + { + $this->zipfile = ''; + + $dir = str_replace("\\", "/", $dir); + + $this->zipdata[] = "\x50\x4b\x03\x04\x0a\x00\x00\x00\x00\x00\x00\x00\x00\x00" + .pack('V', 0) + .pack('V', 0) + .pack('V', 0) + .pack('v', strlen($dir)) + .pack('v', 0) + .$dir + .pack('V', 0) + .pack('V', 0) + .pack('V', 0); + + $newoffset = strlen(implode('', $this->zipdata)); + + $record = "\x50\x4b\x01\x02\x00\x00\x0a\x00\x00\x00\x00\x00\x00\x00\x00\x00" + .pack('V',0) + .pack('V',0) + .pack('V',0) + .pack('v', strlen($dir)) + .pack('v', 0) + .pack('v', 0) + .pack('v', 0) + .pack('v', 0) + .pack('V', 16) + .pack('V', $this->offset) + .$dir; + + $this->offset = $newoffset; + $this->directory[] = $record; + } // -------------------------------------------------------------------- /** - * Add a File + * Add File + * + * 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 string + * @param string the file name + * @param string the data to be encoded * @return void */ - function add_file($data, $name) - { - $name = str_replace("\\", "/", $name); - - $u_len = strlen($data); - $crc = crc32($data); - $data = gzcompress($data); - $data = substr(substr($data, 0,strlen ($data) - 4), 2); - $c_len = strlen($data); - - $fd = "\x50\x4b\x03\x04\x14\x00\x00\x00\x08\x00\x00\x00\x00\x00" - .pack("V", $crc) - .pack("V", $c_len) - .pack("V", $u_len) - .pack("v", strlen($name)) - .pack("v", 0) - .$name - .$data - .pack("V", $crc) - .pack("V", $c_len) - .pack("V", $u_len); - - $this->zdata[] = $fd; - - $cd = "\x50\x4b\x01\x02\x00\x00\x14\x00\x00\x00\x08\x00\x00\x00\x00\x00" - .pack("V", $crc) - .pack("V", $c_len) - .pack("V", $u_len) - .pack("v", strlen ($name)) - .pack("v", 0) - .pack("v", 0) - .pack("v", 0) - .pack("v", 0) - .pack("V", 32 ) - .pack("V", $this->offset) - .$name; - - $this->offset = strlen(implode('', $this->zdata)); - - $this->cdir[] = $cd; - } + function add_file($filename, $data) + { + $this->zipfile = ''; + + $filename = str_replace("\\", "/", $filename); + + $oldlen = strlen($data); + $crc32 = crc32($data); + + $gzdata = gzcompress($data); + $gzdata = substr(substr($gzdata, 0, strlen($gzdata) - 4), 2); + $newlen = strlen($gzdata); + + $this->zipdata[] = "\x50\x4b\x03\x04\x14\x00\x00\x00\x08\x00\x00\x00\x00\x00" + .pack('V', $crc32) + .pack('V', $newlen) + .pack('V', $oldlen) + .pack('v', strlen($filename)) + .pack('v', 0) + .$filename + .$gzdata + .pack('V', $crc32) + .pack('V', $newlen) + .pack('V', $oldlen); + + $newoffset = strlen(implode("", $this->zipdata)); + + $record = "\x50\x4b\x01\x02\x00\x00\x14\x00\x00\x00\x08\x00\x00\x00\x00\x00" + .pack('V', $crc32) + .pack('V', $newlen) + .pack('V', $oldlen) + .pack('v', strlen($filename)) + .pack('v', 0) + .pack('v', 0) + .pack('v', 0) + .pack('v', 0) + .pack('V', 32) + .pack('V', $this->offset); + + $this->offset = $newoffset; + $this->directory[] = $record.$filename; + } // -------------------------------------------------------------------- /** - * Output the zip file + * Read the content of a file * * @access public + * @param string the file path * @return string */ - function output_zipfile() - { - $data = implode("", $this->zdata); - $cdir = implode("", $this->cdir); + function read_file($filepath) + { + if ( ! file_exists($filepath)) + { + return FALSE; + } + + return file_get_contents($filepath); + } + + // -------------------------------------------------------------------- - return $data - .$cdir - ."\x50\x4b\x05\x06\x00\x00\x00\x00" - .pack("v", sizeof($this->cdir)) - .pack("v", sizeof($this->cdir)) - .pack("V", strlen($cdir)) - .pack("V", strlen($data)) - ."\x00\x00"; - } + /** + * Get the Zip file + * + * @access public + * @return binary string + */ + function get_zip() + { + if ($this->zipfile != '') + { + return $this->zipfile; + } + + $data = implode('', $this->zipdata); + $dir = implode('', $this->directory); + + $this->zipfile = $data.$dir."\x50\x4b\x05\x06\x00\x00\x00\x00" + .pack('v', sizeof($this->directory)) + .pack('v', sizeof($this->directory)) + .pack('V', strlen($dir)) + .pack('V', strlen($data)) + ."\x00\x00"; + + return $this->zipfile; + } + + // -------------------------------------------------------------------- + /** + * Write File + * + * Lets you write a file + * + * @access public + * @param string the file name + * @param string the data to be encoded + * @return bool + */ + function write_file($filename, $data) + { + if ( ! ($fp = fopen($filename, "wb"))) + { + return FALSE; + } + + flock($fp, LOCK_EX); + fwrite($fp, $data); + 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, $data) + { + if (strstr($_SERVER['HTTP_USER_AGENT'], "MSIE")) + { + header('Content-Type: application/x-zip'); + header('Content-Disposition: inline; filename="'.$filename.'"'); + header('Expires: 0'); + header('Cache-Control: must-revalidate, post-check=0, pre-check=0'); + header("Content-Transfer-Encoding: binary"); + header('Pragma: public'); + header("Content-Length: ".strlen($data)); + } + else + { + header('Content-Type: application/x-zip'); + header('Content-Disposition: attachment; filename="'.$filename.'"'); + header("Content-Transfer-Encoding: binary"); + header('Expires: 0'); + header('Pragma: no-cache'); + header("Content-Length: ".strlen($data)); + } + + echo $data; + } + } -// END CLASS ?> \ No newline at end of file -- cgit v1.2.3-24-g4f1b From 5dc8042015dbd25329ed1e0df8d4d34ee08dc22a Mon Sep 17 00:00:00 2001 From: admin Date: Sun, 1 Oct 2006 18:53:35 +0000 Subject: --- system/libraries/Unit.php | 331 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 331 insertions(+) create mode 100644 system/libraries/Unit.php (limited to 'system') diff --git a/system/libraries/Unit.php b/system/libraries/Unit.php new file mode 100644 index 000000000..0df78c253 --- /dev/null +++ b/system/libraries/Unit.php @@ -0,0 +1,331 @@ +active == FALSE) + return; + + if (in_array($expected, array('is_string', 'is_bool', 'is_true', 'is_false', 'is_int', 'is_numeric', 'is_float', 'is_double', 'is_array', 'is_null'), TRUE)) + { + $expected = str_replace('is_float', 'is_double', $expected); + $result = ($expected($test)) ? TRUE : FALSE; + $extype = str_replace(array('true', 'false'), 'bool', str_replace('is_', '', $expected)); + } + else + { + if ($this->strict == TRUE) + $result = ($test === $expected) ? TRUE : FALSE; + else + $result = ($test == $expected) ? TRUE : FALSE; + + $extype = gettype($expected); + } + + $back = $this->_backtrace(); + + $report[] = array ( + 'test_name' => $test_name, + 'test_datatype' => gettype($test), + 'res_datatype' => $extype, + 'result' => ($result === TRUE) ? 'passed' : 'failed', + 'file' => $back['file'], + 'line' => $back['line'] + ); + + $this->results[] = $report; + + return($this->report($this->result($report))); + } + + // -------------------------------------------------------------------- + + /** + * Generate a report + * + * Displays a table with the test data + * + * @access public + * @return string + */ + function report($result = array()) + { + if (count($result) == 0) + { + $result = $this->result(); + } + + $this->_parse_template(); + + $r = ''; + foreach ($result as $res) + { + $table = ''; + + foreach ($res as $key => $val) + { + $temp = $this->_template_rows; + $temp = str_replace('{item}', $key, $temp); + $temp = str_replace('{result}', $val, $temp); + $table .= $temp; + } + + $r .= str_replace('{rows}', $table, $this->_template); + } + + return $r; + } + + // -------------------------------------------------------------------- + + /** + * Use strict comparison + * + * Causes the evaluation to use === rather then == + * + * @access public + * @param bool + * @return null + */ + function use_strict($state = TRUE) + { + $this->strict = ($state == FALSE) ? FALSE : TRUE; + } + + // -------------------------------------------------------------------- + + /** + * Make Unit testing active + * + * Enables/disables unit testing + * + * @access public + * @param bool + * @return null + */ + function active($state = TRUE) + { + $this->active = ($state == FALSE) ? FALSE : TRUE; + } + + // -------------------------------------------------------------------- + + /** + * Result Array + * + * Returns the raw result data + * + * @access public + * @return array + */ + function result($results = array()) + { + $obj =& get_instance(); + $obj->load->language('unit_test'); + + if (count($results) == 0) + { + $results = $this->results; + } + + $retval = array(); + foreach ($results as $result) + { + $temp = array(); + foreach ($result as $key => $val) + { + if (is_array($val)) + { + foreach ($val as $k => $v) + { + if (FALSE !== ($line = $obj->lang->line(strtolower('ut_'.$v)))) + { + $v = $line; + } + $temp[$obj->lang->line('ut_'.$k)] = $v; + } + } + else + { + if (FALSE !== ($line = $obj->lang->line(strtolower('ut_'.$val)))) + { + $val = $line; + } + $temp[$obj->lang->line('ut_'.$key)] = $val; + } + } + + $retval[] = $temp; + } + + return $retval; + } + + // -------------------------------------------------------------------- + + /** + * Set the template + * + * This lets us set the template to be used to display results + * + * @access public + * @params string + * @return void + */ + function set_template($template) + { + $this->_template = $template; + } + + // -------------------------------------------------------------------- + + /** + * Generate a backtrace + * + * This lets us show file names and line numbers + * + * @access private + * @return array + */ + function _backtrace() + { + if (function_exists('debug_backtrace')) + { + $back = debug_backtrace(); + + $file = ( ! isset($back['1']['file'])) ? '' : $back['1']['file']; + $line = ( ! isset($back['1']['line'])) ? '' : $back['1']['line']; + + return array('file' => $file, 'line' => $line); + } + return array('file' => 'Unknown', 'line' => 'Unknown'); + } + + // -------------------------------------------------------------------- + + /** + * Get Default Template + * + * @access private + * @return string + */ + function _default_template() + { + $this->_template = ' +
+ + {rows} +
'; + + $this->_template_rows = ' + + {item} + {result} + + '; + } + + // -------------------------------------------------------------------- + + /** + * Parse Template + * + * Harvests the data within the template {pseudo-variables} + * + * @access private + * @return void + */ + function _parse_template() + { + if ( ! is_null($this->_template_rows)) + { + return; + } + + if (is_null($this->_template)) + { + $this->_default_template(); + return; + } + + if ( ! preg_match("/\{rows\}(.*?)\{\/rows\}/si", $this->_template, $match)) + { + $this->_default_template(); + return; + } + + $this->_template_rows = $match['1']; + $this->_template = str_replace($match['0'], '{rows}', $this->_template); + } + +} +// END Unit_test Class + +/** + * Helper functions to test boolean true/false + * + * + * @access private + * @return bool + */ +function is_true($test) +{ + return (is_bool($test) AND $test === TRUE) ? TRUE : FALSE; +} +function is_false($test) +{ + return (is_bool($test) AND $test === FALSE) ? TRUE : FALSE; +} + +?> \ No newline at end of file -- cgit v1.2.3-24-g4f1b From 844cdfd5294c2e252c1fa2a110be02dcce8f48a8 Mon Sep 17 00:00:00 2001 From: admin Date: Sun, 1 Oct 2006 19:00:56 +0000 Subject: --- system/libraries/Unit_test.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'system') diff --git a/system/libraries/Unit_test.php b/system/libraries/Unit_test.php index 78b92edb2..0df78c253 100644 --- a/system/libraries/Unit_test.php +++ b/system/libraries/Unit_test.php @@ -26,7 +26,7 @@ * @author Rick Ellis * @link http://www.codeigniter.com/user_guide/libraries/uri.html */ -class CI_Unit_test { +class CI_Unit { var $active = TRUE; var $results = array(); @@ -34,7 +34,7 @@ class CI_Unit_test { var $_template = NULL; var $_template_rows = NULL; - function CI_Unit_test() + function CI_Unit() { log_message('debug', "Unit Testing Class Initialized"); } -- cgit v1.2.3-24-g4f1b From 24dd7e71d2587c4290c85bc85e0e181b29ab0539 Mon Sep 17 00:00:00 2001 From: admin Date: Sun, 1 Oct 2006 19:02:29 +0000 Subject: --- system/database/DB_utility.php | 40 ++--- system/libraries/Controller.php | 21 +-- system/libraries/Unit_test.php | 331 ---------------------------------------- system/libraries/Zip.php | 152 ++++++++++++------ 4 files changed, 138 insertions(+), 406 deletions(-) delete mode 100644 system/libraries/Unit_test.php (limited to 'system') diff --git a/system/database/DB_utility.php b/system/database/DB_utility.php index e568bce02..2748a4407 100644 --- a/system/database/DB_utility.php +++ b/system/database/DB_utility.php @@ -216,7 +216,7 @@ class CI_DB_utility { // -------------------------------------------------------------------- /** - * Generate CVS from a query result object + * Generate CSV from a query result object * * @access public * @param object The query result object @@ -224,7 +224,7 @@ class CI_DB_utility { * @param string The newline character - \n by default * @return string */ - function cvs_from_result($query, $delim = "\t", $newline = "\n") + function csv_from_result($query, $delim = "\t", $newline = "\n") { if ( ! is_object($query) OR ! method_exists($query, 'field_names')) { @@ -502,6 +502,7 @@ class CI_DB_utility { { $obj->output->set_header('Content-Type: '.$mime); $obj->output->set_header('Content-Disposition: inline; filename="'.$prefs['filename'].'.'.$ext[$prefs['format']].'"'); + $obj->output->set_header('Content-Transfer-Encoding: binary'); $obj->output->set_header('Expires: 0'); $obj->output->set_header('Cache-Control: must-revalidate, post-check=0, pre-check=0'); $obj->output->set_header('Pragma: public'); @@ -510,26 +511,27 @@ class CI_DB_utility { { $obj->output->set_header('Content-Type: '.$mime); $obj->output->set_header('Content-Disposition: attachment; filename="'.$prefs['filename'].'.'.$ext[$prefs['format']].'"'); + $obj->output->set_header('Content-Transfer-Encoding: binary'); $obj->output->set_header('Expires: 0'); $obj->output->set_header('Pragma: no-cache'); } - - - // Write the file based on type - switch ($prefs['format']) - { - case 'gzip' : $obj->output->set_output(gzencode($this->_backup($prefs))); - break; - case 'txt' : $obj->output->set_output($this->_backup($prefs)); - break; - default : - require BASEPATH.'libraries/Zip.php'; - - $zip = new Zip; - $zip->add_file($this->_backup($prefs), $prefs['filename'].'.sql'); - $obj->output->set_output($zip->output_zipfile()); - break; - } + + + // Write the file based on type + switch ($prefs['format']) + { + case 'gzip' : $obj->output->set_output(gzencode($this->_backup($prefs))); + break; + case 'txt' : $obj->output->set_output($this->_backup($prefs)); + break; + default : + require BASEPATH.'libraries/Zip.php'; + + $zip = new Zip; + $zip->add_file($this->_backup($prefs), $prefs['filename'].'.sql'); + $obj->output->set_output($zip->output_zipfile()); + break; + } return TRUE; } diff --git a/system/libraries/Controller.php b/system/libraries/Controller.php index 51f455023..c02074fca 100644 --- a/system/libraries/Controller.php +++ b/system/libraries/Controller.php @@ -80,6 +80,13 @@ class Controller extends CI_Base { { // Prep the class name $class = strtolower(str_replace(EXT, '', $class)); + + // Bug fix for backward compat. + // Kill this at some point in the future + if ($class == 'unit_test') + { + $class = 'unit'; + } // Is this a class extension request? if (substr($class, 0, 3) == 'my_') @@ -168,9 +175,8 @@ class Controller extends CI_Base { * @return null */ function _ci_init_class($class, $prefix = '', $config = NULL) - { + { // Is there an associated config file for this class? - if ($config == NULL) { if (file_exists(APPPATH.'config/'.$class.EXT)) @@ -185,22 +191,19 @@ class Controller extends CI_Base { } else { - $name = $prefix.ucfirst($class); + $name = $prefix.$class; } - - $remap = array( - 'Unit_test' => 'unit' - ); $varname = ( ! isset($remap[$class])) ? $class : $remap[$class]; - + $varname = strtolower($varname); + // Instantiate the class if ($config !== NULL) { $this->$varname = new $name($config); } else - { + { $this->$varname = new $name; } } diff --git a/system/libraries/Unit_test.php b/system/libraries/Unit_test.php deleted file mode 100644 index 0df78c253..000000000 --- a/system/libraries/Unit_test.php +++ /dev/null @@ -1,331 +0,0 @@ -active == FALSE) - return; - - if (in_array($expected, array('is_string', 'is_bool', 'is_true', 'is_false', 'is_int', 'is_numeric', 'is_float', 'is_double', 'is_array', 'is_null'), TRUE)) - { - $expected = str_replace('is_float', 'is_double', $expected); - $result = ($expected($test)) ? TRUE : FALSE; - $extype = str_replace(array('true', 'false'), 'bool', str_replace('is_', '', $expected)); - } - else - { - if ($this->strict == TRUE) - $result = ($test === $expected) ? TRUE : FALSE; - else - $result = ($test == $expected) ? TRUE : FALSE; - - $extype = gettype($expected); - } - - $back = $this->_backtrace(); - - $report[] = array ( - 'test_name' => $test_name, - 'test_datatype' => gettype($test), - 'res_datatype' => $extype, - 'result' => ($result === TRUE) ? 'passed' : 'failed', - 'file' => $back['file'], - 'line' => $back['line'] - ); - - $this->results[] = $report; - - return($this->report($this->result($report))); - } - - // -------------------------------------------------------------------- - - /** - * Generate a report - * - * Displays a table with the test data - * - * @access public - * @return string - */ - function report($result = array()) - { - if (count($result) == 0) - { - $result = $this->result(); - } - - $this->_parse_template(); - - $r = ''; - foreach ($result as $res) - { - $table = ''; - - foreach ($res as $key => $val) - { - $temp = $this->_template_rows; - $temp = str_replace('{item}', $key, $temp); - $temp = str_replace('{result}', $val, $temp); - $table .= $temp; - } - - $r .= str_replace('{rows}', $table, $this->_template); - } - - return $r; - } - - // -------------------------------------------------------------------- - - /** - * Use strict comparison - * - * Causes the evaluation to use === rather then == - * - * @access public - * @param bool - * @return null - */ - function use_strict($state = TRUE) - { - $this->strict = ($state == FALSE) ? FALSE : TRUE; - } - - // -------------------------------------------------------------------- - - /** - * Make Unit testing active - * - * Enables/disables unit testing - * - * @access public - * @param bool - * @return null - */ - function active($state = TRUE) - { - $this->active = ($state == FALSE) ? FALSE : TRUE; - } - - // -------------------------------------------------------------------- - - /** - * Result Array - * - * Returns the raw result data - * - * @access public - * @return array - */ - function result($results = array()) - { - $obj =& get_instance(); - $obj->load->language('unit_test'); - - if (count($results) == 0) - { - $results = $this->results; - } - - $retval = array(); - foreach ($results as $result) - { - $temp = array(); - foreach ($result as $key => $val) - { - if (is_array($val)) - { - foreach ($val as $k => $v) - { - if (FALSE !== ($line = $obj->lang->line(strtolower('ut_'.$v)))) - { - $v = $line; - } - $temp[$obj->lang->line('ut_'.$k)] = $v; - } - } - else - { - if (FALSE !== ($line = $obj->lang->line(strtolower('ut_'.$val)))) - { - $val = $line; - } - $temp[$obj->lang->line('ut_'.$key)] = $val; - } - } - - $retval[] = $temp; - } - - return $retval; - } - - // -------------------------------------------------------------------- - - /** - * Set the template - * - * This lets us set the template to be used to display results - * - * @access public - * @params string - * @return void - */ - function set_template($template) - { - $this->_template = $template; - } - - // -------------------------------------------------------------------- - - /** - * Generate a backtrace - * - * This lets us show file names and line numbers - * - * @access private - * @return array - */ - function _backtrace() - { - if (function_exists('debug_backtrace')) - { - $back = debug_backtrace(); - - $file = ( ! isset($back['1']['file'])) ? '' : $back['1']['file']; - $line = ( ! isset($back['1']['line'])) ? '' : $back['1']['line']; - - return array('file' => $file, 'line' => $line); - } - return array('file' => 'Unknown', 'line' => 'Unknown'); - } - - // -------------------------------------------------------------------- - - /** - * Get Default Template - * - * @access private - * @return string - */ - function _default_template() - { - $this->_template = ' -
- - {rows} -
'; - - $this->_template_rows = ' - - {item} - {result} - - '; - } - - // -------------------------------------------------------------------- - - /** - * Parse Template - * - * Harvests the data within the template {pseudo-variables} - * - * @access private - * @return void - */ - function _parse_template() - { - if ( ! is_null($this->_template_rows)) - { - return; - } - - if (is_null($this->_template)) - { - $this->_default_template(); - return; - } - - if ( ! preg_match("/\{rows\}(.*?)\{\/rows\}/si", $this->_template, $match)) - { - $this->_default_template(); - return; - } - - $this->_template_rows = $match['1']; - $this->_template = str_replace($match['0'], '{rows}', $this->_template); - } - -} -// END Unit_test Class - -/** - * Helper functions to test boolean true/false - * - * - * @access private - * @return bool - */ -function is_true($test) -{ - return (is_bool($test) AND $test === TRUE) ? TRUE : FALSE; -} -function is_false($test) -{ - return (is_bool($test) AND $test === FALSE) ? TRUE : FALSE; -} - -?> \ No newline at end of file diff --git a/system/libraries/Zip.php b/system/libraries/Zip.php index aa264386d..2ffed9fe2 100644 --- a/system/libraries/Zip.php +++ b/system/libraries/Zip.php @@ -18,9 +18,11 @@ /** * Zip Compression Class * - * This class is based on a library aquired at Zend: + * This class is based on a library I found at Zend: * http://www.zend.com/codex.php?id=696&single=1 * + * The original library is a little rough around the edges so I + * refactored it and added several additional methods -- Rick Ellis * * @package CodeIgniter * @subpackage Libraries @@ -28,12 +30,18 @@ * @author Rick Ellis * @link http://www.codeigniter.com/user_guide/general/encryption.html */ -class Zip { - +class CI_Zip { + + var $zipfile = ''; var $zipdata = array(); var $directory = array(); var $offset = 0; - var $zipfile = ''; + + function CI_Zip() + { + log_message('debug', "Zip Compression Class Initialized"); + } + /** * Add Directory @@ -41,13 +49,33 @@ class Zip { * 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 .= '/'; + } + + $this->_add_dir($dir); + } + } + + // -------------------------------------------------------------------- + + /** + * Add Directory + * + * @access private * @param string the directory name * @return void */ - function add_dir($dir) + function _add_dir($dir) { - $this->zipfile = ''; - $dir = str_replace("\\", "/", $dir); $this->zipdata[] = "\x50\x4b\x03\x04\x0a\x00\x00\x00\x00\x00\x00\x00\x00\x00" @@ -78,27 +106,50 @@ class Zip { $this->offset = $newoffset; $this->directory[] = $record; - } - + } + // -------------------------------------------------------------------- /** - * Add File + * 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 string the file name - * @param string the data to be encoded + * @param mixed + * @param string * @return void */ - function add_file($filename, $data) + function add_data($filepath, $data = NULL) { - $this->zipfile = ''; + if (is_array($filepath)) + { + foreach ($filepath as $path => $data) + { + $this->_add_data($path, $data); + } + } + else + { + $this->_add_data($filepath, $data); + } + } - $filename = str_replace("\\", "/", $filename); + // -------------------------------------------------------------------- + + /** + * 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) + { + $filepath = str_replace("\\", "/", $filepath); $oldlen = strlen($data); $crc32 = crc32($data); @@ -111,9 +162,9 @@ class Zip { .pack('V', $crc32) .pack('V', $newlen) .pack('V', $oldlen) - .pack('v', strlen($filename)) + .pack('v', strlen($filepath)) .pack('v', 0) - .$filename + .$filepath .$gzdata .pack('V', $crc32) .pack('V', $newlen) @@ -125,7 +176,7 @@ class Zip { .pack('V', $crc32) .pack('V', $newlen) .pack('V', $oldlen) - .pack('v', strlen($filename)) + .pack('v', strlen($filepath)) .pack('v', 0) .pack('v', 0) .pack('v', 0) @@ -134,26 +185,7 @@ class Zip { .pack('V', $this->offset); $this->offset = $newoffset; - $this->directory[] = $record.$filename; - } - - // -------------------------------------------------------------------- - - /** - * Read the content of a file - * - * @access public - * @param string the file path - * @return string - */ - function read_file($filepath) - { - if ( ! file_exists($filepath)) - { - return FALSE; - } - - return file_get_contents($filepath); + $this->directory[] = $record.$filepath; } // -------------------------------------------------------------------- @@ -166,11 +198,19 @@ class Zip { */ function get_zip() { + // We cache the zip data so multiple calls + // do not require recompiling if ($this->zipfile != '') { return $this->zipfile; } + // Is there any data to return? + if (count($this->zipdata) == 0) + { + return FALSE; + } + $data = implode('', $this->zipdata); $dir = implode('', $this->directory); @@ -180,7 +220,7 @@ class Zip { .pack('V', strlen($dir)) .pack('V', strlen($data)) ."\x00\x00"; - + return $this->zipfile; } @@ -196,15 +236,15 @@ class Zip { * @param string the data to be encoded * @return bool */ - function write_file($filename, $data) + function write_zip($filepath) { - if ( ! ($fp = fopen($filename, "wb"))) + if ( ! ($fp = fopen($filepath, "wb"))) { return FALSE; } flock($fp, LOCK_EX); - fwrite($fp, $data); + fwrite($fp, $this->get_zip()); flock($fp, LOCK_UN); fclose($fp); @@ -216,13 +256,12 @@ class Zip { /** * Download * - * * @access public * @param string the file name * @param string the data to be encoded * @return bool */ - function download($filename, $data) + function download($filename) { if (strstr($_SERVER['HTTP_USER_AGENT'], "MSIE")) { @@ -232,7 +271,7 @@ class Zip { header('Cache-Control: must-revalidate, post-check=0, pre-check=0'); header("Content-Transfer-Encoding: binary"); header('Pragma: public'); - header("Content-Length: ".strlen($data)); + header("Content-Length: ".strlen($this->get_zip())); } else { @@ -241,10 +280,29 @@ class Zip { header("Content-Transfer-Encoding: binary"); header('Expires: 0'); header('Pragma: no-cache'); - header("Content-Length: ".strlen($data)); + header("Content-Length: ".strlen($this->get_zip())); } - echo $data; + echo $this->get_zip(); + } + + // -------------------------------------------------------------------- + + /** + * 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->zipfile = ''; + $this->zipdata = array(); + $this->directory = array(); + $this->offset = array(); } } -- cgit v1.2.3-24-g4f1b From 33dd95d7cb8ac2f6b8da447966a750bdb064fc48 Mon Sep 17 00:00:00 2001 From: admin Date: Sun, 1 Oct 2006 19:20:42 +0000 Subject: --- system/libraries/Zip.php | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'system') diff --git a/system/libraries/Zip.php b/system/libraries/Zip.php index 2ffed9fe2..a11699956 100644 --- a/system/libraries/Zip.php +++ b/system/libraries/Zip.php @@ -261,8 +261,13 @@ class CI_Zip { * @param string the data to be encoded * @return bool */ - function download($filename) + function download($filename = 'backup.zip') { + if ( ! preg_match("|.+?\.zip$|", $filename)) + { + $filename .= '.zip'; + } + if (strstr($_SERVER['HTTP_USER_AGENT'], "MSIE")) { header('Content-Type: application/x-zip'); -- cgit v1.2.3-24-g4f1b From 813d0acb42ea9e367115ffc7da5b6036ab36ed98 Mon Sep 17 00:00:00 2001 From: admin Date: Sun, 1 Oct 2006 20:36:39 +0000 Subject: --- system/libraries/Router.php | 31 +++++++++++++++++++++++++++---- 1 file changed, 27 insertions(+), 4 deletions(-) (limited to 'system') diff --git a/system/libraries/Router.php b/system/libraries/Router.php index c056530a3..d62cf5090 100644 --- a/system/libraries/Router.php +++ b/system/libraries/Router.php @@ -291,13 +291,26 @@ class CI_Router { { if (strtoupper($this->config->item('uri_protocol')) == 'AUTO') { - $path_info = getenv('PATH_INFO'); + // If the URL has a question mark then it's simplest to just + // build the URI string from the zero index of the $_GET array. + // This avoids having to deal with $_SERVER variables, which + // can be unreliable on some servers + if (is_array($_GET) AND count($_GET) == 1) + { + return current(array_keys($_GET)); + } + + // Is there a PATH_INFO variable? + // Note: some servers seem to have trouble with getenv() so we'll test it two ways + $path_info = (isset($_SERVER['PATH_INFO'])) ? $_SERVER['PATH_INFO'] : @getenv('PATH_INFO'); + if ($path_info != '' AND $path_info != "/".SELF) { return $path_info; } else { + // OK, how about REQUEST_URI? $req_uri = $this->_parse_request_uri(); if ($req_uri != "") @@ -306,14 +319,24 @@ class CI_Router { } else { - $path_info = getenv('ORIG_PATH_INFO'); + // Hm... maybe the ORIG_PATH_INFO variable exists? + $path_info = (isset($_SERVER['ORIG_PATH_INFO'])) ? $_SERVER['ORIG_PATH_INFO'] : @getenv('ORIG_PATH_INFO'); if ($path_info != '' AND $path_info != "/".SELF) { return $path_info; } else { - return getenv('QUERY_STRING'); + // At this point we've exhauseted all our options. + // Hopefully QUERY_STRING exists. If not, there's nothing else we can try. + $query_string = (isset($_SERVER['QUERY_STRING'])) ? $_SERVER['QUERY_STRING'] : @getenv('QUERY_STRING'); + + if ($query_string != '') + { + return $query_string; + } + + return ''; } } } @@ -327,7 +350,7 @@ class CI_Router { return $this->_parse_request_uri(); } - return getenv($uri); + return (isset($_SERVER[$uri])) ? $_SERVER[$uri] : @getenv($uri); } } -- cgit v1.2.3-24-g4f1b From 0f8015fcdc4eb7a2bedc6a04548e588b39914c60 Mon Sep 17 00:00:00 2001 From: admin Date: Sun, 1 Oct 2006 22:08:34 +0000 Subject: --- system/database/DB_utility.php | 81 +++++++++++++++++++----------------------- system/libraries/Zip.php | 6 ++-- 2 files changed, 40 insertions(+), 47 deletions(-) (limited to 'system') diff --git a/system/database/DB_utility.php b/system/database/DB_utility.php index 2748a4407..e239d75e8 100644 --- a/system/database/DB_utility.php +++ b/system/database/DB_utility.php @@ -460,10 +460,9 @@ class CI_DB_utility { return TRUE; break; default : - require BASEPATH.'libraries/Zip.php'; - $zip = new Zip; - $zip->add_file($this->_backup($prefs), $prefs['filename'].'.sql'); - write_file($path, $zip->output_zipfile()); + $obj->load->library('zip'); + $obj->zip->add_data($prefs['filename'].'.sql', $this->_backup($prefs)); + $obj->zip->archive($path); return TRUE; break; } @@ -472,65 +471,59 @@ class CI_DB_utility { // ------------------------------------------------------ - // Set the mime type used in the server header - switch ($prefs['format']) - { - case 'zip' : $mime = 'application/x-zip'; - break; - case 'gzip' : $mime = 'application/x-gzip'; - break; - default : - if (strstr($_SERVER['HTTP_USER_AGENT'], "MSIE") || strstr($_SERVER['HTTP_USER_AGENT'], "OPERA")) - { - $mime = 'application/octetstream'; - } - else - { - $mime = 'application/octet-stream'; - } - break; - } // Grab the super object $obj =& get_instance(); // Remap the file extensions $ext = array('gzip' => 'gz', 'zip' => 'zip', 'txt' => 'sql'); + + // Is a Zip file requested? + if ($prefs['format'] == 'zip') + { + $obj->load->library('zip'); + $obj->zip->add_data($prefs['filename'].'.sql', $this->_backup($prefs)); + $obj->zip->download($prefs['filename'].'.'.$ext[$prefs['format']]); + return TRUE; + } + + + // Set the mime type + switch ($prefs['format']) + { + case 'gzip' : $mime = 'application/x-gzip'; + break; + default : $mime = (strstr($_SERVER['HTTP_USER_AGENT'], "MSIE") || strstr($_SERVER['HTTP_USER_AGENT'], "OPERA")) ? 'application/octetstream' : 'application/octet-stream'; + break; + } + + $filename = $prefs['filename'].'.sql.'.$ext[$prefs['format']]; - // Send headers if (strstr($_SERVER['HTTP_USER_AGENT'], "MSIE")) { - $obj->output->set_header('Content-Type: '.$mime); - $obj->output->set_header('Content-Disposition: inline; filename="'.$prefs['filename'].'.'.$ext[$prefs['format']].'"'); - $obj->output->set_header('Content-Transfer-Encoding: binary'); - $obj->output->set_header('Expires: 0'); - $obj->output->set_header('Cache-Control: must-revalidate, post-check=0, pre-check=0'); - $obj->output->set_header('Pragma: public'); + header('Content-Type: '.$mime); + header('Content-Disposition: inline; filename="'.$filename.'"'); + header('Expires: 0'); + header('Cache-Control: must-revalidate, post-check=0, pre-check=0'); + header("Content-Transfer-Encoding: binary"); + header('Pragma: public'); } else { - $obj->output->set_header('Content-Type: '.$mime); - $obj->output->set_header('Content-Disposition: attachment; filename="'.$prefs['filename'].'.'.$ext[$prefs['format']].'"'); - $obj->output->set_header('Content-Transfer-Encoding: binary'); - $obj->output->set_header('Expires: 0'); - $obj->output->set_header('Pragma: no-cache'); + header('Content-Type: '.$mime); + header('Content-Disposition: attachment; filename="'.$filename.'"'); + header("Content-Transfer-Encoding: binary"); + header('Expires: 0'); + header('Pragma: no-cache'); } - // Write the file based on type switch ($prefs['format']) { - case 'gzip' : $obj->output->set_output(gzencode($this->_backup($prefs))); + case 'gzip' : echo gzencode($this->_backup($prefs)); break; - case 'txt' : $obj->output->set_output($this->_backup($prefs)); + case 'txt' : echo $this->_backup($prefs); break; - default : - require BASEPATH.'libraries/Zip.php'; - - $zip = new Zip; - $zip->add_file($this->_backup($prefs), $prefs['filename'].'.sql'); - $obj->output->set_output($zip->output_zipfile()); - break; } return TRUE; diff --git a/system/libraries/Zip.php b/system/libraries/Zip.php index a11699956..218388314 100644 --- a/system/libraries/Zip.php +++ b/system/libraries/Zip.php @@ -227,7 +227,7 @@ class CI_Zip { // -------------------------------------------------------------------- /** - * Write File + * Write File to the specified direcotry * * Lets you write a file * @@ -236,9 +236,9 @@ class CI_Zip { * @param string the data to be encoded * @return bool */ - function write_zip($filepath) + function archive($filepath) { - if ( ! ($fp = fopen($filepath, "wb"))) + if ( ! ($fp = @fopen($filepath, "wb"))) { return FALSE; } -- cgit v1.2.3-24-g4f1b From 78bc039b72695ab67a2d0d537b4c1f03d5d01b83 Mon Sep 17 00:00:00 2001 From: admin Date: Mon, 2 Oct 2006 02:38:50 +0000 Subject: --- system/application/config/mimes.php | 3 +- system/database/DB_utility.php | 141 ++++++------------------------------ 2 files changed, 25 insertions(+), 119 deletions(-) (limited to 'system') diff --git a/system/application/config/mimes.php b/system/application/config/mimes.php index b09cc1963..de0a91752 100644 --- a/system/application/config/mimes.php +++ b/system/application/config/mimes.php @@ -39,6 +39,7 @@ $mimes = array( 'hqx' => 'application/mac-binhex40', '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', @@ -51,7 +52,7 @@ $mimes = array( 'hqx' => 'application/mac-binhex40', 'tgz' => 'application/x-tar', 'xhtml' => 'application/xhtml+xml', 'xht' => 'application/xhtml+xml', - 'zip' => array('application/zip', 'application/x-zip-compressed'), + 'zip' => array('application/x-zip', 'application/zip', 'application/x-zip-compressed'), 'mid' => 'audio/midi', 'midi' => 'audio/midi', 'mpga' => 'audio/mpeg', diff --git a/system/database/DB_utility.php b/system/database/DB_utility.php index e239d75e8..339baa8be 100644 --- a/system/database/DB_utility.php +++ b/system/database/DB_utility.php @@ -330,10 +330,8 @@ class CI_DB_utility { $prefs = array( 'tables' => array(), 'ignore' => array(), - 'format' => 'gzip', // gzip, zip, txt - 'action' => 'download', // download, archive, echo, return 'filename' => '', - 'filepath' => '', + 'format' => 'gzip', // gzip, zip, txt 'add_drop' => TRUE, 'add_insert' => TRUE, 'newline' => "\n" @@ -385,148 +383,55 @@ class CI_DB_utility { // ------------------------------------------------------ - // Set the filename if not provided - if ($prefs['filename'] == '') + // 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()); } // ------------------------------------------------------ - - // If we are archiving the export, does this filepath exist - // and resolve to a writable directory - if ($prefs['action'] == 'archive') + + // Grab the super object + $obj =& get_instance(); + + // Was a Gzip file requested? + if ($prefs['format'] == 'gzip') { - if ($prefs['filepath'] == '' OR ! is_writable($prefs['filepath'])) - { - if ($this->db->db_debug) - { - return $this->db->display_error('db_filepath_error'); - } - - $prefs['action'] = 'download'; - } + return gzencode($this->_backup($prefs)); } // ------------------------------------------------------ - // Are we returning the backup data? If so, we're done... - if ($prefs['action'] == 'return') + // Was a text file requested? + if ($prefs['format'] == 'txt') { return $this->_backup($prefs); } - // ------------------------------------------------------ - - // Are we echoing the backup? If so, format the data and spit it at the screen... - if ($prefs['action'] == 'echo') - { - echo '
';
-			echo htmlspecialchars($this->_backup($prefs));
-			echo '
'; - - return TRUE; - } - // ------------------------------------------------------ - // Are we archiving the data to the server? - if ($prefs['action'] == 'archive') + // Was a Zip file requested? + if ($prefs['format'] == 'zip') { - // Make sure the filepath has a trailing slash - if (ereg("/$", $prefs['filepath']) === FALSE) + // If they included the .zip file extension we'll remove it + if (preg_match("|.+?\.zip$|", $prefs['filename'])) { - $prefs['filepath'] .= '/'; + $prefs['filename'] = str_replace('.zip', '', $prefs['filename']); } - - // Assemble the path and tack on the file extension - $ext = array('gzip' => 'gz', 'zip' => 'zip', 'txt' => 'sql'); - $path = $prefs['filepath'].$prefs['filename'].$ext[$prefs['format']]; - - // Load the file helper - $obj =& get_instance(); - $obj->load->helper('file'); - // Write the file based on type - switch ($prefs['format']) + // Tack on the ".sql" file extension if needed + if ( ! preg_match("|.+?\.sql$|", $prefs['filename'])) { - case 'gzip' : - write_file($path, gzencode($this->_backup($prefs))); - return TRUE; - break; - case 'txt' : - write_file($path, $this->_backup($prefs)); - return TRUE; - break; - default : - $obj->load->library('zip'); - $obj->zip->add_data($prefs['filename'].'.sql', $this->_backup($prefs)); - $obj->zip->archive($path); - return TRUE; - break; + $prefs['filename'] .= '.sql'; } - - } - // ------------------------------------------------------ - - - // Grab the super object - $obj =& get_instance(); - - // Remap the file extensions - $ext = array('gzip' => 'gz', 'zip' => 'zip', 'txt' => 'sql'); - - // Is a Zip file requested? - if ($prefs['format'] == 'zip') - { + // Load the Zip class and output it $obj->load->library('zip'); - $obj->zip->add_data($prefs['filename'].'.sql', $this->_backup($prefs)); - $obj->zip->download($prefs['filename'].'.'.$ext[$prefs['format']]); - return TRUE; + $obj->zip->add_data($prefs['filename'], $this->_backup($prefs)); + return $obj->zip->get_zip(); } - - // Set the mime type - switch ($prefs['format']) - { - case 'gzip' : $mime = 'application/x-gzip'; - break; - default : $mime = (strstr($_SERVER['HTTP_USER_AGENT'], "MSIE") || strstr($_SERVER['HTTP_USER_AGENT'], "OPERA")) ? 'application/octetstream' : 'application/octet-stream'; - break; - } - - $filename = $prefs['filename'].'.sql.'.$ext[$prefs['format']]; - - if (strstr($_SERVER['HTTP_USER_AGENT'], "MSIE")) - { - header('Content-Type: '.$mime); - header('Content-Disposition: inline; filename="'.$filename.'"'); - header('Expires: 0'); - header('Cache-Control: must-revalidate, post-check=0, pre-check=0'); - header("Content-Transfer-Encoding: binary"); - header('Pragma: public'); - } - else - { - header('Content-Type: '.$mime); - header('Content-Disposition: attachment; filename="'.$filename.'"'); - header("Content-Transfer-Encoding: binary"); - header('Expires: 0'); - header('Pragma: no-cache'); - } - - // Write the file based on type - switch ($prefs['format']) - { - case 'gzip' : echo gzencode($this->_backup($prefs)); - break; - case 'txt' : echo $this->_backup($prefs); - break; - } - - return TRUE; } -- cgit v1.2.3-24-g4f1b From 78ce3cc370efc9d63b3d473deb37c92f40002d3d Mon Sep 17 00:00:00 2001 From: admin Date: Mon, 2 Oct 2006 02:58:03 +0000 Subject: --- system/helpers/file_helper.php | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'system') diff --git a/system/helpers/file_helper.php b/system/helpers/file_helper.php index 32c0b2cdc..4c7eaa54e 100644 --- a/system/helpers/file_helper.php +++ b/system/helpers/file_helper.php @@ -42,6 +42,11 @@ function read_file($file) { return FALSE; } + + if (function_exists('file_get_contents')) + { + return file_get_contents($file); + } if ( ! $fp = @fopen($file, 'rb')) { @@ -53,7 +58,7 @@ function read_file($file) $data = ''; if (filesize($file) > 0) { - $data = fread($fp, filesize($file)); + $data =& fread($fp, filesize($file)); } flock($fp, LOCK_UN); -- cgit v1.2.3-24-g4f1b From 3cad41e56fe4edc057cf6a84952a343686376429 Mon Sep 17 00:00:00 2001 From: admin Date: Mon, 2 Oct 2006 03:21:46 +0000 Subject: --- system/database/drivers/mssql/mssql_utility.php | 16 +++ system/database/drivers/mysqli/mysqli_utility.php | 131 +++++++++++++++++++++ system/database/drivers/oci8/oci8_result.php | 6 +- system/database/drivers/oci8/oci8_utility.php | 15 +++ system/database/drivers/odbc/odbc_utility.php | 14 +++ .../database/drivers/postgre/postgre_utility.php | 14 +++ system/database/drivers/sqlite/sqlite_utility.php | 14 +++ 7 files changed, 207 insertions(+), 3 deletions(-) (limited to 'system') diff --git a/system/database/drivers/mssql/mssql_utility.php b/system/database/drivers/mssql/mssql_utility.php index 388dbe1c2..129ba6861 100644 --- a/system/database/drivers/mssql/mssql_utility.php +++ b/system/database/drivers/mssql/mssql_utility.php @@ -109,6 +109,22 @@ class CI_DB_mssql_utility extends CI_DB_utility { return return FALSE; // Is this supported in MS SQL? } + // -------------------------------------------------------------------- + + /** + * MSSQL Export + * + * @access private + * @param array Preferences + * @return mixed + */ + function _backup($params = array()) + { + // Currently unsupported + return $this->db->display_error('db_unsuported_feature'); + } + + } ?> \ No newline at end of file diff --git a/system/database/drivers/mysqli/mysqli_utility.php b/system/database/drivers/mysqli/mysqli_utility.php index a40441d20..17af40b76 100644 --- a/system/database/drivers/mysqli/mysqli_utility.php +++ b/system/database/drivers/mysqli/mysqli_utility.php @@ -108,6 +108,137 @@ class CI_DB_mysqli_utility extends CI_DB_utility { return "REPAIR TABLE ".$this->db->_escape_table($table); } + // -------------------------------------------------------------------- + + /** + * MySQLi 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 = mysqli_fetch_field($query->result_id)) + { + $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) + { + // Do a little formatting... + $v = str_replace(array("\x00", "\x0a", "\x0d", "\x1a"), array('\0', '\n', '\r', '\Z'), $v); + $v = str_replace(array("\n", "\r", "\t"), array('\n', '\r', '\t'), $v); + $v = str_replace('\\', '\\\\', $v); + $v = str_replace('\'', '\\\'', $v); + $v = str_replace('\\\n', '\n', $v); + $v = str_replace('\\\r', '\r', $v); + $v = str_replace('\\\t', '\t', $v); + + // Escape the data if it's not an integer type + $val_str .= ($is_int[$i] == FALSE) ? $this->db->escape($v) : $v; + $val_str .= ', '; + + $i++; + } + + $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; + } + + } diff --git a/system/database/drivers/oci8/oci8_result.php b/system/database/drivers/oci8/oci8_result.php index 59adda76b..30c023ddc 100644 --- a/system/database/drivers/oci8/oci8_result.php +++ b/system/database/drivers/oci8/oci8_result.php @@ -46,9 +46,9 @@ class CI_DB_oci8_result extends CI_DB_result { $rowcount = count($this->result_array); @ociexecute($this->stmt_id); if ($this->curs_id) - { - @ociexecute($this->curs_id); - } + { + @ociexecute($this->curs_id); + } return $rowcount; } diff --git a/system/database/drivers/oci8/oci8_utility.php b/system/database/drivers/oci8/oci8_utility.php index b1d539ad6..96be09506 100644 --- a/system/database/drivers/oci8/oci8_utility.php +++ b/system/database/drivers/oci8/oci8_utility.php @@ -109,6 +109,21 @@ class CI_DB_oci8_utility extends CI_DB_utility { return 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'); + } + } ?> \ No newline at end of file diff --git a/system/database/drivers/odbc/odbc_utility.php b/system/database/drivers/odbc/odbc_utility.php index 5a0e365ef..dc62df9f0 100644 --- a/system/database/drivers/odbc/odbc_utility.php +++ b/system/database/drivers/odbc/odbc_utility.php @@ -141,6 +141,20 @@ class CI_DB_odbc_utility extends CI_DB_utility { 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'); + } } diff --git a/system/database/drivers/postgre/postgre_utility.php b/system/database/drivers/postgre/postgre_utility.php index 038aa26cd..0c265de16 100644 --- a/system/database/drivers/postgre/postgre_utility.php +++ b/system/database/drivers/postgre/postgre_utility.php @@ -109,6 +109,20 @@ class CI_DB_postgre_utility extends CI_DB_utility { return return FALSE; } + // -------------------------------------------------------------------- + + /** + * Postgre Export + * + * @access private + * @param array Preferences + * @return mixed + */ + function _backup($params = array()) + { + // Currently unsupported + return $this->db->display_error('db_unsuported_feature'); + } } diff --git a/system/database/drivers/sqlite/sqlite_utility.php b/system/database/drivers/sqlite/sqlite_utility.php index 19b06bd6d..9cb2cf027 100644 --- a/system/database/drivers/sqlite/sqlite_utility.php +++ b/system/database/drivers/sqlite/sqlite_utility.php @@ -134,6 +134,20 @@ class CI_DB_sqlite_utility extends CI_DB_utility { return 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'); + } } -- cgit v1.2.3-24-g4f1b From e8f6eb62a0600daf5b192746e1eed3e81516bc92 Mon Sep 17 00:00:00 2001 From: admin Date: Mon, 2 Oct 2006 06:46:16 +0000 Subject: --- system/database/DB_cache.php | 32 +++++++++++ system/database/DB_driver.php | 107 +++++++++++++++++++++++++++++++++--- system/database/DB_utility.php | 8 +-- system/helpers/date_helper.php | 38 ++++++++++++- system/language/english/db_lang.php | 2 + 5 files changed, 174 insertions(+), 13 deletions(-) (limited to 'system') diff --git a/system/database/DB_cache.php b/system/database/DB_cache.php index 086958d3d..4721f32c3 100644 --- a/system/database/DB_cache.php +++ b/system/database/DB_cache.php @@ -39,6 +39,38 @@ class CI_DB_cache { // -------------------------------------------------------------------- + + function cache_exists($sql) + { + + + } + + + function get_cache($sql) + { + + + } + + + function delete_cache() + { + + } + + + function delete_all_caches() + { + + + } + + + + + + } ?> \ No newline at end of file diff --git a/system/database/DB_driver.php b/system/database/DB_driver.php index 81af466ef..73c723d96 100644 --- a/system/database/DB_driver.php +++ b/system/database/DB_driver.php @@ -41,11 +41,13 @@ class CI_DB_driver { var $conn_id = FALSE; var $result_id = FALSE; var $db_debug = FALSE; + var $query_caching = FALSE; + var $cache_dir = ''; var $benchmark = 0; var $query_count = 0; var $bind_marker = '?'; var $queries = array(); - var $cache = array(); + var $data_cache = array(); var $trans_enabled = TRUE; var $_trans_depth = 0; var $_trans_failure = FALSE; // Used with transactions to determine if a rollback should occur @@ -55,6 +57,7 @@ class CI_DB_driver { var $curs_id; var $limit_used; + /** * Constructor. Accepts one parameter containing the database @@ -214,6 +217,21 @@ class CI_DB_driver { return FALSE; } + // Is query caching enabled? If the query is a "read type" we'll + // grab the previously cached query if it exists and return it. + if ($this->query_caching == TRUE) + { + if (stristr($sql, 'SELECT')) + { + $CACHE =& _load_cache_class(); + + if (FALSE !== ($CACHE->cache_exists($sql))) + { + return $CACHE->get_cache($sql); + } + } + } + // Compile binds if needed if ($binds !== FALSE) { @@ -257,7 +275,7 @@ class CI_DB_driver { // Was the query a "write" type? // If so we'll simply return true if ($this->is_write_type($sql) === TRUE) - { + { return TRUE; } @@ -564,9 +582,9 @@ class CI_DB_driver { function list_tables() { // Is there a cached result? - if (isset($this->cache['table_names'])) + if (isset($this->data_cache['table_names'])) { - return $this->cache['table_names']; + return $this->data_cache['table_names']; } if (FALSE === ($sql = $this->_list_tables())) @@ -596,7 +614,7 @@ class CI_DB_driver { } } - return $this->cache['table_names'] =& $retval; + return $this->data_cache['table_names'] =& $retval; } // -------------------------------------------------------------------- @@ -623,9 +641,9 @@ class CI_DB_driver { function list_fields($table = '') { // Is there a cached result? - if (isset($this->cache['field_names'][$table])) + if (isset($this->data_cache['field_names'][$table])) { - return $this->cache['field_names'][$table]; + return $this->data_cache['field_names'][$table]; } if ($table == '') @@ -661,7 +679,7 @@ class CI_DB_driver { } } - return $this->cache['field_names'][$table] =& $retval; + return $this->data_cache['field_names'][$table] =& $retval; } // -------------------------------------------------------------------- @@ -820,6 +838,79 @@ class CI_DB_driver { return call_user_func_array($function, $args); } } + + // -------------------------------------------------------------------- + + /** + * Set Cache Path + * + * @access public + * @param string the path to the cache directory + * @return void + */ + function set_cache_path($path = '') + { + if ( ! is_dir($path) OR ! is_writable($path)) + { + if ($this->db_debug) + { + return $this->display_error('db_invalid_cache_path'); + } + + $this->enable_caching(FALSE); + return FALSE; + } + + $this->cache_dir = $path; + } + + // -------------------------------------------------------------------- + + /** + * Enable Query Caching + * + * @access public + * @return void + */ + function cache_on() + { + $this->query_caching = TRUE; + } + + // -------------------------------------------------------------------- + + /** + * Disable Query Caching + * + * @access public + * @return void + */ + function cache_off() + { + $this->query_caching = FALSE; + } + + // -------------------------------------------------------------------- + + /** + * Load Caching Class + * + * @access private + * @return object + */ + function _load_cache_class() + { + static $CACHE = NULL; + + if (is_object($CACHE)) + { + return $CACHE; + } + + require_once BASEPATH.'database/DB_cache'.EXT; + $CACHE = new DB_cache(); + return $CACHE; + } // -------------------------------------------------------------------- diff --git a/system/database/DB_utility.php b/system/database/DB_utility.php index 339baa8be..433056ff0 100644 --- a/system/database/DB_utility.php +++ b/system/database/DB_utility.php @@ -25,7 +25,7 @@ class CI_DB_utility { var $db; - var $cache = array(); + var $data_cache = array(); /** * Constructor @@ -95,9 +95,9 @@ class CI_DB_utility { function list_databases() { // Is there a cached result? - if (isset($this->cache['db_names'])) + if (isset($this->data_cache['db_names'])) { - return $this->cache['db_names']; + return $this->data_cache['db_names']; } $query = $this->db->query($this->_list_database()); @@ -110,7 +110,7 @@ class CI_DB_utility { } } - return $this->cache['db_names'] =& $dbs; + return $this->data_cache['db_names'] =& $dbs; } // -------------------------------------------------------------------- diff --git a/system/helpers/date_helper.php b/system/helpers/date_helper.php index ab3a31867..987658c2e 100644 --- a/system/helpers/date_helper.php +++ b/system/helpers/date_helper.php @@ -92,7 +92,43 @@ function mdate($datestr = '', $time = '') // ------------------------------------------------------------------------ /** - * Convert MySQL Style Datecodes + * Standard Date + * + * Returns a date formatted according to the submitted standard. + * + * @access public + * @param string the chosen format + * @param integer Unix timestamp + * @return string + */ +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%O', + 'DATE_RFC822' => '%D, %d %M %y %H:%i:%s %O', + 'DATE_RFC850' => '%l, %d-%M-%y %H:%m:%i UTC', + 'DATE_RFC1036' => '%D, %d %M %y %H:%i:%s %O', + 'DATE_RFC1123' => '%D, %d %M %Y %H:%i:%s %O', + 'DATE_RFC2822' => '%D, %d %M %Y %H:%i:%s %O', + 'DATE_RSS' => '%D, %d %M %Y %H:%i:%s %O', + 'DATE_W3C' => '%Y-%m-%dT%H:%i:%s%Q' + ); + + if ( ! isset($formats[$fmt])) + { + return FALSE; + } + + return mdate($formats[$fmt], $time); +} + + +// ------------------------------------------------------------------------ + +/** + * Timespan * * Returns a span of seconds in this format: * 10 days 14 hours 36 minutes 47 seconds diff --git a/system/language/english/db_lang.php b/system/language/english/db_lang.php index 392990120..a17bb71ff 100644 --- a/system/language/english/db_lang.php +++ b/system/language/english/db_lang.php @@ -16,6 +16,8 @@ $lang['db_unable_to_drop'] = 'Unable to drop the specified database.'; $lang['db_unsuported_feature'] = 'Unsupported feature of the database platform you are using.'; $lang['db_unsuported_compression'] = 'The file compression format you chose is not supported by your server.'; $lang['db_filepath_error'] = 'Unable to write data to the file path you have submitted.'; +$lang['db_invalid_cache_path'] = 'The cache path you submitted is not valid or writable.'; + -- cgit v1.2.3-24-g4f1b From b8afd045b9ed165bdae0d18b3e6f7483a4566e1c Mon Sep 17 00:00:00 2001 From: admin Date: Mon, 2 Oct 2006 06:46:29 +0000 Subject: --- system/helpers/download_helper.php | 96 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 96 insertions(+) create mode 100644 system/helpers/download_helper.php (limited to 'system') diff --git a/system/helpers/download_helper.php b/system/helpers/download_helper.php new file mode 100644 index 000000000..8d9fee478 --- /dev/null +++ b/system/helpers/download_helper.php @@ -0,0 +1,96 @@ + \ No newline at end of file -- cgit v1.2.3-24-g4f1b From e26611f93bfb21f5e143cc91ce529f6db52cdd88 Mon Sep 17 00:00:00 2001 From: admin Date: Mon, 2 Oct 2006 21:59:12 +0000 Subject: --- system/codeigniter/CodeIgniter.php | 2 +- system/libraries/Benchmark.php | 32 +++++++++++++++++ system/libraries/Output.php | 70 +++++++++++++++++++++++++++++++++++--- 3 files changed, 98 insertions(+), 6 deletions(-) (limited to 'system') diff --git a/system/codeigniter/CodeIgniter.php b/system/codeigniter/CodeIgniter.php index a4f18b0e1..32c08c8f0 100644 --- a/system/codeigniter/CodeIgniter.php +++ b/system/codeigniter/CodeIgniter.php @@ -51,7 +51,7 @@ set_magic_quotes_runtime(0); // Kill magic quotes */ $BM =& _load_class('Benchmark'); -$BM->mark('code_igniter_start'); +$BM->mark('total_execution_time_start'); /* * ------------------------------------------------------ diff --git a/system/libraries/Benchmark.php b/system/libraries/Benchmark.php index d8dd903e7..feedbf570 100644 --- a/system/libraries/Benchmark.php +++ b/system/libraries/Benchmark.php @@ -85,6 +85,38 @@ class CI_Benchmark { // -------------------------------------------------------------------- + /** + * Auto Profiler + * + * This function cycles through the entire array of mark points and + * matches any two points that are named identially (ending in "_start" + * and "_end" respectively). It then compiles the execution times for + * all points and returns it as an array + * + * @access public + * @return array + */ + function auto_profiler() + { + $marker_keys = array_reverse(array_keys($this->marker)); + + $times = array(); + foreach ($marker_keys as $val) + { + if (preg_match("/(.+?)_start/i", $val, $match)) + { + if (isset($this->marker[$match[1].'_end'])) + { + $times[$match[1]] = $this->elapsed_time($val, $match[1].'_end'); + } + } + } + + return $times; + } + + // -------------------------------------------------------------------- + /** * Memory Usage * diff --git a/system/libraries/Output.php b/system/libraries/Output.php index 1c3f0d604..b5b7c9e97 100644 --- a/system/libraries/Output.php +++ b/system/libraries/Output.php @@ -31,6 +31,7 @@ class CI_Output { var $final_output; var $cache_expiration = 0; var $headers = array(); + var $enable_profiler = FALSE; function CI_Output() { @@ -89,6 +90,20 @@ class CI_Output { // -------------------------------------------------------------------- + /** + * Enable/disable Profiler + * + * @access public + * @param bool + * @return void + */ + function enable_profiler($val = TRUE) + { + $this->enable_profiler = (is_bool($val)) ? $val : TRUE; + } + + // -------------------------------------------------------------------- + /** * Set Cache * @@ -123,7 +138,7 @@ class CI_Output { */ function _display($output = '') { - // Note: We can't use $obj =& _get_instance() since this function + // Note: We can't use $obj =& get_instance() since this function // is sometimes called by the caching mechanism, which happens before // it's available. Instead we'll use globals... global $BM, $CFG; @@ -141,7 +156,7 @@ class CI_Output { // Parse out the elapsed time and memory usage, and // swap the pseudo-variables with the data - $elapsed = $BM->elapsed_time('code_igniter_start', 'code_igniter_end'); + $elapsed = $BM->elapsed_time('total_execution_time_start', 'total_execution_time_end'); $memory = ( ! function_exists('memory_get_usage')) ? '0' : round(memory_get_usage()/1024/1024, 2).'MB'; $output = str_replace('{memory_usage}', $memory, $output); @@ -166,14 +181,28 @@ class CI_Output { { @header($header); } - } + } // Send the finalized output either directly // to the browser or to the user's _output() // function if it exists - if (function_exists('_get_instance') AND method_exists($obj, '_output')) + if (function_exists('get_instance')) { - $obj->_output($output); + $obj =& get_instance(); + + if ($this->enable_profiler == TRUE) + { + $output .= $this->_run_profiler(); + } + + if (method_exists($obj, '_output')) + { + $obj->_output($output); + } + else + { + echo $output; // Send it to the browser! + } } else { @@ -295,6 +324,37 @@ class CI_Output { return TRUE; } + // -------------------------------------------------------------------- + + /** + * Run the Auto-profiler + * + * @access private + * @return string + */ + function _run_profiler() + { + $obj =& get_instance(); + + $profile = $obj->benchmark->auto_profiler(); + + $output = ''; + if (count($profile) > 0) + { + $output .= "\n\n\n"; + + foreach ($profile as $key => $val) + { + $key = ucwords(str_replace(array('_', '-'), ' ', $key)); + $output .= "\n"; + } + + $output .= "
".$key."".$val."
\n"; + } + + return $output; + } + } // END Output Class ?> \ No newline at end of file -- cgit v1.2.3-24-g4f1b From e95cd263f6991d99e0103fe858f034b76be6d672 Mon Sep 17 00:00:00 2001 From: admin Date: Mon, 2 Oct 2006 23:17:20 +0000 Subject: --- system/libraries/Hooks.php | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) (limited to 'system') diff --git a/system/libraries/Hooks.php b/system/libraries/Hooks.php index 69ca1a9f1..8767e10d0 100644 --- a/system/libraries/Hooks.php +++ b/system/libraries/Hooks.php @@ -40,7 +40,19 @@ class CI_Hooks { function CI_Hooks() { log_message('debug', "Hooks Class Initialized"); - + $this->_initialize(); + } + + // -------------------------------------------------------------------- + + /** + * Initialize the Hooks Preferences + * + * @access private + * @return void + */ + function _initialize() + { $CFG =& _load_class('Config'); // If hooks are not enabled in the config file @@ -63,8 +75,7 @@ class CI_Hooks { $this->hooks =& $hook; $this->enabled = TRUE; - } - // END CI_Hooks() + } // -------------------------------------------------------------------- -- cgit v1.2.3-24-g4f1b From 243f5cc45f23436a1ed3f2fc1ac5f0388dc3d4f5 Mon Sep 17 00:00:00 2001 From: derek Date: Tue, 3 Oct 2006 00:25:03 +0000 Subject: --- system/libraries/Email.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system') diff --git a/system/libraries/Email.php b/system/libraries/Email.php index 55edd6216..99de17414 100644 --- a/system/libraries/Email.php +++ b/system/libraries/Email.php @@ -1548,7 +1548,7 @@ class CI_Email { */ function _get_hostname() { - return ($this->smtp_host != '') ? $this->smtp_host : $this->_get_ip(); + return (isset($_SERVER['SERVER_NAME'])) ? $_SERVER['SERVER_NAME'] : 'localhost.localdomain'; } // END _get_hostname() -- cgit v1.2.3-24-g4f1b From d13ff07599e9ff114051f4823c4c0d13fd1c814d Mon Sep 17 00:00:00 2001 From: admin Date: Tue, 3 Oct 2006 03:40:45 +0000 Subject: --- system/libraries/Profiler.php | 72 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 72 insertions(+) create mode 100644 system/libraries/Profiler.php (limited to 'system') diff --git a/system/libraries/Profiler.php b/system/libraries/Profiler.php new file mode 100644 index 000000000..026bfac60 --- /dev/null +++ b/system/libraries/Profiler.php @@ -0,0 +1,72 @@ +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($obj->benchmark->marker[$match[1].'_end'])) + { + $times[$match[1]] = $obj->benchmark->elapsed_time($match[1].'_start', $key); + } + } + } + + return $times; + } + + // -------------------------------------------------------------------- + +} + +// END CI_Profiler class +?> \ No newline at end of file -- cgit v1.2.3-24-g4f1b From 90a7b9db21316122816e01d5e6459a4424940d1f Mon Sep 17 00:00:00 2001 From: admin Date: Tue, 3 Oct 2006 04:48:39 +0000 Subject: --- system/libraries/Profiler.php | 130 +++++++++++++++++++++++++++++++++++++++--- 1 file changed, 122 insertions(+), 8 deletions(-) (limited to 'system') diff --git a/system/libraries/Profiler.php b/system/libraries/Profiler.php index 026bfac60..265aaf031 100644 --- a/system/libraries/Profiler.php +++ b/system/libraries/Profiler.php @@ -29,6 +29,13 @@ */ class CI_Profiler { + var $obj; + + function CI_Profiler() + { + $this->obj =& get_instance(); + $this->obj->load->language('profiler'); + } // -------------------------------------------------------------------- @@ -45,27 +52,134 @@ class CI_Profiler { */ function _compile_benchmarks() { - $obj =& get_instance(); - - $times = array(); - foreach ($obj->benchmark->marker as $key => $val) + $profile = array(); + foreach ($this->obj->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($obj->benchmark->marker[$match[1].'_end'])) + if (isset($this->obj->benchmark->marker[$match[1].'_end'])) { - $times[$match[1]] = $obj->benchmark->elapsed_time($match[1].'_start', $key); + $profile[$match[1]] = $this->obj->benchmark->elapsed_time($match[1].'_start', $key); } } } - - return $times; + + // 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->obj->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 .= "
\n\n"; + + return $output; } // -------------------------------------------------------------------- + + function _compile_queries() + { + $output = "\n\n"; + $output .= '
'; + $output .= "\n"; + $output .= '  '.$this->obj->lang->line('profiler_queries').'  '; + $output .= "\n"; + + if ( ! class_exists('CI_DB_driver')) + { + $output .= "
".$this->obj->lang->line('profiler_no_db')."
"; + } + else + { + if (count($this->obj->db->queries) == 0) + { + $output .= "
".$this->obj->lang->line('profiler_no_queries')."
"; + } + else + { + foreach ($this->obj->db->queries as $val) + { + $output .= '
'; + $output .= $val; + $output .= "
\n"; + } + } + } + + $output .= "
\n\n"; + + return $output; + } + + // -------------------------------------------------------------------- + + function _compile_post() + { + $output = "\n\n"; + $output .= '
'; + $output .= "\n"; + $output .= '  '.$this->obj->lang->line('profiler_post_data').'  '; + $output .= "\n"; + + if (count($_POST) == 0) + { + $output .= "
".$this->obj->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."]  ".htmlspecialchars(stripslashes($val))."
\n"; + } + $output .= "
\n\n"; + + return $output; + } + + // -------------------------------------------------------------------- + + /** + * Run the Auto-profiler + * + * @access private + * @return string + */ + function run($output = '') + { + $output = '
'; + + $output .= $this->_compile_benchmarks(); + $output .= $this->_compile_post(); + $output .= $this->_compile_queries(); + + return $output; + } + } // END CI_Profiler class -- cgit v1.2.3-24-g4f1b From 1c5ef5e34a86c2d3aa0a2d7c61d143331802ae8d Mon Sep 17 00:00:00 2001 From: admin Date: Tue, 3 Oct 2006 04:50:09 +0000 Subject: --- system/libraries/Profiler.php | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) (limited to 'system') diff --git a/system/libraries/Profiler.php b/system/libraries/Profiler.php index 265aaf031..807a7a83f 100644 --- a/system/libraries/Profiler.php +++ b/system/libraries/Profiler.php @@ -19,7 +19,10 @@ * Code Igniter Profiler Class * * This class enables you to display benchmark, query, and other data - * in order to help with debugging and optimization + * in order to help with debugging and optimization. + * + * Note: At some point it would be good to move all the HTML in this class + * into a set of template files in order to allow customization. * * @package CodeIgniter * @subpackage Libraries @@ -164,7 +167,7 @@ class CI_Profiler { // -------------------------------------------------------------------- /** - * Run the Auto-profiler + * Run the Profiler * * @access private * @return string -- cgit v1.2.3-24-g4f1b From 727e6b40accba02de0d548be62074b901c647ab0 Mon Sep 17 00:00:00 2001 From: admin Date: Tue, 3 Oct 2006 04:50:28 +0000 Subject: --- system/language/english/profiler_lang.php | 10 ++++++++++ 1 file changed, 10 insertions(+) create mode 100644 system/language/english/profiler_lang.php (limited to 'system') diff --git a/system/language/english/profiler_lang.php b/system/language/english/profiler_lang.php new file mode 100644 index 000000000..d82fdbdee --- /dev/null +++ b/system/language/english/profiler_lang.php @@ -0,0 +1,10 @@ + \ No newline at end of file -- cgit v1.2.3-24-g4f1b From 08f6020b0085842d4ae81949a0f4886c94158a55 Mon Sep 17 00:00:00 2001 From: admin Date: Tue, 3 Oct 2006 05:28:00 +0000 Subject: --- system/libraries/Benchmark.php | 35 ----------- system/libraries/Output.php | 131 +++++++++++++++++++++-------------------- system/libraries/Router.php | 5 ++ 3 files changed, 72 insertions(+), 99 deletions(-) (limited to 'system') diff --git a/system/libraries/Benchmark.php b/system/libraries/Benchmark.php index feedbf570..d29e91798 100644 --- a/system/libraries/Benchmark.php +++ b/system/libraries/Benchmark.php @@ -48,7 +48,6 @@ class CI_Benchmark { { $this->marker[$name] = microtime(); } - // END mark() // -------------------------------------------------------------------- @@ -81,39 +80,6 @@ class CI_Benchmark { return number_format(($em + $es) - ($sm + $ss), $decimals); } - // END elapsed_time() - - // -------------------------------------------------------------------- - - /** - * Auto Profiler - * - * This function cycles through the entire array of mark points and - * matches any two points that are named identially (ending in "_start" - * and "_end" respectively). It then compiles the execution times for - * all points and returns it as an array - * - * @access public - * @return array - */ - function auto_profiler() - { - $marker_keys = array_reverse(array_keys($this->marker)); - - $times = array(); - foreach ($marker_keys as $val) - { - if (preg_match("/(.+?)_start/i", $val, $match)) - { - if (isset($this->marker[$match[1].'_end'])) - { - $times[$match[1]] = $this->elapsed_time($val, $match[1].'_end'); - } - } - } - - return $times; - } // -------------------------------------------------------------------- @@ -132,7 +98,6 @@ class CI_Benchmark { { return '{memory_usage}'; } - // END memory_usage() } diff --git a/system/libraries/Output.php b/system/libraries/Output.php index b5b7c9e97..4ab5dd23c 100644 --- a/system/libraries/Output.php +++ b/system/libraries/Output.php @@ -29,9 +29,10 @@ class CI_Output { var $final_output; - var $cache_expiration = 0; - var $headers = array(); - var $enable_profiler = FALSE; + var $cache_expiration = 0; + var $headers = array(); + var $enable_profiler = FALSE; + function CI_Output() { @@ -121,46 +122,52 @@ class CI_Output { /** * Display Output * - * All "view" data is automatically put into this variable - * by the controller class: + * All "view" data is automatically put into this variable by the controller class: * * $this->final_output * - * This function simply echos the variable out. It also does the following: - * - * Stops the benchmark timer so the page rendering speed can be shown. - * - * Determines if the "memory_get_usage' function is available so that - * the memory usage can be shown. + * 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 - * @return void + * @return mixed */ function _display($output = '') { - // Note: We can't use $obj =& get_instance() since this function - // is sometimes called by the caching mechanism, which happens before - // it's available. Instead we'll use globals... + // Note: We use globals because we can't use $obj =& get_instance() + // since this function is sometimes called by the caching mechanism, + // which happens before the CI super object is available. global $BM, $CFG; - + + // -------------------------------------------------------------------- + + // Set the output data if ($output == '') { $output =& $this->final_output; } + // -------------------------------------------------------------------- + // Do we need to write a cache file? if ($this->cache_expiration > 0) { $this->_write_cache($output); } + + // -------------------------------------------------------------------- - // Parse out the elapsed time and memory usage, and - // swap the pseudo-variables with the data + // 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'); + $output = str_replace('{elapsed_time}', $elapsed, $output); + $memory = ( ! function_exists('memory_get_usage')) ? '0' : round(memory_get_usage()/1024/1024, 2).'MB'; - $output = str_replace('{memory_usage}', $memory, $output); - $output = str_replace('{elapsed_time}', $elapsed, $output); + + // -------------------------------------------------------------------- // Is compression requested? if ($CFG->item('compress_output') === TRUE) @@ -173,6 +180,8 @@ class CI_Output { } } } + + // -------------------------------------------------------------------- // Are there any server headers to send? if (count($this->headers) > 0) @@ -182,30 +191,54 @@ class CI_Output { @header($header); } } + + // -------------------------------------------------------------------- - // Send the finalized output either directly - // to the browser or to the user's _output() - // function if it exists - if (function_exists('get_instance')) + // Does the get_instance() function exist? + // If not we know we are dealing with a cache file so we'll + // simply echo out the data and exit. + if ( ! function_exists('get_instance')) { - $obj =& get_instance(); - - if ($this->enable_profiler == TRUE) - { - $output .= $this->_run_profiler(); - } + echo $output; + log_message('debug', "Final output sent to browser"); + log_message('debug', "Total execution time: ".$elapsed); + } + + // -------------------------------------------------------------------- + + // Grab the super object. We'll need it in a moment... + $obj =& get_instance(); - if (method_exists($obj, '_output')) + // Do we need to generate profile data? + // If so, load the Profile class and run it. + if ($this->enable_profiler == TRUE) + { + $obj->load->library('profiler'); + + // 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)) { - $obj->_output($output); + $output = preg_replace("|.*?|is", '', $output); + $output .= $obj->profiler->run(); + $output .= ''; } else { - echo $output; // Send it to the browser! + $output .= $obj->profiler->run(); } } + + // -------------------------------------------------------------------- + + // Does the controller contain a function named _output()? + // If so send the output there. Otherwise, echo it. + if (method_exists($obj, '_output')) + { + $obj->_output($output); + } else - { + { echo $output; // Send it to the browser! } @@ -324,36 +357,6 @@ class CI_Output { return TRUE; } - // -------------------------------------------------------------------- - - /** - * Run the Auto-profiler - * - * @access private - * @return string - */ - function _run_profiler() - { - $obj =& get_instance(); - - $profile = $obj->benchmark->auto_profiler(); - - $output = ''; - if (count($profile) > 0) - { - $output .= "\n\n\n"; - - foreach ($profile as $key => $val) - { - $key = ucwords(str_replace(array('_', '-'), ' ', $key)); - $output .= "\n"; - } - - $output .= "
".$key."".$val."
\n"; - } - - return $output; - } } // END Output Class diff --git a/system/libraries/Router.php b/system/libraries/Router.php index d62cf5090..7a4fd3899 100644 --- a/system/libraries/Router.php +++ b/system/libraries/Router.php @@ -530,6 +530,11 @@ class CI_Router { */ function fetch_method() { + if ($this->method == $this->fetch_class()) + { + return 'index'; + } + return $this->method; } -- cgit v1.2.3-24-g4f1b From f6edc53e00677d5ec3859ab7fd50bb2c84fc2e6a Mon Sep 17 00:00:00 2001 From: admin Date: Tue, 3 Oct 2006 05:28:09 +0000 Subject: --- system/codeigniter/CodeIgniter.php | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) (limited to 'system') diff --git a/system/codeigniter/CodeIgniter.php b/system/codeigniter/CodeIgniter.php index 32c08c8f0..65ca35438 100644 --- a/system/codeigniter/CodeIgniter.php +++ b/system/codeigniter/CodeIgniter.php @@ -52,6 +52,7 @@ set_magic_quotes_runtime(0); // Kill magic quotes $BM =& _load_class('Benchmark'); $BM->mark('total_execution_time_start'); +$BM->mark('loading_time_base_clases_start'); /* * ------------------------------------------------------ @@ -130,6 +131,9 @@ _load_class('Controller', FALSE); require(APPPATH.'controllers/'.$RTR->fetch_directory().$RTR->fetch_class().EXT); +$BM->mark('loading_time_base_clases_end'); + + /* * ------------------------------------------------------ * Security check @@ -142,6 +146,7 @@ require(APPPATH.'controllers/'.$RTR->fetch_directory().$RTR->fetch_class().EXT); $class = $RTR->fetch_class(); $method = $RTR->fetch_method(); + if ( ! class_exists($class) OR $method == 'controller' OR substr($method, 0, 1) == '_' @@ -163,6 +168,10 @@ $EXT->_call_hook('pre_controller'); * Instantiate the controller and call requested method * ------------------------------------------------------ */ + +// Mark a start point so we can benchmark the controller +$BM->mark('controller_execution_time_( '.$class.' / '.$method.' )_start'); + $CI = new $class(); if ($RTR->scaffolding_request === TRUE) @@ -180,11 +189,6 @@ else * ------------------------------------------------------ */ $EXT->_call_hook('post_controller_constructor'); - - if ($method == $class) - { - $method = 'index'; - } if (method_exists($CI, '_remap')) { @@ -203,6 +207,9 @@ else } } +// Mark a benchmark end point +$BM->mark('controller_execution_time_( '.$class.' / '.$method.' )_end'); + /* * ------------------------------------------------------ * Is there a "post_controller" hook? -- cgit v1.2.3-24-g4f1b From 07ad666409b60610a1e5b07368506f9f0ca45b22 Mon Sep 17 00:00:00 2001 From: admin Date: Tue, 3 Oct 2006 06:12:52 +0000 Subject: --- system/codeigniter/Base5.php | 32 ++++++++++++-------------------- system/database/DB_result.php | 4 ++-- system/libraries/Profiler.php | 4 +++- 3 files changed, 17 insertions(+), 23 deletions(-) (limited to 'system') diff --git a/system/codeigniter/Base5.php b/system/codeigniter/Base5.php index ef3fc67f4..a0beea46c 100644 --- a/system/codeigniter/Base5.php +++ b/system/codeigniter/Base5.php @@ -32,31 +32,23 @@ class CI_Base { - public function CI_Base() - { - $instance =& _load_class('Instance'); - $instance->set_instance($this); - } -} - -class Instance { - public static $instance; + public static $instance; - public function set_instance(&$object) - { - self::$instance =& $object; - } - - public function &get_instance() - { - return self::$instance; - } + public function CI_Base() + { + self::$instance =& $this; + } + + public static function &get_instance() + { + return self::$instance; + } } function &get_instance() { - $instance =& _load_class('Instance'); - return $instance->get_instance(); + return CI_Base::get_instance(); } + ?> \ No newline at end of file diff --git a/system/database/DB_result.php b/system/database/DB_result.php index 32c51e07b..3bd43bac6 100644 --- a/system/database/DB_result.php +++ b/system/database/DB_result.php @@ -70,7 +70,7 @@ class CI_DB_result { if (count($this->result_object) == 0) { - return FALSE; + return array(); } return $this->result_object; @@ -98,7 +98,7 @@ class CI_DB_result { if (count($this->result_array) == 0) { - return FALSE; + return array(); } return $this->result_array; diff --git a/system/libraries/Profiler.php b/system/libraries/Profiler.php index 807a7a83f..6626190b1 100644 --- a/system/libraries/Profiler.php +++ b/system/libraries/Profiler.php @@ -174,7 +174,9 @@ class CI_Profiler { */ function run($output = '') { - $output = '
'; + $obj =& get_instance(); + + $output = '
'; $output .= $this->_compile_benchmarks(); $output .= $this->_compile_post(); -- cgit v1.2.3-24-g4f1b From 2fcd16b467436a13c8a84a4add4e8d113fe1be02 Mon Sep 17 00:00:00 2001 From: admin Date: Tue, 3 Oct 2006 16:41:54 +0000 Subject: --- system/libraries/Input.php | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) (limited to 'system') diff --git a/system/libraries/Input.php b/system/libraries/Input.php index ad7b0c571..41d77a97a 100644 --- a/system/libraries/Input.php +++ b/system/libraries/Input.php @@ -230,10 +230,23 @@ class CI_Input { return FALSE; } else - { + { if ($xss_clean === TRUE) { - return $this->xss_clean($_COOKIE[$index]); + if (is_array($_COOKIE[$index])) + { + $cookie = array(); + foreach($_COOKIE[$index] as $key => $val) + { + $cookie[$key] = $this->xss_clean($val); + } + + return $cookie; + } + else + { + return $this->xss_clean($_COOKIE[$index]); + } } else { -- cgit v1.2.3-24-g4f1b From a813a46adc7eefa9ec3835e07f3b57ab5d870d27 Mon Sep 17 00:00:00 2001 From: admin Date: Tue, 3 Oct 2006 19:17:41 +0000 Subject: --- system/libraries/Profiler.php | 27 +++++++++++++++------------ 1 file changed, 15 insertions(+), 12 deletions(-) (limited to 'system') diff --git a/system/libraries/Profiler.php b/system/libraries/Profiler.php index 6626190b1..9da73b03e 100644 --- a/system/libraries/Profiler.php +++ b/system/libraries/Profiler.php @@ -74,20 +74,20 @@ class CI_Profiler { // be modified. We also might want to make this data available to be logged $output = "\n\n"; - $output .= '
'; + $output .= '
'; $output .= "\n"; $output .= '  '.$this->obj->lang->line('profiler_benchmarks').'  '; $output .= "\n"; - $output .= "\n\n\n"; + $output .= "\n\n
\n"; foreach ($profile as $key => $val) { $key = ucwords(str_replace(array('_', '-'), ' ', $key)); - $output .= "\n"; + $output .= "\n"; } $output .= "
".$key."  ".$val."
".$key."  ".$val."
\n"; - $output .= "
\n\n"; + $output .= "
"; return $output; } @@ -98,7 +98,7 @@ class CI_Profiler { function _compile_queries() { $output = "\n\n"; - $output .= '
'; + $output .= '
'; $output .= "\n"; $output .= '  '.$this->obj->lang->line('profiler_queries').'  '; $output .= "\n"; @@ -117,14 +117,14 @@ class CI_Profiler { { foreach ($this->obj->db->queries as $val) { - $output .= '
'; + $output .= '
'; $output .= $val; $output .= "
\n"; } } } - $output .= "
\n\n"; + $output .= "
"; return $output; } @@ -132,9 +132,9 @@ class CI_Profiler { // -------------------------------------------------------------------- function _compile_post() - { + { $output = "\n\n"; - $output .= '
'; + $output .= '
'; $output .= "\n"; $output .= '  '.$this->obj->lang->line('profiler_post_data').'  '; $output .= "\n"; @@ -145,7 +145,7 @@ class CI_Profiler { } else { - $output .= "\n\n\n"; + $output .= "\n\n
\n"; foreach ($_POST as $key => $val) { @@ -154,12 +154,12 @@ class CI_Profiler { $key = "'".$key."'"; } - $output .= "\n"; + $output .= "\n"; } $output .= "
$_POST[".$key."]  ".htmlspecialchars(stripslashes($val))."
$_POST[".$key."]  ".htmlspecialchars(stripslashes($val))."
\n"; } - $output .= "
\n\n"; + $output .= "
"; return $output; } @@ -177,11 +177,14 @@ class CI_Profiler { $obj =& get_instance(); $output = '
'; + $output .= "
"; $output .= $this->_compile_benchmarks(); $output .= $this->_compile_post(); $output .= $this->_compile_queries(); + $output .= '
'; + return $output; } -- cgit v1.2.3-24-g4f1b From 04ea44e4327be7ae3a9dfb55bfd77e9ec8c7c92d Mon Sep 17 00:00:00 2001 From: admin Date: Tue, 3 Oct 2006 19:17:59 +0000 Subject: --- system/libraries/Input.php | 116 ++++++++++++++++++++------------------------- 1 file changed, 51 insertions(+), 65 deletions(-) (limited to 'system') diff --git a/system/libraries/Input.php b/system/libraries/Input.php index 41d77a97a..98c2cbd55 100644 --- a/system/libraries/Input.php +++ b/system/libraries/Input.php @@ -42,14 +42,13 @@ class CI_Input { */ function CI_Input() { + log_message('debug', "Input Class Initialized"); + $CFG =& _load_class('Config'); $this->use_xss_clean = ($CFG->item('global_xss_filtering') === TRUE) ? TRUE : FALSE; - $this->allow_get_array = ($CFG->item('enable_query_strings') === TRUE) ? TRUE : FALSE; - - log_message('debug', "Input Class Initialized"); + $this->allow_get_array = ($CFG->item('enable_query_strings') === TRUE) ? TRUE : FALSE; $this->_sanitize_globals(); } - // END CI_Input() // -------------------------------------------------------------------- @@ -81,11 +80,11 @@ class CI_Input { foreach ($global as $key => $val) { unset($$key); - } + } } } - // Is $_GET data allowed? + // Is $_GET data allowed? If not we'll set the $_GET to an empty array if ($this->allow_get_array == FALSE) { $_GET = array(); @@ -95,33 +94,22 @@ class CI_Input { if (is_array($_POST) AND count($_POST) > 0) { foreach($_POST as $key => $val) - { - if (is_array($val)) - { - foreach($val as $k => $v) - { - $_POST[$this->_clean_input_keys($key)][$this->_clean_input_keys($k)] = $this->_clean_input_data($v); - } - } - else - { - $_POST[$this->_clean_input_keys($key)] = $this->_clean_input_data($val); - } - } + { + $_POST[$this->_clean_input_keys($key)] = $this->_clean_input_data($val); + } } // Clean $_COOKIE Data if (is_array($_COOKIE) AND count($_COOKIE) > 0) { foreach($_COOKIE as $key => $val) - { + { $_COOKIE[$this->_clean_input_keys($key)] = $this->_clean_input_data($val); - } + } } log_message('debug', "Global POST and COOKIE data sanitized"); } - // END _sanitize_globals() // -------------------------------------------------------------------- @@ -142,7 +130,7 @@ class CI_Input { $new_array = array(); foreach ($str as $key => $val) { - $new_array[$key] = $this->_clean_input_data($val); + $new_array[$this->_clean_input_keys($key)] = $this->_clean_input_data($val); } return $new_array; } @@ -152,9 +140,9 @@ class CI_Input { $str = $this->xss_clean($str); } + // Standardize newlines return preg_replace("/\015\012|\015|\012/", "\n", $str); } - // END _clean_input_data() // -------------------------------------------------------------------- @@ -170,7 +158,7 @@ class CI_Input { * @return string */ function _clean_input_keys($str) - { + { if ( ! preg_match("/^[a-z0-9:_\/-]+$/i", $str)) { exit('Disallowed Key Characters: '.$str); @@ -183,7 +171,6 @@ class CI_Input { return $str; } - // END _clean_input_keys() // -------------------------------------------------------------------- @@ -200,19 +187,24 @@ class CI_Input { { return FALSE; } - else + + if ($xss_clean === TRUE) { - if ($xss_clean === TRUE) + if (is_array($_POST[$index])) { - return $this->xss_clean($_POST[$index]); + foreach($_POST[$index] as $key => $val) + { + $_POST[$index][$key] = $this->xss_clean($val); + } } else { - return $_POST[$index]; + return $this->xss_clean($_POST[$index]); } } + + return $_POST[$index]; } - // END post() // -------------------------------------------------------------------- @@ -229,32 +221,29 @@ class CI_Input { { return FALSE; } - else - { - if ($xss_clean === TRUE) + + if ($xss_clean === TRUE) + { + if (is_array($_COOKIE[$index])) { - if (is_array($_COOKIE[$index])) - { - $cookie = array(); - foreach($_COOKIE[$index] as $key => $val) - { - $cookie[$key] = $this->xss_clean($val); - } - - return $cookie; - } - else + $cookie = array(); + foreach($_COOKIE[$index] as $key => $val) { - return $this->xss_clean($_COOKIE[$index]); + $cookie[$key] = $this->xss_clean($val); } + + return $cookie; } else { - return $_COOKIE[$index]; + return $this->xss_clean($_COOKIE[$index]); } } + else + { + return $_COOKIE[$index]; + } } - // END cookie() // -------------------------------------------------------------------- @@ -297,7 +286,6 @@ class CI_Input { return $this->ip_address; } - // END ip_address() // -------------------------------------------------------------------- @@ -312,7 +300,6 @@ class CI_Input { { return ( ! preg_match( "/^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$/", $ip)) ? FALSE : TRUE; } - // END valid_ip() // -------------------------------------------------------------------- @@ -333,7 +320,6 @@ class CI_Input { return $this->user_agent; } - // END user_agent() // -------------------------------------------------------------------- @@ -403,8 +389,8 @@ class CI_Input { * */ $str = preg_replace("/%u0([a-z0-9]{3})/i", "&#x\\1;", $str); - $str = preg_replace("/%([a-z0-9]{2})/i", "&#x\\1;", $str); - + $str = preg_replace("/%([a-z0-9]{2})/i", "&#x\\1;", $str); + /* * Convert character entities to ASCII * @@ -414,8 +400,8 @@ class CI_Input { * */ - if (preg_match_all("/<(.+?)>/si", $str, $matches)) - { + if (preg_match_all("/<(.+?)>/si", $str, $matches)) + { for ($i = 0; $i < count($matches['0']); $i++) { $str = str_replace($matches['1'][$i], @@ -532,12 +518,12 @@ class CI_Input { $str = preg_replace("#".$key."#i", $val, $str); } - + log_message('debug', "XSS Filtering completed"); return $str; } - // END xss_clean() + // -------------------------------------------------------------------- /** * HTML Entities Decode @@ -555,14 +541,14 @@ class CI_Input { * @return string */ /* ------------------------------------------------- - /* Replacement for html_entity_decode() - /* -------------------------------------------------*/ - - /* - NOTE: html_entity_decode() has a bug in some PHP versions when UTF-8 is the - character set, and the PHP developers said they were not back porting the - fix to versions other than PHP 5.x. - */ + /* Replacement for html_entity_decode() + /* -------------------------------------------------*/ + + /* + NOTE: html_entity_decode() has a bug in some PHP versions when UTF-8 is the + character set, and the PHP developers said they were not back porting the + fix to versions other than PHP 5.x. + */ function _html_entity_decode($str, $charset='ISO-8859-1') { if (stristr($str, '&') === FALSE) return $str; -- cgit v1.2.3-24-g4f1b From 7b6fe7a1cdda513700aeabeba67389d016d0527a Mon Sep 17 00:00:00 2001 From: admin Date: Tue, 3 Oct 2006 19:18:08 +0000 Subject: --- system/codeigniter/Base5.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system') diff --git a/system/codeigniter/Base5.php b/system/codeigniter/Base5.php index a0beea46c..e37c257af 100644 --- a/system/codeigniter/Base5.php +++ b/system/codeigniter/Base5.php @@ -32,7 +32,7 @@ class CI_Base { - public static $instance; + private static $instance; public function CI_Base() { -- cgit v1.2.3-24-g4f1b From 6871d95930a148722f2b99fa80ef6dd44f86f078 Mon Sep 17 00:00:00 2001 From: admin Date: Wed, 4 Oct 2006 00:36:18 +0000 Subject: --- system/application/config/autoload.php | 2 +- system/application/config/config.php | 2 +- system/application/config/database.php | 21 +- system/codeigniter/Base4.php | 15 +- system/database/DB_driver.php | 390 +++++++++++++++++++++------------ system/libraries/Controller.php | 3 +- 6 files changed, 274 insertions(+), 159 deletions(-) (limited to 'system') diff --git a/system/application/config/autoload.php b/system/application/config/autoload.php index 6a62cd652..06d8780c4 100644 --- a/system/application/config/autoload.php +++ b/system/application/config/autoload.php @@ -37,7 +37,7 @@ | $autoload['libraries'] = array('database', 'session', 'xmlrpc'); */ -$autoload['libraries'] = array('database', 'calendar'); +$autoload['libraries'] = array(); /* diff --git a/system/application/config/config.php b/system/application/config/config.php index 12501e684..31094f3b6 100644 --- a/system/application/config/config.php +++ b/system/application/config/config.php @@ -31,7 +31,7 @@ $config['index_page'] = "index.php"; |-------------------------------------------------------------------------- | | This item determines which server global should be used to retrieve the -| URI string. The default setting of "auto" works for most servers. +| URI string. The default setting of "AUTO" works for most servers. | If your links do not seem to work, try one of the other delicious flavors: | | 'AUTO' Default - auto detects diff --git a/system/application/config/database.php b/system/application/config/database.php index 5e6420831..7a5764d26 100644 --- a/system/application/config/database.php +++ b/system/application/config/database.php @@ -34,11 +34,30 @@ $active_group = "default"; $db['default']['hostname'] = "localhost"; $db['default']['username'] = "root"; $db['default']['password'] = ""; -$db['default']['database'] = "tester"; +$db['default']['database'] = "ellislab"; $db['default']['dbdriver'] = "mysql"; $db['default']['dbprefix'] = ""; $db['default']['active_r'] = TRUE; $db['default']['pconnect'] = FALSE; $db['default']['db_debug'] = TRUE; +$db['default']['cache_on'] = TRUE; +$db['default']['cachedir'] = APPPATH.'db_cache/'; + + + +$db['test']['hostname'] = "localhost"; +$db['test']['username'] = "root"; +$db['test']['password'] = ""; +$db['test']['database'] = "exp4"; +$db['test']['dbdriver'] = "mysql"; +$db['test']['dbprefix'] = ""; +$db['test']['active_r'] = TRUE; +$db['test']['pconnect'] = FALSE; +$db['test']['db_debug'] = TRUE; + + + + + ?> \ No newline at end of file diff --git a/system/codeigniter/Base4.php b/system/codeigniter/Base4.php index 5d945c26a..eccf58ed8 100644 --- a/system/codeigniter/Base4.php +++ b/system/codeigniter/Base4.php @@ -20,9 +20,9 @@ * * This file is used only when Code Igniter is being run under PHP 4. * Since PHP 4 has such poor object handling we had to come up with - * a hack to resolve some scoping problems. PHP 5 doesn't suffer from - * this problem so we load one of two files based on the version of - * PHP being run. + * a hack (and a really ugly one at that...) to resolve some scoping + * problems. PHP 5 doesn't suffer from this problem so we load one of + * two files based on the version of PHP being run. * * @package CodeIgniter * @subpackage codeigniter @@ -45,14 +45,7 @@ function &get_instance() { global $OBJ, $CI; - if (is_object($CI)) - { - return $CI; - } - else - { - return $OBJ->load; - } + return (is_object($CI)) ? $CI : $OBJ->load; } ?> \ No newline at end of file diff --git a/system/database/DB_driver.php b/system/database/DB_driver.php index 73c723d96..811f09093 100644 --- a/system/database/DB_driver.php +++ b/system/database/DB_driver.php @@ -41,8 +41,6 @@ class CI_DB_driver { var $conn_id = FALSE; var $result_id = FALSE; var $db_debug = FALSE; - var $query_caching = FALSE; - var $cache_dir = ''; var $benchmark = 0; var $query_count = 0; var $bind_marker = '?'; @@ -51,11 +49,14 @@ class CI_DB_driver { var $trans_enabled = TRUE; var $_trans_depth = 0; var $_trans_failure = FALSE; // Used with transactions to determine if a rollback should occur + var $cache_on = FALSE; + var $cachedir = ''; - // These are use with Oracle - var $stmt_id; - var $curs_id; - var $limit_used; + + // These are use with Oracle + var $stmt_id; + var $curs_id; + var $limit_used; @@ -86,10 +87,24 @@ class CI_DB_driver { * @return void */ function initialize($params = '') - { + { if (is_array($params)) { - foreach (array('hostname' => '', 'username' => '', 'password' => '', 'database' => '', 'dbdriver' => 'mysql', 'dbprefix' => '', 'port' => '', 'pconnect' => FALSE, 'db_debug' => FALSE) as $key => $val) + $defaults = array( + 'hostname' => '', + 'username' => '', + 'password' => '', + 'database' => '', + 'dbdriver' => 'mysql', + 'dbprefix' => '', + 'port' => '', + 'pconnect' => FALSE, + 'db_debug' => FALSE, + 'cachedir' => '', + 'cache_on' => FALSE + ); + + foreach ($defaults as $key => $val) { $this->$key = ( ! isset($params[$key])) ? $val : $params[$key]; } @@ -112,25 +127,19 @@ class CI_DB_driver { $this->password = ( ! isset($dsn['pass'])) ? '' : rawurldecode($dsn['pass']); $this->database = ( ! isset($dsn['path'])) ? '' : rawurldecode(substr($dsn['path'], 1)); } - - if ($this->pconnect == FALSE) - { - $this->conn_id = $this->db_connect(); - } - else - { - $this->conn_id = $this->db_pconnect(); - } - - if ( ! $this->conn_id) - { + + // Connect to the database + $this->conn_id = ($this->pconnect == FALSE) ? $this->db_connect() : $this->db_pconnect(); + + if ( ! $this->conn_id) + { log_message('error', 'Unable to connect to the database'); - if ($this->db_debug) - { + if ($this->db_debug) + { $this->display_error('db_unable_to_connect'); - } - } + } + } else { if ( ! $this->db_select()) @@ -142,7 +151,13 @@ class CI_DB_driver { $this->display_error('db_unable_to_select', $this->database); } } - } + } + + // Is there a cache direcotry specified in the config file? + if ($this->cachedir != '') + { + $this->cache_set_dir($this->cachedir); + } } @@ -172,15 +187,15 @@ class CI_DB_driver { { if (FALSE === ($sql = $this->_version())) { - if ($this->db_debug) - { + if ($this->db_debug) + { return $this->display_error('db_unsupported_function'); - } - return FALSE; + } + return FALSE; } - if ($this->dbdriver == 'oci8') - { + if ($this->dbdriver == 'oci8') + { return $sql; } @@ -205,30 +220,25 @@ class CI_DB_driver { * @param array An array of binding data * @return mixed */ - function query($sql, $binds = FALSE, $return_object = TRUE) - { + function query($sql, $binds = FALSE, $return_object = TRUE) + { if ($sql == '') { - if ($this->db_debug) - { + if ($this->db_debug) + { log_message('error', 'Invalid query: '.$sql); return $this->display_error('db_invalid_query'); - } - return FALSE; + } + return FALSE; } - // Is query caching enabled? If the query is a "read type" we'll + // Is query caching enabled? If the query is a "read type" we will // grab the previously cached query if it exists and return it. - if ($this->query_caching == TRUE) - { - if (stristr($sql, 'SELECT')) + if ($this->cache_on == TRUE AND stristr($sql, 'SELECT')) + { + if (FALSE !== ($cache = $this->cache_read($sql))) { - $CACHE =& _load_cache_class(); - - if (FALSE !== ($CACHE->cache_exists($sql))) - { - return $CACHE->get_cache($sql); - } + return $cache; } } @@ -238,20 +248,20 @@ class CI_DB_driver { $sql = $this->compile_binds($sql, $binds); } - // Save the query for debugging - $this->queries[] = $sql; + // Save the query for debugging + $this->queries[] = $sql; // Start the Query Timer - $time_start = list($sm, $ss) = explode(' ', microtime()); - + $time_start = list($sm, $ss) = explode(' ', microtime()); + // Run the Query - if (FALSE === ($this->result_id = $this->simple_query($sql))) - { - // This will trigger a rollback if transactions are being used - $this->_trans_failure = TRUE; - - if ($this->db_debug) - { + if (FALSE === ($this->result_id = $this->simple_query($sql))) + { + // This will trigger a rollback if transactions are being used + $this->_trans_failure = TRUE; + + if ($this->db_debug) + { log_message('error', 'Query error: '.$this->_error_message()); return $this->display_error( array( @@ -260,18 +270,18 @@ class CI_DB_driver { $sql ) ); - } - - return FALSE; - } - + } + + return FALSE; + } + // Stop and aggregate the query time results $time_end = list($em, $es) = explode(' ', microtime()); $this->benchmark += ($em + $es) - ($sm + $ss); // Increment the query counter - $this->query_count++; - + $this->query_count++; + // Was the query a "write" type? // If so we'll simply return true if ($this->is_write_type($sql) === TRUE) @@ -298,17 +308,17 @@ class CI_DB_driver { } // Instantiate the result object - $RES = new $result(); - $RES->conn_id = $this->conn_id; - $RES->db_debug = $this->db_debug; - $RES->result_id = $this->result_id; - - if ($this->dbdriver == 'oci8') - { + $RES = new $result(); + $RES->conn_id = $this->conn_id; + $RES->db_debug = $this->db_debug; + $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; - } + } return $RES; } @@ -589,11 +599,11 @@ class CI_DB_driver { if (FALSE === ($sql = $this->_list_tables())) { - if ($this->db_debug) - { + if ($this->db_debug) + { return $this->display_error('db_unsupported_function'); - } - return FALSE; + } + return FALSE; } $retval = array(); @@ -638,35 +648,35 @@ class CI_DB_driver { * @param string the table name * @return array */ - function list_fields($table = '') - { + 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 ($table == '') + { if ($this->db_debug) { return $this->display_error('db_field_param_missing'); } return FALSE; - } - + } + if (FALSE === ($sql = $this->_list_columns($this->dbprefix.$table))) { - if ($this->db_debug) - { + if ($this->db_debug) + { return $this->display_error('db_unsupported_function'); - } - return FALSE; + } + return FALSE; } - - $query = $this->query($sql); - - $retval = array(); + + $query = $this->query($sql); + + $retval = array(); foreach($query->result_array() as $row) { if (isset($row['COLUMN_NAME'])) @@ -676,11 +686,11 @@ class CI_DB_driver { else { $retval[] = current($row); - } + } } - + return $this->data_cache['field_names'][$table] =& $retval; - } + } // -------------------------------------------------------------------- @@ -695,16 +705,16 @@ class CI_DB_driver { { return ( ! in_array($field_name, $this->list_fields($table_name))) ? FALSE : TRUE; } - + // -------------------------------------------------------------------- /** * DEPRECATED - use list_fields() */ - function field_names($table = '') - { - return $this->list_fields($table); - } + function field_names($table = '') + { + return $this->list_fields($table); + } // -------------------------------------------------------------------- @@ -717,15 +727,15 @@ class CI_DB_driver { */ function field_data($table = '') { - if ($table == '') - { + if ($table == '') + { if ($this->db_debug) { return $this->display_error('db_field_param_missing'); } return FALSE; - } - + } + $query = $this->query($this->_field_data($this->dbprefix.$table)); return $query->field_data(); } @@ -742,7 +752,7 @@ class CI_DB_driver { */ function insert_string($table, $data) { - $fields = array(); + $fields = array(); $values = array(); foreach($data as $key => $val) @@ -802,7 +812,7 @@ class CI_DB_driver { } return $this->_update($this->dbprefix.$table, $fields, $dest); - } + } // -------------------------------------------------------------------- @@ -838,18 +848,47 @@ class CI_DB_driver { return call_user_func_array($function, $args); } } + + // -------------------------------------------------------------------- + + /** + * Enable Query Caching + * + * @access public + * @return void + */ + function cache_on() + { + $this->query_caching = TRUE; + } // -------------------------------------------------------------------- /** - * Set Cache Path + * Disable Query Caching + * + * @access public + * @return void + */ + function cache_off() + { + $this->query_caching = FALSE; + } + + // -------------------------------------------------------------------- + + /** + * Set Cache Directory Path * * @access public * @param string the path to the cache directory * @return void */ - function set_cache_path($path = '') + function cache_set_dir($path = '') { + // Add a trailing slash to the path if needed + $path = preg_replace("/(.+?)\/*$/", "\\1/", $path); + if ( ! is_dir($path) OR ! is_writable($path)) { if ($this->db_debug) @@ -860,58 +899,121 @@ class CI_DB_driver { $this->enable_caching(FALSE); return FALSE; } - + $this->cache_dir = $path; } // -------------------------------------------------------------------- /** - * Enable Query Caching + * Set Cache Path * * @access public + * @param string the path to the cache directory * @return void - */ - function cache_on() + */ + function cache_set_path($sql) { - $this->query_caching = TRUE; + $obj =& get_instance(); + + // The URI being requested will become the name of the cache sub-folder + + $uri = ($obj->uri->uri_string() == '') ? 'index' : $obj->uri->uri_string(); + + // Convert the SQL query into a hash. This will become the cache file name. + + return md5($uri).'/'.md5($sql); } - + // -------------------------------------------------------------------- /** - * Disable Query Caching + * Retreive a cached query * * @access public - * @return void - */ - function cache_off() - { - $this->query_caching = FALSE; - } + * @return string + */ + function cache_read($sql) + { + if ( ! @is_dir($this->cache_dir)) + { + return $this->cache_on = FALSE; + } + + $filepath = $this->cache_set_path($sql); + + if ( ! @file_exists($this->cache_dir.$filepath)) + { + return FALSE; + } + + if ( ! $fp = @fopen($this->cache_dir.$filepath, 'rb')) + { + return FALSE; + } + + $cachedata = file_get_contents($this->cache_dir.$filepath); + + if ( ! is_string($cachedata)) + { + return FALSE; + } + + return unserialize($cachedata); + } // -------------------------------------------------------------------- /** - * Load Caching Class - * - * @access private - * @return object - */ - function _load_cache_class() + * Write a query to a cache file + * + * @access public + * @return bool + */ + function cache_write($sql, $object) { - static $CACHE = NULL; - - if (is_object($CACHE)) + if ( ! @is_dir($this->cache_dir)) { - return $CACHE; + return $this->cache_on = FALSE; } - require_once BASEPATH.'database/DB_cache'.EXT; - $CACHE = new DB_cache(); - return $CACHE; - } + $filepath = $this->cache_set_path($sql); + + + + + + $dirs = array(PATH_CACHE.'db_cache', substr($this->cache_dir, 0, -1)); + + foreach ($dirs as $dir) + { + if ( ! @is_dir($dir)) + { + if ( ! @mkdir($dir, 0777)) + { + return; + } + + @chmod($dir, 0777); + } + } + + if ( ! $fp = @fopen($this->cache_dir.$this->cache_file, 'wb')) + { + return FALSE; + } + + flock($fp, LOCK_EX); + fwrite($fp, $object); + flock($fp, LOCK_UN); + fclose($fp); + + @chmod($this->cache_dir.$this->cache_file, 0777); + + return TRUE; + } + // -------------------------------------------------------------------- /** @@ -920,14 +1022,14 @@ class CI_DB_driver { * @access public * @return void */ - function close() - { - if (is_resource($this->conn_id)) - { - $this->_close($this->conn_id); + function close() + { + if (is_resource($this->conn_id)) + { + $this->_close($this->conn_id); } $this->conn_id = FALSE; - } + } // -------------------------------------------------------------------- @@ -940,8 +1042,8 @@ class CI_DB_driver { * @param boolean whether to localize the message * @return string sends the application/errror_db.php template */ - function display_error($error = '', $swap = '', $native = FALSE) - { + function display_error($error = '', $swap = '', $native = FALSE) + { $LANG = new CI_Language(); $LANG->load('db'); @@ -965,7 +1067,7 @@ class CI_DB_driver { echo $error->show_error('An Error Was Encountered', $message, 'error_db'); exit; - } + } } diff --git a/system/libraries/Controller.php b/system/libraries/Controller.php index c02074fca..6a3ea9962 100644 --- a/system/libraries/Controller.php +++ b/system/libraries/Controller.php @@ -430,6 +430,7 @@ class Controller extends CI_Base { * @access private * @param mixed database connection values * @param bool whether to return the object for multiple connections + * @param bool whether to load the active record class * @return void */ function _ci_init_database($params = '', $return = FALSE, $active_record = FALSE) @@ -439,7 +440,7 @@ class Controller extends CI_Base { return; } - // Load the DB config file if needed + // Load the DB config file if needed. We'll test for a DSN string if (is_string($params) AND strpos($params, '://') === FALSE) { include(APPPATH.'config/database'.EXT); -- cgit v1.2.3-24-g4f1b From db8a3744e2c40b57aa8d128e0293d098021c69b1 Mon Sep 17 00:00:00 2001 From: admin Date: Wed, 4 Oct 2006 07:43:35 +0000 Subject: --- system/database/DB_driver.php | 213 +++++++++++++++++++++++++----------------- 1 file changed, 125 insertions(+), 88 deletions(-) (limited to 'system') diff --git a/system/database/DB_driver.php b/system/database/DB_driver.php index 811f09093..a7a89a953 100644 --- a/system/database/DB_driver.php +++ b/system/database/DB_driver.php @@ -156,7 +156,7 @@ class CI_DB_driver { // Is there a cache direcotry specified in the config file? if ($this->cachedir != '') { - $this->cache_set_dir($this->cachedir); + $this->cache_set_path($this->cachedir); } } @@ -221,7 +221,7 @@ class CI_DB_driver { * @return mixed */ function query($sql, $binds = FALSE, $return_object = TRUE) - { + { if ($sql == '') { if ($this->db_debug) @@ -235,7 +235,7 @@ class CI_DB_driver { // Is query caching enabled? If the query is a "read type" we will // grab the previously cached query if it exists and return it. if ($this->cache_on == TRUE AND stristr($sql, 'SELECT')) - { + { if (FALSE !== ($cache = $this->cache_read($sql))) { return $cache; @@ -285,7 +285,15 @@ class CI_DB_driver { // 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) + { + $this->cache_delete(); + } + return TRUE; } @@ -296,19 +304,12 @@ class CI_DB_driver { { return TRUE; } - - // Define the result driver name - $result = 'CI_DB_'.$this->dbdriver.'_result'; - - // Load the result classes - if ( ! class_exists($result)) - { - include_once(BASEPATH.'database/DB_result'.EXT); - include_once(BASEPATH.'database/drivers/'.$this->dbdriver.'/'.$this->dbdriver.'_result'.EXT); - } + + // Load and instantiate the result driver - // Instantiate the result object - $RES = new $result(); + $driver = $this->load_rdriver(); + + $RES = new $driver(); $RES->conn_id = $this->conn_id; $RES->db_debug = $this->db_debug; $RES->result_id = $this->result_id; @@ -319,9 +320,37 @@ class CI_DB_driver { $RES->curs_id = NULL; $RES->limit_used = $this->limit_used; } - + + // 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_write($sql, $RES); + } + 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'.EXT); + include_once(BASEPATH.'database/drivers/'.$this->dbdriver.'/'.$this->dbdriver.'_result'.EXT); + } + + return $driver; + } // -------------------------------------------------------------------- @@ -859,7 +888,7 @@ class CI_DB_driver { */ function cache_on() { - $this->query_caching = TRUE; + return $this->query_caching = TRUE; } // -------------------------------------------------------------------- @@ -872,7 +901,7 @@ class CI_DB_driver { */ function cache_off() { - $this->query_caching = FALSE; + return $this->query_caching = FALSE; } // -------------------------------------------------------------------- @@ -882,10 +911,15 @@ class CI_DB_driver { * * @access public * @param string the path to the cache directory - * @return void + * @return bool */ - function cache_set_dir($path = '') + function cache_set_path($path = '') { + if ($path == '') + { + return $this->cache_off(); + } + // Add a trailing slash to the path if needed $path = preg_replace("/(.+?)\/*$/", "\\1/", $path); @@ -896,33 +930,12 @@ class CI_DB_driver { return $this->display_error('db_invalid_cache_path'); } - $this->enable_caching(FALSE); - return FALSE; + // If the path is wrong we'll turn off caching + return $this->cache_off(); } $this->cache_dir = $path; - } - - // -------------------------------------------------------------------- - - /** - * Set Cache Path - * - * @access public - * @param string the path to the cache directory - * @return void - */ - function cache_set_path($sql) - { - $obj =& get_instance(); - - // The URI being requested will become the name of the cache sub-folder - - $uri = ($obj->uri->uri_string() == '') ? 'index' : $obj->uri->uri_string(); - - // Convert the SQL query into a hash. This will become the cache file name. - - return md5($uri).'/'.md5($sql); + return TRUE; } // -------------------------------------------------------------------- @@ -930,31 +943,27 @@ class CI_DB_driver { /** * Retreive 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 cache_read($sql) - { - if ( ! @is_dir($this->cache_dir)) + { + if ( ! $this->cache_set_path($this->cache_dir)) { - return $this->cache_on = FALSE; + return $this->cache_off(); } - $filepath = $this->cache_set_path($sql); - - if ( ! @file_exists($this->cache_dir.$filepath)) - { - return FALSE; - } + $obj =& get_instance(); + $uri = ($obj->uri->segment(1) == FALSE) ? 'base' : $obj->uri->segment(2); + $uri .= ($obj->uri->segment(2) == FALSE) ? 'index' : $obj->uri->segment(2); - if ( ! $fp = @fopen($this->cache_dir.$filepath, 'rb')) - { - return FALSE; - } - - $cachedata = file_get_contents($this->cache_dir.$filepath); + $filepath = md5($uri).'/'.md5($sql); - if ( ! is_string($cachedata)) + $obj->load->helper('file'); + if (FALSE === ($cachedata = read_file($this->cache_dir.$filepath))) { return FALSE; } @@ -972,46 +981,74 @@ class CI_DB_driver { */ function cache_write($sql, $object) { - if ( ! @is_dir($this->cache_dir)) + if ( ! $this->cache_set_path($this->cache_dir)) { - return $this->cache_on = FALSE; + return $this->cache_off(); } - - $filepath = $this->cache_set_path($sql); - - - + + $obj =& get_instance(); + $uri = ($obj->uri->segment(1) == FALSE) ? 'base' : $obj->uri->segment(2); + $uri .= ($obj->uri->segment(2) == FALSE) ? 'index' : $obj->uri->segment(2); - - - $dirs = array(PATH_CACHE.'db_cache', substr($this->cache_dir, 0, -1)); + $dir_path = $this->cache_dir.md5($uri).'/'; - foreach ($dirs as $dir) - { - if ( ! @is_dir($dir)) + $filename = md5($sql); + + if ( ! @is_dir($dir_path)) + { + if ( ! @mkdir($dir_path, 0777)) { - if ( ! @mkdir($dir, 0777)) - { - return; - } - - @chmod($dir, 0777); + return FALSE; } + + @chmod($dir_path, 0777); } - - if ( ! $fp = @fopen($this->cache_dir.$this->cache_file, 'wb')) + + $obj->load->helper('file'); + if (write_file($dir_path.$filename, serialize($object)) === FALSE) { return FALSE; } - flock($fp, LOCK_EX); - fwrite($fp, $object); - flock($fp, LOCK_UN); - fclose($fp); + @chmod($dir_path.$filename, 0777); + return TRUE; + } + + // -------------------------------------------------------------------- + + /** + * Delete cache files within a particular directory + * + * @access public + * @return bool + */ + function cache_delete() + { + $obj =& get_instance(); + $uri = ($obj->uri->segment(1) == FALSE) ? 'base' : $obj->uri->segment(2); + $uri .= ($obj->uri->segment(2) == FALSE) ? 'index' : $obj->uri->segment(2); + + $dir_path = $this->cache_dir.md5($uri).'/'; - @chmod($this->cache_dir.$this->cache_file, 0777); + $obj->load->helper('file'); + delete_files($dir_path, TRUE); + } - return TRUE; + // -------------------------------------------------------------------- + + /** + * Delete all existing cache files + * + * @access public + * @return bool + */ + // -------------------------------------------------------------------- + + function cache_delete_all() + { + $obj =& get_instance(); + $obj->load->helper('file'); + delete_files($this->cache_dir, TRUE); } // -------------------------------------------------------------------- -- cgit v1.2.3-24-g4f1b From b87cf23b9a4a4611cacf6316a7c437af54ebde52 Mon Sep 17 00:00:00 2001 From: admin Date: Wed, 4 Oct 2006 07:46:05 +0000 Subject: --- system/application/config/autoload.php | 2 +- system/application/config/database.php | 2 +- system/codeigniter/Common.php | 3 +-- system/libraries/Controller.php | 2 +- 4 files changed, 4 insertions(+), 5 deletions(-) (limited to 'system') diff --git a/system/application/config/autoload.php b/system/application/config/autoload.php index 06d8780c4..f3b30a410 100644 --- a/system/application/config/autoload.php +++ b/system/application/config/autoload.php @@ -37,7 +37,7 @@ | $autoload['libraries'] = array('database', 'session', 'xmlrpc'); */ -$autoload['libraries'] = array(); +$autoload['libraries'] = array('database'); /* diff --git a/system/application/config/database.php b/system/application/config/database.php index 7a5764d26..b03cb3ab3 100644 --- a/system/application/config/database.php +++ b/system/application/config/database.php @@ -34,7 +34,7 @@ $active_group = "default"; $db['default']['hostname'] = "localhost"; $db['default']['username'] = "root"; $db['default']['password'] = ""; -$db['default']['database'] = "ellislab"; +$db['default']['database'] = "test"; $db['default']['dbdriver'] = "mysql"; $db['default']['dbprefix'] = ""; $db['default']['active_r'] = TRUE; diff --git a/system/codeigniter/Common.php b/system/codeigniter/Common.php index d2342de42..a801c0821 100644 --- a/system/codeigniter/Common.php +++ b/system/codeigniter/Common.php @@ -41,7 +41,7 @@ * @param bool optional flag that lets classes get loaded but not instantiated * @return object */ -function &_load_class($class, $instantiate = TRUE) +function _load_class($class, $instantiate = TRUE) { static $objects = array(); @@ -121,7 +121,6 @@ function &_load_class($class, $instantiate = TRUE) /** * Loads the main config.php file * -* * @access private * @return array */ diff --git a/system/libraries/Controller.php b/system/libraries/Controller.php index 6a3ea9962..2a4c19522 100644 --- a/system/libraries/Controller.php +++ b/system/libraries/Controller.php @@ -504,7 +504,7 @@ class Controller extends CI_Base { $obj =& get_instance(); $obj->db =& $DB; } - + // -------------------------------------------------------------------- /** -- cgit v1.2.3-24-g4f1b From 02855e0a5ca144b8b01be2a49cb2780cf5abf653 Mon Sep 17 00:00:00 2001 From: admin Date: Wed, 4 Oct 2006 07:46:15 +0000 Subject: --- system/helpers/file_helper.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system') diff --git a/system/helpers/file_helper.php b/system/helpers/file_helper.php index 4c7eaa54e..c0f525688 100644 --- a/system/helpers/file_helper.php +++ b/system/helpers/file_helper.php @@ -112,7 +112,7 @@ function write_file($path, $data, $mode = 'wb') */ function delete_files($path, $del_dir = FALSE) { - // Trim the trailing slahs + // Trim the trailing slash $path = preg_replace("|^(.+?)/*$|", "\\1", $path); if ( ! $current_dir = @opendir($path)) -- cgit v1.2.3-24-g4f1b From 078fb91f6b58233066d96a3ff0b4cde19d8e4db2 Mon Sep 17 00:00:00 2001 From: admin Date: Wed, 4 Oct 2006 07:50:05 +0000 Subject: --- system/helpers/user_agent_helper.php | 89 ++++++++++++++++++++++++++++++++++++ 1 file changed, 89 insertions(+) create mode 100644 system/helpers/user_agent_helper.php (limited to 'system') diff --git a/system/helpers/user_agent_helper.php b/system/helpers/user_agent_helper.php new file mode 100644 index 000000000..3c6085e77 --- /dev/null +++ b/system/helpers/user_agent_helper.php @@ -0,0 +1,89 @@ + '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', + 'mac os x' => 'Mac OS X', + 'freebsd' => 'FreeBSD', + 'ppc' => 'Macintosh', + 'sunos' => 'Sun Solaris', + 'linux' => 'Linux', + 'debian' => 'Debian', + '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' + ); + + + foreach ($os as $key => $val) + { + if (preg_match("|$key|i", $_SERVER['HTTP_USER_AGENT'])) + { + return $val; + } + } + + return 'Unknown OS'; +} + + +?> \ No newline at end of file -- cgit v1.2.3-24-g4f1b From 194b894c33eb812f84862b53691eb5de304455bb Mon Sep 17 00:00:00 2001 From: admin Date: Wed, 4 Oct 2006 07:59:32 +0000 Subject: --- system/database/DB_cache.php | 76 -------------------------------------------- 1 file changed, 76 deletions(-) delete mode 100644 system/database/DB_cache.php (limited to 'system') diff --git a/system/database/DB_cache.php b/system/database/DB_cache.php deleted file mode 100644 index 4721f32c3..000000000 --- a/system/database/DB_cache.php +++ /dev/null @@ -1,76 +0,0 @@ - \ No newline at end of file -- cgit v1.2.3-24-g4f1b From 0c40565cbbf0218ad6927cbcbc80daf6aefc4377 Mon Sep 17 00:00:00 2001 From: admin Date: Wed, 4 Oct 2006 18:37:57 +0000 Subject: --- system/database/DB_driver.php | 170 +++++++----------------------------------- 1 file changed, 25 insertions(+), 145 deletions(-) (limited to 'system') diff --git a/system/database/DB_driver.php b/system/database/DB_driver.php index a7a89a953..24707aaca 100644 --- a/system/database/DB_driver.php +++ b/system/database/DB_driver.php @@ -51,6 +51,7 @@ class CI_DB_driver { var $_trans_failure = FALSE; // Used with transactions to determine if a rollback should occur var $cache_on = FALSE; var $cachedir = ''; + var $cache; // The cache class object // These are use with Oracle @@ -152,12 +153,6 @@ class CI_DB_driver { } } } - - // Is there a cache direcotry specified in the config file? - if ($this->cachedir != '') - { - $this->cache_set_path($this->cachedir); - } } @@ -232,13 +227,17 @@ class CI_DB_driver { return FALSE; } - // Is query caching enabled? If the query is a "read type" we will - // grab the previously cached query if it exists and return it. + // 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 (FALSE !== ($cache = $this->cache_read($sql))) + { + if ($this->_cache_init()) { - return $cache; + if (FALSE !== ($cache = $this->cache->read($sql))) + { + return $cache; + } } } @@ -289,9 +288,9 @@ class CI_DB_driver { // If caching is enabled we'll auto-cleanup any // existing files related to this particular URI - if ($this->cache_on == TRUE) + if ($this->cache_on == TRUE AND $this->_cache_init()) { - $this->cache_delete(); + $this->cache->delete(); } return TRUE; @@ -323,9 +322,9 @@ class CI_DB_driver { // Is query caching enabled? If so, we'll serialize the // result object and save it to a cache file - if ($this->cache_on == TRUE) + if ($this->cache_on == TRUE AND $this->_cache_init()) { - $this->cache_write($sql, $RES); + $this->cache->write($sql, $RES); } return $RES; @@ -903,153 +902,34 @@ class CI_DB_driver { { return $this->query_caching = FALSE; } - - // -------------------------------------------------------------------- - - /** - * Set Cache Directory Path - * - * @access public - * @param string the path to the cache directory - * @return bool - */ - function cache_set_path($path = '') - { - if ($path == '') - { - return $this->cache_off(); - } - - // Add a trailing slash to the path if needed - $path = preg_replace("/(.+?)\/*$/", "\\1/", $path); - - if ( ! is_dir($path) OR ! is_writable($path)) - { - if ($this->db_debug) - { - return $this->display_error('db_invalid_cache_path'); - } - - // If the path is wrong we'll turn off caching - return $this->cache_off(); - } - - $this->cache_dir = $path; - return TRUE; - } - - // -------------------------------------------------------------------- - - /** - * Retreive 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 cache_read($sql) - { - if ( ! $this->cache_set_path($this->cache_dir)) - { - return $this->cache_off(); - } - - $obj =& get_instance(); - $uri = ($obj->uri->segment(1) == FALSE) ? 'base' : $obj->uri->segment(2); - $uri .= ($obj->uri->segment(2) == FALSE) ? 'index' : $obj->uri->segment(2); - - $filepath = md5($uri).'/'.md5($sql); - - $obj->load->helper('file'); - if (FALSE === ($cachedata = read_file($this->cache_dir.$filepath))) - { - return FALSE; - } - - return unserialize($cachedata); - } // -------------------------------------------------------------------- /** - * Write a query to a cache file + * Initialize the Cache Class * - * @access public - * @return bool - */ - function cache_write($sql, $object) + * @access private + * @return void + */ + function _cache_init() { - if ( ! $this->cache_set_path($this->cache_dir)) + if (is_object($this->cache)) { - return $this->cache_off(); + return TRUE; } - - $obj =& get_instance(); - $uri = ($obj->uri->segment(1) == FALSE) ? 'base' : $obj->uri->segment(2); - $uri .= ($obj->uri->segment(2) == FALSE) ? 'index' : $obj->uri->segment(2); - - $dir_path = $this->cache_dir.md5($uri).'/'; - - $filename = md5($sql); - if ( ! @is_dir($dir_path)) + if ( ! class_exists('CI_DB_Cache')) { - if ( ! @mkdir($dir_path, 0777)) + if ( ! @include_once(BASEPATH.'database/DB_cache'.EXT)) { - return FALSE; + return $this->cache_off(); } - - @chmod($dir_path, 0777); } - $obj->load->helper('file'); - if (write_file($dir_path.$filename, serialize($object)) === FALSE) - { - return FALSE; - } - - @chmod($dir_path.$filename, 0777); + $this->cache = new CI_DB_Cache; return TRUE; } - // -------------------------------------------------------------------- - - /** - * Delete cache files within a particular directory - * - * @access public - * @return bool - */ - function cache_delete() - { - $obj =& get_instance(); - $uri = ($obj->uri->segment(1) == FALSE) ? 'base' : $obj->uri->segment(2); - $uri .= ($obj->uri->segment(2) == FALSE) ? 'index' : $obj->uri->segment(2); - - $dir_path = $this->cache_dir.md5($uri).'/'; - - $obj->load->helper('file'); - delete_files($dir_path, TRUE); - } - - // -------------------------------------------------------------------- - - /** - * Delete all existing cache files - * - * @access public - * @return bool - */ - // -------------------------------------------------------------------- - - function cache_delete_all() - { - $obj =& get_instance(); - $obj->load->helper('file'); - delete_files($this->cache_dir, TRUE); - } // -------------------------------------------------------------------- -- cgit v1.2.3-24-g4f1b From fa708175d3b3932e67af04858b841eb881c9579b Mon Sep 17 00:00:00 2001 From: admin Date: Wed, 4 Oct 2006 18:42:42 +0000 Subject: --- system/database/DB_driver.php | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) (limited to 'system') diff --git a/system/database/DB_driver.php b/system/database/DB_driver.php index 24707aaca..39577ca83 100644 --- a/system/database/DB_driver.php +++ b/system/database/DB_driver.php @@ -902,6 +902,20 @@ class CI_DB_driver { { return $this->query_caching = FALSE; } + + // -------------------------------------------------------------------- + + /** + * Set Cache Directory Path + * + * @access public + * @param string the path to the cache directory + * @return void + */ + function cache_set_path($path = '') + { + $this->cachedir = $path; + } // -------------------------------------------------------------------- @@ -913,17 +927,14 @@ class CI_DB_driver { */ function _cache_init() { - if (is_object($this->cache)) + if (is_object($this->cache) AND class_exists('CI_DB_Cache')) { return TRUE; } - if ( ! class_exists('CI_DB_Cache')) + if ( ! @include_once(BASEPATH.'database/DB_cache'.EXT)) { - if ( ! @include_once(BASEPATH.'database/DB_cache'.EXT)) - { - return $this->cache_off(); - } + return $this->cache_off(); } $this->cache = new CI_DB_Cache; -- cgit v1.2.3-24-g4f1b From 7e75a7e0c73381072766b52b49240e3aac9bec18 Mon Sep 17 00:00:00 2001 From: admin Date: Wed, 4 Oct 2006 18:43:24 +0000 Subject: --- system/database/DB_cache.php | 187 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 187 insertions(+) create mode 100644 system/database/DB_cache.php (limited to 'system') diff --git a/system/database/DB_cache.php b/system/database/DB_cache.php new file mode 100644 index 000000000..135be3ce9 --- /dev/null +++ b/system/database/DB_cache.php @@ -0,0 +1,187 @@ +obj + // and load the file helper since we use it a lot + $this->obj =& get_instance(); + $this->obj->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->obj->db->cachedir == '') + { + return $this->obj->db->cache_off(); + } + + $path = $this->obj->db->cachedir; + } + + // Add a trailing slash to the path if needed + $path = preg_replace("/(.+?)\/*$/", "\\1/", $path); + + if ( ! is_dir($path) OR ! is_writable($path)) + { + if ($this->obj->db->db_debug) + { + return $this->obj->db->display_error('db_invalid_cache_path'); + } + + // If the path is wrong we'll turn off caching + return $this->obj->db->cache_off(); + } + + $this->obj->db->cachedir = $path; + return TRUE; + } + + // -------------------------------------------------------------------- + + /** + * Retreive 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->obj->db->cache_off(); + } + + $uri = ($this->obj->uri->segment(1) == FALSE) ? 'base' : $this->obj->uri->segment(2); + $uri .= ($this->obj->uri->segment(2) == FALSE) ? 'index' : $this->obj->uri->segment(2); + + $filepath = md5($uri).'/'.md5($sql); + + if (FALSE === ($cachedata = read_file($this->obj->db->cachedir.$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->obj->db->cache_off(); + } + + $uri = ($this->obj->uri->segment(1) == FALSE) ? 'base' : $this->obj->uri->segment(2); + $uri .= ($this->obj->uri->segment(2) == FALSE) ? 'index' : $this->obj->uri->segment(2); + + $dir_path = $this->obj->db->cachedir.md5($uri).'/'; + + $filename = md5($sql); + + if ( ! @is_dir($dir_path)) + { + if ( ! @mkdir($dir_path, 0777)) + { + return FALSE; + } + + @chmod($dir_path, 0777); + } + + if (write_file($dir_path.$filename, serialize($object)) === FALSE) + { + return FALSE; + } + + @chmod($dir_path.$filename, 0777); + return TRUE; + } + + // -------------------------------------------------------------------- + + /** + * Delete cache files within a particular directory + * + * @access public + * @return bool + */ + function delete() + { + $uri = ($this->obj->uri->segment(1) == FALSE) ? 'base' : $this->obj->uri->segment(2); + $uri .= ($this->obj->uri->segment(2) == FALSE) ? 'index' : $this->obj->uri->segment(2); + + $dir_path = $this->obj->db->cachedir.md5($uri).'/'; + + delete_files($dir_path, TRUE); + } + + // -------------------------------------------------------------------- + + /** + * Delete all existing cache files + * + * @access public + * @return bool + */ + function delete_all() + { + delete_files($this->obj->db->cachedir, TRUE); + } + +} + +?> \ No newline at end of file -- cgit v1.2.3-24-g4f1b From c2e3cd76579dd32b434a75287611985acea770bc Mon Sep 17 00:00:00 2001 From: admin Date: Thu, 5 Oct 2006 04:22:30 +0000 Subject: --- system/database/DB_driver.php | 44 +++++++++++++++++++++++++------------------ 1 file changed, 26 insertions(+), 18 deletions(-) (limited to 'system') diff --git a/system/database/DB_driver.php b/system/database/DB_driver.php index 39577ca83..403255799 100644 --- a/system/database/DB_driver.php +++ b/system/database/DB_driver.php @@ -51,7 +51,7 @@ class CI_DB_driver { var $_trans_failure = FALSE; // Used with transactions to determine if a rollback should occur var $cache_on = FALSE; var $cachedir = ''; - var $cache; // The cache class object + var $CACHE; // The cache class object // These are use with Oracle @@ -234,7 +234,7 @@ class CI_DB_driver { { if ($this->_cache_init()) { - if (FALSE !== ($cache = $this->cache->read($sql))) + if (FALSE !== ($cache = $this->CACHE->read($sql))) { return $cache; } @@ -287,10 +287,9 @@ class CI_DB_driver { { // If caching is enabled we'll auto-cleanup any // existing files related to this particular URI - if ($this->cache_on == TRUE AND $this->_cache_init()) { - $this->cache->delete(); + $this->CACHE->delete(); } return TRUE; @@ -305,26 +304,35 @@ class CI_DB_driver { } // Load and instantiate the result driver - - $driver = $this->load_rdriver(); - $RES = new $driver(); + $driver = $this->load_rdriver(); + $RES = new $driver(); $RES->conn_id = $this->conn_id; - $RES->db_debug = $this->db_debug; $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; + $RES->stmt_id = $this->stmt_id; + $RES->curs_id = NULL; + $RES->limit_used = $this->limit_used; } // Is query caching enabled? If so, we'll serialize the - // result object and save it to a cache file + // result object and save it to a cache file. if ($this->cache_on == TRUE AND $this->_cache_init()) - { - $this->cache->write($sql, $RES); + { + // 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(); + + $this->CACHE->write($sql, $CR); } return $RES; @@ -887,7 +895,7 @@ class CI_DB_driver { */ function cache_on() { - return $this->query_caching = TRUE; + return $this->cache_on = TRUE; } // -------------------------------------------------------------------- @@ -900,7 +908,7 @@ class CI_DB_driver { */ function cache_off() { - return $this->query_caching = FALSE; + return $this->cache_on = FALSE; } // -------------------------------------------------------------------- @@ -927,7 +935,7 @@ class CI_DB_driver { */ function _cache_init() { - if (is_object($this->cache) AND class_exists('CI_DB_Cache')) + if (is_object($this->CACHE) AND class_exists('CI_DB_Cache')) { return TRUE; } @@ -937,7 +945,7 @@ class CI_DB_driver { return $this->cache_off(); } - $this->cache = new CI_DB_Cache; + $this->CACHE = new CI_DB_Cache; return TRUE; } -- cgit v1.2.3-24-g4f1b From af644691beae3cbfb3598238d129196da4c7e5bb Mon Sep 17 00:00:00 2001 From: admin Date: Thu, 5 Oct 2006 04:22:41 +0000 Subject: --- system/database/DB_result.php | 133 ++++++++++++++++++++++++++++++------------ 1 file changed, 95 insertions(+), 38 deletions(-) (limited to 'system') diff --git a/system/database/DB_result.php b/system/database/DB_result.php index 3bd43bac6..766a2e380 100644 --- a/system/database/DB_result.php +++ b/system/database/DB_result.php @@ -30,10 +30,10 @@ class CI_DB_result { var $conn_id = FALSE; var $result_id = FALSE; - var $db_debug = FALSE; var $result_array = array(); var $result_object = array(); var $current_row = 0; + var $num_rows = 0; /** @@ -44,7 +44,7 @@ class CI_DB_result { * @return mixed either a result object or array */ function result($type = 'object') - { + { return ($type == 'object') ? $this->result_object() : $this->result_array(); } @@ -62,20 +62,16 @@ class CI_DB_result { { return $this->result_object; } - + + $this->_data_seek(0); while ($row = $this->_fetch_object()) - { + { $this->result_object[] = $row; } - if (count($this->result_object) == 0) - { - return array(); - } - return $this->result_object; } - + // -------------------------------------------------------------------- /** @@ -90,17 +86,13 @@ class CI_DB_result { { return $this->result_array; } - + + $this->_data_seek(0); while ($row = $this->_fetch_assoc()) { $this->result_array[] = $row; } - if (count($this->result_array) == 0) - { - return array(); - } - return $this->result_array; } @@ -128,16 +120,18 @@ class CI_DB_result { */ function row_object($n = 0) { - if (FALSE === ($result = $this->result_object())) + $result = $this->result_object(); + + if (count($result) == 0) { - return FALSE; + return $result; } - + if ($n != $this->current_row AND isset($result[$n])) { $this->current_row = $n; } - + return $result[$this->current_row]; } @@ -151,9 +145,11 @@ class CI_DB_result { */ function row_array($n = 0) { - if (FALSE === ($result = $this->result_array())) + $result = $this->result_array(); + + if (count($result) == 0) { - return FALSE; + return $result; } if ($n != $this->current_row AND isset($result[$n])) @@ -175,9 +171,11 @@ class CI_DB_result { */ function first_row($type = 'object') { - if (FALSE === ($result = $this->result($type))) + $result = $this->result($type); + + if (count($result) == 0) { - return FALSE; + return $result; } return $result[0]; } @@ -192,9 +190,11 @@ class CI_DB_result { */ function last_row($type = 'object') { - if (FALSE === ($result = $this->result($type))) + $result = $this->result($type); + + if (count($result) == 0) { - return FALSE; + return $result; } return $result[count($result) -1]; } @@ -209,9 +209,11 @@ class CI_DB_result { */ function next_row($type = 'object') { - if (FALSE === ($result = $this->result($type))) + $result = $this->result($type); + + if (count($result) == 0) { - return FALSE; + return $result; } if (isset($result[$this->current_row + 1])) @@ -232,9 +234,11 @@ class CI_DB_result { */ function previous_row($type = 'object') { - if (FALSE === ($result = $this->result($type))) + $result = $this->result($type); + + if (count($result) == 0) { - return FALSE; + return $result; } if (isset($result[$this->current_row - 1])) @@ -254,7 +258,7 @@ class CI_DB_result { */ function num_rows() { - // Implemented in the platform-specific result adapter + return $this->num_rows; } // -------------------------------------------------------------------- @@ -267,9 +271,9 @@ class CI_DB_result { */ function num_fields() { - // Implemented in the platform-specific result adapter + return 0; } - + // -------------------------------------------------------------------- /** @@ -281,8 +285,8 @@ class CI_DB_result { * @return array */ function field_names() - { - // Implemented in the platform-specific result adapter + { + return array(); } // -------------------------------------------------------------------- @@ -297,9 +301,16 @@ class CI_DB_result { */ function field_data() { - // Implemented in the platform-specific result adapter + $F = new stdClass(); + $F->name = NULL; + $F->type = NULL; + $F->default = NULL; + $F->max_length = NULL; + $F->primary_key = NULL; + + return $retval[] = $F; } - + // -------------------------------------------------------------------- /** @@ -309,9 +320,55 @@ class CI_DB_result { */ function free_result() { - // Implemented in the platform-specific result adapter + return TRUE; } + // -------------------------------------------------------------------- + + /** + * 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 TRUE; + } + + // -------------------------------------------------------------------- + + /** + * Result - associative array + * + * Returns the result set as an array + * + * @access private + * @return array + */ + function _fetch_assoc() + { + return array(); + } + + // -------------------------------------------------------------------- + + /** + * Result - object + * + * Returns the result set as an object + * + * @access private + * @return object + */ + function _fetch_object() + { + return array(); + } } -- cgit v1.2.3-24-g4f1b From 44351bfc2a4dbd384bce7393cd76333885bf2c7f Mon Sep 17 00:00:00 2001 From: admin Date: Thu, 5 Oct 2006 04:22:54 +0000 Subject: --- system/database/drivers/mysql/mysql_result.php | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) (limited to 'system') diff --git a/system/database/drivers/mysql/mysql_result.php b/system/database/drivers/mysql/mysql_result.php index 91c4af12c..3fdfc8183 100644 --- a/system/database/drivers/mysql/mysql_result.php +++ b/system/database/drivers/mysql/mysql_result.php @@ -117,6 +117,23 @@ class CI_DB_mysql_result extends CI_DB_result { // -------------------------------------------------------------------- + /** + * 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) + { + mysql_data_seek($this->result_id, $n); + } + + // -------------------------------------------------------------------- + /** * Result - associative array * @@ -141,7 +158,7 @@ class CI_DB_mysql_result extends CI_DB_result { * @return object */ function _fetch_object() - { + { return mysql_fetch_object($this->result_id); } -- cgit v1.2.3-24-g4f1b From d2dd03143d9e47a36a2f8561160e278a358fa031 Mon Sep 17 00:00:00 2001 From: admin Date: Thu, 5 Oct 2006 04:34:38 +0000 Subject: --- system/database/drivers/mssql/mssql_result.php | 17 +++++++++++++++++ system/database/drivers/mysqli/mysqli_result.php | 17 +++++++++++++++++ system/database/drivers/oci8/oci8_result.php | 19 +++++++++++++++++++ system/database/drivers/odbc/odbc_result.php | 19 ++++++++++++++++++- system/database/drivers/postgre/postgre_result.php | 17 +++++++++++++++++ system/database/drivers/sqlite/sqlite_result.php | 17 +++++++++++++++++ 6 files changed, 105 insertions(+), 1 deletion(-) (limited to 'system') diff --git a/system/database/drivers/mssql/mssql_result.php b/system/database/drivers/mssql/mssql_result.php index 53b7832d9..498deae09 100644 --- a/system/database/drivers/mssql/mssql_result.php +++ b/system/database/drivers/mssql/mssql_result.php @@ -114,6 +114,23 @@ class CI_DB_mssql_result extends CI_DB_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 + * + * @access private + * @return array + */ + function _data_seek($n = 0) + { + mssql_data_seek($this->result_id, $n); + } // -------------------------------------------------------------------- diff --git a/system/database/drivers/mysqli/mysqli_result.php b/system/database/drivers/mysqli/mysqli_result.php index 2eca68ff5..08db13f10 100644 --- a/system/database/drivers/mysqli/mysqli_result.php +++ b/system/database/drivers/mysqli/mysqli_result.php @@ -117,6 +117,23 @@ class CI_DB_mysqli_result extends CI_DB_result { // -------------------------------------------------------------------- + /** + * 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) + { + mysqli_data_seek($this->result_id, $n); + } + + // -------------------------------------------------------------------- + /** * Result - associative array * diff --git a/system/database/drivers/oci8/oci8_result.php b/system/database/drivers/oci8/oci8_result.php index 30c023ddc..a3da80026 100644 --- a/system/database/drivers/oci8/oci8_result.php +++ b/system/database/drivers/oci8/oci8_result.php @@ -161,6 +161,23 @@ class CI_DB_oci8_result extends CI_DB_result { } } + // -------------------------------------------------------------------- + + /** + * 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; + } + // -------------------------------------------------------------------- /** @@ -192,6 +209,8 @@ class CI_DB_oci8_result extends CI_DB_result { return $res; } + // -------------------------------------------------------------------- + /** * Query result. "array" version. * diff --git a/system/database/drivers/odbc/odbc_result.php b/system/database/drivers/odbc/odbc_result.php index 385209c56..9204d8680 100644 --- a/system/database/drivers/odbc/odbc_result.php +++ b/system/database/drivers/odbc/odbc_result.php @@ -114,7 +114,24 @@ class CI_DB_odbc_result extends CI_DB_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 + * + * @access private + * @return array + */ + function _data_seek($n = 0) + { + return FALSE; + } + // -------------------------------------------------------------------- /** diff --git a/system/database/drivers/postgre/postgre_result.php b/system/database/drivers/postgre/postgre_result.php index ee838b450..8c25c5d4c 100644 --- a/system/database/drivers/postgre/postgre_result.php +++ b/system/database/drivers/postgre/postgre_result.php @@ -117,6 +117,23 @@ class CI_DB_postgre_result extends CI_DB_result { // -------------------------------------------------------------------- + /** + * 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) + { + pg_result_seek($this->result_id, $n); + } + + // -------------------------------------------------------------------- + /** * Result - associative array * diff --git a/system/database/drivers/sqlite/sqlite_result.php b/system/database/drivers/sqlite/sqlite_result.php index 7f48ce8aa..a3e94b471 100644 --- a/system/database/drivers/sqlite/sqlite_result.php +++ b/system/database/drivers/sqlite/sqlite_result.php @@ -113,6 +113,23 @@ class CI_DB_sqlite_result extends CI_DB_result { // -------------------------------------------------------------------- + /** + * 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) + { + sqlite_seek($this->result_id, $n); + } + + // -------------------------------------------------------------------- + /** * Result - associative array * -- cgit v1.2.3-24-g4f1b From 7b9d47296e6e68bfda0a9603d155de4fb7d0c099 Mon Sep 17 00:00:00 2001 From: admin Date: Thu, 5 Oct 2006 04:46:47 +0000 Subject: --- system/database/DB_result.php | 46 ++++++++++++++++++++++++++++++++++--------- 1 file changed, 37 insertions(+), 9 deletions(-) (limited to 'system') diff --git a/system/database/DB_result.php b/system/database/DB_result.php index 766a2e380..b3dbc2149 100644 --- a/system/database/DB_result.php +++ b/system/database/DB_result.php @@ -253,6 +253,11 @@ class CI_DB_result { /** * Number of rows in the result set * + * Note: This function is normally overloaded by the identically named + * method in the platform-specific driver -- except when query caching + * is used. When caching is enabled we do not load the other driver, + * so this function is here primarily to prevent undefined function errors. + * * @access public * @return integer */ @@ -266,6 +271,11 @@ class CI_DB_result { /** * Number of fields in the result set * + * Note: This function is normally overloaded by the identically named + * method in the platform-specific driver -- except when query caching + * is used. When caching is enabled we do not load the other driver, + * so this function is here primarily to prevent undefined function errors. + * * @access public * @return integer */ @@ -279,7 +289,10 @@ class CI_DB_result { /** * Fetch Field Names * - * Generates an array of column names + * Note: This function is normally overloaded by the identically named + * method in the platform-specific driver -- except when query caching + * is used. When caching is enabled we do not load the other driver, + * so this function is here primarily to prevent undefined function errors. * * @access public * @return array @@ -294,7 +307,10 @@ class CI_DB_result { /** * Field data * - * Generates an array of objects containing field meta-data + * Note: This function is normally overloaded by the identically named + * method in the platform-specific driver -- except when query caching + * is used. When caching is enabled we do not load the other driver, + * so this function is here primarily to prevent undefined function errors. * * @access public * @return array @@ -316,6 +332,11 @@ class CI_DB_result { /** * Free the result * + * Note: This function is normally overloaded by the identically named + * method in the platform-specific driver -- except when query caching + * is used. When caching is enabled we do not load the other driver, + * so this function is here primarily to prevent undefined function errors. + * * @return null */ function free_result() @@ -328,14 +349,15 @@ class CI_DB_result { /** * 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 + * Note: This function is normally overloaded by the identically named + * method in the platform-specific driver -- except when query caching + * is used. When caching is enabled we do not load the other driver, + * so this function is here primarily to prevent undefined function errors. * * @access private * @return array */ - function _data_seek($n = 0) + function _data_seek() { return TRUE; } @@ -345,7 +367,10 @@ class CI_DB_result { /** * Result - associative array * - * Returns the result set as an array + * Note: This function is normally overloaded by the identically named + * method in the platform-specific driver -- except when query caching + * is used. When caching is enabled we do not load the other driver, + * so this function is here primarily to prevent undefined function errors. * * @access private * @return array @@ -360,7 +385,10 @@ class CI_DB_result { /** * Result - object * - * Returns the result set as an object + * Note: This function is normally overloaded by the identically named + * method in the platform-specific driver -- except when query caching + * is used. When caching is enabled we do not load the other driver, + * so this function is here primarily to prevent undefined function errors. * * @access private * @return object @@ -371,5 +399,5 @@ class CI_DB_result { } } - +// END DB_result class ?> \ No newline at end of file -- cgit v1.2.3-24-g4f1b From 386ec187efc7c713b37f0155c9b81e1693e2689b Mon Sep 17 00:00:00 2001 From: admin Date: Thu, 5 Oct 2006 21:52:20 +0000 Subject: --- system/database/DB_result.php | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) (limited to 'system') diff --git a/system/database/DB_result.php b/system/database/DB_result.php index b3dbc2149..525dd235a 100644 --- a/system/database/DB_result.php +++ b/system/database/DB_result.php @@ -255,8 +255,8 @@ class CI_DB_result { * * Note: This function is normally overloaded by the identically named * method in the platform-specific driver -- except when query caching - * is used. When caching is enabled we do not load the other driver, - * so this function is here primarily to prevent undefined function errors. + * is used. When caching is enabled we do not load the other driver. + * This function will only be called when a cached result object is in use. * * @access public * @return integer @@ -273,8 +273,8 @@ class CI_DB_result { * * Note: This function is normally overloaded by the identically named * method in the platform-specific driver -- except when query caching - * is used. When caching is enabled we do not load the other driver, - * so this function is here primarily to prevent undefined function errors. + * is used. When caching is enabled we do not load the other driver. + * This function will only be called when a cached result object is in use. * * @access public * @return integer @@ -291,8 +291,8 @@ class CI_DB_result { * * Note: This function is normally overloaded by the identically named * method in the platform-specific driver -- except when query caching - * is used. When caching is enabled we do not load the other driver, - * so this function is here primarily to prevent undefined function errors. + * is used. When caching is enabled we do not load the other driver. + * This function will only be called when a cached result object is in use. * * @access public * @return array @@ -309,8 +309,8 @@ class CI_DB_result { * * Note: This function is normally overloaded by the identically named * method in the platform-specific driver -- except when query caching - * is used. When caching is enabled we do not load the other driver, - * so this function is here primarily to prevent undefined function errors. + * is used. When caching is enabled we do not load the other driver. + * This function will only be called when a cached result object is in use. * * @access public * @return array @@ -334,8 +334,8 @@ class CI_DB_result { * * Note: This function is normally overloaded by the identically named * method in the platform-specific driver -- except when query caching - * is used. When caching is enabled we do not load the other driver, - * so this function is here primarily to prevent undefined function errors. + * is used. When caching is enabled we do not load the other driver. + * This function will only be called when a cached result object is in use. * * @return null */ @@ -351,8 +351,8 @@ class CI_DB_result { * * Note: This function is normally overloaded by the identically named * method in the platform-specific driver -- except when query caching - * is used. When caching is enabled we do not load the other driver, - * so this function is here primarily to prevent undefined function errors. + * is used. When caching is enabled we do not load the other driver. + * This function will only be called when a cached result object is in use. * * @access private * @return array @@ -369,8 +369,8 @@ class CI_DB_result { * * Note: This function is normally overloaded by the identically named * method in the platform-specific driver -- except when query caching - * is used. When caching is enabled we do not load the other driver, - * so this function is here primarily to prevent undefined function errors. + * is used. When caching is enabled we do not load the other driver. + * This function will only be called when a cached result object is in use. * * @access private * @return array @@ -387,8 +387,8 @@ class CI_DB_result { * * Note: This function is normally overloaded by the identically named * method in the platform-specific driver -- except when query caching - * is used. When caching is enabled we do not load the other driver, - * so this function is here primarily to prevent undefined function errors. + * is used. When caching is enabled we do not load the other driver. + * This function will only be called when a cached result object is in use. * * @access private * @return object -- cgit v1.2.3-24-g4f1b From a0564c0c6b8814b8c0e5c1b516e26711deb326a5 Mon Sep 17 00:00:00 2001 From: admin Date: Thu, 5 Oct 2006 22:18:11 +0000 Subject: --- system/database/DB_cache.php | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'system') diff --git a/system/database/DB_cache.php b/system/database/DB_cache.php index 135be3ce9..344736c24 100644 --- a/system/database/DB_cache.php +++ b/system/database/DB_cache.php @@ -97,10 +97,10 @@ class CI_DB_Cache { return $this->obj->db->cache_off(); } - $uri = ($this->obj->uri->segment(1) == FALSE) ? 'base' : $this->obj->uri->segment(2); - $uri .= ($this->obj->uri->segment(2) == FALSE) ? 'index' : $this->obj->uri->segment(2); + $uri = ($this->obj->uri->segment(1) == FALSE) ? 'default_' : $this->obj->uri->segment(1).'_'; + $uri .= ($this->obj->uri->segment(2) == FALSE) ? 'index' : $this->obj->uri->segment(2); - $filepath = md5($uri).'/'.md5($sql); + $filepath = $uri.'/'.md5($sql); if (FALSE === ($cachedata = read_file($this->obj->db->cachedir.$filepath))) { @@ -125,10 +125,10 @@ class CI_DB_Cache { return $this->obj->db->cache_off(); } - $uri = ($this->obj->uri->segment(1) == FALSE) ? 'base' : $this->obj->uri->segment(2); - $uri .= ($this->obj->uri->segment(2) == FALSE) ? 'index' : $this->obj->uri->segment(2); + $uri = ($this->obj->uri->segment(1) == FALSE) ? 'default_' : $this->obj->uri->segment(1).'_'; + $uri .= ($this->obj->uri->segment(2) == FALSE) ? 'index' : $this->obj->uri->segment(2); - $dir_path = $this->obj->db->cachedir.md5($uri).'/'; + $dir_path = $this->obj->db->cachedir.$uri.'/'; $filename = md5($sql); -- cgit v1.2.3-24-g4f1b From 7da9476fe67661398484ff57bdfad94ea483476d Mon Sep 17 00:00:00 2001 From: admin Date: Thu, 5 Oct 2006 22:18:31 +0000 Subject: --- system/database/DB_result.php | 161 +++++------------------------------------- 1 file changed, 16 insertions(+), 145 deletions(-) (limited to 'system') diff --git a/system/database/DB_result.php b/system/database/DB_result.php index 525dd235a..76b7b9e9c 100644 --- a/system/database/DB_result.php +++ b/system/database/DB_result.php @@ -28,8 +28,8 @@ */ class CI_DB_result { - var $conn_id = FALSE; - var $result_id = FALSE; + var $conn_id = NULL; + var $result_id = NULL; var $result_array = array(); var $result_object = array(); var $current_row = 0; @@ -251,152 +251,23 @@ class CI_DB_result { // -------------------------------------------------------------------- /** - * Number of rows in the result set - * - * Note: This function is normally overloaded by the identically named - * method in the platform-specific driver -- except when query caching + * 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. - * This function will only be called when a cached result object is in use. - * - * @access public - * @return integer - */ - function num_rows() - { - return $this->num_rows; - } - - // -------------------------------------------------------------------- - - /** - * Number of fields in the result set - * - * Note: This function is normally overloaded by the identically named - * method in the platform-specific driver -- except when query caching - * is used. When caching is enabled we do not load the other driver. - * This function will only be called when a cached result object is in use. - * - * @access public - * @return integer - */ - function num_fields() - { - return 0; - } - - // -------------------------------------------------------------------- - - /** - * Fetch Field Names - * - * Note: This function is normally overloaded by the identically named - * method in the platform-specific driver -- except when query caching - * is used. When caching is enabled we do not load the other driver. - * This function will only be called when a cached result object is in use. - * - * @access public - * @return array - */ - function field_names() - { - return array(); - } - - // -------------------------------------------------------------------- - - /** - * Field data - * - * Note: This function is normally overloaded by the identically named - * method in the platform-specific driver -- except when query caching - * is used. When caching is enabled we do not load the other driver. - * This function will only be called when a cached result object is in use. - * - * @access public - * @return array - */ - function field_data() - { - $F = new stdClass(); - $F->name = NULL; - $F->type = NULL; - $F->default = NULL; - $F->max_length = NULL; - $F->primary_key = NULL; - - return $retval[] = $F; - } - - // -------------------------------------------------------------------- - - /** - * Free the result - * - * Note: This function is normally overloaded by the identically named - * method in the platform-specific driver -- except when query caching - * is used. When caching is enabled we do not load the other driver. - * This function will only be called when a cached result object is in use. - * - * @return null - */ - function free_result() - { - return TRUE; - } - - // -------------------------------------------------------------------- - - /** - * Data Seek - * - * Note: This function is normally overloaded by the identically named - * method in the platform-specific driver -- except when query caching - * is used. When caching is enabled we do not load the other driver. - * This function will only be called when a cached result object is in use. - * - * @access private - * @return array - */ - function _data_seek() - { - return TRUE; - } - - // -------------------------------------------------------------------- - - /** - * Result - associative array - * - * Note: This function is normally overloaded by the identically named - * method in the platform-specific driver -- except when query caching - * is used. When caching is enabled we do not load the other driver. - * This function will only be called when a cached result object is in use. - * - * @access private - * @return array + * 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 database resource IDs with + * cached results. */ - function _fetch_assoc() - { - return array(); - } - - // -------------------------------------------------------------------- + function num_rows() { return $this->num_rows; } + function num_fields() { return 0; } + function field_names() { return array(); } + function field_data() { return array(); } + function free_result() { return TRUE; } + function _data_seek() { return TRUE; } + function _fetch_assoc() { return array(); } + function _fetch_object() { return array(); } - /** - * Result - object - * - * Note: This function is normally overloaded by the identically named - * method in the platform-specific driver -- except when query caching - * is used. When caching is enabled we do not load the other driver. - * This function will only be called when a cached result object is in use. - * - * @access private - * @return object - */ - function _fetch_object() - { - return array(); - } } // END DB_result class -- cgit v1.2.3-24-g4f1b From a658e314697e0b9e529a73df25edf4fffaf2b519 Mon Sep 17 00:00:00 2001 From: admin Date: Fri, 6 Oct 2006 01:29:36 +0000 Subject: --- system/database/DB_driver.php | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) (limited to 'system') diff --git a/system/database/DB_driver.php b/system/database/DB_driver.php index 403255799..f77b46609 100644 --- a/system/database/DB_driver.php +++ b/system/database/DB_driver.php @@ -51,6 +51,7 @@ class CI_DB_driver { var $_trans_failure = FALSE; // Used with transactions to determine if a rollback should occur var $cache_on = FALSE; var $cachedir = ''; + var $cache_autodel = TRUE; var $CACHE; // The cache class object @@ -287,7 +288,7 @@ class CI_DB_driver { { // If caching is enabled we'll auto-cleanup any // existing files related to this particular URI - if ($this->cache_on == TRUE AND $this->_cache_init()) + if ($this->cache_on == TRUE AND $this->cache_autodel == TRUE AND $this->_cache_init()) { $this->CACHE->delete(); } @@ -331,6 +332,10 @@ class CI_DB_driver { $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); } @@ -910,6 +915,19 @@ class CI_DB_driver { { return $this->cache_on = FALSE; } + + // -------------------------------------------------------------------- + + /** + * Set the cache "auto-delete" value + * + * @access public + * @return void + */ + function cache_autodelete($val = TRUE) + { + $this->cache_autodel = ( ! is_bool($val)) ? TRUE : $val; + } // -------------------------------------------------------------------- -- cgit v1.2.3-24-g4f1b From e6419c4eeed88280a3e59851987e202f4c614dad Mon Sep 17 00:00:00 2001 From: admin Date: Fri, 6 Oct 2006 01:50:43 +0000 Subject: --- system/database/DB_cache.php | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) (limited to 'system') diff --git a/system/database/DB_cache.php b/system/database/DB_cache.php index 344736c24..913140f6c 100644 --- a/system/database/DB_cache.php +++ b/system/database/DB_cache.php @@ -159,12 +159,19 @@ class CI_DB_Cache { * @access public * @return bool */ - function delete() - { - $uri = ($this->obj->uri->segment(1) == FALSE) ? 'base' : $this->obj->uri->segment(2); - $uri .= ($this->obj->uri->segment(2) == FALSE) ? 'index' : $this->obj->uri->segment(2); + function delete($segment_one = '', $segment_two = '') + { + if ($segment_one == '') + { + $segment_one = ($this->obj->uri->segment(1) == FALSE) ? 'default' : $this->obj->uri->segment(2); + } + + if ($segment_two == '') + { + $segment_two = ($this->obj->uri->segment(2) == FALSE) ? 'index' : $this->obj->uri->segment(2); + } - $dir_path = $this->obj->db->cachedir.md5($uri).'/'; + $dir_path = $this->obj->db->cachedir.md5($segment_one.'_'.$segment_two).'/'; delete_files($dir_path, TRUE); } -- cgit v1.2.3-24-g4f1b From c5f7fa3f8fea283b51ee6cd80b36b2112b2e81db Mon Sep 17 00:00:00 2001 From: admin Date: Fri, 6 Oct 2006 02:10:23 +0000 Subject: --- system/database/DB_driver.php | 43 +++++++++++++++++++++++++++++++---------- system/libraries/Validation.php | 27 ++++++++++++++++---------- 2 files changed, 50 insertions(+), 20 deletions(-) (limited to 'system') diff --git a/system/database/DB_driver.php b/system/database/DB_driver.php index f77b46609..e8c4a8236 100644 --- a/system/database/DB_driver.php +++ b/system/database/DB_driver.php @@ -51,7 +51,7 @@ class CI_DB_driver { var $_trans_failure = FALSE; // Used with transactions to determine if a rollback should occur var $cache_on = FALSE; var $cachedir = ''; - var $cache_autodel = TRUE; + var $cache_autodel = FALSE; var $CACHE; // The cache class object @@ -889,7 +889,21 @@ class CI_DB_driver { 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; + } + // -------------------------------------------------------------------- /** @@ -915,32 +929,41 @@ class CI_DB_driver { { return $this->cache_on = FALSE; } + // -------------------------------------------------------------------- /** - * Set the cache "auto-delete" value + * Delete the cache files associated with a particular URI * * @access public * @return void */ - function cache_autodelete($val = TRUE) + function cache_delete() { - $this->cache_autodel = ( ! is_bool($val)) ? TRUE : $val; + if ( ! $this->_cache_init()) + { + return FALSE; + } + return $this->CACHE->delete(); } - + // -------------------------------------------------------------------- /** - * Set Cache Directory Path + * Delete All cache files * * @access public - * @param string the path to the cache directory * @return void */ - function cache_set_path($path = '') + function cache_delete_all() { - $this->cachedir = $path; + if ( ! $this->_cache_init()) + { + return FALSE; + } + + return $this->CACHE->delete_all(); } // -------------------------------------------------------------------- diff --git a/system/libraries/Validation.php b/system/libraries/Validation.php index 7db67a3e1..ff5970837 100644 --- a/system/libraries/Validation.php +++ b/system/libraries/Validation.php @@ -65,18 +65,25 @@ class CI_Validation { function set_fields($data = '', $field = '') { if ($data == '') - return; - - if ( ! is_array($data)) { - if ($field == '') - return; - - $data = array($data => $field); + if (count($this->_fields) == 0) + { + return FALSE; + } } - - $this->_fields = $data; - + else + { + if ( ! is_array($data)) + { + $data = array($data => $field); + } + + if (count($data) > 0) + { + $this->_fields = $data; + } + } + foreach($this->_fields as $key => $val) { $this->$key = ( ! isset($_POST[$key]) OR is_array($_POST[$key])) ? '' : $this->prep_for_form($_POST[$key]); -- cgit v1.2.3-24-g4f1b From fd2750b8f85b4f204e536d255742e18018c3f1f2 Mon Sep 17 00:00:00 2001 From: admin Date: Fri, 6 Oct 2006 17:29:12 +0000 Subject: --- system/database/DB_cache.php | 6 +-- system/database/DB_driver.php | 17 ++++++++ system/libraries/Controller.php | 97 ++--------------------------------------- system/libraries/Loader.php | 54 +++++++++-------------- 4 files changed, 44 insertions(+), 130 deletions(-) (limited to 'system') diff --git a/system/database/DB_cache.php b/system/database/DB_cache.php index 913140f6c..bb2b47b7b 100644 --- a/system/database/DB_cache.php +++ b/system/database/DB_cache.php @@ -97,7 +97,7 @@ class CI_DB_Cache { return $this->obj->db->cache_off(); } - $uri = ($this->obj->uri->segment(1) == FALSE) ? 'default_' : $this->obj->uri->segment(1).'_'; + $uri = ($this->obj->uri->segment(1) == FALSE) ? 'default.' : $this->obj->uri->segment(1).'.'; $uri .= ($this->obj->uri->segment(2) == FALSE) ? 'index' : $this->obj->uri->segment(2); $filepath = $uri.'/'.md5($sql); @@ -125,7 +125,7 @@ class CI_DB_Cache { return $this->obj->db->cache_off(); } - $uri = ($this->obj->uri->segment(1) == FALSE) ? 'default_' : $this->obj->uri->segment(1).'_'; + $uri = ($this->obj->uri->segment(1) == FALSE) ? 'default.' : $this->obj->uri->segment(1).'.'; $uri .= ($this->obj->uri->segment(2) == FALSE) ? 'index' : $this->obj->uri->segment(2); $dir_path = $this->obj->db->cachedir.$uri.'/'; @@ -171,7 +171,7 @@ class CI_DB_Cache { $segment_two = ($this->obj->uri->segment(2) == FALSE) ? 'index' : $this->obj->uri->segment(2); } - $dir_path = $this->obj->db->cachedir.md5($segment_one.'_'.$segment_two).'/'; + $dir_path = $this->obj->db->cachedir.md5($segment_one.'.'.$segment_two).'/'; delete_files($dir_path, TRUE); } diff --git a/system/database/DB_driver.php b/system/database/DB_driver.php index e8c4a8236..b89ebbf8d 100644 --- a/system/database/DB_driver.php +++ b/system/database/DB_driver.php @@ -156,6 +156,23 @@ class CI_DB_driver { } } + // -------------------------------------------------------------------- + + /** + * Load the Utilities Class + * + * @access public + * @return string + */ + function load_utilities() + { + $obj =& get_instance(); + + require_once(BASEPATH.'database/DB_utility'.EXT); + require_once(BASEPATH.'database/drivers/'.$this->dbdriver.'/'.$this->dbdriver.'_utility'.EXT); + $class = 'CI_DB_'.$this->dbdriver.'_utility'; + $obj->dbutil = new $class(); + } // -------------------------------------------------------------------- diff --git a/system/libraries/Controller.php b/system/libraries/Controller.php index 2a4c19522..b09be6c57 100644 --- a/system/libraries/Controller.php +++ b/system/libraries/Controller.php @@ -434,101 +434,10 @@ class Controller extends CI_Base { * @return void */ function _ci_init_database($params = '', $return = FALSE, $active_record = FALSE) - { - if ($this->_ci_is_loaded('db') == TRUE AND $return == FALSE AND $active_record == FALSE) - { - return; - } - - // Load the DB config file if needed. We'll test for a DSN string - if (is_string($params) AND strpos($params, '://') === FALSE) - { - include(APPPATH.'config/database'.EXT); - - $group = ($params == '') ? $active_group : $params; - - if ( ! isset($db[$group])) - { - show_error('You have specified an invalid database connection group: '.$group); - } - - $params = $db[$group]; - } - - // 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 == TRUE) - { - $params['active_r'] = TRUE; - } - - require_once(BASEPATH.'database/DB_driver'.EXT); - - if ( ! isset($params['active_r']) OR $params['active_r'] == TRUE) - { - require_once(BASEPATH.'database/DB_active_rec'.EXT); - - 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'.EXT); - - // Instantiate the DB adapter - $driver = 'CI_DB_'.$params['dbdriver'].'_driver'; - $DB = new $driver($params); - - if ($return === TRUE) - { - return $DB; - } - - $obj =& get_instance(); - $obj->db =& $DB; - } - - // -------------------------------------------------------------------- - - /** - * Initialize Database Ancillary Classes - * - * @access private - * @param str class name - * @return void - */ - function _ci_init_dbextra($class) { - if ( ! $this->_ci_is_loaded('db')) - { - $this->_ci_init_database(); - } - - if ($class == 'dbutil') - { - require_once(BASEPATH.'database/DB_utility'.EXT); - require_once(BASEPATH.'database/drivers/'.$this->db->dbdriver.'/'.$this->db->dbdriver.'_utility'.EXT); - $class = 'CI_DB_'.$this->db->dbdriver.'_utility'; - $this->dbutil = new $class(); - } - } + require_once(BASEPATH.'database/DB'.EXT); + return DB($params, $return, $active_record); + } // -------------------------------------------------------------------- diff --git a/system/libraries/Loader.php b/system/libraries/Loader.php index 2534e6965..6809054e5 100644 --- a/system/libraries/Loader.php +++ b/system/libraries/Loader.php @@ -110,7 +110,9 @@ class CI_Loader { function database($db = '', $return = FALSE, $active_record = FALSE) { $obj =& get_instance(); - + + return DB($params, $return, $active_record); + if ($return === TRUE) { return $obj->_ci_init_database($db, TRUE, $active_record); @@ -124,20 +126,6 @@ class CI_Loader { // -------------------------------------------------------------------- - /** - * Database Utiliy Loader - * - * @access public - * @return object - */ - function dbutil() - { - $obj =& get_instance(); - $obj->_ci_init_dbextra('dbutil'); - } - - // -------------------------------------------------------------------- - /** * Scaffolding Loader * @@ -336,7 +324,24 @@ class CI_Loader { log_message('debug', 'Plugins loaded: '.implode(', ', $plugins)); } + + // -------------------------------------------------------------------- + /** + * Load Plugins + * + * This is simply an alias to the above function in case the + * user has written the plural form of this function. + * + * @access public + * @param array + * @return void + */ + function plugins($plugins = array()) + { + $this->plugin($plugins); + } + // -------------------------------------------------------------------- /** @@ -380,24 +385,7 @@ class CI_Loader { log_message('debug', 'Scripts loaded: '.implode(', ', $scripts)); } - - // -------------------------------------------------------------------- - - /** - * Load Plugins - * - * This is simply an alias to the above function in case the - * user has written the plural form of this function. - * - * @access public - * @param array - * @return void - */ - function plugins($plugins = array()) - { - $this->plugin($plugins); - } - + // -------------------------------------------------------------------- /** -- cgit v1.2.3-24-g4f1b From 61c5717b76bc39823215aaceacdba97264f668d4 Mon Sep 17 00:00:00 2001 From: admin Date: Fri, 6 Oct 2006 17:29:24 +0000 Subject: --- system/database/DB.php | 100 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 100 insertions(+) create mode 100644 system/database/DB.php (limited to 'system') diff --git a/system/database/DB.php b/system/database/DB.php new file mode 100644 index 000000000..a60c98e2e --- /dev/null +++ b/system/database/DB.php @@ -0,0 +1,100 @@ +_ci_is_loaded('db') == TRUE AND $return == FALSE AND $active_record == FALSE) + { + return FALSE; + } + + // Load the DB config file if a DSN string wasn't passed + if (is_string($params) AND strpos($params, '://') === FALSE) + { + include(APPPATH.'config/database'.EXT); + + $group = ($params == '') ? $active_group : $params; + + if ( ! isset($db[$group])) + { + show_error('You have specified an invalid database connection group: '.$group); + } + + $params = $db[$group]; + } + + // 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 == TRUE) + { + $params['active_r'] = TRUE; + } + + require_once(BASEPATH.'database/DB_driver'.EXT); + + if ( ! isset($params['active_r']) OR $params['active_r'] == TRUE) + { + require_once(BASEPATH.'database/DB_active_rec'.EXT); + + 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'.EXT); + + // Instantiate the DB adapter + $driver = 'CI_DB_'.$params['dbdriver'].'_driver'; + $DB = new $driver($params); + + if ($return === TRUE) + { + return $DB; + } + + $obj->db =& $DB; +} + + +?> \ No newline at end of file -- cgit v1.2.3-24-g4f1b From 8f0a8f693307a6d04b8a50aa11f81041c961adf6 Mon Sep 17 00:00:00 2001 From: admin Date: Sat, 7 Oct 2006 01:17:25 +0000 Subject: --- system/codeigniter/CodeIgniter.php | 26 ++- system/database/DB.php | 2 +- system/libraries/Benchmark.php | 7 + system/libraries/Controller.php | 439 ++----------------------------------- system/libraries/Loader.php | 357 +++++++++++++++++++++++++----- system/libraries/Profiler.php | 2 +- 6 files changed, 352 insertions(+), 481 deletions(-) (limited to 'system') diff --git a/system/codeigniter/CodeIgniter.php b/system/codeigniter/CodeIgniter.php index 65ca35438..a237e8a0a 100644 --- a/system/codeigniter/CodeIgniter.php +++ b/system/codeigniter/CodeIgniter.php @@ -38,7 +38,7 @@ require(BASEPATH.'codeigniter/Common'.EXT); /* * ------------------------------------------------------ - * Define a custom error handler so we can log errors + * Define a custom error handler so we can log PHP errors * ------------------------------------------------------ */ set_error_handler('_exception_handler'); @@ -131,6 +131,7 @@ _load_class('Controller', FALSE); require(APPPATH.'controllers/'.$RTR->fetch_directory().$RTR->fetch_class().EXT); +// Set a mark point for benchmarking $BM->mark('loading_time_base_clases_end'); @@ -178,7 +179,26 @@ if ($RTR->scaffolding_request === TRUE) { if ($EXT->_call_hook('scaffolding_override') === FALSE) { - $CI->_ci_scaffolding(); + if ($CI->_ci_scaffolding === FALSE OR $CI->_ci_scaff_table === FALSE) + { + show_404('Scaffolding unavailable'); + } + + if ( ! class_exists('Scaffolding')) + { + if ( ! in_array($CI->uri->segment(3), array('add', 'insert', 'edit', 'update', 'view', 'delete', 'do_delete'), TRUE)) + { + $method = 'view'; + } + else + { + $method = $CI->uri->segment(3); + } + + require_once(BASEPATH.'scaffolding/Scaffolding'.EXT); + $scaff = new Scaffolding($CI->_ci_scaff_table); + $scaff->$method(); + } } } else @@ -240,7 +260,7 @@ $EXT->_call_hook('post_system'); * Close the DB connection of one exists * ------------------------------------------------------ */ -if ($CI->_ci_is_loaded('db')) +if (class_exists('CI_DB')) { $CI->db->close(); } diff --git a/system/database/DB.php b/system/database/DB.php index a60c98e2e..f7476a68e 100644 --- a/system/database/DB.php +++ b/system/database/DB.php @@ -27,7 +27,7 @@ function DB($params = '', $return = FALSE, $active_record = FALSE) $obj =& get_instance(); // Do we even need to load the database class? - if ($obj->_ci_is_loaded('db') == TRUE AND $return == FALSE AND $active_record == FALSE) + if (class_exists('CI_DB') AND $return == FALSE AND $active_record == FALSE) { return FALSE; } diff --git a/system/libraries/Benchmark.php b/system/libraries/Benchmark.php index d29e91798..c20a54269 100644 --- a/system/libraries/Benchmark.php +++ b/system/libraries/Benchmark.php @@ -71,9 +71,16 @@ class CI_Benchmark { { 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]); diff --git a/system/libraries/Controller.php b/system/libraries/Controller.php index b09be6c57..88b49a9e6 100644 --- a/system/libraries/Controller.php +++ b/system/libraries/Controller.php @@ -29,355 +29,39 @@ */ class Controller extends CI_Base { - var $_ci_models = array(); var $_ci_scaffolding = FALSE; var $_ci_scaff_table = FALSE; /** * Constructor * - * Loads the base classes needed to run CI, and runs the "autoload" - * routine which loads the systems specified in the "autoload" config file. + * Calls the initialize() function */ function Controller() { parent::CI_Base(); - // Assign all the class objects that were instantiated by the - // front controller to local class variables so that CI can be - // run as one big super object. - $this->_ci_assign_core(); - - // Load everything specified in the autoload.php file - $this->load->_ci_autoloader($this->_ci_autoload()); - - // This allows anything loaded using $this->load (viwes, files, etc.) - // to become accessible from within the Controller class functions. - foreach (get_object_vars($this) as $key => $var) - { - if (is_object($var)) - { - $this->load->$key =& $this->$key; - } - } + $this->_ci_initialize(); log_message('debug', "Controller Class Initialized"); } - + // -------------------------------------------------------------------- /** - * Initialization Handler + * Initialize * - * This function loads the requested class. - * - * @access private - * @param string the item that is being loaded - * @param mixed any additional parameters - * @return void - */ - function _ci_load_class($class, $params = NULL) - { - // Prep the class name - $class = strtolower(str_replace(EXT, '', $class)); - - // Bug fix for backward compat. - // Kill this at some point in the future - if ($class == 'unit_test') - { - $class = 'unit'; - } - - // Is this a class extension request? - if (substr($class, 0, 3) == 'my_') - { - $class = preg_replace("/my_(.+)/", "\\1", $class); - $extend = TRUE; - } - else - { - $extend = FALSE; - } - - // Does THIS file (Controller.php) contain an initialization - // function that maps to the requested class? - - $method = '_ci_init_'.$class; - - if (method_exists($this, $method)) - { - if (is_null($params)) - { - $this->$method(); - } - else - { - $this->$method($params); - } - - // We're done... - return TRUE; - } - - // Are we extending one of the base classes? - if ($extend == TRUE) - { - // Load the requested library from the main system/libraries folder - if (file_exists(BASEPATH.'libraries/'.ucfirst($class).EXT)) - { - include_once(BASEPATH.'libraries/'.ucfirst($class).EXT); - } - - // Now look for a matching library - foreach (array(ucfirst($class), $class) as $filename) - { - if (file_exists(APPPATH.'libraries/'.$filename.EXT)) - { - include_once(APPPATH.'libraries/'.$filename.EXT); - } - } - - return $this->_ci_init_class($filename, 'MY_', $params); - } - else - { - // Lets search for the requested library file and load it. - // For backward compatibility we'll test for filenames that are - // both uppercase and lower. - foreach (array(ucfirst($class), $class) as $filename) - { - for ($i = 1; $i < 3; $i++) - { - $path = ($i % 2) ? APPPATH : BASEPATH; - - if (file_exists($path.'libraries/'.$filename.EXT)) - { - include_once($path.'libraries/'.$filename.EXT); - return $this->_ci_init_class($filename, '', $params); - } - } - } - } - - // 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 class: ".$class); - } - - // -------------------------------------------------------------------- - - /** - * Instantiates a class - * - * @access private - * @param string - * @param string - * @return null - */ - function _ci_init_class($class, $prefix = '', $config = NULL) - { - // Is there an associated config file for this class? - if ($config == NULL) - { - if (file_exists(APPPATH.'config/'.$class.EXT)) - { - include_once(APPPATH.'config/'.$class.EXT); - } - } - - if ($prefix == '') - { - $name = ( ! class_exists($class)) ? 'CI_'.$class : $class; - } - else - { - $name = $prefix.$class; - } - - $varname = ( ! isset($remap[$class])) ? $class : $remap[$class]; - $varname = strtolower($varname); - - // Instantiate the class - if ($config !== NULL) - { - $this->$varname = new $name($config); - } - else - { - $this->$varname = new $name; - } - } - - // -------------------------------------------------------------------- - - /** - * Loads and instantiates the requested model class - * - * @access private - * @param string - * @return array - */ - function _ci_init_model($model, $name = '', $db_conn = FALSE) - { - // Is the model in a sub-folder? - // If so, parse out the filename and path. - if (strpos($model, '/') === FALSE) - { - $path = ''; - } - else - { - $x = explode('/', $model); - $model = end($x); - unset($x[count($x)-1]); - $path = implode('/', $x).'/'; - } - - if ($name == '') - { - $name = $model; - } - - $obj =& get_instance(); - if (in_array($name, $obj->_ci_models, TRUE)) - { - return; - } - - if (isset($this->$name)) - { - show_error('The model name you are loading is the name of a resource that is already being used: '.$name); - } - - $model = strtolower($model); - - if ( ! file_exists(APPPATH.'models/'.$path.$model.EXT)) - { - show_error('Unable to locate the model you have specified: '.$model); - } - - if ($db_conn !== FALSE) - { - if ($db_conn === TRUE) - $db_conn = ''; - - $this->_ci_init_database($db_conn, FALSE, TRUE); - } - - if ( ! class_exists('Model')) - { - require_once(BASEPATH.'libraries/Model'.EXT); - } - - require_once(APPPATH.'models/'.$path.$model.EXT); - - $model = ucfirst($model); - $this->$name = new $model(); - $this->_ci_models[] = $name; - $this->_ci_assign_to_models(); - } - - // -------------------------------------------------------------------- - - /** - * Assign to Models - * - * Makes sure that anything loaded by the loader class (libraries, plugins, etc.) - * will be available to modles, if any exist. - * - * @access public - * @param object - * @return array - */ - function _ci_assign_to_models() - { - $obj =& get_instance(); - if (count($obj->_ci_models) == 0) - { - return; - } - foreach ($obj->_ci_models as $model) - { - $obj->$model->_assign_libraries(); - } - } - - // -------------------------------------------------------------------- - - /** - * Auto-initialize Core Classes - * - * This initializes the core systems that are specified in the - * libraries/autoload.php file, as well as the systems specified in - * the $autoload class array above. - * - * It returns the "autoload" array so we can pass it to the Loader - * class since it needs to autoload plugins and helper files - * - * The config/autoload.php file contains an array that permits - * sub-systems to be loaded automatically. - * - * @access private - * @return array - */ - function _ci_autoload() - { - include_once(APPPATH.'config/autoload'.EXT); - - if ( ! isset($autoload)) - { - return FALSE; - } - - if (count($autoload['config']) > 0) - { - foreach ($autoload['config'] as $key => $val) - { - $this->config->load($val); - } - } - unset($autoload['config']); - - // A little tweak to remain backward compatible - // The $autoload['core'] item was deprecated - if ( ! isset($autoload['libraries'])) - { - $autoload['libraries'] = $autoload['core']; - - } - - $exceptions = array('dbutil', 'dbexport'); - - foreach ($autoload['libraries'] as $item) - { - if ( ! in_array($item, $exceptions, TRUE)) - { - $this->_ci_load_class($item); - } - else - { - $this->_ci_init_dbextra($item); - } - } - unset($autoload['libraries']); - - return $autoload; - } - - // -------------------------------------------------------------------- - - /** - * Assign the core classes to the global $CI object - * - * By assigning all the classes instantiated by the front controller - * local class variables we enable everything to be accessible using - * $this->class->function() + * Assigns all the bases classes loaded by the front controller to + * variables in this class. Also calls the autoload routine. * * @access private * @return void - */ - function _ci_assign_core() + */ + function _ci_initialize() { + // Assign all the class objects that were instantiated by the + // front controller to local class variables so that CI can be + // run as one big super object. foreach (array('Config', 'Input', 'Benchmark', 'URI', 'Output') as $val) { $class = strtolower($val); @@ -392,101 +76,22 @@ class Controller extends CI_Base { { $this->load = new CI_Loader(); } - } - - // -------------------------------------------------------------------- - /** - * Initialize Scaffolding - * - * This initializing function works a bit different than the - * others. It doesn't load the class. Instead, it simply - * sets a flag indicating that scaffolding is allowed to be - * used. The actual scaffolding function below is - * called by the front controller based on whether the - * second segment of the URL matches the "secret" scaffolding - * word stored in the application/config/routes.php - * - * @access private - * @param string the table to scaffold - * @return void - */ - function _ci_init_scaffolding($table = FALSE) - { - if ($table === FALSE) - { - show_error('You must include the name of the table you would like access when you initialize scaffolding'); - } - $this->_ci_scaffolding = TRUE; - $this->_ci_scaff_table = $table; - } - - // -------------------------------------------------------------------- - - /** - * Initialize Database - * - * @access private - * @param mixed database connection values - * @param bool whether to return the object for multiple connections - * @param bool whether to load the active record class - * @return void - */ - function _ci_init_database($params = '', $return = FALSE, $active_record = FALSE) - { - require_once(BASEPATH.'database/DB'.EXT); - return DB($params, $return, $active_record); - } - - // -------------------------------------------------------------------- - - /** - * Returns TRUE if a class is loaded, FALSE if not - * - * @access public - * @param string the class name - * @return bool - */ - function _ci_is_loaded($class) - { - return ( ! isset($this->$class) OR ! is_object($this->$class)) ? FALSE : TRUE; - } - - // -------------------------------------------------------------------- + // Load everything specified in the autoload.php file + $this->load->_ci_autoloader(); - /** - * Scaffolding - * - * Initializes the scaffolding. - * - * @access private - * @return void - */ - function _ci_scaffolding() - { - if ($this->_ci_scaffolding === FALSE OR $this->_ci_scaff_table === FALSE) - { - show_404('Scaffolding unavailable'); - } - - if (class_exists('Scaffolding')) return; - - if ( ! in_array($this->uri->segment(3), array('add', 'insert', 'edit', 'update', 'view', 'delete', 'do_delete'), TRUE)) - { - $method = 'view'; - } - else + // This allows anything loaded using $this->load (viwes, files, etc.) + // to become accessible from within the Controller class functions. + foreach (get_object_vars($this) as $key => $var) { - $method = $this->uri->segment(3); - } - - $this->_ci_init_database("", FALSE, TRUE); - $this->_ci_load_class('pagination'); - require_once(BASEPATH.'scaffolding/Scaffolding'.EXT); - $this->scaff = new Scaffolding($this->_ci_scaff_table); - $this->scaff->$method(); + if (is_object($var)) + { + $this->load->$key =& $this->$key; + } + } } + } // END _Controller class diff --git a/system/libraries/Loader.php b/system/libraries/Loader.php index 6809054e5..f823d95e8 100644 --- a/system/libraries/Loader.php +++ b/system/libraries/Loader.php @@ -28,6 +28,7 @@ */ class CI_Loader { + var $CI; var $ob_level; var $cached_vars = array(); var $helpers = array(); @@ -35,6 +36,7 @@ class CI_Loader { var $scripts = array(); var $languages = array(); var $view_path = ''; + var $models = array(); /** * Constructor @@ -46,6 +48,8 @@ class CI_Loader { */ function CI_Loader() { + $this->CI =& get_instance(); + $this->view_path = APPPATH.'views/'; $this->ob_level = ob_get_level(); @@ -70,9 +74,8 @@ class CI_Loader { if ($class == '') return; - $obj =& get_instance(); - $obj->_ci_load_class($class, $param); - $obj->_ci_assign_to_models(); + $this->_ci_load_class($class, $param); + $this->_ci_assign_to_models(); } // -------------------------------------------------------------------- @@ -92,8 +95,61 @@ class CI_Loader { if ($model == '') return; - $obj =& get_instance(); - $obj->_ci_init_model($model, $name, $db_conn); + // Is the model in a sub-folder? + // If so, parse out the filename and path. + if (strpos($model, '/') === FALSE) + { + $path = ''; + } + else + { + $x = explode('/', $model); + $model = end($x); + unset($x[count($x)-1]); + $path = implode('/', $x).'/'; + } + + if ($name == '') + { + $name = $model; + } + + if (in_array($name, $this->models, TRUE)) + { + return; + } + + if (isset($this->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); + + if ( ! file_exists(APPPATH.'models/'.$path.$model.EXT)) + { + show_error('Unable to locate the model you have specified: '.$model); + } + + if ($db_conn !== FALSE) + { + if ($db_conn === TRUE) + $db_conn = ''; + + $this->CI->load->database($db_conn, FALSE, TRUE); + } + + if ( ! class_exists('Model')) + { + require_once(BASEPATH.'libraries/Model'.EXT); + } + + require_once(APPPATH.'models/'.$path.$model.EXT); + + $model = ucfirst($model); + $this->CI->$name = new $model(); + $this->models[] = $name; + $this->_ci_assign_to_models(); } // -------------------------------------------------------------------- @@ -107,43 +163,21 @@ class CI_Loader { * @param bool whether to enable active record (this allows us to override the config setting) * @return object */ - function database($db = '', $return = FALSE, $active_record = FALSE) + function database($params = '', $return = FALSE, $active_record = FALSE) { - $obj =& get_instance(); - - return DB($params, $return, $active_record); + require_once(BASEPATH.'database/DB'.EXT); if ($return === TRUE) { - return $obj->_ci_init_database($db, TRUE, $active_record); + return DB($params, $return, $active_record); } else { - $obj->_ci_init_database($db, FALSE, $active_record); - $obj->_ci_assign_to_models(); + DB($params, $return, $active_record); + $this->_ci_assign_to_models(); } } - - // -------------------------------------------------------------------- - - /** - * Scaffolding Loader - * - * @access public - * @param string - * @return void - */ - function scaffolding($table = '') - { - if ($table == FALSE) - { - show_error('You must include the name of the table you would like access when you initialize scaffolding'); - } - $obj =& get_instance(); - $obj->_ci_init_scaffolding($table); - } - // -------------------------------------------------------------------- /** @@ -397,8 +431,7 @@ class CI_Loader { */ function language($file = '', $lang = '', $return = FALSE) { - $obj =& get_instance(); - return $obj->lang->load($file, $lang, $return); + return $this->CI->lang->load($file, $lang, $return); } // -------------------------------------------------------------------- @@ -412,31 +445,43 @@ class CI_Loader { */ function config($file = '') { - $obj =& get_instance(); - $obj->config->load($file); + $this->CI->config->load($file); } - + // -------------------------------------------------------------------- /** - * Set the Path to the "views" folder + * Scaffolding Loader * - * @access private + * This initializing function works a bit different than the + * others. It doesn't load the class. Instead, it simply + * sets a flag indicating that scaffolding is allowed to be + * used. The actual scaffolding function below is + * called by the front controller based on whether the + * second segment of the URL matches the "secret" scaffolding + * word stored in the application/config/routes.php + * + * @access public * @param string * @return void - */ - function _ci_set_view_path($path) - { - $this->view_path = $path; + */ + function scaffolding($table = '') + { + if ($table === FALSE) + { + show_error('You must include the name of the table you would like access when you initialize scaffolding'); + } + + $this->CI->_ci_scaffolding = TRUE; + $this->CI->_ci_scaff_table = $table; } - + // -------------------------------------------------------------------- - + /** * Loader * - * This function isn't called directly. It's called from - * the two functions above. It's used to load views and files + * This function is used to load views and files. * * @access private * @param array @@ -446,12 +491,11 @@ class CI_Loader { { // This allows anything loaded using $this->load (viwes, files, etc.) // to become accessible from within the Controller and Model functions. - $obj =& get_instance(); - foreach (get_object_vars($obj) as $key => $var) + foreach (get_object_vars($this->CI) as $key => $var) { if (is_object($var)) { - $this->$key =& $obj->$key; + $this->$key =& $this->CI->$key; } } @@ -535,10 +579,134 @@ class CI_Loader { } else { - $obj->output->set_output(ob_get_contents()); + $this->CI->output->set_output(ob_get_contents()); ob_end_clean(); } } + + // -------------------------------------------------------------------- + + /** + * Load class + * + * This function loads the requested class. + * + * @access private + * @param string the item that is being loaded + * @param mixed any additional parameters + * @return void + */ + function _ci_load_class($class, $params = NULL) + { + // Prep the class name + $class = strtolower(str_replace(EXT, '', $class)); + + // Bug fix for backward compat. + // Kill this at some point in the future + if ($class == 'unit_test') + { + $class = 'unit'; + } + + // Is this a class extension request? + if (substr($class, 0, 3) == 'my_') + { + $class = preg_replace("/my_(.+)/", "\\1", $class); + $extend = TRUE; + } + else + { + $extend = FALSE; + } + + // Are we extending one of the base classes? + if ($extend == TRUE) + { + // Load the requested library from the main system/libraries folder + if (file_exists(BASEPATH.'libraries/'.ucfirst($class).EXT)) + { + include_once(BASEPATH.'libraries/'.ucfirst($class).EXT); + } + + // Now look for a matching library + foreach (array(ucfirst($class), $class) as $filename) + { + if (file_exists(APPPATH.'libraries/'.$filename.EXT)) + { + include_once(APPPATH.'libraries/'.$filename.EXT); + } + } + + return $this->_ci_init_class($filename, 'MY_', $params); + } + else + { + // Lets search for the requested library file and load it. + // For backward compatibility we'll test for filenames that are + // both uppercase and lower. + foreach (array(ucfirst($class), $class) as $filename) + { + for ($i = 1; $i < 3; $i++) + { + $path = ($i % 2) ? APPPATH : BASEPATH; + + if (file_exists($path.'libraries/'.$filename.EXT)) + { + include_once($path.'libraries/'.$filename.EXT); + return $this->_ci_init_class($filename, '', $params); + } + } + } + } + + // 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 class: ".$class); + } + + // -------------------------------------------------------------------- + + /** + * Instantiates a class + * + * @access private + * @param string + * @param string + * @return null + */ + function _ci_init_class($class, $prefix = '', $config = NULL) + { + // Is there an associated config file for this class? + if ($config == NULL) + { + if (file_exists(APPPATH.'config/'.$class.EXT)) + { + include_once(APPPATH.'config/'.$class.EXT); + } + } + + if ($prefix == '') + { + $name = ( ! class_exists($class)) ? 'CI_'.$class : $class; + } + else + { + $name = $prefix.$class; + } + + $varname = ( ! isset($remap[$class])) ? $class : $remap[$class]; + $varname = strtolower($varname); + + // Instantiate the class + if ($config !== NULL) + { + $this->CI->$varname = new $name($config); + } + else + { + $this->CI->$varname = new $name; + } + } // -------------------------------------------------------------------- @@ -546,27 +714,97 @@ class CI_Loader { * Autoloader * * The config/autoload.php file contains an array that permits sub-systems, - * plugins, and helpers to be loaded automatically. + * libraries, plugins, and helpers to be loaded automatically. * * @access private * @param array * @return void */ - function _ci_autoloader($autoload) - { - if ($autoload === FALSE) + function _ci_autoloader() + { + include_once(APPPATH.'config/autoload'.EXT); + + if ( ! isset($autoload)) { - return; + return FALSE; } - + + // Load any custome config file + if (count($autoload['config']) > 0) + { + foreach ($autoload['config'] as $key => $val) + { + $this->CI->config->load($val); + } + } + + // Load plugins, helpers, and scripts foreach (array('helper', 'plugin', 'script') as $type) { - if (isset($autoload[$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'])) + { + $autoload['libraries'] = $autoload['core']; + } + + // Load libraries + if (isset($autoload['libraries']) AND count($autoload['libraries']) > 0) + { + if (in_array('database', $autoload['libraries'])) + { + $this->database(); + $autoload['libraries'] = array_diff($autoload['libraries'], array('database')); + } + + if (in_array('model', $autoload['libraries'])) + { + $this->model(); + $autoload['libraries'] = array_diff($autoload['libraries'], array('model')); + } + + if (in_array('scaffolding', $autoload['libraries'])) + { + $this->scaffolding(); + $autoload['libraries'] = array_diff($autoload['libraries'], array('scaffolding')); + } + + foreach ($autoload['libraries'] as $item) + { + $this->library($item); + } + } } + + // -------------------------------------------------------------------- + + /** + * Assign to Models + * + * Makes sure that anything loaded by the loader class (libraries, plugins, etc.) + * will be available to modles, if any exist. + * + * @access public + * @param object + * @return array + */ + function _ci_assign_to_models() + { + if (count($this->models) == 0) + { + return; + } + foreach ($this->models as $model) + { + $this->CI->$model->_assign_libraries(); + } + } // -------------------------------------------------------------------- @@ -583,6 +821,7 @@ class CI_Loader { { return (is_object($object)) ? get_object_vars($object) : $object; } + } ?> \ No newline at end of file diff --git a/system/libraries/Profiler.php b/system/libraries/Profiler.php index 9da73b03e..6142267bb 100644 --- a/system/libraries/Profiler.php +++ b/system/libraries/Profiler.php @@ -62,7 +62,7 @@ class CI_Profiler { // up in the order that it was defined if (preg_match("/(.+?)_end/i", $key, $match)) { - if (isset($this->obj->benchmark->marker[$match[1].'_end'])) + if (isset($this->obj->benchmark->marker[$match[1].'_end']) AND isset($this->obj->benchmark->marker[$match[1].'_start'])) { $profile[$match[1]] = $this->obj->benchmark->elapsed_time($match[1].'_start', $key); } -- cgit v1.2.3-24-g4f1b From b3ab70bfdce29b570c853ae53e370e54ca39da93 Mon Sep 17 00:00:00 2001 From: admin Date: Sat, 7 Oct 2006 03:07:29 +0000 Subject: --- system/codeigniter/CodeIgniter.php | 24 ++--------- system/database/DB_cache.php | 46 ++++++++++----------- system/libraries/Calendar.php | 14 +++---- system/libraries/Controller.php | 46 ++++++++++++++++----- system/libraries/Loader.php | 3 +- system/libraries/Profiler.php | 28 ++++++------- system/libraries/Session.php | 71 +++++++++++++++---------------- system/libraries/Validation.php | 17 ++++---- system/scaffolding/Scaffolding.php | 85 +++++++++++++++++++------------------- 9 files changed, 173 insertions(+), 161 deletions(-) (limited to 'system') diff --git a/system/codeigniter/CodeIgniter.php b/system/codeigniter/CodeIgniter.php index a237e8a0a..63ae45864 100644 --- a/system/codeigniter/CodeIgniter.php +++ b/system/codeigniter/CodeIgniter.php @@ -173,32 +173,15 @@ $EXT->_call_hook('pre_controller'); // Mark a start point so we can benchmark the controller $BM->mark('controller_execution_time_( '.$class.' / '.$method.' )_start'); +// Instantiate the Controller $CI = new $class(); +// Is this a scaffolding request? if ($RTR->scaffolding_request === TRUE) { if ($EXT->_call_hook('scaffolding_override') === FALSE) { - if ($CI->_ci_scaffolding === FALSE OR $CI->_ci_scaff_table === FALSE) - { - show_404('Scaffolding unavailable'); - } - - if ( ! class_exists('Scaffolding')) - { - if ( ! in_array($CI->uri->segment(3), array('add', 'insert', 'edit', 'update', 'view', 'delete', 'do_delete'), TRUE)) - { - $method = 'view'; - } - else - { - $method = $CI->uri->segment(3); - } - - require_once(BASEPATH.'scaffolding/Scaffolding'.EXT); - $scaff = new Scaffolding($CI->_ci_scaff_table); - $scaff->$method(); - } + $CI->_ci_scaffolding(); } } else @@ -210,6 +193,7 @@ else */ $EXT->_call_hook('post_controller_constructor'); + // Is there a "remap" function? if (method_exists($CI, '_remap')) { $CI->_remap($method); diff --git a/system/database/DB_cache.php b/system/database/DB_cache.php index bb2b47b7b..081b56584 100644 --- a/system/database/DB_cache.php +++ b/system/database/DB_cache.php @@ -24,7 +24,7 @@ */ class CI_DB_Cache { - var $obj; + var $CI; /** * Constructor @@ -34,10 +34,10 @@ class CI_DB_Cache { */ function CI_DB_Cache() { - // Assign the main CI object to $this->obj + // Assign the main CI object to $this->CI // and load the file helper since we use it a lot - $this->obj =& get_instance(); - $this->obj->load->helper('file'); + $this->CI =& get_instance(); + $this->CI->load->helper('file'); } // -------------------------------------------------------------------- @@ -53,12 +53,12 @@ class CI_DB_Cache { { if ($path == '') { - if ($this->obj->db->cachedir == '') + if ($this->CI->db->cachedir == '') { - return $this->obj->db->cache_off(); + return $this->CI->db->cache_off(); } - $path = $this->obj->db->cachedir; + $path = $this->CI->db->cachedir; } // Add a trailing slash to the path if needed @@ -66,16 +66,16 @@ class CI_DB_Cache { if ( ! is_dir($path) OR ! is_writable($path)) { - if ($this->obj->db->db_debug) + if ($this->CI->db->db_debug) { - return $this->obj->db->display_error('db_invalid_cache_path'); + return $this->CI->db->display_error('db_invalid_cache_path'); } // If the path is wrong we'll turn off caching - return $this->obj->db->cache_off(); + return $this->CI->db->cache_off(); } - $this->obj->db->cachedir = $path; + $this->CI->db->cachedir = $path; return TRUE; } @@ -94,15 +94,15 @@ class CI_DB_Cache { { if ( ! $this->check_path()) { - return $this->obj->db->cache_off(); + return $this->CI->db->cache_off(); } - $uri = ($this->obj->uri->segment(1) == FALSE) ? 'default.' : $this->obj->uri->segment(1).'.'; - $uri .= ($this->obj->uri->segment(2) == FALSE) ? 'index' : $this->obj->uri->segment(2); + $uri = ($this->CI->uri->segment(1) == FALSE) ? 'default.' : $this->CI->uri->segment(1).'.'; + $uri .= ($this->CI->uri->segment(2) == FALSE) ? 'index' : $this->CI->uri->segment(2); $filepath = $uri.'/'.md5($sql); - if (FALSE === ($cachedata = read_file($this->obj->db->cachedir.$filepath))) + if (FALSE === ($cachedata = read_file($this->CI->db->cachedir.$filepath))) { return FALSE; } @@ -122,13 +122,13 @@ class CI_DB_Cache { { if ( ! $this->check_path()) { - return $this->obj->db->cache_off(); + return $this->CI->db->cache_off(); } - $uri = ($this->obj->uri->segment(1) == FALSE) ? 'default.' : $this->obj->uri->segment(1).'.'; - $uri .= ($this->obj->uri->segment(2) == FALSE) ? 'index' : $this->obj->uri->segment(2); + $uri = ($this->CI->uri->segment(1) == FALSE) ? 'default.' : $this->CI->uri->segment(1).'.'; + $uri .= ($this->CI->uri->segment(2) == FALSE) ? 'index' : $this->CI->uri->segment(2); - $dir_path = $this->obj->db->cachedir.$uri.'/'; + $dir_path = $this->CI->db->cachedir.$uri.'/'; $filename = md5($sql); @@ -163,15 +163,15 @@ class CI_DB_Cache { { if ($segment_one == '') { - $segment_one = ($this->obj->uri->segment(1) == FALSE) ? 'default' : $this->obj->uri->segment(2); + $segment_one = ($this->CI->uri->segment(1) == FALSE) ? 'default' : $this->CI->uri->segment(2); } if ($segment_two == '') { - $segment_two = ($this->obj->uri->segment(2) == FALSE) ? 'index' : $this->obj->uri->segment(2); + $segment_two = ($this->CI->uri->segment(2) == FALSE) ? 'index' : $this->CI->uri->segment(2); } - $dir_path = $this->obj->db->cachedir.md5($segment_one.'.'.$segment_two).'/'; + $dir_path = $this->CI->db->cachedir.md5($segment_one.'.'.$segment_two).'/'; delete_files($dir_path, TRUE); } @@ -186,7 +186,7 @@ class CI_DB_Cache { */ function delete_all() { - delete_files($this->obj->db->cachedir, TRUE); + delete_files($this->CI->db->cachedir, TRUE); } } diff --git a/system/libraries/Calendar.php b/system/libraries/Calendar.php index 8cf151703..3cbbbfe6d 100644 --- a/system/libraries/Calendar.php +++ b/system/libraries/Calendar.php @@ -28,8 +28,8 @@ */ class CI_Calendar { + var $CI; var $lang; - var $obj; var $local_time; var $template = ''; var $start_day = 'sunday'; @@ -47,10 +47,10 @@ class CI_Calendar { */ function CI_Calendar() { - $this->obj =& get_instance(); - if ( ! in_array('calendar_lang'.EXT, $this->obj->lang->is_loaded, TRUE)) + $this->CI =& get_instance(); + if ( ! in_array('calendar_lang'.EXT, $this->CI->lang->is_loaded, TRUE)) { - $this->obj->lang->load('calendar'); + $this->CI->lang->load('calendar'); } $this->local_time = time(); @@ -268,12 +268,12 @@ class CI_Calendar { $month = $month_names[$month]; - if ($this->obj->lang->line($month) === FALSE) + if ($this->CI->lang->line($month) === FALSE) { return ucfirst(str_replace('cal_', '', $month)); } - return $this->obj->lang->line($month); + return $this->CI->lang->line($month); } // END get_month_name() @@ -310,7 +310,7 @@ class CI_Calendar { $days = array(); foreach ($day_names as $val) { - $days[] = ($this->obj->lang->line('cal_'.$val) === FALSE) ? ucfirst($val) : $this->obj->lang->line('cal_'.$val); + $days[] = ($this->CI->lang->line('cal_'.$val) === FALSE) ? ucfirst($val) : $this->CI->lang->line('cal_'.$val); } return $days; diff --git a/system/libraries/Controller.php b/system/libraries/Controller.php index 88b49a9e6..58bec841e 100644 --- a/system/libraries/Controller.php +++ b/system/libraries/Controller.php @@ -40,9 +40,7 @@ class Controller extends CI_Base { function Controller() { parent::CI_Base(); - $this->_ci_initialize(); - log_message('debug', "Controller Class Initialized"); } @@ -62,22 +60,28 @@ class Controller extends CI_Base { // Assign all the class objects that were instantiated by the // front controller to local class variables so that CI can be // run as one big super object. - foreach (array('Config', 'Input', 'Benchmark', 'URI', 'Output') as $val) + $classes = array( + 'config' => 'Config', + 'input' => 'Input', + 'benchmark' => 'Benchmark', + 'uri' => 'URI', + 'output' => 'Output', + 'lang' => 'Language' + ); + + foreach ($classes as $var => $class) { - $class = strtolower($val); - $this->$class =& _load_class($val); + $this->$var =& _load_class($class); } - $this->lang =& _load_class('Language'); - - // In PHP 4 the Controller class is a child of CI_Loader. - // In PHP 5 we run it as its own class. + + // In PHP 5 the Controller class is run as a discreet + // class. In PHP 4 it extends the Controller if (floor(phpversion()) >= 5) { $this->load = new CI_Loader(); } - // Load everything specified in the autoload.php file $this->load->_ci_autoloader(); @@ -92,6 +96,28 @@ class Controller extends CI_Base { } } + // -------------------------------------------------------------------- + + /** + * Run Scaffolding + * + * @access private + * @return voikd + */ + function _ci_scaffolding() + { + if ($this->_ci_scaffolding === FALSE OR $this->_ci_scaff_table === FALSE) + { + show_404('Scaffolding unavailable'); + } + + $method = ( ! in_array($this->uri->segment(3), array('add', 'insert', 'edit', 'update', 'view', 'delete', 'do_delete'), TRUE)) ? 'view' : $this->uri->segment(3); + + require_once(BASEPATH.'scaffolding/Scaffolding'.EXT); + $scaff = new Scaffolding($this->_ci_scaff_table); + $scaff->$method(); + } + } // END _Controller class diff --git a/system/libraries/Loader.php b/system/libraries/Loader.php index f823d95e8..90dc0f140 100644 --- a/system/libraries/Loader.php +++ b/system/libraries/Loader.php @@ -31,12 +31,11 @@ class CI_Loader { var $CI; var $ob_level; var $cached_vars = array(); + var $models = array(); var $helpers = array(); var $plugins = array(); var $scripts = array(); - var $languages = array(); var $view_path = ''; - var $models = array(); /** * Constructor diff --git a/system/libraries/Profiler.php b/system/libraries/Profiler.php index 6142267bb..d91f23193 100644 --- a/system/libraries/Profiler.php +++ b/system/libraries/Profiler.php @@ -32,12 +32,12 @@ */ class CI_Profiler { - var $obj; + var $CI; function CI_Profiler() { - $this->obj =& get_instance(); - $this->obj->load->language('profiler'); + $this->CI =& get_instance(); + $this->CI->load->language('profiler'); } // -------------------------------------------------------------------- @@ -56,15 +56,15 @@ class CI_Profiler { function _compile_benchmarks() { $profile = array(); - foreach ($this->obj->benchmark->marker as $key => $val) + 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->obj->benchmark->marker[$match[1].'_end']) AND isset($this->obj->benchmark->marker[$match[1].'_start'])) + if (isset($this->CI->benchmark->marker[$match[1].'_end']) AND isset($this->CI->benchmark->marker[$match[1].'_start'])) { - $profile[$match[1]] = $this->obj->benchmark->elapsed_time($match[1].'_start', $key); + $profile[$match[1]] = $this->CI->benchmark->elapsed_time($match[1].'_start', $key); } } } @@ -76,7 +76,7 @@ class CI_Profiler { $output = "\n\n"; $output .= '
'; $output .= "\n"; - $output .= '  '.$this->obj->lang->line('profiler_benchmarks').'  '; + $output .= '  '.$this->CI->lang->line('profiler_benchmarks').'  '; $output .= "\n"; $output .= "\n\n\n"; @@ -100,22 +100,22 @@ class CI_Profiler { $output = "\n\n"; $output .= '
'; $output .= "\n"; - $output .= '  '.$this->obj->lang->line('profiler_queries').'  '; + $output .= '  '.$this->CI->lang->line('profiler_queries').'  '; $output .= "\n"; if ( ! class_exists('CI_DB_driver')) { - $output .= "
".$this->obj->lang->line('profiler_no_db')."
"; + $output .= "
".$this->CI->lang->line('profiler_no_db')."
"; } else { - if (count($this->obj->db->queries) == 0) + if (count($this->CI->db->queries) == 0) { - $output .= "
".$this->obj->lang->line('profiler_no_queries')."
"; + $output .= "
".$this->CI->lang->line('profiler_no_queries')."
"; } else { - foreach ($this->obj->db->queries as $val) + foreach ($this->CI->db->queries as $val) { $output .= '
'; $output .= $val; @@ -136,12 +136,12 @@ class CI_Profiler { $output = "\n\n"; $output .= '
'; $output .= "\n"; - $output .= '  '.$this->obj->lang->line('profiler_post_data').'  '; + $output .= '  '.$this->CI->lang->line('profiler_post_data').'  '; $output .= "\n"; if (count($_POST) == 0) { - $output .= "
".$this->obj->lang->line('profiler_no_post')."
"; + $output .= "
".$this->CI->lang->line('profiler_no_post')."
"; } else { diff --git a/system/libraries/Session.php b/system/libraries/Session.php index 28e469da7..16f373fd0 100644 --- a/system/libraries/Session.php +++ b/system/libraries/Session.php @@ -26,6 +26,7 @@ */ class CI_Session { + var $CI; var $now; var $encryption = TRUE; var $use_database = FALSE; @@ -34,7 +35,7 @@ class CI_Session { var $sess_cookie = 'ci_session'; var $userdata = array(); var $gc_probability = 5; - var $object; + /** @@ -45,7 +46,7 @@ class CI_Session { */ function CI_Session() { - $this->object =& get_instance(); + $this->CI =& get_instance(); log_message('debug', "Session Class Initialized"); $this->sess_run(); @@ -73,7 +74,7 @@ class CI_Session { * "last_visit" times based on each user's locale. * */ - if (strtolower($this->object->config->item('time_reference')) == 'gmt') + if (strtolower($this->CI->config->item('time_reference')) == 'gmt') { $now = time(); $this->now = mktime(gmdate("H", $now), gmdate("i", $now), gmdate("s", $now), gmdate("m", $now), gmdate("d", $now), gmdate("Y", $now)); @@ -97,13 +98,13 @@ class CI_Session { * two years from now. * */ - $expiration = $this->object->config->item('sess_expiration'); + $expiration = $this->CI->config->item('sess_expiration'); if (is_numeric($expiration)) { if ($expiration > 0) { - $this->sess_length = $this->object->config->item('sess_expiration'); + $this->sess_length = $this->CI->config->item('sess_expiration'); } else { @@ -112,25 +113,25 @@ class CI_Session { } // Do we need encryption? - $this->encryption = $this->object->config->item('sess_encrypt_cookie'); + $this->encryption = $this->CI->config->item('sess_encrypt_cookie'); if ($this->encryption == TRUE) { - $this->object->load->library('encrypt'); + $this->CI->load->library('encrypt'); } // Are we using a database? - if ($this->object->config->item('sess_use_database') === TRUE AND $this->object->config->item('sess_table_name') != '') + if ($this->CI->config->item('sess_use_database') === TRUE AND $this->CI->config->item('sess_table_name') != '') { $this->use_database = TRUE; - $this->session_table = $this->object->config->item('sess_table_name'); - $this->object->load->database(); + $this->session_table = $this->CI->config->item('sess_table_name'); + $this->CI->load->database(); } // Set the cookie name - if ($this->object->config->item('sess_cookie_name') != FALSE) + if ($this->CI->config->item('sess_cookie_name') != FALSE) { - $this->sess_cookie = $this->object->config->item('cookie_prefix').$this->object->config->item('sess_cookie_name'); + $this->sess_cookie = $this->CI->config->item('cookie_prefix').$this->CI->config->item('sess_cookie_name'); } /* @@ -172,7 +173,7 @@ class CI_Session { function sess_read() { // Fetch the cookie - $session = $this->object->input->cookie($this->sess_cookie); + $session = $this->CI->input->cookie($this->sess_cookie); if ($session === FALSE) { @@ -183,7 +184,7 @@ class CI_Session { // Decrypt and unserialize the data if ($this->encryption == TRUE) { - $session = $this->object->encrypt->decode($session); + $session = $this->CI->encrypt->decode($session); } $session = @unserialize($this->strip_slashes($session)); @@ -202,14 +203,14 @@ class CI_Session { } // Does the IP Match? - if ($this->object->config->item('sess_match_ip') == TRUE AND $session['ip_address'] != $this->object->input->ip_address()) + if ($this->CI->config->item('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->object->config->item('sess_match_useragent') == TRUE AND $session['user_agent'] != substr($this->object->input->user_agent(), 0, 50)) + if ($this->CI->config->item('sess_match_useragent') == TRUE AND $session['user_agent'] != substr($this->CI->input->user_agent(), 0, 50)) { $this->sess_destroy(); return FALSE; @@ -218,19 +219,19 @@ class CI_Session { // Is there a corresponding session in the DB? if ($this->use_database === TRUE) { - $this->object->db->where('session_id', $session['session_id']); + $this->CI->db->where('session_id', $session['session_id']); - if ($this->object->config->item('sess_match_ip') == TRUE) + if ($this->CI->config->item('sess_match_ip') == TRUE) { - $this->object->db->where('ip_address', $session['ip_address']); + $this->CI->db->where('ip_address', $session['ip_address']); } - if ($this->object->config->item('sess_match_useragent') == TRUE) + if ($this->CI->config->item('sess_match_useragent') == TRUE) { - $this->object->db->where('user_agent', $session['user_agent']); + $this->CI->db->where('user_agent', $session['user_agent']); } - $query = $this->object->db->get($this->session_table); + $query = $this->CI->db->get($this->session_table); if ($query->num_rows() == 0) { @@ -242,8 +243,8 @@ class CI_Session { $row = $query->row(); if (($row->last_activity + $this->sess_length) < $this->now) { - $this->object->db->where('session_id', $session['session_id']); - $this->object->db->delete($this->session_table); + $this->CI->db->where('session_id', $session['session_id']); + $this->CI->db->delete($this->session_table); $this->sess_destroy(); return FALSE; } @@ -272,15 +273,15 @@ class CI_Session { if ($this->encryption == TRUE) { - $cookie_data = $this->object->encrypt->encode($cookie_data); + $cookie_data = $this->CI->encrypt->encode($cookie_data); } setcookie( $this->sess_cookie, $cookie_data, $this->sess_length + $this->now, - $this->object->config->item('cookie_path'), - $this->object->config->item('cookie_domain'), + $this->CI->config->item('cookie_path'), + $this->CI->config->item('cookie_domain'), 0 ); } @@ -304,8 +305,8 @@ class CI_Session { $this->userdata = array( 'session_id' => md5(uniqid($sessid, TRUE)), - 'ip_address' => $this->object->input->ip_address(), - 'user_agent' => substr($this->object->input->user_agent(), 0, 50), + 'ip_address' => $this->CI->input->ip_address(), + 'user_agent' => substr($this->CI->input->user_agent(), 0, 50), 'last_activity' => $this->now ); @@ -313,7 +314,7 @@ class CI_Session { // Save the session in the DB if needed if ($this->use_database === TRUE) { - $this->object->db->query($this->object->db->insert_string($this->session_table, $this->userdata)); + $this->CI->db->query($this->CI->db->insert_string($this->session_table, $this->userdata)); } // Write the cookie @@ -342,7 +343,7 @@ class CI_Session { // Update the session in the DB if needed if ($this->use_database === TRUE) { - $this->object->db->query($this->object->db->update_string($this->session_table, array('last_activity' => $this->now), array('session_id' => $this->userdata['session_id']))); + $this->CI->db->query($this->CI->db->update_string($this->session_table, array('last_activity' => $this->now), array('session_id' => $this->userdata['session_id']))); } // Write the cookie @@ -364,8 +365,8 @@ class CI_Session { $this->sess_cookie, addslashes(serialize(array())), ($this->now - 31500000), - $this->object->config->item('cookie_path'), - $this->object->config->item('cookie_domain'), + $this->CI->config->item('cookie_path'), + $this->CI->config->item('cookie_domain'), 0 ); } @@ -389,8 +390,8 @@ class CI_Session { { $expire = $this->now - $this->sess_length; - $this->object->db->where("last_activity < {$expire}"); - $this->object->db->delete($this->session_table); + $this->CI->db->where("last_activity < {$expire}"); + $this->CI->db->delete($this->session_table); log_message('debug', 'Session garbage collection performed.'); } diff --git a/system/libraries/Validation.php b/system/libraries/Validation.php index ff5970837..5322be0e9 100644 --- a/system/libraries/Validation.php +++ b/system/libraries/Validation.php @@ -26,6 +26,7 @@ */ class CI_Validation { + var $CI; var $error_string = ''; var $_error_array = array(); var $_rules = array(); @@ -35,7 +36,7 @@ class CI_Validation { var $_safe_form_data = FALSE; var $_error_prefix = '

'; var $_error_suffix = '

'; - var $obj; + /** @@ -44,7 +45,7 @@ class CI_Validation { */ function CI_Validation() { - $this->obj =& get_instance(); + $this->CI =& get_instance(); log_message('debug', "Validation Class Initialized"); } @@ -185,7 +186,7 @@ class CI_Validation { } // Load the language file containing error messages - $this->obj->lang->load('validation'); + $this->CI->lang->load('validation'); // Cycle through the rules and test for errors foreach ($this->_rules as $field => $rules) @@ -217,7 +218,7 @@ class CI_Validation { { if ( ! isset($this->_error_messages['isset'])) { - if (FALSE === ($line = $this->obj->lang->line('isset'))) + if (FALSE === ($line = $this->CI->lang->line('isset'))) { $line = 'The field was not set'; } @@ -267,12 +268,12 @@ class CI_Validation { // Call the function that corresponds to the rule if ($callback === TRUE) { - if ( ! method_exists($this->obj, $rule)) + if ( ! method_exists($this->CI, $rule)) { continue; } - $result = $this->obj->$rule($_POST[$field], $param); + $result = $this->CI->$rule($_POST[$field], $param); // If the field isn't required and we just processed a callback we'll move on... if ( ! in_array('required', $ex, TRUE) AND $result !== FALSE) @@ -309,7 +310,7 @@ class CI_Validation { { if ( ! isset($this->_error_messages[$rule])) { - if (FALSE === ($line = $this->obj->lang->line($rule))) + if (FALSE === ($line = $this->CI->lang->line($rule))) { $line = 'Unable to access an error message corresponding to your field name.'; } @@ -698,7 +699,7 @@ class CI_Validation { */ function xss_clean($str) { - $_POST[$this->_current_field] = $this->obj->input->xss_clean($str); + $_POST[$this->_current_field] = $this->CI->input->xss_clean($str); } // -------------------------------------------------------------------- diff --git a/system/scaffolding/Scaffolding.php b/system/scaffolding/Scaffolding.php index 9059ec15a..c046d228f 100644 --- a/system/scaffolding/Scaffolding.php +++ b/system/scaffolding/Scaffolding.php @@ -27,25 +27,25 @@ */ class Scaffolding { + var $CI; var $current_table; var $base_url = ''; var $lang = array(); function Scaffolding($db_table) { - $obj =& get_instance(); - foreach (get_object_vars($obj) as $key => $var) - { - if (is_object($var)) - { - $this->$key =& $obj->$key; - } - } + $this->CI =& get_instance(); + + $this->CI->load->database("", FALSE, TRUE); + $this->CI->load->library('pagination'); + + // Turn off caching + $this->CI->db->cache_off(); /** * Set the current table name * This is done when initializing scaffolding: - * $this->_ci_init_scaffolding('table_name') + * $this->load->scaffolding('table_name') * */ $this->current_table = $db_table; @@ -55,28 +55,29 @@ class Scaffolding { * We'll manually override the "view" path so that * the load->view function knows where to look. */ - $this->load->_ci_set_view_path(BASEPATH.'scaffolding/views/'); + + $this->CI->load->view_path = BASEPATH.'scaffolding/views/'; // Set the base URL - $this->base_url = $this->config->site_url().'/'.$this->uri->segment(1).$this->uri->slash_segment(2, 'both'); - $this->base_uri = $this->uri->segment(1).$this->uri->slash_segment(2, 'leading'); + $this->base_url = $this->CI->config->site_url().'/'.$this->CI->uri->segment(1).$this->CI->uri->slash_segment(2, 'both'); + $this->base_uri = $this->CI->uri->segment(1).$this->CI->uri->slash_segment(2, 'leading'); // Set a few globals $data = array( - 'image_url' => $this->config->system_url().'scaffolding/images/', + 'image_url' => $this->CI->config->system_url().'scaffolding/images/', 'base_uri' => $this->base_uri, 'base_url' => $this->base_url, 'title' => $this->current_table ); - $this->load->vars($data); + $this->CI->load->vars($data); // Load the language file and create variables - $this->lang = $this->load->language('scaffolding', '', TRUE); - $this->load->vars($this->lang); + $this->lang = $this->CI->load->language('scaffolding', '', TRUE); + $this->CI->load->vars($this->lang); // Load the helper files we plan to use - $this->load->helper(array('url', 'form')); + $this->CI->load->helper(array('url', 'form')); log_message('debug', 'Scaffolding Class Initialized'); @@ -97,11 +98,11 @@ class Scaffolding { { $data = array( 'title' => ( ! isset($this->lang['scaff_add'])) ? 'Add Data' : $this->lang['scaff_add'], - 'fields' => $this->db->field_data($this->current_table), + 'fields' => $this->CI->db->field_data($this->current_table), 'action' => $this->base_uri.'/insert' ); - $this->load->view('add', $data); + $this->CI->load->view('add', $data); } // -------------------------------------------------------------------- @@ -114,7 +115,7 @@ class Scaffolding { */ function insert() { - if ($this->db->insert($this->current_table, $_POST) === FALSE) + if ($this->CI->db->insert($this->current_table, $_POST) === FALSE) { $this->add(); } @@ -138,28 +139,28 @@ class Scaffolding { function view() { // Fetch the total number of DB rows - $total_rows = $this->db->count_all($this->current_table); + $total_rows = $this->CI->db->count_all($this->current_table); if ($total_rows < 1) { - return $this->load->view('no_data'); + return $this->CI->load->view('no_data'); } // Set the query limit/offset $per_page = 20; - $offset = $this->uri->segment(4, 0); + $offset = $this->CI->uri->segment(4, 0); // Run the query - $query = $this->db->get($this->current_table, $per_page, $offset); + $query = $this->CI->db->get($this->current_table, $per_page, $offset); // Now let's get the field names - $fields = $this->db->field_names($this->current_table); + $fields = $this->CI->db->field_names($this->current_table); // We assume that the column in the first position is the primary field. $primary = current($fields); // Pagination! - $this->pagination->initialize( + $this->CI->pagination->initialize( array( 'base_url' => $this->base_url.'/view', 'total_rows' => $total_rows, @@ -175,10 +176,10 @@ class Scaffolding { 'query' => $query, 'fields' => $fields, 'primary' => $primary, - 'paginate' => $this->pagination->create_links() + 'paginate' => $this->CI->pagination->create_links() ); - $this->load->view('view', $data); + $this->CI->load->view('view', $data); } // -------------------------------------------------------------------- @@ -194,25 +195,25 @@ class Scaffolding { */ function edit() { - if (FALSE === ($id = $this->uri->segment(4))) + if (FALSE === ($id = $this->CI->uri->segment(4))) { return $this->view(); } // Fetch the primary field name - $primary = $this->db->primary($this->current_table); + $primary = $this->CI->db->primary($this->current_table); // Run the query - $query = $this->db->getwhere($this->current_table, array($primary => $id)); + $query = $this->CI->db->getwhere($this->current_table, array($primary => $id)); $data = array( 'title' => ( ! isset($this->lang['scaff_edit'])) ? 'Edit Data' : $this->lang['scaff_edit'], 'fields' => $query->field_data(), 'query' => $query->row(), - 'action' => $this->base_uri.'/update/'.$this->uri->segment(4) + 'action' => $this->base_uri.'/update/'.$this->CI->uri->segment(4) ); - $this->load->view('edit', $data); + $this->CI->load->view('edit', $data); } // -------------------------------------------------------------------- @@ -226,10 +227,10 @@ class Scaffolding { function update() { // Fetch the primary key - $primary = $this->db->primary($this->current_table); + $primary = $this->CI->db->primary($this->current_table); // Now do the query - $this->db->update($this->current_table, $_POST, array($primary => $this->uri->segment(4))); + $this->CI->db->update($this->current_table, $_POST, array($primary => $this->CI->uri->segment(4))); redirect($this->base_uri.'/view/'); } @@ -246,21 +247,21 @@ class Scaffolding { { if ( ! isset($this->lang['scaff_del_confirm'])) { - $message = 'Are you sure you want to delete the following row: '.$this->uri->segment(4); + $message = 'Are you sure you want to delete the following row: '.$this->CI->uri->segment(4); } else { - $message = $this->lang['scaff_del_confirm'].' '.$this->uri->segment(4); + $message = $this->lang['scaff_del_confirm'].' '.$this->CI->uri->segment(4); } $data = array( 'title' => ( ! isset($this->lang['scaff_delete'])) ? 'Delete Data' : $this->lang['scaff_delete'], 'message' => $message, 'no' => anchor(array($this->base_uri, 'view'), ( ! isset($this->lang['scaff_no'])) ? 'No' : $this->lang['scaff_no']), - 'yes' => anchor(array($this->base_uri, 'do_delete', $this->uri->segment(4)), ( ! isset($this->lang['scaff_yes'])) ? 'Yes' : $this->lang['scaff_yes']) + 'yes' => anchor(array($this->base_uri, 'do_delete', $this->CI->uri->segment(4)), ( ! isset($this->lang['scaff_yes'])) ? 'Yes' : $this->lang['scaff_yes']) ); - $this->load->view('delete', $data); + $this->CI->load->view('delete', $data); } // -------------------------------------------------------------------- @@ -274,11 +275,11 @@ class Scaffolding { function do_delete() { // Fetch the primary key - $primary = $this->db->primary($this->current_table); + $primary = $this->CI->db->primary($this->current_table); // Now do the query - $this->db->where($primary, $this->uri->segment(4)); - $this->db->delete($this->current_table); + $this->CI->db->where($primary, $this->CI->uri->segment(4)); + $this->CI->db->delete($this->current_table); header("Refresh:0;url=".site_url(array($this->base_uri, 'view'))); exit; -- cgit v1.2.3-24-g4f1b From 88a8ad187b13b36d6120eae2344fe16c3a76219d Mon Sep 17 00:00:00 2001 From: admin Date: Sat, 7 Oct 2006 03:16:32 +0000 Subject: --- system/database/DB.php | 7 +++---- system/database/DB_driver.php | 8 ++++---- system/database/DB_utility.php | 21 ++++++++++----------- system/libraries/Controller.php | 2 +- system/libraries/Email.php | 6 +++--- system/libraries/Encrypt.php | 4 ++-- system/libraries/Image_lib.php | 8 ++++---- system/libraries/Language.php | 4 ++-- system/libraries/Model.php | 8 ++++---- system/libraries/Output.php | 24 ++++++++++++------------ system/libraries/Pagination.php | 6 +++--- system/libraries/Parser.php | 6 +++--- system/libraries/Profiler.php | 4 +--- system/libraries/Unit.php | 12 ++++++------ system/libraries/Upload.php | 12 ++++++------ system/libraries/Xmlrpc.php | 12 ++++++------ system/libraries/Xmlrpcs.php | 4 ++-- 17 files changed, 72 insertions(+), 76 deletions(-) (limited to 'system') diff --git a/system/database/DB.php b/system/database/DB.php index f7476a68e..62237440f 100644 --- a/system/database/DB.php +++ b/system/database/DB.php @@ -24,8 +24,6 @@ */ function DB($params = '', $return = FALSE, $active_record = FALSE) { - $obj =& get_instance(); - // Do we even need to load the database class? if (class_exists('CI_DB') AND $return == FALSE AND $active_record == FALSE) { @@ -92,8 +90,9 @@ function DB($params = '', $return = FALSE, $active_record = FALSE) { return $DB; } - - $obj->db =& $DB; + + $CI =& get_instance(); + $CI->db =& $DB; } diff --git a/system/database/DB_driver.php b/system/database/DB_driver.php index b89ebbf8d..c8a00b7b1 100644 --- a/system/database/DB_driver.php +++ b/system/database/DB_driver.php @@ -165,13 +165,13 @@ class CI_DB_driver { * @return string */ function load_utilities() - { - $obj =& get_instance(); - + { require_once(BASEPATH.'database/DB_utility'.EXT); require_once(BASEPATH.'database/drivers/'.$this->dbdriver.'/'.$this->dbdriver.'_utility'.EXT); $class = 'CI_DB_'.$this->dbdriver.'_utility'; - $obj->dbutil = new $class(); + + $CI =& get_instance(); + $CI->dbutil = new $class(); } // -------------------------------------------------------------------- diff --git a/system/database/DB_utility.php b/system/database/DB_utility.php index 433056ff0..64d67db41 100644 --- a/system/database/DB_utility.php +++ b/system/database/DB_utility.php @@ -36,8 +36,8 @@ class CI_DB_utility { function CI_DB_utility() { // Assign the main database object to $this->db - $obj =& get_instance(); - $this->db =& $obj->db; + $CI =& get_instance(); + $this->CI =& $obj->db; log_message('debug', "Database Utility Class Initialized"); } @@ -286,8 +286,8 @@ class CI_DB_utility { extract($params); // Load the xml helper - $obj =& get_instance(); - $obj->load->helper('xml'); + $CI =& get_instance(); + $CI->load->helper('xml'); // Generate the result $xml = "<{$root}/>".$newline; @@ -391,10 +391,7 @@ class CI_DB_utility { } // ------------------------------------------------------ - - // Grab the super object - $obj =& get_instance(); - + // Was a Gzip file requested? if ($prefs['format'] == 'gzip') { @@ -427,9 +424,11 @@ class CI_DB_utility { } // Load the Zip class and output it - $obj->load->library('zip'); - $obj->zip->add_data($prefs['filename'], $this->_backup($prefs)); - return $obj->zip->get_zip(); + + $CI =& get_instance(); + $CI->load->library('zip'); + $CI->zip->add_data($prefs['filename'], $this->_backup($prefs)); + return $CI->zip->get_zip(); } } diff --git a/system/libraries/Controller.php b/system/libraries/Controller.php index 58bec841e..4b9e3e960 100644 --- a/system/libraries/Controller.php +++ b/system/libraries/Controller.php @@ -102,7 +102,7 @@ class Controller extends CI_Base { * Run Scaffolding * * @access private - * @return voikd + * @return void */ function _ci_scaffolding() { diff --git a/system/libraries/Email.php b/system/libraries/Email.php index 99de17414..23f7fe456 100644 --- a/system/libraries/Email.php +++ b/system/libraries/Email.php @@ -1629,10 +1629,10 @@ class CI_Email { */ function _set_error_message($msg, $val = '') { - $obj =& get_instance(); - $obj->lang->load('email'); + $CI =& get_instance(); + $CI->lang->load('email'); - if (FALSE === ($line = $obj->lang->line($msg))) + if (FALSE === ($line = $CI->lang->line($msg))) { $this->_debug_msg[] = str_replace('%s', $val, $msg)."
"; } diff --git a/system/libraries/Encrypt.php b/system/libraries/Encrypt.php index 537b1ab20..2a1de6f37 100644 --- a/system/libraries/Encrypt.php +++ b/system/libraries/Encrypt.php @@ -66,8 +66,8 @@ class CI_Encrypt { return $this->encryption_key; } - $obj =& get_instance(); - $key = $obj->config->item('encryption_key'); + $CI =& get_instance(); + $key = $CI->config->item('encryption_key'); if ($key === FALSE) { diff --git a/system/libraries/Image_lib.php b/system/libraries/Image_lib.php index ca1d7478b..79b2f9c1c 100644 --- a/system/libraries/Image_lib.php +++ b/system/libraries/Image_lib.php @@ -1503,22 +1503,22 @@ class CI_Image_lib { */ function set_error($msg) { - $obj =& get_instance(); - $obj->lang->load('imglib'); + $CI =& get_instance(); + $CI->lang->load('imglib'); if (is_array($msg)) { foreach ($msg as $val) { - $msg = ($obj->lang->line($val) == FALSE) ? $val : $obj->lang->line($val); + $msg = ($CI->lang->line($val) == FALSE) ? $val : $CI->lang->line($val); $this->error_msg[] = $msg; log_message('error', $msg); } } else { - $msg = ($obj->lang->line($msg) == FALSE) ? $msg : $obj->lang->line($msg); + $msg = ($CI->lang->line($msg) == FALSE) ? $msg : $CI->lang->line($msg); $this->error_msg[] = $msg; log_message('error', $msg); } diff --git a/system/libraries/Language.php b/system/libraries/Language.php index dabfd4145..00e2fb7e8 100644 --- a/system/libraries/Language.php +++ b/system/libraries/Language.php @@ -61,8 +61,8 @@ class CI_Language { if ($idiom == '') { - $obj =& get_instance(); - $deft_lang = $obj->config->item('language'); + $CI =& get_instance(); + $deft_lang = $CI->config->item('language'); $idiom = ($deft_lang == '') ? 'english' : $deft_lang; } diff --git a/system/libraries/Model.php b/system/libraries/Model.php index 55c995636..46f0367cb 100644 --- a/system/libraries/Model.php +++ b/system/libraries/Model.php @@ -49,18 +49,18 @@ class Model { */ function _assign_libraries($use_reference = TRUE) { - $obj =& get_instance(); - foreach (get_object_vars($obj) as $key => $var) + $CI =& get_instance(); + foreach (get_object_vars($CI) as $key => $var) { if (is_object($var) AND ! isset($this->$key)) { if ($use_reference === TRUE) { - $this->$key =& $obj->$key; + $this->$key =& $CI->$key; } else { - $this->$key = $obj->$key; + $this->$key = $CI->$key; } } } diff --git a/system/libraries/Output.php b/system/libraries/Output.php index 4ab5dd23c..507beab59 100644 --- a/system/libraries/Output.php +++ b/system/libraries/Output.php @@ -135,7 +135,7 @@ class CI_Output { */ function _display($output = '') { - // Note: We use globals because we can't use $obj =& get_instance() + // 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; @@ -207,25 +207,25 @@ class CI_Output { // -------------------------------------------------------------------- // Grab the super object. We'll need it in a moment... - $obj =& get_instance(); + $CI =& get_instance(); // Do we need to generate profile data? // If so, load the Profile class and run it. if ($this->enable_profiler == TRUE) { - $obj->load->library('profiler'); + $CI->load->library('profiler'); // 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 .= $obj->profiler->run(); + $output .= $CI->profiler->run(); $output .= ''; } else { - $output .= $obj->profiler->run(); + $output .= $CI->profiler->run(); } } @@ -233,9 +233,9 @@ class CI_Output { // Does the controller contain a function named _output()? // If so send the output there. Otherwise, echo it. - if (method_exists($obj, '_output')) + if (method_exists($CI, '_output')) { - $obj->_output($output); + $CI->_output($output); } else { @@ -256,8 +256,8 @@ class CI_Output { */ function _write_cache($output) { - $obj =& get_instance(); - $path = $obj->config->item('cache_path'); + $CI =& get_instance(); + $path = $CI->config->item('cache_path'); $cache_path = ($path == '') ? BASEPATH.'cache/' : $path; @@ -266,9 +266,9 @@ class CI_Output { return; } - $uri = $obj->config->item('base_url'). - $obj->config->item('index_page'). - $obj->uri->uri_string(); + $uri = $CI->config->item('base_url'). + $CI->config->item('index_page'). + $CI->uri->uri_string(); $cache_path .= md5($uri); diff --git a/system/libraries/Pagination.php b/system/libraries/Pagination.php index 867d214fc..efbe6c27f 100644 --- a/system/libraries/Pagination.php +++ b/system/libraries/Pagination.php @@ -122,10 +122,10 @@ class CI_Pagination { } // Determine the current page number. - $obj =& get_instance(); - if ($obj->uri->segment($this->uri_segment) != 0) + $CI =& get_instance(); + if ($CI->uri->segment($this->uri_segment) != 0) { - $this->cur_page = $obj->uri->segment($this->uri_segment); + $this->cur_page = $CI->uri->segment($this->uri_segment); } if ( ! is_numeric($this->cur_page)) diff --git a/system/libraries/Parser.php b/system/libraries/Parser.php index 42e78b0ee..a0c9dab9e 100644 --- a/system/libraries/Parser.php +++ b/system/libraries/Parser.php @@ -44,8 +44,8 @@ class CI_Parser { */ function parse($template, $data, $return = FALSE) { - $obj =& get_instance(); - $template = $obj->load->view($template, $data, TRUE); + $CI =& get_instance(); + $template = $CI->load->view($template, $data, TRUE); if ($template == '') { @@ -66,7 +66,7 @@ class CI_Parser { if ($return == FALSE) { - $obj->output->final_output = $template; + $CI->output->final_output = $template; } return $template; diff --git a/system/libraries/Profiler.php b/system/libraries/Profiler.php index d91f23193..3370c9113 100644 --- a/system/libraries/Profiler.php +++ b/system/libraries/Profiler.php @@ -173,9 +173,7 @@ class CI_Profiler { * @return string */ function run($output = '') - { - $obj =& get_instance(); - + { $output = '
'; $output .= "
"; diff --git a/system/libraries/Unit.php b/system/libraries/Unit.php index 0df78c253..6573f4269 100644 --- a/system/libraries/Unit.php +++ b/system/libraries/Unit.php @@ -171,8 +171,8 @@ class CI_Unit { */ function result($results = array()) { - $obj =& get_instance(); - $obj->load->language('unit_test'); + $CI =& get_instance(); + $CI->load->language('unit_test'); if (count($results) == 0) { @@ -189,20 +189,20 @@ class CI_Unit { { foreach ($val as $k => $v) { - if (FALSE !== ($line = $obj->lang->line(strtolower('ut_'.$v)))) + if (FALSE !== ($line = $CI->lang->line(strtolower('ut_'.$v)))) { $v = $line; } - $temp[$obj->lang->line('ut_'.$k)] = $v; + $temp[$CI->lang->line('ut_'.$k)] = $v; } } else { - if (FALSE !== ($line = $obj->lang->line(strtolower('ut_'.$val)))) + if (FALSE !== ($line = $CI->lang->line(strtolower('ut_'.$val)))) { $val = $line; } - $temp[$obj->lang->line('ut_'.$key)] = $val; + $temp[$CI->lang->line('ut_'.$key)] = $val; } } diff --git a/system/libraries/Upload.php b/system/libraries/Upload.php index 37fccdfd8..13fa8acdf 100644 --- a/system/libraries/Upload.php +++ b/system/libraries/Upload.php @@ -684,8 +684,8 @@ class CI_Upload { $data = fread($fp, filesize($file)); - $obj =& get_instance(); - $data = $obj->input->xss_clean($data); + $CI =& get_instance(); + $data = $CI->input->xss_clean($data); fwrite($fp, $data); flock($fp, LOCK_UN); @@ -703,21 +703,21 @@ class CI_Upload { */ function set_error($msg) { - $obj =& get_instance(); - $obj->lang->load('upload'); + $CI =& get_instance(); + $CI->lang->load('upload'); if (is_array($msg)) { foreach ($msg as $val) { - $msg = ($obj->lang->line($val) == FALSE) ? $val : $obj->lang->line($val); + $msg = ($CI->lang->line($val) == FALSE) ? $val : $CI->lang->line($val); $this->error_msg[] = $msg; log_message('error', $msg); } } else { - $msg = ($obj->lang->line($msg) == FALSE) ? $msg : $obj->lang->line($msg); + $msg = ($CI->lang->line($msg) == FALSE) ? $msg : $CI->lang->line($msg); $this->error_msg[] = $msg; log_message('error', $msg); } diff --git a/system/libraries/Xmlrpc.php b/system/libraries/Xmlrpc.php index 4cb16f74e..0a3dedae1 100644 --- a/system/libraries/Xmlrpc.php +++ b/system/libraries/Xmlrpc.php @@ -493,7 +493,7 @@ class XML_RPC_Response function decode($array=FALSE) { - $obj =& get_instance(); + $CI =& get_instance(); if ($array !== FALSE && is_array($array)) { @@ -505,7 +505,7 @@ class XML_RPC_Response } else { - $array[$key] = $obj->input->xss_clean($array[$key]); + $array[$key] = $CI->input->xss_clean($array[$key]); } } @@ -521,7 +521,7 @@ class XML_RPC_Response } else { - $result = $obj->input->xss_clean($result); + $result = $CI->input->xss_clean($result); } } @@ -1107,7 +1107,7 @@ class XML_RPC_Message extends CI_Xmlrpc function output_parameters($array=FALSE) { - $obj =& get_instance(); + $CI =& get_instance(); if ($array !== FALSE && is_array($array)) { @@ -1119,7 +1119,7 @@ class XML_RPC_Message extends CI_Xmlrpc } else { - $array[$key] = $obj->input->xss_clean($array[$key]); + $array[$key] = $CI->input->xss_clean($array[$key]); } } @@ -1139,7 +1139,7 @@ class XML_RPC_Message extends CI_Xmlrpc } else { - $parameters[] = $obj->input->xss_clean($a_param); + $parameters[] = $CI->input->xss_clean($a_param); } } } diff --git a/system/libraries/Xmlrpcs.php b/system/libraries/Xmlrpcs.php index b47104857..e4d3cffde 100644 --- a/system/libraries/Xmlrpcs.php +++ b/system/libraries/Xmlrpcs.php @@ -318,8 +318,8 @@ class CI_Xmlrpcs extends CI_Xmlrpc } else { - $obj =& get_instance(); - return $obj->$method_parts['1']($m); + $CI =& get_instance(); + return $CI->$method_parts['1']($m); //$class = new $method_parts['0']; //return $class->$method_parts['1']($m); //return call_user_func(array(&$method_parts['0'],$method_parts['1']), $m); -- cgit v1.2.3-24-g4f1b From 75198f97ba9df6e5696ac295820d9d73a4e4f441 Mon Sep 17 00:00:00 2001 From: admin Date: Sat, 7 Oct 2006 03:16:53 +0000 Subject: --- system/helpers/cookie_helper.php | 18 +++++++++--------- system/helpers/date_helper.php | 28 ++++++++++++++-------------- system/helpers/form_helper.php | 4 ++-- system/helpers/security_helper.php | 4 ++-- system/helpers/url_helper.php | 12 ++++++------ 5 files changed, 33 insertions(+), 33 deletions(-) (limited to 'system') diff --git a/system/helpers/cookie_helper.php b/system/helpers/cookie_helper.php index fc5920f25..8985fae2e 100644 --- a/system/helpers/cookie_helper.php +++ b/system/helpers/cookie_helper.php @@ -56,19 +56,19 @@ function set_cookie($name = '', $value = '', $expire = '', $domain = '', $path = } // Set the config file options - $obj =& get_instance(); + $CI =& get_instance(); - if ($prefix == '' AND $obj->config->item('cookie_prefix') != '') + if ($prefix == '' AND $CI->config->item('cookie_prefix') != '') { - $obj->config->item('cookie_prefix'); + $CI->config->item('cookie_prefix'); } - if ($domain == '' AND $obj->config->item('cookie_domain') != '') + if ($domain == '' AND $CI->config->item('cookie_domain') != '') { - $obj->config->item('cookie_domain'); + $CI->config->item('cookie_domain'); } - if ($prefix == '/' AND $obj->config->item('cookie_path') != '/') + if ($prefix == '/' AND $CI->config->item('cookie_path') != '/') { - $obj->config->item('cookie_path'); + $CI->config->item('cookie_path'); } if ( ! is_numeric($expire)) @@ -102,8 +102,8 @@ function set_cookie($name = '', $value = '', $expire = '', $domain = '', $path = */ function get_cookie($index = '', $xss_clean = FALSE) { - $obj =& get_instance(); - return $obj->input->cookie($index, $xss_clean); + $CI =& get_instance(); + return $CI->input->cookie($index, $xss_clean); } // -------------------------------------------------------------------- diff --git a/system/helpers/date_helper.php b/system/helpers/date_helper.php index 987658c2e..03519e686 100644 --- a/system/helpers/date_helper.php +++ b/system/helpers/date_helper.php @@ -37,9 +37,9 @@ */ function now() { - $obj =& get_instance(); + $CI =& get_instance(); - if (strtolower($obj->config->item('time_reference')) == 'gmt') + if (strtolower($CI->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)); @@ -140,8 +140,8 @@ function standard_date($fmt = 'DATE_RFC822', $time = '') */ function timespan($seconds = 1, $time = '') { - $obj =& get_instance(); - $obj->lang->load('date'); + $CI =& get_instance(); + $CI->lang->load('date'); if ( ! is_numeric($seconds)) { @@ -167,7 +167,7 @@ function timespan($seconds = 1, $time = '') if ($years > 0) { - $str .= $years.' '.$obj->lang->line((($years > 1) ? 'date_years' : 'date_year')).', '; + $str .= $years.' '.$CI->lang->line((($years > 1) ? 'date_years' : 'date_year')).', '; } $seconds -= $years * 31536000; @@ -177,7 +177,7 @@ function timespan($seconds = 1, $time = '') { if ($months > 0) { - $str .= $months.' '.$obj->lang->line((($months > 1) ? 'date_months' : 'date_month')).', '; + $str .= $months.' '.$CI->lang->line((($months > 1) ? 'date_months' : 'date_month')).', '; } $seconds -= $months * 2628000; @@ -189,7 +189,7 @@ function timespan($seconds = 1, $time = '') { if ($weeks > 0) { - $str .= $weeks.' '.$obj->lang->line((($weeks > 1) ? 'date_weeks' : 'date_week')).', '; + $str .= $weeks.' '.$CI->lang->line((($weeks > 1) ? 'date_weeks' : 'date_week')).', '; } $seconds -= $weeks * 604800; @@ -201,7 +201,7 @@ function timespan($seconds = 1, $time = '') { if ($days > 0) { - $str .= $days.' '.$obj->lang->line((($days > 1) ? 'date_days' : 'date_day')).', '; + $str .= $days.' '.$CI->lang->line((($days > 1) ? 'date_days' : 'date_day')).', '; } $seconds -= $days * 86400; @@ -213,7 +213,7 @@ function timespan($seconds = 1, $time = '') { if ($hours > 0) { - $str .= $hours.' '.$obj->lang->line((($hours > 1) ? 'date_hours' : 'date_hour')).', '; + $str .= $hours.' '.$CI->lang->line((($hours > 1) ? 'date_hours' : 'date_hour')).', '; } $seconds -= $hours * 3600; @@ -225,7 +225,7 @@ function timespan($seconds = 1, $time = '') { if ($minutes > 0) { - $str .= $minutes.' '.$obj->lang->line((($minutes > 1) ? 'date_minutes' : 'date_minute')).', '; + $str .= $minutes.' '.$CI->lang->line((($minutes > 1) ? 'date_minutes' : 'date_minute')).', '; } $seconds -= $minutes * 60; @@ -233,7 +233,7 @@ function timespan($seconds = 1, $time = '') if ($str == '') { - $str .= $seconds.' '.$obj->lang->line((($seconds > 1) ? 'date_seconds' : 'date_second')).', '; + $str .= $seconds.' '.$CI->lang->line((($seconds > 1) ? 'date_seconds' : 'date_second')).', '; } return substr(trim($str), 0, -1); @@ -475,8 +475,8 @@ function human_to_unix($datestr = '') */ function timezone_menu($default = 'UTC', $class = "", $name = 'timezones') { - $obj =& get_instance(); - $obj->lang->load('date'); + $CI =& get_instance(); + $CI->lang->load('date'); if ($default == 'GMT') $default = 'UTC'; @@ -493,7 +493,7 @@ function timezone_menu($default = 'UTC', $class = "", $name = 'timezones') foreach (timezones() as $key => $val) { $selected = ($default == $key) ? " selected='selected'" : ''; - $menu .= "\n"; + $menu .= "\n"; } $menu .= ""; diff --git a/system/helpers/form_helper.php b/system/helpers/form_helper.php index eb97913f1..3fd361041 100644 --- a/system/helpers/form_helper.php +++ b/system/helpers/form_helper.php @@ -40,9 +40,9 @@ */ function form_open($action = '', $attributes = array(), $hidden = array()) { - $obj =& get_instance(); + $CI =& get_instance(); - $form = 'config->site_url($action).'"'; if ( ! isset($attributes['method'])) { diff --git a/system/helpers/security_helper.php b/system/helpers/security_helper.php index f14ba72a0..347cab427 100644 --- a/system/helpers/security_helper.php +++ b/system/helpers/security_helper.php @@ -37,8 +37,8 @@ */ function xss_clean($str, $charset = 'ISO-8859-1') { - $obj =& get_instance(); - return $obj->input->xss_clean($str, $charset); + $CI =& get_instance(); + return $CI->input->xss_clean($str, $charset); } // -------------------------------------------------------------------- diff --git a/system/helpers/url_helper.php b/system/helpers/url_helper.php index 6e2f7f452..2f93bcfbf 100644 --- a/system/helpers/url_helper.php +++ b/system/helpers/url_helper.php @@ -39,8 +39,8 @@ */ function site_url($uri = '') { - $obj =& get_instance(); - return $obj->config->site_url($uri); + $CI =& get_instance(); + return $CI->config->site_url($uri); } // ------------------------------------------------------------------------ @@ -55,8 +55,8 @@ function site_url($uri = '') */ function base_url() { - $obj =& get_instance(); - return $obj->config->slash_item('base_url'); + $CI =& get_instance(); + return $CI->config->slash_item('base_url'); } // ------------------------------------------------------------------------ @@ -71,8 +71,8 @@ function base_url() */ function index_page() { - $obj =& get_instance(); - return $obj->config->item('index_page'); + $CI =& get_instance(); + return $CI->config->item('index_page'); } // ------------------------------------------------------------------------ -- cgit v1.2.3-24-g4f1b From dee8ba233621af79fbf9b529b37a845734843fb8 Mon Sep 17 00:00:00 2001 From: admin Date: Sat, 7 Oct 2006 03:20:32 +0000 Subject: --- system/database/DB_cache.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'system') diff --git a/system/database/DB_cache.php b/system/database/DB_cache.php index 081b56584..86493e77c 100644 --- a/system/database/DB_cache.php +++ b/system/database/DB_cache.php @@ -97,7 +97,7 @@ class CI_DB_Cache { return $this->CI->db->cache_off(); } - $uri = ($this->CI->uri->segment(1) == FALSE) ? 'default.' : $this->CI->uri->segment(1).'.'; + $uri = ($this->CI->uri->segment(1) == FALSE) ? 'default.' : $this->CI->uri->segment(1).'+'; $uri .= ($this->CI->uri->segment(2) == FALSE) ? 'index' : $this->CI->uri->segment(2); $filepath = $uri.'/'.md5($sql); @@ -125,7 +125,7 @@ class CI_DB_Cache { return $this->CI->db->cache_off(); } - $uri = ($this->CI->uri->segment(1) == FALSE) ? 'default.' : $this->CI->uri->segment(1).'.'; + $uri = ($this->CI->uri->segment(1) == FALSE) ? 'default.' : $this->CI->uri->segment(1).'+'; $uri .= ($this->CI->uri->segment(2) == FALSE) ? 'index' : $this->CI->uri->segment(2); $dir_path = $this->CI->db->cachedir.$uri.'/'; @@ -171,7 +171,7 @@ class CI_DB_Cache { $segment_two = ($this->CI->uri->segment(2) == FALSE) ? 'index' : $this->CI->uri->segment(2); } - $dir_path = $this->CI->db->cachedir.md5($segment_one.'.'.$segment_two).'/'; + $dir_path = $this->CI->db->cachedir.md5($segment_one.'+'.$segment_two).'/'; delete_files($dir_path, TRUE); } -- cgit v1.2.3-24-g4f1b From 69af5bd5d457468e0b2875c47d06830496679a8f Mon Sep 17 00:00:00 2001 From: admin Date: Sat, 7 Oct 2006 03:22:46 +0000 Subject: --- system/database/DB_utility.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'system') diff --git a/system/database/DB_utility.php b/system/database/DB_utility.php index 64d67db41..c2c5f1fe0 100644 --- a/system/database/DB_utility.php +++ b/system/database/DB_utility.php @@ -290,10 +290,10 @@ class CI_DB_utility { $CI->load->helper('xml'); // Generate the result - $xml = "<{$root}/>".$newline; + $xml = "<{$root}>".$newline; foreach ($query->result_array() as $row) { - $xml .= $tab."<{$element}/>".$newline; + $xml .= $tab."<{$element}>".$newline; foreach ($row as $key => $val) { -- cgit v1.2.3-24-g4f1b From df752b2448b597e6af1adb79d20681be9bad1a8e Mon Sep 17 00:00:00 2001 From: admin Date: Sun, 8 Oct 2006 07:17:13 +0000 Subject: --- system/libraries/User_agent.php | 645 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 645 insertions(+) create mode 100644 system/libraries/User_agent.php (limited to 'system') diff --git a/system/libraries/User_agent.php b/system/libraries/User_agent.php new file mode 100644 index 000000000..33e8451c6 --- /dev/null +++ b/system/libraries/User_agent.php @@ -0,0 +1,645 @@ + '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', + 'mac os x' => 'Mac OS X', + 'freebsd' => 'FreeBSD', + 'ppc' => 'Macintosh', + 'sunos' => 'Sun Solaris', + 'linux' => 'Linux', + 'debian' => 'Debian', + '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' + ); + + var $browsers = array( + 'Opera' => 'Opera', + 'MSIE' => 'Internet Explorer', + 'Internet Explorer' => 'Internet Explorer', + 'Shiira' => 'Shiira', + 'Firefox' => 'Firefox', + 'Camino' => 'Camino', + 'Mozilla' => 'Mozilla', + 'Safari' => 'Safari', + 'Konqueror' => 'Konqueror', + 'Lynx' => 'Lynx', + 'ANTFresco' => 'Fresco' + ); + + var $mobiles = array( + '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' + ); + + var $robots = array( + + 'googlebot' => 'Googlebot', + 'msnbot' => 'MSNBot', + 'slurp' => 'Inktomi Slurp', + 'yahoo' => 'Yahoo', + 'askjeeves' => 'AskJeeves', + 'fastcrawler' => 'FastCrawler', + 'infoseek' => 'InfoSeek Robot 1.0', + 'lycos' => 'Lycos', + 'abcdatos' => 'ABCdatos BotLink', + 'Acme.Spider' => 'Acme.Spider', + 'ahoythehomepagefinder' => 'Ahoy! The Homepage Finder', + 'Alkaline' => 'Alkaline', + 'anthill' => 'Anthill', + 'appie' => 'Walhello appie', + 'arachnophilia' => 'Arachnophilia', + 'arale' => 'Arale', + 'araneo' => 'Araneo', + 'araybot' => 'AraybOt', + 'architext' => 'ArchitextSpider', + 'aretha' => 'Aretha', + 'ariadne' => 'ARIADNE', + 'arks' => 'arks', + 'aspider' => 'ASpider (Associative Spider)', + 'atn.txt' => 'ATN Worldwide', + 'atomz' => 'Atomz.com Search Robot', + 'auresys' => 'AURESYS', + 'backrub' => 'BackRub', + 'bbot' => 'BBot', + 'bigbrother' => 'Big Brother', + 'bjaaland' => 'Bjaaland', + 'blackwidow' => 'BlackWidow', + 'blindekuh' => 'Die Blinde Kuh', + 'Bloodhound' => 'Bloodhound', + 'borg-bot' => 'Borg-Bot', + 'boxseabot' => 'BoxSeaBot', + 'brightnet' => 'bright.net caching robot', + 'bspider' => 'BSpider', + 'cactvschemistryspider' => 'CACTVS Chemistry Spider', + 'calif' => 'Calif', + 'cassandra' => 'Cassandra', + 'cgireader' => 'Digimarc Marcspider/CGI', + 'checkbot' => 'Checkbot', + 'christcrawler' => 'ChristCrawler.com', + 'churl' => 'churl', + 'cienciaficcion' => 'cIeNcIaFiCcIoN.nEt', + 'cmc' => 'CMC/0.01', + 'Collective' => 'Collective', + 'combine' => 'Combine System', + 'confuzzledbot' => 'ConfuzzledBot', + 'coolbot' => 'CoolBot', + 'core' => 'Web Core / Roots', + 'cosmos' => 'XYLEME Robot', + 'cruiser' => 'Internet Cruiser Robot', + 'cusco' => 'Cusco', + 'cyberspyder' => 'CyberSpyder Link Test', + 'cydralspider' => 'CydralSpider', + 'desertrealm' => 'Desert Realm Spider', + 'deweb' => 'DeWeb(c) Katalog/Index', + 'dienstspider' => 'DienstSpider', + 'digger' => 'Digger', + 'diibot' => 'Digital Integrity Robot', + 'directhit' => 'Direct Hit Grabber', + 'dnabot' => 'DNAbot', + 'download_express' => 'DownLoad Express', + 'dragonbot' => 'DragonBot', + 'e-collector' => 'e-collector', + 'ebiness' => 'EbiNess', + 'eit' => 'EIT Link Verifier Robot', + 'elfinbot' => 'ELFINBOT', + 'emacs' => 'Emacs-w3 Search Engine', + 'emcspider' => 'ananzi', + 'esculapio' => 'esculapio', + 'esther' => 'Esther', + 'evliyacelebi' => 'Evliya Celebi', + 'nzexplorer' => 'nzexplorer', + 'fdse' => 'Fluid Dynamics Search Engine robot', + 'felix' => 'Felix IDE', + 'ferret' => 'Wild Ferret Web Hopper #1, #2, #3', + 'fetchrover' => 'FetchRover', + 'fido' => 'fido', + 'finnish' => 'Hämähäkki', + 'fireball' => 'KIT-Fireball', + 'fish' => 'Fish search', + 'fouineur' => 'Fouineur', + 'francoroute' => 'Robot Francoroute', + 'freecrawl' => 'Freecrawl', + 'funnelweb' => 'FunnelWeb', + 'gama' => 'gammaSpider, FocusedCrawler', + 'gazz' => 'gazz', + 'gcreep' => 'GCreep', + 'getbot' => 'GetBot', + 'geturl' => 'GetURL', + 'golem' => 'Golem', + 'grapnel' => 'Grapnel/0.01 Experiment', + 'griffon' => 'Griffon ', + 'gromit' => 'Gromit', + 'gulliver' => 'Northern Light Gulliver', + 'gulperbot' => 'Gulper Bot', + 'hambot' => 'HamBot', + 'harvest' => 'Harvest', + 'havindex' => 'havIndex', + 'hi' => 'HI (HTML Index) Search', + 'hometown' => 'Hometown Spider Pro', + 'wired-digital' => 'Wired Digital', + 'htdig' => 'ht://Dig', + 'htmlgobble' => 'HTMLgobble', + 'hyperdecontextualizer' => 'Hyper-Decontextualizer', + 'iajabot' => 'iajaBot', + 'ibm' => 'IBM_Planetwide', + 'iconoclast' => 'Popular Iconoclast', + 'Ilse' => 'Ingrid', + 'imagelock' => 'Imagelock ', + 'incywincy' => 'IncyWincy', + 'informant' => 'Informant', + 'infoseeksidewinder' => 'Infoseek Sidewinder', + 'infospider' => 'InfoSpiders', + 'inspectorwww' => 'Inspector Web', + 'intelliagent' => 'IntelliAgent', + 'irobot' => 'I, Robot', + 'iron33' => 'Iron33', + 'israelisearch' => 'Israeli-search', + 'javabee' => 'JavaBee', + 'JBot' => 'JBot Java Web Robot', + 'jcrawler' => 'JCrawler', + 'jobo' => 'JoBo Java Web Robot', + 'jobot' => 'Jobot', + 'joebot' => 'JoeBot', + 'jubii' => 'The Jubii Indexing Robot', + 'jumpstation' => 'JumpStation', + 'kapsi' => 'image.kapsi.net', + 'katipo' => 'Katipo', + 'kdd' => 'KDD-Explorer', + 'kilroy' => 'Kilroy', + 'ko_yappo_robot' => 'KO_Yappo_Robot', + 'labelgrabber.txt' => 'LabelGrabber', + 'larbin' => 'larbin', + 'legs' => 'legs', + 'linkidator' => 'Link Validator', + 'linkscan' => 'LinkScan', + 'linkwalker' => 'LinkWalker', + 'lockon' => 'Lockon', + 'logo_gif' => 'logo.gif Crawler', + 'magpie' => 'Magpie', + 'marvin' => 'marvin/infoseek', + 'mattie' => 'Mattie', + 'mediafox' => 'MediaFox', + 'merzscope' => 'MerzScope', + 'meshexplorer' => 'NEC-MeshExplorer', + 'MindCrawler' => 'MindCrawler', + 'mnogosearch' => 'mnoGoSearch search engine software', + 'moget' => 'moget', + 'momspider' => 'MOMspider', + 'monster' => 'Monster', + 'motor' => 'Motor', + 'muncher' => 'Muncher', + 'muninn' => 'Muninn', + 'muscatferret' => 'Muscat Ferret', + 'mwdsearch' => 'Mwd.Search', + 'myweb' => 'Internet Shinchakubin', + 'NDSpider' => 'NDSpider', + 'netcarta' => 'NetCarta WebMap Engine', + 'netmechanic' => 'NetMechanic', + 'netscoop' => 'NetScoop', + 'newscan-online' => 'newscan-online', + 'nhse' => 'NHSE Web Forager', + 'nomad' => 'Nomad', + 'northstar' => 'The NorthStar Robot', + 'objectssearch' => 'ObjectsSearch', + 'occam' => 'Occam', + 'octopus' => 'HKU WWW Octopus', + 'OntoSpider' => 'OntoSpider', + 'openfind' => 'Openfind data gatherer', + 'orb_search' => 'Orb Search', + 'packrat' => 'Pack Rat', + 'pageboy' => 'PageBoy', + 'parasite' => 'ParaSite', + 'patric' => 'Patric', + 'pegasus' => 'pegasus', + 'perignator' => 'The Peregrinator', + 'perlcrawler' => 'PerlCrawler 1.0', + 'phantom' => 'Phantom', + 'phpdig' => 'PhpDig', + 'pitkow' => 'html_analyzer', + 'pjspider' => 'Portal Juice Spider', + 'pka' => 'PGP Key Agent', + 'poppi' => 'Poppi', + 'portalb' => 'PortalB Spider', + 'psbot' => 'psbot', + 'Puu' => 'GetterroboPlus Puu', + 'python' => 'The Python Robot', + 'raven ' => 'Raven Search', + 'rbse' => 'RBSE Spider', + 'resumerobot' => 'Resume Robot', + 'rhcs' => 'RoadHouse Crawling System', + 'rixbot' => 'RixBot', + 'roadrunner' => 'Road Runner: The ImageScape Robot', + 'robbie' => 'Robbie the Robot', + 'robi' => 'ComputingSite Robi/1.0', + 'robocrawl' => 'RoboCrawl Spider', + 'robofox' => 'RoboFox', + 'robozilla' => 'Robozilla', + 'roverbot' => 'Roverbot', + 'rules' => 'RuLeS', + 'safetynetrobot' => 'SafetyNet Robot', + 'scooter' => 'Scooter', + 'search_au' => 'Search.Aus-AU.COM', + 'search-info' => 'Sleek', + 'searchprocess' => 'SearchProcess', + 'senrigan' => 'Senrigan', + 'sgscout' => 'SG-Scout', + 'shaggy' => 'ShagSeeker', + 'sift' => 'Sift', + 'simbot' => 'Simmany Robot Ver1.0', + 'site-valet' => 'Site Valet', + 'sitetech' => 'SiteTech-Rover', + 'skymob' => 'Skymob.com', + 'slcrawler' => 'SLCrawler', + 'smartspider' => 'Smart Spider', + 'snooper' => 'Snooper', + 'solbot' => 'Solbot', + 'speedy' => 'Speedy Spider', + 'spider_monkey' => 'spider_monkey', + 'spiderbot' => 'SpiderBot', + 'spiderline' => 'Spiderline Crawler', + 'spiderman' => 'SpiderMan', + 'spiderview' => 'SpiderView(tm)', + 'spry' => 'Spry Wizard Robot', + 'ssearcher' => 'Site Searcher', + 'suke' => 'Suke', + 'suntek' => 'suntek search engine', + 'sven' => 'Sven', + 'sygol' => 'Sygol ', + 'tach_bw' => 'TACH Black Widow', + 'tarantula' => 'Tarantula', + 'tarspider' => 'tarspider', + 'tcl' => 'Tcl W3 Robot', + 'techbot' => 'TechBOT', + 'templeton' => 'Templeton', + 'titin' => 'TitIn', + 'titan' => 'TITAN', + 'tkwww' => 'The TkWWW Robot', + 'tlspider' => 'TLSpider', + 'ucsd' => 'UCSD Crawl', + 'udmsearch' => 'UdmSearch', + 'ultraseek' => 'Ultraseek', + 'uptimebot' => 'UptimeBot', + 'urlck' => 'URL Check', + 'valkyrie' => 'Valkyrie', + 'verticrawl' => 'Verticrawl', + 'victoria' => 'Victoria', + 'visionsearch' => 'vision-search', + 'voidbot' => 'void-bot', + 'voyager' => 'Voyager', + 'vwbot' => 'VWbot', + 'w3index' => 'The NWI Robot', + 'w3m2' => 'W3M2', + 'wallpaper' => 'WallPaper (alias crawlpaper)', + 'wanderer' => 'the World Wide Web Wanderer', + 'wapspider' => 'w@pSpider by wap4.com', + 'webbandit' => 'WebBandit Web Spider', + 'webcatcher' => 'WebCatcher', + 'webcopy' => 'WebCopy', + 'webfetcher' => 'webfetcher', + 'webfoot' => 'The Webfoot Robot', + 'webinator' => 'Webinator', + 'weblayers' => 'weblayers', + 'weblinker' => 'WebLinker', + 'webmirror' => 'WebMirror', + 'webmoose' => 'The Web Moose', + 'webquest' => 'WebQuest', + 'webreader' => 'Digimarc MarcSpider', + 'webreaper' => 'WebReaper', + 'webs' => 'webs', + 'websnarf' => 'Websnarf', + 'webspider' => 'WebSpider', + 'webvac' => 'WebVac', + 'webwalk' => 'webwalk', + 'webwalker' => 'WebWalker', + 'webwatch' => 'WebWatch', + 'wget' => 'Wget', + 'whatuseek' => 'whatUseek Winona', + 'whowhere' => 'WhoWhere Robot', + 'wlm' => 'Weblog Monitor', + 'wmir' => 'w3mir', + 'wolp' => 'WebStolperer', + 'wombat' => 'The Web Wombat ', + 'worm' => 'The World Wide Web Worm', + 'wwwc' => 'WWWC Ver 0.2.5', + 'wz101' => 'WebZinger', + 'xget' => 'XGET', + ); + + + + /** + * Constructor + * + * Sets the User Agent and runs the compilation routine + * + * @access public + * @return void + */ + function CI_User_agent() + { + if (isset($_SERVER['HTTP_USER_AGENT'])) + { + $this->agent = trim($_SERVER['HTTP_USER_AGENT']); + } + + if ( ! is_null($this->agent)) + { + $this->_compile_data(); + } + } + + // -------------------------------------------------------------------- + + /** + * Compile the User Agent Data + * + * @access private + * @return bool + */ + function _compile_data() + { + $this->_set_platform(); + + foreach (array('_set_browser', '_set_robot', '_set_mobile') as $function) + { + if ($this->$function() === TRUE) + { + break; + } + } + } + + // -------------------------------------------------------------------- + + /** + * Set the Platform + * + * @access private + * @return mixed + */ + function _set_platform() + { + foreach ($this->platforms as $key => $val) + { + if (preg_match("|$key|i", $this->agent)) + { + $this->platform = $val; + return TRUE; + } + } + + $this->platform = 'Unknown Platform'; + } + + // -------------------------------------------------------------------- + + /** + * Set the Browser + * + * @access private + * @return bool + */ + function _set_browser() + { + foreach ($this->browsers as $key => $val) + { + if (preg_match("|".$key.".*?([0-9\.]+)|i", $this->agent, $match)) + { + $this->is_browser = TRUE; + $this->version = $match[1]; + $this->browser = $val; + return TRUE; + } + } + + return FALSE; + } + + // -------------------------------------------------------------------- + + /** + * Set the Robot + * + * @access private + * @return bool + */ + function _set_robot() + { + foreach ($this->robots as $key => $val) + { + if (preg_match("|$key|i", $this->agent)) + { + $this->is_robot = TRUE; + $this->robot = $val; + return TRUE; + } + } + + return FALSE; + } + + // -------------------------------------------------------------------- + + /** + * Set the Mobile Devise + * + * @access private + * @return bool + */ + function _set_mobile() + { + foreach ($this->mobiles as $key => $val) + { + if (FALSE !== (strpos(strtolower($this->agent), $key))) + { + $this->is_mobile = TRUE; + $this->mobile = $val; + return TRUE; + } + } + + return FALSE; + } + + + // -------------------------------------------------------------------- + + /** + * Is Browser + * + * @access public + * @return bool + */ + function is_browser() + { + return $this->is_browser; + } + + // -------------------------------------------------------------------- + + /** + * Is Robot + * + * @access public + * @return bool + */ + function is_robot() + { + return $this->is_robot; + } + + // -------------------------------------------------------------------- + + /** + * Is Mobile + * + * @access public + * @return bool + */ + function is_mobile() + { + return $this->is_mobile; + } + + // -------------------------------------------------------------------- + + /** + * Get Platform + * + * @access public + * @return string + */ + function get_platform() + { + return $this->platform; + } + + // -------------------------------------------------------------------- + + /** + * Get Browser Name + * + * @access public + * @return string + */ + function get_browser() + { + return $this->browser; + } + + // -------------------------------------------------------------------- + + /** + * Get the Browser Version + * + * @access public + * @return string + */ + function get_version() + { + return $this->version; + } + + // -------------------------------------------------------------------- + + /** + * Get The Robot Name + * + * @access public + * @return string + */ + function get_robot() + { + return $this->robot; + } + // -------------------------------------------------------------------- + + /** + * Get the Mobile Devise + * + * @access public + * @return string + */ + function get_mobile() + { + return $this->mobile; + } + + +} + +?> \ No newline at end of file -- cgit v1.2.3-24-g4f1b From 10c3f41cbe5bd3bb66fd106cc9fb171ffcc7364b Mon Sep 17 00:00:00 2001 From: admin Date: Sun, 8 Oct 2006 07:21:12 +0000 Subject: --- system/application/config/database.php | 2 +- system/application/config/routes.php | 4 +-- system/database/DB_result.php | 2 +- system/libraries/Calendar.php | 11 ++---- system/libraries/Encrypt.php | 32 ++++++++++++----- system/libraries/Image_lib.php | 1 + system/libraries/Input.php | 64 ++++++++++++++++++++++++++-------- system/libraries/Loader.php | 45 ++++++++++-------------- system/libraries/Log.php | 3 +- system/libraries/Pagination.php | 21 ++++++----- system/libraries/Router.php | 4 +-- system/libraries/Unit.php | 2 +- system/libraries/Upload.php | 30 ++++++++-------- system/libraries/Validation.php | 14 ++++++++ system/libraries/Zip.php | 3 +- 15 files changed, 145 insertions(+), 93 deletions(-) (limited to 'system') diff --git a/system/application/config/database.php b/system/application/config/database.php index b03cb3ab3..de781646c 100644 --- a/system/application/config/database.php +++ b/system/application/config/database.php @@ -38,7 +38,7 @@ $db['default']['database'] = "test"; $db['default']['dbdriver'] = "mysql"; $db['default']['dbprefix'] = ""; $db['default']['active_r'] = TRUE; -$db['default']['pconnect'] = FALSE; +$db['default']['pconnect'] = TRUE; $db['default']['db_debug'] = TRUE; $db['default']['cache_on'] = TRUE; $db['default']['cachedir'] = APPPATH.'db_cache/'; diff --git a/system/application/config/routes.php b/system/application/config/routes.php index 468ff0ab5..097037e31 100644 --- a/system/application/config/routes.php +++ b/system/application/config/routes.php @@ -40,9 +40,7 @@ */ $route['default_controller'] = "welcome"; -$route['scaffolding_trigger'] = ""; - -// Define your own routes below ------------------------------------------- +$route['scaffolding_trigger'] = "scaffolding"; diff --git a/system/database/DB_result.php b/system/database/DB_result.php index 76b7b9e9c..1c8ad6be0 100644 --- a/system/database/DB_result.php +++ b/system/database/DB_result.php @@ -256,7 +256,7 @@ class CI_DB_result { * 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 database resource IDs with + * operational due to the unavailability of the database resource IDs with * cached results. */ function num_rows() { return $this->num_rows; } diff --git a/system/libraries/Calendar.php b/system/libraries/Calendar.php index 3cbbbfe6d..23a6bf791 100644 --- a/system/libraries/Calendar.php +++ b/system/libraries/Calendar.php @@ -48,6 +48,7 @@ class CI_Calendar { function CI_Calendar() { $this->CI =& get_instance(); + if ( ! in_array('calendar_lang'.EXT, $this->CI->lang->is_loaded, TRUE)) { $this->CI->lang->load('calendar'); @@ -56,7 +57,6 @@ class CI_Calendar { $this->local_time = time(); log_message('debug', "Calendar Class Initialized"); } - // END CI_Calendar() // -------------------------------------------------------------------- @@ -79,7 +79,6 @@ class CI_Calendar { } } } - // END initialize() // -------------------------------------------------------------------- @@ -241,7 +240,6 @@ class CI_Calendar { return $out; } - // END generate() // -------------------------------------------------------------------- @@ -275,7 +273,6 @@ class CI_Calendar { return $this->CI->lang->line($month); } - // END get_month_name() // -------------------------------------------------------------------- @@ -315,7 +312,6 @@ class CI_Calendar { return $days; } - // END get_day_names() // -------------------------------------------------------------------- @@ -357,7 +353,6 @@ class CI_Calendar { return $date; } - // END adjust_date() // -------------------------------------------------------------------- @@ -378,6 +373,7 @@ class CI_Calendar { return 0; } + // Is the year a leap year? if ($month == 2) { if ($year % 400 == 0 OR ($year % 4 == 0 AND $year % 100 != 0)) @@ -388,7 +384,6 @@ class CI_Calendar { return $days_in_month[$month - 1]; } - // END get_total_days() // -------------------------------------------------------------------- @@ -426,7 +421,6 @@ class CI_Calendar { 'table_close' => '
' ); } - // END default_template() // -------------------------------------------------------------------- @@ -465,7 +459,6 @@ class CI_Calendar { } } } - // END parse_template() } diff --git a/system/libraries/Encrypt.php b/system/libraries/Encrypt.php index 2a1de6f37..50b3fab39 100644 --- a/system/libraries/Encrypt.php +++ b/system/libraries/Encrypt.php @@ -27,6 +27,7 @@ * @link http://www.codeigniter.com/user_guide/libraries/encryption.html */ class CI_Encrypt { + var $encryption_key = ''; var $_hash_type = 'sha1'; var $_mcrypt_exists = FALSE; @@ -246,10 +247,9 @@ class CI_Encrypt { */ function mcrypt_encode($data, $key) { - $this->_get_mcrypt(); - $init_size = mcrypt_get_iv_size($this->_mcrypt_cipher, $this->_mcrypt_mode); + $init_size = mcrypt_get_iv_size($this->_get_cipher(), $this->_get_mode()); $init_vect = mcrypt_create_iv($init_size, MCRYPT_RAND); - return mcrypt_encrypt($this->_mcrypt_cipher, $key, $data, $this->_mcrypt_mode, $init_vect); + return mcrypt_encrypt($this->_get_cipher(), $key, $data, $this->_get_mode(), $init_vect); } // -------------------------------------------------------------------- @@ -264,10 +264,9 @@ class CI_Encrypt { */ function mcrypt_decode($data, $key) { - $this->_get_mcrypt(); - $init_size = mcrypt_get_iv_size($this->_mcrypt_cipher, $this->_mcrypt_mode); + $init_size = mcrypt_get_iv_size($this->_get_cipher(), $this->_get_mode()); $init_vect = mcrypt_create_iv($init_size, MCRYPT_RAND); - return rtrim(mcrypt_decrypt($this->_mcrypt_cipher, $key, $data, $this->_mcrypt_mode, $init_vect), "\0"); + return rtrim(mcrypt_decrypt($this->_get_cipher(), $key, $data, $this->_get_mode(), $init_vect), "\0"); } // -------------------------------------------------------------------- @@ -301,22 +300,37 @@ class CI_Encrypt { // -------------------------------------------------------------------- /** - * Get Mcrypt value + * Get Mcrypt Cypher Value * * @access private - * @param string * @return string */ - function _get_mcrypt() + function _get_cypher() { if ($this->_mcrypt_cipher == '') { $this->_mcrypt_cipher = MCRYPT_RIJNDAEL_256; } + + return $this->_mcrypt_cipher; + } + + // -------------------------------------------------------------------- + + /** + * Get Mcrypt MOde Value + * + * @access private + * @return string + */ + function _get_mode() + { if ($this->_mcrypt_mode == '') { $this->_mcrypt_mode = MCRYPT_MODE_ECB; } + + return $this->_mcrypt_mode; } // -------------------------------------------------------------------- diff --git a/system/libraries/Image_lib.php b/system/libraries/Image_lib.php index 79b2f9c1c..16583c063 100644 --- a/system/libraries/Image_lib.php +++ b/system/libraries/Image_lib.php @@ -148,6 +148,7 @@ class CI_Image_lib { $this->set_error('imglib_source_image_required'); return FALSE; } + /* * Is getimagesize() Available? * diff --git a/system/libraries/Input.php b/system/libraries/Input.php index 98c2cbd55..0d3c87b49 100644 --- a/system/libraries/Input.php +++ b/system/libraries/Input.php @@ -179,6 +179,7 @@ class CI_Input { * * @access public * @param string + * @param bool * @return string */ function post($index = '', $xss_clean = FALSE) @@ -213,6 +214,7 @@ class CI_Input { * * @access public * @param string + * @param bool * @return string */ function cookie($index = '', $xss_clean = FALSE) @@ -244,6 +246,31 @@ class CI_Input { return $_COOKIE[$index]; } } + + // -------------------------------------------------------------------- + + /** + * Fetch an item from the SERVER array + * + * @access public + * @param string + * @param bool + * @return string + */ + function server($index = '', $xss_clean = FALSE) + { + if ( ! isset($_SERVER[$index])) + { + return FALSE; + } + + if ($xss_clean === TRUE) + { + return $this->xss_clean($_SERVER[$index]); + } + + return $_SERVER[$index]; + } // -------------------------------------------------------------------- @@ -259,15 +286,28 @@ class CI_Input { { return $this->ip_address; } - - $cip = (isset($_SERVER['HTTP_CLIENT_IP']) AND $_SERVER['HTTP_CLIENT_IP'] != "") ? $_SERVER['HTTP_CLIENT_IP'] : FALSE; - $rip = (isset($_SERVER['REMOTE_ADDR']) AND $_SERVER['REMOTE_ADDR'] != "") ? $_SERVER['REMOTE_ADDR'] : FALSE; - $fip = (isset($_SERVER['HTTP_X_FORWARDED_FOR']) AND $_SERVER['HTTP_X_FORWARDED_FOR'] != "") ? $_SERVER['HTTP_X_FORWARDED_FOR'] : FALSE; - - if ($cip && $rip) $this->ip_address = $cip; - elseif ($rip) $this->ip_address = $rip; - elseif ($cip) $this->ip_address = $cip; - elseif ($fip) $this->ip_address = $fip; + + if ($this->server('REMOTE_ADDR') AND $this->server('HTTP_CLIENT_IP')) + { + $this->ip_address = $_SERVER['HTTP_CLIENT_IP']; + } + elseif ($this->server('REMOTE_ADDR')) + { + $this->ip_address = $_SERVER['REMOTE_ADDR']; + } + elseif ($this->server('HTTP_CLIENT_IP')) + { + $this->ip_address = $_SERVER['HTTP_CLIENT_IP']; + } + elseif ($this->server('HTTP_X_FORWARDED_FOR')) + { + $this->ip_address = $_SERVER['HTTP_X_FORWARDED_FOR']; + } + + if ($this->ip_address === FALSE) + { + return $this->ip_address = '0.0.0.0'; + } if (strstr($this->ip_address, ',')) { @@ -279,11 +319,7 @@ class CI_Input { { $this->ip_address = '0.0.0.0'; } - - unset($cip); - unset($rip); - unset($fip); - + return $this->ip_address; } diff --git a/system/libraries/Loader.php b/system/libraries/Loader.php index 90dc0f140..05ee93959 100644 --- a/system/libraries/Loader.php +++ b/system/libraries/Loader.php @@ -611,16 +611,7 @@ class CI_Loader { if (substr($class, 0, 3) == 'my_') { $class = preg_replace("/my_(.+)/", "\\1", $class); - $extend = TRUE; - } - else - { - $extend = FALSE; - } - - // Are we extending one of the base classes? - if ($extend == TRUE) - { + // Load the requested library from the main system/libraries folder if (file_exists(BASEPATH.'libraries/'.ucfirst($class).EXT)) { @@ -638,22 +629,20 @@ class CI_Loader { return $this->_ci_init_class($filename, 'MY_', $params); } - else - { - // Lets search for the requested library file and load it. - // For backward compatibility we'll test for filenames that are - // both uppercase and lower. - foreach (array(ucfirst($class), $class) as $filename) + + // Lets search for the requested library file and load it. + // For backward compatibility we'll test for filenames that are + // both uppercase and lower. + foreach (array(ucfirst($class), $class) as $filename) + { + for ($i = 1; $i < 3; $i++) { - for ($i = 1; $i < 3; $i++) + $path = ($i % 2) ? APPPATH : BASEPATH; + + if (file_exists($path.'libraries/'.$filename.EXT)) { - $path = ($i % 2) ? APPPATH : BASEPATH; - - if (file_exists($path.'libraries/'.$filename.EXT)) - { - include_once($path.'libraries/'.$filename.EXT); - return $this->_ci_init_class($filename, '', $params); - } + include_once($path.'libraries/'.$filename.EXT); + return $this->_ci_init_class($filename, '', $params); } } } @@ -686,7 +675,7 @@ class CI_Loader { if ($prefix == '') { - $name = ( ! class_exists($class)) ? 'CI_'.$class : $class; + $name = (class_exists('CI_'.$class)) ? 'CI_'.$class : $class; } else { @@ -756,24 +745,28 @@ class CI_Loader { // 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 the model class. if (in_array('model', $autoload['libraries'])) { $this->model(); $autoload['libraries'] = array_diff($autoload['libraries'], array('model')); } - + + // Load scaffolding if (in_array('scaffolding', $autoload['libraries'])) { $this->scaffolding(); $autoload['libraries'] = array_diff($autoload['libraries'], array('scaffolding')); } + // Load all other libraries foreach ($autoload['libraries'] as $item) { $this->library($item); diff --git a/system/libraries/Log.php b/system/libraries/Log.php index 392742584..eff7cb7fc 100644 --- a/system/libraries/Log.php +++ b/system/libraries/Log.php @@ -61,7 +61,6 @@ class CI_Log { $this->_date_fmt = $config['log_date_format']; } } - // END CI_Log() // -------------------------------------------------------------------- @@ -113,7 +112,7 @@ class CI_Log { @chmod($filepath, 0666); return TRUE; } - // END write_log() + } // END Log Class ?> \ No newline at end of file diff --git a/system/libraries/Pagination.php b/system/libraries/Pagination.php index efbe6c27f..b29571eee 100644 --- a/system/libraries/Pagination.php +++ b/system/libraries/Pagination.php @@ -105,16 +105,21 @@ class CI_Pagination { { return ''; } - + // Calculate the total number of pages - $num_pages = intval($this->total_rows / $this->per_page); + $num_pages = ceil($this->total_rows / $this->per_page); + + /* + // Calculate the total number of pages + $num_pages = intval($this->total_rows / $this->per_page); + + // Use modulus to see if our division has a remainder. If so, add one to our page number. + if ($this->total_rows % $this->per_page) + { + $num_pages++; + } + */ - // Use modulus to see if our division has a remainder.If so, add one to our page number. - if ($this->total_rows % $this->per_page) - { - $num_pages++; - } - // Is there only one page? Hm... nothing more to do here then. if ($num_pages == 1) { diff --git a/system/libraries/Router.php b/system/libraries/Router.php index 7a4fd3899..27e3c27cc 100644 --- a/system/libraries/Router.php +++ b/system/libraries/Router.php @@ -66,7 +66,6 @@ class CI_Router { */ function _set_route_mapping() { - // Are query strings enabled in the config file? // If so, we're done since segment based URIs are not used with query strings. if ($this->config->item('enable_query_strings') === TRUE AND isset($_GET[$this->config->item('controller_trigger')])) @@ -120,8 +119,7 @@ class CI_Router { { $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. foreach(explode("/", preg_replace("|/*(.+?)/*$|", "\\1", $this->uri_string)) as $val) diff --git a/system/libraries/Unit.php b/system/libraries/Unit.php index 6573f4269..439424fbb 100644 --- a/system/libraries/Unit.php +++ b/system/libraries/Unit.php @@ -55,7 +55,7 @@ class CI_Unit { function run($test, $expected = TRUE, $test_name = 'undefined') { if ($this->active == FALSE) - return; + return FALSE; if (in_array($expected, array('is_string', 'is_bool', 'is_true', 'is_false', 'is_int', 'is_numeric', 'is_float', 'is_double', 'is_array', 'is_null'), TRUE)) { diff --git a/system/libraries/Upload.php b/system/libraries/Upload.php index 13fa8acdf..5bb506cdb 100644 --- a/system/libraries/Upload.php +++ b/system/libraries/Upload.php @@ -248,20 +248,20 @@ class CI_Upload { function data() { return array ( - 'file_name' => $this->file_name, - 'file_type' => $this->file_type, - 'file_path' => $this->file_path, - 'full_path' => $this->file_path.$this->file_name, - 'raw_name' => str_replace($this->file_ext, '', $this->file_name), - 'orig_name' => $this->orig_name, - 'file_ext' => $this->file_ext, - 'file_size' => $this->file_size, - 'is_image' => $this->is_image(), - 'image_width' => $this->image_width, - 'image_height' => $this->image_height, - 'image_type' => $this->image_type, - 'image_size_str' => $this->image_size_str, - ); + 'file_name' => $this->file_name, + 'file_type' => $this->file_type, + 'file_path' => $this->file_path, + 'full_path' => $this->file_path.$this->file_name, + 'raw_name' => str_replace($this->file_ext, '', $this->file_name), + 'orig_name' => $this->orig_name, + 'file_ext' => $this->file_ext, + 'file_size' => $this->file_size, + 'is_image' => $this->is_image(), + 'image_width' => $this->image_width, + 'image_height' => $this->image_height, + 'image_type' => $this->image_type, + 'image_size_str' => $this->image_size_str, + ); } // -------------------------------------------------------------------- @@ -554,7 +554,7 @@ class CI_Upload { // -------------------------------------------------------------------- /** - * VAlidate Upload Path + * Validate Upload Path * * Verifies that it is a valid upload path with proper permissions. * diff --git a/system/libraries/Validation.php b/system/libraries/Validation.php index 5322be0e9..07ca35a33 100644 --- a/system/libraries/Validation.php +++ b/system/libraries/Validation.php @@ -478,7 +478,21 @@ class CI_Validation { { return ( ! preg_match("/^([a-z0-9\+_\-]+)(\.[a-z0-9\+_\-]+)*@([a-z0-9\-]+\.)+[a-z]{2,6}$/ix", $str)) ? FALSE : TRUE; } + + // -------------------------------------------------------------------- + /** + * Validate IP Address + * + * @access public + * @param string + * @return string + */ + function valid_ip($ip) + { + return ( ! preg_match( "/^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$/", $ip)) ? FALSE : TRUE; + } + // -------------------------------------------------------------------- /** diff --git a/system/libraries/Zip.php b/system/libraries/Zip.php index 218388314..e13c713fe 100644 --- a/system/libraries/Zip.php +++ b/system/libraries/Zip.php @@ -41,7 +41,8 @@ class CI_Zip { { log_message('debug', "Zip Compression Class Initialized"); } - + + // -------------------------------------------------------------------- /** * Add Directory -- cgit v1.2.3-24-g4f1b From 2f8ae02bb689c8280d42bd22837eaa820f8819a8 Mon Sep 17 00:00:00 2001 From: admin Date: Mon, 9 Oct 2006 03:25:43 +0000 Subject: --- system/libraries/Table.php | 325 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 325 insertions(+) create mode 100644 system/libraries/Table.php (limited to 'system') diff --git a/system/libraries/Table.php b/system/libraries/Table.php new file mode 100644 index 000000000..935a7d8a6 --- /dev/null +++ b/system/libraries/Table.php @@ -0,0 +1,325 @@ +template = $template; + } + + // -------------------------------------------------------------------- + + /** + * Add a table heading + * + * Can be passed as an array or discreet params + * + * @access public + * @param mixed + * @return void + */ + function add_heading() + { + $args = func_get_args(); + $this->heading = (is_array($args[0])) ? $args[0] : $args; + } + + // -------------------------------------------------------------------- + + /** + * 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[] = (is_array($args[0])) ? $args[0] : $args; + } + + // -------------------------------------------------------------------- + + /** + * 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)) + { + $this->_set_from_array($table_data); + } + } + + // 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 templata date + $this->_compile_template(); + + + // Build the table! + + $out = $this->template['table_open']; + $out .= $this->newline; + + // Is there a table heading to display? + if (count($this->heading) > 0) + { + $out .= $this->template['heading_row_start']; + $out .= $this->newline; + + foreach($this->heading as $heading) + { + $out .= $this->template['heading_cell_start']; + $out .= $heading; + $out .= $this->template['heading_cell_end']; + } + + $out .= $this->template['heading_row_end']; + $out .= $this->newline; + } + + // Build the table rows + if (count($this->rows) > 0) + { + $i = 1; + foreach($this->rows as $row) + { + if ( ! is_array($row)) + { + break; + } + + // We use modulus to alternate the row colors + $alt = (fmod($i++, 2)) ? '' : 'alt_'; + + $out .= $this->template['row_'.$alt.'start']; + $out .= $this->newline; + + foreach($row as $cells) + { + $out .= $this->template['cell_'.$alt.'start']; + $out .= $cells; + $out .= $this->template['cell_'.$alt.'end']; + } + + $out .= $this->template['row_'.$alt.'end']; + $out .= $this->newline; + } + } + + $out .= $this->template['table_close']; + + return $out; + } + + // -------------------------------------------------------------------- + + /** + * 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, 'field_names')) + { + return FALSE; + } + + $this->heading = $query->field_names(); + } + + // Next blast through the result array and build out the rows + foreach ($query->result_array() as $row) + { + $this->rows[] = $row; + } + } + + // -------------------------------------------------------------------- + + /** + * Set table data from an array + * + * @access public + * @param array + * @return void + */ + function _set_from_array($data) + { + if ( ! is_array($data) OR count($data) == 0) + { + return FALSE; + } + + $i = 0; + foreach ($data as $row) + { + if ( ! is_array($row)) + { + $this->rows[] = $data; + break; + } + + // 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) + { + $this->heading = $row; + } + else + { + $this->rows[] = $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','heading_row_start', 'heading_row_end', 'heading_cell_start', 'heading_cell_end', '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' => '', + + 'heading_row_start' => '', + 'heading_row_end' => '', + 'heading_cell_start' => '', + + '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' => '
' + ); + } + + + + + + + +} + +?> \ No newline at end of file -- cgit v1.2.3-24-g4f1b From 6c9f736650bd9eafb2c44bb844f13de259d5efb6 Mon Sep 17 00:00:00 2001 From: admin Date: Mon, 9 Oct 2006 03:33:48 +0000 Subject: --- system/libraries/Calendar.php | 42 +++++----- system/libraries/User_agent.php | 178 +++++++++++++++++++++++++++++++++++++--- 2 files changed, 189 insertions(+), 31 deletions(-) (limited to 'system') diff --git a/system/libraries/Calendar.php b/system/libraries/Calendar.php index 23a6bf791..048934b82 100644 --- a/system/libraries/Calendar.php +++ b/system/libraries/Calendar.php @@ -398,27 +398,27 @@ class CI_Calendar { 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' => '
' + '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' => '
' ); } diff --git a/system/libraries/User_agent.php b/system/libraries/User_agent.php index 33e8451c6..8c63924b9 100644 --- a/system/libraries/User_agent.php +++ b/system/libraries/User_agent.php @@ -33,6 +33,9 @@ class CI_User_agent { var $is_browser = FALSE; var $is_robot = FALSE; var $is_mobile = FALSE; + + var $languages = array(); + var $charsets = array(); var $platform = ''; var $browser = ''; @@ -40,7 +43,6 @@ class CI_User_agent { var $moble = ''; var $robot = ''; - var $platforms = array ( 'windows nt 6.0' => 'Windows Longhorn', 'windows nt 5.2' => 'Windows 2003', @@ -55,12 +57,13 @@ class CI_User_agent { 'windows 95' => 'Windows 95', 'win95' => 'Windows 95', 'windows' => 'Unknown Windows OS', - 'mac os x' => 'Mac OS X', + 'os x' => 'Mac OS X', + 'ppc mac' => 'Power PC Mac', 'freebsd' => 'FreeBSD', 'ppc' => 'Macintosh', - 'sunos' => 'Sun Solaris', 'linux' => 'Linux', 'debian' => 'Debian', + 'sunos' => 'Sun Solaris', 'beos' => 'BeOS', 'apachebench' => 'ApacheBench', 'aix' => 'AIX', @@ -80,12 +83,21 @@ class CI_User_agent { 'Internet Explorer' => 'Internet Explorer', 'Shiira' => 'Shiira', 'Firefox' => 'Firefox', + 'Chimera' => 'Chimera', + 'Phoenix' => 'Phoenix', + 'Firebird' => 'Firebird', 'Camino' => 'Camino', + 'Netscape' => 'Netscape', + 'OmniWeb' => 'OmniWeb', 'Mozilla' => 'Mozilla', 'Safari' => 'Safari', 'Konqueror' => 'Konqueror', + 'icab' => 'iCab', 'Lynx' => 'Lynx', - 'ANTFresco' => 'Fresco' + 'Links' => 'Links', + 'hotjava' => 'HotJava', + 'amaya' => 'Amaya', + 'IBrowse' => 'IBrowse' ); var $mobiles = array( @@ -488,7 +500,7 @@ class CI_User_agent { return FALSE; } - + // -------------------------------------------------------------------- /** @@ -535,6 +547,51 @@ class CI_User_agent { return FALSE; } + // -------------------------------------------------------------------- + + /** + * Set the accepted languages + * + * @access private + * @return void + */ + function _set_languages() + { + if ((count($this->languages) == 0) AND isset($_SERVER['HTTP_ACCEPT_LANGUAGE']) AND $_SERVER['HTTP_ACCEPT_LANGUAGE'] != '') + { + $languages = preg_replace('/(;q=.+)/i', '', $_SERVER['HTTP_ACCEPT_LANGUAGE']); + + $this->languages = explode(',', $languages); + } + + if (count($this->languages) == 0) + { + $this->languages = array('Undefined'); + } + } + + // -------------------------------------------------------------------- + + /** + * Set the accepted character sets + * + * @access private + * @return void + */ + function _set_charsets() + { + if ((count($this->charsets) == 0) AND isset($_SERVER['HTTP_ACCEPT_CHARSET']) AND $_SERVER['HTTP_ACCEPT_CHARSET'] != '') + { + $charsets = preg_replace('/(;q=.+)/i', '', $_SERVER['HTTP_ACCEPT_CHARSET']); + + $this->charsets = explode(',', $charsets); + } + + if (count($this->charsets) == 0) + { + $this->charsets = array('Undefined'); + } + } // -------------------------------------------------------------------- @@ -577,13 +634,39 @@ class CI_User_agent { // -------------------------------------------------------------------- + /** + * Is this a referral from another site? + * + * @access public + * @return bool + */ + function is_referral() + { + return ( ! isset($_SERVER['HTTP_REFERER']) OR $_SERVER['HTTP_REFERER'] == '') ? FALSE : TRUE; + } + + // -------------------------------------------------------------------- + + /** + * Agent String + * + * @access public + * @return string + */ + function agent() + { + return $this->agent; + } + + // -------------------------------------------------------------------- + /** * Get Platform * * @access public * @return string */ - function get_platform() + function platform() { return $this->platform; } @@ -596,7 +679,7 @@ class CI_User_agent { * @access public * @return string */ - function get_browser() + function browser() { return $this->browser; } @@ -609,7 +692,7 @@ class CI_User_agent { * @access public * @return string */ - function get_version() + function version() { return $this->version; } @@ -622,7 +705,7 @@ class CI_User_agent { * @access public * @return string */ - function get_robot() + function robot() { return $this->robot; } @@ -634,11 +717,86 @@ class CI_User_agent { * @access public * @return string */ - function get_mobile() + function mobile() { return $this->mobile; } + // -------------------------------------------------------------------- + + /** + * Get the referrer + * + * @access public + * @return bool + */ + function referrer() + { + return ( ! isset($_SERVER['HTTP_REFERER']) OR $_SERVER['HTTP_REFERER'] == '') ? '' : $_SERVER['HTTP_REFERER']; + } + + // -------------------------------------------------------------------- + + /** + * Get the accepted languages + * + * @access public + * @return array + */ + function languages() + { + if (count($this->languages) == 0) + { + $this->_set_languages(); + } + + return $this->languages; + } + + // -------------------------------------------------------------------- + + /** + * Get the accepted Character Sets + * + * @access public + * @return array + */ + function charsets() + { + if (count($this->charsets) == 0) + { + $this->_set_charsets(); + } + + return $this->charsets; + } + + // -------------------------------------------------------------------- + + /** + * Test for a particular language + * + * @access public + * @return bool + */ + function accept_lang($lang = 'en') + { + return (in_array(strtolower($lang), $this->languages(), TRUE)) ? TRUE : FALSE; + } + + // -------------------------------------------------------------------- + + /** + * Test for a particular character set + * + * @access public + * @return bool + */ + function accept_charset($charset = 'utf-8') + { + return (in_array(strtolower($charset), $this->charsets(), TRUE)) ? TRUE : FALSE; + } + } -- cgit v1.2.3-24-g4f1b From a1931ad87e8145f08dbf381ceab5bf88457b1a83 Mon Sep 17 00:00:00 2001 From: admin Date: Mon, 9 Oct 2006 04:17:38 +0000 Subject: --- system/libraries/Table.php | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) (limited to 'system') diff --git a/system/libraries/Table.php b/system/libraries/Table.php index 935a7d8a6..4771295a5 100644 --- a/system/libraries/Table.php +++ b/system/libraries/Table.php @@ -61,7 +61,7 @@ class CI_Table { // -------------------------------------------------------------------- /** - * Add a table heading + * Set the table heading * * Can be passed as an array or discreet params * @@ -69,7 +69,7 @@ class CI_Table { * @param mixed * @return void */ - function add_heading() + function set_heading() { $args = func_get_args(); $this->heading = (is_array($args[0])) ? $args[0] : $args; @@ -313,12 +313,7 @@ class CI_Table { 'table_close' => '' ); } - - - - - - + } -- cgit v1.2.3-24-g4f1b From b3ad05ccbc2c0ad24c9af16f7f4d48bf59c71a11 Mon Sep 17 00:00:00 2001 From: admin Date: Mon, 9 Oct 2006 17:25:46 +0000 Subject: --- system/application/config/user_agents.php | 103 ++++++++++++++++++++++++++++++ 1 file changed, 103 insertions(+) create mode 100644 system/application/config/user_agents.php (limited to 'system') diff --git a/system/application/config/user_agents.php b/system/application/config/user_agents.php new file mode 100644 index 000000000..a799f06bd --- /dev/null +++ b/system/application/config/user_agents.php @@ -0,0 +1,103 @@ + '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' + ); + + +// 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( + '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', + 'Mozilla' => 'Mozilla', + 'Safari' => 'Safari', + 'Konqueror' => 'Konqueror', + 'icab' => 'iCab', + 'Lynx' => 'Lynx', + 'Links' => 'Links', + 'hotjava' => 'HotJava', + 'amaya' => 'Amaya', + 'IBrowse' => 'IBrowse' + ); + +$mobiles = array( + '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' + ); + +// 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' + ); + + +?> \ No newline at end of file -- cgit v1.2.3-24-g4f1b From 3822194cde4614137a54eecb1e1fcc86672e84a1 Mon Sep 17 00:00:00 2001 From: admin Date: Mon, 9 Oct 2006 17:34:19 +0000 Subject: --- system/libraries/User_agent.php | 500 ++++++++-------------------------------- 1 file changed, 96 insertions(+), 404 deletions(-) (limited to 'system') diff --git a/system/libraries/User_agent.php b/system/libraries/User_agent.php index 8c63924b9..21162388a 100644 --- a/system/libraries/User_agent.php +++ b/system/libraries/User_agent.php @@ -43,375 +43,6 @@ class CI_User_agent { var $moble = ''; var $robot = ''; - var $platforms = array ( - 'windows nt 6.0' => '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' - ); - - var $browsers = array( - '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', - 'Mozilla' => 'Mozilla', - 'Safari' => 'Safari', - 'Konqueror' => 'Konqueror', - 'icab' => 'iCab', - 'Lynx' => 'Lynx', - 'Links' => 'Links', - 'hotjava' => 'HotJava', - 'amaya' => 'Amaya', - 'IBrowse' => 'IBrowse' - ); - - var $mobiles = array( - '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' - ); - - var $robots = array( - - 'googlebot' => 'Googlebot', - 'msnbot' => 'MSNBot', - 'slurp' => 'Inktomi Slurp', - 'yahoo' => 'Yahoo', - 'askjeeves' => 'AskJeeves', - 'fastcrawler' => 'FastCrawler', - 'infoseek' => 'InfoSeek Robot 1.0', - 'lycos' => 'Lycos', - 'abcdatos' => 'ABCdatos BotLink', - 'Acme.Spider' => 'Acme.Spider', - 'ahoythehomepagefinder' => 'Ahoy! The Homepage Finder', - 'Alkaline' => 'Alkaline', - 'anthill' => 'Anthill', - 'appie' => 'Walhello appie', - 'arachnophilia' => 'Arachnophilia', - 'arale' => 'Arale', - 'araneo' => 'Araneo', - 'araybot' => 'AraybOt', - 'architext' => 'ArchitextSpider', - 'aretha' => 'Aretha', - 'ariadne' => 'ARIADNE', - 'arks' => 'arks', - 'aspider' => 'ASpider (Associative Spider)', - 'atn.txt' => 'ATN Worldwide', - 'atomz' => 'Atomz.com Search Robot', - 'auresys' => 'AURESYS', - 'backrub' => 'BackRub', - 'bbot' => 'BBot', - 'bigbrother' => 'Big Brother', - 'bjaaland' => 'Bjaaland', - 'blackwidow' => 'BlackWidow', - 'blindekuh' => 'Die Blinde Kuh', - 'Bloodhound' => 'Bloodhound', - 'borg-bot' => 'Borg-Bot', - 'boxseabot' => 'BoxSeaBot', - 'brightnet' => 'bright.net caching robot', - 'bspider' => 'BSpider', - 'cactvschemistryspider' => 'CACTVS Chemistry Spider', - 'calif' => 'Calif', - 'cassandra' => 'Cassandra', - 'cgireader' => 'Digimarc Marcspider/CGI', - 'checkbot' => 'Checkbot', - 'christcrawler' => 'ChristCrawler.com', - 'churl' => 'churl', - 'cienciaficcion' => 'cIeNcIaFiCcIoN.nEt', - 'cmc' => 'CMC/0.01', - 'Collective' => 'Collective', - 'combine' => 'Combine System', - 'confuzzledbot' => 'ConfuzzledBot', - 'coolbot' => 'CoolBot', - 'core' => 'Web Core / Roots', - 'cosmos' => 'XYLEME Robot', - 'cruiser' => 'Internet Cruiser Robot', - 'cusco' => 'Cusco', - 'cyberspyder' => 'CyberSpyder Link Test', - 'cydralspider' => 'CydralSpider', - 'desertrealm' => 'Desert Realm Spider', - 'deweb' => 'DeWeb(c) Katalog/Index', - 'dienstspider' => 'DienstSpider', - 'digger' => 'Digger', - 'diibot' => 'Digital Integrity Robot', - 'directhit' => 'Direct Hit Grabber', - 'dnabot' => 'DNAbot', - 'download_express' => 'DownLoad Express', - 'dragonbot' => 'DragonBot', - 'e-collector' => 'e-collector', - 'ebiness' => 'EbiNess', - 'eit' => 'EIT Link Verifier Robot', - 'elfinbot' => 'ELFINBOT', - 'emacs' => 'Emacs-w3 Search Engine', - 'emcspider' => 'ananzi', - 'esculapio' => 'esculapio', - 'esther' => 'Esther', - 'evliyacelebi' => 'Evliya Celebi', - 'nzexplorer' => 'nzexplorer', - 'fdse' => 'Fluid Dynamics Search Engine robot', - 'felix' => 'Felix IDE', - 'ferret' => 'Wild Ferret Web Hopper #1, #2, #3', - 'fetchrover' => 'FetchRover', - 'fido' => 'fido', - 'finnish' => 'Hämähäkki', - 'fireball' => 'KIT-Fireball', - 'fish' => 'Fish search', - 'fouineur' => 'Fouineur', - 'francoroute' => 'Robot Francoroute', - 'freecrawl' => 'Freecrawl', - 'funnelweb' => 'FunnelWeb', - 'gama' => 'gammaSpider, FocusedCrawler', - 'gazz' => 'gazz', - 'gcreep' => 'GCreep', - 'getbot' => 'GetBot', - 'geturl' => 'GetURL', - 'golem' => 'Golem', - 'grapnel' => 'Grapnel/0.01 Experiment', - 'griffon' => 'Griffon ', - 'gromit' => 'Gromit', - 'gulliver' => 'Northern Light Gulliver', - 'gulperbot' => 'Gulper Bot', - 'hambot' => 'HamBot', - 'harvest' => 'Harvest', - 'havindex' => 'havIndex', - 'hi' => 'HI (HTML Index) Search', - 'hometown' => 'Hometown Spider Pro', - 'wired-digital' => 'Wired Digital', - 'htdig' => 'ht://Dig', - 'htmlgobble' => 'HTMLgobble', - 'hyperdecontextualizer' => 'Hyper-Decontextualizer', - 'iajabot' => 'iajaBot', - 'ibm' => 'IBM_Planetwide', - 'iconoclast' => 'Popular Iconoclast', - 'Ilse' => 'Ingrid', - 'imagelock' => 'Imagelock ', - 'incywincy' => 'IncyWincy', - 'informant' => 'Informant', - 'infoseeksidewinder' => 'Infoseek Sidewinder', - 'infospider' => 'InfoSpiders', - 'inspectorwww' => 'Inspector Web', - 'intelliagent' => 'IntelliAgent', - 'irobot' => 'I, Robot', - 'iron33' => 'Iron33', - 'israelisearch' => 'Israeli-search', - 'javabee' => 'JavaBee', - 'JBot' => 'JBot Java Web Robot', - 'jcrawler' => 'JCrawler', - 'jobo' => 'JoBo Java Web Robot', - 'jobot' => 'Jobot', - 'joebot' => 'JoeBot', - 'jubii' => 'The Jubii Indexing Robot', - 'jumpstation' => 'JumpStation', - 'kapsi' => 'image.kapsi.net', - 'katipo' => 'Katipo', - 'kdd' => 'KDD-Explorer', - 'kilroy' => 'Kilroy', - 'ko_yappo_robot' => 'KO_Yappo_Robot', - 'labelgrabber.txt' => 'LabelGrabber', - 'larbin' => 'larbin', - 'legs' => 'legs', - 'linkidator' => 'Link Validator', - 'linkscan' => 'LinkScan', - 'linkwalker' => 'LinkWalker', - 'lockon' => 'Lockon', - 'logo_gif' => 'logo.gif Crawler', - 'magpie' => 'Magpie', - 'marvin' => 'marvin/infoseek', - 'mattie' => 'Mattie', - 'mediafox' => 'MediaFox', - 'merzscope' => 'MerzScope', - 'meshexplorer' => 'NEC-MeshExplorer', - 'MindCrawler' => 'MindCrawler', - 'mnogosearch' => 'mnoGoSearch search engine software', - 'moget' => 'moget', - 'momspider' => 'MOMspider', - 'monster' => 'Monster', - 'motor' => 'Motor', - 'muncher' => 'Muncher', - 'muninn' => 'Muninn', - 'muscatferret' => 'Muscat Ferret', - 'mwdsearch' => 'Mwd.Search', - 'myweb' => 'Internet Shinchakubin', - 'NDSpider' => 'NDSpider', - 'netcarta' => 'NetCarta WebMap Engine', - 'netmechanic' => 'NetMechanic', - 'netscoop' => 'NetScoop', - 'newscan-online' => 'newscan-online', - 'nhse' => 'NHSE Web Forager', - 'nomad' => 'Nomad', - 'northstar' => 'The NorthStar Robot', - 'objectssearch' => 'ObjectsSearch', - 'occam' => 'Occam', - 'octopus' => 'HKU WWW Octopus', - 'OntoSpider' => 'OntoSpider', - 'openfind' => 'Openfind data gatherer', - 'orb_search' => 'Orb Search', - 'packrat' => 'Pack Rat', - 'pageboy' => 'PageBoy', - 'parasite' => 'ParaSite', - 'patric' => 'Patric', - 'pegasus' => 'pegasus', - 'perignator' => 'The Peregrinator', - 'perlcrawler' => 'PerlCrawler 1.0', - 'phantom' => 'Phantom', - 'phpdig' => 'PhpDig', - 'pitkow' => 'html_analyzer', - 'pjspider' => 'Portal Juice Spider', - 'pka' => 'PGP Key Agent', - 'poppi' => 'Poppi', - 'portalb' => 'PortalB Spider', - 'psbot' => 'psbot', - 'Puu' => 'GetterroboPlus Puu', - 'python' => 'The Python Robot', - 'raven ' => 'Raven Search', - 'rbse' => 'RBSE Spider', - 'resumerobot' => 'Resume Robot', - 'rhcs' => 'RoadHouse Crawling System', - 'rixbot' => 'RixBot', - 'roadrunner' => 'Road Runner: The ImageScape Robot', - 'robbie' => 'Robbie the Robot', - 'robi' => 'ComputingSite Robi/1.0', - 'robocrawl' => 'RoboCrawl Spider', - 'robofox' => 'RoboFox', - 'robozilla' => 'Robozilla', - 'roverbot' => 'Roverbot', - 'rules' => 'RuLeS', - 'safetynetrobot' => 'SafetyNet Robot', - 'scooter' => 'Scooter', - 'search_au' => 'Search.Aus-AU.COM', - 'search-info' => 'Sleek', - 'searchprocess' => 'SearchProcess', - 'senrigan' => 'Senrigan', - 'sgscout' => 'SG-Scout', - 'shaggy' => 'ShagSeeker', - 'sift' => 'Sift', - 'simbot' => 'Simmany Robot Ver1.0', - 'site-valet' => 'Site Valet', - 'sitetech' => 'SiteTech-Rover', - 'skymob' => 'Skymob.com', - 'slcrawler' => 'SLCrawler', - 'smartspider' => 'Smart Spider', - 'snooper' => 'Snooper', - 'solbot' => 'Solbot', - 'speedy' => 'Speedy Spider', - 'spider_monkey' => 'spider_monkey', - 'spiderbot' => 'SpiderBot', - 'spiderline' => 'Spiderline Crawler', - 'spiderman' => 'SpiderMan', - 'spiderview' => 'SpiderView(tm)', - 'spry' => 'Spry Wizard Robot', - 'ssearcher' => 'Site Searcher', - 'suke' => 'Suke', - 'suntek' => 'suntek search engine', - 'sven' => 'Sven', - 'sygol' => 'Sygol ', - 'tach_bw' => 'TACH Black Widow', - 'tarantula' => 'Tarantula', - 'tarspider' => 'tarspider', - 'tcl' => 'Tcl W3 Robot', - 'techbot' => 'TechBOT', - 'templeton' => 'Templeton', - 'titin' => 'TitIn', - 'titan' => 'TITAN', - 'tkwww' => 'The TkWWW Robot', - 'tlspider' => 'TLSpider', - 'ucsd' => 'UCSD Crawl', - 'udmsearch' => 'UdmSearch', - 'ultraseek' => 'Ultraseek', - 'uptimebot' => 'UptimeBot', - 'urlck' => 'URL Check', - 'valkyrie' => 'Valkyrie', - 'verticrawl' => 'Verticrawl', - 'victoria' => 'Victoria', - 'visionsearch' => 'vision-search', - 'voidbot' => 'void-bot', - 'voyager' => 'Voyager', - 'vwbot' => 'VWbot', - 'w3index' => 'The NWI Robot', - 'w3m2' => 'W3M2', - 'wallpaper' => 'WallPaper (alias crawlpaper)', - 'wanderer' => 'the World Wide Web Wanderer', - 'wapspider' => 'w@pSpider by wap4.com', - 'webbandit' => 'WebBandit Web Spider', - 'webcatcher' => 'WebCatcher', - 'webcopy' => 'WebCopy', - 'webfetcher' => 'webfetcher', - 'webfoot' => 'The Webfoot Robot', - 'webinator' => 'Webinator', - 'weblayers' => 'weblayers', - 'weblinker' => 'WebLinker', - 'webmirror' => 'WebMirror', - 'webmoose' => 'The Web Moose', - 'webquest' => 'WebQuest', - 'webreader' => 'Digimarc MarcSpider', - 'webreaper' => 'WebReaper', - 'webs' => 'webs', - 'websnarf' => 'Websnarf', - 'webspider' => 'WebSpider', - 'webvac' => 'WebVac', - 'webwalk' => 'webwalk', - 'webwalker' => 'WebWalker', - 'webwatch' => 'WebWatch', - 'wget' => 'Wget', - 'whatuseek' => 'whatUseek Winona', - 'whowhere' => 'WhoWhere Robot', - 'wlm' => 'Weblog Monitor', - 'wmir' => 'w3mir', - 'wolp' => 'WebStolperer', - 'wombat' => 'The Web Wombat ', - 'worm' => 'The World Wide Web Worm', - 'wwwc' => 'WWWC Ver 0.2.5', - 'wz101' => 'WebZinger', - 'xget' => 'XGET', - ); - - /** * Constructor @@ -430,8 +61,61 @@ class CI_User_agent { if ( ! is_null($this->agent)) { - $this->_compile_data(); + if ($this->_load_agent_file()) + { + $this->_compile_data(); + } + } + } + + + // -------------------------------------------------------------------- + + /** + * Compile the User Agent Data + * + * @access private + * @return bool + */ + function _load_agent_file() + { + if ( ! @include(APPPATH.'config/user_agent'.EXT)) + { + return FALSE; + } + + $return = FALSE; + + if (isset($platforms)) + { + $this->platforms = $platforms; + unset($platforms); + $return = TRUE; + } + + if (isset($browsers)) + { + $this->browsers = $browsers; + unset($browsers); + $return = TRUE; + } + + if (isset($mobiles)) + { + $this->browsers = $mobiles; + unset($mobiles); + $return = TRUE; } + + if (isset($robots)) + { + $this->robots = $robots; + unset($robots); + $return = TRUE; + } + + + return $return; } // -------------------------------------------------------------------- @@ -465,15 +149,17 @@ class CI_User_agent { */ function _set_platform() { - foreach ($this->platforms as $key => $val) + if (is_array($this->platforms) AND count($this->platforms) > 0) { - if (preg_match("|$key|i", $this->agent)) + foreach ($this->platforms as $key => $val) { - $this->platform = $val; - return TRUE; + if (preg_match("|".preg_quote($key)."|i", $this->agent)) + { + $this->platform = $val; + return TRUE; + } } } - $this->platform = 'Unknown Platform'; } @@ -487,17 +173,19 @@ class CI_User_agent { */ function _set_browser() { - foreach ($this->browsers as $key => $val) - { - if (preg_match("|".$key.".*?([0-9\.]+)|i", $this->agent, $match)) - { - $this->is_browser = TRUE; - $this->version = $match[1]; - $this->browser = $val; - return TRUE; + if (is_array($this->browsers) AND count($this->browsers) > 0) + { + foreach ($this->browsers as $key => $val) + { + if (preg_match("|".preg_quote($key).".*?([0-9\.]+)|i", $this->agent, $match)) + { + $this->is_browser = TRUE; + $this->version = $match[1]; + $this->browser = $val; + return TRUE; + } } } - return FALSE; } @@ -511,39 +199,43 @@ class CI_User_agent { */ function _set_robot() { - foreach ($this->robots as $key => $val) - { - if (preg_match("|$key|i", $this->agent)) + if (is_array($this->robots) AND count($this->robots) > 0) + { + foreach ($this->robots as $key => $val) { - $this->is_robot = TRUE; - $this->robot = $val; - return TRUE; + if (preg_match("|".preg_quote($key)."|i", $this->agent)) + { + $this->is_robot = TRUE; + $this->robot = $val; + return TRUE; + } } } - return FALSE; } // -------------------------------------------------------------------- /** - * Set the Mobile Devise + * Set the Mobile Device * * @access private * @return bool */ function _set_mobile() { - foreach ($this->mobiles as $key => $val) - { - if (FALSE !== (strpos(strtolower($this->agent), $key))) + if (is_array($this->mobiles) AND count($this->mobiles) > 0) + { + foreach ($this->mobiles as $key => $val) { - $this->is_mobile = TRUE; - $this->mobile = $val; - return TRUE; + if (FALSE !== (strpos(strtolower($this->agent), $key))) + { + $this->is_mobile = TRUE; + $this->mobile = $val; + return TRUE; + } } - } - + } return FALSE; } @@ -559,7 +251,7 @@ class CI_User_agent { { if ((count($this->languages) == 0) AND isset($_SERVER['HTTP_ACCEPT_LANGUAGE']) AND $_SERVER['HTTP_ACCEPT_LANGUAGE'] != '') { - $languages = preg_replace('/(;q=.+)/i', '', $_SERVER['HTTP_ACCEPT_LANGUAGE']); + $languages = preg_replace('/(;q=.+)/i', '', trim($_SERVER['HTTP_ACCEPT_LANGUAGE'])); $this->languages = explode(',', $languages); } @@ -582,7 +274,7 @@ class CI_User_agent { { if ((count($this->charsets) == 0) AND isset($_SERVER['HTTP_ACCEPT_CHARSET']) AND $_SERVER['HTTP_ACCEPT_CHARSET'] != '') { - $charsets = preg_replace('/(;q=.+)/i', '', $_SERVER['HTTP_ACCEPT_CHARSET']); + $charsets = preg_replace('/(;q=.+)/i', '', trim($_SERVER['HTTP_ACCEPT_CHARSET'])); $this->charsets = explode(',', $charsets); } @@ -712,7 +404,7 @@ class CI_User_agent { // -------------------------------------------------------------------- /** - * Get the Mobile Devise + * Get the Mobile Device * * @access public * @return string @@ -732,7 +424,7 @@ class CI_User_agent { */ function referrer() { - return ( ! isset($_SERVER['HTTP_REFERER']) OR $_SERVER['HTTP_REFERER'] == '') ? '' : $_SERVER['HTTP_REFERER']; + return ( ! isset($_SERVER['HTTP_REFERER']) OR $_SERVER['HTTP_REFERER'] == '') ? '' : trim($_SERVER['HTTP_REFERER']); } // -------------------------------------------------------------------- -- cgit v1.2.3-24-g4f1b From 2f0bac87c73febde8019e7cbab541905bcb0e5dd Mon Sep 17 00:00:00 2001 From: admin Date: Mon, 9 Oct 2006 17:36:45 +0000 Subject: --- system/libraries/Loader.php | 29 +++++++++++++---------------- system/libraries/User_agent.php | 3 +-- 2 files changed, 14 insertions(+), 18 deletions(-) (limited to 'system') diff --git a/system/libraries/Loader.php b/system/libraries/Loader.php index 05ee93959..452e39dfa 100644 --- a/system/libraries/Loader.php +++ b/system/libraries/Loader.php @@ -65,15 +65,15 @@ class CI_Loader { * * @access public * @param string the name of the class - * @param mixed any initialization parameters + * @param sring the optional class variable name to assign the library to * @return void */ - function library($class, $param = NULL) + function library($class, $varname = NULL) { if ($class == '') return; - $this->_ci_load_class($class, $param); + $this->_ci_load_class($class, $varname); $this->_ci_assign_to_models(); } @@ -595,7 +595,7 @@ class CI_Loader { * @param mixed any additional parameters * @return void */ - function _ci_load_class($class, $params = NULL) + function _ci_load_class($class, $varname = NULL) { // Prep the class name $class = strtolower(str_replace(EXT, '', $class)); @@ -627,7 +627,7 @@ class CI_Loader { } } - return $this->_ci_init_class($filename, 'MY_', $params); + return $this->_ci_init_class($filename, 'MY_', $varname); } // Lets search for the requested library file and load it. @@ -642,7 +642,7 @@ class CI_Loader { if (file_exists($path.'libraries/'.$filename.EXT)) { include_once($path.'libraries/'.$filename.EXT); - return $this->_ci_init_class($filename, '', $params); + return $this->_ci_init_class($filename, '', $varname); } } } @@ -662,15 +662,12 @@ class CI_Loader { * @param string * @return null */ - function _ci_init_class($class, $prefix = '', $config = NULL) + function _ci_init_class($class, $prefix = '', $varname = NULL) { // Is there an associated config file for this class? - if ($config == NULL) + if (file_exists(APPPATH.'config/'.$class.EXT)) { - if (file_exists(APPPATH.'config/'.$class.EXT)) - { - include_once(APPPATH.'config/'.$class.EXT); - } + include_once(APPPATH.'config/'.$class.EXT); } if ($prefix == '') @@ -682,17 +679,17 @@ class CI_Loader { $name = $prefix.$class; } - $varname = ( ! isset($remap[$class])) ? $class : $remap[$class]; - $varname = strtolower($varname); + $classvar = ( ! is_null($varname)) ? $varname : strtolower($class); + // Instantiate the class if ($config !== NULL) { - $this->CI->$varname = new $name($config); + $this->CI->$classvar = new $name($config); } else { - $this->CI->$varname = new $name; + $this->CI->$classvar = new $name; } } diff --git a/system/libraries/User_agent.php b/system/libraries/User_agent.php index 21162388a..39e12327f 100644 --- a/system/libraries/User_agent.php +++ b/system/libraries/User_agent.php @@ -113,8 +113,7 @@ class CI_User_agent { unset($robots); $return = TRUE; } - - + return $return; } -- cgit v1.2.3-24-g4f1b From b1fddc051af66a0a41a709862dd84d06139e2325 Mon Sep 17 00:00:00 2001 From: admin Date: Mon, 9 Oct 2006 21:29:07 +0000 Subject: --- system/application/config/database.php | 2 +- system/application/config/mimes.php | 2 +- system/libraries/Loader.php | 16 +++++++++++++--- system/libraries/User_agent.php | 15 ++++++++++----- 4 files changed, 25 insertions(+), 10 deletions(-) (limited to 'system') diff --git a/system/application/config/database.php b/system/application/config/database.php index de781646c..c594ba896 100644 --- a/system/application/config/database.php +++ b/system/application/config/database.php @@ -40,7 +40,7 @@ $db['default']['dbprefix'] = ""; $db['default']['active_r'] = TRUE; $db['default']['pconnect'] = TRUE; $db['default']['db_debug'] = TRUE; -$db['default']['cache_on'] = TRUE; +$db['default']['cache_on'] = FALSE; $db['default']['cachedir'] = APPPATH.'db_cache/'; diff --git a/system/application/config/mimes.php b/system/application/config/mimes.php index de0a91752..8b5036f23 100644 --- a/system/application/config/mimes.php +++ b/system/application/config/mimes.php @@ -4,7 +4,7 @@ | MIME TYPES | ------------------------------------------------------------------- | This file contains an array of mime types. It is used by the -| Upload class to help identyfiy allowed file types. +| Upload class to help identify allowed file types. | */ diff --git a/system/libraries/Loader.php b/system/libraries/Loader.php index 452e39dfa..dc588bb0c 100644 --- a/system/libraries/Loader.php +++ b/system/libraries/Loader.php @@ -30,12 +30,13 @@ class CI_Loader { var $CI; var $ob_level; + var $view_path = ''; var $cached_vars = array(); var $models = array(); var $helpers = array(); var $plugins = array(); var $scripts = array(); - var $view_path = ''; + var $varmap = array('unit_test' => 'unit', 'user_agent' => 'agent'); /** * Constructor @@ -665,6 +666,7 @@ class CI_Loader { function _ci_init_class($class, $prefix = '', $varname = NULL) { // Is there an associated config file for this class? + $config = NULL; if (file_exists(APPPATH.'config/'.$class.EXT)) { include_once(APPPATH.'config/'.$class.EXT); @@ -678,9 +680,17 @@ class CI_Loader { { $name = $prefix.$class; } - - $classvar = ( ! is_null($varname)) ? $varname : strtolower($class); + // Set the variable name we will assign the class to + if ( ! is_null($varname)) + { + $classvar = $varname; + } + else + { + $class = strtolower($class); + $classvar = ( ! isset($this->varmap[$class])) ? $class : $this->varmap[$class]; + } // Instantiate the class if ($config !== NULL) diff --git a/system/libraries/User_agent.php b/system/libraries/User_agent.php index 39e12327f..11c2baa68 100644 --- a/system/libraries/User_agent.php +++ b/system/libraries/User_agent.php @@ -37,12 +37,16 @@ class CI_User_agent { var $languages = array(); var $charsets = array(); + var $platforms = array(); + var $browsers = array(); + var $mobiles = array(); + var $robots = array(); + var $platform = ''; var $browser = ''; var $version = ''; var $moble = ''; var $robot = ''; - /** * Constructor @@ -66,8 +70,9 @@ class CI_User_agent { $this->_compile_data(); } } + + log_message('debug', "Table Class Initialized"); } - // -------------------------------------------------------------------- @@ -79,7 +84,7 @@ class CI_User_agent { */ function _load_agent_file() { - if ( ! @include(APPPATH.'config/user_agent'.EXT)) + if ( ! @include(APPPATH.'config/user_agents'.EXT)) { return FALSE; } @@ -102,7 +107,7 @@ class CI_User_agent { if (isset($mobiles)) { - $this->browsers = $mobiles; + $this->mobiles = $mobiles; unset($mobiles); $return = TRUE; } @@ -344,7 +349,7 @@ class CI_User_agent { * @access public * @return string */ - function agent() + function agent_string() { return $this->agent; } -- cgit v1.2.3-24-g4f1b From daaa0c8403a80d325d3ce2b85c5be62067a3854b Mon Sep 17 00:00:00 2001 From: admin Date: Mon, 9 Oct 2006 21:39:12 +0000 Subject: --- system/libraries/Unit_test.php | 331 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 331 insertions(+) create mode 100644 system/libraries/Unit_test.php (limited to 'system') diff --git a/system/libraries/Unit_test.php b/system/libraries/Unit_test.php new file mode 100644 index 000000000..415162388 --- /dev/null +++ b/system/libraries/Unit_test.php @@ -0,0 +1,331 @@ +active == FALSE) + return FALSE; + + if (in_array($expected, array('is_string', 'is_bool', 'is_true', 'is_false', 'is_int', 'is_numeric', 'is_float', 'is_double', 'is_array', 'is_null'), TRUE)) + { + $expected = str_replace('is_float', 'is_double', $expected); + $result = ($expected($test)) ? TRUE : FALSE; + $extype = str_replace(array('true', 'false'), 'bool', str_replace('is_', '', $expected)); + } + else + { + if ($this->strict == TRUE) + $result = ($test === $expected) ? TRUE : FALSE; + else + $result = ($test == $expected) ? TRUE : FALSE; + + $extype = gettype($expected); + } + + $back = $this->_backtrace(); + + $report[] = array ( + 'test_name' => $test_name, + 'test_datatype' => gettype($test), + 'res_datatype' => $extype, + 'result' => ($result === TRUE) ? 'passed' : 'failed', + 'file' => $back['file'], + 'line' => $back['line'] + ); + + $this->results[] = $report; + + return($this->report($this->result($report))); + } + + // -------------------------------------------------------------------- + + /** + * Generate a report + * + * Displays a table with the test data + * + * @access public + * @return string + */ + function report($result = array()) + { + if (count($result) == 0) + { + $result = $this->result(); + } + + $this->_parse_template(); + + $r = ''; + foreach ($result as $res) + { + $table = ''; + + foreach ($res as $key => $val) + { + $temp = $this->_template_rows; + $temp = str_replace('{item}', $key, $temp); + $temp = str_replace('{result}', $val, $temp); + $table .= $temp; + } + + $r .= str_replace('{rows}', $table, $this->_template); + } + + return $r; + } + + // -------------------------------------------------------------------- + + /** + * Use strict comparison + * + * Causes the evaluation to use === rather then == + * + * @access public + * @param bool + * @return null + */ + function use_strict($state = TRUE) + { + $this->strict = ($state == FALSE) ? FALSE : TRUE; + } + + // -------------------------------------------------------------------- + + /** + * Make Unit testing active + * + * Enables/disables unit testing + * + * @access public + * @param bool + * @return null + */ + function active($state = TRUE) + { + $this->active = ($state == FALSE) ? FALSE : TRUE; + } + + // -------------------------------------------------------------------- + + /** + * Result Array + * + * Returns the raw result data + * + * @access public + * @return array + */ + function result($results = array()) + { + $CI =& get_instance(); + $CI->load->language('unit_test'); + + if (count($results) == 0) + { + $results = $this->results; + } + + $retval = array(); + foreach ($results as $result) + { + $temp = array(); + foreach ($result as $key => $val) + { + if (is_array($val)) + { + foreach ($val as $k => $v) + { + if (FALSE !== ($line = $CI->lang->line(strtolower('ut_'.$v)))) + { + $v = $line; + } + $temp[$CI->lang->line('ut_'.$k)] = $v; + } + } + else + { + if (FALSE !== ($line = $CI->lang->line(strtolower('ut_'.$val)))) + { + $val = $line; + } + $temp[$CI->lang->line('ut_'.$key)] = $val; + } + } + + $retval[] = $temp; + } + + return $retval; + } + + // -------------------------------------------------------------------- + + /** + * Set the template + * + * This lets us set the template to be used to display results + * + * @access public + * @params string + * @return void + */ + function set_template($template) + { + $this->_template = $template; + } + + // -------------------------------------------------------------------- + + /** + * Generate a backtrace + * + * This lets us show file names and line numbers + * + * @access private + * @return array + */ + function _backtrace() + { + if (function_exists('debug_backtrace')) + { + $back = debug_backtrace(); + + $file = ( ! isset($back['1']['file'])) ? '' : $back['1']['file']; + $line = ( ! isset($back['1']['line'])) ? '' : $back['1']['line']; + + return array('file' => $file, 'line' => $line); + } + return array('file' => 'Unknown', 'line' => 'Unknown'); + } + + // -------------------------------------------------------------------- + + /** + * Get Default Template + * + * @access private + * @return string + */ + function _default_template() + { + $this->_template = ' +
+ + {rows} +
'; + + $this->_template_rows = ' + + {item} + {result} + + '; + } + + // -------------------------------------------------------------------- + + /** + * Parse Template + * + * Harvests the data within the template {pseudo-variables} + * + * @access private + * @return void + */ + function _parse_template() + { + if ( ! is_null($this->_template_rows)) + { + return; + } + + if (is_null($this->_template)) + { + $this->_default_template(); + return; + } + + if ( ! preg_match("/\{rows\}(.*?)\{\/rows\}/si", $this->_template, $match)) + { + $this->_default_template(); + return; + } + + $this->_template_rows = $match['1']; + $this->_template = str_replace($match['0'], '{rows}', $this->_template); + } + +} +// END Unit_test Class + +/** + * Helper functions to test boolean true/false + * + * + * @access private + * @return bool + */ +function is_true($test) +{ + return (is_bool($test) AND $test === TRUE) ? TRUE : FALSE; +} +function is_false($test) +{ + return (is_bool($test) AND $test === FALSE) ? TRUE : FALSE; +} + +?> \ No newline at end of file -- cgit v1.2.3-24-g4f1b From 8d3f977d2c1d4dc01a72c0add3b14ffc73a54762 Mon Sep 17 00:00:00 2001 From: admin Date: Mon, 9 Oct 2006 21:39:48 +0000 Subject: --- system/libraries/Loader.php | 7 - system/libraries/Unit.php | 331 -------------------------------------------- 2 files changed, 338 deletions(-) delete mode 100644 system/libraries/Unit.php (limited to 'system') diff --git a/system/libraries/Loader.php b/system/libraries/Loader.php index dc588bb0c..ca4c4feba 100644 --- a/system/libraries/Loader.php +++ b/system/libraries/Loader.php @@ -601,13 +601,6 @@ class CI_Loader { // Prep the class name $class = strtolower(str_replace(EXT, '', $class)); - // Bug fix for backward compat. - // Kill this at some point in the future - if ($class == 'unit_test') - { - $class = 'unit'; - } - // Is this a class extension request? if (substr($class, 0, 3) == 'my_') { diff --git a/system/libraries/Unit.php b/system/libraries/Unit.php deleted file mode 100644 index 439424fbb..000000000 --- a/system/libraries/Unit.php +++ /dev/null @@ -1,331 +0,0 @@ -active == FALSE) - return FALSE; - - if (in_array($expected, array('is_string', 'is_bool', 'is_true', 'is_false', 'is_int', 'is_numeric', 'is_float', 'is_double', 'is_array', 'is_null'), TRUE)) - { - $expected = str_replace('is_float', 'is_double', $expected); - $result = ($expected($test)) ? TRUE : FALSE; - $extype = str_replace(array('true', 'false'), 'bool', str_replace('is_', '', $expected)); - } - else - { - if ($this->strict == TRUE) - $result = ($test === $expected) ? TRUE : FALSE; - else - $result = ($test == $expected) ? TRUE : FALSE; - - $extype = gettype($expected); - } - - $back = $this->_backtrace(); - - $report[] = array ( - 'test_name' => $test_name, - 'test_datatype' => gettype($test), - 'res_datatype' => $extype, - 'result' => ($result === TRUE) ? 'passed' : 'failed', - 'file' => $back['file'], - 'line' => $back['line'] - ); - - $this->results[] = $report; - - return($this->report($this->result($report))); - } - - // -------------------------------------------------------------------- - - /** - * Generate a report - * - * Displays a table with the test data - * - * @access public - * @return string - */ - function report($result = array()) - { - if (count($result) == 0) - { - $result = $this->result(); - } - - $this->_parse_template(); - - $r = ''; - foreach ($result as $res) - { - $table = ''; - - foreach ($res as $key => $val) - { - $temp = $this->_template_rows; - $temp = str_replace('{item}', $key, $temp); - $temp = str_replace('{result}', $val, $temp); - $table .= $temp; - } - - $r .= str_replace('{rows}', $table, $this->_template); - } - - return $r; - } - - // -------------------------------------------------------------------- - - /** - * Use strict comparison - * - * Causes the evaluation to use === rather then == - * - * @access public - * @param bool - * @return null - */ - function use_strict($state = TRUE) - { - $this->strict = ($state == FALSE) ? FALSE : TRUE; - } - - // -------------------------------------------------------------------- - - /** - * Make Unit testing active - * - * Enables/disables unit testing - * - * @access public - * @param bool - * @return null - */ - function active($state = TRUE) - { - $this->active = ($state == FALSE) ? FALSE : TRUE; - } - - // -------------------------------------------------------------------- - - /** - * Result Array - * - * Returns the raw result data - * - * @access public - * @return array - */ - function result($results = array()) - { - $CI =& get_instance(); - $CI->load->language('unit_test'); - - if (count($results) == 0) - { - $results = $this->results; - } - - $retval = array(); - foreach ($results as $result) - { - $temp = array(); - foreach ($result as $key => $val) - { - if (is_array($val)) - { - foreach ($val as $k => $v) - { - if (FALSE !== ($line = $CI->lang->line(strtolower('ut_'.$v)))) - { - $v = $line; - } - $temp[$CI->lang->line('ut_'.$k)] = $v; - } - } - else - { - if (FALSE !== ($line = $CI->lang->line(strtolower('ut_'.$val)))) - { - $val = $line; - } - $temp[$CI->lang->line('ut_'.$key)] = $val; - } - } - - $retval[] = $temp; - } - - return $retval; - } - - // -------------------------------------------------------------------- - - /** - * Set the template - * - * This lets us set the template to be used to display results - * - * @access public - * @params string - * @return void - */ - function set_template($template) - { - $this->_template = $template; - } - - // -------------------------------------------------------------------- - - /** - * Generate a backtrace - * - * This lets us show file names and line numbers - * - * @access private - * @return array - */ - function _backtrace() - { - if (function_exists('debug_backtrace')) - { - $back = debug_backtrace(); - - $file = ( ! isset($back['1']['file'])) ? '' : $back['1']['file']; - $line = ( ! isset($back['1']['line'])) ? '' : $back['1']['line']; - - return array('file' => $file, 'line' => $line); - } - return array('file' => 'Unknown', 'line' => 'Unknown'); - } - - // -------------------------------------------------------------------- - - /** - * Get Default Template - * - * @access private - * @return string - */ - function _default_template() - { - $this->_template = ' -
- - {rows} -
'; - - $this->_template_rows = ' - - {item} - {result} - - '; - } - - // -------------------------------------------------------------------- - - /** - * Parse Template - * - * Harvests the data within the template {pseudo-variables} - * - * @access private - * @return void - */ - function _parse_template() - { - if ( ! is_null($this->_template_rows)) - { - return; - } - - if (is_null($this->_template)) - { - $this->_default_template(); - return; - } - - if ( ! preg_match("/\{rows\}(.*?)\{\/rows\}/si", $this->_template, $match)) - { - $this->_default_template(); - return; - } - - $this->_template_rows = $match['1']; - $this->_template = str_replace($match['0'], '{rows}', $this->_template); - } - -} -// END Unit_test Class - -/** - * Helper functions to test boolean true/false - * - * - * @access private - * @return bool - */ -function is_true($test) -{ - return (is_bool($test) AND $test === TRUE) ? TRUE : FALSE; -} -function is_false($test) -{ - return (is_bool($test) AND $test === FALSE) ? TRUE : FALSE; -} - -?> \ No newline at end of file -- cgit v1.2.3-24-g4f1b From cf49390d3d699d878eb6e151745e80285465ddb9 Mon Sep 17 00:00:00 2001 From: admin Date: Tue, 10 Oct 2006 07:12:31 +0000 Subject: --- system/codeigniter/Base4.php | 29 +++-- system/libraries/Controller.php | 17 +-- system/libraries/Loader.php | 219 ++++++++++++++++++++++++++----------- system/libraries/Model.php | 4 +- system/scaffolding/Scaffolding.php | 2 +- 5 files changed, 188 insertions(+), 83 deletions(-) (limited to 'system') diff --git a/system/codeigniter/Base4.php b/system/codeigniter/Base4.php index eccf58ed8..115c10727 100644 --- a/system/codeigniter/Base4.php +++ b/system/codeigniter/Base4.php @@ -18,10 +18,18 @@ /** * CI_BASE - For PHP 4 * - * This file is used only when Code Igniter is being run under PHP 4. - * Since PHP 4 has such poor object handling we had to come up with - * a hack (and a really ugly one at that...) to resolve some scoping - * problems. PHP 5 doesn't suffer from this problem so we load one of + * This file is used only when Code Igniter is being run under PHP 4. + * + * In order to allow CI to work under PHP 4 we had to make the Loader class + * the parent class of the Controller Base class. It's the only way we + * could enable functions like $this->load->library('email') to instantiate + * classes that can then be used within controllers as $this->email->send() + * + * PHP 4 also has trouble referencing the CI super object within application + * constructors since objects do not exist until the class is fully + * instantiated. Basically PHP 4 sucks... + * + * Since PHP 5 doesn't suffer from this problem so we load one of * two files based on the version of PHP being run. * * @package CodeIgniter @@ -34,18 +42,25 @@ function CI_Base() { - global $OBJ; parent::CI_Loader(); $this->load =& $this; + + global $OBJ; $OBJ = $this->load; } } function &get_instance() { - global $OBJ, $CI; + global $CI, $OBJ; + + if (is_object($CI)) + { + $CI->_ci_use_instance = TRUE; + return $CI; + } - return (is_object($CI)) ? $CI : $OBJ->load; + return $OBJ->load; } ?> \ No newline at end of file diff --git a/system/libraries/Controller.php b/system/libraries/Controller.php index 4b9e3e960..c80097a17 100644 --- a/system/libraries/Controller.php +++ b/system/libraries/Controller.php @@ -80,20 +80,13 @@ class Controller extends CI_Base { if (floor(phpversion()) >= 5) { $this->load = new CI_Loader(); + $this->load->_ci_use_instance = TRUE; + $this->load->_ci_autoloader(); } - - // Load everything specified in the autoload.php file - $this->load->_ci_autoloader(); - - // This allows anything loaded using $this->load (viwes, files, etc.) - // to become accessible from within the Controller class functions. - foreach (get_object_vars($this) as $key => $var) + else { - if (is_object($var)) - { - $this->load->$key =& $this->$key; - } - } + $this->_ci_autoloader(); + } } // -------------------------------------------------------------------- diff --git a/system/libraries/Loader.php b/system/libraries/Loader.php index ca4c4feba..1738438ed 100644 --- a/system/libraries/Loader.php +++ b/system/libraries/Loader.php @@ -28,15 +28,18 @@ */ class CI_Loader { - var $CI; - var $ob_level; - var $view_path = ''; - var $cached_vars = array(); - var $models = array(); - var $helpers = array(); - var $plugins = array(); - var $scripts = array(); - var $varmap = array('unit_test' => 'unit', 'user_agent' => 'agent'); + var $_ci_ob_level; + var $_ci_view_path = ''; + var $_ci_cached_vars = array(); + var $_ci_models = array(); + var $_ci_helpers = array(); + var $_ci_plugins = array(); + var $_ci_scripts = array(); + var $_ci_varmap = array('unit_test' => 'unit', 'user_agent' => 'agent'); + + var $_ci_use_instance = FALSE; // This variable determines whether we should + // use $this or $CI =& get_instance() + // throughout this class. Don't mess with it. /** * Constructor @@ -47,11 +50,9 @@ class CI_Loader { * @access public */ function CI_Loader() - { - $this->CI =& get_instance(); - - $this->view_path = APPPATH.'views/'; - $this->ob_level = ob_get_level(); + { + $this->_ci_view_path = APPPATH.'views/'; + $this->_ci_ob_level = ob_get_level(); log_message('debug', "Loader Class Initialized"); } @@ -95,8 +96,7 @@ class CI_Loader { if ($model == '') return; - // Is the model in a sub-folder? - // If so, parse out the filename and path. + // Is the model in a sub-folder? If so, parse out the filename and path. if (strpos($model, '/') === FALSE) { $path = ''; @@ -114,14 +114,25 @@ class CI_Loader { $name = $model; } - if (in_array($name, $this->models, TRUE)) + if (in_array($name, $this->_ci_models, TRUE)) { return; - } + } - if (isset($this->CI->$name)) + if ($this->_ci_use_instance) + { + $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); + } + } + else { - show_error('The model name you are loading is the name of a resource that is already being used: '.$name); + if (isset($this->$name)) + { + show_error('The model name you are loading is the name of a resource that is already being used: '.$name); + } } $model = strtolower($model); @@ -136,7 +147,14 @@ class CI_Loader { if ($db_conn === TRUE) $db_conn = ''; - $this->CI->load->database($db_conn, FALSE, TRUE); + if ($this->_ci_use_instance) + { + $CI->load->database($db_conn, FALSE, TRUE); + } + else + { + $this->database($db_conn, FALSE, TRUE); + } } if ( ! class_exists('Model')) @@ -147,8 +165,17 @@ class CI_Loader { require_once(APPPATH.'models/'.$path.$model.EXT); $model = ucfirst($model); - $this->CI->$name = new $model(); - $this->models[] = $name; + + if ($this->_ci_use_instance) + { + $CI->$name = new $model(); + } + else + { + $this->$name = new $model(); + } + + $this->_ci_models[] = $name; $this->_ci_assign_to_models(); } @@ -239,7 +266,7 @@ class CI_Loader { { foreach ($vars as $key => $val) { - $this->cached_vars[$key] = $val; + $this->_ci_cached_vars[$key] = $val; } } } @@ -264,7 +291,7 @@ class CI_Loader { foreach ($helpers as $helper) { - if (isset($this->helpers[$helper])) + if (isset($this->_ci_helpers[$helper])) { continue; } @@ -287,7 +314,7 @@ class CI_Loader { } } - $this->helpers[$helper] = TRUE; + $this->_ci_helpers[$helper] = TRUE; } log_message('debug', 'Helpers loaded: '.implode(', ', $helpers)); @@ -330,7 +357,7 @@ class CI_Loader { foreach ($plugins as $plugin) { - if (isset($this->plugins[$plugin])) + if (isset($this->_ci_plugins[$plugin])) { continue; } @@ -353,7 +380,7 @@ class CI_Loader { } } - $this->plugins[$plugin] = TRUE; + $this->_ci_plugins[$plugin] = TRUE; } log_message('debug', 'Plugins loaded: '.implode(', ', $plugins)); @@ -400,7 +427,7 @@ class CI_Loader { foreach ($scripts as $script) { - if (isset($this->scripts[$script])) + if (isset($this->_ci_scripts[$script])) { continue; } @@ -414,7 +441,7 @@ class CI_Loader { include_once(APPPATH.'scripts/'.$script.EXT); - $this->scripts[$script] = TRUE; + $this->_ci_scripts[$script] = TRUE; } log_message('debug', 'Scripts loaded: '.implode(', ', $scripts)); @@ -431,7 +458,15 @@ class CI_Loader { */ function language($file = '', $lang = '', $return = FALSE) { - return $this->CI->lang->load($file, $lang, $return); + if ($this->_ci_use_instance) + { + $CI =& get_instance(); + return $CI->lang->load($file, $lang, $return); + } + else + { + return $this->lang->load($file, $lang, $return); + } } // -------------------------------------------------------------------- @@ -444,8 +479,16 @@ class CI_Loader { * @return void */ function config($file = '') - { - $this->CI->config->load($file); + { + if ($this->_ci_use_instance) + { + $CI =& get_instance(); + $CI->config->load($file); + } + else + { + $this->config->load($file); + } } // -------------------------------------------------------------------- @@ -471,9 +514,18 @@ class CI_Loader { { show_error('You must include the name of the table you would like access when you initialize scaffolding'); } - - $this->CI->_ci_scaffolding = TRUE; - $this->CI->_ci_scaff_table = $table; + + if ($this->_ci_use_instance) + { + $CI =& get_instance(); + $CI->_ci_scaffolding = TRUE; + $CI->_ci_scaff_table = $table; + } + else + { + $this->_ci_scaffolding = TRUE; + $this->_ci_scaff_table = $table; + } } // -------------------------------------------------------------------- @@ -491,14 +543,20 @@ class CI_Loader { { // This allows anything loaded using $this->load (viwes, files, etc.) // to become accessible from within the Controller and Model functions. - foreach (get_object_vars($this->CI) as $key => $var) + // Only needed when running PHP 5 + + if ($this->_ci_use_instance) { - if (is_object($var)) + $CI =& get_instance(); + foreach (get_object_vars($CI) as $key => $var) { - $this->$key =& $this->CI->$key; + if ( ! isset($this->$key)) + { + $this->$key =& $CI->$key; + } } } - + // Set the default data variables foreach (array('view', 'vars', 'path', 'return') as $val) { @@ -515,16 +573,16 @@ class CI_Loader { */ if (is_array($vars)) { - $this->cached_vars = array_merge($this->cached_vars, $vars); + $this->_ci_cached_vars = array_merge($this->_ci_cached_vars, $vars); } - extract($this->cached_vars); + extract($this->_ci_cached_vars); // Set the path to the requested file if ($path == '') { $ext = pathinfo($view, PATHINFO_EXTENSION); $file = ($ext == '') ? $view.EXT : $view; - $path = $this->view_path.$file; + $path = $this->_ci_view_path.$file; } else { @@ -572,14 +630,15 @@ class CI_Loader { * it can be seen and included properly by the first included * template and any subsequent ones. Oy! * - */ - if (ob_get_level() > $this->ob_level + 1) + */ + if (ob_get_level() > $this->_ci_ob_level + 1) { ob_end_flush(); } else { - $this->CI->output->set_output(ob_get_contents()); + global $OUT; + $OUT->set_output(ob_get_contents()); ob_end_clean(); } } @@ -682,18 +741,33 @@ class CI_Loader { else { $class = strtolower($class); - $classvar = ( ! isset($this->varmap[$class])) ? $class : $this->varmap[$class]; + $classvar = ( ! isset($this->_ci_varmap[$class])) ? $class : $this->_ci_varmap[$class]; } - // Instantiate the class - if ($config !== NULL) + // Instantiate the class + if ($this->_ci_use_instance) { - $this->CI->$classvar = new $name($config); + $CI =& get_instance(); + if ($config !== NULL) + { + $CI->$classvar = new $name($config); + } + else + { + $CI->$classvar = new $name; + } } else - { - $this->CI->$classvar = new $name; - } + { + if ($config !== NULL) + { + $this->$classvar = new $name($config); + } + else + { + $this->$classvar = new $name; + } + } } // -------------------------------------------------------------------- @@ -719,10 +793,21 @@ class CI_Loader { // Load any custome config file if (count($autoload['config']) > 0) - { - foreach ($autoload['config'] as $key => $val) + { + if ($this->_ci_use_instance) + { + $CI =& get_instance(); + foreach ($autoload['config'] as $key => $val) + { + $CI->config->load($val); + } + } + else { - $this->CI->config->load($val); + foreach ($autoload['config'] as $key => $val) + { + $this->config->load($val); + } } } @@ -788,14 +873,26 @@ class CI_Loader { */ function _ci_assign_to_models() { - if (count($this->models) == 0) + if (count($this->_ci_models) == 0) { return; } - foreach ($this->models as $model) - { - $this->CI->$model->_assign_libraries(); - } + + if ($this->_ci_use_instance) + { + $CI =& get_instance(); + foreach ($this->_ci_models as $model) + { + $CI->$model->_assign_libraries(); + } + } + else + { + foreach ($this->_ci_models as $model) + { + $this->$model->_assign_libraries(); + } + } } // -------------------------------------------------------------------- diff --git a/system/libraries/Model.php b/system/libraries/Model.php index 46f0367cb..48615e07c 100644 --- a/system/libraries/Model.php +++ b/system/libraries/Model.php @@ -51,8 +51,8 @@ class Model { { $CI =& get_instance(); foreach (get_object_vars($CI) as $key => $var) - { - if (is_object($var) AND ! isset($this->$key)) + { + if ( ! isset($this->$key)) { if ($use_reference === TRUE) { diff --git a/system/scaffolding/Scaffolding.php b/system/scaffolding/Scaffolding.php index c046d228f..6c4b3a537 100644 --- a/system/scaffolding/Scaffolding.php +++ b/system/scaffolding/Scaffolding.php @@ -56,7 +56,7 @@ class Scaffolding { * the load->view function knows where to look. */ - $this->CI->load->view_path = BASEPATH.'scaffolding/views/'; + $this->CI->load->_ci_view_path = BASEPATH.'scaffolding/views/'; // Set the base URL $this->base_url = $this->CI->config->site_url().'/'.$this->CI->uri->segment(1).$this->CI->uri->slash_segment(2, 'both'); -- cgit v1.2.3-24-g4f1b From 34f7f2d0a84c59233689908c11d8d2c6c5ba0875 Mon Sep 17 00:00:00 2001 From: admin Date: Tue, 10 Oct 2006 08:06:42 +0000 Subject: --- system/codeigniter/Base4.php | 1 - system/libraries/Controller.php | 3 +- system/libraries/Loader.php | 77 +++++++++++++++++++++++++++++------------ 3 files changed, 57 insertions(+), 24 deletions(-) (limited to 'system') diff --git a/system/codeigniter/Base4.php b/system/codeigniter/Base4.php index 115c10727..8b3dc92f3 100644 --- a/system/codeigniter/Base4.php +++ b/system/codeigniter/Base4.php @@ -56,7 +56,6 @@ function &get_instance() if (is_object($CI)) { - $CI->_ci_use_instance = TRUE; return $CI; } diff --git a/system/libraries/Controller.php b/system/libraries/Controller.php index c80097a17..7a3f5e5d5 100644 --- a/system/libraries/Controller.php +++ b/system/libraries/Controller.php @@ -32,6 +32,8 @@ class Controller extends CI_Base { var $_ci_scaffolding = FALSE; var $_ci_scaff_table = FALSE; + + /** * Constructor * @@ -80,7 +82,6 @@ class Controller extends CI_Base { if (floor(phpversion()) >= 5) { $this->load = new CI_Loader(); - $this->load->_ci_use_instance = TRUE; $this->load->_ci_autoloader(); } else diff --git a/system/libraries/Loader.php b/system/libraries/Loader.php index 1738438ed..43d1cbecb 100644 --- a/system/libraries/Loader.php +++ b/system/libraries/Loader.php @@ -28,8 +28,11 @@ */ class CI_Loader { + // All these are set automatically. Don't mess with them. var $_ci_ob_level; var $_ci_view_path = ''; + var $_ci_is_php5 = FALSE; + var $_ci_use_instance = FALSE; // Whether we should use $this or $CI =& get_instance() var $_ci_cached_vars = array(); var $_ci_models = array(); var $_ci_helpers = array(); @@ -37,20 +40,17 @@ class CI_Loader { var $_ci_scripts = array(); var $_ci_varmap = array('unit_test' => 'unit', 'user_agent' => 'agent'); - var $_ci_use_instance = FALSE; // This variable determines whether we should - // use $this or $CI =& get_instance() - // throughout this class. Don't mess with it. /** * Constructor * - * Sets the path to the view files and gets the initial output - * buffering level + * Sets the path to the view files and gets the initial output buffering level * * @access public */ function CI_Loader() { + $this->_ci_is_php5 = (floor(phpversion()) >= 5) ? TRUE : FALSE; $this->_ci_view_path = APPPATH.'views/'; $this->_ci_ob_level = ob_get_level(); @@ -119,7 +119,7 @@ class CI_Loader { return; } - if ($this->_ci_use_instance) + if ($this->_ci_use_instance()) { $CI =& get_instance(); if (isset($CI->$name)) @@ -147,7 +147,7 @@ class CI_Loader { if ($db_conn === TRUE) $db_conn = ''; - if ($this->_ci_use_instance) + if ($this->_ci_use_instance()) { $CI->load->database($db_conn, FALSE, TRUE); } @@ -165,20 +165,34 @@ class CI_Loader { require_once(APPPATH.'models/'.$path.$model.EXT); $model = ucfirst($model); - - if ($this->_ci_use_instance) + + if ($this->_ci_use_instance()) { - $CI->$name = new $model(); + $CI->$name = new $model(); + foreach (get_object_vars($CI) as $key => $var) + { + if ( ! isset($CI->$name->$key)) + { + $CI->$name->$key =& $CI->$key; + } + } } else { $this->$name = new $model(); - } + foreach (get_object_vars($this) as $key => $var) + { + if ( ! isset($this->$name->$key)) + { + $this->$name->$key =& $CI->$key; + } + } + } $this->_ci_models[] = $name; - $this->_ci_assign_to_models(); } + // -------------------------------------------------------------------- /** @@ -458,7 +472,7 @@ class CI_Loader { */ function language($file = '', $lang = '', $return = FALSE) { - if ($this->_ci_use_instance) + if ($this->_ci_use_instance()) { $CI =& get_instance(); return $CI->lang->load($file, $lang, $return); @@ -480,7 +494,7 @@ class CI_Loader { */ function config($file = '') { - if ($this->_ci_use_instance) + if ($this->_ci_use_instance()) { $CI =& get_instance(); $CI->config->load($file); @@ -515,7 +529,7 @@ class CI_Loader { show_error('You must include the name of the table you would like access when you initialize scaffolding'); } - if ($this->_ci_use_instance) + if ($this->_ci_use_instance()) { $CI =& get_instance(); $CI->_ci_scaffolding = TRUE; @@ -545,7 +559,7 @@ class CI_Loader { // to become accessible from within the Controller and Model functions. // Only needed when running PHP 5 - if ($this->_ci_use_instance) + if ($this->_ci_use_instance()) { $CI =& get_instance(); foreach (get_object_vars($CI) as $key => $var) @@ -627,7 +641,7 @@ class CI_Loader { * In order to permit views to be nested within * other views, we need to flush the content back out whenever * we are beyond the first level of output buffering so that - * it can be seen and included properly by the first included + * it can be seen and included properly by the first included * template and any subsequent ones. Oy! * */ @@ -637,6 +651,7 @@ class CI_Loader { } else { + // PHP 4 requires that we use a global global $OUT; $OUT->set_output(ob_get_contents()); ob_end_clean(); @@ -745,7 +760,7 @@ class CI_Loader { } // Instantiate the class - if ($this->_ci_use_instance) + if ($this->_ci_use_instance()) { $CI =& get_instance(); if ($config !== NULL) @@ -794,7 +809,7 @@ class CI_Loader { // Load any custome config file if (count($autoload['config']) > 0) { - if ($this->_ci_use_instance) + if ($this->_ci_use_instance()) { $CI =& get_instance(); foreach ($autoload['config'] as $key => $val) @@ -867,7 +882,7 @@ class CI_Loader { * Makes sure that anything loaded by the loader class (libraries, plugins, etc.) * will be available to modles, if any exist. * - * @access public + * @access private * @param object * @return array */ @@ -878,7 +893,7 @@ class CI_Loader { return; } - if ($this->_ci_use_instance) + if ($this->_ci_use_instance()) { $CI =& get_instance(); foreach ($this->_ci_models as $model) @@ -902,7 +917,7 @@ class CI_Loader { * * Takes an object as input and convers the class variables to array key/vals * - * @access public + * @access private * @param object * @return array */ @@ -911,6 +926,24 @@ class CI_Loader { return (is_object($object)) ? get_object_vars($object) : $object; } + // -------------------------------------------------------------------- + + /** + * Determines whether we should use the CI instance or $this + * + * @access private + * @return bool + */ + function _ci_use_instance() + { + if ($this->_ci_is_php5 == TRUE) + { + return TRUE; + } + + global $CI; + return (is_object($CI)) ? TRUE : FALSE; + } } ?> \ No newline at end of file -- cgit v1.2.3-24-g4f1b From 1e3039878265b09e85f14e6b5ad3fbb6d4aa24c3 Mon Sep 17 00:00:00 2001 From: admin Date: Tue, 10 Oct 2006 16:35:43 +0000 Subject: --- system/libraries/Loader.php | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) (limited to 'system') diff --git a/system/libraries/Loader.php b/system/libraries/Loader.php index 43d1cbecb..96ec0c919 100644 --- a/system/libraries/Loader.php +++ b/system/libraries/Loader.php @@ -32,7 +32,7 @@ class CI_Loader { var $_ci_ob_level; var $_ci_view_path = ''; var $_ci_is_php5 = FALSE; - var $_ci_use_instance = FALSE; // Whether we should use $this or $CI =& get_instance() + var $_ci_is_instance = FALSE; // Whether we should use $this or $CI =& get_instance() var $_ci_cached_vars = array(); var $_ci_models = array(); var $_ci_helpers = array(); @@ -119,7 +119,7 @@ class CI_Loader { return; } - if ($this->_ci_use_instance()) + if ($this->_ci_is_instance()) { $CI =& get_instance(); if (isset($CI->$name)) @@ -147,7 +147,7 @@ class CI_Loader { if ($db_conn === TRUE) $db_conn = ''; - if ($this->_ci_use_instance()) + if ($this->_ci_is_instance()) { $CI->load->database($db_conn, FALSE, TRUE); } @@ -166,7 +166,7 @@ class CI_Loader { $model = ucfirst($model); - if ($this->_ci_use_instance()) + if ($this->_ci_is_instance()) { $CI->$name = new $model(); foreach (get_object_vars($CI) as $key => $var) @@ -472,7 +472,7 @@ class CI_Loader { */ function language($file = '', $lang = '', $return = FALSE) { - if ($this->_ci_use_instance()) + if ($this->_ci_is_instance()) { $CI =& get_instance(); return $CI->lang->load($file, $lang, $return); @@ -494,7 +494,7 @@ class CI_Loader { */ function config($file = '') { - if ($this->_ci_use_instance()) + if ($this->_ci_is_instance()) { $CI =& get_instance(); $CI->config->load($file); @@ -529,7 +529,7 @@ class CI_Loader { show_error('You must include the name of the table you would like access when you initialize scaffolding'); } - if ($this->_ci_use_instance()) + if ($this->_ci_is_instance()) { $CI =& get_instance(); $CI->_ci_scaffolding = TRUE; @@ -559,7 +559,7 @@ class CI_Loader { // to become accessible from within the Controller and Model functions. // Only needed when running PHP 5 - if ($this->_ci_use_instance()) + if ($this->_ci_is_instance()) { $CI =& get_instance(); foreach (get_object_vars($CI) as $key => $var) @@ -760,7 +760,7 @@ class CI_Loader { } // Instantiate the class - if ($this->_ci_use_instance()) + if ($this->_ci_is_instance()) { $CI =& get_instance(); if ($config !== NULL) @@ -809,7 +809,7 @@ class CI_Loader { // Load any custome config file if (count($autoload['config']) > 0) { - if ($this->_ci_use_instance()) + if ($this->_ci_is_instance()) { $CI =& get_instance(); foreach ($autoload['config'] as $key => $val) @@ -893,7 +893,7 @@ class CI_Loader { return; } - if ($this->_ci_use_instance()) + if ($this->_ci_is_instance()) { $CI =& get_instance(); foreach ($this->_ci_models as $model) @@ -934,7 +934,7 @@ class CI_Loader { * @access private * @return bool */ - function _ci_use_instance() + function _ci_is_instance() { if ($this->_ci_is_php5 == TRUE) { -- cgit v1.2.3-24-g4f1b From 7099a589d1719311427d7552523ec962ebc3b650 Mon Sep 17 00:00:00 2001 From: admin Date: Tue, 10 Oct 2006 17:47:59 +0000 Subject: --- system/codeigniter/Base4.php | 4 ++-- system/codeigniter/CodeIgniter.php | 20 ++++++++-------- system/codeigniter/Common.php | 28 ++++++++++++---------- system/database/DB_driver.php | 12 ++++++---- system/database/DB_utility.php | 3 ++- system/database/drivers/oci8/oci8_driver.php | 3 ++- .../database/drivers/postgre/postgre_utility.php | 2 +- system/libraries/Config.php | 2 +- system/libraries/Controller.php | 2 +- system/libraries/Hooks.php | 2 +- system/libraries/Input.php | 5 ++-- system/libraries/Log.php | 2 +- system/libraries/Output.php | 4 ++-- system/libraries/Router.php | 2 +- system/libraries/URI.php | 2 +- 15 files changed, 52 insertions(+), 41 deletions(-) (limited to 'system') diff --git a/system/codeigniter/Base4.php b/system/codeigniter/Base4.php index 8b3dc92f3..9366b4588 100644 --- a/system/codeigniter/Base4.php +++ b/system/codeigniter/Base4.php @@ -21,8 +21,8 @@ * This file is used only when Code Igniter is being run under PHP 4. * * In order to allow CI to work under PHP 4 we had to make the Loader class - * the parent class of the Controller Base class. It's the only way we - * could enable functions like $this->load->library('email') to instantiate + * the parent of the Controller Base class. It's the only way we enabled + * enable functions like $this->load->library('email') to instantiate * classes that can then be used within controllers as $this->email->send() * * PHP 4 also has trouble referencing the CI super object within application diff --git a/system/codeigniter/CodeIgniter.php b/system/codeigniter/CodeIgniter.php index 63ae45864..611b1a621 100644 --- a/system/codeigniter/CodeIgniter.php +++ b/system/codeigniter/CodeIgniter.php @@ -50,7 +50,7 @@ set_magic_quotes_runtime(0); // Kill magic quotes * ------------------------------------------------------ */ -$BM =& _load_class('Benchmark'); +$BM =& load_class('Benchmark'); $BM->mark('total_execution_time_start'); $BM->mark('loading_time_base_clases_start'); @@ -60,7 +60,7 @@ $BM->mark('loading_time_base_clases_start'); * ------------------------------------------------------ */ -$EXT =& _load_class('Hooks'); +$EXT =& load_class('Hooks'); /* * ------------------------------------------------------ @@ -75,9 +75,9 @@ $EXT->_call_hook('pre_system'); * ------------------------------------------------------ */ -$CFG =& _load_class('Config'); -$RTR =& _load_class('Router'); -$OUT =& _load_class('Output'); +$CFG =& load_class('Config'); +$RTR =& load_class('Router'); +$OUT =& load_class('Output'); /* * ------------------------------------------------------ @@ -99,9 +99,9 @@ if ($EXT->_call_hook('cache_override') === FALSE) * ------------------------------------------------------ */ -$IN =& _load_class('Input'); -$URI =& _load_class('URI'); -$LANG =& _load_class('Language'); +$IN =& load_class('Input'); +$URI =& load_class('URI'); +$LANG =& load_class('Language'); /* * ------------------------------------------------------ @@ -116,7 +116,7 @@ $LANG =& _load_class('Language'); * */ -_load_class('Loader', FALSE); +load_class('Loader', FALSE); if (floor(phpversion()) < 5) { @@ -127,7 +127,7 @@ else require(BASEPATH.'codeigniter/Base5'.EXT); } -_load_class('Controller', FALSE); +load_class('Controller', FALSE); require(APPPATH.'controllers/'.$RTR->fetch_directory().$RTR->fetch_class().EXT); diff --git a/system/codeigniter/Common.php b/system/codeigniter/Common.php index a801c0821..8ac80d634 100644 --- a/system/codeigniter/Common.php +++ b/system/codeigniter/Common.php @@ -41,7 +41,7 @@ * @param bool optional flag that lets classes get loaded but not instantiated * @return object */ -function _load_class($class, $instantiate = TRUE) +function &load_class($class, $instantiate = TRUE) { static $objects = array(); @@ -55,7 +55,8 @@ function _load_class($class, $instantiate = TRUE) // which we don't need to load. We only instantiate it. if ($class == 'Instance') { - return $objects[$class] =& new $class(); + $objects[$class] =& new $class(); + return $objects[$class]; } // If the requested class does not exist in the application/libraries @@ -104,18 +105,21 @@ function _load_class($class, $instantiate = TRUE) if ($instantiate == FALSE) { - return $objects[$class] = TRUE; + $objects[$class] = TRUE; + return $objects[$class]; } if ($is_subclass == TRUE) { $name = 'MY_'.$class; - return $objects[$class] =& new $name(); + $objects[$class] =& new $name(); + return $objects[$class]; } $name = ($class != 'Controller') ? 'CI_'.$class : $class; - return $objects[$class] =& new $name(); + $objects[$class] =& new $name(); + return $objects[$class]; } /** @@ -124,7 +128,7 @@ function _load_class($class, $instantiate = TRUE) * @access private * @return array */ -function &_get_config() +function &get_config() { static $main_conf; @@ -162,7 +166,7 @@ function &_get_config() */ function show_error($message) { - $error =& _load_class('Exceptions'); + $error =& load_class('Exceptions'); echo $error->show_error('An Error Was Encountered', $message); exit; } @@ -180,7 +184,7 @@ function show_error($message) */ function show_404($page = '') { - $error =& _load_class('Exceptions'); + $error =& load_class('Exceptions'); $error->show_404($page); exit; } @@ -199,13 +203,13 @@ function log_message($level = 'error', $message, $php_error = FALSE) { static $LOG; - $config =& _get_config(); + $config = get_config(); if ($config['log_errors'] === FALSE) { return; } - $LOG =& _load_class('Log'); + $LOG =& load_class('Log'); $LOG->write_log($level, $message, $php_error); } @@ -238,7 +242,7 @@ function _exception_handler($severity, $message, $filepath, $line) return; } - $error =& _load_class('Exceptions'); + $error =& load_class('Exceptions'); // Should we display the error? // We'll get the current error_reporting level and add its bits @@ -250,7 +254,7 @@ function _exception_handler($severity, $message, $filepath, $line) } // Should we log the error? No? We're done... - $config =& _get_config(); + $config = get_config(); if ($config['log_errors'] === FALSE) { return; diff --git a/system/database/DB_driver.php b/system/database/DB_driver.php index c8a00b7b1..99c95a6f2 100644 --- a/system/database/DB_driver.php +++ b/system/database/DB_driver.php @@ -682,7 +682,8 @@ class CI_DB_driver { } } - return $this->data_cache['table_names'] =& $retval; + $this->data_cache['table_names'] = $retval; + return $this->data_cache['table_names']; } // -------------------------------------------------------------------- @@ -747,7 +748,8 @@ class CI_DB_driver { } } - return $this->data_cache['field_names'][$table] =& $retval; + $this->data_cache['field_names'][$table] = $retval; + return $this->data_cache['field_names'][$table]; } // -------------------------------------------------------------------- @@ -931,7 +933,8 @@ class CI_DB_driver { */ function cache_on() { - return $this->cache_on = TRUE; + $this->cache_on = TRUE; + return TRUE; } // -------------------------------------------------------------------- @@ -944,7 +947,8 @@ class CI_DB_driver { */ function cache_off() { - return $this->cache_on = FALSE; + $this->cache_on = FALSE; + return FALSE; } diff --git a/system/database/DB_utility.php b/system/database/DB_utility.php index c2c5f1fe0..51e43a7c8 100644 --- a/system/database/DB_utility.php +++ b/system/database/DB_utility.php @@ -110,7 +110,8 @@ class CI_DB_utility { } } - return $this->data_cache['db_names'] =& $dbs; + $this->data_cache['db_names'] = $dbs; + return $this->data_cache['db_names']; } // -------------------------------------------------------------------- diff --git a/system/database/drivers/oci8/oci8_driver.php b/system/database/drivers/oci8/oci8_driver.php index e83c640bd..794405a03 100644 --- a/system/database/drivers/oci8/oci8_driver.php +++ b/system/database/drivers/oci8/oci8_driver.php @@ -163,7 +163,8 @@ class CI_DB_oci8_driver extends CI_DB { */ function get_cursor() { - return $this->curs_id = ocinewcursor($this->conn_id); + $this->curs_id = ocinewcursor($this->conn_id); + return $this->curs_id; } // -------------------------------------------------------------------- diff --git a/system/database/drivers/postgre/postgre_utility.php b/system/database/drivers/postgre/postgre_utility.php index 0c265de16..b08b879d7 100644 --- a/system/database/drivers/postgre/postgre_utility.php +++ b/system/database/drivers/postgre/postgre_utility.php @@ -106,7 +106,7 @@ class CI_DB_postgre_utility extends CI_DB_utility { */ function _repair_table($table) { - return return FALSE; + return FALSE; } // -------------------------------------------------------------------- diff --git a/system/libraries/Config.php b/system/libraries/Config.php index 26770cc4f..82836b1f3 100644 --- a/system/libraries/Config.php +++ b/system/libraries/Config.php @@ -44,7 +44,7 @@ class CI_Config { */ function CI_Config() { - $this->config =& _get_config(); + $this->config = get_config(); log_message('debug', "Config Class Initialized"); } // END CI_Config() diff --git a/system/libraries/Controller.php b/system/libraries/Controller.php index 7a3f5e5d5..938c46e4c 100644 --- a/system/libraries/Controller.php +++ b/system/libraries/Controller.php @@ -73,7 +73,7 @@ class Controller extends CI_Base { foreach ($classes as $var => $class) { - $this->$var =& _load_class($class); + $this->$var =& load_class($class); } diff --git a/system/libraries/Hooks.php b/system/libraries/Hooks.php index 8767e10d0..e2d0500c0 100644 --- a/system/libraries/Hooks.php +++ b/system/libraries/Hooks.php @@ -53,7 +53,7 @@ class CI_Hooks { */ function _initialize() { - $CFG =& _load_class('Config'); + $CFG =& load_class('Config'); // If hooks are not enabled in the config file // there is nothing else to do diff --git a/system/libraries/Input.php b/system/libraries/Input.php index 0d3c87b49..72344e343 100644 --- a/system/libraries/Input.php +++ b/system/libraries/Input.php @@ -44,7 +44,7 @@ class CI_Input { { log_message('debug', "Input Class Initialized"); - $CFG =& _load_class('Config'); + $CFG =& load_class('Config'); $this->use_xss_clean = ($CFG->item('global_xss_filtering') === TRUE) ? TRUE : FALSE; $this->allow_get_array = ($CFG->item('enable_query_strings') === TRUE) ? TRUE : FALSE; $this->_sanitize_globals(); @@ -306,7 +306,8 @@ class CI_Input { if ($this->ip_address === FALSE) { - return $this->ip_address = '0.0.0.0'; + $this->ip_address = '0.0.0.0'; + return $this->ip_address; } if (strstr($this->ip_address, ',')) diff --git a/system/libraries/Log.php b/system/libraries/Log.php index eff7cb7fc..09538fa0b 100644 --- a/system/libraries/Log.php +++ b/system/libraries/Log.php @@ -42,7 +42,7 @@ class CI_Log { */ function CI_Log() { - $config =& _get_config(); + $config = get_config(); $this->log_path = ($config['log_path'] != '') ? $config['log_path'] : BASEPATH.'logs/'; diff --git a/system/libraries/Output.php b/system/libraries/Output.php index 507beab59..7e859453e 100644 --- a/system/libraries/Output.php +++ b/system/libraries/Output.php @@ -299,8 +299,8 @@ class CI_Output { */ function _display_cache(&$CFG, &$RTR) { - $CFG =& _load_class('Config'); - $RTR =& _load_class('Router'); + $CFG =& load_class('Config'); + $RTR =& load_class(('Router'); $cache_path = ($CFG->item('cache_path') == '') ? BASEPATH.'cache/' : $CFG->item('cache_path'); diff --git a/system/libraries/Router.php b/system/libraries/Router.php index 27e3c27cc..dab84883e 100644 --- a/system/libraries/Router.php +++ b/system/libraries/Router.php @@ -48,7 +48,7 @@ class CI_Router { */ function CI_Router() { - $this->config =& _load_class('Config'); + $this->config =& load_class('Config'); $this->_set_route_mapping(); log_message('debug', "Router Class Initialized"); } diff --git a/system/libraries/URI.php b/system/libraries/URI.php index 80b112660..fcf6afe4b 100644 --- a/system/libraries/URI.php +++ b/system/libraries/URI.php @@ -42,7 +42,7 @@ class CI_URI { */ function CI_URI() { - $this->router =& _load_class('Router'); + $this->router =& load_class('Router'); log_message('debug', "URI Class Initialized"); } -- cgit v1.2.3-24-g4f1b From 1b0ab4665720446eee6b03f864bb5576e6065a4a Mon Sep 17 00:00:00 2001 From: admin Date: Tue, 10 Oct 2006 23:30:21 +0000 Subject: --- system/database/DB_driver.php | 4 ++-- system/database/DB_utility.php | 8 ++++---- system/libraries/Output.php | 2 +- 3 files changed, 7 insertions(+), 7 deletions(-) (limited to 'system') diff --git a/system/database/DB_driver.php b/system/database/DB_driver.php index 99c95a6f2..6da645a38 100644 --- a/system/database/DB_driver.php +++ b/system/database/DB_driver.php @@ -960,13 +960,13 @@ class CI_DB_driver { * @access public * @return void */ - function cache_delete() + function cache_delete($segment_one = '', $segment_two = '') { if ( ! $this->_cache_init()) { return FALSE; } - return $this->CACHE->delete(); + return $this->CACHE->delete($segment_one, $segment_two); } // -------------------------------------------------------------------- diff --git a/system/database/DB_utility.php b/system/database/DB_utility.php index 51e43a7c8..13fcaa5c9 100644 --- a/system/database/DB_utility.php +++ b/system/database/DB_utility.php @@ -37,7 +37,7 @@ class CI_DB_utility { { // Assign the main database object to $this->db $CI =& get_instance(); - $this->CI =& $obj->db; + $this->db =& $CI->db; log_message('debug', "Database Utility Class Initialized"); } @@ -100,7 +100,7 @@ class CI_DB_utility { return $this->data_cache['db_names']; } - $query = $this->db->query($this->_list_database()); + $query = $this->db->query($this->_list_databases()); $dbs = array(); if ($query->num_rows() > 0) { @@ -147,7 +147,7 @@ class CI_DB_utility { function optimize_database() { $result = array(); - foreach ($this->list_tables() as $table_name) + foreach ($this->db->list_tables() as $table_name) { $sql = $this->_optimize_table($table_name); @@ -356,7 +356,7 @@ class CI_DB_utility { // If no table names were submitted we'll fetch the entire table list if (count($prefs['tables']) == 0) { - $prefs['tables'] = $this->list_tables(); + $prefs['tables'] = $this->db->list_tables(); } // ------------------------------------------------------ diff --git a/system/libraries/Output.php b/system/libraries/Output.php index 7e859453e..9c48bbb84 100644 --- a/system/libraries/Output.php +++ b/system/libraries/Output.php @@ -300,7 +300,7 @@ class CI_Output { function _display_cache(&$CFG, &$RTR) { $CFG =& load_class('Config'); - $RTR =& load_class(('Router'); + $RTR =& load_class('Router'); $cache_path = ($CFG->item('cache_path') == '') ? BASEPATH.'cache/' : $CFG->item('cache_path'); -- cgit v1.2.3-24-g4f1b From 19ec9b171508e590f8503cf8c1408d6729bad18d Mon Sep 17 00:00:00 2001 From: admin Date: Tue, 10 Oct 2006 23:57:08 +0000 Subject: --- system/application/config/autoload.php | 2 +- system/application/config/database.php | 18 +----------------- system/application/config/routes.php | 2 +- 3 files changed, 3 insertions(+), 19 deletions(-) (limited to 'system') diff --git a/system/application/config/autoload.php b/system/application/config/autoload.php index f3b30a410..06d8780c4 100644 --- a/system/application/config/autoload.php +++ b/system/application/config/autoload.php @@ -37,7 +37,7 @@ | $autoload['libraries'] = array('database', 'session', 'xmlrpc'); */ -$autoload['libraries'] = array('database'); +$autoload['libraries'] = array(); /* diff --git a/system/application/config/database.php b/system/application/config/database.php index c594ba896..32b23058e 100644 --- a/system/application/config/database.php +++ b/system/application/config/database.php @@ -41,23 +41,7 @@ $db['default']['active_r'] = TRUE; $db['default']['pconnect'] = TRUE; $db['default']['db_debug'] = TRUE; $db['default']['cache_on'] = FALSE; -$db['default']['cachedir'] = APPPATH.'db_cache/'; - - - -$db['test']['hostname'] = "localhost"; -$db['test']['username'] = "root"; -$db['test']['password'] = ""; -$db['test']['database'] = "exp4"; -$db['test']['dbdriver'] = "mysql"; -$db['test']['dbprefix'] = ""; -$db['test']['active_r'] = TRUE; -$db['test']['pconnect'] = FALSE; -$db['test']['db_debug'] = TRUE; - - - - +$db['default']['cachedir'] = ''; ?> \ No newline at end of file diff --git a/system/application/config/routes.php b/system/application/config/routes.php index 097037e31..8fa167803 100644 --- a/system/application/config/routes.php +++ b/system/application/config/routes.php @@ -40,7 +40,7 @@ */ $route['default_controller'] = "welcome"; -$route['scaffolding_trigger'] = "scaffolding"; +$route['scaffolding_trigger'] = ""; -- cgit v1.2.3-24-g4f1b From 2799120c10b8d2544dd71e37b3a48c1eaa834c48 Mon Sep 17 00:00:00 2001 From: admin Date: Wed, 11 Oct 2006 01:38:08 +0000 Subject: --- system/libraries/Table.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system') diff --git a/system/libraries/Table.php b/system/libraries/Table.php index 4771295a5..0f2c49d96 100644 --- a/system/libraries/Table.php +++ b/system/libraries/Table.php @@ -50,7 +50,7 @@ class CI_Table { */ function set_template($template) { - if ( ! is_array()) + if ( ! is_array($template)) { return FALSE; } -- cgit v1.2.3-24-g4f1b From 4003718f35247ef9b4a8d678389bda639677bac7 Mon Sep 17 00:00:00 2001 From: admin Date: Wed, 11 Oct 2006 19:16:58 +0000 Subject: --- system/codeigniter/Base4.php | 6 ++++-- system/database/DB_driver.php | 2 +- system/libraries/Controller.php | 3 +-- system/libraries/Table.php | 8 ++++++-- 4 files changed, 12 insertions(+), 7 deletions(-) (limited to 'system') diff --git a/system/codeigniter/Base4.php b/system/codeigniter/Base4.php index 9366b4588..2793317e7 100644 --- a/system/codeigniter/Base4.php +++ b/system/codeigniter/Base4.php @@ -21,7 +21,7 @@ * This file is used only when Code Igniter is being run under PHP 4. * * In order to allow CI to work under PHP 4 we had to make the Loader class - * the parent of the Controller Base class. It's the only way we enabled + * the parent of the Controller Base class. It's the only way we can * enable functions like $this->load->library('email') to instantiate * classes that can then be used within controllers as $this->email->send() * @@ -42,11 +42,13 @@ function CI_Base() { + // This allows syntax like $this->load->foo() to work parent::CI_Loader(); $this->load =& $this; + // This allows resources used within controller constructors to work global $OBJ; - $OBJ = $this->load; + $OBJ = $this->load; // Do NOT use a reference. } } diff --git a/system/database/DB_driver.php b/system/database/DB_driver.php index 6da645a38..22f91ed4c 100644 --- a/system/database/DB_driver.php +++ b/system/database/DB_driver.php @@ -400,7 +400,7 @@ class CI_DB_driver { $this->initialize(); } - return $this->_execute($sql, $this->conn_id); + return $this->_execute($sql); } // -------------------------------------------------------------------- diff --git a/system/libraries/Controller.php b/system/libraries/Controller.php index 938c46e4c..88ab46164 100644 --- a/system/libraries/Controller.php +++ b/system/libraries/Controller.php @@ -75,8 +75,7 @@ class Controller extends CI_Base { { $this->$var =& load_class($class); } - - + // In PHP 5 the Controller class is run as a discreet // class. In PHP 4 it extends the Controller if (floor(phpversion()) >= 5) diff --git a/system/libraries/Table.php b/system/libraries/Table.php index 0f2c49d96..61d04eef5 100644 --- a/system/libraries/Table.php +++ b/system/libraries/Table.php @@ -211,9 +211,13 @@ class CI_Table { } // Next blast through the result array and build out the rows - foreach ($query->result_array() as $row) + + if ($query->num_rows() > 0) { - $this->rows[] = $row; + foreach ($query->result_array() as $row) + { + $this->rows[] = $row; + } } } -- cgit v1.2.3-24-g4f1b From 4c1ab6c826c3f5c3158a38443c2d3c30203f0f5a Mon Sep 17 00:00:00 2001 From: admin Date: Wed, 11 Oct 2006 21:48:33 +0000 Subject: --- system/libraries/Router.php | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) (limited to 'system') diff --git a/system/libraries/Router.php b/system/libraries/Router.php index dab84883e..ead1439f6 100644 --- a/system/libraries/Router.php +++ b/system/libraries/Router.php @@ -366,24 +366,30 @@ class CI_Router { */ function _parse_request_uri() { - if (($request_uri = getenv('REQUEST_URI')) == '') + if ( ! isset($_SERVER['REQUEST_URI']) OR $_SERVER['REQUEST_URI'] == '') { return ''; } - $fc_path = FCPATH; + $request_uri = preg_replace("|/(.*)|", "\\1", str_replace("\\", "/", $_SERVER['REQUEST_URI'])); + + if ($request_uri == '') + { + return ''; + } + $fc_path = FCPATH; if (strpos($request_uri, '?') !== FALSE) { $fc_path .= '?'; } - $parsed_uri = explode("/", preg_replace("|/(.*)|", "\\1", str_replace("\\", "/", $request_uri))); - + $parsed_uri = explode("/", $request_uri); + $i = 0; foreach(explode("/", $fc_path) as $segment) { - if ($segment == $parsed_uri[$i]) + if (isset($parsed_uri[$i]) AND $segment == $parsed_uri[$i]) { $i++; } -- cgit v1.2.3-24-g4f1b From 606f99c043272f96f21911d89c21cd36c2ef59e4 Mon Sep 17 00:00:00 2001 From: admin Date: Wed, 11 Oct 2006 23:48:41 +0000 Subject: --- system/codeigniter/CodeIgniter.php | 2 +- system/database/DB_driver.php | 3 ++- system/database/DB_result.php | 6 +++--- system/database/drivers/mssql/mssql_result.php | 8 +++++++- system/database/drivers/mysql/mysql_result.php | 8 +++++++- system/database/drivers/mysqli/mysqli_result.php | 8 +++++++- system/database/drivers/oci8/oci8_result.php | 8 +++++++- system/database/drivers/odbc/odbc_result.php | 8 +++++++- system/database/drivers/postgre/postgre_result.php | 8 +++++++- system/database/drivers/sqlite/sqlite_result.php | 8 +++++++- system/libraries/Loader.php | 11 +++-------- system/libraries/Table.php | 4 ++-- 12 files changed, 60 insertions(+), 22 deletions(-) (limited to 'system') diff --git a/system/codeigniter/CodeIgniter.php b/system/codeigniter/CodeIgniter.php index 611b1a621..49347715f 100644 --- a/system/codeigniter/CodeIgniter.php +++ b/system/codeigniter/CodeIgniter.php @@ -241,7 +241,7 @@ $EXT->_call_hook('post_system'); /* * ------------------------------------------------------ - * Close the DB connection of one exists + * Close the DB connection if one exists * ------------------------------------------------------ */ if (class_exists('CI_DB')) diff --git a/system/database/DB_driver.php b/system/database/DB_driver.php index 22f91ed4c..a4131fd73 100644 --- a/system/database/DB_driver.php +++ b/system/database/DB_driver.php @@ -172,6 +172,7 @@ class CI_DB_driver { $CI =& get_instance(); $CI->dbutil = new $class(); + $CI->_ci_assign_to_models(); } // -------------------------------------------------------------------- @@ -629,7 +630,7 @@ class CI_DB_driver { */ function primary($table = '') { - $fields = $this->field_names($table); + $fields = $this->list_fields($table); if ( ! is_array($fields)) { diff --git a/system/database/DB_result.php b/system/database/DB_result.php index 1c8ad6be0..b163bb5ea 100644 --- a/system/database/DB_result.php +++ b/system/database/DB_result.php @@ -261,14 +261,14 @@ class CI_DB_result { */ function num_rows() { return $this->num_rows; } function num_fields() { return 0; } - function field_names() { return array(); } + function list_fields() { return array(); } + function field_names() { return array(); } // Deprecated function field_data() { return array(); } function free_result() { return TRUE; } function _data_seek() { return TRUE; } function _fetch_assoc() { return array(); } function _fetch_object() { return array(); } - - + } // END DB_result class ?> \ No newline at end of file diff --git a/system/database/drivers/mssql/mssql_result.php b/system/database/drivers/mssql/mssql_result.php index 498deae09..0ba0b8c57 100644 --- a/system/database/drivers/mssql/mssql_result.php +++ b/system/database/drivers/mssql/mssql_result.php @@ -60,7 +60,7 @@ class CI_DB_mssql_result extends CI_DB_result { * @access public * @return array */ - function field_names() + function list_fields() { $field_names = array(); while ($field = mssql_fetch_field($this->result_id)) @@ -70,6 +70,12 @@ class CI_DB_mssql_result extends CI_DB_result { return $field_names; } + + // Deprecated + function field_names() + { + return $this->list_fields(); + } // -------------------------------------------------------------------- diff --git a/system/database/drivers/mysql/mysql_result.php b/system/database/drivers/mysql/mysql_result.php index 3fdfc8183..1cf6ff188 100644 --- a/system/database/drivers/mysql/mysql_result.php +++ b/system/database/drivers/mysql/mysql_result.php @@ -60,7 +60,7 @@ class CI_DB_mysql_result extends CI_DB_result { * @access public * @return array */ - function field_names() + function list_fields() { $field_names = array(); while ($field = mysql_fetch_field($this->result_id)) @@ -70,6 +70,12 @@ class CI_DB_mysql_result extends CI_DB_result { return $field_names; } + + // Deprecated + function field_names() + { + return $this->list_fields(); + } // -------------------------------------------------------------------- diff --git a/system/database/drivers/mysqli/mysqli_result.php b/system/database/drivers/mysqli/mysqli_result.php index 08db13f10..215403e9d 100644 --- a/system/database/drivers/mysqli/mysqli_result.php +++ b/system/database/drivers/mysqli/mysqli_result.php @@ -60,7 +60,7 @@ class CI_DB_mysqli_result extends CI_DB_result { * @access public * @return array */ - function field_names() + function list_fields() { $field_names = array(); while ($field = mysql_fetch_field($this->result_id)) @@ -71,6 +71,12 @@ class CI_DB_mysqli_result extends CI_DB_result { return $field_names; } + // Deprecated + function field_names() + { + return $this->list_fields(); + } + // -------------------------------------------------------------------- /** diff --git a/system/database/drivers/oci8/oci8_result.php b/system/database/drivers/oci8/oci8_result.php index a3da80026..ab13a3935 100644 --- a/system/database/drivers/oci8/oci8_result.php +++ b/system/database/drivers/oci8/oci8_result.php @@ -84,7 +84,7 @@ class CI_DB_oci8_result extends CI_DB_result { * @access public * @return array */ - function field_names() + function list_fields() { $field_names = array(); $fieldCount = $this->num_fields(); @@ -95,6 +95,12 @@ class CI_DB_oci8_result extends CI_DB_result { return $field_names; } + // Deprecated + function field_names() + { + return $this->list_fields(); + } + // -------------------------------------------------------------------- /** diff --git a/system/database/drivers/odbc/odbc_result.php b/system/database/drivers/odbc/odbc_result.php index 9204d8680..ea834f9b4 100644 --- a/system/database/drivers/odbc/odbc_result.php +++ b/system/database/drivers/odbc/odbc_result.php @@ -60,7 +60,7 @@ class CI_DB_odbc_result extends CI_DB_result { * @access public * @return array */ - function field_names() + function list_fields() { $field_names = array(); for ($i = 0; $i < $this->num_fields(); $i++) @@ -71,6 +71,12 @@ class CI_DB_odbc_result extends CI_DB_result { return $field_names; } + // Deprecated + function field_names() + { + return $this->list_fields(); + } + // -------------------------------------------------------------------- /** diff --git a/system/database/drivers/postgre/postgre_result.php b/system/database/drivers/postgre/postgre_result.php index 8c25c5d4c..e792544ae 100644 --- a/system/database/drivers/postgre/postgre_result.php +++ b/system/database/drivers/postgre/postgre_result.php @@ -60,7 +60,7 @@ class CI_DB_postgre_result extends CI_DB_result { * @access public * @return array */ - function field_names() + function list_fields() { $field_names = array(); for ($i = 0; $i < $this->num_fields(); $i++) @@ -71,6 +71,12 @@ class CI_DB_postgre_result extends CI_DB_result { return $field_names; } + // Deprecated + function field_names() + { + return $this->list_fields(); + } + // -------------------------------------------------------------------- /** diff --git a/system/database/drivers/sqlite/sqlite_result.php b/system/database/drivers/sqlite/sqlite_result.php index a3e94b471..55364bb24 100644 --- a/system/database/drivers/sqlite/sqlite_result.php +++ b/system/database/drivers/sqlite/sqlite_result.php @@ -60,7 +60,7 @@ class CI_DB_sqlite_result extends CI_DB_result { * @access public * @return array */ - function field_names() + function list_fields() { $field_names = array(); for ($i = 0; $i < $this->num_fields(); $i++) @@ -71,6 +71,12 @@ class CI_DB_sqlite_result extends CI_DB_result { return $field_names; } + // Deprecated + function field_names() + { + return $this->list_fields(); + } + // -------------------------------------------------------------------- /** diff --git a/system/libraries/Loader.php b/system/libraries/Loader.php index 96ec0c919..7a6637ac0 100644 --- a/system/libraries/Loader.php +++ b/system/libraries/Loader.php @@ -171,10 +171,7 @@ class CI_Loader { $CI->$name = new $model(); foreach (get_object_vars($CI) as $key => $var) { - if ( ! isset($CI->$name->$key)) - { - $CI->$name->$key =& $CI->$key; - } + $CI->$name->$key =& $CI->$key; } } else @@ -182,14 +179,12 @@ class CI_Loader { $this->$name = new $model(); foreach (get_object_vars($this) as $key => $var) { - if ( ! isset($this->$name->$key)) - { - $this->$name->$key =& $CI->$key; - } + $this->$name->$key =& $this->$key; } } $this->_ci_models[] = $name; + $this->_ci_assign_to_models(); } diff --git a/system/libraries/Table.php b/system/libraries/Table.php index 61d04eef5..758676e27 100644 --- a/system/libraries/Table.php +++ b/system/libraries/Table.php @@ -202,12 +202,12 @@ class CI_Table { // First generate the headings from the table column names if (count($this->heading) == 0) { - if ( ! method_exists($query, 'field_names')) + if ( ! method_exists($query, 'list_fields')) { return FALSE; } - $this->heading = $query->field_names(); + $this->heading = $query->list_fields(); } // Next blast through the result array and build out the rows -- cgit v1.2.3-24-g4f1b From 0aef222d246da84c90e9a89f31f6677cbe6b4ddc Mon Sep 17 00:00:00 2001 From: admin Date: Thu, 12 Oct 2006 18:00:22 +0000 Subject: --- system/database/DB.php | 19 +---- system/database/DB_driver.php | 19 ----- system/libraries/Controller.php | 2 +- system/libraries/Loader.php | 173 ++++++++++++++-------------------------- system/libraries/Model.php | 28 ++----- 5 files changed, 74 insertions(+), 167 deletions(-) (limited to 'system') diff --git a/system/database/DB.php b/system/database/DB.php index 62237440f..a148c9ffe 100644 --- a/system/database/DB.php +++ b/system/database/DB.php @@ -22,14 +22,8 @@ * @author Rick Ellis * @link http://www.codeigniter.com/user_guide/database/ */ -function DB($params = '', $return = FALSE, $active_record = FALSE) +function DB($params = '', $active_record = FALSE) { - // Do we even need to load the database class? - if (class_exists('CI_DB') AND $return == FALSE AND $active_record == FALSE) - { - return FALSE; - } - // Load the DB config file if a DSN string wasn't passed if (is_string($params) AND strpos($params, '://') === FALSE) { @@ -84,15 +78,8 @@ function DB($params = '', $return = FALSE, $active_record = FALSE) // Instantiate the DB adapter $driver = 'CI_DB_'.$params['dbdriver'].'_driver'; - $DB = new $driver($params); - - if ($return === TRUE) - { - return $DB; - } - - $CI =& get_instance(); - $CI->db =& $DB; + $DB = new $driver($params); + return $DB; } diff --git a/system/database/DB_driver.php b/system/database/DB_driver.php index a4131fd73..848d4f1c6 100644 --- a/system/database/DB_driver.php +++ b/system/database/DB_driver.php @@ -155,26 +155,7 @@ class CI_DB_driver { } } } - - // -------------------------------------------------------------------- - - /** - * Load the Utilities Class - * - * @access public - * @return string - */ - function load_utilities() - { - require_once(BASEPATH.'database/DB_utility'.EXT); - require_once(BASEPATH.'database/drivers/'.$this->dbdriver.'/'.$this->dbdriver.'_utility'.EXT); - $class = 'CI_DB_'.$this->dbdriver.'_utility'; - $CI =& get_instance(); - $CI->dbutil = new $class(); - $CI->_ci_assign_to_models(); - } - // -------------------------------------------------------------------- /** diff --git a/system/libraries/Controller.php b/system/libraries/Controller.php index 88ab46164..0bbc7773e 100644 --- a/system/libraries/Controller.php +++ b/system/libraries/Controller.php @@ -88,7 +88,7 @@ class Controller extends CI_Base { $this->_ci_autoloader(); } } - + // -------------------------------------------------------------------- /** diff --git a/system/libraries/Loader.php b/system/libraries/Loader.php index 7a6637ac0..1f6a8bce1 100644 --- a/system/libraries/Loader.php +++ b/system/libraries/Loader.php @@ -119,20 +119,10 @@ class CI_Loader { return; } - if ($this->_ci_is_instance()) - { - $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); - } - } - else + $CI =& get_instance(); + if (isset($CI->$name)) { - if (isset($this->$name)) - { - show_error('The model name you are loading is the name of a resource that is already being used: '.$name); - } + show_error('The model name you are loading is the name of a resource that is already being used: '.$name); } $model = strtolower($model); @@ -147,14 +137,7 @@ class CI_Loader { if ($db_conn === TRUE) $db_conn = ''; - if ($this->_ci_is_instance()) - { - $CI->load->database($db_conn, FALSE, TRUE); - } - else - { - $this->database($db_conn, FALSE, TRUE); - } + $CI->load->database($db_conn, FALSE, TRUE); } if ( ! class_exists('Model')) @@ -166,28 +149,12 @@ class CI_Loader { $model = ucfirst($model); - if ($this->_ci_is_instance()) - { - $CI->$name = new $model(); - foreach (get_object_vars($CI) as $key => $var) - { - $CI->$name->$key =& $CI->$key; - } - } - else - { - $this->$name = new $model(); - foreach (get_object_vars($this) as $key => $var) - { - $this->$name->$key =& $this->$key; - } - } + $CI->$name = new $model(); + $CI->$name->_assign_libraries(); - $this->_ci_models[] = $name; - $this->_ci_assign_to_models(); + $this->_ci_models[] = $name; } - - + // -------------------------------------------------------------------- /** @@ -201,19 +168,49 @@ class CI_Loader { */ function database($params = '', $return = FALSE, $active_record = FALSE) { + // Do we even need to load the database class? + if (class_exists('CI_DB') AND $return == FALSE AND $active_record == FALSE) + { + return FALSE; + } + require_once(BASEPATH.'database/DB'.EXT); if ($return === TRUE) { - return DB($params, $return, $active_record); + return DB($params, $active_record); } - else + + $CI =& get_instance(); + $CI->db =& DB($params, $active_record); + $this->_ci_assign_to_models(); + } + + // -------------------------------------------------------------------- + + /** + * Load the Utilities Class + * + * @access public + * @return string + */ + function dbutil() + { + if ( ! class_exists('CI_DB')) { - DB($params, $return, $active_record); - $this->_ci_assign_to_models(); + $this->database(); } - } + $CI =& get_instance(); + + require_once(BASEPATH.'database/DB_utility'.EXT); + require_once(BASEPATH.'database/drivers/'.$CI->db->dbdriver.'/'.$CI->db->dbdriver.'_utility'.EXT); + $class = 'CI_DB_'.$CI->db->dbdriver.'_utility'; + + $CI->dbutil = new $class(); + $CI->load->_ci_assign_to_models(); + } + // -------------------------------------------------------------------- /** @@ -467,15 +464,8 @@ class CI_Loader { */ function language($file = '', $lang = '', $return = FALSE) { - if ($this->_ci_is_instance()) - { - $CI =& get_instance(); - return $CI->lang->load($file, $lang, $return); - } - else - { - return $this->lang->load($file, $lang, $return); - } + $CI =& get_instance(); + return $CI->lang->load($file, $lang, $return); } // -------------------------------------------------------------------- @@ -489,15 +479,8 @@ class CI_Loader { */ function config($file = '') { - if ($this->_ci_is_instance()) - { - $CI =& get_instance(); - $CI->config->load($file); - } - else - { - $this->config->load($file); - } + $CI =& get_instance(); + $CI->config->load($file); } // -------------------------------------------------------------------- @@ -524,17 +507,9 @@ class CI_Loader { show_error('You must include the name of the table you would like access when you initialize scaffolding'); } - if ($this->_ci_is_instance()) - { - $CI =& get_instance(); - $CI->_ci_scaffolding = TRUE; - $CI->_ci_scaff_table = $table; - } - else - { - $this->_ci_scaffolding = TRUE; - $this->_ci_scaff_table = $table; - } + $CI =& get_instance(); + $CI->_ci_scaffolding = TRUE; + $CI->_ci_scaff_table = $table; } // -------------------------------------------------------------------- @@ -755,29 +730,15 @@ class CI_Loader { } // Instantiate the class - if ($this->_ci_is_instance()) + $CI =& get_instance(); + if ($config !== NULL) { - $CI =& get_instance(); - if ($config !== NULL) - { - $CI->$classvar = new $name($config); - } - else - { - $CI->$classvar = new $name; - } + $CI->$classvar = new $name($config); } else - { - if ($config !== NULL) - { - $this->$classvar = new $name($config); - } - else - { - $this->$classvar = new $name; - } - } + { + $CI->$classvar = new $name; + } } // -------------------------------------------------------------------- @@ -804,20 +765,10 @@ class CI_Loader { // Load any custome config file if (count($autoload['config']) > 0) { - if ($this->_ci_is_instance()) - { - $CI =& get_instance(); - foreach ($autoload['config'] as $key => $val) - { - $CI->config->load($val); - } - } - else + $CI =& get_instance(); + foreach ($autoload['config'] as $key => $val) { - foreach ($autoload['config'] as $key => $val) - { - $this->config->load($val); - } + $CI->config->load($val); } } @@ -893,14 +844,14 @@ class CI_Loader { $CI =& get_instance(); foreach ($this->_ci_models as $model) { - $CI->$model->_assign_libraries(); + $CI->$model->_assign_libraries(); } } else - { + { foreach ($this->_ci_models as $model) { - $this->$model->_assign_libraries(); + $this->$model->_assign_libraries(); } } } diff --git a/system/libraries/Model.php b/system/libraries/Model.php index 48615e07c..017a9c6d8 100644 --- a/system/libraries/Model.php +++ b/system/libraries/Model.php @@ -33,10 +33,9 @@ class Model { */ function Model() { - $this->_assign_libraries(FALSE); + $this->_assign_libraries(); log_message('debug', "Model Class Initialized"); } - // END Model() /** * Assign Libraries @@ -47,26 +46,15 @@ class Model { * * @access private */ - function _assign_libraries($use_reference = TRUE) + function _assign_libraries() { - $CI =& get_instance(); - foreach (get_object_vars($CI) as $key => $var) - { - if ( ! isset($this->$key)) - { - if ($use_reference === TRUE) - { - $this->$key =& $CI->$key; - } - else - { - $this->$key = $CI->$key; - } - } - } - + $CI =& get_instance(); + + foreach (array_keys(get_object_vars($CI)) as $key) + { + $this->$key =& $CI->$key; + } } - // END _assign_libraries() } // END Model Class -- cgit v1.2.3-24-g4f1b From 9fa003797d794a63aa58356926fac9649269c668 Mon Sep 17 00:00:00 2001 From: admin Date: Thu, 12 Oct 2006 18:20:13 +0000 Subject: --- system/libraries/Encrypt.php | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'system') diff --git a/system/libraries/Encrypt.php b/system/libraries/Encrypt.php index 50b3fab39..b7dba2523 100644 --- a/system/libraries/Encrypt.php +++ b/system/libraries/Encrypt.php @@ -272,15 +272,15 @@ class CI_Encrypt { // -------------------------------------------------------------------- /** - * Set the Mcrypt Cypher + * Set the Mcrypt Cipher * * @access public * @param constant * @return string */ - function set_cypher($cypher) + function set_cipher($cipher) { - $this->_mcrypt_cipher = $cypher; + $this->_mcrypt_cipher = $cipher; } // -------------------------------------------------------------------- @@ -300,12 +300,12 @@ class CI_Encrypt { // -------------------------------------------------------------------- /** - * Get Mcrypt Cypher Value + * Get Mcrypt cipher Value * * @access private * @return string */ - function _get_cypher() + function _get_cipher() { if ($this->_mcrypt_cipher == '') { -- cgit v1.2.3-24-g4f1b From 80b2bd9b7f1ecafed0d0170be60bd0a2d8a4201c Mon Sep 17 00:00:00 2001 From: admin Date: Thu, 12 Oct 2006 18:30:36 +0000 Subject: --- system/libraries/Loader.php | 36 ++++++++++++++++-------------------- 1 file changed, 16 insertions(+), 20 deletions(-) (limited to 'system') diff --git a/system/libraries/Loader.php b/system/libraries/Loader.php index 1f6a8bce1..2d312e9eb 100644 --- a/system/libraries/Loader.php +++ b/system/libraries/Loader.php @@ -67,15 +67,15 @@ class CI_Loader { * * @access public * @param string the name of the class - * @param sring the optional class variable name to assign the library to + * @param mixed the optional parameters * @return void */ - function library($class, $varname = NULL) + function library($class, $params = FALSE) { if ($class == '') return; - $this->_ci_load_class($class, $varname); + $this->_ci_load_class($class, $params); $this->_ci_assign_to_models(); } @@ -640,7 +640,7 @@ class CI_Loader { * @param mixed any additional parameters * @return void */ - function _ci_load_class($class, $varname = NULL) + function _ci_load_class($class, $params = FALSE) { // Prep the class name $class = strtolower(str_replace(EXT, '', $class)); @@ -665,7 +665,7 @@ class CI_Loader { } } - return $this->_ci_init_class($filename, 'MY_', $varname); + return $this->_ci_init_class($filename, 'MY_', $params); } // Lets search for the requested library file and load it. @@ -680,7 +680,7 @@ class CI_Loader { if (file_exists($path.'libraries/'.$filename.EXT)) { include_once($path.'libraries/'.$filename.EXT); - return $this->_ci_init_class($filename, '', $varname); + return $this->_ci_init_class($filename, '', $params); } } } @@ -700,13 +700,16 @@ class CI_Loader { * @param string * @return null */ - function _ci_init_class($class, $prefix = '', $varname = NULL) + function _ci_init_class($class, $prefix = '', $config = FALSE) { // Is there an associated config file for this class? - $config = NULL; - if (file_exists(APPPATH.'config/'.$class.EXT)) + if ($config !== FALSE) { - include_once(APPPATH.'config/'.$class.EXT); + $config = FALSE; + if (file_exists(APPPATH.'config/'.$class.EXT)) + { + include_once(APPPATH.'config/'.$class.EXT); + } } if ($prefix == '') @@ -719,16 +722,9 @@ class CI_Loader { } // Set the variable name we will assign the class to - if ( ! is_null($varname)) - { - $classvar = $varname; - } - else - { - $class = strtolower($class); - $classvar = ( ! isset($this->_ci_varmap[$class])) ? $class : $this->_ci_varmap[$class]; - } - + $class = strtolower($class); + $classvar = ( ! isset($this->_ci_varmap[$class])) ? $class : $this->_ci_varmap[$class]; + // Instantiate the class $CI =& get_instance(); if ($config !== NULL) -- cgit v1.2.3-24-g4f1b From f6615e650f7f871fbb4a2e0e1a75fd9afa2e3647 Mon Sep 17 00:00:00 2001 From: admin Date: Thu, 12 Oct 2006 19:16:57 +0000 Subject: --- system/libraries/Router.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system') diff --git a/system/libraries/Router.php b/system/libraries/Router.php index ead1439f6..bbfa0d192 100644 --- a/system/libraries/Router.php +++ b/system/libraries/Router.php @@ -373,7 +373,7 @@ class CI_Router { $request_uri = preg_replace("|/(.*)|", "\\1", str_replace("\\", "/", $_SERVER['REQUEST_URI'])); - if ($request_uri == '') + if ($request_uri == '' OR $request_uri == SELF) { return ''; } -- cgit v1.2.3-24-g4f1b From 5a14ea1599841bdaac15b45e3efd4cba01601f49 Mon Sep 17 00:00:00 2001 From: admin Date: Thu, 12 Oct 2006 20:42:55 +0000 Subject: --- system/codeigniter/CodeIgniter.php | 2 +- system/libraries/Loader.php | 10 +++++----- 2 files changed, 6 insertions(+), 6 deletions(-) (limited to 'system') diff --git a/system/codeigniter/CodeIgniter.php b/system/codeigniter/CodeIgniter.php index 49347715f..93c1dba5f 100644 --- a/system/codeigniter/CodeIgniter.php +++ b/system/codeigniter/CodeIgniter.php @@ -244,7 +244,7 @@ $EXT->_call_hook('post_system'); * Close the DB connection if one exists * ------------------------------------------------------ */ -if (class_exists('CI_DB')) +if (class_exists('CI_DB') AND isset($CI->db)) { $CI->db->close(); } diff --git a/system/libraries/Loader.php b/system/libraries/Loader.php index 2d312e9eb..7bf11609b 100644 --- a/system/libraries/Loader.php +++ b/system/libraries/Loader.php @@ -70,7 +70,7 @@ class CI_Loader { * @param mixed the optional parameters * @return void */ - function library($class, $params = FALSE) + function library($class, $params = NULL) { if ($class == '') return; @@ -640,7 +640,7 @@ class CI_Loader { * @param mixed any additional parameters * @return void */ - function _ci_load_class($class, $params = FALSE) + function _ci_load_class($class, $params = NULL) { // Prep the class name $class = strtolower(str_replace(EXT, '', $class)); @@ -700,12 +700,12 @@ class CI_Loader { * @param string * @return null */ - function _ci_init_class($class, $prefix = '', $config = FALSE) + function _ci_init_class($class, $prefix = '', $config = NULL) { // Is there an associated config file for this class? - if ($config !== FALSE) + if ($config !== NULL) { - $config = FALSE; + $config = NULL; if (file_exists(APPPATH.'config/'.$class.EXT)) { include_once(APPPATH.'config/'.$class.EXT); -- cgit v1.2.3-24-g4f1b From b06d69f03f5149877390d7e99882006a141268ff Mon Sep 17 00:00:00 2001 From: admin Date: Fri, 13 Oct 2006 21:44:17 +0000 Subject: --- system/codeigniter/Common.php | 4 ++-- system/libraries/Profiler.php | 15 +++++++++++++-- system/libraries/Session.php | 18 +++--------------- 3 files changed, 18 insertions(+), 19 deletions(-) (limited to 'system') diff --git a/system/codeigniter/Common.php b/system/codeigniter/Common.php index 8ac80d634..07b468fef 100644 --- a/system/codeigniter/Common.php +++ b/system/codeigniter/Common.php @@ -204,7 +204,7 @@ function log_message($level = 'error', $message, $php_error = FALSE) static $LOG; $config = get_config(); - if ($config['log_errors'] === FALSE) + if ($config['log_threshold'] == 0) { return; } @@ -255,7 +255,7 @@ function _exception_handler($severity, $message, $filepath, $line) // Should we log the error? No? We're done... $config = get_config(); - if ($config['log_errors'] === FALSE) + if ($config['log_threshold'] == 0) { return; } diff --git a/system/libraries/Profiler.php b/system/libraries/Profiler.php index 3370c9113..7fecabd21 100644 --- a/system/libraries/Profiler.php +++ b/system/libraries/Profiler.php @@ -94,7 +94,12 @@ class CI_Profiler { // -------------------------------------------------------------------- - + /** + * Compile Queries + * + * @access private + * @return string + */ function _compile_queries() { $output = "\n\n"; @@ -130,7 +135,13 @@ class CI_Profiler { } // -------------------------------------------------------------------- - + + /** + * Compile $_POST Data + * + * @access private + * @return string + */ function _compile_post() { $output = "\n\n"; diff --git a/system/libraries/Session.php b/system/libraries/Session.php index 16f373fd0..8390fd6d4 100644 --- a/system/libraries/Session.php +++ b/system/libraries/Session.php @@ -112,10 +112,8 @@ class CI_Session { } } - // Do we need encryption? - $this->encryption = $this->CI->config->item('sess_encrypt_cookie'); - - if ($this->encryption == TRUE) + // Do we need encryption? + if ($this->CI->config->item('sess_encrypt_cookie') == TRUE) { $this->CI->load->library('encrypt'); } @@ -160,7 +158,6 @@ class CI_Session { $this->sess_gc(); } } - // END sess_run() // -------------------------------------------------------------------- @@ -257,7 +254,6 @@ class CI_Session { return TRUE; } - // END sess_read() // -------------------------------------------------------------------- @@ -285,7 +281,6 @@ class CI_Session { 0 ); } - // END sess_read() // -------------------------------------------------------------------- @@ -321,7 +316,6 @@ class CI_Session { $this->userdata['last_visit'] = 0; $this->sess_write(); } - // END sess_read() // -------------------------------------------------------------------- @@ -349,7 +343,6 @@ class CI_Session { // Write the cookie $this->sess_write(); } - // END sess_update() // -------------------------------------------------------------------- @@ -370,7 +363,6 @@ class CI_Session { 0 ); } - // END sess_destroy() // -------------------------------------------------------------------- @@ -396,7 +388,6 @@ class CI_Session { log_message('debug', 'Session garbage collection performed.'); } } - // END sess_destroy() // -------------------------------------------------------------------- @@ -411,7 +402,6 @@ class CI_Session { { return ( ! isset($this->userdata[$item])) ? FALSE : $this->userdata[$item]; } - // END sess_destroy() // -------------------------------------------------------------------- @@ -440,7 +430,6 @@ class CI_Session { $this->sess_write(); } - // END set_userdata() // -------------------------------------------------------------------- @@ -467,7 +456,6 @@ class CI_Session { $this->sess_write(); } - // END set_userdata() // -------------------------------------------------------------------- @@ -494,7 +482,7 @@ class CI_Session { return $vals; } - // END strip_slashes() + } // END Session Class ?> \ No newline at end of file -- cgit v1.2.3-24-g4f1b From 9a661810d2b9b96c458c1f369f0059b31012b6a8 Mon Sep 17 00:00:00 2001 From: admin Date: Mon, 16 Oct 2006 19:02:48 +0000 Subject: --- system/database/DB.php | 4 ++-- system/database/drivers/mssql/mssql_utility.php | 2 +- system/database/drivers/oci8/oci8_utility.php | 2 +- system/database/drivers/sqlite/sqlite_utility.php | 2 +- system/libraries/Loader.php | 5 ++--- system/libraries/Router.php | 2 +- 6 files changed, 8 insertions(+), 9 deletions(-) (limited to 'system') diff --git a/system/database/DB.php b/system/database/DB.php index a148c9ffe..d2afce982 100644 --- a/system/database/DB.php +++ b/system/database/DB.php @@ -22,7 +22,7 @@ * @author Rick Ellis * @link http://www.codeigniter.com/user_guide/database/ */ -function DB($params = '', $active_record = FALSE) +function &DB($params = '', $active_record = FALSE) { // Load the DB config file if a DSN string wasn't passed if (is_string($params) AND strpos($params, '://') === FALSE) @@ -78,7 +78,7 @@ function DB($params = '', $active_record = FALSE) // Instantiate the DB adapter $driver = 'CI_DB_'.$params['dbdriver'].'_driver'; - $DB = new $driver($params); + $DB =& new $driver($params); return $DB; } diff --git a/system/database/drivers/mssql/mssql_utility.php b/system/database/drivers/mssql/mssql_utility.php index 129ba6861..24ff1e13c 100644 --- a/system/database/drivers/mssql/mssql_utility.php +++ b/system/database/drivers/mssql/mssql_utility.php @@ -106,7 +106,7 @@ class CI_DB_mssql_utility extends CI_DB_utility { */ function _repair_table($table) { - return return FALSE; // Is this supported in MS SQL? + return FALSE; // Is this supported in MS SQL? } // -------------------------------------------------------------------- diff --git a/system/database/drivers/oci8/oci8_utility.php b/system/database/drivers/oci8/oci8_utility.php index 96be09506..f4e912183 100644 --- a/system/database/drivers/oci8/oci8_utility.php +++ b/system/database/drivers/oci8/oci8_utility.php @@ -106,7 +106,7 @@ class CI_DB_oci8_utility extends CI_DB_utility { */ function _repair_table($table) { - return return FALSE; // Is this supported in Oracle? + return FALSE; // Is this supported in Oracle? } // -------------------------------------------------------------------- diff --git a/system/database/drivers/sqlite/sqlite_utility.php b/system/database/drivers/sqlite/sqlite_utility.php index 9cb2cf027..ecce5be40 100644 --- a/system/database/drivers/sqlite/sqlite_utility.php +++ b/system/database/drivers/sqlite/sqlite_utility.php @@ -131,7 +131,7 @@ class CI_DB_sqlite_utility extends CI_DB_utility { */ function _repair_table($table) { - return return FALSE; + return FALSE; } // -------------------------------------------------------------------- diff --git a/system/libraries/Loader.php b/system/libraries/Loader.php index 7bf11609b..b402464e2 100644 --- a/system/libraries/Loader.php +++ b/system/libraries/Loader.php @@ -703,9 +703,8 @@ class CI_Loader { function _ci_init_class($class, $prefix = '', $config = NULL) { // Is there an associated config file for this class? - if ($config !== NULL) - { - $config = NULL; + if ($config === NULL) + { if (file_exists(APPPATH.'config/'.$class.EXT)) { include_once(APPPATH.'config/'.$class.EXT); diff --git a/system/libraries/Router.php b/system/libraries/Router.php index bbfa0d192..06037209b 100644 --- a/system/libraries/Router.php +++ b/system/libraries/Router.php @@ -373,7 +373,7 @@ class CI_Router { $request_uri = preg_replace("|/(.*)|", "\\1", str_replace("\\", "/", $_SERVER['REQUEST_URI'])); - if ($request_uri == '' OR $request_uri == SELF) + if ($request_uri == '' OR $request_uri == $this->config->item('index_page')) { return ''; } -- cgit v1.2.3-24-g4f1b From 30578eadecee1b7fd96e82b17100bba5347d362e Mon Sep 17 00:00:00 2001 From: admin Date: Tue, 17 Oct 2006 02:31:06 +0000 Subject: --- system/libraries/Loader.php | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) (limited to 'system') diff --git a/system/libraries/Loader.php b/system/libraries/Loader.php index b402464e2..336caf7dd 100644 --- a/system/libraries/Loader.php +++ b/system/libraries/Loader.php @@ -592,8 +592,24 @@ class CI_Loader { } 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 (ini_get("short_open_tag") == 0) + { + $file = file_get_contents($path); + + $file = str_replace('/", " ;?>", $file); + + echo eval('?>'.$file.' Date: Tue, 17 Oct 2006 02:32:59 +0000 Subject: --- system/libraries/Loader.php | 1 - 1 file changed, 1 deletion(-) (limited to 'system') diff --git a/system/libraries/Loader.php b/system/libraries/Loader.php index 336caf7dd..ba98a642a 100644 --- a/system/libraries/Loader.php +++ b/system/libraries/Loader.php @@ -599,7 +599,6 @@ class CI_Loader { if (ini_get("short_open_tag") == 0) { $file = file_get_contents($path); - $file = str_replace('/", " ;?>", $file); -- cgit v1.2.3-24-g4f1b From 94fe038a62c5d535920464266ae404b5e028f662 Mon Sep 17 00:00:00 2001 From: admin Date: Tue, 17 Oct 2006 02:36:31 +0000 Subject: --- system/libraries/Loader.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'system') diff --git a/system/libraries/Loader.php b/system/libraries/Loader.php index ba98a642a..bc2e9dec7 100644 --- a/system/libraries/Loader.php +++ b/system/libraries/Loader.php @@ -599,8 +599,8 @@ class CI_Loader { if (ini_get("short_open_tag") == 0) { $file = file_get_contents($path); - $file = str_replace('/", " ;?>", $file); + $file = str_replace('/", ' ;?>', $file); echo eval('?>'.$file.' Date: Tue, 17 Oct 2006 03:40:51 +0000 Subject: --- system/libraries/Loader.php | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) (limited to 'system') diff --git a/system/libraries/Loader.php b/system/libraries/Loader.php index bc2e9dec7..4252f1633 100644 --- a/system/libraries/Loader.php +++ b/system/libraries/Loader.php @@ -596,13 +596,10 @@ class CI_Loader { // If the PHP installation does not support short tags we'll // do a little string replacement, changing the short tags // to standard PHP echo statements. - if (ini_get("short_open_tag") == 0) - { - $file = file_get_contents($path); - $file = str_replace('/", ' ;?>', $file); - echo eval('?>'.$file.''.preg_replace("/;*\s*\?>/", "; ?>", str_replace(' Date: Thu, 19 Oct 2006 16:38:23 +0000 Subject: --- system/application/config/config.php | 17 +++-------------- 1 file changed, 3 insertions(+), 14 deletions(-) (limited to 'system') diff --git a/system/application/config/config.php b/system/application/config/config.php index 31094f3b6..3f26d48fa 100644 --- a/system/application/config/config.php +++ b/system/application/config/config.php @@ -140,26 +140,15 @@ $config['function_trigger'] = 'm'; */ $config['time_reference'] = 'local'; -/* -|-------------------------------------------------------------------------- -| Enable/Disable Error Logging -|-------------------------------------------------------------------------- -| -| If you would like errors or debug messages logged set this variable to -| TRUE (boolean). Note: You must set the file permissions on the "logs" folder -| such that it is writable. -| -*/ -$config['log_errors'] = FALSE; - /* |-------------------------------------------------------------------------- | Error Logging Threshold |-------------------------------------------------------------------------- | -| If you have enabled error logging, you can set an error threshold to -| determine what gets logged. Threshold options are: +| You can enable error logging by setting a threshold over zero. The +| threshold determines what gets logged. Threshold options are: | +| 0 = Error logging TURNED OFF | 1 = Error Messages (including PHP errors) | 2 = Debug Messages | 3 = Informational Messages -- cgit v1.2.3-24-g4f1b From 3ba33e79963beaf0c177371d175003a9c9151e00 Mon Sep 17 00:00:00 2001 From: admin Date: Thu, 19 Oct 2006 16:40:03 +0000 Subject: --- system/libraries/Hooks.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system') diff --git a/system/libraries/Hooks.php b/system/libraries/Hooks.php index e2d0500c0..3c35c9088 100644 --- a/system/libraries/Hooks.php +++ b/system/libraries/Hooks.php @@ -39,8 +39,8 @@ class CI_Hooks { */ function CI_Hooks() { - log_message('debug', "Hooks Class Initialized"); $this->_initialize(); + log_message('debug', "Hooks Class Initialized"); } // -------------------------------------------------------------------- -- cgit v1.2.3-24-g4f1b From d54078fff55f74ee4fd320b27f8129b48bdcd3fa Mon Sep 17 00:00:00 2001 From: admin Date: Fri, 20 Oct 2006 00:38:16 +0000 Subject: --- system/helpers/typography_helper.php | 72 +++++++++++++++++++++++++++++------- 1 file changed, 58 insertions(+), 14 deletions(-) (limited to 'system') diff --git a/system/helpers/typography_helper.php b/system/helpers/typography_helper.php index 65924f911..84ca0ed6f 100644 --- a/system/helpers/typography_helper.php +++ b/system/helpers/typography_helper.php @@ -129,7 +129,7 @@ class Auto_typography { * * We don't want quotes converted within * tags so we'll temporarily convert them to - * {{{DQ}}} and {{{SQ}}} + * {@DQ} and {@SQ} * */ if (preg_match_all("#\<.+?>#si", $str, $matches)) @@ -137,11 +137,24 @@ class Auto_typography { for ($i = 0; $i < count($matches['0']); $i++) { $str = str_replace($matches['0'][$i], - str_replace(array("'",'"'), array('{{{SQ}}}', '{{{DQ}}}'), $matches['0'][$i]), + str_replace(array("'",'"'), array('{@SQ}', '{@DQ}'), $matches['0'][$i]), $str); } } - + + + /* + * Add closing/opening paragraph tags before/after "block" elements + * + * Since block elements (like ,
, etc.) do not get
+		 * wrapped in paragraph tags we will add a closing 

tag just before + * each block element starts and an opening

tag right after the block element + * ends. Later on we'll do some further clean up. + * + */ + $str = preg_replace("#(<.*?)(".$this->block_elements.")(.*?>)#", "

\\1\\2\\3", $str); + $str = preg_replace("#(block_elements.")(.*?>)#", "\\1\\2\\3

", $str); + /* * Convert "ignore" tags to tempoarary marker * @@ -149,10 +162,10 @@ class Auto_typography { * it encounters. Certain inline tags, like image * tags, links, span tags, etc. will be adversely * affected if they are split out so we'll convert - * the opening < temporarily to: {{{tag}}} + * the opening < temporarily to: {@TAG} * - */ - $str = preg_replace("#<(/*)(".$this->ignore_elements.")#i", "{{{tag}}}\\1\\2", $str); + */ + $str = preg_replace("#<(/*)(".$this->ignore_elements.")#i", "{@TAG}\\1\\2", $str); /* * Split the string at every tag @@ -188,7 +201,7 @@ class Auto_typography { * Well also set the "process" flag which allows us * to skip

 tags and a few other things.
 			 *
-			 */			
+			 */
 			if (preg_match("#<(/*)(".$this->block_elements.").*?\>#", $chunk, $match)) 
 			{
 				if (preg_match("#".$this->skip_elements."#", $match['2']))
@@ -210,20 +223,51 @@ class Auto_typography {
 			$str .= $this->format_newlines($chunk);
 		}
 
+
+		/*
+		 * Clean up paragraph tags before/after "block" elements
+		 *
+		 * Earlier we added 

tags before/after block level elements. + * Then, we added paragraph tags around double line breaks. This + * potentially created incorrectly formatted paragraphs so we'll + * clean it up here. + * + */ + $str = preg_replace("#

({@TAG}.*?)(".$this->block_elements.")(.*?>)#", "\\1\\2\\3", $str); + $str = preg_replace("#({@TAG}/.*?)(".$this->block_elements.")(.*?>)

#", "\\1\\2\\3", $str); + // Convert Quotes and other characters $str = $this->format_characters($str); - - // We'll swap our temporary markers back and do some clean up. + + // Final clean up $str = preg_replace('#(

\n*

)#', '', $str); $str = preg_replace('#()

#', "\\1", $str); - + $str = str_replace( - array('

', '

', '{{{tag}}}', '{{{DQ}}}', '{{{SQ}}}'), - array('

', '

', '<', '"', "'"), + array( + '

', + '

', + '

', + '

', + '{@TAG}', + '{@DQ}', + '{@SQ}', + '

' + ), + array( + '

', + '

', + '

', + '

', + '<', + '"', + "'", + '' + ), $str - ); + ); - return trim($str); + return $str; } // -------------------------------------------------------------------- -- cgit v1.2.3-24-g4f1b From f4c010098af532d9eb843743ef6bb8ed05689765 Mon Sep 17 00:00:00 2001 From: admin Date: Fri, 20 Oct 2006 00:53:22 +0000 Subject: --- system/helpers/typography_helper.php | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) (limited to 'system') diff --git a/system/helpers/typography_helper.php b/system/helpers/typography_helper.php index 84ca0ed6f..ba6804873 100644 --- a/system/helpers/typography_helper.php +++ b/system/helpers/typography_helper.php @@ -223,7 +223,9 @@ class Auto_typography { $str .= $this->format_newlines($chunk); } - + // FINAL CLEAN UP + // IMPORTANT: DO NOT ALTER THE ORDER OF THE ITEMS BELOW! + /* * Clean up paragraph tags before/after "block" elements * @@ -239,10 +241,14 @@ class Auto_typography { // Convert Quotes and other characters $str = $this->format_characters($str); - // Final clean up + // Fix an artifact that happens during the paragraph replacement $str = preg_replace('#(

\n*

)#', '', $str); + + // If the user submitted their own paragraph tags with class data + // in them we will retain them instead of using our tags. $str = preg_replace('#()

#', "\\1", $str); + // Final clean up $str = str_replace( array( '

', -- cgit v1.2.3-24-g4f1b From 90931313c2d8a90f84e3a62b59d9603f4ebe4127 Mon Sep 17 00:00:00 2001 From: admin Date: Fri, 20 Oct 2006 00:59:17 +0000 Subject: --- system/libraries/Router.php | 64 ++++++++++++++++++++------------------------- 1 file changed, 29 insertions(+), 35 deletions(-) (limited to 'system') diff --git a/system/libraries/Router.php b/system/libraries/Router.php index 06037209b..94a9a5243 100644 --- a/system/libraries/Router.php +++ b/system/libraries/Router.php @@ -292,7 +292,7 @@ class CI_Router { // If the URL has a question mark then it's simplest to just // build the URI string from the zero index of the $_GET array. // This avoids having to deal with $_SERVER variables, which - // can be unreliable on some servers + // can be unreliable in some environments if (is_array($_GET) AND count($_GET) == 1) { return current(array_keys($_GET)); @@ -300,44 +300,38 @@ class CI_Router { // Is there a PATH_INFO variable? // Note: some servers seem to have trouble with getenv() so we'll test it two ways - $path_info = (isset($_SERVER['PATH_INFO'])) ? $_SERVER['PATH_INFO'] : @getenv('PATH_INFO'); + $path = (isset($_SERVER['PATH_INFO'])) ? $_SERVER['PATH_INFO'] : @getenv('PATH_INFO'); + if ($path != '' AND $path != "/".SELF) + { + return $path; + } + + // No PATH_INFO?... What about QUERY_STRING? + $path = (isset($_SERVER['QUERY_STRING'])) ? $_SERVER['QUERY_STRING'] : @getenv('QUERY_STRING'); + if ($path != '') + { + return $path; + } - if ($path_info != '' AND $path_info != "/".SELF) + // No QUERY_STRING?... Maybe the ORIG_PATH_INFO variable exists? + $path = (isset($_SERVER['ORIG_PATH_INFO'])) ? $_SERVER['ORIG_PATH_INFO'] : @getenv('ORIG_PATH_INFO'); + if ($path != '' AND $path != "/".SELF) { - return $path_info; + return $path; } - else + + // OK, how about REQUEST_URI? + // Note: REQUEST_URI is not supplied in a consistent manner with all platforms so it's + // a diffucult variable to use. We'll try to parse it out correctly. Hopfully one + // of the other variables above was available. + $path = $this->_parse_request_uri(); + if ($path != "") { - // OK, how about REQUEST_URI? - $req_uri = $this->_parse_request_uri(); - - if ($req_uri != "") - { - return $req_uri; - } - else - { - // Hm... maybe the ORIG_PATH_INFO variable exists? - $path_info = (isset($_SERVER['ORIG_PATH_INFO'])) ? $_SERVER['ORIG_PATH_INFO'] : @getenv('ORIG_PATH_INFO'); - if ($path_info != '' AND $path_info != "/".SELF) - { - return $path_info; - } - else - { - // At this point we've exhauseted all our options. - // Hopefully QUERY_STRING exists. If not, there's nothing else we can try. - $query_string = (isset($_SERVER['QUERY_STRING'])) ? $_SERVER['QUERY_STRING'] : @getenv('QUERY_STRING'); - - if ($query_string != '') - { - return $query_string; - } - - return ''; - } - } + return $path; } + + // We've exhausted all our options... + return ''; } else { @@ -373,7 +367,7 @@ class CI_Router { $request_uri = preg_replace("|/(.*)|", "\\1", str_replace("\\", "/", $_SERVER['REQUEST_URI'])); - if ($request_uri == '' OR $request_uri == $this->config->item('index_page')) + if ($request_uri == '' OR $request_uri == SELF) { return ''; } -- cgit v1.2.3-24-g4f1b From e0cd609abeaeb1be5ed0ef7ac88bb6de86627881 Mon Sep 17 00:00:00 2001 From: admin Date: Fri, 20 Oct 2006 01:00:31 +0000 Subject: --- system/application/config/config.php | 2 +- system/libraries/Exceptions.php | 12 ++++++++++-- 2 files changed, 11 insertions(+), 3 deletions(-) (limited to 'system') diff --git a/system/application/config/config.php b/system/application/config/config.php index 3f26d48fa..bf15525cb 100644 --- a/system/application/config/config.php +++ b/system/application/config/config.php @@ -78,7 +78,7 @@ $config['language'] = "english"; | setting this variable to TRUE (boolean). See the user guide for details. | */ -$config['enable_hooks'] = FALSE; +$config['enable_hooks'] = TRUE; /* diff --git a/system/libraries/Exceptions.php b/system/libraries/Exceptions.php index c3af801ae..4bdbe4f83 100644 --- a/system/libraries/Exceptions.php +++ b/system/libraries/Exceptions.php @@ -117,7 +117,11 @@ class CI_Exceptions { function show_error($heading, $message, $template = 'error_general') { $message = '

'.implode('

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

'; - + + if (ob_get_level() > 1) + { + ob_end_flush(); + } ob_start(); include_once(APPPATH.'errors/'.$template.EXT); $buffer = ob_get_contents(); @@ -151,7 +155,11 @@ class CI_Exceptions { $x = explode('/', $filepath); $filepath = $x[count($x)-2].'/'.end($x); } - + + if (ob_get_level() > 1) + { + ob_end_flush(); + } ob_start(); include_once(APPPATH.'errors/error_php'.EXT); $buffer = ob_get_contents(); -- cgit v1.2.3-24-g4f1b From b807f32ab209a537bbb0a85d6129d495675b189f Mon Sep 17 00:00:00 2001 From: admin Date: Fri, 20 Oct 2006 04:55:37 +0000 Subject: --- system/libraries/Loader.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'system') diff --git a/system/libraries/Loader.php b/system/libraries/Loader.php index 4252f1633..3b1a7f2cd 100644 --- a/system/libraries/Loader.php +++ b/system/libraries/Loader.php @@ -221,7 +221,7 @@ class CI_Loader { * 1. The name of the "view" file to be included. * 2. An associative array of data to be extracted for use in the view. * 3. TRUE/FALSE - whether to return the data or load it. In - * some cases it's advantageous to be able to retun data so that + * some cases it's advantageous to be able to return data so that * a developer can process it in some way. * * @access public @@ -257,7 +257,7 @@ class CI_Loader { /** * Set Variables * - * Once variables are set they become availabe within + * Once variables are set they become available within * the controller class and its "view" files. * * @access public @@ -525,7 +525,7 @@ class CI_Loader { */ function _ci_load($data) { - // This allows anything loaded using $this->load (viwes, files, etc.) + // This allows anything loaded using $this->load (views, files, etc.) // to become accessible from within the Controller and Model functions. // Only needed when running PHP 5 @@ -584,7 +584,7 @@ class CI_Loader { * 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 acurate. + * the browser and then stop the timer it won't be accurate. */ if ( ! file_exists($path)) { -- cgit v1.2.3-24-g4f1b From fe9754ca6af8c6242c7d2761047eb409af354930 Mon Sep 17 00:00:00 2001 From: admin Date: Fri, 20 Oct 2006 05:00:34 +0000 Subject: --- system/application/config/database.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'system') diff --git a/system/application/config/database.php b/system/application/config/database.php index 32b23058e..8a1822e90 100644 --- a/system/application/config/database.php +++ b/system/application/config/database.php @@ -32,16 +32,16 @@ $active_group = "default"; $db['default']['hostname'] = "localhost"; -$db['default']['username'] = "root"; +$db['default']['username'] = ""; $db['default']['password'] = ""; -$db['default']['database'] = "test"; +$db['default']['database'] = ""; $db['default']['dbdriver'] = "mysql"; $db['default']['dbprefix'] = ""; $db['default']['active_r'] = TRUE; $db['default']['pconnect'] = TRUE; $db['default']['db_debug'] = TRUE; $db['default']['cache_on'] = FALSE; -$db['default']['cachedir'] = ''; +$db['default']['cachedir'] = ""; ?> \ No newline at end of file -- cgit v1.2.3-24-g4f1b From 6dfa713d204056d42027b54e851785646d00355a Mon Sep 17 00:00:00 2001 From: admin Date: Fri, 20 Oct 2006 05:01:30 +0000 Subject: --- system/application/config/database.php | 2 ++ 1 file changed, 2 insertions(+) (limited to 'system') diff --git a/system/application/config/database.php b/system/application/config/database.php index 8a1822e90..082e34a05 100644 --- a/system/application/config/database.php +++ b/system/application/config/database.php @@ -23,6 +23,8 @@ | ['pconnect'] TRUE/FALSE - Whether to use a persistent connection | ['db_debug'] TRUE/FALSE - Whether database errors should be displayed. | ['active_r'] TRUE/FALSE - Whether to load the active record class +| ['cache_on'] TRUE/FALSE - Enables/disables query caching +| ['cachedir'] The path to the folder where cache files should be stored | | The $active_group variable lets you choose which connection group to | make active. By default there is only one group (the "default" group). -- cgit v1.2.3-24-g4f1b From 31eeb0587cd5fcef8209ca5083f28a39435c135d Mon Sep 17 00:00:00 2001 From: admin Date: Fri, 20 Oct 2006 05:11:33 +0000 Subject: --- system/database/DB_result.php | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'system') diff --git a/system/database/DB_result.php b/system/database/DB_result.php index b163bb5ea..4e8c4fc76 100644 --- a/system/database/DB_result.php +++ b/system/database/DB_result.php @@ -63,6 +63,11 @@ class CI_DB_result { return $this->result_object; } + if ($this->num_rows == 0) + { + return array(); + } + $this->_data_seek(0); while ($row = $this->_fetch_object()) { @@ -87,6 +92,11 @@ class CI_DB_result { return $this->result_array; } + if ($this->num_rows == 0) + { + return array(); + } + $this->_data_seek(0); while ($row = $this->_fetch_assoc()) { -- cgit v1.2.3-24-g4f1b From 0625e19f3318874d6f95b546312601538edb0f14 Mon Sep 17 00:00:00 2001 From: admin Date: Fri, 20 Oct 2006 22:16:54 +0000 Subject: --- system/application/config/config.php | 43 +++++++++++++------- system/codeigniter/Common.php | 78 +++++++++++++++++------------------- system/libraries/Benchmark.php | 1 - system/libraries/Loader.php | 50 +++++++++-------------- 4 files changed, 83 insertions(+), 89 deletions(-) (limited to 'system') diff --git a/system/application/config/config.php b/system/application/config/config.php index bf15525cb..b0d2bf500 100644 --- a/system/application/config/config.php +++ b/system/application/config/config.php @@ -81,6 +81,21 @@ $config['language'] = "english"; $config['enable_hooks'] = TRUE; +/* +|-------------------------------------------------------------------------- +| Class Extension Prefix +|-------------------------------------------------------------------------- +| +| This item allows you to set the filename/classname prefix when extending +| native libraries. For more information please see the user guide: +| +| http://www.codeigniter.com/user_guide/general/core_classes.html +| http://www.codeigniter.com/user_guide/general/creating_libraries.html +| +*/ +$config['subclass_prefix'] = 'MY_'; + + /* |-------------------------------------------------------------------------- | Allowed URL Characters @@ -129,20 +144,7 @@ $config['function_trigger'] = 'm'; /* |-------------------------------------------------------------------------- -| Master Time Reference -|-------------------------------------------------------------------------- -| -| Options are "local" or "gmt". This pref tells the system whether to use -| your server's local time as the master "now" reference, or convert it to -| GMT. See the "date helper" page of the user guide for information -| regarding date handling. -| -*/ -$config['time_reference'] = 'local'; - -/* -|-------------------------------------------------------------------------- -| Error Logging Threshold +| Error Logging |-------------------------------------------------------------------------- | | You can enable error logging by setting a threshold over zero. The @@ -267,5 +269,18 @@ $config['global_xss_filtering'] = FALSE; */ $config['compress_output'] = FALSE; +/* +|-------------------------------------------------------------------------- +| Master Time Reference +|-------------------------------------------------------------------------- +| +| Options are "local" or "gmt". This pref tells the system whether to use +| your server's local time as the master "now" reference, or convert it to +| GMT. See the "date helper" page of the user guide for information +| regarding date handling. +| +*/ +$config['time_reference'] = 'local'; + ?> \ No newline at end of file diff --git a/system/codeigniter/Common.php b/system/codeigniter/Common.php index 07b468fef..a82d486e6 100644 --- a/system/codeigniter/Common.php +++ b/system/codeigniter/Common.php @@ -50,57 +50,27 @@ function &load_class($class, $instantiate = TRUE) { return $objects[$class]; } - - // This is a special case. It's a class in the Base5.php file - // which we don't need to load. We only instantiate it. - if ($class == 'Instance') - { - $objects[$class] =& new $class(); - return $objects[$class]; - } - + // If the requested class does not exist in the application/libraries - // folder we'll load the native class from the system/libraries folder. - - $is_subclass = FALSE; - if ( ! file_exists(APPPATH.'libraries/'.$class.EXT)) + // folder we'll load the native class from the system/libraries folder. + if (file_exists(APPPATH.'libraries/'.config_item('subclass_prefix').$class.EXT)) { - require(BASEPATH.'libraries/'.$class.EXT); + require(BASEPATH.'libraries/'.$class.EXT); + require(APPPATH.'libraries/'.config_item('subclass_prefix').$class.EXT); + $is_subclass = TRUE; } else { - // A core class can either be extended or replaced by putting an - // identically named file in the application/libraries folder.  - // We need to determine, however, if the class being requested is - // a sub-class of an existing library or an independent instance - // since each needs to be handled slightly different.  - // To do this we'll open the requested class and read the top portion - // of it. If the class extends a base class we will load the base first. - // If it doesn't extend the base we'll only load the requested class. - - // Note: I'm not thrilled with this approach since it requires us to - // read the top part of the file (I set a character limit of 5000 bytes, - // which correlates to roughly the first 100 lines of code), but - // I can't think of a better way to allow classes to be extended or - // replaced on-the-fly with nothing required for the user to do - // except write the declaration.  Fortunately PHP is ridiculously fast - // at file reading operations so I'm not able to discern a performance - // hit based on my benchmarks, assuming only a small number of core - // files are being extended, which will usually be the case. - - $fp = fopen(APPPATH.'libraries/'.$class.EXT, "rb"); - - if (preg_match("/MY_".$class."\s+extends\s+CI_".$class."/i", fread($fp, '6000'))) + if (file_exists(APPPATH.'libraries/'.$class.EXT)) { - require(BASEPATH.'libraries/'.$class.EXT); - require(APPPATH.'libraries/'.$class.EXT); - $is_subclass = TRUE; + require(APPPATH.'libraries/'.$class.EXT); + $is_subclass = FALSE; } else { - require(APPPATH.'libraries/'.$class.EXT); + require(BASEPATH.'libraries/'.$class.EXT); + $is_subclass = FALSE; } - fclose($fp); } if ($instantiate == FALSE) @@ -111,7 +81,7 @@ function &load_class($class, $instantiate = TRUE) if ($is_subclass == TRUE) { - $name = 'MY_'.$class; + $name = config_item('subclass_prefix').$class; $objects[$class] =& new $name(); return $objects[$class]; } @@ -151,6 +121,30 @@ function &get_config() return $main_conf[0]; } +/** +* Gets a config item +* +* @access public +* @return mixed +*/ +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]; +} + /** * Error Handler diff --git a/system/libraries/Benchmark.php b/system/libraries/Benchmark.php index c20a54269..d4262792c 100644 --- a/system/libraries/Benchmark.php +++ b/system/libraries/Benchmark.php @@ -31,7 +31,6 @@ class CI_Benchmark { var $marker = array(); - // -------------------------------------------------------------------- /** diff --git a/system/libraries/Loader.php b/system/libraries/Loader.php index 3b1a7f2cd..b313c6d5a 100644 --- a/system/libraries/Loader.php +++ b/system/libraries/Loader.php @@ -655,51 +655,37 @@ class CI_Loader { function _ci_load_class($class, $params = NULL) { // Prep the class name - $class = strtolower(str_replace(EXT, '', $class)); - - // Is this a class extension request? - if (substr($class, 0, 3) == 'my_') - { - $class = preg_replace("/my_(.+)/", "\\1", $class); + $class = ucfirst(strtolower(str_replace(EXT, '', $class))); - // Load the requested library from the main system/libraries folder - if (file_exists(BASEPATH.'libraries/'.ucfirst($class).EXT)) - { - include_once(BASEPATH.'libraries/'.ucfirst($class).EXT); - } - - // Now look for a matching library - foreach (array(ucfirst($class), $class) as $filename) + // Is this a class extension request? + if (file_exists(APPPATH.'libraries/'.config_item('subclass_prefix').$class.EXT)) + { + if ( ! file_exists(BASEPATH.'libraries/'.$class.EXT)) { - if (file_exists(APPPATH.'libraries/'.$filename.EXT)) - { - include_once(APPPATH.'libraries/'.$filename.EXT); - } + log_message('error', "Unable to load the requested class: ".$class); + show_error("Unable to load the requested class: ".$class); } - - return $this->_ci_init_class($filename, 'MY_', $params); + + include_once(BASEPATH.'libraries/'.ucfirst($class).EXT); + include_once(APPPATH.'libraries/'.config_item('subclass_prefix').$class.EXT); + + return $this->_ci_init_class($filename, config_item('subclass_prefix'), $params); } // Lets search for the requested library file and load it. - // For backward compatibility we'll test for filenames that are - // both uppercase and lower. - foreach (array(ucfirst($class), $class) as $filename) + for ($i = 1; $i < 3; $i++) { - for ($i = 1; $i < 3; $i++) + $path = ($i % 2) ? APPPATH : BASEPATH; + if (file_exists($path.'libraries/'.$filename.EXT)) { - $path = ($i % 2) ? APPPATH : BASEPATH; - - if (file_exists($path.'libraries/'.$filename.EXT)) - { - include_once($path.'libraries/'.$filename.EXT); - return $this->_ci_init_class($filename, '', $params); - } + include_once($path.'libraries/'.$filename.EXT); + return $this->_ci_init_class($filename, '', $params); } } // 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 class: ".$class); + show_error("Unable to load the requested class: ".$class); } // -------------------------------------------------------------------- -- cgit v1.2.3-24-g4f1b From afe3aaa5292132e3f2c4604a413957fa18a603e5 Mon Sep 17 00:00:00 2001 From: admin Date: Fri, 20 Oct 2006 22:22:55 +0000 Subject: --- system/codeigniter/CodeIgniter.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'system') diff --git a/system/codeigniter/CodeIgniter.php b/system/codeigniter/CodeIgniter.php index 93c1dba5f..409cf7765 100644 --- a/system/codeigniter/CodeIgniter.php +++ b/system/codeigniter/CodeIgniter.php @@ -52,11 +52,11 @@ set_magic_quotes_runtime(0); // Kill magic quotes $BM =& load_class('Benchmark'); $BM->mark('total_execution_time_start'); -$BM->mark('loading_time_base_clases_start'); +$BM->mark('loading_time_base_classes_start'); /* * ------------------------------------------------------ - * Instantiate the hooks classe + * Instantiate the hooks class * ------------------------------------------------------ */ @@ -109,7 +109,7 @@ $LANG =& load_class('Language'); * ------------------------------------------------------ * * Note: Due to the poor object handling in PHP 4 we'll - * contditionally load different versions of the base + * conditionally load different versions of the base * class. Retaining PHP 4 compatibility requires a bit of a hack. * * Note: The Loader class needs to be included first @@ -132,7 +132,7 @@ load_class('Controller', FALSE); require(APPPATH.'controllers/'.$RTR->fetch_directory().$RTR->fetch_class().EXT); // Set a mark point for benchmarking -$BM->mark('loading_time_base_clases_end'); +$BM->mark('loading_time_base_classes_end'); /* -- cgit v1.2.3-24-g4f1b From 570c161b4c22c1fcdc0345b0d57a9ea127db4b4a Mon Sep 17 00:00:00 2001 From: admin Date: Fri, 20 Oct 2006 22:28:39 +0000 Subject: --- system/libraries/Loader.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'system') diff --git a/system/libraries/Loader.php b/system/libraries/Loader.php index b313c6d5a..253d916c4 100644 --- a/system/libraries/Loader.php +++ b/system/libraries/Loader.php @@ -669,17 +669,17 @@ class CI_Loader { include_once(BASEPATH.'libraries/'.ucfirst($class).EXT); include_once(APPPATH.'libraries/'.config_item('subclass_prefix').$class.EXT); - return $this->_ci_init_class($filename, config_item('subclass_prefix'), $params); + return $this->_ci_init_class($class, config_item('subclass_prefix'), $params); } // Lets search for the requested library file and load it. for ($i = 1; $i < 3; $i++) { $path = ($i % 2) ? APPPATH : BASEPATH; - if (file_exists($path.'libraries/'.$filename.EXT)) + if (file_exists($path.'libraries/'.$class.EXT)) { - include_once($path.'libraries/'.$filename.EXT); - return $this->_ci_init_class($filename, '', $params); + include_once($path.'libraries/'.$class.EXT); + return $this->_ci_init_class($class, '', $params); } } -- cgit v1.2.3-24-g4f1b From 9fcc28a29299fbbc242f87bf1b1e61fda6543886 Mon Sep 17 00:00:00 2001 From: admin Date: Sat, 21 Oct 2006 17:49:47 +0000 Subject: --- system/database/DB_cache.php | 2 +- system/database/DB_driver.php | 1 + system/helpers/file_helper.php | 7 ++++--- 3 files changed, 6 insertions(+), 4 deletions(-) (limited to 'system') diff --git a/system/database/DB_cache.php b/system/database/DB_cache.php index 86493e77c..aee5ce6fa 100644 --- a/system/database/DB_cache.php +++ b/system/database/DB_cache.php @@ -171,7 +171,7 @@ class CI_DB_Cache { $segment_two = ($this->CI->uri->segment(2) == FALSE) ? 'index' : $this->CI->uri->segment(2); } - $dir_path = $this->CI->db->cachedir.md5($segment_one.'+'.$segment_two).'/'; + $dir_path = $this->CI->db->cachedir.$segment_one.'+'.$segment_two.'/'; delete_files($dir_path, TRUE); } diff --git a/system/database/DB_driver.php b/system/database/DB_driver.php index 848d4f1c6..a24bd20d8 100644 --- a/system/database/DB_driver.php +++ b/system/database/DB_driver.php @@ -236,6 +236,7 @@ class CI_DB_driver { { if (FALSE !== ($cache = $this->CACHE->read($sql))) { + $this->load_rdriver(); return $cache; } } diff --git a/system/helpers/file_helper.php b/system/helpers/file_helper.php index c0f525688..635ef1ba0 100644 --- a/system/helpers/file_helper.php +++ b/system/helpers/file_helper.php @@ -110,7 +110,7 @@ function write_file($path, $data, $mode = 'wb') * @param bool whether to delete any directories found in the path * @return bool */ -function delete_files($path, $del_dir = FALSE) +function delete_files($path, $del_dir = FALSE, $level = 0) { // Trim the trailing slash $path = preg_replace("|^(.+?)/*$|", "\\1", $path); @@ -124,7 +124,8 @@ function delete_files($path, $del_dir = FALSE) { if (is_dir($path.'/'.$filename)) { - delete_files($path.'/'.$filename, $del_dir); + $level++; + delete_files($path.'/'.$filename, $del_dir, $level); } else { @@ -134,7 +135,7 @@ function delete_files($path, $del_dir = FALSE) } @closedir($current_dir); - if ($del_dir == TRUE) + if ($del_dir == TRUE AND $level > 0) { @rmdir($path); } -- cgit v1.2.3-24-g4f1b From e7e1dcd452a15abaaa01c03cd1ade564e3a59453 Mon Sep 17 00:00:00 2001 From: admin Date: Sat, 21 Oct 2006 18:04:01 +0000 Subject: --- system/application/config/config.php | 2 +- system/application/config/database.php | 8 ++++---- system/helpers/array_helper.php | 2 +- system/helpers/directory_helper.php | 2 +- system/libraries/Benchmark.php | 2 +- system/libraries/Controller.php | 2 +- system/libraries/Zip.php | 2 +- 7 files changed, 10 insertions(+), 10 deletions(-) (limited to 'system') diff --git a/system/application/config/config.php b/system/application/config/config.php index b0d2bf500..ab4f445f2 100644 --- a/system/application/config/config.php +++ b/system/application/config/config.php @@ -160,7 +160,7 @@ $config['function_trigger'] = 'm'; | your log files will fill up very fast. | */ -$config['log_threshold'] = 4; +$config['log_threshold'] = 0; /* |-------------------------------------------------------------------------- diff --git a/system/application/config/database.php b/system/application/config/database.php index 082e34a05..9d8c77831 100644 --- a/system/application/config/database.php +++ b/system/application/config/database.php @@ -34,16 +34,16 @@ $active_group = "default"; $db['default']['hostname'] = "localhost"; -$db['default']['username'] = ""; +$db['default']['username'] = "root"; $db['default']['password'] = ""; -$db['default']['database'] = ""; +$db['default']['database'] = "tester"; $db['default']['dbdriver'] = "mysql"; $db['default']['dbprefix'] = ""; $db['default']['active_r'] = TRUE; $db['default']['pconnect'] = TRUE; $db['default']['db_debug'] = TRUE; -$db['default']['cache_on'] = FALSE; -$db['default']['cachedir'] = ""; +$db['default']['cache_on'] = TRUE; +$db['default']['cachedir'] = APPPATH.'dbcache/'; ?> \ No newline at end of file diff --git a/system/helpers/array_helper.php b/system/helpers/array_helper.php index de0faeeff..8adbd8548 100644 --- a/system/helpers/array_helper.php +++ b/system/helpers/array_helper.php @@ -31,7 +31,7 @@ * Element * * Lets you determine whether an array index is set and whether it has a value. - * If the element is empty it returns FALSE (or whater you specify as the default value.) + * If the element is empty it returns FALSE (or whatever you specify as the default value.) * * @access public * @param string diff --git a/system/helpers/directory_helper.php b/system/helpers/directory_helper.php index 69eb13d11..4b7a383b2 100644 --- a/system/helpers/directory_helper.php +++ b/system/helpers/directory_helper.php @@ -28,7 +28,7 @@ // ------------------------------------------------------------------------ /** - * Create a Direcotry Map + * Create a Directory Map * * Reads the specified directory and builds an array * representation of it. Sub-folders contained with the diff --git a/system/libraries/Benchmark.php b/system/libraries/Benchmark.php index d4262792c..5fd24b05f 100644 --- a/system/libraries/Benchmark.php +++ b/system/libraries/Benchmark.php @@ -54,7 +54,7 @@ class CI_Benchmark { * 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 the full system + * {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. * diff --git a/system/libraries/Controller.php b/system/libraries/Controller.php index 0bbc7773e..3db408bec 100644 --- a/system/libraries/Controller.php +++ b/system/libraries/Controller.php @@ -18,7 +18,7 @@ /** * Code Igniter Application Controller Class * - * This class object is the the super class the every library in + * This class object is the super class the every library in * Code Igniter will be assigned to. * * @package CodeIgniter diff --git a/system/libraries/Zip.php b/system/libraries/Zip.php index e13c713fe..6af1ca979 100644 --- a/system/libraries/Zip.php +++ b/system/libraries/Zip.php @@ -228,7 +228,7 @@ class CI_Zip { // -------------------------------------------------------------------- /** - * Write File to the specified direcotry + * Write File to the specified directory * * Lets you write a file * -- cgit v1.2.3-24-g4f1b From fafe28bec4f414e48f63e01ed9105ae5c2c99802 Mon Sep 17 00:00:00 2001 From: admin Date: Sat, 21 Oct 2006 19:08:17 +0000 Subject: --- system/database/DB_active_rec.php | 2 +- system/database/DB_cache.php | 2 +- system/database/DB_driver.php | 6 +- system/database/DB_result.php | 2 +- system/database/drivers/mssql/mssql_driver.php | 2 +- system/database/drivers/mysql/mysql_driver.php | 2 +- system/database/drivers/mysqli/mysqli_driver.php | 2 +- system/database/drivers/oci8/oci8_driver.php | 2 +- system/database/drivers/odbc/odbc_driver.php | 2 +- system/database/drivers/postgre/postgre_driver.php | 2 +- system/database/drivers/sqlite/sqlite_driver.php | 2 +- system/helpers/date_helper.php | 2 +- system/helpers/file_helper.php | 4 +- system/helpers/form_helper.php | 4 +- system/helpers/security_helper.php | 8 +- system/helpers/typography_helper.php | 6 +- system/helpers/user_agent_helper.php | 89 ---------------------- system/libraries/Calendar.php | 2 +- 18 files changed, 26 insertions(+), 115 deletions(-) delete mode 100644 system/helpers/user_agent_helper.php (limited to 'system') diff --git a/system/database/DB_active_rec.php b/system/database/DB_active_rec.php index 1fa4f9557..8db6161af 100644 --- a/system/database/DB_active_rec.php +++ b/system/database/DB_active_rec.php @@ -804,7 +804,7 @@ class CI_DB_active_record extends CI_DB_driver { /** * Object to Array * - * Takes an object as input and convers the class variables to array key/vals + * Takes an object as input and converts the class variables to array key/vals * * @access public * @param object diff --git a/system/database/DB_cache.php b/system/database/DB_cache.php index aee5ce6fa..b469b0e1e 100644 --- a/system/database/DB_cache.php +++ b/system/database/DB_cache.php @@ -82,7 +82,7 @@ class CI_DB_Cache { // -------------------------------------------------------------------- /** - * Retreive a cached query + * 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 diff --git a/system/database/DB_driver.php b/system/database/DB_driver.php index a24bd20d8..8a7b88f18 100644 --- a/system/database/DB_driver.php +++ b/system/database/DB_driver.php @@ -368,7 +368,7 @@ class CI_DB_driver { /** * Simple Query - * This is a simiplified version of the query() function. Internally + * This is a simplified version of the query() function. Internally * we only use it when running transaction commands since they do * not require all the features of the main query() function. * @@ -535,7 +535,7 @@ class CI_DB_driver { * Calculate the aggregate query elapsed time * * @access public - * @param intiger The number of decimal places + * @param integer The number of decimal places * @return integer */ function elapsed_time($decimals = 6) @@ -1021,7 +1021,7 @@ class CI_DB_driver { * @param string the error message * @param string any "swap" values * @param boolean whether to localize the message - * @return string sends the application/errror_db.php template + * @return string sends the application/error_db.php template */ function display_error($error = '', $swap = '', $native = FALSE) { diff --git a/system/database/DB_result.php b/system/database/DB_result.php index 4e8c4fc76..d02bfb96e 100644 --- a/system/database/DB_result.php +++ b/system/database/DB_result.php @@ -63,7 +63,7 @@ class CI_DB_result { return $this->result_object; } - if ($this->num_rows == 0) + if ($this->numerous == 0) { return array(); } diff --git a/system/database/drivers/mssql/mssql_driver.php b/system/database/drivers/mssql/mssql_driver.php index cb2f48dc3..4dc8792ca 100644 --- a/system/database/drivers/mssql/mssql_driver.php +++ b/system/database/drivers/mssql/mssql_driver.php @@ -277,7 +277,7 @@ class CI_DB_mssql_driver extends CI_DB { // -------------------------------------------------------------------- /** - * List columnn query + * List column query * * Generates a platform-specific query string so that the column names can be fetched * diff --git a/system/database/drivers/mysql/mysql_driver.php b/system/database/drivers/mysql/mysql_driver.php index 253627cd9..20311ffa0 100644 --- a/system/database/drivers/mysql/mysql_driver.php +++ b/system/database/drivers/mysql/mysql_driver.php @@ -311,7 +311,7 @@ class CI_DB_mysql_driver extends CI_DB { // -------------------------------------------------------------------- /** - * Show columnn query + * Show column query * * Generates a platform-specific query string so that the column names can be fetched * diff --git a/system/database/drivers/mysqli/mysqli_driver.php b/system/database/drivers/mysqli/mysqli_driver.php index 4fd9f3aaa..ea2adbea9 100644 --- a/system/database/drivers/mysqli/mysqli_driver.php +++ b/system/database/drivers/mysqli/mysqli_driver.php @@ -303,7 +303,7 @@ class CI_DB_mysqli_driver extends CI_DB { // -------------------------------------------------------------------- /** - * Show columnn query + * Show column query * * Generates a platform-specific query string so that the column names can be fetched * diff --git a/system/database/drivers/oci8/oci8_driver.php b/system/database/drivers/oci8/oci8_driver.php index 794405a03..4f5470c1a 100644 --- a/system/database/drivers/oci8/oci8_driver.php +++ b/system/database/drivers/oci8/oci8_driver.php @@ -418,7 +418,7 @@ class CI_DB_oci8_driver extends CI_DB { // -------------------------------------------------------------------- /** - * Show columnn query + * Show column query * * Generates a platform-specific query string so that the column names can be fetched * diff --git a/system/database/drivers/odbc/odbc_driver.php b/system/database/drivers/odbc/odbc_driver.php index 4bd6e1106..17a6dfbd0 100644 --- a/system/database/drivers/odbc/odbc_driver.php +++ b/system/database/drivers/odbc/odbc_driver.php @@ -278,7 +278,7 @@ class CI_DB_odbc_driver extends CI_DB { // -------------------------------------------------------------------- /** - * Show columnn query + * Show column query * * Generates a platform-specific query string so that the column names can be fetched * diff --git a/system/database/drivers/postgre/postgre_driver.php b/system/database/drivers/postgre/postgre_driver.php index 340d65046..f74e652d5 100644 --- a/system/database/drivers/postgre/postgre_driver.php +++ b/system/database/drivers/postgre/postgre_driver.php @@ -305,7 +305,7 @@ class CI_DB_postgre_driver extends CI_DB { // -------------------------------------------------------------------- /** - * Show columnn query + * Show column query * * Generates a platform-specific query string so that the column names can be fetched * diff --git a/system/database/drivers/sqlite/sqlite_driver.php b/system/database/drivers/sqlite/sqlite_driver.php index 9da50b676..fd9fd2c50 100644 --- a/system/database/drivers/sqlite/sqlite_driver.php +++ b/system/database/drivers/sqlite/sqlite_driver.php @@ -297,7 +297,7 @@ class CI_DB_sqlite_driver extends CI_DB { // -------------------------------------------------------------------- /** - * Show columnn query + * Show column query * * Generates a platform-specific query string so that the column names can be fetched * diff --git a/system/helpers/date_helper.php b/system/helpers/date_helper.php index 03519e686..911862423 100644 --- a/system/helpers/date_helper.php +++ b/system/helpers/date_helper.php @@ -507,7 +507,7 @@ function timezone_menu($default = 'UTC', $class = "", $name = 'timezones') * Timezones * * Returns an array of timezones. This is a helper function - * for varios other ones in this library + * for various other ones in this library * * @access public * @param string timezone diff --git a/system/helpers/file_helper.php b/system/helpers/file_helper.php index 635ef1ba0..7a04324e4 100644 --- a/system/helpers/file_helper.php +++ b/system/helpers/file_helper.php @@ -73,7 +73,7 @@ function read_file($file) * Write File * * Writes data to the file specified in the path. - * Creats a new file if non-existant. + * Creates a new file if non-existent. * * @access public * @param string path to file @@ -102,7 +102,7 @@ function write_file($path, $data, $mode = 'wb') * * 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 direcotries contained + * If the second parameter is set to TRUE, any directories contained * within the supplied base directory will be nuked as well. * * @access public diff --git a/system/helpers/form_helper.php b/system/helpers/form_helper.php index 3fd361041..e12d89319 100644 --- a/system/helpers/form_helper.php +++ b/system/helpers/form_helper.php @@ -204,7 +204,7 @@ function form_textarea($data = '', $value = '', $extra = '') // ------------------------------------------------------------------------ /** - * Dropdown Menu + * Drop-down Menu * * @access public * @param string @@ -348,7 +348,7 @@ function form_prep($str = '') * * @access private * @param array - * @parm array + * @param array * @return string */ function parse_form_attributes($attributes, $default) diff --git a/system/helpers/security_helper.php b/system/helpers/security_helper.php index 347cab427..34386ffea 100644 --- a/system/helpers/security_helper.php +++ b/system/helpers/security_helper.php @@ -31,8 +31,8 @@ * XSS Filtering * * @access public - * @parm string - * @parm string the character set of your data + * @param string + * @param string the character set of your data * @return string */ function xss_clean($str, $charset = 'ISO-8859-1') @@ -84,7 +84,7 @@ function dohash($str, $type = 'sha1') * Strip Image Tags * * @access public - * @parm string + * @param string * @return string */ function strip_image_tags($str) @@ -101,7 +101,7 @@ function strip_image_tags($str) * Convert PHP tags to entities * * @access public - * @parm string + * @param string * @return string */ function encode_php_tags($str) diff --git a/system/helpers/typography_helper.php b/system/helpers/typography_helper.php index ba6804873..fe9e3bb92 100644 --- a/system/helpers/typography_helper.php +++ b/system/helpers/typography_helper.php @@ -65,7 +65,7 @@ function nl2br_except_pre($str) * * * @access public - * @parm string + * @param string * @return string */ function auto_typography($str) @@ -125,7 +125,7 @@ class Auto_typography { $str = preg_replace("/\n\n+/", "\n\n", $str); /* - * Convert quotes within tags to tempoarary marker + * Convert quotes within tags to temporary marker * * We don't want quotes converted within * tags so we'll temporarily convert them to @@ -156,7 +156,7 @@ class Auto_typography { $str = preg_replace("#(block_elements.")(.*?>)#", "\\1\\2\\3

", $str); /* - * Convert "ignore" tags to tempoarary marker + * Convert "ignore" tags to temporary marker * * The parser splits out the string at every tag * it encounters. Certain inline tags, like image diff --git a/system/helpers/user_agent_helper.php b/system/helpers/user_agent_helper.php deleted file mode 100644 index 3c6085e77..000000000 --- a/system/helpers/user_agent_helper.php +++ /dev/null @@ -1,89 +0,0 @@ - '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', - 'mac os x' => 'Mac OS X', - 'freebsd' => 'FreeBSD', - 'ppc' => 'Macintosh', - 'sunos' => 'Sun Solaris', - 'linux' => 'Linux', - 'debian' => 'Debian', - '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' - ); - - - foreach ($os as $key => $val) - { - if (preg_match("|$key|i", $_SERVER['HTTP_USER_AGENT'])) - { - return $val; - } - } - - return 'Unknown OS'; -} - - -?> \ No newline at end of file diff --git a/system/libraries/Calendar.php b/system/libraries/Calendar.php index 048934b82..52e99b5ad 100644 --- a/system/libraries/Calendar.php +++ b/system/libraries/Calendar.php @@ -250,7 +250,7 @@ class CI_Calendar { * month provided. * * @access public - * @parm integer the month + * @param integer the month * @return string */ function get_month_name($month) -- cgit v1.2.3-24-g4f1b From 1604062c207cc70eaa8f528e59756a807ba045db Mon Sep 17 00:00:00 2001 From: admin Date: Sat, 21 Oct 2006 19:09:49 +0000 Subject: --- system/libraries/Benchmark.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'system') diff --git a/system/libraries/Benchmark.php b/system/libraries/Benchmark.php index 5fd24b05f..44c32a874 100644 --- a/system/libraries/Benchmark.php +++ b/system/libraries/Benchmark.php @@ -59,8 +59,8 @@ class CI_Benchmark { * swap the real value for this variable. * * @access public - * @param string a paricular marked point - * @param string a paricular marked point + * @param string a particular marked point + * @param string a particular marked point * @param integer the number of decimal places * @return mixed */ -- cgit v1.2.3-24-g4f1b From 5f95aab62d3923e05dacf65d94eeefb2283edc4d Mon Sep 17 00:00:00 2001 From: admin Date: Sat, 21 Oct 2006 19:10:51 +0000 Subject: --- system/libraries/Calendar.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system') diff --git a/system/libraries/Calendar.php b/system/libraries/Calendar.php index 52e99b5ad..ec355d24f 100644 --- a/system/libraries/Calendar.php +++ b/system/libraries/Calendar.php @@ -246,7 +246,7 @@ class CI_Calendar { /** * Get Month Name * - * Generates a texual month name based on the numeric + * Generates a textual month name based on the numeric * month provided. * * @access public -- cgit v1.2.3-24-g4f1b From 23db0ddcd518b8a6ab8b7688a3eab756a73463f0 Mon Sep 17 00:00:00 2001 From: admin Date: Sat, 21 Oct 2006 19:16:50 +0000 Subject: --- system/libraries/Email.php | 63 +++++----------------------------------------- 1 file changed, 6 insertions(+), 57 deletions(-) (limited to 'system') diff --git a/system/libraries/Email.php b/system/libraries/Email.php index 23f7fe456..eb04ae9dc 100644 --- a/system/libraries/Email.php +++ b/system/libraries/Email.php @@ -87,7 +87,6 @@ class CI_Email { log_message('debug', "Email Class Initialized"); } - // END CI_Email() // -------------------------------------------------------------------- @@ -120,7 +119,6 @@ class CI_Email { $this->_smtp_auth = ($this->smtp_user == '' AND $this->smtp_pass == '') ? FALSE : TRUE; $this->_safe_mode = (@ini_get("safe_mode") == 0) ? FALSE : TRUE; } - // END initialize() // -------------------------------------------------------------------- @@ -151,7 +149,6 @@ class CI_Email { $this->_attach_disp = array(); } } - // END clear() // -------------------------------------------------------------------- @@ -179,7 +176,6 @@ class CI_Email { $this->_set_header('From', $name.' <'.$from.'>'); $this->_set_header('Return-Path', '<'.$from.'>'); } - // END from() // -------------------------------------------------------------------- @@ -212,7 +208,6 @@ class CI_Email { $this->_set_header('Reply-To', $name.' <'.$replyto.'>'); $this->_replyto_flag = TRUE; } - // END reply_to() // -------------------------------------------------------------------- @@ -244,7 +239,6 @@ class CI_Email { break; } } - // END to() // -------------------------------------------------------------------- @@ -268,7 +262,6 @@ class CI_Email { if ($this->_get_protocol() == "smtp") $this->_cc_array = $cc; } - // END cc() // -------------------------------------------------------------------- @@ -299,7 +292,6 @@ class CI_Email { else $this->_set_header('Bcc', implode(", ", $bcc)); } - // END bcc() // -------------------------------------------------------------------- @@ -317,7 +309,6 @@ class CI_Email { $this->_set_header('Subject', trim($subject)); } - // END subject() // -------------------------------------------------------------------- @@ -339,7 +330,6 @@ class CI_Email { $this->_body = stripslashes($this->_body); } - // END message() // -------------------------------------------------------------------- @@ -356,7 +346,6 @@ class CI_Email { $this->_attach_type[] = $this->_mime_types(next(explode('.', basename($filename)))); $this->_attach_disp[] = $disposition; // Can also be 'inline' Not sure if it matters } - // END attach() // -------------------------------------------------------------------- @@ -372,7 +361,6 @@ class CI_Email { { $this->_headers[$header] = $value; } - // END _set_header() // -------------------------------------------------------------------- @@ -409,7 +397,6 @@ class CI_Email { } return $email; } - // END _str_to_array() // -------------------------------------------------------------------- @@ -424,7 +411,6 @@ class CI_Email { { $this->alt_message = ($str == '') ? '' : $str; } - // END set_alt_message() // -------------------------------------------------------------------- @@ -439,7 +425,6 @@ class CI_Email { { $this->mailtype = ($type == 'html') ? 'html' : 'text'; } - // END set_mailtype() // -------------------------------------------------------------------- @@ -454,12 +439,11 @@ class CI_Email { { $this->wordwrap = ($wordwrap === FALSE) ? FALSE : TRUE; } - // END set_wordwrap() // -------------------------------------------------------------------- /** - * Set Protocal + * Set Protocol * * @access public * @param string @@ -469,7 +453,6 @@ class CI_Email { { $this->protocol = ( ! in_array($protocol, $this->_protocols, TRUE)) ? 'mail' : strtolower($protocol); } - // END set_protocol() // -------------------------------------------------------------------- @@ -496,7 +479,6 @@ class CI_Email { $this->priority = $n; } - // END set_priority() // -------------------------------------------------------------------- @@ -517,22 +499,20 @@ class CI_Email { $this->newline = $newline; } - // END set_newline() // -------------------------------------------------------------------- /** - * Set Message Boundry + * Set Message Boundary * * @access private * @return void */ function _set_boundaries() { - $this->_alt_boundary = "B_ALT_".uniqid(''); // mulipart/alternative + $this->_alt_boundary = "B_ALT_".uniqid(''); // multipart/alternative $this->_atc_boundary = "B_ATC_".uniqid(''); // attachment boundary } - // END _set_boundaries() // -------------------------------------------------------------------- @@ -550,7 +530,6 @@ class CI_Email { return "<".uniqid('').strstr($from, '@').">"; } - // END _get_message_id() // -------------------------------------------------------------------- @@ -569,7 +548,6 @@ class CI_Email { if ($return == true) return $this->protocol; } - // END _get_protocol() // -------------------------------------------------------------------- @@ -590,7 +568,6 @@ class CI_Email { if ($return == true) return $this->_encoding; } - // END _get_encoding() // -------------------------------------------------------------------- @@ -613,7 +590,6 @@ class CI_Email { else return 'plain'; } - // END _get_content_type() // -------------------------------------------------------------------- @@ -632,7 +608,6 @@ class CI_Email { return sprintf("%s %s%04d", date("D, j M Y H:i:s"), $operator, $timezone); } - // END _set_date() // -------------------------------------------------------------------- @@ -646,7 +621,6 @@ class CI_Email { { return "This is a multi-part message in MIME format.".$this->newline."Your email application may not support this format."; } - // END _get_mime_message() // -------------------------------------------------------------------- @@ -674,7 +648,6 @@ class CI_Email { } } } - // END validate_email() // -------------------------------------------------------------------- @@ -692,7 +665,6 @@ class CI_Email { else return TRUE; } - // END valid_email() // -------------------------------------------------------------------- @@ -725,7 +697,6 @@ class CI_Email { return $clean_email; } - // END clean_email() // -------------------------------------------------------------------- @@ -773,7 +744,6 @@ class CI_Email { return $this->word_wrap($body, '76'); } - // END _get_alt_message() // -------------------------------------------------------------------- @@ -846,7 +816,6 @@ class CI_Email { return $output; } - // END word_wrap() // -------------------------------------------------------------------- @@ -865,7 +834,6 @@ class CI_Email { $this->_set_header('Message-ID', $this->_get_message_id()); $this->_set_header('Mime-Version', '1.0'); } - // END _build_headers() // -------------------------------------------------------------------- @@ -899,7 +867,6 @@ class CI_Email { if ($this->_get_protocol() == 'mail') $this->_header_str = substr($this->_header_str, 0, -1); } - // END _write_headers() // -------------------------------------------------------------------- @@ -1062,7 +1029,6 @@ class CI_Email { return; } - // END _build_message() // -------------------------------------------------------------------- @@ -1102,12 +1068,11 @@ class CI_Email { else return TRUE; } - // END send() // -------------------------------------------------------------------- /** - * Batch Bcc Send. Sends groups of Bccs in batches + * Batch Bcc Send. Sends groups of BCCs in batches * * @access public * @return bool @@ -1154,7 +1119,6 @@ class CI_Email { $this->_spool_email(); } } - // END batch_bcc_send() // -------------------------------------------------------------------- @@ -1168,7 +1132,6 @@ class CI_Email { { $this->_finalbody = preg_replace_callback("/\{unwrap\}(.*?)\{\/unwrap\}/si", array($this, '_remove_nl_callback'), $this->_finalbody); } - // END _unwrap_specials() // -------------------------------------------------------------------- @@ -1182,7 +1145,6 @@ class CI_Email { { return preg_replace("/(\r\n)|(\r)|(\n)/", "", $matches['1']); } - // END _remove_nl_callback() // -------------------------------------------------------------------- @@ -1190,7 +1152,7 @@ class CI_Email { * Spool mail to the mail server * * @access private - * @return bol + * @return bool */ function _spool_email() { @@ -1228,7 +1190,6 @@ class CI_Email { $this->_set_error_message('email_sent', $this->_get_protocol()); return true; } - // END _spool_email() // -------------------------------------------------------------------- @@ -1255,7 +1216,6 @@ class CI_Email { return TRUE; } } - // END _send_with_mail() // -------------------------------------------------------------------- @@ -1281,7 +1241,6 @@ class CI_Email { return TRUE; } - // END _send_with_sendmail() // -------------------------------------------------------------------- @@ -1344,7 +1303,6 @@ class CI_Email { $this->_send_command('quit'); return true; } - // END _send_with_smtp() // -------------------------------------------------------------------- @@ -1373,7 +1331,6 @@ class CI_Email { $this->_set_error_message($this->_get_smtp_data()); return $this->_send_command('hello'); } - // END _smtp_connect() // -------------------------------------------------------------------- @@ -1439,7 +1396,6 @@ class CI_Email { return true; } - // END _send_command() // -------------------------------------------------------------------- @@ -1492,7 +1448,6 @@ class CI_Email { return true; } - // END _smtp_authenticate() // -------------------------------------------------------------------- @@ -1512,7 +1467,6 @@ class CI_Email { else return true; } - // END _send_data() // -------------------------------------------------------------------- @@ -1536,7 +1490,6 @@ class CI_Email { return $data; } - // END _get_smtp_data() // -------------------------------------------------------------------- @@ -1550,7 +1503,6 @@ class CI_Email { { return (isset($_SERVER['SERVER_NAME'])) ? $_SERVER['SERVER_NAME'] : 'localhost.localdomain'; } - // END _get_hostname() // -------------------------------------------------------------------- @@ -1591,12 +1543,11 @@ class CI_Email { return $this->_IP; } - // END _get_ip() // -------------------------------------------------------------------- /** - * Get Debugg Message + * Get Debug Message * * @access public * @return string @@ -1641,7 +1592,6 @@ class CI_Email { $this->_debug_msg[] = str_replace('%s', $val, $line)."
"; } } - // END _set_error_message() // -------------------------------------------------------------------- @@ -1745,7 +1695,6 @@ class CI_Email { return ( ! isset($mimes[strtolower($ext)])) ? "application/x-unknown-content-type" : $mimes[strtolower($ext)]; } - // END _mime_types() } // END CI_Email class -- cgit v1.2.3-24-g4f1b From bd6bee75dd26ade1c8d9cfd104bb913065797c59 Mon Sep 17 00:00:00 2001 From: admin Date: Sat, 21 Oct 2006 19:39:00 +0000 Subject: --- system/libraries/Config.php | 14 ++------------ system/libraries/Exceptions.php | 11 +++-------- system/libraries/Hooks.php | 3 --- system/libraries/Image_lib.php | 36 ++++++------------------------------ system/libraries/Input.php | 12 ++++++------ system/libraries/Language.php | 3 --- system/libraries/Loader.php | 4 ++-- system/libraries/Pagination.php | 2 +- system/libraries/Parser.php | 5 ----- system/libraries/Profiler.php | 2 +- system/libraries/Router.php | 8 ++++---- system/libraries/Session.php | 4 +--- system/libraries/Sha1.php | 5 ----- system/libraries/Table.php | 2 +- system/libraries/Trackback.php | 19 +++---------------- system/libraries/Unit_test.php | 2 +- system/libraries/Upload.php | 4 ++-- 17 files changed, 33 insertions(+), 103 deletions(-) (limited to 'system') diff --git a/system/libraries/Config.php b/system/libraries/Config.php index 82836b1f3..ef6d46a25 100644 --- a/system/libraries/Config.php +++ b/system/libraries/Config.php @@ -46,9 +46,7 @@ class CI_Config { { $this->config = get_config(); log_message('debug', "Config Class Initialized"); - } - // END CI_Config() - + } // -------------------------------------------------------------------- @@ -110,7 +108,6 @@ class CI_Config { log_message('debug', 'Config file loaded: config/'.$file.EXT); return TRUE; } - // END load() // -------------------------------------------------------------------- @@ -152,7 +149,6 @@ class CI_Config { return $pref; } - // END item() // -------------------------------------------------------------------- @@ -186,9 +182,6 @@ class CI_Config { return $pref; } - // END item() - - // -------------------------------------------------------------------- @@ -216,8 +209,7 @@ class CI_Config { return $this->slash_item('base_url').$this->slash_item('index_page').preg_replace("|^/*(.+?)/*$|", "\\1", $uri).$suffix; } } - // END site_url() - + // -------------------------------------------------------------------- /** @@ -231,7 +223,6 @@ class CI_Config { $x = explode("/", preg_replace("|/*(.+?)/*$|", "\\1", BASEPATH)); return $this->slash_item('base_url').end($x).'/'; } - // END system_url() // -------------------------------------------------------------------- @@ -247,7 +238,6 @@ class CI_Config { { $this->config[$item] = $value; } - // END set_item() } diff --git a/system/libraries/Exceptions.php b/system/libraries/Exceptions.php index 4bdbe4f83..a0591e4e5 100644 --- a/system/libraries/Exceptions.php +++ b/system/libraries/Exceptions.php @@ -55,7 +55,6 @@ class CI_Exceptions { { // Note: Do not log messages from this constructor. } - // END CI_Exceptions() // -------------------------------------------------------------------- @@ -77,7 +76,6 @@ class CI_Exceptions { log_message('error', 'Severity: '.$severity.' '.$severity.' --> '.$message. ' '.$filepath.' '.$line, TRUE); } - // END log_exception() // -------------------------------------------------------------------- @@ -97,7 +95,6 @@ class CI_Exceptions { echo $this->show_error($heading, $message, 'error_404'); exit; } - // END show_404() // -------------------------------------------------------------------- @@ -105,7 +102,7 @@ class CI_Exceptions { * General Error Page * * This function takes an error message as input - * (either as a string or an array) and displayes + * (either as a string or an array) and displays * it using the specified template. * * @access private @@ -128,8 +125,6 @@ class CI_Exceptions { ob_end_clean(); return $buffer; } - // END show_error() - // -------------------------------------------------------------------- @@ -166,8 +161,8 @@ class CI_Exceptions { ob_end_clean(); echo $buffer; } - // END show_php_error() -// END Exceptions Class + } +// END Exceptions Class ?> \ No newline at end of file diff --git a/system/libraries/Hooks.php b/system/libraries/Hooks.php index 3c35c9088..6f48723f6 100644 --- a/system/libraries/Hooks.php +++ b/system/libraries/Hooks.php @@ -109,7 +109,6 @@ class CI_Hooks { return TRUE; } - // END hook_exists() // -------------------------------------------------------------------- @@ -218,8 +217,6 @@ class CI_Hooks { $this->in_progress = FALSE; return TRUE; } - // END _run_hook() - } diff --git a/system/libraries/Image_lib.php b/system/libraries/Image_lib.php index 16583c063..f8c05f834 100644 --- a/system/libraries/Image_lib.php +++ b/system/libraries/Image_lib.php @@ -92,7 +92,6 @@ class CI_Image_lib { log_message('debug', "Image Lib Class Initialized"); } - // END CI_Image_lib() // -------------------------------------------------------------------- @@ -113,7 +112,6 @@ class CI_Image_lib { $this->$val = ''; } } - // END clear() // -------------------------------------------------------------------- @@ -186,7 +184,7 @@ class CI_Image_lib { $this->source_image = end($x); $this->source_folder = str_replace($this->source_image, '', $full_source_path); - // Set the Image Propterties + // Set the Image Properties if ( ! $this->get_image_properties($this->source_folder.$this->source_image)) { return FALSE; @@ -333,7 +331,6 @@ class CI_Image_lib { return TRUE; } - // END initialize() // -------------------------------------------------------------------- @@ -357,7 +354,6 @@ class CI_Image_lib { return $this->$protocol('resize'); } - // END resize() // -------------------------------------------------------------------- @@ -381,7 +377,6 @@ class CI_Image_lib { return $this->$protocol('crop'); } - // END crop() // -------------------------------------------------------------------- @@ -435,7 +430,6 @@ class CI_Image_lib { return $this->image_rotate_gd(); } } - // END rotate() // -------------------------------------------------------------------- @@ -540,7 +534,6 @@ class CI_Image_lib { return TRUE; } - // END image_process_gd() // -------------------------------------------------------------------- @@ -611,7 +604,6 @@ class CI_Image_lib { return TRUE; } - // END image_process_imagemagick() // -------------------------------------------------------------------- @@ -698,7 +690,6 @@ class CI_Image_lib { return TRUE; } - // END image_process_netpbm() // -------------------------------------------------------------------- @@ -758,7 +749,6 @@ class CI_Image_lib { return true; } - // END image_rotate_gd() // -------------------------------------------------------------------- @@ -843,7 +833,6 @@ class CI_Image_lib { return TRUE; } - // END image_mirror_gd() // -------------------------------------------------------------------- @@ -868,7 +857,6 @@ class CI_Image_lib { return $this->text_watermark(); } } - // END image_mirror_gd() // -------------------------------------------------------------------- @@ -969,7 +957,6 @@ class CI_Image_lib { return TRUE; } - // END overlay_watermark() // -------------------------------------------------------------------- @@ -1110,7 +1097,6 @@ class CI_Image_lib { return TRUE; } - // END text_watermark() // -------------------------------------------------------------------- @@ -1168,12 +1154,11 @@ class CI_Image_lib { $this->set_error(array('imglib_unsupported_imagecreate')); return FALSE; } - // END image_create_gd() // -------------------------------------------------------------------- /** - * Write imge file to disk - GD + * Write image file to disk - GD * * Takes an image resource as input and writes the file * to the specified destination @@ -1226,12 +1211,11 @@ class CI_Image_lib { return TRUE; } - // END image_save_gd() // -------------------------------------------------------------------- /** - * Dynamically ouputs an image + * Dynamically outputs an image * * @access public * @param resource @@ -1256,18 +1240,17 @@ class CI_Image_lib { break; } } - // END image_display_gd() // -------------------------------------------------------------------- /** - * Reproportion Image Width/Height + * Re-proportion Image Width/Height * * When creating thumbs, the desired width/height * can end up warping the image due to an incorrect * ratio between the full-sized image and the thumb. * - * This function lets us reproportion the width/height + * This function lets us re-proportion the width/height * if users choose to maintain the aspect ratio when resizing. * * @access public @@ -1303,7 +1286,6 @@ class CI_Image_lib { } } } - // END image_reproportion() // -------------------------------------------------------------------- @@ -1355,7 +1337,6 @@ class CI_Image_lib { return TRUE; } - // END get_image_properties() // -------------------------------------------------------------------- @@ -1406,7 +1387,6 @@ class CI_Image_lib { return $vals; } - // END size_calculator() // -------------------------------------------------------------------- @@ -1447,7 +1427,6 @@ class CI_Image_lib { return $ret; } - // END explode_name() // -------------------------------------------------------------------- @@ -1469,7 +1448,6 @@ class CI_Image_lib { return TRUE; } - // END gd_loaded() // -------------------------------------------------------------------- @@ -1491,7 +1469,6 @@ class CI_Image_lib { return FALSE; } - // END gd_version() // -------------------------------------------------------------------- @@ -1524,7 +1501,6 @@ class CI_Image_lib { log_message('error', $msg); } } - // END set_error() // -------------------------------------------------------------------- @@ -1545,7 +1521,7 @@ class CI_Image_lib { return $str; } - // END display_errors() + } // END Image_lib Class ?> \ No newline at end of file diff --git a/system/libraries/Input.php b/system/libraries/Input.php index 72344e343..57696c8a2 100644 --- a/system/libraries/Input.php +++ b/system/libraries/Input.php @@ -55,7 +55,7 @@ class CI_Input { /** * Sanitize Globals * - * This function does the folowing: + * This function does the following: * * Unsets $_GET data (if query strings are not enabled) * @@ -114,7 +114,7 @@ class CI_Input { // -------------------------------------------------------------------- /** - * Clean Intput Data + * Clean Input Data * * This is a helper function. It escapes data and * standardizes newline characters to \n @@ -399,7 +399,7 @@ class CI_Input { $str = preg_replace('/(\\\\0)+/', '', $str); /* - * Validate standard character entites + * Validate standard character entities * * Add a semicolon if missing. We do this to enable * the conversion of entities to ASCII later. @@ -408,7 +408,7 @@ class CI_Input { $str = preg_replace('#(&\#*\w+)[\x00-\x20]+;#u',"\\1;",$str); /* - * Validate UTF16 two byte encodeing (x00) + * Validate UTF16 two byte encoding (x00) * * Just as above, adds a semicolon if missing. * @@ -501,7 +501,7 @@ class CI_Input { * * Note: This code is a little blunt. It removes * the event handler and anything up to the closing >, - * but it's unlkely to be a problem. + * but it's unlikely to be a problem. * */ $str = preg_replace('#(<[^>]+.*?)(onblur|onchange|onclick|onfocus|onload|onmouseover|onmouseup|onmousedown|onselect|onsubmit|onunload|onkeypress|onkeydown|onkeyup|onresize)[^>]*>#iU',"\\1>",$str); @@ -525,7 +525,7 @@ class CI_Input { * 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 unexecutable. + * rendering the code un-executable. * * For example: eval('some code') * Becomes: eval('some code') diff --git a/system/libraries/Language.php b/system/libraries/Language.php index 00e2fb7e8..825080745 100644 --- a/system/libraries/Language.php +++ b/system/libraries/Language.php @@ -38,7 +38,6 @@ class CI_Language { { log_message('debug', "Language Class Initialized"); } - // END CI_Language() // -------------------------------------------------------------------- @@ -103,7 +102,6 @@ class CI_Language { log_message('debug', 'Language file loaded: language/'.$idiom.'/'.$langfile); return TRUE; } - // END load() // -------------------------------------------------------------------- @@ -118,7 +116,6 @@ class CI_Language { { return ($line == '' OR ! isset($this->language[$line])) ? FALSE : $this->language[$line]; } - // END line() } // END Language Class diff --git a/system/libraries/Loader.php b/system/libraries/Loader.php index 253d916c4..849ee731a 100644 --- a/system/libraries/Loader.php +++ b/system/libraries/Loader.php @@ -820,7 +820,7 @@ class CI_Loader { * Assign to Models * * Makes sure that anything loaded by the loader class (libraries, plugins, etc.) - * will be available to modles, if any exist. + * will be available to models, if any exist. * * @access private * @param object @@ -855,7 +855,7 @@ class CI_Loader { /** * Object to Array * - * Takes an object as input and convers the class variables to array key/vals + * Takes an object as input and converts the class variables to array key/vals * * @access private * @param object diff --git a/system/libraries/Pagination.php b/system/libraries/Pagination.php index b29571eee..26fb93ee4 100644 --- a/system/libraries/Pagination.php +++ b/system/libraries/Pagination.php @@ -199,7 +199,7 @@ class CI_Pagination { } // Kill double slashes. Note: Sometimes we can end up with a double slash - // in the penultimate link so we'll kill all double shashes. + // in the penultimate link so we'll kill all double slashes. $output = preg_replace("#([^:])//+#", "\\1/", $output); // Add the wrapper HTML if exists diff --git a/system/libraries/Parser.php b/system/libraries/Parser.php index a0c9dab9e..ebf7644ac 100644 --- a/system/libraries/Parser.php +++ b/system/libraries/Parser.php @@ -71,7 +71,6 @@ class CI_Parser { return $template; } - // END set_method() // -------------------------------------------------------------------- @@ -88,7 +87,6 @@ class CI_Parser { $this->l_delim = $l; $this->r_delim = $r; } - // END set_method() // -------------------------------------------------------------------- @@ -105,7 +103,6 @@ class CI_Parser { { return str_replace($this->l_delim.$key.$this->r_delim, $val, $string); } - // END set_method() // -------------------------------------------------------------------- @@ -148,7 +145,6 @@ class CI_Parser { return str_replace($match['0'], $str, $string); } - // END set_method() // -------------------------------------------------------------------- @@ -169,7 +165,6 @@ class CI_Parser { return $match; } - // END _match_pair() } // END Parser Class diff --git a/system/libraries/Profiler.php b/system/libraries/Profiler.php index 7fecabd21..6e6fb675f 100644 --- a/system/libraries/Profiler.php +++ b/system/libraries/Profiler.php @@ -46,7 +46,7 @@ class CI_Profiler { * Auto Profiler * * This function cycles through the entire array of mark points and - * matches any two points that are named identially (ending in "_start" + * 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 * diff --git a/system/libraries/Router.php b/system/libraries/Router.php index 94a9a5243..6002027d6 100644 --- a/system/libraries/Router.php +++ b/system/libraries/Router.php @@ -58,7 +58,7 @@ class CI_Router { /** * Set the route mapping * - * This function determies what should be served based on the URI request, + * 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 @@ -322,7 +322,7 @@ class CI_Router { // OK, how about REQUEST_URI? // Note: REQUEST_URI is not supplied in a consistent manner with all platforms so it's - // a diffucult variable to use. We'll try to parse it out correctly. Hopfully one + // a difficult variable to use. We'll try to parse it out correctly. Hopefully one // of the other variables above was available. $path = $this->_parse_request_uri(); if ($path != "") @@ -452,10 +452,10 @@ class CI_Router { return; } - // Loop through the route array looking for wildcards + // Loop through the route array looking for wild-cards foreach (array_slice($this->routes, 1) as $key => $val) { - // Convert wildcards to RegEx + // Convert wild-cards to RegEx $key = str_replace(':any', '.+', str_replace(':num', '[0-9]+', $key)); // Does the RegEx match? diff --git a/system/libraries/Session.php b/system/libraries/Session.php index 8390fd6d4..a47599d12 100644 --- a/system/libraries/Session.php +++ b/system/libraries/Session.php @@ -35,8 +35,7 @@ class CI_Session { var $sess_cookie = 'ci_session'; var $userdata = array(); var $gc_probability = 5; - - + /** * Session Constructor @@ -51,7 +50,6 @@ class CI_Session { log_message('debug', "Session Class Initialized"); $this->sess_run(); } - // END display_errors() // -------------------------------------------------------------------- diff --git a/system/libraries/Sha1.php b/system/libraries/Sha1.php index 13196eb69..971c091ad 100644 --- a/system/libraries/Sha1.php +++ b/system/libraries/Sha1.php @@ -117,7 +117,6 @@ class CI_SHA { return $this->_hex($a).$this->_hex($b).$this->_hex($c).$this->_hex($d).$this->_hex($e); } - // END generate() // -------------------------------------------------------------------- @@ -139,7 +138,6 @@ class CI_SHA { return $str; } - // END _hex() // -------------------------------------------------------------------- @@ -160,7 +158,6 @@ class CI_SHA { return $b ^ $c ^ $d; } - // END _ft() // -------------------------------------------------------------------- @@ -189,7 +186,6 @@ class CI_SHA { return -899497514; } } - // END _kt() // -------------------------------------------------------------------- @@ -206,7 +202,6 @@ class CI_SHA { return ($msw << 16) | ($lsw & 0xFFFF); } - // END _safe_add() // -------------------------------------------------------------------- diff --git a/system/libraries/Table.php b/system/libraries/Table.php index 758676e27..c40c85e17 100644 --- a/system/libraries/Table.php +++ b/system/libraries/Table.php @@ -123,7 +123,7 @@ class CI_Table { return 'Undefined table data'; } - // Compile and validate the templata date + // Compile and validate the template date $this->_compile_template(); diff --git a/system/libraries/Trackback.php b/system/libraries/Trackback.php index 8b6cce16d..74649151d 100644 --- a/system/libraries/Trackback.php +++ b/system/libraries/Trackback.php @@ -120,8 +120,7 @@ class CI_Trackback { } return $return; - } - // END send() + } // -------------------------------------------------------------------- @@ -165,14 +164,13 @@ class CI_Trackback { return TRUE; } - // END receive() // -------------------------------------------------------------------- /** * Send Trackback Error Message * - * Allows custom errros to be set. By default it + * Allows custom errors to be set. By default it * sends the "incomplete information" error, as that's * the most common one. * @@ -185,7 +183,6 @@ class CI_Trackback { echo "\n\n1\n".$message."\n"; exit; } - // END send_error() // -------------------------------------------------------------------- @@ -203,7 +200,6 @@ class CI_Trackback { echo "\n\n0\n"; exit; } - // END send_success() // -------------------------------------------------------------------- @@ -218,7 +214,6 @@ class CI_Trackback { { return ( ! isset($this->data[$item])) ? '' : $this->data[$item]; } - // END data() // -------------------------------------------------------------------- @@ -287,7 +282,6 @@ class CI_Trackback { return TRUE; } - // END process() // -------------------------------------------------------------------- @@ -326,7 +320,6 @@ class CI_Trackback { return $urls; } - // END extract_urls() // -------------------------------------------------------------------- @@ -348,7 +341,6 @@ class CI_Trackback { $url = "http://".$url; } } - // END validate_url() // -------------------------------------------------------------------- @@ -401,7 +393,6 @@ class CI_Trackback { return $tb_id; } } - // END get_id() // -------------------------------------------------------------------- @@ -428,7 +419,6 @@ class CI_Trackback { return $str; } - // END get_id() // -------------------------------------------------------------------- @@ -467,7 +457,6 @@ class CI_Trackback { } } } - // END get_id() // -------------------------------------------------------------------- @@ -517,7 +506,6 @@ class CI_Trackback { return $out; } - // END convert_ascii() // -------------------------------------------------------------------- @@ -533,7 +521,6 @@ class CI_Trackback { log_message('error', $msg); $this->error_msg[] = $msg; } - // END convert_ascii() // -------------------------------------------------------------------- @@ -555,7 +542,7 @@ class CI_Trackback { return $str; } - // END display_errors() + } // END Trackback Class ?> \ No newline at end of file diff --git a/system/libraries/Unit_test.php b/system/libraries/Unit_test.php index 415162388..6bfc59dc3 100644 --- a/system/libraries/Unit_test.php +++ b/system/libraries/Unit_test.php @@ -220,7 +220,7 @@ class CI_Unit_test { * This lets us set the template to be used to display results * * @access public - * @params string + * @param string * @return void */ function set_template($template) diff --git a/system/libraries/Upload.php b/system/libraries/Upload.php index 5bb506cdb..09a479431 100644 --- a/system/libraries/Upload.php +++ b/system/libraries/Upload.php @@ -284,8 +284,8 @@ class CI_Upload { * Set the file name * * This function takes a filename/path as input and looks for the - * existnace of a file with the same name. If found, it will append a - * number to the end of the filename to avoid overwritting a pre-existing file. + * existence of a file with the same name. If found, it will append a + * number to the end of the filename to avoid overwriting a pre-existing file. * * @access public * @param string -- cgit v1.2.3-24-g4f1b From e334c472fb4be44feec3a73402fc4a2b062cbfc0 Mon Sep 17 00:00:00 2001 From: admin Date: Sat, 21 Oct 2006 19:44:22 +0000 Subject: --- system/application/config/config.php | 44 +- system/application/config/database.php | 6 +- system/application/config/routes.php | 10 +- system/application/config/user_agents.php | 2 +- system/application/errors/error_404.php | 6 +- system/application/errors/error_db.php | 6 +- system/application/errors/error_general.php | 6 +- system/application/views/welcome_message.php | 6 +- system/codeigniter/Base4.php | 20 +- system/codeigniter/Base5.php | 34 +- system/codeigniter/CodeIgniter.php | 34 +- system/codeigniter/Common.php | 26 +- system/database/DB.php | 6 +- system/database/DB_active_rec.php | 34 +- system/database/DB_cache.php | 2 +- system/database/DB_driver.php | 176 ++-- system/database/DB_result.php | 52 +- system/database/DB_utility.php | 14 +- system/database/drivers/mssql/mssql_driver.php | 26 +- system/database/drivers/mssql/mssql_result.php | 10 +- system/database/drivers/mssql/mssql_utility.php | 6 +- system/database/drivers/mysql/mysql_driver.php | 44 +- system/database/drivers/mysql/mysql_result.php | 8 +- system/database/drivers/mysql/mysql_utility.php | 52 +- system/database/drivers/mysqli/mysqli_driver.php | 34 +- system/database/drivers/mysqli/mysqli_result.php | 10 +- system/database/drivers/mysqli/mysqli_utility.php | 54 +- system/database/drivers/oci8/oci8_driver.php | 902 ++++++++++----------- system/database/drivers/oci8/oci8_result.php | 308 +++---- system/database/drivers/oci8/oci8_utility.php | 4 +- system/database/drivers/odbc/odbc_driver.php | 28 +- system/database/drivers/odbc/odbc_result.php | 8 +- system/database/drivers/odbc/odbc_utility.php | 8 +- system/database/drivers/postgre/postgre_driver.php | 28 +- system/database/drivers/postgre/postgre_result.php | 8 +- .../database/drivers/postgre/postgre_utility.php | 6 +- system/database/drivers/sqlite/sqlite_driver.php | 38 +- system/database/drivers/sqlite/sqlite_result.php | 6 +- system/database/drivers/sqlite/sqlite_utility.php | 6 +- system/fonts/texb.ttf | Bin 143830 -> 143821 bytes system/helpers/array_helper.php | 4 +- system/helpers/cookie_helper.php | 10 +- system/helpers/date_helper.php | 32 +- system/helpers/directory_helper.php | 20 +- system/helpers/download_helper.php | 8 +- system/helpers/file_helper.php | 14 +- system/helpers/form_helper.php | 10 +- system/helpers/html_helper.php | 4 +- system/helpers/inflector_helper.php | 4 +- system/helpers/security_helper.php | 8 +- system/helpers/string_helper.php | 20 +- system/helpers/text_helper.php | 68 +- system/helpers/typography_helper.php | 32 +- system/helpers/url_helper.php | 38 +- system/helpers/xml_helper.php | 6 +- system/libraries/Benchmark.php | 62 +- system/libraries/Calendar.php | 132 +-- system/libraries/Config.php | 32 +- system/libraries/Controller.php | 30 +- system/libraries/Email.php | 127 ++- system/libraries/Encrypt.php | 32 +- system/libraries/Exceptions.php | 14 +- system/libraries/Hooks.php | 12 +- system/libraries/Image_lib.php | 136 ++-- system/libraries/Input.php | 38 +- system/libraries/Language.php | 10 +- system/libraries/Loader.php | 34 +- system/libraries/Log.php | 8 +- system/libraries/Model.php | 6 +- system/libraries/Output.php | 48 +- system/libraries/Pagination.php | 122 +-- system/libraries/Parser.php | 6 +- system/libraries/Profiler.php | 4 +- system/libraries/Router.php | 24 +- system/libraries/Session.php | 102 +-- system/libraries/Sha1.php | 292 +++---- system/libraries/Table.php | 6 +- system/libraries/Trackback.php | 54 +- system/libraries/URI.php | 18 +- system/libraries/Unit_test.php | 16 +- system/libraries/Upload.php | 418 +++++----- system/libraries/User_agent.php | 20 +- system/libraries/Validation.php | 52 +- system/libraries/Xmlrpc.php | 152 ++-- system/libraries/Xmlrpcs.php | 50 +- system/libraries/Zip.php | 46 +- system/plugins/captcha_pi.php | 54 +- system/plugins/js_calendar_pi.php | 26 +- system/scaffolding/Scaffolding.php | 8 +- system/scaffolding/views/stylesheet.css | 2 +- 90 files changed, 2274 insertions(+), 2275 deletions(-) (limited to 'system') diff --git a/system/application/config/config.php b/system/application/config/config.php index ab4f445f2..0ed58d940 100644 --- a/system/application/config/config.php +++ b/system/application/config/config.php @@ -5,7 +5,7 @@ | Base Site URL |-------------------------------------------------------------------------- | -| URL to your Code Igniter root. Typically this will be your base URL, +| URL to your Code Igniter root. Typically this will be your base URL, | WITH a trailing slash: | | http://www.your-site.com/ @@ -18,8 +18,8 @@ $config['base_url'] = "http://127.0.0.1/CodeIgniter/"; | Index File |-------------------------------------------------------------------------- | -| Typically this will be your index.php file, unless you've renamed it to -| something else. If you are using mod_rewrite to remove the page set this +| Typically this will be your index.php file, unless you've renamed it to +| something else. If you are using mod_rewrite to remove the page set this | variable so that it is blank. | */ @@ -30,15 +30,15 @@ $config['index_page'] = "index.php"; | URI PROTOCOL |-------------------------------------------------------------------------- | -| This item determines which server global should be used to retrieve the +| This item determines which server global should be used to retrieve the | URI string. The default setting of "AUTO" works for most servers. | If your links do not seem to work, try one of the other delicious flavors: -| +| | 'AUTO' Default - auto detects -| 'PATH_INFO' Uses the PATH_INFO +| 'PATH_INFO' Uses the PATH_INFO | 'QUERY_STRING' Uses the QUERY_STRING | 'REQUEST_URI' Uses the REQUEST_URI -| 'ORIG_PATH_INFO' Uses the ORIG_PATH_INFO +| 'ORIG_PATH_INFO' Uses the ORIG_PATH_INFO | */ $config['uri_protocol'] = "AUTO"; @@ -50,7 +50,7 @@ $config['uri_protocol'] = "AUTO"; | | This option allows you to add a suffix to all URLs generated by Code Igniter. | For more information please see the user guide: -| +| | http://www.codeigniter.com/user_guide/general/urls.html */ @@ -61,7 +61,7 @@ $config['url_suffix'] = ""; | Default Language |-------------------------------------------------------------------------- | -| This determines which set of language files should be used. Make sure +| This determines which set of language files should be used. Make sure | there is an available translation if you intend to use something other | than english. | @@ -88,7 +88,7 @@ $config['enable_hooks'] = TRUE; | | This item allows you to set the filename/classname prefix when extending | native libraries. For more information please see the user guide: -| +| | http://www.codeigniter.com/user_guide/general/core_classes.html | http://www.codeigniter.com/user_guide/general/creating_libraries.html | @@ -109,7 +109,7 @@ $config['subclass_prefix'] = 'MY_'; | as few characters as possible. By default only these are allowed: a-z 0-9~%.:_- | | Leave blank to allow all characters -- but only if you are insane. -| +| | DO NOT CHANGE THIS UNLESS YOU FULLY UNDERSTAND THE REPERCUSSIONS!! | */ @@ -147,7 +147,7 @@ $config['function_trigger'] = 'm'; | Error Logging |-------------------------------------------------------------------------- | -| You can enable error logging by setting a threshold over zero. The +| You can enable error logging by setting a threshold over zero. The | threshold determines what gets logged. Threshold options are: | | 0 = Error logging TURNED OFF @@ -156,7 +156,7 @@ $config['function_trigger'] = 'm'; | 3 = Informational Messages | 4 = All Messages | -| For a live site you'll usually only enable Errors (1) to be logged otherwise +| For a live site you'll usually only enable Errors (1) to be logged otherwise | your log files will fill up very fast. | */ @@ -200,7 +200,7 @@ $config['cache_path'] = ''; | Encryption Key |-------------------------------------------------------------------------- | -| If you use the Encryption class or the Sessions class with encryption +| If you use the Encryption class or the Sessions class with encryption | enabled you MUST set an encryption key. See the user guide for info. | */ @@ -229,14 +229,14 @@ $config['sess_match_useragent'] = TRUE; |-------------------------------------------------------------------------- | Cookie Related Variables |-------------------------------------------------------------------------- -| +| | 'cookie_prefix' = Set a prefix if you need to avoid collisions | 'cookie_domain' = Set to .your-domain.com for site-wide cookies | 'cookie_path' = Typically will be a forward slash | */ $config['cookie_prefix'] = ""; -$config['cookie_domain'] = ""; +$config['cookie_domain'] = ""; $config['cookie_path'] = "/"; /* @@ -244,7 +244,7 @@ $config['cookie_path'] = "/"; | Global XSS Filtering |-------------------------------------------------------------------------- | -| Determines whether the XSS filter is always active when GET, POST or +| Determines whether the XSS filter is always active when GET, POST or | COOKIE data is encountered | */ @@ -256,13 +256,13 @@ $config['global_xss_filtering'] = FALSE; |-------------------------------------------------------------------------- | | Enables Gzip output compression for faster page loads. When enabled, -| the output class will test whether your server supports Gzip. +| the output class will test whether your server supports Gzip. | Even if it does, however, not all browsers support compression | so enable only if you are reasonably sure your visitors can handle it. | | VERY IMPORTANT: If you are getting a blank page when compression is enabled it | means you are prematurely outputting something to your browser. It could -| even be a line of whitespace at the end of one of your scripts. For +| even be a line of whitespace at the end of one of your scripts. For | compression to work, nothing can be sent before the output buffer is called | by the output class. Do not "echo" any values with compression enabled. | @@ -274,9 +274,9 @@ $config['compress_output'] = FALSE; | Master Time Reference |-------------------------------------------------------------------------- | -| Options are "local" or "gmt". This pref tells the system whether to use -| your server's local time as the master "now" reference, or convert it to -| GMT. See the "date helper" page of the user guide for information +| Options are "local" or "gmt". This pref tells the system whether to use +| your server's local time as the master "now" reference, or convert it to +| GMT. See the "date helper" page of the user guide for information | regarding date handling. | */ diff --git a/system/application/config/database.php b/system/application/config/database.php index 9d8c77831..b3246b6ec 100644 --- a/system/application/config/database.php +++ b/system/application/config/database.php @@ -13,12 +13,12 @@ | ------------------------------------------------------------------- | | ['hostname'] The hostname of your database server. -| ['username'] The username used to connect to the database -| ['password'] The password used to connect to the database +| ['username'] The username used to connect to the database +| ['password'] The password used to connect to the database | ['database'] The name of the database you want to connect to | ['dbdriver'] The database type. ie: mysql. Currently supported: mysql, mysqli, postgre, odbc, mssql -| ['dbprefix'] You can add an optional prefix, which will be added +| ['dbprefix'] You can add an optional prefix, which will be added | to the table name when using the Active Record class | ['pconnect'] TRUE/FALSE - Whether to use a persistent connection | ['db_debug'] TRUE/FALSE - Whether database errors should be displayed. diff --git a/system/application/config/routes.php b/system/application/config/routes.php index 8fa167803..1702e4f4b 100644 --- a/system/application/config/routes.php +++ b/system/application/config/routes.php @@ -3,9 +3,9 @@ | ------------------------------------------------------------------------- | URI ROUTING | ------------------------------------------------------------------------- -| This file lets you re-map URI requests to specific controller functions. +| This file lets you re-map URI requests to specific controller functions. | -| Typically there is a one-to-one relationship between a URL string +| Typically there is a one-to-one relationship between a URL string | and its corresponding controller class/method. The segments in a | URL normally follow this pattern: | @@ -13,7 +13,7 @@ | | In some instances, however, you may want to remap this relationship | so that a different class/function is called than the one -| corresponding to the URL. +| corresponding to the URL. | | Please see the user guide for complete details: | @@ -33,8 +33,8 @@ | | $route['scaffolding_trigger'] = 'scaffolding'; | -| This route lets you se t a "secret" word that will trigger the -| scaffolding feature for added security. Note: Scaffolding must be +| This route lets you se t a "secret" word that will trigger the +| scaffolding feature for added security. Note: Scaffolding must be | enabled in the controller in which you intend to use it. | */ diff --git a/system/application/config/user_agents.php b/system/application/config/user_agents.php index a799f06bd..6fa7b4a7e 100644 --- a/system/application/config/user_agents.php +++ b/system/application/config/user_agents.php @@ -4,7 +4,7 @@ | USER AGENT TYPES | ------------------------------------------------------------------- | This file contains four arrays of user agent data. It is used by the -| User Agent Class to help identify browser, platform, robot, and +| User Agent Class to help identify browser, platform, robot, and | mobile device data. The array keys are used to identify the device | and the array values are used to set the actual name of the item. | diff --git a/system/application/errors/error_404.php b/system/application/errors/error_404.php index e5fa8f9db..bfe9444b2 100644 --- a/system/application/errors/error_404.php +++ b/system/application/errors/error_404.php @@ -4,9 +4,9 @@ 404 Page Not Found - - -- cgit v1.2.3-24-g4f1b From ebfa686046bb98c757d1b41c81eb867478036e68 Mon Sep 17 00:00:00 2001 From: admin Date: Sun, 5 Nov 2006 21:31:00 +0000 Subject: --- system/libraries/Ftp.php | 2 +- system/libraries/Profiler.php | 2 +- system/libraries/User_agent.php | 2 +- system/libraries/Zip.php | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) (limited to 'system') diff --git a/system/libraries/Ftp.php b/system/libraries/Ftp.php index 1572a587c..f213736fb 100644 --- a/system/libraries/Ftp.php +++ b/system/libraries/Ftp.php @@ -22,7 +22,7 @@ * @subpackage Libraries * @category Libraries * @author Rick Ellis - * @link http://www.codeigniter.com/user_guide/libraries/encryption.html + * @link http://www.codeigniter.com/user_guide/libraries/ftp.html */ class CI_FTP { diff --git a/system/libraries/Profiler.php b/system/libraries/Profiler.php index 1d78da8a8..5b0f6e2b7 100644 --- a/system/libraries/Profiler.php +++ b/system/libraries/Profiler.php @@ -28,7 +28,7 @@ * @subpackage Libraries * @category Libraries * @author Rick Ellis - * @link http://www.codeigniter.com/user_guide/libraries/benchmark.html + * @link http://www.codeigniter.com/user_guide/general/profiling.html */ class CI_Profiler { diff --git a/system/libraries/User_agent.php b/system/libraries/User_agent.php index b217367fe..8d160672f 100644 --- a/system/libraries/User_agent.php +++ b/system/libraries/User_agent.php @@ -24,7 +24,7 @@ * @subpackage Libraries * @category User Agent * @author Rick Ellis - * @link http://www.codeigniter.com/user_guide/libraries/uri.html + * @link http://www.codeigniter.com/user_guide/libraries/user_agent.html */ class CI_User_agent { diff --git a/system/libraries/Zip.php b/system/libraries/Zip.php index 828ef0c25..1ff175fe2 100644 --- a/system/libraries/Zip.php +++ b/system/libraries/Zip.php @@ -28,7 +28,7 @@ * @subpackage Libraries * @category Encryption * @author Rick Ellis - * @link http://www.codeigniter.com/user_guide/general/encryption.html + * @link http://www.codeigniter.com/user_guide/libraries/zip.html */ class CI_Zip { -- cgit v1.2.3-24-g4f1b From 325197e700564f8e4e0ba7c9fc82abfd85f451b0 Mon Sep 17 00:00:00 2001 From: Rick Ellis Date: Mon, 20 Nov 2006 17:29:05 +0000 Subject: --- system/application/config/config.php | 4 ++-- system/codeigniter/Common.php | 8 ++++---- system/database/drivers/oci8/oci8_result.php | 24 +++++++++++------------- system/libraries/Exceptions.php | 6 ++++-- system/libraries/Input.php | 6 ++++-- system/libraries/User_agent.php | 1 + 6 files changed, 26 insertions(+), 23 deletions(-) (limited to 'system') diff --git a/system/application/config/config.php b/system/application/config/config.php index 2f385a6ef..b1598b341 100644 --- a/system/application/config/config.php +++ b/system/application/config/config.php @@ -223,9 +223,9 @@ $config['encryption_key'] = ""; $config['sess_cookie_name'] = 'ci_session'; $config['sess_expiration'] = 7200; $config['sess_encrypt_cookie'] = FALSE; -$config['sess_use_database'] = TRUE; +$config['sess_use_database'] = FALSE; $config['sess_table_name'] = 'ci_sessions'; -$config['sess_match_ip'] = TRUE; +$config['sess_match_ip'] = FALSE; $config['sess_match_useragent'] = TRUE; /* diff --git a/system/codeigniter/Common.php b/system/codeigniter/Common.php index 41e13bee6..4576cd964 100644 --- a/system/codeigniter/Common.php +++ b/system/codeigniter/Common.php @@ -106,14 +106,14 @@ function &get_config() { if ( ! file_exists(APPPATH.'config/config'.EXT)) { - show_error('The configuration file config'.EXT.' does not exist.'); + exit('The configuration file config'.EXT.' does not exist.'); } require(APPPATH.'config/config'.EXT); if ( ! isset($config) OR ! is_array($config)) { - show_error('Your config file does not appear to be formatted correctly.'); + exit('Your config file does not appear to be formatted correctly.'); } $main_conf[0] =& $config; @@ -210,8 +210,8 @@ function log_message($level = 'error', $message, $php_error = FALSE) /** * Exception Handler * -* This is the custom exception handler we defined at the -* top of this file. The main reason we use this is permit +* This is the custom exception handler that is declaired at the top +* of Codeigniter.php. The main reason we use this is permit * PHP errors to be logged in our own log files since we may * not have access to server logs. Since this function * effectively intercepts PHP errors, however, we also need diff --git a/system/database/drivers/oci8/oci8_result.php b/system/database/drivers/oci8/oci8_result.php index af30457b3..fb4ed1f0d 100644 --- a/system/database/drivers/oci8/oci8_result.php +++ b/system/database/drivers/oci8/oci8_result.php @@ -31,21 +31,24 @@ class CI_DB_oci8_result extends CI_DB_result { var $limit_used; /** - * Number of rows in the result set + * Number of rows in the result set. + * + * Oracle doesn't have a graceful way to retun the number of rows + * so we have to use what amounts to a hack. + * * * @access public * @return integer */ function num_rows() { - if (function_exists('oci_num_rows')) - { - return @oci_num_rows($this->stmt_id); - } - else + $rowcount = count($this->result_array()); + @ociexecute($this->stmt_id); + if ($this->curs_id) { - return @ocirowcount($this->stmt_id); + @ociexecute($this->curs_id); } + return $rowcount; } // -------------------------------------------------------------------- @@ -175,12 +178,7 @@ class CI_DB_oci8_result extends CI_DB_result { { $id = ($this->curs_id) ? $this->curs_id : $this->stmt_id; - while ($row = oci_fetch_object($id)) - { - $result[] = $row; - } - - return $result; + return @oci_fetch_object($id); } // If PHP 4 is being used we have to build our own result diff --git a/system/libraries/Exceptions.php b/system/libraries/Exceptions.php index 8f90ff8f9..839093911 100644 --- a/system/libraries/Exceptions.php +++ b/system/libraries/Exceptions.php @@ -30,6 +30,7 @@ class CI_Exceptions { var $message; var $filename; var $line; + var $ob_level; var $levels = array( E_ERROR => 'Error', @@ -53,6 +54,7 @@ class CI_Exceptions { */ function CI_Exceptions() { + $this->ob_level = ob_get_level(); // Note: Do not log messages from this constructor. } @@ -115,7 +117,7 @@ class CI_Exceptions { { $message = '

'.implode('

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

'; - if (ob_get_level() > 1) + if (ob_get_level() > $this->ob_level + 1) { ob_end_flush(); } @@ -151,7 +153,7 @@ class CI_Exceptions { $filepath = $x[count($x)-2].'/'.end($x); } - if (ob_get_level() > 1) + if (ob_get_level() > $this->ob_level + 1) { ob_end_flush(); } diff --git a/system/libraries/Input.php b/system/libraries/Input.php index b630bf6b8..801762073 100644 --- a/system/libraries/Input.php +++ b/system/libraries/Input.php @@ -73,13 +73,15 @@ class CI_Input { { if ( ! is_array($global)) { - unset($$global); + global $global; + $$global = NULL; } else { foreach ($global as $key => $val) { - unset($$key); + global $$key; + $$key = NULL; } } } diff --git a/system/libraries/User_agent.php b/system/libraries/User_agent.php index 8d160672f..95eccd124 100644 --- a/system/libraries/User_agent.php +++ b/system/libraries/User_agent.php @@ -186,6 +186,7 @@ class CI_User_agent { $this->is_browser = TRUE; $this->version = $match[1]; $this->browser = $val; + $this->_set_mobile(); return TRUE; } } -- cgit v1.2.3-24-g4f1b From 6b151050a80aa62808a5afc5a4c934f8bfb47512 Mon Sep 17 00:00:00 2001 From: Rick Ellis Date: Thu, 23 Nov 2006 18:08:26 +0000 Subject: --- system/database/drivers/mysqli/mysqli_result.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system') diff --git a/system/database/drivers/mysqli/mysqli_result.php b/system/database/drivers/mysqli/mysqli_result.php index be7ec356c..57c89ea80 100644 --- a/system/database/drivers/mysqli/mysqli_result.php +++ b/system/database/drivers/mysqli/mysqli_result.php @@ -63,7 +63,7 @@ class CI_DB_mysqli_result extends CI_DB_result { function list_fields() { $field_names = array(); - while ($field = mysql_fetch_field($this->result_id)) + while ($field = mysqli_fetch_field($this->result_id)) { $field_names[] = $field->name; } -- cgit v1.2.3-24-g4f1b From 257651d498cbd8c998520b12a1001524cfb88d69 Mon Sep 17 00:00:00 2001 From: Rick Ellis Date: Thu, 23 Nov 2006 18:40:13 +0000 Subject: --- system/application/config/database.php | 2 +- system/codeigniter/CodeIgniter.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'system') diff --git a/system/application/config/database.php b/system/application/config/database.php index 5cfd76347..5293a5a6a 100644 --- a/system/application/config/database.php +++ b/system/application/config/database.php @@ -43,7 +43,7 @@ $db['default']['active_r'] = TRUE; $db['default']['pconnect'] = TRUE; $db['default']['db_debug'] = TRUE; $db['default']['cache_on'] = FALSE; -$db['default']['cachedir'] = APPPATH.'dbcache/'; +$db['default']['cachedir'] = ""; ?> \ No newline at end of file diff --git a/system/codeigniter/CodeIgniter.php b/system/codeigniter/CodeIgniter.php index 88659a744..3008b2ff2 100644 --- a/system/codeigniter/CodeIgniter.php +++ b/system/codeigniter/CodeIgniter.php @@ -28,7 +28,7 @@ */ // CI Version -define('APPVER', '1.5.0.1'); +define('APPVER', '1.5.0.2'); /* * ------------------------------------------------------ -- cgit v1.2.3-24-g4f1b From d1c638f0e9d1d838d80ff3641f1dc889f488cbf6 Mon Sep 17 00:00:00 2001 From: Rick Ellis Date: Thu, 23 Nov 2006 18:56:39 +0000 Subject: --- system/database/DB_driver.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'system') diff --git a/system/database/DB_driver.php b/system/database/DB_driver.php index 03631d69a..2a8510e13 100644 --- a/system/database/DB_driver.php +++ b/system/database/DB_driver.php @@ -372,8 +372,8 @@ class CI_DB_driver { if ( ! class_exists($driver)) { - include(BASEPATH.'database/DB_result'.EXT); - include(BASEPATH.'database/drivers/'.$this->dbdriver.'/'.$this->dbdriver.'_result'.EXT); + include_once(BASEPATH.'database/DB_result'.EXT); + include_once(BASEPATH.'database/drivers/'.$this->dbdriver.'/'.$this->dbdriver.'_result'.EXT); } return $driver; -- cgit v1.2.3-24-g4f1b From 6f62816ef1212a501d5f6c27110e2e5d81a6ebe2 Mon Sep 17 00:00:00 2001 From: Rick Ellis Date: Fri, 24 Nov 2006 01:17:45 +0000 Subject: --- system/libraries/Loader.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system') diff --git a/system/libraries/Loader.php b/system/libraries/Loader.php index 41c0a9b94..0947046ed 100644 --- a/system/libraries/Loader.php +++ b/system/libraries/Loader.php @@ -146,7 +146,7 @@ class CI_Loader { show_error('Unable to locate the model you have specified: '.$model); } - if ($db_conn !== FALSE) + if ($db_conn !== FALSE AND ! class_exists('CI_DB')) { if ($db_conn === TRUE) $db_conn = ''; -- cgit v1.2.3-24-g4f1b From 40a7c6805f4a65605963f10dc2db0fc748710779 Mon Sep 17 00:00:00 2001 From: paulburdick Date: Sat, 13 Jan 2007 00:03:37 +0000 Subject: --- system/libraries/Input.php | 34 ++++++++++++++++++++++++++-------- 1 file changed, 26 insertions(+), 8 deletions(-) (limited to 'system') diff --git a/system/libraries/Input.php b/system/libraries/Input.php index 801762073..4fd2061c7 100644 --- a/system/libraries/Input.php +++ b/system/libraries/Input.php @@ -366,14 +366,14 @@ class CI_Input { * XSS Clean * * Sanitizes data so that Cross Site Scripting Hacks can be - * prevented.Ê This function does a fair amount of work but + * 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, + * 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 + * 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 @@ -447,6 +447,24 @@ class CI_Input { $str); } } + + /* + * Not Allowed Under Any Conditions + */ + $bad = array( + 'document.cookie' => '[removed]', + 'document.write' => '[removed]', + 'window.location' => '[removed]', + "javascript\s*:" => '[removed]', + "Redirect\s+302" => '[removed]', + '' => '-->' + ); + + foreach ($bad as $key => $val) + { + $str = preg_replace("#".$key."#i", $val, $str); + } /* * Convert all tabs to spaces @@ -542,11 +560,11 @@ class CI_Input { * */ $bad = array( - 'document.cookie' => '', - 'document.write' => '', - 'window.location' => '', - "javascript\s*:" => '', - "Redirect\s+302" => '', + 'document.cookie' => '[removed]', + 'document.write' => '[removed]', + 'window.location' => '[removed]', + "javascript\s*:" => '[removed]', + "Redirect\s+302" => '[removed]', '' => '-->' ); -- cgit v1.2.3-24-g4f1b From 17f4d73ff388dbcb4d9fbd4f79a0f9150ddc8c7e Mon Sep 17 00:00:00 2001 From: Derek Allard Date: Sat, 27 Jan 2007 17:23:13 +0000 Subject: unset the value attribute in textarea --- system/helpers/form_helper.php | 806 +++++++++++++++++++++-------------------- 1 file changed, 404 insertions(+), 402 deletions(-) (limited to 'system') diff --git a/system/helpers/form_helper.php b/system/helpers/form_helper.php index 7d594d72c..8186d4ccd 100644 --- a/system/helpers/form_helper.php +++ b/system/helpers/form_helper.php @@ -1,403 +1,405 @@ -config->site_url($action).'"'; - - if ( ! isset($attributes['method'])) - { - $form .= ' method="post"'; - } - - if (is_array($attributes) AND count($attributes) > 0) - { - foreach ($attributes as $key => $val) - { - $form .= ' '.$key.'="'.$val.'"'; - } - } - - $form .= '>'; - - if (is_array($hidden) AND count($hidden > 0)) - { - $form .= form_hidden($hidden); - } - - 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 - */ -function form_open_multipart($action, $attributes = array(), $hidden = array()) -{ - $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 - */ -function form_hidden($name, $value = '') -{ - if ( ! is_array($name)) - { - return ''; - } - - $form = ''; - foreach ($name as $name => $value) - { - $form .= ''; - } - - return $form; -} - -// ------------------------------------------------------------------------ - -/** - * Text Input Field - * - * @access public - * @param mixed - * @param string - * @param string - * @return string - */ -function form_input($data = '', $value = '', $extra = '') -{ - $defaults = array('type' => 'text', 'name' => (( ! is_array($data)) ? $data : ''), 'value' => $value, 'maxlength' => '500', 'size' => '50'); - - return "\n"; -} - -// ------------------------------------------------------------------------ - -/** - * Password Field - * - * Identical to the input function but adds the "password" type - * - * @access public - * @param mixed - * @param string - * @param string - * @return string - */ -function form_password($data = '', $value = '', $extra = '') -{ - if ( ! is_array($data)) - { - $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 - */ -function form_upload($data = '', $value = '', $extra = '') -{ - if ( ! is_array($data)) - { - $data = array('name' => $data); - } - - $data['type'] = 'file'; - return form_input($data, $value, $extra); -} - -// ------------------------------------------------------------------------ - -/** - * Textarea field - * - * @access public - * @param mixed - * @param string - * @param string - * @return string - */ -function form_textarea($data = '', $value = '', $extra = '') -{ - $defaults = array('name' => (( ! is_array($data)) ? $data : ''), 'cols' => '90', 'rows' => '12'); - - $val = (( ! is_array($data) OR ! isset($data['value'])) ? $value : $data['value']); - - return "\n"; -} - -// ------------------------------------------------------------------------ - -/** - * Drop-down Menu - * - * @access public - * @param string - * @param array - * @param string - * @param string - * @return string - */ -function form_dropdown($name = '', $options = array(), $selected = '', $extra = '') -{ - if ($extra != '') $extra = ' '.$extra; - - $form = ''; - - return $form; -} - -// ------------------------------------------------------------------------ - -/** - * Checkbox Field - * - * @access public - * @param mixed - * @param string - * @param bool - * @param string - * @return string - */ -function form_checkbox($data = '', $value = '', $checked = TRUE, $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']); - } - - 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 - */ -function form_radio($data = '', $value = '', $checked = TRUE, $extra = '') -{ - if ( ! is_array($data)) - { - $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 - */ -function form_submit($data = '', $value = '', $extra = '') -{ - $defaults = array('type' => 'submit', 'name' => (( ! is_array($data)) ? $data : ''), 'value' => $value); - - return "\n"; -} - -// ------------------------------------------------------------------------ - -/** - * Form Close Tag - * - * @access public - * @param string - * @return string - */ -function form_close($extra = '') -{ - return "\n".$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 - */ -function form_prep($str = '') -{ - if ($str === '') - { - return ''; - } - - $temp = '__TEMP_AMPERSANDS__'; - - // Replace entities to temporary markers so that - // htmlspecialchars won't mess them up - $str = preg_replace("/&#(\d+);/", "$temp\\1;", $str); - $str = preg_replace("/&(\w+);/", "$temp\\1;", $str); - - $str = htmlspecialchars($str); - - // In case htmlspecialchars misses these. - $str = str_replace(array("'", '"'), array("'", """), $str); - - // Decode the temp markers back to entities - $str = preg_replace("/$temp(\d+);/","&#\\1;",$str); - $str = preg_replace("/$temp(\w+);/","&\\1;",$str); - - return $str; -} - -// ------------------------------------------------------------------------ - -/** - * Parse the form attributes - * - * Helper function used by some of the form helpers - * - * @access private - * @param array - * @param array - * @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 = form_prep($val); - } - - $att .= $key . '="' . $val . '" '; - } - - return $att; -} - +config->site_url($action).'"'; + + if ( ! isset($attributes['method'])) + { + $form .= ' method="post"'; + } + + if (is_array($attributes) AND count($attributes) > 0) + { + foreach ($attributes as $key => $val) + { + $form .= ' '.$key.'="'.$val.'"'; + } + } + + $form .= '>'; + + if (is_array($hidden) AND count($hidden > 0)) + { + $form .= form_hidden($hidden); + } + + 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 + */ +function form_open_multipart($action, $attributes = array(), $hidden = array()) +{ + $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 + */ +function form_hidden($name, $value = '') +{ + if ( ! is_array($name)) + { + return ''; + } + + $form = ''; + foreach ($name as $name => $value) + { + $form .= ''; + } + + return $form; +} + +// ------------------------------------------------------------------------ + +/** + * Text Input Field + * + * @access public + * @param mixed + * @param string + * @param string + * @return string + */ +function form_input($data = '', $value = '', $extra = '') +{ + $defaults = array('type' => 'text', 'name' => (( ! is_array($data)) ? $data : ''), 'value' => $value, 'maxlength' => '500', 'size' => '50'); + + return "\n"; +} + +// ------------------------------------------------------------------------ + +/** + * Password Field + * + * Identical to the input function but adds the "password" type + * + * @access public + * @param mixed + * @param string + * @param string + * @return string + */ +function form_password($data = '', $value = '', $extra = '') +{ + if ( ! is_array($data)) + { + $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 + */ +function form_upload($data = '', $value = '', $extra = '') +{ + if ( ! is_array($data)) + { + $data = array('name' => $data); + } + + $data['type'] = 'file'; + return form_input($data, $value, $extra); +} + +// ------------------------------------------------------------------------ + +/** + * Textarea field + * + * @access public + * @param mixed + * @param string + * @param string + * @return string + */ +function form_textarea($data = '', $value = '', $extra = '') +{ + $defaults = array('name' => (( ! is_array($data)) ? $data : ''), 'cols' => '90', 'rows' => '12'); + + $val = (( ! is_array($data) OR ! isset($data['value'])) ? $value : $data['value']); + + unset ($data['value']); // textareas don't use the value attribute + + return "\n"; +} + +// ------------------------------------------------------------------------ + +/** + * Drop-down Menu + * + * @access public + * @param string + * @param array + * @param string + * @param string + * @return string + */ +function form_dropdown($name = '', $options = array(), $selected = '', $extra = '') +{ + if ($extra != '') $extra = ' '.$extra; + + $form = ''; + + return $form; +} + +// ------------------------------------------------------------------------ + +/** + * Checkbox Field + * + * @access public + * @param mixed + * @param string + * @param bool + * @param string + * @return string + */ +function form_checkbox($data = '', $value = '', $checked = TRUE, $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']); + } + + 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 + */ +function form_radio($data = '', $value = '', $checked = TRUE, $extra = '') +{ + if ( ! is_array($data)) + { + $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 + */ +function form_submit($data = '', $value = '', $extra = '') +{ + $defaults = array('type' => 'submit', 'name' => (( ! is_array($data)) ? $data : ''), 'value' => $value); + + return "\n"; +} + +// ------------------------------------------------------------------------ + +/** + * Form Close Tag + * + * @access public + * @param string + * @return string + */ +function form_close($extra = '') +{ + return "\n".$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 + */ +function form_prep($str = '') +{ + if ($str === '') + { + return ''; + } + + $temp = '__TEMP_AMPERSANDS__'; + + // Replace entities to temporary markers so that + // htmlspecialchars won't mess them up + $str = preg_replace("/&#(\d+);/", "$temp\\1;", $str); + $str = preg_replace("/&(\w+);/", "$temp\\1;", $str); + + $str = htmlspecialchars($str); + + // In case htmlspecialchars misses these. + $str = str_replace(array("'", '"'), array("'", """), $str); + + // Decode the temp markers back to entities + $str = preg_replace("/$temp(\d+);/","&#\\1;",$str); + $str = preg_replace("/$temp(\w+);/","&\\1;",$str); + + return $str; +} + +// ------------------------------------------------------------------------ + +/** + * Parse the form attributes + * + * Helper function used by some of the form helpers + * + * @access private + * @param array + * @param array + * @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 = form_prep($val); + } + + $att .= $key . '="' . $val . '" '; + } + + return $att; +} + ?> \ No newline at end of file -- cgit v1.2.3-24-g4f1b From 5932c867a10ed38d58a51b40a3898ea70605f3cd Mon Sep 17 00:00:00 2001 From: Derek Allard Date: Sat, 27 Jan 2007 17:44:54 +0000 Subject: added set_caption() --- system/libraries/Table.php | 853 +++++++++++++++++++++++---------------------- 1 file changed, 438 insertions(+), 415 deletions(-) (limited to 'system') diff --git a/system/libraries/Table.php b/system/libraries/Table.php index 1b25a441a..b8ce9491a 100644 --- a/system/libraries/Table.php +++ b/system/libraries/Table.php @@ -1,416 +1,439 @@ -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 = (is_array($args[0])) ? $args[0] : $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_slice($array, 0, $col_limit); - $array = array_diff($array, $temp); - - 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[] = (is_array($args[0])) ? $args[0] : $args; - } - - // -------------------------------------------------------------------- - - /** - * 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(); - - - // Build the table! - - $out = $this->template['table_open']; - $out .= $this->newline; - - // Is there a table heading to display? - if (count($this->heading) > 0) - { - $out .= $this->template['heading_row_start']; - $out .= $this->newline; - - foreach($this->heading as $heading) - { - $out .= $this->template['heading_cell_start']; - $out .= $heading; - $out .= $this->template['heading_cell_end']; - } - - $out .= $this->template['heading_row_end']; - $out .= $this->newline; - } - - // Build the table rows - if (count($this->rows) > 0) - { - $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) - { - $out .= $this->template['cell_'.$name.'start']; - - if ($cell == "") - { - $out .= $this->empty_cells; - } - else - { - $out .= $cell; - } - - $out .= $this->template['cell_'.$name.'end']; - } - - $out .= $this->template['row_'.$name.'end']; - $out .= $this->newline; - } - } - - $out .= $this->template['table_close']; - - return $out; - } - - // -------------------------------------------------------------------- - - /** - * Clears the table arrays. Useful if multiple tables are beting 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 = $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[] = $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 ( ! is_array($row)) - { - $this->rows[] = $data; - break; - } - - // 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 = $row; - } - else - { - $this->rows[] = $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','heading_row_start', 'heading_row_end', 'heading_cell_start', 'heading_cell_end', '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' => '', - - 'heading_row_start' => '', - 'heading_row_end' => '', - 'heading_cell_start' => '', - - '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' => '
' - ); - } - - -} - +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 = (is_array($args[0])) ? $args[0] : $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_slice($array, 0, $col_limit); + $array = array_diff($array, $temp); + + 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[] = (is_array($args[0])) ? $args[0] : $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(); + + + // 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['heading_row_start']; + $out .= $this->newline; + + foreach($this->heading as $heading) + { + $out .= $this->template['heading_cell_start']; + $out .= $heading; + $out .= $this->template['heading_cell_end']; + } + + $out .= $this->template['heading_row_end']; + $out .= $this->newline; + } + + // Build the table rows + if (count($this->rows) > 0) + { + $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) + { + $out .= $this->template['cell_'.$name.'start']; + + if ($cell == "") + { + $out .= $this->empty_cells; + } + else + { + $out .= $cell; + } + + $out .= $this->template['cell_'.$name.'end']; + } + + $out .= $this->template['row_'.$name.'end']; + $out .= $this->newline; + } + } + + $out .= $this->template['table_close']; + + return $out; + } + + // -------------------------------------------------------------------- + + /** + * Clears the table arrays. Useful if multiple tables are beting 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 = $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[] = $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 ( ! is_array($row)) + { + $this->rows[] = $data; + break; + } + + // 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 = $row; + } + else + { + $this->rows[] = $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','heading_row_start', 'heading_row_end', 'heading_cell_start', 'heading_cell_end', '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' => '', + + 'heading_row_start' => '', + 'heading_row_end' => '', + 'heading_cell_start' => '', + + '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' => '
' + ); + } + + +} + ?> \ No newline at end of file -- cgit v1.2.3-24-g4f1b From c250b144dcfab2c2667b6eec3fcb1b396cdf3c28 Mon Sep 17 00:00:00 2001 From: Derek Allard Date: Sat, 27 Jan 2007 17:56:40 +0000 Subject: fixed $moble to $mobile --- system/libraries/User_agent.php | 998 ++++++++++++++++++++-------------------- 1 file changed, 499 insertions(+), 499 deletions(-) (limited to 'system') diff --git a/system/libraries/User_agent.php b/system/libraries/User_agent.php index 95eccd124..afd012e30 100644 --- a/system/libraries/User_agent.php +++ b/system/libraries/User_agent.php @@ -1,500 +1,500 @@ -agent = trim($_SERVER['HTTP_USER_AGENT']); - } - - if ( ! is_null($this->agent)) - { - if ($this->_load_agent_file()) - { - $this->_compile_data(); - } - } - - log_message('debug', "Table Class Initialized"); - } - - // -------------------------------------------------------------------- - - /** - * Compile the User Agent Data - * - * @access private - * @return bool - */ - function _load_agent_file() - { - if ( ! @include(APPPATH.'config/user_agents'.EXT)) - { - return FALSE; - } - - $return = FALSE; - - if (isset($platforms)) - { - $this->platforms = $platforms; - unset($platforms); - $return = TRUE; - } - - if (isset($browsers)) - { - $this->browsers = $browsers; - unset($browsers); - $return = TRUE; - } - - if (isset($mobiles)) - { - $this->mobiles = $mobiles; - unset($mobiles); - $return = TRUE; - } - - if (isset($robots)) - { - $this->robots = $robots; - unset($robots); - $return = TRUE; - } - - return $return; - } - - // -------------------------------------------------------------------- - - /** - * Compile the User Agent Data - * - * @access private - * @return bool - */ - function _compile_data() - { - $this->_set_platform(); - - foreach (array('_set_browser', '_set_robot', '_set_mobile') as $function) - { - if ($this->$function() === TRUE) - { - break; - } - } - } - - // -------------------------------------------------------------------- - - /** - * Set the Platform - * - * @access private - * @return mixed - */ - function _set_platform() - { - if (is_array($this->platforms) AND count($this->platforms) > 0) - { - foreach ($this->platforms as $key => $val) - { - if (preg_match("|".preg_quote($key)."|i", $this->agent)) - { - $this->platform = $val; - return TRUE; - } - } - } - $this->platform = 'Unknown Platform'; - } - - // -------------------------------------------------------------------- - - /** - * Set the Browser - * - * @access private - * @return bool - */ - function _set_browser() - { - if (is_array($this->browsers) AND count($this->browsers) > 0) - { - foreach ($this->browsers as $key => $val) - { - if (preg_match("|".preg_quote($key).".*?([0-9\.]+)|i", $this->agent, $match)) - { - $this->is_browser = TRUE; - $this->version = $match[1]; - $this->browser = $val; - $this->_set_mobile(); - return TRUE; - } - } - } - return FALSE; - } - - // -------------------------------------------------------------------- - - /** - * Set the Robot - * - * @access private - * @return bool - */ - function _set_robot() - { - if (is_array($this->robots) AND count($this->robots) > 0) - { - foreach ($this->robots as $key => $val) - { - if (preg_match("|".preg_quote($key)."|i", $this->agent)) - { - $this->is_robot = TRUE; - $this->robot = $val; - return TRUE; - } - } - } - return FALSE; - } - - // -------------------------------------------------------------------- - - /** - * Set the Mobile Device - * - * @access private - * @return bool - */ - function _set_mobile() - { - if (is_array($this->mobiles) AND count($this->mobiles) > 0) - { - foreach ($this->mobiles as $key => $val) - { - if (FALSE !== (strpos(strtolower($this->agent), $key))) - { - $this->is_mobile = TRUE; - $this->mobile = $val; - return TRUE; - } - } - } - return FALSE; - } - - // -------------------------------------------------------------------- - - /** - * Set the accepted languages - * - * @access private - * @return void - */ - function _set_languages() - { - if ((count($this->languages) == 0) AND isset($_SERVER['HTTP_ACCEPT_LANGUAGE']) AND $_SERVER['HTTP_ACCEPT_LANGUAGE'] != '') - { - $languages = preg_replace('/(;q=.+)/i', '', trim($_SERVER['HTTP_ACCEPT_LANGUAGE'])); - - $this->languages = explode(',', $languages); - } - - if (count($this->languages) == 0) - { - $this->languages = array('Undefined'); - } - } - - // -------------------------------------------------------------------- - - /** - * Set the accepted character sets - * - * @access private - * @return void - */ - function _set_charsets() - { - if ((count($this->charsets) == 0) AND isset($_SERVER['HTTP_ACCEPT_CHARSET']) AND $_SERVER['HTTP_ACCEPT_CHARSET'] != '') - { - $charsets = preg_replace('/(;q=.+)/i', '', trim($_SERVER['HTTP_ACCEPT_CHARSET'])); - - $this->charsets = explode(',', $charsets); - } - - if (count($this->charsets) == 0) - { - $this->charsets = array('Undefined'); - } - } - - // -------------------------------------------------------------------- - - /** - * Is Browser - * - * @access public - * @return bool - */ - function is_browser() - { - return $this->is_browser; - } - - // -------------------------------------------------------------------- - - /** - * Is Robot - * - * @access public - * @return bool - */ - function is_robot() - { - return $this->is_robot; - } - - // -------------------------------------------------------------------- - - /** - * Is Mobile - * - * @access public - * @return bool - */ - function is_mobile() - { - return $this->is_mobile; - } - - // -------------------------------------------------------------------- - - /** - * Is this a referral from another site? - * - * @access public - * @return bool - */ - function is_referral() - { - return ( ! isset($_SERVER['HTTP_REFERER']) OR $_SERVER['HTTP_REFERER'] == '') ? FALSE : TRUE; - } - - // -------------------------------------------------------------------- - - /** - * Agent String - * - * @access public - * @return string - */ - function agent_string() - { - return $this->agent; - } - - // -------------------------------------------------------------------- - - /** - * Get Platform - * - * @access public - * @return string - */ - function platform() - { - return $this->platform; - } - - // -------------------------------------------------------------------- - - /** - * Get Browser Name - * - * @access public - * @return string - */ - function browser() - { - return $this->browser; - } - - // -------------------------------------------------------------------- - - /** - * Get the Browser Version - * - * @access public - * @return string - */ - function version() - { - return $this->version; - } - - // -------------------------------------------------------------------- - - /** - * Get The Robot Name - * - * @access public - * @return string - */ - function robot() - { - return $this->robot; - } - // -------------------------------------------------------------------- - - /** - * Get the Mobile Device - * - * @access public - * @return string - */ - function mobile() - { - return $this->mobile; - } - - // -------------------------------------------------------------------- - - /** - * Get the referrer - * - * @access public - * @return bool - */ - function referrer() - { - return ( ! isset($_SERVER['HTTP_REFERER']) OR $_SERVER['HTTP_REFERER'] == '') ? '' : trim($_SERVER['HTTP_REFERER']); - } - - // -------------------------------------------------------------------- - - /** - * Get the accepted languages - * - * @access public - * @return array - */ - function languages() - { - if (count($this->languages) == 0) - { - $this->_set_languages(); - } - - return $this->languages; - } - - // -------------------------------------------------------------------- - - /** - * Get the accepted Character Sets - * - * @access public - * @return array - */ - function charsets() - { - if (count($this->charsets) == 0) - { - $this->_set_charsets(); - } - - return $this->charsets; - } - - // -------------------------------------------------------------------- - - /** - * Test for a particular language - * - * @access public - * @return bool - */ - function accept_lang($lang = 'en') - { - return (in_array(strtolower($lang), $this->languages(), TRUE)) ? TRUE : FALSE; - } - - // -------------------------------------------------------------------- - - /** - * Test for a particular character set - * - * @access public - * @return bool - */ - function accept_charset($charset = 'utf-8') - { - return (in_array(strtolower($charset), $this->charsets(), TRUE)) ? TRUE : FALSE; - } - - -} - +agent = trim($_SERVER['HTTP_USER_AGENT']); + } + + if ( ! is_null($this->agent)) + { + if ($this->_load_agent_file()) + { + $this->_compile_data(); + } + } + + log_message('debug', "Table Class Initialized"); + } + + // -------------------------------------------------------------------- + + /** + * Compile the User Agent Data + * + * @access private + * @return bool + */ + function _load_agent_file() + { + if ( ! @include(APPPATH.'config/user_agents'.EXT)) + { + return FALSE; + } + + $return = FALSE; + + if (isset($platforms)) + { + $this->platforms = $platforms; + unset($platforms); + $return = TRUE; + } + + if (isset($browsers)) + { + $this->browsers = $browsers; + unset($browsers); + $return = TRUE; + } + + if (isset($mobiles)) + { + $this->mobiles = $mobiles; + unset($mobiles); + $return = TRUE; + } + + if (isset($robots)) + { + $this->robots = $robots; + unset($robots); + $return = TRUE; + } + + return $return; + } + + // -------------------------------------------------------------------- + + /** + * Compile the User Agent Data + * + * @access private + * @return bool + */ + function _compile_data() + { + $this->_set_platform(); + + foreach (array('_set_browser', '_set_robot', '_set_mobile') as $function) + { + if ($this->$function() === TRUE) + { + break; + } + } + } + + // -------------------------------------------------------------------- + + /** + * Set the Platform + * + * @access private + * @return mixed + */ + function _set_platform() + { + if (is_array($this->platforms) AND count($this->platforms) > 0) + { + foreach ($this->platforms as $key => $val) + { + if (preg_match("|".preg_quote($key)."|i", $this->agent)) + { + $this->platform = $val; + return TRUE; + } + } + } + $this->platform = 'Unknown Platform'; + } + + // -------------------------------------------------------------------- + + /** + * Set the Browser + * + * @access private + * @return bool + */ + function _set_browser() + { + if (is_array($this->browsers) AND count($this->browsers) > 0) + { + foreach ($this->browsers as $key => $val) + { + if (preg_match("|".preg_quote($key).".*?([0-9\.]+)|i", $this->agent, $match)) + { + $this->is_browser = TRUE; + $this->version = $match[1]; + $this->browser = $val; + $this->_set_mobile(); + return TRUE; + } + } + } + return FALSE; + } + + // -------------------------------------------------------------------- + + /** + * Set the Robot + * + * @access private + * @return bool + */ + function _set_robot() + { + if (is_array($this->robots) AND count($this->robots) > 0) + { + foreach ($this->robots as $key => $val) + { + if (preg_match("|".preg_quote($key)."|i", $this->agent)) + { + $this->is_robot = TRUE; + $this->robot = $val; + return TRUE; + } + } + } + return FALSE; + } + + // -------------------------------------------------------------------- + + /** + * Set the Mobile Device + * + * @access private + * @return bool + */ + function _set_mobile() + { + if (is_array($this->mobiles) AND count($this->mobiles) > 0) + { + foreach ($this->mobiles as $key => $val) + { + if (FALSE !== (strpos(strtolower($this->agent), $key))) + { + $this->is_mobile = TRUE; + $this->mobile = $val; + return TRUE; + } + } + } + return FALSE; + } + + // -------------------------------------------------------------------- + + /** + * Set the accepted languages + * + * @access private + * @return void + */ + function _set_languages() + { + if ((count($this->languages) == 0) AND isset($_SERVER['HTTP_ACCEPT_LANGUAGE']) AND $_SERVER['HTTP_ACCEPT_LANGUAGE'] != '') + { + $languages = preg_replace('/(;q=.+)/i', '', trim($_SERVER['HTTP_ACCEPT_LANGUAGE'])); + + $this->languages = explode(',', $languages); + } + + if (count($this->languages) == 0) + { + $this->languages = array('Undefined'); + } + } + + // -------------------------------------------------------------------- + + /** + * Set the accepted character sets + * + * @access private + * @return void + */ + function _set_charsets() + { + if ((count($this->charsets) == 0) AND isset($_SERVER['HTTP_ACCEPT_CHARSET']) AND $_SERVER['HTTP_ACCEPT_CHARSET'] != '') + { + $charsets = preg_replace('/(;q=.+)/i', '', trim($_SERVER['HTTP_ACCEPT_CHARSET'])); + + $this->charsets = explode(',', $charsets); + } + + if (count($this->charsets) == 0) + { + $this->charsets = array('Undefined'); + } + } + + // -------------------------------------------------------------------- + + /** + * Is Browser + * + * @access public + * @return bool + */ + function is_browser() + { + return $this->is_browser; + } + + // -------------------------------------------------------------------- + + /** + * Is Robot + * + * @access public + * @return bool + */ + function is_robot() + { + return $this->is_robot; + } + + // -------------------------------------------------------------------- + + /** + * Is Mobile + * + * @access public + * @return bool + */ + function is_mobile() + { + return $this->is_mobile; + } + + // -------------------------------------------------------------------- + + /** + * Is this a referral from another site? + * + * @access public + * @return bool + */ + function is_referral() + { + return ( ! isset($_SERVER['HTTP_REFERER']) OR $_SERVER['HTTP_REFERER'] == '') ? FALSE : TRUE; + } + + // -------------------------------------------------------------------- + + /** + * Agent String + * + * @access public + * @return string + */ + function agent_string() + { + return $this->agent; + } + + // -------------------------------------------------------------------- + + /** + * Get Platform + * + * @access public + * @return string + */ + function platform() + { + return $this->platform; + } + + // -------------------------------------------------------------------- + + /** + * Get Browser Name + * + * @access public + * @return string + */ + function browser() + { + return $this->browser; + } + + // -------------------------------------------------------------------- + + /** + * Get the Browser Version + * + * @access public + * @return string + */ + function version() + { + return $this->version; + } + + // -------------------------------------------------------------------- + + /** + * Get The Robot Name + * + * @access public + * @return string + */ + function robot() + { + return $this->robot; + } + // -------------------------------------------------------------------- + + /** + * Get the Mobile Device + * + * @access public + * @return string + */ + function mobile() + { + return $this->mobile; + } + + // -------------------------------------------------------------------- + + /** + * Get the referrer + * + * @access public + * @return bool + */ + function referrer() + { + return ( ! isset($_SERVER['HTTP_REFERER']) OR $_SERVER['HTTP_REFERER'] == '') ? '' : trim($_SERVER['HTTP_REFERER']); + } + + // -------------------------------------------------------------------- + + /** + * Get the accepted languages + * + * @access public + * @return array + */ + function languages() + { + if (count($this->languages) == 0) + { + $this->_set_languages(); + } + + return $this->languages; + } + + // -------------------------------------------------------------------- + + /** + * Get the accepted Character Sets + * + * @access public + * @return array + */ + function charsets() + { + if (count($this->charsets) == 0) + { + $this->_set_charsets(); + } + + return $this->charsets; + } + + // -------------------------------------------------------------------- + + /** + * Test for a particular language + * + * @access public + * @return bool + */ + function accept_lang($lang = 'en') + { + return (in_array(strtolower($lang), $this->languages(), TRUE)) ? TRUE : FALSE; + } + + // -------------------------------------------------------------------- + + /** + * Test for a particular character set + * + * @access public + * @return bool + */ + function accept_charset($charset = 'utf-8') + { + return (in_array(strtolower($charset), $this->charsets(), TRUE)) ? TRUE : FALSE; + } + + +} + ?> \ No newline at end of file -- cgit v1.2.3-24-g4f1b From b29d37c1d070b1e3790c7ce7429c59d789a5ed4b Mon Sep 17 00:00:00 2001 From: Derek Allard Date: Sun, 28 Jan 2007 16:05:51 +0000 Subject: log_exception() printed severity twice... fixed. --- system/libraries/Exceptions.php | 338 ++++++++++++++++++++-------------------- 1 file changed, 169 insertions(+), 169 deletions(-) (limited to 'system') diff --git a/system/libraries/Exceptions.php b/system/libraries/Exceptions.php index 839093911..03588acb3 100644 --- a/system/libraries/Exceptions.php +++ b/system/libraries/Exceptions.php @@ -1,170 +1,170 @@ - '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 - * - */ - function CI_Exceptions() - { - $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.' '.$severity.' --> '.$message. ' '.$filepath.' '.$line, TRUE); - } - - // -------------------------------------------------------------------- - - /** - * 404 Page Not Found Handler - * - * @access private - * @param string - * @return string - */ - function show_404($page = '') - { - $heading = "404 Page Not Found"; - $message = "The page you requested was not found."; - - log_message('error', '404 Page Not Found --> '.$page); - echo $this->show_error($heading, $message, 'error_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 - * @return string - */ - function show_error($heading, $message, $template = 'error_general') - { - $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.EXT); - $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'.EXT); - $buffer = ob_get_contents(); - ob_end_clean(); - echo $buffer; - } - - -} -// END Exceptions Class + '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 + * + */ + function CI_Exceptions() + { + $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 + * @return string + */ + function show_404($page = '') + { + $heading = "404 Page Not Found"; + $message = "The page you requested was not found."; + + log_message('error', '404 Page Not Found --> '.$page); + echo $this->show_error($heading, $message, 'error_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 + * @return string + */ + function show_error($heading, $message, $template = 'error_general') + { + $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.EXT); + $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'.EXT); + $buffer = ob_get_contents(); + ob_end_clean(); + echo $buffer; + } + + +} +// END Exceptions Class ?> \ No newline at end of file -- cgit v1.2.3-24-g4f1b From a72b60d96cbdbfc10fbe20d2c4a3c4a62358b4d3 Mon Sep 17 00:00:00 2001 From: Derek Allard Date: Wed, 31 Jan 2007 23:56:11 +0000 Subject: removed unescaped variable that could be used in XSS --- system/libraries/Input.php | 1278 +++++++++++++++++++++---------------------- system/libraries/Router.php | 1120 ++++++++++++++++++------------------- 2 files changed, 1199 insertions(+), 1199 deletions(-) (limited to 'system') diff --git a/system/libraries/Input.php b/system/libraries/Input.php index 4fd2061c7..f346cabaa 100644 --- a/system/libraries/Input.php +++ b/system/libraries/Input.php @@ -1,640 +1,640 @@ -use_xss_clean = ($CFG->item('global_xss_filtering') === TRUE) ? TRUE : FALSE; - $this->allow_get_array = ($CFG->item('enable_query_strings') === TRUE) ? TRUE : FALSE; - $this->_sanitize_globals(); - } - - // -------------------------------------------------------------------- - - /** - * 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() - { - // Unset globals. This is effectively the same as register_globals = off - foreach (array($_GET, $_POST, $_COOKIE) as $global) - { - if ( ! is_array($global)) - { - global $global; - $$global = NULL; - } - else - { - foreach ($global as $key => $val) - { - 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(); - } - - // 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) - { - foreach($_COOKIE as $key => $val) - { - $_COOKIE[$this->_clean_input_keys($key)] = $this->_clean_input_data($val); - } - } - - 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; - } - - if ($this->use_xss_clean === TRUE) - { - $str = $this->xss_clean($str); - } - - // Standardize newlines - return preg_replace("/\015\012|\015|\012/", "\n", $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: '.$str); - } - - if ( ! get_magic_quotes_gpc()) - { - return addslashes($str); - } - - return $str; - } - - // -------------------------------------------------------------------- - - /** - * Fetch an item from the POST array - * - * @access public - * @param string - * @param bool - * @return string - */ - function post($index = '', $xss_clean = FALSE) - { - if ( ! isset($_POST[$index])) - { - return FALSE; - } - - if ($xss_clean === TRUE) - { - if (is_array($_POST[$index])) - { - foreach($_POST[$index] as $key => $val) - { - $_POST[$index][$key] = $this->xss_clean($val); - } - } - else - { - return $this->xss_clean($_POST[$index]); - } - } - - return $_POST[$index]; - } - - // -------------------------------------------------------------------- - - /** - * Fetch an item from the COOKIE array - * - * @access public - * @param string - * @param bool - * @return string - */ - function cookie($index = '', $xss_clean = FALSE) - { - if ( ! isset($_COOKIE[$index])) - { - return FALSE; - } - - if ($xss_clean === TRUE) - { - if (is_array($_COOKIE[$index])) - { - $cookie = array(); - foreach($_COOKIE[$index] as $key => $val) - { - $cookie[$key] = $this->xss_clean($val); - } - - return $cookie; - } - else - { - return $this->xss_clean($_COOKIE[$index]); - } - } - else - { - return $_COOKIE[$index]; - } - } - - // -------------------------------------------------------------------- - - /** - * Fetch an item from the SERVER array - * - * @access public - * @param string - * @param bool - * @return string - */ - function server($index = '', $xss_clean = FALSE) - { - if ( ! isset($_SERVER[$index])) - { - return FALSE; - } - - if ($xss_clean === TRUE) - { - return $this->xss_clean($_SERVER[$index]); - } - - return $_SERVER[$index]; - } - - // -------------------------------------------------------------------- - - /** - * Fetch the IP Address - * - * @access public - * @return string - */ - function ip_address() - { - if ($this->ip_address !== FALSE) - { - return $this->ip_address; - } - - if ($this->server('REMOTE_ADDR') AND $this->server('HTTP_CLIENT_IP')) - { - $this->ip_address = $_SERVER['HTTP_CLIENT_IP']; - } - elseif ($this->server('REMOTE_ADDR')) - { - $this->ip_address = $_SERVER['REMOTE_ADDR']; - } - elseif ($this->server('HTTP_CLIENT_IP')) - { - $this->ip_address = $_SERVER['HTTP_CLIENT_IP']; - } - elseif ($this->server('HTTP_X_FORWARDED_FOR')) - { - $this->ip_address = $_SERVER['HTTP_X_FORWARDED_FOR']; - } - - if ($this->ip_address === FALSE) - { - $this->ip_address = '0.0.0.0'; - return $this->ip_address; - } - - if (strstr($this->ip_address, ',')) - { - $x = explode(',', $this->ip_address); - $this->ip_address = end($x); - } - - 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 - * @return string - */ - function valid_ip($ip) - { - return ( ! preg_match( "/^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$/", $ip)) ? FALSE : TRUE; - } - - // -------------------------------------------------------------------- - - /** - * 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; - } - - // -------------------------------------------------------------------- - - /** - * 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://blog.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 - * - * @access public - * @param string - * @return string - */ - function xss_clean($str, $charset = 'ISO-8859-1') - { - /* - * Remove Null Characters - * - * This prevents sandwiching null characters - * between ascii characters, like Java\0script. - * - */ - $str = preg_replace('/\0+/', '', $str); - $str = preg_replace('/(\\\\0)+/', '', $str); - - /* - * Validate standard character entities - * - * Add a semicolon if missing. We do this to enable - * the conversion of entities to ASCII later. - * - */ - $str = preg_replace('#(&\#*\w+)[\x00-\x20]+;#u',"\\1;",$str); - - /* - * Validate UTF16 two byte encoding (x00) - * - * Just as above, adds a semicolon if missing. - * - */ - $str = preg_replace('#(&\#x*)([0-9A-F]+);*#iu',"\\1\\2;",$str); - - /* - * URL Decode - * - * Just in case stuff like this is submitted: - * - * Google - * - * Note: Normally urldecode() would be easier but it removes plus signs - * - */ - $str = preg_replace("/%u0([a-z0-9]{3})/i", "&#x\\1;", $str); - $str = preg_replace("/%([a-z0-9]{2})/i", "&#x\\1;", $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. - * - */ - if (preg_match_all("/<(.+?)>/si", $str, $matches)) - { - for ($i = 0; $i < count($matches['0']); $i++) - { - $str = str_replace($matches['1'][$i], - $this->_html_entity_decode($matches['1'][$i], $charset), - $str); - } - } - - /* - * Not Allowed Under Any Conditions - */ - $bad = array( - 'document.cookie' => '[removed]', - 'document.write' => '[removed]', - 'window.location' => '[removed]', - "javascript\s*:" => '[removed]', - "Redirect\s+302" => '[removed]', - '' => '-->' - ); - - foreach ($bad as $key => $val) - { - $str = preg_replace("#".$key."#i", $val, $str); - } - - /* - * Convert all tabs to spaces - * - * This prevents strings like this: ja vascript - * Note: we deal with spaces between characters later. - * - */ - $str = preg_replace("#\t+#", " ", $str); - - /* - * Makes PHP tags safe - * - * Note: XML tags are inadvertently replaced too: - * - * '), array('<?php', '<?PHP', '<?', '?>'), $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', 'vbscript', 'script', 'applet', 'alert', 'document', 'write', 'cookie', 'window'); - foreach ($words as $word) - { - $temp = ''; - for ($i = 0; $i < strlen($word); $i++) - { - $temp .= substr($word, $i, 1)."\s*"; - } - - $temp = substr($temp, 0, -3); - $str = preg_replace('#'.$temp.'#s', $word, $str); - $str = preg_replace('#'.ucfirst($temp).'#s', ucfirst($word), $str); - } - - /* - * Remove disallowed Javascript in links or img tags - */ - $str = preg_replace("#.*?#si", "", $str); - $str = preg_replace("##si", "", $str); - $str = preg_replace("#<(script|xss).*?\>#si", "", $str); - - /* - * Remove JavaScript Event Handlers - * - * Note: This code is a little blunt. It removes - * the event handler and anything up to the closing >, - * but it's unlikely to be a problem. - * - */ - $str = preg_replace('#(<[^>]+.*?)(onblur|onchange|onclick|onfocus|onload|onmouseover|onmouseup|onmousedown|onselect|onsubmit|onunload|onkeypress|onkeydown|onkeyup|onresize)[^>]*>#iU',"\\1>",$str); - - /* - * 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> - * - */ - $str = preg_replace('#<(/*\s*)(alert|applet|basefont|base|behavior|bgsound|blink|body|embed|expression|form|frameset|frame|head|html|ilayer|iframe|input|layer|link|meta|object|plaintext|style|script|textarea|title|xml|xss)([^>]*)>#is', "<\\1\\2\\3>", $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|cmd|passthru|eval|exec|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 - * - */ - $bad = array( - 'document.cookie' => '[removed]', - 'document.write' => '[removed]', - 'window.location' => '[removed]', - "javascript\s*:" => '[removed]', - "Redirect\s+302" => '[removed]', - '' => '-->' - ); - - foreach ($bad as $key => $val) - { - $str = preg_replace("#".$key."#i", $val, $str); - } - - - log_message('debug', "XSS Filtering completed"); - return $str; - } - - // -------------------------------------------------------------------- - - /** - * HTML Entities Decode - * - * This function is a replacement for html_entity_decode() - * - * In some versions of PHP the native function does not work - * when UTF-8 is the specified character set, so this gives us - * a work-around. More info here: - * http://bugs.php.net/bug.php?id=25670 - * - * @access private - * @param string - * @param string - * @return string - */ - /* ------------------------------------------------- - /* Replacement for html_entity_decode() - /* -------------------------------------------------*/ - - /* - NOTE: html_entity_decode() has a bug in some PHP versions when UTF-8 is the - character set, and the PHP developers said they were not back porting the - fix to versions other than PHP 5.x. - */ - function _html_entity_decode($str, $charset='ISO-8859-1') - { - if (stristr($str, '&') === FALSE) return $str; - - // 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. - - if (function_exists('html_entity_decode') && (strtolower($charset) != 'utf-8' OR version_compare(phpversion(), '5.0.0', '>='))) - { - $str = html_entity_decode($str, ENT_COMPAT, $charset); - $str = preg_replace('~&#x([0-9a-f]{2,5})~ei', 'chr(hexdec("\\1"))', $str); - return preg_replace('~&#([0-9]{2,4})~e', 'chr(\\1)', $str); - } - - // Numeric Entities - $str = preg_replace('~&#x([0-9a-f]{2,5});{0,1}~ei', 'chr(hexdec("\\1"))', $str); - $str = preg_replace('~&#([0-9]{2,4});{0,1}~e', 'chr(\\1)', $str); - - // Literal Entities - Slightly slow so we do another check - if (stristr($str, '&') === FALSE) - { - $str = strtr($str, array_flip(get_html_translation_table(HTML_ENTITIES))); - } - - return $str; - } - -} -// END Input class +use_xss_clean = ($CFG->item('global_xss_filtering') === TRUE) ? TRUE : FALSE; + $this->allow_get_array = ($CFG->item('enable_query_strings') === TRUE) ? TRUE : FALSE; + $this->_sanitize_globals(); + } + + // -------------------------------------------------------------------- + + /** + * 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() + { + // Unset globals. This is effectively the same as register_globals = off + foreach (array($_GET, $_POST, $_COOKIE) as $global) + { + if ( ! is_array($global)) + { + global $global; + $$global = NULL; + } + else + { + foreach ($global as $key => $val) + { + 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(); + } + + // 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) + { + foreach($_COOKIE as $key => $val) + { + $_COOKIE[$this->_clean_input_keys($key)] = $this->_clean_input_data($val); + } + } + + 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; + } + + if ($this->use_xss_clean === TRUE) + { + $str = $this->xss_clean($str); + } + + // Standardize newlines + return preg_replace("/\015\012|\015|\012/", "\n", $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.'); + } + + if ( ! get_magic_quotes_gpc()) + { + return addslashes($str); + } + + return $str; + } + + // -------------------------------------------------------------------- + + /** + * Fetch an item from the POST array + * + * @access public + * @param string + * @param bool + * @return string + */ + function post($index = '', $xss_clean = FALSE) + { + if ( ! isset($_POST[$index])) + { + return FALSE; + } + + if ($xss_clean === TRUE) + { + if (is_array($_POST[$index])) + { + foreach($_POST[$index] as $key => $val) + { + $_POST[$index][$key] = $this->xss_clean($val); + } + } + else + { + return $this->xss_clean($_POST[$index]); + } + } + + return $_POST[$index]; + } + + // -------------------------------------------------------------------- + + /** + * Fetch an item from the COOKIE array + * + * @access public + * @param string + * @param bool + * @return string + */ + function cookie($index = '', $xss_clean = FALSE) + { + if ( ! isset($_COOKIE[$index])) + { + return FALSE; + } + + if ($xss_clean === TRUE) + { + if (is_array($_COOKIE[$index])) + { + $cookie = array(); + foreach($_COOKIE[$index] as $key => $val) + { + $cookie[$key] = $this->xss_clean($val); + } + + return $cookie; + } + else + { + return $this->xss_clean($_COOKIE[$index]); + } + } + else + { + return $_COOKIE[$index]; + } + } + + // -------------------------------------------------------------------- + + /** + * Fetch an item from the SERVER array + * + * @access public + * @param string + * @param bool + * @return string + */ + function server($index = '', $xss_clean = FALSE) + { + if ( ! isset($_SERVER[$index])) + { + return FALSE; + } + + if ($xss_clean === TRUE) + { + return $this->xss_clean($_SERVER[$index]); + } + + return $_SERVER[$index]; + } + + // -------------------------------------------------------------------- + + /** + * Fetch the IP Address + * + * @access public + * @return string + */ + function ip_address() + { + if ($this->ip_address !== FALSE) + { + return $this->ip_address; + } + + if ($this->server('REMOTE_ADDR') AND $this->server('HTTP_CLIENT_IP')) + { + $this->ip_address = $_SERVER['HTTP_CLIENT_IP']; + } + elseif ($this->server('REMOTE_ADDR')) + { + $this->ip_address = $_SERVER['REMOTE_ADDR']; + } + elseif ($this->server('HTTP_CLIENT_IP')) + { + $this->ip_address = $_SERVER['HTTP_CLIENT_IP']; + } + elseif ($this->server('HTTP_X_FORWARDED_FOR')) + { + $this->ip_address = $_SERVER['HTTP_X_FORWARDED_FOR']; + } + + if ($this->ip_address === FALSE) + { + $this->ip_address = '0.0.0.0'; + return $this->ip_address; + } + + if (strstr($this->ip_address, ',')) + { + $x = explode(',', $this->ip_address); + $this->ip_address = end($x); + } + + 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 + * @return string + */ + function valid_ip($ip) + { + return ( ! preg_match( "/^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$/", $ip)) ? FALSE : TRUE; + } + + // -------------------------------------------------------------------- + + /** + * 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; + } + + // -------------------------------------------------------------------- + + /** + * 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://blog.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 + * + * @access public + * @param string + * @return string + */ + function xss_clean($str, $charset = 'ISO-8859-1') + { + /* + * Remove Null Characters + * + * This prevents sandwiching null characters + * between ascii characters, like Java\0script. + * + */ + $str = preg_replace('/\0+/', '', $str); + $str = preg_replace('/(\\\\0)+/', '', $str); + + /* + * Validate standard character entities + * + * Add a semicolon if missing. We do this to enable + * the conversion of entities to ASCII later. + * + */ + $str = preg_replace('#(&\#*\w+)[\x00-\x20]+;#u',"\\1;",$str); + + /* + * Validate UTF16 two byte encoding (x00) + * + * Just as above, adds a semicolon if missing. + * + */ + $str = preg_replace('#(&\#x*)([0-9A-F]+);*#iu',"\\1\\2;",$str); + + /* + * URL Decode + * + * Just in case stuff like this is submitted: + * + * Google + * + * Note: Normally urldecode() would be easier but it removes plus signs + * + */ + $str = preg_replace("/%u0([a-z0-9]{3})/i", "&#x\\1;", $str); + $str = preg_replace("/%([a-z0-9]{2})/i", "&#x\\1;", $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. + * + */ + if (preg_match_all("/<(.+?)>/si", $str, $matches)) + { + for ($i = 0; $i < count($matches['0']); $i++) + { + $str = str_replace($matches['1'][$i], + $this->_html_entity_decode($matches['1'][$i], $charset), + $str); + } + } + + /* + * Not Allowed Under Any Conditions + */ + $bad = array( + 'document.cookie' => '[removed]', + 'document.write' => '[removed]', + 'window.location' => '[removed]', + "javascript\s*:" => '[removed]', + "Redirect\s+302" => '[removed]', + '' => '-->' + ); + + foreach ($bad as $key => $val) + { + $str = preg_replace("#".$key."#i", $val, $str); + } + + /* + * Convert all tabs to spaces + * + * This prevents strings like this: ja vascript + * Note: we deal with spaces between characters later. + * + */ + $str = preg_replace("#\t+#", " ", $str); + + /* + * Makes PHP tags safe + * + * Note: XML tags are inadvertently replaced too: + * + * '), array('<?php', '<?PHP', '<?', '?>'), $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', 'vbscript', 'script', 'applet', 'alert', 'document', 'write', 'cookie', 'window'); + foreach ($words as $word) + { + $temp = ''; + for ($i = 0; $i < strlen($word); $i++) + { + $temp .= substr($word, $i, 1)."\s*"; + } + + $temp = substr($temp, 0, -3); + $str = preg_replace('#'.$temp.'#s', $word, $str); + $str = preg_replace('#'.ucfirst($temp).'#s', ucfirst($word), $str); + } + + /* + * Remove disallowed Javascript in links or img tags + */ + $str = preg_replace("#.*?#si", "", $str); + $str = preg_replace("##si", "", $str); + $str = preg_replace("#<(script|xss).*?\>#si", "", $str); + + /* + * Remove JavaScript Event Handlers + * + * Note: This code is a little blunt. It removes + * the event handler and anything up to the closing >, + * but it's unlikely to be a problem. + * + */ + $str = preg_replace('#(<[^>]+.*?)(onblur|onchange|onclick|onfocus|onload|onmouseover|onmouseup|onmousedown|onselect|onsubmit|onunload|onkeypress|onkeydown|onkeyup|onresize)[^>]*>#iU',"\\1>",$str); + + /* + * 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> + * + */ + $str = preg_replace('#<(/*\s*)(alert|applet|basefont|base|behavior|bgsound|blink|body|embed|expression|form|frameset|frame|head|html|ilayer|iframe|input|layer|link|meta|object|plaintext|style|script|textarea|title|xml|xss)([^>]*)>#is', "<\\1\\2\\3>", $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|cmd|passthru|eval|exec|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 + * + */ + $bad = array( + 'document.cookie' => '[removed]', + 'document.write' => '[removed]', + 'window.location' => '[removed]', + "javascript\s*:" => '[removed]', + "Redirect\s+302" => '[removed]', + '' => '-->' + ); + + foreach ($bad as $key => $val) + { + $str = preg_replace("#".$key."#i", $val, $str); + } + + + log_message('debug', "XSS Filtering completed"); + return $str; + } + + // -------------------------------------------------------------------- + + /** + * HTML Entities Decode + * + * This function is a replacement for html_entity_decode() + * + * In some versions of PHP the native function does not work + * when UTF-8 is the specified character set, so this gives us + * a work-around. More info here: + * http://bugs.php.net/bug.php?id=25670 + * + * @access private + * @param string + * @param string + * @return string + */ + /* ------------------------------------------------- + /* Replacement for html_entity_decode() + /* -------------------------------------------------*/ + + /* + NOTE: html_entity_decode() has a bug in some PHP versions when UTF-8 is the + character set, and the PHP developers said they were not back porting the + fix to versions other than PHP 5.x. + */ + function _html_entity_decode($str, $charset='ISO-8859-1') + { + if (stristr($str, '&') === FALSE) return $str; + + // 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. + + if (function_exists('html_entity_decode') && (strtolower($charset) != 'utf-8' OR version_compare(phpversion(), '5.0.0', '>='))) + { + $str = html_entity_decode($str, ENT_COMPAT, $charset); + $str = preg_replace('~&#x([0-9a-f]{2,5})~ei', 'chr(hexdec("\\1"))', $str); + return preg_replace('~&#([0-9]{2,4})~e', 'chr(\\1)', $str); + } + + // Numeric Entities + $str = preg_replace('~&#x([0-9a-f]{2,5});{0,1}~ei', 'chr(hexdec("\\1"))', $str); + $str = preg_replace('~&#([0-9]{2,4});{0,1}~e', 'chr(\\1)', $str); + + // Literal Entities - Slightly slow so we do another check + if (stristr($str, '&') === FALSE) + { + $str = strtr($str, array_flip(get_html_translation_table(HTML_ENTITIES))); + } + + return $str; + } + +} +// END Input class ?> \ No newline at end of file diff --git a/system/libraries/Router.php b/system/libraries/Router.php index 6d925a1c0..8dfc82580 100644 --- a/system/libraries/Router.php +++ b/system/libraries/Router.php @@ -1,561 +1,561 @@ -config =& load_class('Config'); - $this->_set_route_mapping(); - 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_route_mapping() - { - // Are query strings enabled in the config file? - // If so, we're done since segment based URIs are not used with query strings. - if ($this->config->item('enable_query_strings') === TRUE AND isset($_GET[$this->config->item('controller_trigger')])) - { - $this->set_class($_GET[$this->config->item('controller_trigger')]); - - if (isset($_GET[$this->config->item('function_trigger')])) - { - $this->set_method($_GET[$this->config->item('function_trigger')]); - } - - return; - } - - // Load the routes.php file. - @include(APPPATH.'config/routes'.EXT); - $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']); - - // Fetch the complete URI string - $this->uri_string = $this->_get_uri_string(); - - // If the URI contains only a slash we'll kill it - if ($this->uri_string == '/') - { - $this->uri_string = ''; - } - - // Is there a URI string? If not, the default controller specified in the "routes" file will be shown. - if ($this->uri_string == '') - { - 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."); - } - - $this->set_class($this->default_controller); - $this->set_method('index'); - - log_message('debug', "No URI present. Default controller set."); - return; - } - unset($this->routes['default_controller']); - - // Do we need to remove the suffix specified in the config file? - 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. - 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; - } - - // 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->_reindex_segments(); - } - - // -------------------------------------------------------------------- - - /** - * Compile Segments - * - * This function takes an array of URI segments as - * input, and puts it into the $this->segments array. - * It also sets the current class/method - * - * @access private - * @param array - * @param bool - * @return void - */ - function _compile_segments($segments = array()) - { - $segments = $this->_validate_segments($segments); - - if (count($segments) == 0) - { - return; - } - - $this->set_class($segments[0]); - - if (isset($segments[1])) - { - // A scaffolding request. No funny business with the URL - if ($this->routes['scaffolding_trigger'] == $segments[1] AND $segments[1] != '_ci_scaffolding') - { - $this->scaffolding_request = TRUE; - unset($this->routes['scaffolding_trigger']); - } - else - { - // A standard method request - $this->set_method($segments[1]); - } - } - - // Update our "routed" segment array to contain the segments. - // Note: If there is no custom routing, this array will be - // identical to $this->segments - $this->rsegments = $segments; - } - - // -------------------------------------------------------------------- - - /** - * Validates the supplied segments. Attempts to determine the path to - * the controller. - * - * @access private - * @param array - * @return array - */ - function _validate_segments($segments) - { - // Does the requested controller exist in the root folder? - if (file_exists(APPPATH.'controllers/'.$segments[0].EXT)) - { - 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].EXT)) - { - show_404(); - } - } - 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.EXT)) - { - $this->directory = ''; - return array(); - } - - } - - return $segments; - } - - // Can't find the requested controller... - show_404(); - } - - // -------------------------------------------------------------------- - /** - * Re-index Segments - * - * This function re-indexes the $this->segment array so that it - * starts at 1 rather then 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() - { - // Is the routed segment array different then the main segment array? - $diff = (count(array_diff($this->rsegments, $this->segments)) == 0) ? FALSE : TRUE; - - $i = 1; - foreach ($this->segments as $val) - { - $this->segments[$i++] = $val; - } - unset($this->segments[0]); - - if ($diff == FALSE) - { - $this->rsegments = $this->segments; - } - else - { - $i = 1; - foreach ($this->rsegments as $val) - { - $this->rsegments[$i++] = $val; - } - unset($this->rsegments[0]); - } - } - - // -------------------------------------------------------------------- - - /** - * Get the URI String - * - * @access private - * @return string - */ - function _get_uri_string() - { - if (strtoupper($this->config->item('uri_protocol')) == 'AUTO') - { - // If the URL has a question mark then it's simplest to just - // build the URI string from the zero index of the $_GET array. - // This avoids having to deal with $_SERVER variables, which - // can be unreliable in some environments - if (is_array($_GET) AND count($_GET) == 1) - { - // Note: Due to a bug in current() that affects some versions - // of PHP we can not pass function call directly into it - $keys = array_keys($_GET); - return current($keys); - } - - // 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 ($path != '' AND $path != "/".SELF) - { - return $path; - } - - // No PATH_INFO?... What about QUERY_STRING? - $path = (isset($_SERVER['QUERY_STRING'])) ? $_SERVER['QUERY_STRING'] : @getenv('QUERY_STRING'); - if ($path != '') - { - return $path; - } - - // No QUERY_STRING?... Maybe the ORIG_PATH_INFO variable exists? - $path = (isset($_SERVER['ORIG_PATH_INFO'])) ? $_SERVER['ORIG_PATH_INFO'] : @getenv('ORIG_PATH_INFO'); - if ($path != '' AND $path != "/".SELF) - { - return $path; - } - - // We've exhausted all our options... - return ''; - } - else - { - $uri = strtoupper($this->config->item('uri_protocol')); - - if ($uri == 'REQUEST_URI') - { - return $this->_parse_request_uri(); - } - - return (isset($_SERVER[$uri])) ? $_SERVER[$uri] : @getenv($uri); - } - } - - // -------------------------------------------------------------------- - - /** - * Parse the REQUEST_URI - * - * Due to the way REQUEST_URI works it usually contains path info - * that makes it unusable as URI data. We'll trim off the unnecessary - * data, hopefully arriving at a valid URI that we can use. - * - * @access private - * @return string - */ - function _parse_request_uri() - { - if ( ! isset($_SERVER['REQUEST_URI']) OR $_SERVER['REQUEST_URI'] == '') - { - return ''; - } - - $request_uri = preg_replace("|/(.*)|", "\\1", str_replace("\\", "/", $_SERVER['REQUEST_URI'])); - - if ($request_uri == '' OR $request_uri == SELF) - { - return ''; - } - - $fc_path = FCPATH; - if (strpos($request_uri, '?') !== FALSE) - { - $fc_path .= '?'; - } - - $parsed_uri = explode("/", $request_uri); - - $i = 0; - foreach(explode("/", $fc_path) as $segment) - { - if (isset($parsed_uri[$i]) AND $segment == $parsed_uri[$i]) - { - $i++; - } - } - - $parsed_uri = implode("/", array_slice($parsed_uri, $i)); - - if ($parsed_uri != '') - { - $parsed_uri = '/'.$parsed_uri; - } - - return $parsed_uri; - } - - // -------------------------------------------------------------------- - - /** - * Filter segments for malicious characters - * - * @access private - * @param string - * @return string - */ - function _filter_uri($str) - { - if ($this->config->item('permitted_uri_chars') != '') - { - if ( ! preg_match("|^[".preg_quote($this->config->item('permitted_uri_chars'))."]+$|i", $str)) - { - exit('The URI you submitted has disallowed characters: '.$str); - } - } - return $str; - } - - // -------------------------------------------------------------------- - - /** - * 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() - { - // Do we even have any custom routing to deal with? - if (count($this->routes) == 0) - { - $this->_compile_segments($this->segments); - return; - } - - // Turn the segment array into a URI string - $uri = implode('/', $this->segments); - $num = count($this->segments); - - // Is there a literal match? If so we're done - if (isset($this->routes[$uri])) - { - $this->_compile_segments(explode('/', $this->routes[$uri])); - return; - } - - // Loop through the route array looking for wild-cards - foreach (array_slice($this->routes, 1) 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); - } - - $this->_compile_segments(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->_compile_segments($this->segments); - } - - // -------------------------------------------------------------------- - - /** - * Set the class name - * - * @access public - * @param string - * @return void - */ - function set_class($class) - { - $this->class = $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 = $dir.'/'; - } - - // -------------------------------------------------------------------- - - /** - * Fetch the sub-directory (if any) that contains the requested controller class - * - * @access public - * @return string - */ - function fetch_directory() - { - return $this->directory; - } - -} -// END Router Class +config =& load_class('Config'); + $this->_set_route_mapping(); + 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_route_mapping() + { + // Are query strings enabled in the config file? + // If so, we're done since segment based URIs are not used with query strings. + if ($this->config->item('enable_query_strings') === TRUE AND isset($_GET[$this->config->item('controller_trigger')])) + { + $this->set_class($_GET[$this->config->item('controller_trigger')]); + + if (isset($_GET[$this->config->item('function_trigger')])) + { + $this->set_method($_GET[$this->config->item('function_trigger')]); + } + + return; + } + + // Load the routes.php file. + @include(APPPATH.'config/routes'.EXT); + $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']); + + // Fetch the complete URI string + $this->uri_string = $this->_get_uri_string(); + + // If the URI contains only a slash we'll kill it + if ($this->uri_string == '/') + { + $this->uri_string = ''; + } + + // Is there a URI string? If not, the default controller specified in the "routes" file will be shown. + if ($this->uri_string == '') + { + 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."); + } + + $this->set_class($this->default_controller); + $this->set_method('index'); + + log_message('debug', "No URI present. Default controller set."); + return; + } + unset($this->routes['default_controller']); + + // Do we need to remove the suffix specified in the config file? + 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. + 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; + } + + // 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->_reindex_segments(); + } + + // -------------------------------------------------------------------- + + /** + * Compile Segments + * + * This function takes an array of URI segments as + * input, and puts it into the $this->segments array. + * It also sets the current class/method + * + * @access private + * @param array + * @param bool + * @return void + */ + function _compile_segments($segments = array()) + { + $segments = $this->_validate_segments($segments); + + if (count($segments) == 0) + { + return; + } + + $this->set_class($segments[0]); + + if (isset($segments[1])) + { + // A scaffolding request. No funny business with the URL + if ($this->routes['scaffolding_trigger'] == $segments[1] AND $segments[1] != '_ci_scaffolding') + { + $this->scaffolding_request = TRUE; + unset($this->routes['scaffolding_trigger']); + } + else + { + // A standard method request + $this->set_method($segments[1]); + } + } + + // Update our "routed" segment array to contain the segments. + // Note: If there is no custom routing, this array will be + // identical to $this->segments + $this->rsegments = $segments; + } + + // -------------------------------------------------------------------- + + /** + * Validates the supplied segments. Attempts to determine the path to + * the controller. + * + * @access private + * @param array + * @return array + */ + function _validate_segments($segments) + { + // Does the requested controller exist in the root folder? + if (file_exists(APPPATH.'controllers/'.$segments[0].EXT)) + { + 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].EXT)) + { + show_404(); + } + } + 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.EXT)) + { + $this->directory = ''; + return array(); + } + + } + + return $segments; + } + + // Can't find the requested controller... + show_404(); + } + + // -------------------------------------------------------------------- + /** + * Re-index Segments + * + * This function re-indexes the $this->segment array so that it + * starts at 1 rather then 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() + { + // Is the routed segment array different then the main segment array? + $diff = (count(array_diff($this->rsegments, $this->segments)) == 0) ? FALSE : TRUE; + + $i = 1; + foreach ($this->segments as $val) + { + $this->segments[$i++] = $val; + } + unset($this->segments[0]); + + if ($diff == FALSE) + { + $this->rsegments = $this->segments; + } + else + { + $i = 1; + foreach ($this->rsegments as $val) + { + $this->rsegments[$i++] = $val; + } + unset($this->rsegments[0]); + } + } + + // -------------------------------------------------------------------- + + /** + * Get the URI String + * + * @access private + * @return string + */ + function _get_uri_string() + { + if (strtoupper($this->config->item('uri_protocol')) == 'AUTO') + { + // If the URL has a question mark then it's simplest to just + // build the URI string from the zero index of the $_GET array. + // This avoids having to deal with $_SERVER variables, which + // can be unreliable in some environments + if (is_array($_GET) AND count($_GET) == 1) + { + // Note: Due to a bug in current() that affects some versions + // of PHP we can not pass function call directly into it + $keys = array_keys($_GET); + return current($keys); + } + + // 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 ($path != '' AND $path != "/".SELF) + { + return $path; + } + + // No PATH_INFO?... What about QUERY_STRING? + $path = (isset($_SERVER['QUERY_STRING'])) ? $_SERVER['QUERY_STRING'] : @getenv('QUERY_STRING'); + if ($path != '') + { + return $path; + } + + // No QUERY_STRING?... Maybe the ORIG_PATH_INFO variable exists? + $path = (isset($_SERVER['ORIG_PATH_INFO'])) ? $_SERVER['ORIG_PATH_INFO'] : @getenv('ORIG_PATH_INFO'); + if ($path != '' AND $path != "/".SELF) + { + return $path; + } + + // We've exhausted all our options... + return ''; + } + else + { + $uri = strtoupper($this->config->item('uri_protocol')); + + if ($uri == 'REQUEST_URI') + { + return $this->_parse_request_uri(); + } + + return (isset($_SERVER[$uri])) ? $_SERVER[$uri] : @getenv($uri); + } + } + + // -------------------------------------------------------------------- + + /** + * Parse the REQUEST_URI + * + * Due to the way REQUEST_URI works it usually contains path info + * that makes it unusable as URI data. We'll trim off the unnecessary + * data, hopefully arriving at a valid URI that we can use. + * + * @access private + * @return string + */ + function _parse_request_uri() + { + if ( ! isset($_SERVER['REQUEST_URI']) OR $_SERVER['REQUEST_URI'] == '') + { + return ''; + } + + $request_uri = preg_replace("|/(.*)|", "\\1", str_replace("\\", "/", $_SERVER['REQUEST_URI'])); + + if ($request_uri == '' OR $request_uri == SELF) + { + return ''; + } + + $fc_path = FCPATH; + if (strpos($request_uri, '?') !== FALSE) + { + $fc_path .= '?'; + } + + $parsed_uri = explode("/", $request_uri); + + $i = 0; + foreach(explode("/", $fc_path) as $segment) + { + if (isset($parsed_uri[$i]) AND $segment == $parsed_uri[$i]) + { + $i++; + } + } + + $parsed_uri = implode("/", array_slice($parsed_uri, $i)); + + if ($parsed_uri != '') + { + $parsed_uri = '/'.$parsed_uri; + } + + return $parsed_uri; + } + + // -------------------------------------------------------------------- + + /** + * Filter segments for malicious characters + * + * @access private + * @param string + * @return string + */ + function _filter_uri($str) + { + if ($this->config->item('permitted_uri_chars') != '') + { + if ( ! preg_match("|^[".preg_quote($this->config->item('permitted_uri_chars'))."]+$|i", $str)) + { + exit('The URI you submitted has disallowed characters.'); + } + } + return $str; + } + + // -------------------------------------------------------------------- + + /** + * 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() + { + // Do we even have any custom routing to deal with? + if (count($this->routes) == 0) + { + $this->_compile_segments($this->segments); + return; + } + + // Turn the segment array into a URI string + $uri = implode('/', $this->segments); + $num = count($this->segments); + + // Is there a literal match? If so we're done + if (isset($this->routes[$uri])) + { + $this->_compile_segments(explode('/', $this->routes[$uri])); + return; + } + + // Loop through the route array looking for wild-cards + foreach (array_slice($this->routes, 1) 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); + } + + $this->_compile_segments(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->_compile_segments($this->segments); + } + + // -------------------------------------------------------------------- + + /** + * Set the class name + * + * @access public + * @param string + * @return void + */ + function set_class($class) + { + $this->class = $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 = $dir.'/'; + } + + // -------------------------------------------------------------------- + + /** + * Fetch the sub-directory (if any) that contains the requested controller class + * + * @access public + * @return string + */ + function fetch_directory() + { + return $this->directory; + } + +} +// END Router Class ?> \ No newline at end of file -- cgit v1.2.3-24-g4f1b From c5d887941fac6754972e87979e180cc043c4d0fe Mon Sep 17 00:00:00 2001 From: Derek Allard Date: Thu, 1 Feb 2007 03:12:32 +0000 Subject: fixed resize bug that was comparing height to width instead of height to original height --- system/libraries/Image_lib.php | 3052 ++++++++++++++++++++-------------------- 1 file changed, 1526 insertions(+), 1526 deletions(-) (limited to 'system') diff --git a/system/libraries/Image_lib.php b/system/libraries/Image_lib.php index 561c5c03a..28e1bfbbc 100644 --- a/system/libraries/Image_lib.php +++ b/system/libraries/Image_lib.php @@ -1,1527 +1,1527 @@ - 0) - { - $this->initialize($props); - } - - log_message('debug', "Image Lib Class Initialized"); - } - - // -------------------------------------------------------------------- - - /** - * Initialize image properties - * - * Resets values in case this class is used in a loop - * - * @access public - * @return void - */ - function clear() - { - $props = array('source_folder', 'dest_folder', 'source_image', 'full_src_path', 'full_dst_path', 'new_image', 'image_type', 'size_str', 'quality', 'orig_width', 'orig_height', 'rotation_angle', 'x_axis', 'y_axis', 'create_fnc', 'copy_fnc', 'wm_overlay_path', 'wm_use_truetype', 'dynamic_output', 'wm_font_size', 'wm_text', 'wm_vrt_alignment', 'wm_hor_alignment', 'wm_padding', 'wm_hor_offset', 'wm_vrt_offset', 'wm_font_color', 'wm_use_drop_shadow', 'wm_shadow_color', 'wm_shadow_distance', 'wm_opacity'); - - foreach ($props as $val) - { - $this->$val = ''; - } - } - - // -------------------------------------------------------------------- - - /** - * initialize image preferences - * - * @access public - * @param array - * @return void - */ - function initialize($props = array()) - { - /* - * Convert array elements into class variables - */ - if (count($props) > 0) - { - foreach ($props as $key => $val) - { - $this->$key = $val; - } - } - - /* - * Is there a source image? - * - * If not, there's no reason to continue - * - */ - if ($this->source_image == '') - { - $this->set_error('imglib_source_image_required'); - return FALSE; - } - - /* - * Is getimagesize() Available? - * - * We use it to determine the image properties (width/height). - * Note: We need to figure out how to determine image - * properties using ImageMagick and NetPBM - * - */ - if ( ! function_exists('getimagesize')) - { - $this->set_error('imglib_gd_required_for_props'); - return FALSE; - } - - $this->image_library = strtolower($this->image_library); - - /* - * Set the full server path - * - * The source image may or may not contain a path. - * Either way, we'll try use realpath to generate the - * full server path in order to more reliably read it. - * - */ - if (function_exists('realpath') AND @realpath($this->source_image) !== FALSE) - { - $full_source_path = str_replace("\\", "/", realpath($this->source_image)); - } - else - { - $full_source_path = $this->source_image; - } - - $x = explode('/', $full_source_path); - $this->source_image = end($x); - $this->source_folder = str_replace($this->source_image, '', $full_source_path); - - // Set the Image Properties - if ( ! $this->get_image_properties($this->source_folder.$this->source_image)) - { - return FALSE; - } - - /* - * Assign the "new" image name/path - * - * If the user has set a "new_image" name it means - * we are making a copy of the source image. If not - * it means we are altering the original. We'll - * set the destination filename and path accordingly. - * - */ - if ($this->new_image == '') - { - $this->dest_image = $this->source_image; - $this->dest_folder = $this->source_folder; - } - else - { - if (strpos($this->new_image, '/') === FALSE) - { - $this->dest_folder = $this->source_folder; - $this->dest_image = $this->new_image; - } - else - { - if (function_exists('realpath') AND @realpath($this->new_image) !== FALSE) - { - $full_dest_path = str_replace("\\", "/", realpath($this->new_image)); - } - else - { - $full_dest_path = $this->new_image; - } - - // Is there a file name? - if ( ! preg_match("#[\.jpg|\.jpeg|\.gif|\.png]$#i", $full_dest_path)) - { - $this->dest_folder = $full_dest_path.'/'; - $this->dest_image = $this->source_image; - } - else - { - $x = explode('/', $full_dest_path); - $this->dest_image = end($x); - $this->dest_folder = str_replace($this->dest_image, '', $full_dest_path); - } - } - } - - /* - * Compile the finalized filenames/paths - * - * We'll create two master strings containing the - * full server path to the source image and the - * full server path to the destination image. - * We'll also split the destination image name - * so we can insert the thumbnail marker if needed. - * - */ - if ($this->create_thumb === FALSE OR $this->thumb_marker == '') - { - $this->thumb_marker = ''; - } - - $xp = $this->explode_name($this->dest_image); - - $filename = $xp['name']; - $file_ext = $xp['ext']; - - $this->full_src_path = $this->source_folder.$this->source_image; - $this->full_dst_path = $this->dest_folder.$filename.$this->thumb_marker.$file_ext; - - /* - * Should we maintain image proportions? - * - * When creating thumbs or copies, the target width/height - * might not be in correct proportion with the source - * image's width/height. We'll recalculate it here. - * - */ - if ($this->maintain_ratio === TRUE && ($this->width != '' AND $this->height != '')) - { - $this->image_reproportion(); - } - - /* - * Was a width and height specified? - * - * If the destination width/height was - * not submitted we will use the values - * from the actual file - * - */ - if ($this->width == '') - $this->width = $this->orig_width; - - if ($this->height == '') - $this->height = $this->orig_height; - - // Set the quality - $this->quality = trim(str_replace("%", "", $this->quality)); - - if ($this->quality == '' OR $this->quality == 0 OR ! is_numeric($this->quality)) - $this->quality = 90; - - // Set the x/y coordinates - $this->x_axis = ($this->x_axis == '' OR ! is_numeric($this->x_axis)) ? 0 : $this->x_axis; - $this->y_axis = ($this->y_axis == '' OR ! is_numeric($this->y_axis)) ? 0 : $this->y_axis; - - // Watermark-related Stuff... - if ($this->wm_font_color != '') - { - if (strlen($this->wm_font_color) == 6) - { - $this->wm_font_color = '#'.$this->wm_font_color; - } - } - - if ($this->wm_shadow_color != '') - { - if (strlen($this->wm_shadow_color) == 6) - { - $this->wm_shadow_color = '#'.$this->wm_shadow_color; - } - } - - if ($this->wm_overlay_path != '') - { - $this->wm_overlay_path = str_replace("\\", "/", realpath($this->wm_overlay_path)); - } - - if ($this->wm_shadow_color != '') - { - $this->wm_use_drop_shadow = TRUE; - } - - if ($this->wm_font_path != '') - { - $this->wm_use_truetype = TRUE; - } - - return TRUE; - } - - // -------------------------------------------------------------------- - - /** - * Image Resize - * - * This is a wrapper function that chooses the proper - * resize function based on the protocol specified - * - * @access public - * @return bool - */ - function resize() - { - $protocol = 'image_process_'.$this->image_library; - - if (eregi("gd2$", $protocol)) - { - $protocol = 'image_process_gd'; - } - - return $this->$protocol('resize'); - } - - // -------------------------------------------------------------------- - - /** - * Image Crop - * - * This is a wrapper function that chooses the proper - * cropping function based on the protocol specified - * - * @access public - * @return bool - */ - function crop() - { - $protocol = 'image_process_'.$this->image_library; - - if (eregi("gd2$", $protocol)) - { - $protocol = 'image_process_gd'; - } - - return $this->$protocol('crop'); - } - - // -------------------------------------------------------------------- - - /** - * Image Rotate - * - * This is a wrapper function that chooses the proper - * rotation function based on the protocol specified - * - * @access public - * @return bool - */ - function rotate() - { - // Allowed rotation values - $degs = array(90, 180, 270, 'vrt', 'hor'); - - if ($this->rotation_angle == '' OR ! in_array($this->rotation_angle, $degs, TRUE)) - { - $this->set_error('imglib_rotation_angle_required'); - return FALSE; - } - - // Reassign the width and height - if ($this->rotation_angle == 90 OR $this->rotation_angle == 270) - { - $this->width = $this->orig_height; - $this->height = $this->orig_width; - } - else - { - $this->width = $this->orig_width; - $this->height = $this->orig_height; - } - - - // Choose resizing function - if ($this->image_library == 'imagemagick' OR $this->image_library == 'netpbm') - { - $protocol = 'image_process_'.$this->image_library; - - return $this->$protocol('rotate'); - } - - if ($this->rotation_angle == 'hor' OR $this->rotation_angle == 'vrt') - { - return $this->image_mirror_gd(); - } - else - { - return $this->image_rotate_gd(); - } - } - - // -------------------------------------------------------------------- - - /** - * Image Process Using GD/GD2 - * - * This function will resize or crop - * - * @access public - * @param string - * @return bool - */ - function image_process_gd($action = 'resize') - { - $v2_override = FALSE; - - if ($action == 'crop') - { - // If the target width/height match the source then it's pointless to crop, right? - if ($this->width >= $this->orig_width AND $this->height >= $this->orig_width) - { - // We'll return true so the user thinks the process succeeded. - // It'll be our little secret... - - return TRUE; - } - - // Reassign the source width/height if cropping - $this->orig_width = $this->width; - $this->orig_height = $this->height; - - // GD 2.0 has a cropping bug so we'll test for it - if ($this->gd_version() !== FALSE) - { - $gd_version = str_replace('0', '', $this->gd_version()); - $v2_override = ($gd_version == 2) ? TRUE : FALSE; - } - } - else - { - // If the target width/height match the source, AND if - // the new file name is not equal to the old file name - // we'll simply make a copy of the original with the new name - if (($this->orig_width == $this->width AND $this->orig_height == $this->height) AND ($this->source_image != $this->dest_image)) - { - if ( ! @copy($this->full_src_path, $this->full_dst_path)) - { - $this->set_error('imglib_copy_failed'); - return FALSE; - } - - @chmod($this->full_dst_path, 0777); - return TRUE; - } - - // If resizing the x/y axis must be zero - $this->x_axis = 0; - $this->y_axis = 0; - } - - // Create the image handle - if ( ! ($src_img = $this->image_create_gd())) - { - return FALSE; - } - - // Create The Image - if ($this->image_library == 'gd2' AND function_exists('imagecreatetruecolor') AND $v2_override == FALSE) - { - $create = 'imagecreatetruecolor'; - $copy = 'imagecopyresampled'; - } - else - { - $create = 'imagecreate'; - $copy = 'imagecopyresized'; - } - - $dst_img = $create($this->width, $this->height); - $copy($dst_img, $src_img, 0, 0, $this->x_axis, $this->y_axis, $this->width, $this->height, $this->orig_width, $this->orig_height); - - // Show the image - if ($this->dynamic_output == TRUE) - { - $this->image_display_gd($dst_img); - } - else - { - // Or save it - if ( ! $this->image_save_gd($dst_img)) - { - return FALSE; - } - } - - // Kill the file handles - imagedestroy($dst_img); - imagedestroy($src_img); - - // Set the file to 777 - @chmod($this->full_dst_path, 0777); - - return TRUE; - } - - // -------------------------------------------------------------------- - - /** - * Image Process Using ImageMagick - * - * This function will resize, crop or rotate - * - * @access public - * @param string - * @return bool - */ - function image_process_imagemagick($action = 'resize') - { - // Do we have a vaild library path? - if ($this->library_path == '') - { - $this->set_error('imglib_libpath_invalid'); - return FALSE; - } - - if ( ! eregi("convert$", $this->library_path)) - { - if ( ! eregi("/$", $this->library_path)) $this->library_path .= "/"; - - $this->library_path .= 'convert'; - } - - // Execute the command - $cmd = $this->library_path." -quality ".$this->quality; - - if ($action == 'crop') - { - $cmd .= " -crop ".$this->width."x".$this->height."+".$this->x_axis."+".$this->y_axis." \"$this->full_src_path\" \"$this->full_dst_path\" 2>&1"; - } - elseif ($action == 'rotate') - { - switch ($this->rotation_angle) - { - case 'hor' : $angle = '-flop'; - break; - case 'vrt' : $angle = '-flip'; - break; - default : $angle = '-rotate '.$this->rotation_angle; - break; - } - - $cmd .= " ".$angle." \"$this->full_src_path\" \"$this->full_dst_path\" 2>&1"; - } - else // Resize - { - $cmd .= " -resize ".$this->width."x".$this->height." \"$this->full_src_path\" \"$this->full_dst_path\" 2>&1"; - } - - $retval = 1; - - @exec($cmd, $output, $retval); - - // Did it work? - if ($retval > 0) - { - $this->set_error('imglib_image_process_failed'); - return FALSE; - } - - // Set the file to 777 - @chmod($this->full_dst_path, 0777); - - return TRUE; - } - - // -------------------------------------------------------------------- - - /** - * Image Process Using NetPBM - * - * This function will resize, crop or rotate - * - * @access public - * @param string - * @return bool - */ - function image_process_netpbm($action = 'resize') - { - if ($this->library_path == '') - { - $this->set_error('imglib_libpath_invalid'); - return FALSE; - } - - // Build the resizing command - switch ($this->image_type) - { - case 1 : - $cmd_in = 'giftopnm'; - $cmd_out = 'ppmtogif'; - break; - case 2 : - $cmd_in = 'jpegtopnm'; - $cmd_out = 'ppmtojpeg'; - break; - case 3 : - $cmd_in = 'pngtopnm'; - $cmd_out = 'ppmtopng'; - break; - } - - if ($action == 'crop') - { - $cmd_inner = 'pnmcut -left '.$this->x_axis.' -top '.$this->y_axis.' -width '.$this->width.' -height '.$this->height; - } - elseif ($action == 'rotate') - { - switch ($this->rotation_angle) - { - case 90 : $angle = 'r270'; - break; - case 180 : $angle = 'r180'; - break; - case 270 : $angle = 'r90'; - break; - case 'vrt' : $angle = 'tb'; - break; - case 'hor' : $angle = 'lr'; - break; - } - - $cmd_inner = 'pnmflip -'.$angle.' '; - } - else // Resize - { - $cmd_inner = 'pnmscale -xysize '.$this->width.' '.$this->height; - } - - $cmd = $this->library_path.$cmd_in.' '.$this->full_src_path.' | '.$cmd_inner.' | '.$cmd_out.' > '.$this->dest_folder.'netpbm.tmp'; - - $retval = 1; - - @exec($cmd, $output, $retval); - - // Did it work? - if ($retval > 0) - { - $this->set_error('imglib_image_process_failed'); - return FALSE; - } - - // With NetPBM we have to create a temporary image. - // If you try manipulating the original it fails so - // we have to rename the temp file. - copy ($this->dest_folder.'netpbm.tmp', $this->full_dst_path); - unlink ($this->dest_folder.'netpbm.tmp'); - @chmod($dst_image, 0777); - - return TRUE; - } - - // -------------------------------------------------------------------- - - /** - * Image Rotate Using GD - * - * @access public - * @return bool - */ - function image_rotate_gd() - { - // Is Image Rotation Supported? - // this function is only supported as of PHP 4.3 - if ( ! function_exists('imagerotate')) - { - $this->set_error('imglib_rotate_unsupported'); - return FALSE; - } - - // Create the image handle - if ( ! ($src_img = $this->image_create_gd())) - { - return FALSE; - } - - // Set the background color - // This won't work with transparent PNG files so we are - // going to have to figure out how to determine the color - // of the alpha channel in a future release. - - $white = imagecolorallocate($src_img, 255, 255, 255); - - // Rotate it! - $dst_img = imagerotate($src_img, $this->rotation_angle, $white); - - // Save the Image - if ($this->dynamic_output == TRUE) - { - $this->image_display_gd($dst_img); - } - else - { - // Or save it - if ( ! $this->image_save_gd($dst_img)) - { - return FALSE; - } - } - - // Kill the file handles - imagedestroy($dst_img); - imagedestroy($src_img); - - // Set the file to 777 - - @chmod($this->full_dst_path, 0777); - - return true; - } - - // -------------------------------------------------------------------- - - /** - * Create Mirror Image using GD - * - * This function will flip horizontal or vertical - * - * @access public - * @return bool - */ - function image_mirror_gd() - { - if ( ! $src_img = $this->image_create_gd()) - { - return FALSE; - } - - $width = $this->orig_width; - $height = $this->orig_height; - - if ($this->rotation_angle == 'hor') - { - for ($i = 0; $i < $height; $i++) - { - $left = 0; - $right = $width-1; - - while ($left < $right) - { - $cl = imagecolorat($src_img, $left, $i); - $cr = imagecolorat($src_img, $right, $i); - - imagesetpixel($src_img, $left, $i, $cr); - imagesetpixel($src_img, $right, $i, $cl); - - $left++; - $right--; - } - } - } - else - { - for ($i = 0; $i < $width; $i++) - { - $top = 0; - $bot = $height-1; - - while ($top < $bot) - { - $ct = imagecolorat($src_img, $i, $top); - $cb = imagecolorat($src_img, $i, $bot); - - imagesetpixel($src_img, $i, $top, $cb); - imagesetpixel($src_img, $i, $bot, $ct); - - $top++; - $bot--; - } - } - } - - // Show the image - if ($this->dynamic_output == TRUE) - { - $this->image_display_gd($src_img); - } - else - { - // Or save it - if ( ! $this->image_save_gd($src_img)) - { - return FALSE; - } - } - - // Kill the file handles - imagedestroy($src_img); - - // Set the file to 777 - @chmod($this->full_dst_path, 0777); - - return TRUE; - } - - // -------------------------------------------------------------------- - - /** - * Image Watermark - * - * This is a wrapper function that chooses the type - * of watermarking based on the specified preference. - * - * @access public - * @param string - * @return bool - */ - function watermark() - { - if ($this->wm_type == 'overlay') - { - return $this->overlay_watermark(); - } - else - { - return $this->text_watermark(); - } - } - - // -------------------------------------------------------------------- - - /** - * Watermark - Graphic Version - * - * @access public - * @return bool - */ - function overlay_watermark() - { - if ( ! function_exists('imagecolortransparent')) - { - $this->set_error('imglib_gd_required'); - return FALSE; - } - - // Fetch source image properties - $this->get_image_properties(); - - // Fetch watermark image properties - $props = $this->get_image_properties($this->wm_overlay_path, TRUE); - $wm_img_type = $props['image_type']; - $wm_width = $props['width']; - $wm_height = $props['height']; - - // Create two image resources - $wm_img = $this->image_create_gd($this->wm_overlay_path, $wm_img_type); - $src_img = $this->image_create_gd($this->full_src_path); - - // Reverse the offset if necessary - // When the image is positioned at the bottom - // we don't want the vertical offset to push it - // further down. We want the reverse, so we'll - // invert the offset. Same with the horizontal - // offset when the image is at the right - - $this->wm_vrt_alignment = strtoupper(substr($this->wm_vrt_alignment, 0, 1)); - $this->wm_hor_alignment = strtoupper(substr($this->wm_hor_alignment, 0, 1)); - - if ($this->wm_vrt_alignment == 'B') - $this->wm_vrt_offset = $this->wm_vrt_offset * -1; - - if ($this->wm_hor_alignment == 'R') - $this->wm_hor_offset = $this->wm_hor_offset * -1; - - // Set the base x and y axis values - $x_axis = $this->wm_hor_offset + $this->wm_padding; - $y_axis = $this->wm_vrt_offset + $this->wm_padding; - - // Set the vertical position - switch ($this->wm_vrt_alignment) - { - case 'T': - break; - case 'M': $y_axis += ($this->orig_height / 2) - ($wm_height / 2); - break; - case 'B': $y_axis += $this->orig_height - $wm_height; - break; - } - - // Set the horizontal position - switch ($this->wm_hor_alignment) - { - case 'L': - break; - case 'C': $x_axis += ($this->orig_width / 2) - ($wm_width / 2); - break; - case 'R': $x_axis += $this->orig_width - $wm_width; - break; - } - - // Build the finalized image - if ($wm_img_type == 3 AND function_exists('imagealphablending')) - { - @imagealphablending($src_img, TRUE); - } - - // Set RGB values for text and shadow - imagecolortransparent($wm_img, imagecolorat($wm_img, $this->wm_x_transp, $this->wm_y_transp)); - imagecopymerge($src_img, $wm_img, $x_axis, $y_axis, 0, 0, $wm_width, $wm_height, $this->wm_opacity); - - // Output the image - if ($this->dynamic_output == TRUE) - { - $this->image_display_gd($src_img); - } - else - { - if ( ! $this->image_save_gd($src_img)) - { - return FALSE; - } - } - - imagedestroy($src_img); - imagedestroy($wm_img); - - return TRUE; - } - - // -------------------------------------------------------------------- - - /** - * Watermark - Text Version - * - * @access public - * @return bool - */ - function text_watermark() - { - if ( ! ($src_img = $this->image_create_gd())) - { - return FALSE; - } - - if ($this->wm_use_truetype == TRUE AND ! file_exists($this->wm_font_path)) - { - $this->set_error('imglib_missing_font'); - return FALSE; - } - - // Fetch source image properties - $this->get_image_properties(); - - // Set RGB values for text and shadow - $this->wm_font_color = str_replace('#', '', $this->wm_font_color); - $this->wm_shadow_color = str_replace('#', '', $this->wm_shadow_color); - - $R1 = hexdec(substr($this->wm_font_color, 0, 2)); - $G1 = hexdec(substr($this->wm_font_color, 2, 2)); - $B1 = hexdec(substr($this->wm_font_color, 4, 2)); - - $R2 = hexdec(substr($this->wm_shadow_color, 0, 2)); - $G2 = hexdec(substr($this->wm_shadow_color, 2, 2)); - $B2 = hexdec(substr($this->wm_shadow_color, 4, 2)); - - $txt_color = imagecolorclosest($src_img, $R1, $G1, $B1); - $drp_color = imagecolorclosest($src_img, $R2, $G2, $B2); - - // Reverse the vertical offset - // When the image is positioned at the bottom - // we don't want the vertical offset to push it - // further down. We want the reverse, so we'll - // invert the offset. Note: The horizontal - // offset flips itself automatically - - if ($this->wm_vrt_alignment == 'B') - $this->wm_vrt_offset = $this->wm_vrt_offset * -1; - - if ($this->wm_hor_alignment == 'R') - $this->wm_hor_offset = $this->wm_hor_offset * -1; - - // Set font width and height - // These are calculated differently depending on - // whether we are using the true type font or not - if ($this->wm_use_truetype == TRUE) - { - if ($this->wm_font_size == '') - $this->wm_font_size = '17'; - - $fontwidth = $this->wm_font_size-($this->wm_font_size/4); - $fontheight = $this->wm_font_size; - $this->wm_vrt_offset += $this->wm_font_size; - } - else - { - $fontwidth = imagefontwidth($this->wm_font_size); - $fontheight = imagefontheight($this->wm_font_size); - } - - // Set base X and Y axis values - $x_axis = $this->wm_hor_offset + $this->wm_padding; - $y_axis = $this->wm_vrt_offset + $this->wm_padding; - - // Set verticle alignment - if ($this->wm_use_drop_shadow == FALSE) - $this->wm_shadow_distance = 0; - - $this->wm_vrt_alignment = strtoupper(substr($this->wm_vrt_alignment, 0, 1)); - $this->wm_hor_alignment = strtoupper(substr($this->wm_hor_alignment, 0, 1)); - - switch ($this->wm_vrt_alignment) - { - case "T" : - break; - case "M": $y_axis += ($this->orig_height/2)+($fontheight/2); - break; - case "B": $y_axis += ($this->orig_height - $fontheight - $this->wm_shadow_distance - ($fontheight/2)); - break; - } - - $x_shad = $x_axis + $this->wm_shadow_distance; - $y_shad = $y_axis + $this->wm_shadow_distance; - - // Set horizontal alignment - switch ($this->wm_hor_alignment) - { - case "L": - break; - case "R": - if ($this->wm_use_drop_shadow) - $x_shad += ($this->orig_width - $fontwidth*strlen($this->wm_text)); - $x_axis += ($this->orig_width - $fontwidth*strlen($this->wm_text)); - break; - case "C": - if ($this->wm_use_drop_shadow) - $x_shad += floor(($this->orig_width - $fontwidth*strlen($this->wm_text))/2); - $x_axis += floor(($this->orig_width -$fontwidth*strlen($this->wm_text))/2); - break; - } - - // Add the text to the source image - if ($this->wm_use_truetype) - { - if ($this->wm_use_drop_shadow) - imagettftext($src_img, $this->wm_font_size, 0, $x_shad, $y_shad, $drp_color, $this->wm_font_path, $this->wm_text); - imagettftext($src_img, $this->wm_font_size, 0, $x_axis, $y_axis, $txt_color, $this->wm_font_path, $this->wm_text); - } - else - { - if ($this->wm_use_drop_shadow) - imagestring($src_img, $this->wm_font_size, $x_shad, $y_shad, $this->wm_text, $drp_color); - imagestring($src_img, $this->wm_font_size, $x_axis, $y_axis, $this->wm_text, $txt_color); - } - - // Output the final image - if ($this->dynamic_output == TRUE) - { - $this->image_display_gd($src_img); - } - else - { - $this->image_save_gd($src_img); - } - - imagedestroy($src_img); - - return TRUE; - } - - // -------------------------------------------------------------------- - - /** - * Create Image - GD - * - * This simply creates an image resource handle - * based on the type of image being processed - * - * @access public - * @param string - * @return resource - */ - function image_create_gd($path = '', $image_type = '') - { - if ($path == '') - $path = $this->full_src_path; - - if ($image_type == '') - $image_type = $this->image_type; - - - switch ($image_type) - { - case 1 : - if ( ! function_exists('imagecreatefromgif')) - { - $this->set_error(array('imglib_unsupported_imagecreate', 'imglib_gif_not_supported')); - return FALSE; - } - - return imagecreatefromgif($path); - break; - case 2 : - if ( ! function_exists('imagecreatefromjpeg')) - { - $this->set_error(array('imglib_unsupported_imagecreate', 'imglib_jpg_not_supported')); - return FALSE; - } - - return imagecreatefromjpeg($path); - break; - case 3 : - if ( ! function_exists('imagecreatefrompng')) - { - $this->set_error(array('imglib_unsupported_imagecreate', 'imglib_png_not_supported')); - return FALSE; - } - - return imagecreatefrompng($path); - break; - - } - - $this->set_error(array('imglib_unsupported_imagecreate')); - return FALSE; - } - - // -------------------------------------------------------------------- - - /** - * Write image file to disk - GD - * - * Takes an image resource as input and writes the file - * to the specified destination - * - * @access public - * @param resource - * @return bool - */ - function image_save_gd($resource) - { - switch ($this->image_type) - { - case 1 : - if ( ! function_exists('imagegif')) - { - $this->set_error(array('imglib_unsupported_imagecreate', 'imglib_gif_not_supported')); - return FALSE; - } - - @imagegif($resource, $this->full_dst_path); - break; - case 2 : - if ( ! function_exists('imagejpeg')) - { - $this->set_error(array('imglib_unsupported_imagecreate', 'imglib_jpg_not_supported')); - return FALSE; - } - - if (phpversion() == '4.4.1') - { - @touch($this->full_dst_path); // PHP 4.4.1 bug #35060 - workaround - } - - @imagejpeg($resource, $this->full_dst_path, $this->quality); - break; - case 3 : - if ( ! function_exists('imagepng')) - { - $this->set_error(array('imglib_unsupported_imagecreate', 'imglib_png_not_supported')); - return FALSE; - } - - @imagepng($resource, $this->full_dst_path); - break; - default : - $this->set_error(array('imglib_unsupported_imagecreate')); - return FALSE; - break; - } - - return TRUE; - } - - // -------------------------------------------------------------------- - - /** - * Dynamically outputs an image - * - * @access public - * @param resource - * @return void - */ - function image_display_gd($resource) - { - header("Content-Disposition: filename={$this->source_image};"); - header("Content-Type: {$this->mime_type}"); - header('Content-Transfer-Encoding: binary'); - header('Last-Modified: '.gmdate('D, d M Y H:i:s', time()).' GMT'); - - switch ($this->image_type) - { - case 1 : imagegif($resource); - break; - case 2 : imagejpeg($resource, '', $this->quality); - break; - case 3 : imagepng($resource); - break; - default : echo 'Unable to display the image'; - break; - } - } - - // -------------------------------------------------------------------- - - /** - * Re-proportion Image Width/Height - * - * When creating thumbs, the desired width/height - * can end up warping the image due to an incorrect - * ratio between the full-sized image and the thumb. - * - * This function lets us re-proportion the width/height - * if users choose to maintain the aspect ratio when resizing. - * - * @access public - * @return void - */ - function image_reproportion() - { - if ( ! is_numeric($this->width) OR ! is_numeric($this->height) OR $this->width == 0 OR $this->height == 0) - return; - - if ( ! is_numeric($this->orig_width) OR ! is_numeric($this->orig_height) OR $this->orig_width == 0 OR $this->orig_height == 0) - return; - - $new_width = ceil($this->orig_width*$this->height/$this->orig_height); - $new_height = ceil($this->width*$this->orig_height/$this->orig_width); - - $ratio = (($this->orig_height/$this->orig_width) - ($this->height/$this->width)); - - if ($this->master_dim != 'width' AND $this->master_dim != 'height') - { - $this->master_dim = ($ratio < 0) ? 'width' : 'height'; - } - - if (($this->width != $new_width) AND ($this->height != $new_height)) - { - if ($this->master_dim == 'height') - { - $this->width = $new_width; - } - else - { - $this->height = $new_height; - } - } - } - - // -------------------------------------------------------------------- - - /** - * Get image properties - * - * A helper function that gets info about the file - * - * @access public - * @param string - * @return mixed - */ - function get_image_properties($path = '', $return = FALSE) - { - // For now we require GD but we should - // find a way to determine this using IM or NetPBM - - if ($path == '') - $path = $this->full_src_path; - - if ( ! file_exists($path)) - { - $this->set_error('imglib_invalid_path'); - return FALSE; - } - - $vals = @getimagesize($path); - - $types = array(1 => 'gif', 2 => 'jpeg', 3 => 'png'); - - $mime = (isset($types[$vals['2']])) ? 'image/'.$types[$vals['2']] : 'image/jpg'; - - if ($return == TRUE) - { - $v['width'] = $vals['0']; - $v['height'] = $vals['1']; - $v['image_type'] = $vals['2']; - $v['size_str'] = $vals['3']; - $v['mime_type'] = $mime; - - return $v; - } - - $this->orig_width = $vals['0']; - $this->orig_height = $vals['1']; - $this->image_type = $vals['2']; - $this->size_str = $vals['3']; - $this->mime_type = $mime; - - return TRUE; - } - - // -------------------------------------------------------------------- - - /** - * Size calculator - * - * This function takes a known width x height and - * recalculates it to a new size. Only one - * new variable needs to be known - * - * $props = array( - * 'width' => $width, - * 'height' => $height, - * 'new_width' => 40, - * 'new_height' => '' - * ); - * - * @access public - * @param array - * @return array - */ - function size_calculator($vals) - { - if ( ! is_array($vals)) - return; - - $allowed = array('new_width', 'new_height', 'width', 'height'); - - foreach ($allowed as $item) - { - if ( ! isset($vals[$item]) OR $vals[$item] == '') - $vals[$item] = 0; - } - - if ($vals['width'] == 0 OR $vals['height'] == 0) - { - return $vals; - } - - if ($vals['new_width'] == 0) - { - $vals['new_width'] = ceil($vals['width']*$vals['new_height']/$vals['height']); - } - elseif ($vals['new_height'] == 0) - { - $vals['new_height'] = ceil($vals['new_width']*$vals['height']/$vals['width']); - } - - return $vals; - } - - // -------------------------------------------------------------------- - - /** - * Explode source_image - * - * This is a helper function that extracts the extension - * from the source_image. This function lets us deal with - * source_images with multiple periods, like: my.cool.jpg - * It returns an associative array with two elements: - * $array['ext'] = '.jpg'; - * $array['name'] = 'my.cool'; - * - * @access public - * @param array - * @return array - */ - function explode_name($source_image) - { - $x = explode('.', $source_image); - $ret['ext'] = '.'.end($x); - - $name = ''; - - $ct = count($x)-1; - - for ($i = 0; $i < $ct; $i++) - { - $name .= $x[$i]; - - if ($i < ($ct - 1)) - { - $name .= '.'; - } - } - - $ret['name'] = $name; - - return $ret; - } - - // -------------------------------------------------------------------- - - /** - * Is GD Installed? - * - * @access public - * @return bool - */ - function gd_loaded() - { - if ( ! extension_loaded('gd')) - { - if ( ! dl('gd.so')) - { - return FALSE; - } - } - - return TRUE; - } - - // -------------------------------------------------------------------- - - /** - * Get GD version - * - * @access public - * @return mixed - */ - function gd_version() - { - if (function_exists('gd_info')) - { - $gd_version = @gd_info(); - $gd_version = preg_replace("/\D/", "", $gd_version['GD Version']); - - return $gd_version; - } - - return FALSE; - } - - // -------------------------------------------------------------------- - - /** - * Set error message - * - * @access public - * @param string - * @return void - */ - function set_error($msg) - { - $CI =& get_instance(); - $CI->lang->load('imglib'); - - if (is_array($msg)) - { - foreach ($msg as $val) - { - - $msg = ($CI->lang->line($val) == FALSE) ? $val : $CI->lang->line($val); - $this->error_msg[] = $msg; - log_message('error', $msg); - } - } - else - { - $msg = ($CI->lang->line($msg) == FALSE) ? $msg : $CI->lang->line($msg); - $this->error_msg[] = $msg; - log_message('error', $msg); - } - } - - // -------------------------------------------------------------------- - - /** - * Show error messages - * - * @access public - * @param string - * @return string - */ - function display_errors($open = '

', $close = '

') - { - $str = ''; - foreach ($this->error_msg as $val) - { - $str .= $open.$val.$close; - } - - return $str; - } - -} -// END Image_lib Class + 0) + { + $this->initialize($props); + } + + log_message('debug', "Image Lib Class Initialized"); + } + + // -------------------------------------------------------------------- + + /** + * Initialize image properties + * + * Resets values in case this class is used in a loop + * + * @access public + * @return void + */ + function clear() + { + $props = array('source_folder', 'dest_folder', 'source_image', 'full_src_path', 'full_dst_path', 'new_image', 'image_type', 'size_str', 'quality', 'orig_width', 'orig_height', 'rotation_angle', 'x_axis', 'y_axis', 'create_fnc', 'copy_fnc', 'wm_overlay_path', 'wm_use_truetype', 'dynamic_output', 'wm_font_size', 'wm_text', 'wm_vrt_alignment', 'wm_hor_alignment', 'wm_padding', 'wm_hor_offset', 'wm_vrt_offset', 'wm_font_color', 'wm_use_drop_shadow', 'wm_shadow_color', 'wm_shadow_distance', 'wm_opacity'); + + foreach ($props as $val) + { + $this->$val = ''; + } + } + + // -------------------------------------------------------------------- + + /** + * initialize image preferences + * + * @access public + * @param array + * @return void + */ + function initialize($props = array()) + { + /* + * Convert array elements into class variables + */ + if (count($props) > 0) + { + foreach ($props as $key => $val) + { + $this->$key = $val; + } + } + + /* + * Is there a source image? + * + * If not, there's no reason to continue + * + */ + if ($this->source_image == '') + { + $this->set_error('imglib_source_image_required'); + return FALSE; + } + + /* + * Is getimagesize() Available? + * + * We use it to determine the image properties (width/height). + * Note: We need to figure out how to determine image + * properties using ImageMagick and NetPBM + * + */ + if ( ! function_exists('getimagesize')) + { + $this->set_error('imglib_gd_required_for_props'); + return FALSE; + } + + $this->image_library = strtolower($this->image_library); + + /* + * Set the full server path + * + * The source image may or may not contain a path. + * Either way, we'll try use realpath to generate the + * full server path in order to more reliably read it. + * + */ + if (function_exists('realpath') AND @realpath($this->source_image) !== FALSE) + { + $full_source_path = str_replace("\\", "/", realpath($this->source_image)); + } + else + { + $full_source_path = $this->source_image; + } + + $x = explode('/', $full_source_path); + $this->source_image = end($x); + $this->source_folder = str_replace($this->source_image, '', $full_source_path); + + // Set the Image Properties + if ( ! $this->get_image_properties($this->source_folder.$this->source_image)) + { + return FALSE; + } + + /* + * Assign the "new" image name/path + * + * If the user has set a "new_image" name it means + * we are making a copy of the source image. If not + * it means we are altering the original. We'll + * set the destination filename and path accordingly. + * + */ + if ($this->new_image == '') + { + $this->dest_image = $this->source_image; + $this->dest_folder = $this->source_folder; + } + else + { + if (strpos($this->new_image, '/') === FALSE) + { + $this->dest_folder = $this->source_folder; + $this->dest_image = $this->new_image; + } + else + { + if (function_exists('realpath') AND @realpath($this->new_image) !== FALSE) + { + $full_dest_path = str_replace("\\", "/", realpath($this->new_image)); + } + else + { + $full_dest_path = $this->new_image; + } + + // Is there a file name? + if ( ! preg_match("#[\.jpg|\.jpeg|\.gif|\.png]$#i", $full_dest_path)) + { + $this->dest_folder = $full_dest_path.'/'; + $this->dest_image = $this->source_image; + } + else + { + $x = explode('/', $full_dest_path); + $this->dest_image = end($x); + $this->dest_folder = str_replace($this->dest_image, '', $full_dest_path); + } + } + } + + /* + * Compile the finalized filenames/paths + * + * We'll create two master strings containing the + * full server path to the source image and the + * full server path to the destination image. + * We'll also split the destination image name + * so we can insert the thumbnail marker if needed. + * + */ + if ($this->create_thumb === FALSE OR $this->thumb_marker == '') + { + $this->thumb_marker = ''; + } + + $xp = $this->explode_name($this->dest_image); + + $filename = $xp['name']; + $file_ext = $xp['ext']; + + $this->full_src_path = $this->source_folder.$this->source_image; + $this->full_dst_path = $this->dest_folder.$filename.$this->thumb_marker.$file_ext; + + /* + * Should we maintain image proportions? + * + * When creating thumbs or copies, the target width/height + * might not be in correct proportion with the source + * image's width/height. We'll recalculate it here. + * + */ + if ($this->maintain_ratio === TRUE && ($this->width != '' AND $this->height != '')) + { + $this->image_reproportion(); + } + + /* + * Was a width and height specified? + * + * If the destination width/height was + * not submitted we will use the values + * from the actual file + * + */ + if ($this->width == '') + $this->width = $this->orig_width; + + if ($this->height == '') + $this->height = $this->orig_height; + + // Set the quality + $this->quality = trim(str_replace("%", "", $this->quality)); + + if ($this->quality == '' OR $this->quality == 0 OR ! is_numeric($this->quality)) + $this->quality = 90; + + // Set the x/y coordinates + $this->x_axis = ($this->x_axis == '' OR ! is_numeric($this->x_axis)) ? 0 : $this->x_axis; + $this->y_axis = ($this->y_axis == '' OR ! is_numeric($this->y_axis)) ? 0 : $this->y_axis; + + // Watermark-related Stuff... + if ($this->wm_font_color != '') + { + if (strlen($this->wm_font_color) == 6) + { + $this->wm_font_color = '#'.$this->wm_font_color; + } + } + + if ($this->wm_shadow_color != '') + { + if (strlen($this->wm_shadow_color) == 6) + { + $this->wm_shadow_color = '#'.$this->wm_shadow_color; + } + } + + if ($this->wm_overlay_path != '') + { + $this->wm_overlay_path = str_replace("\\", "/", realpath($this->wm_overlay_path)); + } + + if ($this->wm_shadow_color != '') + { + $this->wm_use_drop_shadow = TRUE; + } + + if ($this->wm_font_path != '') + { + $this->wm_use_truetype = TRUE; + } + + return TRUE; + } + + // -------------------------------------------------------------------- + + /** + * Image Resize + * + * This is a wrapper function that chooses the proper + * resize function based on the protocol specified + * + * @access public + * @return bool + */ + function resize() + { + $protocol = 'image_process_'.$this->image_library; + + if (eregi("gd2$", $protocol)) + { + $protocol = 'image_process_gd'; + } + + return $this->$protocol('resize'); + } + + // -------------------------------------------------------------------- + + /** + * Image Crop + * + * This is a wrapper function that chooses the proper + * cropping function based on the protocol specified + * + * @access public + * @return bool + */ + function crop() + { + $protocol = 'image_process_'.$this->image_library; + + if (eregi("gd2$", $protocol)) + { + $protocol = 'image_process_gd'; + } + + return $this->$protocol('crop'); + } + + // -------------------------------------------------------------------- + + /** + * Image Rotate + * + * This is a wrapper function that chooses the proper + * rotation function based on the protocol specified + * + * @access public + * @return bool + */ + function rotate() + { + // Allowed rotation values + $degs = array(90, 180, 270, 'vrt', 'hor'); + + if ($this->rotation_angle == '' OR ! in_array($this->rotation_angle, $degs, TRUE)) + { + $this->set_error('imglib_rotation_angle_required'); + return FALSE; + } + + // Reassign the width and height + if ($this->rotation_angle == 90 OR $this->rotation_angle == 270) + { + $this->width = $this->orig_height; + $this->height = $this->orig_width; + } + else + { + $this->width = $this->orig_width; + $this->height = $this->orig_height; + } + + + // Choose resizing function + if ($this->image_library == 'imagemagick' OR $this->image_library == 'netpbm') + { + $protocol = 'image_process_'.$this->image_library; + + return $this->$protocol('rotate'); + } + + if ($this->rotation_angle == 'hor' OR $this->rotation_angle == 'vrt') + { + return $this->image_mirror_gd(); + } + else + { + return $this->image_rotate_gd(); + } + } + + // -------------------------------------------------------------------- + + /** + * Image Process Using GD/GD2 + * + * This function will resize or crop + * + * @access public + * @param string + * @return bool + */ + function image_process_gd($action = 'resize') + { + $v2_override = FALSE; + + if ($action == 'crop') + { + // If the target width/height match the source then it's pointless to crop, right? + if ($this->width >= $this->orig_width AND $this->height >= $this->orig_height) + { + // We'll return true so the user thinks the process succeeded. + // It'll be our little secret... + + return TRUE; + } + + // Reassign the source width/height if cropping + $this->orig_width = $this->width; + $this->orig_height = $this->height; + + // GD 2.0 has a cropping bug so we'll test for it + if ($this->gd_version() !== FALSE) + { + $gd_version = str_replace('0', '', $this->gd_version()); + $v2_override = ($gd_version == 2) ? TRUE : FALSE; + } + } + else + { + // If the target width/height match the source, AND if + // the new file name is not equal to the old file name + // we'll simply make a copy of the original with the new name + if (($this->orig_width == $this->width AND $this->orig_height == $this->height) AND ($this->source_image != $this->dest_image)) + { + if ( ! @copy($this->full_src_path, $this->full_dst_path)) + { + $this->set_error('imglib_copy_failed'); + return FALSE; + } + + @chmod($this->full_dst_path, 0777); + return TRUE; + } + + // If resizing the x/y axis must be zero + $this->x_axis = 0; + $this->y_axis = 0; + } + + // Create the image handle + if ( ! ($src_img = $this->image_create_gd())) + { + return FALSE; + } + + // Create The Image + if ($this->image_library == 'gd2' AND function_exists('imagecreatetruecolor') AND $v2_override == FALSE) + { + $create = 'imagecreatetruecolor'; + $copy = 'imagecopyresampled'; + } + else + { + $create = 'imagecreate'; + $copy = 'imagecopyresized'; + } + + $dst_img = $create($this->width, $this->height); + $copy($dst_img, $src_img, 0, 0, $this->x_axis, $this->y_axis, $this->width, $this->height, $this->orig_width, $this->orig_height); + + // Show the image + if ($this->dynamic_output == TRUE) + { + $this->image_display_gd($dst_img); + } + else + { + // Or save it + if ( ! $this->image_save_gd($dst_img)) + { + return FALSE; + } + } + + // Kill the file handles + imagedestroy($dst_img); + imagedestroy($src_img); + + // Set the file to 777 + @chmod($this->full_dst_path, 0777); + + return TRUE; + } + + // -------------------------------------------------------------------- + + /** + * Image Process Using ImageMagick + * + * This function will resize, crop or rotate + * + * @access public + * @param string + * @return bool + */ + function image_process_imagemagick($action = 'resize') + { + // Do we have a vaild library path? + if ($this->library_path == '') + { + $this->set_error('imglib_libpath_invalid'); + return FALSE; + } + + if ( ! eregi("convert$", $this->library_path)) + { + if ( ! eregi("/$", $this->library_path)) $this->library_path .= "/"; + + $this->library_path .= 'convert'; + } + + // Execute the command + $cmd = $this->library_path." -quality ".$this->quality; + + if ($action == 'crop') + { + $cmd .= " -crop ".$this->width."x".$this->height."+".$this->x_axis."+".$this->y_axis." \"$this->full_src_path\" \"$this->full_dst_path\" 2>&1"; + } + elseif ($action == 'rotate') + { + switch ($this->rotation_angle) + { + case 'hor' : $angle = '-flop'; + break; + case 'vrt' : $angle = '-flip'; + break; + default : $angle = '-rotate '.$this->rotation_angle; + break; + } + + $cmd .= " ".$angle." \"$this->full_src_path\" \"$this->full_dst_path\" 2>&1"; + } + else // Resize + { + $cmd .= " -resize ".$this->width."x".$this->height." \"$this->full_src_path\" \"$this->full_dst_path\" 2>&1"; + } + + $retval = 1; + + @exec($cmd, $output, $retval); + + // Did it work? + if ($retval > 0) + { + $this->set_error('imglib_image_process_failed'); + return FALSE; + } + + // Set the file to 777 + @chmod($this->full_dst_path, 0777); + + return TRUE; + } + + // -------------------------------------------------------------------- + + /** + * Image Process Using NetPBM + * + * This function will resize, crop or rotate + * + * @access public + * @param string + * @return bool + */ + function image_process_netpbm($action = 'resize') + { + if ($this->library_path == '') + { + $this->set_error('imglib_libpath_invalid'); + return FALSE; + } + + // Build the resizing command + switch ($this->image_type) + { + case 1 : + $cmd_in = 'giftopnm'; + $cmd_out = 'ppmtogif'; + break; + case 2 : + $cmd_in = 'jpegtopnm'; + $cmd_out = 'ppmtojpeg'; + break; + case 3 : + $cmd_in = 'pngtopnm'; + $cmd_out = 'ppmtopng'; + break; + } + + if ($action == 'crop') + { + $cmd_inner = 'pnmcut -left '.$this->x_axis.' -top '.$this->y_axis.' -width '.$this->width.' -height '.$this->height; + } + elseif ($action == 'rotate') + { + switch ($this->rotation_angle) + { + case 90 : $angle = 'r270'; + break; + case 180 : $angle = 'r180'; + break; + case 270 : $angle = 'r90'; + break; + case 'vrt' : $angle = 'tb'; + break; + case 'hor' : $angle = 'lr'; + break; + } + + $cmd_inner = 'pnmflip -'.$angle.' '; + } + else // Resize + { + $cmd_inner = 'pnmscale -xysize '.$this->width.' '.$this->height; + } + + $cmd = $this->library_path.$cmd_in.' '.$this->full_src_path.' | '.$cmd_inner.' | '.$cmd_out.' > '.$this->dest_folder.'netpbm.tmp'; + + $retval = 1; + + @exec($cmd, $output, $retval); + + // Did it work? + if ($retval > 0) + { + $this->set_error('imglib_image_process_failed'); + return FALSE; + } + + // With NetPBM we have to create a temporary image. + // If you try manipulating the original it fails so + // we have to rename the temp file. + copy ($this->dest_folder.'netpbm.tmp', $this->full_dst_path); + unlink ($this->dest_folder.'netpbm.tmp'); + @chmod($dst_image, 0777); + + return TRUE; + } + + // -------------------------------------------------------------------- + + /** + * Image Rotate Using GD + * + * @access public + * @return bool + */ + function image_rotate_gd() + { + // Is Image Rotation Supported? + // this function is only supported as of PHP 4.3 + if ( ! function_exists('imagerotate')) + { + $this->set_error('imglib_rotate_unsupported'); + return FALSE; + } + + // Create the image handle + if ( ! ($src_img = $this->image_create_gd())) + { + return FALSE; + } + + // Set the background color + // This won't work with transparent PNG files so we are + // going to have to figure out how to determine the color + // of the alpha channel in a future release. + + $white = imagecolorallocate($src_img, 255, 255, 255); + + // Rotate it! + $dst_img = imagerotate($src_img, $this->rotation_angle, $white); + + // Save the Image + if ($this->dynamic_output == TRUE) + { + $this->image_display_gd($dst_img); + } + else + { + // Or save it + if ( ! $this->image_save_gd($dst_img)) + { + return FALSE; + } + } + + // Kill the file handles + imagedestroy($dst_img); + imagedestroy($src_img); + + // Set the file to 777 + + @chmod($this->full_dst_path, 0777); + + return true; + } + + // -------------------------------------------------------------------- + + /** + * Create Mirror Image using GD + * + * This function will flip horizontal or vertical + * + * @access public + * @return bool + */ + function image_mirror_gd() + { + if ( ! $src_img = $this->image_create_gd()) + { + return FALSE; + } + + $width = $this->orig_width; + $height = $this->orig_height; + + if ($this->rotation_angle == 'hor') + { + for ($i = 0; $i < $height; $i++) + { + $left = 0; + $right = $width-1; + + while ($left < $right) + { + $cl = imagecolorat($src_img, $left, $i); + $cr = imagecolorat($src_img, $right, $i); + + imagesetpixel($src_img, $left, $i, $cr); + imagesetpixel($src_img, $right, $i, $cl); + + $left++; + $right--; + } + } + } + else + { + for ($i = 0; $i < $width; $i++) + { + $top = 0; + $bot = $height-1; + + while ($top < $bot) + { + $ct = imagecolorat($src_img, $i, $top); + $cb = imagecolorat($src_img, $i, $bot); + + imagesetpixel($src_img, $i, $top, $cb); + imagesetpixel($src_img, $i, $bot, $ct); + + $top++; + $bot--; + } + } + } + + // Show the image + if ($this->dynamic_output == TRUE) + { + $this->image_display_gd($src_img); + } + else + { + // Or save it + if ( ! $this->image_save_gd($src_img)) + { + return FALSE; + } + } + + // Kill the file handles + imagedestroy($src_img); + + // Set the file to 777 + @chmod($this->full_dst_path, 0777); + + return TRUE; + } + + // -------------------------------------------------------------------- + + /** + * Image Watermark + * + * This is a wrapper function that chooses the type + * of watermarking based on the specified preference. + * + * @access public + * @param string + * @return bool + */ + function watermark() + { + if ($this->wm_type == 'overlay') + { + return $this->overlay_watermark(); + } + else + { + return $this->text_watermark(); + } + } + + // -------------------------------------------------------------------- + + /** + * Watermark - Graphic Version + * + * @access public + * @return bool + */ + function overlay_watermark() + { + if ( ! function_exists('imagecolortransparent')) + { + $this->set_error('imglib_gd_required'); + return FALSE; + } + + // Fetch source image properties + $this->get_image_properties(); + + // Fetch watermark image properties + $props = $this->get_image_properties($this->wm_overlay_path, TRUE); + $wm_img_type = $props['image_type']; + $wm_width = $props['width']; + $wm_height = $props['height']; + + // Create two image resources + $wm_img = $this->image_create_gd($this->wm_overlay_path, $wm_img_type); + $src_img = $this->image_create_gd($this->full_src_path); + + // Reverse the offset if necessary + // When the image is positioned at the bottom + // we don't want the vertical offset to push it + // further down. We want the reverse, so we'll + // invert the offset. Same with the horizontal + // offset when the image is at the right + + $this->wm_vrt_alignment = strtoupper(substr($this->wm_vrt_alignment, 0, 1)); + $this->wm_hor_alignment = strtoupper(substr($this->wm_hor_alignment, 0, 1)); + + if ($this->wm_vrt_alignment == 'B') + $this->wm_vrt_offset = $this->wm_vrt_offset * -1; + + if ($this->wm_hor_alignment == 'R') + $this->wm_hor_offset = $this->wm_hor_offset * -1; + + // Set the base x and y axis values + $x_axis = $this->wm_hor_offset + $this->wm_padding; + $y_axis = $this->wm_vrt_offset + $this->wm_padding; + + // Set the vertical position + switch ($this->wm_vrt_alignment) + { + case 'T': + break; + case 'M': $y_axis += ($this->orig_height / 2) - ($wm_height / 2); + break; + case 'B': $y_axis += $this->orig_height - $wm_height; + break; + } + + // Set the horizontal position + switch ($this->wm_hor_alignment) + { + case 'L': + break; + case 'C': $x_axis += ($this->orig_width / 2) - ($wm_width / 2); + break; + case 'R': $x_axis += $this->orig_width - $wm_width; + break; + } + + // Build the finalized image + if ($wm_img_type == 3 AND function_exists('imagealphablending')) + { + @imagealphablending($src_img, TRUE); + } + + // Set RGB values for text and shadow + imagecolortransparent($wm_img, imagecolorat($wm_img, $this->wm_x_transp, $this->wm_y_transp)); + imagecopymerge($src_img, $wm_img, $x_axis, $y_axis, 0, 0, $wm_width, $wm_height, $this->wm_opacity); + + // Output the image + if ($this->dynamic_output == TRUE) + { + $this->image_display_gd($src_img); + } + else + { + if ( ! $this->image_save_gd($src_img)) + { + return FALSE; + } + } + + imagedestroy($src_img); + imagedestroy($wm_img); + + return TRUE; + } + + // -------------------------------------------------------------------- + + /** + * Watermark - Text Version + * + * @access public + * @return bool + */ + function text_watermark() + { + if ( ! ($src_img = $this->image_create_gd())) + { + return FALSE; + } + + if ($this->wm_use_truetype == TRUE AND ! file_exists($this->wm_font_path)) + { + $this->set_error('imglib_missing_font'); + return FALSE; + } + + // Fetch source image properties + $this->get_image_properties(); + + // Set RGB values for text and shadow + $this->wm_font_color = str_replace('#', '', $this->wm_font_color); + $this->wm_shadow_color = str_replace('#', '', $this->wm_shadow_color); + + $R1 = hexdec(substr($this->wm_font_color, 0, 2)); + $G1 = hexdec(substr($this->wm_font_color, 2, 2)); + $B1 = hexdec(substr($this->wm_font_color, 4, 2)); + + $R2 = hexdec(substr($this->wm_shadow_color, 0, 2)); + $G2 = hexdec(substr($this->wm_shadow_color, 2, 2)); + $B2 = hexdec(substr($this->wm_shadow_color, 4, 2)); + + $txt_color = imagecolorclosest($src_img, $R1, $G1, $B1); + $drp_color = imagecolorclosest($src_img, $R2, $G2, $B2); + + // Reverse the vertical offset + // When the image is positioned at the bottom + // we don't want the vertical offset to push it + // further down. We want the reverse, so we'll + // invert the offset. Note: The horizontal + // offset flips itself automatically + + if ($this->wm_vrt_alignment == 'B') + $this->wm_vrt_offset = $this->wm_vrt_offset * -1; + + if ($this->wm_hor_alignment == 'R') + $this->wm_hor_offset = $this->wm_hor_offset * -1; + + // Set font width and height + // These are calculated differently depending on + // whether we are using the true type font or not + if ($this->wm_use_truetype == TRUE) + { + if ($this->wm_font_size == '') + $this->wm_font_size = '17'; + + $fontwidth = $this->wm_font_size-($this->wm_font_size/4); + $fontheight = $this->wm_font_size; + $this->wm_vrt_offset += $this->wm_font_size; + } + else + { + $fontwidth = imagefontwidth($this->wm_font_size); + $fontheight = imagefontheight($this->wm_font_size); + } + + // Set base X and Y axis values + $x_axis = $this->wm_hor_offset + $this->wm_padding; + $y_axis = $this->wm_vrt_offset + $this->wm_padding; + + // Set verticle alignment + if ($this->wm_use_drop_shadow == FALSE) + $this->wm_shadow_distance = 0; + + $this->wm_vrt_alignment = strtoupper(substr($this->wm_vrt_alignment, 0, 1)); + $this->wm_hor_alignment = strtoupper(substr($this->wm_hor_alignment, 0, 1)); + + switch ($this->wm_vrt_alignment) + { + case "T" : + break; + case "M": $y_axis += ($this->orig_height/2)+($fontheight/2); + break; + case "B": $y_axis += ($this->orig_height - $fontheight - $this->wm_shadow_distance - ($fontheight/2)); + break; + } + + $x_shad = $x_axis + $this->wm_shadow_distance; + $y_shad = $y_axis + $this->wm_shadow_distance; + + // Set horizontal alignment + switch ($this->wm_hor_alignment) + { + case "L": + break; + case "R": + if ($this->wm_use_drop_shadow) + $x_shad += ($this->orig_width - $fontwidth*strlen($this->wm_text)); + $x_axis += ($this->orig_width - $fontwidth*strlen($this->wm_text)); + break; + case "C": + if ($this->wm_use_drop_shadow) + $x_shad += floor(($this->orig_width - $fontwidth*strlen($this->wm_text))/2); + $x_axis += floor(($this->orig_width -$fontwidth*strlen($this->wm_text))/2); + break; + } + + // Add the text to the source image + if ($this->wm_use_truetype) + { + if ($this->wm_use_drop_shadow) + imagettftext($src_img, $this->wm_font_size, 0, $x_shad, $y_shad, $drp_color, $this->wm_font_path, $this->wm_text); + imagettftext($src_img, $this->wm_font_size, 0, $x_axis, $y_axis, $txt_color, $this->wm_font_path, $this->wm_text); + } + else + { + if ($this->wm_use_drop_shadow) + imagestring($src_img, $this->wm_font_size, $x_shad, $y_shad, $this->wm_text, $drp_color); + imagestring($src_img, $this->wm_font_size, $x_axis, $y_axis, $this->wm_text, $txt_color); + } + + // Output the final image + if ($this->dynamic_output == TRUE) + { + $this->image_display_gd($src_img); + } + else + { + $this->image_save_gd($src_img); + } + + imagedestroy($src_img); + + return TRUE; + } + + // -------------------------------------------------------------------- + + /** + * Create Image - GD + * + * This simply creates an image resource handle + * based on the type of image being processed + * + * @access public + * @param string + * @return resource + */ + function image_create_gd($path = '', $image_type = '') + { + if ($path == '') + $path = $this->full_src_path; + + if ($image_type == '') + $image_type = $this->image_type; + + + switch ($image_type) + { + case 1 : + if ( ! function_exists('imagecreatefromgif')) + { + $this->set_error(array('imglib_unsupported_imagecreate', 'imglib_gif_not_supported')); + return FALSE; + } + + return imagecreatefromgif($path); + break; + case 2 : + if ( ! function_exists('imagecreatefromjpeg')) + { + $this->set_error(array('imglib_unsupported_imagecreate', 'imglib_jpg_not_supported')); + return FALSE; + } + + return imagecreatefromjpeg($path); + break; + case 3 : + if ( ! function_exists('imagecreatefrompng')) + { + $this->set_error(array('imglib_unsupported_imagecreate', 'imglib_png_not_supported')); + return FALSE; + } + + return imagecreatefrompng($path); + break; + + } + + $this->set_error(array('imglib_unsupported_imagecreate')); + return FALSE; + } + + // -------------------------------------------------------------------- + + /** + * Write image file to disk - GD + * + * Takes an image resource as input and writes the file + * to the specified destination + * + * @access public + * @param resource + * @return bool + */ + function image_save_gd($resource) + { + switch ($this->image_type) + { + case 1 : + if ( ! function_exists('imagegif')) + { + $this->set_error(array('imglib_unsupported_imagecreate', 'imglib_gif_not_supported')); + return FALSE; + } + + @imagegif($resource, $this->full_dst_path); + break; + case 2 : + if ( ! function_exists('imagejpeg')) + { + $this->set_error(array('imglib_unsupported_imagecreate', 'imglib_jpg_not_supported')); + return FALSE; + } + + if (phpversion() == '4.4.1') + { + @touch($this->full_dst_path); // PHP 4.4.1 bug #35060 - workaround + } + + @imagejpeg($resource, $this->full_dst_path, $this->quality); + break; + case 3 : + if ( ! function_exists('imagepng')) + { + $this->set_error(array('imglib_unsupported_imagecreate', 'imglib_png_not_supported')); + return FALSE; + } + + @imagepng($resource, $this->full_dst_path); + break; + default : + $this->set_error(array('imglib_unsupported_imagecreate')); + return FALSE; + break; + } + + return TRUE; + } + + // -------------------------------------------------------------------- + + /** + * Dynamically outputs an image + * + * @access public + * @param resource + * @return void + */ + function image_display_gd($resource) + { + header("Content-Disposition: filename={$this->source_image};"); + header("Content-Type: {$this->mime_type}"); + header('Content-Transfer-Encoding: binary'); + header('Last-Modified: '.gmdate('D, d M Y H:i:s', time()).' GMT'); + + switch ($this->image_type) + { + case 1 : imagegif($resource); + break; + case 2 : imagejpeg($resource, '', $this->quality); + break; + case 3 : imagepng($resource); + break; + default : echo 'Unable to display the image'; + break; + } + } + + // -------------------------------------------------------------------- + + /** + * Re-proportion Image Width/Height + * + * When creating thumbs, the desired width/height + * can end up warping the image due to an incorrect + * ratio between the full-sized image and the thumb. + * + * This function lets us re-proportion the width/height + * if users choose to maintain the aspect ratio when resizing. + * + * @access public + * @return void + */ + function image_reproportion() + { + if ( ! is_numeric($this->width) OR ! is_numeric($this->height) OR $this->width == 0 OR $this->height == 0) + return; + + if ( ! is_numeric($this->orig_width) OR ! is_numeric($this->orig_height) OR $this->orig_width == 0 OR $this->orig_height == 0) + return; + + $new_width = ceil($this->orig_width*$this->height/$this->orig_height); + $new_height = ceil($this->width*$this->orig_height/$this->orig_width); + + $ratio = (($this->orig_height/$this->orig_width) - ($this->height/$this->width)); + + if ($this->master_dim != 'width' AND $this->master_dim != 'height') + { + $this->master_dim = ($ratio < 0) ? 'width' : 'height'; + } + + if (($this->width != $new_width) AND ($this->height != $new_height)) + { + if ($this->master_dim == 'height') + { + $this->width = $new_width; + } + else + { + $this->height = $new_height; + } + } + } + + // -------------------------------------------------------------------- + + /** + * Get image properties + * + * A helper function that gets info about the file + * + * @access public + * @param string + * @return mixed + */ + function get_image_properties($path = '', $return = FALSE) + { + // For now we require GD but we should + // find a way to determine this using IM or NetPBM + + if ($path == '') + $path = $this->full_src_path; + + if ( ! file_exists($path)) + { + $this->set_error('imglib_invalid_path'); + return FALSE; + } + + $vals = @getimagesize($path); + + $types = array(1 => 'gif', 2 => 'jpeg', 3 => 'png'); + + $mime = (isset($types[$vals['2']])) ? 'image/'.$types[$vals['2']] : 'image/jpg'; + + if ($return == TRUE) + { + $v['width'] = $vals['0']; + $v['height'] = $vals['1']; + $v['image_type'] = $vals['2']; + $v['size_str'] = $vals['3']; + $v['mime_type'] = $mime; + + return $v; + } + + $this->orig_width = $vals['0']; + $this->orig_height = $vals['1']; + $this->image_type = $vals['2']; + $this->size_str = $vals['3']; + $this->mime_type = $mime; + + return TRUE; + } + + // -------------------------------------------------------------------- + + /** + * Size calculator + * + * This function takes a known width x height and + * recalculates it to a new size. Only one + * new variable needs to be known + * + * $props = array( + * 'width' => $width, + * 'height' => $height, + * 'new_width' => 40, + * 'new_height' => '' + * ); + * + * @access public + * @param array + * @return array + */ + function size_calculator($vals) + { + if ( ! is_array($vals)) + return; + + $allowed = array('new_width', 'new_height', 'width', 'height'); + + foreach ($allowed as $item) + { + if ( ! isset($vals[$item]) OR $vals[$item] == '') + $vals[$item] = 0; + } + + if ($vals['width'] == 0 OR $vals['height'] == 0) + { + return $vals; + } + + if ($vals['new_width'] == 0) + { + $vals['new_width'] = ceil($vals['width']*$vals['new_height']/$vals['height']); + } + elseif ($vals['new_height'] == 0) + { + $vals['new_height'] = ceil($vals['new_width']*$vals['height']/$vals['width']); + } + + return $vals; + } + + // -------------------------------------------------------------------- + + /** + * Explode source_image + * + * This is a helper function that extracts the extension + * from the source_image. This function lets us deal with + * source_images with multiple periods, like: my.cool.jpg + * It returns an associative array with two elements: + * $array['ext'] = '.jpg'; + * $array['name'] = 'my.cool'; + * + * @access public + * @param array + * @return array + */ + function explode_name($source_image) + { + $x = explode('.', $source_image); + $ret['ext'] = '.'.end($x); + + $name = ''; + + $ct = count($x)-1; + + for ($i = 0; $i < $ct; $i++) + { + $name .= $x[$i]; + + if ($i < ($ct - 1)) + { + $name .= '.'; + } + } + + $ret['name'] = $name; + + return $ret; + } + + // -------------------------------------------------------------------- + + /** + * Is GD Installed? + * + * @access public + * @return bool + */ + function gd_loaded() + { + if ( ! extension_loaded('gd')) + { + if ( ! dl('gd.so')) + { + return FALSE; + } + } + + return TRUE; + } + + // -------------------------------------------------------------------- + + /** + * Get GD version + * + * @access public + * @return mixed + */ + function gd_version() + { + if (function_exists('gd_info')) + { + $gd_version = @gd_info(); + $gd_version = preg_replace("/\D/", "", $gd_version['GD Version']); + + return $gd_version; + } + + return FALSE; + } + + // -------------------------------------------------------------------- + + /** + * Set error message + * + * @access public + * @param string + * @return void + */ + function set_error($msg) + { + $CI =& get_instance(); + $CI->lang->load('imglib'); + + if (is_array($msg)) + { + foreach ($msg as $val) + { + + $msg = ($CI->lang->line($val) == FALSE) ? $val : $CI->lang->line($val); + $this->error_msg[] = $msg; + log_message('error', $msg); + } + } + else + { + $msg = ($CI->lang->line($msg) == FALSE) ? $msg : $CI->lang->line($msg); + $this->error_msg[] = $msg; + log_message('error', $msg); + } + } + + // -------------------------------------------------------------------- + + /** + * Show error messages + * + * @access public + * @param string + * @return string + */ + function display_errors($open = '

', $close = '

') + { + $str = ''; + foreach ($this->error_msg as $val) + { + $str .= $open.$val.$close; + } + + return $str; + } + +} +// END Image_lib Class ?> \ No newline at end of file -- cgit v1.2.3-24-g4f1b From 356da23d8cc237674228f2383b72e878d661d41e Mon Sep 17 00:00:00 2001 From: Derek Allard Date: Sun, 4 Feb 2007 15:05:26 +0000 Subject: $lang['ut_test_datatype'] = 'Test Datatype '; became (removed space) $lang['ut_test_datatype'] = 'Test Datatype'; --- system/language/english/unit_test_lang.php | 42 +++++++++++++++--------------- 1 file changed, 21 insertions(+), 21 deletions(-) (limited to 'system') diff --git a/system/language/english/unit_test_lang.php b/system/language/english/unit_test_lang.php index 33b20c567..a33cad5f2 100644 --- a/system/language/english/unit_test_lang.php +++ b/system/language/english/unit_test_lang.php @@ -1,22 +1,22 @@ - \ No newline at end of file -- cgit v1.2.3-24-g4f1b From bb433723c84e174ed87a1daf46017866c32c83c8 Mon Sep 17 00:00:00 2001 From: Rick Ellis Date: Mon, 5 Feb 2007 22:32:49 +0000 Subject: --- system/database/DB_active_rec.php | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) (limited to 'system') diff --git a/system/database/DB_active_rec.php b/system/database/DB_active_rec.php index 90f58ae0e..d27d3dc1e 100644 --- a/system/database/DB_active_rec.php +++ b/system/database/DB_active_rec.php @@ -134,7 +134,17 @@ class CI_DB_active_record extends CI_DB_driver { $type .= ' '; } } - + + // If a DB prefix is used we might need to add it to the column names + if ($this->dbprefix) + { + // First we remove any existing prefixes in the condition to avoid duplicates + $cond = preg_replace('|('.$this->dbprefix.')([\w\.]+)([\W\s]+)|', "$2$3", $cond); + + // Next we add the prefixes to the condition + $cond = preg_replace('|([\w\.]+)([\W\s]+)(.+)|', $this->dbprefix . "$1$2" . $this->dbprefix . "$3", $cond); + } + $this->ar_join[] = $type.'JOIN '.$this->dbprefix.$table.' ON '.$cond; return $this; } -- cgit v1.2.3-24-g4f1b From 085c00ff6948bd21e72d24c53457f3bbf2274985 Mon Sep 17 00:00:00 2001 From: Rick Ellis Date: Mon, 5 Feb 2007 22:36:56 +0000 Subject: --- system/libraries/Loader.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'system') diff --git a/system/libraries/Loader.php b/system/libraries/Loader.php index 0947046ed..f76146ffd 100644 --- a/system/libraries/Loader.php +++ b/system/libraries/Loader.php @@ -499,10 +499,10 @@ class CI_Loader { * @param string * @return void */ - function config($file = '') - { + function config($file = '', $use_sections = FALSE, $fail_gracefully = FALSE) + { $CI =& get_instance(); - $CI->config->load($file); + $CI->config->load($file, $use_sections, $fail_gracefully); } // -------------------------------------------------------------------- -- cgit v1.2.3-24-g4f1b From 7fcf8ca599f21732a124b8d2610f32a9e4b01c7d Mon Sep 17 00:00:00 2001 From: Rick Ellis Date: Mon, 5 Feb 2007 22:46:56 +0000 Subject: --- system/libraries/Loader.php | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) (limited to 'system') diff --git a/system/libraries/Loader.php b/system/libraries/Loader.php index f76146ffd..38d7c35a8 100644 --- a/system/libraries/Loader.php +++ b/system/libraries/Loader.php @@ -697,7 +697,6 @@ class CI_Loader { } // Lets search for the requested library file and load it. - $is_duplicate = FALSE; for ($i = 1; $i < 3; $i++) { $path = ($i % 2) ? APPPATH : BASEPATH; @@ -712,8 +711,8 @@ class CI_Loader { // Safety: Was the class already loaded by a previous call? if (in_array($fp, $this->_ci_classes)) { - $is_duplicate = TRUE; - continue; + log_message('debug', $class." class already loaded.Ê Second attempt ignored."); + return; } include($fp); -- cgit v1.2.3-24-g4f1b From 29eff53d35fd2fb1ba8867eab20794ef0a53d5bb Mon Sep 17 00:00:00 2001 From: Derek Allard Date: Mon, 5 Feb 2007 23:55:06 +0000 Subject: Fixed a typo in error message --- system/libraries/Loader.php | 1860 +++++++++++++++++++++---------------------- 1 file changed, 930 insertions(+), 930 deletions(-) (limited to 'system') diff --git a/system/libraries/Loader.php b/system/libraries/Loader.php index 38d7c35a8..d11630712 100644 --- a/system/libraries/Loader.php +++ b/system/libraries/Loader.php @@ -1,931 +1,931 @@ - 'unit', 'user_agent' => 'agent'); - - - /** - * Constructor - * - * Sets the path to the view files and gets the initial output buffering level - * - * @access public - */ - function CI_Loader() - { - $this->_ci_is_php5 = (floor(phpversion()) >= 5) ? TRUE : FALSE; - $this->_ci_view_path = APPPATH.'views/'; - $this->_ci_ob_level = ob_get_level(); - - log_message('debug', "Loader Class Initialized"); - } - - // -------------------------------------------------------------------- - - /** - * Class Loader - * - * This function lets users load and instantiate classes. - * It is designed to be called from a user's app controllers. - * - * @access public - * @param string the name of the class - * @param mixed the optional parameters - * @return void - */ - function library($library = '', $params = NULL) - { - if ($library == '') - { - return FALSE; - } - - if (is_array($library)) - { - foreach ($library as $class) - { - $this->_ci_load_class($class, $params); - } - } - else - { - $this->_ci_load_class($library, $params); - } - - $this->_ci_assign_to_models(); - } - - // -------------------------------------------------------------------- - - /** - * Model Loader - * - * This function lets users load and instantiate models. - * - * @access public - * @param string the name of the class - * @param mixed any initialization parameters - * @return void - */ - function model($model, $name = '', $db_conn = FALSE) - { - if ($model == '') - return; - - // Is the model in a sub-folder? If so, parse out the filename and path. - if (strpos($model, '/') === FALSE) - { - $path = ''; - } - else - { - $x = explode('/', $model); - $model = end($x); - unset($x[count($x)-1]); - $path = implode('/', $x).'/'; - } - - 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); - - if ( ! file_exists(APPPATH.'models/'.$path.$model.EXT)) - { - show_error('Unable to locate the model you have specified: '.$model); - } - - 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('Model')) - { - require_once(BASEPATH.'libraries/Model'.EXT); - } - - require_once(APPPATH.'models/'.$path.$model.EXT); - - $model = ucfirst($model); - - $CI->$name = new $model(); - $CI->$name->_assign_libraries(); - - $this->_ci_models[] = $name; - } - - // -------------------------------------------------------------------- - - /** - * Database Loader - * - * @access public - * @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 - */ - function database($params = '', $return = FALSE, $active_record = FALSE) - { - // Do we even need to load the database class? - if (class_exists('CI_DB') AND $return == FALSE AND $active_record == FALSE) - { - return FALSE; - } - - require_once(BASEPATH.'database/DB'.EXT); - - if ($return === TRUE) - { - return DB($params, $active_record); - } - - // Grab the super object - $CI =& get_instance(); - - // Initialize the db variable. Needed to prevent - // reference errors with some configurations - $CI->db = ''; - - // Load the DB class - $CI->db =& DB($params, $active_record); - - // Assign the DB object to any existing models - $this->_ci_assign_to_models(); - } - - // -------------------------------------------------------------------- - - /** - * Load the Utilities Class - * - * @access public - * @return string - */ - function dbutil() - { - if ( ! class_exists('CI_DB')) - { - $this->database(); - } - - $CI =& get_instance(); - - require_once(BASEPATH.'database/DB_utility'.EXT); - require_once(BASEPATH.'database/drivers/'.$CI->db->dbdriver.'/'.$CI->db->dbdriver.'_utility'.EXT); - $class = 'CI_DB_'.$CI->db->dbdriver.'_utility'; - - $CI->dbutil = new $class(); - $CI->load->_ci_assign_to_models(); - } - - // -------------------------------------------------------------------- - - /** - * 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. - * - * @access public - * @param string - * @param array - * @param bool - * @return void - */ - function view($view, $vars = array(), $return = FALSE) - { - return $this->_ci_load(array('view' => $view, 'vars' => $this->_ci_object_to_array($vars), 'return' => $return)); - } - - // -------------------------------------------------------------------- - - /** - * Load File - * - * This is a generic file loader - * - * @access public - * @param string - * @param bool - * @return string - */ - function file($path, $return = FALSE) - { - return $this->_ci_load(array('path' => $path, 'return' => $return)); - } - - // -------------------------------------------------------------------- - - /** - * Set Variables - * - * Once variables are set they become available within - * the controller class and its "view" files. - * - * @access public - * @param array - * @return void - */ - function vars($vars = array()) - { - $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; - } - } - } - - // -------------------------------------------------------------------- - - /** - * Load Helper - * - * This function loads the specified helper file. - * - * @access public - * @param mixed - * @return void - */ - function helper($helpers = array()) - { - if ( ! is_array($helpers)) - { - $helpers = array($helpers); - } - - foreach ($helpers as $helper) - { - $helper = strtolower(str_replace(EXT, '', str_replace('_helper', '', $helper)).'_helper'); - - if (isset($this->_ci_helpers[$helper])) - { - continue; - } - - if (file_exists(APPPATH.'helpers/'.$helper.EXT)) - { - include_once(APPPATH.'helpers/'.$helper.EXT); - } - else - { - if (file_exists(BASEPATH.'helpers/'.$helper.EXT)) - { - include(BASEPATH.'helpers/'.$helper.EXT); - } - else - { - show_error('Unable to load the requested file: helpers/'.$helper.EXT); - } - } - - $this->_ci_helpers[$helper] = TRUE; - - } - - log_message('debug', 'Helpers loaded: '.implode(', ', $helpers)); - } - - // -------------------------------------------------------------------- - - /** - * Load Helpers - * - * This is simply an alias to the above function in case the - * user has written the plural form of this function. - * - * @access public - * @param array - * @return void - */ - function helpers($helpers = array()) - { - $this->helper($helpers); - } - - // -------------------------------------------------------------------- - - /** - * Load Plugin - * - * This function loads the specified plugin. - * - * @access public - * @param array - * @return void - */ - function plugin($plugins = array()) - { - if ( ! is_array($plugins)) - { - $plugins = array($plugins); - } - - foreach ($plugins as $plugin) - { - $plugin = strtolower(str_replace(EXT, '', str_replace('_plugin.', '', $plugin)).'_pi'); - - if (isset($this->_ci_plugins[$plugin])) - { - continue; - } - - if (file_exists(APPPATH.'plugins/'.$plugin.EXT)) - { - include(APPPATH.'plugins/'.$plugin.EXT); - } - else - { - if (file_exists(BASEPATH.'plugins/'.$plugin.EXT)) - { - include(BASEPATH.'plugins/'.$plugin.EXT); - } - else - { - show_error('Unable to load the requested file: plugins/'.$plugin.EXT); - } - } - - $this->_ci_plugins[$plugin] = TRUE; - } - - log_message('debug', 'Plugins loaded: '.implode(', ', $plugins)); - } - - // -------------------------------------------------------------------- - - /** - * Load Plugins - * - * This is simply an alias to the above function in case the - * user has written the plural form of this function. - * - * @access public - * @param array - * @return void - */ - function plugins($plugins = array()) - { - $this->plugin($plugins); - } - - // -------------------------------------------------------------------- - - /** - * Load Script - * - * This function loads the specified include file from the - * application/scripts/ folder. - * - * NOTE: This feature has been deprecated but it will remain available - * for legacy users. - * - * @access public - * @param array - * @return void - */ - function script($scripts = array()) - { - if ( ! is_array($scripts)) - { - $scripts = array($scripts); - } - - foreach ($scripts as $script) - { - $script = strtolower(str_replace(EXT, '', $script)); - - if (isset($this->_ci_scripts[$script])) - { - continue; - } - - if ( ! file_exists(APPPATH.'scripts/'.$script.EXT)) - { - show_error('Unable to load the requested script: scripts/'.$script.EXT); - } - - include(APPPATH.'scripts/'.$script.EXT); - } - - log_message('debug', 'Scripts loaded: '.implode(', ', $scripts)); - } - - // -------------------------------------------------------------------- - - /** - * Loads a language file - * - * @access public - * @param string - * @return void - */ - function language($file = '', $lang = '', $return = FALSE) - { - $CI =& get_instance(); - return $CI->lang->load($file, $lang, $return); - } - - // -------------------------------------------------------------------- - - /** - * Loads a config file - * - * @access public - * @param string - * @return void - */ - function config($file = '', $use_sections = FALSE, $fail_gracefully = FALSE) - { - $CI =& get_instance(); - $CI->config->load($file, $use_sections, $fail_gracefully); - } - - // -------------------------------------------------------------------- - - /** - * Scaffolding Loader - * - * This initializing function works a bit different than the - * others. It doesn't load the class. Instead, it simply - * sets a flag indicating that scaffolding is allowed to be - * used. The actual scaffolding function below is - * called by the front controller based on whether the - * second segment of the URL matches the "secret" scaffolding - * word stored in the application/config/routes.php - * - * @access public - * @param string - * @return void - */ - function scaffolding($table = '') - { - if ($table === FALSE) - { - show_error('You must include the name of the table you would like access when you initialize scaffolding'); - } - - $CI =& get_instance(); - $CI->_ci_scaffolding = TRUE; - $CI->_ci_scaff_table = $table; - } - - // -------------------------------------------------------------------- - - /** - * Loader - * - * This function is used to load views and files. - * - * @access private - * @param array - * @return void - */ - function _ci_load($data) - { - // Set the default data variables - foreach (array('view', 'vars', 'path', 'return') as $val) - { - $$val = ( ! isset($data[$val])) ? FALSE : $data[$val]; - } - - // Set the path to the requested file - if ($path == '') - { - $ext = pathinfo($view, PATHINFO_EXTENSION); - $file = ($ext == '') ? $view.EXT : $view; - $path = $this->_ci_view_path.$file; - } - else - { - $x = explode('/', $path); - $file = end($x); - } - - if ( ! file_exists($path)) - { - show_error('Unable to load the requested file: '.$file); - } - - // This allows anything loaded using $this->load (views, files, etc.) - // to become accessible from within the Controller and Model functions. - // Only needed when running PHP 5 - - if ($this->_ci_is_instance()) - { - $CI =& get_instance(); - foreach (get_object_vars($CI) as $key => $var) - { - if ( ! isset($this->$key)) - { - $this->$key =& $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($vars)) - { - $this->_ci_cached_vars = array_merge($this->_ci_cached_vars, $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 - { - // PHP 4 requires that we use a global - global $OUT; - $OUT->set_output(ob_get_contents()); - @ob_end_clean(); - } - } - - // -------------------------------------------------------------------- - - /** - * Load class - * - * This function loads the requested class. - * - * @access private - * @param string the item that is being loaded - * @param mixed any additional parameters - * @return void - */ - function _ci_load_class($class, $params = NULL) - { - // Get the class name - $class = str_replace(EXT, '', $class); - - // We'll test for both lowercase and capitalized versions of the file name - foreach (array(ucfirst($class), strtolower($class)) as $class) - { - // Is this a class extension request? - if (file_exists(APPPATH.'libraries/'.config_item('subclass_prefix').$class.EXT)) - { - if ( ! file_exists(BASEPATH.'libraries/'.ucfirst($class).EXT)) - { - log_message('error', "Unable to load the requested class: ".$class); - show_error("Unable to load the requested class: ".$class); - } - - include(BASEPATH.'libraries/'.ucfirst($class).EXT); - include(APPPATH.'libraries/'.config_item('subclass_prefix').$class.EXT); - - return $this->_ci_init_class($class, config_item('subclass_prefix'), $params); - } - - // Lets search for the requested library file and load it. - for ($i = 1; $i < 3; $i++) - { - $path = ($i % 2) ? APPPATH : BASEPATH; - $fp = $path.'libraries/'.$class.EXT; - - // Does the file exist? No? Bummer... - if ( ! file_exists($fp)) - { - continue; - } - - // Safety: Was the class already loaded by a previous call? - if (in_array($fp, $this->_ci_classes)) - { - log_message('debug', $class." class already loaded.Ê Second attempt ignored."); - return; - } - - include($fp); - $this->_ci_classes[] = $fp; - return $this->_ci_init_class($class, '', $params); - } - } // END FOREACH - - // 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 - * - * @access private - * @param string - * @param string - * @return null - */ - function _ci_init_class($class, $prefix = '', $config = FALSE) - { - // Is there an associated config file for this class? - if ($config === NULL) - { - $config = NULL; - if (file_exists(APPPATH.'config/'.$class.EXT)) - { - include(APPPATH.'config/'.$class.EXT); - } - } - - if ($prefix == '') - { - $name = (class_exists('CI_'.$class)) ? 'CI_'.$class : $class; - } - else - { - $name = $prefix.$class; - } - - // Set the variable name we will assign the class to - $class = strtolower($class); - $classvar = ( ! isset($this->_ci_varmap[$class])) ? $class : $this->_ci_varmap[$class]; - - // 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, plugins, and helpers to be loaded automatically. - * - * @access private - * @param array - * @return void - */ - function _ci_autoloader() - { - include(APPPATH.'config/autoload'.EXT); - - if ( ! isset($autoload)) - { - return FALSE; - } - - // Load any custome config file - if (count($autoload['config']) > 0) - { - $CI =& get_instance(); - foreach ($autoload['config'] as $key => $val) - { - $CI->config->load($val); - } - } - - // Load plugins, helpers, and scripts - foreach (array('helper', 'plugin', 'script') 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'])) - { - $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 the model class. - if (in_array('model', $autoload['libraries'])) - { - $this->model(); - $autoload['libraries'] = array_diff($autoload['libraries'], array('model')); - } - - // Load scaffolding - if (in_array('scaffolding', $autoload['libraries'])) - { - $this->scaffolding(); - $autoload['libraries'] = array_diff($autoload['libraries'], array('scaffolding')); - } - - // Load all other libraries - foreach ($autoload['libraries'] as $item) - { - $this->library($item); - } - } - } - - // -------------------------------------------------------------------- - - /** - * Assign to Models - * - * Makes sure that anything loaded by the loader class (libraries, plugins, etc.) - * will be available to models, if any exist. - * - * @access private - * @param object - * @return array - */ - function _ci_assign_to_models() - { - if (count($this->_ci_models) == 0) - { - return; - } - - if ($this->_ci_is_instance()) - { - $CI =& get_instance(); - foreach ($this->_ci_models as $model) - { - $CI->$model->_assign_libraries(); - } - } - else - { - foreach ($this->_ci_models as $model) - { - $this->$model->_assign_libraries(); - } - } - } - - // -------------------------------------------------------------------- - - /** - * Object to Array - * - * Takes an object as input and converts the class variables to array key/vals - * - * @access private - * @param object - * @return array - */ - function _ci_object_to_array($object) - { - return (is_object($object)) ? get_object_vars($object) : $object; - } - - // -------------------------------------------------------------------- - - /** - * Determines whether we should use the CI instance or $this - * - * @access private - * @return bool - */ - function _ci_is_instance() - { - if ($this->_ci_is_php5 == TRUE) - { - return TRUE; - } - - global $CI; - return (is_object($CI)) ? TRUE : FALSE; - } - -} + 'unit', 'user_agent' => 'agent'); + + + /** + * Constructor + * + * Sets the path to the view files and gets the initial output buffering level + * + * @access public + */ + function CI_Loader() + { + $this->_ci_is_php5 = (floor(phpversion()) >= 5) ? TRUE : FALSE; + $this->_ci_view_path = APPPATH.'views/'; + $this->_ci_ob_level = ob_get_level(); + + log_message('debug', "Loader Class Initialized"); + } + + // -------------------------------------------------------------------- + + /** + * Class Loader + * + * This function lets users load and instantiate classes. + * It is designed to be called from a user's app controllers. + * + * @access public + * @param string the name of the class + * @param mixed the optional parameters + * @return void + */ + function library($library = '', $params = NULL) + { + if ($library == '') + { + return FALSE; + } + + if (is_array($library)) + { + foreach ($library as $class) + { + $this->_ci_load_class($class, $params); + } + } + else + { + $this->_ci_load_class($library, $params); + } + + $this->_ci_assign_to_models(); + } + + // -------------------------------------------------------------------- + + /** + * Model Loader + * + * This function lets users load and instantiate models. + * + * @access public + * @param string the name of the class + * @param mixed any initialization parameters + * @return void + */ + function model($model, $name = '', $db_conn = FALSE) + { + if ($model == '') + return; + + // Is the model in a sub-folder? If so, parse out the filename and path. + if (strpos($model, '/') === FALSE) + { + $path = ''; + } + else + { + $x = explode('/', $model); + $model = end($x); + unset($x[count($x)-1]); + $path = implode('/', $x).'/'; + } + + 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); + + if ( ! file_exists(APPPATH.'models/'.$path.$model.EXT)) + { + show_error('Unable to locate the model you have specified: '.$model); + } + + 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('Model')) + { + require_once(BASEPATH.'libraries/Model'.EXT); + } + + require_once(APPPATH.'models/'.$path.$model.EXT); + + $model = ucfirst($model); + + $CI->$name = new $model(); + $CI->$name->_assign_libraries(); + + $this->_ci_models[] = $name; + } + + // -------------------------------------------------------------------- + + /** + * Database Loader + * + * @access public + * @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 + */ + function database($params = '', $return = FALSE, $active_record = FALSE) + { + // Do we even need to load the database class? + if (class_exists('CI_DB') AND $return == FALSE AND $active_record == FALSE) + { + return FALSE; + } + + require_once(BASEPATH.'database/DB'.EXT); + + if ($return === TRUE) + { + return DB($params, $active_record); + } + + // Grab the super object + $CI =& get_instance(); + + // Initialize the db variable. Needed to prevent + // reference errors with some configurations + $CI->db = ''; + + // Load the DB class + $CI->db =& DB($params, $active_record); + + // Assign the DB object to any existing models + $this->_ci_assign_to_models(); + } + + // -------------------------------------------------------------------- + + /** + * Load the Utilities Class + * + * @access public + * @return string + */ + function dbutil() + { + if ( ! class_exists('CI_DB')) + { + $this->database(); + } + + $CI =& get_instance(); + + require_once(BASEPATH.'database/DB_utility'.EXT); + require_once(BASEPATH.'database/drivers/'.$CI->db->dbdriver.'/'.$CI->db->dbdriver.'_utility'.EXT); + $class = 'CI_DB_'.$CI->db->dbdriver.'_utility'; + + $CI->dbutil = new $class(); + $CI->load->_ci_assign_to_models(); + } + + // -------------------------------------------------------------------- + + /** + * 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. + * + * @access public + * @param string + * @param array + * @param bool + * @return void + */ + function view($view, $vars = array(), $return = FALSE) + { + return $this->_ci_load(array('view' => $view, 'vars' => $this->_ci_object_to_array($vars), 'return' => $return)); + } + + // -------------------------------------------------------------------- + + /** + * Load File + * + * This is a generic file loader + * + * @access public + * @param string + * @param bool + * @return string + */ + function file($path, $return = FALSE) + { + return $this->_ci_load(array('path' => $path, 'return' => $return)); + } + + // -------------------------------------------------------------------- + + /** + * Set Variables + * + * Once variables are set they become available within + * the controller class and its "view" files. + * + * @access public + * @param array + * @return void + */ + function vars($vars = array()) + { + $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; + } + } + } + + // -------------------------------------------------------------------- + + /** + * Load Helper + * + * This function loads the specified helper file. + * + * @access public + * @param mixed + * @return void + */ + function helper($helpers = array()) + { + if ( ! is_array($helpers)) + { + $helpers = array($helpers); + } + + foreach ($helpers as $helper) + { + $helper = strtolower(str_replace(EXT, '', str_replace('_helper', '', $helper)).'_helper'); + + if (isset($this->_ci_helpers[$helper])) + { + continue; + } + + if (file_exists(APPPATH.'helpers/'.$helper.EXT)) + { + include_once(APPPATH.'helpers/'.$helper.EXT); + } + else + { + if (file_exists(BASEPATH.'helpers/'.$helper.EXT)) + { + include(BASEPATH.'helpers/'.$helper.EXT); + } + else + { + show_error('Unable to load the requested file: helpers/'.$helper.EXT); + } + } + + $this->_ci_helpers[$helper] = TRUE; + + } + + log_message('debug', 'Helpers loaded: '.implode(', ', $helpers)); + } + + // -------------------------------------------------------------------- + + /** + * Load Helpers + * + * This is simply an alias to the above function in case the + * user has written the plural form of this function. + * + * @access public + * @param array + * @return void + */ + function helpers($helpers = array()) + { + $this->helper($helpers); + } + + // -------------------------------------------------------------------- + + /** + * Load Plugin + * + * This function loads the specified plugin. + * + * @access public + * @param array + * @return void + */ + function plugin($plugins = array()) + { + if ( ! is_array($plugins)) + { + $plugins = array($plugins); + } + + foreach ($plugins as $plugin) + { + $plugin = strtolower(str_replace(EXT, '', str_replace('_plugin.', '', $plugin)).'_pi'); + + if (isset($this->_ci_plugins[$plugin])) + { + continue; + } + + if (file_exists(APPPATH.'plugins/'.$plugin.EXT)) + { + include(APPPATH.'plugins/'.$plugin.EXT); + } + else + { + if (file_exists(BASEPATH.'plugins/'.$plugin.EXT)) + { + include(BASEPATH.'plugins/'.$plugin.EXT); + } + else + { + show_error('Unable to load the requested file: plugins/'.$plugin.EXT); + } + } + + $this->_ci_plugins[$plugin] = TRUE; + } + + log_message('debug', 'Plugins loaded: '.implode(', ', $plugins)); + } + + // -------------------------------------------------------------------- + + /** + * Load Plugins + * + * This is simply an alias to the above function in case the + * user has written the plural form of this function. + * + * @access public + * @param array + * @return void + */ + function plugins($plugins = array()) + { + $this->plugin($plugins); + } + + // -------------------------------------------------------------------- + + /** + * Load Script + * + * This function loads the specified include file from the + * application/scripts/ folder. + * + * NOTE: This feature has been deprecated but it will remain available + * for legacy users. + * + * @access public + * @param array + * @return void + */ + function script($scripts = array()) + { + if ( ! is_array($scripts)) + { + $scripts = array($scripts); + } + + foreach ($scripts as $script) + { + $script = strtolower(str_replace(EXT, '', $script)); + + if (isset($this->_ci_scripts[$script])) + { + continue; + } + + if ( ! file_exists(APPPATH.'scripts/'.$script.EXT)) + { + show_error('Unable to load the requested script: scripts/'.$script.EXT); + } + + include(APPPATH.'scripts/'.$script.EXT); + } + + log_message('debug', 'Scripts loaded: '.implode(', ', $scripts)); + } + + // -------------------------------------------------------------------- + + /** + * Loads a language file + * + * @access public + * @param string + * @return void + */ + function language($file = '', $lang = '', $return = FALSE) + { + $CI =& get_instance(); + return $CI->lang->load($file, $lang, $return); + } + + // -------------------------------------------------------------------- + + /** + * Loads a config file + * + * @access public + * @param string + * @return void + */ + function config($file = '', $use_sections = FALSE, $fail_gracefully = FALSE) + { + $CI =& get_instance(); + $CI->config->load($file, $use_sections, $fail_gracefully); + } + + // -------------------------------------------------------------------- + + /** + * Scaffolding Loader + * + * This initializing function works a bit different than the + * others. It doesn't load the class. Instead, it simply + * sets a flag indicating that scaffolding is allowed to be + * used. The actual scaffolding function below is + * called by the front controller based on whether the + * second segment of the URL matches the "secret" scaffolding + * word stored in the application/config/routes.php + * + * @access public + * @param string + * @return void + */ + function scaffolding($table = '') + { + if ($table === FALSE) + { + show_error('You must include the name of the table you would like access when you initialize scaffolding'); + } + + $CI =& get_instance(); + $CI->_ci_scaffolding = TRUE; + $CI->_ci_scaff_table = $table; + } + + // -------------------------------------------------------------------- + + /** + * Loader + * + * This function is used to load views and files. + * + * @access private + * @param array + * @return void + */ + function _ci_load($data) + { + // Set the default data variables + foreach (array('view', 'vars', 'path', 'return') as $val) + { + $$val = ( ! isset($data[$val])) ? FALSE : $data[$val]; + } + + // Set the path to the requested file + if ($path == '') + { + $ext = pathinfo($view, PATHINFO_EXTENSION); + $file = ($ext == '') ? $view.EXT : $view; + $path = $this->_ci_view_path.$file; + } + else + { + $x = explode('/', $path); + $file = end($x); + } + + if ( ! file_exists($path)) + { + show_error('Unable to load the requested file: '.$file); + } + + // This allows anything loaded using $this->load (views, files, etc.) + // to become accessible from within the Controller and Model functions. + // Only needed when running PHP 5 + + if ($this->_ci_is_instance()) + { + $CI =& get_instance(); + foreach (get_object_vars($CI) as $key => $var) + { + if ( ! isset($this->$key)) + { + $this->$key =& $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($vars)) + { + $this->_ci_cached_vars = array_merge($this->_ci_cached_vars, $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 + { + // PHP 4 requires that we use a global + global $OUT; + $OUT->set_output(ob_get_contents()); + @ob_end_clean(); + } + } + + // -------------------------------------------------------------------- + + /** + * Load class + * + * This function loads the requested class. + * + * @access private + * @param string the item that is being loaded + * @param mixed any additional parameters + * @return void + */ + function _ci_load_class($class, $params = NULL) + { + // Get the class name + $class = str_replace(EXT, '', $class); + + // We'll test for both lowercase and capitalized versions of the file name + foreach (array(ucfirst($class), strtolower($class)) as $class) + { + // Is this a class extension request? + if (file_exists(APPPATH.'libraries/'.config_item('subclass_prefix').$class.EXT)) + { + if ( ! file_exists(BASEPATH.'libraries/'.ucfirst($class).EXT)) + { + log_message('error', "Unable to load the requested class: ".$class); + show_error("Unable to load the requested class: ".$class); + } + + include(BASEPATH.'libraries/'.ucfirst($class).EXT); + include(APPPATH.'libraries/'.config_item('subclass_prefix').$class.EXT); + + return $this->_ci_init_class($class, config_item('subclass_prefix'), $params); + } + + // Lets search for the requested library file and load it. + for ($i = 1; $i < 3; $i++) + { + $path = ($i % 2) ? APPPATH : BASEPATH; + $fp = $path.'libraries/'.$class.EXT; + + // Does the file exist? No? Bummer... + if ( ! file_exists($fp)) + { + continue; + } + + // Safety: Was the class already loaded by a previous call? + if (in_array($fp, $this->_ci_classes)) + { + log_message('debug', $class." class already loaded. Second attempt ignored."); + return; + } + + include($fp); + $this->_ci_classes[] = $fp; + return $this->_ci_init_class($class, '', $params); + } + } // END FOREACH + + // 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 + * + * @access private + * @param string + * @param string + * @return null + */ + function _ci_init_class($class, $prefix = '', $config = FALSE) + { + // Is there an associated config file for this class? + if ($config === NULL) + { + $config = NULL; + if (file_exists(APPPATH.'config/'.$class.EXT)) + { + include(APPPATH.'config/'.$class.EXT); + } + } + + if ($prefix == '') + { + $name = (class_exists('CI_'.$class)) ? 'CI_'.$class : $class; + } + else + { + $name = $prefix.$class; + } + + // Set the variable name we will assign the class to + $class = strtolower($class); + $classvar = ( ! isset($this->_ci_varmap[$class])) ? $class : $this->_ci_varmap[$class]; + + // 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, plugins, and helpers to be loaded automatically. + * + * @access private + * @param array + * @return void + */ + function _ci_autoloader() + { + include(APPPATH.'config/autoload'.EXT); + + if ( ! isset($autoload)) + { + return FALSE; + } + + // Load any custome config file + if (count($autoload['config']) > 0) + { + $CI =& get_instance(); + foreach ($autoload['config'] as $key => $val) + { + $CI->config->load($val); + } + } + + // Load plugins, helpers, and scripts + foreach (array('helper', 'plugin', 'script') 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'])) + { + $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 the model class. + if (in_array('model', $autoload['libraries'])) + { + $this->model(); + $autoload['libraries'] = array_diff($autoload['libraries'], array('model')); + } + + // Load scaffolding + if (in_array('scaffolding', $autoload['libraries'])) + { + $this->scaffolding(); + $autoload['libraries'] = array_diff($autoload['libraries'], array('scaffolding')); + } + + // Load all other libraries + foreach ($autoload['libraries'] as $item) + { + $this->library($item); + } + } + } + + // -------------------------------------------------------------------- + + /** + * Assign to Models + * + * Makes sure that anything loaded by the loader class (libraries, plugins, etc.) + * will be available to models, if any exist. + * + * @access private + * @param object + * @return array + */ + function _ci_assign_to_models() + { + if (count($this->_ci_models) == 0) + { + return; + } + + if ($this->_ci_is_instance()) + { + $CI =& get_instance(); + foreach ($this->_ci_models as $model) + { + $CI->$model->_assign_libraries(); + } + } + else + { + foreach ($this->_ci_models as $model) + { + $this->$model->_assign_libraries(); + } + } + } + + // -------------------------------------------------------------------- + + /** + * Object to Array + * + * Takes an object as input and converts the class variables to array key/vals + * + * @access private + * @param object + * @return array + */ + function _ci_object_to_array($object) + { + return (is_object($object)) ? get_object_vars($object) : $object; + } + + // -------------------------------------------------------------------- + + /** + * Determines whether we should use the CI instance or $this + * + * @access private + * @return bool + */ + function _ci_is_instance() + { + if ($this->_ci_is_php5 == TRUE) + { + return TRUE; + } + + global $CI; + return (is_object($CI)) ? TRUE : FALSE; + } + +} ?> \ No newline at end of file -- cgit v1.2.3-24-g4f1b From 320f3dfd8f6ea948d08660b57b29ed9c0de8d712 Mon Sep 17 00:00:00 2001 From: Derek Allard Date: Tue, 6 Feb 2007 04:06:08 +0000 Subject: changed app_ver to 1.5.1.1 --- system/codeigniter/CodeIgniter.php | 516 ++++++++++++++++++------------------- 1 file changed, 258 insertions(+), 258 deletions(-) (limited to 'system') diff --git a/system/codeigniter/CodeIgniter.php b/system/codeigniter/CodeIgniter.php index 3008b2ff2..1caf7c96c 100644 --- a/system/codeigniter/CodeIgniter.php +++ b/system/codeigniter/CodeIgniter.php @@ -1,259 +1,259 @@ -mark('total_execution_time_start'); -$BM->mark('loading_time_base_classes_start'); - -/* - * ------------------------------------------------------ - * Instantiate the hooks class - * ------------------------------------------------------ - */ - -$EXT =& load_class('Hooks'); - -/* - * ------------------------------------------------------ - * Is there a "pre_system" hook? - * ------------------------------------------------------ - */ -$EXT->_call_hook('pre_system'); - -/* - * ------------------------------------------------------ - * Instantiate the base classes - * ------------------------------------------------------ - */ - -$CFG =& load_class('Config'); -$RTR =& load_class('Router'); -$OUT =& load_class('Output'); - -/* - * ------------------------------------------------------ - * Is there a valid cache file? If so, we're done... - * ------------------------------------------------------ - */ - -if ($EXT->_call_hook('cache_override') === FALSE) -{ - if ($OUT->_display_cache($CFG, $RTR) == TRUE) - { - exit; - } -} - -/* - * ------------------------------------------------------ - * Load the remaining base classes - * ------------------------------------------------------ - */ - -$IN =& load_class('Input'); -$URI =& load_class('URI'); -$LANG =& load_class('Language'); - -/* - * ------------------------------------------------------ - * Load the app controller and local controller - * ------------------------------------------------------ - * - * Note: Due to the poor object handling in PHP 4 we'll - * conditionally load different versions of the base - * class. Retaining PHP 4 compatibility requires a bit of a hack. - * - * Note: The Loader class needs to be included first - * - */ -if (floor(phpversion()) < 5) -{ - load_class('Loader', FALSE); - require(BASEPATH.'codeigniter/Base4'.EXT); -} -else -{ - require(BASEPATH.'codeigniter/Base5'.EXT); -} - -// Load the base controller class -load_class('Controller', FALSE); - -// Load the local application controller -// Note: The Router class automatically validates the controller path. If this include fails it -// means that the default controller in the Routes.php file is not resolving to something valid. -if ( ! include(APPPATH.'controllers/'.$RTR->fetch_directory().$RTR->fetch_class().EXT)) -{ - show_error('Unable to load your default controller. Please make sure the controller specified in your Routes.php file is valid.'); -} - -// Set a mark point for benchmarking -$BM->mark('loading_time_base_classes_end'); - - -/* - * ------------------------------------------------------ - * Security check - * ------------------------------------------------------ - * - * 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 $method == 'controller' - OR substr($method, 0, 1) == '_' - OR in_array($method, get_class_methods('Controller'), TRUE) - ) -{ - show_404(); -} - -/* - * ------------------------------------------------------ - * Is there a "pre_controller" hook? - * ------------------------------------------------------ - */ -$EXT->_call_hook('pre_controller'); - -/* - * ------------------------------------------------------ - * Instantiate the controller and call requested method - * ------------------------------------------------------ - */ - -// Mark a start point so we can benchmark the controller -$BM->mark('controller_execution_time_( '.$class.' / '.$method.' )_start'); - -// Instantiate the Controller -$CI = new $class(); - -// Is this a scaffolding request? -if ($RTR->scaffolding_request === TRUE) -{ - if ($EXT->_call_hook('scaffolding_override') === FALSE) - { - $CI->_ci_scaffolding(); - } -} -else -{ - /* - * ------------------------------------------------------ - * Is there a "post_controller_constructor" hook? - * ------------------------------------------------------ - */ - $EXT->_call_hook('post_controller_constructor'); - - // Is there a "remap" function? - if (method_exists($CI, '_remap')) - { - $CI->_remap($method); - } - else - { - if ( ! method_exists($CI, $method)) - { - show_404(); - } - - // 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($RTR->rsegments, (($RTR->fetch_directory() == '') ? 2 : 3))); - } -} - -// Mark a benchmark end point -$BM->mark('controller_execution_time_( '.$class.' / '.$method.' )_end'); - -/* - * ------------------------------------------------------ - * Is there a "post_controller" hook? - * ------------------------------------------------------ - */ -$EXT->_call_hook('post_controller'); - -/* - * ------------------------------------------------------ - * Send the final rendered output to the browser - * ------------------------------------------------------ - */ - -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(); -} - - +mark('total_execution_time_start'); +$BM->mark('loading_time_base_classes_start'); + +/* + * ------------------------------------------------------ + * Instantiate the hooks class + * ------------------------------------------------------ + */ + +$EXT =& load_class('Hooks'); + +/* + * ------------------------------------------------------ + * Is there a "pre_system" hook? + * ------------------------------------------------------ + */ +$EXT->_call_hook('pre_system'); + +/* + * ------------------------------------------------------ + * Instantiate the base classes + * ------------------------------------------------------ + */ + +$CFG =& load_class('Config'); +$RTR =& load_class('Router'); +$OUT =& load_class('Output'); + +/* + * ------------------------------------------------------ + * Is there a valid cache file? If so, we're done... + * ------------------------------------------------------ + */ + +if ($EXT->_call_hook('cache_override') === FALSE) +{ + if ($OUT->_display_cache($CFG, $RTR) == TRUE) + { + exit; + } +} + +/* + * ------------------------------------------------------ + * Load the remaining base classes + * ------------------------------------------------------ + */ + +$IN =& load_class('Input'); +$URI =& load_class('URI'); +$LANG =& load_class('Language'); + +/* + * ------------------------------------------------------ + * Load the app controller and local controller + * ------------------------------------------------------ + * + * Note: Due to the poor object handling in PHP 4 we'll + * conditionally load different versions of the base + * class. Retaining PHP 4 compatibility requires a bit of a hack. + * + * Note: The Loader class needs to be included first + * + */ +if (floor(phpversion()) < 5) +{ + load_class('Loader', FALSE); + require(BASEPATH.'codeigniter/Base4'.EXT); +} +else +{ + require(BASEPATH.'codeigniter/Base5'.EXT); +} + +// Load the base controller class +load_class('Controller', FALSE); + +// Load the local application controller +// Note: The Router class automatically validates the controller path. If this include fails it +// means that the default controller in the Routes.php file is not resolving to something valid. +if ( ! include(APPPATH.'controllers/'.$RTR->fetch_directory().$RTR->fetch_class().EXT)) +{ + show_error('Unable to load your default controller. Please make sure the controller specified in your Routes.php file is valid.'); +} + +// Set a mark point for benchmarking +$BM->mark('loading_time_base_classes_end'); + + +/* + * ------------------------------------------------------ + * Security check + * ------------------------------------------------------ + * + * 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 $method == 'controller' + OR substr($method, 0, 1) == '_' + OR in_array($method, get_class_methods('Controller'), TRUE) + ) +{ + show_404(); +} + +/* + * ------------------------------------------------------ + * Is there a "pre_controller" hook? + * ------------------------------------------------------ + */ +$EXT->_call_hook('pre_controller'); + +/* + * ------------------------------------------------------ + * Instantiate the controller and call requested method + * ------------------------------------------------------ + */ + +// Mark a start point so we can benchmark the controller +$BM->mark('controller_execution_time_( '.$class.' / '.$method.' )_start'); + +// Instantiate the Controller +$CI = new $class(); + +// Is this a scaffolding request? +if ($RTR->scaffolding_request === TRUE) +{ + if ($EXT->_call_hook('scaffolding_override') === FALSE) + { + $CI->_ci_scaffolding(); + } +} +else +{ + /* + * ------------------------------------------------------ + * Is there a "post_controller_constructor" hook? + * ------------------------------------------------------ + */ + $EXT->_call_hook('post_controller_constructor'); + + // Is there a "remap" function? + if (method_exists($CI, '_remap')) + { + $CI->_remap($method); + } + else + { + if ( ! method_exists($CI, $method)) + { + show_404(); + } + + // 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($RTR->rsegments, (($RTR->fetch_directory() == '') ? 2 : 3))); + } +} + +// Mark a benchmark end point +$BM->mark('controller_execution_time_( '.$class.' / '.$method.' )_end'); + +/* + * ------------------------------------------------------ + * Is there a "post_controller" hook? + * ------------------------------------------------------ + */ +$EXT->_call_hook('post_controller'); + +/* + * ------------------------------------------------------ + * Send the final rendered output to the browser + * ------------------------------------------------------ + */ + +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(); +} + + ?> \ No newline at end of file -- cgit v1.2.3-24-g4f1b From 655bc02b4992d0ed764363f8181459d6390be24b Mon Sep 17 00:00:00 2001 From: Derek Allard Date: Tue, 6 Feb 2007 23:45:33 +0000 Subject: fixed grammer error in show_error message --- system/libraries/Loader.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system') diff --git a/system/libraries/Loader.php b/system/libraries/Loader.php index d11630712..aede38d7a 100644 --- a/system/libraries/Loader.php +++ b/system/libraries/Loader.php @@ -526,7 +526,7 @@ class CI_Loader { { if ($table === FALSE) { - show_error('You must include the name of the table you would like access when you initialize scaffolding'); + show_error('You must include the name of the table you would like to access when you initialize scaffolding'); } $CI =& get_instance(); -- cgit v1.2.3-24-g4f1b From dbbe40862c895296a9e3d9e184ff2da3788800d4 Mon Sep 17 00:00:00 2001 From: Derek Allard Date: Tue, 13 Feb 2007 23:46:23 +0000 Subject: changed Content-Disposition: from "inline" to "attachment" for MSIE in force_download() --- system/helpers/download_helper.php | 190 ++++++++++++++++++------------------- 1 file changed, 95 insertions(+), 95 deletions(-) (limited to 'system') diff --git a/system/helpers/download_helper.php b/system/helpers/download_helper.php index dbedd8722..34cc152cc 100644 --- a/system/helpers/download_helper.php +++ b/system/helpers/download_helper.php @@ -1,96 +1,96 @@ - \ No newline at end of file -- cgit v1.2.3-24-g4f1b From 561b6bb7ca046f2e047560a7c8b0db5a6a9b2a51 Mon Sep 17 00:00:00 2001 From: Derek Allard Date: Wed, 14 Feb 2007 01:34:52 +0000 Subject: updated app_version --- system/codeigniter/CodeIgniter.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system') diff --git a/system/codeigniter/CodeIgniter.php b/system/codeigniter/CodeIgniter.php index 1caf7c96c..12f1a0d5e 100644 --- a/system/codeigniter/CodeIgniter.php +++ b/system/codeigniter/CodeIgniter.php @@ -28,7 +28,7 @@ */ // CI Version -define('APPVER', '1.5.1.1'); +define('APPVER', '1.5.2'); /* * ------------------------------------------------------ -- cgit v1.2.3-24-g4f1b From 09de1854b1ac78f81264ca7a6b9d849ddcd1d159 Mon Sep 17 00:00:00 2001 From: Derek Allard Date: Wed, 14 Feb 2007 01:35:56 +0000 Subject: updated AR join() to accommodate database prefixes --- system/database/DB_active_rec.php | 1777 +++++++++++++++++++------------------ 1 file changed, 891 insertions(+), 886 deletions(-) (limited to 'system') diff --git a/system/database/DB_active_rec.php b/system/database/DB_active_rec.php index d27d3dc1e..1c72528e5 100644 --- a/system/database/DB_active_rec.php +++ b/system/database/DB_active_rec.php @@ -1,887 +1,892 @@ -ar_select[] = $val; - } - return $this; - } - - // -------------------------------------------------------------------- - - /** - * DISTINCT - * - * Sets a flag which tells the query string compiler to add DISTINCT - * - * @access public - * @param bool - * @return object - */ - function distinct($val = TRUE) - { - $this->ar_distinct = (is_bool($val)) ? $val : TRUE; - return $this; - } - - // -------------------------------------------------------------------- - - /** - * From - * - * Generates the FROM portion of the query - * - * @access public - * @param mixed can be a string or array - * @return object - */ - function from($from) - { - foreach ((array)$from as $val) - { - $this->ar_from[] = $this->dbprefix.$val; - } - return $this; - } - - // -------------------------------------------------------------------- - - /** - * Join - * - * Generates the JOIN portion of the query - * - * @access public - * @param string - * @param string the join condition - * @param string the type of join - * @return object - */ - function join($table, $cond, $type = '') - { - if ($type != '') - { - $type = strtoupper(trim($type)); - - if ( ! in_array($type, array('LEFT', 'RIGHT', 'OUTER', 'INNER', 'LEFT OUTER', 'RIGHT OUTER'), TRUE)) - { - $type = ''; - } - else - { - $type .= ' '; - } - } - - // If a DB prefix is used we might need to add it to the column names - if ($this->dbprefix) - { - // First we remove any existing prefixes in the condition to avoid duplicates - $cond = preg_replace('|('.$this->dbprefix.')([\w\.]+)([\W\s]+)|', "$2$3", $cond); - - // Next we add the prefixes to the condition - $cond = preg_replace('|([\w\.]+)([\W\s]+)(.+)|', $this->dbprefix . "$1$2" . $this->dbprefix . "$3", $cond); - } - - $this->ar_join[] = $type.'JOIN '.$this->dbprefix.$table.' ON '.$cond; - return $this; - } - - // -------------------------------------------------------------------- - - /** - * Where - * - * Generates the WHERE portion of the query. Separates - * multiple calls with AND - * - * @access public - * @param mixed - * @param mixed - * @return object - */ - function where($key, $value = NULL) - { - return $this->_where($key, $value, 'AND '); - } - - // -------------------------------------------------------------------- - - /** - * OR Where - * - * Generates the WHERE portion of the query. Separates - * multiple calls with OR - * - * @access public - * @param mixed - * @param mixed - * @return object - */ - function orwhere($key, $value = NULL) - { - return $this->_where($key, $value, 'OR '); - } - - // -------------------------------------------------------------------- - - /** - * Where - * - * Called by where() or orwhere() - * - * @access private - * @param mixed - * @param mixed - * @param string - * @return object - */ - function _where($key, $value = NULL, $type = 'AND ') - { - if ( ! is_array($key)) - { - $key = array($key => $value); - } - - foreach ($key as $k => $v) - { - $prefix = (count($this->ar_where) == 0) ? '' : $type; - - if ( ! is_null($v)) - { - if ( ! $this->_has_operator($k)) - { - $k .= ' ='; - } - - $v = ' '.$this->escape($v); - } - - $this->ar_where[] = $prefix.$k.$v; - } - return $this; - } - - - - // -------------------------------------------------------------------- - - /** - * Like - * - * Generates a %LIKE% portion of the query. Separates - * multiple calls with AND - * - * @access public - * @param mixed - * @param mixed - * @return object - */ - function like($field, $match = '') - { - return $this->_like($field, $match, 'AND '); - } - - // -------------------------------------------------------------------- - - /** - * OR Like - * - * Generates a %LIKE% portion of the query. Separates - * multiple calls with OR - * - * @access public - * @param mixed - * @param mixed - * @return object - */ - function orlike($field, $match = '') - { - return $this->_like($field, $match, 'OR '); - } - - // -------------------------------------------------------------------- - - /** - * Like - * - * Called by like() or orlike() - * - * @access private - * @param mixed - * @param mixed - * @param string - * @return object - */ - function _like($field, $match = '', $type = 'AND ') - { - if ( ! is_array($field)) - { - $field = array($field => $match); - } - - foreach ($field as $k => $v) - { - $prefix = (count($this->ar_like) == 0) ? '' : $type; - - $v = $this->escape_str($v); - - $this->ar_like[] = $prefix." $k LIKE '%{$v}%'"; - } - return $this; - } - - // -------------------------------------------------------------------- - - /** - * GROUP BY - * - * @access public - * @param string - * @return object - */ - function groupby($by) - { - if (is_string($by)) - { - $by = explode(',', $by); - } - - foreach ($by as $val) - { - $val = trim($val); - - if ($val != '') - $this->ar_groupby[] = $val; - } - return $this; - } - - // -------------------------------------------------------------------- - - /** - * Sets the HAVING value - * - * Separates multiple calls with AND - * - * @access public - * @param string - * @param string - * @return object - */ - function having($key, $value = '') - { - return $this->_having($key, $value, 'AND '); - } - - // -------------------------------------------------------------------- - - /** - * Sets the OR HAVING value - * - * Separates multiple calls with OR - * - * @access public - * @param string - * @param string - * @return object - */ - function orhaving($key, $value = '') - { - return $this->_having($key, $value, 'OR '); - } - - // -------------------------------------------------------------------- - - /** - * Sets the HAVING values - * - * Called by having() or orhaving() - * - * @access private - * @param string - * @param string - * @return object - */ - function _having($key, $value = '', $type = 'AND ') - { - if ( ! is_array($key)) - { - $key = array($key => $value); - } - - foreach ($key as $k => $v) - { - $prefix = (count($this->ar_having) == 0) ? '' : $type; - - if ($v != '') - { - $v = ' '.$this->escape($v); - } - - $this->ar_having[] = $prefix.$k.$v; - } - return $this; - } - - // -------------------------------------------------------------------- - - /** - * Sets the ORDER BY value - * - * @access public - * @param string - * @param string direction: asc or desc - * @return object - */ - function orderby($orderby, $direction = '') - { - if (trim($direction) != '') - { - $direction = (in_array(strtoupper(trim($direction)), array('ASC', 'DESC', 'RAND()'), TRUE)) ? ' '.$direction : ' ASC'; - } - - $this->ar_orderby[] = $orderby.$direction; - return $this; - } - - // -------------------------------------------------------------------- - - /** - * Sets the LIMIT value - * - * @access public - * @param integer the limit value - * @param integer the offset value - * @return object - */ - function limit($value, $offset = '') - { - $this->ar_limit = $value; - - if ($offset != '') - $this->ar_offset = $offset; - - return $this; - } - - // -------------------------------------------------------------------- - - /** - * Sets the OFFSET value - * - * @access public - * @param integer the offset value - * @return object - */ - function offset($value) - { - $this->ar_offset = $value; - return $this; - } - - // -------------------------------------------------------------------- - - /** - * The "set" function. Allows key/value pairs to be set for inserting or updating - * - * @access public - * @param mixed - * @param string - * @return object - */ - function set($key, $value = '') - { - $key = $this->_object_to_array($key); - - if ( ! is_array($key)) - { - $key = array($key => $value); - } - - foreach ($key as $k => $v) - { - $this->ar_set[$k] = $this->escape($v); - } - - return $this; - } - - // -------------------------------------------------------------------- - - /** - * Get - * - * Compiles the select statement based on the other functions called - * and runs the query - * - * @access public - * @param string the limit clause - * @param string the offset clause - * @return object - */ - function get($table = '', $limit = null, $offset = null) - { - if ($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; - } - - // -------------------------------------------------------------------- - - /** - * GetWhere - * - * Allows the where clause, limit and offset to be added directly - * - * @access public - * @param string the where clause - * @param string the limit clause - * @param string the offset clause - * @return object - */ - function getwhere($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 - * - * Compiles an insert string and runs the query - * - * @access public - * @param string the table to retrieve the results from - * @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->dbprefix.$table, 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 - * - * @access public - * @param string the table to retrieve the results from - * @param array an associative array of update values - * @param mixed the where clause - * @return object - */ - function update($table = '', $set = NULL, $where = 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]; - } - - if ($where != null) - { - $this->where($where); - } - - $sql = $this->_update($this->dbprefix.$table, $this->ar_set, $this->ar_where); - - $this->_reset_write(); - return $this->query($sql); - } - - // -------------------------------------------------------------------- - - /** - * Delete - * - * Compiles a delete string and runs the query - * - * @access public - * @param string the table to retrieve the results from - * @param mixed the where clause - * @return object - */ - function delete($table = '', $where = '') - { - 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 != '') - { - $this->where($where); - } - - if (count($this->ar_where) == 0) - { - if ($this->db_debug) - { - return $this->display_error('db_del_must_use_where'); - } - return FALSE; - } - - $sql = $this->_delete($this->dbprefix.$table, $this->ar_where); - - $this->_reset_write(); - return $this->query($sql); - } - - // -------------------------------------------------------------------- - - /** - * Use Table - DEPRECATED - * - * @deprecated use $this->db->from instead - */ - function use_table($table) - { - return $this->from($table); - return $this; - } - - // -------------------------------------------------------------------- - - /** - * ORDER BY - DEPRECATED - * - * @deprecated use $this->db->orderby() instead - */ - function order_by($orderby, $direction = '') - { - return $this->orderby($orderby, $direction); - } - - // -------------------------------------------------------------------- - - /** - * 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; - } - - // -------------------------------------------------------------------- - - /** - * Compile the SELECT statement - * - * Generates a query string based on which functions were used. - * Should not be called directly. The get() function calls it. - * - * @access private - * @return string - */ - function _compile_select() - { - $sql = ( ! $this->ar_distinct) ? 'SELECT ' : 'SELECT DISTINCT '; - - $sql .= (count($this->ar_select) == 0) ? '*' : implode(', ', $this->ar_select); - - if (count($this->ar_from) > 0) - { - $sql .= "\nFROM "; - $sql .= implode(', ', $this->ar_from); - } - - if (count($this->ar_join) > 0) - { - $sql .= "\n"; - $sql .= implode("\n", $this->ar_join); - } - - if (count($this->ar_where) > 0 OR count($this->ar_like) > 0) - { - $sql .= "\nWHERE "; - } - - $sql .= implode("\n", $this->ar_where); - - if (count($this->ar_like) > 0) - { - if (count($this->ar_where) > 0) - { - $sql .= " AND "; - } - - $sql .= implode("\n", $this->ar_like); - } - - if (count($this->ar_groupby) > 0) - { - $sql .= "\nGROUP BY "; - $sql .= implode(', ', $this->ar_groupby); - } - - if (count($this->ar_having) > 0) - { - $sql .= "\nHAVING "; - $sql .= implode("\n", $this->ar_having); - } - - 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'; - } - } - - 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 - * - * @access public - * @param object - * @return array - */ - function _object_to_array($object) - { - if ( ! is_object($object)) - { - return $object; - } - - $array = array(); - foreach (get_object_vars($object) as $key => $val) - { - if ( ! is_object($val) AND ! is_array($val)) - { - $array[$key] = $val; - } - } - - return $array; - } - - // -------------------------------------------------------------------- - - /** - * Resets the active record values. Called by the get() function - * - * @access private - * @return void - */ - function _reset_select() - { - $this->ar_select = array(); - $this->ar_distinct = FALSE; - $this->ar_from = array(); - $this->ar_join = array(); - $this->ar_where = array(); - $this->ar_like = array(); - $this->ar_groupby = array(); - $this->ar_having = array(); - $this->ar_limit = FALSE; - $this->ar_offset = FALSE; - $this->ar_order = FALSE; - $this->ar_orderby = array(); - } - - // -------------------------------------------------------------------- - - /** - * Resets the active record "write" values. - * - * Called by the insert() or update() functions - * - * @access private - * @return void - */ - function _reset_write() - { - $this->ar_set = array(); - $this->ar_from = array(); - $this->ar_where = array(); - } - -} - +ar_select[] = $val; + } + return $this; + } + + // -------------------------------------------------------------------- + + /** + * DISTINCT + * + * Sets a flag which tells the query string compiler to add DISTINCT + * + * @access public + * @param bool + * @return object + */ + function distinct($val = TRUE) + { + $this->ar_distinct = (is_bool($val)) ? $val : TRUE; + return $this; + } + + // -------------------------------------------------------------------- + + /** + * From + * + * Generates the FROM portion of the query + * + * @access public + * @param mixed can be a string or array + * @return object + */ + function from($from) + { + foreach ((array)$from as $val) + { + $this->ar_from[] = $this->dbprefix.$val; + } + return $this; + } + + // -------------------------------------------------------------------- + + /** + * Join + * + * Generates the JOIN portion of the query + * + * @access public + * @param string + * @param string the join condition + * @param string the type of join + * @return object + */ + function join($table, $cond, $type = '') + { + if ($type != '') + { + $type = strtoupper(trim($type)); + + if ( ! in_array($type, array('LEFT', 'RIGHT', 'OUTER', 'INNER', 'LEFT OUTER', 'RIGHT OUTER'), TRUE)) + { + $type = ''; + } + else + { + $type .= ' '; + } + } + + if ($this->dbprefix) + { + $cond = preg_replace('|([\w\.]+)([\W\s]+)(.+)|', $this->dbprefix . "$1$2" . $this->dbprefix . "$3", $cond); + } + + // If a DB prefix is used we might need to add it to the column names + if ($this->dbprefix) + { + // First we remove any existing prefixes in the condition to avoid duplicates + $cond = preg_replace('|('.$this->dbprefix.')([\w\.]+)([\W\s]+)|', "$2$3", $cond); + + // Next we add the prefixes to the condition + $cond = preg_replace('|([\w\.]+)([\W\s]+)(.+)|', $this->dbprefix . "$1$2" . $this->dbprefix . "$3", $cond); + } + + $this->ar_join[] = $type.'JOIN '.$this->dbprefix.$table.' ON '.$cond; + return $this; + } + + // -------------------------------------------------------------------- + + /** + * Where + * + * Generates the WHERE portion of the query. Separates + * multiple calls with AND + * + * @access public + * @param mixed + * @param mixed + * @return object + */ + function where($key, $value = NULL) + { + return $this->_where($key, $value, 'AND '); + } + + // -------------------------------------------------------------------- + + /** + * OR Where + * + * Generates the WHERE portion of the query. Separates + * multiple calls with OR + * + * @access public + * @param mixed + * @param mixed + * @return object + */ + function orwhere($key, $value = NULL) + { + return $this->_where($key, $value, 'OR '); + } + + // -------------------------------------------------------------------- + + /** + * Where + * + * Called by where() or orwhere() + * + * @access private + * @param mixed + * @param mixed + * @param string + * @return object + */ + function _where($key, $value = NULL, $type = 'AND ') + { + if ( ! is_array($key)) + { + $key = array($key => $value); + } + + foreach ($key as $k => $v) + { + $prefix = (count($this->ar_where) == 0) ? '' : $type; + + if ( ! is_null($v)) + { + if ( ! $this->_has_operator($k)) + { + $k .= ' ='; + } + + $v = ' '.$this->escape($v); + } + + $this->ar_where[] = $prefix.$k.$v; + } + return $this; + } + + + + // -------------------------------------------------------------------- + + /** + * Like + * + * Generates a %LIKE% portion of the query. Separates + * multiple calls with AND + * + * @access public + * @param mixed + * @param mixed + * @return object + */ + function like($field, $match = '') + { + return $this->_like($field, $match, 'AND '); + } + + // -------------------------------------------------------------------- + + /** + * OR Like + * + * Generates a %LIKE% portion of the query. Separates + * multiple calls with OR + * + * @access public + * @param mixed + * @param mixed + * @return object + */ + function orlike($field, $match = '') + { + return $this->_like($field, $match, 'OR '); + } + + // -------------------------------------------------------------------- + + /** + * Like + * + * Called by like() or orlike() + * + * @access private + * @param mixed + * @param mixed + * @param string + * @return object + */ + function _like($field, $match = '', $type = 'AND ') + { + if ( ! is_array($field)) + { + $field = array($field => $match); + } + + foreach ($field as $k => $v) + { + $prefix = (count($this->ar_like) == 0) ? '' : $type; + + $v = $this->escape_str($v); + + $this->ar_like[] = $prefix." $k LIKE '%{$v}%'"; + } + return $this; + } + + // -------------------------------------------------------------------- + + /** + * GROUP BY + * + * @access public + * @param string + * @return object + */ + function groupby($by) + { + if (is_string($by)) + { + $by = explode(',', $by); + } + + foreach ($by as $val) + { + $val = trim($val); + + if ($val != '') + $this->ar_groupby[] = $val; + } + return $this; + } + + // -------------------------------------------------------------------- + + /** + * Sets the HAVING value + * + * Separates multiple calls with AND + * + * @access public + * @param string + * @param string + * @return object + */ + function having($key, $value = '') + { + return $this->_having($key, $value, 'AND '); + } + + // -------------------------------------------------------------------- + + /** + * Sets the OR HAVING value + * + * Separates multiple calls with OR + * + * @access public + * @param string + * @param string + * @return object + */ + function orhaving($key, $value = '') + { + return $this->_having($key, $value, 'OR '); + } + + // -------------------------------------------------------------------- + + /** + * Sets the HAVING values + * + * Called by having() or orhaving() + * + * @access private + * @param string + * @param string + * @return object + */ + function _having($key, $value = '', $type = 'AND ') + { + if ( ! is_array($key)) + { + $key = array($key => $value); + } + + foreach ($key as $k => $v) + { + $prefix = (count($this->ar_having) == 0) ? '' : $type; + + if ($v != '') + { + $v = ' '.$this->escape($v); + } + + $this->ar_having[] = $prefix.$k.$v; + } + return $this; + } + + // -------------------------------------------------------------------- + + /** + * Sets the ORDER BY value + * + * @access public + * @param string + * @param string direction: asc or desc + * @return object + */ + function orderby($orderby, $direction = '') + { + if (trim($direction) != '') + { + $direction = (in_array(strtoupper(trim($direction)), array('ASC', 'DESC', 'RAND()'), TRUE)) ? ' '.$direction : ' ASC'; + } + + $this->ar_orderby[] = $orderby.$direction; + return $this; + } + + // -------------------------------------------------------------------- + + /** + * Sets the LIMIT value + * + * @access public + * @param integer the limit value + * @param integer the offset value + * @return object + */ + function limit($value, $offset = '') + { + $this->ar_limit = $value; + + if ($offset != '') + $this->ar_offset = $offset; + + return $this; + } + + // -------------------------------------------------------------------- + + /** + * Sets the OFFSET value + * + * @access public + * @param integer the offset value + * @return object + */ + function offset($value) + { + $this->ar_offset = $value; + return $this; + } + + // -------------------------------------------------------------------- + + /** + * The "set" function. Allows key/value pairs to be set for inserting or updating + * + * @access public + * @param mixed + * @param string + * @return object + */ + function set($key, $value = '') + { + $key = $this->_object_to_array($key); + + if ( ! is_array($key)) + { + $key = array($key => $value); + } + + foreach ($key as $k => $v) + { + $this->ar_set[$k] = $this->escape($v); + } + + return $this; + } + + // -------------------------------------------------------------------- + + /** + * Get + * + * Compiles the select statement based on the other functions called + * and runs the query + * + * @access public + * @param string the limit clause + * @param string the offset clause + * @return object + */ + function get($table = '', $limit = null, $offset = null) + { + if ($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; + } + + // -------------------------------------------------------------------- + + /** + * GetWhere + * + * Allows the where clause, limit and offset to be added directly + * + * @access public + * @param string the where clause + * @param string the limit clause + * @param string the offset clause + * @return object + */ + function getwhere($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 + * + * Compiles an insert string and runs the query + * + * @access public + * @param string the table to retrieve the results from + * @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->dbprefix.$table, 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 + * + * @access public + * @param string the table to retrieve the results from + * @param array an associative array of update values + * @param mixed the where clause + * @return object + */ + function update($table = '', $set = NULL, $where = 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]; + } + + if ($where != null) + { + $this->where($where); + } + + $sql = $this->_update($this->dbprefix.$table, $this->ar_set, $this->ar_where); + + $this->_reset_write(); + return $this->query($sql); + } + + // -------------------------------------------------------------------- + + /** + * Delete + * + * Compiles a delete string and runs the query + * + * @access public + * @param string the table to retrieve the results from + * @param mixed the where clause + * @return object + */ + function delete($table = '', $where = '') + { + 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 != '') + { + $this->where($where); + } + + if (count($this->ar_where) == 0) + { + if ($this->db_debug) + { + return $this->display_error('db_del_must_use_where'); + } + return FALSE; + } + + $sql = $this->_delete($this->dbprefix.$table, $this->ar_where); + + $this->_reset_write(); + return $this->query($sql); + } + + // -------------------------------------------------------------------- + + /** + * Use Table - DEPRECATED + * + * @deprecated use $this->db->from instead + */ + function use_table($table) + { + return $this->from($table); + return $this; + } + + // -------------------------------------------------------------------- + + /** + * ORDER BY - DEPRECATED + * + * @deprecated use $this->db->orderby() instead + */ + function order_by($orderby, $direction = '') + { + return $this->orderby($orderby, $direction); + } + + // -------------------------------------------------------------------- + + /** + * 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; + } + + // -------------------------------------------------------------------- + + /** + * Compile the SELECT statement + * + * Generates a query string based on which functions were used. + * Should not be called directly. The get() function calls it. + * + * @access private + * @return string + */ + function _compile_select() + { + $sql = ( ! $this->ar_distinct) ? 'SELECT ' : 'SELECT DISTINCT '; + + $sql .= (count($this->ar_select) == 0) ? '*' : implode(', ', $this->ar_select); + + if (count($this->ar_from) > 0) + { + $sql .= "\nFROM "; + $sql .= implode(', ', $this->ar_from); + } + + if (count($this->ar_join) > 0) + { + $sql .= "\n"; + $sql .= implode("\n", $this->ar_join); + } + + if (count($this->ar_where) > 0 OR count($this->ar_like) > 0) + { + $sql .= "\nWHERE "; + } + + $sql .= implode("\n", $this->ar_where); + + if (count($this->ar_like) > 0) + { + if (count($this->ar_where) > 0) + { + $sql .= " AND "; + } + + $sql .= implode("\n", $this->ar_like); + } + + if (count($this->ar_groupby) > 0) + { + $sql .= "\nGROUP BY "; + $sql .= implode(', ', $this->ar_groupby); + } + + if (count($this->ar_having) > 0) + { + $sql .= "\nHAVING "; + $sql .= implode("\n", $this->ar_having); + } + + 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'; + } + } + + 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 + * + * @access public + * @param object + * @return array + */ + function _object_to_array($object) + { + if ( ! is_object($object)) + { + return $object; + } + + $array = array(); + foreach (get_object_vars($object) as $key => $val) + { + if ( ! is_object($val) AND ! is_array($val)) + { + $array[$key] = $val; + } + } + + return $array; + } + + // -------------------------------------------------------------------- + + /** + * Resets the active record values. Called by the get() function + * + * @access private + * @return void + */ + function _reset_select() + { + $this->ar_select = array(); + $this->ar_distinct = FALSE; + $this->ar_from = array(); + $this->ar_join = array(); + $this->ar_where = array(); + $this->ar_like = array(); + $this->ar_groupby = array(); + $this->ar_having = array(); + $this->ar_limit = FALSE; + $this->ar_offset = FALSE; + $this->ar_order = FALSE; + $this->ar_orderby = array(); + } + + // -------------------------------------------------------------------- + + /** + * Resets the active record "write" values. + * + * Called by the insert() or update() functions + * + * @access private + * @return void + */ + function _reset_write() + { + $this->ar_set = array(); + $this->ar_from = array(); + $this->ar_where = array(); + } + +} + ?> \ No newline at end of file -- cgit v1.2.3-24-g4f1b From 4dde0de7576872c075171c75363dfad7e5528952 Mon Sep 17 00:00:00 2001 From: Derek Allard Date: Wed, 14 Feb 2007 22:44:36 +0000 Subject: fixed an undefined var --- system/libraries/Loader.php | 2 ++ 1 file changed, 2 insertions(+) (limited to 'system') diff --git a/system/libraries/Loader.php b/system/libraries/Loader.php index aede38d7a..e634c3885 100644 --- a/system/libraries/Loader.php +++ b/system/libraries/Loader.php @@ -697,6 +697,7 @@ class CI_Loader { } // Lets search for the requested library file and load it. + $is_duplicate = FALSE; for ($i = 1; $i < 3; $i++) { $path = ($i % 2) ? APPPATH : BASEPATH; @@ -711,6 +712,7 @@ class CI_Loader { // Safety: Was the class already loaded by a previous call? if (in_array($fp, $this->_ci_classes)) { + $is_duplicate = TRUE; log_message('debug', $class." class already loaded. Second attempt ignored."); return; } -- cgit v1.2.3-24-g4f1b From c4ac15f47a73a2db99406d901d53803b87f255bb Mon Sep 17 00:00:00 2001 From: Derek Allard Date: Thu, 15 Feb 2007 17:22:31 +0000 Subject: fixed a a value bug introduced when clearing value from textarea --- system/helpers/form_helper.php | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) (limited to 'system') diff --git a/system/helpers/form_helper.php b/system/helpers/form_helper.php index 8186d4ccd..a166198fb 100644 --- a/system/helpers/form_helper.php +++ b/system/helpers/form_helper.php @@ -196,9 +196,15 @@ function form_textarea($data = '', $value = '', $extra = '') { $defaults = array('name' => (( ! is_array($data)) ? $data : ''), 'cols' => '90', 'rows' => '12'); - $val = (( ! is_array($data) OR ! isset($data['value'])) ? $value : $data['value']); - - unset ($data['value']); // textareas don't use the value attribute + 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"; } -- cgit v1.2.3-24-g4f1b From a8b10bed6b1064548b8af605e5b16113b457de02 Mon Sep 17 00:00:00 2001 From: Derek Allard Date: Thu, 15 Feb 2007 18:20:05 +0000 Subject: allow for extending models --- system/libraries/Loader.php | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) (limited to 'system') diff --git a/system/libraries/Loader.php b/system/libraries/Loader.php index e634c3885..8438cc0bb 100644 --- a/system/libraries/Loader.php +++ b/system/libraries/Loader.php @@ -154,10 +154,7 @@ class CI_Loader { $CI->load->database($db_conn, FALSE, TRUE); } - if ( ! class_exists('Model')) - { - require_once(BASEPATH.'libraries/Model'.EXT); - } + load_class('Model', false); require_once(APPPATH.'models/'.$path.$model.EXT); -- cgit v1.2.3-24-g4f1b From ac0eb4543ce713d0d25125614489de3b8b2fd296 Mon Sep 17 00:00:00 2001 From: Derek Allard Date: Thu, 15 Feb 2007 18:42:22 +0000 Subject: reverted a change user testing revealed a flaw. --- system/libraries/Loader.php | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'system') diff --git a/system/libraries/Loader.php b/system/libraries/Loader.php index 8438cc0bb..e634c3885 100644 --- a/system/libraries/Loader.php +++ b/system/libraries/Loader.php @@ -154,7 +154,10 @@ class CI_Loader { $CI->load->database($db_conn, FALSE, TRUE); } - load_class('Model', false); + if ( ! class_exists('Model')) + { + require_once(BASEPATH.'libraries/Model'.EXT); + } require_once(APPPATH.'models/'.$path.$model.EXT); -- cgit v1.2.3-24-g4f1b From 5811bf1da422839d8dd6cfc7e6bac65649fceacd Mon Sep 17 00:00:00 2001 From: Derek Allard Date: Tue, 20 Feb 2007 01:26:08 +0000 Subject: added a space to redirect Location to conform to w3c http spec --- system/helpers/url_helper.php | 984 +++++++++++++++++++++--------------------- 1 file changed, 492 insertions(+), 492 deletions(-) (limited to 'system') diff --git a/system/helpers/url_helper.php b/system/helpers/url_helper.php index 3ca597460..baac0e5d8 100644 --- a/system/helpers/url_helper.php +++ b/system/helpers/url_helper.php @@ -1,493 +1,493 @@ -config->site_url($uri); -} - -// ------------------------------------------------------------------------ - -/** - * Base URL - * - * Returns the "base_url" item from your config file - * - * @access public - * @return string - */ -function base_url() -{ - $CI =& get_instance(); - return $CI->config->slash_item('base_url'); -} - -// ------------------------------------------------------------------------ - -/** - * Index page - * - * Returns the "index_page" from your config file - * - * @access public - * @return string - */ -function index_page() -{ - $CI =& get_instance(); - return $CI->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 - */ -function anchor($uri = '', $title = '', $attributes = '') -{ - 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 = ' title="'.$title.'"'; - } - else - { - $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. - * - * @access public - * @param string the URL - * @param string the link title - * @param mixed any attributes - * @return string - */ -function anchor_popup($uri = '', $title = '', $attributes = FALSE) -{ - $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]; - } - - return "".$title.""; -} - -// ------------------------------------------------------------------------ - -/** - * Mailto Link - * - * @access public - * @param string the email address - * @param string the link title - * @param mixed any attributes - * @return string - */ -function mailto($email, $title = '', $attributes = '') -{ - if ($title == "") - { - $title = $email; - } - - $attributes = _parse_attributes($attributes); - - 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 - */ -function safe_mailto($email, $title = '', $attributes = '') -{ - 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(); - -?>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 < sizeof($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; -} - -// ------------------------------------------------------------------------ - -/** - * Prep URL - * - * Simply adds the http:// part if missing - * - * @access public - * @param string the URL - * @return string - */ -function prep_url($str = '') -{ - if ($str == 'http://' OR $str == '') - { - return ''; - } - - if (substr($str, 0, 7) != 'http://' && substr($str, 0, 8) != 'https://') - { - $str = 'http://'.$str; - } - - return $str; -} - -// ------------------------------------------------------------------------ - -/** - * Create URL Title - * - * Takes a "title" string as input and creates a - * human-friendly URL string with either a dash - * or an underscore as the word separator. - * - * @access public - * @param string the string - * @param string the separator: dash, or underscore - * @return string - */ -function url_title($str, $separator = 'dash') -{ - if ($separator == 'dash') - { - $search = '_'; - $replace = '-'; - } - else - { - $search = '-'; - $replace = '_'; - } - - $trans = array( - $search => $replace, - "\s+" => $replace, - "[^a-z0-9".$replace."]" => '', - $replace."+" => $replace, - $replace."$" => '', - "^".$replace => '' - ); - - $str = strip_tags(strtolower($str)); - - foreach ($trans as $key => $val) - { - $str = preg_replace("#".$key."#", $val, $str); - } - - return trim(stripslashes($str)); -} - -// ------------------------------------------------------------------------ - -/** - * Header Redirect - * - * Header redirect in two flavors - * - * @access public - * @param string the URL - * @param string the method: location or redirect - * @return string - */ -function redirect($uri = '', $method = 'location') -{ - switch($method) - { - case 'refresh' : header("Refresh:0;url=".site_url($uri)); - break; - default : header("location:".site_url($uri)); - break; - } - exit; -} - -// ------------------------------------------------------------------------ - -/** - * Parse out the attributes - * - * Some of the functions use this - * - * @access private - * @param array - * @param bool - * @return string - */ -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; -} - +config->site_url($uri); +} + +// ------------------------------------------------------------------------ + +/** + * Base URL + * + * Returns the "base_url" item from your config file + * + * @access public + * @return string + */ +function base_url() +{ + $CI =& get_instance(); + return $CI->config->slash_item('base_url'); +} + +// ------------------------------------------------------------------------ + +/** + * Index page + * + * Returns the "index_page" from your config file + * + * @access public + * @return string + */ +function index_page() +{ + $CI =& get_instance(); + return $CI->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 + */ +function anchor($uri = '', $title = '', $attributes = '') +{ + 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 = ' title="'.$title.'"'; + } + else + { + $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. + * + * @access public + * @param string the URL + * @param string the link title + * @param mixed any attributes + * @return string + */ +function anchor_popup($uri = '', $title = '', $attributes = FALSE) +{ + $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]; + } + + return "".$title.""; +} + +// ------------------------------------------------------------------------ + +/** + * Mailto Link + * + * @access public + * @param string the email address + * @param string the link title + * @param mixed any attributes + * @return string + */ +function mailto($email, $title = '', $attributes = '') +{ + if ($title == "") + { + $title = $email; + } + + $attributes = _parse_attributes($attributes); + + 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 + */ +function safe_mailto($email, $title = '', $attributes = '') +{ + 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(); + +?>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 < sizeof($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; +} + +// ------------------------------------------------------------------------ + +/** + * Prep URL + * + * Simply adds the http:// part if missing + * + * @access public + * @param string the URL + * @return string + */ +function prep_url($str = '') +{ + if ($str == 'http://' OR $str == '') + { + return ''; + } + + if (substr($str, 0, 7) != 'http://' && substr($str, 0, 8) != 'https://') + { + $str = 'http://'.$str; + } + + return $str; +} + +// ------------------------------------------------------------------------ + +/** + * Create URL Title + * + * Takes a "title" string as input and creates a + * human-friendly URL string with either a dash + * or an underscore as the word separator. + * + * @access public + * @param string the string + * @param string the separator: dash, or underscore + * @return string + */ +function url_title($str, $separator = 'dash') +{ + if ($separator == 'dash') + { + $search = '_'; + $replace = '-'; + } + else + { + $search = '-'; + $replace = '_'; + } + + $trans = array( + $search => $replace, + "\s+" => $replace, + "[^a-z0-9".$replace."]" => '', + $replace."+" => $replace, + $replace."$" => '', + "^".$replace => '' + ); + + $str = strip_tags(strtolower($str)); + + foreach ($trans as $key => $val) + { + $str = preg_replace("#".$key."#", $val, $str); + } + + return trim(stripslashes($str)); +} + +// ------------------------------------------------------------------------ + +/** + * Header Redirect + * + * Header redirect in two flavors + * + * @access public + * @param string the URL + * @param string the method: location or redirect + * @return string + */ +function redirect($uri = '', $method = 'location') +{ + switch($method) + { + case 'refresh' : header("Refresh:0;url=".site_url($uri)); + break; + default : header("Location: ".site_url($uri)); + break; + } + exit; +} + +// ------------------------------------------------------------------------ + +/** + * Parse out the attributes + * + * Some of the functions use this + * + * @access private + * @param array + * @param bool + * @return string + */ +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; +} + ?> \ No newline at end of file -- cgit v1.2.3-24-g4f1b From 112569db87d01a04b98eb6c37d9c9ced03b52f3f Mon Sep 17 00:00:00 2001 From: Rick Ellis Date: Mon, 26 Feb 2007 19:19:08 +0000 Subject: --- system/libraries/Input.php | 74 +++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 73 insertions(+), 1 deletion(-) (limited to 'system') diff --git a/system/libraries/Input.php b/system/libraries/Input.php index f346cabaa..0d41b0a99 100644 --- a/system/libraries/Input.php +++ b/system/libraries/Input.php @@ -91,6 +91,16 @@ class CI_Input { { $_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) @@ -173,6 +183,41 @@ class CI_Input { return $str; } + + // -------------------------------------------------------------------- + + /** + * Fetch an item from the GET array + * + * @access public + * @param string + * @param bool + * @return string + */ + function post($index = '', $xss_clean = FALSE) + { + if ( ! isset($_GET[$index])) + { + return FALSE; + } + + if ($xss_clean === TRUE) + { + if (is_array($_GET[$index])) + { + foreach($_GET[$index] as $key => $val) + { + $_GET[$index][$key] = $this->xss_clean($val); + } + } + else + { + return $this->xss_clean($_GET[$index]); + } + } + + return $_GET[$index]; + } // -------------------------------------------------------------------- @@ -337,7 +382,34 @@ class CI_Input { */ function valid_ip($ip) { - return ( ! preg_match( "/^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$/", $ip)) ? FALSE : TRUE; + if ( ! preg_match( "/^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$/", $ip)) + { + return FALSE; + } + + $octets = explode('.', $ip); + + for ($i = 1; $i <= 4; $i++) + { + $octet = intval($octets[($i-1)]); + if ($i === 1) + { + if ($octet > 223 OR $octet < 1) + return FALSE; + } + elseif ($i === 4) + { + if ($octet < 1) + return FALSE; + } + else + { + if ($octet > 254) + return FALSE; + } + } + + return TRUE; } // -------------------------------------------------------------------- -- cgit v1.2.3-24-g4f1b From 87d1eeb9e1f5678c78e06c3a685fb3aa1a88ece3 Mon Sep 17 00:00:00 2001 From: Derek Allard Date: Thu, 1 Mar 2007 13:20:43 +0000 Subject: function post() duplicated, changed the second to function get() --- system/libraries/Input.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system') diff --git a/system/libraries/Input.php b/system/libraries/Input.php index 0d41b0a99..3a35f498a 100644 --- a/system/libraries/Input.php +++ b/system/libraries/Input.php @@ -194,7 +194,7 @@ class CI_Input { * @param bool * @return string */ - function post($index = '', $xss_clean = FALSE) + function get($index = '', $xss_clean = FALSE) { if ( ! isset($_GET[$index])) { -- cgit v1.2.3-24-g4f1b From ba0dd638336d2617066b67cf4f59667aaff8c531 Mon Sep 17 00:00:00 2001 From: Derek Allard Date: Wed, 7 Mar 2007 12:10:58 +0000 Subject: pg_version() doesn't exist. Changed reference to version() which does. --- system/database/drivers/postgre/postgre_driver.php | 968 ++++++++++----------- 1 file changed, 484 insertions(+), 484 deletions(-) (limited to 'system') diff --git a/system/database/drivers/postgre/postgre_driver.php b/system/database/drivers/postgre/postgre_driver.php index a66fddbdf..58cc69a96 100644 --- a/system/database/drivers/postgre/postgre_driver.php +++ b/system/database/drivers/postgre/postgre_driver.php @@ -1,485 +1,485 @@ -port == '') ? '' : " port=".$this->port; - - return @pg_connect("host=".$this->hostname.$port." dbname=".$this->database." user=".$this->username." password=".$this->password); - } - - // -------------------------------------------------------------------- - - /** - * Persistent database connection - * - * @access private called by the base class - * @return resource - */ - function db_pconnect() - { - $port = ($this->port == '') ? '' : " port=".$this->port; - - return @pg_pconnect("host=".$this->hostname.$port." dbname=".$this->database." user=".$this->username." password=".$this->password); - } - - // -------------------------------------------------------------------- - - /** - * 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; - } - - // -------------------------------------------------------------------- - - /** - * 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 - * @return string - */ - function escape_str($str) - { - return pg_escape_string($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 = pg_version($this->conn_id); - $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('SELECT COUNT(*) AS numrows FROM "'.$this->dbprefix.$table.'"'); - - if ($query->num_rows() == 0) - return '0'; - - $row = $query->row(); - return $row->numrows; - } - - // -------------------------------------------------------------------- - - /** - * Show table query - * - * Generates a platform-specific query string so that the table names can be fetched - * - * @access private - * @return string - */ - function _list_tables() - { - return "SELECT table_name FROM information_schema.tables WHERE table_schema = 'public'"; - } - - // -------------------------------------------------------------------- - - /** - * 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 ='".$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 * FROM ".$this->_escape_table($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 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) - { - if (stristr($table, '.')) - { - $table = '"'.preg_replace("/\./", '"."', $table).'"'; - } - - return $table; - } - - // -------------------------------------------------------------------- - - /** - * 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 - * @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); - } - - // -------------------------------------------------------------------- - - /** - * Delete statement - * - * Generates a platform-specific delete string from the supplied data - * - * @access public - * @param string the table name - * @param array the where 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) - { - $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); - } - - -} - +port == '') ? '' : " port=".$this->port; + + return @pg_connect("host=".$this->hostname.$port." dbname=".$this->database." user=".$this->username." password=".$this->password); + } + + // -------------------------------------------------------------------- + + /** + * Persistent database connection + * + * @access private called by the base class + * @return resource + */ + function db_pconnect() + { + $port = ($this->port == '') ? '' : " port=".$this->port; + + return @pg_pconnect("host=".$this->hostname.$port." dbname=".$this->database." user=".$this->username." password=".$this->password); + } + + // -------------------------------------------------------------------- + + /** + * 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; + } + + // -------------------------------------------------------------------- + + /** + * 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 + * @return string + */ + function escape_str($str) + { + return pg_escape_string($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 = version($this->conn_id); + $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('SELECT COUNT(*) AS numrows FROM "'.$this->dbprefix.$table.'"'); + + if ($query->num_rows() == 0) + return '0'; + + $row = $query->row(); + return $row->numrows; + } + + // -------------------------------------------------------------------- + + /** + * Show table query + * + * Generates a platform-specific query string so that the table names can be fetched + * + * @access private + * @return string + */ + function _list_tables() + { + return "SELECT table_name FROM information_schema.tables WHERE table_schema = 'public'"; + } + + // -------------------------------------------------------------------- + + /** + * 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 ='".$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 * FROM ".$this->_escape_table($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 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) + { + if (stristr($table, '.')) + { + $table = '"'.preg_replace("/\./", '"."', $table).'"'; + } + + return $table; + } + + // -------------------------------------------------------------------- + + /** + * 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 + * @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); + } + + // -------------------------------------------------------------------- + + /** + * Delete statement + * + * Generates a platform-specific delete string from the supplied data + * + * @access public + * @param string the table name + * @param array the where 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) + { + $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); + } + + +} + ?> \ No newline at end of file -- cgit v1.2.3-24-g4f1b From 8389487656f0f8c027b0cfe38014b7035be10888 Mon Sep 17 00:00:00 2001 From: Derek Allard Date: Tue, 13 Mar 2007 20:51:52 +0000 Subject: removed duplicate 'DATE_RFC822' --- system/helpers/date_helper.php | 1129 ++++++++++++++++++++-------------------- 1 file changed, 564 insertions(+), 565 deletions(-) (limited to 'system') diff --git a/system/helpers/date_helper.php b/system/helpers/date_helper.php index b8df03edb..504a962ce 100644 --- a/system/helpers/date_helper.php +++ b/system/helpers/date_helper.php @@ -1,566 +1,565 @@ -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(); - } -} - -// ------------------------------------------------------------------------ - -/** - * 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 - */ -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); -} - -// ------------------------------------------------------------------------ - -/** - * Standard Date - * - * Returns a date formatted according to the submitted standard. - * - * @access public - * @param string the chosen format - * @param integer Unix timestamp - * @return string - */ -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%O', - 'DATE_RFC822' => '%D, %d %M %y %H:%i:%s %O', - 'DATE_RFC850' => '%l, %d-%M-%y %H:%m:%i UTC', - 'DATE_RFC1036' => '%D, %d %M %y %H:%i:%s %O', - 'DATE_RFC1123' => '%D, %d %M %Y %H:%i:%s %O', - 'DATE_RFC2822' => '%D, %d %M %Y %H:%i:%s %O', - 'DATE_RSS' => '%D, %d %M %Y %H:%i:%s %O', - 'DATE_W3C' => '%Y-%m-%dT%H:%i:%s%Q' - ); - - if ( ! isset($formats[$fmt])) - { - return FALSE; - } - - return mdate($formats[$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 - */ -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); -} - -// ------------------------------------------------------------------------ - -/** - * 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 - */ -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]; -} - -// ------------------------------------------------------------------------ - -/** - * Converts a local Unix timestamp to GMT - * - * @access public - * @param integer Unix timestamp - * @return integer - */ -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 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 - */ -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 a MySQL Timestamp to Unix - * - * @access public - * @param integer Unix timestamp - * @return integer - */ -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) - ); -} - -// ------------------------------------------------------------------------ - -/** - * 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 - */ -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; -} - -// ------------------------------------------------------------------------ - -/** - * Convert "human" date to GMT - * - * Reverses the above process - * - * @access public - * @param string format: us or euro - * @return integer - */ -function human_to_unix($datestr = '') -{ - if ($datestr == '') - { - return FALSE; - } - - $datestr = trim($datestr); - $datestr = preg_replace("/\040+/", "\040", $datestr); - - if ( ! ereg("^[0-9]{2,4}\-[0-9]{1,2}\-[0-9]{1,2}\040[0-9]{1,2}:[0-9]{1,2}.*$", $datestr)) - { - return FALSE; - } - - $split = preg_split("/\040/", $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']) AND ereg("[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'; - - if (strlen($hour) == 1) - $hour = '0'.$hour; - } - - return mktime($hour, $min, $sec, $month, $day, $year); -} - -// ------------------------------------------------------------------------ - -/** - * Timezone Menu - * - * Generates a drop-down menu of timezones. - * - * @access public - * @param string timezone - * @param string classname - * @param string menu name - * @return string - */ -function timezone_menu($default = 'UTC', $class = "", $name = 'timezones') -{ - $CI =& get_instance(); - $CI->lang->load('date'); - - if ($default == 'GMT') - $default = 'UTC'; - - $menu = '"; - - return $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 - */ -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, - 'UM9' => -9, - 'UM8' => -8, - 'UM7' => -7, - 'UM6' => -6, - 'UM5' => -5, - 'UM4' => -4, - 'UM25' => -2.5, - 'UM3' => -3, - 'UM2' => -2, - 'UM1' => -1, - 'UTC' => 0, - 'UP1' => +1, - 'UP2' => +2, - 'UP3' => +3, - 'UP25' => +2.5, - 'UP4' => +4, - 'UP35' => +3.5, - 'UP5' => +5, - 'UP45' => +4.5, - 'UP6' => +6, - 'UP7' => +7, - 'UP8' => +8, - 'UP9' => +9, - 'UP85' => +8.5, - 'UP10' => +10, - 'UP11' => +11, - 'UP12' => +12 - ); - - if ($tz == '') - { - return $zones; - } - - if ($tz == 'GMT') - $tz = 'UTC'; - - return ( ! isset($zones[$tz])) ? 0 : $zones[$tz]; -} - - +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(); + } +} + +// ------------------------------------------------------------------------ + +/** + * 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 + */ +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); +} + +// ------------------------------------------------------------------------ + +/** + * Standard Date + * + * Returns a date formatted according to the submitted standard. + * + * @access public + * @param string the chosen format + * @param integer Unix timestamp + * @return string + */ +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%O', + 'DATE_RFC822' => '%D, %d %M %y %H:%i:%s %O', + 'DATE_RFC850' => '%l, %d-%M-%y %H:%m:%i 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); +} + + +// ------------------------------------------------------------------------ + +/** + * 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 + */ +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); +} + +// ------------------------------------------------------------------------ + +/** + * 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 + */ +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]; +} + +// ------------------------------------------------------------------------ + +/** + * Converts a local Unix timestamp to GMT + * + * @access public + * @param integer Unix timestamp + * @return integer + */ +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 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 + */ +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 a MySQL Timestamp to Unix + * + * @access public + * @param integer Unix timestamp + * @return integer + */ +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) + ); +} + +// ------------------------------------------------------------------------ + +/** + * 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 + */ +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; +} + +// ------------------------------------------------------------------------ + +/** + * Convert "human" date to GMT + * + * Reverses the above process + * + * @access public + * @param string format: us or euro + * @return integer + */ +function human_to_unix($datestr = '') +{ + if ($datestr == '') + { + return FALSE; + } + + $datestr = trim($datestr); + $datestr = preg_replace("/\040+/", "\040", $datestr); + + if ( ! ereg("^[0-9]{2,4}\-[0-9]{1,2}\-[0-9]{1,2}\040[0-9]{1,2}:[0-9]{1,2}.*$", $datestr)) + { + return FALSE; + } + + $split = preg_split("/\040/", $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']) AND ereg("[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'; + + if (strlen($hour) == 1) + $hour = '0'.$hour; + } + + return mktime($hour, $min, $sec, $month, $day, $year); +} + +// ------------------------------------------------------------------------ + +/** + * Timezone Menu + * + * Generates a drop-down menu of timezones. + * + * @access public + * @param string timezone + * @param string classname + * @param string menu name + * @return string + */ +function timezone_menu($default = 'UTC', $class = "", $name = 'timezones') +{ + $CI =& get_instance(); + $CI->lang->load('date'); + + if ($default == 'GMT') + $default = 'UTC'; + + $menu = '"; + + return $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 + */ +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, + 'UM9' => -9, + 'UM8' => -8, + 'UM7' => -7, + 'UM6' => -6, + 'UM5' => -5, + 'UM4' => -4, + 'UM25' => -2.5, + 'UM3' => -3, + 'UM2' => -2, + 'UM1' => -1, + 'UTC' => 0, + 'UP1' => +1, + 'UP2' => +2, + 'UP3' => +3, + 'UP25' => +2.5, + 'UP4' => +4, + 'UP35' => +3.5, + 'UP5' => +5, + 'UP45' => +4.5, + 'UP6' => +6, + 'UP7' => +7, + 'UP8' => +8, + 'UP9' => +9, + 'UP85' => +8.5, + 'UP10' => +10, + 'UP11' => +11, + 'UP12' => +12 + ); + + if ($tz == '') + { + return $zones; + } + + if ($tz == 'GMT') + $tz = 'UTC'; + + return ( ! isset($zones[$tz])) ? 0 : $zones[$tz]; +} + + ?> \ No newline at end of file -- cgit v1.2.3-24-g4f1b From 5c3905b4241b4ff68f768a81151f8c6e7a75fa5d Mon Sep 17 00:00:00 2001 From: Derek Allard Date: Sat, 24 Mar 2007 11:08:55 +0000 Subject: passes hostname and not database now --- system/database/drivers/odbc/odbc_driver.php | 904 +++++++++++++-------------- 1 file changed, 452 insertions(+), 452 deletions(-) (limited to 'system') diff --git a/system/database/drivers/odbc/odbc_driver.php b/system/database/drivers/odbc/odbc_driver.php index 7dd9295fc..9d540c77f 100644 --- a/system/database/drivers/odbc/odbc_driver.php +++ b/system/database/drivers/odbc/odbc_driver.php @@ -1,453 +1,453 @@ -database, $this->username, $this->password); - } - - // -------------------------------------------------------------------- - - /** - * Persistent database connection - * - * @access private called by the base class - * @return resource - */ - function db_pconnect() - { - return @odbc_pconnect($this->database, $this->username, $this->password); - } - - // -------------------------------------------------------------------- - - /** - * Select the database - * - * @access private called by the base class - * @return resource - */ - function db_select() - { - // Not needed for ODBC - 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 - * @return string - */ - function escape_str($str) - { - // ODBC doesn't require escaping - 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("SELECT COUNT(*) AS numrows FROM `".$this->dbprefix.$table."`"); - - if ($query->num_rows() == 0) - return '0'; - - $row = $query->row(); - return $row->numrows; - } - - // -------------------------------------------------------------------- - - /** - * Show table query - * - * Generates a platform-specific query string so that the table names can be fetched - * - * @access private - * @return string - */ - function _list_tables() - { - return "SHOW TABLES FROM `".$this->database."`"; - } - - // -------------------------------------------------------------------- - - /** - * 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->_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() - { - return odbc_errormsg($this->conn_id); - } - - // -------------------------------------------------------------------- - - /** - * The error message number - * - * @access private - * @return integer - */ - function _error_number() - { - return odbc_error($this->conn_id); - } - - // -------------------------------------------------------------------- - - /** - * 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) - { - if (stristr($table, '.')) - { - $table = preg_replace("/\./", "`.`", $table); - } - - return $table; - } - - // -------------------------------------------------------------------- - - /** - * 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 - * @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); - } - - // -------------------------------------------------------------------- - - /** - * Delete statement - * - * Generates a platform-specific delete string from the supplied data - * - * @access public - * @param string the table name - * @param array the where 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) - { - // 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); - } - - -} - - +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); + } + + // -------------------------------------------------------------------- + + /** + * Select the database + * + * @access private called by the base class + * @return resource + */ + function db_select() + { + // Not needed for ODBC + 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 + * @return string + */ + function escape_str($str) + { + // ODBC doesn't require escaping + 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("SELECT COUNT(*) AS numrows FROM `".$this->dbprefix.$table."`"); + + if ($query->num_rows() == 0) + return '0'; + + $row = $query->row(); + return $row->numrows; + } + + // -------------------------------------------------------------------- + + /** + * Show table query + * + * Generates a platform-specific query string so that the table names can be fetched + * + * @access private + * @return string + */ + function _list_tables() + { + return "SHOW TABLES FROM `".$this->database."`"; + } + + // -------------------------------------------------------------------- + + /** + * 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->_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() + { + return odbc_errormsg($this->conn_id); + } + + // -------------------------------------------------------------------- + + /** + * The error message number + * + * @access private + * @return integer + */ + function _error_number() + { + return odbc_error($this->conn_id); + } + + // -------------------------------------------------------------------- + + /** + * 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) + { + if (stristr($table, '.')) + { + $table = preg_replace("/\./", "`.`", $table); + } + + return $table; + } + + // -------------------------------------------------------------------- + + /** + * 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 + * @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); + } + + // -------------------------------------------------------------------- + + /** + * Delete statement + * + * Generates a platform-specific delete string from the supplied data + * + * @access public + * @param string the table name + * @param array the where 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) + { + // 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); + } + + +} + + ?> \ No newline at end of file -- cgit v1.2.3-24-g4f1b From c2f90e23b62c7155a49e38a2958796e6a886e868 Mon Sep 17 00:00:00 2001 From: Derek Allard Date: Tue, 3 Apr 2007 11:17:44 +0000 Subject: array to string addition http://codeigniter.com/forums/viewthread/46994/ --- system/libraries/Profiler.php | 414 +++++++++++++++++++++--------------------- 1 file changed, 212 insertions(+), 202 deletions(-) (limited to 'system') diff --git a/system/libraries/Profiler.php b/system/libraries/Profiler.php index 5b0f6e2b7..37b345184 100644 --- a/system/libraries/Profiler.php +++ b/system/libraries/Profiler.php @@ -1,203 +1,213 @@ -CI =& get_instance(); - $this->CI->load->language('profiler'); - } - - // -------------------------------------------------------------------- - - /** - * 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 - * - * @access private - * @return array - */ - 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 - * - * @access private - * @return string - */ - function _compile_queries() - { - $output = "\n\n"; - $output .= '
'; - $output .= "\n"; - $output .= '  '.$this->CI->lang->line('profiler_queries').'  '; - $output .= "\n"; - - if ( ! class_exists('CI_DB_driver')) - { - $output .= "
".$this->CI->lang->line('profiler_no_db')."
"; - } - else - { - if (count($this->CI->db->queries) == 0) - { - $output .= "
".$this->CI->lang->line('profiler_no_queries')."
"; - } - else - { - foreach ($this->CI->db->queries as $val) - { - $output .= '
'; - $output .= $val; - $output .= "
\n"; - } - } - } - - $output .= "
"; - - return $output; - } - - // -------------------------------------------------------------------- - - /** - * Compile $_POST Data - * - * @access private - * @return string - */ - 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."]  ".htmlspecialchars(stripslashes($val))."
\n"; - } - $output .= "
"; - - return $output; - } - - // -------------------------------------------------------------------- - - /** - * Run the Profiler - * - * @access private - * @return string - */ - function run($output = '') - { - $output = '
'; - $output .= "
"; - - $output .= $this->_compile_benchmarks(); - $output .= $this->_compile_post(); - $output .= $this->_compile_queries(); - - $output .= '
'; - - return $output; - } - -} - -// END CI_Profiler class +CI =& get_instance(); + $this->CI->load->language('profiler'); + } + + // -------------------------------------------------------------------- + + /** + * 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 + * + * @access private + * @return array + */ + 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 + * + * @access private + * @return string + */ + function _compile_queries() + { + $output = "\n\n"; + $output .= '
'; + $output .= "\n"; + $output .= '  '.$this->CI->lang->line('profiler_queries').'  '; + $output .= "\n"; + + if ( ! class_exists('CI_DB_driver')) + { + $output .= "
".$this->CI->lang->line('profiler_no_db')."
"; + } + else + { + if (count($this->CI->db->queries) == 0) + { + $output .= "
".$this->CI->lang->line('profiler_no_queries')."
"; + } + else + { + foreach ($this->CI->db->queries as $val) + { + $output .= '
'; + $output .= $val; + $output .= "
\n"; + } + } + } + + $output .= "
"; + + return $output; + } + + // -------------------------------------------------------------------- + + /** + * Compile $_POST Data + * + * @access private + * @return string + */ + 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 .= "\n"; + } + + $output .= "
$_POST[".$key."]  ".htmlspecialchars(stripslashes($val))."
$_POST[".$key."] "; + if (is_array($val)) + { + $output .= "
" . htmlspecialchars(stripslashes(print_r($val, true))) . "
"; + } + else + { + $output .= htmlspecialchars(stripslashes($val)); + } + $output .= "
\n"; + } + $output .= "
"; + + return $output; + } + + // -------------------------------------------------------------------- + + /** + * Run the Profiler + * + * @access private + * @return string + */ + function run($output = '') + { + $output = '
'; + $output .= "
"; + + $output .= $this->_compile_benchmarks(); + $output .= $this->_compile_post(); + $output .= $this->_compile_queries(); + + $output .= '
'; + + return $output; + } + +} + +// END CI_Profiler class ?> \ No newline at end of file -- cgit v1.2.3-24-g4f1b From 72b58ca3afbf507d0b6fcedcecae01cc876ddd1f Mon Sep 17 00:00:00 2001 From: Derek Allard Date: Sat, 7 Apr 2007 20:58:23 +0000 Subject: repeater won't return any results if it is set to repeat 0 times. --- system/helpers/string_helper.php | 306 +++++++++++++++++++-------------------- 1 file changed, 153 insertions(+), 153 deletions(-) (limited to 'system') diff --git a/system/helpers/string_helper.php b/system/helpers/string_helper.php index ba704df9e..c0a8854dc 100644 --- a/system/helpers/string_helper.php +++ b/system/helpers/string_helper.php @@ -1,154 +1,154 @@ - 0) ? str_repeat($data, $num) : ''); +} + + ?> \ No newline at end of file -- cgit v1.2.3-24-g4f1b From 0e254f16f26387e8f8feb0668c1d06a5fe97fa99 Mon Sep 17 00:00:00 2001 From: Derek Allard Date: Tue, 10 Apr 2007 21:53:38 +0000 Subject: typo fix --- system/libraries/Table.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system') diff --git a/system/libraries/Table.php b/system/libraries/Table.php index b8ce9491a..32223708e 100644 --- a/system/libraries/Table.php +++ b/system/libraries/Table.php @@ -286,7 +286,7 @@ class CI_Table { // -------------------------------------------------------------------- /** - * Clears the table arrays. Useful if multiple tables are beting generated + * Clears the table arrays. Useful if multiple tables are being generated * * @access public * @return void -- cgit v1.2.3-24-g4f1b From d2df9bc7cc9d4b3e53818470c5d0977c9a36677c Mon Sep 17 00:00:00 2001 From: Derek Allard Date: Sun, 15 Apr 2007 17:41:17 +0000 Subject: update pMachine to EllisLab update copyright year update Code Igniter to CodeIgniter --- system/application/config/config.php | 602 ++-- system/application/views/welcome_message.php | 122 +- system/codeigniter/Base4.php | 132 +- system/codeigniter/Base5.php | 106 +- system/codeigniter/CodeIgniter.php | 4 +- system/codeigniter/Common.php | 518 +-- system/database/DB.php | 170 +- system/database/DB_active_rec.php | 4 +- system/database/DB_cache.php | 386 +-- system/database/DB_driver.php | 2132 ++++++------ system/database/DB_result.php | 578 ++-- system/database/DB_utility.php | 908 +++--- system/database/drivers/mssql/mssql_driver.php | 914 +++--- system/database/drivers/mssql/mssql_result.php | 344 +- system/database/drivers/mssql/mssql_utility.php | 258 +- system/database/drivers/mysql/mysql_driver.php | 982 +++--- system/database/drivers/mysql/mysql_result.php | 344 +- system/database/drivers/mysql/mysql_utility.php | 486 +-- system/database/drivers/mysqli/mysqli_driver.php | 964 +++--- system/database/drivers/mysqli/mysqli_result.php | 344 +- system/database/drivers/mysqli/mysqli_utility.php | 488 +-- system/database/drivers/oci8/oci8_driver.php | 1208 +++---- system/database/drivers/oci8/oci8_result.php | 500 +-- system/database/drivers/oci8/oci8_utility.php | 256 +- system/database/drivers/odbc/odbc_driver.php | 4 +- system/database/drivers/odbc/odbc_result.php | 466 +-- system/database/drivers/odbc/odbc_utility.php | 320 +- system/database/drivers/postgre/postgre_driver.php | 4 +- system/database/drivers/postgre/postgre_result.php | 344 +- .../database/drivers/postgre/postgre_utility.php | 256 +- system/database/drivers/sqlite/sqlite_driver.php | 966 +++--- system/database/drivers/sqlite/sqlite_result.php | 350 +- system/database/drivers/sqlite/sqlite_utility.php | 306 +- system/helpers/array_helper.php | 140 +- system/helpers/cookie_helper.php | 250 +- system/helpers/date_helper.php | 6 +- system/helpers/directory_helper.php | 132 +- system/helpers/download_helper.php | 6 +- system/helpers/file_helper.php | 356 +- system/helpers/form_helper.php | 6 +- system/helpers/html_helper.php | 406 +-- system/helpers/inflector_helper.php | 278 +- system/helpers/security_helper.php | 222 +- system/helpers/smiley_helper.php | 328 +- system/helpers/string_helper.php | 6 +- system/helpers/text_helper.php | 840 ++--- system/helpers/typography_helper.php | 1078 +++--- system/helpers/url_helper.php | 6 +- system/helpers/xml_helper.php | 114 +- system/libraries/Benchmark.php | 220 +- system/libraries/Calendar.php | 948 +++--- system/libraries/Config.php | 488 +-- system/libraries/Controller.php | 228 +- system/libraries/Email.php | 3436 ++++++++++---------- system/libraries/Encrypt.php | 792 ++--- system/libraries/Exceptions.php | 4 +- system/libraries/Ftp.php | 1230 +++---- system/libraries/Hooks.php | 446 +-- system/libraries/Image_lib.php | 4 +- system/libraries/Input.php | 4 +- system/libraries/Language.php | 240 +- system/libraries/Loader.php | 4 +- system/libraries/Log.php | 234 +- system/libraries/Model.php | 162 +- system/libraries/Output.php | 726 ++--- system/libraries/Pagination.php | 420 +-- system/libraries/Parser.php | 340 +- system/libraries/Profiler.php | 6 +- system/libraries/Router.php | 4 +- system/libraries/Session.php | 974 +++--- system/libraries/Sha1.php | 496 +-- system/libraries/Table.php | 4 +- system/libraries/Trackback.php | 1094 +++---- system/libraries/URI.php | 732 ++--- system/libraries/Unit_test.php | 660 ++-- system/libraries/Upload.php | 1616 ++++----- system/libraries/User_agent.php | 4 +- system/libraries/Validation.php | 1468 ++++----- system/libraries/Xmlrpc.php | 2822 ++++++++-------- system/libraries/Xmlrpcs.php | 1004 +++--- system/libraries/Zip.php | 758 ++--- system/plugins/captcha_pi.php | 690 ++-- system/plugins/js_calendar_pi.php | 1206 +++---- system/scaffolding/Scaffolding.php | 576 ++-- system/scaffolding/views/footer.php | 18 +- 85 files changed, 21999 insertions(+), 21999 deletions(-) (limited to 'system') diff --git a/system/application/config/config.php b/system/application/config/config.php index b1598b341..3bb9d1d23 100644 --- a/system/application/config/config.php +++ b/system/application/config/config.php @@ -1,302 +1,302 @@ - \ No newline at end of file diff --git a/system/application/views/welcome_message.php b/system/application/views/welcome_message.php index 393fb56e1..8313059e4 100644 --- a/system/application/views/welcome_message.php +++ b/system/application/views/welcome_message.php @@ -1,62 +1,62 @@ - - -Welcome to Code Igniter - - - - - -

Welcome to Code Igniter!

- -

The page you are looking at is being generated dynamically by Code Igniter.

- -

If you would like to edit this page you'll find it located at:

-system/application/views/welcome_message.php - -

The corresponding controller for this page is found at:

-system/application/controllers/welcome.php - -

If you are exploring Code Igniter for the very first time, you should start by reading the User Guide.

- - -


Page rendered in {elapsed_time} seconds

- - + + +Welcome to CodeIgniter + + + + + +

Welcome to CodeIgniter!

+ +

The page you are looking at is being generated dynamically by CodeIgniter.

+ +

If you would like to edit this page you'll find it located at:

+system/application/views/welcome_message.php + +

The corresponding controller for this page is found at:

+system/application/controllers/welcome.php + +

If you are exploring CodeIgniter for the very first time, you should start by reading the User Guide.

+ + +


Page rendered in {elapsed_time} seconds

+ + \ No newline at end of file diff --git a/system/codeigniter/Base4.php b/system/codeigniter/Base4.php index b2713b660..b00da8ba2 100644 --- a/system/codeigniter/Base4.php +++ b/system/codeigniter/Base4.php @@ -1,67 +1,67 @@ -load->library('email') to instantiate - * classes that can then be used within controllers as $this->email->send() - * - * PHP 4 also has trouble referencing the CI super object within application - * constructors since objects do not exist until the class is fully - * instantiated. Basically PHP 4 sucks... - * - * Since PHP 5 doesn't suffer from this problem so we load one of - * two files based on the version of PHP being run. - * - * @package CodeIgniter - * @subpackage codeigniter - * @category front-controller - * @author Rick Ellis - * @link http://www.codeigniter.com/user_guide/ - */ - class CI_Base extends CI_Loader { - - function CI_Base() - { - // This allows syntax like $this->load->foo() to work - parent::CI_Loader(); - $this->load =& $this; - - // This allows resources used within controller constructors to work - global $OBJ; - $OBJ = $this->load; // Do NOT use a reference. - } -} - -function &get_instance() -{ - global $CI, $OBJ; - - if (is_object($CI)) - { - return $CI; - } - - return $OBJ->load; -} - +load->library('email') to instantiate + * classes that can then be used within controllers as $this->email->send() + * + * PHP 4 also has trouble referencing the CI super object within application + * constructors since objects do not exist until the class is fully + * instantiated. Basically PHP 4 sucks... + * + * Since PHP 5 doesn't suffer from this problem so we load one of + * two files based on the version of PHP being run. + * + * @package CodeIgniter + * @subpackage codeigniter + * @category front-controller + * @author Rick Ellis + * @link http://www.codeigniter.com/user_guide/ + */ + class CI_Base extends CI_Loader { + + function CI_Base() + { + // This allows syntax like $this->load->foo() to work + parent::CI_Loader(); + $this->load =& $this; + + // This allows resources used within controller constructors to work + global $OBJ; + $OBJ = $this->load; // Do NOT use a reference. + } +} + +function &get_instance() +{ + global $CI, $OBJ; + + if (is_object($CI)) + { + return $CI; + } + + return $OBJ->load; +} + ?> \ No newline at end of file diff --git a/system/codeigniter/Base5.php b/system/codeigniter/Base5.php index 0d036fae2..d1531a571 100644 --- a/system/codeigniter/Base5.php +++ b/system/codeigniter/Base5.php @@ -1,54 +1,54 @@ - \ No newline at end of file diff --git a/system/codeigniter/CodeIgniter.php b/system/codeigniter/CodeIgniter.php index 12f1a0d5e..aed05ddc2 100644 --- a/system/codeigniter/CodeIgniter.php +++ b/system/codeigniter/CodeIgniter.php @@ -1,12 +1,12 @@ show_error('An Error Was Encountered', $message); - 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. -* -* @access public -* @return void -*/ -function show_404($page = '') -{ - $error =& load_class('Exceptions'); - $error->show_404($page); - exit; -} - - -/** -* 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 -*/ -function log_message($level = 'error', $message, $php_error = FALSE) -{ - static $LOG; - - $config =& get_config(); - if ($config['log_threshold'] == 0) - { - return; - } - - $LOG =& load_class('Log'); - $LOG->write_log($level, $message, $php_error); -} - -/** -* Exception Handler -* -* This is the custom exception handler that is declaired at the top -* of Codeigniter.php. The main reason we use this is permit -* PHP errors to be logged in our own log files since we 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 -*/ -function _exception_handler($severity, $message, $filepath, $line) -{ - // We don't bother with "strict" notices since they will fill up - // the log file with information that isn't normally very - // helpful. For example, if you are running PHP 5 and you - // use version 4 style class functions (without prefixes - // like "public", "private", etc.) you'll get notices telling - // you that these have been deprecated. - - if ($severity == E_STRICT) - { - return; - } - - $error =& load_class('Exceptions'); - - // 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... - $config =& get_config(); - if ($config['log_threshold'] == 0) - { - return; - } - - $error->log_exception($severity, $message, $filepath, $line); -} - - +show_error('An Error Was Encountered', $message); + 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. +* +* @access public +* @return void +*/ +function show_404($page = '') +{ + $error =& load_class('Exceptions'); + $error->show_404($page); + exit; +} + + +/** +* 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 +*/ +function log_message($level = 'error', $message, $php_error = FALSE) +{ + static $LOG; + + $config =& get_config(); + if ($config['log_threshold'] == 0) + { + return; + } + + $LOG =& load_class('Log'); + $LOG->write_log($level, $message, $php_error); +} + +/** +* Exception Handler +* +* This is the custom exception handler that is declaired at the top +* of Codeigniter.php. The main reason we use this is permit +* PHP errors to be logged in our own log files since we 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 +*/ +function _exception_handler($severity, $message, $filepath, $line) +{ + // We don't bother with "strict" notices since they will fill up + // the log file with information that isn't normally very + // helpful. For example, if you are running PHP 5 and you + // use version 4 style class functions (without prefixes + // like "public", "private", etc.) you'll get notices telling + // you that these have been deprecated. + + if ($severity == E_STRICT) + { + return; + } + + $error =& load_class('Exceptions'); + + // 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... + $config =& get_config(); + if ($config['log_threshold'] == 0) + { + return; + } + + $error->log_exception($severity, $message, $filepath, $line); +} + + ?> \ No newline at end of file diff --git a/system/database/DB.php b/system/database/DB.php index c6bd365d9..4a119d042 100644 --- a/system/database/DB.php +++ b/system/database/DB.php @@ -1,86 +1,86 @@ - \ No newline at end of file diff --git a/system/database/DB_active_rec.php b/system/database/DB_active_rec.php index 1c72528e5..d79a068e3 100644 --- a/system/database/DB_active_rec.php +++ b/system/database/DB_active_rec.php @@ -1,12 +1,12 @@ CI - // and load the file helper since we use it a lot - $this->CI =& get_instance(); - $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->CI->db->cachedir == '') - { - return $this->CI->db->cache_off(); - } - - $path = $this->CI->db->cachedir; - } - - // Add a trailing slash to the path if needed - $path = preg_replace("/(.+?)\/*$/", "\\1/", $path); - - if ( ! is_dir($path) OR ! is_writable($path)) - { - if ($this->CI->db->db_debug) - { - return $this->CI->db->display_error('db_invalid_cache_path'); - } - - // If the path is wrong we'll turn off caching - return $this->CI->db->cache_off(); - } - - $this->CI->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->CI->db->cache_off(); - } - - $uri = ($this->CI->uri->segment(1) == FALSE) ? 'default.' : $this->CI->uri->segment(1).'+'; - $uri .= ($this->CI->uri->segment(2) == FALSE) ? 'index' : $this->CI->uri->segment(2); - - $filepath = $uri.'/'.md5($sql); - - if (FALSE === ($cachedata = read_file($this->CI->db->cachedir.$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->CI->db->cache_off(); - } - - $uri = ($this->CI->uri->segment(1) == FALSE) ? 'default.' : $this->CI->uri->segment(1).'+'; - $uri .= ($this->CI->uri->segment(2) == FALSE) ? 'index' : $this->CI->uri->segment(2); - - $dir_path = $this->CI->db->cachedir.$uri.'/'; - - $filename = md5($sql); - - if ( ! @is_dir($dir_path)) - { - if ( ! @mkdir($dir_path, 0777)) - { - return FALSE; - } - - @chmod($dir_path, 0777); - } - - if (write_file($dir_path.$filename, serialize($object)) === FALSE) - { - return FALSE; - } - - @chmod($dir_path.$filename, 0777); - 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(2); - } - - if ($segment_two == '') - { - $segment_two = ($this->CI->uri->segment(2) == FALSE) ? 'index' : $this->CI->uri->segment(2); - } - - $dir_path = $this->CI->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->CI->db->cachedir, TRUE); - } - -} - +CI + // and load the file helper since we use it a lot + $this->CI =& get_instance(); + $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->CI->db->cachedir == '') + { + return $this->CI->db->cache_off(); + } + + $path = $this->CI->db->cachedir; + } + + // Add a trailing slash to the path if needed + $path = preg_replace("/(.+?)\/*$/", "\\1/", $path); + + if ( ! is_dir($path) OR ! is_writable($path)) + { + if ($this->CI->db->db_debug) + { + return $this->CI->db->display_error('db_invalid_cache_path'); + } + + // If the path is wrong we'll turn off caching + return $this->CI->db->cache_off(); + } + + $this->CI->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->CI->db->cache_off(); + } + + $uri = ($this->CI->uri->segment(1) == FALSE) ? 'default.' : $this->CI->uri->segment(1).'+'; + $uri .= ($this->CI->uri->segment(2) == FALSE) ? 'index' : $this->CI->uri->segment(2); + + $filepath = $uri.'/'.md5($sql); + + if (FALSE === ($cachedata = read_file($this->CI->db->cachedir.$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->CI->db->cache_off(); + } + + $uri = ($this->CI->uri->segment(1) == FALSE) ? 'default.' : $this->CI->uri->segment(1).'+'; + $uri .= ($this->CI->uri->segment(2) == FALSE) ? 'index' : $this->CI->uri->segment(2); + + $dir_path = $this->CI->db->cachedir.$uri.'/'; + + $filename = md5($sql); + + if ( ! @is_dir($dir_path)) + { + if ( ! @mkdir($dir_path, 0777)) + { + return FALSE; + } + + @chmod($dir_path, 0777); + } + + if (write_file($dir_path.$filename, serialize($object)) === FALSE) + { + return FALSE; + } + + @chmod($dir_path.$filename, 0777); + 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(2); + } + + if ($segment_two == '') + { + $segment_two = ($this->CI->uri->segment(2) == FALSE) ? 'index' : $this->CI->uri->segment(2); + } + + $dir_path = $this->CI->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->CI->db->cachedir, TRUE); + } + +} + ?> \ No newline at end of file diff --git a/system/database/DB_driver.php b/system/database/DB_driver.php index 2a8510e13..7ff33246a 100644 --- a/system/database/DB_driver.php +++ b/system/database/DB_driver.php @@ -1,1067 +1,1067 @@ -initialize($params); - log_message('debug', 'Database Driver Class Initialized'); - } - - // -------------------------------------------------------------------- - - /** - * Initialize Database Settings - * - * @access private Called by the constructor - * @param mixed - * @return void - */ - function initialize($params = '') - { - if (is_array($params)) - { - $defaults = array( - 'hostname' => '', - 'username' => '', - 'password' => '', - 'database' => '', - 'conn_id' => FALSE, - 'dbdriver' => 'mysql', - 'dbprefix' => '', - 'port' => '', - 'pconnect' => FALSE, - 'db_debug' => FALSE, - 'cachedir' => '', - 'cache_on' => FALSE - ); - - foreach ($defaults as $key => $val) - { - $this->$key = ( ! isset($params[$key])) ? $val : $params[$key]; - } - } - elseif (strpos($params, '://')) - { - if (FALSE === ($dsn = @parse_url($params))) - { - log_message('error', 'Invalid DB Connection String'); - - if ($this->db_debug) - { - return $this->display_error('db_invalid_connection_str'); - } - return FALSE; - } - - $this->hostname = ( ! isset($dsn['host'])) ? '' : rawurldecode($dsn['host']); - $this->username = ( ! isset($dsn['user'])) ? '' : rawurldecode($dsn['user']); - $this->password = ( ! isset($dsn['pass'])) ? '' : rawurldecode($dsn['pass']); - $this->database = ( ! isset($dsn['path'])) ? '' : rawurldecode(substr($dsn['path'], 1)); - } - - // If an existing DB connection resource is supplied - // there is no need to connect and select the database - if (is_resource($this->conn_id)) - { - return TRUE; - } - - // Connect to the database - $this->conn_id = ($this->pconnect == FALSE) ? $this->db_connect() : $this->db_pconnect(); - - // No connection? 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 database - 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; - } - } - - 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; - } - - if ($this->dbdriver == 'oci8') - { - return $sql; - } - - $query = $this->query($sql); - $row = $query->row(); - return $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; - } - - // 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; - } - } - } - - // Compile binds if needed - if ($binds !== FALSE) - { - $sql = $this->compile_binds($sql, $binds); - } - - // Save the query for debugging - $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))) - { - // This will trigger a rollback if transactions are being used - $this->_trans_failure = TRUE; - - if ($this->db_debug) - { - log_message('error', 'Query error: '.$this->_error_message()); - return $this->display_error( - array( - 'Error Number: '.$this->_error_number(), - $this->_error_message(), - $sql - ) - ); - } - - return FALSE; - } - - // Stop and aggregate the query time results - $time_end = list($em, $es) = explode(' ', microtime()); - $this->benchmark += ($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; - } - - // 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'.EXT); - include_once(BASEPATH.'database/drivers/'.$this->dbdriver.'/'.$this->dbdriver.'_result'.EXT); - } - - 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; - } - - // -------------------------------------------------------------------- - - /** - * 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 TRUE in the event that a query failed - if ($this->_trans_failure === TRUE) - { - $this->trans_rollback(); - - if ($this->db_debug) - { - return $this->display_error('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_failure; - } - - // -------------------------------------------------------------------- - - /** - * Compile Bindings - * - * @access public - * @param string the sql statement - * @param array an array of bind data - * @return string - */ - function compile_binds($sql, $binds) - { - if (FALSE === strpos($sql, $this->bind_marker)) - { - return $sql; - } - - if ( ! is_array($binds)) - { - $binds = array($binds); - } - - foreach ($binds as $val) - { - $val = $this->escape($val); - - // Just in case the replacement string contains the bind - // character we'll temporarily replace it with a marker - $val = str_replace($this->bind_marker, '{%bind_marker%}', $val); - $sql = preg_replace("#".preg_quote($this->bind_marker, '#')."#", str_replace('$', '\$', $val), $sql, 1); - } - - return str_replace('{%bind_marker%}', $this->bind_marker, $sql); - } - - // -------------------------------------------------------------------- - - /** - * 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*"?(INSERT|UPDATE|DELETE|REPLACE|CREATE|DROP|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 integer - */ - function escape($str) - { - switch (gettype($str)) - { - case 'string' : $str = "'".$this->escape_str($str)."'"; - break; - case 'boolean' : $str = ($str === FALSE) ? 0 : 1; - break; - default : $str = ($str === NULL) ? 'NULL' : $str; - break; - } - - return $str; - } - - // -------------------------------------------------------------------- - - /** - * 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() - { - // Is there a cached result? - if (isset($this->data_cache['table_names'])) - { - return $this->data_cache['table_names']; - } - - if (FALSE === ($sql = $this->_list_tables())) - { - 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->dbprefix.$table_name, $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($this->dbprefix.$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; - } - - // -------------------------------------------------------------------- - - /** - * DEPRECATED - use list_fields() - */ - function field_names($table = '') - { - return $this->list_fields($table); - } - - // -------------------------------------------------------------------- - - /** - * 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->dbprefix.$table)); - 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[] = $key; - $values[] = $this->escape($val); - } - - return $this->_insert($this->dbprefix.$table, $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[$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->dbprefix.$table, $fields, $dest); - } - - // -------------------------------------------------------------------- - - /** - * 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; - - 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 ( ! @include(BASEPATH.'database/DB_cache'.EXT)) - { - return $this->cache_off(); - } - - $this->CACHE = new CI_DB_Cache; - return TRUE; - } - - - // -------------------------------------------------------------------- - - /** - * Close DB Connection - * - * @access public - * @return void - */ - function close() - { - if (is_resource($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 = new CI_Language(); - $LANG->load('db'); - - $heading = 'MySQL Error'; - - if ($native == TRUE) - { - $message = $error; - } - else - { - $message = ( ! is_array($error)) ? array(str_replace('%s', $swap, $LANG->line($error))) : $error; - } - - if ( ! class_exists('CI_Exceptions')) - { - include(BASEPATH.'libraries/Exceptions'.EXT); - } - - $error = new CI_Exceptions(); - echo $error->show_error('An Error Was Encountered', $message, 'error_db'); - exit; - } - -} - +initialize($params); + log_message('debug', 'Database Driver Class Initialized'); + } + + // -------------------------------------------------------------------- + + /** + * Initialize Database Settings + * + * @access private Called by the constructor + * @param mixed + * @return void + */ + function initialize($params = '') + { + if (is_array($params)) + { + $defaults = array( + 'hostname' => '', + 'username' => '', + 'password' => '', + 'database' => '', + 'conn_id' => FALSE, + 'dbdriver' => 'mysql', + 'dbprefix' => '', + 'port' => '', + 'pconnect' => FALSE, + 'db_debug' => FALSE, + 'cachedir' => '', + 'cache_on' => FALSE + ); + + foreach ($defaults as $key => $val) + { + $this->$key = ( ! isset($params[$key])) ? $val : $params[$key]; + } + } + elseif (strpos($params, '://')) + { + if (FALSE === ($dsn = @parse_url($params))) + { + log_message('error', 'Invalid DB Connection String'); + + if ($this->db_debug) + { + return $this->display_error('db_invalid_connection_str'); + } + return FALSE; + } + + $this->hostname = ( ! isset($dsn['host'])) ? '' : rawurldecode($dsn['host']); + $this->username = ( ! isset($dsn['user'])) ? '' : rawurldecode($dsn['user']); + $this->password = ( ! isset($dsn['pass'])) ? '' : rawurldecode($dsn['pass']); + $this->database = ( ! isset($dsn['path'])) ? '' : rawurldecode(substr($dsn['path'], 1)); + } + + // If an existing DB connection resource is supplied + // there is no need to connect and select the database + if (is_resource($this->conn_id)) + { + return TRUE; + } + + // Connect to the database + $this->conn_id = ($this->pconnect == FALSE) ? $this->db_connect() : $this->db_pconnect(); + + // No connection? 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 database + 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; + } + } + + 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; + } + + if ($this->dbdriver == 'oci8') + { + return $sql; + } + + $query = $this->query($sql); + $row = $query->row(); + return $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; + } + + // 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; + } + } + } + + // Compile binds if needed + if ($binds !== FALSE) + { + $sql = $this->compile_binds($sql, $binds); + } + + // Save the query for debugging + $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))) + { + // This will trigger a rollback if transactions are being used + $this->_trans_failure = TRUE; + + if ($this->db_debug) + { + log_message('error', 'Query error: '.$this->_error_message()); + return $this->display_error( + array( + 'Error Number: '.$this->_error_number(), + $this->_error_message(), + $sql + ) + ); + } + + return FALSE; + } + + // Stop and aggregate the query time results + $time_end = list($em, $es) = explode(' ', microtime()); + $this->benchmark += ($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; + } + + // 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'.EXT); + include_once(BASEPATH.'database/drivers/'.$this->dbdriver.'/'.$this->dbdriver.'_result'.EXT); + } + + 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; + } + + // -------------------------------------------------------------------- + + /** + * 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 TRUE in the event that a query failed + if ($this->_trans_failure === TRUE) + { + $this->trans_rollback(); + + if ($this->db_debug) + { + return $this->display_error('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_failure; + } + + // -------------------------------------------------------------------- + + /** + * Compile Bindings + * + * @access public + * @param string the sql statement + * @param array an array of bind data + * @return string + */ + function compile_binds($sql, $binds) + { + if (FALSE === strpos($sql, $this->bind_marker)) + { + return $sql; + } + + if ( ! is_array($binds)) + { + $binds = array($binds); + } + + foreach ($binds as $val) + { + $val = $this->escape($val); + + // Just in case the replacement string contains the bind + // character we'll temporarily replace it with a marker + $val = str_replace($this->bind_marker, '{%bind_marker%}', $val); + $sql = preg_replace("#".preg_quote($this->bind_marker, '#')."#", str_replace('$', '\$', $val), $sql, 1); + } + + return str_replace('{%bind_marker%}', $this->bind_marker, $sql); + } + + // -------------------------------------------------------------------- + + /** + * 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*"?(INSERT|UPDATE|DELETE|REPLACE|CREATE|DROP|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 integer + */ + function escape($str) + { + switch (gettype($str)) + { + case 'string' : $str = "'".$this->escape_str($str)."'"; + break; + case 'boolean' : $str = ($str === FALSE) ? 0 : 1; + break; + default : $str = ($str === NULL) ? 'NULL' : $str; + break; + } + + return $str; + } + + // -------------------------------------------------------------------- + + /** + * 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() + { + // Is there a cached result? + if (isset($this->data_cache['table_names'])) + { + return $this->data_cache['table_names']; + } + + if (FALSE === ($sql = $this->_list_tables())) + { + 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->dbprefix.$table_name, $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($this->dbprefix.$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; + } + + // -------------------------------------------------------------------- + + /** + * DEPRECATED - use list_fields() + */ + function field_names($table = '') + { + return $this->list_fields($table); + } + + // -------------------------------------------------------------------- + + /** + * 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->dbprefix.$table)); + 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[] = $key; + $values[] = $this->escape($val); + } + + return $this->_insert($this->dbprefix.$table, $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[$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->dbprefix.$table, $fields, $dest); + } + + // -------------------------------------------------------------------- + + /** + * 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; + + 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 ( ! @include(BASEPATH.'database/DB_cache'.EXT)) + { + return $this->cache_off(); + } + + $this->CACHE = new CI_DB_Cache; + return TRUE; + } + + + // -------------------------------------------------------------------- + + /** + * Close DB Connection + * + * @access public + * @return void + */ + function close() + { + if (is_resource($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 = new CI_Language(); + $LANG->load('db'); + + $heading = 'MySQL Error'; + + if ($native == TRUE) + { + $message = $error; + } + else + { + $message = ( ! is_array($error)) ? array(str_replace('%s', $swap, $LANG->line($error))) : $error; + } + + if ( ! class_exists('CI_Exceptions')) + { + include(BASEPATH.'libraries/Exceptions'.EXT); + } + + $error = new CI_Exceptions(); + echo $error->show_error('An Error Was Encountered', $message, 'error_db'); + exit; + } + +} + ?> \ No newline at end of file diff --git a/system/database/DB_result.php b/system/database/DB_result.php index 9784561d4..7d85ebb92 100644 --- a/system/database/DB_result.php +++ b/system/database/DB_result.php @@ -1,290 +1,290 @@ -result_object() : $this->result_array(); - } - - // -------------------------------------------------------------------- - - /** - * Query result. "object" version. - * - * @access public - * @return object - */ - 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 - */ - 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 can be "object" or "array" - * @return mixed either a result object or array - */ - function row($n = 0, $type = 'object') - { - return ($type == 'object') ? $this->row_object($n) : $this->row_array($n); - } - - // -------------------------------------------------------------------- - - /** - * Returns a single result row - object version - * - * @access public - * @return object - */ - 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 - */ - 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 - */ - 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 - */ - 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 - */ - 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 - */ - 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. - */ - function num_rows() { return $this->num_rows; } - function num_fields() { return 0; } - function list_fields() { return array(); } - function field_names() { return array(); } // Deprecated - function field_data() { return array(); } - function free_result() { return TRUE; } - function _data_seek() { return TRUE; } - function _fetch_assoc() { return array(); } - function _fetch_object() { return array(); } - -} -// END DB_result class +result_object() : $this->result_array(); + } + + // -------------------------------------------------------------------- + + /** + * Query result. "object" version. + * + * @access public + * @return object + */ + 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 + */ + 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 can be "object" or "array" + * @return mixed either a result object or array + */ + function row($n = 0, $type = 'object') + { + return ($type == 'object') ? $this->row_object($n) : $this->row_array($n); + } + + // -------------------------------------------------------------------- + + /** + * Returns a single result row - object version + * + * @access public + * @return object + */ + 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 + */ + 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 + */ + 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 + */ + 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 + */ + 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 + */ + 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. + */ + function num_rows() { return $this->num_rows; } + function num_fields() { return 0; } + function list_fields() { return array(); } + function field_names() { return array(); } // Deprecated + function field_data() { return array(); } + function free_result() { return TRUE; } + function _data_seek() { return TRUE; } + function _fetch_assoc() { return array(); } + function _fetch_object() { return array(); } + +} +// END DB_result class ?> \ No newline at end of file diff --git a/system/database/DB_utility.php b/system/database/DB_utility.php index 9533ec607..d48425d7e 100644 --- a/system/database/DB_utility.php +++ b/system/database/DB_utility.php @@ -1,455 +1,455 @@ -db - $CI =& get_instance(); - $this->db =& $CI->db; - - log_message('debug', "Database Utility 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); - } - - // -------------------------------------------------------------------- - - /** - * 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']; - } - - // -------------------------------------------------------------------- - - /** - * 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)) - { - return $sql; - } - - $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; - } - - // -------------------------------------------------------------------- - - /** - * Optimize 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); - } - - // -------------------------------------------------------------------- - - /** - * Drop Table - * - * @access public - * @param string the table name - * @return bool - */ - function drop_table($table_name) - { - $sql = $this->_drop_table($table_name); - - if (is_bool($sql)) - { - return $sql; - } - - return $this->db->query($sql); - } - - // -------------------------------------------------------------------- - - /** - * Generate CSV from a query result object - * - * @access public - * @param object The query result object - * @param string The delimiter - tab by default - * @param string The newline character - \n by default - * @return string - */ - function csv_from_result($query, $delim = "\t", $newline = "\n") - { - if ( ! is_object($query) OR ! method_exists($query, 'field_names')) - { - 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 .= $name.$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 .= $item.$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, 'field_names')) - { - 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(); - } - - } - - - - - - -} - +db + $CI =& get_instance(); + $this->db =& $CI->db; + + log_message('debug', "Database Utility 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); + } + + // -------------------------------------------------------------------- + + /** + * 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']; + } + + // -------------------------------------------------------------------- + + /** + * 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)) + { + return $sql; + } + + $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; + } + + // -------------------------------------------------------------------- + + /** + * Optimize 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); + } + + // -------------------------------------------------------------------- + + /** + * Drop Table + * + * @access public + * @param string the table name + * @return bool + */ + function drop_table($table_name) + { + $sql = $this->_drop_table($table_name); + + if (is_bool($sql)) + { + return $sql; + } + + return $this->db->query($sql); + } + + // -------------------------------------------------------------------- + + /** + * Generate CSV from a query result object + * + * @access public + * @param object The query result object + * @param string The delimiter - tab by default + * @param string The newline character - \n by default + * @return string + */ + function csv_from_result($query, $delim = "\t", $newline = "\n") + { + if ( ! is_object($query) OR ! method_exists($query, 'field_names')) + { + 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 .= $name.$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 .= $item.$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, 'field_names')) + { + 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(); + } + + } + + + + + + +} + ?> \ No newline at end of file diff --git a/system/database/drivers/mssql/mssql_driver.php b/system/database/drivers/mssql/mssql_driver.php index 47cfa6bbe..ef66e3f3a 100644 --- a/system/database/drivers/mssql/mssql_driver.php +++ b/system/database/drivers/mssql/mssql_driver.php @@ -1,458 +1,458 @@ -hostname, $this->username, $this->password); - } - - // -------------------------------------------------------------------- - - /** - * Persistent database connection - * - * @access private called by the base class - * @return resource - */ - function db_pconnect() - { - return @mssql_pconnect($this->hostname, $this->username, $this->password); - } - - // -------------------------------------------------------------------- - - /** - * Select the database - * - * @access private called by the base class - * @return resource - */ - function db_select() - { - return @mssql_select_db($this->database, $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 @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 - * @return string - */ - function escape_str($str) - { - // Escape single quotes - return str_replace("'", "''", $str); - } - - // -------------------------------------------------------------------- - - /** - * Affected Rows - * - * @access public - * @return integer - */ - function affected_rows() - { - return @mssql_rows_affected($this->conn_id); - } - - // -------------------------------------------------------------------- - - /** - * Insert ID - * - * @access public - * @return integer - */ - function insert_id() - { - // Not supported in MS SQL? - return 0; - } - - // -------------------------------------------------------------------- - - /** - * "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("SELECT COUNT(*) AS numrows FROM ".$this->dbprefix.$table); - - if ($query->num_rows() == 0) - return '0'; - - $row = $query->row(); - return $row->numrows; - } - - // -------------------------------------------------------------------- - - /** - * List table query - * - * Generates a platform-specific query string so that the table names can be fetched - * - * @access private - * @return string - */ - function _list_tables() - { - 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() - { - // Are errros even supported in MS SQL? - return ''; - } - - // -------------------------------------------------------------------- - - /** - * The error message number - * - * @access private - * @return integer - */ - function _error_number() - { - // Are error numbers supported? - return ''; - } - - // -------------------------------------------------------------------- - - /** - * 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) - { - // I don't believe this is necessary with MS SQL. Not sure, though. - Rick - - /* - if (stristr($table, '.')) - { - $table = preg_replace("/\./", "`.`", $table); - } - */ - - return $table; - } - - // -------------------------------------------------------------------- - - /** - * 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 - * @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); - } - - // -------------------------------------------------------------------- - - /** - * Delete statement - * - * Generates a platform-specific delete string from the supplied data - * - * @access public - * @param string the table name - * @param array the where 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) - { - @mssql_close($conn_id); - } - -} - - +hostname, $this->username, $this->password); + } + + // -------------------------------------------------------------------- + + /** + * Persistent database connection + * + * @access private called by the base class + * @return resource + */ + function db_pconnect() + { + return @mssql_pconnect($this->hostname, $this->username, $this->password); + } + + // -------------------------------------------------------------------- + + /** + * Select the database + * + * @access private called by the base class + * @return resource + */ + function db_select() + { + return @mssql_select_db($this->database, $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 @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 + * @return string + */ + function escape_str($str) + { + // Escape single quotes + return str_replace("'", "''", $str); + } + + // -------------------------------------------------------------------- + + /** + * Affected Rows + * + * @access public + * @return integer + */ + function affected_rows() + { + return @mssql_rows_affected($this->conn_id); + } + + // -------------------------------------------------------------------- + + /** + * Insert ID + * + * @access public + * @return integer + */ + function insert_id() + { + // Not supported in MS SQL? + return 0; + } + + // -------------------------------------------------------------------- + + /** + * "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("SELECT COUNT(*) AS numrows FROM ".$this->dbprefix.$table); + + if ($query->num_rows() == 0) + return '0'; + + $row = $query->row(); + return $row->numrows; + } + + // -------------------------------------------------------------------- + + /** + * List table query + * + * Generates a platform-specific query string so that the table names can be fetched + * + * @access private + * @return string + */ + function _list_tables() + { + 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() + { + // Are errros even supported in MS SQL? + return ''; + } + + // -------------------------------------------------------------------- + + /** + * The error message number + * + * @access private + * @return integer + */ + function _error_number() + { + // Are error numbers supported? + return ''; + } + + // -------------------------------------------------------------------- + + /** + * 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) + { + // I don't believe this is necessary with MS SQL. Not sure, though. - Rick + + /* + if (stristr($table, '.')) + { + $table = preg_replace("/\./", "`.`", $table); + } + */ + + return $table; + } + + // -------------------------------------------------------------------- + + /** + * 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 + * @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); + } + + // -------------------------------------------------------------------- + + /** + * Delete statement + * + * Generates a platform-specific delete string from the supplied data + * + * @access public + * @param string the table name + * @param array the where 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) + { + @mssql_close($conn_id); + } + +} + + ?> \ No newline at end of file diff --git a/system/database/drivers/mssql/mssql_result.php b/system/database/drivers/mssql/mssql_result.php index eb7afef70..eb471e4be 100644 --- a/system/database/drivers/mssql/mssql_result.php +++ b/system/database/drivers/mssql/mssql_result.php @@ -1,173 +1,173 @@ -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; - } - - // Deprecated - function field_names() - { - return $this->list_fields(); - } - - // -------------------------------------------------------------------- - - /** - * 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); - } - -} - +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; + } + + // Deprecated + function field_names() + { + return $this->list_fields(); + } + + // -------------------------------------------------------------------- + + /** + * 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); + } + +} + ?> \ No newline at end of file diff --git a/system/database/drivers/mssql/mssql_utility.php b/system/database/drivers/mssql/mssql_utility.php index b24646123..7f4e73084 100644 --- a/system/database/drivers/mssql/mssql_utility.php +++ b/system/database/drivers/mssql/mssql_utility.php @@ -1,130 +1,130 @@ -db->_escape_table($table); - } - - // -------------------------------------------------------------------- - - /** - * List databases - * - * @access private - * @return bool - */ - function _list_databases() - { - return "EXEC sp_helpdb"; // Can also be: EXEC sp_databases - } - - // -------------------------------------------------------------------- - - /** - * 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 MS SQL? - } - - // -------------------------------------------------------------------- - - /** - * 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 MS SQL? - } - - // -------------------------------------------------------------------- - - /** - * MSSQL Export - * - * @access private - * @param array Preferences - * @return mixed - */ - function _backup($params = array()) - { - // Currently unsupported - return $this->db->display_error('db_unsuported_feature'); - } - - -} - +db->_escape_table($table); + } + + // -------------------------------------------------------------------- + + /** + * List databases + * + * @access private + * @return bool + */ + function _list_databases() + { + return "EXEC sp_helpdb"; // Can also be: EXEC sp_databases + } + + // -------------------------------------------------------------------- + + /** + * 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 MS SQL? + } + + // -------------------------------------------------------------------- + + /** + * 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 MS SQL? + } + + // -------------------------------------------------------------------- + + /** + * MSSQL Export + * + * @access private + * @param array Preferences + * @return mixed + */ + function _backup($params = array()) + { + // Currently unsupported + return $this->db->display_error('db_unsuported_feature'); + } + + +} + ?> \ No newline at end of file diff --git a/system/database/drivers/mysql/mysql_driver.php b/system/database/drivers/mysql/mysql_driver.php index 2104b9abd..367c2d11f 100644 --- a/system/database/drivers/mysql/mysql_driver.php +++ b/system/database/drivers/mysql/mysql_driver.php @@ -1,492 +1,492 @@ -hostname, $this->username, $this->password, TRUE); - } - - // -------------------------------------------------------------------- - - /** - * Persistent database connection - * - * @access private called by the base class - * @return resource - */ - function db_pconnect() - { - return @mysql_pconnect($this->hostname, $this->username, $this->password); - } - - // -------------------------------------------------------------------- - - /** - * Select the database - * - * @access private called by the base class - * @return resource - */ - function db_select() - { - return @mysql_select_db($this->database, $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 - * @return string - */ - function escape_str($str) - { - if (get_magic_quotes_gpc()) - { - return $str; - } - - if (function_exists('mysql_real_escape_string')) - { - return mysql_real_escape_string($str, $this->conn_id); - } - elseif (function_exists('mysql_escape_string')) - { - return mysql_escape_string($str); - } - else - { - return addslashes($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("SELECT COUNT(*) AS numrows FROM `".$this->dbprefix.$table."`"); - - if ($query->num_rows() == 0) - return '0'; - - $row = $query->row(); - return $row->numrows; - } - - // -------------------------------------------------------------------- - - /** - * List table query - * - * Generates a platform-specific query string so that the table names can be fetched - * - * @access private - * @return string - */ - function _list_tables() - { - return "SHOW TABLES FROM `".$this->database."`"; - } - - // -------------------------------------------------------------------- - - /** - * 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->_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 * FROM ".$this->_escape_table($table)." LIMIT 1"; - } - - // -------------------------------------------------------------------- - - /** - * 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 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) - { - if (stristr($table, '.')) - { - $table = preg_replace("/\./", "`.`", $table); - } - - return $table; - } - - // -------------------------------------------------------------------- - - /** - * 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 - * @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); - } - - // -------------------------------------------------------------------- - - /** - * Delete statement - * - * Generates a platform-specific delete string from the supplied data - * - * @access public - * @param string the table name - * @param array the where 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) - { - 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); - } - -} - +hostname, $this->username, $this->password, TRUE); + } + + // -------------------------------------------------------------------- + + /** + * Persistent database connection + * + * @access private called by the base class + * @return resource + */ + function db_pconnect() + { + return @mysql_pconnect($this->hostname, $this->username, $this->password); + } + + // -------------------------------------------------------------------- + + /** + * Select the database + * + * @access private called by the base class + * @return resource + */ + function db_select() + { + return @mysql_select_db($this->database, $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 + * @return string + */ + function escape_str($str) + { + if (get_magic_quotes_gpc()) + { + return $str; + } + + if (function_exists('mysql_real_escape_string')) + { + return mysql_real_escape_string($str, $this->conn_id); + } + elseif (function_exists('mysql_escape_string')) + { + return mysql_escape_string($str); + } + else + { + return addslashes($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("SELECT COUNT(*) AS numrows FROM `".$this->dbprefix.$table."`"); + + if ($query->num_rows() == 0) + return '0'; + + $row = $query->row(); + return $row->numrows; + } + + // -------------------------------------------------------------------- + + /** + * List table query + * + * Generates a platform-specific query string so that the table names can be fetched + * + * @access private + * @return string + */ + function _list_tables() + { + return "SHOW TABLES FROM `".$this->database."`"; + } + + // -------------------------------------------------------------------- + + /** + * 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->_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 * FROM ".$this->_escape_table($table)." LIMIT 1"; + } + + // -------------------------------------------------------------------- + + /** + * 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 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) + { + if (stristr($table, '.')) + { + $table = preg_replace("/\./", "`.`", $table); + } + + return $table; + } + + // -------------------------------------------------------------------- + + /** + * 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 + * @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); + } + + // -------------------------------------------------------------------- + + /** + * Delete statement + * + * Generates a platform-specific delete string from the supplied data + * + * @access public + * @param string the table name + * @param array the where 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) + { + 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); + } + +} + ?> \ No newline at end of file diff --git a/system/database/drivers/mysql/mysql_result.php b/system/database/drivers/mysql/mysql_result.php index 9b28dead7..7dcd5cb0e 100644 --- a/system/database/drivers/mysql/mysql_result.php +++ b/system/database/drivers/mysql/mysql_result.php @@ -1,173 +1,173 @@ -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; - } - - // Deprecated - function field_names() - { - return $this->list_fields(); - } - - // -------------------------------------------------------------------- - - /** - * Field data - * - * Generates an array of objects containing field meta-data - * - * @access public - * @return array - */ - function field_data() - { - $retval = array(); - while ($field = mysql_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; - $F->primary_key = $field->primary_key; - - $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); - } - -} - +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; + } + + // Deprecated + function field_names() + { + return $this->list_fields(); + } + + // -------------------------------------------------------------------- + + /** + * Field data + * + * Generates an array of objects containing field meta-data + * + * @access public + * @return array + */ + function field_data() + { + $retval = array(); + while ($field = mysql_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; + $F->primary_key = $field->primary_key; + + $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); + } + +} + ?> \ No newline at end of file diff --git a/system/database/drivers/mysql/mysql_utility.php b/system/database/drivers/mysql/mysql_utility.php index 32007d224..b357f47df 100644 --- a/system/database/drivers/mysql/mysql_utility.php +++ b/system/database/drivers/mysql/mysql_utility.php @@ -1,244 +1,244 @@ -db->_escape_table($table); - } - - // -------------------------------------------------------------------- - - /** - * 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 "OPTIMIZE TABLE ".$this->db->_escape_table($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_table($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)) - { - $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) - { - // Do a little formatting... - $v = str_replace(array("\x00", "\x0a", "\x0d", "\x1a"), array('\0', '\n', '\r', '\Z'), $v); - $v = str_replace(array("\n", "\r", "\t"), array('\n', '\r', '\t'), $v); - $v = str_replace('\\', '\\\\', $v); - $v = str_replace('\'', '\\\'', $v); - $v = str_replace('\\\n', '\n', $v); - $v = str_replace('\\\r', '\r', $v); - $v = str_replace('\\\t', '\t', $v); - - // Escape the data if it's not an integer type - $val_str .= ($is_int[$i] == FALSE) ? $this->db->escape($v) : $v; - $val_str .= ', '; - - $i++; - } - - $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; - } - - -} - +db->_escape_table($table); + } + + // -------------------------------------------------------------------- + + /** + * 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 "OPTIMIZE TABLE ".$this->db->_escape_table($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_table($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)) + { + $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) + { + // Do a little formatting... + $v = str_replace(array("\x00", "\x0a", "\x0d", "\x1a"), array('\0', '\n', '\r', '\Z'), $v); + $v = str_replace(array("\n", "\r", "\t"), array('\n', '\r', '\t'), $v); + $v = str_replace('\\', '\\\\', $v); + $v = str_replace('\'', '\\\'', $v); + $v = str_replace('\\\n', '\n', $v); + $v = str_replace('\\\r', '\r', $v); + $v = str_replace('\\\t', '\t', $v); + + // Escape the data if it's not an integer type + $val_str .= ($is_int[$i] == FALSE) ? $this->db->escape($v) : $v; + $val_str .= ', '; + + $i++; + } + + $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; + } + + +} + ?> \ No newline at end of file diff --git a/system/database/drivers/mysqli/mysqli_driver.php b/system/database/drivers/mysqli/mysqli_driver.php index f8d3acf20..98e7f6c76 100644 --- a/system/database/drivers/mysqli/mysqli_driver.php +++ b/system/database/drivers/mysqli/mysqli_driver.php @@ -1,483 +1,483 @@ -hostname, $this->username, $this->password); - } - - // -------------------------------------------------------------------- - - /** - * Persistent database connection - * - * @access private called by the base class - * @return resource - */ - function db_pconnect() - { - return $this->db_connect(); - } - - // -------------------------------------------------------------------- - - /** - * Select the database - * - * @access private called by the base class - * @return resource - */ - function db_select() - { - return @mysqli_select_db($this->conn_id, $this->database); - } - - // -------------------------------------------------------------------- - - /** - * 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 - * @return string - */ - function escape_str($str) - { - if (get_magic_quotes_gpc()) - { - return $str; - } - - return mysqli_real_escape_string($this->conn_id, $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("SELECT COUNT(*) AS numrows FROM `".$this->dbprefix.$table."`"); - - if ($query->num_rows() == 0) - return '0'; - - $row = $query->row(); - return $row->numrows; - } - - // -------------------------------------------------------------------- - - /** - * List table query - * - * Generates a platform-specific query string so that the table names can be fetched - * - * @access private - * @return string - */ - function _list_tables() - { - return "SHOW TABLES FROM `".$this->database."`"; - } - - // -------------------------------------------------------------------- - - /** - * 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->_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 * FROM ".$this->_escape_table($table)." LIMIT 1"; - } - - // -------------------------------------------------------------------- - - /** - * 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 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) - { - if (stristr($table, '.')) - { - $table = preg_replace("/\./", "`.`", $table); - } - - return $table; - } - - // -------------------------------------------------------------------- - - /** - * 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 - * @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); - } - - // -------------------------------------------------------------------- - - /** - * Delete statement - * - * Generates a platform-specific delete string from the supplied data - * - * @access public - * @param string the table name - * @param array the where 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) - { - $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); - } - - -} - +hostname, $this->username, $this->password); + } + + // -------------------------------------------------------------------- + + /** + * Persistent database connection + * + * @access private called by the base class + * @return resource + */ + function db_pconnect() + { + return $this->db_connect(); + } + + // -------------------------------------------------------------------- + + /** + * Select the database + * + * @access private called by the base class + * @return resource + */ + function db_select() + { + return @mysqli_select_db($this->conn_id, $this->database); + } + + // -------------------------------------------------------------------- + + /** + * 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 + * @return string + */ + function escape_str($str) + { + if (get_magic_quotes_gpc()) + { + return $str; + } + + return mysqli_real_escape_string($this->conn_id, $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("SELECT COUNT(*) AS numrows FROM `".$this->dbprefix.$table."`"); + + if ($query->num_rows() == 0) + return '0'; + + $row = $query->row(); + return $row->numrows; + } + + // -------------------------------------------------------------------- + + /** + * List table query + * + * Generates a platform-specific query string so that the table names can be fetched + * + * @access private + * @return string + */ + function _list_tables() + { + return "SHOW TABLES FROM `".$this->database."`"; + } + + // -------------------------------------------------------------------- + + /** + * 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->_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 * FROM ".$this->_escape_table($table)." LIMIT 1"; + } + + // -------------------------------------------------------------------- + + /** + * 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 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) + { + if (stristr($table, '.')) + { + $table = preg_replace("/\./", "`.`", $table); + } + + return $table; + } + + // -------------------------------------------------------------------- + + /** + * 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 + * @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); + } + + // -------------------------------------------------------------------- + + /** + * Delete statement + * + * Generates a platform-specific delete string from the supplied data + * + * @access public + * @param string the table name + * @param array the where 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) + { + $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); + } + + +} + ?> \ No newline at end of file diff --git a/system/database/drivers/mysqli/mysqli_result.php b/system/database/drivers/mysqli/mysqli_result.php index 57c89ea80..0f2eb5345 100644 --- a/system/database/drivers/mysqli/mysqli_result.php +++ b/system/database/drivers/mysqli/mysqli_result.php @@ -1,173 +1,173 @@ -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; - } - - // Deprecated - function field_names() - { - return $this->list_fields(); - } - - // -------------------------------------------------------------------- - - /** - * Field data - * - * Generates an array of objects containing field meta-data - * - * @access public - * @return array - */ - function field_data() - { - $retval = array(); - while ($field = mysqli_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; - $F->primary_key = ($field->flags & MYSQLI_PRI_KEY_FLAG) ? 1 : 0; - - $retval[] = $F; - } - - return $retval; - } - - // -------------------------------------------------------------------- - - /** - * Free the result - * - * @return null - */ - function free_result() - { - if (is_resource($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); - } - -} - +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; + } + + // Deprecated + function field_names() + { + return $this->list_fields(); + } + + // -------------------------------------------------------------------- + + /** + * Field data + * + * Generates an array of objects containing field meta-data + * + * @access public + * @return array + */ + function field_data() + { + $retval = array(); + while ($field = mysqli_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; + $F->primary_key = ($field->flags & MYSQLI_PRI_KEY_FLAG) ? 1 : 0; + + $retval[] = $F; + } + + return $retval; + } + + // -------------------------------------------------------------------- + + /** + * Free the result + * + * @return null + */ + function free_result() + { + if (is_resource($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); + } + +} + ?> \ No newline at end of file diff --git a/system/database/drivers/mysqli/mysqli_utility.php b/system/database/drivers/mysqli/mysqli_utility.php index d5dbf2fb0..3e2b8da6e 100644 --- a/system/database/drivers/mysqli/mysqli_utility.php +++ b/system/database/drivers/mysqli/mysqli_utility.php @@ -1,245 +1,245 @@ -db->_escape_table($table); - } - - // -------------------------------------------------------------------- - - /** - * List databases - * - * @access private - * @return bool - */ - function _list_databases() - { - return "SHOW DATABASES"; - } - - // -------------------------------------------------------------------- - - /** - * 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 "OPTIMIZE TABLE ".$this->db->_escape_table($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_table($table); - } - - // -------------------------------------------------------------------- - - /** - * MySQLi 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 = mysqli_fetch_field($query->result_id)) - { - $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) - { - // Do a little formatting... - $v = str_replace(array("\x00", "\x0a", "\x0d", "\x1a"), array('\0', '\n', '\r', '\Z'), $v); - $v = str_replace(array("\n", "\r", "\t"), array('\n', '\r', '\t'), $v); - $v = str_replace('\\', '\\\\', $v); - $v = str_replace('\'', '\\\'', $v); - $v = str_replace('\\\n', '\n', $v); - $v = str_replace('\\\r', '\r', $v); - $v = str_replace('\\\t', '\t', $v); - - // Escape the data if it's not an integer type - $val_str .= ($is_int[$i] == FALSE) ? $this->db->escape($v) : $v; - $val_str .= ', '; - - $i++; - } - - $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; - } - - - -} - +db->_escape_table($table); + } + + // -------------------------------------------------------------------- + + /** + * List databases + * + * @access private + * @return bool + */ + function _list_databases() + { + return "SHOW DATABASES"; + } + + // -------------------------------------------------------------------- + + /** + * 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 "OPTIMIZE TABLE ".$this->db->_escape_table($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_table($table); + } + + // -------------------------------------------------------------------- + + /** + * MySQLi 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 = mysqli_fetch_field($query->result_id)) + { + $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) + { + // Do a little formatting... + $v = str_replace(array("\x00", "\x0a", "\x0d", "\x1a"), array('\0', '\n', '\r', '\Z'), $v); + $v = str_replace(array("\n", "\r", "\t"), array('\n', '\r', '\t'), $v); + $v = str_replace('\\', '\\\\', $v); + $v = str_replace('\'', '\\\'', $v); + $v = str_replace('\\\n', '\n', $v); + $v = str_replace('\\\r', '\r', $v); + $v = str_replace('\\\t', '\t', $v); + + // Escape the data if it's not an integer type + $val_str .= ($is_int[$i] == FALSE) ? $this->db->escape($v) : $v; + $val_str .= ', '; + + $i++; + } + + $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; + } + + + +} + ?> \ No newline at end of file diff --git a/system/database/drivers/oci8/oci8_driver.php b/system/database/drivers/oci8/oci8_driver.php index ff301a57d..291e168eb 100644 --- a/system/database/drivers/oci8/oci8_driver.php +++ b/system/database/drivers/oci8/oci8_driver.php @@ -1,605 +1,605 @@ -username, $this->password, $this->hostname); - } - - // -------------------------------------------------------------------- - - /** - * Persistent database connection - * - * @access private called by the base class - * @return resource - */ - function db_pconnect() - { - return @ociplogon($this->username, $this->password, $this->hostname); - } - - // -------------------------------------------------------------------- - - /** - * Select the database - * - * @access private called by the base class - * @return resource - */ - function db_select() - { - return TRUE; - } - - // -------------------------------------------------------------------- - - /** - * Version number query string - * - * @access public - * @return string - */ - function _version() - { - return ociserverversion($this->conn_id); - } - - // -------------------------------------------------------------------- - - /** - * Execute the query - * - * @access private called by the base class - * @param string an SQL query - * @return resource - */ - 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->_set_stmt_id($sql); - ocisetprefetch($this->stmt_id, 1000); - return @ociexecute($this->stmt_id, $this->_commit); - } - - /** - * Generate a statement ID - * - * @access private - * @param string an SQL query - * @return none - */ - function _set_stmt_id($sql) - { - if ( ! is_resource($this->stmt_id)) - { - $this->stmt_id = ociparse($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 - */ - function _prep_query($sql) - { - return $sql; - } - - // -------------------------------------------------------------------- - - /** - * getCursor. Returns a cursor from the datbase - * - * @access public - * @return cursor id - */ - function get_cursor() - { - $this->curs_id = ocinewcursor($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 - */ - 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 - */ - 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] = ''; - } - } - - ocibindbyname($this->stmt_id, $param['name'], $param['value'], $param['length'], $param['type']); - } - } - - // -------------------------------------------------------------------- - - /** - * 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->_commit = OCI_DEFAULT; - 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; - } - - $ret = OCIcommit($this->conn_id); - $this->_commit = OCI_COMMIT_ON_SUCCESS; - 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 = OCIrollback($this->conn_id); - $this->_commit = OCI_COMMIT_ON_SUCCESS; - return $ret; - } - - // -------------------------------------------------------------------- - - /** - * Escape String - * - * @access public - * @param string - * @return string - */ - function escape_str($str) - { - return $str; - } - - // -------------------------------------------------------------------- - - /** - * Affected Rows - * - * @access public - * @return integer - */ - function affected_rows() - { - return @ocirowcount($this->stmt_id); - } - - // -------------------------------------------------------------------- - - /** - * Insert ID - * - * @access public - * @return integer - */ - function insert_id() - { - // not supported in oracle - return 0; - } - - // -------------------------------------------------------------------- - - /** - * "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("SELECT COUNT(1) AS numrows FROM ".$table); - - if ($query == FALSE) - { - return 0; - } - - $row = $query->row(); - return $row->NUMROWS; - } - - // -------------------------------------------------------------------- - - /** - * Show table query - * - * Generates a platform-specific query string so that the table names can be fetched - * - * @access private - * @return string - */ - function _list_tables() - { - return "SELECT TABLE_NAME FROM ALL_TABLES"; - } - - // -------------------------------------------------------------------- - - /** - * 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 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 - */ - function _field_data($table) - { - return "SELECT * FROM ".$this->_escape_table($table)." where rownum = 1"; - } - - // -------------------------------------------------------------------- - - /** - * The error message string - * - * @access private - * @return string - */ - function _error_message() - { - $error = ocierror($this->conn_id); - return $error['message']; - } - - // -------------------------------------------------------------------- - - /** - * The error message number - * - * @access private - * @return integer - */ - function _error_number() - { - $error = ocierror($this->conn_id); - return $error['code']; - } - - // -------------------------------------------------------------------- - - /** - * 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) - { - if (stristr($table, '.')) - { - $table = preg_replace("/\./", "`.`", $table); - } - - return $table; - } - - // -------------------------------------------------------------------- - - /** - * 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 - * @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); - } - - // -------------------------------------------------------------------- - - /** - * Delete statement - * - * Generates a platform-specific delete string from the supplied data - * - * @access public - * @param string the table name - * @param array the where 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) - { - $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 public - * @param resource - * @return void - */ - function _close($conn_id) - { - @ocilogoff($conn_id); - } - - -} - - +username, $this->password, $this->hostname); + } + + // -------------------------------------------------------------------- + + /** + * Persistent database connection + * + * @access private called by the base class + * @return resource + */ + function db_pconnect() + { + return @ociplogon($this->username, $this->password, $this->hostname); + } + + // -------------------------------------------------------------------- + + /** + * Select the database + * + * @access private called by the base class + * @return resource + */ + function db_select() + { + return TRUE; + } + + // -------------------------------------------------------------------- + + /** + * Version number query string + * + * @access public + * @return string + */ + function _version() + { + return ociserverversion($this->conn_id); + } + + // -------------------------------------------------------------------- + + /** + * Execute the query + * + * @access private called by the base class + * @param string an SQL query + * @return resource + */ + 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->_set_stmt_id($sql); + ocisetprefetch($this->stmt_id, 1000); + return @ociexecute($this->stmt_id, $this->_commit); + } + + /** + * Generate a statement ID + * + * @access private + * @param string an SQL query + * @return none + */ + function _set_stmt_id($sql) + { + if ( ! is_resource($this->stmt_id)) + { + $this->stmt_id = ociparse($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 + */ + function _prep_query($sql) + { + return $sql; + } + + // -------------------------------------------------------------------- + + /** + * getCursor. Returns a cursor from the datbase + * + * @access public + * @return cursor id + */ + function get_cursor() + { + $this->curs_id = ocinewcursor($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 + */ + 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 + */ + 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] = ''; + } + } + + ocibindbyname($this->stmt_id, $param['name'], $param['value'], $param['length'], $param['type']); + } + } + + // -------------------------------------------------------------------- + + /** + * 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->_commit = OCI_DEFAULT; + 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; + } + + $ret = OCIcommit($this->conn_id); + $this->_commit = OCI_COMMIT_ON_SUCCESS; + 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 = OCIrollback($this->conn_id); + $this->_commit = OCI_COMMIT_ON_SUCCESS; + return $ret; + } + + // -------------------------------------------------------------------- + + /** + * Escape String + * + * @access public + * @param string + * @return string + */ + function escape_str($str) + { + return $str; + } + + // -------------------------------------------------------------------- + + /** + * Affected Rows + * + * @access public + * @return integer + */ + function affected_rows() + { + return @ocirowcount($this->stmt_id); + } + + // -------------------------------------------------------------------- + + /** + * Insert ID + * + * @access public + * @return integer + */ + function insert_id() + { + // not supported in oracle + return 0; + } + + // -------------------------------------------------------------------- + + /** + * "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("SELECT COUNT(1) AS numrows FROM ".$table); + + if ($query == FALSE) + { + return 0; + } + + $row = $query->row(); + return $row->NUMROWS; + } + + // -------------------------------------------------------------------- + + /** + * Show table query + * + * Generates a platform-specific query string so that the table names can be fetched + * + * @access private + * @return string + */ + function _list_tables() + { + return "SELECT TABLE_NAME FROM ALL_TABLES"; + } + + // -------------------------------------------------------------------- + + /** + * 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 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 + */ + function _field_data($table) + { + return "SELECT * FROM ".$this->_escape_table($table)." where rownum = 1"; + } + + // -------------------------------------------------------------------- + + /** + * The error message string + * + * @access private + * @return string + */ + function _error_message() + { + $error = ocierror($this->conn_id); + return $error['message']; + } + + // -------------------------------------------------------------------- + + /** + * The error message number + * + * @access private + * @return integer + */ + function _error_number() + { + $error = ocierror($this->conn_id); + return $error['code']; + } + + // -------------------------------------------------------------------- + + /** + * 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) + { + if (stristr($table, '.')) + { + $table = preg_replace("/\./", "`.`", $table); + } + + return $table; + } + + // -------------------------------------------------------------------- + + /** + * 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 + * @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); + } + + // -------------------------------------------------------------------- + + /** + * Delete statement + * + * Generates a platform-specific delete string from the supplied data + * + * @access public + * @param string the table name + * @param array the where 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) + { + $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 public + * @param resource + * @return void + */ + function _close($conn_id) + { + @ocilogoff($conn_id); + } + + +} + + ?> \ No newline at end of file diff --git a/system/database/drivers/oci8/oci8_result.php b/system/database/drivers/oci8/oci8_result.php index fb4ed1f0d..07f154489 100644 --- a/system/database/drivers/oci8/oci8_result.php +++ b/system/database/drivers/oci8/oci8_result.php @@ -1,251 +1,251 @@ -result_array()); - @ociexecute($this->stmt_id); - if ($this->curs_id) - { - @ociexecute($this->curs_id); - } - return $rowcount; - } - - // -------------------------------------------------------------------- - - /** - * Number of fields in the result set - * - * @access public - * @return integer - */ - function num_fields() - { - $count = @ocinumcols($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 - */ - function list_fields() - { - $field_names = array(); - $fieldCount = $this->num_fields(); - for ($c = 1; $c <= $fieldCount; $c++) - { - $field_names[] = ocicolumnname($this->stmt_id, $c); - } - return $field_names; - } - - // Deprecated - function field_names() - { - return $this->list_fields(); - } - - // -------------------------------------------------------------------- - - /** - * Field data - * - * Generates an array of objects containing field meta-data - * - * @access public - * @return array - */ - function field_data() - { - $retval = array(); - $fieldCount = $this->num_fields(); - for ($c = 1; $c <= $fieldCount; $c++) - { - $F = new stdClass(); - $F->name = ocicolumnname($this->stmt_id, $c); - $F->type = ocicolumntype($this->stmt_id, $c); - $F->max_length = ocicolumnsize($this->stmt_id, $c); - - $retval[] = $F; - } - - return $retval; - } - - // -------------------------------------------------------------------- - - /** - * Free the result - * - * @return null - */ - function free_result() - { - if (is_resource($this->result_id)) - { - ocifreestatement($this->result_id); - $this->result_id = FALSE; - } - } - - // -------------------------------------------------------------------- - - /** - * Result - associative array - * - * Returns the result set as an array - * - * @access private - * @return array - */ - function _fetch_assoc(&$row) - { - $id = ($this->curs_id) ? $this->curs_id : $this->stmt_id; - - return ocifetchinto($id, $row, OCI_ASSOC + OCI_RETURN_NULLS); - } - - // -------------------------------------------------------------------- - - /** - * Result - object - * - * Returns the result set as an object - * - * @access private - * @return object - */ - function _fetch_object() - { - $result = array(); - - // If PHP 5 is being used we can fetch an result object - if (function_exists('oci_fetch_object')) - { - $id = ($this->curs_id) ? $this->curs_id : $this->stmt_id; - - return @oci_fetch_object($id); - } - - // If PHP 4 is being used we have to build our own result - foreach ($this->result_array() as $key => $val) - { - $obj = new stdClass(); - if (is_array($val)) - { - foreach ($val as $k => $v) - { - $obj->$k = $v; - } - } - else - { - $obj->$key = $val; - } - - $result[] = $obj; - } - - return $result; - } - - // -------------------------------------------------------------------- - - /** - * Query result. "array" version. - * - * @access public - * @return array - */ - function result_array() - { - if (count($this->result_array) > 0) - { - return $this->result_array; - } - - // oracle's fetch functions do not return arrays. - // The information is returned in reference parameters - $row = NULL; - while ($this->_fetch_assoc($row)) - { - $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 private - * @return array - */ - function _data_seek($n = 0) - { - return FALSE; // Not needed - } - -} - +result_array()); + @ociexecute($this->stmt_id); + if ($this->curs_id) + { + @ociexecute($this->curs_id); + } + return $rowcount; + } + + // -------------------------------------------------------------------- + + /** + * Number of fields in the result set + * + * @access public + * @return integer + */ + function num_fields() + { + $count = @ocinumcols($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 + */ + function list_fields() + { + $field_names = array(); + $fieldCount = $this->num_fields(); + for ($c = 1; $c <= $fieldCount; $c++) + { + $field_names[] = ocicolumnname($this->stmt_id, $c); + } + return $field_names; + } + + // Deprecated + function field_names() + { + return $this->list_fields(); + } + + // -------------------------------------------------------------------- + + /** + * Field data + * + * Generates an array of objects containing field meta-data + * + * @access public + * @return array + */ + function field_data() + { + $retval = array(); + $fieldCount = $this->num_fields(); + for ($c = 1; $c <= $fieldCount; $c++) + { + $F = new stdClass(); + $F->name = ocicolumnname($this->stmt_id, $c); + $F->type = ocicolumntype($this->stmt_id, $c); + $F->max_length = ocicolumnsize($this->stmt_id, $c); + + $retval[] = $F; + } + + return $retval; + } + + // -------------------------------------------------------------------- + + /** + * Free the result + * + * @return null + */ + function free_result() + { + if (is_resource($this->result_id)) + { + ocifreestatement($this->result_id); + $this->result_id = FALSE; + } + } + + // -------------------------------------------------------------------- + + /** + * Result - associative array + * + * Returns the result set as an array + * + * @access private + * @return array + */ + function _fetch_assoc(&$row) + { + $id = ($this->curs_id) ? $this->curs_id : $this->stmt_id; + + return ocifetchinto($id, $row, OCI_ASSOC + OCI_RETURN_NULLS); + } + + // -------------------------------------------------------------------- + + /** + * Result - object + * + * Returns the result set as an object + * + * @access private + * @return object + */ + function _fetch_object() + { + $result = array(); + + // If PHP 5 is being used we can fetch an result object + if (function_exists('oci_fetch_object')) + { + $id = ($this->curs_id) ? $this->curs_id : $this->stmt_id; + + return @oci_fetch_object($id); + } + + // If PHP 4 is being used we have to build our own result + foreach ($this->result_array() as $key => $val) + { + $obj = new stdClass(); + if (is_array($val)) + { + foreach ($val as $k => $v) + { + $obj->$k = $v; + } + } + else + { + $obj->$key = $val; + } + + $result[] = $obj; + } + + return $result; + } + + // -------------------------------------------------------------------- + + /** + * Query result. "array" version. + * + * @access public + * @return array + */ + function result_array() + { + if (count($this->result_array) > 0) + { + return $this->result_array; + } + + // oracle's fetch functions do not return arrays. + // The information is returned in reference parameters + $row = NULL; + while ($this->_fetch_assoc($row)) + { + $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 private + * @return array + */ + function _data_seek($n = 0) + { + return FALSE; // Not needed + } + +} + ?> \ No newline at end of file diff --git a/system/database/drivers/oci8/oci8_utility.php b/system/database/drivers/oci8/oci8_utility.php index 1d83af1fe..1b49f4131 100644 --- a/system/database/drivers/oci8/oci8_utility.php +++ b/system/database/drivers/oci8/oci8_utility.php @@ -1,129 +1,129 @@ -db->display_error('db_unsuported_feature'); - } - -} - +db->display_error('db_unsuported_feature'); + } + +} + ?> \ No newline at end of file diff --git a/system/database/drivers/odbc/odbc_driver.php b/system/database/drivers/odbc/odbc_driver.php index 9d540c77f..d6451e04a 100644 --- a/system/database/drivers/odbc/odbc_driver.php +++ b/system/database/drivers/odbc/odbc_driver.php @@ -1,12 +1,12 @@ 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; - } - - // Deprecated - function field_names() - { - return $this->list_fields(); - } - - // -------------------------------------------------------------------- - - /** - * 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; - } - -} - +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; + } + + // Deprecated + function field_names() + { + return $this->list_fields(); + } + + // -------------------------------------------------------------------- + + /** + * 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; + } + +} + ?> \ No newline at end of file diff --git a/system/database/drivers/odbc/odbc_utility.php b/system/database/drivers/odbc/odbc_utility.php index 8af463b13..f8d9e3c42 100644 --- a/system/database/drivers/odbc/odbc_utility.php +++ b/system/database/drivers/odbc/odbc_utility.php @@ -1,161 +1,161 @@ -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; - } - - // -------------------------------------------------------------------- - - /** - * List databases - * - * @access private - * @return bool - */ - function _list_databases() - { - // Not sure if ODBC lets you list all databases... - if ($this->db->db_debug) - { - return $this->db->display_error('db_unsuported_feature'); - } - return FALSE; - } - - // -------------------------------------------------------------------- - - /** - * 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; - } - - // -------------------------------------------------------------------- - - /** - * 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'); - } - -} - +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; + } + + // -------------------------------------------------------------------- + + /** + * List databases + * + * @access private + * @return bool + */ + function _list_databases() + { + // Not sure if ODBC lets you list all databases... + if ($this->db->db_debug) + { + return $this->db->display_error('db_unsuported_feature'); + } + return FALSE; + } + + // -------------------------------------------------------------------- + + /** + * 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; + } + + // -------------------------------------------------------------------- + + /** + * 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'); + } + +} + ?> \ No newline at end of file diff --git a/system/database/drivers/postgre/postgre_driver.php b/system/database/drivers/postgre/postgre_driver.php index 58cc69a96..bfb212cfd 100644 --- a/system/database/drivers/postgre/postgre_driver.php +++ b/system/database/drivers/postgre/postgre_driver.php @@ -1,12 +1,12 @@ 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++) - { - $Ffield_names[] = pg_field_name($this->result_id, $i); - } - - return $field_names; - } - - // Deprecated - function field_names() - { - return $this->list_fields(); - } - - // -------------------------------------------------------------------- - - /** - * 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 = $i == 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); - } - -} - +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++) + { + $Ffield_names[] = pg_field_name($this->result_id, $i); + } + + return $field_names; + } + + // Deprecated + function field_names() + { + return $this->list_fields(); + } + + // -------------------------------------------------------------------- + + /** + * 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 = $i == 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); + } + +} + ?> \ No newline at end of file diff --git a/system/database/drivers/postgre/postgre_utility.php b/system/database/drivers/postgre/postgre_utility.php index bebe09415..9d56af363 100644 --- a/system/database/drivers/postgre/postgre_utility.php +++ b/system/database/drivers/postgre/postgre_utility.php @@ -1,129 +1,129 @@ -db->_escape_table($table)." CASCADE"; - } - - // -------------------------------------------------------------------- - - /** - * Optimize table query - * - * Is table optimization supported in Postgre? - * - * @access private - * @param string the table name - * @return object - */ - function _optimize_table($table) - { - return FALSE; - } - - // -------------------------------------------------------------------- - - /** - * Repair table query - * - * Are table repairs supported in Postgre? - * - * @access private - * @param string the table name - * @return object - */ - function _repair_table($table) - { - return FALSE; - } - - // -------------------------------------------------------------------- - - /** - * Postgre Export - * - * @access private - * @param array Preferences - * @return mixed - */ - function _backup($params = array()) - { - // Currently unsupported - return $this->db->display_error('db_unsuported_feature'); - } - -} - +db->_escape_table($table)." CASCADE"; + } + + // -------------------------------------------------------------------- + + /** + * Optimize table query + * + * Is table optimization supported in Postgre? + * + * @access private + * @param string the table name + * @return object + */ + function _optimize_table($table) + { + return FALSE; + } + + // -------------------------------------------------------------------- + + /** + * Repair table query + * + * Are table repairs supported in Postgre? + * + * @access private + * @param string the table name + * @return object + */ + function _repair_table($table) + { + return FALSE; + } + + // -------------------------------------------------------------------- + + /** + * Postgre Export + * + * @access private + * @param array Preferences + * @return mixed + */ + function _backup($params = array()) + { + // Currently unsupported + return $this->db->display_error('db_unsuported_feature'); + } + +} + ?> \ No newline at end of file diff --git a/system/database/drivers/sqlite/sqlite_driver.php b/system/database/drivers/sqlite/sqlite_driver.php index 877f445bb..b82618c6a 100644 --- a/system/database/drivers/sqlite/sqlite_driver.php +++ b/system/database/drivers/sqlite/sqlite_driver.php @@ -1,484 +1,484 @@ -database, 0666, $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, 0666, $error)) - { - log_message('error', $error); - - if ($this->db_debug) - { - $this->display_error($error, '', TRUE); - } - - return FALSE; - } - - return $conn_id; - } - - // -------------------------------------------------------------------- - - /** - * Select the database - * - * @access private called by the base class - * @return resource - */ - function db_select() - { - 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 - * @return string - */ - function escape_str($str) - { - return sqlite_escape_string($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("SELECT COUNT(*) AS numrows FROM `".$this->dbprefix.$table."`"); - - if ($query->num_rows() == 0) - return '0'; - - $row = $query->row(); - return $row->numrows; - } - - // -------------------------------------------------------------------- - - /** - * List table query - * - * Generates a platform-specific query string so that the table names can be fetched - * - * @access private - * @return string - */ - function _list_tables() - { - return "SELECT name from sqlite_master WHERE type='table'"; - } - - // -------------------------------------------------------------------- - - /** - * 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 ".$this->_escape_table($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 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) - { - if (stristr($table, '.')) - { - $table = preg_replace("/\./", "`.`", $table); - } - - return $table; - } - - // -------------------------------------------------------------------- - - /** - * 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 - * @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); - } - - // -------------------------------------------------------------------- - - /** - * Delete statement - * - * Generates a platform-specific delete string from the supplied data - * - * @access public - * @param string the table name - * @param array the where 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) - { - 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, 0666, $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, 0666, $error)) + { + log_message('error', $error); + + if ($this->db_debug) + { + $this->display_error($error, '', TRUE); + } + + return FALSE; + } + + return $conn_id; + } + + // -------------------------------------------------------------------- + + /** + * Select the database + * + * @access private called by the base class + * @return resource + */ + function db_select() + { + 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 + * @return string + */ + function escape_str($str) + { + return sqlite_escape_string($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("SELECT COUNT(*) AS numrows FROM `".$this->dbprefix.$table."`"); + + if ($query->num_rows() == 0) + return '0'; + + $row = $query->row(); + return $row->numrows; + } + + // -------------------------------------------------------------------- + + /** + * List table query + * + * Generates a platform-specific query string so that the table names can be fetched + * + * @access private + * @return string + */ + function _list_tables() + { + return "SELECT name from sqlite_master WHERE type='table'"; + } + + // -------------------------------------------------------------------- + + /** + * 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 ".$this->_escape_table($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 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) + { + if (stristr($table, '.')) + { + $table = preg_replace("/\./", "`.`", $table); + } + + return $table; + } + + // -------------------------------------------------------------------- + + /** + * 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 + * @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); + } + + // -------------------------------------------------------------------- + + /** + * Delete statement + * + * Generates a platform-specific delete string from the supplied data + * + * @access public + * @param string the table name + * @param array the where 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) + { + 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); + } + + +} + ?> \ No newline at end of file diff --git a/system/database/drivers/sqlite/sqlite_result.php b/system/database/drivers/sqlite/sqlite_result.php index a406a935c..a16a5b054 100644 --- a/system/database/drivers/sqlite/sqlite_result.php +++ b/system/database/drivers/sqlite/sqlite_result.php @@ -1,176 +1,176 @@ -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++) - { - $Ffield_names[] = sqlite_field_name($this->result_id, $i); - } - - return $field_names; - } - - // Deprecated - function field_names() - { - return $this->list_fields(); - } - - // -------------------------------------------------------------------- - - /** - * 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 - { - return $this->_fetch_assoc(); - } - } - -} - +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++) + { + $Ffield_names[] = sqlite_field_name($this->result_id, $i); + } + + return $field_names; + } + + // Deprecated + function field_names() + { + return $this->list_fields(); + } + + // -------------------------------------------------------------------- + + /** + * 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 + { + return $this->_fetch_assoc(); + } + } + +} + ?> \ No newline at end of file diff --git a/system/database/drivers/sqlite/sqlite_utility.php b/system/database/drivers/sqlite/sqlite_utility.php index 91649c78d..9683b1756 100644 --- a/system/database/drivers/sqlite/sqlite_utility.php +++ b/system/database/drivers/sqlite/sqlite_utility.php @@ -1,154 +1,154 @@ -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; - } - - // -------------------------------------------------------------------- - - /** - * List databases - * - * I don't believe you can do a database listing with SQLite - * since each database is its own file. I suppose we could - * try reading a directory looking for SQLite files, but - * that doesn't seem like a terribly good idea - * - * @access private - * @return bool - */ - function _list_databases() - { - if ($this->db_debug) - { - return $this->display_error('db_unsuported_feature'); - } - return array(); - } - - // -------------------------------------------------------------------- - - /** - * 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(); - } - - // -------------------------------------------------------------------- - - /** - * 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'); - } - -} - +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; + } + + // -------------------------------------------------------------------- + + /** + * List databases + * + * I don't believe you can do a database listing with SQLite + * since each database is its own file. I suppose we could + * try reading a directory looking for SQLite files, but + * that doesn't seem like a terribly good idea + * + * @access private + * @return bool + */ + function _list_databases() + { + if ($this->db_debug) + { + return $this->display_error('db_unsuported_feature'); + } + return array(); + } + + // -------------------------------------------------------------------- + + /** + * 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(); + } + + // -------------------------------------------------------------------- + + /** + * 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'); + } + +} + ?> \ No newline at end of file diff --git a/system/helpers/array_helper.php b/system/helpers/array_helper.php index 491c61577..674ef3bec 100644 --- a/system/helpers/array_helper.php +++ b/system/helpers/array_helper.php @@ -1,71 +1,71 @@ - \ No newline at end of file diff --git a/system/helpers/cookie_helper.php b/system/helpers/cookie_helper.php index b117816e2..9dc5df9b1 100644 --- a/system/helpers/cookie_helper.php +++ b/system/helpers/cookie_helper.php @@ -1,126 +1,126 @@ -config->item('cookie_prefix') != '') - { - $CI->config->item('cookie_prefix'); - } - if ($domain == '' AND $CI->config->item('cookie_domain') != '') - { - $CI->config->item('cookie_domain'); - } - if ($prefix == '/' AND $CI->config->item('cookie_path') != '/') - { - $CI->config->item('cookie_path'); - } - - if ( ! is_numeric($expire)) - { - $expire = time() - 86500; - } - else - { - if ($expire > 0) - { - $expire = time() + $expire; - } - else - { - $expire = 0; - } - } - - setcookie($prefix.$name, $value, $expire, $path, $domain, 0); -} - -// -------------------------------------------------------------------- - -/** - * Fetch an item from the COOKIE array - * - * @access public - * @param string - * @param bool - * @return mixed - */ -function get_cookie($index = '', $xss_clean = FALSE) -{ - $CI =& get_instance(); - return $CI->input->cookie($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 - */ -function delete_cookie($name = '', $domain = '', $path = '/', $prefix = '') -{ - set_cookie($name, '', '', $domain, $path, $prefix); -} - - +config->item('cookie_prefix') != '') + { + $CI->config->item('cookie_prefix'); + } + if ($domain == '' AND $CI->config->item('cookie_domain') != '') + { + $CI->config->item('cookie_domain'); + } + if ($prefix == '/' AND $CI->config->item('cookie_path') != '/') + { + $CI->config->item('cookie_path'); + } + + if ( ! is_numeric($expire)) + { + $expire = time() - 86500; + } + else + { + if ($expire > 0) + { + $expire = time() + $expire; + } + else + { + $expire = 0; + } + } + + setcookie($prefix.$name, $value, $expire, $path, $domain, 0); +} + +// -------------------------------------------------------------------- + +/** + * Fetch an item from the COOKIE array + * + * @access public + * @param string + * @param bool + * @return mixed + */ +function get_cookie($index = '', $xss_clean = FALSE) +{ + $CI =& get_instance(); + return $CI->input->cookie($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 + */ +function delete_cookie($name = '', $domain = '', $path = '/', $prefix = '') +{ + set_cookie($name, '', '', $domain, $path, $prefix); +} + + ?> \ No newline at end of file diff --git a/system/helpers/date_helper.php b/system/helpers/date_helper.php index 504a962ce..c67e3da2d 100644 --- a/system/helpers/date_helper.php +++ b/system/helpers/date_helper.php @@ -1,12 +1,12 @@ \ No newline at end of file diff --git a/system/helpers/download_helper.php b/system/helpers/download_helper.php index 34cc152cc..c9d81f692 100644 --- a/system/helpers/download_helper.php +++ b/system/helpers/download_helper.php @@ -1,12 +1,12 @@ 0) - { - $data =& fread($fp, filesize($file)); - } - - flock($fp, LOCK_UN); - fclose($fp); - - return $data; -} - -// ------------------------------------------------------------------------ - -/** - * 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 - */ -function write_file($path, $data, $mode = 'wb') -{ - if ( ! $fp = @fopen($path, $mode)) - { - return FALSE; - } - - flock($fp, LOCK_EX); - fwrite($fp, $data); - flock($fp, LOCK_UN); - fclose($fp); - - 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. - * - * @access public - * @param string path to file - * @param bool whether to delete any directories found in the path - * @return bool - */ -function delete_files($path, $del_dir = FALSE, $level = 0) -{ - // Trim the trailing slash - $path = preg_replace("|^(.+?)/*$|", "\\1", $path); - - if ( ! $current_dir = @opendir($path)) - return; - - while(FALSE !== ($filename = @readdir($current_dir))) - { - if ($filename != "." and $filename != "..") - { - if (is_dir($path.'/'.$filename)) - { - $level++; - delete_files($path.'/'.$filename, $del_dir, $level); - } - else - { - unlink($path.'/'.$filename); - } - } - } - @closedir($current_dir); - - if ($del_dir == TRUE AND $level > 0) - { - @rmdir($path); - } -} - -// ------------------------------------------------------------------------ - -/** - * 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 - * @return array - */ -function get_filenames($source_dir, $include_path = FALSE) -{ - static $_filedata = array(); - - if ($fp = @opendir($source_dir)) - { - while (FALSE !== ($file = readdir($fp))) - { - if (@is_dir($source_dir.$file) && substr($file, 0, 1) != '.') - { - get_filenames($source_dir.$file."/", $include_path); - } - elseif (substr($file, 0, 1) != ".") - { - - $_filedata[] = ($include_path == TRUE) ? $source_dir.$file : $file; - } - } - return $_filedata; - } -} - + 0) + { + $data =& fread($fp, filesize($file)); + } + + flock($fp, LOCK_UN); + fclose($fp); + + return $data; +} + +// ------------------------------------------------------------------------ + +/** + * 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 + */ +function write_file($path, $data, $mode = 'wb') +{ + if ( ! $fp = @fopen($path, $mode)) + { + return FALSE; + } + + flock($fp, LOCK_EX); + fwrite($fp, $data); + flock($fp, LOCK_UN); + fclose($fp); + + 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. + * + * @access public + * @param string path to file + * @param bool whether to delete any directories found in the path + * @return bool + */ +function delete_files($path, $del_dir = FALSE, $level = 0) +{ + // Trim the trailing slash + $path = preg_replace("|^(.+?)/*$|", "\\1", $path); + + if ( ! $current_dir = @opendir($path)) + return; + + while(FALSE !== ($filename = @readdir($current_dir))) + { + if ($filename != "." and $filename != "..") + { + if (is_dir($path.'/'.$filename)) + { + $level++; + delete_files($path.'/'.$filename, $del_dir, $level); + } + else + { + unlink($path.'/'.$filename); + } + } + } + @closedir($current_dir); + + if ($del_dir == TRUE AND $level > 0) + { + @rmdir($path); + } +} + +// ------------------------------------------------------------------------ + +/** + * 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 + * @return array + */ +function get_filenames($source_dir, $include_path = FALSE) +{ + static $_filedata = array(); + + if ($fp = @opendir($source_dir)) + { + while (FALSE !== ($file = readdir($fp))) + { + if (@is_dir($source_dir.$file) && substr($file, 0, 1) != '.') + { + get_filenames($source_dir.$file."/", $include_path); + } + elseif (substr($file, 0, 1) != ".") + { + + $_filedata[] = ($include_path == TRUE) ? $source_dir.$file : $file; + } + } + return $_filedata; + } +} + ?> \ No newline at end of file diff --git a/system/helpers/form_helper.php b/system/helpers/form_helper.php index a166198fb..adbddd5ad 100644 --- a/system/helpers/form_helper.php +++ b/system/helpers/form_helper.php @@ -1,12 +1,12 @@ ".$data.""; -} - -// ------------------------------------------------------------------------ - -/** - * Unordered List - * - * Generates an HTML unordered list from an single or multi-dimensional array. - * - * @access public - * @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 - */ -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 intiger - * @return string - */ -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; - } - - // 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 HTML BR tags based on number supplied - * - * @access public - * @param integer - * @return string - */ -function br($num = 1) -{ - return str_repeat("
    ", $num); -} - -// ------------------------------------------------------------------------ - -/** - * Generates non-breaking space entities based on number supplied - * - * @access public - * @param integer - * @return string - */ -function nbs($num = 1) -{ - return str_repeat(" ", $num); -} - -// ------------------------------------------------------------------------ - -/** - * Generates meta tags from an array of key/values - * - * @access public - * @param array - * @return string - */ -function meta($meta = array(), $newline = "\n") -{ - $str = ''; - foreach ($meta as $key => $val) - { - $str .= ''.$newline; - } - - return $str; -} - - - - +".$data.""; +} + +// ------------------------------------------------------------------------ + +/** + * Unordered List + * + * Generates an HTML unordered list from an single or multi-dimensional array. + * + * @access public + * @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 + */ +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 intiger + * @return string + */ +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; + } + + // 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 HTML BR tags based on number supplied + * + * @access public + * @param integer + * @return string + */ +function br($num = 1) +{ + return str_repeat("
    ", $num); +} + +// ------------------------------------------------------------------------ + +/** + * Generates non-breaking space entities based on number supplied + * + * @access public + * @param integer + * @return string + */ +function nbs($num = 1) +{ + return str_repeat(" ", $num); +} + +// ------------------------------------------------------------------------ + +/** + * Generates meta tags from an array of key/values + * + * @access public + * @param array + * @return string + */ +function meta($meta = array(), $newline = "\n") +{ + $str = ''; + foreach ($meta as $key => $val) + { + $str .= ''.$newline; + } + + return $str; +} + + + + ?> \ No newline at end of file diff --git a/system/helpers/inflector_helper.php b/system/helpers/inflector_helper.php index 666ec40b8..fbe851f3b 100644 --- a/system/helpers/inflector_helper.php +++ b/system/helpers/inflector_helper.php @@ -1,140 +1,140 @@ - \ No newline at end of file diff --git a/system/helpers/security_helper.php b/system/helpers/security_helper.php index 06228468f..eec04015d 100644 --- a/system/helpers/security_helper.php +++ b/system/helpers/security_helper.php @@ -1,112 +1,112 @@ -input->xss_clean($str, $charset); -} - -// -------------------------------------------------------------------- - -/** - * Hash encode a string - * - * @access public - * @param string - * @return string - */ -function dohash($str, $type = 'sha1') -{ - if ($type == 'sha1') - { - if ( ! function_exists('sha1')) - { - if ( ! function_exists('mhash')) - { - require_once(BASEPATH.'libraries/Sha1'.EXT); - $SH = new CI_SHA; - return $SH->generate($str); - } - else - { - return bin2hex(mhash(MHASH_SHA1, $str)); - } - } - else - { - return sha1($str); - } - } - else - { - return md5($str); - } -} - -// ------------------------------------------------------------------------ - -/** - * Strip Image Tags - * - * @access public - * @param string - * @return string - */ -function strip_image_tags($str) -{ - $str = preg_replace("##", "\\1", $str); - $str = preg_replace("##", "\\1", $str); - - return $str; -} - -// ------------------------------------------------------------------------ - -/** - * Convert PHP tags to entities - * - * @access public - * @param string - * @return string - */ -function encode_php_tags($str) -{ - return str_replace(array(''), array('<?php', '<?PHP', '<?', '?>'), $str); -} - +input->xss_clean($str, $charset); +} + +// -------------------------------------------------------------------- + +/** + * Hash encode a string + * + * @access public + * @param string + * @return string + */ +function dohash($str, $type = 'sha1') +{ + if ($type == 'sha1') + { + if ( ! function_exists('sha1')) + { + if ( ! function_exists('mhash')) + { + require_once(BASEPATH.'libraries/Sha1'.EXT); + $SH = new CI_SHA; + return $SH->generate($str); + } + else + { + return bin2hex(mhash(MHASH_SHA1, $str)); + } + } + else + { + return sha1($str); + } + } + else + { + return md5($str); + } +} + +// ------------------------------------------------------------------------ + +/** + * Strip Image Tags + * + * @access public + * @param string + * @return string + */ +function strip_image_tags($str) +{ + $str = preg_replace("##", "\\1", $str); + $str = preg_replace("##", "\\1", $str); + + return $str; +} + +// ------------------------------------------------------------------------ + +/** + * Convert PHP tags to entities + * + * @access public + * @param string + * @return string + */ +function encode_php_tags($str) +{ + return str_replace(array(''), array('<?php', '<?PHP', '<?', '?>'), $str); +} + ?> \ No newline at end of file diff --git a/system/helpers/smiley_helper.php b/system/helpers/smiley_helper.php index a07337246..9f16d3132 100644 --- a/system/helpers/smiley_helper.php +++ b/system/helpers/smiley_helper.php @@ -1,165 +1,165 @@ - - function insert_smiley(smiley) - { - document.{$form_name}.{$form_field}.value += " " + smiley; - } - -EOF; -} - -// ------------------------------------------------------------------------ - -/** - * 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 - */ -function get_clickable_smileys($image_url = '', $smileys = NULL) -{ - 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); - - $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 - */ -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; -} - -// ------------------------------------------------------------------------ - -/** - * Get Smiley Array - * - * Fetches the config/smiley.php file - * - * @access private - * @return mixed - */ -function _get_smiley_array() -{ - if ( ! file_exists(APPPATH.'config/smileys'.EXT)) - { - return FALSE; - } - - include(APPPATH.'config/smileys'.EXT); - - if ( ! isset($smileys) OR ! is_array($smileys)) - { - return FALSE; - } - - return $smileys; -} - - - - + + function insert_smiley(smiley) + { + document.{$form_name}.{$form_field}.value += " " + smiley; + } + +EOF; +} + +// ------------------------------------------------------------------------ + +/** + * 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 + */ +function get_clickable_smileys($image_url = '', $smileys = NULL) +{ + 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); + + $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 + */ +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; +} + +// ------------------------------------------------------------------------ + +/** + * Get Smiley Array + * + * Fetches the config/smiley.php file + * + * @access private + * @return mixed + */ +function _get_smiley_array() +{ + if ( ! file_exists(APPPATH.'config/smileys'.EXT)) + { + return FALSE; + } + + include(APPPATH.'config/smileys'.EXT); + + if ( ! isset($smileys) OR ! is_array($smileys)) + { + return FALSE; + } + + return $smileys; +} + + + + ?> \ No newline at end of file diff --git a/system/helpers/string_helper.php b/system/helpers/string_helper.php index c0a8854dc..04c3a592a 100644 --- a/system/helpers/string_helper.php +++ b/system/helpers/string_helper.php @@ -1,12 +1,12 @@ = $n) - { - return trim($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 - */ -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) - { - $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; -} - -// ------------------------------------------------------------------------ - -/** - * Entities to ASCII - * - * Converts character entities back to ASCII - * - * @access public - * @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)); - $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; -} - -// ------------------------------------------------------------------------ - -/** - * 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 - */ -function word_censor($str, $censored, $replacement = '') -{ - if ( ! is_array($censored)) - { - return $str; - } - - $str = ' '.$str.' '; - foreach ($censored as $badword) - { - if ($replacement != '') - { - $str = preg_replace("/\b(".str_replace('\*', '\w*?', preg_quote($badword)).")\b/i", $replacement, $str); - } - else - { - $str = preg_replace("/\b(".str_replace('\*', '\w*?', preg_quote($badword)).")\b/ie", "str_repeat('#', strlen('\\1'))", $str); - } - } - - return trim($str); -} - -// ------------------------------------------------------------------------ - -/** - * Code Highlighter - * - * Colorizes code strings - * - * @access public - * @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 - $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('<?php', '?>', '\\'), array('phptagopen', 'phptagclose', 'backslashtmp'), $str); - - // The highlight_string function requires that the text be surrounded - // by PHP tags. Since we don't know if A) the submitted text has PHP tags, - // or B) whether the PHP tags enclose the entire string, we will add our - // own PHP tags around the string along with some markers to make replacement easier later - - $str = ''; - - // All the magic happens here, baby! - $str = highlight_string($str, TRUE); - - // Prior to PHP 5, the highlight function used icky font tags - // so we'll replace them with span tags. - if (abs(phpversion()) < 5) - { - $str = str_replace(array(''), array(''), $str); - $str = preg_replace('#color="(.*?)"#', 'style="color: \\1"', $str); - } - - // Remove our artificially added PHP - $str = preg_replace("#\.+?//tempstart\
    \#is", "\n", $str); - $str = preg_replace("#\.+?//tempstart\
    #is", "\n", $str); - $str = preg_replace("#//tempend.+#is", "
    \n", $str); - - // Replace our markers back to PHP tags. - $str = str_replace(array('phptagopen', 'phptagclose', 'backslashtmp'), array('<?php', '?>', '\\'), $str); //', $tag_close = '
    ') -{ - if ($str == '') - { - return ''; - } - - if ($phrase != '') - { - return preg_replace('/('.preg_quote($phrase).')/i', $tag_open."\\1".$tag_close, $str); - } - - return $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 - */ -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 - $str = preg_replace("/\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.$this->newline.$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; -} - - += $n) + { + return trim($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 + */ +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) + { + $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; +} + +// ------------------------------------------------------------------------ + +/** + * Entities to ASCII + * + * Converts character entities back to ASCII + * + * @access public + * @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)); + $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; +} + +// ------------------------------------------------------------------------ + +/** + * 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 + */ +function word_censor($str, $censored, $replacement = '') +{ + if ( ! is_array($censored)) + { + return $str; + } + + $str = ' '.$str.' '; + foreach ($censored as $badword) + { + if ($replacement != '') + { + $str = preg_replace("/\b(".str_replace('\*', '\w*?', preg_quote($badword)).")\b/i", $replacement, $str); + } + else + { + $str = preg_replace("/\b(".str_replace('\*', '\w*?', preg_quote($badword)).")\b/ie", "str_repeat('#', strlen('\\1'))", $str); + } + } + + return trim($str); +} + +// ------------------------------------------------------------------------ + +/** + * Code Highlighter + * + * Colorizes code strings + * + * @access public + * @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 + $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('<?php', '?>', '\\'), array('phptagopen', 'phptagclose', 'backslashtmp'), $str); + + // The highlight_string function requires that the text be surrounded + // by PHP tags. Since we don't know if A) the submitted text has PHP tags, + // or B) whether the PHP tags enclose the entire string, we will add our + // own PHP tags around the string along with some markers to make replacement easier later + + $str = ''; + + // All the magic happens here, baby! + $str = highlight_string($str, TRUE); + + // Prior to PHP 5, the highlight function used icky font tags + // so we'll replace them with span tags. + if (abs(phpversion()) < 5) + { + $str = str_replace(array(''), array(''), $str); + $str = preg_replace('#color="(.*?)"#', 'style="color: \\1"', $str); + } + + // Remove our artificially added PHP + $str = preg_replace("#\.+?//tempstart\
    \#is", "\n", $str); + $str = preg_replace("#\.+?//tempstart\
    #is", "\n", $str); + $str = preg_replace("#//tempend.+#is", "
    \n", $str); + + // Replace our markers back to PHP tags. + $str = str_replace(array('phptagopen', 'phptagclose', 'backslashtmp'), array('<?php', '?>', '\\'), $str); //', $tag_close = '') +{ + if ($str == '') + { + return ''; + } + + if ($phrase != '') + { + return preg_replace('/('.preg_quote($phrase).')/i', $tag_open."\\1".$tag_close, $str); + } + + return $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 + */ +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 + $str = preg_replace("/\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.$this->newline.$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; +} + + ?> \ No newline at end of file diff --git a/system/helpers/typography_helper.php b/system/helpers/typography_helper.php index 1681fa37c..131358c6a 100644 --- a/system/helpers/typography_helper.php +++ b/system/helpers/typography_helper.php @@ -1,540 +1,540 @@ -",$str); - $ct = count($ex); - - $newstr = ""; - for ($i = 0; $i < $ct; $i++) - { - if (($i % 2) == 0) - { - $newstr .= nl2br($ex[$i]); - } - else - { - $newstr .= $ex[$i]; - } - - if ($ct - 1 != $i) - $newstr .= "pre>"; - } - - return $newstr; -} - -// ------------------------------------------------------------------------ - -/** - * Auto Typography Wrapper Function - * - * - * @access public - * @param string - * @return string - */ -function auto_typography($str) -{ - $TYPE = new Auto_typography(); - return $TYPE->convert($str); -} - -// ------------------------------------------------------------------------ - -/** - * Auto Typography Class - * - * - * @access private - * @category Helpers - * @author Rick Ellis - * @author Paul Burdick - * @link http://www.codeigniter.com/user_guide/helpers/ - */ -class Auto_typography { - - // Block level elements that should not be wrapped inside

    tags - var $block_elements = 'div|blockquote|pre|code|h\d|script|ol|un'; - - // Elements that should not have

    and
    tags within them. - var $skip_elements = 'pre|ol|ul'; - - // Tags we want the parser to completely ignore when splitting the string. - var $ignore_elements = 'a|b|i|em|strong|span|img|li'; - - - /** - * Main Processing Function - * - */ - function convert($str) - { - if ($str == '') - { - return ''; - } - - $str = ' '.$str.' '; - - // Standardize Newlines to make matching easier - $str = preg_replace("/(\r\n|\r)/", "\n", $str); - - /* - * Reduce line breaks - * - * If there are more than two consecutive line - * breaks we'll compress them down to a maximum - * of two since there's no benefit to more. - * - */ - $str = preg_replace("/\n\n+/", "\n\n", $str); - - /* - * Convert quotes within tags to temporary marker - * - * We don't want quotes converted within - * tags so we'll temporarily convert them to - * {@DQ} and {@SQ} - * - */ - if (preg_match_all("#\<.+?>#si", $str, $matches)) - { - for ($i = 0; $i < count($matches['0']); $i++) - { - $str = str_replace($matches['0'][$i], - str_replace(array("'",'"'), array('{@SQ}', '{@DQ}'), $matches['0'][$i]), - $str); - } - } - - - /* - * Add closing/opening paragraph tags before/after "block" elements - * - * Since block elements (like ,

    , etc.) do not get
    -		 * wrapped in paragraph tags we will add a closing 

    tag just before - * each block element starts and an opening

    tag right after the block element - * ends. Later on we'll do some further clean up. - * - */ - $str = preg_replace("#(<.*?)(".$this->block_elements.")(.*?>)#", "

    \\1\\2\\3", $str); - $str = preg_replace("#(block_elements.")(.*?>)#", "\\1\\2\\3

    ", $str); - - /* - * Convert "ignore" tags to temporary marker - * - * The parser splits out the string at every tag - * it encounters. Certain inline tags, like image - * tags, links, span tags, etc. will be adversely - * affected if they are split out so we'll convert - * the opening < temporarily to: {@TAG} - * - */ - $str = preg_replace("#<(/*)(".$this->ignore_elements.")#i", "{@TAG}\\1\\2", $str); - - /* - * Split the string at every tag - * - * This creates an array with this prototype: - * - * [array] - * { - * [0] = - * [1] = Content contained between the tags - * [2] = - * Etc... - * } - * - */ - $chunks = preg_split('/(<(?:[^<>]+(?:"[^"]*"|\'[^\']*\')?)+>)/', $str, -1, PREG_SPLIT_DELIM_CAPTURE|PREG_SPLIT_NO_EMPTY); - - /* - * Build our finalized string - * - * We'll cycle through the array, skipping tags, - * and processing the contained text - * - */ - $str = ''; - $process = TRUE; - foreach ($chunks as $chunk) - { - /* - * Are we dealing with a tag? - * - * If so, we'll skip the processing for this cycle. - * Well also set the "process" flag which allows us - * to skip

     tags and a few other things.
    -			 *
    -			 */
    -			if (preg_match("#<(/*)(".$this->block_elements.").*?\>#", $chunk, $match))
    -			{
    -				if (preg_match("#".$this->skip_elements."#", $match['2']))
    -				{
    -					$process =  ($match['1'] == '/') ? TRUE : FALSE;		
    -				}
    -		
    -				$str .= $chunk;
    -				continue;
    -			}
    -		
    -			if ($process == FALSE)
    -			{
    -				$str .= $chunk;
    -				continue;
    -			}
    -			
    -			//  Convert Newlines into 

    and
    tags - $str .= $this->format_newlines($chunk); - } - - // FINAL CLEAN UP - // IMPORTANT: DO NOT ALTER THE ORDER OF THE ITEMS BELOW! - - /* - * Clean up paragraph tags before/after "block" elements - * - * Earlier we added

    tags before/after block level elements. - * Then, we added paragraph tags around double line breaks. This - * potentially created incorrectly formatted paragraphs so we'll - * clean it up here. - * - */ - $str = preg_replace("#

    ({@TAG}.*?)(".$this->block_elements.")(.*?>)#", "\\1\\2\\3", $str); - $str = preg_replace("#({@TAG}/.*?)(".$this->block_elements.")(.*?>)

    #", "\\1\\2\\3", $str); - - // Convert Quotes and other characters - $str = $this->format_characters($str); - - // Fix an artifact that happens during the paragraph replacement - $str = preg_replace('#(

    \n*

    )#', '', $str); - - // If the user submitted their own paragraph tags with class data - // in them we will retain them instead of using our tags. - $str = preg_replace('#()

    #', "\\1", $str); - - // Final clean up - $str = str_replace( - array( - '

    ', - '

    ', - '

    ', - '

    ', - '{@TAG}', - '{@DQ}', - '{@SQ}', - '

    ' - ), - array( - '

    ', - '

    ', - '

    ', - '

    ', - '<', - '"', - "'", - '' - ), - $str - ); - - return $str; - } - - // -------------------------------------------------------------------- - - /** - * Format Characters - * - * This function mainly converts double and single quotes - * to entities, but since these are directional, it does - * it based on some rules. It also converts em-dashes - * and a couple other things. - */ - function format_characters($str) - { - $table = array( - ' "' => " “", - '" ' => "” ", - " '" => " ‘", - "' " => "’ ", - - '>"' => ">“", - '"<' => "”<", - ">'" => ">‘", - "'<" => "’<", - - "\"." => "”.", - "\"," => "”,", - "\";" => "”;", - "\":" => "”:", - "\"!" => "”!", - "\"?" => "”?", - - ". " => ".  ", - "? " => "?  ", - "! " => "!  ", - ": " => ":  ", - ); - - // These deal with quotes within quotes, like: "'hi here'" - $start = 0; - $space = array("\n", "\t", " "); - - while(TRUE) - { - $current = strpos(substr($str, $start), "\"'"); - - if ($current === FALSE) break; - - $one_before = substr($str, $start+$current-1, 1); - $one_after = substr($str, $start+$current+2, 1); - - if ( ! in_array($one_after, $space, TRUE) && $one_after != "<") - { - $str = str_replace( $one_before."\"'".$one_after, - $one_before."“‘".$one_after, - $str); - } - elseif ( ! in_array($one_before, $space, TRUE) && (in_array($one_after, $space, TRUE) OR $one_after == '<')) - { - $str = str_replace( $one_before."\"'".$one_after, - $one_before."”’".$one_after, - $str); - } - - $start = $start+$current+2; - } - - $start = 0; - - while(TRUE) - { - $current = strpos(substr($str, $start), "'\""); - - if ($current === FALSE) break; - - $one_before = substr($str, $start+$current-1, 1); - $one_after = substr($str, $start+$current+2, 1); - - if ( in_array($one_before, $space, TRUE) && ! in_array($one_after, $space, TRUE) && $one_after != "<") - { - $str = str_replace( $one_before."'\"".$one_after, - $one_before."‘“".$one_after, - $str); - } - elseif ( ! in_array($one_before, $space, TRUE) && $one_before != ">") - { - $str = str_replace( $one_before."'\"".$one_after, - $one_before."’”".$one_after, - $str); - } - - $start = $start+$current+2; - } - - // Are there quotes within a word, as in: ("something") - if (preg_match_all("/(.)\"(\S+?)\"(.)/", $str, $matches)) - { - for ($i=0, $s=sizeof($matches['0']); $i < $s; ++$i) - { - if ( ! in_array($matches['1'][$i], $space, TRUE) && ! in_array($matches['3'][$i], $space, TRUE)) - { - $str = str_replace( $matches['0'][$i], - $matches['1'][$i]."“".$matches['2'][$i]."”".$matches['3'][$i], - $str); - } - } - } - - if (preg_match_all("/(.)\'(\S+?)\'(.)/", $str, $matches)) - { - for ($i=0, $s=sizeof($matches['0']); $i < $s; ++$i) - { - if ( ! in_array($matches['1'][$i], $space, TRUE) && ! in_array($matches['3'][$i], $space, TRUE)) - { - $str = str_replace( $matches['0'][$i], - $matches['1'][$i]."‘".$matches['2'][$i]."’".$matches['3'][$i], - $str); - } - } - } - - // How about one apostrophe, as in Rick's - $start = 0; - - while(TRUE) - { - $current = strpos(substr($str, $start), "'"); - - if ($current === FALSE) break; - - $one_before = substr($str, $start+$current-1, 1); - $one_after = substr($str, $start+$current+1, 1); - - if ( ! in_array($one_before, $space, TRUE) && ! in_array($one_after, $space, TRUE)) - { - $str = str_replace( $one_before."'".$one_after, - $one_before."’".$one_after, - $str); - } - - $start = $start+$current+2; - } - - // Em-dashes - $start = 0; - while(TRUE) - { - $current = strpos(substr($str, $start), "--"); - - if ($current === FALSE) break; - - $one_before = substr($str, $start+$current-1, 1); - $one_after = substr($str, $start+$current+2, 1); - $two_before = substr($str, $start+$current-2, 1); - $two_after = substr($str, $start+$current+3, 1); - - if (( ! in_array($one_before, $space, TRUE) && ! in_array($one_after, $space, TRUE)) - OR - ( ! in_array($two_before, $space, TRUE) && ! in_array($two_after, $space, TRUE) && $one_before == ' ' && $one_after == ' ') - ) - { - $str = str_replace( $two_before.$one_before."--".$one_after.$two_after, - $two_before.trim($one_before)."—".trim($one_after).$two_after, - $str); - } - - $start = $start+$current+2; - } - - // Ellipsis - $str = preg_replace("#(\w)\.\.\.(\s|
    |

    )#", "\\1…\\2", $str); - $str = preg_replace("#(\s|
    |

    )\.\.\.(\w)#", "\\1…\\2", $str); - - // Run the translation array we defined above - $str = str_replace(array_keys($table), array_values($table), $str); - - // If there are any stray double quotes we'll catch them here - - $start = 0; - - while(TRUE) - { - $current = strpos(substr($str, $start), '"'); - - if ($current === FALSE) break; - - $one_before = substr($str, $start+$current-1, 1); - $one_after = substr($str, $start+$current+1, 1); - - if ( ! in_array($one_after, $space, TRUE)) - { - $str = str_replace( $one_before.'"'.$one_after, - $one_before."“".$one_after, - $str); - } - elseif( ! in_array($one_before, $space, TRUE)) - { - $str = str_replace( $one_before."'".$one_after, - $one_before."”".$one_after, - $str); - } - - $start = $start+$current+2; - } - - $start = 0; - - while(TRUE) - { - $current = strpos(substr($str, $start), "'"); - - if ($current === FALSE) break; - - $one_before = substr($str, $start+$current-1, 1); - $one_after = substr($str, $start+$current+1, 1); - - if ( ! in_array($one_after, $space, TRUE)) - { - $str = str_replace( $one_before."'".$one_after, - $one_before."‘".$one_after, - $str); - } - elseif( ! in_array($one_before, $space, TRUE)) - { - $str = str_replace( $one_before."'".$one_after, - $one_before."’".$one_after, - $str); - } - - $start = $start+$current+2; - } - - return $str; - } - - // -------------------------------------------------------------------- - - /** - * Format Newlines - * - * Converts newline characters into either

    tags or
    - * - */ - function format_newlines($str) - { - if ($str == '') - { - return $str; - } - - if (strpos($str, "\n") === FALSE) - { - return '

    '.$str.'

    '; - } - - $str = str_replace("\n\n", "

    \n\n

    ", $str); - $str = preg_replace("/([^\n])(\n)([^\n])/", "\\1
    \\2\\3", $str); - - return '

    '.$str.'

    '; - } -} - - +",$str); + $ct = count($ex); + + $newstr = ""; + for ($i = 0; $i < $ct; $i++) + { + if (($i % 2) == 0) + { + $newstr .= nl2br($ex[$i]); + } + else + { + $newstr .= $ex[$i]; + } + + if ($ct - 1 != $i) + $newstr .= "pre>"; + } + + return $newstr; +} + +// ------------------------------------------------------------------------ + +/** + * Auto Typography Wrapper Function + * + * + * @access public + * @param string + * @return string + */ +function auto_typography($str) +{ + $TYPE = new Auto_typography(); + return $TYPE->convert($str); +} + +// ------------------------------------------------------------------------ + +/** + * Auto Typography Class + * + * + * @access private + * @category Helpers + * @author Rick Ellis + * @author Paul Burdick + * @link http://www.codeigniter.com/user_guide/helpers/ + */ +class Auto_typography { + + // Block level elements that should not be wrapped inside

    tags + var $block_elements = 'div|blockquote|pre|code|h\d|script|ol|un'; + + // Elements that should not have

    and
    tags within them. + var $skip_elements = 'pre|ol|ul'; + + // Tags we want the parser to completely ignore when splitting the string. + var $ignore_elements = 'a|b|i|em|strong|span|img|li'; + + + /** + * Main Processing Function + * + */ + function convert($str) + { + if ($str == '') + { + return ''; + } + + $str = ' '.$str.' '; + + // Standardize Newlines to make matching easier + $str = preg_replace("/(\r\n|\r)/", "\n", $str); + + /* + * Reduce line breaks + * + * If there are more than two consecutive line + * breaks we'll compress them down to a maximum + * of two since there's no benefit to more. + * + */ + $str = preg_replace("/\n\n+/", "\n\n", $str); + + /* + * Convert quotes within tags to temporary marker + * + * We don't want quotes converted within + * tags so we'll temporarily convert them to + * {@DQ} and {@SQ} + * + */ + if (preg_match_all("#\<.+?>#si", $str, $matches)) + { + for ($i = 0; $i < count($matches['0']); $i++) + { + $str = str_replace($matches['0'][$i], + str_replace(array("'",'"'), array('{@SQ}', '{@DQ}'), $matches['0'][$i]), + $str); + } + } + + + /* + * Add closing/opening paragraph tags before/after "block" elements + * + * Since block elements (like ,

    , etc.) do not get
    +		 * wrapped in paragraph tags we will add a closing 

    tag just before + * each block element starts and an opening

    tag right after the block element + * ends. Later on we'll do some further clean up. + * + */ + $str = preg_replace("#(<.*?)(".$this->block_elements.")(.*?>)#", "

    \\1\\2\\3", $str); + $str = preg_replace("#(block_elements.")(.*?>)#", "\\1\\2\\3

    ", $str); + + /* + * Convert "ignore" tags to temporary marker + * + * The parser splits out the string at every tag + * it encounters. Certain inline tags, like image + * tags, links, span tags, etc. will be adversely + * affected if they are split out so we'll convert + * the opening < temporarily to: {@TAG} + * + */ + $str = preg_replace("#<(/*)(".$this->ignore_elements.")#i", "{@TAG}\\1\\2", $str); + + /* + * Split the string at every tag + * + * This creates an array with this prototype: + * + * [array] + * { + * [0] = + * [1] = Content contained between the tags + * [2] = + * Etc... + * } + * + */ + $chunks = preg_split('/(<(?:[^<>]+(?:"[^"]*"|\'[^\']*\')?)+>)/', $str, -1, PREG_SPLIT_DELIM_CAPTURE|PREG_SPLIT_NO_EMPTY); + + /* + * Build our finalized string + * + * We'll cycle through the array, skipping tags, + * and processing the contained text + * + */ + $str = ''; + $process = TRUE; + foreach ($chunks as $chunk) + { + /* + * Are we dealing with a tag? + * + * If so, we'll skip the processing for this cycle. + * Well also set the "process" flag which allows us + * to skip

     tags and a few other things.
    +			 *
    +			 */
    +			if (preg_match("#<(/*)(".$this->block_elements.").*?\>#", $chunk, $match))
    +			{
    +				if (preg_match("#".$this->skip_elements."#", $match['2']))
    +				{
    +					$process =  ($match['1'] == '/') ? TRUE : FALSE;		
    +				}
    +		
    +				$str .= $chunk;
    +				continue;
    +			}
    +		
    +			if ($process == FALSE)
    +			{
    +				$str .= $chunk;
    +				continue;
    +			}
    +			
    +			//  Convert Newlines into 

    and
    tags + $str .= $this->format_newlines($chunk); + } + + // FINAL CLEAN UP + // IMPORTANT: DO NOT ALTER THE ORDER OF THE ITEMS BELOW! + + /* + * Clean up paragraph tags before/after "block" elements + * + * Earlier we added

    tags before/after block level elements. + * Then, we added paragraph tags around double line breaks. This + * potentially created incorrectly formatted paragraphs so we'll + * clean it up here. + * + */ + $str = preg_replace("#

    ({@TAG}.*?)(".$this->block_elements.")(.*?>)#", "\\1\\2\\3", $str); + $str = preg_replace("#({@TAG}/.*?)(".$this->block_elements.")(.*?>)

    #", "\\1\\2\\3", $str); + + // Convert Quotes and other characters + $str = $this->format_characters($str); + + // Fix an artifact that happens during the paragraph replacement + $str = preg_replace('#(

    \n*

    )#', '', $str); + + // If the user submitted their own paragraph tags with class data + // in them we will retain them instead of using our tags. + $str = preg_replace('#()

    #', "\\1", $str); + + // Final clean up + $str = str_replace( + array( + '

    ', + '

    ', + '

    ', + '

    ', + '{@TAG}', + '{@DQ}', + '{@SQ}', + '

    ' + ), + array( + '

    ', + '

    ', + '

    ', + '

    ', + '<', + '"', + "'", + '' + ), + $str + ); + + return $str; + } + + // -------------------------------------------------------------------- + + /** + * Format Characters + * + * This function mainly converts double and single quotes + * to entities, but since these are directional, it does + * it based on some rules. It also converts em-dashes + * and a couple other things. + */ + function format_characters($str) + { + $table = array( + ' "' => " “", + '" ' => "” ", + " '" => " ‘", + "' " => "’ ", + + '>"' => ">“", + '"<' => "”<", + ">'" => ">‘", + "'<" => "’<", + + "\"." => "”.", + "\"," => "”,", + "\";" => "”;", + "\":" => "”:", + "\"!" => "”!", + "\"?" => "”?", + + ". " => ".  ", + "? " => "?  ", + "! " => "!  ", + ": " => ":  ", + ); + + // These deal with quotes within quotes, like: "'hi here'" + $start = 0; + $space = array("\n", "\t", " "); + + while(TRUE) + { + $current = strpos(substr($str, $start), "\"'"); + + if ($current === FALSE) break; + + $one_before = substr($str, $start+$current-1, 1); + $one_after = substr($str, $start+$current+2, 1); + + if ( ! in_array($one_after, $space, TRUE) && $one_after != "<") + { + $str = str_replace( $one_before."\"'".$one_after, + $one_before."“‘".$one_after, + $str); + } + elseif ( ! in_array($one_before, $space, TRUE) && (in_array($one_after, $space, TRUE) OR $one_after == '<')) + { + $str = str_replace( $one_before."\"'".$one_after, + $one_before."”’".$one_after, + $str); + } + + $start = $start+$current+2; + } + + $start = 0; + + while(TRUE) + { + $current = strpos(substr($str, $start), "'\""); + + if ($current === FALSE) break; + + $one_before = substr($str, $start+$current-1, 1); + $one_after = substr($str, $start+$current+2, 1); + + if ( in_array($one_before, $space, TRUE) && ! in_array($one_after, $space, TRUE) && $one_after != "<") + { + $str = str_replace( $one_before."'\"".$one_after, + $one_before."‘“".$one_after, + $str); + } + elseif ( ! in_array($one_before, $space, TRUE) && $one_before != ">") + { + $str = str_replace( $one_before."'\"".$one_after, + $one_before."’”".$one_after, + $str); + } + + $start = $start+$current+2; + } + + // Are there quotes within a word, as in: ("something") + if (preg_match_all("/(.)\"(\S+?)\"(.)/", $str, $matches)) + { + for ($i=0, $s=sizeof($matches['0']); $i < $s; ++$i) + { + if ( ! in_array($matches['1'][$i], $space, TRUE) && ! in_array($matches['3'][$i], $space, TRUE)) + { + $str = str_replace( $matches['0'][$i], + $matches['1'][$i]."“".$matches['2'][$i]."”".$matches['3'][$i], + $str); + } + } + } + + if (preg_match_all("/(.)\'(\S+?)\'(.)/", $str, $matches)) + { + for ($i=0, $s=sizeof($matches['0']); $i < $s; ++$i) + { + if ( ! in_array($matches['1'][$i], $space, TRUE) && ! in_array($matches['3'][$i], $space, TRUE)) + { + $str = str_replace( $matches['0'][$i], + $matches['1'][$i]."‘".$matches['2'][$i]."’".$matches['3'][$i], + $str); + } + } + } + + // How about one apostrophe, as in Rick's + $start = 0; + + while(TRUE) + { + $current = strpos(substr($str, $start), "'"); + + if ($current === FALSE) break; + + $one_before = substr($str, $start+$current-1, 1); + $one_after = substr($str, $start+$current+1, 1); + + if ( ! in_array($one_before, $space, TRUE) && ! in_array($one_after, $space, TRUE)) + { + $str = str_replace( $one_before."'".$one_after, + $one_before."’".$one_after, + $str); + } + + $start = $start+$current+2; + } + + // Em-dashes + $start = 0; + while(TRUE) + { + $current = strpos(substr($str, $start), "--"); + + if ($current === FALSE) break; + + $one_before = substr($str, $start+$current-1, 1); + $one_after = substr($str, $start+$current+2, 1); + $two_before = substr($str, $start+$current-2, 1); + $two_after = substr($str, $start+$current+3, 1); + + if (( ! in_array($one_before, $space, TRUE) && ! in_array($one_after, $space, TRUE)) + OR + ( ! in_array($two_before, $space, TRUE) && ! in_array($two_after, $space, TRUE) && $one_before == ' ' && $one_after == ' ') + ) + { + $str = str_replace( $two_before.$one_before."--".$one_after.$two_after, + $two_before.trim($one_before)."—".trim($one_after).$two_after, + $str); + } + + $start = $start+$current+2; + } + + // Ellipsis + $str = preg_replace("#(\w)\.\.\.(\s|
    |

    )#", "\\1…\\2", $str); + $str = preg_replace("#(\s|
    |

    )\.\.\.(\w)#", "\\1…\\2", $str); + + // Run the translation array we defined above + $str = str_replace(array_keys($table), array_values($table), $str); + + // If there are any stray double quotes we'll catch them here + + $start = 0; + + while(TRUE) + { + $current = strpos(substr($str, $start), '"'); + + if ($current === FALSE) break; + + $one_before = substr($str, $start+$current-1, 1); + $one_after = substr($str, $start+$current+1, 1); + + if ( ! in_array($one_after, $space, TRUE)) + { + $str = str_replace( $one_before.'"'.$one_after, + $one_before."“".$one_after, + $str); + } + elseif( ! in_array($one_before, $space, TRUE)) + { + $str = str_replace( $one_before."'".$one_after, + $one_before."”".$one_after, + $str); + } + + $start = $start+$current+2; + } + + $start = 0; + + while(TRUE) + { + $current = strpos(substr($str, $start), "'"); + + if ($current === FALSE) break; + + $one_before = substr($str, $start+$current-1, 1); + $one_after = substr($str, $start+$current+1, 1); + + if ( ! in_array($one_after, $space, TRUE)) + { + $str = str_replace( $one_before."'".$one_after, + $one_before."‘".$one_after, + $str); + } + elseif( ! in_array($one_before, $space, TRUE)) + { + $str = str_replace( $one_before."'".$one_after, + $one_before."’".$one_after, + $str); + } + + $start = $start+$current+2; + } + + return $str; + } + + // -------------------------------------------------------------------- + + /** + * Format Newlines + * + * Converts newline characters into either

    tags or
    + * + */ + function format_newlines($str) + { + if ($str == '') + { + return $str; + } + + if (strpos($str, "\n") === FALSE) + { + return '

    '.$str.'

    '; + } + + $str = str_replace("\n\n", "

    \n\n

    ", $str); + $str = preg_replace("/([^\n])(\n)([^\n])/", "\\1
    \\2\\3", $str); + + return '

    '.$str.'

    '; + } +} + + ?> \ No newline at end of file diff --git a/system/helpers/url_helper.php b/system/helpers/url_helper.php index baac0e5d8..c05bc2088 100644 --- a/system/helpers/url_helper.php +++ b/system/helpers/url_helper.php @@ -1,12 +1,12 @@ ","\"", "'", "-"), - array("&", "<", ">", """, "'", "-"), - $str); - - // Decode the temp markers back to entities - $str = preg_replace("/$temp(\d+);/","&#\\1;",$str); - $str = preg_replace("/$temp(\w+);/","&\\1;", $str); - - return $str; -} - - +","\"", "'", "-"), + array("&", "<", ">", """, "'", "-"), + $str); + + // Decode the temp markers back to entities + $str = preg_replace("/$temp(\d+);/","&#\\1;",$str); + $str = preg_replace("/$temp(\w+);/","&\\1;", $str); + + return $str; +} + + ?> \ No newline at end of file diff --git a/system/libraries/Benchmark.php b/system/libraries/Benchmark.php index 66e8a24cf..cf980a81e 100644 --- a/system/libraries/Benchmark.php +++ b/system/libraries/Benchmark.php @@ -1,111 +1,111 @@ -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}'; - } - -} - -// END CI_Benchmark class +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}'; + } + +} + +// END CI_Benchmark class ?> \ No newline at end of file diff --git a/system/libraries/Calendar.php b/system/libraries/Calendar.php index fdef5dd75..ef6a3f841 100644 --- a/system/libraries/Calendar.php +++ b/system/libraries/Calendar.php @@ -1,475 +1,475 @@ -CI =& get_instance(); - - if ( ! in_array('calendar_lang'.EXT, $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)]; - } - } - } - } - -} - -// END CI_Calendar class +CI =& get_instance(); + + if ( ! in_array('calendar_lang'.EXT, $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)]; + } + } + } + } + +} + +// END CI_Calendar class ?> \ No newline at end of file diff --git a/system/libraries/Config.php b/system/libraries/Config.php index 28409fbc4..831ba925d 100644 --- a/system/libraries/Config.php +++ b/system/libraries/Config.php @@ -1,245 +1,245 @@ -config =& get_config(); - log_message('debug', "Config Class Initialized"); - } - - // -------------------------------------------------------------------- - - /** - * Load Config File - * - * @access public - * @param string the config file name - * @return boolean if the file was loaded correctly - */ - function load($file = '', $use_sections = FALSE, $fail_gracefully = FALSE) - { - $file = ($file == '') ? 'config' : str_replace(EXT, '', $file); - - if (in_array($file, $this->is_loaded, TRUE)) - { - return TRUE; - } - - if ( ! file_exists(APPPATH.'config/'.$file.EXT)) - { - if ($fail_gracefully === TRUE) - { - return FALSE; - } - show_error('The configuration file '.$file.EXT.' does not exist.'); - } - - include(APPPATH.'config/'.$file.EXT); - - if ( ! isset($config) OR ! is_array($config)) - { - if ($fail_gracefully === TRUE) - { - return FALSE; - } - show_error('Your '.$file.EXT.' 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; - unset($config); - - log_message('debug', 'Config file loaded: config/'.$file.EXT); - 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 - * - * The second parameter allows a slash to be added to the end of - * the item, in the case of a path. - * - * @access public - * @param string the config item name - * @param bool - * @return string - */ - function slash_item($item) - { - if ( ! isset($this->config[$item])) - { - return FALSE; - } - - $pref = $this->config[$item]; - - if ($pref != '') - { - if (ereg("/$", $pref) === FALSE) - { - $pref .= '/'; - } - } - - return $pref; - } - - // -------------------------------------------------------------------- - - /** - * Site URL - * - * @access public - * @param string the URI string - * @return string - */ - function site_url($uri = '') - { - if (is_array($uri)) - { - $uri = implode('/', $uri); - } - - if ($uri == '') - { - return $this->slash_item('base_url').$this->item('index_page'); - } - else - { - $suffix = ($this->item('url_suffix') == FALSE) ? '' : $this->item('url_suffix'); - return $this->slash_item('base_url').$this->slash_item('index_page').preg_replace("|^/*(.+?)/*$|", "\\1", $uri).$suffix; - } - } - - // -------------------------------------------------------------------- - - /** - * 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; - } - -} - -// END CI_Config class +config =& get_config(); + log_message('debug', "Config Class Initialized"); + } + + // -------------------------------------------------------------------- + + /** + * Load Config File + * + * @access public + * @param string the config file name + * @return boolean if the file was loaded correctly + */ + function load($file = '', $use_sections = FALSE, $fail_gracefully = FALSE) + { + $file = ($file == '') ? 'config' : str_replace(EXT, '', $file); + + if (in_array($file, $this->is_loaded, TRUE)) + { + return TRUE; + } + + if ( ! file_exists(APPPATH.'config/'.$file.EXT)) + { + if ($fail_gracefully === TRUE) + { + return FALSE; + } + show_error('The configuration file '.$file.EXT.' does not exist.'); + } + + include(APPPATH.'config/'.$file.EXT); + + if ( ! isset($config) OR ! is_array($config)) + { + if ($fail_gracefully === TRUE) + { + return FALSE; + } + show_error('Your '.$file.EXT.' 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; + unset($config); + + log_message('debug', 'Config file loaded: config/'.$file.EXT); + 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 + * + * The second parameter allows a slash to be added to the end of + * the item, in the case of a path. + * + * @access public + * @param string the config item name + * @param bool + * @return string + */ + function slash_item($item) + { + if ( ! isset($this->config[$item])) + { + return FALSE; + } + + $pref = $this->config[$item]; + + if ($pref != '') + { + if (ereg("/$", $pref) === FALSE) + { + $pref .= '/'; + } + } + + return $pref; + } + + // -------------------------------------------------------------------- + + /** + * Site URL + * + * @access public + * @param string the URI string + * @return string + */ + function site_url($uri = '') + { + if (is_array($uri)) + { + $uri = implode('/', $uri); + } + + if ($uri == '') + { + return $this->slash_item('base_url').$this->item('index_page'); + } + else + { + $suffix = ($this->item('url_suffix') == FALSE) ? '' : $this->item('url_suffix'); + return $this->slash_item('base_url').$this->slash_item('index_page').preg_replace("|^/*(.+?)/*$|", "\\1", $uri).$suffix; + } + } + + // -------------------------------------------------------------------- + + /** + * 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; + } + +} + +// END CI_Config class ?> \ No newline at end of file diff --git a/system/libraries/Controller.php b/system/libraries/Controller.php index c8fa646c7..81421cf31 100644 --- a/system/libraries/Controller.php +++ b/system/libraries/Controller.php @@ -1,115 +1,115 @@ -_ci_initialize(); - log_message('debug', "Controller Class Initialized"); - } - - // -------------------------------------------------------------------- - - /** - * Initialize - * - * Assigns all the bases classes loaded by the front controller to - * variables in this class. Also calls the autoload routine. - * - * @access private - * @return void - */ - function _ci_initialize() - { - // Assign all the class objects that were instantiated by the - // front controller to local class variables so that CI can be - // run as one big super object. - $classes = array( - 'config' => 'Config', - 'input' => 'Input', - 'benchmark' => 'Benchmark', - 'uri' => 'URI', - 'output' => 'Output', - 'lang' => 'Language' - ); - - foreach ($classes as $var => $class) - { - $this->$var =& load_class($class); - } - - // In PHP 5 the Loader class is run as a discreet - // class. In PHP 4 it extends the Controller - if (floor(phpversion()) >= 5) - { - $this->load =& load_class('Loader'); - $this->load->_ci_autoloader(); - } - else - { - $this->_ci_autoloader(); - } - } - - // -------------------------------------------------------------------- - - /** - * Run Scaffolding - * - * @access private - * @return void - */ - function _ci_scaffolding() - { - if ($this->_ci_scaffolding === FALSE OR $this->_ci_scaff_table === FALSE) - { - show_404('Scaffolding unavailable'); - } - - $method = ( ! in_array($this->uri->segment(3), array('add', 'insert', 'edit', 'update', 'view', 'delete', 'do_delete'), TRUE)) ? 'view' : $this->uri->segment(3); - - require_once(BASEPATH.'scaffolding/Scaffolding'.EXT); - $scaff = new Scaffolding($this->_ci_scaff_table); - $scaff->$method(); - } - - -} -// END _Controller class +_ci_initialize(); + log_message('debug', "Controller Class Initialized"); + } + + // -------------------------------------------------------------------- + + /** + * Initialize + * + * Assigns all the bases classes loaded by the front controller to + * variables in this class. Also calls the autoload routine. + * + * @access private + * @return void + */ + function _ci_initialize() + { + // Assign all the class objects that were instantiated by the + // front controller to local class variables so that CI can be + // run as one big super object. + $classes = array( + 'config' => 'Config', + 'input' => 'Input', + 'benchmark' => 'Benchmark', + 'uri' => 'URI', + 'output' => 'Output', + 'lang' => 'Language' + ); + + foreach ($classes as $var => $class) + { + $this->$var =& load_class($class); + } + + // In PHP 5 the Loader class is run as a discreet + // class. In PHP 4 it extends the Controller + if (floor(phpversion()) >= 5) + { + $this->load =& load_class('Loader'); + $this->load->_ci_autoloader(); + } + else + { + $this->_ci_autoloader(); + } + } + + // -------------------------------------------------------------------- + + /** + * Run Scaffolding + * + * @access private + * @return void + */ + function _ci_scaffolding() + { + if ($this->_ci_scaffolding === FALSE OR $this->_ci_scaff_table === FALSE) + { + show_404('Scaffolding unavailable'); + } + + $method = ( ! in_array($this->uri->segment(3), array('add', 'insert', 'edit', 'update', 'view', 'delete', 'do_delete'), TRUE)) ? 'view' : $this->uri->segment(3); + + require_once(BASEPATH.'scaffolding/Scaffolding'.EXT); + $scaff = new Scaffolding($this->_ci_scaff_table); + $scaff->$method(); + } + + +} +// END _Controller class ?> \ No newline at end of file diff --git a/system/libraries/Email.php b/system/libraries/Email.php index e6dd614f4..a8acec674 100644 --- a/system/libraries/Email.php +++ b/system/libraries/Email.php @@ -1,1719 +1,1719 @@ - 0) - { - $this->initialize($config); - } - - log_message('debug', "Email Class Initialized"); - } - - // -------------------------------------------------------------------- - - /** - * Initialize preferences - * - * @access public - * @param array - * @return void - */ - function initialize($config = array()) - { - $this->clear(); - 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->_smtp_auth = ($this->smtp_user == '' AND $this->smtp_pass == '') ? FALSE : TRUE; - $this->_safe_mode = (@ini_get("safe_mode") == 0) ? FALSE : TRUE; - } - - // -------------------------------------------------------------------- - - /** - * Initialize the Email Data - * - * @access public - * @return void - */ - function clear($clear_attachments = FALSE) - { - $this->_subject = ""; - $this->_body = ""; - $this->_finalbody = ""; - $this->_header_str = ""; - $this->_replyto_flag = FALSE; - $this->_recipients = 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(); - } - } - - // -------------------------------------------------------------------- - - /** - * Set FROM - * - * @access public - * @param string - * @param string - * @return void - */ - function from($from, $name = '') - { - if (preg_match( '/\<(.*)\>/', $from, $match)) - $from = $match['1']; - - if ($this->validate) - $this->validate_email($this->_str_to_array($from)); - - if ($name != '' && substr($name, 0, 1) != '"') - { - $name = '"'.$name.'"'; - } - - $this->_set_header('From', $name.' <'.$from.'>'); - $this->_set_header('Return-Path', '<'.$from.'>'); - } - - // -------------------------------------------------------------------- - - /** - * Set Reply-to - * - * @access public - * @param string - * @param string - * @return void - */ - 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 (substr($name, 0, 1) != '"') - { - $name = '"'.$name.'"'; - } - - $this->_set_header('Reply-To', $name.' <'.$replyto.'>'); - $this->_replyto_flag = TRUE; - } - - // -------------------------------------------------------------------- - - /** - * Set Recipients - * - * @access public - * @param string - * @return void - */ - 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' : $this->_recipients = implode(", ", $to); - break; - case 'mail' : $this->_recipients = implode(", ", $to); - break; - } - } - - // -------------------------------------------------------------------- - - /** - * Set CC - * - * @access public - * @param string - * @return void - */ - 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; - } - - // -------------------------------------------------------------------- - - /** - * Set BCC - * - * @access public - * @param string - * @param string - * @return void - */ - 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)); - } - - // -------------------------------------------------------------------- - - /** - * Set Email Subject - * - * @access public - * @param string - * @return void - */ - function subject($subject) - { - $subject = preg_replace("/(\r\n)|(\r)|(\n)/", "", $subject); - $subject = preg_replace("/(\t)/", " ", $subject); - - $this->_set_header('Subject', trim($subject)); - } - - // -------------------------------------------------------------------- - - /** - * Set Body - * - * @access public - * @param string - * @return void - */ - function message($body) - { - $this->_body = stripslashes(rtrim(str_replace("\r", "", $body))); - } - - // -------------------------------------------------------------------- - - /** - * Assign file attachments - * - * @access public - * @param string - * @return string - */ - function attach($filename, $disposition = 'attachment') - { - $this->_attach_name[] = $filename; - $this->_attach_type[] = $this->_mime_types(next(explode('.', basename($filename)))); - $this->_attach_disp[] = $disposition; // Can also be 'inline' Not sure if it matters - } - - // -------------------------------------------------------------------- - - /** - * Add a Header Item - * - * @access public - * @param string - * @param string - * @return void - */ - function _set_header($header, $value) - { - $this->_headers[$header] = $value; - } - - // -------------------------------------------------------------------- - - /** - * Convert a String to an Array - * - * @access public - * @param string - * @return array - */ - function _str_to_array($email) - { - if ( ! is_array($email)) - { - if (ereg(',$', $email)) - $email = substr($email, 0, -1); - - if (ereg('^,', $email)) - $email = substr($email, 1); - - if (ereg(',', $email)) - { - $x = explode(',', $email); - $email = array(); - - for ($i = 0; $i < count($x); $i ++) - $email[] = trim($x[$i]); - } - else - { - $email = trim($email); - settype($email, "array"); - } - } - return $email; - } - - // -------------------------------------------------------------------- - - /** - * Set Multipart Value - * - * @access public - * @param string - * @return void - */ - function set_alt_message($str = '') - { - $this->alt_message = ($str == '') ? '' : $str; - } - - // -------------------------------------------------------------------- - - /** - * Set Mailtype - * - * @access public - * @param string - * @return void - */ - function set_mailtype($type = 'text') - { - $this->mailtype = ($type == 'html') ? 'html' : 'text'; - } - - // -------------------------------------------------------------------- - - /** - * Set Wordwrap - * - * @access public - * @param string - * @return void - */ - function set_wordwrap($wordwrap = TRUE) - { - $this->wordwrap = ($wordwrap === FALSE) ? FALSE : TRUE; - } - - // -------------------------------------------------------------------- - - /** - * Set Protocol - * - * @access public - * @param string - * @return void - */ - function set_protocol($protocol = 'mail') - { - $this->protocol = ( ! in_array($protocol, $this->_protocols, TRUE)) ? 'mail' : strtolower($protocol); - } - - // -------------------------------------------------------------------- - - /** - * Set Priority - * - * @access public - * @param integer - * @return void - */ - 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; - } - - // -------------------------------------------------------------------- - - /** - * Set Newline Character - * - * @access public - * @param string - * @return void - */ - function set_newline($newline = "\n") - { - if ($newline != "\n" OR $newline != "\r\n" OR $newline != "\r") - { - $this->newline = "\n"; - return; - } - - $this->newline = $newline; - } - - // -------------------------------------------------------------------- - - /** - * Set Message Boundary - * - * @access private - * @return void - */ - function _set_boundaries() - { - $this->_alt_boundary = "B_ALT_".uniqid(''); // multipart/alternative - $this->_atc_boundary = "B_ATC_".uniqid(''); // attachment boundary - } - - // -------------------------------------------------------------------- - - /** - * Get the Message ID - * - * @access private - * @return string - */ - 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 private - * @param bool - * @return string - */ - 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 private - * @param bool - * @return string - */ - function _get_encoding($return = true) - { - $this->_encoding = ( ! in_array($this->_encoding, $this->_bit_depths)) ? '7bit' : $this->_encoding; - - if ( ! in_array($this->charset, $this->_base_charsets, TRUE)) - $this->_encoding = "8bit"; - - if ($return == true) - return $this->_encoding; - } - - // -------------------------------------------------------------------- - - /** - * Get content type (text/html/attachment) - * - * @access private - * @return string - */ - 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 public - * @return string - */ - function _set_date() - { - $timezone = date("Z"); - $operator = (substr($timezone, 0, 1) == '-') ? '-' : '+'; - $timezone = abs($timezone); - $timezone = ($timezone/3600) * 100 + ($timezone % 3600) /60; - - return sprintf("%s %s%04d", date("D, j M Y H:i:s"), $operator, $timezone); - } - - // -------------------------------------------------------------------- - - /** - * Mime message - * - * @access private - * @return string - */ - 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 - */ - function validate_email($email) - { - if ( ! is_array($email)) - { - $this->_set_error_message('email_must_be_array'); - return FALSE; - } - - foreach ($email as $val) - { - if ( ! $this->valid_email($val)) - { - $this->_set_error_message('email_invalid_address', $val); - return FALSE; - } - } - } - - // -------------------------------------------------------------------- - - /** - * Email Validation - * - * @access public - * @param string - * @return bool - */ - function valid_email($address) - { - if ( ! preg_match("/^([a-z0-9\+_\-]+)(\.[a-z0-9\+_\-]+)*@([a-z0-9\-]+\.)+[a-z]{2,6}$/ix", $address)) - return FALSE; - else - return TRUE; - } - - // -------------------------------------------------------------------- - - /** - * Clean Extended Email Address: Joe Smith - * - * @access public - * @param string - * @return string - */ - function clean_email($email) - { - if ( ! is_array($email)) - { - if (preg_match('/\<(.*)\>/', $email, $match)) - return $match['1']; - else - return $email; - } - - $clean_email = array(); - - for ($i=0; $i < count($email); $i++) - { - if (preg_match( '/\<(.*)\>/', $email[$i], $match)) - $clean_email[] = $match['1']; - else - $clean_email[] = $email[$i]; - } - - return $clean_email; - } - - // -------------------------------------------------------------------- - - /** - * Build alternative plain text message - * - * This 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 private - * @return string - */ - function _get_alt_message() - { - if ($this->alt_message != "") - { - return $this->word_wrap($this->alt_message, '76'); - } - - if (eregi( '\', $this->_body, $match)) - { - $body = $match['1']; - $body = substr($body, strpos($body, ">") + 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, 0666); - return TRUE; - } - -} -// END Log Class + '1', 'DEBUG' => '2', 'INFO' => '3', 'ALL' => '4'); + + /** + * Constructor + * + * @access public + * @param string the log file path + * @param string the error threshold + * @param string the date formatting codes + */ + function CI_Log() + { + $config =& get_config(); + + $this->log_path = ($config['log_path'] != '') ? $config['log_path'] : BASEPATH.'logs/'; + + if ( ! is_dir($this->log_path) OR ! is_writable($this->log_path)) + { + $this->_enabled = FALSE; + } + + if (is_numeric($config['log_threshold'])) + { + $this->_threshold = $config['log_threshold']; + } + + if ($config['log_date_format'] != '') + { + $this->_date_fmt = $config['log_date_format']; + } + } + + // -------------------------------------------------------------------- + + /** + * Write Log File + * + * Generally this function will be called using the global log_message() function + * + * @access public + * @param string the error level + * @param string the error message + * @param bool whether the error is a native PHP error + * @return bool + */ + function write_log($level = 'error', $msg, $php_error = FALSE) + { + if ($this->_enabled === FALSE) + { + return FALSE; + } + + $level = strtoupper($level); + + if ( ! isset($this->_levels[$level]) OR ($this->_levels[$level] > $this->_threshold)) + { + return FALSE; + } + + $filepath = $this->log_path.'log-'.date('Y-m-d').EXT; + $message = ''; + + if ( ! file_exists($filepath)) + { + $message .= "<"."?php if (!defined('BASEPATH')) exit('No direct script access allowed'); ?".">\n\n"; + } + + if ( ! $fp = @fopen($filepath, "a")) + { + return FALSE; + } + + $message .= $level.' '.(($level == 'INFO') ? ' -' : '-').' '.date($this->_date_fmt). ' --> '.$msg."\n"; + + flock($fp, LOCK_EX); + fwrite($fp, $message); + flock($fp, LOCK_UN); + fclose($fp); + + @chmod($filepath, 0666); + return TRUE; + } + +} +// END Log Class ?> \ No newline at end of file diff --git a/system/libraries/Model.php b/system/libraries/Model.php index 6f4f7e7ef..3b4c2e144 100644 --- a/system/libraries/Model.php +++ b/system/libraries/Model.php @@ -1,82 +1,82 @@ -_assign_libraries( (method_exists($this, '__get') OR method_exists($this, '__set')) ? FALSE : TRUE ); - - // We don't want to assign the model object to itself when using the - // assign_libraries function below so we'll grab the name of the model parent - $this->_parent_name = ucfirst(get_class($this)); - - log_message('debug', "Model Class Initialized"); - } - - /** - * Assign Libraries - * - * Creates local references to all currently instantiated objects - * so that any syntax that can be legally used in a controller - * can be used within models. - * - * @access private - */ - function _assign_libraries($use_reference = TRUE) - { - $CI =& get_instance(); - foreach (array_keys(get_object_vars($CI)) as $key) - { - if ( ! isset($this->$key) AND $key != $this->_parent_name) - { - // In some cases using references can cause - // problems so we'll conditionally use them - if ($use_reference == TRUE) - { - // Needed to prevent reference errors with some configurations - $this->$key = ''; - $this->$key =& $CI->$key; - } - else - { - $this->$key = $CI->$key; - } - } - } - } - -} -// END Model Class +_assign_libraries( (method_exists($this, '__get') OR method_exists($this, '__set')) ? FALSE : TRUE ); + + // We don't want to assign the model object to itself when using the + // assign_libraries function below so we'll grab the name of the model parent + $this->_parent_name = ucfirst(get_class($this)); + + log_message('debug', "Model Class Initialized"); + } + + /** + * Assign Libraries + * + * Creates local references to all currently instantiated objects + * so that any syntax that can be legally used in a controller + * can be used within models. + * + * @access private + */ + function _assign_libraries($use_reference = TRUE) + { + $CI =& get_instance(); + foreach (array_keys(get_object_vars($CI)) as $key) + { + if ( ! isset($this->$key) AND $key != $this->_parent_name) + { + // In some cases using references can cause + // problems so we'll conditionally use them + if ($use_reference == TRUE) + { + // Needed to prevent reference errors with some configurations + $this->$key = ''; + $this->$key =& $CI->$key; + } + else + { + $this->$key = $CI->$key; + } + } + } + } + +} +// END Model Class ?> \ No newline at end of file diff --git a/system/libraries/Output.php b/system/libraries/Output.php index e53627408..743228e53 100644 --- a/system/libraries/Output.php +++ b/system/libraries/Output.php @@ -1,364 +1,364 @@ -final_output; - } - - // -------------------------------------------------------------------- - - /** - * Set Output - * - * Sets the output string - * - * @access public - * @param string - * @return void - */ - function set_output($output) - { - $this->final_output = $output; - } - - // -------------------------------------------------------------------- - - /** - * 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 - * @return void - */ - function set_header($header) - { - $this->headers[] = $header; - } - - // -------------------------------------------------------------------- - - /** - * Enable/disable Profiler - * - * @access public - * @param bool - * @return void - */ - function enable_profiler($val = TRUE) - { - $this->enable_profiler = (is_bool($val)) ? $val : TRUE; - } - - // -------------------------------------------------------------------- - - /** - * Set Cache - * - * @access public - * @param integer - * @return void - */ - function cache($time) - { - $this->cache_expiration = ( ! is_numeric($time)) ? 0 : $time; - } - - // -------------------------------------------------------------------- - - /** - * 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 - * @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; - - // -------------------------------------------------------------------- - - // Set the output data - if ($output == '') - { - $output =& $this->final_output; - } - - // -------------------------------------------------------------------- - - // Do we need to write a cache file? - if ($this->cache_expiration > 0) - { - $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'); - $output = str_replace('{elapsed_time}', $elapsed, $output); - - $memory = ( ! function_exists('memory_get_usage')) ? '0' : round(memory_get_usage()/1024/1024, 2).'MB'; - $output = str_replace('{memory_usage}', $memory, $output); - - // -------------------------------------------------------------------- - - // Is compression requested? - if ($CFG->item('compress_output') === TRUE) - { - 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); - } - } - - // -------------------------------------------------------------------- - - // Does the get_instance() function exist? - // If not we know we are dealing with a cache file so we'll - // simply echo out the data and exit. - if ( ! function_exists('get_instance')) - { - echo $output; - log_message('debug', "Final output sent to browser"); - log_message('debug', "Total execution time: ".$elapsed); - return TRUE; - } - - // -------------------------------------------------------------------- - - // Grab the super object. We'll need it in a moment... - $CI =& get_instance(); - - // 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 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 - * @return void - */ - function _write_cache($output) - { - $CI =& get_instance(); - $path = $CI->config->item('cache_path'); - - $cache_path = ($path == '') ? BASEPATH.'cache/' : $path; - - if ( ! is_dir($cache_path) OR ! is_writable($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, 'wb')) - { - log_message('error', "Unable to write ache file: ".$cache_path); - return; - } - - $expire = time() + ($this->cache_expiration * 60); - - flock($fp, LOCK_EX); - fwrite($fp, $expire.'TS--->'.$output); - flock($fp, LOCK_UN); - fclose($fp); - @chmod($cache_path, 0777); - - log_message('debug', "Cache file written: ".$cache_path); - } - - // -------------------------------------------------------------------- - - /** - * Update/serve a cached file - * - * @access public - * @return void - */ - function _display_cache(&$CFG, &$RTR) - { - $CFG =& load_class('Config'); - $RTR =& load_class('Router'); - - $cache_path = ($CFG->item('cache_path') == '') ? BASEPATH.'cache/' : $CFG->item('cache_path'); - - if ( ! is_dir($cache_path) OR ! is_writable($cache_path)) - { - return FALSE; - } - - // Build the file path. The file name is an MD5 hash of the full URI - $uri = $CFG->item('base_url'). - $CFG->item('index_page'). - $RTR->uri_string; - - $filepath = $cache_path.md5($uri); - - if ( ! @file_exists($filepath)) - { - return FALSE; - } - - if ( ! $fp = @fopen($filepath, 'rb')) - { - 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']))) - { - @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; - } - - -} -// END Output Class +final_output; + } + + // -------------------------------------------------------------------- + + /** + * Set Output + * + * Sets the output string + * + * @access public + * @param string + * @return void + */ + function set_output($output) + { + $this->final_output = $output; + } + + // -------------------------------------------------------------------- + + /** + * 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 + * @return void + */ + function set_header($header) + { + $this->headers[] = $header; + } + + // -------------------------------------------------------------------- + + /** + * Enable/disable Profiler + * + * @access public + * @param bool + * @return void + */ + function enable_profiler($val = TRUE) + { + $this->enable_profiler = (is_bool($val)) ? $val : TRUE; + } + + // -------------------------------------------------------------------- + + /** + * Set Cache + * + * @access public + * @param integer + * @return void + */ + function cache($time) + { + $this->cache_expiration = ( ! is_numeric($time)) ? 0 : $time; + } + + // -------------------------------------------------------------------- + + /** + * 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 + * @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; + + // -------------------------------------------------------------------- + + // Set the output data + if ($output == '') + { + $output =& $this->final_output; + } + + // -------------------------------------------------------------------- + + // Do we need to write a cache file? + if ($this->cache_expiration > 0) + { + $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'); + $output = str_replace('{elapsed_time}', $elapsed, $output); + + $memory = ( ! function_exists('memory_get_usage')) ? '0' : round(memory_get_usage()/1024/1024, 2).'MB'; + $output = str_replace('{memory_usage}', $memory, $output); + + // -------------------------------------------------------------------- + + // Is compression requested? + if ($CFG->item('compress_output') === TRUE) + { + 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); + } + } + + // -------------------------------------------------------------------- + + // Does the get_instance() function exist? + // If not we know we are dealing with a cache file so we'll + // simply echo out the data and exit. + if ( ! function_exists('get_instance')) + { + echo $output; + log_message('debug', "Final output sent to browser"); + log_message('debug', "Total execution time: ".$elapsed); + return TRUE; + } + + // -------------------------------------------------------------------- + + // Grab the super object. We'll need it in a moment... + $CI =& get_instance(); + + // 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 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 + * @return void + */ + function _write_cache($output) + { + $CI =& get_instance(); + $path = $CI->config->item('cache_path'); + + $cache_path = ($path == '') ? BASEPATH.'cache/' : $path; + + if ( ! is_dir($cache_path) OR ! is_writable($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, 'wb')) + { + log_message('error', "Unable to write ache file: ".$cache_path); + return; + } + + $expire = time() + ($this->cache_expiration * 60); + + flock($fp, LOCK_EX); + fwrite($fp, $expire.'TS--->'.$output); + flock($fp, LOCK_UN); + fclose($fp); + @chmod($cache_path, 0777); + + log_message('debug', "Cache file written: ".$cache_path); + } + + // -------------------------------------------------------------------- + + /** + * Update/serve a cached file + * + * @access public + * @return void + */ + function _display_cache(&$CFG, &$RTR) + { + $CFG =& load_class('Config'); + $RTR =& load_class('Router'); + + $cache_path = ($CFG->item('cache_path') == '') ? BASEPATH.'cache/' : $CFG->item('cache_path'); + + if ( ! is_dir($cache_path) OR ! is_writable($cache_path)) + { + return FALSE; + } + + // Build the file path. The file name is an MD5 hash of the full URI + $uri = $CFG->item('base_url'). + $CFG->item('index_page'). + $RTR->uri_string; + + $filepath = $cache_path.md5($uri); + + if ( ! @file_exists($filepath)) + { + return FALSE; + } + + if ( ! $fp = @fopen($filepath, 'rb')) + { + 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']))) + { + @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; + } + + +} +// END Output Class ?> \ No newline at end of file diff --git a/system/libraries/Pagination.php b/system/libraries/Pagination.php index 07ad6a683..27104c95c 100644 --- a/system/libraries/Pagination.php +++ b/system/libraries/Pagination.php @@ -1,211 +1,211 @@ -'; - 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 = ''; - - /** - * Constructor - * - * @access public - * @param array initialization parameters - */ - function CI_Pagination($params = array()) - { - if (count($params) > 0) - { - $this->initialize($params); - } - - 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 ''; - } - - // Determine the current page number. - $CI =& get_instance(); - if ($CI->uri->segment($this->uri_segment) != 0) - { - $this->cur_page = $CI->uri->segment($this->uri_segment); - - // Prep the current page - no funny business! - $this->cur_page = preg_replace("/[a-z\-]/", "", $this->cur_page); - } - - if ( ! is_numeric($this->cur_page)) - { - $this->cur_page = 0; - } - - // Is the page number beyond the result range? - // If so we show the last page - if ($this->cur_page > $this->total_rows) - { - $this->cur_page = ($num_pages - 1) * $this->per_page; - } - - $uri_page_number = $this->cur_page; - $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; - - // Add a trailing slash to the base URL if needed - $this->base_url = preg_replace("/(.+?)\/*$/", "\\1/", $this->base_url); - - // And here we go... - $output = ''; - - // Render the "First" link - if ($this->cur_page > $this->num_links) - { - $output .= $this->first_tag_open.''.$this->first_link.''.$this->first_tag_close; - } - - // Render the "previous" link - if (($this->cur_page - $this->num_links) >= 0) - { - $i = $uri_page_number - $this->per_page; - if ($i == 0) $i = ''; - $output .= $this->prev_tag_open.''.$this->prev_link.''.$this->prev_tag_close; - } - - // Write the digit links - for ($loop = $start -1; $loop <= $end; $loop++) - { - $i = ($loop * $this->per_page) - $this->per_page; - - if ($i >= 0) - { - if ($this->cur_page == $loop) - { - $output .= $this->cur_tag_open.$loop.$this->cur_tag_close; // Current page - } - else - { - $n = ($i == 0) ? '' : $i; - $output .= $this->num_tag_open.''.$loop.''.$this->num_tag_close; - } - } - } - - // Render the "next" link - if ($this->cur_page < $num_pages) - { - $output .= $this->next_tag_open.''.$this->next_link.''.$this->next_tag_close; - } - - // Render the "Last" link - if (($this->cur_page + $this->num_links) < $num_pages) - { - $i = (($num_pages * $this->per_page) - $this->per_page); - $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 - $output = $this->full_tag_open.$output.$this->full_tag_close; - - return $output; - } -} -// END Pagination Class +'; + 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 = ''; + + /** + * Constructor + * + * @access public + * @param array initialization parameters + */ + function CI_Pagination($params = array()) + { + if (count($params) > 0) + { + $this->initialize($params); + } + + 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 ''; + } + + // Determine the current page number. + $CI =& get_instance(); + if ($CI->uri->segment($this->uri_segment) != 0) + { + $this->cur_page = $CI->uri->segment($this->uri_segment); + + // Prep the current page - no funny business! + $this->cur_page = preg_replace("/[a-z\-]/", "", $this->cur_page); + } + + if ( ! is_numeric($this->cur_page)) + { + $this->cur_page = 0; + } + + // Is the page number beyond the result range? + // If so we show the last page + if ($this->cur_page > $this->total_rows) + { + $this->cur_page = ($num_pages - 1) * $this->per_page; + } + + $uri_page_number = $this->cur_page; + $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; + + // Add a trailing slash to the base URL if needed + $this->base_url = preg_replace("/(.+?)\/*$/", "\\1/", $this->base_url); + + // And here we go... + $output = ''; + + // Render the "First" link + if ($this->cur_page > $this->num_links) + { + $output .= $this->first_tag_open.''.$this->first_link.''.$this->first_tag_close; + } + + // Render the "previous" link + if (($this->cur_page - $this->num_links) >= 0) + { + $i = $uri_page_number - $this->per_page; + if ($i == 0) $i = ''; + $output .= $this->prev_tag_open.''.$this->prev_link.''.$this->prev_tag_close; + } + + // Write the digit links + for ($loop = $start -1; $loop <= $end; $loop++) + { + $i = ($loop * $this->per_page) - $this->per_page; + + if ($i >= 0) + { + if ($this->cur_page == $loop) + { + $output .= $this->cur_tag_open.$loop.$this->cur_tag_close; // Current page + } + else + { + $n = ($i == 0) ? '' : $i; + $output .= $this->num_tag_open.''.$loop.''.$this->num_tag_close; + } + } + } + + // Render the "next" link + if ($this->cur_page < $num_pages) + { + $output .= $this->next_tag_open.''.$this->next_link.''.$this->next_tag_close; + } + + // Render the "Last" link + if (($this->cur_page + $this->num_links) < $num_pages) + { + $i = (($num_pages * $this->per_page) - $this->per_page); + $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 + $output = $this->full_tag_open.$output.$this->full_tag_close; + + return $output; + } +} +// END Pagination Class ?> \ No newline at end of file diff --git a/system/libraries/Parser.php b/system/libraries/Parser.php index 760d5d4d3..613668ac8 100644 --- a/system/libraries/Parser.php +++ b/system/libraries/Parser.php @@ -1,171 +1,171 @@ -load->view($template, $data, TRUE); - - if ($template == '') - { - return FALSE; - } - - foreach ($data as $key => $val) - { - if (is_string($val)) - { - $template = $this->_parse_single($key, $val, $template); - } - elseif (is_array($val)) - { - $template = $this->_parse_pair($key, $val, $template); - } - } - - if ($return == FALSE) - { - $CI->output->final_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("|".$this->l_delim . $variable . $this->r_delim."(.+)".$this->l_delim . '/' . $variable . $this->r_delim."|s", $string, $match)) - { - return FALSE; - } - - return $match; - } - -} -// END Parser Class +load->view($template, $data, TRUE); + + if ($template == '') + { + return FALSE; + } + + foreach ($data as $key => $val) + { + if (is_string($val)) + { + $template = $this->_parse_single($key, $val, $template); + } + elseif (is_array($val)) + { + $template = $this->_parse_pair($key, $val, $template); + } + } + + if ($return == FALSE) + { + $CI->output->final_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("|".$this->l_delim . $variable . $this->r_delim."(.+)".$this->l_delim . '/' . $variable . $this->r_delim."|s", $string, $match)) + { + return FALSE; + } + + return $match; + } + +} +// END Parser Class ?> \ No newline at end of file diff --git a/system/libraries/Profiler.php b/system/libraries/Profiler.php index 37b345184..cdc4f6fc9 100644 --- a/system/libraries/Profiler.php +++ b/system/libraries/Profiler.php @@ -1,12 +1,12 @@ CI =& get_instance(); - - log_message('debug', "Session Class Initialized"); - $this->sess_run(); - } - - // -------------------------------------------------------------------- - - /** - * Run the session routines - * - * @access public - * @return void - */ - function sess_run() - { - /* - * Set the "now" time - * - * It can either set to GMT or time(). The pref - * is set in the config file. If the developer - * is doing any sort of time localization they - * might want to set the session time to GMT so - * they can offset the "last_activity" and - * "last_visit" times based on each user's locale. - * - */ - if (strtolower($this->CI->config->item('time_reference')) == 'gmt') - { - $now = time(); - $this->now = mktime(gmdate("H", $now), gmdate("i", $now), gmdate("s", $now), gmdate("m", $now), gmdate("d", $now), gmdate("Y", $now)); - - if (strlen($this->now) < 10) - { - $this->now = time(); - log_message('error', 'The session class could not set a proper GMT timestamp so the local time() value was used.'); - } - } - else - { - $this->now = time(); - } - - /* - * Set the session length - * - * If the session expiration is set to zero in - * the config file we'll set the expiration - * two years from now. - * - */ - $expiration = $this->CI->config->item('sess_expiration'); - - if (is_numeric($expiration)) - { - if ($expiration > 0) - { - $this->sess_length = $this->CI->config->item('sess_expiration'); - } - else - { - $this->sess_length = (60*60*24*365*2); - } - } - - // Do we need encryption? - $this->encryption = $this->CI->config->item('sess_encrypt_cookie'); - - if ($this->encryption == TRUE) - { - $this->CI->load->library('encrypt'); - } - - // Are we using a database? - if ($this->CI->config->item('sess_use_database') === TRUE AND $this->CI->config->item('sess_table_name') != '') - { - $this->use_database = TRUE; - $this->session_table = $this->CI->config->item('sess_table_name'); - $this->CI->load->database(); - } - - // Set the cookie name - if ($this->CI->config->item('sess_cookie_name') != FALSE) - { - $this->sess_cookie = $this->CI->config->item('cookie_prefix').$this->CI->config->item('sess_cookie_name'); - } - - /* - * Fetch the current session - * - * 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 - { - // We only update the session every five minutes - if (($this->userdata['last_activity'] + 300) < $this->now) - { - $this->sess_update(); - } - } - - // Delete expired sessions if necessary - if ($this->use_database === TRUE) - { - $this->sess_gc(); - } - } - - // -------------------------------------------------------------------- - - /** - * Fetch the current session data if it exists - * - * @access public - * @return void - */ - function sess_read() - { - // Fetch the cookie - $session = $this->CI->input->cookie($this->sess_cookie); - - if ($session === FALSE) - { - log_message('debug', 'A session cookie was not found.'); - return FALSE; - } - - // Decrypt and unserialize the data - if ($this->encryption == TRUE) - { - $session = $this->CI->encrypt->decode($session); - } - - $session = @unserialize($this->strip_slashes($session)); - - if ( ! is_array($session) OR ! isset($session['last_activity'])) - { - log_message('error', 'The session cookie data did not contain a valid array. This could be a possible hacking attempt.'); - return FALSE; - } - - // Is the session current? - if (($session['last_activity'] + $this->sess_length) < $this->now) - { - $this->sess_destroy(); - return FALSE; - } - - // Does the IP Match? - if ($this->CI->config->item('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->CI->config->item('sess_match_useragent') == TRUE AND $session['user_agent'] != substr($this->CI->input->user_agent(), 0, 50)) - { - $this->sess_destroy(); - return FALSE; - } - - // Is there a corresponding session in the DB? - if ($this->use_database === TRUE) - { - $this->CI->db->where('session_id', $session['session_id']); - - if ($this->CI->config->item('sess_match_ip') == TRUE) - { - $this->CI->db->where('ip_address', $session['ip_address']); - } - - if ($this->CI->config->item('sess_match_useragent') == TRUE) - { - $this->CI->db->where('user_agent', $session['user_agent']); - } - - $query = $this->CI->db->get($this->session_table); - - if ($query->num_rows() == 0) - { - $this->sess_destroy(); - return FALSE; - } - else - { - $row = $query->row(); - if (($row->last_activity + $this->sess_length) < $this->now) - { - $this->CI->db->where('session_id', $session['session_id']); - $this->CI->db->delete($this->session_table); - $this->sess_destroy(); - return FALSE; - } - } - } - - // Session is valid! - $this->userdata = $session; - unset($session); - - return TRUE; - } - - // -------------------------------------------------------------------- - - /** - * Write the session cookie - * - * @access public - * @return void - */ - function sess_write() - { - $cookie_data = serialize($this->userdata); - - if ($this->encryption == TRUE) - { - $cookie_data = $this->CI->encrypt->encode($cookie_data); - } - - setcookie( - $this->sess_cookie, - $cookie_data, - $this->sess_length + time(), - $this->CI->config->item('cookie_path'), - $this->CI->config->item('cookie_domain'), - 0 - ); - } - - // -------------------------------------------------------------------- - - /** - * Create a new session - * - * @access public - * @return void - */ - function sess_create() - { - $sessid = ''; - while (strlen($sessid) < 32) - { - $sessid .= mt_rand(0, mt_getrandmax()); - } - - $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, 50), - 'last_activity' => $this->now - ); - - - // Save the session in the DB if needed - if ($this->use_database === TRUE) - { - $this->CI->db->query($this->CI->db->insert_string($this->session_table, $this->userdata)); - } - - // Write the cookie - $this->userdata['last_visit'] = 0; - $this->sess_write(); - } - - // -------------------------------------------------------------------- - - /** - * Update an existing session - * - * @access public - * @return void - */ - function sess_update() - { - if (($this->userdata['last_activity'] + $this->sess_length) < $this->now) - { - $this->userdata['last_visit'] = $this->userdata['last_activity']; - } - - $this->userdata['last_activity'] = $this->now; - - // Update the session in the DB if needed - if ($this->use_database === TRUE) - { - $this->CI->db->query($this->CI->db->update_string($this->session_table, array('last_activity' => $this->now), array('session_id' => $this->userdata['session_id']))); - } - - // Write the cookie - $this->sess_write(); - } - - // -------------------------------------------------------------------- - - /** - * Destroy the current session - * - * @access public - * @return void - */ - function sess_destroy() - { - setcookie( - $this->sess_cookie, - addslashes(serialize(array())), - ($this->now - 31500000), - $this->CI->config->item('cookie_path'), - $this->CI->config->item('cookie_domain'), - 0 - ); - } - - // -------------------------------------------------------------------- - - /** - * Garbage collection - * - * This deletes expired session rows from database - * if the probability percentage is met - * - * @access public - * @return void - */ - function sess_gc() - { - srand(time()); - if ((rand() % 100) < $this->gc_probability) - { - $expire = $this->now - $this->sess_length; - - $this->CI->db->where("last_activity < {$expire}"); - $this->CI->db->delete($this->session_table); - - log_message('debug', 'Session garbage collection performed.'); - } - } - - // -------------------------------------------------------------------- - - /** - * Fetch a specific item form the session array - * - * @access public - * @param string - * @return string - */ - function userdata($item) - { - return ( ! isset($this->userdata[$item])) ? FALSE : $this->userdata[$item]; - } - - // -------------------------------------------------------------------- - - /** - * 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(); - } - - // -------------------------------------------------------------------- - - /** - * Strip slashes - * - * @access public - * @param mixed - * @return mixed - */ - function strip_slashes($vals) - { - if (is_array($vals)) - { - foreach ($vals as $key=>$val) - { - $vals[$key] = $this->strip_slashes($val); - } - } - else - { - $vals = stripslashes($vals); - } - - return $vals; - } - -} -// END Session Class +CI =& get_instance(); + + log_message('debug', "Session Class Initialized"); + $this->sess_run(); + } + + // -------------------------------------------------------------------- + + /** + * Run the session routines + * + * @access public + * @return void + */ + function sess_run() + { + /* + * Set the "now" time + * + * It can either set to GMT or time(). The pref + * is set in the config file. If the developer + * is doing any sort of time localization they + * might want to set the session time to GMT so + * they can offset the "last_activity" and + * "last_visit" times based on each user's locale. + * + */ + if (strtolower($this->CI->config->item('time_reference')) == 'gmt') + { + $now = time(); + $this->now = mktime(gmdate("H", $now), gmdate("i", $now), gmdate("s", $now), gmdate("m", $now), gmdate("d", $now), gmdate("Y", $now)); + + if (strlen($this->now) < 10) + { + $this->now = time(); + log_message('error', 'The session class could not set a proper GMT timestamp so the local time() value was used.'); + } + } + else + { + $this->now = time(); + } + + /* + * Set the session length + * + * If the session expiration is set to zero in + * the config file we'll set the expiration + * two years from now. + * + */ + $expiration = $this->CI->config->item('sess_expiration'); + + if (is_numeric($expiration)) + { + if ($expiration > 0) + { + $this->sess_length = $this->CI->config->item('sess_expiration'); + } + else + { + $this->sess_length = (60*60*24*365*2); + } + } + + // Do we need encryption? + $this->encryption = $this->CI->config->item('sess_encrypt_cookie'); + + if ($this->encryption == TRUE) + { + $this->CI->load->library('encrypt'); + } + + // Are we using a database? + if ($this->CI->config->item('sess_use_database') === TRUE AND $this->CI->config->item('sess_table_name') != '') + { + $this->use_database = TRUE; + $this->session_table = $this->CI->config->item('sess_table_name'); + $this->CI->load->database(); + } + + // Set the cookie name + if ($this->CI->config->item('sess_cookie_name') != FALSE) + { + $this->sess_cookie = $this->CI->config->item('cookie_prefix').$this->CI->config->item('sess_cookie_name'); + } + + /* + * Fetch the current session + * + * 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 + { + // We only update the session every five minutes + if (($this->userdata['last_activity'] + 300) < $this->now) + { + $this->sess_update(); + } + } + + // Delete expired sessions if necessary + if ($this->use_database === TRUE) + { + $this->sess_gc(); + } + } + + // -------------------------------------------------------------------- + + /** + * Fetch the current session data if it exists + * + * @access public + * @return void + */ + function sess_read() + { + // Fetch the cookie + $session = $this->CI->input->cookie($this->sess_cookie); + + if ($session === FALSE) + { + log_message('debug', 'A session cookie was not found.'); + return FALSE; + } + + // Decrypt and unserialize the data + if ($this->encryption == TRUE) + { + $session = $this->CI->encrypt->decode($session); + } + + $session = @unserialize($this->strip_slashes($session)); + + if ( ! is_array($session) OR ! isset($session['last_activity'])) + { + log_message('error', 'The session cookie data did not contain a valid array. This could be a possible hacking attempt.'); + return FALSE; + } + + // Is the session current? + if (($session['last_activity'] + $this->sess_length) < $this->now) + { + $this->sess_destroy(); + return FALSE; + } + + // Does the IP Match? + if ($this->CI->config->item('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->CI->config->item('sess_match_useragent') == TRUE AND $session['user_agent'] != substr($this->CI->input->user_agent(), 0, 50)) + { + $this->sess_destroy(); + return FALSE; + } + + // Is there a corresponding session in the DB? + if ($this->use_database === TRUE) + { + $this->CI->db->where('session_id', $session['session_id']); + + if ($this->CI->config->item('sess_match_ip') == TRUE) + { + $this->CI->db->where('ip_address', $session['ip_address']); + } + + if ($this->CI->config->item('sess_match_useragent') == TRUE) + { + $this->CI->db->where('user_agent', $session['user_agent']); + } + + $query = $this->CI->db->get($this->session_table); + + if ($query->num_rows() == 0) + { + $this->sess_destroy(); + return FALSE; + } + else + { + $row = $query->row(); + if (($row->last_activity + $this->sess_length) < $this->now) + { + $this->CI->db->where('session_id', $session['session_id']); + $this->CI->db->delete($this->session_table); + $this->sess_destroy(); + return FALSE; + } + } + } + + // Session is valid! + $this->userdata = $session; + unset($session); + + return TRUE; + } + + // -------------------------------------------------------------------- + + /** + * Write the session cookie + * + * @access public + * @return void + */ + function sess_write() + { + $cookie_data = serialize($this->userdata); + + if ($this->encryption == TRUE) + { + $cookie_data = $this->CI->encrypt->encode($cookie_data); + } + + setcookie( + $this->sess_cookie, + $cookie_data, + $this->sess_length + time(), + $this->CI->config->item('cookie_path'), + $this->CI->config->item('cookie_domain'), + 0 + ); + } + + // -------------------------------------------------------------------- + + /** + * Create a new session + * + * @access public + * @return void + */ + function sess_create() + { + $sessid = ''; + while (strlen($sessid) < 32) + { + $sessid .= mt_rand(0, mt_getrandmax()); + } + + $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, 50), + 'last_activity' => $this->now + ); + + + // Save the session in the DB if needed + if ($this->use_database === TRUE) + { + $this->CI->db->query($this->CI->db->insert_string($this->session_table, $this->userdata)); + } + + // Write the cookie + $this->userdata['last_visit'] = 0; + $this->sess_write(); + } + + // -------------------------------------------------------------------- + + /** + * Update an existing session + * + * @access public + * @return void + */ + function sess_update() + { + if (($this->userdata['last_activity'] + $this->sess_length) < $this->now) + { + $this->userdata['last_visit'] = $this->userdata['last_activity']; + } + + $this->userdata['last_activity'] = $this->now; + + // Update the session in the DB if needed + if ($this->use_database === TRUE) + { + $this->CI->db->query($this->CI->db->update_string($this->session_table, array('last_activity' => $this->now), array('session_id' => $this->userdata['session_id']))); + } + + // Write the cookie + $this->sess_write(); + } + + // -------------------------------------------------------------------- + + /** + * Destroy the current session + * + * @access public + * @return void + */ + function sess_destroy() + { + setcookie( + $this->sess_cookie, + addslashes(serialize(array())), + ($this->now - 31500000), + $this->CI->config->item('cookie_path'), + $this->CI->config->item('cookie_domain'), + 0 + ); + } + + // -------------------------------------------------------------------- + + /** + * Garbage collection + * + * This deletes expired session rows from database + * if the probability percentage is met + * + * @access public + * @return void + */ + function sess_gc() + { + srand(time()); + if ((rand() % 100) < $this->gc_probability) + { + $expire = $this->now - $this->sess_length; + + $this->CI->db->where("last_activity < {$expire}"); + $this->CI->db->delete($this->session_table); + + log_message('debug', 'Session garbage collection performed.'); + } + } + + // -------------------------------------------------------------------- + + /** + * Fetch a specific item form the session array + * + * @access public + * @param string + * @return string + */ + function userdata($item) + { + return ( ! isset($this->userdata[$item])) ? FALSE : $this->userdata[$item]; + } + + // -------------------------------------------------------------------- + + /** + * 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(); + } + + // -------------------------------------------------------------------- + + /** + * Strip slashes + * + * @access public + * @param mixed + * @return mixed + */ + function strip_slashes($vals) + { + if (is_array($vals)) + { + foreach ($vals as $key=>$val) + { + $vals[$key] = $this->strip_slashes($val); + } + } + else + { + $vals = stripslashes($vals); + } + + return $vals; + } + +} +// END Session Class ?> \ No newline at end of file diff --git a/system/libraries/Sha1.php b/system/libraries/Sha1.php index 4dde04038..451428deb 100644 --- a/system/libraries/Sha1.php +++ b/system/libraries/Sha1.php @@ -1,249 +1,249 @@ -> 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 < sizeof($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 +> 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 < sizeof($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 ?> \ No newline at end of file diff --git a/system/libraries/Table.php b/system/libraries/Table.php index 32223708e..44acce657 100644 --- a/system/libraries/Table.php +++ b/system/libraries/Table.php @@ -1,12 +1,12 @@ '', 'title' => '', 'excerpt' => '', 'blog_name' => '', 'charset' => ''); - var $convert_ascii = TRUE; - var $response = ''; - var $error_msg = array(); - - /** - * Constructor - * - * @access public - */ - function CI_Trackback() - { - 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 ( ! eregi("0", $this->response)) - { - $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 (strstr($url, '?')) - { - $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 - { - if (ereg("/$", $url)) - { - $url = substr($url, 0, -1); - } - - $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+/", ' ', preg_replace("/(\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; - } - -} -// END Trackback Class + '', 'title' => '', 'excerpt' => '', 'blog_name' => '', 'charset' => ''); + var $convert_ascii = TRUE; + var $response = ''; + var $error_msg = array(); + + /** + * Constructor + * + * @access public + */ + function CI_Trackback() + { + 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 ( ! eregi("0", $this->response)) + { + $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 (strstr($url, '?')) + { + $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 + { + if (ereg("/$", $url)) + { + $url = substr($url, 0, -1); + } + + $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+/", ' ', preg_replace("/(\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; + } + +} +// END Trackback Class ?> \ No newline at end of file diff --git a/system/libraries/URI.php b/system/libraries/URI.php index 10654a69c..5cedd8e0f 100644 --- a/system/libraries/URI.php +++ b/system/libraries/URI.php @@ -1,367 +1,367 @@ -router =& load_class('Router'); - log_message('debug', "URI Class Initialized"); - } - - // -------------------------------------------------------------------- - - /** - * 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->router->segments[$n])) ? $no_result : $this->router->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->router->rsegments[$n])) ? $no_result : $this->router->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: - * - * www.your-site.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 - * - */ - 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') - { - if ($where == 'trailing') - { - $trailing = '/'; - $leading = ''; - } - elseif ($where == 'leading') - { - $leading = '/'; - $trailing = ''; - } - else - { - $leading = '/'; - $trailing = '/'; - } - return $leading.$this->$which($n).$trailing; - } - - // -------------------------------------------------------------------- - - /** - * Segment Array - * - * @access public - * @return array - */ - function segment_array() - { - return $this->router->segments; - } - - // -------------------------------------------------------------------- - - /** - * Routed Segment Array - * - * @access public - * @return array - */ - function rsegment_array() - { - return $this->router->rsegments; - } - - // -------------------------------------------------------------------- - - /** - * Total number of segments - * - * @access public - * @return integer - */ - function total_segments() - { - return count($this->router->segments); - } - - // -------------------------------------------------------------------- - - /** - * Total number of routed segments - * - * @access public - * @return integer - */ - function total_rsegments() - { - return count($this->router->rsegments); - } - - // -------------------------------------------------------------------- - - /** - * Fetch the entire URI string - * - * @access public - * @return string - */ - function uri_string() - { - return $this->router->uri_string; - } - - - // -------------------------------------------------------------------- - - /** - * Fetch the entire Re-routed URI string - * - * @access public - * @return string - */ - function ruri_string() - { - return '/'.implode('/', $this->rsegment_array()).'/'; - } - -} -// END URI Class +router =& load_class('Router'); + log_message('debug', "URI Class Initialized"); + } + + // -------------------------------------------------------------------- + + /** + * 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->router->segments[$n])) ? $no_result : $this->router->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->router->rsegments[$n])) ? $no_result : $this->router->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: + * + * www.your-site.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 + * + */ + 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') + { + if ($where == 'trailing') + { + $trailing = '/'; + $leading = ''; + } + elseif ($where == 'leading') + { + $leading = '/'; + $trailing = ''; + } + else + { + $leading = '/'; + $trailing = '/'; + } + return $leading.$this->$which($n).$trailing; + } + + // -------------------------------------------------------------------- + + /** + * Segment Array + * + * @access public + * @return array + */ + function segment_array() + { + return $this->router->segments; + } + + // -------------------------------------------------------------------- + + /** + * Routed Segment Array + * + * @access public + * @return array + */ + function rsegment_array() + { + return $this->router->rsegments; + } + + // -------------------------------------------------------------------- + + /** + * Total number of segments + * + * @access public + * @return integer + */ + function total_segments() + { + return count($this->router->segments); + } + + // -------------------------------------------------------------------- + + /** + * Total number of routed segments + * + * @access public + * @return integer + */ + function total_rsegments() + { + return count($this->router->rsegments); + } + + // -------------------------------------------------------------------- + + /** + * Fetch the entire URI string + * + * @access public + * @return string + */ + function uri_string() + { + return $this->router->uri_string; + } + + + // -------------------------------------------------------------------- + + /** + * Fetch the entire Re-routed URI string + * + * @access public + * @return string + */ + function ruri_string() + { + return '/'.implode('/', $this->rsegment_array()).'/'; + } + +} +// END URI Class ?> \ No newline at end of file diff --git a/system/libraries/Unit_test.php b/system/libraries/Unit_test.php index f68f69e71..74ed1275f 100644 --- a/system/libraries/Unit_test.php +++ b/system/libraries/Unit_test.php @@ -1,331 +1,331 @@ -active == FALSE) - return FALSE; - - if (in_array($expected, array('is_string', 'is_bool', 'is_true', 'is_false', 'is_int', 'is_numeric', 'is_float', 'is_double', 'is_array', 'is_null'), TRUE)) - { - $expected = str_replace('is_float', 'is_double', $expected); - $result = ($expected($test)) ? TRUE : FALSE; - $extype = str_replace(array('true', 'false'), 'bool', str_replace('is_', '', $expected)); - } - else - { - if ($this->strict == TRUE) - $result = ($test === $expected) ? TRUE : FALSE; - else - $result = ($test == $expected) ? TRUE : FALSE; - - $extype = gettype($expected); - } - - $back = $this->_backtrace(); - - $report[] = array ( - 'test_name' => $test_name, - 'test_datatype' => gettype($test), - 'res_datatype' => $extype, - 'result' => ($result === TRUE) ? 'passed' : 'failed', - 'file' => $back['file'], - 'line' => $back['line'] - ); - - $this->results[] = $report; - - return($this->report($this->result($report))); - } - - // -------------------------------------------------------------------- - - /** - * Generate a report - * - * Displays a table with the test data - * - * @access public - * @return string - */ - function report($result = array()) - { - if (count($result) == 0) - { - $result = $this->result(); - } - - $this->_parse_template(); - - $r = ''; - foreach ($result as $res) - { - $table = ''; - - foreach ($res as $key => $val) - { - $temp = $this->_template_rows; - $temp = str_replace('{item}', $key, $temp); - $temp = str_replace('{result}', $val, $temp); - $table .= $temp; - } - - $r .= str_replace('{rows}', $table, $this->_template); - } - - return $r; - } - - // -------------------------------------------------------------------- - - /** - * Use strict comparison - * - * Causes the evaluation to use === rather then == - * - * @access public - * @param bool - * @return null - */ - function use_strict($state = TRUE) - { - $this->strict = ($state == FALSE) ? FALSE : TRUE; - } - - // -------------------------------------------------------------------- - - /** - * Make Unit testing active - * - * Enables/disables unit testing - * - * @access public - * @param bool - * @return null - */ - function active($state = TRUE) - { - $this->active = ($state == FALSE) ? FALSE : TRUE; - } - - // -------------------------------------------------------------------- - - /** - * Result Array - * - * Returns the raw result data - * - * @access public - * @return array - */ - function result($results = array()) - { - $CI =& get_instance(); - $CI->load->language('unit_test'); - - if (count($results) == 0) - { - $results = $this->results; - } - - $retval = array(); - foreach ($results as $result) - { - $temp = array(); - foreach ($result as $key => $val) - { - if (is_array($val)) - { - foreach ($val as $k => $v) - { - if (FALSE !== ($line = $CI->lang->line(strtolower('ut_'.$v)))) - { - $v = $line; - } - $temp[$CI->lang->line('ut_'.$k)] = $v; - } - } - else - { - if (FALSE !== ($line = $CI->lang->line(strtolower('ut_'.$val)))) - { - $val = $line; - } - $temp[$CI->lang->line('ut_'.$key)] = $val; - } - } - - $retval[] = $temp; - } - - return $retval; - } - - // -------------------------------------------------------------------- - - /** - * Set the template - * - * This lets us set the template to be used to display results - * - * @access public - * @param string - * @return void - */ - function set_template($template) - { - $this->_template = $template; - } - - // -------------------------------------------------------------------- - - /** - * Generate a backtrace - * - * This lets us show file names and line numbers - * - * @access private - * @return array - */ - function _backtrace() - { - if (function_exists('debug_backtrace')) - { - $back = debug_backtrace(); - - $file = ( ! isset($back['1']['file'])) ? '' : $back['1']['file']; - $line = ( ! isset($back['1']['line'])) ? '' : $back['1']['line']; - - return array('file' => $file, 'line' => $line); - } - return array('file' => 'Unknown', 'line' => 'Unknown'); - } - - // -------------------------------------------------------------------- - - /** - * Get Default Template - * - * @access private - * @return string - */ - function _default_template() - { - $this->_template = ' -
    - - {rows} -
    '; - - $this->_template_rows = ' - - {item} - {result} - - '; - } - - // -------------------------------------------------------------------- - - /** - * Parse Template - * - * Harvests the data within the template {pseudo-variables} - * - * @access private - * @return void - */ - function _parse_template() - { - if ( ! is_null($this->_template_rows)) - { - return; - } - - if (is_null($this->_template)) - { - $this->_default_template(); - return; - } - - if ( ! preg_match("/\{rows\}(.*?)\{\/rows\}/si", $this->_template, $match)) - { - $this->_default_template(); - return; - } - - $this->_template_rows = $match['1']; - $this->_template = str_replace($match['0'], '{rows}', $this->_template); - } - -} -// END Unit_test Class - -/** - * Helper functions to test boolean true/false - * - * - * @access private - * @return bool - */ -function is_true($test) -{ - return (is_bool($test) AND $test === TRUE) ? TRUE : FALSE; -} -function is_false($test) -{ - return (is_bool($test) AND $test === FALSE) ? TRUE : FALSE; -} - +active == FALSE) + return FALSE; + + if (in_array($expected, array('is_string', 'is_bool', 'is_true', 'is_false', 'is_int', 'is_numeric', 'is_float', 'is_double', 'is_array', 'is_null'), TRUE)) + { + $expected = str_replace('is_float', 'is_double', $expected); + $result = ($expected($test)) ? TRUE : FALSE; + $extype = str_replace(array('true', 'false'), 'bool', str_replace('is_', '', $expected)); + } + else + { + if ($this->strict == TRUE) + $result = ($test === $expected) ? TRUE : FALSE; + else + $result = ($test == $expected) ? TRUE : FALSE; + + $extype = gettype($expected); + } + + $back = $this->_backtrace(); + + $report[] = array ( + 'test_name' => $test_name, + 'test_datatype' => gettype($test), + 'res_datatype' => $extype, + 'result' => ($result === TRUE) ? 'passed' : 'failed', + 'file' => $back['file'], + 'line' => $back['line'] + ); + + $this->results[] = $report; + + return($this->report($this->result($report))); + } + + // -------------------------------------------------------------------- + + /** + * Generate a report + * + * Displays a table with the test data + * + * @access public + * @return string + */ + function report($result = array()) + { + if (count($result) == 0) + { + $result = $this->result(); + } + + $this->_parse_template(); + + $r = ''; + foreach ($result as $res) + { + $table = ''; + + foreach ($res as $key => $val) + { + $temp = $this->_template_rows; + $temp = str_replace('{item}', $key, $temp); + $temp = str_replace('{result}', $val, $temp); + $table .= $temp; + } + + $r .= str_replace('{rows}', $table, $this->_template); + } + + return $r; + } + + // -------------------------------------------------------------------- + + /** + * Use strict comparison + * + * Causes the evaluation to use === rather then == + * + * @access public + * @param bool + * @return null + */ + function use_strict($state = TRUE) + { + $this->strict = ($state == FALSE) ? FALSE : TRUE; + } + + // -------------------------------------------------------------------- + + /** + * Make Unit testing active + * + * Enables/disables unit testing + * + * @access public + * @param bool + * @return null + */ + function active($state = TRUE) + { + $this->active = ($state == FALSE) ? FALSE : TRUE; + } + + // -------------------------------------------------------------------- + + /** + * Result Array + * + * Returns the raw result data + * + * @access public + * @return array + */ + function result($results = array()) + { + $CI =& get_instance(); + $CI->load->language('unit_test'); + + if (count($results) == 0) + { + $results = $this->results; + } + + $retval = array(); + foreach ($results as $result) + { + $temp = array(); + foreach ($result as $key => $val) + { + if (is_array($val)) + { + foreach ($val as $k => $v) + { + if (FALSE !== ($line = $CI->lang->line(strtolower('ut_'.$v)))) + { + $v = $line; + } + $temp[$CI->lang->line('ut_'.$k)] = $v; + } + } + else + { + if (FALSE !== ($line = $CI->lang->line(strtolower('ut_'.$val)))) + { + $val = $line; + } + $temp[$CI->lang->line('ut_'.$key)] = $val; + } + } + + $retval[] = $temp; + } + + return $retval; + } + + // -------------------------------------------------------------------- + + /** + * Set the template + * + * This lets us set the template to be used to display results + * + * @access public + * @param string + * @return void + */ + function set_template($template) + { + $this->_template = $template; + } + + // -------------------------------------------------------------------- + + /** + * Generate a backtrace + * + * This lets us show file names and line numbers + * + * @access private + * @return array + */ + function _backtrace() + { + if (function_exists('debug_backtrace')) + { + $back = debug_backtrace(); + + $file = ( ! isset($back['1']['file'])) ? '' : $back['1']['file']; + $line = ( ! isset($back['1']['line'])) ? '' : $back['1']['line']; + + return array('file' => $file, 'line' => $line); + } + return array('file' => 'Unknown', 'line' => 'Unknown'); + } + + // -------------------------------------------------------------------- + + /** + * Get Default Template + * + * @access private + * @return string + */ + function _default_template() + { + $this->_template = ' +
    + + {rows} +
    '; + + $this->_template_rows = ' + + {item} + {result} + + '; + } + + // -------------------------------------------------------------------- + + /** + * Parse Template + * + * Harvests the data within the template {pseudo-variables} + * + * @access private + * @return void + */ + function _parse_template() + { + if ( ! is_null($this->_template_rows)) + { + return; + } + + if (is_null($this->_template)) + { + $this->_default_template(); + return; + } + + if ( ! preg_match("/\{rows\}(.*?)\{\/rows\}/si", $this->_template, $match)) + { + $this->_default_template(); + return; + } + + $this->_template_rows = $match['1']; + $this->_template = str_replace($match['0'], '{rows}', $this->_template); + } + +} +// END Unit_test Class + +/** + * Helper functions to test boolean true/false + * + * + * @access private + * @return bool + */ +function is_true($test) +{ + return (is_bool($test) AND $test === TRUE) ? TRUE : FALSE; +} +function is_false($test) +{ + return (is_bool($test) AND $test === FALSE) ? TRUE : FALSE; +} + ?> \ No newline at end of file diff --git a/system/libraries/Upload.php b/system/libraries/Upload.php index ff0fb1cb9..564e29937 100644 --- a/system/libraries/Upload.php +++ b/system/libraries/Upload.php @@ -1,809 +1,809 @@ - 0) - { - $this->initialize($props); - } - - log_message('debug', "Upload Class Initialized"); - } - - // -------------------------------------------------------------------- - - /** - * Initialize preferences - * - * @access public - * @param array - * @return void - */ - function initialize($config = array()) - { - $defaults = array( - 'max_size' => 0, - 'max_width' => 0, - 'max_height' => 0, - 'allowed_types' => "", - 'file_temp' => "", - 'file_name' => "", - 'orig_name' => "", - 'file_type' => "", - 'file_size' => "", - 'file_ext' => "", - 'upload_path' => "", - 'overwrite' => FALSE, - 'encrypt_name' => FALSE, - 'is_image' => FALSE, - 'image_width' => '', - 'image_height' => '', - 'image_type' => '', - 'image_size_str' => '', - 'error_msg' => array(), - 'mimes' => array(), - 'remove_spaces' => TRUE, - 'xss_clean' => FALSE, - 'temp_prefix' => "temp_file_" - ); - - - foreach ($defaults as $key => $val) - { - if (isset($config[$key])) - { - $method = 'set_'.$key; - if (method_exists($this, $method)) - { - $this->$method($config[$key]); - } - else - { - $this->$key = $config[$key]; - } - } - else - { - $this->$key = $val; - } - } - } - - // -------------------------------------------------------------------- - - /** - * Perform the file upload - * - * @access public - * @return bool - */ - function do_upload($field = 'userfile') - { - // Is $_FILES[$field] set? If not, no reason to continue. - if ( ! isset($_FILES[$field])) - { - $this->set_error('upload_userfile_not_set'); - return FALSE; - } - - // Is the upload path valid? - if ( ! $this->validate_upload_path()) - { - return FALSE; - } - - // Was the file able to be uploaded? If not, determine the reason why. - if ( ! is_uploaded_file($_FILES[$field]['tmp_name'])) - { - $error = ( ! isset($_FILES[$field]['error'])) ? 4 : $_FILES[$field]['error']; - - switch($error) - { - case 1 : $this->set_error('upload_file_exceeds_limit'); - break; - case 3 : $this->set_error('upload_file_partial'); - break; - case 4 : $this->set_error('upload_no_file_selected'); - break; - default : $this->set_error('upload_no_file_selected'); - break; - } - - return FALSE; - } - - // Set the uploaded data as class variables - $this->file_temp = $_FILES[$field]['tmp_name']; - $this->file_name = $_FILES[$field]['name']; - $this->file_size = $_FILES[$field]['size']; - $this->file_type = preg_replace("/^(.+?);.*$/", "\\1", $_FILES[$field]['type']); - $this->file_type = strtolower($this->file_type); - $this->file_ext = $this->get_extension($_FILES[$field]['name']); - - // Convert the file size to kilobytes - if ($this->file_size > 0) - { - $this->file_size = round($this->file_size/1024, 2); - } - - // Is the file type allowed to be uploaded? - if ( ! $this->is_allowed_filetype()) - { - $this->set_error('upload_invalid_filetype'); - return FALSE; - } - - // Is the file size within the allowed maximum? - if ( ! $this->is_allowed_filesize()) - { - $this->set_error('upload_invalid_filesize'); - return FALSE; - } - - // Are the image dimensions within the allowed size? - // Note: This can fail if the server has an open_basdir restriction. - if ( ! $this->is_allowed_dimensions()) - { - $this->set_error('upload_invalid_dimensions'); - return FALSE; - } - - // Sanitize the file name for security - $this->file_name = $this->clean_file_name($this->file_name); - - // Remove white spaces in the name - if ($this->remove_spaces == TRUE) - { - $this->file_name = preg_replace("/\s+/", "_", $this->file_name); - } - - /* - * Validate the file name - * This function appends an number onto the end of - * the file if one with the same name already exists. - * If it returns false there was a problem. - */ - $this->orig_name = $this->file_name; - - if ($this->overwrite == FALSE) - { - $this->file_name = $this->set_filename($this->upload_path, $this->file_name); - - if ($this->file_name === FALSE) - { - return FALSE; - } - } - - /* - * Move the file to the final destination - * To deal with different server configurations - * we'll attempt to use copy() first. If that fails - * we'll use move_uploaded_file(). One of the two should - * reliably work in most environments - */ - if ( ! @copy($this->file_temp, $this->upload_path.$this->file_name)) - { - if ( ! @move_uploaded_file($this->file_temp, $this->upload_path.$this->file_name)) - { - $this->set_error('upload_destination_error'); - return FALSE; - } - } - - /* - * Run the file through the XSS hacking filter - * This helps prevent malicious code from being - * embedded within a file. Scripts can easily - * be disguised as images or other file types. - */ - if ($this->xss_clean == TRUE) - { - $this->do_xss_clean(); - } - - /* - * Set the finalized image dimensions - * This sets the image width/height (assuming the - * file was an image). We use this information - * in the "data" function. - */ - $this->set_image_properties($this->upload_path.$this->file_name); - - return TRUE; - } - - // -------------------------------------------------------------------- - - /** - * Finalized Data Array - * - * Returns an associative array containing all of the information - * related to the upload, allowing the developer easy access in one array. - * - * @access public - * @return array - */ - function data() - { - return array ( - 'file_name' => $this->file_name, - 'file_type' => $this->file_type, - 'file_path' => $this->upload_path, - 'full_path' => $this->upload_path.$this->file_name, - 'raw_name' => str_replace($this->file_ext, '', $this->file_name), - 'orig_name' => $this->orig_name, - 'file_ext' => $this->file_ext, - 'file_size' => $this->file_size, - 'is_image' => $this->is_image(), - 'image_width' => $this->image_width, - 'image_height' => $this->image_height, - 'image_type' => $this->image_type, - 'image_size_str' => $this->image_size_str, - ); - } - - // -------------------------------------------------------------------- - - /** - * Set Upload Path - * - * @access public - * @param string - * @return void - */ - function set_upload_path($path) - { - $this->upload_path = $path; - } - - // -------------------------------------------------------------------- - - /** - * Set the file name - * - * This function takes a filename/path as input and looks for the - * existence of a file with the same name. If found, it will append a - * number to the end of the filename to avoid overwriting a pre-existing file. - * - * @access public - * @param string - * @param string - * @return string - */ - function set_filename($path, $filename) - { - if ($this->encrypt_name == TRUE) - { - mt_srand(); - $filename = md5(uniqid(mt_rand())).$this->file_ext; - } - - if ( ! file_exists($path.$filename)) - { - return $filename; - } - - $filename = str_replace($this->file_ext, '', $filename); - - $new_filename = ''; - for ($i = 1; $i < 100; $i++) - { - if ( ! file_exists($path.$filename.$i.$this->file_ext)) - { - $new_filename = $filename.$i.$this->file_ext; - break; - } - } - - if ($new_filename == '') - { - $this->set_error('upload_bad_filename'); - return FALSE; - } - else - { - return $new_filename; - } - } - - // -------------------------------------------------------------------- - - /** - * Set Maximum File Size - * - * @access public - * @param integer - * @return void - */ - function set_max_filesize($n) - { - $this->max_size = ( ! eregi("^[[:digit:]]+$", $n)) ? 0 : $n; - } - - // -------------------------------------------------------------------- - - /** - * Set Maximum Image Width - * - * @access public - * @param integer - * @return void - */ - function set_max_width($n) - { - $this->max_width = ( ! eregi("^[[:digit:]]+$", $n)) ? 0 : $n; - } - - // -------------------------------------------------------------------- - - /** - * Set Maximum Image Height - * - * @access public - * @param integer - * @return void - */ - function set_max_height($n) - { - $this->max_height = ( ! eregi("^[[:digit:]]+$", $n)) ? 0 : $n; - } - - // -------------------------------------------------------------------- - - /** - * Set Allowed File Types - * - * @access public - * @param string - * @return void - */ - function set_allowed_types($types) - { - $this->allowed_types = explode('|', $types); - } - - // -------------------------------------------------------------------- - - /** - * Set Image Properties - * - * Uses GD to determine the width/height/type of image - * - * @access public - * @param string - * @return void - */ - function set_image_properties($path = '') - { - if ( ! $this->is_image()) - { - return; - } - - if (function_exists('getimagesize')) - { - if (FALSE !== ($D = @getimagesize($path))) - { - $types = array(1 => 'gif', 2 => 'jpeg', 3 => 'png'); - - $this->image_width = $D['0']; - $this->image_height = $D['1']; - $this->image_type = ( ! isset($types[$D['2']])) ? 'unknown' : $types[$D['2']]; - $this->image_size_str = $D['3']; // string containing height and width - } - } - } - - // -------------------------------------------------------------------- - - /** - * Set XSS Clean - * - * Enables the XSS flag so that the file that was uploaded - * will be run through the XSS filter. - * - * @access public - * @param bool - * @return void - */ - function set_xss_clean($flag = FALSE) - { - $this->xss_clean = ($flag == TRUE) ? TRUE : FALSE; - } - - // -------------------------------------------------------------------- - - /** - * Validate the image - * - * @access public - * @return bool - */ - function is_image() - { - $img_mimes = array( - 'image/gif', - 'image/jpg', - 'image/jpe', - 'image/jpeg', - 'image/pjpeg', - 'image/png', - 'image/x-png' - ); - - - return (in_array($this->file_type, $img_mimes, TRUE)) ? TRUE : FALSE; - } - - // -------------------------------------------------------------------- - - /** - * Verify that the filetype is allowed - * - * @access public - * @return bool - */ - function is_allowed_filetype() - { - if (count($this->allowed_types) == 0) - { - $this->set_error('upload_no_file_types'); - return FALSE; - } - - foreach ($this->allowed_types as $val) - { - $mime = $this->mimes_types(strtolower($val)); - - if (is_array($mime)) - { - if (in_array($this->file_type, $mime, TRUE)) - { - return TRUE; - } - } - else - { - if ($mime == $this->file_type) - { - return TRUE; - } - } - } - - return FALSE; - } - - // -------------------------------------------------------------------- - - /** - * Verify that the file is within the allowed size - * - * @access public - * @return bool - */ - function is_allowed_filesize() - { - if ($this->max_size != 0 AND $this->file_size > $this->max_size) - { - return FALSE; - } - else - { - return TRUE; - } - } - - // -------------------------------------------------------------------- - - /** - * Verify that the image is within the allowed width/height - * - * @access public - * @return bool - */ - function is_allowed_dimensions() - { - if ( ! $this->is_image()) - { - return TRUE; - } - - if (function_exists('getimagesize')) - { - $D = @getimagesize($this->file_temp); - - if ($this->max_width > 0 AND $D['0'] > $this->max_width) - { - return FALSE; - } - - if ($this->max_height > 0 AND $D['1'] > $this->max_height) - { - return FALSE; - } - - return TRUE; - } - - return TRUE; - } - - // -------------------------------------------------------------------- - - /** - * Validate Upload Path - * - * Verifies that it is a valid upload path with proper permissions. - * - * - * @access public - * @return bool - */ - function validate_upload_path() - { - if ($this->upload_path == '') - { - $this->set_error('upload_no_filepath'); - return FALSE; - } - - if (function_exists('realpath') AND @realpath($this->upload_path) !== FALSE) - { - $this->upload_path = str_replace("\\", "/", realpath($this->upload_path)); - } - - if ( ! @is_dir($this->upload_path)) - { - $this->set_error('upload_no_filepath'); - return FALSE; - } - - if ( ! is_writable($this->upload_path)) - { - $this->set_error('upload_not_writable'); - return FALSE; - } - - $this->upload_path = preg_replace("/(.+?)\/*$/", "\\1/", $this->upload_path); - return TRUE; - } - - // -------------------------------------------------------------------- - - /** - * Extract the file extension - * - * @access public - * @param string - * @return string - */ - function get_extension($filename) - { - $x = explode('.', $filename); - return '.'.end($x); - } - - // -------------------------------------------------------------------- - - /** - * Clean the file name for security - * - * @access public - * @param string - * @return string - */ - function clean_file_name($filename) - { - $bad = array( - "", - "'", - "<", - ">", - '"', - '&', - '$', - '=', - ';', - '?', - '/', - "%20", - "%22", - "%3c", // < - "%253c", // < - "%3e", // > - "%0e", // > - "%28", // ( - "%29", // ) - "%2528", // ( - "%26", // & - "%24", // $ - "%3f", // ? - "%3b", // ; - "%3d" // = - ); - - foreach ($bad as $val) - { - $filename = str_replace($val, '', $filename); - } - - return $filename; - } - - // -------------------------------------------------------------------- - - /** - * Runs the file through the XSS clean function - * - * This prevents people from embedding malicious code in their files. - * I'm not sure that it won't negatively affect certain files in unexpected ways, - * but so far I haven't found that it causes trouble. - * - * @access public - * @return void - */ - function do_xss_clean() - { - $file = $this->upload_path.$this->file_name; - - if (filesize($file) == 0) - { - return FALSE; - } - - if ( ! $fp = @fopen($file, 'rb')) - { - return FALSE; - } - - flock($fp, LOCK_EX); - - $data = fread($fp, filesize($file)); - - $CI =& get_instance(); - $data = $CI->input->xss_clean($data); - - fwrite($fp, $data); - flock($fp, LOCK_UN); - fclose($fp); - } - - // -------------------------------------------------------------------- - - /** - * Set an error message - * - * @access public - * @param string - * @return void - */ - function set_error($msg) - { - $CI =& get_instance(); - $CI->lang->load('upload'); - - if (is_array($msg)) - { - foreach ($msg as $val) - { - $msg = ($CI->lang->line($val) == FALSE) ? $val : $CI->lang->line($val); - $this->error_msg[] = $msg; - log_message('error', $msg); - } - } - else - { - $msg = ($CI->lang->line($msg) == FALSE) ? $msg : $CI->lang->line($msg); - $this->error_msg[] = $msg; - log_message('error', $msg); - } - } - - // -------------------------------------------------------------------- - - /** - * Display the error message - * - * @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; - } - - // -------------------------------------------------------------------- - - /** - * List of Mime Types - * - * This is a list of mime types. We use it to validate - * the "allowed types" set by the developer - * - * @access public - * @param string - * @return string - */ - function mimes_types($mime) - { - if (count($this->mimes) == 0) - { - if (@include(APPPATH.'config/mimes'.EXT)) - { - $this->mimes = $mimes; - unset($mimes); - } - } - - return ( ! isset($this->mimes[$mime])) ? FALSE : $this->mimes[$mime]; - } - -} -// END Upload Class + 0) + { + $this->initialize($props); + } + + log_message('debug', "Upload Class Initialized"); + } + + // -------------------------------------------------------------------- + + /** + * Initialize preferences + * + * @access public + * @param array + * @return void + */ + function initialize($config = array()) + { + $defaults = array( + 'max_size' => 0, + 'max_width' => 0, + 'max_height' => 0, + 'allowed_types' => "", + 'file_temp' => "", + 'file_name' => "", + 'orig_name' => "", + 'file_type' => "", + 'file_size' => "", + 'file_ext' => "", + 'upload_path' => "", + 'overwrite' => FALSE, + 'encrypt_name' => FALSE, + 'is_image' => FALSE, + 'image_width' => '', + 'image_height' => '', + 'image_type' => '', + 'image_size_str' => '', + 'error_msg' => array(), + 'mimes' => array(), + 'remove_spaces' => TRUE, + 'xss_clean' => FALSE, + 'temp_prefix' => "temp_file_" + ); + + + foreach ($defaults as $key => $val) + { + if (isset($config[$key])) + { + $method = 'set_'.$key; + if (method_exists($this, $method)) + { + $this->$method($config[$key]); + } + else + { + $this->$key = $config[$key]; + } + } + else + { + $this->$key = $val; + } + } + } + + // -------------------------------------------------------------------- + + /** + * Perform the file upload + * + * @access public + * @return bool + */ + function do_upload($field = 'userfile') + { + // Is $_FILES[$field] set? If not, no reason to continue. + if ( ! isset($_FILES[$field])) + { + $this->set_error('upload_userfile_not_set'); + return FALSE; + } + + // Is the upload path valid? + if ( ! $this->validate_upload_path()) + { + return FALSE; + } + + // Was the file able to be uploaded? If not, determine the reason why. + if ( ! is_uploaded_file($_FILES[$field]['tmp_name'])) + { + $error = ( ! isset($_FILES[$field]['error'])) ? 4 : $_FILES[$field]['error']; + + switch($error) + { + case 1 : $this->set_error('upload_file_exceeds_limit'); + break; + case 3 : $this->set_error('upload_file_partial'); + break; + case 4 : $this->set_error('upload_no_file_selected'); + break; + default : $this->set_error('upload_no_file_selected'); + break; + } + + return FALSE; + } + + // Set the uploaded data as class variables + $this->file_temp = $_FILES[$field]['tmp_name']; + $this->file_name = $_FILES[$field]['name']; + $this->file_size = $_FILES[$field]['size']; + $this->file_type = preg_replace("/^(.+?);.*$/", "\\1", $_FILES[$field]['type']); + $this->file_type = strtolower($this->file_type); + $this->file_ext = $this->get_extension($_FILES[$field]['name']); + + // Convert the file size to kilobytes + if ($this->file_size > 0) + { + $this->file_size = round($this->file_size/1024, 2); + } + + // Is the file type allowed to be uploaded? + if ( ! $this->is_allowed_filetype()) + { + $this->set_error('upload_invalid_filetype'); + return FALSE; + } + + // Is the file size within the allowed maximum? + if ( ! $this->is_allowed_filesize()) + { + $this->set_error('upload_invalid_filesize'); + return FALSE; + } + + // Are the image dimensions within the allowed size? + // Note: This can fail if the server has an open_basdir restriction. + if ( ! $this->is_allowed_dimensions()) + { + $this->set_error('upload_invalid_dimensions'); + return FALSE; + } + + // Sanitize the file name for security + $this->file_name = $this->clean_file_name($this->file_name); + + // Remove white spaces in the name + if ($this->remove_spaces == TRUE) + { + $this->file_name = preg_replace("/\s+/", "_", $this->file_name); + } + + /* + * Validate the file name + * This function appends an number onto the end of + * the file if one with the same name already exists. + * If it returns false there was a problem. + */ + $this->orig_name = $this->file_name; + + if ($this->overwrite == FALSE) + { + $this->file_name = $this->set_filename($this->upload_path, $this->file_name); + + if ($this->file_name === FALSE) + { + return FALSE; + } + } + + /* + * Move the file to the final destination + * To deal with different server configurations + * we'll attempt to use copy() first. If that fails + * we'll use move_uploaded_file(). One of the two should + * reliably work in most environments + */ + if ( ! @copy($this->file_temp, $this->upload_path.$this->file_name)) + { + if ( ! @move_uploaded_file($this->file_temp, $this->upload_path.$this->file_name)) + { + $this->set_error('upload_destination_error'); + return FALSE; + } + } + + /* + * Run the file through the XSS hacking filter + * This helps prevent malicious code from being + * embedded within a file. Scripts can easily + * be disguised as images or other file types. + */ + if ($this->xss_clean == TRUE) + { + $this->do_xss_clean(); + } + + /* + * Set the finalized image dimensions + * This sets the image width/height (assuming the + * file was an image). We use this information + * in the "data" function. + */ + $this->set_image_properties($this->upload_path.$this->file_name); + + return TRUE; + } + + // -------------------------------------------------------------------- + + /** + * Finalized Data Array + * + * Returns an associative array containing all of the information + * related to the upload, allowing the developer easy access in one array. + * + * @access public + * @return array + */ + function data() + { + return array ( + 'file_name' => $this->file_name, + 'file_type' => $this->file_type, + 'file_path' => $this->upload_path, + 'full_path' => $this->upload_path.$this->file_name, + 'raw_name' => str_replace($this->file_ext, '', $this->file_name), + 'orig_name' => $this->orig_name, + 'file_ext' => $this->file_ext, + 'file_size' => $this->file_size, + 'is_image' => $this->is_image(), + 'image_width' => $this->image_width, + 'image_height' => $this->image_height, + 'image_type' => $this->image_type, + 'image_size_str' => $this->image_size_str, + ); + } + + // -------------------------------------------------------------------- + + /** + * Set Upload Path + * + * @access public + * @param string + * @return void + */ + function set_upload_path($path) + { + $this->upload_path = $path; + } + + // -------------------------------------------------------------------- + + /** + * Set the file name + * + * This function takes a filename/path as input and looks for the + * existence of a file with the same name. If found, it will append a + * number to the end of the filename to avoid overwriting a pre-existing file. + * + * @access public + * @param string + * @param string + * @return string + */ + function set_filename($path, $filename) + { + if ($this->encrypt_name == TRUE) + { + mt_srand(); + $filename = md5(uniqid(mt_rand())).$this->file_ext; + } + + if ( ! file_exists($path.$filename)) + { + return $filename; + } + + $filename = str_replace($this->file_ext, '', $filename); + + $new_filename = ''; + for ($i = 1; $i < 100; $i++) + { + if ( ! file_exists($path.$filename.$i.$this->file_ext)) + { + $new_filename = $filename.$i.$this->file_ext; + break; + } + } + + if ($new_filename == '') + { + $this->set_error('upload_bad_filename'); + return FALSE; + } + else + { + return $new_filename; + } + } + + // -------------------------------------------------------------------- + + /** + * Set Maximum File Size + * + * @access public + * @param integer + * @return void + */ + function set_max_filesize($n) + { + $this->max_size = ( ! eregi("^[[:digit:]]+$", $n)) ? 0 : $n; + } + + // -------------------------------------------------------------------- + + /** + * Set Maximum Image Width + * + * @access public + * @param integer + * @return void + */ + function set_max_width($n) + { + $this->max_width = ( ! eregi("^[[:digit:]]+$", $n)) ? 0 : $n; + } + + // -------------------------------------------------------------------- + + /** + * Set Maximum Image Height + * + * @access public + * @param integer + * @return void + */ + function set_max_height($n) + { + $this->max_height = ( ! eregi("^[[:digit:]]+$", $n)) ? 0 : $n; + } + + // -------------------------------------------------------------------- + + /** + * Set Allowed File Types + * + * @access public + * @param string + * @return void + */ + function set_allowed_types($types) + { + $this->allowed_types = explode('|', $types); + } + + // -------------------------------------------------------------------- + + /** + * Set Image Properties + * + * Uses GD to determine the width/height/type of image + * + * @access public + * @param string + * @return void + */ + function set_image_properties($path = '') + { + if ( ! $this->is_image()) + { + return; + } + + if (function_exists('getimagesize')) + { + if (FALSE !== ($D = @getimagesize($path))) + { + $types = array(1 => 'gif', 2 => 'jpeg', 3 => 'png'); + + $this->image_width = $D['0']; + $this->image_height = $D['1']; + $this->image_type = ( ! isset($types[$D['2']])) ? 'unknown' : $types[$D['2']]; + $this->image_size_str = $D['3']; // string containing height and width + } + } + } + + // -------------------------------------------------------------------- + + /** + * Set XSS Clean + * + * Enables the XSS flag so that the file that was uploaded + * will be run through the XSS filter. + * + * @access public + * @param bool + * @return void + */ + function set_xss_clean($flag = FALSE) + { + $this->xss_clean = ($flag == TRUE) ? TRUE : FALSE; + } + + // -------------------------------------------------------------------- + + /** + * Validate the image + * + * @access public + * @return bool + */ + function is_image() + { + $img_mimes = array( + 'image/gif', + 'image/jpg', + 'image/jpe', + 'image/jpeg', + 'image/pjpeg', + 'image/png', + 'image/x-png' + ); + + + return (in_array($this->file_type, $img_mimes, TRUE)) ? TRUE : FALSE; + } + + // -------------------------------------------------------------------- + + /** + * Verify that the filetype is allowed + * + * @access public + * @return bool + */ + function is_allowed_filetype() + { + if (count($this->allowed_types) == 0) + { + $this->set_error('upload_no_file_types'); + return FALSE; + } + + foreach ($this->allowed_types as $val) + { + $mime = $this->mimes_types(strtolower($val)); + + if (is_array($mime)) + { + if (in_array($this->file_type, $mime, TRUE)) + { + return TRUE; + } + } + else + { + if ($mime == $this->file_type) + { + return TRUE; + } + } + } + + return FALSE; + } + + // -------------------------------------------------------------------- + + /** + * Verify that the file is within the allowed size + * + * @access public + * @return bool + */ + function is_allowed_filesize() + { + if ($this->max_size != 0 AND $this->file_size > $this->max_size) + { + return FALSE; + } + else + { + return TRUE; + } + } + + // -------------------------------------------------------------------- + + /** + * Verify that the image is within the allowed width/height + * + * @access public + * @return bool + */ + function is_allowed_dimensions() + { + if ( ! $this->is_image()) + { + return TRUE; + } + + if (function_exists('getimagesize')) + { + $D = @getimagesize($this->file_temp); + + if ($this->max_width > 0 AND $D['0'] > $this->max_width) + { + return FALSE; + } + + if ($this->max_height > 0 AND $D['1'] > $this->max_height) + { + return FALSE; + } + + return TRUE; + } + + return TRUE; + } + + // -------------------------------------------------------------------- + + /** + * Validate Upload Path + * + * Verifies that it is a valid upload path with proper permissions. + * + * + * @access public + * @return bool + */ + function validate_upload_path() + { + if ($this->upload_path == '') + { + $this->set_error('upload_no_filepath'); + return FALSE; + } + + if (function_exists('realpath') AND @realpath($this->upload_path) !== FALSE) + { + $this->upload_path = str_replace("\\", "/", realpath($this->upload_path)); + } + + if ( ! @is_dir($this->upload_path)) + { + $this->set_error('upload_no_filepath'); + return FALSE; + } + + if ( ! is_writable($this->upload_path)) + { + $this->set_error('upload_not_writable'); + return FALSE; + } + + $this->upload_path = preg_replace("/(.+?)\/*$/", "\\1/", $this->upload_path); + return TRUE; + } + + // -------------------------------------------------------------------- + + /** + * Extract the file extension + * + * @access public + * @param string + * @return string + */ + function get_extension($filename) + { + $x = explode('.', $filename); + return '.'.end($x); + } + + // -------------------------------------------------------------------- + + /** + * Clean the file name for security + * + * @access public + * @param string + * @return string + */ + function clean_file_name($filename) + { + $bad = array( + "", + "'", + "<", + ">", + '"', + '&', + '$', + '=', + ';', + '?', + '/', + "%20", + "%22", + "%3c", // < + "%253c", // < + "%3e", // > + "%0e", // > + "%28", // ( + "%29", // ) + "%2528", // ( + "%26", // & + "%24", // $ + "%3f", // ? + "%3b", // ; + "%3d" // = + ); + + foreach ($bad as $val) + { + $filename = str_replace($val, '', $filename); + } + + return $filename; + } + + // -------------------------------------------------------------------- + + /** + * Runs the file through the XSS clean function + * + * This prevents people from embedding malicious code in their files. + * I'm not sure that it won't negatively affect certain files in unexpected ways, + * but so far I haven't found that it causes trouble. + * + * @access public + * @return void + */ + function do_xss_clean() + { + $file = $this->upload_path.$this->file_name; + + if (filesize($file) == 0) + { + return FALSE; + } + + if ( ! $fp = @fopen($file, 'rb')) + { + return FALSE; + } + + flock($fp, LOCK_EX); + + $data = fread($fp, filesize($file)); + + $CI =& get_instance(); + $data = $CI->input->xss_clean($data); + + fwrite($fp, $data); + flock($fp, LOCK_UN); + fclose($fp); + } + + // -------------------------------------------------------------------- + + /** + * Set an error message + * + * @access public + * @param string + * @return void + */ + function set_error($msg) + { + $CI =& get_instance(); + $CI->lang->load('upload'); + + if (is_array($msg)) + { + foreach ($msg as $val) + { + $msg = ($CI->lang->line($val) == FALSE) ? $val : $CI->lang->line($val); + $this->error_msg[] = $msg; + log_message('error', $msg); + } + } + else + { + $msg = ($CI->lang->line($msg) == FALSE) ? $msg : $CI->lang->line($msg); + $this->error_msg[] = $msg; + log_message('error', $msg); + } + } + + // -------------------------------------------------------------------- + + /** + * Display the error message + * + * @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; + } + + // -------------------------------------------------------------------- + + /** + * List of Mime Types + * + * This is a list of mime types. We use it to validate + * the "allowed types" set by the developer + * + * @access public + * @param string + * @return string + */ + function mimes_types($mime) + { + if (count($this->mimes) == 0) + { + if (@include(APPPATH.'config/mimes'.EXT)) + { + $this->mimes = $mimes; + unset($mimes); + } + } + + return ( ! isset($this->mimes[$mime])) ? FALSE : $this->mimes[$mime]; + } + +} +// END Upload Class ?> \ No newline at end of file diff --git a/system/libraries/User_agent.php b/system/libraries/User_agent.php index afd012e30..b93bd340e 100644 --- a/system/libraries/User_agent.php +++ b/system/libraries/User_agent.php @@ -1,12 +1,12 @@ '; - var $_error_suffix = '

    '; - - - - /** - * Constructor - * - */ - function CI_Validation() - { - $this->CI =& get_instance(); - log_message('debug', "Validation Class Initialized"); - } - - // -------------------------------------------------------------------- - - /** - * Set Fields - * - * This function takes an array of field names as input - * and generates class variables with the same name, which will - * either be blank or contain the $_POST value corresponding to it - * - * @access public - * @param string - * @param string - * @return void - */ - function set_fields($data = '', $field = '') - { - if ($data == '') - { - if (count($this->_fields) == 0) - { - return FALSE; - } - } - else - { - if ( ! is_array($data)) - { - $data = array($data => $field); - } - - if (count($data) > 0) - { - $this->_fields = $data; - } - } - - foreach($this->_fields as $key => $val) - { - $this->$key = ( ! isset($_POST[$key]) OR is_array($_POST[$key])) ? '' : $this->prep_for_form($_POST[$key]); - - $error = $key.'_error'; - if ( ! isset($this->$error)) - { - $this->$error = ''; - } - } - } - - // -------------------------------------------------------------------- - - /** - * Set Rules - * - * This function takes an array of field names and validation - * rules as input ad simply stores is for use later. - * - * @access public - * @param mixed - * @param string - * @return void - */ - function set_rules($data, $rules = '') - { - if ( ! is_array($data)) - { - if ($rules == '') - return; - - $data[$data] = $rules; - } - - foreach ($data as $key => $val) - { - $this->_rules[$key] = $val; - } - } - - // -------------------------------------------------------------------- - - /** - * Set Error Message - * - * Lets users set their own error messages on the fly. Note: The key - * name has to match the function name that it corresponds to. - * - * @access public - * @param string - * @param string - * @return string - */ - function set_message($lang, $val = '') - { - if ( ! is_array($lang)) - { - $lang = array($lang => $val); - } - - $this->_error_messages = array_merge($this->_error_messages, $lang); - } - - // -------------------------------------------------------------------- - - /** - * Set The Error Delimiter - * - * Permits a prefix/suffix to be added to each error message - * - * @access public - * @param string - * @param string - * @return void - */ - function set_error_delimiters($prefix = '

    ', $suffix = '

    ') - { - $this->_error_prefix = $prefix; - $this->_error_suffix = $suffix; - } - - // -------------------------------------------------------------------- - - /** - * Run the Validator - * - * This function does all the work. - * - * @access public - * @return bool - */ - function run() - { - // Do we even have any data to process? Mm? - if (count($_POST) == 0 OR count($this->_rules) == 0) - { - return FALSE; - } - - // Load the language file containing error messages - $this->CI->lang->load('validation'); - - // Cycle through the rules and test for errors - foreach ($this->_rules as $field => $rules) - { - //Explode out the rules! - $ex = explode('|', $rules); - - // Is the field required? If not, if the field is blank we'll move on to the next text - if ( ! in_array('required', $ex, TRUE) AND strpos($rules, 'callback_') === FALSE) - { - if ( ! isset($_POST[$field]) OR $_POST[$field] == '') - { - continue; - } - } - - /* - * Are we dealing with an "isset" rule? - * - * Before going further, we'll see if one of the rules - * is to check whether the item is set (typically this - * applies only to checkboxes). If so, we'll - * test for it here since there's not reason to go - * further - */ - if ( ! isset($_POST[$field])) - { - if (in_array('isset', $ex, TRUE) OR in_array('required', $ex)) - { - if ( ! isset($this->_error_messages['isset'])) - { - if (FALSE === ($line = $this->CI->lang->line('isset'))) - { - $line = 'The field was not set'; - } - } - else - { - $line = $this->_error_messages['isset']; - } - - $field = ( ! isset($this->_fields[$field])) ? $field : $this->_fields[$field]; - $this->_error_array[] = sprintf($line, $field); - } - - continue; - } - - /* - * Set the current field - * - * The various prepping functions need to know the - * current field name so they can do this: - * - * $_POST[$this->_current_field] == 'bla bla'; - */ - $this->_current_field = $field; - - // Cycle through the rules! - foreach ($ex As $rule) - { - // Is the rule a callback? - $callback = FALSE; - if (substr($rule, 0, 9) == 'callback_') - { - $rule = substr($rule, 9); - $callback = TRUE; - } - - // Strip the parameter (if exists) from the rule - // Rules can contain a parameter: max_length[5] - $param = FALSE; - if (preg_match("/(.*?)\[(.*?)\]/", $rule, $match)) - { - $rule = $match[1]; - $param = $match[2]; - } - - // Call the function that corresponds to the rule - if ($callback === TRUE) - { - if ( ! method_exists($this->CI, $rule)) - { - continue; - } - - $result = $this->CI->$rule($_POST[$field], $param); - - // If the field isn't required and we just processed a callback we'll move on... - if ( ! in_array('required', $ex, TRUE) AND $result !== FALSE) - { - continue 2; - } - - } - else - { - if ( ! method_exists($this, $rule)) - { - /* - * Run the native PHP function if called for - * - * If our own wrapper function doesn't exist we see - * if a native PHP function does. Users can use - * any native PHP function call that has one param. - */ - if (function_exists($rule)) - { - $_POST[$field] = $rule($_POST[$field]); - $this->$field = $_POST[$field]; - } - - continue; - } - - $result = $this->$rule($_POST[$field], $param); - } - - // Did the rule test negatively? If so, grab the error. - if ($result === FALSE) - { - if ( ! isset($this->_error_messages[$rule])) - { - if (FALSE === ($line = $this->CI->lang->line($rule))) - { - $line = 'Unable to access an error message corresponding to your field name.'; - } - } - else - { - $line = $this->_error_messages[$rule];; - } - - // Build the error message - $mfield = ( ! isset($this->_fields[$field])) ? $field : $this->_fields[$field]; - $mparam = ( ! isset($this->_fields[$param])) ? $param : $this->_fields[$param]; - $message = sprintf($line, $mfield, $mparam); - - // Set the error variable. Example: $this->username_error - $error = $field.'_error'; - $this->$error = $this->_error_prefix.$message.$this->_error_suffix; - - // Add the error to the error array - $this->_error_array[] = $message; - continue 2; - } - } - - } - - $total_errors = count($this->_error_array); - - /* - * Recompile the class variables - * - * If any prepping functions were called the $_POST data - * might now be different then the corresponding class - * variables so we'll set them anew. - */ - if ($total_errors > 0) - { - $this->_safe_form_data = TRUE; - } - - $this->set_fields(); - - // Did we end up with any errors? - if ($total_errors == 0) - { - return TRUE; - } - - // Generate the error string - foreach ($this->_error_array as $val) - { - $this->error_string .= $this->_error_prefix.$val.$this->_error_suffix."\n"; - } - - return FALSE; - } - - // -------------------------------------------------------------------- - - /** - * Required - * - * @access public - * @param string - * @return bool - */ - function required($str) - { - if ( ! is_array($str)) - { - return (trim($str) == '') ? FALSE : TRUE; - } - else - { - return ( ! empty($str)); - } - } - - // -------------------------------------------------------------------- - - /** - * Match one field to another - * - * @access public - * @param string - * @return bool - */ - function matches($str, $field) - { - if ( ! isset($_POST[$field])) - { - return FALSE; - } - - return ($str !== $_POST[$field]) ? FALSE : TRUE; - } - - // -------------------------------------------------------------------- - - /** - * Minimum Length - * - * @access public - * @param string - * @return bool - */ - function min_length($str, $val) - { - if ( ! is_numeric($val)) - { - return FALSE; - } - - return (strlen($str) < $val) ? FALSE : TRUE; - } - - // -------------------------------------------------------------------- - - /** - * Max Length - * - * @access public - * @param string - * @return bool - */ - function max_length($str, $val) - { - if ( ! is_numeric($val)) - { - return FALSE; - } - - return (strlen($str) > $val) ? FALSE : TRUE; - } - - // -------------------------------------------------------------------- - - /** - * Exact Length - * - * @access public - * @param string - * @return bool - */ - function exact_length($str, $val) - { - if ( ! is_numeric($val)) - { - return FALSE; - } - - return (strlen($str) != $val) ? FALSE : TRUE; - } - - // -------------------------------------------------------------------- - - /** - * Valid Email - * - * @access public - * @param string - * @return bool - */ - function valid_email($str) - { - return ( ! preg_match("/^([a-z0-9\+_\-]+)(\.[a-z0-9\+_\-]+)*@([a-z0-9\-]+\.)+[a-z]{2,6}$/ix", $str)) ? FALSE : TRUE; - } - - // -------------------------------------------------------------------- - - /** - * Validate IP Address - * - * @access public - * @param string - * @return string - */ - function valid_ip($ip) - { - return ( ! preg_match( "/^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$/", $ip)) ? FALSE : TRUE; - } - - // -------------------------------------------------------------------- - - /** - * Alpha - * - * @access public - * @param string - * @return bool - */ - function alpha($str) - { - return ( ! preg_match("/^([-a-z])+$/i", $str)) ? FALSE : TRUE; - } - - // -------------------------------------------------------------------- - - /** - * Alpha-numeric - * - * @access public - * @param string - * @return bool - */ - function alpha_numeric($str) - { - return ( ! preg_match("/^([-a-z0-9])+$/i", $str)) ? FALSE : TRUE; - } - - // -------------------------------------------------------------------- - - /** - * Alpha-numeric with underscores and dashes - * - * @access public - * @param string - * @return bool - */ - function alpha_dash($str) - { - return ( ! preg_match("/^([-a-z0-9_-])+$/i", $str)) ? FALSE : TRUE; - } - - // -------------------------------------------------------------------- - - /** - * Numeric - * - * @access public - * @param int - * @return bool - */ - function numeric($str) - { - return ( ! ereg("^[0-9\.]+$", $str)) ? FALSE : TRUE; - } - - // -------------------------------------------------------------------- - - /** - * Is Numeric - * - * @access public - * @param string - * @return bool - */ - function is_numeric($str) - { - return ( ! is_numeric($str)) ? FALSE : TRUE; - } - - // -------------------------------------------------------------------- - - /** - * Set Select - * - * Enables pull-down lists to be set to the value the user - * selected in the event of an error - * - * @access public - * @param string - * @param string - * @return string - */ - function set_select($field = '', $value = '') - { - if ($field == '' OR $value == '' OR ! isset($_POST[$field])) - { - return ''; - } - - if ($_POST[$field] == $value) - { - return ' selected="selected"'; - } - } - - // -------------------------------------------------------------------- - - /** - * Set Radio - * - * Enables radio buttons to be set to the value the user - * selected in the event of an error - * - * @access public - * @param string - * @param string - * @return string - */ - function set_radio($field = '', $value = '') - { - if ($field == '' OR $value == '' OR ! isset($_POST[$field])) - { - return ''; - } - - if ($_POST[$field] == $value) - { - return ' checked="checked"'; - } - } - - // -------------------------------------------------------------------- - - /** - * Set Checkbox - * - * Enables checkboxes to be set to the value the user - * selected in the event of an error - * - * @access public - * @param string - * @param string - * @return string - */ - function set_checkbox($field = '', $value = '') - { - if ($field == '' OR $value == '' OR ! isset($_POST[$field])) - { - return ''; - } - - if ($_POST[$field] == $value) - { - return ' checked="checked"'; - } - } - - // -------------------------------------------------------------------- - - /** - * Prep data for form - * - * This function allows HTML to be safely shown in a form. - * Special characters are converted. - * - * @access public - * @param string - * @return string - */ - function prep_for_form($str = '') - { - if ($this->_safe_form_data == FALSE OR $str == '') - { - return $str; - } - - return str_replace(array("'", '"', '<', '>'), array("'", """, '<', '>'), stripslashes($str)); - } - - // -------------------------------------------------------------------- - - /** - * Prep URL - * - * @access public - * @param string - * @return string - */ - function prep_url($str = '') - { - if ($str == 'http://' OR $str == '') - { - $_POST[$this->_current_field] = ''; - return; - } - - if (substr($str, 0, 7) != 'http://' && substr($str, 0, 8) != 'https://') - { - $str = 'http://'.$str; - } - - $_POST[$this->_current_field] = $str; - } - - // -------------------------------------------------------------------- - - /** - * Strip Image Tags - * - * @access public - * @param string - * @return string - */ - function strip_image_tags($str) - { - $_POST[$this->_current_field] = $this->input->strip_image_tags($str); - } - - // -------------------------------------------------------------------- - - /** - * XSS Clean - * - * @access public - * @param string - * @return string - */ - function xss_clean($str) - { - $_POST[$this->_current_field] = $this->CI->input->xss_clean($str); - } - - // -------------------------------------------------------------------- - - /** - * Convert PHP tags to entities - * - * @access public - * @param string - * @return string - */ - function encode_php_tags($str) - { - $_POST[$this->_current_field] = str_replace(array(''), array('<?php', '<?PHP', '<?', '?>'), $str); - } - -} -// END Validation Class +'; + var $_error_suffix = '

    '; + + + + /** + * Constructor + * + */ + function CI_Validation() + { + $this->CI =& get_instance(); + log_message('debug', "Validation Class Initialized"); + } + + // -------------------------------------------------------------------- + + /** + * Set Fields + * + * This function takes an array of field names as input + * and generates class variables with the same name, which will + * either be blank or contain the $_POST value corresponding to it + * + * @access public + * @param string + * @param string + * @return void + */ + function set_fields($data = '', $field = '') + { + if ($data == '') + { + if (count($this->_fields) == 0) + { + return FALSE; + } + } + else + { + if ( ! is_array($data)) + { + $data = array($data => $field); + } + + if (count($data) > 0) + { + $this->_fields = $data; + } + } + + foreach($this->_fields as $key => $val) + { + $this->$key = ( ! isset($_POST[$key]) OR is_array($_POST[$key])) ? '' : $this->prep_for_form($_POST[$key]); + + $error = $key.'_error'; + if ( ! isset($this->$error)) + { + $this->$error = ''; + } + } + } + + // -------------------------------------------------------------------- + + /** + * Set Rules + * + * This function takes an array of field names and validation + * rules as input ad simply stores is for use later. + * + * @access public + * @param mixed + * @param string + * @return void + */ + function set_rules($data, $rules = '') + { + if ( ! is_array($data)) + { + if ($rules == '') + return; + + $data[$data] = $rules; + } + + foreach ($data as $key => $val) + { + $this->_rules[$key] = $val; + } + } + + // -------------------------------------------------------------------- + + /** + * Set Error Message + * + * Lets users set their own error messages on the fly. Note: The key + * name has to match the function name that it corresponds to. + * + * @access public + * @param string + * @param string + * @return string + */ + function set_message($lang, $val = '') + { + if ( ! is_array($lang)) + { + $lang = array($lang => $val); + } + + $this->_error_messages = array_merge($this->_error_messages, $lang); + } + + // -------------------------------------------------------------------- + + /** + * Set The Error Delimiter + * + * Permits a prefix/suffix to be added to each error message + * + * @access public + * @param string + * @param string + * @return void + */ + function set_error_delimiters($prefix = '

    ', $suffix = '

    ') + { + $this->_error_prefix = $prefix; + $this->_error_suffix = $suffix; + } + + // -------------------------------------------------------------------- + + /** + * Run the Validator + * + * This function does all the work. + * + * @access public + * @return bool + */ + function run() + { + // Do we even have any data to process? Mm? + if (count($_POST) == 0 OR count($this->_rules) == 0) + { + return FALSE; + } + + // Load the language file containing error messages + $this->CI->lang->load('validation'); + + // Cycle through the rules and test for errors + foreach ($this->_rules as $field => $rules) + { + //Explode out the rules! + $ex = explode('|', $rules); + + // Is the field required? If not, if the field is blank we'll move on to the next text + if ( ! in_array('required', $ex, TRUE) AND strpos($rules, 'callback_') === FALSE) + { + if ( ! isset($_POST[$field]) OR $_POST[$field] == '') + { + continue; + } + } + + /* + * Are we dealing with an "isset" rule? + * + * Before going further, we'll see if one of the rules + * is to check whether the item is set (typically this + * applies only to checkboxes). If so, we'll + * test for it here since there's not reason to go + * further + */ + if ( ! isset($_POST[$field])) + { + if (in_array('isset', $ex, TRUE) OR in_array('required', $ex)) + { + if ( ! isset($this->_error_messages['isset'])) + { + if (FALSE === ($line = $this->CI->lang->line('isset'))) + { + $line = 'The field was not set'; + } + } + else + { + $line = $this->_error_messages['isset']; + } + + $field = ( ! isset($this->_fields[$field])) ? $field : $this->_fields[$field]; + $this->_error_array[] = sprintf($line, $field); + } + + continue; + } + + /* + * Set the current field + * + * The various prepping functions need to know the + * current field name so they can do this: + * + * $_POST[$this->_current_field] == 'bla bla'; + */ + $this->_current_field = $field; + + // Cycle through the rules! + foreach ($ex As $rule) + { + // Is the rule a callback? + $callback = FALSE; + if (substr($rule, 0, 9) == 'callback_') + { + $rule = substr($rule, 9); + $callback = TRUE; + } + + // Strip the parameter (if exists) from the rule + // Rules can contain a parameter: max_length[5] + $param = FALSE; + if (preg_match("/(.*?)\[(.*?)\]/", $rule, $match)) + { + $rule = $match[1]; + $param = $match[2]; + } + + // Call the function that corresponds to the rule + if ($callback === TRUE) + { + if ( ! method_exists($this->CI, $rule)) + { + continue; + } + + $result = $this->CI->$rule($_POST[$field], $param); + + // If the field isn't required and we just processed a callback we'll move on... + if ( ! in_array('required', $ex, TRUE) AND $result !== FALSE) + { + continue 2; + } + + } + else + { + if ( ! method_exists($this, $rule)) + { + /* + * Run the native PHP function if called for + * + * If our own wrapper function doesn't exist we see + * if a native PHP function does. Users can use + * any native PHP function call that has one param. + */ + if (function_exists($rule)) + { + $_POST[$field] = $rule($_POST[$field]); + $this->$field = $_POST[$field]; + } + + continue; + } + + $result = $this->$rule($_POST[$field], $param); + } + + // Did the rule test negatively? If so, grab the error. + if ($result === FALSE) + { + if ( ! isset($this->_error_messages[$rule])) + { + if (FALSE === ($line = $this->CI->lang->line($rule))) + { + $line = 'Unable to access an error message corresponding to your field name.'; + } + } + else + { + $line = $this->_error_messages[$rule];; + } + + // Build the error message + $mfield = ( ! isset($this->_fields[$field])) ? $field : $this->_fields[$field]; + $mparam = ( ! isset($this->_fields[$param])) ? $param : $this->_fields[$param]; + $message = sprintf($line, $mfield, $mparam); + + // Set the error variable. Example: $this->username_error + $error = $field.'_error'; + $this->$error = $this->_error_prefix.$message.$this->_error_suffix; + + // Add the error to the error array + $this->_error_array[] = $message; + continue 2; + } + } + + } + + $total_errors = count($this->_error_array); + + /* + * Recompile the class variables + * + * If any prepping functions were called the $_POST data + * might now be different then the corresponding class + * variables so we'll set them anew. + */ + if ($total_errors > 0) + { + $this->_safe_form_data = TRUE; + } + + $this->set_fields(); + + // Did we end up with any errors? + if ($total_errors == 0) + { + return TRUE; + } + + // Generate the error string + foreach ($this->_error_array as $val) + { + $this->error_string .= $this->_error_prefix.$val.$this->_error_suffix."\n"; + } + + return FALSE; + } + + // -------------------------------------------------------------------- + + /** + * Required + * + * @access public + * @param string + * @return bool + */ + function required($str) + { + if ( ! is_array($str)) + { + return (trim($str) == '') ? FALSE : TRUE; + } + else + { + return ( ! empty($str)); + } + } + + // -------------------------------------------------------------------- + + /** + * Match one field to another + * + * @access public + * @param string + * @return bool + */ + function matches($str, $field) + { + if ( ! isset($_POST[$field])) + { + return FALSE; + } + + return ($str !== $_POST[$field]) ? FALSE : TRUE; + } + + // -------------------------------------------------------------------- + + /** + * Minimum Length + * + * @access public + * @param string + * @return bool + */ + function min_length($str, $val) + { + if ( ! is_numeric($val)) + { + return FALSE; + } + + return (strlen($str) < $val) ? FALSE : TRUE; + } + + // -------------------------------------------------------------------- + + /** + * Max Length + * + * @access public + * @param string + * @return bool + */ + function max_length($str, $val) + { + if ( ! is_numeric($val)) + { + return FALSE; + } + + return (strlen($str) > $val) ? FALSE : TRUE; + } + + // -------------------------------------------------------------------- + + /** + * Exact Length + * + * @access public + * @param string + * @return bool + */ + function exact_length($str, $val) + { + if ( ! is_numeric($val)) + { + return FALSE; + } + + return (strlen($str) != $val) ? FALSE : TRUE; + } + + // -------------------------------------------------------------------- + + /** + * Valid Email + * + * @access public + * @param string + * @return bool + */ + function valid_email($str) + { + return ( ! preg_match("/^([a-z0-9\+_\-]+)(\.[a-z0-9\+_\-]+)*@([a-z0-9\-]+\.)+[a-z]{2,6}$/ix", $str)) ? FALSE : TRUE; + } + + // -------------------------------------------------------------------- + + /** + * Validate IP Address + * + * @access public + * @param string + * @return string + */ + function valid_ip($ip) + { + return ( ! preg_match( "/^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$/", $ip)) ? FALSE : TRUE; + } + + // -------------------------------------------------------------------- + + /** + * Alpha + * + * @access public + * @param string + * @return bool + */ + function alpha($str) + { + return ( ! preg_match("/^([-a-z])+$/i", $str)) ? FALSE : TRUE; + } + + // -------------------------------------------------------------------- + + /** + * Alpha-numeric + * + * @access public + * @param string + * @return bool + */ + function alpha_numeric($str) + { + return ( ! preg_match("/^([-a-z0-9])+$/i", $str)) ? FALSE : TRUE; + } + + // -------------------------------------------------------------------- + + /** + * Alpha-numeric with underscores and dashes + * + * @access public + * @param string + * @return bool + */ + function alpha_dash($str) + { + return ( ! preg_match("/^([-a-z0-9_-])+$/i", $str)) ? FALSE : TRUE; + } + + // -------------------------------------------------------------------- + + /** + * Numeric + * + * @access public + * @param int + * @return bool + */ + function numeric($str) + { + return ( ! ereg("^[0-9\.]+$", $str)) ? FALSE : TRUE; + } + + // -------------------------------------------------------------------- + + /** + * Is Numeric + * + * @access public + * @param string + * @return bool + */ + function is_numeric($str) + { + return ( ! is_numeric($str)) ? FALSE : TRUE; + } + + // -------------------------------------------------------------------- + + /** + * Set Select + * + * Enables pull-down lists to be set to the value the user + * selected in the event of an error + * + * @access public + * @param string + * @param string + * @return string + */ + function set_select($field = '', $value = '') + { + if ($field == '' OR $value == '' OR ! isset($_POST[$field])) + { + return ''; + } + + if ($_POST[$field] == $value) + { + return ' selected="selected"'; + } + } + + // -------------------------------------------------------------------- + + /** + * Set Radio + * + * Enables radio buttons to be set to the value the user + * selected in the event of an error + * + * @access public + * @param string + * @param string + * @return string + */ + function set_radio($field = '', $value = '') + { + if ($field == '' OR $value == '' OR ! isset($_POST[$field])) + { + return ''; + } + + if ($_POST[$field] == $value) + { + return ' checked="checked"'; + } + } + + // -------------------------------------------------------------------- + + /** + * Set Checkbox + * + * Enables checkboxes to be set to the value the user + * selected in the event of an error + * + * @access public + * @param string + * @param string + * @return string + */ + function set_checkbox($field = '', $value = '') + { + if ($field == '' OR $value == '' OR ! isset($_POST[$field])) + { + return ''; + } + + if ($_POST[$field] == $value) + { + return ' checked="checked"'; + } + } + + // -------------------------------------------------------------------- + + /** + * Prep data for form + * + * This function allows HTML to be safely shown in a form. + * Special characters are converted. + * + * @access public + * @param string + * @return string + */ + function prep_for_form($str = '') + { + if ($this->_safe_form_data == FALSE OR $str == '') + { + return $str; + } + + return str_replace(array("'", '"', '<', '>'), array("'", """, '<', '>'), stripslashes($str)); + } + + // -------------------------------------------------------------------- + + /** + * Prep URL + * + * @access public + * @param string + * @return string + */ + function prep_url($str = '') + { + if ($str == 'http://' OR $str == '') + { + $_POST[$this->_current_field] = ''; + return; + } + + if (substr($str, 0, 7) != 'http://' && substr($str, 0, 8) != 'https://') + { + $str = 'http://'.$str; + } + + $_POST[$this->_current_field] = $str; + } + + // -------------------------------------------------------------------- + + /** + * Strip Image Tags + * + * @access public + * @param string + * @return string + */ + function strip_image_tags($str) + { + $_POST[$this->_current_field] = $this->input->strip_image_tags($str); + } + + // -------------------------------------------------------------------- + + /** + * XSS Clean + * + * @access public + * @param string + * @return string + */ + function xss_clean($str) + { + $_POST[$this->_current_field] = $this->CI->input->xss_clean($str); + } + + // -------------------------------------------------------------------- + + /** + * Convert PHP tags to entities + * + * @access public + * @param string + * @return string + */ + function encode_php_tags($str) + { + $_POST[$this->_current_field] = str_replace(array(''), array('<?php', '<?PHP', '<?', '?>'), $str); + } + +} +// END Validation Class ?> \ No newline at end of file diff --git a/system/libraries/Xmlrpc.php b/system/libraries/Xmlrpc.php index 2d9a4c11b..49747e481 100644 --- a/system/libraries/Xmlrpc.php +++ b/system/libraries/Xmlrpc.php @@ -1,1412 +1,1412 @@ -xmlrpcName = $this->xmlrpcName; - $this->xmlrpc_backslash = chr(92).chr(92); - - // Types for info sent back and forth - $this->xmlrpcTypes = array( - $this->xmlrpcI4 => '1', - $this->xmlrpcInt => '1', - $this->xmlrpcBoolean => '1', - $this->xmlrpcString => '1', - $this->xmlrpcDouble => '1', - $this->xmlrpcDateTime => '1', - $this->xmlrpcBase64 => '1', - $this->xmlrpcArray => '2', - $this->xmlrpcStruct => '3' - ); - - // Array of Valid Parents for Various XML-RPC elements - $this->valid_parents = array('BOOLEAN' => array('VALUE'), - 'I4' => array('VALUE'), - 'INT' => array('VALUE'), - 'STRING' => array('VALUE'), - 'DOUBLE' => array('VALUE'), - 'DATETIME.ISO8601' => array('VALUE'), - 'BASE64' => array('VALUE'), - 'ARRAY' => array('VALUE'), - 'STRUCT' => array('VALUE'), - 'PARAM' => array('PARAMS'), - 'METHODNAME' => array('METHODCALL'), - 'PARAMS' => array('METHODCALL', 'METHODRESPONSE'), - 'MEMBER' => array('STRUCT'), - 'NAME' => array('MEMBER'), - 'DATA' => array('ARRAY'), - 'FAULT' => array('METHODRESPONSE'), - 'VALUE' => array('MEMBER', 'DATA', 'PARAM', 'FAULT') - ); - - - // XML-RPC Responses - $this->xmlrpcerr['unknown_method'] = '1'; - $this->xmlrpcstr['unknown_method'] = 'This is not a known method for this XML-RPC Server'; - $this->xmlrpcerr['invalid_return'] = '2'; - $this->xmlrpcstr['invalid_return'] = 'The XML data receieved was either invalid or not in the correct form for XML-RPC. Turn on debugging to examine the XML data further.'; - $this->xmlrpcerr['incorrect_params'] = '3'; - $this->xmlrpcstr['incorrect_params'] = 'Incorrect parameters were passed to method'; - $this->xmlrpcerr['introspect_unknown'] = '4'; - $this->xmlrpcstr['introspect_unknown'] = "Cannot inspect signature for request: method unknown"; - $this->xmlrpcerr['http_error'] = '5'; - $this->xmlrpcstr['http_error'] = "Did not receive a '200 OK' response from remote server."; - $this->xmlrpcerr['no_data'] = '6'; - $this->xmlrpcstr['no_data'] ='No data received from server.'; - - $this->initialize($config); - - log_message('debug', "XML-RPC Class Initialized"); - } - - - //------------------------------------- - // Initialize Prefs - //------------------------------------- - - function initialize($config = array()) - { - if (sizeof($config) > 0) - { - foreach ($config as $key => $val) - { - if (isset($this->$key)) - { - $this->$key = $val; - } - } - } - } - // END - - //------------------------------------- - // Take URL and parse it - //------------------------------------- - - function server($url, $port=80) - { - if (substr($url, 0, 4) != "http") - { - $url = "http://".$url; - } - - $parts = parse_url($url); - - $path = (!isset($parts['path'])) ? '/' : $parts['path']; - - if (isset($parts['query']) && $parts['query'] != '') - { - $path .= '?'.$parts['query']; - } - - $this->client = new XML_RPC_Client($path, $parts['host'], $port); - } - // END - - //------------------------------------- - // Set Timeout - //------------------------------------- - - function timeout($seconds=5) - { - if ( ! is_null($this->client) && is_int($seconds)) - { - $this->client->timeout = $seconds; - } - } - // END - - //------------------------------------- - // Set Methods - //------------------------------------- - - function method($function) - { - $this->method = $function; - } - // END - - //------------------------------------- - // Take Array of Data and Create Objects - //------------------------------------- - - function request($incoming) - { - if ( ! is_array($incoming)) - { - // Send Error - } - - foreach($incoming as $key => $value) - { - $this->data[$key] = $this->values_parsing($value); - } - } - // END - - - //------------------------------------- - // Set Debug - //------------------------------------- - - function set_debug($flag = TRUE) - { - $this->debug = ($flag == TRUE) ? TRUE : FALSE; - } - - //------------------------------------- - // Values Parsing - //------------------------------------- - - function values_parsing($value, $return = FALSE) - { - if (is_array($value) && isset($value['0'])) - { - if ( ! isset($value['1']) OR ! isset($this->xmlrpcTypes[strtolower($value['1'])])) - { - $temp = new XML_RPC_Values($value['0'], 'string'); - } - elseif(is_array($value['0']) && ($value['1'] == 'struct' OR $value['1'] == 'array')) - { - while (list($k) = each($value['0'])) - { - $value['0'][$k] = $this->values_parsing($value['0'][$k], TRUE); - } - - $temp = new XML_RPC_Values($value['0'], $value['1']); - } - else - { - $temp = new XML_RPC_Values($value['0'], $value['1']); - } - } - else - { - $temp = new XML_RPC_Values($value, 'string'); - } - - return $temp; - } - // END - - - //------------------------------------- - // Sends XML-RPC Request - //------------------------------------- - - function send_request() - { - $this->message = new XML_RPC_Message($this->method,$this->data); - $this->message->debug = $this->debug; - - if ( ! $this->result = $this->client->send($this->message)) - { - $this->error = $this->result->errstr; - return FALSE; - } - elseif( ! is_object($this->result->val)) - { - $this->error = $this->result->errstr; - return FALSE; - } - - $this->response = $this->result->decode(); - - return TRUE; - } - // END - - //------------------------------------- - // Returns Error - //------------------------------------- - - function display_error() - { - return $this->error; - } - // END - - //------------------------------------- - // Returns Remote Server Response - //------------------------------------- - - function display_response() - { - return $this->response; - } - // END - - //------------------------------------- - // Sends an Error Message for Server Request - //------------------------------------- - - function send_error_message($number, $message) - { - return new XML_RPC_Response('0',$number, $message); - } - // END - - - //------------------------------------- - // Send Response for Server Request - //------------------------------------- - - function send_response($response) - { - // $response should be array of values, which will be parsed - // based on their data and type into a valid group of XML-RPC values - - $response = $this->values_parsing($response); - - return new XML_RPC_Response($response); - } - // END - -} // END XML_RPC Class - - - -/** - * XML-RPC Client class - * - * @category XML-RPC - * @author Paul Burdick - * @link http://www.codeigniter.com/user_guide/libraries/xmlrpc.html - */ -class XML_RPC_Client extends CI_Xmlrpc -{ - var $path = ''; - var $server = ''; - var $port = 80; - var $errno = ''; - var $errstring = ''; - var $timeout = 5; - var $no_multicall = false; - - function XML_RPC_Client($path, $server, $port=80) - { - parent::CI_Xmlrpc(); - - $this->port = $port; - $this->server = $server; - $this->path = $path; - } - - function send($msg) - { - if (is_array($msg)) - { - // Multi-call disabled - $r = new XML_RPC_Response(0, $this->xmlrpcerr['multicall_recursion'],$this->xmlrpcstr['multicall_recursion']); - return $r; - } - - return $this->sendPayload($msg); - } - - function sendPayload($msg) - { - $fp = @fsockopen($this->server, $this->port,$this->errno, $this->errstr, $this->timeout); - - if (! is_resource($fp)) - { - error_log($this->xmlrpcstr['http_error']); - $r = new XML_RPC_Response(0, $this->xmlrpcerr['http_error'],$this->xmlrpcstr['http_error']); - return $r; - } - - if(empty($msg->payload)) - { - // $msg = XML_RPC_Messages - $msg->createPayload(); - } - - $r = "\r\n"; - $op = "POST {$this->path} HTTP/1.0$r"; - $op .= "Host: {$this->server}$r"; - $op .= "Content-Type: text/xml$r"; - $op .= "User-Agent: {$this->xmlrpcName}$r"; - $op .= "Content-Length: ".strlen($msg->payload). "$r$r"; - $op .= $msg->payload; - - - if (!fputs($fp, $op, strlen($op))) - { - error_log($this->xmlrpcstr['http_error']); - $r = new XML_RPC_Response(0, $this->xmlrpcerr['http_error'], $this->xmlrpcstr['http_error']); - return $r; - } - $resp = $msg->parseResponse($fp); - fclose($fp); - return $resp; - } - -} // end class XML_RPC_Client - - -/** - * XML-RPC Response class - * - * @category XML-RPC - * @author Paul Burdick - * @link http://www.codeigniter.com/user_guide/libraries/xmlrpc.html - */ -class XML_RPC_Response -{ - var $val = 0; - var $errno = 0; - var $errstr = ''; - var $headers = array(); - - function XML_RPC_Response($val, $code = 0, $fstr = '') - { - if ($code != 0) - { - // error - $this->errno = $code; - $this->errstr = htmlentities($fstr); - } - else if (!is_object($val)) - { - // programmer error, not an object - error_log("Invalid type '" . gettype($val) . "' (value: $val) passed to XML_RPC_Response. Defaulting to empty value."); - $this->val = new XML_RPC_Values(); - } - else - { - $this->val = $val; - } - } - - function faultCode() - { - return $this->errno; - } - - function faultString() - { - return $this->errstr; - } - - function value() - { - return $this->val; - } - - function prepare_response() - { - $result = "\n"; - if ($this->errno) - { - $result .= ' - - - - faultCode - ' . $this->errno . ' - - - faultString - ' . $this->errstr . ' - - - -'; - } - else - { - $result .= "\n\n" . - $this->val->serialize_class() . - "\n"; - } - $result .= "\n"; - return $result; - } - - function decode($array=FALSE) - { - $CI =& get_instance(); - - if ($array !== FALSE && is_array($array)) - { - while (list($key) = each($array)) - { - if (is_array($array[$key])) - { - $array[$key] = $this->decode($array[$key]); - } - else - { - $array[$key] = $CI->input->xss_clean($array[$key]); - } - } - - $result = $array; - } - else - { - $result = $this->xmlrpc_decoder($this->val); - - if (is_array($result)) - { - $result = $this->decode($result); - } - else - { - $result = $CI->input->xss_clean($result); - } - } - - return $result; - } - - - - //------------------------------------- - // XML-RPC Object to PHP Types - //------------------------------------- - - function xmlrpc_decoder($xmlrpc_val) - { - $kind = $xmlrpc_val->kindOf(); - - if($kind == 'scalar') - { - return $xmlrpc_val->scalarval(); - } - elseif($kind == 'array') - { - reset($xmlrpc_val->me); - list($a,$b) = each($xmlrpc_val->me); - $size = sizeof($b); - - $arr = array(); - - for($i = 0; $i < $size; $i++) - { - $arr[] = $this->xmlrpc_decoder($xmlrpc_val->me['array'][$i]); - } - return $arr; - } - elseif($kind == 'struct') - { - reset($xmlrpc_val->me['struct']); - $arr = array(); - - while(list($key,$value) = each($xmlrpc_val->me['struct'])) - { - $arr[$key] = $this->xmlrpc_decoder($value); - } - return $arr; - } - } - - - //------------------------------------- - // ISO-8601 time to server or UTC time - //------------------------------------- - - function iso8601_decode($time, $utc=0) - { - // return a timet in the localtime, or UTC - $t = 0; - if (ereg("([0-9]{4})([0-9]{2})([0-9]{2})T([0-9]{2}):([0-9]{2}):([0-9]{2})", $time, $regs)) - { - if ($utc == 1) - $t = gmmktime($regs[4], $regs[5], $regs[6], $regs[2], $regs[3], $regs[1]); - else - $t = mktime($regs[4], $regs[5], $regs[6], $regs[2], $regs[3], $regs[1]); - } - return $t; - } - -} // End Response Class - - - -/** - * XML-RPC Message class - * - * @category XML-RPC - * @author Paul Burdick - * @link http://www.codeigniter.com/user_guide/libraries/xmlrpc.html - */ -class XML_RPC_Message extends CI_Xmlrpc -{ - var $payload; - var $method_name; - var $params = array(); - var $xh = array(); - - function XML_RPC_Message($method, $pars=0) - { - parent::CI_Xmlrpc(); - - $this->method_name = $method; - if (is_array($pars) && sizeof($pars) > 0) - { - for($i=0; $iparams[] = $pars[$i]; - } - } - } - - //------------------------------------- - // Create Payload to Send - //------------------------------------- - - function createPayload() - { - $this->payload = "\r\n\r\n"; - $this->payload .= '' . $this->method_name . "\r\n"; - $this->payload .= "\r\n"; - - for($i=0; $iparams); $i++) - { - // $p = XML_RPC_Values - $p = $this->params[$i]; - $this->payload .= "\r\n".$p->serialize_class()."\r\n"; - } - - $this->payload .= "\r\n\r\n"; - } - - //------------------------------------- - // Parse External XML-RPC Server's Response - //------------------------------------- - - function parseResponse($fp) - { - $data = ''; - - while($datum = fread($fp, 4096)) - { - $data .= $datum; - } - - //------------------------------------- - // DISPLAY HTTP CONTENT for DEBUGGING - //------------------------------------- - - if ($this->debug === TRUE) - { - echo "
    ";
    -			echo "---DATA---\n" . htmlspecialchars($data) . "\n---END DATA---\n\n";
    -			echo "
    "; - } - - //------------------------------------- - // Check for data - //------------------------------------- - - if($data == "") - { - error_log($this->xmlrpcstr['no_data']); - $r = new XML_RPC_Response(0, $this->xmlrpcerr['no_data'], $this->xmlrpcstr['no_data']); - return $r; - } - - - //------------------------------------- - // Check for HTTP 200 Response - //------------------------------------- - - if(ereg("^HTTP",$data) && !ereg("^HTTP/[0-9\.]+ 200 ", $data)) - { - $errstr= substr($data, 0, strpos($data, "\n")-1); - $r = new XML_RPC_Response(0, $this->xmlrpcerr['http_error'], $this->xmlrpcstr['http_error']. ' (' . $errstr . ')'); - return $r; - } - - //------------------------------------- - // Create and Set Up XML Parser - //------------------------------------- - - $parser = xml_parser_create($this->xmlrpc_defencoding); - - $this->xh[$parser] = array(); - $this->xh[$parser]['isf'] = 0; - $this->xh[$parser]['ac'] = ''; - $this->xh[$parser]['headers'] = array(); - $this->xh[$parser]['stack'] = array(); - $this->xh[$parser]['valuestack'] = array(); - $this->xh[$parser]['isf_reason'] = 0; - - xml_set_object($parser, $this); - 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'); - - - //------------------------------------- - // GET HEADERS - //------------------------------------- - - $lines = explode("\r\n", $data); - while (($line = array_shift($lines))) - { - if (strlen($line) < 1) - { - break; - } - $this->xh[$parser]['headers'][] = $line; - } - $data = implode("\r\n", $lines); - - - //------------------------------------- - // PARSE XML DATA - //------------------------------------- - - if (!xml_parse($parser, $data, sizeof($data))) - { - $errstr = sprintf('XML error: %s at line %d', - xml_error_string(xml_get_error_code($parser)), - xml_get_current_line_number($parser)); - //error_log($errstr); - $r = new XML_RPC_Response(0, $this->xmlrpcerr['invalid_return'], $this->xmlrpcstr['invalid_return']); - xml_parser_free($parser); - return $r; - } - xml_parser_free($parser); - - // --------------------------------------- - // Got Ourselves Some Badness, It Seems - // --------------------------------------- - - if ($this->xh[$parser]['isf'] > 1) - { - if ($this->debug === TRUE) - { - echo "---Invalid Return---\n"; - echo $this->xh[$parser]['isf_reason']; - echo "---Invalid Return---\n\n"; - } - - $r = new XML_RPC_Response(0, $this->xmlrpcerr['invalid_return'],$this->xmlrpcstr['invalid_return'].' '.$this->xh[$parser]['isf_reason']); - return $r; - } - elseif ( ! is_object($this->xh[$parser]['value'])) - { - $r = new XML_RPC_Response(0, $this->xmlrpcerr['invalid_return'],$this->xmlrpcstr['invalid_return'].' '.$this->xh[$parser]['isf_reason']); - return $r; - } - - //------------------------------------- - // DISPLAY XML CONTENT for DEBUGGING - //------------------------------------- - - if ($this->debug === TRUE) - { - echo "
    ";
    -			
    -			if (count($this->xh[$parser]['headers'] > 0))
    -			{
    -				echo "---HEADERS---\n";
    -				foreach ($this->xh[$parser]['headers'] as $header)
    -				{
    -					echo "$header\n";
    -				}
    -				echo "---END HEADERS---\n\n";
    -			}
    -			
    -			echo "---DATA---\n" . htmlspecialchars($data) . "\n---END DATA---\n\n";
    -			
    -			echo "---PARSED---\n" ;
    -			var_dump($this->xh[$parser]['value']);
    -			echo "\n---END PARSED---
    "; - } - - //------------------------------------- - // SEND RESPONSE - //------------------------------------- - - $v = $this->xh[$parser]['value']; - - if ($this->xh[$parser]['isf']) - { - $errno_v = $v->me['struct']['faultCode']; - $errstr_v = $v->me['struct']['faultString']; - $errno = $errno_v->scalarval(); - - if ($errno == 0) - { - // FAULT returned, errno needs to reflect that - $errno = -1; - } - - $r = new XML_RPC_Response($v, $errno, $errstr_v->scalarval()); - } - else - { - $r = new XML_RPC_Response($v); - } - - $r->headers = $this->xh[$parser]['headers']; - return $r; - } - - // ------------------------------------ - // Begin Return Message Parsing section - // ------------------------------------ - - // quick explanation of components: - // ac - used to accumulate values - // isf - used to indicate a fault - // lv - used to indicate "looking for a value": implements - // the logic to allow values with no types to be strings - // params - used to store parameters in method calls - // method - used to store method name - // stack - array with parent tree of the xml element, - // used to validate the nesting of elements - - //------------------------------------- - // Start Element Handler - //------------------------------------- - - function open_tag($the_parser, $name, $attrs) - { - // If invalid nesting, then return - if ($this->xh[$the_parser]['isf'] > 1) return; - - // Evaluate and check for correct nesting of XML elements - - if (count($this->xh[$the_parser]['stack']) == 0) - { - if ($name != 'METHODRESPONSE' && $name != 'METHODCALL') - { - $this->xh[$the_parser]['isf'] = 2; - $this->xh[$the_parser]['isf_reason'] = 'Top level XML-RPC element is missing'; - return; - } - } - else - { - // not top level element: see if parent is OK - if (!in_array($this->xh[$the_parser]['stack'][0], $this->valid_parents[$name], TRUE)) - { - $this->xh[$the_parser]['isf'] = 2; - $this->xh[$the_parser]['isf_reason'] = "XML-RPC element $name cannot be child of ".$this->xh[$the_parser]['stack'][0]; - return; - } - } - - switch($name) - { - case 'STRUCT': - case 'ARRAY': - // Creates array for child elements - - $cur_val = array('value' => array(), - 'type' => $name); - - array_unshift($this->xh[$the_parser]['valuestack'], $cur_val); - break; - case 'METHODNAME': - case 'NAME': - $this->xh[$the_parser]['ac'] = ''; - break; - case 'FAULT': - $this->xh[$the_parser]['isf'] = 1; - break; - case 'PARAM': - $this->xh[$the_parser]['value'] = null; - break; - case 'VALUE': - $this->xh[$the_parser]['vt'] = 'value'; - $this->xh[$the_parser]['ac'] = ''; - $this->xh[$the_parser]['lv'] = 1; - break; - case 'I4': - case 'INT': - case 'STRING': - case 'BOOLEAN': - case 'DOUBLE': - case 'DATETIME.ISO8601': - case 'BASE64': - if ($this->xh[$the_parser]['vt'] != 'value') - { - //two data elements inside a value: an error occurred! - $this->xh[$the_parser]['isf'] = 2; - $this->xh[$the_parser]['isf_reason'] = "'Twas a $name element following a ".$this->xh[$the_parser]['vt']." element inside a single value"; - return; - } - - $this->xh[$the_parser]['ac'] = ''; - break; - case 'MEMBER': - // Set name of to nothing to prevent errors later if no is found - $this->xh[$the_parser]['valuestack'][0]['name'] = ''; - - // Set NULL value to check to see if value passed for this param/member - $this->xh[$the_parser]['value'] = null; - break; - case 'DATA': - case 'METHODCALL': - case 'METHODRESPONSE': - case 'PARAMS': - // valid elements that add little to processing - break; - default: - /// An Invalid Element is Found, so we have trouble - $this->xh[$the_parser]['isf'] = 2; - $this->xh[$the_parser]['isf_reason'] = "Invalid XML-RPC element found: $name"; - break; - } - - // Add current element name to stack, to allow validation of nesting - array_unshift($this->xh[$the_parser]['stack'], $name); - - if ($name != 'VALUE') $this->xh[$the_parser]['lv'] = 0; - } - // END - - - //------------------------------------- - // End Element Handler - //------------------------------------- - - function closing_tag($the_parser, $name) - { - if ($this->xh[$the_parser]['isf'] > 1) return; - - // Remove current element from stack and set variable - // NOTE: If the XML validates, then we do not have to worry about - // the opening and closing of elements. Nesting is checked on the opening - // tag so we be safe there as well. - - $curr_elem = array_shift($this->xh[$the_parser]['stack']); - - switch($name) - { - case 'STRUCT': - case 'ARRAY': - $cur_val = array_shift($this->xh[$the_parser]['valuestack']); - $this->xh[$the_parser]['value'] = ( ! isset($cur_val['values'])) ? array() : $cur_val['values']; - $this->xh[$the_parser]['vt'] = strtolower($name); - break; - case 'NAME': - $this->xh[$the_parser]['valuestack'][0]['name'] = $this->xh[$the_parser]['ac']; - break; - case 'BOOLEAN': - case 'I4': - case 'INT': - case 'STRING': - case 'DOUBLE': - case 'DATETIME.ISO8601': - case 'BASE64': - $this->xh[$the_parser]['vt'] = strtolower($name); - - if ($name == 'STRING') - { - $this->xh[$the_parser]['value'] = $this->xh[$the_parser]['ac']; - } - elseif ($name=='DATETIME.ISO8601') - { - $this->xh[$the_parser]['vt'] = $this->xmlrpcDateTime; - $this->xh[$the_parser]['value'] = $this->xh[$the_parser]['ac']; - } - elseif ($name=='BASE64') - { - $this->xh[$the_parser]['value'] = base64_decode($this->xh[$the_parser]['ac']); - } - elseif ($name=='BOOLEAN') - { - // Translated BOOLEAN values to TRUE AND FALSE - if ($this->xh[$the_parser]['ac'] == '1') - { - $this->xh[$the_parser]['value'] = TRUE; - } - else - { - $this->xh[$the_parser]['value'] = FALSE; - } - } - elseif ($name=='DOUBLE') - { - // we have a DOUBLE - // we must check that only 0123456789-. are characters here - if (!ereg("^[+-]?[eE0123456789 \\t\\.]+$", $this->xh[$the_parser]['ac'])) - { - $this->xh[$the_parser]['value'] = 'ERROR_NON_NUMERIC_FOUND'; - } - else - { - $this->xh[$the_parser]['value'] = (double)$this->xh[$the_parser]['ac']; - } - } - else - { - // we have an I4/INT - // we must check that only 0123456789- are characters here - if (!ereg("^[+-]?[0123456789 \\t]+$", $this->xh[$the_parser]['ac'])) - { - $this->xh[$the_parser]['value'] = 'ERROR_NON_NUMERIC_FOUND'; - } - else - { - $this->xh[$the_parser]['value'] = (int)$this->xh[$the_parser]['ac']; - } - } - $this->xh[$the_parser]['ac'] = ''; - $this->xh[$the_parser]['lv'] = 3; // indicate we've found a value - break; - case 'VALUE': - // This if() detects if no scalar was inside - if ($this->xh[$the_parser]['vt']=='value') - { - $this->xh[$the_parser]['value'] = $this->xh[$the_parser]['ac']; - $this->xh[$the_parser]['vt'] = $this->xmlrpcString; - } - - // build the XML-RPC value out of the data received, and substitute it - $temp = new XML_RPC_Values($this->xh[$the_parser]['value'], $this->xh[$the_parser]['vt']); - - if (count($this->xh[$the_parser]['valuestack']) && $this->xh[$the_parser]['valuestack'][0]['type'] == 'ARRAY') - { - // Array - $this->xh[$the_parser]['valuestack'][0]['values'][] = $temp; - } - else - { - // Struct - $this->xh[$the_parser]['value'] = $temp; - } - break; - case 'MEMBER': - $this->xh[$the_parser]['ac']=''; - - // If value add to array in the stack for the last element built - if ($this->xh[$the_parser]['value']) - { - $this->xh[$the_parser]['valuestack'][0]['values'][$this->xh[$the_parser]['valuestack'][0]['name']] = $this->xh[$the_parser]['value']; - } - break; - case 'DATA': - $this->xh[$the_parser]['ac']=''; - break; - case 'PARAM': - if ($this->xh[$the_parser]['value']) - { - $this->xh[$the_parser]['params'][] = $this->xh[$the_parser]['value']; - } - break; - case 'METHODNAME': - $this->xh[$the_parser]['method'] = ereg_replace("^[\n\r\t ]+", '', $this->xh[$the_parser]['ac']); - break; - case 'PARAMS': - case 'FAULT': - case 'METHODCALL': - case 'METHORESPONSE': - // We're all good kids with nuthin' to do - break; - default: - // End of an Invalid Element. Taken care of during the opening tag though - break; - } - } - - //------------------------------------- - // Parses Character Data - //------------------------------------- - - function character_data($the_parser, $data) - { - if ($this->xh[$the_parser]['isf'] > 1) return; // XML Fault found already - - // If a value has not been found - if ($this->xh[$the_parser]['lv'] != 3) - { - if ($this->xh[$the_parser]['lv'] == 1) - { - $this->xh[$the_parser]['lv'] = 2; // Found a value - } - - if( ! @isset($this->xh[$the_parser]['ac'])) - { - $this->xh[$the_parser]['ac'] = ''; - } - - $this->xh[$the_parser]['ac'] .= $data; - } - } - - - function addParam($par) { $this->params[]=$par; } - - function output_parameters($array=FALSE) - { - $CI =& get_instance(); - - if ($array !== FALSE && is_array($array)) - { - while (list($key) = each($array)) - { - if (is_array($array[$key])) - { - $array[$key] = $this->output_parameters($array[$key]); - } - else - { - $array[$key] = $CI->input->xss_clean($array[$key]); - } - } - - $parameters = $array; - } - else - { - $parameters = array(); - - for ($i = 0; $i < sizeof($this->params); $i++) - { - $a_param = $this->decode_message($this->params[$i]); - - if (is_array($a_param)) - { - $parameters[] = $this->output_parameters($a_param); - } - else - { - $parameters[] = $CI->input->xss_clean($a_param); - } - } - } - - return $parameters; - } - - - function decode_message($param) - { - $kind = $param->kindOf(); - - if($kind == 'scalar') - { - return $param->scalarval(); - } - elseif($kind == 'array') - { - reset($param->me); - list($a,$b) = each($param->me); - - $arr = array(); - - for($i = 0; $i < sizeof($b); $i++) - { - $arr[] = $this->decode_message($param->me['array'][$i]); - } - - return $arr; - } - elseif($kind == 'struct') - { - reset($param->me['struct']); - - $arr = array(); - - while(list($key,$value) = each($param->me['struct'])) - { - $arr[$key] = $this->decode_message($value); - } - - return $arr; - } - } - -} // End XML_RPC_Messages class - - - -/** - * XML-RPC Values class - * - * @category XML-RPC - * @author Paul Burdick - * @link http://www.codeigniter.com/user_guide/libraries/xmlrpc.html - */ -class XML_RPC_Values extends CI_Xmlrpc -{ - var $me = array(); - var $mytype = 0; - - function XML_RPC_Values($val=-1, $type='') - { - parent::CI_Xmlrpc(); - - if ($val != -1 || $type != '') - { - $type = $type == '' ? 'string' : $type; - - if ($this->xmlrpcTypes[$type] == 1) - { - $this->addScalar($val,$type); - } - elseif ($this->xmlrpcTypes[$type] == 2) - { - $this->addArray($val); - } - elseif ($this->xmlrpcTypes[$type] == 3) - { - $this->addStruct($val); - } - } - } - - function addScalar($val, $type='string') - { - $typeof = $this->xmlrpcTypes[$type]; - - if ($this->mytype==1) - { - echo 'XML_RPC_Values: scalar can have only one value
    '; - return 0; - } - - if ($typeof != 1) - { - echo 'XML_RPC_Values: not a scalar type (${typeof})
    '; - return 0; - } - - if ($type == $this->xmlrpcBoolean) - { - if (strcasecmp($val,'true')==0 || $val==1 || ($val==true && strcasecmp($val,'false'))) - { - $val = 1; - } - else - { - $val=0; - } - } - - if ($this->mytype == 2) - { - // adding to an array here - $ar = $this->me['array']; - $ar[] = new XML_RPC_Values($val, $type); - $this->me['array'] = $ar; - } - else - { - // a scalar, so set the value and remember we're scalar - $this->me[$type] = $val; - $this->mytype = $typeof; - } - return 1; - } - - function addArray($vals) - { - if ($this->mytype != 0) - { - echo 'XML_RPC_Values: already initialized as a [' . $this->kindOf() . ']
    '; - return 0; - } - - $this->mytype = $this->xmlrpcTypes['array']; - $this->me['array'] = $vals; - return 1; - } - - function addStruct($vals) - { - if ($this->mytype != 0) - { - echo 'XML_RPC_Values: already initialized as a [' . $this->kindOf() . ']
    '; - return 0; - } - $this->mytype = $this->xmlrpcTypes['struct']; - $this->me['struct'] = $vals; - return 1; - } - - function kindOf() - { - switch($this->mytype) - { - case 3: - return 'struct'; - break; - case 2: - return 'array'; - break; - case 1: - return 'scalar'; - break; - default: - return 'undef'; - } - } - - function serializedata($typ, $val) - { - $rs = ''; - - switch($this->xmlrpcTypes[$typ]) - { - case 3: - // struct - $rs .= "\n"; - reset($val); - while(list($key2, $val2) = each($val)) - { - $rs .= "\n{$key2}\n"; - $rs .= $this->serializeval($val2); - $rs .= "\n"; - } - $rs .= ''; - break; - case 2: - // array - $rs .= "\n\n"; - for($i=0; $i < sizeof($val); $i++) - { - $rs .= $this->serializeval($val[$i]); - } - $rs.="\n\n"; - break; - case 1: - // others - switch ($typ) - { - case $this->xmlrpcBase64: - $rs .= "<{$typ}>" . base64_encode($val) . "\n"; - break; - case $this->xmlrpcBoolean: - $rs .= "<{$typ}>" . ($val ? '1' : '0') . "\n"; - break; - case $this->xmlrpcString: - $rs .= "<{$typ}>" . htmlspecialchars($val). "\n"; - break; - default: - $rs .= "<{$typ}>{$val}\n"; - break; - } - default: - break; - } - return $rs; - } - - function serialize_class() - { - return $this->serializeval($this); - } - - function serializeval($o) - { - - $ar = $o->me; - reset($ar); - - list($typ, $val) = each($ar); - $rs = "\n".$this->serializedata($typ, $val)."\n"; - return $rs; - } - - function scalarval() - { - reset($this->me); - list($a,$b) = each($this->me); - return $b; - } - - - //------------------------------------- - // Encode time in ISO-8601 form. - //------------------------------------- - - // Useful for sending time in XML-RPC - - function iso8601_encode($time, $utc=0) - { - if ($utc == 1) - { - $t = strftime("%Y%m%dT%H:%M:%S", $time); - } - else - { - if (function_exists('gmstrftime')) - $t = gmstrftime("%Y%m%dT%H:%M:%S", $time); - else - $t = strftime("%Y%m%dT%H:%M:%S", $time - date('Z')); - } - return $t; - } - -} -// END XML_RPC_Values Class +xmlrpcName = $this->xmlrpcName; + $this->xmlrpc_backslash = chr(92).chr(92); + + // Types for info sent back and forth + $this->xmlrpcTypes = array( + $this->xmlrpcI4 => '1', + $this->xmlrpcInt => '1', + $this->xmlrpcBoolean => '1', + $this->xmlrpcString => '1', + $this->xmlrpcDouble => '1', + $this->xmlrpcDateTime => '1', + $this->xmlrpcBase64 => '1', + $this->xmlrpcArray => '2', + $this->xmlrpcStruct => '3' + ); + + // Array of Valid Parents for Various XML-RPC elements + $this->valid_parents = array('BOOLEAN' => array('VALUE'), + 'I4' => array('VALUE'), + 'INT' => array('VALUE'), + 'STRING' => array('VALUE'), + 'DOUBLE' => array('VALUE'), + 'DATETIME.ISO8601' => array('VALUE'), + 'BASE64' => array('VALUE'), + 'ARRAY' => array('VALUE'), + 'STRUCT' => array('VALUE'), + 'PARAM' => array('PARAMS'), + 'METHODNAME' => array('METHODCALL'), + 'PARAMS' => array('METHODCALL', 'METHODRESPONSE'), + 'MEMBER' => array('STRUCT'), + 'NAME' => array('MEMBER'), + 'DATA' => array('ARRAY'), + 'FAULT' => array('METHODRESPONSE'), + 'VALUE' => array('MEMBER', 'DATA', 'PARAM', 'FAULT') + ); + + + // XML-RPC Responses + $this->xmlrpcerr['unknown_method'] = '1'; + $this->xmlrpcstr['unknown_method'] = 'This is not a known method for this XML-RPC Server'; + $this->xmlrpcerr['invalid_return'] = '2'; + $this->xmlrpcstr['invalid_return'] = 'The XML data receieved was either invalid or not in the correct form for XML-RPC. Turn on debugging to examine the XML data further.'; + $this->xmlrpcerr['incorrect_params'] = '3'; + $this->xmlrpcstr['incorrect_params'] = 'Incorrect parameters were passed to method'; + $this->xmlrpcerr['introspect_unknown'] = '4'; + $this->xmlrpcstr['introspect_unknown'] = "Cannot inspect signature for request: method unknown"; + $this->xmlrpcerr['http_error'] = '5'; + $this->xmlrpcstr['http_error'] = "Did not receive a '200 OK' response from remote server."; + $this->xmlrpcerr['no_data'] = '6'; + $this->xmlrpcstr['no_data'] ='No data received from server.'; + + $this->initialize($config); + + log_message('debug', "XML-RPC Class Initialized"); + } + + + //------------------------------------- + // Initialize Prefs + //------------------------------------- + + function initialize($config = array()) + { + if (sizeof($config) > 0) + { + foreach ($config as $key => $val) + { + if (isset($this->$key)) + { + $this->$key = $val; + } + } + } + } + // END + + //------------------------------------- + // Take URL and parse it + //------------------------------------- + + function server($url, $port=80) + { + if (substr($url, 0, 4) != "http") + { + $url = "http://".$url; + } + + $parts = parse_url($url); + + $path = (!isset($parts['path'])) ? '/' : $parts['path']; + + if (isset($parts['query']) && $parts['query'] != '') + { + $path .= '?'.$parts['query']; + } + + $this->client = new XML_RPC_Client($path, $parts['host'], $port); + } + // END + + //------------------------------------- + // Set Timeout + //------------------------------------- + + function timeout($seconds=5) + { + if ( ! is_null($this->client) && is_int($seconds)) + { + $this->client->timeout = $seconds; + } + } + // END + + //------------------------------------- + // Set Methods + //------------------------------------- + + function method($function) + { + $this->method = $function; + } + // END + + //------------------------------------- + // Take Array of Data and Create Objects + //------------------------------------- + + function request($incoming) + { + if ( ! is_array($incoming)) + { + // Send Error + } + + foreach($incoming as $key => $value) + { + $this->data[$key] = $this->values_parsing($value); + } + } + // END + + + //------------------------------------- + // Set Debug + //------------------------------------- + + function set_debug($flag = TRUE) + { + $this->debug = ($flag == TRUE) ? TRUE : FALSE; + } + + //------------------------------------- + // Values Parsing + //------------------------------------- + + function values_parsing($value, $return = FALSE) + { + if (is_array($value) && isset($value['0'])) + { + if ( ! isset($value['1']) OR ! isset($this->xmlrpcTypes[strtolower($value['1'])])) + { + $temp = new XML_RPC_Values($value['0'], 'string'); + } + elseif(is_array($value['0']) && ($value['1'] == 'struct' OR $value['1'] == 'array')) + { + while (list($k) = each($value['0'])) + { + $value['0'][$k] = $this->values_parsing($value['0'][$k], TRUE); + } + + $temp = new XML_RPC_Values($value['0'], $value['1']); + } + else + { + $temp = new XML_RPC_Values($value['0'], $value['1']); + } + } + else + { + $temp = new XML_RPC_Values($value, 'string'); + } + + return $temp; + } + // END + + + //------------------------------------- + // Sends XML-RPC Request + //------------------------------------- + + function send_request() + { + $this->message = new XML_RPC_Message($this->method,$this->data); + $this->message->debug = $this->debug; + + if ( ! $this->result = $this->client->send($this->message)) + { + $this->error = $this->result->errstr; + return FALSE; + } + elseif( ! is_object($this->result->val)) + { + $this->error = $this->result->errstr; + return FALSE; + } + + $this->response = $this->result->decode(); + + return TRUE; + } + // END + + //------------------------------------- + // Returns Error + //------------------------------------- + + function display_error() + { + return $this->error; + } + // END + + //------------------------------------- + // Returns Remote Server Response + //------------------------------------- + + function display_response() + { + return $this->response; + } + // END + + //------------------------------------- + // Sends an Error Message for Server Request + //------------------------------------- + + function send_error_message($number, $message) + { + return new XML_RPC_Response('0',$number, $message); + } + // END + + + //------------------------------------- + // Send Response for Server Request + //------------------------------------- + + function send_response($response) + { + // $response should be array of values, which will be parsed + // based on their data and type into a valid group of XML-RPC values + + $response = $this->values_parsing($response); + + return new XML_RPC_Response($response); + } + // END + +} // END XML_RPC Class + + + +/** + * XML-RPC Client class + * + * @category XML-RPC + * @author Paul Burdick + * @link http://www.codeigniter.com/user_guide/libraries/xmlrpc.html + */ +class XML_RPC_Client extends CI_Xmlrpc +{ + var $path = ''; + var $server = ''; + var $port = 80; + var $errno = ''; + var $errstring = ''; + var $timeout = 5; + var $no_multicall = false; + + function XML_RPC_Client($path, $server, $port=80) + { + parent::CI_Xmlrpc(); + + $this->port = $port; + $this->server = $server; + $this->path = $path; + } + + function send($msg) + { + if (is_array($msg)) + { + // Multi-call disabled + $r = new XML_RPC_Response(0, $this->xmlrpcerr['multicall_recursion'],$this->xmlrpcstr['multicall_recursion']); + return $r; + } + + return $this->sendPayload($msg); + } + + function sendPayload($msg) + { + $fp = @fsockopen($this->server, $this->port,$this->errno, $this->errstr, $this->timeout); + + if (! is_resource($fp)) + { + error_log($this->xmlrpcstr['http_error']); + $r = new XML_RPC_Response(0, $this->xmlrpcerr['http_error'],$this->xmlrpcstr['http_error']); + return $r; + } + + if(empty($msg->payload)) + { + // $msg = XML_RPC_Messages + $msg->createPayload(); + } + + $r = "\r\n"; + $op = "POST {$this->path} HTTP/1.0$r"; + $op .= "Host: {$this->server}$r"; + $op .= "Content-Type: text/xml$r"; + $op .= "User-Agent: {$this->xmlrpcName}$r"; + $op .= "Content-Length: ".strlen($msg->payload). "$r$r"; + $op .= $msg->payload; + + + if (!fputs($fp, $op, strlen($op))) + { + error_log($this->xmlrpcstr['http_error']); + $r = new XML_RPC_Response(0, $this->xmlrpcerr['http_error'], $this->xmlrpcstr['http_error']); + return $r; + } + $resp = $msg->parseResponse($fp); + fclose($fp); + return $resp; + } + +} // end class XML_RPC_Client + + +/** + * XML-RPC Response class + * + * @category XML-RPC + * @author Paul Burdick + * @link http://www.codeigniter.com/user_guide/libraries/xmlrpc.html + */ +class XML_RPC_Response +{ + var $val = 0; + var $errno = 0; + var $errstr = ''; + var $headers = array(); + + function XML_RPC_Response($val, $code = 0, $fstr = '') + { + if ($code != 0) + { + // error + $this->errno = $code; + $this->errstr = htmlentities($fstr); + } + else if (!is_object($val)) + { + // programmer error, not an object + error_log("Invalid type '" . gettype($val) . "' (value: $val) passed to XML_RPC_Response. Defaulting to empty value."); + $this->val = new XML_RPC_Values(); + } + else + { + $this->val = $val; + } + } + + function faultCode() + { + return $this->errno; + } + + function faultString() + { + return $this->errstr; + } + + function value() + { + return $this->val; + } + + function prepare_response() + { + $result = "\n"; + if ($this->errno) + { + $result .= ' + + + + faultCode + ' . $this->errno . ' + + + faultString + ' . $this->errstr . ' + + + +'; + } + else + { + $result .= "\n\n" . + $this->val->serialize_class() . + "\n"; + } + $result .= "\n"; + return $result; + } + + function decode($array=FALSE) + { + $CI =& get_instance(); + + if ($array !== FALSE && is_array($array)) + { + while (list($key) = each($array)) + { + if (is_array($array[$key])) + { + $array[$key] = $this->decode($array[$key]); + } + else + { + $array[$key] = $CI->input->xss_clean($array[$key]); + } + } + + $result = $array; + } + else + { + $result = $this->xmlrpc_decoder($this->val); + + if (is_array($result)) + { + $result = $this->decode($result); + } + else + { + $result = $CI->input->xss_clean($result); + } + } + + return $result; + } + + + + //------------------------------------- + // XML-RPC Object to PHP Types + //------------------------------------- + + function xmlrpc_decoder($xmlrpc_val) + { + $kind = $xmlrpc_val->kindOf(); + + if($kind == 'scalar') + { + return $xmlrpc_val->scalarval(); + } + elseif($kind == 'array') + { + reset($xmlrpc_val->me); + list($a,$b) = each($xmlrpc_val->me); + $size = sizeof($b); + + $arr = array(); + + for($i = 0; $i < $size; $i++) + { + $arr[] = $this->xmlrpc_decoder($xmlrpc_val->me['array'][$i]); + } + return $arr; + } + elseif($kind == 'struct') + { + reset($xmlrpc_val->me['struct']); + $arr = array(); + + while(list($key,$value) = each($xmlrpc_val->me['struct'])) + { + $arr[$key] = $this->xmlrpc_decoder($value); + } + return $arr; + } + } + + + //------------------------------------- + // ISO-8601 time to server or UTC time + //------------------------------------- + + function iso8601_decode($time, $utc=0) + { + // return a timet in the localtime, or UTC + $t = 0; + if (ereg("([0-9]{4})([0-9]{2})([0-9]{2})T([0-9]{2}):([0-9]{2}):([0-9]{2})", $time, $regs)) + { + if ($utc == 1) + $t = gmmktime($regs[4], $regs[5], $regs[6], $regs[2], $regs[3], $regs[1]); + else + $t = mktime($regs[4], $regs[5], $regs[6], $regs[2], $regs[3], $regs[1]); + } + return $t; + } + +} // End Response Class + + + +/** + * XML-RPC Message class + * + * @category XML-RPC + * @author Paul Burdick + * @link http://www.codeigniter.com/user_guide/libraries/xmlrpc.html + */ +class XML_RPC_Message extends CI_Xmlrpc +{ + var $payload; + var $method_name; + var $params = array(); + var $xh = array(); + + function XML_RPC_Message($method, $pars=0) + { + parent::CI_Xmlrpc(); + + $this->method_name = $method; + if (is_array($pars) && sizeof($pars) > 0) + { + for($i=0; $iparams[] = $pars[$i]; + } + } + } + + //------------------------------------- + // Create Payload to Send + //------------------------------------- + + function createPayload() + { + $this->payload = "\r\n\r\n"; + $this->payload .= '' . $this->method_name . "\r\n"; + $this->payload .= "\r\n"; + + for($i=0; $iparams); $i++) + { + // $p = XML_RPC_Values + $p = $this->params[$i]; + $this->payload .= "\r\n".$p->serialize_class()."\r\n"; + } + + $this->payload .= "\r\n\r\n"; + } + + //------------------------------------- + // Parse External XML-RPC Server's Response + //------------------------------------- + + function parseResponse($fp) + { + $data = ''; + + while($datum = fread($fp, 4096)) + { + $data .= $datum; + } + + //------------------------------------- + // DISPLAY HTTP CONTENT for DEBUGGING + //------------------------------------- + + if ($this->debug === TRUE) + { + echo "
    ";
    +			echo "---DATA---\n" . htmlspecialchars($data) . "\n---END DATA---\n\n";
    +			echo "
    "; + } + + //------------------------------------- + // Check for data + //------------------------------------- + + if($data == "") + { + error_log($this->xmlrpcstr['no_data']); + $r = new XML_RPC_Response(0, $this->xmlrpcerr['no_data'], $this->xmlrpcstr['no_data']); + return $r; + } + + + //------------------------------------- + // Check for HTTP 200 Response + //------------------------------------- + + if(ereg("^HTTP",$data) && !ereg("^HTTP/[0-9\.]+ 200 ", $data)) + { + $errstr= substr($data, 0, strpos($data, "\n")-1); + $r = new XML_RPC_Response(0, $this->xmlrpcerr['http_error'], $this->xmlrpcstr['http_error']. ' (' . $errstr . ')'); + return $r; + } + + //------------------------------------- + // Create and Set Up XML Parser + //------------------------------------- + + $parser = xml_parser_create($this->xmlrpc_defencoding); + + $this->xh[$parser] = array(); + $this->xh[$parser]['isf'] = 0; + $this->xh[$parser]['ac'] = ''; + $this->xh[$parser]['headers'] = array(); + $this->xh[$parser]['stack'] = array(); + $this->xh[$parser]['valuestack'] = array(); + $this->xh[$parser]['isf_reason'] = 0; + + xml_set_object($parser, $this); + 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'); + + + //------------------------------------- + // GET HEADERS + //------------------------------------- + + $lines = explode("\r\n", $data); + while (($line = array_shift($lines))) + { + if (strlen($line) < 1) + { + break; + } + $this->xh[$parser]['headers'][] = $line; + } + $data = implode("\r\n", $lines); + + + //------------------------------------- + // PARSE XML DATA + //------------------------------------- + + if (!xml_parse($parser, $data, sizeof($data))) + { + $errstr = sprintf('XML error: %s at line %d', + xml_error_string(xml_get_error_code($parser)), + xml_get_current_line_number($parser)); + //error_log($errstr); + $r = new XML_RPC_Response(0, $this->xmlrpcerr['invalid_return'], $this->xmlrpcstr['invalid_return']); + xml_parser_free($parser); + return $r; + } + xml_parser_free($parser); + + // --------------------------------------- + // Got Ourselves Some Badness, It Seems + // --------------------------------------- + + if ($this->xh[$parser]['isf'] > 1) + { + if ($this->debug === TRUE) + { + echo "---Invalid Return---\n"; + echo $this->xh[$parser]['isf_reason']; + echo "---Invalid Return---\n\n"; + } + + $r = new XML_RPC_Response(0, $this->xmlrpcerr['invalid_return'],$this->xmlrpcstr['invalid_return'].' '.$this->xh[$parser]['isf_reason']); + return $r; + } + elseif ( ! is_object($this->xh[$parser]['value'])) + { + $r = new XML_RPC_Response(0, $this->xmlrpcerr['invalid_return'],$this->xmlrpcstr['invalid_return'].' '.$this->xh[$parser]['isf_reason']); + return $r; + } + + //------------------------------------- + // DISPLAY XML CONTENT for DEBUGGING + //------------------------------------- + + if ($this->debug === TRUE) + { + echo "
    ";
    +			
    +			if (count($this->xh[$parser]['headers'] > 0))
    +			{
    +				echo "---HEADERS---\n";
    +				foreach ($this->xh[$parser]['headers'] as $header)
    +				{
    +					echo "$header\n";
    +				}
    +				echo "---END HEADERS---\n\n";
    +			}
    +			
    +			echo "---DATA---\n" . htmlspecialchars($data) . "\n---END DATA---\n\n";
    +			
    +			echo "---PARSED---\n" ;
    +			var_dump($this->xh[$parser]['value']);
    +			echo "\n---END PARSED---
    "; + } + + //------------------------------------- + // SEND RESPONSE + //------------------------------------- + + $v = $this->xh[$parser]['value']; + + if ($this->xh[$parser]['isf']) + { + $errno_v = $v->me['struct']['faultCode']; + $errstr_v = $v->me['struct']['faultString']; + $errno = $errno_v->scalarval(); + + if ($errno == 0) + { + // FAULT returned, errno needs to reflect that + $errno = -1; + } + + $r = new XML_RPC_Response($v, $errno, $errstr_v->scalarval()); + } + else + { + $r = new XML_RPC_Response($v); + } + + $r->headers = $this->xh[$parser]['headers']; + return $r; + } + + // ------------------------------------ + // Begin Return Message Parsing section + // ------------------------------------ + + // quick explanation of components: + // ac - used to accumulate values + // isf - used to indicate a fault + // lv - used to indicate "looking for a value": implements + // the logic to allow values with no types to be strings + // params - used to store parameters in method calls + // method - used to store method name + // stack - array with parent tree of the xml element, + // used to validate the nesting of elements + + //------------------------------------- + // Start Element Handler + //------------------------------------- + + function open_tag($the_parser, $name, $attrs) + { + // If invalid nesting, then return + if ($this->xh[$the_parser]['isf'] > 1) return; + + // Evaluate and check for correct nesting of XML elements + + if (count($this->xh[$the_parser]['stack']) == 0) + { + if ($name != 'METHODRESPONSE' && $name != 'METHODCALL') + { + $this->xh[$the_parser]['isf'] = 2; + $this->xh[$the_parser]['isf_reason'] = 'Top level XML-RPC element is missing'; + return; + } + } + else + { + // not top level element: see if parent is OK + if (!in_array($this->xh[$the_parser]['stack'][0], $this->valid_parents[$name], TRUE)) + { + $this->xh[$the_parser]['isf'] = 2; + $this->xh[$the_parser]['isf_reason'] = "XML-RPC element $name cannot be child of ".$this->xh[$the_parser]['stack'][0]; + return; + } + } + + switch($name) + { + case 'STRUCT': + case 'ARRAY': + // Creates array for child elements + + $cur_val = array('value' => array(), + 'type' => $name); + + array_unshift($this->xh[$the_parser]['valuestack'], $cur_val); + break; + case 'METHODNAME': + case 'NAME': + $this->xh[$the_parser]['ac'] = ''; + break; + case 'FAULT': + $this->xh[$the_parser]['isf'] = 1; + break; + case 'PARAM': + $this->xh[$the_parser]['value'] = null; + break; + case 'VALUE': + $this->xh[$the_parser]['vt'] = 'value'; + $this->xh[$the_parser]['ac'] = ''; + $this->xh[$the_parser]['lv'] = 1; + break; + case 'I4': + case 'INT': + case 'STRING': + case 'BOOLEAN': + case 'DOUBLE': + case 'DATETIME.ISO8601': + case 'BASE64': + if ($this->xh[$the_parser]['vt'] != 'value') + { + //two data elements inside a value: an error occurred! + $this->xh[$the_parser]['isf'] = 2; + $this->xh[$the_parser]['isf_reason'] = "'Twas a $name element following a ".$this->xh[$the_parser]['vt']." element inside a single value"; + return; + } + + $this->xh[$the_parser]['ac'] = ''; + break; + case 'MEMBER': + // Set name of to nothing to prevent errors later if no is found + $this->xh[$the_parser]['valuestack'][0]['name'] = ''; + + // Set NULL value to check to see if value passed for this param/member + $this->xh[$the_parser]['value'] = null; + break; + case 'DATA': + case 'METHODCALL': + case 'METHODRESPONSE': + case 'PARAMS': + // valid elements that add little to processing + break; + default: + /// An Invalid Element is Found, so we have trouble + $this->xh[$the_parser]['isf'] = 2; + $this->xh[$the_parser]['isf_reason'] = "Invalid XML-RPC element found: $name"; + break; + } + + // Add current element name to stack, to allow validation of nesting + array_unshift($this->xh[$the_parser]['stack'], $name); + + if ($name != 'VALUE') $this->xh[$the_parser]['lv'] = 0; + } + // END + + + //------------------------------------- + // End Element Handler + //------------------------------------- + + function closing_tag($the_parser, $name) + { + if ($this->xh[$the_parser]['isf'] > 1) return; + + // Remove current element from stack and set variable + // NOTE: If the XML validates, then we do not have to worry about + // the opening and closing of elements. Nesting is checked on the opening + // tag so we be safe there as well. + + $curr_elem = array_shift($this->xh[$the_parser]['stack']); + + switch($name) + { + case 'STRUCT': + case 'ARRAY': + $cur_val = array_shift($this->xh[$the_parser]['valuestack']); + $this->xh[$the_parser]['value'] = ( ! isset($cur_val['values'])) ? array() : $cur_val['values']; + $this->xh[$the_parser]['vt'] = strtolower($name); + break; + case 'NAME': + $this->xh[$the_parser]['valuestack'][0]['name'] = $this->xh[$the_parser]['ac']; + break; + case 'BOOLEAN': + case 'I4': + case 'INT': + case 'STRING': + case 'DOUBLE': + case 'DATETIME.ISO8601': + case 'BASE64': + $this->xh[$the_parser]['vt'] = strtolower($name); + + if ($name == 'STRING') + { + $this->xh[$the_parser]['value'] = $this->xh[$the_parser]['ac']; + } + elseif ($name=='DATETIME.ISO8601') + { + $this->xh[$the_parser]['vt'] = $this->xmlrpcDateTime; + $this->xh[$the_parser]['value'] = $this->xh[$the_parser]['ac']; + } + elseif ($name=='BASE64') + { + $this->xh[$the_parser]['value'] = base64_decode($this->xh[$the_parser]['ac']); + } + elseif ($name=='BOOLEAN') + { + // Translated BOOLEAN values to TRUE AND FALSE + if ($this->xh[$the_parser]['ac'] == '1') + { + $this->xh[$the_parser]['value'] = TRUE; + } + else + { + $this->xh[$the_parser]['value'] = FALSE; + } + } + elseif ($name=='DOUBLE') + { + // we have a DOUBLE + // we must check that only 0123456789-. are characters here + if (!ereg("^[+-]?[eE0123456789 \\t\\.]+$", $this->xh[$the_parser]['ac'])) + { + $this->xh[$the_parser]['value'] = 'ERROR_NON_NUMERIC_FOUND'; + } + else + { + $this->xh[$the_parser]['value'] = (double)$this->xh[$the_parser]['ac']; + } + } + else + { + // we have an I4/INT + // we must check that only 0123456789- are characters here + if (!ereg("^[+-]?[0123456789 \\t]+$", $this->xh[$the_parser]['ac'])) + { + $this->xh[$the_parser]['value'] = 'ERROR_NON_NUMERIC_FOUND'; + } + else + { + $this->xh[$the_parser]['value'] = (int)$this->xh[$the_parser]['ac']; + } + } + $this->xh[$the_parser]['ac'] = ''; + $this->xh[$the_parser]['lv'] = 3; // indicate we've found a value + break; + case 'VALUE': + // This if() detects if no scalar was inside + if ($this->xh[$the_parser]['vt']=='value') + { + $this->xh[$the_parser]['value'] = $this->xh[$the_parser]['ac']; + $this->xh[$the_parser]['vt'] = $this->xmlrpcString; + } + + // build the XML-RPC value out of the data received, and substitute it + $temp = new XML_RPC_Values($this->xh[$the_parser]['value'], $this->xh[$the_parser]['vt']); + + if (count($this->xh[$the_parser]['valuestack']) && $this->xh[$the_parser]['valuestack'][0]['type'] == 'ARRAY') + { + // Array + $this->xh[$the_parser]['valuestack'][0]['values'][] = $temp; + } + else + { + // Struct + $this->xh[$the_parser]['value'] = $temp; + } + break; + case 'MEMBER': + $this->xh[$the_parser]['ac']=''; + + // If value add to array in the stack for the last element built + if ($this->xh[$the_parser]['value']) + { + $this->xh[$the_parser]['valuestack'][0]['values'][$this->xh[$the_parser]['valuestack'][0]['name']] = $this->xh[$the_parser]['value']; + } + break; + case 'DATA': + $this->xh[$the_parser]['ac']=''; + break; + case 'PARAM': + if ($this->xh[$the_parser]['value']) + { + $this->xh[$the_parser]['params'][] = $this->xh[$the_parser]['value']; + } + break; + case 'METHODNAME': + $this->xh[$the_parser]['method'] = ereg_replace("^[\n\r\t ]+", '', $this->xh[$the_parser]['ac']); + break; + case 'PARAMS': + case 'FAULT': + case 'METHODCALL': + case 'METHORESPONSE': + // We're all good kids with nuthin' to do + break; + default: + // End of an Invalid Element. Taken care of during the opening tag though + break; + } + } + + //------------------------------------- + // Parses Character Data + //------------------------------------- + + function character_data($the_parser, $data) + { + if ($this->xh[$the_parser]['isf'] > 1) return; // XML Fault found already + + // If a value has not been found + if ($this->xh[$the_parser]['lv'] != 3) + { + if ($this->xh[$the_parser]['lv'] == 1) + { + $this->xh[$the_parser]['lv'] = 2; // Found a value + } + + if( ! @isset($this->xh[$the_parser]['ac'])) + { + $this->xh[$the_parser]['ac'] = ''; + } + + $this->xh[$the_parser]['ac'] .= $data; + } + } + + + function addParam($par) { $this->params[]=$par; } + + function output_parameters($array=FALSE) + { + $CI =& get_instance(); + + if ($array !== FALSE && is_array($array)) + { + while (list($key) = each($array)) + { + if (is_array($array[$key])) + { + $array[$key] = $this->output_parameters($array[$key]); + } + else + { + $array[$key] = $CI->input->xss_clean($array[$key]); + } + } + + $parameters = $array; + } + else + { + $parameters = array(); + + for ($i = 0; $i < sizeof($this->params); $i++) + { + $a_param = $this->decode_message($this->params[$i]); + + if (is_array($a_param)) + { + $parameters[] = $this->output_parameters($a_param); + } + else + { + $parameters[] = $CI->input->xss_clean($a_param); + } + } + } + + return $parameters; + } + + + function decode_message($param) + { + $kind = $param->kindOf(); + + if($kind == 'scalar') + { + return $param->scalarval(); + } + elseif($kind == 'array') + { + reset($param->me); + list($a,$b) = each($param->me); + + $arr = array(); + + for($i = 0; $i < sizeof($b); $i++) + { + $arr[] = $this->decode_message($param->me['array'][$i]); + } + + return $arr; + } + elseif($kind == 'struct') + { + reset($param->me['struct']); + + $arr = array(); + + while(list($key,$value) = each($param->me['struct'])) + { + $arr[$key] = $this->decode_message($value); + } + + return $arr; + } + } + +} // End XML_RPC_Messages class + + + +/** + * XML-RPC Values class + * + * @category XML-RPC + * @author Paul Burdick + * @link http://www.codeigniter.com/user_guide/libraries/xmlrpc.html + */ +class XML_RPC_Values extends CI_Xmlrpc +{ + var $me = array(); + var $mytype = 0; + + function XML_RPC_Values($val=-1, $type='') + { + parent::CI_Xmlrpc(); + + if ($val != -1 || $type != '') + { + $type = $type == '' ? 'string' : $type; + + if ($this->xmlrpcTypes[$type] == 1) + { + $this->addScalar($val,$type); + } + elseif ($this->xmlrpcTypes[$type] == 2) + { + $this->addArray($val); + } + elseif ($this->xmlrpcTypes[$type] == 3) + { + $this->addStruct($val); + } + } + } + + function addScalar($val, $type='string') + { + $typeof = $this->xmlrpcTypes[$type]; + + if ($this->mytype==1) + { + echo 'XML_RPC_Values: scalar can have only one value
    '; + return 0; + } + + if ($typeof != 1) + { + echo 'XML_RPC_Values: not a scalar type (${typeof})
    '; + return 0; + } + + if ($type == $this->xmlrpcBoolean) + { + if (strcasecmp($val,'true')==0 || $val==1 || ($val==true && strcasecmp($val,'false'))) + { + $val = 1; + } + else + { + $val=0; + } + } + + if ($this->mytype == 2) + { + // adding to an array here + $ar = $this->me['array']; + $ar[] = new XML_RPC_Values($val, $type); + $this->me['array'] = $ar; + } + else + { + // a scalar, so set the value and remember we're scalar + $this->me[$type] = $val; + $this->mytype = $typeof; + } + return 1; + } + + function addArray($vals) + { + if ($this->mytype != 0) + { + echo 'XML_RPC_Values: already initialized as a [' . $this->kindOf() . ']
    '; + return 0; + } + + $this->mytype = $this->xmlrpcTypes['array']; + $this->me['array'] = $vals; + return 1; + } + + function addStruct($vals) + { + if ($this->mytype != 0) + { + echo 'XML_RPC_Values: already initialized as a [' . $this->kindOf() . ']
    '; + return 0; + } + $this->mytype = $this->xmlrpcTypes['struct']; + $this->me['struct'] = $vals; + return 1; + } + + function kindOf() + { + switch($this->mytype) + { + case 3: + return 'struct'; + break; + case 2: + return 'array'; + break; + case 1: + return 'scalar'; + break; + default: + return 'undef'; + } + } + + function serializedata($typ, $val) + { + $rs = ''; + + switch($this->xmlrpcTypes[$typ]) + { + case 3: + // struct + $rs .= "\n"; + reset($val); + while(list($key2, $val2) = each($val)) + { + $rs .= "\n{$key2}\n"; + $rs .= $this->serializeval($val2); + $rs .= "\n"; + } + $rs .= ''; + break; + case 2: + // array + $rs .= "\n\n"; + for($i=0; $i < sizeof($val); $i++) + { + $rs .= $this->serializeval($val[$i]); + } + $rs.="\n\n"; + break; + case 1: + // others + switch ($typ) + { + case $this->xmlrpcBase64: + $rs .= "<{$typ}>" . base64_encode($val) . "\n"; + break; + case $this->xmlrpcBoolean: + $rs .= "<{$typ}>" . ($val ? '1' : '0') . "\n"; + break; + case $this->xmlrpcString: + $rs .= "<{$typ}>" . htmlspecialchars($val). "\n"; + break; + default: + $rs .= "<{$typ}>{$val}\n"; + break; + } + default: + break; + } + return $rs; + } + + function serialize_class() + { + return $this->serializeval($this); + } + + function serializeval($o) + { + + $ar = $o->me; + reset($ar); + + list($typ, $val) = each($ar); + $rs = "\n".$this->serializedata($typ, $val)."\n"; + return $rs; + } + + function scalarval() + { + reset($this->me); + list($a,$b) = each($this->me); + return $b; + } + + + //------------------------------------- + // Encode time in ISO-8601 form. + //------------------------------------- + + // Useful for sending time in XML-RPC + + function iso8601_encode($time, $utc=0) + { + if ($utc == 1) + { + $t = strftime("%Y%m%dT%H:%M:%S", $time); + } + else + { + if (function_exists('gmstrftime')) + $t = gmstrftime("%Y%m%dT%H:%M:%S", $time); + else + $t = strftime("%Y%m%dT%H:%M:%S", $time - date('Z')); + } + return $t; + } + +} +// END XML_RPC_Values Class ?> \ No newline at end of file diff --git a/system/libraries/Xmlrpcs.php b/system/libraries/Xmlrpcs.php index bdb058e82..fe55e36d6 100644 --- a/system/libraries/Xmlrpcs.php +++ b/system/libraries/Xmlrpcs.php @@ -1,503 +1,503 @@ -set_system_methods(); - - if (isset($config['functions']) && is_array($config['functions'])) - { - $this->methods = $config['functions']; - } - - log_message('debug', "XML-RPC Server Class Initialized"); - } - - //------------------------------------- - // Initialize Prefs and Serve - //------------------------------------- - - function initialize($config=array()) - { - if (isset($config['functions']) && is_array($config['functions'])) - { - $this->methods = $config['functions']; - } - - if (isset($config['debug'])) - { - $this->debug = $config['debug']; - } - } - - //------------------------------------- - // Setting of System Methods - //------------------------------------- - - function set_system_methods () - { - $system_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 - //------------------------------------- - - function serve() - { - $r = $this->parseRequest(); - $payload = 'xmlrpc_defencoding.'"?'.'>'."\n"; - $payload .= $this->debug_msg; - $payload .= $r->prepare_response(); - - header("Content-Type: text/xml"); - header("Content-Length: ".strlen($payload)); - echo $payload; - } - - //------------------------------------- - // Add Method to Class - //------------------------------------- - - function add_to_map($methodname,$function,$sig,$doc) - { - $this->methods[$methodname] = array( - 'function' => $function, - 'signature' => $sig, - 'docstring' => $doc - ); - } - - - //------------------------------------- - // Parse Server Request - //------------------------------------- - - function parseRequest($data='') - { - global $HTTP_RAW_POST_DATA; - - //------------------------------------- - // Get Data - //------------------------------------- - - if ($data == '') - { - $data = $HTTP_RAW_POST_DATA; - } - - - //------------------------------------- - // Set up XML Parser - //------------------------------------- - - $parser = xml_parser_create($this->xmlrpc_defencoding); - $parser_object = new XML_RPC_Message("filler"); - - $parser_object->xh[$parser] = array(); - $parser_object->xh[$parser]['isf'] = 0; - $parser_object->xh[$parser]['isf_reason'] = ''; - $parser_object->xh[$parser]['params'] = array(); - $parser_object->xh[$parser]['stack'] = array(); - $parser_object->xh[$parser]['valuestack'] = array(); - $parser_object->xh[$parser]['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[$parser]['isf']) - { - return new XML_RPC_Response(0, - $this->xmlrpcerr['invalid_return'], - $this->xmlrpcstr['invalid_retrun']); - } - else - { - xml_parser_free($parser); - - $m = new XML_RPC_Message($parser_object->xh[$parser]['method']); - $plist=''; - - for($i=0; $i < sizeof($parser_object->xh[$parser]['params']); $i++) - { - $plist .= "$i - " . print_r(get_object_vars($parser_object->xh[$parser]['params'][$i]), TRUE). ";\n"; - - $m->addParam($parser_object->xh[$parser]['params'][$i]); - } - - if ($this->debug === TRUE) - { - echo "
    ";
    -				echo "---PLIST---\n" . $plist . "\n---PLIST END---\n\n";
    -				echo "
    "; - } - - $r = $this->_execute($m); - } - - //------------------------------------- - // SET DEBUGGING MESSAGE - //------------------------------------- - - if ($this->debug === TRUE) - { - $this->debug_msg = "\n"; - } - - return $r; - } - - //------------------------------------- - // Executes the Method - //------------------------------------- - - function _execute($m) - { - $methName = $m->method_name; - - // Check to see if it is a system call - // If so, load the system_methods - $sysCall = ereg("^system\.", $methName); - $methods = $sysCall ? $this->system_methods : $this->methods; - - //------------------------------------- - // Check for Function - //------------------------------------- - - if (!isset($methods[$methName]['function'])) - { - return new XML_RPC_Response(0, - $this->xmlrpcerr['unknown_method'], - $this->xmlrpcstr['unknown_method']); - } - else - { - // See if we are calling function in an object - - $method_parts = explode(".",$methods[$methName]['function']); - $objectCall = (isset($method_parts['1']) && $method_parts['1'] != "") ? true : false; - - 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($methods[$methName]['function'])) - { - return new XML_RPC_Response(0, - $this->xmlrpcerr['unknown_method'], - $this->xmlrpcstr['unknown_method']); - } - } - - //------------------------------------- - // Checking Methods Signature - //------------------------------------- - - if (isset($methods[$methName]['signature'])) - { - $sig = $methods[$methName]['signature']; - for($i=0; $iparams)+1) - { - for($n=0; $n < sizeof($m->params); $n++) - { - $p = $m->params[$n]; - $pt = ($p->kindOf() == 'scalar') ? $p->scalartyp() : $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) - { - if ($method_parts['1'] == "this") - { - return call_user_func(array($this, $method_parts['0']), $m); - } - else - { - $CI =& get_instance(); - return $CI->$method_parts['1']($m); - //$class = new $method_parts['0']; - //return $class->$method_parts['1']($m); - //return call_user_func(array(&$method_parts['0'],$method_parts['1']), $m); - } - } - else - { - return call_user_func($methods[$methName]['function'], $m); - } - } - - - //------------------------------------- - // Server Function: List Methods - //------------------------------------- - - 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 - //------------------------------------- - - function methodSignature($m) - { - $methName = $m->getParam(0); - $method_name = $methName->scalarval(); - - $methods = ereg("^system\.", $method_name) ? $this->system_methods : $this->methods; - - if (isset($methods[$method_name])) - { - if ($methods[$method_name]['signature']) - { - $sigs = array(); - $signature = $methods[$method_name]['signature']; - - for($i=0; $i < sizeof($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 - //------------------------------------- - - function methodHelp($m) - { - $methName = $m->getParam(0); - $method_name = $methName->scalarval(); - - $methods = ereg("^system\.", $method_name) ? $this->system_methods : $this->methods; - - if (isset($methods[$methName])) - { - $docstring = isset($methods[$method_name]['docstring']) ? $methods[$method_name]['docstring'] : ''; - $r = new XML_RPC_Response(new XML_RPC_Values($docstring, 'string')); - } - else - { - $r = new XML_RPC_Response(0, $this->xmlrpcerr['introspect_unknown'], $this->xmlrpcstr['introspect_unknown']); - } - return $r; - } - - //------------------------------------- - // Server Function: Multi-call - //------------------------------------- - - function multicall($m) - { - $calls = $m->getParam(0); - list($a,$b)=each($calls->me); - $result = array(); - - for ($i = 0; $i < sizeof($b); $i++) - { - $call = $calls->me['array'][$i]; - $result[$i] = $this->do_multicall($call); - } - - return new XML_RPC_Response(new XML_RPC_Values($result, 'array')); - } - - - //------------------------------------- - // Multi-call Function: Error Handling - //------------------------------------- - - 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 - //------------------------------------- - - 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' || $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 = sizeof($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'); - } - -} -// END XML_RPC_Server class - +set_system_methods(); + + if (isset($config['functions']) && is_array($config['functions'])) + { + $this->methods = $config['functions']; + } + + log_message('debug', "XML-RPC Server Class Initialized"); + } + + //------------------------------------- + // Initialize Prefs and Serve + //------------------------------------- + + function initialize($config=array()) + { + if (isset($config['functions']) && is_array($config['functions'])) + { + $this->methods = $config['functions']; + } + + if (isset($config['debug'])) + { + $this->debug = $config['debug']; + } + } + + //------------------------------------- + // Setting of System Methods + //------------------------------------- + + function set_system_methods () + { + $system_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 + //------------------------------------- + + function serve() + { + $r = $this->parseRequest(); + $payload = 'xmlrpc_defencoding.'"?'.'>'."\n"; + $payload .= $this->debug_msg; + $payload .= $r->prepare_response(); + + header("Content-Type: text/xml"); + header("Content-Length: ".strlen($payload)); + echo $payload; + } + + //------------------------------------- + // Add Method to Class + //------------------------------------- + + function add_to_map($methodname,$function,$sig,$doc) + { + $this->methods[$methodname] = array( + 'function' => $function, + 'signature' => $sig, + 'docstring' => $doc + ); + } + + + //------------------------------------- + // Parse Server Request + //------------------------------------- + + function parseRequest($data='') + { + global $HTTP_RAW_POST_DATA; + + //------------------------------------- + // Get Data + //------------------------------------- + + if ($data == '') + { + $data = $HTTP_RAW_POST_DATA; + } + + + //------------------------------------- + // Set up XML Parser + //------------------------------------- + + $parser = xml_parser_create($this->xmlrpc_defencoding); + $parser_object = new XML_RPC_Message("filler"); + + $parser_object->xh[$parser] = array(); + $parser_object->xh[$parser]['isf'] = 0; + $parser_object->xh[$parser]['isf_reason'] = ''; + $parser_object->xh[$parser]['params'] = array(); + $parser_object->xh[$parser]['stack'] = array(); + $parser_object->xh[$parser]['valuestack'] = array(); + $parser_object->xh[$parser]['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[$parser]['isf']) + { + return new XML_RPC_Response(0, + $this->xmlrpcerr['invalid_return'], + $this->xmlrpcstr['invalid_retrun']); + } + else + { + xml_parser_free($parser); + + $m = new XML_RPC_Message($parser_object->xh[$parser]['method']); + $plist=''; + + for($i=0; $i < sizeof($parser_object->xh[$parser]['params']); $i++) + { + $plist .= "$i - " . print_r(get_object_vars($parser_object->xh[$parser]['params'][$i]), TRUE). ";\n"; + + $m->addParam($parser_object->xh[$parser]['params'][$i]); + } + + if ($this->debug === TRUE) + { + echo "
    ";
    +				echo "---PLIST---\n" . $plist . "\n---PLIST END---\n\n";
    +				echo "
    "; + } + + $r = $this->_execute($m); + } + + //------------------------------------- + // SET DEBUGGING MESSAGE + //------------------------------------- + + if ($this->debug === TRUE) + { + $this->debug_msg = "\n"; + } + + return $r; + } + + //------------------------------------- + // Executes the Method + //------------------------------------- + + function _execute($m) + { + $methName = $m->method_name; + + // Check to see if it is a system call + // If so, load the system_methods + $sysCall = ereg("^system\.", $methName); + $methods = $sysCall ? $this->system_methods : $this->methods; + + //------------------------------------- + // Check for Function + //------------------------------------- + + if (!isset($methods[$methName]['function'])) + { + return new XML_RPC_Response(0, + $this->xmlrpcerr['unknown_method'], + $this->xmlrpcstr['unknown_method']); + } + else + { + // See if we are calling function in an object + + $method_parts = explode(".",$methods[$methName]['function']); + $objectCall = (isset($method_parts['1']) && $method_parts['1'] != "") ? true : false; + + 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($methods[$methName]['function'])) + { + return new XML_RPC_Response(0, + $this->xmlrpcerr['unknown_method'], + $this->xmlrpcstr['unknown_method']); + } + } + + //------------------------------------- + // Checking Methods Signature + //------------------------------------- + + if (isset($methods[$methName]['signature'])) + { + $sig = $methods[$methName]['signature']; + for($i=0; $iparams)+1) + { + for($n=0; $n < sizeof($m->params); $n++) + { + $p = $m->params[$n]; + $pt = ($p->kindOf() == 'scalar') ? $p->scalartyp() : $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) + { + if ($method_parts['1'] == "this") + { + return call_user_func(array($this, $method_parts['0']), $m); + } + else + { + $CI =& get_instance(); + return $CI->$method_parts['1']($m); + //$class = new $method_parts['0']; + //return $class->$method_parts['1']($m); + //return call_user_func(array(&$method_parts['0'],$method_parts['1']), $m); + } + } + else + { + return call_user_func($methods[$methName]['function'], $m); + } + } + + + //------------------------------------- + // Server Function: List Methods + //------------------------------------- + + 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 + //------------------------------------- + + function methodSignature($m) + { + $methName = $m->getParam(0); + $method_name = $methName->scalarval(); + + $methods = ereg("^system\.", $method_name) ? $this->system_methods : $this->methods; + + if (isset($methods[$method_name])) + { + if ($methods[$method_name]['signature']) + { + $sigs = array(); + $signature = $methods[$method_name]['signature']; + + for($i=0; $i < sizeof($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 + //------------------------------------- + + function methodHelp($m) + { + $methName = $m->getParam(0); + $method_name = $methName->scalarval(); + + $methods = ereg("^system\.", $method_name) ? $this->system_methods : $this->methods; + + if (isset($methods[$methName])) + { + $docstring = isset($methods[$method_name]['docstring']) ? $methods[$method_name]['docstring'] : ''; + $r = new XML_RPC_Response(new XML_RPC_Values($docstring, 'string')); + } + else + { + $r = new XML_RPC_Response(0, $this->xmlrpcerr['introspect_unknown'], $this->xmlrpcstr['introspect_unknown']); + } + return $r; + } + + //------------------------------------- + // Server Function: Multi-call + //------------------------------------- + + function multicall($m) + { + $calls = $m->getParam(0); + list($a,$b)=each($calls->me); + $result = array(); + + for ($i = 0; $i < sizeof($b); $i++) + { + $call = $calls->me['array'][$i]; + $result[$i] = $this->do_multicall($call); + } + + return new XML_RPC_Response(new XML_RPC_Values($result, 'array')); + } + + + //------------------------------------- + // Multi-call Function: Error Handling + //------------------------------------- + + 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 + //------------------------------------- + + 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' || $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 = sizeof($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'); + } + +} +// END XML_RPC_Server class + ?> \ No newline at end of file diff --git a/system/libraries/Zip.php b/system/libraries/Zip.php index 1ff175fe2..377c38741 100644 --- a/system/libraries/Zip.php +++ b/system/libraries/Zip.php @@ -1,380 +1,380 @@ -_add_dir($dir); - } - } - - // -------------------------------------------------------------------- - - /** - * Add Directory - * - * @access private - * @param string the directory name - * @return void - */ - function _add_dir($dir) - { - $dir = str_replace("\\", "/", $dir); - - $this->zipdata[] = "\x50\x4b\x03\x04\x0a\x00\x00\x00\x00\x00\x00\x00\x00\x00" - .pack('V', 0) - .pack('V', 0) - .pack('V', 0) - .pack('v', strlen($dir)) - .pack('v', 0) - .$dir - .pack('V', 0) - .pack('V', 0) - .pack('V', 0); - - $newoffset = strlen(implode('', $this->zipdata)); - - $record = "\x50\x4b\x01\x02\x00\x00\x0a\x00\x00\x00\x00\x00\x00\x00\x00\x00" - .pack('V',0) - .pack('V',0) - .pack('V',0) - .pack('v', strlen($dir)) - .pack('v', 0) - .pack('v', 0) - .pack('v', 0) - .pack('v', 0) - .pack('V', 16) - .pack('V', $this->offset) - .$dir; - - $this->offset = $newoffset; - $this->directory[] = $record; - } - - // -------------------------------------------------------------------- - - /** - * 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) - { - $this->_add_data($path, $data); - } - } - else - { - $this->_add_data($filepath, $data); - } - } - - // -------------------------------------------------------------------- - - /** - * 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) - { - $filepath = str_replace("\\", "/", $filepath); - - $oldlen = strlen($data); - $crc32 = crc32($data); - - $gzdata = gzcompress($data); - $gzdata = substr(substr($gzdata, 0, strlen($gzdata) - 4), 2); - $newlen = strlen($gzdata); - - $this->zipdata[] = "\x50\x4b\x03\x04\x14\x00\x00\x00\x08\x00\x00\x00\x00\x00" - .pack('V', $crc32) - .pack('V', $newlen) - .pack('V', $oldlen) - .pack('v', strlen($filepath)) - .pack('v', 0) - .$filepath - .$gzdata - .pack('V', $crc32) - .pack('V', $newlen) - .pack('V', $oldlen); - - $newoffset = strlen(implode("", $this->zipdata)); - - $record = "\x50\x4b\x01\x02\x00\x00\x14\x00\x00\x00\x08\x00\x00\x00\x00\x00" - .pack('V', $crc32) - .pack('V', $newlen) - .pack('V', $oldlen) - .pack('v', strlen($filepath)) - .pack('v', 0) - .pack('v', 0) - .pack('v', 0) - .pack('v', 0) - .pack('V', 32) - .pack('V', $this->offset); - - $this->offset = $newoffset; - $this->directory[] = $record.$filepath; - } - - // -------------------------------------------------------------------- - - /** - * 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) - { - if ($fp = @opendir($path)) - { - while (FALSE !== ($file = readdir($fp))) - { - if (@is_dir($path.$file) && substr($file, 0, 1) != '.') - { - $this->read_dir($path.$file."/"); - } - elseif (substr($file, 0, 1) != ".") - { - if (FALSE !== ($data = file_get_contents($path.$file))) - { - $this->add_data(str_replace("\\", "/", $path).$file, $data); - } - } - } - return TRUE; - } - } - - // -------------------------------------------------------------------- - - /** - * Get the Zip file - * - * @access public - * @return binary string - */ - function get_zip() - { - // We cache the zip data so multiple calls - // do not require recompiling - if ($this->zipfile != '') - { - return $this->zipfile; - } - - // Is there any data to return? - if (count($this->zipdata) == 0) - { - return FALSE; - } - - $data = implode('', $this->zipdata); - $dir = implode('', $this->directory); - - $this->zipfile = $data.$dir."\x50\x4b\x05\x06\x00\x00\x00\x00" - .pack('v', sizeof($this->directory)) - .pack('v', sizeof($this->directory)) - .pack('V', strlen($dir)) - .pack('V', strlen($data)) - ."\x00\x00"; - - return $this->zipfile; - } - - // -------------------------------------------------------------------- - - /** - * Write File to the specified directory - * - * Lets you write a file - * - * @access public - * @param string the file name - * @param string the data to be encoded - * @return bool - */ - function archive($filepath) - { - if ( ! ($fp = @fopen($filepath, "wb"))) - { - 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'; - } - - if (strstr($_SERVER['HTTP_USER_AGENT'], "MSIE")) - { - header('Content-Type: application/x-zip'); - header('Content-Disposition: inline; filename="'.$filename.'"'); - header('Expires: 0'); - header('Cache-Control: must-revalidate, post-check=0, pre-check=0'); - header("Content-Transfer-Encoding: binary"); - header('Pragma: public'); - header("Content-Length: ".strlen($this->get_zip())); - } - else - { - header('Content-Type: application/x-zip'); - header('Content-Disposition: attachment; filename="'.$filename.'"'); - header("Content-Transfer-Encoding: binary"); - header('Expires: 0'); - header('Pragma: no-cache'); - header("Content-Length: ".strlen($this->get_zip())); - } - - echo $this->get_zip(); - } - - // -------------------------------------------------------------------- - - /** - * 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->zipfile = ''; - $this->zipdata = array(); - $this->directory = array(); - $this->offset = array(); - } - -} +_add_dir($dir); + } + } + + // -------------------------------------------------------------------- + + /** + * Add Directory + * + * @access private + * @param string the directory name + * @return void + */ + function _add_dir($dir) + { + $dir = str_replace("\\", "/", $dir); + + $this->zipdata[] = "\x50\x4b\x03\x04\x0a\x00\x00\x00\x00\x00\x00\x00\x00\x00" + .pack('V', 0) + .pack('V', 0) + .pack('V', 0) + .pack('v', strlen($dir)) + .pack('v', 0) + .$dir + .pack('V', 0) + .pack('V', 0) + .pack('V', 0); + + $newoffset = strlen(implode('', $this->zipdata)); + + $record = "\x50\x4b\x01\x02\x00\x00\x0a\x00\x00\x00\x00\x00\x00\x00\x00\x00" + .pack('V',0) + .pack('V',0) + .pack('V',0) + .pack('v', strlen($dir)) + .pack('v', 0) + .pack('v', 0) + .pack('v', 0) + .pack('v', 0) + .pack('V', 16) + .pack('V', $this->offset) + .$dir; + + $this->offset = $newoffset; + $this->directory[] = $record; + } + + // -------------------------------------------------------------------- + + /** + * 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) + { + $this->_add_data($path, $data); + } + } + else + { + $this->_add_data($filepath, $data); + } + } + + // -------------------------------------------------------------------- + + /** + * 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) + { + $filepath = str_replace("\\", "/", $filepath); + + $oldlen = strlen($data); + $crc32 = crc32($data); + + $gzdata = gzcompress($data); + $gzdata = substr(substr($gzdata, 0, strlen($gzdata) - 4), 2); + $newlen = strlen($gzdata); + + $this->zipdata[] = "\x50\x4b\x03\x04\x14\x00\x00\x00\x08\x00\x00\x00\x00\x00" + .pack('V', $crc32) + .pack('V', $newlen) + .pack('V', $oldlen) + .pack('v', strlen($filepath)) + .pack('v', 0) + .$filepath + .$gzdata + .pack('V', $crc32) + .pack('V', $newlen) + .pack('V', $oldlen); + + $newoffset = strlen(implode("", $this->zipdata)); + + $record = "\x50\x4b\x01\x02\x00\x00\x14\x00\x00\x00\x08\x00\x00\x00\x00\x00" + .pack('V', $crc32) + .pack('V', $newlen) + .pack('V', $oldlen) + .pack('v', strlen($filepath)) + .pack('v', 0) + .pack('v', 0) + .pack('v', 0) + .pack('v', 0) + .pack('V', 32) + .pack('V', $this->offset); + + $this->offset = $newoffset; + $this->directory[] = $record.$filepath; + } + + // -------------------------------------------------------------------- + + /** + * 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) + { + if ($fp = @opendir($path)) + { + while (FALSE !== ($file = readdir($fp))) + { + if (@is_dir($path.$file) && substr($file, 0, 1) != '.') + { + $this->read_dir($path.$file."/"); + } + elseif (substr($file, 0, 1) != ".") + { + if (FALSE !== ($data = file_get_contents($path.$file))) + { + $this->add_data(str_replace("\\", "/", $path).$file, $data); + } + } + } + return TRUE; + } + } + + // -------------------------------------------------------------------- + + /** + * Get the Zip file + * + * @access public + * @return binary string + */ + function get_zip() + { + // We cache the zip data so multiple calls + // do not require recompiling + if ($this->zipfile != '') + { + return $this->zipfile; + } + + // Is there any data to return? + if (count($this->zipdata) == 0) + { + return FALSE; + } + + $data = implode('', $this->zipdata); + $dir = implode('', $this->directory); + + $this->zipfile = $data.$dir."\x50\x4b\x05\x06\x00\x00\x00\x00" + .pack('v', sizeof($this->directory)) + .pack('v', sizeof($this->directory)) + .pack('V', strlen($dir)) + .pack('V', strlen($data)) + ."\x00\x00"; + + return $this->zipfile; + } + + // -------------------------------------------------------------------- + + /** + * Write File to the specified directory + * + * Lets you write a file + * + * @access public + * @param string the file name + * @param string the data to be encoded + * @return bool + */ + function archive($filepath) + { + if ( ! ($fp = @fopen($filepath, "wb"))) + { + 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'; + } + + if (strstr($_SERVER['HTTP_USER_AGENT'], "MSIE")) + { + header('Content-Type: application/x-zip'); + header('Content-Disposition: inline; filename="'.$filename.'"'); + header('Expires: 0'); + header('Cache-Control: must-revalidate, post-check=0, pre-check=0'); + header("Content-Transfer-Encoding: binary"); + header('Pragma: public'); + header("Content-Length: ".strlen($this->get_zip())); + } + else + { + header('Content-Type: application/x-zip'); + header('Content-Disposition: attachment; filename="'.$filename.'"'); + header("Content-Transfer-Encoding: binary"); + header('Expires: 0'); + header('Pragma: no-cache'); + header("Content-Length: ".strlen($this->get_zip())); + } + + echo $this->get_zip(); + } + + // -------------------------------------------------------------------- + + /** + * 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->zipfile = ''; + $this->zipdata = array(); + $this->directory = array(); + $this->offset = array(); + } + +} ?> \ No newline at end of file diff --git a/system/plugins/captcha_pi.php b/system/plugins/captcha_pi.php index b3c22f092..e16a214b6 100644 --- a/system/plugins/captcha_pi.php +++ b/system/plugins/captcha_pi.php @@ -1,346 +1,346 @@ -load->plugin('captcha'); - -Once loaded you can generate a captcha like this: - - $vals = array( - 'word' => 'Random word', - 'img_path' => './captcha/', - 'img_url' => 'http://www.your-site.com/captcha/', - 'font_path' => './system/texb.ttf', - 'img_width' => '150', - 'img_height' => 30, - 'expiration' => 7200 - ); - - $cap = create_captcha($vals); - echo $cap['image']; - - -NOTES: - - The captcha function requires the GD image library. - - Only the img_path and img_url are required. - - If a "word" is not supplied, the function will generate a random - ASCII string. You might put together your own word library that - you can draw randomly from. - - If you do not specify a path to a TRUE TYPE font, the native ugly GD - font will be used. - - The "captcha" folder must be writable (666, or 777) - - The "expiration" (in seconds) signifies how long an image will - remain in the captcha folder before it will be deleted. The default - is two hours. - -RETURNED DATA - -The create_captcha() function returns an associative array with this data: - - [array] - ( - 'image' => IMAGE TAG - 'time' => TIMESTAMP (in microtime) - 'word' => CAPTCHA WORD - ) - -The "image" is the actual image tag: - - -The "time" is the micro timestamp used as the image name without the file -extension. It will be a number like this: 1139612155.3422 - -The "word" is the word that appears in the captcha image, which if not -supplied to the function, will be a random string. - - -ADDING A DATABASE - -In order for the captcha function to prevent someone from posting, you will need -to add the information returned from create_captcha() function to your database. -Then, when the data from the form is submitted by the user you will need to verify -that the data exists in the database and has not expired. - -Here is a table prototype: - - CREATE TABLE captcha ( - captcha_id bigint(13) unsigned NOT NULL auto_increment, - captcha_time int(10) unsigned NOT NULL, - ip_address varchar(16) default '0' NOT NULL, - word varchar(20) NOT NULL, - PRIMARY KEY (captcha_id), - KEY (word) - ) - - -Here is an example of usage with a DB. - -On the page where the captcha will be shown you'll have something like this: - - $this->load->plugin('captcha'); - $vals = array( - 'img_path' => './captcha/', - 'img_url' => 'http://www.your-site.com/captcha/' - ); - - $cap = create_captcha($vals); - - $data = array( - 'captcha_id' => '', - 'captcha_time' => $cap['time'], - 'ip_address' => $this->input->ip_address(), - 'word' => $cap['word'] - ); - - $query = $this->db->insert_string('captcha', $data); - $this->db->query($query); - - echo 'Submit the word you see below:'; - echo $cap['image']; - echo ''; - - -Then, on the page that accepts the submission you'll have something like this: - - // First, delete old captchas - $expiration = time()-7200; // Two hour limit - $DB->query("DELETE FROM captcha WHERE captcha_time < ".$expiration); - - // Then see if a captcha exists: - $sql = "SELECT COUNT(*) AS count FROM captcha WHERE word = ? AND ip_address = ? AND date > ?"; - $binds = array($_POST['captcha'], $this->input->ip_address(), $expiration); - $query = $this->db->query($sql, $binds); - $row = $query->row(); - - if ($row->count == 0) - { - echo "You must submit the word that appears in the image"; - } - -*/ - - - -/** -|========================================================== -| Create Captcha -|========================================================== -| -*/ -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); - - 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 - // ----------------------------------- - - $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); -} - +load->plugin('captcha'); + +Once loaded you can generate a captcha like this: + + $vals = array( + 'word' => 'Random word', + 'img_path' => './captcha/', + 'img_url' => 'http://www.your-site.com/captcha/', + 'font_path' => './system/texb.ttf', + 'img_width' => '150', + 'img_height' => 30, + 'expiration' => 7200 + ); + + $cap = create_captcha($vals); + echo $cap['image']; + + +NOTES: + + The captcha function requires the GD image library. + + Only the img_path and img_url are required. + + If a "word" is not supplied, the function will generate a random + ASCII string. You might put together your own word library that + you can draw randomly from. + + If you do not specify a path to a TRUE TYPE font, the native ugly GD + font will be used. + + The "captcha" folder must be writable (666, or 777) + + The "expiration" (in seconds) signifies how long an image will + remain in the captcha folder before it will be deleted. The default + is two hours. + +RETURNED DATA + +The create_captcha() function returns an associative array with this data: + + [array] + ( + 'image' => IMAGE TAG + 'time' => TIMESTAMP (in microtime) + 'word' => CAPTCHA WORD + ) + +The "image" is the actual image tag: + + +The "time" is the micro timestamp used as the image name without the file +extension. It will be a number like this: 1139612155.3422 + +The "word" is the word that appears in the captcha image, which if not +supplied to the function, will be a random string. + + +ADDING A DATABASE + +In order for the captcha function to prevent someone from posting, you will need +to add the information returned from create_captcha() function to your database. +Then, when the data from the form is submitted by the user you will need to verify +that the data exists in the database and has not expired. + +Here is a table prototype: + + CREATE TABLE captcha ( + captcha_id bigint(13) unsigned NOT NULL auto_increment, + captcha_time int(10) unsigned NOT NULL, + ip_address varchar(16) default '0' NOT NULL, + word varchar(20) NOT NULL, + PRIMARY KEY (captcha_id), + KEY (word) + ) + + +Here is an example of usage with a DB. + +On the page where the captcha will be shown you'll have something like this: + + $this->load->plugin('captcha'); + $vals = array( + 'img_path' => './captcha/', + 'img_url' => 'http://www.your-site.com/captcha/' + ); + + $cap = create_captcha($vals); + + $data = array( + 'captcha_id' => '', + 'captcha_time' => $cap['time'], + 'ip_address' => $this->input->ip_address(), + 'word' => $cap['word'] + ); + + $query = $this->db->insert_string('captcha', $data); + $this->db->query($query); + + echo 'Submit the word you see below:'; + echo $cap['image']; + echo ''; + + +Then, on the page that accepts the submission you'll have something like this: + + // First, delete old captchas + $expiration = time()-7200; // Two hour limit + $DB->query("DELETE FROM captcha WHERE captcha_time < ".$expiration); + + // Then see if a captcha exists: + $sql = "SELECT COUNT(*) AS count FROM captcha WHERE word = ? AND ip_address = ? AND date > ?"; + $binds = array($_POST['captcha'], $this->input->ip_address(), $expiration); + $query = $this->db->query($sql, $binds); + $row = $query->row(); + + if ($row->count == 0) + { + echo "You must submit the word that appears in the image"; + } + +*/ + + + +/** +|========================================================== +| Create Captcha +|========================================================== +| +*/ +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); + + 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 + // ----------------------------------- + + $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); +} + ?> \ No newline at end of file diff --git a/system/plugins/js_calendar_pi.php b/system/plugins/js_calendar_pi.php index 987bd49ed..a461e34a7 100644 --- a/system/plugins/js_calendar_pi.php +++ b/system/plugins/js_calendar_pi.php @@ -1,604 +1,604 @@ -load->plugin('js_calendar'); - -Once loaded you'll add the calendar script to the of your page like this: - - - -The above function will be passed the name of your form. - -Then to show the actual calendar you'll do this: - - -
    - -

    Today

    -
    - - -Note: The first parameter is the name of the field containing your date, the second parameter contains the "now" time, -and the third tells the calendar whether to highlight the current day or not. - -Lastly, you'll need some CSS for your calendar: - -.calendar { - border: 1px #6975A3 solid; - background-color: transparent; -} -.calheading { - background-color: #7C8BC0; - color: #fff; - font-family: Lucida Grande, Verdana, Geneva, Sans-serif; - font-size: 11px; - font-weight: bold; - text-align: center; -} -.calnavleft { - background-color: #7C8BC0; - font-family: Lucida Grande, Verdana, Geneva, Sans-serif; - font-size: 10px; - font-weight: bold; - color: #fff; - padding: 4px; - cursor: pointer; -} -.calnavright { - background-color: #7C8BC0; - font-family: Lucida Grande, Verdana, Geneva, Sans-serif; - font-size: 10px; - font-weight: bold; - color: #fff; - text-align: right; - padding: 4px; - cursor: pointer; -} -.caldayheading { - background-color: #000; - color: #fff; - font-family: Lucida Grande, Verdana, Geneva, Sans-serif; - font-size: 10px; - text-align: center; - padding: 6px 2px 6px 2px; -} -.caldaycells{ - color: #000; - background-color: #D1D7E6; - font-family: Lucida Grande, Verdana, Geneva, Sans-serif; - font-size: 11px; - text-align: center; - padding: 4px; - border: 1px #E0E5F1 solid; - cursor: pointer; -} -.caldaycellhover{ - color: #fff; - background-color: #B3BCD4; - font-family: Lucida Grande, Verdana, Geneva, Sans-serif; - font-size: 11px; - text-align: center; - padding: 4px; - border: 1px #B3BCD4 solid; - cursor: pointer; -} -.caldayselected{ - background-color: #737FAC; - color: #fff; - font-family: Lucida Grande, Verdana, Geneva, Sans-serif; - font-size: 11px; - font-weight: bold; - text-align: center; - border: 1px #566188 solid; - padding: 3px; - cursor: pointer; -} -.calblanktop { - background-color: #fff; - padding: 4px; -} -.calblankbot { - background-color: #fff; - padding: 4px; -} - - -*/ - -function js_calendar_script($form_name = 'entryform') -{ - -ob_start(); -?> - - - var '.$field_id.' = new calendar("'.$field_id.'", '.$time.', '.(($highlight == TRUE) ? 'true' : 'false').'); - document.write('.$field_id.'.write()); - '; -} - +load->plugin('js_calendar'); + +Once loaded you'll add the calendar script to the of your page like this: + + + +The above function will be passed the name of your form. + +Then to show the actual calendar you'll do this: + + +
    + +

    Today

    +
    + + +Note: The first parameter is the name of the field containing your date, the second parameter contains the "now" time, +and the third tells the calendar whether to highlight the current day or not. + +Lastly, you'll need some CSS for your calendar: + +.calendar { + border: 1px #6975A3 solid; + background-color: transparent; +} +.calheading { + background-color: #7C8BC0; + color: #fff; + font-family: Lucida Grande, Verdana, Geneva, Sans-serif; + font-size: 11px; + font-weight: bold; + text-align: center; +} +.calnavleft { + background-color: #7C8BC0; + font-family: Lucida Grande, Verdana, Geneva, Sans-serif; + font-size: 10px; + font-weight: bold; + color: #fff; + padding: 4px; + cursor: pointer; +} +.calnavright { + background-color: #7C8BC0; + font-family: Lucida Grande, Verdana, Geneva, Sans-serif; + font-size: 10px; + font-weight: bold; + color: #fff; + text-align: right; + padding: 4px; + cursor: pointer; +} +.caldayheading { + background-color: #000; + color: #fff; + font-family: Lucida Grande, Verdana, Geneva, Sans-serif; + font-size: 10px; + text-align: center; + padding: 6px 2px 6px 2px; +} +.caldaycells{ + color: #000; + background-color: #D1D7E6; + font-family: Lucida Grande, Verdana, Geneva, Sans-serif; + font-size: 11px; + text-align: center; + padding: 4px; + border: 1px #E0E5F1 solid; + cursor: pointer; +} +.caldaycellhover{ + color: #fff; + background-color: #B3BCD4; + font-family: Lucida Grande, Verdana, Geneva, Sans-serif; + font-size: 11px; + text-align: center; + padding: 4px; + border: 1px #B3BCD4 solid; + cursor: pointer; +} +.caldayselected{ + background-color: #737FAC; + color: #fff; + font-family: Lucida Grande, Verdana, Geneva, Sans-serif; + font-size: 11px; + font-weight: bold; + text-align: center; + border: 1px #566188 solid; + padding: 3px; + cursor: pointer; +} +.calblanktop { + background-color: #fff; + padding: 4px; +} +.calblankbot { + background-color: #fff; + padding: 4px; +} + + +*/ + +function js_calendar_script($form_name = 'entryform') +{ + +ob_start(); +?> + + + var '.$field_id.' = new calendar("'.$field_id.'", '.$time.', '.(($highlight == TRUE) ? 'true' : 'false').'); + document.write('.$field_id.'.write()); + '; +} + ?> \ No newline at end of file diff --git a/system/scaffolding/Scaffolding.php b/system/scaffolding/Scaffolding.php index d42b56863..fe2744e77 100644 --- a/system/scaffolding/Scaffolding.php +++ b/system/scaffolding/Scaffolding.php @@ -1,289 +1,289 @@ -CI =& get_instance(); - - $this->CI->load->database("", FALSE, TRUE); - $this->CI->load->library('pagination'); - - // Turn off caching - $this->CI->db->cache_off(); - - /** - * Set the current table name - * This is done when initializing scaffolding: - * $this->load->scaffolding('table_name') - * - */ - $this->current_table = $db_table; - - /** - * Set the path to the "view" files - * We'll manually override the "view" path so that - * the load->view function knows where to look. - */ - - $this->CI->load->_ci_view_path = BASEPATH.'scaffolding/views/'; - - // Set the base URL - $this->base_url = $this->CI->config->site_url().'/'.$this->CI->uri->segment(1).$this->CI->uri->slash_segment(2, 'both'); - $this->base_uri = $this->CI->uri->segment(1).$this->CI->uri->slash_segment(2, 'leading'); - - // Set a few globals - $data = array( - 'image_url' => $this->CI->config->system_url().'scaffolding/images/', - 'base_uri' => $this->base_uri, - 'base_url' => $this->base_url, - 'title' => $this->current_table - ); - - $this->CI->load->vars($data); - - // Load the language file and create variables - $this->lang = $this->CI->load->language('scaffolding', '', TRUE); - $this->CI->load->vars($this->lang); - - // Load the helper files we plan to use - $this->CI->load->helper(array('url', 'form')); - - - log_message('debug', 'Scaffolding Class Initialized'); - } - - // -------------------------------------------------------------------- - - /** - * "Add" Page - * - * Shows a form representing the currently selected DB - * so that data can be inserted - * - * @access public - * @return string the HTML "add" page - */ - function add() - { - $data = array( - 'title' => ( ! isset($this->lang['scaff_add'])) ? 'Add Data' : $this->lang['scaff_add'], - 'fields' => $this->CI->db->field_data($this->current_table), - 'action' => $this->base_uri.'/insert' - ); - - $this->CI->load->view('add', $data); - } - - // -------------------------------------------------------------------- - - /** - * Insert the data - * - * @access public - * @return void redirects to the view page - */ - function insert() - { - if ($this->CI->db->insert($this->current_table, $_POST) === FALSE) - { - $this->add(); - } - else - { - redirect($this->base_uri.'/view/'); - } - } - - // -------------------------------------------------------------------- - - /** - * "View" Page - * - * Shows a table containing the data in the currently - * selected DB - * - * @access public - * @return string the HTML "view" page - */ - function view() - { - // Fetch the total number of DB rows - $total_rows = $this->CI->db->count_all($this->current_table); - - if ($total_rows < 1) - { - return $this->CI->load->view('no_data'); - } - - // Set the query limit/offset - $per_page = 20; - $offset = $this->CI->uri->segment(4, 0); - - // Run the query - $query = $this->CI->db->get($this->current_table, $per_page, $offset); - - // Now let's get the field names - $fields = $this->CI->db->list_fields($this->current_table); - - // We assume that the column in the first position is the primary field. - $primary = current($fields); - - // Pagination! - $this->CI->pagination->initialize( - array( - 'base_url' => $this->base_url.'/view', - 'total_rows' => $total_rows, - 'per_page' => $per_page, - 'uri_segment' => 4, - 'full_tag_open' => '

    ', - 'full_tag_close' => '

    ' - ) - ); - - $data = array( - 'title' => ( ! isset($this->lang['scaff_view'])) ? 'View Data' : $this->lang['scaff_view'], - 'query' => $query, - 'fields' => $fields, - 'primary' => $primary, - 'paginate' => $this->CI->pagination->create_links() - ); - - $this->CI->load->view('view', $data); - } - - // -------------------------------------------------------------------- - - /** - * "Edit" Page - * - * Shows a form representing the currently selected DB - * so that data can be edited - * - * @access public - * @return string the HTML "edit" page - */ - function edit() - { - if (FALSE === ($id = $this->CI->uri->segment(4))) - { - return $this->view(); - } - - // Fetch the primary field name - $primary = $this->CI->db->primary($this->current_table); - - // Run the query - $query = $this->CI->db->getwhere($this->current_table, array($primary => $id)); - - $data = array( - 'title' => ( ! isset($this->lang['scaff_edit'])) ? 'Edit Data' : $this->lang['scaff_edit'], - 'fields' => $query->field_data(), - 'query' => $query->row(), - 'action' => $this->base_uri.'/update/'.$this->CI->uri->segment(4) - ); - - $this->CI->load->view('edit', $data); - } - - // -------------------------------------------------------------------- - - /** - * Update - * - * @access public - * @return void redirects to the view page - */ - function update() - { - // Fetch the primary key - $primary = $this->CI->db->primary($this->current_table); - - // Now do the query - $this->CI->db->update($this->current_table, $_POST, array($primary => $this->CI->uri->segment(4))); - - redirect($this->base_uri.'/view/'); - } - - // -------------------------------------------------------------------- - - /** - * Delete Confirmation - * - * @access public - * @return string the HTML "delete confirm" page - */ - function delete() - { - if ( ! isset($this->lang['scaff_del_confirm'])) - { - $message = 'Are you sure you want to delete the following row: '.$this->CI->uri->segment(4); - } - else - { - $message = $this->lang['scaff_del_confirm'].' '.$this->CI->uri->segment(4); - } - - $data = array( - 'title' => ( ! isset($this->lang['scaff_delete'])) ? 'Delete Data' : $this->lang['scaff_delete'], - 'message' => $message, - 'no' => anchor(array($this->base_uri, 'view'), ( ! isset($this->lang['scaff_no'])) ? 'No' : $this->lang['scaff_no']), - 'yes' => anchor(array($this->base_uri, 'do_delete', $this->CI->uri->segment(4)), ( ! isset($this->lang['scaff_yes'])) ? 'Yes' : $this->lang['scaff_yes']) - ); - - $this->CI->load->view('delete', $data); - } - - // -------------------------------------------------------------------- - - /** - * Delete - * - * @access public - * @return void redirects to the view page - */ - function do_delete() - { - // Fetch the primary key - $primary = $this->CI->db->primary($this->current_table); - - // Now do the query - $this->CI->db->where($primary, $this->CI->uri->segment(4)); - $this->CI->db->delete($this->current_table); - - header("Refresh:0;url=".site_url(array($this->base_uri, 'view'))); - exit; - } - -} +CI =& get_instance(); + + $this->CI->load->database("", FALSE, TRUE); + $this->CI->load->library('pagination'); + + // Turn off caching + $this->CI->db->cache_off(); + + /** + * Set the current table name + * This is done when initializing scaffolding: + * $this->load->scaffolding('table_name') + * + */ + $this->current_table = $db_table; + + /** + * Set the path to the "view" files + * We'll manually override the "view" path so that + * the load->view function knows where to look. + */ + + $this->CI->load->_ci_view_path = BASEPATH.'scaffolding/views/'; + + // Set the base URL + $this->base_url = $this->CI->config->site_url().'/'.$this->CI->uri->segment(1).$this->CI->uri->slash_segment(2, 'both'); + $this->base_uri = $this->CI->uri->segment(1).$this->CI->uri->slash_segment(2, 'leading'); + + // Set a few globals + $data = array( + 'image_url' => $this->CI->config->system_url().'scaffolding/images/', + 'base_uri' => $this->base_uri, + 'base_url' => $this->base_url, + 'title' => $this->current_table + ); + + $this->CI->load->vars($data); + + // Load the language file and create variables + $this->lang = $this->CI->load->language('scaffolding', '', TRUE); + $this->CI->load->vars($this->lang); + + // Load the helper files we plan to use + $this->CI->load->helper(array('url', 'form')); + + + log_message('debug', 'Scaffolding Class Initialized'); + } + + // -------------------------------------------------------------------- + + /** + * "Add" Page + * + * Shows a form representing the currently selected DB + * so that data can be inserted + * + * @access public + * @return string the HTML "add" page + */ + function add() + { + $data = array( + 'title' => ( ! isset($this->lang['scaff_add'])) ? 'Add Data' : $this->lang['scaff_add'], + 'fields' => $this->CI->db->field_data($this->current_table), + 'action' => $this->base_uri.'/insert' + ); + + $this->CI->load->view('add', $data); + } + + // -------------------------------------------------------------------- + + /** + * Insert the data + * + * @access public + * @return void redirects to the view page + */ + function insert() + { + if ($this->CI->db->insert($this->current_table, $_POST) === FALSE) + { + $this->add(); + } + else + { + redirect($this->base_uri.'/view/'); + } + } + + // -------------------------------------------------------------------- + + /** + * "View" Page + * + * Shows a table containing the data in the currently + * selected DB + * + * @access public + * @return string the HTML "view" page + */ + function view() + { + // Fetch the total number of DB rows + $total_rows = $this->CI->db->count_all($this->current_table); + + if ($total_rows < 1) + { + return $this->CI->load->view('no_data'); + } + + // Set the query limit/offset + $per_page = 20; + $offset = $this->CI->uri->segment(4, 0); + + // Run the query + $query = $this->CI->db->get($this->current_table, $per_page, $offset); + + // Now let's get the field names + $fields = $this->CI->db->list_fields($this->current_table); + + // We assume that the column in the first position is the primary field. + $primary = current($fields); + + // Pagination! + $this->CI->pagination->initialize( + array( + 'base_url' => $this->base_url.'/view', + 'total_rows' => $total_rows, + 'per_page' => $per_page, + 'uri_segment' => 4, + 'full_tag_open' => '

    ', + 'full_tag_close' => '

    ' + ) + ); + + $data = array( + 'title' => ( ! isset($this->lang['scaff_view'])) ? 'View Data' : $this->lang['scaff_view'], + 'query' => $query, + 'fields' => $fields, + 'primary' => $primary, + 'paginate' => $this->CI->pagination->create_links() + ); + + $this->CI->load->view('view', $data); + } + + // -------------------------------------------------------------------- + + /** + * "Edit" Page + * + * Shows a form representing the currently selected DB + * so that data can be edited + * + * @access public + * @return string the HTML "edit" page + */ + function edit() + { + if (FALSE === ($id = $this->CI->uri->segment(4))) + { + return $this->view(); + } + + // Fetch the primary field name + $primary = $this->CI->db->primary($this->current_table); + + // Run the query + $query = $this->CI->db->getwhere($this->current_table, array($primary => $id)); + + $data = array( + 'title' => ( ! isset($this->lang['scaff_edit'])) ? 'Edit Data' : $this->lang['scaff_edit'], + 'fields' => $query->field_data(), + 'query' => $query->row(), + 'action' => $this->base_uri.'/update/'.$this->CI->uri->segment(4) + ); + + $this->CI->load->view('edit', $data); + } + + // -------------------------------------------------------------------- + + /** + * Update + * + * @access public + * @return void redirects to the view page + */ + function update() + { + // Fetch the primary key + $primary = $this->CI->db->primary($this->current_table); + + // Now do the query + $this->CI->db->update($this->current_table, $_POST, array($primary => $this->CI->uri->segment(4))); + + redirect($this->base_uri.'/view/'); + } + + // -------------------------------------------------------------------- + + /** + * Delete Confirmation + * + * @access public + * @return string the HTML "delete confirm" page + */ + function delete() + { + if ( ! isset($this->lang['scaff_del_confirm'])) + { + $message = 'Are you sure you want to delete the following row: '.$this->CI->uri->segment(4); + } + else + { + $message = $this->lang['scaff_del_confirm'].' '.$this->CI->uri->segment(4); + } + + $data = array( + 'title' => ( ! isset($this->lang['scaff_delete'])) ? 'Delete Data' : $this->lang['scaff_delete'], + 'message' => $message, + 'no' => anchor(array($this->base_uri, 'view'), ( ! isset($this->lang['scaff_no'])) ? 'No' : $this->lang['scaff_no']), + 'yes' => anchor(array($this->base_uri, 'do_delete', $this->CI->uri->segment(4)), ( ! isset($this->lang['scaff_yes'])) ? 'Yes' : $this->lang['scaff_yes']) + ); + + $this->CI->load->view('delete', $data); + } + + // -------------------------------------------------------------------- + + /** + * Delete + * + * @access public + * @return void redirects to the view page + */ + function do_delete() + { + // Fetch the primary key + $primary = $this->CI->db->primary($this->current_table); + + // Now do the query + $this->CI->db->where($primary, $this->CI->uri->segment(4)); + $this->CI->db->delete($this->current_table); + + header("Refresh:0;url=".site_url(array($this->base_uri, 'view'))); + exit; + } + +} ?> \ No newline at end of file diff --git a/system/scaffolding/views/footer.php b/system/scaffolding/views/footer.php index 36b29d1cd..60b0a53e2 100644 --- a/system/scaffolding/views/footer.php +++ b/system/scaffolding/views/footer.php @@ -1,10 +1,10 @@ - - - - - - + + + + + + \ No newline at end of file -- cgit v1.2.3-24-g4f1b From 99c69e90f715541e8c1712b5be385af66ac69aa4 Mon Sep 17 00:00:00 2001 From: Derek Allard Date: Sun, 15 Apr 2007 17:56:51 +0000 Subject: update app_ver --- system/codeigniter/CodeIgniter.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system') diff --git a/system/codeigniter/CodeIgniter.php b/system/codeigniter/CodeIgniter.php index aed05ddc2..0c21086a3 100644 --- a/system/codeigniter/CodeIgniter.php +++ b/system/codeigniter/CodeIgniter.php @@ -28,7 +28,7 @@ */ // CI Version -define('APPVER', '1.5.2'); +define('APPVER', '1.5.3'); /* * ------------------------------------------------------ -- cgit v1.2.3-24-g4f1b From 445b24d4b377013eb3946383409b7668cd54e060 Mon Sep 17 00:00:00 2001 From: Derek Allard Date: Tue, 24 Apr 2007 12:48:19 +0000 Subject: fixed router but that was ignoring the scaffolding route for optimization --- system/libraries/Router.php | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'system') diff --git a/system/libraries/Router.php b/system/libraries/Router.php index 64becf535..e44d9a4db 100644 --- a/system/libraries/Router.php +++ b/system/libraries/Router.php @@ -428,12 +428,13 @@ class CI_Router { function _parse_routes() { // Do we even have any custom routing to deal with? - if (count($this->routes) == 0) + // There is a default scaffolding trigger, so we'll look just for 1 + if (count($this->routes) == 1) { $this->_compile_segments($this->segments); return; } - + // Turn the segment array into a URI string $uri = implode('/', $this->segments); $num = count($this->segments); -- cgit v1.2.3-24-g4f1b From fbcc8e421ed5ae9c76b17923d5ea1e3f813b408f Mon Sep 17 00:00:00 2001 From: Derek Allard Date: Wed, 25 Apr 2007 15:26:50 +0000 Subject: APPVER replaced by CI_VERSION --- system/codeigniter/CodeIgniter.php | 2 +- system/scaffolding/views/footer.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'system') diff --git a/system/codeigniter/CodeIgniter.php b/system/codeigniter/CodeIgniter.php index 0c21086a3..987478f9f 100644 --- a/system/codeigniter/CodeIgniter.php +++ b/system/codeigniter/CodeIgniter.php @@ -28,7 +28,7 @@ */ // CI Version -define('APPVER', '1.5.3'); +define('CI_VERSION', '1.5.3'); /* * ------------------------------------------------------ diff --git a/system/scaffolding/views/footer.php b/system/scaffolding/views/footer.php index 60b0a53e2..d25365dd8 100644 --- a/system/scaffolding/views/footer.php +++ b/system/scaffolding/views/footer.php @@ -2,7 +2,7 @@ -- cgit v1.2.3-24-g4f1b From cea5dbe08c909c5efa54bbaa56980b2288bbd296 Mon Sep 17 00:00:00 2001 From: Derek Allard Date: Fri, 27 Apr 2007 03:33:21 +0000 Subject: fixed checked = 1 to be checked = checked in array created checkboxes --- system/helpers/form_helper.php | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'system') diff --git a/system/helpers/form_helper.php b/system/helpers/form_helper.php index adbddd5ad..531ab66c0 100644 --- a/system/helpers/form_helper.php +++ b/system/helpers/form_helper.php @@ -260,7 +260,13 @@ function form_checkbox($data = '', $value = '', $checked = TRUE, $extra = '') $checked = $data['checked']; if ($checked == FALSE) + { unset($data['checked']); + } + else + { + $data['checked'] = 'checked'; + } } if ($checked == TRUE) -- cgit v1.2.3-24-g4f1b From 44a736f74bd6a7852cba442e5ad4126068caf626 Mon Sep 17 00:00:00 2001 From: Derek Jones Date: Fri, 27 Apr 2007 17:03:10 +0000 Subject: modified _add_data() to be compatible with OS X (removed CRC and length from end of file stream) --- system/libraries/Zip.php | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) (limited to 'system') diff --git a/system/libraries/Zip.php b/system/libraries/Zip.php index 377c38741..518c97836 100644 --- a/system/libraries/Zip.php +++ b/system/libraries/Zip.php @@ -156,7 +156,7 @@ class CI_Zip { $crc32 = crc32($data); $gzdata = gzcompress($data); - $gzdata = substr(substr($gzdata, 0, strlen($gzdata) - 4), 2); + $gzdata = substr($gzdata, 2, -4); $newlen = strlen($gzdata); $this->zipdata[] = "\x50\x4b\x03\x04\x14\x00\x00\x00\x08\x00\x00\x00\x00\x00" @@ -166,10 +166,7 @@ class CI_Zip { .pack('v', strlen($filepath)) .pack('v', 0) .$filepath - .$gzdata - .pack('V', $crc32) - .pack('V', $newlen) - .pack('V', $oldlen); + .$gzdata; $newoffset = strlen(implode("", $this->zipdata)); -- cgit v1.2.3-24-g4f1b From a1b05a1c6505fe2afce28c0268a51582c655a190 Mon Sep 17 00:00:00 2001 From: Rick Ellis Date: Fri, 27 Apr 2007 21:20:38 +0000 Subject: --- system/libraries/Validation.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system') diff --git a/system/libraries/Validation.php b/system/libraries/Validation.php index 7ad8509a3..c28713c1b 100644 --- a/system/libraries/Validation.php +++ b/system/libraries/Validation.php @@ -194,7 +194,7 @@ class CI_Validation { //Explode out the rules! $ex = explode('|', $rules); - // Is the field required? If not, if the field is blank we'll move on to the next text + // Is the field required? If not, if the field is blank we'll move on to the next test if ( ! in_array('required', $ex, TRUE) AND strpos($rules, 'callback_') === FALSE) { if ( ! isset($_POST[$field]) OR $_POST[$field] == '') -- cgit v1.2.3-24-g4f1b From 74c46a16d1ae6b52eb53c46eee305bc1b19ccb26 Mon Sep 17 00:00:00 2001 From: Derek Allard Date: Mon, 30 Apr 2007 01:39:39 +0000 Subject: fixed a typo in rpcs.php library --- system/libraries/Xmlrpcs.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system') diff --git a/system/libraries/Xmlrpcs.php b/system/libraries/Xmlrpcs.php index fe55e36d6..018530216 100644 --- a/system/libraries/Xmlrpcs.php +++ b/system/libraries/Xmlrpcs.php @@ -191,7 +191,7 @@ class CI_Xmlrpcs extends CI_Xmlrpc { return new XML_RPC_Response(0, $this->xmlrpcerr['invalid_return'], - $this->xmlrpcstr['invalid_retrun']); + $this->xmlrpcstr['invalid_return']); } else { -- cgit v1.2.3-24-g4f1b From e6c4f7b7bcf96117bdcbd885b3ea4a4f1a7b570d Mon Sep 17 00:00:00 2001 From: Derek Allard Date: Mon, 30 Apr 2007 11:54:45 +0000 Subject: fixed bug in output --- system/libraries/Profiler.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system') diff --git a/system/libraries/Profiler.php b/system/libraries/Profiler.php index cdc4f6fc9..ffd664a88 100644 --- a/system/libraries/Profiler.php +++ b/system/libraries/Profiler.php @@ -166,7 +166,7 @@ class CI_Profiler { } // $output .= "$_POST[".$key."]  ".htmlspecialchars(stripslashes($val))."\n"; - $output .= "$_POST[".$key."] "; + $output .= "".$_POST[$key]." "; if (is_array($val)) { $output .= "
    " . htmlspecialchars(stripslashes(print_r($val, true))) . "
    "; -- cgit v1.2.3-24-g4f1b From 24d954454a9fa3c4f5d54a7388f930b912ec308a Mon Sep 17 00:00:00 2001 From: Derek Allard Date: Mon, 30 Apr 2007 12:21:37 +0000 Subject: added a note about regex and custom routes --- system/application/config/routes.php | 97 ++++++++++++++++++------------------ 1 file changed, 49 insertions(+), 48 deletions(-) (limited to 'system') diff --git a/system/application/config/routes.php b/system/application/config/routes.php index 1702e4f4b..8a09dec39 100644 --- a/system/application/config/routes.php +++ b/system/application/config/routes.php @@ -1,49 +1,50 @@ - \ No newline at end of file -- cgit v1.2.3-24-g4f1b From 971af995fb3ba4268dd4ba434254d35001013b5b Mon Sep 17 00:00:00 2001 From: Derek Allard Date: Tue, 1 May 2007 20:21:28 +0000 Subject: fixed a bug in the calendar library --- system/libraries/Calendar.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system') diff --git a/system/libraries/Calendar.php b/system/libraries/Calendar.php index ef6a3f841..5fec40e1c 100644 --- a/system/libraries/Calendar.php +++ b/system/libraries/Calendar.php @@ -270,7 +270,7 @@ class CI_Calendar { } 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_names = array('01' => 'cal_january', '02' => 'cal_february', '03' => 'cal_march', '04' => 'cal_april', '05' => 'cal_may', '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]; -- cgit v1.2.3-24-g4f1b From 31d363b39fe8ec09e1af3b4441f9bd5844bf8224 Mon Sep 17 00:00:00 2001 From: Derek Allard Date: Wed, 2 May 2007 01:18:58 +0000 Subject: // Prep the current page - no funny business! $this->cur_page = preg_replace("/[a-z\-]/", "", $this->cur_page); became // Prep the current page - no funny business! $this->cur_page = (int) $this->cur_page; --- system/libraries/Pagination.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system') diff --git a/system/libraries/Pagination.php b/system/libraries/Pagination.php index 27104c95c..8ea0dab19 100644 --- a/system/libraries/Pagination.php +++ b/system/libraries/Pagination.php @@ -122,7 +122,7 @@ class CI_Pagination { $this->cur_page = $CI->uri->segment($this->uri_segment); // Prep the current page - no funny business! - $this->cur_page = preg_replace("/[a-z\-]/", "", $this->cur_page); + $this->cur_page = (int) $this->cur_page; } if ( ! is_numeric($this->cur_page)) -- cgit v1.2.3-24-g4f1b From bbc5ec2a660c960873f7c41437859fa1d82703d6 Mon Sep 17 00:00:00 2001 From: Derek Allard Date: Wed, 2 May 2007 11:34:08 +0000 Subject: $this->base_url = preg_replace("/(.+?)\/*$/", "\\1/", $this->base_url); changed to $this->base_url = rtrim($this->base_url, '/') .'/'; --- system/libraries/Pagination.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'system') diff --git a/system/libraries/Pagination.php b/system/libraries/Pagination.php index 8ea0dab19..c5c718dee 100644 --- a/system/libraries/Pagination.php +++ b/system/libraries/Pagination.php @@ -146,8 +146,8 @@ class CI_Pagination { $end = (($this->cur_page + $this->num_links) < $num_pages) ? $this->cur_page + $this->num_links : $num_pages; // Add a trailing slash to the base URL if needed - $this->base_url = preg_replace("/(.+?)\/*$/", "\\1/", $this->base_url); - + $this->base_url = rtrim($this->base_url, '/') .'/'; + // And here we go... $output = ''; -- cgit v1.2.3-24-g4f1b From 2c25fd0fb075090257e69440c94ef6fddd6f02f2 Mon Sep 17 00:00:00 2001 From: Derek Allard Date: Wed, 2 May 2007 11:39:23 +0000 Subject: return preg_replace("|^/*(.+?)/*$|", "\\1", $str); to return trim($str, '/'); --- system/helpers/string_helper.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'system') diff --git a/system/helpers/string_helper.php b/system/helpers/string_helper.php index 04c3a592a..011be2333 100644 --- a/system/helpers/string_helper.php +++ b/system/helpers/string_helper.php @@ -44,8 +44,8 @@ */ function trim_slashes($str) { - return preg_replace("|^/*(.+?)/*$|", "\\1", $str); -} + return trim($str, '/'); +} // ------------------------------------------------------------------------ -- cgit v1.2.3-24-g4f1b From 01f72ca6c27d99938cd1f814f812c5b844d51b83 Mon Sep 17 00:00:00 2001 From: Derek Jones Date: Fri, 4 May 2007 18:19:17 +0000 Subject: Modified XSS Cleaning routine to be more performance friendly and compatible with PHP 5.2's new PCRE backtrack and recursion limits. - replaced link and image tag javascript sanitization preg_replace()'s with callback functions to avoid excessive backtracks on strings with many links / image tags. --- system/libraries/Input.php | 55 +++++++++++++++++++++++++++++++++++++++------- 1 file changed, 47 insertions(+), 8 deletions(-) (limited to 'system') diff --git a/system/libraries/Input.php b/system/libraries/Input.php index 64c0ed418..63a6833d6 100644 --- a/system/libraries/Input.php +++ b/system/libraries/Input.php @@ -499,8 +499,10 @@ class CI_Input { * Note: Normally urldecode() would be easier but it removes plus signs * */ + $str = preg_replace("/(%20)+/", '9u3iovBnRThju941s89rKozm', $str); $str = preg_replace("/%u0([a-z0-9]{3})/i", "&#x\\1;", $str); - $str = preg_replace("/%([a-z0-9]{2})/i", "&#x\\1;", $str); + $str = preg_replace("/%([a-z0-9]{2})/i", "&#x\\1;", $str); + $str = str_replace('9u3iovBnRThju941s89rKozm', "%20", $str); /* * Convert character entities to ASCII @@ -575,17 +577,17 @@ class CI_Input { $temp .= substr($word, $i, 1)."\s*"; } - $temp = substr($temp, 0, -3); - $str = preg_replace('#'.$temp.'#s', $word, $str); - $str = preg_replace('#'.ucfirst($temp).'#s', ucfirst($word), $str); + // 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('#('.substr($temp, 0, -3).')(\W)#ise', "preg_replace('/\s+/s', '', '\\1').'\\2'", $str); } /* * Remove disallowed Javascript in links or img tags */ - $str = preg_replace("#.*?#si", "", $str); - $str = preg_replace("##si", "", $str); - $str = preg_replace("#<(script|xss).*?\>#si", "", $str); + $str = preg_replace_callback("##si", array($this, '_js_link_removal'), $str); + $str = preg_replace_callback("##si", array($this, '_js_img_removal'), $str); + $str = preg_replace("#<(script|xss).*?\>#si", "", $str); /* * Remove JavaScript Event Handlers @@ -595,7 +597,8 @@ class CI_Input { * but it's unlikely to be a problem. * */ - $str = preg_replace('#(<[^>]+.*?)(onblur|onchange|onclick|onfocus|onload|onmouseover|onmouseup|onmousedown|onselect|onsubmit|onunload|onkeypress|onkeydown|onkeyup|onresize)[^>]*>#iU',"\\1>",$str); + $event_handlers = array('onblur','onchange','onclick','onfocus','onload','onmouseover','onmouseup','onmousedown','onselect','onsubmit','onunload','onkeypress','onkeydown','onkeyup','onresize', 'xmlns'); + $str = preg_replace("#<([^>]+)(".implode('|', $event_handlers).")([^>]*)>#iU", "<\\1\\2\\3>", $str); /* * Sanitize naughty HTML elements @@ -652,7 +655,43 @@ class CI_Input { } // -------------------------------------------------------------------- + + /** + * 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 + * + * @access private + * @param array + * @return string + */ + function _js_link_removal($match) + { + return preg_replace("#.*?#si", "", $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 + * + * @access private + * @param array + * @return string + */ + function _js_img_removal($match) + { + return preg_replace("##si", "", $match[0]); + } + // -------------------------------------------------------------------- + /** * HTML Entities Decode * -- cgit v1.2.3-24-g4f1b From 3d378b1fc634f5def5399bee35f11752a5929e1c Mon Sep 17 00:00:00 2001 From: Derek Allard Date: Tue, 8 May 2007 23:03:59 +0000 Subject: typo fixes --- system/application/config/autoload.php | 186 ++++++++++++++++----------------- system/application/config/config.php | 3 +- system/application/config/routes.php | 4 - 3 files changed, 94 insertions(+), 99 deletions(-) (limited to 'system') diff --git a/system/application/config/autoload.php b/system/application/config/autoload.php index 06d8780c4..26e71f74c 100644 --- a/system/application/config/autoload.php +++ b/system/application/config/autoload.php @@ -1,94 +1,94 @@ - \ No newline at end of file diff --git a/system/application/config/config.php b/system/application/config/config.php index 3bb9d1d23..941d9c303 100644 --- a/system/application/config/config.php +++ b/system/application/config/config.php @@ -152,8 +152,7 @@ $config['function_trigger'] = 'm'; | You can enable error logging by setting a threshold over zero. The | threshold determines what gets logged. Threshold options are: | -| 0 = Disables logging -| 0 = Error logging TURNED OFF +| 0 = Disables logging, Error logging TURNED OFF | 1 = Error Messages (including PHP errors) | 2 = Debug Messages | 3 = Informational Messages diff --git a/system/application/config/routes.php b/system/application/config/routes.php index 8a09dec39..be09f5aa2 100644 --- a/system/application/config/routes.php +++ b/system/application/config/routes.php @@ -43,8 +43,4 @@ $route['default_controller'] = "welcome"; $route['scaffolding_trigger'] = ""; - - - - ?> \ No newline at end of file -- cgit v1.2.3-24-g4f1b From d885680948438cf59ad3d67820fb3ac2c6f7a8c6 Mon Sep 17 00:00:00 2001 From: Derek Allard Date: Thu, 24 May 2007 03:49:37 +0000 Subject: typo fix --- system/libraries/Output.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system') diff --git a/system/libraries/Output.php b/system/libraries/Output.php index 743228e53..756d4b4cc 100644 --- a/system/libraries/Output.php +++ b/system/libraries/Output.php @@ -275,7 +275,7 @@ class CI_Output { if ( ! $fp = @fopen($cache_path, 'wb')) { - log_message('error', "Unable to write ache file: ".$cache_path); + log_message('error', "Unable to write cache file: ".$cache_path); return; } -- cgit v1.2.3-24-g4f1b From bb2041dc4e5a121de9321fbf87846b7358d59d39 Mon Sep 17 00:00:00 2001 From: Rick Ellis Date: Sat, 9 Jun 2007 00:16:13 +0000 Subject: --- system/database/drivers/mysql/mysql_driver.php | 5 ----- system/database/drivers/mysqli/mysqli_driver.php | 5 ----- system/libraries/Input.php | 17 ++++++++++------- 3 files changed, 10 insertions(+), 17 deletions(-) (limited to 'system') diff --git a/system/database/drivers/mysql/mysql_driver.php b/system/database/drivers/mysql/mysql_driver.php index 367c2d11f..50f4ecfbf 100644 --- a/system/database/drivers/mysql/mysql_driver.php +++ b/system/database/drivers/mysql/mysql_driver.php @@ -222,11 +222,6 @@ class CI_DB_mysql_driver extends CI_DB { */ function escape_str($str) { - if (get_magic_quotes_gpc()) - { - return $str; - } - if (function_exists('mysql_real_escape_string')) { return mysql_real_escape_string($str, $this->conn_id); diff --git a/system/database/drivers/mysqli/mysqli_driver.php b/system/database/drivers/mysqli/mysqli_driver.php index 98e7f6c76..9cfc68ea6 100644 --- a/system/database/drivers/mysqli/mysqli_driver.php +++ b/system/database/drivers/mysqli/mysqli_driver.php @@ -225,11 +225,6 @@ class CI_DB_mysqli_driver extends CI_DB { */ function escape_str($str) { - if (get_magic_quotes_gpc()) - { - return $str; - } - return mysqli_real_escape_string($this->conn_id, $str); } diff --git a/system/libraries/Input.php b/system/libraries/Input.php index 63a6833d6..f113cff71 100644 --- a/system/libraries/Input.php +++ b/system/libraries/Input.php @@ -68,7 +68,8 @@ class CI_Input { */ function _sanitize_globals() { - // Unset globals. This is effectively the same as register_globals = off + // Unset globals for securiy. + // This is effectively the same as register_globals = off foreach (array($_GET, $_POST, $_COOKIE) as $global) { if ( ! is_array($global)) @@ -147,6 +148,13 @@ class CI_Input { return $new_array; } + // We strip slashes if magic quotes is on to keep things consistent + if (get_magic_quotes_gpc()) + { + $str = stripslashes($str); + } + + // Should we filter the input data? if ($this->use_xss_clean === TRUE) { $str = $this->xss_clean($str); @@ -175,12 +183,7 @@ class CI_Input { { exit('Disallowed Key Characters.'); } - - if ( ! get_magic_quotes_gpc()) - { - return addslashes($str); - } - + return $str; } -- cgit v1.2.3-24-g4f1b From 8c501b3ba6d1aa0c18e749550f0ee3435a9272d6 Mon Sep 17 00:00:00 2001 From: Rick Ellis Date: Sat, 9 Jun 2007 01:13:36 +0000 Subject: --- system/libraries/Loader.php | 33 +++++++++++++++++++++++---------- 1 file changed, 23 insertions(+), 10 deletions(-) (limited to 'system') diff --git a/system/libraries/Loader.php b/system/libraries/Loader.php index ff5ffbfe4..abe3a1c37 100644 --- a/system/libraries/Loader.php +++ b/system/libraries/Loader.php @@ -681,17 +681,30 @@ class CI_Loader { // We'll test for both lowercase and capitalized versions of the file name foreach (array(ucfirst($class), strtolower($class)) as $class) { - // Is this a class extension request? - if (file_exists(APPPATH.'libraries/'.config_item('subclass_prefix').$class.EXT)) + $subclass = APPPATH.'libraries/'.config_item('subclass_prefix').$class.EXT; + + // Is this a class extension request? + if (file_exists($subclass)) { - if ( ! file_exists(BASEPATH.'libraries/'.ucfirst($class).EXT)) + $baseclass = BASEPATH.'libraries/'.ucfirst($class).EXT; + + 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_classes)) + { + $is_duplicate = TRUE; + log_message('debug', $class." class already loaded. Second attempt ignored."); + return; + } - include(BASEPATH.'libraries/'.ucfirst($class).EXT); - include(APPPATH.'libraries/'.config_item('subclass_prefix').$class.EXT); + include($baseclass); + include($subclass); + $this->_ci_classes[] = $subclass; return $this->_ci_init_class($class, config_item('subclass_prefix'), $params); } @@ -701,24 +714,24 @@ class CI_Loader { for ($i = 1; $i < 3; $i++) { $path = ($i % 2) ? APPPATH : BASEPATH; - $fp = $path.'libraries/'.$class.EXT; + $filepath = $path.'libraries/'.$class.EXT; // Does the file exist? No? Bummer... - if ( ! file_exists($fp)) + if ( ! file_exists($filepath)) { continue; } // Safety: Was the class already loaded by a previous call? - if (in_array($fp, $this->_ci_classes)) + if (in_array($filepath, $this->_ci_classes)) { $is_duplicate = TRUE; log_message('debug', $class." class already loaded. Second attempt ignored."); return; } - include($fp); - $this->_ci_classes[] = $fp; + include($filepath); + $this->_ci_classes[] = $filepath; return $this->_ci_init_class($class, '', $params); } } // END FOREACH -- cgit v1.2.3-24-g4f1b From f660315a3cea96279a755ece825aabb9dcfd5a1d Mon Sep 17 00:00:00 2001 From: Rick Ellis Date: Sat, 9 Jun 2007 01:16:00 +0000 Subject: --- system/libraries/Router.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system') diff --git a/system/libraries/Router.php b/system/libraries/Router.php index e44d9a4db..6c3062c07 100644 --- a/system/libraries/Router.php +++ b/system/libraries/Router.php @@ -303,7 +303,7 @@ class CI_Router { // 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'); + $path = (isset($_SERVER['PATH_INFO'])) ? $_SERVER['PATH_INFO'] : @getenv('PATH_INFO'); if ($path != '' AND $path != "/".SELF) { return $path; -- cgit v1.2.3-24-g4f1b From e6b4a80ed09aa9d171db6abf2af2bca3cbac4945 Mon Sep 17 00:00:00 2001 From: Rick Ellis Date: Mon, 11 Jun 2007 04:20:44 +0000 Subject: --- system/libraries/Upload.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system') diff --git a/system/libraries/Upload.php b/system/libraries/Upload.php index 564e29937..4cea9cd71 100644 --- a/system/libraries/Upload.php +++ b/system/libraries/Upload.php @@ -709,7 +709,7 @@ class CI_Upload { return FALSE; } - if ( ! $fp = @fopen($file, 'rb')) + if ( ! $fp = @fopen($file, 'r+b')) { return FALSE; } -- cgit v1.2.3-24-g4f1b From 28239ad0146eccecc9f2ca81764ca5605b3c50bf Mon Sep 17 00:00:00 2001 From: Rick Ellis Date: Mon, 11 Jun 2007 04:26:39 +0000 Subject: --- system/database/DB_driver.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'system') diff --git a/system/database/DB_driver.php b/system/database/DB_driver.php index 7ff33246a..8f238fc52 100644 --- a/system/database/DB_driver.php +++ b/system/database/DB_driver.php @@ -48,7 +48,7 @@ class CI_DB_driver { var $data_cache = array(); var $trans_enabled = TRUE; var $_trans_depth = 0; - var $_trans_failure = FALSE; // Used with transactions to determine if a rollback should occur + var $_trans_status = TRUE; // Used with transactions to determine if a rollback should occur var $cache_on = FALSE; var $cachedir = ''; var $cache_autodel = FALSE; @@ -273,7 +273,7 @@ class CI_DB_driver { if (FALSE === ($this->result_id = $this->simple_query($sql))) { // This will trigger a rollback if transactions are being used - $this->_trans_failure = TRUE; + $this->_trans_status = FALSE; if ($this->db_debug) { @@ -463,7 +463,7 @@ class CI_DB_driver { } // The query() function will set this flag to TRUE in the event that a query failed - if ($this->_trans_failure === TRUE) + if ($this->_trans_status === FALSE) { $this->trans_rollback(); @@ -488,7 +488,7 @@ class CI_DB_driver { */ function trans_status() { - return $this->_trans_failure; + return $this->_trans_status; } // -------------------------------------------------------------------- -- cgit v1.2.3-24-g4f1b From 64bbd04d8a3c92e577254513504e9c9d617fe676 Mon Sep 17 00:00:00 2001 From: Rick Ellis Date: Mon, 11 Jun 2007 04:35:52 +0000 Subject: --- system/libraries/Upload.php | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) (limited to 'system') diff --git a/system/libraries/Upload.php b/system/libraries/Upload.php index 4cea9cd71..d8a8f69a7 100644 --- a/system/libraries/Upload.php +++ b/system/libraries/Upload.php @@ -708,19 +708,21 @@ class CI_Upload { { return FALSE; } - + + if ( ! $data = file_get_contents($file)) + { + return FALSE; + } + if ( ! $fp = @fopen($file, 'r+b')) { return FALSE; } - - flock($fp, LOCK_EX); - $data = fread($fp, filesize($file)); - $CI =& get_instance(); $data = $CI->input->xss_clean($data); - + + flock($fp, LOCK_EX); fwrite($fp, $data); flock($fp, LOCK_UN); fclose($fp); -- cgit v1.2.3-24-g4f1b From 8de97ffd0629a4fe1f7dfe97276935793591a179 Mon Sep 17 00:00:00 2001 From: Rick Ellis Date: Mon, 11 Jun 2007 04:38:47 +0000 Subject: --- system/libraries/Validation.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system') diff --git a/system/libraries/Validation.php b/system/libraries/Validation.php index c28713c1b..79ab76c6b 100644 --- a/system/libraries/Validation.php +++ b/system/libraries/Validation.php @@ -518,7 +518,7 @@ class CI_Validation { */ function alpha_numeric($str) { - return ( ! preg_match("/^([-a-z0-9])+$/i", $str)) ? FALSE : TRUE; + return ( ! preg_match("/^([a-z0-9])+$/i", $str)) ? FALSE : TRUE; } // -------------------------------------------------------------------- -- cgit v1.2.3-24-g4f1b From 63966df193cb275d957ffc64398f6fe941c00e31 Mon Sep 17 00:00:00 2001 From: Rick Ellis Date: Mon, 11 Jun 2007 04:44:11 +0000 Subject: --- system/libraries/Upload.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'system') diff --git a/system/libraries/Upload.php b/system/libraries/Upload.php index d8a8f69a7..dc3fd4a12 100644 --- a/system/libraries/Upload.php +++ b/system/libraries/Upload.php @@ -708,8 +708,8 @@ class CI_Upload { { return FALSE; } - - if ( ! $data = file_get_contents($file)) + + if (($data = @file_get_contents($file)) !== FALSE) { return FALSE; } -- cgit v1.2.3-24-g4f1b From 1adf1db17260090e2678f209ad429b0b186e3dbc Mon Sep 17 00:00:00 2001 From: Rick Ellis Date: Mon, 11 Jun 2007 04:46:57 +0000 Subject: --- system/libraries/Validation.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system') diff --git a/system/libraries/Validation.php b/system/libraries/Validation.php index 79ab76c6b..960053426 100644 --- a/system/libraries/Validation.php +++ b/system/libraries/Validation.php @@ -504,7 +504,7 @@ class CI_Validation { */ function alpha($str) { - return ( ! preg_match("/^([-a-z])+$/i", $str)) ? FALSE : TRUE; + return ( ! preg_match("/^([a-z])+$/i", $str)) ? FALSE : TRUE; } // -------------------------------------------------------------------- -- cgit v1.2.3-24-g4f1b From 8d127c78fe0a1d6034cb503529dc548b566156c8 Mon Sep 17 00:00:00 2001 From: Rick Ellis Date: Mon, 11 Jun 2007 04:47:58 +0000 Subject: --- system/libraries/Email.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system') diff --git a/system/libraries/Email.php b/system/libraries/Email.php index a8acec674..7b7dc091c 100644 --- a/system/libraries/Email.php +++ b/system/libraries/Email.php @@ -484,7 +484,7 @@ class CI_Email { */ function set_newline($newline = "\n") { - if ($newline != "\n" OR $newline != "\r\n" OR $newline != "\r") + if ($newline != "\n" AND $newline != "\r\n" AND $newline != "\r") { $this->newline = "\n"; return; -- cgit v1.2.3-24-g4f1b From e666afc7eaf8c8224c4e6cf6f7e415966f22783e Mon Sep 17 00:00:00 2001 From: Rick Ellis Date: Mon, 11 Jun 2007 05:03:11 +0000 Subject: --- system/libraries/Input.php | 36 +++++++++++++++++------------------- 1 file changed, 17 insertions(+), 19 deletions(-) (limited to 'system') diff --git a/system/libraries/Input.php b/system/libraries/Input.php index f113cff71..e493f6d33 100644 --- a/system/libraries/Input.php +++ b/system/libraries/Input.php @@ -379,36 +379,34 @@ class CI_Input { /** * Validate IP Address * + * Updated version suggested by Geert De Deckere + * * @access public * @param string * @return string */ function valid_ip($ip) { - if ( ! preg_match( "/^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$/", $ip)) + $ip_segments = explode('.', $ip); + + // Always 4 segments needed + if (count($ip_segments) != 4) { return FALSE; } - - $octets = explode('.', $ip); - - for ($i = 1; $i <= 4; $i++) + // IP cannot start with 0 + if (substr($ip_segments[0], 0, 1) == 0) { - $octet = intval($octets[($i-1)]); - if ($i === 1) - { - if ($octet > 223 OR $octet < 1) - return FALSE; - } - elseif ($i === 4) - { - if ($octet < 1) - return FALSE; - } - else + 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 ( ! ctype_digit($segment) OR $segment > 255 OR strlen($segment) > 3) { - if ($octet > 254) - return FALSE; + return FALSE; } } -- cgit v1.2.3-24-g4f1b From a405117ece2113aa58dff481834abc6fe103a546 Mon Sep 17 00:00:00 2001 From: Rick Ellis Date: Mon, 11 Jun 2007 05:08:11 +0000 Subject: --- system/libraries/Validation.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system') diff --git a/system/libraries/Validation.php b/system/libraries/Validation.php index 960053426..896cd39d7 100644 --- a/system/libraries/Validation.php +++ b/system/libraries/Validation.php @@ -490,7 +490,7 @@ class CI_Validation { */ function valid_ip($ip) { - return ( ! preg_match( "/^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$/", $ip)) ? FALSE : TRUE; + return $this->CI->valid_ip($ip); } // -------------------------------------------------------------------- -- cgit v1.2.3-24-g4f1b From 1db17b57686911fea83103509c1438cbe1e545da Mon Sep 17 00:00:00 2001 From: Rick Ellis Date: Mon, 11 Jun 2007 05:33:21 +0000 Subject: --- system/database/drivers/mssql/mssql_driver.php | 50 ++++++++++++++++++++++---- 1 file changed, 43 insertions(+), 7 deletions(-) (limited to 'system') diff --git a/system/database/drivers/mssql/mssql_driver.php b/system/database/drivers/mssql/mssql_driver.php index ef66e3f3a..aef8da926 100644 --- a/system/database/drivers/mssql/mssql_driver.php +++ b/system/database/drivers/mssql/mssql_driver.php @@ -222,15 +222,51 @@ class CI_DB_mssql_driver extends CI_DB { // -------------------------------------------------------------------- /** - * Insert ID - * - * @access public - * @return integer - */ + * Insert ID + * + * Returns the last id created in the Identity column. + * + * @access public + * @return integer + */ function insert_id() { - // Not supported in MS SQL? - return 0; + $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"; } // -------------------------------------------------------------------- -- cgit v1.2.3-24-g4f1b From ba648939ddc1ed86e36fa7cdf20d3d05401e4ffe Mon Sep 17 00:00:00 2001 From: Rick Ellis Date: Tue, 12 Jun 2007 03:39:38 +0000 Subject: --- system/libraries/Input.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system') diff --git a/system/libraries/Input.php b/system/libraries/Input.php index e493f6d33..7b0282418 100644 --- a/system/libraries/Input.php +++ b/system/libraries/Input.php @@ -404,7 +404,7 @@ class CI_Input { { // IP segments must be digits and can not be // longer than 3 digits or greater then 255 - if ( ! ctype_digit($segment) OR $segment > 255 OR strlen($segment) > 3) + if (preg_match("/[^0-9]/", $segment) OR $segment > 255 OR strlen($segment) > 3) { return FALSE; } -- cgit v1.2.3-24-g4f1b From 3921314954fb851cf2b0980cabc750e0481d0de5 Mon Sep 17 00:00:00 2001 From: Rick Ellis Date: Tue, 12 Jun 2007 03:53:12 +0000 Subject: --- system/libraries/Input.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system') diff --git a/system/libraries/Input.php b/system/libraries/Input.php index 7b0282418..102e3b5eb 100644 --- a/system/libraries/Input.php +++ b/system/libraries/Input.php @@ -395,7 +395,7 @@ class CI_Input { return FALSE; } // IP cannot start with 0 - if (substr($ip_segments[0], 0, 1) == 0) + if (substr($ip_segments[0], 0, 1) == '0') { return FALSE; } -- cgit v1.2.3-24-g4f1b From 65e8f0e0833dac10362775b9edf3cffae126abb8 Mon Sep 17 00:00:00 2001 From: Rick Ellis Date: Tue, 12 Jun 2007 03:53:21 +0000 Subject: --- system/libraries/Input.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system') diff --git a/system/libraries/Input.php b/system/libraries/Input.php index 102e3b5eb..1ff72877b 100644 --- a/system/libraries/Input.php +++ b/system/libraries/Input.php @@ -394,7 +394,7 @@ class CI_Input { { return FALSE; } - // IP cannot start with 0 + // IP can not start with 0 if (substr($ip_segments[0], 0, 1) == '0') { return FALSE; -- cgit v1.2.3-24-g4f1b From da3fc9415ca42a5ca7fe80a4fe9e1a07029d8438 Mon Sep 17 00:00:00 2001 From: Rick Ellis Date: Wed, 13 Jun 2007 21:53:34 +0000 Subject: --- system/application/config/mimes.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system') diff --git a/system/application/config/mimes.php b/system/application/config/mimes.php index 12b9de750..ff87c57d2 100644 --- a/system/application/config/mimes.php +++ b/system/application/config/mimes.php @@ -10,7 +10,7 @@ $mimes = array( 'hqx' => 'application/mac-binhex40', 'cpt' => 'application/mac-compactpro', - 'csv' => array('text/x-comma-separated-values', 'application/vnd.ms-excel'), + 'csv' => array('text/x-comma-separated-values', 'text/comma-separated-values', 'application/octet-stream', 'application/vnd.ms-excel'), 'bin' => 'application/macbinary', 'dms' => 'application/octet-stream', 'lha' => 'application/octet-stream', -- cgit v1.2.3-24-g4f1b From 001e25623f7dc53e38999adce07188088ac6e032 Mon Sep 17 00:00:00 2001 From: Rick Ellis Date: Wed, 13 Jun 2007 22:01:30 +0000 Subject: --- system/libraries/Validation.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'system') diff --git a/system/libraries/Validation.php b/system/libraries/Validation.php index 896cd39d7..6b6ec0c68 100644 --- a/system/libraries/Validation.php +++ b/system/libraries/Validation.php @@ -419,7 +419,7 @@ class CI_Validation { */ function min_length($str, $val) { - if ( ! is_numeric($val)) + if (preg_match("/[^0-9]/", $val)) { return FALSE; } @@ -438,7 +438,7 @@ class CI_Validation { */ function max_length($str, $val) { - if ( ! is_numeric($val)) + if (preg_match("/[^0-9]/", $val)) { return FALSE; } @@ -457,7 +457,7 @@ class CI_Validation { */ function exact_length($str, $val) { - if ( ! is_numeric($val)) + if (preg_match("/[^0-9]/", $val)) { return FALSE; } -- cgit v1.2.3-24-g4f1b From 83ec240297a25342748846df84ad3c5ecb7cd623 Mon Sep 17 00:00:00 2001 From: Derek Allard Date: Mon, 18 Jun 2007 00:14:44 +0000 Subject: typo in comments --- system/libraries/Encrypt.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system') diff --git a/system/libraries/Encrypt.php b/system/libraries/Encrypt.php index 758c0f0a5..dc952dde3 100644 --- a/system/libraries/Encrypt.php +++ b/system/libraries/Encrypt.php @@ -318,7 +318,7 @@ class CI_Encrypt { // -------------------------------------------------------------------- /** - * Get Mcrypt MOde Value + * Get Mcrypt Mode Value * * @access private * @return string -- cgit v1.2.3-24-g4f1b From 3c5e373a2c95ba06b8d5b9820f53a72bea2f5681 Mon Sep 17 00:00:00 2001 From: paulburdick Date: Sun, 24 Jun 2007 20:27:42 +0000 Subject: Fixed the do_xss_clean() method so that if file_get_contents returns FALSE, then we return FALSE... Previously, if it did NOT return FALSE we returned FALSE and that is simply idiotic. --- system/libraries/Upload.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system') diff --git a/system/libraries/Upload.php b/system/libraries/Upload.php index dc3fd4a12..9d2bae2ae 100644 --- a/system/libraries/Upload.php +++ b/system/libraries/Upload.php @@ -709,7 +709,7 @@ class CI_Upload { return FALSE; } - if (($data = @file_get_contents($file)) !== FALSE) + if (($data = @file_get_contents($file)) === FALSE) { return FALSE; } -- cgit v1.2.3-24-g4f1b From 2f35c4b91526d2d813601401a3e6563255f2b639 Mon Sep 17 00:00:00 2001 From: paulburdick Date: Sun, 24 Jun 2007 20:29:09 +0000 Subject: Modified the is_image() method in the Upload library to take into account Windows IE 6/7 eccentricities when dealing with MIMEs --- system/libraries/Upload.php | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) (limited to 'system') diff --git a/system/libraries/Upload.php b/system/libraries/Upload.php index 9d2bae2ae..fa1cf1e73 100644 --- a/system/libraries/Upload.php +++ b/system/libraries/Upload.php @@ -477,17 +477,28 @@ class CI_Upload { */ function is_image() { + // IE will sometimes return odd mime-types during upload, so here we just standardize all + // jpegs or pngs to the same file type. + + $png_mimes = array('image/x-png'); + $jpeg_mimes = array('image/jpg', 'image/jpe', 'image/jpeg', 'image/pjpeg'); + + if (in_array($this->file_type, $png_mimes)) + { + $this->file_type = 'image/png'; + } + + if (in_array($this->file_type, $jpeg_mimes)) + { + $this->file_type = 'image/jpeg'; + } + $img_mimes = array( 'image/gif', - 'image/jpg', - 'image/jpe', 'image/jpeg', - 'image/pjpeg', 'image/png', - 'image/x-png' ); - return (in_array($this->file_type, $img_mimes, TRUE)) ? TRUE : FALSE; } -- cgit v1.2.3-24-g4f1b From 033ef02392d70dbc873deacc50ee76a800d0d228 Mon Sep 17 00:00:00 2001 From: paulburdick Date: Tue, 26 Jun 2007 21:52:52 +0000 Subject: *Updated the XSS Filtering to take into account the IE expression() ability --- system/libraries/Input.php | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'system') diff --git a/system/libraries/Input.php b/system/libraries/Input.php index 1ff72877b..dc4e605b8 100644 --- a/system/libraries/Input.php +++ b/system/libraries/Input.php @@ -528,9 +528,12 @@ class CI_Input { */ $bad = array( 'document.cookie' => '[removed]', + '.parentNode' => '[removed]', + '.innerHTML' => '[removed]', 'document.write' => '[removed]', 'window.location' => '[removed]', "javascript\s*:" => '[removed]', + "expression\s*\(" => '[removed]', // CSS and IE "Redirect\s+302" => '[removed]', '' => '-->' @@ -626,7 +629,7 @@ class CI_Input { * Becomes: eval('some code') * */ - $str = preg_replace('#(alert|cmd|passthru|eval|exec|system|fopen|fsockopen|file|file_get_contents|readfile|unlink)(\s*)\((.*?)\)#si', "\\1\\2(\\3)", $str); + $str = preg_replace('#(alert|cmd|passthru|eval|exec|expression|system|fopen|fsockopen|file|file_get_contents|readfile|unlink)(\s*)\((.*?)\)#si', "\\1\\2(\\3)", $str); /* * Final clean up @@ -637,9 +640,12 @@ class CI_Input { */ $bad = array( 'document.cookie' => '[removed]', + '.parentNode' => '[removed]', + '.innerHTML' => '[removed]', 'document.write' => '[removed]', 'window.location' => '[removed]', "javascript\s*:" => '[removed]', + "expression\s*\(" => '[removed]', // CSS and IE "Redirect\s+302" => '[removed]', '' => '-->' -- cgit v1.2.3-24-g4f1b From b614d392ccafd1decadbdc11afd7c0dcc4baec34 Mon Sep 17 00:00:00 2001 From: paulburdick Date: Tue, 26 Jun 2007 21:58:56 +0000 Subject: --- system/libraries/Input.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system') diff --git a/system/libraries/Input.php b/system/libraries/Input.php index dc4e605b8..51d4ed288 100644 --- a/system/libraries/Input.php +++ b/system/libraries/Input.php @@ -572,7 +572,7 @@ class CI_Input { * These words are compacted back to their correct state. * */ - $words = array('javascript', 'vbscript', 'script', 'applet', 'alert', 'document', 'write', 'cookie', 'window'); + $words = array('javascript', 'expression', 'vbscript', 'script', 'applet', 'alert', 'document', 'write', 'cookie', 'window'); foreach ($words as $word) { $temp = ''; -- cgit v1.2.3-24-g4f1b From 391eb03004deee85b9b0e978982950723b9742b5 Mon Sep 17 00:00:00 2001 From: paulburdick Date: Wed, 27 Jun 2007 22:58:24 +0000 Subject: Improved XSS clean to not allowing this: xss_clean("ss ipt a='>'>alert/**/('!');//*/>"); --- system/libraries/Input.php | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) (limited to 'system') diff --git a/system/libraries/Input.php b/system/libraries/Input.php index 51d4ed288..f9d23ae79 100644 --- a/system/libraries/Input.php +++ b/system/libraries/Input.php @@ -588,10 +588,18 @@ class CI_Input { /* * Remove disallowed Javascript in links or img tags - */ - $str = preg_replace_callback("##si", array($this, '_js_link_removal'), $str); - $str = preg_replace_callback("##si", array($this, '_js_img_removal'), $str); - $str = preg_replace("#<(script|xss).*?\>#si", "", $str); + */ + do + { + $original = $str; + + $str = preg_replace_callback("##si", array($this, '_js_link_removal'), $str); + $str = preg_replace_callback("##si", array($this, '_js_img_removal'), $str); + $str = preg_replace("##si", "", $str); + } + while($original != $str); + + unset($original); /* * Remove JavaScript Event Handlers -- cgit v1.2.3-24-g4f1b From 8816aaab7ac21d4e3ccd1eedd86462bc94aff2c1 Mon Sep 17 00:00:00 2001 From: paulburdick Date: Wed, 27 Jun 2007 23:07:36 +0000 Subject: --- system/libraries/Input.php | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) (limited to 'system') diff --git a/system/libraries/Input.php b/system/libraries/Input.php index f9d23ae79..9a73ab9b9 100644 --- a/system/libraries/Input.php +++ b/system/libraries/Input.php @@ -68,21 +68,30 @@ class CI_Input { */ function _sanitize_globals() { + // Would kind of be "wrong" to unset any of these GLOBALS. + $protected = array('_SERVER', '_GET', '_POST', '_FILES', '_REQUEST', '_SESSION', '_ENV', 'GLOBALS', 'HTTP_RAW_POST_DATA'); + // Unset globals for securiy. // This is effectively the same as register_globals = off foreach (array($_GET, $_POST, $_COOKIE) as $global) { if ( ! is_array($global)) { - global $global; - $$global = NULL; + if ( ! in_array($global, $protected)) + { + global $global; + $$global = NULL; + } } else { foreach ($global as $key => $val) { - global $$key; - $$key = NULL; + if ( ! in_array($key, $protected)) + { + global $$key; + $$key = NULL; + } } } } -- cgit v1.2.3-24-g4f1b From 3541313e896794514b7d44a5f0aab1e47b340ef7 Mon Sep 17 00:00:00 2001 From: paulburdick Date: Wed, 27 Jun 2007 23:25:19 +0000 Subject: *Modified the Router so that when Query Strings are Enabled, the controller trigger and function trigger values are sanitized for filename include security. --- system/libraries/Router.php | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'system') diff --git a/system/libraries/Router.php b/system/libraries/Router.php index 6c3062c07..e2a14800d 100644 --- a/system/libraries/Router.php +++ b/system/libraries/Router.php @@ -49,6 +49,7 @@ class CI_Router { function CI_Router() { $this->config =& load_class('Config'); + $this->input =& load_class('Input'); $this->_set_route_mapping(); log_message('debug', "Router Class Initialized"); } @@ -482,7 +483,7 @@ class CI_Router { */ function set_class($class) { - $this->class = $class; + $this->class = $this->input->filename_security($class); } // -------------------------------------------------------------------- @@ -509,7 +510,7 @@ class CI_Router { */ function set_method($method) { - $this->method = $method; + $this->method = $this->input->filename_security($method); } // -------------------------------------------------------------------- @@ -541,7 +542,7 @@ class CI_Router { */ function set_directory($dir) { - $this->directory = $dir.'/'; + $this->directory = $this->input->filename_security($dir).'/'; } // -------------------------------------------------------------------- -- cgit v1.2.3-24-g4f1b From 763064b8661f92953497d6ca094d687e9078903f Mon Sep 17 00:00:00 2001 From: paulburdick Date: Wed, 27 Jun 2007 23:25:55 +0000 Subject: *Added filename_security() method to Input library *Modified the Router so that when Query Strings are Enabled, the controller trigger and function trigger values are sanitized for filename include security. --- system/libraries/Input.php | 50 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) (limited to 'system') diff --git a/system/libraries/Input.php b/system/libraries/Input.php index 9a73ab9b9..337eeff30 100644 --- a/system/libraries/Input.php +++ b/system/libraries/Input.php @@ -444,6 +444,56 @@ class CI_Input { // -------------------------------------------------------------------- + /** + * Filename Security + * + * @access public + * @param string + * @return string + */ + function filename_security($str) + { + $bad = array( + "../", + "./", + "", + "<", + ">", + "'", + '"', + '&', + '$', + '#', + '{', + '}', + '[', + ']', + '=', + ';', + '?', + '/', + "%20", + "%22", + "%3c", // < + "%253c", // < + "%3e", // > + "%0e", // > + "%28", // ( + "%29", // ) + "%2528", // ( + "%26", // & + "%24", // $ + "%3f", // ? + "%3b", // ; + "%3d" // = + ); + + return stripslashes(str_replace($bad, '', $str)); + } + + // -------------------------------------------------------------------- + /** * XSS Clean * -- cgit v1.2.3-24-g4f1b From 8b1c3874d61d2c05f6368c9cad82aa533ad42b03 Mon Sep 17 00:00:00 2001 From: paulburdick Date: Wed, 27 Jun 2007 23:30:41 +0000 Subject: Modified the include so that there is a bit of filename security --- system/codeigniter/CodeIgniter.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system') diff --git a/system/codeigniter/CodeIgniter.php b/system/codeigniter/CodeIgniter.php index 987478f9f..8b067ff72 100644 --- a/system/codeigniter/CodeIgniter.php +++ b/system/codeigniter/CodeIgniter.php @@ -132,7 +132,7 @@ load_class('Controller', FALSE); // Load the local application controller // Note: The Router class automatically validates the controller path. If this include fails it // means that the default controller in the Routes.php file is not resolving to something valid. -if ( ! include(APPPATH.'controllers/'.$RTR->fetch_directory().$RTR->fetch_class().EXT)) +if ( ! include(APPPATH.'controllers/'.$IN->filename_security($RTR->fetch_directory()).$IN->filename_security($RTR->fetch_class()).EXT)) { show_error('Unable to load your default controller. Please make sure the controller specified in your Routes.php file is valid.'); } -- cgit v1.2.3-24-g4f1b From 01f0888f7d574b92104f8aedf77ab5426d753fd3 Mon Sep 17 00:00:00 2001 From: paulburdick Date: Wed, 27 Jun 2007 23:47:39 +0000 Subject: --- system/codeigniter/CodeIgniter.php | 2 +- system/libraries/Input.php | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) (limited to 'system') diff --git a/system/codeigniter/CodeIgniter.php b/system/codeigniter/CodeIgniter.php index 8b067ff72..987478f9f 100644 --- a/system/codeigniter/CodeIgniter.php +++ b/system/codeigniter/CodeIgniter.php @@ -132,7 +132,7 @@ load_class('Controller', FALSE); // Load the local application controller // Note: The Router class automatically validates the controller path. If this include fails it // means that the default controller in the Routes.php file is not resolving to something valid. -if ( ! include(APPPATH.'controllers/'.$IN->filename_security($RTR->fetch_directory()).$IN->filename_security($RTR->fetch_class()).EXT)) +if ( ! include(APPPATH.'controllers/'.$RTR->fetch_directory().$RTR->fetch_class().EXT)) { show_error('Unable to load your default controller. Please make sure the controller specified in your Routes.php file is valid.'); } diff --git a/system/libraries/Input.php b/system/libraries/Input.php index 337eeff30..33f288688 100644 --- a/system/libraries/Input.php +++ b/system/libraries/Input.php @@ -472,7 +472,6 @@ class CI_Input { '=', ';', '?', - '/', "%20", "%22", "%3c", // < -- cgit v1.2.3-24-g4f1b From 691010e72ec7fb4a05740332a10b5f046a82c666 Mon Sep 17 00:00:00 2001 From: paulburdick Date: Thu, 28 Jun 2007 00:02:30 +0000 Subject: Instead of doing file name security for Enable Query Strings, I am using the already existin _filter_uri() --- system/libraries/Router.php | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) (limited to 'system') diff --git a/system/libraries/Router.php b/system/libraries/Router.php index e2a14800d..6af6ad380 100644 --- a/system/libraries/Router.php +++ b/system/libraries/Router.php @@ -49,7 +49,6 @@ class CI_Router { function CI_Router() { $this->config =& load_class('Config'); - $this->input =& load_class('Input'); $this->_set_route_mapping(); log_message('debug', "Router Class Initialized"); } @@ -71,11 +70,11 @@ class CI_Router { // If so, we're done since segment based URIs are not used with query strings. if ($this->config->item('enable_query_strings') === TRUE AND isset($_GET[$this->config->item('controller_trigger')])) { - $this->set_class($_GET[$this->config->item('controller_trigger')]); + $this->set_class(trim($this->_filter_uri($_GET[$this->config->item('controller_trigger')]))); if (isset($_GET[$this->config->item('function_trigger')])) { - $this->set_method($_GET[$this->config->item('function_trigger')]); + $this->set_method(trim($this->_filter_uri($_GET[$this->config->item('function_trigger')]))); } return; @@ -483,7 +482,7 @@ class CI_Router { */ function set_class($class) { - $this->class = $this->input->filename_security($class); + $this->class = $class; } // -------------------------------------------------------------------- @@ -510,7 +509,7 @@ class CI_Router { */ function set_method($method) { - $this->method = $this->input->filename_security($method); + $this->method = $method; } // -------------------------------------------------------------------- @@ -542,7 +541,7 @@ class CI_Router { */ function set_directory($dir) { - $this->directory = $this->input->filename_security($dir).'/'; + $this->directory = $dir.'/'; } // -------------------------------------------------------------------- -- cgit v1.2.3-24-g4f1b From c39a41f4615378b9b7b112a1b6cd37f358533493 Mon Sep 17 00:00:00 2001 From: Derek Allard Date: Wed, 11 Jul 2007 17:26:21 +0000 Subject: fixed log message typo --- system/libraries/User_agent.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system') diff --git a/system/libraries/User_agent.php b/system/libraries/User_agent.php index b93bd340e..ea5db4d78 100644 --- a/system/libraries/User_agent.php +++ b/system/libraries/User_agent.php @@ -71,7 +71,7 @@ class CI_User_agent { } } - log_message('debug', "Table Class Initialized"); + log_message('debug', "User Agent Class Initialized"); } // -------------------------------------------------------------------- -- cgit v1.2.3-24-g4f1b From f5a519822db2201b98f822ad4f8659bad2ce9bcd Mon Sep 17 00:00:00 2001 From: Derek Allard Date: Wed, 11 Jul 2007 19:35:09 +0000 Subject: inflector helper changes to account for words ending in "s" --- system/helpers/inflector_helper.php | 78 ++++++++++++++++++++++--------------- 1 file changed, 46 insertions(+), 32 deletions(-) (limited to 'system') diff --git a/system/helpers/inflector_helper.php b/system/helpers/inflector_helper.php index fbe851f3b..28ecf5201 100644 --- a/system/helpers/inflector_helper.php +++ b/system/helpers/inflector_helper.php @@ -39,26 +39,31 @@ */ function singular($str) { - $str = strtolower(trim($str)); - $end = substr($str, -3); - - if ($end == 'ies') - { - $str = substr($str, 0, strlen($str)-3).'y'; - } - else - { - $end = substr($str, -1); - - if ($end == 's') - { - $str = substr($str, 0, strlen($str)-1); - } - } - - return $str; + $str = strtolower(trim($str)); + $end = substr($str, -3); + + if ($end == 'ies') + { + $str = substr($str, 0, strlen($str)-3).'y'; + } + elseif ($end == 'ses') + { + $str = substr($str, 0, strlen($str)-2); + } + else + { + $end = substr($str, -1); + + if ($end == 's') + { + $str = substr($str, 0, strlen($str)-1); + } + } + + return $str; } + // -------------------------------------------------------------------- /** @@ -68,25 +73,34 @@ function singular($str) * * @access public * @param string + * @param bool * @return str */ -function plural($str) +function plural($str, $force = FALSE) { - $str = strtolower(trim($str)); - $end = substr($str, -1); - - if ($end == 'y') - { - $str = substr($str, 0, strlen($str)-1).'ies'; - } - elseif ($end != 's') - { - $str .= 's'; - } - - return $str; + $str = strtolower(trim($str)); + $end = substr($str, -1); + + if ($end == 'y') + { + $str = substr($str, 0, strlen($str)-1).'ies'; + } + elseif ($end == 's') + { + if ($force == TRUE) + { + $str .= 'es'; + } + } + else + { + $str .= 's'; + } + + return $str; } + // -------------------------------------------------------------------- /** -- cgit v1.2.3-24-g4f1b From 9687c493de92eb71a91ed89723abd4ede977bb3d Mon Sep 17 00:00:00 2001 From: Derek Jones Date: Wed, 11 Jul 2007 21:43:23 +0000 Subject: bugfix for profiler output: POST keys were not being displayed properly, and queries needed htmlspecialchars() --- system/libraries/Profiler.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'system') diff --git a/system/libraries/Profiler.php b/system/libraries/Profiler.php index ffd664a88..6b1d5ea71 100644 --- a/system/libraries/Profiler.php +++ b/system/libraries/Profiler.php @@ -123,7 +123,7 @@ class CI_Profiler { foreach ($this->CI->db->queries as $val) { $output .= '
    '; - $output .= $val; + $output .= htmlspecialchars($val, ENT_QUOTES); $output .= "
    \n"; } } @@ -166,7 +166,7 @@ class CI_Profiler { } // $output .= "$_POST[".$key."]  ".htmlspecialchars(stripslashes($val))."\n"; - $output .= "".$_POST[$key]." "; + $output .= "$_POST[".$key."]   "; if (is_array($val)) { $output .= "
    " . htmlspecialchars(stripslashes(print_r($val, true))) . "
    "; -- cgit v1.2.3-24-g4f1b From 1f2fd2d5db0ff9e91388cec079a9ff58392ab654 Mon Sep 17 00:00:00 2001 From: Derek Jones Date: Wed, 11 Jul 2007 21:59:12 +0000 Subject: adding type casting of $title argument in URL helper functions to a string. A numeric 0 sent to these functions would evaluate if ($title == '') as TRUE, and type casting seems the more appropriate fix than simply using $title === '', since we're expecting and treating $title as a string. --- system/helpers/url_helper.php | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'system') diff --git a/system/helpers/url_helper.php b/system/helpers/url_helper.php index c05bc2088..01cd3458d 100644 --- a/system/helpers/url_helper.php +++ b/system/helpers/url_helper.php @@ -90,6 +90,8 @@ function index_page() */ function anchor($uri = '', $title = '', $attributes = '') { + $title = (string) $title; + if ( ! is_array($uri)) { $site_url = ( ! preg_match('!^\w+://!i', $uri)) ? site_url($uri) : $uri; @@ -132,6 +134,8 @@ function anchor($uri = '', $title = '', $attributes = '') */ function anchor_popup($uri = '', $title = '', $attributes = FALSE) { + $title = (string) $title; + $site_url = ( ! preg_match('!^\w+://!i', $uri)) ? site_url($uri) : $uri; if ($title == '') @@ -170,6 +174,8 @@ function anchor_popup($uri = '', $title = '', $attributes = FALSE) */ function mailto($email, $title = '', $attributes = '') { + $title = (string) $title; + if ($title == "") { $title = $email; @@ -195,6 +201,8 @@ function mailto($email, $title = '', $attributes = '') */ function safe_mailto($email, $title = '', $attributes = '') { + $title = (string) $title; + if ($title == "") { $title = $email; -- cgit v1.2.3-24-g4f1b From eea2bdaaffcbee1a9efb56e60ae5712e30873f87 Mon Sep 17 00:00:00 2001 From: Derek Jones Date: Wed, 11 Jul 2007 22:09:45 +0000 Subject: fixed the plural() and singular() function comments --- system/helpers/inflector_helper.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'system') diff --git a/system/helpers/inflector_helper.php b/system/helpers/inflector_helper.php index 28ecf5201..49143913c 100644 --- a/system/helpers/inflector_helper.php +++ b/system/helpers/inflector_helper.php @@ -31,7 +31,7 @@ /** * Singular * - * Takes a singular word and makes it plural + * Takes a plural word and makes it singular * * @access public * @param string @@ -69,7 +69,7 @@ function singular($str) /** * Plural * - * Takes a plural word and makes it singular + * Takes a singular word and makes it plural * * @access public * @param string -- cgit v1.2.3-24-g4f1b From c80593c537117b11e2f75287fc9a18e0d0d2bf5a Mon Sep 17 00:00:00 2001 From: Derek Jones Date: Wed, 11 Jul 2007 23:40:14 +0000 Subject: type cast $key => $val pair in $options array as strings for friendlier handling of setting options as 'selected' --- system/helpers/form_helper.php | 3 +++ 1 file changed, 3 insertions(+) (limited to 'system') diff --git a/system/helpers/form_helper.php b/system/helpers/form_helper.php index 531ab66c0..263dc0f19 100644 --- a/system/helpers/form_helper.php +++ b/system/helpers/form_helper.php @@ -229,6 +229,9 @@ function form_dropdown($name = '', $options = array(), $selected = '', $extra = foreach ($options as $key => $val) { + $key = (string) $key; + $val = (string) $val; + $sel = ($selected != $key) ? '' : ' selected="selected"'; $form .= '\n"; -- cgit v1.2.3-24-g4f1b From 2d2437edf10edf2669dd85e5943bd4061216eef0 Mon Sep 17 00:00:00 2001 From: Derek Jones Date: Thu, 12 Jul 2007 11:32:37 +0000 Subject: fixed quoted-printable in HTML emails, and added htmlspecialchars() to email debugging output --- system/libraries/Email.php | 104 +++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 100 insertions(+), 4 deletions(-) (limited to 'system') diff --git a/system/libraries/Email.php b/system/libraries/Email.php index 7b7dc091c..c7aeb33c8 100644 --- a/system/libraries/Email.php +++ b/system/libraries/Email.php @@ -45,6 +45,11 @@ class CI_Email { var $validate = FALSE; // true/false. Enables email validation var $priority = "3"; // Default priority (1 - 5) var $newline = "\n"; // Default newline. "\r\n" or "\n" (Use "\r\n" to comply with RFC 822) + + var $crlf = "\n"; // The RFC 2045 compliant CRLF for quoted-printable is "\r\n". Apparently some servers, + // even on the receiving end think they need to muck with CRLFs, so using "\n", while + // distasteful, is the only thing that seems to work for all environments. + var $bcc_batch_mode = FALSE; // true/false Turns on/off Bcc batch feature var $bcc_batch_size = 200; // If bcc_batch_mode = true, sets max number of Bccs in each batch var $_subject = ""; @@ -924,7 +929,7 @@ class CI_Email { break; case 'html' : - + $hdr .= "Content-Type: multipart/alternative; boundary=\"" . $this->_alt_boundary . "\"" . $this->newline; $hdr .= $this->_get_mime_message() . $this->newline . $this->newline; $hdr .= "--" . $this->_alt_boundary . $this->newline; @@ -934,7 +939,9 @@ class CI_Email { $hdr .= $this->_get_alt_message() . $this->newline . $this->newline . "--" . $this->_alt_boundary . $this->newline; $hdr .= "Content-Type: text/html; charset=" . $this->charset . $this->newline; - $hdr .= "Content-Transfer-Encoding: quoted/printable"; + $hdr .= "Content-Transfer-Encoding: quoted-printable"; + + $this->_body = $this->_prep_quoted_printable($this->_body); if ($this->_get_protocol() == 'mail') { @@ -985,7 +992,9 @@ class CI_Email { $hdr .= $this->_get_alt_message() . $this->newline . $this->newline . "--" . $this->_alt_boundary . $this->newline; $hdr .= "Content-Type: text/html; charset=" . $this->charset . $this->newline; - $hdr .= "Content-Transfer-Encoding: quoted/printable"; + $hdr .= "Content-Transfer-Encoding: quoted-printable"; + + $this->_body = $this->_prep_quoted_printable($this->_body); if ($this->_get_protocol() == 'mail') { @@ -1050,7 +1059,94 @@ class CI_Email { } // -------------------------------------------------------------------- + + /** + * Prep Quoted Printable + * + * Prepares string for Quoted-Printable Content-Transfer-Encoding + * Refer to RFC 2045 http://www.ietf.org/rfc/rfc2045.txt + * + * @access public + * @param string + * @param integer + * @return string + */ + function _prep_quoted_printable($str, $charlim = '') + { + // Set the character limit + // Don't allow over 76, as that will make servers and MUAs barf + // all over quoted-printable data + if ($charlim == '' OR $charlim > '76') + { + $charlim = '76'; + } + + // Reduce multiple spaces + $str = preg_replace("| +|", " ", $str); + + // Standardize newlines + $str = preg_replace("/\r\n|\r/", "\n", $str); + + // We are intentionally wrapping so mail servers will encode characters + // properly and MUAs will behave, so {unwrap} must go! + $str = str_replace(array('{unwrap}', '{/unwrap}'), '', $str); + + // Break into an array of lines + $lines = preg_split("/\n/", $str); + $escape = '='; + $output = ''; + + foreach ($lines as $line) + { + $length = strlen($line); + $temp = ''; + + // Loop through each character in the line to add soft-wrap + // characters at the end of a line " =\r\n" and add the newly + // processed line(s) to the output (see comment on $crlf class property) + for ($i = 0; $i < $length; $i++) + { + // Grab the next character + $char = substr($line, $i, 1); + $ascii = ord($char); + + // Convert spaces and tabs but only if it's the end of the line + if ($i == ($length - 1)) + { + $char = ($ascii == '32' OR $ascii == '9') ? $escape.sprintf('%02s', dechex($char)) : $char; + } + + // encode = signs + if ($ascii == '61') + { + $char = $escape.strtoupper(sprintf('%02s', dechex($ascii))); // =3D + } + + // If we're at the character limit, add the line to the output, + // reset our temp variable, and keep on chuggin' + if ((strlen($temp) + strlen($char)) >= $charlim) + { + $output .= $temp.$escape.$this->crlf; + $temp = ''; + } + + // Add the character to our temporary line + $temp .= $char; + } + + // Add our completed line to the output + $output .= $temp.$this->crlf; + } + + // get rid of extra CRLF tacked onto the end + $output = substr($output, 0, strlen($this->crlf) * -1); + + return $output; + } + + // -------------------------------------------------------------------- + /** * Send Email * @@ -1583,7 +1679,7 @@ class CI_Email { } } - $msg .= "
    ".$this->_header_str."\n".$this->_subject."\n".$this->_finalbody.'
    '; + $msg .= "
    ".$this->_header_str."\n".htmlspecialchars($this->_subject)."\n".htmlspecialchars($this->_finalbody).'
    '; return $msg; } -- cgit v1.2.3-24-g4f1b From c9e2b10f08a3c718e52e287e2dd14b880e4e3057 Mon Sep 17 00:00:00 2001 From: Derek Allard Date: Thu, 12 Jul 2007 12:14:45 +0000 Subject: added language files to autoload --- system/application/config/autoload.php | 15 +++++++++++++++ system/libraries/Language.php | 5 ----- system/libraries/Loader.php | 25 ++++++++++++++++++------- 3 files changed, 33 insertions(+), 12 deletions(-) (limited to 'system') diff --git a/system/application/config/autoload.php b/system/application/config/autoload.php index 26e71f74c..85b65aa7f 100644 --- a/system/application/config/autoload.php +++ b/system/application/config/autoload.php @@ -80,6 +80,21 @@ $autoload['plugin'] = array(); $autoload['config'] = array(); +/* +| ------------------------------------------------------------------- +| Auto-load Language files +| ------------------------------------------------------------------- +| Prototype: +| +| $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 Core Libraries diff --git a/system/libraries/Language.php b/system/libraries/Language.php index 26775ec7e..94923a3e7 100644 --- a/system/libraries/Language.php +++ b/system/libraries/Language.php @@ -89,11 +89,6 @@ class CI_Language { return; } - if ($return == TRUE) - { - return $lang; - } - $this->is_loaded[] = $langfile; $this->language = array_merge($this->language, $lang); unset($lang); diff --git a/system/libraries/Loader.php b/system/libraries/Loader.php index abe3a1c37..7fa46c3ad 100644 --- a/system/libraries/Loader.php +++ b/system/libraries/Loader.php @@ -481,13 +481,24 @@ class CI_Loader { * Loads a language file * * @access public + * @param array * @param string + * @param bool * @return void */ - function language($file = '', $lang = '', $return = FALSE) + function language($file = array(), $lang = '') { $CI =& get_instance(); - return $CI->lang->load($file, $lang, $return); + + if ( ! is_array($file)) + { + $file = array($file); + } + + foreach ($file as $langfile) + { + $CI->lang->load($langfile, $lang); + } } // -------------------------------------------------------------------- @@ -813,7 +824,7 @@ class CI_Loader { return FALSE; } - // Load any custome config file + // Load any custom config file if (count($autoload['config']) > 0) { $CI =& get_instance(); @@ -823,15 +834,15 @@ class CI_Loader { } } - // Load plugins, helpers, and scripts - foreach (array('helper', 'plugin', 'script') as $type) - { + // Autoload plugins, helpers, scripts and languages + foreach (array('helper', 'plugin', 'script', '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'])) -- cgit v1.2.3-24-g4f1b From 7dcd7a3aa4b145fc8a040c16e7c4de9ea35fd5cf Mon Sep 17 00:00:00 2001 From: Derek Allard Date: Thu, 12 Jul 2007 12:36:50 +0000 Subject: csv_from_result() move robust against data with "," in it. --- system/database/DB_utility.php | 54 +++++++++++++++++++++++++++--------------- 1 file changed, 35 insertions(+), 19 deletions(-) (limited to 'system') diff --git a/system/database/DB_utility.php b/system/database/DB_utility.php index d48425d7e..8ce19b17f 100644 --- a/system/database/DB_utility.php +++ b/system/database/DB_utility.php @@ -236,35 +236,51 @@ class CI_DB_utility { * @param string The newline character - \n by default * @return string */ - function csv_from_result($query, $delim = "\t", $newline = "\n") + function csv_from_result($query, $delim = ',', $newline = '', $enclosure = '"') { - if ( ! is_object($query) OR ! method_exists($query, 'field_names')) - { - show_error('You must submit a valid result object'); - } + if (!is_a($query, 'CI_DB_result')) { + show_error('CI_DB_utility::csv_from_result - You must submit a valid result object'); + } + + if ($delim === '') { + show_error('CI_DB_utility::csv_from_result - Empty delimiters are not permitted'); + } + + if ($newline === '') { + $newline = (stripos(getenv('HTTP_USER_AGENT'), 'win') !== false) ? "\r\n" : "\n"; + } + if ((strpos($enclosure, $newline) !== false) or (($enclosure !== '') and (strpos($newline, $enclosure) !== false))) { + show_error('CI_DB_utility::csv_from_result - Field enclosure must not be contained within delimiter (or vice versa)'); + } + $out = ''; // First generate the headings from the table column names - foreach ($query->list_fields() as $name) - { - $out .= $name.$delim; + foreach ($query->list_fields() as $name) { + // there's no point enclosing strings that do not require it + if (strpos($name, $delim) !== false) { + $out .= $enclosure . $name . $enclosure . $delim; + } else { + $out .= $name . $delim; + } } - $out = rtrim($out); - $out .= $newline; - + $out = rtrim($out, $delim) . $newline; + // Next blast through the result array and build out the rows - foreach ($query->result_array() as $row) - { - foreach ($row as $item) - { - $out .= $item.$delim; + foreach ($query->result_array() as $row) { + foreach ($row as $item) { + // there's no point enclosing strings that do not require it + if (strpos($item, $delim) !== false) { + $out .= $enclosure . $item . $enclosure . $delim; + } else { + $out .= $item . $delim; + } } - $out = rtrim($out); - $out .= $newline; + $out = rtrim($out, $delim) . $newline; } - + return $out; } -- cgit v1.2.3-24-g4f1b From 48bb32aece18e9dce381602e242609adfc71b0d0 Mon Sep 17 00:00:00 2001 From: Derek Jones Date: Thu, 12 Jul 2007 13:10:42 +0000 Subject: further xss_clean() enhancements --- system/libraries/Input.php | 97 ++++++++++++++++++++++++++++++++-------------- 1 file changed, 67 insertions(+), 30 deletions(-) (limited to 'system') diff --git a/system/libraries/Input.php b/system/libraries/Input.php index 33f288688..fcca722b7 100644 --- a/system/libraries/Input.php +++ b/system/libraries/Input.php @@ -538,15 +538,15 @@ class CI_Input { * the conversion of entities to ASCII later. * */ - $str = preg_replace('#(&\#*\w+)[\x00-\x20]+;#u',"\\1;",$str); + $str = preg_replace('#(&\#?[0-9a-z]+)[\x00-\x20]*;?#i', "\\1;", $str); /* - * Validate UTF16 two byte encoding (x00) + * Validate UTF16 two byte encoding (x00) * * Just as above, adds a semicolon if missing. * */ - $str = preg_replace('#(&\#x*)([0-9A-F]+);*#iu',"\\1\\2;",$str); + $str = preg_replace('#(&\#x?)([0-9A-F]+);?#i',"\\1\\2;",$str); /* * URL Decode @@ -580,37 +580,50 @@ class CI_Input { $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); + /* * Not Allowed Under Any Conditions */ $bad = array( 'document.cookie' => '[removed]', + 'document.write' => '[removed]', '.parentNode' => '[removed]', '.innerHTML' => '[removed]', - 'document.write' => '[removed]', 'window.location' => '[removed]', + '-moz-binding' => '[removed]', + '' => '-->', + ' '<![CDATA[' + ); + + foreach ($bad as $key => $val) + { + $str = str_replace($key, $val, $str); + } + + $bad = array( "javascript\s*:" => '[removed]', "expression\s*\(" => '[removed]', // CSS and IE - "Redirect\s+302" => '[removed]', - '' => '-->' + "Redirect\s+302" => '[removed]' ); - + foreach ($bad as $key => $val) { $str = preg_replace("#".$key."#i", $val, $str); } - /* - * Convert all tabs to spaces - * - * This prevents strings like this: ja vascript - * Note: we deal with spaces between characters later. - * - */ - $str = preg_replace("#\t+#", " ", $str); - /* * Makes PHP tags safe * @@ -621,7 +634,7 @@ class CI_Input { * But it doesn't seem to pose a problem. * */ - $str = str_replace(array(''), array('<?php', '<?PHP', '<?', '?>'), $str); + $str = str_replace(array(''), array('<?php', '<?PHP', '<?', '?>'), $str); /* * Compact any exploded words @@ -650,10 +663,24 @@ class CI_Input { do { $original = $str; - - $str = preg_replace_callback("##si", array($this, '_js_link_removal'), $str); - $str = preg_replace_callback("##si", array($this, '_js_img_removal'), $str); - $str = preg_replace("##si", "", $str); + + if ((version_compare(PHP_VERSION, '5.0', '>=') === TRUE && stripos($str, '') !== FALSE) OR + preg_match("/<\/a>/i", $str)) + { + $str = preg_replace_callback("##si", array($this, '_js_link_removal'), $str); + } + + if ((version_compare(PHP_VERSION, '5.0', '>=') === TRUE && stripos($str, '#si", array($this, '_js_img_removal'), $str); + } + + if ((version_compare(PHP_VERSION, '5.0', '>=') === TRUE && (stripos($str, 'script') !== FALSE OR stripos($str, 'xss') !== FALSE)) OR + preg_match("/(script|xss)/i", $str)) + { + $str = preg_replace("##si", "", $str); + } } while($original != $str); @@ -706,20 +733,30 @@ class CI_Input { */ $bad = array( 'document.cookie' => '[removed]', + 'document.write' => '[removed]', '.parentNode' => '[removed]', '.innerHTML' => '[removed]', - 'document.write' => '[removed]', 'window.location' => '[removed]', + '-moz-binding' => '[removed]', + '' => '-->', + ' '<![CDATA[' + ); + + foreach ($bad as $key => $val) + { + $str = str_replace($key, $val, $str); + } + + $bad = array( "javascript\s*:" => '[removed]', "expression\s*\(" => '[removed]', // CSS and IE - "Redirect\s+302" => '[removed]', - '' => '-->' + "Redirect\s+302" => '[removed]' ); - + foreach ($bad as $key => $val) { - $str = preg_replace("#".$key."#i", $val, $str); + $str = preg_replace("#".$key."#i", $val, $str); } @@ -764,7 +801,7 @@ class CI_Input { } // -------------------------------------------------------------------- - + /** * HTML Entities Decode * -- cgit v1.2.3-24-g4f1b From e5808cf64d1177127cc9f26e6f681b412a192339 Mon Sep 17 00:00:00 2001 From: Derek Jones Date: Thu, 12 Jul 2007 13:36:56 +0000 Subject: removed $return argument from load() --- system/libraries/Language.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'system') diff --git a/system/libraries/Language.php b/system/libraries/Language.php index 94923a3e7..bcf84cf67 100644 --- a/system/libraries/Language.php +++ b/system/libraries/Language.php @@ -49,7 +49,7 @@ class CI_Language { * @param string the language (english, etc.) * @return void */ - function load($langfile = '', $idiom = '', $return = FALSE) + function load($langfile = '', $idiom = '') { $langfile = str_replace(EXT, '', str_replace('_lang.', '', $langfile)).'_lang'.EXT; @@ -82,7 +82,6 @@ class CI_Language { } } - if ( ! isset($lang)) { log_message('error', 'Language file contains no data: language/'.$idiom.'/'.$langfile); -- cgit v1.2.3-24-g4f1b From 3f2fc0d5a9aa13209dd4ec1175a4ee2bc4172408 Mon Sep 17 00:00:00 2001 From: Derek Jones Date: Thu, 12 Jul 2007 13:38:18 +0000 Subject: removed empty string element from default $autoload['language'] array --- system/application/config/autoload.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system') diff --git a/system/application/config/autoload.php b/system/application/config/autoload.php index 85b65aa7f..90ff6fedf 100644 --- a/system/application/config/autoload.php +++ b/system/application/config/autoload.php @@ -93,7 +93,7 @@ $autoload['config'] = array(); | */ -$autoload['language'] = array(''); +$autoload['language'] = array(); /* | ------------------------------------------------------------------- -- cgit v1.2.3-24-g4f1b From f9a4e9e04589df8dcf808519c95703f16c318384 Mon Sep 17 00:00:00 2001 From: Derek Jones Date: Thu, 12 Jul 2007 13:56:21 +0000 Subject: fixed undefined function in insert_id() of PostgreSQL driver --- system/database/drivers/postgre/postgre_driver.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system') diff --git a/system/database/drivers/postgre/postgre_driver.php b/system/database/drivers/postgre/postgre_driver.php index bfb212cfd..798905126 100644 --- a/system/database/drivers/postgre/postgre_driver.php +++ b/system/database/drivers/postgre/postgre_driver.php @@ -230,7 +230,7 @@ class CI_DB_postgre_driver extends CI_DB { */ function insert_id() { - $v = version($this->conn_id); + $v = $this->_version(); $v = $v['server']; $table = func_num_args() > 0 ? func_get_arg(0) : null; -- cgit v1.2.3-24-g4f1b From 476b87150809861e6963eb26be083086f8ea0464 Mon Sep 17 00:00:00 2001 From: Derek Allard Date: Thu, 12 Jul 2007 18:22:05 +0000 Subject: csv_from_result buggy. revert to old function until rewrite --- system/database/DB_utility.php | 924 ++++++++++++++++++++--------------------- 1 file changed, 454 insertions(+), 470 deletions(-) (limited to 'system') diff --git a/system/database/DB_utility.php b/system/database/DB_utility.php index 8ce19b17f..9533ec607 100644 --- a/system/database/DB_utility.php +++ b/system/database/DB_utility.php @@ -1,471 +1,455 @@ -db - $CI =& get_instance(); - $this->db =& $CI->db; - - log_message('debug', "Database Utility 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); - } - - // -------------------------------------------------------------------- - - /** - * 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']; - } - - // -------------------------------------------------------------------- - - /** - * 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)) - { - return $sql; - } - - $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; - } - - // -------------------------------------------------------------------- - - /** - * Optimize 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); - } - - // -------------------------------------------------------------------- - - /** - * Drop Table - * - * @access public - * @param string the table name - * @return bool - */ - function drop_table($table_name) - { - $sql = $this->_drop_table($table_name); - - if (is_bool($sql)) - { - return $sql; - } - - return $this->db->query($sql); - } - - // -------------------------------------------------------------------- - - /** - * Generate CSV from a query result object - * - * @access public - * @param object The query result object - * @param string The delimiter - tab by default - * @param string The newline character - \n by default - * @return string - */ - function csv_from_result($query, $delim = ',', $newline = '', $enclosure = '"') - { - if (!is_a($query, 'CI_DB_result')) { - show_error('CI_DB_utility::csv_from_result - You must submit a valid result object'); - } - - if ($delim === '') { - show_error('CI_DB_utility::csv_from_result - Empty delimiters are not permitted'); - } - - if ($newline === '') { - $newline = (stripos(getenv('HTTP_USER_AGENT'), 'win') !== false) ? "\r\n" : "\n"; - } - - if ((strpos($enclosure, $newline) !== false) or (($enclosure !== '') and (strpos($newline, $enclosure) !== false))) { - show_error('CI_DB_utility::csv_from_result - Field enclosure must not be contained within delimiter (or vice versa)'); - } - - $out = ''; - - // First generate the headings from the table column names - foreach ($query->list_fields() as $name) { - // there's no point enclosing strings that do not require it - if (strpos($name, $delim) !== false) { - $out .= $enclosure . $name . $enclosure . $delim; - } else { - $out .= $name . $delim; - } - } - - $out = rtrim($out, $delim) . $newline; - - // Next blast through the result array and build out the rows - foreach ($query->result_array() as $row) { - foreach ($row as $item) { - // there's no point enclosing strings that do not require it - if (strpos($item, $delim) !== false) { - $out .= $enclosure . $item . $enclosure . $delim; - } else { - $out .= $item . $delim; - } - } - $out = rtrim($out, $delim) . $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, 'field_names')) - { - 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(); - } - - } - - - - - - -} - +db + $CI =& get_instance(); + $this->db =& $CI->db; + + log_message('debug', "Database Utility 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); + } + + // -------------------------------------------------------------------- + + /** + * 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']; + } + + // -------------------------------------------------------------------- + + /** + * 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)) + { + return $sql; + } + + $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; + } + + // -------------------------------------------------------------------- + + /** + * Optimize 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); + } + + // -------------------------------------------------------------------- + + /** + * Drop Table + * + * @access public + * @param string the table name + * @return bool + */ + function drop_table($table_name) + { + $sql = $this->_drop_table($table_name); + + if (is_bool($sql)) + { + return $sql; + } + + return $this->db->query($sql); + } + + // -------------------------------------------------------------------- + + /** + * Generate CSV from a query result object + * + * @access public + * @param object The query result object + * @param string The delimiter - tab by default + * @param string The newline character - \n by default + * @return string + */ + function csv_from_result($query, $delim = "\t", $newline = "\n") + { + if ( ! is_object($query) OR ! method_exists($query, 'field_names')) + { + 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 .= $name.$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 .= $item.$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, 'field_names')) + { + 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(); + } + + } + + + + + + +} + ?> \ No newline at end of file -- cgit v1.2.3-24-g4f1b From 33d1056c454eeb5e4484ff4454f78da9dc2a3ec5 Mon Sep 17 00:00:00 2001 From: Derek Jones Date: Thu, 12 Jul 2007 18:44:13 +0000 Subject: sacked duplicate and incorrect version of _version()! --- system/database/drivers/mssql/mssql_driver.php | 13 ------------- 1 file changed, 13 deletions(-) (limited to 'system') diff --git a/system/database/drivers/mssql/mssql_driver.php b/system/database/drivers/mssql/mssql_driver.php index aef8da926..e4a2960e5 100644 --- a/system/database/drivers/mssql/mssql_driver.php +++ b/system/database/drivers/mssql/mssql_driver.php @@ -69,19 +69,6 @@ class CI_DB_mssql_driver extends CI_DB { // -------------------------------------------------------------------- - /** - * Version number query string - * - * @access public - * @return string - */ - function _version() - { - return "SELECT version() AS ver"; - } - - // -------------------------------------------------------------------- - /** * Execute the query * -- cgit v1.2.3-24-g4f1b From 303c9cb958a52ef2d13e985da397cb49590113b0 Mon Sep 17 00:00:00 2001 From: Derek Jones Date: Thu, 12 Jul 2007 19:12:37 +0000 Subject: added attribute and html entity decode callbacks to xss_clean() --- system/libraries/Input.php | 80 +++++++++++++++++++++++++++++++++++++++------- 1 file changed, 69 insertions(+), 11 deletions(-) (limited to 'system') diff --git a/system/libraries/Input.php b/system/libraries/Input.php index fcca722b7..ba94d854f 100644 --- a/system/libraries/Input.php +++ b/system/libraries/Input.php @@ -519,7 +519,7 @@ class CI_Input { * @param string * @return string */ - function xss_clean($str, $charset = 'ISO-8859-1') + function xss_clean($str) { /* * Remove Null Characters @@ -564,23 +564,46 @@ class CI_Input { $str = str_replace('9u3iovBnRThju941s89rKozm', "%20", $str); /* - * Convert character entities to ASCII + * 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. * */ - if (preg_match_all("/<(.+?)>/si", $str, $matches)) - { - for ($i = 0; $i < count($matches['0']); $i++) + + $str = preg_replace_callback("/[a-z]+=([\'\"]).*?\\1/si", array($this, '_attribute_conversion'), $str); + + $str = preg_replace_callback("/<([\w]+)[^>]*>/si", array($this, '_html_entity_decode_callback'), $str); + + /* + + Old Code that when modified to use preg_replace()'s above became more efficient memory-wise + + if (preg_match_all("/[a-z]+=([\'\"]).*?\\1/si", $str, $matches)) + { + for ($i = 0; $i < count($matches[0]); $i++) + { + if (stristr($matches[0][$i], '>')) + { + $str = str_replace( $matches['0'][$i], + str_replace('>', '<', $matches[0][$i]), + $str); + } + } + } + + if (preg_match_all("/<([\w]+)[^>]*>/si", $str, $matches)) + { + for ($i = 0; $i < count($matches[0]); $i++) { - $str = str_replace($matches['1'][$i], - $this->_html_entity_decode($matches['1'][$i], $charset), + $str = str_replace($matches[0][$i], + $this->_html_entity_decode($matches[0][$i], $charset), $str); } } - + */ + /* * Convert all tabs to spaces * @@ -801,7 +824,42 @@ class CI_Input { } // -------------------------------------------------------------------- - + + /** + * Attribute Conversion + * + * Used as a callback for XSS Clean + * + * @access public + * @param array + * @return string + */ + function _attribute_conversion($match) + { + return str_replace('>', '<', $match[0]); + } + + // -------------------------------------------------------------------- + + /** + * HTML Entity Decode Callback + * + * Used as a callback for XSS Clean + * + * @access public + * @param array + * @return string + */ + function _html_entity_decode_callback($match) + { + $CI =& get_instance(); + $charset = $CI->config->item('charset'); + + return $this->_html_entity_decode($match[0], strtoupper($charset)); + } + + // -------------------------------------------------------------------- + /** * HTML Entities Decode * @@ -826,10 +884,10 @@ class CI_Input { character set, and the PHP developers said they were not back porting the fix to versions other than PHP 5.x. */ - function _html_entity_decode($str, $charset='ISO-8859-1') + function _html_entity_decode($str, $charset='UTF-8') { if (stristr($str, '&') === FALSE) return $str; - + // 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 -- cgit v1.2.3-24-g4f1b From b940ebc2d8f7b830c877777a14259da4927ce3fe Mon Sep 17 00:00:00 2001 From: Derek Jones Date: Thu, 12 Jul 2007 19:15:09 +0000 Subject: added $config['charset'] --- system/application/config/config.php | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'system') diff --git a/system/application/config/config.php b/system/application/config/config.php index 941d9c303..f0ba241f6 100644 --- a/system/application/config/config.php +++ b/system/application/config/config.php @@ -68,6 +68,16 @@ $config['url_suffix'] = ""; */ $config['language'] = "english"; +/* +|-------------------------------------------------------------------------- +| Default Character Set +|-------------------------------------------------------------------------- +| +| This determines which character set is used by default in various methods +| that require a character set to be provided. +| +*/ +$config['charset'] = "UTF-8"; /* |-------------------------------------------------------------------------- -- cgit v1.2.3-24-g4f1b From 60ca9b7c03d576eb8b83759ca04eaf21e25e1d9c Mon Sep 17 00:00:00 2001 From: Derek Allard Date: Thu, 12 Jul 2007 19:53:27 +0000 Subject: moved version number up in docs and CI_VERSION --- system/codeigniter/CodeIgniter.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system') diff --git a/system/codeigniter/CodeIgniter.php b/system/codeigniter/CodeIgniter.php index 987478f9f..1cd66a187 100644 --- a/system/codeigniter/CodeIgniter.php +++ b/system/codeigniter/CodeIgniter.php @@ -28,7 +28,7 @@ */ // CI Version -define('CI_VERSION', '1.5.3'); +define('CI_VERSION', '1.5.4'); /* * ------------------------------------------------------ -- cgit v1.2.3-24-g4f1b From 593712b25007d78c87a76221ffa186b72dd52095 Mon Sep 17 00:00:00 2001 From: Derek Allard Date: Thu, 12 Jul 2007 20:01:19 +0000 Subject: added a comment re: autoloading languages --- system/application/config/autoload.php | 1 + 1 file changed, 1 insertion(+) (limited to 'system') diff --git a/system/application/config/autoload.php b/system/application/config/autoload.php index 90ff6fedf..8bb4181b5 100644 --- a/system/application/config/autoload.php +++ b/system/application/config/autoload.php @@ -22,6 +22,7 @@ | 2. Helper files | 3. Plugins | 4. Custom config files +| 5. Language files | */ -- cgit v1.2.3-24-g4f1b From 060052de1f91b9b1fc533d0957eb18dab9057bfe Mon Sep 17 00:00:00 2001 From: Derek Allard Date: Sat, 14 Jul 2007 14:26:13 +0000 Subject: Fixed a bug in database driver where num_rows property wasn't getting updated --- system/database/DB_driver.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'system') diff --git a/system/database/DB_driver.php b/system/database/DB_driver.php index 8f238fc52..381b70f42 100644 --- a/system/database/DB_driver.php +++ b/system/database/DB_driver.php @@ -325,7 +325,8 @@ class CI_DB_driver { $RES = new $driver(); $RES->conn_id = $this->conn_id; $RES->result_id = $this->result_id; - + $RES->num_rows = $RES->num_rows(); + if ($this->dbdriver == 'oci8') { $RES->stmt_id = $this->stmt_id; -- cgit v1.2.3-24-g4f1b From 88c6bba4e6f5184a8a7349728b8250b8030d0706 Mon Sep 17 00:00:00 2001 From: Derek Allard Date: Sun, 15 Jul 2007 15:06:08 +0000 Subject: changed ImageColorAllocate to imagecolorallocate --- system/plugins/captcha_pi.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'system') diff --git a/system/plugins/captcha_pi.php b/system/plugins/captcha_pi.php index e16a214b6..7d1694f2e 100644 --- a/system/plugins/captcha_pi.php +++ b/system/plugins/captcha_pi.php @@ -250,9 +250,9 @@ function create_captcha($data = '', $img_path = '', $img_url = '', $font_path = // Assign colors // ----------------------------------- - $bg_color = ImageColorAllocate($im, 255, 255, 255); - $border_color = ImageColorAllocate($im, 153, 102, 102); - $text_color = ImageColorAllocate($im, 204, 153, 153); + $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); -- cgit v1.2.3-24-g4f1b From 669f999dcd1002c941066c83f89d856bcf057f2b Mon Sep 17 00:00:00 2001 From: Derek Allard Date: Sun, 15 Jul 2007 15:21:36 +0000 Subject: Fixed a typo ("cal_mayl") in English calendar language file --- system/language/english/calendar_lang.php | 97 ++++++++++++++++--------------- 1 file changed, 49 insertions(+), 48 deletions(-) (limited to 'system') diff --git a/system/language/english/calendar_lang.php b/system/language/english/calendar_lang.php index 02475e1f3..f044606b8 100644 --- a/system/language/english/calendar_lang.php +++ b/system/language/english/calendar_lang.php @@ -1,49 +1,50 @@ - \ No newline at end of file -- cgit v1.2.3-24-g4f1b From 5f41eddda985b85763c0b275a411b2503ca51496 Mon Sep 17 00:00:00 2001 From: Derek Allard Date: Sun, 15 Jul 2007 17:45:36 +0000 Subject: revert calendar change... I'm an idiot --- system/language/english/calendar_lang.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'system') diff --git a/system/language/english/calendar_lang.php b/system/language/english/calendar_lang.php index f044606b8..9ee4a5e69 100644 --- a/system/language/english/calendar_lang.php +++ b/system/language/english/calendar_lang.php @@ -37,8 +37,7 @@ $lang['cal_january'] = "January"; $lang['cal_february'] = "February"; $lang['cal_march'] = "March"; $lang['cal_april'] = "April"; -$lang['cal_mayl'] = "May"; // typo, left in for backwards compatibility -$lang['cal_may'] = "May"; // fix typo +$lang['cal_mayl'] = "May"; $lang['cal_june'] = "June"; $lang['cal_july'] = "July"; $lang['cal_august'] = "August"; -- cgit v1.2.3-24-g4f1b From 79ecefd0ec2cc7e2bcf35fad4f80e22d9ac70e16 Mon Sep 17 00:00:00 2001 From: Derek Allard Date: Sun, 15 Jul 2007 22:49:07 +0000 Subject: fix for scaffolding --- system/libraries/Language.php | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'system') diff --git a/system/libraries/Language.php b/system/libraries/Language.php index bcf84cf67..26775ec7e 100644 --- a/system/libraries/Language.php +++ b/system/libraries/Language.php @@ -49,7 +49,7 @@ class CI_Language { * @param string the language (english, etc.) * @return void */ - function load($langfile = '', $idiom = '') + function load($langfile = '', $idiom = '', $return = FALSE) { $langfile = str_replace(EXT, '', str_replace('_lang.', '', $langfile)).'_lang'.EXT; @@ -82,12 +82,18 @@ class CI_Language { } } + 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); -- cgit v1.2.3-24-g4f1b From 873c722774f8cc43c737b5ee0befd8e6a0796bc8 Mon Sep 17 00:00:00 2001 From: Derek Allard Date: Sun, 15 Jul 2007 23:03:05 +0000 Subject: further scaffolding language fixes --- system/libraries/Loader.php | 13 +++++++++++++ system/scaffolding/Scaffolding.php | 2 +- 2 files changed, 14 insertions(+), 1 deletion(-) (limited to 'system') diff --git a/system/libraries/Loader.php b/system/libraries/Loader.php index 7fa46c3ad..ee99696a0 100644 --- a/system/libraries/Loader.php +++ b/system/libraries/Loader.php @@ -500,6 +500,19 @@ class CI_Loader { $CI->lang->load($langfile, $lang); } } + + /** + * Loads a language file + * + * @access public + * @param string + * @return void + */ + function scaffold_language($file = '', $lang = '', $return = FALSE) + { + $CI =& get_instance(); + return $CI->lang->load($file, $lang, $return); + } // -------------------------------------------------------------------- diff --git a/system/scaffolding/Scaffolding.php b/system/scaffolding/Scaffolding.php index fe2744e77..6f4babd91 100644 --- a/system/scaffolding/Scaffolding.php +++ b/system/scaffolding/Scaffolding.php @@ -73,7 +73,7 @@ class Scaffolding { $this->CI->load->vars($data); // Load the language file and create variables - $this->lang = $this->CI->load->language('scaffolding', '', TRUE); + $this->lang = $this->CI->load->scaffold_language('scaffolding', '', TRUE); $this->CI->load->vars($this->lang); // Load the helper files we plan to use -- cgit v1.2.3-24-g4f1b From 5808a11cedc9bc825450dc3d652e0a4a45b02b4f Mon Sep 17 00:00:00 2001 From: Derek Allard Date: Sun, 15 Jul 2007 23:19:08 +0000 Subject: comment clean up --- system/libraries/Loader.php | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) (limited to 'system') diff --git a/system/libraries/Loader.php b/system/libraries/Loader.php index ee99696a0..2e762e9f1 100644 --- a/system/libraries/Loader.php +++ b/system/libraries/Loader.php @@ -483,7 +483,6 @@ class CI_Loader { * @access public * @param array * @param string - * @param bool * @return void */ function language($file = array(), $lang = '') @@ -502,11 +501,11 @@ class CI_Loader { } /** - * Loads a language file + * Loads language files for scaffolding * * @access public * @param string - * @return void + * @return arra */ function scaffold_language($file = '', $lang = '', $return = FALSE) { -- cgit v1.2.3-24-g4f1b From 6159d1dd0945490d1425ae3269dc3172680a3c91 Mon Sep 17 00:00:00 2001 From: Derek Jones Date: Mon, 16 Jul 2007 13:04:46 +0000 Subject: Switched from CI super object to $CFG to fetch charset --- system/libraries/Input.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'system') diff --git a/system/libraries/Input.php b/system/libraries/Input.php index ba94d854f..b41dcfb29 100644 --- a/system/libraries/Input.php +++ b/system/libraries/Input.php @@ -852,8 +852,8 @@ class CI_Input { */ function _html_entity_decode_callback($match) { - $CI =& get_instance(); - $charset = $CI->config->item('charset'); + global $CFG; + $charset = $CFG->item('charset'); return $this->_html_entity_decode($match[0], strtoupper($charset)); } -- cgit v1.2.3-24-g4f1b From 409904637cd661be6ceccb59af1046468da09802 Mon Sep 17 00:00:00 2001 From: Rick Ellis Date: Tue, 17 Jul 2007 21:40:44 +0000 Subject: --- system/database/DB_driver.php | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'system') diff --git a/system/database/DB_driver.php b/system/database/DB_driver.php index 381b70f42..ee965b74c 100644 --- a/system/database/DB_driver.php +++ b/system/database/DB_driver.php @@ -44,6 +44,7 @@ class CI_DB_driver { var $benchmark = 0; var $query_count = 0; var $bind_marker = '?'; + var $save_queries = TRUE; var $queries = array(); var $data_cache = array(); var $trans_enabled = TRUE; @@ -264,7 +265,10 @@ class CI_DB_driver { } // Save the query for debugging - $this->queries[] = $sql; + if ($this->save_queries == TRUE) + { + $this->queries[] = $sql; + } // Start the Query Timer $time_start = list($sm, $ss) = explode(' ', microtime()); -- cgit v1.2.3-24-g4f1b From 7aa1809e775bddfa08e17d8424a3532fcf06d6ae Mon Sep 17 00:00:00 2001 From: Rick Ellis Date: Thu, 19 Jul 2007 00:13:13 +0000 Subject: --- system/helpers/cookie_helper.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'system') diff --git a/system/helpers/cookie_helper.php b/system/helpers/cookie_helper.php index 9dc5df9b1..4fb30bd5b 100644 --- a/system/helpers/cookie_helper.php +++ b/system/helpers/cookie_helper.php @@ -60,15 +60,15 @@ function set_cookie($name = '', $value = '', $expire = '', $domain = '', $path = if ($prefix == '' AND $CI->config->item('cookie_prefix') != '') { - $CI->config->item('cookie_prefix'); + $prefix = $CI->config->item('cookie_prefix'); } if ($domain == '' AND $CI->config->item('cookie_domain') != '') { - $CI->config->item('cookie_domain'); + $domain = $CI->config->item('cookie_domain'); } - if ($prefix == '/' AND $CI->config->item('cookie_path') != '/') + if ($path == '/' AND $CI->config->item('cookie_path') != '/') { - $CI->config->item('cookie_path'); + $path = $CI->config->item('cookie_path'); } if ( ! is_numeric($expire)) -- cgit v1.2.3-24-g4f1b From 30b40153739419d50c64e2dce338166a5c58ab58 Mon Sep 17 00:00:00 2001 From: Rick Ellis Date: Fri, 20 Jul 2007 00:01:13 +0000 Subject: --- system/codeigniter/CodeIgniter.php | 4 +- system/libraries/Output.php | 4 +- system/libraries/Router.php | 247 ++++--------------------------------- system/libraries/URI.php | 244 ++++++++++++++++++++++++++++++++++-- system/libraries/Xmlrpc.php | 1 - 5 files changed, 264 insertions(+), 236 deletions(-) (limited to 'system') diff --git a/system/codeigniter/CodeIgniter.php b/system/codeigniter/CodeIgniter.php index 1cd66a187..160d86c8e 100644 --- a/system/codeigniter/CodeIgniter.php +++ b/system/codeigniter/CodeIgniter.php @@ -77,6 +77,7 @@ $EXT->_call_hook('pre_system'); */ $CFG =& load_class('Config'); +$URI =& load_class('URI'); $RTR =& load_class('Router'); $OUT =& load_class('Output'); @@ -101,7 +102,6 @@ if ($EXT->_call_hook('cache_override') === FALSE) */ $IN =& load_class('Input'); -$URI =& load_class('URI'); $LANG =& load_class('Language'); /* @@ -213,7 +213,7 @@ else // 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($RTR->rsegments, (($RTR->fetch_directory() == '') ? 2 : 3))); + call_user_func_array(array(&$CI, $method), array_slice($URI->rsegments, (($RTR->fetch_directory() == '') ? 2 : 3))); } } diff --git a/system/libraries/Output.php b/system/libraries/Output.php index 756d4b4cc..53003f180 100644 --- a/system/libraries/Output.php +++ b/system/libraries/Output.php @@ -301,7 +301,7 @@ class CI_Output { function _display_cache(&$CFG, &$RTR) { $CFG =& load_class('Config'); - $RTR =& load_class('Router'); + $URI =& load_class('URI'); $cache_path = ($CFG->item('cache_path') == '') ? BASEPATH.'cache/' : $CFG->item('cache_path'); @@ -313,7 +313,7 @@ class CI_Output { // Build the file path. The file name is an MD5 hash of the full URI $uri = $CFG->item('base_url'). $CFG->item('index_page'). - $RTR->uri_string; + $URI->uri_string; $filepath = $cache_path.md5($uri); diff --git a/system/libraries/Router.php b/system/libraries/Router.php index 6af6ad380..6fca45227 100644 --- a/system/libraries/Router.php +++ b/system/libraries/Router.php @@ -28,10 +28,7 @@ */ class CI_Router { - var $config; - var $uri_string = ''; - var $segments = array(); - var $rsegments = array(); + var $config; var $routes = array(); var $error_routes = array(); var $class = ''; @@ -49,7 +46,8 @@ class CI_Router { function CI_Router() { $this->config =& load_class('Config'); - $this->_set_route_mapping(); + $this->uri =& load_class('URI'); + $this->_set_routing(); log_message('debug', "Router Class Initialized"); } @@ -64,17 +62,17 @@ class CI_Router { * @access private * @return void */ - function _set_route_mapping() + function _set_routing() { // Are query strings enabled in the config file? // If so, we're done since segment based URIs are not used with query strings. if ($this->config->item('enable_query_strings') === TRUE AND isset($_GET[$this->config->item('controller_trigger')])) { - $this->set_class(trim($this->_filter_uri($_GET[$this->config->item('controller_trigger')]))); + $this->set_class(trim($this->uri->_filter_uri($_GET[$this->config->item('controller_trigger')]))); if (isset($_GET[$this->config->item('function_trigger')])) { - $this->set_method(trim($this->_filter_uri($_GET[$this->config->item('function_trigger')]))); + $this->set_method(trim($this->uri->_filter_uri($_GET[$this->config->item('function_trigger')]))); } return; @@ -90,16 +88,10 @@ class CI_Router { $this->default_controller = ( ! isset($this->routes['default_controller']) OR $this->routes['default_controller'] == '') ? FALSE : strtolower($this->routes['default_controller']); // Fetch the complete URI string - $this->uri_string = $this->_get_uri_string(); - - // If the URI contains only a slash we'll kill it - if ($this->uri_string == '/') - { - $this->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_string == '') + if ($this->uri->uri_string == '') { if ($this->default_controller === FALSE) { @@ -114,47 +106,35 @@ class CI_Router { } unset($this->routes['default_controller']); - // Do we need to remove the suffix specified in the config file? - if ($this->config->item('url_suffix') != "") - { - $this->uri_string = preg_replace("|".preg_quote($this->config->item('url_suffix'))."$|", "", $this->uri_string); - } + // Do we need to remove the URL suffix? + $this->uri->_remove_url_suffix(); - // Explode the URI Segments. The individual segments will - // be stored in the $this->segments array. - 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; - } + // 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->_reindex_segments(); + $this->uri->_reindex_segments(); } // -------------------------------------------------------------------- /** - * Compile Segments + * Set the Route * * This function takes an array of URI segments as - * input, and puts it into the $this->segments array. - * It also sets the current class/method + * input, and sets the current class/method * * @access private * @param array * @param bool * @return void */ - function _compile_segments($segments = array()) + function _set_request($segments = array()) { - $segments = $this->_validate_segments($segments); + $segments = $this->_validate_request($segments); if (count($segments) == 0) { @@ -180,8 +160,8 @@ class CI_Router { // Update our "routed" segment array to contain the segments. // Note: If there is no custom routing, this array will be - // identical to $this->segments - $this->rsegments = $segments; + // identical to $this->uri->segments + $this->uri->rsegments = $segments; } // -------------------------------------------------------------------- @@ -194,7 +174,7 @@ class CI_Router { * @param array * @return array */ - function _validate_segments($segments) + function _validate_request($segments) { // Does the requested controller exist in the root folder? if (file_exists(APPPATH.'controllers/'.$segments[0].EXT)) @@ -237,182 +217,7 @@ class CI_Router { // Can't find the requested controller... show_404(); } - - // -------------------------------------------------------------------- - /** - * Re-index Segments - * - * This function re-indexes the $this->segment array so that it - * starts at 1 rather then 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() - { - // Is the routed segment array different then the main segment array? - $diff = (count(array_diff($this->rsegments, $this->segments)) == 0) ? FALSE : TRUE; - - $i = 1; - foreach ($this->segments as $val) - { - $this->segments[$i++] = $val; - } - unset($this->segments[0]); - if ($diff == FALSE) - { - $this->rsegments = $this->segments; - } - else - { - $i = 1; - foreach ($this->rsegments as $val) - { - $this->rsegments[$i++] = $val; - } - unset($this->rsegments[0]); - } - } - - // -------------------------------------------------------------------- - - /** - * Get the URI String - * - * @access private - * @return string - */ - function _get_uri_string() - { - if (strtoupper($this->config->item('uri_protocol')) == 'AUTO') - { - // If the URL has a question mark then it's simplest to just - // build the URI string from the zero index of the $_GET array. - // This avoids having to deal with $_SERVER variables, which - // can be unreliable in some environments - if (is_array($_GET) AND count($_GET) == 1) - { - // Note: Due to a bug in current() that affects some versions - // of PHP we can not pass function call directly into it - $keys = array_keys($_GET); - return current($keys); - } - - // 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 ($path != '' AND $path != "/".SELF) - { - return $path; - } - - // No PATH_INFO?... What about QUERY_STRING? - $path = (isset($_SERVER['QUERY_STRING'])) ? $_SERVER['QUERY_STRING'] : @getenv('QUERY_STRING'); - if ($path != '') - { - return $path; - } - - // No QUERY_STRING?... Maybe the ORIG_PATH_INFO variable exists? - $path = (isset($_SERVER['ORIG_PATH_INFO'])) ? $_SERVER['ORIG_PATH_INFO'] : @getenv('ORIG_PATH_INFO'); - if ($path != '' AND $path != "/".SELF) - { - return $path; - } - - // We've exhausted all our options... - return ''; - } - else - { - $uri = strtoupper($this->config->item('uri_protocol')); - - if ($uri == 'REQUEST_URI') - { - return $this->_parse_request_uri(); - } - - return (isset($_SERVER[$uri])) ? $_SERVER[$uri] : @getenv($uri); - } - } - - // -------------------------------------------------------------------- - - /** - * Parse the REQUEST_URI - * - * Due to the way REQUEST_URI works it usually contains path info - * that makes it unusable as URI data. We'll trim off the unnecessary - * data, hopefully arriving at a valid URI that we can use. - * - * @access private - * @return string - */ - function _parse_request_uri() - { - if ( ! isset($_SERVER['REQUEST_URI']) OR $_SERVER['REQUEST_URI'] == '') - { - return ''; - } - - $request_uri = preg_replace("|/(.*)|", "\\1", str_replace("\\", "/", $_SERVER['REQUEST_URI'])); - - if ($request_uri == '' OR $request_uri == SELF) - { - return ''; - } - - $fc_path = FCPATH; - if (strpos($request_uri, '?') !== FALSE) - { - $fc_path .= '?'; - } - - $parsed_uri = explode("/", $request_uri); - - $i = 0; - foreach(explode("/", $fc_path) as $segment) - { - if (isset($parsed_uri[$i]) AND $segment == $parsed_uri[$i]) - { - $i++; - } - } - - $parsed_uri = implode("/", array_slice($parsed_uri, $i)); - - if ($parsed_uri != '') - { - $parsed_uri = '/'.$parsed_uri; - } - - return $parsed_uri; - } - - // -------------------------------------------------------------------- - - /** - * Filter segments for malicious characters - * - * @access private - * @param string - * @return string - */ - function _filter_uri($str) - { - if ($this->config->item('permitted_uri_chars') != '') - { - if ( ! preg_match("|^[".preg_quote($this->config->item('permitted_uri_chars'))."]+$|i", $str)) - { - exit('The URI you submitted has disallowed characters.'); - } - } - return $str; - } - // -------------------------------------------------------------------- /** @@ -431,18 +236,18 @@ class CI_Router { // There is a default scaffolding trigger, so we'll look just for 1 if (count($this->routes) == 1) { - $this->_compile_segments($this->segments); + $this->_set_request($this->uri->segments); return; } // Turn the segment array into a URI string - $uri = implode('/', $this->segments); - $num = count($this->segments); + $uri = implode('/', $this->uri->segments); + $num = count($this->uri->segments); // Is there a literal match? If so we're done if (isset($this->routes[$uri])) { - $this->_compile_segments(explode('/', $this->routes[$uri])); + $this->_set_request(explode('/', $this->routes[$uri])); return; } @@ -461,14 +266,14 @@ class CI_Router { $val = preg_replace('#^'.$key.'$#', $val, $uri); } - $this->_compile_segments(explode('/', $val)); + $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->_compile_segments($this->segments); + $this->_set_request($this->uri->segments); } // -------------------------------------------------------------------- diff --git a/system/libraries/URI.php b/system/libraries/URI.php index 5cedd8e0f..2777e2f18 100644 --- a/system/libraries/URI.php +++ b/system/libraries/URI.php @@ -28,8 +28,10 @@ */ class CI_URI { - var $router; var $keyval = array(); + var $uri_string; + var $segments = array(); + var $rsegments = array(); /** * Constructor @@ -42,10 +44,229 @@ class CI_URI { */ function CI_URI() { - $this->router =& load_class('Router'); + $this->config =& load_class('Config'); 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') + { + // If the URL has a question mark then it's simplest to just + // build the URI string from the zero index of the $_GET array. + // This avoids having to deal with $_SERVER variables, which + // can be unreliable in some environments + if (is_array($_GET) AND count($_GET) == 1) + { + // Note: Due to a bug in current() that affects some versions + // of PHP we can not pass function call directly into it + $keys = array_keys($_GET); + $this->uri_string = current($keys); + } + + // 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 ($path != '' AND $path != "/".SELF) + { + $this->uri_string = $path; + } + + // No PATH_INFO?... What about QUERY_STRING? + $path = (isset($_SERVER['QUERY_STRING'])) ? $_SERVER['QUERY_STRING'] : @getenv('QUERY_STRING'); + if ($path != '') + { + $this->uri_string = $path; + } + + // No QUERY_STRING?... Maybe the ORIG_PATH_INFO variable exists? + $path = (isset($_SERVER['ORIG_PATH_INFO'])) ? $_SERVER['ORIG_PATH_INFO'] : @getenv('ORIG_PATH_INFO'); + if ($path != '' AND $path != "/".SELF) + { + $this->uri_string = $path; + } + + // We've exhausted all our options... + $this->uri_string = ''; + } + else + { + $uri = strtoupper($this->config->item('uri_protocol')); + + if ($uri == 'REQUEST_URI') + { + $this->uri_string = $this->_parse_request_uri(); + } + + $this->uri_string = (isset($_SERVER[$uri])) ? $_SERVER[$uri] : @getenv($uri); + } + + // If the URI contains only a slash we'll kill it + if ($this->uri_string == '/') + { + $this->uri_string = ''; + } + } + + // -------------------------------------------------------------------- + + /** + * Parse the REQUEST_URI + * + * Due to the way REQUEST_URI works it usually contains path info + * that makes it unusable as URI data. We'll trim off the unnecessary + * data, hopefully arriving at a valid URI that we can use. + * + * @access private + * @return string + */ + function _parse_request_uri() + { + if ( ! isset($_SERVER['REQUEST_URI']) OR $_SERVER['REQUEST_URI'] == '') + { + return ''; + } + + $request_uri = preg_replace("|/(.*)|", "\\1", str_replace("\\", "/", $_SERVER['REQUEST_URI'])); + + if ($request_uri == '' OR $request_uri == SELF) + { + return ''; + } + + $fc_path = FCPATH; + if (strpos($request_uri, '?') !== FALSE) + { + $fc_path .= '?'; + } + + $parsed_uri = explode("/", $request_uri); + + $i = 0; + foreach(explode("/", $fc_path) as $segment) + { + if (isset($parsed_uri[$i]) AND $segment == $parsed_uri[$i]) + { + $i++; + } + } + + $parsed_uri = implode("/", array_slice($parsed_uri, $i)); + + if ($parsed_uri != '') + { + $parsed_uri = '/'.$parsed_uri; + } + + return $parsed_uri; + } + + // -------------------------------------------------------------------- + + /** + * Filter segments for malicious characters + * + * @access private + * @param string + * @return string + */ + function _filter_uri($str) + { + if ($this->config->item('permitted_uri_chars') != '') + { + if ( ! preg_match("|^[".preg_quote($this->config->item('permitted_uri_chars'))."]+$|i", $str)) + { + exit('The URI you submitted has disallowed characters.'); + } + } + return $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 then 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() + { + // Is the routed segment array different then the main segment array? + $diff = (count(array_diff($this->rsegments, $this->segments)) == 0) ? FALSE : TRUE; + + $i = 1; + foreach ($this->segments as $val) + { + $this->segments[$i++] = $val; + } + unset($this->segments[0]); + + if ($diff == FALSE) + { + $this->rsegments = $this->segments; + } + else + { + $i = 1; + foreach ($this->rsegments as $val) + { + $this->rsegments[$i++] = $val; + } + unset($this->rsegments[0]); + } + } + // -------------------------------------------------------------------- /** @@ -60,7 +281,7 @@ class CI_URI { */ function segment($n, $no_result = FALSE) { - return ( ! isset($this->router->segments[$n])) ? $no_result : $this->router->segments[$n]; + return ( ! isset($this->segments[$n])) ? $no_result : $this->segments[$n]; } // -------------------------------------------------------------------- @@ -79,7 +300,7 @@ class CI_URI { */ function rsegment($n, $no_result = FALSE) { - return ( ! isset($this->router->rsegments[$n])) ? $no_result : $this->router->rsegments[$n]; + return ( ! isset($this->rsegments[$n])) ? $no_result : $this->rsegments[$n]; } // -------------------------------------------------------------------- @@ -203,6 +424,8 @@ class CI_URI { return $retval; } + // -------------------------------------------------------------------- + /** * Generate a URI string from an associative array * @@ -210,7 +433,8 @@ class CI_URI { * @access public * @param array an associative array of key/values * @return array - */ function assoc_to_uri($array) + */ + function assoc_to_uri($array) { $temp = array(); foreach ((array)$array as $key => $val) @@ -293,7 +517,7 @@ class CI_URI { */ function segment_array() { - return $this->router->segments; + return $this->segments; } // -------------------------------------------------------------------- @@ -306,7 +530,7 @@ class CI_URI { */ function rsegment_array() { - return $this->router->rsegments; + return $this->rsegments; } // -------------------------------------------------------------------- @@ -319,7 +543,7 @@ class CI_URI { */ function total_segments() { - return count($this->router->segments); + return count($this->segments); } // -------------------------------------------------------------------- @@ -332,7 +556,7 @@ class CI_URI { */ function total_rsegments() { - return count($this->router->rsegments); + return count($this->rsegments); } // -------------------------------------------------------------------- @@ -345,7 +569,7 @@ class CI_URI { */ function uri_string() { - return $this->router->uri_string; + return $this->uri_string; } diff --git a/system/libraries/Xmlrpc.php b/system/libraries/Xmlrpc.php index 49747e481..fc6208e94 100644 --- a/system/libraries/Xmlrpc.php +++ b/system/libraries/Xmlrpc.php @@ -70,7 +70,6 @@ class CI_Xmlrpc { function CI_Xmlrpc ($config = array()) { - $this->xmlrpcName = $this->xmlrpcName; $this->xmlrpc_backslash = chr(92).chr(92); -- cgit v1.2.3-24-g4f1b From 6a47c119215219813f6c53b854f104d9fa16f62c Mon Sep 17 00:00:00 2001 From: Rick Ellis Date: Sat, 21 Jul 2007 17:42:35 +0000 Subject: --- system/codeigniter/CodeIgniter.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'system') diff --git a/system/codeigniter/CodeIgniter.php b/system/codeigniter/CodeIgniter.php index 160d86c8e..b5f21a1b7 100644 --- a/system/codeigniter/CodeIgniter.php +++ b/system/codeigniter/CodeIgniter.php @@ -132,11 +132,13 @@ load_class('Controller', FALSE); // Load the local application controller // Note: The Router class automatically validates the controller path. If this include fails it // means that the default controller in the Routes.php file is not resolving to something valid. -if ( ! include(APPPATH.'controllers/'.$RTR->fetch_directory().$RTR->fetch_class().EXT)) +if ( ! file_exists(APPPATH.'controllers/'.$RTR->fetch_directory().$RTR->fetch_class().EXT)) { 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().EXT); + // Set a mark point for benchmarking $BM->mark('loading_time_base_classes_end'); -- cgit v1.2.3-24-g4f1b From de2623c7a748e2e40ce4f6d64161915ed5141c4e Mon Sep 17 00:00:00 2001 From: Rick Ellis Date: Sat, 21 Jul 2007 18:28:24 +0000 Subject: --- system/libraries/URI.php | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) (limited to 'system') diff --git a/system/libraries/URI.php b/system/libraries/URI.php index 2777e2f18..254a8a6e9 100644 --- a/system/libraries/URI.php +++ b/system/libraries/URI.php @@ -58,7 +58,7 @@ class CI_URI { * @return string */ function _fetch_uri_string() - { + { if (strtoupper($this->config->item('uri_protocol')) == 'AUTO') { // If the URL has a question mark then it's simplest to just @@ -71,6 +71,7 @@ class CI_URI { // of PHP we can not pass function call directly into it $keys = array_keys($_GET); $this->uri_string = current($keys); + return; } // Is there a PATH_INFO variable? @@ -79,6 +80,7 @@ class CI_URI { if ($path != '' AND $path != "/".SELF) { $this->uri_string = $path; + return; } // No PATH_INFO?... What about QUERY_STRING? @@ -86,6 +88,7 @@ class CI_URI { if ($path != '') { $this->uri_string = $path; + return; } // No QUERY_STRING?... Maybe the ORIG_PATH_INFO variable exists? @@ -93,6 +96,7 @@ class CI_URI { if ($path != '' AND $path != "/".SELF) { $this->uri_string = $path; + return; } // We've exhausted all our options... @@ -105,6 +109,7 @@ class CI_URI { if ($uri == 'REQUEST_URI') { $this->uri_string = $this->_parse_request_uri(); + return; } $this->uri_string = (isset($_SERVER[$uri])) ? $_SERVER[$uri] : @getenv($uri); @@ -116,7 +121,7 @@ class CI_URI { $this->uri_string = ''; } } - + // -------------------------------------------------------------------- /** -- cgit v1.2.3-24-g4f1b From 183fe844a99da30c4bc2b4b8d881f6b94310dbc5 Mon Sep 17 00:00:00 2001 From: Rick Ellis Date: Sun, 22 Jul 2007 02:09:13 +0000 Subject: --- system/libraries/Router.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system') diff --git a/system/libraries/Router.php b/system/libraries/Router.php index 6fca45227..501a8ee82 100644 --- a/system/libraries/Router.php +++ b/system/libraries/Router.php @@ -252,7 +252,7 @@ class CI_Router { } // Loop through the route array looking for wild-cards - foreach (array_slice($this->routes, 1) as $key => $val) + foreach ($this->routes as $key => $val) { // Convert wild-cards to RegEx $key = str_replace(':any', '.+', str_replace(':num', '[0-9]+', $key)); -- cgit v1.2.3-24-g4f1b From e0a4cc035b39622a035d5de2c4ea69655d3aaae6 Mon Sep 17 00:00:00 2001 From: Rick Ellis Date: Sun, 22 Jul 2007 18:14:32 +0000 Subject: --- system/codeigniter/CodeIgniter.php | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'system') diff --git a/system/codeigniter/CodeIgniter.php b/system/codeigniter/CodeIgniter.php index b5f21a1b7..16fe97ac3 100644 --- a/system/codeigniter/CodeIgniter.php +++ b/system/codeigniter/CodeIgniter.php @@ -181,8 +181,10 @@ $EXT->_call_hook('pre_controller'); // Mark a start point so we can benchmark the controller $BM->mark('controller_execution_time_( '.$class.' / '.$method.' )_start'); -// Instantiate the Controller -$CI = new $class(); +// Instantiate the Controller and pass any global data that might exist +$global_data = ( ! isset($global_data)) ? NULL : $global_data; + +$CI = new $class($global_data); // Is this a scaffolding request? if ($RTR->scaffolding_request === TRUE) -- cgit v1.2.3-24-g4f1b From f66c71b114653f3a2a418950b258a45428871410 Mon Sep 17 00:00:00 2001 From: Rick Ellis Date: Sun, 22 Jul 2007 18:22:56 +0000 Subject: --- system/codeigniter/CodeIgniter.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'system') diff --git a/system/codeigniter/CodeIgniter.php b/system/codeigniter/CodeIgniter.php index 16fe97ac3..54f37c922 100644 --- a/system/codeigniter/CodeIgniter.php +++ b/system/codeigniter/CodeIgniter.php @@ -182,9 +182,9 @@ $EXT->_call_hook('pre_controller'); $BM->mark('controller_execution_time_( '.$class.' / '.$method.' )_start'); // Instantiate the Controller and pass any global data that might exist -$global_data = ( ! isset($global_data)) ? NULL : $global_data; +$assign_to_controller = ( ! isset($assign_to_controller)) ? NULL : $assign_to_controller; -$CI = new $class($global_data); +$CI = new $class($assign_to_controller); // Is this a scaffolding request? if ($RTR->scaffolding_request === TRUE) -- cgit v1.2.3-24-g4f1b From d8de26ea04a83d5d138e8771c69ae790b4cc6a78 Mon Sep 17 00:00:00 2001 From: Rick Ellis Date: Sun, 22 Jul 2007 18:24:25 +0000 Subject: --- system/codeigniter/CodeIgniter.php | 2 ++ 1 file changed, 2 insertions(+) (limited to 'system') diff --git a/system/codeigniter/CodeIgniter.php b/system/codeigniter/CodeIgniter.php index 54f37c922..00032fa02 100644 --- a/system/codeigniter/CodeIgniter.php +++ b/system/codeigniter/CodeIgniter.php @@ -186,6 +186,8 @@ $assign_to_controller = ( ! isset($assign_to_controller)) ? NULL : $assign_to_co $CI = new $class($assign_to_controller); +unset($assign_to_controller); + // Is this a scaffolding request? if ($RTR->scaffolding_request === TRUE) { -- cgit v1.2.3-24-g4f1b From 5fbffd780bb24c0fb925ffb26a9036f008d9b664 Mon Sep 17 00:00:00 2001 From: Rick Ellis Date: Wed, 25 Jul 2007 18:47:11 +0000 Subject: --- system/libraries/URI.php | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'system') diff --git a/system/libraries/URI.php b/system/libraries/URI.php index 254a8a6e9..e3cf9c55b 100644 --- a/system/libraries/URI.php +++ b/system/libraries/URI.php @@ -69,8 +69,9 @@ class CI_URI { { // Note: Due to a bug in current() that affects some versions // of PHP we can not pass function call directly into it - $keys = array_keys($_GET); - $this->uri_string = current($keys); + $key = array_keys($_GET); + $index = current($key); + $this->uri_string = $_GET[$index]; return; } -- cgit v1.2.3-24-g4f1b From c2ce7dfa7e16b2eac7e6c0e6ddaef9cb5e2a6952 Mon Sep 17 00:00:00 2001 From: Derek Allard Date: Mon, 30 Jul 2007 12:13:26 +0000 Subject: changed so day and month names are derived from calendar lang file instead of being hard-coded. --- system/plugins/js_calendar_pi.php | 37 ++++++++++++++++++++++++++++++------- 1 file changed, 30 insertions(+), 7 deletions(-) (limited to 'system') diff --git a/system/plugins/js_calendar_pi.php b/system/plugins/js_calendar_pi.php index a461e34a7..686dcdf76 100644 --- a/system/plugins/js_calendar_pi.php +++ b/system/plugins/js_calendar_pi.php @@ -30,10 +30,10 @@ The above function will be passed the name of your form. Then to show the actual calendar you'll do this: - +
    -

    Today

    +

    Today

    @@ -126,15 +126,37 @@ Lastly, you'll need some CSS for your calendar: function js_calendar_script($form_name = 'entryform') { - +$CI =& get_instance(); +$CI->load->language('calendar'); ob_start(); ?> '), + array('phptagopen', 'phptagclose', 'asptagopen', 'asptagclose', 'backslashtmp', 'scriptclose'), $str); + // The highlight_string function requires that the text be surrounded // by PHP tags. Since we don't know if A) the submitted text has PHP tags, // or B) whether the PHP tags enclose the entire string, we will add our @@ -279,14 +280,16 @@ function highlight_code($str) $str = preg_replace('#color="(.*?)"#', 'style="color: \\1"', $str); } - // Remove our artificially added PHP + // Remove our artificially added PHP and the empty span that results from our temp markers $str = preg_replace("#\.+?//tempstart\
    \#is", "\n", $str); $str = preg_replace("#\.+?//tempstart\
    #is", "\n", $str); $str = preg_replace("#//tempend.+#is", "\n", $str); + $str = preg_replace("#\\n
    #is", "\n
    ", $str); // Replace our markers back to PHP tags. - $str = str_replace(array('phptagopen', 'phptagclose', 'backslashtmp'), array('<?php', '?>', '\\'), $str); // Date: Tue, 22 Jan 2008 19:40:05 +0000 Subject: modifications to numeric and integer validation --- system/libraries/Validation.php | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'system') diff --git a/system/libraries/Validation.php b/system/libraries/Validation.php index dc4e016bc..a3ce9808b 100644 --- a/system/libraries/Validation.php +++ b/system/libraries/Validation.php @@ -552,7 +552,8 @@ class CI_Validation { */ function numeric($str) { - return ( ! is_numeric($str)) ? FALSE : TRUE; + return (bool)preg_match( '/^[\-+]?[0-9]*\.?[0-9]+$/', $str); + } // -------------------------------------------------------------------- @@ -566,7 +567,7 @@ class CI_Validation { */ function integer($str) { - return ( ! is_int($str)) ? FALSE : TRUE; + return (bool)preg_match( '/^[\-+]?[0-9]+$/', $str); } // -------------------------------------------------------------------- -- cgit v1.2.3-24-g4f1b From 22cd38b2752cff83a07a12ff0662c3c841933e53 Mon Sep 17 00:00:00 2001 From: Derek Allard Date: Tue, 22 Jan 2008 19:45:03 +0000 Subject: changed a code comment param int to param string --- system/libraries/Validation.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system') diff --git a/system/libraries/Validation.php b/system/libraries/Validation.php index a3ce9808b..08397ecb8 100644 --- a/system/libraries/Validation.php +++ b/system/libraries/Validation.php @@ -547,7 +547,7 @@ class CI_Validation { * Numeric * * @access public - * @param int + * @param string * @return bool */ function numeric($str) -- cgit v1.2.3-24-g4f1b From 1487f8c96493cac4aa8fb440fb829e20231a6053 Mon Sep 17 00:00:00 2001 From: Derek Allard Date: Tue, 22 Jan 2008 19:46:36 +0000 Subject: added a language key for the integer validation rule --- system/language/english/validation_lang.php | 1 + 1 file changed, 1 insertion(+) (limited to 'system') diff --git a/system/language/english/validation_lang.php b/system/language/english/validation_lang.php index 1ca67c0fb..1e9ec2c1b 100644 --- a/system/language/english/validation_lang.php +++ b/system/language/english/validation_lang.php @@ -12,6 +12,7 @@ $lang['alpha'] = "The %s field may only contain alphabetical characters."; $lang['alpha_numeric'] = "The %s field may only contain alpha-numeric characters."; $lang['alpha_dash'] = "The %s field may only contain alpha-numeric characters, underscores, and dashes."; $lang['numeric'] = "The %s field must contain a number."; +$lang['integer'] = "The %s field must contain an integer."; $lang['matches'] = "The %s field does not match the %s field."; ?> \ No newline at end of file -- cgit v1.2.3-24-g4f1b From e352549535beda0ba2be97a437c694d9f794fd4b Mon Sep 17 00:00:00 2001 From: Derek Jones Date: Tue, 22 Jan 2008 19:51:03 +0000 Subject: modified markers in highlight_code() to not introduce unintended highlighting, and to allow code where the first line is a code comment to be styled properly --- system/helpers/text_helper.php | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) (limited to 'system') diff --git a/system/helpers/text_helper.php b/system/helpers/text_helper.php index 8b671140d..2a42cba7e 100644 --- a/system/helpers/text_helper.php +++ b/system/helpers/text_helper.php @@ -267,7 +267,7 @@ function highlight_code($str) // or B) whether the PHP tags enclose the entire string, we will add our // own PHP tags around the string along with some markers to make replacement easier later - $str = ''; + $str = ''; // All the magic happens here, baby! $str = highlight_string($str, TRUE); @@ -281,10 +281,9 @@ function highlight_code($str) } // Remove our artificially added PHP and the empty span that results from our temp markers - $str = preg_replace("#\.+?//tempstart\
    \#is", "\n", $str); - $str = preg_replace("#\.+?//tempstart\
    #is", "\n", $str); - $str = preg_replace("#//tempend.+#is", "\n", $str); - $str = preg_replace("#\\n
    #is", "\n", $str); + $str = preg_replace("#\.+?tempstart\
    \#is", "\n", $str); + $str = preg_replace("#\.+?tempstart\
    #is", "\n", $str); + $str = preg_replace("#tempend.+#is", "\n", $str); // Replace our markers back to PHP tags. $str = str_replace(array('phptagopen', 'phptagclose', 'asptagopen', 'asptagclose', 'backslashtmp', 'scriptclose'), -- cgit v1.2.3-24-g4f1b From 9cee79136d2b197584bc6e076e7df5d69344be1c Mon Sep 17 00:00:00 2001 From: Derek Jones Date: Tue, 22 Jan 2008 20:12:47 +0000 Subject: further refinement to highlight_code()'s regex replacements --- system/helpers/text_helper.php | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) (limited to 'system') diff --git a/system/helpers/text_helper.php b/system/helpers/text_helper.php index 2a42cba7e..20bf32335 100644 --- a/system/helpers/text_helper.php +++ b/system/helpers/text_helper.php @@ -280,9 +280,8 @@ function highlight_code($str) $str = preg_replace('#color="(.*?)"#', 'style="color: \\1"', $str); } - // Remove our artificially added PHP and the empty span that results from our temp markers - $str = preg_replace("#\.+?tempstart\
    \#is", "\n", $str); - $str = preg_replace("#\.+?tempstart\
    #is", "\n", $str); + // Remove our artificially added PHP + $str = preg_replace("#\.+?tempstart\
    (?:\)?#is", "\n", $str); $str = preg_replace("#tempend.+#is", "\n", $str); // Replace our markers back to PHP tags. -- cgit v1.2.3-24-g4f1b From 77fee9affdd28c647759965aec20028aeb1d8798 Mon Sep 17 00:00:00 2001 From: Derek Jones Date: Tue, 22 Jan 2008 21:09:26 +0000 Subject: removed extraneous load of $CFG in _display_cache() --- system/libraries/Output.php | 1 - 1 file changed, 1 deletion(-) (limited to 'system') diff --git a/system/libraries/Output.php b/system/libraries/Output.php index ed9f6f4ff..f98dab5e0 100644 --- a/system/libraries/Output.php +++ b/system/libraries/Output.php @@ -323,7 +323,6 @@ class CI_Output { */ function _display_cache(&$CFG, &$RTR) { - $CFG =& load_class('Config'); $URI =& load_class('URI'); $cache_path = ($CFG->item('cache_path') == '') ? BASEPATH.'cache/' : $CFG->item('cache_path'); -- cgit v1.2.3-24-g4f1b From 2e061440560701f68dd2d65d8d56355f4bdfe6f4 Mon Sep 17 00:00:00 2001 From: Derek Jones Date: Tue, 22 Jan 2008 21:13:12 +0000 Subject: added enclosures to csv_from _result() --- system/database/DB_utility.php | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) (limited to 'system') diff --git a/system/database/DB_utility.php b/system/database/DB_utility.php index 9b78aa8ec..d9b8fed74 100644 --- a/system/database/DB_utility.php +++ b/system/database/DB_utility.php @@ -168,11 +168,12 @@ class CI_DB_utility extends CI_DB_forge { * * @access public * @param object The query result object - * @param string The delimiter - tab by default + * @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 = "\t", $newline = "\n") + function csv_from_result($query, $delim = ",", $newline = "\n", $enclosure = '"') { if ( ! is_object($query) OR ! method_exists($query, 'field_names')) { @@ -184,7 +185,7 @@ class CI_DB_utility extends CI_DB_forge { // First generate the headings from the table column names foreach ($query->list_fields() as $name) { - $out .= $name.$delim; + $out .= $enclosure.str_replace($enclosure, $enclosure.$enclosure, $name).$enclosure.$delim; } $out = rtrim($out); @@ -195,7 +196,7 @@ class CI_DB_utility extends CI_DB_forge { { foreach ($row as $item) { - $out .= $item.$delim; + $out .= $enclosure.str_replace($enclosure, $enclosure.$enclosure, $item).$enclosure.$delim; } $out = rtrim($out); $out .= $newline; -- cgit v1.2.3-24-g4f1b From 9279062a19bef980b1f034716c5dc483eccb3cf5 Mon Sep 17 00:00:00 2001 From: paulburdick Date: Tue, 22 Jan 2008 23:33:33 +0000 Subject: Fixed a bug in the XML-RPC library so that if not type is specified, a more intelligent decision is made as to the default type Also fixed a few formatting problems and updated the eregi() to preg_match() and strncmp(). --- system/libraries/Xmlrpc.php | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) (limited to 'system') diff --git a/system/libraries/Xmlrpc.php b/system/libraries/Xmlrpc.php index 9eb329346..91e3809a8 100644 --- a/system/libraries/Xmlrpc.php +++ b/system/libraries/Xmlrpc.php @@ -231,7 +231,14 @@ class CI_Xmlrpc { { if ( ! isset($value['1']) OR ! isset($this->xmlrpcTypes[strtolower($value['1'])])) { - $temp = new XML_RPC_Values($value['0'], 'string'); + if (is_array($value[0])) + { + $temp = new XML_RPC_Values($value['0'], 'array'); + } + else + { + $temp = new XML_RPC_Values($value['0'], 'string'); + } } elseif(is_array($value['0']) && ($value['1'] == 'struct' OR $value['1'] == 'array')) { @@ -337,7 +344,7 @@ class CI_Xmlrpc { * XML-RPC Client class * * @category XML-RPC - * @author ExpressionEngine Dev Team + * @author ExpressionEngine Dev Team * @link http://codeigniter.com/user_guide/libraries/xmlrpc.html */ class XML_RPC_Client extends CI_Xmlrpc @@ -492,7 +499,7 @@ class XML_RPC_Response function decode($array=FALSE) { - $CI =& get_instance(); + $CI =& get_instance(); if ($array !== FALSE && is_array($array)) { @@ -577,7 +584,7 @@ class XML_RPC_Response { // return a timet in the localtime, or UTC $t = 0; - if (ereg("([0-9]{4})([0-9]{2})([0-9]{2})T([0-9]{2}):([0-9]{2}):([0-9]{2})", $time, $regs)) + if (preg_match('/([0-9]{4})([0-9]{2})([0-9]{2})T([0-9]{2}):([0-9]{2}):([0-9]{2})/', $time, $regs)) { if ($utc == 1) $t = gmmktime($regs[4], $regs[5], $regs[6], $regs[2], $regs[3], $regs[1]); @@ -680,7 +687,7 @@ class XML_RPC_Message extends CI_Xmlrpc // Check for HTTP 200 Response //------------------------------------- - if(ereg("^HTTP",$data) && !ereg("^HTTP/[0-9\.]+ 200 ", $data)) + if (strncmp($data, 'HTTP', 4) == 0 && ! preg_match('/^HTTP\/[0-9\.]+ 200 /', $data)) { $errstr= substr($data, 0, strpos($data, "\n")-1); $r = new XML_RPC_Response(0, $this->xmlrpcerr['http_error'], $this->xmlrpcstr['http_error']. ' (' . $errstr . ')'); @@ -996,7 +1003,7 @@ class XML_RPC_Message extends CI_Xmlrpc { // we have a DOUBLE // we must check that only 0123456789-. are characters here - if (!ereg("^[+-]?[eE0123456789 \\t\\.]+$", $this->xh[$the_parser]['ac'])) + if (! preg_match('/^[+-]?[eE0-9\t \.]+$/', $this->xh[$the_parser]['ac'])) { $this->xh[$the_parser]['value'] = 'ERROR_NON_NUMERIC_FOUND'; } @@ -1009,7 +1016,7 @@ class XML_RPC_Message extends CI_Xmlrpc { // we have an I4/INT // we must check that only 0123456789- are characters here - if (!ereg("^[+-]?[0123456789 \\t]+$", $this->xh[$the_parser]['ac'])) + if (! preg_match('/^[+-]?[0-9\t ]+$/', $this->xh[$the_parser]['ac'])) { $this->xh[$the_parser]['value'] = 'ERROR_NON_NUMERIC_FOUND'; } @@ -1062,7 +1069,7 @@ class XML_RPC_Message extends CI_Xmlrpc } break; case 'METHODNAME': - $this->xh[$the_parser]['method'] = ereg_replace("^[\n\r\t ]+", '', $this->xh[$the_parser]['ac']); + $this->xh[$the_parser]['method'] = ltrim($this->xh[$the_parser]['ac']); break; case 'PARAMS': case 'FAULT': @@ -1367,7 +1374,6 @@ class XML_RPC_Values extends CI_Xmlrpc function serializeval($o) { - $ar = $o->me; reset($ar); -- cgit v1.2.3-24-g4f1b From c45cf3c14696bbc04b6270a29948682954afecb7 Mon Sep 17 00:00:00 2001 From: paulburdick Date: Tue, 22 Jan 2008 23:35:10 +0000 Subject: *Enabled the default 'system' methods for the XML-RPC Server library, except for 'system.multicall' which is still disabled. --- system/libraries/Xmlrpcs.php | 166 ++++++++++++++++++++++++------------------- 1 file changed, 91 insertions(+), 75 deletions(-) (limited to 'system') diff --git a/system/libraries/Xmlrpcs.php b/system/libraries/Xmlrpcs.php index 59ac58576..ac644d894 100644 --- a/system/libraries/Xmlrpcs.php +++ b/system/libraries/Xmlrpcs.php @@ -53,7 +53,7 @@ class CI_Xmlrpcs extends CI_Xmlrpc if (isset($config['functions']) && is_array($config['functions'])) { - $this->methods = $config['functions']; + $this->methods = array_merge($this->methods, $config['functions']); } log_message('debug', "XML-RPC Server Class Initialized"); @@ -67,7 +67,7 @@ class CI_Xmlrpcs extends CI_Xmlrpc { if (isset($config['functions']) && is_array($config['functions'])) { - $this->methods = $config['functions']; + $this->methods = array_merge($this->methods, $config['functions']); } if (isset($config['debug'])) @@ -82,24 +82,24 @@ class CI_Xmlrpcs extends CI_Xmlrpc function set_system_methods () { - $system_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') - ); + $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') + ); } @@ -150,7 +150,6 @@ class CI_Xmlrpcs extends CI_Xmlrpc $data = $HTTP_RAW_POST_DATA; } - //------------------------------------- // Set up XML Parser //------------------------------------- @@ -189,9 +188,7 @@ class CI_Xmlrpcs extends CI_Xmlrpc } elseif($parser_object->xh[$parser]['isf']) { - return new XML_RPC_Response(0, - $this->xmlrpcerr['invalid_return'], - $this->xmlrpcstr['invalid_return']); + return new XML_RPC_Response(0, $this->xmlrpcerr['invalid_return'], $this->xmlrpcstr['invalid_return']); } else { @@ -241,48 +238,50 @@ class CI_Xmlrpcs extends CI_Xmlrpc $methName = $m->method_name; // Check to see if it is a system call - // If so, load the system_methods - $sysCall = ereg("^system\.", $methName); - $methods = $sysCall ? $this->system_methods : $this->methods; + $system_call = (strncmp($methName, 'system', 5) == 0) ? TRUE : FALSE; //------------------------------------- - // Check for Function + // Valid Method //------------------------------------- - if (!isset($methods[$methName]['function'])) + if ( ! isset($this->methods[$methName]['function'])) { - return new XML_RPC_Response(0, - $this->xmlrpcerr['unknown_method'], - $this->xmlrpcstr['unknown_method']); + 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 { - // See if we are calling function in an object - - $method_parts = explode(".",$methods[$methName]['function']); - $objectCall = (isset($method_parts['1']) && $method_parts['1'] != "") ? true : false; - 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']); + return new XML_RPC_Response(0, $this->xmlrpcerr['unknown_method'], $this->xmlrpcstr['unknown_method']); } - elseif (!$objectCall && !is_callable($methods[$methName]['function'])) + elseif (!$objectCall && !is_callable($this->methods[$methName]['function'])) { - return new XML_RPC_Response(0, - $this->xmlrpcerr['unknown_method'], - $this->xmlrpcstr['unknown_method']); - } + return new XML_RPC_Response(0, $this->xmlrpcerr['unknown_method'], $this->xmlrpcstr['unknown_method']); + } } - + //------------------------------------- // Checking Methods Signature //------------------------------------- - if (isset($methods[$methName]['signature'])) + if (isset($this->methods[$methName]['signature'])) { - $sig = $methods[$methName]['signature']; + $sig = $this->methods[$methName]['signature']; for($i=0; $iparams); $n++) { $p = $m->params[$n]; - $pt = ($p->kindOf() == 'scalar') ? $p->scalartyp() : $p->kindOf(); + $pt = ($p->kindOf() == 'scalar') ? $p->scalarval() : $p->kindOf(); if ($pt != $current_sig[$n+1]) { @@ -313,11 +312,11 @@ class CI_Xmlrpcs extends CI_Xmlrpc // Calls the Function //------------------------------------- - if ($objectCall) + if ($objectCall === TRUE) { - if ($method_parts['1'] == "this") + if ($method_parts[0] == "this" && $system_call == TRUE) { - return call_user_func(array($this, $method_parts['0']), $m); + return call_user_func(array($this, $method_parts[1]), $m); } else { @@ -330,7 +329,7 @@ class CI_Xmlrpcs extends CI_Xmlrpc } else { - return call_user_func($methods[$methName]['function'], $m); + return call_user_func($this->methods[$methName]['function'], $m); } } @@ -343,7 +342,8 @@ class CI_Xmlrpcs extends CI_Xmlrpc { $v = new XML_RPC_Values(); $output = array(); - foreach($this->$methods as $key => $value) + + foreach($this->methods as $key => $value) { $output[] = new XML_RPC_Values($key, 'string'); } @@ -363,17 +363,15 @@ class CI_Xmlrpcs extends CI_Xmlrpc function methodSignature($m) { - $methName = $m->getParam(0); - $method_name = $methName->scalarval(); + $parameters = $m->output_parameters(); + $method_name = $parameters[0]; - $methods = ereg("^system\.", $method_name) ? $this->system_methods : $this->methods; - - if (isset($methods[$method_name])) + if (isset($this->methods[$method_name])) { - if ($methods[$method_name]['signature']) + if ($this->methods[$method_name]['signature']) { $sigs = array(); - $signature = $methods[$method_name]['signature']; + $signature = $this->methods[$method_name]['signature']; for($i=0; $i < sizeof($signature); $i++) { @@ -405,21 +403,19 @@ class CI_Xmlrpcs extends CI_Xmlrpc function methodHelp($m) { - $methName = $m->getParam(0); - $method_name = $methName->scalarval(); - - $methods = ereg("^system\.", $method_name) ? $this->system_methods : $this->methods; + $parameters = $m->output_parameters(); + $method_name = $parameters[0]; - if (isset($methods[$methName])) + if (isset($this->methods[$method_name])) { - $docstring = isset($methods[$method_name]['docstring']) ? $methods[$method_name]['docstring'] : ''; - $r = new XML_RPC_Response(new XML_RPC_Values($docstring, 'string')); + $docstring = isset($this->methods[$method_name]['docstring']) ? $this->methods[$method_name]['docstring'] : ''; + + return new XML_RPC_Response(new XML_RPC_Values($docstring, 'string')); } else { - $r = new XML_RPC_Response(0, $this->xmlrpcerr['introspect_unknown'], $this->xmlrpcstr['introspect_unknown']); + return new XML_RPC_Response(0, $this->xmlrpcerr['introspect_unknown'], $this->xmlrpcstr['introspect_unknown']); } - return $r; } //------------------------------------- @@ -428,14 +424,34 @@ class CI_Xmlrpcs extends CI_Xmlrpc function multicall($m) { - $calls = $m->getParam(0); - list($a,$b)=each($calls->me); + // Disabled + return new XML_RPC_Response(0, $this->xmlrpcerr['unknown_method'], $this->xmlrpcstr['unknown_method']); + + $parameters = $m->output_parameters(); + $calls = $parameters[0]; + $result = array(); - for ($i = 0; $i < sizeof($b); $i++) + foreach ($calls as $value) { - $call = $calls->me['array'][$i]; - $result[$i] = $this->do_multicall($call); + //$attempt = $this->_execute(new XML_RPC_Message($value[0], $value[1])); + + $m = new XML_RPC_Message($value[0]); + $plist=''; + + for($i=0; $i < sizeof($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')); -- cgit v1.2.3-24-g4f1b From 3b11868b3aa56c83419d904435a5b7dfbf997063 Mon Sep 17 00:00:00 2001 From: Derek Allard Date: Tue, 22 Jan 2008 23:44:32 +0000 Subject: Added $this->db->dbprefix() to manually add database prefixes. --- system/database/DB_active_rec.php | 27 ++++++++++++++++++++++++--- 1 file changed, 24 insertions(+), 3 deletions(-) (limited to 'system') diff --git a/system/database/DB_active_rec.php b/system/database/DB_active_rec.php index 08213af5c..ba68e1e8f 100644 --- a/system/database/DB_active_rec.php +++ b/system/database/DB_active_rec.php @@ -7,8 +7,8 @@ * @package CodeIgniter * @author ExpressionEngine Dev Team * @copyright Copyright (c) 2006, EllisLab, Inc. - * @license http://codeigniter.com/user_guide/license.html - * @link http://codeigniter.com + * @license http://www.codeigniter.com/user_guide/license.html + * @link http://www.codeigniter.com * @since Version 1.0 * @filesource */ @@ -24,7 +24,7 @@ * @subpackage Drivers * @category Database * @author ExpressionEngine Dev Team - * @link http://codeigniter.com/user_guide/database/ + * @link http://www.codeigniter.com/user_guide/database/ */ class CI_DB_active_record extends CI_DB_driver { @@ -44,6 +44,27 @@ class CI_DB_active_record extends CI_DB_driver { var $ar_wherein = array(); var $ar_aliased_tables = array(); + /** + * DB Prefix + * + * Prepends a database prefix if one exists in configuration + * + * @access public + * @param string the table + * @return string + */ + function dbprefix($table = '') + { + if ($table == '') + { + $this->display_error('db_table_name_required'); + } + + return $this->dbprefix.$table; + } + + // -------------------------------------------------------------------- + /** * Select * -- cgit v1.2.3-24-g4f1b From d12555b899eb32fc27e021160611251aeeeca49f Mon Sep 17 00:00:00 2001 From: paulburdick Date: Tue, 22 Jan 2008 23:46:17 +0000 Subject: http://codeigniter.com/bug_tracker/bug/3249/ Modification so that a second calling of request() will reset the $this->data array. In the future, it might be prudent to create an initialization() method instead. --- system/libraries/Xmlrpc.php | 2 ++ 1 file changed, 2 insertions(+) (limited to 'system') diff --git a/system/libraries/Xmlrpc.php b/system/libraries/Xmlrpc.php index 91e3809a8..f90ee56b1 100644 --- a/system/libraries/Xmlrpc.php +++ b/system/libraries/Xmlrpc.php @@ -204,6 +204,8 @@ class CI_Xmlrpc { // Send Error } + $this->data = array(); + foreach($incoming as $key => $value) { $this->data[$key] = $this->values_parsing($value); -- cgit v1.2.3-24-g4f1b From cdd2ab25d134c67447e1f1f63c28992f8d0a5b68 Mon Sep 17 00:00:00 2001 From: Derek Allard Date: Wed, 23 Jan 2008 00:05:38 +0000 Subject: fixing www.codeigniter.com to codeigniter.com --- system/database/DB_active_rec.php | 6 +++--- system/libraries/Validation.php | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) (limited to 'system') diff --git a/system/database/DB_active_rec.php b/system/database/DB_active_rec.php index ba68e1e8f..0455b981e 100644 --- a/system/database/DB_active_rec.php +++ b/system/database/DB_active_rec.php @@ -7,8 +7,8 @@ * @package CodeIgniter * @author ExpressionEngine Dev Team * @copyright Copyright (c) 2006, EllisLab, Inc. - * @license http://www.codeigniter.com/user_guide/license.html - * @link http://www.codeigniter.com + * @license http://codeigniter.com/user_guide/license.html + * @link http://codeigniter.com * @since Version 1.0 * @filesource */ @@ -24,7 +24,7 @@ * @subpackage Drivers * @category Database * @author ExpressionEngine Dev Team - * @link http://www.codeigniter.com/user_guide/database/ + * @link http://codeigniter.com/user_guide/database/ */ class CI_DB_active_record extends CI_DB_driver { diff --git a/system/libraries/Validation.php b/system/libraries/Validation.php index 08397ecb8..162d362da 100644 --- a/system/libraries/Validation.php +++ b/system/libraries/Validation.php @@ -7,8 +7,8 @@ * @package CodeIgniter * @author ExpressionEngine Dev Team * @copyright Copyright (c) 2006, EllisLab, Inc. - * @license http://www.codeigniter.com/user_guide/license.html - * @link http://www.codeigniter.com + * @license http://codeigniter.com/user_guide/license.html + * @link http://codeigniter.com * @since Version 1.0 * @filesource */ @@ -22,7 +22,7 @@ * @subpackage Libraries * @category Validation * @author ExpressionEngine Dev Team - * @link http://www.codeigniter.com/user_guide/libraries/validation.html + * @link http://codeigniter.com/user_guide/libraries/validation.html */ class CI_Validation { -- cgit v1.2.3-24-g4f1b From d92d3c4e004674d7a5fdb37c8d27a49a1783509f Mon Sep 17 00:00:00 2001 From: Derek Allard Date: Wed, 23 Jan 2008 04:10:23 +0000 Subject: Fixed a series of grammatical and spelling errors in the language files. --- system/language/english/date_lang.php | 96 +++++++++++++++---------------- system/language/english/email_lang.php | 2 +- system/language/english/ftp_lang.php | 16 +++++- system/language/english/imglib_lang.php | 10 ++-- system/language/english/profiler_lang.php | 1 - system/language/english/upload_lang.php | 38 ++++++------ 6 files changed, 88 insertions(+), 75 deletions(-) (limited to 'system') diff --git a/system/language/english/date_lang.php b/system/language/english/date_lang.php index 02ebe7386..6b18aa7be 100644 --- a/system/language/english/date_lang.php +++ b/system/language/english/date_lang.php @@ -1,49 +1,49 @@ - \ No newline at end of file diff --git a/system/language/english/email_lang.php b/system/language/english/email_lang.php index 040e0eaa3..f02686509 100644 --- a/system/language/english/email_lang.php +++ b/system/language/english/email_lang.php @@ -10,7 +10,7 @@ $lang['email_send_failure_sendmail'] = "Unable to send email using PHP Sendmail. $lang['email_send_failure_smtp'] = "Unable to send email using PHP SMTP. Your server might not be configured to send mail using this method."; $lang['email_sent'] = "Your message has been successfully sent using the following protocol: %s"; $lang['email_no_socket'] = "Unable to open a socket to Sendmail. Please check settings."; -$lang['email_no_hostname'] = "You did not specify a SMTP hostname"; +$lang['email_no_hostname'] = "You did not specify a SMTP hostname."; $lang['email_smtp_error'] = "The following SMTP error was encountered: %s"; $lang['email_no_smtp_unpw'] = "Error: You must assign a SMTP username and password."; $lang['email_failed_smtp_login'] = "Failed to send AUTH LOGIN command. Error: %s"; diff --git a/system/language/english/ftp_lang.php b/system/language/english/ftp_lang.php index a891ae5fc..0b7087a6c 100644 --- a/system/language/english/ftp_lang.php +++ b/system/language/english/ftp_lang.php @@ -1 +1,15 @@ - \ No newline at end of file + \ No newline at end of file diff --git a/system/language/english/imglib_lang.php b/system/language/english/imglib_lang.php index 1921027f9..520f17f35 100644 --- a/system/language/english/imglib_lang.php +++ b/system/language/english/imglib_lang.php @@ -2,19 +2,19 @@ $lang['imglib_source_image_required'] = "You must specify a source image in your preferences."; $lang['imglib_gd_required'] = "The GD image library is required for this feature."; -$lang['imglib_gd_required_for_props'] = "Your server must support the GD image library in order to determine the image properties"; +$lang['imglib_gd_required_for_props'] = "Your server must support the GD image library in order to determine the image properties."; $lang['imglib_unsupported_imagecreate'] = "Your server does not support the GD function required to process this type of image."; $lang['imglib_gif_not_supported'] = "GIF images are often not supported due to licensing restrictions. You may have to use JPG or PNG images instead."; -$lang['imglib_jpg_not_supported'] = "JPG images are not supported"; -$lang['imglib_png_not_supported'] = "PNG images are not supported"; +$lang['imglib_jpg_not_supported'] = "JPG images are not supported."; +$lang['imglib_png_not_supported'] = "PNG images are not supported."; $lang['imglib_jpg_or_png_required'] = "The image resize protocol specified in your preferences only works with JPEG or PNG image types."; $lang['imglib_copy_error'] = "An error was encountered while attempting to replace the file. Please make sure your file directory is writable."; $lang['imglib_rotate_unsupported'] = "Image rotation does not appear to be supported by your server."; $lang['imglib_libpath_invalid'] = "The path to your image library is not correct. Please set the correct path in your image preferences."; $lang['imglib_image_process_failed'] = "Image processing failed. Please verify that your server supports the chosen protocol and that the path to your image library is correct."; $lang['imglib_rotation_angle_required'] = "An angle of rotation is required to rotate the image."; -$lang['imglib_writing_failed_gif'] = "GIF image "; -$lang['imglib_invalid_path'] = "The path to the image is not correct"; +$lang['imglib_writing_failed_gif'] = "GIF image."; +$lang['imglib_invalid_path'] = "The path to the image is not correct."; $lang['imglib_copy_failed'] = "The image copy routine failed."; $lang['imglib_missing_font'] = "Unable to find a font to use."; diff --git a/system/language/english/profiler_lang.php b/system/language/english/profiler_lang.php index b3a0dd3ba..219a83856 100644 --- a/system/language/english/profiler_lang.php +++ b/system/language/english/profiler_lang.php @@ -12,5 +12,4 @@ $lang['profiler_no_post'] = 'No POST data exists'; $lang['profiler_no_get'] = 'No GET data exists'; $lang['profiler_no_uri'] = 'No URI data exists'; $lang['profiler_no_memory'] = 'Memory Usage Unavailable'; - ?> \ No newline at end of file diff --git a/system/language/english/upload_lang.php b/system/language/english/upload_lang.php index ab155acd2..fa6d7c9fb 100644 --- a/system/language/english/upload_lang.php +++ b/system/language/english/upload_lang.php @@ -1,20 +1,20 @@ - \ No newline at end of file -- cgit v1.2.3-24-g4f1b From db708af87341897cbc7fd1157291377c253d371f Mon Sep 17 00:00:00 2001 From: Derek Allard Date: Wed, 23 Jan 2008 17:18:41 +0000 Subject: added an "unsupported" error to insert_id() in oracle --- system/database/drivers/oci8/oci8_driver.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system') diff --git a/system/database/drivers/oci8/oci8_driver.php b/system/database/drivers/oci8/oci8_driver.php index bc0862b5e..99f7d57bd 100644 --- a/system/database/drivers/oci8/oci8_driver.php +++ b/system/database/drivers/oci8/oci8_driver.php @@ -393,7 +393,7 @@ class CI_DB_oci8_driver extends CI_DB { function insert_id() { // not supported in oracle - return 0; + return $this->display_error('db_unsupported_function'); } // -------------------------------------------------------------------- -- cgit v1.2.3-24-g4f1b From 56e9fa581b9e7d590dfb56482b898339f29bd8f2 Mon Sep 17 00:00:00 2001 From: Derek Jones Date: Wed, 23 Jan 2008 17:26:37 +0000 Subject: added $query_times property to DB driver for profiling added individual query execution time to profiler output --- system/database/DB_driver.php | 6 ++++++ system/libraries/Profiler.php | 35 +++++++++++++++++++++++++---------- 2 files changed, 31 insertions(+), 10 deletions(-) (limited to 'system') diff --git a/system/database/DB_driver.php b/system/database/DB_driver.php index 65be13dc9..dbd54bebe 100644 --- a/system/database/DB_driver.php +++ b/system/database/DB_driver.php @@ -48,6 +48,7 @@ class CI_DB_driver { var $bind_marker = '?'; var $save_queries = TRUE; var $queries = array(); + var $query_times = array(); var $data_cache = array(); var $trans_enabled = TRUE; var $_trans_depth = 0; @@ -341,6 +342,11 @@ class CI_DB_driver { $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++; diff --git a/system/libraries/Profiler.php b/system/libraries/Profiler.php index 3b189027f..21c2135cc 100644 --- a/system/libraries/Profiler.php +++ b/system/libraries/Profiler.php @@ -105,34 +105,49 @@ class CI_Profiler { $output = "\n\n"; $output .= '
    '; $output .= "\n"; - $output .= '  '.$this->CI->lang->line('profiler_queries').'  '; - $output .= "\n"; if ( ! class_exists('CI_DB_driver')) { - $output .= "
    ".$this->CI->lang->line('profiler_no_db')."
    "; + $output .= '  '.$this->CI->lang->line('profiler_queries').'  '; + $output .= "\n"; + $output .= "\n\n\n"; + $output .="\n"; } else { + $output .= '  '.$this->CI->lang->line('profiler_queries').' ('.count($this->CI->db->queries).')  '; + $output .= "\n"; + $output .= "\n\n
    ".$this->CI->lang->line('profiler_no_db')."
    \n"; + if (count($this->CI->db->queries) == 0) { - $output .= "
    ".$this->CI->lang->line('profiler_no_queries')."
    "; + $output .= "\n"; } else { - foreach ($this->CI->db->queries as $val) + $highlight = array('SELECT', 'FROM', 'WHERE', 'AND', 'OR', 'LEFT JOIN', 'ORDER BY', 'LIMIT', 'INSERT', 'INTO', 'VALUES', 'UPDATE'); + + foreach ($this->CI->db->queries as $key => $val) { - $output .= '
    '; - $output .= htmlspecialchars($val, ENT_QUOTES); - $output .= "
    \n"; - } + $val = htmlspecialchars($val, ENT_QUOTES); + $time = number_format($this->CI->db->query_times[$key], 4); + + foreach ($highlight as $bold) + { + $val = str_replace($bold, ''.$bold.'', $val); + } + + $output .= "\n"; + } } } - $output .= ""; + $output .= "
    ".$this->CI->lang->line('profiler_no_queries')."
    ".$time."  ".$val."
    \n"; + $output .= "
    "; return $output; } + // -------------------------------------------------------------------- -- cgit v1.2.3-24-g4f1b From d85a11e9f9da50d04c724c0a4bc8c9ee734f2f59 Mon Sep 17 00:00:00 2001 From: Derek Jones Date: Thu, 24 Jan 2008 20:48:07 +0000 Subject: added CI's global variables to the protected array in_sanitize_globals() --- system/libraries/Input.php | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'system') diff --git a/system/libraries/Input.php b/system/libraries/Input.php index de70738e2..1874b3790 100644 --- a/system/libraries/Input.php +++ b/system/libraries/Input.php @@ -68,8 +68,9 @@ class CI_Input { */ function _sanitize_globals() { - // Would kind of be "wrong" to unset any of these GLOBALS. - $protected = array('_SERVER', '_GET', '_POST', '_FILES', '_REQUEST', '_SESSION', '_ENV', 'GLOBALS', 'HTTP_RAW_POST_DATA'); + // Would kind of 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 @@ -79,7 +80,7 @@ class CI_Input { { if ( ! in_array($global, $protected)) { - global $global; + global $$global; $$global = NULL; } } -- cgit v1.2.3-24-g4f1b From 065a0cef3081baa7d8f13b6918ecec1d086a60f3 Mon Sep 17 00:00:00 2001 From: Derek Jones Date: Fri, 25 Jan 2008 17:06:27 +0000 Subject: added db_unable_to_set_charset error message --- system/language/english/db_lang.php | 1 + 1 file changed, 1 insertion(+) (limited to 'system') diff --git a/system/language/english/db_lang.php b/system/language/english/db_lang.php index c8c48f844..1e79a706d 100644 --- a/system/language/english/db_lang.php +++ b/system/language/english/db_lang.php @@ -20,5 +20,6 @@ $lang['db_invalid_cache_path'] = 'The cache path you submitted is not valid or w $lang['db_table_name_required'] = 'A table name is required for that operation.'; $lang['db_column_name_required'] = 'A column name is required for that operation.'; $lang['db_column_definition_required'] = 'A column definition is required for that operation.'; +$lang['db_unable_to_set_charset'] = 'Unable to set client connection character set: %s'; ?> \ No newline at end of file -- cgit v1.2.3-24-g4f1b From a66574398c9ba225a088282b608fa490c0db8d2c Mon Sep 17 00:00:00 2001 From: Derek Allard Date: Sat, 26 Jan 2008 15:26:33 +0000 Subject: Added a stripslashes() into the Upload Library. --- system/libraries/Upload.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system') diff --git a/system/libraries/Upload.php b/system/libraries/Upload.php index 6511c68ab..39f1ed59b 100644 --- a/system/libraries/Upload.php +++ b/system/libraries/Upload.php @@ -711,7 +711,7 @@ class CI_Upload { $filename = str_replace($val, '', $filename); } - return $filename; + return stripslashes($filename); } // -------------------------------------------------------------------- -- cgit v1.2.3-24-g4f1b From 4acd792e54f58a5d86269057b5a827440fc2efcd Mon Sep 17 00:00:00 2001 From: Derek Allard Date: Sat, 26 Jan 2008 19:33:59 +0000 Subject: fix a postgre escape error --- system/database/drivers/postgre/postgre_driver.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'system') diff --git a/system/database/drivers/postgre/postgre_driver.php b/system/database/drivers/postgre/postgre_driver.php index 34d76de61..96cf2dfe9 100644 --- a/system/database/drivers/postgre/postgre_driver.php +++ b/system/database/drivers/postgre/postgre_driver.php @@ -451,7 +451,7 @@ class CI_DB_postgre_driver extends CI_DB { } else { - return ""{$item}""; + return "\"{$item}\""; } $exceptions = array('AS', '/', '-', '%', '+', '*'); @@ -459,7 +459,7 @@ class CI_DB_postgre_driver extends CI_DB { foreach ($exceptions as $exception) { - if (stristr($item, " "{$exception}" ") !== FALSE) + if (stristr($item, " \"{$exception}\" ") !== FALSE) { $item = preg_replace('/ "('.preg_quote($exception).')" /i', ' $1 ', $item); } -- cgit v1.2.3-24-g4f1b From 1353ffb2ea331e068cddac6afe7a1fa949d207a1 Mon Sep 17 00:00:00 2001 From: Derek Allard Date: Sun, 27 Jan 2008 14:54:29 +0000 Subject: Fixed a bug (#3330) in the FTP class where a comparison wasn't getting made. Fixed typo in the FTP Class (ftp_unable_to_remame). --- system/language/english/ftp_lang.php | 2 +- system/libraries/Ftp.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'system') diff --git a/system/language/english/ftp_lang.php b/system/language/english/ftp_lang.php index 0b7087a6c..da744fea7 100644 --- a/system/language/english/ftp_lang.php +++ b/system/language/english/ftp_lang.php @@ -8,7 +8,7 @@ $lang['ftp_unable_to_changedir'] = "Unable to change directories."; $lang['ftp_unable_to_chmod'] = "Unable to set file permissions. Please check your path. Note: This feature is only available in PHP 5 or higher."; $lang['ftp_unable_to_upload'] = "Unable to upload the specified file. Please check your path."; $lang['ftp_no_source_file'] = "Unable to locate the source file. Please check your path."; -$lang['ftp_unable_to_remame'] = "Unable to rename the file."; +$lang['ftp_unable_to_rename'] = "Unable to rename the file."; $lang['ftp_unable_to_delete'] = "Unable to delete the file."; $lang['ftp_unable_to_move'] = "Unable to move the file. Please make sure the destination directory exists."; diff --git a/system/libraries/Ftp.php b/system/libraries/Ftp.php index 9fdee0122..ed934b548 100644 --- a/system/libraries/Ftp.php +++ b/system/libraries/Ftp.php @@ -302,7 +302,7 @@ class CI_FTP { { if ($this->debug == TRUE) { - $msg = ($move = FALSE) ? 'ftp_unable_to_remame' : 'ftp_unable_to_move'; + $msg = ($move == FALSE) ? 'ftp_unable_to_rename' : 'ftp_unable_to_move'; $this->_error($msg); } -- cgit v1.2.3-24-g4f1b From b52bdc4e9e1b21ddfd0ff3231e09042258cb1399 Mon Sep 17 00:00:00 2001 From: Derek Allard Date: Sun, 27 Jan 2008 14:58:24 +0000 Subject: fixed a variable call to $this-> --- system/database/drivers/odbc/odbc_driver.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system') diff --git a/system/database/drivers/odbc/odbc_driver.php b/system/database/drivers/odbc/odbc_driver.php index daecabe13..604dd778c 100644 --- a/system/database/drivers/odbc/odbc_driver.php +++ b/system/database/drivers/odbc/odbc_driver.php @@ -41,7 +41,7 @@ class CI_DB_odbc_driver extends CI_DB { function CI_DB_odbc_driver() { - $_random_keyword = ' RND('.time().')'; // database specific random keyword + $this->_random_keyword = ' RND('.time().')'; // database specific random keyword } /** -- cgit v1.2.3-24-g4f1b From 1a704ceb6712b7f27402f4806f3894f48564e131 Mon Sep 17 00:00:00 2001 From: Derek Allard Date: Sun, 27 Jan 2008 15:03:06 +0000 Subject: fixed an overwritten parameter in protect_identifiers --- system/database/DB_driver.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'system') diff --git a/system/database/DB_driver.php b/system/database/DB_driver.php index dbd54bebe..966fd3ad5 100644 --- a/system/database/DB_driver.php +++ b/system/database/DB_driver.php @@ -652,7 +652,7 @@ class CI_DB_driver { */ function protect_identifiers($item, $first_word_only = FALSE) { - return $this->_protect_identifiers($item, $first_word_only = FALSE); + return $this->_protect_identifiers($item, $first_word_only); } // -------------------------------------------------------------------- @@ -1136,7 +1136,7 @@ class CI_DB_driver { $LANG = new CI_Language(); $LANG->load('db'); - $heading = 'MySQL Error'; + $heading = 'Database Error'; if ($native == TRUE) { -- cgit v1.2.3-24-g4f1b From 50bce4e0745eda3d148ee8112c18c2b3ab2b6be8 Mon Sep 17 00:00:00 2001 From: Derek Allard Date: Sun, 27 Jan 2008 15:06:28 +0000 Subject: fix extraneous returns and variables --- system/database/DB_active_rec.php | 5 ----- 1 file changed, 5 deletions(-) (limited to 'system') diff --git a/system/database/DB_active_rec.php b/system/database/DB_active_rec.php index 0455b981e..1ad4f3d1f 100644 --- a/system/database/DB_active_rec.php +++ b/system/database/DB_active_rec.php @@ -124,8 +124,6 @@ class CI_DB_active_record extends CI_DB_driver { $this->ar_select[] = $sql; return $this; - - return $this; } // -------------------------------------------------------------------- @@ -1246,7 +1244,6 @@ class CI_DB_active_record extends CI_DB_driver { function use_table($table) { return $this->from($table); - return $this; } // -------------------------------------------------------------------- @@ -1307,8 +1304,6 @@ class CI_DB_active_record extends CI_DB_driver { */ function _filter_table_aliases($statements) { - $statements_without_aliases = array(); - foreach ($statements as $k => $v) { foreach ($this->ar_aliased_tables as $table) -- cgit v1.2.3-24-g4f1b From 15130caa8d3f4650d383647050ce918de728bc53 Mon Sep 17 00:00:00 2001 From: Derek Jones Date: Mon, 28 Jan 2008 15:54:45 +0000 Subject: * Added valid_base64() to the Validation class * Tightened up validation of the supplied string given to the decode() method of the Encryption class (#3320) --- system/libraries/Encrypt.php | 28 +++++++++++++++++++++------- system/libraries/Validation.php | 17 +++++++++++++++++ 2 files changed, 38 insertions(+), 7 deletions(-) (limited to 'system') diff --git a/system/libraries/Encrypt.php b/system/libraries/Encrypt.php index b533c0438..48f9d3e51 100644 --- a/system/libraries/Encrypt.php +++ b/system/libraries/Encrypt.php @@ -27,7 +27,8 @@ * @link http://codeigniter.com/user_guide/libraries/encryption.html */ class CI_Encrypt { - + + var $CI; var $encryption_key = ''; var $_hash_type = 'sha1'; var $_mcrypt_exists = FALSE; @@ -42,6 +43,7 @@ class CI_Encrypt { */ function CI_Encrypt() { + $this->CI =& get_instance(); $this->_mcrypt_exists = ( ! function_exists('mcrypt_encrypt')) ? FALSE : TRUE; log_message('debug', "Encrypt Class Initialized"); } @@ -138,16 +140,22 @@ class CI_Encrypt { function decode($string, $key = '') { $key = $this->get_key($key); - $dec = base64_decode($string); - if ($dec === FALSE) - { - return FALSE; - } + $this->CI->load->library('validation'); + if ($this->CI->validation->valid_base64($string) === FALSE) + { + return FALSE; + } + + $dec = base64_decode($string); + if ($this->_mcrypt_exists === TRUE) { - $dec = $this->mcrypt_decode($dec, $key); + if (($dec = $this->mcrypt_decode($dec, $key)) === FALSE) + { + return FALSE; + } } return $this->_xor_decode($dec, $key); @@ -266,6 +274,12 @@ class CI_Encrypt { { $data = $this->_remove_cipher_noise($data, $key); $init_size = mcrypt_get_iv_size($this->_get_cipher(), $this->_get_mode()); + + if ($init_size > strlen($data)) + { + return FALSE; + } + $init_vect = substr($data, 0, $init_size); $data = substr($data, $init_size); return rtrim(mcrypt_decrypt($this->_get_cipher(), $key, $data, $this->_get_mode(), $init_vect), "\0"); diff --git a/system/libraries/Validation.php b/system/libraries/Validation.php index 162d362da..7720a7d17 100644 --- a/system/libraries/Validation.php +++ b/system/libraries/Validation.php @@ -572,6 +572,23 @@ class CI_Validation { // -------------------------------------------------------------------- + /** + * Valid Base64 + * + * Tests a string for characters outside of the Base64 alphabet + * as defined by RFC 2045 http://www.faqs.org/rfcs/rfc2045 + * + * @access public + * @param string + * @return bool + */ + function valid_base64($str) + { + return (bool) ! preg_match('/[^a-zA-Z0-9\/\+=]/', $str); + } + + // -------------------------------------------------------------------- + /** * Set Select * -- cgit v1.2.3-24-g4f1b From a25530f6594c7ba45b3faa9537fda9f807069759 Mon Sep 17 00:00:00 2001 From: Derek Jones Date: Mon, 28 Jan 2008 17:11:02 +0000 Subject: added is_really_writable() to Common.php, replaced is_writable() throughout application with is_really_writable() --- system/codeigniter/Common.php | 38 ++++++++++++++++++++++++++++++++++++++ system/database/DB_cache.php | 3 --- system/helpers/file_helper.php | 35 ----------------------------------- system/libraries/Log.php | 2 +- system/libraries/Output.php | 4 ++-- system/libraries/Upload.php | 2 +- system/plugins/captcha_pi.php | 2 +- 7 files changed, 43 insertions(+), 43 deletions(-) (limited to 'system') diff --git a/system/codeigniter/Common.php b/system/codeigniter/Common.php index b6f0a46e8..d9ddf80c7 100644 --- a/system/codeigniter/Common.php +++ b/system/codeigniter/Common.php @@ -29,6 +29,44 @@ // ------------------------------------------------------------------------ +/** + * Tests for file writability + * + * is_writable() returns TRUE on Windows servers + * when you really can't write to the file + * as the OS reports to PHP as FALSE only if the + * read-only attribute is marked. Ugh? + * + * @access private + * @return void + */ +function is_really_writable($file) +{ + if (is_dir($file)) + { + $file = rtrim($file, '/').'/'.md5(rand(1,100)); + + if (($fp = @fopen($file, 'ab')) === FALSE) + { + return FALSE; + } + + fclose($fp); + @chmod($file, 0777); + @unlink($file); + return TRUE; + } + elseif (($fp = @fopen($file, 'ab')) === FALSE) + { + return FALSE; + } + + fclose($fp); + return TRUE; +} + +// ------------------------------------------------------------------------ + /** * Class registry * diff --git a/system/database/DB_cache.php b/system/database/DB_cache.php index 44b8e815f..ad54fc315 100644 --- a/system/database/DB_cache.php +++ b/system/database/DB_cache.php @@ -63,9 +63,6 @@ class CI_DB_Cache { // Add a trailing slash to the path if needed $path = preg_replace("/(.+?)\/*$/", "\\1/", $path); - - // Load the file helper - $this->CI->load->helper('file'); if ( ! is_dir($path) OR ! is_really_writable($path)) { diff --git a/system/helpers/file_helper.php b/system/helpers/file_helper.php index 5fb31cfaa..868561b5a 100644 --- a/system/helpers/file_helper.php +++ b/system/helpers/file_helper.php @@ -178,39 +178,4 @@ function get_filenames($source_dir, $include_path = FALSE) // -------------------------------------------------------------------- -/** - * Tests for file writability - * - * is_writable() returns TRUE on Windows servers - * when you really can't write to the file - * as the OS reports to PHP as FALSE only if the - * read-only attribute is marked. Ugh? - * - * @access private - * @return void - */ -function is_really_writable($file) -{ - if (is_dir($file)) - { - $file = rtrim($file, '/').'/'.md5(rand(1,100)); - - if (($fp = @fopen($file, 'ab')) === FALSE) - { - return FALSE; - } - - fclose($fp); - @chmod($file, 0777); - @unlink($file); - return TRUE; - } - elseif (($fp = @fopen($file, 'ab')) === FALSE) - { - return FALSE; - } - - fclose($fp); - return TRUE; -} ?> \ No newline at end of file diff --git a/system/libraries/Log.php b/system/libraries/Log.php index 011bdbfd1..f9ca85a30 100644 --- a/system/libraries/Log.php +++ b/system/libraries/Log.php @@ -46,7 +46,7 @@ class CI_Log { $this->log_path = ($config['log_path'] != '') ? $config['log_path'] : BASEPATH.'logs/'; - if ( ! is_dir($this->log_path) OR ! is_writable($this->log_path)) + if ( ! is_dir($this->log_path) OR ! is_really_writable($this->log_path)) { $this->_enabled = FALSE; } diff --git a/system/libraries/Output.php b/system/libraries/Output.php index f98dab5e0..a4d8d34b8 100644 --- a/system/libraries/Output.php +++ b/system/libraries/Output.php @@ -285,7 +285,7 @@ class CI_Output { $cache_path = ($path == '') ? BASEPATH.'cache/' : $path; - if ( ! is_dir($cache_path) OR ! is_writable($cache_path)) + if ( ! is_dir($cache_path) OR ! is_really_writable($cache_path)) { return; } @@ -327,7 +327,7 @@ class CI_Output { $cache_path = ($CFG->item('cache_path') == '') ? BASEPATH.'cache/' : $CFG->item('cache_path'); - if ( ! is_dir($cache_path) OR ! is_writable($cache_path)) + if ( ! is_dir($cache_path) OR ! is_really_writable($cache_path)) { return FALSE; } diff --git a/system/libraries/Upload.php b/system/libraries/Upload.php index 39f1ed59b..dd7012211 100644 --- a/system/libraries/Upload.php +++ b/system/libraries/Upload.php @@ -641,7 +641,7 @@ class CI_Upload { return FALSE; } - if ( ! is_writable($this->upload_path)) + if ( ! is_really_writable($this->upload_path)) { $this->set_error('upload_not_writable'); return FALSE; diff --git a/system/plugins/captcha_pi.php b/system/plugins/captcha_pi.php index 11d4564d3..693fd9117 100644 --- a/system/plugins/captcha_pi.php +++ b/system/plugins/captcha_pi.php @@ -180,7 +180,7 @@ function create_captcha($data = '', $img_path = '', $img_url = '', $font_path = return FALSE; } - if ( ! is_writable($img_path)) + if ( ! is_really_writable($img_path)) { return FALSE; } -- cgit v1.2.3-24-g4f1b From 269b942a2bf7b022795e591d9b0ad04526ee7e09 Mon Sep 17 00:00:00 2001 From: Derek Jones Date: Mon, 28 Jan 2008 21:00:20 +0000 Subject: added ability to "extend" helpers * modified Loader to check for prefixed helpers in application/helpers folder * surrounded provided helper functions with if (! function_exists('foo')) conditionals so the user's helper functions take precedent. --- system/helpers/array_helper.php | 27 +- system/helpers/cookie_helper.php | 86 ++--- system/helpers/date_helper.php | 598 ++++++++++++++++++----------------- system/helpers/directory_helper.php | 34 +- system/helpers/download_helper.php | 94 +++--- system/helpers/email_helper.php | 14 +- system/helpers/file_helper.php | 138 ++++---- system/helpers/form_helper.php | 402 +++++++++++++---------- system/helpers/html_helper.php | 140 ++++---- system/helpers/inflector_helper.php | 133 ++++---- system/helpers/security_helper.php | 66 ++-- system/helpers/smiley_helper.php | 120 +++---- system/helpers/string_helper.php | 165 ++++++---- system/helpers/text_helper.php | 431 +++++++++++++------------ system/helpers/typography_helper.php | 46 +-- system/helpers/url_helper.php | 482 +++++++++++++++------------- system/helpers/xml_helper.php | 32 +- system/libraries/Loader.php | 17 +- 18 files changed, 1654 insertions(+), 1371 deletions(-) (limited to 'system') diff --git a/system/helpers/array_helper.php b/system/helpers/array_helper.php index 85d03794c..236e3904e 100644 --- a/system/helpers/array_helper.php +++ b/system/helpers/array_helper.php @@ -39,14 +39,17 @@ * @param mixed * @return mixed depends on what the array contains */ -function element($item, $array, $default = FALSE) +if (! function_exists('element')) { - if ( ! isset($array[$item]) OR $array[$item] == "") + function element($item, $array, $default = FALSE) { - return $default; - } + if ( ! isset($array[$item]) OR $array[$item] == "") + { + return $default; + } - return $array[$item]; + return $array[$item]; + } } // ------------------------------------------------------------------------ @@ -58,14 +61,16 @@ function element($item, $array, $default = FALSE) * @param array * @return mixed depends on what the array contains */ -function random_element($array) +if (! function_exists('random_element')) { - if ( ! is_array($array)) + function random_element($array) { - return $array; - } - return $array[array_rand($array)]; + if ( ! is_array($array)) + { + return $array; + } + return $array[array_rand($array)]; + } } - ?> \ No newline at end of file diff --git a/system/helpers/cookie_helper.php b/system/helpers/cookie_helper.php index 2a4a963dd..102057f8c 100644 --- a/system/helpers/cookie_helper.php +++ b/system/helpers/cookie_helper.php @@ -42,52 +42,55 @@ * @param string the cookie prefix * @return void */ -function set_cookie($name = '', $value = '', $expire = '', $domain = '', $path = '/', $prefix = '') +if (! function_exists('set_cookie')) { - if (is_array($name)) - { - foreach (array('value', 'expire', 'domain', 'path', 'prefix', 'name') as $item) - { - if (isset($name[$item])) + function set_cookie($name = '', $value = '', $expire = '', $domain = '', $path = '/', $prefix = '') + { + if (is_array($name)) + { + foreach (array('value', 'expire', 'domain', 'path', 'prefix', 'name') as $item) { - $$item = $name[$item]; + if (isset($name[$item])) + { + $$item = $name[$item]; + } } } - } - // Set the config file options - $CI =& get_instance(); + // Set the config file options + $CI =& get_instance(); - if ($prefix == '' AND $CI->config->item('cookie_prefix') != '') - { - $prefix = $CI->config->item('cookie_prefix'); - } - if ($domain == '' AND $CI->config->item('cookie_domain') != '') - { - $domain = $CI->config->item('cookie_domain'); - } - if ($path == '/' AND $CI->config->item('cookie_path') != '/') - { - $path = $CI->config->item('cookie_path'); - } + if ($prefix == '' AND $CI->config->item('cookie_prefix') != '') + { + $prefix = $CI->config->item('cookie_prefix'); + } + if ($domain == '' AND $CI->config->item('cookie_domain') != '') + { + $domain = $CI->config->item('cookie_domain'); + } + if ($path == '/' AND $CI->config->item('cookie_path') != '/') + { + $path = $CI->config->item('cookie_path'); + } - if ( ! is_numeric($expire)) - { - $expire = time() - 86500; - } - else - { - if ($expire > 0) + if ( ! is_numeric($expire)) { - $expire = time() + $expire; + $expire = time() - 86500; } else { - $expire = 0; + if ($expire > 0) + { + $expire = time() + $expire; + } + else + { + $expire = 0; + } } - } - setcookie($prefix.$name, $value, $expire, $path, $domain, 0); + setcookie($prefix.$name, $value, $expire, $path, $domain, 0); + } } // -------------------------------------------------------------------- @@ -100,10 +103,13 @@ function set_cookie($name = '', $value = '', $expire = '', $domain = '', $path = * @param bool * @return mixed */ -function get_cookie($index = '', $xss_clean = FALSE) +if (! function_exists('get_cookie')) { - $CI =& get_instance(); - return $CI->input->cookie($index, $xss_clean); + function get_cookie($index = '', $xss_clean = FALSE) + { + $CI =& get_instance(); + return $CI->input->cookie($index, $xss_clean); + } } // -------------------------------------------------------------------- @@ -117,10 +123,12 @@ function get_cookie($index = '', $xss_clean = FALSE) * @param string the cookie prefix * @return void */ -function delete_cookie($name = '', $domain = '', $path = '/', $prefix = '') +if (! function_exists('delete_cookie')) { - set_cookie($name, '', '', $domain, $path, $prefix); + function delete_cookie($name = '', $domain = '', $path = '/', $prefix = '') + { + set_cookie($name, '', '', $domain, $path, $prefix); + } } - ?> \ No newline at end of file diff --git a/system/helpers/date_helper.php b/system/helpers/date_helper.php index 9f4c66b4e..24e0b1794 100644 --- a/system/helpers/date_helper.php +++ b/system/helpers/date_helper.php @@ -35,26 +35,29 @@ * @access public * @return integer */ -function now() +if (! function_exists('now')) { - $CI =& get_instance(); - - if (strtolower($CI->config->item('time_reference')) == 'gmt') + function now() { - $now = time(); - $system_time = mktime(gmdate("H", $now), gmdate("i", $now), gmdate("s", $now), gmdate("m", $now), gmdate("d", $now), gmdate("Y", $now)); + $CI =& get_instance(); - if (strlen($system_time) < 10) + if (strtolower($CI->config->item('time_reference')) == 'gmt') { - $system_time = time(); - log_message('error', 'The Date class could not set a proper GMT timestamp so the local time() value was used.'); - } + $now = time(); + $system_time = mktime(gmdate("H", $now), gmdate("i", $now), gmdate("s", $now), gmdate("m", $now), gmdate("d", $now), gmdate("Y", $now)); - return $system_time; - } - else - { - return time(); + 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(); + } } } @@ -77,16 +80,19 @@ function now() * @param integer * @return integer */ -function mdate($datestr = '', $time = '') +if (! function_exists('mdate')) { - if ($datestr == '') - return ''; + function mdate($datestr = '', $time = '') + { + if ($datestr == '') + return ''; - if ($time == '') - $time = now(); + if ($time == '') + $time = now(); - $datestr = str_replace('%\\', '', preg_replace("/([a-z]+?){1}/i", "\\\\\\1", $datestr)); - return date($datestr, $time); + $datestr = str_replace('%\\', '', preg_replace("/([a-z]+?){1}/i", "\\\\\\1", $datestr)); + return date($datestr, $time); + } } // ------------------------------------------------------------------------ @@ -101,28 +107,30 @@ function mdate($datestr = '', $time = '') * @param integer Unix timestamp * @return string */ -function standard_date($fmt = 'DATE_RFC822', $time = '') +if (! function_exists('standard_date')) { - $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%O', - 'DATE_RFC822' => '%D, %d %M %y %H:%i:%s %O', - 'DATE_RFC850' => '%l, %d-%M-%y %H:%m:%i 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])) + function standard_date($fmt = 'DATE_RFC822', $time = '') { - return FALSE; - } + $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%O', + 'DATE_RFC822' => '%D, %d %M %y %H:%i:%s %O', + 'DATE_RFC850' => '%l, %d-%M-%y %H:%m:%i 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); + return mdate($formats[$fmt], $time); + } } - // ------------------------------------------------------------------------ @@ -137,105 +145,108 @@ function standard_date($fmt = 'DATE_RFC822', $time = '') * @param integer Unix timestamp * @return integer */ -function timespan($seconds = 1, $time = '') +if (! function_exists('timespan')) { - $CI =& get_instance(); - $CI->lang->load('date'); - - if ( ! is_numeric($seconds)) + function timespan($seconds = 1, $time = '') { - $seconds = 1; - } + $CI =& get_instance(); + $CI->lang->load('date'); + + if ( ! is_numeric($seconds)) + { + $seconds = 1; + } - if ( ! is_numeric($time)) - { - $time = time(); - } + if ( ! is_numeric($time)) + { + $time = time(); + } - if ($time <= $seconds) - { - $seconds = 1; - } - else - { - $seconds = $time - $seconds; - } + 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')).', '; - } + $str = ''; + $years = floor($seconds / 31536000); - $seconds -= $years * 31536000; - $months = floor($seconds / 2628000); - - if ($years > 0 OR $months > 0) - { - if ($months > 0) + if ($years > 0) { - $str .= $months.' '.$CI->lang->line((($months > 1) ? 'date_months' : 'date_month')).', '; + $str .= $years.' '.$CI->lang->line((($years > 1) ? 'date_years' : 'date_year')).', '; } - $seconds -= $months * 2628000; - } - - $weeks = floor($seconds / 604800); + $seconds -= $years * 31536000; + $months = floor($seconds / 2628000); - if ($years > 0 OR $months > 0 OR $weeks > 0) - { - if ($weeks > 0) - { - $str .= $weeks.' '.$CI->lang->line((($weeks > 1) ? 'date_weeks' : 'date_week')).', '; + 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; - } + $seconds -= $weeks * 604800; + } - $days = floor($seconds / 86400); + $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')).', '; - } + 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; - } + $seconds -= $days * 86400; + } - $hours = floor($seconds / 3600); + $hours = floor($seconds / 3600); - if ($days > 0 OR $hours > 0) - { - if ($hours > 0) + if ($days > 0 OR $hours > 0) { - $str .= $hours.' '.$CI->lang->line((($hours > 1) ? 'date_hours' : 'date_hour')).', '; - } + if ($hours > 0) + { + $str .= $hours.' '.$CI->lang->line((($hours > 1) ? 'date_hours' : 'date_hour')).', '; + } - $seconds -= $hours * 3600; - } + $seconds -= $hours * 3600; + } - $minutes = floor($seconds / 60); + $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')).', '; - } + 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; - } + $seconds -= $minutes * 60; + } - if ($str == '') - { - $str .= $seconds.' '.$CI->lang->line((($seconds > 1) ? 'date_seconds' : 'date_second')).', '; - } + if ($str == '') + { + $str .= $seconds.' '.$CI->lang->line((($seconds > 1) ? 'date_seconds' : 'date_second')).', '; + } - return substr(trim($str), 0, -1); + return substr(trim($str), 0, -1); + } } // ------------------------------------------------------------------------ @@ -251,28 +262,31 @@ function timespan($seconds = 1, $time = '') * @param integer a numeric year * @return integer */ -function days_in_month($month = 0, $year = '') +if (! function_exists('days_in_month')) { - if ($month < 1 OR $month > 12) + function days_in_month($month = 0, $year = '') { - return 0; - } + if ($month < 1 OR $month > 12) + { + return 0; + } - if ( ! is_numeric($year) OR strlen($year) != 4) - { - $year = date('Y'); - } + 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)) + if ($month == 2) { - return 29; + 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]; + $days_in_month = array(31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31); + return $days_in_month[$month - 1]; + } } // ------------------------------------------------------------------------ @@ -284,12 +298,15 @@ function days_in_month($month = 0, $year = '') * @param integer Unix timestamp * @return integer */ -function local_to_gmt($time = '') +if (! function_exists('local_to_gmt')) { - if ($time == '') - $time = time(); + 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)); + return mktime( gmdate("H", $time), gmdate("i", $time), gmdate("s", $time), gmdate("m", $time), gmdate("d", $time), gmdate("Y", $time)); + } } // ------------------------------------------------------------------------ @@ -307,21 +324,24 @@ function local_to_gmt($time = '') * @param bool whether DST is active * @return integer */ -function gmt_to_local($time = '', $timezone = 'UTC', $dst = FALSE) -{ - if ($time == '') - { - return now(); - } +if (! function_exists('gmt_to_local')) +{ + function gmt_to_local($time = '', $timezone = 'UTC', $dst = FALSE) + { + if ($time == '') + { + return now(); + } - $time += timezones($timezone) * 3600; + $time += timezones($timezone) * 3600; - if ($dst == TRUE) - { - $time += 3600; - } + if ($dst == TRUE) + { + $time += 3600; + } - return $time; + return $time; + } } // ------------------------------------------------------------------------ @@ -333,25 +353,28 @@ function gmt_to_local($time = '', $timezone = 'UTC', $dst = FALSE) * @param integer Unix timestamp * @return integer */ -function mysql_to_unix($time = '') +if (! function_exists('mysql_to_unix')) { - // 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) - ); + 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) + ); + } } // ------------------------------------------------------------------------ @@ -367,30 +390,33 @@ function mysql_to_unix($time = '') * @param string format: us or euro * @return string */ -function unix_to_human($time = '', $seconds = FALSE, $fmt = 'us') +if (! function_exists('unix_to_human')) { - $r = date('Y', $time).'-'.date('m', $time).'-'.date('d', $time).' '; - - if ($fmt == 'us') + function unix_to_human($time = '', $seconds = FALSE, $fmt = 'us') { - $r .= date('h', $time).':'.date('i', $time); - } - else - { - $r .= date('H', $time).':'.date('i', $time); - } + $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 ($seconds) + { + $r .= ':'.date('s', $time); + } - if ($fmt == 'us') - { - $r .= ' '.date('A', $time); - } + if ($fmt == 'us') + { + $r .= ' '.date('A', $time); + } - return $r; + return $r; + } } // ------------------------------------------------------------------------ @@ -404,59 +430,62 @@ function unix_to_human($time = '', $seconds = FALSE, $fmt = 'us') * @param string format: us or euro * @return integer */ -function human_to_unix($datestr = '') +if (! function_exists('human_to_unix')) { - if ($datestr == '') + function human_to_unix($datestr = '') { - return FALSE; - } + if ($datestr == '') + { + return FALSE; + } - $datestr = trim($datestr); - $datestr = preg_replace("/\040+/", "\040", $datestr); + $datestr = trim($datestr); + $datestr = preg_replace("/\040+/", "\040", $datestr); - if ( ! ereg("^[0-9]{2,4}\-[0-9]{1,2}\-[0-9]{1,2}\040[0-9]{1,2}:[0-9]{1,2}.*$", $datestr)) - { - return FALSE; - } + if ( ! ereg("^[0-9]{2,4}\-[0-9]{1,2}\-[0-9]{1,2}\040[0-9]{1,2}:[0-9]{1,2}.*$", $datestr)) + { + return FALSE; + } - $split = preg_split("/\040/", $datestr); + $split = preg_split("/\040/", $datestr); - $ex = explode("-", $split['0']); + $ex = explode("-", $split['0']); - $year = (strlen($ex['0']) == 2) ? '20'.$ex['0'] : $ex['0']; - $month = (strlen($ex['1']) == 1) ? '0'.$ex['1'] : $ex['1']; - $day = (strlen($ex['2']) == 1) ? '0'.$ex['2'] : $ex['2']; + $year = (strlen($ex['0']) == 2) ? '20'.$ex['0'] : $ex['0']; + $month = (strlen($ex['1']) == 1) ? '0'.$ex['1'] : $ex['1']; + $day = (strlen($ex['2']) == 1) ? '0'.$ex['2'] : $ex['2']; - $ex = explode(":", $split['1']); + $ex = explode(":", $split['1']); - $hour = (strlen($ex['0']) == 1) ? '0'.$ex['0'] : $ex['0']; - $min = (strlen($ex['1']) == 1) ? '0'.$ex['1'] : $ex['1']; + $hour = (strlen($ex['0']) == 1) ? '0'.$ex['0'] : $ex['0']; + $min = (strlen($ex['1']) == 1) ? '0'.$ex['1'] : $ex['1']; - if (isset($ex['2']) AND ereg("[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($ex['2']) AND ereg("[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 (isset($split['2'])) + { + $ampm = strtolower($split['2']); - if (substr($ampm, 0, 1) == 'p' AND $hour < 12) - $hour = $hour + 12; + if (substr($ampm, 0, 1) == 'p' AND $hour < 12) + $hour = $hour + 12; - if (substr($ampm, 0, 1) == 'a' AND $hour == 12) - $hour = '00'; + if (substr($ampm, 0, 1) == 'a' AND $hour == 12) + $hour = '00'; - if (strlen($hour) == 1) - $hour = '0'.$hour; - } + if (strlen($hour) == 1) + $hour = '0'.$hour; + } - return mktime($hour, $min, $sec, $month, $day, $year); + return mktime($hour, $min, $sec, $month, $day, $year); + } } // ------------------------------------------------------------------------ @@ -472,32 +501,35 @@ function human_to_unix($datestr = '') * @param string menu name * @return string */ -function timezone_menu($default = 'UTC', $class = "", $name = 'timezones') +if (! function_exists('timezone_menu')) { - $CI =& get_instance(); - $CI->lang->load('date'); + function timezone_menu($default = 'UTC', $class = "", $name = 'timezones') + { + $CI =& get_instance(); + $CI->lang->load('date'); - if ($default == 'GMT') - $default = 'UTC'; + if ($default == 'GMT') + $default = 'UTC'; - $menu = '"; + $menu .= ""; - return $menu; + return $menu; + } } // ------------------------------------------------------------------------ @@ -512,54 +544,56 @@ function timezone_menu($default = 'UTC', $class = "", $name = 'timezones') * @param string timezone * @return string */ -function timezones($tz = '') +if (! function_exists('timezones')) { - // Note: Don't change the order of these even though - // some items appear to be in the wrong order + 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, - 'UM9' => -9, - 'UM8' => -8, - 'UM7' => -7, - 'UM6' => -6, - 'UM5' => -5, - 'UM4' => -4, - 'UM25' => -2.5, - 'UM3' => -3, - 'UM2' => -2, - 'UM1' => -1, - 'UTC' => 0, - 'UP1' => +1, - 'UP2' => +2, - 'UP3' => +3, - 'UP25' => +2.5, - 'UP4' => +4, - 'UP35' => +3.5, - 'UP5' => +5, - 'UP45' => +4.5, - 'UP6' => +6, - 'UP7' => +7, - 'UP8' => +8, - 'UP9' => +9, - 'UP85' => +8.5, - 'UP10' => +10, - 'UP11' => +11, - 'UP12' => +12 - ); + $zones = array( + 'UM12' => -12, + 'UM11' => -11, + 'UM10' => -10, + 'UM9' => -9, + 'UM8' => -8, + 'UM7' => -7, + 'UM6' => -6, + 'UM5' => -5, + 'UM4' => -4, + 'UM25' => -2.5, + 'UM3' => -3, + 'UM2' => -2, + 'UM1' => -1, + 'UTC' => 0, + 'UP1' => +1, + 'UP2' => +2, + 'UP3' => +3, + 'UP25' => +2.5, + 'UP4' => +4, + 'UP35' => +3.5, + 'UP5' => +5, + 'UP45' => +4.5, + 'UP6' => +6, + 'UP7' => +7, + 'UP8' => +8, + 'UP9' => +9, + 'UP85' => +8.5, + 'UP10' => +10, + 'UP11' => +11, + 'UP12' => +12 + ); - if ($tz == '') - { - return $zones; - } + if ($tz == '') + { + return $zones; + } - if ($tz == 'GMT') - $tz = 'UTC'; + if ($tz == 'GMT') + $tz = 'UTC'; - return ( ! isset($zones[$tz])) ? 0 : $zones[$tz]; + return ( ! isset($zones[$tz])) ? 0 : $zones[$tz]; + } } - ?> \ No newline at end of file diff --git a/system/helpers/directory_helper.php b/system/helpers/directory_helper.php index 4a499de5c..5a23944cb 100644 --- a/system/helpers/directory_helper.php +++ b/system/helpers/directory_helper.php @@ -39,29 +39,31 @@ * @param bool whether to limit the result to the top level only * @return array */ -function directory_map($source_dir, $top_level_only = FALSE) -{ - if ($fp = @opendir($source_dir)) - { - $filedata = array(); - while (FALSE !== ($file = readdir($fp))) +if (! function_exists('directory_map')) +{ + function directory_map($source_dir, $top_level_only = FALSE) + { + if ($fp = @opendir($source_dir)) { - if (@is_dir($source_dir.$file) && substr($file, 0, 1) != '.' AND $top_level_only == FALSE) + $filedata = array(); + while (FALSE !== ($file = readdir($fp))) { - $temp_array = array(); + if (@is_dir($source_dir.$file) && substr($file, 0, 1) != '.' AND $top_level_only == FALSE) + { + $temp_array = array(); - $temp_array = directory_map($source_dir.$file."/"); + $temp_array = directory_map($source_dir.$file."/"); - $filedata[$file] = $temp_array; - } - elseif (substr($file, 0, 1) != ".") - { - $filedata[] = $file; + $filedata[$file] = $temp_array; + } + elseif (substr($file, 0, 1) != ".") + { + $filedata[] = $file; + } } + return $filedata; } - return $filedata; } } - ?> \ No newline at end of file diff --git a/system/helpers/download_helper.php b/system/helpers/download_helper.php index e8bc2f7f6..2d0e737c9 100644 --- a/system/helpers/download_helper.php +++ b/system/helpers/download_helper.php @@ -37,60 +37,62 @@ * @param mixed the data to be downloaded * @return void */ -function force_download($filename = '', $data = '') +if (! function_exists('force_download')) { - if ($filename == '' OR $data == '') + function force_download($filename = '', $data = '') { - return FALSE; - } + if ($filename == '' OR $data == '') + { + return FALSE; + } - // Try to determine if the filename includes a file extension. - // We need it in order to set the MIME type - if (FALSE === strpos($filename, '.')) - { - return FALSE; - } + // Try to determine if the filename includes a file extension. + // We need it in order to set the MIME type + if (FALSE === strpos($filename, '.')) + { + return FALSE; + } - // Grab the file extension - $x = explode('.', $filename); - $extension = end($x); + // Grab the file extension + $x = explode('.', $filename); + $extension = end($x); - // Load the mime types - @include(APPPATH.'config/mimes'.EXT); + // Load the mime types + @include(APPPATH.'config/mimes'.EXT); - // Set a default mime if we can't find it - if ( ! isset($mimes[$extension])) - { - $mime = 'application/octet-stream'; - } - else - { - $mime = (is_array($mimes[$extension])) ? $mimes[$extension][0] : $mimes[$extension]; - } + // Set a default mime if we can't find it + if ( ! isset($mimes[$extension])) + { + $mime = 'application/octet-stream'; + } + else + { + $mime = (is_array($mimes[$extension])) ? $mimes[$extension][0] : $mimes[$extension]; + } - // Generate the server headers - if (strstr($_SERVER['HTTP_USER_AGENT'], "MSIE")) - { - header('Content-Type: "'.$mime.'"'); - header('Content-Disposition: attachment; filename="'.$filename.'"'); - header('Expires: 0'); - header('Cache-Control: must-revalidate, post-check=0, pre-check=0'); - header("Content-Transfer-Encoding: binary"); - header('Pragma: public'); - header("Content-Length: ".strlen($data)); - } - else - { - header('Content-Type: "'.$mime.'"'); - header('Content-Disposition: attachment; filename="'.$filename.'"'); - header("Content-Transfer-Encoding: binary"); - header('Expires: 0'); - header('Pragma: no-cache'); - header("Content-Length: ".strlen($data)); - } + // Generate the server headers + if (strstr($_SERVER['HTTP_USER_AGENT'], "MSIE")) + { + header('Content-Type: "'.$mime.'"'); + header('Content-Disposition: attachment; filename="'.$filename.'"'); + header('Expires: 0'); + header('Cache-Control: must-revalidate, post-check=0, pre-check=0'); + header("Content-Transfer-Encoding: binary"); + header('Pragma: public'); + header("Content-Length: ".strlen($data)); + } + else + { + header('Content-Type: "'.$mime.'"'); + header('Content-Disposition: attachment; filename="'.$filename.'"'); + header("Content-Transfer-Encoding: binary"); + header('Expires: 0'); + header('Pragma: no-cache'); + header("Content-Length: ".strlen($data)); + } - echo $data; + echo $data; + } } - ?> \ No newline at end of file diff --git a/system/helpers/email_helper.php b/system/helpers/email_helper.php index b44fae554..e677afd28 100644 --- a/system/helpers/email_helper.php +++ b/system/helpers/email_helper.php @@ -33,9 +33,12 @@ * @access public * @return bool */ -function valid_email($address) +if (! function_exists('valid_email')) { - return ( ! preg_match("/^([a-z0-9\+_\-]+)(\.[a-z0-9\+_\-]+)*@([a-z0-9\-]+\.)+[a-z]{2,6}$/ix", $address)) ? FALSE : TRUE; + function valid_email($address) + { + return ( ! preg_match("/^([a-z0-9\+_\-]+)(\.[a-z0-9\+_\-]+)*@([a-z0-9\-]+\.)+[a-z]{2,6}$/ix", $address)) ? FALSE : TRUE; + } } // ------------------------------------------------------------------------ @@ -46,9 +49,12 @@ function valid_email($address) * @access public * @return bool */ -function send_email($recipient, $subject = 'Test email', $message = 'Hello World') +if (! function_exists('send_email')) { - return mail($recipient, $subject, $message); + function send_email($recipient, $subject = 'Test email', $message = 'Hello World') + { + return mail($recipient, $subject, $message); + } } ?> \ No newline at end of file diff --git a/system/helpers/file_helper.php b/system/helpers/file_helper.php index 868561b5a..bbf340930 100644 --- a/system/helpers/file_helper.php +++ b/system/helpers/file_helper.php @@ -36,35 +36,38 @@ * @param string path to file * @return string */ -function read_file($file) +if (! function_exists('read_file')) { - if ( ! file_exists($file)) + function read_file($file) { - return FALSE; - } + if ( ! file_exists($file)) + { + return FALSE; + } - if (function_exists('file_get_contents')) - { - return file_get_contents($file); - } + if (function_exists('file_get_contents')) + { + return file_get_contents($file); + } - if ( ! $fp = @fopen($file, 'rb')) - { - return FALSE; - } + if ( ! $fp = @fopen($file, 'rb')) + { + return FALSE; + } - flock($fp, LOCK_SH); + flock($fp, LOCK_SH); - $data = ''; - if (filesize($file) > 0) - { - $data =& fread($fp, filesize($file)); - } + $data = ''; + if (filesize($file) > 0) + { + $data =& fread($fp, filesize($file)); + } - flock($fp, LOCK_UN); - fclose($fp); + flock($fp, LOCK_UN); + fclose($fp); - return $data; + return $data; + } } // ------------------------------------------------------------------------ @@ -80,19 +83,22 @@ function read_file($file) * @param string file data * @return bool */ -function write_file($path, $data, $mode = 'wb') +if (! function_exists('write_file')) { - if ( ! $fp = @fopen($path, $mode)) + function write_file($path, $data, $mode = 'wb') { - return FALSE; - } + if ( ! $fp = @fopen($path, $mode)) + { + return FALSE; + } - flock($fp, LOCK_EX); - fwrite($fp, $data); - flock($fp, LOCK_UN); - fclose($fp); + flock($fp, LOCK_EX); + fwrite($fp, $data); + flock($fp, LOCK_UN); + fclose($fp); - return TRUE; + return TRUE; + } } // ------------------------------------------------------------------------ @@ -110,34 +116,37 @@ function write_file($path, $data, $mode = 'wb') * @param bool whether to delete any directories found in the path * @return bool */ -function delete_files($path, $del_dir = FALSE, $level = 0) -{ - // Trim the trailing slash - $path = preg_replace("|^(.+?)/*$|", "\\1", $path); +if (! function_exists('delete_files')) +{ + function delete_files($path, $del_dir = FALSE, $level = 0) + { + // Trim the trailing slash + $path = preg_replace("|^(.+?)/*$|", "\\1", $path); - if ( ! $current_dir = @opendir($path)) - return; + if ( ! $current_dir = @opendir($path)) + return; - while(FALSE !== ($filename = @readdir($current_dir))) - { - if ($filename != "." and $filename != "..") + while(FALSE !== ($filename = @readdir($current_dir))) { - if (is_dir($path.'/'.$filename)) - { - $level++; - delete_files($path.'/'.$filename, $del_dir, $level); - } - else + if ($filename != "." and $filename != "..") { - unlink($path.'/'.$filename); + if (is_dir($path.'/'.$filename)) + { + $level++; + delete_files($path.'/'.$filename, $del_dir, $level); + } + else + { + unlink($path.'/'.$filename); + } } } - } - @closedir($current_dir); + @closedir($current_dir); - if ($del_dir == TRUE AND $level > 0) - { - @rmdir($path); + if ($del_dir == TRUE AND $level > 0) + { + @rmdir($path); + } } } @@ -154,25 +163,28 @@ function delete_files($path, $del_dir = FALSE, $level = 0) * @param bool whether to include the path as part of the filename * @return array */ -function get_filenames($source_dir, $include_path = FALSE) +if (! function_exists('get_filenames')) { - $_filedata = array(); - - if ($fp = @opendir($source_dir)) + function get_filenames($source_dir, $include_path = FALSE) { - while (FALSE !== ($file = readdir($fp))) + $_filedata = array(); + + if ($fp = @opendir($source_dir)) { - if (@is_dir($source_dir.$file) && substr($file, 0, 1) != '.') - { - get_filenames($source_dir.$file."/", $include_path); - } - elseif (substr($file, 0, 1) != ".") + while (FALSE !== ($file = readdir($fp))) { + if (@is_dir($source_dir.$file) && substr($file, 0, 1) != '.') + { + get_filenames($source_dir.$file."/", $include_path); + } + elseif (substr($file, 0, 1) != ".") + { - $_filedata[] = ($include_path == TRUE) ? $source_dir.$file : $file; + $_filedata[] = ($include_path == TRUE) ? $source_dir.$file : $file; + } } + return $_filedata; } - return $_filedata; } } diff --git a/system/helpers/form_helper.php b/system/helpers/form_helper.php index a2bc2002e..7c3b16ff1 100644 --- a/system/helpers/form_helper.php +++ b/system/helpers/form_helper.php @@ -38,35 +38,38 @@ * @param array a key/value pair hidden data * @return string */ -function form_open($action = '', $attributes = array(), $hidden = array()) +if (! function_exists('form_open')) { - $CI =& get_instance(); + function form_open($action = '', $attributes = array(), $hidden = array()) + { + $CI =& get_instance(); - $action = ( strpos($action, '://') === FALSE) ? $CI->config->site_url($action) : $action; + $action = ( strpos($action, '://') === FALSE) ? $CI->config->site_url($action) : $action; - $form = '
    0) - { - foreach ($attributes as $key => $val) + if (is_array($attributes) AND count($attributes) > 0) { - $form .= ' '.$key.'="'.$val.'"'; + foreach ($attributes as $key => $val) + { + $form .= ' '.$key.'="'.$val.'"'; + } } - } - $form .= '>'; + $form .= '>'; - if (is_array($hidden) AND count($hidden > 0)) - { - $form .= form_hidden($hidden); - } + if (is_array($hidden) AND count($hidden > 0)) + { + $form .= form_hidden($hidden); + } - return $form; + return $form; + } } // ------------------------------------------------------------------------ @@ -82,10 +85,13 @@ function form_open($action = '', $attributes = array(), $hidden = array()) * @param array a key/value pair hidden data * @return string */ -function form_open_multipart($action, $attributes = array(), $hidden = array()) +if (! function_exists('form_open_multipart')) { - $attributes['enctype'] = 'multipart/form-data'; - return form_open($action, $attributes, $hidden); + function form_open_multipart($action, $attributes = array(), $hidden = array()) + { + $attributes['enctype'] = 'multipart/form-data'; + return form_open($action, $attributes, $hidden); + } } // ------------------------------------------------------------------------ @@ -101,20 +107,23 @@ function form_open_multipart($action, $attributes = array(), $hidden = array()) * @param string * @return string */ -function form_hidden($name, $value = '') +if (! function_exists('form_hidden')) { - if ( ! is_array($name)) + function form_hidden($name, $value = '') { - return ''; - } + if ( ! is_array($name)) + { + return ''; + } - $form = ''; - foreach ($name as $name => $value) - { - $form .= ''; - } + $form = ''; + foreach ($name as $name => $value) + { + $form .= ''; + } - return $form; + return $form; + } } // ------------------------------------------------------------------------ @@ -128,11 +137,14 @@ function form_hidden($name, $value = '') * @param string * @return string */ -function form_input($data = '', $value = '', $extra = '') +if (! function_exists('form_input')) { - $defaults = array('type' => 'text', 'name' => (( ! is_array($data)) ? $data : ''), 'value' => $value, 'maxlength' => '500', 'size' => '50'); + function form_input($data = '', $value = '', $extra = '') + { + $defaults = array('type' => 'text', 'name' => (( ! is_array($data)) ? $data : ''), 'value' => $value, 'maxlength' => '500', 'size' => '50'); - return "\n"; + return "\n"; + } } // ------------------------------------------------------------------------ @@ -148,15 +160,18 @@ function form_input($data = '', $value = '', $extra = '') * @param string * @return string */ -function form_password($data = '', $value = '', $extra = '') +if (! function_exists('form_password')) { - if ( ! is_array($data)) + function form_password($data = '', $value = '', $extra = '') { - $data = array('name' => $data); - } + if ( ! is_array($data)) + { + $data = array('name' => $data); + } - $data['type'] = 'password'; - return form_input($data, $value, $extra); + $data['type'] = 'password'; + return form_input($data, $value, $extra); + } } // ------------------------------------------------------------------------ @@ -172,15 +187,18 @@ function form_password($data = '', $value = '', $extra = '') * @param string * @return string */ -function form_upload($data = '', $value = '', $extra = '') +if (! function_exists('form_upload')) { - if ( ! is_array($data)) + function form_upload($data = '', $value = '', $extra = '') { - $data = array('name' => $data); - } + if ( ! is_array($data)) + { + $data = array('name' => $data); + } - $data['type'] = 'file'; - return form_input($data, $value, $extra); + $data['type'] = 'file'; + return form_input($data, $value, $extra); + } } // ------------------------------------------------------------------------ @@ -194,21 +212,24 @@ function form_upload($data = '', $value = '', $extra = '') * @param string * @return string */ -function form_textarea($data = '', $value = '', $extra = '') +if (! function_exists('form_textarea')) { - $defaults = array('name' => (( ! is_array($data)) ? $data : ''), 'cols' => '90', 'rows' => '12'); - - if ( ! is_array($data) OR ! isset($data['value'])) - { - $val = $value; - } - else + function form_textarea($data = '', $value = '', $extra = '') { - $val = $data['value']; - unset($data['value']); // textareas don't use the value attribute - } + $defaults = array('name' => (( ! is_array($data)) ? $data : ''), 'cols' => '90', 'rows' => '12'); + + 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"; + return "\n"; + } } // ------------------------------------------------------------------------ @@ -223,32 +244,35 @@ function form_textarea($data = '', $value = '', $extra = '') * @param string * @return string */ -function form_dropdown($name = '', $options = array(), $selected = array(), $extra = '') +if (! function_exists('form_dropdown')) { - if ( ! is_array($selected)) + function form_dropdown($name = '', $options = array(), $selected = array(), $extra = '') { - $selected = array($selected); - } + if ( ! is_array($selected)) + { + $selected = array($selected); + } - if ($extra != '') $extra = ' '.$extra; + if ($extra != '') $extra = ' '.$extra; - $multiple = (count($selected) > 1 && strpos($extra, 'multiple') === FALSE) ? ' multiple="multiple"' : ''; + $multiple = (count($selected) > 1 && strpos($extra, 'multiple') === FALSE) ? ' multiple="multiple"' : ''; - $form = '\n"; - foreach ($options as $key => $val) - { - $key = (string) $key; - $val = (string) $val; + foreach ($options as $key => $val) + { + $key = (string) $key; + $val = (string) $val; - $sel = (in_array($key, $selected))?' selected="selected"':''; + $sel = (in_array($key, $selected))?' selected="selected"':''; - $form .= '\n"; - } + $form .= '\n"; + } - $form .= ''; + $form .= ''; - return $form; + return $form; + } } // ------------------------------------------------------------------------ @@ -263,30 +287,33 @@ function form_dropdown($name = '', $options = array(), $selected = array(), $ext * @param string * @return string */ -function form_checkbox($data = '', $value = '', $checked = TRUE, $extra = '') +if (! function_exists('form_checkbox')) { - $defaults = array('type' => 'checkbox', 'name' => (( ! is_array($data)) ? $data : ''), 'value' => $value); - - if (is_array($data) AND array_key_exists('checked', $data)) + function form_checkbox($data = '', $value = '', $checked = TRUE, $extra = '') { - $checked = $data['checked']; - - if ($checked == FALSE) - { - unset($data['checked']); - } - else + $defaults = array('type' => 'checkbox', 'name' => (( ! is_array($data)) ? $data : ''), 'value' => $value); + + if (is_array($data) AND array_key_exists('checked', $data)) { - $data['checked'] = 'checked'; + $checked = $data['checked']; + + if ($checked == FALSE) + { + unset($data['checked']); + } + else + { + $data['checked'] = 'checked'; + } } - } - if ($checked == TRUE) - $defaults['checked'] = 'checked'; - else - unset($defaults['checked']); + if ($checked == TRUE) + $defaults['checked'] = 'checked'; + else + unset($defaults['checked']); - return "\n"; + return "\n"; + } } // ------------------------------------------------------------------------ @@ -301,15 +328,18 @@ function form_checkbox($data = '', $value = '', $checked = TRUE, $extra = '') * @param string * @return string */ -function form_radio($data = '', $value = '', $checked = TRUE, $extra = '') +if (! function_exists('form_radio')) { - if ( ! is_array($data)) - { - $data = array('name' => $data); - } + function form_radio($data = '', $value = '', $checked = TRUE, $extra = '') + { + if ( ! is_array($data)) + { + $data = array('name' => $data); + } - $data['type'] = 'radio'; - return form_checkbox($data, $value, $checked, $extra); + $data['type'] = 'radio'; + return form_checkbox($data, $value, $checked, $extra); + } } // ------------------------------------------------------------------------ @@ -322,12 +352,15 @@ function form_radio($data = '', $value = '', $checked = TRUE, $extra = '') * @param string * @param string * @return string - */ -function form_submit($data = '', $value = '', $extra = '') -{ - $defaults = array('type' => 'submit', 'name' => (( ! is_array($data)) ? $data : ''), 'value' => $value); + */ +if (! function_exists('form_submit')) +{ + function form_submit($data = '', $value = '', $extra = '') + { + $defaults = array('type' => 'submit', 'name' => (( ! is_array($data)) ? $data : ''), 'value' => $value); - return "\n"; + return "\n"; + } } // ------------------------------------------------------------------------ @@ -341,11 +374,14 @@ function form_submit($data = '', $value = '', $extra = '') * @param string * @return string */ -function form_reset($data = '', $value = '', $extra = '') +if (! function_exists('form_reset')) { - $defaults = array('type' => 'reset', 'name' => (( ! is_array($data)) ? $data : ''), 'value' => $value); + function form_reset($data = '', $value = '', $extra = '') + { + $defaults = array('type' => 'reset', 'name' => (( ! is_array($data)) ? $data : ''), 'value' => $value); - return "\n"; + return "\n"; + } } // ------------------------------------------------------------------------ @@ -359,27 +395,30 @@ function form_reset($data = '', $value = '', $extra = '') * @param string Additional attributes * @return string */ -function form_label($label_text = '', $id = '', $attributes = array()) +if (! function_exists('form_label')) { + function form_label($label_text = '', $id = '', $attributes = array()) + { - $label = ' 0) - { - foreach ($attributes as $key => $val) + if (is_array($attributes) AND count($attributes) > 0) { - $label .= ' '.$key.'="'.$val.'"'; + foreach ($attributes as $key => $val) + { + $label .= ' '.$key.'="'.$val.'"'; + } } - } - $label .= ">$label_text"; + $label .= ">$label_text"; - return $label; + return $label; + } } // ------------------------------------------------------------------------ @@ -394,29 +433,32 @@ function form_label($label_text = '', $id = '', $attributes = array()) * @param string Additional attributes * @return string */ -function form_fieldset($legend_text = '', $attributes = array()) +if (! function_exists('form_fieldset')) { + function form_fieldset($legend_text = '', $attributes = array()) + { - $fieldset = " 0) - { - foreach ($attributes as $key => $val) + if (is_array($attributes) AND count($attributes) > 0) { - $fieldset .= ' '.$key.'="'.$val.'"'; + foreach ($attributes as $key => $val) + { + $fieldset .= ' '.$key.'="'.$val.'"'; + } } - } - $fieldset .= ">\n"; + $fieldset .= ">\n"; - if ($legend_text != '') - { - $fieldset .= "$legend_text\n"; - } + if ($legend_text != '') + { + $fieldset .= "$legend_text\n"; + } - return $fieldset; + return $fieldset; + } } // ------------------------------------------------------------------------ @@ -428,9 +470,12 @@ function form_fieldset($legend_text = '', $attributes = array()) * @param string * @return string */ -function form_fieldset_close($extra = '') +if (! function_exists('form_fieldset_close')) { - return "
    \n".$extra; + function form_fieldset_close($extra = '') + { + return "\n".$extra; + } } // ------------------------------------------------------------------------ @@ -442,9 +487,12 @@ function form_fieldset_close($extra = '') * @param string * @return string */ -function form_close($extra = '') +if (! function_exists('form_close')) { - return "\n".$extra; + function form_close($extra = '') + { + return "\n".$extra; + } } // ------------------------------------------------------------------------ @@ -458,30 +506,33 @@ function form_close($extra = '') * @param string * @return string */ -function form_prep($str = '') +if (! function_exists('form_prep')) { - if ($str === '') + function form_prep($str = '') { - return ''; - } + if ($str === '') + { + return ''; + } - $temp = '__TEMP_AMPERSANDS__'; + $temp = '__TEMP_AMPERSANDS__'; - // Replace entities to temporary markers so that - // htmlspecialchars won't mess them up - $str = preg_replace("/&#(\d+);/", "$temp\\1;", $str); - $str = preg_replace("/&(\w+);/", "$temp\\1;", $str); + // Replace entities to temporary markers so that + // htmlspecialchars won't mess them up + $str = preg_replace("/&#(\d+);/", "$temp\\1;", $str); + $str = preg_replace("/&(\w+);/", "$temp\\1;", $str); - $str = htmlspecialchars($str); + $str = htmlspecialchars($str); - // In case htmlspecialchars misses these. - $str = str_replace(array("'", '"'), array("'", """), $str); + // In case htmlspecialchars misses these. + $str = str_replace(array("'", '"'), array("'", """), $str); - // Decode the temp markers back to entities - $str = preg_replace("/$temp(\d+);/","&#\\1;",$str); - $str = preg_replace("/$temp(\w+);/","&\\1;",$str); + // Decode the temp markers back to entities + $str = preg_replace("/$temp(\d+);/","&#\\1;",$str); + $str = preg_replace("/$temp(\w+);/","&\\1;",$str); - return $str; + return $str; + } } // ------------------------------------------------------------------------ @@ -496,37 +547,40 @@ function form_prep($str = '') * @param array * @return string */ -function parse_form_attributes($attributes, $default) +if (! function_exists('parse_form_attributes')) { - if (is_array($attributes)) + function parse_form_attributes($attributes, $default) { - foreach ($default as $key => $val) + if (is_array($attributes)) { - if (isset($attributes[$key])) + foreach ($default as $key => $val) { - $default[$key] = $attributes[$key]; - unset($attributes[$key]); + if (isset($attributes[$key])) + { + $default[$key] = $attributes[$key]; + unset($attributes[$key]); + } } - } - if (count($attributes) > 0) - { - $default = array_merge($default, $attributes); + if (count($attributes) > 0) + { + $default = array_merge($default, $attributes); + } } - } - $att = ''; - foreach ($default as $key => $val) - { - if ($key == 'value') + $att = ''; + foreach ($default as $key => $val) { - $val = form_prep($val); - } + if ($key == 'value') + { + $val = form_prep($val); + } - $att .= $key . '="' . $val . '" '; - } + $att .= $key . '="' . $val . '" '; + } - return $att; + return $att; + } } ?> \ No newline at end of file diff --git a/system/helpers/html_helper.php b/system/helpers/html_helper.php index a11d23e15..56e25316c 100644 --- a/system/helpers/html_helper.php +++ b/system/helpers/html_helper.php @@ -38,9 +38,12 @@ * @param integer * @return string */ -function heading($data = '', $h = '1') +if (! function_exists('heading')) { - return "".$data.""; + function heading($data = '', $h = '1') + { + return "".$data.""; + } } // ------------------------------------------------------------------------ @@ -55,9 +58,12 @@ function heading($data = '', $h = '1') * @param mixed * @return string */ -function ul($list, $attributes = '') +if (! function_exists('ul')) { - return _list('ul', $list, $attributes); + function ul($list, $attributes = '') + { + return _list('ul', $list, $attributes); + } } // ------------------------------------------------------------------------ @@ -72,9 +78,12 @@ function ul($list, $attributes = '') * @param mixed * @return string */ -function ol($list, $attributes = '') +if (! function_exists('ol')) { - return _list('ol', $list, $attributes); + function ol($list, $attributes = '') + { + return _list('ol', $list, $attributes); + } } // ------------------------------------------------------------------------ @@ -91,63 +100,66 @@ function ol($list, $attributes = '') * @param intiger * @return string */ -function _list($type = 'ul', $list, $attributes = '', $depth = 0) +if (! function_exists('_list')) { - // If an array wasn't submitted there's nothing to do... - if ( ! is_array($list)) + function _list($type = 'ul', $list, $attributes = '', $depth = 0) { - return $list; - } + // 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); + // 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) + // Were any attributes submitted? If so generate a string + if (is_array($attributes)) { - $atts .= ' ' . $key . '="' . $val . '"'; + $atts = ''; + foreach ($attributes as $key => $val) + { + $atts .= ' ' . $key . '="' . $val . '"'; + } + $attributes = $atts; } - $attributes = $atts; - } - // Write the opening list tag - $out .= "<".$type.$attributes.">\n"; + // Write the opening list tag + $out .= "<".$type.$attributes.">\n"; - // Cycle through the list elements. If an array is - // encountered we will recursively call _list() + // 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; + 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 .= "
  • "; + + 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"; } - $out .= "\n"; - } - - // Set the indentation for the closing tag - $out .= str_repeat(" ", $depth); + // Set the indentation for the closing tag + $out .= str_repeat(" ", $depth); - // Write the closing list tag - $out .= "\n"; + // Write the closing list tag + $out .= "\n"; - return $out; + return $out; + } } // ------------------------------------------------------------------------ @@ -159,9 +171,12 @@ function _list($type = 'ul', $list, $attributes = '', $depth = 0) * @param integer * @return string */ -function br($num = 1) +if (! function_exists('br')) { - return str_repeat("
    ", $num); + function br($num = 1) + { + return str_repeat("
    ", $num); + } } // ------------------------------------------------------------------------ @@ -173,9 +188,12 @@ function br($num = 1) * @param integer * @return string */ -function nbs($num = 1) +if (! function_exists('nbs')) { - return str_repeat(" ", $num); + function nbs($num = 1) + { + return str_repeat(" ", $num); + } } // ------------------------------------------------------------------------ @@ -187,18 +205,18 @@ function nbs($num = 1) * @param array * @return string */ -function meta($meta = array(), $newline = "\n") +if (! function_exists('meta')) { - $str = ''; - foreach ($meta as $key => $val) + function meta($meta = array(), $newline = "\n") { - $str .= ''.$newline; - } + $str = ''; + foreach ($meta as $key => $val) + { + $str .= ''.$newline; + } - return $str; + return $str; + } } - - - ?> \ No newline at end of file diff --git a/system/helpers/inflector_helper.php b/system/helpers/inflector_helper.php index b1864cb0b..bf70a6799 100644 --- a/system/helpers/inflector_helper.php +++ b/system/helpers/inflector_helper.php @@ -36,34 +36,36 @@ * @access public * @param string * @return str - */ -function singular($str) -{ - $str = strtolower(trim($str)); - $end = substr($str, -3); + */ +if (! function_exists('singular')) +{ + function singular($str) + { + $str = strtolower(trim($str)); + $end = substr($str, -3); - if ($end == 'ies') - { - $str = substr($str, 0, strlen($str)-3).'y'; - } - elseif ($end == 'ses') - { - $str = substr($str, 0, strlen($str)-2); - } - else - { - $end = substr($str, -1); + if ($end == 'ies') + { + $str = substr($str, 0, strlen($str)-3).'y'; + } + elseif ($end == 'ses') + { + $str = substr($str, 0, strlen($str)-2); + } + else + { + $end = substr($str, -1); - if ($end == 's') - { - $str = substr($str, 0, strlen($str)-1); - } - } + if ($end == 's') + { + $str = substr($str, 0, strlen($str)-1); + } + } - return $str; + return $str; + } } - // -------------------------------------------------------------------- /** @@ -75,32 +77,34 @@ function singular($str) * @param string * @param bool * @return str - */ -function plural($str, $force = FALSE) -{ - $str = strtolower(trim($str)); - $end = substr($str, -1); - - if ($end == 'y') - { - $str = substr($str, 0, strlen($str)-1).'ies'; - } - elseif ($end == 's') - { - if ($force == TRUE) - { - $str .= 'es'; - } - } - else - { - $str .= 's'; - } - - return $str; + */ +if (! function_exists('plural')) +{ + function plural($str, $force = FALSE) + { + $str = strtolower(trim($str)); + $end = substr($str, -1); + + if ($end == 'y') + { + $str = substr($str, 0, strlen($str)-1).'ies'; + } + elseif ($end == 's') + { + if ($force == TRUE) + { + $str .= 'es'; + } + } + else + { + $str .= 's'; + } + + return $str; + } } - // -------------------------------------------------------------------- /** @@ -111,12 +115,15 @@ function plural($str, $force = FALSE) * @access public * @param string * @return str - */ -function camelize($str) -{ - $str = 'x'.strtolower(trim($str)); - $str = ucwords(preg_replace('/[\s_]+/', ' ', $str)); - return substr(str_replace(' ', '', $str), 1); + */ +if (! function_exists('camelize')) +{ + function camelize($str) + { + $str = 'x'.strtolower(trim($str)); + $str = ucwords(preg_replace('/[\s_]+/', ' ', $str)); + return substr(str_replace(' ', '', $str), 1); + } } // -------------------------------------------------------------------- @@ -129,10 +136,13 @@ function camelize($str) * @access public * @param string * @return str - */ -function underscore($str) + */ +if (! function_exists('underscore')) { - return preg_replace('/[\s]+/', '_', strtolower(trim($str))); + function underscore($str) + { + return preg_replace('/[\s]+/', '_', strtolower(trim($str))); + } } // -------------------------------------------------------------------- @@ -145,10 +155,13 @@ function underscore($str) * @access public * @param string * @return str - */ -function humanize($str) -{ - return ucwords(preg_replace('/[_]+/', ' ', strtolower(trim($str)))); + */ +if (! function_exists('humanize')) +{ + function humanize($str) + { + return ucwords(preg_replace('/[_]+/', ' ', strtolower(trim($str)))); + } } ?> \ No newline at end of file diff --git a/system/helpers/security_helper.php b/system/helpers/security_helper.php index 97c9a6ba6..7552fd89c 100644 --- a/system/helpers/security_helper.php +++ b/system/helpers/security_helper.php @@ -35,10 +35,13 @@ * @param string the character set of your data * @return string */ -function xss_clean($str, $charset = 'ISO-8859-1') +if (! function_exists('xss_clean')) { - $CI =& get_instance(); - return $CI->input->xss_clean($str, $charset); + function xss_clean($str, $charset = 'ISO-8859-1') + { + $CI =& get_instance(); + return $CI->input->xss_clean($str, $charset); + } } // -------------------------------------------------------------------- @@ -49,32 +52,35 @@ function xss_clean($str, $charset = 'ISO-8859-1') * @access public * @param string * @return string - */ -function dohash($str, $type = 'sha1') -{ - if ($type == 'sha1') + */ +if (! function_exists('dohash')) +{ + function dohash($str, $type = 'sha1') { - if ( ! function_exists('sha1')) + if ($type == 'sha1') { - if ( ! function_exists('mhash')) - { - require_once(BASEPATH.'libraries/Sha1'.EXT); - $SH = new CI_SHA; - return $SH->generate($str); + if ( ! function_exists('sha1')) + { + if ( ! function_exists('mhash')) + { + require_once(BASEPATH.'libraries/Sha1'.EXT); + $SH = new CI_SHA; + return $SH->generate($str); + } + else + { + return bin2hex(mhash(MHASH_SHA1, $str)); + } } else { - return bin2hex(mhash(MHASH_SHA1, $str)); - } + return sha1($str); + } } else { - return sha1($str); - } - } - else - { - return md5($str); + return md5($str); + } } } @@ -87,12 +93,15 @@ function dohash($str, $type = 'sha1') * @param string * @return string */ -function strip_image_tags($str) +if (! function_exists('strip_image_tags')) { - $str = preg_replace("##", "\\1", $str); - $str = preg_replace("##", "\\1", $str); + function strip_image_tags($str) + { + $str = preg_replace("##", "\\1", $str); + $str = preg_replace("##", "\\1", $str); - return $str; + return $str; + } } // ------------------------------------------------------------------------ @@ -104,9 +113,12 @@ function strip_image_tags($str) * @param string * @return string */ -function encode_php_tags($str) +if (! function_exists('encode_php_tags')) { - return str_replace(array(''), array('<?php', '<?PHP', '<?', '?>'), $str); + function encode_php_tags($str) + { + return str_replace(array(''), array('<?php', '<?PHP', '<?', '?>'), $str); + } } ?> \ No newline at end of file diff --git a/system/helpers/smiley_helper.php b/system/helpers/smiley_helper.php index d61ea7828..f4149478c 100644 --- a/system/helpers/smiley_helper.php +++ b/system/helpers/smiley_helper.php @@ -37,9 +37,11 @@ * @param string field name * @return string */ -function js_insert_smiley($form_name = '', $form_field = '') +if (! function_exists('js_insert_smiley')) { -return << function insert_smiley(smiley) { @@ -47,8 +49,8 @@ return << EOF; -} - + } +} // ------------------------------------------------------------------------ /** @@ -61,37 +63,40 @@ EOF; * @param string the URL to the folder containing the smiley images * @return array */ -function get_clickable_smileys($image_url = '', $smileys = NULL) +if (! function_exists('get_clickable_smileys')) { - if ( ! is_array($smileys)) + function get_clickable_smileys($image_url = '', $smileys = NULL) { - if (FALSE === ($smileys = _get_smiley_array())) + if ( ! is_array($smileys)) { - return $str; - } - } + 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); + // Add a trailing slash to the file path if needed + $image_url = preg_replace("/(.+?)\/*$/", "\\1/", $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]])) + $used = array(); + foreach ($smileys as $key => $val) { - continue; - } + // 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]."\""; + $link[] = "\"".$smileys[$key][3]."\""; - $used[$smileys[$key][0]] = TRUE; - } + $used[$smileys[$key][0]] = TRUE; + } - return $link; + return $link; + } } // ------------------------------------------------------------------------ @@ -106,30 +111,33 @@ function get_clickable_smileys($image_url = '', $smileys = NULL) * @param string the URL to the folder containing the smiley images * @return string */ -function parse_smileys($str = '', $image_url = '', $smileys = NULL) +if (! function_exists('parse_smileys')) { - if ($image_url == '') + function parse_smileys($str = '', $image_url = '', $smileys = NULL) { - return $str; - } - - if ( ! is_array($smileys)) - { - if (FALSE === ($smileys = _get_smiley_array())) + 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); + // 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); - } + foreach ($smileys as $key => $val) + { + $str = str_replace($key, "\"".$smileys[$key][3]."\"", $str); + } - return $str; + return $str; + } } // ------------------------------------------------------------------------ @@ -142,24 +150,24 @@ function parse_smileys($str = '', $image_url = '', $smileys = NULL) * @access private * @return mixed */ -function _get_smiley_array() +if (! function_exists('_get_smiley_array')) { - if ( ! file_exists(APPPATH.'config/smileys'.EXT)) + function _get_smiley_array() { - return FALSE; - } + if ( ! file_exists(APPPATH.'config/smileys'.EXT)) + { + return FALSE; + } - include(APPPATH.'config/smileys'.EXT); + include(APPPATH.'config/smileys'.EXT); - if ( ! isset($smileys) OR ! is_array($smileys)) - { - return FALSE; - } + if ( ! isset($smileys) OR ! is_array($smileys)) + { + return FALSE; + } - return $smileys; + return $smileys; + } } - - - ?> \ No newline at end of file diff --git a/system/helpers/string_helper.php b/system/helpers/string_helper.php index 42bcd57ad..f68f44ac1 100644 --- a/system/helpers/string_helper.php +++ b/system/helpers/string_helper.php @@ -42,10 +42,13 @@ * @param string * @return string */ -function trim_slashes($str) +if (! function_exists('trim_slashes')) { - return trim($str, '/'); -} + function trim_slashes($str) + { + return trim($str, '/'); + } +} // ------------------------------------------------------------------------ @@ -58,21 +61,24 @@ function trim_slashes($str) * @param mixed string or array * @return mixed string or array */ - function strip_slashes($str) - { - if (is_array($str)) - { - foreach ($str as $key => $val) +if (! function_exists('strip_slashes')) +{ + function strip_slashes($str) + { + if (is_array($str)) + { + foreach ($str as $key => $val) + { + $str[$key] = strip_slashes($val); + } + } + else { - $str[$key] = strip_slashes($val); + $str = stripslashes($str); } - } - else - { - $str = stripslashes($str); - } - return $str; + return $str; + } } // ------------------------------------------------------------------------ @@ -86,9 +92,12 @@ function trim_slashes($str) * @param string * @return string */ -function strip_quotes($str) +if (! function_exists('strip_quotes')) { - return str_replace(array('"', "'"), '', $str); + function strip_quotes($str) + { + return str_replace(array('"', "'"), '', $str); + } } // ------------------------------------------------------------------------ @@ -102,9 +111,12 @@ function strip_quotes($str) * @param string * @return string */ -function quotes_to_entities($str) -{ - return str_replace(array("\'","\"","'",'"'), array("'",""","'","""), $str); +if (! function_exists('quotes_to_entities')) +{ + function quotes_to_entities($str) + { + return str_replace(array("\'","\"","'",'"'), array("'",""","'","""), $str); + } } // ------------------------------------------------------------------------ @@ -124,9 +136,12 @@ function quotes_to_entities($str) * @param string * @return string */ -function reduce_double_slashes($str) +if (! function_exists('reduce_double_slashes')) { - return preg_replace("#([^:])//+#", "\\1/", $str); + function reduce_double_slashes($str) + { + return preg_replace("#([^:])//+#", "\\1/", $str); + } } // ------------------------------------------------------------------------ @@ -148,16 +163,19 @@ function reduce_double_slashes($str) * @param bool TRUE/FALSE - whether to trim the character from the beginning/end * @return string */ -function reduce_multiples($str, $character = ',', $trim = FALSE) +if (! function_exists('reduce_multiples')) { - $str = preg_replace('#'.preg_quote($character, '#').'{2,}#', $character, $str); - - if ($trim === TRUE) + function reduce_multiples($str, $character = ',', $trim = FALSE) { - $str = trim($str, $character); - } + $str = preg_replace('#'.preg_quote($character, '#').'{2,}#', $character, $str); + + if ($trim === TRUE) + { + $str = trim($str, $character); + } - return $str; + return $str; + } } // ------------------------------------------------------------------------ @@ -171,36 +189,40 @@ function reduce_multiples($str, $character = ',', $trim = FALSE) * @param string type of random string. Options: alunum, numeric, nozero, unique * @param integer number of characters * @return string - */ -function random_string($type = 'alnum', $len = 8) -{ - switch($type) - { - case 'alnum' : - case 'numeric' : - case 'nozero' : + */ +if (! function_exists('random_string')) +{ + function random_string($type = 'alnum', $len = 8) + { + switch($type) + { + case 'alnum' : + case 'numeric' : + case 'nozero' : - switch ($type) - { - 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' : return md5(uniqid(mt_rand())); - break; + switch ($type) + { + 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' : return md5(uniqid(mt_rand())); + break; + } } } + // ------------------------------------------------------------------------ /** @@ -211,18 +233,21 @@ function random_string($type = 'alnum', $len = 8) * @access public * @param string (as many parameters as needed) * @return string - */ -function alternator() + */ +if (! function_exists('alternator')) { - static $i; - - if (func_num_args() == 0) + function alternator() { - $i = 0; - return ''; + static $i; + + if (func_num_args() == 0) + { + $i = 0; + return ''; + } + $args = func_get_args(); + return $args[($i++ % count($args))]; } - $args = func_get_args(); - return $args[($i++ % count($args))]; } // ------------------------------------------------------------------------ @@ -235,10 +260,12 @@ function alternator() * @param integer number of repeats * @return string */ -function repeater($data, $num = 1) +if (! function_exists('repeater')) { - return (($num > 0) ? str_repeat($data, $num) : ''); -} - + function repeater($data, $num = 1) + { + return (($num > 0) ? str_repeat($data, $num) : ''); + } +} ?> \ No newline at end of file diff --git a/system/helpers/text_helper.php b/system/helpers/text_helper.php index 20bf32335..30cec3148 100644 --- a/system/helpers/text_helper.php +++ b/system/helpers/text_helper.php @@ -38,27 +38,30 @@ * @param string the end character. Usually an ellipsis * @return string */ -function word_limiter($str, $n = 100, $end_char = '…') +if (! function_exists('word_limiter')) { - if (strlen($str) < $n) + function word_limiter($str, $n = 100, $end_char = '…') { - return $str; - } + if (strlen($str) < $n) + { + return $str; + } - $words = explode(' ', preg_replace("/\s+/", ' ', preg_replace("/(\r\n|\r|\n)/", " ", $str))); + $words = explode(' ', preg_replace("/\s+/", ' ', preg_replace("/(\r\n|\r|\n)/", " ", $str))); - if (count($words) <= $n) - { - return $str; - } + if (count($words) <= $n) + { + return $str; + } - $str = ''; - for ($i = 0; $i < $n; $i++) - { - $str .= $words[$i].' '; - } + $str = ''; + for ($i = 0; $i < $n; $i++) + { + $str .= $words[$i].' '; + } - return trim($str).$end_char; + return trim($str).$end_char; + } } // ------------------------------------------------------------------------ @@ -75,28 +78,31 @@ function word_limiter($str, $n = 100, $end_char = '…') * @param string the end character. Usually an ellipsis * @return string */ -function character_limiter($str, $n = 500, $end_char = '…') +if (! function_exists('character_limiter')) { - if (strlen($str) < $n) + function character_limiter($str, $n = 500, $end_char = '…') { - return $str; - } + if (strlen($str) < $n) + { + return $str; + } - $str = preg_replace("/\s+/", ' ', preg_replace("/(\r\n|\r|\n)/", " ", $str)); + $str = preg_replace("/\s+/", ' ', preg_replace("/(\r\n|\r|\n)/", " ", $str)); - if (strlen($str) <= $n) - { - return $str; - } + if (strlen($str) <= $n) + { + return $str; + } - $out = ""; - foreach (explode(' ', trim($str)) as $val) - { - $out .= $val.' '; - if (strlen($out) >= $n) + $out = ""; + foreach (explode(' ', trim($str)) as $val) { - return trim($out).$end_char; - } + $out .= $val.' '; + if (strlen($out) >= $n) + { + return trim($out).$end_char; + } + } } } @@ -111,41 +117,44 @@ function character_limiter($str, $n = 500, $end_char = '…') * @param string * @return string */ -function ascii_to_entities($str) +if (! function_exists('ascii_to_entities')) { - $count = 1; - $out = ''; - $temp = array(); - - for ($i = 0, $s = strlen($str); $i < $s; $i++) - { - $ordinal = ord($str[$i]); + function ascii_to_entities($str) + { + $count = 1; + $out = ''; + $temp = array(); - if ($ordinal < 128) - { - $out .= $str[$i]; - } - else + for ($i = 0, $s = strlen($str); $i < $s; $i++) { - if (count($temp) == 0) + $ordinal = ord($str[$i]); + + if ($ordinal < 128) { - $count = ($ordinal < 224) ? 2 : 3; + $out .= $str[$i]; } + else + { + if (count($temp) == 0) + { + $count = ($ordinal < 224) ? 2 : 3; + } - $temp[] = $ordinal; + $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); + 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(); + $out .= '&#'.$number.';'; + $count = 1; + $temp = array(); + } } } - } - return $out; + return $out; + } } // ------------------------------------------------------------------------ @@ -160,45 +169,48 @@ function ascii_to_entities($str) * @param bool * @return string */ -function entities_to_ascii($str, $all = TRUE) +if (! function_exists('entities_to_ascii')) { - if (preg_match_all('/\&#(\d+)\;/', $str, $matches)) - { - for ($i = 0, $s = count($matches['0']); $i < $s; $i++) - { - $digits = $matches['1'][$i]; + 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 = ''; + $out = ''; - if ($digits < 128) - { - $out .= chr($digits); + 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)); - } + } + 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); + $str = str_replace($matches['0'][$i], $out, $str); + } } - } - if ($all) - { - $str = str_replace(array("&", "<", ">", """, "'", "-"), - array("&","<",">","\"", "'", "-"), - $str); - } + if ($all) + { + $str = str_replace(array("&", "<", ">", """, "'", "-"), + array("&","<",">","\"", "'", "-"), + $str); + } - return $str; + return $str; + } } // ------------------------------------------------------------------------ @@ -216,27 +228,30 @@ function entities_to_ascii($str, $all = TRUE) * @param string the optional replacement value * @return string */ -function word_censor($str, $censored, $replacement = '') +if (! function_exists('word_censor')) { - if ( ! is_array($censored)) - { - return $str; - } - - $str = ' '.$str.' '; - foreach ($censored as $badword) + function word_censor($str, $censored, $replacement = '') { - if ($replacement != '') + if ( ! is_array($censored)) { - $str = preg_replace("/\b(".str_replace('\*', '\w*?', preg_quote($badword)).")\b/i", $replacement, $str); + return $str; } - else + + $str = ' '.$str.' '; + foreach ($censored as $badword) { - $str = preg_replace("/\b(".str_replace('\*', '\w*?', preg_quote($badword)).")\b/ie", "str_repeat('#', strlen('\\1'))", $str); + if ($replacement != '') + { + $str = preg_replace("/\b(".str_replace('\*', '\w*?', preg_quote($badword)).")\b/i", $replacement, $str); + } + else + { + $str = preg_replace("/\b(".str_replace('\*', '\w*?', preg_quote($badword)).")\b/ie", "str_repeat('#', strlen('\\1'))", $str); + } } - } - return trim($str); + return trim($str); + } } // ------------------------------------------------------------------------ @@ -250,45 +265,48 @@ function word_censor($str, $censored, $replacement = '') * @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 - $str = str_replace(array('<', '>'), array('<', '>'), $str); +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. + // 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); + $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. Since we don't know if A) the submitted text has PHP tags, - // or B) whether the PHP tags enclose the entire string, we will add our - // own PHP tags around the string along with some markers to make replacement easier later + // The highlight_string function requires that the text be surrounded + // by PHP tags. Since we don't know if A) the submitted text has PHP tags, + // or B) whether the PHP tags enclose the entire string, we will add our + // own PHP tags around the string along with some markers to make replacement easier later - $str = ''; + $str = ''; - // All the magic happens here, baby! - $str = highlight_string($str, TRUE); + // All the magic happens here, baby! + $str = highlight_string($str, TRUE); - // Prior to PHP 5, the highlight function used icky font tags - // so we'll replace them with span tags. - if (abs(phpversion()) < 5) - { - $str = str_replace(array(''), array(''), $str); - $str = preg_replace('#color="(.*?)"#', 'style="color: \\1"', $str); - } + // Prior to PHP 5, the highlight function used icky font tags + // so we'll replace them with span tags. + if (abs(phpversion()) < 5) + { + $str = str_replace(array(''), array(''), $str); + $str = preg_replace('#color="(.*?)"#', 'style="color: \\1"', $str); + } - // Remove our artificially added PHP - $str = preg_replace("#\.+?tempstart\
    (?:\)?#is", "\n", $str); - $str = preg_replace("#tempend.+#is", "
    \n", $str); + // Remove our artificially added PHP + $str = preg_replace("#\.+?tempstart\
    (?:\)?#is", "\n", $str); + $str = preg_replace("#tempend.+#is", "
    \n", $str); - // Replace our markers back to PHP tags. - $str = str_replace(array('phptagopen', 'phptagclose', 'asptagopen', 'asptagclose', 'backslashtmp', 'scriptclose'), - array('<?', '?>', '<%', '%>', '\\', '</script>'), $str); + // Replace our markers back to PHP tags. + $str = str_replace(array('phptagopen', 'phptagclose', 'asptagopen', 'asptagclose', 'backslashtmp', 'scriptclose'), + array('<?', '?>', '<%', '%>', '\\', '</script>'), $str); - return $str; + return $str; + } } // ------------------------------------------------------------------------ @@ -305,19 +323,22 @@ function highlight_code($str) * @param string the closing tag to end the phrase with * @return string */ -function highlight_phrase($str, $phrase, $tag_open = '', $tag_close = '') +if (! function_exists('highlight_phrase')) { - if ($str == '') + function highlight_phrase($str, $phrase, $tag_open = '', $tag_close = '') { - return ''; - } + if ($str == '') + { + return ''; + } - if ($phrase != '') - { - return preg_replace('/('.preg_quote($phrase, '/').')/i', $tag_open."\\1".$tag_close, $str); - } + if ($phrase != '') + { + return preg_replace('/('.preg_quote($phrase, '/').')/i', $tag_open."\\1".$tag_close, $str); + } - return $str; + return $str; + } } // ------------------------------------------------------------------------ @@ -334,89 +355,91 @@ function highlight_phrase($str, $phrase, $tag_open = '', $tag_close = '< * @param integer the number of characters to wrap at * @return string */ -function word_wrap($str, $charlim = '76') +if (! function_exists('word_wrap')) { - // Se the character limit - if ( ! is_numeric($charlim)) - $charlim = 76; + function word_wrap($str, $charlim = '76') + { + // Se the character limit + if ( ! is_numeric($charlim)) + $charlim = 76; - // Reduce multiple spaces - $str = preg_replace("| +|", " ", $str); + // Reduce multiple spaces + $str = preg_replace("| +|", " ", $str); - // Standardize newlines - $str = preg_replace("/\r\n|\r/", "\n", $str); + // Standardize newlines + $str = preg_replace("/\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++) + // 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)) { - $unwrap[] = $matches['1'][$i]; - $str = str_replace($matches['1'][$i], "{{unwrapped".$i."}}", $str); + 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); + // 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) + // Split the string into individual lines of text and cycle through them + $output = ""; + foreach (explode("\n", $str) as $line) { - $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)) + // Is the line within the allowed character count? + // If so we'll join it to the output and continue + if (strlen($line) <= $charlim) { - break; + $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); - } + // 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; - } + // 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"; - } + $output .= "\n"; + } - // Put our markers back - if (count($unwrap) > 0) - { - foreach ($unwrap as $key => $val) - { - $output = str_replace("{{unwrapped".$key."}}", $val, $output); + // 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); + // Remove the unwrap tags + $output = str_replace(array('{unwrap}', '{/unwrap}'), '', $output); - return $output; + return $output; + } } - ?> \ No newline at end of file diff --git a/system/helpers/typography_helper.php b/system/helpers/typography_helper.php index 4a746c6e4..4d9a1bb6b 100644 --- a/system/helpers/typography_helper.php +++ b/system/helpers/typography_helper.php @@ -34,28 +34,31 @@ * @param string * @return string */ -function nl2br_except_pre($str) +if (! function_exists('nl2br_except_pre')) { - $ex = explode("pre>",$str); - $ct = count($ex); - - $newstr = ""; - for ($i = 0; $i < $ct; $i++) + function nl2br_except_pre($str) { - if (($i % 2) == 0) - { - $newstr .= nl2br($ex[$i]); - } - else + $ex = explode("pre>",$str); + $ct = count($ex); + + $newstr = ""; + for ($i = 0; $i < $ct; $i++) { - $newstr .= $ex[$i]; - } + if (($i % 2) == 0) + { + $newstr .= nl2br($ex[$i]); + } + else + { + $newstr .= $ex[$i]; + } - if ($ct - 1 != $i) - $newstr .= "pre>"; - } + if ($ct - 1 != $i) + $newstr .= "pre>"; + } - return $newstr; + return $newstr; + } } // ------------------------------------------------------------------------ @@ -68,10 +71,13 @@ function nl2br_except_pre($str) * @param string * @return string */ -function auto_typography($str) +if (! function_exists('auto_typography')) { - $TYPE = new Auto_typography(); - return $TYPE->convert($str); + function auto_typography($str) + { + $TYPE = new Auto_typography(); + return $TYPE->convert($str); + } } // ------------------------------------------------------------------------ diff --git a/system/helpers/url_helper.php b/system/helpers/url_helper.php index 9969af044..ad71caa45 100644 --- a/system/helpers/url_helper.php +++ b/system/helpers/url_helper.php @@ -37,10 +37,13 @@ * @param string * @return string */ -function site_url($uri = '') +if (! function_exists('site_url')) { - $CI =& get_instance(); - return $CI->config->site_url($uri); + function site_url($uri = '') + { + $CI =& get_instance(); + return $CI->config->site_url($uri); + } } // ------------------------------------------------------------------------ @@ -53,10 +56,13 @@ function site_url($uri = '') * @access public * @return string */ -function base_url() +if (! function_exists('base_url')) { - $CI =& get_instance(); - return $CI->config->slash_item('base_url'); + function base_url() + { + $CI =& get_instance(); + return $CI->config->slash_item('base_url'); + } } // ------------------------------------------------------------------------ @@ -69,10 +75,13 @@ function base_url() * @access public * @return string */ -function index_page() +if (! function_exists('index_page')) { - $CI =& get_instance(); - return $CI->config->item('index_page'); + function index_page() + { + $CI =& get_instance(); + return $CI->config->item('index_page'); + } } // ------------------------------------------------------------------------ @@ -88,34 +97,37 @@ function index_page() * @param mixed any attributes * @return string */ -function anchor($uri = '', $title = '', $attributes = '') +if (! function_exists('anchor')) { - $title = (string) $title; - - if ( ! is_array($uri)) - { - $site_url = ( ! preg_match('!^\w+://!i', $uri)) ? site_url($uri) : $uri; - } - else + function anchor($uri = '', $title = '', $attributes = '') { - $site_url = site_url($uri); - } + $title = (string) $title; - if ($title == '') - { - $title = $site_url; - } + 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 = ' title="'.$title.'"'; - } - else - { - $attributes = _parse_attributes($attributes); - } + if ($attributes == '') + { + $attributes = ' title="'.$title.'"'; + } + else + { + $attributes = _parse_attributes($attributes); + } - return ''.$title.''; + return ''.$title.''; + } } // ------------------------------------------------------------------------ @@ -132,33 +144,36 @@ function anchor($uri = '', $title = '', $attributes = '') * @param mixed any attributes * @return string */ -function anchor_popup($uri = '', $title = '', $attributes = FALSE) -{ - $title = (string) $title; +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; + $site_url = ( ! preg_match('!^\w+://!i', $uri)) ? site_url($uri) : $uri; - if ($title == '') - { - $title = $site_url; - } + if ($title == '') + { + $title = $site_url; + } - if ($attributes === FALSE) - { - return "".$title.""; - } + if ($attributes === FALSE) + { + return "".$title.""; + } - if ( ! is_array($attributes)) - { - $attributes = array(); - } + 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]; - } + 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]; + } - return "".$title.""; + return "".$title.""; + } } // ------------------------------------------------------------------------ @@ -172,18 +187,21 @@ function anchor_popup($uri = '', $title = '', $attributes = FALSE) * @param mixed any attributes * @return string */ -function mailto($email, $title = '', $attributes = '') +if (! function_exists('mailto')) { - $title = (string) $title; - - if ($title == "") + function mailto($email, $title = '', $attributes = '') { - $title = $email; - } + $title = (string) $title; - $attributes = _parse_attributes($attributes); + if ($title == "") + { + $title = $email; + } - return ''.$title.''; + $attributes = _parse_attributes($attributes); + + return ''.$title.''; + } } // ------------------------------------------------------------------------ @@ -199,100 +217,103 @@ function mailto($email, $title = '', $attributes = '') * @param mixed any attributes * @return string */ -function safe_mailto($email, $title = '', $attributes = '') +if (! function_exists('safe_mailto')) { - $title = (string) $title; - - if ($title == "") + function safe_mailto($email, $title = '', $attributes = '') { - $title = $email; - } + $title = (string) $title; + + if ($title == "") + { + $title = $email; + } - for ($i = 0; $i < 16; $i++) - { - $x[] = substr(' $val) + if (is_array($attributes)) { - $x[] = ' '.$key.'="'; - for ($i = 0; $i < strlen($val); $i++) + foreach ($attributes as $key => $val) { - $x[] = "|".ord(substr($val, $i, 1)); + $x[] = ' '.$key.'="'; + for ($i = 0; $i < strlen($val); $i++) + { + $x[] = "|".ord(substr($val, $i, 1)); + } + $x[] = '"'; } - $x[] = '"'; } - } - else - { - for ($i = 0; $i < strlen($attributes); $i++) - { - $x[] = substr($attributes, $i, 1); + 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]); + $x[] = '>'; - if ($ordinal < 128) + $temp = array(); + for ($i = 0; $i < strlen($title); $i++) { - $x[] = "|".$ordinal; - } - else - { - if (count($temp) == 0) + $ordinal = ord($title[$i]); + + if ($ordinal < 128) { - $count = ($ordinal < 224) ? 2 : 3; + $x[] = "|".$ordinal; } - - $temp[] = $ordinal; - if (count($temp) == $count) + else { - $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(); + 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[] = '<'; $x[] = '/'; $x[] = 'a'; $x[] = '>'; - $x = array_reverse($x); - ob_start(); + $x = array_reverse($x); + ob_start(); -?>= 0; i=i-1){ + if (l[i].substring(0, 1) == '|') document.write("&#"+unescape(l[i].substring(1))+";"); + else document.write(unescape(l[i]));} + //]]> + http'. - $matches['4'][$i].'://'. - $matches['5'][$i]. - $matches['6'][$i].''. - $period, $str); + $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 < sizeof($matches['0']); $i++) + if ($type != 'url') + { + if (preg_match_all("/([a-zA-Z0-9_\.\-]+)@([a-zA-Z0-9\-]+)\.([a-zA-Z0-9\-\.]*)/i", $str, $matches)) { - $period = ''; - if (preg_match("|\.$|", $matches['3'][$i])) + for ($i = 0; $i < sizeof($matches['0']); $i++) { - $period = '.'; - $matches['3'][$i] = substr($matches['3'][$i], 0, -1); - } + $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); - } + $str = str_replace($matches['0'][$i], safe_mailto($matches['1'][$i].'@'.$matches['2'][$i].'.'.$matches['3'][$i]).$period, $str); + } + } } + return $str; } - return $str; } // ------------------------------------------------------------------------ @@ -373,19 +397,22 @@ function auto_link($str, $type = 'both', $popup = FALSE) * @param string the URL * @return string */ -function prep_url($str = '') +if (! function_exists('prep_url')) { - if ($str == 'http://' OR $str == '') + function prep_url($str = '') { - return ''; - } + if ($str == 'http://' OR $str == '') + { + return ''; + } - if (substr($str, 0, 7) != 'http://' && substr($str, 0, 8) != 'https://') - { - $str = 'http://'.$str; - } + if (substr($str, 0, 7) != 'http://' && substr($str, 0, 8) != 'https://') + { + $str = 'http://'.$str; + } - return $str; + return $str; + } } // ------------------------------------------------------------------------ @@ -402,36 +429,39 @@ function prep_url($str = '') * @param string the separator: dash, or underscore * @return string */ -function url_title($str, $separator = 'dash') +if (! function_exists('url_title')) { - if ($separator == 'dash') - { - $search = '_'; - $replace = '-'; - } - else + function url_title($str, $separator = 'dash') { - $search = '-'; - $replace = '_'; - } + if ($separator == 'dash') + { + $search = '_'; + $replace = '-'; + } + else + { + $search = '-'; + $replace = '_'; + } - $trans = array( - $search => $replace, - "\s+" => $replace, - "[^a-z0-9".$replace."]" => '', - $replace."+" => $replace, - $replace."$" => '', - "^".$replace => '' - ); + $trans = array( + $search => $replace, + "\s+" => $replace, + "[^a-z0-9".$replace."]" => '', + $replace."+" => $replace, + $replace."$" => '', + "^".$replace => '' + ); - $str = strip_tags(strtolower($str)); + $str = strip_tags(strtolower($str)); - foreach ($trans as $key => $val) - { - $str = preg_replace("#".$key."#", $val, $str); - } + foreach ($trans as $key => $val) + { + $str = preg_replace("#".$key."#", $val, $str); + } - return trim(stripslashes($str)); + return trim(stripslashes($str)); + } } // ------------------------------------------------------------------------ @@ -446,16 +476,19 @@ function url_title($str, $separator = 'dash') * @param string the method: location or redirect * @return string */ -function redirect($uri = '', $method = 'location') +if (! function_exists('redirect')) { - switch($method) + function redirect($uri = '', $method = 'location') { - case 'refresh' : header("Refresh:0;url=".site_url($uri)); - break; - default : header("Location: ".site_url($uri)); - break; + switch($method) + { + case 'refresh' : header("Refresh:0;url=".site_url($uri)); + break; + default : header("Location: ".site_url($uri)); + break; + } + exit; } - exit; } // ------------------------------------------------------------------------ @@ -470,32 +503,35 @@ function redirect($uri = '', $method = 'location') * @param bool * @return string */ -function _parse_attributes($attributes, $javascript = FALSE) +if (! function_exists('_parse_attributes')) { - if (is_string($attributes)) + function _parse_attributes($attributes, $javascript = FALSE) { - return ($attributes != '') ? ' '.$attributes : ''; - } + if (is_string($attributes)) + { + return ($attributes != '') ? ' '.$attributes : ''; + } - $att = ''; - foreach ($attributes as $key => $val) - { - if ($javascript == TRUE) + $att = ''; + foreach ($attributes as $key => $val) { - $att .= $key . '=' . $val . ','; + if ($javascript == TRUE) + { + $att .= $key . '=' . $val . ','; + } + else + { + $att .= ' ' . $key . '="' . $val . '"'; + } } - else + + if ($javascript == TRUE AND $att != '') { - $att .= ' ' . $key . '="' . $val . '"'; + $att = substr($att, 0, -1); } - } - if ($javascript == TRUE AND $att != '') - { - $att = substr($att, 0, -1); + return $att; } - - return $att; } ?> \ No newline at end of file diff --git a/system/helpers/xml_helper.php b/system/helpers/xml_helper.php index 1a2c7379c..5aa6de9ec 100644 --- a/system/helpers/xml_helper.php +++ b/system/helpers/xml_helper.php @@ -34,25 +34,27 @@ * @param string * @return string */ -function xml_convert($str) +if (! function_exists('xml_convert')) { - $temp = '__TEMP_AMPERSANDS__'; - - // Replace entities to temporary markers so that - // ampersands won't get messed up - $str = preg_replace("/&#(\d+);/", "$temp\\1;", $str); - $str = preg_replace("/&(\w+);/", "$temp\\1;", $str); + function xml_convert($str) + { + $temp = '__TEMP_AMPERSANDS__'; + + // Replace entities to temporary markers so that + // ampersands won't get messed up + $str = preg_replace("/&#(\d+);/", "$temp\\1;", $str); + $str = preg_replace("/&(\w+);/", "$temp\\1;", $str); - $str = str_replace(array("&","<",">","\"", "'", "-"), - array("&", "<", ">", """, "'", "-"), - $str); + $str = str_replace(array("&","<",">","\"", "'", "-"), + array("&", "<", ">", """, "'", "-"), + $str); - // Decode the temp markers back to entities - $str = preg_replace("/$temp(\d+);/","&#\\1;",$str); - $str = preg_replace("/$temp(\w+);/","&\\1;", $str); + // Decode the temp markers back to entities + $str = preg_replace("/$temp(\d+);/","&#\\1;",$str); + $str = preg_replace("/$temp(\w+);/","&\\1;", $str); - return $str; + return $str; + } } - ?> \ No newline at end of file diff --git a/system/libraries/Loader.php b/system/libraries/Loader.php index 320a43a00..a59d6e38e 100644 --- a/system/libraries/Loader.php +++ b/system/libraries/Loader.php @@ -366,8 +366,23 @@ class CI_Loader { { continue; } + + $ext_helper = APPPATH.'helpers/'.config_item('subclass_prefix').$helper.EXT; - if (file_exists(APPPATH.'helpers/'.$helper.EXT)) + // Is this a helper extension request? + if (file_exists($ext_helper)) + { + $base_helper = BASEPATH.'helpers/'.$helper.EXT; + + if ( ! file_exists($base_helper)) + { + show_error('Unable to load the requested file: helpers/'.$helper.EXT); + } + + include_once($ext_helper); + include_once($base_helper); + } + elseif (file_exists(APPPATH.'helpers/'.$helper.EXT)) { include_once(APPPATH.'helpers/'.$helper.EXT); } -- cgit v1.2.3-24-g4f1b From 31438fe2339067f7bf677eb0695c635960c5faa9 Mon Sep 17 00:00:00 2001 From: Derek Allard Date: Tue, 29 Jan 2008 01:07:06 +0000 Subject: Removed an unused parameter from Profiler (#3332). --- system/libraries/Profiler.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system') diff --git a/system/libraries/Profiler.php b/system/libraries/Profiler.php index 21c2135cc..eb2f25094 100644 --- a/system/libraries/Profiler.php +++ b/system/libraries/Profiler.php @@ -320,7 +320,7 @@ class CI_Profiler { * @access private * @return string */ - function run($output = '') + function run() { $output = '
    '; $output .= "
    "; -- cgit v1.2.3-24-g4f1b From 9ece7433d90375a3ad67e1310e35e198a15645fe Mon Sep 17 00:00:00 2001 From: Derek Allard Date: Tue, 29 Jan 2008 01:15:19 +0000 Subject: fixed an error message, and added one if the path is invalid. --- system/libraries/Upload.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'system') diff --git a/system/libraries/Upload.php b/system/libraries/Upload.php index dd7012211..2a3f53d4b 100644 --- a/system/libraries/Upload.php +++ b/system/libraries/Upload.php @@ -137,13 +137,14 @@ class CI_Upload { // Is $_FILES[$field] set? If not, no reason to continue. if ( ! isset($_FILES[$field])) { - $this->set_error('upload_userfile_not_set'); + $this->set_error('upload_no_file_selected'); return FALSE; } // Is the upload path valid? if ( ! $this->validate_upload_path()) { + $this->set_error('upload_no_filepath'); return FALSE; } -- cgit v1.2.3-24-g4f1b From 0975bcc8d56392af3d07f1e2af941b727d6dc389 Mon Sep 17 00:00:00 2001 From: Derek Allard Date: Tue, 29 Jan 2008 17:21:27 +0000 Subject: Fixed a bug (#3328) where the smiley helper might return an undefined variable. --- system/helpers/smiley_helper.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system') diff --git a/system/helpers/smiley_helper.php b/system/helpers/smiley_helper.php index f4149478c..25962eb54 100644 --- a/system/helpers/smiley_helper.php +++ b/system/helpers/smiley_helper.php @@ -71,7 +71,7 @@ if (! function_exists('get_clickable_smileys')) { if (FALSE === ($smileys = _get_smiley_array())) { - return $str; + return $smileys; } } -- cgit v1.2.3-24-g4f1b From 878cd70078c579f6c0ce8ad2e311518c8a688d17 Mon Sep 17 00:00:00 2001 From: Derek Allard Date: Tue, 29 Jan 2008 18:00:03 +0000 Subject: Fixed a bug (#2858) which referenced a wrong variable in the Image class. --- system/libraries/Image_lib.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'system') diff --git a/system/libraries/Image_lib.php b/system/libraries/Image_lib.php index 9a78adf62..239865b9d 100644 --- a/system/libraries/Image_lib.php +++ b/system/libraries/Image_lib.php @@ -473,7 +473,9 @@ class CI_Image_lib { // If the target width/height match the source, AND if // the new file name is not equal to the old file name // we'll simply make a copy of the original with the new name - if (($this->orig_width == $this->width AND $this->orig_height == $this->height) AND ($this->source_image != $this->dest_image)) + if (($this->orig_width == $this->width AND $this->orig_height == $this->height) AND ($this->source_image != $this->new_image)) + + { if ( ! @copy($this->full_src_path, $this->full_dst_path)) { -- cgit v1.2.3-24-g4f1b From 1d3137b68e41bff7541fa249d8946409d463f7f2 Mon Sep 17 00:00:00 2001 From: Derek Allard Date: Tue, 29 Jan 2008 18:44:07 +0000 Subject: fixed a dynamic_output error, and a gdversion bug. --- system/libraries/Image_lib.php | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) (limited to 'system') diff --git a/system/libraries/Image_lib.php b/system/libraries/Image_lib.php index 239865b9d..16a23f12a 100644 --- a/system/libraries/Image_lib.php +++ b/system/libraries/Image_lib.php @@ -449,14 +449,14 @@ class CI_Image_lib { if ($action == 'crop') { // If the target width/height match the source then it's pointless to crop, right? - if ($this->width >= $this->orig_width AND $this->height >= $this->orig_height) + // So if dynamic output isn't on, then we'll return true so the user thinks + // the process succeeded. It'll be our little secret... + + if ($this->width >= $this->orig_width AND $this->height >= $this->orig_height AND $this->dynamic_output !== TRUE) { - // We'll return true so the user thinks the process succeeded. - // It'll be our little secret... - return TRUE; } - + // Reassign the source width/height if cropping $this->orig_width = $this->width; $this->orig_height = $this->height; @@ -473,9 +473,7 @@ class CI_Image_lib { // If the target width/height match the source, AND if // the new file name is not equal to the old file name // we'll simply make a copy of the original with the new name - if (($this->orig_width == $this->width AND $this->orig_height == $this->height) AND ($this->source_image != $this->new_image)) - - + if (($this->orig_width == $this->width AND $this->orig_height == $this->height) AND ($this->source_image != $this->new_image)) { if ( ! @copy($this->full_src_path, $this->full_dst_path)) { @@ -499,7 +497,7 @@ class CI_Image_lib { } // Create The Image - if ($this->image_library == 'gd2' AND function_exists('imagecreatetruecolor') AND $v2_override == FALSE) + if ($this->image_library == 'gd2' AND function_exists('imagecreatetruecolor')) { $create = 'imagecreatetruecolor'; $copy = 'imagecopyresampled'; -- cgit v1.2.3-24-g4f1b From c6ad0237eb6957046343ca654ab1c7d26787d466 Mon Sep 17 00:00:00 2001 From: Derek Jones Date: Tue, 29 Jan 2008 18:44:54 +0000 Subject: Abstracted FROM table listing in Active Record for databases that do not support parenthetic grouping of tables to explicitly define operator precedence --- system/database/DB_active_rec.php | 2 +- system/database/drivers/mssql/mssql_driver.php | 22 ++++++++++++++++++++++ system/database/drivers/mysql/mysql_driver.php | 22 ++++++++++++++++++++++ system/database/drivers/mysqli/mysqli_driver.php | 22 ++++++++++++++++++++++ system/database/drivers/oci8/oci8_driver.php | 22 ++++++++++++++++++++++ system/database/drivers/odbc/odbc_driver.php | 22 ++++++++++++++++++++++ system/database/drivers/postgre/postgre_driver.php | 22 ++++++++++++++++++++++ system/database/drivers/sqlite/sqlite_driver.php | 22 ++++++++++++++++++++++ 8 files changed, 155 insertions(+), 1 deletion(-) (limited to 'system') diff --git a/system/database/DB_active_rec.php b/system/database/DB_active_rec.php index 1ad4f3d1f..37bf9ed05 100644 --- a/system/database/DB_active_rec.php +++ b/system/database/DB_active_rec.php @@ -1343,7 +1343,7 @@ class CI_DB_active_record extends CI_DB_driver { if (count($this->ar_from) > 0) { $sql .= "\nFROM "; - $sql .= '(' . implode(', ', $this->ar_from) . ')'; + $sql .= $this->_from_tables($this->ar_from); } if (count($this->ar_join) > 0) diff --git a/system/database/drivers/mssql/mssql_driver.php b/system/database/drivers/mssql/mssql_driver.php index e0c4db75c..ad747d4ad 100644 --- a/system/database/drivers/mssql/mssql_driver.php +++ b/system/database/drivers/mssql/mssql_driver.php @@ -438,6 +438,28 @@ class CI_DB_mssql_driver extends CI_DB { // -------------------------------------------------------------------- + /** + * From Tables + * + * This function implicitly groups FROM tables so there is no confusion + * about operator precedence in harmony with SQL standards + * + * @access public + * @param type + * @return type + */ + function _from_tables($tables) + { + if (! is_array($tables)) + { + $tables = array($tables); + } + + return implode(', ', $tables); + } + + // -------------------------------------------------------------------- + /** * Insert statement * diff --git a/system/database/drivers/mysql/mysql_driver.php b/system/database/drivers/mysql/mysql_driver.php index 6e53537b4..f00257250 100644 --- a/system/database/drivers/mysql/mysql_driver.php +++ b/system/database/drivers/mysql/mysql_driver.php @@ -479,6 +479,28 @@ class CI_DB_mysql_driver extends CI_DB { // -------------------------------------------------------------------- + /** + * From Tables + * + * This function implicitly groups FROM tables so there is no confusion + * about operator precedence in harmony with SQL standards + * + * @access public + * @param type + * @return type + */ + function _from_tables($tables) + { + if (! is_array($tables)) + { + $tables = array($tables); + } + + return '('.implode(', ', $tables).')'; + } + + // -------------------------------------------------------------------- + /** * Insert statement * diff --git a/system/database/drivers/mysqli/mysqli_driver.php b/system/database/drivers/mysqli/mysqli_driver.php index d645cc820..b2e97f927 100644 --- a/system/database/drivers/mysqli/mysqli_driver.php +++ b/system/database/drivers/mysqli/mysqli_driver.php @@ -473,6 +473,28 @@ class CI_DB_mysqli_driver extends CI_DB { // -------------------------------------------------------------------- + /** + * From Tables + * + * This function implicitly groups FROM tables so there is no confusion + * about operator precedence in harmony with SQL standards + * + * @access public + * @param type + * @return type + */ + function _from_tables($tables) + { + if (! is_array($tables)) + { + $tables = array($tables); + } + + return '('.implode(', ', $tables).')'; + } + + // -------------------------------------------------------------------- + /** * Insert statement * diff --git a/system/database/drivers/oci8/oci8_driver.php b/system/database/drivers/oci8/oci8_driver.php index 99f7d57bd..ddc0fba99 100644 --- a/system/database/drivers/oci8/oci8_driver.php +++ b/system/database/drivers/oci8/oci8_driver.php @@ -584,6 +584,28 @@ class CI_DB_oci8_driver extends CI_DB { // -------------------------------------------------------------------- + /** + * From Tables + * + * This function implicitly groups FROM tables so there is no confusion + * about operator precedence in harmony with SQL standards + * + * @access public + * @param type + * @return type + */ + function _from_tables($tables) + { + if (! is_array($tables)) + { + $tables = array($tables); + } + + return '('.implode(', ', $tables).')'; + } + + // -------------------------------------------------------------------- + /** * Insert statement * diff --git a/system/database/drivers/odbc/odbc_driver.php b/system/database/drivers/odbc/odbc_driver.php index 604dd778c..03c0e6a86 100644 --- a/system/database/drivers/odbc/odbc_driver.php +++ b/system/database/drivers/odbc/odbc_driver.php @@ -449,6 +449,28 @@ class CI_DB_odbc_driver extends CI_DB { // -------------------------------------------------------------------- + /** + * From Tables + * + * This function implicitly groups FROM tables so there is no confusion + * about operator precedence in harmony with SQL standards + * + * @access public + * @param type + * @return type + */ + function _from_tables($tables) + { + if (! is_array($tables)) + { + $tables = array($tables); + } + + return '('.implode(', ', $tables).')'; + } + + // -------------------------------------------------------------------- + /** * Insert statement * diff --git a/system/database/drivers/postgre/postgre_driver.php b/system/database/drivers/postgre/postgre_driver.php index 96cf2dfe9..20f91650a 100644 --- a/system/database/drivers/postgre/postgre_driver.php +++ b/system/database/drivers/postgre/postgre_driver.php @@ -469,6 +469,28 @@ class CI_DB_postgre_driver extends CI_DB { // -------------------------------------------------------------------- + /** + * From Tables + * + * This function implicitly groups FROM tables so there is no confusion + * about operator precedence in harmony with SQL standards + * + * @access public + * @param type + * @return type + */ + function _from_tables($tables) + { + if (! is_array($tables)) + { + $tables = array($tables); + } + + return '('.implode(', ', $tables).')'; + } + + // -------------------------------------------------------------------- + /** * Insert statement * diff --git a/system/database/drivers/sqlite/sqlite_driver.php b/system/database/drivers/sqlite/sqlite_driver.php index 9cc69bb63..38febca29 100644 --- a/system/database/drivers/sqlite/sqlite_driver.php +++ b/system/database/drivers/sqlite/sqlite_driver.php @@ -465,6 +465,28 @@ class CI_DB_sqlite_driver extends CI_DB { // -------------------------------------------------------------------- + /** + * From Tables + * + * This function implicitly groups FROM tables so there is no confusion + * about operator precedence in harmony with SQL standards + * + * @access public + * @param type + * @return type + */ + function _from_tables($tables) + { + if (! is_array($tables)) + { + $tables = array($tables); + } + + return '('.implode(', ', $tables).')'; + } + + // -------------------------------------------------------------------- + /** * Insert statement * -- cgit v1.2.3-24-g4f1b From c9c6faa5e07ad9dd33da9fb18cc4d146c95fcc49 Mon Sep 17 00:00:00 2001 From: Derek Jones Date: Tue, 29 Jan 2008 18:54:04 +0000 Subject: added verbose comment regarding the $v2_override change --- system/libraries/Image_lib.php | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'system') diff --git a/system/libraries/Image_lib.php b/system/libraries/Image_lib.php index 16a23f12a..d9ed761c5 100644 --- a/system/libraries/Image_lib.php +++ b/system/libraries/Image_lib.php @@ -497,6 +497,12 @@ class CI_Image_lib { } // Create The Image + // + // old conditional which users report cause problems with shared GD libs who report themselves as "2.0 or greater" + // it appears that this is no longer the issue that it was in 2004, so we've removed it, retaining it in the comment + // below should that ever prove inaccurate. + // + // if ($this->image_library == 'gd2' AND function_exists('imagecreatetruecolor') AND $v2_override == FALSE) if ($this->image_library == 'gd2' AND function_exists('imagecreatetruecolor')) { $create = 'imagecreatetruecolor'; -- cgit v1.2.3-24-g4f1b From 26fba4676ffee5c03d9c7b99d31c9f230cc5c242 Mon Sep 17 00:00:00 2001 From: Derek Jones Date: Tue, 29 Jan 2008 18:59:12 +0000 Subject: fixed bug (#3331) with image destination path in image_process_ntpbm() --- system/libraries/Image_lib.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system') diff --git a/system/libraries/Image_lib.php b/system/libraries/Image_lib.php index d9ed761c5..260075ecd 100644 --- a/system/libraries/Image_lib.php +++ b/system/libraries/Image_lib.php @@ -692,7 +692,7 @@ class CI_Image_lib { // we have to rename the temp file. copy ($this->dest_folder.'netpbm.tmp', $this->full_dst_path); unlink ($this->dest_folder.'netpbm.tmp'); - @chmod($dst_image, 0777); + @chmod($this->full_dst_path, 0777); return TRUE; } -- cgit v1.2.3-24-g4f1b From 11c75eab4d04b9c88b0096015fb3c0711555bf9a Mon Sep 17 00:00:00 2001 From: Derek Allard Date: Tue, 29 Jan 2008 19:35:31 +0000 Subject: Removed support for db_backup in MySQLi due to incompatible functions. --- system/database/drivers/mysqli/mysqli_utility.php | 138 +--------------------- 1 file changed, 3 insertions(+), 135 deletions(-) (limited to 'system') diff --git a/system/database/drivers/mysqli/mysqli_utility.php b/system/database/drivers/mysqli/mysqli_utility.php index bb1f6f917..4ab2bb1d1 100644 --- a/system/database/drivers/mysqli/mysqli_utility.php +++ b/system/database/drivers/mysqli/mysqli_utility.php @@ -78,143 +78,11 @@ class CI_DB_mysqli_utility extends CI_DB_utility { */ 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 = mysqli_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 - { - // Do a little formatting... - $v = str_replace(array("\x00", "\x0a", "\x0d", "\x1a"), array('\0', '\n', '\r', '\Z'), $v); - $v = str_replace(array("\n", "\r", "\t"), array('\n', '\r', '\t'), $v); - $v = str_replace('\\', '\\\\', $v); - $v = str_replace('\'', '\\\'', $v); - $v = str_replace('\\\n', '\n', $v); - $v = str_replace('\\\r', '\r', $v); - $v = str_replace('\\\t', '\t', $v); - - // 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; + // Currently unsupported + return $this->db->display_error('db_unsuported_feature'); } + /** * * The functions below have been deprecated as of 1.6, and are only here for backwards -- cgit v1.2.3-24-g4f1b From 1c8dd3ad67bfa8da796bc0ebbfdf72be8d5bafb1 Mon Sep 17 00:00:00 2001 From: Derek Jones Date: Tue, 29 Jan 2008 20:20:00 +0000 Subject: fixed bug #3314 where the top level path would be deleted along with files in delete_files() --- system/helpers/file_helper.php | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) (limited to 'system') diff --git a/system/helpers/file_helper.php b/system/helpers/file_helper.php index bbf340930..ef07de76c 100644 --- a/system/helpers/file_helper.php +++ b/system/helpers/file_helper.php @@ -122,7 +122,7 @@ if (! function_exists('delete_files')) { // Trim the trailing slash $path = preg_replace("|^(.+?)/*$|", "\\1", $path); - + if ( ! $current_dir = @opendir($path)) return; @@ -132,8 +132,7 @@ if (! function_exists('delete_files')) { if (is_dir($path.'/'.$filename)) { - $level++; - delete_files($path.'/'.$filename, $del_dir, $level); + delete_files($path.'/'.$filename, $del_dir, $level + 1); } else { -- cgit v1.2.3-24-g4f1b From 44dbc7826dc34c86829b734fcec0015271b7873f Mon Sep 17 00:00:00 2001 From: Derek Allard Date: Tue, 29 Jan 2008 20:38:55 +0000 Subject: Fixed a bug (#3024) in which master_dim wasn't getting reset by clear() in the Image library. Documented clear() --- system/libraries/Image_lib.php | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) (limited to 'system') diff --git a/system/libraries/Image_lib.php b/system/libraries/Image_lib.php index 260075ecd..dbb6f82e0 100644 --- a/system/libraries/Image_lib.php +++ b/system/libraries/Image_lib.php @@ -110,7 +110,10 @@ class CI_Image_lib { foreach ($props as $val) { $this->$val = ''; - } + } + + // special consideration for master_dim + $this->master_dim = 'auto'; } // -------------------------------------------------------------------- @@ -497,12 +500,6 @@ class CI_Image_lib { } // Create The Image - // - // old conditional which users report cause problems with shared GD libs who report themselves as "2.0 or greater" - // it appears that this is no longer the issue that it was in 2004, so we've removed it, retaining it in the comment - // below should that ever prove inaccurate. - // - // if ($this->image_library == 'gd2' AND function_exists('imagecreatetruecolor') AND $v2_override == FALSE) if ($this->image_library == 'gd2' AND function_exists('imagecreatetruecolor')) { $create = 'imagecreatetruecolor'; @@ -692,7 +689,7 @@ class CI_Image_lib { // we have to rename the temp file. copy ($this->dest_folder.'netpbm.tmp', $this->full_dst_path); unlink ($this->dest_folder.'netpbm.tmp'); - @chmod($this->full_dst_path, 0777); + @chmod($dst_image, 0777); return TRUE; } -- cgit v1.2.3-24-g4f1b From 15a34776698d8c42d109a7568468a6d08c5817e9 Mon Sep 17 00:00:00 2001 From: Derek Allard Date: Tue, 29 Jan 2008 21:09:26 +0000 Subject: fixed a syntax bug in strip_imge_tags --- system/libraries/Validation.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system') diff --git a/system/libraries/Validation.php b/system/libraries/Validation.php index 7720a7d17..c81ad6b88 100644 --- a/system/libraries/Validation.php +++ b/system/libraries/Validation.php @@ -731,7 +731,7 @@ class CI_Validation { */ function strip_image_tags($str) { - $_POST[$this->_current_field] = $this->input->strip_image_tags($str); + $_POST[$this->_current_field] = $this->CI->input->strip_image_tags($str); } // -------------------------------------------------------------------- -- cgit v1.2.3-24-g4f1b From 2712610b7ce4b8beb6984558e4a919c66fb40ca9 Mon Sep 17 00:00:00 2001 From: Derek Jones Date: Tue, 29 Jan 2008 23:43:09 +0000 Subject: fixed bug (#3321) where the uri_string was not being set properly when retrieved from $_GET (segment based GET, not ?c=controller) --- system/libraries/URI.php | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) (limited to 'system') diff --git a/system/libraries/URI.php b/system/libraries/URI.php index 1349ebedb..6c8eb2e23 100644 --- a/system/libraries/URI.php +++ b/system/libraries/URI.php @@ -67,11 +67,7 @@ class CI_URI { // can be unreliable in some environments if (is_array($_GET) AND count($_GET) == 1) { - // Note: Due to a bug in current() that affects some versions - // of PHP we can not pass function call directly into it - $key = array_keys($_GET); - $index = current($key); - $this->uri_string = $_GET[$index]; + $this->uri_string = key($_GET); return; } -- cgit v1.2.3-24-g4f1b From 240292e5a7b9ed9ead1b88bc169ad3aeb15900d6 Mon Sep 17 00:00:00 2001 From: Derek Jones Date: Wed, 30 Jan 2008 00:18:05 +0000 Subject: fixed bug (#3284) where the $rsegment array would not be set properly if the requested URI contained more segments than the routed URI. --- system/libraries/URI.php | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'system') diff --git a/system/libraries/URI.php b/system/libraries/URI.php index 6c8eb2e23..8de26f933 100644 --- a/system/libraries/URI.php +++ b/system/libraries/URI.php @@ -246,8 +246,9 @@ class CI_URI { function _reindex_segments() { // Is the routed segment array different then the main segment array? - $diff = (count(array_diff($this->rsegments, $this->segments)) == 0) ? FALSE : TRUE; - + // have to compute the diff both ways since PHP returns only values in $arr1 that are not in $arr2. + $diff = (array_diff($this->rsegments, $this->segments) != array_diff($this->segments, $this->rsegments)) ? TRUE : FALSE; + $i = 1; foreach ($this->segments as $val) { -- cgit v1.2.3-24-g4f1b From f37fa6edd5f6e12de1ad93861fd640fa8e939f42 Mon Sep 17 00:00:00 2001 From: Derek Allard Date: Wed, 30 Jan 2008 01:15:03 +0000 Subject: Fixed a bug (#2679) where the "previous" pagination link would get drawn on the first page. --- system/libraries/Pagination.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system') diff --git a/system/libraries/Pagination.php b/system/libraries/Pagination.php index ba1572f66..28b74f1f0 100644 --- a/system/libraries/Pagination.php +++ b/system/libraries/Pagination.php @@ -165,7 +165,7 @@ class CI_Pagination { } // Render the "previous" link - if (($this->cur_page - $this->num_links) >= 0) + if ($this->cur_page != 1) { $i = $uri_page_number - $this->per_page; if ($i == 0) $i = ''; -- cgit v1.2.3-24-g4f1b From d45379e879419a3de63ab226b2458c4764c7c001 Mon Sep 17 00:00:00 2001 From: Derek Jones Date: Wed, 30 Jan 2008 03:47:03 +0000 Subject: Fixed a bug (#3269) where the rsegment array would not be set properly when there is no URI request. --- system/libraries/Router.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'system') diff --git a/system/libraries/Router.php b/system/libraries/Router.php index df72cea26..fd0ffa22a 100644 --- a/system/libraries/Router.php +++ b/system/libraries/Router.php @@ -100,7 +100,8 @@ class CI_Router { $this->set_class($this->default_controller); $this->set_method('index'); - + $this->_set_request(array($this->default_controller, 'index')); + log_message('debug', "No URI present. Default controller set."); return; } -- cgit v1.2.3-24-g4f1b From f30445be8871f71bca9a4b11fa4e49edff0ac936 Mon Sep 17 00:00:00 2001 From: Derek Jones Date: Wed, 30 Jan 2008 05:23:32 +0000 Subject: Fixed a bug (#2849) with arguments passed to a subfolder controller - CodeIgniter.php was expecting the subfolder to still be in $URI->rsegments, but it is removed already by Router::_validate_request() --- system/codeigniter/CodeIgniter.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system') diff --git a/system/codeigniter/CodeIgniter.php b/system/codeigniter/CodeIgniter.php index 7556f48d3..1af8023e0 100644 --- a/system/codeigniter/CodeIgniter.php +++ b/system/codeigniter/CodeIgniter.php @@ -221,7 +221,7 @@ else // 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, (($RTR->fetch_directory() == '') ? 2 : 3))); + call_user_func_array(array(&$CI, $method), array_slice($URI->rsegments, 2)); } } -- cgit v1.2.3-24-g4f1b From 2d87b4d2fa7d2fd01876eaa8cf1f727d863d3e6c Mon Sep 17 00:00:00 2001 From: Derek Jones Date: Wed, 30 Jan 2008 15:19:53 +0000 Subject: Fixed a bug (#1872) where word_limiter() was not retaining whitespace. --- system/helpers/text_helper.php | 20 +++++++------------- 1 file changed, 7 insertions(+), 13 deletions(-) (limited to 'system') diff --git a/system/helpers/text_helper.php b/system/helpers/text_helper.php index 30cec3148..21ab77830 100644 --- a/system/helpers/text_helper.php +++ b/system/helpers/text_helper.php @@ -40,27 +40,21 @@ */ if (! function_exists('word_limiter')) { - function word_limiter($str, $n = 100, $end_char = '…') + function word_limiter($str, $limit = 100, $end_char = '…') { - if (strlen($str) < $n) + if (trim($str) == '') { return $str; } - $words = explode(' ', preg_replace("/\s+/", ' ', preg_replace("/(\r\n|\r|\n)/", " ", $str))); - - if (count($words) <= $n) - { - return $str; - } + preg_match('/^\s*+(?:\S++\s*+){1,'.(int) $limit.'}/', $str, $matches); - $str = ''; - for ($i = 0; $i < $n; $i++) + if (strlen($str) == strlen($matches[0])) { - $str .= $words[$i].' '; + $end_char = ''; } - - return trim($str).$end_char; + + return rtrim($matches[0]).$end_char; } } -- cgit v1.2.3-24-g4f1b From c38c7037d0e8028912030fa3317b6180e62d8bd8 Mon Sep 17 00:00:00 2001 From: Derek Jones Date: Wed, 30 Jan 2008 15:38:56 +0000 Subject: bugfix (#1842) - added 'index' to routed segment array when only the controller was specified in the URI. --- system/libraries/Router.php | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'system') diff --git a/system/libraries/Router.php b/system/libraries/Router.php index fd0ffa22a..d24192c18 100644 --- a/system/libraries/Router.php +++ b/system/libraries/Router.php @@ -158,6 +158,12 @@ class CI_Router { $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 @@ -271,7 +277,7 @@ class CI_Router { 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($this->uri->segments); -- cgit v1.2.3-24-g4f1b From 63df95edbaaa6f94ee8e37128a4577909a9574a1 Mon Sep 17 00:00:00 2001 From: Derek Jones Date: Wed, 30 Jan 2008 15:59:12 +0000 Subject: removed last_visit from the Session class --- system/libraries/Session.php | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) (limited to 'system') diff --git a/system/libraries/Session.php b/system/libraries/Session.php index a92db0ecc..2cdd50c23 100644 --- a/system/libraries/Session.php +++ b/system/libraries/Session.php @@ -69,8 +69,8 @@ class CI_Session { * is set in the config file. If the developer * is doing any sort of time localization they * might want to set the session time to GMT so - * they can offset the "last_activity" and - * "last_visit" times based on each user's locale. + * they can offset the "last_activity" time + * based on each user's locale. * */ @@ -326,7 +326,6 @@ class CI_Session { } // Write the cookie - $this->userdata['last_visit'] = 0; $this->sess_write(); } @@ -340,11 +339,6 @@ class CI_Session { */ function sess_update() { - if (($this->userdata['last_activity'] + $this->sess_length) < $this->now) - { - $this->userdata['last_visit'] = $this->userdata['last_activity']; - } - // 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']; -- cgit v1.2.3-24-g4f1b From 432e97322ad518468235649ad25974eef3f3d39f Mon Sep 17 00:00:00 2001 From: Derek Allard Date: Wed, 30 Jan 2008 16:13:57 +0000 Subject: Added link() to the HTML helper. --- system/helpers/html_helper.php | 130 +++++++++++++++++++++++++++++++++++++++-- 1 file changed, 126 insertions(+), 4 deletions(-) (limited to 'system') diff --git a/system/helpers/html_helper.php b/system/helpers/html_helper.php index 56e25316c..d887be6ce 100644 --- a/system/helpers/html_helper.php +++ b/system/helpers/html_helper.php @@ -182,17 +182,122 @@ if (! function_exists('br')) // ------------------------------------------------------------------------ /** - * Generates non-breaking space entities based on number supplied + * Image + * + * Generates an image tag * * @access public * @param integer * @return string */ -if (! function_exists('nbs')) +if (! function_exists('image')) { - function nbs($num = 1) + function image($src = '', $alt = '', $index_page = FALSE) { - return str_repeat(" ", $num); + $CI =& get_instance(); + + $css = ''; + + foreach ($stylesheets as $stylesheet) + { + if (strpos($stylesheet, '://') !== FALSE) + { + $href = ' href="'.$stylesheet.'"'; + } + elseif ($index_page === TRUE) + { + $href = ' href="'.$CI->config->site_url($stylesheet).'"'; + } + else + { + $href = ' href="'.$CI->config->slash_item('base_url').$stylesheet.'"'; + } + + $media = ($media !== '') ? ' media="'.$media.'"' : ''; + + $css .= 'link type="text/css" rel="stylesheet"'.$href.$media.' />'."\n"; + } + + return $css; + } +} + +// ------------------------------------------------------------------------ + +/** + * Link + * + * Generates link to a CSS file + * + * @access public + * @param mixed stylesheet name(s) + * @param string media type + * @param boolean should index_page be added to the css path + * @return string + */ +if (! function_exists('link')) +{ + function link($href = '', $rel = 'stylesheet', $type = 'text/css', $title = '', $media = '', $index_page = FALSE) + { + $CI =& get_instance(); + + $link = 'link '; + + if (is_array($href)) + { + foreach ($href as $k=>$v) + { + if ($k == 'href' AND strpos($k, '://') === 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 .= "/>\n"; + } + 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 .= '/>'."\n"; + } + + + return $link; } } @@ -219,4 +324,21 @@ if (! function_exists('meta')) } } +// ------------------------------------------------------------------------ + +/** + * Generates non-breaking space entities based on number supplied + * + * @access public + * @param integer + * @return string + */ +if (! function_exists('nbs')) +{ + function nbs($num = 1) + { + return str_repeat(" ", $num); + } +} + ?> \ No newline at end of file -- cgit v1.2.3-24-g4f1b From 165da619b64c6ade34366b99ef87758ef547dbdb Mon Sep 17 00:00:00 2001 From: Derek Allard Date: Wed, 30 Jan 2008 16:36:00 +0000 Subject: added stylesheet() to html helper --- system/helpers/html_helper.php | 26 ++++++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) (limited to 'system') diff --git a/system/helpers/html_helper.php b/system/helpers/html_helper.php index d887be6ce..660d867bd 100644 --- a/system/helpers/html_helper.php +++ b/system/helpers/html_helper.php @@ -230,8 +230,11 @@ if (! function_exists('image')) * Generates link to a CSS file * * @access public - * @param mixed stylesheet name(s) - * @param string media type + * @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 */ @@ -303,6 +306,25 @@ if (! function_exists('link')) // ------------------------------------------------------------------------ +/** + * Stylesheet + * + * Generates a to a CSS + * + * @access public + * @param array + * @return string + */ +if (! function_exists('stylesheet')) +{ + function stylesheet($href = '', $rel = 'stylesheet', $title = '', $media = 'screen') + { + return link($href, $rel, 'text/css', $title, $media); + } +} + +// ------------------------------------------------------------------------ + /** * Generates meta tags from an array of key/values * -- cgit v1.2.3-24-g4f1b From 0684897f89f8363dc431e8ade0535bce521a7af2 Mon Sep 17 00:00:00 2001 From: Derek Allard Date: Wed, 30 Jan 2008 16:55:30 +0000 Subject: remove stylesheet() so as not to overly pollute function names, rename link() to link_tag() to avoid PHP collision. --- system/helpers/html_helper.php | 23 ++--------------------- 1 file changed, 2 insertions(+), 21 deletions(-) (limited to 'system') diff --git a/system/helpers/html_helper.php b/system/helpers/html_helper.php index 660d867bd..f88bc0723 100644 --- a/system/helpers/html_helper.php +++ b/system/helpers/html_helper.php @@ -238,9 +238,9 @@ if (! function_exists('image')) * @param boolean should index_page be added to the css path * @return string */ -if (! function_exists('link')) +if (! function_exists('link_tag')) { - function link($href = '', $rel = 'stylesheet', $type = 'text/css', $title = '', $media = '', $index_page = FALSE) + function link_tag($href = '', $rel = 'stylesheet', $type = 'text/css', $title = '', $media = '', $index_page = FALSE) { $CI =& get_instance(); @@ -306,25 +306,6 @@ if (! function_exists('link')) // ------------------------------------------------------------------------ -/** - * Stylesheet - * - * Generates a to a CSS - * - * @access public - * @param array - * @return string - */ -if (! function_exists('stylesheet')) -{ - function stylesheet($href = '', $rel = 'stylesheet', $title = '', $media = 'screen') - { - return link($href, $rel, 'text/css', $title, $media); - } -} - -// ------------------------------------------------------------------------ - /** * Generates meta tags from an array of key/values * -- cgit v1.2.3-24-g4f1b From f653a2fe2f82130ff9d8db6a4913b4823dd81424 Mon Sep 17 00:00:00 2001 From: Derek Allard Date: Wed, 30 Jan 2008 20:16:01 +0000 Subject: added img() to HTML helper --- system/helpers/html_helper.php | 51 ++++++++++++++++++++++++------------------ 1 file changed, 29 insertions(+), 22 deletions(-) (limited to 'system') diff --git a/system/helpers/html_helper.php b/system/helpers/html_helper.php index f88bc0723..0c884502f 100644 --- a/system/helpers/html_helper.php +++ b/system/helpers/html_helper.php @@ -184,41 +184,48 @@ if (! function_exists('br')) /** * Image * - * Generates an image tag + * Generates an element * * @access public - * @param integer + * @param mixed * @return string */ -if (! function_exists('image')) +if (! function_exists('img')) { - function image($src = '', $alt = '', $index_page = FALSE) + function img($src = '', $index_page = FALSE) { - $CI =& get_instance(); - - $css = ''; + if ( ! is_array($src) ) + { + $src = array('src' => $src); + } + + $img = '$v) { - if (strpos($stylesheet, '://') !== FALSE) - { - $href = ' href="'.$stylesheet.'"'; - } - elseif ($index_page === TRUE) + + if ($k == 'src' AND strpos($v, '://') === FALSE) { - $href = ' href="'.$CI->config->site_url($stylesheet).'"'; + $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 { - $href = ' href="'.$CI->config->slash_item('base_url').$stylesheet.'"'; + $img .= " $k=\"$v\" "; } - - $media = ($media !== '') ? ' media="'.$media.'"' : ''; - - $css .= 'link type="text/css" rel="stylesheet"'.$href.$media.' />'."\n"; } - - return $css; + + $img .= '/>'; + + return $img; } } @@ -244,7 +251,7 @@ if (! function_exists('link_tag')) { $CI =& get_instance(); - $link = 'link '; + $link = ' Date: Wed, 30 Jan 2008 20:26:25 +0000 Subject: removed 'active_r' db config variable, replaced with global $active_record setting. (bug report #1834) --- system/application/config/database.php | 4 +++- system/database/DB.php | 8 ++++---- 2 files changed, 7 insertions(+), 5 deletions(-) (limited to 'system') diff --git a/system/application/config/database.php b/system/application/config/database.php index 59b973981..472affbe5 100644 --- a/system/application/config/database.php +++ b/system/application/config/database.php @@ -22,7 +22,6 @@ | to the table name when using the Active Record class | ['pconnect'] TRUE/FALSE - Whether to use a persistent connection | ['db_debug'] TRUE/FALSE - Whether database errors should be displayed. -| ['active_r'] TRUE/FALSE - Whether to load the active record class | ['cache_on'] TRUE/FALSE - Enables/disables query caching | ['cachedir'] The path to the folder where cache files should be stored | ['char_set'] The character set used in communicating with the database @@ -31,9 +30,12 @@ | 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 */ $active_group = "default"; +$active_record = TRUE; $db['default']['hostname'] = "localhost"; $db['default']['username'] = ""; diff --git a/system/database/DB.php b/system/database/DB.php index abd782c34..8f25e5e1a 100644 --- a/system/database/DB.php +++ b/system/database/DB.php @@ -22,7 +22,7 @@ * @author ExpressionEngine Dev Team * @link http://codeigniter.com/user_guide/database/ */ -function &DB($params = '', $active_record = FALSE) +function &DB($params = '', $active_record_override = FALSE) { // Load the DB config file if a DSN string wasn't passed if (is_string($params) AND strpos($params, '://') === FALSE) @@ -58,14 +58,14 @@ function &DB($params = '', $active_record = FALSE) // 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 == TRUE) + if ($active_record_override == TRUE) { - $params['active_r'] = TRUE; + $active_record = TRUE; } require_once(BASEPATH.'database/DB_driver'.EXT); - if ( ! isset($params['active_r']) OR $params['active_r'] == TRUE) + if ($active_record == TRUE) { require_once(BASEPATH.'database/DB_active_rec'.EXT); -- cgit v1.2.3-24-g4f1b From afc7fd52389adf43756e1083fe854ce0da61710f Mon Sep 17 00:00:00 2001 From: Derek Jones Date: Wed, 30 Jan 2008 20:28:55 +0000 Subject: actually removed 'active_r' from database.php config like I said I already did... --- system/application/config/database.php | 1 - 1 file changed, 1 deletion(-) (limited to 'system') diff --git a/system/application/config/database.php b/system/application/config/database.php index 472affbe5..0d0e08e22 100644 --- a/system/application/config/database.php +++ b/system/application/config/database.php @@ -43,7 +43,6 @@ $db['default']['password'] = ""; $db['default']['database'] = ""; $db['default']['dbdriver'] = "mysql"; $db['default']['dbprefix'] = ""; -$db['default']['active_r'] = TRUE; $db['default']['pconnect'] = TRUE; $db['default']['db_debug'] = TRUE; $db['default']['cache_on'] = FALSE; -- cgit v1.2.3-24-g4f1b From 72d61337496738d276d7671f0e07f201713aec6a Mon Sep 17 00:00:00 2001 From: Derek Jones Date: Wed, 30 Jan 2008 20:52:22 +0000 Subject: Fixed bug #1813 - added check for $CI->db isset() and is_object() before returning false in Loader::database() --- system/libraries/Loader.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'system') diff --git a/system/libraries/Loader.php b/system/libraries/Loader.php index a59d6e38e..576cb11f3 100644 --- a/system/libraries/Loader.php +++ b/system/libraries/Loader.php @@ -193,8 +193,11 @@ class CI_Loader { */ function database($params = '', $return = FALSE, $active_record = FALSE) { + // 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 == FALSE) + if (class_exists('CI_DB') AND $return == FALSE AND $active_record == FALSE AND isset($CI->db) AND is_object($CI->db)) { return FALSE; } @@ -205,9 +208,6 @@ class CI_Loader { { return DB($params, $active_record); } - - // Grab the super object - $CI =& get_instance(); // Initialize the db variable. Needed to prevent // reference errors with some configurations -- cgit v1.2.3-24-g4f1b From 4e1241bbe6c0459c28d9a7cda89ef1c81dec1bd4 Mon Sep 17 00:00:00 2001 From: Derek Jones Date: Wed, 30 Jan 2008 21:00:33 +0000 Subject: added default value for $active_record when it's not set --- system/database/DB.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system') diff --git a/system/database/DB.php b/system/database/DB.php index 8f25e5e1a..078f1ef0f 100644 --- a/system/database/DB.php +++ b/system/database/DB.php @@ -65,7 +65,7 @@ function &DB($params = '', $active_record_override = FALSE) require_once(BASEPATH.'database/DB_driver'.EXT); - if ($active_record == TRUE) + if (! isset($active_record) OR $active_record == TRUE) { require_once(BASEPATH.'database/DB_active_rec'.EXT); -- cgit v1.2.3-24-g4f1b From 4a310b7aef013a02288fc0b37571c841c10323f7 Mon Sep 17 00:00:00 2001 From: Derek Allard Date: Wed, 30 Jan 2008 21:32:47 +0000 Subject: fix orlike to call or_like --- system/database/DB_active_rec.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system') diff --git a/system/database/DB_active_rec.php b/system/database/DB_active_rec.php index 37bf9ed05..e93b99e3d 100644 --- a/system/database/DB_active_rec.php +++ b/system/database/DB_active_rec.php @@ -595,7 +595,7 @@ class CI_DB_active_record extends CI_DB_driver { */ function orlike($field, $match = '', $side = 'both') { - return $this->orlike($field, $match, $side); + return $this->or_like($field, $match, $side); } // -------------------------------------------------------------------- -- cgit v1.2.3-24-g4f1b From 7b80700a88e3e3a9ad46fe484e1cbfc3bd353b91 Mon Sep 17 00:00:00 2001 From: Derek Allard Date: Thu, 31 Jan 2008 23:52:01 +0000 Subject: remove parenthesis from postrgre _from_tables --- system/database/drivers/postgre/postgre_driver.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system') diff --git a/system/database/drivers/postgre/postgre_driver.php b/system/database/drivers/postgre/postgre_driver.php index 20f91650a..e72981348 100644 --- a/system/database/drivers/postgre/postgre_driver.php +++ b/system/database/drivers/postgre/postgre_driver.php @@ -486,7 +486,7 @@ class CI_DB_postgre_driver extends CI_DB { $tables = array($tables); } - return '('.implode(', ', $tables).')'; + return implode(', ', $tables); } // -------------------------------------------------------------------- -- cgit v1.2.3-24-g4f1b From ab32a428c572f859010e990e621df4f34b9dc606 Mon Sep 17 00:00:00 2001 From: Derek Jones Date: Mon, 4 Feb 2008 22:02:11 +0000 Subject: changed URL decoding implementation of xss_clean() to use rawurldecode() to discontinue misconversion of characters to bad entities, and to continue avoidance of unwanted removal of + signs --- system/libraries/Input.php | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) (limited to 'system') diff --git a/system/libraries/Input.php b/system/libraries/Input.php index 1874b3790..5832d2d80 100644 --- a/system/libraries/Input.php +++ b/system/libraries/Input.php @@ -556,14 +556,11 @@ class CI_Input { * * Google * - * Note: Normally urldecode() would be easier but it removes plus signs + * Note: Use rawurldecode() so it does not remove plus signs * */ - $str = preg_replace("/(%20)+/", '9u3iovBnRThju941s89rKozm', $str); - $str = preg_replace("/%u0([a-z0-9]{3})/i", "&#x\\1;", $str); - $str = preg_replace("/%([a-z0-9]{2})/i", "&#x\\1;", $str); - $str = str_replace('9u3iovBnRThju941s89rKozm', "%20", $str); - + $str = rawurldecode($str); + /* * Convert character entities to ASCII * -- cgit v1.2.3-24-g4f1b From 613c6f605666031aa5b60c2dca568ac2d3a3c264 Mon Sep 17 00:00:00 2001 From: Derek Allard Date: Mon, 4 Feb 2008 22:13:45 +0000 Subject: change CI_VERSION from 1.6.0 to 1.6.1 --- system/codeigniter/CodeIgniter.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system') diff --git a/system/codeigniter/CodeIgniter.php b/system/codeigniter/CodeIgniter.php index 1af8023e0..8f9dbdf64 100644 --- a/system/codeigniter/CodeIgniter.php +++ b/system/codeigniter/CodeIgniter.php @@ -28,7 +28,7 @@ */ // CI Version -define('CI_VERSION', '1.6.0'); +define('CI_VERSION', '1.6.1'); /* * ------------------------------------------------------ -- cgit v1.2.3-24-g4f1b From 9b3e7b5f2d4ec4feae793ef90454506addbb19e1 Mon Sep 17 00:00:00 2001 From: Derek Allard Date: Mon, 4 Feb 2008 23:20:34 +0000 Subject: Added and documented Active Record caching. Made AR fully database-prefix aware --- system/database/DB_active_rec.php | 313 ++++++++++++++++++--- system/database/drivers/mssql/mssql_driver.php | 7 + system/database/drivers/mysql/mysql_driver.php | 7 + system/database/drivers/mysqli/mysqli_driver.php | 7 + system/database/drivers/oci8/oci8_driver.php | 7 + system/database/drivers/odbc/odbc_driver.php | 7 + system/database/drivers/postgre/postgre_driver.php | 9 +- system/database/drivers/sqlite/sqlite_driver.php | 7 + 8 files changed, 322 insertions(+), 42 deletions(-) (limited to 'system') diff --git a/system/database/DB_active_rec.php b/system/database/DB_active_rec.php index e93b99e3d..b3bf02a8b 100644 --- a/system/database/DB_active_rec.php +++ b/system/database/DB_active_rec.php @@ -43,6 +43,23 @@ class CI_DB_active_record extends CI_DB_driver { var $ar_set = array(); var $ar_wherein = array(); var $ar_aliased_tables = array(); + var $ar_store_array = array(); + + // Active Record Caching variables + var $ar_caching = FALSE; + var $ar_cache_select = array(); + var $ar_cache_from = array(); + var $ar_cache_join = array(); + var $ar_cache_where = array(); + var $ar_cache_like = array(); + var $ar_cache_groupby = array(); + var $ar_cache_having = array(); + var $ar_cache_limit = FALSE; + var $ar_cache_offset = FALSE; + var $ar_cache_order = FALSE; + var $ar_cache_orderby = array(); + var $ar_cache_set = array(); + /** * DB Prefix @@ -87,12 +104,23 @@ class CI_DB_active_record extends CI_DB_driver { if ($val != '*' && $protect_identifiers !== FALSE) { - $val = $this->_protect_identifiers($val); + if (strpos($val, '.') !== FALSE) + { + $val = $this->dbprefix.$val; + } + else + { + $val = $this->_protect_identifiers($val); + } } if ($val != '') { $this->ar_select[] = $val; + if ($this->ar_caching === TRUE) + { + $this->ar_cache_select[] = $val; + } } } return $this; @@ -122,6 +150,10 @@ class CI_DB_active_record extends CI_DB_driver { $sql = 'MAX('.$this->_protect_identifiers(trim($select)).') AS '.$this->_protect_identifiers(trim($alias)); $this->ar_select[] = $sql; + if ($this->ar_caching === TRUE) + { + $this->ar_cache_select[] = $sql; + } return $this; } @@ -150,7 +182,11 @@ class CI_DB_active_record extends CI_DB_driver { $sql = 'MIN('.$this->_protect_identifiers(trim($select)).') AS '.$this->_protect_identifiers(trim($alias)); $this->ar_select[] = $sql; - + if ($this->ar_caching === TRUE) + { + $this->ar_cache_select[] = $sql; + } + return $this; } @@ -178,7 +214,11 @@ class CI_DB_active_record extends CI_DB_driver { $sql = 'AVG('.$this->_protect_identifiers(trim($select)).') AS '.$this->_protect_identifiers(trim($alias)); $this->ar_select[] = $sql; - + if ($this->ar_caching === TRUE) + { + $this->ar_cache_select[] = $sql; + } + return $this; } @@ -206,7 +246,11 @@ class CI_DB_active_record extends CI_DB_driver { $sql = 'SUM('.$this->_protect_identifiers(trim($select)).') AS '.$this->_protect_identifiers(trim($alias)); $this->ar_select[] = $sql; - + if ($this->ar_caching === TRUE) + { + $this->ar_cache_select[] = $sql; + } + return $this; } @@ -243,6 +287,10 @@ class CI_DB_active_record extends CI_DB_driver { foreach ((array)$from as $val) { $this->ar_from[] = $this->_protect_identifiers($this->_track_aliases($val)); + if ($this->ar_caching === TRUE) + { + $this->ar_cache_from[] = $this->_protect_identifiers($val); + } } return $this; @@ -289,7 +337,14 @@ class CI_DB_active_record extends CI_DB_driver { $cond = preg_replace('|([\w\.]+)([\W\s]+)(.+)|', $this->dbprefix . "$1$2" . $this->dbprefix . "$3", $cond); } - $this->ar_join[] = $type.'JOIN '.$this->_protect_identifiers($this->dbprefix.$table, TRUE).' ON '.$cond; + $join = $type.'JOIN '.$this->_protect_identifiers($this->dbprefix.$table, TRUE).' ON '.$cond; + + $this->ar_join[] = $join; + if ($this->ar_caching === TRUE) + { + $this->ar_cache_join[] = $join; + } + return $this; } @@ -360,7 +415,7 @@ class CI_DB_active_record extends CI_DB_driver { { $key = array($key => $value); } - + foreach ($key as $k => $v) { $prefix = (count($this->ar_where) == 0) ? '' : $type; @@ -393,10 +448,18 @@ class CI_DB_active_record extends CI_DB_driver { } $v = ' '.$this->escape($v); - } - + else + { + $k = $this->_protect_identifiers($k, TRUE); + } + $this->ar_where[] = $prefix.$k.$v; + if ($this->ar_caching === TRUE) + { + $this->ar_cache_where[] = $prefix.$k.$v; + } + } return $this; } @@ -507,7 +570,13 @@ class CI_DB_active_record extends CI_DB_driver { $prefix = (count($this->ar_where) == 0) ? '' : $type; - $this->ar_where[] = $prefix . $this->_protect_identifiers($key) . $not . " IN (" . implode(", ", $this->ar_wherein) . ") "; + $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; + } // reset the array for multiple calls $this->ar_wherein = array(); @@ -629,16 +698,23 @@ class CI_DB_active_record extends CI_DB_driver { if ($side == 'before') { - $this->ar_like[] = $prefix." $k $not LIKE '%{$v}'"; + $like_statement = $prefix." $k $not LIKE '%{$v}'"; } elseif ($side == 'after') { - $this->ar_like[] = $prefix." $k $not LIKE '{$v}%'"; + $like_statement = $prefix." $k $not LIKE '{$v}%'"; } else { - $this->ar_like[] = $prefix." $k $not LIKE '%{$v}%'"; + $like_statement = $prefix." $k $not LIKE '%{$v}%'"; } + + $this->ar_like[] = $like_statement; + if ($this->ar_caching === TRUE) + { + $this->ar_cache_like[] = $like_statement; + } + } return $this; } @@ -664,7 +740,13 @@ class CI_DB_active_record extends CI_DB_driver { $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); + } + } } return $this; } @@ -724,6 +806,7 @@ class CI_DB_active_record extends CI_DB_driver { * * @access private * @param string + * @param string * @return object */ @@ -737,14 +820,20 @@ class CI_DB_active_record extends CI_DB_driver { foreach ($key as $k => $v) { $prefix = (count($this->ar_having) == 0) ? '' : $type; + $k = $this->_protect_identifiers($k); if ($v != '') { - $v = ' '.$this->escape($v); + $v = ' '.$this->escape_str($v); } $this->ar_having[] = $prefix.$k.$v; + if ($this->ar_caching === TRUE) + { + $this->ar_cache_having[] = $prefix.$k.$v; + } } + return $this; } @@ -770,7 +859,14 @@ class CI_DB_active_record extends CI_DB_driver { $direction = (in_array(strtoupper(trim($direction)), array('ASC', 'DESC'), TRUE)) ? ' '.$direction : ' ASC'; } - $this->ar_orderby[] = $this->_protect_identifiers($orderby, TRUE).$direction; + $orderby_statement = $this->_protect_identifiers($orderby, TRUE).$direction; + + $this->ar_orderby[] = $orderby_statement; + if ($this->ar_caching === TRUE) + { + $this->ar_cache_orderby[] = $orderby_statement; + } + return $this; } @@ -799,9 +895,19 @@ class CI_DB_active_record extends CI_DB_driver { function limit($value, $offset = '') { $this->ar_limit = $value; - + if ($this->ar_caching === TRUE) + { + $this->ar_cache_limit[] = $value; + } + if ($offset != '') + { $this->ar_offset = $offset; + if ($this->ar_caching === TRUE) + { + $this->ar_cache_offset[] = $offset; + } + } return $this; } @@ -815,9 +921,14 @@ class CI_DB_active_record extends CI_DB_driver { * @param integer the offset value * @return object */ - function offset($value) + function offset($offset) { - $this->ar_offset = $value; + $this->ar_offset = $offset; + if ($this->ar_caching === TRUE) + { + $this->ar_cache_offset[] = $offset; + } + return $this; } @@ -846,12 +957,19 @@ class CI_DB_active_record extends CI_DB_driver { if ($escape === FALSE) { $this->ar_set[$this->_protect_identifiers($k)] = $v; + if ($this->ar_caching === TRUE) + { + $this->ar_cache_offset[$this->_protect_identifiers($k)] = $v; + } } else { $this->ar_set[$this->_protect_identifiers($k)] = $this->escape($v); + if ($this->ar_caching === TRUE) + { + $this->ar_cache_offset[$this->_protect_identifiers($k)] = $this->escape($v); + } } - } return $this; @@ -1331,6 +1449,11 @@ class CI_DB_active_record extends CI_DB_driver { */ function _compile_select($select_override = FALSE) { + if ($this->ar_caching === TRUE) + { + $this->_merge_cache(); + } + $sql = ( ! $this->ar_distinct) ? 'SELECT ' : 'SELECT DISTINCT '; $sql .= (count($this->ar_select) == 0) ? '*' : implode(', ', $this->ar_select); @@ -1455,6 +1578,107 @@ class CI_DB_active_record extends CI_DB_driver { // -------------------------------------------------------------------- + /** + * Start Cache + * + * Starts AR caching + * + * @access public + * @return void + */ + function start_cache() + { + $this->ar_caching = TRUE; + } + + // -------------------------------------------------------------------- + + /** + * Stop Cache + * + * Stops AR caching + * + * @access public + * @return void + */ + function stop_cache() + { + $this->ar_caching = FALSE; + } + + + // -------------------------------------------------------------------- + + /** + * Flush Cache + * + * Empties the AR cache + * + * @access public + * @return void + */ + function flush_cache() + { + $ar_reset_items = 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() + ); + + $this->_reset_run($ar_reset_items); + } + + // -------------------------------------------------------------------- + + /** + * Merge Cache + * + * When called, this function merges any cached AR arrays with + * locally called ones. + * + * @access private + * @return void + */ + function _merge_cache() + { + $ar_items = array('select', 'from', 'join', 'where', 'like', 'groupby', 'having', 'orderby', 'set'); + + foreach ($ar_items as $ar_item) + { + $ar_cache_item = 'ar_cache_'.$ar_item; + $ar_item = 'ar_'.$ar_item; + $this->$ar_item = array_unique(array_merge($this->$ar_item, $this->$ar_cache_item)); + } + } + + // -------------------------------------------------------------------- + + /** + * Resets the active record values. Called by the get() function + * + * @access private + * @param array An array of fields to reset + * @return void + */ + 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 * @@ -1463,20 +1687,24 @@ class CI_DB_active_record extends CI_DB_driver { */ function _reset_select() { - $this->ar_select = array(); - $this->ar_distinct = FALSE; - $this->ar_from = array(); - $this->ar_join = array(); - $this->ar_where = array(); - $this->ar_like = array(); - $this->ar_groupby = array(); - $this->ar_having = array(); - $this->ar_limit = FALSE; - $this->ar_offset = FALSE; - $this->ar_order = FALSE; - $this->ar_orderby = array(); - $this->ar_wherein = array(); - $this->ar_aliased_tables = array(); + $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_distinct' => FALSE, + 'ar_limit' => FALSE, + 'ar_offset' => FALSE, + 'ar_order' => FALSE, + ); + + $this->_reset_run($ar_reset_items); } // -------------------------------------------------------------------- @@ -1490,16 +1718,19 @@ class CI_DB_active_record extends CI_DB_driver { * @return void */ function _reset_write() - { - $this->ar_set = array(); - $this->ar_from = array(); - $this->ar_where = array(); - $this->ar_like = array(); - $this->ar_limit = FALSE; - $this->ar_order = FALSE; - $this->ar_orderby = array(); + { + $ar_reset_items = array( + 'ar_set' => array(), + 'ar_from' => array(), + 'ar_where' => array(), + 'ar_like' => array(), + 'ar_orderby' => array(), + 'ar_limit' => FALSE, + 'ar_order' => FALSE + ); + + $this->_reset_run($ar_reset_items); } } - ?> \ No newline at end of file diff --git a/system/database/drivers/mssql/mssql_driver.php b/system/database/drivers/mssql/mssql_driver.php index ad747d4ad..ecd404b52 100644 --- a/system/database/drivers/mssql/mssql_driver.php +++ b/system/database/drivers/mssql/mssql_driver.php @@ -433,6 +433,13 @@ class CI_DB_mssql_driver extends CI_DB { function _protect_identifiers($item, $affect_spaces = TRUE, $first_word_only = FALSE) { // MSSQL doesn't use backticks + if (strpos($item, '.') !== FALSE) + { + $aliased_tables = implode(".",$this->ar_aliased_tables).'.'; + $table_name = substr($item, 0, strpos($item, '.')+1); + $item = (strpos($aliased_tables, $table_name) !== FALSE) ? $item = $item : $this->dbprefix.$item; + } + return $item; } diff --git a/system/database/drivers/mysql/mysql_driver.php b/system/database/drivers/mysql/mysql_driver.php index f00257250..a5082d1b3 100644 --- a/system/database/drivers/mysql/mysql_driver.php +++ b/system/database/drivers/mysql/mysql_driver.php @@ -454,6 +454,13 @@ class CI_DB_mysql_driver extends CI_DB { // we may need "`item1` `item2`" and not "`item1 item2`" if (ctype_alnum($item) === FALSE) { + if (strpos($item, '.') !== FALSE) + { + $aliased_tables = implode(".",$this->ar_aliased_tables).'.'; + $table_name = substr($item, 0, strpos($item, '.')+1); + $item = (strpos($aliased_tables, $table_name) !== FALSE) ? $item = $item : $this->dbprefix.$item; + } + // This function may get "field >= 1", and need it to return "`field` >= 1" $lbound = ($first_word_only === TRUE) ? '' : '|\s|\('; diff --git a/system/database/drivers/mysqli/mysqli_driver.php b/system/database/drivers/mysqli/mysqli_driver.php index b2e97f927..9e7cc0c9f 100644 --- a/system/database/drivers/mysqli/mysqli_driver.php +++ b/system/database/drivers/mysqli/mysqli_driver.php @@ -448,6 +448,13 @@ class CI_DB_mysqli_driver extends CI_DB { // we may need "`item1` `item2`" and not "`item1 item2`" if (ctype_alnum($item) === FALSE) { + if (strpos($item, '.') !== FALSE) + { + $aliased_tables = implode(".",$this->ar_aliased_tables).'.'; + $table_name = substr($item, 0, strpos($item, '.')+1); + $item = (strpos($aliased_tables, $table_name) !== FALSE) ? $item = $item : $this->dbprefix.$item; + } + // This function may get "field >= 1", and need it to return "`field` >= 1" $lbound = ($first_word_only === TRUE) ? '' : '|\s|\('; diff --git a/system/database/drivers/oci8/oci8_driver.php b/system/database/drivers/oci8/oci8_driver.php index ddc0fba99..aa2aeca42 100644 --- a/system/database/drivers/oci8/oci8_driver.php +++ b/system/database/drivers/oci8/oci8_driver.php @@ -559,6 +559,13 @@ class CI_DB_oci8_driver extends CI_DB { // we may need "`item1` `item2`" and not "`item1 item2`" if (ctype_alnum($item) === FALSE) { + if (strpos($item, '.') !== FALSE) + { + $aliased_tables = implode(".",$this->ar_aliased_tables).'.'; + $table_name = substr($item, 0, strpos($item, '.')+1); + $item = (strpos($aliased_tables, $table_name) !== FALSE) ? $item = $item : $this->dbprefix.$item; + } + // This function may get "field >= 1", and need it to return "`field` >= 1" $lbound = ($first_word_only === TRUE) ? '' : '|\s|\('; diff --git a/system/database/drivers/odbc/odbc_driver.php b/system/database/drivers/odbc/odbc_driver.php index 03c0e6a86..88fff4365 100644 --- a/system/database/drivers/odbc/odbc_driver.php +++ b/system/database/drivers/odbc/odbc_driver.php @@ -424,6 +424,13 @@ class CI_DB_odbc_driver extends CI_DB { // we may need "`item1` `item2`" and not "`item1 item2`" if (ctype_alnum($item) === FALSE) { + if (strpos($item, '.') !== FALSE) + { + $aliased_tables = implode(".",$this->ar_aliased_tables).'.'; + $table_name = substr($item, 0, strpos($item, '.')+1); + $item = (strpos($aliased_tables, $table_name) !== FALSE) ? $item = $item : $this->dbprefix.$item; + } + // This function may get "field >= 1", and need it to return "`field` >= 1" $lbound = ($first_word_only === TRUE) ? '' : '|\s|\('; diff --git a/system/database/drivers/postgre/postgre_driver.php b/system/database/drivers/postgre/postgre_driver.php index e72981348..ae8bd86eb 100644 --- a/system/database/drivers/postgre/postgre_driver.php +++ b/system/database/drivers/postgre/postgre_driver.php @@ -444,6 +444,13 @@ class CI_DB_postgre_driver extends CI_DB { // we may need ""item1" "item2"" and not ""item1 item2"" if (ctype_alnum($item) === FALSE) { + if (strpos($item, '.') !== FALSE) + { + $aliased_tables = implode(".",$this->ar_aliased_tables).'.'; + $table_name = substr($item, 0, strpos($item, '.')+1); + $item = (strpos($aliased_tables, $table_name) !== FALSE) ? $item = $item : $this->dbprefix.$item; + } + // This function may get "field >= 1", and need it to return ""field" >= 1" $lbound = ($first_word_only === TRUE) ? '' : '|\s|\('; @@ -486,7 +493,7 @@ class CI_DB_postgre_driver extends CI_DB { $tables = array($tables); } - return implode(', ', $tables); + return '('.implode(', ', $tables).')'; } // -------------------------------------------------------------------- diff --git a/system/database/drivers/sqlite/sqlite_driver.php b/system/database/drivers/sqlite/sqlite_driver.php index 38febca29..dad5eeedf 100644 --- a/system/database/drivers/sqlite/sqlite_driver.php +++ b/system/database/drivers/sqlite/sqlite_driver.php @@ -440,6 +440,13 @@ class CI_DB_sqlite_driver extends CI_DB { // we may need "`item1` `item2`" and not "`item1 item2`" if (ctype_alnum($item) === FALSE) { + if (strpos($item, '.') !== FALSE) + { + $aliased_tables = implode(".",$this->ar_aliased_tables).'.'; + $table_name = substr($item, 0, strpos($item, '.')+1); + $item = (strpos($aliased_tables, $table_name) !== FALSE) ? $item = $item : $this->dbprefix.$item; + } + // This function may get "field >= 1", and need it to return "`field` >= 1" $lbound = ($first_word_only === TRUE) ? '' : '|\s|\('; -- cgit v1.2.3-24-g4f1b From 0ea06fd2878d802b1e627ac3ec31b6a5b61d9f9d Mon Sep 17 00:00:00 2001 From: Derek Jones Date: Tue, 5 Feb 2008 15:23:51 +0000 Subject: * Fixed a bug (#3396) where certain POST variables would cause a PHP warning. * Added $_SERVER, $_FILES, $_ENV, and $_SESSION to sanitization of globals. --- system/libraries/Input.php | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) (limited to 'system') diff --git a/system/libraries/Input.php b/system/libraries/Input.php index 5832d2d80..1c5682eb7 100644 --- a/system/libraries/Input.php +++ b/system/libraries/Input.php @@ -72,16 +72,15 @@ class CI_Input { $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. + // Unset globals for security. // This is effectively the same as register_globals = off - foreach (array($_GET, $_POST, $_COOKIE) as $global) + foreach (array($_GET, $_POST, $_COOKIE, $_SERVER, $_FILES, $_ENV, (isset($_SESSION) && is_array($_SESSION)) ? $_SESSION : array()) as $global) { if ( ! is_array($global)) { if ( ! in_array($global, $protected)) { - global $$global; - $$global = NULL; + unset($GLOBALS[$global]); } } else @@ -90,8 +89,18 @@ class CI_Input { { if ( ! in_array($key, $protected)) { - global $$key; - $$key = NULL; + unset($GLOBALS[$key]); + } + + if (is_array($val)) + { + foreach($val as $k => $v) + { + if ( ! in_array($k, $protected)) + { + unset($GLOBALS[$k]); + } + } } } } -- cgit v1.2.3-24-g4f1b From 32cf7eb132ec688a3b0339f266efa3f064c58a60 Mon Sep 17 00:00:00 2001 From: Derek Allard Date: Tue, 5 Feb 2008 16:03:50 +0000 Subject: Changed the behaviour of Active Record's update() to make the WHERE clause optional (#3395) --- system/database/drivers/mssql/mssql_driver.php | 6 +++++- system/database/drivers/mysql/mysql_driver.php | 6 +++++- system/database/drivers/mysqli/mysqli_driver.php | 6 +++++- system/database/drivers/oci8/oci8_driver.php | 6 +++++- system/database/drivers/odbc/odbc_driver.php | 6 +++++- system/database/drivers/postgre/postgre_driver.php | 6 +++++- system/database/drivers/sqlite/sqlite_driver.php | 6 +++++- 7 files changed, 35 insertions(+), 7 deletions(-) (limited to 'system') diff --git a/system/database/drivers/mssql/mssql_driver.php b/system/database/drivers/mssql/mssql_driver.php index ecd404b52..4cf444088 100644 --- a/system/database/drivers/mssql/mssql_driver.php +++ b/system/database/drivers/mssql/mssql_driver.php @@ -509,7 +509,11 @@ class CI_DB_mssql_driver extends CI_DB { $orderby = (count($orderby) >= 1)?' ORDER BY '.implode(", ", $orderby):''; - return "UPDATE ".$this->_escape_table($table)." SET ".implode(', ', $valstr)." WHERE ".implode(" ", $where).$orderby.$limit; + $sql = "UPDATE ".$this->_escape_table($table)." SET ".implode(', ', $valstr); + $sql .= ($where != '' AND count($where) >=1) ? " WHERE ".implode(" ", $where) : ''; + $sql .= $orderby.$limit; + + return $sql; } diff --git a/system/database/drivers/mysql/mysql_driver.php b/system/database/drivers/mysql/mysql_driver.php index a5082d1b3..372365aeb 100644 --- a/system/database/drivers/mysql/mysql_driver.php +++ b/system/database/drivers/mysql/mysql_driver.php @@ -550,7 +550,11 @@ class CI_DB_mysql_driver extends CI_DB { $orderby = (count($orderby) >= 1)?' ORDER BY '.implode(", ", $orderby):''; - return "UPDATE ".$this->_escape_table($table)." SET ".implode(', ', $valstr)." WHERE ".implode(" ", $where).$orderby.$limit; + $sql = "UPDATE ".$this->_escape_table($table)." SET ".implode(', ', $valstr); + $sql .= ($where != '' AND count($where) >=1) ? " WHERE ".implode(" ", $where) : ''; + $sql .= $orderby.$limit; + + return $sql; } // -------------------------------------------------------------------- diff --git a/system/database/drivers/mysqli/mysqli_driver.php b/system/database/drivers/mysqli/mysqli_driver.php index 9e7cc0c9f..31c27117c 100644 --- a/system/database/drivers/mysqli/mysqli_driver.php +++ b/system/database/drivers/mysqli/mysqli_driver.php @@ -544,7 +544,11 @@ class CI_DB_mysqli_driver extends CI_DB { $orderby = (count($orderby) >= 1)?' ORDER BY '.implode(", ", $orderby):''; - return "UPDATE ".$this->_escape_table($table)." SET ".implode(', ', $valstr)." WHERE ".implode(" ", $where).$orderby.$limit; + $sql = "UPDATE ".$this->_escape_table($table)." SET ".implode(', ', $valstr); + $sql .= ($where != '' AND count($where) >=1) ? " WHERE ".implode(" ", $where) : ''; + $sql .= $orderby.$limit; + + return $sql; } diff --git a/system/database/drivers/oci8/oci8_driver.php b/system/database/drivers/oci8/oci8_driver.php index aa2aeca42..7aab37e82 100644 --- a/system/database/drivers/oci8/oci8_driver.php +++ b/system/database/drivers/oci8/oci8_driver.php @@ -655,7 +655,11 @@ class CI_DB_oci8_driver extends CI_DB { $orderby = (count($orderby) >= 1)?' ORDER BY '.implode(", ", $orderby):''; - return "UPDATE ".$this->_escape_table($table)." SET ".implode(', ', $valstr)." WHERE ".implode(" ", $where).$orderby.$limit; + $sql = "UPDATE ".$this->_escape_table($table)." SET ".implode(', ', $valstr); + $sql .= ($where != '' AND count($where) >=1) ? " WHERE ".implode(" ", $where) : ''; + $sql .= $orderby.$limit; + + return $sql; } // -------------------------------------------------------------------- diff --git a/system/database/drivers/odbc/odbc_driver.php b/system/database/drivers/odbc/odbc_driver.php index 88fff4365..dd10fbdd3 100644 --- a/system/database/drivers/odbc/odbc_driver.php +++ b/system/database/drivers/odbc/odbc_driver.php @@ -520,7 +520,11 @@ class CI_DB_odbc_driver extends CI_DB { $orderby = (count($orderby) >= 1)?' ORDER BY '.implode(", ", $orderby):''; - return "UPDATE ".$this->_escape_table($table)." SET ".implode(', ', $valstr)." WHERE ".implode(" ", $where).$orderby.$limit; + $sql = "UPDATE ".$this->_escape_table($table)." SET ".implode(', ', $valstr); + $sql .= ($where != '' AND count($where) >=1) ? " WHERE ".implode(" ", $where) : ''; + $sql .= $orderby.$limit; + + return $sql; } diff --git a/system/database/drivers/postgre/postgre_driver.php b/system/database/drivers/postgre/postgre_driver.php index ae8bd86eb..cac0ecb60 100644 --- a/system/database/drivers/postgre/postgre_driver.php +++ b/system/database/drivers/postgre/postgre_driver.php @@ -540,7 +540,11 @@ class CI_DB_postgre_driver extends CI_DB { $orderby = (count($orderby) >= 1)?' ORDER BY '.implode(", ", $orderby):''; - return "UPDATE ".$this->_escape_table($table)." SET ".implode(', ', $valstr)." WHERE ".implode(" ", $where).$orderby.$limit; + $sql = "UPDATE ".$this->_escape_table($table)." SET ".implode(', ', $valstr); + $sql .= ($where != '' AND count($where) >=1) ? " WHERE ".implode(" ", $where) : ''; + $sql .= $orderby.$limit; + + return $sql; } diff --git a/system/database/drivers/sqlite/sqlite_driver.php b/system/database/drivers/sqlite/sqlite_driver.php index dad5eeedf..5290edeea 100644 --- a/system/database/drivers/sqlite/sqlite_driver.php +++ b/system/database/drivers/sqlite/sqlite_driver.php @@ -536,7 +536,11 @@ class CI_DB_sqlite_driver extends CI_DB { $orderby = (count($orderby) >= 1)?' ORDER BY '.implode(", ", $orderby):''; - return "UPDATE ".$this->_escape_table($table)." SET ".implode(', ', $valstr)." WHERE ".implode(" ", $where).$orderby.$limit; + $sql = "UPDATE ".$this->_escape_table($table)." SET ".implode(', ', $valstr); + $sql .= ($where != '' AND count($where) >=1) ? " WHERE ".implode(" ", $where) : ''; + $sql .= $orderby.$limit; + + return $sql; } -- cgit v1.2.3-24-g4f1b From 7825526a596b0db6a15fac519cf45e2e929c684d Mon Sep 17 00:00:00 2001 From: Derek Allard Date: Wed, 6 Feb 2008 13:54:23 +0000 Subject: cache_stop() fix... --- system/database/DB_active_rec.php | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) (limited to 'system') diff --git a/system/database/DB_active_rec.php b/system/database/DB_active_rec.php index b3bf02a8b..263172a86 100644 --- a/system/database/DB_active_rec.php +++ b/system/database/DB_active_rec.php @@ -1449,10 +1449,7 @@ class CI_DB_active_record extends CI_DB_driver { */ function _compile_select($select_override = FALSE) { - if ($this->ar_caching === TRUE) - { - $this->_merge_cache(); - } + $this->_merge_cache(); $sql = ( ! $this->ar_distinct) ? 'SELECT ' : 'SELECT DISTINCT '; -- cgit v1.2.3-24-g4f1b From a47a2e26f3e8bcf96657ac343c224bd592ed32f8 Mon Sep 17 00:00:00 2001 From: Derek Jones Date: Thu, 7 Feb 2008 18:05:59 +0000 Subject: added functionality for setting client character set and collation in MySQLi driver --- system/database/drivers/mysqli/mysqli_driver.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'system') diff --git a/system/database/drivers/mysqli/mysqli_driver.php b/system/database/drivers/mysqli/mysqli_driver.php index 31c27117c..b6d1cba77 100644 --- a/system/database/drivers/mysqli/mysqli_driver.php +++ b/system/database/drivers/mysqli/mysqli_driver.php @@ -96,8 +96,7 @@ class CI_DB_mysqli_driver extends CI_DB { */ function db_set_charset($charset, $collation) { - // TODO - add support if needed - return TRUE; + return @mysqli_query($this->conn_id, "SET NAMES '".$this->escape_str($charset)."' COLLATE '".$this->escape_str($collation)."'"); } // -------------------------------------------------------------------- -- cgit v1.2.3-24-g4f1b From b35c3f5b978690a17e18c76fe1301b8f46d6710b Mon Sep 17 00:00:00 2001 From: Derek Jones Date: Fri, 8 Feb 2008 20:48:23 +0000 Subject: changed order of SQL keywords in the $highlight array so OR would not be highlighted before ORDER BY --- system/libraries/Profiler.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system') diff --git a/system/libraries/Profiler.php b/system/libraries/Profiler.php index eb2f25094..8a45933e1 100644 --- a/system/libraries/Profiler.php +++ b/system/libraries/Profiler.php @@ -125,7 +125,7 @@ class CI_Profiler { } else { - $highlight = array('SELECT', 'FROM', 'WHERE', 'AND', 'OR', 'LEFT JOIN', 'ORDER BY', 'LIMIT', 'INSERT', 'INTO', 'VALUES', 'UPDATE'); + $highlight = array('SELECT', 'FROM', 'WHERE', 'AND', 'LEFT JOIN', 'ORDER BY', 'LIMIT', 'INSERT', 'INTO', 'VALUES', 'UPDATE', 'OR'); foreach ($this->CI->db->queries as $key => $val) { -- cgit v1.2.3-24-g4f1b From eb002ffdf55de1e19619efc4242691e16c590794 Mon Sep 17 00:00:00 2001 From: Derek Allard Date: Sun, 10 Feb 2008 20:27:40 +0000 Subject: adding is_numeric back into validation library --- system/libraries/Validation.php | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'system') diff --git a/system/libraries/Validation.php b/system/libraries/Validation.php index c81ad6b88..d0714d040 100644 --- a/system/libraries/Validation.php +++ b/system/libraries/Validation.php @@ -557,6 +557,20 @@ class CI_Validation { } // -------------------------------------------------------------------- + + /** + * Is Numeric + * + * @access public + * @param string + * @return bool + */ + function is_numeric($str) + { + return ( ! is_numeric($str)) ? FALSE : TRUE; + } + + // -------------------------------------------------------------------- /** * Integer -- cgit v1.2.3-24-g4f1b From 156481371306db532d6b3880d0914e9237b93685 Mon Sep 17 00:00:00 2001 From: Derek Allard Date: Sun, 10 Feb 2008 21:46:18 +0000 Subject: changes for enhanced database compatibility --- system/database/DB_forge.php | 1 - system/database/drivers/mssql/mssql_driver.php | 47 +++++++++++++++++++--- system/database/drivers/mysqli/mysqli_driver.php | 3 +- system/database/drivers/oci8/oci8_driver.php | 14 +++---- system/database/drivers/postgre/postgre_driver.php | 2 +- system/database/drivers/sqlite/sqlite_driver.php | 14 +++---- 6 files changed, 58 insertions(+), 23 deletions(-) (limited to 'system') diff --git a/system/database/DB_forge.php b/system/database/DB_forge.php index 7febb72c2..cd468bc6a 100644 --- a/system/database/DB_forge.php +++ b/system/database/DB_forge.php @@ -40,7 +40,6 @@ class CI_DB_forge { // Assign the main database object to $this->db $CI =& get_instance(); $this->db =& $CI->db; - log_message('debug', "Database Forge Class Initialized"); } diff --git a/system/database/drivers/mssql/mssql_driver.php b/system/database/drivers/mssql/mssql_driver.php index 4cf444088..8e12a2d21 100644 --- a/system/database/drivers/mssql/mssql_driver.php +++ b/system/database/drivers/mssql/mssql_driver.php @@ -430,16 +430,51 @@ class CI_DB_mssql_driver extends CI_DB { * @param boolean only affect the first word * @return mixed the item with backticks */ - function _protect_identifiers($item, $affect_spaces = TRUE, $first_word_only = FALSE) + function _protect_identifiers($item, $first_word_only = FALSE) { - // MSSQL doesn't use backticks - if (strpos($item, '.') !== FALSE) + if (is_array($item)) { - $aliased_tables = implode(".",$this->ar_aliased_tables).'.'; - $table_name = substr($item, 0, strpos($item, '.')+1); - $item = (strpos($aliased_tables, $table_name) !== FALSE) ? $item = $item : $this->dbprefix.$item; + $escaped_array = array(); + + foreach($item as $k=>$v) + { + $escaped_array[$this->_protect_identifiers($k)] = $this->_protect_identifiers($v, $first_word_only); + } + + return $escaped_array; + } + + // This function may get "item1 item2" as a string, and so + // we may need ""item1" "item2"" and not ""item1 item2"" + if (ctype_alnum($item) === FALSE) + { + if (strpos($item, '.') !== FALSE) + { + $aliased_tables = implode(".",$this->ar_aliased_tables).'.'; + $table_name = substr($item, 0, strpos($item, '.')+1); + $item = (strpos($aliased_tables, $table_name) !== FALSE) ? $item = $item : $this->dbprefix.$item; + } + + // This function may get "field >= 1", and need it to return ""field" >= 1" + $lbound = ($first_word_only === TRUE) ? '' : '|\s|\('; + + $item = preg_replace('/(^'.$lbound.')([\w\d\-\_]+?)(\s|\)|$)/iS', '$1"$2"$3', $item); + } + else + { + return "\"{$item}\""; } + $exceptions = array('AS', '/', '-', '%', '+', '*'); + + foreach ($exceptions as $exception) + { + + if (stristr($item, " \"{$exception}\" ") !== FALSE) + { + $item = preg_replace('/ "('.preg_quote($exception).')" /i', ' $1 ', $item); + } + } return $item; } diff --git a/system/database/drivers/mysqli/mysqli_driver.php b/system/database/drivers/mysqli/mysqli_driver.php index b6d1cba77..31c27117c 100644 --- a/system/database/drivers/mysqli/mysqli_driver.php +++ b/system/database/drivers/mysqli/mysqli_driver.php @@ -96,7 +96,8 @@ class CI_DB_mysqli_driver extends CI_DB { */ function db_set_charset($charset, $collation) { - return @mysqli_query($this->conn_id, "SET NAMES '".$this->escape_str($charset)."' COLLATE '".$this->escape_str($collation)."'"); + // TODO - add support if needed + return TRUE; } // -------------------------------------------------------------------- diff --git a/system/database/drivers/oci8/oci8_driver.php b/system/database/drivers/oci8/oci8_driver.php index 7aab37e82..8f63c25a5 100644 --- a/system/database/drivers/oci8/oci8_driver.php +++ b/system/database/drivers/oci8/oci8_driver.php @@ -556,7 +556,7 @@ class CI_DB_oci8_driver extends CI_DB { } // This function may get "item1 item2" as a string, and so - // we may need "`item1` `item2`" and not "`item1 item2`" + // we may need ""item1" "item2"" and not ""item1 item2"" if (ctype_alnum($item) === FALSE) { if (strpos($item, '.') !== FALSE) @@ -566,14 +566,14 @@ class CI_DB_oci8_driver extends CI_DB { $item = (strpos($aliased_tables, $table_name) !== FALSE) ? $item = $item : $this->dbprefix.$item; } - // This function may get "field >= 1", and need it to return "`field` >= 1" + // This function may get "field >= 1", and need it to return ""field" >= 1" $lbound = ($first_word_only === TRUE) ? '' : '|\s|\('; - $item = preg_replace('/(^'.$lbound.')([\w\d\-\_]+?)(\s|\)|$)/iS', '$1`$2`$3', $item); + $item = preg_replace('/(^'.$lbound.')([\w\d\-\_]+?)(\s|\)|$)/iS', '$1"$2"$3', $item); } else { - return "`{$item}`"; + return "\"{$item}\""; } $exceptions = array('AS', '/', '-', '%', '+', '*'); @@ -581,9 +581,9 @@ class CI_DB_oci8_driver extends CI_DB { foreach ($exceptions as $exception) { - if (stristr($item, " `{$exception}` ") !== FALSE) + if (stristr($item, " \"{$exception}\" ") !== FALSE) { - $item = preg_replace('/ `('.preg_quote($exception).')` /i', ' $1 ', $item); + $item = preg_replace('/ "('.preg_quote($exception).')" /i', ' $1 ', $item); } } return $item; @@ -608,7 +608,7 @@ class CI_DB_oci8_driver extends CI_DB { $tables = array($tables); } - return '('.implode(', ', $tables).')'; + return implode(', ', $tables); } // -------------------------------------------------------------------- diff --git a/system/database/drivers/postgre/postgre_driver.php b/system/database/drivers/postgre/postgre_driver.php index cac0ecb60..a32c37ed8 100644 --- a/system/database/drivers/postgre/postgre_driver.php +++ b/system/database/drivers/postgre/postgre_driver.php @@ -493,7 +493,7 @@ class CI_DB_postgre_driver extends CI_DB { $tables = array($tables); } - return '('.implode(', ', $tables).')'; + return implode(', ', $tables); } // -------------------------------------------------------------------- diff --git a/system/database/drivers/sqlite/sqlite_driver.php b/system/database/drivers/sqlite/sqlite_driver.php index 5290edeea..b6cb460b1 100644 --- a/system/database/drivers/sqlite/sqlite_driver.php +++ b/system/database/drivers/sqlite/sqlite_driver.php @@ -404,7 +404,7 @@ class CI_DB_sqlite_driver extends CI_DB { { if (stristr($table, '.')) { - $table = preg_replace("/\./", "`.`", $table); + $table = preg_replace("/\./", ".", $table); } return $table; @@ -437,7 +437,7 @@ class CI_DB_sqlite_driver extends CI_DB { } // This function may get "item1 item2" as a string, and so - // we may need "`item1` `item2`" and not "`item1 item2`" + // we may need "item1 item2" and not "item1 item2" if (ctype_alnum($item) === FALSE) { if (strpos($item, '.') !== FALSE) @@ -447,14 +447,14 @@ class CI_DB_sqlite_driver extends CI_DB { $item = (strpos($aliased_tables, $table_name) !== FALSE) ? $item = $item : $this->dbprefix.$item; } - // This function may get "field >= 1", and need it to return "`field` >= 1" + // This function may get "field >= 1", and need it to return "field >= 1" $lbound = ($first_word_only === TRUE) ? '' : '|\s|\('; - $item = preg_replace('/(^'.$lbound.')([\w\d\-\_]+?)(\s|\)|$)/iS', '$1`$2`$3', $item); + $item = preg_replace('/(^'.$lbound.')([\w\d\-\_]+?)(\s|\)|$)/iS', '$1$2$3', $item); } else { - return "`{$item}`"; + return "{$item}"; } $exceptions = array('AS', '/', '-', '%', '+', '*'); @@ -462,9 +462,9 @@ class CI_DB_sqlite_driver extends CI_DB { foreach ($exceptions as $exception) { - if (stristr($item, " `{$exception}` ") !== FALSE) + if (stristr($item, " {$exception} ") !== FALSE) { - $item = preg_replace('/ `('.preg_quote($exception).')` /i', ' $1 ', $item); + $item = preg_replace('/ ('.preg_quote($exception).') /i', ' $1 ', $item); } } return $item; -- cgit v1.2.3-24-g4f1b From 7555ade507982af16ed763e2e560a60892408bd2 Mon Sep 17 00:00:00 2001 From: Derek Allard Date: Sun, 10 Feb 2008 23:40:41 +0000 Subject: clarifying comment on sqlite escape table --- system/database/drivers/sqlite/sqlite_driver.php | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) (limited to 'system') diff --git a/system/database/drivers/sqlite/sqlite_driver.php b/system/database/drivers/sqlite/sqlite_driver.php index b6cb460b1..c51edfb07 100644 --- a/system/database/drivers/sqlite/sqlite_driver.php +++ b/system/database/drivers/sqlite/sqlite_driver.php @@ -402,11 +402,9 @@ class CI_DB_sqlite_driver extends CI_DB { */ function _escape_table($table) { - if (stristr($table, '.')) - { - $table = preg_replace("/\./", ".", $table); - } - + + // other database drivers use this to add backticks, hence this + // function is simply going to return the tablename for sqlite return $table; } -- cgit v1.2.3-24-g4f1b From 41d4b592b9b0962e444938fcf106cccbbd8fda59 Mon Sep 17 00:00:00 2001 From: Derek Allard Date: Sun, 10 Feb 2008 23:47:13 +0000 Subject: escape_table made consistent with mysql driver across all drivers --- system/database/drivers/mssql/mssql_driver.php | 4 ++-- system/database/drivers/mysqli/mysqli_driver.php | 4 ++-- system/database/drivers/oci8/oci8_driver.php | 4 ++-- system/database/drivers/odbc/odbc_driver.php | 4 ++-- system/database/drivers/postgre/postgre_driver.php | 4 ++-- 5 files changed, 10 insertions(+), 10 deletions(-) (limited to 'system') diff --git a/system/database/drivers/mssql/mssql_driver.php b/system/database/drivers/mssql/mssql_driver.php index 8e12a2d21..e429d21a6 100644 --- a/system/database/drivers/mssql/mssql_driver.php +++ b/system/database/drivers/mssql/mssql_driver.php @@ -408,9 +408,9 @@ class CI_DB_mssql_driver extends CI_DB { // I don't believe this is necessary with MS SQL. Not sure, though. - Rick /* - if (stristr($table, '.')) + if (strpos($table, '.') !== FALSE) { - $table = preg_replace("/\./", "`.`", $table); + $table = str_replace('.', '`.`', $table); } */ diff --git a/system/database/drivers/mysqli/mysqli_driver.php b/system/database/drivers/mysqli/mysqli_driver.php index 31c27117c..61848a674 100644 --- a/system/database/drivers/mysqli/mysqli_driver.php +++ b/system/database/drivers/mysqli/mysqli_driver.php @@ -410,9 +410,9 @@ class CI_DB_mysqli_driver extends CI_DB { */ function _escape_table($table) { - if (stristr($table, '.')) + if (strpos($table, '.') !== FALSE) { - $table = preg_replace("/\./", "`.`", $table); + $table = str_replace('.', '`.`', $table); } return $table; diff --git a/system/database/drivers/oci8/oci8_driver.php b/system/database/drivers/oci8/oci8_driver.php index 8f63c25a5..33fe08725 100644 --- a/system/database/drivers/oci8/oci8_driver.php +++ b/system/database/drivers/oci8/oci8_driver.php @@ -521,9 +521,9 @@ class CI_DB_oci8_driver extends CI_DB { */ function _escape_table($table) { - if (stristr($table, '.')) + if (strpos($table, '.') !== FALSE) { - $table = preg_replace("/\./", "`.`", $table); + $table = str_replace('.', '`.`', $table); } return $table; diff --git a/system/database/drivers/odbc/odbc_driver.php b/system/database/drivers/odbc/odbc_driver.php index dd10fbdd3..c949a4670 100644 --- a/system/database/drivers/odbc/odbc_driver.php +++ b/system/database/drivers/odbc/odbc_driver.php @@ -386,9 +386,9 @@ class CI_DB_odbc_driver extends CI_DB { */ function _escape_table($table) { - if (stristr($table, '.')) + if (strpos($table, '.') !== FALSE) { - $table = preg_replace("/\./", "`.`", $table); + $table = str_replace('.', '`.`', $table); } return $table; diff --git a/system/database/drivers/postgre/postgre_driver.php b/system/database/drivers/postgre/postgre_driver.php index a32c37ed8..2472c5e92 100644 --- a/system/database/drivers/postgre/postgre_driver.php +++ b/system/database/drivers/postgre/postgre_driver.php @@ -406,9 +406,9 @@ class CI_DB_postgre_driver extends CI_DB { */ function _escape_table($table) { - if (stristr($table, '.')) + if (strpos($table, '.') !== FALSE) { - $table = '"'.preg_replace("/\./", '"."', $table).'"'; + $table = str_replace('.', '`.`', $table); } return $table; -- cgit v1.2.3-24-g4f1b From 70529a739dd0a73fc72124720390313d8a8b0dca Mon Sep 17 00:00:00 2001 From: Derek Allard Date: Mon, 11 Feb 2008 03:54:42 +0000 Subject: driver escape_table fixes --- system/database/drivers/mssql/mssql_driver.php | 4 ++-- system/database/drivers/mysqli/mysqli_driver.php | 4 ++-- system/database/drivers/oci8/oci8_driver.php | 4 ++-- system/database/drivers/odbc/odbc_driver.php | 4 ++-- system/database/drivers/postgre/postgre_driver.php | 4 ++-- 5 files changed, 10 insertions(+), 10 deletions(-) (limited to 'system') diff --git a/system/database/drivers/mssql/mssql_driver.php b/system/database/drivers/mssql/mssql_driver.php index e429d21a6..8e12a2d21 100644 --- a/system/database/drivers/mssql/mssql_driver.php +++ b/system/database/drivers/mssql/mssql_driver.php @@ -408,9 +408,9 @@ class CI_DB_mssql_driver extends CI_DB { // I don't believe this is necessary with MS SQL. Not sure, though. - Rick /* - if (strpos($table, '.') !== FALSE) + if (stristr($table, '.')) { - $table = str_replace('.', '`.`', $table); + $table = preg_replace("/\./", "`.`", $table); } */ diff --git a/system/database/drivers/mysqli/mysqli_driver.php b/system/database/drivers/mysqli/mysqli_driver.php index 61848a674..31c27117c 100644 --- a/system/database/drivers/mysqli/mysqli_driver.php +++ b/system/database/drivers/mysqli/mysqli_driver.php @@ -410,9 +410,9 @@ class CI_DB_mysqli_driver extends CI_DB { */ function _escape_table($table) { - if (strpos($table, '.') !== FALSE) + if (stristr($table, '.')) { - $table = str_replace('.', '`.`', $table); + $table = preg_replace("/\./", "`.`", $table); } return $table; diff --git a/system/database/drivers/oci8/oci8_driver.php b/system/database/drivers/oci8/oci8_driver.php index 33fe08725..8f63c25a5 100644 --- a/system/database/drivers/oci8/oci8_driver.php +++ b/system/database/drivers/oci8/oci8_driver.php @@ -521,9 +521,9 @@ class CI_DB_oci8_driver extends CI_DB { */ function _escape_table($table) { - if (strpos($table, '.') !== FALSE) + if (stristr($table, '.')) { - $table = str_replace('.', '`.`', $table); + $table = preg_replace("/\./", "`.`", $table); } return $table; diff --git a/system/database/drivers/odbc/odbc_driver.php b/system/database/drivers/odbc/odbc_driver.php index c949a4670..dd10fbdd3 100644 --- a/system/database/drivers/odbc/odbc_driver.php +++ b/system/database/drivers/odbc/odbc_driver.php @@ -386,9 +386,9 @@ class CI_DB_odbc_driver extends CI_DB { */ function _escape_table($table) { - if (strpos($table, '.') !== FALSE) + if (stristr($table, '.')) { - $table = str_replace('.', '`.`', $table); + $table = preg_replace("/\./", "`.`", $table); } return $table; diff --git a/system/database/drivers/postgre/postgre_driver.php b/system/database/drivers/postgre/postgre_driver.php index 2472c5e92..a32c37ed8 100644 --- a/system/database/drivers/postgre/postgre_driver.php +++ b/system/database/drivers/postgre/postgre_driver.php @@ -406,9 +406,9 @@ class CI_DB_postgre_driver extends CI_DB { */ function _escape_table($table) { - if (strpos($table, '.') !== FALSE) + if (stristr($table, '.')) { - $table = str_replace('.', '`.`', $table); + $table = '"'.preg_replace("/\./", '"."', $table).'"'; } return $table; -- cgit v1.2.3-24-g4f1b From c0743381b20910a3fc23b391e8b2009ac5771ae8 Mon Sep 17 00:00:00 2001 From: Derek Allard Date: Mon, 11 Feb 2008 05:54:44 +0000 Subject: database enhancements, compatibility additions and bugfixes --- system/database/DB_driver.php | 28 ++++++++++++++-------- system/database/drivers/mssql/mssql_driver.php | 4 ++-- system/database/drivers/mysql/mysql_driver.php | 2 +- system/database/drivers/mysqli/mysqli_driver.php | 4 ++-- system/database/drivers/oci8/oci8_driver.php | 4 ++-- system/database/drivers/odbc/odbc_driver.php | 4 ++-- system/database/drivers/postgre/postgre_driver.php | 4 ++-- 7 files changed, 29 insertions(+), 21 deletions(-) (limited to 'system') diff --git a/system/database/DB_driver.php b/system/database/DB_driver.php index 966fd3ad5..6b3a74b94 100644 --- a/system/database/DB_driver.php +++ b/system/database/DB_driver.php @@ -556,8 +556,8 @@ class CI_DB_driver { * @return string */ function compile_binds($sql, $binds) - { - if (FALSE === strpos($sql, $this->bind_marker)) + { + if (strpos($sql, $this->bind_marker) === FALSE) { return $sql; } @@ -567,17 +567,25 @@ class CI_DB_driver { $binds = array($binds); } - foreach ($binds as $val) + // 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) { - $val = $this->escape($val); - - // Just in case the replacement string contains the bind - // character we'll temporarily replace it with a marker - $val = str_replace($this->bind_marker, '{%bind_marker%}', $val); - $sql = preg_replace("#".preg_quote($this->bind_marker, '#')."#", str_replace('$', '\$', $val), $sql, 1); + $result .= $this->escape($bind); + $result .= $segments[++$i]; } - return str_replace('{%bind_marker%}', $this->bind_marker, $sql); + return $result; } // -------------------------------------------------------------------- diff --git a/system/database/drivers/mssql/mssql_driver.php b/system/database/drivers/mssql/mssql_driver.php index 8e12a2d21..7b024d414 100644 --- a/system/database/drivers/mssql/mssql_driver.php +++ b/system/database/drivers/mssql/mssql_driver.php @@ -408,9 +408,9 @@ class CI_DB_mssql_driver extends CI_DB { // I don't believe this is necessary with MS SQL. Not sure, though. - Rick /* - if (stristr($table, '.')) + if (strpos($table, '.') !== FALSE) { - $table = preg_replace("/\./", "`.`", $table); + $table = '"' . str_replace('.', '"."', $table) . '"'; } */ diff --git a/system/database/drivers/mysql/mysql_driver.php b/system/database/drivers/mysql/mysql_driver.php index 372365aeb..edf09a170 100644 --- a/system/database/drivers/mysql/mysql_driver.php +++ b/system/database/drivers/mysql/mysql_driver.php @@ -418,7 +418,7 @@ class CI_DB_mysql_driver extends CI_DB { { if (strpos($table, '.') !== FALSE) { - $table = str_replace('.', '`.`', $table); + $table = '`' . str_replace('.', '`.`', $table) . '`'; } return $table; diff --git a/system/database/drivers/mysqli/mysqli_driver.php b/system/database/drivers/mysqli/mysqli_driver.php index 31c27117c..dab56c7e7 100644 --- a/system/database/drivers/mysqli/mysqli_driver.php +++ b/system/database/drivers/mysqli/mysqli_driver.php @@ -410,9 +410,9 @@ class CI_DB_mysqli_driver extends CI_DB { */ function _escape_table($table) { - if (stristr($table, '.')) + if (strpos($table, '.') !== FALSE) { - $table = preg_replace("/\./", "`.`", $table); + $table = '`' . str_replace('.', '`.`', $table) . '`'; } return $table; diff --git a/system/database/drivers/oci8/oci8_driver.php b/system/database/drivers/oci8/oci8_driver.php index 8f63c25a5..ec26f5be6 100644 --- a/system/database/drivers/oci8/oci8_driver.php +++ b/system/database/drivers/oci8/oci8_driver.php @@ -521,9 +521,9 @@ class CI_DB_oci8_driver extends CI_DB { */ function _escape_table($table) { - if (stristr($table, '.')) + if (strpos($table, '.') !== FALSE) { - $table = preg_replace("/\./", "`.`", $table); + $table = '"' . str_replace('.', '"."', $table) . '"'; } return $table; diff --git a/system/database/drivers/odbc/odbc_driver.php b/system/database/drivers/odbc/odbc_driver.php index dd10fbdd3..fd2460853 100644 --- a/system/database/drivers/odbc/odbc_driver.php +++ b/system/database/drivers/odbc/odbc_driver.php @@ -386,9 +386,9 @@ class CI_DB_odbc_driver extends CI_DB { */ function _escape_table($table) { - if (stristr($table, '.')) + if (strpos($table, '.') !== FALSE) { - $table = preg_replace("/\./", "`.`", $table); + $table = '`' . str_replace('.', '`.`', $table) . '`'; } return $table; diff --git a/system/database/drivers/postgre/postgre_driver.php b/system/database/drivers/postgre/postgre_driver.php index a32c37ed8..ce8cb258a 100644 --- a/system/database/drivers/postgre/postgre_driver.php +++ b/system/database/drivers/postgre/postgre_driver.php @@ -406,9 +406,9 @@ class CI_DB_postgre_driver extends CI_DB { */ function _escape_table($table) { - if (stristr($table, '.')) + if (strpos($table, '.') !== FALSE) { - $table = '"'.preg_replace("/\./", '"."', $table).'"'; + $table = '"' . str_replace('.', '"."', $table) . '"'; } return $table; -- cgit v1.2.3-24-g4f1b From 903cc985da13463369a4cb1831ccbe5449316ee7 Mon Sep 17 00:00:00 2001 From: Derek Allard Date: Mon, 11 Feb 2008 06:06:59 +0000 Subject: remove backticks from ODBC --- system/database/drivers/odbc/odbc_driver.php | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) (limited to 'system') diff --git a/system/database/drivers/odbc/odbc_driver.php b/system/database/drivers/odbc/odbc_driver.php index fd2460853..bdedab32f 100644 --- a/system/database/drivers/odbc/odbc_driver.php +++ b/system/database/drivers/odbc/odbc_driver.php @@ -386,11 +386,7 @@ class CI_DB_odbc_driver extends CI_DB { */ function _escape_table($table) { - if (strpos($table, '.') !== FALSE) - { - $table = '`' . str_replace('.', '`.`', $table) . '`'; - } - + // used to add backticks in other db drivers return $table; } @@ -438,7 +434,7 @@ class CI_DB_odbc_driver extends CI_DB { } else { - return "`{$item}`"; + return "{$item}"; } $exceptions = array('AS', '/', '-', '%', '+', '*'); @@ -446,9 +442,9 @@ class CI_DB_odbc_driver extends CI_DB { foreach ($exceptions as $exception) { - if (stristr($item, " `{$exception}` ") !== FALSE) + if (stristr($item, " {$exception} ") !== FALSE) { - $item = preg_replace('/ `('.preg_quote($exception).')` /i', ' $1 ', $item); + $item = preg_replace('/ ('.preg_quote($exception).') /i', ' $1 ', $item); } } return $item; -- cgit v1.2.3-24-g4f1b From 466039ab97e67a23168798731084d4127c7f30a1 Mon Sep 17 00:00:00 2001 From: Derek Allard Date: Mon, 11 Feb 2008 12:46:24 +0000 Subject: added Path Helper --- system/helpers/path_helper.php | 70 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 70 insertions(+) create mode 100644 system/helpers/path_helper.php (limited to 'system') diff --git a/system/helpers/path_helper.php b/system/helpers/path_helper.php new file mode 100644 index 000000000..30d26d6ee --- /dev/null +++ b/system/helpers/path_helper.php @@ -0,0 +1,70 @@ + \ No newline at end of file -- cgit v1.2.3-24-g4f1b From 26b63aab0639318cb2216363de175c4f00f208a4 Mon Sep 17 00:00:00 2001 From: Derek Allard Date: Tue, 12 Feb 2008 04:18:49 +0000 Subject: change 1.6.1 to 1.6.0.1 --- system/codeigniter/CodeIgniter.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system') diff --git a/system/codeigniter/CodeIgniter.php b/system/codeigniter/CodeIgniter.php index 8f9dbdf64..72b4b7ed5 100644 --- a/system/codeigniter/CodeIgniter.php +++ b/system/codeigniter/CodeIgniter.php @@ -28,7 +28,7 @@ */ // CI Version -define('CI_VERSION', '1.6.1'); +define('CI_VERSION', '1.6.0.1'); /* * ------------------------------------------------------ -- cgit v1.2.3-24-g4f1b From 197d10b0cc22ee2127058e3b859b7b4e4abcc30b Mon Sep 17 00:00:00 2001 From: Derek Allard Date: Tue, 12 Feb 2008 04:20:38 +0000 Subject: --- system/codeigniter/CodeIgniter.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system') diff --git a/system/codeigniter/CodeIgniter.php b/system/codeigniter/CodeIgniter.php index 72b4b7ed5..8f9dbdf64 100644 --- a/system/codeigniter/CodeIgniter.php +++ b/system/codeigniter/CodeIgniter.php @@ -28,7 +28,7 @@ */ // CI Version -define('CI_VERSION', '1.6.0.1'); +define('CI_VERSION', '1.6.1'); /* * ------------------------------------------------------ -- cgit v1.2.3-24-g4f1b From 881a79e0ce32bc579ff58449c85e183b96227615 Mon Sep 17 00:00:00 2001 From: Derek Jones Date: Wed, 13 Feb 2008 03:28:18 +0000 Subject: Fixed bug (#3445) where the routed segment array when the default controller is used was not being re-indexed to begin with 1 --- system/libraries/Router.php | 3 +++ 1 file changed, 3 insertions(+) (limited to 'system') diff --git a/system/libraries/Router.php b/system/libraries/Router.php index d24192c18..f6464a31d 100644 --- a/system/libraries/Router.php +++ b/system/libraries/Router.php @@ -102,6 +102,9 @@ class CI_Router { $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."); return; } -- cgit v1.2.3-24-g4f1b From b069789c78fdd1d33eff4b4f6c71a9883f1890a1 Mon Sep 17 00:00:00 2001 From: Derek Jones Date: Wed, 13 Feb 2008 03:38:39 +0000 Subject: removed the array_diff comparison in _reindex_segments(). That conditional and use of those functions is probably slower than looping through both arrays, even if someone went crazy with dozens of URI segments. --- system/libraries/URI.php | 23 ++++++++--------------- 1 file changed, 8 insertions(+), 15 deletions(-) (limited to 'system') diff --git a/system/libraries/URI.php b/system/libraries/URI.php index 8de26f933..aecf05138 100644 --- a/system/libraries/URI.php +++ b/system/libraries/URI.php @@ -245,30 +245,23 @@ class CI_URI { */ function _reindex_segments() { - // Is the routed segment array different then the main segment array? - // have to compute the diff both ways since PHP returns only values in $arr1 that are not in $arr2. - $diff = (array_diff($this->rsegments, $this->segments) != array_diff($this->segments, $this->rsegments)) ? TRUE : FALSE; - $i = 1; + foreach ($this->segments as $val) { $this->segments[$i++] = $val; } + unset($this->segments[0]); - if ($diff == FALSE) - { - $this->rsegments = $this->segments; - } - else + $i = 1; + + foreach ($this->rsegments as $val) { - $i = 1; - foreach ($this->rsegments as $val) - { - $this->rsegments[$i++] = $val; - } - unset($this->rsegments[0]); + $this->rsegments[$i++] = $val; } + + unset($this->rsegments[0]); } // -------------------------------------------------------------------- -- cgit v1.2.3-24-g4f1b From d33972bed776a8e95d1e5602534898672eb56cae Mon Sep 17 00:00:00 2001 From: Derek Jones Date: Wed, 13 Feb 2008 04:16:27 +0000 Subject: changed escape_str() in mysqli_driver() to use is_object() instead of is_resource() to test $this->conn_id --- system/database/drivers/mysqli/mysqli_driver.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system') diff --git a/system/database/drivers/mysqli/mysqli_driver.php b/system/database/drivers/mysqli/mysqli_driver.php index dab56c7e7..aaeab5765 100644 --- a/system/database/drivers/mysqli/mysqli_driver.php +++ b/system/database/drivers/mysqli/mysqli_driver.php @@ -249,7 +249,7 @@ class CI_DB_mysqli_driver extends CI_DB { */ function escape_str($str) { - if (function_exists('mysqli_real_escape_string') AND is_resource($this->conn_id)) + if (function_exists('mysqli_real_escape_string') AND is_object($this->conn_id)) { return mysqli_real_escape_string($this->conn_id, $str); } -- cgit v1.2.3-24-g4f1b From 5b4d53271a841c60e43d64f4b6b3c32794b41ac7 Mon Sep 17 00:00:00 2001 From: Derek Jones Date: Wed, 13 Feb 2008 04:34:10 +0000 Subject: fixes to _create_table() in sqlite_forge.php: removed space between table name and parenthesis added version check for IF NOT EXISTS --- system/database/drivers/sqlite/sqlite_forge.php | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'system') diff --git a/system/database/drivers/sqlite/sqlite_forge.php b/system/database/drivers/sqlite/sqlite_forge.php index e3196cce1..1fd2a2bd4 100644 --- a/system/database/drivers/sqlite/sqlite_forge.php +++ b/system/database/drivers/sqlite/sqlite_forge.php @@ -76,12 +76,13 @@ class CI_DB_sqlite_forge extends CI_DB_forge { { $sql = 'CREATE TABLE '; - if ($if_not_exists === TRUE) + // IF NOT EXISTS added to SQLite in 3.3.0 + if ($if_not_exists === TRUE && version_compare($this->_version(), '3.3.0', '>=') === TRUE) { $sql .= 'IF NOT EXISTS '; } - $sql .= $this->db->_escape_table($table)." ("; + $sql .= $this->db->_escape_table($table)."("; $current_field_count = 0; foreach ($fields as $field=>$attributes) -- cgit v1.2.3-24-g4f1b From 7dd3838f188f35d63a30c30b435fbb7f2e2d3d7e Mon Sep 17 00:00:00 2001 From: Derek Jones Date: Wed, 13 Feb 2008 04:52:58 +0000 Subject: fixed bug #3419, moved DSN parsing to DB.php so the driver could properly be set to instantiate the correct db driver class. --- system/database/DB.php | 23 +++++++++++++++++++++++ system/database/DB_driver.php | 25 +------------------------ 2 files changed, 24 insertions(+), 24 deletions(-) (limited to 'system') diff --git a/system/database/DB.php b/system/database/DB.php index 078f1ef0f..c3e7722d3 100644 --- a/system/database/DB.php +++ b/system/database/DB.php @@ -46,6 +46,29 @@ function &DB($params = '', $active_record_override = FALSE) $params = $db[$active_group]; } + else + { + + /* 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 (($dns = @parse_url($params)) === FALSE) + { + show_error('Invalid DB Connection String'); + } + + $params = array( + 'dbdriver' => $dns['scheme'], + 'hostname' => (isset($dns['host'])) ? rawurldecode($dns['host']) : '', + 'username' => (isset($dns['user'])) ? rawurldecode($dns['user']) : '', + 'password' => (isset($dns['pass'])) ? rawurldecode($dns['pass']) : '', + 'database' => (isset($dns['path'])) ? rawurldecode(substr($dns['host'], 1)) : '' + ); + } // No DB specified yet? Beat them senseless... if ( ! isset($params['dbdriver']) OR $params['dbdriver'] == '') diff --git a/system/database/DB_driver.php b/system/database/DB_driver.php index 6b3a74b94..b1013178e 100644 --- a/system/database/DB_driver.php +++ b/system/database/DB_driver.php @@ -70,12 +70,7 @@ class CI_DB_driver { * Constructor. Accepts one parameter containing the database * connection settings. * - * 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'; - * - * @param mixed. Can be an array or a DSN string + * @param array */ function CI_DB_driver($params) { @@ -86,24 +81,6 @@ class CI_DB_driver { $this->$key = $val; } } - elseif (strpos($params, '://')) - { - if (FALSE === ($dsn = @parse_url($params))) - { - log_message('error', 'Invalid DB Connection String'); - - if ($this->db_debug) - { - return $this->display_error('db_invalid_connection_str'); - } - return FALSE; - } - - $this->hostname = ( ! isset($dsn['host'])) ? '' : rawurldecode($dsn['host']); - $this->username = ( ! isset($dsn['user'])) ? '' : rawurldecode($dsn['user']); - $this->password = ( ! isset($dsn['pass'])) ? '' : rawurldecode($dsn['pass']); - $this->database = ( ! isset($dsn['path'])) ? '' : rawurldecode(substr($dsn['path'], 1)); - } log_message('debug', 'Database Driver Class Initialized'); } -- cgit v1.2.3-24-g4f1b From b1f90dbfd5fb7610865c4ff31b9d75bc821560a7 Mon Sep 17 00:00:00 2001 From: Derek Jones Date: Wed, 13 Feb 2008 05:22:38 +0000 Subject: reapplied implementation of db_set_charset() for MySQLi... --- system/database/drivers/mysqli/mysqli_driver.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'system') diff --git a/system/database/drivers/mysqli/mysqli_driver.php b/system/database/drivers/mysqli/mysqli_driver.php index aaeab5765..73396c594 100644 --- a/system/database/drivers/mysqli/mysqli_driver.php +++ b/system/database/drivers/mysqli/mysqli_driver.php @@ -96,8 +96,7 @@ class CI_DB_mysqli_driver extends CI_DB { */ function db_set_charset($charset, $collation) { - // TODO - add support if needed - return TRUE; + return @mysqli_query($this->conn_id, "SET NAMES '".$this->escape_str($charset)."' COLLATE '".$this->escape_str($collation)."'"); } // -------------------------------------------------------------------- -- cgit v1.2.3-24-g4f1b From 63eac3eb96563336612c69452745190e8af3c813 Mon Sep 17 00:00:00 2001 From: Derek Jones Date: Thu, 14 Feb 2008 20:23:37 +0000 Subject: little protection in case an array is provided as the $params for the DB class --- system/database/DB.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system') diff --git a/system/database/DB.php b/system/database/DB.php index c3e7722d3..16ca1c888 100644 --- a/system/database/DB.php +++ b/system/database/DB.php @@ -46,7 +46,7 @@ function &DB($params = '', $active_record_override = FALSE) $params = $db[$active_group]; } - else + elseif (is_string($params)) { /* parse the URL from the DSN string -- cgit v1.2.3-24-g4f1b From 05a37a1ed0e12554e8d4fbd47712434853f7e6b2 Mon Sep 17 00:00:00 2001 From: Derek Jones Date: Mon, 18 Feb 2008 20:54:15 +0000 Subject: Escaped the '-' in the default 'permitted_uri_chars' config item, as some developers just want to add characters to the pattern and do not have a good grasp of regular expressions. --- system/application/config/config.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system') diff --git a/system/application/config/config.php b/system/application/config/config.php index a02fed142..72d38199c 100644 --- a/system/application/config/config.php +++ b/system/application/config/config.php @@ -123,7 +123,7 @@ $config['subclass_prefix'] = 'MY_'; | DO NOT CHANGE THIS UNLESS YOU FULLY UNDERSTAND THE REPERCUSSIONS!! | */ -$config['permitted_uri_chars'] = 'a-z 0-9~%.:_-'; +$config['permitted_uri_chars'] = 'a-z 0-9~%.:_\-'; /* -- cgit v1.2.3-24-g4f1b From 06935e610645384faf3d3897585ed4be668d4795 Mon Sep 17 00:00:00 2001 From: Derek Jones Date: Mon, 18 Feb 2008 23:04:22 +0000 Subject: clarified in the config comment instructions that 'permitted_uri_chars' is a regular expression --- system/application/config/config.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'system') diff --git a/system/application/config/config.php b/system/application/config/config.php index 72d38199c..6a7b85745 100644 --- a/system/application/config/config.php +++ b/system/application/config/config.php @@ -111,9 +111,9 @@ $config['subclass_prefix'] = 'MY_'; | Allowed URL Characters |-------------------------------------------------------------------------- | -| This lets you specify which characters are permitted within your URLs. -| When someone tries to submit a URL with disallowed characters they will -| get a warning message. +| This lets you specify with a regular expression which characters are permitted +| within your URLs. When someone tries to submit a URL with disallowed +| characters they will get a warning message. | | As a security measure you are STRONGLY encouraged to restrict URLs to | as few characters as possible. By default only these are allowed: a-z 0-9~%.:_- -- cgit v1.2.3-24-g4f1b From fd971781c4f4d1b436cc7b9efd2e409b7b400b88 Mon Sep 17 00:00:00 2001 From: Derek Jones Date: Wed, 20 Feb 2008 18:39:18 +0000 Subject: modified get_filenames() to return FALSE if the directory cannot be read --- system/helpers/file_helper.php | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'system') diff --git a/system/helpers/file_helper.php b/system/helpers/file_helper.php index ef07de76c..0005c2a24 100644 --- a/system/helpers/file_helper.php +++ b/system/helpers/file_helper.php @@ -184,6 +184,10 @@ if (! function_exists('get_filenames')) } return $_filedata; } + else + { + return $FALSE; + } } } -- cgit v1.2.3-24-g4f1b From bca400fbd1cccf817bc16c725da2ffe82757b4c7 Mon Sep 17 00:00:00 2001 From: Derek Allard Date: Thu, 21 Feb 2008 22:19:55 +0000 Subject: fix $FALSE to FALSE --- system/helpers/file_helper.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system') diff --git a/system/helpers/file_helper.php b/system/helpers/file_helper.php index 0005c2a24..096d225d7 100644 --- a/system/helpers/file_helper.php +++ b/system/helpers/file_helper.php @@ -186,7 +186,7 @@ if (! function_exists('get_filenames')) } else { - return $FALSE; + return FALSE; } } } -- cgit v1.2.3-24-g4f1b From 80ddb6b70f97c8b08f02b0d8dcffbc6ab136555c Mon Sep 17 00:00:00 2001 From: Derek Allard Date: Mon, 25 Feb 2008 12:51:00 +0000 Subject: Moved the safe mode and auth checks for the Email library into the constructor --- system/libraries/Email.php | 86 ++++++++++++++++++++++++---------------------- 1 file changed, 44 insertions(+), 42 deletions(-) (limited to 'system') diff --git a/system/libraries/Email.php b/system/libraries/Email.php index 25e59632f..189678742 100644 --- a/system/libraries/Email.php +++ b/system/libraries/Email.php @@ -45,13 +45,13 @@ class CI_Email { var $validate = FALSE; // TRUE/FALSE. Enables email validation var $priority = "3"; // Default priority (1 - 5) var $newline = "\n"; // Default newline. "\r\n" or "\n" (Use "\r\n" to comply with RFC 822) - var $crlf = "\n"; // The RFC 2045 compliant CRLF for quoted-printable is "\r\n". Apparently some servers, // even on the receiving end think they need to muck with CRLFs, so using "\n", while // distasteful, is the only thing that seems to work for all environments. - + var $send_multipart = TRUE; // TRUE/FALSE - Yahoo does not like multipart alternative, so this is an override. Set to FALSE for Yahoo. var $bcc_batch_mode = FALSE; // TRUE/FALSE Turns on/off Bcc batch feature var $bcc_batch_size = 200; // If bcc_batch_mode = TRUE, sets max number of Bccs in each batch + var $_safe_mode = FALSE; var $_subject = ""; var $_body = ""; var $_finalbody = ""; @@ -59,8 +59,7 @@ class CI_Email { var $_atc_boundary = ""; var $_header_str = ""; var $_smtp_connect = ""; - var $_encoding = "8bit"; - var $_safe_mode = FALSE; + var $_encoding = "8bit"; var $_IP = FALSE; var $_smtp_auth = FALSE; var $_replyto_flag = FALSE; @@ -90,6 +89,9 @@ class CI_Email { $this->initialize($config); } + $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"); } @@ -121,8 +123,6 @@ class CI_Email { } } } - $this->_smtp_auth = ($this->smtp_user == '' AND $this->smtp_pass == '') ? FALSE : TRUE; - $this->_safe_mode = ((boolean)@ini_get("safe_mode") === FALSE) ? FALSE : TRUE; } // -------------------------------------------------------------------- @@ -372,20 +372,10 @@ class CI_Email { function _str_to_array($email) { if ( ! is_array($email)) - { - if (ereg(',$', $email)) - $email = substr($email, 0, -1); - - if (ereg('^,', $email)) - $email = substr($email, 1); - - if (ereg(',', $email)) - { - $x = explode(',', $email); - $email = array(); - - for ($i = 0; $i < count($x); $i ++) - $email[] = trim($x[$i]); + { + if (strpos($email, ',') !== FALSE) + { + $email = preg_split('/[\s,]/', $email, -1, PREG_SPLIT_NO_EMPTY); } else { @@ -665,10 +655,7 @@ class CI_Email { */ function valid_email($address) { - if ( ! preg_match("/^([a-z0-9\+_\-]+)(\.[a-z0-9\+_\-]+)*@([a-z0-9\-]+\.)+[a-z]{2,6}$/ix", $address)) - return FALSE; - else - return TRUE; + return ( ! preg_match("/^([a-z0-9\+_\-]+)(\.[a-z0-9\+_\-]+)*@([a-z0-9\-]+\.)+[a-z]{2,6}$/ix", $address)) ? FALSE : TRUE; } // -------------------------------------------------------------------- @@ -691,7 +678,7 @@ class CI_Email { } $clean_email = array(); - + foreach ($email as $addy) { if (preg_match( '/\<(.*)\>/', $addy, $match)) @@ -726,11 +713,10 @@ class CI_Email { { return $this->word_wrap($this->alt_message, '76'); } - - if (eregi( '\', $this->_body, $match)) + + if (preg_match('/\(.*)\<\/body\>/si', $this->_body, $match)) { $body = $match['1']; - $body = substr($body, strpos($body, ">") + 1); } else { @@ -940,30 +926,47 @@ class CI_Email { break; case 'html' : - - $hdr .= "Content-Type: multipart/alternative; boundary=\"" . $this->_alt_boundary . "\"" . $this->newline; - $hdr .= $this->_get_mime_message() . $this->newline . $this->newline; - $hdr .= "--" . $this->_alt_boundary . $this->newline; + + if ($this->send_multipart === FALSE) + { + $hdr .= "Content-Type: text/html;". $this->newline; + } + else + { + $hdr .= "Content-Type: multipart/alternative; boundary=\"" . $this->_alt_boundary . "\"" . $this->newline; + $hdr .= $this->_get_mime_message() . $this->newline . $this->newline; + $hdr .= "--" . $this->_alt_boundary . $this->newline; + + $hdr .= "Content-Type: text/plain; charset=" . $this->charset . $this->newline; + $hdr .= "Content-Transfer-Encoding: " . $this->_get_encoding() . $this->newline . $this->newline; + $hdr .= $this->_get_alt_message() . $this->newline . $this->newline . "--" . $this->_alt_boundary . $this->newline; - $hdr .= "Content-Type: text/plain; charset=" . $this->charset . $this->newline; - $hdr .= "Content-Transfer-Encoding: " . $this->_get_encoding() . $this->newline . $this->newline; - $hdr .= $this->_get_alt_message() . $this->newline . $this->newline . "--" . $this->_alt_boundary . $this->newline; - - $hdr .= "Content-Type: text/html; charset=" . $this->charset . $this->newline; - $hdr .= "Content-Transfer-Encoding: quoted-printable"; + $hdr .= "Content-Type: text/html; charset=" . $this->charset . $this->newline; + $hdr .= "Content-Transfer-Encoding: quoted-printable"; + } $this->_body = $this->_prep_quoted_printable($this->_body); if ($this->_get_protocol() == 'mail') { $this->_header_str .= $hdr; - $this->_finalbody = $this->_body . $this->newline . $this->newline . "--" . $this->_alt_boundary . "--"; + $this->_finalbody = $this->_body . $this->newline . $this->newline; + + if ($this->send_multipart !== FALSE) + { + $this->_finalbody .= "--" . $this->_alt_boundary . "--"; + } return; } $hdr .= $this->newline . $this->newline; - $hdr .= $this->_body . $this->newline . $this->newline . "--" . $this->_alt_boundary . "--"; + $hdr .= $this->_body . $this->newline . $this->newline; + + if ($this->send_multipart !== FALSE) + { + $hdr .= "--" . $this->_alt_boundary . "--"; + } $this->_finalbody = $hdr; return; @@ -1443,7 +1446,6 @@ class CI_Email { */ function _smtp_connect() { - $this->_smtp_connect = fsockopen($this->smtp_host, $this->smtp_port, $errno, @@ -1613,7 +1615,7 @@ class CI_Email { $data .= $str; if (substr($str, 3, 1) == " ") - break; + break; } return $data; -- cgit v1.2.3-24-g4f1b From 9a4d1da5fa823b6bb58cdd1d210f782e95830e91 Mon Sep 17 00:00:00 2001 From: Derek Allard Date: Mon, 25 Feb 2008 14:18:38 +0000 Subject: Fixed an AR_caching error where it wasn't tracking table aliases (#3463) --- system/database/DB_active_rec.php | 2 +- system/database/drivers/mssql/mssql_driver.php | 2 +- system/database/drivers/mysql/mysql_driver.php | 2 +- system/database/drivers/mysqli/mysqli_driver.php | 2 +- system/database/drivers/oci8/oci8_driver.php | 2 +- system/database/drivers/odbc/odbc_driver.php | 2 +- system/database/drivers/postgre/postgre_driver.php | 2 +- system/database/drivers/sqlite/sqlite_driver.php | 2 +- 8 files changed, 8 insertions(+), 8 deletions(-) (limited to 'system') diff --git a/system/database/DB_active_rec.php b/system/database/DB_active_rec.php index 263172a86..903584200 100644 --- a/system/database/DB_active_rec.php +++ b/system/database/DB_active_rec.php @@ -289,7 +289,7 @@ class CI_DB_active_record extends CI_DB_driver { $this->ar_from[] = $this->_protect_identifiers($this->_track_aliases($val)); if ($this->ar_caching === TRUE) { - $this->ar_cache_from[] = $this->_protect_identifiers($val); + $this->ar_cache_from[] = $this->_protect_identifiers($this->_track_aliases($val)); } } diff --git a/system/database/drivers/mssql/mssql_driver.php b/system/database/drivers/mssql/mssql_driver.php index 7b024d414..1ed333de0 100644 --- a/system/database/drivers/mssql/mssql_driver.php +++ b/system/database/drivers/mssql/mssql_driver.php @@ -465,7 +465,7 @@ class CI_DB_mssql_driver extends CI_DB { return "\"{$item}\""; } - $exceptions = array('AS', '/', '-', '%', '+', '*'); + $exceptions = array('AS', '/', '-', '%', '+', '*', 'OR', 'IS'); foreach ($exceptions as $exception) { diff --git a/system/database/drivers/mysql/mysql_driver.php b/system/database/drivers/mysql/mysql_driver.php index edf09a170..2bc66ecf2 100644 --- a/system/database/drivers/mysql/mysql_driver.php +++ b/system/database/drivers/mysql/mysql_driver.php @@ -471,7 +471,7 @@ class CI_DB_mysql_driver extends CI_DB { return "`{$item}`"; } - $exceptions = array('AS', '/', '-', '%', '+', '*'); + $exceptions = array('AS', '/', '-', '%', '+', '*', 'OR', 'IS'); foreach ($exceptions as $exception) { diff --git a/system/database/drivers/mysqli/mysqli_driver.php b/system/database/drivers/mysqli/mysqli_driver.php index 73396c594..6ff37f7e2 100644 --- a/system/database/drivers/mysqli/mysqli_driver.php +++ b/system/database/drivers/mysqli/mysqli_driver.php @@ -464,7 +464,7 @@ class CI_DB_mysqli_driver extends CI_DB { return "`{$item}`"; } - $exceptions = array('AS', '/', '-', '%', '+', '*'); + $exceptions = array('AS', '/', '-', '%', '+', '*', 'OR', 'IS'); foreach ($exceptions as $exception) { diff --git a/system/database/drivers/oci8/oci8_driver.php b/system/database/drivers/oci8/oci8_driver.php index ec26f5be6..364268b98 100644 --- a/system/database/drivers/oci8/oci8_driver.php +++ b/system/database/drivers/oci8/oci8_driver.php @@ -576,7 +576,7 @@ class CI_DB_oci8_driver extends CI_DB { return "\"{$item}\""; } - $exceptions = array('AS', '/', '-', '%', '+', '*'); + $exceptions = array('AS', '/', '-', '%', '+', '*', 'OR', 'IS'); foreach ($exceptions as $exception) { diff --git a/system/database/drivers/odbc/odbc_driver.php b/system/database/drivers/odbc/odbc_driver.php index bdedab32f..82fe36b5d 100644 --- a/system/database/drivers/odbc/odbc_driver.php +++ b/system/database/drivers/odbc/odbc_driver.php @@ -437,7 +437,7 @@ class CI_DB_odbc_driver extends CI_DB { return "{$item}"; } - $exceptions = array('AS', '/', '-', '%', '+', '*'); + $exceptions = array('AS', '/', '-', '%', '+', '*', 'OR', 'IS'); foreach ($exceptions as $exception) { diff --git a/system/database/drivers/postgre/postgre_driver.php b/system/database/drivers/postgre/postgre_driver.php index ce8cb258a..4eff97fcc 100644 --- a/system/database/drivers/postgre/postgre_driver.php +++ b/system/database/drivers/postgre/postgre_driver.php @@ -461,7 +461,7 @@ class CI_DB_postgre_driver extends CI_DB { return "\"{$item}\""; } - $exceptions = array('AS', '/', '-', '%', '+', '*'); + $exceptions = array('AS', '/', '-', '%', '+', '*', 'OR', 'IS'); foreach ($exceptions as $exception) { diff --git a/system/database/drivers/sqlite/sqlite_driver.php b/system/database/drivers/sqlite/sqlite_driver.php index c51edfb07..c859dea6e 100644 --- a/system/database/drivers/sqlite/sqlite_driver.php +++ b/system/database/drivers/sqlite/sqlite_driver.php @@ -455,7 +455,7 @@ class CI_DB_sqlite_driver extends CI_DB { return "{$item}"; } - $exceptions = array('AS', '/', '-', '%', '+', '*'); + $exceptions = array('AS', '/', '-', '%', '+', '*', 'OR', 'IS'); foreach ($exceptions as $exception) { -- cgit v1.2.3-24-g4f1b From 92e048746c3849dd809e2c47f235b69e02af7e9b Mon Sep 17 00:00:00 2001 From: Derek Allard Date: Mon, 25 Feb 2008 14:25:31 +0000 Subject: Added 'application/vnd.ms-powerpoint' to list of mime types. --- system/application/config/mimes.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system') diff --git a/system/application/config/mimes.php b/system/application/config/mimes.php index 225b0a543..a8addb932 100644 --- a/system/application/config/mimes.php +++ b/system/application/config/mimes.php @@ -30,7 +30,7 @@ $mimes = array( 'hqx' => 'application/mac-binhex40', 'smil' => 'application/smil', 'mif' => 'application/vnd.mif', 'xls' => array('application/excel', 'application/vnd.ms-excel'), - 'ppt' => 'application/powerpoint', + 'ppt' => array('application/powerpoint', 'application/vnd.ms-powerpoint'), 'wbxml' => 'application/wbxml', 'wmlc' => 'application/wmlc', 'dcr' => 'application/x-director', -- cgit v1.2.3-24-g4f1b From 964366de070c20636d9037ff06d98081b9d1b0cc Mon Sep 17 00:00:00 2001 From: Derek Jones Date: Tue, 26 Feb 2008 15:40:15 +0000 Subject: changed conditional for empty cells to not match on variables that would be loosely cast as an empty string --- system/libraries/Table.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system') diff --git a/system/libraries/Table.php b/system/libraries/Table.php index d1c525486..439fe2ef9 100644 --- a/system/libraries/Table.php +++ b/system/libraries/Table.php @@ -261,7 +261,7 @@ class CI_Table { { $out .= $this->template['cell_'.$name.'start']; - if ($cell == "") + if ($cell === "") { $out .= $this->empty_cells; } -- cgit v1.2.3-24-g4f1b From 2c6dda41c8207ffa704934a1fbde65769ce86992 Mon Sep 17 00:00:00 2001 From: Derek Jones Date: Tue, 26 Feb 2008 23:18:27 +0000 Subject: fixed recursion in get_filenames() (bug #3523) --- system/helpers/file_helper.php | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) (limited to 'system') diff --git a/system/helpers/file_helper.php b/system/helpers/file_helper.php index 096d225d7..1b37af2fd 100644 --- a/system/helpers/file_helper.php +++ b/system/helpers/file_helper.php @@ -164,17 +164,22 @@ if (! function_exists('delete_files')) */ if (! function_exists('get_filenames')) { - function get_filenames($source_dir, $include_path = FALSE) + function get_filenames($source_dir, $include_path = FALSE, $recursion = FALSE) { - $_filedata = array(); - + static $_filedata = array(); + + if ($recursion === FALSE) + { + $_filedata = array(); + } + if ($fp = @opendir($source_dir)) { while (FALSE !== ($file = readdir($fp))) { if (@is_dir($source_dir.$file) && substr($file, 0, 1) != '.') { - get_filenames($source_dir.$file."/", $include_path); + get_filenames($source_dir.$file."/", $include_path, TRUE); } elseif (substr($file, 0, 1) != ".") { -- cgit v1.2.3-24-g4f1b From 8a1607772c5e9221884d9f0a39a514536f1fe21d Mon Sep 17 00:00:00 2001 From: Derek Jones Date: Wed, 27 Feb 2008 05:19:50 +0000 Subject: added improved check for controller method access so that CI does not attempt to load private or protected controller methods added controller/method details to framework initiated 404 pages for logging --- system/codeigniter/CodeIgniter.php | 8 +++++--- system/libraries/Router.php | 4 ++-- 2 files changed, 7 insertions(+), 5 deletions(-) (limited to 'system') diff --git a/system/codeigniter/CodeIgniter.php b/system/codeigniter/CodeIgniter.php index 8f9dbdf64..d1ef965cc 100644 --- a/system/codeigniter/CodeIgniter.php +++ b/system/codeigniter/CodeIgniter.php @@ -169,7 +169,7 @@ if ( ! class_exists($class) OR in_array($method, get_class_methods('Controller'), TRUE) ) { - show_404(); + show_404("{$class}/{$method}"); } /* @@ -214,9 +214,11 @@ else } else { - if ( ! method_exists($CI, $method)) + // 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($method, get_class_methods($CI))) { - show_404(); + show_404("{$class}/{$method}"); } // Call the requested method. diff --git a/system/libraries/Router.php b/system/libraries/Router.php index f6464a31d..d9dd6dd3f 100644 --- a/system/libraries/Router.php +++ b/system/libraries/Router.php @@ -204,7 +204,7 @@ class CI_Router { // Does the requested controller exist in the sub-folder? if ( ! file_exists(APPPATH.'controllers/'.$this->fetch_directory().$segments[0].EXT)) { - show_404(); + show_404($this->fetch_directory().$segments[0]); } } else @@ -225,7 +225,7 @@ class CI_Router { } // Can't find the requested controller... - show_404(); + show_404($segments[0]); } // -------------------------------------------------------------------- -- cgit v1.2.3-24-g4f1b From 3951e8e3c56e9ddef2048350bde8b39cbef1568a Mon Sep 17 00:00:00 2001 From: Derek Jones Date: Thu, 28 Feb 2008 18:20:18 +0000 Subject: modified the new check for a callable controller method to be case-insensitive for backwards compatibility and consistent behavior between PHP 4 and 5. --- system/codeigniter/CodeIgniter.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system') diff --git a/system/codeigniter/CodeIgniter.php b/system/codeigniter/CodeIgniter.php index d1ef965cc..866be35cc 100644 --- a/system/codeigniter/CodeIgniter.php +++ b/system/codeigniter/CodeIgniter.php @@ -216,7 +216,7 @@ 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($method, get_class_methods($CI))) + if (! in_array(strtolower($method), array_map('strtolower', get_class_methods($CI)))) { show_404("{$class}/{$method}"); } -- cgit v1.2.3-24-g4f1b From 43e8cbf51bfdca8bc29acc23208f1018d7af913a Mon Sep 17 00:00:00 2001 From: Derek Allard Date: Sat, 1 Mar 2008 23:14:43 +0000 Subject: added or_having, deprecated orhaving --- system/database/DB_active_rec.php | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) (limited to 'system') diff --git a/system/database/DB_active_rec.php b/system/database/DB_active_rec.php index 903584200..b97fb11cd 100644 --- a/system/database/DB_active_rec.php +++ b/system/database/DB_active_rec.php @@ -779,7 +779,19 @@ class CI_DB_active_record extends CI_DB_driver { { return $this->_having($key, $value, 'AND '); } - + + // -------------------------------------------------------------------- + + /** + * orhaving() is an alias of or_having() + * this function is here for backwards compatibility, as + * orhaving() has been deprecated + */ + + function orhaving($key, $value = '') + { + return $this->or_havinggroup_by($key, $value = ''); + } // -------------------------------------------------------------------- /** @@ -792,7 +804,7 @@ class CI_DB_active_record extends CI_DB_driver { * @param string * @return object */ - function orhaving($key, $value = '') + function or_having($key, $value = '') { return $this->_having($key, $value, 'OR '); } -- cgit v1.2.3-24-g4f1b From 49ef042b211b41e4a24815bbf6fd65fb41f86021 Mon Sep 17 00:00:00 2001 From: Derek Allard Date: Tue, 4 Mar 2008 21:31:16 +0000 Subject: fix silly copy-paste error in active record --- system/database/DB_active_rec.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system') diff --git a/system/database/DB_active_rec.php b/system/database/DB_active_rec.php index b97fb11cd..add0b8c94 100644 --- a/system/database/DB_active_rec.php +++ b/system/database/DB_active_rec.php @@ -790,7 +790,7 @@ class CI_DB_active_record extends CI_DB_driver { function orhaving($key, $value = '') { - return $this->or_havinggroup_by($key, $value = ''); + return $this->or_having($key, $value = ''); } // -------------------------------------------------------------------- -- cgit v1.2.3-24-g4f1b From 4acd41aaa0e70577ab179a3a81d485ac2ab27523 Mon Sep 17 00:00:00 2001 From: Derek Allard Date: Wed, 5 Mar 2008 16:22:31 +0000 Subject: restore a comment --- system/libraries/Image_lib.php | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) (limited to 'system') diff --git a/system/libraries/Image_lib.php b/system/libraries/Image_lib.php index dbb6f82e0..395742092 100644 --- a/system/libraries/Image_lib.php +++ b/system/libraries/Image_lib.php @@ -499,8 +499,14 @@ class CI_Image_lib { return FALSE; } - // Create The Image - if ($this->image_library == 'gd2' AND function_exists('imagecreatetruecolor')) + // Create The Image + // + // old conditional which users report cause problems with shared GD libs who report themselves as "2.0 or greater" + // it appears that this is no longer the issue that it was in 2004, so we've removed it, retaining it in the comment + // below should that ever prove inaccurate. + // + // if ($this->image_library == 'gd2' AND function_exists('imagecreatetruecolor') AND $v2_override == FALSE) + if ($this->image_library == 'gd2' AND function_exists('imagecreatetruecolor')) { $create = 'imagecreatetruecolor'; $copy = 'imagecopyresampled'; -- cgit v1.2.3-24-g4f1b From 37fb01baec92a3e7898380923712e0c48b21107a Mon Sep 17 00:00:00 2001 From: Derek Allard Date: Thu, 6 Mar 2008 13:01:47 +0000 Subject: Modified img() in the HTML Helper to remove an unneeded space. Modified anchor() in the URL helper to convert entities in the title attribute. --- system/helpers/html_helper.php | 2 +- system/helpers/url_helper.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'system') diff --git a/system/helpers/html_helper.php b/system/helpers/html_helper.php index 0c884502f..4684d8ea8 100644 --- a/system/helpers/html_helper.php +++ b/system/helpers/html_helper.php @@ -199,7 +199,7 @@ if (! function_exists('img')) $src = array('src' => $src); } - $img = '$v) { diff --git a/system/helpers/url_helper.php b/system/helpers/url_helper.php index ad71caa45..bd94b390c 100644 --- a/system/helpers/url_helper.php +++ b/system/helpers/url_helper.php @@ -119,7 +119,7 @@ if (! function_exists('anchor')) if ($attributes == '') { - $attributes = ' title="'.$title.'"'; + $attributes = ' title="'.htmlentities($title).'"'; } else { -- cgit v1.2.3-24-g4f1b From 8b2f19b7b2671526c8e5eca74251b6339932e5bf Mon Sep 17 00:00:00 2001 From: Derek Allard Date: Thu, 6 Mar 2008 15:51:55 +0000 Subject: change to the way AR handles aliased tables --- system/database/DB_active_rec.php | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) (limited to 'system') diff --git a/system/database/DB_active_rec.php b/system/database/DB_active_rec.php index add0b8c94..bde43abf0 100644 --- a/system/database/DB_active_rec.php +++ b/system/database/DB_active_rec.php @@ -1434,17 +1434,15 @@ class CI_DB_active_record extends CI_DB_driver { */ function _filter_table_aliases($statements) { + foreach ($statements as $k => $v) { foreach ($this->ar_aliased_tables as $table) { - $statement = preg_replace('/(\w+\.\w+)/', $this->_protect_identifiers('$0'), $v); // makes `table.field` - $statement = str_replace(array($this->dbprefix.$table, '.'), array($table, $this->_protect_identifiers('.')), $statement); + $statements[$k] = preg_replace('/(\w+\.\w+)/', $this->_protect_identifiers('$0'), $statements[$k]); // makes `table.field` + $statements[$k] = str_replace($this->dbprefix.$table.'.', $table.'.', $statements[$k]); } - - $statements[$k] = $statement; } - return $statements; } -- cgit v1.2.3-24-g4f1b From 6ef8b69b80093bf706d29df28d108f77acbf9dc0 Mon Sep 17 00:00:00 2001 From: Derek Jones Date: Mon, 17 Mar 2008 19:09:12 +0000 Subject: added filename prepping in the Upload library to prevent files with multiple extensions to potentially be parsed as a script by Apache --- system/libraries/Upload.php | 42 +++++++++++++++++++++++++++++++++++++++++- 1 file changed, 41 insertions(+), 1 deletion(-) (limited to 'system') diff --git a/system/libraries/Upload.php b/system/libraries/Upload.php index 2a3f53d4b..760d93999 100644 --- a/system/libraries/Upload.php +++ b/system/libraries/Upload.php @@ -185,7 +185,7 @@ class CI_Upload { // Set the uploaded data as class variables $this->file_temp = $_FILES[$field]['tmp_name']; - $this->file_name = $_FILES[$field]['name']; + $this->file_name = $this->_prep_filename($_FILES[$field]['name']); $this->file_size = $_FILES[$field]['size']; $this->file_type = preg_replace("/^(.+?);.*$/", "\\1", $_FILES[$field]['type']); $this->file_type = strtolower($this->file_type); @@ -833,6 +833,46 @@ class CI_Upload { return ( ! isset($this->mimes[$mime])) ? FALSE : $this->mimes[$mime]; } + /** + * Prep Filename + * + * Prevents possible script execution from Apache's handling of files multiple extensions + * http://httpd.apache.org/docs/1.3/mod/mod_mime.html#multipleext + * + * @access private + * @param string + * @return string + */ + function _prep_filename($filename) + { + if (strpos($filename, '.') === FALSE) + { + return $filename; + } + + $parts = explode('.', $filename); + $ext = array_pop($parts); + $filename = array_shift($parts); + + foreach ($parts as $part) + { + if ($this->mimes_types(strtolower($part)) === FALSE) + { + $filename .= '.'.$part.'_'; + } + else + { + $filename .= '.'.$part; + } + } + + $filename .= '.'.$ext; + + return $filename; + } + + // -------------------------------------------------------------------- + } // END Upload Class ?> \ No newline at end of file -- cgit v1.2.3-24-g4f1b From 9c4280be80f1f0ad4011ca1ae4f05c89e7963bb9 Mon Sep 17 00:00:00 2001 From: Derek Allard Date: Tue, 18 Mar 2008 00:01:52 +0000 Subject: added hashing to prevent client side data tampering to sessions --- system/libraries/Session.php | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) (limited to 'system') diff --git a/system/libraries/Session.php b/system/libraries/Session.php index 2cdd50c23..afa43348e 100644 --- a/system/libraries/Session.php +++ b/system/libraries/Session.php @@ -196,7 +196,22 @@ class CI_Session { { $session = $this->CI->encrypt->decode($session); } + else + { + // encryption was not used, so we need to check the md5 hash + $hash = substr($session, strlen($session)-32); // get last 32 chars + $session = substr($session, 0, strlen($session)-32); + // Does the md5 hash match? This is to prevent manipulation of session data + // in userspace + if ($hash !== md5($session.$this->CI->config->item('encryption_key'))) + { + log_message('error', 'The session cookie data did not match what was expected. This could be a possible hacking attempt.'); + $this->sess_destroy(); + return FALSE; + } + } + $session = @unserialize($this->strip_slashes($session)); if ( ! is_array($session) OR ! isset($session['last_activity'])) @@ -284,6 +299,11 @@ class CI_Session { { $cookie_data = $this->CI->encrypt->encode($cookie_data); } + else + { + // if encryption is not used, we provide an md5 hash to prevent userside tampering + $cookie_data = $cookie_data . md5($cookie_data.$this->CI->config->item('encryption_key')); + } setcookie( $this->sess_cookie, -- cgit v1.2.3-24-g4f1b From d888c3551189526e1b63cf09206dd40aad5bff5b Mon Sep 17 00:00:00 2001 From: Derek Allard Date: Tue, 18 Mar 2008 04:04:33 +0000 Subject: changed include into include_once --- system/libraries/Loader.php | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) (limited to 'system') diff --git a/system/libraries/Loader.php b/system/libraries/Loader.php index 576cb11f3..50bd4130e 100644 --- a/system/libraries/Loader.php +++ b/system/libraries/Loader.php @@ -390,7 +390,7 @@ class CI_Loader { { if (file_exists(BASEPATH.'helpers/'.$helper.EXT)) { - include(BASEPATH.'helpers/'.$helper.EXT); + include_once(BASEPATH.'helpers/'.$helper.EXT); } else { @@ -451,13 +451,13 @@ class CI_Loader { if (file_exists(APPPATH.'plugins/'.$plugin.EXT)) { - include(APPPATH.'plugins/'.$plugin.EXT); + include_once(APPPATH.'plugins/'.$plugin.EXT); } else { if (file_exists(BASEPATH.'plugins/'.$plugin.EXT)) { - include(BASEPATH.'plugins/'.$plugin.EXT); + include_once(BASEPATH.'plugins/'.$plugin.EXT); } else { @@ -524,7 +524,7 @@ class CI_Loader { show_error('Unable to load the requested script: scripts/'.$script.EXT); } - include(APPPATH.'scripts/'.$script.EXT); + include_once(APPPATH.'scripts/'.$script.EXT); } log_message('debug', 'Scripts loaded: '.implode(', ', $scripts)); @@ -705,7 +705,7 @@ class CI_Loader { } else { - include($_ci_path); + include_once($_ci_path); } log_message('debug', 'File loaded: '.$_ci_path); @@ -782,8 +782,8 @@ class CI_Loader { return; } - include($baseclass); - include($subclass); + include_once($baseclass); + include_once($subclass); $this->_ci_classes[] = $subclass; return $this->_ci_init_class($class, config_item('subclass_prefix'), $params); @@ -810,7 +810,7 @@ class CI_Loader { return; } - include($filepath); + include_once($filepath); $this->_ci_classes[] = $filepath; return $this->_ci_init_class($class, '', $params); } @@ -844,7 +844,7 @@ class CI_Loader { { if (file_exists(APPPATH.'config/'.$class.EXT)) { - include(APPPATH.'config/'.$class.EXT); + include_once(APPPATH.'config/'.$class.EXT); } } @@ -886,7 +886,7 @@ class CI_Loader { */ function _ci_autoloader() { - include(APPPATH.'config/autoload'.EXT); + include_once(APPPATH.'config/autoload'.EXT); if ( ! isset($autoload)) { -- cgit v1.2.3-24-g4f1b From 707d0e0f1e0ea922fbe38d8b43f1fb4e2ea001e5 Mon Sep 17 00:00:00 2001 From: Derek Allard Date: Tue, 18 Mar 2008 11:50:00 +0000 Subject: added form_button to form helper --- system/helpers/form_helper.php | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) (limited to 'system') diff --git a/system/helpers/form_helper.php b/system/helpers/form_helper.php index 7c3b16ff1..db41cb5cd 100644 --- a/system/helpers/form_helper.php +++ b/system/helpers/form_helper.php @@ -386,6 +386,33 @@ if (! function_exists('form_reset')) // ------------------------------------------------------------------------ +/** + * 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' => 'submit'); + + if ( is_array($data) AND isset($data['content'])) + { + $content = $data['content']; + unset($data['content']); // content is not an attribute + } + + return "\n"; + } +} + +// ------------------------------------------------------------------------ + /** * Form Label Tag * -- cgit v1.2.3-24-g4f1b From 5636709a4ae83c1a93ab82f617cd523d3cecc502 Mon Sep 17 00:00:00 2001 From: Derek Allard Date: Wed, 19 Mar 2008 11:53:16 +0000 Subject: Added 'audio/mpg' to list of mime types. --- system/application/config/mimes.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'system') diff --git a/system/application/config/mimes.php b/system/application/config/mimes.php index a8addb932..7f5f20803 100644 --- a/system/application/config/mimes.php +++ b/system/application/config/mimes.php @@ -51,12 +51,12 @@ $mimes = array( 'hqx' => 'application/mac-binhex40', 'tgz' => 'application/x-tar', 'xhtml' => 'application/xhtml+xml', 'xht' => 'application/xhtml+xml', - 'zip' => array('application/x-zip', 'application/zip', 'application/x-zip-compressed'), + 'zip' => array('application/x-zip', 'application/zip', 'application/x-zip-compressed'), 'mid' => 'audio/midi', 'midi' => 'audio/midi', 'mpga' => 'audio/mpeg', 'mp2' => 'audio/mpeg', - 'mp3' => 'audio/mpeg', + 'mp3' => array('audio/mpeg', 'audio/mpg'), 'aif' => 'audio/x-aiff', 'aiff' => 'audio/x-aiff', 'aifc' => 'audio/x-aiff', -- cgit v1.2.3-24-g4f1b From be97bdc41601ead493287d67ac80cd5241ddc746 Mon Sep 17 00:00:00 2001 From: Derek Allard Date: Sun, 23 Mar 2008 16:24:37 +0000 Subject: Modified captcha generation to first look for the function imagecreatetruecolor, and fallback to imagecreate if it isn't available (#4226). --- system/plugins/captcha_pi.php | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) (limited to 'system') diff --git a/system/plugins/captcha_pi.php b/system/plugins/captcha_pi.php index 693fd9117..7aa31efb1 100644 --- a/system/plugins/captcha_pi.php +++ b/system/plugins/captcha_pi.php @@ -244,7 +244,15 @@ function create_captcha($data = '', $img_path = '', $img_url = '', $font_path = // Create image // ----------------------------------- - $im = ImageCreate($img_width, $img_height); + // 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 -- cgit v1.2.3-24-g4f1b From 11213e4c0f1de094746e834ca6c8f547459703dd Mon Sep 17 00:00:00 2001 From: Derek Allard Date: Sun, 23 Mar 2008 23:20:42 +0000 Subject: missing quotes --- system/plugins/captcha_pi.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system') diff --git a/system/plugins/captcha_pi.php b/system/plugins/captcha_pi.php index 7aa31efb1..2c82f70a1 100644 --- a/system/plugins/captcha_pi.php +++ b/system/plugins/captcha_pi.php @@ -245,7 +245,7 @@ function create_captcha($data = '', $img_path = '', $img_url = '', $font_path = // ----------------------------------- // PHP.net recommends imagecreatetruecolor(), but it isn't always available - if (function_exists(imagecreatetruecolor)) + if (function_exists('imagecreatetruecolor')) { $im = imagecreatetruecolor($img_width, $img_height); } -- cgit v1.2.3-24-g4f1b From 560efb353a1395f51a170f32b974c2afb897a712 Mon Sep 17 00:00:00 2001 From: Derek Jones Date: Thu, 27 Mar 2008 16:07:00 +0000 Subject: Fixed bug #4350 in get_filenames() when the $source_dir does not include a trailing slash --- system/helpers/file_helper.php | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'system') diff --git a/system/helpers/file_helper.php b/system/helpers/file_helper.php index 1b37af2fd..7eb93dab2 100644 --- a/system/helpers/file_helper.php +++ b/system/helpers/file_helper.php @@ -160,19 +160,23 @@ if (! function_exists('delete_files')) * @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) + function get_filenames($source_dir, $include_path = FALSE, $_recursion = FALSE) { static $_filedata = array(); - if ($recursion === FALSE) + // reset the array and make sure $source_dir has a trailing slash on the initial call + if ($_recursion === FALSE) { $_filedata = array(); + $source_dir = realpath($source_dir).'/'; } + if ($fp = @opendir($source_dir)) { while (FALSE !== ($file = readdir($fp))) -- cgit v1.2.3-24-g4f1b From f00992d66cab3efa8cbec8cc8623c4ea830cc5e3 Mon Sep 17 00:00:00 2001 From: Derek Jones Date: Fri, 28 Mar 2008 14:13:14 +0000 Subject: moved the $_recursion conditional in get_filenames() to fix a bug where a bad submitted path would result in the system using / as the source directory. --- system/helpers/file_helper.php | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) (limited to 'system') diff --git a/system/helpers/file_helper.php b/system/helpers/file_helper.php index 7eb93dab2..e1a4ff31a 100644 --- a/system/helpers/file_helper.php +++ b/system/helpers/file_helper.php @@ -168,17 +168,16 @@ if (! function_exists('get_filenames')) function get_filenames($source_dir, $include_path = FALSE, $_recursion = FALSE) { static $_filedata = array(); - - // reset the array and make sure $source_dir has a trailing slash on the initial call - if ($_recursion === FALSE) - { - $_filedata = array(); - $source_dir = realpath($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 = realpath($source_dir).'/'; + } + while (FALSE !== ($file = readdir($fp))) { if (@is_dir($source_dir.$file) && substr($file, 0, 1) != '.') -- cgit v1.2.3-24-g4f1b From 2ec3a5e12f2095ae2cc341760a9c44acf353743e Mon Sep 17 00:00:00 2001 From: Derek Allard Date: Sun, 30 Mar 2008 17:51:11 +0000 Subject: Fixed a bug in link_tag() of the URL helper where a key was passed instead of a value. --- system/helpers/html_helper.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system') diff --git a/system/helpers/html_helper.php b/system/helpers/html_helper.php index 4684d8ea8..3e15b4442 100644 --- a/system/helpers/html_helper.php +++ b/system/helpers/html_helper.php @@ -257,7 +257,7 @@ if (! function_exists('link_tag')) { foreach ($href as $k=>$v) { - if ($k == 'href' AND strpos($k, '://') === FALSE) + if ($k == 'href' AND strpos($v, '://') === FALSE) { if ($index_page === TRUE) { -- cgit v1.2.3-24-g4f1b From ac7c81e3cd8891d7a8103c121911f7192b5027af Mon Sep 17 00:00:00 2001 From: Derek Jones Date: Tue, 1 Apr 2008 13:59:49 +0000 Subject: Modified get_filenames() to use DIRECTORY_SEPARATOR constant instead of '/' for better cross-platform compatibility --- system/helpers/file_helper.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'system') diff --git a/system/helpers/file_helper.php b/system/helpers/file_helper.php index e1a4ff31a..04c5747bf 100644 --- a/system/helpers/file_helper.php +++ b/system/helpers/file_helper.php @@ -175,14 +175,14 @@ if (! function_exists('get_filenames')) if ($_recursion === FALSE) { $_filedata = array(); - $source_dir = realpath($source_dir).'/'; + $source_dir = rtrim(realpath($source_dir), DIRECTORY_SEPARATOR).DIRECTORY_SEPARATOR; } while (FALSE !== ($file = readdir($fp))) { if (@is_dir($source_dir.$file) && substr($file, 0, 1) != '.') { - get_filenames($source_dir.$file."/", $include_path, TRUE); + get_filenames($source_dir.$file.DIRECTORY_SEPARATOR, $include_path, TRUE); } elseif (substr($file, 0, 1) != ".") { -- cgit v1.2.3-24-g4f1b From e97b13635f8985ac88add9659ae6a78e67006b9b Mon Sep 17 00:00:00 2001 From: Derek Jones Date: Thu, 3 Apr 2008 21:23:13 +0000 Subject: replaced isset() with array_key_exists() in row() to allow retrieval of individual fields with MySQL NULL values --- system/database/DB_result.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'system') diff --git a/system/database/DB_result.php b/system/database/DB_result.php index 7d5097911..6461431e2 100644 --- a/system/database/DB_result.php +++ b/system/database/DB_result.php @@ -133,7 +133,8 @@ class CI_DB_result { $this->row_data = $this->row_array(0); } - if (isset($this->row_data[$n])) + // 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]; } -- cgit v1.2.3-24-g4f1b From 43cbdaaf9dc073b7e6bcf6416650c3249ea37d5d Mon Sep 17 00:00:00 2001 From: Derek Jones Date: Thu, 3 Apr 2008 21:54:15 +0000 Subject: syntax error: extraneous closing parenthesis --- system/database/DB_result.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system') diff --git a/system/database/DB_result.php b/system/database/DB_result.php index 6461431e2..c2eeefb94 100644 --- a/system/database/DB_result.php +++ b/system/database/DB_result.php @@ -134,7 +134,7 @@ class CI_DB_result { } // array_key_exists() instead of isset() to allow for MySQL NULL values - if (array_key_exists($n, $this->row_data))) + if (array_key_exists($n, $this->row_data)) { return $this->row_data[$n]; } -- cgit v1.2.3-24-g4f1b From 72c82c1de6efb25a529f3206800de7ddd70ea83e Mon Sep 17 00:00:00 2001 From: Derek Allard Date: Fri, 4 Apr 2008 11:34:58 +0000 Subject: include() vs include_once() allows for multiple views with the same name --- system/libraries/Loader.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system') diff --git a/system/libraries/Loader.php b/system/libraries/Loader.php index 50bd4130e..31e7d660f 100644 --- a/system/libraries/Loader.php +++ b/system/libraries/Loader.php @@ -705,7 +705,7 @@ class CI_Loader { } else { - include_once($_ci_path); + include($_ci_path); // include() vs include_once() allows for multiple views with the same name } log_message('debug', 'File loaded: '.$_ci_path); -- cgit v1.2.3-24-g4f1b From 3ad8efe07deb3ec27a205815dc9097c20c728e9b Mon Sep 17 00:00:00 2001 From: Derek Jones Date: Fri, 4 Apr 2008 18:56:04 +0000 Subject: added constants.php file and implemented constants for file system modes --- system/application/config/constants.php | 21 +++++++++++++++++++++ system/codeigniter/CodeIgniter.php | 9 ++++++++- system/codeigniter/Common.php | 2 +- system/database/DB_cache.php | 6 +++--- system/database/drivers/sqlite/sqlite_driver.php | 4 ++-- system/libraries/Image_lib.php | 12 ++++++------ system/libraries/Log.php | 2 +- system/libraries/Output.php | 2 +- 8 files changed, 43 insertions(+), 15 deletions(-) create mode 100644 system/application/config/constants.php (limited to 'system') diff --git a/system/application/config/constants.php b/system/application/config/constants.php new file mode 100644 index 000000000..ace3f8b9d --- /dev/null +++ b/system/application/config/constants.php @@ -0,0 +1,21 @@ + \ No newline at end of file diff --git a/system/codeigniter/CodeIgniter.php b/system/codeigniter/CodeIgniter.php index 866be35cc..04936b956 100644 --- a/system/codeigniter/CodeIgniter.php +++ b/system/codeigniter/CodeIgniter.php @@ -43,7 +43,14 @@ require(BASEPATH.'codeigniter/Common'.EXT); * ------------------------------------------------------ */ require(BASEPATH.'codeigniter/Compat'.EXT); - + +/* + * ------------------------------------------------------ + * Load the compatibility override functions + * ------------------------------------------------------ + */ +require(APPPATH.'config/constants'.EXT); + /* * ------------------------------------------------------ * Define a custom error handler so we can log PHP errors diff --git a/system/codeigniter/Common.php b/system/codeigniter/Common.php index d9ddf80c7..4554a712b 100644 --- a/system/codeigniter/Common.php +++ b/system/codeigniter/Common.php @@ -52,7 +52,7 @@ function is_really_writable($file) } fclose($fp); - @chmod($file, 0777); + @chmod($file, DIR_WRITE_MODE); @unlink($file); return TRUE; } diff --git a/system/database/DB_cache.php b/system/database/DB_cache.php index ad54fc315..08394da29 100644 --- a/system/database/DB_cache.php +++ b/system/database/DB_cache.php @@ -129,12 +129,12 @@ class CI_DB_Cache { if ( ! @is_dir($dir_path)) { - if ( ! @mkdir($dir_path, 0777)) + if ( ! @mkdir($dir_path, DIR_WRITE_MODE)) { return FALSE; } - @chmod($dir_path, 0777); + @chmod($dir_path, DIR_WRITE_MODE); } if (write_file($dir_path.$filename, serialize($object)) === FALSE) @@ -142,7 +142,7 @@ class CI_DB_Cache { return FALSE; } - @chmod($dir_path.$filename, 0777); + @chmod($dir_path.$filename, DIR_WRITE_MODE); return TRUE; } diff --git a/system/database/drivers/sqlite/sqlite_driver.php b/system/database/drivers/sqlite/sqlite_driver.php index c859dea6e..16a8308c1 100644 --- a/system/database/drivers/sqlite/sqlite_driver.php +++ b/system/database/drivers/sqlite/sqlite_driver.php @@ -48,7 +48,7 @@ class CI_DB_sqlite_driver extends CI_DB { */ function db_connect() { - if ( ! $conn_id = @sqlite_open($this->database, 0666, $error)) + if ( ! $conn_id = @sqlite_open($this->database, FILE_WRITE_MODE, $error)) { log_message('error', $error); @@ -73,7 +73,7 @@ class CI_DB_sqlite_driver extends CI_DB { */ function db_pconnect() { - if ( ! $conn_id = @sqlite_popen($this->database, 0666, $error)) + if ( ! $conn_id = @sqlite_popen($this->database, FILE_WRITE_MODE, $error)) { log_message('error', $error); diff --git a/system/libraries/Image_lib.php b/system/libraries/Image_lib.php index 395742092..85435f6c9 100644 --- a/system/libraries/Image_lib.php +++ b/system/libraries/Image_lib.php @@ -484,7 +484,7 @@ class CI_Image_lib { return FALSE; } - @chmod($this->full_dst_path, 0777); + @chmod($this->full_dst_path, DIR_WRITE_MODE); return TRUE; } @@ -539,7 +539,7 @@ class CI_Image_lib { imagedestroy($src_img); // Set the file to 777 - @chmod($this->full_dst_path, 0777); + @chmod($this->full_dst_path, DIR_WRITE_MODE); return TRUE; } @@ -609,7 +609,7 @@ class CI_Image_lib { } // Set the file to 777 - @chmod($this->full_dst_path, 0777); + @chmod($this->full_dst_path, DIR_WRITE_MODE); return TRUE; } @@ -695,7 +695,7 @@ class CI_Image_lib { // we have to rename the temp file. copy ($this->dest_folder.'netpbm.tmp', $this->full_dst_path); unlink ($this->dest_folder.'netpbm.tmp'); - @chmod($dst_image, 0777); + @chmod($dst_image, DIR_WRITE_MODE); return TRUE; } @@ -754,7 +754,7 @@ class CI_Image_lib { // Set the file to 777 - @chmod($this->full_dst_path, 0777); + @chmod($this->full_dst_path, DIR_WRITE_MODE); return true; } @@ -838,7 +838,7 @@ class CI_Image_lib { imagedestroy($src_img); // Set the file to 777 - @chmod($this->full_dst_path, 0777); + @chmod($this->full_dst_path, DIR_WRITE_MODE); return TRUE; } diff --git a/system/libraries/Log.php b/system/libraries/Log.php index f9ca85a30..1aa8bd0f4 100644 --- a/system/libraries/Log.php +++ b/system/libraries/Log.php @@ -109,7 +109,7 @@ class CI_Log { flock($fp, LOCK_UN); fclose($fp); - @chmod($filepath, 0666); + @chmod($filepath, FILE_WRITE_MODE); return TRUE; } diff --git a/system/libraries/Output.php b/system/libraries/Output.php index a4d8d34b8..07990eb16 100644 --- a/system/libraries/Output.php +++ b/system/libraries/Output.php @@ -308,7 +308,7 @@ class CI_Output { fwrite($fp, $expire.'TS--->'.$output); flock($fp, LOCK_UN); fclose($fp); - @chmod($cache_path, 0777); + @chmod($cache_path, DIR_WRITE_MODE); log_message('debug', "Cache file written: ".$cache_path); } -- cgit v1.2.3-24-g4f1b From e808aac2627c35d50082f814d9778c4bf976011c Mon Sep 17 00:00:00 2001 From: Derek Allard Date: Sun, 6 Apr 2008 18:22:00 +0000 Subject: Added the ability to prevent escaping in having() clauses. --- system/database/DB_active_rec.php | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) (limited to 'system') diff --git a/system/database/DB_active_rec.php b/system/database/DB_active_rec.php index bde43abf0..23a5a7adf 100644 --- a/system/database/DB_active_rec.php +++ b/system/database/DB_active_rec.php @@ -775,9 +775,9 @@ class CI_DB_active_record extends CI_DB_driver { * @param string * @return object */ - function having($key, $value = '') + function having($key, $value = '', $escape = TRUE) { - return $this->_having($key, $value, 'AND '); + return $this->_having($key, $value, 'AND ', $escape); } // -------------------------------------------------------------------- @@ -788,9 +788,9 @@ class CI_DB_active_record extends CI_DB_driver { * orhaving() has been deprecated */ - function orhaving($key, $value = '') + function orhaving($key, $value = '', $escape = TRUE) { - return $this->or_having($key, $value = ''); + return $this->or_having($key, $value = '', $escape); } // -------------------------------------------------------------------- @@ -804,9 +804,9 @@ class CI_DB_active_record extends CI_DB_driver { * @param string * @return object */ - function or_having($key, $value = '') + function or_having($key, $value = '', $escape = TRUE) { - return $this->_having($key, $value, 'OR '); + return $this->_having($key, $value, 'OR ', $escape); } // -------------------------------------------------------------------- @@ -822,7 +822,7 @@ class CI_DB_active_record extends CI_DB_driver { * @param string * @return object */ - function _having($key, $value = '', $type = 'AND ') + function _having($key, $value = '', $type = 'AND ', $escape = TRUE) { if ( ! is_array($key)) { @@ -832,7 +832,12 @@ class CI_DB_active_record extends CI_DB_driver { foreach ($key as $k => $v) { $prefix = (count($this->ar_having) == 0) ? '' : $type; - $k = $this->_protect_identifiers($k); + + if ($escape === TRUE) + { + $k = $this->_protect_identifiers($k); + } + if ($v != '') { -- cgit v1.2.3-24-g4f1b From 96863ce12d88b2126b80bf1b00a73eed1ad6be86 Mon Sep 17 00:00:00 2001 From: Derek Allard Date: Sun, 6 Apr 2008 19:20:17 +0000 Subject: testing an escape issue --- system/database/DB_active_rec.php | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'system') diff --git a/system/database/DB_active_rec.php b/system/database/DB_active_rec.php index 23a5a7adf..b2638f25c 100644 --- a/system/database/DB_active_rec.php +++ b/system/database/DB_active_rec.php @@ -447,7 +447,10 @@ class CI_DB_active_record extends CI_DB_driver { $k .= ' ='; } - $v = ' '.$this->escape($v); + if ($v != '') + { + $v = ' '.$this->escape($v); + } } else { -- cgit v1.2.3-24-g4f1b From 16629b1cef61db05646839d6789d98ddc5aaf16b Mon Sep 17 00:00:00 2001 From: Derek Allard Date: Sun, 6 Apr 2008 19:58:20 +0000 Subject: Fixed a bug that wasn't allowing escaping to be turned off if the value of a query was NULL. --- system/database/DB_active_rec.php | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) (limited to 'system') diff --git a/system/database/DB_active_rec.php b/system/database/DB_active_rec.php index b2638f25c..d58580637 100644 --- a/system/database/DB_active_rec.php +++ b/system/database/DB_active_rec.php @@ -447,14 +447,19 @@ class CI_DB_active_record extends CI_DB_driver { $k .= ' ='; } - if ($v != '') + if ($v !== '' AND $v !== NULL) { $v = ' '.$this->escape($v); } } else { - $k = $this->_protect_identifiers($k, TRUE); + + if ($escape === TRUE) + { + $k = $this->_protect_identifiers($k, TRUE); + } + } $this->ar_where[] = $prefix.$k.$v; -- cgit v1.2.3-24-g4f1b From 2385d30422b865052bbc6f333e6a189f46215a61 Mon Sep 17 00:00:00 2001 From: Derek Allard Date: Mon, 7 Apr 2008 14:01:01 +0000 Subject: Added rename_table() into DBForge. --- system/database/DB_forge.php | 21 +++++++++++++++++++++ system/database/drivers/mssql/mssql_forge.php | 19 +++++++++++++++++++ system/database/drivers/mysql/mysql_forge.php | 20 +++++++++++++++++++- system/database/drivers/mysqli/mysqli_forge.php | 19 +++++++++++++++++++ system/database/drivers/oci8/oci8_forge.php | 19 +++++++++++++++++++ system/database/drivers/odbc/odbc_forge.php | 20 ++++++++++++++++++++ system/database/drivers/postgre/postgre_forge.php | 19 +++++++++++++++++++ system/database/drivers/sqlite/sqlite_driver.php | 18 ++++++++++++++++++ 8 files changed, 154 insertions(+), 1 deletion(-) (limited to 'system') diff --git a/system/database/DB_forge.php b/system/database/DB_forge.php index cd468bc6a..5f25ebedc 100644 --- a/system/database/DB_forge.php +++ b/system/database/DB_forge.php @@ -208,6 +208,27 @@ class CI_DB_forge { // -------------------------------------------------------------------- + /** + * 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($table_name, $new_table_name); + return $this->db->query($sql); + } + + // -------------------------------------------------------------------- + /** * Column Add * diff --git a/system/database/drivers/mssql/mssql_forge.php b/system/database/drivers/mssql/mssql_forge.php index baf776c74..63063f259 100644 --- a/system/database/drivers/mssql/mssql_forge.php +++ b/system/database/drivers/mssql/mssql_forge.php @@ -215,5 +215,24 @@ class CI_DB_mssql_forge extends CI_DB_forge { } + // -------------------------------------------------------------------- + + /** + * 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; + } + } ?> \ No newline at end of file diff --git a/system/database/drivers/mysql/mysql_forge.php b/system/database/drivers/mysql/mysql_forge.php index 6e3a2d170..4eb449ef2 100644 --- a/system/database/drivers/mysql/mysql_forge.php +++ b/system/database/drivers/mysql/mysql_forge.php @@ -177,7 +177,7 @@ class CI_DB_mysql_forge extends CI_DB_forge { * Drop Table * * @access private - * @return bool + * @return string */ function _drop_table($table) { @@ -219,5 +219,23 @@ class CI_DB_mysql_forge extends CI_DB_forge { 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; + } + } ?> \ No newline at end of file diff --git a/system/database/drivers/mysqli/mysqli_forge.php b/system/database/drivers/mysqli/mysqli_forge.php index cb315a450..46a107565 100644 --- a/system/database/drivers/mysqli/mysqli_forge.php +++ b/system/database/drivers/mysqli/mysqli_forge.php @@ -213,5 +213,24 @@ class CI_DB_mysqli_forge extends CI_DB_forge { 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; + } + } ?> \ No newline at end of file diff --git a/system/database/drivers/oci8/oci8_forge.php b/system/database/drivers/oci8/oci8_forge.php index b9d9e6354..a3940aedb 100644 --- a/system/database/drivers/oci8/oci8_forge.php +++ b/system/database/drivers/oci8/oci8_forge.php @@ -212,5 +212,24 @@ class CI_DB_oci8_forge extends CI_DB_forge { } + // -------------------------------------------------------------------- + + /** + * 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; + } + + } ?> \ No newline at end of file diff --git a/system/database/drivers/odbc/odbc_forge.php b/system/database/drivers/odbc/odbc_forge.php index 374c15fcd..66e1722d8 100644 --- a/system/database/drivers/odbc/odbc_forge.php +++ b/system/database/drivers/odbc/odbc_forge.php @@ -232,5 +232,25 @@ class CI_DB_odbc_forge extends CI_DB_forge { } + + // -------------------------------------------------------------------- + + /** + * 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; + } + + } ?> \ No newline at end of file diff --git a/system/database/drivers/postgre/postgre_forge.php b/system/database/drivers/postgre/postgre_forge.php index 81ac8e92b..72a61748d 100644 --- a/system/database/drivers/postgre/postgre_forge.php +++ b/system/database/drivers/postgre/postgre_forge.php @@ -215,5 +215,24 @@ class CI_DB_postgre_forge extends CI_DB_forge { } + // -------------------------------------------------------------------- + + /** + * 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; + } + + } ?> \ No newline at end of file diff --git a/system/database/drivers/sqlite/sqlite_driver.php b/system/database/drivers/sqlite/sqlite_driver.php index 16a8308c1..2ad5d6120 100644 --- a/system/database/drivers/sqlite/sqlite_driver.php +++ b/system/database/drivers/sqlite/sqlite_driver.php @@ -635,6 +635,24 @@ class CI_DB_sqlite_driver extends CI_DB { @sqlite_close($conn_id); } + // -------------------------------------------------------------------- + + /** + * 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; + } + } -- cgit v1.2.3-24-g4f1b From e146ed7ddd607e2b40e4590e0600a4694d43423f Mon Sep 17 00:00:00 2001 From: Derek Jones Date: Tue, 8 Apr 2008 20:29:53 +0000 Subject: fixed code comment --- system/codeigniter/CodeIgniter.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system') diff --git a/system/codeigniter/CodeIgniter.php b/system/codeigniter/CodeIgniter.php index 04936b956..3114cd4ec 100644 --- a/system/codeigniter/CodeIgniter.php +++ b/system/codeigniter/CodeIgniter.php @@ -46,7 +46,7 @@ require(BASEPATH.'codeigniter/Compat'.EXT); /* * ------------------------------------------------------ - * Load the compatibility override functions + * Load the framework constants * ------------------------------------------------------ */ require(APPPATH.'config/constants'.EXT); -- cgit v1.2.3-24-g4f1b From d7f421133d78156a8587f9c244b4bebb4d2c6a8c Mon Sep 17 00:00:00 2001 From: Derek Allard Date: Fri, 11 Apr 2008 11:43:11 +0000 Subject: The MySQLi forge class is now in sync with MySQL forge. --- system/database/drivers/mysqli/mysqli_forge.php | 125 ++++++++++++------------ 1 file changed, 65 insertions(+), 60 deletions(-) (limited to 'system') diff --git a/system/database/drivers/mysqli/mysqli_forge.php b/system/database/drivers/mysqli/mysqli_forge.php index 46a107565..e6bc0093f 100644 --- a/system/database/drivers/mysqli/mysqli_forge.php +++ b/system/database/drivers/mysqli/mysqli_forge.php @@ -53,40 +53,16 @@ class CI_DB_mysqli_forge extends CI_DB_forge { // -------------------------------------------------------------------- /** - * Drop Table - * - * @access private - * @return bool - */ - function _drop_table($table) - { - return "DROP TABLE IF EXISTS ".$this->db->_escape_table($table); - } - - // -------------------------------------------------------------------- - - /** - * Create Table + * Process Fields * * @access private - * @param string the table name - * @param array the fields - * @param mixed primary key(s) - * @param mixed key(s) - * @param boolean should 'IF NOT EXISTS' be added to the SQL - * @return bool + * @param mixed the fields + * @return string */ - function _create_table($table, $fields, $primary_keys, $keys, $if_not_exists) + function _process_fields($fields) { - $sql = 'CREATE TABLE '; - - if ($if_not_exists === TRUE) - { - $sql .= 'IF NOT EXISTS '; - } - - $sql .= $this->db->_escape_table($table)." ("; $current_field_count = 0; + $sql = ''; foreach ($fields as $field=>$attributes) { @@ -102,8 +78,16 @@ class CI_DB_mysqli_forge extends CI_DB_forge { $attributes = array_change_key_case($attributes, CASE_UPPER); $sql .= "\n\t".$this->db->_protect_identifiers($field); + + if (array_key_exists('NAME', $attributes)) + { + $sql .= ' '.$this->db->_protect_identifiers($attributes['NAME']).' '; + } - $sql .= ' '.$attributes['TYPE']; + if (array_key_exists('TYPE', $attributes)) + { + $sql .= ' '.$attributes['TYPE']; + } if (array_key_exists('CONSTRAINT', $attributes)) { @@ -120,13 +104,9 @@ class CI_DB_mysqli_forge extends CI_DB_forge { $sql .= ' DEFAULT \''.$attributes['DEFAULT'].'\''; } - if (array_key_exists('NULL', $attributes) && $attributes['NULL'] === TRUE) - { - $sql .= ' NULL'; - } - else + if (array_key_exists('NULL', $attributes)) { - $sql .= ' NOT NULL'; + $sql .= ($attributes['NULL'] === TRUE) ? ' NULL' : ' NOT NULL'; } if (array_key_exists('AUTO_INCREMENT', $attributes) && $attributes['AUTO_INCREMENT'] === TRUE) @@ -141,6 +121,35 @@ class CI_DB_mysqli_forge extends CI_DB_forge { $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_table($table)." ("; + + $sql .= $this->_process_fields($fields); if (count($primary_keys) > 0) { @@ -164,6 +173,19 @@ class CI_DB_mysqli_forge extends CI_DB_forge { // -------------------------------------------------------------------- + /** + * Drop Table + * + * @access private + * @return string + */ + function _drop_table($table) + { + return "DROP TABLE IF EXISTS ".$this->db->_escape_table($table); + } + + // -------------------------------------------------------------------- + /** * Alter table query * @@ -173,45 +195,28 @@ class CI_DB_mysqli_forge extends CI_DB_forge { * @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 array fields * @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 = '') + function _alter_table($alter_type, $table, $fields, $after_field = '') { - $sql = 'ALTER TABLE '.$this->db->_protect_identifiers($table)." $alter_type ".$this->db->_protect_identifiers($column_name); + $sql = 'ALTER TABLE '.$this->db->_protect_identifiers($table)." $alter_type "; // DROP has everything it needs now. if ($alter_type == 'DROP') { - return $sql; + return $sql.$this->db->_protect_identifiers($fields); } - $sql .= " $column_definition"; - - if ($default_value != '') - { - $sql .= " DEFAULT \"$default_value\""; - } - - if ($null === NULL) - { - $sql .= ' NULL'; - } - else - { - $sql .= ' NOT NULL'; - } + $sql .= $this->_process_fields($fields); if ($after_field != '') { $sql .= ' AFTER ' . $this->db->_protect_identifiers($after_field); } - return $sql; + return $sql; } // -------------------------------------------------------------------- @@ -231,6 +236,6 @@ class CI_DB_mysqli_forge extends CI_DB_forge { $sql = 'ALTER TABLE '.$this->db->_protect_identifiers($table_name)." RENAME TO ".$this->db->_protect_identifiers($new_table_name); return $sql; } - + } ?> \ No newline at end of file -- cgit v1.2.3-24-g4f1b From 27b5005d23ab2d55e459b59890d0108e100cb070 Mon Sep 17 00:00:00 2001 From: Derek Jones Date: Mon, 14 Apr 2008 14:03:04 +0000 Subject: added check to make sure the URI path is not constructed entirely of slashes in URI::_fetch_uri_string() --- system/libraries/URI.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'system') diff --git a/system/libraries/URI.php b/system/libraries/URI.php index aecf05138..d10a5daeb 100644 --- a/system/libraries/URI.php +++ b/system/libraries/URI.php @@ -65,7 +65,7 @@ class CI_URI { // build the URI string from the zero index of the $_GET array. // This avoids having to deal with $_SERVER variables, which // can be unreliable in some environments - if (is_array($_GET) AND count($_GET) == 1) + if (is_array($_GET) AND count($_GET) == 1 AND trim(key($_GET), '/') != '') { $this->uri_string = key($_GET); return; @@ -74,7 +74,7 @@ class CI_URI { // Is there a PATH_INFO variable? // Note: some servers seem to have trouble with getenv() so we'll test it two ways $path = (isset($_SERVER['PATH_INFO'])) ? $_SERVER['PATH_INFO'] : @getenv('PATH_INFO'); - if ($path != '' AND $path != '/' AND $path != "/".SELF) + if (trim($path, '/') != '' AND $path != "/".SELF) { $this->uri_string = $path; return; @@ -82,7 +82,7 @@ class CI_URI { // No PATH_INFO?... What about QUERY_STRING? $path = (isset($_SERVER['QUERY_STRING'])) ? $_SERVER['QUERY_STRING'] : @getenv('QUERY_STRING'); - if ($path != '' AND $path != '/') + if (trim($path, '/') != '') { $this->uri_string = $path; return; @@ -90,7 +90,7 @@ class CI_URI { // No QUERY_STRING?... Maybe the ORIG_PATH_INFO variable exists? $path = (isset($_SERVER['ORIG_PATH_INFO'])) ? $_SERVER['ORIG_PATH_INFO'] : @getenv('ORIG_PATH_INFO'); - if ($path != '' AND $path != '/' AND $path != "/".SELF) + if (trim($path, '/') != '' AND $path != "/".SELF) { $this->uri_string = $path; return; -- cgit v1.2.3-24-g4f1b From 3a11555ec302eb81f5d8c1d7984f24501674b736 Mon Sep 17 00:00:00 2001 From: Derek Allard Date: Tue, 15 Apr 2008 19:57:59 +0000 Subject: incorrect path fixed up for fonts --- system/plugins/captcha_pi.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system') diff --git a/system/plugins/captcha_pi.php b/system/plugins/captcha_pi.php index 2c82f70a1..50a4eae0d 100644 --- a/system/plugins/captcha_pi.php +++ b/system/plugins/captcha_pi.php @@ -28,7 +28,7 @@ Once loaded you can generate a captcha like this: 'word' => 'Random word', 'img_path' => './captcha/', 'img_url' => 'http://www.your-site.com/captcha/', - 'font_path' => './system/texb.ttf', + 'font_path' => './system/fonts/texb.ttf', 'img_width' => '150', 'img_height' => 30, 'expiration' => 7200 -- cgit v1.2.3-24-g4f1b From 5162fc778acb1ecc8f879578e48bde9ce767775c Mon Sep 17 00:00:00 2001 From: Derek Allard Date: Tue, 15 Apr 2008 20:05:37 +0000 Subject: Fixed an AR bug when joining with a table alias and table prefix (#4400). --- system/database/DB_active_rec.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system') diff --git a/system/database/DB_active_rec.php b/system/database/DB_active_rec.php index d58580637..6f50c110d 100644 --- a/system/database/DB_active_rec.php +++ b/system/database/DB_active_rec.php @@ -1476,7 +1476,7 @@ class CI_DB_active_record extends CI_DB_driver { $sql = ( ! $this->ar_distinct) ? 'SELECT ' : 'SELECT DISTINCT '; - $sql .= (count($this->ar_select) == 0) ? '*' : implode(', ', $this->ar_select); + $sql .= (count($this->ar_select) == 0) ? '*' : implode(', ', $this->_filter_table_aliases($this->ar_select)); if ($select_override !== FALSE) { -- cgit v1.2.3-24-g4f1b From 3a555ef16dfe811815af83fdeccfebd6c04b99b2 Mon Sep 17 00:00:00 2001 From: Derek Allard Date: Thu, 17 Apr 2008 22:03:00 +0000 Subject: The Download helper now exits within force-download(). --- system/helpers/download_helper.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system') diff --git a/system/helpers/download_helper.php b/system/helpers/download_helper.php index 2d0e737c9..5e47fc5c9 100644 --- a/system/helpers/download_helper.php +++ b/system/helpers/download_helper.php @@ -91,7 +91,7 @@ if (! function_exists('force_download')) header("Content-Length: ".strlen($data)); } - echo $data; + exit($data); } } -- cgit v1.2.3-24-g4f1b From 6b397a8bf28d2bf01b43ae393f853a853410cd57 Mon Sep 17 00:00:00 2001 From: Derek Allard Date: Sun, 20 Apr 2008 17:49:09 +0000 Subject: noted 2 additional database types in db config --- system/application/config/database.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system') diff --git a/system/application/config/database.php b/system/application/config/database.php index 0d0e08e22..6973c5afa 100644 --- a/system/application/config/database.php +++ b/system/application/config/database.php @@ -17,7 +17,7 @@ | ['password'] The password used to connect to the database | ['database'] The name of the database you want to connect to | ['dbdriver'] The database type. ie: mysql. Currently supported: - mysql, mysqli, postgre, odbc, mssql + mysql, mysqli, postgre, odbc, mssql, sqlite, oci8 | ['dbprefix'] You can add an optional prefix, which will be added | to the table name when using the Active Record class | ['pconnect'] TRUE/FALSE - Whether to use a persistent connection -- cgit v1.2.3-24-g4f1b From 866b8138c5f51b0ca544dd8a91c265d9200acab8 Mon Sep 17 00:00:00 2001 From: Derek Allard Date: Mon, 21 Apr 2008 22:02:37 +0000 Subject: doc clarifications, example fixes, grammar. --- system/scaffolding/views/stylesheet.css | 286 ++++++++++++++++---------------- 1 file changed, 143 insertions(+), 143 deletions(-) (limited to 'system') diff --git a/system/scaffolding/views/stylesheet.css b/system/scaffolding/views/stylesheet.css index e2e3aa574..ba6ee0a2f 100644 --- a/system/scaffolding/views/stylesheet.css +++ b/system/scaffolding/views/stylesheet.css @@ -1,143 +1,143 @@ -body { - margin: 0; - padding: 0; - font-family: Lucida Grande, Verdana, Geneva, Sans-serif; - font-size: 11px; - color: #4F5155; - background: #fff url(background.jpg) repeat-x left top; -} - -a { - color: #8B0D00; - background-color: transparent; - text-decoration: none; - font-weight: bold; -} - -a:visited { - color: #8B0D00; - background-color: transparent; - text-decoration: none; -} - -a:hover { - color: #000; - text-decoration: none; - background-color: transparent; -} - - -#header { - margin: 0; - padding: 0; -} - -#header_left { - background-color: transparent; - float: left; - padding: 21px 0 0 32px; - margin: 0 -} - -#header_right { - background-color: transparent; - float: right; - text-align: right; - padding: 35px 50px 20px 0; - margin: 0 -} - -#footer { - margin: 20px 0 15px 0; - padding: 0; -} - -#footer p { - font-size: 10px; - color: #999; - text-align: center; -} - -#outer { - margin: 30px 40px 0 40px; -} - -img { - padding:0; - border: 0; - margin: 0; -} - -.nopad { - padding:0; - border: 0; - margin: 0; -} - -table { - background-color: #efefef; -} - -th { - background-color: #eee; - font-weight: bold; - padding: 6px; - text-align: left; -} - -td { - background-color: #fff; - padding: 6px; -} - - -form { - margin: 0; - padding: 0; -} - -.input { - font-family: Lucida Grande, Verdana, Geneva, Sans-serif; - font-size: 11px; - width: 600px; - color: #333; - border: 1px solid #B3B4BD; - font-size: 11px; - height: 2em; - padding: 0; - margin: 0; -} - -.textarea { - font-family: Lucida Grande, Verdana, Geneva, Sans-serif; - font-size: 12px; - width: 600px; - color: #333; - border: 1px solid #B3B4BD; - padding: 0; - margin: 0; -} - -.select { - background-color: #fff; - font-size: 11px; - font-weight: normal; - color: #333; - padding: 0; - margin: 0 0 3px 0; -} - -.checkbox { - background-color: transparent; - padding: 0; - border: 0; -} - -.submit { - background-color: #8B0D00; - color: transparent; - font-weight: normal; - border: 1px solid #000; - margin: 6px 0 0 0; - padding: 1px 5px 1px 5px; -} +body { + margin: 0; + padding: 0; + font-family: Lucida Grande, Verdana, Geneva, Sans-serif; + font-size: 11px; + color: #4F5155; + background: #fff url(background.jpg) repeat-x left top; +} + +a { + color: #8B0D00; + background-color: transparent; + text-decoration: none; + font-weight: bold; +} + +a:visited { + color: #8B0D00; + background-color: transparent; + text-decoration: none; +} + +a:hover { + color: #000; + text-decoration: none; + background-color: transparent; +} + + +#header { + margin: 0; + padding: 0; +} + +#header_left { + background-color: transparent; + float: left; + padding: 21px 0 0 32px; + margin: 0 +} + +#header_right { + background-color: transparent; + float: right; + text-align: right; + padding: 35px 50px 20px 0; + margin: 0 +} + +#footer { + margin: 20px 0 15px 0; + padding: 0; +} + +#footer p { + font-size: 10px; + color: #999; + text-align: center; +} + +#outer { + margin: 30px 40px 0 40px; +} + +img { + padding:0; + border: 0; + margin: 0; +} + +.nopad { + padding:0; + border: 0; + margin: 0; +} + +table { + background-color: #efefef; +} + +th { + background-color: #eee; + font-weight: bold; + padding: 6px; + text-align: left; +} + +td { + background-color: #fff; + padding: 6px; +} + + +form { + margin: 0; + padding: 0; +} + +.input { + font-family: Lucida Grande, Verdana, Geneva, Sans-serif; + font-size: 11px; + width: 600px; + color: #333; + border: 1px solid #B3B4BD; + font-size: 11px; + height: 2em; + padding: 0; + margin: 0; +} + +.textarea { + font-family: Lucida Grande, Verdana, Geneva, Sans-serif; + font-size: 12px; + width: 600px; + color: #333; + border: 1px solid #B3B4BD; + padding: 0; + margin: 0; +} + +.select { + background-color: #fff; + font-size: 11px; + font-weight: normal; + color: #333; + padding: 0; + margin: 0 0 3px 0; +} + +.checkbox { + background-color: transparent; + padding: 0; + border: 0; +} + +.submit { + background-color: #8B0D00; + color: #FFF; + font-weight: normal; + border: 1px solid #000; + margin: 6px 0 0 0; + padding: 1px 5px 1px 5px; +} -- cgit v1.2.3-24-g4f1b From 7c53be42a74b103774729281aef09ad505f3b611 Mon Sep 17 00:00:00 2001 From: Derek Allard Date: Tue, 22 Apr 2008 12:02:43 +0000 Subject: Added the ability to set CRLF settings via config in the Email class. Added SVN commit number to changelog Fixed more guide typos and examples --- system/libraries/Email.php | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) (limited to 'system') diff --git a/system/libraries/Email.php b/system/libraries/Email.php index 189678742..19121c56b 100644 --- a/system/libraries/Email.php +++ b/system/libraries/Email.php @@ -490,6 +490,26 @@ class CI_Email { // -------------------------------------------------------------------- + /** + * Set CRLF + * + * @access public + * @param string + * @return void + */ + function set_crlf($crlf = "\n") + { + if ($crlf != "\n" AND $crlf != "\r\n" AND $crlf != "\r") + { + $this->crlf = "\n"; + return; + } + + $this->crlf = $crlf; + } + + // -------------------------------------------------------------------- + /** * Set Message Boundary * -- cgit v1.2.3-24-g4f1b From f9d5348cf2776374bf09bdda8c941198167d9ae9 Mon Sep 17 00:00:00 2001 From: Derek Allard Date: Sat, 26 Apr 2008 19:19:25 +0000 Subject: Unit Testing results are now colour coded, and a change was made to the default template of results. --- system/libraries/Router.php | 12 +++++----- system/libraries/Unit_test.php | 52 ++++++++++++++++++++++++++---------------- 2 files changed, 38 insertions(+), 26 deletions(-) (limited to 'system') diff --git a/system/libraries/Router.php b/system/libraries/Router.php index d9dd6dd3f..804e80bd2 100644 --- a/system/libraries/Router.php +++ b/system/libraries/Router.php @@ -204,7 +204,7 @@ class CI_Router { // Does the requested controller exist in the sub-folder? if ( ! file_exists(APPPATH.'controllers/'.$this->fetch_directory().$segments[0].EXT)) { - show_404($this->fetch_directory().$segments[0]); + show_404($this->fetch_directory().$segments[0]); } } else @@ -220,16 +220,16 @@ class CI_Router { } } - + return $segments; } - + // Can't find the requested controller... - show_404($segments[0]); + show_404($segments[0]); } - + // -------------------------------------------------------------------- - + /** * Parse Routes * diff --git a/system/libraries/Unit_test.php b/system/libraries/Unit_test.php index 33a8f3109..ff4d0c7ed 100644 --- a/system/libraries/Unit_test.php +++ b/system/libraries/Unit_test.php @@ -100,32 +100,48 @@ class CI_Unit_test { * @return string */ function report($result = array()) - { + { if (count($result) == 0) { $result = $this->result(); } - + + $CI =& get_instance(); + $CI->load->language('unit_test'); + $this->_parse_template(); - + $r = ''; foreach ($result as $res) { $table = ''; - + foreach ($res as $key => $val) { - $temp = $this->_template_rows; + + if ($key == $CI->lang->line('ut_result')) + { + if ($val == $CI->lang->line('ut_passed')) + { + $val = ''.$val.''; + } + elseif ($val == $CI->lang->line('ut_failed')) + { + $val = ''.$val.''; + } + } + + $temp = $this->_template_rows; $temp = str_replace('{item}', $key, $temp); $temp = str_replace('{result}', $val, $temp); $table .= $temp; } - + $r .= str_replace('{rows}', $table, $this->_template); } - - return $r; - } + + return $r; + } // -------------------------------------------------------------------- @@ -262,18 +278,14 @@ class CI_Unit_test { */ function _default_template() { - $this->_template = ' -
    - - {rows} -
    '; + $this->_template = "\n".''; + $this->_template .= '{rows}'; + $this->_template .= "\n".'
    '; - $this->_template_rows = ' - - {item} - {result} - - '; + $this->_template_rows = "\n\t".''; + $this->_template_rows .= "\n\t\t".'{item}'; + $this->_template_rows .= "\n\t\t".'{result}'; + $this->_template_rows .= "\n\t".''; } // -------------------------------------------------------------------- -- cgit v1.2.3-24-g4f1b From 05f830c7105ef3cd4a8388bffe7cf73c35236105 Mon Sep 17 00:00:00 2001 From: Derek Allard Date: Sun, 27 Apr 2008 13:35:20 +0000 Subject: Added the ability to include an optional HTTP Response Code in the redirect() function of the URL Helper. --- system/helpers/url_helper.php | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'system') diff --git a/system/helpers/url_helper.php b/system/helpers/url_helper.php index bd94b390c..1ff26082c 100644 --- a/system/helpers/url_helper.php +++ b/system/helpers/url_helper.php @@ -470,6 +470,8 @@ if (! function_exists('url_title')) * Header Redirect * * Header redirect in two flavors + * For very fine grained control over headers, you could use the Output + * Library's set_header() function. * * @access public * @param string the URL @@ -478,13 +480,13 @@ if (! function_exists('url_title')) */ if (! function_exists('redirect')) { - function redirect($uri = '', $method = 'location') + function redirect($uri = '', $method = 'location', $http_response_code = 302) { switch($method) { case 'refresh' : header("Refresh:0;url=".site_url($uri)); break; - default : header("Location: ".site_url($uri)); + default : header("Location: ".site_url($uri), TRUE, $http_response_code); break; } exit; -- cgit v1.2.3-24-g4f1b From b94b89c69195a0708add8dedb1721f12bcafbf8c Mon Sep 17 00:00:00 2001 From: Derek Allard Date: Mon, 28 Apr 2008 23:18:00 +0000 Subject: Added a valid_emails rule to the Validation class. --- system/database/drivers/mysql/mysql_driver.php | 5 +---- system/libraries/Validation.php | 27 ++++++++++++++++++++++++++ 2 files changed, 28 insertions(+), 4 deletions(-) (limited to 'system') diff --git a/system/database/drivers/mysql/mysql_driver.php b/system/database/drivers/mysql/mysql_driver.php index 2bc66ecf2..f435c0bc4 100644 --- a/system/database/drivers/mysql/mysql_driver.php +++ b/system/database/drivers/mysql/mysql_driver.php @@ -314,11 +314,8 @@ class CI_DB_mysql_driver extends CI_DB { $query = $this->query($this->_count_string . $this->_protect_identifiers('numrows'). " FROM " . $this->_protect_identifiers($this->dbprefix.$table)); - if ($query->num_rows() == 0) - return '0'; - $row = $query->row(); - return $row->numrows; + return (int)$row->numrows; } // -------------------------------------------------------------------- diff --git a/system/libraries/Validation.php b/system/libraries/Validation.php index d0714d040..18fdba2d3 100644 --- a/system/libraries/Validation.php +++ b/system/libraries/Validation.php @@ -487,6 +487,33 @@ class CI_Validation { // -------------------------------------------------------------------- + /** + * Valid Emails + * + * @access public + * @param string + * @return bool + */ + function valid_emails($str) + { + if (strpos($str, ',') === FALSE) + { + return $this->valid_email(trim($str)); + } + + foreach(explode(',', $str) as $email) + { + if (trim($email) != '' && $this->valid_email(trim($email)) === FALSE) + { + return FALSE; + } + } + + return TRUE; + } + + // -------------------------------------------------------------------- + /** * Validate IP Address * -- cgit v1.2.3-24-g4f1b From a9911fc06160f9d4538475e2bf9ee45c9ff8f746 Mon Sep 17 00:00:00 2001 From: Derek Allard Date: Thu, 1 May 2008 01:48:51 +0000 Subject: another change to the download helper for compatibility --- system/helpers/download_helper.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'system') diff --git a/system/helpers/download_helper.php b/system/helpers/download_helper.php index 5e47fc5c9..ee3d78f25 100644 --- a/system/helpers/download_helper.php +++ b/system/helpers/download_helper.php @@ -91,7 +91,8 @@ if (! function_exists('force_download')) header("Content-Length: ".strlen($data)); } - exit($data); + echo $data; + exit; // exit($data); // didn't work on some browsers } } -- cgit v1.2.3-24-g4f1b From c0c5c97ffbfac81837e1913c77da7462c096ae87 Mon Sep 17 00:00:00 2001 From: Derek Allard Date: Thu, 1 May 2008 01:56:51 +0000 Subject: revert... Derek's an idiot --- system/helpers/download_helper.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'system') diff --git a/system/helpers/download_helper.php b/system/helpers/download_helper.php index ee3d78f25..5e47fc5c9 100644 --- a/system/helpers/download_helper.php +++ b/system/helpers/download_helper.php @@ -91,8 +91,7 @@ if (! function_exists('force_download')) header("Content-Length: ".strlen($data)); } - echo $data; - exit; // exit($data); // didn't work on some browsers + exit($data); } } -- cgit v1.2.3-24-g4f1b From c39d202d35f76f8a85f357d6e86a2223258d6c07 Mon Sep 17 00:00:00 2001 From: Derek Allard Date: Thu, 1 May 2008 03:26:24 +0000 Subject: The Zip class now exits within download(). --- system/libraries/Zip.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system') diff --git a/system/libraries/Zip.php b/system/libraries/Zip.php index a3d42f34c..fab8e7f6b 100644 --- a/system/libraries/Zip.php +++ b/system/libraries/Zip.php @@ -351,7 +351,7 @@ class CI_Zip { header("Content-Length: ".strlen($this->get_zip())); } - echo $this->get_zip(); + exit($this->get_zip()); } // -------------------------------------------------------------------- -- cgit v1.2.3-24-g4f1b From 7539f67a23c8536f892263d8d7ab9448655d8e22 Mon Sep 17 00:00:00 2001 From: Derek Allard Date: Mon, 5 May 2008 16:38:35 +0000 Subject: Added get_dir_file_info(), get_file_info(), and get_mime_by_extension() to the File Helper. Changed ( ! condition) into (! condition) within the code --- system/codeigniter/CodeIgniter.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'system') diff --git a/system/codeigniter/CodeIgniter.php b/system/codeigniter/CodeIgniter.php index 3114cd4ec..bf3398d81 100644 --- a/system/codeigniter/CodeIgniter.php +++ b/system/codeigniter/CodeIgniter.php @@ -146,7 +146,7 @@ load_class('Controller', FALSE); // Load the local application controller // Note: The Router class automatically validates the controller path. 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().EXT)) +if (! file_exists(APPPATH.'controllers/'.$RTR->fetch_directory().$RTR->fetch_class().EXT)) { show_error('Unable to load your default controller. Please make sure the controller specified in your Routes.php file is valid.'); } @@ -170,7 +170,7 @@ $class = $RTR->fetch_class(); $method = $RTR->fetch_method(); -if ( ! class_exists($class) +if (! class_exists($class) OR $method == 'controller' OR substr($method, 0, 1) == '_' OR in_array($method, get_class_methods('Controller'), TRUE) -- cgit v1.2.3-24-g4f1b From 7327499064ae165468c7440f8571c3e570b58a0b Mon Sep 17 00:00:00 2001 From: Derek Allard Date: Mon, 5 May 2008 16:39:18 +0000 Subject: Added get_dir_file_info(), get_file_info(), and get_mime_by_extension() to the File Helper. Changed ( ! condition) into (! condition) within the code --- system/codeigniter/Common.php | 10 +- system/codeigniter/Compat.php | 2 +- system/database/DB.php | 10 +- system/database/DB_active_rec.php | 44 ++--- system/database/DB_cache.php | 10 +- system/database/DB_driver.php | 40 ++--- system/database/DB_result.php | 6 +- system/database/DB_utility.php | 10 +- system/database/drivers/mssql/mssql_driver.php | 6 +- system/database/drivers/mysql/mysql_driver.php | 6 +- system/database/drivers/mysqli/mysqli_driver.php | 6 +- system/database/drivers/oci8/oci8_driver.php | 12 +- system/database/drivers/odbc/odbc_driver.php | 6 +- system/database/drivers/postgre/postgre_driver.php | 6 +- system/database/drivers/sqlite/sqlite_driver.php | 10 +- system/database/drivers/sqlite/sqlite_forge.php | 2 +- system/database/drivers/sqlite/sqlite_utility.php | 2 +- system/helpers/array_helper.php | 4 +- system/helpers/cookie_helper.php | 2 +- system/helpers/date_helper.php | 12 +- system/helpers/download_helper.php | 2 +- system/helpers/email_helper.php | 2 +- system/helpers/file_helper.php | 181 ++++++++++++++++++++- system/helpers/form_helper.php | 26 +-- system/helpers/html_helper.php | 6 +- system/helpers/path_helper.php | 2 +- system/helpers/security_helper.php | 4 +- system/helpers/smiley_helper.php | 8 +- system/helpers/text_helper.php | 4 +- system/helpers/typography_helper.php | 24 +-- system/helpers/url_helper.php | 10 +- system/libraries/Benchmark.php | 4 +- system/libraries/Calendar.php | 4 +- system/libraries/Config.php | 12 +- system/libraries/Controller.php | 2 +- system/libraries/Email.php | 52 +++--- system/libraries/Encrypt.php | 6 +- system/libraries/Exceptions.php | 6 +- system/libraries/Ftp.php | 34 ++-- system/libraries/Hooks.php | 14 +- system/libraries/Image_lib.php | 58 +++---- system/libraries/Input.php | 22 +-- system/libraries/Language.php | 2 +- system/libraries/Loader.php | 36 ++-- system/libraries/Log.php | 8 +- system/libraries/Model.php | 2 +- system/libraries/Output.php | 18 +- system/libraries/Pagination.php | 2 +- system/libraries/Parser.php | 4 +- system/libraries/Profiler.php | 6 +- system/libraries/Router.php | 8 +- system/libraries/Session.php | 8 +- system/libraries/Table.php | 18 +- system/libraries/Trackback.php | 24 +-- system/libraries/URI.php | 12 +- system/libraries/Unit_test.php | 8 +- system/libraries/Upload.php | 42 ++--- system/libraries/User_agent.php | 8 +- system/libraries/Validation.php | 48 +++--- system/libraries/Xmlrpc.php | 18 +- system/libraries/Xmlrpcs.php | 8 +- system/libraries/Zip.php | 8 +- system/plugins/captcha_pi.php | 12 +- system/scaffolding/Scaffolding.php | 14 +- 64 files changed, 585 insertions(+), 418 deletions(-) (limited to 'system') diff --git a/system/codeigniter/Common.php b/system/codeigniter/Common.php index 4554a712b..05720a459 100644 --- a/system/codeigniter/Common.php +++ b/system/codeigniter/Common.php @@ -140,16 +140,16 @@ function &get_config() { static $main_conf; - if ( ! isset($main_conf)) + if (! isset($main_conf)) { - if ( ! file_exists(APPPATH.'config/config'.EXT)) + if (! file_exists(APPPATH.'config/config'.EXT)) { exit('The configuration file config'.EXT.' does not exist.'); } require(APPPATH.'config/config'.EXT); - if ( ! isset($config) OR ! is_array($config)) + if (! isset($config) OR ! is_array($config)) { exit('Your config file does not appear to be formatted correctly.'); } @@ -169,11 +169,11 @@ function config_item($item) { static $config_item = array(); - if ( ! isset($config_item[$item])) + if (! isset($config_item[$item])) { $config =& get_config(); - if ( ! isset($config[$item])) + if (! isset($config[$item])) { return FALSE; } diff --git a/system/codeigniter/Compat.php b/system/codeigniter/Compat.php index 56ebbf45d..8537432f5 100644 --- a/system/codeigniter/Compat.php +++ b/system/codeigniter/Compat.php @@ -36,7 +36,7 @@ * will generate errors when running under PHP 4 * */ -if ( ! defined('E_STRICT')) +if (! defined('E_STRICT')) { define('E_STRICT', 2048); } diff --git a/system/database/DB.php b/system/database/DB.php index 16ca1c888..8efe05560 100644 --- a/system/database/DB.php +++ b/system/database/DB.php @@ -29,7 +29,7 @@ function &DB($params = '', $active_record_override = FALSE) { include(APPPATH.'config/database'.EXT); - if ( ! isset($db) OR count($db) == 0) + if (! isset($db) OR count($db) == 0) { show_error('No database connection settings were found in the database config file.'); } @@ -39,7 +39,7 @@ function &DB($params = '', $active_record_override = FALSE) $active_group = $params; } - if ( ! isset($active_group) OR ! isset($db[$active_group])) + if (! isset($active_group) OR ! isset($db[$active_group])) { show_error('You have specified an invalid database connection group.'); } @@ -71,7 +71,7 @@ function &DB($params = '', $active_record_override = FALSE) } // No DB specified yet? Beat them senseless... - if ( ! isset($params['dbdriver']) OR $params['dbdriver'] == '') + if (! isset($params['dbdriver']) OR $params['dbdriver'] == '') { show_error('You have not selected a database type to connect to.'); } @@ -92,14 +92,14 @@ function &DB($params = '', $active_record_override = FALSE) { require_once(BASEPATH.'database/DB_active_rec'.EXT); - if ( ! class_exists('CI_DB')) + if (! class_exists('CI_DB')) { eval('class CI_DB extends CI_DB_active_record { }'); } } else { - if ( ! class_exists('CI_DB')) + if (! class_exists('CI_DB')) { eval('class CI_DB extends CI_DB_driver { }'); } diff --git a/system/database/DB_active_rec.php b/system/database/DB_active_rec.php index 6f50c110d..1820bd202 100644 --- a/system/database/DB_active_rec.php +++ b/system/database/DB_active_rec.php @@ -315,7 +315,7 @@ class CI_DB_active_record extends CI_DB_driver { { $type = strtoupper(trim($type)); - if ( ! in_array($type, array('LEFT', 'RIGHT', 'OUTER', 'INNER', 'LEFT OUTER', 'RIGHT OUTER'), TRUE)) + if (! in_array($type, array('LEFT', 'RIGHT', 'OUTER', 'INNER', 'LEFT OUTER', 'RIGHT OUTER'), TRUE)) { $type = ''; } @@ -411,7 +411,7 @@ class CI_DB_active_record extends CI_DB_driver { */ function _where($key, $value = NULL, $type = 'AND ', $escape = TRUE) { - if ( ! is_array($key)) + if (! is_array($key)) { $key = array($key => $value); } @@ -420,13 +420,13 @@ class CI_DB_active_record extends CI_DB_driver { { $prefix = (count($this->ar_where) == 0) ? '' : $type; - if ( ! $this->_has_operator($k) && is_null($key[$k])) + if (! $this->_has_operator($k) && is_null($key[$k])) { // value appears not to have been set, assign the test to IS NULL $k .= ' IS NULL'; } - if ( ! is_null($v)) + if (! is_null($v)) { if ($escape === TRUE) @@ -442,7 +442,7 @@ class CI_DB_active_record extends CI_DB_driver { } } - if ( ! $this->_has_operator($k)) + if (! $this->_has_operator($k)) { $k .= ' ='; } @@ -690,7 +690,7 @@ class CI_DB_active_record extends CI_DB_driver { */ function _like($field, $match = '', $type = 'AND ', $side = 'both', $not = '') { - if ( ! is_array($field)) + if (! is_array($field)) { $field = array($field => $match); } @@ -832,7 +832,7 @@ class CI_DB_active_record extends CI_DB_driver { */ function _having($key, $value = '', $type = 'AND ', $escape = TRUE) { - if ( ! is_array($key)) + if (! is_array($key)) { $key = array($key => $value); } @@ -972,7 +972,7 @@ class CI_DB_active_record extends CI_DB_driver { { $key = $this->_object_to_array($key); - if ( ! is_array($key)) + if (! is_array($key)) { $key = array($key => $value); } @@ -1022,7 +1022,7 @@ class CI_DB_active_record extends CI_DB_driver { $this->from($table); } - if ( ! is_null($limit)) + if (! is_null($limit)) { $this->limit($limit, $offset); } @@ -1087,12 +1087,12 @@ class CI_DB_active_record extends CI_DB_driver { $this->from($table); } - if ( ! is_null($where)) + if (! is_null($where)) { $this->where($where); } - if ( ! is_null($limit)) + if (! is_null($limit)) { $this->limit($limit, $offset); } @@ -1130,7 +1130,7 @@ class CI_DB_active_record extends CI_DB_driver { */ function insert($table = '', $set = NULL) { - if ( ! is_null($set)) + if (! is_null($set)) { $this->set($set); } @@ -1146,7 +1146,7 @@ class CI_DB_active_record extends CI_DB_driver { if ($table == '') { - if ( ! isset($this->ar_from[0])) + if (! isset($this->ar_from[0])) { if ($this->db_debug) { @@ -1179,7 +1179,7 @@ class CI_DB_active_record extends CI_DB_driver { */ function update($table = '', $set = NULL, $where = NULL, $limit = NULL) { - if ( ! is_null($set)) + if (! is_null($set)) { $this->set($set); } @@ -1195,7 +1195,7 @@ class CI_DB_active_record extends CI_DB_driver { if ($table == '') { - if ( ! isset($this->ar_from[0])) + if (! isset($this->ar_from[0])) { if ($this->db_debug) { @@ -1238,7 +1238,7 @@ class CI_DB_active_record extends CI_DB_driver { { if ($table == '') { - if ( ! isset($this->ar_from[0])) + if (! isset($this->ar_from[0])) { if ($this->db_debug) { @@ -1279,7 +1279,7 @@ class CI_DB_active_record extends CI_DB_driver { { if ($table == '') { - if ( ! isset($this->ar_from[0])) + if (! isset($this->ar_from[0])) { if ($this->db_debug) { @@ -1321,7 +1321,7 @@ class CI_DB_active_record extends CI_DB_driver { { if ($table == '') { - if ( ! isset($this->ar_from[0])) + if (! isset($this->ar_from[0])) { if ($this->db_debug) { @@ -1401,7 +1401,7 @@ class CI_DB_active_record extends CI_DB_driver { function _has_operator($str) { $str = trim($str); - if ( ! preg_match("/(\s|<|>|!|=|is null|is not null)/i", $str)) + if (! preg_match("/(\s|<|>|!|=|is null|is not null)/i", $str)) { return FALSE; } @@ -1474,7 +1474,7 @@ class CI_DB_active_record extends CI_DB_driver { { $this->_merge_cache(); - $sql = ( ! $this->ar_distinct) ? 'SELECT ' : 'SELECT DISTINCT '; + $sql = (! $this->ar_distinct) ? 'SELECT ' : 'SELECT DISTINCT '; $sql .= (count($this->ar_select) == 0) ? '*' : implode(', ', $this->_filter_table_aliases($this->ar_select)); @@ -1577,7 +1577,7 @@ class CI_DB_active_record extends CI_DB_driver { */ function _object_to_array($object) { - if ( ! is_object($object)) + if (! is_object($object)) { return $object; } @@ -1586,7 +1586,7 @@ class CI_DB_active_record extends CI_DB_driver { foreach (get_object_vars($object) as $key => $val) { // There are some built in keys we need to ignore for this conversion - if ( ! is_object($val) && ! is_array($val) && $key != '_parent_name' && $key != '_ci_scaffolding' && $key != '_ci_scaff_table') + if (! is_object($val) && ! is_array($val) && $key != '_parent_name' && $key != '_ci_scaffolding' && $key != '_ci_scaff_table') { $array[$key] = $val; diff --git a/system/database/DB_cache.php b/system/database/DB_cache.php index 08394da29..982725aaa 100644 --- a/system/database/DB_cache.php +++ b/system/database/DB_cache.php @@ -64,7 +64,7 @@ class CI_DB_Cache { // Add a trailing slash to the path if needed $path = preg_replace("/(.+?)\/*$/", "\\1/", $path); - if ( ! is_dir($path) OR ! is_really_writable($path)) + if (! is_dir($path) OR ! is_really_writable($path)) { // If the path is wrong we'll turn off caching return $this->CI->db->cache_off(); @@ -87,7 +87,7 @@ class CI_DB_Cache { */ function read($sql) { - if ( ! $this->check_path()) + if (! $this->check_path()) { return $this->CI->db->cache_off(); } @@ -115,7 +115,7 @@ class CI_DB_Cache { */ function write($sql, $object) { - if ( ! $this->check_path()) + if (! $this->check_path()) { return $this->CI->db->cache_off(); } @@ -127,9 +127,9 @@ class CI_DB_Cache { $filename = md5($sql); - if ( ! @is_dir($dir_path)) + if (! @is_dir($dir_path)) { - if ( ! @mkdir($dir_path, DIR_WRITE_MODE)) + if (! @mkdir($dir_path, DIR_WRITE_MODE)) { return FALSE; } diff --git a/system/database/DB_driver.php b/system/database/DB_driver.php index b1013178e..0f3a1ea0a 100644 --- a/system/database/DB_driver.php +++ b/system/database/DB_driver.php @@ -107,7 +107,7 @@ class CI_DB_driver { $this->conn_id = ($this->pconnect == FALSE) ? $this->db_connect() : $this->db_pconnect(); // No connection? Throw an error - if ( ! $this->conn_id) + if (! $this->conn_id) { log_message('error', 'Unable to connect to the database'); @@ -121,7 +121,7 @@ class CI_DB_driver { // Select the database if ($this->database != '') { - if ( ! $this->db_select()) + if (! $this->db_select()) { // Should we attempt to create the database? if ($create_db == TRUE) @@ -131,7 +131,7 @@ class CI_DB_driver { $CI->load->dbutil(); // Create the DB - if ( ! $CI->dbutil->create_database($this->database)) + if (! $CI->dbutil->create_database($this->database)) { log_message('error', 'Unable to create database: '.$this->database); @@ -401,7 +401,7 @@ class CI_DB_driver { { $driver = 'CI_DB_'.$this->dbdriver.'_result'; - if ( ! class_exists($driver)) + if (! class_exists($driver)) { include_once(BASEPATH.'database/DB_result'.EXT); include_once(BASEPATH.'database/drivers/'.$this->dbdriver.'/'.$this->dbdriver.'_result'.EXT); @@ -424,7 +424,7 @@ class CI_DB_driver { */ function simple_query($sql) { - if ( ! $this->conn_id) + if (! $this->conn_id) { $this->initialize(); } @@ -456,7 +456,7 @@ class CI_DB_driver { */ function trans_start($test_mode = FALSE) { - if ( ! $this->trans_enabled) + if (! $this->trans_enabled) { return FALSE; } @@ -481,7 +481,7 @@ class CI_DB_driver { */ function trans_complete() { - if ( ! $this->trans_enabled) + if (! $this->trans_enabled) { return FALSE; } @@ -539,7 +539,7 @@ class CI_DB_driver { return $sql; } - if ( ! is_array($binds)) + if (! is_array($binds)) { $binds = array($binds); } @@ -576,7 +576,7 @@ class CI_DB_driver { */ function is_write_type($sql) { - if ( ! preg_match('/^\s*"?(INSERT|UPDATE|DELETE|REPLACE|CREATE|DROP|LOAD DATA|COPY|ALTER|GRANT|REVOKE|LOCK|UNLOCK)\s+/i', $sql)) + if (! preg_match('/^\s*"?(INSERT|UPDATE|DELETE|REPLACE|CREATE|DROP|LOAD DATA|COPY|ALTER|GRANT|REVOKE|LOCK|UNLOCK)\s+/i', $sql)) { return FALSE; } @@ -683,7 +683,7 @@ class CI_DB_driver { { $fields = $this->list_fields($table); - if ( ! is_array($fields)) + if (! is_array($fields)) { return FALSE; } @@ -747,7 +747,7 @@ class CI_DB_driver { */ function table_exists($table_name) { - return ( ! in_array($this->prep_tablename($table_name), $this->list_tables())) ? FALSE : TRUE; + return (! in_array($this->prep_tablename($table_name), $this->list_tables())) ? FALSE : TRUE; } // -------------------------------------------------------------------- @@ -815,7 +815,7 @@ class CI_DB_driver { */ function field_exists($field_name, $table_name) { - return ( ! in_array($field_name, $this->list_fields($table_name))) ? FALSE : TRUE; + return (! in_array($field_name, $this->list_fields($table_name))) ? FALSE : TRUE; } // -------------------------------------------------------------------- @@ -899,7 +899,7 @@ class CI_DB_driver { $fields[$key] = $this->escape($val); } - if ( ! is_array($where)) + if (! is_array($where)) { $dest = array($where); } @@ -912,7 +912,7 @@ class CI_DB_driver { if ($val !== '') { - if ( ! $this->_has_operator($key)) + if (! $this->_has_operator($key)) { $key .= ' ='; } @@ -969,7 +969,7 @@ class CI_DB_driver { $function = $driver.$function; } - if ( ! function_exists($function)) + if (! function_exists($function)) { if ($this->db_debug) { @@ -1038,7 +1038,7 @@ class CI_DB_driver { */ function cache_delete($segment_one = '', $segment_two = '') { - if ( ! $this->_cache_init()) + if (! $this->_cache_init()) { return FALSE; } @@ -1055,7 +1055,7 @@ class CI_DB_driver { */ function cache_delete_all() { - if ( ! $this->_cache_init()) + if (! $this->_cache_init()) { return FALSE; } @@ -1078,7 +1078,7 @@ class CI_DB_driver { return TRUE; } - if ( ! @include(BASEPATH.'database/DB_cache'.EXT)) + if (! @include(BASEPATH.'database/DB_cache'.EXT)) { return $this->cache_off(); } @@ -1129,10 +1129,10 @@ class CI_DB_driver { } else { - $message = ( ! is_array($error)) ? array(str_replace('%s', $swap, $LANG->line($error))) : $error; + $message = (! is_array($error)) ? array(str_replace('%s', $swap, $LANG->line($error))) : $error; } - if ( ! class_exists('CI_Exceptions')) + if (! class_exists('CI_Exceptions')) { // include(BASEPATH.'core/Exceptions'.EXT); include(BASEPATH.'libraries/Exceptions'.EXT); diff --git a/system/database/DB_result.php b/system/database/DB_result.php index c2eeefb94..cfe9d2a32 100644 --- a/system/database/DB_result.php +++ b/system/database/DB_result.php @@ -125,10 +125,10 @@ class CI_DB_result { */ function row($n = 0, $type = 'object') { - if ( ! is_numeric($n)) + if (! is_numeric($n)) { // We cache the row data for subsequent uses - if ( ! is_array($this->row_data)) + if (! is_array($this->row_data)) { $this->row_data = $this->row_array(0); } @@ -156,7 +156,7 @@ class CI_DB_result { function set_row($key, $value = NULL) { // We cache the row data for subsequent uses - if ( ! is_array($this->row_data)) + if (! is_array($this->row_data)) { $this->row_data = $this->row_array(0); } diff --git a/system/database/DB_utility.php b/system/database/DB_utility.php index d9b8fed74..11f1fb4de 100644 --- a/system/database/DB_utility.php +++ b/system/database/DB_utility.php @@ -175,7 +175,7 @@ class CI_DB_utility extends CI_DB_forge { */ function csv_from_result($query, $delim = ",", $newline = "\n", $enclosure = '"') { - if ( ! is_object($query) OR ! method_exists($query, 'field_names')) + if (! is_object($query) OR ! method_exists($query, 'field_names')) { show_error('You must submit a valid result object'); } @@ -217,7 +217,7 @@ class CI_DB_utility extends CI_DB_forge { */ function xml_from_result($query, $params = array()) { - if ( ! is_object($query) OR ! method_exists($query, 'field_names')) + if (! is_object($query) OR ! method_exists($query, 'field_names')) { show_error('You must submit a valid result object'); } @@ -225,7 +225,7 @@ class CI_DB_utility extends CI_DB_forge { // Set our default values foreach (array('root' => 'root', 'element' => 'element', 'newline' => "\n", 'tab' => "\t") as $key => $val) { - if ( ! isset($params[$key])) + if (! isset($params[$key])) { $params[$key] = $val; } @@ -310,7 +310,7 @@ class CI_DB_utility extends CI_DB_forge { // ------------------------------------------------------ // Validate the format - if ( ! in_array($prefs['format'], array('gzip', 'zip', 'txt'), TRUE)) + if (! in_array($prefs['format'], array('gzip', 'zip', 'txt'), TRUE)) { $prefs['format'] = 'txt'; } @@ -367,7 +367,7 @@ class CI_DB_utility extends CI_DB_forge { } // Tack on the ".sql" file extension if needed - if ( ! preg_match("|.+?\.sql$|", $prefs['filename'])) + if (! preg_match("|.+?\.sql$|", $prefs['filename'])) { $prefs['filename'] .= '.sql'; } diff --git a/system/database/drivers/mssql/mssql_driver.php b/system/database/drivers/mssql/mssql_driver.php index 1ed333de0..6e67c57c0 100644 --- a/system/database/drivers/mssql/mssql_driver.php +++ b/system/database/drivers/mssql/mssql_driver.php @@ -132,7 +132,7 @@ class CI_DB_mssql_driver extends CI_DB { */ function trans_begin($test_mode = FALSE) { - if ( ! $this->trans_enabled) + if (! $this->trans_enabled) { return TRUE; } @@ -162,7 +162,7 @@ class CI_DB_mssql_driver extends CI_DB { */ function trans_commit() { - if ( ! $this->trans_enabled) + if (! $this->trans_enabled) { return TRUE; } @@ -187,7 +187,7 @@ class CI_DB_mssql_driver extends CI_DB { */ function trans_rollback() { - if ( ! $this->trans_enabled) + if (! $this->trans_enabled) { return TRUE; } diff --git a/system/database/drivers/mysql/mysql_driver.php b/system/database/drivers/mysql/mysql_driver.php index f435c0bc4..f15983d2b 100644 --- a/system/database/drivers/mysql/mysql_driver.php +++ b/system/database/drivers/mysql/mysql_driver.php @@ -161,7 +161,7 @@ class CI_DB_mysql_driver extends CI_DB { */ function trans_begin($test_mode = FALSE) { - if ( ! $this->trans_enabled) + if (! $this->trans_enabled) { return TRUE; } @@ -192,7 +192,7 @@ class CI_DB_mysql_driver extends CI_DB { */ function trans_commit() { - if ( ! $this->trans_enabled) + if (! $this->trans_enabled) { return TRUE; } @@ -218,7 +218,7 @@ class CI_DB_mysql_driver extends CI_DB { */ function trans_rollback() { - if ( ! $this->trans_enabled) + if (! $this->trans_enabled) { return TRUE; } diff --git a/system/database/drivers/mysqli/mysqli_driver.php b/system/database/drivers/mysqli/mysqli_driver.php index 6ff37f7e2..a196f755a 100644 --- a/system/database/drivers/mysqli/mysqli_driver.php +++ b/system/database/drivers/mysqli/mysqli_driver.php @@ -164,7 +164,7 @@ class CI_DB_mysqli_driver extends CI_DB { */ function trans_begin($test_mode = FALSE) { - if ( ! $this->trans_enabled) + if (! $this->trans_enabled) { return TRUE; } @@ -195,7 +195,7 @@ class CI_DB_mysqli_driver extends CI_DB { */ function trans_commit() { - if ( ! $this->trans_enabled) + if (! $this->trans_enabled) { return TRUE; } @@ -221,7 +221,7 @@ class CI_DB_mysqli_driver extends CI_DB { */ function trans_rollback() { - if ( ! $this->trans_enabled) + if (! $this->trans_enabled) { return TRUE; } diff --git a/system/database/drivers/oci8/oci8_driver.php b/system/database/drivers/oci8/oci8_driver.php index 364268b98..8fc20449f 100644 --- a/system/database/drivers/oci8/oci8_driver.php +++ b/system/database/drivers/oci8/oci8_driver.php @@ -155,7 +155,7 @@ class CI_DB_oci8_driver extends CI_DB { */ function _set_stmt_id($sql) { - if ( ! is_resource($this->stmt_id)) + if (! is_resource($this->stmt_id)) { $this->stmt_id = ociparse($this->conn_id, $this->_prep_query($sql)); } @@ -254,7 +254,7 @@ class CI_DB_oci8_driver extends CI_DB { */ function _bind_params($params) { - if ( ! is_array($params) OR ! is_resource($this->stmt_id)) + if (! is_array($params) OR ! is_resource($this->stmt_id)) { return; } @@ -263,7 +263,7 @@ class CI_DB_oci8_driver extends CI_DB { { foreach (array('name', 'value', 'type', 'length') as $val) { - if ( ! isset($param[$val])) + if (! isset($param[$val])) { $param[$val] = ''; } @@ -283,7 +283,7 @@ class CI_DB_oci8_driver extends CI_DB { */ function trans_begin($test_mode = FALSE) { - if ( ! $this->trans_enabled) + if (! $this->trans_enabled) { return TRUE; } @@ -313,7 +313,7 @@ class CI_DB_oci8_driver extends CI_DB { */ function trans_commit() { - if ( ! $this->trans_enabled) + if (! $this->trans_enabled) { return TRUE; } @@ -339,7 +339,7 @@ class CI_DB_oci8_driver extends CI_DB { */ function trans_rollback() { - if ( ! $this->trans_enabled) + if (! $this->trans_enabled) { return TRUE; } diff --git a/system/database/drivers/odbc/odbc_driver.php b/system/database/drivers/odbc/odbc_driver.php index 82fe36b5d..20e34ec7b 100644 --- a/system/database/drivers/odbc/odbc_driver.php +++ b/system/database/drivers/odbc/odbc_driver.php @@ -152,7 +152,7 @@ class CI_DB_odbc_driver extends CI_DB { */ function trans_begin($test_mode = FALSE) { - if ( ! $this->trans_enabled) + if (! $this->trans_enabled) { return TRUE; } @@ -181,7 +181,7 @@ class CI_DB_odbc_driver extends CI_DB { */ function trans_commit() { - if ( ! $this->trans_enabled) + if (! $this->trans_enabled) { return TRUE; } @@ -207,7 +207,7 @@ class CI_DB_odbc_driver extends CI_DB { */ function trans_rollback() { - if ( ! $this->trans_enabled) + if (! $this->trans_enabled) { return TRUE; } diff --git a/system/database/drivers/postgre/postgre_driver.php b/system/database/drivers/postgre/postgre_driver.php index 4eff97fcc..46ba1d009 100644 --- a/system/database/drivers/postgre/postgre_driver.php +++ b/system/database/drivers/postgre/postgre_driver.php @@ -150,7 +150,7 @@ class CI_DB_postgre_driver extends CI_DB { */ function trans_begin($test_mode = FALSE) { - if ( ! $this->trans_enabled) + if (! $this->trans_enabled) { return TRUE; } @@ -179,7 +179,7 @@ class CI_DB_postgre_driver extends CI_DB { */ function trans_commit() { - if ( ! $this->trans_enabled) + if (! $this->trans_enabled) { return TRUE; } @@ -203,7 +203,7 @@ class CI_DB_postgre_driver extends CI_DB { */ function trans_rollback() { - if ( ! $this->trans_enabled) + if (! $this->trans_enabled) { return TRUE; } diff --git a/system/database/drivers/sqlite/sqlite_driver.php b/system/database/drivers/sqlite/sqlite_driver.php index 2ad5d6120..70148f360 100644 --- a/system/database/drivers/sqlite/sqlite_driver.php +++ b/system/database/drivers/sqlite/sqlite_driver.php @@ -48,7 +48,7 @@ class CI_DB_sqlite_driver extends CI_DB { */ function db_connect() { - if ( ! $conn_id = @sqlite_open($this->database, FILE_WRITE_MODE, $error)) + if (! $conn_id = @sqlite_open($this->database, FILE_WRITE_MODE, $error)) { log_message('error', $error); @@ -73,7 +73,7 @@ class CI_DB_sqlite_driver extends CI_DB { */ function db_pconnect() { - if ( ! $conn_id = @sqlite_popen($this->database, FILE_WRITE_MODE, $error)) + if (! $conn_id = @sqlite_popen($this->database, FILE_WRITE_MODE, $error)) { log_message('error', $error); @@ -171,7 +171,7 @@ class CI_DB_sqlite_driver extends CI_DB { */ function trans_begin($test_mode = FALSE) { - if ( ! $this->trans_enabled) + if (! $this->trans_enabled) { return TRUE; } @@ -201,7 +201,7 @@ class CI_DB_sqlite_driver extends CI_DB { */ function trans_commit() { - if ( ! $this->trans_enabled) + if (! $this->trans_enabled) { return TRUE; } @@ -226,7 +226,7 @@ class CI_DB_sqlite_driver extends CI_DB { */ function trans_rollback() { - if ( ! $this->trans_enabled) + if (! $this->trans_enabled) { return TRUE; } diff --git a/system/database/drivers/sqlite/sqlite_forge.php b/system/database/drivers/sqlite/sqlite_forge.php index 1fd2a2bd4..44950bfc7 100644 --- a/system/database/drivers/sqlite/sqlite_forge.php +++ b/system/database/drivers/sqlite/sqlite_forge.php @@ -49,7 +49,7 @@ class CI_DB_sqlite_forge extends CI_DB_forge { */ function _drop_database($name) { - if ( ! @file_exists($this->db->database) OR ! @unlink($this->db->database)) + if (! @file_exists($this->db->database) OR ! @unlink($this->db->database)) { if ($this->db->db_debug) { diff --git a/system/database/drivers/sqlite/sqlite_utility.php b/system/database/drivers/sqlite/sqlite_utility.php index d1e1fe026..ab58f8fd7 100644 --- a/system/database/drivers/sqlite/sqlite_utility.php +++ b/system/database/drivers/sqlite/sqlite_utility.php @@ -124,7 +124,7 @@ class CI_DB_sqlite_utility extends CI_DB_utility { */ function _drop_database($name) { - if ( ! @file_exists($this->db->database) OR ! @unlink($this->db->database)) + if (! @file_exists($this->db->database) OR ! @unlink($this->db->database)) { if ($this->db->db_debug) { diff --git a/system/helpers/array_helper.php b/system/helpers/array_helper.php index 236e3904e..8ae44826a 100644 --- a/system/helpers/array_helper.php +++ b/system/helpers/array_helper.php @@ -43,7 +43,7 @@ if (! function_exists('element')) { function element($item, $array, $default = FALSE) { - if ( ! isset($array[$item]) OR $array[$item] == "") + if (! isset($array[$item]) OR $array[$item] == "") { return $default; } @@ -65,7 +65,7 @@ if (! function_exists('random_element')) { function random_element($array) { - if ( ! is_array($array)) + if (! is_array($array)) { return $array; } diff --git a/system/helpers/cookie_helper.php b/system/helpers/cookie_helper.php index 102057f8c..75c769e9c 100644 --- a/system/helpers/cookie_helper.php +++ b/system/helpers/cookie_helper.php @@ -73,7 +73,7 @@ if (! function_exists('set_cookie')) $path = $CI->config->item('cookie_path'); } - if ( ! is_numeric($expire)) + if (! is_numeric($expire)) { $expire = time() - 86500; } diff --git a/system/helpers/date_helper.php b/system/helpers/date_helper.php index 24e0b1794..004cfb122 100644 --- a/system/helpers/date_helper.php +++ b/system/helpers/date_helper.php @@ -123,7 +123,7 @@ if (! function_exists('standard_date')) 'DATE_W3C' => '%Y-%m-%dT%H:%i:%s%Q' ); - if ( ! isset($formats[$fmt])) + if (! isset($formats[$fmt])) { return FALSE; } @@ -152,12 +152,12 @@ if (! function_exists('timespan')) $CI =& get_instance(); $CI->lang->load('date'); - if ( ! is_numeric($seconds)) + if (! is_numeric($seconds)) { $seconds = 1; } - if ( ! is_numeric($time)) + if (! is_numeric($time)) { $time = time(); } @@ -271,7 +271,7 @@ if (! function_exists('days_in_month')) return 0; } - if ( ! is_numeric($year) OR strlen($year) != 4) + if (! is_numeric($year) OR strlen($year) != 4) { $year = date('Y'); } @@ -442,7 +442,7 @@ if (! function_exists('human_to_unix')) $datestr = trim($datestr); $datestr = preg_replace("/\040+/", "\040", $datestr); - if ( ! ereg("^[0-9]{2,4}\-[0-9]{1,2}\-[0-9]{1,2}\040[0-9]{1,2}:[0-9]{1,2}.*$", $datestr)) + if (! ereg("^[0-9]{2,4}\-[0-9]{1,2}\-[0-9]{1,2}\040[0-9]{1,2}:[0-9]{1,2}.*$", $datestr)) { return FALSE; } @@ -592,7 +592,7 @@ if (! function_exists('timezones')) if ($tz == 'GMT') $tz = 'UTC'; - return ( ! isset($zones[$tz])) ? 0 : $zones[$tz]; + return (! isset($zones[$tz])) ? 0 : $zones[$tz]; } } diff --git a/system/helpers/download_helper.php b/system/helpers/download_helper.php index 5e47fc5c9..284c6c96e 100644 --- a/system/helpers/download_helper.php +++ b/system/helpers/download_helper.php @@ -61,7 +61,7 @@ if (! function_exists('force_download')) @include(APPPATH.'config/mimes'.EXT); // Set a default mime if we can't find it - if ( ! isset($mimes[$extension])) + if (! isset($mimes[$extension])) { $mime = 'application/octet-stream'; } diff --git a/system/helpers/email_helper.php b/system/helpers/email_helper.php index e677afd28..307f3b588 100644 --- a/system/helpers/email_helper.php +++ b/system/helpers/email_helper.php @@ -37,7 +37,7 @@ if (! function_exists('valid_email')) { function valid_email($address) { - return ( ! preg_match("/^([a-z0-9\+_\-]+)(\.[a-z0-9\+_\-]+)*@([a-z0-9\-]+\.)+[a-z]{2,6}$/ix", $address)) ? FALSE : TRUE; + return (! preg_match("/^([a-z0-9\+_\-]+)(\.[a-z0-9\+_\-]+)*@([a-z0-9\-]+\.)+[a-z]{2,6}$/ix", $address)) ? FALSE : TRUE; } } diff --git a/system/helpers/file_helper.php b/system/helpers/file_helper.php index 04c5747bf..1eb8348e9 100644 --- a/system/helpers/file_helper.php +++ b/system/helpers/file_helper.php @@ -40,7 +40,7 @@ if (! function_exists('read_file')) { function read_file($file) { - if ( ! file_exists($file)) + if (! file_exists($file)) { return FALSE; } @@ -50,7 +50,7 @@ if (! function_exists('read_file')) return file_get_contents($file); } - if ( ! $fp = @fopen($file, 'rb')) + if (! $fp = @fopen($file, 'rb')) { return FALSE; } @@ -87,7 +87,7 @@ if (! function_exists('write_file')) { function write_file($path, $data, $mode = 'wb') { - if ( ! $fp = @fopen($path, $mode)) + if (! $fp = @fopen($path, $mode)) { return FALSE; } @@ -123,7 +123,7 @@ if (! function_exists('delete_files')) // Trim the trailing slash $path = preg_replace("|^(.+?)/*$|", "\\1", $path); - if ( ! $current_dir = @opendir($path)) + if (! $current_dir = @opendir($path)) return; while(FALSE !== ($filename = @readdir($current_dir))) @@ -167,7 +167,7 @@ if (! function_exists('get_filenames')) { function get_filenames($source_dir, $include_path = FALSE, $_recursion = FALSE) { - static $_filedata = array(); + $_filedata = array(); if ($fp = @opendir($source_dir)) { @@ -180,11 +180,11 @@ if (! function_exists('get_filenames')) while (FALSE !== ($file = readdir($fp))) { - if (@is_dir($source_dir.$file) && substr($file, 0, 1) != '.') + if (@is_dir($source_dir.$file) && strncmp($file, '.', 1) !== 0) { get_filenames($source_dir.$file.DIRECTORY_SEPARATOR, $include_path, TRUE); } - elseif (substr($file, 0, 1) != ".") + elseif (strncmp($file, '.', 1) !== 0) { $_filedata[] = ($include_path == TRUE) ? $source_dir.$file : $file; @@ -201,4 +201,171 @@ if (! function_exists('get_filenames')) // -------------------------------------------------------------------- +/** + * 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 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_dir_file_info')) +{ + function get_dir_file_info($source_dir, $include_path = FALSE, $_recursion = FALSE) + { + $_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; + } + + while (FALSE !== ($file = readdir($fp))) + { + if (@is_dir($source_dir.$file) && strncmp($file, '.', 1) !== 0) + { + get_dir_file_info($source_dir.$file.DIRECTORY_SEPARATOR, $include_path, 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 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, '/'), 1); + break; + case 'server_path': + $fileinfo['server_path'] = $file; + break; + case 'size': + $fileinfo['size'] = filesize($file); + break; + case 'date': + $fileinfo['date'] = filectime($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 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 = substr(strrchr($file, '.'), 1); + + global $mimes; + + if (! is_array($mimes)) + { + if (! require_once(APPPATH.'config/mimes.php')) + { + 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; + } + } +} + ?> \ No newline at end of file diff --git a/system/helpers/form_helper.php b/system/helpers/form_helper.php index db41cb5cd..10858339e 100644 --- a/system/helpers/form_helper.php +++ b/system/helpers/form_helper.php @@ -48,7 +48,7 @@ if (! function_exists('form_open')) $form = '
    '; } @@ -141,7 +141,7 @@ if (! function_exists('form_input')) { function form_input($data = '', $value = '', $extra = '') { - $defaults = array('type' => 'text', 'name' => (( ! is_array($data)) ? $data : ''), 'value' => $value, 'maxlength' => '500', 'size' => '50'); + $defaults = array('type' => 'text', 'name' => ((! is_array($data)) ? $data : ''), 'value' => $value, 'maxlength' => '500', 'size' => '50'); return "\n"; } @@ -164,7 +164,7 @@ if (! function_exists('form_password')) { function form_password($data = '', $value = '', $extra = '') { - if ( ! is_array($data)) + if (! is_array($data)) { $data = array('name' => $data); } @@ -191,7 +191,7 @@ if (! function_exists('form_upload')) { function form_upload($data = '', $value = '', $extra = '') { - if ( ! is_array($data)) + if (! is_array($data)) { $data = array('name' => $data); } @@ -216,9 +216,9 @@ if (! function_exists('form_textarea')) { function form_textarea($data = '', $value = '', $extra = '') { - $defaults = array('name' => (( ! is_array($data)) ? $data : ''), 'cols' => '90', 'rows' => '12'); + $defaults = array('name' => ((! is_array($data)) ? $data : ''), 'cols' => '90', 'rows' => '12'); - if ( ! is_array($data) OR ! isset($data['value'])) + if (! is_array($data) OR ! isset($data['value'])) { $val = $value; } @@ -248,7 +248,7 @@ if (! function_exists('form_dropdown')) { function form_dropdown($name = '', $options = array(), $selected = array(), $extra = '') { - if ( ! is_array($selected)) + if (! is_array($selected)) { $selected = array($selected); } @@ -291,7 +291,7 @@ if (! function_exists('form_checkbox')) { function form_checkbox($data = '', $value = '', $checked = TRUE, $extra = '') { - $defaults = array('type' => 'checkbox', 'name' => (( ! is_array($data)) ? $data : ''), 'value' => $value); + $defaults = array('type' => 'checkbox', 'name' => ((! is_array($data)) ? $data : ''), 'value' => $value); if (is_array($data) AND array_key_exists('checked', $data)) { @@ -332,7 +332,7 @@ if (! function_exists('form_radio')) { function form_radio($data = '', $value = '', $checked = TRUE, $extra = '') { - if ( ! is_array($data)) + if (! is_array($data)) { $data = array('name' => $data); } @@ -357,7 +357,7 @@ if (! function_exists('form_submit')) { function form_submit($data = '', $value = '', $extra = '') { - $defaults = array('type' => 'submit', 'name' => (( ! is_array($data)) ? $data : ''), 'value' => $value); + $defaults = array('type' => 'submit', 'name' => ((! is_array($data)) ? $data : ''), 'value' => $value); return "\n"; } @@ -378,7 +378,7 @@ if (! function_exists('form_reset')) { function form_reset($data = '', $value = '', $extra = '') { - $defaults = array('type' => 'reset', 'name' => (( ! is_array($data)) ? $data : ''), 'value' => $value); + $defaults = array('type' => 'reset', 'name' => ((! is_array($data)) ? $data : ''), 'value' => $value); return "\n"; } @@ -399,7 +399,7 @@ if (! function_exists('form_button')) { function form_button($data = '', $content = '', $extra = '') { - $defaults = array('name' => (( ! is_array($data)) ? $data : ''), 'type' => 'submit'); + $defaults = array('name' => ((! is_array($data)) ? $data : ''), 'type' => 'submit'); if ( is_array($data) AND isset($data['content'])) { diff --git a/system/helpers/html_helper.php b/system/helpers/html_helper.php index 3e15b4442..4e86465c1 100644 --- a/system/helpers/html_helper.php +++ b/system/helpers/html_helper.php @@ -105,7 +105,7 @@ 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)) + if (! is_array($list)) { return $list; } @@ -138,7 +138,7 @@ if (! function_exists('_list')) $out .= str_repeat(" ", $depth + 2); $out .= "
  • "; - if ( ! is_array($val)) + if (! is_array($val)) { $out .= $val; } @@ -194,7 +194,7 @@ if (! function_exists('img')) { function img($src = '', $index_page = FALSE) { - if ( ! is_array($src) ) + if (! is_array($src) ) { $src = array('src' => $src); } diff --git a/system/helpers/path_helper.php b/system/helpers/path_helper.php index 30d26d6ee..6abff06af 100644 --- a/system/helpers/path_helper.php +++ b/system/helpers/path_helper.php @@ -57,7 +57,7 @@ if (! function_exists('set_realpath')) // Make sure the path exists if ($check_existance == TRUE) { - if ( ! is_dir($path)) + if (! is_dir($path)) { show_error('Not a valid path: '.$path); } diff --git a/system/helpers/security_helper.php b/system/helpers/security_helper.php index 7552fd89c..edb6ebb50 100644 --- a/system/helpers/security_helper.php +++ b/system/helpers/security_helper.php @@ -59,9 +59,9 @@ if (! function_exists('dohash')) { if ($type == 'sha1') { - if ( ! function_exists('sha1')) + if (! function_exists('sha1')) { - if ( ! function_exists('mhash')) + if (! function_exists('mhash')) { require_once(BASEPATH.'libraries/Sha1'.EXT); $SH = new CI_SHA; diff --git a/system/helpers/smiley_helper.php b/system/helpers/smiley_helper.php index 25962eb54..81c6b9199 100644 --- a/system/helpers/smiley_helper.php +++ b/system/helpers/smiley_helper.php @@ -67,7 +67,7 @@ if (! function_exists('get_clickable_smileys')) { function get_clickable_smileys($image_url = '', $smileys = NULL) { - if ( ! is_array($smileys)) + if (! is_array($smileys)) { if (FALSE === ($smileys = _get_smiley_array())) { @@ -120,7 +120,7 @@ if (! function_exists('parse_smileys')) return $str; } - if ( ! is_array($smileys)) + if (! is_array($smileys)) { if (FALSE === ($smileys = _get_smiley_array())) { @@ -154,14 +154,14 @@ if (! function_exists('_get_smiley_array')) { function _get_smiley_array() { - if ( ! file_exists(APPPATH.'config/smileys'.EXT)) + if (! file_exists(APPPATH.'config/smileys'.EXT)) { return FALSE; } include(APPPATH.'config/smileys'.EXT); - if ( ! isset($smileys) OR ! is_array($smileys)) + if (! isset($smileys) OR ! is_array($smileys)) { return FALSE; } diff --git a/system/helpers/text_helper.php b/system/helpers/text_helper.php index 21ab77830..df3c89e6f 100644 --- a/system/helpers/text_helper.php +++ b/system/helpers/text_helper.php @@ -226,7 +226,7 @@ if (! function_exists('word_censor')) { function word_censor($str, $censored, $replacement = '') { - if ( ! is_array($censored)) + if (! is_array($censored)) { return $str; } @@ -354,7 +354,7 @@ if (! function_exists('word_wrap')) function word_wrap($str, $charlim = '76') { // Se the character limit - if ( ! is_numeric($charlim)) + if (! is_numeric($charlim)) $charlim = 76; // Reduce multiple spaces diff --git a/system/helpers/typography_helper.php b/system/helpers/typography_helper.php index 4d9a1bb6b..88071604d 100644 --- a/system/helpers/typography_helper.php +++ b/system/helpers/typography_helper.php @@ -330,13 +330,13 @@ class Auto_typography { $one_before = substr($str, $start+$current-1, 1); $one_after = substr($str, $start+$current+2, 1); - if ( ! in_array($one_after, $space, TRUE) && $one_after != "<") + if (! in_array($one_after, $space, TRUE) && $one_after != "<") { $str = str_replace( $one_before."\"'".$one_after, $one_before."“‘".$one_after, $str); } - elseif ( ! in_array($one_before, $space, TRUE) && (in_array($one_after, $space, TRUE) OR $one_after == '<')) + elseif (! in_array($one_before, $space, TRUE) && (in_array($one_after, $space, TRUE) OR $one_after == '<')) { $str = str_replace( $one_before."\"'".$one_after, $one_before."”’".$one_after, @@ -363,7 +363,7 @@ class Auto_typography { $one_before."‘“".$one_after, $str); } - elseif ( ! in_array($one_before, $space, TRUE) && $one_before != ">") + elseif (! in_array($one_before, $space, TRUE) && $one_before != ">") { $str = str_replace( $one_before."'\"".$one_after, $one_before."’”".$one_after, @@ -378,7 +378,7 @@ class Auto_typography { { for ($i=0, $s=sizeof($matches['0']); $i < $s; ++$i) { - if ( ! in_array($matches['1'][$i], $space, TRUE) && ! in_array($matches['3'][$i], $space, TRUE)) + if (! in_array($matches['1'][$i], $space, TRUE) && ! in_array($matches['3'][$i], $space, TRUE)) { $str = str_replace( $matches['0'][$i], $matches['1'][$i]."“".$matches['2'][$i]."”".$matches['3'][$i], @@ -391,7 +391,7 @@ class Auto_typography { { for ($i=0, $s=sizeof($matches['0']); $i < $s; ++$i) { - if ( ! in_array($matches['1'][$i], $space, TRUE) && ! in_array($matches['3'][$i], $space, TRUE)) + if (! in_array($matches['1'][$i], $space, TRUE) && ! in_array($matches['3'][$i], $space, TRUE)) { $str = str_replace( $matches['0'][$i], $matches['1'][$i]."‘".$matches['2'][$i]."’".$matches['3'][$i], @@ -412,7 +412,7 @@ class Auto_typography { $one_before = substr($str, $start+$current-1, 1); $one_after = substr($str, $start+$current+1, 1); - if ( ! in_array($one_before, $space, TRUE) && ! in_array($one_after, $space, TRUE)) + if (! in_array($one_before, $space, TRUE) && ! in_array($one_after, $space, TRUE)) { $str = str_replace( $one_before."'".$one_after, $one_before."’".$one_after, @@ -435,9 +435,9 @@ class Auto_typography { $two_before = substr($str, $start+$current-2, 1); $two_after = substr($str, $start+$current+3, 1); - if (( ! in_array($one_before, $space, TRUE) && ! in_array($one_after, $space, TRUE)) + if ((! in_array($one_before, $space, TRUE) && ! in_array($one_after, $space, TRUE)) OR - ( ! in_array($two_before, $space, TRUE) && ! in_array($two_after, $space, TRUE) && $one_before == ' ' && $one_after == ' ') + (! in_array($two_before, $space, TRUE) && ! in_array($two_after, $space, TRUE) && $one_before == ' ' && $one_after == ' ') ) { $str = str_replace( $two_before.$one_before."--".$one_after.$two_after, @@ -468,13 +468,13 @@ class Auto_typography { $one_before = substr($str, $start+$current-1, 1); $one_after = substr($str, $start+$current+1, 1); - if ( ! in_array($one_after, $space, TRUE)) + if (! in_array($one_after, $space, TRUE)) { $str = str_replace( $one_before.'"'.$one_after, $one_before."“".$one_after, $str); } - elseif( ! in_array($one_before, $space, TRUE)) + elseif(! in_array($one_before, $space, TRUE)) { $str = str_replace( $one_before."'".$one_after, $one_before."”".$one_after, @@ -495,13 +495,13 @@ class Auto_typography { $one_before = substr($str, $start+$current-1, 1); $one_after = substr($str, $start+$current+1, 1); - if ( ! in_array($one_after, $space, TRUE)) + if (! in_array($one_after, $space, TRUE)) { $str = str_replace( $one_before."'".$one_after, $one_before."‘".$one_after, $str); } - elseif( ! in_array($one_before, $space, TRUE)) + elseif(! in_array($one_before, $space, TRUE)) { $str = str_replace( $one_before."'".$one_after, $one_before."’".$one_after, diff --git a/system/helpers/url_helper.php b/system/helpers/url_helper.php index 1ff26082c..02c7f3379 100644 --- a/system/helpers/url_helper.php +++ b/system/helpers/url_helper.php @@ -103,9 +103,9 @@ if (! function_exists('anchor')) { $title = (string) $title; - if ( ! is_array($uri)) + if (! is_array($uri)) { - $site_url = ( ! preg_match('!^\w+://!i', $uri)) ? site_url($uri) : $uri; + $site_url = (! preg_match('!^\w+://!i', $uri)) ? site_url($uri) : $uri; } else { @@ -150,7 +150,7 @@ if (! function_exists('anchor_popup')) { $title = (string) $title; - $site_url = ( ! preg_match('!^\w+://!i', $uri)) ? site_url($uri) : $uri; + $site_url = (! preg_match('!^\w+://!i', $uri)) ? site_url($uri) : $uri; if ($title == '') { @@ -162,14 +162,14 @@ if (! function_exists('anchor_popup')) return "".$title.""; } - if ( ! is_array($attributes)) + 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]; + $atts[$key] = (! isset($attributes[$key])) ? $val : $attributes[$key]; } return "".$title.""; diff --git a/system/libraries/Benchmark.php b/system/libraries/Benchmark.php index bca37822b..323d9668d 100644 --- a/system/libraries/Benchmark.php +++ b/system/libraries/Benchmark.php @@ -71,12 +71,12 @@ class CI_Benchmark { return '{elapsed_time}'; } - if ( ! isset($this->marker[$point1])) + if (! isset($this->marker[$point1])) { return ''; } - if ( ! isset($this->marker[$point2])) + if (! isset($this->marker[$point2])) { $this->marker[$point2] = microtime(); } diff --git a/system/libraries/Calendar.php b/system/libraries/Calendar.php index a85c18303..e9621fec1 100644 --- a/system/libraries/Calendar.php +++ b/system/libraries/Calendar.php @@ -49,7 +49,7 @@ class CI_Calendar { { $this->CI =& get_instance(); - if ( ! in_array('calendar_lang'.EXT, $this->CI->lang->is_loaded, TRUE)) + if (! in_array('calendar_lang'.EXT, $this->CI->lang->is_loaded, TRUE)) { $this->CI->lang->load('calendar'); } @@ -125,7 +125,7 @@ class CI_Calendar { // Set the starting day of the week $start_days = array('sunday' => 0, 'monday' => 1, 'tuesday' => 2, 'wednesday' => 3, 'thursday' => 4, 'friday' => 5, 'saturday' => 6); - $start_day = ( ! isset($start_days[$this->start_day])) ? 0 : $start_days[$this->start_day]; + $start_day = (! isset($start_days[$this->start_day])) ? 0 : $start_days[$this->start_day]; // Set the starting day number $local_date = mktime(12, 0, 0, $month, 1, $year); diff --git a/system/libraries/Config.php b/system/libraries/Config.php index 9b8b07c5a..73f1986a0 100644 --- a/system/libraries/Config.php +++ b/system/libraries/Config.php @@ -66,7 +66,7 @@ class CI_Config { return TRUE; } - if ( ! file_exists(APPPATH.'config/'.$file.EXT)) + if (! file_exists(APPPATH.'config/'.$file.EXT)) { if ($fail_gracefully === TRUE) { @@ -77,7 +77,7 @@ class CI_Config { include(APPPATH.'config/'.$file.EXT); - if ( ! isset($config) OR ! is_array($config)) + if (! isset($config) OR ! is_array($config)) { if ($fail_gracefully === TRUE) { @@ -125,7 +125,7 @@ class CI_Config { { if ($index == '') { - if ( ! isset($this->config[$item])) + if (! isset($this->config[$item])) { return FALSE; } @@ -134,12 +134,12 @@ class CI_Config { } else { - if ( ! isset($this->config[$index])) + if (! isset($this->config[$index])) { return FALSE; } - if ( ! isset($this->config[$index][$item])) + if (! isset($this->config[$index][$item])) { return FALSE; } @@ -165,7 +165,7 @@ class CI_Config { */ function slash_item($item) { - if ( ! isset($this->config[$item])) + if (! isset($this->config[$item])) { return FALSE; } diff --git a/system/libraries/Controller.php b/system/libraries/Controller.php index ad9c66805..4957fc35e 100644 --- a/system/libraries/Controller.php +++ b/system/libraries/Controller.php @@ -111,7 +111,7 @@ class Controller extends CI_Base { show_404('Scaffolding unavailable'); } - $method = ( ! in_array($this->uri->segment(3), array('add', 'insert', 'edit', 'update', 'view', 'delete', 'do_delete'), TRUE)) ? 'view' : $this->uri->segment(3); + $method = (! in_array($this->uri->segment(3), array('add', 'insert', 'edit', 'update', 'view', 'delete', 'do_delete'), TRUE)) ? 'view' : $this->uri->segment(3); require_once(BASEPATH.'scaffolding/Scaffolding'.EXT); $scaff = new Scaffolding($this->_ci_scaff_table); diff --git a/system/libraries/Email.php b/system/libraries/Email.php index 19121c56b..3b4dddd00 100644 --- a/system/libraries/Email.php +++ b/system/libraries/Email.php @@ -371,7 +371,7 @@ class CI_Email { */ function _str_to_array($email) { - if ( ! is_array($email)) + if (! is_array($email)) { if (strpos($email, ',') !== FALSE) { @@ -439,7 +439,7 @@ class CI_Email { */ function set_protocol($protocol = 'mail') { - $this->protocol = ( ! in_array($protocol, $this->_protocols, TRUE)) ? 'mail' : strtolower($protocol); + $this->protocol = (! in_array($protocol, $this->_protocols, TRUE)) ? 'mail' : strtolower($protocol); } // -------------------------------------------------------------------- @@ -453,7 +453,7 @@ class CI_Email { */ function set_priority($n = 3) { - if ( ! is_numeric($n)) + if (! is_numeric($n)) { $this->priority = 3; return; @@ -551,7 +551,7 @@ class CI_Email { function _get_protocol($return = TRUE) { $this->protocol = strtolower($this->protocol); - $this->protocol = ( ! in_array($this->protocol, $this->_protocols, TRUE)) ? 'mail' : $this->protocol; + $this->protocol = (! in_array($this->protocol, $this->_protocols, TRUE)) ? 'mail' : $this->protocol; if ($return == TRUE) return $this->protocol; @@ -568,7 +568,7 @@ class CI_Email { */ function _get_encoding($return = TRUE) { - $this->_encoding = ( ! in_array($this->_encoding, $this->_bit_depths)) ? '8bit' : $this->_encoding; + $this->_encoding = (! in_array($this->_encoding, $this->_bit_depths)) ? '8bit' : $this->_encoding; foreach ($this->_base_charsets as $charset) { @@ -648,7 +648,7 @@ class CI_Email { */ function validate_email($email) { - if ( ! is_array($email)) + if (! is_array($email)) { $this->_set_error_message('email_must_be_array'); return FALSE; @@ -656,7 +656,7 @@ class CI_Email { foreach ($email as $val) { - if ( ! $this->valid_email($val)) + if (! $this->valid_email($val)) { $this->_set_error_message('email_invalid_address', $val); return FALSE; @@ -675,7 +675,7 @@ class CI_Email { */ function valid_email($address) { - return ( ! preg_match("/^([a-z0-9\+_\-]+)(\.[a-z0-9\+_\-]+)*@([a-z0-9\-]+\.)+[a-z]{2,6}$/ix", $address)) ? FALSE : TRUE; + return (! preg_match("/^([a-z0-9\+_\-]+)(\.[a-z0-9\+_\-]+)*@([a-z0-9\-]+\.)+[a-z]{2,6}$/ix", $address)) ? FALSE : TRUE; } // -------------------------------------------------------------------- @@ -689,7 +689,7 @@ class CI_Email { */ function clean_email($email) { - if ( ! is_array($email)) + if (! is_array($email)) { if (preg_match('/\<(.*)\>/', $email, $match)) return $match['1']; @@ -1055,7 +1055,7 @@ class CI_Email { $basename = basename($filename); $ctype = $this->_attach_type[$i]; - if ( ! file_exists($filename)) + if (! file_exists($filename)) { $this->_set_error_message('email_attachment_missing', $filename); return FALSE; @@ -1070,7 +1070,7 @@ class CI_Email { $attachment[$z++] = $h; $file = filesize($filename) +1; - if ( ! $fp = fopen($filename, 'r')) + if (! $fp = fopen($filename, 'r')) { $this->_set_error_message('email_attachment_unreadable', $filename); return FALSE; @@ -1194,9 +1194,9 @@ class CI_Email { $this->reply_to($this->_headers['From']); } - if (( ! isset($this->_recipients) AND ! isset($this->_headers['To'])) AND - ( ! isset($this->_bcc_array) AND ! isset($this->_headers['Bcc'])) AND - ( ! isset($this->_headers['Cc']))) + if ((! isset($this->_recipients) AND ! isset($this->_headers['To'])) AND + (! isset($this->_bcc_array) AND ! isset($this->_headers['Bcc'])) AND + (! isset($this->_headers['Cc']))) { $this->_set_error_message('email_no_recipients'); return FALSE; @@ -1212,7 +1212,7 @@ class CI_Email { $this->_build_message(); - if ( ! $this->_spool_email()) + if (! $this->_spool_email()) return FALSE; else return TRUE; @@ -1311,7 +1311,7 @@ class CI_Email { { case 'mail' : - if ( ! $this->_send_with_mail()) + if (! $this->_send_with_mail()) { $this->_set_error_message('email_send_failure_phpmail'); return FALSE; @@ -1319,7 +1319,7 @@ class CI_Email { break; case 'sendmail' : - if ( ! $this->_send_with_sendmail()) + if (! $this->_send_with_sendmail()) { $this->_set_error_message('email_send_failure_sendmail'); return FALSE; @@ -1327,7 +1327,7 @@ class CI_Email { break; case 'smtp' : - if ( ! $this->_send_with_smtp()) + if (! $this->_send_with_smtp()) { $this->_set_error_message('email_send_failure_smtp'); return FALSE; @@ -1352,7 +1352,7 @@ class CI_Email { { if ($this->_safe_mode == TRUE) { - if ( ! mail($this->_recipients, $this->_subject, $this->_finalbody, $this->_header_str)) + if (! mail($this->_recipients, $this->_subject, $this->_finalbody, $this->_header_str)) return FALSE; else return TRUE; @@ -1361,7 +1361,7 @@ class CI_Email { { // most documentation of sendmail using the "-f" flag lacks a space after it, however // we've encountered servers that seem to require it to be in place. - if ( ! mail($this->_recipients, $this->_subject, $this->_finalbody, $this->_header_str, "-f ".$this->clean_email($this->_headers['From']))) + if (! mail($this->_recipients, $this->_subject, $this->_finalbody, $this->_header_str, "-f ".$this->clean_email($this->_headers['From']))) return FALSE; else return TRUE; @@ -1380,7 +1380,7 @@ class CI_Email { { $fp = @popen($this->mailpath . " -oi -f ".$this->clean_email($this->_headers['From'])." -t", 'w'); - if ( ! is_resource($fp)) + if (! is_resource($fp)) { $this->_set_error_message('email_no_socket'); return FALSE; @@ -1472,7 +1472,7 @@ class CI_Email { $errstr, $this->smtp_timeout); - if( ! is_resource($this->_smtp_connect)) + if(! is_resource($this->_smtp_connect)) { $this->_set_error_message('email_smtp_error', $errno." ".$errstr); return FALSE; @@ -1557,7 +1557,7 @@ class CI_Email { */ function _smtp_authenticate() { - if ( ! $this->_smtp_auth) + if (! $this->_smtp_auth) return TRUE; if ($this->smtp_user == "" AND $this->smtp_pass == "") @@ -1609,7 +1609,7 @@ class CI_Email { */ function _send_data($data) { - if ( ! fwrite($this->_smtp_connect, $data . $this->newline)) + if (! fwrite($this->_smtp_connect, $data . $this->newline)) { $this->_set_error_message('email_smtp_data_failure', $data); return FALSE; @@ -1684,7 +1684,7 @@ class CI_Email { $this->_IP = end($x); } - if ( ! preg_match( "/^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$/", $this->_IP)) + if (! preg_match( "/^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$/", $this->_IP)) $this->_IP = '0.0.0.0'; unset($cip); @@ -1842,7 +1842,7 @@ class CI_Email { 'eml' => 'message/rfc822' ); - return ( ! isset($mimes[strtolower($ext)])) ? "application/x-unknown-content-type" : $mimes[strtolower($ext)]; + return (! isset($mimes[strtolower($ext)])) ? "application/x-unknown-content-type" : $mimes[strtolower($ext)]; } } diff --git a/system/libraries/Encrypt.php b/system/libraries/Encrypt.php index 48f9d3e51..9a784d254 100644 --- a/system/libraries/Encrypt.php +++ b/system/libraries/Encrypt.php @@ -44,7 +44,7 @@ class CI_Encrypt { function CI_Encrypt() { $this->CI =& get_instance(); - $this->_mcrypt_exists = ( ! function_exists('mcrypt_encrypt')) ? FALSE : TRUE; + $this->_mcrypt_exists = (! function_exists('mcrypt_encrypt')) ? FALSE : TRUE; log_message('debug', "Encrypt Class Initialized"); } @@ -459,9 +459,9 @@ class CI_Encrypt { */ function sha1($str) { - if ( ! function_exists('sha1')) + if (! function_exists('sha1')) { - if ( ! function_exists('mhash')) + if (! function_exists('mhash')) { require_once(BASEPATH.'libraries/Sha1'.EXT); $SH = new CI_SHA; diff --git a/system/libraries/Exceptions.php b/system/libraries/Exceptions.php index b22ef9f7a..7c9640554 100644 --- a/system/libraries/Exceptions.php +++ b/system/libraries/Exceptions.php @@ -74,7 +74,7 @@ class CI_Exceptions { */ function log_exception($severity, $message, $filepath, $line) { - $severity = ( ! isset($this->levels[$severity])) ? $severity : $this->levels[$severity]; + $severity = (! isset($this->levels[$severity])) ? $severity : $this->levels[$severity]; log_message('error', 'Severity: '.$severity.' --> '.$message. ' '.$filepath.' '.$line, TRUE); } @@ -115,7 +115,7 @@ class CI_Exceptions { */ function show_error($heading, $message, $template = 'error_general') { - $message = '

    '.implode('

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

    '; + $message = '

    '.implode('

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

    '; if (ob_get_level() > $this->ob_level + 1) { @@ -142,7 +142,7 @@ class CI_Exceptions { */ function show_php_error($severity, $message, $filepath, $line) { - $severity = ( ! isset($this->levels[$severity])) ? $severity : $this->levels[$severity]; + $severity = (! isset($this->levels[$severity])) ? $severity : $this->levels[$severity]; $filepath = str_replace("\\", "/", $filepath); diff --git a/system/libraries/Ftp.php b/system/libraries/Ftp.php index ed934b548..1b5ec2fd2 100644 --- a/system/libraries/Ftp.php +++ b/system/libraries/Ftp.php @@ -98,7 +98,7 @@ class CI_FTP { return FALSE; } - if ( ! $this->_login()) + if (! $this->_login()) { if ($this->debug == TRUE) { @@ -139,7 +139,7 @@ class CI_FTP { */ function _is_conn() { - if ( ! is_resource($this->conn_id)) + if (! is_resource($this->conn_id)) { if ($this->debug == TRUE) { @@ -216,7 +216,7 @@ class CI_FTP { } // Set file permissions if needed - if ( ! is_null($permissions)) + if (! is_null($permissions)) { $this->chmod($path, (int)$permissions); } @@ -237,12 +237,12 @@ class CI_FTP { */ function upload($locpath, $rempath, $mode = 'auto', $permissions = NULL) { - if ( ! $this->_is_conn()) + if (! $this->_is_conn()) { return FALSE; } - if ( ! file_exists($locpath)) + if (! file_exists($locpath)) { $this->_error('ftp_no_source_file'); return FALSE; @@ -270,7 +270,7 @@ class CI_FTP { } // Set file permissions if needed - if ( ! is_null($permissions)) + if (! is_null($permissions)) { $this->chmod($rempath, (int)$permissions); } @@ -291,7 +291,7 @@ class CI_FTP { */ function rename($old_file, $new_file, $move = FALSE) { - if ( ! $this->_is_conn()) + if (! $this->_is_conn()) { return FALSE; } @@ -338,7 +338,7 @@ class CI_FTP { */ function delete_file($filepath) { - if ( ! $this->_is_conn()) + if (! $this->_is_conn()) { return FALSE; } @@ -369,7 +369,7 @@ class CI_FTP { */ function delete_dir($filepath) { - if ( ! $this->_is_conn()) + if (! $this->_is_conn()) { return FALSE; } @@ -385,7 +385,7 @@ class CI_FTP { { // If we can't delete the item it's probaly a folder so // we'll recursively call delete_dir() - if ( ! @ftp_delete($this->conn_id, $filepath.$item)) + if (! @ftp_delete($this->conn_id, $filepath.$item)) { $this->delete_dir($filepath.$item); } @@ -418,13 +418,13 @@ class CI_FTP { */ function chmod($path, $perm) { - if ( ! $this->_is_conn()) + if (! $this->_is_conn()) { return FALSE; } // Permissions can only be set when running PHP 5 - if ( ! function_exists('ftp_chmod')) + if (! function_exists('ftp_chmod')) { if ($this->debug == TRUE) { @@ -457,7 +457,7 @@ class CI_FTP { */ function list_files($path = '.') { - if ( ! $this->_is_conn()) + if (! $this->_is_conn()) { return FALSE; } @@ -481,7 +481,7 @@ class CI_FTP { */ function mirror($locpath, $rempath) { - if ( ! $this->_is_conn()) + if (! $this->_is_conn()) { return FALSE; } @@ -490,10 +490,10 @@ class CI_FTP { if ($fp = @opendir($locpath)) { // Attempt to open the remote file path. - if ( ! $this->changedir($rempath, TRUE)) + if (! $this->changedir($rempath, TRUE)) { // If it doesn't exist we'll attempt to create the direcotory - if ( ! $this->mkdir($rempath) OR ! $this->changedir($rempath)) + if (! $this->mkdir($rempath) OR ! $this->changedir($rempath)) { return FALSE; } @@ -586,7 +586,7 @@ class CI_FTP { */ function close() { - if ( ! $this->_is_conn()) + if (! $this->_is_conn()) { return FALSE; } diff --git a/system/libraries/Hooks.php b/system/libraries/Hooks.php index 49cb230c0..a41320c5e 100644 --- a/system/libraries/Hooks.php +++ b/system/libraries/Hooks.php @@ -68,7 +68,7 @@ class CI_Hooks { @include(APPPATH.'config/hooks'.EXT); - if ( ! isset($hook) OR ! is_array($hook)) + if (! isset($hook) OR ! is_array($hook)) { return; } @@ -90,7 +90,7 @@ class CI_Hooks { */ function _call_hook($which = '') { - if ( ! $this->enabled OR ! isset($this->hooks[$which])) + if (! $this->enabled OR ! isset($this->hooks[$which])) { return FALSE; } @@ -123,7 +123,7 @@ class CI_Hooks { */ function _run_hook($data) { - if ( ! is_array($data)) + if (! is_array($data)) { return FALSE; } @@ -144,14 +144,14 @@ class CI_Hooks { // Set file path // ----------------------------------- - if ( ! isset($data['filepath']) OR ! isset($data['filename'])) + if (! isset($data['filepath']) OR ! isset($data['filename'])) { return FALSE; } $filepath = APPPATH.$data['filepath'].'/'.$data['filename']; - if ( ! file_exists($filepath)) + if (! file_exists($filepath)) { return FALSE; } @@ -196,7 +196,7 @@ class CI_Hooks { if ($class !== FALSE) { - if ( ! class_exists($class)) + if (! class_exists($class)) { require($filepath); } @@ -206,7 +206,7 @@ class CI_Hooks { } else { - if ( ! function_exists($function)) + if (! function_exists($function)) { require($filepath); } diff --git a/system/libraries/Image_lib.php b/system/libraries/Image_lib.php index 85435f6c9..c236e391e 100644 --- a/system/libraries/Image_lib.php +++ b/system/libraries/Image_lib.php @@ -158,7 +158,7 @@ class CI_Image_lib { * properties using ImageMagick and NetPBM * */ - if ( ! function_exists('getimagesize')) + if (! function_exists('getimagesize')) { $this->set_error('imglib_gd_required_for_props'); return FALSE; @@ -188,7 +188,7 @@ class CI_Image_lib { $this->source_folder = str_replace($this->source_image, '', $full_source_path); // Set the Image Properties - if ( ! $this->get_image_properties($this->source_folder.$this->source_image)) + if (! $this->get_image_properties($this->source_folder.$this->source_image)) { return FALSE; } @@ -226,7 +226,7 @@ class CI_Image_lib { } // Is there a file name? - if ( ! preg_match("#[\.jpg|\.jpeg|\.gif|\.png]$#i", $full_dest_path)) + if (! preg_match("#[\.jpg|\.jpeg|\.gif|\.png]$#i", $full_dest_path)) { $this->dest_folder = $full_dest_path.'/'; $this->dest_image = $this->source_image; @@ -478,7 +478,7 @@ class CI_Image_lib { // we'll simply make a copy of the original with the new name if (($this->orig_width == $this->width AND $this->orig_height == $this->height) AND ($this->source_image != $this->new_image)) { - if ( ! @copy($this->full_src_path, $this->full_dst_path)) + if (! @copy($this->full_src_path, $this->full_dst_path)) { $this->set_error('imglib_copy_failed'); return FALSE; @@ -494,7 +494,7 @@ class CI_Image_lib { } // Create the image handle - if ( ! ($src_img = $this->image_create_gd())) + if (! ($src_img = $this->image_create_gd())) { return FALSE; } @@ -528,7 +528,7 @@ class CI_Image_lib { else { // Or save it - if ( ! $this->image_save_gd($dst_img)) + if (! $this->image_save_gd($dst_img)) { return FALSE; } @@ -564,9 +564,9 @@ class CI_Image_lib { return FALSE; } - if ( ! eregi("convert$", $this->library_path)) + if (! eregi("convert$", $this->library_path)) { - if ( ! eregi("/$", $this->library_path)) $this->library_path .= "/"; + if (! eregi("/$", $this->library_path)) $this->library_path .= "/"; $this->library_path .= 'convert'; } @@ -712,14 +712,14 @@ class CI_Image_lib { { // Is Image Rotation Supported? // this function is only supported as of PHP 4.3 - if ( ! function_exists('imagerotate')) + if (! function_exists('imagerotate')) { $this->set_error('imglib_rotate_unsupported'); return FALSE; } // Create the image handle - if ( ! ($src_img = $this->image_create_gd())) + if (! ($src_img = $this->image_create_gd())) { return FALSE; } @@ -742,7 +742,7 @@ class CI_Image_lib { else { // Or save it - if ( ! $this->image_save_gd($dst_img)) + if (! $this->image_save_gd($dst_img)) { return FALSE; } @@ -771,7 +771,7 @@ class CI_Image_lib { */ function image_mirror_gd() { - if ( ! $src_img = $this->image_create_gd()) + if (! $src_img = $this->image_create_gd()) { return FALSE; } @@ -828,7 +828,7 @@ class CI_Image_lib { else { // Or save it - if ( ! $this->image_save_gd($src_img)) + if (! $this->image_save_gd($src_img)) { return FALSE; } @@ -877,7 +877,7 @@ class CI_Image_lib { */ function overlay_watermark() { - if ( ! function_exists('imagecolortransparent')) + if (! function_exists('imagecolortransparent')) { $this->set_error('imglib_gd_required'); return FALSE; @@ -955,7 +955,7 @@ class CI_Image_lib { } else { - if ( ! $this->image_save_gd($src_img)) + if (! $this->image_save_gd($src_img)) { return FALSE; } @@ -977,7 +977,7 @@ class CI_Image_lib { */ function text_watermark() { - if ( ! ($src_img = $this->image_create_gd())) + if (! ($src_img = $this->image_create_gd())) { return FALSE; } @@ -1131,7 +1131,7 @@ class CI_Image_lib { switch ($image_type) { case 1 : - if ( ! function_exists('imagecreatefromgif')) + if (! function_exists('imagecreatefromgif')) { $this->set_error(array('imglib_unsupported_imagecreate', 'imglib_gif_not_supported')); return FALSE; @@ -1140,7 +1140,7 @@ class CI_Image_lib { return imagecreatefromgif($path); break; case 2 : - if ( ! function_exists('imagecreatefromjpeg')) + if (! function_exists('imagecreatefromjpeg')) { $this->set_error(array('imglib_unsupported_imagecreate', 'imglib_jpg_not_supported')); return FALSE; @@ -1149,7 +1149,7 @@ class CI_Image_lib { return imagecreatefromjpeg($path); break; case 3 : - if ( ! function_exists('imagecreatefrompng')) + if (! function_exists('imagecreatefrompng')) { $this->set_error(array('imglib_unsupported_imagecreate', 'imglib_png_not_supported')); return FALSE; @@ -1181,7 +1181,7 @@ class CI_Image_lib { switch ($this->image_type) { case 1 : - if ( ! function_exists('imagegif')) + if (! function_exists('imagegif')) { $this->set_error(array('imglib_unsupported_imagecreate', 'imglib_gif_not_supported')); return FALSE; @@ -1190,7 +1190,7 @@ class CI_Image_lib { @imagegif($resource, $this->full_dst_path); break; case 2 : - if ( ! function_exists('imagejpeg')) + if (! function_exists('imagejpeg')) { $this->set_error(array('imglib_unsupported_imagecreate', 'imglib_jpg_not_supported')); return FALSE; @@ -1204,7 +1204,7 @@ class CI_Image_lib { @imagejpeg($resource, $this->full_dst_path, $this->quality); break; case 3 : - if ( ! function_exists('imagepng')) + if (! function_exists('imagepng')) { $this->set_error(array('imglib_unsupported_imagecreate', 'imglib_png_not_supported')); return FALSE; @@ -1267,10 +1267,10 @@ class CI_Image_lib { */ function image_reproportion() { - if ( ! is_numeric($this->width) OR ! is_numeric($this->height) OR $this->width == 0 OR $this->height == 0) + if (! is_numeric($this->width) OR ! is_numeric($this->height) OR $this->width == 0 OR $this->height == 0) return; - if ( ! is_numeric($this->orig_width) OR ! is_numeric($this->orig_height) OR $this->orig_width == 0 OR $this->orig_height == 0) + if (! is_numeric($this->orig_width) OR ! is_numeric($this->orig_height) OR $this->orig_width == 0 OR $this->orig_height == 0) return; $new_width = ceil($this->orig_width*$this->height/$this->orig_height); @@ -1315,7 +1315,7 @@ class CI_Image_lib { if ($path == '') $path = $this->full_src_path; - if ( ! file_exists($path)) + if (! file_exists($path)) { $this->set_error('imglib_invalid_path'); return FALSE; @@ -1369,14 +1369,14 @@ class CI_Image_lib { */ function size_calculator($vals) { - if ( ! is_array($vals)) + if (! is_array($vals)) return; $allowed = array('new_width', 'new_height', 'width', 'height'); foreach ($allowed as $item) { - if ( ! isset($vals[$item]) OR $vals[$item] == '') + if (! isset($vals[$item]) OR $vals[$item] == '') $vals[$item] = 0; } @@ -1447,9 +1447,9 @@ class CI_Image_lib { */ function gd_loaded() { - if ( ! extension_loaded('gd')) + if (! extension_loaded('gd')) { - if ( ! dl('gd.so')) + if (! dl('gd.so')) { return FALSE; } diff --git a/system/libraries/Input.php b/system/libraries/Input.php index 1c5682eb7..8a0478be2 100644 --- a/system/libraries/Input.php +++ b/system/libraries/Input.php @@ -76,9 +76,9 @@ class CI_Input { // This is effectively the same as register_globals = off foreach (array($_GET, $_POST, $_COOKIE, $_SERVER, $_FILES, $_ENV, (isset($_SESSION) && is_array($_SESSION)) ? $_SESSION : array()) as $global) { - if ( ! is_array($global)) + if (! is_array($global)) { - if ( ! in_array($global, $protected)) + if (! in_array($global, $protected)) { unset($GLOBALS[$global]); } @@ -87,7 +87,7 @@ class CI_Input { { foreach ($global as $key => $val) { - if ( ! in_array($key, $protected)) + if (! in_array($key, $protected)) { unset($GLOBALS[$key]); } @@ -96,7 +96,7 @@ class CI_Input { { foreach($val as $k => $v) { - if ( ! in_array($k, $protected)) + if (! in_array($k, $protected)) { unset($GLOBALS[$k]); } @@ -198,7 +198,7 @@ class CI_Input { */ function _clean_input_keys($str) { - if ( ! preg_match("/^[a-z0-9:_\/-]+$/i", $str)) + if (! preg_match("/^[a-z0-9:_\/-]+$/i", $str)) { exit('Disallowed Key Characters.'); } @@ -218,7 +218,7 @@ class CI_Input { */ function get($index = '', $xss_clean = FALSE) { - if ( ! isset($_GET[$index])) + if (! isset($_GET[$index])) { return FALSE; } @@ -253,7 +253,7 @@ class CI_Input { */ function post($index = '', $xss_clean = FALSE) { - if ( ! isset($_POST[$index])) + if (! isset($_POST[$index])) { return FALSE; } @@ -288,7 +288,7 @@ class CI_Input { */ function cookie($index = '', $xss_clean = FALSE) { - if ( ! isset($_COOKIE[$index])) + if (! isset($_COOKIE[$index])) { return FALSE; } @@ -328,7 +328,7 @@ class CI_Input { */ function server($index = '', $xss_clean = FALSE) { - if ( ! isset($_SERVER[$index])) + if (! isset($_SERVER[$index])) { return FALSE; } @@ -385,7 +385,7 @@ class CI_Input { $this->ip_address = end($x); } - if ( ! $this->valid_ip($this->ip_address)) + if (! $this->valid_ip($this->ip_address)) { $this->ip_address = '0.0.0.0'; } @@ -447,7 +447,7 @@ class CI_Input { return $this->user_agent; } - $this->user_agent = ( ! isset($_SERVER['HTTP_USER_AGENT'])) ? FALSE : $_SERVER['HTTP_USER_AGENT']; + $this->user_agent = (! isset($_SERVER['HTTP_USER_AGENT'])) ? FALSE : $_SERVER['HTTP_USER_AGENT']; return $this->user_agent; } diff --git a/system/libraries/Language.php b/system/libraries/Language.php index 3dac1a61f..a8e6366bb 100644 --- a/system/libraries/Language.php +++ b/system/libraries/Language.php @@ -83,7 +83,7 @@ class CI_Language { } - if ( ! isset($lang)) + if (! isset($lang)) { log_message('error', 'Language file contains no data: language/'.$idiom.'/'.$langfile); return; diff --git a/system/libraries/Loader.php b/system/libraries/Loader.php index 31e7d660f..5cf1f2ae6 100644 --- a/system/libraries/Loader.php +++ b/system/libraries/Loader.php @@ -152,7 +152,7 @@ class CI_Loader { $model = strtolower($model); - if ( ! file_exists(APPPATH.'models/'.$path.$model.EXT)) + if (! file_exists(APPPATH.'models/'.$path.$model.EXT)) { show_error('Unable to locate the model you have specified: '.$model); } @@ -165,7 +165,7 @@ class CI_Loader { $CI->load->database($db_conn, FALSE, TRUE); } - if ( ! class_exists('Model')) + if (! class_exists('Model')) { load_class('Model', FALSE); } @@ -230,7 +230,7 @@ class CI_Loader { */ function dbutil() { - if ( ! class_exists('CI_DB')) + if (! class_exists('CI_DB')) { $this->database(); } @@ -260,7 +260,7 @@ class CI_Loader { */ function dbforge() { - if ( ! class_exists('CI_DB')) + if (! class_exists('CI_DB')) { $this->database(); } @@ -353,7 +353,7 @@ class CI_Loader { */ function helper($helpers = array()) { - if ( ! is_array($helpers)) + if (! is_array($helpers)) { $helpers = array($helpers); } @@ -374,7 +374,7 @@ class CI_Loader { { $base_helper = BASEPATH.'helpers/'.$helper.EXT; - if ( ! file_exists($base_helper)) + if (! file_exists($base_helper)) { show_error('Unable to load the requested file: helpers/'.$helper.EXT); } @@ -435,7 +435,7 @@ class CI_Loader { */ function plugin($plugins = array()) { - if ( ! is_array($plugins)) + if (! is_array($plugins)) { $plugins = array($plugins); } @@ -505,7 +505,7 @@ class CI_Loader { */ function script($scripts = array()) { - if ( ! is_array($scripts)) + if (! is_array($scripts)) { $scripts = array($scripts); } @@ -519,7 +519,7 @@ class CI_Loader { continue; } - if ( ! file_exists(APPPATH.'scripts/'.$script.EXT)) + if (! file_exists(APPPATH.'scripts/'.$script.EXT)) { show_error('Unable to load the requested script: scripts/'.$script.EXT); } @@ -544,7 +544,7 @@ class CI_Loader { { $CI =& get_instance(); - if ( ! is_array($file)) + if (! is_array($file)) { $file = array($file); } @@ -630,7 +630,7 @@ class CI_Loader { // 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]; + $$_ci_val = (! isset($_ci_data[$_ci_val])) ? FALSE : $_ci_data[$_ci_val]; } // Set the path to the requested file @@ -646,7 +646,7 @@ class CI_Loader { $_ci_file = end($_ci_x); } - if ( ! file_exists($_ci_path)) + if (! file_exists($_ci_path)) { show_error('Unable to load the requested file: '.$_ci_file); } @@ -660,7 +660,7 @@ class CI_Loader { $_ci_CI =& get_instance(); foreach (get_object_vars($_ci_CI) as $_ci_key => $_ci_var) { - if ( ! isset($this->$_ci_key)) + if (! isset($this->$_ci_key)) { $this->$_ci_key =& $_ci_CI->$_ci_key; } @@ -768,7 +768,7 @@ class CI_Loader { { $baseclass = BASEPATH.'libraries/'.ucfirst($class).EXT; - if ( ! file_exists($baseclass)) + if (! file_exists($baseclass)) { log_message('error', "Unable to load the requested class: ".$class); show_error("Unable to load the requested class: ".$class); @@ -797,7 +797,7 @@ class CI_Loader { $filepath = $path.'libraries/'.$class.EXT; // Does the file exist? No? Bummer... - if ( ! file_exists($filepath)) + if (! file_exists($filepath)) { continue; } @@ -858,7 +858,7 @@ class CI_Loader { } // Set the variable name we will assign the class to - $classvar = ( ! isset($this->_ci_varmap[$class])) ? $class : $this->_ci_varmap[$class]; + $classvar = (! isset($this->_ci_varmap[$class])) ? $class : $this->_ci_varmap[$class]; // Instantiate the class $CI =& get_instance(); @@ -888,7 +888,7 @@ class CI_Loader { { include_once(APPPATH.'config/autoload'.EXT); - if ( ! isset($autoload)) + if (! isset($autoload)) { return FALSE; } @@ -916,7 +916,7 @@ class CI_Loader { // A little tweak to remain backward compatible // The $autoload['core'] item was deprecated - if ( ! isset($autoload['libraries'])) + if (! isset($autoload['libraries'])) { $autoload['libraries'] = $autoload['core']; } diff --git a/system/libraries/Log.php b/system/libraries/Log.php index 1aa8bd0f4..247aee13c 100644 --- a/system/libraries/Log.php +++ b/system/libraries/Log.php @@ -46,7 +46,7 @@ class CI_Log { $this->log_path = ($config['log_path'] != '') ? $config['log_path'] : BASEPATH.'logs/'; - if ( ! is_dir($this->log_path) OR ! is_really_writable($this->log_path)) + if (! is_dir($this->log_path) OR ! is_really_writable($this->log_path)) { $this->_enabled = FALSE; } @@ -84,7 +84,7 @@ class CI_Log { $level = strtoupper($level); - if ( ! isset($this->_levels[$level]) OR ($this->_levels[$level] > $this->_threshold)) + if (! isset($this->_levels[$level]) OR ($this->_levels[$level] > $this->_threshold)) { return FALSE; } @@ -92,12 +92,12 @@ class CI_Log { $filepath = $this->log_path.'log-'.date('Y-m-d').EXT; $message = ''; - if ( ! file_exists($filepath)) + if (! file_exists($filepath)) { $message .= "<"."?php if (!defined('BASEPATH')) exit('No direct script access allowed'); ?".">\n\n"; } - if ( ! $fp = @fopen($filepath, "a")) + if (! $fp = @fopen($filepath, "a")) { return FALSE; } diff --git a/system/libraries/Model.php b/system/libraries/Model.php index 8181ead32..e87d6045c 100644 --- a/system/libraries/Model.php +++ b/system/libraries/Model.php @@ -59,7 +59,7 @@ class Model { $CI =& get_instance(); foreach (array_keys(get_object_vars($CI)) as $key) { - if ( ! isset($this->$key) AND $key != $this->_parent_name) + if (! isset($this->$key) AND $key != $this->_parent_name) { // In some cases using references can cause // problems so we'll conditionally use them diff --git a/system/libraries/Output.php b/system/libraries/Output.php index 07990eb16..d513a1279 100644 --- a/system/libraries/Output.php +++ b/system/libraries/Output.php @@ -137,7 +137,7 @@ class CI_Output { */ function cache($time) { - $this->cache_expiration = ( ! is_numeric($time)) ? 0 : $time; + $this->cache_expiration = (! is_numeric($time)) ? 0 : $time; } // -------------------------------------------------------------------- @@ -187,7 +187,7 @@ class CI_Output { $elapsed = $BM->elapsed_time('total_execution_time_start', 'total_execution_time_end'); $output = str_replace('{elapsed_time}', $elapsed, $output); - $memory = ( ! function_exists('memory_get_usage')) ? '0' : round(memory_get_usage()/1024/1024, 2).'MB'; + $memory = (! function_exists('memory_get_usage')) ? '0' : round(memory_get_usage()/1024/1024, 2).'MB'; $output = str_replace('{memory_usage}', $memory, $output); // -------------------------------------------------------------------- @@ -220,7 +220,7 @@ class CI_Output { // Does the get_instance() function exist? // If not we know we are dealing with a cache file so we'll // simply echo out the data and exit. - if ( ! function_exists('get_instance')) + if (! function_exists('get_instance')) { echo $output; log_message('debug', "Final output sent to browser"); @@ -285,7 +285,7 @@ class CI_Output { $cache_path = ($path == '') ? BASEPATH.'cache/' : $path; - if ( ! is_dir($cache_path) OR ! is_really_writable($cache_path)) + if (! is_dir($cache_path) OR ! is_really_writable($cache_path)) { return; } @@ -296,7 +296,7 @@ class CI_Output { $cache_path .= md5($uri); - if ( ! $fp = @fopen($cache_path, 'wb')) + if (! $fp = @fopen($cache_path, 'wb')) { log_message('error', "Unable to write cache file: ".$cache_path); return; @@ -327,7 +327,7 @@ class CI_Output { $cache_path = ($CFG->item('cache_path') == '') ? BASEPATH.'cache/' : $CFG->item('cache_path'); - if ( ! is_dir($cache_path) OR ! is_really_writable($cache_path)) + if (! is_dir($cache_path) OR ! is_really_writable($cache_path)) { return FALSE; } @@ -339,12 +339,12 @@ class CI_Output { $filepath = $cache_path.md5($uri); - if ( ! @file_exists($filepath)) + if (! @file_exists($filepath)) { return FALSE; } - if ( ! $fp = @fopen($filepath, 'rb')) + if (! $fp = @fopen($filepath, 'rb')) { return FALSE; } @@ -361,7 +361,7 @@ class CI_Output { fclose($fp); // Strip out the embedded timestamp - if ( ! preg_match("/(\d+TS--->)/", $cache, $match)) + if (! preg_match("/(\d+TS--->)/", $cache, $match)) { return FALSE; } diff --git a/system/libraries/Pagination.php b/system/libraries/Pagination.php index 28b74f1f0..e1212035a 100644 --- a/system/libraries/Pagination.php +++ b/system/libraries/Pagination.php @@ -132,7 +132,7 @@ class CI_Pagination { show_error('Your number of links must be a positive number.'); } - if ( ! is_numeric($this->cur_page)) + if (! is_numeric($this->cur_page)) { $this->cur_page = 0; } diff --git a/system/libraries/Parser.php b/system/libraries/Parser.php index a0b310f00..417e04f29 100644 --- a/system/libraries/Parser.php +++ b/system/libraries/Parser.php @@ -130,7 +130,7 @@ class CI_Parser { $temp = $match['1']; foreach ($row as $key => $val) { - if ( ! is_array($val)) + if (! is_array($val)) { $temp = $this->_parse_single($key, $val, $temp); } @@ -158,7 +158,7 @@ class CI_Parser { */ function _match_pair($string, $variable) { - if ( ! preg_match("|".$this->l_delim . $variable . $this->r_delim."(.+)".$this->l_delim . '/' . $variable . $this->r_delim."|s", $string, $match)) + if (! preg_match("|".$this->l_delim . $variable . $this->r_delim."(.+)".$this->l_delim . '/' . $variable . $this->r_delim."|s", $string, $match)) { return FALSE; } diff --git a/system/libraries/Profiler.php b/system/libraries/Profiler.php index 8a45933e1..807c1aff6 100644 --- a/system/libraries/Profiler.php +++ b/system/libraries/Profiler.php @@ -106,7 +106,7 @@ class CI_Profiler { $output .= '
    '; $output .= "\n"; - if ( ! class_exists('CI_DB_driver')) + if (! class_exists('CI_DB_driver')) { $output .= '  '.$this->CI->lang->line('profiler_queries').'  '; $output .= "\n"; @@ -175,7 +175,7 @@ class CI_Profiler { foreach ($_GET as $key => $val) { - if ( ! is_numeric($key)) + if (! is_numeric($key)) { $key = "'".$key."'"; } @@ -225,7 +225,7 @@ class CI_Profiler { foreach ($_POST as $key => $val) { - if ( ! is_numeric($key)) + if (! is_numeric($key)) { $key = "'".$key."'"; } diff --git a/system/libraries/Router.php b/system/libraries/Router.php index 804e80bd2..6bb85518f 100644 --- a/system/libraries/Router.php +++ b/system/libraries/Router.php @@ -80,12 +80,12 @@ class CI_Router { // Load the routes.php file. @include(APPPATH.'config/routes'.EXT); - $this->routes = ( ! isset($route) OR ! is_array($route)) ? array() : $route; + $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']); + $this->default_controller = (! isset($this->routes['default_controller']) OR $this->routes['default_controller'] == '') ? FALSE : strtolower($this->routes['default_controller']); // Fetch the complete URI string $this->uri->_fetch_uri_string(); @@ -202,7 +202,7 @@ class CI_Router { if (count($segments) > 0) { // Does the requested controller exist in the sub-folder? - if ( ! file_exists(APPPATH.'controllers/'.$this->fetch_directory().$segments[0].EXT)) + if (! file_exists(APPPATH.'controllers/'.$this->fetch_directory().$segments[0].EXT)) { show_404($this->fetch_directory().$segments[0]); } @@ -213,7 +213,7 @@ class CI_Router { $this->set_method('index'); // Does the default controller exist in the sub-folder? - if ( ! file_exists(APPPATH.'controllers/'.$this->fetch_directory().$this->default_controller.EXT)) + if (! file_exists(APPPATH.'controllers/'.$this->fetch_directory().$this->default_controller.EXT)) { $this->directory = ''; return array(); diff --git a/system/libraries/Session.php b/system/libraries/Session.php index afa43348e..d4fdd3ac7 100644 --- a/system/libraries/Session.php +++ b/system/libraries/Session.php @@ -146,7 +146,7 @@ class CI_Session { * a new one. If it does, we'll update it. * */ - if ( ! $this->sess_read()) + if (! $this->sess_read()) { $this->sess_create(); } @@ -214,7 +214,7 @@ class CI_Session { $session = @unserialize($this->strip_slashes($session)); - if ( ! is_array($session) OR ! isset($session['last_activity'])) + if (! is_array($session) OR ! isset($session['last_activity'])) { log_message('error', 'The session cookie data did not contain a valid array. This could be a possible hacking attempt.'); return FALSE; @@ -439,7 +439,7 @@ class CI_Session { */ function userdata($item) { - return ( ! isset($this->userdata[$item])) ? FALSE : $this->userdata[$item]; + return (! isset($this->userdata[$item])) ? FALSE : $this->userdata[$item]; } // -------------------------------------------------------------------- @@ -452,7 +452,7 @@ class CI_Session { */ function all_userdata() { - return ( ! isset($this->userdata)) ? FALSE : $this->userdata; + return (! isset($this->userdata)) ? FALSE : $this->userdata; } // -------------------------------------------------------------------- diff --git a/system/libraries/Table.php b/system/libraries/Table.php index 439fe2ef9..38affa579 100644 --- a/system/libraries/Table.php +++ b/system/libraries/Table.php @@ -53,7 +53,7 @@ class CI_Table { */ function set_template($template) { - if ( ! is_array($template)) + if (! is_array($template)) { return FALSE; } @@ -93,7 +93,7 @@ class CI_Table { */ function make_columns($array = array(), $col_limit = 0) { - if ( ! is_array($array) OR count($array) == 0) + if (! is_array($array) OR count($array) == 0) { return FALSE; } @@ -187,7 +187,7 @@ class CI_Table { { // 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_null($table_data)) { if (is_object($table_data)) { @@ -246,7 +246,7 @@ class CI_Table { $i = 1; foreach($this->rows as $row) { - if ( ! is_array($row)) + if (! is_array($row)) { break; } @@ -309,7 +309,7 @@ class CI_Table { */ function _set_from_object($query) { - if ( ! is_object($query)) + if (! is_object($query)) { return FALSE; } @@ -317,7 +317,7 @@ class CI_Table { // First generate the headings from the table column names if (count($this->heading) == 0) { - if ( ! method_exists($query, 'list_fields')) + if (! method_exists($query, 'list_fields')) { return FALSE; } @@ -347,7 +347,7 @@ class CI_Table { */ function _set_from_array($data, $set_heading = TRUE) { - if ( ! is_array($data) OR count($data) == 0) + if (! is_array($data) OR count($data) == 0) { return FALSE; } @@ -355,7 +355,7 @@ class CI_Table { $i = 0; foreach ($data as $row) { - if ( ! is_array($row)) + if (! is_array($row)) { $this->rows[] = $data; break; @@ -394,7 +394,7 @@ class CI_Table { $this->temp = $this->_default_template(); foreach (array('table_open','heading_row_start', 'heading_row_end', 'heading_cell_start', 'heading_cell_end', '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])) + if (! isset($this->template[$val])) { $this->template[$val] = $this->temp[$val]; } diff --git a/system/libraries/Trackback.php b/system/libraries/Trackback.php index 5371e9050..3e1c20210 100644 --- a/system/libraries/Trackback.php +++ b/system/libraries/Trackback.php @@ -56,7 +56,7 @@ class CI_Trackback { */ function send($tb_data) { - if ( ! is_array($tb_data)) + if (! is_array($tb_data)) { $this->set_error('The send() method must be passed an array'); return FALSE; @@ -65,7 +65,7 @@ class CI_Trackback { // Pre-process the Trackback Data foreach (array('url', 'title', 'excerpt', 'blog_name', 'ping_url') as $item) { - if ( ! isset($tb_data[$item])) + if (! isset($tb_data[$item])) { $this->set_error('Required item missing: '.$item); return FALSE; @@ -102,7 +102,7 @@ class CI_Trackback { } // Build the Trackback data string - $charset = ( ! isset($tb_data['charset'])) ? $this->charset : $tb_data['charset']; + $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); @@ -139,13 +139,13 @@ class CI_Trackback { { foreach (array('url', 'title', 'blog_name', 'excerpt') as $val) { - if ( ! isset($_POST[$val]) OR $_POST[$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'])); + $this->data['charset'] = (! isset($_POST['charset'])) ? 'auto' : strtoupper(trim($_POST['charset'])); if ($val != 'url' && function_exists('mb_convert_encoding')) { @@ -212,7 +212,7 @@ class CI_Trackback { */ function data($item) { - return ( ! isset($this->data[$item])) ? '' : $this->data[$item]; + return (! isset($this->data[$item])) ? '' : $this->data[$item]; } // -------------------------------------------------------------------- @@ -233,14 +233,14 @@ class CI_Trackback { $target = parse_url($url); // Open the socket - if ( ! $fp = @fsockopen($target['host'], 80)) + if (! $fp = @fsockopen($target['host'], 80)) { $this->set_error('Invalid Connection: '.$url); return FALSE; } // Build the path - $ppath = ( ! isset($target['path'])) ? $url : $target['path']; + $ppath = (! isset($target['path'])) ? $url : $target['path']; $path = (isset($target['query']) && $target['query'] != "") ? $ppath.'?'.$target['query'] : $ppath; @@ -267,7 +267,7 @@ class CI_Trackback { } @fclose($fp); - if ( ! eregi("0", $this->response)) + if (! eregi("0", $this->response)) { $message = 'An unknown error was encountered'; @@ -360,7 +360,7 @@ class CI_Trackback { $tb_array = explode('/', $url); $tb_end = $tb_array[count($tb_array)-1]; - if ( ! is_numeric($tb_end)) + if (! is_numeric($tb_end)) { $tb_end = $tb_array[count($tb_array)-2]; } @@ -378,13 +378,13 @@ class CI_Trackback { $tb_array = explode('/', $url); $tb_id = $tb_array[count($tb_array)-1]; - if ( ! is_numeric($tb_id)) + if (! is_numeric($tb_id)) { $tb_id = $tb_array[count($tb_array)-2]; } } - if ( ! preg_match ("/^([0-9]+)$/", $tb_id)) + if (! preg_match ("/^([0-9]+)$/", $tb_id)) { return false; } diff --git a/system/libraries/URI.php b/system/libraries/URI.php index d10a5daeb..f0d02101a 100644 --- a/system/libraries/URI.php +++ b/system/libraries/URI.php @@ -133,7 +133,7 @@ class CI_URI { */ function _parse_request_uri() { - if ( ! isset($_SERVER['REQUEST_URI']) OR $_SERVER['REQUEST_URI'] == '') + if (! isset($_SERVER['REQUEST_URI']) OR $_SERVER['REQUEST_URI'] == '') { return ''; } @@ -185,7 +185,7 @@ class CI_URI { { if ($str != '' AND $this->config->item('permitted_uri_chars') != '') { - if ( ! preg_match("|^[".preg_quote($this->config->item('permitted_uri_chars'))."]+$|i", $str)) + if (! preg_match("|^[".preg_quote($this->config->item('permitted_uri_chars'))."]+$|i", $str)) { exit('The URI you submitted has disallowed characters.'); } @@ -278,7 +278,7 @@ class CI_URI { */ function segment($n, $no_result = FALSE) { - return ( ! isset($this->segments[$n])) ? $no_result : $this->segments[$n]; + return (! isset($this->segments[$n])) ? $no_result : $this->segments[$n]; } // -------------------------------------------------------------------- @@ -297,7 +297,7 @@ class CI_URI { */ function rsegment($n, $no_result = FALSE) { - return ( ! isset($this->rsegments[$n])) ? $no_result : $this->rsegments[$n]; + return (! isset($this->rsegments[$n])) ? $no_result : $this->rsegments[$n]; } // -------------------------------------------------------------------- @@ -360,7 +360,7 @@ class CI_URI { $segment_array = 'rsegment_array'; } - if ( ! is_numeric($n)) + if (! is_numeric($n)) { return $default; } @@ -409,7 +409,7 @@ class CI_URI { { foreach ($default as $val) { - if ( ! array_key_exists($val, $retval)) + if (! array_key_exists($val, $retval)) { $retval[$val] = FALSE; } diff --git a/system/libraries/Unit_test.php b/system/libraries/Unit_test.php index ff4d0c7ed..3cdf45f12 100644 --- a/system/libraries/Unit_test.php +++ b/system/libraries/Unit_test.php @@ -260,8 +260,8 @@ class CI_Unit_test { { $back = debug_backtrace(); - $file = ( ! isset($back['1']['file'])) ? '' : $back['1']['file']; - $line = ( ! isset($back['1']['line'])) ? '' : $back['1']['line']; + $file = (! isset($back['1']['file'])) ? '' : $back['1']['file']; + $line = (! isset($back['1']['line'])) ? '' : $back['1']['line']; return array('file' => $file, 'line' => $line); } @@ -300,7 +300,7 @@ class CI_Unit_test { */ function _parse_template() { - if ( ! is_null($this->_template_rows)) + if (! is_null($this->_template_rows)) { return; } @@ -311,7 +311,7 @@ class CI_Unit_test { return; } - if ( ! preg_match("/\{rows\}(.*?)\{\/rows\}/si", $this->_template, $match)) + if (! preg_match("/\{rows\}(.*?)\{\/rows\}/si", $this->_template, $match)) { $this->_default_template(); return; diff --git a/system/libraries/Upload.php b/system/libraries/Upload.php index 760d93999..f13907000 100644 --- a/system/libraries/Upload.php +++ b/system/libraries/Upload.php @@ -135,23 +135,23 @@ class CI_Upload { function do_upload($field = 'userfile') { // Is $_FILES[$field] set? If not, no reason to continue. - if ( ! isset($_FILES[$field])) + if (! isset($_FILES[$field])) { $this->set_error('upload_no_file_selected'); return FALSE; } // Is the upload path valid? - if ( ! $this->validate_upload_path()) + if (! $this->validate_upload_path()) { $this->set_error('upload_no_filepath'); return FALSE; } // Was the file able to be uploaded? If not, determine the reason why. - if ( ! is_uploaded_file($_FILES[$field]['tmp_name'])) + if (! is_uploaded_file($_FILES[$field]['tmp_name'])) { - $error = ( ! isset($_FILES[$field]['error'])) ? 4 : $_FILES[$field]['error']; + $error = (! isset($_FILES[$field]['error'])) ? 4 : $_FILES[$field]['error']; switch($error) { @@ -198,14 +198,14 @@ class CI_Upload { } // Is the file type allowed to be uploaded? - if ( ! $this->is_allowed_filetype()) + if (! $this->is_allowed_filetype()) { $this->set_error('upload_invalid_filetype'); return FALSE; } // Is the file size within the allowed maximum? - if ( ! $this->is_allowed_filesize()) + if (! $this->is_allowed_filesize()) { $this->set_error('upload_invalid_filesize'); return FALSE; @@ -213,7 +213,7 @@ class CI_Upload { // Are the image dimensions within the allowed size? // Note: This can fail if the server has an open_basdir restriction. - if ( ! $this->is_allowed_dimensions()) + if (! $this->is_allowed_dimensions()) { $this->set_error('upload_invalid_dimensions'); return FALSE; @@ -253,9 +253,9 @@ class CI_Upload { * we'll use move_uploaded_file(). One of the two should * reliably work in most environments */ - if ( ! @copy($this->file_temp, $this->upload_path.$this->file_name)) + if (! @copy($this->file_temp, $this->upload_path.$this->file_name)) { - if ( ! @move_uploaded_file($this->file_temp, $this->upload_path.$this->file_name)) + if (! @move_uploaded_file($this->file_temp, $this->upload_path.$this->file_name)) { $this->set_error('upload_destination_error'); return FALSE; @@ -350,7 +350,7 @@ class CI_Upload { $filename = md5(uniqid(mt_rand())).$this->file_ext; } - if ( ! file_exists($path.$filename)) + if (! file_exists($path.$filename)) { return $filename; } @@ -360,7 +360,7 @@ class CI_Upload { $new_filename = ''; for ($i = 1; $i < 100; $i++) { - if ( ! file_exists($path.$filename.$i.$this->file_ext)) + if (! file_exists($path.$filename.$i.$this->file_ext)) { $new_filename = $filename.$i.$this->file_ext; break; @@ -389,7 +389,7 @@ class CI_Upload { */ function set_max_filesize($n) { - $this->max_size = ( ! eregi("^[[:digit:]]+$", $n)) ? 0 : $n; + $this->max_size = (! eregi("^[[:digit:]]+$", $n)) ? 0 : $n; } // -------------------------------------------------------------------- @@ -403,7 +403,7 @@ class CI_Upload { */ function set_max_width($n) { - $this->max_width = ( ! eregi("^[[:digit:]]+$", $n)) ? 0 : $n; + $this->max_width = (! eregi("^[[:digit:]]+$", $n)) ? 0 : $n; } // -------------------------------------------------------------------- @@ -417,7 +417,7 @@ class CI_Upload { */ function set_max_height($n) { - $this->max_height = ( ! eregi("^[[:digit:]]+$", $n)) ? 0 : $n; + $this->max_height = (! eregi("^[[:digit:]]+$", $n)) ? 0 : $n; } // -------------------------------------------------------------------- @@ -447,7 +447,7 @@ class CI_Upload { */ function set_image_properties($path = '') { - if ( ! $this->is_image()) + if (! $this->is_image()) { return; } @@ -460,7 +460,7 @@ class CI_Upload { $this->image_width = $D['0']; $this->image_height = $D['1']; - $this->image_type = ( ! isset($types[$D['2']])) ? 'unknown' : $types[$D['2']]; + $this->image_type = (! isset($types[$D['2']])) ? 'unknown' : $types[$D['2']]; $this->image_size_str = $D['3']; // string containing height and width } } @@ -587,7 +587,7 @@ class CI_Upload { */ function is_allowed_dimensions() { - if ( ! $this->is_image()) + if (! $this->is_image()) { return TRUE; } @@ -636,13 +636,13 @@ class CI_Upload { $this->upload_path = str_replace("\\", "/", realpath($this->upload_path)); } - if ( ! @is_dir($this->upload_path)) + if (! @is_dir($this->upload_path)) { $this->set_error('upload_no_filepath'); return FALSE; } - if ( ! is_really_writable($this->upload_path)) + if (! is_really_writable($this->upload_path)) { $this->set_error('upload_not_writable'); return FALSE; @@ -741,7 +741,7 @@ class CI_Upload { return FALSE; } - if ( ! $fp = @fopen($file, 'r+b')) + if (! $fp = @fopen($file, 'r+b')) { return FALSE; } @@ -830,7 +830,7 @@ class CI_Upload { } } - return ( ! isset($this->mimes[$mime])) ? FALSE : $this->mimes[$mime]; + return (! isset($this->mimes[$mime])) ? FALSE : $this->mimes[$mime]; } /** diff --git a/system/libraries/User_agent.php b/system/libraries/User_agent.php index ff6d4a933..dd60a56a1 100644 --- a/system/libraries/User_agent.php +++ b/system/libraries/User_agent.php @@ -63,7 +63,7 @@ class CI_User_agent { $this->agent = trim($_SERVER['HTTP_USER_AGENT']); } - if ( ! is_null($this->agent)) + if (! is_null($this->agent)) { if ($this->_load_agent_file()) { @@ -84,7 +84,7 @@ class CI_User_agent { */ function _load_agent_file() { - if ( ! @include(APPPATH.'config/user_agents'.EXT)) + if (! @include(APPPATH.'config/user_agents'.EXT)) { return FALSE; } @@ -339,7 +339,7 @@ class CI_User_agent { */ function is_referral() { - return ( ! isset($_SERVER['HTTP_REFERER']) OR $_SERVER['HTTP_REFERER'] == '') ? FALSE : TRUE; + return (! isset($_SERVER['HTTP_REFERER']) OR $_SERVER['HTTP_REFERER'] == '') ? FALSE : TRUE; } // -------------------------------------------------------------------- @@ -429,7 +429,7 @@ class CI_User_agent { */ function referrer() { - return ( ! isset($_SERVER['HTTP_REFERER']) OR $_SERVER['HTTP_REFERER'] == '') ? '' : trim($_SERVER['HTTP_REFERER']); + return (! isset($_SERVER['HTTP_REFERER']) OR $_SERVER['HTTP_REFERER'] == '') ? '' : trim($_SERVER['HTTP_REFERER']); } // -------------------------------------------------------------------- diff --git a/system/libraries/Validation.php b/system/libraries/Validation.php index 18fdba2d3..16e8cd74f 100644 --- a/system/libraries/Validation.php +++ b/system/libraries/Validation.php @@ -74,7 +74,7 @@ class CI_Validation { } else { - if ( ! is_array($data)) + if (! is_array($data)) { $data = array($data => $field); } @@ -87,10 +87,10 @@ class CI_Validation { foreach($this->_fields as $key => $val) { - $this->$key = ( ! isset($_POST[$key])) ? '' : $this->prep_for_form($_POST[$key]); + $this->$key = (! isset($_POST[$key])) ? '' : $this->prep_for_form($_POST[$key]); $error = $key.'_error'; - if ( ! isset($this->$error)) + if (! isset($this->$error)) { $this->$error = ''; } @@ -112,7 +112,7 @@ class CI_Validation { */ function set_rules($data, $rules = '') { - if ( ! is_array($data)) + if (! is_array($data)) { if ($rules == '') return; @@ -141,7 +141,7 @@ class CI_Validation { */ function set_message($lang, $val = '') { - if ( ! is_array($lang)) + if (! is_array($lang)) { $lang = array($lang => $val); } @@ -195,9 +195,9 @@ class CI_Validation { $ex = explode('|', $rules); // Is the field required? If not, if the field is blank we'll move on to the next test - if ( ! in_array('required', $ex, TRUE)) + if (! in_array('required', $ex, TRUE)) { - if ( ! isset($_POST[$field]) OR $_POST[$field] == '') + if (! isset($_POST[$field]) OR $_POST[$field] == '') { continue; } @@ -212,11 +212,11 @@ class CI_Validation { * test for it here since there's not reason to go * further */ - if ( ! isset($_POST[$field])) + if (! isset($_POST[$field])) { if (in_array('isset', $ex, TRUE) OR in_array('required', $ex)) { - if ( ! isset($this->_error_messages['isset'])) + if (! isset($this->_error_messages['isset'])) { if (FALSE === ($line = $this->CI->lang->line('isset'))) { @@ -229,7 +229,7 @@ class CI_Validation { } // Build the error message - $mfield = ( ! isset($this->_fields[$field])) ? $field : $this->_fields[$field]; + $mfield = (! isset($this->_fields[$field])) ? $field : $this->_fields[$field]; $message = sprintf($line, $mfield); // Set the error variable. Example: $this->username_error @@ -274,7 +274,7 @@ class CI_Validation { // Call the function that corresponds to the rule if ($callback === TRUE) { - if ( ! method_exists($this->CI, $rule)) + if (! method_exists($this->CI, $rule)) { continue; } @@ -282,7 +282,7 @@ class CI_Validation { $result = $this->CI->$rule($_POST[$field], $param); // If the field isn't required and we just processed a callback we'll move on... - if ( ! in_array('required', $ex, TRUE) AND $result !== FALSE) + if (! in_array('required', $ex, TRUE) AND $result !== FALSE) { continue 2; } @@ -290,7 +290,7 @@ class CI_Validation { } else { - if ( ! method_exists($this, $rule)) + if (! method_exists($this, $rule)) { /* * Run the native PHP function if called for @@ -314,7 +314,7 @@ class CI_Validation { // Did the rule test negatively? If so, grab the error. if ($result === FALSE) { - if ( ! isset($this->_error_messages[$rule])) + if (! isset($this->_error_messages[$rule])) { if (FALSE === ($line = $this->CI->lang->line($rule))) { @@ -327,8 +327,8 @@ class CI_Validation { } // Build the error message - $mfield = ( ! isset($this->_fields[$field])) ? $field : $this->_fields[$field]; - $mparam = ( ! isset($this->_fields[$param])) ? $param : $this->_fields[$param]; + $mfield = (! isset($this->_fields[$field])) ? $field : $this->_fields[$field]; + $mparam = (! isset($this->_fields[$param])) ? $param : $this->_fields[$param]; $message = sprintf($line, $mfield, $mparam); // Set the error variable. Example: $this->username_error @@ -385,13 +385,13 @@ class CI_Validation { */ function required($str) { - if ( ! is_array($str)) + if (! is_array($str)) { return (trim($str) == '') ? FALSE : TRUE; } else { - return ( ! empty($str)); + return (! empty($str)); } } @@ -406,7 +406,7 @@ class CI_Validation { */ function matches($str, $field) { - if ( ! isset($_POST[$field])) + if (! isset($_POST[$field])) { return FALSE; } @@ -482,7 +482,7 @@ class CI_Validation { */ function valid_email($str) { - return ( ! preg_match("/^([a-z0-9\+_\-]+)(\.[a-z0-9\+_\-]+)*@([a-z0-9\-]+\.)+[a-z]{2,6}$/ix", $str)) ? FALSE : TRUE; + return (! preg_match("/^([a-z0-9\+_\-]+)(\.[a-z0-9\+_\-]+)*@([a-z0-9\-]+\.)+[a-z]{2,6}$/ix", $str)) ? FALSE : TRUE; } // -------------------------------------------------------------------- @@ -537,7 +537,7 @@ class CI_Validation { */ function alpha($str) { - return ( ! preg_match("/^([a-z])+$/i", $str)) ? FALSE : TRUE; + return (! preg_match("/^([a-z])+$/i", $str)) ? FALSE : TRUE; } // -------------------------------------------------------------------- @@ -551,7 +551,7 @@ class CI_Validation { */ function alpha_numeric($str) { - return ( ! preg_match("/^([a-z0-9])+$/i", $str)) ? FALSE : TRUE; + return (! preg_match("/^([a-z0-9])+$/i", $str)) ? FALSE : TRUE; } // -------------------------------------------------------------------- @@ -565,7 +565,7 @@ class CI_Validation { */ function alpha_dash($str) { - return ( ! preg_match("/^([-a-z0-9_-])+$/i", $str)) ? FALSE : TRUE; + return (! preg_match("/^([-a-z0-9_-])+$/i", $str)) ? FALSE : TRUE; } // -------------------------------------------------------------------- @@ -594,7 +594,7 @@ class CI_Validation { */ function is_numeric($str) { - return ( ! is_numeric($str)) ? FALSE : TRUE; + return (! is_numeric($str)) ? FALSE : TRUE; } // -------------------------------------------------------------------- diff --git a/system/libraries/Xmlrpc.php b/system/libraries/Xmlrpc.php index f90ee56b1..f8ad01714 100644 --- a/system/libraries/Xmlrpc.php +++ b/system/libraries/Xmlrpc.php @@ -13,7 +13,7 @@ * @filesource */ -if ( ! function_exists('xml_parser_create')) +if (! function_exists('xml_parser_create')) { show_error('Your PHP installation does not support XML'); } @@ -176,7 +176,7 @@ class CI_Xmlrpc { function timeout($seconds=5) { - if ( ! is_null($this->client) && is_int($seconds)) + if (! is_null($this->client) && is_int($seconds)) { $this->client->timeout = $seconds; } @@ -199,7 +199,7 @@ class CI_Xmlrpc { function request($incoming) { - if ( ! is_array($incoming)) + if (! is_array($incoming)) { // Send Error } @@ -231,7 +231,7 @@ class CI_Xmlrpc { { if (is_array($value) && isset($value['0'])) { - if ( ! isset($value['1']) OR ! isset($this->xmlrpcTypes[strtolower($value['1'])])) + if (! isset($value['1']) OR ! isset($this->xmlrpcTypes[strtolower($value['1'])])) { if (is_array($value[0])) { @@ -275,12 +275,12 @@ class CI_Xmlrpc { $this->message = new XML_RPC_Message($this->method,$this->data); $this->message->debug = $this->debug; - if ( ! $this->result = $this->client->send($this->message)) + if (! $this->result = $this->client->send($this->message)) { $this->error = $this->result->errstr; return FALSE; } - elseif( ! is_object($this->result->val)) + elseif(! is_object($this->result->val)) { $this->error = $this->result->errstr; return FALSE; @@ -765,7 +765,7 @@ class XML_RPC_Message extends CI_Xmlrpc $r = new XML_RPC_Response(0, $this->xmlrpcerr['invalid_return'],$this->xmlrpcstr['invalid_return'].' '.$this->xh[$parser]['isf_reason']); return $r; } - elseif ( ! is_object($this->xh[$parser]['value'])) + elseif (! is_object($this->xh[$parser]['value'])) { $r = new XML_RPC_Response(0, $this->xmlrpcerr['invalid_return'],$this->xmlrpcstr['invalid_return'].' '.$this->xh[$parser]['isf_reason']); return $r; @@ -961,7 +961,7 @@ class XML_RPC_Message extends CI_Xmlrpc case 'STRUCT': case 'ARRAY': $cur_val = array_shift($this->xh[$the_parser]['valuestack']); - $this->xh[$the_parser]['value'] = ( ! isset($cur_val['values'])) ? array() : $cur_val['values']; + $this->xh[$the_parser]['value'] = (! isset($cur_val['values'])) ? array() : $cur_val['values']; $this->xh[$the_parser]['vt'] = strtolower($name); break; case 'NAME': @@ -1101,7 +1101,7 @@ class XML_RPC_Message extends CI_Xmlrpc $this->xh[$the_parser]['lv'] = 2; // Found a value } - if( ! @isset($this->xh[$the_parser]['ac'])) + if(! @isset($this->xh[$the_parser]['ac'])) { $this->xh[$the_parser]['ac'] = ''; } diff --git a/system/libraries/Xmlrpcs.php b/system/libraries/Xmlrpcs.php index ac644d894..1b2ffca05 100644 --- a/system/libraries/Xmlrpcs.php +++ b/system/libraries/Xmlrpcs.php @@ -13,12 +13,12 @@ * @filesource */ -if ( ! function_exists('xml_parser_create')) +if (! function_exists('xml_parser_create')) { show_error('Your PHP installation does not support XML'); } -if ( ! class_exists('CI_Xmlrpc')) +if (! class_exists('CI_Xmlrpc')) { show_error('You must load the Xmlrpc class before loading the Xmlrpcs class in order to create a server.'); } @@ -176,7 +176,7 @@ class CI_Xmlrpcs extends CI_Xmlrpc // PARSE + PROCESS XML DATA //------------------------------------- - if ( ! xml_parse($parser, $data, 1)) + if (! xml_parse($parser, $data, 1)) { // return XML error as a faultCode $r = new XML_RPC_Response(0, @@ -244,7 +244,7 @@ class CI_Xmlrpcs extends CI_Xmlrpc // Valid Method //------------------------------------- - if ( ! isset($this->methods[$methName]['function'])) + if (! isset($this->methods[$methName]['function'])) { return new XML_RPC_Response(0, $this->xmlrpcerr['unknown_method'], $this->xmlrpcstr['unknown_method']); } diff --git a/system/libraries/Zip.php b/system/libraries/Zip.php index fab8e7f6b..4bdc92547 100644 --- a/system/libraries/Zip.php +++ b/system/libraries/Zip.php @@ -57,7 +57,7 @@ class CI_Zip { { foreach ((array)$directory as $dir) { - if ( ! preg_match("|.+/$|", $dir)) + if (! preg_match("|.+/$|", $dir)) { $dir .= '/'; } @@ -196,7 +196,7 @@ class CI_Zip { */ function read_file($path, $preserve_filepath = FALSE) { - if ( ! file_exists($path)) + if (! file_exists($path)) { return FALSE; } @@ -301,7 +301,7 @@ class CI_Zip { */ function archive($filepath) { - if ( ! ($fp = @fopen($filepath, "wb"))) + if (! ($fp = @fopen($filepath, "wb"))) { return FALSE; } @@ -326,7 +326,7 @@ class CI_Zip { */ function download($filename = 'backup.zip') { - if ( ! preg_match("|.+?\.zip$|", $filename)) + if (! preg_match("|.+?\.zip$|", $filename)) { $filename .= '.zip'; } diff --git a/system/plugins/captcha_pi.php b/system/plugins/captcha_pi.php index 50a4eae0d..309ef7ea5 100644 --- a/system/plugins/captcha_pi.php +++ b/system/plugins/captcha_pi.php @@ -157,16 +157,16 @@ function create_captcha($data = '', $img_path = '', $img_url = '', $font_path = foreach ($defaults as $key => $val) { - if ( ! is_array($data)) + if (! is_array($data)) { - if ( ! isset($$key) OR $$key == '') + if (! isset($$key) OR $$key == '') { $$key = $val; } } else { - $$key = ( ! isset($data[$key])) ? $val : $data[$key]; + $$key = (! isset($data[$key])) ? $val : $data[$key]; } } @@ -175,17 +175,17 @@ function create_captcha($data = '', $img_path = '', $img_url = '', $font_path = return FALSE; } - if ( ! @is_dir($img_path)) + if (! @is_dir($img_path)) { return FALSE; } - if ( ! is_really_writable($img_path)) + if (! is_really_writable($img_path)) { return FALSE; } - if ( ! extension_loaded('gd')) + if (! extension_loaded('gd')) { return FALSE; } diff --git a/system/scaffolding/Scaffolding.php b/system/scaffolding/Scaffolding.php index a9777040f..64f62a3d6 100644 --- a/system/scaffolding/Scaffolding.php +++ b/system/scaffolding/Scaffolding.php @@ -97,7 +97,7 @@ class Scaffolding { function add() { $data = array( - 'title' => ( ! isset($this->lang['scaff_add'])) ? 'Add Data' : $this->lang['scaff_add'], + 'title' => (! isset($this->lang['scaff_add'])) ? 'Add Data' : $this->lang['scaff_add'], 'fields' => $this->CI->db->field_data($this->current_table), 'action' => $this->base_uri.'/insert' ); @@ -172,7 +172,7 @@ class Scaffolding { ); $data = array( - 'title' => ( ! isset($this->lang['scaff_view'])) ? 'View Data' : $this->lang['scaff_view'], + 'title' => (! isset($this->lang['scaff_view'])) ? 'View Data' : $this->lang['scaff_view'], 'query' => $query, 'fields' => $fields, 'primary' => $primary, @@ -207,7 +207,7 @@ class Scaffolding { $query = $this->CI->db->get_where($this->current_table, array($primary => $id)); $data = array( - 'title' => ( ! isset($this->lang['scaff_edit'])) ? 'Edit Data' : $this->lang['scaff_edit'], + 'title' => (! isset($this->lang['scaff_edit'])) ? 'Edit Data' : $this->lang['scaff_edit'], 'fields' => $query->field_data(), 'query' => $query->row(), 'action' => $this->base_uri.'/update/'.$this->CI->uri->segment(4) @@ -245,7 +245,7 @@ class Scaffolding { */ function delete() { - if ( ! isset($this->lang['scaff_del_confirm'])) + if (! isset($this->lang['scaff_del_confirm'])) { $message = 'Are you sure you want to delete the following row: '.$this->CI->uri->segment(4); } @@ -255,10 +255,10 @@ class Scaffolding { } $data = array( - 'title' => ( ! isset($this->lang['scaff_delete'])) ? 'Delete Data' : $this->lang['scaff_delete'], + 'title' => (! isset($this->lang['scaff_delete'])) ? 'Delete Data' : $this->lang['scaff_delete'], 'message' => $message, - 'no' => anchor(array($this->base_uri, 'view'), ( ! isset($this->lang['scaff_no'])) ? 'No' : $this->lang['scaff_no']), - 'yes' => anchor(array($this->base_uri, 'do_delete', $this->CI->uri->segment(4)), ( ! isset($this->lang['scaff_yes'])) ? 'Yes' : $this->lang['scaff_yes']) + 'no' => anchor(array($this->base_uri, 'view'), (! isset($this->lang['scaff_no'])) ? 'No' : $this->lang['scaff_no']), + 'yes' => anchor(array($this->base_uri, 'do_delete', $this->CI->uri->segment(4)), (! isset($this->lang['scaff_yes'])) ? 'Yes' : $this->lang['scaff_yes']) ); $this->CI->load->view('delete', $data); -- cgit v1.2.3-24-g4f1b From 5f6b5442e5a3d7fa5cf6c047ed716b82946629a2 Mon Sep 17 00:00:00 2001 From: Derek Jones Date: Mon, 5 May 2008 18:28:27 +0000 Subject: adding some fopen constants --- system/application/config/constants.php | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'system') diff --git a/system/application/config/constants.php b/system/application/config/constants.php index ace3f8b9d..3909941ec 100644 --- a/system/application/config/constants.php +++ b/system/application/config/constants.php @@ -18,4 +18,20 @@ define('FILE_WRITE_MODE', 0666); define('DIR_READ_MODE', 0755); define('DIR_WRITE_MODE', 0777); +/* +|-------------------------------------------------------------------------- +| File Stream Modes +|-------------------------------------------------------------------------- +| +| These modes are used when working with fopen()/popen() +| +*/ +define('FOPEN_READ_BOF', 'rb'); +define('FOPEN_READ_WRITE_BOF', 'r+b'); +define('FOPEN_WRITE_CREATE_BOF', 'wb'); // truncates existing file data, use with care +define('FOPEN_READ_WRITE_CREATE_BOF', 'w+b'); // truncates existing file data, use with care +define('FOPEN_WRITE_CREATE_EOF', 'ab'); +define('FOPEN_READ_WRITE_CREATE_EOF', 'a+b'); +define('FOPEN_WRITE_CREATE_STRICT', 'xb'); +define('FOPEN_READ_WRITE_CREATE_STRICT','x+b'); ?> \ No newline at end of file -- cgit v1.2.3-24-g4f1b From 14031d152b76e7744d6f8a70964ecae77ca55179 Mon Sep 17 00:00:00 2001 From: Derek Jones Date: Mon, 5 May 2008 18:29:43 +0000 Subject: implemented fopen mode constants --- system/codeigniter/Common.php | 4 ++-- system/helpers/file_helper.php | 6 +++--- system/libraries/Email.php | 2 +- system/libraries/Log.php | 2 +- system/libraries/Upload.php | 2 +- system/libraries/Zip.php | 2 +- 6 files changed, 9 insertions(+), 9 deletions(-) (limited to 'system') diff --git a/system/codeigniter/Common.php b/system/codeigniter/Common.php index 05720a459..b6a4ce4c5 100644 --- a/system/codeigniter/Common.php +++ b/system/codeigniter/Common.php @@ -46,7 +46,7 @@ function is_really_writable($file) { $file = rtrim($file, '/').'/'.md5(rand(1,100)); - if (($fp = @fopen($file, 'ab')) === FALSE) + if (($fp = @fopen($file, FOPEN_WRITE_CREATE_EOF)) === FALSE) { return FALSE; } @@ -56,7 +56,7 @@ function is_really_writable($file) @unlink($file); return TRUE; } - elseif (($fp = @fopen($file, 'ab')) === FALSE) + elseif (($fp = @fopen($file, FOPEN_WRITE_CREATE_EOF)) === FALSE) { return FALSE; } diff --git a/system/helpers/file_helper.php b/system/helpers/file_helper.php index 1eb8348e9..2bcb98b4d 100644 --- a/system/helpers/file_helper.php +++ b/system/helpers/file_helper.php @@ -50,7 +50,7 @@ if (! function_exists('read_file')) return file_get_contents($file); } - if (! $fp = @fopen($file, 'rb')) + if (! $fp = @fopen($file, FOPEN_READ_BOF)) { return FALSE; } @@ -85,7 +85,7 @@ if (! function_exists('read_file')) */ if (! function_exists('write_file')) { - function write_file($path, $data, $mode = 'wb') + function write_file($path, $data, $mode = FOPEN_WRITE_CREATE_BOF) { if (! $fp = @fopen($path, $mode)) { @@ -167,7 +167,7 @@ if (! function_exists('get_filenames')) { function get_filenames($source_dir, $include_path = FALSE, $_recursion = FALSE) { - $_filedata = array(); + static $_filedata = array(); if ($fp = @opendir($source_dir)) { diff --git a/system/libraries/Email.php b/system/libraries/Email.php index 3b4dddd00..d71f593e9 100644 --- a/system/libraries/Email.php +++ b/system/libraries/Email.php @@ -1070,7 +1070,7 @@ class CI_Email { $attachment[$z++] = $h; $file = filesize($filename) +1; - if (! $fp = fopen($filename, 'r')) + if (! $fp = fopen($filename, FOPEN_READ_BOF)) { $this->_set_error_message('email_attachment_unreadable', $filename); return FALSE; diff --git a/system/libraries/Log.php b/system/libraries/Log.php index 247aee13c..370ab7922 100644 --- a/system/libraries/Log.php +++ b/system/libraries/Log.php @@ -97,7 +97,7 @@ class CI_Log { $message .= "<"."?php if (!defined('BASEPATH')) exit('No direct script access allowed'); ?".">\n\n"; } - if (! $fp = @fopen($filepath, "a")) + if (! $fp = @fopen($filepath, FOPEN_WRITE_CREATE_EOF)) { return FALSE; } diff --git a/system/libraries/Upload.php b/system/libraries/Upload.php index f13907000..853c162bd 100644 --- a/system/libraries/Upload.php +++ b/system/libraries/Upload.php @@ -741,7 +741,7 @@ class CI_Upload { return FALSE; } - if (! $fp = @fopen($file, 'r+b')) + if (! $fp = @fopen($file, FOPEN_READ_WRITE_BOF)) { return FALSE; } diff --git a/system/libraries/Zip.php b/system/libraries/Zip.php index 4bdc92547..6b5988017 100644 --- a/system/libraries/Zip.php +++ b/system/libraries/Zip.php @@ -301,7 +301,7 @@ class CI_Zip { */ function archive($filepath) { - if (! ($fp = @fopen($filepath, "wb"))) + if (! ($fp = @fopen($filepath, FOPEN_WRITE_CREATE_BOF))) { return FALSE; } -- cgit v1.2.3-24-g4f1b From 3be20e26b7d3c0f60bc60b314a85138100edab52 Mon Sep 17 00:00:00 2001 From: Derek Jones Date: Mon, 5 May 2008 20:07:09 +0000 Subject: tweak to the new fopen mode constant names --- system/application/config/constants.php | 18 ++++++++++-------- system/codeigniter/Common.php | 4 ++-- system/helpers/file_helper.php | 4 ++-- system/libraries/Email.php | 2 +- system/libraries/Log.php | 2 +- system/libraries/Upload.php | 2 +- system/libraries/Zip.php | 2 +- 7 files changed, 18 insertions(+), 16 deletions(-) (limited to 'system') diff --git a/system/application/config/constants.php b/system/application/config/constants.php index 3909941ec..3f7975635 100644 --- a/system/application/config/constants.php +++ b/system/application/config/constants.php @@ -26,12 +26,14 @@ define('DIR_WRITE_MODE', 0777); | These modes are used when working with fopen()/popen() | */ -define('FOPEN_READ_BOF', 'rb'); -define('FOPEN_READ_WRITE_BOF', 'r+b'); -define('FOPEN_WRITE_CREATE_BOF', 'wb'); // truncates existing file data, use with care -define('FOPEN_READ_WRITE_CREATE_BOF', 'w+b'); // truncates existing file data, use with care -define('FOPEN_WRITE_CREATE_EOF', 'ab'); -define('FOPEN_READ_WRITE_CREATE_EOF', 'a+b'); -define('FOPEN_WRITE_CREATE_STRICT', 'xb'); -define('FOPEN_READ_WRITE_CREATE_STRICT','x+b'); + +define('FOPEN_READ', 'rb'); +define('FOPEN_READ_WRITE', 'r+b'); +define('FOPEN_WRITE_CREATE_DESTRUCTIVE', 'wb'); // truncates existing file data, use with care +define('FOPEN_READ_WRITE_CREATE_DESTRUCTIVE', 'w+b'); // truncates existing file data, use with care +define('FOPEN_WRITE_CREATE', 'ab'); +define('FOPEN_READ_WRITE_CREATE', 'a+b'); +define('FOPEN_WRITE_CREATE_STRICT', 'xb'); +define('FOPEN_READ_WRITE_CREATE_STRICT', 'x+b'); + ?> \ No newline at end of file diff --git a/system/codeigniter/Common.php b/system/codeigniter/Common.php index b6a4ce4c5..c5c548cdf 100644 --- a/system/codeigniter/Common.php +++ b/system/codeigniter/Common.php @@ -46,7 +46,7 @@ function is_really_writable($file) { $file = rtrim($file, '/').'/'.md5(rand(1,100)); - if (($fp = @fopen($file, FOPEN_WRITE_CREATE_EOF)) === FALSE) + if (($fp = @fopen($file, FOPEN_WRITE_CREATE)) === FALSE) { return FALSE; } @@ -56,7 +56,7 @@ function is_really_writable($file) @unlink($file); return TRUE; } - elseif (($fp = @fopen($file, FOPEN_WRITE_CREATE_EOF)) === FALSE) + elseif (($fp = @fopen($file, FOPEN_WRITE_CREATE)) === FALSE) { return FALSE; } diff --git a/system/helpers/file_helper.php b/system/helpers/file_helper.php index 2bcb98b4d..147a7fdf1 100644 --- a/system/helpers/file_helper.php +++ b/system/helpers/file_helper.php @@ -50,7 +50,7 @@ if (! function_exists('read_file')) return file_get_contents($file); } - if (! $fp = @fopen($file, FOPEN_READ_BOF)) + if (! $fp = @fopen($file, FOPEN_READ)) { return FALSE; } @@ -85,7 +85,7 @@ if (! function_exists('read_file')) */ if (! function_exists('write_file')) { - function write_file($path, $data, $mode = FOPEN_WRITE_CREATE_BOF) + function write_file($path, $data, $mode = FOPEN_WRITE_CREATE_DESTRUCTIVE) { if (! $fp = @fopen($path, $mode)) { diff --git a/system/libraries/Email.php b/system/libraries/Email.php index d71f593e9..e0fa689b3 100644 --- a/system/libraries/Email.php +++ b/system/libraries/Email.php @@ -1070,7 +1070,7 @@ class CI_Email { $attachment[$z++] = $h; $file = filesize($filename) +1; - if (! $fp = fopen($filename, FOPEN_READ_BOF)) + if (! $fp = fopen($filename, FOPEN_READ)) { $this->_set_error_message('email_attachment_unreadable', $filename); return FALSE; diff --git a/system/libraries/Log.php b/system/libraries/Log.php index 370ab7922..26757ba50 100644 --- a/system/libraries/Log.php +++ b/system/libraries/Log.php @@ -97,7 +97,7 @@ class CI_Log { $message .= "<"."?php if (!defined('BASEPATH')) exit('No direct script access allowed'); ?".">\n\n"; } - if (! $fp = @fopen($filepath, FOPEN_WRITE_CREATE_EOF)) + if (! $fp = @fopen($filepath, FOPEN_WRITE_CREATE)) { return FALSE; } diff --git a/system/libraries/Upload.php b/system/libraries/Upload.php index 853c162bd..0fc38dc4f 100644 --- a/system/libraries/Upload.php +++ b/system/libraries/Upload.php @@ -741,7 +741,7 @@ class CI_Upload { return FALSE; } - if (! $fp = @fopen($file, FOPEN_READ_WRITE_BOF)) + if (! $fp = @fopen($file, FOPEN_READ_WRITE)) { return FALSE; } diff --git a/system/libraries/Zip.php b/system/libraries/Zip.php index 6b5988017..f7f47ab42 100644 --- a/system/libraries/Zip.php +++ b/system/libraries/Zip.php @@ -301,7 +301,7 @@ class CI_Zip { */ function archive($filepath) { - if (! ($fp = @fopen($filepath, FOPEN_WRITE_CREATE_BOF))) + if (! ($fp = @fopen($filepath, FOPEN_WRITE_CREATE_DESTRUCTIVE))) { return FALSE; } -- cgit v1.2.3-24-g4f1b From 7f309810a6d3da76c1a2c4ef8e900c88f47afee4 Mon Sep 17 00:00:00 2001 From: Derek Allard Date: Tue, 6 May 2008 00:17:10 +0000 Subject: Fixed a bug in DB Forge, when inserting an id field (#3456). --- system/database/DB_forge.php | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) (limited to 'system') diff --git a/system/database/DB_forge.php b/system/database/DB_forge.php index 5f25ebedc..2ddb21be7 100644 --- a/system/database/DB_forge.php +++ b/system/database/DB_forge.php @@ -132,12 +132,13 @@ class CI_DB_forge { { if ($field == 'id') { - $this->fields[] = array('id' => array( - 'type' => 'INT', - 'constraint' => 9, - 'auto_increment' => TRUE - ) - ); + $this->add_field(array( + 'id' => array( + 'type' => 'INT', + 'constraint' => 9, + 'auto_increment' => TRUE + ) + )); $this->add_key('id', TRUE); } else -- cgit v1.2.3-24-g4f1b From ff390bdb457dbcfb5ba3e95323bce5f4a2c17497 Mon Sep 17 00:00:00 2001 From: Derek Allard Date: Tue, 6 May 2008 00:37:12 +0000 Subject: DB Forge is now assigned to any models that exist after loading (#3457). --- system/libraries/Loader.php | 2 ++ 1 file changed, 2 insertions(+) (limited to 'system') diff --git a/system/libraries/Loader.php b/system/libraries/Loader.php index 5cf1f2ae6..5966aebf6 100644 --- a/system/libraries/Loader.php +++ b/system/libraries/Loader.php @@ -272,6 +272,8 @@ class CI_Loader { $class = 'CI_DB_'.$CI->db->dbdriver.'_forge'; $CI->dbforge = new $class(); + + $CI->load->_ci_assign_to_models(); } // -------------------------------------------------------------------- -- cgit v1.2.3-24-g4f1b From be8ec803cf8542acca9d2dd24c46b219fecabd9c Mon Sep 17 00:00:00 2001 From: Derek Allard Date: Tue, 6 May 2008 01:02:41 +0000 Subject: Fixed a bug in the table library that could cause identically constructed rows to be dropped (#3459). --- system/libraries/Table.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'system') diff --git a/system/libraries/Table.php b/system/libraries/Table.php index 38affa579..01b490a5d 100644 --- a/system/libraries/Table.php +++ b/system/libraries/Table.php @@ -110,8 +110,7 @@ class CI_Table { $new = array(); while(count($array) > 0) { - $temp = array_slice($array, 0, $col_limit); - $array = array_diff($array, $temp); + $temp = array_splice($array, 0, $col_limit); if (count($temp) < $col_limit) { -- cgit v1.2.3-24-g4f1b From de7320bb78f02baa3b7cad3983d5b6d3a9c74f34 Mon Sep 17 00:00:00 2001 From: Derek Allard Date: Tue, 6 May 2008 13:51:02 +0000 Subject: Changed the radio() and checkbox() functions to default to not checked by default. --- system/helpers/form_helper.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'system') diff --git a/system/helpers/form_helper.php b/system/helpers/form_helper.php index 10858339e..c9a6897ae 100644 --- a/system/helpers/form_helper.php +++ b/system/helpers/form_helper.php @@ -289,7 +289,7 @@ if (! function_exists('form_dropdown')) */ if (! function_exists('form_checkbox')) { - function form_checkbox($data = '', $value = '', $checked = TRUE, $extra = '') + function form_checkbox($data = '', $value = '', $checked = FALSE, $extra = '') { $defaults = array('type' => 'checkbox', 'name' => ((! is_array($data)) ? $data : ''), 'value' => $value); @@ -330,7 +330,7 @@ if (! function_exists('form_checkbox')) */ if (! function_exists('form_radio')) { - function form_radio($data = '', $value = '', $checked = TRUE, $extra = '') + function form_radio($data = '', $value = '', $checked = FALSE, $extra = '') { if (! is_array($data)) { -- cgit v1.2.3-24-g4f1b From 2798b5033815f9165ad10137c0866b5fdb59ea54 Mon Sep 17 00:00:00 2001 From: Derek Jones Date: Tue, 6 May 2008 14:12:18 +0000 Subject: fixed a bug where the dir resource was not closed in the directory helper, and made it more efficient http://codeigniter.com/bug_tracker/bug/4206/ --- system/helpers/directory_helper.php | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) (limited to 'system') diff --git a/system/helpers/directory_helper.php b/system/helpers/directory_helper.php index 5a23944cb..25c16c1fc 100644 --- a/system/helpers/directory_helper.php +++ b/system/helpers/directory_helper.php @@ -45,22 +45,31 @@ if (! function_exists('directory_map')) { if ($fp = @opendir($source_dir)) { + $source_dir = rtrim($source_dir, DIRECTORY_SEPARATOR).DIRECTORY_SEPARATOR; $filedata = array(); + while (FALSE !== ($file = readdir($fp))) { - if (@is_dir($source_dir.$file) && substr($file, 0, 1) != '.' AND $top_level_only == FALSE) + if (substr($file, 0, 1) == '.') + { + continue; + } + + if ($top_level_only == FALSE && @is_dir($source_dir.$file)) { $temp_array = array(); - $temp_array = directory_map($source_dir.$file."/"); + $temp_array = directory_map($source_dir.$file.DIRECTORY_SEPARATOR); $filedata[$file] = $temp_array; } - elseif (substr($file, 0, 1) != ".") + else { $filedata[] = $file; } } + + closedir($fp); return $filedata; } } -- cgit v1.2.3-24-g4f1b From fd93d22814b090ef85f3079d31fffa66d23d95e8 Mon Sep 17 00:00:00 2001 From: Derek Jones Date: Tue, 6 May 2008 15:18:50 +0000 Subject: Flipped user guide page titles for easier recognition in tabs: CodeIgniter User Guide : Page TItle to Page Title : CodeIgniter User Guide --- system/helpers/file_helper.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system') diff --git a/system/helpers/file_helper.php b/system/helpers/file_helper.php index 147a7fdf1..21ed5ff97 100644 --- a/system/helpers/file_helper.php +++ b/system/helpers/file_helper.php @@ -22,7 +22,7 @@ * @subpackage Helpers * @category Helpers * @author ExpressionEngine Dev Team - * @link http://codeigniter.com/user_guide/helpers/file_helpers.html + * @link http://codeigniter.com/user_guide/helpers/file_helper.html */ // ------------------------------------------------------------------------ -- cgit v1.2.3-24-g4f1b From 00618de8c4aca96edb09094a86242b2495ba124d Mon Sep 17 00:00:00 2001 From: Derek Jones Date: Tue, 6 May 2008 15:59:14 +0000 Subject: Added a Compatibility Helper --- system/helpers/compatibility_helper.php | 496 ++++++++++++++++++++++++++++++++ 1 file changed, 496 insertions(+) create mode 100644 system/helpers/compatibility_helper.php (limited to 'system') diff --git a/system/helpers/compatibility_helper.php b/system/helpers/compatibility_helper.php new file mode 100644 index 000000000..9cc282598 --- /dev/null +++ b/system/helpers/compatibility_helper.php @@ -0,0 +1,496 @@ + 0) // 8 = FILE_APPEND flag + { + $mode = FOPEN_WRITE_CREATE; + } + else + { + $mode = FOPEN_WRITE_CREATE_DESTRUCTIVE; + } + + // Check if we're using the include path + if (($flags & 1) > 0) // 1 = FILE_USE_INCLUDE_PATH flag + { + $use_include_path = TRUE; + } + else + { + $use_include_path = FALSE; + } + + $fp = @fopen($filename, $mode, $use_include_path); + + if ($fp === FALSE) + { + $backtrace = debug_backtrace(); + _exception_handler(E_USER_WARNING, 'file_put_contents('.htmlentities($filename).') failed to open stream', $backtrace[0]['file'], $backtrace[0]['line']); + return FALSE; + } + + if (($flags & LOCK_EX) > 0) + { + if (! flock($fh, LOCK_EX)) + { + $backtrace = debug_backtrace(); + _exception_handler(E_USER_WARNING, 'file_put_contents('.htmlentities($filename).') unable to acquire an exclusive lock on file', $backtrace[0]['file'], $backtrace[0]['line']); + return FALSE; + } + } + + // write it + if (($written = @fwrite($fp, $data)) === FALSE) + { + $backtrace = debug_backtrace(); + _exception_handler(E_USER_WARNING, 'file_put_contents('.htmlentities($filename).') failed to write to '.htmlentities($filename), $backtrace[0]['file'], $backtrace[0]['line']); + } + + // Close the handle + @fclose($fh); + + // Return length + return $written; + } +} + +// ------------------------------------------------------------------------ + +/** + * fputcsv() + * + * Format line as CSV and write to file pointer + * http://us.php.net/manual/en/function.fputcsv.php + * + * @access public + * @param resource file pointer + * @param array data to be written + * @param string delimiter + * @param string enclosure + * @return int length of written string + */ +if (! function_exists('fputcsv')) +{ + function fputcsv($handle, $fields, $delimiter = ',', $enclosure = '"') + { + // Checking for a handle resource + if (! is_resource($handle)) + { + $backtrace = debug_backtrace(); + _exception_handler(E_USER_WARNING, 'fputcsv() expects parameter 1 to be stream resource, '.gettype($handle).' given', $backtrace[0]['file'], $backtrace[0]['line']); + return FALSE; + } + + // OK, it is a resource, but is it a stream? + if (get_resource_type($handle) !== 'stream') + { + $backtrace = debug_backtrace(); + _exception_handler(E_USER_WARNING, 'fputcsv() expects parameter 1 to be stream resource, '.get_resource_type($handle).' given', $backtrace[0]['file'], $backtrace[0]['line']); + return FALSE; + } + + // Checking for an array of fields + if (! is_array($fields)) + { + $backtrace = debug_backtrace(); + _exception_handler(E_USER_WARNING, 'fputcsv() expects parameter 2 to be array, '.gettype($fields).' given', $backtrace[0]['file'], $backtrace[0]['line']); + return FALSE; + } + + // validate delimiter + if (strlen($delimiter) > 1) + { + $delimiter = substr($delimiter, 0, 1); + $backtrace = debug_backtrace(); + _exception_handler(E_NOTICE, 'fputcsv() delimiter must be one character long, "'.htmlentities($delimiter).'" used', $backtrace[0]['file'], $backtrace[0]['line']); + } + + // validate enclosure + if (strlen($enclosure) > 1) + { + $enclosure = substr($enclosure, 0, 1); + $backtrace = debug_backtrace(); + _exception_handler(E_NOTICE, 'fputcsv() enclosure must be one character long, "'.htmlentities($enclosure).'" used', $backtrace[0]['file'], $backtrace[0]['line']); + + } + + $out = ''; + + foreach ($fields as $cell) + { + $cell = str_replace($enclosure, $enclosure.$enclosure, $cell); + + if (strpos($cell, $delimiter) !== FALSE || strpos($cell, $enclosure) !== FALSE || strpos($cell, "\n") !== FALSE) + { + $out .= $enclosure.$cell.$enclosure.$delimiter; + } + else + { + $out .= $cell.$delimiter; + } + } + + $length = @fwrite($handle, substr($out, 0, -1)."\n"); + + return $length; + } +} + +// ------------------------------------------------------------------------ + +/** + * stripos() + * + * Find position of first occurrence of a case-insensitive string + * http://us.php.net/manual/en/function.stripos.php + * + * @access public + * @param string haystack + * @param string needle + * @param int offset + * @return int numeric position of the first occurrence of needle in the haystack + */ +if (! function_exists('stripos')) +{ + function stripos($haystack, $needle, $offset = NULL) + { + // Cast non string scalar values + if (is_scalar($haystack)) + { + settype($haystack, 'STRING'); + } + + if (! is_string($haystack)) + { + $backtrace = debug_backtrace(); + _exception_handler(E_USER_WARNING, 'stripos() expects parameter 1 to be string, '.gettype($haystack).' given', $backtrace[0]['file'], $backtrace[0]['line']); + return FALSE; + } + + if (! is_scalar($needle)) + { + $backtrace = debug_backtrace(); + _exception_handler(E_USER_WARNING, 'stripos() needle is not a string or an integer in '.$backtrace[0]['file'], $backtrace[0]['line']); + return FALSE; + } + + if (is_float($offset)) + { + $offset = (int)$offset; + } + + if (! is_int($offset) && ! is_bool($offset) && ! is_null($offset)) + { + $backtrace = debug_backtrace(); + _exception_handler(E_USER_WARNING, 'stripos() expects parameter 3 to be long, '.gettype($offset).' given', $backtrace[0]['file'], $backtrace[0]['line']); + return NULL; + } + + return strpos(strtolower($haystack), strtolower($needle), $offset); + } +} + +// ------------------------------------------------------------------------ + +/** + * str_ireplace() + * + * Find position of first occurrence of a case-insensitive string + * http://us.php.net/manual/en/function.str-ireplace.php + * (parameter 4, $count, is not supported as to do so in PHP 4 would make + * it a required parameter) + * + * @access public + * @param mixed search + * @param mixed replace + * @param mixed subject + * @return int numeric position of the first occurrence of needle in the haystack + */ +if (! function_exists('str_ireplace')) +{ + function str_ireplace($search, $replace, $subject) + { + // Nothing to do here + if ($search === NULL || $subject === NULL) + { + return $subject; + } + + // Crazy arguments + if (is_scalar($search) && is_array($replace)) + { + $backtrace = debug_backtrace(); + + if (is_object($replace)) + { + show_error('Object of class '.get_class($replace).' could not be converted to string in '.$backtrace[0]['file'].' on line '.$backtrace[0]['line']); + } + else + { + _exception_handler(E_USER_NOTICE, 'Array to string conversion in '.$backtrace[0]['file'], $backtrace[0]['line']); + } + } + + // Searching for an array + if (is_array($search)) + { + // Replacing with an array + if (is_array($replace)) + { + $search = array_values($search); + $replace = array_values($replace); + + if (count($search) >= count($replace)) + { + $replace = array_pad($replace, count($search), ''); + } + else + { + $replace = array_slice($replace, 0, count($search)); + } + } + else + { + // Replacing with a string all positions + $replace = array_fill(0, count($search), $replace); + } + } + else + { + //Searching for a string and replacing with a string. + $search = array((string)$search); + $replace = array((string)$replace); + } + + // Prepare the search array + foreach ($search as $search_key => $search_value) + { + $search[$search_key] = '/'.preg_quote($search_value, '/').'/i'; + } + + // Prepare the replace array (escape backreferences) + foreach ($replace as $k => $v) + { + $replace[$k] = str_replace(array(chr(92), '$'), array(chr(92).chr(92), '\$'), $v); + } + + // do the replacement + $result = preg_replace($search, $replace, (array)$subject); + + // Check if subject was initially a string and return it as a string + if (! is_array($subject)) + { + return current($result); + } + + // Otherwise, just return the array + return $result; + } +} + +// ------------------------------------------------------------------------ + +/** + * http_build_query() + * + * Generate URL-encoded query string + * http://us.php.net/manual/en/function.http-build-query.php + * + * @access public + * @param array form data + * @param string numeric prefix + * @param string argument separator + * @return string URL-encoded string + */ +if (! function_exists('http_build_query')) +{ + function http_build_query($formdata, $numeric_prefix = NULL, $separator = NULL) + { + // Check the data + if (! is_array($formdata) && ! is_object($formdata)) + { + $backtrace = debug_backtrace(); + _exception_handler(E_USER_WARNING, 'http_build_query() Parameter 1 expected to be Array or Object. Incorrect value given', $backtrace[0]['file'], $backtrace[0]['line']); + return FALSE; + } + + // Cast it as array + if (is_object($formdata)) + { + $formdata = get_object_vars($formdata); + } + + // If the array is empty, return NULL + if (empty($formdata)) + { + return NULL; + } + + // Argument separator + if ($separator === NULL) + { + $separator = ini_get('arg_separator.output'); + + if (strlen($separator) == 0) + { + $separator = '&'; + } + } + + // Start building the query + $tmp = array(); + + foreach ($formdata as $key => $val) + { + if ($val === NULL) + { + continue; + } + + if (is_integer($key) && $numeric_prefix != NULL) + { + $key = $numeric_prefix.$key; + } + + if (is_resource($val)) + { + return NULL; + } + + // hand it off to a recursive parser + $tmp[] = _http_build_query_helper($key, $val, $separator); + } + + return implode($separator, $tmp); + } + + + // Helper helper. Remind anyone of college? + // Required to handle recursion in nested arrays. + // + // You could shave fractions of fractions of a second by moving where + // the urlencoding takes place, but it's much less intuitive, and if + // your application has 10,000 form fields, well, you have other problems ;) + function _http_build_query_helper($key, $val, $separator = '&') + { + if (is_scalar($val)) + { + return urlencode($key).'='.urlencode($val); + } + else + { + // arrays please + if (is_object($val)) + { + $val = get_object_vars($val); + } + + foreach ($val as $k => $v) + { + $tmp[] = _http_build_query_helper($key.'['.$k.']', $v, $separator); + } + } + + return implode($separator, $tmp); + } +} + +?> \ No newline at end of file -- cgit v1.2.3-24-g4f1b From f9f9f66428518cdae3a2a9ce157d4755c4e8f9f9 Mon Sep 17 00:00:00 2001 From: Derek Allard Date: Tue, 6 May 2008 17:03:57 +0000 Subject: updated CI_VERSION to 1.6.2 --- system/codeigniter/CodeIgniter.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system') diff --git a/system/codeigniter/CodeIgniter.php b/system/codeigniter/CodeIgniter.php index bf3398d81..75332e678 100644 --- a/system/codeigniter/CodeIgniter.php +++ b/system/codeigniter/CodeIgniter.php @@ -28,7 +28,7 @@ */ // CI Version -define('CI_VERSION', '1.6.1'); +define('CI_VERSION', '1.6.2'); /* * ------------------------------------------------------ -- cgit v1.2.3-24-g4f1b From d196d4e8593adc8324e4bfbbb959c89ecb3284dc Mon Sep 17 00:00:00 2001 From: Derek Jones Date: Wed, 7 May 2008 03:20:03 +0000 Subject: fixed a typo with a variable in the compatibility helper --- system/helpers/compatibility_helper.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'system') diff --git a/system/helpers/compatibility_helper.php b/system/helpers/compatibility_helper.php index 9cc282598..0d214648c 100644 --- a/system/helpers/compatibility_helper.php +++ b/system/helpers/compatibility_helper.php @@ -129,7 +129,7 @@ if (! function_exists('file_put_contents')) if (($flags & LOCK_EX) > 0) { - if (! flock($fh, LOCK_EX)) + if (! flock($fp, LOCK_EX)) { $backtrace = debug_backtrace(); _exception_handler(E_USER_WARNING, 'file_put_contents('.htmlentities($filename).') unable to acquire an exclusive lock on file', $backtrace[0]['file'], $backtrace[0]['line']); @@ -145,7 +145,7 @@ if (! function_exists('file_put_contents')) } // Close the handle - @fclose($fh); + @fclose($fp); // Return length return $written; -- cgit v1.2.3-24-g4f1b From 62a90205c4ace42df775dbe1354c41340e89c92c Mon Sep 17 00:00:00 2001 From: Derek Jones Date: Wed, 7 May 2008 16:40:28 +0000 Subject: removed SCRIPT_NAME from path provided by ORIG_PATH_INFO to remove the path and script name from the URI data (bug #3191) --- system/libraries/URI.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'system') diff --git a/system/libraries/URI.php b/system/libraries/URI.php index f0d02101a..8ee888a2e 100644 --- a/system/libraries/URI.php +++ b/system/libraries/URI.php @@ -92,7 +92,8 @@ class CI_URI { $path = (isset($_SERVER['ORIG_PATH_INFO'])) ? $_SERVER['ORIG_PATH_INFO'] : @getenv('ORIG_PATH_INFO'); if (trim($path, '/') != '' AND $path != "/".SELF) { - $this->uri_string = $path; + // remove path and script information so we have good URI data + $this->uri_string = str_replace($_SERVER['SCRIPT_NAME'], '', $path); return; } -- cgit v1.2.3-24-g4f1b From cd6f9cdbbcdd550e73beccb906fe7ee78714a3f1 Mon Sep 17 00:00:00 2001 From: Derek Jones Date: Wed, 7 May 2008 17:31:03 +0000 Subject: removed default title= attribute from anchor() in URL Helper --- system/helpers/url_helper.php | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) (limited to 'system') diff --git a/system/helpers/url_helper.php b/system/helpers/url_helper.php index 02c7f3379..d702f6b87 100644 --- a/system/helpers/url_helper.php +++ b/system/helpers/url_helper.php @@ -117,11 +117,7 @@ if (! function_exists('anchor')) $title = $site_url; } - if ($attributes == '') - { - $attributes = ' title="'.htmlentities($title).'"'; - } - else + if ($attributes != '') { $attributes = _parse_attributes($attributes); } -- cgit v1.2.3-24-g4f1b From 05097759476d3e18f2699503c1c47a30dba702af Mon Sep 17 00:00:00 2001 From: Derek Jones Date: Wed, 7 May 2008 19:58:23 +0000 Subject: Added checks for objects in DB driver instead of just resources to accommodate MySQLi, and fixed check in mysqli_result.php checking for a resource. http://codeigniter.com/bug_tracker/bug/3461/ --- system/database/DB_driver.php | 4 ++-- system/database/drivers/mysqli/mysqli_result.php | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) (limited to 'system') diff --git a/system/database/DB_driver.php b/system/database/DB_driver.php index 0f3a1ea0a..5a55002f7 100644 --- a/system/database/DB_driver.php +++ b/system/database/DB_driver.php @@ -98,7 +98,7 @@ class CI_DB_driver { { // If an existing DB connection resource is supplied // there is no need to connect and select the database - if (is_resource($this->conn_id)) + if (is_resource($this->conn_id) OR is_object($this->conn_id)) { return TRUE; } @@ -1097,7 +1097,7 @@ class CI_DB_driver { */ function close() { - if (is_resource($this->conn_id)) + if (is_resource($this->conn_id) OR is_object($this->conn_id)) { $this->_close($this->conn_id); } diff --git a/system/database/drivers/mysqli/mysqli_result.php b/system/database/drivers/mysqli/mysqli_result.php index 586c29252..692d4f729 100644 --- a/system/database/drivers/mysqli/mysqli_result.php +++ b/system/database/drivers/mysqli/mysqli_result.php @@ -114,7 +114,7 @@ class CI_DB_mysqli_result extends CI_DB_result { */ function free_result() { - if (is_resource($this->result_id)) + if (is_object($this->result_id)) { mysqli_free_result($this->result_id); $this->result_id = FALSE; -- cgit v1.2.3-24-g4f1b From b514b029391c9559b567d2e2d5dd97f0e7de0be1 Mon Sep 17 00:00:00 2001 From: Derek Jones Date: Wed, 7 May 2008 21:22:12 +0000 Subject: added code comment for 'directory_trigger' config value which is not yet implemented --- system/application/config/config.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system') diff --git a/system/application/config/config.php b/system/application/config/config.php index 6a7b85745..24fbb4b7a 100644 --- a/system/application/config/config.php +++ b/system/application/config/config.php @@ -149,7 +149,7 @@ $config['permitted_uri_chars'] = 'a-z 0-9~%.:_\-'; | */ $config['enable_query_strings'] = FALSE; -$config['directory_trigger'] = 'd'; +$config['directory_trigger'] = 'd'; // experimental not currently in use $config['controller_trigger'] = 'c'; $config['function_trigger'] = 'm'; -- cgit v1.2.3-24-g4f1b From d007243f15002bac68291fc7e8acbe6303f81a78 Mon Sep 17 00:00:00 2001 From: Derek Jones Date: Wed, 7 May 2008 22:06:51 +0000 Subject: flipped the $not flag for or_where_not_in() http://codeigniter.com/bug_tracker/bug/4171/ --- system/database/DB_active_rec.php | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) (limited to 'system') diff --git a/system/database/DB_active_rec.php b/system/database/DB_active_rec.php index 1820bd202..49d438727 100644 --- a/system/database/DB_active_rec.php +++ b/system/database/DB_active_rec.php @@ -483,7 +483,6 @@ class CI_DB_active_record extends CI_DB_driver { * @access public * @param string The field to search * @param array The values searched on - * @return object */ function where_in($key = NULL, $values = NULL) @@ -502,7 +501,6 @@ class CI_DB_active_record extends CI_DB_driver { * @access public * @param string The field to search * @param array The values searched on - * @return object */ function or_where_in($key = NULL, $values = NULL) @@ -521,7 +519,6 @@ class CI_DB_active_record extends CI_DB_driver { * @access public * @param string The field to search * @param array The values searched on - * @return object */ function where_not_in($key = NULL, $values = NULL) @@ -540,12 +537,11 @@ class CI_DB_active_record extends CI_DB_driver { * @access public * @param string The field to search * @param array The values searched on - * @return object */ function or_where_not_in($key = NULL, $values = NULL) { - return $this->_where_in($key, $values, FALSE, 'OR '); + return $this->_where_in($key, $values, TRUE, 'OR '); } // -------------------------------------------------------------------- -- cgit v1.2.3-24-g4f1b From 4dc06183aa67ba1911562719c97f41c6a9529075 Mon Sep 17 00:00:00 2001 From: Derek Jones Date: Wed, 7 May 2008 22:45:21 +0000 Subject: Fixed bug with recursive deletes in delete_dir() http://codeigniter.com/bug_tracker/bug/4215/ --- system/libraries/Ftp.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'system') diff --git a/system/libraries/Ftp.php b/system/libraries/Ftp.php index 1b5ec2fd2..74b7728fa 100644 --- a/system/libraries/Ftp.php +++ b/system/libraries/Ftp.php @@ -379,15 +379,15 @@ class CI_FTP { $list = $this->list_files($filepath); - if ($list !== FALSE AND count($list) > 0) + if ($list !== FALSE) { foreach ($list as $item) { // If we can't delete the item it's probaly a folder so // we'll recursively call delete_dir() - if (! @ftp_delete($this->conn_id, $filepath.$item)) + if (! @ftp_delete($this->conn_id, $item)) { - $this->delete_dir($filepath.$item); + $this->delete_dir($item); } } } -- cgit v1.2.3-24-g4f1b From 40306b5283b2929e344c7e11da7b736b9e51ef43 Mon Sep 17 00:00:00 2001 From: Derek Jones Date: Wed, 7 May 2008 22:52:45 +0000 Subject: Fixed a bug where $data was not being converted to an array properly in set_rules() http://codeigniter.com/bug_tracker/bug/4220/ --- system/libraries/Validation.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system') diff --git a/system/libraries/Validation.php b/system/libraries/Validation.php index 16e8cd74f..f628d8612 100644 --- a/system/libraries/Validation.php +++ b/system/libraries/Validation.php @@ -117,7 +117,7 @@ class CI_Validation { if ($rules == '') return; - $data[$data] = $rules; + $data = array($data => $rules); } foreach ($data as $key => $val) -- cgit v1.2.3-24-g4f1b From 94a2182c95cc95646ad582616d335bce62152c86 Mon Sep 17 00:00:00 2001 From: Derek Jones Date: Thu, 8 May 2008 15:00:28 +0000 Subject: added symbolic_permissions() and octal_permissions() to the File helper --- system/helpers/file_helper.php | 88 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 88 insertions(+) (limited to 'system') diff --git a/system/helpers/file_helper.php b/system/helpers/file_helper.php index 21ed5ff97..bdde2d55d 100644 --- a/system/helpers/file_helper.php +++ b/system/helpers/file_helper.php @@ -368,4 +368,92 @@ if (! function_exists('get_mime_by_extension')) } } +// -------------------------------------------------------------------- + +/** + * 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; + } +} + +// -------------------------------------------------------------------- + +/** + * 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); + } +} + ?> \ No newline at end of file -- cgit v1.2.3-24-g4f1b From 0f13a13bbf7bc54dc2ef4dda44bbe2f3890af8c6 Mon Sep 17 00:00:00 2001 From: Derek Jones Date: Thu, 8 May 2008 18:54:03 +0000 Subject: added SET to the list of write type queries --- system/database/DB_driver.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system') diff --git a/system/database/DB_driver.php b/system/database/DB_driver.php index 5a55002f7..a5ca75dd6 100644 --- a/system/database/DB_driver.php +++ b/system/database/DB_driver.php @@ -576,7 +576,7 @@ class CI_DB_driver { */ function is_write_type($sql) { - if (! preg_match('/^\s*"?(INSERT|UPDATE|DELETE|REPLACE|CREATE|DROP|LOAD DATA|COPY|ALTER|GRANT|REVOKE|LOCK|UNLOCK)\s+/i', $sql)) + if (! preg_match('/^\s*"?(SET|INSERT|UPDATE|DELETE|REPLACE|CREATE|DROP|LOAD DATA|COPY|ALTER|GRANT|REVOKE|LOCK|UNLOCK)\s+/i', $sql)) { return FALSE; } -- cgit v1.2.3-24-g4f1b From 044379d18fbfb7673e5a5992e9c5af7830e358a8 Mon Sep 17 00:00:00 2001 From: Derek Jones Date: Thu, 8 May 2008 18:57:58 +0000 Subject: added 'object' key to the XML-RPCS config allowing the passing of a class object for method calls that aren't part of the CI super object --- system/libraries/Xmlrpcs.php | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) (limited to 'system') diff --git a/system/libraries/Xmlrpcs.php b/system/libraries/Xmlrpcs.php index 1b2ffca05..7a4bc825e 100644 --- a/system/libraries/Xmlrpcs.php +++ b/system/libraries/Xmlrpcs.php @@ -41,7 +41,9 @@ class CI_Xmlrpcs extends CI_Xmlrpc var $system_methods = array(); // XML RPC Server methods var $controller_obj; - + var $object = FALSE; + + //------------------------------------- // Constructor, more or less //------------------------------------- @@ -74,6 +76,11 @@ class CI_Xmlrpcs extends CI_Xmlrpc { $this->debug = $config['debug']; } + + if (isset($config['object']) && is_object($config['object'])) + { + $this->object = $config['object']; + } } //------------------------------------- @@ -320,11 +327,16 @@ class CI_Xmlrpcs extends CI_Xmlrpc } else { - $CI =& get_instance(); - return $CI->$method_parts['1']($m); - //$class = new $method_parts['0']; - //return $class->$method_parts['1']($m); - //return call_user_func(array(&$method_parts['0'],$method_parts['1']), $m); + 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 -- cgit v1.2.3-24-g4f1b From 8e94646b3147d5f9f70ad09b4cc0aff284b93a98 Mon Sep 17 00:00:00 2001 From: Derek Jones Date: Thu, 8 May 2008 19:55:35 +0000 Subject: removed extraneous error message from Upload lib on failure of validate_upload_path() http://codeigniter.com/bug_tracker/bug/4390/ --- system/libraries/Upload.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system') diff --git a/system/libraries/Upload.php b/system/libraries/Upload.php index 0fc38dc4f..317cf9560 100644 --- a/system/libraries/Upload.php +++ b/system/libraries/Upload.php @@ -144,7 +144,7 @@ class CI_Upload { // Is the upload path valid? if (! $this->validate_upload_path()) { - $this->set_error('upload_no_filepath'); + // errors will already be set by validate_upload_path() so just return FALSE return FALSE; } -- cgit v1.2.3-24-g4f1b From af4a8a057f7b69da2973847717d0ff9388669f54 Mon Sep 17 00:00:00 2001 From: Derek Jones Date: Thu, 8 May 2008 22:16:33 +0000 Subject: added dot transformation to body of email when sending via SMTP --- system/libraries/Email.php | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'system') diff --git a/system/libraries/Email.php b/system/libraries/Email.php index e0fa689b3..aa08971f9 100644 --- a/system/libraries/Email.php +++ b/system/libraries/Email.php @@ -1436,8 +1436,9 @@ class CI_Email { } $this->_send_command('data'); - - $this->_send_data($this->_header_str . $this->_finalbody); + + // perform dot transformation on any lines that begin with a dot + $this->_send_data($this->_header_str . preg_replace('/^\./m', '..$1', $this->_finalbody)); $this->_send_data('.'); -- cgit v1.2.3-24-g4f1b From 5583e1aae64ff7e902136c4ba610d438dc2015d4 Mon Sep 17 00:00:00 2001 From: Derek Jones Date: Sun, 11 May 2008 15:48:20 +0000 Subject: removed closing PHP tag from all framework files --- system/application/config/autoload.php | 1 - system/application/config/config.php | 1 - system/application/config/constants.php | 1 - system/application/config/database.php | 1 - system/application/config/hooks.php | 1 - system/application/config/mimes.php | 1 - system/application/config/routes.php | 1 - system/application/config/smileys.php | 1 - system/application/config/user_agents.php | 1 - system/application/controllers/welcome.php | 1 - system/codeigniter/Base4.php | 1 - system/codeigniter/Base5.php | 1 - system/codeigniter/CodeIgniter.php | 1 - system/codeigniter/Common.php | 1 - system/codeigniter/Compat.php | 1 - system/database/DB.php | 1 - system/database/DB_active_rec.php | 1 - system/database/DB_cache.php | 1 - system/database/DB_driver.php | 1 - system/database/DB_forge.php | 1 - system/database/DB_result.php | 1 - system/database/DB_utility.php | 1 - system/database/drivers/mssql/mssql_driver.php | 1 - system/database/drivers/mssql/mssql_forge.php | 1 - system/database/drivers/mssql/mssql_result.php | 1 - system/database/drivers/mssql/mssql_utility.php | 1 - system/database/drivers/mysql/mysql_driver.php | 1 - system/database/drivers/mysql/mysql_forge.php | 1 - system/database/drivers/mysql/mysql_result.php | 1 - system/database/drivers/mysql/mysql_utility.php | 1 - system/database/drivers/mysqli/mysqli_driver.php | 1 - system/database/drivers/mysqli/mysqli_forge.php | 1 - system/database/drivers/mysqli/mysqli_result.php | 1 - system/database/drivers/mysqli/mysqli_utility.php | 1 - system/database/drivers/oci8/oci8_driver.php | 1 - system/database/drivers/oci8/oci8_forge.php | 1 - system/database/drivers/oci8/oci8_result.php | 1 - system/database/drivers/oci8/oci8_utility.php | 1 - system/database/drivers/odbc/odbc_driver.php | 1 - system/database/drivers/odbc/odbc_forge.php | 1 - system/database/drivers/odbc/odbc_result.php | 1 - system/database/drivers/odbc/odbc_utility.php | 1 - system/database/drivers/postgre/postgre_driver.php | 1 - system/database/drivers/postgre/postgre_forge.php | 1 - system/database/drivers/postgre/postgre_result.php | 1 - system/database/drivers/postgre/postgre_utility.php | 1 - system/database/drivers/sqlite/sqlite_driver.php | 1 - system/database/drivers/sqlite/sqlite_forge.php | 1 - system/database/drivers/sqlite/sqlite_result.php | 1 - system/database/drivers/sqlite/sqlite_utility.php | 1 - system/helpers/array_helper.php | 1 - system/helpers/compatibility_helper.php | 1 - system/helpers/cookie_helper.php | 1 - system/helpers/date_helper.php | 1 - system/helpers/directory_helper.php | 1 - system/helpers/download_helper.php | 1 - system/helpers/email_helper.php | 1 - system/helpers/file_helper.php | 1 - system/helpers/form_helper.php | 1 - system/helpers/html_helper.php | 1 - system/helpers/inflector_helper.php | 1 - system/helpers/path_helper.php | 1 - system/helpers/security_helper.php | 1 - system/helpers/smiley_helper.php | 1 - system/helpers/string_helper.php | 1 - system/helpers/text_helper.php | 1 - system/helpers/typography_helper.php | 1 - system/helpers/url_helper.php | 1 - system/helpers/xml_helper.php | 1 - system/language/english/calendar_lang.php | 1 - system/language/english/date_lang.php | 1 - system/language/english/db_lang.php | 1 - system/language/english/email_lang.php | 1 - system/language/english/ftp_lang.php | 1 - system/language/english/imglib_lang.php | 1 - system/language/english/profiler_lang.php | 1 - system/language/english/scaffolding_lang.php | 1 - system/language/english/unit_test_lang.php | 1 - system/language/english/upload_lang.php | 1 - system/language/english/validation_lang.php | 1 - system/libraries/Benchmark.php | 1 - system/libraries/Calendar.php | 1 - system/libraries/Config.php | 1 - system/libraries/Controller.php | 1 - system/libraries/Email.php | 1 - system/libraries/Encrypt.php | 1 - system/libraries/Exceptions.php | 1 - system/libraries/Ftp.php | 1 - system/libraries/Hooks.php | 1 - system/libraries/Image_lib.php | 1 - system/libraries/Input.php | 1 - system/libraries/Language.php | 1 - system/libraries/Loader.php | 1 - system/libraries/Log.php | 1 - system/libraries/Model.php | 1 - system/libraries/Output.php | 1 - system/libraries/Pagination.php | 1 - system/libraries/Parser.php | 1 - system/libraries/Profiler.php | 1 - system/libraries/Router.php | 1 - system/libraries/Session.php | 1 - system/libraries/Sha1.php | 1 - system/libraries/Table.php | 1 - system/libraries/Trackback.php | 1 - system/libraries/URI.php | 1 - system/libraries/Unit_test.php | 1 - system/libraries/Upload.php | 1 - system/libraries/User_agent.php | 1 - system/libraries/Validation.php | 1 - system/libraries/Xmlrpc.php | 1 - system/libraries/Xmlrpcs.php | 1 - system/libraries/Zip.php | 1 - system/plugins/captcha_pi.php | 1 - system/scaffolding/Scaffolding.php | 1 - 114 files changed, 114 deletions(-) (limited to 'system') diff --git a/system/application/config/autoload.php b/system/application/config/autoload.php index 2dfbe422c..15e2e7b40 100644 --- a/system/application/config/autoload.php +++ b/system/application/config/autoload.php @@ -122,4 +122,3 @@ $autoload['model'] = array(); // $autoload['core'] = array(); -?> \ No newline at end of file diff --git a/system/application/config/config.php b/system/application/config/config.php index 24fbb4b7a..22fe4513a 100644 --- a/system/application/config/config.php +++ b/system/application/config/config.php @@ -311,4 +311,3 @@ $config['time_reference'] = 'local'; $config['rewrite_short_tags'] = FALSE; -?> \ No newline at end of file diff --git a/system/application/config/constants.php b/system/application/config/constants.php index 3f7975635..303d87372 100644 --- a/system/application/config/constants.php +++ b/system/application/config/constants.php @@ -36,4 +36,3 @@ define('FOPEN_READ_WRITE_CREATE', 'a+b'); define('FOPEN_WRITE_CREATE_STRICT', 'xb'); define('FOPEN_READ_WRITE_CREATE_STRICT', 'x+b'); -?> \ No newline at end of file diff --git a/system/application/config/database.php b/system/application/config/database.php index 6973c5afa..feefc77e1 100644 --- a/system/application/config/database.php +++ b/system/application/config/database.php @@ -50,4 +50,3 @@ $db['default']['cachedir'] = ""; $db['default']['char_set'] = "utf8"; $db['default']['dbcollat'] = "utf8_general_ci"; -?> \ No newline at end of file diff --git a/system/application/config/hooks.php b/system/application/config/hooks.php index f0a0d6e3a..4fce538d0 100644 --- a/system/application/config/hooks.php +++ b/system/application/config/hooks.php @@ -11,4 +11,3 @@ */ -?> \ No newline at end of file diff --git a/system/application/config/mimes.php b/system/application/config/mimes.php index 7f5f20803..fae325b24 100644 --- a/system/application/config/mimes.php +++ b/system/application/config/mimes.php @@ -99,4 +99,3 @@ $mimes = array( 'hqx' => 'application/mac-binhex40', ); -?> \ No newline at end of file diff --git a/system/application/config/routes.php b/system/application/config/routes.php index 1395b7aed..ec03d77b5 100644 --- a/system/application/config/routes.php +++ b/system/application/config/routes.php @@ -43,4 +43,3 @@ $route['default_controller'] = "welcome"; $route['scaffolding_trigger'] = ""; -?> \ No newline at end of file diff --git a/system/application/config/smileys.php b/system/application/config/smileys.php index a227d8b68..abecede68 100644 --- a/system/application/config/smileys.php +++ b/system/application/config/smileys.php @@ -61,4 +61,3 @@ $smileys = array( ':question:' => array('question.gif', '19', '19', 'question') // no comma after last item ); -?> \ No newline at end of file diff --git a/system/application/config/user_agents.php b/system/application/config/user_agents.php index 08a665f9d..873a5a503 100644 --- a/system/application/config/user_agents.php +++ b/system/application/config/user_agents.php @@ -100,4 +100,3 @@ $robots = array( ); -?> \ No newline at end of file diff --git a/system/application/controllers/welcome.php b/system/application/controllers/welcome.php index 7f7296d81..243423a65 100644 --- a/system/application/controllers/welcome.php +++ b/system/application/controllers/welcome.php @@ -12,4 +12,3 @@ class Welcome extends Controller { $this->load->view('welcome_message'); } } -?> \ No newline at end of file diff --git a/system/codeigniter/Base4.php b/system/codeigniter/Base4.php index 577977c1c..fcf8b9850 100644 --- a/system/codeigniter/Base4.php +++ b/system/codeigniter/Base4.php @@ -64,4 +64,3 @@ function &get_instance() return $OBJ->load; } -?> \ No newline at end of file diff --git a/system/codeigniter/Base5.php b/system/codeigniter/Base5.php index c731a00c4..9e0e20d6c 100644 --- a/system/codeigniter/Base5.php +++ b/system/codeigniter/Base5.php @@ -51,4 +51,3 @@ function &get_instance() } -?> \ No newline at end of file diff --git a/system/codeigniter/CodeIgniter.php b/system/codeigniter/CodeIgniter.php index 75332e678..12a7423c4 100644 --- a/system/codeigniter/CodeIgniter.php +++ b/system/codeigniter/CodeIgniter.php @@ -273,4 +273,3 @@ if (class_exists('CI_DB') AND isset($CI->db)) } -?> \ No newline at end of file diff --git a/system/codeigniter/Common.php b/system/codeigniter/Common.php index c5c548cdf..874f588b5 100644 --- a/system/codeigniter/Common.php +++ b/system/codeigniter/Common.php @@ -295,4 +295,3 @@ function _exception_handler($severity, $message, $filepath, $line) } -?> \ No newline at end of file diff --git a/system/codeigniter/Compat.php b/system/codeigniter/Compat.php index 8537432f5..469964a09 100644 --- a/system/codeigniter/Compat.php +++ b/system/codeigniter/Compat.php @@ -91,4 +91,3 @@ if (! function_exists('ctype_alnum')) // -------------------------------------------------------------------- -?> \ No newline at end of file diff --git a/system/database/DB.php b/system/database/DB.php index 8efe05560..55d73ba0b 100644 --- a/system/database/DB.php +++ b/system/database/DB.php @@ -120,4 +120,3 @@ function &DB($params = '', $active_record_override = FALSE) } -?> \ No newline at end of file diff --git a/system/database/DB_active_rec.php b/system/database/DB_active_rec.php index 49d438727..af042dcd2 100644 --- a/system/database/DB_active_rec.php +++ b/system/database/DB_active_rec.php @@ -1749,4 +1749,3 @@ class CI_DB_active_record extends CI_DB_driver { } } -?> \ No newline at end of file diff --git a/system/database/DB_cache.php b/system/database/DB_cache.php index 982725aaa..a154ba86d 100644 --- a/system/database/DB_cache.php +++ b/system/database/DB_cache.php @@ -186,4 +186,3 @@ class CI_DB_Cache { } -?> \ No newline at end of file diff --git a/system/database/DB_driver.php b/system/database/DB_driver.php index a5ca75dd6..dd235103e 100644 --- a/system/database/DB_driver.php +++ b/system/database/DB_driver.php @@ -1145,4 +1145,3 @@ class CI_DB_driver { } -?> \ No newline at end of file diff --git a/system/database/DB_forge.php b/system/database/DB_forge.php index 2ddb21be7..258da346d 100644 --- a/system/database/DB_forge.php +++ b/system/database/DB_forge.php @@ -341,4 +341,3 @@ class CI_DB_forge { } } -?> \ No newline at end of file diff --git a/system/database/DB_result.php b/system/database/DB_result.php index cfe9d2a32..90338d0c4 100644 --- a/system/database/DB_result.php +++ b/system/database/DB_result.php @@ -338,4 +338,3 @@ class CI_DB_result { } // END DB_result class -?> \ No newline at end of file diff --git a/system/database/DB_utility.php b/system/database/DB_utility.php index 11f1fb4de..2604a3e76 100644 --- a/system/database/DB_utility.php +++ b/system/database/DB_utility.php @@ -384,4 +384,3 @@ class CI_DB_utility extends CI_DB_forge { } -?> \ No newline at end of file diff --git a/system/database/drivers/mssql/mssql_driver.php b/system/database/drivers/mssql/mssql_driver.php index 6e67c57c0..3a9bb31cc 100644 --- a/system/database/drivers/mssql/mssql_driver.php +++ b/system/database/drivers/mssql/mssql_driver.php @@ -641,4 +641,3 @@ class CI_DB_mssql_driver extends CI_DB { } -?> \ No newline at end of file diff --git a/system/database/drivers/mssql/mssql_forge.php b/system/database/drivers/mssql/mssql_forge.php index 63063f259..b81b565eb 100644 --- a/system/database/drivers/mssql/mssql_forge.php +++ b/system/database/drivers/mssql/mssql_forge.php @@ -235,4 +235,3 @@ class CI_DB_mssql_forge extends CI_DB_forge { } } -?> \ No newline at end of file diff --git a/system/database/drivers/mssql/mssql_result.php b/system/database/drivers/mssql/mssql_result.php index c95fd91f6..9044bc095 100644 --- a/system/database/drivers/mssql/mssql_result.php +++ b/system/database/drivers/mssql/mssql_result.php @@ -170,4 +170,3 @@ class CI_DB_mssql_result extends CI_DB_result { } -?> \ No newline at end of file diff --git a/system/database/drivers/mssql/mssql_utility.php b/system/database/drivers/mssql/mssql_utility.php index 87f8196f7..9ba65742c 100644 --- a/system/database/drivers/mssql/mssql_utility.php +++ b/system/database/drivers/mssql/mssql_utility.php @@ -118,4 +118,3 @@ class CI_DB_mssql_utility extends CI_DB_utility { } -?> \ No newline at end of file diff --git a/system/database/drivers/mysql/mysql_driver.php b/system/database/drivers/mysql/mysql_driver.php index f15983d2b..9fd042151 100644 --- a/system/database/drivers/mysql/mysql_driver.php +++ b/system/database/drivers/mysql/mysql_driver.php @@ -649,4 +649,3 @@ class CI_DB_mysql_driver extends CI_DB { } -?> \ No newline at end of file diff --git a/system/database/drivers/mysql/mysql_forge.php b/system/database/drivers/mysql/mysql_forge.php index 4eb449ef2..e9ea94706 100644 --- a/system/database/drivers/mysql/mysql_forge.php +++ b/system/database/drivers/mysql/mysql_forge.php @@ -238,4 +238,3 @@ class CI_DB_mysql_forge extends CI_DB_forge { } } -?> \ No newline at end of file diff --git a/system/database/drivers/mysql/mysql_result.php b/system/database/drivers/mysql/mysql_result.php index 9e6a3c3d1..7c5125fc4 100644 --- a/system/database/drivers/mysql/mysql_result.php +++ b/system/database/drivers/mysql/mysql_result.php @@ -170,4 +170,3 @@ class CI_DB_mysql_result extends CI_DB_result { } -?> \ No newline at end of file diff --git a/system/database/drivers/mysql/mysql_utility.php b/system/database/drivers/mysql/mysql_utility.php index dc8fd0866..22bc23383 100644 --- a/system/database/drivers/mysql/mysql_utility.php +++ b/system/database/drivers/mysql/mysql_utility.php @@ -249,4 +249,3 @@ class CI_DB_mysql_utility extends CI_DB_utility { } } -?> \ No newline at end of file diff --git a/system/database/drivers/mysqli/mysqli_driver.php b/system/database/drivers/mysqli/mysqli_driver.php index a196f755a..4ffbbaca1 100644 --- a/system/database/drivers/mysqli/mysqli_driver.php +++ b/system/database/drivers/mysqli/mysqli_driver.php @@ -645,4 +645,3 @@ class CI_DB_mysqli_driver extends CI_DB { } -?> \ No newline at end of file diff --git a/system/database/drivers/mysqli/mysqli_forge.php b/system/database/drivers/mysqli/mysqli_forge.php index e6bc0093f..a0ff9f574 100644 --- a/system/database/drivers/mysqli/mysqli_forge.php +++ b/system/database/drivers/mysqli/mysqli_forge.php @@ -238,4 +238,3 @@ class CI_DB_mysqli_forge extends CI_DB_forge { } } -?> \ No newline at end of file diff --git a/system/database/drivers/mysqli/mysqli_result.php b/system/database/drivers/mysqli/mysqli_result.php index 692d4f729..b1a060405 100644 --- a/system/database/drivers/mysqli/mysqli_result.php +++ b/system/database/drivers/mysqli/mysqli_result.php @@ -170,4 +170,3 @@ class CI_DB_mysqli_result extends CI_DB_result { } -?> \ No newline at end of file diff --git a/system/database/drivers/mysqli/mysqli_utility.php b/system/database/drivers/mysqli/mysqli_utility.php index 4ab2bb1d1..75f4a4192 100644 --- a/system/database/drivers/mysqli/mysqli_utility.php +++ b/system/database/drivers/mysqli/mysqli_utility.php @@ -118,4 +118,3 @@ class CI_DB_mysqli_utility extends CI_DB_utility { } } -?> \ No newline at end of file diff --git a/system/database/drivers/oci8/oci8_driver.php b/system/database/drivers/oci8/oci8_driver.php index 8fc20449f..fb288087c 100644 --- a/system/database/drivers/oci8/oci8_driver.php +++ b/system/database/drivers/oci8/oci8_driver.php @@ -761,4 +761,3 @@ class CI_DB_oci8_driver extends CI_DB { } -?> \ No newline at end of file diff --git a/system/database/drivers/oci8/oci8_forge.php b/system/database/drivers/oci8/oci8_forge.php index a3940aedb..6ca6c5434 100644 --- a/system/database/drivers/oci8/oci8_forge.php +++ b/system/database/drivers/oci8/oci8_forge.php @@ -232,4 +232,3 @@ class CI_DB_oci8_forge extends CI_DB_forge { } -?> \ No newline at end of file diff --git a/system/database/drivers/oci8/oci8_result.php b/system/database/drivers/oci8/oci8_result.php index 30dd0da09..9f1257642 100644 --- a/system/database/drivers/oci8/oci8_result.php +++ b/system/database/drivers/oci8/oci8_result.php @@ -248,4 +248,3 @@ class CI_DB_oci8_result extends CI_DB_result { } -?> \ No newline at end of file diff --git a/system/database/drivers/oci8/oci8_utility.php b/system/database/drivers/oci8/oci8_utility.php index 117f8e629..c361c5ec3 100644 --- a/system/database/drivers/oci8/oci8_utility.php +++ b/system/database/drivers/oci8/oci8_utility.php @@ -117,4 +117,3 @@ class CI_DB_oci8_utility extends CI_DB_utility { } } -?> \ No newline at end of file diff --git a/system/database/drivers/odbc/odbc_driver.php b/system/database/drivers/odbc/odbc_driver.php index 20e34ec7b..93a1d4e05 100644 --- a/system/database/drivers/odbc/odbc_driver.php +++ b/system/database/drivers/odbc/odbc_driver.php @@ -613,4 +613,3 @@ class CI_DB_odbc_driver extends CI_DB { } -?> \ No newline at end of file diff --git a/system/database/drivers/odbc/odbc_forge.php b/system/database/drivers/odbc/odbc_forge.php index 66e1722d8..ee4745ccc 100644 --- a/system/database/drivers/odbc/odbc_forge.php +++ b/system/database/drivers/odbc/odbc_forge.php @@ -253,4 +253,3 @@ class CI_DB_odbc_forge extends CI_DB_forge { } -?> \ No newline at end of file diff --git a/system/database/drivers/odbc/odbc_result.php b/system/database/drivers/odbc/odbc_result.php index dd3f92382..d513171d0 100644 --- a/system/database/drivers/odbc/odbc_result.php +++ b/system/database/drivers/odbc/odbc_result.php @@ -229,4 +229,3 @@ class CI_DB_odbc_result extends CI_DB_result { } -?> \ No newline at end of file diff --git a/system/database/drivers/odbc/odbc_utility.php b/system/database/drivers/odbc/odbc_utility.php index f74d031bd..75d1ca283 100644 --- a/system/database/drivers/odbc/odbc_utility.php +++ b/system/database/drivers/odbc/odbc_utility.php @@ -143,4 +143,3 @@ class CI_DB_odbc_utility extends CI_DB_utility { return FALSE; } } -?> \ No newline at end of file diff --git a/system/database/drivers/postgre/postgre_driver.php b/system/database/drivers/postgre/postgre_driver.php index 46ba1d009..7c46e7a4b 100644 --- a/system/database/drivers/postgre/postgre_driver.php +++ b/system/database/drivers/postgre/postgre_driver.php @@ -641,4 +641,3 @@ class CI_DB_postgre_driver extends CI_DB { } -?> \ No newline at end of file diff --git a/system/database/drivers/postgre/postgre_forge.php b/system/database/drivers/postgre/postgre_forge.php index 72a61748d..ad4c5cdae 100644 --- a/system/database/drivers/postgre/postgre_forge.php +++ b/system/database/drivers/postgre/postgre_forge.php @@ -235,4 +235,3 @@ class CI_DB_postgre_forge extends CI_DB_forge { } -?> \ No newline at end of file diff --git a/system/database/drivers/postgre/postgre_result.php b/system/database/drivers/postgre/postgre_result.php index fdce01aac..f3fb89951 100644 --- a/system/database/drivers/postgre/postgre_result.php +++ b/system/database/drivers/postgre/postgre_result.php @@ -170,4 +170,3 @@ class CI_DB_postgre_result extends CI_DB_result { } -?> \ No newline at end of file diff --git a/system/database/drivers/postgre/postgre_utility.php b/system/database/drivers/postgre/postgre_utility.php index 573654f68..25f44f06c 100644 --- a/system/database/drivers/postgre/postgre_utility.php +++ b/system/database/drivers/postgre/postgre_utility.php @@ -119,4 +119,3 @@ class CI_DB_postgre_utility extends CI_DB_utility { } -?> \ No newline at end of file diff --git a/system/database/drivers/sqlite/sqlite_driver.php b/system/database/drivers/sqlite/sqlite_driver.php index 70148f360..f84ee2095 100644 --- a/system/database/drivers/sqlite/sqlite_driver.php +++ b/system/database/drivers/sqlite/sqlite_driver.php @@ -656,4 +656,3 @@ class CI_DB_sqlite_driver extends CI_DB { } -?> \ No newline at end of file diff --git a/system/database/drivers/sqlite/sqlite_forge.php b/system/database/drivers/sqlite/sqlite_forge.php index 44950bfc7..8afd39e99 100644 --- a/system/database/drivers/sqlite/sqlite_forge.php +++ b/system/database/drivers/sqlite/sqlite_forge.php @@ -231,4 +231,3 @@ class CI_DB_sqlite_forge extends CI_DB_forge { } } -?> \ No newline at end of file diff --git a/system/database/drivers/sqlite/sqlite_result.php b/system/database/drivers/sqlite/sqlite_result.php index b8f3dc5b7..92bc3872a 100644 --- a/system/database/drivers/sqlite/sqlite_result.php +++ b/system/database/drivers/sqlite/sqlite_result.php @@ -180,4 +180,3 @@ class CI_DB_sqlite_result extends CI_DB_result { } -?> \ No newline at end of file diff --git a/system/database/drivers/sqlite/sqlite_utility.php b/system/database/drivers/sqlite/sqlite_utility.php index ab58f8fd7..8d2b44362 100644 --- a/system/database/drivers/sqlite/sqlite_utility.php +++ b/system/database/drivers/sqlite/sqlite_utility.php @@ -136,4 +136,3 @@ class CI_DB_sqlite_utility extends CI_DB_utility { } } -?> \ No newline at end of file diff --git a/system/helpers/array_helper.php b/system/helpers/array_helper.php index 8ae44826a..0d9fc0b47 100644 --- a/system/helpers/array_helper.php +++ b/system/helpers/array_helper.php @@ -73,4 +73,3 @@ if (! function_exists('random_element')) } } -?> \ No newline at end of file diff --git a/system/helpers/compatibility_helper.php b/system/helpers/compatibility_helper.php index 0d214648c..ee7e77058 100644 --- a/system/helpers/compatibility_helper.php +++ b/system/helpers/compatibility_helper.php @@ -493,4 +493,3 @@ if (! function_exists('http_build_query')) } } -?> \ No newline at end of file diff --git a/system/helpers/cookie_helper.php b/system/helpers/cookie_helper.php index 75c769e9c..0d21f11e4 100644 --- a/system/helpers/cookie_helper.php +++ b/system/helpers/cookie_helper.php @@ -131,4 +131,3 @@ if (! function_exists('delete_cookie')) } } -?> \ No newline at end of file diff --git a/system/helpers/date_helper.php b/system/helpers/date_helper.php index 004cfb122..447146860 100644 --- a/system/helpers/date_helper.php +++ b/system/helpers/date_helper.php @@ -596,4 +596,3 @@ if (! function_exists('timezones')) } } -?> \ No newline at end of file diff --git a/system/helpers/directory_helper.php b/system/helpers/directory_helper.php index 25c16c1fc..a3227c810 100644 --- a/system/helpers/directory_helper.php +++ b/system/helpers/directory_helper.php @@ -75,4 +75,3 @@ if (! function_exists('directory_map')) } } -?> \ No newline at end of file diff --git a/system/helpers/download_helper.php b/system/helpers/download_helper.php index 284c6c96e..39c2a2afc 100644 --- a/system/helpers/download_helper.php +++ b/system/helpers/download_helper.php @@ -95,4 +95,3 @@ if (! function_exists('force_download')) } } -?> \ No newline at end of file diff --git a/system/helpers/email_helper.php b/system/helpers/email_helper.php index 307f3b588..a1452cec9 100644 --- a/system/helpers/email_helper.php +++ b/system/helpers/email_helper.php @@ -57,4 +57,3 @@ if (! function_exists('send_email')) } } -?> \ No newline at end of file diff --git a/system/helpers/file_helper.php b/system/helpers/file_helper.php index bdde2d55d..0c2ae5af6 100644 --- a/system/helpers/file_helper.php +++ b/system/helpers/file_helper.php @@ -456,4 +456,3 @@ if (! function_exists('octal_permissions')) } } -?> \ No newline at end of file diff --git a/system/helpers/form_helper.php b/system/helpers/form_helper.php index c9a6897ae..c91e5a5c7 100644 --- a/system/helpers/form_helper.php +++ b/system/helpers/form_helper.php @@ -610,4 +610,3 @@ if (! function_exists('parse_form_attributes')) } } -?> \ No newline at end of file diff --git a/system/helpers/html_helper.php b/system/helpers/html_helper.php index 4e86465c1..f488a5d3d 100644 --- a/system/helpers/html_helper.php +++ b/system/helpers/html_helper.php @@ -351,4 +351,3 @@ if (! function_exists('nbs')) } } -?> \ No newline at end of file diff --git a/system/helpers/inflector_helper.php b/system/helpers/inflector_helper.php index bf70a6799..a833c70b8 100644 --- a/system/helpers/inflector_helper.php +++ b/system/helpers/inflector_helper.php @@ -164,4 +164,3 @@ if (! function_exists('humanize')) } } -?> \ No newline at end of file diff --git a/system/helpers/path_helper.php b/system/helpers/path_helper.php index 6abff06af..8ff9f2425 100644 --- a/system/helpers/path_helper.php +++ b/system/helpers/path_helper.php @@ -67,4 +67,3 @@ if (! function_exists('set_realpath')) } } -?> \ No newline at end of file diff --git a/system/helpers/security_helper.php b/system/helpers/security_helper.php index edb6ebb50..6e61aa71d 100644 --- a/system/helpers/security_helper.php +++ b/system/helpers/security_helper.php @@ -121,4 +121,3 @@ if (! function_exists('encode_php_tags')) } } -?> \ No newline at end of file diff --git a/system/helpers/smiley_helper.php b/system/helpers/smiley_helper.php index 81c6b9199..d65801834 100644 --- a/system/helpers/smiley_helper.php +++ b/system/helpers/smiley_helper.php @@ -170,4 +170,3 @@ if (! function_exists('_get_smiley_array')) } } -?> \ No newline at end of file diff --git a/system/helpers/string_helper.php b/system/helpers/string_helper.php index f68f44ac1..cd2af0cef 100644 --- a/system/helpers/string_helper.php +++ b/system/helpers/string_helper.php @@ -268,4 +268,3 @@ if (! function_exists('repeater')) } } -?> \ No newline at end of file diff --git a/system/helpers/text_helper.php b/system/helpers/text_helper.php index df3c89e6f..95c2c619b 100644 --- a/system/helpers/text_helper.php +++ b/system/helpers/text_helper.php @@ -436,4 +436,3 @@ if (! function_exists('word_wrap')) } } -?> \ No newline at end of file diff --git a/system/helpers/typography_helper.php b/system/helpers/typography_helper.php index 88071604d..82573844b 100644 --- a/system/helpers/typography_helper.php +++ b/system/helpers/typography_helper.php @@ -542,4 +542,3 @@ class Auto_typography { } -?> \ No newline at end of file diff --git a/system/helpers/url_helper.php b/system/helpers/url_helper.php index d702f6b87..1c6c5c552 100644 --- a/system/helpers/url_helper.php +++ b/system/helpers/url_helper.php @@ -532,4 +532,3 @@ if (! function_exists('_parse_attributes')) } } -?> \ No newline at end of file diff --git a/system/helpers/xml_helper.php b/system/helpers/xml_helper.php index 5aa6de9ec..a3d08f622 100644 --- a/system/helpers/xml_helper.php +++ b/system/helpers/xml_helper.php @@ -57,4 +57,3 @@ if (! function_exists('xml_convert')) } } -?> \ No newline at end of file diff --git a/system/language/english/calendar_lang.php b/system/language/english/calendar_lang.php index 9ee4a5e69..62f24ac57 100644 --- a/system/language/english/calendar_lang.php +++ b/system/language/english/calendar_lang.php @@ -46,4 +46,3 @@ $lang['cal_october'] = "October"; $lang['cal_november'] = "November"; $lang['cal_december'] = "December"; -?> \ No newline at end of file diff --git a/system/language/english/date_lang.php b/system/language/english/date_lang.php index 6b18aa7be..6cb93031f 100644 --- a/system/language/english/date_lang.php +++ b/system/language/english/date_lang.php @@ -46,4 +46,3 @@ $lang['UP10'] = "(UTC + 10:00) Melbourne, Papua New Guinea, Sydney, Vladivostok" $lang['UP11'] = "(UTC + 11:00) Magadan, New Caledonia, Solomon Islands"; $lang['UP12'] = "(UTC + 12:00) Auckland, Wellington, Fiji, Marshall Islands"; -?> \ No newline at end of file diff --git a/system/language/english/db_lang.php b/system/language/english/db_lang.php index 1e79a706d..2748bf9c8 100644 --- a/system/language/english/db_lang.php +++ b/system/language/english/db_lang.php @@ -22,4 +22,3 @@ $lang['db_column_name_required'] = 'A column name is required for that operation $lang['db_column_definition_required'] = 'A column definition is required for that operation.'; $lang['db_unable_to_set_charset'] = 'Unable to set client connection character set: %s'; -?> \ No newline at end of file diff --git a/system/language/english/email_lang.php b/system/language/english/email_lang.php index f02686509..5e3dc106c 100644 --- a/system/language/english/email_lang.php +++ b/system/language/english/email_lang.php @@ -18,4 +18,3 @@ $lang['email_smtp_auth_un'] = "Failed to authenticate username. Error: %s"; $lang['email_smtp_auth_pw'] = "Failed to authenticate password. Error: %s"; $lang['email_smtp_data_failure'] = "Unable to send data: %s"; -?> \ No newline at end of file diff --git a/system/language/english/ftp_lang.php b/system/language/english/ftp_lang.php index da744fea7..7b9203338 100644 --- a/system/language/english/ftp_lang.php +++ b/system/language/english/ftp_lang.php @@ -12,4 +12,3 @@ $lang['ftp_unable_to_rename'] = "Unable to rename the file."; $lang['ftp_unable_to_delete'] = "Unable to delete the file."; $lang['ftp_unable_to_move'] = "Unable to move the file. Please make sure the destination directory exists."; -?> \ No newline at end of file diff --git a/system/language/english/imglib_lang.php b/system/language/english/imglib_lang.php index 520f17f35..78e1ec2fb 100644 --- a/system/language/english/imglib_lang.php +++ b/system/language/english/imglib_lang.php @@ -18,4 +18,3 @@ $lang['imglib_invalid_path'] = "The path to the image is not correct."; $lang['imglib_copy_failed'] = "The image copy routine failed."; $lang['imglib_missing_font'] = "Unable to find a font to use."; -?> \ No newline at end of file diff --git a/system/language/english/profiler_lang.php b/system/language/english/profiler_lang.php index 219a83856..c8f183511 100644 --- a/system/language/english/profiler_lang.php +++ b/system/language/english/profiler_lang.php @@ -12,4 +12,3 @@ $lang['profiler_no_post'] = 'No POST data exists'; $lang['profiler_no_get'] = 'No GET data exists'; $lang['profiler_no_uri'] = 'No URI data exists'; $lang['profiler_no_memory'] = 'Memory Usage Unavailable'; -?> \ No newline at end of file diff --git a/system/language/english/scaffolding_lang.php b/system/language/english/scaffolding_lang.php index 96fe167e5..4e3cde7dc 100644 --- a/system/language/english/scaffolding_lang.php +++ b/system/language/english/scaffolding_lang.php @@ -12,4 +12,3 @@ $lang['scaff_no'] = 'No'; $lang['scaff_no_data'] = 'No data exists for this table yet.'; $lang['scaff_del_confirm'] = 'Are you sure you want to delete the following row:'; -?> \ No newline at end of file diff --git a/system/language/english/unit_test_lang.php b/system/language/english/unit_test_lang.php index a33cad5f2..aa71ad2e5 100644 --- a/system/language/english/unit_test_lang.php +++ b/system/language/english/unit_test_lang.php @@ -19,4 +19,3 @@ $lang['ut_object'] = 'Object'; $lang['ut_resource'] = 'Resource'; $lang['ut_null'] = 'Null' -?> \ No newline at end of file diff --git a/system/language/english/upload_lang.php b/system/language/english/upload_lang.php index fa6d7c9fb..4667489c9 100644 --- a/system/language/english/upload_lang.php +++ b/system/language/english/upload_lang.php @@ -17,4 +17,3 @@ $lang['upload_no_file_types'] = "You have not specified any allowed file types." $lang['upload_bad_filename'] = "The file name you submitted already exists on the server."; $lang['upload_not_writable'] = "The upload destination folder does not appear to be writable."; -?> \ No newline at end of file diff --git a/system/language/english/validation_lang.php b/system/language/english/validation_lang.php index 1e9ec2c1b..82fd9c99d 100644 --- a/system/language/english/validation_lang.php +++ b/system/language/english/validation_lang.php @@ -15,4 +15,3 @@ $lang['numeric'] = "The %s field must contain a number."; $lang['integer'] = "The %s field must contain an integer."; $lang['matches'] = "The %s field does not match the %s field."; -?> \ No newline at end of file diff --git a/system/libraries/Benchmark.php b/system/libraries/Benchmark.php index 323d9668d..db9239d61 100644 --- a/system/libraries/Benchmark.php +++ b/system/libraries/Benchmark.php @@ -108,4 +108,3 @@ class CI_Benchmark { } // END CI_Benchmark class -?> \ No newline at end of file diff --git a/system/libraries/Calendar.php b/system/libraries/Calendar.php index e9621fec1..42e70f4de 100644 --- a/system/libraries/Calendar.php +++ b/system/libraries/Calendar.php @@ -472,4 +472,3 @@ class CI_Calendar { } // END CI_Calendar class -?> \ No newline at end of file diff --git a/system/libraries/Config.php b/system/libraries/Config.php index 73f1986a0..a3a7d9d75 100644 --- a/system/libraries/Config.php +++ b/system/libraries/Config.php @@ -242,4 +242,3 @@ class CI_Config { } // END CI_Config class -?> \ No newline at end of file diff --git a/system/libraries/Controller.php b/system/libraries/Controller.php index 4957fc35e..e5b2f2796 100644 --- a/system/libraries/Controller.php +++ b/system/libraries/Controller.php @@ -121,4 +121,3 @@ class Controller extends CI_Base { } // END _Controller class -?> \ No newline at end of file diff --git a/system/libraries/Email.php b/system/libraries/Email.php index aa08971f9..bb72ad439 100644 --- a/system/libraries/Email.php +++ b/system/libraries/Email.php @@ -1848,4 +1848,3 @@ class CI_Email { } // END CI_Email class -?> \ No newline at end of file diff --git a/system/libraries/Encrypt.php b/system/libraries/Encrypt.php index 9a784d254..7463fd0a6 100644 --- a/system/libraries/Encrypt.php +++ b/system/libraries/Encrypt.php @@ -481,4 +481,3 @@ class CI_Encrypt { } // END CI_Encrypt class -?> \ No newline at end of file diff --git a/system/libraries/Exceptions.php b/system/libraries/Exceptions.php index 7c9640554..0b647df39 100644 --- a/system/libraries/Exceptions.php +++ b/system/libraries/Exceptions.php @@ -167,4 +167,3 @@ class CI_Exceptions { } // END Exceptions Class -?> \ No newline at end of file diff --git a/system/libraries/Ftp.php b/system/libraries/Ftp.php index 74b7728fa..f45f992d1 100644 --- a/system/libraries/Ftp.php +++ b/system/libraries/Ftp.php @@ -613,4 +613,3 @@ class CI_FTP { } // END FTP Class -?> \ No newline at end of file diff --git a/system/libraries/Hooks.php b/system/libraries/Hooks.php index a41320c5e..c68b42353 100644 --- a/system/libraries/Hooks.php +++ b/system/libraries/Hooks.php @@ -221,4 +221,3 @@ class CI_Hooks { } // END CI_Hooks class -?> \ No newline at end of file diff --git a/system/libraries/Image_lib.php b/system/libraries/Image_lib.php index c236e391e..d2f464044 100644 --- a/system/libraries/Image_lib.php +++ b/system/libraries/Image_lib.php @@ -1533,4 +1533,3 @@ class CI_Image_lib { } // END Image_lib Class -?> \ No newline at end of file diff --git a/system/libraries/Input.php b/system/libraries/Input.php index 8a0478be2..9d64a2cb4 100644 --- a/system/libraries/Input.php +++ b/system/libraries/Input.php @@ -923,4 +923,3 @@ class CI_Input { } // END Input class -?> \ No newline at end of file diff --git a/system/libraries/Language.php b/system/libraries/Language.php index a8e6366bb..45c839250 100644 --- a/system/libraries/Language.php +++ b/system/libraries/Language.php @@ -118,4 +118,3 @@ class CI_Language { } // END Language Class -?> \ No newline at end of file diff --git a/system/libraries/Loader.php b/system/libraries/Loader.php index 5966aebf6..60dc73b1f 100644 --- a/system/libraries/Loader.php +++ b/system/libraries/Loader.php @@ -1027,4 +1027,3 @@ class CI_Loader { } } -?> \ No newline at end of file diff --git a/system/libraries/Log.php b/system/libraries/Log.php index 26757ba50..1754b3980 100644 --- a/system/libraries/Log.php +++ b/system/libraries/Log.php @@ -115,4 +115,3 @@ class CI_Log { } // END Log Class -?> \ No newline at end of file diff --git a/system/libraries/Model.php b/system/libraries/Model.php index e87d6045c..ce8e128ad 100644 --- a/system/libraries/Model.php +++ b/system/libraries/Model.php @@ -79,4 +79,3 @@ class Model { } // END Model Class -?> \ No newline at end of file diff --git a/system/libraries/Output.php b/system/libraries/Output.php index d513a1279..69206f519 100644 --- a/system/libraries/Output.php +++ b/system/libraries/Output.php @@ -383,4 +383,3 @@ class CI_Output { } // END Output Class -?> \ No newline at end of file diff --git a/system/libraries/Pagination.php b/system/libraries/Pagination.php index e1212035a..68bd1892d 100644 --- a/system/libraries/Pagination.php +++ b/system/libraries/Pagination.php @@ -215,4 +215,3 @@ class CI_Pagination { } } // END Pagination Class -?> \ No newline at end of file diff --git a/system/libraries/Parser.php b/system/libraries/Parser.php index 417e04f29..d2bdba11a 100644 --- a/system/libraries/Parser.php +++ b/system/libraries/Parser.php @@ -168,4 +168,3 @@ class CI_Parser { } // END Parser Class -?> \ No newline at end of file diff --git a/system/libraries/Profiler.php b/system/libraries/Profiler.php index 807c1aff6..38f0d2346 100644 --- a/system/libraries/Profiler.php +++ b/system/libraries/Profiler.php @@ -340,4 +340,3 @@ class CI_Profiler { } // END CI_Profiler class -?> \ No newline at end of file diff --git a/system/libraries/Router.php b/system/libraries/Router.php index 6bb85518f..ade01a6c1 100644 --- a/system/libraries/Router.php +++ b/system/libraries/Router.php @@ -374,4 +374,3 @@ class CI_Router { } // END Router Class -?> \ No newline at end of file diff --git a/system/libraries/Session.php b/system/libraries/Session.php index d4fdd3ac7..c77eb9e0a 100644 --- a/system/libraries/Session.php +++ b/system/libraries/Session.php @@ -649,4 +649,3 @@ class CI_Session { } // END Session Class -?> \ No newline at end of file diff --git a/system/libraries/Sha1.php b/system/libraries/Sha1.php index 6bb891177..768ffa166 100644 --- a/system/libraries/Sha1.php +++ b/system/libraries/Sha1.php @@ -246,4 +246,3 @@ class CI_SHA { } } // END CI_SHA -?> \ No newline at end of file diff --git a/system/libraries/Table.php b/system/libraries/Table.php index 01b490a5d..5edb5e4cc 100644 --- a/system/libraries/Table.php +++ b/system/libraries/Table.php @@ -435,4 +435,3 @@ class CI_Table { } -?> \ No newline at end of file diff --git a/system/libraries/Trackback.php b/system/libraries/Trackback.php index 3e1c20210..b4c296d1e 100644 --- a/system/libraries/Trackback.php +++ b/system/libraries/Trackback.php @@ -545,4 +545,3 @@ class CI_Trackback { } // END Trackback Class -?> \ No newline at end of file diff --git a/system/libraries/URI.php b/system/libraries/URI.php index 8ee888a2e..59fcff3d7 100644 --- a/system/libraries/URI.php +++ b/system/libraries/URI.php @@ -586,4 +586,3 @@ class CI_URI { } // END URI Class -?> \ No newline at end of file diff --git a/system/libraries/Unit_test.php b/system/libraries/Unit_test.php index 3cdf45f12..e02ecf037 100644 --- a/system/libraries/Unit_test.php +++ b/system/libraries/Unit_test.php @@ -340,4 +340,3 @@ function is_false($test) return (is_bool($test) AND $test === FALSE) ? TRUE : FALSE; } -?> \ No newline at end of file diff --git a/system/libraries/Upload.php b/system/libraries/Upload.php index 317cf9560..e0ce2b037 100644 --- a/system/libraries/Upload.php +++ b/system/libraries/Upload.php @@ -875,4 +875,3 @@ class CI_Upload { } // END Upload Class -?> \ No newline at end of file diff --git a/system/libraries/User_agent.php b/system/libraries/User_agent.php index dd60a56a1..a8ce787dc 100644 --- a/system/libraries/User_agent.php +++ b/system/libraries/User_agent.php @@ -497,4 +497,3 @@ class CI_User_agent { } -?> \ No newline at end of file diff --git a/system/libraries/Validation.php b/system/libraries/Validation.php index f628d8612..8a81568c4 100644 --- a/system/libraries/Validation.php +++ b/system/libraries/Validation.php @@ -805,4 +805,3 @@ class CI_Validation { } // END Validation Class -?> \ No newline at end of file diff --git a/system/libraries/Xmlrpc.php b/system/libraries/Xmlrpc.php index f8ad01714..dee71f4d1 100644 --- a/system/libraries/Xmlrpc.php +++ b/system/libraries/Xmlrpc.php @@ -1416,4 +1416,3 @@ class XML_RPC_Values extends CI_Xmlrpc } // END XML_RPC_Values Class -?> \ No newline at end of file diff --git a/system/libraries/Xmlrpcs.php b/system/libraries/Xmlrpcs.php index 7a4bc825e..11f0cfc40 100644 --- a/system/libraries/Xmlrpcs.php +++ b/system/libraries/Xmlrpcs.php @@ -531,4 +531,3 @@ class CI_Xmlrpcs extends CI_Xmlrpc } // END XML_RPC_Server class -?> \ No newline at end of file diff --git a/system/libraries/Zip.php b/system/libraries/Zip.php index f7f47ab42..1940ded37 100644 --- a/system/libraries/Zip.php +++ b/system/libraries/Zip.php @@ -374,4 +374,3 @@ class CI_Zip { } } -?> \ No newline at end of file diff --git a/system/plugins/captcha_pi.php b/system/plugins/captcha_pi.php index 309ef7ea5..ac31f590c 100644 --- a/system/plugins/captcha_pi.php +++ b/system/plugins/captcha_pi.php @@ -351,4 +351,3 @@ function create_captcha($data = '', $img_path = '', $img_url = '', $font_path = return array('word' => $word, 'time' => $now, 'image' => $img); } -?> \ No newline at end of file diff --git a/system/scaffolding/Scaffolding.php b/system/scaffolding/Scaffolding.php index 64f62a3d6..559807b7e 100644 --- a/system/scaffolding/Scaffolding.php +++ b/system/scaffolding/Scaffolding.php @@ -286,4 +286,3 @@ class Scaffolding { } } -?> \ No newline at end of file -- cgit v1.2.3-24-g4f1b From c7deac9f2f9e43cedb18202542e8a46061df046e Mon Sep 17 00:00:00 2001 From: Derek Jones Date: Sun, 11 May 2008 16:27:41 +0000 Subject: Undoing change committed in r1115 --- system/application/config/autoload.php | 1 + system/application/config/config.php | 1 + system/application/config/constants.php | 1 + system/application/config/database.php | 1 + system/application/config/hooks.php | 1 + system/application/config/mimes.php | 1 + system/application/config/routes.php | 1 + system/application/config/smileys.php | 1 + system/application/config/user_agents.php | 1 + system/application/controllers/welcome.php | 1 + system/codeigniter/Base4.php | 1 + system/codeigniter/Base5.php | 1 + system/codeigniter/CodeIgniter.php | 1 + system/codeigniter/Common.php | 1 + system/codeigniter/Compat.php | 1 + system/database/DB.php | 1 + system/database/DB_active_rec.php | 1 + system/database/DB_cache.php | 1 + system/database/DB_driver.php | 1 + system/database/DB_forge.php | 1 + system/database/DB_result.php | 1 + system/database/DB_utility.php | 1 + system/database/drivers/mssql/mssql_driver.php | 1 + system/database/drivers/mssql/mssql_forge.php | 1 + system/database/drivers/mssql/mssql_result.php | 1 + system/database/drivers/mssql/mssql_utility.php | 1 + system/database/drivers/mysql/mysql_driver.php | 1 + system/database/drivers/mysql/mysql_forge.php | 1 + system/database/drivers/mysql/mysql_result.php | 1 + system/database/drivers/mysql/mysql_utility.php | 1 + system/database/drivers/mysqli/mysqli_driver.php | 1 + system/database/drivers/mysqli/mysqli_forge.php | 1 + system/database/drivers/mysqli/mysqli_result.php | 1 + system/database/drivers/mysqli/mysqli_utility.php | 1 + system/database/drivers/oci8/oci8_driver.php | 1 + system/database/drivers/oci8/oci8_forge.php | 1 + system/database/drivers/oci8/oci8_result.php | 1 + system/database/drivers/oci8/oci8_utility.php | 1 + system/database/drivers/odbc/odbc_driver.php | 1 + system/database/drivers/odbc/odbc_forge.php | 1 + system/database/drivers/odbc/odbc_result.php | 1 + system/database/drivers/odbc/odbc_utility.php | 1 + system/database/drivers/postgre/postgre_driver.php | 1 + system/database/drivers/postgre/postgre_forge.php | 1 + system/database/drivers/postgre/postgre_result.php | 1 + system/database/drivers/postgre/postgre_utility.php | 1 + system/database/drivers/sqlite/sqlite_driver.php | 1 + system/database/drivers/sqlite/sqlite_forge.php | 1 + system/database/drivers/sqlite/sqlite_result.php | 1 + system/database/drivers/sqlite/sqlite_utility.php | 1 + system/helpers/array_helper.php | 1 + system/helpers/compatibility_helper.php | 1 + system/helpers/cookie_helper.php | 1 + system/helpers/date_helper.php | 1 + system/helpers/directory_helper.php | 1 + system/helpers/download_helper.php | 1 + system/helpers/email_helper.php | 1 + system/helpers/file_helper.php | 1 + system/helpers/form_helper.php | 1 + system/helpers/html_helper.php | 1 + system/helpers/inflector_helper.php | 1 + system/helpers/path_helper.php | 1 + system/helpers/security_helper.php | 1 + system/helpers/smiley_helper.php | 1 + system/helpers/string_helper.php | 1 + system/helpers/text_helper.php | 1 + system/helpers/typography_helper.php | 1 + system/helpers/url_helper.php | 1 + system/helpers/xml_helper.php | 1 + system/language/english/calendar_lang.php | 1 + system/language/english/date_lang.php | 1 + system/language/english/db_lang.php | 1 + system/language/english/email_lang.php | 1 + system/language/english/ftp_lang.php | 1 + system/language/english/imglib_lang.php | 1 + system/language/english/profiler_lang.php | 1 + system/language/english/scaffolding_lang.php | 1 + system/language/english/unit_test_lang.php | 1 + system/language/english/upload_lang.php | 1 + system/language/english/validation_lang.php | 1 + system/libraries/Benchmark.php | 1 + system/libraries/Calendar.php | 1 + system/libraries/Config.php | 1 + system/libraries/Controller.php | 1 + system/libraries/Email.php | 1 + system/libraries/Encrypt.php | 1 + system/libraries/Exceptions.php | 1 + system/libraries/Ftp.php | 1 + system/libraries/Hooks.php | 1 + system/libraries/Image_lib.php | 1 + system/libraries/Input.php | 1 + system/libraries/Language.php | 1 + system/libraries/Loader.php | 1 + system/libraries/Log.php | 1 + system/libraries/Model.php | 1 + system/libraries/Output.php | 1 + system/libraries/Pagination.php | 1 + system/libraries/Parser.php | 1 + system/libraries/Profiler.php | 1 + system/libraries/Router.php | 1 + system/libraries/Session.php | 1 + system/libraries/Sha1.php | 1 + system/libraries/Table.php | 1 + system/libraries/Trackback.php | 1 + system/libraries/URI.php | 1 + system/libraries/Unit_test.php | 1 + system/libraries/Upload.php | 1 + system/libraries/User_agent.php | 1 + system/libraries/Validation.php | 1 + system/libraries/Xmlrpc.php | 1 + system/libraries/Xmlrpcs.php | 1 + system/libraries/Zip.php | 1 + system/plugins/captcha_pi.php | 1 + system/scaffolding/Scaffolding.php | 1 + 114 files changed, 114 insertions(+) (limited to 'system') diff --git a/system/application/config/autoload.php b/system/application/config/autoload.php index 15e2e7b40..2dfbe422c 100644 --- a/system/application/config/autoload.php +++ b/system/application/config/autoload.php @@ -122,3 +122,4 @@ $autoload['model'] = array(); // $autoload['core'] = array(); +?> \ No newline at end of file diff --git a/system/application/config/config.php b/system/application/config/config.php index 22fe4513a..24fbb4b7a 100644 --- a/system/application/config/config.php +++ b/system/application/config/config.php @@ -311,3 +311,4 @@ $config['time_reference'] = 'local'; $config['rewrite_short_tags'] = FALSE; +?> \ No newline at end of file diff --git a/system/application/config/constants.php b/system/application/config/constants.php index 303d87372..3f7975635 100644 --- a/system/application/config/constants.php +++ b/system/application/config/constants.php @@ -36,3 +36,4 @@ define('FOPEN_READ_WRITE_CREATE', 'a+b'); define('FOPEN_WRITE_CREATE_STRICT', 'xb'); define('FOPEN_READ_WRITE_CREATE_STRICT', 'x+b'); +?> \ No newline at end of file diff --git a/system/application/config/database.php b/system/application/config/database.php index feefc77e1..6973c5afa 100644 --- a/system/application/config/database.php +++ b/system/application/config/database.php @@ -50,3 +50,4 @@ $db['default']['cachedir'] = ""; $db['default']['char_set'] = "utf8"; $db['default']['dbcollat'] = "utf8_general_ci"; +?> \ No newline at end of file diff --git a/system/application/config/hooks.php b/system/application/config/hooks.php index 4fce538d0..f0a0d6e3a 100644 --- a/system/application/config/hooks.php +++ b/system/application/config/hooks.php @@ -11,3 +11,4 @@ */ +?> \ No newline at end of file diff --git a/system/application/config/mimes.php b/system/application/config/mimes.php index fae325b24..7f5f20803 100644 --- a/system/application/config/mimes.php +++ b/system/application/config/mimes.php @@ -99,3 +99,4 @@ $mimes = array( 'hqx' => 'application/mac-binhex40', ); +?> \ No newline at end of file diff --git a/system/application/config/routes.php b/system/application/config/routes.php index ec03d77b5..1395b7aed 100644 --- a/system/application/config/routes.php +++ b/system/application/config/routes.php @@ -43,3 +43,4 @@ $route['default_controller'] = "welcome"; $route['scaffolding_trigger'] = ""; +?> \ No newline at end of file diff --git a/system/application/config/smileys.php b/system/application/config/smileys.php index abecede68..a227d8b68 100644 --- a/system/application/config/smileys.php +++ b/system/application/config/smileys.php @@ -61,3 +61,4 @@ $smileys = array( ':question:' => array('question.gif', '19', '19', 'question') // no comma after last item ); +?> \ No newline at end of file diff --git a/system/application/config/user_agents.php b/system/application/config/user_agents.php index 873a5a503..08a665f9d 100644 --- a/system/application/config/user_agents.php +++ b/system/application/config/user_agents.php @@ -100,3 +100,4 @@ $robots = array( ); +?> \ No newline at end of file diff --git a/system/application/controllers/welcome.php b/system/application/controllers/welcome.php index 243423a65..7f7296d81 100644 --- a/system/application/controllers/welcome.php +++ b/system/application/controllers/welcome.php @@ -12,3 +12,4 @@ class Welcome extends Controller { $this->load->view('welcome_message'); } } +?> \ No newline at end of file diff --git a/system/codeigniter/Base4.php b/system/codeigniter/Base4.php index fcf8b9850..577977c1c 100644 --- a/system/codeigniter/Base4.php +++ b/system/codeigniter/Base4.php @@ -64,3 +64,4 @@ function &get_instance() return $OBJ->load; } +?> \ No newline at end of file diff --git a/system/codeigniter/Base5.php b/system/codeigniter/Base5.php index 9e0e20d6c..c731a00c4 100644 --- a/system/codeigniter/Base5.php +++ b/system/codeigniter/Base5.php @@ -51,3 +51,4 @@ function &get_instance() } +?> \ No newline at end of file diff --git a/system/codeigniter/CodeIgniter.php b/system/codeigniter/CodeIgniter.php index 12a7423c4..75332e678 100644 --- a/system/codeigniter/CodeIgniter.php +++ b/system/codeigniter/CodeIgniter.php @@ -273,3 +273,4 @@ if (class_exists('CI_DB') AND isset($CI->db)) } +?> \ No newline at end of file diff --git a/system/codeigniter/Common.php b/system/codeigniter/Common.php index 874f588b5..c5c548cdf 100644 --- a/system/codeigniter/Common.php +++ b/system/codeigniter/Common.php @@ -295,3 +295,4 @@ function _exception_handler($severity, $message, $filepath, $line) } +?> \ No newline at end of file diff --git a/system/codeigniter/Compat.php b/system/codeigniter/Compat.php index 469964a09..8537432f5 100644 --- a/system/codeigniter/Compat.php +++ b/system/codeigniter/Compat.php @@ -91,3 +91,4 @@ if (! function_exists('ctype_alnum')) // -------------------------------------------------------------------- +?> \ No newline at end of file diff --git a/system/database/DB.php b/system/database/DB.php index 55d73ba0b..8efe05560 100644 --- a/system/database/DB.php +++ b/system/database/DB.php @@ -120,3 +120,4 @@ function &DB($params = '', $active_record_override = FALSE) } +?> \ No newline at end of file diff --git a/system/database/DB_active_rec.php b/system/database/DB_active_rec.php index af042dcd2..49d438727 100644 --- a/system/database/DB_active_rec.php +++ b/system/database/DB_active_rec.php @@ -1749,3 +1749,4 @@ class CI_DB_active_record extends CI_DB_driver { } } +?> \ No newline at end of file diff --git a/system/database/DB_cache.php b/system/database/DB_cache.php index a154ba86d..982725aaa 100644 --- a/system/database/DB_cache.php +++ b/system/database/DB_cache.php @@ -186,3 +186,4 @@ class CI_DB_Cache { } +?> \ No newline at end of file diff --git a/system/database/DB_driver.php b/system/database/DB_driver.php index dd235103e..a5ca75dd6 100644 --- a/system/database/DB_driver.php +++ b/system/database/DB_driver.php @@ -1145,3 +1145,4 @@ class CI_DB_driver { } +?> \ No newline at end of file diff --git a/system/database/DB_forge.php b/system/database/DB_forge.php index 258da346d..2ddb21be7 100644 --- a/system/database/DB_forge.php +++ b/system/database/DB_forge.php @@ -341,3 +341,4 @@ class CI_DB_forge { } } +?> \ No newline at end of file diff --git a/system/database/DB_result.php b/system/database/DB_result.php index 90338d0c4..cfe9d2a32 100644 --- a/system/database/DB_result.php +++ b/system/database/DB_result.php @@ -338,3 +338,4 @@ class CI_DB_result { } // END DB_result class +?> \ No newline at end of file diff --git a/system/database/DB_utility.php b/system/database/DB_utility.php index 2604a3e76..11f1fb4de 100644 --- a/system/database/DB_utility.php +++ b/system/database/DB_utility.php @@ -384,3 +384,4 @@ class CI_DB_utility extends CI_DB_forge { } +?> \ No newline at end of file diff --git a/system/database/drivers/mssql/mssql_driver.php b/system/database/drivers/mssql/mssql_driver.php index 3a9bb31cc..6e67c57c0 100644 --- a/system/database/drivers/mssql/mssql_driver.php +++ b/system/database/drivers/mssql/mssql_driver.php @@ -641,3 +641,4 @@ class CI_DB_mssql_driver extends CI_DB { } +?> \ No newline at end of file diff --git a/system/database/drivers/mssql/mssql_forge.php b/system/database/drivers/mssql/mssql_forge.php index b81b565eb..63063f259 100644 --- a/system/database/drivers/mssql/mssql_forge.php +++ b/system/database/drivers/mssql/mssql_forge.php @@ -235,3 +235,4 @@ class CI_DB_mssql_forge extends CI_DB_forge { } } +?> \ No newline at end of file diff --git a/system/database/drivers/mssql/mssql_result.php b/system/database/drivers/mssql/mssql_result.php index 9044bc095..c95fd91f6 100644 --- a/system/database/drivers/mssql/mssql_result.php +++ b/system/database/drivers/mssql/mssql_result.php @@ -170,3 +170,4 @@ class CI_DB_mssql_result extends CI_DB_result { } +?> \ No newline at end of file diff --git a/system/database/drivers/mssql/mssql_utility.php b/system/database/drivers/mssql/mssql_utility.php index 9ba65742c..87f8196f7 100644 --- a/system/database/drivers/mssql/mssql_utility.php +++ b/system/database/drivers/mssql/mssql_utility.php @@ -118,3 +118,4 @@ class CI_DB_mssql_utility extends CI_DB_utility { } +?> \ No newline at end of file diff --git a/system/database/drivers/mysql/mysql_driver.php b/system/database/drivers/mysql/mysql_driver.php index 9fd042151..f15983d2b 100644 --- a/system/database/drivers/mysql/mysql_driver.php +++ b/system/database/drivers/mysql/mysql_driver.php @@ -649,3 +649,4 @@ class CI_DB_mysql_driver extends CI_DB { } +?> \ No newline at end of file diff --git a/system/database/drivers/mysql/mysql_forge.php b/system/database/drivers/mysql/mysql_forge.php index e9ea94706..4eb449ef2 100644 --- a/system/database/drivers/mysql/mysql_forge.php +++ b/system/database/drivers/mysql/mysql_forge.php @@ -238,3 +238,4 @@ class CI_DB_mysql_forge extends CI_DB_forge { } } +?> \ No newline at end of file diff --git a/system/database/drivers/mysql/mysql_result.php b/system/database/drivers/mysql/mysql_result.php index 7c5125fc4..9e6a3c3d1 100644 --- a/system/database/drivers/mysql/mysql_result.php +++ b/system/database/drivers/mysql/mysql_result.php @@ -170,3 +170,4 @@ class CI_DB_mysql_result extends CI_DB_result { } +?> \ No newline at end of file diff --git a/system/database/drivers/mysql/mysql_utility.php b/system/database/drivers/mysql/mysql_utility.php index 22bc23383..dc8fd0866 100644 --- a/system/database/drivers/mysql/mysql_utility.php +++ b/system/database/drivers/mysql/mysql_utility.php @@ -249,3 +249,4 @@ class CI_DB_mysql_utility extends CI_DB_utility { } } +?> \ No newline at end of file diff --git a/system/database/drivers/mysqli/mysqli_driver.php b/system/database/drivers/mysqli/mysqli_driver.php index 4ffbbaca1..a196f755a 100644 --- a/system/database/drivers/mysqli/mysqli_driver.php +++ b/system/database/drivers/mysqli/mysqli_driver.php @@ -645,3 +645,4 @@ class CI_DB_mysqli_driver extends CI_DB { } +?> \ No newline at end of file diff --git a/system/database/drivers/mysqli/mysqli_forge.php b/system/database/drivers/mysqli/mysqli_forge.php index a0ff9f574..e6bc0093f 100644 --- a/system/database/drivers/mysqli/mysqli_forge.php +++ b/system/database/drivers/mysqli/mysqli_forge.php @@ -238,3 +238,4 @@ class CI_DB_mysqli_forge extends CI_DB_forge { } } +?> \ No newline at end of file diff --git a/system/database/drivers/mysqli/mysqli_result.php b/system/database/drivers/mysqli/mysqli_result.php index b1a060405..692d4f729 100644 --- a/system/database/drivers/mysqli/mysqli_result.php +++ b/system/database/drivers/mysqli/mysqli_result.php @@ -170,3 +170,4 @@ class CI_DB_mysqli_result extends CI_DB_result { } +?> \ No newline at end of file diff --git a/system/database/drivers/mysqli/mysqli_utility.php b/system/database/drivers/mysqli/mysqli_utility.php index 75f4a4192..4ab2bb1d1 100644 --- a/system/database/drivers/mysqli/mysqli_utility.php +++ b/system/database/drivers/mysqli/mysqli_utility.php @@ -118,3 +118,4 @@ class CI_DB_mysqli_utility extends CI_DB_utility { } } +?> \ No newline at end of file diff --git a/system/database/drivers/oci8/oci8_driver.php b/system/database/drivers/oci8/oci8_driver.php index fb288087c..8fc20449f 100644 --- a/system/database/drivers/oci8/oci8_driver.php +++ b/system/database/drivers/oci8/oci8_driver.php @@ -761,3 +761,4 @@ class CI_DB_oci8_driver extends CI_DB { } +?> \ No newline at end of file diff --git a/system/database/drivers/oci8/oci8_forge.php b/system/database/drivers/oci8/oci8_forge.php index 6ca6c5434..a3940aedb 100644 --- a/system/database/drivers/oci8/oci8_forge.php +++ b/system/database/drivers/oci8/oci8_forge.php @@ -232,3 +232,4 @@ class CI_DB_oci8_forge extends CI_DB_forge { } +?> \ No newline at end of file diff --git a/system/database/drivers/oci8/oci8_result.php b/system/database/drivers/oci8/oci8_result.php index 9f1257642..30dd0da09 100644 --- a/system/database/drivers/oci8/oci8_result.php +++ b/system/database/drivers/oci8/oci8_result.php @@ -248,3 +248,4 @@ class CI_DB_oci8_result extends CI_DB_result { } +?> \ No newline at end of file diff --git a/system/database/drivers/oci8/oci8_utility.php b/system/database/drivers/oci8/oci8_utility.php index c361c5ec3..117f8e629 100644 --- a/system/database/drivers/oci8/oci8_utility.php +++ b/system/database/drivers/oci8/oci8_utility.php @@ -117,3 +117,4 @@ class CI_DB_oci8_utility extends CI_DB_utility { } } +?> \ No newline at end of file diff --git a/system/database/drivers/odbc/odbc_driver.php b/system/database/drivers/odbc/odbc_driver.php index 93a1d4e05..20e34ec7b 100644 --- a/system/database/drivers/odbc/odbc_driver.php +++ b/system/database/drivers/odbc/odbc_driver.php @@ -613,3 +613,4 @@ class CI_DB_odbc_driver extends CI_DB { } +?> \ No newline at end of file diff --git a/system/database/drivers/odbc/odbc_forge.php b/system/database/drivers/odbc/odbc_forge.php index ee4745ccc..66e1722d8 100644 --- a/system/database/drivers/odbc/odbc_forge.php +++ b/system/database/drivers/odbc/odbc_forge.php @@ -253,3 +253,4 @@ class CI_DB_odbc_forge extends CI_DB_forge { } +?> \ No newline at end of file diff --git a/system/database/drivers/odbc/odbc_result.php b/system/database/drivers/odbc/odbc_result.php index d513171d0..dd3f92382 100644 --- a/system/database/drivers/odbc/odbc_result.php +++ b/system/database/drivers/odbc/odbc_result.php @@ -229,3 +229,4 @@ class CI_DB_odbc_result extends CI_DB_result { } +?> \ No newline at end of file diff --git a/system/database/drivers/odbc/odbc_utility.php b/system/database/drivers/odbc/odbc_utility.php index 75d1ca283..f74d031bd 100644 --- a/system/database/drivers/odbc/odbc_utility.php +++ b/system/database/drivers/odbc/odbc_utility.php @@ -143,3 +143,4 @@ class CI_DB_odbc_utility extends CI_DB_utility { return FALSE; } } +?> \ No newline at end of file diff --git a/system/database/drivers/postgre/postgre_driver.php b/system/database/drivers/postgre/postgre_driver.php index 7c46e7a4b..46ba1d009 100644 --- a/system/database/drivers/postgre/postgre_driver.php +++ b/system/database/drivers/postgre/postgre_driver.php @@ -641,3 +641,4 @@ class CI_DB_postgre_driver extends CI_DB { } +?> \ No newline at end of file diff --git a/system/database/drivers/postgre/postgre_forge.php b/system/database/drivers/postgre/postgre_forge.php index ad4c5cdae..72a61748d 100644 --- a/system/database/drivers/postgre/postgre_forge.php +++ b/system/database/drivers/postgre/postgre_forge.php @@ -235,3 +235,4 @@ class CI_DB_postgre_forge extends CI_DB_forge { } +?> \ No newline at end of file diff --git a/system/database/drivers/postgre/postgre_result.php b/system/database/drivers/postgre/postgre_result.php index f3fb89951..fdce01aac 100644 --- a/system/database/drivers/postgre/postgre_result.php +++ b/system/database/drivers/postgre/postgre_result.php @@ -170,3 +170,4 @@ class CI_DB_postgre_result extends CI_DB_result { } +?> \ No newline at end of file diff --git a/system/database/drivers/postgre/postgre_utility.php b/system/database/drivers/postgre/postgre_utility.php index 25f44f06c..573654f68 100644 --- a/system/database/drivers/postgre/postgre_utility.php +++ b/system/database/drivers/postgre/postgre_utility.php @@ -119,3 +119,4 @@ class CI_DB_postgre_utility extends CI_DB_utility { } +?> \ No newline at end of file diff --git a/system/database/drivers/sqlite/sqlite_driver.php b/system/database/drivers/sqlite/sqlite_driver.php index f84ee2095..70148f360 100644 --- a/system/database/drivers/sqlite/sqlite_driver.php +++ b/system/database/drivers/sqlite/sqlite_driver.php @@ -656,3 +656,4 @@ class CI_DB_sqlite_driver extends CI_DB { } +?> \ No newline at end of file diff --git a/system/database/drivers/sqlite/sqlite_forge.php b/system/database/drivers/sqlite/sqlite_forge.php index 8afd39e99..44950bfc7 100644 --- a/system/database/drivers/sqlite/sqlite_forge.php +++ b/system/database/drivers/sqlite/sqlite_forge.php @@ -231,3 +231,4 @@ class CI_DB_sqlite_forge extends CI_DB_forge { } } +?> \ No newline at end of file diff --git a/system/database/drivers/sqlite/sqlite_result.php b/system/database/drivers/sqlite/sqlite_result.php index 92bc3872a..b8f3dc5b7 100644 --- a/system/database/drivers/sqlite/sqlite_result.php +++ b/system/database/drivers/sqlite/sqlite_result.php @@ -180,3 +180,4 @@ class CI_DB_sqlite_result extends CI_DB_result { } +?> \ No newline at end of file diff --git a/system/database/drivers/sqlite/sqlite_utility.php b/system/database/drivers/sqlite/sqlite_utility.php index 8d2b44362..ab58f8fd7 100644 --- a/system/database/drivers/sqlite/sqlite_utility.php +++ b/system/database/drivers/sqlite/sqlite_utility.php @@ -136,3 +136,4 @@ class CI_DB_sqlite_utility extends CI_DB_utility { } } +?> \ No newline at end of file diff --git a/system/helpers/array_helper.php b/system/helpers/array_helper.php index 0d9fc0b47..8ae44826a 100644 --- a/system/helpers/array_helper.php +++ b/system/helpers/array_helper.php @@ -73,3 +73,4 @@ if (! function_exists('random_element')) } } +?> \ No newline at end of file diff --git a/system/helpers/compatibility_helper.php b/system/helpers/compatibility_helper.php index ee7e77058..0d214648c 100644 --- a/system/helpers/compatibility_helper.php +++ b/system/helpers/compatibility_helper.php @@ -493,3 +493,4 @@ if (! function_exists('http_build_query')) } } +?> \ No newline at end of file diff --git a/system/helpers/cookie_helper.php b/system/helpers/cookie_helper.php index 0d21f11e4..75c769e9c 100644 --- a/system/helpers/cookie_helper.php +++ b/system/helpers/cookie_helper.php @@ -131,3 +131,4 @@ if (! function_exists('delete_cookie')) } } +?> \ No newline at end of file diff --git a/system/helpers/date_helper.php b/system/helpers/date_helper.php index 447146860..004cfb122 100644 --- a/system/helpers/date_helper.php +++ b/system/helpers/date_helper.php @@ -596,3 +596,4 @@ if (! function_exists('timezones')) } } +?> \ No newline at end of file diff --git a/system/helpers/directory_helper.php b/system/helpers/directory_helper.php index a3227c810..25c16c1fc 100644 --- a/system/helpers/directory_helper.php +++ b/system/helpers/directory_helper.php @@ -75,3 +75,4 @@ if (! function_exists('directory_map')) } } +?> \ No newline at end of file diff --git a/system/helpers/download_helper.php b/system/helpers/download_helper.php index 39c2a2afc..284c6c96e 100644 --- a/system/helpers/download_helper.php +++ b/system/helpers/download_helper.php @@ -95,3 +95,4 @@ if (! function_exists('force_download')) } } +?> \ No newline at end of file diff --git a/system/helpers/email_helper.php b/system/helpers/email_helper.php index a1452cec9..307f3b588 100644 --- a/system/helpers/email_helper.php +++ b/system/helpers/email_helper.php @@ -57,3 +57,4 @@ if (! function_exists('send_email')) } } +?> \ No newline at end of file diff --git a/system/helpers/file_helper.php b/system/helpers/file_helper.php index 0c2ae5af6..bdde2d55d 100644 --- a/system/helpers/file_helper.php +++ b/system/helpers/file_helper.php @@ -456,3 +456,4 @@ if (! function_exists('octal_permissions')) } } +?> \ No newline at end of file diff --git a/system/helpers/form_helper.php b/system/helpers/form_helper.php index c91e5a5c7..c9a6897ae 100644 --- a/system/helpers/form_helper.php +++ b/system/helpers/form_helper.php @@ -610,3 +610,4 @@ if (! function_exists('parse_form_attributes')) } } +?> \ No newline at end of file diff --git a/system/helpers/html_helper.php b/system/helpers/html_helper.php index f488a5d3d..4e86465c1 100644 --- a/system/helpers/html_helper.php +++ b/system/helpers/html_helper.php @@ -351,3 +351,4 @@ if (! function_exists('nbs')) } } +?> \ No newline at end of file diff --git a/system/helpers/inflector_helper.php b/system/helpers/inflector_helper.php index a833c70b8..bf70a6799 100644 --- a/system/helpers/inflector_helper.php +++ b/system/helpers/inflector_helper.php @@ -164,3 +164,4 @@ if (! function_exists('humanize')) } } +?> \ No newline at end of file diff --git a/system/helpers/path_helper.php b/system/helpers/path_helper.php index 8ff9f2425..6abff06af 100644 --- a/system/helpers/path_helper.php +++ b/system/helpers/path_helper.php @@ -67,3 +67,4 @@ if (! function_exists('set_realpath')) } } +?> \ No newline at end of file diff --git a/system/helpers/security_helper.php b/system/helpers/security_helper.php index 6e61aa71d..edb6ebb50 100644 --- a/system/helpers/security_helper.php +++ b/system/helpers/security_helper.php @@ -121,3 +121,4 @@ if (! function_exists('encode_php_tags')) } } +?> \ No newline at end of file diff --git a/system/helpers/smiley_helper.php b/system/helpers/smiley_helper.php index d65801834..81c6b9199 100644 --- a/system/helpers/smiley_helper.php +++ b/system/helpers/smiley_helper.php @@ -170,3 +170,4 @@ if (! function_exists('_get_smiley_array')) } } +?> \ No newline at end of file diff --git a/system/helpers/string_helper.php b/system/helpers/string_helper.php index cd2af0cef..f68f44ac1 100644 --- a/system/helpers/string_helper.php +++ b/system/helpers/string_helper.php @@ -268,3 +268,4 @@ if (! function_exists('repeater')) } } +?> \ No newline at end of file diff --git a/system/helpers/text_helper.php b/system/helpers/text_helper.php index 95c2c619b..df3c89e6f 100644 --- a/system/helpers/text_helper.php +++ b/system/helpers/text_helper.php @@ -436,3 +436,4 @@ if (! function_exists('word_wrap')) } } +?> \ No newline at end of file diff --git a/system/helpers/typography_helper.php b/system/helpers/typography_helper.php index 82573844b..88071604d 100644 --- a/system/helpers/typography_helper.php +++ b/system/helpers/typography_helper.php @@ -542,3 +542,4 @@ class Auto_typography { } +?> \ No newline at end of file diff --git a/system/helpers/url_helper.php b/system/helpers/url_helper.php index 1c6c5c552..d702f6b87 100644 --- a/system/helpers/url_helper.php +++ b/system/helpers/url_helper.php @@ -532,3 +532,4 @@ if (! function_exists('_parse_attributes')) } } +?> \ No newline at end of file diff --git a/system/helpers/xml_helper.php b/system/helpers/xml_helper.php index a3d08f622..5aa6de9ec 100644 --- a/system/helpers/xml_helper.php +++ b/system/helpers/xml_helper.php @@ -57,3 +57,4 @@ if (! function_exists('xml_convert')) } } +?> \ No newline at end of file diff --git a/system/language/english/calendar_lang.php b/system/language/english/calendar_lang.php index 62f24ac57..9ee4a5e69 100644 --- a/system/language/english/calendar_lang.php +++ b/system/language/english/calendar_lang.php @@ -46,3 +46,4 @@ $lang['cal_october'] = "October"; $lang['cal_november'] = "November"; $lang['cal_december'] = "December"; +?> \ No newline at end of file diff --git a/system/language/english/date_lang.php b/system/language/english/date_lang.php index 6cb93031f..6b18aa7be 100644 --- a/system/language/english/date_lang.php +++ b/system/language/english/date_lang.php @@ -46,3 +46,4 @@ $lang['UP10'] = "(UTC + 10:00) Melbourne, Papua New Guinea, Sydney, Vladivostok" $lang['UP11'] = "(UTC + 11:00) Magadan, New Caledonia, Solomon Islands"; $lang['UP12'] = "(UTC + 12:00) Auckland, Wellington, Fiji, Marshall Islands"; +?> \ No newline at end of file diff --git a/system/language/english/db_lang.php b/system/language/english/db_lang.php index 2748bf9c8..1e79a706d 100644 --- a/system/language/english/db_lang.php +++ b/system/language/english/db_lang.php @@ -22,3 +22,4 @@ $lang['db_column_name_required'] = 'A column name is required for that operation $lang['db_column_definition_required'] = 'A column definition is required for that operation.'; $lang['db_unable_to_set_charset'] = 'Unable to set client connection character set: %s'; +?> \ No newline at end of file diff --git a/system/language/english/email_lang.php b/system/language/english/email_lang.php index 5e3dc106c..f02686509 100644 --- a/system/language/english/email_lang.php +++ b/system/language/english/email_lang.php @@ -18,3 +18,4 @@ $lang['email_smtp_auth_un'] = "Failed to authenticate username. Error: %s"; $lang['email_smtp_auth_pw'] = "Failed to authenticate password. Error: %s"; $lang['email_smtp_data_failure'] = "Unable to send data: %s"; +?> \ No newline at end of file diff --git a/system/language/english/ftp_lang.php b/system/language/english/ftp_lang.php index 7b9203338..da744fea7 100644 --- a/system/language/english/ftp_lang.php +++ b/system/language/english/ftp_lang.php @@ -12,3 +12,4 @@ $lang['ftp_unable_to_rename'] = "Unable to rename the file."; $lang['ftp_unable_to_delete'] = "Unable to delete the file."; $lang['ftp_unable_to_move'] = "Unable to move the file. Please make sure the destination directory exists."; +?> \ No newline at end of file diff --git a/system/language/english/imglib_lang.php b/system/language/english/imglib_lang.php index 78e1ec2fb..520f17f35 100644 --- a/system/language/english/imglib_lang.php +++ b/system/language/english/imglib_lang.php @@ -18,3 +18,4 @@ $lang['imglib_invalid_path'] = "The path to the image is not correct."; $lang['imglib_copy_failed'] = "The image copy routine failed."; $lang['imglib_missing_font'] = "Unable to find a font to use."; +?> \ No newline at end of file diff --git a/system/language/english/profiler_lang.php b/system/language/english/profiler_lang.php index c8f183511..219a83856 100644 --- a/system/language/english/profiler_lang.php +++ b/system/language/english/profiler_lang.php @@ -12,3 +12,4 @@ $lang['profiler_no_post'] = 'No POST data exists'; $lang['profiler_no_get'] = 'No GET data exists'; $lang['profiler_no_uri'] = 'No URI data exists'; $lang['profiler_no_memory'] = 'Memory Usage Unavailable'; +?> \ No newline at end of file diff --git a/system/language/english/scaffolding_lang.php b/system/language/english/scaffolding_lang.php index 4e3cde7dc..96fe167e5 100644 --- a/system/language/english/scaffolding_lang.php +++ b/system/language/english/scaffolding_lang.php @@ -12,3 +12,4 @@ $lang['scaff_no'] = 'No'; $lang['scaff_no_data'] = 'No data exists for this table yet.'; $lang['scaff_del_confirm'] = 'Are you sure you want to delete the following row:'; +?> \ No newline at end of file diff --git a/system/language/english/unit_test_lang.php b/system/language/english/unit_test_lang.php index aa71ad2e5..a33cad5f2 100644 --- a/system/language/english/unit_test_lang.php +++ b/system/language/english/unit_test_lang.php @@ -19,3 +19,4 @@ $lang['ut_object'] = 'Object'; $lang['ut_resource'] = 'Resource'; $lang['ut_null'] = 'Null' +?> \ No newline at end of file diff --git a/system/language/english/upload_lang.php b/system/language/english/upload_lang.php index 4667489c9..fa6d7c9fb 100644 --- a/system/language/english/upload_lang.php +++ b/system/language/english/upload_lang.php @@ -17,3 +17,4 @@ $lang['upload_no_file_types'] = "You have not specified any allowed file types." $lang['upload_bad_filename'] = "The file name you submitted already exists on the server."; $lang['upload_not_writable'] = "The upload destination folder does not appear to be writable."; +?> \ No newline at end of file diff --git a/system/language/english/validation_lang.php b/system/language/english/validation_lang.php index 82fd9c99d..1e9ec2c1b 100644 --- a/system/language/english/validation_lang.php +++ b/system/language/english/validation_lang.php @@ -15,3 +15,4 @@ $lang['numeric'] = "The %s field must contain a number."; $lang['integer'] = "The %s field must contain an integer."; $lang['matches'] = "The %s field does not match the %s field."; +?> \ No newline at end of file diff --git a/system/libraries/Benchmark.php b/system/libraries/Benchmark.php index db9239d61..323d9668d 100644 --- a/system/libraries/Benchmark.php +++ b/system/libraries/Benchmark.php @@ -108,3 +108,4 @@ class CI_Benchmark { } // END CI_Benchmark class +?> \ No newline at end of file diff --git a/system/libraries/Calendar.php b/system/libraries/Calendar.php index 42e70f4de..e9621fec1 100644 --- a/system/libraries/Calendar.php +++ b/system/libraries/Calendar.php @@ -472,3 +472,4 @@ class CI_Calendar { } // END CI_Calendar class +?> \ No newline at end of file diff --git a/system/libraries/Config.php b/system/libraries/Config.php index a3a7d9d75..73f1986a0 100644 --- a/system/libraries/Config.php +++ b/system/libraries/Config.php @@ -242,3 +242,4 @@ class CI_Config { } // END CI_Config class +?> \ No newline at end of file diff --git a/system/libraries/Controller.php b/system/libraries/Controller.php index e5b2f2796..4957fc35e 100644 --- a/system/libraries/Controller.php +++ b/system/libraries/Controller.php @@ -121,3 +121,4 @@ class Controller extends CI_Base { } // END _Controller class +?> \ No newline at end of file diff --git a/system/libraries/Email.php b/system/libraries/Email.php index bb72ad439..aa08971f9 100644 --- a/system/libraries/Email.php +++ b/system/libraries/Email.php @@ -1848,3 +1848,4 @@ class CI_Email { } // END CI_Email class +?> \ No newline at end of file diff --git a/system/libraries/Encrypt.php b/system/libraries/Encrypt.php index 7463fd0a6..9a784d254 100644 --- a/system/libraries/Encrypt.php +++ b/system/libraries/Encrypt.php @@ -481,3 +481,4 @@ class CI_Encrypt { } // END CI_Encrypt class +?> \ No newline at end of file diff --git a/system/libraries/Exceptions.php b/system/libraries/Exceptions.php index 0b647df39..7c9640554 100644 --- a/system/libraries/Exceptions.php +++ b/system/libraries/Exceptions.php @@ -167,3 +167,4 @@ class CI_Exceptions { } // END Exceptions Class +?> \ No newline at end of file diff --git a/system/libraries/Ftp.php b/system/libraries/Ftp.php index f45f992d1..74b7728fa 100644 --- a/system/libraries/Ftp.php +++ b/system/libraries/Ftp.php @@ -613,3 +613,4 @@ class CI_FTP { } // END FTP Class +?> \ No newline at end of file diff --git a/system/libraries/Hooks.php b/system/libraries/Hooks.php index c68b42353..a41320c5e 100644 --- a/system/libraries/Hooks.php +++ b/system/libraries/Hooks.php @@ -221,3 +221,4 @@ class CI_Hooks { } // END CI_Hooks class +?> \ No newline at end of file diff --git a/system/libraries/Image_lib.php b/system/libraries/Image_lib.php index d2f464044..c236e391e 100644 --- a/system/libraries/Image_lib.php +++ b/system/libraries/Image_lib.php @@ -1533,3 +1533,4 @@ class CI_Image_lib { } // END Image_lib Class +?> \ No newline at end of file diff --git a/system/libraries/Input.php b/system/libraries/Input.php index 9d64a2cb4..8a0478be2 100644 --- a/system/libraries/Input.php +++ b/system/libraries/Input.php @@ -923,3 +923,4 @@ class CI_Input { } // END Input class +?> \ No newline at end of file diff --git a/system/libraries/Language.php b/system/libraries/Language.php index 45c839250..a8e6366bb 100644 --- a/system/libraries/Language.php +++ b/system/libraries/Language.php @@ -118,3 +118,4 @@ class CI_Language { } // END Language Class +?> \ No newline at end of file diff --git a/system/libraries/Loader.php b/system/libraries/Loader.php index 60dc73b1f..5966aebf6 100644 --- a/system/libraries/Loader.php +++ b/system/libraries/Loader.php @@ -1027,3 +1027,4 @@ class CI_Loader { } } +?> \ No newline at end of file diff --git a/system/libraries/Log.php b/system/libraries/Log.php index 1754b3980..26757ba50 100644 --- a/system/libraries/Log.php +++ b/system/libraries/Log.php @@ -115,3 +115,4 @@ class CI_Log { } // END Log Class +?> \ No newline at end of file diff --git a/system/libraries/Model.php b/system/libraries/Model.php index ce8e128ad..e87d6045c 100644 --- a/system/libraries/Model.php +++ b/system/libraries/Model.php @@ -79,3 +79,4 @@ class Model { } // END Model Class +?> \ No newline at end of file diff --git a/system/libraries/Output.php b/system/libraries/Output.php index 69206f519..d513a1279 100644 --- a/system/libraries/Output.php +++ b/system/libraries/Output.php @@ -383,3 +383,4 @@ class CI_Output { } // END Output Class +?> \ No newline at end of file diff --git a/system/libraries/Pagination.php b/system/libraries/Pagination.php index 68bd1892d..e1212035a 100644 --- a/system/libraries/Pagination.php +++ b/system/libraries/Pagination.php @@ -215,3 +215,4 @@ class CI_Pagination { } } // END Pagination Class +?> \ No newline at end of file diff --git a/system/libraries/Parser.php b/system/libraries/Parser.php index d2bdba11a..417e04f29 100644 --- a/system/libraries/Parser.php +++ b/system/libraries/Parser.php @@ -168,3 +168,4 @@ class CI_Parser { } // END Parser Class +?> \ No newline at end of file diff --git a/system/libraries/Profiler.php b/system/libraries/Profiler.php index 38f0d2346..807c1aff6 100644 --- a/system/libraries/Profiler.php +++ b/system/libraries/Profiler.php @@ -340,3 +340,4 @@ class CI_Profiler { } // END CI_Profiler class +?> \ No newline at end of file diff --git a/system/libraries/Router.php b/system/libraries/Router.php index ade01a6c1..6bb85518f 100644 --- a/system/libraries/Router.php +++ b/system/libraries/Router.php @@ -374,3 +374,4 @@ class CI_Router { } // END Router Class +?> \ No newline at end of file diff --git a/system/libraries/Session.php b/system/libraries/Session.php index c77eb9e0a..d4fdd3ac7 100644 --- a/system/libraries/Session.php +++ b/system/libraries/Session.php @@ -649,3 +649,4 @@ class CI_Session { } // END Session Class +?> \ No newline at end of file diff --git a/system/libraries/Sha1.php b/system/libraries/Sha1.php index 768ffa166..6bb891177 100644 --- a/system/libraries/Sha1.php +++ b/system/libraries/Sha1.php @@ -246,3 +246,4 @@ class CI_SHA { } } // END CI_SHA +?> \ No newline at end of file diff --git a/system/libraries/Table.php b/system/libraries/Table.php index 5edb5e4cc..01b490a5d 100644 --- a/system/libraries/Table.php +++ b/system/libraries/Table.php @@ -435,3 +435,4 @@ class CI_Table { } +?> \ No newline at end of file diff --git a/system/libraries/Trackback.php b/system/libraries/Trackback.php index b4c296d1e..3e1c20210 100644 --- a/system/libraries/Trackback.php +++ b/system/libraries/Trackback.php @@ -545,3 +545,4 @@ class CI_Trackback { } // END Trackback Class +?> \ No newline at end of file diff --git a/system/libraries/URI.php b/system/libraries/URI.php index 59fcff3d7..8ee888a2e 100644 --- a/system/libraries/URI.php +++ b/system/libraries/URI.php @@ -586,3 +586,4 @@ class CI_URI { } // END URI Class +?> \ No newline at end of file diff --git a/system/libraries/Unit_test.php b/system/libraries/Unit_test.php index e02ecf037..3cdf45f12 100644 --- a/system/libraries/Unit_test.php +++ b/system/libraries/Unit_test.php @@ -340,3 +340,4 @@ function is_false($test) return (is_bool($test) AND $test === FALSE) ? TRUE : FALSE; } +?> \ No newline at end of file diff --git a/system/libraries/Upload.php b/system/libraries/Upload.php index e0ce2b037..317cf9560 100644 --- a/system/libraries/Upload.php +++ b/system/libraries/Upload.php @@ -875,3 +875,4 @@ class CI_Upload { } // END Upload Class +?> \ No newline at end of file diff --git a/system/libraries/User_agent.php b/system/libraries/User_agent.php index a8ce787dc..dd60a56a1 100644 --- a/system/libraries/User_agent.php +++ b/system/libraries/User_agent.php @@ -497,3 +497,4 @@ class CI_User_agent { } +?> \ No newline at end of file diff --git a/system/libraries/Validation.php b/system/libraries/Validation.php index 8a81568c4..f628d8612 100644 --- a/system/libraries/Validation.php +++ b/system/libraries/Validation.php @@ -805,3 +805,4 @@ class CI_Validation { } // END Validation Class +?> \ No newline at end of file diff --git a/system/libraries/Xmlrpc.php b/system/libraries/Xmlrpc.php index dee71f4d1..f8ad01714 100644 --- a/system/libraries/Xmlrpc.php +++ b/system/libraries/Xmlrpc.php @@ -1416,3 +1416,4 @@ class XML_RPC_Values extends CI_Xmlrpc } // END XML_RPC_Values Class +?> \ No newline at end of file diff --git a/system/libraries/Xmlrpcs.php b/system/libraries/Xmlrpcs.php index 11f0cfc40..7a4bc825e 100644 --- a/system/libraries/Xmlrpcs.php +++ b/system/libraries/Xmlrpcs.php @@ -531,3 +531,4 @@ class CI_Xmlrpcs extends CI_Xmlrpc } // END XML_RPC_Server class +?> \ No newline at end of file diff --git a/system/libraries/Zip.php b/system/libraries/Zip.php index 1940ded37..f7f47ab42 100644 --- a/system/libraries/Zip.php +++ b/system/libraries/Zip.php @@ -374,3 +374,4 @@ class CI_Zip { } } +?> \ No newline at end of file diff --git a/system/plugins/captcha_pi.php b/system/plugins/captcha_pi.php index ac31f590c..309ef7ea5 100644 --- a/system/plugins/captcha_pi.php +++ b/system/plugins/captcha_pi.php @@ -351,3 +351,4 @@ function create_captcha($data = '', $img_path = '', $img_url = '', $font_path = return array('word' => $word, 'time' => $now, 'image' => $img); } +?> \ No newline at end of file diff --git a/system/scaffolding/Scaffolding.php b/system/scaffolding/Scaffolding.php index 559807b7e..64f62a3d6 100644 --- a/system/scaffolding/Scaffolding.php +++ b/system/scaffolding/Scaffolding.php @@ -286,3 +286,4 @@ class Scaffolding { } } +?> \ No newline at end of file -- cgit v1.2.3-24-g4f1b From a3ffbbb75ab9403941e4f810703313432b3993cc Mon Sep 17 00:00:00 2001 From: Derek Jones Date: Sun, 11 May 2008 18:18:29 +0000 Subject: Removed closing PHP tags, replaced with a comment block identifying the end of the file --- system/application/config/autoload.php | 4 +++- system/application/config/config.php | 4 +++- system/application/config/constants.php | 4 +++- system/application/config/database.php | 4 +++- system/application/config/hooks.php | 4 +++- system/application/config/mimes.php | 4 +++- system/application/config/routes.php | 4 +++- system/application/config/smileys.php | 4 +++- system/application/config/user_agents.php | 4 +++- system/application/controllers/welcome.php | 4 +++- system/codeigniter/Base4.php | 4 +++- system/codeigniter/Base5.php | 4 +++- system/codeigniter/CodeIgniter.php | 4 +++- system/codeigniter/Common.php | 4 +++- system/codeigniter/Compat.php | 4 +++- system/database/DB.php | 4 +++- system/database/DB_active_rec.php | 4 +++- system/database/DB_cache.php | 4 +++- system/database/DB_driver.php | 4 +++- system/database/DB_forge.php | 4 +++- system/database/DB_result.php | 4 +++- system/database/DB_utility.php | 4 +++- system/database/drivers/mssql/mssql_driver.php | 4 +++- system/database/drivers/mssql/mssql_forge.php | 4 +++- system/database/drivers/mssql/mssql_result.php | 4 +++- system/database/drivers/mssql/mssql_utility.php | 4 +++- system/database/drivers/mysql/mysql_driver.php | 4 +++- system/database/drivers/mysql/mysql_forge.php | 4 +++- system/database/drivers/mysql/mysql_result.php | 4 +++- system/database/drivers/mysql/mysql_utility.php | 4 +++- system/database/drivers/mysqli/mysqli_driver.php | 4 +++- system/database/drivers/mysqli/mysqli_forge.php | 4 +++- system/database/drivers/mysqli/mysqli_result.php | 4 +++- system/database/drivers/mysqli/mysqli_utility.php | 4 +++- system/database/drivers/oci8/oci8_driver.php | 4 +++- system/database/drivers/oci8/oci8_forge.php | 4 +++- system/database/drivers/oci8/oci8_result.php | 4 +++- system/database/drivers/oci8/oci8_utility.php | 4 +++- system/database/drivers/odbc/odbc_driver.php | 4 +++- system/database/drivers/odbc/odbc_forge.php | 4 +++- system/database/drivers/odbc/odbc_result.php | 4 +++- system/database/drivers/odbc/odbc_utility.php | 4 +++- system/database/drivers/postgre/postgre_driver.php | 4 +++- system/database/drivers/postgre/postgre_forge.php | 4 +++- system/database/drivers/postgre/postgre_result.php | 4 +++- system/database/drivers/postgre/postgre_utility.php | 4 +++- system/database/drivers/sqlite/sqlite_driver.php | 4 +++- system/database/drivers/sqlite/sqlite_forge.php | 4 +++- system/database/drivers/sqlite/sqlite_result.php | 4 +++- system/database/drivers/sqlite/sqlite_utility.php | 4 +++- system/helpers/array_helper.php | 4 +++- system/helpers/compatibility_helper.php | 4 +++- system/helpers/cookie_helper.php | 4 +++- system/helpers/date_helper.php | 4 +++- system/helpers/directory_helper.php | 4 +++- system/helpers/download_helper.php | 4 +++- system/helpers/email_helper.php | 4 +++- system/helpers/file_helper.php | 6 ++++-- system/helpers/form_helper.php | 4 +++- system/helpers/html_helper.php | 4 +++- system/helpers/inflector_helper.php | 4 +++- system/helpers/path_helper.php | 4 +++- system/helpers/security_helper.php | 4 +++- system/helpers/smiley_helper.php | 4 +++- system/helpers/string_helper.php | 4 +++- system/helpers/text_helper.php | 4 +++- system/helpers/typography_helper.php | 4 +++- system/helpers/url_helper.php | 4 +++- system/helpers/xml_helper.php | 4 +++- system/language/english/calendar_lang.php | 4 +++- system/language/english/date_lang.php | 4 +++- system/language/english/db_lang.php | 4 +++- system/language/english/email_lang.php | 4 +++- system/language/english/ftp_lang.php | 4 +++- system/language/english/imglib_lang.php | 4 +++- system/language/english/profiler_lang.php | 4 +++- system/language/english/scaffolding_lang.php | 4 +++- system/language/english/unit_test_lang.php | 4 +++- system/language/english/upload_lang.php | 4 +++- system/language/english/validation_lang.php | 4 +++- system/libraries/Benchmark.php | 4 +++- system/libraries/Calendar.php | 4 +++- system/libraries/Config.php | 4 +++- system/libraries/Controller.php | 4 +++- system/libraries/Email.php | 4 +++- system/libraries/Encrypt.php | 4 +++- system/libraries/Exceptions.php | 4 +++- system/libraries/Ftp.php | 4 +++- system/libraries/Hooks.php | 4 +++- system/libraries/Image_lib.php | 4 +++- system/libraries/Input.php | 4 +++- system/libraries/Language.php | 4 +++- system/libraries/Loader.php | 4 +++- system/libraries/Log.php | 4 +++- system/libraries/Model.php | 4 +++- system/libraries/Output.php | 4 +++- system/libraries/Pagination.php | 4 +++- system/libraries/Parser.php | 4 +++- system/libraries/Profiler.php | 4 +++- system/libraries/Router.php | 4 +++- system/libraries/Session.php | 4 +++- system/libraries/Sha1.php | 4 +++- system/libraries/Table.php | 4 +++- system/libraries/Trackback.php | 4 +++- system/libraries/URI.php | 4 +++- system/libraries/Unit_test.php | 4 +++- system/libraries/Upload.php | 4 +++- system/libraries/User_agent.php | 4 +++- system/libraries/Validation.php | 4 +++- system/libraries/Xmlrpc.php | 4 +++- system/libraries/Xmlrpcs.php | 4 +++- system/libraries/Zip.php | 4 +++- system/plugins/captcha_pi.php | 4 +++- system/plugins/js_calendar_pi.php | 4 +++- system/scaffolding/Scaffolding.php | 4 +++- system/scaffolding/views/add.php | 4 +++- system/scaffolding/views/delete.php | 4 +++- system/scaffolding/views/edit.php | 4 +++- system/scaffolding/views/no_data.php | 4 +++- system/scaffolding/views/view.php | 4 +++- 120 files changed, 361 insertions(+), 121 deletions(-) (limited to 'system') diff --git a/system/application/config/autoload.php b/system/application/config/autoload.php index 2dfbe422c..e3e76d560 100644 --- a/system/application/config/autoload.php +++ b/system/application/config/autoload.php @@ -122,4 +122,6 @@ $autoload['model'] = array(); // $autoload['core'] = array(); -?> \ No newline at end of file + +/* End of file autoload.php */ +/* Location: ./system/application/config/autoload.php */ \ No newline at end of file diff --git a/system/application/config/config.php b/system/application/config/config.php index 24fbb4b7a..c93127366 100644 --- a/system/application/config/config.php +++ b/system/application/config/config.php @@ -311,4 +311,6 @@ $config['time_reference'] = 'local'; $config['rewrite_short_tags'] = FALSE; -?> \ No newline at end of file + +/* End of file config.php */ +/* Location: ./system/application/config/config.php */ \ No newline at end of file diff --git a/system/application/config/constants.php b/system/application/config/constants.php index 3f7975635..020baa2d1 100644 --- a/system/application/config/constants.php +++ b/system/application/config/constants.php @@ -36,4 +36,6 @@ define('FOPEN_READ_WRITE_CREATE', 'a+b'); define('FOPEN_WRITE_CREATE_STRICT', 'xb'); define('FOPEN_READ_WRITE_CREATE_STRICT', 'x+b'); -?> \ No newline at end of file + +/* End of file constants.php */ +/* Location: ./system/application/config/constants.php */ \ No newline at end of file diff --git a/system/application/config/database.php b/system/application/config/database.php index 6973c5afa..e8eebef97 100644 --- a/system/application/config/database.php +++ b/system/application/config/database.php @@ -50,4 +50,6 @@ $db['default']['cachedir'] = ""; $db['default']['char_set'] = "utf8"; $db['default']['dbcollat'] = "utf8_general_ci"; -?> \ No newline at end of file + +/* End of file database.php */ +/* Location: ./system/application/config/database.php */ \ No newline at end of file diff --git a/system/application/config/hooks.php b/system/application/config/hooks.php index f0a0d6e3a..b13ce6cbd 100644 --- a/system/application/config/hooks.php +++ b/system/application/config/hooks.php @@ -11,4 +11,6 @@ */ -?> \ No newline at end of file + +/* End of file hooks.php */ +/* Location: ./system/application/config/hooks.php */ \ No newline at end of file diff --git a/system/application/config/mimes.php b/system/application/config/mimes.php index 7f5f20803..f3bfe8713 100644 --- a/system/application/config/mimes.php +++ b/system/application/config/mimes.php @@ -99,4 +99,6 @@ $mimes = array( 'hqx' => 'application/mac-binhex40', ); -?> \ No newline at end of file + +/* End of file mimes.php */ +/* Location: ./system/application/config/mimes.php */ \ No newline at end of file diff --git a/system/application/config/routes.php b/system/application/config/routes.php index 1395b7aed..5cd3cca70 100644 --- a/system/application/config/routes.php +++ b/system/application/config/routes.php @@ -43,4 +43,6 @@ $route['default_controller'] = "welcome"; $route['scaffolding_trigger'] = ""; -?> \ No newline at end of file + +/* End of file routes.php */ +/* Location: ./system/application/config/routes.php */ \ No newline at end of file diff --git a/system/application/config/smileys.php b/system/application/config/smileys.php index a227d8b68..5968f3733 100644 --- a/system/application/config/smileys.php +++ b/system/application/config/smileys.php @@ -61,4 +61,6 @@ $smileys = array( ':question:' => array('question.gif', '19', '19', 'question') // no comma after last item ); -?> \ No newline at end of file + +/* End of file smileys.php */ +/* Location: ./system/application/config/smileys.php */ \ No newline at end of file diff --git a/system/application/config/user_agents.php b/system/application/config/user_agents.php index 08a665f9d..4a59ab6bc 100644 --- a/system/application/config/user_agents.php +++ b/system/application/config/user_agents.php @@ -100,4 +100,6 @@ $robots = array( ); -?> \ No newline at end of file + +/* End of file user_agents.php */ +/* Location: ./system/application/config/user_agents.php */ \ No newline at end of file diff --git a/system/application/controllers/welcome.php b/system/application/controllers/welcome.php index 7f7296d81..20d48855e 100644 --- a/system/application/controllers/welcome.php +++ b/system/application/controllers/welcome.php @@ -12,4 +12,6 @@ class Welcome extends Controller { $this->load->view('welcome_message'); } } -?> \ No newline at end of file + +/* End of file welcome.php */ +/* Location: ./system/application/controllers/welcome.php */ \ No newline at end of file diff --git a/system/codeigniter/Base4.php b/system/codeigniter/Base4.php index 577977c1c..178b1b8b7 100644 --- a/system/codeigniter/Base4.php +++ b/system/codeigniter/Base4.php @@ -64,4 +64,6 @@ function &get_instance() return $OBJ->load; } -?> \ No newline at end of file + +/* End of file Base4.php */ +/* Location: ./system/codeigniter/Base4.php */ \ No newline at end of file diff --git a/system/codeigniter/Base5.php b/system/codeigniter/Base5.php index c731a00c4..8f9416537 100644 --- a/system/codeigniter/Base5.php +++ b/system/codeigniter/Base5.php @@ -51,4 +51,6 @@ function &get_instance() } -?> \ No newline at end of file + +/* End of file Base5.php */ +/* Location: ./system/codeigniter/Base5.php */ \ No newline at end of file diff --git a/system/codeigniter/CodeIgniter.php b/system/codeigniter/CodeIgniter.php index 75332e678..642ff7801 100644 --- a/system/codeigniter/CodeIgniter.php +++ b/system/codeigniter/CodeIgniter.php @@ -273,4 +273,6 @@ if (class_exists('CI_DB') AND isset($CI->db)) } -?> \ No newline at end of file + +/* End of file CodeIgniter.php */ +/* Location: ./system/codeigniter/CodeIgniter.php */ \ No newline at end of file diff --git a/system/codeigniter/Common.php b/system/codeigniter/Common.php index c5c548cdf..d4c88c15f 100644 --- a/system/codeigniter/Common.php +++ b/system/codeigniter/Common.php @@ -295,4 +295,6 @@ function _exception_handler($severity, $message, $filepath, $line) } -?> \ No newline at end of file + +/* End of file Common.php */ +/* Location: ./system/codeigniter/Common.php */ \ No newline at end of file diff --git a/system/codeigniter/Compat.php b/system/codeigniter/Compat.php index 8537432f5..1f01ca812 100644 --- a/system/codeigniter/Compat.php +++ b/system/codeigniter/Compat.php @@ -91,4 +91,6 @@ if (! function_exists('ctype_alnum')) // -------------------------------------------------------------------- -?> \ No newline at end of file + +/* End of file Compat.php */ +/* Location: ./system/codeigniter/Compat.php */ \ No newline at end of file diff --git a/system/database/DB.php b/system/database/DB.php index 8efe05560..d603805a5 100644 --- a/system/database/DB.php +++ b/system/database/DB.php @@ -120,4 +120,6 @@ function &DB($params = '', $active_record_override = FALSE) } -?> \ No newline at end of file + +/* 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 index 49d438727..a4ef2e4db 100644 --- a/system/database/DB_active_rec.php +++ b/system/database/DB_active_rec.php @@ -1749,4 +1749,6 @@ class CI_DB_active_record extends CI_DB_driver { } } -?> \ No newline at end of file + +/* 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 index 982725aaa..21113aff3 100644 --- a/system/database/DB_cache.php +++ b/system/database/DB_cache.php @@ -186,4 +186,6 @@ class CI_DB_Cache { } -?> \ No newline at end of file + +/* 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 index a5ca75dd6..c296d4ca8 100644 --- a/system/database/DB_driver.php +++ b/system/database/DB_driver.php @@ -1145,4 +1145,6 @@ class CI_DB_driver { } -?> \ No newline at end of file + +/* 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 index 2ddb21be7..d7259c08c 100644 --- a/system/database/DB_forge.php +++ b/system/database/DB_forge.php @@ -341,4 +341,6 @@ class CI_DB_forge { } } -?> \ No newline at end of file + +/* End of file DB_forge.php */ +/* Location: ./system/database/DB_forge.php */ \ No newline at end of file diff --git a/system/database/DB_result.php b/system/database/DB_result.php index cfe9d2a32..b98d7a97b 100644 --- a/system/database/DB_result.php +++ b/system/database/DB_result.php @@ -338,4 +338,6 @@ class CI_DB_result { } // END DB_result class -?> \ No newline at end of file + +/* End of file DB_result.php */ +/* Location: ./system/database/DB_result.php */ \ No newline at end of file diff --git a/system/database/DB_utility.php b/system/database/DB_utility.php index 11f1fb4de..5d4c2de45 100644 --- a/system/database/DB_utility.php +++ b/system/database/DB_utility.php @@ -384,4 +384,6 @@ class CI_DB_utility extends CI_DB_forge { } -?> \ No newline at end of file + +/* End of file DB_utility.php */ +/* Location: ./system/database/DB_utility.php */ \ No newline at end of file diff --git a/system/database/drivers/mssql/mssql_driver.php b/system/database/drivers/mssql/mssql_driver.php index 6e67c57c0..f789634f8 100644 --- a/system/database/drivers/mssql/mssql_driver.php +++ b/system/database/drivers/mssql/mssql_driver.php @@ -641,4 +641,6 @@ class CI_DB_mssql_driver extends CI_DB { } -?> \ No newline at end of file + +/* End of file mssql_driver.php */ +/* Location: ./system/database/drivers/mssql/mssql_driver.php */ \ No newline at end of file diff --git a/system/database/drivers/mssql/mssql_forge.php b/system/database/drivers/mssql/mssql_forge.php index 63063f259..d42fd5ee6 100644 --- a/system/database/drivers/mssql/mssql_forge.php +++ b/system/database/drivers/mssql/mssql_forge.php @@ -235,4 +235,6 @@ class CI_DB_mssql_forge extends CI_DB_forge { } } -?> \ No newline at end of file + +/* 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 index c95fd91f6..fded4cf37 100644 --- a/system/database/drivers/mssql/mssql_result.php +++ b/system/database/drivers/mssql/mssql_result.php @@ -170,4 +170,6 @@ class CI_DB_mssql_result extends CI_DB_result { } -?> \ No newline at end of file + +/* End of file mssql_result.php */ +/* Location: ./system/database/drivers/mssql/mssql_result.php */ \ No newline at end of file diff --git a/system/database/drivers/mssql/mssql_utility.php b/system/database/drivers/mssql/mssql_utility.php index 87f8196f7..75a8fb4cd 100644 --- a/system/database/drivers/mssql/mssql_utility.php +++ b/system/database/drivers/mssql/mssql_utility.php @@ -118,4 +118,6 @@ class CI_DB_mssql_utility extends CI_DB_utility { } -?> \ No newline at end of file + +/* 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/mysql_driver.php b/system/database/drivers/mysql/mysql_driver.php index f15983d2b..397af02f5 100644 --- a/system/database/drivers/mysql/mysql_driver.php +++ b/system/database/drivers/mysql/mysql_driver.php @@ -649,4 +649,6 @@ class CI_DB_mysql_driver extends CI_DB { } -?> \ No newline at end of file + +/* 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 index 4eb449ef2..6701c42d5 100644 --- a/system/database/drivers/mysql/mysql_forge.php +++ b/system/database/drivers/mysql/mysql_forge.php @@ -238,4 +238,6 @@ class CI_DB_mysql_forge extends CI_DB_forge { } } -?> \ No newline at end of file + +/* 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 index 9e6a3c3d1..01b57e1e7 100644 --- a/system/database/drivers/mysql/mysql_result.php +++ b/system/database/drivers/mysql/mysql_result.php @@ -170,4 +170,6 @@ class CI_DB_mysql_result extends CI_DB_result { } -?> \ No newline at end of file + +/* 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 index dc8fd0866..0804f291c 100644 --- a/system/database/drivers/mysql/mysql_utility.php +++ b/system/database/drivers/mysql/mysql_utility.php @@ -249,4 +249,6 @@ class CI_DB_mysql_utility extends CI_DB_utility { } } -?> \ No newline at end of file + +/* 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/mysqli_driver.php b/system/database/drivers/mysqli/mysqli_driver.php index a196f755a..c993e3368 100644 --- a/system/database/drivers/mysqli/mysqli_driver.php +++ b/system/database/drivers/mysqli/mysqli_driver.php @@ -645,4 +645,6 @@ class CI_DB_mysqli_driver extends CI_DB { } -?> \ No newline at end of file + +/* End of file mysqli_driver.php */ +/* Location: ./system/database/drivers/mysqli/mysqli_driver.php */ \ No newline at end of file diff --git a/system/database/drivers/mysqli/mysqli_forge.php b/system/database/drivers/mysqli/mysqli_forge.php index e6bc0093f..087f9b80b 100644 --- a/system/database/drivers/mysqli/mysqli_forge.php +++ b/system/database/drivers/mysqli/mysqli_forge.php @@ -238,4 +238,6 @@ class CI_DB_mysqli_forge extends CI_DB_forge { } } -?> \ No newline at end of file + +/* 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 index 692d4f729..6b42d35e9 100644 --- a/system/database/drivers/mysqli/mysqli_result.php +++ b/system/database/drivers/mysqli/mysqli_result.php @@ -170,4 +170,6 @@ class CI_DB_mysqli_result extends CI_DB_result { } -?> \ No newline at end of file + +/* End of file mysqli_result.php */ +/* Location: ./system/database/drivers/mysqli/mysqli_result.php */ \ No newline at end of file diff --git a/system/database/drivers/mysqli/mysqli_utility.php b/system/database/drivers/mysqli/mysqli_utility.php index 4ab2bb1d1..24b05b7af 100644 --- a/system/database/drivers/mysqli/mysqli_utility.php +++ b/system/database/drivers/mysqli/mysqli_utility.php @@ -118,4 +118,6 @@ class CI_DB_mysqli_utility extends CI_DB_utility { } } -?> \ No newline at end of file + +/* End of file mysqli_utility.php */ +/* Location: ./system/database/drivers/mysqli/mysqli_utility.php */ \ No newline at end of file diff --git a/system/database/drivers/oci8/oci8_driver.php b/system/database/drivers/oci8/oci8_driver.php index 8fc20449f..367095990 100644 --- a/system/database/drivers/oci8/oci8_driver.php +++ b/system/database/drivers/oci8/oci8_driver.php @@ -761,4 +761,6 @@ class CI_DB_oci8_driver extends CI_DB { } -?> \ No newline at end of file + +/* End of file oci8_driver.php */ +/* Location: ./system/database/drivers/oci8/oci8_driver.php */ \ No newline at end of file diff --git a/system/database/drivers/oci8/oci8_forge.php b/system/database/drivers/oci8/oci8_forge.php index a3940aedb..64dd2a202 100644 --- a/system/database/drivers/oci8/oci8_forge.php +++ b/system/database/drivers/oci8/oci8_forge.php @@ -232,4 +232,6 @@ class CI_DB_oci8_forge extends CI_DB_forge { } -?> \ No newline at end of file + +/* 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 index 30dd0da09..416c57de0 100644 --- a/system/database/drivers/oci8/oci8_result.php +++ b/system/database/drivers/oci8/oci8_result.php @@ -248,4 +248,6 @@ class CI_DB_oci8_result extends CI_DB_result { } -?> \ No newline at end of file + +/* End of file oci8_result.php */ +/* Location: ./system/database/drivers/oci8/oci8_result.php */ \ No newline at end of file diff --git a/system/database/drivers/oci8/oci8_utility.php b/system/database/drivers/oci8/oci8_utility.php index 117f8e629..93eaa226f 100644 --- a/system/database/drivers/oci8/oci8_utility.php +++ b/system/database/drivers/oci8/oci8_utility.php @@ -117,4 +117,6 @@ class CI_DB_oci8_utility extends CI_DB_utility { } } -?> \ No newline at end of file + +/* 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/odbc_driver.php b/system/database/drivers/odbc/odbc_driver.php index 20e34ec7b..4511592bb 100644 --- a/system/database/drivers/odbc/odbc_driver.php +++ b/system/database/drivers/odbc/odbc_driver.php @@ -613,4 +613,6 @@ class CI_DB_odbc_driver extends CI_DB { } -?> \ No newline at end of file + +/* End of file odbc_driver.php */ +/* Location: ./system/database/drivers/odbc/odbc_driver.php */ \ No newline at end of file diff --git a/system/database/drivers/odbc/odbc_forge.php b/system/database/drivers/odbc/odbc_forge.php index 66e1722d8..fb011f298 100644 --- a/system/database/drivers/odbc/odbc_forge.php +++ b/system/database/drivers/odbc/odbc_forge.php @@ -253,4 +253,6 @@ class CI_DB_odbc_forge extends CI_DB_forge { } -?> \ No newline at end of file + +/* 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 index dd3f92382..4acfb056e 100644 --- a/system/database/drivers/odbc/odbc_result.php +++ b/system/database/drivers/odbc/odbc_result.php @@ -229,4 +229,6 @@ class CI_DB_odbc_result extends CI_DB_result { } -?> \ No newline at end of file + +/* End of file odbc_result.php */ +/* Location: ./system/database/drivers/odbc/odbc_result.php */ \ No newline at end of file diff --git a/system/database/drivers/odbc/odbc_utility.php b/system/database/drivers/odbc/odbc_utility.php index f74d031bd..ac8b5d808 100644 --- a/system/database/drivers/odbc/odbc_utility.php +++ b/system/database/drivers/odbc/odbc_utility.php @@ -143,4 +143,6 @@ class CI_DB_odbc_utility extends CI_DB_utility { return FALSE; } } -?> \ No newline at end of file + +/* 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/postgre/postgre_driver.php b/system/database/drivers/postgre/postgre_driver.php index 46ba1d009..4fd92f0c0 100644 --- a/system/database/drivers/postgre/postgre_driver.php +++ b/system/database/drivers/postgre/postgre_driver.php @@ -641,4 +641,6 @@ class CI_DB_postgre_driver extends CI_DB { } -?> \ No newline at end of file + +/* End of file postgre_driver.php */ +/* Location: ./system/database/drivers/postgre/postgre_driver.php */ \ No newline at end of file diff --git a/system/database/drivers/postgre/postgre_forge.php b/system/database/drivers/postgre/postgre_forge.php index 72a61748d..fb4fcf128 100644 --- a/system/database/drivers/postgre/postgre_forge.php +++ b/system/database/drivers/postgre/postgre_forge.php @@ -235,4 +235,6 @@ class CI_DB_postgre_forge extends CI_DB_forge { } -?> \ No newline at end of file + +/* 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 index fdce01aac..25360b3f3 100644 --- a/system/database/drivers/postgre/postgre_result.php +++ b/system/database/drivers/postgre/postgre_result.php @@ -170,4 +170,6 @@ class CI_DB_postgre_result extends CI_DB_result { } -?> \ No newline at end of file + +/* End of file postgre_result.php */ +/* Location: ./system/database/drivers/postgre/postgre_result.php */ \ No newline at end of file diff --git a/system/database/drivers/postgre/postgre_utility.php b/system/database/drivers/postgre/postgre_utility.php index 573654f68..17df599b6 100644 --- a/system/database/drivers/postgre/postgre_utility.php +++ b/system/database/drivers/postgre/postgre_utility.php @@ -119,4 +119,6 @@ class CI_DB_postgre_utility extends CI_DB_utility { } -?> \ No newline at end of file + +/* End of file postgre_utility.php */ +/* Location: ./system/database/drivers/postgre/postgre_utility.php */ \ No newline at end of file diff --git a/system/database/drivers/sqlite/sqlite_driver.php b/system/database/drivers/sqlite/sqlite_driver.php index 70148f360..cb53ad91a 100644 --- a/system/database/drivers/sqlite/sqlite_driver.php +++ b/system/database/drivers/sqlite/sqlite_driver.php @@ -656,4 +656,6 @@ class CI_DB_sqlite_driver extends CI_DB { } -?> \ No newline at end of file + +/* End of file sqlite_driver.php */ +/* Location: ./system/database/drivers/sqlite/sqlite_driver.php */ \ No newline at end of file diff --git a/system/database/drivers/sqlite/sqlite_forge.php b/system/database/drivers/sqlite/sqlite_forge.php index 44950bfc7..8a1a4da01 100644 --- a/system/database/drivers/sqlite/sqlite_forge.php +++ b/system/database/drivers/sqlite/sqlite_forge.php @@ -231,4 +231,6 @@ class CI_DB_sqlite_forge extends CI_DB_forge { } } -?> \ No newline at end of file + +/* 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 index b8f3dc5b7..72c93fd48 100644 --- a/system/database/drivers/sqlite/sqlite_result.php +++ b/system/database/drivers/sqlite/sqlite_result.php @@ -180,4 +180,6 @@ class CI_DB_sqlite_result extends CI_DB_result { } -?> \ No newline at end of file + +/* End of file sqlite_result.php */ +/* Location: ./system/database/drivers/sqlite/sqlite_result.php */ \ No newline at end of file diff --git a/system/database/drivers/sqlite/sqlite_utility.php b/system/database/drivers/sqlite/sqlite_utility.php index ab58f8fd7..c85e36575 100644 --- a/system/database/drivers/sqlite/sqlite_utility.php +++ b/system/database/drivers/sqlite/sqlite_utility.php @@ -136,4 +136,6 @@ class CI_DB_sqlite_utility extends CI_DB_utility { } } -?> \ No newline at end of file + +/* End of file sqlite_utility.php */ +/* Location: ./system/database/drivers/sqlite/sqlite_utility.php */ \ No newline at end of file diff --git a/system/helpers/array_helper.php b/system/helpers/array_helper.php index 8ae44826a..837e41f14 100644 --- a/system/helpers/array_helper.php +++ b/system/helpers/array_helper.php @@ -73,4 +73,6 @@ if (! function_exists('random_element')) } } -?> \ No newline at end of file + +/* End of file array_helper.php */ +/* Location: ./system/helpers/array_helper.php */ \ No newline at end of file diff --git a/system/helpers/compatibility_helper.php b/system/helpers/compatibility_helper.php index 0d214648c..076f677fa 100644 --- a/system/helpers/compatibility_helper.php +++ b/system/helpers/compatibility_helper.php @@ -493,4 +493,6 @@ if (! function_exists('http_build_query')) } } -?> \ No newline at end of file + +/* End of file compatibility_helper.php */ +/* Location: ./system/helpers/compatibility_helper.php */ \ No newline at end of file diff --git a/system/helpers/cookie_helper.php b/system/helpers/cookie_helper.php index 75c769e9c..7b8989e3b 100644 --- a/system/helpers/cookie_helper.php +++ b/system/helpers/cookie_helper.php @@ -131,4 +131,6 @@ if (! function_exists('delete_cookie')) } } -?> \ No newline at end of file + +/* 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 index 004cfb122..c4f0e9a40 100644 --- a/system/helpers/date_helper.php +++ b/system/helpers/date_helper.php @@ -596,4 +596,6 @@ if (! function_exists('timezones')) } } -?> \ No newline at end of file + +/* End of file date_helper.php */ +/* Location: ./system/helpers/date_helper.php */ \ No newline at end of file diff --git a/system/helpers/directory_helper.php b/system/helpers/directory_helper.php index 25c16c1fc..7af4d1e38 100644 --- a/system/helpers/directory_helper.php +++ b/system/helpers/directory_helper.php @@ -75,4 +75,6 @@ if (! function_exists('directory_map')) } } -?> \ No newline at end of file + +/* End of file directory_helper.php */ +/* Location: ./system/helpers/directory_helper.php */ \ No newline at end of file diff --git a/system/helpers/download_helper.php b/system/helpers/download_helper.php index 284c6c96e..2096fd849 100644 --- a/system/helpers/download_helper.php +++ b/system/helpers/download_helper.php @@ -95,4 +95,6 @@ if (! function_exists('force_download')) } } -?> \ No newline at end of file + +/* End of file download_helper.php */ +/* Location: ./system/helpers/download_helper.php */ \ No newline at end of file diff --git a/system/helpers/email_helper.php b/system/helpers/email_helper.php index 307f3b588..594a030fe 100644 --- a/system/helpers/email_helper.php +++ b/system/helpers/email_helper.php @@ -57,4 +57,6 @@ if (! function_exists('send_email')) } } -?> \ No newline at end of file + +/* End of file email_helper.php */ +/* Location: ./system/helpers/email_helper.php */ \ No newline at end of file diff --git a/system/helpers/file_helper.php b/system/helpers/file_helper.php index bdde2d55d..fac916f3d 100644 --- a/system/helpers/file_helper.php +++ b/system/helpers/file_helper.php @@ -87,7 +87,7 @@ if (! function_exists('write_file')) { function write_file($path, $data, $mode = FOPEN_WRITE_CREATE_DESTRUCTIVE) { - if (! $fp = @fopen($path, $mode)) + if (! $fp = fopen($path, $mode)) { return FALSE; } @@ -456,4 +456,6 @@ if (! function_exists('octal_permissions')) } } -?> \ No newline at end of file + +/* 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 index c9a6897ae..541ab844a 100644 --- a/system/helpers/form_helper.php +++ b/system/helpers/form_helper.php @@ -610,4 +610,6 @@ if (! function_exists('parse_form_attributes')) } } -?> \ No newline at end of file + +/* End of file form_helper.php */ +/* Location: ./system/helpers/form_helper.php */ \ No newline at end of file diff --git a/system/helpers/html_helper.php b/system/helpers/html_helper.php index 4e86465c1..592c33a50 100644 --- a/system/helpers/html_helper.php +++ b/system/helpers/html_helper.php @@ -351,4 +351,6 @@ if (! function_exists('nbs')) } } -?> \ No newline at end of file + +/* End of file html_helper.php */ +/* Location: ./system/helpers/html_helper.php */ \ No newline at end of file diff --git a/system/helpers/inflector_helper.php b/system/helpers/inflector_helper.php index bf70a6799..b0b99be54 100644 --- a/system/helpers/inflector_helper.php +++ b/system/helpers/inflector_helper.php @@ -164,4 +164,6 @@ if (! function_exists('humanize')) } } -?> \ No newline at end of file + +/* End of file inflector_helper.php */ +/* Location: ./system/helpers/inflector_helper.php */ \ No newline at end of file diff --git a/system/helpers/path_helper.php b/system/helpers/path_helper.php index 6abff06af..05bbd0027 100644 --- a/system/helpers/path_helper.php +++ b/system/helpers/path_helper.php @@ -67,4 +67,6 @@ if (! function_exists('set_realpath')) } } -?> \ No newline at end of file + +/* End of file path_helper.php */ +/* Location: ./system/helpers/path_helper.php */ \ No newline at end of file diff --git a/system/helpers/security_helper.php b/system/helpers/security_helper.php index edb6ebb50..0dc1429dd 100644 --- a/system/helpers/security_helper.php +++ b/system/helpers/security_helper.php @@ -121,4 +121,6 @@ if (! function_exists('encode_php_tags')) } } -?> \ No newline at end of file + +/* 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 index 81c6b9199..2162ddda0 100644 --- a/system/helpers/smiley_helper.php +++ b/system/helpers/smiley_helper.php @@ -170,4 +170,6 @@ if (! function_exists('_get_smiley_array')) } } -?> \ No newline at end of file + +/* End of file smiley_helper.php */ +/* Location: ./system/helpers/smiley_helper.php */ \ No newline at end of file diff --git a/system/helpers/string_helper.php b/system/helpers/string_helper.php index f68f44ac1..b934723bf 100644 --- a/system/helpers/string_helper.php +++ b/system/helpers/string_helper.php @@ -268,4 +268,6 @@ if (! function_exists('repeater')) } } -?> \ No newline at end of file + +/* 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 index df3c89e6f..2d03699f3 100644 --- a/system/helpers/text_helper.php +++ b/system/helpers/text_helper.php @@ -436,4 +436,6 @@ if (! function_exists('word_wrap')) } } -?> \ No newline at end of file + +/* 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 index 88071604d..78ade5cc3 100644 --- a/system/helpers/typography_helper.php +++ b/system/helpers/typography_helper.php @@ -542,4 +542,6 @@ class Auto_typography { } -?> \ No newline at end of file + +/* 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 index d702f6b87..32d2da80e 100644 --- a/system/helpers/url_helper.php +++ b/system/helpers/url_helper.php @@ -532,4 +532,6 @@ if (! function_exists('_parse_attributes')) } } -?> \ No newline at end of file + +/* End of file url_helper.php */ +/* Location: ./system/helpers/url_helper.php */ \ No newline at end of file diff --git a/system/helpers/xml_helper.php b/system/helpers/xml_helper.php index 5aa6de9ec..b91664433 100644 --- a/system/helpers/xml_helper.php +++ b/system/helpers/xml_helper.php @@ -57,4 +57,6 @@ if (! function_exists('xml_convert')) } } -?> \ No newline at end of file + +/* End of file xml_helper.php */ +/* Location: ./system/helpers/xml_helper.php */ \ No newline at end of file diff --git a/system/language/english/calendar_lang.php b/system/language/english/calendar_lang.php index 9ee4a5e69..107c0f733 100644 --- a/system/language/english/calendar_lang.php +++ b/system/language/english/calendar_lang.php @@ -46,4 +46,6 @@ $lang['cal_october'] = "October"; $lang['cal_november'] = "November"; $lang['cal_december'] = "December"; -?> \ No newline at end of file + +/* End of file calendar_lang.php */ +/* Location: ./system/language/english/calendar_lang.php */ \ No newline at end of file diff --git a/system/language/english/date_lang.php b/system/language/english/date_lang.php index 6b18aa7be..93989eb45 100644 --- a/system/language/english/date_lang.php +++ b/system/language/english/date_lang.php @@ -46,4 +46,6 @@ $lang['UP10'] = "(UTC + 10:00) Melbourne, Papua New Guinea, Sydney, Vladivostok" $lang['UP11'] = "(UTC + 11:00) Magadan, New Caledonia, Solomon Islands"; $lang['UP12'] = "(UTC + 12:00) Auckland, Wellington, Fiji, Marshall Islands"; -?> \ No newline at end of file + +/* End of file date_lang.php */ +/* Location: ./system/language/english/date_lang.php */ \ No newline at end of file diff --git a/system/language/english/db_lang.php b/system/language/english/db_lang.php index 1e79a706d..6c053a139 100644 --- a/system/language/english/db_lang.php +++ b/system/language/english/db_lang.php @@ -22,4 +22,6 @@ $lang['db_column_name_required'] = 'A column name is required for that operation $lang['db_column_definition_required'] = 'A column definition is required for that operation.'; $lang['db_unable_to_set_charset'] = 'Unable to set client connection character set: %s'; -?> \ No newline at end of file + +/* End of file db_lang.php */ +/* Location: ./system/language/english/db_lang.php */ \ No newline at end of file diff --git a/system/language/english/email_lang.php b/system/language/english/email_lang.php index f02686509..3e94bf3c6 100644 --- a/system/language/english/email_lang.php +++ b/system/language/english/email_lang.php @@ -18,4 +18,6 @@ $lang['email_smtp_auth_un'] = "Failed to authenticate username. Error: %s"; $lang['email_smtp_auth_pw'] = "Failed to authenticate password. Error: %s"; $lang['email_smtp_data_failure'] = "Unable to send data: %s"; -?> \ No newline at end of file + +/* End of file email_lang.php */ +/* Location: ./system/language/english/email_lang.php */ \ No newline at end of file diff --git a/system/language/english/ftp_lang.php b/system/language/english/ftp_lang.php index da744fea7..e0140285f 100644 --- a/system/language/english/ftp_lang.php +++ b/system/language/english/ftp_lang.php @@ -12,4 +12,6 @@ $lang['ftp_unable_to_rename'] = "Unable to rename the file."; $lang['ftp_unable_to_delete'] = "Unable to delete the file."; $lang['ftp_unable_to_move'] = "Unable to move the file. Please make sure the destination directory exists."; -?> \ No newline at end of file + +/* End of file ftp_lang.php */ +/* Location: ./system/language/english/ftp_lang.php */ \ No newline at end of file diff --git a/system/language/english/imglib_lang.php b/system/language/english/imglib_lang.php index 520f17f35..4baf971a4 100644 --- a/system/language/english/imglib_lang.php +++ b/system/language/english/imglib_lang.php @@ -18,4 +18,6 @@ $lang['imglib_invalid_path'] = "The path to the image is not correct."; $lang['imglib_copy_failed'] = "The image copy routine failed."; $lang['imglib_missing_font'] = "Unable to find a font to use."; -?> \ No newline at end of file + +/* End of file imglib_lang.php */ +/* Location: ./system/language/english/imglib_lang.php */ \ No newline at end of file diff --git a/system/language/english/profiler_lang.php b/system/language/english/profiler_lang.php index 219a83856..e60304bbc 100644 --- a/system/language/english/profiler_lang.php +++ b/system/language/english/profiler_lang.php @@ -12,4 +12,6 @@ $lang['profiler_no_post'] = 'No POST data exists'; $lang['profiler_no_get'] = 'No GET data exists'; $lang['profiler_no_uri'] = 'No URI data exists'; $lang['profiler_no_memory'] = 'Memory Usage Unavailable'; -?> \ No newline at end of file + +/* End of file profiler_lang.php */ +/* Location: ./system/language/english/profiler_lang.php */ \ No newline at end of file diff --git a/system/language/english/scaffolding_lang.php b/system/language/english/scaffolding_lang.php index 96fe167e5..c4d54d5c6 100644 --- a/system/language/english/scaffolding_lang.php +++ b/system/language/english/scaffolding_lang.php @@ -12,4 +12,6 @@ $lang['scaff_no'] = 'No'; $lang['scaff_no_data'] = 'No data exists for this table yet.'; $lang['scaff_del_confirm'] = 'Are you sure you want to delete the following row:'; -?> \ No newline at end of file + +/* End of file scaffolding_lang.php */ +/* Location: ./system/language/english/scaffolding_lang.php */ \ No newline at end of file diff --git a/system/language/english/unit_test_lang.php b/system/language/english/unit_test_lang.php index a33cad5f2..26fc21ae8 100644 --- a/system/language/english/unit_test_lang.php +++ b/system/language/english/unit_test_lang.php @@ -19,4 +19,6 @@ $lang['ut_object'] = 'Object'; $lang['ut_resource'] = 'Resource'; $lang['ut_null'] = 'Null' -?> \ No newline at end of file + +/* End of file unit_test_lang.php */ +/* Location: ./system/language/english/unit_test_lang.php */ \ No newline at end of file diff --git a/system/language/english/upload_lang.php b/system/language/english/upload_lang.php index fa6d7c9fb..5f7d449c0 100644 --- a/system/language/english/upload_lang.php +++ b/system/language/english/upload_lang.php @@ -17,4 +17,6 @@ $lang['upload_no_file_types'] = "You have not specified any allowed file types." $lang['upload_bad_filename'] = "The file name you submitted already exists on the server."; $lang['upload_not_writable'] = "The upload destination folder does not appear to be writable."; -?> \ No newline at end of file + +/* End of file upload_lang.php */ +/* Location: ./system/language/english/upload_lang.php */ \ No newline at end of file diff --git a/system/language/english/validation_lang.php b/system/language/english/validation_lang.php index 1e9ec2c1b..f26115f40 100644 --- a/system/language/english/validation_lang.php +++ b/system/language/english/validation_lang.php @@ -15,4 +15,6 @@ $lang['numeric'] = "The %s field must contain a number."; $lang['integer'] = "The %s field must contain an integer."; $lang['matches'] = "The %s field does not match the %s field."; -?> \ No newline at end of file + +/* End of file validation_lang.php */ +/* Location: ./system/language/english/validation_lang.php */ \ No newline at end of file diff --git a/system/libraries/Benchmark.php b/system/libraries/Benchmark.php index 323d9668d..f83e86482 100644 --- a/system/libraries/Benchmark.php +++ b/system/libraries/Benchmark.php @@ -108,4 +108,6 @@ class CI_Benchmark { } // END CI_Benchmark class -?> \ No newline at end of file + +/* End of file Benchmark.php */ +/* Location: ./system/libraries/Benchmark.php */ \ No newline at end of file diff --git a/system/libraries/Calendar.php b/system/libraries/Calendar.php index e9621fec1..fbb275c5f 100644 --- a/system/libraries/Calendar.php +++ b/system/libraries/Calendar.php @@ -472,4 +472,6 @@ class CI_Calendar { } // END CI_Calendar class -?> \ No newline at end of file + +/* End of file Calendar.php */ +/* Location: ./system/libraries/Calendar.php */ \ No newline at end of file diff --git a/system/libraries/Config.php b/system/libraries/Config.php index 73f1986a0..f3ae76390 100644 --- a/system/libraries/Config.php +++ b/system/libraries/Config.php @@ -242,4 +242,6 @@ class CI_Config { } // END CI_Config class -?> \ No newline at end of file + +/* End of file Config.php */ +/* Location: ./system/libraries/Config.php */ \ No newline at end of file diff --git a/system/libraries/Controller.php b/system/libraries/Controller.php index 4957fc35e..1a1e3df53 100644 --- a/system/libraries/Controller.php +++ b/system/libraries/Controller.php @@ -121,4 +121,6 @@ class Controller extends CI_Base { } // END _Controller class -?> \ No newline at end of file + +/* End of file Controller.php */ +/* Location: ./system/libraries/Controller.php */ \ No newline at end of file diff --git a/system/libraries/Email.php b/system/libraries/Email.php index aa08971f9..d32928a66 100644 --- a/system/libraries/Email.php +++ b/system/libraries/Email.php @@ -1848,4 +1848,6 @@ class CI_Email { } // END CI_Email class -?> \ No newline at end of file + +/* End of file Email.php */ +/* Location: ./system/libraries/Email.php */ \ No newline at end of file diff --git a/system/libraries/Encrypt.php b/system/libraries/Encrypt.php index 9a784d254..4b13efda3 100644 --- a/system/libraries/Encrypt.php +++ b/system/libraries/Encrypt.php @@ -481,4 +481,6 @@ class CI_Encrypt { } // END CI_Encrypt class -?> \ No newline at end of file + +/* End of file Encrypt.php */ +/* Location: ./system/libraries/Encrypt.php */ \ No newline at end of file diff --git a/system/libraries/Exceptions.php b/system/libraries/Exceptions.php index 7c9640554..428759042 100644 --- a/system/libraries/Exceptions.php +++ b/system/libraries/Exceptions.php @@ -167,4 +167,6 @@ class CI_Exceptions { } // END Exceptions Class -?> \ No newline at end of file + +/* End of file Exceptions.php */ +/* Location: ./system/libraries/Exceptions.php */ \ No newline at end of file diff --git a/system/libraries/Ftp.php b/system/libraries/Ftp.php index 74b7728fa..01354cf05 100644 --- a/system/libraries/Ftp.php +++ b/system/libraries/Ftp.php @@ -613,4 +613,6 @@ class CI_FTP { } // END FTP Class -?> \ No newline at end of file + +/* End of file Ftp.php */ +/* Location: ./system/libraries/Ftp.php */ \ No newline at end of file diff --git a/system/libraries/Hooks.php b/system/libraries/Hooks.php index a41320c5e..d7637c39e 100644 --- a/system/libraries/Hooks.php +++ b/system/libraries/Hooks.php @@ -221,4 +221,6 @@ class CI_Hooks { } // END CI_Hooks class -?> \ No newline at end of file + +/* End of file Hooks.php */ +/* Location: ./system/libraries/Hooks.php */ \ No newline at end of file diff --git a/system/libraries/Image_lib.php b/system/libraries/Image_lib.php index c236e391e..0750b6454 100644 --- a/system/libraries/Image_lib.php +++ b/system/libraries/Image_lib.php @@ -1533,4 +1533,6 @@ class CI_Image_lib { } // END Image_lib Class -?> \ No newline at end of file + +/* End of file Image_lib.php */ +/* Location: ./system/libraries/Image_lib.php */ \ No newline at end of file diff --git a/system/libraries/Input.php b/system/libraries/Input.php index 8a0478be2..ee7e9ad31 100644 --- a/system/libraries/Input.php +++ b/system/libraries/Input.php @@ -923,4 +923,6 @@ class CI_Input { } // END Input class -?> \ No newline at end of file + +/* End of file Input.php */ +/* Location: ./system/libraries/Input.php */ \ No newline at end of file diff --git a/system/libraries/Language.php b/system/libraries/Language.php index a8e6366bb..aacc6c1f9 100644 --- a/system/libraries/Language.php +++ b/system/libraries/Language.php @@ -118,4 +118,6 @@ class CI_Language { } // END Language Class -?> \ No newline at end of file + +/* End of file Language.php */ +/* Location: ./system/libraries/Language.php */ \ No newline at end of file diff --git a/system/libraries/Loader.php b/system/libraries/Loader.php index 5966aebf6..687598096 100644 --- a/system/libraries/Loader.php +++ b/system/libraries/Loader.php @@ -1027,4 +1027,6 @@ class CI_Loader { } } -?> \ No newline at end of file + +/* End of file Loader.php */ +/* Location: ./system/libraries/Loader.php */ \ No newline at end of file diff --git a/system/libraries/Log.php b/system/libraries/Log.php index 26757ba50..22b505906 100644 --- a/system/libraries/Log.php +++ b/system/libraries/Log.php @@ -115,4 +115,6 @@ class CI_Log { } // END Log Class -?> \ No newline at end of file + +/* End of file Log.php */ +/* Location: ./system/libraries/Log.php */ \ No newline at end of file diff --git a/system/libraries/Model.php b/system/libraries/Model.php index e87d6045c..1e7b9a184 100644 --- a/system/libraries/Model.php +++ b/system/libraries/Model.php @@ -79,4 +79,6 @@ class Model { } // END Model Class -?> \ No newline at end of file + +/* End of file Model.php */ +/* Location: ./system/libraries/Model.php */ \ No newline at end of file diff --git a/system/libraries/Output.php b/system/libraries/Output.php index d513a1279..f76550e2b 100644 --- a/system/libraries/Output.php +++ b/system/libraries/Output.php @@ -383,4 +383,6 @@ class CI_Output { } // END Output Class -?> \ No newline at end of file + +/* End of file Output.php */ +/* Location: ./system/libraries/Output.php */ \ No newline at end of file diff --git a/system/libraries/Pagination.php b/system/libraries/Pagination.php index e1212035a..c3f6bd89c 100644 --- a/system/libraries/Pagination.php +++ b/system/libraries/Pagination.php @@ -215,4 +215,6 @@ class CI_Pagination { } } // END Pagination Class -?> \ No newline at end of file + +/* 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 index 417e04f29..f260b2e19 100644 --- a/system/libraries/Parser.php +++ b/system/libraries/Parser.php @@ -168,4 +168,6 @@ class CI_Parser { } // END Parser Class -?> \ No newline at end of file + +/* End of file Parser.php */ +/* Location: ./system/libraries/Parser.php */ \ No newline at end of file diff --git a/system/libraries/Profiler.php b/system/libraries/Profiler.php index 807c1aff6..fe4fb6d62 100644 --- a/system/libraries/Profiler.php +++ b/system/libraries/Profiler.php @@ -340,4 +340,6 @@ class CI_Profiler { } // END CI_Profiler class -?> \ No newline at end of file + +/* End of file Profiler.php */ +/* Location: ./system/libraries/Profiler.php */ \ No newline at end of file diff --git a/system/libraries/Router.php b/system/libraries/Router.php index 6bb85518f..3b2520dce 100644 --- a/system/libraries/Router.php +++ b/system/libraries/Router.php @@ -374,4 +374,6 @@ class CI_Router { } // END Router Class -?> \ No newline at end of file + +/* End of file Router.php */ +/* Location: ./system/libraries/Router.php */ \ No newline at end of file diff --git a/system/libraries/Session.php b/system/libraries/Session.php index d4fdd3ac7..ce1b75e66 100644 --- a/system/libraries/Session.php +++ b/system/libraries/Session.php @@ -649,4 +649,6 @@ class CI_Session { } // END Session Class -?> \ No newline at end of file + +/* End of file Session.php */ +/* Location: ./system/libraries/Session.php */ \ No newline at end of file diff --git a/system/libraries/Sha1.php b/system/libraries/Sha1.php index 6bb891177..a7b9b98d3 100644 --- a/system/libraries/Sha1.php +++ b/system/libraries/Sha1.php @@ -246,4 +246,6 @@ class CI_SHA { } } // END CI_SHA -?> \ No newline at end of file + +/* 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 index 01b490a5d..f4df02e76 100644 --- a/system/libraries/Table.php +++ b/system/libraries/Table.php @@ -435,4 +435,6 @@ class CI_Table { } -?> \ No newline at end of file + +/* 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 index 3e1c20210..41ac5fca8 100644 --- a/system/libraries/Trackback.php +++ b/system/libraries/Trackback.php @@ -545,4 +545,6 @@ class CI_Trackback { } // END Trackback Class -?> \ No newline at end of file + +/* End of file Trackback.php */ +/* Location: ./system/libraries/Trackback.php */ \ No newline at end of file diff --git a/system/libraries/URI.php b/system/libraries/URI.php index 8ee888a2e..26a7b4a33 100644 --- a/system/libraries/URI.php +++ b/system/libraries/URI.php @@ -586,4 +586,6 @@ class CI_URI { } // END URI Class -?> \ No newline at end of file + +/* End of file URI.php */ +/* Location: ./system/libraries/URI.php */ \ No newline at end of file diff --git a/system/libraries/Unit_test.php b/system/libraries/Unit_test.php index 3cdf45f12..2fb2bbd32 100644 --- a/system/libraries/Unit_test.php +++ b/system/libraries/Unit_test.php @@ -340,4 +340,6 @@ function is_false($test) return (is_bool($test) AND $test === FALSE) ? TRUE : FALSE; } -?> \ No newline at end of file + +/* End of file Unit_test.php */ +/* Location: ./system/libraries/Unit_test.php */ \ No newline at end of file diff --git a/system/libraries/Upload.php b/system/libraries/Upload.php index 317cf9560..07cbd924b 100644 --- a/system/libraries/Upload.php +++ b/system/libraries/Upload.php @@ -875,4 +875,6 @@ class CI_Upload { } // END Upload Class -?> \ No newline at end of file + +/* End of file Upload.php */ +/* Location: ./system/libraries/Upload.php */ \ No newline at end of file diff --git a/system/libraries/User_agent.php b/system/libraries/User_agent.php index dd60a56a1..ee1839277 100644 --- a/system/libraries/User_agent.php +++ b/system/libraries/User_agent.php @@ -497,4 +497,6 @@ class CI_User_agent { } -?> \ No newline at end of file + +/* End of file User_agent.php */ +/* Location: ./system/libraries/User_agent.php */ \ No newline at end of file diff --git a/system/libraries/Validation.php b/system/libraries/Validation.php index f628d8612..8796d7ffb 100644 --- a/system/libraries/Validation.php +++ b/system/libraries/Validation.php @@ -805,4 +805,6 @@ class CI_Validation { } // END Validation Class -?> \ No newline at end of file + +/* End of file Validation.php */ +/* Location: ./system/libraries/Validation.php */ \ No newline at end of file diff --git a/system/libraries/Xmlrpc.php b/system/libraries/Xmlrpc.php index f8ad01714..b8ac3bea7 100644 --- a/system/libraries/Xmlrpc.php +++ b/system/libraries/Xmlrpc.php @@ -1416,4 +1416,6 @@ class XML_RPC_Values extends CI_Xmlrpc } // END XML_RPC_Values Class -?> \ No newline at end of file + +/* End of file Xmlrpc.php */ +/* Location: ./system/libraries/Xmlrpc.php */ \ No newline at end of file diff --git a/system/libraries/Xmlrpcs.php b/system/libraries/Xmlrpcs.php index 7a4bc825e..754b8ae26 100644 --- a/system/libraries/Xmlrpcs.php +++ b/system/libraries/Xmlrpcs.php @@ -531,4 +531,6 @@ class CI_Xmlrpcs extends CI_Xmlrpc } // END XML_RPC_Server class -?> \ No newline at end of file + +/* 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 index f7f47ab42..5a24e4057 100644 --- a/system/libraries/Zip.php +++ b/system/libraries/Zip.php @@ -374,4 +374,6 @@ class CI_Zip { } } -?> \ No newline at end of file + +/* End of file Zip.php */ +/* Location: ./system/libraries/Zip.php */ \ No newline at end of file diff --git a/system/plugins/captcha_pi.php b/system/plugins/captcha_pi.php index 309ef7ea5..ec45309e5 100644 --- a/system/plugins/captcha_pi.php +++ b/system/plugins/captcha_pi.php @@ -351,4 +351,6 @@ function create_captcha($data = '', $img_path = '', $img_url = '', $font_path = return array('word' => $word, 'time' => $now, 'image' => $img); } -?> \ No newline at end of file + +/* End of file captcha_pi.php */ +/* Location: ./system/plugins/captcha_pi.php */ \ No newline at end of file diff --git a/system/plugins/js_calendar_pi.php b/system/plugins/js_calendar_pi.php index 86270cacf..6bb3b3629 100644 --- a/system/plugins/js_calendar_pi.php +++ b/system/plugins/js_calendar_pi.php @@ -624,4 +624,6 @@ function js_calendar_write($field_id, $time = '', $highlight = TRUE) '; } -?> \ No newline at end of file + +/* End of file js_calendar_pi.php */ +/* Location: ./system/plugins/js_calendar_pi.php */ \ No newline at end of file diff --git a/system/scaffolding/Scaffolding.php b/system/scaffolding/Scaffolding.php index 64f62a3d6..807a3d76a 100644 --- a/system/scaffolding/Scaffolding.php +++ b/system/scaffolding/Scaffolding.php @@ -286,4 +286,6 @@ class Scaffolding { } } -?> \ No newline at end of file + +/* End of file Scaffolding.php */ +/* Location: ./system/scaffolding/Scaffolding.php */ \ No newline at end of file diff --git a/system/scaffolding/views/add.php b/system/scaffolding/views/add.php index a65e3d745..cbb12f6fb 100644 --- a/system/scaffolding/views/add.php +++ b/system/scaffolding/views/add.php @@ -27,4 +27,6 @@ -load->view('footer'); ?> +load->view('footer'); +/* End of file add.php */ +/* Location: ./system/scaffolding/views/add.php */ diff --git a/system/scaffolding/views/delete.php b/system/scaffolding/views/delete.php index 75a5c21b8..d19542195 100644 --- a/system/scaffolding/views/delete.php +++ b/system/scaffolding/views/delete.php @@ -4,4 +4,6 @@

      |   -load->view('footer'); ?> +load->view('footer'); +/* End of file delete.php */ +/* Location: ./system/scaffolding/views/delete.php */ diff --git a/system/scaffolding/views/edit.php b/system/scaffolding/views/edit.php index a7d65c619..fe553e591 100644 --- a/system/scaffolding/views/edit.php +++ b/system/scaffolding/views/edit.php @@ -28,4 +28,6 @@ -load->view('footer'); ?> \ No newline at end of file +load->view('footer'); +/* End of file edit.php */ +/* Location: ./system/scaffolding/views/edit.php */ \ No newline at end of file diff --git a/system/scaffolding/views/no_data.php b/system/scaffolding/views/no_data.php index dca477e2d..bc81e7480 100644 --- a/system/scaffolding/views/no_data.php +++ b/system/scaffolding/views/no_data.php @@ -3,4 +3,6 @@

    -load->view('footer'); ?> \ No newline at end of file +load->view('footer'); +/* End of file no_data.php */ +/* Location: ./system/scaffolding/views/no_data.php */ \ No newline at end of file diff --git a/system/scaffolding/views/view.php b/system/scaffolding/views/view.php index e7abda6d9..a81241d39 100644 --- a/system/scaffolding/views/view.php +++ b/system/scaffolding/views/view.php @@ -22,4 +22,6 @@ -load->view('footer'); ?> \ No newline at end of file +load->view('footer'); +/* End of file view.php */ +/* Location: ./system/scaffolding/views/view.php */ \ No newline at end of file -- cgit v1.2.3-24-g4f1b From 7f88aa51fb56cb6e0d50f55f07fd8638d7a625b2 Mon Sep 17 00:00:00 2001 From: Derek Jones Date: Mon, 12 May 2008 00:03:51 +0000 Subject: changed class instantiations to reference global $LANG and fetch existing Exceptions class, and added language variable for database error heading http://codeigniter.com/bug_tracker/bug/4421/ --- system/database/DB_driver.php | 21 +++++++-------------- system/language/english/db_lang.php | 4 ++-- 2 files changed, 9 insertions(+), 16 deletions(-) (limited to 'system') diff --git a/system/database/DB_driver.php b/system/database/DB_driver.php index c296d4ca8..35bdc29b6 100644 --- a/system/database/DB_driver.php +++ b/system/database/DB_driver.php @@ -1117,12 +1117,11 @@ class CI_DB_driver { */ function display_error($error = '', $swap = '', $native = FALSE) { -// $LANG = new CI_Lang(); - $LANG = new CI_Language(); + global $LANG; $LANG->load('db'); - $heading = 'Database Error'; - + $heading = $LANG->line('db_error_heading'); + if ($native == TRUE) { $message = $error; @@ -1131,20 +1130,14 @@ class CI_DB_driver { { $message = (! is_array($error)) ? array(str_replace('%s', $swap, $LANG->line($error))) : $error; } - - if (! class_exists('CI_Exceptions')) - { -// include(BASEPATH.'core/Exceptions'.EXT); - include(BASEPATH.'libraries/Exceptions'.EXT); - } - $error = new CI_Exceptions(); - echo $error->show_error('An Error Was Encountered', $message, 'error_db'); + $error =& load_class('Exceptions'); + echo $error->show_error($heading, $message, 'error_db'); exit; } } - -/* End of file DB_driver.php */ + +/* End of file DB_driver.php */ /* Location: ./system/database/DB_driver.php */ \ No newline at end of file diff --git a/system/language/english/db_lang.php b/system/language/english/db_lang.php index 6c053a139..697eb7880 100644 --- a/system/language/english/db_lang.php +++ b/system/language/english/db_lang.php @@ -21,7 +21,7 @@ $lang['db_table_name_required'] = 'A table name is required for that operation.' $lang['db_column_name_required'] = 'A column name is required for that operation.'; $lang['db_column_definition_required'] = 'A column definition is required for that operation.'; $lang['db_unable_to_set_charset'] = 'Unable to set client connection character set: %s'; +$lang['db_error_heading'] = 'A Database Error Occurred'; - -/* End of file db_lang.php */ +/* End of file db_lang.php */ /* Location: ./system/language/english/db_lang.php */ \ No newline at end of file -- cgit v1.2.3-24-g4f1b From 500fa6c3a934ac9d9f0a5c1ded5c00ad1709187f Mon Sep 17 00:00:00 2001 From: Derek Jones Date: Mon, 12 May 2008 15:08:35 +0000 Subject: changed overlay_watermark() to check for an alpha value before applying the image to help support PNG-24s with alpha transparency http://codeigniter.com/bug_tracker/bug/4506/ --- system/libraries/Image_lib.php | 25 +++++++++++++++++++------ 1 file changed, 19 insertions(+), 6 deletions(-) (limited to 'system') diff --git a/system/libraries/Image_lib.php b/system/libraries/Image_lib.php index 0750b6454..4017afb13 100644 --- a/system/libraries/Image_lib.php +++ b/system/libraries/Image_lib.php @@ -943,10 +943,23 @@ class CI_Image_lib { { @imagealphablending($src_img, TRUE); } - - // Set RGB values for text and shadow - imagecolortransparent($wm_img, imagecolorat($wm_img, $this->wm_x_transp, $this->wm_y_transp)); - imagecopymerge($src_img, $wm_img, $x_axis, $y_axis, 0, 0, $wm_width, $wm_height, $this->wm_opacity); + + // Set RGB values for text and shadow + $rgba = imagecolorat($wm_img, $this->wm_x_transp, $this->wm_y_transp); + $alpha = ($rgba & 0x7F000000) >> 24; + + // make a best guess as to whether we're dealing with an image with alpha transparency or no/binary transparency + if ($alpha > 0) + { + // copy the image directly, the image's alpha transparency being the sole determinant of blending + imagecopy($src_img, $wm_img, $x_axis, $y_axis, 0, 0, $wm_width, $wm_height); + } + else + { + // set our RGB value from above to be transparent and merge the images with the specified opacity + imagecolortransparent($wm_img, imagecolorat($wm_img, $this->wm_x_transp, $this->wm_y_transp)); + imagecopymerge($src_img, $wm_img, $x_axis, $y_axis, 0, 0, $wm_width, $wm_height, $this->wm_opacity); + } // Output the image if ($this->dynamic_output == TRUE) @@ -1533,6 +1546,6 @@ class CI_Image_lib { } // END Image_lib Class - -/* End of file Image_lib.php */ + +/* End of file Image_lib.php */ /* Location: ./system/libraries/Image_lib.php */ \ No newline at end of file -- cgit v1.2.3-24-g4f1b From d36ade01b57ac39c328d9e0278b28b04fbef895e Mon Sep 17 00:00:00 2001 From: Derek Jones Date: Mon, 12 May 2008 15:17:41 +0000 Subject: passed db object by reference to DB Cache class, and changed the cache class to use that db object instead of $CI->db, to support returned db objects and multiple db connections http://codeigniter.com/bug_tracker/bug/4223/ --- system/database/DB_cache.php | 30 ++++++++++++++++-------------- system/database/DB_driver.php | 2 +- 2 files changed, 17 insertions(+), 15 deletions(-) (limited to 'system') diff --git a/system/database/DB_cache.php b/system/database/DB_cache.php index 21113aff3..448727fd0 100644 --- a/system/database/DB_cache.php +++ b/system/database/DB_cache.php @@ -25,6 +25,7 @@ class CI_DB_Cache { var $CI; + var $db; // allows passing of db object so that multiple database connections and returned db objects can be supported /** * Constructor @@ -32,11 +33,12 @@ class CI_DB_Cache { * Grabs the CI super object instance so we can access it. * */ - function CI_DB_Cache() + function CI_DB_Cache(&$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'); } @@ -53,12 +55,12 @@ class CI_DB_Cache { { if ($path == '') { - if ($this->CI->db->cachedir == '') + if ($this->db->cachedir == '') { - return $this->CI->db->cache_off(); + return $this->db->cache_off(); } - $path = $this->CI->db->cachedir; + $path = $this->db->cachedir; } // Add a trailing slash to the path if needed @@ -67,10 +69,10 @@ class CI_DB_Cache { if (! is_dir($path) OR ! is_really_writable($path)) { // If the path is wrong we'll turn off caching - return $this->CI->db->cache_off(); + return $this->db->cache_off(); } - $this->CI->db->cachedir = $path; + $this->db->cachedir = $path; return TRUE; } @@ -89,7 +91,7 @@ class CI_DB_Cache { { if (! $this->check_path()) { - return $this->CI->db->cache_off(); + return $this->db->cache_off(); } $uri = ($this->CI->uri->segment(1) == FALSE) ? 'default.' : $this->CI->uri->segment(1).'+'; @@ -97,7 +99,7 @@ class CI_DB_Cache { $filepath = $uri.'/'.md5($sql); - if (FALSE === ($cachedata = read_file($this->CI->db->cachedir.$filepath))) + if (FALSE === ($cachedata = read_file($this->db->cachedir.$filepath))) { return FALSE; } @@ -117,13 +119,13 @@ class CI_DB_Cache { { if (! $this->check_path()) { - return $this->CI->db->cache_off(); + return $this->db->cache_off(); } $uri = ($this->CI->uri->segment(1) == FALSE) ? 'default.' : $this->CI->uri->segment(1).'+'; $uri .= ($this->CI->uri->segment(2) == FALSE) ? 'index' : $this->CI->uri->segment(2); - $dir_path = $this->CI->db->cachedir.$uri.'/'; + $dir_path = $this->db->cachedir.$uri.'/'; $filename = md5($sql); @@ -166,7 +168,7 @@ class CI_DB_Cache { $segment_two = ($this->CI->uri->segment(2) == FALSE) ? 'index' : $this->CI->uri->segment(2); } - $dir_path = $this->CI->db->cachedir.$segment_one.'+'.$segment_two.'/'; + $dir_path = $this->db->cachedir.$segment_one.'+'.$segment_two.'/'; delete_files($dir_path, TRUE); } @@ -181,11 +183,11 @@ class CI_DB_Cache { */ function delete_all() { - delete_files($this->CI->db->cachedir, TRUE); + delete_files($this->db->cachedir, TRUE); } } - -/* End of file DB_cache.php */ + +/* 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 index 35bdc29b6..b055d6dc3 100644 --- a/system/database/DB_driver.php +++ b/system/database/DB_driver.php @@ -1083,7 +1083,7 @@ class CI_DB_driver { return $this->cache_off(); } - $this->CACHE = new CI_DB_Cache; + $this->CACHE = new CI_DB_Cache($this); // pass db object to support multiple db connections and returned db objects return TRUE; } -- cgit v1.2.3-24-g4f1b From d56743b0d65603ebd556a05f740d5bd5da05101b Mon Sep 17 00:00:00 2001 From: Derek Jones Date: Mon, 12 May 2008 16:17:58 +0000 Subject: fixed a bug that would lead to a PHP notice error of array to string conversion in prep_for_form() http://codeigniter.com/bug_tracker/bug/4425/ --- system/libraries/Validation.php | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'system') diff --git a/system/libraries/Validation.php b/system/libraries/Validation.php index 8796d7ffb..a0f038c02 100644 --- a/system/libraries/Validation.php +++ b/system/libraries/Validation.php @@ -726,6 +726,8 @@ class CI_Validation { { $data[$key] = $this->prep_for_form($val); } + + return $data; } if ($this->_safe_form_data == FALSE OR $data == '') @@ -805,6 +807,6 @@ class CI_Validation { } // END Validation Class - -/* End of file Validation.php */ + +/* End of file Validation.php */ /* Location: ./system/libraries/Validation.php */ \ No newline at end of file -- cgit v1.2.3-24-g4f1b From c14968d0a2d6f25cdaf333b8f697991177387bed Mon Sep 17 00:00:00 2001 From: Derek Jones Date: Mon, 12 May 2008 17:19:51 +0000 Subject: changed $xmlrpcDateTime property to all lowercase 'datetime.iso8601' so it can be recognized as a valid XML-RPC type http://codeigniter.com/bug_tracker/bug/4153/ --- system/libraries/Xmlrpc.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'system') diff --git a/system/libraries/Xmlrpc.php b/system/libraries/Xmlrpc.php index b8ac3bea7..32d739689 100644 --- a/system/libraries/Xmlrpc.php +++ b/system/libraries/Xmlrpc.php @@ -38,7 +38,7 @@ class CI_Xmlrpc { var $xmlrpcBoolean = 'boolean'; var $xmlrpcDouble = 'double'; var $xmlrpcString = 'string'; - var $xmlrpcDateTime = 'dateTime.iso8601'; + var $xmlrpcDateTime = 'datetime.iso8601'; var $xmlrpcBase64 = 'base64'; var $xmlrpcArray = 'array'; var $xmlrpcStruct = 'struct'; @@ -1416,6 +1416,6 @@ class XML_RPC_Values extends CI_Xmlrpc } // END XML_RPC_Values Class - -/* End of file Xmlrpc.php */ + +/* End of file Xmlrpc.php */ /* Location: ./system/libraries/Xmlrpc.php */ \ No newline at end of file -- cgit v1.2.3-24-g4f1b From a632589001aa9ec769f9a80871097ce3a09b74d1 Mon Sep 17 00:00:00 2001 From: Derek Allard Date: Mon, 12 May 2008 17:51:47 +0000 Subject: Fixed a bug in AR compiling, where select statements with arguments got incorrectly escaped (#3478). --- system/database/DB_active_rec.php | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) (limited to 'system') diff --git a/system/database/DB_active_rec.php b/system/database/DB_active_rec.php index a4ef2e4db..9a7ef5def 100644 --- a/system/database/DB_active_rec.php +++ b/system/database/DB_active_rec.php @@ -95,7 +95,14 @@ class CI_DB_active_record extends CI_DB_driver { { if (is_string($select)) { - $select = explode(',', $select); + if ($protect_identifiers !== FALSE) + { + $select = explode(',', $select); + } + else + { + $select = array($select); + } } foreach ($select as $val) @@ -1749,6 +1756,6 @@ class CI_DB_active_record extends CI_DB_driver { } } - -/* End of file DB_active_rec.php */ + +/* End of file DB_active_rec.php */ /* Location: ./system/database/DB_active_rec.php */ \ No newline at end of file -- cgit v1.2.3-24-g4f1b From 53437de1f94dd4c0ab270f0c6d2309344d323d9e Mon Sep 17 00:00:00 2001 From: Derek Jones Date: Mon, 12 May 2008 18:07:08 +0000 Subject: Added protection in xss_clean() for GET variables in URLs http://codeigniter.com/bug_tracker/bug/4167/ --- system/libraries/Input.php | 58 +++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 55 insertions(+), 3 deletions(-) (limited to 'system') diff --git a/system/libraries/Input.php b/system/libraries/Input.php index ee7e9ad31..9b012d320 100644 --- a/system/libraries/Input.php +++ b/system/libraries/Input.php @@ -28,6 +28,7 @@ */ class CI_Input { var $use_xss_clean = FALSE; + var $xss_hash = ''; var $ip_address = FALSE; var $user_agent = FALSE; var $allow_get_array = FALSE; @@ -530,7 +531,21 @@ class CI_Input { * @return string */ function xss_clean($str) - { + { + /* + * Is the string an array? + * + */ + if (is_array($str)) + { + while (list($key) = each($str)) + { + $str[$key] = $this->xss_clean($str[$key]); + } + + return $str; + } + /* * Remove Null Characters * @@ -541,6 +556,14 @@ class CI_Input { $str = preg_replace('/\0+/', '', $str); $str = preg_replace('/(\\\\0)+/', '', $str); + /* + * Protect GET variables in URLs + */ + + // 901119URL5918AMP18930PROTECT8198 + + $str = preg_replace('|\&([a-z\_0-9]+)\=([a-z\_0-9]+)|i', $this->xss_hash()."\\1=\\2", $str); + /* * Validate standard character entities * @@ -558,6 +581,12 @@ class CI_Input { */ $str = preg_replace('#(&\#x?)([0-9A-F]+);?#i',"\\1\\2;",$str); + /* + * Un-Protect GET variables in URLs + */ + + $str = str_replace($this->xss_hash(), '&', $str); + /* * URL Decode * @@ -796,6 +825,29 @@ class CI_Input { // -------------------------------------------------------------------- + /** + * Random Hash for protecting URLs + * + * @access public + * @return string + */ + function xss_hash() + { + if ($this->xss_hash == '') + { + if (phpversion() >= 4.2) + mt_srand(); + else + mt_srand(hexdec(substr(md5(microtime()), -8)) & 0x7fffffff); + + $this->xss_hash = md5(time() + mt_rand(0, 1999999999)); + } + + return $this->xss_hash; + } + + // -------------------------------------------------------------------- + /** * JS Link Removal * @@ -923,6 +975,6 @@ class CI_Input { } // END Input class - -/* End of file Input.php */ + +/* End of file Input.php */ /* Location: ./system/libraries/Input.php */ \ No newline at end of file -- cgit v1.2.3-24-g4f1b From 244b4c7bcf88b2ed10cb48ca961d615e5a5002ed Mon Sep 17 00:00:00 2001 From: Rick Ellis Date: Mon, 12 May 2008 18:21:33 +0000 Subject: --- system/database/DB_driver.php | 79 +++++++++++++++++++++++++++++++------------ 1 file changed, 57 insertions(+), 22 deletions(-) (limited to 'system') diff --git a/system/database/DB_driver.php b/system/database/DB_driver.php index b055d6dc3..9ad235ded 100644 --- a/system/database/DB_driver.php +++ b/system/database/DB_driver.php @@ -51,6 +51,7 @@ class CI_DB_driver { var $query_times = array(); var $data_cache = array(); var $trans_enabled = TRUE; + var $trans_strict = TRUE; var $_trans_depth = 0; var $_trans_status = TRUE; // Used with transactions to determine if a rollback should occur var $cache_on = FALSE; @@ -107,7 +108,7 @@ class CI_DB_driver { $this->conn_id = ($this->pconnect == FALSE) ? $this->db_connect() : $this->db_pconnect(); // No connection? Throw an error - if (! $this->conn_id) + if ( ! $this->conn_id) { log_message('error', 'Unable to connect to the database'); @@ -121,7 +122,7 @@ class CI_DB_driver { // Select the database if ($this->database != '') { - if (! $this->db_select()) + if ( ! $this->db_select()) { // Should we attempt to create the database? if ($create_db == TRUE) @@ -131,7 +132,7 @@ class CI_DB_driver { $CI->load->dbutil(); // Create the DB - if (! $CI->dbutil->create_database($this->database)) + if ( ! $CI->dbutil->create_database($this->database)) { log_message('error', 'Unable to create database: '.$this->database); @@ -297,11 +298,23 @@ class CI_DB_driver { // 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) { + // 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: '.$this->_error_message()); return $this->display_error( array( @@ -401,7 +414,7 @@ class CI_DB_driver { { $driver = 'CI_DB_'.$this->dbdriver.'_result'; - if (! class_exists($driver)) + if ( ! class_exists($driver)) { include_once(BASEPATH.'database/DB_result'.EXT); include_once(BASEPATH.'database/drivers/'.$this->dbdriver.'/'.$this->dbdriver.'_result'.EXT); @@ -424,7 +437,7 @@ class CI_DB_driver { */ function simple_query($sql) { - if (! $this->conn_id) + if ( ! $this->conn_id) { $this->initialize(); } @@ -448,6 +461,23 @@ class CI_DB_driver { // -------------------------------------------------------------------- + /** + * 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 * @@ -456,7 +486,7 @@ class CI_DB_driver { */ function trans_start($test_mode = FALSE) { - if (! $this->trans_enabled) + if ( ! $this->trans_enabled) { return FALSE; } @@ -481,7 +511,7 @@ class CI_DB_driver { */ function trans_complete() { - if (! $this->trans_enabled) + if ( ! $this->trans_enabled) { return FALSE; } @@ -493,15 +523,20 @@ class CI_DB_driver { return TRUE; } - // The query() function will set this flag to TRUE in the event that a query failed + // 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 ($this->db_debug) + // 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) { - return $this->display_error('db_transaction_failure'); + $this->_trans_status = TRUE; } + + log_message('debug', 'DB Transaction Failure'); return FALSE; } @@ -539,7 +574,7 @@ class CI_DB_driver { return $sql; } - if (! is_array($binds)) + if ( ! is_array($binds)) { $binds = array($binds); } @@ -576,7 +611,7 @@ class CI_DB_driver { */ function is_write_type($sql) { - if (! preg_match('/^\s*"?(SET|INSERT|UPDATE|DELETE|REPLACE|CREATE|DROP|LOAD DATA|COPY|ALTER|GRANT|REVOKE|LOCK|UNLOCK)\s+/i', $sql)) + if ( ! preg_match('/^\s*"?(SET|INSERT|UPDATE|DELETE|REPLACE|CREATE|DROP|LOAD DATA|COPY|ALTER|GRANT|REVOKE|LOCK|UNLOCK)\s+/i', $sql)) { return FALSE; } @@ -683,7 +718,7 @@ class CI_DB_driver { { $fields = $this->list_fields($table); - if (! is_array($fields)) + if ( ! is_array($fields)) { return FALSE; } @@ -747,7 +782,7 @@ class CI_DB_driver { */ function table_exists($table_name) { - return (! in_array($this->prep_tablename($table_name), $this->list_tables())) ? FALSE : TRUE; + return ( ! in_array($this->prep_tablename($table_name), $this->list_tables())) ? FALSE : TRUE; } // -------------------------------------------------------------------- @@ -815,7 +850,7 @@ class CI_DB_driver { */ function field_exists($field_name, $table_name) { - return (! in_array($field_name, $this->list_fields($table_name))) ? FALSE : TRUE; + return ( ! in_array($field_name, $this->list_fields($table_name))) ? FALSE : TRUE; } // -------------------------------------------------------------------- @@ -899,7 +934,7 @@ class CI_DB_driver { $fields[$key] = $this->escape($val); } - if (! is_array($where)) + if ( ! is_array($where)) { $dest = array($where); } @@ -912,7 +947,7 @@ class CI_DB_driver { if ($val !== '') { - if (! $this->_has_operator($key)) + if ( ! $this->_has_operator($key)) { $key .= ' ='; } @@ -969,7 +1004,7 @@ class CI_DB_driver { $function = $driver.$function; } - if (! function_exists($function)) + if ( ! function_exists($function)) { if ($this->db_debug) { @@ -1038,7 +1073,7 @@ class CI_DB_driver { */ function cache_delete($segment_one = '', $segment_two = '') { - if (! $this->_cache_init()) + if ( ! $this->_cache_init()) { return FALSE; } @@ -1055,7 +1090,7 @@ class CI_DB_driver { */ function cache_delete_all() { - if (! $this->_cache_init()) + if ( ! $this->_cache_init()) { return FALSE; } @@ -1078,7 +1113,7 @@ class CI_DB_driver { return TRUE; } - if (! @include(BASEPATH.'database/DB_cache'.EXT)) + if ( ! @include(BASEPATH.'database/DB_cache'.EXT)) { return $this->cache_off(); } -- cgit v1.2.3-24-g4f1b From 5fe155ecd05af4ee68ef093200fb6a241baa89ce Mon Sep 17 00:00:00 2001 From: Derek Allard Date: Mon, 12 May 2008 19:14:57 +0000 Subject: Escape behaviour in where() clauses has changed; values in those with the "FALSE" argument are no longer escaped (ie: quoted). --- system/database/DB_active_rec.php | 41 +++++++++++++++++++++------------------ 1 file changed, 22 insertions(+), 19 deletions(-) (limited to 'system') diff --git a/system/database/DB_active_rec.php b/system/database/DB_active_rec.php index 9a7ef5def..b53158577 100644 --- a/system/database/DB_active_rec.php +++ b/system/database/DB_active_rec.php @@ -69,14 +69,14 @@ class CI_DB_active_record extends CI_DB_driver { * @access public * @param string the table * @return string - */ + */ function dbprefix($table = '') { if ($table == '') { $this->display_error('db_table_name_required'); } - + return $this->dbprefix.$table; } @@ -104,7 +104,7 @@ class CI_DB_active_record extends CI_DB_driver { $select = array($select); } } - + foreach ($select as $val) { $val = trim($val); @@ -120,7 +120,7 @@ class CI_DB_active_record extends CI_DB_driver { $val = $this->_protect_identifiers($val); } } - + if ($val != '') { $this->ar_select[] = $val; @@ -183,7 +183,7 @@ class CI_DB_active_record extends CI_DB_driver { { $this->display_error('db_invalid_query'); } - + $alias = ($alias != '') ? $alias : $select; $sql = 'MIN('.$this->_protect_identifiers(trim($select)).') AS '.$this->_protect_identifiers(trim($alias)); @@ -217,7 +217,7 @@ class CI_DB_active_record extends CI_DB_driver { } $alias = ($alias != '') ? $alias : $select; - + $sql = 'AVG('.$this->_protect_identifiers(trim($select)).') AS '.$this->_protect_identifiers(trim($alias)); $this->ar_select[] = $sql; @@ -230,7 +230,7 @@ class CI_DB_active_record extends CI_DB_driver { } // -------------------------------------------------------------------- - + /** * Select Sum * @@ -302,7 +302,7 @@ class CI_DB_active_record extends CI_DB_driver { return $this; } - + // -------------------------------------------------------------------- /** @@ -339,10 +339,10 @@ class CI_DB_active_record extends CI_DB_driver { // First we remove any existing prefixes in the condition to avoid duplicates $cond = preg_replace('|('.$this->dbprefix.')([\w\.]+)([\W\s]+)|', "$2$3", $cond); - + // Next we add the prefixes to the condition $cond = preg_replace('|([\w\.]+)([\W\s]+)(.+)|', $this->dbprefix . "$1$2" . $this->dbprefix . "$3", $cond); - } + } $join = $type.'JOIN '.$this->_protect_identifiers($this->dbprefix.$table, TRUE).' ON '.$cond; @@ -354,7 +354,7 @@ class CI_DB_active_record extends CI_DB_driver { return $this; } - + // -------------------------------------------------------------------- /** @@ -453,15 +453,18 @@ class CI_DB_active_record extends CI_DB_driver { { $k .= ' ='; } - + if ($v !== '' AND $v !== NULL) { - $v = ' '.$this->escape($v); + if ($escape === TRUE) + { + $v = ' '.$this->escape($v); + } } } else { - + if ($escape === TRUE) { $k = $this->_protect_identifiers($k, TRUE); @@ -511,7 +514,7 @@ class CI_DB_active_record extends CI_DB_driver { * @return object */ function or_where_in($key = NULL, $values = NULL) - { + { return $this->_where_in($key, $values, FALSE, 'OR '); } @@ -529,7 +532,7 @@ class CI_DB_active_record extends CI_DB_driver { * @return object */ function where_not_in($key = NULL, $values = NULL) - { + { return $this->_where_in($key, $values, TRUE); } @@ -547,7 +550,7 @@ class CI_DB_active_record extends CI_DB_driver { * @return object */ function or_where_not_in($key = NULL, $values = NULL) - { + { return $this->_where_in($key, $values, TRUE, 'OR '); } @@ -566,7 +569,7 @@ class CI_DB_active_record extends CI_DB_driver { * @return object */ function _where_in($key = NULL, $values = NULL, $not = FALSE, $type = 'AND ') - { + { if ($key === NULL || !is_array($values)) { return; @@ -580,7 +583,7 @@ class CI_DB_active_record extends CI_DB_driver { } $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; -- cgit v1.2.3-24-g4f1b From 15dcf49a0ea6895cbf009dc15277858cfdd422ef Mon Sep 17 00:00:00 2001 From: Derek Allard Date: Mon, 12 May 2008 21:37:04 +0000 Subject: removed an ereg from config added a qualifier to a str_replace for \t in Input changed substr to strncmp in Codeigniter.php and directory_map function added braces in an if statement of unit test Removed "scripts" from the auto-load search path. Scripts were deprecated in Version 1.4.1 (September 21, 2006). If you still need to use them for legacy reasons, they must now be manually loaded in each Controller. --- system/codeigniter/CodeIgniter.php | 6 +- system/helpers/directory_helper.php | 6 +- system/libraries/Config.php | 11 +- system/libraries/Input.php | 222 ++++++++++++++++++------------------ system/libraries/Loader.php | 8 +- system/libraries/Unit_test.php | 8 +- 6 files changed, 131 insertions(+), 130 deletions(-) (limited to 'system') diff --git a/system/codeigniter/CodeIgniter.php b/system/codeigniter/CodeIgniter.php index 642ff7801..4eb31cbcd 100644 --- a/system/codeigniter/CodeIgniter.php +++ b/system/codeigniter/CodeIgniter.php @@ -172,7 +172,7 @@ $method = $RTR->fetch_method(); if (! class_exists($class) OR $method == 'controller' - OR substr($method, 0, 1) == '_' + OR strncmp($method, '_', 1) == 0 OR in_array($method, get_class_methods('Controller'), TRUE) ) { @@ -273,6 +273,6 @@ if (class_exists('CI_DB') AND isset($CI->db)) } - -/* End of file CodeIgniter.php */ + +/* End of file CodeIgniter.php */ /* Location: ./system/codeigniter/CodeIgniter.php */ \ No newline at end of file diff --git a/system/helpers/directory_helper.php b/system/helpers/directory_helper.php index 7af4d1e38..d00bdf0aa 100644 --- a/system/helpers/directory_helper.php +++ b/system/helpers/directory_helper.php @@ -50,7 +50,7 @@ if (! function_exists('directory_map')) while (FALSE !== ($file = readdir($fp))) { - if (substr($file, 0, 1) == '.') + if (strncmp($file, '.', 1) == 0) { continue; } @@ -75,6 +75,6 @@ if (! function_exists('directory_map')) } } - -/* End of file directory_helper.php */ + +/* End of file directory_helper.php */ /* Location: ./system/helpers/directory_helper.php */ \ No newline at end of file diff --git a/system/libraries/Config.php b/system/libraries/Config.php index f3ae76390..b1a9defe0 100644 --- a/system/libraries/Config.php +++ b/system/libraries/Config.php @@ -172,12 +172,9 @@ class CI_Config { $pref = $this->config[$item]; - if ($pref != '') + if ($pref != '' && substr($pref, -1) != '/') { - if (ereg("/$", $pref) === FALSE) - { - $pref .= '/'; - } + $pref .= '/'; } return $pref; @@ -242,6 +239,6 @@ class CI_Config { } // END CI_Config class - -/* End of file Config.php */ + +/* End of file Config.php */ /* Location: ./system/libraries/Config.php */ \ No newline at end of file diff --git a/system/libraries/Input.php b/system/libraries/Input.php index 9b012d320..e3515661d 100644 --- a/system/libraries/Input.php +++ b/system/libraries/Input.php @@ -32,7 +32,7 @@ class CI_Input { var $ip_address = FALSE; var $user_agent = FALSE; var $allow_get_array = FALSE; - + /** * Constructor * @@ -40,19 +40,19 @@ class CI_Input { * and whether to allow the $_GET array * * @access public - */ + */ function CI_Input() - { + { log_message('debug', "Input Class Initialized"); - + $CFG =& load_class('Config'); $this->use_xss_clean = ($CFG->item('global_xss_filtering') === TRUE) ? TRUE : FALSE; - $this->allow_get_array = ($CFG->item('enable_query_strings') === TRUE) ? TRUE : FALSE; + $this->allow_get_array = ($CFG->item('enable_query_strings') === TRUE) ? TRUE : FALSE; $this->_sanitize_globals(); } - + // -------------------------------------------------------------------- - + /** * Sanitize Globals * @@ -72,7 +72,7 @@ class CI_Input { // Would kind of 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 security. // This is effectively the same as register_globals = off foreach (array($_GET, $_POST, $_COOKIE, $_SERVER, $_FILES, $_ENV, (isset($_SESSION) && is_array($_SESSION)) ? $_SESSION : array()) as $global) @@ -92,7 +92,7 @@ class CI_Input { { unset($GLOBALS[$key]); } - + if (is_array($val)) { foreach($val as $k => $v) @@ -103,7 +103,7 @@ class CI_Input { } } } - } + } } } @@ -122,30 +122,30 @@ class CI_Input { } } } - + // 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) { foreach($_COOKIE as $key => $val) - { + { $_COOKIE[$this->_clean_input_keys($key)] = $this->_clean_input_data($val); - } + } } - + log_message('debug', "Global POST and COOKIE data sanitized"); - } - + } + // -------------------------------------------------------------------- - + /** * Clean Input Data * @@ -155,7 +155,7 @@ class CI_Input { * @access private * @param string * @return string - */ + */ function _clean_input_data($str) { if (is_array($str)) @@ -167,25 +167,25 @@ class CI_Input { } return $new_array; } - + // We strip slashes if magic quotes is on to keep things consistent if (get_magic_quotes_gpc()) { $str = stripslashes($str); } - + // Should we filter the input data? if ($this->use_xss_clean === TRUE) { $str = $this->xss_clean($str); } - + // Standardize newlines return preg_replace("/\015\012|\015|\012/", "\n", $str); } - + // -------------------------------------------------------------------- - + /** * Clean Keys * @@ -198,7 +198,7 @@ class CI_Input { * @return string */ function _clean_input_keys($str) - { + { if (! preg_match("/^[a-z0-9:_\/-]+$/i", $str)) { exit('Disallowed Key Characters.'); @@ -208,7 +208,7 @@ class CI_Input { } // -------------------------------------------------------------------- - + /** * Fetch an item from the GET array * @@ -218,7 +218,7 @@ class CI_Input { * @return string */ function get($index = '', $xss_clean = FALSE) - { + { if (! isset($_GET[$index])) { return FALSE; @@ -229,7 +229,7 @@ class CI_Input { if (is_array($_GET[$index])) { foreach($_GET[$index] as $key => $val) - { + { $_GET[$index][$key] = $this->xss_clean($val); } } @@ -241,9 +241,9 @@ class CI_Input { return $_GET[$index]; } - + // -------------------------------------------------------------------- - + /** * Fetch an item from the POST array * @@ -253,7 +253,7 @@ class CI_Input { * @return string */ function post($index = '', $xss_clean = FALSE) - { + { if (! isset($_POST[$index])) { return FALSE; @@ -264,7 +264,7 @@ class CI_Input { if (is_array($_POST[$index])) { foreach($_POST[$index] as $key => $val) - { + { $_POST[$index][$key] = $this->xss_clean($val); } } @@ -276,9 +276,9 @@ class CI_Input { return $_POST[$index]; } - + // -------------------------------------------------------------------- - + /** * Fetch an item from the COOKIE array * @@ -303,7 +303,7 @@ class CI_Input { { $cookie[$key] = $this->xss_clean($val); } - + return $cookie; } else @@ -318,7 +318,7 @@ class CI_Input { } // -------------------------------------------------------------------- - + /** * Fetch an item from the SERVER array * @@ -328,7 +328,7 @@ class CI_Input { * @return string */ function server($index = '', $xss_clean = FALSE) - { + { if (! isset($_SERVER[$index])) { return FALSE; @@ -338,12 +338,12 @@ class CI_Input { { return $this->xss_clean($_SERVER[$index]); } - + return $_SERVER[$index]; } - + // -------------------------------------------------------------------- - + /** * Fetch the IP Address * @@ -356,7 +356,7 @@ class CI_Input { { return $this->ip_address; } - + if ($this->server('REMOTE_ADDR') AND $this->server('HTTP_CLIENT_IP')) { $this->ip_address = $_SERVER['HTTP_CLIENT_IP']; @@ -373,29 +373,29 @@ class CI_Input { { $this->ip_address = $_SERVER['HTTP_X_FORWARDED_FOR']; } - + if ($this->ip_address === FALSE) { $this->ip_address = '0.0.0.0'; return $this->ip_address; } - + if (strstr($this->ip_address, ',')) { $x = explode(',', $this->ip_address); $this->ip_address = end($x); } - + if (! $this->valid_ip($this->ip_address)) { $this->ip_address = '0.0.0.0'; } - + return $this->ip_address; } - + // -------------------------------------------------------------------- - + /** * Validate IP Address * @@ -408,7 +408,7 @@ class CI_Input { function valid_ip($ip) { $ip_segments = explode('.', $ip); - + // Always 4 segments needed if (count($ip_segments) != 4) { @@ -429,12 +429,12 @@ class CI_Input { return FALSE; } } - + return TRUE; } - + // -------------------------------------------------------------------- - + /** * User Agent * @@ -447,14 +447,14 @@ class CI_Input { { return $this->user_agent; } - + $this->user_agent = (! isset($_SERVER['HTTP_USER_AGENT'])) ? FALSE : $_SERVER['HTTP_USER_AGENT']; - + return $this->user_agent; } - + // -------------------------------------------------------------------- - + /** * Filename Security * @@ -497,13 +497,13 @@ class CI_Input { "%3f", // ? "%3b", // ; "%3d" // = - ); - - return stripslashes(str_replace($bad, '', $str)); + ); + + return stripslashes(str_replace($bad, '', $str)); } - + // -------------------------------------------------------------------- - + /** * XSS Clean * @@ -542,10 +542,10 @@ class CI_Input { { $str[$key] = $this->xss_clean($str[$key]); } - + return $str; } - + /* * Remove Null Characters * @@ -572,7 +572,7 @@ class CI_Input { * */ $str = preg_replace('#(&\#?[0-9a-z]+)[\x00-\x20]*;?#i', "\\1;", $str); - + /* * Validate UTF16 two byte encoding (x00) * @@ -586,7 +586,7 @@ class CI_Input { */ $str = str_replace($this->xss_hash(), '&', $str); - + /* * URL Decode * @@ -596,9 +596,9 @@ class CI_Input { * * Note: Use rawurldecode() so it does not remove plus signs * - */ + */ $str = rawurldecode($str); - + /* * Convert character entities to ASCII * @@ -607,15 +607,15 @@ class CI_Input { * these are the ones that will pose security problems. * */ - + $str = preg_replace_callback("/[a-z]+=([\'\"]).*?\\1/si", array($this, '_attribute_conversion'), $str); $str = preg_replace_callback("/<([\w]+)[^>]*>/si", array($this, '_html_entity_decode_callback'), $str); /* - + Old Code that when modified to use preg_replace()'s above became more efficient memory-wise - + if (preg_match_all("/[a-z]+=([\'\"]).*?\\1/si", $str, $matches)) { for ($i = 0; $i < count($matches[0]); $i++) @@ -639,7 +639,7 @@ class CI_Input { } } */ - + /* * Convert all tabs to spaces * @@ -649,12 +649,14 @@ class CI_Input { * so we use str_replace. * */ - - $str = str_replace("\t", " ", $str); + + if (strpos($str, "\t") !== FALSE) { + $str = str_replace("\t", " ", $str); + } /* * Not Allowed Under Any Conditions - */ + */ $bad = array( 'document.cookie' => '[removed]', 'document.write' => '[removed]', @@ -677,12 +679,12 @@ class CI_Input { "expression\s*\(" => '[removed]', // CSS and IE "Redirect\s+302" => '[removed]' ); - + foreach ($bad as $key => $val) { $str = preg_replace("#".$key."#i", $val, $str); } - + /* * Makes PHP tags safe * @@ -692,16 +694,16 @@ class CI_Input { * * But it doesn't seem to pose a problem. * - */ + */ $str = str_replace(array(''), array('<?php', '<?PHP', '<?', '?>'), $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', 'script', 'applet', 'alert', 'document', 'write', 'cookie', 'window'); foreach ($words as $word) { @@ -710,31 +712,31 @@ class CI_Input { { $temp .= substr($word, $i, 1)."\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('#('.substr($temp, 0, -3).')(\W)#ise', "preg_replace('/\s+/s', '', '\\1').'\\2'", $str); } - + /* * Remove disallowed Javascript in links or img tags */ do { $original = $str; - + if ((version_compare(PHP_VERSION, '5.0', '>=') === TRUE && stripos($str, '') !== FALSE) OR preg_match("/<\/a>/i", $str)) { $str = preg_replace_callback("##si", array($this, '_js_link_removal'), $str); } - + if ((version_compare(PHP_VERSION, '5.0', '>=') === TRUE && stripos($str, '#si", array($this, '_js_img_removal'), $str); } - + if ((version_compare(PHP_VERSION, '5.0', '>=') === TRUE && (stripos($str, 'script') !== FALSE OR stripos($str, 'xss') !== FALSE)) OR preg_match("/(script|xss)/i", $str)) { @@ -742,7 +744,7 @@ class CI_Input { } } while($original != $str); - + unset($original); /* @@ -752,10 +754,10 @@ class CI_Input { * the event handler and anything up to the closing >, * but it's unlikely to be a problem. * - */ + */ $event_handlers = array('onblur','onchange','onclick','onfocus','onload','onmouseover','onmouseup','onmousedown','onselect','onsubmit','onunload','onkeypress','onkeydown','onkeyup','onresize', 'xmlns'); $str = preg_replace("#<([^>]+)(".implode('|', $event_handlers).")([^>]*)>#iU", "<\\1\\2\\3>", $str); - + /* * Sanitize naughty HTML elements * @@ -765,9 +767,9 @@ class CI_Input { * So this: * Becomes: <blink> * - */ + */ $str = preg_replace('#<(/*\s*)(alert|applet|basefont|base|behavior|bgsound|blink|body|embed|expression|form|frameset|frame|head|html|ilayer|iframe|input|layer|link|meta|object|plaintext|style|script|textarea|title|xml|xss)([^>]*)>#is', "<\\1\\2\\3>", $str); - + /* * Sanitize naughty scripting elements * @@ -782,14 +784,14 @@ class CI_Input { * */ $str = preg_replace('#(alert|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 * - */ + */ $bad = array( 'document.cookie' => '[removed]', 'document.write' => '[removed]', @@ -812,19 +814,19 @@ class CI_Input { "expression\s*\(" => '[removed]', // CSS and IE "Redirect\s+302" => '[removed]' ); - + foreach ($bad as $key => $val) { $str = preg_replace("#".$key."#i", $val, $str); } - - + + log_message('debug', "XSS Filtering completed"); return $str; } // -------------------------------------------------------------------- - + /** * Random Hash for protecting URLs * @@ -832,22 +834,22 @@ class CI_Input { * @return string */ function xss_hash() - { + { if ($this->xss_hash == '') { if (phpversion() >= 4.2) mt_srand(); else mt_srand(hexdec(substr(md5(microtime()), -8)) & 0x7fffffff); - + $this->xss_hash = md5(time() + mt_rand(0, 1999999999)); } - + return $this->xss_hash; } // -------------------------------------------------------------------- - + /** * JS Link Removal * @@ -864,7 +866,7 @@ class CI_Input { { return preg_replace("#.*?#si", "", $match[0]); } - + /** * JS Image Removal * @@ -883,7 +885,7 @@ class CI_Input { } // -------------------------------------------------------------------- - + /** * Attribute Conversion * @@ -897,7 +899,7 @@ class CI_Input { { return str_replace('>', '<', $match[0]); } - + // -------------------------------------------------------------------- /** @@ -918,7 +920,7 @@ class CI_Input { } // -------------------------------------------------------------------- - + /** * HTML Entities Decode * @@ -937,7 +939,7 @@ class CI_Input { /* ------------------------------------------------- /* Replacement for html_entity_decode() /* -------------------------------------------------*/ - + /* NOTE: html_entity_decode() has a bug in some PHP versions when UTF-8 is the character set, and the PHP developers said they were not back porting the @@ -946,30 +948,30 @@ class CI_Input { function _html_entity_decode($str, $charset='UTF-8') { if (stristr($str, '&') === FALSE) return $str; - + // 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. - + if (function_exists('html_entity_decode') && (strtolower($charset) != 'utf-8' OR version_compare(phpversion(), '5.0.0', '>='))) { $str = html_entity_decode($str, ENT_COMPAT, $charset); $str = preg_replace('~&#x([0-9a-f]{2,5})~ei', 'chr(hexdec("\\1"))', $str); return preg_replace('~&#([0-9]{2,4})~e', 'chr(\\1)', $str); } - + // Numeric Entities $str = preg_replace('~&#x([0-9a-f]{2,5});{0,1}~ei', 'chr(hexdec("\\1"))', $str); $str = preg_replace('~&#([0-9]{2,4});{0,1}~e', 'chr(\\1)', $str); - + // Literal Entities - Slightly slow so we do another check if (stristr($str, '&') === FALSE) { $str = strtr($str, array_flip(get_html_translation_table(HTML_ENTITIES))); } - + return $str; } diff --git a/system/libraries/Loader.php b/system/libraries/Loader.php index 687598096..b5a69bbdd 100644 --- a/system/libraries/Loader.php +++ b/system/libraries/Loader.php @@ -905,8 +905,8 @@ class CI_Loader { } } - // Autoload plugins, helpers, scripts and languages - foreach (array('helper', 'plugin', 'script', 'language') as $type) + // Autoload plugins, helpers and languages + foreach (array('helper', 'plugin', 'language') as $type) { if (isset($autoload[$type]) AND count($autoload[$type]) > 0) { @@ -1027,6 +1027,6 @@ class CI_Loader { } } - -/* End of file Loader.php */ + +/* End of file Loader.php */ /* Location: ./system/libraries/Loader.php */ \ No newline at end of file diff --git a/system/libraries/Unit_test.php b/system/libraries/Unit_test.php index 2fb2bbd32..bfa6d5dc5 100644 --- a/system/libraries/Unit_test.php +++ b/system/libraries/Unit_test.php @@ -55,8 +55,10 @@ class CI_Unit_test { function run($test, $expected = TRUE, $test_name = 'undefined') { if ($this->active == FALSE) + { return FALSE; - + } + if (in_array($expected, array('is_string', 'is_bool', 'is_true', 'is_false', 'is_int', 'is_numeric', 'is_float', 'is_double', 'is_array', 'is_null'), TRUE)) { $expected = str_replace('is_float', 'is_double', $expected); @@ -340,6 +342,6 @@ function is_false($test) return (is_bool($test) AND $test === FALSE) ? TRUE : FALSE; } - -/* End of file Unit_test.php */ + +/* End of file Unit_test.php */ /* Location: ./system/libraries/Unit_test.php */ \ No newline at end of file -- cgit v1.2.3-24-g4f1b From 751506e7dd58dd1c257c7170b61fe1f439e25021 Mon Sep 17 00:00:00 2001 From: Derek Allard Date: Mon, 12 May 2008 21:43:54 +0000 Subject: fixed a misspelling in the Input library of CDATA --- system/libraries/Input.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system') diff --git a/system/libraries/Input.php b/system/libraries/Input.php index e3515661d..f98757947 100644 --- a/system/libraries/Input.php +++ b/system/libraries/Input.php @@ -666,7 +666,7 @@ class CI_Input { '-moz-binding' => '[removed]', '' => '-->', - ' '<![CDATA[' + ' '<![CDATA[' ); foreach ($bad as $key => $val) -- cgit v1.2.3-24-g4f1b From 20d2405051bae7da50299df94c6bcdd9d55e86a2 Mon Sep 17 00:00:00 2001 From: Derek Allard Date: Mon, 12 May 2008 22:12:11 +0000 Subject: substr checks swapped out with strncmp { braces } added around if and for statements --- system/libraries/Email.php | 88 +++++++++++++++++++++++++++++++++++++--------- 1 file changed, 72 insertions(+), 16 deletions(-) (limited to 'system') diff --git a/system/libraries/Email.php b/system/libraries/Email.php index d32928a66..b7d9d2ebf 100644 --- a/system/libraries/Email.php +++ b/system/libraries/Email.php @@ -168,12 +168,16 @@ class CI_Email { function from($from, $name = '') { if (preg_match( '/\<(.*)\>/', $from, $match)) + { $from = $match['1']; + } if ($this->validate) + { $this->validate_email($this->_str_to_array($from)); + } - if ($name != '' && substr($name, 0, 1) != '"') + if ($name != '' && strncmp($name, '"', 1) != 0) { $name = '"'.$name.'"'; } @@ -195,17 +199,21 @@ class CI_Email { 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 (substr($name, 0, 1) != '"') + if (strncmp($name, '"', 1) != 0) { $name = '"'.$name.'"'; } @@ -229,10 +237,14 @@ class CI_Email { $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()) { @@ -265,7 +277,9 @@ class CI_Email { $this->_set_header('Cc', implode(", ", $cc)); if ($this->_get_protocol() == "smtp") + { $this->_cc_array = $cc; + } } // -------------------------------------------------------------------- @@ -290,12 +304,18 @@ class CI_Email { $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)); + } } // -------------------------------------------------------------------- @@ -554,7 +574,9 @@ class CI_Email { $this->protocol = (! in_array($this->protocol, $this->_protocols, TRUE)) ? 'mail' : $this->protocol; if ($return == TRUE) + { return $this->protocol; + } } // -------------------------------------------------------------------- @@ -594,16 +616,22 @@ class CI_Email { */ function _get_content_type() { - if ($this->mailtype == 'html' && count($this->_attach_name) == 0) + 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'; + } + else + { + return 'plain'; + } } // -------------------------------------------------------------------- @@ -617,7 +645,7 @@ class CI_Email { function _set_date() { $timezone = date("Z"); - $operator = (substr($timezone, 0, 1) == '-') ? '-' : '+'; + $operator = (strncmp($timezone, '-', 1) == 0) ? '-' : '+'; $timezone = abs($timezone); $timezone = floor($timezone/3600) * 100 + ($timezone % 3600 ) / 60; @@ -692,9 +720,13 @@ class CI_Email { if (! is_array($email)) { if (preg_match('/\<(.*)\>/', $email, $match)) + { return $match['1']; + } else + { return $email; + } } $clean_email = array(); @@ -752,7 +784,9 @@ class CI_Email { $n = ""; for ($x = 1; $x <= $i; $x ++) + { $n .= "\n"; + } $body = str_replace($n, "\n\n", $body); } @@ -823,7 +857,7 @@ class CI_Email { } // Trim the word down - $temp .= substr($line, 0, $charlim-1); + $temp .= ($line, 0, $charlim-1); $line = substr($line, $charlim-1); } @@ -1213,9 +1247,13 @@ class CI_Email { $this->_build_message(); if (! $this->_spool_email()) + { return FALSE; + } else + { return TRUE; + } } // -------------------------------------------------------------------- @@ -1238,7 +1276,9 @@ class CI_Email { for ($i = 0; $i < count($this->_bcc_array); $i++) { if (isset($this->_bcc_array[$i])) + { $set .= ", ".$this->_bcc_array[$i]; + } if ($i == $float) { @@ -1248,7 +1288,9 @@ class CI_Email { } if ($i == count($this->_bcc_array)-1) - $chunk[] = substr($set, 1); + { + $chunk[] = substr($set, 1); + } } for ($i = 0; $i < count($chunk); $i++) @@ -1260,9 +1302,13 @@ class CI_Email { $bcc = $this->clean_email($bcc); if ($this->protocol != 'smtp') + { $this->_set_header('Bcc', implode(", ", $bcc)); + } else + { $this->_bcc_array = $bcc; + } $this->_build_message(); $this->_spool_email(); @@ -1446,7 +1492,7 @@ class CI_Email { $this->_set_error_message($reply); - if (substr($reply, 0, 3) != '250') + if (strncmp($reply, '250', 3) != 0) { $this->_set_error_message('email_smtp_error', $reply); return FALSE; @@ -1543,7 +1589,9 @@ class CI_Email { } if ($cmd == 'quit') + { fclose($this->_smtp_connect); + } return TRUE; } @@ -1559,7 +1607,9 @@ class CI_Email { function _smtp_authenticate() { if (! $this->_smtp_auth) + { return TRUE; + } if ($this->smtp_user == "" AND $this->smtp_pass == "") { @@ -1571,7 +1621,7 @@ class CI_Email { $reply = $this->_get_smtp_data(); - if (substr($reply, 0, 3) != '334') + if (strncmp($reply, '334', 3) != 0) { $this->_set_error_message('email_failed_smtp_login', $reply); return FALSE; @@ -1581,7 +1631,7 @@ class CI_Email { $reply = $this->_get_smtp_data(); - if (substr($reply, 0, 3) != '334') + if (strncmp($reply, '334', 3) != 0) { $this->_set_error_message('email_smtp_auth_un', $reply); return FALSE; @@ -1591,7 +1641,7 @@ class CI_Email { $reply = $this->_get_smtp_data(); - if (substr($reply, 0, 3) != '235') + if (strncmp($reply, '235', 3) != 0) { $this->_set_error_message('email_smtp_auth_pw', $reply); return FALSE; @@ -1616,7 +1666,9 @@ class CI_Email { return FALSE; } else + { return TRUE; + } } // -------------------------------------------------------------------- @@ -1636,7 +1688,9 @@ class CI_Email { $data .= $str; if (substr($str, 3, 1) == " ") + { break; + } } return $data; @@ -1686,7 +1740,9 @@ class CI_Email { } if (! preg_match( "/^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$/", $this->_IP)) + { $this->_IP = '0.0.0.0'; + } unset($cip); unset($rip); @@ -1848,6 +1904,6 @@ class CI_Email { } // END CI_Email class - -/* End of file Email.php */ + +/* End of file Email.php */ /* Location: ./system/libraries/Email.php */ \ No newline at end of file -- cgit v1.2.3-24-g4f1b From 62bd43029cbd290d684ee32a8387f66ccad3a64a Mon Sep 17 00:00:00 2001 From: Derek Allard Date: Mon, 12 May 2008 22:19:03 +0000 Subject: preg_split changed to explode --- system/libraries/Email.php | 330 ++++++++++++++++++++++----------------------- 1 file changed, 165 insertions(+), 165 deletions(-) (limited to 'system') diff --git a/system/libraries/Email.php b/system/libraries/Email.php index b7d9d2ebf..ebb969288 100644 --- a/system/libraries/Email.php +++ b/system/libraries/Email.php @@ -83,13 +83,13 @@ class CI_Email { * The constructor can be passed an array of config values */ function CI_Email($config = array()) - { + { if (count($config) > 0) { $this->initialize($config); } - $this->_smtp_auth = ($this->smtp_user == '' AND $this->smtp_pass == '') ? FALSE : TRUE; + $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"); @@ -112,7 +112,7 @@ class CI_Email { if (isset($this->$key)) { $method = 'set_'.$key; - + if (method_exists($this, $method)) { $this->$method($val); @@ -120,7 +120,7 @@ class CI_Email { else { $this->$key = $val; - } + } } } } @@ -143,16 +143,16 @@ class CI_Email { $this->_recipients = array(); $this->_headers = array(); $this->_debug_msg = array(); - - $this->_set_header('User-Agent', $this->useragent); + + $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(); - } + } } // -------------------------------------------------------------------- @@ -176,7 +176,7 @@ class CI_Email { { $this->validate_email($this->_str_to_array($from)); } - + if ($name != '' && strncmp($name, '"', 1) != 0) { $name = '"'.$name.'"'; @@ -240,7 +240,7 @@ class CI_Email { { $this->validate_email($to); } - + if ($this->_get_protocol() != 'mail') { $this->_set_header('To', implode(", ", $to)); @@ -275,7 +275,7 @@ class CI_Email { $this->validate_email($cc); $this->_set_header('Cc', implode(", ", $cc)); - + if ($this->_get_protocol() == "smtp") { $this->_cc_array = $cc; @@ -302,7 +302,7 @@ class CI_Email { $bcc = $this->_str_to_array($bcc); $bcc = $this->clean_email($bcc); - + if ($this->validate) { $this->validate_email($bcc); @@ -331,8 +331,8 @@ class CI_Email { { $subject = preg_replace("/(\r\n)|(\r)|(\n)/", "", $subject); $subject = preg_replace("/(\t)/", " ", $subject); - - $this->_set_header('Subject', trim($subject)); + + $this->_set_header('Subject', trim($subject)); } // -------------------------------------------------------------------- @@ -357,9 +357,9 @@ class CI_Email { * @access public * @param string * @return string - */ + */ function attach($filename, $disposition = 'attachment') - { + { $this->_attach_name[] = $filename; $this->_attach_type[] = $this->_mime_types(next(explode('.', basename($filename)))); $this->_attach_disp[] = $disposition; // Can also be 'inline' Not sure if it matters @@ -398,7 +398,7 @@ class CI_Email { $email = preg_split('/[\s,]/', $email, -1, PREG_SPLIT_NO_EMPTY); } else - { + { $email = trim($email); settype($email, "array"); } @@ -572,7 +572,7 @@ class CI_Email { { $this->protocol = strtolower($this->protocol); $this->protocol = (! in_array($this->protocol, $this->_protocols, TRUE)) ? 'mail' : $this->protocol; - + if ($return == TRUE) { return $this->protocol; @@ -589,9 +589,9 @@ class CI_Email { * @return string */ 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) @@ -599,10 +599,10 @@ class CI_Email { $this->_encoding = '7bit'; } } - + if ($return == TRUE) { - return $this->_encoding; + return $this->_encoding; } } @@ -622,7 +622,7 @@ class CI_Email { } elseif ($this->mailtype == 'html' && count($this->_attach_name) > 0) { - return 'html-attach'; + return 'html-attach'; } elseif ($this->mailtype == 'text' && count($this->_attach_name) > 0) { @@ -648,7 +648,7 @@ class CI_Email { $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); } @@ -678,7 +678,7 @@ class CI_Email { { if (! is_array($email)) { - $this->_set_error_message('email_must_be_array'); + $this->_set_error_message('email_must_be_array'); return FALSE; } @@ -686,7 +686,7 @@ class CI_Email { { if (! $this->valid_email($val)) { - $this->_set_error_message('email_invalid_address', $val); + $this->_set_error_message('email_invalid_address', $val); return FALSE; } } @@ -728,21 +728,21 @@ class CI_Email { return $email; } } - + $clean_email = array(); foreach ($email as $addy) { if (preg_match( '/\<(.*)\>/', $addy, $match)) { - $clean_email[] = $match['1']; + $clean_email[] = $match['1']; } else { - $clean_email[] = $addy; + $clean_email[] = $addy; } } - + return $clean_email; } @@ -765,7 +765,7 @@ class CI_Email { { return $this->word_wrap($this->alt_message, '76'); } - + if (preg_match('/\(.*)\<\/body\>/si', $this->_body, $match)) { $body = $match['1']; @@ -774,20 +774,20 @@ class CI_Email { { $body = $this->_body; } - + $body = trim(strip_tags($body)); $body = preg_replace( '# '.$message. ' '.$filepath.' '.$line, TRUE); } @@ -115,7 +115,7 @@ class CI_Exceptions { */ function show_error($heading, $message, $template = 'error_general') { - $message = '

    '.implode('

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

    '; + $message = '

    '.implode('

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

    '; if (ob_get_level() > $this->ob_level + 1) { @@ -142,7 +142,7 @@ class CI_Exceptions { */ function show_php_error($severity, $message, $filepath, $line) { - $severity = (! isset($this->levels[$severity])) ? $severity : $this->levels[$severity]; + $severity = ( ! isset($this->levels[$severity])) ? $severity : $this->levels[$severity]; $filepath = str_replace("\\", "/", $filepath); @@ -167,6 +167,6 @@ class CI_Exceptions { } // END Exceptions Class - -/* End of file Exceptions.php */ + +/* End of file Exceptions.php */ /* Location: ./system/libraries/Exceptions.php */ \ No newline at end of file diff --git a/system/libraries/Ftp.php b/system/libraries/Ftp.php index 01354cf05..170ebe1c4 100644 --- a/system/libraries/Ftp.php +++ b/system/libraries/Ftp.php @@ -1,4 +1,4 @@ -_login()) + if ( ! $this->_login()) { if ($this->debug == TRUE) { @@ -139,7 +139,7 @@ class CI_FTP { */ function _is_conn() { - if (! is_resource($this->conn_id)) + if ( ! is_resource($this->conn_id)) { if ($this->debug == TRUE) { @@ -216,7 +216,7 @@ class CI_FTP { } // Set file permissions if needed - if (! is_null($permissions)) + if ( ! is_null($permissions)) { $this->chmod($path, (int)$permissions); } @@ -237,12 +237,12 @@ class CI_FTP { */ function upload($locpath, $rempath, $mode = 'auto', $permissions = NULL) { - if (! $this->_is_conn()) + if ( ! $this->_is_conn()) { return FALSE; } - if (! file_exists($locpath)) + if ( ! file_exists($locpath)) { $this->_error('ftp_no_source_file'); return FALSE; @@ -270,7 +270,7 @@ class CI_FTP { } // Set file permissions if needed - if (! is_null($permissions)) + if ( ! is_null($permissions)) { $this->chmod($rempath, (int)$permissions); } @@ -291,7 +291,7 @@ class CI_FTP { */ function rename($old_file, $new_file, $move = FALSE) { - if (! $this->_is_conn()) + if ( ! $this->_is_conn()) { return FALSE; } @@ -338,7 +338,7 @@ class CI_FTP { */ function delete_file($filepath) { - if (! $this->_is_conn()) + if ( ! $this->_is_conn()) { return FALSE; } @@ -369,7 +369,7 @@ class CI_FTP { */ function delete_dir($filepath) { - if (! $this->_is_conn()) + if ( ! $this->_is_conn()) { return FALSE; } @@ -385,7 +385,7 @@ class CI_FTP { { // If we can't delete the item it's probaly a folder so // we'll recursively call delete_dir() - if (! @ftp_delete($this->conn_id, $item)) + if ( ! @ftp_delete($this->conn_id, $item)) { $this->delete_dir($item); } @@ -418,13 +418,13 @@ class CI_FTP { */ function chmod($path, $perm) { - if (! $this->_is_conn()) + if ( ! $this->_is_conn()) { return FALSE; } // Permissions can only be set when running PHP 5 - if (! function_exists('ftp_chmod')) + if ( ! function_exists('ftp_chmod')) { if ($this->debug == TRUE) { @@ -457,7 +457,7 @@ class CI_FTP { */ function list_files($path = '.') { - if (! $this->_is_conn()) + if ( ! $this->_is_conn()) { return FALSE; } @@ -481,7 +481,7 @@ class CI_FTP { */ function mirror($locpath, $rempath) { - if (! $this->_is_conn()) + if ( ! $this->_is_conn()) { return FALSE; } @@ -490,10 +490,10 @@ class CI_FTP { if ($fp = @opendir($locpath)) { // Attempt to open the remote file path. - if (! $this->changedir($rempath, TRUE)) + if ( ! $this->changedir($rempath, TRUE)) { // If it doesn't exist we'll attempt to create the direcotory - if (! $this->mkdir($rempath) OR ! $this->changedir($rempath)) + if ( ! $this->mkdir($rempath) OR ! $this->changedir($rempath)) { return FALSE; } @@ -586,7 +586,7 @@ class CI_FTP { */ function close() { - if (! $this->_is_conn()) + if ( ! $this->_is_conn()) { return FALSE; } @@ -613,6 +613,6 @@ class CI_FTP { } // END FTP Class - -/* End of file Ftp.php */ + +/* End of file Ftp.php */ /* Location: ./system/libraries/Ftp.php */ \ No newline at end of file diff --git a/system/libraries/Hooks.php b/system/libraries/Hooks.php index d7637c39e..8c99bdd10 100644 --- a/system/libraries/Hooks.php +++ b/system/libraries/Hooks.php @@ -1,4 +1,4 @@ -enabled OR ! isset($this->hooks[$which])) + if ( ! $this->enabled OR ! isset($this->hooks[$which])) { return FALSE; } @@ -123,7 +123,7 @@ class CI_Hooks { */ function _run_hook($data) { - if (! is_array($data)) + if ( ! is_array($data)) { return FALSE; } @@ -144,14 +144,14 @@ class CI_Hooks { // Set file path // ----------------------------------- - if (! isset($data['filepath']) OR ! isset($data['filename'])) + if ( ! isset($data['filepath']) OR ! isset($data['filename'])) { return FALSE; } $filepath = APPPATH.$data['filepath'].'/'.$data['filename']; - if (! file_exists($filepath)) + if ( ! file_exists($filepath)) { return FALSE; } @@ -196,7 +196,7 @@ class CI_Hooks { if ($class !== FALSE) { - if (! class_exists($class)) + if ( ! class_exists($class)) { require($filepath); } @@ -206,7 +206,7 @@ class CI_Hooks { } else { - if (! function_exists($function)) + if ( ! function_exists($function)) { require($filepath); } @@ -221,6 +221,6 @@ class CI_Hooks { } // END CI_Hooks class - -/* End of file Hooks.php */ + +/* End of file Hooks.php */ /* Location: ./system/libraries/Hooks.php */ \ No newline at end of file diff --git a/system/libraries/Image_lib.php b/system/libraries/Image_lib.php index 4017afb13..a602b4645 100644 --- a/system/libraries/Image_lib.php +++ b/system/libraries/Image_lib.php @@ -1,4 +1,4 @@ -set_error('imglib_gd_required_for_props'); return FALSE; @@ -188,7 +188,7 @@ class CI_Image_lib { $this->source_folder = str_replace($this->source_image, '', $full_source_path); // Set the Image Properties - if (! $this->get_image_properties($this->source_folder.$this->source_image)) + if ( ! $this->get_image_properties($this->source_folder.$this->source_image)) { return FALSE; } @@ -226,7 +226,7 @@ class CI_Image_lib { } // Is there a file name? - if (! preg_match("#[\.jpg|\.jpeg|\.gif|\.png]$#i", $full_dest_path)) + if ( ! preg_match("#[\.jpg|\.jpeg|\.gif|\.png]$#i", $full_dest_path)) { $this->dest_folder = $full_dest_path.'/'; $this->dest_image = $this->source_image; @@ -478,7 +478,7 @@ class CI_Image_lib { // we'll simply make a copy of the original with the new name if (($this->orig_width == $this->width AND $this->orig_height == $this->height) AND ($this->source_image != $this->new_image)) { - if (! @copy($this->full_src_path, $this->full_dst_path)) + if ( ! @copy($this->full_src_path, $this->full_dst_path)) { $this->set_error('imglib_copy_failed'); return FALSE; @@ -494,7 +494,7 @@ class CI_Image_lib { } // Create the image handle - if (! ($src_img = $this->image_create_gd())) + if ( ! ($src_img = $this->image_create_gd())) { return FALSE; } @@ -528,7 +528,7 @@ class CI_Image_lib { else { // Or save it - if (! $this->image_save_gd($dst_img)) + if ( ! $this->image_save_gd($dst_img)) { return FALSE; } @@ -564,9 +564,9 @@ class CI_Image_lib { return FALSE; } - if (! eregi("convert$", $this->library_path)) + if ( ! eregi("convert$", $this->library_path)) { - if (! eregi("/$", $this->library_path)) $this->library_path .= "/"; + if ( ! eregi("/$", $this->library_path)) $this->library_path .= "/"; $this->library_path .= 'convert'; } @@ -712,14 +712,14 @@ class CI_Image_lib { { // Is Image Rotation Supported? // this function is only supported as of PHP 4.3 - if (! function_exists('imagerotate')) + if ( ! function_exists('imagerotate')) { $this->set_error('imglib_rotate_unsupported'); return FALSE; } // Create the image handle - if (! ($src_img = $this->image_create_gd())) + if ( ! ($src_img = $this->image_create_gd())) { return FALSE; } @@ -742,7 +742,7 @@ class CI_Image_lib { else { // Or save it - if (! $this->image_save_gd($dst_img)) + if ( ! $this->image_save_gd($dst_img)) { return FALSE; } @@ -771,7 +771,7 @@ class CI_Image_lib { */ function image_mirror_gd() { - if (! $src_img = $this->image_create_gd()) + if ( ! $src_img = $this->image_create_gd()) { return FALSE; } @@ -828,7 +828,7 @@ class CI_Image_lib { else { // Or save it - if (! $this->image_save_gd($src_img)) + if ( ! $this->image_save_gd($src_img)) { return FALSE; } @@ -877,7 +877,7 @@ class CI_Image_lib { */ function overlay_watermark() { - if (! function_exists('imagecolortransparent')) + if ( ! function_exists('imagecolortransparent')) { $this->set_error('imglib_gd_required'); return FALSE; @@ -968,7 +968,7 @@ class CI_Image_lib { } else { - if (! $this->image_save_gd($src_img)) + if ( ! $this->image_save_gd($src_img)) { return FALSE; } @@ -990,7 +990,7 @@ class CI_Image_lib { */ function text_watermark() { - if (! ($src_img = $this->image_create_gd())) + if ( ! ($src_img = $this->image_create_gd())) { return FALSE; } @@ -1144,7 +1144,7 @@ class CI_Image_lib { switch ($image_type) { case 1 : - if (! function_exists('imagecreatefromgif')) + if ( ! function_exists('imagecreatefromgif')) { $this->set_error(array('imglib_unsupported_imagecreate', 'imglib_gif_not_supported')); return FALSE; @@ -1153,7 +1153,7 @@ class CI_Image_lib { return imagecreatefromgif($path); break; case 2 : - if (! function_exists('imagecreatefromjpeg')) + if ( ! function_exists('imagecreatefromjpeg')) { $this->set_error(array('imglib_unsupported_imagecreate', 'imglib_jpg_not_supported')); return FALSE; @@ -1162,7 +1162,7 @@ class CI_Image_lib { return imagecreatefromjpeg($path); break; case 3 : - if (! function_exists('imagecreatefrompng')) + if ( ! function_exists('imagecreatefrompng')) { $this->set_error(array('imglib_unsupported_imagecreate', 'imglib_png_not_supported')); return FALSE; @@ -1194,7 +1194,7 @@ class CI_Image_lib { switch ($this->image_type) { case 1 : - if (! function_exists('imagegif')) + if ( ! function_exists('imagegif')) { $this->set_error(array('imglib_unsupported_imagecreate', 'imglib_gif_not_supported')); return FALSE; @@ -1203,7 +1203,7 @@ class CI_Image_lib { @imagegif($resource, $this->full_dst_path); break; case 2 : - if (! function_exists('imagejpeg')) + if ( ! function_exists('imagejpeg')) { $this->set_error(array('imglib_unsupported_imagecreate', 'imglib_jpg_not_supported')); return FALSE; @@ -1217,7 +1217,7 @@ class CI_Image_lib { @imagejpeg($resource, $this->full_dst_path, $this->quality); break; case 3 : - if (! function_exists('imagepng')) + if ( ! function_exists('imagepng')) { $this->set_error(array('imglib_unsupported_imagecreate', 'imglib_png_not_supported')); return FALSE; @@ -1280,10 +1280,10 @@ class CI_Image_lib { */ function image_reproportion() { - if (! is_numeric($this->width) OR ! is_numeric($this->height) OR $this->width == 0 OR $this->height == 0) + if ( ! is_numeric($this->width) OR ! is_numeric($this->height) OR $this->width == 0 OR $this->height == 0) return; - if (! is_numeric($this->orig_width) OR ! is_numeric($this->orig_height) OR $this->orig_width == 0 OR $this->orig_height == 0) + if ( ! is_numeric($this->orig_width) OR ! is_numeric($this->orig_height) OR $this->orig_width == 0 OR $this->orig_height == 0) return; $new_width = ceil($this->orig_width*$this->height/$this->orig_height); @@ -1328,7 +1328,7 @@ class CI_Image_lib { if ($path == '') $path = $this->full_src_path; - if (! file_exists($path)) + if ( ! file_exists($path)) { $this->set_error('imglib_invalid_path'); return FALSE; @@ -1382,14 +1382,14 @@ class CI_Image_lib { */ function size_calculator($vals) { - if (! is_array($vals)) + if ( ! is_array($vals)) return; $allowed = array('new_width', 'new_height', 'width', 'height'); foreach ($allowed as $item) { - if (! isset($vals[$item]) OR $vals[$item] == '') + if ( ! isset($vals[$item]) OR $vals[$item] == '') $vals[$item] = 0; } @@ -1460,9 +1460,9 @@ class CI_Image_lib { */ function gd_loaded() { - if (! extension_loaded('gd')) + if ( ! extension_loaded('gd')) { - if (! dl('gd.so')) + if ( ! dl('gd.so')) { return FALSE; } diff --git a/system/libraries/Input.php b/system/libraries/Input.php index f98757947..978d1ff34 100644 --- a/system/libraries/Input.php +++ b/system/libraries/Input.php @@ -1,4 +1,4 @@ - $val) { - if (! in_array($key, $protected)) + if ( ! in_array($key, $protected)) { unset($GLOBALS[$key]); } @@ -97,7 +97,7 @@ class CI_Input { { foreach($val as $k => $v) { - if (! in_array($k, $protected)) + if ( ! in_array($k, $protected)) { unset($GLOBALS[$k]); } @@ -181,7 +181,12 @@ class CI_Input { } // Standardize newlines - return preg_replace("/\015\012|\015|\012/", "\n", $str); + if (strpos($str, "\r") !== FALSE) + { + $str = str_replace(array("\r\n", "\r"), "\n", $str); + } + + return $str; } // -------------------------------------------------------------------- @@ -199,7 +204,7 @@ class CI_Input { */ function _clean_input_keys($str) { - if (! preg_match("/^[a-z0-9:_\/-]+$/i", $str)) + if ( ! preg_match("/^[a-z0-9:_\/-]+$/i", $str)) { exit('Disallowed Key Characters.'); } @@ -219,7 +224,7 @@ class CI_Input { */ function get($index = '', $xss_clean = FALSE) { - if (! isset($_GET[$index])) + if ( ! isset($_GET[$index])) { return FALSE; } @@ -254,7 +259,7 @@ class CI_Input { */ function post($index = '', $xss_clean = FALSE) { - if (! isset($_POST[$index])) + if ( ! isset($_POST[$index])) { return FALSE; } @@ -289,7 +294,7 @@ class CI_Input { */ function cookie($index = '', $xss_clean = FALSE) { - if (! isset($_COOKIE[$index])) + if ( ! isset($_COOKIE[$index])) { return FALSE; } @@ -329,7 +334,7 @@ class CI_Input { */ function server($index = '', $xss_clean = FALSE) { - if (! isset($_SERVER[$index])) + if ( ! isset($_SERVER[$index])) { return FALSE; } @@ -386,7 +391,7 @@ class CI_Input { $this->ip_address = end($x); } - if (! $this->valid_ip($this->ip_address)) + if ( ! $this->valid_ip($this->ip_address)) { $this->ip_address = '0.0.0.0'; } @@ -448,7 +453,7 @@ class CI_Input { return $this->user_agent; } - $this->user_agent = (! isset($_SERVER['HTTP_USER_AGENT'])) ? FALSE : $_SERVER['HTTP_USER_AGENT']; + $this->user_agent = ( ! isset($_SERVER['HTTP_USER_AGENT'])) ? FALSE : $_SERVER['HTTP_USER_AGENT']; return $this->user_agent; } @@ -650,8 +655,9 @@ class CI_Input { * */ - if (strpos($str, "\t") !== FALSE) { - $str = str_replace("\t", " ", $str); + if (strpos($str, "\t") !== FALSE) + { + $str = str_replace("\t", ' ', $str); } /* diff --git a/system/libraries/Language.php b/system/libraries/Language.php index aacc6c1f9..f97db3506 100644 --- a/system/libraries/Language.php +++ b/system/libraries/Language.php @@ -1,4 +1,4 @@ -load->database($db_conn, FALSE, TRUE); } - if (! class_exists('Model')) + if ( ! class_exists('Model')) { load_class('Model', FALSE); } @@ -230,7 +230,7 @@ class CI_Loader { */ function dbutil() { - if (! class_exists('CI_DB')) + if ( ! class_exists('CI_DB')) { $this->database(); } @@ -260,7 +260,7 @@ class CI_Loader { */ function dbforge() { - if (! class_exists('CI_DB')) + if ( ! class_exists('CI_DB')) { $this->database(); } @@ -355,7 +355,7 @@ class CI_Loader { */ function helper($helpers = array()) { - if (! is_array($helpers)) + if ( ! is_array($helpers)) { $helpers = array($helpers); } @@ -376,7 +376,7 @@ class CI_Loader { { $base_helper = BASEPATH.'helpers/'.$helper.EXT; - if (! file_exists($base_helper)) + if ( ! file_exists($base_helper)) { show_error('Unable to load the requested file: helpers/'.$helper.EXT); } @@ -437,7 +437,7 @@ class CI_Loader { */ function plugin($plugins = array()) { - if (! is_array($plugins)) + if ( ! is_array($plugins)) { $plugins = array($plugins); } @@ -507,7 +507,7 @@ class CI_Loader { */ function script($scripts = array()) { - if (! is_array($scripts)) + if ( ! is_array($scripts)) { $scripts = array($scripts); } @@ -521,7 +521,7 @@ class CI_Loader { continue; } - if (! file_exists(APPPATH.'scripts/'.$script.EXT)) + if ( ! file_exists(APPPATH.'scripts/'.$script.EXT)) { show_error('Unable to load the requested script: scripts/'.$script.EXT); } @@ -546,7 +546,7 @@ class CI_Loader { { $CI =& get_instance(); - if (! is_array($file)) + if ( ! is_array($file)) { $file = array($file); } @@ -632,7 +632,7 @@ class CI_Loader { // 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]; + $$_ci_val = ( ! isset($_ci_data[$_ci_val])) ? FALSE : $_ci_data[$_ci_val]; } // Set the path to the requested file @@ -648,7 +648,7 @@ class CI_Loader { $_ci_file = end($_ci_x); } - if (! file_exists($_ci_path)) + if ( ! file_exists($_ci_path)) { show_error('Unable to load the requested file: '.$_ci_file); } @@ -662,7 +662,7 @@ class CI_Loader { $_ci_CI =& get_instance(); foreach (get_object_vars($_ci_CI) as $_ci_key => $_ci_var) { - if (! isset($this->$_ci_key)) + if ( ! isset($this->$_ci_key)) { $this->$_ci_key =& $_ci_CI->$_ci_key; } @@ -703,7 +703,7 @@ class CI_Loader { if ((bool) @ini_get('short_open_tag') === FALSE AND config_item('rewrite_short_tags') == TRUE) { - echo eval('?>'.preg_replace("/;*\s*\?>/", "; ?>", str_replace('/", "; ?>", str_replace('_ci_varmap[$class])) ? $class : $this->_ci_varmap[$class]; + $classvar = ( ! isset($this->_ci_varmap[$class])) ? $class : $this->_ci_varmap[$class]; // Instantiate the class $CI =& get_instance(); @@ -890,7 +890,7 @@ class CI_Loader { { include_once(APPPATH.'config/autoload'.EXT); - if (! isset($autoload)) + if ( ! isset($autoload)) { return FALSE; } @@ -918,7 +918,7 @@ class CI_Loader { // A little tweak to remain backward compatible // The $autoload['core'] item was deprecated - if (! isset($autoload['libraries'])) + if ( ! isset($autoload['libraries'])) { $autoload['libraries'] = $autoload['core']; } diff --git a/system/libraries/Log.php b/system/libraries/Log.php index 22b505906..4d64cd328 100644 --- a/system/libraries/Log.php +++ b/system/libraries/Log.php @@ -1,4 +1,4 @@ -log_path = ($config['log_path'] != '') ? $config['log_path'] : BASEPATH.'logs/'; - if (! is_dir($this->log_path) OR ! is_really_writable($this->log_path)) + if ( ! is_dir($this->log_path) OR ! is_really_writable($this->log_path)) { $this->_enabled = FALSE; } @@ -84,7 +84,7 @@ class CI_Log { $level = strtoupper($level); - if (! isset($this->_levels[$level]) OR ($this->_levels[$level] > $this->_threshold)) + if ( ! isset($this->_levels[$level]) OR ($this->_levels[$level] > $this->_threshold)) { return FALSE; } @@ -92,12 +92,12 @@ class CI_Log { $filepath = $this->log_path.'log-'.date('Y-m-d').EXT; $message = ''; - if (! file_exists($filepath)) + if ( ! file_exists($filepath)) { - $message .= "<"."?php if (!defined('BASEPATH')) exit('No direct script access allowed'); ?".">\n\n"; + $message .= "<"."?php if ( ! defined('BASEPATH')) exit('No direct script access allowed'); ?".">\n\n"; } - if (! $fp = @fopen($filepath, FOPEN_WRITE_CREATE)) + if ( ! $fp = @fopen($filepath, FOPEN_WRITE_CREATE)) { return FALSE; } @@ -115,6 +115,6 @@ class CI_Log { } // END Log Class - -/* End of file Log.php */ + +/* End of file Log.php */ /* Location: ./system/libraries/Log.php */ \ No newline at end of file diff --git a/system/libraries/Model.php b/system/libraries/Model.php index 1e7b9a184..5c8d43363 100644 --- a/system/libraries/Model.php +++ b/system/libraries/Model.php @@ -1,4 +1,4 @@ -$key) AND $key != $this->_parent_name) + if ( ! isset($this->$key) AND $key != $this->_parent_name) { // In some cases using references can cause // problems so we'll conditionally use them @@ -79,6 +79,6 @@ class Model { } // END Model Class - -/* End of file Model.php */ + +/* End of file Model.php */ /* Location: ./system/libraries/Model.php */ \ No newline at end of file diff --git a/system/libraries/Output.php b/system/libraries/Output.php index f76550e2b..49cfc0a28 100644 --- a/system/libraries/Output.php +++ b/system/libraries/Output.php @@ -1,4 +1,4 @@ -cache_expiration = (! is_numeric($time)) ? 0 : $time; + $this->cache_expiration = ( ! is_numeric($time)) ? 0 : $time; } // -------------------------------------------------------------------- @@ -187,7 +187,7 @@ class CI_Output { $elapsed = $BM->elapsed_time('total_execution_time_start', 'total_execution_time_end'); $output = str_replace('{elapsed_time}', $elapsed, $output); - $memory = (! function_exists('memory_get_usage')) ? '0' : round(memory_get_usage()/1024/1024, 2).'MB'; + $memory = ( ! function_exists('memory_get_usage')) ? '0' : round(memory_get_usage()/1024/1024, 2).'MB'; $output = str_replace('{memory_usage}', $memory, $output); // -------------------------------------------------------------------- @@ -220,7 +220,7 @@ class CI_Output { // Does the get_instance() function exist? // If not we know we are dealing with a cache file so we'll // simply echo out the data and exit. - if (! function_exists('get_instance')) + if ( ! function_exists('get_instance')) { echo $output; log_message('debug', "Final output sent to browser"); @@ -285,7 +285,7 @@ class CI_Output { $cache_path = ($path == '') ? BASEPATH.'cache/' : $path; - if (! is_dir($cache_path) OR ! is_really_writable($cache_path)) + if ( ! is_dir($cache_path) OR ! is_really_writable($cache_path)) { return; } @@ -296,7 +296,7 @@ class CI_Output { $cache_path .= md5($uri); - if (! $fp = @fopen($cache_path, 'wb')) + if ( ! $fp = @fopen($cache_path, 'wb')) { log_message('error', "Unable to write cache file: ".$cache_path); return; @@ -327,7 +327,7 @@ class CI_Output { $cache_path = ($CFG->item('cache_path') == '') ? BASEPATH.'cache/' : $CFG->item('cache_path'); - if (! is_dir($cache_path) OR ! is_really_writable($cache_path)) + if ( ! is_dir($cache_path) OR ! is_really_writable($cache_path)) { return FALSE; } @@ -339,12 +339,12 @@ class CI_Output { $filepath = $cache_path.md5($uri); - if (! @file_exists($filepath)) + if ( ! @file_exists($filepath)) { return FALSE; } - if (! $fp = @fopen($filepath, 'rb')) + if ( ! $fp = @fopen($filepath, 'rb')) { return FALSE; } @@ -361,7 +361,7 @@ class CI_Output { fclose($fp); // Strip out the embedded timestamp - if (! preg_match("/(\d+TS--->)/", $cache, $match)) + if ( ! preg_match("/(\d+TS--->)/", $cache, $match)) { return FALSE; } @@ -383,6 +383,6 @@ class CI_Output { } // END Output Class - -/* End of file Output.php */ + +/* End of file Output.php */ /* Location: ./system/libraries/Output.php */ \ No newline at end of file diff --git a/system/libraries/Pagination.php b/system/libraries/Pagination.php index c3f6bd89c..10af3fd11 100644 --- a/system/libraries/Pagination.php +++ b/system/libraries/Pagination.php @@ -1,4 +1,4 @@ -cur_page)) + if ( ! is_numeric($this->cur_page)) { $this->cur_page = 0; } @@ -215,6 +215,6 @@ class CI_Pagination { } } // END Pagination Class - -/* End of file Pagination.php */ + +/* 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 index f260b2e19..d349e26d3 100644 --- a/system/libraries/Parser.php +++ b/system/libraries/Parser.php @@ -1,4 +1,4 @@ - $val) { - if (! is_array($val)) + if ( ! is_array($val)) { $temp = $this->_parse_single($key, $val, $temp); } @@ -158,7 +158,7 @@ class CI_Parser { */ function _match_pair($string, $variable) { - if (! preg_match("|".$this->l_delim . $variable . $this->r_delim."(.+)".$this->l_delim . '/' . $variable . $this->r_delim."|s", $string, $match)) + if ( ! preg_match("|".$this->l_delim . $variable . $this->r_delim."(.+)".$this->l_delim . '/' . $variable . $this->r_delim."|s", $string, $match)) { return FALSE; } @@ -168,6 +168,6 @@ class CI_Parser { } // END Parser Class - -/* End of file Parser.php */ + +/* End of file Parser.php */ /* Location: ./system/libraries/Parser.php */ \ No newline at end of file diff --git a/system/libraries/Profiler.php b/system/libraries/Profiler.php index fe4fb6d62..da1fff19b 100644 --- a/system/libraries/Profiler.php +++ b/system/libraries/Profiler.php @@ -1,4 +1,4 @@ -'; $output .= "\n"; - if (! class_exists('CI_DB_driver')) + if ( ! class_exists('CI_DB_driver')) { $output .= '  '.$this->CI->lang->line('profiler_queries').'  '; $output .= "\n"; @@ -175,7 +175,7 @@ class CI_Profiler { foreach ($_GET as $key => $val) { - if (! is_numeric($key)) + if ( ! is_numeric($key)) { $key = "'".$key."'"; } @@ -225,7 +225,7 @@ class CI_Profiler { foreach ($_POST as $key => $val) { - if (! is_numeric($key)) + if ( ! is_numeric($key)) { $key = "'".$key."'"; } @@ -340,6 +340,6 @@ class CI_Profiler { } // END CI_Profiler class - -/* End of file Profiler.php */ + +/* End of file Profiler.php */ /* Location: ./system/libraries/Profiler.php */ \ No newline at end of file diff --git a/system/libraries/Router.php b/system/libraries/Router.php index 3b2520dce..6e705f842 100644 --- a/system/libraries/Router.php +++ b/system/libraries/Router.php @@ -1,4 +1,4 @@ -routes = (! isset($route) OR ! is_array($route)) ? array() : $route; + $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']); + $this->default_controller = ( ! isset($this->routes['default_controller']) OR $this->routes['default_controller'] == '') ? FALSE : strtolower($this->routes['default_controller']); // Fetch the complete URI string $this->uri->_fetch_uri_string(); @@ -202,7 +202,7 @@ class CI_Router { if (count($segments) > 0) { // Does the requested controller exist in the sub-folder? - if (! file_exists(APPPATH.'controllers/'.$this->fetch_directory().$segments[0].EXT)) + if ( ! file_exists(APPPATH.'controllers/'.$this->fetch_directory().$segments[0].EXT)) { show_404($this->fetch_directory().$segments[0]); } @@ -213,7 +213,7 @@ class CI_Router { $this->set_method('index'); // Does the default controller exist in the sub-folder? - if (! file_exists(APPPATH.'controllers/'.$this->fetch_directory().$this->default_controller.EXT)) + if ( ! file_exists(APPPATH.'controllers/'.$this->fetch_directory().$this->default_controller.EXT)) { $this->directory = ''; return array(); @@ -374,6 +374,6 @@ class CI_Router { } // END Router Class - -/* End of file Router.php */ + +/* End of file Router.php */ /* Location: ./system/libraries/Router.php */ \ No newline at end of file diff --git a/system/libraries/Session.php b/system/libraries/Session.php index ce1b75e66..31a162e81 100644 --- a/system/libraries/Session.php +++ b/system/libraries/Session.php @@ -1,4 +1,4 @@ -sess_read()) + if ( ! $this->sess_read()) { $this->sess_create(); } @@ -214,7 +214,7 @@ class CI_Session { $session = @unserialize($this->strip_slashes($session)); - if (! is_array($session) OR ! isset($session['last_activity'])) + if ( ! is_array($session) OR ! isset($session['last_activity'])) { log_message('error', 'The session cookie data did not contain a valid array. This could be a possible hacking attempt.'); return FALSE; @@ -439,7 +439,7 @@ class CI_Session { */ function userdata($item) { - return (! isset($this->userdata[$item])) ? FALSE : $this->userdata[$item]; + return ( ! isset($this->userdata[$item])) ? FALSE : $this->userdata[$item]; } // -------------------------------------------------------------------- @@ -452,7 +452,7 @@ class CI_Session { */ function all_userdata() { - return (! isset($this->userdata)) ? FALSE : $this->userdata; + return ( ! isset($this->userdata)) ? FALSE : $this->userdata; } // -------------------------------------------------------------------- @@ -649,6 +649,6 @@ class CI_Session { } // END Session Class - -/* End of file Session.php */ + +/* End of file Session.php */ /* Location: ./system/libraries/Session.php */ \ No newline at end of file diff --git a/system/libraries/Sha1.php b/system/libraries/Sha1.php index a7b9b98d3..71b4ccd0d 100644 --- a/system/libraries/Sha1.php +++ b/system/libraries/Sha1.php @@ -1,4 +1,4 @@ -rows as $row) { - if (! is_array($row)) + if ( ! is_array($row)) { break; } @@ -308,7 +308,7 @@ class CI_Table { */ function _set_from_object($query) { - if (! is_object($query)) + if ( ! is_object($query)) { return FALSE; } @@ -316,7 +316,7 @@ class CI_Table { // First generate the headings from the table column names if (count($this->heading) == 0) { - if (! method_exists($query, 'list_fields')) + if ( ! method_exists($query, 'list_fields')) { return FALSE; } @@ -346,7 +346,7 @@ class CI_Table { */ function _set_from_array($data, $set_heading = TRUE) { - if (! is_array($data) OR count($data) == 0) + if ( ! is_array($data) OR count($data) == 0) { return FALSE; } @@ -354,7 +354,7 @@ class CI_Table { $i = 0; foreach ($data as $row) { - if (! is_array($row)) + if ( ! is_array($row)) { $this->rows[] = $data; break; @@ -393,7 +393,7 @@ class CI_Table { $this->temp = $this->_default_template(); foreach (array('table_open','heading_row_start', 'heading_row_end', 'heading_cell_start', 'heading_cell_end', '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])) + if ( ! isset($this->template[$val])) { $this->template[$val] = $this->temp[$val]; } @@ -435,6 +435,6 @@ class CI_Table { } - -/* End of file Table.php */ + +/* 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 index 41ac5fca8..6696fd2da 100644 --- a/system/libraries/Trackback.php +++ b/system/libraries/Trackback.php @@ -1,4 +1,4 @@ -set_error('The send() method must be passed an array'); return FALSE; @@ -65,7 +65,7 @@ class CI_Trackback { // Pre-process the Trackback Data foreach (array('url', 'title', 'excerpt', 'blog_name', 'ping_url') as $item) { - if (! isset($tb_data[$item])) + if ( ! isset($tb_data[$item])) { $this->set_error('Required item missing: '.$item); return FALSE; @@ -102,7 +102,7 @@ class CI_Trackback { } // Build the Trackback data string - $charset = (! isset($tb_data['charset'])) ? $this->charset : $tb_data['charset']; + $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); @@ -139,13 +139,13 @@ class CI_Trackback { { foreach (array('url', 'title', 'blog_name', 'excerpt') as $val) { - if (! isset($_POST[$val]) OR $_POST[$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'])); + $this->data['charset'] = ( ! isset($_POST['charset'])) ? 'auto' : strtoupper(trim($_POST['charset'])); if ($val != 'url' && function_exists('mb_convert_encoding')) { @@ -212,7 +212,7 @@ class CI_Trackback { */ function data($item) { - return (! isset($this->data[$item])) ? '' : $this->data[$item]; + return ( ! isset($this->data[$item])) ? '' : $this->data[$item]; } // -------------------------------------------------------------------- @@ -233,14 +233,14 @@ class CI_Trackback { $target = parse_url($url); // Open the socket - if (! $fp = @fsockopen($target['host'], 80)) + if ( ! $fp = @fsockopen($target['host'], 80)) { $this->set_error('Invalid Connection: '.$url); return FALSE; } // Build the path - $ppath = (! isset($target['path'])) ? $url : $target['path']; + $ppath = ( ! isset($target['path'])) ? $url : $target['path']; $path = (isset($target['query']) && $target['query'] != "") ? $ppath.'?'.$target['query'] : $ppath; @@ -261,13 +261,13 @@ class CI_Trackback { // Was it successful? $this->response = ""; - while(!feof($fp)) + while( ! feof($fp)) { $this->response .= fgets($fp, 128); } @fclose($fp); - if (! eregi("0", $this->response)) + if ( ! eregi("0", $this->response)) { $message = 'An unknown error was encountered'; @@ -360,7 +360,7 @@ class CI_Trackback { $tb_array = explode('/', $url); $tb_end = $tb_array[count($tb_array)-1]; - if (! is_numeric($tb_end)) + if ( ! is_numeric($tb_end)) { $tb_end = $tb_array[count($tb_array)-2]; } @@ -378,13 +378,13 @@ class CI_Trackback { $tb_array = explode('/', $url); $tb_id = $tb_array[count($tb_array)-1]; - if (! is_numeric($tb_id)) + if ( ! is_numeric($tb_id)) { $tb_id = $tb_array[count($tb_array)-2]; } } - if (! preg_match ("/^([0-9]+)$/", $tb_id)) + if ( ! preg_match ("/^([0-9]+)$/", $tb_id)) { return false; } @@ -439,8 +439,8 @@ class CI_Trackback { { return $str; } - - $str = preg_replace("/\s+/", ' ', preg_replace("/(\r\n|\r|\n)/", " ", $str)); + + $str = preg_replace("/\s+/", ' ', str_replace(array("\r\n", "\r", "\n"), ' ', $str)); if (strlen($str) <= $n) { @@ -545,6 +545,6 @@ class CI_Trackback { } // END Trackback Class - -/* End of file Trackback.php */ + +/* End of file Trackback.php */ /* Location: ./system/libraries/Trackback.php */ \ No newline at end of file diff --git a/system/libraries/URI.php b/system/libraries/URI.php index 26a7b4a33..4d0cd9c17 100644 --- a/system/libraries/URI.php +++ b/system/libraries/URI.php @@ -1,4 +1,4 @@ -config->item('permitted_uri_chars') != '') { - if (! preg_match("|^[".preg_quote($this->config->item('permitted_uri_chars'))."]+$|i", $str)) + if ( ! preg_match("|^[".preg_quote($this->config->item('permitted_uri_chars'))."]+$|i", $str)) { exit('The URI you submitted has disallowed characters.'); } @@ -279,7 +279,7 @@ class CI_URI { */ function segment($n, $no_result = FALSE) { - return (! isset($this->segments[$n])) ? $no_result : $this->segments[$n]; + return ( ! isset($this->segments[$n])) ? $no_result : $this->segments[$n]; } // -------------------------------------------------------------------- @@ -298,7 +298,7 @@ class CI_URI { */ function rsegment($n, $no_result = FALSE) { - return (! isset($this->rsegments[$n])) ? $no_result : $this->rsegments[$n]; + return ( ! isset($this->rsegments[$n])) ? $no_result : $this->rsegments[$n]; } // -------------------------------------------------------------------- @@ -361,7 +361,7 @@ class CI_URI { $segment_array = 'rsegment_array'; } - if (! is_numeric($n)) + if ( ! is_numeric($n)) { return $default; } @@ -410,7 +410,7 @@ class CI_URI { { foreach ($default as $val) { - if (! array_key_exists($val, $retval)) + if ( ! array_key_exists($val, $retval)) { $retval[$val] = FALSE; } @@ -586,6 +586,6 @@ class CI_URI { } // END URI Class - -/* End of file URI.php */ + +/* End of file URI.php */ /* Location: ./system/libraries/URI.php */ \ No newline at end of file diff --git a/system/libraries/Unit_test.php b/system/libraries/Unit_test.php index bfa6d5dc5..e53e04c15 100644 --- a/system/libraries/Unit_test.php +++ b/system/libraries/Unit_test.php @@ -1,4 +1,4 @@ - $file, 'line' => $line); } @@ -302,7 +302,7 @@ class CI_Unit_test { */ function _parse_template() { - if (! is_null($this->_template_rows)) + if ( ! is_null($this->_template_rows)) { return; } @@ -313,7 +313,7 @@ class CI_Unit_test { return; } - if (! preg_match("/\{rows\}(.*?)\{\/rows\}/si", $this->_template, $match)) + if ( ! preg_match("/\{rows\}(.*?)\{\/rows\}/si", $this->_template, $match)) { $this->_default_template(); return; diff --git a/system/libraries/Upload.php b/system/libraries/Upload.php index 07cbd924b..1225ee36b 100644 --- a/system/libraries/Upload.php +++ b/system/libraries/Upload.php @@ -1,4 +1,4 @@ -set_error('upload_no_file_selected'); return FALSE; } // Is the upload path valid? - if (! $this->validate_upload_path()) + if ( ! $this->validate_upload_path()) { // errors will already be set by validate_upload_path() so just return FALSE return FALSE; } // Was the file able to be uploaded? If not, determine the reason why. - if (! is_uploaded_file($_FILES[$field]['tmp_name'])) + if ( ! is_uploaded_file($_FILES[$field]['tmp_name'])) { - $error = (! isset($_FILES[$field]['error'])) ? 4 : $_FILES[$field]['error']; + $error = ( ! isset($_FILES[$field]['error'])) ? 4 : $_FILES[$field]['error']; switch($error) { @@ -198,14 +198,14 @@ class CI_Upload { } // Is the file type allowed to be uploaded? - if (! $this->is_allowed_filetype()) + if ( ! $this->is_allowed_filetype()) { $this->set_error('upload_invalid_filetype'); return FALSE; } // Is the file size within the allowed maximum? - if (! $this->is_allowed_filesize()) + if ( ! $this->is_allowed_filesize()) { $this->set_error('upload_invalid_filesize'); return FALSE; @@ -213,7 +213,7 @@ class CI_Upload { // Are the image dimensions within the allowed size? // Note: This can fail if the server has an open_basdir restriction. - if (! $this->is_allowed_dimensions()) + if ( ! $this->is_allowed_dimensions()) { $this->set_error('upload_invalid_dimensions'); return FALSE; @@ -253,9 +253,9 @@ class CI_Upload { * we'll use move_uploaded_file(). One of the two should * reliably work in most environments */ - if (! @copy($this->file_temp, $this->upload_path.$this->file_name)) + if ( ! @copy($this->file_temp, $this->upload_path.$this->file_name)) { - if (! @move_uploaded_file($this->file_temp, $this->upload_path.$this->file_name)) + if ( ! @move_uploaded_file($this->file_temp, $this->upload_path.$this->file_name)) { $this->set_error('upload_destination_error'); return FALSE; @@ -350,7 +350,7 @@ class CI_Upload { $filename = md5(uniqid(mt_rand())).$this->file_ext; } - if (! file_exists($path.$filename)) + if ( ! file_exists($path.$filename)) { return $filename; } @@ -360,7 +360,7 @@ class CI_Upload { $new_filename = ''; for ($i = 1; $i < 100; $i++) { - if (! file_exists($path.$filename.$i.$this->file_ext)) + if ( ! file_exists($path.$filename.$i.$this->file_ext)) { $new_filename = $filename.$i.$this->file_ext; break; @@ -389,7 +389,7 @@ class CI_Upload { */ function set_max_filesize($n) { - $this->max_size = (! eregi("^[[:digit:]]+$", $n)) ? 0 : $n; + $this->max_size = ( ! eregi("^[[:digit:]]+$", $n)) ? 0 : $n; } // -------------------------------------------------------------------- @@ -403,7 +403,7 @@ class CI_Upload { */ function set_max_width($n) { - $this->max_width = (! eregi("^[[:digit:]]+$", $n)) ? 0 : $n; + $this->max_width = ( ! eregi("^[[:digit:]]+$", $n)) ? 0 : $n; } // -------------------------------------------------------------------- @@ -417,7 +417,7 @@ class CI_Upload { */ function set_max_height($n) { - $this->max_height = (! eregi("^[[:digit:]]+$", $n)) ? 0 : $n; + $this->max_height = ( ! eregi("^[[:digit:]]+$", $n)) ? 0 : $n; } // -------------------------------------------------------------------- @@ -447,7 +447,7 @@ class CI_Upload { */ function set_image_properties($path = '') { - if (! $this->is_image()) + if ( ! $this->is_image()) { return; } @@ -460,7 +460,7 @@ class CI_Upload { $this->image_width = $D['0']; $this->image_height = $D['1']; - $this->image_type = (! isset($types[$D['2']])) ? 'unknown' : $types[$D['2']]; + $this->image_type = ( ! isset($types[$D['2']])) ? 'unknown' : $types[$D['2']]; $this->image_size_str = $D['3']; // string containing height and width } } @@ -528,7 +528,7 @@ class CI_Upload { */ function is_allowed_filetype() { - if (count($this->allowed_types) == 0 || ! is_array($this->allowed_types)) + if (count($this->allowed_types) == 0 OR ! is_array($this->allowed_types)) { $this->set_error('upload_no_file_types'); return FALSE; @@ -587,7 +587,7 @@ class CI_Upload { */ function is_allowed_dimensions() { - if (! $this->is_image()) + if ( ! $this->is_image()) { return TRUE; } @@ -636,13 +636,13 @@ class CI_Upload { $this->upload_path = str_replace("\\", "/", realpath($this->upload_path)); } - if (! @is_dir($this->upload_path)) + if ( ! @is_dir($this->upload_path)) { $this->set_error('upload_no_filepath'); return FALSE; } - if (! is_really_writable($this->upload_path)) + if ( ! is_really_writable($this->upload_path)) { $this->set_error('upload_not_writable'); return FALSE; @@ -741,7 +741,7 @@ class CI_Upload { return FALSE; } - if (! $fp = @fopen($file, FOPEN_READ_WRITE)) + if ( ! $fp = @fopen($file, FOPEN_READ_WRITE)) { return FALSE; } @@ -830,7 +830,7 @@ class CI_Upload { } } - return (! isset($this->mimes[$mime])) ? FALSE : $this->mimes[$mime]; + return ( ! isset($this->mimes[$mime])) ? FALSE : $this->mimes[$mime]; } /** @@ -875,6 +875,6 @@ class CI_Upload { } // END Upload Class - -/* End of file Upload.php */ + +/* End of file Upload.php */ /* Location: ./system/libraries/Upload.php */ \ No newline at end of file diff --git a/system/libraries/User_agent.php b/system/libraries/User_agent.php index ee1839277..86b249ccd 100644 --- a/system/libraries/User_agent.php +++ b/system/libraries/User_agent.php @@ -1,4 +1,4 @@ -agent = trim($_SERVER['HTTP_USER_AGENT']); } - if (! is_null($this->agent)) + if ( ! is_null($this->agent)) { if ($this->_load_agent_file()) { @@ -84,7 +84,7 @@ class CI_User_agent { */ function _load_agent_file() { - if (! @include(APPPATH.'config/user_agents'.EXT)) + if ( ! @include(APPPATH.'config/user_agents'.EXT)) { return FALSE; } @@ -339,7 +339,7 @@ class CI_User_agent { */ function is_referral() { - return (! isset($_SERVER['HTTP_REFERER']) OR $_SERVER['HTTP_REFERER'] == '') ? FALSE : TRUE; + return ( ! isset($_SERVER['HTTP_REFERER']) OR $_SERVER['HTTP_REFERER'] == '') ? FALSE : TRUE; } // -------------------------------------------------------------------- @@ -429,7 +429,7 @@ class CI_User_agent { */ function referrer() { - return (! isset($_SERVER['HTTP_REFERER']) OR $_SERVER['HTTP_REFERER'] == '') ? '' : trim($_SERVER['HTTP_REFERER']); + return ( ! isset($_SERVER['HTTP_REFERER']) OR $_SERVER['HTTP_REFERER'] == '') ? '' : trim($_SERVER['HTTP_REFERER']); } // -------------------------------------------------------------------- @@ -497,6 +497,6 @@ class CI_User_agent { } - -/* End of file User_agent.php */ + +/* End of file User_agent.php */ /* Location: ./system/libraries/User_agent.php */ \ No newline at end of file diff --git a/system/libraries/Validation.php b/system/libraries/Validation.php index a0f038c02..9654b4f4e 100644 --- a/system/libraries/Validation.php +++ b/system/libraries/Validation.php @@ -1,4 +1,4 @@ - $field); } @@ -87,10 +87,10 @@ class CI_Validation { foreach($this->_fields as $key => $val) { - $this->$key = (! isset($_POST[$key])) ? '' : $this->prep_for_form($_POST[$key]); + $this->$key = ( ! isset($_POST[$key])) ? '' : $this->prep_for_form($_POST[$key]); $error = $key.'_error'; - if (! isset($this->$error)) + if ( ! isset($this->$error)) { $this->$error = ''; } @@ -112,7 +112,7 @@ class CI_Validation { */ function set_rules($data, $rules = '') { - if (! is_array($data)) + if ( ! is_array($data)) { if ($rules == '') return; @@ -141,7 +141,7 @@ class CI_Validation { */ function set_message($lang, $val = '') { - if (! is_array($lang)) + if ( ! is_array($lang)) { $lang = array($lang => $val); } @@ -195,9 +195,9 @@ class CI_Validation { $ex = explode('|', $rules); // Is the field required? If not, if the field is blank we'll move on to the next test - if (! in_array('required', $ex, TRUE)) + if ( ! in_array('required', $ex, TRUE)) { - if (! isset($_POST[$field]) OR $_POST[$field] == '') + if ( ! isset($_POST[$field]) OR $_POST[$field] == '') { continue; } @@ -212,11 +212,11 @@ class CI_Validation { * test for it here since there's not reason to go * further */ - if (! isset($_POST[$field])) + if ( ! isset($_POST[$field])) { if (in_array('isset', $ex, TRUE) OR in_array('required', $ex)) { - if (! isset($this->_error_messages['isset'])) + if ( ! isset($this->_error_messages['isset'])) { if (FALSE === ($line = $this->CI->lang->line('isset'))) { @@ -229,7 +229,7 @@ class CI_Validation { } // Build the error message - $mfield = (! isset($this->_fields[$field])) ? $field : $this->_fields[$field]; + $mfield = ( ! isset($this->_fields[$field])) ? $field : $this->_fields[$field]; $message = sprintf($line, $mfield); // Set the error variable. Example: $this->username_error @@ -274,7 +274,7 @@ class CI_Validation { // Call the function that corresponds to the rule if ($callback === TRUE) { - if (! method_exists($this->CI, $rule)) + if ( ! method_exists($this->CI, $rule)) { continue; } @@ -282,7 +282,7 @@ class CI_Validation { $result = $this->CI->$rule($_POST[$field], $param); // If the field isn't required and we just processed a callback we'll move on... - if (! in_array('required', $ex, TRUE) AND $result !== FALSE) + if ( ! in_array('required', $ex, TRUE) AND $result !== FALSE) { continue 2; } @@ -290,7 +290,7 @@ class CI_Validation { } else { - if (! method_exists($this, $rule)) + if ( ! method_exists($this, $rule)) { /* * Run the native PHP function if called for @@ -314,7 +314,7 @@ class CI_Validation { // Did the rule test negatively? If so, grab the error. if ($result === FALSE) { - if (! isset($this->_error_messages[$rule])) + if ( ! isset($this->_error_messages[$rule])) { if (FALSE === ($line = $this->CI->lang->line($rule))) { @@ -327,8 +327,8 @@ class CI_Validation { } // Build the error message - $mfield = (! isset($this->_fields[$field])) ? $field : $this->_fields[$field]; - $mparam = (! isset($this->_fields[$param])) ? $param : $this->_fields[$param]; + $mfield = ( ! isset($this->_fields[$field])) ? $field : $this->_fields[$field]; + $mparam = ( ! isset($this->_fields[$param])) ? $param : $this->_fields[$param]; $message = sprintf($line, $mfield, $mparam); // Set the error variable. Example: $this->username_error @@ -385,13 +385,13 @@ class CI_Validation { */ function required($str) { - if (! is_array($str)) + if ( ! is_array($str)) { return (trim($str) == '') ? FALSE : TRUE; } else { - return (! empty($str)); + return ( ! empty($str)); } } @@ -406,7 +406,7 @@ class CI_Validation { */ function matches($str, $field) { - if (! isset($_POST[$field])) + if ( ! isset($_POST[$field])) { return FALSE; } @@ -482,7 +482,7 @@ class CI_Validation { */ function valid_email($str) { - return (! preg_match("/^([a-z0-9\+_\-]+)(\.[a-z0-9\+_\-]+)*@([a-z0-9\-]+\.)+[a-z]{2,6}$/ix", $str)) ? FALSE : TRUE; + return ( ! preg_match("/^([a-z0-9\+_\-]+)(\.[a-z0-9\+_\-]+)*@([a-z0-9\-]+\.)+[a-z]{2,6}$/ix", $str)) ? FALSE : TRUE; } // -------------------------------------------------------------------- @@ -537,7 +537,7 @@ class CI_Validation { */ function alpha($str) { - return (! preg_match("/^([a-z])+$/i", $str)) ? FALSE : TRUE; + return ( ! preg_match("/^([a-z])+$/i", $str)) ? FALSE : TRUE; } // -------------------------------------------------------------------- @@ -551,7 +551,7 @@ class CI_Validation { */ function alpha_numeric($str) { - return (! preg_match("/^([a-z0-9])+$/i", $str)) ? FALSE : TRUE; + return ( ! preg_match("/^([a-z0-9])+$/i", $str)) ? FALSE : TRUE; } // -------------------------------------------------------------------- @@ -565,7 +565,7 @@ class CI_Validation { */ function alpha_dash($str) { - return (! preg_match("/^([-a-z0-9_-])+$/i", $str)) ? FALSE : TRUE; + return ( ! preg_match("/^([-a-z0-9_-])+$/i", $str)) ? FALSE : TRUE; } // -------------------------------------------------------------------- @@ -594,7 +594,7 @@ class CI_Validation { */ function is_numeric($str) { - return (! is_numeric($str)) ? FALSE : TRUE; + return ( ! is_numeric($str)) ? FALSE : TRUE; } // -------------------------------------------------------------------- diff --git a/system/libraries/Xmlrpc.php b/system/libraries/Xmlrpc.php index 32d739689..1748ab833 100644 --- a/system/libraries/Xmlrpc.php +++ b/system/libraries/Xmlrpc.php @@ -1,4 +1,4 @@ -client) && is_int($seconds)) + if ( ! is_null($this->client) && is_int($seconds)) { $this->client->timeout = $seconds; } @@ -199,7 +199,7 @@ class CI_Xmlrpc { function request($incoming) { - if (! is_array($incoming)) + if ( ! is_array($incoming)) { // Send Error } @@ -231,7 +231,7 @@ class CI_Xmlrpc { { if (is_array($value) && isset($value['0'])) { - if (! isset($value['1']) OR ! isset($this->xmlrpcTypes[strtolower($value['1'])])) + if ( ! isset($value['1']) OR ! isset($this->xmlrpcTypes[strtolower($value['1'])])) { if (is_array($value[0])) { @@ -275,12 +275,12 @@ class CI_Xmlrpc { $this->message = new XML_RPC_Message($this->method,$this->data); $this->message->debug = $this->debug; - if (! $this->result = $this->client->send($this->message)) + if ( ! $this->result = $this->client->send($this->message)) { $this->error = $this->result->errstr; return FALSE; } - elseif(! is_object($this->result->val)) + elseif( ! is_object($this->result->val)) { $this->error = $this->result->errstr; return FALSE; @@ -384,7 +384,7 @@ class XML_RPC_Client extends CI_Xmlrpc { $fp = @fsockopen($this->server, $this->port,$this->errno, $this->errstr, $this->timeout); - if (! is_resource($fp)) + if ( ! is_resource($fp)) { error_log($this->xmlrpcstr['http_error']); $r = new XML_RPC_Response(0, $this->xmlrpcerr['http_error'],$this->xmlrpcstr['http_error']); @@ -406,7 +406,7 @@ class XML_RPC_Client extends CI_Xmlrpc $op .= $msg->payload; - if (!fputs($fp, $op, strlen($op))) + if ( ! fputs($fp, $op, strlen($op))) { error_log($this->xmlrpcstr['http_error']); $r = new XML_RPC_Response(0, $this->xmlrpcerr['http_error'], $this->xmlrpcstr['http_error']); @@ -442,7 +442,7 @@ class XML_RPC_Response $this->errno = $code; $this->errstr = htmlentities($fstr); } - else if (!is_object($val)) + else if ( ! is_object($val)) { // programmer error, not an object error_log("Invalid type '" . gettype($val) . "' (value: $val) passed to XML_RPC_Response. Defaulting to empty value."); @@ -737,7 +737,7 @@ class XML_RPC_Message extends CI_Xmlrpc // PARSE XML DATA //------------------------------------- - if (!xml_parse($parser, $data, sizeof($data))) + if ( ! xml_parse($parser, $data, sizeof($data))) { $errstr = sprintf('XML error: %s at line %d', xml_error_string(xml_get_error_code($parser)), @@ -765,7 +765,7 @@ class XML_RPC_Message extends CI_Xmlrpc $r = new XML_RPC_Response(0, $this->xmlrpcerr['invalid_return'],$this->xmlrpcstr['invalid_return'].' '.$this->xh[$parser]['isf_reason']); return $r; } - elseif (! is_object($this->xh[$parser]['value'])) + elseif ( ! is_object($this->xh[$parser]['value'])) { $r = new XML_RPC_Response(0, $this->xmlrpcerr['invalid_return'],$this->xmlrpcstr['invalid_return'].' '.$this->xh[$parser]['isf_reason']); return $r; @@ -862,7 +862,7 @@ class XML_RPC_Message extends CI_Xmlrpc else { // not top level element: see if parent is OK - if (!in_array($this->xh[$the_parser]['stack'][0], $this->valid_parents[$name], TRUE)) + if ( ! in_array($this->xh[$the_parser]['stack'][0], $this->valid_parents[$name], TRUE)) { $this->xh[$the_parser]['isf'] = 2; $this->xh[$the_parser]['isf_reason'] = "XML-RPC element $name cannot be child of ".$this->xh[$the_parser]['stack'][0]; @@ -961,7 +961,7 @@ class XML_RPC_Message extends CI_Xmlrpc case 'STRUCT': case 'ARRAY': $cur_val = array_shift($this->xh[$the_parser]['valuestack']); - $this->xh[$the_parser]['value'] = (! isset($cur_val['values'])) ? array() : $cur_val['values']; + $this->xh[$the_parser]['value'] = ( ! isset($cur_val['values'])) ? array() : $cur_val['values']; $this->xh[$the_parser]['vt'] = strtolower($name); break; case 'NAME': @@ -1005,7 +1005,7 @@ class XML_RPC_Message extends CI_Xmlrpc { // we have a DOUBLE // we must check that only 0123456789-. are characters here - if (! preg_match('/^[+-]?[eE0-9\t \.]+$/', $this->xh[$the_parser]['ac'])) + if ( ! preg_match('/^[+-]?[eE0-9\t \.]+$/', $this->xh[$the_parser]['ac'])) { $this->xh[$the_parser]['value'] = 'ERROR_NON_NUMERIC_FOUND'; } @@ -1018,7 +1018,7 @@ class XML_RPC_Message extends CI_Xmlrpc { // we have an I4/INT // we must check that only 0123456789- are characters here - if (! preg_match('/^[+-]?[0-9\t ]+$/', $this->xh[$the_parser]['ac'])) + if ( ! preg_match('/^[+-]?[0-9\t ]+$/', $this->xh[$the_parser]['ac'])) { $this->xh[$the_parser]['value'] = 'ERROR_NON_NUMERIC_FOUND'; } @@ -1101,7 +1101,7 @@ class XML_RPC_Message extends CI_Xmlrpc $this->xh[$the_parser]['lv'] = 2; // Found a value } - if(! @isset($this->xh[$the_parser]['ac'])) + if( ! @isset($this->xh[$the_parser]['ac'])) { $this->xh[$the_parser]['ac'] = ''; } @@ -1213,7 +1213,7 @@ class XML_RPC_Values extends CI_Xmlrpc { parent::CI_Xmlrpc(); - if ($val != -1 || $type != '') + if ($val != -1 OR $type != '') { $type = $type == '' ? 'string' : $type; @@ -1250,7 +1250,7 @@ class XML_RPC_Values extends CI_Xmlrpc if ($type == $this->xmlrpcBoolean) { - if (strcasecmp($val,'true')==0 || $val==1 || ($val==true && strcasecmp($val,'false'))) + if (strcasecmp($val,'true')==0 OR $val==1 OR ($val==true && strcasecmp($val,'false'))) { $val = 1; } diff --git a/system/libraries/Xmlrpcs.php b/system/libraries/Xmlrpcs.php index 754b8ae26..a9cf19d2c 100644 --- a/system/libraries/Xmlrpcs.php +++ b/system/libraries/Xmlrpcs.php @@ -1,4 +1,4 @@ -methods[$methName]['function'])) + if ( ! isset($this->methods[$methName]['function'])) { return new XML_RPC_Response(0, $this->xmlrpcerr['unknown_method'], $this->xmlrpcstr['unknown_method']); } @@ -265,18 +265,18 @@ class CI_Xmlrpcs extends CI_Xmlrpc if ($system_call === TRUE) { - if (! is_callable(array($this,$method_parts['1']))) + 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']))) + 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'])) + elseif ( ! $objectCall && ! is_callable($this->methods[$methName]['function'])) { return new XML_RPC_Response(0, $this->xmlrpcerr['unknown_method'], $this->xmlrpcstr['unknown_method']); } @@ -494,17 +494,17 @@ class CI_Xmlrpcs extends CI_Xmlrpc { if ($call->kindOf() != 'struct') return $this->multicall_error('notstruct'); - elseif (!$methName = $call->me['struct']['methodName']) + 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' || $scalar_type != 'string') + 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']) + elseif ( ! $params = $call->me['struct']['params']) return $this->multicall_error('noparams'); elseif ($params->kindOf() != 'array') return $this->multicall_error('notarray'); @@ -531,6 +531,6 @@ class CI_Xmlrpcs extends CI_Xmlrpc } // END XML_RPC_Server class - -/* End of file Xmlrpcs.php */ + +/* 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 index 5a24e4057..97695a07f 100644 --- a/system/libraries/Zip.php +++ b/system/libraries/Zip.php @@ -1,4 +1,4 @@ - $val) { - if (! is_array($data)) + if ( ! is_array($data)) { - if (! isset($$key) OR $$key == '') + if ( ! isset($$key) OR $$key == '') { $$key = $val; } } else { - $$key = (! isset($data[$key])) ? $val : $data[$key]; + $$key = ( ! isset($data[$key])) ? $val : $data[$key]; } } @@ -175,17 +175,17 @@ function create_captcha($data = '', $img_path = '', $img_url = '', $font_path = return FALSE; } - if (! @is_dir($img_path)) + if ( ! @is_dir($img_path)) { return FALSE; } - if (! is_really_writable($img_path)) + if ( ! is_really_writable($img_path)) { return FALSE; } - if (! extension_loaded('gd')) + if ( ! extension_loaded('gd')) { return FALSE; } @@ -351,6 +351,6 @@ function create_captcha($data = '', $img_path = '', $img_url = '', $font_path = return array('word' => $word, 'time' => $now, 'image' => $img); } - -/* End of file captcha_pi.php */ + +/* End of file captcha_pi.php */ /* Location: ./system/plugins/captcha_pi.php */ \ No newline at end of file diff --git a/system/plugins/js_calendar_pi.php b/system/plugins/js_calendar_pi.php index 6bb3b3629..964d50315 100644 --- a/system/plugins/js_calendar_pi.php +++ b/system/plugins/js_calendar_pi.php @@ -1,4 +1,4 @@ - 12) newMonth = 12; @@ -396,7 +396,7 @@ function update_calendar(id, dateValue) switch(newMonth - 1) { case 1: // Check for leap year - if ((newYear % 4 == 0 && newYear % 100 != 0) || newYear % 400 == 0) + if ((newYear % 4 == 0 && newYear % 100 != 0) OR newYear % 400 == 0) { if (newDay > 29) newDay = 29; } @@ -541,7 +541,7 @@ function change_month(mo, cal) switch(newMonth) { case 1: // Check for leap year - if ((newYear % 4 == 0 && newYear % 100 != 0) || newYear % 400 == 0) + if ((newYear % 4 == 0 && newYear % 100 != 0) OR newYear % 400 == 0) { if (newDate > 29) newDate = 29; } @@ -624,6 +624,6 @@ function js_calendar_write($field_id, $time = '', $highlight = TRUE) '; } - -/* End of file js_calendar_pi.php */ + +/* End of file js_calendar_pi.php */ /* Location: ./system/plugins/js_calendar_pi.php */ \ No newline at end of file diff --git a/system/scaffolding/Scaffolding.php b/system/scaffolding/Scaffolding.php index 807a3d76a..89a9ed4cf 100644 --- a/system/scaffolding/Scaffolding.php +++ b/system/scaffolding/Scaffolding.php @@ -1,4 +1,4 @@ - (! isset($this->lang['scaff_add'])) ? 'Add Data' : $this->lang['scaff_add'], + 'title' => ( ! isset($this->lang['scaff_add'])) ? 'Add Data' : $this->lang['scaff_add'], 'fields' => $this->CI->db->field_data($this->current_table), 'action' => $this->base_uri.'/insert' ); @@ -172,7 +172,7 @@ class Scaffolding { ); $data = array( - 'title' => (! isset($this->lang['scaff_view'])) ? 'View Data' : $this->lang['scaff_view'], + 'title' => ( ! isset($this->lang['scaff_view'])) ? 'View Data' : $this->lang['scaff_view'], 'query' => $query, 'fields' => $fields, 'primary' => $primary, @@ -207,7 +207,7 @@ class Scaffolding { $query = $this->CI->db->get_where($this->current_table, array($primary => $id)); $data = array( - 'title' => (! isset($this->lang['scaff_edit'])) ? 'Edit Data' : $this->lang['scaff_edit'], + 'title' => ( ! isset($this->lang['scaff_edit'])) ? 'Edit Data' : $this->lang['scaff_edit'], 'fields' => $query->field_data(), 'query' => $query->row(), 'action' => $this->base_uri.'/update/'.$this->CI->uri->segment(4) @@ -245,7 +245,7 @@ class Scaffolding { */ function delete() { - if (! isset($this->lang['scaff_del_confirm'])) + if ( ! isset($this->lang['scaff_del_confirm'])) { $message = 'Are you sure you want to delete the following row: '.$this->CI->uri->segment(4); } @@ -255,10 +255,10 @@ class Scaffolding { } $data = array( - 'title' => (! isset($this->lang['scaff_delete'])) ? 'Delete Data' : $this->lang['scaff_delete'], + 'title' => ( ! isset($this->lang['scaff_delete'])) ? 'Delete Data' : $this->lang['scaff_delete'], 'message' => $message, - 'no' => anchor(array($this->base_uri, 'view'), (! isset($this->lang['scaff_no'])) ? 'No' : $this->lang['scaff_no']), - 'yes' => anchor(array($this->base_uri, 'do_delete', $this->CI->uri->segment(4)), (! isset($this->lang['scaff_yes'])) ? 'Yes' : $this->lang['scaff_yes']) + 'no' => anchor(array($this->base_uri, 'view'), ( ! isset($this->lang['scaff_no'])) ? 'No' : $this->lang['scaff_no']), + 'yes' => anchor(array($this->base_uri, 'do_delete', $this->CI->uri->segment(4)), ( ! isset($this->lang['scaff_yes'])) ? 'Yes' : $this->lang['scaff_yes']) ); $this->CI->load->view('delete', $data); @@ -286,6 +286,6 @@ class Scaffolding { } } - -/* End of file Scaffolding.php */ + +/* End of file Scaffolding.php */ /* Location: ./system/scaffolding/Scaffolding.php */ \ No newline at end of file -- cgit v1.2.3-24-g4f1b From 1b7ef4f19a903b4aedd16a2863e882802962752d Mon Sep 17 00:00:00 2001 From: Derek Jones Date: Tue, 13 May 2008 04:23:20 +0000 Subject: reverted OR back to || for js_calendar_pi.php javascript --- system/plugins/js_calendar_pi.php | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'system') diff --git a/system/plugins/js_calendar_pi.php b/system/plugins/js_calendar_pi.php index 964d50315..d75b77371 100644 --- a/system/plugins/js_calendar_pi.php +++ b/system/plugins/js_calendar_pi.php @@ -274,7 +274,7 @@ function total_days() case 1: // Check for leap year if (( this.date_obj.getFullYear() % 4 == 0 && this.date_obj.getFullYear() % 100 != 0) - OR this.date_obj.getFullYear() % 400 == 0) + || this.date_obj.getFullYear() % 400 == 0) return 29; else return 28; @@ -385,9 +385,9 @@ function update_calendar(id, dateValue) var newMonth = dateParts[1]; var newDay = dateParts[2]; - if (isNaN(newDay) OR newDay < 1 OR (newDay.length != 1 && newDay.length != 2)) return; - if (isNaN(newYear) OR newYear < 1 OR newYear.length != 4) return; - if (isNaN(newMonth) OR newMonth < 1 OR (newMonth.length != 1 && newMonth.length != 2)) return; + if (isNaN(newDay) || newDay < 1 || (newDay.length != 1 && newDay.length != 2)) return; + if (isNaN(newYear) || newYear < 1 || newYear.length != 4) return; + if (isNaN(newMonth) || newMonth < 1 || (newMonth.length != 1 && newMonth.length != 2)) return; if (newMonth > 12) newMonth = 12; @@ -396,7 +396,7 @@ function update_calendar(id, dateValue) switch(newMonth - 1) { case 1: // Check for leap year - if ((newYear % 4 == 0 && newYear % 100 != 0) OR newYear % 400 == 0) + if ((newYear % 4 == 0 && newYear % 100 != 0) || newYear % 400 == 0) { if (newDay > 29) newDay = 29; } @@ -541,7 +541,7 @@ function change_month(mo, cal) switch(newMonth) { case 1: // Check for leap year - if ((newYear % 4 == 0 && newYear % 100 != 0) OR newYear % 400 == 0) + if ((newYear % 4 == 0 && newYear % 100 != 0) || newYear % 400 == 0) { if (newDate > 29) newDate = 29; } -- cgit v1.2.3-24-g4f1b From 687cdcaa4bc45a616308e3ecdf735d87065153a5 Mon Sep 17 00:00:00 2001 From: Derek Allard Date: Tue, 13 May 2008 11:46:39 +0000 Subject: removed some stray testing code --- system/application/controllers/welcome.php | 34 +++++++++++++--------------- system/application/views/welcome_message.php | 6 +---- 2 files changed, 17 insertions(+), 23 deletions(-) (limited to 'system') diff --git a/system/application/controllers/welcome.php b/system/application/controllers/welcome.php index 9ab91d039..ec16000df 100644 --- a/system/application/controllers/welcome.php +++ b/system/application/controllers/welcome.php @@ -1,19 +1,17 @@ -load->view('welcome_message'); - $this->load->view('fake'); - - } -} - -/* End of file welcome.php */ +load->view('welcome_message'); + } +} + +/* End of file welcome.php */ /* Location: ./system/application/controllers/welcome.php */ \ No newline at end of file diff --git a/system/application/views/welcome_message.php b/system/application/views/welcome_message.php index 40997b6b2..8313059e4 100644 --- a/system/application/views/welcome_message.php +++ b/system/application/views/welcome_message.php @@ -59,8 +59,4 @@ code {


    Page rendered in {elapsed_time} seconds

    - - \ No newline at end of file -- cgit v1.2.3-24-g4f1b From a065bab0fb0fdd6c0012db137ab8e065b131a2e9 Mon Sep 17 00:00:00 2001 From: Derek Allard Date: Tue, 13 May 2008 13:31:18 +0000 Subject: The Zip class has undergone a substantial re-write for speed and clarity --- system/libraries/Zip.php | 221 ++++++++++++++++++++++------------------------- 1 file changed, 101 insertions(+), 120 deletions(-) (limited to 'system') diff --git a/system/libraries/Zip.php b/system/libraries/Zip.php index 97695a07f..ed476ab48 100644 --- a/system/libraries/Zip.php +++ b/system/libraries/Zip.php @@ -32,9 +32,10 @@ */ class CI_Zip { - var $zipfile = ''; - var $zipdata = array(); - var $directory = array(); + var $zipdata = ''; + var $directory = ''; + var $entries = 0; + var $file_num = 0; var $offset = 0; function CI_Zip() @@ -61,7 +62,7 @@ class CI_Zip { { $dir .= '/'; } - + $this->_add_dir($dir); } } @@ -78,35 +79,36 @@ class CI_Zip { function _add_dir($dir) { $dir = str_replace("\\", "/", $dir); - - $this->zipdata[] = "\x50\x4b\x03\x04\x0a\x00\x00\x00\x00\x00\x00\x00\x00\x00" - .pack('V', 0) - .pack('V', 0) - .pack('V', 0) - .pack('v', strlen($dir)) - .pack('v', 0) - .$dir - .pack('V', 0) - .pack('V', 0) - .pack('V', 0); - - $newoffset = strlen(implode('', $this->zipdata)); - - $record = "\x50\x4b\x01\x02\x00\x00\x0a\x00\x00\x00\x00\x00\x00\x00\x00\x00" - .pack('V',0) - .pack('V',0) - .pack('V',0) - .pack('v', strlen($dir)) - .pack('v', 0) - .pack('v', 0) - .pack('v', 0) - .pack('v', 0) - .pack('V', 16) - .pack('V', $this->offset) - .$dir; - - $this->offset = $newoffset; - $this->directory[] = $record; + + $this->zipdata .= + "\x50\x4b\x03\x04\x0a\x00\x00\x00\x00\x00\x00\x00\x00\x00" + .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\x00\x00\x00\x00" + .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++; } // -------------------------------------------------------------------- @@ -137,7 +139,7 @@ class CI_Zip { $this->_add_data($filepath, $data); } } - + // -------------------------------------------------------------------- /** @@ -149,41 +151,43 @@ class CI_Zip { * @return void */ function _add_data($filepath, $data) - { + { $filepath = str_replace("\\", "/", $filepath); - - $oldlen = strlen($data); - $crc32 = crc32($data); - + + $uncompressed_size = strlen($data); + $crc32 = crc32($data); + $gzdata = gzcompress($data); $gzdata = substr($gzdata, 2, -4); - $newlen = strlen($gzdata); - - $this->zipdata[] = "\x50\x4b\x03\x04\x14\x00\x00\x00\x08\x00\x00\x00\x00\x00" - .pack('V', $crc32) - .pack('V', $newlen) - .pack('V', $oldlen) - .pack('v', strlen($filepath)) - .pack('v', 0) - .$filepath - .$gzdata; - - $newoffset = strlen(implode("", $this->zipdata)); - - $record = "\x50\x4b\x01\x02\x00\x00\x14\x00\x00\x00\x08\x00\x00\x00\x00\x00" - .pack('V', $crc32) - .pack('V', $newlen) - .pack('V', $oldlen) - .pack('v', strlen($filepath)) - .pack('v', 0) - .pack('v', 0) - .pack('v', 0) - .pack('v', 0) - .pack('V', 32) - .pack('V', $this->offset); - - $this->offset = $newoffset; - $this->directory[] = $record.$filepath; + $compressed_size = strlen($gzdata); + + $this->zipdata .= + "\x50\x4b\x03\x04\x14\x00\x00\x00\x08\x00\x00\x00\x00\x00" + .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\x00\x00\x00\x00" + .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++; } // -------------------------------------------------------------------- @@ -200,7 +204,7 @@ class CI_Zip { { return FALSE; } - + if (FALSE !== ($data = file_get_contents($path))) { $name = str_replace("\\", "/", $path); @@ -209,7 +213,7 @@ class CI_Zip { { $name = preg_replace("|.*/(.+)|", "\\1", $name); } - + $this->add_data($name, $data); return TRUE; } @@ -261,30 +265,21 @@ class CI_Zip { */ function get_zip() { - // We cache the zip data so multiple calls - // do not require recompiling - if ($this->zipfile != '') - { - return $this->zipfile; - } - // Is there any data to return? - if (count($this->zipdata) == 0) + if ($this->entries == 0) { return FALSE; } - - $data = implode('', $this->zipdata); - $dir = implode('', $this->directory); - - $this->zipfile = $data.$dir."\x50\x4b\x05\x06\x00\x00\x00\x00" - .pack('v', sizeof($this->directory)) - .pack('v', sizeof($this->directory)) - .pack('V', strlen($dir)) - .pack('V', strlen($data)) - ."\x00\x00"; - - return $this->zipfile; + + $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; } // -------------------------------------------------------------------- @@ -305,7 +300,7 @@ class CI_Zip { { return FALSE; } - + flock($fp, LOCK_EX); fwrite($fp, $this->get_zip()); flock($fp, LOCK_UN); @@ -323,35 +318,20 @@ class CI_Zip { * @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'; - } - - if (strstr($_SERVER['HTTP_USER_AGENT'], "MSIE")) - { - header('Content-Type: application/x-zip'); - header('Content-Disposition: inline; filename="'.$filename.'"'); - header('Expires: 0'); - header('Cache-Control: must-revalidate, post-check=0, pre-check=0'); - header("Content-Transfer-Encoding: binary"); - header('Pragma: public'); - header("Content-Length: ".strlen($this->get_zip())); - } - else - { - header('Content-Type: application/x-zip'); - header('Content-Disposition: attachment; filename="'.$filename.'"'); - header("Content-Transfer-Encoding: binary"); - header('Expires: 0'); - header('Pragma: no-cache'); - header("Content-Length: ".strlen($this->get_zip())); - } - - exit($this->get_zip()); + if ( ! preg_match("|.+?\.zip$|", $filename)) + { + $filename .= '.zip'; + } + + $zip_content =& $this->get_zip(); + + $CI =& get_instance(); + $CI->load->helper('download'); + + force_download($filename, $zip_content); } // -------------------------------------------------------------------- @@ -367,10 +347,11 @@ class CI_Zip { */ function clear_data() { - $this->zipfile = ''; - $this->zipdata = array(); - $this->directory = array(); - $this->offset = array(); + $this->zipdata = ''; + $this->directory = ''; + $this->entries = 0; + $this->file_num = 0; + $this->offset = 0; } } -- cgit v1.2.3-24-g4f1b From e3332b0ab5dfcc42994fe4c2c1827f4e41f35c7b Mon Sep 17 00:00:00 2001 From: Derek Jones Date: Tue, 13 May 2008 14:44:32 +0000 Subject: increased security and performance of xss_clean(), added _sanitize_naughty_html() callback and removed "never allowed" items to a class property --- system/libraries/Input.php | 80 ++++++++++++++++++++++++++++++++-------------- 1 file changed, 56 insertions(+), 24 deletions(-) (limited to 'system') diff --git a/system/libraries/Input.php b/system/libraries/Input.php index 978d1ff34..c86a3cec0 100644 --- a/system/libraries/Input.php +++ b/system/libraries/Input.php @@ -32,7 +32,26 @@ class CI_Input { var $ip_address = FALSE; var $user_agent = FALSE; var $allow_get_array = FALSE; - + + /* never allowed, string replacement */ + var $never_allowed_str = array( + 'document.cookie' => '[removed]', + 'document.write' => '[removed]', + '.parentNode' => '[removed]', + '.innerHTML' => '[removed]', + 'window.location' => '[removed]', + '-moz-binding' => '[removed]', + '' => '-->', + ' '<![CDATA[' + ); + /* never allowed, regex replacement */ + var $never_allowed_regex = array( + "javascript\s*:" => '[removed]', + "expression\s*\(" => '[removed]', // CSS and IE + "Redirect\s+302" => '[removed]' + ); + /** * Constructor * @@ -663,30 +682,13 @@ class CI_Input { /* * Not Allowed Under Any Conditions */ - $bad = array( - 'document.cookie' => '[removed]', - 'document.write' => '[removed]', - '.parentNode' => '[removed]', - '.innerHTML' => '[removed]', - 'window.location' => '[removed]', - '-moz-binding' => '[removed]', - '' => '-->', - ' '<![CDATA[' - ); - - foreach ($bad as $key => $val) + + foreach ($this->never_allowed_str as $key => $val) { $str = str_replace($key, $val, $str); } - - $bad = array( - "javascript\s*:" => '[removed]', - "expression\s*\(" => '[removed]', // CSS and IE - "Redirect\s+302" => '[removed]' - ); - - foreach ($bad as $key => $val) + + foreach ($this->never_allowed_regex as $key => $val) { $str = preg_replace("#".$key."#i", $val, $str); } @@ -774,7 +776,8 @@ class CI_Input { * Becomes: <blink> * */ - $str = preg_replace('#<(/*\s*)(alert|applet|basefont|base|behavior|bgsound|blink|body|embed|expression|form|frameset|frame|head|html|ilayer|iframe|input|layer|link|meta|object|plaintext|style|script|textarea|title|xml|xss)([^>]*)>#is', "<\\1\\2\\3>", $str); + $naughty = 'alert|applet|basefont|base|behavior|bgsound|blink|body|embed|expression|form|frameset|frame|head|html|ilayer|iframe|input|layer|link|meta|object|plaintext|style|script|textarea|title|xml|xss'; + $str = preg_replace_callback('#<(/*\s*)('.$naughty.')([^><]*)([><]*)#is', array($this, '_sanitize_naughty_html'), $str); /* * Sanitize naughty scripting elements @@ -807,7 +810,7 @@ class CI_Input { '-moz-binding' => '[removed]', '' => '-->', - ' '<![CDATA[' + ' '<![CDATA[' ); foreach ($bad as $key => $val) @@ -855,7 +858,36 @@ class CI_Input { } // -------------------------------------------------------------------- + + /** + * Sanitize Naughty HTML + * + * Callback function for xss_clean() to remove naughty HTML elements + * + * @access private + * @param array + * @return string + */ + function _sanitize_naughty_html($matches) + { + // encode opening brace + $str = '<'.$matches[1].$matches[2].$matches[3]; + + // encode captured opening or closing brace to prevent recursive vectors + if ($matches[4] == '>') + { + $str .= '>'; + } + elseif ($matches[4] == '<') + { + $str .= '<'; + } + return $str; + } + + // -------------------------------------------------------------------- + /** * JS Link Removal * -- cgit v1.2.3-24-g4f1b From 000ab69f536420a0214e4d8d15898bcacf918ece Mon Sep 17 00:00:00 2001 From: Derek Jones Date: Tue, 13 May 2008 14:46:38 +0000 Subject: Hey you! Yeah, you, that other set of hardcoded arrays in xss_clean(). You're coming with me, pal! --- system/libraries/Input.php | 24 +++--------------------- 1 file changed, 3 insertions(+), 21 deletions(-) (limited to 'system') diff --git a/system/libraries/Input.php b/system/libraries/Input.php index c86a3cec0..ec06101e6 100644 --- a/system/libraries/Input.php +++ b/system/libraries/Input.php @@ -801,30 +801,12 @@ class CI_Input { * something got through the above filters * */ - $bad = array( - 'document.cookie' => '[removed]', - 'document.write' => '[removed]', - '.parentNode' => '[removed]', - '.innerHTML' => '[removed]', - 'window.location' => '[removed]', - '-moz-binding' => '[removed]', - '' => '-->', - ' '<![CDATA[' - ); - - foreach ($bad as $key => $val) + foreach ($this->never_allowed_str as $key => $val) { $str = str_replace($key, $val, $str); } - - $bad = array( - "javascript\s*:" => '[removed]', - "expression\s*\(" => '[removed]', // CSS and IE - "Redirect\s+302" => '[removed]' - ); - - foreach ($bad as $key => $val) + + foreach ($this->never_allowed_regex as $key => $val) { $str = preg_replace("#".$key."#i", $val, $str); } -- cgit v1.2.3-24-g4f1b From f38fe09dfecde176dc2803dd6a55177666f7d616 Mon Sep 17 00:00:00 2001 From: Derek Jones Date: Tue, 13 May 2008 20:28:11 +0000 Subject: hotfix for a bug in database error display introduced by 1.6.2 fix for bugs #4451, #4299, and #4339 --- system/database/DB_driver.php | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) (limited to 'system') diff --git a/system/database/DB_driver.php b/system/database/DB_driver.php index 306f09d7d..a0833d0ce 100644 --- a/system/database/DB_driver.php +++ b/system/database/DB_driver.php @@ -308,18 +308,23 @@ class CI_DB_driver { 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: '.$this->_error_message()); return $this->display_error( array( - 'Error Number: '.$this->_error_number(), - $this->_error_message(), + 'Error Number: '.$error_no, + $error_msg, $sql ) ); -- cgit v1.2.3-24-g4f1b From 454fa7e0039689ca480eb6ef999d3fa753f5f875 Mon Sep 17 00:00:00 2001 From: Derek Jones Date: Tue, 13 May 2008 22:26:09 +0000 Subject: force closing tag on eval() for servers not running short_open_tags --- system/libraries/Loader.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system') diff --git a/system/libraries/Loader.php b/system/libraries/Loader.php index 5e3819ea6..3346f0a2a 100644 --- a/system/libraries/Loader.php +++ b/system/libraries/Loader.php @@ -703,7 +703,7 @@ class CI_Loader { if ((bool) @ini_get('short_open_tag') === FALSE AND config_item('rewrite_short_tags') == TRUE) { - echo eval(preg_replace("/;*\s*\?>/", "; ?>", str_replace(''.preg_replace("/;*\s*\?>/", "; ?>", str_replace(' Date: Wed, 14 May 2008 15:01:50 +0000 Subject: fixed bug #3419 where the 'database' setting for DSN connections was using the host portion of the URL instead of the path. Added ability to set other db config values in DSN connections via query string --- system/database/DB.php | 25 +++++++++++++++++++++++-- system/database/DB_driver.php | 2 ++ 2 files changed, 25 insertions(+), 2 deletions(-) (limited to 'system') diff --git a/system/database/DB.php b/system/database/DB.php index 2446645a7..eb25273a1 100644 --- a/system/database/DB.php +++ b/system/database/DB.php @@ -66,10 +66,31 @@ function &DB($params = '', $active_record_override = FALSE) '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['host'], 1)) : '' + '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'] == '') { diff --git a/system/database/DB_driver.php b/system/database/DB_driver.php index a0833d0ce..c9cece621 100644 --- a/system/database/DB_driver.php +++ b/system/database/DB_driver.php @@ -36,6 +36,8 @@ class CI_DB_driver { var $database; var $dbdriver = 'mysql'; var $dbprefix = ''; + var $char_set = ''; + var $dbcollat = ''; var $autoinit = TRUE; // Whether to automatically initialize the DB var $swap_pre = ''; var $port = ''; -- cgit v1.2.3-24-g4f1b From cafd63e83b20c40b1d9bd234dd2c20b2cdaab2c1 Mon Sep 17 00:00:00 2001 From: Derek Jones Date: Wed, 14 May 2008 15:08:17 +0000 Subject: set $DB->char_set and $DB->dbcollat defaults to utf8 and utf8_general_ci respectively --- system/database/DB_driver.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'system') diff --git a/system/database/DB_driver.php b/system/database/DB_driver.php index c9cece621..eeaf6ea78 100644 --- a/system/database/DB_driver.php +++ b/system/database/DB_driver.php @@ -36,8 +36,8 @@ class CI_DB_driver { var $database; var $dbdriver = 'mysql'; var $dbprefix = ''; - var $char_set = ''; - var $dbcollat = ''; + var $char_set = 'utf8'; + var $dbcollat = 'utf8_general_ci'; var $autoinit = TRUE; // Whether to automatically initialize the DB var $swap_pre = ''; var $port = ''; -- cgit v1.2.3-24-g4f1b From b846d38da5deff9dac602a9d7dbb8e88ce14a73c Mon Sep 17 00:00:00 2001 From: Derek Jones Date: Wed, 14 May 2008 17:01:12 +0000 Subject: Added missing semicolon in upload_lang.php --- system/language/english/unit_test_lang.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'system') diff --git a/system/language/english/unit_test_lang.php b/system/language/english/unit_test_lang.php index 26fc21ae8..7e1b61607 100644 --- a/system/language/english/unit_test_lang.php +++ b/system/language/english/unit_test_lang.php @@ -17,8 +17,8 @@ $lang['ut_string'] = 'String'; $lang['ut_array'] = 'Array'; $lang['ut_object'] = 'Object'; $lang['ut_resource'] = 'Resource'; -$lang['ut_null'] = 'Null' +$lang['ut_null'] = 'Null'; - -/* End of file unit_test_lang.php */ + +/* End of file unit_test_lang.php */ /* Location: ./system/language/english/unit_test_lang.php */ \ No newline at end of file -- cgit v1.2.3-24-g4f1b From d9d379c1b4d674ed16edaf8167cc8f5f65becc86 Mon Sep 17 00:00:00 2001 From: Derek Allard Date: Wed, 14 May 2008 21:26:35 +0000 Subject: Set the mime type check in the Upload class to reference the global mimes variable. --- system/libraries/Upload.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'system') diff --git a/system/libraries/Upload.php b/system/libraries/Upload.php index 1225ee36b..23e52e403 100644 --- a/system/libraries/Upload.php +++ b/system/libraries/Upload.php @@ -821,9 +821,11 @@ class CI_Upload { */ function mimes_types($mime) { + global $mimes; + if (count($this->mimes) == 0) { - if (@include(APPPATH.'config/mimes'.EXT)) + if (@require_once(APPPATH.'config/mimes'.EXT)) { $this->mimes = $mimes; unset($mimes); -- cgit v1.2.3-24-g4f1b From 63fc5fe5c6d8c9c8a2d693b0f65c3c8af8f2a74f Mon Sep 17 00:00:00 2001 From: Derek Jones Date: Thu, 15 May 2008 20:13:14 +0000 Subject: added ability to use xss_clean() to test images, and improved security for vectors particular to the Opera family of browsers --- system/libraries/Input.php | 86 ++++++++++++++++++++++++++-------------------- 1 file changed, 49 insertions(+), 37 deletions(-) (limited to 'system') diff --git a/system/libraries/Input.php b/system/libraries/Input.php index ec06101e6..e6ac460b0 100644 --- a/system/libraries/Input.php +++ b/system/libraries/Input.php @@ -554,7 +554,7 @@ class CI_Input { * @param string * @return string */ - function xss_clean($str) + function xss_clean($str, $is_image = FALSE, $loops = 0) { /* * Is the string an array? @@ -569,6 +569,15 @@ class CI_Input { return $str; } + + /* + * Runaway loop prevention. If the text has had to be examined this many times + * I think it's safe to say that it is best to simply ignore it. + */ + if ($loops > 9) + { + return ''; + } /* * Remove Null Characters @@ -608,7 +617,6 @@ class CI_Input { /* * Un-Protect GET variables in URLs */ - $str = str_replace($this->xss_hash(), '&', $str); /* @@ -622,7 +630,7 @@ class CI_Input { * */ $str = rawurldecode($str); - + /* * Convert character entities to ASCII * @@ -634,35 +642,7 @@ class CI_Input { $str = preg_replace_callback("/[a-z]+=([\'\"]).*?\\1/si", array($this, '_attribute_conversion'), $str); - $str = preg_replace_callback("/<([\w]+)[^>]*>/si", array($this, '_html_entity_decode_callback'), $str); - - /* - - Old Code that when modified to use preg_replace()'s above became more efficient memory-wise - - if (preg_match_all("/[a-z]+=([\'\"]).*?\\1/si", $str, $matches)) - { - for ($i = 0; $i < count($matches[0]); $i++) - { - if (stristr($matches[0][$i], '>')) - { - $str = str_replace( $matches['0'][$i], - str_replace('>', '<', $matches[0][$i]), - $str); - } - } - } - - if (preg_match_all("/<([\w]+)[^>]*>/si", $str, $matches)) - { - for ($i = 0; $i < count($matches[0]); $i++) - { - $str = str_replace($matches[0][$i], - $this->_html_entity_decode($matches[0][$i], $charset), - $str); - } - } - */ + $str = preg_replace_callback("/<\w+.*?(?=>|<|$)/si", array($this, '_html_entity_decode_callback'), $str); /* * Convert all tabs to spaces @@ -679,6 +659,9 @@ class CI_Input { $str = str_replace("\t", ' ', $str); } + // capture for comparison at the end + $converted_string = $str; + /* * Not Allowed Under Any Conditions */ @@ -808,10 +791,39 @@ class CI_Input { foreach ($this->never_allowed_regex as $key => $val) { - $str = preg_replace("#".$key."#i", $val, $str); + $str = preg_replace("#".$key."#i", $val, $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) + { + if ($str == $converted_string) + { + return TRUE; + } + else + { + return FALSE; + } + } + + /* + * If something changed after character conversion, we can be fairly confident that something + * malicious was removed, so let's take no chances that the attacker is counting on specific + * mutations taking place to allow a new attack to reveal itself. So say we all. + */ + if ($converted_string != $str) + { + $str = $this->xss_clean($str, $is_image, ++$loops); + } + log_message('debug', "XSS Filtering completed"); return $str; } @@ -884,7 +896,7 @@ class CI_Input { */ function _js_link_removal($match) { - return preg_replace("#.*?#si", "", $match[0]); + return preg_replace("#.*?#si", "", $match[0]); } /** @@ -901,7 +913,7 @@ class CI_Input { */ function _js_img_removal($match) { - return preg_replace("##si", "", $match[0]); + return preg_replace("##si", "", $match[0]); } // -------------------------------------------------------------------- @@ -978,12 +990,12 @@ class CI_Input { if (function_exists('html_entity_decode') && (strtolower($charset) != 'utf-8' OR version_compare(phpversion(), '5.0.0', '>='))) { $str = html_entity_decode($str, ENT_COMPAT, $charset); - $str = preg_replace('~&#x([0-9a-f]{2,5})~ei', 'chr(hexdec("\\1"))', $str); + $str = preg_replace('~&#x(0*[0-9a-f]{2,5})~ei', 'chr(hexdec("\\1"))', $str); return preg_replace('~&#([0-9]{2,4})~e', 'chr(\\1)', $str); } // Numeric Entities - $str = preg_replace('~&#x([0-9a-f]{2,5});{0,1}~ei', 'chr(hexdec("\\1"))', $str); + $str = preg_replace('~&#x(0*[0-9a-f]{2,5});{0,1}~ei', 'chr(hexdec("\\1"))', $str); $str = preg_replace('~&#([0-9]{2,4});{0,1}~e', 'chr(\\1)', $str); // Literal Entities - Slightly slow so we do another check -- cgit v1.2.3-24-g4f1b From 245038d6a5121f396b231d268d3ca5edac9c105a Mon Sep 17 00:00:00 2001 From: Derek Jones Date: Thu, 15 May 2008 21:58:07 +0000 Subject: addition xss protection against certain data urls, stripping of anything sent with utf-7 encoding --- system/libraries/Input.php | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) (limited to 'system') diff --git a/system/libraries/Input.php b/system/libraries/Input.php index e6ac460b0..c1659ab8d 100644 --- a/system/libraries/Input.php +++ b/system/libraries/Input.php @@ -747,6 +747,16 @@ class CI_Input { * */ $event_handlers = array('onblur','onchange','onclick','onfocus','onload','onmouseover','onmouseup','onmousedown','onselect','onsubmit','onunload','onkeypress','onkeydown','onkeyup','onresize', 'xmlns'); + + if ($is_image === TRUE) + { + /* + * Adobe Photoshop puts XML metadata into JFIF images, including namespacing, + * so we have to allow this for images. -Paul + */ + unset($event_handlers[array_search('xmlns', $event_handlers)]); + } + $str = preg_replace("#<([^>]+)(".implode('|', $event_handlers).")([^>]*)>#iU", "<\\1\\2\\3>", $str); /* @@ -896,7 +906,7 @@ class CI_Input { */ function _js_link_removal($match) { - return preg_replace("#.*?#si", "", $match[0]); + return preg_replace("#.*?#si", "", $match[0]); } /** @@ -913,7 +923,7 @@ class CI_Input { */ function _js_img_removal($match) { - return preg_replace("##si", "", $match[0]); + return preg_replace("##si", "", $match[0]); } // -------------------------------------------------------------------- -- cgit v1.2.3-24-g4f1b From ef40640f53351cea789a9657050422917f0b581f Mon Sep 17 00:00:00 2001 From: Derek Jones Date: Fri, 16 May 2008 04:14:36 +0000 Subject: fixed regular expression in Image lib, CI bug #4542 --- system/libraries/Image_lib.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system') diff --git a/system/libraries/Image_lib.php b/system/libraries/Image_lib.php index a602b4645..430369786 100644 --- a/system/libraries/Image_lib.php +++ b/system/libraries/Image_lib.php @@ -226,7 +226,7 @@ class CI_Image_lib { } // Is there a file name? - if ( ! preg_match("#[\.jpg|\.jpeg|\.gif|\.png]$#i", $full_dest_path)) + if ( ! preg_match("#\.(jpg|jpeg|gif|png)$#i", $full_dest_path)) { $this->dest_folder = $full_dest_path.'/'; $this->dest_image = $this->source_image; -- cgit v1.2.3-24-g4f1b From 5453b8e306b6d3d0ce96bfd0cb5bbbe331084bdc Mon Sep 17 00:00:00 2001 From: Derek Jones Date: Fri, 16 May 2008 14:38:40 +0000 Subject: changed foreach() reindexing of segment arrays to array_unshift() - teensy tiny memory and speed improvement. --- system/libraries/URI.php | 17 ++--------------- 1 file changed, 2 insertions(+), 15 deletions(-) (limited to 'system') diff --git a/system/libraries/URI.php b/system/libraries/URI.php index 4d0cd9c17..8d979d0d2 100644 --- a/system/libraries/URI.php +++ b/system/libraries/URI.php @@ -246,22 +246,9 @@ class CI_URI { */ function _reindex_segments() { - $i = 1; - - foreach ($this->segments as $val) - { - $this->segments[$i++] = $val; - } - + array_unshift($this->segments, NULL); + array_unshift($this->rsegments, NULL); unset($this->segments[0]); - - $i = 1; - - foreach ($this->rsegments as $val) - { - $this->rsegments[$i++] = $val; - } - unset($this->rsegments[0]); } -- cgit v1.2.3-24-g4f1b From ac27fbeee734776ed524a067848c8df148c782a7 Mon Sep 17 00:00:00 2001 From: Derek Allard Date: Fri, 16 May 2008 18:09:52 +0000 Subject: Considerably expanded list of mobile user-agents in config/user_agents.php. --- system/application/config/user_agents.php | 83 ++++++++++++++++++++++++++----- 1 file changed, 71 insertions(+), 12 deletions(-) (limited to 'system') diff --git a/system/application/config/user_agents.php b/system/application/config/user_agents.php index 27a9d0c76..61e04715a 100644 --- a/system/application/config/user_agents.php +++ b/system/application/config/user_agents.php @@ -87,18 +87,77 @@ $mobiles = array( 'motorola' => 'Motorola' ); -// 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' - ); - +$mobiles = array( + // Phones and Manufacturers + 'motorola' => "Motorola", + 'nokia' => "Nokia", + 'palm' => "Palm", + 'iphone' => "Apple iPhone", + '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", + + // Operating Systems + 'symbian' => "Symbian", + 'elaine' => "Palm", + 'palm' => "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", + + // 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" + ); /* End of file user_agents.php */ -- cgit v1.2.3-24-g4f1b From 23df94da0cb01d57e5418cbf8a7c9806f42f370a Mon Sep 17 00:00:00 2001 From: Derek Jones Date: Sat, 17 May 2008 13:02:14 +0000 Subject: reduced $mobiles to single array --- system/application/config/user_agents.php | 27 +++++++++++++-------------- 1 file changed, 13 insertions(+), 14 deletions(-) (limited to 'system') diff --git a/system/application/config/user_agents.php b/system/application/config/user_agents.php index 61e04715a..bc25ce998 100644 --- a/system/application/config/user_agents.php +++ b/system/application/config/user_agents.php @@ -71,23 +71,22 @@ $browsers = array( ); $mobiles = array( + // legacy array, old values commented out 'mobileexplorer' => 'Mobile Explorer', - 'openwave' => 'Open Wave', - 'opera mini' => 'Opera Mini', - 'operamini' => 'Opera Mini', - 'elaine' => 'Palm', +// 'openwave' => 'Open Wave', +// 'opera mini' => 'Opera Mini', +// 'operamini' => 'Opera Mini', +// 'elaine' => 'Palm', 'palmsource' => 'Palm', - 'digital paths' => 'Palm', - 'avantgo' => 'Avantgo', - 'xiino' => 'Xiino', +// 'digital paths' => 'Palm', +// 'avantgo' => 'Avantgo', +// 'xiino' => 'Xiino', 'palmscape' => 'Palmscape', - 'nokia' => 'Nokia', - 'ericsson' => 'Ericsson', - 'blackberry' => 'BlackBerry', - 'motorola' => 'Motorola' - ); - -$mobiles = array( +// 'nokia' => 'Nokia', +// 'ericsson' => 'Ericsson', +// 'blackberry' => 'BlackBerry', +// 'motorola' => 'Motorola' + // Phones and Manufacturers 'motorola' => "Motorola", 'nokia' => "Nokia", -- cgit v1.2.3-24-g4f1b From 513ce070bfcbb2b59d0aabd1732b7666b90b4d83 Mon Sep 17 00:00:00 2001 From: Derek Allard Date: Sun, 18 May 2008 12:23:11 +0000 Subject: Moved the _has_operators() function into DB_driver from DB_active_rec. --- system/database/DB_active_rec.php | 20 -------------------- system/database/DB_driver.php | 22 ++++++++++++++++++++++ 2 files changed, 22 insertions(+), 20 deletions(-) (limited to 'system') diff --git a/system/database/DB_active_rec.php b/system/database/DB_active_rec.php index 3cb39822c..dcf9d3868 100644 --- a/system/database/DB_active_rec.php +++ b/system/database/DB_active_rec.php @@ -1394,27 +1394,7 @@ class CI_DB_active_record extends CI_DB_driver { { return $this->from($table); } - - // -------------------------------------------------------------------- - - /** - * 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; - } - // -------------------------------------------------------------------- /** diff --git a/system/database/DB_driver.php b/system/database/DB_driver.php index eeaf6ea78..60f51d757 100644 --- a/system/database/DB_driver.php +++ b/system/database/DB_driver.php @@ -933,7 +933,9 @@ class CI_DB_driver { function update_string($table, $data, $where) { if ($where == '') + { return false; + } $fields = array(); foreach($data as $key => $val) @@ -971,6 +973,26 @@ class CI_DB_driver { // -------------------------------------------------------------------- + /** + * 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; + } + + // -------------------------------------------------------------------- + /** * Prep the table name - simply adds the table prefix if needed * -- cgit v1.2.3-24-g4f1b From bd08d84525e5f9af869d3aaba92906d2047272cc Mon Sep 17 00:00:00 2001 From: Derek Jones Date: Tue, 20 May 2008 15:07:27 +0000 Subject: improved security in xss_clean(), added
    \n".$extra; + return "".$extra; } } @@ -503,7 +508,7 @@ if ( ! function_exists('form_close')) { function form_close($extra = '') { - return "\n".$extra; + return "".$extra; } } diff --git a/system/helpers/html_helper.php b/system/helpers/html_helper.php index 7a61055f7..c3f0fbc29 100644 --- a/system/helpers/html_helper.php +++ b/system/helpers/html_helper.php @@ -274,7 +274,7 @@ if ( ! function_exists('link_tag')) } } - $link .= "/>\n"; + $link .= "/>"; } else { @@ -303,7 +303,7 @@ if ( ! function_exists('link_tag')) $link .= 'title="'.$title.'" '; } - $link .= '/>'."\n"; + $link .= '/>'.""; } -- cgit v1.2.3-24-g4f1b From 8b5d42b3fc1eb9bb7ef5133220340a1418501460 Mon Sep 17 00:00:00 2001 From: Derek Allard Date: Mon, 21 Jul 2008 12:02:57 +0000 Subject: removing stray quotes --- system/helpers/html_helper.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system') diff --git a/system/helpers/html_helper.php b/system/helpers/html_helper.php index c3f0fbc29..6d74c6d19 100644 --- a/system/helpers/html_helper.php +++ b/system/helpers/html_helper.php @@ -303,7 +303,7 @@ if ( ! function_exists('link_tag')) $link .= 'title="'.$title.'" '; } - $link .= '/>'.""; + $link .= '/>'; } -- cgit v1.2.3-24-g4f1b From 5f171c8ce895a42774c6de98f7f984ab4373e9e4 Mon Sep 17 00:00:00 2001 From: Derek Jones Date: Fri, 25 Jul 2008 20:30:35 +0000 Subject: put $robots back into user_agents.php --- system/application/config/user_agents.php | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'system') diff --git a/system/application/config/user_agents.php b/system/application/config/user_agents.php index a63aa4995..d350af3aa 100644 --- a/system/application/config/user_agents.php +++ b/system/application/config/user_agents.php @@ -159,6 +159,17 @@ $mobiles = array( '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' + ); /* End of file user_agents.php */ /* Location: ./system/application/config/user_agents.php */ \ No newline at end of file -- cgit v1.2.3-24-g4f1b From 3018465a7fd25ee66d215bf881ca8b91f7b8ab62 Mon Sep 17 00:00:00 2001 From: Derek Jones Date: Wed, 6 Aug 2008 18:31:54 +0000 Subject: fixed bug where dechex() was being fed the wrong variable for encoding space and tab characters at the end of a line of quoted-printable encoded content --- system/libraries/Email.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system') diff --git a/system/libraries/Email.php b/system/libraries/Email.php index 6ced2c5c8..ee3d76367 100644 --- a/system/libraries/Email.php +++ b/system/libraries/Email.php @@ -1196,7 +1196,7 @@ class CI_Email { // Convert spaces and tabs but only if it's the end of the line if ($i == ($length - 1)) { - $char = ($ascii == '32' OR $ascii == '9') ? $escape.sprintf('%02s', dechex($char)) : $char; + $char = ($ascii == '32' OR $ascii == '9') ? $escape.sprintf('%02s', dechex($ascii)) : $char; } // encode = signs -- cgit v1.2.3-24-g4f1b From 30e9c533700ef014d4c3ff513bc7dd1a2b5c2309 Mon Sep 17 00:00:00 2001 From: Derek Jones Date: Wed, 6 Aug 2008 18:35:27 +0000 Subject: added killing of nulls to _prep_quoted_printable() --- system/libraries/Email.php | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'system') diff --git a/system/libraries/Email.php b/system/libraries/Email.php index ee3d76367..b0d9f1269 100644 --- a/system/libraries/Email.php +++ b/system/libraries/Email.php @@ -1162,7 +1162,10 @@ class CI_Email { // Reduce multiple spaces $str = preg_replace("| +|", " ", $str); - + + // kill nulls + $str = preg_replace('/\x00+/', '', $str); + // Standardize newlines if (strpos($str, "\r") !== FALSE) { -- cgit v1.2.3-24-g4f1b From 17756a07a877436d520edb87813e13b860ace169 Mon Sep 17 00:00:00 2001 From: Derek Jones Date: Thu, 7 Aug 2008 00:01:09 +0000 Subject: tightened human time stamp validation regex --- system/helpers/date_helper.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system') diff --git a/system/helpers/date_helper.php b/system/helpers/date_helper.php index 095e460a9..a82450aa1 100644 --- a/system/helpers/date_helper.php +++ b/system/helpers/date_helper.php @@ -442,7 +442,7 @@ if ( ! function_exists('human_to_unix')) $datestr = trim($datestr); $datestr = preg_replace("/\040+/", "\040", $datestr); - if ( ! ereg("^[0-9]{2,4}\-[0-9]{1,2}\-[0-9]{1,2}\040[0-9]{1,2}:[0-9]{1,2}.*$", $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; } -- cgit v1.2.3-24-g4f1b From 0ea8f9877eb2b47abffe9a02fee7ea9fa066015d Mon Sep 17 00:00:00 2001 From: Rick Ellis Date: Tue, 12 Aug 2008 00:39:10 +0000 Subject: Added support for libraries in subdirectories --- system/libraries/Loader.php | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) (limited to 'system') diff --git a/system/libraries/Loader.php b/system/libraries/Loader.php index 9b21bc31a..ec09f00c6 100644 --- a/system/libraries/Loader.php +++ b/system/libraries/Loader.php @@ -757,8 +757,28 @@ class CI_Loader { */ function _ci_load_class($class, $params = NULL) { - // Get the class name - $class = str_replace(EXT, '', $class); + // 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(EXT, '', trim($class, '/')); + + // Was the path included with the class name? + // We look for a slash to determine this + $subdir = ''; + if (strpos($class, '/') !== FALSE) + { + // explode the path so we can separate the filename from the path + $x = explode('/', $class); + + // Reset the $class variable now that we know the actual filename + $class = end($x); + + // Kill the filename from the array + unset($x[count($x)-1]); + + // Glue the path back together, sans filename + $subdir = implode($x, '/').'/'; + } // We'll test for both lowercase and capitalized versions of the file name foreach (array(ucfirst($class), strtolower($class)) as $class) -- cgit v1.2.3-24-g4f1b From afb056afd8335dd972f4e6d84b652641663ab6f4 Mon Sep 17 00:00:00 2001 From: Rick Ellis Date: Tue, 12 Aug 2008 00:44:25 +0000 Subject: --- system/libraries/Loader.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'system') diff --git a/system/libraries/Loader.php b/system/libraries/Loader.php index ec09f00c6..e5640b070 100644 --- a/system/libraries/Loader.php +++ b/system/libraries/Loader.php @@ -783,7 +783,7 @@ class CI_Loader { // We'll test for both lowercase and capitalized versions of the file name foreach (array(ucfirst($class), strtolower($class)) as $class) { - $subclass = APPPATH.'libraries/'.config_item('subclass_prefix').$class.EXT; + $subclass = APPPATH.'libraries/'.$subdir.config_item('subclass_prefix').$class.EXT; // Is this a class extension request? if (file_exists($subclass)) @@ -816,7 +816,7 @@ class CI_Loader { for ($i = 1; $i < 3; $i++) { $path = ($i % 2) ? APPPATH : BASEPATH; - $filepath = $path.'libraries/'.$class.EXT; + $filepath = $path.'libraries/'.$subdir.$class.EXT; // Does the file exist? No? Bummer... if ( ! file_exists($filepath)) -- cgit v1.2.3-24-g4f1b From f388511b8596558ef560eca6a99bd435805e2d59 Mon Sep 17 00:00:00 2001 From: Rick Ellis Date: Tue, 12 Aug 2008 05:32:25 +0000 Subject: Added newline character in between hidden fields --- system/helpers/form_helper.php | 1 + 1 file changed, 1 insertion(+) (limited to 'system') diff --git a/system/helpers/form_helper.php b/system/helpers/form_helper.php index 21b7df42f..0ad57d532 100644 --- a/system/helpers/form_helper.php +++ b/system/helpers/form_helper.php @@ -114,6 +114,7 @@ if ( ! function_exists('form_hidden')) foreach ($name as $name => $value) { + $form .= "\n"; $form .= ''; } -- cgit v1.2.3-24-g4f1b From c9a4f2800a7d21e338ddd755e111f4c85a09ff79 Mon Sep 17 00:00:00 2001 From: Derek Jones Date: Wed, 13 Aug 2008 20:42:56 +0000 Subject: updated time zone list and offsets to match the world's current time zones --- system/helpers/date_helper.php | 72 +++++++++++++++++++--------------- system/language/english/date_lang.php | 73 ++++++++++++++++++++--------------- 2 files changed, 82 insertions(+), 63 deletions(-) (limited to 'system') diff --git a/system/helpers/date_helper.php b/system/helpers/date_helper.php index a82450aa1..401d64306 100644 --- a/system/helpers/date_helper.php +++ b/system/helpers/date_helper.php @@ -551,37 +551,47 @@ if ( ! function_exists('timezones')) // 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, - 'UM9' => -9, - 'UM8' => -8, - 'UM7' => -7, - 'UM6' => -6, - 'UM5' => -5, - 'UM4' => -4, - 'UM25' => -2.5, - 'UM3' => -3, - 'UM2' => -2, - 'UM1' => -1, - 'UTC' => 0, - 'UP1' => +1, - 'UP2' => +2, - 'UP3' => +3, - 'UP25' => +2.5, - 'UP4' => +4, - 'UP35' => +3.5, - 'UP5' => +5, - 'UP45' => +4.5, - 'UP6' => +6, - 'UP7' => +7, - 'UP8' => +8, - 'UP9' => +9, - 'UP85' => +8.5, - 'UP10' => +10, - 'UP11' => +11, - 'UP12' => +12 + $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 == '') diff --git a/system/language/english/date_lang.php b/system/language/english/date_lang.php index 93989eb45..329ad0999 100644 --- a/system/language/english/date_lang.php +++ b/system/language/english/date_lang.php @@ -15,37 +15,46 @@ $lang['date_minutes'] = "Minutes"; $lang['date_second'] = "Second"; $lang['date_seconds'] = "Seconds"; -$lang['UM12'] = "(UTC - 12:00) Eniwetok, Kwajalein"; -$lang['UM11'] = "(UTC - 11:00) Nome, Midway Island, Samoa"; -$lang['UM10'] = "(UTC - 10:00) Hawaii"; -$lang['UM9'] = "(UTC - 9:00) Alaska"; -$lang['UM8'] = "(UTC - 8:00) Pacific Time"; -$lang['UM7'] = "(UTC - 7:00) Mountain Time"; -$lang['UM6'] = "(UTC - 6:00) Central Time, Mexico City"; -$lang['UM5'] = "(UTC - 5:00) Eastern Time, Bogota, Lima, Quito"; -$lang['UM4'] = "(UTC - 4:00) Atlantic Time, Caracas, La Paz"; -$lang['UM25'] = "(UTC - 3:30) Newfoundland"; -$lang['UM3'] = "(UTC - 3:00) Brazil, Buenos Aires, Georgetown, Falkland Is."; -$lang['UM2'] = "(UTC - 2:00) Mid-Atlantic, Ascension Is., St. Helena"; -$lang['UM1'] = "(UTC - 1:00) Azores, Cape Verde Islands"; -$lang['UTC'] = "(UTC) Casablanca, Dublin, Edinburgh, London, Lisbon, Monrovia"; -$lang['UP1'] = "(UTC + 1:00) Berlin, Brussels, Copenhagen, Madrid, Paris, Rome"; -$lang['UP2'] = "(UTC + 2:00) Kaliningrad, South Africa, Warsaw"; -$lang['UP3'] = "(UTC + 3:00) Baghdad, Riyadh, Moscow, Nairobi"; -$lang['UP25'] = "(UTC + 3:30) Tehran"; -$lang['UP4'] = "(UTC + 4:00) Abu Dhabi, Baku, Muscat, Tbilisi"; -$lang['UP35'] = "(UTC + 4:30) Kabul"; -$lang['UP5'] = "(UTC + 5:00) Islamabad, Karachi, Tashkent"; -$lang['UP45'] = "(UTC + 5:30) Mumbai, Kolkata, Chennai, New Delhi"; -$lang['UP6'] = "(UTC + 6:00) Almaty, Colomba, Dhaka"; -$lang['UP7'] = "(UTC + 7:00) Bangkok, Hanoi, Jakarta"; -$lang['UP8'] = "(UTC + 8:00) Beijing, Hong Kong, Perth, Singapore, Taipei"; -$lang['UP9'] = "(UTC + 9:00) Osaka, Sapporo, Seoul, Tokyo, Yakutsk"; -$lang['UP85'] = "(UTC + 9:30) Adelaide, Darwin"; -$lang['UP10'] = "(UTC + 10:00) Melbourne, Papua New Guinea, Sydney, Vladivostok"; -$lang['UP11'] = "(UTC + 11:00) Magadan, New Caledonia, Solomon Islands"; -$lang['UP12'] = "(UTC + 12:00) Auckland, Wellington, Fiji, Marshall Islands"; +$lang['UM12'] = '(UTC -12:00) Baker/Howland Island', +$lang['UM11'] = '(UTC -11:00) Samoa Time Zone, Niue', +$lang['UM10'] = '(UTC -10:00) Hawaii-Aleutian Standard Time, Cook Islands, Tahiti', +$lang['UM95'] = '(UTC -9:30) Marquesas Islands', +$lang['UM9'] = '(UTC -9:00) Alaska Standard Time, Gambier Islands', +$lang['UM8'] = '(UTC -8:00) Pacific Standard Time, Clipperton Island', +$lang['UM7'] = '(UTC -7:00) Mountain Standard Time', +$lang['UM6'] = '(UTC -6:00) Central Standard Time', +$lang['UM5'] = '(UTC -5:00) Eastern Standard Time, Western Caribbean Standard Time', +$lang['UM45'] = '(UTC -4:30) Venezuelan Standard Time', +$lang['UM4'] = '(UTC -4:00) Atlantic Standard Time, Eastern Caribbean Standard Time', +$lang['UM35'] = '(UTC -3:30) Newfoundland Standard Time', +$lang['UM3'] = '(UTC -3:00) Argentina, Brazil, French Guiana, Uruguay', +$lang['UM2'] = '(UTC -2:00) South Georgia/South Sandwich Islands', +$lang['UM1'] = '(UTC -1:00) Azores, Cape Verde Islands', +$lang['UTC'] = '(UTC) Greenwich Mean Time, Western European Time', +$lang['UP1'] = '(UTC +1:00) Central European Time, West Africa Time', +$lang['UP2'] = '(UTC +2:00) Central Africa Time, Eastern European Time, Kaliningrad Time', +$lang['UP3'] = '(UTC +3:00) Moscow Time, East Africa Time', +$lang['UP35'] = '(UTC +3:30) Iran Standard Time', +$lang['UP4'] = '(UTC +4:00) Azerbaijan Standard Time, Samara Time', +$lang['UP45'] = '(UTC +4:30) Afghanistan', +$lang['UP5'] = '(UTC +5:00) Pakistan Standard Time, Yekaterinburg Time', +$lang['UP55'] = '(UTC +5:30) Indian Standard Time, Sri Lanka Time', +$lang['UP575'] = '(UTC +5:45) Nepal Time', +$lang['UP6'] = '(UTC +6:00) Bangladesh Standard Time, Bhutan Time, Omsk Time', +$lang['UP65'] = '(UTC +6:30) Cocos Islands, Myanmar', +$lang['UP7'] = '(UTC +7:00) Krasnoyarsk Time, Cambodia, Laos, Thailand, Vietnam', +$lang['UP8'] = '(UTC +8:00) Australian Western Standard Time, Beijing Time, Irkutsk Time', +$lang['UP875'] = '(UTC +8:45) Australian Central Western Standard Time', +$lang['UP9'] = '(UTC +9:00) Japan Standard Time, Korea Standard Time, Yakutsk Time', +$lang['UP95'] = '(UTC +9:30) Australian Central Standard Time', +$lang['UP10'] = '(UTC +10:00) Australian Eastern Standard Time, Vladivostok Time', +$lang['UP105'] = '(UTC +10:30) Lord Howe Island', +$lang['UP11'] = '(UTC +11:00) Magadan Time, Solomon Islands, Vanuatu', +$lang['UP115'] = '(UTC +11:30) Norfolk Island', +$lang['UP12'] = '(UTC +12:00) Fiji, Gilbert Islands, Kamchatka Time, New Zealand Standard Time', +$lang['UP1275'] = '(UTC +12:45) Chatham Islands Standard Time', +$lang['UP13'] = '(UTC +13:00) Phoenix Islands Time, Tonga', +$lang['UP14'] = '(UTC +14:00) Line Islands', - -/* End of file date_lang.php */ +/* End of file date_lang.php */ /* Location: ./system/language/english/date_lang.php */ \ No newline at end of file -- cgit v1.2.3-24-g4f1b From 5f725870198dfa765ff455f212be97684a8f8cfb Mon Sep 17 00:00:00 2001 From: Derek Jones Date: Wed, 13 Aug 2008 20:48:24 +0000 Subject: lines, not arrays, Mr. Jones --- system/language/english/date_lang.php | 80 +++++++++++++++++------------------ 1 file changed, 40 insertions(+), 40 deletions(-) (limited to 'system') diff --git a/system/language/english/date_lang.php b/system/language/english/date_lang.php index 329ad0999..29b00f509 100644 --- a/system/language/english/date_lang.php +++ b/system/language/english/date_lang.php @@ -15,46 +15,46 @@ $lang['date_minutes'] = "Minutes"; $lang['date_second'] = "Second"; $lang['date_seconds'] = "Seconds"; -$lang['UM12'] = '(UTC -12:00) Baker/Howland Island', -$lang['UM11'] = '(UTC -11:00) Samoa Time Zone, Niue', -$lang['UM10'] = '(UTC -10:00) Hawaii-Aleutian Standard Time, Cook Islands, Tahiti', -$lang['UM95'] = '(UTC -9:30) Marquesas Islands', -$lang['UM9'] = '(UTC -9:00) Alaska Standard Time, Gambier Islands', -$lang['UM8'] = '(UTC -8:00) Pacific Standard Time, Clipperton Island', -$lang['UM7'] = '(UTC -7:00) Mountain Standard Time', -$lang['UM6'] = '(UTC -6:00) Central Standard Time', -$lang['UM5'] = '(UTC -5:00) Eastern Standard Time, Western Caribbean Standard Time', -$lang['UM45'] = '(UTC -4:30) Venezuelan Standard Time', -$lang['UM4'] = '(UTC -4:00) Atlantic Standard Time, Eastern Caribbean Standard Time', -$lang['UM35'] = '(UTC -3:30) Newfoundland Standard Time', -$lang['UM3'] = '(UTC -3:00) Argentina, Brazil, French Guiana, Uruguay', -$lang['UM2'] = '(UTC -2:00) South Georgia/South Sandwich Islands', -$lang['UM1'] = '(UTC -1:00) Azores, Cape Verde Islands', -$lang['UTC'] = '(UTC) Greenwich Mean Time, Western European Time', -$lang['UP1'] = '(UTC +1:00) Central European Time, West Africa Time', -$lang['UP2'] = '(UTC +2:00) Central Africa Time, Eastern European Time, Kaliningrad Time', -$lang['UP3'] = '(UTC +3:00) Moscow Time, East Africa Time', -$lang['UP35'] = '(UTC +3:30) Iran Standard Time', -$lang['UP4'] = '(UTC +4:00) Azerbaijan Standard Time, Samara Time', -$lang['UP45'] = '(UTC +4:30) Afghanistan', -$lang['UP5'] = '(UTC +5:00) Pakistan Standard Time, Yekaterinburg Time', -$lang['UP55'] = '(UTC +5:30) Indian Standard Time, Sri Lanka Time', -$lang['UP575'] = '(UTC +5:45) Nepal Time', -$lang['UP6'] = '(UTC +6:00) Bangladesh Standard Time, Bhutan Time, Omsk Time', -$lang['UP65'] = '(UTC +6:30) Cocos Islands, Myanmar', -$lang['UP7'] = '(UTC +7:00) Krasnoyarsk Time, Cambodia, Laos, Thailand, Vietnam', -$lang['UP8'] = '(UTC +8:00) Australian Western Standard Time, Beijing Time, Irkutsk Time', -$lang['UP875'] = '(UTC +8:45) Australian Central Western Standard Time', -$lang['UP9'] = '(UTC +9:00) Japan Standard Time, Korea Standard Time, Yakutsk Time', -$lang['UP95'] = '(UTC +9:30) Australian Central Standard Time', -$lang['UP10'] = '(UTC +10:00) Australian Eastern Standard Time, Vladivostok Time', -$lang['UP105'] = '(UTC +10:30) Lord Howe Island', -$lang['UP11'] = '(UTC +11:00) Magadan Time, Solomon Islands, Vanuatu', -$lang['UP115'] = '(UTC +11:30) Norfolk Island', -$lang['UP12'] = '(UTC +12:00) Fiji, Gilbert Islands, Kamchatka Time, New Zealand Standard Time', -$lang['UP1275'] = '(UTC +12:45) Chatham Islands Standard Time', -$lang['UP13'] = '(UTC +13:00) Phoenix Islands Time, Tonga', -$lang['UP14'] = '(UTC +14:00) Line Islands', +$lang['UM12'] = '(UTC -12:00) Baker/Howland Island'; +$lang['UM11'] = '(UTC -11:00) Samoa Time Zone, Niue'; +$lang['UM10'] = '(UTC -10:00) Hawaii-Aleutian Standard Time, Cook Islands, Tahiti'; +$lang['UM95'] = '(UTC -9:30) Marquesas Islands'; +$lang['UM9'] = '(UTC -9:00) Alaska Standard Time, Gambier Islands'; +$lang['UM8'] = '(UTC -8:00) Pacific Standard Time, Clipperton Island'; +$lang['UM7'] = '(UTC -7:00) Mountain Standard Time'; +$lang['UM6'] = '(UTC -6:00) Central Standard Time'; +$lang['UM5'] = '(UTC -5:00) Eastern Standard Time, Western Caribbean Standard Time'; +$lang['UM45'] = '(UTC -4:30) Venezuelan Standard Time'; +$lang['UM4'] = '(UTC -4:00) Atlantic Standard Time, Eastern Caribbean Standard Time'; +$lang['UM35'] = '(UTC -3:30) Newfoundland Standard Time'; +$lang['UM3'] = '(UTC -3:00) Argentina, Brazil, French Guiana, Uruguay'; +$lang['UM2'] = '(UTC -2:00) South Georgia/South Sandwich Islands'; +$lang['UM1'] = '(UTC -1:00) Azores, Cape Verde Islands'; +$lang['UTC'] = '(UTC) Greenwich Mean Time, Western European Time'; +$lang['UP1'] = '(UTC +1:00) Central European Time, West Africa Time'; +$lang['UP2'] = '(UTC +2:00) Central Africa Time, Eastern European Time, Kaliningrad Time'; +$lang['UP3'] = '(UTC +3:00) Moscow Time, East Africa Time'; +$lang['UP35'] = '(UTC +3:30) Iran Standard Time'; +$lang['UP4'] = '(UTC +4:00) Azerbaijan Standard Time, Samara Time'; +$lang['UP45'] = '(UTC +4:30) Afghanistan'; +$lang['UP5'] = '(UTC +5:00) Pakistan Standard Time, Yekaterinburg Time'; +$lang['UP55'] = '(UTC +5:30) Indian Standard Time, Sri Lanka Time'; +$lang['UP575'] = '(UTC +5:45) Nepal Time'; +$lang['UP6'] = '(UTC +6:00) Bangladesh Standard Time, Bhutan Time, Omsk Time'; +$lang['UP65'] = '(UTC +6:30) Cocos Islands, Myanmar'; +$lang['UP7'] = '(UTC +7:00) Krasnoyarsk Time, Cambodia, Laos, Thailand, Vietnam'; +$lang['UP8'] = '(UTC +8:00) Australian Western Standard Time, Beijing Time, Irkutsk Time'; +$lang['UP875'] = '(UTC +8:45) Australian Central Western Standard Time'; +$lang['UP9'] = '(UTC +9:00) Japan Standard Time, Korea Standard Time, Yakutsk Time'; +$lang['UP95'] = '(UTC +9:30) Australian Central Standard Time'; +$lang['UP10'] = '(UTC +10:00) Australian Eastern Standard Time, Vladivostok Time'; +$lang['UP105'] = '(UTC +10:30) Lord Howe Island'; +$lang['UP11'] = '(UTC +11:00) Magadan Time, Solomon Islands, Vanuatu'; +$lang['UP115'] = '(UTC +11:30) Norfolk Island'; +$lang['UP12'] = '(UTC +12:00) Fiji, Gilbert Islands, Kamchatka Time, New Zealand Standard Time'; +$lang['UP1275'] = '(UTC +12:45) Chatham Islands Standard Time'; +$lang['UP13'] = '(UTC +13:00) Phoenix Islands Time, Tonga'; +$lang['UP14'] = '(UTC +14:00) Line Islands'; /* End of file date_lang.php */ /* Location: ./system/language/english/date_lang.php */ \ No newline at end of file -- cgit v1.2.3-24-g4f1b From cbde3f032de0f02fb28a5502a32c30626119716e Mon Sep 17 00:00:00 2001 From: Derek Jones Date: Thu, 14 Aug 2008 22:13:05 +0000 Subject: changed entity standardization to require at least two characters after an ampersand before forcing a semi-colon --- system/libraries/Input.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system') diff --git a/system/libraries/Input.php b/system/libraries/Input.php index 24c6c1967..ff1dd9b15 100644 --- a/system/libraries/Input.php +++ b/system/libraries/Input.php @@ -547,7 +547,7 @@ class CI_Input { * the conversion of entities to ASCII later. * */ - $str = preg_replace('#(&\#?[0-9a-z]+)[\x00-\x20]*;?#i', "\\1;", $str); + $str = preg_replace('#(&\#?[0-9a-z]{2,})[\x00-\x20]*;?#i', "\\1;", $str); /* * Validate UTF16 two byte encoding (x00) -- cgit v1.2.3-24-g4f1b From 9e2c04cf14fe8fb27d5ac520c95c68336255b2db Mon Sep 17 00:00:00 2001 From: Rick Ellis Date: Tue, 19 Aug 2008 22:12:26 +0000 Subject: Added current_url() and uri_string() functions to the URL helper --- system/helpers/url_helper.php | 42 ++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 40 insertions(+), 2 deletions(-) (limited to 'system') diff --git a/system/helpers/url_helper.php b/system/helpers/url_helper.php index 16dd3e021..e5b02972d 100644 --- a/system/helpers/url_helper.php +++ b/system/helpers/url_helper.php @@ -45,7 +45,7 @@ if ( ! function_exists('site_url')) return $CI->config->site_url($uri); } } - + // ------------------------------------------------------------------------ /** @@ -64,7 +64,45 @@ if ( ! function_exists('base_url')) return $CI->config->slash_item('base_url'); } } - + +// ------------------------------------------------------------------------ + +/** + * 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()); + } +} + +// ------------------------------------------------------------------------ +/** + * 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(); + } +} + // ------------------------------------------------------------------------ /** -- cgit v1.2.3-24-g4f1b From 34d191466fc1436c3ac4560880431ad3d97e9e91 Mon Sep 17 00:00:00 2001 From: Derek Allard Date: Wed, 20 Aug 2008 19:07:12 +0000 Subject: Changed the output of the profiler to use style attribute rather then clear, and added the id "codeigniter_profiler" to the container div --- system/libraries/Profiler.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'system') diff --git a/system/libraries/Profiler.php b/system/libraries/Profiler.php index da1fff19b..74461e6b2 100644 --- a/system/libraries/Profiler.php +++ b/system/libraries/Profiler.php @@ -322,8 +322,8 @@ class CI_Profiler { */ function run() { - $output = '
    '; - $output .= "
    "; + $output = '
    '; + $output .= "
    "; $output .= $this->_compile_memory_usage(); $output .= $this->_compile_benchmarks(); -- cgit v1.2.3-24-g4f1b From d6b0649f9815e9aefe1f2b6cd3b93dcca53cda80 Mon Sep 17 00:00:00 2001 From: Rick Ellis Date: Wed, 20 Aug 2008 22:07:30 +0000 Subject: Added two new functions: is_natural and is_natural_no_zero --- system/libraries/Validation.php | 30 +++++++++++++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) (limited to 'system') diff --git a/system/libraries/Validation.php b/system/libraries/Validation.php index f5e4d2223..a0423c7b6 100644 --- a/system/libraries/Validation.php +++ b/system/libraries/Validation.php @@ -614,7 +614,35 @@ class CI_Validation { { return (bool)preg_match( '/^[\-+]?[0-9]+$/', $str); } - + + // -------------------------------------------------------------------- + + /** + * Is a Natural number (0,1,2,3, etc.) + * + * @access public + * @param string + * @return bool + */ + function is_natural($str) + { + return (bool)preg_match( '/^[0-9]+$/', $str); + } + + // -------------------------------------------------------------------- + + /** + * Is a Natural number, but not a zero (1,2,3, etc.) + * + * @access public + * @param string + * @return bool + */ + function is_natural_no_zero($str) + { + return (bool)preg_match( '/^[1-9]+$/', $str); + } + // -------------------------------------------------------------------- /** -- cgit v1.2.3-24-g4f1b From 209ac23cbe2e0d78c07e3696171db6e6c47f1cf2 Mon Sep 17 00:00:00 2001 From: Rick Ellis Date: Wed, 20 Aug 2008 22:16:00 +0000 Subject: --- system/language/english/validation_lang.php | 33 ++++++++++++++++------------- 1 file changed, 18 insertions(+), 15 deletions(-) (limited to 'system') diff --git a/system/language/english/validation_lang.php b/system/language/english/validation_lang.php index 7da801d15..7ca762d72 100644 --- a/system/language/english/validation_lang.php +++ b/system/language/english/validation_lang.php @@ -1,20 +1,23 @@ Date: Wed, 20 Aug 2008 22:18:48 +0000 Subject: --- system/libraries/Validation.php | 60 ++++++++++++++++++++--------------------- 1 file changed, 30 insertions(+), 30 deletions(-) (limited to 'system') diff --git a/system/libraries/Validation.php b/system/libraries/Validation.php index a0423c7b6..c828328b6 100644 --- a/system/libraries/Validation.php +++ b/system/libraries/Validation.php @@ -589,17 +589,17 @@ class CI_Validation { // -------------------------------------------------------------------- - /** - * Is Numeric - * - * @access public - * @param string - * @return bool - */ - function is_numeric($str) - { - return ( ! is_numeric($str)) ? FALSE : TRUE; - } + /** + * Is Numeric + * + * @access public + * @param string + * @return bool + */ + function is_numeric($str) + { + return ( ! is_numeric($str)) ? FALSE : TRUE; + } // -------------------------------------------------------------------- @@ -617,31 +617,31 @@ class CI_Validation { // -------------------------------------------------------------------- - /** - * Is a Natural number (0,1,2,3, etc.) - * - * @access public - * @param string - * @return bool - */ - function is_natural($str) - { + /** + * Is a Natural number (0,1,2,3, etc.) + * + * @access public + * @param string + * @return bool + */ + function is_natural($str) + { return (bool)preg_match( '/^[0-9]+$/', $str); - } + } // -------------------------------------------------------------------- - /** - * Is a Natural number, but not a zero (1,2,3, etc.) - * - * @access public - * @param string - * @return bool - */ + /** + * Is a Natural number, but not a zero (1,2,3, etc.) + * + * @access public + * @param string + * @return bool + */ function is_natural_no_zero($str) - { + { return (bool)preg_match( '/^[1-9]+$/', $str); - } + } // -------------------------------------------------------------------- -- cgit v1.2.3-24-g4f1b From 44984d6b3e3ee7102d09f7be626e0029564cd56a Mon Sep 17 00:00:00 2001 From: Rick Ellis Date: Wed, 20 Aug 2008 22:26:07 +0000 Subject: Updated the Session class so that if a database is being used, any custom data is stored to the DB rather then the cookie. --- system/libraries/Session.php | 467 +++++++++++++++++++++++-------------------- 1 file changed, 254 insertions(+), 213 deletions(-) (limited to 'system') diff --git a/system/libraries/Session.php b/system/libraries/Session.php index 31a162e81..9907ade47 100644 --- a/system/libraries/Session.php +++ b/system/libraries/Session.php @@ -26,17 +26,24 @@ */ class CI_Session { + var $sess_encrypt_cookie = FALSE; + var $sess_use_database = FALSE; + var $sess_table_name = ''; + var $sess_expiration = 7200; + var $sess_match_ip = FALSE; + var $sess_match_useragent = TRUE; + var $sess_cookie_name = 'ci_session'; + var $cookie_prefix = ''; + var $cookie_path = ''; + var $cookie_domain = ''; + var $sess_time_to_update = 300; + var $encryption_key = ''; + var $flashdata_key = 'flash'; + var $time_reference = 'time'; + var $gc_probability = 5; + var $userdata = array(); var $CI; var $now; - var $encryption = TRUE; - var $use_database = FALSE; - var $session_table = FALSE; - var $sess_length = 7200; - var $sess_cookie = 'ci_session'; - var $userdata = array(); - var $gc_probability = 5; - var $flashdata_key = 'flash'; - var $time_to_update = 300; /** * Session Constructor @@ -44,132 +51,70 @@ class CI_Session { * The constructor runs the session routines automatically * whenever the class is instantiated. */ - function CI_Session() + function CI_Session($params = array()) { - $this->CI =& get_instance(); - log_message('debug', "Session Class Initialized"); - $this->sess_run(); - } - - // -------------------------------------------------------------------- - - /** - * Run the session routines - * - * @access public - * @return void - */ - function sess_run() - { - /* - * Set the "now" time - * - * It can either set to GMT or time(). The pref - * is set in the config file. If the developer - * is doing any sort of time localization they - * might want to set the session time to GMT so - * they can offset the "last_activity" time - * based on each user's locale. - * - */ - if (is_numeric($this->CI->config->item('sess_time_to_update'))) - { - $this->time_to_update = $this->CI->config->item('sess_time_to_update'); - } - - if (strtolower($this->CI->config->item('time_reference')) == 'gmt') - { - $now = time(); - $this->now = mktime(gmdate("H", $now), gmdate("i", $now), gmdate("s", $now), gmdate("m", $now), gmdate("d", $now), gmdate("Y", $now)); - - if (strlen($this->now) < 10) - { - $this->now = time(); - log_message('error', 'The session class could not set a proper GMT timestamp so the local time() value was used.'); - } - } - else - { - $this->now = time(); - } - - /* - * Set the session length - * - * If the session expiration is set to zero in - * the config file we'll set the expiration - * two years from now. - * - */ - $expiration = $this->CI->config->item('sess_expiration'); + // Set the super object to a local variable for use throughout the class + $this->CI =& get_instance(); - if (is_numeric($expiration)) + // 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_match_ip', 'sess_match_useragent', 'sess_cookie_name', 'cookie_path', 'cookie_domain', 'sess_time_to_update', 'time_reference', 'cookie_prefix', 'encryption_key') as $key) { - if ($expiration > 0) - { - $this->sess_length = $this->CI->config->item('sess_expiration'); - } - else - { - $this->sess_length = (60*60*24*365*2); - } - } - - // Do we need encryption? - $this->encryption = $this->CI->config->item('sess_encrypt_cookie'); + $this->$key = (isset($params[$key])) ? $params[$key] : $this->CI->config->item($key); + } - if ($this->encryption == TRUE) + // 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 ($this->CI->config->item('sess_use_database') === TRUE AND $this->CI->config->item('sess_table_name') != '') + // Are we using a database? If so, load it + if ($this->sess_use_database === TRUE AND $this->sess_table_name != '') { - $this->use_database = TRUE; - $this->session_table = $this->CI->config->item('sess_table_name'); $this->CI->load->database(); } - - // Set the cookie name - if ($this->CI->config->item('sess_cookie_name') != FALSE) + + // 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_cookie = $this->CI->config->item('cookie_prefix').$this->CI->config->item('sess_cookie_name'); + $this->sess_expiration = (60*60*24*365*2); } + + // Set the cookie name + $this->sess_cookie_name = $this->cookie_prefix.$this->sess_cookie_name; - /* - * Fetch the current session - * - * If a session doesn't exist we'll create - * a new one. If it does, we'll update it. - * - */ + // 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 { - // We only update the session every five minutes - if (($this->userdata['last_activity'] + $this->time_to_update) < $this->now) - { - $this->sess_update(); - } + $this->sess_update(); } - // Delete expired sessions if necessary - if ($this->use_database === TRUE) - { - $this->sess_gc(); - } - // 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"); } // -------------------------------------------------------------------- @@ -183,28 +128,28 @@ class CI_Session { function sess_read() { // Fetch the cookie - $session = $this->CI->input->cookie($this->sess_cookie); + $session = $this->CI->input->cookie($this->sess_cookie_name); + // No cookie? Goodbye cruel world!... if ($session === FALSE) { log_message('debug', 'A session cookie was not found.'); return FALSE; } - // Decrypt and unserialize the data - if ($this->encryption == TRUE) + // Decrypt the cookie data + if ($this->sess_encrypt_cookie == TRUE) { $session = $this->CI->encrypt->decode($session); } else { // encryption was not used, so we need to check the md5 hash - $hash = substr($session, strlen($session)-32); // get last 32 chars + $hash = substr($session, strlen($session)-32); // get last 32 chars $session = substr($session, 0, strlen($session)-32); - // Does the md5 hash match? This is to prevent manipulation of session data - // in userspace - if ($hash !== md5($session.$this->CI->config->item('encryption_key'))) + // Does the md5 hash match? This is to prevent manipulation of session data in userspace + if ($hash !== md5($session.$this->encryption_key)) { log_message('error', 'The session cookie data did not match what was expected. This could be a possible hacking attempt.'); $this->sess_destroy(); @@ -212,68 +157,75 @@ class CI_Session { } } - $session = @unserialize($this->strip_slashes($session)); + // Unserialize the session array + $session = @unserialize(strip_slashes($session)); - if ( ! is_array($session) OR ! isset($session['last_activity'])) + // Is the session data we unserialized and 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'])) { - log_message('error', 'The session cookie data did not contain a valid array. This could be a possible hacking attempt.'); + $this->sess_destroy(); return FALSE; } // Is the session current? - if (($session['last_activity'] + $this->sess_length) < $this->now) + if (($session['last_activity'] + $this->sess_expiration) < $this->now) { $this->sess_destroy(); return FALSE; } // Does the IP Match? - if ($this->CI->config->item('sess_match_ip') == TRUE AND $session['ip_address'] != $this->CI->input->ip_address()) + 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->CI->config->item('sess_match_useragent') == TRUE AND trim($session['user_agent']) != trim(substr($this->CI->input->user_agent(), 0, 50))) + if ($this->sess_match_useragent == TRUE AND trim($session['user_agent']) != trim(substr($this->CI->input->user_agent(), 0, 50))) { $this->sess_destroy(); return FALSE; } // Is there a corresponding session in the DB? - if ($this->use_database === TRUE) + if ($this->sess_use_database === TRUE) { $this->CI->db->where('session_id', $session['session_id']); - if ($this->CI->config->item('sess_match_ip') == TRUE) + if ($this->sess_match_ip == TRUE) { $this->CI->db->where('ip_address', $session['ip_address']); } - if ($this->CI->config->item('sess_match_useragent') == TRUE) + if ($this->sess_match_useragent == TRUE) { $this->CI->db->where('user_agent', $session['user_agent']); } - $query = $this->CI->db->get($this->session_table); + $query = $this->CI->db->get($this->sess_table_name); + // No result? Kill it! if ($query->num_rows() == 0) { $this->sess_destroy(); return FALSE; } - else + + // 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 != '') { - $row = $query->row(); - if (($row->last_activity + $this->sess_length) < $this->now) + $custom_data = @unserialize(strip_slashes($row->user_data)); + + if (is_array($custom_data)) { - $this->CI->db->where('session_id', $session['session_id']); - $this->CI->db->delete($this->session_table); - $this->sess_destroy(); - return FALSE; + foreach ($custom_data as $key => $val) + { + $session[$key] = $val; + } } - } + } } // Session is valid! @@ -286,35 +238,61 @@ class CI_Session { // -------------------------------------------------------------------- /** - * Write the session cookie + * Write the session data * * @access public * @return void */ function sess_write() - { - $cookie_data = serialize($this->userdata); + { + // 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; + } + + // We need two copies of the session data array. One will contain any custom data + // that might have been set. The other will contain the data that will be saved to the cookie + $cookie_userdata = $this->userdata; + $custom_userdata = $this->userdata; + + // 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 + foreach (array('session_id','ip_address','user_agent','last_activity') as $val) + { + unset($custom_userdata[$val]); + } - if ($this->encryption == TRUE) + // 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) { - $cookie_data = $this->CI->encrypt->encode($cookie_data); + $custom_userdata = ''; } else { - // if encryption is not used, we provide an md5 hash to prevent userside tampering - $cookie_data = $cookie_data . md5($cookie_data.$this->CI->config->item('encryption_key')); + // Before we serialize the custom data array, let's remove that data from the + // main session array since we do not want to save that info to the cookie + foreach (array_keys($custom_userdata) as $val) + { + unset($cookie_userdata[$val]); + } + + // Serialize the custom data array so we can store it + $custom_userdata = 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)); - setcookie( - $this->sess_cookie, - $cookie_data, - $this->sess_length + time(), - $this->CI->config->item('cookie_path'), - $this->CI->config->item('cookie_domain'), - 0 - ); + // 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); } - + // -------------------------------------------------------------------- /** @@ -330,6 +308,9 @@ class CI_Session { { $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)), @@ -339,14 +320,14 @@ class CI_Session { ); - // Save the session in the DB if needed - if ($this->use_database === TRUE) + // Save the data to the DB if needed + if ($this->sess_use_database === TRUE) { - $this->CI->db->query($this->CI->db->insert_string($this->session_table, $this->userdata)); + $this->CI->db->query($this->CI->db->insert_string($this->sess_table_name, $this->userdata)); } // Write the cookie - $this->sess_write(); + $this->_set_cookie(); } // -------------------------------------------------------------------- @@ -358,7 +339,13 @@ class CI_Session { * @return void */ function sess_update() - { + { + // We only update the session every five minutes by default + if (($this->userdata['last_activity'] + $this->sess_time_to_update) >= $this->now) + { + return; + } + // 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']; @@ -367,20 +354,25 @@ class CI_Session { { $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; - // Update the session in the DB if needed - if ($this->use_database === TRUE) - { - $this->CI->db->query($this->CI->db->update_string($this->session_table, array('last_activity' => $this->now, 'session_id' => $new_sessid), array('session_id' => $old_sessid))); + // Update the session ID and last_activity field in the DB if needed + if ($this->sess_use_database === TRUE) + { + $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->sess_write(); + $this->_set_cookie(); } // -------------------------------------------------------------------- @@ -392,44 +384,27 @@ class CI_Session { * @return void */ function sess_destroy() - { + { + // Kill the session DB row + if ($this->sess_use_database === TRUE AND 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, + $this->sess_cookie_name, addslashes(serialize(array())), ($this->now - 31500000), - $this->CI->config->item('cookie_path'), - $this->CI->config->item('cookie_domain'), + $this->cookie_path, + $this->cookie_domain, 0 ); } // -------------------------------------------------------------------- - /** - * Garbage collection - * - * This deletes expired session rows from database - * if the probability percentage is met - * - * @access public - * @return void - */ - function sess_gc() - { - srand(time()); - if ((rand() % 100) < $this->gc_probability) - { - $expire = $this->now - $this->sess_length; - - $this->CI->db->where("last_activity < {$expire}"); - $this->CI->db->delete($this->session_table); - - log_message('debug', 'Session garbage collection performed.'); - } - } - - // -------------------------------------------------------------------- - /** * Fetch a specific item from the session array * @@ -509,33 +484,6 @@ class CI_Session { $this->sess_write(); } - // -------------------------------------------------------------------- - - /** - * Strip slashes - * - * @access public - * @param mixed - * @return mixed - */ - function strip_slashes($vals) - { - if (is_array($vals)) - { - foreach ($vals as $key=>$val) - { - $vals[$key] = $this->strip_slashes($val); - } - } - else - { - $vals = stripslashes($vals); - } - - return $vals; - } - - // ------------------------------------------------------------------------ /** @@ -646,6 +594,99 @@ class CI_Session { } } + + // -------------------------------------------------------------------- + + /** + * 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 = serialize($cookie_data); + + if ($this->sess_encrypt_cookie == TRUE) + { + $cookie_data = $this->CI->encrypt->encode($cookie_data); + } + else + { + // if encryption is not used, we provide an md5 hash to prevent userside tampering + $cookie_data = $cookie_data.md5($cookie_data.$this->encryption_key); + } + + // Set the cookie + setcookie( + $this->sess_cookie_name, + $cookie_data, + $this->sess_expiration + time(), + $this->cookie_path, + $this->cookie_domain, + 0 + ); + } + + // -------------------------------------------------------------------- + + /** + * 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 -- cgit v1.2.3-24-g4f1b From 719b65d54a85337c5616a781eff07d5031c106e9 Mon Sep 17 00:00:00 2001 From: Rick Ellis Date: Thu, 21 Aug 2008 01:06:11 +0000 Subject: Fixed a bug in is_natural_no_zero --- system/libraries/Validation.php | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) (limited to 'system') diff --git a/system/libraries/Validation.php b/system/libraries/Validation.php index c828328b6..cae1a3f5a 100644 --- a/system/libraries/Validation.php +++ b/system/libraries/Validation.php @@ -640,7 +640,17 @@ class CI_Validation { */ function is_natural_no_zero($str) { - return (bool)preg_match( '/^[1-9]+$/', $str); + if ( ! preg_match( '/^[0-9]+$/', $str)) + { + return FALSE; + } + + if ($str == 0) + { + return FALSE; + } + + return TRUE; } // -------------------------------------------------------------------- -- cgit v1.2.3-24-g4f1b From 993925b47a0bfb08e79961c47bcc3d247a03a5dd Mon Sep 17 00:00:00 2001 From: Derek Allard Date: Thu, 21 Aug 2008 12:43:31 +0000 Subject: whitespace fixes a minor re-ordering of the changelog --- system/application/config/config.php | 2 +- system/application/config/constants.php | 2 +- system/application/config/user_agents.php | 6 +- system/codeigniter/Common.php | 10 +- system/database/DB.php | 3 +- system/database/DB_driver.php | 24 ++-- system/database/DB_result.php | 2 +- system/database/drivers/mysql/mysql_driver.php | 18 +-- system/database/drivers/oci8/oci8_result.php | 10 +- system/helpers/file_helper.php | 104 ++++++++-------- system/helpers/form_helper.php | 12 +- system/helpers/inflector_helper.php | 84 ++++++------- system/helpers/smiley_helper.php | 34 +++--- system/helpers/string_helper.php | 4 +- system/libraries/Controller.php | 12 +- system/libraries/Email.php | 6 +- system/libraries/Session.php | 158 ++++++++++++------------- system/libraries/Upload.php | 2 +- system/libraries/Validation.php | 22 ++-- system/libraries/Zip.php | 30 ++--- 20 files changed, 273 insertions(+), 272 deletions(-) (limited to 'system') diff --git a/system/application/config/config.php b/system/application/config/config.php index f8fd9c809..da7979788 100644 --- a/system/application/config/config.php +++ b/system/application/config/config.php @@ -149,7 +149,7 @@ $config['permitted_uri_chars'] = 'a-z 0-9~%.:_\-'; | */ $config['enable_query_strings'] = FALSE; -$config['directory_trigger'] = 'd'; // experimental not currently in use +$config['directory_trigger'] = 'd'; // experimental not currently in use $config['controller_trigger'] = 'c'; $config['function_trigger'] = 'm'; diff --git a/system/application/config/constants.php b/system/application/config/constants.php index 55dc6b777..3d317f58e 100644 --- a/system/application/config/constants.php +++ b/system/application/config/constants.php @@ -29,7 +29,7 @@ define('DIR_WRITE_MODE', 0777); define('FOPEN_READ', 'rb'); define('FOPEN_READ_WRITE', 'r+b'); -define('FOPEN_WRITE_CREATE_DESTRUCTIVE', 'wb'); // truncates existing file data, use with care +define('FOPEN_WRITE_CREATE_DESTRUCTIVE', 'wb'); // truncates existing file data, use with care define('FOPEN_READ_WRITE_CREATE_DESTRUCTIVE', 'w+b'); // truncates existing file data, use with care define('FOPEN_WRITE_CREATE', 'ab'); define('FOPEN_READ_WRITE_CREATE', 'a+b'); diff --git a/system/application/config/user_agents.php b/system/application/config/user_agents.php index d350af3aa..38bfc1f72 100644 --- a/system/application/config/user_agents.php +++ b/system/application/config/user_agents.php @@ -163,12 +163,12 @@ $mobiles = array( $robots = array( 'googlebot' => 'Googlebot', 'msnbot' => 'MSNBot', - 'slurp' => 'Inktomi Slurp', - 'yahoo' => 'Yahoo', + 'slurp' => 'Inktomi Slurp', + 'yahoo' => 'Yahoo', 'askjeeves' => 'AskJeeves', 'fastcrawler' => 'FastCrawler', 'infoseek' => 'InfoSeek Robot 1.0', - 'lycos' => 'Lycos' + 'lycos' => 'Lycos' ); /* End of file user_agents.php */ diff --git a/system/codeigniter/Common.php b/system/codeigniter/Common.php index b0df52921..8f4f9a941 100644 --- a/system/codeigniter/Common.php +++ b/system/codeigniter/Common.php @@ -93,16 +93,16 @@ function &load_class($class, $instantiate = TRUE) // folder we'll load the native class from the system/libraries folder. if (file_exists(APPPATH.'libraries/'.config_item('subclass_prefix').$class.EXT)) { - require(BASEPATH.'libraries/'.$class.EXT); + require(BASEPATH.'libraries/'.$class.EXT); require(APPPATH.'libraries/'.config_item('subclass_prefix').$class.EXT); - $is_subclass = TRUE; + $is_subclass = TRUE; } else { if (file_exists(APPPATH.'libraries/'.$class.EXT)) { - require(APPPATH.'libraries/'.$class.EXT); - $is_subclass = FALSE; + require(APPPATH.'libraries/'.$class.EXT); + $is_subclass = FALSE; } else { @@ -241,7 +241,7 @@ function log_message($level = 'error', $message, $php_error = FALSE) return; } - $LOG =& load_class('Log'); + $LOG =& load_class('Log'); $LOG->write_log($level, $message, $php_error); } diff --git a/system/database/DB.php b/system/database/DB.php index eb25273a1..ef67c80c8 100644 --- a/system/database/DB.php +++ b/system/database/DB.php @@ -44,8 +44,7 @@ function &DB($params = '', $active_record_override = FALSE) show_error('You have specified an invalid database connection group.'); } - $params = $db[$active_group]; - } + $params = $db[$active_group] } elseif (is_string($params)) { diff --git a/system/database/DB_driver.php b/system/database/DB_driver.php index 60f51d757..1678cffd5 100644 --- a/system/database/DB_driver.php +++ b/system/database/DB_driver.php @@ -142,7 +142,7 @@ class CI_DB_driver { { $this->display_error('db_unable_to_create', $this->database); } - return FALSE; + return FALSE; } else { @@ -221,7 +221,7 @@ class CI_DB_driver { { return $this->display_error('db_unsupported_function'); } - return FALSE; + return FALSE; } if ($this->dbdriver == 'oci8') @@ -258,7 +258,7 @@ class CI_DB_driver { log_message('error', 'Invalid query: '.$sql); return $this->display_error('db_invalid_query'); } - return FALSE; + return FALSE; } // Verify table prefix and replace if necessary @@ -543,12 +543,12 @@ class CI_DB_driver { $this->_trans_status = TRUE; } - log_message('debug', 'DB Transaction Failure'); - return FALSE; + log_message('debug', 'DB Transaction Failure'); + return FALSE; } $this->trans_commit(); - return TRUE; + return TRUE; } // -------------------------------------------------------------------- @@ -755,7 +755,7 @@ class CI_DB_driver { { return $this->display_error('db_unsupported_function'); } - return FALSE; + return FALSE; } $retval = array(); @@ -815,7 +815,7 @@ class CI_DB_driver { { return $this->display_error('db_field_param_missing'); } - return FALSE; + return FALSE; } if (FALSE === ($sql = $this->_list_columns($this->prep_tablename($table)))) @@ -824,7 +824,7 @@ class CI_DB_driver { { return $this->display_error('db_unsupported_function'); } - return FALSE; + return FALSE; } $query = $this->query($sql); @@ -887,7 +887,7 @@ class CI_DB_driver { { return $this->display_error('db_field_param_missing'); } - return FALSE; + return FALSE; } $query = $this->query($this->_field_data($this->prep_tablename($table))); @@ -906,7 +906,7 @@ class CI_DB_driver { */ function insert_string($table, $data) { - $fields = array(); + $fields = array(); $values = array(); foreach($data as $key => $val) @@ -1039,7 +1039,7 @@ class CI_DB_driver { { return $this->display_error('db_unsupported_function'); } - return FALSE; + return FALSE; } else { diff --git a/system/database/DB_result.php b/system/database/DB_result.php index d8d0d0d97..2a7824ff5 100644 --- a/system/database/DB_result.php +++ b/system/database/DB_result.php @@ -104,7 +104,7 @@ class CI_DB_result { return array(); } - $this->_data_seek(0); + $this->_data_seek(0); while ($row = $this->_fetch_assoc()) { $this->result_array[] = $row; diff --git a/system/database/drivers/mysql/mysql_driver.php b/system/database/drivers/mysql/mysql_driver.php index 8df6c1b70..889ea17fb 100644 --- a/system/database/drivers/mysql/mysql_driver.php +++ b/system/database/drivers/mysql/mysql_driver.php @@ -246,15 +246,15 @@ class CI_DB_mysql_driver extends CI_DB { function escape_str($str) { if (is_array($str)) - { - foreach($str as $key => $val) - { - $str[$key] = $this->escape_str($val); - } - - return $str; - } - + { + foreach($str as $key => $val) + { + $str[$key] = $this->escape_str($val); + } + + return $str; + } + if (function_exists('mysql_real_escape_string') AND is_resource($this->conn_id)) { return mysql_real_escape_string($str, $this->conn_id); diff --git a/system/database/drivers/oci8/oci8_result.php b/system/database/drivers/oci8/oci8_result.php index 73373c882..20ab925fd 100644 --- a/system/database/drivers/oci8/oci8_result.php +++ b/system/database/drivers/oci8/oci8_result.php @@ -42,13 +42,15 @@ class CI_DB_oci8_result extends CI_DB_result { */ function num_rows() { - $rowcount = count($this->result_array()); - @ociexecute($this->stmt_id); - if ($this->curs_id) + $rowcount = count($this->result_array()); + @ociexecute($this->stmt_id); + + if ($this->curs_id) { @ociexecute($this->curs_id); } - return $rowcount; + + return $rowcount; } // -------------------------------------------------------------------- diff --git a/system/helpers/file_helper.php b/system/helpers/file_helper.php index 86c5c09db..b59443c0e 100644 --- a/system/helpers/file_helper.php +++ b/system/helpers/file_helper.php @@ -262,60 +262,60 @@ if ( ! function_exists('get_dir_file_info')) * 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 -*/ +* @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, '/'), 1); - break; - case 'server_path': - $fileinfo['server_path'] = $file; - break; - case 'size': - $fileinfo['size'] = filesize($file); - break; - case 'date': - $fileinfo['date'] = filectime($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; - } + 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, '/'), 1); + break; + case 'server_path': + $fileinfo['server_path'] = $file; + break; + case 'size': + $fileinfo['size'] = filesize($file); + break; + case 'date': + $fileinfo['date'] = filectime($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; + } } // -------------------------------------------------------------------- diff --git a/system/helpers/form_helper.php b/system/helpers/form_helper.php index 0ad57d532..0c74ac0ff 100644 --- a/system/helpers/form_helper.php +++ b/system/helpers/form_helper.php @@ -53,7 +53,7 @@ if ( ! function_exists('form_open')) $form = '
    (( ! is_array($data)) ? $data : ''), 'cols' => '90', 'rows' => '12'); - if ( ! is_array($data) OR ! isset($data['value'])) + if ( ! is_array($data) OR ! isset($data['value'])) { $val = $value; } - else + else { $val = $data['value']; unset($data['value']); // textareas don't use the value attribute @@ -466,7 +466,7 @@ if ( ! function_exists('form_fieldset')) { $fieldset = " 0) diff --git a/system/helpers/inflector_helper.php b/system/helpers/inflector_helper.php index 49ba542a1..e362a3fd7 100644 --- a/system/helpers/inflector_helper.php +++ b/system/helpers/inflector_helper.php @@ -41,28 +41,28 @@ if ( ! function_exists('singular')) { function singular($str) { - $str = strtolower(trim($str)); - $end = substr($str, -3); - - if ($end == 'ies') - { - $str = substr($str, 0, strlen($str)-3).'y'; - } - elseif ($end == 'ses') - { - $str = substr($str, 0, strlen($str)-2); - } - else - { - $end = substr($str, -1); - - if ($end == 's') - { - $str = substr($str, 0, strlen($str)-1); - } - } - - return $str; + $str = strtolower(trim($str)); + $end = substr($str, -3); + + if ($end == 'ies') + { + $str = substr($str, 0, strlen($str)-3).'y'; + } + elseif ($end == 'ses') + { + $str = substr($str, 0, strlen($str)-2); + } + else + { + $end = substr($str, -1); + + if ($end == 's') + { + $str = substr($str, 0, strlen($str)-1); + } + } + + return $str; } } @@ -82,26 +82,26 @@ if ( ! function_exists('plural')) { function plural($str, $force = FALSE) { - $str = strtolower(trim($str)); - $end = substr($str, -1); - - if ($end == 'y') - { - $str = substr($str, 0, strlen($str)-1).'ies'; - } - elseif ($end == 's') - { - if ($force == TRUE) - { - $str .= 'es'; - } - } - else - { - $str .= 's'; - } - - return $str; + $str = strtolower(trim($str)); + $end = substr($str, -1); + + if ($end == 'y') + { + $str = substr($str, 0, strlen($str)-1).'ies'; + } + elseif ($end == 's') + { + if ($force == TRUE) + { + $str .= 'es'; + } + } + else + { + $str .= 's'; + } + + return $str; } } diff --git a/system/helpers/smiley_helper.php b/system/helpers/smiley_helper.php index 8f7543746..efa338467 100644 --- a/system/helpers/smiley_helper.php +++ b/system/helpers/smiley_helper.php @@ -36,7 +36,7 @@ * @param string form name * @param string field name * @return string - */ + */ if ( ! function_exists('js_insert_smiley')) { function js_insert_smiley($form_name = '', $form_field = '') @@ -49,7 +49,7 @@ if ( ! function_exists('js_insert_smiley')) } EOF; - } + } } // ------------------------------------------------------------------------ @@ -62,7 +62,7 @@ EOF; * @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 = '', $smileys = NULL) @@ -72,12 +72,12 @@ if ( ! function_exists('get_clickable_smileys')) if (FALSE === ($smileys = _get_smiley_array())) { return $smileys; - } + } } // Add a trailing slash to the file path if needed $image_url = preg_replace("/(.+?)\/*$/", "\\1/", $image_url); - + $used = array(); foreach ($smileys as $key => $val) { @@ -89,12 +89,12 @@ if ( ! function_exists('get_clickable_smileys')) { continue; } - - $link[] = "\"".$smileys[$key][3]."\""; - + + $link[] = "\"".$smileys[$key][3]."\""; + $used[$smileys[$key][0]] = TRUE; } - + return $link; } } @@ -110,7 +110,7 @@ if ( ! function_exists('get_clickable_smileys')) * @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) @@ -125,17 +125,17 @@ if ( ! function_exists('parse_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; } } @@ -149,7 +149,7 @@ if ( ! function_exists('parse_smileys')) * * @access private * @return mixed - */ + */ if ( ! function_exists('_get_smiley_array')) { function _get_smiley_array() @@ -160,12 +160,12 @@ if ( ! function_exists('_get_smiley_array')) } include(APPPATH.'config/smileys'.EXT); - + if ( ! isset($smileys) OR ! is_array($smileys)) { return FALSE; } - + return $smileys; } } diff --git a/system/helpers/string_helper.php b/system/helpers/string_helper.php index 7b6becffe..d85d76ca4 100644 --- a/system/helpers/string_helper.php +++ b/system/helpers/string_helper.php @@ -46,7 +46,7 @@ if ( ! function_exists('trim_slashes')) { function trim_slashes($str) { - return trim($str, '/'); + return trim($str, '/'); } } @@ -173,7 +173,7 @@ if ( ! function_exists('reduce_multiples')) { $str = trim($str, $character); } - + return $str; } } diff --git a/system/libraries/Controller.php b/system/libraries/Controller.php index 5c96c577a..f9c6bd270 100644 --- a/system/libraries/Controller.php +++ b/system/libraries/Controller.php @@ -87,12 +87,12 @@ class Controller extends CI_Base { // sync up the objects since PHP4 was working from a copy foreach (array_keys(get_object_vars($this)) as $attribute) - { - if (is_object($this->$attribute)) - { - $this->load->$attribute =& $this->$attribute; - } - } + { + if (is_object($this->$attribute)) + { + $this->load->$attribute =& $this->$attribute; + } + } } } diff --git a/system/libraries/Email.php b/system/libraries/Email.php index b0d9f1269..ca1093a9b 100644 --- a/system/libraries/Email.php +++ b/system/libraries/Email.php @@ -1169,7 +1169,7 @@ class CI_Email { // Standardize newlines if (strpos($str, "\r") !== FALSE) { - $str = str_replace(array("\r\n", "\r"), "\n", $str); + $str = str_replace(array("\r\n", "\r"), "\n", $str); } // We are intentionally wrapping so mail servers will encode characters @@ -1179,8 +1179,8 @@ class CI_Email { // Break into an array of lines $lines = explode("\n", $str); - $escape = '='; - $output = ''; + $escape = '='; + $output = ''; foreach ($lines as $line) { diff --git a/system/libraries/Session.php b/system/libraries/Session.php index 9907ade47..9fad08cf9 100644 --- a/system/libraries/Session.php +++ b/system/libraries/Session.php @@ -69,10 +69,10 @@ class CI_Session { $this->CI->load->helper('string'); // Do we need encryption? If so, load the encryption class - if ($this->sess_encrypt_cookie == TRUE) + 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 != '') @@ -106,10 +106,10 @@ class CI_Session { } // 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(); + $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(); @@ -361,7 +361,7 @@ class CI_Session { // Turn it into a hash $new_sessid = md5(uniqid($new_sessid, TRUE)); - // Update the session data in the session data array + // Update the session data in the session data array $this->userdata['session_id'] = $new_sessid; $this->userdata['last_activity'] = $this->now; @@ -427,7 +427,7 @@ class CI_Session { */ function all_userdata() { - return ( ! isset($this->userdata)) ? FALSE : $this->userdata; + return ( ! isset($this->userdata)) ? FALSE : $this->userdata; } // -------------------------------------------------------------------- @@ -484,9 +484,9 @@ class CI_Session { $this->sess_write(); } - // ------------------------------------------------------------------------ + // ------------------------------------------------------------------------ - /** + /** * Add or change flashdata, only available * until the next request * @@ -495,46 +495,46 @@ class CI_Session { * @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. + 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) - { + */ + 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); + $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); - } + $new_flashdata_key = $this->flashdata_key.':new:'.$key; + $this->set_userdata($new_flashdata_key, $value); + } - // ------------------------------------------------------------------------ + // ------------------------------------------------------------------------ /** * Fetch a specific flashdata item from the session array @@ -543,57 +543,57 @@ class CI_Session { * @param string * @return string */ - function flashdata($key) - { - $flashdata_key = $this->flashdata_key.':old:'.$key; - return $this->userdata($flashdata_key); - } + function flashdata($key) + { + $flashdata_key = $this->flashdata_key.':old:'.$key; + return $this->userdata($flashdata_key); + } - // ------------------------------------------------------------------------ + // ------------------------------------------------------------------------ - /** - * Identifies flashdata as 'old' for removal + /** + * Identifies flashdata as 'old' for removal * when _flashdata_sweep() runs. * * @access private * @return void - */ - function _flashdata_mark() - { + */ + 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' + 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() - { + function _flashdata_sweep() + { $userdata = $this->all_userdata(); - foreach ($userdata as $key => $value) - { - if (strpos($key, ':old:')) - { - $this->unset_userdata($key); - } - } - - } + foreach ($userdata as $key => $value) + { + if (strpos($key, ':old:')) + { + $this->unset_userdata($key); + } + } + + } // -------------------------------------------------------------------- diff --git a/system/libraries/Upload.php b/system/libraries/Upload.php index 25e143567..4a615352e 100644 --- a/system/libraries/Upload.php +++ b/system/libraries/Upload.php @@ -836,7 +836,7 @@ class CI_Upload { * Prep Filename * * Prevents possible script execution from Apache's handling of files multiple extensions - * http://httpd.apache.org/docs/1.3/mod/mod_mime.html#multipleext + * http://httpd.apache.org/docs/1.3/mod/mod_mime.html#multipleext * * @access private * @param string diff --git a/system/libraries/Validation.php b/system/libraries/Validation.php index cae1a3f5a..b42d0e06d 100644 --- a/system/libraries/Validation.php +++ b/system/libraries/Validation.php @@ -640,17 +640,17 @@ class CI_Validation { */ function is_natural_no_zero($str) { - if ( ! preg_match( '/^[0-9]+$/', $str)) - { - return FALSE; - } - - if ($str == 0) - { - return FALSE; - } - - return TRUE; + if ( ! preg_match( '/^[0-9]+$/', $str)) + { + return FALSE; + } + + if ($str == 0) + { + return FALSE; + } + + return TRUE; } // -------------------------------------------------------------------- diff --git a/system/libraries/Zip.php b/system/libraries/Zip.php index 8958b572c..6ca9cfb50 100644 --- a/system/libraries/Zip.php +++ b/system/libraries/Zip.php @@ -34,8 +34,8 @@ class CI_Zip { var $zipdata = ''; var $directory = ''; - var $entries = 0; - var $file_num = 0; + var $entries = 0; + var $file_num = 0; var $offset = 0; function CI_Zip() @@ -320,16 +320,16 @@ class CI_Zip { */ function download($filename = 'backup.zip') { - if ( ! preg_match("|.+?\.zip$|", $filename)) - { - $filename .= '.zip'; - } + if ( ! preg_match("|.+?\.zip$|", $filename)) + { + $filename .= '.zip'; + } + + $zip_content =& $this->get_zip(); - $zip_content =& $this->get_zip(); + $CI =& get_instance(); + $CI->load->helper('download'); - $CI =& get_instance(); - $CI->load->helper('download'); - force_download($filename, $zip_content); } @@ -346,11 +346,11 @@ class CI_Zip { */ function clear_data() { - $this->zipdata = ''; - $this->directory = ''; - $this->entries = 0; - $this->file_num = 0; - $this->offset = 0; + $this->zipdata = ''; + $this->directory = ''; + $this->entries = 0; + $this->file_num = 0; + $this->offset = 0; } } -- cgit v1.2.3-24-g4f1b From 6ad532917aa69d86db70f0da4a3b196003926fe9 Mon Sep 17 00:00:00 2001 From: Rick Ellis Date: Thu, 21 Aug 2008 18:31:28 +0000 Subject: Added the ability to assign a custom object name when loading a library. Added some code that looks to see if a library is in a subdirectory if the class is not found, and if the path was not specified --- system/libraries/Loader.php | 65 ++++++++++++++++++++++++++++++++++++++------- 1 file changed, 56 insertions(+), 9 deletions(-) (limited to 'system') diff --git a/system/libraries/Loader.php b/system/libraries/Loader.php index e5640b070..e090cc09c 100644 --- a/system/libraries/Loader.php +++ b/system/libraries/Loader.php @@ -69,9 +69,10 @@ class CI_Loader { * @access public * @param string the name of the class * @param mixed the optional parameters + * @param string an optional object name * @return void */ - function library($library = '', $params = NULL) + function library($library = '', $params = NULL, $object_name = NULL) { if ($library == '') { @@ -87,7 +88,7 @@ class CI_Loader { } else { - $this->_ci_load_class($library, $params); + $this->_ci_load_class($library, $params, $object_name); } $this->_ci_assign_to_models(); @@ -329,8 +330,13 @@ class CI_Loader { * @param array * @return void */ - function vars($vars = array()) + 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) @@ -753,9 +759,10 @@ class CI_Loader { * @access private * @param string the item that is being loaded * @param mixed any additional parameters + * @param string an optional object name * @return void */ - function _ci_load_class($class, $params = NULL) + 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, @@ -799,6 +806,18 @@ class CI_Loader { // Safety: Was the class already loaded by a previous call? if (in_array($subclass, $this->_ci_classes)) { + // 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; @@ -808,7 +827,7 @@ class CI_Loader { include_once($subclass); $this->_ci_classes[] = $subclass; - return $this->_ci_init_class($class, config_item('subclass_prefix'), $params); + return $this->_ci_init_class($class, config_item('subclass_prefix'), $params, $object_name); } // Lets search for the requested library file and load it. @@ -827,6 +846,18 @@ class CI_Loader { // Safety: Was the class already loaded by a previous call? if (in_array($filepath, $this->_ci_classes)) { + // 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; @@ -834,9 +865,16 @@ class CI_Loader { include_once($filepath); $this->_ci_classes[] = $filepath; - return $this->_ci_init_class($class, '', $params); + 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 @@ -855,9 +893,10 @@ class CI_Loader { * @access private * @param string * @param string + * @param string an optional object name * @return null */ - function _ci_init_class($class, $prefix = '', $config = FALSE) + function _ci_init_class($class, $prefix = '', $config = FALSE, $object_name = NULL) { $class = strtolower($class); @@ -879,8 +918,16 @@ class CI_Loader { $name = $prefix.$class; } - // Set the variable name we will assign the class to - $classvar = ( ! isset($this->_ci_varmap[$class])) ? $class : $this->_ci_varmap[$class]; + // Set the variable name we will assign the class to + // Was a custom class name supplied? If so we'll use it + if (is_null($object_name)) + { + $classvar = ( ! isset($this->_ci_varmap[$class])) ? $class : $this->_ci_varmap[$class]; + } + else + { + $classvar = $object_name; + } // Instantiate the class $CI =& get_instance(); -- cgit v1.2.3-24-g4f1b From 65f46063afcebbe92a8ad67d9092bb073f79b8ce Mon Sep 17 00:00:00 2001 From: Rick Ellis Date: Thu, 21 Aug 2008 18:55:09 +0000 Subject: Added a bit more error trapping in the load() function --- system/libraries/Loader.php | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'system') diff --git a/system/libraries/Loader.php b/system/libraries/Loader.php index e090cc09c..1d88841dd 100644 --- a/system/libraries/Loader.php +++ b/system/libraries/Loader.php @@ -79,6 +79,11 @@ class CI_Loader { return FALSE; } + if ( ! is_null($params) AND ! is_array($params)) + { + $params = NULL; + } + if (is_array($library)) { foreach ($library as $class) -- cgit v1.2.3-24-g4f1b From f65308f36173d7924f1460e0383e5a6c46e626b5 Mon Sep 17 00:00:00 2001 From: Derek Allard Date: Thu, 21 Aug 2008 23:11:23 +0000 Subject: fixed a missing semi colon --- system/database/DB.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'system') diff --git a/system/database/DB.php b/system/database/DB.php index ef67c80c8..2dd86e14e 100644 --- a/system/database/DB.php +++ b/system/database/DB.php @@ -44,7 +44,8 @@ function &DB($params = '', $active_record_override = FALSE) show_error('You have specified an invalid database connection group.'); } - $params = $db[$active_group] } + $params = $db[$active_group]; + } elseif (is_string($params)) { -- cgit v1.2.3-24-g4f1b From edc41b55c343af2f03fb6fce6fd707c8b1b986fc Mon Sep 17 00:00:00 2001 From: Rick Ellis Date: Fri, 22 Aug 2008 07:16:47 +0000 Subject: Fixed a comment typo --- system/libraries/Session.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system') diff --git a/system/libraries/Session.php b/system/libraries/Session.php index 9fad08cf9..ab14bfe1a 100644 --- a/system/libraries/Session.php +++ b/system/libraries/Session.php @@ -160,7 +160,7 @@ class CI_Session { // Unserialize the session array $session = @unserialize(strip_slashes($session)); - // Is the session data we unserialized and array with the correct format? + // 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(); -- cgit v1.2.3-24-g4f1b From 7cdef03633cf8cc40678fc837ccec2d2164caade Mon Sep 17 00:00:00 2001 From: Rick Ellis Date: Tue, 26 Aug 2008 18:44:54 +0000 Subject: Made a Loader changes so that the new validation class will work. Made some doc style changes --- system/libraries/Loader.php | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) (limited to 'system') diff --git a/system/libraries/Loader.php b/system/libraries/Loader.php index 1d88841dd..b870ffbae 100644 --- a/system/libraries/Loader.php +++ b/system/libraries/Loader.php @@ -35,6 +35,7 @@ class CI_Loader { var $_ci_is_instance = FALSE; // Whether we should use $this or $CI =& get_instance() var $_ci_cached_vars = array(); var $_ci_classes = array(); + var $_ci_loaded_files = array(); var $_ci_models = array(); var $_ci_helpers = array(); var $_ci_plugins = array(); @@ -809,7 +810,7 @@ class CI_Loader { } // Safety: Was the class already loaded by a previous call? - if (in_array($subclass, $this->_ci_classes)) + 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 @@ -830,7 +831,7 @@ class CI_Loader { include_once($baseclass); include_once($subclass); - $this->_ci_classes[] = $subclass; + $this->_ci_loaded_files[] = $subclass; return $this->_ci_init_class($class, config_item('subclass_prefix'), $params, $object_name); } @@ -849,7 +850,7 @@ class CI_Loader { } // Safety: Was the class already loaded by a previous call? - if (in_array($filepath, $this->_ci_classes)) + 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 @@ -869,7 +870,7 @@ class CI_Loader { } include_once($filepath); - $this->_ci_classes[] = $filepath; + $this->_ci_loaded_files[] = $filepath; return $this->_ci_init_class($class, '', $params, $object_name); } } // END FOREACH @@ -933,7 +934,10 @@ class CI_Loader { { $classvar = $object_name; } - + + // Save the class name and object name + $this->_ci_classes[$class] = $object_name; + // Instantiate the class $CI =& get_instance(); if ($config !== NULL) -- cgit v1.2.3-24-g4f1b From 6945097110d174950b13d3d8407f8c0282a178af Mon Sep 17 00:00:00 2001 From: Rick Ellis Date: Tue, 26 Aug 2008 18:51:19 +0000 Subject: --- system/libraries/Loader.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system') diff --git a/system/libraries/Loader.php b/system/libraries/Loader.php index b870ffbae..644c49345 100644 --- a/system/libraries/Loader.php +++ b/system/libraries/Loader.php @@ -89,7 +89,7 @@ class CI_Loader { { foreach ($library as $class) { - $this->_ci_load_class($class, $params); + $this->_ci_load_class($class, $params, $object_name); } } else -- cgit v1.2.3-24-g4f1b From 76c504e13bc03fa38823e32603706860727d341b Mon Sep 17 00:00:00 2001 From: Rick Ellis Date: Tue, 26 Aug 2008 19:11:34 +0000 Subject: Made some changes for compatibility with the new form validation class --- system/libraries/Loader.php | 93 ++++++++++++++++----------------------------- 1 file changed, 32 insertions(+), 61 deletions(-) (limited to 'system') diff --git a/system/libraries/Loader.php b/system/libraries/Loader.php index 644c49345..550235737 100644 --- a/system/libraries/Loader.php +++ b/system/libraries/Loader.php @@ -39,7 +39,6 @@ class CI_Loader { var $_ci_models = array(); var $_ci_helpers = array(); var $_ci_plugins = array(); - var $_ci_scripts = array(); var $_ci_varmap = array('unit_test' => 'unit', 'user_agent' => 'agent'); @@ -74,7 +73,7 @@ class CI_Loader { * @return void */ function library($library = '', $params = NULL, $object_name = NULL) - { + { if ($library == '') { return FALSE; @@ -107,6 +106,7 @@ class CI_Loader { * * This function lets users load and instantiate models. * + * @access public * @param string the name of the class * @param string name for the model * @param bool database connection @@ -375,7 +375,7 @@ class CI_Loader { foreach ($helpers as $helper) { $helper = strtolower(str_replace(EXT, '', str_replace('_helper', '', $helper)).'_helper'); - + if (isset($this->_ci_helpers[$helper])) { continue; @@ -413,10 +413,8 @@ class CI_Loader { } $this->_ci_helpers[$helper] = TRUE; - - } - - log_message('debug', 'Helpers loaded: '.implode(', ', $helpers)); + log_message('debug', 'Helper loaded: '.$helper); + } } // -------------------------------------------------------------------- @@ -480,9 +478,8 @@ class CI_Loader { } $this->_ci_plugins[$plugin] = TRUE; - } - - log_message('debug', 'Plugins loaded: '.implode(', ', $plugins)); + log_message('debug', 'Plugin loaded: '.$plugin); + } } // -------------------------------------------------------------------- @@ -501,48 +498,6 @@ class CI_Loader { { $this->plugin($plugins); } - - // -------------------------------------------------------------------- - - /** - * Load Script - * - * This function loads the specified include file from the - * application/scripts/ folder. - * - * NOTE: This feature has been deprecated but it will remain available - * for legacy users. - * - * @access public - * @param array - * @return void - */ - function script($scripts = array()) - { - if ( ! is_array($scripts)) - { - $scripts = array($scripts); - } - - foreach ($scripts as $script) - { - $script = strtolower(str_replace(EXT, '', $script)); - - if (isset($this->_ci_scripts[$script])) - { - continue; - } - - if ( ! file_exists(APPPATH.'scripts/'.$script.EXT)) - { - show_error('Unable to load the requested script: scripts/'.$script.EXT); - } - - include_once(APPPATH.'scripts/'.$script.EXT); - } - - log_message('debug', 'Scripts loaded: '.implode(', ', $scripts)); - } // -------------------------------------------------------------------- @@ -822,8 +777,8 @@ class CI_Loader { { 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; @@ -904,8 +859,6 @@ class CI_Loader { */ function _ci_init_class($class, $prefix = '', $config = FALSE, $object_name = NULL) { - $class = strtolower($class); - // Is there an associated config file for this class? if ($config === NULL) { @@ -916,16 +869,36 @@ class CI_Loader { } if ($prefix == '') - { - $name = (class_exists('CI_'.$class)) ? 'CI_'.$class : $class; + { + 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-existant class: ".$name); + show_error("Non-existant 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]; @@ -990,8 +963,6 @@ class CI_Loader { } } - - // A little tweak to remain backward compatible // The $autoload['core'] item was deprecated if ( ! isset($autoload['libraries'])) @@ -1101,7 +1072,7 @@ class CI_Loader { global $CI; return (is_object($CI)) ? TRUE : FALSE; } - + } /* End of file Loader.php */ -- cgit v1.2.3-24-g4f1b From ec1b70f47e2161cf98bf0cad3d57368d2ca762dc Mon Sep 17 00:00:00 2001 From: Rick Ellis Date: Tue, 26 Aug 2008 19:21:27 +0000 Subject: --- system/libraries/Form_validation.php | 1220 ++++++++++++++++++++++++++++++++++ 1 file changed, 1220 insertions(+) create mode 100644 system/libraries/Form_validation.php (limited to 'system') diff --git a/system/libraries/Form_validation.php b/system/libraries/Form_validation.php new file mode 100644 index 000000000..fd0c22ec1 --- /dev/null +++ b/system/libraries/Form_validation.php @@ -0,0 +1,1220 @@ +'; + var $_error_suffix = '

    '; + var $error_string = ''; + var $_safe_form_data = FALSE; + + + /** + * Constructor + * + */ + function CI_Form_validation($rules = array()) + { + $this->CI =& get_instance(); + + // Validation rules can be stored in a config file. + $this->_config_rules = $rules; + + // Automatically load the form helper + $this->CI->load->helper('form'); + + log_message('debug', "Validation Class Initialized"); + } + + // -------------------------------------------------------------------- + + /** + * Set Rules + * + * This function takes an array of field names and validation + * rules as input, validates the info, and stores it + * + * @access public + * @param mixed + * @param string + * @return void + */ + function set_rules($field, $label = '', $rules = '') + { + // No reason to set rules if we have no POST data + if (count($_POST) == 0) + { + return; + } + + // If an array was passed via the first parameter instead of indidual string + // values we cycle through it and recursively call this function. + if (is_array($field)) + { + foreach ($field as $row) + { + // Houston, we have a problem... + if ( ! isset($row['field']) OR ! isset($row['rules'])) + { + continue; + } + + // If the field label wasn't passed we use the field name + $label = ( ! isset($row['label'])) ? $row['field'] : $row['label']; + + // Here we go! + $this->set_rules($row['field'], $label, $row['rules']); + } + return; + } + + // No rules or fields? Nothing to do... + if ( ! is_string($field) OR ! is_string($rules) OR $field == '' OR $rules == '') + { + return; + } + + // If the field label wasn't passed we use the field name + $label = ($label == '') ? $field : $label; + + // Is the field name an array? We test for the existence of a bracket "[" in + // the field name to determine this. If it is an array, we break it apart + // into its components so that we can fetch the corresponding POST data later + if (strpos($field, '[') !== FALSE AND preg_match_all('/\[(.*?)\]/', $field, $matches)) + { + // Note: Due to a bug in current() that affects some versions + // of PHP we can not pass function call directly into it + $x = explode('[', $field); + $indexes[] = current($x); + + for ($i = 0; $i < count($matches['0']); $i++) + { + if ($matches['1'][$i] != '') + { + $indexes[] = $matches['1'][$i]; + } + } + + $is_array = TRUE; + } + else + { + $indexes = array(); + $is_array = FALSE; + } + + // Build our master array + $this->_field_data[$field] = array( + 'field' => $field, + 'label' => $label, + 'rules' => $rules, + 'is_array' => $is_array, + 'keys' => $indexes, + 'postdata' => NULL, + 'error' => '' + ); + } + + // -------------------------------------------------------------------- + + /** + * Set Error Message + * + * Lets users set their own error messages on the fly. Note: The key + * name has to match the function name that it corresponds to. + * + * @access public + * @param string + * @param string + * @return string + */ + function set_message($lang, $val = '') + { + if ( ! is_array($lang)) + { + $lang = array($lang => $val); + } + + $this->_error_messages = array_merge($this->_error_messages, $lang); + } + + // -------------------------------------------------------------------- + + /** + * Set The Error Delimiter + * + * Permits a prefix/suffix to be added to each error message + * + * @access public + * @param string + * @param string + * @return void + */ + function set_error_delimiters($prefix = '

    ', $suffix = '

    ') + { + $this->_error_prefix = $prefix; + $this->_error_suffix = $suffix; + } + + // -------------------------------------------------------------------- + + /** + * Get Error Message + * + * Gets the error message associated with a particular field + * + * @access public + * @param string the field name + * @return void + */ + function error($field = '', $prefix = '', $suffix = '') + { + if ( ! isset($this->_field_data[$field]['error'])) + { + return ''; + } + + if ($prefix == '') + { + $prefix = $this->_error_prefix; + } + + if ($suffix == '') + { + $suffix = $this->_error_suffix; + } + + return $prefix.$this->_field_data[$field]['error'].$suffix; + } + + // -------------------------------------------------------------------- + + /** + * Error String + * + * Returns the error messages as a string, wrapped in the error delimiters + * + * @access public + * @param string + * @param string + * @return str + */ + function error_string($prefix = '', $suffix = '') + { + // No errrors, validation passes! + if (count($this->_error_array) === 0) + { + return ''; + } + + if ($prefix == '') + { + $prefix = $this->_error_prefix; + } + + if ($suffix == '') + { + $suffix = $this->_error_suffix; + } + + // Generate the error string + $str = ''; + foreach ($this->_error_array as $val) + { + $str .= $prefix.$val.$suffix."\n"; + } + + return $str; + } + + // -------------------------------------------------------------------- + + /** + * Run the Validator + * + * This function does all the work. + * + * @access public + * @return bool + */ + function run($group = '') + { + // Do we even have any data to process? Mm? + if (count($_POST) == 0) + { + return FALSE; + } + + // Does the _field_data array containing the validation rules exist? + // If not, we look to see if they were assigned via a config file + if (count($this->_field_data) == 0) + { + // No validation rules? We're done... + if (count($this->_config_rules) == 0) + { + return FALSE; + } + + // Is there a validation rule for the particular URI being accessed? + $uri = ($group == '') ? trim($this->CI->uri->ruri_string(), '/') : $group; + + if ($uri != '' AND isset($this->_config_rules[$uri])) + { + $this->set_rules($this->_config_rules[$uri]); + } + else + { + $this->set_rules($this->_config_rules); + } + + // We're we able to set the rules correctly? + if (count($this->_field_data) == 0) + { + log_message('debug', "Unable to find validation rules"); + return FALSE; + } + } + + // Load the language file containing error messages + $this->CI->lang->load('form_validation'); + + // Cycle through the rules for each field, match the + // corresponding $_POST item and test for errors + foreach ($this->_field_data as $field => $row) + { + // Fetch the data from the corresponding $_POST array and cache it in the _field_data array. + // Depending on whether the field name is an array or a string will determine where we get it from. + + if ($row['is_array'] == TRUE) + { + $this->_field_data[$field]['postdata'] = $this->_reduce_array($_POST, $row['keys']); + } + else + { + if (isset($_POST[$field])) + { + $this->_field_data[$field]['postdata'] = $_POST[$field]; + } + } + + $this->_execute($row, explode('|', $row['rules']), $this->_field_data[$field]['postdata']); + } + + // Did we end up with any errors? + $total_errors = count($this->_error_array); + + if ($total_errors > 0) + { + $this->_safe_form_data = TRUE; + } + + // Now we need to re-set the POST data with the new, processed data + $this->_reset_post_array(); + + // No errors, validation passes! + if ($total_errors == 0) + { + return TRUE; + } + + // Validation fails + return FALSE; + } + + // -------------------------------------------------------------------- + + /** + * Traverse a multidimensional $_POST array index until the data is found + * + * @access private + * @param array + * @param array + * @param integer + * @return mixed + */ + function _reduce_array($array, $keys, $i = 0) + { + if (is_array($array)) + { + if (isset($keys[$i])) + { + if (isset($array[$keys[$i]])) + { + $array = $this->_reduce_array($array[$keys[$i]], $keys, ($i+1)); + } + else + { + return NULL; + } + } + else + { + return $array; + } + } + + return $array; + } + + // -------------------------------------------------------------------- + + /** + * Re-populate the _POST array with our finalized and processed data + * + * @access private + * @return null + */ + function _reset_post_array() + { + foreach ($this->_field_data as $field => $row) + { + if ( ! is_null($row['postdata'])) + { + if ($row['is_array'] == FALSE) + { + if (isset($_POST[$row['field']])) + { + $_POST[$row['field']] = $this->prep_for_form($row['postdata']); + } + } + else + { + $post = '$_POST["'; + + if (count($row['keys']) == 1) + { + $post .= current($row['keys']); + $post .= '"]'; + } + else + { + $i = 0; + foreach ($row['keys'] as $val) + { + if ($i == 0) + { + $post .= $val.'"]'; + $i++; + continue; + } + + $post .= '["'.$val.'"]'; + } + } + + if (is_array($row['postdata'])) + { + $array = array(); + foreach ($row['postdata'] as $k => $v) + { + $array[$k] = $this->prep_for_form($v); + } + + $post .= ' = $array;'; + } + else + { + $post .= ' = "'.$this->prep_for_form($row['postdata']).'";'; + } + + eval($post); + } + } + } + } + + // -------------------------------------------------------------------- + + /** + * Executes the Validation routines + * + * @access private + * @param array + * @param array + * @param mixed + * @param integer + * @return mixed + */ + function _execute($row, $rules, $postdata = NULL, $cycles = 0) + { + // If the $_POST data is an array we will run a recursive call + if (is_array($postdata)) + { + foreach ($postdata as $key => $val) + { + $this->_execute($row, $rules, $val, $cycles); + $cycles++; + } + + return; + } + + // -------------------------------------------------------------------- + + // If the field is blank, but NOT required, no further tests are necessary + if ( ! in_array('required', $rules, TRUE) AND is_null($postdata)) + { + return; + } + + // -------------------------------------------------------------------- + + // Isset Test. Typically this rule will only apply to checkboxes. + if (is_null($postdata)) + { + if (in_array('isset', $rules, TRUE) OR in_array('required', $rules)) + { + if ( ! isset($this->_error_messages['isset'])) + { + if (FALSE === ($line = $this->CI->lang->line('isset'))) + { + $line = 'The field was not set'; + } + } + else + { + $line = $this->_error_messages['isset']; + } + + // Build the error message + $message = sprintf($line, $row['label']); + + // Save the error message + $this->_field_data[$row['field']]['error'] = $message; + + if ( ! isset($this->_error_array[$row['field']])) + { + $this->_error_array[$row['field']] = $message; + } + } + + return; + } + + // -------------------------------------------------------------------- + + // Cycle through each rule and run it + foreach ($rules As $rule) + { + $_in_array = FALSE; + + // We set the $postdata variable with the current data in our master array so that + // each cycle of the loop is dealing with the processed data from the last cycle + if ($row['is_array'] == TRUE AND is_array($this->_field_data[$row['field']]['postdata'])) + { + // We shouldn't need this safety, but just in case there isn't an array index + // associated with this cycle we'll bail out + if ( ! isset($this->_field_data[$row['field']]['postdata'][$cycles])) + { + continue; + } + + $postdata = $this->_field_data[$row['field']]['postdata'][$cycles]; + $_in_array = TRUE; + } + else + { + $postdata = $this->_field_data[$row['field']]['postdata']; + } + + // -------------------------------------------------------------------- + + // Is the rule a callback? + $callback = FALSE; + if (substr($rule, 0, 9) == 'callback_') + { + $rule = substr($rule, 9); + $callback = TRUE; + } + + // Strip the parameter (if exists) from the rule + // Rules can contain a parameter: max_length[5] + $param = FALSE; + if (preg_match("/(.*?)\[(.*?)\]/", $rule, $match)) + { + $rule = $match[1]; + $param = $match[2]; + } + + // Call the function that corresponds to the rule + if ($callback === TRUE) + { + if ( ! method_exists($this->CI, $rule)) + { + continue; + } + + // Run the function and grab the result + $result = $this->CI->$rule($postdata, $param); + + // Re-assign the result to the master data array + if ($_in_array == TRUE) + { + $this->_field_data[$row['field']]['postdata'][$cycles] = (is_bool($result)) ? $postdata : $result; + } + else + { + $this->_field_data[$row['field']]['postdata'] = (is_bool($result)) ? $postdata : $result; + } + + // If the field isn't required and we just processed a callback we'll move on... + if ( ! in_array('required', $rules, TRUE) AND $result !== FALSE) + { + return; + } + } + else + { + if ( ! method_exists($this, $rule)) + { + /* + * Run the native PHP function if called for + * + * If our own wrapper function doesn't exist we see + * if a native PHP function does. Users can use + * any native PHP function call that has one param. + */ + if (function_exists($rule)) + { + $result = $rule($postdata); + + if ($_in_array == TRUE) + { + $this->_field_data[$row['field']]['postdata'][$cycles] = (is_bool($result)) ? $postdata : $result; + } + else + { + $this->_field_data[$row['field']]['postdata'] = (is_bool($result)) ? $postdata : $result; + } + } + + continue; + } + + $result = $this->$rule($postdata, $param); + + if ($_in_array == TRUE) + { + $this->_field_data[$row['field']]['postdata'][$cycles] = (is_bool($result)) ? $postdata : $result; + } + else + { + $this->_field_data[$row['field']]['postdata'] = (is_bool($result)) ? $postdata : $result; + } + } + + // Did the rule test negatively? If so, grab the error. + if ($result === FALSE) + { + if ( ! isset($this->_error_messages[$rule])) + { + if (FALSE === ($line = $this->CI->lang->line($rule))) + { + $line = 'Unable to access an error message corresponding to your field name.'; + } + } + else + { + $line = $this->_error_messages[$rule]; + } + + // Build the error message + $message = sprintf($line, $row['label'], $param); + + // Save the error message + $this->_field_data[$row['field']]['error'] = $message; + + if ( ! isset($this->_error_array[$row['field']])) + { + $this->_error_array[$row['field']] = $message; + } + + return; + } + } + } + + // -------------------------------------------------------------------- + + /** + * Get the value from a form + * + * Permits you to repopulate a form field with the value it was submitted + * with, or, if that value doesn't exist, with the default + * + * @access public + * @param string the field name + * @param string + * @return void + */ + function set_value($field = '', $default = '') + { + if ( ! isset($this->_field_data[$field])) + { + return $default; + } + + return $this->_field_data[$field]['postdata']; + } + + // -------------------------------------------------------------------- + + /** + * Set Select + * + * Enables pull-down lists to be set to the value the user + * selected in the event of an error + * + * @access public + * @param string + * @param string + * @return string + */ + function set_select($field = '', $value = '', $default = FALSE) + { + if ( ! isset($this->_field_data[$field]) OR ! isset($this->_field_data[$field]['postdata'])) + { + if ($default === TRUE AND count($this->_field_data) === 0) + { + return ' selected="selected"'; + } + return ''; + } + + $field = $this->_field_data[$field]['postdata']; + + if (is_array($field)) + { + if ( ! in_array($value, $field, TRUE)) + { + return ''; + } + } + else + { + if (($field == '' OR $value == '') OR ($field != $value)) + { + return ''; + } + } + + return ' selected="selected"'; + } + + // -------------------------------------------------------------------- + + /** + * Set Radio + * + * Enables radio buttons to be set to the value the user + * selected in the event of an error + * + * @access public + * @param string + * @param string + * @return string + */ + function set_radio($field = '', $value = '', $default = FALSE) + { + if ( ! isset($this->_field_data[$field]) OR ! isset($this->_field_data[$field]['postdata'])) + { + if ($default === TRUE AND count($this->_field_data) === 0) + { + return ' checked="checked"'; + } + return ''; + } + + $field = $this->_field_data[$field]['postdata']; + + if (is_array($field)) + { + if ( ! in_array($value, $field, TRUE)) + { + return ''; + } + } + else + { + if (($field == '' OR $value == '') OR ($field != $value)) + { + return ''; + } + } + + return ' checked="checked"'; + } + + // -------------------------------------------------------------------- + + /** + * Set Checkbox + * + * Enables checkboxes to be set to the value the user + * selected in the event of an error + * + * @access public + * @param string + * @param string + * @return string + */ + function set_checkbox($field = '', $value = '', $default = FALSE) + { + if ( ! isset($this->_field_data[$field]) OR ! isset($this->_field_data[$field]['postdata'])) + { + if ($default === TRUE AND count($this->_field_data) === 0) + { + return ' checked="checked"'; + } + return ''; + } + + $field = $this->_field_data[$field]['postdata']; + + if (is_array($field)) + { + if ( ! in_array($value, $field, TRUE)) + { + return ''; + } + } + else + { + if (($field == '' OR $value == '') OR ($field != $value)) + { + return ''; + } + } + + return ' checked="checked"'; + } + + // -------------------------------------------------------------------- + + /** + * Required + * + * @access public + * @param string + * @return bool + */ + function required($str) + { + if ( ! is_array($str)) + { + return (trim($str) == '') ? FALSE : TRUE; + } + else + { + return ( ! empty($str)); + } + } + + // -------------------------------------------------------------------- + + /** + * Match one field to another + * + * @access public + * @param string + * @param field + * @return bool + */ + function matches($str, $field) + { + if ( ! isset($_POST[$field])) + { + return FALSE; + } + + $field = $_POST[$field]; + + return ($str !== $field) ? FALSE : TRUE; + } + + // -------------------------------------------------------------------- + + /** + * Minimum Length + * + * @access public + * @param string + * @param value + * @return bool + */ + function min_length($str, $val) + { + if (preg_match("/[^0-9]/", $val)) + { + return FALSE; + } + + return (strlen($str) < $val) ? FALSE : TRUE; + } + + // -------------------------------------------------------------------- + + /** + * Max Length + * + * @access public + * @param string + * @param value + * @return bool + */ + function max_length($str, $val) + { + if (preg_match("/[^0-9]/", $val)) + { + return FALSE; + } + + return (strlen($str) > $val) ? FALSE : TRUE; + } + + // -------------------------------------------------------------------- + + /** + * Exact Length + * + * @access public + * @param string + * @param value + * @return bool + */ + function exact_length($str, $val) + { + if (preg_match("/[^0-9]/", $val)) + { + return FALSE; + } + + return (strlen($str) != $val) ? FALSE : TRUE; + } + + // -------------------------------------------------------------------- + + /** + * Valid Email + * + * @access public + * @param string + * @return bool + */ + function valid_email($str) + { + return ( ! preg_match("/^([a-z0-9\+_\-]+)(\.[a-z0-9\+_\-]+)*@([a-z0-9\-]+\.)+[a-z]{2,6}$/ix", $str)) ? FALSE : TRUE; + } + + // -------------------------------------------------------------------- + + /** + * Valid Emails + * + * @access public + * @param string + * @return bool + */ + function valid_emails($str) + { + if (strpos($str, ',') === FALSE) + { + return $this->valid_email(trim($str)); + } + + foreach(explode(',', $str) as $email) + { + if (trim($email) != '' && $this->valid_email(trim($email)) === FALSE) + { + return FALSE; + } + } + + return TRUE; + } + + // -------------------------------------------------------------------- + + /** + * Validate IP Address + * + * @access public + * @param string + * @return string + */ + function valid_ip($ip) + { + return $this->CI->input->valid_ip($ip); + } + + // -------------------------------------------------------------------- + + /** + * Alpha + * + * @access public + * @param string + * @return bool + */ + function alpha($str) + { + return ( ! preg_match("/^([a-z])+$/i", $str)) ? FALSE : TRUE; + } + + // -------------------------------------------------------------------- + + /** + * Alpha-numeric + * + * @access public + * @param string + * @return bool + */ + function alpha_numeric($str) + { + return ( ! preg_match("/^([a-z0-9])+$/i", $str)) ? FALSE : TRUE; + } + + // -------------------------------------------------------------------- + + /** + * Alpha-numeric with underscores and dashes + * + * @access public + * @param string + * @return bool + */ + function alpha_dash($str) + { + return ( ! preg_match("/^([-a-z0-9_-])+$/i", $str)) ? FALSE : TRUE; + } + + // -------------------------------------------------------------------- + + /** + * Numeric + * + * @access public + * @param string + * @return bool + */ + function numeric($str) + { + return (bool)preg_match( '/^[\-+]?[0-9]*\.?[0-9]+$/', $str); + + } + + // -------------------------------------------------------------------- + + /** + * Is Numeric + * + * @access public + * @param string + * @return bool + */ + function is_numeric($str) + { + return ( ! is_numeric($str)) ? FALSE : TRUE; + } + + // -------------------------------------------------------------------- + + /** + * Integer + * + * @access public + * @param string + * @return bool + */ + function integer($str) + { + return (bool)preg_match( '/^[\-+]?[0-9]+$/', $str); + } + + // -------------------------------------------------------------------- + + /** + * Is a Natural number (0,1,2,3, etc.) + * + * @access public + * @param string + * @return bool + */ + function is_natural($str) + { + return (bool)preg_match( '/^[0-9]+$/', $str); + } + + // -------------------------------------------------------------------- + + /** + * Is a Natural number, but not a zero (1,2,3, etc.) + * + * @access public + * @param string + * @return bool + */ + function is_natural_no_zero($str) + { + if ( ! preg_match( '/^[0-9]+$/', $str)) + { + return FALSE; + } + + if ($str == 0) + { + return FALSE; + } + + return TRUE; + } + + // -------------------------------------------------------------------- + + /** + * Valid Base64 + * + * Tests a string for characters outside of the Base64 alphabet + * as defined by RFC 2045 http://www.faqs.org/rfcs/rfc2045 + * + * @access public + * @param string + * @return bool + */ + function valid_base64($str) + { + return (bool) ! preg_match('/[^a-zA-Z0-9\/\+=]/', $str); + } + + // -------------------------------------------------------------------- + + /** + * Prep data for form + * + * This function allows HTML to be safely shown in a form. + * Special characters are converted. + * + * @access public + * @param string + * @return string + */ + function prep_for_form($data = '') + { + if (is_array($data)) + { + foreach ($data as $key => $val) + { + $data[$key] = $this->prep_for_form($val); + } + + return $data; + } + + if ($this->_safe_form_data == FALSE OR $data === '') + { + return $data; + } + + return str_replace(array("'", '"', '<', '>'), array("'", """, '<', '>'), stripslashes($data)); + } + + // -------------------------------------------------------------------- + + /** + * Prep URL + * + * @access public + * @param string + * @return string + */ + function prep_url($str = '') + { + if ($str == 'http://' OR $str == '') + { + return ''; + } + + if (substr($str, 0, 7) != 'http://' && substr($str, 0, 8) != 'https://') + { + $str = 'http://'.$str; + } + + return $str; + } + + // -------------------------------------------------------------------- + + /** + * Strip Image Tags + * + * @access public + * @param string + * @return string + */ + function strip_image_tags($str) + { + return $this->CI->input->strip_image_tags($str); + } + + // -------------------------------------------------------------------- + + /** + * XSS Clean + * + * @access public + * @param string + * @return string + */ + function xss_clean($str) + { + return $this->CI->input->xss_clean($str); + } + + // -------------------------------------------------------------------- + + /** + * Convert PHP tags to entities + * + * @access public + * @param string + * @return string + */ + function encode_php_tags($str) + { + return str_replace(array(''), array('<?php', '<?PHP', '<?', '?>'), $str); + } + +} +// END Form Validation Class + +/* End of file Form_validation.php */ +/* Location: ./system/libraries/Form_validation.php */ \ No newline at end of file -- cgit v1.2.3-24-g4f1b From 43e0fbb650d05466cd2568b8a2cc1c38849a6b52 Mon Sep 17 00:00:00 2001 From: Rick Ellis Date: Tue, 26 Aug 2008 19:22:31 +0000 Subject: Added some new functions that work with the new form validation class --- system/helpers/form_helper.php | 335 +++++++++++++++++++++++++++++++++++++++-- 1 file changed, 321 insertions(+), 14 deletions(-) (limited to 'system') diff --git a/system/helpers/form_helper.php b/system/helpers/form_helper.php index 0c74ac0ff..a96adb97d 100644 --- a/system/helpers/form_helper.php +++ b/system/helpers/form_helper.php @@ -53,7 +53,7 @@ if ( ! function_exists('form_open')) $form = ' 'text', 'name' => (( ! is_array($data)) ? $data : ''), 'value' => $value); - return ""; + return ""; } } @@ -214,17 +214,17 @@ if ( ! function_exists('form_textarea')) { $defaults = array('name' => (( ! is_array($data)) ? $data : ''), 'cols' => '90', 'rows' => '12'); - if ( ! is_array($data) OR ! isset($data['value'])) + if ( ! is_array($data) OR ! isset($data['value'])) { $val = $value; } - else + else { $val = $data['value']; unset($data['value']); // textareas don't use the value attribute } - return ""; + return ""; } } @@ -248,6 +248,16 @@ if ( ! function_exists('form_dropdown')) { $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; @@ -312,7 +322,7 @@ if ( ! function_exists('form_checkbox')) unset($defaults['checked']); } - return ""; + return ""; } } @@ -359,7 +369,7 @@ if ( ! function_exists('form_submit')) { $defaults = array('type' => 'submit', 'name' => (( ! is_array($data)) ? $data : ''), 'value' => $value); - return ""; + return ""; } } @@ -380,7 +390,7 @@ if ( ! function_exists('form_reset')) { $defaults = array('type' => 'reset', 'name' => (( ! is_array($data)) ? $data : ''), 'value' => $value); - return ""; + return ""; } } @@ -407,7 +417,7 @@ if ( ! function_exists('form_button')) unset($data['content']); // content is not an attribute } - return ""; + return ""; } } @@ -466,7 +476,7 @@ if ( ! function_exists('form_fieldset')) { $fieldset = " $val) + { + $str[$key] = form_prep($val); + } + + return $str; + } + if ($str === '') { return ''; @@ -552,7 +573,256 @@ if ( ! function_exists('form_prep')) return $str; } } + +// ------------------------------------------------------------------------ + +/** + * 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 $_POST[$field]; + } + + return $OBJ->set_value($field, $default); + } +} + +// ------------------------------------------------------------------------ + +/** + * Set Select + * + * Let's you set the selected value of a '; } - + return $form; } } - + // ------------------------------------------------------------------------ /** @@ -132,7 +132,7 @@ if ( ! function_exists('form_hidden')) * @param string * @param string * @return string - */ + */ if ( ! function_exists('form_input')) { function form_input($data = '', $value = '', $extra = '') @@ -142,7 +142,7 @@ if ( ! function_exists('form_input')) return ""; } } - + // ------------------------------------------------------------------------ /** @@ -155,7 +155,7 @@ if ( ! function_exists('form_input')) * @param string * @param string * @return string - */ + */ if ( ! function_exists('form_password')) { function form_password($data = '', $value = '', $extra = '') @@ -169,7 +169,7 @@ if ( ! function_exists('form_password')) return form_input($data, $value, $extra); } } - + // ------------------------------------------------------------------------ /** @@ -182,7 +182,7 @@ if ( ! function_exists('form_password')) * @param string * @param string * @return string - */ + */ if ( ! function_exists('form_upload')) { function form_upload($data = '', $value = '', $extra = '') @@ -196,7 +196,7 @@ if ( ! function_exists('form_upload')) return form_input($data, $value, $extra); } } - + // ------------------------------------------------------------------------ /** @@ -207,13 +207,13 @@ if ( ! function_exists('form_upload')) * @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' => '90', 'rows' => '12'); - + if ( ! is_array($data) OR ! isset($data['value'])) { $val = $value; @@ -223,11 +223,11 @@ if ( ! function_exists('form_textarea')) $val = $data['value']; unset($data['value']); // textareas don't use the value attribute } - + return ""; } } - + // ------------------------------------------------------------------------ /** @@ -239,7 +239,7 @@ if ( ! function_exists('form_textarea')) * @param string * @param string * @return string - */ + */ if ( ! function_exists('form_dropdown')) { function form_dropdown($name = '', $options = array(), $selected = array(), $extra = '') @@ -248,7 +248,7 @@ if ( ! function_exists('form_dropdown')) { $selected = array($selected); } - + // If no selected state was submitted we will attempt to set it automatically if (count($selected) === 0) { @@ -269,18 +269,18 @@ if ( ! function_exists('form_dropdown')) { $key = (string) $key; $val = (string) $val; - + $sel = (in_array($key, $selected))?' selected="selected"':''; - + $form .= '\n"; } $form .= ''; - + return $form; } } - + // ------------------------------------------------------------------------ /** @@ -292,17 +292,17 @@ if ( ! function_exists('form_dropdown')) * @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']); @@ -312,7 +312,7 @@ if ( ! function_exists('form_checkbox')) $data['checked'] = 'checked'; } } - + if ($checked == TRUE) { $defaults['checked'] = 'checked'; @@ -325,7 +325,7 @@ if ( ! function_exists('form_checkbox')) return ""; } } - + // ------------------------------------------------------------------------ /** @@ -337,7 +337,7 @@ if ( ! function_exists('form_checkbox')) * @param bool * @param string * @return string - */ + */ if ( ! function_exists('form_radio')) { function form_radio($data = '', $value = '', $checked = FALSE, $extra = '') @@ -351,7 +351,7 @@ if ( ! function_exists('form_radio')) return form_checkbox($data, $value, $checked, $extra); } } - + // ------------------------------------------------------------------------ /** @@ -383,7 +383,7 @@ if ( ! function_exists('form_submit')) * @param string * @param string * @return string - */ + */ if ( ! function_exists('form_reset')) { function form_reset($data = '', $value = '', $extra = '') @@ -404,19 +404,19 @@ if ( ! function_exists('form_reset')) * @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' => 'submit'); - + if ( is_array($data) AND isset($data['content'])) { $content = $data['content']; unset($data['content']); // content is not an attribute } - + return ""; } } @@ -431,19 +431,19 @@ if ( ! function_exists('form_button')) * @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) @@ -469,7 +469,7 @@ if ( ! function_exists('form_label')) * @param string The legend text * @param string Additional attributes * @return string - */ + */ if ( ! function_exists('form_fieldset')) { function form_fieldset($legend_text = '', $attributes = array()) @@ -477,9 +477,9 @@ if ( ! function_exists('form_fieldset')) $fieldset = "".$extra; } } - + // ------------------------------------------------------------------------ /** @@ -514,7 +514,7 @@ if ( ! function_exists('form_fieldset_close')) * @access public * @param string * @return string - */ + */ if ( ! function_exists('form_close')) { function form_close($extra = '') @@ -522,7 +522,7 @@ if ( ! function_exists('form_close')) return "".$extra; } } - + // ------------------------------------------------------------------------ /** @@ -533,7 +533,7 @@ if ( ! function_exists('form_close')) * @access public * @param string * @return string - */ + */ if ( ! function_exists('form_prep')) { function form_prep($str = '') @@ -545,17 +545,17 @@ if ( ! function_exists('form_prep')) { $str[$key] = form_prep($val); } - + return $str; } - + if ($str === '') { return ''; } $temp = '__TEMP_AMPERSANDS__'; - + // Replace entities to temporary markers so that // htmlspecialchars won't mess them up $str = preg_replace("/&#(\d+);/", "$temp\\1;", $str); @@ -564,13 +564,13 @@ if ( ! function_exists('form_prep')) $str = htmlspecialchars($str); // In case htmlspecialchars misses these. - $str = str_replace(array("'", '"'), array("'", """), $str); - + $str = str_replace(array("'", '"'), array("'", """), $str); + // Decode the temp markers back to entities $str = preg_replace("/$temp(\d+);/","&#\\1;",$str); - $str = preg_replace("/$temp(\w+);/","&\\1;",$str); - - return $str; + $str = preg_replace("/$temp(\w+);/","&\\1;",$str); + + return $str; } } @@ -586,7 +586,7 @@ if ( ! function_exists('form_prep')) * @access public * @param string * @return mixed - */ + */ if ( ! function_exists('set_value')) { function set_value($field = '', $default = '') @@ -597,10 +597,10 @@ if ( ! function_exists('set_value')) { return $default; } - + return $_POST[$field]; } - + return $OBJ->set_value($field, $default); } } @@ -618,7 +618,7 @@ if ( ! function_exists('set_value')) * @param string * @param bool * @return string - */ + */ if ( ! function_exists('set_select')) { function set_select($field = '', $value = '', $default = FALSE) @@ -635,9 +635,9 @@ if ( ! function_exists('set_select')) } return ''; } - + $field = $_POST[$field]; - + if (is_array($field)) { if ( ! in_array($value, $field)) @@ -652,10 +652,10 @@ if ( ! function_exists('set_select')) return ''; } } - + return ' selected="selected"'; } - + return $OBJ->set_select($field, $value, $default); } } @@ -673,7 +673,7 @@ if ( ! function_exists('set_select')) * @param string * @param bool * @return string - */ + */ if ( ! function_exists('set_checkbox')) { function set_checkbox($field = '', $value = '', $default = FALSE) @@ -690,7 +690,7 @@ if ( ! function_exists('set_checkbox')) } return ''; } - + $field = $_POST[$field]; if (is_array($field)) @@ -707,10 +707,10 @@ if ( ! function_exists('set_checkbox')) return ''; } } - + return ' checked="checked"'; } - + return $OBJ->set_checkbox($field, $value, $default); } } @@ -728,7 +728,7 @@ if ( ! function_exists('set_checkbox')) * @param string * @param bool * @return string - */ + */ if ( ! function_exists('set_radio')) { function set_radio($field = '', $value = '', $default = FALSE) @@ -745,7 +745,7 @@ if ( ! function_exists('set_radio')) } return ''; } - + $field = $_POST[$field]; if (is_array($field)) @@ -762,10 +762,10 @@ if ( ! function_exists('set_radio')) return ''; } } - + return ' checked="checked"'; } - + return $OBJ->set_radio($field, $value, $default); } } @@ -783,7 +783,7 @@ if ( ! function_exists('set_radio')) * @param string * @param string * @return string - */ + */ if ( ! function_exists('form_error')) { function form_error($field = '', $prefix = '', $suffix = '') @@ -792,7 +792,7 @@ if ( ! function_exists('form_error')) { return ''; } - + return $OBJ->error($field, $prefix, $suffix); } } @@ -809,7 +809,7 @@ if ( ! function_exists('form_error')) * @param string * @param string * @return string - */ + */ if ( ! function_exists('validation_errors')) { function validation_errors($prefix = '', $suffix = '') @@ -818,7 +818,7 @@ if ( ! function_exists('validation_errors')) { return ''; } - + return $OBJ->error_string($prefix, $suffix); } } @@ -834,7 +834,7 @@ if ( ! function_exists('validation_errors')) * @param array * @param array * @return string - */ + */ if ( ! function_exists('_parse_form_attributes')) { function _parse_form_attributes($attributes, $default) @@ -849,21 +849,22 @@ if ( ! function_exists('_parse_form_attributes')) 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); } - + $att .= $key . '="' . $val . '" '; } @@ -882,43 +883,43 @@ if ( ! function_exists('_parse_form_attributes')) * @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"'; - } - - 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 (is_string($attributes) AND strlen($attributes) > 0) + { + if ($formtag == TRUE AND strpos($attributes, 'method=') === FALSE) + { + $attributes .= ' method="post"'; + } + + return ' '.$attributes; + } - foreach ($attributes as $key => $val) - { - $atts .= ' '.$key.'="'.$val.'"'; - } - - return $atts; - } - } + 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"'; + } + + foreach ($attributes as $key => $val) + { + $atts .= ' '.$key.'="'.$val.'"'; + } + + return $atts; + } + } } // ------------------------------------------------------------------------ @@ -931,28 +932,28 @@ if ( ! function_exists('_attributes_to_string')) * * @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 ( ! isset($CI->load->_ci_classes) OR ! isset($CI->load->_ci_classes['form_validation'])) { return $return; } - + $object = $CI->load->_ci_classes['form_validation']; - + if ( ! isset($CI->$object) OR ! is_object($CI->$object)) { return $return; } - + return $CI->$object; } } -- cgit v1.2.3-24-g4f1b From fe61d63138f4534125e2250cc2f6809613fe9e90 Mon Sep 17 00:00:00 2001 From: Rick Ellis Date: Mon, 22 Sep 2008 21:55:12 +0000 Subject: Fixed a language bug when setting errors manually --- system/libraries/Form_validation.php | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) (limited to 'system') diff --git a/system/libraries/Form_validation.php b/system/libraries/Form_validation.php index 6ef11e345..42ce433c7 100644 --- a/system/libraries/Form_validation.php +++ b/system/libraries/Form_validation.php @@ -690,13 +690,22 @@ class CI_Form_validation { // We look for the prefix lang: to determine this if (substr($fieldname, 0, 5) == 'lang:') { - $label = $this->CI->lang->line(substr($fieldname, 5)); + $line = substr($fieldname, 5); + + $fieldname = $this->CI->lang->line($line); // Were we able to translate the field name? - $fieldname = ($label === FALSE) ? substr($fieldname, 5) : $label; + if ($fieldname === FALSE) + { + return $this->CI->lang->line($line); + } + else + { + return $label; + } } - return $fieldname; + return $this->CI->lang->line($fieldname); } // -------------------------------------------------------------------- -- cgit v1.2.3-24-g4f1b From 193743a4a65cee93941022896be6791cbadb979a Mon Sep 17 00:00:00 2001 From: Rick Ellis Date: Mon, 22 Sep 2008 21:55:41 +0000 Subject: Oops... fixed the fix I just fixed... --- system/libraries/Form_validation.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system') diff --git a/system/libraries/Form_validation.php b/system/libraries/Form_validation.php index 42ce433c7..427e62f7c 100644 --- a/system/libraries/Form_validation.php +++ b/system/libraries/Form_validation.php @@ -701,7 +701,7 @@ class CI_Form_validation { } else { - return $label; + return $fieldname; } } -- cgit v1.2.3-24-g4f1b From 066954088c74cc4eaa1d46a6193b2ed45dcf13ff Mon Sep 17 00:00:00 2001 From: Rick Ellis Date: Mon, 22 Sep 2008 21:58:10 +0000 Subject: One more tweak... --- system/libraries/Form_validation.php | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'system') diff --git a/system/libraries/Form_validation.php b/system/libraries/Form_validation.php index 427e62f7c..643aecbce 100644 --- a/system/libraries/Form_validation.php +++ b/system/libraries/Form_validation.php @@ -690,14 +690,16 @@ class CI_Form_validation { // We look for the prefix lang: to determine this if (substr($fieldname, 0, 5) == 'lang:') { + // Grab the variable $line = substr($fieldname, 5); - + + // Translate it $fieldname = $this->CI->lang->line($line); // Were we able to translate the field name? if ($fieldname === FALSE) { - return $this->CI->lang->line($line); + return $line; } else { -- cgit v1.2.3-24-g4f1b From 96fabe576f4caf78d3c3af759d2d03bab64801f9 Mon Sep 17 00:00:00 2001 From: Rick Ellis Date: Tue, 23 Sep 2008 01:18:36 +0000 Subject: Fixed a boneheaded mistake I made... --- system/libraries/Form_validation.php | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'system') diff --git a/system/libraries/Form_validation.php b/system/libraries/Form_validation.php index 643aecbce..f0c1500df 100644 --- a/system/libraries/Form_validation.php +++ b/system/libraries/Form_validation.php @@ -514,7 +514,7 @@ class CI_Form_validation { } else { - $line = $this->_translate_fieldname('isset'); + $line = $this->_error_messages[$rule]; } // Build the error message @@ -646,7 +646,7 @@ class CI_Form_validation { // Did the rule test negatively? If so, grab the error. if ($result === FALSE) - { + { if ( ! isset($this->_error_messages[$rule])) { if (FALSE === ($line = $this->CI->lang->line($rule))) @@ -656,8 +656,8 @@ class CI_Form_validation { } else { - $line = $this->_translate_fieldname($rule); - } + $line = $this->_error_messages[$rule]; + } // Build the error message $message = sprintf($line, $this->_translate_fieldname($row['label']), $param); @@ -707,7 +707,7 @@ class CI_Form_validation { } } - return $this->CI->lang->line($fieldname); + return $fieldname; } // -------------------------------------------------------------------- -- cgit v1.2.3-24-g4f1b From 9b8bc35dbaf3aa0f37885122dccb24d1d7811f1e Mon Sep 17 00:00:00 2001 From: Rick Ellis Date: Tue, 23 Sep 2008 01:21:23 +0000 Subject: --- system/libraries/Form_validation.php | 13 +++---------- 1 file changed, 3 insertions(+), 10 deletions(-) (limited to 'system') diff --git a/system/libraries/Form_validation.php b/system/libraries/Form_validation.php index f0c1500df..df57f80ff 100644 --- a/system/libraries/Form_validation.php +++ b/system/libraries/Form_validation.php @@ -691,20 +691,13 @@ class CI_Form_validation { if (substr($fieldname, 0, 5) == 'lang:') { // Grab the variable - $line = substr($fieldname, 5); - - // Translate it - $fieldname = $this->CI->lang->line($line); + $line = substr($fieldname, 5); - // Were we able to translate the field name? - if ($fieldname === FALSE) + // Were we able to translate the field name? If not we use $line + if (FALSE === ($fieldname = $this->CI->lang->line($line))) { return $line; } - else - { - return $fieldname; - } } return $fieldname; -- cgit v1.2.3-24-g4f1b From e5ad2c797162091fade9a809ccc4578d835027bd Mon Sep 17 00:00:00 2001 From: Derek Allard Date: Tue, 23 Sep 2008 06:01:26 +0000 Subject: change of a false test --- system/libraries/Encrypt.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system') diff --git a/system/libraries/Encrypt.php b/system/libraries/Encrypt.php index aabf90d08..16c9efe61 100644 --- a/system/libraries/Encrypt.php +++ b/system/libraries/Encrypt.php @@ -141,7 +141,7 @@ class CI_Encrypt { { $key = $this->get_key($key); - if ( ! preg_match('/[^a-zA-Z0-9\/\+=]/', $string)) + if (preg_match('/[^a-zA-Z0-9\/\+=]/', $string) === FALSE) { return FALSE; } -- cgit v1.2.3-24-g4f1b From 0c9e2700ee0950ada00205d60151224505203dd7 Mon Sep 17 00:00:00 2001 From: Derek Allard Date: Tue, 23 Sep 2008 06:06:21 +0000 Subject: mostly trivial whitespace adjustments --- system/libraries/Encrypt.php | 100 +++++++++++++++++++++---------------------- 1 file changed, 50 insertions(+), 50 deletions(-) (limited to 'system') diff --git a/system/libraries/Encrypt.php b/system/libraries/Encrypt.php index 16c9efe61..bd74592d1 100644 --- a/system/libraries/Encrypt.php +++ b/system/libraries/Encrypt.php @@ -27,14 +27,14 @@ * @link http://codeigniter.com/user_guide/libraries/encryption.html */ class CI_Encrypt { - + var $CI; var $encryption_key = ''; var $_hash_type = 'sha1'; var $_mcrypt_exists = FALSE; var $_mcrypt_cipher; var $_mcrypt_mode; - + /** * Constructor * @@ -47,7 +47,7 @@ class CI_Encrypt { $this->_mcrypt_exists = ( ! function_exists('mcrypt_encrypt')) ? FALSE : TRUE; log_message('debug', "Encrypt Class Initialized"); } - + // -------------------------------------------------------------------- /** @@ -63,12 +63,12 @@ class CI_Encrypt { function get_key($key = '') { if ($key == '') - { + { if ($this->encryption_key != '') { return $this->encryption_key; } - + $CI =& get_instance(); $key = $CI->config->item('encryption_key'); @@ -77,7 +77,7 @@ class CI_Encrypt { show_error('In order to use the encryption class requires that you set an encryption key in your config file.'); } } - + return md5($key); } @@ -94,7 +94,7 @@ class CI_Encrypt { { $this->encryption_key = $key; } - + // -------------------------------------------------------------------- /** @@ -122,9 +122,9 @@ class CI_Encrypt { { $enc = $this->mcrypt_encode($enc, $key); } - return base64_encode($enc); + return base64_encode($enc); } - + // -------------------------------------------------------------------- /** @@ -155,10 +155,10 @@ class CI_Encrypt { return FALSE; } } - + return $this->_xor_decode($dec, $key); } - + // -------------------------------------------------------------------- /** @@ -171,7 +171,7 @@ class CI_Encrypt { * @param string * @param string * @return string - */ + */ function _xor_encode($string, $key) { $rand = ''; @@ -179,18 +179,18 @@ class CI_Encrypt { { $rand .= mt_rand(0, mt_getrandmax()); } - + $rand = $this->hash($rand); - + $enc = ''; for ($i = 0; $i < strlen($string); $i++) { $enc .= substr($rand, ($i % strlen($rand)), 1).(substr($rand, ($i % strlen($rand)), 1) ^ substr($string, $i, 1)); } - + return $this->_xor_merge($enc, $key); } - + // -------------------------------------------------------------------- /** @@ -203,20 +203,20 @@ class CI_Encrypt { * @param string * @param string * @return string - */ + */ function _xor_decode($string, $key) { $string = $this->_xor_merge($string, $key); - + $dec = ''; for ($i = 0; $i < strlen($string); $i++) { $dec .= (substr($string, $i++, 1) ^ substr($string, $i, 1)); } - + return $dec; } - + // -------------------------------------------------------------------- /** @@ -228,7 +228,7 @@ class CI_Encrypt { * @param string * @param string * @return string - */ + */ function _xor_merge($string, $key) { $hash = $this->hash($key); @@ -237,10 +237,10 @@ class CI_Encrypt { { $str .= substr($string, $i, 1) ^ substr($hash, ($i % strlen($hash)), 1); } - + return $str; } - + // -------------------------------------------------------------------- /** @@ -252,12 +252,12 @@ class CI_Encrypt { * @return string */ function mcrypt_encode($data, $key) - { + { $init_size = mcrypt_get_iv_size($this->_get_cipher(), $this->_get_mode()); $init_vect = mcrypt_create_iv($init_size, MCRYPT_RAND); return $this->_add_cipher_noise($init_vect.mcrypt_encrypt($this->_get_cipher(), $key, $data, $this->_get_mode(), $init_vect), $key); } - + // -------------------------------------------------------------------- /** @@ -267,22 +267,22 @@ class CI_Encrypt { * @param string * @param string * @return string - */ + */ function mcrypt_decode($data, $key) { $data = $this->_remove_cipher_noise($data, $key); $init_size = mcrypt_get_iv_size($this->_get_cipher(), $this->_get_mode()); - + if ($init_size > strlen($data)) { return FALSE; } - + $init_vect = substr($data, 0, $init_size); $data = substr($data, $init_size); return rtrim(mcrypt_decrypt($this->_get_cipher(), $key, $data, $this->_get_mode(), $init_vect), "\0"); } - + // -------------------------------------------------------------------- /** @@ -302,22 +302,22 @@ class CI_Encrypt { $keyhash = $this->hash($key); $keylen = strlen($keyhash); $str = ''; - + for ($i = 0, $j = 0, $len = strlen($data); $i < $len; ++$i, ++$j) - { + { if ($j >= $keylen) { $j = 0; } - + $str .= chr((ord($data[$i]) + ord($keyhash[$j])) % 256); } - + return $str; } // -------------------------------------------------------------------- - + /** * Removes permuted noise from the IV + encrypted data, reversing * _add_cipher_noise() @@ -340,9 +340,9 @@ class CI_Encrypt { { $j = 0; } - + $temp = ord($data[$i]) - ord($keyhash[$j]); - + if ($temp < 0) { $temp = $temp + 256; @@ -350,7 +350,7 @@ class CI_Encrypt { $str .= chr($temp); } - + return $str; } @@ -367,7 +367,7 @@ class CI_Encrypt { { $this->_mcrypt_cipher = $cipher; } - + // -------------------------------------------------------------------- /** @@ -381,7 +381,7 @@ class CI_Encrypt { { $this->_mcrypt_mode = $mode; } - + // -------------------------------------------------------------------- /** @@ -389,7 +389,7 @@ class CI_Encrypt { * * @access private * @return string - */ + */ function _get_cipher() { if ($this->_mcrypt_cipher == '') @@ -407,7 +407,7 @@ class CI_Encrypt { * * @access private * @return string - */ + */ function _get_mode() { if ($this->_mcrypt_mode == '') @@ -417,7 +417,7 @@ class CI_Encrypt { return $this->_mcrypt_mode; } - + // -------------------------------------------------------------------- /** @@ -426,12 +426,12 @@ class CI_Encrypt { * @access public * @param string * @return string - */ + */ function set_hash($type = 'sha1') { $this->_hash_type = ($type != 'sha1' AND $type != 'md5') ? 'sha1' : $type; } - + // -------------------------------------------------------------------- /** @@ -440,12 +440,12 @@ class CI_Encrypt { * @access public * @param string * @return string - */ + */ function hash($str) { return ($this->_hash_type == 'sha1') ? $this->sha1($str) : md5($str); } - + // -------------------------------------------------------------------- /** @@ -454,13 +454,13 @@ class CI_Encrypt { * @access public * @param string * @return string - */ + */ function sha1($str) { if ( ! function_exists('sha1')) { if ( ! function_exists('mhash')) - { + { require_once(BASEPATH.'libraries/Sha1'.EXT); $SH = new CI_SHA; return $SH->generate($str); @@ -473,9 +473,9 @@ class CI_Encrypt { else { return sha1($str); - } + } } - + } // END CI_Encrypt class -- cgit v1.2.3-24-g4f1b From faa6d09ad2347e31189134ab8e4cde7d0e84e81b Mon Sep 17 00:00:00 2001 From: Rick Ellis Date: Tue, 23 Sep 2008 20:01:33 +0000 Subject: Cleaned up a comment --- system/libraries/Form_validation.php | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) (limited to 'system') diff --git a/system/libraries/Form_validation.php b/system/libraries/Form_validation.php index df57f80ff..4bbb6f2dd 100644 --- a/system/libraries/Form_validation.php +++ b/system/libraries/Form_validation.php @@ -608,13 +608,8 @@ class CI_Form_validation { { if ( ! method_exists($this, $rule)) { - /* - * Run the native PHP function if called for - * - * If our own wrapper function doesn't exist we see - * if a native PHP function does. Users can use - * any native PHP function call that has one param. - */ + // If our own wrapper function doesn't exist we see if a native PHP function does. + // Users can use any native PHP function call that has one param. if (function_exists($rule)) { $result = $rule($postdata); -- cgit v1.2.3-24-g4f1b From 9da2ee9155eb8694f06a125ac1bec166e9071ac8 Mon Sep 17 00:00:00 2001 From: Rick Ellis Date: Tue, 23 Sep 2008 20:39:50 +0000 Subject: Fixed a bug that was adding too many blank paragraph tags under certain conditions --- system/libraries/Typography.php | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) (limited to 'system') diff --git a/system/libraries/Typography.php b/system/libraries/Typography.php index 13b36dd64..76160bfe1 100644 --- a/system/libraries/Typography.php +++ b/system/libraries/Typography.php @@ -27,10 +27,10 @@ class CI_Typography { // Block level elements that should not be wrapped inside

    tags - var $block_elements = 'p|div|blockquote|pre|code|h\d|script|ol|ul'; + var $block_elements = 'p|div|blockquote|pre|code|h\d|script|ol|ul|dl|dt|dd'; // Elements that should not have

    and
    tags within them. - var $skip_elements = 'p|pre|ol|ul'; + var $skip_elements = 'p|pre|ol|ul|dl'; // Tags we want the parser to completely ignore when splitting the string. var $ignore_elements = 'a|b|i|em|strong|span|img|li'; @@ -154,7 +154,7 @@ class CI_Typography { '/()

    /' => '$1', // )+#' => '

    ', + '#(

    )+#' => '

    ', '/(

    )+/' => '

    ', // Clean up stray paragraph tags that appear before block level elements @@ -260,11 +260,21 @@ class CI_Typography { { return $str; } - - $str = str_replace("\n\n", "

    \n\n

    ", $str); + + // Convert two consecutive newlines to paragraphs + $str = str_replace("\n\n", "

    \n\n

    ", $str); + + // Convert single spaces to
    tags $str = preg_replace("/([^\n])(\n)([^\n])/", "\\1
    \\2\\3", $str); - return '

    '.$str.'

    '; + // Wrap the whole enchilada in enclosing paragraphs + $str = '

    '.$str.'

    '; + + // Remove empty paragraphs if they are on the first line, as this + // is a potential unintended consequence of the previous code + $str = preg_replace("/

    <\/p>(.*)/", "\\1", $str, 1); + + return $str; } // ------------------------------------------------------------------------ -- cgit v1.2.3-24-g4f1b From 57f9f39ca6edd4c9cea0f68b86da0ec7a9098f0b Mon Sep 17 00:00:00 2001 From: Derek Allard Date: Tue, 23 Sep 2008 20:59:14 +0000 Subject: change of a false test (yes, again) --- system/libraries/Encrypt.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system') diff --git a/system/libraries/Encrypt.php b/system/libraries/Encrypt.php index bd74592d1..656d51b4a 100644 --- a/system/libraries/Encrypt.php +++ b/system/libraries/Encrypt.php @@ -141,7 +141,7 @@ class CI_Encrypt { { $key = $this->get_key($key); - if (preg_match('/[^a-zA-Z0-9\/\+=]/', $string) === FALSE) + if ( ! preg_match('/[a-zA-Z0-9\/\+=]/', $string)) { return FALSE; } -- cgit v1.2.3-24-g4f1b From 4585159f8b39e58b22fa409a1e33e404cfe33777 Mon Sep 17 00:00:00 2001 From: Derek Jones Date: Tue, 23 Sep 2008 22:42:23 +0000 Subject: Fixed a bug in the Session class when database sessions are used where upon session update all userdata would be errantly written to the session cookie. Also rewrote a bit of the cookie handling code to be a bit more efficient and understandable --- system/libraries/Session.php | 31 ++++++++++++++++++------------- 1 file changed, 18 insertions(+), 13 deletions(-) (limited to 'system') diff --git a/system/libraries/Session.php b/system/libraries/Session.php index 7e50dce25..4fe449727 100644 --- a/system/libraries/Session.php +++ b/system/libraries/Session.php @@ -252,16 +252,17 @@ class CI_Session { return; } - // We need two copies of the session data array. One will contain any custom data - // that might have been set. The other will contain the data that will be saved to the cookie - $cookie_userdata = $this->userdata; + // 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 @@ -271,14 +272,7 @@ class CI_Session { $custom_userdata = ''; } else - { - // Before we serialize the custom data array, let's remove that data from the - // main session array since we do not want to save that info to the cookie - foreach (array_keys($custom_userdata) as $val) - { - unset($cookie_userdata[$val]); - } - + { // Serialize the custom data array so we can store it $custom_userdata = serialize($custom_userdata); } @@ -365,14 +359,25 @@ class CI_Session { $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(); + $this->_set_cookie($cookie_data); } // -------------------------------------------------------------------- -- cgit v1.2.3-24-g4f1b From 9976587c01b21e96b0b98b4155d72287f8033118 Mon Sep 17 00:00:00 2001 From: Derek Jones Date: Wed, 24 Sep 2008 17:19:44 +0000 Subject: put all valid block level elements into $block_elements array, added table to tags with which

    should not be directly contained within --- system/libraries/Typography.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'system') diff --git a/system/libraries/Typography.php b/system/libraries/Typography.php index 76160bfe1..eeb507d34 100644 --- a/system/libraries/Typography.php +++ b/system/libraries/Typography.php @@ -27,10 +27,10 @@ class CI_Typography { // Block level elements that should not be wrapped inside

    tags - var $block_elements = 'p|div|blockquote|pre|code|h\d|script|ol|ul|dl|dt|dd'; + var $block_elements = 'address|blockquote|del|div|dl|fieldset|form|h\d|hr|ins|noscript|ol|p|pre|script|table|ul'; // Elements that should not have

    and
    tags within them. - var $skip_elements = 'p|pre|ol|ul|dl'; + var $skip_elements = 'p|pre|ol|ul|dl|table'; // Tags we want the parser to completely ignore when splitting the string. var $ignore_elements = 'a|b|i|em|strong|span|img|li'; @@ -126,7 +126,7 @@ class CI_Typography { { if (preg_match("#".$this->skip_elements."#", $match[2])) { - $process = ($match[1] == '/') ? TRUE : FALSE; + $process = ($match[1] == '/') ? TRUE : FALSE; } $str .= $chunk; -- cgit v1.2.3-24-g4f1b From c184b3beda28be9c5815fdfc1be7aa79c8b84b16 Mon Sep 17 00:00:00 2001 From: Derek Jones Date: Wed, 24 Sep 2008 17:54:50 +0000 Subject: renamed $ignore_elements to $inline_elements, and made more robust by including all valid inline HTML elements --- system/libraries/Typography.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'system') diff --git a/system/libraries/Typography.php b/system/libraries/Typography.php index eeb507d34..da100dc17 100644 --- a/system/libraries/Typography.php +++ b/system/libraries/Typography.php @@ -27,13 +27,13 @@ class CI_Typography { // Block level elements that should not be wrapped inside

    tags - var $block_elements = 'address|blockquote|del|div|dl|fieldset|form|h\d|hr|ins|noscript|ol|p|pre|script|table|ul'; + var $block_elements = 'address|blockquote|div|dl|fieldset|form|h\d|hr|noscript|ol|p|pre|script|table|ul'; // Elements that should not have

    and
    tags within them. var $skip_elements = 'p|pre|ol|ul|dl|table'; // Tags we want the parser to completely ignore when splitting the string. - var $ignore_elements = 'a|b|i|em|strong|span|img|li'; + var $inline_elements = 'a|abbr|acronym|b|bdo|br|button|cite|code|del|dfn|em|i|img|ins|input|label|map|kbd|object|samp|select|span|strong|sub|sup|textarea|var'; /** * Nothing to do here... @@ -101,7 +101,7 @@ class CI_Typography { // Convert "ignore" tags to temporary marker. The parser splits out the string at every tag // it encounters. Certain inline tags, like image tags, links, span tags, etc. will be // adversely affected if they are split out so we'll convert the opening bracket < temporarily to: {@TAG} - $str = preg_replace("#<(/*)(".$this->ignore_elements.")#i", "{@TAG}\\1\\2", $str); + $str = preg_replace("#<(/*)(".$this->inline_elements.")#i", "{@TAG}\\1\\2", $str); // Split the string at every tag. This expression creates an array with this prototype: // -- cgit v1.2.3-24-g4f1b From d16bab12339fe2746e1ead72ba96351c3423c27c Mon Sep 17 00:00:00 2001 From: Derek Jones Date: Wed, 24 Sep 2008 18:22:03 +0000 Subject: added removal of non-printing characters to escape_str() of drivers that do not have native PHP escaping mechanisms --- system/database/drivers/mssql/mssql_driver.php | 2 +- system/database/drivers/oci8/oci8_driver.php | 2 +- system/database/drivers/odbc/odbc_driver.php | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) (limited to 'system') diff --git a/system/database/drivers/mssql/mssql_driver.php b/system/database/drivers/mssql/mssql_driver.php index 98c03c56e..5ac90b451 100644 --- a/system/database/drivers/mssql/mssql_driver.php +++ b/system/database/drivers/mssql/mssql_driver.php @@ -214,7 +214,7 @@ class CI_DB_mssql_driver extends CI_DB { function escape_str($str) { // Escape single quotes - return str_replace("'", "''", $str); + return str_replace("'", "''", $this->input->_remove_invisible_characters($str)); } // -------------------------------------------------------------------- diff --git a/system/database/drivers/oci8/oci8_driver.php b/system/database/drivers/oci8/oci8_driver.php index d6bc512be..765c3f6c9 100644 --- a/system/database/drivers/oci8/oci8_driver.php +++ b/system/database/drivers/oci8/oci8_driver.php @@ -366,7 +366,7 @@ class CI_DB_oci8_driver extends CI_DB { */ function escape_str($str) { - return $str; + return $this->input->_remove_invisible_characters($str); } // -------------------------------------------------------------------- diff --git a/system/database/drivers/odbc/odbc_driver.php b/system/database/drivers/odbc/odbc_driver.php index 647171696..f89000d83 100644 --- a/system/database/drivers/odbc/odbc_driver.php +++ b/system/database/drivers/odbc/odbc_driver.php @@ -235,7 +235,7 @@ class CI_DB_odbc_driver extends CI_DB { function escape_str($str) { // ODBC doesn't require escaping - return $str; + return $this->input->_remove_invisible_characters($str); } // -------------------------------------------------------------------- -- cgit v1.2.3-24-g4f1b From 92490684ef1b2a1b1417727c392ee28288fd41a9 Mon Sep 17 00:00:00 2001 From: Derek Jones Date: Wed, 24 Sep 2008 20:44:34 +0000 Subject: fixed an issue where the last character before convert ... to an ellipsis was being dropped --- system/libraries/Typography.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system') diff --git a/system/libraries/Typography.php b/system/libraries/Typography.php index da100dc17..6b18a2dfd 100644 --- a/system/libraries/Typography.php +++ b/system/libraries/Typography.php @@ -225,7 +225,7 @@ class CI_Typography { // Em dash and ellipses dots '/\s?\-\-\s?/' => '—', - '/\w\.{3}/' => '…', + '/(\w)\.{3}/' => '$1…', // double space after sentences '/(\W) /' => '$1  ', -- cgit v1.2.3-24-g4f1b From 69db8efaffadfc93ff0eec3a9733793e8b358dfb Mon Sep 17 00:00:00 2001 From: Derek Allard Date: Thu, 25 Sep 2008 13:04:12 +0000 Subject: Fixed incorrect parenthesis in form_open() function. (#5135) A few doc typo fixes --- system/helpers/form_helper.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system') diff --git a/system/helpers/form_helper.php b/system/helpers/form_helper.php index fc2592241..a45faf631 100644 --- a/system/helpers/form_helper.php +++ b/system/helpers/form_helper.php @@ -57,7 +57,7 @@ if ( ! function_exists('form_open')) $form .= '>'; - if (is_array($hidden) AND count($hidden > 0)) + if (is_array($hidden) AND count($hidden) > 0) { $form .= form_hidden($hidden); } -- cgit v1.2.3-24-g4f1b From e07ba013ad4ee70ff26ce6ee081cc0d5396a7e03 Mon Sep 17 00:00:00 2001 From: Derek Jones Date: Thu, 25 Sep 2008 22:14:01 +0000 Subject: added check that content is surrounded by a valid block level element, and if not, wrapped in paragraph tags --- system/libraries/Typography.php | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'system') diff --git a/system/libraries/Typography.php b/system/libraries/Typography.php index 6b18a2dfd..94c9de01b 100644 --- a/system/libraries/Typography.php +++ b/system/libraries/Typography.php @@ -143,6 +143,12 @@ class CI_Typography { $str .= $this->_format_newlines($chunk); } + // is the whole of the content inside a block level element? + if ( ! preg_match("/^<(?:".$this->block_elements.")/i", $str, $match)) + { + $str = "

    {$str}

    "; + } + // Convert quotes, elipsis, and em-dashes $str = $this->format_characters($str); -- cgit v1.2.3-24-g4f1b From af03e056ce1a479dc9f1d6b0a88a6bcb06a31d3c Mon Sep 17 00:00:00 2001 From: Derek Jones Date: Fri, 26 Sep 2008 15:59:28 +0000 Subject: fixed decode()'s validation of the string... --- system/libraries/Encrypt.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system') diff --git a/system/libraries/Encrypt.php b/system/libraries/Encrypt.php index 656d51b4a..035ce8f68 100644 --- a/system/libraries/Encrypt.php +++ b/system/libraries/Encrypt.php @@ -141,7 +141,7 @@ class CI_Encrypt { { $key = $this->get_key($key); - if ( ! preg_match('/[a-zA-Z0-9\/\+=]/', $string)) + if (preg_match('/[^a-zA-Z0-9\/\+=]/', $string)) { return FALSE; } -- cgit v1.2.3-24-g4f1b From b3a3bf342903b32a79e8799860a61b93d7f28581 Mon Sep 17 00:00:00 2001 From: Derek Jones Date: Fri, 26 Sep 2008 17:20:53 +0000 Subject: removed some legacy escaping code from _backup() in the MySQL utility, fixing bug 4536 http://codeigniter.com/bug_tracker/bug/4536/ --- system/database/drivers/mysql/mysql_utility.php | 9 --------- 1 file changed, 9 deletions(-) (limited to 'system') diff --git a/system/database/drivers/mysql/mysql_utility.php b/system/database/drivers/mysql/mysql_utility.php index 6fb1ab4bb..e035e0cf6 100644 --- a/system/database/drivers/mysql/mysql_utility.php +++ b/system/database/drivers/mysql/mysql_utility.php @@ -176,15 +176,6 @@ class CI_DB_mysql_utility extends CI_DB_utility { } else { - // Do a little formatting... - $v = str_replace(array("\x00", "\x0a", "\x0d", "\x1a"), array('\0', '\n', '\r', '\Z'), $v); - $v = str_replace(array("\n", "\r", "\t"), array('\n', '\r', '\t'), $v); - $v = str_replace('\\', '\\\\', $v); - $v = str_replace('\'', '\\\'', $v); - $v = str_replace('\\\n', '\n', $v); - $v = str_replace('\\\r', '\r', $v); - $v = str_replace('\\\t', '\t', $v); - // Escape the data if it's not an integer if ($is_int[$i] == FALSE) { -- cgit v1.2.3-24-g4f1b From 07fa5664978b333f6fd84f4248c50cdbdfe9dc6b Mon Sep 17 00:00:00 2001 From: Derek Jones Date: Sat, 27 Sep 2008 00:06:19 +0000 Subject: tweak of inline_element regex so that it doesn't hit partial matches, i.e. viewing
    inline_elements.")#i", "{@TAG}\\1\\2", $str); + $str = preg_replace("#<(/*)(".$this->inline_elements.")[ >]#i", "{@TAG}\\1\\2", $str); // Split the string at every tag. This expression creates an array with this prototype: // @@ -132,7 +132,7 @@ class CI_Typography { $str .= $chunk; continue; } - + if ($process == FALSE) { $str .= $chunk; -- cgit v1.2.3-24-g4f1b From f2b7f62f79791cae890a84a4f7b0eeb46449a5d1 Mon Sep 17 00:00:00 2001 From: Derek Jones Date: Sat, 27 Sep 2008 00:10:37 +0000 Subject: tweak tweak... --- system/libraries/Typography.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system') diff --git a/system/libraries/Typography.php b/system/libraries/Typography.php index 57cb97c73..7eaa4057d 100644 --- a/system/libraries/Typography.php +++ b/system/libraries/Typography.php @@ -101,7 +101,7 @@ class CI_Typography { // Convert "ignore" tags to temporary marker. The parser splits out the string at every tag // it encounters. Certain inline tags, like image tags, links, span tags, etc. will be // adversely affected if they are split out so we'll convert the opening bracket < temporarily to: {@TAG} - $str = preg_replace("#<(/*)(".$this->inline_elements.")[ >]#i", "{@TAG}\\1\\2", $str); + $str = preg_replace("#<(/*)(".$this->inline_elements.")([ >])#i", "{@TAG}\\1\\2\\3", $str); // Split the string at every tag. This expression creates an array with this prototype: // -- cgit v1.2.3-24-g4f1b From fa5c4101d4dc171824e222d4650e0ad15409fce0 Mon Sep 17 00:00:00 2001 From: Derek Jones Date: Tue, 30 Sep 2008 00:47:54 +0000 Subject: moved object out of inline elements to the block elements and skip elements variables. Yes, I know it's technically an inline element, but it's common usage is as a block element, and the typography parser needs to know not to smash a bunch of paragraph tags and
    s inside of it, regardless of how it's used --- system/libraries/Typography.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'system') diff --git a/system/libraries/Typography.php b/system/libraries/Typography.php index 7eaa4057d..7cdf7ddd6 100644 --- a/system/libraries/Typography.php +++ b/system/libraries/Typography.php @@ -27,13 +27,13 @@ class CI_Typography { // Block level elements that should not be wrapped inside

    tags - var $block_elements = 'address|blockquote|div|dl|fieldset|form|h\d|hr|noscript|ol|p|pre|script|table|ul'; + 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|table'; + var $skip_elements = 'p|pre|ol|ul|dl|object|table'; // Tags we want the parser to completely ignore when splitting the string. - var $inline_elements = 'a|abbr|acronym|b|bdo|br|button|cite|code|del|dfn|em|i|img|ins|input|label|map|kbd|object|samp|select|span|strong|sub|sup|textarea|var'; + var $inline_elements = 'a|abbr|acronym|b|bdo|br|button|cite|code|del|dfn|em|i|img|ins|input|label|map|kbd|samp|select|span|strong|sub|sup|textarea|var'; /** * Nothing to do here... -- cgit v1.2.3-24-g4f1b From 52dc8ca4372eb36e9186cef0e34bf0cafe5b1cd8 Mon Sep 17 00:00:00 2001 From: Rick Ellis Date: Tue, 30 Sep 2008 19:53:52 +0000 Subject: Added backticks to column names when using insert_string and update_string. Relates to this bug report: http://codeigniter.com/bug_tracker/bug/4509/ --- system/database/DB_driver.php | 5 ++-- system/database/drivers/mssql/mssql_driver.php | 29 ++++++++++++++-------- system/database/drivers/mysql/mysql_driver.php | 16 ++++++++++++ system/database/drivers/mysqli/mysqli_driver.php | 16 ++++++++++++ system/database/drivers/oci8/oci8_driver.php | 17 +++++++++++++ system/database/drivers/odbc/odbc_driver.php | 22 +++++++++++++--- system/database/drivers/postgre/postgre_driver.php | 18 +++++++++++++- system/database/drivers/sqlite/sqlite_driver.php | 20 +++++++++++++-- 8 files changed, 124 insertions(+), 19 deletions(-) (limited to 'system') diff --git a/system/database/DB_driver.php b/system/database/DB_driver.php index 1450a0644..b937ffd6a 100644 --- a/system/database/DB_driver.php +++ b/system/database/DB_driver.php @@ -911,11 +911,10 @@ class CI_DB_driver { foreach($data as $key => $val) { - $fields[] = $key; + $fields[] = $this->_escape_column($key); $values[] = $this->escape($val); } - return $this->_insert($this->prep_tablename($table), $fields, $values); } @@ -940,7 +939,7 @@ class CI_DB_driver { $fields = array(); foreach($data as $key => $val) { - $fields[$key] = $this->escape($val); + $fields[$this->_escape_column($key)] = $this->escape($val); } if ( ! is_array($where)) diff --git a/system/database/drivers/mssql/mssql_driver.php b/system/database/drivers/mssql/mssql_driver.php index 5ac90b451..9a912a320 100644 --- a/system/database/drivers/mssql/mssql_driver.php +++ b/system/database/drivers/mssql/mssql_driver.php @@ -390,7 +390,24 @@ class CI_DB_mssql_driver extends CI_DB { // Are error numbers supported? return ''; } - + + // -------------------------------------------------------------------- + + /** + * Escape Column Name + * + * This function adds backticks around supplied column name + * + * @access private + * @param string the column name + * @return string + */ + function _escape_column($column) + { + // Not necessary with MS SQL so we simply return the value + return $column; + } + // -------------------------------------------------------------------- /** @@ -405,15 +422,7 @@ class CI_DB_mssql_driver extends CI_DB { */ function _escape_table($table) { - // I don't believe this is necessary with MS SQL. Not sure, though. - Rick - - /* - if (strpos($table, '.') !== FALSE) - { - $table = '"' . str_replace('.', '"."', $table) . '"'; - } - */ - + // Not necessary with MS SQL so we simply return the value return $table; } diff --git a/system/database/drivers/mysql/mysql_driver.php b/system/database/drivers/mysql/mysql_driver.php index 9d9b6512b..de372e669 100644 --- a/system/database/drivers/mysql/mysql_driver.php +++ b/system/database/drivers/mysql/mysql_driver.php @@ -398,6 +398,22 @@ class CI_DB_mysql_driver extends CI_DB { { return mysql_errno($this->conn_id); } + + // -------------------------------------------------------------------- + + /** + * Escape Column Name + * + * This function adds backticks around supplied column name + * + * @access private + * @param string the column name + * @return string + */ + function _escape_column($column) + { + return '`' .$column. '`'; + } // -------------------------------------------------------------------- diff --git a/system/database/drivers/mysqli/mysqli_driver.php b/system/database/drivers/mysqli/mysqli_driver.php index cd683dfe7..35a7fc077 100644 --- a/system/database/drivers/mysqli/mysqli_driver.php +++ b/system/database/drivers/mysqli/mysqli_driver.php @@ -394,6 +394,22 @@ class CI_DB_mysqli_driver extends CI_DB { { return mysqli_errno($this->conn_id); } + + // -------------------------------------------------------------------- + + /** + * Escape Column Name + * + * This function adds backticks around supplied column name + * + * @access private + * @param string the column name + * @return string + */ + function _escape_column($column) + { + return '`' .$column. '`'; + } // -------------------------------------------------------------------- diff --git a/system/database/drivers/oci8/oci8_driver.php b/system/database/drivers/oci8/oci8_driver.php index 765c3f6c9..b45b00326 100644 --- a/system/database/drivers/oci8/oci8_driver.php +++ b/system/database/drivers/oci8/oci8_driver.php @@ -506,6 +506,23 @@ class CI_DB_oci8_driver extends CI_DB { $error = ocierror($this->conn_id); return $error['code']; } + + // -------------------------------------------------------------------- + + /** + * Escape Column Name + * + * This function adds backticks around supplied column name + * + * @access private + * @param string the column name + * @return string + */ + function _escape_column($column) + { + // Probably not necessary with Oracle so we simply return the value + return $column; + } // -------------------------------------------------------------------- diff --git a/system/database/drivers/odbc/odbc_driver.php b/system/database/drivers/odbc/odbc_driver.php index f89000d83..ed8f81cb9 100644 --- a/system/database/drivers/odbc/odbc_driver.php +++ b/system/database/drivers/odbc/odbc_driver.php @@ -371,7 +371,23 @@ class CI_DB_odbc_driver extends CI_DB { { return odbc_error($this->conn_id); } - + // -------------------------------------------------------------------- + + /** + * Escape Column Name + * + * This function adds backticks around supplied column name + * + * @access private + * @param string the column name + * @return string + */ + function _escape_column($column) + { + // Not necessary with ODBC so we simply return the value + return $column; + } + // -------------------------------------------------------------------- /** @@ -386,9 +402,9 @@ class CI_DB_odbc_driver extends CI_DB { */ function _escape_table($table) { - // used to add backticks in other db drivers + // Not necessary with ODBC so we simply return the value return $table; - } + } // -------------------------------------------------------------------- diff --git a/system/database/drivers/postgre/postgre_driver.php b/system/database/drivers/postgre/postgre_driver.php index 7574ded13..3d006d3d6 100644 --- a/system/database/drivers/postgre/postgre_driver.php +++ b/system/database/drivers/postgre/postgre_driver.php @@ -391,7 +391,23 @@ class CI_DB_postgre_driver extends CI_DB { { return ''; } - + // -------------------------------------------------------------------- + + /** + * Escape Column Name + * + * This function adds backticks around supplied column name + * + * @access private + * @param string the column name + * @return string + */ + function _escape_column($column) + { + // Probably not necessary with Postgres so we simply return the value + return $column; + } + // -------------------------------------------------------------------- /** diff --git a/system/database/drivers/sqlite/sqlite_driver.php b/system/database/drivers/sqlite/sqlite_driver.php index 5cac04dfa..46e0fae49 100644 --- a/system/database/drivers/sqlite/sqlite_driver.php +++ b/system/database/drivers/sqlite/sqlite_driver.php @@ -387,7 +387,24 @@ class CI_DB_sqlite_driver extends CI_DB { { return sqlite_last_error($this->conn_id); } - + + // -------------------------------------------------------------------- + + /** + * Escape Column Name + * + * This function adds backticks around supplied column name + * + * @access private + * @param string the column name + * @return string + */ + function _escape_column($column) + { + // Not necessary with SQLite so we simply return the value + return $column; + } + // -------------------------------------------------------------------- /** @@ -402,7 +419,6 @@ class CI_DB_sqlite_driver extends CI_DB { */ function _escape_table($table) { - // other database drivers use this to add backticks, hence this // function is simply going to return the tablename for sqlite return $table; -- cgit v1.2.3-24-g4f1b From 8f99224e6c6d3ac51cb0f356e2e0feb10fa93f31 Mon Sep 17 00:00:00 2001 From: Rick Ellis Date: Tue, 30 Sep 2008 20:13:53 +0000 Subject: Added a case-sensitivity check to called controller methods, as per this bug report: http://codeigniter.com/bug_tracker/bug/4560/ --- system/codeigniter/CodeIgniter.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'system') diff --git a/system/codeigniter/CodeIgniter.php b/system/codeigniter/CodeIgniter.php index 692d84a38..27094d240 100644 --- a/system/codeigniter/CodeIgniter.php +++ b/system/codeigniter/CodeIgniter.php @@ -169,11 +169,10 @@ $BM->mark('loading_time_base_classes_end'); $class = $RTR->fetch_class(); $method = $RTR->fetch_method(); - if ( ! class_exists($class) OR $method == 'controller' OR strncmp($method, '_', 1) == 0 - OR in_array($method, get_class_methods('Controller'), TRUE) + OR in_array(strtolower($method), array_map('strtolower', get_class_methods('Controller'))) ) { show_404("{$class}/{$method}"); -- cgit v1.2.3-24-g4f1b From ff73401cdef0136c15c6dab95d4d722123668e7a Mon Sep 17 00:00:00 2001 From: Rick Ellis Date: Tue, 30 Sep 2008 20:38:12 +0000 Subject: Did a little clean up. Nothing that affected functionality --- system/database/DB_active_rec.php | 3 +-- system/database/DB_forge.php | 10 ++++++++++ system/database/drivers/mssql/mssql_driver.php | 2 +- system/database/drivers/mysql/mysql_driver.php | 3 +++ system/database/drivers/oci8/oci8_driver.php | 2 +- system/database/drivers/odbc/odbc_driver.php | 2 +- system/database/drivers/postgre/postgre_driver.php | 2 +- system/database/drivers/sqlite/sqlite_driver.php | 20 +------------------- system/database/drivers/sqlite/sqlite_forge.php | 22 ++++++++++++++++++++-- 9 files changed, 39 insertions(+), 27 deletions(-) (limited to 'system') diff --git a/system/database/DB_active_rec.php b/system/database/DB_active_rec.php index fccf1b0a2..355868386 100644 --- a/system/database/DB_active_rec.php +++ b/system/database/DB_active_rec.php @@ -821,11 +821,10 @@ class CI_DB_active_record extends CI_DB_driver { /** * Sets the HAVING values * - * Called by having() or orhaving() + * Called by having() or or_having() * * @access private * @param string - * @param string * @return object */ diff --git a/system/database/DB_forge.php b/system/database/DB_forge.php index cc88c32f9..d48165e2b 100644 --- a/system/database/DB_forge.php +++ b/system/database/DB_forge.php @@ -97,6 +97,16 @@ class CI_DB_forge { */ 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.'); diff --git a/system/database/drivers/mssql/mssql_driver.php b/system/database/drivers/mssql/mssql_driver.php index 9a912a320..fd3f9638a 100644 --- a/system/database/drivers/mssql/mssql_driver.php +++ b/system/database/drivers/mssql/mssql_driver.php @@ -87,7 +87,7 @@ class CI_DB_mssql_driver extends CI_DB { */ function db_set_charset($charset, $collation) { - // TODO - add support if needed + // @todo - add support if needed return TRUE; } diff --git a/system/database/drivers/mysql/mysql_driver.php b/system/database/drivers/mysql/mysql_driver.php index de372e669..52df1e591 100644 --- a/system/database/drivers/mysql/mysql_driver.php +++ b/system/database/drivers/mysql/mysql_driver.php @@ -314,6 +314,9 @@ class CI_DB_mysql_driver extends CI_DB { $query = $this->query($this->_count_string . $this->_protect_identifiers('numrows'). " FROM " . $this->_protect_identifiers($this->dbprefix.$table)); + if ($query->num_rows() == 0) + return '0'; + $row = $query->row(); return (int)$row->numrows; } diff --git a/system/database/drivers/oci8/oci8_driver.php b/system/database/drivers/oci8/oci8_driver.php index b45b00326..9d9193252 100644 --- a/system/database/drivers/oci8/oci8_driver.php +++ b/system/database/drivers/oci8/oci8_driver.php @@ -111,7 +111,7 @@ class CI_DB_oci8_driver extends CI_DB { */ function db_set_charset($charset, $collation) { - // TODO - add support if needed + // @todo - add support if needed return TRUE; } diff --git a/system/database/drivers/odbc/odbc_driver.php b/system/database/drivers/odbc/odbc_driver.php index ed8f81cb9..06282e55c 100644 --- a/system/database/drivers/odbc/odbc_driver.php +++ b/system/database/drivers/odbc/odbc_driver.php @@ -94,7 +94,7 @@ class CI_DB_odbc_driver extends CI_DB { */ function db_set_charset($charset, $collation) { - // TODO - add support if needed + // @todo - add support if needed return TRUE; } diff --git a/system/database/drivers/postgre/postgre_driver.php b/system/database/drivers/postgre/postgre_driver.php index 3d006d3d6..55f650280 100644 --- a/system/database/drivers/postgre/postgre_driver.php +++ b/system/database/drivers/postgre/postgre_driver.php @@ -92,7 +92,7 @@ class CI_DB_postgre_driver extends CI_DB { */ function db_set_charset($charset, $collation) { - // TODO - add support if needed + // @todo - add support if needed return TRUE; } diff --git a/system/database/drivers/sqlite/sqlite_driver.php b/system/database/drivers/sqlite/sqlite_driver.php index 46e0fae49..782156949 100644 --- a/system/database/drivers/sqlite/sqlite_driver.php +++ b/system/database/drivers/sqlite/sqlite_driver.php @@ -113,7 +113,7 @@ class CI_DB_sqlite_driver extends CI_DB { */ function db_set_charset($charset, $collation) { - // TODO - add support if needed + // @todo - add support if needed return TRUE; } @@ -651,24 +651,6 @@ class CI_DB_sqlite_driver extends CI_DB { @sqlite_close($conn_id); } - // -------------------------------------------------------------------- - - /** - * 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; - } - } diff --git a/system/database/drivers/sqlite/sqlite_forge.php b/system/database/drivers/sqlite/sqlite_forge.php index 05f366a6f..631c9c771 100644 --- a/system/database/drivers/sqlite/sqlite_forge.php +++ b/system/database/drivers/sqlite/sqlite_forge.php @@ -144,7 +144,7 @@ class CI_DB_sqlite_forge extends CI_DB_forge { $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) @@ -161,7 +161,7 @@ class CI_DB_sqlite_forge extends CI_DB_forge { $sql .= ",\n\tUNIQUE (" . implode(', ', $key) . ")"; } } - + $sql .= "\n)"; return $sql; @@ -241,6 +241,24 @@ class CI_DB_sqlite_forge extends CI_DB_forge { 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 */ -- cgit v1.2.3-24-g4f1b From 1346aac56e4c5effee5a66780095ea9d4ea8cf52 Mon Sep 17 00:00:00 2001 From: Rick Ellis Date: Tue, 30 Sep 2008 20:46:58 +0000 Subject: Removed some spaces --- system/database/DB.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'system') diff --git a/system/database/DB.php b/system/database/DB.php index 27eb336f7..2b3ff3dc6 100644 --- a/system/database/DB.php +++ b/system/database/DB.php @@ -73,7 +73,7 @@ function &DB($params = '', $active_record_override = FALSE) if (isset($dns['query'])) { parse_str($dns['query'], $extra); - + foreach($extra as $key => $val) { // booleans please @@ -85,12 +85,12 @@ function &DB($params = '', $active_record_override = FALSE) { $val = FALSE; } - + $params[$key] = $val; } } } - + // No DB specified yet? Beat them senseless... if ( ! isset($params['dbdriver']) OR $params['dbdriver'] == '') { -- cgit v1.2.3-24-g4f1b From b2675159482af40004e32ec30fbf6f52cfe62a51 Mon Sep 17 00:00:00 2001 From: Rick Ellis Date: Tue, 30 Sep 2008 21:07:22 +0000 Subject: Fixed a routing bug that occurred when the default route pointed to a subfolder. Bug report: http://codeigniter.com/bug_tracker/bug/4661/ --- system/libraries/Router.php | 14 +++----------- 1 file changed, 3 insertions(+), 11 deletions(-) (limited to 'system') diff --git a/system/libraries/Router.php b/system/libraries/Router.php index 4b90b4bd2..f1923794e 100644 --- a/system/libraries/Router.php +++ b/system/libraries/Router.php @@ -63,7 +63,7 @@ class CI_Router { * @return void */ function _set_routing() - { + { // Are query strings enabled in the config file? // If so, we're done since segment based URIs are not used with query strings. if ($this->config->item('enable_query_strings') === TRUE AND isset($_GET[$this->config->item('controller_trigger')])) @@ -97,16 +97,8 @@ class CI_Router { { show_error("Unable to determine what should be displayed. A default route has not been specified in the routing file."); } - - $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."); - return; + + $this->uri->uri_string = $this->default_controller; } unset($this->routes['default_controller']); -- cgit v1.2.3-24-g4f1b From f08f655d4f3f63f66f8db3dbce6045939f304f03 Mon Sep 17 00:00:00 2001 From: Rick Ellis Date: Tue, 30 Sep 2008 21:16:03 +0000 Subject: Added smtp authorization settings to initialize function, as per this bug report: http://codeigniter.com/bug_tracker/bug/4615/ --- system/libraries/Email.php | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) (limited to 'system') diff --git a/system/libraries/Email.php b/system/libraries/Email.php index 592ead3d2..8c56ccca0 100644 --- a/system/libraries/Email.php +++ b/system/libraries/Email.php @@ -88,10 +88,12 @@ class CI_Email { { $this->initialize($config); } - - $this->_smtp_auth = ($this->smtp_user == '' AND $this->smtp_pass == '') ? FALSE : TRUE; - $this->_safe_mode = ((boolean)@ini_get("safe_mode") === FALSE) ? FALSE : TRUE; - + 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"); } @@ -123,6 +125,9 @@ class CI_Email { } } } + + $this->_smtp_auth = ($this->smtp_user == '' AND $this->smtp_pass == '') ? FALSE : TRUE; + $this->_safe_mode = ((boolean)@ini_get("safe_mode") === FALSE) ? FALSE : TRUE; } // -------------------------------------------------------------------- -- cgit v1.2.3-24-g4f1b From 2aa5a18635a8982b7318d0976ae5d00832fa71ca Mon Sep 17 00:00:00 2001 From: Rick Ellis Date: Tue, 30 Sep 2008 21:23:58 +0000 Subject: Did a little cleanup for better readability --- system/libraries/Email.php | 42 ++++++++++++++++++++++++++++++------------ 1 file changed, 30 insertions(+), 12 deletions(-) (limited to 'system') diff --git a/system/libraries/Email.php b/system/libraries/Email.php index 8c56ccca0..e9a5344fe 100644 --- a/system/libraries/Email.php +++ b/system/libraries/Email.php @@ -59,7 +59,7 @@ class CI_Email { var $_atc_boundary = ""; var $_header_str = ""; var $_smtp_connect = ""; - var $_encoding = "8bit"; + var $_encoding = "8bit"; var $_IP = FALSE; var $_smtp_auth = FALSE; var $_replyto_flag = FALSE; @@ -74,16 +74,16 @@ class CI_Email { var $_protocols = array('mail', 'sendmail', 'smtp'); var $_base_charsets = array('us-ascii', 'iso-2022-'); // 7-bit charsets (excluding language suffix) var $_bit_depths = array('7bit', '8bit'); - var $_priorities = array('1 (Highest)', '2 (High)', '3 (Normal)', '4 (Low)', '5 (Lowest)'); + var $_priorities = array('1 (Highest)', '2 (High)', '3 (Normal)', '4 (Low)', '5 (Lowest)'); /** * Constructor - Sets Email Preferences * * The constructor can be passed an array of config values - */ + */ function CI_Email($config = array()) - { + { if (count($config) > 0) { $this->initialize($config); @@ -105,7 +105,7 @@ class CI_Email { * @access public * @param array * @return void - */ + */ function initialize($config = array()) { $this->clear(); @@ -277,7 +277,9 @@ class CI_Email { $cc = $this->clean_email($cc); if ($this->validate) + { $this->validate_email($cc); + } $this->_set_header('Cc', implode(", ", $cc)); @@ -630,15 +632,15 @@ class CI_Email { { if ($this->mailtype == 'html' && count($this->_attach_name) == 0) { - return 'html'; + return 'html'; } elseif ($this->mailtype == 'html' && count($this->_attach_name) > 0) { - return 'html-attach'; + return 'html-attach'; } elseif ($this->mailtype == 'text' && count($this->_attach_name) > 0) { - return 'plain-attach'; + return 'plain-attach'; } else { @@ -950,7 +952,9 @@ class CI_Email { } if ($this->_get_protocol() == 'mail') + { $this->_header_str = substr($this->_header_str, 0, -1); + } } // -------------------------------------------------------------------- @@ -1167,14 +1171,14 @@ class CI_Email { // Reduce multiple spaces $str = preg_replace("| +|", " ", $str); - + // kill nulls $str = preg_replace('/\x00+/', '', $str); // Standardize newlines if (strpos($str, "\r") !== FALSE) { - $str = str_replace(array("\r\n", "\r"), "\n", $str); + $str = str_replace(array("\r\n", "\r"), "\n", $str); } // We are intentionally wrapping so mail servers will encode characters @@ -1425,18 +1429,26 @@ class CI_Email { if ($this->_safe_mode == TRUE) { if ( ! mail($this->_recipients, $this->_subject, $this->_finalbody, $this->_header_str)) + { return FALSE; + } else + { return TRUE; + } } else { // most documentation of sendmail using the "-f" flag lacks a space after it, however // we've encountered servers that seem to require it to be in place. if ( ! mail($this->_recipients, $this->_subject, $this->_finalbody, $this->_header_str, "-f ".$this->clean_email($this->_headers['From']))) + { return FALSE; + } else + { return TRUE; + } } } @@ -1487,14 +1499,18 @@ class CI_Email { $this->_send_command('from', $this->clean_email($this->_headers['From'])); foreach($this->_recipients as $val) + { $this->_send_command('to', $val); + } if (count($this->_cc_array) > 0) { foreach($this->_cc_array as $val) { if ($val != "") - $this->_send_command('to', $val); + { + $this->_send_command('to', $val); + } } } @@ -1503,7 +1519,9 @@ class CI_Email { foreach($this->_bcc_array as $val) { if ($val != "") - $this->_send_command('to', $val); + { + $this->_send_command('to', $val); + } } } -- cgit v1.2.3-24-g4f1b From 9f02e3c852a38b4e17ac1ade26144d0b9d554693 Mon Sep 17 00:00:00 2001 From: Rick Ellis Date: Tue, 30 Sep 2008 21:51:01 +0000 Subject: Added backticks around column names in where clause. Bug report number: 4668 --- system/database/DB_active_rec.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system') diff --git a/system/database/DB_active_rec.php b/system/database/DB_active_rec.php index 355868386..cd616336d 100644 --- a/system/database/DB_active_rec.php +++ b/system/database/DB_active_rec.php @@ -440,7 +440,7 @@ class CI_DB_active_record extends CI_DB_driver { // exception for "field<=" keys if ($this->_has_operator($k)) { - $k = preg_replace("/([A-Za-z_0-9]+)/", $this->_protect_identifiers('$1'), $k); + $k = preg_replace("/([A-Za-z_0-9]+)/", $this->_escape_column($this->_protect_identifiers('$1')), $k); } else { -- cgit v1.2.3-24-g4f1b From 852160a27ba330f9e47f4fb16d8042c6074f435c Mon Sep 17 00:00:00 2001 From: Rick Ellis Date: Tue, 30 Sep 2008 21:55:34 +0000 Subject: Swiched to escape() rather then escape_str(), as per bug report #4680 --- system/database/DB_active_rec.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'system') diff --git a/system/database/DB_active_rec.php b/system/database/DB_active_rec.php index cd616336d..e7920d083 100644 --- a/system/database/DB_active_rec.php +++ b/system/database/DB_active_rec.php @@ -701,7 +701,7 @@ class CI_DB_active_record extends CI_DB_driver { $prefix = (count($this->ar_like) == 0) ? '' : $type; - $v = $this->escape_str($v); + $v = $this->escape($v); if ($side == 'before') { @@ -851,7 +851,7 @@ class CI_DB_active_record extends CI_DB_driver { if ($v != '') { - $v = ' '.$this->escape_str($v); + $v = ' '.$this->escape($v); } $this->ar_having[] = $prefix.$k.$v; -- cgit v1.2.3-24-g4f1b From 91a091abc17714e00b870b36e5f1d2bb8f009fb2 Mon Sep 17 00:00:00 2001 From: Rick Ellis Date: Wed, 1 Oct 2008 01:07:23 +0000 Subject: Removed some stray tabs --- system/libraries/Benchmark.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'system') diff --git a/system/libraries/Benchmark.php b/system/libraries/Benchmark.php index b5a9a6526..4984bb158 100644 --- a/system/libraries/Benchmark.php +++ b/system/libraries/Benchmark.php @@ -47,7 +47,7 @@ class CI_Benchmark { { $this->marker[$name] = microtime(); } - + // -------------------------------------------------------------------- /** @@ -80,13 +80,13 @@ class CI_Benchmark { { $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); } - + // -------------------------------------------------------------------- /** -- cgit v1.2.3-24-g4f1b From ed339bc99ba2e7b26b3153cbf350a307fb4367c6 Mon Sep 17 00:00:00 2001 From: Rick Ellis Date: Wed, 1 Oct 2008 01:11:29 +0000 Subject: Removed some stray tabs --- system/libraries/Config.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system') diff --git a/system/libraries/Config.php b/system/libraries/Config.php index ca12fde7b..a9cf9f4e4 100644 --- a/system/libraries/Config.php +++ b/system/libraries/Config.php @@ -46,7 +46,7 @@ class CI_Config { { $this->config =& get_config(); log_message('debug', "Config Class Initialized"); - } + } // -------------------------------------------------------------------- -- cgit v1.2.3-24-g4f1b From 8d9b44ddb371846d458cef241c35ea5c196a5424 Mon Sep 17 00:00:00 2001 From: Rick Ellis Date: Wed, 1 Oct 2008 01:18:43 +0000 Subject: Made a small error trapping change to the delete_directory function --- system/libraries/Ftp.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system') diff --git a/system/libraries/Ftp.php b/system/libraries/Ftp.php index 6a957a183..0e3dd5ef9 100644 --- a/system/libraries/Ftp.php +++ b/system/libraries/Ftp.php @@ -379,7 +379,7 @@ class CI_FTP { $list = $this->list_files($filepath); - if ($list !== FALSE) + if ($list !== FALSE AND count($list) > 0) { foreach ($list as $item) { -- cgit v1.2.3-24-g4f1b From b5c93ce3c63af4c4130d5b55a0f16cd022014e57 Mon Sep 17 00:00:00 2001 From: Rick Ellis Date: Wed, 1 Oct 2008 01:21:54 +0000 Subject: removed an errant tab --- system/libraries/Image_lib.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system') diff --git a/system/libraries/Image_lib.php b/system/libraries/Image_lib.php index c734c3063..6b1e7e704 100644 --- a/system/libraries/Image_lib.php +++ b/system/libraries/Image_lib.php @@ -943,7 +943,7 @@ class CI_Image_lib { { @imagealphablending($src_img, TRUE); } - + // Set RGB values for text and shadow $rgba = imagecolorat($wm_img, $this->wm_x_transp, $this->wm_y_transp); $alpha = ($rgba & 0x7F000000) >> 24; -- cgit v1.2.3-24-g4f1b From c3b33befcbcc7846a638c8af8f08e1eafc7b79c2 Mon Sep 17 00:00:00 2001 From: Rick Ellis Date: Wed, 1 Oct 2008 01:31:36 +0000 Subject: Added set_staus_header --- system/libraries/Output.php | 60 +++++++++++++++++++++++++++++++++++++++------ 1 file changed, 53 insertions(+), 7 deletions(-) (limited to 'system') diff --git a/system/libraries/Output.php b/system/libraries/Output.php index 88a30469b..2263fdfb9 100644 --- a/system/libraries/Output.php +++ b/system/libraries/Output.php @@ -94,7 +94,7 @@ class CI_Output { } // -------------------------------------------------------------------- - + /** * Set Header * @@ -107,9 +107,55 @@ class CI_Output { * @param string * @return void */ - function set_header($header) + function set_header($header, $replace = TRUE) { - $this->headers[] = $header; + $this->headers[] = array($header, $replace); + } + + // -------------------------------------------------------------------- + + /** + * Set HTTP Status Header + * + * @access public + * @param int the status code + * @param string + * @return void + */ + function set_status_header($code, $text='') + { + if ( ! in_array($code, array(200, 304, 401, 404)) AND $text == '') + { + show_error('You must submit a status message and a status code'); + } + + if ($text == '') + { + switch($code) + { + case 200: $text = 'OK'; + break; + case 304: $text = 'Not Modified'; + break; + case 401: $text = 'Unauthorized'; + break; + case 404: $text = 'Not Found'; + break; + } + } + + if (substr(php_sapi_name(), 0, 3) == 'cgi') + { + @header("Status: {$code} {$text}", TRUE); + } + elseif ($_SERVER['SERVER_PROTOCOL'] == 'HTTP/1.1' OR $_SERVER['SERVER_PROTOCOL'] == 'HTTP/1.0') + { + @header($_SERVER['SERVER_PROTOCOL']." {$code} {$text}", TRUE, $code); + } + else + { + @header("HTTP/1.1 {$code} {$text}", TRUE, $code); + } } // -------------------------------------------------------------------- @@ -183,7 +229,7 @@ class CI_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'); $output = str_replace('{elapsed_time}', $elapsed, $output); @@ -211,7 +257,7 @@ class CI_Output { { foreach ($this->headers as $header) { - @header($header); + @header($header[0], $header[1]); } } @@ -296,7 +342,7 @@ class CI_Output { $cache_path .= md5($uri); - if ( ! $fp = @fopen($cache_path, 'wb')) + if ( ! $fp = @fopen($cache_path, FOPEN_WRITE_CREATE_DESTRUCTIVE)) { log_message('error', "Unable to write cache file: ".$cache_path); return; @@ -342,7 +388,7 @@ class CI_Output { return FALSE; } - if ( ! $fp = @fopen($filepath, 'rb')) + if ( ! $fp = @fopen($filepath, FOPEN_READ)) { return FALSE; } -- cgit v1.2.3-24-g4f1b From a42f38709d4628ba7e93d62a26d405bfbc0eeb69 Mon Sep 17 00:00:00 2001 From: Rick Ellis Date: Wed, 1 Oct 2008 01:33:52 +0000 Subject: Removed some errant spaces --- system/libraries/Pagination.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'system') diff --git a/system/libraries/Pagination.php b/system/libraries/Pagination.php index 58a706508..957994485 100644 --- a/system/libraries/Pagination.php +++ b/system/libraries/Pagination.php @@ -88,7 +88,7 @@ class CI_Pagination { { $this->$key = $val; } - } + } } } @@ -118,7 +118,7 @@ class CI_Pagination { } // Determine the current page number. - $CI =& get_instance(); + $CI =& get_instance(); if ($CI->config->item('enable_query_strings') === TRUE OR $this->page_query_string === TRUE) { -- cgit v1.2.3-24-g4f1b From d6778fb261dedd1163d947295fd59970256a1f48 Mon Sep 17 00:00:00 2001 From: Rick Ellis Date: Wed, 1 Oct 2008 01:34:52 +0000 Subject: Updated copyright --- system/libraries/Profiler.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system') diff --git a/system/libraries/Profiler.php b/system/libraries/Profiler.php index 55ad1e3c1..13cb1ccaa 100644 --- a/system/libraries/Profiler.php +++ b/system/libraries/Profiler.php @@ -6,7 +6,7 @@ * * @package CodeIgniter * @author ExpressionEngine Dev Team - * @copyright Copyright (c) 2006, EllisLab, Inc. + * @copyright Copyright (c) 2008, EllisLab, Inc. * @license http://codeigniter.com/user_guide/license.html * @link http://codeigniter.com * @since Version 1.0 -- cgit v1.2.3-24-g4f1b From 8ca943f0c550c9b2e7f0deabe2f3fdd269db544d Mon Sep 17 00:00:00 2001 From: Rick Ellis Date: Wed, 1 Oct 2008 01:37:59 +0000 Subject: Removed some errant spaces and tabs --- system/libraries/Typography.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'system') diff --git a/system/libraries/Typography.php b/system/libraries/Typography.php index 7cdf7ddd6..59a96dfdb 100644 --- a/system/libraries/Typography.php +++ b/system/libraries/Typography.php @@ -84,7 +84,7 @@ class CI_Typography { if ($strip_js_event_handlers === TRUE) { $str = preg_replace("#<([^><]+?)([^a-z_\-]on\w*|xmlns)(\s*=\s*[^><]*)([><]*)#i", "<\\1\\4", $str); - } + } // Convert quotes within tags to temporary markers. We don't want quotes converted // within tags so we'll temporarily convert them to {@DQ} and {@SQ} @@ -132,7 +132,7 @@ class CI_Typography { $str .= $chunk; continue; } - + if ($process == FALSE) { $str .= $chunk; -- cgit v1.2.3-24-g4f1b From 8e3869a90ae46c477ba1059a65fc480abea1cc03 Mon Sep 17 00:00:00 2001 From: Rick Ellis Date: Wed, 1 Oct 2008 02:01:53 +0000 Subject: Tweaked the filter_uri function for better security --- system/libraries/URI.php | 28 +++++++++++++++++----------- 1 file changed, 17 insertions(+), 11 deletions(-) (limited to 'system') diff --git a/system/libraries/URI.php b/system/libraries/URI.php index ce64f3c7d..0e4ff50c7 100644 --- a/system/libraries/URI.php +++ b/system/libraries/URI.php @@ -58,23 +58,23 @@ class CI_URI { * @return string */ function _fetch_uri_string() - { + { if (strtoupper($this->config->item('uri_protocol')) == 'AUTO') { // If the URL has a question mark then it's simplest to just // build the URI string from the zero index of the $_GET array. // This avoids having to deal with $_SERVER variables, which // can be unreliable in some environments - if (is_array($_GET) AND count($_GET) == 1 AND trim(key($_GET), '/') != '') + if (is_array($_GET) && count($_GET) == 1 && trim(key($_GET), '/') != '') { - $this->uri_string = key($_GET); + $this->uri_string = key($_GET); 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, '/') != '' AND $path != "/".SELF) + if (trim($path, '/') != '' && $path != "/".SELF) { $this->uri_string = $path; return; @@ -90,7 +90,7 @@ class CI_URI { // No QUERY_STRING?... Maybe the ORIG_PATH_INFO variable exists? $path = (isset($_SERVER['ORIG_PATH_INFO'])) ? $_SERVER['ORIG_PATH_INFO'] : @getenv('ORIG_PATH_INFO'); - if (trim($path, '/') != '' AND $path != "/".SELF) + if (trim($path, '/') != '' && $path != "/".SELF) { // remove path and script information so we have good URI data $this->uri_string = str_replace($_SERVER['SCRIPT_NAME'], '', $path); @@ -119,7 +119,7 @@ class CI_URI { $this->uri_string = ''; } } - + // -------------------------------------------------------------------- /** @@ -157,7 +157,7 @@ class CI_URI { $i = 0; foreach(explode("/", $fc_path) as $segment) { - if (isset($parsed_uri[$i]) AND $segment == $parsed_uri[$i]) + if (isset($parsed_uri[$i]) && $segment == $parsed_uri[$i]) { $i++; } @@ -184,15 +184,19 @@ class CI_URI { */ function _filter_uri($str) { - if ($str != '' AND $this->config->item('permitted_uri_chars') != '') + if ($str != '' && $this->config->item('permitted_uri_chars') != '' && $this->config->item('enable_query_strings') == FALSE) { if ( ! preg_match("|^[".preg_quote($this->config->item('permitted_uri_chars'))."]+$|i", $str)) { exit('The URI you submitted has disallowed characters.'); } - } - - return $str; + } + + // Convert programatic characters to entities + $bad = array('$', '(', ')', '%28', '%29'); + $good = array('$', '(', ')', '(', ')'); + + return str_replace($bad, $good, $str); } // -------------------------------------------------------------------- @@ -228,7 +232,9 @@ class CI_URI { $val = trim($this->_filter_uri($val)); if ($val != '') + { $this->segments[] = $val; + } } } -- cgit v1.2.3-24-g4f1b From d95ebca78e200cb325dcf934492c83090cf2b462 Mon Sep 17 00:00:00 2001 From: Derek Jones Date: Wed, 1 Oct 2008 23:57:38 +0000 Subject: added $protect_braced_quotes to Typography class, to prevent curly-quoting single and double quoted string within {curly "braces"} --- system/libraries/Typography.php | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) (limited to 'system') diff --git a/system/libraries/Typography.php b/system/libraries/Typography.php index 59a96dfdb..2393e164e 100644 --- a/system/libraries/Typography.php +++ b/system/libraries/Typography.php @@ -35,6 +35,9 @@ class CI_Typography { // Tags we want the parser to completely ignore when splitting the string. var $inline_elements = 'a|abbr|acronym|b|bdo|br|button|cite|code|del|dfn|em|i|img|ins|input|label|map|kbd|samp|select|span|strong|sub|sup|textarea|var'; + // whether or not to protect quotes within { curly braces } + var $protect_braced_quotes = FALSE; + /** * Nothing to do here... * @@ -97,7 +100,20 @@ class CI_Typography { $str); } } - + + if ($this->protect_braced_quotes === TRUE) + { + if (preg_match_all("#\{.+?}#si", $str, $matches)) + { + for ($i = 0; $i < count($matches['0']); $i++) + { + $str = str_replace($matches['0'][$i], + str_replace(array("'",'"'), array('{@SQ}', '{@DQ}'), $matches['0'][$i]), + $str); + } + } + } + // Convert "ignore" tags to temporary marker. The parser splits out the string at every tag // it encounters. Certain inline tags, like image tags, links, span tags, etc. will be // adversely affected if they are split out so we'll convert the opening bracket < temporarily to: {@TAG} -- cgit v1.2.3-24-g4f1b From 0dc925f7f30c008c50f8fa801e90203b82cf0542 Mon Sep 17 00:00:00 2001 From: Rick Ellis Date: Thu, 2 Oct 2008 01:03:21 +0000 Subject: Added set_status_header function --- system/libraries/Output.php | 79 +++++++++++++++++++++++++++++++++------------ 1 file changed, 59 insertions(+), 20 deletions(-) (limited to 'system') diff --git a/system/libraries/Output.php b/system/libraries/Output.php index 2263fdfb9..781e368cb 100644 --- a/system/libraries/Output.php +++ b/system/libraries/Output.php @@ -122,39 +122,78 @@ class CI_Output { * @param string * @return void */ - function set_status_header($code, $text='') - { - if ( ! in_array($code, array(200, 304, 401, 404)) AND $text == '') + 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('You must submit a status message and a status code'); + show_error('Status codes must be numeric'); } - + + if (isset($stati[$code]) AND $text == '') + { + $text = $stati[$code]; + } + if ($text == '') { - switch($code) - { - case 200: $text = 'OK'; - break; - case 304: $text = 'Not Modified'; - break; - case 401: $text = 'Unauthorized'; - break; - case 404: $text = 'Not Found'; - break; - } + show_error('No status text available. Please check your status code number or supply your own message text.'); } + + $server_protocol = (isset($_SERVER['SERVER_PROTOCOL'])) ? $_SERVER['SERVER_PROTOCOL'] : FALSE; if (substr(php_sapi_name(), 0, 3) == 'cgi') { - @header("Status: {$code} {$text}", TRUE); + header("Status: {$code} {$text}", TRUE); } - elseif ($_SERVER['SERVER_PROTOCOL'] == 'HTTP/1.1' OR $_SERVER['SERVER_PROTOCOL'] == 'HTTP/1.0') + elseif ($server_protocol == 'HTTP/1.1' OR $server_protocol == 'HTTP/1.0') { - @header($_SERVER['SERVER_PROTOCOL']." {$code} {$text}", TRUE, $code); + header($server_protocol." {$code} {$text}", TRUE, $code); } else { - @header("HTTP/1.1 {$code} {$text}", TRUE, $code); + header("HTTP/1.1 {$code} {$text}", TRUE, $code); } } -- cgit v1.2.3-24-g4f1b From 02b0c399244435f0aeaa710b1992c75964fac88b Mon Sep 17 00:00:00 2001 From: Derek Jones Date: Thu, 2 Oct 2008 21:54:24 +0000 Subject: changed if ($this->cur_page > $this->num_links) to if ($this->cur_page > ($this-> num_links + 1)) so the "First" link only renders when the link for page 1 is now shown --- system/libraries/Pagination.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system') diff --git a/system/libraries/Pagination.php b/system/libraries/Pagination.php index 957994485..4206f4e72 100644 --- a/system/libraries/Pagination.php +++ b/system/libraries/Pagination.php @@ -183,7 +183,7 @@ class CI_Pagination { $output = ''; // Render the "First" link - if ($this->cur_page > $this->num_links) + if ($this->cur_page > ($this->num_links + 1)) { $output .= $this->first_tag_open.''.$this->first_link.''.$this->first_tag_close; } -- cgit v1.2.3-24-g4f1b From 26bde91ef36cacd22772102d3083277bd937a60d Mon Sep 17 00:00:00 2001 From: Rick Ellis Date: Fri, 3 Oct 2008 02:29:56 +0000 Subject: When I fixed a bug that did not permit the default route to be in a sub-folder, I introducted a different bug (#5285), which this should fix --- system/libraries/Router.php | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) (limited to 'system') diff --git a/system/libraries/Router.php b/system/libraries/Router.php index f1923794e..cf425163d 100644 --- a/system/libraries/Router.php +++ b/system/libraries/Router.php @@ -98,7 +98,22 @@ class CI_Router { show_error("Unable to determine what should be displayed. A default route has not been specified in the routing file."); } - $this->uri->uri_string = $this->default_controller; + // Turn the default route into an array. We explode it in the event that + // the controller is located in a subfolder + $segments = $this->_validate_request(explode('/', $this->default_controller)); + + // Set the class and method + $this->set_class($segments[0]); + $this->set_method('index'); + + // Assign the segments to the URI class + $this->uri->rsegments = $segments; + + // 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."); + return; } unset($this->routes['default_controller']); -- cgit v1.2.3-24-g4f1b From c0e72b0609827484dc822ded7fcd0a312ed4eb98 Mon Sep 17 00:00:00 2001 From: Derek Jones Date: Fri, 3 Oct 2008 18:56:06 +0000 Subject: modified how we're performing text highlighting to prevent extra or missing span tags. Namely, removed the start and ending markers, as if the code being highlighted would be styled the same, PHP would put it all in the same , so when we removed our own additions, it would remove the needed opening span style --- system/helpers/text_helper.php | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) (limited to 'system') diff --git a/system/helpers/text_helper.php b/system/helpers/text_helper.php index 954eb797a..54ef1b580 100644 --- a/system/helpers/text_helper.php +++ b/system/helpers/text_helper.php @@ -274,27 +274,27 @@ if ( ! function_exists('highlight_code')) array('phptagopen', 'phptagclose', 'asptagopen', 'asptagclose', 'backslashtmp', 'scriptclose'), $str); // The highlight_string function requires that the text be surrounded - // by PHP tags. Since we don't know if A) the submitted text has PHP tags, - // or B) whether the PHP tags enclose the entire string, we will add our - // own PHP tags around the string along with some markers to make replacement easier later - - $str = ''; - - // All the magic happens here, baby! + // by PHP tags, which we will remove later + $str = ''; // tags + // so we'll replace them with tags. + + if (abs(PHP_VERSION) < 5) { $str = str_replace(array(''), array(''), $str); $str = preg_replace('#color="(.*?)"#', 'style="color: \\1"', $str); + $str = str_replace('<?php ', '', $str); } - - // Remove our artificially added PHP - $str = preg_replace("#\.+?tempstart\
    (?:\)?#is", "\n", $str); - $str = preg_replace("#tempend.+#is", "
    \n", $str); - + + // Remove our artificially added PHP, and the syntax highlighting that came with it + $str = str_replace('<?php ', '', $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); -- cgit v1.2.3-24-g4f1b From 337c74ab2af0dec69659f8c68c82b12c878c1b88 Mon Sep 17 00:00:00 2001 From: Derek Jones Date: Fri, 3 Oct 2008 19:09:53 +0000 Subject: tweak of temp tag and highlighting replacement to accommodate environments with different colors specified for highlight_string() --- system/helpers/text_helper.php | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) (limited to 'system') diff --git a/system/helpers/text_helper.php b/system/helpers/text_helper.php index 54ef1b580..9f13896ae 100644 --- a/system/helpers/text_helper.php +++ b/system/helpers/text_helper.php @@ -287,12 +287,11 @@ if ( ! function_exists('highlight_code')) { $str = str_replace(array(''), array(''), $str); $str = preg_replace('#color="(.*?)"#', 'style="color: \\1"', $str); - $str = str_replace('<?php ', '', $str); } - + // Remove our artificially added PHP, and the syntax highlighting that came with it - $str = str_replace('<?php ', '', $str); - $str = preg_replace('/(.*?)\?><\/span>\n<\/span>\n<\/code>/is', "$1\n\n
    ", $str); + $str = preg_replace('/<\?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. -- cgit v1.2.3-24-g4f1b From 2f26ba98c2ccda07fe2177d0b48b117ca8fddafe Mon Sep 17 00:00:00 2001 From: Rick Ellis Date: Sat, 4 Oct 2008 01:38:01 +0000 Subject: Added function to optionally limit the length of the file name --- system/libraries/Upload.php | 57 ++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 54 insertions(+), 3 deletions(-) (limited to 'system') diff --git a/system/libraries/Upload.php b/system/libraries/Upload.php index 13026bcac..a2437d072 100644 --- a/system/libraries/Upload.php +++ b/system/libraries/Upload.php @@ -29,6 +29,7 @@ class CI_Upload { var $max_size = 0; var $max_width = 0; var $max_height = 0; + var $max_filename = 0; var $allowed_types = ""; var $file_temp = ""; var $file_name = ""; @@ -147,7 +148,7 @@ class CI_Upload { // errors will already be set by validate_upload_path() so just return FALSE return FALSE; } - + // Was the file able to be uploaded? If not, determine the reason why. if ( ! is_uploaded_file($_FILES[$field]['tmp_name'])) { @@ -221,6 +222,12 @@ class CI_Upload { // Sanitize the file name for security $this->file_name = $this->clean_file_name($this->file_name); + + // Truncate the file name if it's too long + if ($this->max_filename > 0) + { + $this->file_name = $this->limit_filename_length($this->file_name, $this->max_filename); + } // Remove white spaces in the name if ($this->remove_spaces == TRUE) @@ -325,7 +332,8 @@ class CI_Upload { */ function set_upload_path($path) { - $this->upload_path = $path; + // Make sure it has a trailing slash + $this->upload_path = rtrim($path, '/').'/'; } // -------------------------------------------------------------------- @@ -347,7 +355,7 @@ class CI_Upload { if ($this->encrypt_name == TRUE) { mt_srand(); - $filename = md5(uniqid(mt_rand())).$this->file_ext; + $filename = md5(uniqid(mt_rand())).$this->file_ext; } if ( ! file_exists($path.$filename)) @@ -394,6 +402,20 @@ class CI_Upload { // -------------------------------------------------------------------- + /** + * Set Maximum File Name Length + * + * @access public + * @param integer + * @return void + */ + function set_max_filename($n) + { + $this->max_filename = ( ! eregi("^[[:digit:]]+$", $n)) ? 0 : $n; + } + + // -------------------------------------------------------------------- + /** * Set Maximum Image Width * @@ -711,7 +733,34 @@ class CI_Upload { return stripslashes($filename); } + + // -------------------------------------------------------------------- + /** + * Limit the File Name Length + * + * @access public + * @param string + * @return string + */ + function limit_filename_length($filename, $length) + { + if (strlen($filename) < $length) + { + return $filename; + } + + $ext = ''; + if (strpos($filename, '.') !== FALSE) + { + $parts = explode('.', $filename); + $ext = '.'.array_pop($parts); + $filename = implode('.', $parts); + } + + return substr($filename, 0, ($length - strlen($ext))).$ext; + } + // -------------------------------------------------------------------- /** @@ -832,6 +881,8 @@ class CI_Upload { return ( ! isset($this->mimes[$mime])) ? FALSE : $this->mimes[$mime]; } + // -------------------------------------------------------------------- + /** * Prep Filename * -- cgit v1.2.3-24-g4f1b From 0aac08e4a24b3fdad3af7f608f6861c18547a42b Mon Sep 17 00:00:00 2001 From: Rick Ellis Date: Sat, 4 Oct 2008 01:39:44 +0000 Subject: Tweaked the last feature added to limit file name length --- system/libraries/Upload.php | 1 + 1 file changed, 1 insertion(+) (limited to 'system') diff --git a/system/libraries/Upload.php b/system/libraries/Upload.php index a2437d072..42d02d941 100644 --- a/system/libraries/Upload.php +++ b/system/libraries/Upload.php @@ -81,6 +81,7 @@ class CI_Upload { 'max_size' => 0, 'max_width' => 0, 'max_height' => 0, + 'max_filename' => 0, 'allowed_types' => "", 'file_temp' => "", 'file_name' => "", -- cgit v1.2.3-24-g4f1b From 9af2ec4d32deb49282587b45d2a02446a6400b19 Mon Sep 17 00:00:00 2001 From: Rick Ellis Date: Sat, 4 Oct 2008 01:47:48 +0000 Subject: removed some ereg() calls for better performance --- system/libraries/Upload.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'system') diff --git a/system/libraries/Upload.php b/system/libraries/Upload.php index 42d02d941..3832dab06 100644 --- a/system/libraries/Upload.php +++ b/system/libraries/Upload.php @@ -398,7 +398,7 @@ class CI_Upload { */ function set_max_filesize($n) { - $this->max_size = ( ! eregi("^[[:digit:]]+$", $n)) ? 0 : $n; + $this->max_size = ((int) $n < 0) ? 0: (int) $n; } // -------------------------------------------------------------------- @@ -412,7 +412,7 @@ class CI_Upload { */ function set_max_filename($n) { - $this->max_filename = ( ! eregi("^[[:digit:]]+$", $n)) ? 0 : $n; + $this->max_filename = ((int) $n < 0) ? 0: (int) $n; } // -------------------------------------------------------------------- @@ -426,7 +426,7 @@ class CI_Upload { */ function set_max_width($n) { - $this->max_width = ( ! eregi("^[[:digit:]]+$", $n)) ? 0 : $n; + $this->max_width = ((int) $n < 0) ? 0: (int) $n; } // -------------------------------------------------------------------- @@ -440,7 +440,7 @@ class CI_Upload { */ function set_max_height($n) { - $this->max_height = ( ! eregi("^[[:digit:]]+$", $n)) ? 0 : $n; + $this->max_height = ((int) $n < 0) ? 0: (int) $n; } // -------------------------------------------------------------------- -- cgit v1.2.3-24-g4f1b From dbc9e15c814ad2fc8a3fb10fbd1350d42b1f7f9c Mon Sep 17 00:00:00 2001 From: Derek Allard Date: Mon, 6 Oct 2008 14:41:47 +0000 Subject: Altered auto_link() in the URL helper so that email addresses with "+" included will be linked. --- system/helpers/url_helper.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system') diff --git a/system/helpers/url_helper.php b/system/helpers/url_helper.php index 121b36b97..acf889007 100644 --- a/system/helpers/url_helper.php +++ b/system/helpers/url_helper.php @@ -400,7 +400,7 @@ if ( ! function_exists('auto_link')) if ($type != 'url') { - if (preg_match_all("/([a-zA-Z0-9_\.\-]+)@([a-zA-Z0-9\-]+)\.([a-zA-Z0-9\-\.]*)/i", $str, $matches)) + if (preg_match_all("/([a-zA-Z0-9_\.\-\+Ã…]+)@([a-zA-Z0-9\-]+)\.([a-zA-Z0-9\-\.]*)/i", $str, $matches)) { for ($i = 0; $i < sizeof($matches['0']); $i++) { -- cgit v1.2.3-24-g4f1b From b4a6cf35fe8c637cec5be811f109f6f841456283 Mon Sep 17 00:00:00 2001 From: Rick Ellis Date: Mon, 6 Oct 2008 18:39:36 +0000 Subject: Added some code to ignore empty folders when deleting directories --- system/helpers/file_helper.php | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'system') diff --git a/system/helpers/file_helper.php b/system/helpers/file_helper.php index 58951823b..6378784f4 100644 --- a/system/helpers/file_helper.php +++ b/system/helpers/file_helper.php @@ -132,7 +132,11 @@ if ( ! function_exists('delete_files')) { if (is_dir($path.'/'.$filename)) { - delete_files($path.'/'.$filename, $del_dir, $level + 1); + // Ignore empty folders + if (substr($filename, 0, 1) != '.') + { + delete_files($path.'/'.$filename, $del_dir, $level + 1); + } } else { -- cgit v1.2.3-24-g4f1b From 2cad6e9da8b94833503d0d2f545bcaa29d50bd5d Mon Sep 17 00:00:00 2001 From: Rick Ellis Date: Tue, 7 Oct 2008 00:19:34 +0000 Subject: There was a call to $this->input->_remove_invisible_characters($str); It should have been: $this->input->CI->_remove_invisible_characters($str); --- system/database/DB_forge.php | 2 +- system/database/drivers/mssql/mssql_driver.php | 2 +- system/database/drivers/oci8/oci8_driver.php | 2 +- system/database/drivers/odbc/odbc_driver.php | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) (limited to 'system') diff --git a/system/database/DB_forge.php b/system/database/DB_forge.php index d48165e2b..64f95d635 100644 --- a/system/database/DB_forge.php +++ b/system/database/DB_forge.php @@ -191,7 +191,7 @@ class CI_DB_forge { } $sql = $this->_create_table($this->db->dbprefix.$table, $this->fields, $this->primary_keys, $this->keys, $if_not_exists); - + $this->_reset(); return $this->db->query($sql); } diff --git a/system/database/drivers/mssql/mssql_driver.php b/system/database/drivers/mssql/mssql_driver.php index fd3f9638a..9d7e072a4 100644 --- a/system/database/drivers/mssql/mssql_driver.php +++ b/system/database/drivers/mssql/mssql_driver.php @@ -214,7 +214,7 @@ class CI_DB_mssql_driver extends CI_DB { function escape_str($str) { // Escape single quotes - return str_replace("'", "''", $this->input->_remove_invisible_characters($str)); + return str_replace("'", "''", $this->CI->input->_remove_invisible_characters($str)); } // -------------------------------------------------------------------- diff --git a/system/database/drivers/oci8/oci8_driver.php b/system/database/drivers/oci8/oci8_driver.php index 9d9193252..98c993291 100644 --- a/system/database/drivers/oci8/oci8_driver.php +++ b/system/database/drivers/oci8/oci8_driver.php @@ -366,7 +366,7 @@ class CI_DB_oci8_driver extends CI_DB { */ function escape_str($str) { - return $this->input->_remove_invisible_characters($str); + return $this->input->CI->_remove_invisible_characters($str); } // -------------------------------------------------------------------- diff --git a/system/database/drivers/odbc/odbc_driver.php b/system/database/drivers/odbc/odbc_driver.php index 06282e55c..a64eb56b9 100644 --- a/system/database/drivers/odbc/odbc_driver.php +++ b/system/database/drivers/odbc/odbc_driver.php @@ -235,7 +235,7 @@ class CI_DB_odbc_driver extends CI_DB { function escape_str($str) { // ODBC doesn't require escaping - return $this->input->_remove_invisible_characters($str); + return $this->input->CI->_remove_invisible_characters($str); } // -------------------------------------------------------------------- -- cgit v1.2.3-24-g4f1b From b6ba6a3a8ef3d594ff3f32f2d128a8211f1d2db3 Mon Sep 17 00:00:00 2001 From: Rick Ellis Date: Tue, 7 Oct 2008 00:44:41 +0000 Subject: Added support for empty connection strings, based on bug # 3135 --- system/database/drivers/postgre/postgre_driver.php | 39 ++++++++++++++++++---- 1 file changed, 32 insertions(+), 7 deletions(-) (limited to 'system') diff --git a/system/database/drivers/postgre/postgre_driver.php b/system/database/drivers/postgre/postgre_driver.php index 55f650280..aada164d0 100644 --- a/system/database/drivers/postgre/postgre_driver.php +++ b/system/database/drivers/postgre/postgre_driver.php @@ -38,6 +38,35 @@ class CI_DB_postgre_driver extends CI_DB { var $_count_string = "SELECT COUNT(*) AS "; var $_random_keyword = ' RANDOM()'; // database specific random keyword + /** + * Connection String + * + * @access private + * @return string + */ + function _connect_string() + { + $components = array( + 'hostname' => '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 * @@ -45,10 +74,8 @@ class CI_DB_postgre_driver extends CI_DB { * @return resource */ function db_connect() - { - $port = ($this->port == '') ? '' : " port=".$this->port; - - return @pg_connect("host=".$this->hostname.$port." dbname=".$this->database." user=".$this->username." password=".$this->password); + { + return @pg_connect($this->_connect_string()); } // -------------------------------------------------------------------- @@ -61,9 +88,7 @@ class CI_DB_postgre_driver extends CI_DB { */ function db_pconnect() { - $port = ($this->port == '') ? '' : " port=".$this->port; - - return @pg_pconnect("host=".$this->hostname.$port." dbname=".$this->database." user=".$this->username." password=".$this->password); + return @pg_pconnect($this->_connect_string()); } // -------------------------------------------------------------------- -- cgit v1.2.3-24-g4f1b From ceb6f0bfdeaad23bad419ff4e62519342cc03d05 Mon Sep 17 00:00:00 2001 From: Rick Ellis Date: Tue, 7 Oct 2008 00:48:19 +0000 Subject: Added $params to ODBC constructor, based on bug report #3374 --- system/database/drivers/odbc/odbc_driver.php | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) (limited to 'system') diff --git a/system/database/drivers/odbc/odbc_driver.php b/system/database/drivers/odbc/odbc_driver.php index a64eb56b9..7c59c3060 100644 --- a/system/database/drivers/odbc/odbc_driver.php +++ b/system/database/drivers/odbc/odbc_driver.php @@ -39,8 +39,16 @@ class CI_DB_odbc_driver extends CI_DB { var $_random_keyword; - function CI_DB_odbc_driver() + function CI_DB_odbc_driver($params) { + if (is_array($params)) + { + foreach ($params as $key => $val) + { + $this->$key = $val; + } + } + $this->_random_keyword = ' RND('.time().')'; // database specific random keyword } -- cgit v1.2.3-24-g4f1b From a2a240a87baa0cf6a425837158880f5235e3bca6 Mon Sep 17 00:00:00 2001 From: Rick Ellis Date: Tue, 7 Oct 2008 00:55:41 +0000 Subject: Fixed a bug (#2985) in which multiple queries using a single request were not being honored --- system/database/DB_driver.php | 1 + 1 file changed, 1 insertion(+) (limited to 'system') diff --git a/system/database/DB_driver.php b/system/database/DB_driver.php index b937ffd6a..257f1ee9b 100644 --- a/system/database/DB_driver.php +++ b/system/database/DB_driver.php @@ -382,6 +382,7 @@ class CI_DB_driver { $RES->stmt_id = $this->stmt_id; $RES->curs_id = NULL; $RES->limit_used = $this->limit_used; + $this->stmt_id = FALSE; } // Is query caching enabled? If so, we'll serialize the -- cgit v1.2.3-24-g4f1b From 482ee4325894bb05b4f97bb9e9ded14e5fce93ba Mon Sep 17 00:00:00 2001 From: Rick Ellis Date: Tue, 7 Oct 2008 00:59:08 +0000 Subject: Fixed Oracle bug (#3306) that was preventing multiple queries in one action --- system/database/drivers/oci8/oci8_driver.php | 1 + 1 file changed, 1 insertion(+) (limited to 'system') diff --git a/system/database/drivers/oci8/oci8_driver.php b/system/database/drivers/oci8/oci8_driver.php index 98c993291..362da58fb 100644 --- a/system/database/drivers/oci8/oci8_driver.php +++ b/system/database/drivers/oci8/oci8_driver.php @@ -141,6 +141,7 @@ class CI_DB_oci8_driver extends CI_DB { { // 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); ocisetprefetch($this->stmt_id, 1000); return @ociexecute($this->stmt_id, $this->_commit); -- cgit v1.2.3-24-g4f1b From 06a2e74e8834e88e4639d17dc756403985ca00f8 Mon Sep 17 00:00:00 2001 From: Rick Ellis Date: Tue, 7 Oct 2008 01:04:15 +0000 Subject: Oops! Didn't realize that the CI super object was not being used by the main Driver. Fixed... --- system/database/drivers/mssql/mssql_driver.php | 7 +++++-- system/database/drivers/oci8/oci8_driver.php | 5 ++++- system/database/drivers/odbc/odbc_driver.php | 5 ++++- 3 files changed, 13 insertions(+), 4 deletions(-) (limited to 'system') diff --git a/system/database/drivers/mssql/mssql_driver.php b/system/database/drivers/mssql/mssql_driver.php index 9d7e072a4..1c6249aef 100644 --- a/system/database/drivers/mssql/mssql_driver.php +++ b/system/database/drivers/mssql/mssql_driver.php @@ -212,9 +212,12 @@ class CI_DB_mssql_driver extends CI_DB { * @return string */ function escape_str($str) - { + { + // Access the CI object + $CI->get_instance(); + // Escape single quotes - return str_replace("'", "''", $this->CI->input->_remove_invisible_characters($str)); + return str_replace("'", "''", $CI->input->_remove_invisible_characters($str)); } // -------------------------------------------------------------------- diff --git a/system/database/drivers/oci8/oci8_driver.php b/system/database/drivers/oci8/oci8_driver.php index 362da58fb..82bc51bf3 100644 --- a/system/database/drivers/oci8/oci8_driver.php +++ b/system/database/drivers/oci8/oci8_driver.php @@ -367,7 +367,10 @@ class CI_DB_oci8_driver extends CI_DB { */ function escape_str($str) { - return $this->input->CI->_remove_invisible_characters($str); + // Access the CI object + $CI->get_instance(); + + return $CI->_remove_invisible_characters($str); } // -------------------------------------------------------------------- diff --git a/system/database/drivers/odbc/odbc_driver.php b/system/database/drivers/odbc/odbc_driver.php index 7c59c3060..985c975ce 100644 --- a/system/database/drivers/odbc/odbc_driver.php +++ b/system/database/drivers/odbc/odbc_driver.php @@ -242,8 +242,11 @@ class CI_DB_odbc_driver extends CI_DB { */ function escape_str($str) { + // Access the CI object + $CI->get_instance(); + // ODBC doesn't require escaping - return $this->input->CI->_remove_invisible_characters($str); + return $CI->_remove_invisible_characters($str); } // -------------------------------------------------------------------- -- cgit v1.2.3-24-g4f1b From 9f0de7967cc2c5fe8140a3042bb900c43ab8336c Mon Sep 17 00:00:00 2001 From: Rick Ellis Date: Tue, 7 Oct 2008 01:09:40 +0000 Subject: Added a file lock check during cache writing, as per suggestion at bug #3466 --- system/libraries/Output.php | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) (limited to 'system') diff --git a/system/libraries/Output.php b/system/libraries/Output.php index 781e368cb..98a941af5 100644 --- a/system/libraries/Output.php +++ b/system/libraries/Output.php @@ -389,9 +389,16 @@ class CI_Output { $expire = time() + ($this->cache_expiration * 60); - flock($fp, LOCK_EX); - fwrite($fp, $expire.'TS--->'.$output); - flock($fp, LOCK_UN); + 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, DIR_WRITE_MODE); -- cgit v1.2.3-24-g4f1b From 218839a7f4910834e4e991c6650da05b1bd7f743 Mon Sep 17 00:00:00 2001 From: Rick Ellis Date: Tue, 7 Oct 2008 01:15:48 +0000 Subject: Fixed bug (#3472) that was adding quotes incorrectly. --- system/database/drivers/mssql/mssql_driver.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'system') diff --git a/system/database/drivers/mssql/mssql_driver.php b/system/database/drivers/mssql/mssql_driver.php index 1c6249aef..d0e1092e6 100644 --- a/system/database/drivers/mssql/mssql_driver.php +++ b/system/database/drivers/mssql/mssql_driver.php @@ -470,11 +470,11 @@ class CI_DB_mssql_driver extends CI_DB { // This function may get "field >= 1", and need it to return ""field" >= 1" $lbound = ($first_word_only === TRUE) ? '' : '|\s|\('; - $item = preg_replace('/(^'.$lbound.')([\w\d\-\_]+?)(\s|\)|$)/iS', '$1"$2"$3', $item); + $item = preg_replace('/(^'.$lbound.')([\w\d\-\_]+?)(\s|\)|$)/iS', '$1$2$3', $item); } else { - return "\"{$item}\""; + return $item; } $exceptions = array('AS', '/', '-', '%', '+', '*', 'OR', 'IS'); -- cgit v1.2.3-24-g4f1b From ca86a7cf108fe13b89ba22b727a10ab3ac58db19 Mon Sep 17 00:00:00 2001 From: Rick Ellis Date: Tue, 7 Oct 2008 01:16:57 +0000 Subject: --- system/database/drivers/mssql/mssql_driver.php | 2 +- system/database/drivers/oci8/oci8_driver.php | 2 +- system/database/drivers/odbc/odbc_driver.php | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) (limited to 'system') diff --git a/system/database/drivers/mssql/mssql_driver.php b/system/database/drivers/mssql/mssql_driver.php index d0e1092e6..ed6eadbf8 100644 --- a/system/database/drivers/mssql/mssql_driver.php +++ b/system/database/drivers/mssql/mssql_driver.php @@ -214,7 +214,7 @@ class CI_DB_mssql_driver extends CI_DB { function escape_str($str) { // Access the CI object - $CI->get_instance(); + $CI =& get_instance(); // Escape single quotes return str_replace("'", "''", $CI->input->_remove_invisible_characters($str)); diff --git a/system/database/drivers/oci8/oci8_driver.php b/system/database/drivers/oci8/oci8_driver.php index 82bc51bf3..96a6a1352 100644 --- a/system/database/drivers/oci8/oci8_driver.php +++ b/system/database/drivers/oci8/oci8_driver.php @@ -368,7 +368,7 @@ class CI_DB_oci8_driver extends CI_DB { function escape_str($str) { // Access the CI object - $CI->get_instance(); + $CI =& get_instance(); return $CI->_remove_invisible_characters($str); } diff --git a/system/database/drivers/odbc/odbc_driver.php b/system/database/drivers/odbc/odbc_driver.php index 985c975ce..29928807b 100644 --- a/system/database/drivers/odbc/odbc_driver.php +++ b/system/database/drivers/odbc/odbc_driver.php @@ -243,7 +243,7 @@ class CI_DB_odbc_driver extends CI_DB { function escape_str($str) { // Access the CI object - $CI->get_instance(); + $CI =& get_instance(); // ODBC doesn't require escaping return $CI->_remove_invisible_characters($str); -- cgit v1.2.3-24-g4f1b From 5aa8c60392a89140448691b838a90b7d1c644774 Mon Sep 17 00:00:00 2001 From: Rick Ellis Date: Tue, 7 Oct 2008 01:24:07 +0000 Subject: Explicitly added driver name variable in each DB driver, based on this bug report: #4436 --- system/database/drivers/mssql/mssql_driver.php | 3 ++- system/database/drivers/mysql/mysql_driver.php | 2 ++ system/database/drivers/mysqli/mysqli_driver.php | 2 ++ system/database/drivers/oci8/oci8_driver.php | 2 ++ system/database/drivers/odbc/odbc_driver.php | 2 ++ system/database/drivers/postgre/postgre_driver.php | 2 ++ system/database/drivers/sqlite/sqlite_driver.php | 2 ++ 7 files changed, 14 insertions(+), 1 deletion(-) (limited to 'system') diff --git a/system/database/drivers/mssql/mssql_driver.php b/system/database/drivers/mssql/mssql_driver.php index ed6eadbf8..02b975ad2 100644 --- a/system/database/drivers/mssql/mssql_driver.php +++ b/system/database/drivers/mssql/mssql_driver.php @@ -37,7 +37,8 @@ class CI_DB_mssql_driver extends CI_DB { */ var $_count_string = "SELECT COUNT(*) AS "; var $_random_keyword = ' ASC'; // not currently supported - + var $dbdriver = 'mssql'; + /** * Non-persistent database connection * diff --git a/system/database/drivers/mysql/mysql_driver.php b/system/database/drivers/mysql/mysql_driver.php index 52df1e591..db04c6de8 100644 --- a/system/database/drivers/mysql/mysql_driver.php +++ b/system/database/drivers/mysql/mysql_driver.php @@ -30,6 +30,8 @@ */ class CI_DB_mysql_driver extends CI_DB { + var $dbdriver = 'mysql'; + /** * Whether to use the MySQL "delete hack" which allows the number * of affected rows to be shown. Uses a preg_replace when enabled, diff --git a/system/database/drivers/mysqli/mysqli_driver.php b/system/database/drivers/mysqli/mysqli_driver.php index 35a7fc077..a5d104cc2 100644 --- a/system/database/drivers/mysqli/mysqli_driver.php +++ b/system/database/drivers/mysqli/mysqli_driver.php @@ -30,6 +30,8 @@ */ class CI_DB_mysqli_driver extends CI_DB { + var $dbdriver = 'mysqli'; + /** * The syntax to count rows is slightly different across different * database engines, so this string appears in each driver and is diff --git a/system/database/drivers/oci8/oci8_driver.php b/system/database/drivers/oci8/oci8_driver.php index 96a6a1352..006e6ef1f 100644 --- a/system/database/drivers/oci8/oci8_driver.php +++ b/system/database/drivers/oci8/oci8_driver.php @@ -43,6 +43,8 @@ class CI_DB_oci8_driver extends CI_DB { + var $dbdriver = 'oci8'; + /** * The syntax to count rows is slightly different across different * database engines, so this string appears in each driver and is diff --git a/system/database/drivers/odbc/odbc_driver.php b/system/database/drivers/odbc/odbc_driver.php index 29928807b..cc8d3347b 100644 --- a/system/database/drivers/odbc/odbc_driver.php +++ b/system/database/drivers/odbc/odbc_driver.php @@ -30,6 +30,8 @@ */ class CI_DB_odbc_driver extends CI_DB { + var $dbdriver = 'odbc'; + /** * The syntax to count rows is slightly different across different * database engines, so this string appears in each driver and is diff --git a/system/database/drivers/postgre/postgre_driver.php b/system/database/drivers/postgre/postgre_driver.php index aada164d0..c5c70a736 100644 --- a/system/database/drivers/postgre/postgre_driver.php +++ b/system/database/drivers/postgre/postgre_driver.php @@ -30,6 +30,8 @@ */ class CI_DB_postgre_driver extends CI_DB { + var $dbdriver = 'postgre'; + /** * The syntax to count rows is slightly different across different * database engines, so this string appears in each driver and is diff --git a/system/database/drivers/sqlite/sqlite_driver.php b/system/database/drivers/sqlite/sqlite_driver.php index 782156949..df19dba78 100644 --- a/system/database/drivers/sqlite/sqlite_driver.php +++ b/system/database/drivers/sqlite/sqlite_driver.php @@ -32,6 +32,8 @@ */ class CI_DB_sqlite_driver extends CI_DB { + var $dbdriver = 'sqlite'; + /** * The syntax to count rows is slightly different across different * database engines, so this string appears in each driver and is -- cgit v1.2.3-24-g4f1b From 98e2532e5bd31dc8ec7c88e60b463436157ca011 Mon Sep 17 00:00:00 2001 From: Derek Jones Date: Tue, 7 Oct 2008 02:03:16 +0000 Subject: unset $Version, $Path, and $Domain cookie keys, to prevent Disallowed Key Characters from halting app execution on environments which improperly set these as keys --- system/libraries/Input.php | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'system') diff --git a/system/libraries/Input.php b/system/libraries/Input.php index 853b06d7a..f840c433c 100644 --- a/system/libraries/Input.php +++ b/system/libraries/Input.php @@ -140,6 +140,14 @@ class CI_Input { $_POST = $this->_clean_input_data($_POST); // Clean $_COOKIE Data + // 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']) $_COOKIE = $this->_clean_input_data($_COOKIE); log_message('debug', "Global POST and COOKIE data sanitized"); -- cgit v1.2.3-24-g4f1b From bfbe73500060cf1e3b5dd7901e78ca7c1474b84e Mon Sep 17 00:00:00 2001 From: Derek Jones Date: Tue, 7 Oct 2008 02:40:47 +0000 Subject: syntax error --- system/libraries/Input.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system') diff --git a/system/libraries/Input.php b/system/libraries/Input.php index f840c433c..4e312c7aa 100644 --- a/system/libraries/Input.php +++ b/system/libraries/Input.php @@ -147,7 +147,7 @@ class CI_Input { // note that the key names below are single quoted strings, and are not PHP variables unset($_COOKIE['$Version']); unset($_COOKIE['$Path']); - unset($_COOKIE['$Domain']) + unset($_COOKIE['$Domain']); $_COOKIE = $this->_clean_input_data($_COOKIE); log_message('debug', "Global POST and COOKIE data sanitized"); -- cgit v1.2.3-24-g4f1b From a8664295b31968aa29556b93b13bb6a6080be19e Mon Sep 17 00:00:00 2001 From: Derek Jones Date: Wed, 8 Oct 2008 22:38:31 +0000 Subject: moved call to $RES->num_rows() further down in code so that oracle-specific class variables would be set properly as needed before executing --- system/database/DB_driver.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'system') diff --git a/system/database/DB_driver.php b/system/database/DB_driver.php index 257f1ee9b..572595f42 100644 --- a/system/database/DB_driver.php +++ b/system/database/DB_driver.php @@ -375,7 +375,6 @@ class CI_DB_driver { $RES = new $driver(); $RES->conn_id = $this->conn_id; $RES->result_id = $this->result_id; - $RES->num_rows = $RES->num_rows(); if ($this->dbdriver == 'oci8') { @@ -385,6 +384,9 @@ class CI_DB_driver { $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()) -- cgit v1.2.3-24-g4f1b From ccfe9139d574f37163c81d8c7d2c73d6a53d3ab1 Mon Sep 17 00:00:00 2001 From: Derek Jones Date: Thu, 9 Oct 2008 18:46:13 +0000 Subject: fixed spelling of existant to existent --- system/libraries/Loader.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'system') diff --git a/system/libraries/Loader.php b/system/libraries/Loader.php index 37cab318b..b30798f6b 100644 --- a/system/libraries/Loader.php +++ b/system/libraries/Loader.php @@ -891,8 +891,8 @@ class CI_Loader { // Is the class name valid? if ( ! class_exists($name)) { - log_message('error', "Non-existant class: ".$name); - show_error("Non-existant class: ".$class); + log_message('error', "Non-existent class: ".$name); + show_error("Non-existent class: ".$class); } // Set the variable name we will assign the class to -- cgit v1.2.3-24-g4f1b From fd275707f6c1a5a63feb8708731d7c97683df765 Mon Sep 17 00:00:00 2001 From: Derek Jones Date: Fri, 10 Oct 2008 22:37:06 +0000 Subject: modifications to url_title() --- system/helpers/url_helper.php | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) (limited to 'system') diff --git a/system/helpers/url_helper.php b/system/helpers/url_helper.php index acf889007..002090df1 100644 --- a/system/helpers/url_helper.php +++ b/system/helpers/url_helper.php @@ -479,19 +479,20 @@ if ( ! function_exists('url_title')) } $trans = array( - $search => $replace, - "\s+" => $replace, - "[^a-z0-9".$replace."]" => '', - $replace."+" => $replace, - $replace."$" => '', - "^".$replace => '' - ); + '&\#\d+?;' => '', + '&\S+?;' => '', + '\s+' => $replace, + '[^a-z0-9\-\._]' => '', + $replace.'+' => $replace, + $replace.'$' => $replace, + '^'.$replace => $replace + ); - $str = strip_tags(strtolower($str)); + $str = strip_tags($str); foreach ($trans as $key => $val) { - $str = preg_replace("#".$key."#", $val, $str); + $str = preg_replace("#".$key."#i", $val, $str); } return trim(stripslashes($str)); -- cgit v1.2.3-24-g4f1b From 42597a107d799fa86ebc706bf8cbac4f9471d08c Mon Sep 17 00:00:00 2001 From: Derek Allard Date: Wed, 15 Oct 2008 14:10:44 +0000 Subject: Added support for arbitrary attributes in anchor_popup() of the URL helper. --- system/helpers/url_helper.php | 112 ++++++++++++++++++++++-------------------- 1 file changed, 59 insertions(+), 53 deletions(-) (limited to 'system') diff --git a/system/helpers/url_helper.php b/system/helpers/url_helper.php index 002090df1..744295f4c 100644 --- a/system/helpers/url_helper.php +++ b/system/helpers/url_helper.php @@ -36,7 +36,7 @@ * @access public * @param string * @return string - */ + */ if ( ! function_exists('site_url')) { function site_url($uri = '') @@ -55,7 +55,7 @@ if ( ! function_exists('site_url')) * * @access public * @return string - */ + */ if ( ! function_exists('base_url')) { function base_url() @@ -75,7 +75,7 @@ if ( ! function_exists('base_url')) * * @access public * @return string - */ + */ if ( ! function_exists('current_url')) { function current_url() @@ -89,11 +89,11 @@ if ( ! function_exists('current_url')) /** * URL String * - * Returns the URI segments. + * Returns the URI segments. * * @access public * @return string - */ + */ if ( ! function_exists('uri_string')) { function uri_string() @@ -112,7 +112,7 @@ if ( ! function_exists('uri_string')) * * @access public * @return string - */ + */ if ( ! function_exists('index_page')) { function index_page() @@ -121,7 +121,7 @@ if ( ! function_exists('index_page')) return $CI->config->item('index_page'); } } - + // ------------------------------------------------------------------------ /** @@ -134,13 +134,13 @@ if ( ! function_exists('index_page')) * @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; @@ -149,7 +149,7 @@ if ( ! function_exists('anchor')) { $site_url = site_url($uri); } - + if ($title == '') { $title = $site_url; @@ -163,7 +163,7 @@ if ( ! function_exists('anchor')) return ''.$title.''; } } - + // ------------------------------------------------------------------------ /** @@ -181,35 +181,41 @@ if ( ! function_exists('anchor')) 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.""; + return "".$title.""; } } - + // ------------------------------------------------------------------------ /** @@ -226,18 +232,18 @@ if ( ! function_exists('mailto')) function mailto($email, $title = '', $attributes = '') { $title = (string) $title; - + if ($title == "") { $title = $email; } - + $attributes = _parse_attributes($attributes); - + return ''.$title.''; } } - + // ------------------------------------------------------------------------ /** @@ -256,17 +262,17 @@ 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(' -EOF; - } -} -// ------------------------------------------------------------------------ - -/** - * 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 = '', $smileys = NULL) - { - if ( ! is_array($smileys)) - { - if (FALSE === ($smileys = _get_smiley_array())) - { - return $smileys; - } - } - - // Add a trailing slash to the file path if needed - $image_url = preg_replace("/(.+?)\/*$/", "\\1/", $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; - } -} - -// ------------------------------------------------------------------------ - -/** - * Get Smiley Array - * - * Fetches the config/smiley.php file - * - * @access private - * @return mixed - */ -if ( ! function_exists('_get_smiley_array')) -{ - function _get_smiley_array() - { - if ( ! file_exists(APPPATH.'config/smileys'.EXT)) - { - return FALSE; - } - - include(APPPATH.'config/smileys'.EXT); - - if ( ! isset($smileys) OR ! is_array($smileys)) - { - return FALSE; - } - - return $smileys; - } -} - - -/* End of file smiley_helper.php */ + + function insert_smiley(smiley) + { + document.{$form_name}.{$form_field}.value += " " + smiley; + } + +EOF; + } +} +// ------------------------------------------------------------------------ + +/** + * 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 = '', $smileys = NULL) + { + if ( ! is_array($smileys)) + { + if (FALSE === ($smileys = _get_smiley_array())) + { + return $smileys; + } + } + + // Add a trailing slash to the file path if needed + $image_url = preg_replace("/(.+?)\/*$/", "\\1/", $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; + } +} + +// ------------------------------------------------------------------------ + +/** + * Get Smiley Array + * + * Fetches the config/smiley.php file + * + * @access private + * @return mixed + */ +if ( ! function_exists('_get_smiley_array')) +{ + function _get_smiley_array() + { + if ( ! file_exists(APPPATH.'config/smileys'.EXT)) + { + return FALSE; + } + + include(APPPATH.'config/smileys'.EXT); + + if ( ! isset($smileys) OR ! is_array($smileys)) + { + return FALSE; + } + + 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 index 4e376a88c..319002ea7 100644 --- a/system/helpers/string_helper.php +++ b/system/helpers/string_helper.php @@ -1,273 +1,273 @@ - $val) - { - $str[$key] = strip_slashes($val); - } - } - else - { - $str = stripslashes($str); - } - - 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); - } -} - -// ------------------------------------------------------------------------ - -/** - * 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); - } -} - -// ------------------------------------------------------------------------ -/** - * 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 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; - } -} - -// ------------------------------------------------------------------------ - -/** - * Create a Random String - * - * Useful for generating passwords or hashes. - * - * @access public - * @param string type of random string. Options: alunum, numeric, nozero, unique - * @param integer number of characters - * @return string - */ -if ( ! function_exists('random_string')) -{ - function random_string($type = 'alnum', $len = 8) - { - switch($type) - { - case 'alnum' : - case 'numeric' : - case 'nozero' : - - switch ($type) - { - 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' : return md5(uniqid(mt_rand())); - break; - } - } -} - -// ------------------------------------------------------------------------ - -/** - * 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))]; - } -} - -// ------------------------------------------------------------------------ - -/** - * 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) : ''); - } -} - - -/* End of file string_helper.php */ + $val) + { + $str[$key] = strip_slashes($val); + } + } + else + { + $str = stripslashes($str); + } + + 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); + } +} + +// ------------------------------------------------------------------------ + +/** + * 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); + } +} + +// ------------------------------------------------------------------------ +/** + * 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 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; + } +} + +// ------------------------------------------------------------------------ + +/** + * Create a Random String + * + * Useful for generating passwords or hashes. + * + * @access public + * @param string type of random string. Options: alunum, numeric, nozero, unique + * @param integer number of characters + * @return string + */ +if ( ! function_exists('random_string')) +{ + function random_string($type = 'alnum', $len = 8) + { + switch($type) + { + case 'alnum' : + case 'numeric' : + case 'nozero' : + + switch ($type) + { + 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' : return md5(uniqid(mt_rand())); + break; + } + } +} + +// ------------------------------------------------------------------------ + +/** + * 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))]; + } +} + +// ------------------------------------------------------------------------ + +/** + * 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) : ''); + } +} + + +/* 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 index 8a4460825..6e61f776a 100644 --- a/system/helpers/text_helper.php +++ b/system/helpers/text_helper.php @@ -1,443 +1,443 @@ -= $n) - { - return trim($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) - { - $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; - } -} - -// ------------------------------------------------------------------------ - -/** - * 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; - } -} - -// ------------------------------------------------------------------------ - -/** - * 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.' '; - foreach ($censored as $badword) - { - if ($replacement != '') - { - $str = preg_replace("/\b(".str_replace('\*', '\w*?', preg_quote($badword, '/')).")\b/i", $replacement, $str); - } - else - { - $str = preg_replace("/\b(".str_replace('\*', '\w*?', preg_quote($badword, '/')).")\b/ie", "str_repeat('#', strlen('\\1'))", $str); - } - } - - 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 = ''; // tags - // so we'll replace them with tags. - - if (abs(PHP_VERSION) < 5) - { - $str = str_replace(array(''), array(''), $str); - $str = preg_replace('#color="(.*?)"#', 'style="color: \\1"', $str); - } - - // Remove our artificially added PHP, and the syntax highlighting that came with it - $str = preg_replace('/<\?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; - } -} - -// ------------------------------------------------------------------------ - -/** - * 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; - } -} - -// ------------------------------------------------------------------------ - -/** - * 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; - } -} - - -/* End of file text_helper.php */ += $n) + { + return trim($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) + { + $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; + } +} + +// ------------------------------------------------------------------------ + +/** + * 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; + } +} + +// ------------------------------------------------------------------------ + +/** + * 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.' '; + foreach ($censored as $badword) + { + if ($replacement != '') + { + $str = preg_replace("/\b(".str_replace('\*', '\w*?', preg_quote($badword, '/')).")\b/i", $replacement, $str); + } + else + { + $str = preg_replace("/\b(".str_replace('\*', '\w*?', preg_quote($badword, '/')).")\b/ie", "str_repeat('#', strlen('\\1'))", $str); + } + } + + 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 = ''; // tags + // so we'll replace them with tags. + + if (abs(PHP_VERSION) < 5) + { + $str = str_replace(array(''), array(''), $str); + $str = preg_replace('#color="(.*?)"#', 'style="color: \\1"', $str); + } + + // Remove our artificially added PHP, and the syntax highlighting that came with it + $str = preg_replace('/<\?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; + } +} + +// ------------------------------------------------------------------------ + +/** + * 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; + } +} + +// ------------------------------------------------------------------------ + +/** + * 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; + } +} + + +/* 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 index d3cc7f175..46fe6bf36 100644 --- a/system/helpers/typography_helper.php +++ b/system/helpers/typography_helper.php @@ -1,71 +1,71 @@ -load->library('typography'); - - return $CI->typography->nl2br_except_pre($str); - } -} - -// ------------------------------------------------------------------------ - -/** - * Auto Typography Wrapper Function - * - * - * @access public - * @param string - * @param bool whether to reduce multiple instances of double newlines to two - * @return string - */ -if ( ! function_exists('auto_typography')) -{ - function auto_typography($str, $reduce_linebreaks = FALSE) - { - $CI =& get_instance(); - $CI->load->library('typography'); - return $CI->typography->auto_typography($str, $reduce_linebreaks); - } -} - -/* End of file typography_helper.php */ +load->library('typography'); + + return $CI->typography->nl2br_except_pre($str); + } +} + +// ------------------------------------------------------------------------ + +/** + * Auto Typography Wrapper Function + * + * + * @access public + * @param string + * @param bool whether to reduce multiple instances of double newlines to two + * @return string + */ +if ( ! function_exists('auto_typography')) +{ + function auto_typography($str, $reduce_linebreaks = FALSE) + { + $CI =& get_instance(); + $CI->load->library('typography'); + return $CI->typography->auto_typography($str, $reduce_linebreaks); + } +} + +/* 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 index 744295f4c..fd13dc2d4 100644 --- a/system/helpers/url_helper.php +++ b/system/helpers/url_helper.php @@ -1,582 +1,582 @@ -config->site_url($uri); - } -} - -// ------------------------------------------------------------------------ - -/** - * Base URL - * - * Returns the "base_url" item from your config file - * - * @access public - * @return string - */ -if ( ! function_exists('base_url')) -{ - function base_url() - { - $CI =& get_instance(); - return $CI->config->slash_item('base_url'); - } -} - -// ------------------------------------------------------------------------ - -/** - * 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()); - } -} - -// ------------------------------------------------------------------------ -/** - * 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(); - } -} - -// ------------------------------------------------------------------------ - -/** - * 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'); - } -} - -// ------------------------------------------------------------------------ - -/** - * 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 - 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.""; - } -} - -// ------------------------------------------------------------------------ - -/** - * 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.''; - } -} - -// ------------------------------------------------------------------------ - -/** - * 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(); - - ?>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 < sizeof($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; - } -} - -// ------------------------------------------------------------------------ - -/** - * Prep URL - * - * Simply adds the http:// part if missing - * - * @access public - * @param string the URL - * @return string - */ -if ( ! function_exists('prep_url')) -{ - function prep_url($str = '') - { - if ($str == 'http://' OR $str == '') - { - return ''; - } - - if (substr($str, 0, 7) != 'http://' && substr($str, 0, 8) != 'https://') - { - $str = 'http://'.$str; - } - - return $str; - } -} - -// ------------------------------------------------------------------------ - -/** - * Create URL Title - * - * Takes a "title" string as input and creates a - * human-friendly URL string with either a dash - * or an underscore as the word separator. - * - * @access public - * @param string the string - * @param string the separator: dash, or underscore - * @return string - */ -if ( ! function_exists('url_title')) -{ - function url_title($str, $separator = 'dash') - { - if ($separator == 'dash') - { - $search = '_'; - $replace = '-'; - } - else - { - $search = '-'; - $replace = '_'; - } - - $trans = array( - '&\#\d+?;' => '', - '&\S+?;' => '', - '\s+' => $replace, - '[^a-z0-9\-\._]' => '', - $replace.'+' => $replace, - $replace.'$' => $replace, - '^'.$replace => $replace - ); - - $str = strip_tags($str); - - foreach ($trans as $key => $val) - { - $str = preg_replace("#".$key."#i", $val, $str); - } - - return trim(stripslashes($str)); - } -} - -// ------------------------------------------------------------------------ - -/** - * 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) - { - switch($method) - { - case 'refresh' : header("Refresh:0;url=".site_url($uri)); - break; - default : header("Location: ".site_url($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; - } -} - - -/* End of file url_helper.php */ +config->site_url($uri); + } +} + +// ------------------------------------------------------------------------ + +/** + * Base URL + * + * Returns the "base_url" item from your config file + * + * @access public + * @return string + */ +if ( ! function_exists('base_url')) +{ + function base_url() + { + $CI =& get_instance(); + return $CI->config->slash_item('base_url'); + } +} + +// ------------------------------------------------------------------------ + +/** + * 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()); + } +} + +// ------------------------------------------------------------------------ +/** + * 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(); + } +} + +// ------------------------------------------------------------------------ + +/** + * 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'); + } +} + +// ------------------------------------------------------------------------ + +/** + * 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 - 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.""; + } +} + +// ------------------------------------------------------------------------ + +/** + * 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.''; + } +} + +// ------------------------------------------------------------------------ + +/** + * 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(); + + ?>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 < sizeof($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; + } +} + +// ------------------------------------------------------------------------ + +/** + * Prep URL + * + * Simply adds the http:// part if missing + * + * @access public + * @param string the URL + * @return string + */ +if ( ! function_exists('prep_url')) +{ + function prep_url($str = '') + { + if ($str == 'http://' OR $str == '') + { + return ''; + } + + if (substr($str, 0, 7) != 'http://' && substr($str, 0, 8) != 'https://') + { + $str = 'http://'.$str; + } + + return $str; + } +} + +// ------------------------------------------------------------------------ + +/** + * Create URL Title + * + * Takes a "title" string as input and creates a + * human-friendly URL string with either a dash + * or an underscore as the word separator. + * + * @access public + * @param string the string + * @param string the separator: dash, or underscore + * @return string + */ +if ( ! function_exists('url_title')) +{ + function url_title($str, $separator = 'dash') + { + if ($separator == 'dash') + { + $search = '_'; + $replace = '-'; + } + else + { + $search = '-'; + $replace = '_'; + } + + $trans = array( + '&\#\d+?;' => '', + '&\S+?;' => '', + '\s+' => $replace, + '[^a-z0-9\-\._]' => '', + $replace.'+' => $replace, + $replace.'$' => $replace, + '^'.$replace => $replace + ); + + $str = strip_tags($str); + + foreach ($trans as $key => $val) + { + $str = preg_replace("#".$key."#i", $val, $str); + } + + return trim(stripslashes($str)); + } +} + +// ------------------------------------------------------------------------ + +/** + * 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) + { + switch($method) + { + case 'refresh' : header("Refresh:0;url=".site_url($uri)); + break; + default : header("Location: ".site_url($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; + } +} + + +/* End of file url_helper.php */ /* Location: ./system/helpers/url_helper.php */ \ No newline at end of file diff --git a/system/helpers/xml_helper.php b/system/helpers/xml_helper.php index 83e2bb3a0..90cce3dda 100644 --- a/system/helpers/xml_helper.php +++ b/system/helpers/xml_helper.php @@ -1,62 +1,62 @@ -","\"", "'", "-"), - array("&", "<", ">", """, "'", "-"), - $str); - - // Decode the temp markers back to entities - $str = preg_replace("/$temp(\d+);/","&#\\1;",$str); - $str = preg_replace("/$temp(\w+);/","&\\1;", $str); - - return $str; - } -} - - -/* End of file xml_helper.php */ +","\"", "'", "-"), + array("&", "<", ">", """, "'", "-"), + $str); + + // Decode the temp markers back to entities + $str = preg_replace("/$temp(\d+);/","&#\\1;",$str); + $str = preg_replace("/$temp(\w+);/","&\\1;", $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/language/english/calendar_lang.php b/system/language/english/calendar_lang.php index 107c0f733..e26f84930 100644 --- a/system/language/english/calendar_lang.php +++ b/system/language/english/calendar_lang.php @@ -1,51 +1,51 @@ - - - 403 Forbidden - - - -

    Directory access is forbidden.

    - - + + + 403 Forbidden + + + +

    Directory access is forbidden.

    + + \ No newline at end of file diff --git a/system/language/english/number_lang.php b/system/language/english/number_lang.php index f9b91661d..908580914 100644 --- a/system/language/english/number_lang.php +++ b/system/language/english/number_lang.php @@ -1,10 +1,10 @@ - - - 403 Forbidden - - - -

    Directory access is forbidden.

    - - + + + 403 Forbidden + + + +

    Directory access is forbidden.

    + + \ No newline at end of file diff --git a/system/libraries/Benchmark.php b/system/libraries/Benchmark.php index 4984bb158..fec507154 100644 --- a/system/libraries/Benchmark.php +++ b/system/libraries/Benchmark.php @@ -1,113 +1,113 @@ -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}'; - } - -} - -// END CI_Benchmark class - -/* End of file Benchmark.php */ +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}'; + } + +} + +// END CI_Benchmark class + +/* End of file Benchmark.php */ /* Location: ./system/libraries/Benchmark.php */ \ No newline at end of file diff --git a/system/libraries/Calendar.php b/system/libraries/Calendar.php index dcf8a12a8..ca4b9d5a6 100644 --- a/system/libraries/Calendar.php +++ b/system/libraries/Calendar.php @@ -1,477 +1,477 @@ -CI =& get_instance(); - - if ( ! in_array('calendar_lang'.EXT, $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_may', '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)]; - } - } - } - } - -} - -// END CI_Calendar class - -/* End of file Calendar.php */ +CI =& get_instance(); + + if ( ! in_array('calendar_lang'.EXT, $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_may', '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)]; + } + } + } + } + +} + +// 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/Config.php b/system/libraries/Config.php index a9cf9f4e4..027f6bf8e 100644 --- a/system/libraries/Config.php +++ b/system/libraries/Config.php @@ -1,244 +1,244 @@ -config =& get_config(); - log_message('debug', "Config Class Initialized"); - } - - // -------------------------------------------------------------------- - - /** - * Load Config File - * - * @access public - * @param string the config file name - * @return boolean if the file was loaded correctly - */ - function load($file = '', $use_sections = FALSE, $fail_gracefully = FALSE) - { - $file = ($file == '') ? 'config' : str_replace(EXT, '', $file); - - if (in_array($file, $this->is_loaded, TRUE)) - { - return TRUE; - } - - if ( ! file_exists(APPPATH.'config/'.$file.EXT)) - { - if ($fail_gracefully === TRUE) - { - return FALSE; - } - show_error('The configuration file '.$file.EXT.' does not exist.'); - } - - include(APPPATH.'config/'.$file.EXT); - - if ( ! isset($config) OR ! is_array($config)) - { - if ($fail_gracefully === TRUE) - { - return FALSE; - } - show_error('Your '.$file.EXT.' 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; - unset($config); - - log_message('debug', 'Config file loaded: config/'.$file.EXT); - 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 - * - * The second parameter allows a slash to be added to the end of - * the item, in the case of a path. - * - * @access public - * @param string the config item name - * @param bool - * @return string - */ - function slash_item($item) - { - if ( ! isset($this->config[$item])) - { - return FALSE; - } - - $pref = $this->config[$item]; - - if ($pref != '' && substr($pref, -1) != '/') - { - $pref .= '/'; - } - - return $pref; - } - - // -------------------------------------------------------------------- - - /** - * Site URL - * - * @access public - * @param string the URI string - * @return string - */ - function site_url($uri = '') - { - if (is_array($uri)) - { - $uri = implode('/', $uri); - } - - if ($uri == '') - { - return $this->slash_item('base_url').$this->item('index_page'); - } - else - { - $suffix = ($this->item('url_suffix') == FALSE) ? '' : $this->item('url_suffix'); - return $this->slash_item('base_url').$this->slash_item('index_page').preg_replace("|^/*(.+?)/*$|", "\\1", $uri).$suffix; - } - } - - // -------------------------------------------------------------------- - - /** - * 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; - } - -} - -// END CI_Config class - -/* End of file Config.php */ +config =& get_config(); + log_message('debug', "Config Class Initialized"); + } + + // -------------------------------------------------------------------- + + /** + * Load Config File + * + * @access public + * @param string the config file name + * @return boolean if the file was loaded correctly + */ + function load($file = '', $use_sections = FALSE, $fail_gracefully = FALSE) + { + $file = ($file == '') ? 'config' : str_replace(EXT, '', $file); + + if (in_array($file, $this->is_loaded, TRUE)) + { + return TRUE; + } + + if ( ! file_exists(APPPATH.'config/'.$file.EXT)) + { + if ($fail_gracefully === TRUE) + { + return FALSE; + } + show_error('The configuration file '.$file.EXT.' does not exist.'); + } + + include(APPPATH.'config/'.$file.EXT); + + if ( ! isset($config) OR ! is_array($config)) + { + if ($fail_gracefully === TRUE) + { + return FALSE; + } + show_error('Your '.$file.EXT.' 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; + unset($config); + + log_message('debug', 'Config file loaded: config/'.$file.EXT); + 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 + * + * The second parameter allows a slash to be added to the end of + * the item, in the case of a path. + * + * @access public + * @param string the config item name + * @param bool + * @return string + */ + function slash_item($item) + { + if ( ! isset($this->config[$item])) + { + return FALSE; + } + + $pref = $this->config[$item]; + + if ($pref != '' && substr($pref, -1) != '/') + { + $pref .= '/'; + } + + return $pref; + } + + // -------------------------------------------------------------------- + + /** + * Site URL + * + * @access public + * @param string the URI string + * @return string + */ + function site_url($uri = '') + { + if (is_array($uri)) + { + $uri = implode('/', $uri); + } + + if ($uri == '') + { + return $this->slash_item('base_url').$this->item('index_page'); + } + else + { + $suffix = ($this->item('url_suffix') == FALSE) ? '' : $this->item('url_suffix'); + return $this->slash_item('base_url').$this->slash_item('index_page').preg_replace("|^/*(.+?)/*$|", "\\1", $uri).$suffix; + } + } + + // -------------------------------------------------------------------- + + /** + * 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; + } + +} + +// END CI_Config class + +/* End of file Config.php */ /* Location: ./system/libraries/Config.php */ \ No newline at end of file diff --git a/system/libraries/Controller.php b/system/libraries/Controller.php index b6e10a3aa..5d9b80d9c 100644 --- a/system/libraries/Controller.php +++ b/system/libraries/Controller.php @@ -1,127 +1,127 @@ -_ci_initialize(); - log_message('debug', "Controller Class Initialized"); - } - - // -------------------------------------------------------------------- - - /** - * Initialize - * - * Assigns all the bases classes loaded by the front controller to - * variables in this class. Also calls the autoload routine. - * - * @access private - * @return void - */ - function _ci_initialize() - { - // Assign all the class objects that were instantiated by the - // front controller to local class variables so that CI can be - // run as one big super object. - $classes = array( - 'config' => 'Config', - 'input' => 'Input', - 'benchmark' => 'Benchmark', - 'uri' => 'URI', - 'output' => 'Output', - 'lang' => 'Language', - 'router' => 'Router' - ); - - foreach ($classes as $var => $class) - { - $this->$var =& load_class($class); - } - - // In PHP 5 the Loader class is run as a discreet - // class. In PHP 4 it extends the Controller - if (floor(phpversion()) >= 5) - { - $this->load =& load_class('Loader'); - $this->load->_ci_autoloader(); - } - else - { - $this->_ci_autoloader(); - - // sync up the objects since PHP4 was working from a copy - foreach (array_keys(get_object_vars($this)) as $attribute) - { - if (is_object($this->$attribute)) - { - $this->load->$attribute =& $this->$attribute; - } - } - } - } - - // -------------------------------------------------------------------- - - /** - * Run Scaffolding - * - * @access private - * @return void - */ - function _ci_scaffolding() - { - if ($this->_ci_scaffolding === FALSE OR $this->_ci_scaff_table === FALSE) - { - show_404('Scaffolding unavailable'); - } - - $method = ( ! in_array($this->uri->segment(3), array('add', 'insert', 'edit', 'update', 'view', 'delete', 'do_delete'), TRUE)) ? 'view' : $this->uri->segment(3); - - require_once(BASEPATH.'scaffolding/Scaffolding'.EXT); - $scaff = new Scaffolding($this->_ci_scaff_table); - $scaff->$method(); - } - - -} -// END _Controller class - -/* End of file Controller.php */ +_ci_initialize(); + log_message('debug', "Controller Class Initialized"); + } + + // -------------------------------------------------------------------- + + /** + * Initialize + * + * Assigns all the bases classes loaded by the front controller to + * variables in this class. Also calls the autoload routine. + * + * @access private + * @return void + */ + function _ci_initialize() + { + // Assign all the class objects that were instantiated by the + // front controller to local class variables so that CI can be + // run as one big super object. + $classes = array( + 'config' => 'Config', + 'input' => 'Input', + 'benchmark' => 'Benchmark', + 'uri' => 'URI', + 'output' => 'Output', + 'lang' => 'Language', + 'router' => 'Router' + ); + + foreach ($classes as $var => $class) + { + $this->$var =& load_class($class); + } + + // In PHP 5 the Loader class is run as a discreet + // class. In PHP 4 it extends the Controller + if (floor(phpversion()) >= 5) + { + $this->load =& load_class('Loader'); + $this->load->_ci_autoloader(); + } + else + { + $this->_ci_autoloader(); + + // sync up the objects since PHP4 was working from a copy + foreach (array_keys(get_object_vars($this)) as $attribute) + { + if (is_object($this->$attribute)) + { + $this->load->$attribute =& $this->$attribute; + } + } + } + } + + // -------------------------------------------------------------------- + + /** + * Run Scaffolding + * + * @access private + * @return void + */ + function _ci_scaffolding() + { + if ($this->_ci_scaffolding === FALSE OR $this->_ci_scaff_table === FALSE) + { + show_404('Scaffolding unavailable'); + } + + $method = ( ! in_array($this->uri->segment(3), array('add', 'insert', 'edit', 'update', 'view', 'delete', 'do_delete'), TRUE)) ? 'view' : $this->uri->segment(3); + + require_once(BASEPATH.'scaffolding/Scaffolding'.EXT); + $scaff = new Scaffolding($this->_ci_scaff_table); + $scaff->$method(); + } + + +} +// END _Controller class + +/* End of file Controller.php */ /* Location: ./system/libraries/Controller.php */ \ No newline at end of file diff --git a/system/libraries/Email.php b/system/libraries/Email.php index a0ede7248..94f517c45 100644 --- a/system/libraries/Email.php +++ b/system/libraries/Email.php @@ -1,2028 +1,2028 @@ - 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 - */ - function initialize($config = array()) - { - $this->clear(); - 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->_smtp_auth = ($this->smtp_user == '' AND $this->smtp_pass == '') ? FALSE : TRUE; - $this->_safe_mode = ((boolean)@ini_get("safe_mode") === FALSE) ? FALSE : TRUE; - } - - // -------------------------------------------------------------------- - - /** - * Initialize the Email Data - * - * @access public - * @return void - */ - function clear($clear_attachments = FALSE) - { - $this->_subject = ""; - $this->_body = ""; - $this->_finalbody = ""; - $this->_header_str = ""; - $this->_replyto_flag = FALSE; - $this->_recipients = 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(); - } - } - - // -------------------------------------------------------------------- - - /** - * Set FROM - * - * @access public - * @param string - * @param string - * @return void - */ - 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.'>'); - } - - // -------------------------------------------------------------------- - - /** - * Set Reply-to - * - * @access public - * @param string - * @param string - * @return void - */ - 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; - } - - // -------------------------------------------------------------------- - - /** - * Set Recipients - * - * @access public - * @param string - * @return void - */ - 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' : $this->_recipients = implode(", ", $to); - break; - case 'mail' : $this->_recipients = implode(", ", $to); - break; - } - } - - // -------------------------------------------------------------------- - - /** - * Set CC - * - * @access public - * @param string - * @return void - */ - 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; - } - } - - // -------------------------------------------------------------------- - - /** - * Set BCC - * - * @access public - * @param string - * @param string - * @return void - */ - 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)); - } - } - - // -------------------------------------------------------------------- - - /** - * Set Email Subject - * - * @access public - * @param string - * @return void - */ - function subject($subject) - { - $subject = $this->_prep_q_encoding($subject); - $this->_set_header('Subject', $subject); - } - - // -------------------------------------------------------------------- - - /** - * Set Body - * - * @access public - * @param string - * @return void - */ - function message($body) - { - $this->_body = stripslashes(rtrim(str_replace("\r", "", $body))); - } - - // -------------------------------------------------------------------- - - /** - * Assign file attachments - * - * @access public - * @param string - * @return void - */ - function attach($filename, $disposition = 'attachment') - { - $this->_attach_name[] = $filename; - $this->_attach_type[] = $this->_mime_types(next(explode('.', basename($filename)))); - $this->_attach_disp[] = $disposition; // Can also be 'inline' Not sure if it matters - } - - // -------------------------------------------------------------------- - - /** - * Add a Header Item - * - * @access private - * @param string - * @param string - * @return void - */ - function _set_header($header, $value) - { - $this->_headers[$header] = $value; - } - - // -------------------------------------------------------------------- - - /** - * Convert a String to an Array - * - * @access private - * @param string - * @return array - */ - 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 - */ - function set_alt_message($str = '') - { - $this->alt_message = ($str == '') ? '' : $str; - } - - // -------------------------------------------------------------------- - - /** - * Set Mailtype - * - * @access public - * @param string - * @return void - */ - function set_mailtype($type = 'text') - { - $this->mailtype = ($type == 'html') ? 'html' : 'text'; - } - - // -------------------------------------------------------------------- - - /** - * Set Wordwrap - * - * @access public - * @param string - * @return void - */ - function set_wordwrap($wordwrap = TRUE) - { - $this->wordwrap = ($wordwrap === FALSE) ? FALSE : TRUE; - } - - // -------------------------------------------------------------------- - - /** - * Set Protocol - * - * @access public - * @param string - * @return void - */ - function set_protocol($protocol = 'mail') - { - $this->protocol = ( ! in_array($protocol, $this->_protocols, TRUE)) ? 'mail' : strtolower($protocol); - } - - // -------------------------------------------------------------------- - - /** - * Set Priority - * - * @access public - * @param integer - * @return void - */ - 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; - } - - // -------------------------------------------------------------------- - - /** - * Set Newline Character - * - * @access public - * @param string - * @return void - */ - function set_newline($newline = "\n") - { - if ($newline != "\n" AND $newline != "\r\n" AND $newline != "\r") - { - $this->newline = "\n"; - return; - } - - $this->newline = $newline; - } - - // -------------------------------------------------------------------- - - /** - * Set CRLF - * - * @access public - * @param string - * @return void - */ - function set_crlf($crlf = "\n") - { - if ($crlf != "\n" AND $crlf != "\r\n" AND $crlf != "\r") - { - $this->crlf = "\n"; - return; - } - - $this->crlf = $crlf; - } - - // -------------------------------------------------------------------- - - /** - * Set Message Boundary - * - * @access private - * @return void - */ - function _set_boundaries() - { - $this->_alt_boundary = "B_ALT_".uniqid(''); // multipart/alternative - $this->_atc_boundary = "B_ATC_".uniqid(''); // attachment boundary - } - - // -------------------------------------------------------------------- - - /** - * Get the Message ID - * - * @access private - * @return string - */ - 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 private - * @param bool - * @return string - */ - 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 private - * @param bool - * @return string - */ - 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 private - * @return string - */ - 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 private - * @return string - */ - 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 private - * @return string - */ - 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 - */ - function validate_email($email) - { - if ( ! is_array($email)) - { - $this->_set_error_message('email_must_be_array'); - return FALSE; - } - - foreach ($email as $val) - { - if ( ! $this->valid_email($val)) - { - $this->_set_error_message('email_invalid_address', $val); - return FALSE; - } - } - - return TRUE; - } - - // -------------------------------------------------------------------- - - /** - * Email Validation - * - * @access public - * @param string - * @return bool - */ - 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 - */ - 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 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 private - * @return string - */ - 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( '# '.$message. ' '.$filepath.' '.$line, TRUE); - } - - // -------------------------------------------------------------------- - - /** - * 404 Page Not Found Handler - * - * @access private - * @param string - * @return string - */ - function show_404($page = '') - { - $heading = "404 Page Not Found"; - $message = "The page you requested was not found."; - - log_message('error', '404 Page Not Found --> '.$page); - echo $this->show_error($heading, $message, 'error_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 - * @return string - */ - function show_error($heading, $message, $template = 'error_general') - { - $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.EXT); - $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'.EXT); - $buffer = ob_get_contents(); - ob_end_clean(); - echo $buffer; - } - - -} -// END Exceptions Class - -/* End of file Exceptions.php */ + '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 + * + */ + function CI_Exceptions() + { + $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 + * @return string + */ + function show_404($page = '') + { + $heading = "404 Page Not Found"; + $message = "The page you requested was not found."; + + log_message('error', '404 Page Not Found --> '.$page); + echo $this->show_error($heading, $message, 'error_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 + * @return string + */ + function show_error($heading, $message, $template = 'error_general') + { + $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.EXT); + $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'.EXT); + $buffer = ob_get_contents(); + ob_end_clean(); + echo $buffer; + } + + +} +// END Exceptions Class + +/* End of file Exceptions.php */ /* Location: ./system/libraries/Exceptions.php */ \ No newline at end of file diff --git a/system/libraries/Form_validation.php b/system/libraries/Form_validation.php index 0c7687aa1..7be93a192 100644 --- a/system/libraries/Form_validation.php +++ b/system/libraries/Form_validation.php @@ -1,1287 +1,1287 @@ -'; - var $_error_suffix = '

    '; - var $error_string = ''; - var $_safe_form_data = FALSE; - - - /** - * Constructor - * - */ - function CI_Form_validation($rules = array()) - { - $this->CI =& get_instance(); - - // Validation rules can be stored in a config file. - $this->_config_rules = $rules; - - // Automatically load the form helper - $this->CI->load->helper('form'); - - // Set the character encoding in MB. - if (function_exists('mb_internal_encoding')) - { - mb_internal_encoding($this->CI->config->item('charset')); - } - - log_message('debug', "Form Validation Class Initialized"); - } - - // -------------------------------------------------------------------- - - /** - * Set Rules - * - * This function takes an array of field names and validation - * rules as input, validates the info, and stores it - * - * @access public - * @param mixed - * @param string - * @return void - */ - function set_rules($field, $label = '', $rules = '') - { - // No reason to set rules if we have no POST data - if (count($_POST) == 0) - { - return; - } - - // If an array was passed via the first parameter instead of indidual string - // values we cycle through it and recursively call this function. - if (is_array($field)) - { - foreach ($field as $row) - { - // Houston, we have a problem... - if ( ! isset($row['field']) OR ! isset($row['rules'])) - { - continue; - } - - // If the field label wasn't passed we use the field name - $label = ( ! isset($row['label'])) ? $row['field'] : $row['label']; - - // Here we go! - $this->set_rules($row['field'], $label, $row['rules']); - } - return; - } - - // No fields? Nothing to do... - if ( ! is_string($field) OR ! is_string($rules) OR $field == '') - { - return; - } - - // If the field label wasn't passed we use the field name - $label = ($label == '') ? $field : $label; - - // Is the field name an array? We test for the existence of a bracket "[" in - // the field name to determine this. If it is an array, we break it apart - // into its components so that we can fetch the corresponding POST data later - if (strpos($field, '[') !== FALSE AND preg_match_all('/\[(.*?)\]/', $field, $matches)) - { - // Note: Due to a bug in current() that affects some versions - // of PHP we can not pass function call directly into it - $x = explode('[', $field); - $indexes[] = current($x); - - for ($i = 0; $i < count($matches['0']); $i++) - { - if ($matches['1'][$i] != '') - { - $indexes[] = $matches['1'][$i]; - } - } - - $is_array = TRUE; - } - else - { - $indexes = array(); - $is_array = FALSE; - } - - // Build our master array - $this->_field_data[$field] = array( - 'field' => $field, - 'label' => $label, - 'rules' => $rules, - 'is_array' => $is_array, - 'keys' => $indexes, - 'postdata' => NULL, - 'error' => '' - ); - } - - // -------------------------------------------------------------------- - - /** - * Set Error Message - * - * Lets users set their own error messages on the fly. Note: The key - * name has to match the function name that it corresponds to. - * - * @access public - * @param string - * @param string - * @return string - */ - function set_message($lang, $val = '') - { - if ( ! is_array($lang)) - { - $lang = array($lang => $val); - } - - $this->_error_messages = array_merge($this->_error_messages, $lang); - } - - // -------------------------------------------------------------------- - - /** - * Set The Error Delimiter - * - * Permits a prefix/suffix to be added to each error message - * - * @access public - * @param string - * @param string - * @return void - */ - function set_error_delimiters($prefix = '

    ', $suffix = '

    ') - { - $this->_error_prefix = $prefix; - $this->_error_suffix = $suffix; - } - - // -------------------------------------------------------------------- - - /** - * Get Error Message - * - * Gets the error message associated with a particular field - * - * @access public - * @param string the field name - * @return void - */ - function error($field = '', $prefix = '', $suffix = '') - { - if ( ! isset($this->_field_data[$field]['error']) OR $this->_field_data[$field]['error'] == '') - { - return ''; - } - - if ($prefix == '') - { - $prefix = $this->_error_prefix; - } - - if ($suffix == '') - { - $suffix = $this->_error_suffix; - } - - return $prefix.$this->_field_data[$field]['error'].$suffix; - } - - // -------------------------------------------------------------------- - - /** - * Error String - * - * Returns the error messages as a string, wrapped in the error delimiters - * - * @access public - * @param string - * @param string - * @return str - */ - function error_string($prefix = '', $suffix = '') - { - // No errrors, validation passes! - if (count($this->_error_array) === 0) - { - return ''; - } - - if ($prefix == '') - { - $prefix = $this->_error_prefix; - } - - if ($suffix == '') - { - $suffix = $this->_error_suffix; - } - - // Generate the error string - $str = ''; - foreach ($this->_error_array as $val) - { - if ($val != '') - { - $str .= $prefix.$val.$suffix."\n"; - } - } - - return $str; - } - - // -------------------------------------------------------------------- - - /** - * Run the Validator - * - * This function does all the work. - * - * @access public - * @return bool - */ - function run($group = '') - { - // Do we even have any data to process? Mm? - if (count($_POST) == 0) - { - return FALSE; - } - - // Does the _field_data array containing the validation rules exist? - // If not, we look to see if they were assigned via a config file - if (count($this->_field_data) == 0) - { - // No validation rules? We're done... - if (count($this->_config_rules) == 0) - { - return FALSE; - } - - // Is there a validation rule for the particular URI being accessed? - $uri = ($group == '') ? trim($this->CI->uri->ruri_string(), '/') : $group; - - if ($uri != '' AND isset($this->_config_rules[$uri])) - { - $this->set_rules($this->_config_rules[$uri]); - } - else - { - $this->set_rules($this->_config_rules); - } - - // We're we able to set the rules correctly? - if (count($this->_field_data) == 0) - { - log_message('debug', "Unable to find validation rules"); - return FALSE; - } - } - - // Load the language file containing error messages - $this->CI->lang->load('form_validation'); - - // Cycle through the rules for each field, match the - // corresponding $_POST item and test for errors - foreach ($this->_field_data as $field => $row) - { - // Fetch the data from the corresponding $_POST array and cache it in the _field_data array. - // Depending on whether the field name is an array or a string will determine where we get it from. - - if ($row['is_array'] == TRUE) - { - $this->_field_data[$field]['postdata'] = $this->_reduce_array($_POST, $row['keys']); - } - else - { - if (isset($_POST[$field]) AND $_POST[$field] != "") - { - $this->_field_data[$field]['postdata'] = $_POST[$field]; - } - } - - $this->_execute($row, explode('|', $row['rules']), $this->_field_data[$field]['postdata']); - } - - // Did we end up with any errors? - $total_errors = count($this->_error_array); - - if ($total_errors > 0) - { - $this->_safe_form_data = TRUE; - } - - // Now we need to re-set the POST data with the new, processed data - $this->_reset_post_array(); - - // No errors, validation passes! - if ($total_errors == 0) - { - return TRUE; - } - - // Validation fails - return FALSE; - } - - // -------------------------------------------------------------------- - - /** - * Traverse a multidimensional $_POST array index until the data is found - * - * @access private - * @param array - * @param array - * @param integer - * @return mixed - */ - function _reduce_array($array, $keys, $i = 0) - { - if (is_array($array)) - { - if (isset($keys[$i])) - { - if (isset($array[$keys[$i]])) - { - $array = $this->_reduce_array($array[$keys[$i]], $keys, ($i+1)); - } - else - { - return NULL; - } - } - else - { - return $array; - } - } - - return $array; - } - - // -------------------------------------------------------------------- - - /** - * Re-populate the _POST array with our finalized and processed data - * - * @access private - * @return null - */ - function _reset_post_array() - { - foreach ($this->_field_data as $field => $row) - { - if ( ! is_null($row['postdata'])) - { - if ($row['is_array'] == FALSE) - { - if (isset($_POST[$row['field']])) - { - $_POST[$row['field']] = $this->prep_for_form($row['postdata']); - } - } - else - { - $post = '$_POST["'; - - if (count($row['keys']) == 1) - { - $post .= current($row['keys']); - $post .= '"]'; - } - else - { - $i = 0; - foreach ($row['keys'] as $val) - { - if ($i == 0) - { - $post .= $val.'"]'; - $i++; - continue; - } - - $post .= '["'.$val.'"]'; - } - } - - if (is_array($row['postdata'])) - { - $array = array(); - foreach ($row['postdata'] as $k => $v) - { - $array[$k] = $this->prep_for_form($v); - } - - $post .= ' = $array;'; - } - else - { - $post .= ' = "'.$this->prep_for_form($row['postdata']).'";'; - } - - eval($post); - } - } - } - } - - // -------------------------------------------------------------------- - - /** - * Executes the Validation routines - * - * @access private - * @param array - * @param array - * @param mixed - * @param integer - * @return mixed - */ - function _execute($row, $rules, $postdata = NULL, $cycles = 0) - { - // If the $_POST data is an array we will run a recursive call - if (is_array($postdata)) - { - foreach ($postdata as $key => $val) - { - $this->_execute($row, $rules, $val, $cycles); - $cycles++; - } - - return; - } - - // -------------------------------------------------------------------- - - // If the field is blank, but NOT required, no further tests are necessary - $callback = FALSE; - if ( ! in_array('required', $rules) AND is_null($postdata)) - { - // Before we bail out, does the rule contain a callback? - if (preg_match("/(callback_\w+)/", implode(' ', $rules), $match)) - { - $callback = TRUE; - $rules = (array('1' => $match[1])); - } - else - { - return; - } - } - - // -------------------------------------------------------------------- - - // Isset Test. Typically this rule will only apply to checkboxes. - if (is_null($postdata) AND $callback == FALSE) - { - if (in_array('isset', $rules, TRUE) OR in_array('required', $rules)) - { - // Set the message type - $type = (in_array('required', $rules)) ? 'required' : 'isset'; - - if ( ! isset($this->_error_messages[$type])) - { - if (FALSE === ($line = $this->CI->lang->line($type))) - { - $line = 'The field was not set'; - } - } - else - { - $line = $this->_error_messages[$type]; - } - - // Build the error message - $message = sprintf($line, $this->_translate_fieldname($row['label'])); - - // Save the error message - $this->_field_data[$row['field']]['error'] = $message; - - if ( ! isset($this->_error_array[$row['field']])) - { - $this->_error_array[$row['field']] = $message; - } - } - - return; - } - - // -------------------------------------------------------------------- - - // Cycle through each rule and run it - foreach ($rules As $rule) - { - $_in_array = FALSE; - - // We set the $postdata variable with the current data in our master array so that - // each cycle of the loop is dealing with the processed data from the last cycle - if ($row['is_array'] == TRUE AND is_array($this->_field_data[$row['field']]['postdata'])) - { - // We shouldn't need this safety, but just in case there isn't an array index - // associated with this cycle we'll bail out - if ( ! isset($this->_field_data[$row['field']]['postdata'][$cycles])) - { - continue; - } - - $postdata = $this->_field_data[$row['field']]['postdata'][$cycles]; - $_in_array = TRUE; - } - else - { - $postdata = $this->_field_data[$row['field']]['postdata']; - } - - // -------------------------------------------------------------------- - - // Is the rule a callback? - $callback = FALSE; - if (substr($rule, 0, 9) == 'callback_') - { - $rule = substr($rule, 9); - $callback = TRUE; - } - - // Strip the parameter (if exists) from the rule - // Rules can contain a parameter: max_length[5] - $param = FALSE; - if (preg_match("/(.*?)\[(.*?)\]/", $rule, $match)) - { - $rule = $match[1]; - $param = $match[2]; - } - - // Call the function that corresponds to the rule - if ($callback === TRUE) - { - if ( ! method_exists($this->CI, $rule)) - { - continue; - } - - // Run the function and grab the result - $result = $this->CI->$rule($postdata, $param); - - // Re-assign the result to the master data array - if ($_in_array == TRUE) - { - $this->_field_data[$row['field']]['postdata'][$cycles] = (is_bool($result)) ? $postdata : $result; - } - else - { - $this->_field_data[$row['field']]['postdata'] = (is_bool($result)) ? $postdata : $result; - } - - // If the field isn't required and we just processed a callback we'll move on... - if ( ! in_array('required', $rules, TRUE) AND $result !== FALSE) - { - return; - } - } - else - { - if ( ! method_exists($this, $rule)) - { - // If our own wrapper function doesn't exist we see if a native PHP function does. - // Users can use any native PHP function call that has one param. - if (function_exists($rule)) - { - $result = $rule($postdata); - - if ($_in_array == TRUE) - { - $this->_field_data[$row['field']]['postdata'][$cycles] = (is_bool($result)) ? $postdata : $result; - } - else - { - $this->_field_data[$row['field']]['postdata'] = (is_bool($result)) ? $postdata : $result; - } - } - - continue; - } - - $result = $this->$rule($postdata, $param); - - if ($_in_array == TRUE) - { - $this->_field_data[$row['field']]['postdata'][$cycles] = (is_bool($result)) ? $postdata : $result; - } - else - { - $this->_field_data[$row['field']]['postdata'] = (is_bool($result)) ? $postdata : $result; - } - } - - // Did the rule test negatively? If so, grab the error. - if ($result === FALSE) - { - if ( ! isset($this->_error_messages[$rule])) - { - if (FALSE === ($line = $this->CI->lang->line($rule))) - { - $line = 'Unable to access an error message corresponding to your field name.'; - } - } - else - { - $line = $this->_error_messages[$rule]; - } - - // Is the parameter we are inserting into the error message the name - // of another field? If so we need to grab its "field label" - if (isset($this->_field_data[$param]) AND isset($this->_field_data[$param]['label'])) - { - $param = $this->_field_data[$param]['label']; - } - - // Build the error message - $message = sprintf($line, $this->_translate_fieldname($row['label']), $param); - - // Save the error message - $this->_field_data[$row['field']]['error'] = $message; - - if ( ! isset($this->_error_array[$row['field']])) - { - $this->_error_array[$row['field']] = $message; - } - - return; - } - } - } - - // -------------------------------------------------------------------- - - /** - * Translate a field name - * - * @access private - * @param string the field name - * @return string - */ - function _translate_fieldname($fieldname) - { - // Do we need to translate the field name? - // We look for the prefix lang: to determine this - if (substr($fieldname, 0, 5) == 'lang:') - { - // Grab the variable - $line = substr($fieldname, 5); - - // Were we able to translate the field name? If not we use $line - if (FALSE === ($fieldname = $this->CI->lang->line($line))) - { - return $line; - } - } - - return $fieldname; - } - - // -------------------------------------------------------------------- - - /** - * Get the value from a form - * - * Permits you to repopulate a form field with the value it was submitted - * with, or, if that value doesn't exist, with the default - * - * @access public - * @param string the field name - * @param string - * @return void - */ - function set_value($field = '', $default = '') - { - if ( ! isset($this->_field_data[$field])) - { - return $default; - } - - return $this->_field_data[$field]['postdata']; - } - - // -------------------------------------------------------------------- - - /** - * Set Select - * - * Enables pull-down lists to be set to the value the user - * selected in the event of an error - * - * @access public - * @param string - * @param string - * @return string - */ - function set_select($field = '', $value = '', $default = FALSE) - { - if ( ! isset($this->_field_data[$field]) OR ! isset($this->_field_data[$field]['postdata'])) - { - if ($default === TRUE AND count($this->_field_data) === 0) - { - return ' selected="selected"'; - } - return ''; - } - - $field = $this->_field_data[$field]['postdata']; - - if (is_array($field)) - { - if ( ! in_array($value, $field)) - { - return ''; - } - } - else - { - if (($field == '' OR $value == '') OR ($field != $value)) - { - return ''; - } - } - - return ' selected="selected"'; - } - - // -------------------------------------------------------------------- - - /** - * Set Radio - * - * Enables radio buttons to be set to the value the user - * selected in the event of an error - * - * @access public - * @param string - * @param string - * @return string - */ - function set_radio($field = '', $value = '', $default = FALSE) - { - if ( ! isset($this->_field_data[$field]) OR ! isset($this->_field_data[$field]['postdata'])) - { - if ($default === TRUE AND count($this->_field_data) === 0) - { - return ' checked="checked"'; - } - return ''; - } - - $field = $this->_field_data[$field]['postdata']; - - if (is_array($field)) - { - if ( ! in_array($value, $field)) - { - return ''; - } - } - else - { - if (($field == '' OR $value == '') OR ($field != $value)) - { - return ''; - } - } - - return ' checked="checked"'; - } - - // -------------------------------------------------------------------- - - /** - * Set Checkbox - * - * Enables checkboxes to be set to the value the user - * selected in the event of an error - * - * @access public - * @param string - * @param string - * @return string - */ - function set_checkbox($field = '', $value = '', $default = FALSE) - { - if ( ! isset($this->_field_data[$field]) OR ! isset($this->_field_data[$field]['postdata'])) - { - if ($default === TRUE AND count($this->_field_data) === 0) - { - return ' checked="checked"'; - } - return ''; - } - - $field = $this->_field_data[$field]['postdata']; - - if (is_array($field)) - { - if ( ! in_array($value, $field)) - { - return ''; - } - } - else - { - if (($field == '' OR $value == '') OR ($field != $value)) - { - return ''; - } - } - - return ' checked="checked"'; - } - - // -------------------------------------------------------------------- - - /** - * Required - * - * @access public - * @param string - * @return bool - */ - function required($str) - { - if ( ! is_array($str)) - { - return (trim($str) == '') ? FALSE : TRUE; - } - else - { - return ( ! empty($str)); - } - } - - // -------------------------------------------------------------------- - - /** - * Match one field to another - * - * @access public - * @param string - * @param field - * @return bool - */ - function matches($str, $field) - { - if ( ! isset($_POST[$field])) - { - return FALSE; - } - - $field = $_POST[$field]; - - return ($str !== $field) ? FALSE : TRUE; - } - - // -------------------------------------------------------------------- - - /** - * Minimum Length - * - * @access public - * @param string - * @param value - * @return bool - */ - function min_length($str, $val) - { - if (preg_match("/[^0-9]/", $val)) - { - return FALSE; - } - - if (function_exists('mb_strlen')) - { - return (mb_strlen($str) < $val) ? FALSE : TRUE; - } - - return (strlen($str) < $val) ? FALSE : TRUE; - } - - // -------------------------------------------------------------------- - - /** - * Max Length - * - * @access public - * @param string - * @param value - * @return bool - */ - function max_length($str, $val) - { - if (preg_match("/[^0-9]/", $val)) - { - return FALSE; - } - - if (function_exists('mb_strlen')) - { - return (mb_strlen($str) > $val) ? FALSE : TRUE; - } - - return (strlen($str) > $val) ? FALSE : TRUE; - } - - // -------------------------------------------------------------------- - - /** - * Exact Length - * - * @access public - * @param string - * @param value - * @return bool - */ - function exact_length($str, $val) - { - if (preg_match("/[^0-9]/", $val)) - { - return FALSE; - } - - if (function_exists('mb_strlen')) - { - return (mb_strlen($str) != $val) ? FALSE : TRUE; - } - - return (strlen($str) != $val) ? FALSE : TRUE; - } - - // -------------------------------------------------------------------- - - /** - * Valid Email - * - * @access public - * @param string - * @return bool - */ - function valid_email($str) - { - return ( ! preg_match("/^([a-z0-9\+_\-]+)(\.[a-z0-9\+_\-]+)*@([a-z0-9\-]+\.)+[a-z]{2,6}$/ix", $str)) ? FALSE : TRUE; - } - - // -------------------------------------------------------------------- - - /** - * Valid Emails - * - * @access public - * @param string - * @return bool - */ - function valid_emails($str) - { - if (strpos($str, ',') === FALSE) - { - return $this->valid_email(trim($str)); - } - - foreach(explode(',', $str) as $email) - { - if (trim($email) != '' && $this->valid_email(trim($email)) === FALSE) - { - return FALSE; - } - } - - return TRUE; - } - - // -------------------------------------------------------------------- - - /** - * Validate IP Address - * - * @access public - * @param string - * @return string - */ - function valid_ip($ip) - { - return $this->CI->input->valid_ip($ip); - } - - // -------------------------------------------------------------------- - - /** - * Alpha - * - * @access public - * @param string - * @return bool - */ - function alpha($str) - { - return ( ! preg_match("/^([a-z])+$/i", $str)) ? FALSE : TRUE; - } - - // -------------------------------------------------------------------- - - /** - * Alpha-numeric - * - * @access public - * @param string - * @return bool - */ - function alpha_numeric($str) - { - return ( ! preg_match("/^([a-z0-9])+$/i", $str)) ? FALSE : TRUE; - } - - // -------------------------------------------------------------------- - - /** - * Alpha-numeric with underscores and dashes - * - * @access public - * @param string - * @return bool - */ - function alpha_dash($str) - { - return ( ! preg_match("/^([-a-z0-9_-])+$/i", $str)) ? FALSE : TRUE; - } - - // -------------------------------------------------------------------- - - /** - * Numeric - * - * @access public - * @param string - * @return bool - */ - function numeric($str) - { - return (bool)preg_match( '/^[\-+]?[0-9]*\.?[0-9]+$/', $str); - - } - - // -------------------------------------------------------------------- - - /** - * Is Numeric - * - * @access public - * @param string - * @return bool - */ - function is_numeric($str) - { - return ( ! is_numeric($str)) ? FALSE : TRUE; - } - - // -------------------------------------------------------------------- - - /** - * Integer - * - * @access public - * @param string - * @return bool - */ - function integer($str) - { - return (bool)preg_match( '/^[\-+]?[0-9]+$/', $str); - } - - // -------------------------------------------------------------------- - - /** - * Is a Natural number (0,1,2,3, etc.) - * - * @access public - * @param string - * @return bool - */ - function is_natural($str) - { - return (bool)preg_match( '/^[0-9]+$/', $str); - } - - // -------------------------------------------------------------------- - - /** - * Is a Natural number, but not a zero (1,2,3, etc.) - * - * @access public - * @param string - * @return bool - */ - function is_natural_no_zero($str) - { - if ( ! preg_match( '/^[0-9]+$/', $str)) - { - return FALSE; - } - - if ($str == 0) - { - return FALSE; - } - - return TRUE; - } - - // -------------------------------------------------------------------- - - /** - * Valid Base64 - * - * Tests a string for characters outside of the Base64 alphabet - * as defined by RFC 2045 http://www.faqs.org/rfcs/rfc2045 - * - * @access public - * @param string - * @return bool - */ - function valid_base64($str) - { - return (bool) ! preg_match('/[^a-zA-Z0-9\/\+=]/', $str); - } - - // -------------------------------------------------------------------- - - /** - * Prep data for form - * - * This function allows HTML to be safely shown in a form. - * Special characters are converted. - * - * @access public - * @param string - * @return string - */ - function prep_for_form($data = '') - { - if (is_array($data)) - { - foreach ($data as $key => $val) - { - $data[$key] = $this->prep_for_form($val); - } - - return $data; - } - - if ($this->_safe_form_data == FALSE OR $data === '') - { - return $data; - } - - return str_replace(array("'", '"', '<', '>'), array("'", """, '<', '>'), stripslashes($data)); - } - - // -------------------------------------------------------------------- - - /** - * Prep URL - * - * @access public - * @param string - * @return string - */ - function prep_url($str = '') - { - if ($str == 'http://' OR $str == '') - { - return ''; - } - - if (substr($str, 0, 7) != 'http://' && substr($str, 0, 8) != 'https://') - { - $str = 'http://'.$str; - } - - return $str; - } - - // -------------------------------------------------------------------- - - /** - * Strip Image Tags - * - * @access public - * @param string - * @return string - */ - function strip_image_tags($str) - { - return $this->CI->input->strip_image_tags($str); - } - - // -------------------------------------------------------------------- - - /** - * XSS Clean - * - * @access public - * @param string - * @return string - */ - function xss_clean($str) - { - return $this->CI->input->xss_clean($str); - } - - // -------------------------------------------------------------------- - - /** - * Convert PHP tags to entities - * - * @access public - * @param string - * @return string - */ - function encode_php_tags($str) - { - return str_replace(array(''), array('<?php', '<?PHP', '<?', '?>'), $str); - } - -} -// END Form Validation Class - -/* End of file Form_validation.php */ +'; + var $_error_suffix = '

    '; + var $error_string = ''; + var $_safe_form_data = FALSE; + + + /** + * Constructor + * + */ + function CI_Form_validation($rules = array()) + { + $this->CI =& get_instance(); + + // Validation rules can be stored in a config file. + $this->_config_rules = $rules; + + // Automatically load the form helper + $this->CI->load->helper('form'); + + // Set the character encoding in MB. + if (function_exists('mb_internal_encoding')) + { + mb_internal_encoding($this->CI->config->item('charset')); + } + + log_message('debug', "Form Validation Class Initialized"); + } + + // -------------------------------------------------------------------- + + /** + * Set Rules + * + * This function takes an array of field names and validation + * rules as input, validates the info, and stores it + * + * @access public + * @param mixed + * @param string + * @return void + */ + function set_rules($field, $label = '', $rules = '') + { + // No reason to set rules if we have no POST data + if (count($_POST) == 0) + { + return; + } + + // If an array was passed via the first parameter instead of indidual string + // values we cycle through it and recursively call this function. + if (is_array($field)) + { + foreach ($field as $row) + { + // Houston, we have a problem... + if ( ! isset($row['field']) OR ! isset($row['rules'])) + { + continue; + } + + // If the field label wasn't passed we use the field name + $label = ( ! isset($row['label'])) ? $row['field'] : $row['label']; + + // Here we go! + $this->set_rules($row['field'], $label, $row['rules']); + } + return; + } + + // No fields? Nothing to do... + if ( ! is_string($field) OR ! is_string($rules) OR $field == '') + { + return; + } + + // If the field label wasn't passed we use the field name + $label = ($label == '') ? $field : $label; + + // Is the field name an array? We test for the existence of a bracket "[" in + // the field name to determine this. If it is an array, we break it apart + // into its components so that we can fetch the corresponding POST data later + if (strpos($field, '[') !== FALSE AND preg_match_all('/\[(.*?)\]/', $field, $matches)) + { + // Note: Due to a bug in current() that affects some versions + // of PHP we can not pass function call directly into it + $x = explode('[', $field); + $indexes[] = current($x); + + for ($i = 0; $i < count($matches['0']); $i++) + { + if ($matches['1'][$i] != '') + { + $indexes[] = $matches['1'][$i]; + } + } + + $is_array = TRUE; + } + else + { + $indexes = array(); + $is_array = FALSE; + } + + // Build our master array + $this->_field_data[$field] = array( + 'field' => $field, + 'label' => $label, + 'rules' => $rules, + 'is_array' => $is_array, + 'keys' => $indexes, + 'postdata' => NULL, + 'error' => '' + ); + } + + // -------------------------------------------------------------------- + + /** + * Set Error Message + * + * Lets users set their own error messages on the fly. Note: The key + * name has to match the function name that it corresponds to. + * + * @access public + * @param string + * @param string + * @return string + */ + function set_message($lang, $val = '') + { + if ( ! is_array($lang)) + { + $lang = array($lang => $val); + } + + $this->_error_messages = array_merge($this->_error_messages, $lang); + } + + // -------------------------------------------------------------------- + + /** + * Set The Error Delimiter + * + * Permits a prefix/suffix to be added to each error message + * + * @access public + * @param string + * @param string + * @return void + */ + function set_error_delimiters($prefix = '

    ', $suffix = '

    ') + { + $this->_error_prefix = $prefix; + $this->_error_suffix = $suffix; + } + + // -------------------------------------------------------------------- + + /** + * Get Error Message + * + * Gets the error message associated with a particular field + * + * @access public + * @param string the field name + * @return void + */ + function error($field = '', $prefix = '', $suffix = '') + { + if ( ! isset($this->_field_data[$field]['error']) OR $this->_field_data[$field]['error'] == '') + { + return ''; + } + + if ($prefix == '') + { + $prefix = $this->_error_prefix; + } + + if ($suffix == '') + { + $suffix = $this->_error_suffix; + } + + return $prefix.$this->_field_data[$field]['error'].$suffix; + } + + // -------------------------------------------------------------------- + + /** + * Error String + * + * Returns the error messages as a string, wrapped in the error delimiters + * + * @access public + * @param string + * @param string + * @return str + */ + function error_string($prefix = '', $suffix = '') + { + // No errrors, validation passes! + if (count($this->_error_array) === 0) + { + return ''; + } + + if ($prefix == '') + { + $prefix = $this->_error_prefix; + } + + if ($suffix == '') + { + $suffix = $this->_error_suffix; + } + + // Generate the error string + $str = ''; + foreach ($this->_error_array as $val) + { + if ($val != '') + { + $str .= $prefix.$val.$suffix."\n"; + } + } + + return $str; + } + + // -------------------------------------------------------------------- + + /** + * Run the Validator + * + * This function does all the work. + * + * @access public + * @return bool + */ + function run($group = '') + { + // Do we even have any data to process? Mm? + if (count($_POST) == 0) + { + return FALSE; + } + + // Does the _field_data array containing the validation rules exist? + // If not, we look to see if they were assigned via a config file + if (count($this->_field_data) == 0) + { + // No validation rules? We're done... + if (count($this->_config_rules) == 0) + { + return FALSE; + } + + // Is there a validation rule for the particular URI being accessed? + $uri = ($group == '') ? trim($this->CI->uri->ruri_string(), '/') : $group; + + if ($uri != '' AND isset($this->_config_rules[$uri])) + { + $this->set_rules($this->_config_rules[$uri]); + } + else + { + $this->set_rules($this->_config_rules); + } + + // We're we able to set the rules correctly? + if (count($this->_field_data) == 0) + { + log_message('debug', "Unable to find validation rules"); + return FALSE; + } + } + + // Load the language file containing error messages + $this->CI->lang->load('form_validation'); + + // Cycle through the rules for each field, match the + // corresponding $_POST item and test for errors + foreach ($this->_field_data as $field => $row) + { + // Fetch the data from the corresponding $_POST array and cache it in the _field_data array. + // Depending on whether the field name is an array or a string will determine where we get it from. + + if ($row['is_array'] == TRUE) + { + $this->_field_data[$field]['postdata'] = $this->_reduce_array($_POST, $row['keys']); + } + else + { + if (isset($_POST[$field]) AND $_POST[$field] != "") + { + $this->_field_data[$field]['postdata'] = $_POST[$field]; + } + } + + $this->_execute($row, explode('|', $row['rules']), $this->_field_data[$field]['postdata']); + } + + // Did we end up with any errors? + $total_errors = count($this->_error_array); + + if ($total_errors > 0) + { + $this->_safe_form_data = TRUE; + } + + // Now we need to re-set the POST data with the new, processed data + $this->_reset_post_array(); + + // No errors, validation passes! + if ($total_errors == 0) + { + return TRUE; + } + + // Validation fails + return FALSE; + } + + // -------------------------------------------------------------------- + + /** + * Traverse a multidimensional $_POST array index until the data is found + * + * @access private + * @param array + * @param array + * @param integer + * @return mixed + */ + function _reduce_array($array, $keys, $i = 0) + { + if (is_array($array)) + { + if (isset($keys[$i])) + { + if (isset($array[$keys[$i]])) + { + $array = $this->_reduce_array($array[$keys[$i]], $keys, ($i+1)); + } + else + { + return NULL; + } + } + else + { + return $array; + } + } + + return $array; + } + + // -------------------------------------------------------------------- + + /** + * Re-populate the _POST array with our finalized and processed data + * + * @access private + * @return null + */ + function _reset_post_array() + { + foreach ($this->_field_data as $field => $row) + { + if ( ! is_null($row['postdata'])) + { + if ($row['is_array'] == FALSE) + { + if (isset($_POST[$row['field']])) + { + $_POST[$row['field']] = $this->prep_for_form($row['postdata']); + } + } + else + { + $post = '$_POST["'; + + if (count($row['keys']) == 1) + { + $post .= current($row['keys']); + $post .= '"]'; + } + else + { + $i = 0; + foreach ($row['keys'] as $val) + { + if ($i == 0) + { + $post .= $val.'"]'; + $i++; + continue; + } + + $post .= '["'.$val.'"]'; + } + } + + if (is_array($row['postdata'])) + { + $array = array(); + foreach ($row['postdata'] as $k => $v) + { + $array[$k] = $this->prep_for_form($v); + } + + $post .= ' = $array;'; + } + else + { + $post .= ' = "'.$this->prep_for_form($row['postdata']).'";'; + } + + eval($post); + } + } + } + } + + // -------------------------------------------------------------------- + + /** + * Executes the Validation routines + * + * @access private + * @param array + * @param array + * @param mixed + * @param integer + * @return mixed + */ + function _execute($row, $rules, $postdata = NULL, $cycles = 0) + { + // If the $_POST data is an array we will run a recursive call + if (is_array($postdata)) + { + foreach ($postdata as $key => $val) + { + $this->_execute($row, $rules, $val, $cycles); + $cycles++; + } + + return; + } + + // -------------------------------------------------------------------- + + // If the field is blank, but NOT required, no further tests are necessary + $callback = FALSE; + if ( ! in_array('required', $rules) AND is_null($postdata)) + { + // Before we bail out, does the rule contain a callback? + if (preg_match("/(callback_\w+)/", implode(' ', $rules), $match)) + { + $callback = TRUE; + $rules = (array('1' => $match[1])); + } + else + { + return; + } + } + + // -------------------------------------------------------------------- + + // Isset Test. Typically this rule will only apply to checkboxes. + if (is_null($postdata) AND $callback == FALSE) + { + if (in_array('isset', $rules, TRUE) OR in_array('required', $rules)) + { + // Set the message type + $type = (in_array('required', $rules)) ? 'required' : 'isset'; + + if ( ! isset($this->_error_messages[$type])) + { + if (FALSE === ($line = $this->CI->lang->line($type))) + { + $line = 'The field was not set'; + } + } + else + { + $line = $this->_error_messages[$type]; + } + + // Build the error message + $message = sprintf($line, $this->_translate_fieldname($row['label'])); + + // Save the error message + $this->_field_data[$row['field']]['error'] = $message; + + if ( ! isset($this->_error_array[$row['field']])) + { + $this->_error_array[$row['field']] = $message; + } + } + + return; + } + + // -------------------------------------------------------------------- + + // Cycle through each rule and run it + foreach ($rules As $rule) + { + $_in_array = FALSE; + + // We set the $postdata variable with the current data in our master array so that + // each cycle of the loop is dealing with the processed data from the last cycle + if ($row['is_array'] == TRUE AND is_array($this->_field_data[$row['field']]['postdata'])) + { + // We shouldn't need this safety, but just in case there isn't an array index + // associated with this cycle we'll bail out + if ( ! isset($this->_field_data[$row['field']]['postdata'][$cycles])) + { + continue; + } + + $postdata = $this->_field_data[$row['field']]['postdata'][$cycles]; + $_in_array = TRUE; + } + else + { + $postdata = $this->_field_data[$row['field']]['postdata']; + } + + // -------------------------------------------------------------------- + + // Is the rule a callback? + $callback = FALSE; + if (substr($rule, 0, 9) == 'callback_') + { + $rule = substr($rule, 9); + $callback = TRUE; + } + + // Strip the parameter (if exists) from the rule + // Rules can contain a parameter: max_length[5] + $param = FALSE; + if (preg_match("/(.*?)\[(.*?)\]/", $rule, $match)) + { + $rule = $match[1]; + $param = $match[2]; + } + + // Call the function that corresponds to the rule + if ($callback === TRUE) + { + if ( ! method_exists($this->CI, $rule)) + { + continue; + } + + // Run the function and grab the result + $result = $this->CI->$rule($postdata, $param); + + // Re-assign the result to the master data array + if ($_in_array == TRUE) + { + $this->_field_data[$row['field']]['postdata'][$cycles] = (is_bool($result)) ? $postdata : $result; + } + else + { + $this->_field_data[$row['field']]['postdata'] = (is_bool($result)) ? $postdata : $result; + } + + // If the field isn't required and we just processed a callback we'll move on... + if ( ! in_array('required', $rules, TRUE) AND $result !== FALSE) + { + return; + } + } + else + { + if ( ! method_exists($this, $rule)) + { + // If our own wrapper function doesn't exist we see if a native PHP function does. + // Users can use any native PHP function call that has one param. + if (function_exists($rule)) + { + $result = $rule($postdata); + + if ($_in_array == TRUE) + { + $this->_field_data[$row['field']]['postdata'][$cycles] = (is_bool($result)) ? $postdata : $result; + } + else + { + $this->_field_data[$row['field']]['postdata'] = (is_bool($result)) ? $postdata : $result; + } + } + + continue; + } + + $result = $this->$rule($postdata, $param); + + if ($_in_array == TRUE) + { + $this->_field_data[$row['field']]['postdata'][$cycles] = (is_bool($result)) ? $postdata : $result; + } + else + { + $this->_field_data[$row['field']]['postdata'] = (is_bool($result)) ? $postdata : $result; + } + } + + // Did the rule test negatively? If so, grab the error. + if ($result === FALSE) + { + if ( ! isset($this->_error_messages[$rule])) + { + if (FALSE === ($line = $this->CI->lang->line($rule))) + { + $line = 'Unable to access an error message corresponding to your field name.'; + } + } + else + { + $line = $this->_error_messages[$rule]; + } + + // Is the parameter we are inserting into the error message the name + // of another field? If so we need to grab its "field label" + if (isset($this->_field_data[$param]) AND isset($this->_field_data[$param]['label'])) + { + $param = $this->_field_data[$param]['label']; + } + + // Build the error message + $message = sprintf($line, $this->_translate_fieldname($row['label']), $param); + + // Save the error message + $this->_field_data[$row['field']]['error'] = $message; + + if ( ! isset($this->_error_array[$row['field']])) + { + $this->_error_array[$row['field']] = $message; + } + + return; + } + } + } + + // -------------------------------------------------------------------- + + /** + * Translate a field name + * + * @access private + * @param string the field name + * @return string + */ + function _translate_fieldname($fieldname) + { + // Do we need to translate the field name? + // We look for the prefix lang: to determine this + if (substr($fieldname, 0, 5) == 'lang:') + { + // Grab the variable + $line = substr($fieldname, 5); + + // Were we able to translate the field name? If not we use $line + if (FALSE === ($fieldname = $this->CI->lang->line($line))) + { + return $line; + } + } + + return $fieldname; + } + + // -------------------------------------------------------------------- + + /** + * Get the value from a form + * + * Permits you to repopulate a form field with the value it was submitted + * with, or, if that value doesn't exist, with the default + * + * @access public + * @param string the field name + * @param string + * @return void + */ + function set_value($field = '', $default = '') + { + if ( ! isset($this->_field_data[$field])) + { + return $default; + } + + return $this->_field_data[$field]['postdata']; + } + + // -------------------------------------------------------------------- + + /** + * Set Select + * + * Enables pull-down lists to be set to the value the user + * selected in the event of an error + * + * @access public + * @param string + * @param string + * @return string + */ + function set_select($field = '', $value = '', $default = FALSE) + { + if ( ! isset($this->_field_data[$field]) OR ! isset($this->_field_data[$field]['postdata'])) + { + if ($default === TRUE AND count($this->_field_data) === 0) + { + return ' selected="selected"'; + } + return ''; + } + + $field = $this->_field_data[$field]['postdata']; + + if (is_array($field)) + { + if ( ! in_array($value, $field)) + { + return ''; + } + } + else + { + if (($field == '' OR $value == '') OR ($field != $value)) + { + return ''; + } + } + + return ' selected="selected"'; + } + + // -------------------------------------------------------------------- + + /** + * Set Radio + * + * Enables radio buttons to be set to the value the user + * selected in the event of an error + * + * @access public + * @param string + * @param string + * @return string + */ + function set_radio($field = '', $value = '', $default = FALSE) + { + if ( ! isset($this->_field_data[$field]) OR ! isset($this->_field_data[$field]['postdata'])) + { + if ($default === TRUE AND count($this->_field_data) === 0) + { + return ' checked="checked"'; + } + return ''; + } + + $field = $this->_field_data[$field]['postdata']; + + if (is_array($field)) + { + if ( ! in_array($value, $field)) + { + return ''; + } + } + else + { + if (($field == '' OR $value == '') OR ($field != $value)) + { + return ''; + } + } + + return ' checked="checked"'; + } + + // -------------------------------------------------------------------- + + /** + * Set Checkbox + * + * Enables checkboxes to be set to the value the user + * selected in the event of an error + * + * @access public + * @param string + * @param string + * @return string + */ + function set_checkbox($field = '', $value = '', $default = FALSE) + { + if ( ! isset($this->_field_data[$field]) OR ! isset($this->_field_data[$field]['postdata'])) + { + if ($default === TRUE AND count($this->_field_data) === 0) + { + return ' checked="checked"'; + } + return ''; + } + + $field = $this->_field_data[$field]['postdata']; + + if (is_array($field)) + { + if ( ! in_array($value, $field)) + { + return ''; + } + } + else + { + if (($field == '' OR $value == '') OR ($field != $value)) + { + return ''; + } + } + + return ' checked="checked"'; + } + + // -------------------------------------------------------------------- + + /** + * Required + * + * @access public + * @param string + * @return bool + */ + function required($str) + { + if ( ! is_array($str)) + { + return (trim($str) == '') ? FALSE : TRUE; + } + else + { + return ( ! empty($str)); + } + } + + // -------------------------------------------------------------------- + + /** + * Match one field to another + * + * @access public + * @param string + * @param field + * @return bool + */ + function matches($str, $field) + { + if ( ! isset($_POST[$field])) + { + return FALSE; + } + + $field = $_POST[$field]; + + return ($str !== $field) ? FALSE : TRUE; + } + + // -------------------------------------------------------------------- + + /** + * Minimum Length + * + * @access public + * @param string + * @param value + * @return bool + */ + function min_length($str, $val) + { + if (preg_match("/[^0-9]/", $val)) + { + return FALSE; + } + + if (function_exists('mb_strlen')) + { + return (mb_strlen($str) < $val) ? FALSE : TRUE; + } + + return (strlen($str) < $val) ? FALSE : TRUE; + } + + // -------------------------------------------------------------------- + + /** + * Max Length + * + * @access public + * @param string + * @param value + * @return bool + */ + function max_length($str, $val) + { + if (preg_match("/[^0-9]/", $val)) + { + return FALSE; + } + + if (function_exists('mb_strlen')) + { + return (mb_strlen($str) > $val) ? FALSE : TRUE; + } + + return (strlen($str) > $val) ? FALSE : TRUE; + } + + // -------------------------------------------------------------------- + + /** + * Exact Length + * + * @access public + * @param string + * @param value + * @return bool + */ + function exact_length($str, $val) + { + if (preg_match("/[^0-9]/", $val)) + { + return FALSE; + } + + if (function_exists('mb_strlen')) + { + return (mb_strlen($str) != $val) ? FALSE : TRUE; + } + + return (strlen($str) != $val) ? FALSE : TRUE; + } + + // -------------------------------------------------------------------- + + /** + * Valid Email + * + * @access public + * @param string + * @return bool + */ + function valid_email($str) + { + return ( ! preg_match("/^([a-z0-9\+_\-]+)(\.[a-z0-9\+_\-]+)*@([a-z0-9\-]+\.)+[a-z]{2,6}$/ix", $str)) ? FALSE : TRUE; + } + + // -------------------------------------------------------------------- + + /** + * Valid Emails + * + * @access public + * @param string + * @return bool + */ + function valid_emails($str) + { + if (strpos($str, ',') === FALSE) + { + return $this->valid_email(trim($str)); + } + + foreach(explode(',', $str) as $email) + { + if (trim($email) != '' && $this->valid_email(trim($email)) === FALSE) + { + return FALSE; + } + } + + return TRUE; + } + + // -------------------------------------------------------------------- + + /** + * Validate IP Address + * + * @access public + * @param string + * @return string + */ + function valid_ip($ip) + { + return $this->CI->input->valid_ip($ip); + } + + // -------------------------------------------------------------------- + + /** + * Alpha + * + * @access public + * @param string + * @return bool + */ + function alpha($str) + { + return ( ! preg_match("/^([a-z])+$/i", $str)) ? FALSE : TRUE; + } + + // -------------------------------------------------------------------- + + /** + * Alpha-numeric + * + * @access public + * @param string + * @return bool + */ + function alpha_numeric($str) + { + return ( ! preg_match("/^([a-z0-9])+$/i", $str)) ? FALSE : TRUE; + } + + // -------------------------------------------------------------------- + + /** + * Alpha-numeric with underscores and dashes + * + * @access public + * @param string + * @return bool + */ + function alpha_dash($str) + { + return ( ! preg_match("/^([-a-z0-9_-])+$/i", $str)) ? FALSE : TRUE; + } + + // -------------------------------------------------------------------- + + /** + * Numeric + * + * @access public + * @param string + * @return bool + */ + function numeric($str) + { + return (bool)preg_match( '/^[\-+]?[0-9]*\.?[0-9]+$/', $str); + + } + + // -------------------------------------------------------------------- + + /** + * Is Numeric + * + * @access public + * @param string + * @return bool + */ + function is_numeric($str) + { + return ( ! is_numeric($str)) ? FALSE : TRUE; + } + + // -------------------------------------------------------------------- + + /** + * Integer + * + * @access public + * @param string + * @return bool + */ + function integer($str) + { + return (bool)preg_match( '/^[\-+]?[0-9]+$/', $str); + } + + // -------------------------------------------------------------------- + + /** + * Is a Natural number (0,1,2,3, etc.) + * + * @access public + * @param string + * @return bool + */ + function is_natural($str) + { + return (bool)preg_match( '/^[0-9]+$/', $str); + } + + // -------------------------------------------------------------------- + + /** + * Is a Natural number, but not a zero (1,2,3, etc.) + * + * @access public + * @param string + * @return bool + */ + function is_natural_no_zero($str) + { + if ( ! preg_match( '/^[0-9]+$/', $str)) + { + return FALSE; + } + + if ($str == 0) + { + return FALSE; + } + + return TRUE; + } + + // -------------------------------------------------------------------- + + /** + * Valid Base64 + * + * Tests a string for characters outside of the Base64 alphabet + * as defined by RFC 2045 http://www.faqs.org/rfcs/rfc2045 + * + * @access public + * @param string + * @return bool + */ + function valid_base64($str) + { + return (bool) ! preg_match('/[^a-zA-Z0-9\/\+=]/', $str); + } + + // -------------------------------------------------------------------- + + /** + * Prep data for form + * + * This function allows HTML to be safely shown in a form. + * Special characters are converted. + * + * @access public + * @param string + * @return string + */ + function prep_for_form($data = '') + { + if (is_array($data)) + { + foreach ($data as $key => $val) + { + $data[$key] = $this->prep_for_form($val); + } + + return $data; + } + + if ($this->_safe_form_data == FALSE OR $data === '') + { + return $data; + } + + return str_replace(array("'", '"', '<', '>'), array("'", """, '<', '>'), stripslashes($data)); + } + + // -------------------------------------------------------------------- + + /** + * Prep URL + * + * @access public + * @param string + * @return string + */ + function prep_url($str = '') + { + if ($str == 'http://' OR $str == '') + { + return ''; + } + + if (substr($str, 0, 7) != 'http://' && substr($str, 0, 8) != 'https://') + { + $str = 'http://'.$str; + } + + return $str; + } + + // -------------------------------------------------------------------- + + /** + * Strip Image Tags + * + * @access public + * @param string + * @return string + */ + function strip_image_tags($str) + { + return $this->CI->input->strip_image_tags($str); + } + + // -------------------------------------------------------------------- + + /** + * XSS Clean + * + * @access public + * @param string + * @return string + */ + function xss_clean($str) + { + return $this->CI->input->xss_clean($str); + } + + // -------------------------------------------------------------------- + + /** + * Convert PHP tags to entities + * + * @access public + * @param string + * @return string + */ + function encode_php_tags($str) + { + return str_replace(array(''), array('<?php', '<?PHP', '<?', '?>'), $str); + } + +} +// END Form Validation Class + +/* End of file Form_validation.php */ /* Location: ./system/libraries/Form_validation.php */ \ No newline at end of file diff --git a/system/libraries/Ftp.php b/system/libraries/Ftp.php index 1a3ab184c..ec84eb0a7 100644 --- a/system/libraries/Ftp.php +++ b/system/libraries/Ftp.php @@ -1,618 +1,618 @@ - 0) - { - $this->initialize($config); - } - - log_message('debug', "FTP Class Initialized"); - } - - // -------------------------------------------------------------------- - - /** - * Initialize preferences - * - * @access public - * @param array - * @return void - */ - function initialize($config = array()) - { - foreach ($config as $key => $val) - { - if (isset($this->$key)) - { - $this->$key = $val; - } - } - - // Prep the hostname - $this->hostname = preg_replace('|.+?://|', '', $this->hostname); - } - - // -------------------------------------------------------------------- - - /** - * FTP Connect - * - * @access public - * @param array the connection values - * @return bool - */ - function connect($config = array()) - { - if (count($config) > 0) - { - $this->initialize($config); - } - - if (FALSE === ($this->conn_id = @ftp_connect($this->hostname, $this->port))) - { - if ($this->debug == TRUE) - { - $this->_error('ftp_unable_to_connect'); - } - return FALSE; - } - - if ( ! $this->_login()) - { - if ($this->debug == TRUE) - { - $this->_error('ftp_unable_to_login'); - } - return FALSE; - } - - // Set passive mode if needed - if ($this->passive == TRUE) - { - ftp_pasv($this->conn_id, TRUE); - } - - return TRUE; - } - - // -------------------------------------------------------------------- - - /** - * FTP Login - * - * @access private - * @return bool - */ - function _login() - { - return @ftp_login($this->conn_id, $this->username, $this->password); - } - - // -------------------------------------------------------------------- - - /** - * Validates the connection ID - * - * @access private - * @return bool - */ - function _is_conn() - { - if ( ! is_resource($this->conn_id)) - { - if ($this->debug == TRUE) - { - $this->_error('ftp_no_connection'); - } - return FALSE; - } - return TRUE; - } - - // -------------------------------------------------------------------- - - - /** - * Change direcotry - * - * The second parameter lets us momentarily turn off debugging so that - * this function can be used to test for the existance of a folder - * without throwing an error. There's no FTP equivalent to is_dir() - * so we do it by trying to change to a particular directory. - * Internally, this paramter is only used by the "mirror" function below. - * - * @access public - * @param string - * @param bool - * @return bool - */ - function changedir($path = '', $supress_debug = FALSE) - { - if ($path == '' OR ! $this->_is_conn()) - { - return FALSE; - } - - $result = @ftp_chdir($this->conn_id, $path); - - if ($result === FALSE) - { - if ($this->debug == TRUE AND $supress_debug == FALSE) - { - $this->_error('ftp_unable_to_changedir'); - } - return FALSE; - } - - return TRUE; - } - - // -------------------------------------------------------------------- - - /** - * Create a directory - * - * @access public - * @param string - * @return bool - */ - function mkdir($path = '', $permissions = NULL) - { - if ($path == '' OR ! $this->_is_conn()) - { - return FALSE; - } - - $result = @ftp_mkdir($this->conn_id, $path); - - if ($result === FALSE) - { - if ($this->debug == TRUE) - { - $this->_error('ftp_unable_to_makdir'); - } - return FALSE; - } - - // Set file permissions if needed - if ( ! is_null($permissions)) - { - $this->chmod($path, (int)$permissions); - } - - return TRUE; - } - - // -------------------------------------------------------------------- - - /** - * Upload a file to the server - * - * @access public - * @param string - * @param string - * @param string - * @return bool - */ - function upload($locpath, $rempath, $mode = 'auto', $permissions = NULL) - { - if ( ! $this->_is_conn()) - { - return FALSE; - } - - if ( ! file_exists($locpath)) - { - $this->_error('ftp_no_source_file'); - return FALSE; - } - - // Set the mode if not specified - if ($mode == 'auto') - { - // Get the file extension so we can set the upload type - $ext = $this->_getext($locpath); - $mode = $this->_settype($ext); - } - - $mode = ($mode == 'ascii') ? FTP_ASCII : FTP_BINARY; - - $result = @ftp_put($this->conn_id, $rempath, $locpath, $mode); - - if ($result === FALSE) - { - if ($this->debug == TRUE) - { - $this->_error('ftp_unable_to_upload'); - } - return FALSE; - } - - // Set file permissions if needed - if ( ! is_null($permissions)) - { - $this->chmod($rempath, (int)$permissions); - } - - return TRUE; - } - - // -------------------------------------------------------------------- - - /** - * Rename (or move) a file - * - * @access public - * @param string - * @param string - * @param bool - * @return bool - */ - function rename($old_file, $new_file, $move = FALSE) - { - if ( ! $this->_is_conn()) - { - return FALSE; - } - - $result = @ftp_rename($this->conn_id, $old_file, $new_file); - - if ($result === FALSE) - { - if ($this->debug == TRUE) - { - $msg = ($move == FALSE) ? 'ftp_unable_to_rename' : 'ftp_unable_to_move'; - - $this->_error($msg); - } - return FALSE; - } - - return TRUE; - } - - // -------------------------------------------------------------------- - - /** - * Move a file - * - * @access public - * @param string - * @param string - * @return bool - */ - function move($old_file, $new_file) - { - return $this->rename($old_file, $new_file, TRUE); - } - - // -------------------------------------------------------------------- - - /** - * Rename (or move) a file - * - * @access public - * @param string - * @return bool - */ - function delete_file($filepath) - { - if ( ! $this->_is_conn()) - { - return FALSE; - } - - $result = @ftp_delete($this->conn_id, $filepath); - - if ($result === FALSE) - { - if ($this->debug == TRUE) - { - $this->_error('ftp_unable_to_delete'); - } - return FALSE; - } - - return TRUE; - } - - // -------------------------------------------------------------------- - - /** - * Delete a folder and recursively delete everything (including sub-folders) - * containted within it. - * - * @access public - * @param string - * @return bool - */ - function delete_dir($filepath) - { - if ( ! $this->_is_conn()) - { - return FALSE; - } - - // Add a trailing slash to the file path if needed - $filepath = preg_replace("/(.+?)\/*$/", "\\1/", $filepath); - - $list = $this->list_files($filepath); - - if ($list !== FALSE AND count($list) > 0) - { - foreach ($list as $item) - { - // If we can't delete the item it's probaly a folder so - // we'll recursively call delete_dir() - if ( ! @ftp_delete($this->conn_id, $item)) - { - $this->delete_dir($item); - } - } - } - - $result = @ftp_rmdir($this->conn_id, $filepath); - - if ($result === FALSE) - { - if ($this->debug == TRUE) - { - $this->_error('ftp_unable_to_delete'); - } - return FALSE; - } - - return TRUE; - } - - // -------------------------------------------------------------------- - - /** - * Set file permissions - * - * @access public - * @param string the file path - * @param string the permissions - * @return bool - */ - function chmod($path, $perm) - { - if ( ! $this->_is_conn()) - { - return FALSE; - } - - // Permissions can only be set when running PHP 5 - if ( ! function_exists('ftp_chmod')) - { - if ($this->debug == TRUE) - { - $this->_error('ftp_unable_to_chmod'); - } - return FALSE; - } - - $result = @ftp_chmod($this->conn_id, $perm, $path); - - if ($result === FALSE) - { - if ($this->debug == TRUE) - { - $this->_error('ftp_unable_to_chmod'); - } - return FALSE; - } - - return TRUE; - } - - // -------------------------------------------------------------------- - - /** - * FTP List files in the specified directory - * - * @access public - * @return array - */ - function list_files($path = '.') - { - if ( ! $this->_is_conn()) - { - return FALSE; - } - - return ftp_nlist($this->conn_id, $path); - } - - // ------------------------------------------------------------------------ - - /** - * Read a directory and recreate it remotely - * - * This function recursively reads a folder and everything it contains (including - * sub-folders) and creates a mirror via FTP based on it. Whatever the directory structure - * of the original file path will be recreated on the server. - * - * @access public - * @param string path to source with trailing slash - * @param string path to destination - include the base folder with trailing slash - * @return bool - */ - function mirror($locpath, $rempath) - { - if ( ! $this->_is_conn()) - { - return FALSE; - } - - // Open the local file path - if ($fp = @opendir($locpath)) - { - // Attempt to open the remote file path. - if ( ! $this->changedir($rempath, TRUE)) - { - // If it doesn't exist we'll attempt to create the direcotory - if ( ! $this->mkdir($rempath) OR ! $this->changedir($rempath)) - { - return FALSE; - } - } - - // Recursively read the local directory - while (FALSE !== ($file = readdir($fp))) - { - if (@is_dir($locpath.$file) && substr($file, 0, 1) != '.') - { - $this->mirror($locpath.$file."/", $rempath.$file."/"); - } - elseif (substr($file, 0, 1) != ".") - { - // Get the file extension so we can se the upload type - $ext = $this->_getext($file); - $mode = $this->_settype($ext); - - $this->upload($locpath.$file, $rempath.$file, $mode); - } - } - return TRUE; - } - - return FALSE; - } - - - // -------------------------------------------------------------------- - - /** - * Extract the file extension - * - * @access private - * @param string - * @return string - */ - function _getext($filename) - { - if (FALSE === strpos($filename, '.')) - { - return 'txt'; - } - - $x = explode('.', $filename); - return end($x); - } - - - // -------------------------------------------------------------------- - - /** - * Set the upload type - * - * @access private - * @param string - * @return string - */ - function _settype($ext) - { - $text_types = array( - 'txt', - 'text', - 'php', - 'phps', - 'php4', - 'js', - 'css', - 'htm', - 'html', - 'phtml', - 'shtml', - 'log', - 'xml' - ); - - - return (in_array($ext, $text_types)) ? 'ascii' : 'binary'; - } - - // ------------------------------------------------------------------------ - - /** - * Close the connection - * - * @access public - * @param string path to source - * @param string path to destination - * @return bool - */ - function close() - { - if ( ! $this->_is_conn()) - { - return FALSE; - } - - @ftp_close($this->conn_id); - } - - // ------------------------------------------------------------------------ - - /** - * Display error message - * - * @access private - * @param string - * @return bool - */ - function _error($line) - { - $CI =& get_instance(); - $CI->lang->load('ftp'); - show_error($CI->lang->line($line)); - } - - -} -// END FTP Class - -/* End of file Ftp.php */ + 0) + { + $this->initialize($config); + } + + log_message('debug', "FTP Class Initialized"); + } + + // -------------------------------------------------------------------- + + /** + * Initialize preferences + * + * @access public + * @param array + * @return void + */ + function initialize($config = array()) + { + foreach ($config as $key => $val) + { + if (isset($this->$key)) + { + $this->$key = $val; + } + } + + // Prep the hostname + $this->hostname = preg_replace('|.+?://|', '', $this->hostname); + } + + // -------------------------------------------------------------------- + + /** + * FTP Connect + * + * @access public + * @param array the connection values + * @return bool + */ + function connect($config = array()) + { + if (count($config) > 0) + { + $this->initialize($config); + } + + if (FALSE === ($this->conn_id = @ftp_connect($this->hostname, $this->port))) + { + if ($this->debug == TRUE) + { + $this->_error('ftp_unable_to_connect'); + } + return FALSE; + } + + if ( ! $this->_login()) + { + if ($this->debug == TRUE) + { + $this->_error('ftp_unable_to_login'); + } + return FALSE; + } + + // Set passive mode if needed + if ($this->passive == TRUE) + { + ftp_pasv($this->conn_id, TRUE); + } + + return TRUE; + } + + // -------------------------------------------------------------------- + + /** + * FTP Login + * + * @access private + * @return bool + */ + function _login() + { + return @ftp_login($this->conn_id, $this->username, $this->password); + } + + // -------------------------------------------------------------------- + + /** + * Validates the connection ID + * + * @access private + * @return bool + */ + function _is_conn() + { + if ( ! is_resource($this->conn_id)) + { + if ($this->debug == TRUE) + { + $this->_error('ftp_no_connection'); + } + return FALSE; + } + return TRUE; + } + + // -------------------------------------------------------------------- + + + /** + * Change direcotry + * + * The second parameter lets us momentarily turn off debugging so that + * this function can be used to test for the existance of a folder + * without throwing an error. There's no FTP equivalent to is_dir() + * so we do it by trying to change to a particular directory. + * Internally, this paramter is only used by the "mirror" function below. + * + * @access public + * @param string + * @param bool + * @return bool + */ + function changedir($path = '', $supress_debug = FALSE) + { + if ($path == '' OR ! $this->_is_conn()) + { + return FALSE; + } + + $result = @ftp_chdir($this->conn_id, $path); + + if ($result === FALSE) + { + if ($this->debug == TRUE AND $supress_debug == FALSE) + { + $this->_error('ftp_unable_to_changedir'); + } + return FALSE; + } + + return TRUE; + } + + // -------------------------------------------------------------------- + + /** + * Create a directory + * + * @access public + * @param string + * @return bool + */ + function mkdir($path = '', $permissions = NULL) + { + if ($path == '' OR ! $this->_is_conn()) + { + return FALSE; + } + + $result = @ftp_mkdir($this->conn_id, $path); + + if ($result === FALSE) + { + if ($this->debug == TRUE) + { + $this->_error('ftp_unable_to_makdir'); + } + return FALSE; + } + + // Set file permissions if needed + if ( ! is_null($permissions)) + { + $this->chmod($path, (int)$permissions); + } + + return TRUE; + } + + // -------------------------------------------------------------------- + + /** + * Upload a file to the server + * + * @access public + * @param string + * @param string + * @param string + * @return bool + */ + function upload($locpath, $rempath, $mode = 'auto', $permissions = NULL) + { + if ( ! $this->_is_conn()) + { + return FALSE; + } + + if ( ! file_exists($locpath)) + { + $this->_error('ftp_no_source_file'); + return FALSE; + } + + // Set the mode if not specified + if ($mode == 'auto') + { + // Get the file extension so we can set the upload type + $ext = $this->_getext($locpath); + $mode = $this->_settype($ext); + } + + $mode = ($mode == 'ascii') ? FTP_ASCII : FTP_BINARY; + + $result = @ftp_put($this->conn_id, $rempath, $locpath, $mode); + + if ($result === FALSE) + { + if ($this->debug == TRUE) + { + $this->_error('ftp_unable_to_upload'); + } + return FALSE; + } + + // Set file permissions if needed + if ( ! is_null($permissions)) + { + $this->chmod($rempath, (int)$permissions); + } + + return TRUE; + } + + // -------------------------------------------------------------------- + + /** + * Rename (or move) a file + * + * @access public + * @param string + * @param string + * @param bool + * @return bool + */ + function rename($old_file, $new_file, $move = FALSE) + { + if ( ! $this->_is_conn()) + { + return FALSE; + } + + $result = @ftp_rename($this->conn_id, $old_file, $new_file); + + if ($result === FALSE) + { + if ($this->debug == TRUE) + { + $msg = ($move == FALSE) ? 'ftp_unable_to_rename' : 'ftp_unable_to_move'; + + $this->_error($msg); + } + return FALSE; + } + + return TRUE; + } + + // -------------------------------------------------------------------- + + /** + * Move a file + * + * @access public + * @param string + * @param string + * @return bool + */ + function move($old_file, $new_file) + { + return $this->rename($old_file, $new_file, TRUE); + } + + // -------------------------------------------------------------------- + + /** + * Rename (or move) a file + * + * @access public + * @param string + * @return bool + */ + function delete_file($filepath) + { + if ( ! $this->_is_conn()) + { + return FALSE; + } + + $result = @ftp_delete($this->conn_id, $filepath); + + if ($result === FALSE) + { + if ($this->debug == TRUE) + { + $this->_error('ftp_unable_to_delete'); + } + return FALSE; + } + + return TRUE; + } + + // -------------------------------------------------------------------- + + /** + * Delete a folder and recursively delete everything (including sub-folders) + * containted within it. + * + * @access public + * @param string + * @return bool + */ + function delete_dir($filepath) + { + if ( ! $this->_is_conn()) + { + return FALSE; + } + + // Add a trailing slash to the file path if needed + $filepath = preg_replace("/(.+?)\/*$/", "\\1/", $filepath); + + $list = $this->list_files($filepath); + + if ($list !== FALSE AND count($list) > 0) + { + foreach ($list as $item) + { + // If we can't delete the item it's probaly a folder so + // we'll recursively call delete_dir() + if ( ! @ftp_delete($this->conn_id, $item)) + { + $this->delete_dir($item); + } + } + } + + $result = @ftp_rmdir($this->conn_id, $filepath); + + if ($result === FALSE) + { + if ($this->debug == TRUE) + { + $this->_error('ftp_unable_to_delete'); + } + return FALSE; + } + + return TRUE; + } + + // -------------------------------------------------------------------- + + /** + * Set file permissions + * + * @access public + * @param string the file path + * @param string the permissions + * @return bool + */ + function chmod($path, $perm) + { + if ( ! $this->_is_conn()) + { + return FALSE; + } + + // Permissions can only be set when running PHP 5 + if ( ! function_exists('ftp_chmod')) + { + if ($this->debug == TRUE) + { + $this->_error('ftp_unable_to_chmod'); + } + return FALSE; + } + + $result = @ftp_chmod($this->conn_id, $perm, $path); + + if ($result === FALSE) + { + if ($this->debug == TRUE) + { + $this->_error('ftp_unable_to_chmod'); + } + return FALSE; + } + + return TRUE; + } + + // -------------------------------------------------------------------- + + /** + * FTP List files in the specified directory + * + * @access public + * @return array + */ + function list_files($path = '.') + { + if ( ! $this->_is_conn()) + { + return FALSE; + } + + return ftp_nlist($this->conn_id, $path); + } + + // ------------------------------------------------------------------------ + + /** + * Read a directory and recreate it remotely + * + * This function recursively reads a folder and everything it contains (including + * sub-folders) and creates a mirror via FTP based on it. Whatever the directory structure + * of the original file path will be recreated on the server. + * + * @access public + * @param string path to source with trailing slash + * @param string path to destination - include the base folder with trailing slash + * @return bool + */ + function mirror($locpath, $rempath) + { + if ( ! $this->_is_conn()) + { + return FALSE; + } + + // Open the local file path + if ($fp = @opendir($locpath)) + { + // Attempt to open the remote file path. + if ( ! $this->changedir($rempath, TRUE)) + { + // If it doesn't exist we'll attempt to create the direcotory + if ( ! $this->mkdir($rempath) OR ! $this->changedir($rempath)) + { + return FALSE; + } + } + + // Recursively read the local directory + while (FALSE !== ($file = readdir($fp))) + { + if (@is_dir($locpath.$file) && substr($file, 0, 1) != '.') + { + $this->mirror($locpath.$file."/", $rempath.$file."/"); + } + elseif (substr($file, 0, 1) != ".") + { + // Get the file extension so we can se the upload type + $ext = $this->_getext($file); + $mode = $this->_settype($ext); + + $this->upload($locpath.$file, $rempath.$file, $mode); + } + } + return TRUE; + } + + return FALSE; + } + + + // -------------------------------------------------------------------- + + /** + * Extract the file extension + * + * @access private + * @param string + * @return string + */ + function _getext($filename) + { + if (FALSE === strpos($filename, '.')) + { + return 'txt'; + } + + $x = explode('.', $filename); + return end($x); + } + + + // -------------------------------------------------------------------- + + /** + * Set the upload type + * + * @access private + * @param string + * @return string + */ + function _settype($ext) + { + $text_types = array( + 'txt', + 'text', + 'php', + 'phps', + 'php4', + 'js', + 'css', + 'htm', + 'html', + 'phtml', + 'shtml', + 'log', + 'xml' + ); + + + return (in_array($ext, $text_types)) ? 'ascii' : 'binary'; + } + + // ------------------------------------------------------------------------ + + /** + * Close the connection + * + * @access public + * @param string path to source + * @param string path to destination + * @return bool + */ + function close() + { + if ( ! $this->_is_conn()) + { + return FALSE; + } + + @ftp_close($this->conn_id); + } + + // ------------------------------------------------------------------------ + + /** + * Display error message + * + * @access private + * @param string + * @return bool + */ + function _error($line) + { + $CI =& get_instance(); + $CI->lang->load('ftp'); + show_error($CI->lang->line($line)); + } + + +} +// END FTP Class + +/* End of file Ftp.php */ /* Location: ./system/libraries/Ftp.php */ \ No newline at end of file diff --git a/system/libraries/Hooks.php b/system/libraries/Hooks.php index 55019e486..46f3ac478 100644 --- a/system/libraries/Hooks.php +++ b/system/libraries/Hooks.php @@ -1,226 +1,226 @@ -_initialize(); - log_message('debug', "Hooks Class Initialized"); - } - - // -------------------------------------------------------------------- - - /** - * Initialize the Hooks Preferences - * - * @access private - * @return void - */ - function _initialize() - { - $CFG =& load_class('Config'); - - // 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. - - @include(APPPATH.'config/hooks'.EXT); - - 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; - } - -} - -// END CI_Hooks class - -/* End of file Hooks.php */ +_initialize(); + log_message('debug', "Hooks Class Initialized"); + } + + // -------------------------------------------------------------------- + + /** + * Initialize the Hooks Preferences + * + * @access private + * @return void + */ + function _initialize() + { + $CFG =& load_class('Config'); + + // 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. + + @include(APPPATH.'config/hooks'.EXT); + + 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; + } + +} + +// END CI_Hooks class + +/* End of file Hooks.php */ /* Location: ./system/libraries/Hooks.php */ \ No newline at end of file diff --git a/system/libraries/Image_lib.php b/system/libraries/Image_lib.php index f260e7627..16201ee9e 100644 --- a/system/libraries/Image_lib.php +++ b/system/libraries/Image_lib.php @@ -1,1548 +1,1548 @@ - 0) - { - $this->initialize($props); - } - - log_message('debug', "Image Lib Class Initialized"); - } - - // -------------------------------------------------------------------- - - /** - * Initialize image properties - * - * Resets values in case this class is used in a loop - * - * @access public - * @return void - */ - function clear() - { - $props = array('source_folder', 'dest_folder', 'source_image', 'full_src_path', 'full_dst_path', 'new_image', 'image_type', 'size_str', 'quality', 'orig_width', 'orig_height', 'rotation_angle', 'x_axis', 'y_axis', 'create_fnc', 'copy_fnc', 'wm_overlay_path', 'wm_use_truetype', 'dynamic_output', 'wm_font_size', 'wm_text', 'wm_vrt_alignment', 'wm_hor_alignment', 'wm_padding', 'wm_hor_offset', 'wm_vrt_offset', 'wm_font_color', 'wm_use_drop_shadow', 'wm_shadow_color', 'wm_shadow_distance', 'wm_opacity'); - - foreach ($props as $val) - { - $this->$val = ''; - } - - // special consideration for master_dim - $this->master_dim = 'auto'; - } - - // -------------------------------------------------------------------- - - /** - * initialize image preferences - * - * @access public - * @param array - * @return bool - */ - function initialize($props = array()) - { - /* - * Convert array elements into class variables - */ - if (count($props) > 0) - { - foreach ($props as $key => $val) - { - $this->$key = $val; - } - } - - /* - * Is there a source image? - * - * If not, there's no reason to continue - * - */ - if ($this->source_image == '') - { - $this->set_error('imglib_source_image_required'); - return FALSE; - } - - /* - * Is getimagesize() Available? - * - * We use it to determine the image properties (width/height). - * Note: We need to figure out how to determine image - * properties using ImageMagick and NetPBM - * - */ - if ( ! function_exists('getimagesize')) - { - $this->set_error('imglib_gd_required_for_props'); - return FALSE; - } - - $this->image_library = strtolower($this->image_library); - - /* - * Set the full server path - * - * The source image may or may not contain a path. - * Either way, we'll try use realpath to generate the - * full server path in order to more reliably read it. - * - */ - if (function_exists('realpath') AND @realpath($this->source_image) !== FALSE) - { - $full_source_path = str_replace("\\", "/", realpath($this->source_image)); - } - else - { - $full_source_path = $this->source_image; - } - - $x = explode('/', $full_source_path); - $this->source_image = end($x); - $this->source_folder = str_replace($this->source_image, '', $full_source_path); - - // Set the Image Properties - if ( ! $this->get_image_properties($this->source_folder.$this->source_image)) - { - return FALSE; - } - - /* - * Assign the "new" image name/path - * - * If the user has set a "new_image" name it means - * we are making a copy of the source image. If not - * it means we are altering the original. We'll - * set the destination filename and path accordingly. - * - */ - if ($this->new_image == '') - { - $this->dest_image = $this->source_image; - $this->dest_folder = $this->source_folder; - } - else - { - if (strpos($this->new_image, '/') === FALSE) - { - $this->dest_folder = $this->source_folder; - $this->dest_image = $this->new_image; - } - else - { - if (function_exists('realpath') AND @realpath($this->new_image) !== FALSE) - { - $full_dest_path = str_replace("\\", "/", realpath($this->new_image)); - } - else - { - $full_dest_path = $this->new_image; - } - - // Is there a file name? - if ( ! preg_match("#\.(jpg|jpeg|gif|png)$#i", $full_dest_path)) - { - $this->dest_folder = $full_dest_path.'/'; - $this->dest_image = $this->source_image; - } - else - { - $x = explode('/', $full_dest_path); - $this->dest_image = end($x); - $this->dest_folder = str_replace($this->dest_image, '', $full_dest_path); - } - } - } - - /* - * Compile the finalized filenames/paths - * - * We'll create two master strings containing the - * full server path to the source image and the - * full server path to the destination image. - * We'll also split the destination image name - * so we can insert the thumbnail marker if needed. - * - */ - if ($this->create_thumb === FALSE OR $this->thumb_marker == '') - { - $this->thumb_marker = ''; - } - - $xp = $this->explode_name($this->dest_image); - - $filename = $xp['name']; - $file_ext = $xp['ext']; - - $this->full_src_path = $this->source_folder.$this->source_image; - $this->full_dst_path = $this->dest_folder.$filename.$this->thumb_marker.$file_ext; - - /* - * Should we maintain image proportions? - * - * When creating thumbs or copies, the target width/height - * might not be in correct proportion with the source - * image's width/height. We'll recalculate it here. - * - */ - if ($this->maintain_ratio === TRUE && ($this->width != '' AND $this->height != '')) - { - $this->image_reproportion(); - } - - /* - * Was a width and height specified? - * - * If the destination width/height was - * not submitted we will use the values - * from the actual file - * - */ - if ($this->width == '') - $this->width = $this->orig_width; - - if ($this->height == '') - $this->height = $this->orig_height; - - // Set the quality - $this->quality = trim(str_replace("%", "", $this->quality)); - - if ($this->quality == '' OR $this->quality == 0 OR ! is_numeric($this->quality)) - $this->quality = 90; - - // Set the x/y coordinates - $this->x_axis = ($this->x_axis == '' OR ! is_numeric($this->x_axis)) ? 0 : $this->x_axis; - $this->y_axis = ($this->y_axis == '' OR ! is_numeric($this->y_axis)) ? 0 : $this->y_axis; - - // Watermark-related Stuff... - if ($this->wm_font_color != '') - { - if (strlen($this->wm_font_color) == 6) - { - $this->wm_font_color = '#'.$this->wm_font_color; - } - } - - if ($this->wm_shadow_color != '') - { - if (strlen($this->wm_shadow_color) == 6) - { - $this->wm_shadow_color = '#'.$this->wm_shadow_color; - } - } - - if ($this->wm_overlay_path != '') - { - $this->wm_overlay_path = str_replace("\\", "/", realpath($this->wm_overlay_path)); - } - - if ($this->wm_shadow_color != '') - { - $this->wm_use_drop_shadow = TRUE; - } - - if ($this->wm_font_path != '') - { - $this->wm_use_truetype = TRUE; - } - - return TRUE; - } - - // -------------------------------------------------------------------- - - /** - * Image Resize - * - * This is a wrapper function that chooses the proper - * resize function based on the protocol specified - * - * @access public - * @return bool - */ - function resize() - { - $protocol = 'image_process_'.$this->image_library; - - if (eregi("gd2$", $protocol)) - { - $protocol = 'image_process_gd'; - } - - return $this->$protocol('resize'); - } - - // -------------------------------------------------------------------- - - /** - * Image Crop - * - * This is a wrapper function that chooses the proper - * cropping function based on the protocol specified - * - * @access public - * @return bool - */ - function crop() - { - $protocol = 'image_process_'.$this->image_library; - - if (eregi("gd2$", $protocol)) - { - $protocol = 'image_process_gd'; - } - - return $this->$protocol('crop'); - } - - // -------------------------------------------------------------------- - - /** - * Image Rotate - * - * This is a wrapper function that chooses the proper - * rotation function based on the protocol specified - * - * @access public - * @return bool - */ - function rotate() - { - // Allowed rotation values - $degs = array(90, 180, 270, 'vrt', 'hor'); - - if ($this->rotation_angle == '' OR ! in_array($this->rotation_angle, $degs, TRUE)) - { - $this->set_error('imglib_rotation_angle_required'); - return FALSE; - } - - // Reassign the width and height - if ($this->rotation_angle == 90 OR $this->rotation_angle == 270) - { - $this->width = $this->orig_height; - $this->height = $this->orig_width; - } - else - { - $this->width = $this->orig_width; - $this->height = $this->orig_height; - } - - - // Choose resizing function - if ($this->image_library == 'imagemagick' OR $this->image_library == 'netpbm') - { - $protocol = 'image_process_'.$this->image_library; - - return $this->$protocol('rotate'); - } - - if ($this->rotation_angle == 'hor' OR $this->rotation_angle == 'vrt') - { - return $this->image_mirror_gd(); - } - else - { - return $this->image_rotate_gd(); - } - } - - // -------------------------------------------------------------------- - - /** - * Image Process Using GD/GD2 - * - * This function will resize or crop - * - * @access public - * @param string - * @return bool - */ - function image_process_gd($action = 'resize') - { - $v2_override = FALSE; - - // If the target width/height match the source, AND if the new file name is not equal to the old file name - // we'll simply make a copy of the original with the new name... assuming dynamic rendering is off. - if ($this->dynamic_output === FALSE) - { - if ($this->orig_width == $this->width AND $this->orig_height == $this->height) - { - if ($this->source_image != $this->new_image) - { - if (@copy($this->full_src_path, $this->full_dst_path)) - { - @chmod($this->full_dst_path, DIR_WRITE_MODE); - } - } - - return TRUE; - } - } - - // Let's set up our values based on the action - if ($action == 'crop') - { - // Reassign the source width/height if cropping - $this->orig_width = $this->width; - $this->orig_height = $this->height; - - // GD 2.0 has a cropping bug so we'll test for it - if ($this->gd_version() !== FALSE) - { - $gd_version = str_replace('0', '', $this->gd_version()); - $v2_override = ($gd_version == 2) ? TRUE : FALSE; - } - } - else - { - // If resizing the x/y axis must be zero - $this->x_axis = 0; - $this->y_axis = 0; - } - - // Create the image handle - if ( ! ($src_img = $this->image_create_gd())) - { - return FALSE; - } - - // Create The Image - // - // old conditional which users report cause problems with shared GD libs who report themselves as "2.0 or greater" - // it appears that this is no longer the issue that it was in 2004, so we've removed it, retaining it in the comment - // below should that ever prove inaccurate. - // - // if ($this->image_library == 'gd2' AND function_exists('imagecreatetruecolor') AND $v2_override == FALSE) - if ($this->image_library == 'gd2' AND function_exists('imagecreatetruecolor')) - { - $create = 'imagecreatetruecolor'; - $copy = 'imagecopyresampled'; - } - else - { - $create = 'imagecreate'; - $copy = 'imagecopyresized'; - } - - $dst_img = $create($this->width, $this->height); - $copy($dst_img, $src_img, 0, 0, $this->x_axis, $this->y_axis, $this->width, $this->height, $this->orig_width, $this->orig_height); - - // Show the image - if ($this->dynamic_output == TRUE) - { - $this->image_display_gd($dst_img); - } - else - { - // Or save it - if ( ! $this->image_save_gd($dst_img)) - { - return FALSE; - } - } - - // Kill the file handles - imagedestroy($dst_img); - imagedestroy($src_img); - - // Set the file to 777 - @chmod($this->full_dst_path, DIR_WRITE_MODE); - - return TRUE; - } - - // -------------------------------------------------------------------- - - /** - * Image Process Using ImageMagick - * - * This function will resize, crop or rotate - * - * @access public - * @param string - * @return bool - */ - function image_process_imagemagick($action = 'resize') - { - // Do we have a vaild library path? - if ($this->library_path == '') - { - $this->set_error('imglib_libpath_invalid'); - return FALSE; - } - - if ( ! eregi("convert$", $this->library_path)) - { - if ( ! eregi("/$", $this->library_path)) $this->library_path .= "/"; - - $this->library_path .= 'convert'; - } - - // Execute the command - $cmd = $this->library_path." -quality ".$this->quality; - - if ($action == 'crop') - { - $cmd .= " -crop ".$this->width."x".$this->height."+".$this->x_axis."+".$this->y_axis." \"$this->full_src_path\" \"$this->full_dst_path\" 2>&1"; - } - elseif ($action == 'rotate') - { - switch ($this->rotation_angle) - { - case 'hor' : $angle = '-flop'; - break; - case 'vrt' : $angle = '-flip'; - break; - default : $angle = '-rotate '.$this->rotation_angle; - break; - } - - $cmd .= " ".$angle." \"$this->full_src_path\" \"$this->full_dst_path\" 2>&1"; - } - else // Resize - { - $cmd .= " -resize ".$this->width."x".$this->height." \"$this->full_src_path\" \"$this->full_dst_path\" 2>&1"; - } - - $retval = 1; - - @exec($cmd, $output, $retval); - - // Did it work? - if ($retval > 0) - { - $this->set_error('imglib_image_process_failed'); - return FALSE; - } - - // Set the file to 777 - @chmod($this->full_dst_path, DIR_WRITE_MODE); - - return TRUE; - } - - // -------------------------------------------------------------------- - - /** - * Image Process Using NetPBM - * - * This function will resize, crop or rotate - * - * @access public - * @param string - * @return bool - */ - function image_process_netpbm($action = 'resize') - { - if ($this->library_path == '') - { - $this->set_error('imglib_libpath_invalid'); - return FALSE; - } - - // Build the resizing command - switch ($this->image_type) - { - case 1 : - $cmd_in = 'giftopnm'; - $cmd_out = 'ppmtogif'; - break; - case 2 : - $cmd_in = 'jpegtopnm'; - $cmd_out = 'ppmtojpeg'; - break; - case 3 : - $cmd_in = 'pngtopnm'; - $cmd_out = 'ppmtopng'; - break; - } - - if ($action == 'crop') - { - $cmd_inner = 'pnmcut -left '.$this->x_axis.' -top '.$this->y_axis.' -width '.$this->width.' -height '.$this->height; - } - elseif ($action == 'rotate') - { - switch ($this->rotation_angle) - { - case 90 : $angle = 'r270'; - break; - case 180 : $angle = 'r180'; - break; - case 270 : $angle = 'r90'; - break; - case 'vrt' : $angle = 'tb'; - break; - case 'hor' : $angle = 'lr'; - break; - } - - $cmd_inner = 'pnmflip -'.$angle.' '; - } - else // Resize - { - $cmd_inner = 'pnmscale -xysize '.$this->width.' '.$this->height; - } - - $cmd = $this->library_path.$cmd_in.' '.$this->full_src_path.' | '.$cmd_inner.' | '.$cmd_out.' > '.$this->dest_folder.'netpbm.tmp'; - - $retval = 1; - - @exec($cmd, $output, $retval); - - // Did it work? - if ($retval > 0) - { - $this->set_error('imglib_image_process_failed'); - return FALSE; - } - - // With NetPBM we have to create a temporary image. - // If you try manipulating the original it fails so - // we have to rename the temp file. - copy ($this->dest_folder.'netpbm.tmp', $this->full_dst_path); - unlink ($this->dest_folder.'netpbm.tmp'); - @chmod($this->full_dst_path, DIR_WRITE_MODE); - - return TRUE; - } - - // -------------------------------------------------------------------- - - /** - * Image Rotate Using GD - * - * @access public - * @return bool - */ - function image_rotate_gd() - { - // Is Image Rotation Supported? - // this function is only supported as of PHP 4.3 - if ( ! function_exists('imagerotate')) - { - $this->set_error('imglib_rotate_unsupported'); - return FALSE; - } - - // Create the image handle - if ( ! ($src_img = $this->image_create_gd())) - { - return FALSE; - } - - // Set the background color - // This won't work with transparent PNG files so we are - // going to have to figure out how to determine the color - // of the alpha channel in a future release. - - $white = imagecolorallocate($src_img, 255, 255, 255); - - // Rotate it! - $dst_img = imagerotate($src_img, $this->rotation_angle, $white); - - // Save the Image - if ($this->dynamic_output == TRUE) - { - $this->image_display_gd($dst_img); - } - else - { - // Or save it - if ( ! $this->image_save_gd($dst_img)) - { - return FALSE; - } - } - - // Kill the file handles - imagedestroy($dst_img); - imagedestroy($src_img); - - // Set the file to 777 - - @chmod($this->full_dst_path, DIR_WRITE_MODE); - - return true; - } - - // -------------------------------------------------------------------- - - /** - * Create Mirror Image using GD - * - * This function will flip horizontal or vertical - * - * @access public - * @return bool - */ - function image_mirror_gd() - { - if ( ! $src_img = $this->image_create_gd()) - { - return FALSE; - } - - $width = $this->orig_width; - $height = $this->orig_height; - - if ($this->rotation_angle == 'hor') - { - for ($i = 0; $i < $height; $i++) - { - $left = 0; - $right = $width-1; - - while ($left < $right) - { - $cl = imagecolorat($src_img, $left, $i); - $cr = imagecolorat($src_img, $right, $i); - - imagesetpixel($src_img, $left, $i, $cr); - imagesetpixel($src_img, $right, $i, $cl); - - $left++; - $right--; - } - } - } - else - { - for ($i = 0; $i < $width; $i++) - { - $top = 0; - $bot = $height-1; - - while ($top < $bot) - { - $ct = imagecolorat($src_img, $i, $top); - $cb = imagecolorat($src_img, $i, $bot); - - imagesetpixel($src_img, $i, $top, $cb); - imagesetpixel($src_img, $i, $bot, $ct); - - $top++; - $bot--; - } - } - } - - // Show the image - if ($this->dynamic_output == TRUE) - { - $this->image_display_gd($src_img); - } - else - { - // Or save it - if ( ! $this->image_save_gd($src_img)) - { - return FALSE; - } - } - - // Kill the file handles - imagedestroy($src_img); - - // Set the file to 777 - @chmod($this->full_dst_path, DIR_WRITE_MODE); - - return TRUE; - } - - // -------------------------------------------------------------------- - - /** - * Image Watermark - * - * This is a wrapper function that chooses the type - * of watermarking based on the specified preference. - * - * @access public - * @param string - * @return bool - */ - function watermark() - { - if ($this->wm_type == 'overlay') - { - return $this->overlay_watermark(); - } - else - { - return $this->text_watermark(); - } - } - - // -------------------------------------------------------------------- - - /** - * Watermark - Graphic Version - * - * @access public - * @return bool - */ - function overlay_watermark() - { - if ( ! function_exists('imagecolortransparent')) - { - $this->set_error('imglib_gd_required'); - return FALSE; - } - - // Fetch source image properties - $this->get_image_properties(); - - // Fetch watermark image properties - $props = $this->get_image_properties($this->wm_overlay_path, TRUE); - $wm_img_type = $props['image_type']; - $wm_width = $props['width']; - $wm_height = $props['height']; - - // Create two image resources - $wm_img = $this->image_create_gd($this->wm_overlay_path, $wm_img_type); - $src_img = $this->image_create_gd($this->full_src_path); - - // Reverse the offset if necessary - // When the image is positioned at the bottom - // we don't want the vertical offset to push it - // further down. We want the reverse, so we'll - // invert the offset. Same with the horizontal - // offset when the image is at the right - - $this->wm_vrt_alignment = strtoupper(substr($this->wm_vrt_alignment, 0, 1)); - $this->wm_hor_alignment = strtoupper(substr($this->wm_hor_alignment, 0, 1)); - - if ($this->wm_vrt_alignment == 'B') - $this->wm_vrt_offset = $this->wm_vrt_offset * -1; - - if ($this->wm_hor_alignment == 'R') - $this->wm_hor_offset = $this->wm_hor_offset * -1; - - // Set the base x and y axis values - $x_axis = $this->wm_hor_offset + $this->wm_padding; - $y_axis = $this->wm_vrt_offset + $this->wm_padding; - - // Set the vertical position - switch ($this->wm_vrt_alignment) - { - case 'T': - break; - case 'M': $y_axis += ($this->orig_height / 2) - ($wm_height / 2); - break; - case 'B': $y_axis += $this->orig_height - $wm_height; - break; - } - - // Set the horizontal position - switch ($this->wm_hor_alignment) - { - case 'L': - break; - case 'C': $x_axis += ($this->orig_width / 2) - ($wm_width / 2); - break; - case 'R': $x_axis += $this->orig_width - $wm_width; - break; - } - - // Build the finalized image - if ($wm_img_type == 3 AND function_exists('imagealphablending')) - { - @imagealphablending($src_img, TRUE); - } - - // Set RGB values for text and shadow - $rgba = imagecolorat($wm_img, $this->wm_x_transp, $this->wm_y_transp); - $alpha = ($rgba & 0x7F000000) >> 24; - - // make a best guess as to whether we're dealing with an image with alpha transparency or no/binary transparency - if ($alpha > 0) - { - // copy the image directly, the image's alpha transparency being the sole determinant of blending - imagecopy($src_img, $wm_img, $x_axis, $y_axis, 0, 0, $wm_width, $wm_height); - } - else - { - // set our RGB value from above to be transparent and merge the images with the specified opacity - imagecolortransparent($wm_img, imagecolorat($wm_img, $this->wm_x_transp, $this->wm_y_transp)); - imagecopymerge($src_img, $wm_img, $x_axis, $y_axis, 0, 0, $wm_width, $wm_height, $this->wm_opacity); - } - - // Output the image - if ($this->dynamic_output == TRUE) - { - $this->image_display_gd($src_img); - } - else - { - if ( ! $this->image_save_gd($src_img)) - { - return FALSE; - } - } - - imagedestroy($src_img); - imagedestroy($wm_img); - - return TRUE; - } - - // -------------------------------------------------------------------- - - /** - * Watermark - Text Version - * - * @access public - * @return bool - */ - function text_watermark() - { - if ( ! ($src_img = $this->image_create_gd())) - { - return FALSE; - } - - if ($this->wm_use_truetype == TRUE AND ! file_exists($this->wm_font_path)) - { - $this->set_error('imglib_missing_font'); - return FALSE; - } - - // Fetch source image properties - $this->get_image_properties(); - - // Set RGB values for text and shadow - $this->wm_font_color = str_replace('#', '', $this->wm_font_color); - $this->wm_shadow_color = str_replace('#', '', $this->wm_shadow_color); - - $R1 = hexdec(substr($this->wm_font_color, 0, 2)); - $G1 = hexdec(substr($this->wm_font_color, 2, 2)); - $B1 = hexdec(substr($this->wm_font_color, 4, 2)); - - $R2 = hexdec(substr($this->wm_shadow_color, 0, 2)); - $G2 = hexdec(substr($this->wm_shadow_color, 2, 2)); - $B2 = hexdec(substr($this->wm_shadow_color, 4, 2)); - - $txt_color = imagecolorclosest($src_img, $R1, $G1, $B1); - $drp_color = imagecolorclosest($src_img, $R2, $G2, $B2); - - // Reverse the vertical offset - // When the image is positioned at the bottom - // we don't want the vertical offset to push it - // further down. We want the reverse, so we'll - // invert the offset. Note: The horizontal - // offset flips itself automatically - - if ($this->wm_vrt_alignment == 'B') - $this->wm_vrt_offset = $this->wm_vrt_offset * -1; - - if ($this->wm_hor_alignment == 'R') - $this->wm_hor_offset = $this->wm_hor_offset * -1; - - // Set font width and height - // These are calculated differently depending on - // whether we are using the true type font or not - if ($this->wm_use_truetype == TRUE) - { - if ($this->wm_font_size == '') - $this->wm_font_size = '17'; - - $fontwidth = $this->wm_font_size-($this->wm_font_size/4); - $fontheight = $this->wm_font_size; - $this->wm_vrt_offset += $this->wm_font_size; - } - else - { - $fontwidth = imagefontwidth($this->wm_font_size); - $fontheight = imagefontheight($this->wm_font_size); - } - - // Set base X and Y axis values - $x_axis = $this->wm_hor_offset + $this->wm_padding; - $y_axis = $this->wm_vrt_offset + $this->wm_padding; - - // Set verticle alignment - if ($this->wm_use_drop_shadow == FALSE) - $this->wm_shadow_distance = 0; - - $this->wm_vrt_alignment = strtoupper(substr($this->wm_vrt_alignment, 0, 1)); - $this->wm_hor_alignment = strtoupper(substr($this->wm_hor_alignment, 0, 1)); - - switch ($this->wm_vrt_alignment) - { - case "T" : - break; - case "M": $y_axis += ($this->orig_height/2)+($fontheight/2); - break; - case "B": $y_axis += ($this->orig_height - $fontheight - $this->wm_shadow_distance - ($fontheight/2)); - break; - } - - $x_shad = $x_axis + $this->wm_shadow_distance; - $y_shad = $y_axis + $this->wm_shadow_distance; - - // Set horizontal alignment - switch ($this->wm_hor_alignment) - { - case "L": - break; - case "R": - if ($this->wm_use_drop_shadow) - $x_shad += ($this->orig_width - $fontwidth*strlen($this->wm_text)); - $x_axis += ($this->orig_width - $fontwidth*strlen($this->wm_text)); - break; - case "C": - if ($this->wm_use_drop_shadow) - $x_shad += floor(($this->orig_width - $fontwidth*strlen($this->wm_text))/2); - $x_axis += floor(($this->orig_width -$fontwidth*strlen($this->wm_text))/2); - break; - } - - // Add the text to the source image - if ($this->wm_use_truetype) - { - if ($this->wm_use_drop_shadow) - imagettftext($src_img, $this->wm_font_size, 0, $x_shad, $y_shad, $drp_color, $this->wm_font_path, $this->wm_text); - imagettftext($src_img, $this->wm_font_size, 0, $x_axis, $y_axis, $txt_color, $this->wm_font_path, $this->wm_text); - } - else - { - if ($this->wm_use_drop_shadow) - imagestring($src_img, $this->wm_font_size, $x_shad, $y_shad, $this->wm_text, $drp_color); - imagestring($src_img, $this->wm_font_size, $x_axis, $y_axis, $this->wm_text, $txt_color); - } - - // Output the final image - if ($this->dynamic_output == TRUE) - { - $this->image_display_gd($src_img); - } - else - { - $this->image_save_gd($src_img); - } - - imagedestroy($src_img); - - return TRUE; - } - - // -------------------------------------------------------------------- - - /** - * Create Image - GD - * - * This simply creates an image resource handle - * based on the type of image being processed - * - * @access public - * @param string - * @return resource - */ - function image_create_gd($path = '', $image_type = '') - { - if ($path == '') - $path = $this->full_src_path; - - if ($image_type == '') - $image_type = $this->image_type; - - - switch ($image_type) - { - case 1 : - if ( ! function_exists('imagecreatefromgif')) - { - $this->set_error(array('imglib_unsupported_imagecreate', 'imglib_gif_not_supported')); - return FALSE; - } - - return imagecreatefromgif($path); - break; - case 2 : - if ( ! function_exists('imagecreatefromjpeg')) - { - $this->set_error(array('imglib_unsupported_imagecreate', 'imglib_jpg_not_supported')); - return FALSE; - } - - return imagecreatefromjpeg($path); - break; - case 3 : - if ( ! function_exists('imagecreatefrompng')) - { - $this->set_error(array('imglib_unsupported_imagecreate', 'imglib_png_not_supported')); - return FALSE; - } - - return imagecreatefrompng($path); - break; - - } - - $this->set_error(array('imglib_unsupported_imagecreate')); - return FALSE; - } - - // -------------------------------------------------------------------- - - /** - * Write image file to disk - GD - * - * Takes an image resource as input and writes the file - * to the specified destination - * - * @access public - * @param resource - * @return bool - */ - function image_save_gd($resource) - { - switch ($this->image_type) - { - case 1 : - if ( ! function_exists('imagegif')) - { - $this->set_error(array('imglib_unsupported_imagecreate', 'imglib_gif_not_supported')); - return FALSE; - } - - @imagegif($resource, $this->full_dst_path); - break; - case 2 : - if ( ! function_exists('imagejpeg')) - { - $this->set_error(array('imglib_unsupported_imagecreate', 'imglib_jpg_not_supported')); - return FALSE; - } - - if (phpversion() == '4.4.1') - { - @touch($this->full_dst_path); // PHP 4.4.1 bug #35060 - workaround - } - - @imagejpeg($resource, $this->full_dst_path, $this->quality); - break; - case 3 : - if ( ! function_exists('imagepng')) - { - $this->set_error(array('imglib_unsupported_imagecreate', 'imglib_png_not_supported')); - return FALSE; - } - - @imagepng($resource, $this->full_dst_path); - break; - default : - $this->set_error(array('imglib_unsupported_imagecreate')); - return FALSE; - break; - } - - return TRUE; - } - - // -------------------------------------------------------------------- - - /** - * Dynamically outputs an image - * - * @access public - * @param resource - * @return void - */ - function image_display_gd($resource) - { - header("Content-Disposition: filename={$this->source_image};"); - header("Content-Type: {$this->mime_type}"); - header('Content-Transfer-Encoding: binary'); - header('Last-Modified: '.gmdate('D, d M Y H:i:s', time()).' GMT'); - - switch ($this->image_type) - { - case 1 : imagegif($resource); - break; - case 2 : imagejpeg($resource, '', $this->quality); - break; - case 3 : imagepng($resource); - break; - default : echo 'Unable to display the image'; - break; - } - } - - // -------------------------------------------------------------------- - - /** - * Re-proportion Image Width/Height - * - * When creating thumbs, the desired width/height - * can end up warping the image due to an incorrect - * ratio between the full-sized image and the thumb. - * - * This function lets us re-proportion the width/height - * if users choose to maintain the aspect ratio when resizing. - * - * @access public - * @return void - */ - function image_reproportion() - { - if ( ! is_numeric($this->width) OR ! is_numeric($this->height) OR $this->width == 0 OR $this->height == 0) - return; - - if ( ! is_numeric($this->orig_width) OR ! is_numeric($this->orig_height) OR $this->orig_width == 0 OR $this->orig_height == 0) - return; - - $new_width = ceil($this->orig_width*$this->height/$this->orig_height); - $new_height = ceil($this->width*$this->orig_height/$this->orig_width); - - $ratio = (($this->orig_height/$this->orig_width) - ($this->height/$this->width)); - - if ($this->master_dim != 'width' AND $this->master_dim != 'height') - { - $this->master_dim = ($ratio < 0) ? 'width' : 'height'; - } - - if (($this->width != $new_width) AND ($this->height != $new_height)) - { - if ($this->master_dim == 'height') - { - $this->width = $new_width; - } - else - { - $this->height = $new_height; - } - } - } - - // -------------------------------------------------------------------- - - /** - * Get image properties - * - * A helper function that gets info about the file - * - * @access public - * @param string - * @return mixed - */ - function get_image_properties($path = '', $return = FALSE) - { - // For now we require GD but we should - // find a way to determine this using IM or NetPBM - - if ($path == '') - $path = $this->full_src_path; - - if ( ! file_exists($path)) - { - $this->set_error('imglib_invalid_path'); - return FALSE; - } - - $vals = @getimagesize($path); - - $types = array(1 => 'gif', 2 => 'jpeg', 3 => 'png'); - - $mime = (isset($types[$vals['2']])) ? 'image/'.$types[$vals['2']] : 'image/jpg'; - - if ($return == TRUE) - { - $v['width'] = $vals['0']; - $v['height'] = $vals['1']; - $v['image_type'] = $vals['2']; - $v['size_str'] = $vals['3']; - $v['mime_type'] = $mime; - - return $v; - } - - $this->orig_width = $vals['0']; - $this->orig_height = $vals['1']; - $this->image_type = $vals['2']; - $this->size_str = $vals['3']; - $this->mime_type = $mime; - - return TRUE; - } - - // -------------------------------------------------------------------- - - /** - * Size calculator - * - * This function takes a known width x height and - * recalculates it to a new size. Only one - * new variable needs to be known - * - * $props = array( - * 'width' => $width, - * 'height' => $height, - * 'new_width' => 40, - * 'new_height' => '' - * ); - * - * @access public - * @param array - * @return array - */ - function size_calculator($vals) - { - if ( ! is_array($vals)) - { - return; - } - - $allowed = array('new_width', 'new_height', 'width', 'height'); - - foreach ($allowed as $item) - { - if ( ! isset($vals[$item]) OR $vals[$item] == '') - $vals[$item] = 0; - } - - if ($vals['width'] == 0 OR $vals['height'] == 0) - { - return $vals; - } - - if ($vals['new_width'] == 0) - { - $vals['new_width'] = ceil($vals['width']*$vals['new_height']/$vals['height']); - } - elseif ($vals['new_height'] == 0) - { - $vals['new_height'] = ceil($vals['new_width']*$vals['height']/$vals['width']); - } - - return $vals; - } - - // -------------------------------------------------------------------- - - /** - * Explode source_image - * - * This is a helper function that extracts the extension - * from the source_image. This function lets us deal with - * source_images with multiple periods, like: my.cool.jpg - * It returns an associative array with two elements: - * $array['ext'] = '.jpg'; - * $array['name'] = 'my.cool'; - * - * @access public - * @param array - * @return array - */ - function explode_name($source_image) - { - $x = explode('.', $source_image); - $ret['ext'] = '.'.end($x); - - $name = ''; - - $ct = count($x)-1; - - for ($i = 0; $i < $ct; $i++) - { - $name .= $x[$i]; - - if ($i < ($ct - 1)) - { - $name .= '.'; - } - } - - $ret['name'] = $name; - - return $ret; - } - - // -------------------------------------------------------------------- - - /** - * Is GD Installed? - * - * @access public - * @return bool - */ - function gd_loaded() - { - if ( ! extension_loaded('gd')) - { - if ( ! dl('gd.so')) - { - return FALSE; - } - } - - return TRUE; - } - - // -------------------------------------------------------------------- - - /** - * Get GD version - * - * @access public - * @return mixed - */ - function gd_version() - { - if (function_exists('gd_info')) - { - $gd_version = @gd_info(); - $gd_version = preg_replace("/\D/", "", $gd_version['GD Version']); - - return $gd_version; - } - - return FALSE; - } - - // -------------------------------------------------------------------- - - /** - * Set error message - * - * @access public - * @param string - * @return void - */ - function set_error($msg) - { - $CI =& get_instance(); - $CI->lang->load('imglib'); - - if (is_array($msg)) - { - foreach ($msg as $val) - { - - $msg = ($CI->lang->line($val) == FALSE) ? $val : $CI->lang->line($val); - $this->error_msg[] = $msg; - log_message('error', $msg); - } - } - else - { - $msg = ($CI->lang->line($msg) == FALSE) ? $msg : $CI->lang->line($msg); - $this->error_msg[] = $msg; - log_message('error', $msg); - } - } - - // -------------------------------------------------------------------- - - /** - * Show error messages - * - * @access public - * @param string - * @return string - */ - function display_errors($open = '

    ', $close = '

    ') - { - $str = ''; - foreach ($this->error_msg as $val) - { - $str .= $open.$val.$close; - } - - return $str; - } - -} -// END Image_lib Class - -/* End of file Image_lib.php */ + 0) + { + $this->initialize($props); + } + + log_message('debug', "Image Lib Class Initialized"); + } + + // -------------------------------------------------------------------- + + /** + * Initialize image properties + * + * Resets values in case this class is used in a loop + * + * @access public + * @return void + */ + function clear() + { + $props = array('source_folder', 'dest_folder', 'source_image', 'full_src_path', 'full_dst_path', 'new_image', 'image_type', 'size_str', 'quality', 'orig_width', 'orig_height', 'rotation_angle', 'x_axis', 'y_axis', 'create_fnc', 'copy_fnc', 'wm_overlay_path', 'wm_use_truetype', 'dynamic_output', 'wm_font_size', 'wm_text', 'wm_vrt_alignment', 'wm_hor_alignment', 'wm_padding', 'wm_hor_offset', 'wm_vrt_offset', 'wm_font_color', 'wm_use_drop_shadow', 'wm_shadow_color', 'wm_shadow_distance', 'wm_opacity'); + + foreach ($props as $val) + { + $this->$val = ''; + } + + // special consideration for master_dim + $this->master_dim = 'auto'; + } + + // -------------------------------------------------------------------- + + /** + * initialize image preferences + * + * @access public + * @param array + * @return bool + */ + function initialize($props = array()) + { + /* + * Convert array elements into class variables + */ + if (count($props) > 0) + { + foreach ($props as $key => $val) + { + $this->$key = $val; + } + } + + /* + * Is there a source image? + * + * If not, there's no reason to continue + * + */ + if ($this->source_image == '') + { + $this->set_error('imglib_source_image_required'); + return FALSE; + } + + /* + * Is getimagesize() Available? + * + * We use it to determine the image properties (width/height). + * Note: We need to figure out how to determine image + * properties using ImageMagick and NetPBM + * + */ + if ( ! function_exists('getimagesize')) + { + $this->set_error('imglib_gd_required_for_props'); + return FALSE; + } + + $this->image_library = strtolower($this->image_library); + + /* + * Set the full server path + * + * The source image may or may not contain a path. + * Either way, we'll try use realpath to generate the + * full server path in order to more reliably read it. + * + */ + if (function_exists('realpath') AND @realpath($this->source_image) !== FALSE) + { + $full_source_path = str_replace("\\", "/", realpath($this->source_image)); + } + else + { + $full_source_path = $this->source_image; + } + + $x = explode('/', $full_source_path); + $this->source_image = end($x); + $this->source_folder = str_replace($this->source_image, '', $full_source_path); + + // Set the Image Properties + if ( ! $this->get_image_properties($this->source_folder.$this->source_image)) + { + return FALSE; + } + + /* + * Assign the "new" image name/path + * + * If the user has set a "new_image" name it means + * we are making a copy of the source image. If not + * it means we are altering the original. We'll + * set the destination filename and path accordingly. + * + */ + if ($this->new_image == '') + { + $this->dest_image = $this->source_image; + $this->dest_folder = $this->source_folder; + } + else + { + if (strpos($this->new_image, '/') === FALSE) + { + $this->dest_folder = $this->source_folder; + $this->dest_image = $this->new_image; + } + else + { + if (function_exists('realpath') AND @realpath($this->new_image) !== FALSE) + { + $full_dest_path = str_replace("\\", "/", realpath($this->new_image)); + } + else + { + $full_dest_path = $this->new_image; + } + + // Is there a file name? + if ( ! preg_match("#\.(jpg|jpeg|gif|png)$#i", $full_dest_path)) + { + $this->dest_folder = $full_dest_path.'/'; + $this->dest_image = $this->source_image; + } + else + { + $x = explode('/', $full_dest_path); + $this->dest_image = end($x); + $this->dest_folder = str_replace($this->dest_image, '', $full_dest_path); + } + } + } + + /* + * Compile the finalized filenames/paths + * + * We'll create two master strings containing the + * full server path to the source image and the + * full server path to the destination image. + * We'll also split the destination image name + * so we can insert the thumbnail marker if needed. + * + */ + if ($this->create_thumb === FALSE OR $this->thumb_marker == '') + { + $this->thumb_marker = ''; + } + + $xp = $this->explode_name($this->dest_image); + + $filename = $xp['name']; + $file_ext = $xp['ext']; + + $this->full_src_path = $this->source_folder.$this->source_image; + $this->full_dst_path = $this->dest_folder.$filename.$this->thumb_marker.$file_ext; + + /* + * Should we maintain image proportions? + * + * When creating thumbs or copies, the target width/height + * might not be in correct proportion with the source + * image's width/height. We'll recalculate it here. + * + */ + if ($this->maintain_ratio === TRUE && ($this->width != '' AND $this->height != '')) + { + $this->image_reproportion(); + } + + /* + * Was a width and height specified? + * + * If the destination width/height was + * not submitted we will use the values + * from the actual file + * + */ + if ($this->width == '') + $this->width = $this->orig_width; + + if ($this->height == '') + $this->height = $this->orig_height; + + // Set the quality + $this->quality = trim(str_replace("%", "", $this->quality)); + + if ($this->quality == '' OR $this->quality == 0 OR ! is_numeric($this->quality)) + $this->quality = 90; + + // Set the x/y coordinates + $this->x_axis = ($this->x_axis == '' OR ! is_numeric($this->x_axis)) ? 0 : $this->x_axis; + $this->y_axis = ($this->y_axis == '' OR ! is_numeric($this->y_axis)) ? 0 : $this->y_axis; + + // Watermark-related Stuff... + if ($this->wm_font_color != '') + { + if (strlen($this->wm_font_color) == 6) + { + $this->wm_font_color = '#'.$this->wm_font_color; + } + } + + if ($this->wm_shadow_color != '') + { + if (strlen($this->wm_shadow_color) == 6) + { + $this->wm_shadow_color = '#'.$this->wm_shadow_color; + } + } + + if ($this->wm_overlay_path != '') + { + $this->wm_overlay_path = str_replace("\\", "/", realpath($this->wm_overlay_path)); + } + + if ($this->wm_shadow_color != '') + { + $this->wm_use_drop_shadow = TRUE; + } + + if ($this->wm_font_path != '') + { + $this->wm_use_truetype = TRUE; + } + + return TRUE; + } + + // -------------------------------------------------------------------- + + /** + * Image Resize + * + * This is a wrapper function that chooses the proper + * resize function based on the protocol specified + * + * @access public + * @return bool + */ + function resize() + { + $protocol = 'image_process_'.$this->image_library; + + if (eregi("gd2$", $protocol)) + { + $protocol = 'image_process_gd'; + } + + return $this->$protocol('resize'); + } + + // -------------------------------------------------------------------- + + /** + * Image Crop + * + * This is a wrapper function that chooses the proper + * cropping function based on the protocol specified + * + * @access public + * @return bool + */ + function crop() + { + $protocol = 'image_process_'.$this->image_library; + + if (eregi("gd2$", $protocol)) + { + $protocol = 'image_process_gd'; + } + + return $this->$protocol('crop'); + } + + // -------------------------------------------------------------------- + + /** + * Image Rotate + * + * This is a wrapper function that chooses the proper + * rotation function based on the protocol specified + * + * @access public + * @return bool + */ + function rotate() + { + // Allowed rotation values + $degs = array(90, 180, 270, 'vrt', 'hor'); + + if ($this->rotation_angle == '' OR ! in_array($this->rotation_angle, $degs, TRUE)) + { + $this->set_error('imglib_rotation_angle_required'); + return FALSE; + } + + // Reassign the width and height + if ($this->rotation_angle == 90 OR $this->rotation_angle == 270) + { + $this->width = $this->orig_height; + $this->height = $this->orig_width; + } + else + { + $this->width = $this->orig_width; + $this->height = $this->orig_height; + } + + + // Choose resizing function + if ($this->image_library == 'imagemagick' OR $this->image_library == 'netpbm') + { + $protocol = 'image_process_'.$this->image_library; + + return $this->$protocol('rotate'); + } + + if ($this->rotation_angle == 'hor' OR $this->rotation_angle == 'vrt') + { + return $this->image_mirror_gd(); + } + else + { + return $this->image_rotate_gd(); + } + } + + // -------------------------------------------------------------------- + + /** + * Image Process Using GD/GD2 + * + * This function will resize or crop + * + * @access public + * @param string + * @return bool + */ + function image_process_gd($action = 'resize') + { + $v2_override = FALSE; + + // If the target width/height match the source, AND if the new file name is not equal to the old file name + // we'll simply make a copy of the original with the new name... assuming dynamic rendering is off. + if ($this->dynamic_output === FALSE) + { + if ($this->orig_width == $this->width AND $this->orig_height == $this->height) + { + if ($this->source_image != $this->new_image) + { + if (@copy($this->full_src_path, $this->full_dst_path)) + { + @chmod($this->full_dst_path, DIR_WRITE_MODE); + } + } + + return TRUE; + } + } + + // Let's set up our values based on the action + if ($action == 'crop') + { + // Reassign the source width/height if cropping + $this->orig_width = $this->width; + $this->orig_height = $this->height; + + // GD 2.0 has a cropping bug so we'll test for it + if ($this->gd_version() !== FALSE) + { + $gd_version = str_replace('0', '', $this->gd_version()); + $v2_override = ($gd_version == 2) ? TRUE : FALSE; + } + } + else + { + // If resizing the x/y axis must be zero + $this->x_axis = 0; + $this->y_axis = 0; + } + + // Create the image handle + if ( ! ($src_img = $this->image_create_gd())) + { + return FALSE; + } + + // Create The Image + // + // old conditional which users report cause problems with shared GD libs who report themselves as "2.0 or greater" + // it appears that this is no longer the issue that it was in 2004, so we've removed it, retaining it in the comment + // below should that ever prove inaccurate. + // + // if ($this->image_library == 'gd2' AND function_exists('imagecreatetruecolor') AND $v2_override == FALSE) + if ($this->image_library == 'gd2' AND function_exists('imagecreatetruecolor')) + { + $create = 'imagecreatetruecolor'; + $copy = 'imagecopyresampled'; + } + else + { + $create = 'imagecreate'; + $copy = 'imagecopyresized'; + } + + $dst_img = $create($this->width, $this->height); + $copy($dst_img, $src_img, 0, 0, $this->x_axis, $this->y_axis, $this->width, $this->height, $this->orig_width, $this->orig_height); + + // Show the image + if ($this->dynamic_output == TRUE) + { + $this->image_display_gd($dst_img); + } + else + { + // Or save it + if ( ! $this->image_save_gd($dst_img)) + { + return FALSE; + } + } + + // Kill the file handles + imagedestroy($dst_img); + imagedestroy($src_img); + + // Set the file to 777 + @chmod($this->full_dst_path, DIR_WRITE_MODE); + + return TRUE; + } + + // -------------------------------------------------------------------- + + /** + * Image Process Using ImageMagick + * + * This function will resize, crop or rotate + * + * @access public + * @param string + * @return bool + */ + function image_process_imagemagick($action = 'resize') + { + // Do we have a vaild library path? + if ($this->library_path == '') + { + $this->set_error('imglib_libpath_invalid'); + return FALSE; + } + + if ( ! eregi("convert$", $this->library_path)) + { + if ( ! eregi("/$", $this->library_path)) $this->library_path .= "/"; + + $this->library_path .= 'convert'; + } + + // Execute the command + $cmd = $this->library_path." -quality ".$this->quality; + + if ($action == 'crop') + { + $cmd .= " -crop ".$this->width."x".$this->height."+".$this->x_axis."+".$this->y_axis." \"$this->full_src_path\" \"$this->full_dst_path\" 2>&1"; + } + elseif ($action == 'rotate') + { + switch ($this->rotation_angle) + { + case 'hor' : $angle = '-flop'; + break; + case 'vrt' : $angle = '-flip'; + break; + default : $angle = '-rotate '.$this->rotation_angle; + break; + } + + $cmd .= " ".$angle." \"$this->full_src_path\" \"$this->full_dst_path\" 2>&1"; + } + else // Resize + { + $cmd .= " -resize ".$this->width."x".$this->height." \"$this->full_src_path\" \"$this->full_dst_path\" 2>&1"; + } + + $retval = 1; + + @exec($cmd, $output, $retval); + + // Did it work? + if ($retval > 0) + { + $this->set_error('imglib_image_process_failed'); + return FALSE; + } + + // Set the file to 777 + @chmod($this->full_dst_path, DIR_WRITE_MODE); + + return TRUE; + } + + // -------------------------------------------------------------------- + + /** + * Image Process Using NetPBM + * + * This function will resize, crop or rotate + * + * @access public + * @param string + * @return bool + */ + function image_process_netpbm($action = 'resize') + { + if ($this->library_path == '') + { + $this->set_error('imglib_libpath_invalid'); + return FALSE; + } + + // Build the resizing command + switch ($this->image_type) + { + case 1 : + $cmd_in = 'giftopnm'; + $cmd_out = 'ppmtogif'; + break; + case 2 : + $cmd_in = 'jpegtopnm'; + $cmd_out = 'ppmtojpeg'; + break; + case 3 : + $cmd_in = 'pngtopnm'; + $cmd_out = 'ppmtopng'; + break; + } + + if ($action == 'crop') + { + $cmd_inner = 'pnmcut -left '.$this->x_axis.' -top '.$this->y_axis.' -width '.$this->width.' -height '.$this->height; + } + elseif ($action == 'rotate') + { + switch ($this->rotation_angle) + { + case 90 : $angle = 'r270'; + break; + case 180 : $angle = 'r180'; + break; + case 270 : $angle = 'r90'; + break; + case 'vrt' : $angle = 'tb'; + break; + case 'hor' : $angle = 'lr'; + break; + } + + $cmd_inner = 'pnmflip -'.$angle.' '; + } + else // Resize + { + $cmd_inner = 'pnmscale -xysize '.$this->width.' '.$this->height; + } + + $cmd = $this->library_path.$cmd_in.' '.$this->full_src_path.' | '.$cmd_inner.' | '.$cmd_out.' > '.$this->dest_folder.'netpbm.tmp'; + + $retval = 1; + + @exec($cmd, $output, $retval); + + // Did it work? + if ($retval > 0) + { + $this->set_error('imglib_image_process_failed'); + return FALSE; + } + + // With NetPBM we have to create a temporary image. + // If you try manipulating the original it fails so + // we have to rename the temp file. + copy ($this->dest_folder.'netpbm.tmp', $this->full_dst_path); + unlink ($this->dest_folder.'netpbm.tmp'); + @chmod($this->full_dst_path, DIR_WRITE_MODE); + + return TRUE; + } + + // -------------------------------------------------------------------- + + /** + * Image Rotate Using GD + * + * @access public + * @return bool + */ + function image_rotate_gd() + { + // Is Image Rotation Supported? + // this function is only supported as of PHP 4.3 + if ( ! function_exists('imagerotate')) + { + $this->set_error('imglib_rotate_unsupported'); + return FALSE; + } + + // Create the image handle + if ( ! ($src_img = $this->image_create_gd())) + { + return FALSE; + } + + // Set the background color + // This won't work with transparent PNG files so we are + // going to have to figure out how to determine the color + // of the alpha channel in a future release. + + $white = imagecolorallocate($src_img, 255, 255, 255); + + // Rotate it! + $dst_img = imagerotate($src_img, $this->rotation_angle, $white); + + // Save the Image + if ($this->dynamic_output == TRUE) + { + $this->image_display_gd($dst_img); + } + else + { + // Or save it + if ( ! $this->image_save_gd($dst_img)) + { + return FALSE; + } + } + + // Kill the file handles + imagedestroy($dst_img); + imagedestroy($src_img); + + // Set the file to 777 + + @chmod($this->full_dst_path, DIR_WRITE_MODE); + + return true; + } + + // -------------------------------------------------------------------- + + /** + * Create Mirror Image using GD + * + * This function will flip horizontal or vertical + * + * @access public + * @return bool + */ + function image_mirror_gd() + { + if ( ! $src_img = $this->image_create_gd()) + { + return FALSE; + } + + $width = $this->orig_width; + $height = $this->orig_height; + + if ($this->rotation_angle == 'hor') + { + for ($i = 0; $i < $height; $i++) + { + $left = 0; + $right = $width-1; + + while ($left < $right) + { + $cl = imagecolorat($src_img, $left, $i); + $cr = imagecolorat($src_img, $right, $i); + + imagesetpixel($src_img, $left, $i, $cr); + imagesetpixel($src_img, $right, $i, $cl); + + $left++; + $right--; + } + } + } + else + { + for ($i = 0; $i < $width; $i++) + { + $top = 0; + $bot = $height-1; + + while ($top < $bot) + { + $ct = imagecolorat($src_img, $i, $top); + $cb = imagecolorat($src_img, $i, $bot); + + imagesetpixel($src_img, $i, $top, $cb); + imagesetpixel($src_img, $i, $bot, $ct); + + $top++; + $bot--; + } + } + } + + // Show the image + if ($this->dynamic_output == TRUE) + { + $this->image_display_gd($src_img); + } + else + { + // Or save it + if ( ! $this->image_save_gd($src_img)) + { + return FALSE; + } + } + + // Kill the file handles + imagedestroy($src_img); + + // Set the file to 777 + @chmod($this->full_dst_path, DIR_WRITE_MODE); + + return TRUE; + } + + // -------------------------------------------------------------------- + + /** + * Image Watermark + * + * This is a wrapper function that chooses the type + * of watermarking based on the specified preference. + * + * @access public + * @param string + * @return bool + */ + function watermark() + { + if ($this->wm_type == 'overlay') + { + return $this->overlay_watermark(); + } + else + { + return $this->text_watermark(); + } + } + + // -------------------------------------------------------------------- + + /** + * Watermark - Graphic Version + * + * @access public + * @return bool + */ + function overlay_watermark() + { + if ( ! function_exists('imagecolortransparent')) + { + $this->set_error('imglib_gd_required'); + return FALSE; + } + + // Fetch source image properties + $this->get_image_properties(); + + // Fetch watermark image properties + $props = $this->get_image_properties($this->wm_overlay_path, TRUE); + $wm_img_type = $props['image_type']; + $wm_width = $props['width']; + $wm_height = $props['height']; + + // Create two image resources + $wm_img = $this->image_create_gd($this->wm_overlay_path, $wm_img_type); + $src_img = $this->image_create_gd($this->full_src_path); + + // Reverse the offset if necessary + // When the image is positioned at the bottom + // we don't want the vertical offset to push it + // further down. We want the reverse, so we'll + // invert the offset. Same with the horizontal + // offset when the image is at the right + + $this->wm_vrt_alignment = strtoupper(substr($this->wm_vrt_alignment, 0, 1)); + $this->wm_hor_alignment = strtoupper(substr($this->wm_hor_alignment, 0, 1)); + + if ($this->wm_vrt_alignment == 'B') + $this->wm_vrt_offset = $this->wm_vrt_offset * -1; + + if ($this->wm_hor_alignment == 'R') + $this->wm_hor_offset = $this->wm_hor_offset * -1; + + // Set the base x and y axis values + $x_axis = $this->wm_hor_offset + $this->wm_padding; + $y_axis = $this->wm_vrt_offset + $this->wm_padding; + + // Set the vertical position + switch ($this->wm_vrt_alignment) + { + case 'T': + break; + case 'M': $y_axis += ($this->orig_height / 2) - ($wm_height / 2); + break; + case 'B': $y_axis += $this->orig_height - $wm_height; + break; + } + + // Set the horizontal position + switch ($this->wm_hor_alignment) + { + case 'L': + break; + case 'C': $x_axis += ($this->orig_width / 2) - ($wm_width / 2); + break; + case 'R': $x_axis += $this->orig_width - $wm_width; + break; + } + + // Build the finalized image + if ($wm_img_type == 3 AND function_exists('imagealphablending')) + { + @imagealphablending($src_img, TRUE); + } + + // Set RGB values for text and shadow + $rgba = imagecolorat($wm_img, $this->wm_x_transp, $this->wm_y_transp); + $alpha = ($rgba & 0x7F000000) >> 24; + + // make a best guess as to whether we're dealing with an image with alpha transparency or no/binary transparency + if ($alpha > 0) + { + // copy the image directly, the image's alpha transparency being the sole determinant of blending + imagecopy($src_img, $wm_img, $x_axis, $y_axis, 0, 0, $wm_width, $wm_height); + } + else + { + // set our RGB value from above to be transparent and merge the images with the specified opacity + imagecolortransparent($wm_img, imagecolorat($wm_img, $this->wm_x_transp, $this->wm_y_transp)); + imagecopymerge($src_img, $wm_img, $x_axis, $y_axis, 0, 0, $wm_width, $wm_height, $this->wm_opacity); + } + + // Output the image + if ($this->dynamic_output == TRUE) + { + $this->image_display_gd($src_img); + } + else + { + if ( ! $this->image_save_gd($src_img)) + { + return FALSE; + } + } + + imagedestroy($src_img); + imagedestroy($wm_img); + + return TRUE; + } + + // -------------------------------------------------------------------- + + /** + * Watermark - Text Version + * + * @access public + * @return bool + */ + function text_watermark() + { + if ( ! ($src_img = $this->image_create_gd())) + { + return FALSE; + } + + if ($this->wm_use_truetype == TRUE AND ! file_exists($this->wm_font_path)) + { + $this->set_error('imglib_missing_font'); + return FALSE; + } + + // Fetch source image properties + $this->get_image_properties(); + + // Set RGB values for text and shadow + $this->wm_font_color = str_replace('#', '', $this->wm_font_color); + $this->wm_shadow_color = str_replace('#', '', $this->wm_shadow_color); + + $R1 = hexdec(substr($this->wm_font_color, 0, 2)); + $G1 = hexdec(substr($this->wm_font_color, 2, 2)); + $B1 = hexdec(substr($this->wm_font_color, 4, 2)); + + $R2 = hexdec(substr($this->wm_shadow_color, 0, 2)); + $G2 = hexdec(substr($this->wm_shadow_color, 2, 2)); + $B2 = hexdec(substr($this->wm_shadow_color, 4, 2)); + + $txt_color = imagecolorclosest($src_img, $R1, $G1, $B1); + $drp_color = imagecolorclosest($src_img, $R2, $G2, $B2); + + // Reverse the vertical offset + // When the image is positioned at the bottom + // we don't want the vertical offset to push it + // further down. We want the reverse, so we'll + // invert the offset. Note: The horizontal + // offset flips itself automatically + + if ($this->wm_vrt_alignment == 'B') + $this->wm_vrt_offset = $this->wm_vrt_offset * -1; + + if ($this->wm_hor_alignment == 'R') + $this->wm_hor_offset = $this->wm_hor_offset * -1; + + // Set font width and height + // These are calculated differently depending on + // whether we are using the true type font or not + if ($this->wm_use_truetype == TRUE) + { + if ($this->wm_font_size == '') + $this->wm_font_size = '17'; + + $fontwidth = $this->wm_font_size-($this->wm_font_size/4); + $fontheight = $this->wm_font_size; + $this->wm_vrt_offset += $this->wm_font_size; + } + else + { + $fontwidth = imagefontwidth($this->wm_font_size); + $fontheight = imagefontheight($this->wm_font_size); + } + + // Set base X and Y axis values + $x_axis = $this->wm_hor_offset + $this->wm_padding; + $y_axis = $this->wm_vrt_offset + $this->wm_padding; + + // Set verticle alignment + if ($this->wm_use_drop_shadow == FALSE) + $this->wm_shadow_distance = 0; + + $this->wm_vrt_alignment = strtoupper(substr($this->wm_vrt_alignment, 0, 1)); + $this->wm_hor_alignment = strtoupper(substr($this->wm_hor_alignment, 0, 1)); + + switch ($this->wm_vrt_alignment) + { + case "T" : + break; + case "M": $y_axis += ($this->orig_height/2)+($fontheight/2); + break; + case "B": $y_axis += ($this->orig_height - $fontheight - $this->wm_shadow_distance - ($fontheight/2)); + break; + } + + $x_shad = $x_axis + $this->wm_shadow_distance; + $y_shad = $y_axis + $this->wm_shadow_distance; + + // Set horizontal alignment + switch ($this->wm_hor_alignment) + { + case "L": + break; + case "R": + if ($this->wm_use_drop_shadow) + $x_shad += ($this->orig_width - $fontwidth*strlen($this->wm_text)); + $x_axis += ($this->orig_width - $fontwidth*strlen($this->wm_text)); + break; + case "C": + if ($this->wm_use_drop_shadow) + $x_shad += floor(($this->orig_width - $fontwidth*strlen($this->wm_text))/2); + $x_axis += floor(($this->orig_width -$fontwidth*strlen($this->wm_text))/2); + break; + } + + // Add the text to the source image + if ($this->wm_use_truetype) + { + if ($this->wm_use_drop_shadow) + imagettftext($src_img, $this->wm_font_size, 0, $x_shad, $y_shad, $drp_color, $this->wm_font_path, $this->wm_text); + imagettftext($src_img, $this->wm_font_size, 0, $x_axis, $y_axis, $txt_color, $this->wm_font_path, $this->wm_text); + } + else + { + if ($this->wm_use_drop_shadow) + imagestring($src_img, $this->wm_font_size, $x_shad, $y_shad, $this->wm_text, $drp_color); + imagestring($src_img, $this->wm_font_size, $x_axis, $y_axis, $this->wm_text, $txt_color); + } + + // Output the final image + if ($this->dynamic_output == TRUE) + { + $this->image_display_gd($src_img); + } + else + { + $this->image_save_gd($src_img); + } + + imagedestroy($src_img); + + return TRUE; + } + + // -------------------------------------------------------------------- + + /** + * Create Image - GD + * + * This simply creates an image resource handle + * based on the type of image being processed + * + * @access public + * @param string + * @return resource + */ + function image_create_gd($path = '', $image_type = '') + { + if ($path == '') + $path = $this->full_src_path; + + if ($image_type == '') + $image_type = $this->image_type; + + + switch ($image_type) + { + case 1 : + if ( ! function_exists('imagecreatefromgif')) + { + $this->set_error(array('imglib_unsupported_imagecreate', 'imglib_gif_not_supported')); + return FALSE; + } + + return imagecreatefromgif($path); + break; + case 2 : + if ( ! function_exists('imagecreatefromjpeg')) + { + $this->set_error(array('imglib_unsupported_imagecreate', 'imglib_jpg_not_supported')); + return FALSE; + } + + return imagecreatefromjpeg($path); + break; + case 3 : + if ( ! function_exists('imagecreatefrompng')) + { + $this->set_error(array('imglib_unsupported_imagecreate', 'imglib_png_not_supported')); + return FALSE; + } + + return imagecreatefrompng($path); + break; + + } + + $this->set_error(array('imglib_unsupported_imagecreate')); + return FALSE; + } + + // -------------------------------------------------------------------- + + /** + * Write image file to disk - GD + * + * Takes an image resource as input and writes the file + * to the specified destination + * + * @access public + * @param resource + * @return bool + */ + function image_save_gd($resource) + { + switch ($this->image_type) + { + case 1 : + if ( ! function_exists('imagegif')) + { + $this->set_error(array('imglib_unsupported_imagecreate', 'imglib_gif_not_supported')); + return FALSE; + } + + @imagegif($resource, $this->full_dst_path); + break; + case 2 : + if ( ! function_exists('imagejpeg')) + { + $this->set_error(array('imglib_unsupported_imagecreate', 'imglib_jpg_not_supported')); + return FALSE; + } + + if (phpversion() == '4.4.1') + { + @touch($this->full_dst_path); // PHP 4.4.1 bug #35060 - workaround + } + + @imagejpeg($resource, $this->full_dst_path, $this->quality); + break; + case 3 : + if ( ! function_exists('imagepng')) + { + $this->set_error(array('imglib_unsupported_imagecreate', 'imglib_png_not_supported')); + return FALSE; + } + + @imagepng($resource, $this->full_dst_path); + break; + default : + $this->set_error(array('imglib_unsupported_imagecreate')); + return FALSE; + break; + } + + return TRUE; + } + + // -------------------------------------------------------------------- + + /** + * Dynamically outputs an image + * + * @access public + * @param resource + * @return void + */ + function image_display_gd($resource) + { + header("Content-Disposition: filename={$this->source_image};"); + header("Content-Type: {$this->mime_type}"); + header('Content-Transfer-Encoding: binary'); + header('Last-Modified: '.gmdate('D, d M Y H:i:s', time()).' GMT'); + + switch ($this->image_type) + { + case 1 : imagegif($resource); + break; + case 2 : imagejpeg($resource, '', $this->quality); + break; + case 3 : imagepng($resource); + break; + default : echo 'Unable to display the image'; + break; + } + } + + // -------------------------------------------------------------------- + + /** + * Re-proportion Image Width/Height + * + * When creating thumbs, the desired width/height + * can end up warping the image due to an incorrect + * ratio between the full-sized image and the thumb. + * + * This function lets us re-proportion the width/height + * if users choose to maintain the aspect ratio when resizing. + * + * @access public + * @return void + */ + function image_reproportion() + { + if ( ! is_numeric($this->width) OR ! is_numeric($this->height) OR $this->width == 0 OR $this->height == 0) + return; + + if ( ! is_numeric($this->orig_width) OR ! is_numeric($this->orig_height) OR $this->orig_width == 0 OR $this->orig_height == 0) + return; + + $new_width = ceil($this->orig_width*$this->height/$this->orig_height); + $new_height = ceil($this->width*$this->orig_height/$this->orig_width); + + $ratio = (($this->orig_height/$this->orig_width) - ($this->height/$this->width)); + + if ($this->master_dim != 'width' AND $this->master_dim != 'height') + { + $this->master_dim = ($ratio < 0) ? 'width' : 'height'; + } + + if (($this->width != $new_width) AND ($this->height != $new_height)) + { + if ($this->master_dim == 'height') + { + $this->width = $new_width; + } + else + { + $this->height = $new_height; + } + } + } + + // -------------------------------------------------------------------- + + /** + * Get image properties + * + * A helper function that gets info about the file + * + * @access public + * @param string + * @return mixed + */ + function get_image_properties($path = '', $return = FALSE) + { + // For now we require GD but we should + // find a way to determine this using IM or NetPBM + + if ($path == '') + $path = $this->full_src_path; + + if ( ! file_exists($path)) + { + $this->set_error('imglib_invalid_path'); + return FALSE; + } + + $vals = @getimagesize($path); + + $types = array(1 => 'gif', 2 => 'jpeg', 3 => 'png'); + + $mime = (isset($types[$vals['2']])) ? 'image/'.$types[$vals['2']] : 'image/jpg'; + + if ($return == TRUE) + { + $v['width'] = $vals['0']; + $v['height'] = $vals['1']; + $v['image_type'] = $vals['2']; + $v['size_str'] = $vals['3']; + $v['mime_type'] = $mime; + + return $v; + } + + $this->orig_width = $vals['0']; + $this->orig_height = $vals['1']; + $this->image_type = $vals['2']; + $this->size_str = $vals['3']; + $this->mime_type = $mime; + + return TRUE; + } + + // -------------------------------------------------------------------- + + /** + * Size calculator + * + * This function takes a known width x height and + * recalculates it to a new size. Only one + * new variable needs to be known + * + * $props = array( + * 'width' => $width, + * 'height' => $height, + * 'new_width' => 40, + * 'new_height' => '' + * ); + * + * @access public + * @param array + * @return array + */ + function size_calculator($vals) + { + if ( ! is_array($vals)) + { + return; + } + + $allowed = array('new_width', 'new_height', 'width', 'height'); + + foreach ($allowed as $item) + { + if ( ! isset($vals[$item]) OR $vals[$item] == '') + $vals[$item] = 0; + } + + if ($vals['width'] == 0 OR $vals['height'] == 0) + { + return $vals; + } + + if ($vals['new_width'] == 0) + { + $vals['new_width'] = ceil($vals['width']*$vals['new_height']/$vals['height']); + } + elseif ($vals['new_height'] == 0) + { + $vals['new_height'] = ceil($vals['new_width']*$vals['height']/$vals['width']); + } + + return $vals; + } + + // -------------------------------------------------------------------- + + /** + * Explode source_image + * + * This is a helper function that extracts the extension + * from the source_image. This function lets us deal with + * source_images with multiple periods, like: my.cool.jpg + * It returns an associative array with two elements: + * $array['ext'] = '.jpg'; + * $array['name'] = 'my.cool'; + * + * @access public + * @param array + * @return array + */ + function explode_name($source_image) + { + $x = explode('.', $source_image); + $ret['ext'] = '.'.end($x); + + $name = ''; + + $ct = count($x)-1; + + for ($i = 0; $i < $ct; $i++) + { + $name .= $x[$i]; + + if ($i < ($ct - 1)) + { + $name .= '.'; + } + } + + $ret['name'] = $name; + + return $ret; + } + + // -------------------------------------------------------------------- + + /** + * Is GD Installed? + * + * @access public + * @return bool + */ + function gd_loaded() + { + if ( ! extension_loaded('gd')) + { + if ( ! dl('gd.so')) + { + return FALSE; + } + } + + return TRUE; + } + + // -------------------------------------------------------------------- + + /** + * Get GD version + * + * @access public + * @return mixed + */ + function gd_version() + { + if (function_exists('gd_info')) + { + $gd_version = @gd_info(); + $gd_version = preg_replace("/\D/", "", $gd_version['GD Version']); + + return $gd_version; + } + + return FALSE; + } + + // -------------------------------------------------------------------- + + /** + * Set error message + * + * @access public + * @param string + * @return void + */ + function set_error($msg) + { + $CI =& get_instance(); + $CI->lang->load('imglib'); + + if (is_array($msg)) + { + foreach ($msg as $val) + { + + $msg = ($CI->lang->line($val) == FALSE) ? $val : $CI->lang->line($val); + $this->error_msg[] = $msg; + log_message('error', $msg); + } + } + else + { + $msg = ($CI->lang->line($msg) == FALSE) ? $msg : $CI->lang->line($msg); + $this->error_msg[] = $msg; + log_message('error', $msg); + } + } + + // -------------------------------------------------------------------- + + /** + * Show error messages + * + * @access public + * @param string + * @return string + */ + function display_errors($open = '

    ', $close = '

    ') + { + $str = ''; + foreach ($this->error_msg as $val) + { + $str .= $open.$val.$close; + } + + return $str; + } + +} +// END Image_lib Class + +/* End of file Image_lib.php */ /* Location: ./system/libraries/Image_lib.php */ \ No newline at end of file diff --git a/system/libraries/Input.php b/system/libraries/Input.php index fe76559fe..f26df7552 100644 --- a/system/libraries/Input.php +++ b/system/libraries/Input.php @@ -1,1059 +1,1059 @@ - '[removed]', - 'document.write' => '[removed]', - '.parentNode' => '[removed]', - '.innerHTML' => '[removed]', - 'window.location' => '[removed]', - '-moz-binding' => '[removed]', - '' => '-->', - ' '<![CDATA[' - ); - /* never allowed, regex replacement */ - var $never_allowed_regex = array( - "javascript\s*:" => '[removed]', - "expression\s*\(" => '[removed]', // CSS and IE - "Redirect\s+302" => '[removed]' - ); - - /** - * Constructor - * - * Sets whether to globally enable the XSS processing - * and whether to allow the $_GET array - * - * @access public - */ - function CI_Input() - { - log_message('debug', "Input Class Initialized"); - - $CFG =& load_class('Config'); - $this->use_xss_clean = ($CFG->item('global_xss_filtering') === TRUE) ? TRUE : FALSE; - $this->allow_get_array = ($CFG->item('enable_query_strings') === TRUE) ? TRUE : FALSE; - $this->_sanitize_globals(); - } - - // -------------------------------------------------------------------- - - /** - * 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() - { - // Would kind of 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 security. - // This is effectively the same as register_globals = off - foreach (array($_GET, $_POST, $_COOKIE, $_SERVER, $_FILES, $_ENV, (isset($_SESSION) && is_array($_SESSION)) ? $_SESSION : array()) as $global) - { - if ( ! is_array($global)) - { - if ( ! in_array($global, $protected)) - { - unset($GLOBALS[$global]); - } - } - else - { - foreach ($global as $key => $val) - { - if ( ! in_array($key, $protected)) - { - unset($GLOBALS[$key]); - } - - if (is_array($val)) - { - foreach($val as $k => $v) - { - if ( ! in_array($k, $protected)) - { - unset($GLOBALS[$k]); - } - } - } - } - } - } - - // Is $_GET data allowed? If not we'll set the $_GET to an empty array - if ($this->allow_get_array == FALSE) - { - $_GET = array(); - } - else - { - $_GET = $this->_clean_input_data($_GET); - } - - // Clean $_POST Data - $_POST = $this->_clean_input_data($_POST); - - // Clean $_COOKIE Data - // 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']); - $_COOKIE = $this->_clean_input_data($_COOKIE); - - 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 - if (get_magic_quotes_gpc()) - { - $str = stripslashes($str); - } - - // Should we filter the input data? - if ($this->use_xss_clean === TRUE) - { - $str = $this->xss_clean($str); - } - - // Standardize newlines - if (strpos($str, "\r") !== FALSE) - { - $str = str_replace(array("\r\n", "\r"), "\n", $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.'); - } - - return $str; - } - - // -------------------------------------------------------------------- - - /** - * 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->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 = '', $xss_clean = FALSE) - { - 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 = '', $xss_clean = FALSE) - { - 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); - } - - // -------------------------------------------------------------------- - - /** - * 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 - * - * @access public - * @return string - */ - function ip_address() - { - if ($this->ip_address !== FALSE) - { - return $this->ip_address; - } - - if ($this->server('REMOTE_ADDR') AND $this->server('HTTP_CLIENT_IP')) - { - $this->ip_address = $_SERVER['HTTP_CLIENT_IP']; - } - elseif ($this->server('REMOTE_ADDR')) - { - $this->ip_address = $_SERVER['REMOTE_ADDR']; - } - elseif ($this->server('HTTP_CLIENT_IP')) - { - $this->ip_address = $_SERVER['HTTP_CLIENT_IP']; - } - elseif ($this->server('HTTP_X_FORWARDED_FOR')) - { - $this->ip_address = $_SERVER['HTTP_X_FORWARDED_FOR']; - } - - if ($this->ip_address === FALSE) - { - $this->ip_address = '0.0.0.0'; - return $this->ip_address; - } - - if (strstr($this->ip_address, ',')) - { - $x = explode(',', $this->ip_address); - $this->ip_address = end($x); - } - - if ( ! $this->valid_ip($this->ip_address)) - { - $this->ip_address = '0.0.0.0'; - } - - return $this->ip_address; - } - - // -------------------------------------------------------------------- - - /** - * Validate IP Address - * - * Updated version suggested by Geert De Deckere - * - * @access public - * @param string - * @return string - */ - function valid_ip($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; - } - - // -------------------------------------------------------------------- - - /** - * 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; - } - - // -------------------------------------------------------------------- - - /** - * Filename Security - * - * @access public - * @param string - * @return string - */ - function filename_security($str) - { - $bad = array( - "../", - "./", - "", - "<", - ">", - "'", - '"', - '&', - '$', - '#', - '{', - '}', - '[', - ']', - '=', - ';', - '?', - "%20", - "%22", - "%3c", // < - "%253c", // < - "%3e", // > - "%0e", // > - "%28", // ( - "%29", // ) - "%2528", // ( - "%26", // & - "%24", // $ - "%3f", // ? - "%3b", // ; - "%3d" // = - ); - - return stripslashes(str_replace($bad, '', $str)); - } - - // -------------------------------------------------------------------- - - /** - * 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://blog.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 - * - * @access public - * @param string - * @return string - */ - 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 = $this->_remove_invisible_characters($str); - - /* - * Protect GET variables in URLs - */ - - // 901119URL5918AMP18930PROTECT8198 - - $str = preg_replace('|\&([a-z\_0-9]+)\=([a-z\_0-9]+)|i', $this->xss_hash()."\\1=\\2", $str); - - /* - * Validate standard character entities - * - * Add a semicolon if missing. We do this to enable - * the conversion of entities to ASCII later. - * - */ - $str = preg_replace('#(&\#?[0-9a-z]{2,})[\x00-\x20]*;?#i', "\\1;", $str); - - /* - * Validate UTF16 two byte encoding (x00) - * - * Just as above, adds a semicolon if missing. - * - */ - $str = preg_replace('#(&\#x?)([0-9A-F]+);?#i',"\\1\\2;",$str); - - /* - * Un-Protect GET variables in URLs - */ - $str = str_replace($this->xss_hash(), '&', $str); - - /* - * URL Decode - * - * Just in case stuff like this is submitted: - * - * Google - * - * Note: Use rawurldecode() so it does not remove plus signs - * - */ - $str = rawurldecode($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-z]+=([\'\"]).*?\\1/si", array($this, '_convert_attribute'), $str); - - $str = preg_replace_callback("/<\w+.*?(?=>|<|$)/si", array($this, '_html_entity_decode_callback'), $str); - - /* - * Remove Invisible Characters Again! - */ - $str = $this->_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. - * - */ - - if (strpos($str, "\t") !== FALSE) - { - $str = str_replace("\t", ' ', $str); - } - - /* - * Capture converted string for later comparison - */ - $converted_string = $str; - - /* - * Not Allowed Under Any Conditions - */ - - foreach ($this->never_allowed_str as $key => $val) - { - $str = str_replace($key, $val, $str); - } - - foreach ($this->never_allowed_regex as $key => $val) - { - $str = preg_replace("#".$key."#i", $val, $str); - } - - /* - * Makes PHP tags safe - * - * Note: XML tags are inadvertently replaced too: - * - * '), array('<?php', '<?PHP', '<?', '?>'), $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', 'script', 'applet', 'alert', 'document', 'write', 'cookie', 'window'); - foreach ($words as $word) - { - $temp = ''; - - for ($i = 0, $wordlen = strlen($word); $i < $wordlen; $i++) - { - $temp .= substr($word, $i, 1)."\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($temp, 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 for PHP5, but it is dog slow compared - * to these simplified non-capturing preg_match(), especially if the pattern exists in the string - */ - 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/i", $str) OR preg_match("/xss/i", $str)) - { - $str = preg_replace("#<(/*)(script|xss)(.*?)\>#si", '[removed]', $str); - } - } - while($original != $str); - - unset($original); - - /* - * Remove JavaScript Event Handlers - * - * Note: This code is a little blunt. It removes - * the event handler and anything up to the closing >, - * but it's unlikely to be a problem. - * - */ - $event_handlers = array('[^a-z_\-]on\w*','xmlns'); - - if ($is_image === TRUE) - { - /* - * Adobe Photoshop puts XML metadata into JFIF images, including namespacing, - * so we have to allow this for images. -Paul - */ - unset($event_handlers[array_search('xmlns', $event_handlers)]); - } - - $str = preg_replace("#<([^><]+?)(".implode('|', $event_handlers).")(\s*=\s*[^><]*)([><]*)#i", "<\\1\\4", $str); - - /* - * 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|applet|audio|basefont|base|behavior|bgsound|blink|body|embed|expression|form|frameset|frame|head|html|ilayer|iframe|input|isindex|layer|link|meta|object|plaintext|style|script|textarea|title|video|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|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 - * - */ - foreach ($this->never_allowed_str as $key => $val) - { - $str = str_replace($key, $val, $str); - } - - foreach ($this->never_allowed_regex as $key => $val) - { - $str = preg_replace("#".$key."#i", $val, $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) - { - if ($str == $converted_string) - { - return TRUE; - } - else - { - return FALSE; - } - } - - log_message('debug', "XSS Filtering completed"); - return $str; - } - - // -------------------------------------------------------------------- - - /** - * Random Hash for protecting URLs - * - * @access public - * @return string - */ - function xss_hash() - { - if ($this->xss_hash == '') - { - if (phpversion() >= 4.2) - mt_srand(); - else - mt_srand(hexdec(substr(md5(microtime()), -8)) & 0x7fffffff); - - $this->xss_hash = md5(time() + mt_rand(0, 1999999999)); - } - - return $this->xss_hash; - } - - // -------------------------------------------------------------------- - - /** - * Remove Invisible Characters - * - * This prevents sandwiching null characters - * between ascii characters, like Java\0script. - * - * @access public - * @param string - * @return string - */ - function _remove_invisible_characters($str) - { - static $non_displayables; - - if ( ! isset($non_displayables)) - { - // every control character except newline (dec 10), carriage return (dec 13), and horizontal tab (dec 09), - $non_displayables = array( - '/%0[0-8bcef]/', // url encoded 00-08, 11, 12, 14, 15 - '/%1[0-9a-f]/', // url encoded 16-31 - '/[\x00-\x08]/', // 00-08 - '/\x0b/', '/\x0c/', // 11, 12 - '/[\x0e-\x1f]/' // 14-31 - ); - } - - do - { - $cleaned = $str; - $str = preg_replace($non_displayables, '', $str); - } - while ($cleaned != $str); - - return $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 - * - * @access public - * @param type - * @return type - */ - function _compact_exploded_words($matches) - { - return preg_replace('/\s+/s', '', $matches[1]).$matches[2]; - } - - // -------------------------------------------------------------------- - - /** - * Sanitize Naughty HTML - * - * Callback function for xss_clean() to remove naughty HTML elements - * - * @access private - * @param array - * @return string - */ - function _sanitize_naughty_html($matches) - { - // encode opening brace - $str = '<'.$matches[1].$matches[2].$matches[3]; - - // encode captured opening or closing brace to prevent recursive vectors - $str .= str_replace(array('>', '<'), array('>', '<'), $matches[4]); - - return $str; - } - - // -------------------------------------------------------------------- - - /** - * 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 - * - * @access private - * @param array - * @return string - */ - function _js_link_removal($match) - { - $attributes = $this->_filter_attributes(str_replace(array('<', '>'), '', $match[1])); - return str_replace($match[1], preg_replace("#href=.*?(alert\(|alert&\#40;|javascript\:|charset\=|window\.|document\.|\.cookie|_filter_attributes(str_replace(array('<', '>'), '', $match[1])); - return str_replace($match[1], preg_replace("#src=.*?(alert\(|alert&\#40;|javascript\:|charset\=|window\.|document\.|\.cookie|', '<'), array('>', '<'), $match[0]); - } - - // -------------------------------------------------------------------- - - /** - * HTML Entity Decode Callback - * - * Used as a callback for XSS Clean - * - * @access public - * @param array - * @return string - */ - function _html_entity_decode_callback($match) - { - $CFG =& load_class('Config'); - $charset = $CFG->item('charset'); - - return $this->_html_entity_decode($match[0], strtoupper($charset)); - } - - // -------------------------------------------------------------------- - - /** - * HTML Entities Decode - * - * This function is a replacement for html_entity_decode() - * - * In some versions of PHP the native function does not work - * when UTF-8 is the specified character set, so this gives us - * a work-around. More info here: - * http://bugs.php.net/bug.php?id=25670 - * - * @access private - * @param string - * @param string - * @return string - */ - /* ------------------------------------------------- - /* Replacement for html_entity_decode() - /* -------------------------------------------------*/ - - /* - NOTE: html_entity_decode() has a bug in some PHP versions when UTF-8 is the - character set, and the PHP developers said they were not back porting the - fix to versions other than PHP 5.x. - */ - function _html_entity_decode($str, $charset='UTF-8') - { - if (stristr($str, '&') === FALSE) return $str; - - // 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. - - if (function_exists('html_entity_decode') && (strtolower($charset) != 'utf-8' OR version_compare(phpversion(), '5.0.0', '>='))) - { - $str = html_entity_decode($str, ENT_COMPAT, $charset); - $str = preg_replace('~&#x(0*[0-9a-f]{2,5})~ei', 'chr(hexdec("\\1"))', $str); - return preg_replace('~&#([0-9]{2,4})~e', 'chr(\\1)', $str); - } - - // Numeric Entities - $str = preg_replace('~&#x(0*[0-9a-f]{2,5});{0,1}~ei', 'chr(hexdec("\\1"))', $str); - $str = preg_replace('~&#([0-9]{2,4});{0,1}~e', 'chr(\\1)', $str); - - // Literal Entities - Slightly slow so we do another check - if (stristr($str, '&') === FALSE) - { - $str = strtr($str, array_flip(get_html_translation_table(HTML_ENTITIES))); - } - - return $str; - } - - // -------------------------------------------------------------------- - - /** - * Filter Attributes - * - * Filters tag attributes for consistency and safety - * - * @access public - * @param string - * @return string - */ - 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 .= "{$match}"; - } - } - - return $out; - } - - // -------------------------------------------------------------------- - -} -// END Input class - -/* End of file Input.php */ + '[removed]', + 'document.write' => '[removed]', + '.parentNode' => '[removed]', + '.innerHTML' => '[removed]', + 'window.location' => '[removed]', + '-moz-binding' => '[removed]', + '' => '-->', + ' '<![CDATA[' + ); + /* never allowed, regex replacement */ + var $never_allowed_regex = array( + "javascript\s*:" => '[removed]', + "expression\s*\(" => '[removed]', // CSS and IE + "Redirect\s+302" => '[removed]' + ); + + /** + * Constructor + * + * Sets whether to globally enable the XSS processing + * and whether to allow the $_GET array + * + * @access public + */ + function CI_Input() + { + log_message('debug', "Input Class Initialized"); + + $CFG =& load_class('Config'); + $this->use_xss_clean = ($CFG->item('global_xss_filtering') === TRUE) ? TRUE : FALSE; + $this->allow_get_array = ($CFG->item('enable_query_strings') === TRUE) ? TRUE : FALSE; + $this->_sanitize_globals(); + } + + // -------------------------------------------------------------------- + + /** + * 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() + { + // Would kind of 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 security. + // This is effectively the same as register_globals = off + foreach (array($_GET, $_POST, $_COOKIE, $_SERVER, $_FILES, $_ENV, (isset($_SESSION) && is_array($_SESSION)) ? $_SESSION : array()) as $global) + { + if ( ! is_array($global)) + { + if ( ! in_array($global, $protected)) + { + unset($GLOBALS[$global]); + } + } + else + { + foreach ($global as $key => $val) + { + if ( ! in_array($key, $protected)) + { + unset($GLOBALS[$key]); + } + + if (is_array($val)) + { + foreach($val as $k => $v) + { + if ( ! in_array($k, $protected)) + { + unset($GLOBALS[$k]); + } + } + } + } + } + } + + // Is $_GET data allowed? If not we'll set the $_GET to an empty array + if ($this->allow_get_array == FALSE) + { + $_GET = array(); + } + else + { + $_GET = $this->_clean_input_data($_GET); + } + + // Clean $_POST Data + $_POST = $this->_clean_input_data($_POST); + + // Clean $_COOKIE Data + // 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']); + $_COOKIE = $this->_clean_input_data($_COOKIE); + + 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 + if (get_magic_quotes_gpc()) + { + $str = stripslashes($str); + } + + // Should we filter the input data? + if ($this->use_xss_clean === TRUE) + { + $str = $this->xss_clean($str); + } + + // Standardize newlines + if (strpos($str, "\r") !== FALSE) + { + $str = str_replace(array("\r\n", "\r"), "\n", $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.'); + } + + return $str; + } + + // -------------------------------------------------------------------- + + /** + * 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->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 = '', $xss_clean = FALSE) + { + 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 = '', $xss_clean = FALSE) + { + 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); + } + + // -------------------------------------------------------------------- + + /** + * 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 + * + * @access public + * @return string + */ + function ip_address() + { + if ($this->ip_address !== FALSE) + { + return $this->ip_address; + } + + if ($this->server('REMOTE_ADDR') AND $this->server('HTTP_CLIENT_IP')) + { + $this->ip_address = $_SERVER['HTTP_CLIENT_IP']; + } + elseif ($this->server('REMOTE_ADDR')) + { + $this->ip_address = $_SERVER['REMOTE_ADDR']; + } + elseif ($this->server('HTTP_CLIENT_IP')) + { + $this->ip_address = $_SERVER['HTTP_CLIENT_IP']; + } + elseif ($this->server('HTTP_X_FORWARDED_FOR')) + { + $this->ip_address = $_SERVER['HTTP_X_FORWARDED_FOR']; + } + + if ($this->ip_address === FALSE) + { + $this->ip_address = '0.0.0.0'; + return $this->ip_address; + } + + if (strstr($this->ip_address, ',')) + { + $x = explode(',', $this->ip_address); + $this->ip_address = end($x); + } + + if ( ! $this->valid_ip($this->ip_address)) + { + $this->ip_address = '0.0.0.0'; + } + + return $this->ip_address; + } + + // -------------------------------------------------------------------- + + /** + * Validate IP Address + * + * Updated version suggested by Geert De Deckere + * + * @access public + * @param string + * @return string + */ + function valid_ip($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; + } + + // -------------------------------------------------------------------- + + /** + * 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; + } + + // -------------------------------------------------------------------- + + /** + * Filename Security + * + * @access public + * @param string + * @return string + */ + function filename_security($str) + { + $bad = array( + "../", + "./", + "", + "<", + ">", + "'", + '"', + '&', + '$', + '#', + '{', + '}', + '[', + ']', + '=', + ';', + '?', + "%20", + "%22", + "%3c", // < + "%253c", // < + "%3e", // > + "%0e", // > + "%28", // ( + "%29", // ) + "%2528", // ( + "%26", // & + "%24", // $ + "%3f", // ? + "%3b", // ; + "%3d" // = + ); + + return stripslashes(str_replace($bad, '', $str)); + } + + // -------------------------------------------------------------------- + + /** + * 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://blog.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 + * + * @access public + * @param string + * @return string + */ + 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 = $this->_remove_invisible_characters($str); + + /* + * Protect GET variables in URLs + */ + + // 901119URL5918AMP18930PROTECT8198 + + $str = preg_replace('|\&([a-z\_0-9]+)\=([a-z\_0-9]+)|i', $this->xss_hash()."\\1=\\2", $str); + + /* + * Validate standard character entities + * + * Add a semicolon if missing. We do this to enable + * the conversion of entities to ASCII later. + * + */ + $str = preg_replace('#(&\#?[0-9a-z]{2,})[\x00-\x20]*;?#i', "\\1;", $str); + + /* + * Validate UTF16 two byte encoding (x00) + * + * Just as above, adds a semicolon if missing. + * + */ + $str = preg_replace('#(&\#x?)([0-9A-F]+);?#i',"\\1\\2;",$str); + + /* + * Un-Protect GET variables in URLs + */ + $str = str_replace($this->xss_hash(), '&', $str); + + /* + * URL Decode + * + * Just in case stuff like this is submitted: + * + * Google + * + * Note: Use rawurldecode() so it does not remove plus signs + * + */ + $str = rawurldecode($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-z]+=([\'\"]).*?\\1/si", array($this, '_convert_attribute'), $str); + + $str = preg_replace_callback("/<\w+.*?(?=>|<|$)/si", array($this, '_html_entity_decode_callback'), $str); + + /* + * Remove Invisible Characters Again! + */ + $str = $this->_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. + * + */ + + if (strpos($str, "\t") !== FALSE) + { + $str = str_replace("\t", ' ', $str); + } + + /* + * Capture converted string for later comparison + */ + $converted_string = $str; + + /* + * Not Allowed Under Any Conditions + */ + + foreach ($this->never_allowed_str as $key => $val) + { + $str = str_replace($key, $val, $str); + } + + foreach ($this->never_allowed_regex as $key => $val) + { + $str = preg_replace("#".$key."#i", $val, $str); + } + + /* + * Makes PHP tags safe + * + * Note: XML tags are inadvertently replaced too: + * + * '), array('<?php', '<?PHP', '<?', '?>'), $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', 'script', 'applet', 'alert', 'document', 'write', 'cookie', 'window'); + foreach ($words as $word) + { + $temp = ''; + + for ($i = 0, $wordlen = strlen($word); $i < $wordlen; $i++) + { + $temp .= substr($word, $i, 1)."\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($temp, 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 for PHP5, but it is dog slow compared + * to these simplified non-capturing preg_match(), especially if the pattern exists in the string + */ + 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/i", $str) OR preg_match("/xss/i", $str)) + { + $str = preg_replace("#<(/*)(script|xss)(.*?)\>#si", '[removed]', $str); + } + } + while($original != $str); + + unset($original); + + /* + * Remove JavaScript Event Handlers + * + * Note: This code is a little blunt. It removes + * the event handler and anything up to the closing >, + * but it's unlikely to be a problem. + * + */ + $event_handlers = array('[^a-z_\-]on\w*','xmlns'); + + if ($is_image === TRUE) + { + /* + * Adobe Photoshop puts XML metadata into JFIF images, including namespacing, + * so we have to allow this for images. -Paul + */ + unset($event_handlers[array_search('xmlns', $event_handlers)]); + } + + $str = preg_replace("#<([^><]+?)(".implode('|', $event_handlers).")(\s*=\s*[^><]*)([><]*)#i", "<\\1\\4", $str); + + /* + * 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|applet|audio|basefont|base|behavior|bgsound|blink|body|embed|expression|form|frameset|frame|head|html|ilayer|iframe|input|isindex|layer|link|meta|object|plaintext|style|script|textarea|title|video|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|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 + * + */ + foreach ($this->never_allowed_str as $key => $val) + { + $str = str_replace($key, $val, $str); + } + + foreach ($this->never_allowed_regex as $key => $val) + { + $str = preg_replace("#".$key."#i", $val, $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) + { + if ($str == $converted_string) + { + return TRUE; + } + else + { + return FALSE; + } + } + + log_message('debug', "XSS Filtering completed"); + return $str; + } + + // -------------------------------------------------------------------- + + /** + * Random Hash for protecting URLs + * + * @access public + * @return string + */ + function xss_hash() + { + if ($this->xss_hash == '') + { + if (phpversion() >= 4.2) + mt_srand(); + else + mt_srand(hexdec(substr(md5(microtime()), -8)) & 0x7fffffff); + + $this->xss_hash = md5(time() + mt_rand(0, 1999999999)); + } + + return $this->xss_hash; + } + + // -------------------------------------------------------------------- + + /** + * Remove Invisible Characters + * + * This prevents sandwiching null characters + * between ascii characters, like Java\0script. + * + * @access public + * @param string + * @return string + */ + function _remove_invisible_characters($str) + { + static $non_displayables; + + if ( ! isset($non_displayables)) + { + // every control character except newline (dec 10), carriage return (dec 13), and horizontal tab (dec 09), + $non_displayables = array( + '/%0[0-8bcef]/', // url encoded 00-08, 11, 12, 14, 15 + '/%1[0-9a-f]/', // url encoded 16-31 + '/[\x00-\x08]/', // 00-08 + '/\x0b/', '/\x0c/', // 11, 12 + '/[\x0e-\x1f]/' // 14-31 + ); + } + + do + { + $cleaned = $str; + $str = preg_replace($non_displayables, '', $str); + } + while ($cleaned != $str); + + return $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 + * + * @access public + * @param type + * @return type + */ + function _compact_exploded_words($matches) + { + return preg_replace('/\s+/s', '', $matches[1]).$matches[2]; + } + + // -------------------------------------------------------------------- + + /** + * Sanitize Naughty HTML + * + * Callback function for xss_clean() to remove naughty HTML elements + * + * @access private + * @param array + * @return string + */ + function _sanitize_naughty_html($matches) + { + // encode opening brace + $str = '<'.$matches[1].$matches[2].$matches[3]; + + // encode captured opening or closing brace to prevent recursive vectors + $str .= str_replace(array('>', '<'), array('>', '<'), $matches[4]); + + return $str; + } + + // -------------------------------------------------------------------- + + /** + * 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 + * + * @access private + * @param array + * @return string + */ + function _js_link_removal($match) + { + $attributes = $this->_filter_attributes(str_replace(array('<', '>'), '', $match[1])); + return str_replace($match[1], preg_replace("#href=.*?(alert\(|alert&\#40;|javascript\:|charset\=|window\.|document\.|\.cookie|_filter_attributes(str_replace(array('<', '>'), '', $match[1])); + return str_replace($match[1], preg_replace("#src=.*?(alert\(|alert&\#40;|javascript\:|charset\=|window\.|document\.|\.cookie|', '<'), array('>', '<'), $match[0]); + } + + // -------------------------------------------------------------------- + + /** + * HTML Entity Decode Callback + * + * Used as a callback for XSS Clean + * + * @access public + * @param array + * @return string + */ + function _html_entity_decode_callback($match) + { + $CFG =& load_class('Config'); + $charset = $CFG->item('charset'); + + return $this->_html_entity_decode($match[0], strtoupper($charset)); + } + + // -------------------------------------------------------------------- + + /** + * HTML Entities Decode + * + * This function is a replacement for html_entity_decode() + * + * In some versions of PHP the native function does not work + * when UTF-8 is the specified character set, so this gives us + * a work-around. More info here: + * http://bugs.php.net/bug.php?id=25670 + * + * @access private + * @param string + * @param string + * @return string + */ + /* ------------------------------------------------- + /* Replacement for html_entity_decode() + /* -------------------------------------------------*/ + + /* + NOTE: html_entity_decode() has a bug in some PHP versions when UTF-8 is the + character set, and the PHP developers said they were not back porting the + fix to versions other than PHP 5.x. + */ + function _html_entity_decode($str, $charset='UTF-8') + { + if (stristr($str, '&') === FALSE) return $str; + + // 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. + + if (function_exists('html_entity_decode') && (strtolower($charset) != 'utf-8' OR version_compare(phpversion(), '5.0.0', '>='))) + { + $str = html_entity_decode($str, ENT_COMPAT, $charset); + $str = preg_replace('~&#x(0*[0-9a-f]{2,5})~ei', 'chr(hexdec("\\1"))', $str); + return preg_replace('~&#([0-9]{2,4})~e', 'chr(\\1)', $str); + } + + // Numeric Entities + $str = preg_replace('~&#x(0*[0-9a-f]{2,5});{0,1}~ei', 'chr(hexdec("\\1"))', $str); + $str = preg_replace('~&#([0-9]{2,4});{0,1}~e', 'chr(\\1)', $str); + + // Literal Entities - Slightly slow so we do another check + if (stristr($str, '&') === FALSE) + { + $str = strtr($str, array_flip(get_html_translation_table(HTML_ENTITIES))); + } + + return $str; + } + + // -------------------------------------------------------------------- + + /** + * Filter Attributes + * + * Filters tag attributes for consistency and safety + * + * @access public + * @param string + * @return string + */ + 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 .= "{$match}"; + } + } + + return $out; + } + + // -------------------------------------------------------------------- + +} +// END Input class + +/* End of file Input.php */ /* Location: ./system/libraries/Input.php */ \ No newline at end of file diff --git a/system/libraries/Language.php b/system/libraries/Language.php index bc237e756..78f4143af 100644 --- a/system/libraries/Language.php +++ b/system/libraries/Language.php @@ -1,123 +1,123 @@ -is_loaded, TRUE)) - { - return; - } - - if ($idiom == '') - { - $CI =& get_instance(); - $deft_lang = $CI->config->item('language'); - $idiom = ($deft_lang == '') ? 'english' : $deft_lang; - } - - // Determine where the language file is and load it - if (file_exists(APPPATH.'language/'.$idiom.'/'.$langfile)) - { - include(APPPATH.'language/'.$idiom.'/'.$langfile); - } - else - { - if (file_exists(BASEPATH.'language/'.$idiom.'/'.$langfile)) - { - include(BASEPATH.'language/'.$idiom.'/'.$langfile); - } - else - { - show_error('Unable to load the requested language file: language/'.$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 = '') - { - $line = ($line == '' OR ! isset($this->language[$line])) ? FALSE : $this->language[$line]; - return $line; - } - -} -// END Language Class - -/* End of file Language.php */ +is_loaded, TRUE)) + { + return; + } + + if ($idiom == '') + { + $CI =& get_instance(); + $deft_lang = $CI->config->item('language'); + $idiom = ($deft_lang == '') ? 'english' : $deft_lang; + } + + // Determine where the language file is and load it + if (file_exists(APPPATH.'language/'.$idiom.'/'.$langfile)) + { + include(APPPATH.'language/'.$idiom.'/'.$langfile); + } + else + { + if (file_exists(BASEPATH.'language/'.$idiom.'/'.$langfile)) + { + include(BASEPATH.'language/'.$idiom.'/'.$langfile); + } + else + { + show_error('Unable to load the requested language file: language/'.$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 = '') + { + $line = ($line == '' OR ! isset($this->language[$line])) ? FALSE : $this->language[$line]; + return $line; + } + +} +// END Language Class + +/* End of file Language.php */ /* Location: ./system/libraries/Language.php */ \ No newline at end of file diff --git a/system/libraries/Loader.php b/system/libraries/Loader.php index da8d9e761..b58cc7d72 100644 --- a/system/libraries/Loader.php +++ b/system/libraries/Loader.php @@ -1,1088 +1,1088 @@ - 'unit', 'user_agent' => 'agent'); - - - /** - * Constructor - * - * Sets the path to the view files and gets the initial output buffering level - * - * @access public - */ - function CI_Loader() - { - $this->_ci_is_php5 = (floor(phpversion()) >= 5) ? TRUE : FALSE; - $this->_ci_view_path = APPPATH.'views/'; - $this->_ci_ob_level = ob_get_level(); - - log_message('debug', "Loader Class Initialized"); - } - - // -------------------------------------------------------------------- - - /** - * Class Loader - * - * This function lets users load and instantiate classes. - * It is designed to be called from a user's app controllers. - * - * @access public - * @param string the name of the class - * @param mixed the optional parameters - * @param string an optional object name - * @return void - */ - function library($library = '', $params = NULL, $object_name = NULL) - { - if ($library == '') - { - return FALSE; - } - - if ( ! is_null($params) AND ! is_array($params)) - { - $params = NULL; - } - - if (is_array($library)) - { - foreach ($library as $class) - { - $this->_ci_load_class($class, $params, $object_name); - } - } - else - { - $this->_ci_load_class($library, $params, $object_name); - } - - $this->_ci_assign_to_models(); - } - - // -------------------------------------------------------------------- - - /** - * Model Loader - * - * This function lets users load and instantiate models. - * - * @access public - * @param string the name of the class - * @param string name for the model - * @param bool database connection - * @return void - */ - function model($model, $name = '', $db_conn = FALSE) - { - if (is_array($model)) - { - foreach($model as $babe) - { - $this->model($babe); - } - return; - } - - if ($model == '') - { - return; - } - - // Is the model in a sub-folder? If so, parse out the filename and path. - if (strpos($model, '/') === FALSE) - { - $path = ''; - } - else - { - $x = explode('/', $model); - $model = end($x); - unset($x[count($x)-1]); - $path = implode('/', $x).'/'; - } - - 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); - - if ( ! file_exists(APPPATH.'models/'.$path.$model.EXT)) - { - show_error('Unable to locate the model you have specified: '.$model); - } - - 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('Model')) - { - load_class('Model', FALSE); - } - - require_once(APPPATH.'models/'.$path.$model.EXT); - - $model = ucfirst($model); - - $CI->$name = new $model(); - $CI->$name->_assign_libraries(); - - $this->_ci_models[] = $name; - } - - // -------------------------------------------------------------------- - - /** - * Database Loader - * - * @access public - * @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 - */ - function database($params = '', $return = FALSE, $active_record = FALSE) - { - // 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 == FALSE AND isset($CI->db) AND is_object($CI->db)) - { - return FALSE; - } - - require_once(BASEPATH.'database/DB'.EXT); - - 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); - - // Assign the DB object to any existing models - $this->_ci_assign_to_models(); - } - - // -------------------------------------------------------------------- - - /** - * Load the Utilities Class - * - * @access public - * @return string - */ - 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'.EXT); - require_once(BASEPATH.'database/drivers/'.$CI->db->dbdriver.'/'.$CI->db->dbdriver.'_utility'.EXT); - $class = 'CI_DB_'.$CI->db->dbdriver.'_utility'; - - $CI->dbutil =& new $class(); - - $CI->load->_ci_assign_to_models(); - } - - // -------------------------------------------------------------------- - - /** - * Load the Database Forge Class - * - * @access public - * @return string - */ - function dbforge() - { - if ( ! class_exists('CI_DB')) - { - $this->database(); - } - - $CI =& get_instance(); - - require_once(BASEPATH.'database/DB_forge'.EXT); - require_once(BASEPATH.'database/drivers/'.$CI->db->dbdriver.'/'.$CI->db->dbdriver.'_forge'.EXT); - $class = 'CI_DB_'.$CI->db->dbdriver.'_forge'; - - $CI->dbforge = new $class(); - - $CI->load->_ci_assign_to_models(); - } - - // -------------------------------------------------------------------- - - /** - * 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. - * - * @access public - * @param string - * @param array - * @param bool - * @return void - */ - 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 - * - * @access public - * @param string - * @param bool - * @return string - */ - 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. - * - * @access public - * @param array - * @return void - */ - 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; - } - } - } - - // -------------------------------------------------------------------- - - /** - * Load Helper - * - * This function loads the specified helper file. - * - * @access public - * @param mixed - * @return void - */ - function helper($helpers = array()) - { - if ( ! is_array($helpers)) - { - $helpers = array($helpers); - } - - foreach ($helpers as $helper) - { - $helper = strtolower(str_replace(EXT, '', str_replace('_helper', '', $helper)).'_helper'); - - if (isset($this->_ci_helpers[$helper])) - { - continue; - } - - $ext_helper = APPPATH.'helpers/'.config_item('subclass_prefix').$helper.EXT; - - // Is this a helper extension request? - if (file_exists($ext_helper)) - { - $base_helper = BASEPATH.'helpers/'.$helper.EXT; - - if ( ! file_exists($base_helper)) - { - show_error('Unable to load the requested file: helpers/'.$helper.EXT); - } - - include_once($ext_helper); - include_once($base_helper); - } - elseif (file_exists(APPPATH.'helpers/'.$helper.EXT)) - { - include_once(APPPATH.'helpers/'.$helper.EXT); - } - else - { - if (file_exists(BASEPATH.'helpers/'.$helper.EXT)) - { - include_once(BASEPATH.'helpers/'.$helper.EXT); - } - else - { - show_error('Unable to load the requested file: helpers/'.$helper.EXT); - } - } - - $this->_ci_helpers[$helper] = TRUE; - log_message('debug', 'Helper loaded: '.$helper); - } - } - - // -------------------------------------------------------------------- - - /** - * Load Helpers - * - * This is simply an alias to the above function in case the - * user has written the plural form of this function. - * - * @access public - * @param array - * @return void - */ - function helpers($helpers = array()) - { - $this->helper($helpers); - } - - // -------------------------------------------------------------------- - - /** - * Load Plugin - * - * This function loads the specified plugin. - * - * @access public - * @param array - * @return void - */ - function plugin($plugins = array()) - { - if ( ! is_array($plugins)) - { - $plugins = array($plugins); - } - - foreach ($plugins as $plugin) - { - $plugin = strtolower(str_replace(EXT, '', str_replace('_pi', '', $plugin)).'_pi'); - - if (isset($this->_ci_plugins[$plugin])) - { - continue; - } - - if (file_exists(APPPATH.'plugins/'.$plugin.EXT)) - { - include_once(APPPATH.'plugins/'.$plugin.EXT); - } - else - { - if (file_exists(BASEPATH.'plugins/'.$plugin.EXT)) - { - include_once(BASEPATH.'plugins/'.$plugin.EXT); - } - else - { - show_error('Unable to load the requested file: plugins/'.$plugin.EXT); - } - } - - $this->_ci_plugins[$plugin] = TRUE; - log_message('debug', 'Plugin loaded: '.$plugin); - } - } - - // -------------------------------------------------------------------- - - /** - * Load Plugins - * - * This is simply an alias to the above function in case the - * user has written the plural form of this function. - * - * @access public - * @param array - * @return void - */ - function plugins($plugins = array()) - { - $this->plugin($plugins); - } - - // -------------------------------------------------------------------- - - /** - * Loads a language file - * - * @access public - * @param array - * @param string - * @return void - */ - 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 language files for scaffolding - * - * @access public - * @param string - * @return arra - */ - function scaffold_language($file = '', $lang = '', $return = FALSE) - { - $CI =& get_instance(); - return $CI->lang->load($file, $lang, $return); - } - - // -------------------------------------------------------------------- - - /** - * Loads a config file - * - * @access public - * @param string - * @return void - */ - function config($file = '', $use_sections = FALSE, $fail_gracefully = FALSE) - { - $CI =& get_instance(); - $CI->config->load($file, $use_sections, $fail_gracefully); - } - - // -------------------------------------------------------------------- - - /** - * Scaffolding Loader - * - * This initializing function works a bit different than the - * others. It doesn't load the class. Instead, it simply - * sets a flag indicating that scaffolding is allowed to be - * used. The actual scaffolding function below is - * called by the front controller based on whether the - * second segment of the URL matches the "secret" scaffolding - * word stored in the application/config/routes.php - * - * @access public - * @param string - * @return void - */ - function scaffolding($table = '') - { - if ($table === FALSE) - { - show_error('You must include the name of the table you would like to access when you initialize scaffolding'); - } - - $CI =& get_instance(); - $CI->_ci_scaffolding = TRUE; - $CI->_ci_scaff_table = $table; - } - - // -------------------------------------------------------------------- - - /** - * 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 - * - * @access private - * @param array - * @return void - */ - 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]; - } - - // Set the path to the requested file - if ($_ci_path == '') - { - $_ci_ext = pathinfo($_ci_view, PATHINFO_EXTENSION); - $_ci_file = ($_ci_ext == '') ? $_ci_view.EXT : $_ci_view; - $_ci_path = $this->_ci_view_path.$_ci_file; - } - else - { - $_ci_x = explode('/', $_ci_path); - $_ci_file = end($_ci_x); - } - - if ( ! 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. - // Only needed when running PHP 5 - - if ($this->_ci_is_instance()) - { - $_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 - { - // PHP 4 requires that we use a global - global $OUT; - $OUT->append_output(ob_get_contents()); - @ob_end_clean(); - } - } - - // -------------------------------------------------------------------- - - /** - * Load class - * - * This function loads the requested class. - * - * @access private - * @param string the item that is being loaded - * @param mixed any additional parameters - * @param string an optional object name - * @return void - */ - 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(EXT, '', trim($class, '/')); - - // Was the path included with the class name? - // We look for a slash to determine this - $subdir = ''; - if (strpos($class, '/') !== FALSE) - { - // explode the path so we can separate the filename from the path - $x = explode('/', $class); - - // Reset the $class variable now that we know the actual filename - $class = end($x); - - // Kill the filename from the array - unset($x[count($x)-1]); - - // Glue the path back together, sans filename - $subdir = implode($x, '/').'/'; - } - - // 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.EXT; - - // Is this a class extension request? - if (file_exists($subclass)) - { - $baseclass = BASEPATH.'libraries/'.ucfirst($class).EXT; - - 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; - for ($i = 1; $i < 3; $i++) - { - $path = ($i % 2) ? APPPATH : BASEPATH; - $filepath = $path.'libraries/'.$subdir.$class.EXT; - - // 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 - * - * @access private - * @param string - * @param string - * @param string an optional object name - * @return null - */ - function _ci_init_class($class, $prefix = '', $config = FALSE, $object_name = NULL) - { - // Is there an associated config file for this class? - if ($config === NULL) - { - // We test for both uppercase and lowercase, for servers that - // are case-sensitive with regard to file names - if (file_exists(APPPATH.'config/'.strtolower($class).EXT)) - { - include_once(APPPATH.'config/'.strtolower($class).EXT); - } - else - { - if (file_exists(APPPATH.'config/'.ucfirst(strtolower($class)).EXT)) - { - include_once(APPPATH.'config/'.ucfirst(strtolower($class)).EXT); - } - } - } - - 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, plugins, and helpers to be loaded automatically. - * - * @access private - * @param array - * @return void - */ - function _ci_autoloader() - { - include_once(APPPATH.'config/autoload'.EXT); - - if ( ! isset($autoload)) - { - return FALSE; - } - - // Load any custom config file - if (count($autoload['config']) > 0) - { - $CI =& get_instance(); - foreach ($autoload['config'] as $key => $val) - { - $CI->config->load($val); - } - } - - // Autoload plugins, helpers and languages - foreach (array('helper', 'plugin', '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'])) - { - $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 scaffolding - if (in_array('scaffolding', $autoload['libraries'])) - { - $this->scaffolding(); - $autoload['libraries'] = array_diff($autoload['libraries'], array('scaffolding')); - } - - // Load all other libraries - foreach ($autoload['libraries'] as $item) - { - $this->library($item); - } - } - - // Autoload models - if (isset($autoload['model'])) - { - $this->model($autoload['model']); - } - - } - - // -------------------------------------------------------------------- - - /** - * Assign to Models - * - * Makes sure that anything loaded by the loader class (libraries, plugins, etc.) - * will be available to models, if any exist. - * - * @access private - * @param object - * @return array - */ - function _ci_assign_to_models() - { - if (count($this->_ci_models) == 0) - { - return; - } - - if ($this->_ci_is_instance()) - { - $CI =& get_instance(); - foreach ($this->_ci_models as $model) - { - $CI->$model->_assign_libraries(); - } - } - else - { - foreach ($this->_ci_models as $model) - { - $this->$model->_assign_libraries(); - } - } - } - - // -------------------------------------------------------------------- - - /** - * Object to Array - * - * Takes an object as input and converts the class variables to array key/vals - * - * @access private - * @param object - * @return array - */ - function _ci_object_to_array($object) - { - return (is_object($object)) ? get_object_vars($object) : $object; - } - - // -------------------------------------------------------------------- - - /** - * Determines whether we should use the CI instance or $this - * - * @access private - * @return bool - */ - function _ci_is_instance() - { - if ($this->_ci_is_php5 == TRUE) - { - return TRUE; - } - - global $CI; - return (is_object($CI)) ? TRUE : FALSE; - } - -} - -/* End of file Loader.php */ + 'unit', 'user_agent' => 'agent'); + + + /** + * Constructor + * + * Sets the path to the view files and gets the initial output buffering level + * + * @access public + */ + function CI_Loader() + { + $this->_ci_is_php5 = (floor(phpversion()) >= 5) ? TRUE : FALSE; + $this->_ci_view_path = APPPATH.'views/'; + $this->_ci_ob_level = ob_get_level(); + + log_message('debug', "Loader Class Initialized"); + } + + // -------------------------------------------------------------------- + + /** + * Class Loader + * + * This function lets users load and instantiate classes. + * It is designed to be called from a user's app controllers. + * + * @access public + * @param string the name of the class + * @param mixed the optional parameters + * @param string an optional object name + * @return void + */ + function library($library = '', $params = NULL, $object_name = NULL) + { + if ($library == '') + { + return FALSE; + } + + if ( ! is_null($params) AND ! is_array($params)) + { + $params = NULL; + } + + if (is_array($library)) + { + foreach ($library as $class) + { + $this->_ci_load_class($class, $params, $object_name); + } + } + else + { + $this->_ci_load_class($library, $params, $object_name); + } + + $this->_ci_assign_to_models(); + } + + // -------------------------------------------------------------------- + + /** + * Model Loader + * + * This function lets users load and instantiate models. + * + * @access public + * @param string the name of the class + * @param string name for the model + * @param bool database connection + * @return void + */ + function model($model, $name = '', $db_conn = FALSE) + { + if (is_array($model)) + { + foreach($model as $babe) + { + $this->model($babe); + } + return; + } + + if ($model == '') + { + return; + } + + // Is the model in a sub-folder? If so, parse out the filename and path. + if (strpos($model, '/') === FALSE) + { + $path = ''; + } + else + { + $x = explode('/', $model); + $model = end($x); + unset($x[count($x)-1]); + $path = implode('/', $x).'/'; + } + + 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); + + if ( ! file_exists(APPPATH.'models/'.$path.$model.EXT)) + { + show_error('Unable to locate the model you have specified: '.$model); + } + + 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('Model')) + { + load_class('Model', FALSE); + } + + require_once(APPPATH.'models/'.$path.$model.EXT); + + $model = ucfirst($model); + + $CI->$name = new $model(); + $CI->$name->_assign_libraries(); + + $this->_ci_models[] = $name; + } + + // -------------------------------------------------------------------- + + /** + * Database Loader + * + * @access public + * @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 + */ + function database($params = '', $return = FALSE, $active_record = FALSE) + { + // 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 == FALSE AND isset($CI->db) AND is_object($CI->db)) + { + return FALSE; + } + + require_once(BASEPATH.'database/DB'.EXT); + + 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); + + // Assign the DB object to any existing models + $this->_ci_assign_to_models(); + } + + // -------------------------------------------------------------------- + + /** + * Load the Utilities Class + * + * @access public + * @return string + */ + 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'.EXT); + require_once(BASEPATH.'database/drivers/'.$CI->db->dbdriver.'/'.$CI->db->dbdriver.'_utility'.EXT); + $class = 'CI_DB_'.$CI->db->dbdriver.'_utility'; + + $CI->dbutil =& new $class(); + + $CI->load->_ci_assign_to_models(); + } + + // -------------------------------------------------------------------- + + /** + * Load the Database Forge Class + * + * @access public + * @return string + */ + function dbforge() + { + if ( ! class_exists('CI_DB')) + { + $this->database(); + } + + $CI =& get_instance(); + + require_once(BASEPATH.'database/DB_forge'.EXT); + require_once(BASEPATH.'database/drivers/'.$CI->db->dbdriver.'/'.$CI->db->dbdriver.'_forge'.EXT); + $class = 'CI_DB_'.$CI->db->dbdriver.'_forge'; + + $CI->dbforge = new $class(); + + $CI->load->_ci_assign_to_models(); + } + + // -------------------------------------------------------------------- + + /** + * 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. + * + * @access public + * @param string + * @param array + * @param bool + * @return void + */ + 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 + * + * @access public + * @param string + * @param bool + * @return string + */ + 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. + * + * @access public + * @param array + * @return void + */ + 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; + } + } + } + + // -------------------------------------------------------------------- + + /** + * Load Helper + * + * This function loads the specified helper file. + * + * @access public + * @param mixed + * @return void + */ + function helper($helpers = array()) + { + if ( ! is_array($helpers)) + { + $helpers = array($helpers); + } + + foreach ($helpers as $helper) + { + $helper = strtolower(str_replace(EXT, '', str_replace('_helper', '', $helper)).'_helper'); + + if (isset($this->_ci_helpers[$helper])) + { + continue; + } + + $ext_helper = APPPATH.'helpers/'.config_item('subclass_prefix').$helper.EXT; + + // Is this a helper extension request? + if (file_exists($ext_helper)) + { + $base_helper = BASEPATH.'helpers/'.$helper.EXT; + + if ( ! file_exists($base_helper)) + { + show_error('Unable to load the requested file: helpers/'.$helper.EXT); + } + + include_once($ext_helper); + include_once($base_helper); + } + elseif (file_exists(APPPATH.'helpers/'.$helper.EXT)) + { + include_once(APPPATH.'helpers/'.$helper.EXT); + } + else + { + if (file_exists(BASEPATH.'helpers/'.$helper.EXT)) + { + include_once(BASEPATH.'helpers/'.$helper.EXT); + } + else + { + show_error('Unable to load the requested file: helpers/'.$helper.EXT); + } + } + + $this->_ci_helpers[$helper] = TRUE; + log_message('debug', 'Helper loaded: '.$helper); + } + } + + // -------------------------------------------------------------------- + + /** + * Load Helpers + * + * This is simply an alias to the above function in case the + * user has written the plural form of this function. + * + * @access public + * @param array + * @return void + */ + function helpers($helpers = array()) + { + $this->helper($helpers); + } + + // -------------------------------------------------------------------- + + /** + * Load Plugin + * + * This function loads the specified plugin. + * + * @access public + * @param array + * @return void + */ + function plugin($plugins = array()) + { + if ( ! is_array($plugins)) + { + $plugins = array($plugins); + } + + foreach ($plugins as $plugin) + { + $plugin = strtolower(str_replace(EXT, '', str_replace('_pi', '', $plugin)).'_pi'); + + if (isset($this->_ci_plugins[$plugin])) + { + continue; + } + + if (file_exists(APPPATH.'plugins/'.$plugin.EXT)) + { + include_once(APPPATH.'plugins/'.$plugin.EXT); + } + else + { + if (file_exists(BASEPATH.'plugins/'.$plugin.EXT)) + { + include_once(BASEPATH.'plugins/'.$plugin.EXT); + } + else + { + show_error('Unable to load the requested file: plugins/'.$plugin.EXT); + } + } + + $this->_ci_plugins[$plugin] = TRUE; + log_message('debug', 'Plugin loaded: '.$plugin); + } + } + + // -------------------------------------------------------------------- + + /** + * Load Plugins + * + * This is simply an alias to the above function in case the + * user has written the plural form of this function. + * + * @access public + * @param array + * @return void + */ + function plugins($plugins = array()) + { + $this->plugin($plugins); + } + + // -------------------------------------------------------------------- + + /** + * Loads a language file + * + * @access public + * @param array + * @param string + * @return void + */ + 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 language files for scaffolding + * + * @access public + * @param string + * @return arra + */ + function scaffold_language($file = '', $lang = '', $return = FALSE) + { + $CI =& get_instance(); + return $CI->lang->load($file, $lang, $return); + } + + // -------------------------------------------------------------------- + + /** + * Loads a config file + * + * @access public + * @param string + * @return void + */ + function config($file = '', $use_sections = FALSE, $fail_gracefully = FALSE) + { + $CI =& get_instance(); + $CI->config->load($file, $use_sections, $fail_gracefully); + } + + // -------------------------------------------------------------------- + + /** + * Scaffolding Loader + * + * This initializing function works a bit different than the + * others. It doesn't load the class. Instead, it simply + * sets a flag indicating that scaffolding is allowed to be + * used. The actual scaffolding function below is + * called by the front controller based on whether the + * second segment of the URL matches the "secret" scaffolding + * word stored in the application/config/routes.php + * + * @access public + * @param string + * @return void + */ + function scaffolding($table = '') + { + if ($table === FALSE) + { + show_error('You must include the name of the table you would like to access when you initialize scaffolding'); + } + + $CI =& get_instance(); + $CI->_ci_scaffolding = TRUE; + $CI->_ci_scaff_table = $table; + } + + // -------------------------------------------------------------------- + + /** + * 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 + * + * @access private + * @param array + * @return void + */ + 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]; + } + + // Set the path to the requested file + if ($_ci_path == '') + { + $_ci_ext = pathinfo($_ci_view, PATHINFO_EXTENSION); + $_ci_file = ($_ci_ext == '') ? $_ci_view.EXT : $_ci_view; + $_ci_path = $this->_ci_view_path.$_ci_file; + } + else + { + $_ci_x = explode('/', $_ci_path); + $_ci_file = end($_ci_x); + } + + if ( ! 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. + // Only needed when running PHP 5 + + if ($this->_ci_is_instance()) + { + $_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 + { + // PHP 4 requires that we use a global + global $OUT; + $OUT->append_output(ob_get_contents()); + @ob_end_clean(); + } + } + + // -------------------------------------------------------------------- + + /** + * Load class + * + * This function loads the requested class. + * + * @access private + * @param string the item that is being loaded + * @param mixed any additional parameters + * @param string an optional object name + * @return void + */ + 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(EXT, '', trim($class, '/')); + + // Was the path included with the class name? + // We look for a slash to determine this + $subdir = ''; + if (strpos($class, '/') !== FALSE) + { + // explode the path so we can separate the filename from the path + $x = explode('/', $class); + + // Reset the $class variable now that we know the actual filename + $class = end($x); + + // Kill the filename from the array + unset($x[count($x)-1]); + + // Glue the path back together, sans filename + $subdir = implode($x, '/').'/'; + } + + // 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.EXT; + + // Is this a class extension request? + if (file_exists($subclass)) + { + $baseclass = BASEPATH.'libraries/'.ucfirst($class).EXT; + + 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; + for ($i = 1; $i < 3; $i++) + { + $path = ($i % 2) ? APPPATH : BASEPATH; + $filepath = $path.'libraries/'.$subdir.$class.EXT; + + // 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 + * + * @access private + * @param string + * @param string + * @param string an optional object name + * @return null + */ + function _ci_init_class($class, $prefix = '', $config = FALSE, $object_name = NULL) + { + // Is there an associated config file for this class? + if ($config === NULL) + { + // We test for both uppercase and lowercase, for servers that + // are case-sensitive with regard to file names + if (file_exists(APPPATH.'config/'.strtolower($class).EXT)) + { + include_once(APPPATH.'config/'.strtolower($class).EXT); + } + else + { + if (file_exists(APPPATH.'config/'.ucfirst(strtolower($class)).EXT)) + { + include_once(APPPATH.'config/'.ucfirst(strtolower($class)).EXT); + } + } + } + + 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, plugins, and helpers to be loaded automatically. + * + * @access private + * @param array + * @return void + */ + function _ci_autoloader() + { + include_once(APPPATH.'config/autoload'.EXT); + + if ( ! isset($autoload)) + { + return FALSE; + } + + // Load any custom config file + if (count($autoload['config']) > 0) + { + $CI =& get_instance(); + foreach ($autoload['config'] as $key => $val) + { + $CI->config->load($val); + } + } + + // Autoload plugins, helpers and languages + foreach (array('helper', 'plugin', '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'])) + { + $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 scaffolding + if (in_array('scaffolding', $autoload['libraries'])) + { + $this->scaffolding(); + $autoload['libraries'] = array_diff($autoload['libraries'], array('scaffolding')); + } + + // Load all other libraries + foreach ($autoload['libraries'] as $item) + { + $this->library($item); + } + } + + // Autoload models + if (isset($autoload['model'])) + { + $this->model($autoload['model']); + } + + } + + // -------------------------------------------------------------------- + + /** + * Assign to Models + * + * Makes sure that anything loaded by the loader class (libraries, plugins, etc.) + * will be available to models, if any exist. + * + * @access private + * @param object + * @return array + */ + function _ci_assign_to_models() + { + if (count($this->_ci_models) == 0) + { + return; + } + + if ($this->_ci_is_instance()) + { + $CI =& get_instance(); + foreach ($this->_ci_models as $model) + { + $CI->$model->_assign_libraries(); + } + } + else + { + foreach ($this->_ci_models as $model) + { + $this->$model->_assign_libraries(); + } + } + } + + // -------------------------------------------------------------------- + + /** + * Object to Array + * + * Takes an object as input and converts the class variables to array key/vals + * + * @access private + * @param object + * @return array + */ + function _ci_object_to_array($object) + { + return (is_object($object)) ? get_object_vars($object) : $object; + } + + // -------------------------------------------------------------------- + + /** + * Determines whether we should use the CI instance or $this + * + * @access private + * @return bool + */ + function _ci_is_instance() + { + if ($this->_ci_is_php5 == TRUE) + { + return TRUE; + } + + global $CI; + return (is_object($CI)) ? TRUE : FALSE; + } + +} + +/* End of file Loader.php */ /* Location: ./system/libraries/Loader.php */ \ No newline at end of file diff --git a/system/libraries/Log.php b/system/libraries/Log.php index 811c87376..326edaa38 100644 --- a/system/libraries/Log.php +++ b/system/libraries/Log.php @@ -1,117 +1,117 @@ - '1', 'DEBUG' => '2', 'INFO' => '3', 'ALL' => '4'); - - /** - * Constructor - * - * @access public - */ - function CI_Log() - { - $config =& get_config(); - - $this->log_path = ($config['log_path'] != '') ? $config['log_path'] : BASEPATH.'logs/'; - - if ( ! is_dir($this->log_path) OR ! is_really_writable($this->log_path)) - { - $this->_enabled = FALSE; - } - - if (is_numeric($config['log_threshold'])) - { - $this->_threshold = $config['log_threshold']; - } - - if ($config['log_date_format'] != '') - { - $this->_date_fmt = $config['log_date_format']; - } - } - - // -------------------------------------------------------------------- - - /** - * Write Log File - * - * Generally this function will be called using the global log_message() function - * - * @access public - * @param string the error level - * @param string the error message - * @param bool whether the error is a native PHP error - * @return bool - */ - function write_log($level = 'error', $msg, $php_error = FALSE) - { - if ($this->_enabled === FALSE) - { - return FALSE; - } - - $level = strtoupper($level); - - if ( ! isset($this->_levels[$level]) OR ($this->_levels[$level] > $this->_threshold)) - { - return FALSE; - } - - $filepath = $this->log_path.'log-'.date('Y-m-d').EXT; - $message = ''; - - if ( ! file_exists($filepath)) - { - $message .= "<"."?php if ( ! defined('BASEPATH')) exit('No direct script access allowed'); ?".">\n\n"; - } - - if ( ! $fp = @fopen($filepath, FOPEN_WRITE_CREATE)) - { - return FALSE; - } - - $message .= $level.' '.(($level == 'INFO') ? ' -' : '-').' '.date($this->_date_fmt). ' --> '.$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 */ + '1', 'DEBUG' => '2', 'INFO' => '3', 'ALL' => '4'); + + /** + * Constructor + * + * @access public + */ + function CI_Log() + { + $config =& get_config(); + + $this->log_path = ($config['log_path'] != '') ? $config['log_path'] : BASEPATH.'logs/'; + + if ( ! is_dir($this->log_path) OR ! is_really_writable($this->log_path)) + { + $this->_enabled = FALSE; + } + + if (is_numeric($config['log_threshold'])) + { + $this->_threshold = $config['log_threshold']; + } + + if ($config['log_date_format'] != '') + { + $this->_date_fmt = $config['log_date_format']; + } + } + + // -------------------------------------------------------------------- + + /** + * Write Log File + * + * Generally this function will be called using the global log_message() function + * + * @access public + * @param string the error level + * @param string the error message + * @param bool whether the error is a native PHP error + * @return bool + */ + function write_log($level = 'error', $msg, $php_error = FALSE) + { + if ($this->_enabled === FALSE) + { + return FALSE; + } + + $level = strtoupper($level); + + if ( ! isset($this->_levels[$level]) OR ($this->_levels[$level] > $this->_threshold)) + { + return FALSE; + } + + $filepath = $this->log_path.'log-'.date('Y-m-d').EXT; + $message = ''; + + if ( ! file_exists($filepath)) + { + $message .= "<"."?php if ( ! defined('BASEPATH')) exit('No direct script access allowed'); ?".">\n\n"; + } + + if ( ! $fp = @fopen($filepath, FOPEN_WRITE_CREATE)) + { + return FALSE; + } + + $message .= $level.' '.(($level == 'INFO') ? ' -' : '-').' '.date($this->_date_fmt). ' --> '.$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/Model.php b/system/libraries/Model.php index 1d3cbdfa0..c4cba562e 100644 --- a/system/libraries/Model.php +++ b/system/libraries/Model.php @@ -1,83 +1,83 @@ -_assign_libraries( (method_exists($this, '__get') OR method_exists($this, '__set')) ? FALSE : TRUE ); - - // We don't want to assign the model object to itself when using the - // assign_libraries function below so we'll grab the name of the model parent - $this->_parent_name = ucfirst(get_class($this)); - - log_message('debug', "Model Class Initialized"); - } - - /** - * Assign Libraries - * - * Creates local references to all currently instantiated objects - * so that any syntax that can be legally used in a controller - * can be used within models. - * - * @access private - */ - function _assign_libraries($use_reference = TRUE) - { - $CI =& get_instance(); - foreach (array_keys(get_object_vars($CI)) as $key) - { - if ( ! isset($this->$key) AND $key != $this->_parent_name) - { - // In some cases using references can cause - // problems so we'll conditionally use them - if ($use_reference == TRUE) - { - $this->$key = NULL; // Needed to prevent reference errors with some configurations - $this->$key =& $CI->$key; - } - else - { - $this->$key = $CI->$key; - } - } - } - } - -} -// END Model Class - -/* End of file Model.php */ +_assign_libraries( (method_exists($this, '__get') OR method_exists($this, '__set')) ? FALSE : TRUE ); + + // We don't want to assign the model object to itself when using the + // assign_libraries function below so we'll grab the name of the model parent + $this->_parent_name = ucfirst(get_class($this)); + + log_message('debug', "Model Class Initialized"); + } + + /** + * Assign Libraries + * + * Creates local references to all currently instantiated objects + * so that any syntax that can be legally used in a controller + * can be used within models. + * + * @access private + */ + function _assign_libraries($use_reference = TRUE) + { + $CI =& get_instance(); + foreach (array_keys(get_object_vars($CI)) as $key) + { + if ( ! isset($this->$key) AND $key != $this->_parent_name) + { + // In some cases using references can cause + // problems so we'll conditionally use them + if ($use_reference == TRUE) + { + $this->$key = NULL; // Needed to prevent reference errors with some configurations + $this->$key =& $CI->$key; + } + else + { + $this->$key = $CI->$key; + } + } + } + } + +} +// END Model Class + +/* End of file Model.php */ /* Location: ./system/libraries/Model.php */ \ No newline at end of file diff --git a/system/libraries/Output.php b/system/libraries/Output.php index 98a941af5..b93963a39 100644 --- a/system/libraries/Output.php +++ b/system/libraries/Output.php @@ -1,478 +1,478 @@ -final_output; - } - - // -------------------------------------------------------------------- - - /** - * Set Output - * - * Sets the output string - * - * @access public - * @param string - * @return void - */ - function set_output($output) - { - $this->final_output = $output; - } - - // -------------------------------------------------------------------- - - /** - * 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; - } - } - - // -------------------------------------------------------------------- - - /** - * 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 - * @return void - */ - function set_header($header, $replace = TRUE) - { - $this->headers[] = array($header, $replace); - } - - // -------------------------------------------------------------------- - - /** - * Set HTTP Status Header - * - * @access public - * @param int the status code - * @param string - * @return void - */ - 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'); - } - - 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.'); - } - - $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); - } - } - - // -------------------------------------------------------------------- - - /** - * Enable/disable Profiler - * - * @access public - * @param bool - * @return void - */ - function enable_profiler($val = TRUE) - { - $this->enable_profiler = (is_bool($val)) ? $val : TRUE; - } - - // -------------------------------------------------------------------- - - /** - * Set Cache - * - * @access public - * @param integer - * @return void - */ - function cache($time) - { - $this->cache_expiration = ( ! is_numeric($time)) ? 0 : $time; - } - - // -------------------------------------------------------------------- - - /** - * 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 - * @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; - - // -------------------------------------------------------------------- - - // Set the output data - if ($output == '') - { - $output =& $this->final_output; - } - - // -------------------------------------------------------------------- - - // Do we need to write a cache file? - if ($this->cache_expiration > 0) - { - $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'); - $output = str_replace('{elapsed_time}', $elapsed, $output); - - $memory = ( ! function_exists('memory_get_usage')) ? '0' : round(memory_get_usage()/1024/1024, 2).'MB'; - $output = str_replace('{memory_usage}', $memory, $output); - - // -------------------------------------------------------------------- - - // Is compression requested? - if ($CFG->item('compress_output') === TRUE) - { - 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 get_instance() function exist? - // If not we know we are dealing with a cache file so we'll - // simply echo out the data and exit. - if ( ! function_exists('get_instance')) - { - echo $output; - log_message('debug', "Final output sent to browser"); - log_message('debug', "Total execution time: ".$elapsed); - return TRUE; - } - - // -------------------------------------------------------------------- - - // Grab the super object. We'll need it in a moment... - $CI =& get_instance(); - - // 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 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 - * @return void - */ - function _write_cache($output) - { - $CI =& get_instance(); - $path = $CI->config->item('cache_path'); - - $cache_path = ($path == '') ? BASEPATH.'cache/' : $path; - - if ( ! is_dir($cache_path) OR ! is_really_writable($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, DIR_WRITE_MODE); - - log_message('debug', "Cache file written: ".$cache_path); - } - - // -------------------------------------------------------------------- - - /** - * Update/serve a cached file - * - * @access public - * @return void - */ - function _display_cache(&$CFG, &$URI) - { - $cache_path = ($CFG->item('cache_path') == '') ? BASEPATH.'cache/' : $CFG->item('cache_path'); - - if ( ! is_dir($cache_path) OR ! is_really_writable($cache_path)) - { - return FALSE; - } - - // 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']))) - { - @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; - } - - -} -// END Output Class - -/* End of file Output.php */ +final_output; + } + + // -------------------------------------------------------------------- + + /** + * Set Output + * + * Sets the output string + * + * @access public + * @param string + * @return void + */ + function set_output($output) + { + $this->final_output = $output; + } + + // -------------------------------------------------------------------- + + /** + * 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; + } + } + + // -------------------------------------------------------------------- + + /** + * 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 + * @return void + */ + function set_header($header, $replace = TRUE) + { + $this->headers[] = array($header, $replace); + } + + // -------------------------------------------------------------------- + + /** + * Set HTTP Status Header + * + * @access public + * @param int the status code + * @param string + * @return void + */ + 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'); + } + + 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.'); + } + + $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); + } + } + + // -------------------------------------------------------------------- + + /** + * Enable/disable Profiler + * + * @access public + * @param bool + * @return void + */ + function enable_profiler($val = TRUE) + { + $this->enable_profiler = (is_bool($val)) ? $val : TRUE; + } + + // -------------------------------------------------------------------- + + /** + * Set Cache + * + * @access public + * @param integer + * @return void + */ + function cache($time) + { + $this->cache_expiration = ( ! is_numeric($time)) ? 0 : $time; + } + + // -------------------------------------------------------------------- + + /** + * 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 + * @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; + + // -------------------------------------------------------------------- + + // Set the output data + if ($output == '') + { + $output =& $this->final_output; + } + + // -------------------------------------------------------------------- + + // Do we need to write a cache file? + if ($this->cache_expiration > 0) + { + $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'); + $output = str_replace('{elapsed_time}', $elapsed, $output); + + $memory = ( ! function_exists('memory_get_usage')) ? '0' : round(memory_get_usage()/1024/1024, 2).'MB'; + $output = str_replace('{memory_usage}', $memory, $output); + + // -------------------------------------------------------------------- + + // Is compression requested? + if ($CFG->item('compress_output') === TRUE) + { + 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 get_instance() function exist? + // If not we know we are dealing with a cache file so we'll + // simply echo out the data and exit. + if ( ! function_exists('get_instance')) + { + echo $output; + log_message('debug', "Final output sent to browser"); + log_message('debug', "Total execution time: ".$elapsed); + return TRUE; + } + + // -------------------------------------------------------------------- + + // Grab the super object. We'll need it in a moment... + $CI =& get_instance(); + + // 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 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 + * @return void + */ + function _write_cache($output) + { + $CI =& get_instance(); + $path = $CI->config->item('cache_path'); + + $cache_path = ($path == '') ? BASEPATH.'cache/' : $path; + + if ( ! is_dir($cache_path) OR ! is_really_writable($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, DIR_WRITE_MODE); + + log_message('debug', "Cache file written: ".$cache_path); + } + + // -------------------------------------------------------------------- + + /** + * Update/serve a cached file + * + * @access public + * @return void + */ + function _display_cache(&$CFG, &$URI) + { + $cache_path = ($CFG->item('cache_path') == '') ? BASEPATH.'cache/' : $CFG->item('cache_path'); + + if ( ! is_dir($cache_path) OR ! is_really_writable($cache_path)) + { + return FALSE; + } + + // 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']))) + { + @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; + } + + +} +// END Output Class + +/* End of file Output.php */ /* Location: ./system/libraries/Output.php */ \ No newline at end of file diff --git a/system/libraries/Pagination.php b/system/libraries/Pagination.php index ed912d26a..09b5bec84 100644 --- a/system/libraries/Pagination.php +++ b/system/libraries/Pagination.php @@ -1,244 +1,244 @@ -'; - 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'; - - /** - * Constructor - * - * @access public - * @param array initialization parameters - */ - function CI_Pagination($params = array()) - { - if (count($params) > 0) - { - $this->initialize($params); - } - - 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 ''; - } - - // 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) != 0) - { - $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) != 0) - { - $this->cur_page = $CI->uri->segment($this->uri_segment); - - // Prep the current page - no funny business! - $this->cur_page = (int) $this->cur_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 = 0; - } - - // Is the page number beyond the result range? - // If so we show the last page - if ($this->cur_page > $this->total_rows) - { - $this->cur_page = ($num_pages - 1) * $this->per_page; - } - - $uri_page_number = $this->cur_page; - $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->cur_page > ($this->num_links + 1)) - { - $output .= $this->first_tag_open.''.$this->first_link.''.$this->first_tag_close; - } - - // Render the "previous" link - if ($this->cur_page != 1) - { - $i = $uri_page_number - $this->per_page; - if ($i == 0) $i = ''; - $output .= $this->prev_tag_open.''.$this->prev_link.''.$this->prev_tag_close; - } - - // Write the digit links - for ($loop = $start -1; $loop <= $end; $loop++) - { - $i = ($loop * $this->per_page) - $this->per_page; - - if ($i >= 0) - { - if ($this->cur_page == $loop) - { - $output .= $this->cur_tag_open.$loop.$this->cur_tag_close; // Current page - } - else - { - $n = ($i == 0) ? '' : $i; - $output .= $this->num_tag_open.''.$loop.''.$this->num_tag_close; - } - } - } - - // Render the "next" link - if ($this->cur_page < $num_pages) - { - $output .= $this->next_tag_open.''.$this->next_link.''.$this->next_tag_close; - } - - // Render the "Last" link - if (($this->cur_page + $this->num_links) < $num_pages) - { - $i = (($num_pages * $this->per_page) - $this->per_page); - $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 - $output = $this->full_tag_open.$output.$this->full_tag_close; - - return $output; - } -} -// END Pagination Class - -/* End of file Pagination.php */ +'; + 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'; + + /** + * Constructor + * + * @access public + * @param array initialization parameters + */ + function CI_Pagination($params = array()) + { + if (count($params) > 0) + { + $this->initialize($params); + } + + 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 ''; + } + + // 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) != 0) + { + $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) != 0) + { + $this->cur_page = $CI->uri->segment($this->uri_segment); + + // Prep the current page - no funny business! + $this->cur_page = (int) $this->cur_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 = 0; + } + + // Is the page number beyond the result range? + // If so we show the last page + if ($this->cur_page > $this->total_rows) + { + $this->cur_page = ($num_pages - 1) * $this->per_page; + } + + $uri_page_number = $this->cur_page; + $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->cur_page > ($this->num_links + 1)) + { + $output .= $this->first_tag_open.''.$this->first_link.''.$this->first_tag_close; + } + + // Render the "previous" link + if ($this->cur_page != 1) + { + $i = $uri_page_number - $this->per_page; + if ($i == 0) $i = ''; + $output .= $this->prev_tag_open.''.$this->prev_link.''.$this->prev_tag_close; + } + + // Write the digit links + for ($loop = $start -1; $loop <= $end; $loop++) + { + $i = ($loop * $this->per_page) - $this->per_page; + + if ($i >= 0) + { + if ($this->cur_page == $loop) + { + $output .= $this->cur_tag_open.$loop.$this->cur_tag_close; // Current page + } + else + { + $n = ($i == 0) ? '' : $i; + $output .= $this->num_tag_open.''.$loop.''.$this->num_tag_close; + } + } + } + + // Render the "next" link + if ($this->cur_page < $num_pages) + { + $output .= $this->next_tag_open.''.$this->next_link.''.$this->next_tag_close; + } + + // Render the "Last" link + if (($this->cur_page + $this->num_links) < $num_pages) + { + $i = (($num_pages * $this->per_page) - $this->per_page); + $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 + $output = $this->full_tag_open.$output.$this->full_tag_close; + + return $output; + } +} +// END Pagination Class + +/* 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 index e276a0d07..3d379b221 100644 --- a/system/libraries/Parser.php +++ b/system/libraries/Parser.php @@ -1,173 +1,173 @@ -load->view($template, $data, TRUE); - - 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->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("|".$this->l_delim . $variable . $this->r_delim."(.+?)".$this->l_delim . '/' . $variable . $this->r_delim."|s", $string, $match)) - { - return FALSE; - } - - return $match; - } - -} -// END Parser Class - -/* End of file Parser.php */ +load->view($template, $data, TRUE); + + 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->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("|".$this->l_delim . $variable . $this->r_delim."(.+?)".$this->l_delim . '/' . $variable . $this->r_delim."|s", $string, $match)) + { + return FALSE; + } + + return $match; + } + +} +// END Parser Class + +/* End of file Parser.php */ /* Location: ./system/libraries/Parser.php */ \ No newline at end of file diff --git a/system/libraries/Profiler.php b/system/libraries/Profiler.php index 7f869f46f..5e9fa8bf4 100644 --- a/system/libraries/Profiler.php +++ b/system/libraries/Profiler.php @@ -1,392 +1,392 @@ -CI =& get_instance(); - $this->CI->load->language('profiler'); - } - - // -------------------------------------------------------------------- - - /** - * 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 - * - * @access private - * @return array - */ - 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 - * - * @access private - * @return string - */ - 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_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"; - - foreach ($dbs as $db) - { - $output .= '
    '; - $output .= "\n"; - $output .= '  '.$this->CI->lang->line('profiler_database').':  '.$db->database.'   '.$this->CI->lang->line('profiler_queries').': '.count($this->CI->db->queries).'   '; - $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 - * - * @access private - * @return string - */ - 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 - * - * @access private - * @return string - */ - 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 - * - * @access private - * @return string - */ - 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 - * - * @access private - * @return string - */ - 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 - * - * @access public - * @return string - */ - 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_usage')."
    "; - } - - $output .= "
    "; - - return $output; - } - - // -------------------------------------------------------------------- - - /** - * Run the Profiler - * - * @access private - * @return string - */ - function run() - { - $output = "
    "; - - $output .= $this->_compile_uri_string(); - $output .= $this->_compile_controller_info(); - $output .= $this->_compile_memory_usage(); - $output .= $this->_compile_benchmarks(); - $output .= $this->_compile_get(); - $output .= $this->_compile_post(); - $output .= $this->_compile_queries(); - - $output .= '
    '; - - return $output; - } - -} - -// END CI_Profiler class - -/* End of file Profiler.php */ +CI =& get_instance(); + $this->CI->load->language('profiler'); + } + + // -------------------------------------------------------------------- + + /** + * 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 + * + * @access private + * @return array + */ + 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 + * + * @access private + * @return string + */ + 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_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"; + + foreach ($dbs as $db) + { + $output .= '
    '; + $output .= "\n"; + $output .= '  '.$this->CI->lang->line('profiler_database').':  '.$db->database.'   '.$this->CI->lang->line('profiler_queries').': '.count($this->CI->db->queries).'   '; + $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 + * + * @access private + * @return string + */ + 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 + * + * @access private + * @return string + */ + 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 + * + * @access private + * @return string + */ + 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 + * + * @access private + * @return string + */ + 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 + * + * @access public + * @return string + */ + 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_usage')."
    "; + } + + $output .= "
    "; + + return $output; + } + + // -------------------------------------------------------------------- + + /** + * Run the Profiler + * + * @access private + * @return string + */ + function run() + { + $output = "
    "; + + $output .= $this->_compile_uri_string(); + $output .= $this->_compile_controller_info(); + $output .= $this->_compile_memory_usage(); + $output .= $this->_compile_benchmarks(); + $output .= $this->_compile_get(); + $output .= $this->_compile_post(); + $output .= $this->_compile_queries(); + + $output .= '
    '; + + return $output; + } + +} + +// END CI_Profiler class + +/* End of file Profiler.php */ /* Location: ./system/libraries/Profiler.php */ \ No newline at end of file diff --git a/system/libraries/Router.php b/system/libraries/Router.php index cf425163d..32de58dbf 100644 --- a/system/libraries/Router.php +++ b/system/libraries/Router.php @@ -1,385 +1,385 @@ -config =& load_class('Config'); - $this->uri =& load_class('URI'); - $this->_set_routing(); - 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? - // If so, we're done since segment based URIs are not used with query strings. - if ($this->config->item('enable_query_strings') === TRUE AND isset($_GET[$this->config->item('controller_trigger')])) - { - $this->set_class(trim($this->uri->_filter_uri($_GET[$this->config->item('controller_trigger')]))); - - if (isset($_GET[$this->config->item('function_trigger')])) - { - $this->set_method(trim($this->uri->_filter_uri($_GET[$this->config->item('function_trigger')]))); - } - - return; - } - - // Load the routes.php file. - @include(APPPATH.'config/routes'.EXT); - $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']); - - // 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 == '') - { - 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."); - } - - // Turn the default route into an array. We explode it in the event that - // the controller is located in a subfolder - $segments = $this->_validate_request(explode('/', $this->default_controller)); - - // Set the class and method - $this->set_class($segments[0]); - $this->set_method('index'); - - // Assign the segments to the URI class - $this->uri->rsegments = $segments; - - // 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."); - return; - } - unset($this->routes['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 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_class($segments[0]); - - if (isset($segments[1])) - { - // A scaffolding request. No funny business with the URL - if ($this->routes['scaffolding_trigger'] == $segments[1] AND $segments[1] != '_ci_scaffolding') - { - $this->scaffolding_request = TRUE; - unset($this->routes['scaffolding_trigger']); - } - else - { - // 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) - { - // Does the requested controller exist in the root folder? - if (file_exists(APPPATH.'controllers/'.$segments[0].EXT)) - { - 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].EXT)) - { - show_404($this->fetch_directory().$segments[0]); - } - } - 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.EXT)) - { - $this->directory = ''; - return array(); - } - - } - - return $segments; - } - - // Can't find the requested controller... - 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() - { - // Do we even have any custom routing to deal with? - // There is a default scaffolding trigger, so we'll look just for 1 - if (count($this->routes) == 1) - { - $this->_set_request($this->uri->segments); - return; - } - - // 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])) - { - $this->_set_request(explode('/', $this->routes[$uri])); - return; - } - - // 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); - } - - $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($this->uri->segments); - } - - // -------------------------------------------------------------------- - - /** - * Set the class name - * - * @access public - * @param string - * @return void - */ - function set_class($class) - { - $this->class = $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 = $dir.'/'; - } - - // -------------------------------------------------------------------- - - /** - * Fetch the sub-directory (if any) that contains the requested controller class - * - * @access public - * @return string - */ - function fetch_directory() - { - return $this->directory; - } - -} -// END Router Class - -/* End of file Router.php */ +config =& load_class('Config'); + $this->uri =& load_class('URI'); + $this->_set_routing(); + 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? + // If so, we're done since segment based URIs are not used with query strings. + if ($this->config->item('enable_query_strings') === TRUE AND isset($_GET[$this->config->item('controller_trigger')])) + { + $this->set_class(trim($this->uri->_filter_uri($_GET[$this->config->item('controller_trigger')]))); + + if (isset($_GET[$this->config->item('function_trigger')])) + { + $this->set_method(trim($this->uri->_filter_uri($_GET[$this->config->item('function_trigger')]))); + } + + return; + } + + // Load the routes.php file. + @include(APPPATH.'config/routes'.EXT); + $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']); + + // 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 == '') + { + 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."); + } + + // Turn the default route into an array. We explode it in the event that + // the controller is located in a subfolder + $segments = $this->_validate_request(explode('/', $this->default_controller)); + + // Set the class and method + $this->set_class($segments[0]); + $this->set_method('index'); + + // Assign the segments to the URI class + $this->uri->rsegments = $segments; + + // 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."); + return; + } + unset($this->routes['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 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_class($segments[0]); + + if (isset($segments[1])) + { + // A scaffolding request. No funny business with the URL + if ($this->routes['scaffolding_trigger'] == $segments[1] AND $segments[1] != '_ci_scaffolding') + { + $this->scaffolding_request = TRUE; + unset($this->routes['scaffolding_trigger']); + } + else + { + // 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) + { + // Does the requested controller exist in the root folder? + if (file_exists(APPPATH.'controllers/'.$segments[0].EXT)) + { + 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].EXT)) + { + show_404($this->fetch_directory().$segments[0]); + } + } + 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.EXT)) + { + $this->directory = ''; + return array(); + } + + } + + return $segments; + } + + // Can't find the requested controller... + 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() + { + // Do we even have any custom routing to deal with? + // There is a default scaffolding trigger, so we'll look just for 1 + if (count($this->routes) == 1) + { + $this->_set_request($this->uri->segments); + return; + } + + // 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])) + { + $this->_set_request(explode('/', $this->routes[$uri])); + return; + } + + // 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); + } + + $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($this->uri->segments); + } + + // -------------------------------------------------------------------- + + /** + * Set the class name + * + * @access public + * @param string + * @return void + */ + function set_class($class) + { + $this->class = $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 = $dir.'/'; + } + + // -------------------------------------------------------------------- + + /** + * Fetch the sub-directory (if any) that contains the requested controller class + * + * @access public + * @return string + */ + function fetch_directory() + { + return $this->directory; + } + +} +// END Router Class + +/* End of file Router.php */ /* Location: ./system/libraries/Router.php */ \ No newline at end of file diff --git a/system/libraries/Session.php b/system/libraries/Session.php index 25bf21fb1..660ce8f16 100644 --- a/system/libraries/Session.php +++ b/system/libraries/Session.php @@ -1,758 +1,758 @@ -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_match_ip', 'sess_match_useragent', 'sess_cookie_name', 'cookie_path', 'cookie_domain', 'sess_time_to_update', 'time_reference', 'cookie_prefix', 'encryption_key') as $key) - { - $this->$key = (isset($params[$key])) ? $params[$key] : $this->CI->config->item($key); - } - - // 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; - } - - // Decrypt the cookie data - if ($this->sess_encrypt_cookie == TRUE) - { - $session = $this->CI->encrypt->decode($session); - } - else - { - // encryption was not used, so we need to check the md5 hash - $hash = substr($session, strlen($session)-32); // get last 32 chars - $session = substr($session, 0, strlen($session)-32); - - // Does the md5 hash match? This is to prevent manipulation of session data in userspace - if ($hash !== md5($session.$this->encryption_key)) - { - log_message('error', 'The session cookie data did not match what was expected. This could be a possible hacking attempt.'); - $this->sess_destroy(); - return FALSE; - } - } - - // Unserialize the session array - $session = $this->_unserialize($session); - - // Is the session data we unserialized an array with the correct format? - if ( ! is_array($session) OR ! isset($session['session_id']) 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, 50))) - { - $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, 50), - 'last_activity' => $this->now - ); - - - // 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->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 AND 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 - ); - } - - // -------------------------------------------------------------------- - - /** - * 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 mixed - */ - function all_userdata() - { - return ( ! isset($this->userdata)) ? FALSE : $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); - } - else - { - // if encryption is not used, we provide an md5 hash to prevent userside tampering - $cookie_data = $cookie_data.md5($cookie_data.$this->encryption_key); - } - - // Set the cookie - setcookie( - $this->sess_cookie_name, - $cookie_data, - $this->sess_expiration + time(), - $this->cookie_path, - $this->cookie_domain, - 0 - ); - } - - // -------------------------------------------------------------------- - - /** - * 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) - { - $data[$key] = str_replace('\\', '{{slash}}', $val); - } - } - else - { - $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) - { - $data[$key] = str_replace('{{slash}}', '\\', $val); - } - - return $data; - } - - return str_replace('{{slash}}', '\\', $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 */ +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_match_ip', 'sess_match_useragent', 'sess_cookie_name', 'cookie_path', 'cookie_domain', 'sess_time_to_update', 'time_reference', 'cookie_prefix', 'encryption_key') as $key) + { + $this->$key = (isset($params[$key])) ? $params[$key] : $this->CI->config->item($key); + } + + // 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; + } + + // Decrypt the cookie data + if ($this->sess_encrypt_cookie == TRUE) + { + $session = $this->CI->encrypt->decode($session); + } + else + { + // encryption was not used, so we need to check the md5 hash + $hash = substr($session, strlen($session)-32); // get last 32 chars + $session = substr($session, 0, strlen($session)-32); + + // Does the md5 hash match? This is to prevent manipulation of session data in userspace + if ($hash !== md5($session.$this->encryption_key)) + { + log_message('error', 'The session cookie data did not match what was expected. This could be a possible hacking attempt.'); + $this->sess_destroy(); + return FALSE; + } + } + + // Unserialize the session array + $session = $this->_unserialize($session); + + // Is the session data we unserialized an array with the correct format? + if ( ! is_array($session) OR ! isset($session['session_id']) 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, 50))) + { + $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, 50), + 'last_activity' => $this->now + ); + + + // 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->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 AND 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 + ); + } + + // -------------------------------------------------------------------- + + /** + * 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 mixed + */ + function all_userdata() + { + return ( ! isset($this->userdata)) ? FALSE : $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); + } + else + { + // if encryption is not used, we provide an md5 hash to prevent userside tampering + $cookie_data = $cookie_data.md5($cookie_data.$this->encryption_key); + } + + // Set the cookie + setcookie( + $this->sess_cookie_name, + $cookie_data, + $this->sess_expiration + time(), + $this->cookie_path, + $this->cookie_domain, + 0 + ); + } + + // -------------------------------------------------------------------- + + /** + * 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) + { + $data[$key] = str_replace('\\', '{{slash}}', $val); + } + } + else + { + $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) + { + $data[$key] = str_replace('{{slash}}', '\\', $val); + } + + return $data; + } + + return str_replace('{{slash}}', '\\', $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 */ \ No newline at end of file diff --git a/system/libraries/Sha1.php b/system/libraries/Sha1.php index 282cdb220..93982bfc4 100644 --- a/system/libraries/Sha1.php +++ b/system/libraries/Sha1.php @@ -1,251 +1,251 @@ -> 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 < sizeof($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 */ +> 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 < sizeof($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 index 6940ece66..1afc17ce3 100644 --- a/system/libraries/Table.php +++ b/system/libraries/Table.php @@ -1,440 +1,440 @@ -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 = (is_array($args[0])) ? $args[0] : $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[] = (is_array($args[0])) ? $args[0] : $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(); - - - // 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['heading_row_start']; - $out .= $this->newline; - - foreach($this->heading as $heading) - { - $out .= $this->template['heading_cell_start']; - $out .= $heading; - $out .= $this->template['heading_cell_end']; - } - - $out .= $this->template['heading_row_end']; - $out .= $this->newline; - } - - // Build the table rows - if (count($this->rows) > 0) - { - $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) - { - $out .= $this->template['cell_'.$name.'start']; - - if ($cell === "") - { - $out .= $this->empty_cells; - } - else - { - $out .= $cell; - } - - $out .= $this->template['cell_'.$name.'end']; - } - - $out .= $this->template['row_'.$name.'end']; - $out .= $this->newline; - } - } - - $out .= $this->template['table_close']; - - 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 = $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[] = $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 ( ! is_array($row)) - { - $this->rows[] = $data; - break; - } - - // 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 = $row; - } - else - { - $this->rows[] = $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','heading_row_start', 'heading_row_end', 'heading_cell_start', 'heading_cell_end', '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' => '', - - 'heading_row_start' => '', - 'heading_row_end' => '', - 'heading_cell_start' => '', - - '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 */ +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 = (is_array($args[0])) ? $args[0] : $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[] = (is_array($args[0])) ? $args[0] : $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(); + + + // 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['heading_row_start']; + $out .= $this->newline; + + foreach($this->heading as $heading) + { + $out .= $this->template['heading_cell_start']; + $out .= $heading; + $out .= $this->template['heading_cell_end']; + } + + $out .= $this->template['heading_row_end']; + $out .= $this->newline; + } + + // Build the table rows + if (count($this->rows) > 0) + { + $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) + { + $out .= $this->template['cell_'.$name.'start']; + + if ($cell === "") + { + $out .= $this->empty_cells; + } + else + { + $out .= $cell; + } + + $out .= $this->template['cell_'.$name.'end']; + } + + $out .= $this->template['row_'.$name.'end']; + $out .= $this->newline; + } + } + + $out .= $this->template['table_close']; + + 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 = $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[] = $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 ( ! is_array($row)) + { + $this->rows[] = $data; + break; + } + + // 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 = $row; + } + else + { + $this->rows[] = $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','heading_row_start', 'heading_row_end', 'heading_cell_start', 'heading_cell_end', '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' => '', + + 'heading_row_start' => '', + 'heading_row_end' => '', + 'heading_cell_start' => '', + + '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 index 998849239..844e50364 100644 --- a/system/libraries/Trackback.php +++ b/system/libraries/Trackback.php @@ -1,550 +1,550 @@ - '', 'title' => '', 'excerpt' => '', 'blog_name' => '', 'charset' => ''); - var $convert_ascii = TRUE; - var $response = ''; - var $error_msg = array(); - - /** - * Constructor - * - * @access public - */ - function CI_Trackback() - { - 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 ( ! eregi("0", $this->response)) - { - $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 (strstr($url, '?')) - { - $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 - { - if (ereg("/$", $url)) - { - $url = substr($url, 0, -1); - } - - $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; - } - -} -// END Trackback Class - -/* End of file Trackback.php */ + '', 'title' => '', 'excerpt' => '', 'blog_name' => '', 'charset' => ''); + var $convert_ascii = TRUE; + var $response = ''; + var $error_msg = array(); + + /** + * Constructor + * + * @access public + */ + function CI_Trackback() + { + 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 ( ! eregi("0", $this->response)) + { + $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 (strstr($url, '?')) + { + $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 + { + if (ereg("/$", $url)) + { + $url = substr($url, 0, -1); + } + + $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; + } + +} +// 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 index 3ff0d2f58..29b871e23 100644 --- a/system/libraries/Typography.php +++ b/system/libraries/Typography.php @@ -1,385 +1,385 @@ - 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'; - - // 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'; - - // whether or not to protect quotes within { curly braces } - var $protect_braced_quotes = FALSE; - - /** - * Nothing to do here... - * - */ - function CI_Typography() - { - } - - /** - * 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); - } - - // Convert quotes within tags to temporary markers. We don't want quotes converted - // within tags so we'll temporarily convert them to {@DQ} and {@SQ} - // and we don't want double dashes converted to emdash entities, so they are marked with {@DD} - // likewise double spaces are converted to {@NBS} to prevent entity conversion - if (preg_match_all("#\<.+?>#si", $str, $matches)) - { - for ($i = 0, $total = count($matches[0]); $i < $total; $i++) - { - $str = str_replace($matches[0][$i], - str_replace(array("'",'"','--',' '), array('{@SQ}', '{@DQ}', '{@DD}', '{@NBS}'), $matches[0][$i]), - $str); - } - } - - if ($this->protect_braced_quotes === TRUE) - { - if (preg_match_all("#\{.+?}#si", $str, $matches)) - { - for ($i = 0, $total = count($matches[0]); $i < $total; $i++) - { - $str = str_replace($matches[0][$i], - str_replace(array("'",'"'), array('{@SQ}', '{@DQ}'), $matches[0][$i]), - $str); - } - } - } - - // Convert "ignore" tags to temporary marker. The parser splits out the string at every tag - // it encounters. Certain inline tags, like image tags, links, span tags, etc. will be - // adversely affected if they are split out so we'll convert the opening bracket < temporarily to: {@TAG} - $str = preg_replace("#<(/*)(".$this->inline_elements.")([ >])#i", "{@TAG}\\1\\2\\3", $str); - - // Split the string at every tag. This expression creates an array with this prototype: - // - // [array] - // { - // [0] = - // [1] = Content... - // [2] = - // Etc... - // } - $chunks = preg_split('/(<(?:[^<>]+(?:"[^"]*"|\'[^\']*\')?)+>)/', $str, -1, PREG_SPLIT_DELIM_CAPTURE|PREG_SPLIT_NO_EMPTY); - - // Build our finalized string. We cycle through the array, skipping tags, and processing the contained text - $str = ''; - $process = TRUE; - $paragraph = FALSE; - foreach ($chunks as $chunk) - { - // Are we dealing with a tag? If so, we'll skip the processing for this cycle. - // Well also set the "process" flag which allows us to skip

     tags and a few other things.
    -			if (preg_match("#<(/*)(".$this->block_elements.").*?>#", $chunk, $match))
    -			{
    -				if (preg_match("#".$this->skip_elements."#", $match[2]))
    -				{
    -					$process =  ($match[1] == '/') ? TRUE : FALSE;
    -				}
    -				
    -				$str .= $chunk;
    -				continue;
    -			}
    -			elseif (preg_match('/<(\/?)([a-z]*).*?>/s', $chunk, $tagmatch))
    -			{
    -				if ($tagmatch[1] == '/' && $tagmatch[2] == $this->last_tag)
    -				{
    -					$process = FALSE;
    -				}
    -				else
    -				{
    -					$process = TRUE;
    -					$this->last_tag = $tagmatch[2];					
    -				}
    -			}
    -
    -			if ($process == FALSE)
    -			{
    -				$str .= $chunk;
    -				continue;
    -			}
    -			
    -			//  Convert Newlines into 

    and
    tags - $str .= $this->format_characters($this->_format_newlines($chunk)); - } - - // is the whole of the content inside a block level element? - if ( ! preg_match("/^<(?:".$this->block_elements.")/i", $str, $match)) - { - $str = "

    {$str}

    "; - } - - - // some special linebreak cleanup - $str = preg_replace_callback('#<(?!/|'.$this->block_elements.')([^>]*)>

    (.*?)

    <(\w*)#si', array($this, '_linebreak_cleanup'), $str); - - // and cleanup empty paragraph tags sitting between two closing tags - $str = preg_replace('#()

    (\s*)

    ()#si', '$1$2$3', $str); - - // Final clean up - $table = array( - - // If the user submitted their own paragraph tags within the text - // we will retain them instead of using our tags. - '/(*?]>)

    /' => '$1', // )+#' => '

    ', - '/(

    \W*

    )+/' => '

    ', - - // Clean up stray paragraph tags that appear before block level elements - '#

    <('.$this->block_elements.')#' => '<$1', - - // Clean up open paragraph tags that appear before block level elements - '#

    (\W)<('.$this->block_elements.')#' => '

    $1<$2', - - // Clean up stray non-breaking spaces preceeding block elements - '#[  ]+<('.$this->block_elements.')#' => ' <$1', - - // Replace the temporary markers we added earlier - '/\{@TAG\}/' => '<', - '/\{@DQ\}/' => '"', - '/\{@SQ\}/' => "'", - '/\{@DD\}/' => '--', - '/\{@NBS\}/' => ' ' - - ); - - // Do we need to reduce empty lines? - if ($reduce_linebreaks === TRUE) - { - $table['#

    \n*

    #'] = ''; - } - else - { - // If we have empty paragraph tags we add a non-breaking space - // otherwise most browsers won't treat them as true paragraphs - $table['#

    #'] = '

     

    '; - } - - return preg_replace(array_keys($table), $table, $str); - - } - - // -------------------------------------------------------------------- - - /** - * Linebreak Cleanup - * - * Removes paragraph and line break tags inserted inbetween - * inline content and a new opening block level element - * - * @access private - * @param array - * @return string - */ - function _linebreak_cleanup($match) - { - if (in_array($match[3], explode('|', $this->block_elements))) - { - return "<{$match[1]}>".str_replace('
    ', '', $match[2])."<{$match[3]}"; - } - else - { - return $match[0]; - } - } - - // -------------------------------------------------------------------- - - /** - * Format Characters - * - * This function mainly converts double and single quotes - * to curly entities, but it also converts em-dashes, - * double spaces, and ampersands - * - * @access public - * @param string - * @return string - */ - function format_characters($str) - { - static $table; - - if ( ! isset($table)) - { - $table = array( - // nested smart quotes, opening and closing - // note that rules for grammar (English) allow only for two levels deep - // and that single quotes are _supposed_ to always be on the outside - // but we'll accommodate both - '/(^|\W|\s)\'"/' => '$1‘“', - '/\'"(\s|\W|$)/' => '’”$1', - '/(^|\W|\s)"\'/' => '$1“‘', - '/"\'(\s|\W|$)/' => '”’$1', - - // single quote smart quotes - '/\'(\s|\W|$)/' => '’$1', - '/(^|\W|\s)\'/' => '$1‘', - - // double quote smart quotes - '/"(\s|\W|$)/' => '”$1', - '/(^|\W|\s)"/' => '$1“', - - // apostrophes - "/(\w)'(\w)/" => '$1’$2', - - // Em dash and ellipses dots - '/\s?\-\-\s?/' => '—', - '/(\w)\.{3}/' => '$1…', - - // double space after sentences - '/(\W) /' => '$1  ', - - // ampersands, if not a character entity - '/&(?!#?[a-zA-Z0-9]{2,};)/' => '&' - ); - } - - return preg_replace(array_keys($table), $table, $str); - } - - // -------------------------------------------------------------------- - - /** - * Format Newlines - * - * Converts newline characters into either

    tags or
    - * - * @access public - * @param string - * @return string - */ - function _format_newlines($str) - { - if ($str == '') - { - return $str; - } - - if (strpos($str, "\n") === FALSE) - { - return $str; - } - - // Convert two consecutive newlines to paragraphs - $str = str_replace("\n\n", "

    \n\n

    ", $str); - - // Convert single spaces to
    tags - $str = preg_replace("/([^\n])(\n)([^\n])/", "\\1
    \\2\\3", $str); - - // Wrap the whole enchilada in enclosing paragraphs - if ($str != "\n") - { - $str = '

    '.$str.'

    '; - } - - // Remove empty paragraphs if they are on the first line, as this - // is a potential unintended consequence of the previous code - $str = preg_replace("/

    <\/p>(.*)/", "\\1", $str, 1); - - return $str; - } - - // ------------------------------------------------------------------------ - - /** - * Convert newlines to HTML line breaks except within PRE tags - * - * @access public - * @param string - * @return string - */ - function nl2br_except_pre($str) - { - $ex = explode("pre>",$str); - $ct = count($ex); - - $newstr = ""; - for ($i = 0; $i < $ct; $i++) - { - if (($i % 2) == 0) - { - $newstr .= nl2br($ex[$i]); - } - else - { - $newstr .= $ex[$i]; - } - - if ($ct - 1 != $i) - $newstr .= "pre>"; - } - - return $newstr; - } - -} -// END Typography Class - -/* End of file Typography.php */ + 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'; + + // 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'; + + // whether or not to protect quotes within { curly braces } + var $protect_braced_quotes = FALSE; + + /** + * Nothing to do here... + * + */ + function CI_Typography() + { + } + + /** + * 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); + } + + // Convert quotes within tags to temporary markers. We don't want quotes converted + // within tags so we'll temporarily convert them to {@DQ} and {@SQ} + // and we don't want double dashes converted to emdash entities, so they are marked with {@DD} + // likewise double spaces are converted to {@NBS} to prevent entity conversion + if (preg_match_all("#\<.+?>#si", $str, $matches)) + { + for ($i = 0, $total = count($matches[0]); $i < $total; $i++) + { + $str = str_replace($matches[0][$i], + str_replace(array("'",'"','--',' '), array('{@SQ}', '{@DQ}', '{@DD}', '{@NBS}'), $matches[0][$i]), + $str); + } + } + + if ($this->protect_braced_quotes === TRUE) + { + if (preg_match_all("#\{.+?}#si", $str, $matches)) + { + for ($i = 0, $total = count($matches[0]); $i < $total; $i++) + { + $str = str_replace($matches[0][$i], + str_replace(array("'",'"'), array('{@SQ}', '{@DQ}'), $matches[0][$i]), + $str); + } + } + } + + // Convert "ignore" tags to temporary marker. The parser splits out the string at every tag + // it encounters. Certain inline tags, like image tags, links, span tags, etc. will be + // adversely affected if they are split out so we'll convert the opening bracket < temporarily to: {@TAG} + $str = preg_replace("#<(/*)(".$this->inline_elements.")([ >])#i", "{@TAG}\\1\\2\\3", $str); + + // Split the string at every tag. This expression creates an array with this prototype: + // + // [array] + // { + // [0] = + // [1] = Content... + // [2] = + // Etc... + // } + $chunks = preg_split('/(<(?:[^<>]+(?:"[^"]*"|\'[^\']*\')?)+>)/', $str, -1, PREG_SPLIT_DELIM_CAPTURE|PREG_SPLIT_NO_EMPTY); + + // Build our finalized string. We cycle through the array, skipping tags, and processing the contained text + $str = ''; + $process = TRUE; + $paragraph = FALSE; + foreach ($chunks as $chunk) + { + // Are we dealing with a tag? If so, we'll skip the processing for this cycle. + // Well also set the "process" flag which allows us to skip

     tags and a few other things.
    +			if (preg_match("#<(/*)(".$this->block_elements.").*?>#", $chunk, $match))
    +			{
    +				if (preg_match("#".$this->skip_elements."#", $match[2]))
    +				{
    +					$process =  ($match[1] == '/') ? TRUE : FALSE;
    +				}
    +				
    +				$str .= $chunk;
    +				continue;
    +			}
    +			elseif (preg_match('/<(\/?)([a-z]*).*?>/s', $chunk, $tagmatch))
    +			{
    +				if ($tagmatch[1] == '/' && $tagmatch[2] == $this->last_tag)
    +				{
    +					$process = FALSE;
    +				}
    +				else
    +				{
    +					$process = TRUE;
    +					$this->last_tag = $tagmatch[2];					
    +				}
    +			}
    +
    +			if ($process == FALSE)
    +			{
    +				$str .= $chunk;
    +				continue;
    +			}
    +			
    +			//  Convert Newlines into 

    and
    tags + $str .= $this->format_characters($this->_format_newlines($chunk)); + } + + // is the whole of the content inside a block level element? + if ( ! preg_match("/^<(?:".$this->block_elements.")/i", $str, $match)) + { + $str = "

    {$str}

    "; + } + + + // some special linebreak cleanup + $str = preg_replace_callback('#<(?!/|'.$this->block_elements.')([^>]*)>

    (.*?)

    <(\w*)#si', array($this, '_linebreak_cleanup'), $str); + + // and cleanup empty paragraph tags sitting between two closing tags + $str = preg_replace('#()

    (\s*)

    ()#si', '$1$2$3', $str); + + // Final clean up + $table = array( + + // If the user submitted their own paragraph tags within the text + // we will retain them instead of using our tags. + '/(*?]>)

    /' => '$1', // )+#' => '

    ', + '/(

    \W*

    )+/' => '

    ', + + // Clean up stray paragraph tags that appear before block level elements + '#

    <('.$this->block_elements.')#' => '<$1', + + // Clean up open paragraph tags that appear before block level elements + '#

    (\W)<('.$this->block_elements.')#' => '

    $1<$2', + + // Clean up stray non-breaking spaces preceeding block elements + '#[  ]+<('.$this->block_elements.')#' => ' <$1', + + // Replace the temporary markers we added earlier + '/\{@TAG\}/' => '<', + '/\{@DQ\}/' => '"', + '/\{@SQ\}/' => "'", + '/\{@DD\}/' => '--', + '/\{@NBS\}/' => ' ' + + ); + + // Do we need to reduce empty lines? + if ($reduce_linebreaks === TRUE) + { + $table['#

    \n*

    #'] = ''; + } + else + { + // If we have empty paragraph tags we add a non-breaking space + // otherwise most browsers won't treat them as true paragraphs + $table['#

    #'] = '

     

    '; + } + + return preg_replace(array_keys($table), $table, $str); + + } + + // -------------------------------------------------------------------- + + /** + * Linebreak Cleanup + * + * Removes paragraph and line break tags inserted inbetween + * inline content and a new opening block level element + * + * @access private + * @param array + * @return string + */ + function _linebreak_cleanup($match) + { + if (in_array($match[3], explode('|', $this->block_elements))) + { + return "<{$match[1]}>".str_replace('
    ', '', $match[2])."<{$match[3]}"; + } + else + { + return $match[0]; + } + } + + // -------------------------------------------------------------------- + + /** + * Format Characters + * + * This function mainly converts double and single quotes + * to curly entities, but it also converts em-dashes, + * double spaces, and ampersands + * + * @access public + * @param string + * @return string + */ + function format_characters($str) + { + static $table; + + if ( ! isset($table)) + { + $table = array( + // nested smart quotes, opening and closing + // note that rules for grammar (English) allow only for two levels deep + // and that single quotes are _supposed_ to always be on the outside + // but we'll accommodate both + '/(^|\W|\s)\'"/' => '$1‘“', + '/\'"(\s|\W|$)/' => '’”$1', + '/(^|\W|\s)"\'/' => '$1“‘', + '/"\'(\s|\W|$)/' => '”’$1', + + // single quote smart quotes + '/\'(\s|\W|$)/' => '’$1', + '/(^|\W|\s)\'/' => '$1‘', + + // double quote smart quotes + '/"(\s|\W|$)/' => '”$1', + '/(^|\W|\s)"/' => '$1“', + + // apostrophes + "/(\w)'(\w)/" => '$1’$2', + + // Em dash and ellipses dots + '/\s?\-\-\s?/' => '—', + '/(\w)\.{3}/' => '$1…', + + // double space after sentences + '/(\W) /' => '$1  ', + + // ampersands, if not a character entity + '/&(?!#?[a-zA-Z0-9]{2,};)/' => '&' + ); + } + + return preg_replace(array_keys($table), $table, $str); + } + + // -------------------------------------------------------------------- + + /** + * Format Newlines + * + * Converts newline characters into either

    tags or
    + * + * @access public + * @param string + * @return string + */ + function _format_newlines($str) + { + if ($str == '') + { + return $str; + } + + if (strpos($str, "\n") === FALSE) + { + return $str; + } + + // Convert two consecutive newlines to paragraphs + $str = str_replace("\n\n", "

    \n\n

    ", $str); + + // Convert single spaces to
    tags + $str = preg_replace("/([^\n])(\n)([^\n])/", "\\1
    \\2\\3", $str); + + // Wrap the whole enchilada in enclosing paragraphs + if ($str != "\n") + { + $str = '

    '.$str.'

    '; + } + + // Remove empty paragraphs if they are on the first line, as this + // is a potential unintended consequence of the previous code + $str = preg_replace("/

    <\/p>(.*)/", "\\1", $str, 1); + + return $str; + } + + // ------------------------------------------------------------------------ + + /** + * Convert newlines to HTML line breaks except within PRE tags + * + * @access public + * @param string + * @return string + */ + function nl2br_except_pre($str) + { + $ex = explode("pre>",$str); + $ct = count($ex); + + $newstr = ""; + for ($i = 0; $i < $ct; $i++) + { + if (($i % 2) == 0) + { + $newstr .= nl2br($ex[$i]); + } + else + { + $newstr .= $ex[$i]; + } + + if ($ct - 1 != $i) + $newstr .= "pre>"; + } + + return $newstr; + } + +} +// END Typography Class + +/* End of file Typography.php */ /* Location: ./system/libraries/Typography.php */ \ No newline at end of file diff --git a/system/libraries/URI.php b/system/libraries/URI.php index b27dfa3cc..aa2d71e87 100644 --- a/system/libraries/URI.php +++ b/system/libraries/URI.php @@ -1,585 +1,585 @@ -config =& load_class('Config'); - 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') - { - // If the URL has a question mark then it's simplest to just - // build the URI string from the zero index of the $_GET array. - // This avoids having to deal with $_SERVER variables, which - // can be unreliable in some environments - if (is_array($_GET) && count($_GET) == 1 && trim(key($_GET), '/') != '') - { - $this->uri_string = key($_GET); - 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->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->uri_string = $path; - return; - } - - // No QUERY_STRING?... Maybe the ORIG_PATH_INFO variable exists? - $path = (isset($_SERVER['ORIG_PATH_INFO'])) ? $_SERVER['ORIG_PATH_INFO'] : @getenv('ORIG_PATH_INFO'); - if (trim($path, '/') != '' && $path != "/".SELF) - { - // remove path and script information so we have good URI data - $this->uri_string = str_replace($_SERVER['SCRIPT_NAME'], '', $path); - return; - } - - // We've exhausted all our options... - $this->uri_string = ''; - } - else - { - $uri = strtoupper($this->config->item('uri_protocol')); - - if ($uri == 'REQUEST_URI') - { - $this->uri_string = $this->_parse_request_uri(); - return; - } - - $this->uri_string = (isset($_SERVER[$uri])) ? $_SERVER[$uri] : @getenv($uri); - } - - // If the URI contains only a slash we'll kill it - if ($this->uri_string == '/') - { - $this->uri_string = ''; - } - } - - // -------------------------------------------------------------------- - - /** - * Parse the REQUEST_URI - * - * Due to the way REQUEST_URI works it usually contains path info - * that makes it unusable as URI data. We'll trim off the unnecessary - * data, hopefully arriving at a valid URI that we can use. - * - * @access private - * @return string - */ - function _parse_request_uri() - { - if ( ! isset($_SERVER['REQUEST_URI']) OR $_SERVER['REQUEST_URI'] == '') - { - return ''; - } - - $request_uri = preg_replace("|/(.*)|", "\\1", str_replace("\\", "/", $_SERVER['REQUEST_URI'])); - - if ($request_uri == '' OR $request_uri == SELF) - { - return ''; - } - - $fc_path = FCPATH; - if (strpos($request_uri, '?') !== FALSE) - { - $fc_path .= '?'; - } - - $parsed_uri = explode("/", $request_uri); - - $i = 0; - foreach(explode("/", $fc_path) as $segment) - { - if (isset($parsed_uri[$i]) && $segment == $parsed_uri[$i]) - { - $i++; - } - } - - $parsed_uri = implode("/", array_slice($parsed_uri, $i)); - - if ($parsed_uri != '') - { - $parsed_uri = '/'.$parsed_uri; - } - - return $parsed_uri; - } - - // -------------------------------------------------------------------- - - /** - * 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) - { - if ( ! preg_match("|^[".preg_quote($this->config->item('permitted_uri_chars'))."]+$|i", $str)) - { - header('HTTP/1.1 400 Bad Request'); - exit('The URI you submitted has disallowed characters.'); - } - } - - // 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 - * - */ - 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') - { - if ($where == 'trailing') - { - $trailing = '/'; - $leading = ''; - } - elseif ($where == 'leading') - { - $leading = '/'; - $trailing = ''; - } - else - { - $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()).'/'; - } - -} -// END URI Class - -/* End of file URI.php */ +config =& load_class('Config'); + 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') + { + // If the URL has a question mark then it's simplest to just + // build the URI string from the zero index of the $_GET array. + // This avoids having to deal with $_SERVER variables, which + // can be unreliable in some environments + if (is_array($_GET) && count($_GET) == 1 && trim(key($_GET), '/') != '') + { + $this->uri_string = key($_GET); + 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->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->uri_string = $path; + return; + } + + // No QUERY_STRING?... Maybe the ORIG_PATH_INFO variable exists? + $path = (isset($_SERVER['ORIG_PATH_INFO'])) ? $_SERVER['ORIG_PATH_INFO'] : @getenv('ORIG_PATH_INFO'); + if (trim($path, '/') != '' && $path != "/".SELF) + { + // remove path and script information so we have good URI data + $this->uri_string = str_replace($_SERVER['SCRIPT_NAME'], '', $path); + return; + } + + // We've exhausted all our options... + $this->uri_string = ''; + } + else + { + $uri = strtoupper($this->config->item('uri_protocol')); + + if ($uri == 'REQUEST_URI') + { + $this->uri_string = $this->_parse_request_uri(); + return; + } + + $this->uri_string = (isset($_SERVER[$uri])) ? $_SERVER[$uri] : @getenv($uri); + } + + // If the URI contains only a slash we'll kill it + if ($this->uri_string == '/') + { + $this->uri_string = ''; + } + } + + // -------------------------------------------------------------------- + + /** + * Parse the REQUEST_URI + * + * Due to the way REQUEST_URI works it usually contains path info + * that makes it unusable as URI data. We'll trim off the unnecessary + * data, hopefully arriving at a valid URI that we can use. + * + * @access private + * @return string + */ + function _parse_request_uri() + { + if ( ! isset($_SERVER['REQUEST_URI']) OR $_SERVER['REQUEST_URI'] == '') + { + return ''; + } + + $request_uri = preg_replace("|/(.*)|", "\\1", str_replace("\\", "/", $_SERVER['REQUEST_URI'])); + + if ($request_uri == '' OR $request_uri == SELF) + { + return ''; + } + + $fc_path = FCPATH; + if (strpos($request_uri, '?') !== FALSE) + { + $fc_path .= '?'; + } + + $parsed_uri = explode("/", $request_uri); + + $i = 0; + foreach(explode("/", $fc_path) as $segment) + { + if (isset($parsed_uri[$i]) && $segment == $parsed_uri[$i]) + { + $i++; + } + } + + $parsed_uri = implode("/", array_slice($parsed_uri, $i)); + + if ($parsed_uri != '') + { + $parsed_uri = '/'.$parsed_uri; + } + + return $parsed_uri; + } + + // -------------------------------------------------------------------- + + /** + * 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) + { + if ( ! preg_match("|^[".preg_quote($this->config->item('permitted_uri_chars'))."]+$|i", $str)) + { + header('HTTP/1.1 400 Bad Request'); + exit('The URI you submitted has disallowed characters.'); + } + } + + // 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 + * + */ + 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') + { + if ($where == 'trailing') + { + $trailing = '/'; + $leading = ''; + } + elseif ($where == 'leading') + { + $leading = '/'; + $trailing = ''; + } + else + { + $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()).'/'; + } + +} +// END URI Class + +/* End of file URI.php */ /* Location: ./system/libraries/URI.php */ \ No newline at end of file diff --git a/system/libraries/Unit_test.php b/system/libraries/Unit_test.php index 5ed048ba7..a5aa381a4 100644 --- a/system/libraries/Unit_test.php +++ b/system/libraries/Unit_test.php @@ -1,347 +1,347 @@ -active == FALSE) - { - return FALSE; - } - - if (in_array($expected, array('is_string', 'is_bool', 'is_true', 'is_false', 'is_int', 'is_numeric', 'is_float', 'is_double', 'is_array', 'is_null'), TRUE)) - { - $expected = str_replace('is_float', 'is_double', $expected); - $result = ($expected($test)) ? TRUE : FALSE; - $extype = str_replace(array('true', 'false'), 'bool', str_replace('is_', '', $expected)); - } - else - { - if ($this->strict == TRUE) - $result = ($test === $expected) ? TRUE : FALSE; - else - $result = ($test == $expected) ? TRUE : FALSE; - - $extype = gettype($expected); - } - - $back = $this->_backtrace(); - - $report[] = array ( - 'test_name' => $test_name, - 'test_datatype' => gettype($test), - 'res_datatype' => $extype, - 'result' => ($result === TRUE) ? 'passed' : 'failed', - 'file' => $back['file'], - 'line' => $back['line'] - ); - - $this->results[] = $report; - - return($this->report($this->result($report))); - } - - // -------------------------------------------------------------------- - - /** - * Generate a report - * - * Displays a table with the test data - * - * @access public - * @return string - */ - function report($result = array()) - { - if (count($result) == 0) - { - $result = $this->result(); - } - - $CI =& get_instance(); - $CI->load->language('unit_test'); - - $this->_parse_template(); - - $r = ''; - foreach ($result as $res) - { - $table = ''; - - foreach ($res as $key => $val) - { - - if ($key == $CI->lang->line('ut_result')) - { - if ($val == $CI->lang->line('ut_passed')) - { - $val = ''.$val.''; - } - elseif ($val == $CI->lang->line('ut_failed')) - { - $val = ''.$val.''; - } - } - - $temp = $this->_template_rows; - $temp = str_replace('{item}', $key, $temp); - $temp = str_replace('{result}', $val, $temp); - $table .= $temp; - } - - $r .= str_replace('{rows}', $table, $this->_template); - } - - return $r; - } - - // -------------------------------------------------------------------- - - /** - * Use strict comparison - * - * Causes the evaluation to use === rather than == - * - * @access public - * @param bool - * @return null - */ - function use_strict($state = TRUE) - { - $this->strict = ($state == FALSE) ? FALSE : TRUE; - } - - // -------------------------------------------------------------------- - - /** - * Make Unit testing active - * - * Enables/disables unit testing - * - * @access public - * @param bool - * @return null - */ - function active($state = TRUE) - { - $this->active = ($state == FALSE) ? FALSE : TRUE; - } - - // -------------------------------------------------------------------- - - /** - * Result Array - * - * Returns the raw result data - * - * @access public - * @return array - */ - function result($results = array()) - { - $CI =& get_instance(); - $CI->load->language('unit_test'); - - if (count($results) == 0) - { - $results = $this->results; - } - - $retval = array(); - foreach ($results as $result) - { - $temp = array(); - foreach ($result as $key => $val) - { - if (is_array($val)) - { - foreach ($val as $k => $v) - { - if (FALSE !== ($line = $CI->lang->line(strtolower('ut_'.$v)))) - { - $v = $line; - } - $temp[$CI->lang->line('ut_'.$k)] = $v; - } - } - else - { - if (FALSE !== ($line = $CI->lang->line(strtolower('ut_'.$val)))) - { - $val = $line; - } - $temp[$CI->lang->line('ut_'.$key)] = $val; - } - } - - $retval[] = $temp; - } - - return $retval; - } - - // -------------------------------------------------------------------- - - /** - * Set the template - * - * This lets us set the template to be used to display results - * - * @access public - * @param string - * @return void - */ - function set_template($template) - { - $this->_template = $template; - } - - // -------------------------------------------------------------------- - - /** - * Generate a backtrace - * - * This lets us show file names and line numbers - * - * @access private - * @return array - */ - function _backtrace() - { - if (function_exists('debug_backtrace')) - { - $back = debug_backtrace(); - - $file = ( ! isset($back['1']['file'])) ? '' : $back['1']['file']; - $line = ( ! isset($back['1']['line'])) ? '' : $back['1']['line']; - - return array('file' => $file, 'line' => $line); - } - return array('file' => 'Unknown', 'line' => 'Unknown'); - } - - // -------------------------------------------------------------------- - - /** - * Get Default Template - * - * @access private - * @return string - */ - function _default_template() - { - $this->_template = "\n".''; - $this->_template .= '{rows}'; - $this->_template .= "\n".'
    '; - - $this->_template_rows = "\n\t".''; - $this->_template_rows .= "\n\t\t".'{item}'; - $this->_template_rows .= "\n\t\t".'{result}'; - $this->_template_rows .= "\n\t".''; - } - - // -------------------------------------------------------------------- - - /** - * Parse Template - * - * Harvests the data within the template {pseudo-variables} - * - * @access private - * @return void - */ - function _parse_template() - { - if ( ! is_null($this->_template_rows)) - { - return; - } - - if (is_null($this->_template)) - { - $this->_default_template(); - return; - } - - if ( ! preg_match("/\{rows\}(.*?)\{\/rows\}/si", $this->_template, $match)) - { - $this->_default_template(); - return; - } - - $this->_template_rows = $match['1']; - $this->_template = str_replace($match['0'], '{rows}', $this->_template); - } - -} -// END Unit_test Class - -/** - * Helper functions to test boolean true/false - * - * - * @access private - * @return bool - */ -function is_true($test) -{ - return (is_bool($test) AND $test === TRUE) ? TRUE : FALSE; -} -function is_false($test) -{ - return (is_bool($test) AND $test === FALSE) ? TRUE : FALSE; -} - - -/* End of file Unit_test.php */ +active == FALSE) + { + return FALSE; + } + + if (in_array($expected, array('is_string', 'is_bool', 'is_true', 'is_false', 'is_int', 'is_numeric', 'is_float', 'is_double', 'is_array', 'is_null'), TRUE)) + { + $expected = str_replace('is_float', 'is_double', $expected); + $result = ($expected($test)) ? TRUE : FALSE; + $extype = str_replace(array('true', 'false'), 'bool', str_replace('is_', '', $expected)); + } + else + { + if ($this->strict == TRUE) + $result = ($test === $expected) ? TRUE : FALSE; + else + $result = ($test == $expected) ? TRUE : FALSE; + + $extype = gettype($expected); + } + + $back = $this->_backtrace(); + + $report[] = array ( + 'test_name' => $test_name, + 'test_datatype' => gettype($test), + 'res_datatype' => $extype, + 'result' => ($result === TRUE) ? 'passed' : 'failed', + 'file' => $back['file'], + 'line' => $back['line'] + ); + + $this->results[] = $report; + + return($this->report($this->result($report))); + } + + // -------------------------------------------------------------------- + + /** + * Generate a report + * + * Displays a table with the test data + * + * @access public + * @return string + */ + function report($result = array()) + { + if (count($result) == 0) + { + $result = $this->result(); + } + + $CI =& get_instance(); + $CI->load->language('unit_test'); + + $this->_parse_template(); + + $r = ''; + foreach ($result as $res) + { + $table = ''; + + foreach ($res as $key => $val) + { + + if ($key == $CI->lang->line('ut_result')) + { + if ($val == $CI->lang->line('ut_passed')) + { + $val = ''.$val.''; + } + elseif ($val == $CI->lang->line('ut_failed')) + { + $val = ''.$val.''; + } + } + + $temp = $this->_template_rows; + $temp = str_replace('{item}', $key, $temp); + $temp = str_replace('{result}', $val, $temp); + $table .= $temp; + } + + $r .= str_replace('{rows}', $table, $this->_template); + } + + return $r; + } + + // -------------------------------------------------------------------- + + /** + * Use strict comparison + * + * Causes the evaluation to use === rather than == + * + * @access public + * @param bool + * @return null + */ + function use_strict($state = TRUE) + { + $this->strict = ($state == FALSE) ? FALSE : TRUE; + } + + // -------------------------------------------------------------------- + + /** + * Make Unit testing active + * + * Enables/disables unit testing + * + * @access public + * @param bool + * @return null + */ + function active($state = TRUE) + { + $this->active = ($state == FALSE) ? FALSE : TRUE; + } + + // -------------------------------------------------------------------- + + /** + * Result Array + * + * Returns the raw result data + * + * @access public + * @return array + */ + function result($results = array()) + { + $CI =& get_instance(); + $CI->load->language('unit_test'); + + if (count($results) == 0) + { + $results = $this->results; + } + + $retval = array(); + foreach ($results as $result) + { + $temp = array(); + foreach ($result as $key => $val) + { + if (is_array($val)) + { + foreach ($val as $k => $v) + { + if (FALSE !== ($line = $CI->lang->line(strtolower('ut_'.$v)))) + { + $v = $line; + } + $temp[$CI->lang->line('ut_'.$k)] = $v; + } + } + else + { + if (FALSE !== ($line = $CI->lang->line(strtolower('ut_'.$val)))) + { + $val = $line; + } + $temp[$CI->lang->line('ut_'.$key)] = $val; + } + } + + $retval[] = $temp; + } + + return $retval; + } + + // -------------------------------------------------------------------- + + /** + * Set the template + * + * This lets us set the template to be used to display results + * + * @access public + * @param string + * @return void + */ + function set_template($template) + { + $this->_template = $template; + } + + // -------------------------------------------------------------------- + + /** + * Generate a backtrace + * + * This lets us show file names and line numbers + * + * @access private + * @return array + */ + function _backtrace() + { + if (function_exists('debug_backtrace')) + { + $back = debug_backtrace(); + + $file = ( ! isset($back['1']['file'])) ? '' : $back['1']['file']; + $line = ( ! isset($back['1']['line'])) ? '' : $back['1']['line']; + + return array('file' => $file, 'line' => $line); + } + return array('file' => 'Unknown', 'line' => 'Unknown'); + } + + // -------------------------------------------------------------------- + + /** + * Get Default Template + * + * @access private + * @return string + */ + function _default_template() + { + $this->_template = "\n".''; + $this->_template .= '{rows}'; + $this->_template .= "\n".'
    '; + + $this->_template_rows = "\n\t".''; + $this->_template_rows .= "\n\t\t".'{item}'; + $this->_template_rows .= "\n\t\t".'{result}'; + $this->_template_rows .= "\n\t".''; + } + + // -------------------------------------------------------------------- + + /** + * Parse Template + * + * Harvests the data within the template {pseudo-variables} + * + * @access private + * @return void + */ + function _parse_template() + { + if ( ! is_null($this->_template_rows)) + { + return; + } + + if (is_null($this->_template)) + { + $this->_default_template(); + return; + } + + if ( ! preg_match("/\{rows\}(.*?)\{\/rows\}/si", $this->_template, $match)) + { + $this->_default_template(); + return; + } + + $this->_template_rows = $match['1']; + $this->_template = str_replace($match['0'], '{rows}', $this->_template); + } + +} +// END Unit_test Class + +/** + * Helper functions to test boolean true/false + * + * + * @access private + * @return bool + */ +function is_true($test) +{ + return (is_bool($test) AND $test === TRUE) ? TRUE : FALSE; +} +function is_false($test) +{ + return (is_bool($test) AND $test === FALSE) ? TRUE : FALSE; +} + + +/* End of file Unit_test.php */ /* Location: ./system/libraries/Unit_test.php */ \ No newline at end of file diff --git a/system/libraries/Upload.php b/system/libraries/Upload.php index 3832dab06..54124bc3d 100644 --- a/system/libraries/Upload.php +++ b/system/libraries/Upload.php @@ -1,931 +1,931 @@ - 0) - { - $this->initialize($props); - } - - log_message('debug', "Upload Class Initialized"); - } - - // -------------------------------------------------------------------- - - /** - * Initialize preferences - * - * @access public - * @param array - * @return void - */ - function initialize($config = array()) - { - $defaults = array( - 'max_size' => 0, - 'max_width' => 0, - 'max_height' => 0, - 'max_filename' => 0, - 'allowed_types' => "", - 'file_temp' => "", - 'file_name' => "", - 'orig_name' => "", - 'file_type' => "", - 'file_size' => "", - 'file_ext' => "", - 'upload_path' => "", - 'overwrite' => FALSE, - 'encrypt_name' => FALSE, - 'is_image' => FALSE, - 'image_width' => '', - 'image_height' => '', - 'image_type' => '', - 'image_size_str' => '', - 'error_msg' => array(), - 'mimes' => array(), - 'remove_spaces' => TRUE, - 'xss_clean' => FALSE, - 'temp_prefix' => "temp_file_" - ); - - - foreach ($defaults as $key => $val) - { - if (isset($config[$key])) - { - $method = 'set_'.$key; - if (method_exists($this, $method)) - { - $this->$method($config[$key]); - } - else - { - $this->$key = $config[$key]; - } - } - else - { - $this->$key = $val; - } - } - } - - // -------------------------------------------------------------------- - - /** - * Perform the file upload - * - * @access public - * @return bool - */ - function do_upload($field = 'userfile') - { - // Is $_FILES[$field] set? If not, no reason to continue. - if ( ! isset($_FILES[$field])) - { - $this->set_error('upload_no_file_selected'); - return FALSE; - } - - // Is the upload path valid? - if ( ! $this->validate_upload_path()) - { - // errors will already be set by validate_upload_path() so just return FALSE - return FALSE; - } - - // Was the file able to be uploaded? If not, determine the reason why. - if ( ! is_uploaded_file($_FILES[$field]['tmp_name'])) - { - $error = ( ! isset($_FILES[$field]['error'])) ? 4 : $_FILES[$field]['error']; - - switch($error) - { - case 1: // UPLOAD_ERR_INI_SIZE - $this->set_error('upload_file_exceeds_limit'); - break; - case 2: // UPLOAD_ERR_FORM_SIZE - $this->set_error('upload_file_exceeds_form_limit'); - break; - case 3: // UPLOAD_ERR_PARTIAL - $this->set_error('upload_file_partial'); - break; - case 4: // UPLOAD_ERR_NO_FILE - $this->set_error('upload_no_file_selected'); - break; - case 6: // UPLOAD_ERR_NO_TMP_DIR - $this->set_error('upload_no_temp_directory'); - break; - case 7: // UPLOAD_ERR_CANT_WRITE - $this->set_error('upload_unable_to_write_file'); - break; - case 8: // UPLOAD_ERR_EXTENSION - $this->set_error('upload_stopped_by_extension'); - break; - default : $this->set_error('upload_no_file_selected'); - break; - } - - return FALSE; - } - - // Set the uploaded data as class variables - $this->file_temp = $_FILES[$field]['tmp_name']; - $this->file_name = $this->_prep_filename($_FILES[$field]['name']); - $this->file_size = $_FILES[$field]['size']; - $this->file_type = preg_replace("/^(.+?);.*$/", "\\1", $_FILES[$field]['type']); - $this->file_type = strtolower($this->file_type); - $this->file_ext = $this->get_extension($_FILES[$field]['name']); - - // Convert the file size to kilobytes - if ($this->file_size > 0) - { - $this->file_size = round($this->file_size/1024, 2); - } - - // Is the file type allowed to be uploaded? - if ( ! $this->is_allowed_filetype()) - { - $this->set_error('upload_invalid_filetype'); - return FALSE; - } - - // Is the file size within the allowed maximum? - if ( ! $this->is_allowed_filesize()) - { - $this->set_error('upload_invalid_filesize'); - return FALSE; - } - - // Are the image dimensions within the allowed size? - // Note: This can fail if the server has an open_basdir restriction. - if ( ! $this->is_allowed_dimensions()) - { - $this->set_error('upload_invalid_dimensions'); - return FALSE; - } - - // Sanitize the file name for security - $this->file_name = $this->clean_file_name($this->file_name); - - // Truncate the file name if it's too long - if ($this->max_filename > 0) - { - $this->file_name = $this->limit_filename_length($this->file_name, $this->max_filename); - } - - // Remove white spaces in the name - if ($this->remove_spaces == TRUE) - { - $this->file_name = preg_replace("/\s+/", "_", $this->file_name); - } - - /* - * Validate the file name - * This function appends an number onto the end of - * the file if one with the same name already exists. - * If it returns false there was a problem. - */ - $this->orig_name = $this->file_name; - - if ($this->overwrite == FALSE) - { - $this->file_name = $this->set_filename($this->upload_path, $this->file_name); - - if ($this->file_name === FALSE) - { - return FALSE; - } - } - - /* - * Move the file to the final destination - * To deal with different server configurations - * we'll attempt to use copy() first. If that fails - * we'll use move_uploaded_file(). One of the two should - * reliably work in most environments - */ - if ( ! @copy($this->file_temp, $this->upload_path.$this->file_name)) - { - if ( ! @move_uploaded_file($this->file_temp, $this->upload_path.$this->file_name)) - { - $this->set_error('upload_destination_error'); - return FALSE; - } - } - - /* - * Run the file through the XSS hacking filter - * This helps prevent malicious code from being - * embedded within a file. Scripts can easily - * be disguised as images or other file types. - */ - if ($this->xss_clean == TRUE) - { - $this->do_xss_clean(); - } - - /* - * Set the finalized image dimensions - * This sets the image width/height (assuming the - * file was an image). We use this information - * in the "data" function. - */ - $this->set_image_properties($this->upload_path.$this->file_name); - - return TRUE; - } - - // -------------------------------------------------------------------- - - /** - * Finalized Data Array - * - * Returns an associative array containing all of the information - * related to the upload, allowing the developer easy access in one array. - * - * @access public - * @return array - */ - function data() - { - return array ( - 'file_name' => $this->file_name, - 'file_type' => $this->file_type, - 'file_path' => $this->upload_path, - 'full_path' => $this->upload_path.$this->file_name, - 'raw_name' => str_replace($this->file_ext, '', $this->file_name), - 'orig_name' => $this->orig_name, - 'file_ext' => $this->file_ext, - 'file_size' => $this->file_size, - 'is_image' => $this->is_image(), - 'image_width' => $this->image_width, - 'image_height' => $this->image_height, - 'image_type' => $this->image_type, - 'image_size_str' => $this->image_size_str, - ); - } - - // -------------------------------------------------------------------- - - /** - * Set Upload Path - * - * @access public - * @param string - * @return void - */ - function set_upload_path($path) - { - // Make sure it has a trailing slash - $this->upload_path = rtrim($path, '/').'/'; - } - - // -------------------------------------------------------------------- - - /** - * Set the file name - * - * This function takes a filename/path as input and looks for the - * existence of a file with the same name. If found, it will append a - * number to the end of the filename to avoid overwriting a pre-existing file. - * - * @access public - * @param string - * @param string - * @return string - */ - function set_filename($path, $filename) - { - if ($this->encrypt_name == TRUE) - { - mt_srand(); - $filename = md5(uniqid(mt_rand())).$this->file_ext; - } - - if ( ! file_exists($path.$filename)) - { - return $filename; - } - - $filename = str_replace($this->file_ext, '', $filename); - - $new_filename = ''; - for ($i = 1; $i < 100; $i++) - { - if ( ! file_exists($path.$filename.$i.$this->file_ext)) - { - $new_filename = $filename.$i.$this->file_ext; - break; - } - } - - if ($new_filename == '') - { - $this->set_error('upload_bad_filename'); - return FALSE; - } - else - { - return $new_filename; - } - } - - // -------------------------------------------------------------------- - - /** - * Set Maximum File Size - * - * @access public - * @param integer - * @return void - */ - function set_max_filesize($n) - { - $this->max_size = ((int) $n < 0) ? 0: (int) $n; - } - - // -------------------------------------------------------------------- - - /** - * Set Maximum File Name Length - * - * @access public - * @param integer - * @return void - */ - function set_max_filename($n) - { - $this->max_filename = ((int) $n < 0) ? 0: (int) $n; - } - - // -------------------------------------------------------------------- - - /** - * Set Maximum Image Width - * - * @access public - * @param integer - * @return void - */ - function set_max_width($n) - { - $this->max_width = ((int) $n < 0) ? 0: (int) $n; - } - - // -------------------------------------------------------------------- - - /** - * Set Maximum Image Height - * - * @access public - * @param integer - * @return void - */ - function set_max_height($n) - { - $this->max_height = ((int) $n < 0) ? 0: (int) $n; - } - - // -------------------------------------------------------------------- - - /** - * Set Allowed File Types - * - * @access public - * @param string - * @return void - */ - function set_allowed_types($types) - { - $this->allowed_types = explode('|', $types); - } - - // -------------------------------------------------------------------- - - /** - * Set Image Properties - * - * Uses GD to determine the width/height/type of image - * - * @access public - * @param string - * @return void - */ - function set_image_properties($path = '') - { - if ( ! $this->is_image()) - { - return; - } - - if (function_exists('getimagesize')) - { - if (FALSE !== ($D = @getimagesize($path))) - { - $types = array(1 => 'gif', 2 => 'jpeg', 3 => 'png'); - - $this->image_width = $D['0']; - $this->image_height = $D['1']; - $this->image_type = ( ! isset($types[$D['2']])) ? 'unknown' : $types[$D['2']]; - $this->image_size_str = $D['3']; // string containing height and width - } - } - } - - // -------------------------------------------------------------------- - - /** - * Set XSS Clean - * - * Enables the XSS flag so that the file that was uploaded - * will be run through the XSS filter. - * - * @access public - * @param bool - * @return void - */ - function set_xss_clean($flag = FALSE) - { - $this->xss_clean = ($flag == TRUE) ? TRUE : FALSE; - } - - // -------------------------------------------------------------------- - - /** - * Validate the image - * - * @access public - * @return bool - */ - function is_image() - { - // IE will sometimes return odd mime-types during upload, so here we just standardize all - // jpegs or pngs to the same file type. - - $png_mimes = array('image/x-png'); - $jpeg_mimes = array('image/jpg', 'image/jpe', 'image/jpeg', 'image/pjpeg'); - - if (in_array($this->file_type, $png_mimes)) - { - $this->file_type = 'image/png'; - } - - if (in_array($this->file_type, $jpeg_mimes)) - { - $this->file_type = 'image/jpeg'; - } - - $img_mimes = array( - 'image/gif', - 'image/jpeg', - 'image/png', - ); - - return (in_array($this->file_type, $img_mimes, TRUE)) ? TRUE : FALSE; - } - - // -------------------------------------------------------------------- - - /** - * Verify that the filetype is allowed - * - * @access public - * @return bool - */ - function is_allowed_filetype() - { - if (count($this->allowed_types) == 0 OR ! is_array($this->allowed_types)) - { - $this->set_error('upload_no_file_types'); - return FALSE; - } - - foreach ($this->allowed_types as $val) - { - $mime = $this->mimes_types(strtolower($val)); - - if (is_array($mime)) - { - if (in_array($this->file_type, $mime, TRUE)) - { - return TRUE; - } - } - else - { - if ($mime == $this->file_type) - { - return TRUE; - } - } - } - - return FALSE; - } - - // -------------------------------------------------------------------- - - /** - * Verify that the file is within the allowed size - * - * @access public - * @return bool - */ - function is_allowed_filesize() - { - if ($this->max_size != 0 AND $this->file_size > $this->max_size) - { - return FALSE; - } - else - { - return TRUE; - } - } - - // -------------------------------------------------------------------- - - /** - * Verify that the image is within the allowed width/height - * - * @access public - * @return bool - */ - function is_allowed_dimensions() - { - if ( ! $this->is_image()) - { - return TRUE; - } - - if (function_exists('getimagesize')) - { - $D = @getimagesize($this->file_temp); - - if ($this->max_width > 0 AND $D['0'] > $this->max_width) - { - return FALSE; - } - - if ($this->max_height > 0 AND $D['1'] > $this->max_height) - { - return FALSE; - } - - return TRUE; - } - - return TRUE; - } - - // -------------------------------------------------------------------- - - /** - * Validate Upload Path - * - * Verifies that it is a valid upload path with proper permissions. - * - * - * @access public - * @return bool - */ - function validate_upload_path() - { - if ($this->upload_path == '') - { - $this->set_error('upload_no_filepath'); - return FALSE; - } - - if (function_exists('realpath') AND @realpath($this->upload_path) !== FALSE) - { - $this->upload_path = str_replace("\\", "/", realpath($this->upload_path)); - } - - if ( ! @is_dir($this->upload_path)) - { - $this->set_error('upload_no_filepath'); - return FALSE; - } - - if ( ! is_really_writable($this->upload_path)) - { - $this->set_error('upload_not_writable'); - return FALSE; - } - - $this->upload_path = preg_replace("/(.+?)\/*$/", "\\1/", $this->upload_path); - return TRUE; - } - - // -------------------------------------------------------------------- - - /** - * Extract the file extension - * - * @access public - * @param string - * @return string - */ - function get_extension($filename) - { - $x = explode('.', $filename); - return '.'.end($x); - } - - // -------------------------------------------------------------------- - - /** - * Clean the file name for security - * - * @access public - * @param string - * @return string - */ - function clean_file_name($filename) - { - $bad = array( - "", - "'", - "<", - ">", - '"', - '&', - '$', - '=', - ';', - '?', - '/', - "%20", - "%22", - "%3c", // < - "%253c", // < - "%3e", // > - "%0e", // > - "%28", // ( - "%29", // ) - "%2528", // ( - "%26", // & - "%24", // $ - "%3f", // ? - "%3b", // ; - "%3d" // = - ); - - $filename = str_replace($bad, '', $filename); - - return stripslashes($filename); - } - - // -------------------------------------------------------------------- - - /** - * Limit the File Name Length - * - * @access public - * @param string - * @return string - */ - function limit_filename_length($filename, $length) - { - if (strlen($filename) < $length) - { - return $filename; - } - - $ext = ''; - if (strpos($filename, '.') !== FALSE) - { - $parts = explode('.', $filename); - $ext = '.'.array_pop($parts); - $filename = implode('.', $parts); - } - - return substr($filename, 0, ($length - strlen($ext))).$ext; - } - - // -------------------------------------------------------------------- - - /** - * Runs the file through the XSS clean function - * - * This prevents people from embedding malicious code in their files. - * I'm not sure that it won't negatively affect certain files in unexpected ways, - * but so far I haven't found that it causes trouble. - * - * @access public - * @return void - */ - function do_xss_clean() - { - $file = $this->upload_path.$this->file_name; - - if (filesize($file) == 0) - { - return FALSE; - } - - if (($data = @file_get_contents($file)) === FALSE) - { - return FALSE; - } - - if ( ! $fp = @fopen($file, FOPEN_READ_WRITE)) - { - return FALSE; - } - - $CI =& get_instance(); - $data = $CI->input->xss_clean($data); - - flock($fp, LOCK_EX); - fwrite($fp, $data); - flock($fp, LOCK_UN); - fclose($fp); - } - - // -------------------------------------------------------------------- - - /** - * Set an error message - * - * @access public - * @param string - * @return void - */ - function set_error($msg) - { - $CI =& get_instance(); - $CI->lang->load('upload'); - - if (is_array($msg)) - { - foreach ($msg as $val) - { - $msg = ($CI->lang->line($val) == FALSE) ? $val : $CI->lang->line($val); - $this->error_msg[] = $msg; - log_message('error', $msg); - } - } - else - { - $msg = ($CI->lang->line($msg) == FALSE) ? $msg : $CI->lang->line($msg); - $this->error_msg[] = $msg; - log_message('error', $msg); - } - } - - // -------------------------------------------------------------------- - - /** - * Display the error message - * - * @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; - } - - // -------------------------------------------------------------------- - - /** - * List of Mime Types - * - * This is a list of mime types. We use it to validate - * the "allowed types" set by the developer - * - * @access public - * @param string - * @return string - */ - function mimes_types($mime) - { - global $mimes; - - if (count($this->mimes) == 0) - { - if (@require_once(APPPATH.'config/mimes'.EXT)) - { - $this->mimes = $mimes; - unset($mimes); - } - } - - return ( ! isset($this->mimes[$mime])) ? FALSE : $this->mimes[$mime]; - } - - // -------------------------------------------------------------------- - - /** - * Prep Filename - * - * Prevents possible script execution from Apache's handling of files multiple extensions - * http://httpd.apache.org/docs/1.3/mod/mod_mime.html#multipleext - * - * @access private - * @param string - * @return string - */ - function _prep_filename($filename) - { - if (strpos($filename, '.') === FALSE) - { - return $filename; - } - - $parts = explode('.', $filename); - $ext = array_pop($parts); - $filename = array_shift($parts); - - foreach ($parts as $part) - { - if ($this->mimes_types(strtolower($part)) === FALSE) - { - $filename .= '.'.$part.'_'; - } - else - { - $filename .= '.'.$part; - } - } - - $filename .= '.'.$ext; - - return $filename; - } - - // -------------------------------------------------------------------- - -} -// END Upload Class - -/* End of file Upload.php */ + 0) + { + $this->initialize($props); + } + + log_message('debug', "Upload Class Initialized"); + } + + // -------------------------------------------------------------------- + + /** + * Initialize preferences + * + * @access public + * @param array + * @return void + */ + function initialize($config = array()) + { + $defaults = array( + 'max_size' => 0, + 'max_width' => 0, + 'max_height' => 0, + 'max_filename' => 0, + 'allowed_types' => "", + 'file_temp' => "", + 'file_name' => "", + 'orig_name' => "", + 'file_type' => "", + 'file_size' => "", + 'file_ext' => "", + 'upload_path' => "", + 'overwrite' => FALSE, + 'encrypt_name' => FALSE, + 'is_image' => FALSE, + 'image_width' => '', + 'image_height' => '', + 'image_type' => '', + 'image_size_str' => '', + 'error_msg' => array(), + 'mimes' => array(), + 'remove_spaces' => TRUE, + 'xss_clean' => FALSE, + 'temp_prefix' => "temp_file_" + ); + + + foreach ($defaults as $key => $val) + { + if (isset($config[$key])) + { + $method = 'set_'.$key; + if (method_exists($this, $method)) + { + $this->$method($config[$key]); + } + else + { + $this->$key = $config[$key]; + } + } + else + { + $this->$key = $val; + } + } + } + + // -------------------------------------------------------------------- + + /** + * Perform the file upload + * + * @access public + * @return bool + */ + function do_upload($field = 'userfile') + { + // Is $_FILES[$field] set? If not, no reason to continue. + if ( ! isset($_FILES[$field])) + { + $this->set_error('upload_no_file_selected'); + return FALSE; + } + + // Is the upload path valid? + if ( ! $this->validate_upload_path()) + { + // errors will already be set by validate_upload_path() so just return FALSE + return FALSE; + } + + // Was the file able to be uploaded? If not, determine the reason why. + if ( ! is_uploaded_file($_FILES[$field]['tmp_name'])) + { + $error = ( ! isset($_FILES[$field]['error'])) ? 4 : $_FILES[$field]['error']; + + switch($error) + { + case 1: // UPLOAD_ERR_INI_SIZE + $this->set_error('upload_file_exceeds_limit'); + break; + case 2: // UPLOAD_ERR_FORM_SIZE + $this->set_error('upload_file_exceeds_form_limit'); + break; + case 3: // UPLOAD_ERR_PARTIAL + $this->set_error('upload_file_partial'); + break; + case 4: // UPLOAD_ERR_NO_FILE + $this->set_error('upload_no_file_selected'); + break; + case 6: // UPLOAD_ERR_NO_TMP_DIR + $this->set_error('upload_no_temp_directory'); + break; + case 7: // UPLOAD_ERR_CANT_WRITE + $this->set_error('upload_unable_to_write_file'); + break; + case 8: // UPLOAD_ERR_EXTENSION + $this->set_error('upload_stopped_by_extension'); + break; + default : $this->set_error('upload_no_file_selected'); + break; + } + + return FALSE; + } + + // Set the uploaded data as class variables + $this->file_temp = $_FILES[$field]['tmp_name']; + $this->file_name = $this->_prep_filename($_FILES[$field]['name']); + $this->file_size = $_FILES[$field]['size']; + $this->file_type = preg_replace("/^(.+?);.*$/", "\\1", $_FILES[$field]['type']); + $this->file_type = strtolower($this->file_type); + $this->file_ext = $this->get_extension($_FILES[$field]['name']); + + // Convert the file size to kilobytes + if ($this->file_size > 0) + { + $this->file_size = round($this->file_size/1024, 2); + } + + // Is the file type allowed to be uploaded? + if ( ! $this->is_allowed_filetype()) + { + $this->set_error('upload_invalid_filetype'); + return FALSE; + } + + // Is the file size within the allowed maximum? + if ( ! $this->is_allowed_filesize()) + { + $this->set_error('upload_invalid_filesize'); + return FALSE; + } + + // Are the image dimensions within the allowed size? + // Note: This can fail if the server has an open_basdir restriction. + if ( ! $this->is_allowed_dimensions()) + { + $this->set_error('upload_invalid_dimensions'); + return FALSE; + } + + // Sanitize the file name for security + $this->file_name = $this->clean_file_name($this->file_name); + + // Truncate the file name if it's too long + if ($this->max_filename > 0) + { + $this->file_name = $this->limit_filename_length($this->file_name, $this->max_filename); + } + + // Remove white spaces in the name + if ($this->remove_spaces == TRUE) + { + $this->file_name = preg_replace("/\s+/", "_", $this->file_name); + } + + /* + * Validate the file name + * This function appends an number onto the end of + * the file if one with the same name already exists. + * If it returns false there was a problem. + */ + $this->orig_name = $this->file_name; + + if ($this->overwrite == FALSE) + { + $this->file_name = $this->set_filename($this->upload_path, $this->file_name); + + if ($this->file_name === FALSE) + { + return FALSE; + } + } + + /* + * Move the file to the final destination + * To deal with different server configurations + * we'll attempt to use copy() first. If that fails + * we'll use move_uploaded_file(). One of the two should + * reliably work in most environments + */ + if ( ! @copy($this->file_temp, $this->upload_path.$this->file_name)) + { + if ( ! @move_uploaded_file($this->file_temp, $this->upload_path.$this->file_name)) + { + $this->set_error('upload_destination_error'); + return FALSE; + } + } + + /* + * Run the file through the XSS hacking filter + * This helps prevent malicious code from being + * embedded within a file. Scripts can easily + * be disguised as images or other file types. + */ + if ($this->xss_clean == TRUE) + { + $this->do_xss_clean(); + } + + /* + * Set the finalized image dimensions + * This sets the image width/height (assuming the + * file was an image). We use this information + * in the "data" function. + */ + $this->set_image_properties($this->upload_path.$this->file_name); + + return TRUE; + } + + // -------------------------------------------------------------------- + + /** + * Finalized Data Array + * + * Returns an associative array containing all of the information + * related to the upload, allowing the developer easy access in one array. + * + * @access public + * @return array + */ + function data() + { + return array ( + 'file_name' => $this->file_name, + 'file_type' => $this->file_type, + 'file_path' => $this->upload_path, + 'full_path' => $this->upload_path.$this->file_name, + 'raw_name' => str_replace($this->file_ext, '', $this->file_name), + 'orig_name' => $this->orig_name, + 'file_ext' => $this->file_ext, + 'file_size' => $this->file_size, + 'is_image' => $this->is_image(), + 'image_width' => $this->image_width, + 'image_height' => $this->image_height, + 'image_type' => $this->image_type, + 'image_size_str' => $this->image_size_str, + ); + } + + // -------------------------------------------------------------------- + + /** + * Set Upload Path + * + * @access public + * @param string + * @return void + */ + function set_upload_path($path) + { + // Make sure it has a trailing slash + $this->upload_path = rtrim($path, '/').'/'; + } + + // -------------------------------------------------------------------- + + /** + * Set the file name + * + * This function takes a filename/path as input and looks for the + * existence of a file with the same name. If found, it will append a + * number to the end of the filename to avoid overwriting a pre-existing file. + * + * @access public + * @param string + * @param string + * @return string + */ + function set_filename($path, $filename) + { + if ($this->encrypt_name == TRUE) + { + mt_srand(); + $filename = md5(uniqid(mt_rand())).$this->file_ext; + } + + if ( ! file_exists($path.$filename)) + { + return $filename; + } + + $filename = str_replace($this->file_ext, '', $filename); + + $new_filename = ''; + for ($i = 1; $i < 100; $i++) + { + if ( ! file_exists($path.$filename.$i.$this->file_ext)) + { + $new_filename = $filename.$i.$this->file_ext; + break; + } + } + + if ($new_filename == '') + { + $this->set_error('upload_bad_filename'); + return FALSE; + } + else + { + return $new_filename; + } + } + + // -------------------------------------------------------------------- + + /** + * Set Maximum File Size + * + * @access public + * @param integer + * @return void + */ + function set_max_filesize($n) + { + $this->max_size = ((int) $n < 0) ? 0: (int) $n; + } + + // -------------------------------------------------------------------- + + /** + * Set Maximum File Name Length + * + * @access public + * @param integer + * @return void + */ + function set_max_filename($n) + { + $this->max_filename = ((int) $n < 0) ? 0: (int) $n; + } + + // -------------------------------------------------------------------- + + /** + * Set Maximum Image Width + * + * @access public + * @param integer + * @return void + */ + function set_max_width($n) + { + $this->max_width = ((int) $n < 0) ? 0: (int) $n; + } + + // -------------------------------------------------------------------- + + /** + * Set Maximum Image Height + * + * @access public + * @param integer + * @return void + */ + function set_max_height($n) + { + $this->max_height = ((int) $n < 0) ? 0: (int) $n; + } + + // -------------------------------------------------------------------- + + /** + * Set Allowed File Types + * + * @access public + * @param string + * @return void + */ + function set_allowed_types($types) + { + $this->allowed_types = explode('|', $types); + } + + // -------------------------------------------------------------------- + + /** + * Set Image Properties + * + * Uses GD to determine the width/height/type of image + * + * @access public + * @param string + * @return void + */ + function set_image_properties($path = '') + { + if ( ! $this->is_image()) + { + return; + } + + if (function_exists('getimagesize')) + { + if (FALSE !== ($D = @getimagesize($path))) + { + $types = array(1 => 'gif', 2 => 'jpeg', 3 => 'png'); + + $this->image_width = $D['0']; + $this->image_height = $D['1']; + $this->image_type = ( ! isset($types[$D['2']])) ? 'unknown' : $types[$D['2']]; + $this->image_size_str = $D['3']; // string containing height and width + } + } + } + + // -------------------------------------------------------------------- + + /** + * Set XSS Clean + * + * Enables the XSS flag so that the file that was uploaded + * will be run through the XSS filter. + * + * @access public + * @param bool + * @return void + */ + function set_xss_clean($flag = FALSE) + { + $this->xss_clean = ($flag == TRUE) ? TRUE : FALSE; + } + + // -------------------------------------------------------------------- + + /** + * Validate the image + * + * @access public + * @return bool + */ + function is_image() + { + // IE will sometimes return odd mime-types during upload, so here we just standardize all + // jpegs or pngs to the same file type. + + $png_mimes = array('image/x-png'); + $jpeg_mimes = array('image/jpg', 'image/jpe', 'image/jpeg', 'image/pjpeg'); + + if (in_array($this->file_type, $png_mimes)) + { + $this->file_type = 'image/png'; + } + + if (in_array($this->file_type, $jpeg_mimes)) + { + $this->file_type = 'image/jpeg'; + } + + $img_mimes = array( + 'image/gif', + 'image/jpeg', + 'image/png', + ); + + return (in_array($this->file_type, $img_mimes, TRUE)) ? TRUE : FALSE; + } + + // -------------------------------------------------------------------- + + /** + * Verify that the filetype is allowed + * + * @access public + * @return bool + */ + function is_allowed_filetype() + { + if (count($this->allowed_types) == 0 OR ! is_array($this->allowed_types)) + { + $this->set_error('upload_no_file_types'); + return FALSE; + } + + foreach ($this->allowed_types as $val) + { + $mime = $this->mimes_types(strtolower($val)); + + if (is_array($mime)) + { + if (in_array($this->file_type, $mime, TRUE)) + { + return TRUE; + } + } + else + { + if ($mime == $this->file_type) + { + return TRUE; + } + } + } + + return FALSE; + } + + // -------------------------------------------------------------------- + + /** + * Verify that the file is within the allowed size + * + * @access public + * @return bool + */ + function is_allowed_filesize() + { + if ($this->max_size != 0 AND $this->file_size > $this->max_size) + { + return FALSE; + } + else + { + return TRUE; + } + } + + // -------------------------------------------------------------------- + + /** + * Verify that the image is within the allowed width/height + * + * @access public + * @return bool + */ + function is_allowed_dimensions() + { + if ( ! $this->is_image()) + { + return TRUE; + } + + if (function_exists('getimagesize')) + { + $D = @getimagesize($this->file_temp); + + if ($this->max_width > 0 AND $D['0'] > $this->max_width) + { + return FALSE; + } + + if ($this->max_height > 0 AND $D['1'] > $this->max_height) + { + return FALSE; + } + + return TRUE; + } + + return TRUE; + } + + // -------------------------------------------------------------------- + + /** + * Validate Upload Path + * + * Verifies that it is a valid upload path with proper permissions. + * + * + * @access public + * @return bool + */ + function validate_upload_path() + { + if ($this->upload_path == '') + { + $this->set_error('upload_no_filepath'); + return FALSE; + } + + if (function_exists('realpath') AND @realpath($this->upload_path) !== FALSE) + { + $this->upload_path = str_replace("\\", "/", realpath($this->upload_path)); + } + + if ( ! @is_dir($this->upload_path)) + { + $this->set_error('upload_no_filepath'); + return FALSE; + } + + if ( ! is_really_writable($this->upload_path)) + { + $this->set_error('upload_not_writable'); + return FALSE; + } + + $this->upload_path = preg_replace("/(.+?)\/*$/", "\\1/", $this->upload_path); + return TRUE; + } + + // -------------------------------------------------------------------- + + /** + * Extract the file extension + * + * @access public + * @param string + * @return string + */ + function get_extension($filename) + { + $x = explode('.', $filename); + return '.'.end($x); + } + + // -------------------------------------------------------------------- + + /** + * Clean the file name for security + * + * @access public + * @param string + * @return string + */ + function clean_file_name($filename) + { + $bad = array( + "", + "'", + "<", + ">", + '"', + '&', + '$', + '=', + ';', + '?', + '/', + "%20", + "%22", + "%3c", // < + "%253c", // < + "%3e", // > + "%0e", // > + "%28", // ( + "%29", // ) + "%2528", // ( + "%26", // & + "%24", // $ + "%3f", // ? + "%3b", // ; + "%3d" // = + ); + + $filename = str_replace($bad, '', $filename); + + return stripslashes($filename); + } + + // -------------------------------------------------------------------- + + /** + * Limit the File Name Length + * + * @access public + * @param string + * @return string + */ + function limit_filename_length($filename, $length) + { + if (strlen($filename) < $length) + { + return $filename; + } + + $ext = ''; + if (strpos($filename, '.') !== FALSE) + { + $parts = explode('.', $filename); + $ext = '.'.array_pop($parts); + $filename = implode('.', $parts); + } + + return substr($filename, 0, ($length - strlen($ext))).$ext; + } + + // -------------------------------------------------------------------- + + /** + * Runs the file through the XSS clean function + * + * This prevents people from embedding malicious code in their files. + * I'm not sure that it won't negatively affect certain files in unexpected ways, + * but so far I haven't found that it causes trouble. + * + * @access public + * @return void + */ + function do_xss_clean() + { + $file = $this->upload_path.$this->file_name; + + if (filesize($file) == 0) + { + return FALSE; + } + + if (($data = @file_get_contents($file)) === FALSE) + { + return FALSE; + } + + if ( ! $fp = @fopen($file, FOPEN_READ_WRITE)) + { + return FALSE; + } + + $CI =& get_instance(); + $data = $CI->input->xss_clean($data); + + flock($fp, LOCK_EX); + fwrite($fp, $data); + flock($fp, LOCK_UN); + fclose($fp); + } + + // -------------------------------------------------------------------- + + /** + * Set an error message + * + * @access public + * @param string + * @return void + */ + function set_error($msg) + { + $CI =& get_instance(); + $CI->lang->load('upload'); + + if (is_array($msg)) + { + foreach ($msg as $val) + { + $msg = ($CI->lang->line($val) == FALSE) ? $val : $CI->lang->line($val); + $this->error_msg[] = $msg; + log_message('error', $msg); + } + } + else + { + $msg = ($CI->lang->line($msg) == FALSE) ? $msg : $CI->lang->line($msg); + $this->error_msg[] = $msg; + log_message('error', $msg); + } + } + + // -------------------------------------------------------------------- + + /** + * Display the error message + * + * @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; + } + + // -------------------------------------------------------------------- + + /** + * List of Mime Types + * + * This is a list of mime types. We use it to validate + * the "allowed types" set by the developer + * + * @access public + * @param string + * @return string + */ + function mimes_types($mime) + { + global $mimes; + + if (count($this->mimes) == 0) + { + if (@require_once(APPPATH.'config/mimes'.EXT)) + { + $this->mimes = $mimes; + unset($mimes); + } + } + + return ( ! isset($this->mimes[$mime])) ? FALSE : $this->mimes[$mime]; + } + + // -------------------------------------------------------------------- + + /** + * Prep Filename + * + * Prevents possible script execution from Apache's handling of files multiple extensions + * http://httpd.apache.org/docs/1.3/mod/mod_mime.html#multipleext + * + * @access private + * @param string + * @return string + */ + function _prep_filename($filename) + { + if (strpos($filename, '.') === FALSE) + { + return $filename; + } + + $parts = explode('.', $filename); + $ext = array_pop($parts); + $filename = array_shift($parts); + + foreach ($parts as $part) + { + if ($this->mimes_types(strtolower($part)) === FALSE) + { + $filename .= '.'.$part.'_'; + } + else + { + $filename .= '.'.$part; + } + } + + $filename .= '.'.$ext; + + return $filename; + } + + // -------------------------------------------------------------------- + +} +// END Upload Class + +/* End of file Upload.php */ /* Location: ./system/libraries/Upload.php */ \ No newline at end of file diff --git a/system/libraries/User_agent.php b/system/libraries/User_agent.php index c7cf87030..78178d02f 100644 --- a/system/libraries/User_agent.php +++ b/system/libraries/User_agent.php @@ -1,502 +1,502 @@ -agent = trim($_SERVER['HTTP_USER_AGENT']); - } - - if ( ! is_null($this->agent)) - { - if ($this->_load_agent_file()) - { - $this->_compile_data(); - } - } - - log_message('debug', "User Agent Class Initialized"); - } - - // -------------------------------------------------------------------- - - /** - * Compile the User Agent Data - * - * @access private - * @return bool - */ - function _load_agent_file() - { - if ( ! @include(APPPATH.'config/user_agents'.EXT)) - { - return FALSE; - } - - $return = FALSE; - - if (isset($platforms)) - { - $this->platforms = $platforms; - unset($platforms); - $return = TRUE; - } - - if (isset($browsers)) - { - $this->browsers = $browsers; - unset($browsers); - $return = TRUE; - } - - if (isset($mobiles)) - { - $this->mobiles = $mobiles; - unset($mobiles); - $return = TRUE; - } - - if (isset($robots)) - { - $this->robots = $robots; - unset($robots); - $return = TRUE; - } - - return $return; - } - - // -------------------------------------------------------------------- - - /** - * Compile the User Agent Data - * - * @access private - * @return bool - */ - function _compile_data() - { - $this->_set_platform(); - - foreach (array('_set_browser', '_set_robot', '_set_mobile') as $function) - { - if ($this->$function() === TRUE) - { - break; - } - } - } - - // -------------------------------------------------------------------- - - /** - * Set the Platform - * - * @access private - * @return mixed - */ - function _set_platform() - { - if (is_array($this->platforms) AND count($this->platforms) > 0) - { - foreach ($this->platforms as $key => $val) - { - if (preg_match("|".preg_quote($key)."|i", $this->agent)) - { - $this->platform = $val; - return TRUE; - } - } - } - $this->platform = 'Unknown Platform'; - } - - // -------------------------------------------------------------------- - - /** - * Set the Browser - * - * @access private - * @return bool - */ - function _set_browser() - { - if (is_array($this->browsers) AND count($this->browsers) > 0) - { - foreach ($this->browsers as $key => $val) - { - if (preg_match("|".preg_quote($key).".*?([0-9\.]+)|i", $this->agent, $match)) - { - $this->is_browser = TRUE; - $this->version = $match[1]; - $this->browser = $val; - $this->_set_mobile(); - return TRUE; - } - } - } - return FALSE; - } - - // -------------------------------------------------------------------- - - /** - * Set the Robot - * - * @access private - * @return bool - */ - function _set_robot() - { - if (is_array($this->robots) AND count($this->robots) > 0) - { - foreach ($this->robots as $key => $val) - { - if (preg_match("|".preg_quote($key)."|i", $this->agent)) - { - $this->is_robot = TRUE; - $this->robot = $val; - return TRUE; - } - } - } - return FALSE; - } - - // -------------------------------------------------------------------- - - /** - * Set the Mobile Device - * - * @access private - * @return bool - */ - function _set_mobile() - { - if (is_array($this->mobiles) AND count($this->mobiles) > 0) - { - foreach ($this->mobiles as $key => $val) - { - if (FALSE !== (strpos(strtolower($this->agent), $key))) - { - $this->is_mobile = TRUE; - $this->mobile = $val; - return TRUE; - } - } - } - return FALSE; - } - - // -------------------------------------------------------------------- - - /** - * Set the accepted languages - * - * @access private - * @return void - */ - function _set_languages() - { - if ((count($this->languages) == 0) AND isset($_SERVER['HTTP_ACCEPT_LANGUAGE']) AND $_SERVER['HTTP_ACCEPT_LANGUAGE'] != '') - { - $languages = preg_replace('/(;q=[0-9\.]+)/i', '', strtolower(trim($_SERVER['HTTP_ACCEPT_LANGUAGE']))); - - $this->languages = explode(',', $languages); - } - - if (count($this->languages) == 0) - { - $this->languages = array('Undefined'); - } - } - - // -------------------------------------------------------------------- - - /** - * Set the accepted character sets - * - * @access private - * @return void - */ - function _set_charsets() - { - if ((count($this->charsets) == 0) AND isset($_SERVER['HTTP_ACCEPT_CHARSET']) AND $_SERVER['HTTP_ACCEPT_CHARSET'] != '') - { - $charsets = preg_replace('/(;q=.+)/i', '', strtolower(trim($_SERVER['HTTP_ACCEPT_CHARSET']))); - - $this->charsets = explode(',', $charsets); - } - - if (count($this->charsets) == 0) - { - $this->charsets = array('Undefined'); - } - } - - // -------------------------------------------------------------------- - - /** - * Is Browser - * - * @access public - * @return bool - */ - function is_browser() - { - return $this->is_browser; - } - - // -------------------------------------------------------------------- - - /** - * Is Robot - * - * @access public - * @return bool - */ - function is_robot() - { - return $this->is_robot; - } - - // -------------------------------------------------------------------- - - /** - * Is Mobile - * - * @access public - * @return bool - */ - function is_mobile() - { - return $this->is_mobile; - } - - // -------------------------------------------------------------------- - - /** - * Is this a referral from another site? - * - * @access public - * @return bool - */ - function is_referral() - { - return ( ! isset($_SERVER['HTTP_REFERER']) OR $_SERVER['HTTP_REFERER'] == '') ? FALSE : TRUE; - } - - // -------------------------------------------------------------------- - - /** - * Agent String - * - * @access public - * @return string - */ - function agent_string() - { - return $this->agent; - } - - // -------------------------------------------------------------------- - - /** - * Get Platform - * - * @access public - * @return string - */ - function platform() - { - return $this->platform; - } - - // -------------------------------------------------------------------- - - /** - * Get Browser Name - * - * @access public - * @return string - */ - function browser() - { - return $this->browser; - } - - // -------------------------------------------------------------------- - - /** - * Get the Browser Version - * - * @access public - * @return string - */ - function version() - { - return $this->version; - } - - // -------------------------------------------------------------------- - - /** - * Get The Robot Name - * - * @access public - * @return string - */ - function robot() - { - return $this->robot; - } - // -------------------------------------------------------------------- - - /** - * Get the Mobile Device - * - * @access public - * @return string - */ - function mobile() - { - return $this->mobile; - } - - // -------------------------------------------------------------------- - - /** - * Get the referrer - * - * @access public - * @return bool - */ - function referrer() - { - return ( ! isset($_SERVER['HTTP_REFERER']) OR $_SERVER['HTTP_REFERER'] == '') ? '' : trim($_SERVER['HTTP_REFERER']); - } - - // -------------------------------------------------------------------- - - /** - * Get the accepted languages - * - * @access public - * @return array - */ - function languages() - { - if (count($this->languages) == 0) - { - $this->_set_languages(); - } - - return $this->languages; - } - - // -------------------------------------------------------------------- - - /** - * Get the accepted Character Sets - * - * @access public - * @return array - */ - function charsets() - { - if (count($this->charsets) == 0) - { - $this->_set_charsets(); - } - - return $this->charsets; - } - - // -------------------------------------------------------------------- - - /** - * Test for a particular language - * - * @access public - * @return bool - */ - function accept_lang($lang = 'en') - { - return (in_array(strtolower($lang), $this->languages(), TRUE)) ? TRUE : FALSE; - } - - // -------------------------------------------------------------------- - - /** - * Test for a particular character set - * - * @access public - * @return bool - */ - function accept_charset($charset = 'utf-8') - { - return (in_array(strtolower($charset), $this->charsets(), TRUE)) ? TRUE : FALSE; - } - - -} - - -/* End of file User_agent.php */ +agent = trim($_SERVER['HTTP_USER_AGENT']); + } + + if ( ! is_null($this->agent)) + { + if ($this->_load_agent_file()) + { + $this->_compile_data(); + } + } + + log_message('debug', "User Agent Class Initialized"); + } + + // -------------------------------------------------------------------- + + /** + * Compile the User Agent Data + * + * @access private + * @return bool + */ + function _load_agent_file() + { + if ( ! @include(APPPATH.'config/user_agents'.EXT)) + { + return FALSE; + } + + $return = FALSE; + + if (isset($platforms)) + { + $this->platforms = $platforms; + unset($platforms); + $return = TRUE; + } + + if (isset($browsers)) + { + $this->browsers = $browsers; + unset($browsers); + $return = TRUE; + } + + if (isset($mobiles)) + { + $this->mobiles = $mobiles; + unset($mobiles); + $return = TRUE; + } + + if (isset($robots)) + { + $this->robots = $robots; + unset($robots); + $return = TRUE; + } + + return $return; + } + + // -------------------------------------------------------------------- + + /** + * Compile the User Agent Data + * + * @access private + * @return bool + */ + function _compile_data() + { + $this->_set_platform(); + + foreach (array('_set_browser', '_set_robot', '_set_mobile') as $function) + { + if ($this->$function() === TRUE) + { + break; + } + } + } + + // -------------------------------------------------------------------- + + /** + * Set the Platform + * + * @access private + * @return mixed + */ + function _set_platform() + { + if (is_array($this->platforms) AND count($this->platforms) > 0) + { + foreach ($this->platforms as $key => $val) + { + if (preg_match("|".preg_quote($key)."|i", $this->agent)) + { + $this->platform = $val; + return TRUE; + } + } + } + $this->platform = 'Unknown Platform'; + } + + // -------------------------------------------------------------------- + + /** + * Set the Browser + * + * @access private + * @return bool + */ + function _set_browser() + { + if (is_array($this->browsers) AND count($this->browsers) > 0) + { + foreach ($this->browsers as $key => $val) + { + if (preg_match("|".preg_quote($key).".*?([0-9\.]+)|i", $this->agent, $match)) + { + $this->is_browser = TRUE; + $this->version = $match[1]; + $this->browser = $val; + $this->_set_mobile(); + return TRUE; + } + } + } + return FALSE; + } + + // -------------------------------------------------------------------- + + /** + * Set the Robot + * + * @access private + * @return bool + */ + function _set_robot() + { + if (is_array($this->robots) AND count($this->robots) > 0) + { + foreach ($this->robots as $key => $val) + { + if (preg_match("|".preg_quote($key)."|i", $this->agent)) + { + $this->is_robot = TRUE; + $this->robot = $val; + return TRUE; + } + } + } + return FALSE; + } + + // -------------------------------------------------------------------- + + /** + * Set the Mobile Device + * + * @access private + * @return bool + */ + function _set_mobile() + { + if (is_array($this->mobiles) AND count($this->mobiles) > 0) + { + foreach ($this->mobiles as $key => $val) + { + if (FALSE !== (strpos(strtolower($this->agent), $key))) + { + $this->is_mobile = TRUE; + $this->mobile = $val; + return TRUE; + } + } + } + return FALSE; + } + + // -------------------------------------------------------------------- + + /** + * Set the accepted languages + * + * @access private + * @return void + */ + function _set_languages() + { + if ((count($this->languages) == 0) AND isset($_SERVER['HTTP_ACCEPT_LANGUAGE']) AND $_SERVER['HTTP_ACCEPT_LANGUAGE'] != '') + { + $languages = preg_replace('/(;q=[0-9\.]+)/i', '', strtolower(trim($_SERVER['HTTP_ACCEPT_LANGUAGE']))); + + $this->languages = explode(',', $languages); + } + + if (count($this->languages) == 0) + { + $this->languages = array('Undefined'); + } + } + + // -------------------------------------------------------------------- + + /** + * Set the accepted character sets + * + * @access private + * @return void + */ + function _set_charsets() + { + if ((count($this->charsets) == 0) AND isset($_SERVER['HTTP_ACCEPT_CHARSET']) AND $_SERVER['HTTP_ACCEPT_CHARSET'] != '') + { + $charsets = preg_replace('/(;q=.+)/i', '', strtolower(trim($_SERVER['HTTP_ACCEPT_CHARSET']))); + + $this->charsets = explode(',', $charsets); + } + + if (count($this->charsets) == 0) + { + $this->charsets = array('Undefined'); + } + } + + // -------------------------------------------------------------------- + + /** + * Is Browser + * + * @access public + * @return bool + */ + function is_browser() + { + return $this->is_browser; + } + + // -------------------------------------------------------------------- + + /** + * Is Robot + * + * @access public + * @return bool + */ + function is_robot() + { + return $this->is_robot; + } + + // -------------------------------------------------------------------- + + /** + * Is Mobile + * + * @access public + * @return bool + */ + function is_mobile() + { + return $this->is_mobile; + } + + // -------------------------------------------------------------------- + + /** + * Is this a referral from another site? + * + * @access public + * @return bool + */ + function is_referral() + { + return ( ! isset($_SERVER['HTTP_REFERER']) OR $_SERVER['HTTP_REFERER'] == '') ? FALSE : TRUE; + } + + // -------------------------------------------------------------------- + + /** + * Agent String + * + * @access public + * @return string + */ + function agent_string() + { + return $this->agent; + } + + // -------------------------------------------------------------------- + + /** + * Get Platform + * + * @access public + * @return string + */ + function platform() + { + return $this->platform; + } + + // -------------------------------------------------------------------- + + /** + * Get Browser Name + * + * @access public + * @return string + */ + function browser() + { + return $this->browser; + } + + // -------------------------------------------------------------------- + + /** + * Get the Browser Version + * + * @access public + * @return string + */ + function version() + { + return $this->version; + } + + // -------------------------------------------------------------------- + + /** + * Get The Robot Name + * + * @access public + * @return string + */ + function robot() + { + return $this->robot; + } + // -------------------------------------------------------------------- + + /** + * Get the Mobile Device + * + * @access public + * @return string + */ + function mobile() + { + return $this->mobile; + } + + // -------------------------------------------------------------------- + + /** + * Get the referrer + * + * @access public + * @return bool + */ + function referrer() + { + return ( ! isset($_SERVER['HTTP_REFERER']) OR $_SERVER['HTTP_REFERER'] == '') ? '' : trim($_SERVER['HTTP_REFERER']); + } + + // -------------------------------------------------------------------- + + /** + * Get the accepted languages + * + * @access public + * @return array + */ + function languages() + { + if (count($this->languages) == 0) + { + $this->_set_languages(); + } + + return $this->languages; + } + + // -------------------------------------------------------------------- + + /** + * Get the accepted Character Sets + * + * @access public + * @return array + */ + function charsets() + { + if (count($this->charsets) == 0) + { + $this->_set_charsets(); + } + + return $this->charsets; + } + + // -------------------------------------------------------------------- + + /** + * Test for a particular language + * + * @access public + * @return bool + */ + function accept_lang($lang = 'en') + { + return (in_array(strtolower($lang), $this->languages(), TRUE)) ? TRUE : FALSE; + } + + // -------------------------------------------------------------------- + + /** + * Test for a particular character set + * + * @access public + * @return bool + */ + function accept_charset($charset = 'utf-8') + { + return (in_array(strtolower($charset), $this->charsets(), TRUE)) ? TRUE : FALSE; + } + + +} + + +/* End of file User_agent.php */ /* Location: ./system/libraries/User_agent.php */ \ No newline at end of file diff --git a/system/libraries/Validation.php b/system/libraries/Validation.php index a463202eb..4baf78b91 100644 --- a/system/libraries/Validation.php +++ b/system/libraries/Validation.php @@ -1,875 +1,875 @@ -'; - var $_error_suffix = '

    '; - - - - /** - * Constructor - * - */ - function CI_Validation() - { - $this->CI =& get_instance(); - - if (function_exists('mb_internal_encoding')) - { - mb_internal_encoding($this->CI->config->item('charset')); - } - - log_message('debug', "Validation Class Initialized"); - } - - // -------------------------------------------------------------------- - - /** - * Set Fields - * - * This function takes an array of field names as input - * and generates class variables with the same name, which will - * either be blank or contain the $_POST value corresponding to it - * - * @access public - * @param string - * @param string - * @return void - */ - function set_fields($data = '', $field = '') - { - if ($data == '') - { - if (count($this->_fields) == 0) - { - return FALSE; - } - } - else - { - if ( ! is_array($data)) - { - $data = array($data => $field); - } - - if (count($data) > 0) - { - $this->_fields = $data; - } - } - - foreach($this->_fields as $key => $val) - { - $this->$key = ( ! isset($_POST[$key])) ? '' : $this->prep_for_form($_POST[$key]); - - $error = $key.'_error'; - if ( ! isset($this->$error)) - { - $this->$error = ''; - } - } - } - - // -------------------------------------------------------------------- - - /** - * Set Rules - * - * This function takes an array of field names and validation - * rules as input ad simply stores is for use later. - * - * @access public - * @param mixed - * @param string - * @return void - */ - function set_rules($data, $rules = '') - { - if ( ! is_array($data)) - { - if ($rules == '') - return; - - $data = array($data => $rules); - } - - foreach ($data as $key => $val) - { - $this->_rules[$key] = $val; - } - } - - // -------------------------------------------------------------------- - - /** - * Set Error Message - * - * Lets users set their own error messages on the fly. Note: The key - * name has to match the function name that it corresponds to. - * - * @access public - * @param string - * @param string - * @return string - */ - function set_message($lang, $val = '') - { - if ( ! is_array($lang)) - { - $lang = array($lang => $val); - } - - $this->_error_messages = array_merge($this->_error_messages, $lang); - } - - // -------------------------------------------------------------------- - - /** - * Set The Error Delimiter - * - * Permits a prefix/suffix to be added to each error message - * - * @access public - * @param string - * @param string - * @return void - */ - function set_error_delimiters($prefix = '

    ', $suffix = '

    ') - { - $this->_error_prefix = $prefix; - $this->_error_suffix = $suffix; - } - - // -------------------------------------------------------------------- - - /** - * Run the Validator - * - * This function does all the work. - * - * @access public - * @return bool - */ - function run() - { - // Do we even have any data to process? Mm? - if (count($_POST) == 0 OR count($this->_rules) == 0) - { - return FALSE; - } - - // Load the language file containing error messages - $this->CI->lang->load('validation'); - - // Cycle through the rules and test for errors - foreach ($this->_rules as $field => $rules) - { - //Explode out the rules! - $ex = explode('|', $rules); - - // Is the field required? If not, if the field is blank we'll move on to the next test - if ( ! in_array('required', $ex, TRUE)) - { - if ( ! isset($_POST[$field]) OR $_POST[$field] == '') - { - continue; - } - } - - /* - * Are we dealing with an "isset" rule? - * - * Before going further, we'll see if one of the rules - * is to check whether the item is set (typically this - * applies only to checkboxes). If so, we'll - * test for it here since there's not reason to go - * further - */ - if ( ! isset($_POST[$field])) - { - if (in_array('isset', $ex, TRUE) OR in_array('required', $ex)) - { - if ( ! isset($this->_error_messages['isset'])) - { - if (FALSE === ($line = $this->CI->lang->line('isset'))) - { - $line = 'The field was not set'; - } - } - else - { - $line = $this->_error_messages['isset']; - } - - // Build the error message - $mfield = ( ! isset($this->_fields[$field])) ? $field : $this->_fields[$field]; - $message = sprintf($line, $mfield); - - // Set the error variable. Example: $this->username_error - $error = $field.'_error'; - $this->$error = $this->_error_prefix.$message.$this->_error_suffix; - $this->_error_array[] = $message; - } - - continue; - } - - /* - * Set the current field - * - * The various prepping functions need to know the - * current field name so they can do this: - * - * $_POST[$this->_current_field] == 'bla bla'; - */ - $this->_current_field = $field; - - // Cycle through the rules! - foreach ($ex As $rule) - { - // Is the rule a callback? - $callback = FALSE; - if (substr($rule, 0, 9) == 'callback_') - { - $rule = substr($rule, 9); - $callback = TRUE; - } - - // Strip the parameter (if exists) from the rule - // Rules can contain a parameter: max_length[5] - $param = FALSE; - if (preg_match("/(.*?)\[(.*?)\]/", $rule, $match)) - { - $rule = $match[1]; - $param = $match[2]; - } - - // Call the function that corresponds to the rule - if ($callback === TRUE) - { - if ( ! method_exists($this->CI, $rule)) - { - continue; - } - - $result = $this->CI->$rule($_POST[$field], $param); - - // If the field isn't required and we just processed a callback we'll move on... - if ( ! in_array('required', $ex, TRUE) AND $result !== FALSE) - { - continue 2; - } - - } - else - { - if ( ! method_exists($this, $rule)) - { - /* - * Run the native PHP function if called for - * - * If our own wrapper function doesn't exist we see - * if a native PHP function does. Users can use - * any native PHP function call that has one param. - */ - if (function_exists($rule)) - { - $_POST[$field] = $rule($_POST[$field]); - $this->$field = $_POST[$field]; - } - - continue; - } - - $result = $this->$rule($_POST[$field], $param); - } - - // Did the rule test negatively? If so, grab the error. - if ($result === FALSE) - { - if ( ! isset($this->_error_messages[$rule])) - { - if (FALSE === ($line = $this->CI->lang->line($rule))) - { - $line = 'Unable to access an error message corresponding to your field name.'; - } - } - else - { - $line = $this->_error_messages[$rule]; - } - - // Build the error message - $mfield = ( ! isset($this->_fields[$field])) ? $field : $this->_fields[$field]; - $mparam = ( ! isset($this->_fields[$param])) ? $param : $this->_fields[$param]; - $message = sprintf($line, $mfield, $mparam); - - // Set the error variable. Example: $this->username_error - $error = $field.'_error'; - $this->$error = $this->_error_prefix.$message.$this->_error_suffix; - - // Add the error to the error array - $this->_error_array[] = $message; - continue 2; - } - } - - } - - $total_errors = count($this->_error_array); - - /* - * Recompile the class variables - * - * If any prepping functions were called the $_POST data - * might now be different then the corresponding class - * variables so we'll set them anew. - */ - if ($total_errors > 0) - { - $this->_safe_form_data = TRUE; - } - - $this->set_fields(); - - // Did we end up with any errors? - if ($total_errors == 0) - { - return TRUE; - } - - // Generate the error string - foreach ($this->_error_array as $val) - { - $this->error_string .= $this->_error_prefix.$val.$this->_error_suffix."\n"; - } - - return FALSE; - } - - // -------------------------------------------------------------------- - - /** - * Required - * - * @access public - * @param string - * @return bool - */ - function required($str) - { - if ( ! is_array($str)) - { - return (trim($str) == '') ? FALSE : TRUE; - } - else - { - return ( ! empty($str)); - } - } - - // -------------------------------------------------------------------- - - /** - * Match one field to another - * - * @access public - * @param string - * @param field - * @return bool - */ - function matches($str, $field) - { - if ( ! isset($_POST[$field])) - { - return FALSE; - } - - return ($str !== $_POST[$field]) ? FALSE : TRUE; - } - - // -------------------------------------------------------------------- - - /** - * Minimum Length - * - * @access public - * @param string - * @param value - * @return bool - */ - function min_length($str, $val) - { - if (preg_match("/[^0-9]/", $val)) - { - return FALSE; - } - - if (function_exists('mb_strlen')) - { - return (mb_strlen($str) < $val) ? FALSE : TRUE; - } - - return (strlen($str) < $val) ? FALSE : TRUE; - } - - // -------------------------------------------------------------------- - - /** - * Max Length - * - * @access public - * @param string - * @param value - * @return bool - */ - function max_length($str, $val) - { - if (preg_match("/[^0-9]/", $val)) - { - return FALSE; - } - - if (function_exists('mb_strlen')) - { - return (mb_strlen($str) > $val) ? FALSE : TRUE; - } - - return (strlen($str) > $val) ? FALSE : TRUE; - } - - // -------------------------------------------------------------------- - - /** - * Exact Length - * - * @access public - * @param string - * @param value - * @return bool - */ - function exact_length($str, $val) - { - if (preg_match("/[^0-9]/", $val)) - { - return FALSE; - } - - if (function_exists('mb_strlen')) - { - return (mb_strlen($str) != $val) ? FALSE : TRUE; - } - - return (strlen($str) != $val) ? FALSE : TRUE; - } - - // -------------------------------------------------------------------- - - /** - * Valid Email - * - * @access public - * @param string - * @return bool - */ - function valid_email($str) - { - return ( ! preg_match("/^([a-z0-9\+_\-]+)(\.[a-z0-9\+_\-]+)*@([a-z0-9\-]+\.)+[a-z]{2,6}$/ix", $str)) ? FALSE : TRUE; - } - - // -------------------------------------------------------------------- - - /** - * Valid Emails - * - * @access public - * @param string - * @return bool - */ - function valid_emails($str) - { - if (strpos($str, ',') === FALSE) - { - return $this->valid_email(trim($str)); - } - - foreach(explode(',', $str) as $email) - { - if (trim($email) != '' && $this->valid_email(trim($email)) === FALSE) - { - return FALSE; - } - } - - return TRUE; - } - - // -------------------------------------------------------------------- - - /** - * Validate IP Address - * - * @access public - * @param string - * @return string - */ - function valid_ip($ip) - { - return $this->CI->input->valid_ip($ip); - } - - // -------------------------------------------------------------------- - - /** - * Alpha - * - * @access public - * @param string - * @return bool - */ - function alpha($str) - { - return ( ! preg_match("/^([a-z])+$/i", $str)) ? FALSE : TRUE; - } - - // -------------------------------------------------------------------- - - /** - * Alpha-numeric - * - * @access public - * @param string - * @return bool - */ - function alpha_numeric($str) - { - return ( ! preg_match("/^([a-z0-9])+$/i", $str)) ? FALSE : TRUE; - } - - // -------------------------------------------------------------------- - - /** - * Alpha-numeric with underscores and dashes - * - * @access public - * @param string - * @return bool - */ - function alpha_dash($str) - { - return ( ! preg_match("/^([-a-z0-9_-])+$/i", $str)) ? FALSE : TRUE; - } - - // -------------------------------------------------------------------- - - /** - * Numeric - * - * @access public - * @param string - * @return bool - */ - function numeric($str) - { - return (bool)preg_match( '/^[\-+]?[0-9]*\.?[0-9]+$/', $str); - - } - - // -------------------------------------------------------------------- - - /** - * Is Numeric - * - * @access public - * @param string - * @return bool - */ - function is_numeric($str) - { - return ( ! is_numeric($str)) ? FALSE : TRUE; - } - - // -------------------------------------------------------------------- - - /** - * Integer - * - * @access public - * @param string - * @return bool - */ - function integer($str) - { - return (bool)preg_match( '/^[\-+]?[0-9]+$/', $str); - } - - // -------------------------------------------------------------------- - - /** - * Is a Natural number (0,1,2,3, etc.) - * - * @access public - * @param string - * @return bool - */ - function is_natural($str) - { - return (bool)preg_match( '/^[0-9]+$/', $str); - } - - // -------------------------------------------------------------------- - - /** - * Is a Natural number, but not a zero (1,2,3, etc.) - * - * @access public - * @param string - * @return bool - */ - function is_natural_no_zero($str) - { - if ( ! preg_match( '/^[0-9]+$/', $str)) - { - return FALSE; - } - - if ($str == 0) - { - return FALSE; - } - - return TRUE; - } - - // -------------------------------------------------------------------- - - /** - * Valid Base64 - * - * Tests a string for characters outside of the Base64 alphabet - * as defined by RFC 2045 http://www.faqs.org/rfcs/rfc2045 - * - * @access public - * @param string - * @return bool - */ - function valid_base64($str) - { - return (bool) ! preg_match('/[^a-zA-Z0-9\/\+=]/', $str); - } - - // -------------------------------------------------------------------- - - /** - * Set Select - * - * Enables pull-down lists to be set to the value the user - * selected in the event of an error - * - * @access public - * @param string - * @param string - * @return string - */ - function set_select($field = '', $value = '') - { - if ($field == '' OR $value == '' OR ! isset($_POST[$field])) - { - return ''; - } - - if ($_POST[$field] == $value) - { - return ' selected="selected"'; - } - } - - // -------------------------------------------------------------------- - - /** - * Set Radio - * - * Enables radio buttons to be set to the value the user - * selected in the event of an error - * - * @access public - * @param string - * @param string - * @return string - */ - function set_radio($field = '', $value = '') - { - if ($field == '' OR $value == '' OR ! isset($_POST[$field])) - { - return ''; - } - - if ($_POST[$field] == $value) - { - return ' checked="checked"'; - } - } - - // -------------------------------------------------------------------- - - /** - * Set Checkbox - * - * Enables checkboxes to be set to the value the user - * selected in the event of an error - * - * @access public - * @param string - * @param string - * @return string - */ - function set_checkbox($field = '', $value = '') - { - if ($field == '' OR $value == '' OR ! isset($_POST[$field])) - { - return ''; - } - - if ($_POST[$field] == $value) - { - return ' checked="checked"'; - } - } - - // -------------------------------------------------------------------- - - /** - * Prep data for form - * - * This function allows HTML to be safely shown in a form. - * Special characters are converted. - * - * @access public - * @param string - * @return string - */ - function prep_for_form($data = '') - { - if (is_array($data)) - { - foreach ($data as $key => $val) - { - $data[$key] = $this->prep_for_form($val); - } - - return $data; - } - - if ($this->_safe_form_data == FALSE OR $data == '') - { - return $data; - } - - return str_replace(array("'", '"', '<', '>'), array("'", """, '<', '>'), stripslashes($data)); - } - - // -------------------------------------------------------------------- - - /** - * Prep URL - * - * @access public - * @param string - * @return string - */ - function prep_url($str = '') - { - if ($str == 'http://' OR $str == '') - { - $_POST[$this->_current_field] = ''; - return; - } - - if (substr($str, 0, 7) != 'http://' && substr($str, 0, 8) != 'https://') - { - $str = 'http://'.$str; - } - - $_POST[$this->_current_field] = $str; - } - - // -------------------------------------------------------------------- - - /** - * Strip Image Tags - * - * @access public - * @param string - * @return string - */ - function strip_image_tags($str) - { - $_POST[$this->_current_field] = $this->CI->input->strip_image_tags($str); - } - - // -------------------------------------------------------------------- - - /** - * XSS Clean - * - * @access public - * @param string - * @return string - */ - function xss_clean($str) - { - $_POST[$this->_current_field] = $this->CI->input->xss_clean($str); - } - - // -------------------------------------------------------------------- - - /** - * Convert PHP tags to entities - * - * @access public - * @param string - * @return string - */ - function encode_php_tags($str) - { - $_POST[$this->_current_field] = str_replace(array(''), array('<?php', '<?PHP', '<?', '?>'), $str); - } - -} -// END Validation Class - -/* End of file Validation.php */ +'; + var $_error_suffix = '

    '; + + + + /** + * Constructor + * + */ + function CI_Validation() + { + $this->CI =& get_instance(); + + if (function_exists('mb_internal_encoding')) + { + mb_internal_encoding($this->CI->config->item('charset')); + } + + log_message('debug', "Validation Class Initialized"); + } + + // -------------------------------------------------------------------- + + /** + * Set Fields + * + * This function takes an array of field names as input + * and generates class variables with the same name, which will + * either be blank or contain the $_POST value corresponding to it + * + * @access public + * @param string + * @param string + * @return void + */ + function set_fields($data = '', $field = '') + { + if ($data == '') + { + if (count($this->_fields) == 0) + { + return FALSE; + } + } + else + { + if ( ! is_array($data)) + { + $data = array($data => $field); + } + + if (count($data) > 0) + { + $this->_fields = $data; + } + } + + foreach($this->_fields as $key => $val) + { + $this->$key = ( ! isset($_POST[$key])) ? '' : $this->prep_for_form($_POST[$key]); + + $error = $key.'_error'; + if ( ! isset($this->$error)) + { + $this->$error = ''; + } + } + } + + // -------------------------------------------------------------------- + + /** + * Set Rules + * + * This function takes an array of field names and validation + * rules as input ad simply stores is for use later. + * + * @access public + * @param mixed + * @param string + * @return void + */ + function set_rules($data, $rules = '') + { + if ( ! is_array($data)) + { + if ($rules == '') + return; + + $data = array($data => $rules); + } + + foreach ($data as $key => $val) + { + $this->_rules[$key] = $val; + } + } + + // -------------------------------------------------------------------- + + /** + * Set Error Message + * + * Lets users set their own error messages on the fly. Note: The key + * name has to match the function name that it corresponds to. + * + * @access public + * @param string + * @param string + * @return string + */ + function set_message($lang, $val = '') + { + if ( ! is_array($lang)) + { + $lang = array($lang => $val); + } + + $this->_error_messages = array_merge($this->_error_messages, $lang); + } + + // -------------------------------------------------------------------- + + /** + * Set The Error Delimiter + * + * Permits a prefix/suffix to be added to each error message + * + * @access public + * @param string + * @param string + * @return void + */ + function set_error_delimiters($prefix = '

    ', $suffix = '

    ') + { + $this->_error_prefix = $prefix; + $this->_error_suffix = $suffix; + } + + // -------------------------------------------------------------------- + + /** + * Run the Validator + * + * This function does all the work. + * + * @access public + * @return bool + */ + function run() + { + // Do we even have any data to process? Mm? + if (count($_POST) == 0 OR count($this->_rules) == 0) + { + return FALSE; + } + + // Load the language file containing error messages + $this->CI->lang->load('validation'); + + // Cycle through the rules and test for errors + foreach ($this->_rules as $field => $rules) + { + //Explode out the rules! + $ex = explode('|', $rules); + + // Is the field required? If not, if the field is blank we'll move on to the next test + if ( ! in_array('required', $ex, TRUE)) + { + if ( ! isset($_POST[$field]) OR $_POST[$field] == '') + { + continue; + } + } + + /* + * Are we dealing with an "isset" rule? + * + * Before going further, we'll see if one of the rules + * is to check whether the item is set (typically this + * applies only to checkboxes). If so, we'll + * test for it here since there's not reason to go + * further + */ + if ( ! isset($_POST[$field])) + { + if (in_array('isset', $ex, TRUE) OR in_array('required', $ex)) + { + if ( ! isset($this->_error_messages['isset'])) + { + if (FALSE === ($line = $this->CI->lang->line('isset'))) + { + $line = 'The field was not set'; + } + } + else + { + $line = $this->_error_messages['isset']; + } + + // Build the error message + $mfield = ( ! isset($this->_fields[$field])) ? $field : $this->_fields[$field]; + $message = sprintf($line, $mfield); + + // Set the error variable. Example: $this->username_error + $error = $field.'_error'; + $this->$error = $this->_error_prefix.$message.$this->_error_suffix; + $this->_error_array[] = $message; + } + + continue; + } + + /* + * Set the current field + * + * The various prepping functions need to know the + * current field name so they can do this: + * + * $_POST[$this->_current_field] == 'bla bla'; + */ + $this->_current_field = $field; + + // Cycle through the rules! + foreach ($ex As $rule) + { + // Is the rule a callback? + $callback = FALSE; + if (substr($rule, 0, 9) == 'callback_') + { + $rule = substr($rule, 9); + $callback = TRUE; + } + + // Strip the parameter (if exists) from the rule + // Rules can contain a parameter: max_length[5] + $param = FALSE; + if (preg_match("/(.*?)\[(.*?)\]/", $rule, $match)) + { + $rule = $match[1]; + $param = $match[2]; + } + + // Call the function that corresponds to the rule + if ($callback === TRUE) + { + if ( ! method_exists($this->CI, $rule)) + { + continue; + } + + $result = $this->CI->$rule($_POST[$field], $param); + + // If the field isn't required and we just processed a callback we'll move on... + if ( ! in_array('required', $ex, TRUE) AND $result !== FALSE) + { + continue 2; + } + + } + else + { + if ( ! method_exists($this, $rule)) + { + /* + * Run the native PHP function if called for + * + * If our own wrapper function doesn't exist we see + * if a native PHP function does. Users can use + * any native PHP function call that has one param. + */ + if (function_exists($rule)) + { + $_POST[$field] = $rule($_POST[$field]); + $this->$field = $_POST[$field]; + } + + continue; + } + + $result = $this->$rule($_POST[$field], $param); + } + + // Did the rule test negatively? If so, grab the error. + if ($result === FALSE) + { + if ( ! isset($this->_error_messages[$rule])) + { + if (FALSE === ($line = $this->CI->lang->line($rule))) + { + $line = 'Unable to access an error message corresponding to your field name.'; + } + } + else + { + $line = $this->_error_messages[$rule]; + } + + // Build the error message + $mfield = ( ! isset($this->_fields[$field])) ? $field : $this->_fields[$field]; + $mparam = ( ! isset($this->_fields[$param])) ? $param : $this->_fields[$param]; + $message = sprintf($line, $mfield, $mparam); + + // Set the error variable. Example: $this->username_error + $error = $field.'_error'; + $this->$error = $this->_error_prefix.$message.$this->_error_suffix; + + // Add the error to the error array + $this->_error_array[] = $message; + continue 2; + } + } + + } + + $total_errors = count($this->_error_array); + + /* + * Recompile the class variables + * + * If any prepping functions were called the $_POST data + * might now be different then the corresponding class + * variables so we'll set them anew. + */ + if ($total_errors > 0) + { + $this->_safe_form_data = TRUE; + } + + $this->set_fields(); + + // Did we end up with any errors? + if ($total_errors == 0) + { + return TRUE; + } + + // Generate the error string + foreach ($this->_error_array as $val) + { + $this->error_string .= $this->_error_prefix.$val.$this->_error_suffix."\n"; + } + + return FALSE; + } + + // -------------------------------------------------------------------- + + /** + * Required + * + * @access public + * @param string + * @return bool + */ + function required($str) + { + if ( ! is_array($str)) + { + return (trim($str) == '') ? FALSE : TRUE; + } + else + { + return ( ! empty($str)); + } + } + + // -------------------------------------------------------------------- + + /** + * Match one field to another + * + * @access public + * @param string + * @param field + * @return bool + */ + function matches($str, $field) + { + if ( ! isset($_POST[$field])) + { + return FALSE; + } + + return ($str !== $_POST[$field]) ? FALSE : TRUE; + } + + // -------------------------------------------------------------------- + + /** + * Minimum Length + * + * @access public + * @param string + * @param value + * @return bool + */ + function min_length($str, $val) + { + if (preg_match("/[^0-9]/", $val)) + { + return FALSE; + } + + if (function_exists('mb_strlen')) + { + return (mb_strlen($str) < $val) ? FALSE : TRUE; + } + + return (strlen($str) < $val) ? FALSE : TRUE; + } + + // -------------------------------------------------------------------- + + /** + * Max Length + * + * @access public + * @param string + * @param value + * @return bool + */ + function max_length($str, $val) + { + if (preg_match("/[^0-9]/", $val)) + { + return FALSE; + } + + if (function_exists('mb_strlen')) + { + return (mb_strlen($str) > $val) ? FALSE : TRUE; + } + + return (strlen($str) > $val) ? FALSE : TRUE; + } + + // -------------------------------------------------------------------- + + /** + * Exact Length + * + * @access public + * @param string + * @param value + * @return bool + */ + function exact_length($str, $val) + { + if (preg_match("/[^0-9]/", $val)) + { + return FALSE; + } + + if (function_exists('mb_strlen')) + { + return (mb_strlen($str) != $val) ? FALSE : TRUE; + } + + return (strlen($str) != $val) ? FALSE : TRUE; + } + + // -------------------------------------------------------------------- + + /** + * Valid Email + * + * @access public + * @param string + * @return bool + */ + function valid_email($str) + { + return ( ! preg_match("/^([a-z0-9\+_\-]+)(\.[a-z0-9\+_\-]+)*@([a-z0-9\-]+\.)+[a-z]{2,6}$/ix", $str)) ? FALSE : TRUE; + } + + // -------------------------------------------------------------------- + + /** + * Valid Emails + * + * @access public + * @param string + * @return bool + */ + function valid_emails($str) + { + if (strpos($str, ',') === FALSE) + { + return $this->valid_email(trim($str)); + } + + foreach(explode(',', $str) as $email) + { + if (trim($email) != '' && $this->valid_email(trim($email)) === FALSE) + { + return FALSE; + } + } + + return TRUE; + } + + // -------------------------------------------------------------------- + + /** + * Validate IP Address + * + * @access public + * @param string + * @return string + */ + function valid_ip($ip) + { + return $this->CI->input->valid_ip($ip); + } + + // -------------------------------------------------------------------- + + /** + * Alpha + * + * @access public + * @param string + * @return bool + */ + function alpha($str) + { + return ( ! preg_match("/^([a-z])+$/i", $str)) ? FALSE : TRUE; + } + + // -------------------------------------------------------------------- + + /** + * Alpha-numeric + * + * @access public + * @param string + * @return bool + */ + function alpha_numeric($str) + { + return ( ! preg_match("/^([a-z0-9])+$/i", $str)) ? FALSE : TRUE; + } + + // -------------------------------------------------------------------- + + /** + * Alpha-numeric with underscores and dashes + * + * @access public + * @param string + * @return bool + */ + function alpha_dash($str) + { + return ( ! preg_match("/^([-a-z0-9_-])+$/i", $str)) ? FALSE : TRUE; + } + + // -------------------------------------------------------------------- + + /** + * Numeric + * + * @access public + * @param string + * @return bool + */ + function numeric($str) + { + return (bool)preg_match( '/^[\-+]?[0-9]*\.?[0-9]+$/', $str); + + } + + // -------------------------------------------------------------------- + + /** + * Is Numeric + * + * @access public + * @param string + * @return bool + */ + function is_numeric($str) + { + return ( ! is_numeric($str)) ? FALSE : TRUE; + } + + // -------------------------------------------------------------------- + + /** + * Integer + * + * @access public + * @param string + * @return bool + */ + function integer($str) + { + return (bool)preg_match( '/^[\-+]?[0-9]+$/', $str); + } + + // -------------------------------------------------------------------- + + /** + * Is a Natural number (0,1,2,3, etc.) + * + * @access public + * @param string + * @return bool + */ + function is_natural($str) + { + return (bool)preg_match( '/^[0-9]+$/', $str); + } + + // -------------------------------------------------------------------- + + /** + * Is a Natural number, but not a zero (1,2,3, etc.) + * + * @access public + * @param string + * @return bool + */ + function is_natural_no_zero($str) + { + if ( ! preg_match( '/^[0-9]+$/', $str)) + { + return FALSE; + } + + if ($str == 0) + { + return FALSE; + } + + return TRUE; + } + + // -------------------------------------------------------------------- + + /** + * Valid Base64 + * + * Tests a string for characters outside of the Base64 alphabet + * as defined by RFC 2045 http://www.faqs.org/rfcs/rfc2045 + * + * @access public + * @param string + * @return bool + */ + function valid_base64($str) + { + return (bool) ! preg_match('/[^a-zA-Z0-9\/\+=]/', $str); + } + + // -------------------------------------------------------------------- + + /** + * Set Select + * + * Enables pull-down lists to be set to the value the user + * selected in the event of an error + * + * @access public + * @param string + * @param string + * @return string + */ + function set_select($field = '', $value = '') + { + if ($field == '' OR $value == '' OR ! isset($_POST[$field])) + { + return ''; + } + + if ($_POST[$field] == $value) + { + return ' selected="selected"'; + } + } + + // -------------------------------------------------------------------- + + /** + * Set Radio + * + * Enables radio buttons to be set to the value the user + * selected in the event of an error + * + * @access public + * @param string + * @param string + * @return string + */ + function set_radio($field = '', $value = '') + { + if ($field == '' OR $value == '' OR ! isset($_POST[$field])) + { + return ''; + } + + if ($_POST[$field] == $value) + { + return ' checked="checked"'; + } + } + + // -------------------------------------------------------------------- + + /** + * Set Checkbox + * + * Enables checkboxes to be set to the value the user + * selected in the event of an error + * + * @access public + * @param string + * @param string + * @return string + */ + function set_checkbox($field = '', $value = '') + { + if ($field == '' OR $value == '' OR ! isset($_POST[$field])) + { + return ''; + } + + if ($_POST[$field] == $value) + { + return ' checked="checked"'; + } + } + + // -------------------------------------------------------------------- + + /** + * Prep data for form + * + * This function allows HTML to be safely shown in a form. + * Special characters are converted. + * + * @access public + * @param string + * @return string + */ + function prep_for_form($data = '') + { + if (is_array($data)) + { + foreach ($data as $key => $val) + { + $data[$key] = $this->prep_for_form($val); + } + + return $data; + } + + if ($this->_safe_form_data == FALSE OR $data == '') + { + return $data; + } + + return str_replace(array("'", '"', '<', '>'), array("'", """, '<', '>'), stripslashes($data)); + } + + // -------------------------------------------------------------------- + + /** + * Prep URL + * + * @access public + * @param string + * @return string + */ + function prep_url($str = '') + { + if ($str == 'http://' OR $str == '') + { + $_POST[$this->_current_field] = ''; + return; + } + + if (substr($str, 0, 7) != 'http://' && substr($str, 0, 8) != 'https://') + { + $str = 'http://'.$str; + } + + $_POST[$this->_current_field] = $str; + } + + // -------------------------------------------------------------------- + + /** + * Strip Image Tags + * + * @access public + * @param string + * @return string + */ + function strip_image_tags($str) + { + $_POST[$this->_current_field] = $this->CI->input->strip_image_tags($str); + } + + // -------------------------------------------------------------------- + + /** + * XSS Clean + * + * @access public + * @param string + * @return string + */ + function xss_clean($str) + { + $_POST[$this->_current_field] = $this->CI->input->xss_clean($str); + } + + // -------------------------------------------------------------------- + + /** + * Convert PHP tags to entities + * + * @access public + * @param string + * @return string + */ + function encode_php_tags($str) + { + $_POST[$this->_current_field] = str_replace(array(''), array('<?php', '<?PHP', '<?', '?>'), $str); + } + +} +// END Validation Class + +/* End of file Validation.php */ /* Location: ./system/libraries/Validation.php */ \ No newline at end of file diff --git a/system/libraries/Xmlrpc.php b/system/libraries/Xmlrpc.php index c9e79728b..b077d3d1f 100644 --- a/system/libraries/Xmlrpc.php +++ b/system/libraries/Xmlrpc.php @@ -1,1421 +1,1421 @@ -xmlrpcName = $this->xmlrpcName; - $this->xmlrpc_backslash = chr(92).chr(92); - - // Types for info sent back and forth - $this->xmlrpcTypes = array( - $this->xmlrpcI4 => '1', - $this->xmlrpcInt => '1', - $this->xmlrpcBoolean => '1', - $this->xmlrpcString => '1', - $this->xmlrpcDouble => '1', - $this->xmlrpcDateTime => '1', - $this->xmlrpcBase64 => '1', - $this->xmlrpcArray => '2', - $this->xmlrpcStruct => '3' - ); - - // Array of Valid Parents for Various XML-RPC elements - $this->valid_parents = array('BOOLEAN' => array('VALUE'), - 'I4' => array('VALUE'), - 'INT' => array('VALUE'), - 'STRING' => array('VALUE'), - 'DOUBLE' => array('VALUE'), - 'DATETIME.ISO8601' => array('VALUE'), - 'BASE64' => array('VALUE'), - 'ARRAY' => array('VALUE'), - 'STRUCT' => array('VALUE'), - 'PARAM' => array('PARAMS'), - 'METHODNAME' => array('METHODCALL'), - 'PARAMS' => array('METHODCALL', 'METHODRESPONSE'), - 'MEMBER' => array('STRUCT'), - 'NAME' => array('MEMBER'), - 'DATA' => array('ARRAY'), - 'FAULT' => array('METHODRESPONSE'), - 'VALUE' => array('MEMBER', 'DATA', 'PARAM', 'FAULT') - ); - - - // XML-RPC Responses - $this->xmlrpcerr['unknown_method'] = '1'; - $this->xmlrpcstr['unknown_method'] = 'This is not a known method for this XML-RPC Server'; - $this->xmlrpcerr['invalid_return'] = '2'; - $this->xmlrpcstr['invalid_return'] = 'The XML data receieved was either invalid or not in the correct form for XML-RPC. Turn on debugging to examine the XML data further.'; - $this->xmlrpcerr['incorrect_params'] = '3'; - $this->xmlrpcstr['incorrect_params'] = 'Incorrect parameters were passed to method'; - $this->xmlrpcerr['introspect_unknown'] = '4'; - $this->xmlrpcstr['introspect_unknown'] = "Cannot inspect signature for request: method unknown"; - $this->xmlrpcerr['http_error'] = '5'; - $this->xmlrpcstr['http_error'] = "Did not receive a '200 OK' response from remote server."; - $this->xmlrpcerr['no_data'] = '6'; - $this->xmlrpcstr['no_data'] ='No data received from server.'; - - $this->initialize($config); - - log_message('debug', "XML-RPC Class Initialized"); - } - - - //------------------------------------- - // Initialize Prefs - //------------------------------------- - - function initialize($config = array()) - { - if (sizeof($config) > 0) - { - foreach ($config as $key => $val) - { - if (isset($this->$key)) - { - $this->$key = $val; - } - } - } - } - // END - - //------------------------------------- - // Take URL and parse it - //------------------------------------- - - function server($url, $port=80) - { - if (substr($url, 0, 4) != "http") - { - $url = "http://".$url; - } - - $parts = parse_url($url); - - $path = ( ! isset($parts['path'])) ? '/' : $parts['path']; - - if (isset($parts['query']) && $parts['query'] != '') - { - $path .= '?'.$parts['query']; - } - - $this->client = new XML_RPC_Client($path, $parts['host'], $port); - } - // END - - //------------------------------------- - // Set Timeout - //------------------------------------- - - function timeout($seconds=5) - { - if ( ! is_null($this->client) && is_int($seconds)) - { - $this->client->timeout = $seconds; - } - } - // END - - //------------------------------------- - // Set Methods - //------------------------------------- - - function method($function) - { - $this->method = $function; - } - // END - - //------------------------------------- - // Take Array of Data and Create Objects - //------------------------------------- - - function request($incoming) - { - if ( ! is_array($incoming)) - { - // Send Error - } - - $this->data = array(); - - foreach($incoming as $key => $value) - { - $this->data[$key] = $this->values_parsing($value); - } - } - // END - - - //------------------------------------- - // Set Debug - //------------------------------------- - - function set_debug($flag = TRUE) - { - $this->debug = ($flag == TRUE) ? TRUE : FALSE; - } - - //------------------------------------- - // Values Parsing - //------------------------------------- - - function values_parsing($value, $return = FALSE) - { - if (is_array($value) && isset($value['0'])) - { - if ( ! isset($value['1']) OR ! isset($this->xmlrpcTypes[strtolower($value['1'])])) - { - if (is_array($value[0])) - { - $temp = new XML_RPC_Values($value['0'], 'array'); - } - else - { - $temp = new XML_RPC_Values($value['0'], 'string'); - } - } - elseif(is_array($value['0']) && ($value['1'] == 'struct' OR $value['1'] == 'array')) - { - while (list($k) = each($value['0'])) - { - $value['0'][$k] = $this->values_parsing($value['0'][$k], TRUE); - } - - $temp = new XML_RPC_Values($value['0'], $value['1']); - } - else - { - $temp = new XML_RPC_Values($value['0'], $value['1']); - } - } - else - { - $temp = new XML_RPC_Values($value, 'string'); - } - - return $temp; - } - // END - - - //------------------------------------- - // Sends XML-RPC Request - //------------------------------------- - - function send_request() - { - $this->message = new XML_RPC_Message($this->method,$this->data); - $this->message->debug = $this->debug; - - if ( ! $this->result = $this->client->send($this->message)) - { - $this->error = $this->result->errstr; - return FALSE; - } - elseif( ! is_object($this->result->val)) - { - $this->error = $this->result->errstr; - return FALSE; - } - - $this->response = $this->result->decode(); - - return TRUE; - } - // END - - //------------------------------------- - // Returns Error - //------------------------------------- - - function display_error() - { - return $this->error; - } - // END - - //------------------------------------- - // Returns Remote Server Response - //------------------------------------- - - function display_response() - { - return $this->response; - } - // END - - //------------------------------------- - // Sends an Error Message for Server Request - //------------------------------------- - - function send_error_message($number, $message) - { - return new XML_RPC_Response('0',$number, $message); - } - // END - - - //------------------------------------- - // Send Response for Server Request - //------------------------------------- - - function send_response($response) - { - // $response should be array of values, which will be parsed - // based on their data and type into a valid group of XML-RPC values - - $response = $this->values_parsing($response); - - return new XML_RPC_Response($response); - } - // END - -} // END XML_RPC Class - - - -/** - * XML-RPC Client class - * - * @category XML-RPC - * @author ExpressionEngine Dev Team - * @link http://codeigniter.com/user_guide/libraries/xmlrpc.html - */ -class XML_RPC_Client extends CI_Xmlrpc -{ - var $path = ''; - var $server = ''; - var $port = 80; - var $errno = ''; - var $errstring = ''; - var $timeout = 5; - var $no_multicall = false; - - function XML_RPC_Client($path, $server, $port=80) - { - parent::CI_Xmlrpc(); - - $this->port = $port; - $this->server = $server; - $this->path = $path; - } - - function send($msg) - { - if (is_array($msg)) - { - // Multi-call disabled - $r = new XML_RPC_Response(0, $this->xmlrpcerr['multicall_recursion'],$this->xmlrpcstr['multicall_recursion']); - return $r; - } - - return $this->sendPayload($msg); - } - - function sendPayload($msg) - { - $fp = @fsockopen($this->server, $this->port,$this->errno, $this->errstr, $this->timeout); - - if ( ! is_resource($fp)) - { - error_log($this->xmlrpcstr['http_error']); - $r = new XML_RPC_Response(0, $this->xmlrpcerr['http_error'],$this->xmlrpcstr['http_error']); - return $r; - } - - if(empty($msg->payload)) - { - // $msg = XML_RPC_Messages - $msg->createPayload(); - } - - $r = "\r\n"; - $op = "POST {$this->path} HTTP/1.0$r"; - $op .= "Host: {$this->server}$r"; - $op .= "Content-Type: text/xml$r"; - $op .= "User-Agent: {$this->xmlrpcName}$r"; - $op .= "Content-Length: ".strlen($msg->payload). "$r$r"; - $op .= $msg->payload; - - - if ( ! fputs($fp, $op, strlen($op))) - { - error_log($this->xmlrpcstr['http_error']); - $r = new XML_RPC_Response(0, $this->xmlrpcerr['http_error'], $this->xmlrpcstr['http_error']); - return $r; - } - $resp = $msg->parseResponse($fp); - fclose($fp); - return $resp; - } - -} // end class XML_RPC_Client - - -/** - * XML-RPC Response class - * - * @category XML-RPC - * @author ExpressionEngine Dev Team - * @link http://codeigniter.com/user_guide/libraries/xmlrpc.html - */ -class XML_RPC_Response -{ - var $val = 0; - var $errno = 0; - var $errstr = ''; - var $headers = array(); - - function XML_RPC_Response($val, $code = 0, $fstr = '') - { - if ($code != 0) - { - // error - $this->errno = $code; - $this->errstr = htmlentities($fstr); - } - else if ( ! is_object($val)) - { - // programmer error, not an object - error_log("Invalid type '" . gettype($val) . "' (value: $val) passed to XML_RPC_Response. Defaulting to empty value."); - $this->val = new XML_RPC_Values(); - } - else - { - $this->val = $val; - } - } - - function faultCode() - { - return $this->errno; - } - - function faultString() - { - return $this->errstr; - } - - function value() - { - return $this->val; - } - - function prepare_response() - { - $result = "\n"; - if ($this->errno) - { - $result .= ' - - - - faultCode - ' . $this->errno . ' - - - faultString - ' . $this->errstr . ' - - - -'; - } - else - { - $result .= "\n\n" . - $this->val->serialize_class() . - "\n"; - } - $result .= "\n"; - return $result; - } - - function decode($array=FALSE) - { - $CI =& get_instance(); - - if ($array !== FALSE && is_array($array)) - { - while (list($key) = each($array)) - { - if (is_array($array[$key])) - { - $array[$key] = $this->decode($array[$key]); - } - else - { - $array[$key] = $CI->input->xss_clean($array[$key]); - } - } - - $result = $array; - } - else - { - $result = $this->xmlrpc_decoder($this->val); - - if (is_array($result)) - { - $result = $this->decode($result); - } - else - { - $result = $CI->input->xss_clean($result); - } - } - - return $result; - } - - - - //------------------------------------- - // XML-RPC Object to PHP Types - //------------------------------------- - - function xmlrpc_decoder($xmlrpc_val) - { - $kind = $xmlrpc_val->kindOf(); - - if($kind == 'scalar') - { - return $xmlrpc_val->scalarval(); - } - elseif($kind == 'array') - { - reset($xmlrpc_val->me); - list($a,$b) = each($xmlrpc_val->me); - $size = sizeof($b); - - $arr = array(); - - for($i = 0; $i < $size; $i++) - { - $arr[] = $this->xmlrpc_decoder($xmlrpc_val->me['array'][$i]); - } - return $arr; - } - elseif($kind == 'struct') - { - reset($xmlrpc_val->me['struct']); - $arr = array(); - - while(list($key,$value) = each($xmlrpc_val->me['struct'])) - { - $arr[$key] = $this->xmlrpc_decoder($value); - } - return $arr; - } - } - - - //------------------------------------- - // ISO-8601 time to server or UTC time - //------------------------------------- - - function iso8601_decode($time, $utc=0) - { - // return a timet in the localtime, or UTC - $t = 0; - if (preg_match('/([0-9]{4})([0-9]{2})([0-9]{2})T([0-9]{2}):([0-9]{2}):([0-9]{2})/', $time, $regs)) - { - if ($utc == 1) - $t = gmmktime($regs[4], $regs[5], $regs[6], $regs[2], $regs[3], $regs[1]); - else - $t = mktime($regs[4], $regs[5], $regs[6], $regs[2], $regs[3], $regs[1]); - } - return $t; - } - -} // End Response Class - - - -/** - * XML-RPC Message class - * - * @category XML-RPC - * @author ExpressionEngine Dev Team - * @link http://codeigniter.com/user_guide/libraries/xmlrpc.html - */ -class XML_RPC_Message extends CI_Xmlrpc -{ - var $payload; - var $method_name; - var $params = array(); - var $xh = array(); - - function XML_RPC_Message($method, $pars=0) - { - parent::CI_Xmlrpc(); - - $this->method_name = $method; - if (is_array($pars) && sizeof($pars) > 0) - { - for($i=0; $iparams[] = $pars[$i]; - } - } - } - - //------------------------------------- - // Create Payload to Send - //------------------------------------- - - function createPayload() - { - $this->payload = "\r\n\r\n"; - $this->payload .= '' . $this->method_name . "\r\n"; - $this->payload .= "\r\n"; - - for($i=0; $iparams); $i++) - { - // $p = XML_RPC_Values - $p = $this->params[$i]; - $this->payload .= "\r\n".$p->serialize_class()."\r\n"; - } - - $this->payload .= "\r\n\r\n"; - } - - //------------------------------------- - // Parse External XML-RPC Server's Response - //------------------------------------- - - function parseResponse($fp) - { - $data = ''; - - while($datum = fread($fp, 4096)) - { - $data .= $datum; - } - - //------------------------------------- - // DISPLAY HTTP CONTENT for DEBUGGING - //------------------------------------- - - if ($this->debug === TRUE) - { - echo "
    ";
    -			echo "---DATA---\n" . htmlspecialchars($data) . "\n---END DATA---\n\n";
    -			echo "
    "; - } - - //------------------------------------- - // Check for data - //------------------------------------- - - if($data == "") - { - error_log($this->xmlrpcstr['no_data']); - $r = new XML_RPC_Response(0, $this->xmlrpcerr['no_data'], $this->xmlrpcstr['no_data']); - return $r; - } - - - //------------------------------------- - // Check for HTTP 200 Response - //------------------------------------- - - if (strncmp($data, 'HTTP', 4) == 0 && ! preg_match('/^HTTP\/[0-9\.]+ 200 /', $data)) - { - $errstr= substr($data, 0, strpos($data, "\n")-1); - $r = new XML_RPC_Response(0, $this->xmlrpcerr['http_error'], $this->xmlrpcstr['http_error']. ' (' . $errstr . ')'); - return $r; - } - - //------------------------------------- - // Create and Set Up XML Parser - //------------------------------------- - - $parser = xml_parser_create($this->xmlrpc_defencoding); - - $this->xh[$parser] = array(); - $this->xh[$parser]['isf'] = 0; - $this->xh[$parser]['ac'] = ''; - $this->xh[$parser]['headers'] = array(); - $this->xh[$parser]['stack'] = array(); - $this->xh[$parser]['valuestack'] = array(); - $this->xh[$parser]['isf_reason'] = 0; - - xml_set_object($parser, $this); - 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'); - - - //------------------------------------- - // GET HEADERS - //------------------------------------- - - $lines = explode("\r\n", $data); - while (($line = array_shift($lines))) - { - if (strlen($line) < 1) - { - break; - } - $this->xh[$parser]['headers'][] = $line; - } - $data = implode("\r\n", $lines); - - - //------------------------------------- - // PARSE XML DATA - //------------------------------------- - - if ( ! xml_parse($parser, $data, sizeof($data))) - { - $errstr = sprintf('XML error: %s at line %d', - xml_error_string(xml_get_error_code($parser)), - xml_get_current_line_number($parser)); - //error_log($errstr); - $r = new XML_RPC_Response(0, $this->xmlrpcerr['invalid_return'], $this->xmlrpcstr['invalid_return']); - xml_parser_free($parser); - return $r; - } - xml_parser_free($parser); - - // --------------------------------------- - // Got Ourselves Some Badness, It Seems - // --------------------------------------- - - if ($this->xh[$parser]['isf'] > 1) - { - if ($this->debug === TRUE) - { - echo "---Invalid Return---\n"; - echo $this->xh[$parser]['isf_reason']; - echo "---Invalid Return---\n\n"; - } - - $r = new XML_RPC_Response(0, $this->xmlrpcerr['invalid_return'],$this->xmlrpcstr['invalid_return'].' '.$this->xh[$parser]['isf_reason']); - return $r; - } - elseif ( ! is_object($this->xh[$parser]['value'])) - { - $r = new XML_RPC_Response(0, $this->xmlrpcerr['invalid_return'],$this->xmlrpcstr['invalid_return'].' '.$this->xh[$parser]['isf_reason']); - return $r; - } - - //------------------------------------- - // DISPLAY XML CONTENT for DEBUGGING - //------------------------------------- - - if ($this->debug === TRUE) - { - echo "
    ";
    -			
    -			if (count($this->xh[$parser]['headers'] > 0))
    -			{
    -				echo "---HEADERS---\n";
    -				foreach ($this->xh[$parser]['headers'] as $header)
    -				{
    -					echo "$header\n";
    -				}
    -				echo "---END HEADERS---\n\n";
    -			}
    -			
    -			echo "---DATA---\n" . htmlspecialchars($data) . "\n---END DATA---\n\n";
    -			
    -			echo "---PARSED---\n" ;
    -			var_dump($this->xh[$parser]['value']);
    -			echo "\n---END PARSED---
    "; - } - - //------------------------------------- - // SEND RESPONSE - //------------------------------------- - - $v = $this->xh[$parser]['value']; - - if ($this->xh[$parser]['isf']) - { - $errno_v = $v->me['struct']['faultCode']; - $errstr_v = $v->me['struct']['faultString']; - $errno = $errno_v->scalarval(); - - if ($errno == 0) - { - // FAULT returned, errno needs to reflect that - $errno = -1; - } - - $r = new XML_RPC_Response($v, $errno, $errstr_v->scalarval()); - } - else - { - $r = new XML_RPC_Response($v); - } - - $r->headers = $this->xh[$parser]['headers']; - return $r; - } - - // ------------------------------------ - // Begin Return Message Parsing section - // ------------------------------------ - - // quick explanation of components: - // ac - used to accumulate values - // isf - used to indicate a fault - // lv - used to indicate "looking for a value": implements - // the logic to allow values with no types to be strings - // params - used to store parameters in method calls - // method - used to store method name - // stack - array with parent tree of the xml element, - // used to validate the nesting of elements - - //------------------------------------- - // Start Element Handler - //------------------------------------- - - function open_tag($the_parser, $name, $attrs) - { - // If invalid nesting, then return - if ($this->xh[$the_parser]['isf'] > 1) return; - - // Evaluate and check for correct nesting of XML elements - - if (count($this->xh[$the_parser]['stack']) == 0) - { - if ($name != 'METHODRESPONSE' && $name != 'METHODCALL') - { - $this->xh[$the_parser]['isf'] = 2; - $this->xh[$the_parser]['isf_reason'] = 'Top level XML-RPC element is missing'; - return; - } - } - else - { - // not top level element: see if parent is OK - if ( ! in_array($this->xh[$the_parser]['stack'][0], $this->valid_parents[$name], TRUE)) - { - $this->xh[$the_parser]['isf'] = 2; - $this->xh[$the_parser]['isf_reason'] = "XML-RPC element $name cannot be child of ".$this->xh[$the_parser]['stack'][0]; - return; - } - } - - switch($name) - { - case 'STRUCT': - case 'ARRAY': - // Creates array for child elements - - $cur_val = array('value' => array(), - 'type' => $name); - - array_unshift($this->xh[$the_parser]['valuestack'], $cur_val); - break; - case 'METHODNAME': - case 'NAME': - $this->xh[$the_parser]['ac'] = ''; - break; - case 'FAULT': - $this->xh[$the_parser]['isf'] = 1; - break; - case 'PARAM': - $this->xh[$the_parser]['value'] = null; - break; - case 'VALUE': - $this->xh[$the_parser]['vt'] = 'value'; - $this->xh[$the_parser]['ac'] = ''; - $this->xh[$the_parser]['lv'] = 1; - break; - case 'I4': - case 'INT': - case 'STRING': - case 'BOOLEAN': - case 'DOUBLE': - case 'DATETIME.ISO8601': - case 'BASE64': - if ($this->xh[$the_parser]['vt'] != 'value') - { - //two data elements inside a value: an error occurred! - $this->xh[$the_parser]['isf'] = 2; - $this->xh[$the_parser]['isf_reason'] = "'Twas a $name element following a ".$this->xh[$the_parser]['vt']." element inside a single value"; - return; - } - - $this->xh[$the_parser]['ac'] = ''; - break; - case 'MEMBER': - // Set name of to nothing to prevent errors later if no is found - $this->xh[$the_parser]['valuestack'][0]['name'] = ''; - - // Set NULL value to check to see if value passed for this param/member - $this->xh[$the_parser]['value'] = null; - break; - case 'DATA': - case 'METHODCALL': - case 'METHODRESPONSE': - case 'PARAMS': - // valid elements that add little to processing - break; - default: - /// An Invalid Element is Found, so we have trouble - $this->xh[$the_parser]['isf'] = 2; - $this->xh[$the_parser]['isf_reason'] = "Invalid XML-RPC element found: $name"; - break; - } - - // Add current element name to stack, to allow validation of nesting - array_unshift($this->xh[$the_parser]['stack'], $name); - - if ($name != 'VALUE') $this->xh[$the_parser]['lv'] = 0; - } - // END - - - //------------------------------------- - // End Element Handler - //------------------------------------- - - function closing_tag($the_parser, $name) - { - if ($this->xh[$the_parser]['isf'] > 1) return; - - // Remove current element from stack and set variable - // NOTE: If the XML validates, then we do not have to worry about - // the opening and closing of elements. Nesting is checked on the opening - // tag so we be safe there as well. - - $curr_elem = array_shift($this->xh[$the_parser]['stack']); - - switch($name) - { - case 'STRUCT': - case 'ARRAY': - $cur_val = array_shift($this->xh[$the_parser]['valuestack']); - $this->xh[$the_parser]['value'] = ( ! isset($cur_val['values'])) ? array() : $cur_val['values']; - $this->xh[$the_parser]['vt'] = strtolower($name); - break; - case 'NAME': - $this->xh[$the_parser]['valuestack'][0]['name'] = $this->xh[$the_parser]['ac']; - break; - case 'BOOLEAN': - case 'I4': - case 'INT': - case 'STRING': - case 'DOUBLE': - case 'DATETIME.ISO8601': - case 'BASE64': - $this->xh[$the_parser]['vt'] = strtolower($name); - - if ($name == 'STRING') - { - $this->xh[$the_parser]['value'] = $this->xh[$the_parser]['ac']; - } - elseif ($name=='DATETIME.ISO8601') - { - $this->xh[$the_parser]['vt'] = $this->xmlrpcDateTime; - $this->xh[$the_parser]['value'] = $this->xh[$the_parser]['ac']; - } - elseif ($name=='BASE64') - { - $this->xh[$the_parser]['value'] = base64_decode($this->xh[$the_parser]['ac']); - } - elseif ($name=='BOOLEAN') - { - // Translated BOOLEAN values to TRUE AND FALSE - if ($this->xh[$the_parser]['ac'] == '1') - { - $this->xh[$the_parser]['value'] = TRUE; - } - else - { - $this->xh[$the_parser]['value'] = FALSE; - } - } - elseif ($name=='DOUBLE') - { - // we have a DOUBLE - // we must check that only 0123456789-. are characters here - if ( ! preg_match('/^[+-]?[eE0-9\t \.]+$/', $this->xh[$the_parser]['ac'])) - { - $this->xh[$the_parser]['value'] = 'ERROR_NON_NUMERIC_FOUND'; - } - else - { - $this->xh[$the_parser]['value'] = (double)$this->xh[$the_parser]['ac']; - } - } - else - { - // we have an I4/INT - // we must check that only 0123456789- are characters here - if ( ! preg_match('/^[+-]?[0-9\t ]+$/', $this->xh[$the_parser]['ac'])) - { - $this->xh[$the_parser]['value'] = 'ERROR_NON_NUMERIC_FOUND'; - } - else - { - $this->xh[$the_parser]['value'] = (int)$this->xh[$the_parser]['ac']; - } - } - $this->xh[$the_parser]['ac'] = ''; - $this->xh[$the_parser]['lv'] = 3; // indicate we've found a value - break; - case 'VALUE': - // This if() detects if no scalar was inside - if ($this->xh[$the_parser]['vt']=='value') - { - $this->xh[$the_parser]['value'] = $this->xh[$the_parser]['ac']; - $this->xh[$the_parser]['vt'] = $this->xmlrpcString; - } - - // build the XML-RPC value out of the data received, and substitute it - $temp = new XML_RPC_Values($this->xh[$the_parser]['value'], $this->xh[$the_parser]['vt']); - - if (count($this->xh[$the_parser]['valuestack']) && $this->xh[$the_parser]['valuestack'][0]['type'] == 'ARRAY') - { - // Array - $this->xh[$the_parser]['valuestack'][0]['values'][] = $temp; - } - else - { - // Struct - $this->xh[$the_parser]['value'] = $temp; - } - break; - case 'MEMBER': - $this->xh[$the_parser]['ac']=''; - - // If value add to array in the stack for the last element built - if ($this->xh[$the_parser]['value']) - { - $this->xh[$the_parser]['valuestack'][0]['values'][$this->xh[$the_parser]['valuestack'][0]['name']] = $this->xh[$the_parser]['value']; - } - break; - case 'DATA': - $this->xh[$the_parser]['ac']=''; - break; - case 'PARAM': - if ($this->xh[$the_parser]['value']) - { - $this->xh[$the_parser]['params'][] = $this->xh[$the_parser]['value']; - } - break; - case 'METHODNAME': - $this->xh[$the_parser]['method'] = ltrim($this->xh[$the_parser]['ac']); - break; - case 'PARAMS': - case 'FAULT': - case 'METHODCALL': - case 'METHORESPONSE': - // We're all good kids with nuthin' to do - break; - default: - // End of an Invalid Element. Taken care of during the opening tag though - break; - } - } - - //------------------------------------- - // Parses Character Data - //------------------------------------- - - function character_data($the_parser, $data) - { - if ($this->xh[$the_parser]['isf'] > 1) return; // XML Fault found already - - // If a value has not been found - if ($this->xh[$the_parser]['lv'] != 3) - { - if ($this->xh[$the_parser]['lv'] == 1) - { - $this->xh[$the_parser]['lv'] = 2; // Found a value - } - - if( ! @isset($this->xh[$the_parser]['ac'])) - { - $this->xh[$the_parser]['ac'] = ''; - } - - $this->xh[$the_parser]['ac'] .= $data; - } - } - - - function addParam($par) { $this->params[]=$par; } - - function output_parameters($array=FALSE) - { - $CI =& get_instance(); - - if ($array !== FALSE && is_array($array)) - { - while (list($key) = each($array)) - { - if (is_array($array[$key])) - { - $array[$key] = $this->output_parameters($array[$key]); - } - else - { - $array[$key] = $CI->input->xss_clean($array[$key]); - } - } - - $parameters = $array; - } - else - { - $parameters = array(); - - for ($i = 0; $i < sizeof($this->params); $i++) - { - $a_param = $this->decode_message($this->params[$i]); - - if (is_array($a_param)) - { - $parameters[] = $this->output_parameters($a_param); - } - else - { - $parameters[] = $CI->input->xss_clean($a_param); - } - } - } - - return $parameters; - } - - - function decode_message($param) - { - $kind = $param->kindOf(); - - if($kind == 'scalar') - { - return $param->scalarval(); - } - elseif($kind == 'array') - { - reset($param->me); - list($a,$b) = each($param->me); - - $arr = array(); - - for($i = 0; $i < sizeof($b); $i++) - { - $arr[] = $this->decode_message($param->me['array'][$i]); - } - - return $arr; - } - elseif($kind == 'struct') - { - reset($param->me['struct']); - - $arr = array(); - - while(list($key,$value) = each($param->me['struct'])) - { - $arr[$key] = $this->decode_message($value); - } - - return $arr; - } - } - -} // End XML_RPC_Messages class - - - -/** - * XML-RPC Values class - * - * @category XML-RPC - * @author ExpressionEngine Dev Team - * @link http://codeigniter.com/user_guide/libraries/xmlrpc.html - */ -class XML_RPC_Values extends CI_Xmlrpc -{ - var $me = array(); - var $mytype = 0; - - function XML_RPC_Values($val=-1, $type='') - { - parent::CI_Xmlrpc(); - - if ($val != -1 OR $type != '') - { - $type = $type == '' ? 'string' : $type; - - if ($this->xmlrpcTypes[$type] == 1) - { - $this->addScalar($val,$type); - } - elseif ($this->xmlrpcTypes[$type] == 2) - { - $this->addArray($val); - } - elseif ($this->xmlrpcTypes[$type] == 3) - { - $this->addStruct($val); - } - } - } - - function addScalar($val, $type='string') - { - $typeof = $this->xmlrpcTypes[$type]; - - if ($this->mytype==1) - { - echo 'XML_RPC_Values: scalar can have only one value
    '; - return 0; - } - - if ($typeof != 1) - { - echo 'XML_RPC_Values: not a scalar type (${typeof})
    '; - return 0; - } - - if ($type == $this->xmlrpcBoolean) - { - if (strcasecmp($val,'true')==0 OR $val==1 OR ($val==true && strcasecmp($val,'false'))) - { - $val = 1; - } - else - { - $val=0; - } - } - - if ($this->mytype == 2) - { - // adding to an array here - $ar = $this->me['array']; - $ar[] = new XML_RPC_Values($val, $type); - $this->me['array'] = $ar; - } - else - { - // a scalar, so set the value and remember we're scalar - $this->me[$type] = $val; - $this->mytype = $typeof; - } - return 1; - } - - function addArray($vals) - { - if ($this->mytype != 0) - { - echo 'XML_RPC_Values: already initialized as a [' . $this->kindOf() . ']
    '; - return 0; - } - - $this->mytype = $this->xmlrpcTypes['array']; - $this->me['array'] = $vals; - return 1; - } - - function addStruct($vals) - { - if ($this->mytype != 0) - { - echo 'XML_RPC_Values: already initialized as a [' . $this->kindOf() . ']
    '; - return 0; - } - $this->mytype = $this->xmlrpcTypes['struct']; - $this->me['struct'] = $vals; - return 1; - } - - function kindOf() - { - switch($this->mytype) - { - case 3: - return 'struct'; - break; - case 2: - return 'array'; - break; - case 1: - return 'scalar'; - break; - default: - return 'undef'; - } - } - - function serializedata($typ, $val) - { - $rs = ''; - - switch($this->xmlrpcTypes[$typ]) - { - case 3: - // struct - $rs .= "\n"; - reset($val); - while(list($key2, $val2) = each($val)) - { - $rs .= "\n{$key2}\n"; - $rs .= $this->serializeval($val2); - $rs .= "\n"; - } - $rs .= ''; - break; - case 2: - // array - $rs .= "\n\n"; - for($i=0; $i < sizeof($val); $i++) - { - $rs .= $this->serializeval($val[$i]); - } - $rs.="\n\n"; - break; - case 1: - // others - switch ($typ) - { - case $this->xmlrpcBase64: - $rs .= "<{$typ}>" . base64_encode($val) . "\n"; - break; - case $this->xmlrpcBoolean: - $rs .= "<{$typ}>" . ($val ? '1' : '0') . "\n"; - break; - case $this->xmlrpcString: - $rs .= "<{$typ}>" . htmlspecialchars($val). "\n"; - break; - default: - $rs .= "<{$typ}>{$val}\n"; - break; - } - default: - break; - } - return $rs; - } - - function serialize_class() - { - return $this->serializeval($this); - } - - function serializeval($o) - { - $ar = $o->me; - reset($ar); - - list($typ, $val) = each($ar); - $rs = "\n".$this->serializedata($typ, $val)."\n"; - return $rs; - } - - function scalarval() - { - reset($this->me); - list($a,$b) = each($this->me); - return $b; - } - - - //------------------------------------- - // Encode time in ISO-8601 form. - //------------------------------------- - - // Useful for sending time in XML-RPC - - function iso8601_encode($time, $utc=0) - { - if ($utc == 1) - { - $t = strftime("%Y%m%dT%H:%M:%S", $time); - } - else - { - if (function_exists('gmstrftime')) - $t = gmstrftime("%Y%m%dT%H:%M:%S", $time); - else - $t = strftime("%Y%m%dT%H:%M:%S", $time - date('Z')); - } - return $t; - } - -} -// END XML_RPC_Values Class - -/* End of file Xmlrpc.php */ +xmlrpcName = $this->xmlrpcName; + $this->xmlrpc_backslash = chr(92).chr(92); + + // Types for info sent back and forth + $this->xmlrpcTypes = array( + $this->xmlrpcI4 => '1', + $this->xmlrpcInt => '1', + $this->xmlrpcBoolean => '1', + $this->xmlrpcString => '1', + $this->xmlrpcDouble => '1', + $this->xmlrpcDateTime => '1', + $this->xmlrpcBase64 => '1', + $this->xmlrpcArray => '2', + $this->xmlrpcStruct => '3' + ); + + // Array of Valid Parents for Various XML-RPC elements + $this->valid_parents = array('BOOLEAN' => array('VALUE'), + 'I4' => array('VALUE'), + 'INT' => array('VALUE'), + 'STRING' => array('VALUE'), + 'DOUBLE' => array('VALUE'), + 'DATETIME.ISO8601' => array('VALUE'), + 'BASE64' => array('VALUE'), + 'ARRAY' => array('VALUE'), + 'STRUCT' => array('VALUE'), + 'PARAM' => array('PARAMS'), + 'METHODNAME' => array('METHODCALL'), + 'PARAMS' => array('METHODCALL', 'METHODRESPONSE'), + 'MEMBER' => array('STRUCT'), + 'NAME' => array('MEMBER'), + 'DATA' => array('ARRAY'), + 'FAULT' => array('METHODRESPONSE'), + 'VALUE' => array('MEMBER', 'DATA', 'PARAM', 'FAULT') + ); + + + // XML-RPC Responses + $this->xmlrpcerr['unknown_method'] = '1'; + $this->xmlrpcstr['unknown_method'] = 'This is not a known method for this XML-RPC Server'; + $this->xmlrpcerr['invalid_return'] = '2'; + $this->xmlrpcstr['invalid_return'] = 'The XML data receieved was either invalid or not in the correct form for XML-RPC. Turn on debugging to examine the XML data further.'; + $this->xmlrpcerr['incorrect_params'] = '3'; + $this->xmlrpcstr['incorrect_params'] = 'Incorrect parameters were passed to method'; + $this->xmlrpcerr['introspect_unknown'] = '4'; + $this->xmlrpcstr['introspect_unknown'] = "Cannot inspect signature for request: method unknown"; + $this->xmlrpcerr['http_error'] = '5'; + $this->xmlrpcstr['http_error'] = "Did not receive a '200 OK' response from remote server."; + $this->xmlrpcerr['no_data'] = '6'; + $this->xmlrpcstr['no_data'] ='No data received from server.'; + + $this->initialize($config); + + log_message('debug', "XML-RPC Class Initialized"); + } + + + //------------------------------------- + // Initialize Prefs + //------------------------------------- + + function initialize($config = array()) + { + if (sizeof($config) > 0) + { + foreach ($config as $key => $val) + { + if (isset($this->$key)) + { + $this->$key = $val; + } + } + } + } + // END + + //------------------------------------- + // Take URL and parse it + //------------------------------------- + + function server($url, $port=80) + { + if (substr($url, 0, 4) != "http") + { + $url = "http://".$url; + } + + $parts = parse_url($url); + + $path = ( ! isset($parts['path'])) ? '/' : $parts['path']; + + if (isset($parts['query']) && $parts['query'] != '') + { + $path .= '?'.$parts['query']; + } + + $this->client = new XML_RPC_Client($path, $parts['host'], $port); + } + // END + + //------------------------------------- + // Set Timeout + //------------------------------------- + + function timeout($seconds=5) + { + if ( ! is_null($this->client) && is_int($seconds)) + { + $this->client->timeout = $seconds; + } + } + // END + + //------------------------------------- + // Set Methods + //------------------------------------- + + function method($function) + { + $this->method = $function; + } + // END + + //------------------------------------- + // Take Array of Data and Create Objects + //------------------------------------- + + function request($incoming) + { + if ( ! is_array($incoming)) + { + // Send Error + } + + $this->data = array(); + + foreach($incoming as $key => $value) + { + $this->data[$key] = $this->values_parsing($value); + } + } + // END + + + //------------------------------------- + // Set Debug + //------------------------------------- + + function set_debug($flag = TRUE) + { + $this->debug = ($flag == TRUE) ? TRUE : FALSE; + } + + //------------------------------------- + // Values Parsing + //------------------------------------- + + function values_parsing($value, $return = FALSE) + { + if (is_array($value) && isset($value['0'])) + { + if ( ! isset($value['1']) OR ! isset($this->xmlrpcTypes[strtolower($value['1'])])) + { + if (is_array($value[0])) + { + $temp = new XML_RPC_Values($value['0'], 'array'); + } + else + { + $temp = new XML_RPC_Values($value['0'], 'string'); + } + } + elseif(is_array($value['0']) && ($value['1'] == 'struct' OR $value['1'] == 'array')) + { + while (list($k) = each($value['0'])) + { + $value['0'][$k] = $this->values_parsing($value['0'][$k], TRUE); + } + + $temp = new XML_RPC_Values($value['0'], $value['1']); + } + else + { + $temp = new XML_RPC_Values($value['0'], $value['1']); + } + } + else + { + $temp = new XML_RPC_Values($value, 'string'); + } + + return $temp; + } + // END + + + //------------------------------------- + // Sends XML-RPC Request + //------------------------------------- + + function send_request() + { + $this->message = new XML_RPC_Message($this->method,$this->data); + $this->message->debug = $this->debug; + + if ( ! $this->result = $this->client->send($this->message)) + { + $this->error = $this->result->errstr; + return FALSE; + } + elseif( ! is_object($this->result->val)) + { + $this->error = $this->result->errstr; + return FALSE; + } + + $this->response = $this->result->decode(); + + return TRUE; + } + // END + + //------------------------------------- + // Returns Error + //------------------------------------- + + function display_error() + { + return $this->error; + } + // END + + //------------------------------------- + // Returns Remote Server Response + //------------------------------------- + + function display_response() + { + return $this->response; + } + // END + + //------------------------------------- + // Sends an Error Message for Server Request + //------------------------------------- + + function send_error_message($number, $message) + { + return new XML_RPC_Response('0',$number, $message); + } + // END + + + //------------------------------------- + // Send Response for Server Request + //------------------------------------- + + function send_response($response) + { + // $response should be array of values, which will be parsed + // based on their data and type into a valid group of XML-RPC values + + $response = $this->values_parsing($response); + + return new XML_RPC_Response($response); + } + // END + +} // END XML_RPC Class + + + +/** + * XML-RPC Client class + * + * @category XML-RPC + * @author ExpressionEngine Dev Team + * @link http://codeigniter.com/user_guide/libraries/xmlrpc.html + */ +class XML_RPC_Client extends CI_Xmlrpc +{ + var $path = ''; + var $server = ''; + var $port = 80; + var $errno = ''; + var $errstring = ''; + var $timeout = 5; + var $no_multicall = false; + + function XML_RPC_Client($path, $server, $port=80) + { + parent::CI_Xmlrpc(); + + $this->port = $port; + $this->server = $server; + $this->path = $path; + } + + function send($msg) + { + if (is_array($msg)) + { + // Multi-call disabled + $r = new XML_RPC_Response(0, $this->xmlrpcerr['multicall_recursion'],$this->xmlrpcstr['multicall_recursion']); + return $r; + } + + return $this->sendPayload($msg); + } + + function sendPayload($msg) + { + $fp = @fsockopen($this->server, $this->port,$this->errno, $this->errstr, $this->timeout); + + if ( ! is_resource($fp)) + { + error_log($this->xmlrpcstr['http_error']); + $r = new XML_RPC_Response(0, $this->xmlrpcerr['http_error'],$this->xmlrpcstr['http_error']); + return $r; + } + + if(empty($msg->payload)) + { + // $msg = XML_RPC_Messages + $msg->createPayload(); + } + + $r = "\r\n"; + $op = "POST {$this->path} HTTP/1.0$r"; + $op .= "Host: {$this->server}$r"; + $op .= "Content-Type: text/xml$r"; + $op .= "User-Agent: {$this->xmlrpcName}$r"; + $op .= "Content-Length: ".strlen($msg->payload). "$r$r"; + $op .= $msg->payload; + + + if ( ! fputs($fp, $op, strlen($op))) + { + error_log($this->xmlrpcstr['http_error']); + $r = new XML_RPC_Response(0, $this->xmlrpcerr['http_error'], $this->xmlrpcstr['http_error']); + return $r; + } + $resp = $msg->parseResponse($fp); + fclose($fp); + return $resp; + } + +} // end class XML_RPC_Client + + +/** + * XML-RPC Response class + * + * @category XML-RPC + * @author ExpressionEngine Dev Team + * @link http://codeigniter.com/user_guide/libraries/xmlrpc.html + */ +class XML_RPC_Response +{ + var $val = 0; + var $errno = 0; + var $errstr = ''; + var $headers = array(); + + function XML_RPC_Response($val, $code = 0, $fstr = '') + { + if ($code != 0) + { + // error + $this->errno = $code; + $this->errstr = htmlentities($fstr); + } + else if ( ! is_object($val)) + { + // programmer error, not an object + error_log("Invalid type '" . gettype($val) . "' (value: $val) passed to XML_RPC_Response. Defaulting to empty value."); + $this->val = new XML_RPC_Values(); + } + else + { + $this->val = $val; + } + } + + function faultCode() + { + return $this->errno; + } + + function faultString() + { + return $this->errstr; + } + + function value() + { + return $this->val; + } + + function prepare_response() + { + $result = "\n"; + if ($this->errno) + { + $result .= ' + + + + faultCode + ' . $this->errno . ' + + + faultString + ' . $this->errstr . ' + + + +'; + } + else + { + $result .= "\n\n" . + $this->val->serialize_class() . + "\n"; + } + $result .= "\n"; + return $result; + } + + function decode($array=FALSE) + { + $CI =& get_instance(); + + if ($array !== FALSE && is_array($array)) + { + while (list($key) = each($array)) + { + if (is_array($array[$key])) + { + $array[$key] = $this->decode($array[$key]); + } + else + { + $array[$key] = $CI->input->xss_clean($array[$key]); + } + } + + $result = $array; + } + else + { + $result = $this->xmlrpc_decoder($this->val); + + if (is_array($result)) + { + $result = $this->decode($result); + } + else + { + $result = $CI->input->xss_clean($result); + } + } + + return $result; + } + + + + //------------------------------------- + // XML-RPC Object to PHP Types + //------------------------------------- + + function xmlrpc_decoder($xmlrpc_val) + { + $kind = $xmlrpc_val->kindOf(); + + if($kind == 'scalar') + { + return $xmlrpc_val->scalarval(); + } + elseif($kind == 'array') + { + reset($xmlrpc_val->me); + list($a,$b) = each($xmlrpc_val->me); + $size = sizeof($b); + + $arr = array(); + + for($i = 0; $i < $size; $i++) + { + $arr[] = $this->xmlrpc_decoder($xmlrpc_val->me['array'][$i]); + } + return $arr; + } + elseif($kind == 'struct') + { + reset($xmlrpc_val->me['struct']); + $arr = array(); + + while(list($key,$value) = each($xmlrpc_val->me['struct'])) + { + $arr[$key] = $this->xmlrpc_decoder($value); + } + return $arr; + } + } + + + //------------------------------------- + // ISO-8601 time to server or UTC time + //------------------------------------- + + function iso8601_decode($time, $utc=0) + { + // return a timet in the localtime, or UTC + $t = 0; + if (preg_match('/([0-9]{4})([0-9]{2})([0-9]{2})T([0-9]{2}):([0-9]{2}):([0-9]{2})/', $time, $regs)) + { + if ($utc == 1) + $t = gmmktime($regs[4], $regs[5], $regs[6], $regs[2], $regs[3], $regs[1]); + else + $t = mktime($regs[4], $regs[5], $regs[6], $regs[2], $regs[3], $regs[1]); + } + return $t; + } + +} // End Response Class + + + +/** + * XML-RPC Message class + * + * @category XML-RPC + * @author ExpressionEngine Dev Team + * @link http://codeigniter.com/user_guide/libraries/xmlrpc.html + */ +class XML_RPC_Message extends CI_Xmlrpc +{ + var $payload; + var $method_name; + var $params = array(); + var $xh = array(); + + function XML_RPC_Message($method, $pars=0) + { + parent::CI_Xmlrpc(); + + $this->method_name = $method; + if (is_array($pars) && sizeof($pars) > 0) + { + for($i=0; $iparams[] = $pars[$i]; + } + } + } + + //------------------------------------- + // Create Payload to Send + //------------------------------------- + + function createPayload() + { + $this->payload = "\r\n\r\n"; + $this->payload .= '' . $this->method_name . "\r\n"; + $this->payload .= "\r\n"; + + for($i=0; $iparams); $i++) + { + // $p = XML_RPC_Values + $p = $this->params[$i]; + $this->payload .= "\r\n".$p->serialize_class()."\r\n"; + } + + $this->payload .= "\r\n\r\n"; + } + + //------------------------------------- + // Parse External XML-RPC Server's Response + //------------------------------------- + + function parseResponse($fp) + { + $data = ''; + + while($datum = fread($fp, 4096)) + { + $data .= $datum; + } + + //------------------------------------- + // DISPLAY HTTP CONTENT for DEBUGGING + //------------------------------------- + + if ($this->debug === TRUE) + { + echo "
    ";
    +			echo "---DATA---\n" . htmlspecialchars($data) . "\n---END DATA---\n\n";
    +			echo "
    "; + } + + //------------------------------------- + // Check for data + //------------------------------------- + + if($data == "") + { + error_log($this->xmlrpcstr['no_data']); + $r = new XML_RPC_Response(0, $this->xmlrpcerr['no_data'], $this->xmlrpcstr['no_data']); + return $r; + } + + + //------------------------------------- + // Check for HTTP 200 Response + //------------------------------------- + + if (strncmp($data, 'HTTP', 4) == 0 && ! preg_match('/^HTTP\/[0-9\.]+ 200 /', $data)) + { + $errstr= substr($data, 0, strpos($data, "\n")-1); + $r = new XML_RPC_Response(0, $this->xmlrpcerr['http_error'], $this->xmlrpcstr['http_error']. ' (' . $errstr . ')'); + return $r; + } + + //------------------------------------- + // Create and Set Up XML Parser + //------------------------------------- + + $parser = xml_parser_create($this->xmlrpc_defencoding); + + $this->xh[$parser] = array(); + $this->xh[$parser]['isf'] = 0; + $this->xh[$parser]['ac'] = ''; + $this->xh[$parser]['headers'] = array(); + $this->xh[$parser]['stack'] = array(); + $this->xh[$parser]['valuestack'] = array(); + $this->xh[$parser]['isf_reason'] = 0; + + xml_set_object($parser, $this); + 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'); + + + //------------------------------------- + // GET HEADERS + //------------------------------------- + + $lines = explode("\r\n", $data); + while (($line = array_shift($lines))) + { + if (strlen($line) < 1) + { + break; + } + $this->xh[$parser]['headers'][] = $line; + } + $data = implode("\r\n", $lines); + + + //------------------------------------- + // PARSE XML DATA + //------------------------------------- + + if ( ! xml_parse($parser, $data, sizeof($data))) + { + $errstr = sprintf('XML error: %s at line %d', + xml_error_string(xml_get_error_code($parser)), + xml_get_current_line_number($parser)); + //error_log($errstr); + $r = new XML_RPC_Response(0, $this->xmlrpcerr['invalid_return'], $this->xmlrpcstr['invalid_return']); + xml_parser_free($parser); + return $r; + } + xml_parser_free($parser); + + // --------------------------------------- + // Got Ourselves Some Badness, It Seems + // --------------------------------------- + + if ($this->xh[$parser]['isf'] > 1) + { + if ($this->debug === TRUE) + { + echo "---Invalid Return---\n"; + echo $this->xh[$parser]['isf_reason']; + echo "---Invalid Return---\n\n"; + } + + $r = new XML_RPC_Response(0, $this->xmlrpcerr['invalid_return'],$this->xmlrpcstr['invalid_return'].' '.$this->xh[$parser]['isf_reason']); + return $r; + } + elseif ( ! is_object($this->xh[$parser]['value'])) + { + $r = new XML_RPC_Response(0, $this->xmlrpcerr['invalid_return'],$this->xmlrpcstr['invalid_return'].' '.$this->xh[$parser]['isf_reason']); + return $r; + } + + //------------------------------------- + // DISPLAY XML CONTENT for DEBUGGING + //------------------------------------- + + if ($this->debug === TRUE) + { + echo "
    ";
    +			
    +			if (count($this->xh[$parser]['headers'] > 0))
    +			{
    +				echo "---HEADERS---\n";
    +				foreach ($this->xh[$parser]['headers'] as $header)
    +				{
    +					echo "$header\n";
    +				}
    +				echo "---END HEADERS---\n\n";
    +			}
    +			
    +			echo "---DATA---\n" . htmlspecialchars($data) . "\n---END DATA---\n\n";
    +			
    +			echo "---PARSED---\n" ;
    +			var_dump($this->xh[$parser]['value']);
    +			echo "\n---END PARSED---
    "; + } + + //------------------------------------- + // SEND RESPONSE + //------------------------------------- + + $v = $this->xh[$parser]['value']; + + if ($this->xh[$parser]['isf']) + { + $errno_v = $v->me['struct']['faultCode']; + $errstr_v = $v->me['struct']['faultString']; + $errno = $errno_v->scalarval(); + + if ($errno == 0) + { + // FAULT returned, errno needs to reflect that + $errno = -1; + } + + $r = new XML_RPC_Response($v, $errno, $errstr_v->scalarval()); + } + else + { + $r = new XML_RPC_Response($v); + } + + $r->headers = $this->xh[$parser]['headers']; + return $r; + } + + // ------------------------------------ + // Begin Return Message Parsing section + // ------------------------------------ + + // quick explanation of components: + // ac - used to accumulate values + // isf - used to indicate a fault + // lv - used to indicate "looking for a value": implements + // the logic to allow values with no types to be strings + // params - used to store parameters in method calls + // method - used to store method name + // stack - array with parent tree of the xml element, + // used to validate the nesting of elements + + //------------------------------------- + // Start Element Handler + //------------------------------------- + + function open_tag($the_parser, $name, $attrs) + { + // If invalid nesting, then return + if ($this->xh[$the_parser]['isf'] > 1) return; + + // Evaluate and check for correct nesting of XML elements + + if (count($this->xh[$the_parser]['stack']) == 0) + { + if ($name != 'METHODRESPONSE' && $name != 'METHODCALL') + { + $this->xh[$the_parser]['isf'] = 2; + $this->xh[$the_parser]['isf_reason'] = 'Top level XML-RPC element is missing'; + return; + } + } + else + { + // not top level element: see if parent is OK + if ( ! in_array($this->xh[$the_parser]['stack'][0], $this->valid_parents[$name], TRUE)) + { + $this->xh[$the_parser]['isf'] = 2; + $this->xh[$the_parser]['isf_reason'] = "XML-RPC element $name cannot be child of ".$this->xh[$the_parser]['stack'][0]; + return; + } + } + + switch($name) + { + case 'STRUCT': + case 'ARRAY': + // Creates array for child elements + + $cur_val = array('value' => array(), + 'type' => $name); + + array_unshift($this->xh[$the_parser]['valuestack'], $cur_val); + break; + case 'METHODNAME': + case 'NAME': + $this->xh[$the_parser]['ac'] = ''; + break; + case 'FAULT': + $this->xh[$the_parser]['isf'] = 1; + break; + case 'PARAM': + $this->xh[$the_parser]['value'] = null; + break; + case 'VALUE': + $this->xh[$the_parser]['vt'] = 'value'; + $this->xh[$the_parser]['ac'] = ''; + $this->xh[$the_parser]['lv'] = 1; + break; + case 'I4': + case 'INT': + case 'STRING': + case 'BOOLEAN': + case 'DOUBLE': + case 'DATETIME.ISO8601': + case 'BASE64': + if ($this->xh[$the_parser]['vt'] != 'value') + { + //two data elements inside a value: an error occurred! + $this->xh[$the_parser]['isf'] = 2; + $this->xh[$the_parser]['isf_reason'] = "'Twas a $name element following a ".$this->xh[$the_parser]['vt']." element inside a single value"; + return; + } + + $this->xh[$the_parser]['ac'] = ''; + break; + case 'MEMBER': + // Set name of to nothing to prevent errors later if no is found + $this->xh[$the_parser]['valuestack'][0]['name'] = ''; + + // Set NULL value to check to see if value passed for this param/member + $this->xh[$the_parser]['value'] = null; + break; + case 'DATA': + case 'METHODCALL': + case 'METHODRESPONSE': + case 'PARAMS': + // valid elements that add little to processing + break; + default: + /// An Invalid Element is Found, so we have trouble + $this->xh[$the_parser]['isf'] = 2; + $this->xh[$the_parser]['isf_reason'] = "Invalid XML-RPC element found: $name"; + break; + } + + // Add current element name to stack, to allow validation of nesting + array_unshift($this->xh[$the_parser]['stack'], $name); + + if ($name != 'VALUE') $this->xh[$the_parser]['lv'] = 0; + } + // END + + + //------------------------------------- + // End Element Handler + //------------------------------------- + + function closing_tag($the_parser, $name) + { + if ($this->xh[$the_parser]['isf'] > 1) return; + + // Remove current element from stack and set variable + // NOTE: If the XML validates, then we do not have to worry about + // the opening and closing of elements. Nesting is checked on the opening + // tag so we be safe there as well. + + $curr_elem = array_shift($this->xh[$the_parser]['stack']); + + switch($name) + { + case 'STRUCT': + case 'ARRAY': + $cur_val = array_shift($this->xh[$the_parser]['valuestack']); + $this->xh[$the_parser]['value'] = ( ! isset($cur_val['values'])) ? array() : $cur_val['values']; + $this->xh[$the_parser]['vt'] = strtolower($name); + break; + case 'NAME': + $this->xh[$the_parser]['valuestack'][0]['name'] = $this->xh[$the_parser]['ac']; + break; + case 'BOOLEAN': + case 'I4': + case 'INT': + case 'STRING': + case 'DOUBLE': + case 'DATETIME.ISO8601': + case 'BASE64': + $this->xh[$the_parser]['vt'] = strtolower($name); + + if ($name == 'STRING') + { + $this->xh[$the_parser]['value'] = $this->xh[$the_parser]['ac']; + } + elseif ($name=='DATETIME.ISO8601') + { + $this->xh[$the_parser]['vt'] = $this->xmlrpcDateTime; + $this->xh[$the_parser]['value'] = $this->xh[$the_parser]['ac']; + } + elseif ($name=='BASE64') + { + $this->xh[$the_parser]['value'] = base64_decode($this->xh[$the_parser]['ac']); + } + elseif ($name=='BOOLEAN') + { + // Translated BOOLEAN values to TRUE AND FALSE + if ($this->xh[$the_parser]['ac'] == '1') + { + $this->xh[$the_parser]['value'] = TRUE; + } + else + { + $this->xh[$the_parser]['value'] = FALSE; + } + } + elseif ($name=='DOUBLE') + { + // we have a DOUBLE + // we must check that only 0123456789-. are characters here + if ( ! preg_match('/^[+-]?[eE0-9\t \.]+$/', $this->xh[$the_parser]['ac'])) + { + $this->xh[$the_parser]['value'] = 'ERROR_NON_NUMERIC_FOUND'; + } + else + { + $this->xh[$the_parser]['value'] = (double)$this->xh[$the_parser]['ac']; + } + } + else + { + // we have an I4/INT + // we must check that only 0123456789- are characters here + if ( ! preg_match('/^[+-]?[0-9\t ]+$/', $this->xh[$the_parser]['ac'])) + { + $this->xh[$the_parser]['value'] = 'ERROR_NON_NUMERIC_FOUND'; + } + else + { + $this->xh[$the_parser]['value'] = (int)$this->xh[$the_parser]['ac']; + } + } + $this->xh[$the_parser]['ac'] = ''; + $this->xh[$the_parser]['lv'] = 3; // indicate we've found a value + break; + case 'VALUE': + // This if() detects if no scalar was inside + if ($this->xh[$the_parser]['vt']=='value') + { + $this->xh[$the_parser]['value'] = $this->xh[$the_parser]['ac']; + $this->xh[$the_parser]['vt'] = $this->xmlrpcString; + } + + // build the XML-RPC value out of the data received, and substitute it + $temp = new XML_RPC_Values($this->xh[$the_parser]['value'], $this->xh[$the_parser]['vt']); + + if (count($this->xh[$the_parser]['valuestack']) && $this->xh[$the_parser]['valuestack'][0]['type'] == 'ARRAY') + { + // Array + $this->xh[$the_parser]['valuestack'][0]['values'][] = $temp; + } + else + { + // Struct + $this->xh[$the_parser]['value'] = $temp; + } + break; + case 'MEMBER': + $this->xh[$the_parser]['ac']=''; + + // If value add to array in the stack for the last element built + if ($this->xh[$the_parser]['value']) + { + $this->xh[$the_parser]['valuestack'][0]['values'][$this->xh[$the_parser]['valuestack'][0]['name']] = $this->xh[$the_parser]['value']; + } + break; + case 'DATA': + $this->xh[$the_parser]['ac']=''; + break; + case 'PARAM': + if ($this->xh[$the_parser]['value']) + { + $this->xh[$the_parser]['params'][] = $this->xh[$the_parser]['value']; + } + break; + case 'METHODNAME': + $this->xh[$the_parser]['method'] = ltrim($this->xh[$the_parser]['ac']); + break; + case 'PARAMS': + case 'FAULT': + case 'METHODCALL': + case 'METHORESPONSE': + // We're all good kids with nuthin' to do + break; + default: + // End of an Invalid Element. Taken care of during the opening tag though + break; + } + } + + //------------------------------------- + // Parses Character Data + //------------------------------------- + + function character_data($the_parser, $data) + { + if ($this->xh[$the_parser]['isf'] > 1) return; // XML Fault found already + + // If a value has not been found + if ($this->xh[$the_parser]['lv'] != 3) + { + if ($this->xh[$the_parser]['lv'] == 1) + { + $this->xh[$the_parser]['lv'] = 2; // Found a value + } + + if( ! @isset($this->xh[$the_parser]['ac'])) + { + $this->xh[$the_parser]['ac'] = ''; + } + + $this->xh[$the_parser]['ac'] .= $data; + } + } + + + function addParam($par) { $this->params[]=$par; } + + function output_parameters($array=FALSE) + { + $CI =& get_instance(); + + if ($array !== FALSE && is_array($array)) + { + while (list($key) = each($array)) + { + if (is_array($array[$key])) + { + $array[$key] = $this->output_parameters($array[$key]); + } + else + { + $array[$key] = $CI->input->xss_clean($array[$key]); + } + } + + $parameters = $array; + } + else + { + $parameters = array(); + + for ($i = 0; $i < sizeof($this->params); $i++) + { + $a_param = $this->decode_message($this->params[$i]); + + if (is_array($a_param)) + { + $parameters[] = $this->output_parameters($a_param); + } + else + { + $parameters[] = $CI->input->xss_clean($a_param); + } + } + } + + return $parameters; + } + + + function decode_message($param) + { + $kind = $param->kindOf(); + + if($kind == 'scalar') + { + return $param->scalarval(); + } + elseif($kind == 'array') + { + reset($param->me); + list($a,$b) = each($param->me); + + $arr = array(); + + for($i = 0; $i < sizeof($b); $i++) + { + $arr[] = $this->decode_message($param->me['array'][$i]); + } + + return $arr; + } + elseif($kind == 'struct') + { + reset($param->me['struct']); + + $arr = array(); + + while(list($key,$value) = each($param->me['struct'])) + { + $arr[$key] = $this->decode_message($value); + } + + return $arr; + } + } + +} // End XML_RPC_Messages class + + + +/** + * XML-RPC Values class + * + * @category XML-RPC + * @author ExpressionEngine Dev Team + * @link http://codeigniter.com/user_guide/libraries/xmlrpc.html + */ +class XML_RPC_Values extends CI_Xmlrpc +{ + var $me = array(); + var $mytype = 0; + + function XML_RPC_Values($val=-1, $type='') + { + parent::CI_Xmlrpc(); + + if ($val != -1 OR $type != '') + { + $type = $type == '' ? 'string' : $type; + + if ($this->xmlrpcTypes[$type] == 1) + { + $this->addScalar($val,$type); + } + elseif ($this->xmlrpcTypes[$type] == 2) + { + $this->addArray($val); + } + elseif ($this->xmlrpcTypes[$type] == 3) + { + $this->addStruct($val); + } + } + } + + function addScalar($val, $type='string') + { + $typeof = $this->xmlrpcTypes[$type]; + + if ($this->mytype==1) + { + echo 'XML_RPC_Values: scalar can have only one value
    '; + return 0; + } + + if ($typeof != 1) + { + echo 'XML_RPC_Values: not a scalar type (${typeof})
    '; + return 0; + } + + if ($type == $this->xmlrpcBoolean) + { + if (strcasecmp($val,'true')==0 OR $val==1 OR ($val==true && strcasecmp($val,'false'))) + { + $val = 1; + } + else + { + $val=0; + } + } + + if ($this->mytype == 2) + { + // adding to an array here + $ar = $this->me['array']; + $ar[] = new XML_RPC_Values($val, $type); + $this->me['array'] = $ar; + } + else + { + // a scalar, so set the value and remember we're scalar + $this->me[$type] = $val; + $this->mytype = $typeof; + } + return 1; + } + + function addArray($vals) + { + if ($this->mytype != 0) + { + echo 'XML_RPC_Values: already initialized as a [' . $this->kindOf() . ']
    '; + return 0; + } + + $this->mytype = $this->xmlrpcTypes['array']; + $this->me['array'] = $vals; + return 1; + } + + function addStruct($vals) + { + if ($this->mytype != 0) + { + echo 'XML_RPC_Values: already initialized as a [' . $this->kindOf() . ']
    '; + return 0; + } + $this->mytype = $this->xmlrpcTypes['struct']; + $this->me['struct'] = $vals; + return 1; + } + + function kindOf() + { + switch($this->mytype) + { + case 3: + return 'struct'; + break; + case 2: + return 'array'; + break; + case 1: + return 'scalar'; + break; + default: + return 'undef'; + } + } + + function serializedata($typ, $val) + { + $rs = ''; + + switch($this->xmlrpcTypes[$typ]) + { + case 3: + // struct + $rs .= "\n"; + reset($val); + while(list($key2, $val2) = each($val)) + { + $rs .= "\n{$key2}\n"; + $rs .= $this->serializeval($val2); + $rs .= "\n"; + } + $rs .= ''; + break; + case 2: + // array + $rs .= "\n\n"; + for($i=0; $i < sizeof($val); $i++) + { + $rs .= $this->serializeval($val[$i]); + } + $rs.="\n\n"; + break; + case 1: + // others + switch ($typ) + { + case $this->xmlrpcBase64: + $rs .= "<{$typ}>" . base64_encode($val) . "\n"; + break; + case $this->xmlrpcBoolean: + $rs .= "<{$typ}>" . ($val ? '1' : '0') . "\n"; + break; + case $this->xmlrpcString: + $rs .= "<{$typ}>" . htmlspecialchars($val). "\n"; + break; + default: + $rs .= "<{$typ}>{$val}\n"; + break; + } + default: + break; + } + return $rs; + } + + function serialize_class() + { + return $this->serializeval($this); + } + + function serializeval($o) + { + $ar = $o->me; + reset($ar); + + list($typ, $val) = each($ar); + $rs = "\n".$this->serializedata($typ, $val)."\n"; + return $rs; + } + + function scalarval() + { + reset($this->me); + list($a,$b) = each($this->me); + return $b; + } + + + //------------------------------------- + // Encode time in ISO-8601 form. + //------------------------------------- + + // Useful for sending time in XML-RPC + + function iso8601_encode($time, $utc=0) + { + if ($utc == 1) + { + $t = strftime("%Y%m%dT%H:%M:%S", $time); + } + else + { + if (function_exists('gmstrftime')) + $t = gmstrftime("%Y%m%dT%H:%M:%S", $time); + else + $t = strftime("%Y%m%dT%H:%M:%S", $time - date('Z')); + } + return $t; + } + +} +// END XML_RPC_Values Class + +/* End of file Xmlrpc.php */ /* Location: ./system/libraries/Xmlrpc.php */ \ No newline at end of file diff --git a/system/libraries/Xmlrpcs.php b/system/libraries/Xmlrpcs.php index a21018328..cdbdee955 100644 --- a/system/libraries/Xmlrpcs.php +++ b/system/libraries/Xmlrpcs.php @@ -1,536 +1,536 @@ -set_system_methods(); - - if (isset($config['functions']) && is_array($config['functions'])) - { - $this->methods = array_merge($this->methods, $config['functions']); - } - - log_message('debug', "XML-RPC Server Class Initialized"); - } - - //------------------------------------- - // Initialize Prefs and Serve - //------------------------------------- - - 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']; - } - } - - //------------------------------------- - // Setting of System Methods - //------------------------------------- - - 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 - //------------------------------------- - - function serve() - { - $r = $this->parseRequest(); - $payload = 'xmlrpc_defencoding.'"?'.'>'."\n"; - $payload .= $this->debug_msg; - $payload .= $r->prepare_response(); - - header("Content-Type: text/xml"); - header("Content-Length: ".strlen($payload)); - echo $payload; - } - - //------------------------------------- - // Add Method to Class - //------------------------------------- - - function add_to_map($methodname,$function,$sig,$doc) - { - $this->methods[$methodname] = array( - 'function' => $function, - 'signature' => $sig, - 'docstring' => $doc - ); - } - - - //------------------------------------- - // Parse Server Request - //------------------------------------- - - function parseRequest($data='') - { - global $HTTP_RAW_POST_DATA; - - //------------------------------------- - // Get Data - //------------------------------------- - - if ($data == '') - { - $data = $HTTP_RAW_POST_DATA; - } - - //------------------------------------- - // Set up XML Parser - //------------------------------------- - - $parser = xml_parser_create($this->xmlrpc_defencoding); - $parser_object = new XML_RPC_Message("filler"); - - $parser_object->xh[$parser] = array(); - $parser_object->xh[$parser]['isf'] = 0; - $parser_object->xh[$parser]['isf_reason'] = ''; - $parser_object->xh[$parser]['params'] = array(); - $parser_object->xh[$parser]['stack'] = array(); - $parser_object->xh[$parser]['valuestack'] = array(); - $parser_object->xh[$parser]['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[$parser]['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[$parser]['method']); - $plist=''; - - for($i=0; $i < sizeof($parser_object->xh[$parser]['params']); $i++) - { - if ($this->debug === TRUE) - { - $plist .= "$i - " . print_r(get_object_vars($parser_object->xh[$parser]['params'][$i]), TRUE). ";\n"; - } - - $m->addParam($parser_object->xh[$parser]['params'][$i]); - } - - if ($this->debug === TRUE) - { - echo "
    ";
    -				echo "---PLIST---\n" . $plist . "\n---PLIST END---\n\n";
    -				echo "
    "; - } - - $r = $this->_execute($m); - } - - //------------------------------------- - // SET DEBUGGING MESSAGE - //------------------------------------- - - if ($this->debug === TRUE) - { - $this->debug_msg = "\n"; - } - - return $r; - } - - //------------------------------------- - // Executes the Method - //------------------------------------- - - 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; - - //------------------------------------- - // 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 < sizeof($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 - //------------------------------------- - - 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 - //------------------------------------- - - 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 < sizeof($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 - //------------------------------------- - - 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 - //------------------------------------- - - 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 < sizeof($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 - //------------------------------------- - - 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 - //------------------------------------- - - 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 = sizeof($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'); - } - -} -// END XML_RPC_Server class - - -/* End of file Xmlrpcs.php */ +set_system_methods(); + + if (isset($config['functions']) && is_array($config['functions'])) + { + $this->methods = array_merge($this->methods, $config['functions']); + } + + log_message('debug', "XML-RPC Server Class Initialized"); + } + + //------------------------------------- + // Initialize Prefs and Serve + //------------------------------------- + + 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']; + } + } + + //------------------------------------- + // Setting of System Methods + //------------------------------------- + + 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 + //------------------------------------- + + function serve() + { + $r = $this->parseRequest(); + $payload = 'xmlrpc_defencoding.'"?'.'>'."\n"; + $payload .= $this->debug_msg; + $payload .= $r->prepare_response(); + + header("Content-Type: text/xml"); + header("Content-Length: ".strlen($payload)); + echo $payload; + } + + //------------------------------------- + // Add Method to Class + //------------------------------------- + + function add_to_map($methodname,$function,$sig,$doc) + { + $this->methods[$methodname] = array( + 'function' => $function, + 'signature' => $sig, + 'docstring' => $doc + ); + } + + + //------------------------------------- + // Parse Server Request + //------------------------------------- + + function parseRequest($data='') + { + global $HTTP_RAW_POST_DATA; + + //------------------------------------- + // Get Data + //------------------------------------- + + if ($data == '') + { + $data = $HTTP_RAW_POST_DATA; + } + + //------------------------------------- + // Set up XML Parser + //------------------------------------- + + $parser = xml_parser_create($this->xmlrpc_defencoding); + $parser_object = new XML_RPC_Message("filler"); + + $parser_object->xh[$parser] = array(); + $parser_object->xh[$parser]['isf'] = 0; + $parser_object->xh[$parser]['isf_reason'] = ''; + $parser_object->xh[$parser]['params'] = array(); + $parser_object->xh[$parser]['stack'] = array(); + $parser_object->xh[$parser]['valuestack'] = array(); + $parser_object->xh[$parser]['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[$parser]['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[$parser]['method']); + $plist=''; + + for($i=0; $i < sizeof($parser_object->xh[$parser]['params']); $i++) + { + if ($this->debug === TRUE) + { + $plist .= "$i - " . print_r(get_object_vars($parser_object->xh[$parser]['params'][$i]), TRUE). ";\n"; + } + + $m->addParam($parser_object->xh[$parser]['params'][$i]); + } + + if ($this->debug === TRUE) + { + echo "
    ";
    +				echo "---PLIST---\n" . $plist . "\n---PLIST END---\n\n";
    +				echo "
    "; + } + + $r = $this->_execute($m); + } + + //------------------------------------- + // SET DEBUGGING MESSAGE + //------------------------------------- + + if ($this->debug === TRUE) + { + $this->debug_msg = "\n"; + } + + return $r; + } + + //------------------------------------- + // Executes the Method + //------------------------------------- + + 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; + + //------------------------------------- + // 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 < sizeof($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 + //------------------------------------- + + 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 + //------------------------------------- + + 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 < sizeof($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 + //------------------------------------- + + 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 + //------------------------------------- + + 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 < sizeof($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 + //------------------------------------- + + 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 + //------------------------------------- + + 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 = sizeof($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'); + } + +} +// 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 index c15255a85..731881590 100644 --- a/system/libraries/Zip.php +++ b/system/libraries/Zip.php @@ -1,359 +1,359 @@ -_add_dir($dir); - } - } - - // -------------------------------------------------------------------- - - /** - * Add Directory - * - * @access private - * @param string the directory name - * @return void - */ - function _add_dir($dir) - { - $dir = str_replace("\\", "/", $dir); - - $this->zipdata .= - "\x50\x4b\x03\x04\x0a\x00\x00\x00\x00\x00\x00\x00\x00\x00" - .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\x00\x00\x00\x00" - .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) - { - $this->_add_data($path, $data); - } - } - else - { - $this->_add_data($filepath, $data); - } - } - - // -------------------------------------------------------------------- - - /** - * 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) - { - $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\x00\x00\x00\x00" - .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\x00\x00\x00\x00" - .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) - { - if ($fp = @opendir($path)) - { - while (FALSE !== ($file = readdir($fp))) - { - if (@is_dir($path.$file) && substr($file, 0, 1) != '.') - { - $this->read_dir($path.$file."/"); - } - elseif (substr($file, 0, 1) != ".") - { - if (FALSE !== ($data = file_get_contents($path.$file))) - { - $this->add_data(str_replace("\\", "/", $path).$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'; - } - - $zip_content =& $this->get_zip(); - - $CI =& get_instance(); - $CI->load->helper('download'); - - 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; - } - -} - -/* End of file Zip.php */ +_add_dir($dir); + } + } + + // -------------------------------------------------------------------- + + /** + * Add Directory + * + * @access private + * @param string the directory name + * @return void + */ + function _add_dir($dir) + { + $dir = str_replace("\\", "/", $dir); + + $this->zipdata .= + "\x50\x4b\x03\x04\x0a\x00\x00\x00\x00\x00\x00\x00\x00\x00" + .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\x00\x00\x00\x00" + .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) + { + $this->_add_data($path, $data); + } + } + else + { + $this->_add_data($filepath, $data); + } + } + + // -------------------------------------------------------------------- + + /** + * 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) + { + $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\x00\x00\x00\x00" + .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\x00\x00\x00\x00" + .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) + { + if ($fp = @opendir($path)) + { + while (FALSE !== ($file = readdir($fp))) + { + if (@is_dir($path.$file) && substr($file, 0, 1) != '.') + { + $this->read_dir($path.$file."/"); + } + elseif (substr($file, 0, 1) != ".") + { + if (FALSE !== ($data = file_get_contents($path.$file))) + { + $this->add_data(str_replace("\\", "/", $path).$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'; + } + + $zip_content =& $this->get_zip(); + + $CI =& get_instance(); + $CI->load->helper('download'); + + 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; + } + +} + +/* 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 index 065d2da5e..c942a79ce 100644 --- a/system/libraries/index.html +++ b/system/libraries/index.html @@ -1,10 +1,10 @@ - - - 403 Forbidden - - - -

    Directory access is forbidden.

    - - + + + 403 Forbidden + + + +

    Directory access is forbidden.

    + + \ No newline at end of file diff --git a/system/logs/index.html b/system/logs/index.html index 065d2da5e..c942a79ce 100644 --- a/system/logs/index.html +++ b/system/logs/index.html @@ -1,10 +1,10 @@ - - - 403 Forbidden - - - -

    Directory access is forbidden.

    - - + + + 403 Forbidden + + + +

    Directory access is forbidden.

    + + \ No newline at end of file diff --git a/system/plugins/captcha_pi.php b/system/plugins/captcha_pi.php index 0484a6f1e..4a09dcbb5 100644 --- a/system/plugins/captcha_pi.php +++ b/system/plugins/captcha_pi.php @@ -1,356 +1,356 @@ -load->plugin('captcha'); - -Once loaded you can generate a captcha like this: - - $vals = array( - 'word' => 'Random word', - 'img_path' => './captcha/', - 'img_url' => 'http://example.com/captcha/', - 'font_path' => './system/fonts/texb.ttf', - 'img_width' => '150', - 'img_height' => 30, - 'expiration' => 7200 - ); - - $cap = create_captcha($vals); - echo $cap['image']; - - -NOTES: - - The captcha function requires the GD image library. - - Only the img_path and img_url are required. - - If a "word" is not supplied, the function will generate a random - ASCII string. You might put together your own word library that - you can draw randomly from. - - If you do not specify a path to a TRUE TYPE font, the native ugly GD - font will be used. - - The "captcha" folder must be writable (666, or 777) - - The "expiration" (in seconds) signifies how long an image will - remain in the captcha folder before it will be deleted. The default - is two hours. - -RETURNED DATA - -The create_captcha() function returns an associative array with this data: - - [array] - ( - 'image' => IMAGE TAG - 'time' => TIMESTAMP (in microtime) - 'word' => CAPTCHA WORD - ) - -The "image" is the actual image tag: - - -The "time" is the micro timestamp used as the image name without the file -extension. It will be a number like this: 1139612155.3422 - -The "word" is the word that appears in the captcha image, which if not -supplied to the function, will be a random string. - - -ADDING A DATABASE - -In order for the captcha function to prevent someone from posting, you will need -to add the information returned from create_captcha() function to your database. -Then, when the data from the form is submitted by the user you will need to verify -that the data exists in the database and has not expired. - -Here is a table prototype: - - CREATE TABLE captcha ( - captcha_id bigint(13) unsigned NOT NULL auto_increment, - captcha_time int(10) unsigned NOT NULL, - ip_address varchar(16) default '0' NOT NULL, - word varchar(20) NOT NULL, - PRIMARY KEY `captcha_id` (`captcha_id`), - KEY `word` (`word`) - ) - - -Here is an example of usage with a DB. - -On the page where the captcha will be shown you'll have something like this: - - $this->load->plugin('captcha'); - $vals = array( - 'img_path' => './captcha/', - 'img_url' => 'http://example.com/captcha/' - ); - - $cap = create_captcha($vals); - - $data = array( - 'captcha_id' => '', - 'captcha_time' => $cap['time'], - 'ip_address' => $this->input->ip_address(), - 'word' => $cap['word'] - ); - - $query = $this->db->insert_string('captcha', $data); - $this->db->query($query); - - echo 'Submit the word you see below:'; - echo $cap['image']; - echo ''; - - -Then, on the page that accepts the submission you'll have something like this: - - // First, delete old captchas - $expiration = time()-7200; // Two hour limit - $DB->query("DELETE FROM captcha WHERE captcha_time < ".$expiration); - - // Then see if a captcha exists: - $sql = "SELECT COUNT(*) AS count FROM captcha WHERE word = ? AND ip_address = ? AND date > ?"; - $binds = array($_POST['captcha'], $this->input->ip_address(), $expiration); - $query = $this->db->query($sql, $binds); - $row = $query->row(); - - if ($row->count == 0) - { - echo "You must submit the word that appears in the image"; - } - -*/ - - - -/** -|========================================================== -| Create Captcha -|========================================================== -| -*/ -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); - - 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_really_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); -} - - -/* End of file captcha_pi.php */ +load->plugin('captcha'); + +Once loaded you can generate a captcha like this: + + $vals = array( + 'word' => 'Random word', + 'img_path' => './captcha/', + 'img_url' => 'http://example.com/captcha/', + 'font_path' => './system/fonts/texb.ttf', + 'img_width' => '150', + 'img_height' => 30, + 'expiration' => 7200 + ); + + $cap = create_captcha($vals); + echo $cap['image']; + + +NOTES: + + The captcha function requires the GD image library. + + Only the img_path and img_url are required. + + If a "word" is not supplied, the function will generate a random + ASCII string. You might put together your own word library that + you can draw randomly from. + + If you do not specify a path to a TRUE TYPE font, the native ugly GD + font will be used. + + The "captcha" folder must be writable (666, or 777) + + The "expiration" (in seconds) signifies how long an image will + remain in the captcha folder before it will be deleted. The default + is two hours. + +RETURNED DATA + +The create_captcha() function returns an associative array with this data: + + [array] + ( + 'image' => IMAGE TAG + 'time' => TIMESTAMP (in microtime) + 'word' => CAPTCHA WORD + ) + +The "image" is the actual image tag: + + +The "time" is the micro timestamp used as the image name without the file +extension. It will be a number like this: 1139612155.3422 + +The "word" is the word that appears in the captcha image, which if not +supplied to the function, will be a random string. + + +ADDING A DATABASE + +In order for the captcha function to prevent someone from posting, you will need +to add the information returned from create_captcha() function to your database. +Then, when the data from the form is submitted by the user you will need to verify +that the data exists in the database and has not expired. + +Here is a table prototype: + + CREATE TABLE captcha ( + captcha_id bigint(13) unsigned NOT NULL auto_increment, + captcha_time int(10) unsigned NOT NULL, + ip_address varchar(16) default '0' NOT NULL, + word varchar(20) NOT NULL, + PRIMARY KEY `captcha_id` (`captcha_id`), + KEY `word` (`word`) + ) + + +Here is an example of usage with a DB. + +On the page where the captcha will be shown you'll have something like this: + + $this->load->plugin('captcha'); + $vals = array( + 'img_path' => './captcha/', + 'img_url' => 'http://example.com/captcha/' + ); + + $cap = create_captcha($vals); + + $data = array( + 'captcha_id' => '', + 'captcha_time' => $cap['time'], + 'ip_address' => $this->input->ip_address(), + 'word' => $cap['word'] + ); + + $query = $this->db->insert_string('captcha', $data); + $this->db->query($query); + + echo 'Submit the word you see below:'; + echo $cap['image']; + echo ''; + + +Then, on the page that accepts the submission you'll have something like this: + + // First, delete old captchas + $expiration = time()-7200; // Two hour limit + $DB->query("DELETE FROM captcha WHERE captcha_time < ".$expiration); + + // Then see if a captcha exists: + $sql = "SELECT COUNT(*) AS count FROM captcha WHERE word = ? AND ip_address = ? AND date > ?"; + $binds = array($_POST['captcha'], $this->input->ip_address(), $expiration); + $query = $this->db->query($sql, $binds); + $row = $query->row(); + + if ($row->count == 0) + { + echo "You must submit the word that appears in the image"; + } + +*/ + + + +/** +|========================================================== +| Create Captcha +|========================================================== +| +*/ +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); + + 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_really_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); +} + + +/* End of file captcha_pi.php */ /* Location: ./system/plugins/captcha_pi.php */ \ No newline at end of file diff --git a/system/plugins/index.html b/system/plugins/index.html index 065d2da5e..c942a79ce 100644 --- a/system/plugins/index.html +++ b/system/plugins/index.html @@ -1,10 +1,10 @@ - - - 403 Forbidden - - - -

    Directory access is forbidden.

    - - + + + 403 Forbidden + + + +

    Directory access is forbidden.

    + + \ No newline at end of file diff --git a/system/plugins/js_calendar_pi.php b/system/plugins/js_calendar_pi.php index e165c5444..6dadd4ad9 100644 --- a/system/plugins/js_calendar_pi.php +++ b/system/plugins/js_calendar_pi.php @@ -1,629 +1,629 @@ -load->plugin('js_calendar'); - -Once loaded you'll add the calendar script to the of your page like this: - - - -The above function will be passed the name of your form. - -Then to show the actual calendar you'll do this: - - -
    - -

    Today

    -
    - - -Note: The first parameter is the name of the field containing your date, the second parameter contains the "now" time, -and the third tells the calendar whether to highlight the current day or not. - -Lastly, you'll need some CSS for your calendar: - -.calendar { - border: 1px #6975A3 solid; - background-color: transparent; -} -.calheading { - background-color: #7C8BC0; - color: #fff; - font-family: Lucida Grande, Verdana, Geneva, Sans-serif; - font-size: 11px; - font-weight: bold; - text-align: center; -} -.calnavleft { - background-color: #7C8BC0; - font-family: Lucida Grande, Verdana, Geneva, Sans-serif; - font-size: 10px; - font-weight: bold; - color: #fff; - padding: 4px; - cursor: pointer; -} -.calnavright { - background-color: #7C8BC0; - font-family: Lucida Grande, Verdana, Geneva, Sans-serif; - font-size: 10px; - font-weight: bold; - color: #fff; - text-align: right; - padding: 4px; - cursor: pointer; -} -.caldayheading { - background-color: #000; - color: #fff; - font-family: Lucida Grande, Verdana, Geneva, Sans-serif; - font-size: 10px; - text-align: center; - padding: 6px 2px 6px 2px; -} -.caldaycells{ - color: #000; - background-color: #D1D7E6; - font-family: Lucida Grande, Verdana, Geneva, Sans-serif; - font-size: 11px; - text-align: center; - padding: 4px; - border: 1px #E0E5F1 solid; - cursor: pointer; -} -.caldaycellhover{ - color: #fff; - background-color: #B3BCD4; - font-family: Lucida Grande, Verdana, Geneva, Sans-serif; - font-size: 11px; - text-align: center; - padding: 4px; - border: 1px #B3BCD4 solid; - cursor: pointer; -} -.caldayselected{ - background-color: #737FAC; - color: #fff; - font-family: Lucida Grande, Verdana, Geneva, Sans-serif; - font-size: 11px; - font-weight: bold; - text-align: center; - border: 1px #566188 solid; - padding: 3px; - cursor: pointer; -} -.calblanktop { - background-color: #fff; - padding: 4px; -} -.calblankbot { - background-color: #fff; - padding: 4px; -} - - -*/ - -function js_calendar_script($form_name = 'entryform') -{ -$CI =& get_instance(); -$CI->load->language('calendar'); -ob_start(); -?> - - - var '.$field_id.' = new calendar("'.$field_id.'", '.$time.', '.(($highlight == TRUE) ? 'true' : 'false').'); - document.write('.$field_id.'.write()); - '; -} - - -/* End of file js_calendar_pi.php */ +load->plugin('js_calendar'); + +Once loaded you'll add the calendar script to the of your page like this: + + + +The above function will be passed the name of your form. + +Then to show the actual calendar you'll do this: + + +
    + +

    Today

    +
    + + +Note: The first parameter is the name of the field containing your date, the second parameter contains the "now" time, +and the third tells the calendar whether to highlight the current day or not. + +Lastly, you'll need some CSS for your calendar: + +.calendar { + border: 1px #6975A3 solid; + background-color: transparent; +} +.calheading { + background-color: #7C8BC0; + color: #fff; + font-family: Lucida Grande, Verdana, Geneva, Sans-serif; + font-size: 11px; + font-weight: bold; + text-align: center; +} +.calnavleft { + background-color: #7C8BC0; + font-family: Lucida Grande, Verdana, Geneva, Sans-serif; + font-size: 10px; + font-weight: bold; + color: #fff; + padding: 4px; + cursor: pointer; +} +.calnavright { + background-color: #7C8BC0; + font-family: Lucida Grande, Verdana, Geneva, Sans-serif; + font-size: 10px; + font-weight: bold; + color: #fff; + text-align: right; + padding: 4px; + cursor: pointer; +} +.caldayheading { + background-color: #000; + color: #fff; + font-family: Lucida Grande, Verdana, Geneva, Sans-serif; + font-size: 10px; + text-align: center; + padding: 6px 2px 6px 2px; +} +.caldaycells{ + color: #000; + background-color: #D1D7E6; + font-family: Lucida Grande, Verdana, Geneva, Sans-serif; + font-size: 11px; + text-align: center; + padding: 4px; + border: 1px #E0E5F1 solid; + cursor: pointer; +} +.caldaycellhover{ + color: #fff; + background-color: #B3BCD4; + font-family: Lucida Grande, Verdana, Geneva, Sans-serif; + font-size: 11px; + text-align: center; + padding: 4px; + border: 1px #B3BCD4 solid; + cursor: pointer; +} +.caldayselected{ + background-color: #737FAC; + color: #fff; + font-family: Lucida Grande, Verdana, Geneva, Sans-serif; + font-size: 11px; + font-weight: bold; + text-align: center; + border: 1px #566188 solid; + padding: 3px; + cursor: pointer; +} +.calblanktop { + background-color: #fff; + padding: 4px; +} +.calblankbot { + background-color: #fff; + padding: 4px; +} + + +*/ + +function js_calendar_script($form_name = 'entryform') +{ +$CI =& get_instance(); +$CI->load->language('calendar'); +ob_start(); +?> + + + var '.$field_id.' = new calendar("'.$field_id.'", '.$time.', '.(($highlight == TRUE) ? 'true' : 'false').'); + document.write('.$field_id.'.write()); + '; +} + + +/* End of file js_calendar_pi.php */ /* Location: ./system/plugins/js_calendar_pi.php */ \ No newline at end of file diff --git a/system/scaffolding/Scaffolding.php b/system/scaffolding/Scaffolding.php index 28172ca1e..1d5267016 100644 --- a/system/scaffolding/Scaffolding.php +++ b/system/scaffolding/Scaffolding.php @@ -1,291 +1,291 @@ -CI =& get_instance(); - - $this->CI->load->database("", FALSE, TRUE); - $this->CI->load->library('pagination'); - - // Turn off caching - $this->CI->db->cache_off(); - - /** - * Set the current table name - * This is done when initializing scaffolding: - * $this->load->scaffolding('table_name') - * - */ - $this->current_table = $db_table; - - /** - * Set the path to the "view" files - * We'll manually override the "view" path so that - * the load->view function knows where to look. - */ - - $this->CI->load->_ci_view_path = BASEPATH.'scaffolding/views/'; - - // Set the base URL - $this->base_url = $this->CI->config->site_url().'/'.$this->CI->uri->segment(1).$this->CI->uri->slash_segment(2, 'both'); - $this->base_uri = $this->CI->uri->segment(1).$this->CI->uri->slash_segment(2, 'leading'); - - // Set a few globals - $data = array( - 'image_url' => $this->CI->config->system_url().'scaffolding/images/', - 'base_uri' => $this->base_uri, - 'base_url' => $this->base_url, - 'title' => $this->current_table - ); - - $this->CI->load->vars($data); - - // Load the language file and create variables - $this->lang = $this->CI->load->scaffold_language('scaffolding', '', TRUE); - $this->CI->load->vars($this->lang); - - // Load the helper files we plan to use - $this->CI->load->helper(array('url', 'form')); - - - log_message('debug', 'Scaffolding Class Initialized'); - } - - // -------------------------------------------------------------------- - - /** - * "Add" Page - * - * Shows a form representing the currently selected DB - * so that data can be inserted - * - * @access public - * @return string the HTML "add" page - */ - function add() - { - $data = array( - 'title' => ( ! isset($this->lang['scaff_add'])) ? 'Add Data' : $this->lang['scaff_add'], - 'fields' => $this->CI->db->field_data($this->current_table), - 'action' => $this->base_uri.'/insert' - ); - - $this->CI->load->view('add', $data); - } - - // -------------------------------------------------------------------- - - /** - * Insert the data - * - * @access public - * @return void redirects to the view page - */ - function insert() - { - if ($this->CI->db->insert($this->current_table, $_POST) === FALSE) - { - $this->add(); - } - else - { - redirect($this->base_uri.'/view/'); - } - } - - // -------------------------------------------------------------------- - - /** - * "View" Page - * - * Shows a table containing the data in the currently - * selected DB - * - * @access public - * @return string the HTML "view" page - */ - function view() - { - // Fetch the total number of DB rows - $total_rows = $this->CI->db->count_all($this->current_table); - - if ($total_rows < 1) - { - return $this->CI->load->view('no_data'); - } - - // Set the query limit/offset - $per_page = 20; - $offset = $this->CI->uri->segment(4, 0); - - // Run the query - $query = $this->CI->db->get($this->current_table, $per_page, $offset); - - // Now let's get the field names - $fields = $this->CI->db->list_fields($this->current_table); - - // We assume that the column in the first position is the primary field. - $primary = current($fields); - - // Pagination! - $this->CI->pagination->initialize( - array( - 'base_url' => $this->base_url.'/view', - 'total_rows' => $total_rows, - 'per_page' => $per_page, - 'uri_segment' => 4, - 'full_tag_open' => '

    ', - 'full_tag_close' => '

    ' - ) - ); - - $data = array( - 'title' => ( ! isset($this->lang['scaff_view'])) ? 'View Data' : $this->lang['scaff_view'], - 'query' => $query, - 'fields' => $fields, - 'primary' => $primary, - 'paginate' => $this->CI->pagination->create_links() - ); - - $this->CI->load->view('view', $data); - } - - // -------------------------------------------------------------------- - - /** - * "Edit" Page - * - * Shows a form representing the currently selected DB - * so that data can be edited - * - * @access public - * @return string the HTML "edit" page - */ - function edit() - { - if (FALSE === ($id = $this->CI->uri->segment(4))) - { - return $this->view(); - } - - // Fetch the primary field name - $primary = $this->CI->db->primary($this->current_table); - - // Run the query - $query = $this->CI->db->get_where($this->current_table, array($primary => $id)); - - $data = array( - 'title' => ( ! isset($this->lang['scaff_edit'])) ? 'Edit Data' : $this->lang['scaff_edit'], - 'fields' => $query->field_data(), - 'query' => $query->row(), - 'action' => $this->base_uri.'/update/'.$this->CI->uri->segment(4) - ); - - $this->CI->load->view('edit', $data); - } - - // -------------------------------------------------------------------- - - /** - * Update - * - * @access public - * @return void redirects to the view page - */ - function update() - { - // Fetch the primary key - $primary = $this->CI->db->primary($this->current_table); - - // Now do the query - $this->CI->db->update($this->current_table, $_POST, array($primary => $this->CI->uri->segment(4))); - - redirect($this->base_uri.'/view/'); - } - - // -------------------------------------------------------------------- - - /** - * Delete Confirmation - * - * @access public - * @return string the HTML "delete confirm" page - */ - function delete() - { - if ( ! isset($this->lang['scaff_del_confirm'])) - { - $message = 'Are you sure you want to delete the following row: '.$this->CI->uri->segment(4); - } - else - { - $message = $this->lang['scaff_del_confirm'].' '.$this->CI->uri->segment(4); - } - - $data = array( - 'title' => ( ! isset($this->lang['scaff_delete'])) ? 'Delete Data' : $this->lang['scaff_delete'], - 'message' => $message, - 'no' => anchor(array($this->base_uri, 'view'), ( ! isset($this->lang['scaff_no'])) ? 'No' : $this->lang['scaff_no']), - 'yes' => anchor(array($this->base_uri, 'do_delete', $this->CI->uri->segment(4)), ( ! isset($this->lang['scaff_yes'])) ? 'Yes' : $this->lang['scaff_yes']) - ); - - $this->CI->load->view('delete', $data); - } - - // -------------------------------------------------------------------- - - /** - * Delete - * - * @access public - * @return void redirects to the view page - */ - function do_delete() - { - // Fetch the primary key - $primary = $this->CI->db->primary($this->current_table); - - // Now do the query - $this->CI->db->where($primary, $this->CI->uri->segment(4)); - $this->CI->db->delete($this->current_table); - - header("Refresh:0;url=".site_url(array($this->base_uri, 'view'))); - exit; - } - -} - -/* End of file Scaffolding.php */ +CI =& get_instance(); + + $this->CI->load->database("", FALSE, TRUE); + $this->CI->load->library('pagination'); + + // Turn off caching + $this->CI->db->cache_off(); + + /** + * Set the current table name + * This is done when initializing scaffolding: + * $this->load->scaffolding('table_name') + * + */ + $this->current_table = $db_table; + + /** + * Set the path to the "view" files + * We'll manually override the "view" path so that + * the load->view function knows where to look. + */ + + $this->CI->load->_ci_view_path = BASEPATH.'scaffolding/views/'; + + // Set the base URL + $this->base_url = $this->CI->config->site_url().'/'.$this->CI->uri->segment(1).$this->CI->uri->slash_segment(2, 'both'); + $this->base_uri = $this->CI->uri->segment(1).$this->CI->uri->slash_segment(2, 'leading'); + + // Set a few globals + $data = array( + 'image_url' => $this->CI->config->system_url().'scaffolding/images/', + 'base_uri' => $this->base_uri, + 'base_url' => $this->base_url, + 'title' => $this->current_table + ); + + $this->CI->load->vars($data); + + // Load the language file and create variables + $this->lang = $this->CI->load->scaffold_language('scaffolding', '', TRUE); + $this->CI->load->vars($this->lang); + + // Load the helper files we plan to use + $this->CI->load->helper(array('url', 'form')); + + + log_message('debug', 'Scaffolding Class Initialized'); + } + + // -------------------------------------------------------------------- + + /** + * "Add" Page + * + * Shows a form representing the currently selected DB + * so that data can be inserted + * + * @access public + * @return string the HTML "add" page + */ + function add() + { + $data = array( + 'title' => ( ! isset($this->lang['scaff_add'])) ? 'Add Data' : $this->lang['scaff_add'], + 'fields' => $this->CI->db->field_data($this->current_table), + 'action' => $this->base_uri.'/insert' + ); + + $this->CI->load->view('add', $data); + } + + // -------------------------------------------------------------------- + + /** + * Insert the data + * + * @access public + * @return void redirects to the view page + */ + function insert() + { + if ($this->CI->db->insert($this->current_table, $_POST) === FALSE) + { + $this->add(); + } + else + { + redirect($this->base_uri.'/view/'); + } + } + + // -------------------------------------------------------------------- + + /** + * "View" Page + * + * Shows a table containing the data in the currently + * selected DB + * + * @access public + * @return string the HTML "view" page + */ + function view() + { + // Fetch the total number of DB rows + $total_rows = $this->CI->db->count_all($this->current_table); + + if ($total_rows < 1) + { + return $this->CI->load->view('no_data'); + } + + // Set the query limit/offset + $per_page = 20; + $offset = $this->CI->uri->segment(4, 0); + + // Run the query + $query = $this->CI->db->get($this->current_table, $per_page, $offset); + + // Now let's get the field names + $fields = $this->CI->db->list_fields($this->current_table); + + // We assume that the column in the first position is the primary field. + $primary = current($fields); + + // Pagination! + $this->CI->pagination->initialize( + array( + 'base_url' => $this->base_url.'/view', + 'total_rows' => $total_rows, + 'per_page' => $per_page, + 'uri_segment' => 4, + 'full_tag_open' => '

    ', + 'full_tag_close' => '

    ' + ) + ); + + $data = array( + 'title' => ( ! isset($this->lang['scaff_view'])) ? 'View Data' : $this->lang['scaff_view'], + 'query' => $query, + 'fields' => $fields, + 'primary' => $primary, + 'paginate' => $this->CI->pagination->create_links() + ); + + $this->CI->load->view('view', $data); + } + + // -------------------------------------------------------------------- + + /** + * "Edit" Page + * + * Shows a form representing the currently selected DB + * so that data can be edited + * + * @access public + * @return string the HTML "edit" page + */ + function edit() + { + if (FALSE === ($id = $this->CI->uri->segment(4))) + { + return $this->view(); + } + + // Fetch the primary field name + $primary = $this->CI->db->primary($this->current_table); + + // Run the query + $query = $this->CI->db->get_where($this->current_table, array($primary => $id)); + + $data = array( + 'title' => ( ! isset($this->lang['scaff_edit'])) ? 'Edit Data' : $this->lang['scaff_edit'], + 'fields' => $query->field_data(), + 'query' => $query->row(), + 'action' => $this->base_uri.'/update/'.$this->CI->uri->segment(4) + ); + + $this->CI->load->view('edit', $data); + } + + // -------------------------------------------------------------------- + + /** + * Update + * + * @access public + * @return void redirects to the view page + */ + function update() + { + // Fetch the primary key + $primary = $this->CI->db->primary($this->current_table); + + // Now do the query + $this->CI->db->update($this->current_table, $_POST, array($primary => $this->CI->uri->segment(4))); + + redirect($this->base_uri.'/view/'); + } + + // -------------------------------------------------------------------- + + /** + * Delete Confirmation + * + * @access public + * @return string the HTML "delete confirm" page + */ + function delete() + { + if ( ! isset($this->lang['scaff_del_confirm'])) + { + $message = 'Are you sure you want to delete the following row: '.$this->CI->uri->segment(4); + } + else + { + $message = $this->lang['scaff_del_confirm'].' '.$this->CI->uri->segment(4); + } + + $data = array( + 'title' => ( ! isset($this->lang['scaff_delete'])) ? 'Delete Data' : $this->lang['scaff_delete'], + 'message' => $message, + 'no' => anchor(array($this->base_uri, 'view'), ( ! isset($this->lang['scaff_no'])) ? 'No' : $this->lang['scaff_no']), + 'yes' => anchor(array($this->base_uri, 'do_delete', $this->CI->uri->segment(4)), ( ! isset($this->lang['scaff_yes'])) ? 'Yes' : $this->lang['scaff_yes']) + ); + + $this->CI->load->view('delete', $data); + } + + // -------------------------------------------------------------------- + + /** + * Delete + * + * @access public + * @return void redirects to the view page + */ + function do_delete() + { + // Fetch the primary key + $primary = $this->CI->db->primary($this->current_table); + + // Now do the query + $this->CI->db->where($primary, $this->CI->uri->segment(4)); + $this->CI->db->delete($this->current_table); + + header("Refresh:0;url=".site_url(array($this->base_uri, 'view'))); + exit; + } + +} + +/* End of file Scaffolding.php */ /* Location: ./system/scaffolding/Scaffolding.php */ \ No newline at end of file diff --git a/system/scaffolding/images/index.html b/system/scaffolding/images/index.html index 065d2da5e..c942a79ce 100644 --- a/system/scaffolding/images/index.html +++ b/system/scaffolding/images/index.html @@ -1,10 +1,10 @@ - - - 403 Forbidden - - - -

    Directory access is forbidden.

    - - + + + 403 Forbidden + + + +

    Directory access is forbidden.

    + + \ No newline at end of file diff --git a/system/scaffolding/index.html b/system/scaffolding/index.html index 065d2da5e..c942a79ce 100644 --- a/system/scaffolding/index.html +++ b/system/scaffolding/index.html @@ -1,10 +1,10 @@ - - - 403 Forbidden - - - -

    Directory access is forbidden.

    - - + + + 403 Forbidden + + + +

    Directory access is forbidden.

    + + \ No newline at end of file diff --git a/system/scaffolding/views/add.php b/system/scaffolding/views/add.php index cac255acf..cbb12f6fb 100644 --- a/system/scaffolding/views/add.php +++ b/system/scaffolding/views/add.php @@ -1,32 +1,32 @@ -load->view('header'); ?> - -

    - - - - - - - -primary_key == 1) continue; ?> - - - - - type == 'blob'): ?> - - - - - - - -
    name; echo ' '.$field->default; ?>
    - - - - - -load->view('footer'); -/* End of file add.php */ -/* Location: ./system/scaffolding/views/add.php */ +load->view('header'); ?> + +

    + + + + + + + +primary_key == 1) continue; ?> + + + + + type == 'blob'): ?> + + + + + + + +
    name; echo ' '.$field->default; ?>
    + + + + + +load->view('footer'); +/* End of file add.php */ +/* Location: ./system/scaffolding/views/add.php */ diff --git a/system/scaffolding/views/delete.php b/system/scaffolding/views/delete.php index 87b59bef9..d19542195 100644 --- a/system/scaffolding/views/delete.php +++ b/system/scaffolding/views/delete.php @@ -1,9 +1,9 @@ -load->view('header'); ?> - -

    - -

      |   - -load->view('footer'); -/* End of file delete.php */ -/* Location: ./system/scaffolding/views/delete.php */ +load->view('header'); ?> + +

    + +

      |   + +load->view('footer'); +/* End of file delete.php */ +/* Location: ./system/scaffolding/views/delete.php */ diff --git a/system/scaffolding/views/edit.php b/system/scaffolding/views/edit.php index c66259d90..fe553e591 100644 --- a/system/scaffolding/views/edit.php +++ b/system/scaffolding/views/edit.php @@ -1,33 +1,33 @@ -load->view('header'); ?> - - -

    - - - - - - - -primary_key == 1) continue; ?> - - - - - type == 'blob'): ?> - - - - - - - -
    name; ?>
    - - - - - -load->view('footer'); -/* End of file edit.php */ +load->view('header'); ?> + + +

    + + + + + + + +primary_key == 1) continue; ?> + + + + + type == 'blob'): ?> + + + + + + + +
    name; ?>
    + + + + + +load->view('footer'); +/* End of file edit.php */ /* Location: ./system/scaffolding/views/edit.php */ \ No newline at end of file diff --git a/system/scaffolding/views/footer.php b/system/scaffolding/views/footer.php index a287664f1..0e71401c9 100644 --- a/system/scaffolding/views/footer.php +++ b/system/scaffolding/views/footer.php @@ -1,10 +1,10 @@ - -
    - - - - + +
    + + + + \ No newline at end of file diff --git a/system/scaffolding/views/header.php b/system/scaffolding/views/header.php index a1621ff3c..50f234a49 100644 --- a/system/scaffolding/views/header.php +++ b/system/scaffolding/views/header.php @@ -1,29 +1,29 @@ - - - - -<?php echo $title; ?> - - - - - - - - - - - - -
    + + + + +<?php echo $title; ?> + + + + + + + + + + + + +
    \ No newline at end of file diff --git a/system/scaffolding/views/index.html b/system/scaffolding/views/index.html index 065d2da5e..c942a79ce 100644 --- a/system/scaffolding/views/index.html +++ b/system/scaffolding/views/index.html @@ -1,10 +1,10 @@ - - - 403 Forbidden - - - -

    Directory access is forbidden.

    - - + + + 403 Forbidden + + + +

    Directory access is forbidden.

    + + \ No newline at end of file diff --git a/system/scaffolding/views/no_data.php b/system/scaffolding/views/no_data.php index 963341b70..bc81e7480 100644 --- a/system/scaffolding/views/no_data.php +++ b/system/scaffolding/views/no_data.php @@ -1,8 +1,8 @@ -load->view('header'); ?> - -

    -

    - -load->view('footer'); -/* End of file no_data.php */ +load->view('header'); ?> + +

    +

    + +load->view('footer'); +/* End of file no_data.php */ /* Location: ./system/scaffolding/views/no_data.php */ \ No newline at end of file diff --git a/system/scaffolding/views/stylesheet.css b/system/scaffolding/views/stylesheet.css index ba6ee0a2f..3f487dd0b 100644 --- a/system/scaffolding/views/stylesheet.css +++ b/system/scaffolding/views/stylesheet.css @@ -1,143 +1,143 @@ -body { - margin: 0; - padding: 0; - font-family: Lucida Grande, Verdana, Geneva, Sans-serif; - font-size: 11px; - color: #4F5155; - background: #fff url(background.jpg) repeat-x left top; -} - -a { - color: #8B0D00; - background-color: transparent; - text-decoration: none; - font-weight: bold; -} - -a:visited { - color: #8B0D00; - background-color: transparent; - text-decoration: none; -} - -a:hover { - color: #000; - text-decoration: none; - background-color: transparent; -} - - -#header { - margin: 0; - padding: 0; -} - -#header_left { - background-color: transparent; - float: left; - padding: 21px 0 0 32px; - margin: 0 -} - -#header_right { - background-color: transparent; - float: right; - text-align: right; - padding: 35px 50px 20px 0; - margin: 0 -} - -#footer { - margin: 20px 0 15px 0; - padding: 0; -} - -#footer p { - font-size: 10px; - color: #999; - text-align: center; -} - -#outer { - margin: 30px 40px 0 40px; -} - -img { - padding:0; - border: 0; - margin: 0; -} - -.nopad { - padding:0; - border: 0; - margin: 0; -} - -table { - background-color: #efefef; -} - -th { - background-color: #eee; - font-weight: bold; - padding: 6px; - text-align: left; -} - -td { - background-color: #fff; - padding: 6px; -} - - -form { - margin: 0; - padding: 0; -} - -.input { - font-family: Lucida Grande, Verdana, Geneva, Sans-serif; - font-size: 11px; - width: 600px; - color: #333; - border: 1px solid #B3B4BD; - font-size: 11px; - height: 2em; - padding: 0; - margin: 0; -} - -.textarea { - font-family: Lucida Grande, Verdana, Geneva, Sans-serif; - font-size: 12px; - width: 600px; - color: #333; - border: 1px solid #B3B4BD; - padding: 0; - margin: 0; -} - -.select { - background-color: #fff; - font-size: 11px; - font-weight: normal; - color: #333; - padding: 0; - margin: 0 0 3px 0; -} - -.checkbox { - background-color: transparent; - padding: 0; - border: 0; -} - -.submit { - background-color: #8B0D00; - color: #FFF; - font-weight: normal; - border: 1px solid #000; - margin: 6px 0 0 0; - padding: 1px 5px 1px 5px; -} +body { + margin: 0; + padding: 0; + font-family: Lucida Grande, Verdana, Geneva, Sans-serif; + font-size: 11px; + color: #4F5155; + background: #fff url(background.jpg) repeat-x left top; +} + +a { + color: #8B0D00; + background-color: transparent; + text-decoration: none; + font-weight: bold; +} + +a:visited { + color: #8B0D00; + background-color: transparent; + text-decoration: none; +} + +a:hover { + color: #000; + text-decoration: none; + background-color: transparent; +} + + +#header { + margin: 0; + padding: 0; +} + +#header_left { + background-color: transparent; + float: left; + padding: 21px 0 0 32px; + margin: 0 +} + +#header_right { + background-color: transparent; + float: right; + text-align: right; + padding: 35px 50px 20px 0; + margin: 0 +} + +#footer { + margin: 20px 0 15px 0; + padding: 0; +} + +#footer p { + font-size: 10px; + color: #999; + text-align: center; +} + +#outer { + margin: 30px 40px 0 40px; +} + +img { + padding:0; + border: 0; + margin: 0; +} + +.nopad { + padding:0; + border: 0; + margin: 0; +} + +table { + background-color: #efefef; +} + +th { + background-color: #eee; + font-weight: bold; + padding: 6px; + text-align: left; +} + +td { + background-color: #fff; + padding: 6px; +} + + +form { + margin: 0; + padding: 0; +} + +.input { + font-family: Lucida Grande, Verdana, Geneva, Sans-serif; + font-size: 11px; + width: 600px; + color: #333; + border: 1px solid #B3B4BD; + font-size: 11px; + height: 2em; + padding: 0; + margin: 0; +} + +.textarea { + font-family: Lucida Grande, Verdana, Geneva, Sans-serif; + font-size: 12px; + width: 600px; + color: #333; + border: 1px solid #B3B4BD; + padding: 0; + margin: 0; +} + +.select { + background-color: #fff; + font-size: 11px; + font-weight: normal; + color: #333; + padding: 0; + margin: 0 0 3px 0; +} + +.checkbox { + background-color: transparent; + padding: 0; + border: 0; +} + +.submit { + background-color: #8B0D00; + color: #FFF; + font-weight: normal; + border: 1px solid #000; + margin: 6px 0 0 0; + padding: 1px 5px 1px 5px; +} diff --git a/system/scaffolding/views/view.php b/system/scaffolding/views/view.php index 69c1f45d8..a81241d39 100644 --- a/system/scaffolding/views/view.php +++ b/system/scaffolding/views/view.php @@ -1,27 +1,27 @@ -load->view('header'); ?> - - - - - - - - - - -result() as $row): ?> - - - - - - - - -
    EditDelete
     $primary), $scaff_edit); ?> $primary), $scaff_delete); ?>$field);?>
    - - - -load->view('footer'); -/* End of file view.php */ +load->view('header'); ?> + + + + + + + + + + +result() as $row): ?> + + + + + + + + +
    EditDelete
     $primary), $scaff_edit); ?> $primary), $scaff_delete); ?>$field);?>
    + + + +load->view('footer'); +/* End of file view.php */ /* Location: ./system/scaffolding/views/view.php */ \ No newline at end of file -- cgit v1.2.3-24-g4f1b From d5738d9fcafa831be8a1e709e42fdafb70d4330f Mon Sep 17 00:00:00 2001 From: Derek Jones Date: Fri, 14 Nov 2008 16:53:34 +0000 Subject: added some block level tag tracking so we can add inner block level elements when required --- system/libraries/Typography.php | 82 +++++++++++++---------------------------- 1 file changed, 25 insertions(+), 57 deletions(-) (limited to 'system') diff --git a/system/libraries/Typography.php b/system/libraries/Typography.php index 29b871e23..0502eef1e 100644 --- a/system/libraries/Typography.php +++ b/system/libraries/Typography.php @@ -34,7 +34,13 @@ class CI_Typography { // 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; @@ -80,7 +86,7 @@ class CI_Typography { if ($reduce_linebreaks === TRUE) { $str = preg_replace("/\n\n+/", "\n\n", $str); - } + } // Convert quotes within tags to temporary markers. We don't want quotes converted // within tags so we'll temporarily convert them to {@DQ} and {@SQ} @@ -133,37 +139,30 @@ class CI_Typography { { // Are we dealing with a tag? If so, we'll skip the processing for this cycle. // Well also set the "process" flag which allows us to skip
     tags and a few other things.
    -			if (preg_match("#<(/*)(".$this->block_elements.").*?>#", $chunk, $match))
    +			if (preg_match("#<(/*)(".$this->block_elements.").*?\>#", $chunk, $match))
     			{
     				if (preg_match("#".$this->skip_elements."#", $match[2]))
     				{
     					$process =  ($match[1] == '/') ? TRUE : FALSE;
     				}
     				
    -				$str .= $chunk;
    -				continue;
    -			}
    -			elseif (preg_match('/<(\/?)([a-z]*).*?>/s', $chunk, $tagmatch))
    -			{
    -				if ($tagmatch[1] == '/' && $tagmatch[2] == $this->last_tag)
    +				if ($match[1] == '')
     				{
    -					$process = FALSE;
    +					$this->last_block_element = $match[2];
     				}
    -				else
    -				{
    -					$process = TRUE;
    -					$this->last_tag = $tagmatch[2];					
    -				}
    -			}
     
    +				$str .= $chunk;
    +				continue;
    +			}
    +			
     			if ($process == FALSE)
     			{
     				$str .= $chunk;
     				continue;
     			}
    -			
    +
     			//  Convert Newlines into 

    and
    tags - $str .= $this->format_characters($this->_format_newlines($chunk)); + $str .= $this->_format_newlines($chunk); } // is the whole of the content inside a block level element? @@ -171,20 +170,16 @@ class CI_Typography { { $str = "

    {$str}

    "; } - - - // some special linebreak cleanup - $str = preg_replace_callback('#<(?!/|'.$this->block_elements.')([^>]*)>

    (.*?)

    <(\w*)#si', array($this, '_linebreak_cleanup'), $str); - - // and cleanup empty paragraph tags sitting between two closing tags - $str = preg_replace('#()

    (\s*)

    ()#si', '$1$2$3', $str); + // Convert quotes, elipsis, and em-dashes + $str = $this->format_characters($str); + // Final clean up $table = array( // If the user submitted their own paragraph tags within the text // we will retain them instead of using our tags. - '/(*?]>)

    /' => '$1', // *?]>)

    /' => '$1', // )+#' => '

    ', @@ -192,13 +187,10 @@ class CI_Typography { // Clean up stray paragraph tags that appear before block level elements '#

    <('.$this->block_elements.')#' => '<$1', - - // Clean up open paragraph tags that appear before block level elements - '#

    (\W)<('.$this->block_elements.')#' => '

    $1<$2', // Clean up stray non-breaking spaces preceeding block elements '#[  ]+<('.$this->block_elements.')#' => ' <$1', - + // Replace the temporary markers we added earlier '/\{@TAG\}/' => '<', '/\{@DQ\}/' => '"', @@ -207,7 +199,7 @@ class CI_Typography { '/\{@NBS\}/' => ' ' ); - + // Do we need to reduce empty lines? if ($reduce_linebreaks === TRUE) { @@ -226,30 +218,6 @@ class CI_Typography { // -------------------------------------------------------------------- - /** - * Linebreak Cleanup - * - * Removes paragraph and line break tags inserted inbetween - * inline content and a new opening block level element - * - * @access private - * @param array - * @return string - */ - function _linebreak_cleanup($match) - { - if (in_array($match[3], explode('|', $this->block_elements))) - { - return "<{$match[1]}>".str_replace('
    ', '', $match[2])."<{$match[3]}"; - } - else - { - return $match[0]; - } - } - - // -------------------------------------------------------------------- - /** * Format Characters * @@ -320,8 +288,8 @@ class CI_Typography { { return $str; } - - if (strpos($str, "\n") === FALSE) + + if (strpos($str, "\n") === FALSE && ! in_array($this->last_block_element, $this->inner_block_required)) { return $str; } -- cgit v1.2.3-24-g4f1b From 89cd0a752fd6f165f06a345bb04ce45529c618fc Mon Sep 17 00:00:00 2001 From: Derek Jones Date: Fri, 14 Nov 2008 17:12:14 +0000 Subject: switched order of parsing opening and closing curly quotes for greater accuracy --- system/libraries/Typography.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'system') diff --git a/system/libraries/Typography.php b/system/libraries/Typography.php index 0502eef1e..808a76953 100644 --- a/system/libraries/Typography.php +++ b/system/libraries/Typography.php @@ -246,13 +246,13 @@ class CI_Typography { '/"\'(\s|\W|$)/' => '”’$1', // single quote smart quotes - '/\'(\s|\W|$)/' => '’$1', '/(^|\W|\s)\'/' => '$1‘', + '/\'(\s|\W|$)/' => '’$1', // double quote smart quotes - '/"(\s|\W|$)/' => '”$1', '/(^|\W|\s)"/' => '$1“', - + '/"(\s|\W|$)/' => '”$1', + // apostrophes "/(\w)'(\w)/" => '$1’$2', -- cgit v1.2.3-24-g4f1b From c630bcfca816f625b8cd70a1a7467a77c8065bbd Mon Sep 17 00:00:00 2001 From: Derek Jones Date: Mon, 17 Nov 2008 21:09:45 +0000 Subject: added sendmail debugging and fixed a bug with single to double quoted string syntax in from() --- system/libraries/Email.php | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) (limited to 'system') diff --git a/system/libraries/Email.php b/system/libraries/Email.php index 94f517c45..89d0976ae 100644 --- a/system/libraries/Email.php +++ b/system/libraries/Email.php @@ -189,7 +189,7 @@ class CI_Email { 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"\\').'"'; + $name = '"'.addcslashes($name, "\0..\37\177'\"\\").'"'; } else { @@ -1539,16 +1539,22 @@ class CI_Email { { $fp = @popen($this->mailpath . " -oi -f ".$this->clean_email($this->_headers['From'])." -t", 'w'); - if ( ! is_resource($fp)) + fputs($fp, $this->_header_str); + fputs($fp, $this->_finalbody); + + $status = pclose($fp); + + if (version_compare(PHP_VERSION, '4.2.3') == -1) + { + $status = $status >> 8 & 0xFF; + } + + if ($status == 0) { $this->_set_error_message('email_no_socket'); return FALSE; } - fputs($fp, $this->_header_str); - fputs($fp, $this->_finalbody); - pclose($fp) >> 8 & 0xFF; - return TRUE; } -- cgit v1.2.3-24-g4f1b From b859df894145b8a41609958917cf394fc46b8b10 Mon Sep 17 00:00:00 2001 From: Derek Jones Date: Tue, 18 Nov 2008 15:24:20 +0000 Subject: Smart curly quotes! Spaces trump all, then worry about \W, you can't convert them all at once or either your opening or your ending (whichever you process first) is going to be too greedy. --- system/libraries/Typography.php | 37 ++++++++++++++++++++++++------------- 1 file changed, 24 insertions(+), 13 deletions(-) (limited to 'system') diff --git a/system/libraries/Typography.php b/system/libraries/Typography.php index 808a76953..27fa42192 100644 --- a/system/libraries/Typography.php +++ b/system/libraries/Typography.php @@ -235,26 +235,37 @@ class CI_Typography { if ( ! isset($table)) { - $table = array( + $table = array( // nested smart quotes, opening and closing // note that rules for grammar (English) allow only for two levels deep // and that single quotes are _supposed_ to always be on the outside // but we'll accommodate both - '/(^|\W|\s)\'"/' => '$1‘“', - '/\'"(\s|\W|$)/' => '’”$1', - '/(^|\W|\s)"\'/' => '$1“‘', - '/"\'(\s|\W|$)/' => '”’$1', + // Note that in all cases, whitespace is the primary determining factor + // on which direction to curl, with non-word characters like punctuation + // being a secondary factor only after whitespace is addressed. + '/\'"(\s|$)/' => '’”$1', + '/(^|\s)\'"/' => '$1‘“', + '/\'"(\W)/' => '’”$1', + '/(\W)\'"/' => '$1‘“', + '/"\'(\s|$)/' => '”’$1', + '/(^|\s)"\'/' => '$1“‘', + '/"\'(\W)/' => '”’$1', + '/(\W)"\'/' => '$1“‘', // single quote smart quotes - '/(^|\W|\s)\'/' => '$1‘', - '/\'(\s|\W|$)/' => '’$1', + '/\'(\s|$)/' => '’$1', + '/(^|\s)\'/' => '$1‘', + '/\'(\W)/' => '’$1', + '/(\W)\'/' => '$1‘', // double quote smart quotes - '/(^|\W|\s)"/' => '$1“', - '/"(\s|\W|$)/' => '”$1', - + '/"(\s|$)/' => '”$1', + '/(^|\s)"/' => '$1“', + '/"(\W)/' => '”$1', + '/(\W)"/' => '$1“', + // apostrophes - "/(\w)'(\w)/" => '$1’$2', + "/(\w)'(\w)/" => '$1’$2', // Em dash and ellipses dots '/\s?\-\-\s?/' => '—', @@ -265,8 +276,8 @@ class CI_Typography { // ampersands, if not a character entity '/&(?!#?[a-zA-Z0-9]{2,};)/' => '&' - ); - } + ); + } return preg_replace(array_keys($table), $table, $str); } -- cgit v1.2.3-24-g4f1b From 604873fe068c39c55afa1deaafaf34a95fd3359e Mon Sep 17 00:00:00 2001 From: Derek Jones Date: Tue, 18 Nov 2008 15:57:24 +0000 Subject: better error messages for sendmail failure --- system/language/english/email_lang.php | 1 + system/libraries/Email.php | 3 ++- 2 files changed, 3 insertions(+), 1 deletion(-) (limited to 'system') diff --git a/system/language/english/email_lang.php b/system/language/english/email_lang.php index 932427787..e3bd113cb 100644 --- a/system/language/english/email_lang.php +++ b/system/language/english/email_lang.php @@ -17,6 +17,7 @@ $lang['email_failed_smtp_login'] = "Failed to send AUTH LOGIN command. Error: %s $lang['email_smtp_auth_un'] = "Failed to authenticate username. Error: %s"; $lang['email_smtp_auth_pw'] = "Failed to authenticate password. Error: %s"; $lang['email_smtp_data_failure'] = "Unable to send data: %s"; +$lang['email_exit_status'] = "Exit status code: %s"; /* End of file email_lang.php */ diff --git a/system/libraries/Email.php b/system/libraries/Email.php index 89d0976ae..99a5ea385 100644 --- a/system/libraries/Email.php +++ b/system/libraries/Email.php @@ -1549,8 +1549,9 @@ class CI_Email { $status = $status >> 8 & 0xFF; } - if ($status == 0) + if ($status != 0) { + $this->_set_error_message('email_exit_status', $status); $this->_set_error_message('email_no_socket'); return FALSE; } -- cgit v1.2.3-24-g4f1b From ef22efd7c7b0a9006d43ef207450768722815453 Mon Sep 17 00:00:00 2001 From: Derek Allard Date: Thu, 20 Nov 2008 15:25:45 +0000 Subject: Added where_in to the list of expected arguments received by delete() --- system/database/DB_active_rec.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system') diff --git a/system/database/DB_active_rec.php b/system/database/DB_active_rec.php index e8cefa2db..b8dce6df5 100644 --- a/system/database/DB_active_rec.php +++ b/system/database/DB_active_rec.php @@ -1374,7 +1374,7 @@ class CI_DB_active_record extends CI_DB_driver { $this->limit($limit); } - if (count($this->ar_where) == 0 && count($this->ar_like) == 0) + if (count($this->ar_where) == 0 && count($this->ar_wherein) == 0 && count($this->ar_like)) { if ($this->db_debug) { -- cgit v1.2.3-24-g4f1b From d9c7f031cf525229238c1f8ab02a44436ee2c32e Mon Sep 17 00:00:00 2001 From: Derek Allard Date: Mon, 1 Dec 2008 20:18:00 +0000 Subject: Removed a strict type check from the rotate() function of the Image Manipulation Class. --- system/libraries/Image_lib.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system') diff --git a/system/libraries/Image_lib.php b/system/libraries/Image_lib.php index 16201ee9e..1b2d33de8 100644 --- a/system/libraries/Image_lib.php +++ b/system/libraries/Image_lib.php @@ -397,7 +397,7 @@ class CI_Image_lib { // Allowed rotation values $degs = array(90, 180, 270, 'vrt', 'hor'); - if ($this->rotation_angle == '' OR ! in_array($this->rotation_angle, $degs, TRUE)) + if ($this->rotation_angle == '' OR ! in_array($this->rotation_angle, $degs)) { $this->set_error('imglib_rotation_angle_required'); return FALSE; -- cgit v1.2.3-24-g4f1b From ab0e31f09a8cf3596e6547fc47fd085a0d2bcdd0 Mon Sep 17 00:00:00 2001 From: Derek Jones Date: Fri, 5 Dec 2008 22:03:47 +0000 Subject: fixed a bug where whitespace would be lost if a string was forced into a character entity e.g. &foo you know? would become &foo;you know? instead of &foo; you know? --- system/libraries/Input.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system') diff --git a/system/libraries/Input.php b/system/libraries/Input.php index f26df7552..347aac3ac 100644 --- a/system/libraries/Input.php +++ b/system/libraries/Input.php @@ -555,7 +555,7 @@ class CI_Input { * the conversion of entities to ASCII later. * */ - $str = preg_replace('#(&\#?[0-9a-z]{2,})[\x00-\x20]*;?#i', "\\1;", $str); + $str = preg_replace('#(&\#?[0-9a-z]{2,})([\x00-\x20])*;?#i', "\\1;\\2", $str); /* * Validate UTF16 two byte encoding (x00) -- cgit v1.2.3-24-g4f1b From 541ddbd6f3c0231f0e7fc0a18d9d54670a808958 Mon Sep 17 00:00:00 2001 From: Derek Jones Date: Tue, 9 Dec 2008 15:25:31 +0000 Subject: added some better error checking for saving files with GD --- system/language/english/imglib_lang.php | 1 + system/libraries/Image_lib.php | 18 +++++++++++++++--- 2 files changed, 16 insertions(+), 3 deletions(-) (limited to 'system') diff --git a/system/language/english/imglib_lang.php b/system/language/english/imglib_lang.php index a587c0b9e..66505da07 100644 --- a/system/language/english/imglib_lang.php +++ b/system/language/english/imglib_lang.php @@ -17,6 +17,7 @@ $lang['imglib_writing_failed_gif'] = "GIF image."; $lang['imglib_invalid_path'] = "The path to the image is not correct."; $lang['imglib_copy_failed'] = "The image copy routine failed."; $lang['imglib_missing_font'] = "Unable to find a font to use."; +$lang['imglib_save_failed'] = "Unable to save the image. Please make sure the image and file directory are writable."; /* End of file imglib_lang.php */ diff --git a/system/libraries/Image_lib.php b/system/libraries/Image_lib.php index 1b2d33de8..0e7f21435 100644 --- a/system/libraries/Image_lib.php +++ b/system/libraries/Image_lib.php @@ -1195,7 +1195,11 @@ class CI_Image_lib { return FALSE; } - @imagegif($resource, $this->full_dst_path); + if ( ! @imagegif($resource, $this->full_dst_path)) + { + $this->set_error('imglib_save_failed'); + return FALSE; + } break; case 2 : if ( ! function_exists('imagejpeg')) @@ -1209,7 +1213,11 @@ class CI_Image_lib { @touch($this->full_dst_path); // PHP 4.4.1 bug #35060 - workaround } - @imagejpeg($resource, $this->full_dst_path, $this->quality); + if ( ! @imagejpeg($resource, $this->full_dst_path, $this->quality)) + { + $this->set_error('imglib_save_failed'); + return FALSE; + } break; case 3 : if ( ! function_exists('imagepng')) @@ -1218,7 +1226,11 @@ class CI_Image_lib { return FALSE; } - @imagepng($resource, $this->full_dst_path); + if ( ! @imagepng($resource, $this->full_dst_path)) + { + $this->set_error('imglib_save_failed'); + return FALSE; + } break; default : $this->set_error(array('imglib_unsupported_imagecreate')); -- cgit v1.2.3-24-g4f1b From 40a2fc8ab781130761237a29455718d24cb23821 Mon Sep 17 00:00:00 2001 From: Derek Jones Date: Tue, 9 Dec 2008 19:41:25 +0000 Subject: added $lowercase parameter to url_title() to allow forced lowercase --- system/helpers/url_helper.php | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'system') diff --git a/system/helpers/url_helper.php b/system/helpers/url_helper.php index fd13dc2d4..9b449ea9e 100644 --- a/system/helpers/url_helper.php +++ b/system/helpers/url_helper.php @@ -471,7 +471,7 @@ if ( ! function_exists('prep_url')) */ if ( ! function_exists('url_title')) { - function url_title($str, $separator = 'dash') + function url_title($str, $separator = 'dash', $lowercase = FALSE) { if ($separator == 'dash') { @@ -501,6 +501,11 @@ if ( ! function_exists('url_title')) $str = preg_replace("#".$key."#i", $val, $str); } + if ($lowercase === TRUE) + { + $str = strtolower($str); + } + return trim(stripslashes($str)); } } -- cgit v1.2.3-24-g4f1b From a633ec293e9647aaca615a829171d641fbac9035 Mon Sep 17 00:00:00 2001 From: Derek Jones Date: Thu, 11 Dec 2008 14:31:33 +0000 Subject: various typography bugs, HTML comment parsing,
     parsing, more
     accurate block matching, etc.
    
    ---
     system/libraries/Typography.php | 41 +++++++++++++++++++++++++++++------------
     1 file changed, 29 insertions(+), 12 deletions(-)
    
    (limited to 'system')
    
    diff --git a/system/libraries/Typography.php b/system/libraries/Typography.php
    index 27fa42192..fa1ec1999 100644
    --- a/system/libraries/Typography.php
    +++ b/system/libraries/Typography.php
    @@ -88,11 +88,25 @@ class CI_Typography {
     			$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, ' '.$page);
    -		echo $this->show_error($heading, $message, 'error_404');
    +		echo $this->show_error($heading, $message, 'error_404', 404);
     		exit;
     	}
       	
    -- 
    cgit v1.2.3-24-g4f1b
    
    
    From a14ab128263c4fe107f0412f659e96843a63cf30 Mon Sep 17 00:00:00 2001
    From: Derek Allard 
    Date: Mon, 13 Jul 2009 12:01:01 +0000
    Subject: spelling in code comment
    
    ---
     system/libraries/Ftp.php | 6 +++---
     1 file changed, 3 insertions(+), 3 deletions(-)
    
    (limited to 'system')
    
    diff --git a/system/libraries/Ftp.php b/system/libraries/Ftp.php
    index 90c65946c..6fb170496 100644
    --- a/system/libraries/Ftp.php
    +++ b/system/libraries/Ftp.php
    @@ -154,13 +154,13 @@ class CI_FTP {
     
     
     	/**
    -	 * Change direcotry
    +	 * Change directory
     	 *
     	 * The second parameter lets us momentarily turn off debugging so that
    -	 * this function can be used to test for the existance of a folder
    +	 * this function can be used to test for the existence of a folder
     	 * without throwing an error.  There's no FTP equivalent to is_dir()
     	 * so we do it by trying to change to a particular directory.
    -	 * Internally, this paramter is only used by the "mirror" function below.
    +	 * Internally, this parameter is only used by the "mirror" function below.
     	 *
     	 * @access	public
     	 * @param	string
    -- 
    cgit v1.2.3-24-g4f1b
    
    
    From 94026d914090861da9c2826508a4597badb86af6 Mon Sep 17 00:00:00 2001
    From: Derek Jones 
    Date: Wed, 15 Jul 2009 15:56:58 +0000
    Subject: added return FALSE if directory_map() cannot read the directory
    
    ---
     system/helpers/directory_helper.php | 4 ++++
     1 file changed, 4 insertions(+)
    
    (limited to 'system')
    
    diff --git a/system/helpers/directory_helper.php b/system/helpers/directory_helper.php
    index b1c497686..a6fb7841e 100644
    --- a/system/helpers/directory_helper.php
    +++ b/system/helpers/directory_helper.php
    @@ -72,6 +72,10 @@ if ( ! function_exists('directory_map'))
     			closedir($fp);
     			return $filedata;
     		}
    +		else
    +		{
    +			return FALSE;
    +		}
     	}
     }
     
    -- 
    cgit v1.2.3-24-g4f1b
    
    
    From 01a9b107cab449d1ce24746612e9cf7074e6608d Mon Sep 17 00:00:00 2001
    From: Derek Jones 
    Date: Fri, 17 Jul 2009 18:30:36 +0000
    Subject: modified Form Helper so that form_prep() keeps track of strings it's
     already processed, to prevent encoding and prep from occurring more than once
    
    ---
     system/helpers/form_helper.php | 31 ++++++++++++++++++++++---------
     1 file changed, 22 insertions(+), 9 deletions(-)
    
    (limited to 'system')
    
    diff --git a/system/helpers/form_helper.php b/system/helpers/form_helper.php
    index 987ff18e2..4c229ae9f 100644
    --- a/system/helpers/form_helper.php
    +++ b/system/helpers/form_helper.php
    @@ -123,7 +123,7 @@ if ( ! function_exists('form_hidden'))
     
     		if ( ! is_array($value))
     		{
    -			$form .= ''."\n";
    +			$form .= ''."\n";
     		}
     		else
     		{
    @@ -239,8 +239,9 @@ if ( ! function_exists('form_textarea'))
     			$val = $data['value']; 
     			unset($data['value']); // textareas don't use the value attribute
     		}
    -
    -		return "";
    +		
    +		$name = (is_array($data)) ? $data['name'] : $data;
    +		return "";
     	}
     }
     
    @@ -264,7 +265,7 @@ if (! function_exists('form_multiselect'))
     		{
     			$extra .= ' multiple="multiple"';
     		}
    -	
    +		
     		return form_dropdown($name, $options, $selected, $extra);
     	}
     }
    @@ -592,8 +593,10 @@ if ( ! function_exists('form_close'))
      */
     if ( ! function_exists('form_prep'))
     {
    -	function form_prep($str = '')
    +	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))
     		{
    @@ -610,11 +613,21 @@ if ( ! function_exists('form_prep'))
     			return '';
     		}
     
    +		if (isset($prepped_fields[$field_name]))
    +		{
    +			return $prepped_fields[$field_name];
    +		}
    +		
     		$str = htmlspecialchars($str);
     
     		// In case htmlspecialchars misses these.
     		$str = str_replace(array("'", '"'), array("'", """), $str);
     
    +		if ($field_name != '')
    +		{
    +			$prepped_fields[$field_name] = $str;
    +		}
    +		
     		return $str;
     	}
     }
    @@ -643,10 +656,10 @@ if ( ! function_exists('set_value'))
     				return $default;
     			}
     
    -			return form_prep($_POST[$field]);
    +			return form_prep($_POST[$field], $field);
     		}
     
    -		return form_prep($OBJ->set_value($field, $default));
    +		return form_prep($OBJ->set_value($field, $default), $field);
     	}
     }
     
    @@ -902,12 +915,12 @@ if ( ! function_exists('_parse_form_attributes'))
     		}
     
     		$att = '';
    -
    +		
     		foreach ($default as $key => $val)
     		{
     			if ($key == 'value')
     			{
    -				$val = form_prep($val);
    +				$val = form_prep($val, $default['name']);
     			}
     
     			$att .= $key . '="' . $val . '" ';
    -- 
    cgit v1.2.3-24-g4f1b
    
    
    From 3eb9faceb9fedb0fa50a2b2d1fc4952c2652af70 Mon Sep 17 00:00:00 2001
    From: Derek Jones 
    Date: Fri, 17 Jul 2009 20:25:13 +0000
    Subject: modification to form_prep() solution.  A bandaid really, to return
     the $str if the field has already been prepped
    
    ---
     system/helpers/form_helper.php | 6 +++++-
     1 file changed, 5 insertions(+), 1 deletion(-)
    
    (limited to 'system')
    
    diff --git a/system/helpers/form_helper.php b/system/helpers/form_helper.php
    index 4c229ae9f..c5e977a40 100644
    --- a/system/helpers/form_helper.php
    +++ b/system/helpers/form_helper.php
    @@ -613,9 +613,13 @@ if ( ! function_exists('form_prep'))
     			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 $prepped_fields[$field_name];
    +			return $str;
     		}
     		
     		$str = htmlspecialchars($str);
    -- 
    cgit v1.2.3-24-g4f1b
    
    
    From 8db2d5ebf30d7d8e648f36e9d669297a9a52cd3d Mon Sep 17 00:00:00 2001
    From: Robin Sowell 
    Date: Fri, 17 Jul 2009 22:07:04 +0000
    Subject: Added heading tags to skippable elements in the typography class-
     started as 1.6 EE bug fix- carried over.
    
    ---
     system/libraries/Typography.php | 2 +-
     1 file changed, 1 insertion(+), 1 deletion(-)
    
    (limited to 'system')
    
    diff --git a/system/libraries/Typography.php b/system/libraries/Typography.php
    index a16839362..242ca3cb6 100644
    --- a/system/libraries/Typography.php
    +++ b/system/libraries/Typography.php
    @@ -30,7 +30,7 @@ class CI_Typography {
     	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'; + 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'; -- cgit v1.2.3-24-g4f1b From 086ee5a06dc2a9b8273574c8c883efdbaa815765 Mon Sep 17 00:00:00 2001 From: Derek Jones Date: Tue, 28 Jul 2009 14:42:12 +0000 Subject: add is_php() to Common.php --- system/codeigniter/Common.php | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) (limited to 'system') diff --git a/system/codeigniter/Common.php b/system/codeigniter/Common.php index 340be2454..39005f602 100644 --- a/system/codeigniter/Common.php +++ b/system/codeigniter/Common.php @@ -29,6 +29,29 @@ // ------------------------------------------------------------------------ +/** +* Determines if the current version of PHP is greater then the supplied value +* +* Since there are a few places where we conditionally test for PHP > 5 +* we'll set a static variable. +* +* @access public +* @return bool +*/ + function is_php($version = '5.0.0') + { + static $_is_php; + + if ( ! isset($_is_php[$version])) + { + $_is_php[$version] = (version_compare(PHP_VERSION, $version) < 0) ? FALSE : TRUE; + } + + return $_is_php[$version]; + } + +// ------------------------------------------------------------------------ + /** * Tests for file writability * -- cgit v1.2.3-24-g4f1b From 5bcfd2e83e52155f199058479ac116a136f334a3 Mon Sep 17 00:00:00 2001 From: Derek Jones Date: Tue, 28 Jul 2009 14:42:42 +0000 Subject: whitespace --- system/codeigniter/Common.php | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) (limited to 'system') diff --git a/system/codeigniter/Common.php b/system/codeigniter/Common.php index 39005f602..f45c85c26 100644 --- a/system/codeigniter/Common.php +++ b/system/codeigniter/Common.php @@ -38,18 +38,18 @@ * @access public * @return bool */ - function is_php($version = '5.0.0') - { - static $_is_php; - - if ( ! isset($_is_php[$version])) - { - $_is_php[$version] = (version_compare(PHP_VERSION, $version) < 0) ? FALSE : TRUE; - } +function is_php($version = '5.0.0') +{ + static $_is_php; - return $_is_php[$version]; + if ( ! isset($_is_php[$version])) + { + $_is_php[$version] = (version_compare(PHP_VERSION, $version) < 0) ? FALSE : TRUE; } + return $_is_php[$version]; +} + // ------------------------------------------------------------------------ /** -- cgit v1.2.3-24-g4f1b From de8f409e84c4b2c428cba3f2845f2658d3db9b90 Mon Sep 17 00:00:00 2001 From: Pascal Kriete Date: Wed, 29 Jul 2009 13:46:37 +0000 Subject: Updating the smiley helper to work with more than one field. Also changing insertion position to be at the cursor and using ids instead of form names. --- system/helpers/smiley_helper.php | 140 +++++++++++++++++++++++++++++++++------ 1 file changed, 119 insertions(+), 21 deletions(-) (limited to 'system') diff --git a/system/helpers/smiley_helper.php b/system/helpers/smiley_helper.php index f9a2cf2b0..f085e53b1 100644 --- a/system/helpers/smiley_helper.php +++ b/system/helpers/smiley_helper.php @@ -28,29 +28,91 @@ // ------------------------------------------------------------------------ /** - * JS Insert Smiley + * Smiley Javascript * - * Generates the javascrip function needed to insert smileys into a form field + * Returns the javascript required for the smiley insertion. Optionally takes + * an array of aliases to loosely couple the smiley array to the view. * * @access public - * @param string form name - * @param string field name - * @return string + * @param mixed alias name or array of alias->field_id pairs + * @param string field_id if alias name was passed in + * @return array */ -if ( ! function_exists('js_insert_smiley')) +if ( ! function_exists('smiley_js')) { - function js_insert_smiley($form_name = '', $form_field = '') - { - return << - function insert_smiley(smiley) + function smiley_js($alias = '', $field_id = '') { - document.{$form_name}.{$form_field}.value += " " + smiley; - } - + 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"; + } + } + } + + return ''; } } + // ------------------------------------------------------------------------ /** @@ -65,8 +127,15 @@ EOF; */ if ( ! function_exists('get_clickable_smileys')) { - function get_clickable_smileys($image_url = '', $smileys = NULL) + 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())) @@ -76,8 +145,8 @@ if ( ! function_exists('get_clickable_smileys')) } // Add a trailing slash to the file path if needed - $image_url = preg_replace("/(.+?)\/*$/", "\\1/", $image_url); - + $image_url = rtrim($image_url, '/').'/'; + $used = array(); foreach ($smileys as $key => $val) { @@ -89,12 +158,12 @@ if ( ! function_exists('get_clickable_smileys')) { continue; } - - $link[] = "\"".$smileys[$key][3]."\""; - + + $link[] = "\"".$smileys[$key][3]."\""; + $used[$smileys[$key][0]] = TRUE; } - + return $link; } } @@ -170,6 +239,35 @@ if ( ! function_exists('_get_smiley_array')) } } +// ------------------------------------------------------------------------ + +/** + * JS Insert Smiley + * + * Generates the javascript function needed to insert smileys into a form field + * + * DEPRECATED as of version 1.7.2, use smiley_js instead + * + * @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; + } +} + /* End of file smiley_helper.php */ /* Location: ./system/helpers/smiley_helper.php */ \ No newline at end of file -- cgit v1.2.3-24-g4f1b From f0a9b332445977cfb05fee2dacc02667946a9cd2 Mon Sep 17 00:00:00 2001 From: Derek Jones Date: Wed, 29 Jul 2009 14:19:18 +0000 Subject: PHP 5.3.0 compatibility changes --- system/codeigniter/CodeIgniter.php | 6 +++--- system/codeigniter/Common.php | 24 +++++++++++++++++++++--- system/database/DB.php | 2 +- system/libraries/Loader.php | 2 +- system/libraries/Profiler.php | 4 ++-- system/libraries/URI.php | 4 +++- 6 files changed, 31 insertions(+), 11 deletions(-) (limited to 'system') diff --git a/system/codeigniter/CodeIgniter.php b/system/codeigniter/CodeIgniter.php index 68f6c759e..b78736a04 100644 --- a/system/codeigniter/CodeIgniter.php +++ b/system/codeigniter/CodeIgniter.php @@ -56,8 +56,8 @@ require(APPPATH.'config/constants'.EXT); * Define a custom error handler so we can log PHP errors * ------------------------------------------------------ */ -set_error_handler('_exception_handler'); -set_magic_quotes_runtime(0); // Kill magic quotes +//set_error_handler('_exception_handler'); +@set_magic_quotes_runtime(0); // Kill magic quotes /* * ------------------------------------------------------ @@ -130,7 +130,7 @@ $LANG =& load_class('Language'); * Note: The Loader class needs to be included first * */ -if (floor(phpversion()) < 5) +if ( ! is_php(5)) { load_class('Loader', FALSE); require(BASEPATH.'codeigniter/Base4'.EXT); diff --git a/system/codeigniter/Common.php b/system/codeigniter/Common.php index f45c85c26..1ffed6a0c 100644 --- a/system/codeigniter/Common.php +++ b/system/codeigniter/Common.php @@ -150,16 +150,34 @@ function &load_class($class, $instantiate = TRUE) if ($is_subclass == TRUE) { $name = config_item('subclass_prefix').$class; - $objects[$class] =& new $name(); + + $objects[$class] =& instantiate_class(new $name()); return $objects[$class]; } $name = ($class != 'Controller') ? 'CI_'.$class : $class; - - $objects[$class] =& new $name(); + + $objects[$class] =& instantiate_class(new $name()); return $objects[$class]; } +/** + * Instantiate Class + * + * Returns a new class object by reference, used by load_class() and the DB class. + * Required to retain PHP 4 compatibility and also not make PHP 5.3 cry. + * + * Use: $obj =& instantiate_class(new Foo()); + * + * @access public + * @param object + * @return object + */ +function &instantiate_class(&$class_object) +{ + return $class_object; +} + /** * Loads the main config.php file * diff --git a/system/database/DB.php b/system/database/DB.php index efe1d388a..0f734d748 100644 --- a/system/database/DB.php +++ b/system/database/DB.php @@ -130,7 +130,7 @@ function &DB($params = '', $active_record_override = FALSE) // Instantiate the DB adapter $driver = 'CI_DB_'.$params['dbdriver'].'_driver'; - $DB =& new $driver($params); + $DB =& instantiate_class(new $driver($params)); if ($DB->autoinit == TRUE) { diff --git a/system/libraries/Loader.php b/system/libraries/Loader.php index d615a1363..781c83c65 100644 --- a/system/libraries/Loader.php +++ b/system/libraries/Loader.php @@ -252,7 +252,7 @@ class CI_Loader { require_once(BASEPATH.'database/drivers/'.$CI->db->dbdriver.'/'.$CI->db->dbdriver.'_utility'.EXT); $class = 'CI_DB_'.$CI->db->dbdriver.'_utility'; - $CI->dbutil =& new $class(); + $CI->dbutil =& instantiate_class(new $class()); $CI->load->_ci_assign_to_models(); } diff --git a/system/libraries/Profiler.php b/system/libraries/Profiler.php index 98cec0653..ecd0e708d 100644 --- a/system/libraries/Profiler.php +++ b/system/libraries/Profiler.php @@ -103,11 +103,11 @@ class CI_Profiler { 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_subclass_of(get_class($CI_object), 'CI_DB') ) + if (is_object($CI_object) && is_subclass_of(get_class($CI_object), 'CI_DB') ) { $dbs[] = $CI_object; } diff --git a/system/libraries/URI.php b/system/libraries/URI.php index efc7a18b3..68b678053 100644 --- a/system/libraries/URI.php +++ b/system/libraries/URI.php @@ -186,7 +186,9 @@ class CI_URI { { if ($str != '' && $this->config->item('permitted_uri_chars') != '' && $this->config->item('enable_query_strings') == FALSE) { - if ( ! preg_match("|^[".preg_quote($this->config->item('permitted_uri_chars'))."]+$|i", $str)) + // 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); } -- cgit v1.2.3-24-g4f1b From 109ad9902b4eb9c1fba2c30a06f2104fae36f385 Mon Sep 17 00:00:00 2001 From: Derek Jones Date: Wed, 29 Jul 2009 14:24:46 +0000 Subject: undo of a did (left a line commented out that should not have been) --- system/codeigniter/CodeIgniter.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system') diff --git a/system/codeigniter/CodeIgniter.php b/system/codeigniter/CodeIgniter.php index b78736a04..5c14c7d3d 100644 --- a/system/codeigniter/CodeIgniter.php +++ b/system/codeigniter/CodeIgniter.php @@ -56,7 +56,7 @@ require(APPPATH.'config/constants'.EXT); * Define a custom error handler so we can log PHP errors * ------------------------------------------------------ */ -//set_error_handler('_exception_handler'); +set_error_handler('_exception_handler'); @set_magic_quotes_runtime(0); // Kill magic quotes /* -- cgit v1.2.3-24-g4f1b From 962d2258f9b2f2b8e3dbce7368b69673e839eb54 Mon Sep 17 00:00:00 2001 From: Derek Jones Date: Wed, 5 Aug 2009 04:26:11 +0000 Subject: protected @set_magic_quotes_runtime(0); from running under PHP 5.3, as it will trigger the loading of the Exceptions class, which triggers get_config() which will statically load some config items that might change later with $assign_to_config --- system/codeigniter/CodeIgniter.php | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'system') diff --git a/system/codeigniter/CodeIgniter.php b/system/codeigniter/CodeIgniter.php index 5c14c7d3d..5cf7d2fdc 100644 --- a/system/codeigniter/CodeIgniter.php +++ b/system/codeigniter/CodeIgniter.php @@ -57,7 +57,11 @@ require(APPPATH.'config/constants'.EXT); * ------------------------------------------------------ */ set_error_handler('_exception_handler'); -@set_magic_quotes_runtime(0); // Kill magic quotes + +if ( ! is_php(5.3)) +{ + @set_magic_quotes_runtime(0); // Kill magic quotes +} /* * ------------------------------------------------------ -- cgit v1.2.3-24-g4f1b From 77b513b821bf6df4b3afd4b841db93999632050e Mon Sep 17 00:00:00 2001 From: Derek Jones Date: Thu, 6 Aug 2009 14:39:25 +0000 Subject: fixed a bug in r1718 where the PHP version key was cast as float in a particular test, making the array keys used by is_php() inaccurate beyond whole number versions http://codeigniter.com/bug_tracker/bug/8475/ --- system/codeigniter/CodeIgniter.php | 2 +- system/codeigniter/Common.php | 6 ++++-- 2 files changed, 5 insertions(+), 3 deletions(-) (limited to 'system') diff --git a/system/codeigniter/CodeIgniter.php b/system/codeigniter/CodeIgniter.php index 5cf7d2fdc..1671287d0 100644 --- a/system/codeigniter/CodeIgniter.php +++ b/system/codeigniter/CodeIgniter.php @@ -58,7 +58,7 @@ require(APPPATH.'config/constants'.EXT); */ set_error_handler('_exception_handler'); -if ( ! is_php(5.3)) +if ( ! is_php('5.3')) { @set_magic_quotes_runtime(0); // Kill magic quotes } diff --git a/system/codeigniter/Common.php b/system/codeigniter/Common.php index 1ffed6a0c..6d3202d1b 100644 --- a/system/codeigniter/Common.php +++ b/system/codeigniter/Common.php @@ -36,12 +36,14 @@ * we'll set a static variable. * * @access public -* @return bool +* @param string +* * @return bool */ function is_php($version = '5.0.0') { static $_is_php; - + $version = (string)$version; + if ( ! isset($_is_php[$version])) { $_is_php[$version] = (version_compare(PHP_VERSION, $version) < 0) ? FALSE : TRUE; -- cgit v1.2.3-24-g4f1b From 6d3c2c3511f1c041228da0c13b9d25b716dcf1e1 Mon Sep 17 00:00:00 2001 From: Derek Jones Date: Thu, 6 Aug 2009 14:43:16 +0000 Subject: code comment cleanup --- system/codeigniter/Common.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system') diff --git a/system/codeigniter/Common.php b/system/codeigniter/Common.php index 6d3202d1b..15204492e 100644 --- a/system/codeigniter/Common.php +++ b/system/codeigniter/Common.php @@ -37,7 +37,7 @@ * * @access public * @param string -* * @return bool +* @return bool */ function is_php($version = '5.0.0') { -- cgit v1.2.3-24-g4f1b From 8f26dbe1c4b49042d2653956d6278b87351af661 Mon Sep 17 00:00:00 2001 From: Derek Jones Date: Thu, 6 Aug 2009 14:45:07 +0000 Subject: let's go ahead and be thorough and explicit if ( ! is_php(5)) becomes if ( ! is_php('5.0.0')) ref: http://codeigniter.com/bug_tracker/bug/8475/ --- system/codeigniter/CodeIgniter.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system') diff --git a/system/codeigniter/CodeIgniter.php b/system/codeigniter/CodeIgniter.php index 1671287d0..7b945d249 100644 --- a/system/codeigniter/CodeIgniter.php +++ b/system/codeigniter/CodeIgniter.php @@ -134,7 +134,7 @@ $LANG =& load_class('Language'); * Note: The Loader class needs to be included first * */ -if ( ! is_php(5)) +if ( ! is_php('5.0.0')) { load_class('Loader', FALSE); require(BASEPATH.'codeigniter/Base4'.EXT); -- cgit v1.2.3-24-g4f1b From 64c398bde1ac0332737980a66a780624ab069be2 Mon Sep 17 00:00:00 2001 From: Derek Allard Date: Mon, 17 Aug 2009 15:13:45 +0000 Subject: Modified MSSQL driver to use mssql_get_last_message() for error messages. --- system/database/drivers/mssql/mssql_driver.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'system') diff --git a/system/database/drivers/mssql/mssql_driver.php b/system/database/drivers/mssql/mssql_driver.php index 4748d5683..97ac971bd 100644 --- a/system/database/drivers/mssql/mssql_driver.php +++ b/system/database/drivers/mssql/mssql_driver.php @@ -438,8 +438,7 @@ class CI_DB_mssql_driver extends CI_DB { */ function _error_message() { - // Are errros even supported in MS SQL? - return ''; + return mssql_get_last_message(); } // -------------------------------------------------------------------- -- cgit v1.2.3-24-g4f1b From 42dada789aba190fcdd23ffc8dcc50e6c44e6657 Mon Sep 17 00:00:00 2001 From: Derek Allard Date: Mon, 17 Aug 2009 15:20:37 +0000 Subject: comment fix --- system/codeigniter/Common.php | 14 -------------- 1 file changed, 14 deletions(-) (limited to 'system') diff --git a/system/codeigniter/Common.php b/system/codeigniter/Common.php index 15204492e..eb9dce648 100644 --- a/system/codeigniter/Common.php +++ b/system/codeigniter/Common.php @@ -15,20 +15,6 @@ // ------------------------------------------------------------------------ -/** - * Common Functions - * - * Loads the base classes and executes the request. - * - * @package CodeIgniter - * @subpackage codeigniter - * @category Common Functions - * @author ExpressionEngine Dev Team - * @link http://codeigniter.com/user_guide/ - */ - -// ------------------------------------------------------------------------ - /** * Determines if the current version of PHP is greater then the supplied value * -- cgit v1.2.3-24-g4f1b From defaa17f0977c340440d81fbfb619db2c13c5ce5 Mon Sep 17 00:00:00 2001 From: Derek Allard Date: Mon, 17 Aug 2009 17:24:31 +0000 Subject: Fixed a bug in the Calendar library where the shortname was output for "May". --- system/libraries/Calendar.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system') diff --git a/system/libraries/Calendar.php b/system/libraries/Calendar.php index 9c5961fb2..68d402254 100644 --- a/system/libraries/Calendar.php +++ b/system/libraries/Calendar.php @@ -270,7 +270,7 @@ class CI_Calendar { } else { - $month_names = array('01' => 'cal_january', '02' => 'cal_february', '03' => 'cal_march', '04' => 'cal_april', '05' => 'cal_may', '06' => 'cal_june', '07' => 'cal_july', '08' => 'cal_august', '09' => 'cal_september', '10' => 'cal_october', '11' => 'cal_november', '12' => 'cal_december'); + $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]; -- cgit v1.2.3-24-g4f1b From ea9e4e0c22368f80597c073e99446ffa386e7531 Mon Sep 17 00:00:00 2001 From: Derek Allard Date: Mon, 17 Aug 2009 17:40:48 +0000 Subject: Fixed a bug in the language class when outputting an error for an unfound file. --- system/libraries/Language.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system') diff --git a/system/libraries/Language.php b/system/libraries/Language.php index cf6d53239..b679c891f 100644 --- a/system/libraries/Language.php +++ b/system/libraries/Language.php @@ -78,7 +78,7 @@ class CI_Language { } else { - show_error('Unable to load the requested language file: language/'.$langfile); + show_error('Unable to load the requested language file: language/'.$idiom.'/'.$langfile); } } -- cgit v1.2.3-24-g4f1b From 69b1fcc0b26c181b24aed8c347db94563328a83e Mon Sep 17 00:00:00 2001 From: Pascal Kriete Date: Mon, 24 Aug 2009 16:42:52 +0000 Subject: updating xml_from_result to check for list_fields instead of field_names --- system/database/DB_utility.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system') diff --git a/system/database/DB_utility.php b/system/database/DB_utility.php index 4ba69adbd..33c68faea 100644 --- a/system/database/DB_utility.php +++ b/system/database/DB_utility.php @@ -217,7 +217,7 @@ class CI_DB_utility extends CI_DB_forge { */ function xml_from_result($query, $params = array()) { - if ( ! is_object($query) OR ! method_exists($query, 'field_names')) + if ( ! is_object($query) OR ! method_exists($query, 'list_fields')) { show_error('You must submit a valid result object'); } -- cgit v1.2.3-24-g4f1b From 5f58ecb632447a6b82697074d41bd0804399a952 Mon Sep 17 00:00:00 2001 From: Derek Allard Date: Tue, 25 Aug 2009 13:25:27 +0000 Subject: removed an unneeded regex --- system/libraries/Config.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system') diff --git a/system/libraries/Config.php b/system/libraries/Config.php index ed1541b20..0cafde71a 100644 --- a/system/libraries/Config.php +++ b/system/libraries/Config.php @@ -203,7 +203,7 @@ class CI_Config { else { $suffix = ($this->item('url_suffix') == FALSE) ? '' : $this->item('url_suffix'); - return $this->slash_item('base_url').$this->slash_item('index_page').preg_replace("|^/*(.+?)/*$|", "\\1", $uri).$suffix; + return $this->slash_item('‘base_url').$this->slash_item('index_page').trim($uri, '/').$suffix; } } -- cgit v1.2.3-24-g4f1b From 30d5698f6643703fa0e4a66c70db6ebc8cfd0e2a Mon Sep 17 00:00:00 2001 From: Derek Allard Date: Tue, 25 Aug 2009 15:50:29 +0000 Subject: reverting until further testing can be done --- system/libraries/Config.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'system') diff --git a/system/libraries/Config.php b/system/libraries/Config.php index 0cafde71a..9bf3d5026 100644 --- a/system/libraries/Config.php +++ b/system/libraries/Config.php @@ -203,7 +203,8 @@ class CI_Config { else { $suffix = ($this->item('url_suffix') == FALSE) ? '' : $this->item('url_suffix'); - return $this->slash_item('‘base_url').$this->slash_item('index_page').trim($uri, '/').$suffix; +// return $this->slash_item('‘base_url').$this->slash_item('index_page').trim($uri, '/').$suffix; + return $this->slash_item('base_url').$this->slash_item('index_page').preg_replace("|^/*(.+?)/*$|", "\\1", $uri).$suffix; } } -- cgit v1.2.3-24-g4f1b From 0835090ee5448f8ed8ba260d35c82abe24c81d50 Mon Sep 17 00:00:00 2001 From: Derek Allard Date: Tue, 25 Aug 2009 19:15:05 +0000 Subject: removed an unneeded regex --- system/libraries/Config.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'system') diff --git a/system/libraries/Config.php b/system/libraries/Config.php index 9bf3d5026..4ef278635 100644 --- a/system/libraries/Config.php +++ b/system/libraries/Config.php @@ -203,8 +203,7 @@ class CI_Config { else { $suffix = ($this->item('url_suffix') == FALSE) ? '' : $this->item('url_suffix'); -// return $this->slash_item('‘base_url').$this->slash_item('index_page').trim($uri, '/').$suffix; - return $this->slash_item('base_url').$this->slash_item('index_page').preg_replace("|^/*(.+?)/*$|", "\\1", $uri).$suffix; + return $this->slash_item('base_url').$this->slash_item('index_page').trim($uri, '/').$suffix; } } -- cgit v1.2.3-24-g4f1b From bbedc76aaf59f6f12a7bc32e1aa851317a61c837 Mon Sep 17 00:00:00 2001 From: Derek Jones Date: Fri, 11 Sep 2009 14:47:37 +0000 Subject: prep for 1.7.2 release --- system/codeigniter/CodeIgniter.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system') diff --git a/system/codeigniter/CodeIgniter.php b/system/codeigniter/CodeIgniter.php index 7b945d249..dac137bf6 100644 --- a/system/codeigniter/CodeIgniter.php +++ b/system/codeigniter/CodeIgniter.php @@ -28,7 +28,7 @@ */ // CI Version -define('CI_VERSION', '1.7.1'); +define('CI_VERSION', '1.7.2'); /* * ------------------------------------------------------ -- cgit v1.2.3-24-g4f1b From 928158bf3a308330ab6518ff0d149d4585d7f38f Mon Sep 17 00:00:00 2001 From: Derek Allard Date: Wed, 16 Sep 2009 08:20:58 +0000 Subject: adding accept-charset to form_open() --- system/helpers/form_helper.php | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) (limited to 'system') diff --git a/system/helpers/form_helper.php b/system/helpers/form_helper.php index c5e977a40..2fd4807fc 100644 --- a/system/helpers/form_helper.php +++ b/system/helpers/form_helper.php @@ -44,9 +44,30 @@ if ( ! function_exists('form_open')) { $CI =& get_instance(); + $charset = strtolower($CI->config->item('charset')); + if ($attributes == '') { - $attributes = 'method="post"'; + $attributes = 'method="post" accept-charset="'.$charset.'"'; + } + else + { + if ( is_string($attributes) ) + { + if(strpos('accept-charset=') === FALSE) + { + $attributes .= ' accept-charset="'.$charset.'"'; + } + } + else + { + $attributes = (array) $attributes; + + if(!in_array('accept-charset', $attributes)) + { + $attributes['accept-charset'] = $charset; + } + } } $action = ( strpos($action, '://') === FALSE) ? $CI->config->site_url($action) : $action; -- cgit v1.2.3-24-g4f1b From f673a87ad9530a2982caef0bd5a53983d6b06a63 Mon Sep 17 00:00:00 2001 From: Derek Allard Date: Wed, 16 Sep 2009 09:35:03 +0000 Subject: --- system/helpers/form_helper.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'system') diff --git a/system/helpers/form_helper.php b/system/helpers/form_helper.php index 2fd4807fc..5917d1016 100644 --- a/system/helpers/form_helper.php +++ b/system/helpers/form_helper.php @@ -52,7 +52,7 @@ if ( ! function_exists('form_open')) } else { - if ( is_string($attributes) ) + if ( is_string($attributes)) { if(strpos('accept-charset=') === FALSE) { @@ -63,7 +63,7 @@ if ( ! function_exists('form_open')) { $attributes = (array) $attributes; - if(!in_array('accept-charset', $attributes)) + if ( ! in_array('accept-charset', $attributes)) { $attributes['accept-charset'] = $charset; } -- cgit v1.2.3-24-g4f1b From 76763bb6e18c15bf099564789bfa621a938313d8 Mon Sep 17 00:00:00 2001 From: Derek Allard Date: Wed, 16 Sep 2009 11:25:20 +0000 Subject: removed some trivial spaces from output --- system/helpers/html_helper.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'system') diff --git a/system/helpers/html_helper.php b/system/helpers/html_helper.php index 427d1ce3f..ca933bd78 100644 --- a/system/helpers/html_helper.php +++ b/system/helpers/html_helper.php @@ -301,11 +301,11 @@ if ( ! function_exists('link_tag')) { if ($index_page === TRUE) { - $link .= ' href="'.$CI->config->site_url($v).'" '; + $link .= 'href="'.$CI->config->site_url($v).'" '; } else { - $link .= ' href="'.$CI->config->slash_item('base_url').$v.'" '; + $link .= 'href="'.$CI->config->slash_item('base_url').$v.'" '; } } else @@ -324,11 +324,11 @@ if ( ! function_exists('link_tag')) } elseif ($index_page === TRUE) { - $link .= ' href="'.$CI->config->site_url($href).'" '; + $link .= 'href="'.$CI->config->site_url($href).'" '; } else { - $link .= ' href="'.$CI->config->slash_item('base_url').$href.'" '; + $link .= 'href="'.$CI->config->slash_item('base_url').$href.'" '; } $link .= 'rel="'.$rel.'" type="'.$type.'" '; -- cgit v1.2.3-24-g4f1b From 292dcd83359db59a60564cf7ceb1890e5395ac36 Mon Sep 17 00:00:00 2001 From: Derek Allard Date: Wed, 16 Sep 2009 11:26:32 +0000 Subject: removed some trivial spaces from output --- system/helpers/html_helper.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system') diff --git a/system/helpers/html_helper.php b/system/helpers/html_helper.php index ca933bd78..b55ec88ca 100644 --- a/system/helpers/html_helper.php +++ b/system/helpers/html_helper.php @@ -320,7 +320,7 @@ if ( ! function_exists('link_tag')) { if ( strpos($href, '://') !== FALSE) { - $link .= ' href="'.$href.'" '; + $link .= 'href="'.$href.'" '; } elseif ($index_page === TRUE) { -- cgit v1.2.3-24-g4f1b From 3241d73d55649893cea7c55d1d24b2981088b0d1 Mon Sep 17 00:00:00 2001 From: Derek Allard Date: Thu, 17 Sep 2009 12:17:45 +0000 Subject: modified the way accept-charset is added --- system/helpers/form_helper.php | 54 +++++++++++++++++------------------------- 1 file changed, 22 insertions(+), 32 deletions(-) (limited to 'system') diff --git a/system/helpers/form_helper.php b/system/helpers/form_helper.php index 5917d1016..02e2edd3e 100644 --- a/system/helpers/form_helper.php +++ b/system/helpers/form_helper.php @@ -44,30 +44,9 @@ if ( ! function_exists('form_open')) { $CI =& get_instance(); - $charset = strtolower($CI->config->item('charset')); - if ($attributes == '') { - $attributes = 'method="post" accept-charset="'.$charset.'"'; - } - else - { - if ( is_string($attributes)) - { - if(strpos('accept-charset=') === FALSE) - { - $attributes .= ' accept-charset="'.$charset.'"'; - } - } - else - { - $attributes = (array) $attributes; - - if ( ! in_array('accept-charset', $attributes)) - { - $attributes['accept-charset'] = $charset; - } - } + $attributes = 'method="post"'; } $action = ( strpos($action, '://') === FALSE) ? $CI->config->site_url($action) : $action; @@ -87,6 +66,7 @@ if ( ! function_exists('form_open')) } } + // ------------------------------------------------------------------------ /** @@ -978,6 +958,11 @@ if ( ! function_exists('_attributes_to_string')) $attributes .= ' method="post"'; } + if ($formtag == TRUE AND strpos($attributes, 'accept-charset=') === FALSE) + { + $attributes .= ' accept-charset="'.strtolower(config_item('charset')).'"'; + } + return ' '.$attributes; } @@ -988,19 +973,24 @@ if ( ! function_exists('_attributes_to_string')) if (is_array($attributes) AND count($attributes) > 0) { - $atts = ''; + $atts = ''; - if ( ! isset($attributes['method']) AND $formtag === TRUE) - { - $atts .= ' method="post"'; - } + if ( ! isset($attributes['method']) AND $formtag === TRUE) + { + $atts .= ' method="post"'; + } - foreach ($attributes as $key => $val) - { - $atts .= ' '.$key.'="'.$val.'"'; - } + 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; + return $atts; } } } -- cgit v1.2.3-24-g4f1b From 8a52791ee8387e6f5cac570088ee18183900741b Mon Sep 17 00:00:00 2001 From: Derek Jones Date: Thu, 24 Sep 2009 14:25:39 +0000 Subject: increased randomness of file name used in is_really_writable() --- system/codeigniter/Common.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system') diff --git a/system/codeigniter/Common.php b/system/codeigniter/Common.php index eb9dce648..73ff0196f 100644 --- a/system/codeigniter/Common.php +++ b/system/codeigniter/Common.php @@ -62,7 +62,7 @@ function is_really_writable($file) // write a file then read it. Bah... if (is_dir($file)) { - $file = rtrim($file, '/').'/'.md5(rand(1,100)); + $file = rtrim($file, '/').'/'.md5(mt_rand(1,100).mt_rand(1,100)); if (($fp = @fopen($file, FOPEN_WRITE_CREATE)) === FALSE) { -- cgit v1.2.3-24-g4f1b From e339ef56f366024b4d094a8f7335d56cf683598b Mon Sep 17 00:00:00 2001 From: Derek Allard Date: Fri, 25 Sep 2009 03:23:21 +0000 Subject: Made get_mime_by_extension() case insensitive. --- system/helpers/file_helper.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system') diff --git a/system/helpers/file_helper.php b/system/helpers/file_helper.php index 0d7b5d5aa..cb3d60ee9 100644 --- a/system/helpers/file_helper.php +++ b/system/helpers/file_helper.php @@ -340,7 +340,7 @@ if ( ! function_exists('get_mime_by_extension')) { function get_mime_by_extension($file) { - $extension = substr(strrchr($file, '.'), 1); + $extension = strtolower(substr(strrchr($file, '.'), 1)); global $mimes; -- cgit v1.2.3-24-g4f1b From 15bc6f50246c864c64fabd55a35be28c3b5ef6c1 Mon Sep 17 00:00:00 2001 From: Derek Allard Date: Mon, 28 Sep 2009 11:27:26 +0000 Subject: uncommenting a function --- system/plugins/js_calendar_pi.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'system') diff --git a/system/plugins/js_calendar_pi.php b/system/plugins/js_calendar_pi.php index 19d056810..4a616f10f 100644 --- a/system/plugins/js_calendar_pi.php +++ b/system/plugins/js_calendar_pi.php @@ -479,7 +479,7 @@ function set_date(td, cal) // Insert the date into the form insert_date(cal); } -/* + // Insert the date into the form field function insert_date(cal) { @@ -495,9 +495,9 @@ function insert_date(cal) time = fval.value.substring(10); new_date = cal.date_str('n') + time; fval.value = new_date; - } + } } -*/ + // Remove the date from the form field function remove_date(cal) { -- cgit v1.2.3-24-g4f1b From 8719a5c7fe75b84f49f584065e5ef4e4e2a0f16f Mon Sep 17 00:00:00 2001 From: Derek Allard Date: Thu, 8 Oct 2009 16:42:59 +0000 Subject: Deprecated the dohash() function in favour of do_hash() for naming consistency. --- system/helpers/security_helper.php | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) (limited to 'system') diff --git a/system/helpers/security_helper.php b/system/helpers/security_helper.php index 9cc70aaff..8fb53e718 100644 --- a/system/helpers/security_helper.php +++ b/system/helpers/security_helper.php @@ -46,6 +46,22 @@ if ( ! function_exists('xss_clean')) // -------------------------------------------------------------------- +/** + * Hash encode a string + * + * This is simply an alias for do_hash() + * dohash() is now deprecated + */ +if ( ! function_exists('dohash')) +{ + function dohash($str, $type = 'sha1') + { + return $this->do_hash($str, $type); + } +} + +// -------------------------------------------------------------------- + /** * Hash encode a string * @@ -53,9 +69,9 @@ if ( ! function_exists('xss_clean')) * @param string * @return string */ -if ( ! function_exists('dohash')) +if ( ! function_exists('do_hash')) { - function dohash($str, $type = 'sha1') + function do_hash($str, $type = 'sha1') { if ($type == 'sha1') { -- cgit v1.2.3-24-g4f1b From c1895834c410f04419febe83d29547201bbab7d0 Mon Sep 17 00:00:00 2001 From: Pascal Kriete Date: Tue, 13 Oct 2009 12:56:43 +0000 Subject: added translation of fields passed as validation rule parameters --- system/libraries/Form_validation.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system') diff --git a/system/libraries/Form_validation.php b/system/libraries/Form_validation.php index 1497d8517..e825b1b32 100644 --- a/system/libraries/Form_validation.php +++ b/system/libraries/Form_validation.php @@ -658,7 +658,7 @@ class CI_Form_validation { // of another field? If so we need to grab its "field label" if (isset($this->_field_data[$param]) AND isset($this->_field_data[$param]['label'])) { - $param = $this->_field_data[$param]['label']; + $param = $this->_translate_fieldname($this->_field_data[$param]['label']); } // Build the error message -- cgit v1.2.3-24-g4f1b From 172e16191889558ca6f6710cf34755200d3e6334 Mon Sep 17 00:00:00 2001 From: Derek Jones Date: Tue, 13 Oct 2009 14:32:48 +0000 Subject: numerous changes from DIR_WRITE_MODE to FILE_WRITE_MODE chmod operations on files were using the DIR_ constant permisisons --- system/database/DB_cache.php | 2 +- system/libraries/Image_lib.php | 12 ++++++------ system/libraries/Output.php | 2 +- 3 files changed, 8 insertions(+), 8 deletions(-) (limited to 'system') diff --git a/system/database/DB_cache.php b/system/database/DB_cache.php index 8b0ad4fb4..f01bc8212 100644 --- a/system/database/DB_cache.php +++ b/system/database/DB_cache.php @@ -146,7 +146,7 @@ class CI_DB_Cache { return FALSE; } - @chmod($dir_path.$filename, DIR_WRITE_MODE); + @chmod($dir_path.$filename, FILE_WRITE_MODE); return TRUE; } diff --git a/system/libraries/Image_lib.php b/system/libraries/Image_lib.php index 169c6e489..59aefc55c 100644 --- a/system/libraries/Image_lib.php +++ b/system/libraries/Image_lib.php @@ -459,7 +459,7 @@ class CI_Image_lib { { if (@copy($this->full_src_path, $this->full_dst_path)) { - @chmod($this->full_dst_path, DIR_WRITE_MODE); + @chmod($this->full_dst_path, FILE_WRITE_MODE); } } @@ -534,7 +534,7 @@ class CI_Image_lib { imagedestroy($src_img); // Set the file to 777 - @chmod($this->full_dst_path, DIR_WRITE_MODE); + @chmod($this->full_dst_path, FILE_WRITE_MODE); return TRUE; } @@ -604,7 +604,7 @@ class CI_Image_lib { } // Set the file to 777 - @chmod($this->full_dst_path, DIR_WRITE_MODE); + @chmod($this->full_dst_path, FILE_WRITE_MODE); return TRUE; } @@ -690,7 +690,7 @@ class CI_Image_lib { // we have to rename the temp file. copy ($this->dest_folder.'netpbm.tmp', $this->full_dst_path); unlink ($this->dest_folder.'netpbm.tmp'); - @chmod($this->full_dst_path, DIR_WRITE_MODE); + @chmod($this->full_dst_path, FILE_WRITE_MODE); return TRUE; } @@ -749,7 +749,7 @@ class CI_Image_lib { // Set the file to 777 - @chmod($this->full_dst_path, DIR_WRITE_MODE); + @chmod($this->full_dst_path, FILE_WRITE_MODE); return true; } @@ -833,7 +833,7 @@ class CI_Image_lib { imagedestroy($src_img); // Set the file to 777 - @chmod($this->full_dst_path, DIR_WRITE_MODE); + @chmod($this->full_dst_path, FILE_WRITE_MODE); return TRUE; } diff --git a/system/libraries/Output.php b/system/libraries/Output.php index 4423ac726..0cf6739bd 100644 --- a/system/libraries/Output.php +++ b/system/libraries/Output.php @@ -331,7 +331,7 @@ class CI_Output { return; } fclose($fp); - @chmod($cache_path, DIR_WRITE_MODE); + @chmod($cache_path, FILE_WRITE_MODE); log_message('debug', "Cache file written: ".$cache_path); } -- cgit v1.2.3-24-g4f1b From a3f47180e3885fca82599e90c95ce6e5c26072d6 Mon Sep 17 00:00:00 2001 From: Greg Aker Date: Wed, 4 Nov 2009 17:23:32 +0000 Subject: Modified inflector helper to properly pluralize words that end in 'ch' or 'sh' http://codeigniter.com/bug_tracker/bug/9384/ --- system/helpers/inflector_helper.php | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'system') diff --git a/system/helpers/inflector_helper.php b/system/helpers/inflector_helper.php index e65968a9d..8db4f3d75 100644 --- a/system/helpers/inflector_helper.php +++ b/system/helpers/inflector_helper.php @@ -91,6 +91,17 @@ if ( ! function_exists('plural')) $vowels = array('a', 'e', 'i', 'o', 'u'); $str = in_array(substr($str, -2, 1), $vowels) ? $str.'s' : substr($str, 0, -1).'ies'; } + elseif ($end == 'h') + { + if (substr($str, -2) == 'ch' || substr($str, -2) == 'sh') + { + $str .= 'es'; + } + else + { + $str .= 's'; + } + } elseif ($end == 's') { if ($force == TRUE) -- cgit v1.2.3-24-g4f1b From e24f61a2bb61c2445cb205777f897415e86fc10e Mon Sep 17 00:00:00 2001 From: Derek Jones Date: Thu, 5 Nov 2009 15:06:31 +0000 Subject: added hyphens to allowed characters in GET keys and vals in submitted URLs in xss_clean() --- system/libraries/Input.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system') diff --git a/system/libraries/Input.php b/system/libraries/Input.php index e7bf72779..98f28262f 100644 --- a/system/libraries/Input.php +++ b/system/libraries/Input.php @@ -554,7 +554,7 @@ class CI_Input { // 901119URL5918AMP18930PROTECT8198 - $str = preg_replace('|\&([a-z\_0-9]+)\=([a-z\_0-9]+)|i', $this->xss_hash()."\\1=\\2", $str); + $str = preg_replace('|\&([a-z\_0-9\-]+)\=([a-z\_0-9\-]+)|i', $this->xss_hash()."\\1=\\2", $str); /* * Validate standard character entities -- cgit v1.2.3-24-g4f1b From 986e17262a17aa2c2059bc3be25a18b43deb712e Mon Sep 17 00:00:00 2001 From: Pascal Kriete Date: Mon, 9 Nov 2009 20:51:15 +0000 Subject: incorrect variable name in the smiley helper js --- system/helpers/smiley_helper.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system') diff --git a/system/helpers/smiley_helper.php b/system/helpers/smiley_helper.php index f085e53b1..ab1f2c27e 100644 --- a/system/helpers/smiley_helper.php +++ b/system/helpers/smiley_helper.php @@ -93,7 +93,7 @@ if ( ! function_exists('smiley_js')) el.setSelectionRange(newStart, newStart); } else if (document.selection) { - document.selection.createRange().text = text; + document.selection.createRange().text = smiley; } } EOF; -- cgit v1.2.3-24-g4f1b From de27adfa84600ea863e8737d60861991ff2bbb62 Mon Sep 17 00:00:00 2001 From: Derek Allard Date: Fri, 20 Nov 2009 02:26:14 +0000 Subject: margin fix --- system/libraries/Profiler.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system') diff --git a/system/libraries/Profiler.php b/system/libraries/Profiler.php index ecd0e708d..9eb7dfa70 100644 --- a/system/libraries/Profiler.php +++ b/system/libraries/Profiler.php @@ -74,7 +74,7 @@ class CI_Profiler { // be modified. We also might want to make this data available to be logged $output = "\n\n"; - $output .= '

    '; + $output .= '
    '; $output .= "\n"; $output .= '  '.$this->CI->lang->line('profiler_benchmarks').'  '; $output .= "\n"; -- cgit v1.2.3-24-g4f1b From 788b00f7eaad969120079acedc82e8d60b0e2a46 Mon Sep 17 00:00:00 2001 From: Derek Jones Date: Fri, 27 Nov 2009 18:00:20 +0000 Subject: non-backwards compatible change to get_dir_file_info() for performance reasons, as well as fixing recursive bug --- system/helpers/file_helper.php | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) (limited to 'system') diff --git a/system/helpers/file_helper.php b/system/helpers/file_helper.php index cb3d60ee9..41ec2648e 100644 --- a/system/helpers/file_helper.php +++ b/system/helpers/file_helper.php @@ -220,7 +220,7 @@ if ( ! function_exists('get_filenames')) */ if ( ! function_exists('get_dir_file_info')) { - function get_dir_file_info($source_dir, $include_path = FALSE, $_recursion = FALSE) + function get_dir_file_info($source_dir, $top_level_only = TRUE, $_recursion = FALSE) { static $_filedata = array(); $relative_path = $source_dir; @@ -234,18 +234,20 @@ if ( ! function_exists('get_dir_file_info')) $source_dir = rtrim(realpath($source_dir), DIRECTORY_SEPARATOR).DIRECTORY_SEPARATOR; } + // foreach (scandir($source_dir, 1) as $file) // In addition to being PHP5+, scandir() is simply not as fast while (FALSE !== ($file = readdir($fp))) { - if (@is_dir($source_dir.$file) && strncmp($file, '.', 1) !== 0) - { - get_dir_file_info($source_dir.$file.DIRECTORY_SEPARATOR, $include_path, TRUE); - } - elseif (strncmp($file, '.', 1) !== 0) + 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 -- cgit v1.2.3-24-g4f1b From ffca6c2202f89249d3bc50b5645b94c772ff3b0d Mon Sep 17 00:00:00 2001 From: Derek Jones Date: Sat, 5 Dec 2009 15:31:44 +0000 Subject: fixed bug where active record override wasn't being honored properly --- system/database/DB.php | 6 +++--- system/libraries/Loader.php | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) (limited to 'system') diff --git a/system/database/DB.php b/system/database/DB.php index 0f734d748..0451c18e6 100644 --- a/system/database/DB.php +++ b/system/database/DB.php @@ -22,7 +22,7 @@ * @author ExpressionEngine Dev Team * @link http://codeigniter.com/user_guide/database/ */ -function &DB($params = '', $active_record_override = FALSE) +function &DB($params = '', $active_record_override = NULL) { // Load the DB config file if a DSN string wasn't passed if (is_string($params) AND strpos($params, '://') === FALSE) @@ -102,9 +102,9 @@ function &DB($params = '', $active_record_override = FALSE) // 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 == TRUE) + if ($active_record_override !== NULL) { - $active_record = TRUE; + $active_record = $active_record_override; } require_once(BASEPATH.'database/DB_driver'.EXT); diff --git a/system/libraries/Loader.php b/system/libraries/Loader.php index 781c83c65..710c5c148 100644 --- a/system/libraries/Loader.php +++ b/system/libraries/Loader.php @@ -198,7 +198,7 @@ class CI_Loader { * @param bool whether to enable active record (this allows us to override the config setting) * @return object */ - function database($params = '', $return = FALSE, $active_record = FALSE) + function database($params = '', $return = FALSE, $active_record = NULL) { // Grab the super object $CI =& get_instance(); -- cgit v1.2.3-24-g4f1b From 9fb6dd19f74c72cb98b6108a42575a98d3a9ba0c Mon Sep 17 00:00:00 2001 From: Derek Jones Date: Sat, 5 Dec 2009 15:32:48 +0000 Subject: tweak in database() to match change to $active_record variable --- system/libraries/Loader.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system') diff --git a/system/libraries/Loader.php b/system/libraries/Loader.php index 710c5c148..60c495820 100644 --- a/system/libraries/Loader.php +++ b/system/libraries/Loader.php @@ -204,7 +204,7 @@ class CI_Loader { $CI =& get_instance(); // Do we even need to load the database class? - if (class_exists('CI_DB') AND $return == FALSE AND $active_record == FALSE AND isset($CI->db) AND is_object($CI->db)) + if (class_exists('CI_DB') AND $return == FALSE AND $active_record == NULL AND isset($CI->db) AND is_object($CI->db)) { return FALSE; } -- cgit v1.2.3-24-g4f1b From 8dc2c7cb55e33e96bc82e61985553192c9af4ebd Mon Sep 17 00:00:00 2001 From: Derek Allard Date: Mon, 7 Dec 2009 16:07:15 +0000 Subject: Fixed an error in the Zip library that didn't allow downloading on PHP 4 servers. --- system/libraries/Zip.php | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'system') diff --git a/system/libraries/Zip.php b/system/libraries/Zip.php index f81da856c..4ed1f1820 100644 --- a/system/libraries/Zip.php +++ b/system/libraries/Zip.php @@ -325,11 +325,13 @@ class CI_Zip { $filename .= '.zip'; } - $zip_content =& $this->get_zip(); - $CI =& get_instance(); $CI->load->helper('download'); + $get_zip = $this->get_zip(); + + $zip_content =& $get_zip; + force_download($filename, $zip_content); } -- cgit v1.2.3-24-g4f1b From e8b26199a3d13eeae0f413195745e2298878f096 Mon Sep 17 00:00:00 2001 From: Derek Allard Date: Mon, 7 Dec 2009 16:32:18 +0000 Subject: Fixed a language key in the profiler: "profiler_no_memory_usage" to "profiler_no_memory". --- system/libraries/Profiler.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system') diff --git a/system/libraries/Profiler.php b/system/libraries/Profiler.php index 9eb7dfa70..5676898c8 100644 --- a/system/libraries/Profiler.php +++ b/system/libraries/Profiler.php @@ -351,7 +351,7 @@ class CI_Profiler { } else { - $output .= "
    ".$this->CI->lang->line('profiler_no_memory_usage')."
    "; + $output .= "
    ".$this->CI->lang->line('profiler_no_memory')."
    "; } $output .= "
    "; -- cgit v1.2.3-24-g4f1b From 3683f775bec4993b3777b012a087e82d6bff8d3f Mon Sep 17 00:00:00 2001 From: Derek Allard Date: Wed, 16 Dec 2009 17:32:33 +0000 Subject: Change to CI's db->version() function to allow a list of exceptions for dbs with functions to return version string, vs SQL queries to return version strings. Currently this list only includes Oracle and SQLite. --- system/database/DB_driver.php | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) (limited to 'system') diff --git a/system/database/DB_driver.php b/system/database/DB_driver.php index 014dfd44e..aee06205b 100644 --- a/system/database/DB_driver.php +++ b/system/database/DB_driver.php @@ -215,14 +215,20 @@ class CI_DB_driver { } return FALSE; } - - if ($this->dbdriver == 'oci8') + + // 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'); + + if (in_array($this->dbdriver, $driver_version_exceptions)) { return $sql; } - - $query = $this->query($sql); - return $query->row('ver'); + else + { + $query = $this->query($sql); + return $query->row('ver'); + } } // -------------------------------------------------------------------- -- cgit v1.2.3-24-g4f1b From 82d6ec41b5029141d10f30f5f6a791bbf7d14693 Mon Sep 17 00:00:00 2001 From: Derek Allard Date: Tue, 22 Dec 2009 13:53:53 +0000 Subject: Added "is_object" into the list of unit tests capable of being run. --- system/libraries/Unit_test.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system') diff --git a/system/libraries/Unit_test.php b/system/libraries/Unit_test.php index d1db6297b..29a7fa383 100644 --- a/system/libraries/Unit_test.php +++ b/system/libraries/Unit_test.php @@ -59,7 +59,7 @@ class CI_Unit_test { return FALSE; } - if (in_array($expected, array('is_string', 'is_bool', 'is_true', 'is_false', 'is_int', 'is_numeric', 'is_float', 'is_double', 'is_array', 'is_null'), TRUE)) + if (in_array($expected, array('is_object', 'is_string', 'is_bool', 'is_true', 'is_false', 'is_int', 'is_numeric', 'is_float', 'is_double', 'is_array', 'is_null'), TRUE)) { $expected = str_replace('is_float', 'is_double', $expected); $result = ($expected($test)) ? TRUE : FALSE; -- cgit v1.2.3-24-g4f1b From 42e74bc677f3f59d6c6a77d371b70c8365ce2e27 Mon Sep 17 00:00:00 2001 From: Pascal Kriete Date: Wed, 23 Dec 2009 16:44:07 +0000 Subject: tweaking the regex for reduce_double_slashes to correctly handle duplicates at the beginning of the string --- system/helpers/string_helper.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system') diff --git a/system/helpers/string_helper.php b/system/helpers/string_helper.php index 3f7f09a15..dbfa0c41a 100644 --- a/system/helpers/string_helper.php +++ b/system/helpers/string_helper.php @@ -140,7 +140,7 @@ if ( ! function_exists('reduce_double_slashes')) { function reduce_double_slashes($str) { - return preg_replace("#([^:])//+#", "\\1/", $str); + return preg_replace("#(^|[^:])//+#", "\\1/", $str); } } -- cgit v1.2.3-24-g4f1b From 7f3719faf120dc15f3d7b45e132ab3192f60ad62 Mon Sep 17 00:00:00 2001 From: Derek Jones Date: Tue, 5 Jan 2010 13:35:37 +0000 Subject: updated copyrights --- system/codeigniter/Base4.php | 2 +- system/codeigniter/Base5.php | 2 +- system/codeigniter/CodeIgniter.php | 2 +- system/codeigniter/Common.php | 2 +- system/codeigniter/Compat.php | 2 +- system/database/DB.php | 2 +- system/database/DB_active_rec.php | 2 +- system/database/DB_cache.php | 2 +- system/database/DB_driver.php | 2 +- system/database/DB_forge.php | 2 +- system/database/DB_result.php | 2 +- system/database/DB_utility.php | 2 +- system/database/drivers/mssql/mssql_driver.php | 2 +- system/database/drivers/mssql/mssql_forge.php | 2 +- system/database/drivers/mssql/mssql_result.php | 2 +- system/database/drivers/mssql/mssql_utility.php | 2 +- system/database/drivers/mysql/mysql_driver.php | 2 +- system/database/drivers/mysql/mysql_forge.php | 2 +- system/database/drivers/mysql/mysql_result.php | 2 +- system/database/drivers/mysql/mysql_utility.php | 2 +- system/database/drivers/mysqli/mysqli_driver.php | 2 +- system/database/drivers/mysqli/mysqli_forge.php | 2 +- system/database/drivers/mysqli/mysqli_result.php | 2 +- system/database/drivers/mysqli/mysqli_utility.php | 2 +- system/database/drivers/oci8/oci8_driver.php | 2 +- system/database/drivers/oci8/oci8_forge.php | 2 +- system/database/drivers/oci8/oci8_result.php | 2 +- system/database/drivers/oci8/oci8_utility.php | 2 +- system/database/drivers/odbc/odbc_driver.php | 2 +- system/database/drivers/odbc/odbc_forge.php | 2 +- system/database/drivers/odbc/odbc_result.php | 2 +- system/database/drivers/odbc/odbc_utility.php | 2 +- system/database/drivers/postgre/postgre_driver.php | 2 +- system/database/drivers/postgre/postgre_forge.php | 2 +- system/database/drivers/postgre/postgre_result.php | 2 +- system/database/drivers/postgre/postgre_utility.php | 2 +- system/database/drivers/sqlite/sqlite_driver.php | 2 +- system/database/drivers/sqlite/sqlite_forge.php | 2 +- system/database/drivers/sqlite/sqlite_result.php | 2 +- system/database/drivers/sqlite/sqlite_utility.php | 2 +- system/helpers/array_helper.php | 2 +- system/helpers/compatibility_helper.php | 2 +- system/helpers/cookie_helper.php | 2 +- system/helpers/date_helper.php | 2 +- system/helpers/directory_helper.php | 2 +- system/helpers/download_helper.php | 2 +- system/helpers/email_helper.php | 2 +- system/helpers/file_helper.php | 2 +- system/helpers/form_helper.php | 2 +- system/helpers/html_helper.php | 2 +- system/helpers/inflector_helper.php | 2 +- system/helpers/language_helper.php | 2 +- system/helpers/number_helper.php | 2 +- system/helpers/path_helper.php | 2 +- system/helpers/security_helper.php | 2 +- system/helpers/smiley_helper.php | 2 +- system/helpers/string_helper.php | 2 +- system/helpers/text_helper.php | 2 +- system/helpers/typography_helper.php | 2 +- system/helpers/url_helper.php | 2 +- system/helpers/xml_helper.php | 2 +- system/libraries/Benchmark.php | 2 +- system/libraries/Calendar.php | 2 +- system/libraries/Cart.php | 2 +- system/libraries/Config.php | 2 +- system/libraries/Controller.php | 2 +- system/libraries/Email.php | 2 +- system/libraries/Encrypt.php | 2 +- system/libraries/Exceptions.php | 2 +- system/libraries/Form_validation.php | 2 +- system/libraries/Ftp.php | 2 +- system/libraries/Hooks.php | 2 +- system/libraries/Image_lib.php | 2 +- system/libraries/Input.php | 2 +- system/libraries/Language.php | 2 +- system/libraries/Loader.php | 2 +- system/libraries/Log.php | 2 +- system/libraries/Model.php | 2 +- system/libraries/Output.php | 2 +- system/libraries/Pagination.php | 2 +- system/libraries/Parser.php | 2 +- system/libraries/Profiler.php | 2 +- system/libraries/Router.php | 2 +- system/libraries/Session.php | 2 +- system/libraries/Sha1.php | 2 +- system/libraries/Table.php | 2 +- system/libraries/Trackback.php | 2 +- system/libraries/Typography.php | 2 +- system/libraries/URI.php | 2 +- system/libraries/Unit_test.php | 2 +- system/libraries/Upload.php | 2 +- system/libraries/User_agent.php | 2 +- system/libraries/Validation.php | 2 +- system/libraries/Xmlrpc.php | 2 +- system/libraries/Xmlrpcs.php | 2 +- system/libraries/Zip.php | 2 +- system/plugins/captcha_pi.php | 2 +- system/plugins/js_calendar_pi.php | 2 +- system/scaffolding/Scaffolding.php | 2 +- 99 files changed, 99 insertions(+), 99 deletions(-) (limited to 'system') diff --git a/system/codeigniter/Base4.php b/system/codeigniter/Base4.php index 91a435025..3561c2564 100644 --- a/system/codeigniter/Base4.php +++ b/system/codeigniter/Base4.php @@ -6,7 +6,7 @@ * * @package CodeIgniter * @author ExpressionEngine Dev Team - * @copyright Copyright (c) 2008 - 2009, EllisLab, Inc. + * @copyright Copyright (c) 2008 - 2010, EllisLab, Inc. * @license http://codeigniter.com/user_guide/license.html * @link http://codeigniter.com * @since Version 1.3 diff --git a/system/codeigniter/Base5.php b/system/codeigniter/Base5.php index a2cca72cc..5d944ae5a 100644 --- a/system/codeigniter/Base5.php +++ b/system/codeigniter/Base5.php @@ -6,7 +6,7 @@ * * @package CodeIgniter * @author ExpressionEngine Dev Team - * @copyright Copyright (c) 2008 - 2009, EllisLab, Inc. + * @copyright Copyright (c) 2008 - 2010, EllisLab, Inc. * @license http://codeigniter.com/user_guide/license.html * @link http://codeigniter.com * @since Version 1.3 diff --git a/system/codeigniter/CodeIgniter.php b/system/codeigniter/CodeIgniter.php index dac137bf6..5d5bb144b 100644 --- a/system/codeigniter/CodeIgniter.php +++ b/system/codeigniter/CodeIgniter.php @@ -6,7 +6,7 @@ * * @package CodeIgniter * @author ExpressionEngine Dev Team - * @copyright Copyright (c) 2008 - 2009, EllisLab, Inc. + * @copyright Copyright (c) 2008 - 2010, EllisLab, Inc. * @license http://codeigniter.com/user_guide/license.html * @link http://codeigniter.com * @since Version 1.0 diff --git a/system/codeigniter/Common.php b/system/codeigniter/Common.php index 73ff0196f..9a35062a4 100644 --- a/system/codeigniter/Common.php +++ b/system/codeigniter/Common.php @@ -6,7 +6,7 @@ * * @package CodeIgniter * @author ExpressionEngine Dev Team - * @copyright Copyright (c) 2008 - 2009, EllisLab, Inc. + * @copyright Copyright (c) 2008 - 2010, EllisLab, Inc. * @license http://codeigniter.com/user_guide/license.html * @link http://codeigniter.com * @since Version 1.0 diff --git a/system/codeigniter/Compat.php b/system/codeigniter/Compat.php index 958ab4c0c..40017a93b 100644 --- a/system/codeigniter/Compat.php +++ b/system/codeigniter/Compat.php @@ -6,7 +6,7 @@ * * @package CodeIgniter * @author ExpressionEngine Dev Team - * @copyright Copyright (c) 2008 - 2009, EllisLab, Inc. + * @copyright Copyright (c) 2008 - 2010, EllisLab, Inc. * @license http://codeigniter.com/user_guide/license.html * @link http://codeigniter.com * @since Version 1.0 diff --git a/system/database/DB.php b/system/database/DB.php index 0451c18e6..6930411c7 100644 --- a/system/database/DB.php +++ b/system/database/DB.php @@ -6,7 +6,7 @@ * * @package CodeIgniter * @author ExpressionEngine Dev Team - * @copyright Copyright (c) 2008 - 2009, EllisLab, Inc. + * @copyright Copyright (c) 2008 - 2010, EllisLab, Inc. * @license http://codeigniter.com/user_guide/license.html * @link http://codeigniter.com * @since Version 1.0 diff --git a/system/database/DB_active_rec.php b/system/database/DB_active_rec.php index 07021999f..bf4d5117e 100644 --- a/system/database/DB_active_rec.php +++ b/system/database/DB_active_rec.php @@ -6,7 +6,7 @@ * * @package CodeIgniter * @author ExpressionEngine Dev Team - * @copyright Copyright (c) 2008 - 2009, EllisLab, Inc. + * @copyright Copyright (c) 2008 - 2010, EllisLab, Inc. * @license http://codeigniter.com/user_guide/license.html * @link http://codeigniter.com * @since Version 1.0 diff --git a/system/database/DB_cache.php b/system/database/DB_cache.php index f01bc8212..2606df842 100644 --- a/system/database/DB_cache.php +++ b/system/database/DB_cache.php @@ -6,7 +6,7 @@ * * @package CodeIgniter * @author ExpressionEngine Dev Team - * @copyright Copyright (c) 2008 - 2009, EllisLab, Inc. + * @copyright Copyright (c) 2008 - 2010, EllisLab, Inc. * @license http://codeigniter.com/user_guide/license.html * @link http://codeigniter.com * @since Version 1.0 diff --git a/system/database/DB_driver.php b/system/database/DB_driver.php index aee06205b..390d5570b 100644 --- a/system/database/DB_driver.php +++ b/system/database/DB_driver.php @@ -6,7 +6,7 @@ * * @package CodeIgniter * @author ExpressionEngine Dev Team - * @copyright Copyright (c) 2008 - 2009, EllisLab, Inc. + * @copyright Copyright (c) 2008 - 2010, EllisLab, Inc. * @license http://codeigniter.com/user_guide/license.html * @link http://codeigniter.com * @since Version 1.0 diff --git a/system/database/DB_forge.php b/system/database/DB_forge.php index 4050e300f..c5931db27 100644 --- a/system/database/DB_forge.php +++ b/system/database/DB_forge.php @@ -6,7 +6,7 @@ * * @package CodeIgniter * @author ExpressionEngine Dev Team - * @copyright Copyright (c) 2008 - 2009, EllisLab, Inc. + * @copyright Copyright (c) 2008 - 2010, EllisLab, Inc. * @license http://codeigniter.com/user_guide/license.html * @link http://codeigniter.com * @since Version 1.0 diff --git a/system/database/DB_result.php b/system/database/DB_result.php index 4614e29f6..b9e64feeb 100644 --- a/system/database/DB_result.php +++ b/system/database/DB_result.php @@ -6,7 +6,7 @@ * * @package CodeIgniter * @author ExpressionEngine Dev Team - * @copyright Copyright (c) 2008 - 2009, EllisLab, Inc. + * @copyright Copyright (c) 2008 - 2010, EllisLab, Inc. * @license http://codeigniter.com/user_guide/license.html * @link http://codeigniter.com * @since Version 1.0 diff --git a/system/database/DB_utility.php b/system/database/DB_utility.php index 33c68faea..94e7a0bda 100644 --- a/system/database/DB_utility.php +++ b/system/database/DB_utility.php @@ -6,7 +6,7 @@ * * @package CodeIgniter * @author ExpressionEngine Dev Team - * @copyright Copyright (c) 2008 - 2009, EllisLab, Inc. + * @copyright Copyright (c) 2008 - 2010, EllisLab, Inc. * @license http://codeigniter.com/user_guide/license.html * @link http://codeigniter.com * @since Version 1.0 diff --git a/system/database/drivers/mssql/mssql_driver.php b/system/database/drivers/mssql/mssql_driver.php index 97ac971bd..f301ba533 100644 --- a/system/database/drivers/mssql/mssql_driver.php +++ b/system/database/drivers/mssql/mssql_driver.php @@ -6,7 +6,7 @@ * * @package CodeIgniter * @author ExpressionEngine Dev Team - * @copyright Copyright (c) 2008 - 2009, EllisLab, Inc. + * @copyright Copyright (c) 2008 - 2010, EllisLab, Inc. * @license http://codeigniter.com/user_guide/license.html * @link http://codeigniter.com * @since Version 1.0 diff --git a/system/database/drivers/mssql/mssql_forge.php b/system/database/drivers/mssql/mssql_forge.php index 632b4d907..f6a17811f 100644 --- a/system/database/drivers/mssql/mssql_forge.php +++ b/system/database/drivers/mssql/mssql_forge.php @@ -6,7 +6,7 @@ * * @package CodeIgniter * @author ExpressionEngine Dev Team - * @copyright Copyright (c) 2008 - 2009, EllisLab, Inc. + * @copyright Copyright (c) 2008 - 2010, EllisLab, Inc. * @license http://codeigniter.com/user_guide/license.html * @link http://codeigniter.com * @since Version 1.0 diff --git a/system/database/drivers/mssql/mssql_result.php b/system/database/drivers/mssql/mssql_result.php index a56a3a9e2..e7b338045 100644 --- a/system/database/drivers/mssql/mssql_result.php +++ b/system/database/drivers/mssql/mssql_result.php @@ -6,7 +6,7 @@ * * @package CodeIgniter * @author ExpressionEngine Dev Team - * @copyright Copyright (c) 2008 - 2009, EllisLab, Inc. + * @copyright Copyright (c) 2008 - 2010, EllisLab, Inc. * @license http://codeigniter.com/user_guide/license.html * @link http://codeigniter.com * @since Version 1.0 diff --git a/system/database/drivers/mssql/mssql_utility.php b/system/database/drivers/mssql/mssql_utility.php index 9fa257a69..da887b815 100644 --- a/system/database/drivers/mssql/mssql_utility.php +++ b/system/database/drivers/mssql/mssql_utility.php @@ -6,7 +6,7 @@ * * @package CodeIgniter * @author ExpressionEngine Dev Team - * @copyright Copyright (c) 2008 - 2009, EllisLab, Inc. + * @copyright Copyright (c) 2008 - 2010, EllisLab, Inc. * @license http://codeigniter.com/user_guide/license.html * @link http://codeigniter.com * @since Version 1.0 diff --git a/system/database/drivers/mysql/mysql_driver.php b/system/database/drivers/mysql/mysql_driver.php index fe1859805..85a6ef4a0 100644 --- a/system/database/drivers/mysql/mysql_driver.php +++ b/system/database/drivers/mysql/mysql_driver.php @@ -6,7 +6,7 @@ * * @package CodeIgniter * @author ExpressionEngine Dev Team - * @copyright Copyright (c) 2008 - 2009, EllisLab, Inc. + * @copyright Copyright (c) 2008 - 2010, EllisLab, Inc. * @license http://codeigniter.com/user_guide/license.html * @link http://codeigniter.com * @since Version 1.0 diff --git a/system/database/drivers/mysql/mysql_forge.php b/system/database/drivers/mysql/mysql_forge.php index d343b36a0..ccacf99f8 100644 --- a/system/database/drivers/mysql/mysql_forge.php +++ b/system/database/drivers/mysql/mysql_forge.php @@ -6,7 +6,7 @@ * * @package CodeIgniter * @author ExpressionEngine Dev Team - * @copyright Copyright (c) 2008 - 2009, EllisLab, Inc. + * @copyright Copyright (c) 2008 - 2010, EllisLab, Inc. * @license http://codeigniter.com/user_guide/license.html * @link http://codeigniter.com * @since Version 1.0 diff --git a/system/database/drivers/mysql/mysql_result.php b/system/database/drivers/mysql/mysql_result.php index 2e9550702..acc586626 100644 --- a/system/database/drivers/mysql/mysql_result.php +++ b/system/database/drivers/mysql/mysql_result.php @@ -6,7 +6,7 @@ * * @package CodeIgniter * @author ExpressionEngine Dev Team - * @copyright Copyright (c) 2008 - 2009, EllisLab, Inc. + * @copyright Copyright (c) 2008 - 2010, EllisLab, Inc. * @license http://codeigniter.com/user_guide/license.html * @link http://codeigniter.com * @since Version 1.0 diff --git a/system/database/drivers/mysql/mysql_utility.php b/system/database/drivers/mysql/mysql_utility.php index 2c8b264ce..3277b0ff7 100644 --- a/system/database/drivers/mysql/mysql_utility.php +++ b/system/database/drivers/mysql/mysql_utility.php @@ -6,7 +6,7 @@ * * @package CodeIgniter * @author ExpressionEngine Dev Team - * @copyright Copyright (c) 2008 - 2009, EllisLab, Inc. + * @copyright Copyright (c) 2008 - 2010, EllisLab, Inc. * @license http://codeigniter.com/user_guide/license.html * @link http://codeigniter.com * @since Version 1.0 diff --git a/system/database/drivers/mysqli/mysqli_driver.php b/system/database/drivers/mysqli/mysqli_driver.php index 488b074a3..5d7200fbd 100644 --- a/system/database/drivers/mysqli/mysqli_driver.php +++ b/system/database/drivers/mysqli/mysqli_driver.php @@ -6,7 +6,7 @@ * * @package CodeIgniter * @author ExpressionEngine Dev Team - * @copyright Copyright (c) 2008 - 2009, EllisLab, Inc. + * @copyright Copyright (c) 2008 - 2010, EllisLab, Inc. * @license http://codeigniter.com/user_guide/license.html * @link http://codeigniter.com * @since Version 1.0 diff --git a/system/database/drivers/mysqli/mysqli_forge.php b/system/database/drivers/mysqli/mysqli_forge.php index 0992274e9..262d491ed 100644 --- a/system/database/drivers/mysqli/mysqli_forge.php +++ b/system/database/drivers/mysqli/mysqli_forge.php @@ -6,7 +6,7 @@ * * @package CodeIgniter * @author ExpressionEngine Dev Team - * @copyright Copyright (c) 2008 - 2009, EllisLab, Inc. + * @copyright Copyright (c) 2008 - 2010, EllisLab, Inc. * @license http://codeigniter.com/user_guide/license.html * @link http://codeigniter.com * @since Version 1.0 diff --git a/system/database/drivers/mysqli/mysqli_result.php b/system/database/drivers/mysqli/mysqli_result.php index 00fc0db47..81d22cc9c 100644 --- a/system/database/drivers/mysqli/mysqli_result.php +++ b/system/database/drivers/mysqli/mysqli_result.php @@ -6,7 +6,7 @@ * * @package CodeIgniter * @author ExpressionEngine Dev Team - * @copyright Copyright (c) 2008 - 2009, EllisLab, Inc. + * @copyright Copyright (c) 2008 - 2010, EllisLab, Inc. * @license http://codeigniter.com/user_guide/license.html * @link http://codeigniter.com * @since Version 1.0 diff --git a/system/database/drivers/mysqli/mysqli_utility.php b/system/database/drivers/mysqli/mysqli_utility.php index 7ebda4c56..44fd0f7aa 100644 --- a/system/database/drivers/mysqli/mysqli_utility.php +++ b/system/database/drivers/mysqli/mysqli_utility.php @@ -6,7 +6,7 @@ * * @package CodeIgniter * @author ExpressionEngine Dev Team - * @copyright Copyright (c) 2008 - 2009, EllisLab, Inc. + * @copyright Copyright (c) 2008 - 2010, EllisLab, Inc. * @license http://codeigniter.com/user_guide/license.html * @link http://codeigniter.com * @since Version 1.0 diff --git a/system/database/drivers/oci8/oci8_driver.php b/system/database/drivers/oci8/oci8_driver.php index 614571940..758192358 100644 --- a/system/database/drivers/oci8/oci8_driver.php +++ b/system/database/drivers/oci8/oci8_driver.php @@ -6,7 +6,7 @@ * * @package CodeIgniter * @author ExpressionEngine Dev Team - * @copyright Copyright (c) 2008 - 2009, EllisLab, Inc. + * @copyright Copyright (c) 2008 - 2010, EllisLab, Inc. * @license http://codeigniter.com/user_guide/license.html * @link http://codeigniter.com * @since Version 1.0 diff --git a/system/database/drivers/oci8/oci8_forge.php b/system/database/drivers/oci8/oci8_forge.php index c3e9cb98f..d77ed8de6 100644 --- a/system/database/drivers/oci8/oci8_forge.php +++ b/system/database/drivers/oci8/oci8_forge.php @@ -6,7 +6,7 @@ * * @package CodeIgniter * @author ExpressionEngine Dev Team - * @copyright Copyright (c) 2008 - 2009, EllisLab, Inc. + * @copyright Copyright (c) 2008 - 2010, EllisLab, Inc. * @license http://codeigniter.com/user_guide/license.html * @link http://codeigniter.com * @since Version 1.0 diff --git a/system/database/drivers/oci8/oci8_result.php b/system/database/drivers/oci8/oci8_result.php index 1d0b7db26..cab538e21 100644 --- a/system/database/drivers/oci8/oci8_result.php +++ b/system/database/drivers/oci8/oci8_result.php @@ -6,7 +6,7 @@ * * @package CodeIgniter * @author ExpressionEngine Dev Team - * @copyright Copyright (c) 2008 - 2009, EllisLab, Inc. + * @copyright Copyright (c) 2008 - 2010, EllisLab, Inc. * @license http://codeigniter.com/user_guide/license.html * @link http://codeigniter.com * @since Version 1.0 diff --git a/system/database/drivers/oci8/oci8_utility.php b/system/database/drivers/oci8/oci8_utility.php index c8049c248..74670eaab 100644 --- a/system/database/drivers/oci8/oci8_utility.php +++ b/system/database/drivers/oci8/oci8_utility.php @@ -6,7 +6,7 @@ * * @package CodeIgniter * @author ExpressionEngine Dev Team - * @copyright Copyright (c) 2008 - 2009, EllisLab, Inc. + * @copyright Copyright (c) 2008 - 2010, EllisLab, Inc. * @license http://codeigniter.com/user_guide/license.html * @link http://codeigniter.com * @since Version 1.0 diff --git a/system/database/drivers/odbc/odbc_driver.php b/system/database/drivers/odbc/odbc_driver.php index dacbaaba9..6cb3080d4 100644 --- a/system/database/drivers/odbc/odbc_driver.php +++ b/system/database/drivers/odbc/odbc_driver.php @@ -6,7 +6,7 @@ * * @package CodeIgniter * @author ExpressionEngine Dev Team - * @copyright Copyright (c) 2008 - 2009, EllisLab, Inc. + * @copyright Copyright (c) 2008 - 2010, EllisLab, Inc. * @license http://codeigniter.com/user_guide/license.html * @link http://codeigniter.com * @since Version 1.0 diff --git a/system/database/drivers/odbc/odbc_forge.php b/system/database/drivers/odbc/odbc_forge.php index 99cb282af..1ae559b6e 100644 --- a/system/database/drivers/odbc/odbc_forge.php +++ b/system/database/drivers/odbc/odbc_forge.php @@ -6,7 +6,7 @@ * * @package CodeIgniter * @author ExpressionEngine Dev Team - * @copyright Copyright (c) 2008 - 2009, EllisLab, Inc. + * @copyright Copyright (c) 2008 - 2010, EllisLab, Inc. * @license http://codeigniter.com/user_guide/license.html * @link http://codeigniter.com * @since Version 1.0 diff --git a/system/database/drivers/odbc/odbc_result.php b/system/database/drivers/odbc/odbc_result.php index d6f15015e..5ae46df62 100644 --- a/system/database/drivers/odbc/odbc_result.php +++ b/system/database/drivers/odbc/odbc_result.php @@ -6,7 +6,7 @@ * * @package CodeIgniter * @author ExpressionEngine Dev Team - * @copyright Copyright (c) 2008 - 2009, EllisLab, Inc. + * @copyright Copyright (c) 2008 - 2010, EllisLab, Inc. * @license http://codeigniter.com/user_guide/license.html * @link http://codeigniter.com * @since Version 1.0 diff --git a/system/database/drivers/odbc/odbc_utility.php b/system/database/drivers/odbc/odbc_utility.php index 85707a073..4e6848e82 100644 --- a/system/database/drivers/odbc/odbc_utility.php +++ b/system/database/drivers/odbc/odbc_utility.php @@ -6,7 +6,7 @@ * * @package CodeIgniter * @author ExpressionEngine Dev Team - * @copyright Copyright (c) 2008 - 2009, EllisLab, Inc. + * @copyright Copyright (c) 2008 - 2010, EllisLab, Inc. * @license http://codeigniter.com/user_guide/license.html * @link http://codeigniter.com * @since Version 1.0 diff --git a/system/database/drivers/postgre/postgre_driver.php b/system/database/drivers/postgre/postgre_driver.php index 9258da684..bac179d40 100644 --- a/system/database/drivers/postgre/postgre_driver.php +++ b/system/database/drivers/postgre/postgre_driver.php @@ -6,7 +6,7 @@ * * @package CodeIgniter * @author ExpressionEngine Dev Team - * @copyright Copyright (c) 2008 - 2009, EllisLab, Inc. + * @copyright Copyright (c) 2008 - 2010, EllisLab, Inc. * @license http://codeigniter.com/user_guide/license.html * @link http://codeigniter.com * @since Version 1.0 diff --git a/system/database/drivers/postgre/postgre_forge.php b/system/database/drivers/postgre/postgre_forge.php index 471dd80c9..c98ef425d 100644 --- a/system/database/drivers/postgre/postgre_forge.php +++ b/system/database/drivers/postgre/postgre_forge.php @@ -6,7 +6,7 @@ * * @package CodeIgniter * @author ExpressionEngine Dev Team - * @copyright Copyright (c) 2008 - 2009, EllisLab, Inc. + * @copyright Copyright (c) 2008 - 2010, EllisLab, Inc. * @license http://codeigniter.com/user_guide/license.html * @link http://codeigniter.com * @since Version 1.0 diff --git a/system/database/drivers/postgre/postgre_result.php b/system/database/drivers/postgre/postgre_result.php index 8e45eb1cf..545f413e8 100644 --- a/system/database/drivers/postgre/postgre_result.php +++ b/system/database/drivers/postgre/postgre_result.php @@ -6,7 +6,7 @@ * * @package CodeIgniter * @author ExpressionEngine Dev Team - * @copyright Copyright (c) 2008 - 2009, EllisLab, Inc. + * @copyright Copyright (c) 2008 - 2010, EllisLab, Inc. * @license http://codeigniter.com/user_guide/license.html * @link http://codeigniter.com * @since Version 1.0 diff --git a/system/database/drivers/postgre/postgre_utility.php b/system/database/drivers/postgre/postgre_utility.php index 235954fa6..dda22ddb0 100644 --- a/system/database/drivers/postgre/postgre_utility.php +++ b/system/database/drivers/postgre/postgre_utility.php @@ -6,7 +6,7 @@ * * @package CodeIgniter * @author ExpressionEngine Dev Team - * @copyright Copyright (c) 2008 - 2009, EllisLab, Inc. + * @copyright Copyright (c) 2008 - 2010, EllisLab, Inc. * @license http://codeigniter.com/user_guide/license.html * @link http://codeigniter.com * @since Version 1.0 diff --git a/system/database/drivers/sqlite/sqlite_driver.php b/system/database/drivers/sqlite/sqlite_driver.php index 0cb799775..05e38848a 100644 --- a/system/database/drivers/sqlite/sqlite_driver.php +++ b/system/database/drivers/sqlite/sqlite_driver.php @@ -6,7 +6,7 @@ * * @package CodeIgniter * @author ExpressionEngine Dev Team - * @copyright Copyright (c) 2008 - 2009, EllisLab, Inc. + * @copyright Copyright (c) 2008 - 2010, EllisLab, Inc. * @license http://codeigniter.com/user_guide/license.html * @link http://codeigniter.com * @since Version 1.0 diff --git a/system/database/drivers/sqlite/sqlite_forge.php b/system/database/drivers/sqlite/sqlite_forge.php index 0688ba368..b7d25e755 100644 --- a/system/database/drivers/sqlite/sqlite_forge.php +++ b/system/database/drivers/sqlite/sqlite_forge.php @@ -6,7 +6,7 @@ * * @package CodeIgniter * @author ExpressionEngine Dev Team - * @copyright Copyright (c) 2008 - 2009, EllisLab, Inc. + * @copyright Copyright (c) 2008 - 2010, EllisLab, Inc. * @license http://codeigniter.com/user_guide/license.html * @link http://codeigniter.com * @since Version 1.0 diff --git a/system/database/drivers/sqlite/sqlite_result.php b/system/database/drivers/sqlite/sqlite_result.php index c1c24c78e..7b0631221 100644 --- a/system/database/drivers/sqlite/sqlite_result.php +++ b/system/database/drivers/sqlite/sqlite_result.php @@ -6,7 +6,7 @@ * * @package CodeIgniter * @author ExpressionEngine Dev Team - * @copyright Copyright (c) 2008 - 2009, EllisLab, Inc. + * @copyright Copyright (c) 2008 - 2010, EllisLab, Inc. * @license http://codeigniter.com/user_guide/license.html * @link http://codeigniter.com * @since Version 1.0 diff --git a/system/database/drivers/sqlite/sqlite_utility.php b/system/database/drivers/sqlite/sqlite_utility.php index f66464e3e..5629dac99 100644 --- a/system/database/drivers/sqlite/sqlite_utility.php +++ b/system/database/drivers/sqlite/sqlite_utility.php @@ -6,7 +6,7 @@ * * @package CodeIgniter * @author ExpressionEngine Dev Team - * @copyright Copyright (c) 2008 - 2009, EllisLab, Inc. + * @copyright Copyright (c) 2008 - 2010, EllisLab, Inc. * @license http://codeigniter.com/user_guide/license.html * @link http://codeigniter.com * @since Version 1.0 diff --git a/system/helpers/array_helper.php b/system/helpers/array_helper.php index 39d0c88c6..b7289900f 100644 --- a/system/helpers/array_helper.php +++ b/system/helpers/array_helper.php @@ -6,7 +6,7 @@ * * @package CodeIgniter * @author ExpressionEngine Dev Team - * @copyright Copyright (c) 2008 - 2009, EllisLab, Inc. + * @copyright Copyright (c) 2008 - 2010, EllisLab, Inc. * @license http://codeigniter.com/user_guide/license.html * @link http://codeigniter.com * @since Version 1.0 diff --git a/system/helpers/compatibility_helper.php b/system/helpers/compatibility_helper.php index c217f7f52..e7b21c660 100644 --- a/system/helpers/compatibility_helper.php +++ b/system/helpers/compatibility_helper.php @@ -6,7 +6,7 @@ * * @package CodeIgniter * @author ExpressionEngine Dev Team - * @copyright Copyright (c) 2008 - 2009, EllisLab, Inc. + * @copyright Copyright (c) 2008 - 2010, EllisLab, Inc. * @license http://codeigniter.com/user_guide/license.html * @link http://codeigniter.com * @since Version 1.0 diff --git a/system/helpers/cookie_helper.php b/system/helpers/cookie_helper.php index 7607ffb4a..40afadb57 100644 --- a/system/helpers/cookie_helper.php +++ b/system/helpers/cookie_helper.php @@ -6,7 +6,7 @@ * * @package CodeIgniter * @author ExpressionEngine Dev Team - * @copyright Copyright (c) 2008 - 2009, EllisLab, Inc. + * @copyright Copyright (c) 2008 - 2010, EllisLab, Inc. * @license http://codeigniter.com/user_guide/license.html * @link http://codeigniter.com * @since Version 1.0 diff --git a/system/helpers/date_helper.php b/system/helpers/date_helper.php index fae9e66e4..0e9781666 100644 --- a/system/helpers/date_helper.php +++ b/system/helpers/date_helper.php @@ -6,7 +6,7 @@ * * @package CodeIgniter * @author ExpressionEngine Dev Team - * @copyright Copyright (c) 2008 - 2009, EllisLab, Inc. + * @copyright Copyright (c) 2008 - 2010, EllisLab, Inc. * @license http://codeigniter.com/user_guide/license.html * @link http://codeigniter.com * @since Version 1.0 diff --git a/system/helpers/directory_helper.php b/system/helpers/directory_helper.php index a6fb7841e..791cf0d10 100644 --- a/system/helpers/directory_helper.php +++ b/system/helpers/directory_helper.php @@ -6,7 +6,7 @@ * * @package CodeIgniter * @author ExpressionEngine Dev Team - * @copyright Copyright (c) 2008 - 2009, EllisLab, Inc. + * @copyright Copyright (c) 2008 - 2010, EllisLab, Inc. * @license http://codeigniter.com/user_guide/license.html * @link http://codeigniter.com * @since Version 1.0 diff --git a/system/helpers/download_helper.php b/system/helpers/download_helper.php index a8f7b1a7f..638ebaa88 100644 --- a/system/helpers/download_helper.php +++ b/system/helpers/download_helper.php @@ -6,7 +6,7 @@ * * @package CodeIgniter * @author ExpressionEngine Dev Team - * @copyright Copyright (c) 2008 - 2009, EllisLab, Inc. + * @copyright Copyright (c) 2008 - 2010, EllisLab, Inc. * @license http://codeigniter.com/user_guide/license.html * @link http://codeigniter.com * @since Version 1.0 diff --git a/system/helpers/email_helper.php b/system/helpers/email_helper.php index df602b115..046562a91 100644 --- a/system/helpers/email_helper.php +++ b/system/helpers/email_helper.php @@ -6,7 +6,7 @@ * * @package CodeIgniter * @author ExpressionEngine Dev Team - * @copyright Copyright (c) 2008 - 2009, EllisLab, Inc. + * @copyright Copyright (c) 2008 - 2010, EllisLab, Inc. * @license http://codeigniter.com/user_guide/license.html * @link http://codeigniter.com * @since Version 1.0 diff --git a/system/helpers/file_helper.php b/system/helpers/file_helper.php index 41ec2648e..114b2927a 100644 --- a/system/helpers/file_helper.php +++ b/system/helpers/file_helper.php @@ -6,7 +6,7 @@ * * @package CodeIgniter * @author ExpressionEngine Dev Team - * @copyright Copyright (c) 2008 - 2009, EllisLab, Inc. + * @copyright Copyright (c) 2008 - 2010, EllisLab, Inc. * @license http://codeigniter.com/user_guide/license.html * @link http://codeigniter.com * @since Version 1.0 diff --git a/system/helpers/form_helper.php b/system/helpers/form_helper.php index 02e2edd3e..c78b805e5 100644 --- a/system/helpers/form_helper.php +++ b/system/helpers/form_helper.php @@ -6,7 +6,7 @@ * * @package CodeIgniter * @author ExpressionEngine Dev Team - * @copyright Copyright (c) 2008 - 2009, EllisLab, Inc. + * @copyright Copyright (c) 2008 - 2010, EllisLab, Inc. * @license http://codeigniter.com/user_guide/license.html * @link http://codeigniter.com * @since Version 1.0 diff --git a/system/helpers/html_helper.php b/system/helpers/html_helper.php index b55ec88ca..d5bdd080c 100644 --- a/system/helpers/html_helper.php +++ b/system/helpers/html_helper.php @@ -6,7 +6,7 @@ * * @package CodeIgniter * @author ExpressionEngine Dev Team - * @copyright Copyright (c) 2008 - 2009, EllisLab, Inc. + * @copyright Copyright (c) 2008 - 2010, EllisLab, Inc. * @license http://codeigniter.com/user_guide/license.html * @link http://codeigniter.com * @since Version 1.0 diff --git a/system/helpers/inflector_helper.php b/system/helpers/inflector_helper.php index 8db4f3d75..c4c530bc5 100644 --- a/system/helpers/inflector_helper.php +++ b/system/helpers/inflector_helper.php @@ -6,7 +6,7 @@ * * @package CodeIgniter * @author ExpressionEngine Dev Team - * @copyright Copyright (c) 2008 - 2009, EllisLab, Inc. + * @copyright Copyright (c) 2008 - 2010, EllisLab, Inc. * @license http://codeigniter.com/user_guide/license.html * @link http://codeigniter.com * @since Version 1.0 diff --git a/system/helpers/language_helper.php b/system/helpers/language_helper.php index e97a8c78b..442619c93 100644 --- a/system/helpers/language_helper.php +++ b/system/helpers/language_helper.php @@ -6,7 +6,7 @@ * * @package CodeIgniter * @author ExpressionEngine Dev Team - * @copyright Copyright (c) 2008 - 2009, EllisLab, Inc. + * @copyright Copyright (c) 2008 - 2010, EllisLab, Inc. * @license http://codeigniter.com/user_guide/license.html * @link http://codeigniter.com * @since Version 1.0 diff --git a/system/helpers/number_helper.php b/system/helpers/number_helper.php index a041a60b7..cf683f2a1 100644 --- a/system/helpers/number_helper.php +++ b/system/helpers/number_helper.php @@ -6,7 +6,7 @@ * * @package CodeIgniter * @author ExpressionEngine Dev Team - * @copyright Copyright (c) 2008 - 2009, EllisLab, Inc. + * @copyright Copyright (c) 2008 - 2010, EllisLab, Inc. * @license http://codeigniter.com/user_guide/license.html * @link http://codeigniter.com * @since Version 1.0 diff --git a/system/helpers/path_helper.php b/system/helpers/path_helper.php index 502fae4b3..030b6bff1 100644 --- a/system/helpers/path_helper.php +++ b/system/helpers/path_helper.php @@ -6,7 +6,7 @@ * * @package CodeIgniter * @author ExpressionEngine Dev Team - * @copyright Copyright (c) 2008 - 2009, EllisLab, Inc. + * @copyright Copyright (c) 2008 - 2010, EllisLab, Inc. * @license http://codeigniter.com/user_guide/license.html * @link http://codeigniter.com * @since Version 1.0 diff --git a/system/helpers/security_helper.php b/system/helpers/security_helper.php index 8fb53e718..1f0a62906 100644 --- a/system/helpers/security_helper.php +++ b/system/helpers/security_helper.php @@ -6,7 +6,7 @@ * * @package CodeIgniter * @author ExpressionEngine Dev Team - * @copyright Copyright (c) 2008 - 2009, EllisLab, Inc. + * @copyright Copyright (c) 2008 - 2010, EllisLab, Inc. * @license http://codeigniter.com/user_guide/license.html * @link http://codeigniter.com * @since Version 1.0 diff --git a/system/helpers/smiley_helper.php b/system/helpers/smiley_helper.php index ab1f2c27e..931f1308d 100644 --- a/system/helpers/smiley_helper.php +++ b/system/helpers/smiley_helper.php @@ -6,7 +6,7 @@ * * @package CodeIgniter * @author ExpressionEngine Dev Team - * @copyright Copyright (c) 2008 - 2009, EllisLab, Inc. + * @copyright Copyright (c) 2008 - 2010, EllisLab, Inc. * @license http://codeigniter.com/user_guide/license.html * @link http://codeigniter.com * @since Version 1.0 diff --git a/system/helpers/string_helper.php b/system/helpers/string_helper.php index dbfa0c41a..67cbd0eb6 100644 --- a/system/helpers/string_helper.php +++ b/system/helpers/string_helper.php @@ -6,7 +6,7 @@ * * @package CodeIgniter * @author ExpressionEngine Dev Team - * @copyright Copyright (c) 2008 - 2009, EllisLab, Inc. + * @copyright Copyright (c) 2008 - 2010, EllisLab, Inc. * @license http://codeigniter.com/user_guide/license.html * @link http://codeigniter.com * @since Version 1.0 diff --git a/system/helpers/text_helper.php b/system/helpers/text_helper.php index 06910e411..1e672937b 100644 --- a/system/helpers/text_helper.php +++ b/system/helpers/text_helper.php @@ -6,7 +6,7 @@ * * @package CodeIgniter * @author ExpressionEngine Dev Team - * @copyright Copyright (c) 2008 - 2009, EllisLab, Inc. + * @copyright Copyright (c) 2008 - 2010, EllisLab, Inc. * @license http://codeigniter.com/user_guide/license.html * @link http://codeigniter.com * @since Version 1.0 diff --git a/system/helpers/typography_helper.php b/system/helpers/typography_helper.php index 2706d53b0..5621e6dd0 100644 --- a/system/helpers/typography_helper.php +++ b/system/helpers/typography_helper.php @@ -6,7 +6,7 @@ * * @package CodeIgniter * @author ExpressionEngine Dev Team - * @copyright Copyright (c) 2008 - 2009, EllisLab, Inc. + * @copyright Copyright (c) 2008 - 2010, EllisLab, Inc. * @license http://codeigniter.com/user_guide/license.html * @link http://codeigniter.com * @since Version 1.0 diff --git a/system/helpers/url_helper.php b/system/helpers/url_helper.php index 546552a69..90ea9207e 100644 --- a/system/helpers/url_helper.php +++ b/system/helpers/url_helper.php @@ -6,7 +6,7 @@ * * @package CodeIgniter * @author ExpressionEngine Dev Team - * @copyright Copyright (c) 2008 - 2009, EllisLab, Inc. + * @copyright Copyright (c) 2008 - 2010, EllisLab, Inc. * @license http://codeigniter.com/user_guide/license.html * @link http://codeigniter.com * @since Version 1.0 diff --git a/system/helpers/xml_helper.php b/system/helpers/xml_helper.php index 2a4c808ce..712f6777e 100644 --- a/system/helpers/xml_helper.php +++ b/system/helpers/xml_helper.php @@ -6,7 +6,7 @@ * * @package CodeIgniter * @author ExpressionEngine Dev Team - * @copyright Copyright (c) 2008 - 2009, EllisLab, Inc. + * @copyright Copyright (c) 2008 - 2010, EllisLab, Inc. * @license http://codeigniter.com/user_guide/license.html * @link http://codeigniter.com * @since Version 1.0 diff --git a/system/libraries/Benchmark.php b/system/libraries/Benchmark.php index 695029ed4..d485ee21d 100644 --- a/system/libraries/Benchmark.php +++ b/system/libraries/Benchmark.php @@ -6,7 +6,7 @@ * * @package CodeIgniter * @author ExpressionEngine Dev Team - * @copyright Copyright (c) 2008 - 2009, EllisLab, Inc. + * @copyright Copyright (c) 2008 - 2010, EllisLab, Inc. * @license http://codeigniter.com/user_guide/license.html * @link http://codeigniter.com * @since Version 1.0 diff --git a/system/libraries/Calendar.php b/system/libraries/Calendar.php index 68d402254..275bf2451 100644 --- a/system/libraries/Calendar.php +++ b/system/libraries/Calendar.php @@ -6,7 +6,7 @@ * * @package CodeIgniter * @author ExpressionEngine Dev Team - * @copyright Copyright (c) 2008 - 2009, EllisLab, Inc. + * @copyright Copyright (c) 2008 - 2010, EllisLab, Inc. * @license http://codeigniter.com/user_guide/license.html * @link http://codeigniter.com * @since Version 1.0 diff --git a/system/libraries/Cart.php b/system/libraries/Cart.php index 2eb8b75be..643d2eca4 100644 --- a/system/libraries/Cart.php +++ b/system/libraries/Cart.php @@ -6,7 +6,7 @@ * * @package CodeIgniter * @author ExpressionEngine Dev Team - * @copyright Copyright (c) 2006 - 2009, EllisLab, Inc. + * @copyright Copyright (c) 2006 - 2010, EllisLab, Inc. * @license http://codeigniter.com/user_guide/license.html * @link http://codeigniter.com * @since Version 1.0 diff --git a/system/libraries/Config.php b/system/libraries/Config.php index 4ef278635..760120779 100644 --- a/system/libraries/Config.php +++ b/system/libraries/Config.php @@ -6,7 +6,7 @@ * * @package CodeIgniter * @author ExpressionEngine Dev Team - * @copyright Copyright (c) 2008 - 2009, EllisLab, Inc. + * @copyright Copyright (c) 2008 - 2010, EllisLab, Inc. * @license http://codeigniter.com/user_guide/license.html * @link http://codeigniter.com * @since Version 1.0 diff --git a/system/libraries/Controller.php b/system/libraries/Controller.php index 5e93de3bf..c5637c951 100644 --- a/system/libraries/Controller.php +++ b/system/libraries/Controller.php @@ -6,7 +6,7 @@ * * @package CodeIgniter * @author ExpressionEngine Dev Team - * @copyright Copyright (c) 2008 - 2009, EllisLab, Inc. + * @copyright Copyright (c) 2008 - 2010, EllisLab, Inc. * @license http://codeigniter.com/user_guide/license.html * @link http://codeigniter.com * @since Version 1.0 diff --git a/system/libraries/Email.php b/system/libraries/Email.php index 585815934..d0f2ea9a5 100644 --- a/system/libraries/Email.php +++ b/system/libraries/Email.php @@ -6,7 +6,7 @@ * * @package CodeIgniter * @author ExpressionEngine Dev Team - * @copyright Copyright (c) 2008 - 2009, EllisLab, Inc. + * @copyright Copyright (c) 2008 - 2010, EllisLab, Inc. * @license http://codeigniter.com/user_guide/license.html * @link http://codeigniter.com * @since Version 1.0 diff --git a/system/libraries/Encrypt.php b/system/libraries/Encrypt.php index 95c758fb4..c893fbf9e 100644 --- a/system/libraries/Encrypt.php +++ b/system/libraries/Encrypt.php @@ -6,7 +6,7 @@ * * @package CodeIgniter * @author ExpressionEngine Dev Team - * @copyright Copyright (c) 2008 - 2009, EllisLab, Inc. + * @copyright Copyright (c) 2008 - 2010, EllisLab, Inc. * @license http://codeigniter.com/user_guide/license.html * @link http://codeigniter.com * @since Version 1.0 diff --git a/system/libraries/Exceptions.php b/system/libraries/Exceptions.php index 9c655a174..bd567ccdc 100644 --- a/system/libraries/Exceptions.php +++ b/system/libraries/Exceptions.php @@ -6,7 +6,7 @@ * * @package CodeIgniter * @author ExpressionEngine Dev Team - * @copyright Copyright (c) 2008 - 2009, EllisLab, Inc. + * @copyright Copyright (c) 2008 - 2010, EllisLab, Inc. * @license http://codeigniter.com/user_guide/license.html * @link http://codeigniter.com * @since Version 1.0 diff --git a/system/libraries/Form_validation.php b/system/libraries/Form_validation.php index e825b1b32..bb70f0f7f 100644 --- a/system/libraries/Form_validation.php +++ b/system/libraries/Form_validation.php @@ -6,7 +6,7 @@ * * @package CodeIgniter * @author ExpressionEngine Dev Team - * @copyright Copyright (c) 2008 - 2009, EllisLab, Inc. + * @copyright Copyright (c) 2008 - 2010, EllisLab, Inc. * @license http://codeigniter.com/user_guide/license.html * @link http://codeigniter.com * @since Version 1.0 diff --git a/system/libraries/Ftp.php b/system/libraries/Ftp.php index 6fb170496..16ad9ad43 100644 --- a/system/libraries/Ftp.php +++ b/system/libraries/Ftp.php @@ -6,7 +6,7 @@ * * @package CodeIgniter * @author ExpressionEngine Dev Team - * @copyright Copyright (c) 2008 - 2009, EllisLab, Inc. + * @copyright Copyright (c) 2008 - 2010, EllisLab, Inc. * @license http://codeigniter.com/user_guide/license.html * @link http://codeigniter.com * @since Version 1.0 diff --git a/system/libraries/Hooks.php b/system/libraries/Hooks.php index 0b5d46809..6d736c3f6 100644 --- a/system/libraries/Hooks.php +++ b/system/libraries/Hooks.php @@ -6,7 +6,7 @@ * * @package CodeIgniter * @author ExpressionEngine Dev Team - * @copyright Copyright (c) 2008 - 2009, EllisLab, Inc. + * @copyright Copyright (c) 2008 - 2010, EllisLab, Inc. * @license http://codeigniter.com/user_guide/license.html * @link http://codeigniter.com * @since Version 1.0 diff --git a/system/libraries/Image_lib.php b/system/libraries/Image_lib.php index 59aefc55c..21e0a709b 100644 --- a/system/libraries/Image_lib.php +++ b/system/libraries/Image_lib.php @@ -6,7 +6,7 @@ * * @package CodeIgniter * @author ExpressionEngine Dev Team - * @copyright Copyright (c) 2008 - 2009, EllisLab, Inc. + * @copyright Copyright (c) 2008 - 2010, EllisLab, Inc. * @license http://codeigniter.com/user_guide/license.html * @link http://codeigniter.com * @since Version 1.0 diff --git a/system/libraries/Input.php b/system/libraries/Input.php index 98f28262f..e736d2b8b 100644 --- a/system/libraries/Input.php +++ b/system/libraries/Input.php @@ -6,7 +6,7 @@ * * @package CodeIgniter * @author ExpressionEngine Dev Team - * @copyright Copyright (c) 2008 - 2009, EllisLab, Inc. + * @copyright Copyright (c) 2008 - 2010, EllisLab, Inc. * @license http://codeigniter.com/user_guide/license.html * @link http://codeigniter.com * @since Version 1.0 diff --git a/system/libraries/Language.php b/system/libraries/Language.php index b679c891f..515d04a40 100644 --- a/system/libraries/Language.php +++ b/system/libraries/Language.php @@ -6,7 +6,7 @@ * * @package CodeIgniter * @author ExpressionEngine Dev Team - * @copyright Copyright (c) 2008 - 2009, EllisLab, Inc. + * @copyright Copyright (c) 2008 - 2010, EllisLab, Inc. * @license http://codeigniter.com/user_guide/license.html * @link http://codeigniter.com * @since Version 1.0 diff --git a/system/libraries/Loader.php b/system/libraries/Loader.php index 60c495820..2cd2e93b9 100644 --- a/system/libraries/Loader.php +++ b/system/libraries/Loader.php @@ -6,7 +6,7 @@ * * @package CodeIgniter * @author ExpressionEngine Dev Team - * @copyright Copyright (c) 2008 - 2009, EllisLab, Inc. + * @copyright Copyright (c) 2008 - 2010, EllisLab, Inc. * @license http://codeigniter.com/user_guide/license.html * @link http://codeigniter.com * @since Version 1.0 diff --git a/system/libraries/Log.php b/system/libraries/Log.php index d8a07a9dd..4e6b3bc39 100644 --- a/system/libraries/Log.php +++ b/system/libraries/Log.php @@ -6,7 +6,7 @@ * * @package CodeIgniter * @author ExpressionEngine Dev Team - * @copyright Copyright (c) 2008 - 2009, EllisLab, Inc. + * @copyright Copyright (c) 2008 - 2010, EllisLab, Inc. * @license http://codeigniter.com/user_guide/license.html * @link http://codeigniter.com * @since Version 1.0 diff --git a/system/libraries/Model.php b/system/libraries/Model.php index f5e501b00..e9c2d24d1 100644 --- a/system/libraries/Model.php +++ b/system/libraries/Model.php @@ -6,7 +6,7 @@ * * @package CodeIgniter * @author ExpressionEngine Dev Team - * @copyright Copyright (c) 2008 - 2009, EllisLab, Inc. + * @copyright Copyright (c) 2008 - 2010, EllisLab, Inc. * @license http://codeigniter.com/user_guide/license.html * @link http://codeigniter.com * @since Version 1.0 diff --git a/system/libraries/Output.php b/system/libraries/Output.php index 0cf6739bd..6a9a11677 100644 --- a/system/libraries/Output.php +++ b/system/libraries/Output.php @@ -6,7 +6,7 @@ * * @package CodeIgniter * @author ExpressionEngine Dev Team - * @copyright Copyright (c) 2008 - 2009, EllisLab, Inc. + * @copyright Copyright (c) 2008 - 2010, EllisLab, Inc. * @license http://codeigniter.com/user_guide/license.html * @link http://codeigniter.com * @since Version 1.0 diff --git a/system/libraries/Pagination.php b/system/libraries/Pagination.php index d73c58e08..d6321f41c 100644 --- a/system/libraries/Pagination.php +++ b/system/libraries/Pagination.php @@ -6,7 +6,7 @@ * * @package CodeIgniter * @author ExpressionEngine Dev Team - * @copyright Copyright (c) 2008 - 2009, EllisLab, Inc. + * @copyright Copyright (c) 2008 - 2010, EllisLab, Inc. * @license http://codeigniter.com/user_guide/license.html * @link http://codeigniter.com * @since Version 1.0 diff --git a/system/libraries/Parser.php b/system/libraries/Parser.php index da3243755..399b14b2d 100644 --- a/system/libraries/Parser.php +++ b/system/libraries/Parser.php @@ -6,7 +6,7 @@ * * @package CodeIgniter * @author ExpressionEngine Dev Team - * @copyright Copyright (c) 2008 - 2009, EllisLab, Inc. + * @copyright Copyright (c) 2008 - 2010, EllisLab, Inc. * @license http://codeigniter.com/user_guide/license.html * @link http://codeigniter.com * @since Version 1.0 diff --git a/system/libraries/Profiler.php b/system/libraries/Profiler.php index 5676898c8..ec185a1e8 100644 --- a/system/libraries/Profiler.php +++ b/system/libraries/Profiler.php @@ -6,7 +6,7 @@ * * @package CodeIgniter * @author ExpressionEngine Dev Team - * @copyright Copyright (c) 2008 - 2009, EllisLab, Inc. + * @copyright Copyright (c) 2008 - 2010, EllisLab, Inc. * @license http://codeigniter.com/user_guide/license.html * @link http://codeigniter.com * @since Version 1.0 diff --git a/system/libraries/Router.php b/system/libraries/Router.php index 50c7dd7cc..20e69721d 100644 --- a/system/libraries/Router.php +++ b/system/libraries/Router.php @@ -6,7 +6,7 @@ * * @package CodeIgniter * @author ExpressionEngine Dev Team - * @copyright Copyright (c) 2008 - 2009, EllisLab, Inc. + * @copyright Copyright (c) 2008 - 2010, EllisLab, Inc. * @license http://codeigniter.com/user_guide/license.html * @link http://codeigniter.com * @since Version 1.0 diff --git a/system/libraries/Session.php b/system/libraries/Session.php index 5e0ce48e9..bd9426818 100644 --- a/system/libraries/Session.php +++ b/system/libraries/Session.php @@ -6,7 +6,7 @@ * * @package CodeIgniter * @author ExpressionEngine Dev Team - * @copyright Copyright (c) 2008 - 2009, EllisLab, Inc. + * @copyright Copyright (c) 2008 - 2010, EllisLab, Inc. * @license http://codeigniter.com/user_guide/license.html * @link http://codeigniter.com * @since Version 1.0 diff --git a/system/libraries/Sha1.php b/system/libraries/Sha1.php index 6c39a5b11..f9611a8a5 100644 --- a/system/libraries/Sha1.php +++ b/system/libraries/Sha1.php @@ -6,7 +6,7 @@ * * @package CodeIgniter * @author ExpressionEngine Dev Team - * @copyright Copyright (c) 2008 - 2009, EllisLab, Inc. + * @copyright Copyright (c) 2008 - 2010, EllisLab, Inc. * @license http://codeigniter.com/user_guide/license.html * @link http://codeigniter.com * @since Version 1.0 diff --git a/system/libraries/Table.php b/system/libraries/Table.php index 86d54217f..a990d406c 100644 --- a/system/libraries/Table.php +++ b/system/libraries/Table.php @@ -6,7 +6,7 @@ * * @package CodeIgniter * @author ExpressionEngine Dev Team - * @copyright Copyright (c) 2008 - 2009, EllisLab, Inc. + * @copyright Copyright (c) 2008 - 2010, EllisLab, Inc. * @license http://codeigniter.com/user_guide/license.html * @link http://codeigniter.com * @since Version 1.3.1 diff --git a/system/libraries/Trackback.php b/system/libraries/Trackback.php index ab8f46a69..9b1737c5f 100644 --- a/system/libraries/Trackback.php +++ b/system/libraries/Trackback.php @@ -6,7 +6,7 @@ * * @package CodeIgniter * @author ExpressionEngine Dev Team - * @copyright Copyright (c) 2008 - 2009, EllisLab, Inc. + * @copyright Copyright (c) 2008 - 2010, EllisLab, Inc. * @license http://codeigniter.com/user_guide/license.html * @link http://codeigniter.com * @since Version 1.0 diff --git a/system/libraries/Typography.php b/system/libraries/Typography.php index 242ca3cb6..0f0a8b7a2 100644 --- a/system/libraries/Typography.php +++ b/system/libraries/Typography.php @@ -6,7 +6,7 @@ * * @package CodeIgniter * @author ExpressionEngine Dev Team - * @copyright Copyright (c) 2008 - 2009, EllisLab, Inc. + * @copyright Copyright (c) 2008 - 2010, EllisLab, Inc. * @license http://codeigniter.com/user_guide/license.html * @link http://codeigniter.com * @since Version 1.0 diff --git a/system/libraries/URI.php b/system/libraries/URI.php index 68b678053..23efb38c1 100644 --- a/system/libraries/URI.php +++ b/system/libraries/URI.php @@ -6,7 +6,7 @@ * * @package CodeIgniter * @author ExpressionEngine Dev Team - * @copyright Copyright (c) 2008 - 2009, EllisLab, Inc. + * @copyright Copyright (c) 2008 - 2010, EllisLab, Inc. * @license http://codeigniter.com/user_guide/license.html * @link http://codeigniter.com * @since Version 1.0 diff --git a/system/libraries/Unit_test.php b/system/libraries/Unit_test.php index 29a7fa383..a6427b2c3 100644 --- a/system/libraries/Unit_test.php +++ b/system/libraries/Unit_test.php @@ -6,7 +6,7 @@ * * @package CodeIgniter * @author ExpressionEngine Dev Team - * @copyright Copyright (c) 2008 - 2009, EllisLab, Inc. + * @copyright Copyright (c) 2008 - 2010, EllisLab, Inc. * @license http://codeigniter.com/user_guide/license.html * @link http://codeigniter.com * @since Version 1.3.1 diff --git a/system/libraries/Upload.php b/system/libraries/Upload.php index 618c49be0..5ff478269 100644 --- a/system/libraries/Upload.php +++ b/system/libraries/Upload.php @@ -6,7 +6,7 @@ * * @package CodeIgniter * @author ExpressionEngine Dev Team - * @copyright Copyright (c) 2008 - 2009, EllisLab, Inc. + * @copyright Copyright (c) 2008 - 2010, EllisLab, Inc. * @license http://codeigniter.com/user_guide/license.html * @link http://codeigniter.com * @since Version 1.0 diff --git a/system/libraries/User_agent.php b/system/libraries/User_agent.php index 180b93dea..a7c7a7609 100644 --- a/system/libraries/User_agent.php +++ b/system/libraries/User_agent.php @@ -6,7 +6,7 @@ * * @package CodeIgniter * @author ExpressionEngine Dev Team - * @copyright Copyright (c) 2008 - 2009, EllisLab, Inc. + * @copyright Copyright (c) 2008 - 2010, EllisLab, Inc. * @license http://codeigniter.com/user_guide/license.html * @link http://codeigniter.com * @since Version 1.0 diff --git a/system/libraries/Validation.php b/system/libraries/Validation.php index 5e7759f14..a42b7760b 100644 --- a/system/libraries/Validation.php +++ b/system/libraries/Validation.php @@ -6,7 +6,7 @@ * * @package CodeIgniter * @author ExpressionEngine Dev Team - * @copyright Copyright (c) 2008 - 2009, EllisLab, Inc. + * @copyright Copyright (c) 2008 - 2010, EllisLab, Inc. * @license http://codeigniter.com/user_guide/license.html * @link http://codeigniter.com * @since Version 1.0 diff --git a/system/libraries/Xmlrpc.php b/system/libraries/Xmlrpc.php index 5460842b6..fe5562fef 100644 --- a/system/libraries/Xmlrpc.php +++ b/system/libraries/Xmlrpc.php @@ -6,7 +6,7 @@ * * @package CodeIgniter * @author ExpressionEngine Dev Team - * @copyright Copyright (c) 2008 - 2009, EllisLab, Inc. + * @copyright Copyright (c) 2008 - 2010, EllisLab, Inc. * @license http://codeigniter.com/user_guide/license.html * @link http://codeigniter.com * @since Version 1.0 diff --git a/system/libraries/Xmlrpcs.php b/system/libraries/Xmlrpcs.php index c7daa600f..429ab8472 100644 --- a/system/libraries/Xmlrpcs.php +++ b/system/libraries/Xmlrpcs.php @@ -6,7 +6,7 @@ * * @package CodeIgniter * @author ExpressionEngine Dev Team - * @copyright Copyright (c) 2008 - 2009, EllisLab, Inc. + * @copyright Copyright (c) 2008 - 2010, EllisLab, Inc. * @license http://codeigniter.com/user_guide/license.html * @link http://codeigniter.com * @since Version 1.0 diff --git a/system/libraries/Zip.php b/system/libraries/Zip.php index 4ed1f1820..aae62d74d 100644 --- a/system/libraries/Zip.php +++ b/system/libraries/Zip.php @@ -6,7 +6,7 @@ * * @package CodeIgniter * @author ExpressionEngine Dev Team - * @copyright Copyright (c) 2008 - 2009, EllisLab, Inc. + * @copyright Copyright (c) 2008 - 2010, EllisLab, Inc. * @license http://codeigniter.com/user_guide/license.html * @link http://codeigniter.com * @since Version 1.0 diff --git a/system/plugins/captcha_pi.php b/system/plugins/captcha_pi.php index 36a74c42f..77f29f8b9 100644 --- a/system/plugins/captcha_pi.php +++ b/system/plugins/captcha_pi.php @@ -6,7 +6,7 @@ * * @package CodeIgniter * @author ExpressionEngine Dev Team - * @copyright Copyright (c) 2008 - 2009, EllisLab, Inc. + * @copyright Copyright (c) 2008 - 2010, EllisLab, Inc. * @license http://codeigniter.com/user_guide/license.html * @link http://codeigniter.com * @since Version 1.0 diff --git a/system/plugins/js_calendar_pi.php b/system/plugins/js_calendar_pi.php index 4a616f10f..a35ab56bd 100644 --- a/system/plugins/js_calendar_pi.php +++ b/system/plugins/js_calendar_pi.php @@ -6,7 +6,7 @@ * * @package CodeIgniter * @author ExpressionEngine Dev Team - * @copyright Copyright (c) 2008 - 2009, EllisLab, Inc. + * @copyright Copyright (c) 2008 - 2010, EllisLab, Inc. * @license http://codeigniter.com/user_guide/license.html * @link http://codeigniter.com * @since Version 1.0 diff --git a/system/scaffolding/Scaffolding.php b/system/scaffolding/Scaffolding.php index fb2ee5dad..d110626b1 100644 --- a/system/scaffolding/Scaffolding.php +++ b/system/scaffolding/Scaffolding.php @@ -6,7 +6,7 @@ * * @package CodeIgniter * @author ExpressionEngine Dev Team - * @copyright Copyright (c) 2008 - 2009, EllisLab, Inc. + * @copyright Copyright (c) 2008 - 2010, EllisLab, Inc. * @license http://codeigniter.com/user_guide/license.html * @link http://codeigniter.com * @since Version 1.0 -- cgit v1.2.3-24-g4f1b From 8c4b5e78a8f3a87e30ffc3b09b897153ffe86193 Mon Sep 17 00:00:00 2001 From: Derek Jones Date: Wed, 6 Jan 2010 22:21:41 +0000 Subject: changed isset() to array_key_exists() in values_parsing() conditional of XML-RPC class to allow for array keys set with NULL values --- system/libraries/Xmlrpc.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system') diff --git a/system/libraries/Xmlrpc.php b/system/libraries/Xmlrpc.php index fe5562fef..5a82391dd 100644 --- a/system/libraries/Xmlrpc.php +++ b/system/libraries/Xmlrpc.php @@ -229,7 +229,7 @@ class CI_Xmlrpc { function values_parsing($value, $return = FALSE) { - if (is_array($value) && isset($value['0'])) + if (is_array($value) && array_key_exists(0, $value)) { if ( ! isset($value['1']) OR (! isset($this->xmlrpcTypes[$value['1']]))) { -- cgit v1.2.3-24-g4f1b From 98a447ac363d00d856c18f34ffbd4d14cad51eb3 Mon Sep 17 00:00:00 2001 From: Pascal Kriete Date: Thu, 7 Jan 2010 18:14:28 +0000 Subject: changing the second parameter in directory_map to an integer that controls recursion depth. A depth of 0 is fully recursive to maintain backward compatibility with the boolean values. --- system/helpers/directory_helper.php | 32 ++++++++++++++------------------ 1 file changed, 14 insertions(+), 18 deletions(-) (limited to 'system') diff --git a/system/helpers/directory_helper.php b/system/helpers/directory_helper.php index 791cf0d10..7de6a3c51 100644 --- a/system/helpers/directory_helper.php +++ b/system/helpers/directory_helper.php @@ -36,32 +36,30 @@ * * @access public * @param string path to source - * @param bool whether to limit the result to the top level only + * @param int depth of directories to traverse (0 = fully recursive, 1 = current dir, etc) * @return array */ if ( ! function_exists('directory_map')) { - function directory_map($source_dir, $top_level_only = FALSE, $hidden = FALSE) - { + function directory_map($source_dir, $directory_depth = 0, $hidden = FALSE) + { if ($fp = @opendir($source_dir)) { - $source_dir = rtrim($source_dir, DIRECTORY_SEPARATOR).DIRECTORY_SEPARATOR; - $filedata = array(); - + $filedata = array(); + $new_depth = $directory_depth - 1; + $source_dir = rtrim($source_dir, DIRECTORY_SEPARATOR).DIRECTORY_SEPARATOR; + while (FALSE !== ($file = readdir($fp))) { - if (($hidden == FALSE && strncmp($file, '.', 1) == 0) OR ($file == '.' OR $file == '..')) + // Remove '.', '..', and hidden files [optional] + if ( ! trim($file, '.') OR ($hidden == FALSE && $file[0] == '.')) { continue; } - - if ($top_level_only == FALSE && @is_dir($source_dir.$file)) + + if (($directory_depth < 1 OR $new_depth > 0) && @is_dir($source_dir.$file)) { - $temp_array = array(); - - $temp_array = directory_map($source_dir.$file.DIRECTORY_SEPARATOR, $top_level_only, $hidden); - - $filedata[$file] = $temp_array; + $filedata[$file] = directory_map($source_dir.$file.DIRECTORY_SEPARATOR, $new_depth, $hidden); } else { @@ -72,10 +70,8 @@ if ( ! function_exists('directory_map')) closedir($fp); return $filedata; } - else - { - return FALSE; - } + + return FALSE; } } -- cgit v1.2.3-24-g4f1b From 3e9519e07af366f9bd7b48de34db689f573d37ea Mon Sep 17 00:00:00 2001 From: Greg Aker Date: Fri, 15 Jan 2010 00:09:34 +0000 Subject: Update to file helper to return FALSE on failure. --- system/helpers/file_helper.php | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'system') diff --git a/system/helpers/file_helper.php b/system/helpers/file_helper.php index 114b2927a..2be06ac4f 100644 --- a/system/helpers/file_helper.php +++ b/system/helpers/file_helper.php @@ -124,7 +124,9 @@ if ( ! function_exists('delete_files')) $path = rtrim($path, DIRECTORY_SEPARATOR); if ( ! $current_dir = @opendir($path)) - return; + { + return TRUE; + } while(FALSE !== ($filename = @readdir($current_dir))) { @@ -148,8 +150,10 @@ if ( ! function_exists('delete_files')) if ($del_dir == TRUE AND $level > 0) { - @rmdir($path); + return @rmdir($path); } + + return TRUE; } } -- cgit v1.2.3-24-g4f1b From d827058bb0b1d2b54f7cb0e8343885cedac43334 Mon Sep 17 00:00:00 2001 From: Derek Allard Date: Fri, 15 Jan 2010 17:10:56 +0000 Subject: adding parse_string method adding null values generating an empty cell in table lib --- system/libraries/Parser.php | 51 +++++++++++++++++++++++++++++++++++++++------ system/libraries/Table.php | 2 +- 2 files changed, 46 insertions(+), 7 deletions(-) (limited to 'system') diff --git a/system/libraries/Parser.php b/system/libraries/Parser.php index 399b14b2d..56d27e7da 100644 --- a/system/libraries/Parser.php +++ b/system/libraries/Parser.php @@ -29,11 +29,11 @@ class CI_Parser { var $l_delim = '{'; var $r_delim = '}'; var $object; - + /** * Parse a template * - * Parses pseudo-variables contained in the specified template, + * Parses pseudo-variables contained in the specified template view, * replacing them with the data in the second param * * @access public @@ -46,12 +46,50 @@ class CI_Parser { { $CI =& get_instance(); $template = $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 + * + * @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)) @@ -63,12 +101,13 @@ class CI_Parser { $template = $this->_parse_single($key, (string)$val, $template); } } - + if ($return == FALSE) { + $CI =& get_instance(); $CI->output->append_output($template); } - + return $template; } diff --git a/system/libraries/Table.php b/system/libraries/Table.php index a990d406c..6d36121f2 100644 --- a/system/libraries/Table.php +++ b/system/libraries/Table.php @@ -260,7 +260,7 @@ class CI_Table { { $out .= $this->template['cell_'.$name.'start']; - if ($cell === "") + if ($cell === "" OR $cell === NULL) { $out .= $this->empty_cells; } -- cgit v1.2.3-24-g4f1b From 03151b09a805f0e91700a7f49a3deffed8beecf8 Mon Sep 17 00:00:00 2001 From: Derek Allard Date: Sat, 16 Jan 2010 19:06:30 +0000 Subject: preg_quote() in parser --- system/libraries/Parser.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system') diff --git a/system/libraries/Parser.php b/system/libraries/Parser.php index 56d27e7da..161de613f 100644 --- a/system/libraries/Parser.php +++ b/system/libraries/Parser.php @@ -197,7 +197,7 @@ class CI_Parser { */ function _match_pair($string, $variable) { - if ( ! preg_match("|".$this->l_delim . $variable . $this->r_delim."(.+?)".$this->l_delim . '/' . $variable . $this->r_delim."|s", $string, $match)) + 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; } -- cgit v1.2.3-24-g4f1b From 76af409a0157f981c145973e5668052621c38415 Mon Sep 17 00:00:00 2001 From: Derek Allard Date: Sat, 16 Jan 2010 19:20:49 +0000 Subject: adding http headers and config to CI profiler --- system/language/english/profiler_lang.php | 2 + system/libraries/Profiler.php | 81 ++++++++++++++++++++++++++++--- 2 files changed, 77 insertions(+), 6 deletions(-) (limited to 'system') diff --git a/system/language/english/profiler_lang.php b/system/language/english/profiler_lang.php index 7c40e3f3e..bf2183004 100644 --- a/system/language/english/profiler_lang.php +++ b/system/language/english/profiler_lang.php @@ -8,6 +8,8 @@ $lang['profiler_get_data'] = 'GET DATA'; $lang['profiler_post_data'] = 'POST DATA'; $lang['profiler_uri_string'] = 'URI STRING'; $lang['profiler_memory_usage'] = 'MEMORY USAGE'; +$lang['profiler_config'] = 'CONFIG VARIABLES'; +$lang['profiler_headers'] = 'HTTP HEADERS'; $lang['profiler_no_db'] = 'Database driver is not currently loaded'; $lang['profiler_no_queries'] = 'No queries were run'; $lang['profiler_no_post'] = 'No POST data exists'; diff --git a/system/libraries/Profiler.php b/system/libraries/Profiler.php index ec185a1e8..ebadf8610 100644 --- a/system/libraries/Profiler.php +++ b/system/libraries/Profiler.php @@ -74,16 +74,16 @@ class CI_Profiler { // be modified. We also might want to make this data available to be logged $output = "\n\n"; - $output .= '
    '; + $output .= '
    '; $output .= "\n"; - $output .= '  '.$this->CI->lang->line('profiler_benchmarks').'  '; + $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 .= "\n"; } $output .= "
    ".$key."  ".$val."
    ".$key."  ".$val."
    \n"; @@ -161,7 +161,7 @@ class CI_Profiler { $val = str_replace($bold, ''.$bold.'', $val); } - $output .= "".$time."  ".$val."\n"; + $output .= "".$time."  ".$val."\n"; } } @@ -327,6 +327,7 @@ class CI_Profiler { return $output; } + // -------------------------------------------------------------------- /** @@ -351,7 +352,7 @@ class CI_Profiler { } else { - $output .= "
    ".$this->CI->lang->line('profiler_no_memory')."
    "; + $output .= "
    ".$this->CI->lang->line('profiler_no_memory_usage')."
    "; } $output .= "
    "; @@ -361,6 +362,73 @@ class CI_Profiler { // -------------------------------------------------------------------- + /** + * Compile header information + * + * Lists HTTP headers + * + * @access public + * @return string + */ + function _compile_http_headers() + { + $output = "\n\n"; + $output .= '
    '; + $output .= "\n"; + $output .= '  '.$this->CI->lang->line('profiler_headers').'  '; + $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') as $header) + { + $val = (isset($_SERVER[$header])) ? $_SERVER[$header] : ''; + $output .= "\n"; + } + + $output .= "
    ".$header."  ".$val."
    \n"; + $output .= "
    "; + + $output .= "
    "; + + return $output; + } + + // -------------------------------------------------------------------- + + /** + * Compile config information + * + * Lists developer config variables + * + * @access public + * @return string + */ + function _compile_config() + { + $output = "\n\n"; + $output .= '
    '; + $output .= "\n"; + $output .= '  '.$this->CI->lang->line('profiler_config').'  '; + $output .= "\n"; + + $output .= "\n\n\n"; + + foreach($this->CI->config->config as $config=>$val) + { + $output .= "\n"; + } + + $output .= "
    ".$config."  ".$val."
    \n"; + $output .= "
    "; + + $output .= "
    "; + + return $output; + } + + // -------------------------------------------------------------------- + /** * Run the Profiler * @@ -378,7 +446,8 @@ class CI_Profiler { $output .= $this->_compile_get(); $output .= $this->_compile_post(); $output .= $this->_compile_queries(); - + $output .= $this->_compile_config(); + $output .= $this->_compile_http_headers(); $output .= '
    '; return $output; -- cgit v1.2.3-24-g4f1b From 33d4b6aac7f33d6cddfa5fb39c5701ecc9cfa80b Mon Sep 17 00:00:00 2001 From: Derek Allard Date: Sun, 17 Jan 2010 07:23:00 +0000 Subject: adding the ability for form_open_multipart() to accept string attribute arguments --- system/helpers/form_helper.php | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) (limited to 'system') diff --git a/system/helpers/form_helper.php b/system/helpers/form_helper.php index c78b805e5..60d2631e9 100644 --- a/system/helpers/form_helper.php +++ b/system/helpers/form_helper.php @@ -84,7 +84,15 @@ if ( ! function_exists('form_open_multipart')) { function form_open_multipart($action, $attributes = array(), $hidden = array()) { - $attributes['enctype'] = 'multipart/form-data'; + if (is_string($attributes)) + { + $attributes .= ' enctype="multipart/form-data"'; + } + else + { + $attributes['enctype'] = 'multipart/form-data'; + } + return form_open($action, $attributes, $hidden); } } -- cgit v1.2.3-24-g4f1b From f063ed7a0d51fd2abd5dd716ab7f92a54e45cd11 Mon Sep 17 00:00:00 2001 From: Derek Allard Date: Sun, 17 Jan 2010 07:48:25 +0000 Subject: making get_mime_by_extension case insensitive --- system/helpers/file_helper.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system') diff --git a/system/helpers/file_helper.php b/system/helpers/file_helper.php index 2be06ac4f..9ea5018ae 100644 --- a/system/helpers/file_helper.php +++ b/system/helpers/file_helper.php @@ -346,7 +346,7 @@ if ( ! function_exists('get_mime_by_extension')) { function get_mime_by_extension($file) { - $extension = strtolower(substr(strrchr($file, '.'), 1)); + $extension = strtolower(substr(strrchr(strtolower($file), '.'), 1)); global $mimes; -- cgit v1.2.3-24-g4f1b From 9502311beeda23042370bb891f850eab3aadad96 Mon Sep 17 00:00:00 2001 From: Derek Allard Date: Sun, 17 Jan 2010 07:51:21 +0000 Subject: change already made - revert --- system/helpers/file_helper.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system') diff --git a/system/helpers/file_helper.php b/system/helpers/file_helper.php index 9ea5018ae..2be06ac4f 100644 --- a/system/helpers/file_helper.php +++ b/system/helpers/file_helper.php @@ -346,7 +346,7 @@ if ( ! function_exists('get_mime_by_extension')) { function get_mime_by_extension($file) { - $extension = strtolower(substr(strrchr(strtolower($file), '.'), 1)); + $extension = strtolower(substr(strrchr($file, '.'), 1)); global $mimes; -- cgit v1.2.3-24-g4f1b From aca699599d3a6eacc2f36a487d874a02c3df31a4 Mon Sep 17 00:00:00 2001 From: Derek Allard Date: Sun, 17 Jan 2010 15:52:47 +0000 Subject: adding Chrome to list of browsers for user-agent class --- system/application/config/user_agents.php | 1 + 1 file changed, 1 insertion(+) (limited to 'system') diff --git a/system/application/config/user_agents.php b/system/application/config/user_agents.php index f15b007a5..a1becd98f 100644 --- a/system/application/config/user_agents.php +++ b/system/application/config/user_agents.php @@ -48,6 +48,7 @@ $platforms = array ( // 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( + 'Chrome' => 'Chrome', 'Opera' => 'Opera', 'MSIE' => 'Internet Explorer', 'Internet Explorer' => 'Internet Explorer', -- cgit v1.2.3-24-g4f1b From b251c522205973bfc3992e22d70827eb0c2b1b7a Mon Sep 17 00:00:00 2001 From: Derek Allard Date: Sun, 17 Jan 2010 16:02:01 +0000 Subject: Added Flock to the list of browsers in the user agent class --- system/application/config/user_agents.php | 1 + 1 file changed, 1 insertion(+) (limited to 'system') diff --git a/system/application/config/user_agents.php b/system/application/config/user_agents.php index a1becd98f..a1c0b14b6 100644 --- a/system/application/config/user_agents.php +++ b/system/application/config/user_agents.php @@ -48,6 +48,7 @@ $platforms = array ( // 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', -- cgit v1.2.3-24-g4f1b From fcbb0266468db83d2d8d4006d80f77445fd6a0e2 Mon Sep 17 00:00:00 2001 From: Derek Allard Date: Sun, 17 Jan 2010 16:13:15 +0000 Subject: optional precision argument in byte_format() --- system/helpers/number_helper.php | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) (limited to 'system') diff --git a/system/helpers/number_helper.php b/system/helpers/number_helper.php index cf683f2a1..1fdd30326 100644 --- a/system/helpers/number_helper.php +++ b/system/helpers/number_helper.php @@ -36,29 +36,29 @@ */ if ( ! function_exists('byte_format')) { - function byte_format($num) + function byte_format($num, $precision = 1) { $CI =& get_instance(); $CI->lang->load('number'); if ($num >= 1000000000000) { - $num = round($num / 1099511627776, 1); + $num = round($num / 1099511627776, $precision); $unit = $CI->lang->line('terabyte_abbr'); } elseif ($num >= 1000000000) { - $num = round($num / 1073741824, 1); + $num = round($num / 1073741824, $precision); $unit = $CI->lang->line('gigabyte_abbr'); } elseif ($num >= 1000000) { - $num = round($num / 1048576, 1); + $num = round($num / 1048576, $precision); $unit = $CI->lang->line('megabyte_abbr'); } elseif ($num >= 1000) { - $num = round($num / 1024, 1); + $num = round($num / 1024, $precision); $unit = $CI->lang->line('kilobyte_abbr'); } else @@ -67,9 +67,11 @@ if ( ! function_exists('byte_format')) return number_format($num).' '.$unit; } - return number_format($num, 1).' '.$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 -- cgit v1.2.3-24-g4f1b From 81c98057a9b0a3ad26d204efd2639a4843d2b2da Mon Sep 17 00:00:00 2001 From: Derek Allard Date: Sun, 17 Jan 2010 16:27:03 +0000 Subject: Added 'application/x-msdownload' for .exe files and ''application/x-gzip-compressed' for .tgz files to config/mimes.php --- system/application/config/mimes.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'system') diff --git a/system/application/config/mimes.php b/system/application/config/mimes.php index 438f610ce..f31fff2ec 100644 --- a/system/application/config/mimes.php +++ b/system/application/config/mimes.php @@ -15,7 +15,7 @@ $mimes = array( 'hqx' => 'application/mac-binhex40', 'dms' => 'application/octet-stream', 'lha' => 'application/octet-stream', 'lzh' => 'application/octet-stream', - 'exe' => 'application/octet-stream', + 'exe' => array('application/octet-stream', 'application/x-msdownload'), 'class' => 'application/octet-stream', 'psd' => 'application/x-photoshop', 'so' => 'application/octet-stream', @@ -48,7 +48,7 @@ $mimes = array( 'hqx' => 'application/mac-binhex40', 'swf' => 'application/x-shockwave-flash', 'sit' => 'application/x-stuffit', 'tar' => 'application/x-tar', - 'tgz' => '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'), @@ -102,4 +102,4 @@ $mimes = array( 'hqx' => 'application/mac-binhex40', /* End of file mimes.php */ -/* Location: ./system/application/config/mimes.php */ \ No newline at end of file +/* Location: ./application/config/mimes.php */ \ No newline at end of file -- cgit v1.2.3-24-g4f1b From 0ce73efdef39b5760766fcdde08485e94b754953 Mon Sep 17 00:00:00 2001 From: Derek Allard Date: Mon, 18 Jan 2010 15:48:25 +0000 Subject: The Unit Test Class now has an optional "notes" field available to it, and allows for discrete display of test result items using $this->unit->set_test_items(). --- system/libraries/Unit_test.php | 60 +++++++++++++++++++++++++++++++++--------- 1 file changed, 48 insertions(+), 12 deletions(-) (limited to 'system') diff --git a/system/libraries/Unit_test.php b/system/libraries/Unit_test.php index a6427b2c3..c47143637 100644 --- a/system/libraries/Unit_test.php +++ b/system/libraries/Unit_test.php @@ -28,19 +28,50 @@ */ class CI_Unit_test { - var $active = TRUE; - var $results = array(); - var $strict = FALSE; - var $_template = NULL; - var $_template_rows = NULL; + var $active = TRUE; + var $results = array(); + var $strict = FALSE; + var $_template = NULL; + var $_template_rows = NULL; + var $_test_items_visible = array(); function CI_Unit_test() { + // These are the default items visible when a test is run. + $this->_test_items_visible = array ( + 'test_name', + 'test_datatype', + 'res_datatype', + 'result', + 'file', + 'line', + 'notes' + ); + log_message('debug', "Unit Testing Class Initialized"); - } + } // -------------------------------------------------------------------- - + + /** + * Run the tests + * + * Runs the supplied tests + * + * @access public + * @param array + * @return void + */ + function set_test_items($items = array()) + { + if ( ! empty($items) AND is_array($items)) + { + $this->_test_items_visible = $items; + } + } + + // -------------------------------------------------------------------- + /** * Run the tests * @@ -52,7 +83,7 @@ class CI_Unit_test { * @param string * @return string */ - function run($test, $expected = TRUE, $test_name = 'undefined') + function run($test, $expected = TRUE, $test_name = 'undefined', $notes = '') { if ($this->active == FALSE) { @@ -83,11 +114,12 @@ class CI_Unit_test { 'res_datatype' => $extype, 'result' => ($result === TRUE) ? 'passed' : 'failed', 'file' => $back['file'], - 'line' => $back['line'] + 'line' => $back['line'], + 'notes' => $notes ); - $this->results[] = $report; - + $this->results[] = $report; + return($this->report($this->result($report))); } @@ -120,7 +152,6 @@ class CI_Unit_test { foreach ($res as $key => $val) { - if ($key == $CI->lang->line('ut_result')) { if ($val == $CI->lang->line('ut_passed')) @@ -203,6 +234,11 @@ class CI_Unit_test { $temp = array(); foreach ($result as $key => $val) { + if ( ! in_array($key, $this->_test_items_visible)) + { + continue; + } + if (is_array($val)) { foreach ($val as $k => $v) -- cgit v1.2.3-24-g4f1b From f947e0a744833b95d2b732a3910bb80e1d66c7b9 Mon Sep 17 00:00:00 2001 From: Derek Allard Date: Mon, 18 Jan 2010 15:52:17 +0000 Subject: updated lang file for unit test changes --- system/language/english/unit_test_lang.php | 1 + 1 file changed, 1 insertion(+) (limited to 'system') diff --git a/system/language/english/unit_test_lang.php b/system/language/english/unit_test_lang.php index 45b5acf55..070bcd1f2 100644 --- a/system/language/english/unit_test_lang.php +++ b/system/language/english/unit_test_lang.php @@ -18,6 +18,7 @@ $lang['ut_array'] = 'Array'; $lang['ut_object'] = 'Object'; $lang['ut_resource'] = 'Resource'; $lang['ut_null'] = 'Null'; +$lang['ut_notes'] = 'Notes'; /* End of file unit_test_lang.php */ -- cgit v1.2.3-24-g4f1b From 9e94ee10520a9d95eab1b1a0e9c9b27d39b7214a Mon Sep 17 00:00:00 2001 From: Derek Allard Date: Mon, 18 Jan 2010 21:42:59 +0000 Subject: nongreedy regex --- system/libraries/Parser.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system') diff --git a/system/libraries/Parser.php b/system/libraries/Parser.php index 161de613f..9387f1a9a 100644 --- a/system/libraries/Parser.php +++ b/system/libraries/Parser.php @@ -197,7 +197,7 @@ class CI_Parser { */ 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)) + 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; } -- cgit v1.2.3-24-g4f1b From 472dd21a7bc60147afff7bf100bbb6c9f339d0fc Mon Sep 17 00:00:00 2001 From: Derek Allard Date: Sat, 23 Jan 2010 20:03:27 +0000 Subject: Added alpha, and sha1 string types to random_string() in the String Helper. --- system/helpers/string_helper.php | 25 ++++++++++++++++++++----- 1 file changed, 20 insertions(+), 5 deletions(-) (limited to 'system') diff --git a/system/helpers/string_helper.php b/system/helpers/string_helper.php index 67cbd0eb6..4767f0b5f 100644 --- a/system/helpers/string_helper.php +++ b/system/helpers/string_helper.php @@ -186,22 +186,27 @@ if ( ! function_exists('reduce_multiples')) * Useful for generating passwords or hashes. * * @access public - * @param string type of random string. Options: alunum, numeric, nozero, unique + * @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'; @@ -217,12 +222,22 @@ if ( ! function_exists('random_string')) } return $str; break; - case 'unique' : return md5(uniqid(mt_rand())); + 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; } } } - // ------------------------------------------------------------------------ /** -- cgit v1.2.3-24-g4f1b From 1edde30e4443bdcb54a16bf220a5a359825ab549 Mon Sep 17 00:00:00 2001 From: Greg Aker Date: Tue, 26 Jan 2010 00:17:01 +0000 Subject: Fixing bug in DB Driver where identifiers could be escaped in some drivers that can't accept it in the list_fields() function. http://codeigniter.com/bug_tracker/bug/5865/ http://codeigniter.com/bug_tracker/bug/11218/ --- system/database/DB_driver.php | 2 +- system/database/drivers/mysql/mysql_driver.php | 2 +- system/database/drivers/mysqli/mysqli_driver.php | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) (limited to 'system') diff --git a/system/database/DB_driver.php b/system/database/DB_driver.php index 390d5570b..d7f17ccb8 100644 --- a/system/database/DB_driver.php +++ b/system/database/DB_driver.php @@ -822,7 +822,7 @@ class CI_DB_driver { return FALSE; } - if (FALSE === ($sql = $this->_list_columns($this->_protect_identifiers($table, TRUE, NULL, FALSE)))) + if (FALSE === ($sql = $this->_list_columns($table))) { if ($this->db_debug) { diff --git a/system/database/drivers/mysql/mysql_driver.php b/system/database/drivers/mysql/mysql_driver.php index 85a6ef4a0..bd60d9ffe 100644 --- a/system/database/drivers/mysql/mysql_driver.php +++ b/system/database/drivers/mysql/mysql_driver.php @@ -408,7 +408,7 @@ class CI_DB_mysql_driver extends CI_DB { */ function _list_columns($table = '') { - return "SHOW COLUMNS FROM ".$table; + return "SHOW COLUMNS FROM ".$this->_protect_identifiers($table, TRUE, NULL, FALSE); } // -------------------------------------------------------------------- diff --git a/system/database/drivers/mysqli/mysqli_driver.php b/system/database/drivers/mysqli/mysqli_driver.php index 5d7200fbd..d0e2defec 100644 --- a/system/database/drivers/mysqli/mysqli_driver.php +++ b/system/database/drivers/mysqli/mysqli_driver.php @@ -409,7 +409,7 @@ class CI_DB_mysqli_driver extends CI_DB { */ function _list_columns($table = '') { - return "SHOW COLUMNS FROM ".$table; + return "SHOW COLUMNS FROM ".$this->_protect_identifiers($table, TRUE, NULL, FALSE); } // -------------------------------------------------------------------- -- cgit v1.2.3-24-g4f1b From 0d42489234e0fdfecd11f46b1d3573e60db3918c Mon Sep 17 00:00:00 2001 From: Greg Aker Date: Tue, 26 Jan 2010 02:14:44 +0000 Subject: Misspelled class property in db class. _like_escape_chr, not _like_escape_char http://codeigniter.com/bug_tracker/bug/9518/ --- system/database/DB_active_rec.php | 2 +- system/database/drivers/mssql/mssql_driver.php | 2 +- system/database/drivers/oci8/oci8_driver.php | 2 +- system/database/drivers/odbc/odbc_driver.php | 2 +- system/database/drivers/postgre/postgre_driver.php | 2 +- system/database/drivers/sqlite/sqlite_driver.php | 2 +- 6 files changed, 6 insertions(+), 6 deletions(-) (limited to 'system') diff --git a/system/database/DB_active_rec.php b/system/database/DB_active_rec.php index bf4d5117e..a3abff11e 100644 --- a/system/database/DB_active_rec.php +++ b/system/database/DB_active_rec.php @@ -725,7 +725,7 @@ class CI_DB_active_record extends CI_DB_driver { // 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_char); + $like_statement = $like_statement.sprintf($this->_like_escape_str, $this->_like_escape_chr); } $this->ar_like[] = $like_statement; diff --git a/system/database/drivers/mssql/mssql_driver.php b/system/database/drivers/mssql/mssql_driver.php index f301ba533..0c74726a2 100644 --- a/system/database/drivers/mssql/mssql_driver.php +++ b/system/database/drivers/mssql/mssql_driver.php @@ -389,7 +389,7 @@ class CI_DB_mssql_driver extends CI_DB { // 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_char); + //$sql .= " LIKE '".$this->escape_like_str($this->dbprefix)."%' ".sprintf($this->_like_escape_str, $this->_like_escape_chr); return FALSE; // not currently supported } diff --git a/system/database/drivers/oci8/oci8_driver.php b/system/database/drivers/oci8/oci8_driver.php index 758192358..cd0e09577 100644 --- a/system/database/drivers/oci8/oci8_driver.php +++ b/system/database/drivers/oci8/oci8_driver.php @@ -493,7 +493,7 @@ class CI_DB_oci8_driver extends CI_DB { 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_char); + $sql .= " WHERE TABLE_NAME LIKE '".$this->escape_like_str($this->dbprefix)."%' ".sprintf($this->_like_escape_str, $this->_like_escape_chr); } return $sql; diff --git a/system/database/drivers/odbc/odbc_driver.php b/system/database/drivers/odbc/odbc_driver.php index 6cb3080d4..d5df8ef8c 100644 --- a/system/database/drivers/odbc/odbc_driver.php +++ b/system/database/drivers/odbc/odbc_driver.php @@ -362,7 +362,7 @@ class CI_DB_odbc_driver extends CI_DB { if ($prefix_limit !== FALSE AND $this->dbprefix != '') { - //$sql .= " LIKE '".$this->escape_like_str($this->dbprefix)."%' ".sprintf($this->_like_escape_str, $this->_like_escape_char); + //$sql .= " LIKE '".$this->escape_like_str($this->dbprefix)."%' ".sprintf($this->_like_escape_str, $this->_like_escape_chr); return FALSE; // not currently supported } diff --git a/system/database/drivers/postgre/postgre_driver.php b/system/database/drivers/postgre/postgre_driver.php index bac179d40..9f991e4a0 100644 --- a/system/database/drivers/postgre/postgre_driver.php +++ b/system/database/drivers/postgre/postgre_driver.php @@ -405,7 +405,7 @@ class CI_DB_postgre_driver extends CI_DB { 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_char); + $sql .= " AND table_name LIKE '".$this->escape_like_str($this->dbprefix)."%' ".sprintf($this->_like_escape_str, $this->_like_escape_chr); } return $sql; diff --git a/system/database/drivers/sqlite/sqlite_driver.php b/system/database/drivers/sqlite/sqlite_driver.php index 05e38848a..c08ed2a56 100644 --- a/system/database/drivers/sqlite/sqlite_driver.php +++ b/system/database/drivers/sqlite/sqlite_driver.php @@ -374,7 +374,7 @@ class CI_DB_sqlite_driver extends CI_DB { 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_char); + $sql .= " AND 'name' LIKE '".$this->escape_like_str($this->dbprefix)."%' ".sprintf($this->_like_escape_str, $this->_like_escape_chr); } return $sql; } -- cgit v1.2.3-24-g4f1b From e7f0325af984392aa4c509dc5a5ca409f5e9474a Mon Sep 17 00:00:00 2001 From: Derek Allard Date: Thu, 4 Feb 2010 16:47:01 +0000 Subject: database exists function in dbutil --- system/database/DB_utility.php | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'system') diff --git a/system/database/DB_utility.php b/system/database/DB_utility.php index 94e7a0bda..af62dcf3d 100644 --- a/system/database/DB_utility.php +++ b/system/database/DB_utility.php @@ -74,6 +74,20 @@ class CI_DB_utility extends CI_DB_forge { // -------------------------------------------------------------------- + /** + * Determine if a particular database exists + * + * @access public + * @param string + * @return boolean + */ + function database_exists($database_name) + { + return ( ! in_array($database_name, $this->list_databases())) ? FALSE : TRUE; + } + + // -------------------------------------------------------------------- + /** * Optimize Table * -- cgit v1.2.3-24-g4f1b From 62396232658467b463f37e55bec159aadc188edd Mon Sep 17 00:00:00 2001 From: Derek Allard Date: Thu, 4 Feb 2010 17:45:47 +0000 Subject: database_exists extension to allow for databases without list_databases() functionality --- system/database/DB_utility.php | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) (limited to 'system') diff --git a/system/database/DB_utility.php b/system/database/DB_utility.php index af62dcf3d..124967a5a 100644 --- a/system/database/DB_utility.php +++ b/system/database/DB_utility.php @@ -82,10 +82,21 @@ class CI_DB_utility extends CI_DB_forge { * @return boolean */ function database_exists($database_name) - { - return ( ! in_array($database_name, $this->list_databases())) ? FALSE : TRUE; + { + // 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; + } } + // -------------------------------------------------------------------- /** -- cgit v1.2.3-24-g4f1b From 4860ec52f5bdf917d12f511ecd07b7d4797f0d91 Mon Sep 17 00:00:00 2001 From: Derek Allard Date: Thu, 4 Feb 2010 21:29:03 +0000 Subject: fixing a series of errors in (ironically) error display in some database drivers --- system/database/drivers/oci8/oci8_driver.php | 4 ++-- system/database/drivers/sqlite/sqlite_driver.php | 4 ++-- system/database/drivers/sqlite/sqlite_utility.php | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) (limited to 'system') diff --git a/system/database/drivers/oci8/oci8_driver.php b/system/database/drivers/oci8/oci8_driver.php index cd0e09577..1ad05a793 100644 --- a/system/database/drivers/oci8/oci8_driver.php +++ b/system/database/drivers/oci8/oci8_driver.php @@ -244,7 +244,7 @@ class CI_DB_oci8_driver extends CI_DB { if ($this->db_debug) { log_message('error', 'Invalid query: '.$package.'.'.$procedure); - return $this->display_error('db_invalid_query'); + return $this->db->display_error('db_invalid_query'); } return FALSE; } @@ -443,7 +443,7 @@ class CI_DB_oci8_driver extends CI_DB { function insert_id() { // not supported in oracle - return $this->display_error('db_unsupported_function'); + return $this->db->display_error('db_unsupported_function'); } // -------------------------------------------------------------------- diff --git a/system/database/drivers/sqlite/sqlite_driver.php b/system/database/drivers/sqlite/sqlite_driver.php index c08ed2a56..4309c1656 100644 --- a/system/database/drivers/sqlite/sqlite_driver.php +++ b/system/database/drivers/sqlite/sqlite_driver.php @@ -63,7 +63,7 @@ class CI_DB_sqlite_driver extends CI_DB { if ($this->db_debug) { - $this->display_error($error, '', TRUE); + $this->db->display_error($error, '', TRUE); } return FALSE; @@ -88,7 +88,7 @@ class CI_DB_sqlite_driver extends CI_DB { if ($this->db_debug) { - $this->display_error($error, '', TRUE); + $this->db->display_error($error, '', TRUE); } return FALSE; diff --git a/system/database/drivers/sqlite/sqlite_utility.php b/system/database/drivers/sqlite/sqlite_utility.php index 5629dac99..fe63362ee 100644 --- a/system/database/drivers/sqlite/sqlite_utility.php +++ b/system/database/drivers/sqlite/sqlite_utility.php @@ -39,7 +39,7 @@ class CI_DB_sqlite_utility extends CI_DB_utility { { if ($this->db_debug) { - return $this->display_error('db_unsuported_feature'); + return $this->db->display_error('db_unsuported_feature'); } return array(); } -- cgit v1.2.3-24-g4f1b From fac8fbc8bd60399110c8daf4b87dddc9397f5dc7 Mon Sep 17 00:00:00 2001 From: Derek Allard Date: Fri, 5 Feb 2010 16:14:49 +0000 Subject: display_error in driver needs no db reference --- system/database/drivers/oci8/oci8_driver.php | 4 ++-- system/database/drivers/sqlite/sqlite_driver.php | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) (limited to 'system') diff --git a/system/database/drivers/oci8/oci8_driver.php b/system/database/drivers/oci8/oci8_driver.php index 1ad05a793..cd0e09577 100644 --- a/system/database/drivers/oci8/oci8_driver.php +++ b/system/database/drivers/oci8/oci8_driver.php @@ -244,7 +244,7 @@ class CI_DB_oci8_driver extends CI_DB { if ($this->db_debug) { log_message('error', 'Invalid query: '.$package.'.'.$procedure); - return $this->db->display_error('db_invalid_query'); + return $this->display_error('db_invalid_query'); } return FALSE; } @@ -443,7 +443,7 @@ class CI_DB_oci8_driver extends CI_DB { function insert_id() { // not supported in oracle - return $this->db->display_error('db_unsupported_function'); + return $this->display_error('db_unsupported_function'); } // -------------------------------------------------------------------- diff --git a/system/database/drivers/sqlite/sqlite_driver.php b/system/database/drivers/sqlite/sqlite_driver.php index 4309c1656..c08ed2a56 100644 --- a/system/database/drivers/sqlite/sqlite_driver.php +++ b/system/database/drivers/sqlite/sqlite_driver.php @@ -63,7 +63,7 @@ class CI_DB_sqlite_driver extends CI_DB { if ($this->db_debug) { - $this->db->display_error($error, '', TRUE); + $this->display_error($error, '', TRUE); } return FALSE; @@ -88,7 +88,7 @@ class CI_DB_sqlite_driver extends CI_DB { if ($this->db_debug) { - $this->db->display_error($error, '', TRUE); + $this->display_error($error, '', TRUE); } return FALSE; -- cgit v1.2.3-24-g4f1b From b97d21f92c3f38aaab36d2c1f885918375417845 Mon Sep 17 00:00:00 2001 From: Derek Jones Date: Tue, 2 Mar 2010 12:53:43 -0600 Subject: moving core library files out of libraries into new core folder --- system/codeigniter/Base4.php | 69 --- system/codeigniter/Base5.php | 56 -- system/codeigniter/CodeIgniter.php | 280 ---------- system/codeigniter/Common.php | 421 -------------- system/codeigniter/Compat.php | 93 ---- system/codeigniter/index.html | 10 - system/core/Base4.php | 69 +++ system/core/Base5.php | 56 ++ system/core/Benchmark.php | 113 ++++ system/core/CodeIgniter.php | 280 ++++++++++ system/core/Common.php | 421 ++++++++++++++ system/core/Compat.php | 93 ++++ system/core/Config.php | 244 ++++++++ system/core/Controller.php | 127 +++++ system/core/Exceptions.php | 174 ++++++ system/core/Hooks.php | 226 ++++++++ system/core/Input.php | 1067 +++++++++++++++++++++++++++++++++++ system/core/Lang.php | 123 ++++ system/core/Loader.php | 1085 ++++++++++++++++++++++++++++++++++++ system/core/Model.php | 83 +++ system/core/Output.php | 409 ++++++++++++++ system/core/Router.php | 389 +++++++++++++ system/core/URI.php | 586 +++++++++++++++++++ system/core/index.html | 10 + system/libraries/Benchmark.php | 113 ---- system/libraries/Config.php | 244 -------- system/libraries/Controller.php | 127 ----- system/libraries/Exceptions.php | 174 ------ system/libraries/Hooks.php | 226 -------- system/libraries/Input.php | 1067 ----------------------------------- system/libraries/Language.php | 123 ---- system/libraries/Loader.php | 1085 ------------------------------------ system/libraries/Model.php | 83 --- system/libraries/Output.php | 409 -------------- system/libraries/Router.php | 389 ------------- system/libraries/URI.php | 586 ------------------- 36 files changed, 5555 insertions(+), 5555 deletions(-) delete mode 100644 system/codeigniter/Base4.php delete mode 100644 system/codeigniter/Base5.php delete mode 100644 system/codeigniter/CodeIgniter.php delete mode 100644 system/codeigniter/Common.php delete mode 100644 system/codeigniter/Compat.php delete mode 100644 system/codeigniter/index.html create mode 100644 system/core/Base4.php create mode 100644 system/core/Base5.php create mode 100644 system/core/Benchmark.php create mode 100644 system/core/CodeIgniter.php create mode 100644 system/core/Common.php create mode 100644 system/core/Compat.php create mode 100644 system/core/Config.php create mode 100644 system/core/Controller.php create mode 100644 system/core/Exceptions.php create mode 100644 system/core/Hooks.php create mode 100644 system/core/Input.php create mode 100644 system/core/Lang.php create mode 100644 system/core/Loader.php create mode 100644 system/core/Model.php create mode 100644 system/core/Output.php create mode 100644 system/core/Router.php create mode 100644 system/core/URI.php create mode 100644 system/core/index.html delete mode 100644 system/libraries/Benchmark.php delete mode 100644 system/libraries/Config.php delete mode 100644 system/libraries/Controller.php delete mode 100644 system/libraries/Exceptions.php delete mode 100644 system/libraries/Hooks.php delete mode 100644 system/libraries/Input.php delete mode 100644 system/libraries/Language.php delete mode 100644 system/libraries/Loader.php delete mode 100644 system/libraries/Model.php delete mode 100644 system/libraries/Output.php delete mode 100644 system/libraries/Router.php delete mode 100644 system/libraries/URI.php (limited to 'system') diff --git a/system/codeigniter/Base4.php b/system/codeigniter/Base4.php deleted file mode 100644 index 3561c2564..000000000 --- a/system/codeigniter/Base4.php +++ /dev/null @@ -1,69 +0,0 @@ -load->library('email') to instantiate - * classes that can then be used within controllers as $this->email->send() - * - * PHP 4 also has trouble referencing the CI super object within application - * constructors since objects do not exist until the class is fully - * instantiated. Basically PHP 4 sucks... - * - * Since PHP 5 doesn't suffer from this problem so we load one of - * two files based on the version of PHP being run. - * - * @package CodeIgniter - * @subpackage codeigniter - * @category front-controller - * @author ExpressionEngine Dev Team - * @link http://codeigniter.com/user_guide/ - */ - class CI_Base extends CI_Loader { - - function CI_Base() - { - // This allows syntax like $this->load->foo() to work - parent::CI_Loader(); - $this->load =& $this; - - // This allows resources used within controller constructors to work - global $OBJ; - $OBJ = $this->load; // Do NOT use a reference. - } -} - -function &get_instance() -{ - global $CI, $OBJ; - - if (is_object($CI)) - { - return $CI; - } - - return $OBJ->load; -} - - -/* End of file Base4.php */ -/* Location: ./system/codeigniter/Base4.php */ \ No newline at end of file diff --git a/system/codeigniter/Base5.php b/system/codeigniter/Base5.php deleted file mode 100644 index 5d944ae5a..000000000 --- a/system/codeigniter/Base5.php +++ /dev/null @@ -1,56 +0,0 @@ -mark('total_execution_time_start'); -$BM->mark('loading_time_base_classes_start'); - -/* - * ------------------------------------------------------ - * Instantiate the hooks class - * ------------------------------------------------------ - */ - -$EXT =& load_class('Hooks'); - -/* - * ------------------------------------------------------ - * Is there a "pre_system" hook? - * ------------------------------------------------------ - */ -$EXT->_call_hook('pre_system'); - -/* - * ------------------------------------------------------ - * Instantiate the base classes - * ------------------------------------------------------ - */ - -$CFG =& load_class('Config'); -$URI =& load_class('URI'); -$RTR =& load_class('Router'); -$OUT =& load_class('Output'); - -/* - * ------------------------------------------------------ - * 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; - } -} - -/* - * ------------------------------------------------------ - * Load the remaining base classes - * ------------------------------------------------------ - */ - -$IN =& load_class('Input'); -$LANG =& load_class('Language'); - -/* - * ------------------------------------------------------ - * Load the app controller and local controller - * ------------------------------------------------------ - * - * Note: Due to the poor object handling in PHP 4 we'll - * conditionally load different versions of the base - * class. Retaining PHP 4 compatibility requires a bit of a hack. - * - * Note: The Loader class needs to be included first - * - */ -if ( ! is_php('5.0.0')) -{ - load_class('Loader', FALSE); - require(BASEPATH.'codeigniter/Base4'.EXT); -} -else -{ - require(BASEPATH.'codeigniter/Base5'.EXT); -} - -// Load the base controller class -load_class('Controller', FALSE); - -// Load the local application controller -// Note: The Router class automatically validates the controller path. 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().EXT)) -{ - 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().EXT); - -// Set a mark point for benchmarking -$BM->mark('loading_time_base_classes_end'); - - -/* - * ------------------------------------------------------ - * Security check - * ------------------------------------------------------ - * - * 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 $method == 'controller' - OR strncmp($method, '_', 1) == 0 - OR in_array(strtolower($method), array_map('strtolower', get_class_methods('Controller'))) - ) -{ - show_404("{$class}/{$method}"); -} - -/* - * ------------------------------------------------------ - * Is there a "pre_controller" hook? - * ------------------------------------------------------ - */ -$EXT->_call_hook('pre_controller'); - -/* - * ------------------------------------------------------ - * Instantiate the controller and call requested method - * ------------------------------------------------------ - */ - -// Mark a start point so we can benchmark the controller -$BM->mark('controller_execution_time_( '.$class.' / '.$method.' )_start'); - -$CI = new $class(); - -// Is this a scaffolding request? -if ($RTR->scaffolding_request === TRUE) -{ - if ($EXT->_call_hook('scaffolding_override') === FALSE) - { - $CI->_ci_scaffolding(); - } -} -else -{ - /* - * ------------------------------------------------------ - * Is there a "post_controller_constructor" hook? - * ------------------------------------------------------ - */ - $EXT->_call_hook('post_controller_constructor'); - - // Is there a "remap" function? - if (method_exists($CI, '_remap')) - { - $CI->_remap($method); - } - 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)))) - { - 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'); - -/* - * ------------------------------------------------------ - * Is there a "post_controller" hook? - * ------------------------------------------------------ - */ -$EXT->_call_hook('post_controller'); - -/* - * ------------------------------------------------------ - * Send the final rendered output to the browser - * ------------------------------------------------------ - */ - -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/codeigniter/CodeIgniter.php */ \ No newline at end of file diff --git a/system/codeigniter/Common.php b/system/codeigniter/Common.php deleted file mode 100644 index 9a35062a4..000000000 --- a/system/codeigniter/Common.php +++ /dev/null @@ -1,421 +0,0 @@ - 5 -* we'll set a static variable. -* -* @access public -* @param string -* @return bool -*/ -function is_php($version = '5.0.0') -{ - static $_is_php; - $version = (string)$version; - - if ( ! isset($_is_php[$version])) - { - $_is_php[$version] = (version_compare(PHP_VERSION, $version) < 0) ? FALSE : TRUE; - } - - 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 - */ -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 (($fp = @fopen($file, FOPEN_WRITE_CREATE)) === 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 bool optional flag that lets classes get loaded but not instantiated -* @return object -*/ -function &load_class($class, $instantiate = TRUE) -{ - static $objects = array(); - - // Does the class exist? If so, we're done... - if (isset($objects[$class])) - { - return $objects[$class]; - } - - // If the requested class does not exist in the application/libraries - // folder we'll load the native class from the system/libraries folder. - if (file_exists(APPPATH.'libraries/'.config_item('subclass_prefix').$class.EXT)) - { - require(BASEPATH.'libraries/'.$class.EXT); - require(APPPATH.'libraries/'.config_item('subclass_prefix').$class.EXT); - $is_subclass = TRUE; - } - else - { - if (file_exists(APPPATH.'libraries/'.$class.EXT)) - { - require(APPPATH.'libraries/'.$class.EXT); - $is_subclass = FALSE; - } - else - { - require(BASEPATH.'libraries/'.$class.EXT); - $is_subclass = FALSE; - } - } - - if ($instantiate == FALSE) - { - $objects[$class] = TRUE; - return $objects[$class]; - } - - if ($is_subclass == TRUE) - { - $name = config_item('subclass_prefix').$class; - - $objects[$class] =& instantiate_class(new $name()); - return $objects[$class]; - } - - $name = ($class != 'Controller') ? 'CI_'.$class : $class; - - $objects[$class] =& instantiate_class(new $name()); - return $objects[$class]; -} - -/** - * Instantiate Class - * - * Returns a new class object by reference, used by load_class() and the DB class. - * Required to retain PHP 4 compatibility and also not make PHP 5.3 cry. - * - * Use: $obj =& instantiate_class(new Foo()); - * - * @access public - * @param object - * @return object - */ -function &instantiate_class(&$class_object) -{ - return $class_object; -} - -/** -* Loads the main config.php file -* -* @access private -* @return array -*/ -function &get_config() -{ - static $main_conf; - - if ( ! isset($main_conf)) - { - if ( ! file_exists(APPPATH.'config/config'.EXT)) - { - exit('The configuration file config'.EXT.' does not exist.'); - } - - require(APPPATH.'config/config'.EXT); - - if ( ! isset($config) OR ! is_array($config)) - { - exit('Your config file does not appear to be formatted correctly.'); - } - - $main_conf[0] =& $config; - } - return $main_conf[0]; -} - -/** -* Gets a config item -* -* @access public -* @return mixed -*/ -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]; -} - - -/** -* 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 -*/ -function show_error($message, $status_code = 500) -{ - $error =& load_class('Exceptions'); - echo $error->show_error('An Error Was Encountered', $message, 'error_general', $status_code); - 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. -* -* @access public -* @return void -*/ -function show_404($page = '') -{ - $error =& load_class('Exceptions'); - $error->show_404($page); - exit; -} - - -/** -* 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 -*/ -function log_message($level = 'error', $message, $php_error = FALSE) -{ - static $LOG; - - $config =& get_config(); - if ($config['log_threshold'] == 0) - { - return; - } - - $LOG =& load_class('Log'); - $LOG->write_log($level, $message, $php_error); -} - - -/** - * Set HTTP Status Header - * - * @access public - * @param int the status code - * @param string - * @return void - */ -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); - } -} - - -/** -* Exception Handler -* -* This is the custom exception handler that is declaired at the top -* of Codeigniter.php. The main reason we use this is permit -* PHP errors to be logged in our own log files since we 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 -*/ -function _exception_handler($severity, $message, $filepath, $line) -{ - // We don't bother with "strict" notices since they will fill up - // the log file with information that isn't normally very - // helpful. For example, if you are running PHP 5 and you - // use version 4 style class functions (without prefixes - // like "public", "private", etc.) you'll get notices telling - // you that these have been deprecated. - - if ($severity == E_STRICT) - { - return; - } - - $error =& load_class('Exceptions'); - - // 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... - $config =& get_config(); - if ($config['log_threshold'] == 0) - { - return; - } - - $error->log_exception($severity, $message, $filepath, $line); -} - - - -/* End of file Common.php */ -/* Location: ./system/codeigniter/Common.php */ \ No newline at end of file diff --git a/system/codeigniter/Compat.php b/system/codeigniter/Compat.php deleted file mode 100644 index 40017a93b..000000000 --- a/system/codeigniter/Compat.php +++ /dev/null @@ -1,93 +0,0 @@ - - - 403 Forbidden - - - -

    Directory access is forbidden.

    - - - \ No newline at end of file diff --git a/system/core/Base4.php b/system/core/Base4.php new file mode 100644 index 000000000..3561c2564 --- /dev/null +++ b/system/core/Base4.php @@ -0,0 +1,69 @@ +load->library('email') to instantiate + * classes that can then be used within controllers as $this->email->send() + * + * PHP 4 also has trouble referencing the CI super object within application + * constructors since objects do not exist until the class is fully + * instantiated. Basically PHP 4 sucks... + * + * Since PHP 5 doesn't suffer from this problem so we load one of + * two files based on the version of PHP being run. + * + * @package CodeIgniter + * @subpackage codeigniter + * @category front-controller + * @author ExpressionEngine Dev Team + * @link http://codeigniter.com/user_guide/ + */ + class CI_Base extends CI_Loader { + + function CI_Base() + { + // This allows syntax like $this->load->foo() to work + parent::CI_Loader(); + $this->load =& $this; + + // This allows resources used within controller constructors to work + global $OBJ; + $OBJ = $this->load; // Do NOT use a reference. + } +} + +function &get_instance() +{ + global $CI, $OBJ; + + if (is_object($CI)) + { + return $CI; + } + + return $OBJ->load; +} + + +/* End of file Base4.php */ +/* Location: ./system/codeigniter/Base4.php */ \ No newline at end of file diff --git a/system/core/Base5.php b/system/core/Base5.php new file mode 100644 index 000000000..5d944ae5a --- /dev/null +++ b/system/core/Base5.php @@ -0,0 +1,56 @@ +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}'; + } + +} + +// END CI_Benchmark class + +/* End of file Benchmark.php */ +/* Location: ./system/libraries/Benchmark.php */ \ No newline at end of file diff --git a/system/core/CodeIgniter.php b/system/core/CodeIgniter.php new file mode 100644 index 000000000..5d5bb144b --- /dev/null +++ b/system/core/CodeIgniter.php @@ -0,0 +1,280 @@ +mark('total_execution_time_start'); +$BM->mark('loading_time_base_classes_start'); + +/* + * ------------------------------------------------------ + * Instantiate the hooks class + * ------------------------------------------------------ + */ + +$EXT =& load_class('Hooks'); + +/* + * ------------------------------------------------------ + * Is there a "pre_system" hook? + * ------------------------------------------------------ + */ +$EXT->_call_hook('pre_system'); + +/* + * ------------------------------------------------------ + * Instantiate the base classes + * ------------------------------------------------------ + */ + +$CFG =& load_class('Config'); +$URI =& load_class('URI'); +$RTR =& load_class('Router'); +$OUT =& load_class('Output'); + +/* + * ------------------------------------------------------ + * 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; + } +} + +/* + * ------------------------------------------------------ + * Load the remaining base classes + * ------------------------------------------------------ + */ + +$IN =& load_class('Input'); +$LANG =& load_class('Language'); + +/* + * ------------------------------------------------------ + * Load the app controller and local controller + * ------------------------------------------------------ + * + * Note: Due to the poor object handling in PHP 4 we'll + * conditionally load different versions of the base + * class. Retaining PHP 4 compatibility requires a bit of a hack. + * + * Note: The Loader class needs to be included first + * + */ +if ( ! is_php('5.0.0')) +{ + load_class('Loader', FALSE); + require(BASEPATH.'codeigniter/Base4'.EXT); +} +else +{ + require(BASEPATH.'codeigniter/Base5'.EXT); +} + +// Load the base controller class +load_class('Controller', FALSE); + +// Load the local application controller +// Note: The Router class automatically validates the controller path. 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().EXT)) +{ + 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().EXT); + +// Set a mark point for benchmarking +$BM->mark('loading_time_base_classes_end'); + + +/* + * ------------------------------------------------------ + * Security check + * ------------------------------------------------------ + * + * 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 $method == 'controller' + OR strncmp($method, '_', 1) == 0 + OR in_array(strtolower($method), array_map('strtolower', get_class_methods('Controller'))) + ) +{ + show_404("{$class}/{$method}"); +} + +/* + * ------------------------------------------------------ + * Is there a "pre_controller" hook? + * ------------------------------------------------------ + */ +$EXT->_call_hook('pre_controller'); + +/* + * ------------------------------------------------------ + * Instantiate the controller and call requested method + * ------------------------------------------------------ + */ + +// Mark a start point so we can benchmark the controller +$BM->mark('controller_execution_time_( '.$class.' / '.$method.' )_start'); + +$CI = new $class(); + +// Is this a scaffolding request? +if ($RTR->scaffolding_request === TRUE) +{ + if ($EXT->_call_hook('scaffolding_override') === FALSE) + { + $CI->_ci_scaffolding(); + } +} +else +{ + /* + * ------------------------------------------------------ + * Is there a "post_controller_constructor" hook? + * ------------------------------------------------------ + */ + $EXT->_call_hook('post_controller_constructor'); + + // Is there a "remap" function? + if (method_exists($CI, '_remap')) + { + $CI->_remap($method); + } + 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)))) + { + 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'); + +/* + * ------------------------------------------------------ + * Is there a "post_controller" hook? + * ------------------------------------------------------ + */ +$EXT->_call_hook('post_controller'); + +/* + * ------------------------------------------------------ + * Send the final rendered output to the browser + * ------------------------------------------------------ + */ + +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/codeigniter/CodeIgniter.php */ \ No newline at end of file diff --git a/system/core/Common.php b/system/core/Common.php new file mode 100644 index 000000000..9a35062a4 --- /dev/null +++ b/system/core/Common.php @@ -0,0 +1,421 @@ + 5 +* we'll set a static variable. +* +* @access public +* @param string +* @return bool +*/ +function is_php($version = '5.0.0') +{ + static $_is_php; + $version = (string)$version; + + if ( ! isset($_is_php[$version])) + { + $_is_php[$version] = (version_compare(PHP_VERSION, $version) < 0) ? FALSE : TRUE; + } + + 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 + */ +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 (($fp = @fopen($file, FOPEN_WRITE_CREATE)) === 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 bool optional flag that lets classes get loaded but not instantiated +* @return object +*/ +function &load_class($class, $instantiate = TRUE) +{ + static $objects = array(); + + // Does the class exist? If so, we're done... + if (isset($objects[$class])) + { + return $objects[$class]; + } + + // If the requested class does not exist in the application/libraries + // folder we'll load the native class from the system/libraries folder. + if (file_exists(APPPATH.'libraries/'.config_item('subclass_prefix').$class.EXT)) + { + require(BASEPATH.'libraries/'.$class.EXT); + require(APPPATH.'libraries/'.config_item('subclass_prefix').$class.EXT); + $is_subclass = TRUE; + } + else + { + if (file_exists(APPPATH.'libraries/'.$class.EXT)) + { + require(APPPATH.'libraries/'.$class.EXT); + $is_subclass = FALSE; + } + else + { + require(BASEPATH.'libraries/'.$class.EXT); + $is_subclass = FALSE; + } + } + + if ($instantiate == FALSE) + { + $objects[$class] = TRUE; + return $objects[$class]; + } + + if ($is_subclass == TRUE) + { + $name = config_item('subclass_prefix').$class; + + $objects[$class] =& instantiate_class(new $name()); + return $objects[$class]; + } + + $name = ($class != 'Controller') ? 'CI_'.$class : $class; + + $objects[$class] =& instantiate_class(new $name()); + return $objects[$class]; +} + +/** + * Instantiate Class + * + * Returns a new class object by reference, used by load_class() and the DB class. + * Required to retain PHP 4 compatibility and also not make PHP 5.3 cry. + * + * Use: $obj =& instantiate_class(new Foo()); + * + * @access public + * @param object + * @return object + */ +function &instantiate_class(&$class_object) +{ + return $class_object; +} + +/** +* Loads the main config.php file +* +* @access private +* @return array +*/ +function &get_config() +{ + static $main_conf; + + if ( ! isset($main_conf)) + { + if ( ! file_exists(APPPATH.'config/config'.EXT)) + { + exit('The configuration file config'.EXT.' does not exist.'); + } + + require(APPPATH.'config/config'.EXT); + + if ( ! isset($config) OR ! is_array($config)) + { + exit('Your config file does not appear to be formatted correctly.'); + } + + $main_conf[0] =& $config; + } + return $main_conf[0]; +} + +/** +* Gets a config item +* +* @access public +* @return mixed +*/ +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]; +} + + +/** +* 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 +*/ +function show_error($message, $status_code = 500) +{ + $error =& load_class('Exceptions'); + echo $error->show_error('An Error Was Encountered', $message, 'error_general', $status_code); + 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. +* +* @access public +* @return void +*/ +function show_404($page = '') +{ + $error =& load_class('Exceptions'); + $error->show_404($page); + exit; +} + + +/** +* 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 +*/ +function log_message($level = 'error', $message, $php_error = FALSE) +{ + static $LOG; + + $config =& get_config(); + if ($config['log_threshold'] == 0) + { + return; + } + + $LOG =& load_class('Log'); + $LOG->write_log($level, $message, $php_error); +} + + +/** + * Set HTTP Status Header + * + * @access public + * @param int the status code + * @param string + * @return void + */ +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); + } +} + + +/** +* Exception Handler +* +* This is the custom exception handler that is declaired at the top +* of Codeigniter.php. The main reason we use this is permit +* PHP errors to be logged in our own log files since we 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 +*/ +function _exception_handler($severity, $message, $filepath, $line) +{ + // We don't bother with "strict" notices since they will fill up + // the log file with information that isn't normally very + // helpful. For example, if you are running PHP 5 and you + // use version 4 style class functions (without prefixes + // like "public", "private", etc.) you'll get notices telling + // you that these have been deprecated. + + if ($severity == E_STRICT) + { + return; + } + + $error =& load_class('Exceptions'); + + // 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... + $config =& get_config(); + if ($config['log_threshold'] == 0) + { + return; + } + + $error->log_exception($severity, $message, $filepath, $line); +} + + + +/* End of file Common.php */ +/* Location: ./system/codeigniter/Common.php */ \ No newline at end of file diff --git a/system/core/Compat.php b/system/core/Compat.php new file mode 100644 index 000000000..40017a93b --- /dev/null +++ b/system/core/Compat.php @@ -0,0 +1,93 @@ +config =& get_config(); + log_message('debug', "Config Class Initialized"); + } + + // -------------------------------------------------------------------- + + /** + * Load Config File + * + * @access public + * @param string the config file name + * @return boolean if the file was loaded correctly + */ + function load($file = '', $use_sections = FALSE, $fail_gracefully = FALSE) + { + $file = ($file == '') ? 'config' : str_replace(EXT, '', $file); + + if (in_array($file, $this->is_loaded, TRUE)) + { + return TRUE; + } + + if ( ! file_exists(APPPATH.'config/'.$file.EXT)) + { + if ($fail_gracefully === TRUE) + { + return FALSE; + } + show_error('The configuration file '.$file.EXT.' does not exist.'); + } + + include(APPPATH.'config/'.$file.EXT); + + if ( ! isset($config) OR ! is_array($config)) + { + if ($fail_gracefully === TRUE) + { + return FALSE; + } + show_error('Your '.$file.EXT.' 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; + unset($config); + + log_message('debug', 'Config file loaded: config/'.$file.EXT); + 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 + * + * The second parameter allows a slash to be added to the end of + * the item, in the case of a path. + * + * @access public + * @param string the config item name + * @param bool + * @return string + */ + function slash_item($item) + { + if ( ! isset($this->config[$item])) + { + return FALSE; + } + + $pref = $this->config[$item]; + + if ($pref != '' && substr($pref, -1) != '/') + { + $pref .= '/'; + } + + return $pref; + } + + // -------------------------------------------------------------------- + + /** + * Site URL + * + * @access public + * @param string the URI string + * @return string + */ + function site_url($uri = '') + { + if (is_array($uri)) + { + $uri = implode('/', $uri); + } + + if ($uri == '') + { + return $this->slash_item('base_url').$this->item('index_page'); + } + else + { + $suffix = ($this->item('url_suffix') == FALSE) ? '' : $this->item('url_suffix'); + return $this->slash_item('base_url').$this->slash_item('index_page').trim($uri, '/').$suffix; + } + } + + // -------------------------------------------------------------------- + + /** + * 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; + } + +} + +// END CI_Config class + +/* End of file Config.php */ +/* Location: ./system/libraries/Config.php */ \ No newline at end of file diff --git a/system/core/Controller.php b/system/core/Controller.php new file mode 100644 index 000000000..c5637c951 --- /dev/null +++ b/system/core/Controller.php @@ -0,0 +1,127 @@ +_ci_initialize(); + log_message('debug', "Controller Class Initialized"); + } + + // -------------------------------------------------------------------- + + /** + * Initialize + * + * Assigns all the bases classes loaded by the front controller to + * variables in this class. Also calls the autoload routine. + * + * @access private + * @return void + */ + function _ci_initialize() + { + // Assign all the class objects that were instantiated by the + // front controller to local class variables so that CI can be + // run as one big super object. + $classes = array( + 'config' => 'Config', + 'input' => 'Input', + 'benchmark' => 'Benchmark', + 'uri' => 'URI', + 'output' => 'Output', + 'lang' => 'Language', + 'router' => 'Router' + ); + + foreach ($classes as $var => $class) + { + $this->$var =& load_class($class); + } + + // In PHP 5 the Loader class is run as a discreet + // class. In PHP 4 it extends the Controller + if (floor(phpversion()) >= 5) + { + $this->load =& load_class('Loader'); + $this->load->_ci_autoloader(); + } + else + { + $this->_ci_autoloader(); + + // sync up the objects since PHP4 was working from a copy + foreach (array_keys(get_object_vars($this)) as $attribute) + { + if (is_object($this->$attribute)) + { + $this->load->$attribute =& $this->$attribute; + } + } + } + } + + // -------------------------------------------------------------------- + + /** + * Run Scaffolding + * + * @access private + * @return void + */ + function _ci_scaffolding() + { + if ($this->_ci_scaffolding === FALSE OR $this->_ci_scaff_table === FALSE) + { + show_404('Scaffolding unavailable'); + } + + $method = ( ! in_array($this->uri->segment(3), array('add', 'insert', 'edit', 'update', 'view', 'delete', 'do_delete'), TRUE)) ? 'view' : $this->uri->segment(3); + + require_once(BASEPATH.'scaffolding/Scaffolding'.EXT); + $scaff = new Scaffolding($this->_ci_scaff_table); + $scaff->$method(); + } + + +} +// END _Controller class + +/* End of file Controller.php */ +/* Location: ./system/libraries/Controller.php */ \ No newline at end of file diff --git a/system/core/Exceptions.php b/system/core/Exceptions.php new file mode 100644 index 000000000..bd567ccdc --- /dev/null +++ b/system/core/Exceptions.php @@ -0,0 +1,174 @@ + '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 + * + */ + function CI_Exceptions() + { + $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 + * @return string + */ + function show_404($page = '') + { + $heading = "404 Page Not Found"; + $message = "The page you requested was not found."; + + 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 + * @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.EXT); + $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'.EXT); + $buffer = ob_get_contents(); + ob_end_clean(); + echo $buffer; + } + + +} +// END Exceptions Class + +/* End of file Exceptions.php */ +/* Location: ./system/libraries/Exceptions.php */ \ No newline at end of file diff --git a/system/core/Hooks.php b/system/core/Hooks.php new file mode 100644 index 000000000..6d736c3f6 --- /dev/null +++ b/system/core/Hooks.php @@ -0,0 +1,226 @@ +_initialize(); + log_message('debug', "Hooks Class Initialized"); + } + + // -------------------------------------------------------------------- + + /** + * Initialize the Hooks Preferences + * + * @access private + * @return void + */ + function _initialize() + { + $CFG =& load_class('Config'); + + // 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. + + @include(APPPATH.'config/hooks'.EXT); + + 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; + } + +} + +// END CI_Hooks class + +/* End of file Hooks.php */ +/* Location: ./system/libraries/Hooks.php */ \ No newline at end of file diff --git a/system/core/Input.php b/system/core/Input.php new file mode 100644 index 000000000..e736d2b8b --- /dev/null +++ b/system/core/Input.php @@ -0,0 +1,1067 @@ + '[removed]', + 'document.write' => '[removed]', + '.parentNode' => '[removed]', + '.innerHTML' => '[removed]', + 'window.location' => '[removed]', + '-moz-binding' => '[removed]', + '' => '-->', + ' '<![CDATA[' + ); + /* never allowed, regex replacement */ + var $never_allowed_regex = array( + "javascript\s*:" => '[removed]', + "expression\s*(\(|&\#40;)" => '[removed]', // CSS and IE + "vbscript\s*:" => '[removed]', // IE, surprise! + "Redirect\s+302" => '[removed]' + ); + + /** + * Constructor + * + * Sets whether to globally enable the XSS processing + * and whether to allow the $_GET array + * + * @access public + */ + function CI_Input() + { + log_message('debug', "Input Class Initialized"); + + $CFG =& load_class('Config'); + $this->use_xss_clean = ($CFG->item('global_xss_filtering') === TRUE) ? TRUE : FALSE; + $this->allow_get_array = ($CFG->item('enable_query_strings') === TRUE) ? TRUE : FALSE; + $this->_sanitize_globals(); + } + + // -------------------------------------------------------------------- + + /** + * 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() + { + // Would kind of 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 security. + // This is effectively the same as register_globals = off + foreach (array($_GET, $_POST, $_COOKIE, $_SERVER, $_FILES, $_ENV, (isset($_SESSION) && is_array($_SESSION)) ? $_SESSION : array()) as $global) + { + if ( ! is_array($global)) + { + if ( ! in_array($global, $protected)) + { + unset($GLOBALS[$global]); + } + } + else + { + foreach ($global as $key => $val) + { + if ( ! in_array($key, $protected)) + { + unset($GLOBALS[$key]); + } + + if (is_array($val)) + { + foreach($val as $k => $v) + { + if ( ! in_array($k, $protected)) + { + unset($GLOBALS[$k]); + } + } + } + } + } + } + + // Is $_GET data allowed? If not we'll set the $_GET to an empty array + if ($this->allow_get_array == FALSE) + { + $_GET = array(); + } + else + { + $_GET = $this->_clean_input_data($_GET); + } + + // Clean $_POST Data + $_POST = $this->_clean_input_data($_POST); + + // Clean $_COOKIE Data + // 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']); + $_COOKIE = $this->_clean_input_data($_COOKIE); + + 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 + if (get_magic_quotes_gpc()) + { + $str = stripslashes($str); + } + + // Should we filter the input data? + if ($this->use_xss_clean === TRUE) + { + $str = $this->xss_clean($str); + } + + // Standardize newlines + if (strpos($str, "\r") !== FALSE) + { + $str = str_replace(array("\r\n", "\r"), "\n", $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.'); + } + + return $str; + } + + // -------------------------------------------------------------------- + + /** + * 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->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 = '', $xss_clean = FALSE) + { + 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 = '', $xss_clean = FALSE) + { + 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); + } + + // -------------------------------------------------------------------- + + /** + * 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 + * + * @access public + * @return string + */ + function ip_address() + { + if ($this->ip_address !== FALSE) + { + return $this->ip_address; + } + + if (config_item('proxy_ips') != '' && $this->server('HTTP_X_FORWARDED_FOR') && $this->server('REMOTE_ADDR')) + { + $proxies = preg_split('/[\s,]/', config_item('proxy_ips'), -1, PREG_SPLIT_NO_EMPTY); + $proxies = is_array($proxies) ? $proxies : array($proxies); + + $this->ip_address = in_array($_SERVER['REMOTE_ADDR'], $proxies) ? $_SERVER['HTTP_X_FORWARDED_FOR'] : $_SERVER['REMOTE_ADDR']; + } + elseif ($this->server('REMOTE_ADDR') AND $this->server('HTTP_CLIENT_IP')) + { + $this->ip_address = $_SERVER['HTTP_CLIENT_IP']; + } + elseif ($this->server('REMOTE_ADDR')) + { + $this->ip_address = $_SERVER['REMOTE_ADDR']; + } + elseif ($this->server('HTTP_CLIENT_IP')) + { + $this->ip_address = $_SERVER['HTTP_CLIENT_IP']; + } + elseif ($this->server('HTTP_X_FORWARDED_FOR')) + { + $this->ip_address = $_SERVER['HTTP_X_FORWARDED_FOR']; + } + + if ($this->ip_address === FALSE) + { + $this->ip_address = '0.0.0.0'; + return $this->ip_address; + } + + if (strstr($this->ip_address, ',')) + { + $x = explode(',', $this->ip_address); + $this->ip_address = trim(end($x)); + } + + if ( ! $this->valid_ip($this->ip_address)) + { + $this->ip_address = '0.0.0.0'; + } + + return $this->ip_address; + } + + // -------------------------------------------------------------------- + + /** + * Validate IP Address + * + * Updated version suggested by Geert De Deckere + * + * @access public + * @param string + * @return string + */ + function valid_ip($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; + } + + // -------------------------------------------------------------------- + + /** + * 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; + } + + // -------------------------------------------------------------------- + + /** + * Filename Security + * + * @access public + * @param string + * @return string + */ + function filename_security($str) + { + $bad = array( + "../", + "./", + "", + "<", + ">", + "'", + '"', + '&', + '$', + '#', + '{', + '}', + '[', + ']', + '=', + ';', + '?', + "%20", + "%22", + "%3c", // < + "%253c", // < + "%3e", // > + "%0e", // > + "%28", // ( + "%29", // ) + "%2528", // ( + "%26", // & + "%24", // $ + "%3f", // ? + "%3b", // ; + "%3d" // = + ); + + return stripslashes(str_replace($bad, '', $str)); + } + + // -------------------------------------------------------------------- + + /** + * 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://blog.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 + * + * @access public + * @param string + * @return string + */ + 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 = $this->_remove_invisible_characters($str); + + /* + * Protect GET variables in URLs + */ + + // 901119URL5918AMP18930PROTECT8198 + + $str = preg_replace('|\&([a-z\_0-9\-]+)\=([a-z\_0-9\-]+)|i', $this->xss_hash()."\\1=\\2", $str); + + /* + * Validate standard character entities + * + * Add a semicolon if missing. We do this to enable + * the conversion of entities to ASCII later. + * + */ + $str = preg_replace('#(&\#?[0-9a-z]{2,})([\x00-\x20])*;?#i', "\\1;\\2", $str); + + /* + * Validate UTF16 two byte encoding (x00) + * + * Just as above, adds a semicolon if missing. + * + */ + $str = preg_replace('#(&\#x?)([0-9A-F]+);?#i',"\\1\\2;",$str); + + /* + * Un-Protect GET variables in URLs + */ + $str = str_replace($this->xss_hash(), '&', $str); + + /* + * URL Decode + * + * Just in case stuff like this is submitted: + * + * Google + * + * Note: Use rawurldecode() so it does not remove plus signs + * + */ + $str = rawurldecode($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-z]+=([\'\"]).*?\\1/si", array($this, '_convert_attribute'), $str); + + $str = preg_replace_callback("/<\w+.*?(?=>|<|$)/si", array($this, '_html_entity_decode_callback'), $str); + + /* + * Remove Invisible Characters Again! + */ + $str = $this->_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. + * + */ + + if (strpos($str, "\t") !== FALSE) + { + $str = str_replace("\t", ' ', $str); + } + + /* + * Capture converted string for later comparison + */ + $converted_string = $str; + + /* + * Not Allowed Under Any Conditions + */ + + foreach ($this->never_allowed_str as $key => $val) + { + $str = str_replace($key, $val, $str); + } + + foreach ($this->never_allowed_regex as $key => $val) + { + $str = preg_replace("#".$key."#i", $val, $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', 'script', 'applet', 'alert', 'document', 'write', 'cookie', 'window'); + foreach ($words as $word) + { + $temp = ''; + + for ($i = 0, $wordlen = strlen($word); $i < $wordlen; $i++) + { + $temp .= substr($word, $i, 1)."\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($temp, 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 for PHP5, but it is dog slow compared + * to these simplified non-capturing preg_match(), especially if the pattern exists in the string + */ + 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/i", $str) OR preg_match("/xss/i", $str)) + { + $str = preg_replace("#<(/*)(script|xss)(.*?)\>#si", '[removed]', $str); + } + } + while($original != $str); + + unset($original); + + /* + * Remove JavaScript Event Handlers + * + * Note: This code is a little blunt. It removes + * the event handler and anything up to the closing >, + * but it's unlikely to be a problem. + * + */ + $event_handlers = array('[^a-z_\-]on\w*','xmlns'); + + if ($is_image === TRUE) + { + /* + * Adobe Photoshop puts XML metadata into JFIF images, including namespacing, + * so we have to allow this for images. -Paul + */ + unset($event_handlers[array_search('xmlns', $event_handlers)]); + } + + $str = preg_replace("#<([^><]+?)(".implode('|', $event_handlers).")(\s*=\s*[^><]*)([><]*)#i", "<\\1\\4", $str); + + /* + * 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|applet|audio|basefont|base|behavior|bgsound|blink|body|embed|expression|form|frameset|frame|head|html|ilayer|iframe|input|isindex|layer|link|meta|object|plaintext|style|script|textarea|title|video|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|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 + * + */ + foreach ($this->never_allowed_str as $key => $val) + { + $str = str_replace($key, $val, $str); + } + + foreach ($this->never_allowed_regex as $key => $val) + { + $str = preg_replace("#".$key."#i", $val, $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) + { + if ($str == $converted_string) + { + return TRUE; + } + else + { + return FALSE; + } + } + + log_message('debug', "XSS Filtering completed"); + return $str; + } + + // -------------------------------------------------------------------- + + /** + * Random Hash for protecting URLs + * + * @access public + * @return string + */ + function xss_hash() + { + if ($this->xss_hash == '') + { + if (phpversion() >= 4.2) + mt_srand(); + else + mt_srand(hexdec(substr(md5(microtime()), -8)) & 0x7fffffff); + + $this->xss_hash = md5(time() + mt_rand(0, 1999999999)); + } + + return $this->xss_hash; + } + + // -------------------------------------------------------------------- + + /** + * Remove Invisible Characters + * + * This prevents sandwiching null characters + * between ascii characters, like Java\0script. + * + * @access public + * @param string + * @return string + */ + function _remove_invisible_characters($str) + { + static $non_displayables; + + if ( ! isset($non_displayables)) + { + // every control character except newline (dec 10), carriage return (dec 13), and horizontal tab (dec 09), + $non_displayables = array( + '/%0[0-8bcef]/', // url encoded 00-08, 11, 12, 14, 15 + '/%1[0-9a-f]/', // url encoded 16-31 + '/[\x00-\x08]/', // 00-08 + '/\x0b/', '/\x0c/', // 11, 12 + '/[\x0e-\x1f]/' // 14-31 + ); + } + + do + { + $cleaned = $str; + $str = preg_replace($non_displayables, '', $str); + } + while ($cleaned != $str); + + return $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 + * + * @access public + * @param type + * @return type + */ + function _compact_exploded_words($matches) + { + return preg_replace('/\s+/s', '', $matches[1]).$matches[2]; + } + + // -------------------------------------------------------------------- + + /** + * Sanitize Naughty HTML + * + * Callback function for xss_clean() to remove naughty HTML elements + * + * @access private + * @param array + * @return string + */ + function _sanitize_naughty_html($matches) + { + // encode opening brace + $str = '<'.$matches[1].$matches[2].$matches[3]; + + // encode captured opening or closing brace to prevent recursive vectors + $str .= str_replace(array('>', '<'), array('>', '<'), $matches[4]); + + return $str; + } + + // -------------------------------------------------------------------- + + /** + * 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 + * + * @access private + * @param array + * @return string + */ + function _js_link_removal($match) + { + $attributes = $this->_filter_attributes(str_replace(array('<', '>'), '', $match[1])); + return str_replace($match[1], preg_replace("#href=.*?(alert\(|alert&\#40;|javascript\:|charset\=|window\.|document\.|\.cookie|_filter_attributes(str_replace(array('<', '>'), '', $match[1])); + return str_replace($match[1], preg_replace("#src=.*?(alert\(|alert&\#40;|javascript\:|charset\=|window\.|document\.|\.cookie|', '<', '\\'), array('>', '<', '\\\\'), $match[0]); + } + + // -------------------------------------------------------------------- + + /** + * HTML Entity Decode Callback + * + * Used as a callback for XSS Clean + * + * @access public + * @param array + * @return string + */ + function _html_entity_decode_callback($match) + { + $CFG =& load_class('Config'); + $charset = $CFG->item('charset'); + + return $this->_html_entity_decode($match[0], strtoupper($charset)); + } + + // -------------------------------------------------------------------- + + /** + * HTML Entities Decode + * + * This function is a replacement for html_entity_decode() + * + * In some versions of PHP the native function does not work + * when UTF-8 is the specified character set, so this gives us + * a work-around. More info here: + * http://bugs.php.net/bug.php?id=25670 + * + * @access private + * @param string + * @param string + * @return string + */ + /* ------------------------------------------------- + /* Replacement for html_entity_decode() + /* -------------------------------------------------*/ + + /* + NOTE: html_entity_decode() has a bug in some PHP versions when UTF-8 is the + character set, and the PHP developers said they were not back porting the + fix to versions other than PHP 5.x. + */ + function _html_entity_decode($str, $charset='UTF-8') + { + if (stristr($str, '&') === FALSE) return $str; + + // 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. + + if (function_exists('html_entity_decode') && (strtolower($charset) != 'utf-8' OR version_compare(phpversion(), '5.0.0', '>='))) + { + $str = html_entity_decode($str, ENT_COMPAT, $charset); + $str = preg_replace('~&#x(0*[0-9a-f]{2,5})~ei', 'chr(hexdec("\\1"))', $str); + return preg_replace('~&#([0-9]{2,4})~e', 'chr(\\1)', $str); + } + + // Numeric Entities + $str = preg_replace('~&#x(0*[0-9a-f]{2,5});{0,1}~ei', 'chr(hexdec("\\1"))', $str); + $str = preg_replace('~&#([0-9]{2,4});{0,1}~e', 'chr(\\1)', $str); + + // Literal Entities - Slightly slow so we do another check + if (stristr($str, '&') === FALSE) + { + $str = strtr($str, array_flip(get_html_translation_table(HTML_ENTITIES))); + } + + return $str; + } + + // -------------------------------------------------------------------- + + /** + * Filter Attributes + * + * Filters tag attributes for consistency and safety + * + * @access public + * @param string + * @return string + */ + 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; + } + + // -------------------------------------------------------------------- + +} +// END Input class + +/* End of file Input.php */ +/* Location: ./system/libraries/Input.php */ \ No newline at end of file diff --git a/system/core/Lang.php b/system/core/Lang.php new file mode 100644 index 000000000..515d04a40 --- /dev/null +++ b/system/core/Lang.php @@ -0,0 +1,123 @@ +is_loaded, TRUE)) + { + return; + } + + if ($idiom == '') + { + $CI =& get_instance(); + $deft_lang = $CI->config->item('language'); + $idiom = ($deft_lang == '') ? 'english' : $deft_lang; + } + + // Determine where the language file is and load it + if (file_exists(APPPATH.'language/'.$idiom.'/'.$langfile)) + { + include(APPPATH.'language/'.$idiom.'/'.$langfile); + } + else + { + if (file_exists(BASEPATH.'language/'.$idiom.'/'.$langfile)) + { + include(BASEPATH.'language/'.$idiom.'/'.$langfile); + } + else + { + 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 = '') + { + $line = ($line == '' OR ! isset($this->language[$line])) ? FALSE : $this->language[$line]; + return $line; + } + +} +// END Language Class + +/* End of file Language.php */ +/* Location: ./system/libraries/Language.php */ \ No newline at end of file diff --git a/system/core/Loader.php b/system/core/Loader.php new file mode 100644 index 000000000..2cd2e93b9 --- /dev/null +++ b/system/core/Loader.php @@ -0,0 +1,1085 @@ + 'unit', 'user_agent' => 'agent'); + + + /** + * Constructor + * + * Sets the path to the view files and gets the initial output buffering level + * + * @access public + */ + function CI_Loader() + { + $this->_ci_is_php5 = (floor(phpversion()) >= 5) ? TRUE : FALSE; + $this->_ci_view_path = APPPATH.'views/'; + $this->_ci_ob_level = ob_get_level(); + + log_message('debug', "Loader Class Initialized"); + } + + // -------------------------------------------------------------------- + + /** + * Class Loader + * + * This function lets users load and instantiate classes. + * It is designed to be called from a user's app controllers. + * + * @access public + * @param string the name of the class + * @param mixed the optional parameters + * @param string an optional object name + * @return void + */ + function library($library = '', $params = NULL, $object_name = NULL) + { + if ($library == '') + { + return FALSE; + } + + if ( ! is_null($params) AND ! is_array($params)) + { + $params = NULL; + } + + if (is_array($library)) + { + foreach ($library as $class) + { + $this->_ci_load_class($class, $params, $object_name); + } + } + else + { + $this->_ci_load_class($library, $params, $object_name); + } + + $this->_ci_assign_to_models(); + } + + // -------------------------------------------------------------------- + + /** + * Model Loader + * + * This function lets users load and instantiate models. + * + * @access public + * @param string the name of the class + * @param string name for the model + * @param bool database connection + * @return void + */ + function model($model, $name = '', $db_conn = FALSE) + { + if (is_array($model)) + { + foreach($model as $babe) + { + $this->model($babe); + } + return; + } + + if ($model == '') + { + return; + } + + // Is the model in a sub-folder? If so, parse out the filename and path. + if (strpos($model, '/') === FALSE) + { + $path = ''; + } + else + { + $x = explode('/', $model); + $model = end($x); + unset($x[count($x)-1]); + $path = implode('/', $x).'/'; + } + + 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); + + if ( ! file_exists(APPPATH.'models/'.$path.$model.EXT)) + { + show_error('Unable to locate the model you have specified: '.$model); + } + + 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('Model')) + { + load_class('Model', FALSE); + } + + require_once(APPPATH.'models/'.$path.$model.EXT); + + $model = ucfirst($model); + + $CI->$name = new $model(); + $CI->$name->_assign_libraries(); + + $this->_ci_models[] = $name; + } + + // -------------------------------------------------------------------- + + /** + * Database Loader + * + * @access public + * @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 + */ + 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'.EXT); + + 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); + + // Assign the DB object to any existing models + $this->_ci_assign_to_models(); + } + + // -------------------------------------------------------------------- + + /** + * Load the Utilities Class + * + * @access public + * @return string + */ + 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'.EXT); + require_once(BASEPATH.'database/drivers/'.$CI->db->dbdriver.'/'.$CI->db->dbdriver.'_utility'.EXT); + $class = 'CI_DB_'.$CI->db->dbdriver.'_utility'; + + $CI->dbutil =& instantiate_class(new $class()); + + $CI->load->_ci_assign_to_models(); + } + + // -------------------------------------------------------------------- + + /** + * Load the Database Forge Class + * + * @access public + * @return string + */ + function dbforge() + { + if ( ! class_exists('CI_DB')) + { + $this->database(); + } + + $CI =& get_instance(); + + require_once(BASEPATH.'database/DB_forge'.EXT); + require_once(BASEPATH.'database/drivers/'.$CI->db->dbdriver.'/'.$CI->db->dbdriver.'_forge'.EXT); + $class = 'CI_DB_'.$CI->db->dbdriver.'_forge'; + + $CI->dbforge = new $class(); + + $CI->load->_ci_assign_to_models(); + } + + // -------------------------------------------------------------------- + + /** + * 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. + * + * @access public + * @param string + * @param array + * @param bool + * @return void + */ + 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 + * + * @access public + * @param string + * @param bool + * @return string + */ + 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. + * + * @access public + * @param array + * @return void + */ + 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; + } + } + } + + // -------------------------------------------------------------------- + + /** + * Load Helper + * + * This function loads the specified helper file. + * + * @access public + * @param mixed + * @return void + */ + function helper($helpers = array()) + { + if ( ! is_array($helpers)) + { + $helpers = array($helpers); + } + + foreach ($helpers as $helper) + { + $helper = strtolower(str_replace(EXT, '', str_replace('_helper', '', $helper)).'_helper'); + + if (isset($this->_ci_helpers[$helper])) + { + continue; + } + + $ext_helper = APPPATH.'helpers/'.config_item('subclass_prefix').$helper.EXT; + + // Is this a helper extension request? + if (file_exists($ext_helper)) + { + $base_helper = BASEPATH.'helpers/'.$helper.EXT; + + if ( ! file_exists($base_helper)) + { + show_error('Unable to load the requested file: helpers/'.$helper.EXT); + } + + include_once($ext_helper); + include_once($base_helper); + } + elseif (file_exists(APPPATH.'helpers/'.$helper.EXT)) + { + include_once(APPPATH.'helpers/'.$helper.EXT); + } + else + { + if (file_exists(BASEPATH.'helpers/'.$helper.EXT)) + { + include_once(BASEPATH.'helpers/'.$helper.EXT); + } + else + { + show_error('Unable to load the requested file: helpers/'.$helper.EXT); + } + } + + $this->_ci_helpers[$helper] = TRUE; + log_message('debug', 'Helper loaded: '.$helper); + } + } + + // -------------------------------------------------------------------- + + /** + * Load Helpers + * + * This is simply an alias to the above function in case the + * user has written the plural form of this function. + * + * @access public + * @param array + * @return void + */ + function helpers($helpers = array()) + { + $this->helper($helpers); + } + + // -------------------------------------------------------------------- + + /** + * Load Plugin + * + * This function loads the specified plugin. + * + * @access public + * @param array + * @return void + */ + function plugin($plugins = array()) + { + if ( ! is_array($plugins)) + { + $plugins = array($plugins); + } + + foreach ($plugins as $plugin) + { + $plugin = strtolower(str_replace(EXT, '', str_replace('_pi', '', $plugin)).'_pi'); + + if (isset($this->_ci_plugins[$plugin])) + { + continue; + } + + if (file_exists(APPPATH.'plugins/'.$plugin.EXT)) + { + include_once(APPPATH.'plugins/'.$plugin.EXT); + } + else + { + if (file_exists(BASEPATH.'plugins/'.$plugin.EXT)) + { + include_once(BASEPATH.'plugins/'.$plugin.EXT); + } + else + { + show_error('Unable to load the requested file: plugins/'.$plugin.EXT); + } + } + + $this->_ci_plugins[$plugin] = TRUE; + log_message('debug', 'Plugin loaded: '.$plugin); + } + } + + // -------------------------------------------------------------------- + + /** + * Load Plugins + * + * This is simply an alias to the above function in case the + * user has written the plural form of this function. + * + * @access public + * @param array + * @return void + */ + function plugins($plugins = array()) + { + $this->plugin($plugins); + } + + // -------------------------------------------------------------------- + + /** + * Loads a language file + * + * @access public + * @param array + * @param string + * @return void + */ + 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 language files for scaffolding + * + * @access public + * @param string + * @return arra + */ + function scaffold_language($file = '', $lang = '', $return = FALSE) + { + $CI =& get_instance(); + return $CI->lang->load($file, $lang, $return); + } + + // -------------------------------------------------------------------- + + /** + * Loads a config file + * + * @access public + * @param string + * @return void + */ + function config($file = '', $use_sections = FALSE, $fail_gracefully = FALSE) + { + $CI =& get_instance(); + $CI->config->load($file, $use_sections, $fail_gracefully); + } + + // -------------------------------------------------------------------- + + /** + * Scaffolding Loader + * + * This initializing function works a bit different than the + * others. It doesn't load the class. Instead, it simply + * sets a flag indicating that scaffolding is allowed to be + * used. The actual scaffolding function below is + * called by the front controller based on whether the + * second segment of the URL matches the "secret" scaffolding + * word stored in the application/config/routes.php + * + * @access public + * @param string + * @return void + */ + function scaffolding($table = '') + { + if ($table === FALSE) + { + show_error('You must include the name of the table you would like to access when you initialize scaffolding'); + } + + $CI =& get_instance(); + $CI->_ci_scaffolding = TRUE; + $CI->_ci_scaff_table = $table; + } + + // -------------------------------------------------------------------- + + /** + * 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 + * + * @access private + * @param array + * @return void + */ + 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]; + } + + // Set the path to the requested file + if ($_ci_path == '') + { + $_ci_ext = pathinfo($_ci_view, PATHINFO_EXTENSION); + $_ci_file = ($_ci_ext == '') ? $_ci_view.EXT : $_ci_view; + $_ci_path = $this->_ci_view_path.$_ci_file; + } + else + { + $_ci_x = explode('/', $_ci_path); + $_ci_file = end($_ci_x); + } + + if ( ! 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. + // Only needed when running PHP 5 + + if ($this->_ci_is_instance()) + { + $_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 + { + // PHP 4 requires that we use a global + global $OUT; + $OUT->append_output(ob_get_contents()); + @ob_end_clean(); + } + } + + // -------------------------------------------------------------------- + + /** + * Load class + * + * This function loads the requested class. + * + * @access private + * @param string the item that is being loaded + * @param mixed any additional parameters + * @param string an optional object name + * @return void + */ + 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(EXT, '', trim($class, '/')); + + // Was the path included with the class name? + // We look for a slash to determine this + $subdir = ''; + if (strpos($class, '/') !== FALSE) + { + // explode the path so we can separate the filename from the path + $x = explode('/', $class); + + // Reset the $class variable now that we know the actual filename + $class = end($x); + + // Kill the filename from the array + unset($x[count($x)-1]); + + // Glue the path back together, sans filename + $subdir = implode($x, '/').'/'; + } + + // 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.EXT; + + // Is this a class extension request? + if (file_exists($subclass)) + { + $baseclass = BASEPATH.'libraries/'.ucfirst($class).EXT; + + 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; + for ($i = 1; $i < 3; $i++) + { + $path = ($i % 2) ? APPPATH : BASEPATH; + $filepath = $path.'libraries/'.$subdir.$class.EXT; + + // 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 + * + * @access private + * @param string + * @param string + * @param string an optional object name + * @return null + */ + function _ci_init_class($class, $prefix = '', $config = FALSE, $object_name = NULL) + { + // Is there an associated config file for this class? + if ($config === NULL) + { + // We test for both uppercase and lowercase, for servers that + // are case-sensitive with regard to file names + if (file_exists(APPPATH.'config/'.strtolower($class).EXT)) + { + include_once(APPPATH.'config/'.strtolower($class).EXT); + } + elseif (file_exists(APPPATH.'config/'.ucfirst(strtolower($class)).EXT)) + { + include_once(APPPATH.'config/'.ucfirst(strtolower($class)).EXT); + } + } + + 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, plugins, and helpers to be loaded automatically. + * + * @access private + * @param array + * @return void + */ + function _ci_autoloader() + { + include_once(APPPATH.'config/autoload'.EXT); + + if ( ! isset($autoload)) + { + return FALSE; + } + + // Load any custom config file + if (count($autoload['config']) > 0) + { + $CI =& get_instance(); + foreach ($autoload['config'] as $key => $val) + { + $CI->config->load($val); + } + } + + // Autoload plugins, helpers and languages + foreach (array('helper', 'plugin', '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'])) + { + $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 scaffolding + if (in_array('scaffolding', $autoload['libraries'])) + { + $this->scaffolding(); + $autoload['libraries'] = array_diff($autoload['libraries'], array('scaffolding')); + } + + // Load all other libraries + foreach ($autoload['libraries'] as $item) + { + $this->library($item); + } + } + + // Autoload models + if (isset($autoload['model'])) + { + $this->model($autoload['model']); + } + + } + + // -------------------------------------------------------------------- + + /** + * Assign to Models + * + * Makes sure that anything loaded by the loader class (libraries, plugins, etc.) + * will be available to models, if any exist. + * + * @access private + * @param object + * @return array + */ + function _ci_assign_to_models() + { + if (count($this->_ci_models) == 0) + { + return; + } + + if ($this->_ci_is_instance()) + { + $CI =& get_instance(); + foreach ($this->_ci_models as $model) + { + $CI->$model->_assign_libraries(); + } + } + else + { + foreach ($this->_ci_models as $model) + { + $this->$model->_assign_libraries(); + } + } + } + + // -------------------------------------------------------------------- + + /** + * Object to Array + * + * Takes an object as input and converts the class variables to array key/vals + * + * @access private + * @param object + * @return array + */ + function _ci_object_to_array($object) + { + return (is_object($object)) ? get_object_vars($object) : $object; + } + + // -------------------------------------------------------------------- + + /** + * Determines whether we should use the CI instance or $this + * + * @access private + * @return bool + */ + function _ci_is_instance() + { + if ($this->_ci_is_php5 == TRUE) + { + return TRUE; + } + + global $CI; + return (is_object($CI)) ? TRUE : FALSE; + } + +} + +/* End of file Loader.php */ +/* Location: ./system/libraries/Loader.php */ \ No newline at end of file diff --git a/system/core/Model.php b/system/core/Model.php new file mode 100644 index 000000000..e9c2d24d1 --- /dev/null +++ b/system/core/Model.php @@ -0,0 +1,83 @@ +_assign_libraries( (method_exists($this, '__get') OR method_exists($this, '__set')) ? FALSE : TRUE ); + + // We don't want to assign the model object to itself when using the + // assign_libraries function below so we'll grab the name of the model parent + $this->_parent_name = ucfirst(get_class($this)); + + log_message('debug', "Model Class Initialized"); + } + + /** + * Assign Libraries + * + * Creates local references to all currently instantiated objects + * so that any syntax that can be legally used in a controller + * can be used within models. + * + * @access private + */ + function _assign_libraries($use_reference = TRUE) + { + $CI =& get_instance(); + foreach (array_keys(get_object_vars($CI)) as $key) + { + if ( ! isset($this->$key) AND $key != $this->_parent_name) + { + // In some cases using references can cause + // problems so we'll conditionally use them + if ($use_reference == TRUE) + { + $this->$key = NULL; // Needed to prevent reference errors with some configurations + $this->$key =& $CI->$key; + } + else + { + $this->$key = $CI->$key; + } + } + } + } + +} +// END Model Class + +/* End of file Model.php */ +/* Location: ./system/libraries/Model.php */ \ No newline at end of file diff --git a/system/core/Output.php b/system/core/Output.php new file mode 100644 index 000000000..6a9a11677 --- /dev/null +++ b/system/core/Output.php @@ -0,0 +1,409 @@ +final_output; + } + + // -------------------------------------------------------------------- + + /** + * Set Output + * + * Sets the output string + * + * @access public + * @param string + * @return void + */ + function set_output($output) + { + $this->final_output = $output; + } + + // -------------------------------------------------------------------- + + /** + * 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; + } + } + + // -------------------------------------------------------------------- + + /** + * 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 + * @return void + */ + function set_header($header, $replace = TRUE) + { + $this->headers[] = array($header, $replace); + } + + // -------------------------------------------------------------------- + + /** + * 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); + } + + // -------------------------------------------------------------------- + + /** + * Enable/disable Profiler + * + * @access public + * @param bool + * @return void + */ + function enable_profiler($val = TRUE) + { + $this->enable_profiler = (is_bool($val)) ? $val : TRUE; + } + + // -------------------------------------------------------------------- + + /** + * Set Cache + * + * @access public + * @param integer + * @return void + */ + function cache($time) + { + $this->cache_expiration = ( ! is_numeric($time)) ? 0 : $time; + } + + // -------------------------------------------------------------------- + + /** + * 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 + * @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; + + // -------------------------------------------------------------------- + + // Set the output data + if ($output == '') + { + $output =& $this->final_output; + } + + // -------------------------------------------------------------------- + + // Do we need to write a cache file? + if ($this->cache_expiration > 0) + { + $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'); + $output = str_replace('{elapsed_time}', $elapsed, $output); + + $memory = ( ! function_exists('memory_get_usage')) ? '0' : round(memory_get_usage()/1024/1024, 2).'MB'; + $output = str_replace('{memory_usage}', $memory, $output); + + // -------------------------------------------------------------------- + + // Is compression requested? + if ($CFG->item('compress_output') === TRUE) + { + 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 get_instance() function exist? + // If not we know we are dealing with a cache file so we'll + // simply echo out the data and exit. + if ( ! function_exists('get_instance')) + { + echo $output; + log_message('debug', "Final output sent to browser"); + log_message('debug', "Total execution time: ".$elapsed); + return TRUE; + } + + // -------------------------------------------------------------------- + + // Grab the super object. We'll need it in a moment... + $CI =& get_instance(); + + // 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 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 + * @return void + */ + function _write_cache($output) + { + $CI =& get_instance(); + $path = $CI->config->item('cache_path'); + + $cache_path = ($path == '') ? BASEPATH.'cache/' : $path; + + if ( ! is_dir($cache_path) OR ! is_really_writable($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 + * @return void + */ + function _display_cache(&$CFG, &$URI) + { + $cache_path = ($CFG->item('cache_path') == '') ? BASEPATH.'cache/' : $CFG->item('cache_path'); + + if ( ! is_dir($cache_path) OR ! is_really_writable($cache_path)) + { + return FALSE; + } + + // 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']))) + { + @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; + } + + +} +// END Output Class + +/* End of file Output.php */ +/* Location: ./system/libraries/Output.php */ \ No newline at end of file diff --git a/system/core/Router.php b/system/core/Router.php new file mode 100644 index 000000000..20e69721d --- /dev/null +++ b/system/core/Router.php @@ -0,0 +1,389 @@ +config =& load_class('Config'); + $this->uri =& load_class('URI'); + $this->_set_routing(); + 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? + // If so, we're done since segment based URIs are not used with query strings. + if ($this->config->item('enable_query_strings') === TRUE AND isset($_GET[$this->config->item('controller_trigger')])) + { + $this->set_class(trim($this->uri->_filter_uri($_GET[$this->config->item('controller_trigger')]))); + + if (isset($_GET[$this->config->item('function_trigger')])) + { + $this->set_method(trim($this->uri->_filter_uri($_GET[$this->config->item('function_trigger')]))); + } + + return; + } + + // Load the routes.php file. + @include(APPPATH.'config/routes'.EXT); + $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']); + + // 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 == '') + { + 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."); + } + + if (strpos($this->default_controller, '/') !== FALSE) + { + $x = explode('/', $this->default_controller); + + $this->set_class(end($x)); + $this->set_method('index'); + $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."); + return; + } + unset($this->routes['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 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_class($segments[0]); + + if (isset($segments[1])) + { + // A scaffolding request. No funny business with the URL + if ($this->routes['scaffolding_trigger'] == $segments[1] AND $segments[1] != '_ci_scaffolding') + { + $this->scaffolding_request = TRUE; + unset($this->routes['scaffolding_trigger']); + } + else + { + // 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) + { + // Does the requested controller exist in the root folder? + if (file_exists(APPPATH.'controllers/'.$segments[0].EXT)) + { + 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].EXT)) + { + show_404($this->fetch_directory().$segments[0]); + } + } + 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.EXT)) + { + $this->directory = ''; + return array(); + } + + } + + return $segments; + } + + // Can't find the requested controller... + 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() + { + // Do we even have any custom routing to deal with? + // There is a default scaffolding trigger, so we'll look just for 1 + if (count($this->routes) == 1) + { + $this->_set_request($this->uri->segments); + return; + } + + // 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])) + { + $this->_set_request(explode('/', $this->routes[$uri])); + return; + } + + // 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); + } + + $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($this->uri->segments); + } + + // -------------------------------------------------------------------- + + /** + * Set the class name + * + * @access public + * @param string + * @return void + */ + function set_class($class) + { + $this->class = $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 = $dir.'/'; + } + + // -------------------------------------------------------------------- + + /** + * Fetch the sub-directory (if any) that contains the requested controller class + * + * @access public + * @return string + */ + function fetch_directory() + { + return $this->directory; + } + +} +// END Router Class + +/* End of file Router.php */ +/* Location: ./system/libraries/Router.php */ \ No newline at end of file diff --git a/system/core/URI.php b/system/core/URI.php new file mode 100644 index 000000000..23efb38c1 --- /dev/null +++ b/system/core/URI.php @@ -0,0 +1,586 @@ +config =& load_class('Config'); + 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') + { + // If the URL has a question mark then it's simplest to just + // build the URI string from the zero index of the $_GET array. + // This avoids having to deal with $_SERVER variables, which + // can be unreliable in some environments + if (is_array($_GET) && count($_GET) == 1 && trim(key($_GET), '/') != '') + { + $this->uri_string = key($_GET); + 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->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->uri_string = $path; + return; + } + + // No QUERY_STRING?... Maybe the ORIG_PATH_INFO variable exists? + $path = str_replace($_SERVER['SCRIPT_NAME'], '', (isset($_SERVER['ORIG_PATH_INFO'])) ? $_SERVER['ORIG_PATH_INFO'] : @getenv('ORIG_PATH_INFO')); + if (trim($path, '/') != '' && $path != "/".SELF) + { + // remove path and script information so we have good URI data + $this->uri_string = $path; + return; + } + + // We've exhausted all our options... + $this->uri_string = ''; + } + else + { + $uri = strtoupper($this->config->item('uri_protocol')); + + if ($uri == 'REQUEST_URI') + { + $this->uri_string = $this->_parse_request_uri(); + return; + } + + $this->uri_string = (isset($_SERVER[$uri])) ? $_SERVER[$uri] : @getenv($uri); + } + + // If the URI contains only a slash we'll kill it + if ($this->uri_string == '/') + { + $this->uri_string = ''; + } + } + + // -------------------------------------------------------------------- + + /** + * Parse the REQUEST_URI + * + * Due to the way REQUEST_URI works it usually contains path info + * that makes it unusable as URI data. We'll trim off the unnecessary + * data, hopefully arriving at a valid URI that we can use. + * + * @access private + * @return string + */ + function _parse_request_uri() + { + if ( ! isset($_SERVER['REQUEST_URI']) OR $_SERVER['REQUEST_URI'] == '') + { + return ''; + } + + $request_uri = preg_replace("|/(.*)|", "\\1", str_replace("\\", "/", $_SERVER['REQUEST_URI'])); + + if ($request_uri == '' OR $request_uri == SELF) + { + return ''; + } + + $fc_path = FCPATH.SELF; + if (strpos($request_uri, '?') !== FALSE) + { + $fc_path .= '?'; + } + + $parsed_uri = explode("/", $request_uri); + + $i = 0; + foreach(explode("/", $fc_path) as $segment) + { + if (isset($parsed_uri[$i]) && $segment == $parsed_uri[$i]) + { + $i++; + } + } + + $parsed_uri = implode("/", array_slice($parsed_uri, $i)); + + if ($parsed_uri != '') + { + $parsed_uri = '/'.$parsed_uri; + } + + return $parsed_uri; + } + + // -------------------------------------------------------------------- + + /** + * 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 + * + */ + 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') + { + if ($where == 'trailing') + { + $trailing = '/'; + $leading = ''; + } + elseif ($where == 'leading') + { + $leading = '/'; + $trailing = ''; + } + else + { + $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()).'/'; + } + +} +// END URI Class + +/* End of file URI.php */ +/* Location: ./system/libraries/URI.php */ \ No newline at end of file diff --git a/system/core/index.html b/system/core/index.html new file mode 100644 index 000000000..c942a79ce --- /dev/null +++ b/system/core/index.html @@ -0,0 +1,10 @@ + + + 403 Forbidden + + + +

    Directory access is forbidden.

    + + + \ No newline at end of file diff --git a/system/libraries/Benchmark.php b/system/libraries/Benchmark.php deleted file mode 100644 index d485ee21d..000000000 --- a/system/libraries/Benchmark.php +++ /dev/null @@ -1,113 +0,0 @@ -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}'; - } - -} - -// END CI_Benchmark class - -/* End of file Benchmark.php */ -/* Location: ./system/libraries/Benchmark.php */ \ No newline at end of file diff --git a/system/libraries/Config.php b/system/libraries/Config.php deleted file mode 100644 index 760120779..000000000 --- a/system/libraries/Config.php +++ /dev/null @@ -1,244 +0,0 @@ -config =& get_config(); - log_message('debug', "Config Class Initialized"); - } - - // -------------------------------------------------------------------- - - /** - * Load Config File - * - * @access public - * @param string the config file name - * @return boolean if the file was loaded correctly - */ - function load($file = '', $use_sections = FALSE, $fail_gracefully = FALSE) - { - $file = ($file == '') ? 'config' : str_replace(EXT, '', $file); - - if (in_array($file, $this->is_loaded, TRUE)) - { - return TRUE; - } - - if ( ! file_exists(APPPATH.'config/'.$file.EXT)) - { - if ($fail_gracefully === TRUE) - { - return FALSE; - } - show_error('The configuration file '.$file.EXT.' does not exist.'); - } - - include(APPPATH.'config/'.$file.EXT); - - if ( ! isset($config) OR ! is_array($config)) - { - if ($fail_gracefully === TRUE) - { - return FALSE; - } - show_error('Your '.$file.EXT.' 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; - unset($config); - - log_message('debug', 'Config file loaded: config/'.$file.EXT); - 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 - * - * The second parameter allows a slash to be added to the end of - * the item, in the case of a path. - * - * @access public - * @param string the config item name - * @param bool - * @return string - */ - function slash_item($item) - { - if ( ! isset($this->config[$item])) - { - return FALSE; - } - - $pref = $this->config[$item]; - - if ($pref != '' && substr($pref, -1) != '/') - { - $pref .= '/'; - } - - return $pref; - } - - // -------------------------------------------------------------------- - - /** - * Site URL - * - * @access public - * @param string the URI string - * @return string - */ - function site_url($uri = '') - { - if (is_array($uri)) - { - $uri = implode('/', $uri); - } - - if ($uri == '') - { - return $this->slash_item('base_url').$this->item('index_page'); - } - else - { - $suffix = ($this->item('url_suffix') == FALSE) ? '' : $this->item('url_suffix'); - return $this->slash_item('base_url').$this->slash_item('index_page').trim($uri, '/').$suffix; - } - } - - // -------------------------------------------------------------------- - - /** - * 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; - } - -} - -// END CI_Config class - -/* End of file Config.php */ -/* Location: ./system/libraries/Config.php */ \ No newline at end of file diff --git a/system/libraries/Controller.php b/system/libraries/Controller.php deleted file mode 100644 index c5637c951..000000000 --- a/system/libraries/Controller.php +++ /dev/null @@ -1,127 +0,0 @@ -_ci_initialize(); - log_message('debug', "Controller Class Initialized"); - } - - // -------------------------------------------------------------------- - - /** - * Initialize - * - * Assigns all the bases classes loaded by the front controller to - * variables in this class. Also calls the autoload routine. - * - * @access private - * @return void - */ - function _ci_initialize() - { - // Assign all the class objects that were instantiated by the - // front controller to local class variables so that CI can be - // run as one big super object. - $classes = array( - 'config' => 'Config', - 'input' => 'Input', - 'benchmark' => 'Benchmark', - 'uri' => 'URI', - 'output' => 'Output', - 'lang' => 'Language', - 'router' => 'Router' - ); - - foreach ($classes as $var => $class) - { - $this->$var =& load_class($class); - } - - // In PHP 5 the Loader class is run as a discreet - // class. In PHP 4 it extends the Controller - if (floor(phpversion()) >= 5) - { - $this->load =& load_class('Loader'); - $this->load->_ci_autoloader(); - } - else - { - $this->_ci_autoloader(); - - // sync up the objects since PHP4 was working from a copy - foreach (array_keys(get_object_vars($this)) as $attribute) - { - if (is_object($this->$attribute)) - { - $this->load->$attribute =& $this->$attribute; - } - } - } - } - - // -------------------------------------------------------------------- - - /** - * Run Scaffolding - * - * @access private - * @return void - */ - function _ci_scaffolding() - { - if ($this->_ci_scaffolding === FALSE OR $this->_ci_scaff_table === FALSE) - { - show_404('Scaffolding unavailable'); - } - - $method = ( ! in_array($this->uri->segment(3), array('add', 'insert', 'edit', 'update', 'view', 'delete', 'do_delete'), TRUE)) ? 'view' : $this->uri->segment(3); - - require_once(BASEPATH.'scaffolding/Scaffolding'.EXT); - $scaff = new Scaffolding($this->_ci_scaff_table); - $scaff->$method(); - } - - -} -// END _Controller class - -/* End of file Controller.php */ -/* Location: ./system/libraries/Controller.php */ \ No newline at end of file diff --git a/system/libraries/Exceptions.php b/system/libraries/Exceptions.php deleted file mode 100644 index bd567ccdc..000000000 --- a/system/libraries/Exceptions.php +++ /dev/null @@ -1,174 +0,0 @@ - '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 - * - */ - function CI_Exceptions() - { - $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 - * @return string - */ - function show_404($page = '') - { - $heading = "404 Page Not Found"; - $message = "The page you requested was not found."; - - 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 - * @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.EXT); - $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'.EXT); - $buffer = ob_get_contents(); - ob_end_clean(); - echo $buffer; - } - - -} -// END Exceptions Class - -/* End of file Exceptions.php */ -/* Location: ./system/libraries/Exceptions.php */ \ No newline at end of file diff --git a/system/libraries/Hooks.php b/system/libraries/Hooks.php deleted file mode 100644 index 6d736c3f6..000000000 --- a/system/libraries/Hooks.php +++ /dev/null @@ -1,226 +0,0 @@ -_initialize(); - log_message('debug', "Hooks Class Initialized"); - } - - // -------------------------------------------------------------------- - - /** - * Initialize the Hooks Preferences - * - * @access private - * @return void - */ - function _initialize() - { - $CFG =& load_class('Config'); - - // 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. - - @include(APPPATH.'config/hooks'.EXT); - - 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; - } - -} - -// END CI_Hooks class - -/* End of file Hooks.php */ -/* Location: ./system/libraries/Hooks.php */ \ No newline at end of file diff --git a/system/libraries/Input.php b/system/libraries/Input.php deleted file mode 100644 index e736d2b8b..000000000 --- a/system/libraries/Input.php +++ /dev/null @@ -1,1067 +0,0 @@ - '[removed]', - 'document.write' => '[removed]', - '.parentNode' => '[removed]', - '.innerHTML' => '[removed]', - 'window.location' => '[removed]', - '-moz-binding' => '[removed]', - '' => '-->', - ' '<![CDATA[' - ); - /* never allowed, regex replacement */ - var $never_allowed_regex = array( - "javascript\s*:" => '[removed]', - "expression\s*(\(|&\#40;)" => '[removed]', // CSS and IE - "vbscript\s*:" => '[removed]', // IE, surprise! - "Redirect\s+302" => '[removed]' - ); - - /** - * Constructor - * - * Sets whether to globally enable the XSS processing - * and whether to allow the $_GET array - * - * @access public - */ - function CI_Input() - { - log_message('debug', "Input Class Initialized"); - - $CFG =& load_class('Config'); - $this->use_xss_clean = ($CFG->item('global_xss_filtering') === TRUE) ? TRUE : FALSE; - $this->allow_get_array = ($CFG->item('enable_query_strings') === TRUE) ? TRUE : FALSE; - $this->_sanitize_globals(); - } - - // -------------------------------------------------------------------- - - /** - * 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() - { - // Would kind of 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 security. - // This is effectively the same as register_globals = off - foreach (array($_GET, $_POST, $_COOKIE, $_SERVER, $_FILES, $_ENV, (isset($_SESSION) && is_array($_SESSION)) ? $_SESSION : array()) as $global) - { - if ( ! is_array($global)) - { - if ( ! in_array($global, $protected)) - { - unset($GLOBALS[$global]); - } - } - else - { - foreach ($global as $key => $val) - { - if ( ! in_array($key, $protected)) - { - unset($GLOBALS[$key]); - } - - if (is_array($val)) - { - foreach($val as $k => $v) - { - if ( ! in_array($k, $protected)) - { - unset($GLOBALS[$k]); - } - } - } - } - } - } - - // Is $_GET data allowed? If not we'll set the $_GET to an empty array - if ($this->allow_get_array == FALSE) - { - $_GET = array(); - } - else - { - $_GET = $this->_clean_input_data($_GET); - } - - // Clean $_POST Data - $_POST = $this->_clean_input_data($_POST); - - // Clean $_COOKIE Data - // 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']); - $_COOKIE = $this->_clean_input_data($_COOKIE); - - 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 - if (get_magic_quotes_gpc()) - { - $str = stripslashes($str); - } - - // Should we filter the input data? - if ($this->use_xss_clean === TRUE) - { - $str = $this->xss_clean($str); - } - - // Standardize newlines - if (strpos($str, "\r") !== FALSE) - { - $str = str_replace(array("\r\n", "\r"), "\n", $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.'); - } - - return $str; - } - - // -------------------------------------------------------------------- - - /** - * 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->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 = '', $xss_clean = FALSE) - { - 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 = '', $xss_clean = FALSE) - { - 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); - } - - // -------------------------------------------------------------------- - - /** - * 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 - * - * @access public - * @return string - */ - function ip_address() - { - if ($this->ip_address !== FALSE) - { - return $this->ip_address; - } - - if (config_item('proxy_ips') != '' && $this->server('HTTP_X_FORWARDED_FOR') && $this->server('REMOTE_ADDR')) - { - $proxies = preg_split('/[\s,]/', config_item('proxy_ips'), -1, PREG_SPLIT_NO_EMPTY); - $proxies = is_array($proxies) ? $proxies : array($proxies); - - $this->ip_address = in_array($_SERVER['REMOTE_ADDR'], $proxies) ? $_SERVER['HTTP_X_FORWARDED_FOR'] : $_SERVER['REMOTE_ADDR']; - } - elseif ($this->server('REMOTE_ADDR') AND $this->server('HTTP_CLIENT_IP')) - { - $this->ip_address = $_SERVER['HTTP_CLIENT_IP']; - } - elseif ($this->server('REMOTE_ADDR')) - { - $this->ip_address = $_SERVER['REMOTE_ADDR']; - } - elseif ($this->server('HTTP_CLIENT_IP')) - { - $this->ip_address = $_SERVER['HTTP_CLIENT_IP']; - } - elseif ($this->server('HTTP_X_FORWARDED_FOR')) - { - $this->ip_address = $_SERVER['HTTP_X_FORWARDED_FOR']; - } - - if ($this->ip_address === FALSE) - { - $this->ip_address = '0.0.0.0'; - return $this->ip_address; - } - - if (strstr($this->ip_address, ',')) - { - $x = explode(',', $this->ip_address); - $this->ip_address = trim(end($x)); - } - - if ( ! $this->valid_ip($this->ip_address)) - { - $this->ip_address = '0.0.0.0'; - } - - return $this->ip_address; - } - - // -------------------------------------------------------------------- - - /** - * Validate IP Address - * - * Updated version suggested by Geert De Deckere - * - * @access public - * @param string - * @return string - */ - function valid_ip($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; - } - - // -------------------------------------------------------------------- - - /** - * 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; - } - - // -------------------------------------------------------------------- - - /** - * Filename Security - * - * @access public - * @param string - * @return string - */ - function filename_security($str) - { - $bad = array( - "../", - "./", - "", - "<", - ">", - "'", - '"', - '&', - '$', - '#', - '{', - '}', - '[', - ']', - '=', - ';', - '?', - "%20", - "%22", - "%3c", // < - "%253c", // < - "%3e", // > - "%0e", // > - "%28", // ( - "%29", // ) - "%2528", // ( - "%26", // & - "%24", // $ - "%3f", // ? - "%3b", // ; - "%3d" // = - ); - - return stripslashes(str_replace($bad, '', $str)); - } - - // -------------------------------------------------------------------- - - /** - * 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://blog.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 - * - * @access public - * @param string - * @return string - */ - 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 = $this->_remove_invisible_characters($str); - - /* - * Protect GET variables in URLs - */ - - // 901119URL5918AMP18930PROTECT8198 - - $str = preg_replace('|\&([a-z\_0-9\-]+)\=([a-z\_0-9\-]+)|i', $this->xss_hash()."\\1=\\2", $str); - - /* - * Validate standard character entities - * - * Add a semicolon if missing. We do this to enable - * the conversion of entities to ASCII later. - * - */ - $str = preg_replace('#(&\#?[0-9a-z]{2,})([\x00-\x20])*;?#i', "\\1;\\2", $str); - - /* - * Validate UTF16 two byte encoding (x00) - * - * Just as above, adds a semicolon if missing. - * - */ - $str = preg_replace('#(&\#x?)([0-9A-F]+);?#i',"\\1\\2;",$str); - - /* - * Un-Protect GET variables in URLs - */ - $str = str_replace($this->xss_hash(), '&', $str); - - /* - * URL Decode - * - * Just in case stuff like this is submitted: - * - *
    Google - * - * Note: Use rawurldecode() so it does not remove plus signs - * - */ - $str = rawurldecode($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-z]+=([\'\"]).*?\\1/si", array($this, '_convert_attribute'), $str); - - $str = preg_replace_callback("/<\w+.*?(?=>|<|$)/si", array($this, '_html_entity_decode_callback'), $str); - - /* - * Remove Invisible Characters Again! - */ - $str = $this->_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. - * - */ - - if (strpos($str, "\t") !== FALSE) - { - $str = str_replace("\t", ' ', $str); - } - - /* - * Capture converted string for later comparison - */ - $converted_string = $str; - - /* - * Not Allowed Under Any Conditions - */ - - foreach ($this->never_allowed_str as $key => $val) - { - $str = str_replace($key, $val, $str); - } - - foreach ($this->never_allowed_regex as $key => $val) - { - $str = preg_replace("#".$key."#i", $val, $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', 'script', 'applet', 'alert', 'document', 'write', 'cookie', 'window'); - foreach ($words as $word) - { - $temp = ''; - - for ($i = 0, $wordlen = strlen($word); $i < $wordlen; $i++) - { - $temp .= substr($word, $i, 1)."\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($temp, 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 for PHP5, but it is dog slow compared - * to these simplified non-capturing preg_match(), especially if the pattern exists in the string - */ - 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/i", $str) OR preg_match("/xss/i", $str)) - { - $str = preg_replace("#<(/*)(script|xss)(.*?)\>#si", '[removed]', $str); - } - } - while($original != $str); - - unset($original); - - /* - * Remove JavaScript Event Handlers - * - * Note: This code is a little blunt. It removes - * the event handler and anything up to the closing >, - * but it's unlikely to be a problem. - * - */ - $event_handlers = array('[^a-z_\-]on\w*','xmlns'); - - if ($is_image === TRUE) - { - /* - * Adobe Photoshop puts XML metadata into JFIF images, including namespacing, - * so we have to allow this for images. -Paul - */ - unset($event_handlers[array_search('xmlns', $event_handlers)]); - } - - $str = preg_replace("#<([^><]+?)(".implode('|', $event_handlers).")(\s*=\s*[^><]*)([><]*)#i", "<\\1\\4", $str); - - /* - * 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|applet|audio|basefont|base|behavior|bgsound|blink|body|embed|expression|form|frameset|frame|head|html|ilayer|iframe|input|isindex|layer|link|meta|object|plaintext|style|script|textarea|title|video|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|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 - * - */ - foreach ($this->never_allowed_str as $key => $val) - { - $str = str_replace($key, $val, $str); - } - - foreach ($this->never_allowed_regex as $key => $val) - { - $str = preg_replace("#".$key."#i", $val, $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) - { - if ($str == $converted_string) - { - return TRUE; - } - else - { - return FALSE; - } - } - - log_message('debug', "XSS Filtering completed"); - return $str; - } - - // -------------------------------------------------------------------- - - /** - * Random Hash for protecting URLs - * - * @access public - * @return string - */ - function xss_hash() - { - if ($this->xss_hash == '') - { - if (phpversion() >= 4.2) - mt_srand(); - else - mt_srand(hexdec(substr(md5(microtime()), -8)) & 0x7fffffff); - - $this->xss_hash = md5(time() + mt_rand(0, 1999999999)); - } - - return $this->xss_hash; - } - - // -------------------------------------------------------------------- - - /** - * Remove Invisible Characters - * - * This prevents sandwiching null characters - * between ascii characters, like Java\0script. - * - * @access public - * @param string - * @return string - */ - function _remove_invisible_characters($str) - { - static $non_displayables; - - if ( ! isset($non_displayables)) - { - // every control character except newline (dec 10), carriage return (dec 13), and horizontal tab (dec 09), - $non_displayables = array( - '/%0[0-8bcef]/', // url encoded 00-08, 11, 12, 14, 15 - '/%1[0-9a-f]/', // url encoded 16-31 - '/[\x00-\x08]/', // 00-08 - '/\x0b/', '/\x0c/', // 11, 12 - '/[\x0e-\x1f]/' // 14-31 - ); - } - - do - { - $cleaned = $str; - $str = preg_replace($non_displayables, '', $str); - } - while ($cleaned != $str); - - return $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 - * - * @access public - * @param type - * @return type - */ - function _compact_exploded_words($matches) - { - return preg_replace('/\s+/s', '', $matches[1]).$matches[2]; - } - - // -------------------------------------------------------------------- - - /** - * Sanitize Naughty HTML - * - * Callback function for xss_clean() to remove naughty HTML elements - * - * @access private - * @param array - * @return string - */ - function _sanitize_naughty_html($matches) - { - // encode opening brace - $str = '<'.$matches[1].$matches[2].$matches[3]; - - // encode captured opening or closing brace to prevent recursive vectors - $str .= str_replace(array('>', '<'), array('>', '<'), $matches[4]); - - return $str; - } - - // -------------------------------------------------------------------- - - /** - * 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 - * - * @access private - * @param array - * @return string - */ - function _js_link_removal($match) - { - $attributes = $this->_filter_attributes(str_replace(array('<', '>'), '', $match[1])); - return str_replace($match[1], preg_replace("#href=.*?(alert\(|alert&\#40;|javascript\:|charset\=|window\.|document\.|\.cookie|_filter_attributes(str_replace(array('<', '>'), '', $match[1])); - return str_replace($match[1], preg_replace("#src=.*?(alert\(|alert&\#40;|javascript\:|charset\=|window\.|document\.|\.cookie|', '<', '\\'), array('>', '<', '\\\\'), $match[0]); - } - - // -------------------------------------------------------------------- - - /** - * HTML Entity Decode Callback - * - * Used as a callback for XSS Clean - * - * @access public - * @param array - * @return string - */ - function _html_entity_decode_callback($match) - { - $CFG =& load_class('Config'); - $charset = $CFG->item('charset'); - - return $this->_html_entity_decode($match[0], strtoupper($charset)); - } - - // -------------------------------------------------------------------- - - /** - * HTML Entities Decode - * - * This function is a replacement for html_entity_decode() - * - * In some versions of PHP the native function does not work - * when UTF-8 is the specified character set, so this gives us - * a work-around. More info here: - * http://bugs.php.net/bug.php?id=25670 - * - * @access private - * @param string - * @param string - * @return string - */ - /* ------------------------------------------------- - /* Replacement for html_entity_decode() - /* -------------------------------------------------*/ - - /* - NOTE: html_entity_decode() has a bug in some PHP versions when UTF-8 is the - character set, and the PHP developers said they were not back porting the - fix to versions other than PHP 5.x. - */ - function _html_entity_decode($str, $charset='UTF-8') - { - if (stristr($str, '&') === FALSE) return $str; - - // 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. - - if (function_exists('html_entity_decode') && (strtolower($charset) != 'utf-8' OR version_compare(phpversion(), '5.0.0', '>='))) - { - $str = html_entity_decode($str, ENT_COMPAT, $charset); - $str = preg_replace('~&#x(0*[0-9a-f]{2,5})~ei', 'chr(hexdec("\\1"))', $str); - return preg_replace('~&#([0-9]{2,4})~e', 'chr(\\1)', $str); - } - - // Numeric Entities - $str = preg_replace('~&#x(0*[0-9a-f]{2,5});{0,1}~ei', 'chr(hexdec("\\1"))', $str); - $str = preg_replace('~&#([0-9]{2,4});{0,1}~e', 'chr(\\1)', $str); - - // Literal Entities - Slightly slow so we do another check - if (stristr($str, '&') === FALSE) - { - $str = strtr($str, array_flip(get_html_translation_table(HTML_ENTITIES))); - } - - return $str; - } - - // -------------------------------------------------------------------- - - /** - * Filter Attributes - * - * Filters tag attributes for consistency and safety - * - * @access public - * @param string - * @return string - */ - 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; - } - - // -------------------------------------------------------------------- - -} -// END Input class - -/* End of file Input.php */ -/* Location: ./system/libraries/Input.php */ \ No newline at end of file diff --git a/system/libraries/Language.php b/system/libraries/Language.php deleted file mode 100644 index 515d04a40..000000000 --- a/system/libraries/Language.php +++ /dev/null @@ -1,123 +0,0 @@ -is_loaded, TRUE)) - { - return; - } - - if ($idiom == '') - { - $CI =& get_instance(); - $deft_lang = $CI->config->item('language'); - $idiom = ($deft_lang == '') ? 'english' : $deft_lang; - } - - // Determine where the language file is and load it - if (file_exists(APPPATH.'language/'.$idiom.'/'.$langfile)) - { - include(APPPATH.'language/'.$idiom.'/'.$langfile); - } - else - { - if (file_exists(BASEPATH.'language/'.$idiom.'/'.$langfile)) - { - include(BASEPATH.'language/'.$idiom.'/'.$langfile); - } - else - { - 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 = '') - { - $line = ($line == '' OR ! isset($this->language[$line])) ? FALSE : $this->language[$line]; - return $line; - } - -} -// END Language Class - -/* End of file Language.php */ -/* Location: ./system/libraries/Language.php */ \ No newline at end of file diff --git a/system/libraries/Loader.php b/system/libraries/Loader.php deleted file mode 100644 index 2cd2e93b9..000000000 --- a/system/libraries/Loader.php +++ /dev/null @@ -1,1085 +0,0 @@ - 'unit', 'user_agent' => 'agent'); - - - /** - * Constructor - * - * Sets the path to the view files and gets the initial output buffering level - * - * @access public - */ - function CI_Loader() - { - $this->_ci_is_php5 = (floor(phpversion()) >= 5) ? TRUE : FALSE; - $this->_ci_view_path = APPPATH.'views/'; - $this->_ci_ob_level = ob_get_level(); - - log_message('debug', "Loader Class Initialized"); - } - - // -------------------------------------------------------------------- - - /** - * Class Loader - * - * This function lets users load and instantiate classes. - * It is designed to be called from a user's app controllers. - * - * @access public - * @param string the name of the class - * @param mixed the optional parameters - * @param string an optional object name - * @return void - */ - function library($library = '', $params = NULL, $object_name = NULL) - { - if ($library == '') - { - return FALSE; - } - - if ( ! is_null($params) AND ! is_array($params)) - { - $params = NULL; - } - - if (is_array($library)) - { - foreach ($library as $class) - { - $this->_ci_load_class($class, $params, $object_name); - } - } - else - { - $this->_ci_load_class($library, $params, $object_name); - } - - $this->_ci_assign_to_models(); - } - - // -------------------------------------------------------------------- - - /** - * Model Loader - * - * This function lets users load and instantiate models. - * - * @access public - * @param string the name of the class - * @param string name for the model - * @param bool database connection - * @return void - */ - function model($model, $name = '', $db_conn = FALSE) - { - if (is_array($model)) - { - foreach($model as $babe) - { - $this->model($babe); - } - return; - } - - if ($model == '') - { - return; - } - - // Is the model in a sub-folder? If so, parse out the filename and path. - if (strpos($model, '/') === FALSE) - { - $path = ''; - } - else - { - $x = explode('/', $model); - $model = end($x); - unset($x[count($x)-1]); - $path = implode('/', $x).'/'; - } - - 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); - - if ( ! file_exists(APPPATH.'models/'.$path.$model.EXT)) - { - show_error('Unable to locate the model you have specified: '.$model); - } - - 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('Model')) - { - load_class('Model', FALSE); - } - - require_once(APPPATH.'models/'.$path.$model.EXT); - - $model = ucfirst($model); - - $CI->$name = new $model(); - $CI->$name->_assign_libraries(); - - $this->_ci_models[] = $name; - } - - // -------------------------------------------------------------------- - - /** - * Database Loader - * - * @access public - * @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 - */ - 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'.EXT); - - 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); - - // Assign the DB object to any existing models - $this->_ci_assign_to_models(); - } - - // -------------------------------------------------------------------- - - /** - * Load the Utilities Class - * - * @access public - * @return string - */ - 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'.EXT); - require_once(BASEPATH.'database/drivers/'.$CI->db->dbdriver.'/'.$CI->db->dbdriver.'_utility'.EXT); - $class = 'CI_DB_'.$CI->db->dbdriver.'_utility'; - - $CI->dbutil =& instantiate_class(new $class()); - - $CI->load->_ci_assign_to_models(); - } - - // -------------------------------------------------------------------- - - /** - * Load the Database Forge Class - * - * @access public - * @return string - */ - function dbforge() - { - if ( ! class_exists('CI_DB')) - { - $this->database(); - } - - $CI =& get_instance(); - - require_once(BASEPATH.'database/DB_forge'.EXT); - require_once(BASEPATH.'database/drivers/'.$CI->db->dbdriver.'/'.$CI->db->dbdriver.'_forge'.EXT); - $class = 'CI_DB_'.$CI->db->dbdriver.'_forge'; - - $CI->dbforge = new $class(); - - $CI->load->_ci_assign_to_models(); - } - - // -------------------------------------------------------------------- - - /** - * 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. - * - * @access public - * @param string - * @param array - * @param bool - * @return void - */ - 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 - * - * @access public - * @param string - * @param bool - * @return string - */ - 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. - * - * @access public - * @param array - * @return void - */ - 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; - } - } - } - - // -------------------------------------------------------------------- - - /** - * Load Helper - * - * This function loads the specified helper file. - * - * @access public - * @param mixed - * @return void - */ - function helper($helpers = array()) - { - if ( ! is_array($helpers)) - { - $helpers = array($helpers); - } - - foreach ($helpers as $helper) - { - $helper = strtolower(str_replace(EXT, '', str_replace('_helper', '', $helper)).'_helper'); - - if (isset($this->_ci_helpers[$helper])) - { - continue; - } - - $ext_helper = APPPATH.'helpers/'.config_item('subclass_prefix').$helper.EXT; - - // Is this a helper extension request? - if (file_exists($ext_helper)) - { - $base_helper = BASEPATH.'helpers/'.$helper.EXT; - - if ( ! file_exists($base_helper)) - { - show_error('Unable to load the requested file: helpers/'.$helper.EXT); - } - - include_once($ext_helper); - include_once($base_helper); - } - elseif (file_exists(APPPATH.'helpers/'.$helper.EXT)) - { - include_once(APPPATH.'helpers/'.$helper.EXT); - } - else - { - if (file_exists(BASEPATH.'helpers/'.$helper.EXT)) - { - include_once(BASEPATH.'helpers/'.$helper.EXT); - } - else - { - show_error('Unable to load the requested file: helpers/'.$helper.EXT); - } - } - - $this->_ci_helpers[$helper] = TRUE; - log_message('debug', 'Helper loaded: '.$helper); - } - } - - // -------------------------------------------------------------------- - - /** - * Load Helpers - * - * This is simply an alias to the above function in case the - * user has written the plural form of this function. - * - * @access public - * @param array - * @return void - */ - function helpers($helpers = array()) - { - $this->helper($helpers); - } - - // -------------------------------------------------------------------- - - /** - * Load Plugin - * - * This function loads the specified plugin. - * - * @access public - * @param array - * @return void - */ - function plugin($plugins = array()) - { - if ( ! is_array($plugins)) - { - $plugins = array($plugins); - } - - foreach ($plugins as $plugin) - { - $plugin = strtolower(str_replace(EXT, '', str_replace('_pi', '', $plugin)).'_pi'); - - if (isset($this->_ci_plugins[$plugin])) - { - continue; - } - - if (file_exists(APPPATH.'plugins/'.$plugin.EXT)) - { - include_once(APPPATH.'plugins/'.$plugin.EXT); - } - else - { - if (file_exists(BASEPATH.'plugins/'.$plugin.EXT)) - { - include_once(BASEPATH.'plugins/'.$plugin.EXT); - } - else - { - show_error('Unable to load the requested file: plugins/'.$plugin.EXT); - } - } - - $this->_ci_plugins[$plugin] = TRUE; - log_message('debug', 'Plugin loaded: '.$plugin); - } - } - - // -------------------------------------------------------------------- - - /** - * Load Plugins - * - * This is simply an alias to the above function in case the - * user has written the plural form of this function. - * - * @access public - * @param array - * @return void - */ - function plugins($plugins = array()) - { - $this->plugin($plugins); - } - - // -------------------------------------------------------------------- - - /** - * Loads a language file - * - * @access public - * @param array - * @param string - * @return void - */ - 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 language files for scaffolding - * - * @access public - * @param string - * @return arra - */ - function scaffold_language($file = '', $lang = '', $return = FALSE) - { - $CI =& get_instance(); - return $CI->lang->load($file, $lang, $return); - } - - // -------------------------------------------------------------------- - - /** - * Loads a config file - * - * @access public - * @param string - * @return void - */ - function config($file = '', $use_sections = FALSE, $fail_gracefully = FALSE) - { - $CI =& get_instance(); - $CI->config->load($file, $use_sections, $fail_gracefully); - } - - // -------------------------------------------------------------------- - - /** - * Scaffolding Loader - * - * This initializing function works a bit different than the - * others. It doesn't load the class. Instead, it simply - * sets a flag indicating that scaffolding is allowed to be - * used. The actual scaffolding function below is - * called by the front controller based on whether the - * second segment of the URL matches the "secret" scaffolding - * word stored in the application/config/routes.php - * - * @access public - * @param string - * @return void - */ - function scaffolding($table = '') - { - if ($table === FALSE) - { - show_error('You must include the name of the table you would like to access when you initialize scaffolding'); - } - - $CI =& get_instance(); - $CI->_ci_scaffolding = TRUE; - $CI->_ci_scaff_table = $table; - } - - // -------------------------------------------------------------------- - - /** - * 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 - * - * @access private - * @param array - * @return void - */ - 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]; - } - - // Set the path to the requested file - if ($_ci_path == '') - { - $_ci_ext = pathinfo($_ci_view, PATHINFO_EXTENSION); - $_ci_file = ($_ci_ext == '') ? $_ci_view.EXT : $_ci_view; - $_ci_path = $this->_ci_view_path.$_ci_file; - } - else - { - $_ci_x = explode('/', $_ci_path); - $_ci_file = end($_ci_x); - } - - if ( ! 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. - // Only needed when running PHP 5 - - if ($this->_ci_is_instance()) - { - $_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 - { - // PHP 4 requires that we use a global - global $OUT; - $OUT->append_output(ob_get_contents()); - @ob_end_clean(); - } - } - - // -------------------------------------------------------------------- - - /** - * Load class - * - * This function loads the requested class. - * - * @access private - * @param string the item that is being loaded - * @param mixed any additional parameters - * @param string an optional object name - * @return void - */ - 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(EXT, '', trim($class, '/')); - - // Was the path included with the class name? - // We look for a slash to determine this - $subdir = ''; - if (strpos($class, '/') !== FALSE) - { - // explode the path so we can separate the filename from the path - $x = explode('/', $class); - - // Reset the $class variable now that we know the actual filename - $class = end($x); - - // Kill the filename from the array - unset($x[count($x)-1]); - - // Glue the path back together, sans filename - $subdir = implode($x, '/').'/'; - } - - // 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.EXT; - - // Is this a class extension request? - if (file_exists($subclass)) - { - $baseclass = BASEPATH.'libraries/'.ucfirst($class).EXT; - - 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; - for ($i = 1; $i < 3; $i++) - { - $path = ($i % 2) ? APPPATH : BASEPATH; - $filepath = $path.'libraries/'.$subdir.$class.EXT; - - // 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 - * - * @access private - * @param string - * @param string - * @param string an optional object name - * @return null - */ - function _ci_init_class($class, $prefix = '', $config = FALSE, $object_name = NULL) - { - // Is there an associated config file for this class? - if ($config === NULL) - { - // We test for both uppercase and lowercase, for servers that - // are case-sensitive with regard to file names - if (file_exists(APPPATH.'config/'.strtolower($class).EXT)) - { - include_once(APPPATH.'config/'.strtolower($class).EXT); - } - elseif (file_exists(APPPATH.'config/'.ucfirst(strtolower($class)).EXT)) - { - include_once(APPPATH.'config/'.ucfirst(strtolower($class)).EXT); - } - } - - 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, plugins, and helpers to be loaded automatically. - * - * @access private - * @param array - * @return void - */ - function _ci_autoloader() - { - include_once(APPPATH.'config/autoload'.EXT); - - if ( ! isset($autoload)) - { - return FALSE; - } - - // Load any custom config file - if (count($autoload['config']) > 0) - { - $CI =& get_instance(); - foreach ($autoload['config'] as $key => $val) - { - $CI->config->load($val); - } - } - - // Autoload plugins, helpers and languages - foreach (array('helper', 'plugin', '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'])) - { - $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 scaffolding - if (in_array('scaffolding', $autoload['libraries'])) - { - $this->scaffolding(); - $autoload['libraries'] = array_diff($autoload['libraries'], array('scaffolding')); - } - - // Load all other libraries - foreach ($autoload['libraries'] as $item) - { - $this->library($item); - } - } - - // Autoload models - if (isset($autoload['model'])) - { - $this->model($autoload['model']); - } - - } - - // -------------------------------------------------------------------- - - /** - * Assign to Models - * - * Makes sure that anything loaded by the loader class (libraries, plugins, etc.) - * will be available to models, if any exist. - * - * @access private - * @param object - * @return array - */ - function _ci_assign_to_models() - { - if (count($this->_ci_models) == 0) - { - return; - } - - if ($this->_ci_is_instance()) - { - $CI =& get_instance(); - foreach ($this->_ci_models as $model) - { - $CI->$model->_assign_libraries(); - } - } - else - { - foreach ($this->_ci_models as $model) - { - $this->$model->_assign_libraries(); - } - } - } - - // -------------------------------------------------------------------- - - /** - * Object to Array - * - * Takes an object as input and converts the class variables to array key/vals - * - * @access private - * @param object - * @return array - */ - function _ci_object_to_array($object) - { - return (is_object($object)) ? get_object_vars($object) : $object; - } - - // -------------------------------------------------------------------- - - /** - * Determines whether we should use the CI instance or $this - * - * @access private - * @return bool - */ - function _ci_is_instance() - { - if ($this->_ci_is_php5 == TRUE) - { - return TRUE; - } - - global $CI; - return (is_object($CI)) ? TRUE : FALSE; - } - -} - -/* End of file Loader.php */ -/* Location: ./system/libraries/Loader.php */ \ No newline at end of file diff --git a/system/libraries/Model.php b/system/libraries/Model.php deleted file mode 100644 index e9c2d24d1..000000000 --- a/system/libraries/Model.php +++ /dev/null @@ -1,83 +0,0 @@ -_assign_libraries( (method_exists($this, '__get') OR method_exists($this, '__set')) ? FALSE : TRUE ); - - // We don't want to assign the model object to itself when using the - // assign_libraries function below so we'll grab the name of the model parent - $this->_parent_name = ucfirst(get_class($this)); - - log_message('debug', "Model Class Initialized"); - } - - /** - * Assign Libraries - * - * Creates local references to all currently instantiated objects - * so that any syntax that can be legally used in a controller - * can be used within models. - * - * @access private - */ - function _assign_libraries($use_reference = TRUE) - { - $CI =& get_instance(); - foreach (array_keys(get_object_vars($CI)) as $key) - { - if ( ! isset($this->$key) AND $key != $this->_parent_name) - { - // In some cases using references can cause - // problems so we'll conditionally use them - if ($use_reference == TRUE) - { - $this->$key = NULL; // Needed to prevent reference errors with some configurations - $this->$key =& $CI->$key; - } - else - { - $this->$key = $CI->$key; - } - } - } - } - -} -// END Model Class - -/* End of file Model.php */ -/* Location: ./system/libraries/Model.php */ \ No newline at end of file diff --git a/system/libraries/Output.php b/system/libraries/Output.php deleted file mode 100644 index 6a9a11677..000000000 --- a/system/libraries/Output.php +++ /dev/null @@ -1,409 +0,0 @@ -final_output; - } - - // -------------------------------------------------------------------- - - /** - * Set Output - * - * Sets the output string - * - * @access public - * @param string - * @return void - */ - function set_output($output) - { - $this->final_output = $output; - } - - // -------------------------------------------------------------------- - - /** - * 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; - } - } - - // -------------------------------------------------------------------- - - /** - * 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 - * @return void - */ - function set_header($header, $replace = TRUE) - { - $this->headers[] = array($header, $replace); - } - - // -------------------------------------------------------------------- - - /** - * 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); - } - - // -------------------------------------------------------------------- - - /** - * Enable/disable Profiler - * - * @access public - * @param bool - * @return void - */ - function enable_profiler($val = TRUE) - { - $this->enable_profiler = (is_bool($val)) ? $val : TRUE; - } - - // -------------------------------------------------------------------- - - /** - * Set Cache - * - * @access public - * @param integer - * @return void - */ - function cache($time) - { - $this->cache_expiration = ( ! is_numeric($time)) ? 0 : $time; - } - - // -------------------------------------------------------------------- - - /** - * 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 - * @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; - - // -------------------------------------------------------------------- - - // Set the output data - if ($output == '') - { - $output =& $this->final_output; - } - - // -------------------------------------------------------------------- - - // Do we need to write a cache file? - if ($this->cache_expiration > 0) - { - $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'); - $output = str_replace('{elapsed_time}', $elapsed, $output); - - $memory = ( ! function_exists('memory_get_usage')) ? '0' : round(memory_get_usage()/1024/1024, 2).'MB'; - $output = str_replace('{memory_usage}', $memory, $output); - - // -------------------------------------------------------------------- - - // Is compression requested? - if ($CFG->item('compress_output') === TRUE) - { - 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 get_instance() function exist? - // If not we know we are dealing with a cache file so we'll - // simply echo out the data and exit. - if ( ! function_exists('get_instance')) - { - echo $output; - log_message('debug', "Final output sent to browser"); - log_message('debug', "Total execution time: ".$elapsed); - return TRUE; - } - - // -------------------------------------------------------------------- - - // Grab the super object. We'll need it in a moment... - $CI =& get_instance(); - - // 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 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 - * @return void - */ - function _write_cache($output) - { - $CI =& get_instance(); - $path = $CI->config->item('cache_path'); - - $cache_path = ($path == '') ? BASEPATH.'cache/' : $path; - - if ( ! is_dir($cache_path) OR ! is_really_writable($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 - * @return void - */ - function _display_cache(&$CFG, &$URI) - { - $cache_path = ($CFG->item('cache_path') == '') ? BASEPATH.'cache/' : $CFG->item('cache_path'); - - if ( ! is_dir($cache_path) OR ! is_really_writable($cache_path)) - { - return FALSE; - } - - // 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']))) - { - @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; - } - - -} -// END Output Class - -/* End of file Output.php */ -/* Location: ./system/libraries/Output.php */ \ No newline at end of file diff --git a/system/libraries/Router.php b/system/libraries/Router.php deleted file mode 100644 index 20e69721d..000000000 --- a/system/libraries/Router.php +++ /dev/null @@ -1,389 +0,0 @@ -config =& load_class('Config'); - $this->uri =& load_class('URI'); - $this->_set_routing(); - 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? - // If so, we're done since segment based URIs are not used with query strings. - if ($this->config->item('enable_query_strings') === TRUE AND isset($_GET[$this->config->item('controller_trigger')])) - { - $this->set_class(trim($this->uri->_filter_uri($_GET[$this->config->item('controller_trigger')]))); - - if (isset($_GET[$this->config->item('function_trigger')])) - { - $this->set_method(trim($this->uri->_filter_uri($_GET[$this->config->item('function_trigger')]))); - } - - return; - } - - // Load the routes.php file. - @include(APPPATH.'config/routes'.EXT); - $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']); - - // 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 == '') - { - 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."); - } - - if (strpos($this->default_controller, '/') !== FALSE) - { - $x = explode('/', $this->default_controller); - - $this->set_class(end($x)); - $this->set_method('index'); - $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."); - return; - } - unset($this->routes['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 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_class($segments[0]); - - if (isset($segments[1])) - { - // A scaffolding request. No funny business with the URL - if ($this->routes['scaffolding_trigger'] == $segments[1] AND $segments[1] != '_ci_scaffolding') - { - $this->scaffolding_request = TRUE; - unset($this->routes['scaffolding_trigger']); - } - else - { - // 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) - { - // Does the requested controller exist in the root folder? - if (file_exists(APPPATH.'controllers/'.$segments[0].EXT)) - { - 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].EXT)) - { - show_404($this->fetch_directory().$segments[0]); - } - } - 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.EXT)) - { - $this->directory = ''; - return array(); - } - - } - - return $segments; - } - - // Can't find the requested controller... - 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() - { - // Do we even have any custom routing to deal with? - // There is a default scaffolding trigger, so we'll look just for 1 - if (count($this->routes) == 1) - { - $this->_set_request($this->uri->segments); - return; - } - - // 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])) - { - $this->_set_request(explode('/', $this->routes[$uri])); - return; - } - - // 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); - } - - $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($this->uri->segments); - } - - // -------------------------------------------------------------------- - - /** - * Set the class name - * - * @access public - * @param string - * @return void - */ - function set_class($class) - { - $this->class = $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 = $dir.'/'; - } - - // -------------------------------------------------------------------- - - /** - * Fetch the sub-directory (if any) that contains the requested controller class - * - * @access public - * @return string - */ - function fetch_directory() - { - return $this->directory; - } - -} -// END Router Class - -/* End of file Router.php */ -/* Location: ./system/libraries/Router.php */ \ No newline at end of file diff --git a/system/libraries/URI.php b/system/libraries/URI.php deleted file mode 100644 index 23efb38c1..000000000 --- a/system/libraries/URI.php +++ /dev/null @@ -1,586 +0,0 @@ -config =& load_class('Config'); - 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') - { - // If the URL has a question mark then it's simplest to just - // build the URI string from the zero index of the $_GET array. - // This avoids having to deal with $_SERVER variables, which - // can be unreliable in some environments - if (is_array($_GET) && count($_GET) == 1 && trim(key($_GET), '/') != '') - { - $this->uri_string = key($_GET); - 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->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->uri_string = $path; - return; - } - - // No QUERY_STRING?... Maybe the ORIG_PATH_INFO variable exists? - $path = str_replace($_SERVER['SCRIPT_NAME'], '', (isset($_SERVER['ORIG_PATH_INFO'])) ? $_SERVER['ORIG_PATH_INFO'] : @getenv('ORIG_PATH_INFO')); - if (trim($path, '/') != '' && $path != "/".SELF) - { - // remove path and script information so we have good URI data - $this->uri_string = $path; - return; - } - - // We've exhausted all our options... - $this->uri_string = ''; - } - else - { - $uri = strtoupper($this->config->item('uri_protocol')); - - if ($uri == 'REQUEST_URI') - { - $this->uri_string = $this->_parse_request_uri(); - return; - } - - $this->uri_string = (isset($_SERVER[$uri])) ? $_SERVER[$uri] : @getenv($uri); - } - - // If the URI contains only a slash we'll kill it - if ($this->uri_string == '/') - { - $this->uri_string = ''; - } - } - - // -------------------------------------------------------------------- - - /** - * Parse the REQUEST_URI - * - * Due to the way REQUEST_URI works it usually contains path info - * that makes it unusable as URI data. We'll trim off the unnecessary - * data, hopefully arriving at a valid URI that we can use. - * - * @access private - * @return string - */ - function _parse_request_uri() - { - if ( ! isset($_SERVER['REQUEST_URI']) OR $_SERVER['REQUEST_URI'] == '') - { - return ''; - } - - $request_uri = preg_replace("|/(.*)|", "\\1", str_replace("\\", "/", $_SERVER['REQUEST_URI'])); - - if ($request_uri == '' OR $request_uri == SELF) - { - return ''; - } - - $fc_path = FCPATH.SELF; - if (strpos($request_uri, '?') !== FALSE) - { - $fc_path .= '?'; - } - - $parsed_uri = explode("/", $request_uri); - - $i = 0; - foreach(explode("/", $fc_path) as $segment) - { - if (isset($parsed_uri[$i]) && $segment == $parsed_uri[$i]) - { - $i++; - } - } - - $parsed_uri = implode("/", array_slice($parsed_uri, $i)); - - if ($parsed_uri != '') - { - $parsed_uri = '/'.$parsed_uri; - } - - return $parsed_uri; - } - - // -------------------------------------------------------------------- - - /** - * 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 - * - */ - 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') - { - if ($where == 'trailing') - { - $trailing = '/'; - $leading = ''; - } - elseif ($where == 'leading') - { - $leading = '/'; - $trailing = ''; - } - else - { - $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()).'/'; - } - -} -// END URI Class - -/* End of file URI.php */ -/* Location: ./system/libraries/URI.php */ \ No newline at end of file -- cgit v1.2.3-24-g4f1b From c68dfbf9df1bd76f608307185ec16f5be4b550f1 Mon Sep 17 00:00:00 2001 From: Derek Jones Date: Tue, 2 Mar 2010 12:59:23 -0600 Subject: fixed EOF code comment file locations --- system/core/Base4.php | 2 +- system/core/Base5.php | 2 +- system/core/Benchmark.php | 2 +- system/core/CodeIgniter.php | 2 +- system/core/Common.php | 2 +- system/core/Compat.php | 2 +- system/core/Config.php | 2 +- system/core/Controller.php | 2 +- system/core/Exceptions.php | 2 +- system/core/Hooks.php | 2 +- system/core/Input.php | 2 +- system/core/Lang.php | 2 +- system/core/Loader.php | 2 +- system/core/Model.php | 2 +- system/core/Output.php | 2 +- system/core/Router.php | 2 +- system/core/URI.php | 2 +- 17 files changed, 17 insertions(+), 17 deletions(-) (limited to 'system') diff --git a/system/core/Base4.php b/system/core/Base4.php index 3561c2564..24474830c 100644 --- a/system/core/Base4.php +++ b/system/core/Base4.php @@ -66,4 +66,4 @@ function &get_instance() /* End of file Base4.php */ -/* Location: ./system/codeigniter/Base4.php */ \ No newline at end of file +/* Location: ./system/core/Base4.php */ \ No newline at end of file diff --git a/system/core/Base5.php b/system/core/Base5.php index 5d944ae5a..86e3513c7 100644 --- a/system/core/Base5.php +++ b/system/core/Base5.php @@ -53,4 +53,4 @@ function &get_instance() /* End of file Base5.php */ -/* Location: ./system/codeigniter/Base5.php */ \ No newline at end of file +/* Location: ./system/core/Base5.php */ \ No newline at end of file diff --git a/system/core/Benchmark.php b/system/core/Benchmark.php index d485ee21d..1149b7a76 100644 --- a/system/core/Benchmark.php +++ b/system/core/Benchmark.php @@ -110,4 +110,4 @@ class CI_Benchmark { // END CI_Benchmark class /* End of file Benchmark.php */ -/* Location: ./system/libraries/Benchmark.php */ \ No newline at end of file +/* Location: ./system/core/Benchmark.php */ \ No newline at end of file diff --git a/system/core/CodeIgniter.php b/system/core/CodeIgniter.php index 5d5bb144b..65c75a6c4 100644 --- a/system/core/CodeIgniter.php +++ b/system/core/CodeIgniter.php @@ -277,4 +277,4 @@ if (class_exists('CI_DB') AND isset($CI->db)) /* End of file CodeIgniter.php */ -/* Location: ./system/codeigniter/CodeIgniter.php */ \ No newline at end of file +/* Location: ./system/core/CodeIgniter.php */ \ No newline at end of file diff --git a/system/core/Common.php b/system/core/Common.php index 9a35062a4..ae147461e 100644 --- a/system/core/Common.php +++ b/system/core/Common.php @@ -418,4 +418,4 @@ function _exception_handler($severity, $message, $filepath, $line) /* End of file Common.php */ -/* Location: ./system/codeigniter/Common.php */ \ No newline at end of file +/* Location: ./system/core/Common.php */ \ No newline at end of file diff --git a/system/core/Compat.php b/system/core/Compat.php index 40017a93b..1ccc811db 100644 --- a/system/core/Compat.php +++ b/system/core/Compat.php @@ -90,4 +90,4 @@ if ( ! function_exists('ctype_alnum')) } /* End of file Compat.php */ -/* Location: ./system/codeigniter/Compat.php */ \ No newline at end of file +/* Location: ./system/core/Compat.php */ \ No newline at end of file diff --git a/system/core/Config.php b/system/core/Config.php index 760120779..ab69c0720 100644 --- a/system/core/Config.php +++ b/system/core/Config.php @@ -241,4 +241,4 @@ class CI_Config { // END CI_Config class /* End of file Config.php */ -/* Location: ./system/libraries/Config.php */ \ No newline at end of file +/* Location: ./system/core/Config.php */ \ No newline at end of file diff --git a/system/core/Controller.php b/system/core/Controller.php index c5637c951..1b76d0daa 100644 --- a/system/core/Controller.php +++ b/system/core/Controller.php @@ -124,4 +124,4 @@ class Controller extends CI_Base { // END _Controller class /* End of file Controller.php */ -/* Location: ./system/libraries/Controller.php */ \ No newline at end of file +/* Location: ./system/core/Controller.php */ \ No newline at end of file diff --git a/system/core/Exceptions.php b/system/core/Exceptions.php index bd567ccdc..503015dfd 100644 --- a/system/core/Exceptions.php +++ b/system/core/Exceptions.php @@ -171,4 +171,4 @@ class CI_Exceptions { // END Exceptions Class /* End of file Exceptions.php */ -/* Location: ./system/libraries/Exceptions.php */ \ No newline at end of file +/* Location: ./system/core/Exceptions.php */ \ No newline at end of file diff --git a/system/core/Hooks.php b/system/core/Hooks.php index 6d736c3f6..2c12ffafd 100644 --- a/system/core/Hooks.php +++ b/system/core/Hooks.php @@ -223,4 +223,4 @@ class CI_Hooks { // END CI_Hooks class /* End of file Hooks.php */ -/* Location: ./system/libraries/Hooks.php */ \ No newline at end of file +/* Location: ./system/core/Hooks.php */ \ No newline at end of file diff --git a/system/core/Input.php b/system/core/Input.php index e736d2b8b..51c12a8a0 100644 --- a/system/core/Input.php +++ b/system/core/Input.php @@ -1064,4 +1064,4 @@ class CI_Input { // END Input class /* End of file Input.php */ -/* Location: ./system/libraries/Input.php */ \ No newline at end of file +/* Location: ./system/core/Input.php */ \ No newline at end of file diff --git a/system/core/Lang.php b/system/core/Lang.php index 515d04a40..bbecab645 100644 --- a/system/core/Lang.php +++ b/system/core/Lang.php @@ -120,4 +120,4 @@ class CI_Language { // END Language Class /* End of file Language.php */ -/* Location: ./system/libraries/Language.php */ \ No newline at end of file +/* Location: ./system/core/Language.php */ \ No newline at end of file diff --git a/system/core/Loader.php b/system/core/Loader.php index 2cd2e93b9..a30238c3e 100644 --- a/system/core/Loader.php +++ b/system/core/Loader.php @@ -1082,4 +1082,4 @@ class CI_Loader { } /* End of file Loader.php */ -/* Location: ./system/libraries/Loader.php */ \ No newline at end of file +/* Location: ./system/core/Loader.php */ \ No newline at end of file diff --git a/system/core/Model.php b/system/core/Model.php index e9c2d24d1..541f966b6 100644 --- a/system/core/Model.php +++ b/system/core/Model.php @@ -80,4 +80,4 @@ class Model { // END Model Class /* End of file Model.php */ -/* Location: ./system/libraries/Model.php */ \ No newline at end of file +/* Location: ./system/core/Model.php */ \ No newline at end of file diff --git a/system/core/Output.php b/system/core/Output.php index 6a9a11677..ea4b0e314 100644 --- a/system/core/Output.php +++ b/system/core/Output.php @@ -406,4 +406,4 @@ class CI_Output { // END Output Class /* End of file Output.php */ -/* Location: ./system/libraries/Output.php */ \ No newline at end of file +/* Location: ./system/core/Output.php */ \ No newline at end of file diff --git a/system/core/Router.php b/system/core/Router.php index 20e69721d..32c1c3820 100644 --- a/system/core/Router.php +++ b/system/core/Router.php @@ -386,4 +386,4 @@ class CI_Router { // END Router Class /* End of file Router.php */ -/* Location: ./system/libraries/Router.php */ \ No newline at end of file +/* Location: ./system/core/Router.php */ \ No newline at end of file diff --git a/system/core/URI.php b/system/core/URI.php index 23efb38c1..77b814925 100644 --- a/system/core/URI.php +++ b/system/core/URI.php @@ -583,4 +583,4 @@ class CI_URI { // END URI Class /* End of file URI.php */ -/* Location: ./system/libraries/URI.php */ \ No newline at end of file +/* Location: ./system/core/URI.php */ \ No newline at end of file -- cgit v1.2.3-24-g4f1b From 98badc154c59a1018ada449ad7100bc97c4fbd52 Mon Sep 17 00:00:00 2001 From: Derek Jones Date: Tue, 2 Mar 2010 13:08:02 -0600 Subject: adding Unicode class to core --- system/core/Unicode.php | 165 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 165 insertions(+) create mode 100644 system/core/Unicode.php (limited to 'system') diff --git a/system/core/Unicode.php b/system/core/Unicode.php new file mode 100644 index 000000000..c8f1203f7 --- /dev/null +++ b/system/core/Unicode.php @@ -0,0 +1,165 @@ +item('charset') == 'UTF-8' // Application charset must be UTF-8 + ) + { + log_message('debug', "Unicode Class - 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', "Unicode Class - 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 preg_replace('/[\x00-\x08\x0B\x0C\x0E-\x1F\x7F]+/S', '', $str); + } + + // -------------------------------------------------------------------- + + /** + * 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); + } + + // -------------------------------------------------------------------- + +} +// End Unicode Class + +/* End of file Unicode.php */ +/* Location: ./system/core/Unicode.php */ \ No newline at end of file -- cgit v1.2.3-24-g4f1b From 218876c55d9d3f56c20675c4444f19433880878f Mon Sep 17 00:00:00 2001 From: Derek Jones Date: Tue, 2 Mar 2010 13:11:00 -0600 Subject: updating CodeIgniter.php init file --- system/core/CodeIgniter.php | 292 +++++++++++++++++++++++++++----------------- 1 file changed, 180 insertions(+), 112 deletions(-) (limited to 'system') diff --git a/system/core/CodeIgniter.php b/system/core/CodeIgniter.php index 65c75a6c4..90cce1c6e 100644 --- a/system/core/CodeIgniter.php +++ b/system/core/CodeIgniter.php @@ -16,7 +16,7 @@ // ------------------------------------------------------------------------ /** - * System Front Controller + * System Initialization File * * Loads the base classes and executes the request. * @@ -27,100 +27,177 @@ * @link http://codeigniter.com/user_guide/ */ -// CI Version -define('CI_VERSION', '1.7.2'); +/* + * ------------------------------------------------------ + * Define the CodeIgniter Version + * ------------------------------------------------------ + */ + define('CI_VERSION', '2.0'); /* * ------------------------------------------------------ * Load the global functions * ------------------------------------------------------ */ -require(BASEPATH.'codeigniter/Common'.EXT); + require(BASEPATH.'core/Common'.EXT); /* * ------------------------------------------------------ * Load the compatibility override functions * ------------------------------------------------------ */ -require(BASEPATH.'codeigniter/Compat'.EXT); + require(BASEPATH.'core/Compat'.EXT); /* * ------------------------------------------------------ * Load the framework constants * ------------------------------------------------------ */ -require(APPPATH.'config/constants'.EXT); + require(APPPATH.'config/constants'.EXT); /* * ------------------------------------------------------ * Define a custom error handler so we can log PHP errors * ------------------------------------------------------ */ -set_error_handler('_exception_handler'); + set_error_handler('_exception_handler'); + + if ( ! is_php('5.3')) + { + @set_magic_quotes_runtime(0); // Kill magic quotes + } -if ( ! is_php('5.3')) -{ - @set_magic_quotes_runtime(0); // Kill magic quotes -} + // Set a liberal script execution time limit + if (function_exists("set_time_limit") == TRUE AND @ini_get("safe_mode") == 0) + { + @set_time_limit(300); + } /* * ------------------------------------------------------ - * Start the timer... tick tock tick tock... + * Set the subclass_prefix * ------------------------------------------------------ + * + * Normally the "subclass_prefix" is set in the config file. + * 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, + * before proceeding we need to know if a subclass_prefix + * 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'])); + } -$BM =& load_class('Benchmark'); -$BM->mark('total_execution_time_start'); -$BM->mark('loading_time_base_classes_start'); +/* + * ------------------------------------------------------ + * 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'); /* * ------------------------------------------------------ * Instantiate the hooks class * ------------------------------------------------------ */ - -$EXT =& load_class('Hooks'); + $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 + * ------------------------------------------------------ + */ + $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); + } + +/* + * ------------------------------------------------------ + * Instantiate the Unicode class + * ------------------------------------------------------ + * + * Note: Order here is rather important as the Unicode + * 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. + * + */ + $UNI =& load_class('Unicode', 'core'); + /* * ------------------------------------------------------ - * Instantiate the base classes + * Instantiate the URI class * ------------------------------------------------------ */ + $URI =& load_class('URI', 'core'); -$CFG =& load_class('Config'); -$URI =& load_class('URI'); -$RTR =& load_class('Router'); -$OUT =& load_class('Output'); +/* + * ------------------------------------------------------ + * 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); + } /* * ------------------------------------------------------ - * Is there a valid cache file? If so, we're done... + * Instantiate the output class * ------------------------------------------------------ */ + $OUT =& load_class('Output', 'core'); -if ($EXT->_call_hook('cache_override') === FALSE) -{ - if ($OUT->_display_cache($CFG, $URI) == TRUE) +/* + * ------------------------------------------------------ + * Is there a valid cache file? If so, we're done... + * ------------------------------------------------------ + */ + if ($EXT->_call_hook('cache_override') === FALSE) { - exit; + if ($OUT->_display_cache($CFG, $URI) == TRUE) + { + exit; + } } -} /* * ------------------------------------------------------ - * Load the remaining base classes + * Load the Input class and sanitize globals * ------------------------------------------------------ */ + $IN =& load_class('Input', 'core'); -$IN =& load_class('Input'); -$LANG =& load_class('Language'); +/* + * ------------------------------------------------------ + * Load the Language class + * ------------------------------------------------------ + */ + $LANG =& load_class('Lang', 'core'); /* * ------------------------------------------------------ @@ -131,35 +208,33 @@ $LANG =& load_class('Language'); * conditionally load different versions of the base * class. Retaining PHP 4 compatibility requires a bit of a hack. * - * Note: The Loader class needs to be included first - * */ -if ( ! is_php('5.0.0')) -{ - load_class('Loader', FALSE); - require(BASEPATH.'codeigniter/Base4'.EXT); -} -else -{ - require(BASEPATH.'codeigniter/Base5'.EXT); -} - -// Load the base controller class -load_class('Controller', FALSE); - -// Load the local application controller -// Note: The Router class automatically validates the controller path. 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().EXT)) -{ - 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().EXT); - -// Set a mark point for benchmarking -$BM->mark('loading_time_base_classes_end'); - + if (is_php('5.0.0') == TRUE) + { + require(BASEPATH.'core/Base5'.EXT); + } + else + { + // The Loader class needs to be included first when running PHP 4.x + load_class('Loader', 'core'); + require(BASEPATH.'core/Base4'.EXT); + } + + // Load the base controller class + require BASEPATH.'core/Controller'.EXT; + + // 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().EXT)) + { + 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().EXT); + + // Set a mark point for benchmarking + $BM->mark('loading_time:_base_classes_end'); /* * ------------------------------------------------------ @@ -170,54 +245,48 @@ $BM->mark('loading_time_base_classes_end'); * 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 $method == 'controller' - OR strncmp($method, '_', 1) == 0 - OR in_array(strtolower($method), array_map('strtolower', get_class_methods('Controller'))) - ) -{ - show_404("{$class}/{$method}"); -} + $class = $RTR->fetch_class(); + $method = $RTR->fetch_method(); + + if ( ! class_exists($class) + OR $method == 'controller' + OR strncmp($method, '_', 1) == 0 + OR in_array(strtolower($method), array_map('strtolower', get_class_methods('Controller'))) + ) + { + show_404("{$class}/{$method}"); + } /* * ------------------------------------------------------ * Is there a "pre_controller" hook? * ------------------------------------------------------ */ -$EXT->_call_hook('pre_controller'); + $EXT->_call_hook('pre_controller'); /* * ------------------------------------------------------ - * Instantiate the controller and call requested method + * Instantiate the requested controller * ------------------------------------------------------ */ + // Mark a start point so we can benchmark the controller + $BM->mark('controller_execution_time_( '.$class.' / '.$method.' )_start'); + + $CI = new $class(); -// Mark a start point so we can benchmark the controller -$BM->mark('controller_execution_time_( '.$class.' / '.$method.' )_start'); - -$CI = new $class(); - -// Is this a scaffolding request? -if ($RTR->scaffolding_request === TRUE) -{ - if ($EXT->_call_hook('scaffolding_override') === FALSE) - { - $CI->_ci_scaffolding(); - } -} -else -{ - /* - * ------------------------------------------------------ - * Is there a "post_controller_constructor" hook? - * ------------------------------------------------------ - */ +/* + * ------------------------------------------------------ + * Is there a "post_controller_constructor" hook? + * ------------------------------------------------------ + */ $EXT->_call_hook('post_controller_constructor'); - - // Is there a "remap" function? + +/* + * ------------------------------------------------------ + * Call the requested method + * ------------------------------------------------------ + */ + // Is there a "remap" function? If so, we call it instead if (method_exists($CI, '_remap')) { $CI->_remap($method); @@ -232,48 +301,47 @@ else } // 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)); + // 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'); + + // 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'); + $EXT->_call_hook('post_system'); /* * ------------------------------------------------------ * Close the DB connection if one exists * ------------------------------------------------------ */ -if (class_exists('CI_DB') AND isset($CI->db)) -{ - $CI->db->close(); -} + if (class_exists('CI_DB') AND isset($CI->db)) + { + $CI->db->close(); + } /* End of file CodeIgniter.php */ -- cgit v1.2.3-24-g4f1b From dc8e9ea8e559d7193492e94ccdcbe18bdd8173e4 Mon Sep 17 00:00:00 2001 From: Derek Jones Date: Tue, 2 Mar 2010 13:17:19 -0600 Subject: updated Common functions - whitespace formatting - load_class() changes for new structure --- system/core/Common.php | 528 +++++++++++++++++++++++++++---------------------- 1 file changed, 296 insertions(+), 232 deletions(-) (limited to 'system') diff --git a/system/core/Common.php b/system/core/Common.php index ae147461e..47293a11b 100644 --- a/system/core/Common.php +++ b/system/core/Common.php @@ -15,6 +15,20 @@ // ------------------------------------------------------------------------ +/** + * Common Functions + * + * Loads the base classes and executes the request. + * + * @package CodeIgniter + * @subpackage codeigniter + * @category Common Functions + * @author ExpressionEngine Dev Team + * @link http://codeigniter.com/user_guide/ + */ + +// ------------------------------------------------------------------------ + /** * Determines if the current version of PHP is greater then the supplied value * @@ -23,20 +37,20 @@ * * @access public * @param string -* @return bool +* @return bool TRUE if the current version is $version or higher */ -function is_php($version = '5.0.0') -{ - static $_is_php; - $version = (string)$version; - - if ( ! isset($_is_php[$version])) + function is_php($version = '5.0.0') { - $_is_php[$version] = (version_compare(PHP_VERSION, $version) < 0) ? FALSE : TRUE; - } + static $_is_php; + $version = (string)$version; + + if ( ! isset($_is_php[$version])) + { + $_is_php[$version] = (version_compare(PHP_VERSION, $version) < 0) ? FALSE : TRUE; + } - return $_is_php[$version]; -} + return $_is_php[$version]; + } // ------------------------------------------------------------------------ @@ -45,43 +59,43 @@ function is_php($version = '5.0.0') * * 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. + * on Unix servers if safe_mode is on. * * @access private * @return void - */ -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) + */ + function is_really_writable($file) { - return is_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)); + // 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) + if (($fp = @fopen($file, FOPEN_WRITE_CREATE)) === FALSE) + { + return FALSE; + } + + fclose($fp); + @chmod($file, DIR_WRITE_MODE); + @unlink($file); + return TRUE; + } + elseif (($fp = @fopen($file, FOPEN_WRITE_CREATE)) === FALSE) { return FALSE; } fclose($fp); - @chmod($file, DIR_WRITE_MODE); - @unlink($file); return TRUE; } - elseif (($fp = @fopen($file, FOPEN_WRITE_CREATE)) === FALSE) - { - return FALSE; - } - - fclose($fp); - return TRUE; -} // ------------------------------------------------------------------------ @@ -94,60 +108,66 @@ function is_really_writable($file) * * @access public * @param string the class name being requested -* @param bool optional flag that lets classes get loaded but not instantiated +* @param string the directory where the class should be found +* @param string the class name prefix * @return object */ -function &load_class($class, $instantiate = TRUE) -{ - static $objects = array(); - - // Does the class exist? If so, we're done... - if (isset($objects[$class])) + function &load_class($class, $directory = 'libraries', $prefix = 'CI_') { - return $objects[$class]; - } - - // If the requested class does not exist in the application/libraries - // folder we'll load the native class from the system/libraries folder. - if (file_exists(APPPATH.'libraries/'.config_item('subclass_prefix').$class.EXT)) - { - require(BASEPATH.'libraries/'.$class.EXT); - require(APPPATH.'libraries/'.config_item('subclass_prefix').$class.EXT); - $is_subclass = TRUE; - } - else - { - if (file_exists(APPPATH.'libraries/'.$class.EXT)) + static $_classes = array(); + + // Does the class exist? If so, we're done... + if (isset($_classes[$class])) { - require(APPPATH.'libraries/'.$class.EXT); - $is_subclass = FALSE; + return $_classes[$class]; } - else - { - require(BASEPATH.'libraries/'.$class.EXT); - $is_subclass = FALSE; + + $name = FALSE; + + // Look for the class first in the native system/libraries folder + // thenin the local application/libraries folder + foreach (array(BASEPATH, APPPATH) as $path) + { + if (file_exists($path.$directory.'/'.$class.EXT)) + { + $name = $prefix.$class; + + if (class_exists($name) === FALSE) + { + require($path.$directory.'/'.$class.EXT); + } + + break; + } } - } - if ($instantiate == FALSE) - { - $objects[$class] = TRUE; - return $objects[$class]; - } + // Is the request a class extension? If so we load it too + if (file_exists(APPPATH.'libraries/'.config_item('subclass_prefix').$class.EXT)) + { + $name = config_item('subclass_prefix').$class; + + if (class_exists($name) === FALSE) + { + require(APPPATH.'libraries/'.config_item('subclass_prefix').$class.EXT); + } + } - if ($is_subclass == TRUE) - { - $name = config_item('subclass_prefix').$class; + // 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.EXT); + } - $objects[$class] =& instantiate_class(new $name()); - return $objects[$class]; - } + // Keep track of what we just loaded + is_loaded($class); - $name = ($class != 'Controller') ? 'CI_'.$class : $class; + $_classes[$class] =& instantiate_class(new $name()); + return $_classes[$class]; + } - $objects[$class] =& instantiate_class(new $name()); - return $objects[$class]; -} +// ------------------------------------------------------------------------ /** * Instantiate Class @@ -161,64 +181,110 @@ function &load_class($class, $instantiate = TRUE) * @param object * @return object */ -function &instantiate_class(&$class_object) -{ - return $class_object; -} + function &instantiate_class(&$class_object) + { + return $class_object; + } + +// -------------------------------------------------------------------- + +/** +* Keeps track of which libraries have been loaded. This function is +* called by the load_class() function above +* +* @access public +* @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 */ -function &get_config() -{ - static $main_conf; - - if ( ! isset($main_conf)) + function &get_config($replace = array()) { + static $_config; + + if (isset($_config)) + { + return $_config[0]; + } + + // Fetch the config file if ( ! file_exists(APPPATH.'config/config'.EXT)) { - exit('The configuration file config'.EXT.' does not exist.'); + exit('The configuration file does not exist.'); + } + else + { + require(APPPATH.'config/config'.EXT); } - require(APPPATH.'config/config'.EXT); - + // 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.'); } - $main_conf[0] =& $config; + // Are any values being dynamically replaced? + if (count($replace) > 0) + { + foreach ($replace as $key => $val) + { + if (isset($config[$key])) + { + $config[$key] = $val; + } + } + } + + return $_config[0] =& $config; } - return $main_conf[0]; -} + +// ------------------------------------------------------------------------ /** -* Gets a config item +* Returns the specified config item * * @access public * @return mixed */ -function config_item($item) -{ - static $config_item = array(); - - if ( ! isset($config_item[$item])) + function config_item($item) { - $config =& get_config(); - - if ( ! isset($config[$item])) + static $_config_item = array(); + + if ( ! isset($_config_item[$item])) { - return FALSE; + $config =& get_config(); + + if ( ! isset($config[$item])) + { + return FALSE; + } + $_config_item[$item] = $config[$item]; } - $config_item[$item] = $config[$item]; + + return $_config_item[$item]; } - return $config_item[$item]; -} - +// ------------------------------------------------------------------------ /** * Error Handler @@ -232,13 +298,14 @@ function config_item($item) * @access public * @return void */ -function show_error($message, $status_code = 500) -{ - $error =& load_class('Exceptions'); - echo $error->show_error('An Error Was Encountered', $message, 'error_general', $status_code); - exit; -} + 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; + } +// ------------------------------------------------------------------------ /** * 404 Page Handler @@ -250,13 +317,14 @@ function show_error($message, $status_code = 500) * @access public * @return void */ -function show_404($page = '') -{ - $error =& load_class('Exceptions'); - $error->show_404($page); - exit; -} + function show_404($page = '') + { + $_error =& load_class('Exceptions', 'core'); + $_error->show_404($page); + exit; + } +// ------------------------------------------------------------------------ /** * Error Logging Interface @@ -267,20 +335,20 @@ function show_404($page = '') * @access public * @return void */ -function log_message($level = 'error', $message, $php_error = FALSE) -{ - static $LOG; - - $config =& get_config(); - if ($config['log_threshold'] == 0) + function log_message($level = 'error', $message, $php_error = FALSE) { - return; - } + static $_log; - $LOG =& load_class('Log'); - $LOG->write_log($level, $message, $php_error); -} + if (config_item('log_threshold') == 0) + { + return; + } + + $_log =& load_class('Log'); + $_log->write_log($level, $message, $php_error); + } +// ------------------------------------------------------------------------ /** * Set HTTP Status Header @@ -289,89 +357,90 @@ function log_message($level = 'error', $message, $php_error = FALSE) * @param int the status code * @param string * @return void - */ -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)) + */ + function set_status_header($code = 200, $text = '') { - show_error('Status codes must be numeric', 500); - } + $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 (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); - } + 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; + $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); + 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); + } } -} - + +// -------------------------------------------------------------------- /** * Exception Handler * * This is the custom exception handler that is declaired at the top -* of Codeigniter.php. The main reason we use this is permit -* PHP errors to be logged in our own log files since we may +* 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. @@ -380,41 +449,36 @@ function set_status_header($code = 200, $text = '') * @access private * @return void */ -function _exception_handler($severity, $message, $filepath, $line) -{ - // We don't bother with "strict" notices since they will fill up - // the log file with information that isn't normally very - // helpful. For example, if you are running PHP 5 and you - // use version 4 style class functions (without prefixes - // like "public", "private", etc.) you'll get notices telling - // you that these have been deprecated. + function _exception_handler($severity, $message, $filepath, $line) + { + // We don't bother with "strict" notices since they tend to fill up + // the log file with excess information that isn't normally very helpful. + // For example, if you are running PHP 5 and you use version 4 style + // class functions (without prefixes like "public", "private", etc.) + // you'll get notices telling you that these have been deprecated. + if ($severity == E_STRICT) + { + return; + } - if ($severity == E_STRICT) - { - return; - } - - $error =& load_class('Exceptions'); - - // Should we display the error? - // We'll get the current error_reporting level and add its bits - // with the severity bits to find out. + $_error =& load_class('Exceptions', 'core'); - if (($severity & error_reporting()) == $severity) - { - $error->show_php_error($severity, $message, $filepath, $line); - } + // 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; + } - // Should we log the error? No? We're done... - $config =& get_config(); - if ($config['log_threshold'] == 0) - { - return; + $_error->log_exception($severity, $message, $filepath, $line); } - $error->log_exception($severity, $message, $filepath, $line); -} - /* End of file Common.php */ -- cgit v1.2.3-24-g4f1b From 7ec1310547af2a624b53f51a07231fe022b0664b Mon Sep 17 00:00:00 2001 From: Derek Jones Date: Tue, 2 Mar 2010 13:18:39 -0600 Subject: whitespace and doc block update to Compat functions --- system/core/Compat.php | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'system') diff --git a/system/core/Compat.php b/system/core/Compat.php index 1ccc811db..06e5e78de 100644 --- a/system/core/Compat.php +++ b/system/core/Compat.php @@ -24,7 +24,7 @@ * @package CodeIgniter * @subpackage codeigniter * @category Compatibility Functions - * @author ExpressionEngine Development Team + * @author ExpressionEngine Dev Team * @link http://codeigniter.com/user_guide/ */ @@ -89,5 +89,8 @@ if ( ! function_exists('ctype_alnum')) } } +// -------------------------------------------------------------------- + + /* End of file Compat.php */ /* Location: ./system/core/Compat.php */ \ No newline at end of file -- cgit v1.2.3-24-g4f1b From 6d743e2be06efe133a3372389ac4d35d2a94e2a6 Mon Sep 17 00:00:00 2001 From: Derek Jones Date: Tue, 2 Mar 2010 13:22:03 -0600 Subject: added config paths class property added assign_to_config() method to override config items via index.php files --- system/core/Config.php | 143 ++++++++++++++++++++++++++++++++++++------------- 1 file changed, 107 insertions(+), 36 deletions(-) (limited to 'system') diff --git a/system/core/Config.php b/system/core/Config.php index ab69c0720..7e0443c1f 100644 --- a/system/core/Config.php +++ b/system/core/Config.php @@ -30,6 +30,7 @@ class CI_Config { var $config = array(); var $is_loaded = array(); + var $_config_paths = array(APPPATH); /** * Constructor @@ -44,7 +45,7 @@ class CI_Config { */ function CI_Config() { - $this->config =& get_config(); + $this->config =& get_config(); log_message('debug', "Config Class Initialized"); } @@ -60,52 +61,66 @@ class CI_Config { function load($file = '', $use_sections = FALSE, $fail_gracefully = FALSE) { $file = ($file == '') ? 'config' : str_replace(EXT, '', $file); + $loaded = FALSE; - if (in_array($file, $this->is_loaded, TRUE)) + foreach($this->_config_paths as $path) { - return TRUE; - } - - if ( ! file_exists(APPPATH.'config/'.$file.EXT)) - { - if ($fail_gracefully === TRUE) + $file_path = $path.'config/'.$file.EXT; + + if (in_array($file_path, $this->is_loaded, TRUE)) { - return FALSE; + $loaded = TRUE; + continue; } - show_error('The configuration file '.$file.EXT.' does not exist.'); - } - - include(APPPATH.'config/'.$file.EXT); - if ( ! isset($config) OR ! is_array($config)) - { - if ($fail_gracefully === TRUE) + if ( ! file_exists($path.'config/'.$file.EXT)) { - return FALSE; + continue; } - show_error('Your '.$file.EXT.' file does not appear to contain a valid configuration array.'); - } + + include($file_path); - if ($use_sections === TRUE) - { - if (isset($this->config[$file])) + 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] = array_merge($this->config[$file], $config); + if (isset($this->config[$file])) + { + $this->config[$file] = array_merge($this->config[$file], $config); + } + else + { + $this->config[$file] = $config; + } } else { - $this->config[$file] = $config; + $this->config = array_merge($this->config, $config); } + + $this->is_loaded[] = $file_path; + unset($config); + + $loaded = TRUE; + log_message('debug', 'Config file loaded: '.$file_path); } - else + + if ($loaded === FALSE) { - $this->config = array_merge($this->config, $config); + if ($fail_gracefully === TRUE) + { + return FALSE; + } + show_error('The configuration file '.$file.EXT.' does not exist.'); } - $this->is_loaded[] = $file; - unset($config); - - log_message('debug', 'Config file loaded: config/'.$file.EXT); return TRUE; } @@ -191,19 +206,52 @@ class CI_Config { */ function site_url($uri = '') { - if (is_array($uri)) + if ($uri == '') { - $uri = implode('/', $uri); + if ($this->item('base_url') == '') + { + return $this->item('index_page'); + } + else + { + return $this->slash_item('base_url').$this->item('index_page'); + } } - if ($uri == '') + if ($this->item('enable_query_strings') == FALSE) { - return $this->slash_item('base_url').$this->item('index_page'); + if (is_array($uri)) + { + $uri = implode('/', $uri); + } + + $suffix = ($this->item('url_suffix') == FALSE) ? '' : $this->item('url_suffix'); + return $this->slash_item('base_url').$this->slash_item('index_page').trim($uri, '/').$suffix; } else { - $suffix = ($this->item('url_suffix') == FALSE) ? '' : $this->item('url_suffix'); - return $this->slash_item('base_url').$this->slash_item('index_page').trim($uri, '/').$suffix; + if (is_array($uri)) + { + $i = 0; + $str = ''; + foreach ($uri as $key => $val) + { + $prefix = ($i == 0) ? '' : '&'; + $str .= $prefix.$key.'='.$val; + $i++; + } + + $uri = $str; + } + + if ($this->item('base_url') == '') + { + return $this->item('index_page').'?'.$uri; + } + else + { + return $this->slash_item('base_url').$this->item('index_page').'?'.$uri; + } } } @@ -235,7 +283,30 @@ class CI_Config { { $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 -- cgit v1.2.3-24-g4f1b From 8f9f977c407bfcfc893f418d4c62d91d33d83fe8 Mon Sep 17 00:00:00 2001 From: Derek Jones Date: Tue, 2 Mar 2010 13:28:24 -0600 Subject: killed scaffolding from Controller class reworked to use is_loaded() and is_php() from Common added PHP4 tag --- system/core/Controller.php | 70 ++++++++-------------------------------------- 1 file changed, 12 insertions(+), 58 deletions(-) (limited to 'system') diff --git a/system/core/Controller.php b/system/core/Controller.php index 1b76d0daa..2e44500a6 100644 --- a/system/core/Controller.php +++ b/system/core/Controller.php @@ -18,7 +18,7 @@ /** * CodeIgniter Application Controller Class * - * This class object is the super class that every library in + * This class object is the super class the every library in * CodeIgniter will be assigned to. * * @package CodeIgniter @@ -28,9 +28,6 @@ * @link http://codeigniter.com/user_guide/general/controllers.html */ class Controller extends CI_Base { - - var $_ci_scaffolding = FALSE; - var $_ci_scaff_table = FALSE; /** * Constructor @@ -40,46 +37,23 @@ class Controller extends CI_Base { function Controller() { parent::CI_Base(); - $this->_ci_initialize(); - log_message('debug', "Controller Class Initialized"); - } - // -------------------------------------------------------------------- - - /** - * Initialize - * - * Assigns all the bases classes loaded by the front controller to - * variables in this class. Also calls the autoload routine. - * - * @access private - * @return void - */ - function _ci_initialize() - { // Assign all the class objects that were instantiated by the - // front controller to local class variables so that CI can be - // run as one big super object. - $classes = array( - 'config' => 'Config', - 'input' => 'Input', - 'benchmark' => 'Benchmark', - 'uri' => 'URI', - 'output' => 'Output', - 'lang' => 'Language', - 'router' => 'Router' - ); - - foreach ($classes as $var => $class) + // 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); } // In PHP 5 the Loader class is run as a discreet - // class. In PHP 4 it extends the Controller - if (floor(phpversion()) >= 5) + // class. In PHP 4 it extends the Controller @PHP4 + if (is_php('5.0.0') == TRUE) { - $this->load =& load_class('Loader'); + $this->load =& load_class('Loader', 'core'); + + $this->load->_base_classes =& is_loaded(); + $this->load->_ci_autoloader(); } else @@ -95,31 +69,11 @@ class Controller extends CI_Base { } } } - } - - // -------------------------------------------------------------------- - - /** - * Run Scaffolding - * - * @access private - * @return void - */ - function _ci_scaffolding() - { - if ($this->_ci_scaffolding === FALSE OR $this->_ci_scaff_table === FALSE) - { - show_404('Scaffolding unavailable'); - } - - $method = ( ! in_array($this->uri->segment(3), array('add', 'insert', 'edit', 'update', 'view', 'delete', 'do_delete'), TRUE)) ? 'view' : $this->uri->segment(3); + + log_message('debug', "Controller Class Initialized"); - require_once(BASEPATH.'scaffolding/Scaffolding'.EXT); - $scaff = new Scaffolding($this->_ci_scaff_table); - $scaff->$method(); } - } // END _Controller class -- cgit v1.2.3-24-g4f1b From ac2b24776fc92800585005f0db2ef82463847c81 Mon Sep 17 00:00:00 2001 From: Derek Jones Date: Tue, 2 Mar 2010 13:29:14 -0600 Subject: added @PHP4 tags to Compat functions --- system/core/Compat.php | 3 +++ 1 file changed, 3 insertions(+) (limited to 'system') diff --git a/system/core/Compat.php b/system/core/Compat.php index 06e5e78de..088d5815a 100644 --- a/system/core/Compat.php +++ b/system/core/Compat.php @@ -34,6 +34,7 @@ * PHP versions prior to 5.0 don't support the E_STRICT constant * so we need to explicitly define it otherwise the Exception class * will generate errors when running under PHP 4 + * @PHP4 * */ if ( ! defined('E_STRICT')) @@ -46,6 +47,7 @@ if ( ! defined('E_STRICT')) * * Determines if a string is comprised only of digits * http://us.php.net/manual/en/function.ctype_digit.php + * @PHP4 * * @access public * @param string @@ -71,6 +73,7 @@ if ( ! function_exists('ctype_digit')) * * Determines if a string is comprised of only alphanumeric characters * http://us.php.net/manual/en/function.ctype-alnum.php + * @PHP4 * * @access public * @param string -- cgit v1.2.3-24-g4f1b From 1efda7bc21582c6d0b6409e1f9a37d58e2d79571 Mon Sep 17 00:00:00 2001 From: Derek Jones Date: Tue, 2 Mar 2010 13:30:20 -0600 Subject: @PHP4 tags to CodeIgniter.php --- system/core/CodeIgniter.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'system') diff --git a/system/core/CodeIgniter.php b/system/core/CodeIgniter.php index 90cce1c6e..488f9f3ce 100644 --- a/system/core/CodeIgniter.php +++ b/system/core/CodeIgniter.php @@ -207,7 +207,8 @@ * Note: Due to the poor object handling in PHP 4 we'll * conditionally load different versions of the base * class. Retaining PHP 4 compatibility requires a bit of a hack. - * + * @PHP4 + * */ if (is_php('5.0.0') == TRUE) { -- cgit v1.2.3-24-g4f1b From d7055aaf8fed8120db13ae29f0da3fe45b725008 Mon Sep 17 00:00:00 2001 From: Derek Jones Date: Tue, 2 Mar 2010 13:32:57 -0600 Subject: adding @PHP4 tags to Base classes --- system/core/Base4.php | 3 ++- system/core/Base5.php | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) (limited to 'system') diff --git a/system/core/Base4.php b/system/core/Base4.php index 24474830c..bd0434158 100644 --- a/system/core/Base4.php +++ b/system/core/Base4.php @@ -31,7 +31,8 @@ * * Since PHP 5 doesn't suffer from this problem so we load one of * two files based on the version of PHP being run. - * + * @PHP4 + * * @package CodeIgniter * @subpackage codeigniter * @category front-controller diff --git a/system/core/Base5.php b/system/core/Base5.php index 86e3513c7..6f2fbdab0 100644 --- a/system/core/Base5.php +++ b/system/core/Base5.php @@ -22,7 +22,8 @@ * This file contains some code used only when CodeIgniter is being * run under PHP 5. It allows us to manage the CI super object more * gracefully than what is possible with PHP 4. - * + * @PHP4 (no need for separate Bases after PHP 4 is gone) + * * @package CodeIgniter * @subpackage codeigniter * @category front-controller -- cgit v1.2.3-24-g4f1b From 6f4d17fa4a9987c37c615413b1e98b77f0407416 Mon Sep 17 00:00:00 2001 From: Derek Jones Date: Tue, 2 Mar 2010 13:34:23 -0600 Subject: update Hooks to use load_class() from core --- system/core/Hooks.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'system') diff --git a/system/core/Hooks.php b/system/core/Hooks.php index 2c12ffafd..5e017ccb7 100644 --- a/system/core/Hooks.php +++ b/system/core/Hooks.php @@ -18,8 +18,7 @@ /** * CodeIgniter Hooks Class * - * Provides a mechanism to extend the base system without hacking. Most of - * this class is borrowed from Paul's Extension class in ExpressionEngine. + * Provides a mechanism to extend the base system without hacking. * * @package CodeIgniter * @subpackage Libraries -- cgit v1.2.3-24-g4f1b From 69fc4fc9e729f8ef510150ea01185923bffaf58b Mon Sep 17 00:00:00 2001 From: Derek Jones Date: Tue, 2 Mar 2010 13:36:31 -0600 Subject: significant rewrite to Input class some items will be moved to Security class added set_cookie() added UTF-8 uniformity to input --- system/core/Input.php | 897 +++++++++++--------------------------------------- 1 file changed, 192 insertions(+), 705 deletions(-) (limited to 'system') diff --git a/system/core/Input.php b/system/core/Input.php index 51c12a8a0..0760dc830 100644 --- a/system/core/Input.php +++ b/system/core/Input.php @@ -27,31 +27,14 @@ * @link http://codeigniter.com/user_guide/libraries/input.html */ class CI_Input { - var $use_xss_clean = FALSE; - var $xss_hash = ''; - var $ip_address = FALSE; - var $user_agent = FALSE; - var $allow_get_array = FALSE; - - /* never allowed, string replacement */ - var $never_allowed_str = array( - 'document.cookie' => '[removed]', - 'document.write' => '[removed]', - '.parentNode' => '[removed]', - '.innerHTML' => '[removed]', - 'window.location' => '[removed]', - '-moz-binding' => '[removed]', - '' => '-->', - ' '<![CDATA[' - ); - /* never allowed, regex replacement */ - var $never_allowed_regex = array( - "javascript\s*:" => '[removed]', - "expression\s*(\(|&\#40;)" => '[removed]', // CSS and IE - "vbscript\s*:" => '[removed]', // IE, surprise! - "Redirect\s+302" => '[removed]' - ); + + var $ip_address = FALSE; + var $user_agent = FALSE; + var $_allow_get_array = FALSE; + var $_standardize_newlines = TRUE; + var $_enable_xss = FALSE; // Set automatically based on config setting + var $_enable_csrf = FALSE; // Set automatically based on config setting + /** * Constructor @@ -65,161 +48,25 @@ class CI_Input { { log_message('debug', "Input Class Initialized"); - $CFG =& load_class('Config'); - $this->use_xss_clean = ($CFG->item('global_xss_filtering') === TRUE) ? TRUE : FALSE; - $this->allow_get_array = ($CFG->item('enable_query_strings') === TRUE) ? TRUE : FALSE; - $this->_sanitize_globals(); - } - - // -------------------------------------------------------------------- - - /** - * 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() - { - // Would kind of 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 security. - // This is effectively the same as register_globals = off - foreach (array($_GET, $_POST, $_COOKIE, $_SERVER, $_FILES, $_ENV, (isset($_SESSION) && is_array($_SESSION)) ? $_SESSION : array()) as $global) - { - if ( ! is_array($global)) - { - if ( ! in_array($global, $protected)) - { - unset($GLOBALS[$global]); - } - } - else - { - foreach ($global as $key => $val) - { - if ( ! in_array($key, $protected)) - { - unset($GLOBALS[$key]); - } - - if (is_array($val)) - { - foreach($val as $k => $v) - { - if ( ! in_array($k, $protected)) - { - unset($GLOBALS[$k]); - } - } - } - } - } - } - - // Is $_GET data allowed? If not we'll set the $_GET to an empty array - if ($this->allow_get_array == FALSE) - { - $_GET = array(); - } - else - { - $_GET = $this->_clean_input_data($_GET); - } - - // Clean $_POST Data - $_POST = $this->_clean_input_data($_POST); - - // Clean $_COOKIE Data - // 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']); - $_COOKIE = $this->_clean_input_data($_COOKIE); - - 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 - if (get_magic_quotes_gpc()) - { - $str = stripslashes($str); - } + $this->_allow_get_array = (config_item('enable_query_strings') === TRUE) ? TRUE : FALSE; + $this->_enable_xss = (config_item('global_xss_filtering') === TRUE) ? TRUE : FALSE; + $this->_enable_csrf = (config_item('csrf_protection') === TRUE) ? TRUE : FALSE; - // Should we filter the input data? - if ($this->use_xss_clean === TRUE) + // Do we need to load the security class? + if ($this->_enable_xss == TRUE OR $this->_enable_csrf == TRUE) { - $str = $this->xss_clean($str); + $this->security =& load_class('Security'); } - // Standardize newlines - if (strpos($str, "\r") !== FALSE) + // Do we need the Unicode class? + if (UTF8_ENABLED === TRUE) { - $str = str_replace(array("\r\n", "\r"), "\n", $str); + global $UNI; + $this->uni =& $UNI; } - 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.'); - } - - return $str; + // Sanitize global arrays + $this->_sanitize_globals(); } // -------------------------------------------------------------------- @@ -244,7 +91,8 @@ class CI_Input { if ($xss_clean === TRUE) { - return $this->xss_clean($array[$index]); + $_security =& load_class('Security'); + return $_security->xss_clean($array[$index]); } return $array[$index]; @@ -280,6 +128,7 @@ class CI_Input { return $this->_fetch_from_array($_POST, $index, $xss_clean); } + // -------------------------------------------------------------------- /** @@ -317,6 +166,68 @@ class CI_Input { 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 + * @return void + */ + function set_cookie($name = '', $value = '', $expire = '', $domain = '', $path = '/', $prefix = '') + { + if (is_array($name)) + { + foreach (array('value', 'expire', 'domain', 'path', 'prefix', '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 ( ! is_numeric($expire)) + { + $expire = time() - 86500; + } + else + { + if ($expire > 0) + { + $expire = time() + $expire; + } + else + { + $expire = 0; + } + } + + setcookie($prefix.$name, $value, $expire, $path, $domain, 0); + } + // -------------------------------------------------------------------- /** @@ -453,580 +364,155 @@ class CI_Input { // -------------------------------------------------------------------- /** - * Filename Security - * - * @access public - * @param string - * @return string - */ - function filename_security($str) - { - $bad = array( - "../", - "./", - "", - "<", - ">", - "'", - '"', - '&', - '$', - '#', - '{', - '}', - '[', - ']', - '=', - ';', - '?', - "%20", - "%22", - "%3c", // < - "%253c", // < - "%3e", // > - "%0e", // > - "%28", // ( - "%29", // ) - "%2528", // ( - "%26", // & - "%24", // $ - "%3f", // ? - "%3b", // ; - "%3d" // = - ); - - return stripslashes(str_replace($bad, '', $str)); - } - - // -------------------------------------------------------------------- - - /** - * XSS Clean + * Sanitize Globals * - * 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. + * This function does the following: * - * 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. + * Unsets $_GET data (if query strings are not enabled) * - * This function was based in part on some code and ideas I - * got from Bitflux: http://blog.bitflux.ch/wiki/XSS_Prevention + * Unsets all globals if register_globals is enabled * - * 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 + * Standardizes newline characters to \n * - * @access public - * @param string - * @return string + * @access private + * @return void */ - function xss_clean($str, $is_image = FALSE) + function _sanitize_globals() { - /* - * Is the string an array? - * - */ - if (is_array($str)) + // 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) { - while (list($key) = each($str)) + if ( ! is_array($global)) { - $str[$key] = $this->xss_clean($str[$key]); + if ( ! in_array($global, $protected)) + { + global $$global; + $$global = NULL; + } + } + else + { + foreach ($global as $key => $val) + { + if ( ! in_array($key, $protected)) + { + global $$key; + $$key = NULL; + } + } } - - return $str; - } - - /* - * Remove Invisible Characters - */ - $str = $this->_remove_invisible_characters($str); - - /* - * Protect GET variables in URLs - */ - - // 901119URL5918AMP18930PROTECT8198 - - $str = preg_replace('|\&([a-z\_0-9\-]+)\=([a-z\_0-9\-]+)|i', $this->xss_hash()."\\1=\\2", $str); - - /* - * Validate standard character entities - * - * Add a semicolon if missing. We do this to enable - * the conversion of entities to ASCII later. - * - */ - $str = preg_replace('#(&\#?[0-9a-z]{2,})([\x00-\x20])*;?#i', "\\1;\\2", $str); - - /* - * Validate UTF16 two byte encoding (x00) - * - * Just as above, adds a semicolon if missing. - * - */ - $str = preg_replace('#(&\#x?)([0-9A-F]+);?#i',"\\1\\2;",$str); - - /* - * Un-Protect GET variables in URLs - */ - $str = str_replace($this->xss_hash(), '&', $str); - - /* - * URL Decode - * - * Just in case stuff like this is submitted: - * - * Google - * - * Note: Use rawurldecode() so it does not remove plus signs - * - */ - $str = rawurldecode($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-z]+=([\'\"]).*?\\1/si", array($this, '_convert_attribute'), $str); - - $str = preg_replace_callback("/<\w+.*?(?=>|<|$)/si", array($this, '_html_entity_decode_callback'), $str); - - /* - * Remove Invisible Characters Again! - */ - $str = $this->_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. - * - */ - - if (strpos($str, "\t") !== FALSE) - { - $str = str_replace("\t", ' ', $str); - } - - /* - * Capture converted string for later comparison - */ - $converted_string = $str; - - /* - * Not Allowed Under Any Conditions - */ - - foreach ($this->never_allowed_str as $key => $val) - { - $str = str_replace($key, $val, $str); - } - - foreach ($this->never_allowed_regex as $key => $val) - { - $str = preg_replace("#".$key."#i", $val, $str); } - /* - * Makes PHP tags safe - * - * Note: XML tags are inadvertently replaced too: - * - * _allow_get_array == FALSE) { - // Images have a tendency to have the PHP short opening and closing tags every so often - // so we skip those and only do the long opening tags. - $str = preg_replace('/<\?(php)/i', "<?\\1", $str); + $_GET = array(); } else { - $str = str_replace(array(''), 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', 'script', 'applet', 'alert', 'document', 'write', 'cookie', 'window'); - foreach ($words as $word) - { - $temp = ''; - - for ($i = 0, $wordlen = strlen($word); $i < $wordlen; $i++) + if (is_array($_GET) AND count($_GET) > 0) { - $temp .= substr($word, $i, 1)."\s*"; + foreach($_GET as $key => $val) + { + $_GET[$this->_clean_input_keys($key)] = $this->_clean_input_data($val); + } } - - // 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($temp, 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 for PHP5, but it is dog slow compared - * to these simplified non-capturing preg_match(), especially if the pattern exists in the string - */ - do + // Clean $_POST Data + if (is_array($_POST) AND count($_POST) > 0) { - $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/i", $str) OR preg_match("/xss/i", $str)) + foreach($_POST as $key => $val) { - $str = preg_replace("#<(/*)(script|xss)(.*?)\>#si", '[removed]', $str); + $_POST[$this->_clean_input_keys($key)] = $this->_clean_input_data($val); } } - while($original != $str); - - unset($original); - - /* - * Remove JavaScript Event Handlers - * - * Note: This code is a little blunt. It removes - * the event handler and anything up to the closing >, - * but it's unlikely to be a problem. - * - */ - $event_handlers = array('[^a-z_\-]on\w*','xmlns'); - - if ($is_image === TRUE) - { - /* - * Adobe Photoshop puts XML metadata into JFIF images, including namespacing, - * so we have to allow this for images. -Paul - */ - unset($event_handlers[array_search('xmlns', $event_handlers)]); - } - - $str = preg_replace("#<([^><]+?)(".implode('|', $event_handlers).")(\s*=\s*[^><]*)([><]*)#i", "<\\1\\4", $str); - - /* - * 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|applet|audio|basefont|base|behavior|bgsound|blink|body|embed|expression|form|frameset|frame|head|html|ilayer|iframe|input|isindex|layer|link|meta|object|plaintext|style|script|textarea|title|video|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|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 - * - */ - foreach ($this->never_allowed_str as $key => $val) - { - $str = str_replace($key, $val, $str); - } - - foreach ($this->never_allowed_regex as $key => $val) - { - $str = preg_replace("#".$key."#i", $val, $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) - { - if ($str == $converted_string) - { - return TRUE; - } - else + // 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']); + + foreach($_COOKIE as $key => $val) { - return FALSE; + $_COOKIE[$this->_clean_input_keys($key)] = $this->_clean_input_data($val); } } - log_message('debug', "XSS Filtering completed"); - return $str; - } + // Sanitize PHP_SELF + $_SERVER['PHP_SELF'] = strip_tags($_SERVER['PHP_SELF']); - // -------------------------------------------------------------------- - /** - * Random Hash for protecting URLs - * - * @access public - * @return string - */ - function xss_hash() - { - if ($this->xss_hash == '') + // CSRF Protection check + if ($this->_enable_csrf == TRUE) { - if (phpversion() >= 4.2) - mt_srand(); - else - mt_srand(hexdec(substr(md5(microtime()), -8)) & 0x7fffffff); - - $this->xss_hash = md5(time() + mt_rand(0, 1999999999)); + $this->security->csrf_verify(); } - return $this->xss_hash; + log_message('debug', "Global POST and COOKIE data sanitized"); } // -------------------------------------------------------------------- /** - * Remove Invisible Characters + * Clean Input Data * - * This prevents sandwiching null characters - * between ascii characters, like Java\0script. + * This is a helper function. It escapes data and + * standardizes newline characters to \n * - * @access public + * @access private * @param string * @return string */ - function _remove_invisible_characters($str) + function _clean_input_data($str) { - static $non_displayables; - - if ( ! isset($non_displayables)) + if (is_array($str)) { - // every control character except newline (dec 10), carriage return (dec 13), and horizontal tab (dec 09), - $non_displayables = array( - '/%0[0-8bcef]/', // url encoded 00-08, 11, 12, 14, 15 - '/%1[0-9a-f]/', // url encoded 16-31 - '/[\x00-\x08]/', // 00-08 - '/\x0b/', '/\x0c/', // 11, 12 - '/[\x0e-\x1f]/' // 14-31 - ); + $new_array = array(); + foreach ($str as $key => $val) + { + $new_array[$this->_clean_input_keys($key)] = $this->_clean_input_data($val); + } + return $new_array; } - do + // We strip slashes if magic quotes is on to keep things consistent + if (get_magic_quotes_gpc()) { - $cleaned = $str; - $str = preg_replace($non_displayables, '', $str); + $str = stripslashes($str); } - while ($cleaned != $str); - - return $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 - * - * @access public - * @param type - * @return type - */ - function _compact_exploded_words($matches) - { - return preg_replace('/\s+/s', '', $matches[1]).$matches[2]; - } - - // -------------------------------------------------------------------- - - /** - * Sanitize Naughty HTML - * - * Callback function for xss_clean() to remove naughty HTML elements - * - * @access private - * @param array - * @return string - */ - function _sanitize_naughty_html($matches) - { - // encode opening brace - $str = '<'.$matches[1].$matches[2].$matches[3]; - - // encode captured opening or closing brace to prevent recursive vectors - $str .= str_replace(array('>', '<'), array('>', '<'), $matches[4]); - - return $str; - } - - // -------------------------------------------------------------------- - - /** - * 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 - * - * @access private - * @param array - * @return string - */ - function _js_link_removal($match) - { - $attributes = $this->_filter_attributes(str_replace(array('<', '>'), '', $match[1])); - return str_replace($match[1], preg_replace("#href=.*?(alert\(|alert&\#40;|javascript\:|charset\=|window\.|document\.|\.cookie|_filter_attributes(str_replace(array('<', '>'), '', $match[1])); - return str_replace($match[1], preg_replace("#src=.*?(alert\(|alert&\#40;|javascript\:|charset\=|window\.|document\.|\.cookie|', '<', '\\'), array('>', '<', '\\\\'), $match[0]); - } - - // -------------------------------------------------------------------- - /** - * HTML Entity Decode Callback - * - * Used as a callback for XSS Clean - * - * @access public - * @param array - * @return string - */ - function _html_entity_decode_callback($match) - { - $CFG =& load_class('Config'); - $charset = $CFG->item('charset'); - - return $this->_html_entity_decode($match[0], strtoupper($charset)); - } - - // -------------------------------------------------------------------- - - /** - * HTML Entities Decode - * - * This function is a replacement for html_entity_decode() - * - * In some versions of PHP the native function does not work - * when UTF-8 is the specified character set, so this gives us - * a work-around. More info here: - * http://bugs.php.net/bug.php?id=25670 - * - * @access private - * @param string - * @param string - * @return string - */ - /* ------------------------------------------------- - /* Replacement for html_entity_decode() - /* -------------------------------------------------*/ - - /* - NOTE: html_entity_decode() has a bug in some PHP versions when UTF-8 is the - character set, and the PHP developers said they were not back porting the - fix to versions other than PHP 5.x. - */ - function _html_entity_decode($str, $charset='UTF-8') - { - if (stristr($str, '&') === FALSE) return $str; - - // 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. - - if (function_exists('html_entity_decode') && (strtolower($charset) != 'utf-8' OR version_compare(phpversion(), '5.0.0', '>='))) + // Clean UTF-8 if supported + if (UTF8_ENABLED === TRUE) { - $str = html_entity_decode($str, ENT_COMPAT, $charset); - $str = preg_replace('~&#x(0*[0-9a-f]{2,5})~ei', 'chr(hexdec("\\1"))', $str); - return preg_replace('~&#([0-9]{2,4})~e', 'chr(\\1)', $str); + $str = $this->uni->clean_string($str); } - // Numeric Entities - $str = preg_replace('~&#x(0*[0-9a-f]{2,5});{0,1}~ei', 'chr(hexdec("\\1"))', $str); - $str = preg_replace('~&#([0-9]{2,4});{0,1}~e', 'chr(\\1)', $str); + // Should we filter the input data? + if ($this->_enable_xss === TRUE) + { + $str = $this->security->xss_clean($str); + } - // Literal Entities - Slightly slow so we do another check - if (stristr($str, '&') === FALSE) + // Standardize newlines if needed + if ($this->_standardize_newlines == TRUE) { - $str = strtr($str, array_flip(get_html_translation_table(HTML_ENTITIES))); + if (strpos($str, "\r") !== FALSE) + { + $str = str_replace(array("\r\n", "\r"), "\n", $str); + } } return $str; @@ -1035,31 +521,32 @@ class CI_Input { // -------------------------------------------------------------------- /** - * Filter Attributes + * Clean Keys * - * Filters tag attributes for consistency and safety + * 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 public + * @access private * @param string * @return string */ - function _filter_attributes($str) + function _clean_input_keys($str) { - $out = ''; + if ( ! preg_match("/^[a-z0-9:_\/-]+$/i", $str)) + { + exit('Disallowed Key Characters.'); + } - if (preg_match_all('#\s*[a-z\-]+\s*=\s*(\042|\047)([^\\1]*?)\\1#is', $str, $matches)) + // Clean UTF-8 if supported + if (UTF8_ENABLED === TRUE) { - foreach ($matches[0] as $match) - { - $out .= preg_replace("#/\*.*?\*/#s", '', $match); - } + $str = $this->uni->clean_string($str); } - return $out; + return $str; } - // -------------------------------------------------------------------- - } // END Input class -- cgit v1.2.3-24-g4f1b From 692c5486cdcfc05cd9dc6f348b09bc093b32eea8 Mon Sep 17 00:00:00 2001 From: Derek Jones Date: Tue, 2 Mar 2010 13:39:48 -0600 Subject: renamed class added ability to specify arbitrary path for language file (packages!) added ability to specify lang files that don't end in _lang, or to call file with _lang directly without it adding another _lang suffix --- system/core/Lang.php | 31 ++++++++++++++++++++++--------- 1 file changed, 22 insertions(+), 9 deletions(-) (limited to 'system') diff --git a/system/core/Lang.php b/system/core/Lang.php index bbecab645..e071495b8 100644 --- a/system/core/Lang.php +++ b/system/core/Lang.php @@ -24,7 +24,7 @@ * @author ExpressionEngine Dev Team * @link http://codeigniter.com/user_guide/libraries/language.html */ -class CI_Language { +class CI_Lang { var $language = array(); var $is_loaded = array(); @@ -34,7 +34,7 @@ class CI_Language { * * @access public */ - function CI_Language() + function CI_Lang() { log_message('debug', "Language Class Initialized"); } @@ -49,24 +49,36 @@ class CI_Language { * @param string the language (english, etc.) * @return mixed */ - function load($langfile = '', $idiom = '', $return = FALSE) + function load($langfile = '', $idiom = '', $return = FALSE, $add_suffix = TRUE, $alt_path = '') { - $langfile = str_replace(EXT, '', str_replace('_lang.', '', $langfile)).'_lang'.EXT; + $langfile = str_replace(EXT, '', $langfile); + + if ($add_suffix == TRUE) + { + $langfile = str_replace('_lang.', '', $langfile).'_lang'; + } + + $langfile .= EXT; if (in_array($langfile, $this->is_loaded, TRUE)) { return; } + $config =& get_config(); + if ($idiom == '') { - $CI =& get_instance(); - $deft_lang = $CI->config->item('language'); + $deft_lang = ( ! isset($config['language'])) ? 'english' : $config['language']; $idiom = ($deft_lang == '') ? 'english' : $deft_lang; } // Determine where the language file is and load it - if (file_exists(APPPATH.'language/'.$idiom.'/'.$langfile)) + if ($alt_path != '' && file_exists($alt_path.'language/'.$idiom.'/'.$langfile)) + { + include($alt_path.'language/'.$idiom.'/'.$langfile); + } + elseif (file_exists(APPPATH.'language/'.$idiom.'/'.$langfile)) { include(APPPATH.'language/'.$idiom.'/'.$langfile); } @@ -82,6 +94,7 @@ class CI_Language { } } + if ( ! isset($lang)) { log_message('error', 'Language file contains no data: language/'.$idiom.'/'.$langfile); @@ -119,5 +132,5 @@ class CI_Language { } // END Language Class -/* End of file Language.php */ -/* Location: ./system/core/Language.php */ \ No newline at end of file +/* End of file Lang.php */ +/* Location: ./system/core/Lang.php */ \ No newline at end of file -- cgit v1.2.3-24-g4f1b From 32bf18694a43a346ae9c1819f9c37f3fc64d3b1c Mon Sep 17 00:00:00 2001 From: Derek Jones Date: Tue, 2 Mar 2010 13:46:07 -0600 Subject: rewrite of Loader class killed scaffolding added @PHP4 tags --- system/core/Loader.php | 340 ++++++++++++++++++++++++++++--------------------- 1 file changed, 198 insertions(+), 142 deletions(-) (limited to 'system') diff --git a/system/core/Loader.php b/system/core/Loader.php index a30238c3e..f70ee0334 100644 --- a/system/core/Loader.php +++ b/system/core/Loader.php @@ -31,8 +31,11 @@ class CI_Loader { // All these are set automatically. Don't mess with them. var $_ci_ob_level; var $_ci_view_path = ''; - var $_ci_is_php5 = FALSE; + var $_ci_library_paths = array(); + var $_ci_model_paths = array(); + var $_ci_helper_paths = array(); var $_ci_is_instance = FALSE; // Whether we should use $this or $CI =& get_instance() + var $_base_classes = array(); // Set by the controller class var $_ci_cached_vars = array(); var $_ci_classes = array(); var $_ci_loaded_files = array(); @@ -51,10 +54,12 @@ class CI_Loader { */ function CI_Loader() { - $this->_ci_is_php5 = (floor(phpversion()) >= 5) ? TRUE : FALSE; $this->_ci_view_path = APPPATH.'views/'; $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); + log_message('debug', "Loader Class Initialized"); } @@ -74,12 +79,12 @@ class CI_Loader { */ function library($library = '', $params = NULL, $object_name = NULL) { - if ($library == '') + if ($library == '' OR isset($this->_base_classes[$library])) { return FALSE; } - if ( ! is_null($params) AND ! is_array($params)) + if ( ! is_null($params) && ! is_array($params)) { $params = NULL; } @@ -128,17 +133,16 @@ class CI_Loader { return; } + $path = ''; + // Is the model in a sub-folder? If so, parse out the filename and path. - if (strpos($model, '/') === FALSE) - { - $path = ''; - } - else + if (($last_slash = strrpos($model, '/')) !== FALSE) { - $x = explode('/', $model); - $model = end($x); - unset($x[count($x)-1]); - $path = implode('/', $x).'/'; + // 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 == '') @@ -158,33 +162,40 @@ class CI_Loader { } $model = strtolower($model); - - if ( ! file_exists(APPPATH.'models/'.$path.$model.EXT)) - { - show_error('Unable to locate the model you have specified: '.$model); - } - - 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('Model')) + + foreach ($this->_ci_model_paths as $mod_path) { - load_class('Model', FALSE); - } + if ( ! file_exists($mod_path.'models/'.$path.$model.EXT)) + { + continue; + } - require_once(APPPATH.'models/'.$path.$model.EXT); + if ($db_conn !== FALSE AND ! class_exists('CI_DB')) + { + if ($db_conn === TRUE) + $db_conn = ''; - $model = ucfirst($model); - - $CI->$name = new $model(); - $CI->$name->_assign_libraries(); + $CI->load->database($db_conn, FALSE, TRUE); + } + + if ( ! class_exists('Model')) + { + load_class('Model', 'core'); + } + + require_once($mod_path.'models/'.$path.$model.EXT); + + $model = ucfirst($model); + + $CI->$name = new $model(); + $CI->$name->_assign_libraries(); + + $this->_ci_models[] = $name; + return; + } - $this->_ci_models[] = $name; + // couldn't find the model + show_error('Unable to locate the model you have specified: '.$model); } // -------------------------------------------------------------------- @@ -366,21 +377,14 @@ class CI_Loader { * @return void */ function helper($helpers = array()) - { - if ( ! is_array($helpers)) - { - $helpers = array($helpers); - } - - foreach ($helpers as $helper) - { - $helper = strtolower(str_replace(EXT, '', str_replace('_helper', '', $helper)).'_helper'); - + { + 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.EXT; // Is this a helper extension request? @@ -395,25 +399,30 @@ class CI_Loader { include_once($ext_helper); include_once($base_helper); + + $this->_ci_helpers[$helper] = TRUE; + log_message('debug', 'Helper loaded: '.$helper); + continue; } - elseif (file_exists(APPPATH.'helpers/'.$helper.EXT)) - { - include_once(APPPATH.'helpers/'.$helper.EXT); - } - else - { - if (file_exists(BASEPATH.'helpers/'.$helper.EXT)) - { - include_once(BASEPATH.'helpers/'.$helper.EXT); - } - else - { - show_error('Unable to load the requested file: helpers/'.$helper.EXT); + + // Try to load the helper + foreach ($this->_ci_helper_paths as $path) + { + if (file_exists($path.'helpers/'.$helper.EXT)) + { + include_once($path.'helpers/'.$helper.EXT); + + $this->_ci_helpers[$helper] = TRUE; + log_message('debug', 'Helper loaded: '.$helper); + break; } } - $this->_ci_helpers[$helper] = TRUE; - log_message('debug', 'Helper loaded: '.$helper); + // unable to load the helper + if ( ! isset($this->_ci_helpers[$helper])) + { + show_error('Unable to load the requested file: helpers/'.$helper.EXT); + } } } @@ -447,15 +456,8 @@ class CI_Loader { */ function plugin($plugins = array()) { - if ( ! is_array($plugins)) - { - $plugins = array($plugins); - } - - foreach ($plugins as $plugin) + foreach ($this->_ci_prep_filename($plugins, '_pi') as $plugin) { - $plugin = strtolower(str_replace(EXT, '', str_replace('_pi', '', $plugin)).'_pi'); - if (isset($this->_ci_plugins[$plugin])) { continue; @@ -523,19 +525,6 @@ class CI_Loader { $CI->lang->load($langfile, $lang); } } - - /** - * Loads language files for scaffolding - * - * @access public - * @param string - * @return arra - */ - function scaffold_language($file = '', $lang = '', $return = FALSE) - { - $CI =& get_instance(); - return $CI->lang->load($file, $lang, $return); - } // -------------------------------------------------------------------- @@ -553,36 +542,75 @@ class CI_Loader { } // -------------------------------------------------------------------- - + /** - * Scaffolding Loader + * Add Package Path * - * This initializing function works a bit different than the - * others. It doesn't load the class. Instead, it simply - * sets a flag indicating that scaffolding is allowed to be - * used. The actual scaffolding function below is - * called by the front controller based on whether the - * second segment of the URL matches the "secret" scaffolding - * word stored in the application/config/routes.php + * Prepends a parent path to the library, model, helper, and config path arrays * * @access public * @param string * @return void - */ - function scaffolding($table = '') - { - if ($table === FALSE) + */ + function add_package_path($path) + { + array_unshift($this->_ci_library_paths, $path); + array_unshift($this->_ci_model_paths, $path); + array_unshift($this->_ci_helper_paths, $path); + + // Add config file path + $config =& $this->_ci_get_component('config'); + array_unshift($config->_config_paths, $path); + } + + // -------------------------------------------------------------------- + + /** + * 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. + * + * @access public + * @param type + * @return type + */ + function remove_package_path($path = '', $remove_config_path = TRUE) + { + $config =& $this->_ci_get_component('config'); + + if ($path == '') { - show_error('You must include the name of the table you would like to access when you initialize scaffolding'); + $void = array_shift($this->_ci_library_paths); + $void = array_shift($this->_ci_model_paths); + $void = array_shift($this->_ci_helper_paths); + $void = array_shift($config->_config_paths); + } + else + { + 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 (($key = array_search($path, $config->_config_paths)) !== FALSE) + { + unset($config->_config_paths[$key]); + } } - $CI =& get_instance(); - $CI->_ci_scaffolding = TRUE; - $CI->_ci_scaff_table = $table; + // 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))); + $config->_config_paths = array_unique(array_merge($config->_config_paths, array(APPPATH))); } // -------------------------------------------------------------------- - + /** * Loader * @@ -733,19 +761,13 @@ class CI_Loader { // Was the path included with the class name? // We look for a slash to determine this $subdir = ''; - if (strpos($class, '/') !== FALSE) + if (($last_slash = strrpos($class, '/')) !== FALSE) { - // explode the path so we can separate the filename from the path - $x = explode('/', $class); - - // Reset the $class variable now that we know the actual filename - $class = end($x); - - // Kill the filename from the array - unset($x[count($x)-1]); + // Extract the path + $subdir = substr($class, 0, $last_slash + 1); - // Glue the path back together, sans filename - $subdir = implode($x, '/').'/'; + // 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 @@ -792,12 +814,11 @@ class CI_Loader { } // Lets search for the requested library file and load it. - $is_duplicate = FALSE; - for ($i = 1; $i < 3; $i++) + $is_duplicate = FALSE; + foreach ($this->_ci_library_paths as $path) { - $path = ($i % 2) ? APPPATH : BASEPATH; $filepath = $path.'libraries/'.$subdir.$class.EXT; - + // Does the file exist? No? Bummer... if ( ! file_exists($filepath)) { @@ -826,8 +847,9 @@ class CI_Loader { include_once($filepath); $this->_ci_loaded_files[] = $filepath; - return $this->_ci_init_class($class, '', $params, $object_name); + 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? @@ -859,7 +881,7 @@ class CI_Loader { */ function _ci_init_class($class, $prefix = '', $config = FALSE, $object_name = NULL) { - // Is there an associated config file for this class? + // Is there an associated config file for this class? Note: these should always be lowercase if ($config === NULL) { // We test for both uppercase and lowercase, for servers that @@ -971,7 +993,7 @@ class CI_Loader { // A little tweak to remain backward compatible // The $autoload['core'] item was deprecated - if ( ! isset($autoload['libraries'])) + if ( ! isset($autoload['libraries']) AND isset($autoload['core'])) { $autoload['libraries'] = $autoload['core']; } @@ -985,13 +1007,6 @@ class CI_Loader { $this->database(); $autoload['libraries'] = array_diff($autoload['libraries'], array('database')); } - - // Load scaffolding - if (in_array('scaffolding', $autoload['libraries'])) - { - $this->scaffolding(); - $autoload['libraries'] = array_diff($autoload['libraries'], array('scaffolding')); - } // Load all other libraries foreach ($autoload['libraries'] as $item) @@ -1027,20 +1042,10 @@ class CI_Loader { return; } - if ($this->_ci_is_instance()) + foreach($this->_ci_models as $model) { - $CI =& get_instance(); - foreach ($this->_ci_models as $model) - { - $CI->$model->_assign_libraries(); - } - } - else - { - foreach ($this->_ci_models as $model) - { - $this->$model->_assign_libraries(); - } + $model = $this->_ci_get_component($model); + $model->_assign_libraries(); } } @@ -1064,13 +1069,14 @@ class CI_Loader { /** * Determines whether we should use the CI instance or $this - * + * @PHP4 + * * @access private * @return bool */ function _ci_is_instance() { - if ($this->_ci_is_php5 == TRUE) + if (is_php('5.0.0') == TRUE) { return TRUE; } @@ -1078,6 +1084,56 @@ class CI_Loader { global $CI; return (is_object($CI)) ? TRUE : FALSE; } + + // -------------------------------------------------------------------- + + /** + * Get a reference to a specific library or model + * + * @access private + * @return bool + */ + function &_ci_get_component($component) + { + if ($this->_ci_is_instance()) + { + $CI =& get_instance(); + return $CI->$component; + } + else + { + return $this->$component; + } + } + + // -------------------------------------------------------------------- + + /** + * Prep filename + * + * This function preps the name of various items to make loading them more reliable. + * + * @access private + * @param mixed + * @return array + */ + function _ci_prep_filename($filename, $extension) + { + if ( ! is_array($filename)) + { + return array(strtolower(str_replace(EXT, '', str_replace($extension, '', $filename)).$extension)); + } + else + { + foreach ($filename as $key => $val) + { + $filename[$key] = strtolower(str_replace(EXT, '', str_replace($extension, '', $val)).$extension); + } + + return $filename; + } + } + } -- cgit v1.2.3-24-g4f1b From 8eae4d7a9a922763c64d282f5d46de240bba60d0 Mon Sep 17 00:00:00 2001 From: Derek Jones Date: Tue, 2 Mar 2010 13:47:19 -0600 Subject: class rename --- system/core/Model.php | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'system') diff --git a/system/core/Model.php b/system/core/Model.php index 541f966b6..16c4e7dd8 100644 --- a/system/core/Model.php +++ b/system/core/Model.php @@ -24,7 +24,7 @@ * @author ExpressionEngine Dev Team * @link http://codeigniter.com/user_guide/libraries/config.html */ -class Model { +class CI_Model { var $_parent_name = ''; @@ -33,7 +33,7 @@ class Model { * * @access public */ - function Model() + function CI_Model() { // If the magic __get() or __set() methods are used in a Model references can't be used. $this->_assign_libraries( (method_exists($this, '__get') OR method_exists($this, '__set')) ? FALSE : TRUE ); @@ -65,7 +65,8 @@ class Model { // problems so we'll conditionally use them if ($use_reference == TRUE) { - $this->$key = NULL; // Needed to prevent reference errors with some configurations + // Needed to prevent reference errors with some configurations + $this->$key = ''; $this->$key =& $CI->$key; } else -- cgit v1.2.3-24-g4f1b From 46520494d494aa9a3579c24c0e22bfbf31aa719e Mon Sep 17 00:00:00 2001 From: Derek Jones Date: Tue, 2 Mar 2010 13:53:25 -0600 Subject: changed set_status_header() default $code param to proper integer added ability to disable {elapsed_time} and {memory_usage} variables --- system/core/Output.php | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) (limited to 'system') diff --git a/system/core/Output.php b/system/core/Output.php index ea4b0e314..ad92accd6 100644 --- a/system/core/Output.php +++ b/system/core/Output.php @@ -32,7 +32,7 @@ class CI_Output { var $cache_expiration = 0; var $headers = array(); var $enable_profiler = FALSE; - + var $parse_exec_vars = TRUE; // whether or not to parse variables like {elapsed_time} and {memory_usage} function CI_Output() { @@ -123,7 +123,7 @@ class CI_Output { * @param string * @return void */ - function set_status_header($code = '200', $text = '') + function set_status_header($code = 200, $text = '') { set_status_header($code, $text); } @@ -199,12 +199,16 @@ class CI_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'); - $output = str_replace('{elapsed_time}', $elapsed, $output); - $memory = ( ! function_exists('memory_get_usage')) ? '0' : round(memory_get_usage()/1024/1024, 2).'MB'; - $output = str_replace('{memory_usage}', $memory, $output); + $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); + } // -------------------------------------------------------------------- -- cgit v1.2.3-24-g4f1b From c77384069446fb1eee1a0ccf4296d48497fb433c Mon Sep 17 00:00:00 2001 From: Derek Jones Date: Tue, 2 Mar 2010 13:55:13 -0600 Subject: Router class rewrite killed scaffolding abstracted _set_default_controller() added implementation for directory and controller trigger when query strings are enabled --- system/core/Router.php | 234 ++++++++++++++++++++++++++++++++----------------- 1 file changed, 153 insertions(+), 81 deletions(-) (limited to 'system') diff --git a/system/core/Router.php b/system/core/Router.php index 32c1c3820..b371d5241 100644 --- a/system/core/Router.php +++ b/system/core/Router.php @@ -34,9 +34,7 @@ class CI_Router { var $class = ''; var $method = 'index'; var $directory = ''; - var $uri_protocol = 'auto'; var $default_controller; - var $scaffolding_request = FALSE; // Must be set to FALSE /** * Constructor @@ -45,9 +43,8 @@ class CI_Router { */ function CI_Router() { - $this->config =& load_class('Config'); - $this->uri =& load_class('URI'); - $this->_set_routing(); + $this->config =& load_class('Config', 'core'); + $this->uri =& load_class('URI', 'core'); log_message('debug', "Router Class Initialized"); } @@ -63,63 +60,55 @@ class CI_Router { * @return void */ function _set_routing() - { - // Are query strings enabled in the config file? - // If so, we're done since segment based URIs are not used with query strings. + { + // 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')])) { - $this->set_class(trim($this->uri->_filter_uri($_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(); } - - return; } // Load the routes.php file. @include(APPPATH.'config/routes'.EXT); $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']); + $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 == '') { - 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."); - } - - if (strpos($this->default_controller, '/') !== FALSE) - { - $x = explode('/', $this->default_controller); - - $this->set_class(end($x)); - $this->set_method('index'); - $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."); - return; + return $this->_set_default_controller(); } - unset($this->routes['default_controller']); // Do we need to remove the URL suffix? $this->uri->_remove_url_suffix(); @@ -133,6 +122,42 @@ class CI_Router { // 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(array($x[0], $x[1])); + } + 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."); + } // -------------------------------------------------------------------- @@ -148,29 +173,20 @@ class CI_Router { * @return void */ function _set_request($segments = array()) - { + { $segments = $this->_validate_request($segments); if (count($segments) == 0) { - return; + return $this->_set_default_controller(); } $this->set_class($segments[0]); if (isset($segments[1])) { - // A scaffolding request. No funny business with the URL - if ($this->routes['scaffolding_trigger'] == $segments[1] AND $segments[1] != '_ci_scaffolding') - { - $this->scaffolding_request = TRUE; - unset($this->routes['scaffolding_trigger']); - } - else - { - // A standard method request - $this->set_method($segments[1]); - } + // A standard method request + $this->set_method($segments[1]); } else { @@ -197,15 +213,20 @@ class CI_Router { */ 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].EXT)) { 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); @@ -215,13 +236,24 @@ class CI_Router { // Does the requested controller exist in the sub-folder? if ( ! file_exists(APPPATH.'controllers/'.$this->fetch_directory().$segments[0].EXT)) { - show_404($this->fetch_directory().$segments[0]); + show_404($this->fetch_directory().$segments[0]); } } else { - $this->set_class($this->default_controller); - $this->set_method('index'); + // 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.EXT)) @@ -231,16 +263,32 @@ class CI_Router { } } - + return $segments; } - - // Can't find the requested controller... - show_404($segments[0]); + + + // 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 (isset($this->routes['404_override']) AND $this->routes['404_override'] != '') + { + if (strpos($this->routes['404_override'], '/') !== FALSE) + { + $x = explode('/', $this->routes['404_override']); + + $this->set_class($x[0]); + $this->set_method($x[1]); + + return $x; + } + } + + // Nothing else to do at this point but show a 404 + show_404($segments[0]); } - + // -------------------------------------------------------------------- - + /** * Parse Routes * @@ -253,22 +301,13 @@ class CI_Router { */ function _parse_routes() { - // Do we even have any custom routing to deal with? - // There is a default scaffolding trigger, so we'll look just for 1 - if (count($this->routes) == 1) - { - $this->_set_request($this->uri->segments); - return; - } - // 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])) { - $this->_set_request(explode('/', $this->routes[$uri])); - return; + return $this->_set_request(explode('/', $this->routes[$uri])); } // Loop through the route array looking for wild-cards @@ -276,18 +315,17 @@ class CI_Router { { // 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); } - $this->_set_request(explode('/', $val)); - return; + return $this->_set_request(explode('/', $val)); } } @@ -366,7 +404,7 @@ class CI_Router { */ function set_directory($dir) { - $this->directory = $dir.'/'; + $this->directory = trim($dir, '/').'/'; } // -------------------------------------------------------------------- @@ -382,6 +420,40 @@ class CI_Router { 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']); + } + } + + } // END Router Class -- cgit v1.2.3-24-g4f1b From 7576a3b6b7ed5658cabae96b3e64614f312d76d7 Mon Sep 17 00:00:00 2001 From: Derek Jones Date: Tue, 2 Mar 2010 14:00:36 -0600 Subject: change to use load_class() from core --- system/core/URI.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system') diff --git a/system/core/URI.php b/system/core/URI.php index 77b814925..cffffc20d 100644 --- a/system/core/URI.php +++ b/system/core/URI.php @@ -44,7 +44,7 @@ class CI_URI { */ function CI_URI() { - $this->config =& load_class('Config'); + $this->config =& load_class('Config', 'core'); log_message('debug', "URI Class Initialized"); } -- cgit v1.2.3-24-g4f1b From cf24ffea2b91f48900c3c5a19ce11982f76c45ed Mon Sep 17 00:00:00 2001 From: Derek Jones Date: Tue, 2 Mar 2010 15:37:56 -0600 Subject: dumping scaffolding folder --- system/scaffolding/Scaffolding.php | 291 ------------------------------- system/scaffolding/images/background.jpg | Bin 410 -> 0 bytes system/scaffolding/images/index.html | 10 -- system/scaffolding/images/logo.jpg | Bin 4518 -> 0 bytes system/scaffolding/index.html | 10 -- system/scaffolding/views/add.php | 32 ---- system/scaffolding/views/delete.php | 9 - system/scaffolding/views/edit.php | 33 ---- system/scaffolding/views/footer.php | 10 -- system/scaffolding/views/header.php | 29 --- system/scaffolding/views/index.html | 10 -- system/scaffolding/views/no_data.php | 8 - system/scaffolding/views/stylesheet.css | 143 --------------- system/scaffolding/views/view.php | 27 --- 14 files changed, 612 deletions(-) delete mode 100644 system/scaffolding/Scaffolding.php delete mode 100644 system/scaffolding/images/background.jpg delete mode 100644 system/scaffolding/images/index.html delete mode 100644 system/scaffolding/images/logo.jpg delete mode 100644 system/scaffolding/index.html delete mode 100644 system/scaffolding/views/add.php delete mode 100644 system/scaffolding/views/delete.php delete mode 100644 system/scaffolding/views/edit.php delete mode 100644 system/scaffolding/views/footer.php delete mode 100644 system/scaffolding/views/header.php delete mode 100644 system/scaffolding/views/index.html delete mode 100644 system/scaffolding/views/no_data.php delete mode 100644 system/scaffolding/views/stylesheet.css delete mode 100644 system/scaffolding/views/view.php (limited to 'system') diff --git a/system/scaffolding/Scaffolding.php b/system/scaffolding/Scaffolding.php deleted file mode 100644 index d110626b1..000000000 --- a/system/scaffolding/Scaffolding.php +++ /dev/null @@ -1,291 +0,0 @@ -CI =& get_instance(); - - $this->CI->load->database("", FALSE, TRUE); - $this->CI->load->library('pagination'); - - // Turn off caching - $this->CI->db->cache_off(); - - /** - * Set the current table name - * This is done when initializing scaffolding: - * $this->load->scaffolding('table_name') - * - */ - $this->current_table = $db_table; - - /** - * Set the path to the "view" files - * We'll manually override the "view" path so that - * the load->view function knows where to look. - */ - - $this->CI->load->_ci_view_path = BASEPATH.'scaffolding/views/'; - - // Set the base URL - $this->base_url = $this->CI->config->site_url().'/'.$this->CI->uri->segment(1).$this->CI->uri->slash_segment(2, 'both'); - $this->base_uri = $this->CI->uri->segment(1).$this->CI->uri->slash_segment(2, 'leading'); - - // Set a few globals - $data = array( - 'image_url' => $this->CI->config->system_url().'scaffolding/images/', - 'base_uri' => $this->base_uri, - 'base_url' => $this->base_url, - 'title' => $this->current_table - ); - - $this->CI->load->vars($data); - - // Load the language file and create variables - $this->lang = $this->CI->load->scaffold_language('scaffolding', '', TRUE); - $this->CI->load->vars($this->lang); - - // Load the helper files we plan to use - $this->CI->load->helper(array('url', 'form')); - - - log_message('debug', 'Scaffolding Class Initialized'); - } - - // -------------------------------------------------------------------- - - /** - * "Add" Page - * - * Shows a form representing the currently selected DB - * so that data can be inserted - * - * @access public - * @return string the HTML "add" page - */ - function add() - { - $data = array( - 'title' => ( ! isset($this->lang['scaff_add'])) ? 'Add Data' : $this->lang['scaff_add'], - 'fields' => $this->CI->db->field_data($this->current_table), - 'action' => $this->base_uri.'/insert' - ); - - $this->CI->load->view('add', $data); - } - - // -------------------------------------------------------------------- - - /** - * Insert the data - * - * @access public - * @return void redirects to the view page - */ - function insert() - { - if ($this->CI->db->insert($this->current_table, $_POST) === FALSE) - { - $this->add(); - } - else - { - redirect($this->base_uri.'/view/'); - } - } - - // -------------------------------------------------------------------- - - /** - * "View" Page - * - * Shows a table containing the data in the currently - * selected DB - * - * @access public - * @return string the HTML "view" page - */ - function view() - { - // Fetch the total number of DB rows - $total_rows = $this->CI->db->count_all($this->current_table); - - if ($total_rows < 1) - { - return $this->CI->load->view('no_data'); - } - - // Set the query limit/offset - $per_page = 20; - $offset = $this->CI->uri->segment(4, 0); - - // Run the query - $query = $this->CI->db->get($this->current_table, $per_page, $offset); - - // Now let's get the field names - $fields = $this->CI->db->list_fields($this->current_table); - - // We assume that the column in the first position is the primary field. - $primary = current($fields); - - // Pagination! - $this->CI->pagination->initialize( - array( - 'base_url' => $this->base_url.'/view', - 'total_rows' => $total_rows, - 'per_page' => $per_page, - 'uri_segment' => 4, - 'full_tag_open' => '

    ', - 'full_tag_close' => '

    ' - ) - ); - - $data = array( - 'title' => ( ! isset($this->lang['scaff_view'])) ? 'View Data' : $this->lang['scaff_view'], - 'query' => $query, - 'fields' => $fields, - 'primary' => $primary, - 'paginate' => $this->CI->pagination->create_links() - ); - - $this->CI->load->view('view', $data); - } - - // -------------------------------------------------------------------- - - /** - * "Edit" Page - * - * Shows a form representing the currently selected DB - * so that data can be edited - * - * @access public - * @return string the HTML "edit" page - */ - function edit() - { - if (FALSE === ($id = $this->CI->uri->segment(4))) - { - return $this->view(); - } - - // Fetch the primary field name - $primary = $this->CI->db->primary($this->current_table); - - // Run the query - $query = $this->CI->db->get_where($this->current_table, array($primary => $id)); - - $data = array( - 'title' => ( ! isset($this->lang['scaff_edit'])) ? 'Edit Data' : $this->lang['scaff_edit'], - 'fields' => $query->field_data(), - 'query' => $query->row(), - 'action' => $this->base_uri.'/update/'.$this->CI->uri->segment(4) - ); - - $this->CI->load->view('edit', $data); - } - - // -------------------------------------------------------------------- - - /** - * Update - * - * @access public - * @return void redirects to the view page - */ - function update() - { - // Fetch the primary key - $primary = $this->CI->db->primary($this->current_table); - - // Now do the query - $this->CI->db->update($this->current_table, $_POST, array($primary => $this->CI->uri->segment(4))); - - redirect($this->base_uri.'/view/'); - } - - // -------------------------------------------------------------------- - - /** - * Delete Confirmation - * - * @access public - * @return string the HTML "delete confirm" page - */ - function delete() - { - if ( ! isset($this->lang['scaff_del_confirm'])) - { - $message = 'Are you sure you want to delete the following row: '.$this->CI->uri->segment(4); - } - else - { - $message = $this->lang['scaff_del_confirm'].' '.$this->CI->uri->segment(4); - } - - $data = array( - 'title' => ( ! isset($this->lang['scaff_delete'])) ? 'Delete Data' : $this->lang['scaff_delete'], - 'message' => $message, - 'no' => anchor(array($this->base_uri, 'view'), ( ! isset($this->lang['scaff_no'])) ? 'No' : $this->lang['scaff_no']), - 'yes' => anchor(array($this->base_uri, 'do_delete', $this->CI->uri->segment(4)), ( ! isset($this->lang['scaff_yes'])) ? 'Yes' : $this->lang['scaff_yes']) - ); - - $this->CI->load->view('delete', $data); - } - - // -------------------------------------------------------------------- - - /** - * Delete - * - * @access public - * @return void redirects to the view page - */ - function do_delete() - { - // Fetch the primary key - $primary = $this->CI->db->primary($this->current_table); - - // Now do the query - $this->CI->db->where($primary, $this->CI->uri->segment(4)); - $this->CI->db->delete($this->current_table); - - header("Refresh:0;url=".site_url(array($this->base_uri, 'view'))); - exit; - } - -} - -/* End of file Scaffolding.php */ -/* Location: ./system/scaffolding/Scaffolding.php */ \ No newline at end of file diff --git a/system/scaffolding/images/background.jpg b/system/scaffolding/images/background.jpg deleted file mode 100644 index 9d5bdcea1..000000000 Binary files a/system/scaffolding/images/background.jpg and /dev/null differ diff --git a/system/scaffolding/images/index.html b/system/scaffolding/images/index.html deleted file mode 100644 index c942a79ce..000000000 --- a/system/scaffolding/images/index.html +++ /dev/null @@ -1,10 +0,0 @@ - - - 403 Forbidden - - - -

    Directory access is forbidden.

    - - - \ No newline at end of file diff --git a/system/scaffolding/images/logo.jpg b/system/scaffolding/images/logo.jpg deleted file mode 100644 index d6cc9a76d..000000000 Binary files a/system/scaffolding/images/logo.jpg and /dev/null differ diff --git a/system/scaffolding/index.html b/system/scaffolding/index.html deleted file mode 100644 index c942a79ce..000000000 --- a/system/scaffolding/index.html +++ /dev/null @@ -1,10 +0,0 @@ - - - 403 Forbidden - - - -

    Directory access is forbidden.

    - - - \ No newline at end of file diff --git a/system/scaffolding/views/add.php b/system/scaffolding/views/add.php deleted file mode 100644 index cbb12f6fb..000000000 --- a/system/scaffolding/views/add.php +++ /dev/null @@ -1,32 +0,0 @@ -load->view('header'); ?> - -

    - - - - - - - -primary_key == 1) continue; ?> - - - - - type == 'blob'): ?> - - - - - - - -
    name; echo ' '.$field->default; ?>
    - - - - - -load->view('footer'); -/* End of file add.php */ -/* Location: ./system/scaffolding/views/add.php */ diff --git a/system/scaffolding/views/delete.php b/system/scaffolding/views/delete.php deleted file mode 100644 index d19542195..000000000 --- a/system/scaffolding/views/delete.php +++ /dev/null @@ -1,9 +0,0 @@ -load->view('header'); ?> - -

    - -

      |   - -load->view('footer'); -/* End of file delete.php */ -/* Location: ./system/scaffolding/views/delete.php */ diff --git a/system/scaffolding/views/edit.php b/system/scaffolding/views/edit.php deleted file mode 100644 index fe553e591..000000000 --- a/system/scaffolding/views/edit.php +++ /dev/null @@ -1,33 +0,0 @@ -load->view('header'); ?> - - -

    - - - - - - - -primary_key == 1) continue; ?> - - - - - type == 'blob'): ?> - - - - - - - -
    name; ?>
    - - - - - -load->view('footer'); -/* End of file edit.php */ -/* Location: ./system/scaffolding/views/edit.php */ \ No newline at end of file diff --git a/system/scaffolding/views/footer.php b/system/scaffolding/views/footer.php deleted file mode 100644 index 0e71401c9..000000000 --- a/system/scaffolding/views/footer.php +++ /dev/null @@ -1,10 +0,0 @@ - -
  • - - - - - \ No newline at end of file diff --git a/system/scaffolding/views/header.php b/system/scaffolding/views/header.php deleted file mode 100644 index 50f234a49..000000000 --- a/system/scaffolding/views/header.php +++ /dev/null @@ -1,29 +0,0 @@ - - - - -<?php echo $title; ?> - - - - - - - - - - - - -
    -
    \ No newline at end of file diff --git a/system/scaffolding/views/index.html b/system/scaffolding/views/index.html deleted file mode 100644 index c942a79ce..000000000 --- a/system/scaffolding/views/index.html +++ /dev/null @@ -1,10 +0,0 @@ - - - 403 Forbidden - - - -

    Directory access is forbidden.

    - - - \ No newline at end of file diff --git a/system/scaffolding/views/no_data.php b/system/scaffolding/views/no_data.php deleted file mode 100644 index bc81e7480..000000000 --- a/system/scaffolding/views/no_data.php +++ /dev/null @@ -1,8 +0,0 @@ -load->view('header'); ?> - -

    -

    - -load->view('footer'); -/* End of file no_data.php */ -/* Location: ./system/scaffolding/views/no_data.php */ \ No newline at end of file diff --git a/system/scaffolding/views/stylesheet.css b/system/scaffolding/views/stylesheet.css deleted file mode 100644 index 3f487dd0b..000000000 --- a/system/scaffolding/views/stylesheet.css +++ /dev/null @@ -1,143 +0,0 @@ -body { - margin: 0; - padding: 0; - font-family: Lucida Grande, Verdana, Geneva, Sans-serif; - font-size: 11px; - color: #4F5155; - background: #fff url(background.jpg) repeat-x left top; -} - -a { - color: #8B0D00; - background-color: transparent; - text-decoration: none; - font-weight: bold; -} - -a:visited { - color: #8B0D00; - background-color: transparent; - text-decoration: none; -} - -a:hover { - color: #000; - text-decoration: none; - background-color: transparent; -} - - -#header { - margin: 0; - padding: 0; -} - -#header_left { - background-color: transparent; - float: left; - padding: 21px 0 0 32px; - margin: 0 -} - -#header_right { - background-color: transparent; - float: right; - text-align: right; - padding: 35px 50px 20px 0; - margin: 0 -} - -#footer { - margin: 20px 0 15px 0; - padding: 0; -} - -#footer p { - font-size: 10px; - color: #999; - text-align: center; -} - -#outer { - margin: 30px 40px 0 40px; -} - -img { - padding:0; - border: 0; - margin: 0; -} - -.nopad { - padding:0; - border: 0; - margin: 0; -} - -table { - background-color: #efefef; -} - -th { - background-color: #eee; - font-weight: bold; - padding: 6px; - text-align: left; -} - -td { - background-color: #fff; - padding: 6px; -} - - -form { - margin: 0; - padding: 0; -} - -.input { - font-family: Lucida Grande, Verdana, Geneva, Sans-serif; - font-size: 11px; - width: 600px; - color: #333; - border: 1px solid #B3B4BD; - font-size: 11px; - height: 2em; - padding: 0; - margin: 0; -} - -.textarea { - font-family: Lucida Grande, Verdana, Geneva, Sans-serif; - font-size: 12px; - width: 600px; - color: #333; - border: 1px solid #B3B4BD; - padding: 0; - margin: 0; -} - -.select { - background-color: #fff; - font-size: 11px; - font-weight: normal; - color: #333; - padding: 0; - margin: 0 0 3px 0; -} - -.checkbox { - background-color: transparent; - padding: 0; - border: 0; -} - -.submit { - background-color: #8B0D00; - color: #FFF; - font-weight: normal; - border: 1px solid #000; - margin: 6px 0 0 0; - padding: 1px 5px 1px 5px; -} diff --git a/system/scaffolding/views/view.php b/system/scaffolding/views/view.php deleted file mode 100644 index a81241d39..000000000 --- a/system/scaffolding/views/view.php +++ /dev/null @@ -1,27 +0,0 @@ -load->view('header'); ?> - - - - - - - - - - -result() as $row): ?> - - - - - - - - -
    EditDelete
     $primary), $scaff_edit); ?> $primary), $scaff_delete); ?>$field);?>
    - - - -load->view('footer'); -/* End of file view.php */ -/* Location: ./system/scaffolding/views/view.php */ \ No newline at end of file -- cgit v1.2.3-24-g4f1b From fcb7bfd9c78f87f93b53c276c92f239794839501 Mon Sep 17 00:00:00 2001 From: Derek Jones Date: Tue, 2 Mar 2010 15:45:15 -0600 Subject: brought captcha plugin up to date --- system/plugins/captcha_pi.php | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) (limited to 'system') diff --git a/system/plugins/captcha_pi.php b/system/plugins/captcha_pi.php index 77f29f8b9..7092f28e1 100644 --- a/system/plugins/captcha_pi.php +++ b/system/plugins/captcha_pi.php @@ -28,7 +28,7 @@ Once loaded you can generate a captcha like this: 'word' => 'Random word', 'img_path' => './captcha/', 'img_url' => 'http://example.com/captcha/', - 'font_path' => './system/fonts/texb.ttf', + 'font_path' => './path/to/fonts/texb.ttf', 'img_width' => '150', 'img_height' => 30, 'expiration' => 7200 @@ -110,7 +110,6 @@ On the page where the captcha will be shown you'll have something like this: $cap = create_captcha($vals); $data = array( - 'captcha_id' => '', 'captcha_time' => $cap['time'], 'ip_address' => $this->input->ip_address(), 'word' => $cap['word'] @@ -128,7 +127,7 @@ Then, on the page that accepts the submission you'll have something like this: // First, delete old captchas $expiration = time()-7200; // Two hour limit - $DB->query("DELETE FROM captcha WHERE captcha_time < ".$expiration); + $this->db->query("DELETE FROM captcha WHERE captcha_time < ".$expiration); // Then see if a captcha exists: $sql = "SELECT COUNT(*) AS count FROM captcha WHERE word = ? AND ip_address = ? AND date > ?"; @@ -180,7 +179,7 @@ function create_captcha($data = '', $img_path = '', $img_url = '', $font_path = return FALSE; } - if ( ! is_really_writable($img_path)) + if ( ! is_writable($img_path)) { return FALSE; } @@ -243,7 +242,7 @@ function create_captcha($data = '', $img_path = '', $img_url = '', $font_path = // ----------------------------------- // Create image // ----------------------------------- - + // PHP.net recommends imagecreatetruecolor(), but it isn't always available if (function_exists('imagecreatetruecolor')) { -- cgit v1.2.3-24-g4f1b From b2fd44474b126ce8fa179651ea8ad1edc110131c Mon Sep 17 00:00:00 2001 From: Derek Jones Date: Tue, 2 Mar 2010 15:45:30 -0600 Subject: lowercased all tag attribute values --- system/plugins/js_calendar_pi.php | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'system') diff --git a/system/plugins/js_calendar_pi.php b/system/plugins/js_calendar_pi.php index a35ab56bd..f722777b3 100644 --- a/system/plugins/js_calendar_pi.php +++ b/system/plugins/js_calendar_pi.php @@ -33,7 +33,7 @@ Then to show the actual calendar you'll do this:
    -

    Today

    +

    Today

    @@ -210,9 +210,9 @@ function build_calendar() str += '
    '; str += ''; str += ''; - str += '
    <<<\/td>'; + str += '<<<\/td>'; str += '' + months[this.month] + ' ' + this.year + '<\/td>'; - str += '>><\/td>'; + str += '>><\/td>'; str += '<\/tr>'; // Day Names @@ -242,7 +242,7 @@ function build_calendar() } else if (displayNum == selDate && this.highlight == true) // Selected date { - str += '' + displayNum + '<\/td>'; + str += '' + displayNum + '<\/td>'; } else if (displayNum > this.total_days()) { @@ -250,7 +250,7 @@ function build_calendar() } else // Unselected days { - str += '' + displayNum + '<\/td>'; + str += '' + displayNum + '<\/td>'; } if (j % 7 == 6) -- cgit v1.2.3-24-g4f1b From c16f49eebbc00b33902dcdb05c4b652937d4b2e9 Mon Sep 17 00:00:00 2001 From: Derek Jones Date: Tue, 2 Mar 2010 16:39:47 -0600 Subject: added .htaccess file to cache folder --- system/cache/.htaccess | 1 + 1 file changed, 1 insertion(+) create mode 100644 system/cache/.htaccess (limited to 'system') diff --git a/system/cache/.htaccess b/system/cache/.htaccess new file mode 100644 index 000000000..3418e55a6 --- /dev/null +++ b/system/cache/.htaccess @@ -0,0 +1 @@ +deny from all \ No newline at end of file -- cgit v1.2.3-24-g4f1b From 71141ce88b5d77e28049b4f641045125921e3dc0 Mon Sep 17 00:00:00 2001 From: Derek Jones Date: Tue, 2 Mar 2010 16:41:20 -0600 Subject: whitespace in Email lib --- system/libraries/Email.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'system') diff --git a/system/libraries/Email.php b/system/libraries/Email.php index d0f2ea9a5..8014bd21e 100644 --- a/system/libraries/Email.php +++ b/system/libraries/Email.php @@ -1544,7 +1544,7 @@ class CI_Email { // server probably has popen disabled, so nothing we can do to get a verbose error. return FALSE; } - + fputs($fp, $this->_header_str); fputs($fp, $this->_finalbody); @@ -1554,7 +1554,7 @@ class CI_Email { { $status = $status >> 8 & 0xFF; } - + if ($status != 0) { $this->_set_error_message('email_exit_status', $status); -- cgit v1.2.3-24-g4f1b From d10e89666380d717e3e40dda046be78dbb7a38c4 Mon Sep 17 00:00:00 2001 From: Derek Jones Date: Tue, 2 Mar 2010 17:10:36 -0600 Subject: added batch insert/update and a replace method to active record --- system/database/DB_active_rec.php | 327 +++++++++++++++++++++++++++++++++++++- 1 file changed, 325 insertions(+), 2 deletions(-) (limited to 'system') diff --git a/system/database/DB_active_rec.php b/system/database/DB_active_rec.php index a3abff11e..88690a8f9 100644 --- a/system/database/DB_active_rec.php +++ b/system/database/DB_active_rec.php @@ -721,13 +721,13 @@ class CI_DB_active_record extends CI_DB_driver { { $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) { @@ -1134,7 +1134,127 @@ class CI_DB_active_record extends CI_DB_driver { { return $this->get_where($table, $where, $limit, $offset); } + + // -------------------------------------------------------------------- + + /** + * Insert_Batch + * + * Compiles batch insert strings and runs the queries + * + * @access public + * @param string the table to retrieve the results from + * @param array an associative array of insert values + * @return object + */ + 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 + * + * @access public + * @param mixed + * @param string + * @param boolean + * @return object + */ + + 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; + } + // -------------------------------------------------------------------- /** @@ -1183,6 +1303,42 @@ class CI_DB_active_record extends CI_DB_driver { return $this->query($sql); } + 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); + } + // -------------------------------------------------------------------- /** @@ -1245,6 +1401,133 @@ class CI_DB_active_record extends CI_DB_driver { return $this->query($sql); } + + // -------------------------------------------------------------------- + + /** + * Update_Batch + * + * Compiles an update string and runs the query + * + * @access public + * @param string the table to retrieve the results from + * @param array an associative array of update values + * @param string the where key + * @return object + */ + 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_myst_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 + * + * @access public + * @param array + * @param string + * @param boolean + * @return object + */ + + 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[] = $k.'-'.$v; + } + + 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; + } + // -------------------------------------------------------------------- /** @@ -1638,7 +1921,47 @@ class CI_DB_active_record extends CI_DB_driver { $array[$key] = $val; } } + + return $array; + } + // -------------------------------------------------------------------- + + /** + * Object to Array + * + * Takes an object as input and converts the class variables to array key/vals + * + * @access public + * @param object + * @return array + */ + 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' && $val != '_ci_scaffolding' && $val != '_ci_scaff_table') + { + + $i = 0; + foreach ($out[$val] as $data) + { + $array[$i][$val] = $data; + $i++; + } + } + } + return $array; } -- cgit v1.2.3-24-g4f1b From e77922026939fed28a607338e24c1c37066a97b4 Mon Sep 17 00:00:00 2001 From: Derek Jones Date: Tue, 2 Mar 2010 17:24:46 -0600 Subject: whitespace and changes to load_class() to use core --- system/database/DB_driver.php | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) (limited to 'system') diff --git a/system/database/DB_driver.php b/system/database/DB_driver.php index d7f17ccb8..dfef42757 100644 --- a/system/database/DB_driver.php +++ b/system/database/DB_driver.php @@ -261,10 +261,10 @@ class CI_DB_driver { // 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); } - + // 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 @@ -679,7 +679,7 @@ class CI_DB_driver { * @return mixed */ function escape($str) - { + { if (is_string($str)) { $str = "'".$this->escape_str($str)."'"; @@ -697,7 +697,7 @@ class CI_DB_driver { } // -------------------------------------------------------------------- - + /** * Escape LIKE String * @@ -714,7 +714,7 @@ class CI_DB_driver { } // -------------------------------------------------------------------- - + /** * Primary * @@ -1155,7 +1155,7 @@ class CI_DB_driver { */ function display_error($error = '', $swap = '', $native = FALSE) { - $LANG =& load_class('Language'); + $LANG =& load_class('Lang', 'core'); $LANG->load('db'); $heading = $LANG->line('db_error_heading'); @@ -1169,7 +1169,7 @@ class CI_DB_driver { $message = ( ! is_array($error)) ? array(str_replace('%s', $swap, $LANG->line($error))) : $error; } - $error =& load_class('Exceptions'); + $error =& load_class('Exceptions', 'core'); echo $error->show_error($heading, $message, 'error_db'); exit; } @@ -1315,13 +1315,13 @@ class CI_DB_driver { { $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) { -- cgit v1.2.3-24-g4f1b From 30b35eb12edef6018fe61f383a002d895683e468 Mon Sep 17 00:00:00 2001 From: Derek Jones Date: Tue, 2 Mar 2010 17:25:41 -0600 Subject: whitespace --- system/database/DB_forge.php | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'system') diff --git a/system/database/DB_forge.php b/system/database/DB_forge.php index c5931db27..8be65e0d6 100644 --- a/system/database/DB_forge.php +++ b/system/database/DB_forge.php @@ -259,8 +259,8 @@ class CI_DB_forge { // add field info into field array, but we can only do one at a time // so we cycle through - foreach ($field as $k => $v) - { + foreach ($field as $k => $v) + { $this->add_field(array($k => $field[$k])); if (count($this->fields) == 0) @@ -279,6 +279,7 @@ class CI_DB_forge { } return TRUE; + } // -------------------------------------------------------------------- -- cgit v1.2.3-24-g4f1b From 20aa2bd6d852530b3d4b2e76076fe7e7b48bf148 Mon Sep 17 00:00:00 2001 From: Derek Jones Date: Tue, 2 Mar 2010 17:28:07 -0600 Subject: added batch insert/update and replace methods to MySQL driver --- system/database/drivers/mysql/mysql_driver.php | 92 ++++++++++++++++++++++++++ 1 file changed, 92 insertions(+) (limited to 'system') diff --git a/system/database/drivers/mysql/mysql_driver.php b/system/database/drivers/mysql/mysql_driver.php index bd60d9ffe..d684c8a49 100644 --- a/system/database/drivers/mysql/mysql_driver.php +++ b/system/database/drivers/mysql/mysql_driver.php @@ -537,6 +537,44 @@ class CI_DB_mysql_driver extends CI_DB { // -------------------------------------------------------------------- + + /** + * 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 * @@ -572,6 +610,60 @@ class CI_DB_mysql_driver extends CI_DB { // -------------------------------------------------------------------- + + /** + * 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 * -- cgit v1.2.3-24-g4f1b From c34e578c4bf993481381b1efb8f95089482135a4 Mon Sep 17 00:00:00 2001 From: Derek Jones Date: Tue, 2 Mar 2010 17:35:55 -0600 Subject: added stricton db config item to force strict mode - good for ensuring strict sql during development --- system/application/config/database.php | 3 +++ system/database/DB.php | 5 +++++ 2 files changed, 8 insertions(+) (limited to 'system') diff --git a/system/application/config/database.php b/system/application/config/database.php index ee11c8a7a..28dfff5c9 100644 --- a/system/application/config/database.php +++ b/system/application/config/database.php @@ -26,6 +26,8 @@ | ['cachedir'] The path to the folder where cache files should be stored | ['char_set'] The character set used in communicating with the database | ['dbcollat'] The character collation used in communicating with the database +| ['stricton'] TRUE/FALSE - forces "Strict Mode" connections +| - good for ensuring strict SQL while developing | | The $active_group variable lets you choose which connection group to | make active. By default there is only one group (the "default" group). @@ -49,6 +51,7 @@ $db['default']['cache_on'] = FALSE; $db['default']['cachedir'] = ""; $db['default']['char_set'] = "utf8"; $db['default']['dbcollat'] = "utf8_general_ci"; +$db['default']['stricton'] = FALSE; /* End of file database.php */ diff --git a/system/database/DB.php b/system/database/DB.php index 6930411c7..a91ca08fa 100644 --- a/system/database/DB.php +++ b/system/database/DB.php @@ -137,6 +137,11 @@ function &DB($params = '', $active_record_override = NULL) $DB->initialize(); } + if (isset($params['stricton']) && $params['stricton'] == TRUE) + { + $DB->query('SET SESSION sql_mode="STRICT_ALL_TABLES"'); + } + return $DB; } -- cgit v1.2.3-24-g4f1b From 2a58e7a6945c47929d5003f15f1bdc32a1717270 Mon Sep 17 00:00:00 2001 From: Derek Jones Date: Tue, 2 Mar 2010 17:53:38 -0600 Subject: bringing language files up to date --- system/language/english/date_lang.php | 1 + system/language/english/db_lang.php | 3 ++- system/language/english/scaffolding_lang.php | 17 -------------- system/language/english/validation_lang.php | 33 +++++++++++++--------------- 4 files changed, 18 insertions(+), 36 deletions(-) delete mode 100644 system/language/english/scaffolding_lang.php (limited to 'system') diff --git a/system/language/english/date_lang.php b/system/language/english/date_lang.php index 628e55b1a..c0ace16ef 100644 --- a/system/language/english/date_lang.php +++ b/system/language/english/date_lang.php @@ -56,5 +56,6 @@ $lang['UP1275'] = '(UTC +12:45) Chatham Islands Standard Time'; $lang['UP13'] = '(UTC +13:00) Phoenix Islands Time, Tonga'; $lang['UP14'] = '(UTC +14:00) Line Islands'; + /* End of file date_lang.php */ /* Location: ./system/language/english/date_lang.php */ \ No newline at end of file diff --git a/system/language/english/db_lang.php b/system/language/english/db_lang.php index dc98afcad..79b82c73a 100644 --- a/system/language/english/db_lang.php +++ b/system/language/english/db_lang.php @@ -6,8 +6,9 @@ $lang['db_unable_to_select'] = 'Unable to select the specified database: %s'; $lang['db_unable_to_create'] = 'Unable to create the specified database: %s'; $lang['db_invalid_query'] = 'The query you submitted is not valid.'; $lang['db_must_set_table'] = 'You must set the database table to be used with your query.'; -$lang['db_must_set_database'] = 'You must set the database name in your database config file.'; $lang['db_must_use_set'] = 'You must use the "set" method to update an entry.'; +$lang['db_must_use_index'] = 'You must specify an index to match on for batch updates.'; +$lang['db_batch_missing_index'] = 'One or more rows submitted for batch updating is missing the specified index.'; $lang['db_must_use_where'] = 'Updates are not allowed unless they contain a "where" clause.'; $lang['db_del_must_use_where'] = 'Deletes are not allowed unless they contain a "where" or "like" clause.'; $lang['db_field_param_missing'] = 'To fetch fields requires the name of the table as a parameter.'; diff --git a/system/language/english/scaffolding_lang.php b/system/language/english/scaffolding_lang.php deleted file mode 100644 index c4d54d5c6..000000000 --- a/system/language/english/scaffolding_lang.php +++ /dev/null @@ -1,17 +0,0 @@ - Date: Tue, 2 Mar 2010 18:13:59 -0600 Subject: adding initial Javascript and Jquery libs --- system/libraries/Javascript.php | 847 +++++++++++++++++++++++++++++++ system/libraries/Jquery.php | 1071 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 1918 insertions(+) create mode 100644 system/libraries/Javascript.php create mode 100644 system/libraries/Jquery.php (limited to 'system') diff --git a/system/libraries/Javascript.php b/system/libraries/Javascript.php new file mode 100644 index 000000000..3b7dcc6ff --- /dev/null +++ b/system/libraries/Javascript.php @@ -0,0 +1,847 @@ + 'jquery', 'autoload' => TRUE); + + foreach ($defaults as $key => $val) + { + if (isset($params[$key]) && $params[$key] !== "") + { + $defaults[$key] = $params[$key]; + } + } + + extract($defaults); + + $this->CI =& get_instance(); + + // load the requested js library + $this->CI->load->library($js_library_driver, array('autoload' => $autoload)); + // make js to refer to current library + $this->js =& $this->CI->$js_library_driver; + + log_message('debug', "Javascript Class Initialized and loaded. Driver used: $js_library_driver"); + } + + // -------------------------------------------------------------------- + // Event Code + // -------------------------------------------------------------------- + + /** + * Blur + * + * Outputs a javascript library blur event + * + * @access public + * @param string The element to attach the event to + * @param string The code to execute + * @return string + */ + function blur($element = 'this', $js = '') + { + return $this->js->_blur($element, $js); + } + + // -------------------------------------------------------------------- + + /** + * Change + * + * Outputs a javascript library change event + * + * @access public + * @param string The element to attach the event to + * @param string The code to execute + * @return string + */ + function change($element = 'this', $js = '') + { + return $this->js->_change($element, $js); + } + + // -------------------------------------------------------------------- + + /** + * Click + * + * Outputs a javascript library click event + * + * @access public + * @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) + { + return $this->js->_click($element, $js, $ret_false); + } + + // -------------------------------------------------------------------- + + /** + * Double Click + * + * Outputs a javascript library dblclick event + * + * @access public + * @param string The element to attach the event to + * @param string The code to execute + * @return string + */ + function dblclick($element = 'this', $js = '') + { + return $this->js->_dblclick($element, $js); + } + + // -------------------------------------------------------------------- + + /** + * Error + * + * Outputs a javascript library error event + * + * @access public + * @param string The element to attach the event to + * @param string The code to execute + * @return string + */ + function error($element = 'this', $js = '') + { + return $this->js->_error($element, $js); + } + + // -------------------------------------------------------------------- + + /** + * Focus + * + * Outputs a javascript library focus event + * + * @access public + * @param string The element to attach the event to + * @param string The code to execute + * @return string + */ + function focus($element = 'this', $js = '') + { + return $this->js->__add_event($focus, $js); + } + + // -------------------------------------------------------------------- + + /** + * Hover + * + * Outputs a javascript library hover event + * + * @access public + * @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) + { + return $this->js->__hover($element, $over, $out); + } + + // -------------------------------------------------------------------- + + /** + * Keydown + * + * Outputs a javascript library keydown event + * + * @access public + * @param string The element to attach the event to + * @param string The code to execute + * @return string + */ + function keydown($element = 'this', $js = '') + { + return $this->js->_keydown($element, $js); + } + + // -------------------------------------------------------------------- + + /** + * Keyup + * + * Outputs a javascript library keydown event + * + * @access public + * @param string The element to attach the event to + * @param string The code to execute + * @return string + */ + function keyup($element = 'this', $js = '') + { + return $this->js->_keyup($element, $js); + } + + // -------------------------------------------------------------------- + + /** + * Load + * + * Outputs a javascript library load event + * + * @access public + * @param string The element to attach the event to + * @param string The code to execute + * @return string + */ + function load($element = 'this', $js = '') + { + return $this->js->_load($element, $js); + } + + // -------------------------------------------------------------------- + + /** + * Mousedown + * + * Outputs a javascript library mousedown event + * + * @access public + * @param string The element to attach the event to + * @param string The code to execute + * @return string + */ + function mousedown($element = 'this', $js = '') + { + return $this->js->_mousedown($element, $js); + } + + // -------------------------------------------------------------------- + + /** + * Mouse Out + * + * Outputs a javascript library mouseout event + * + * @access public + * @param string The element to attach the event to + * @param string The code to execute + * @return string + */ + function mouseout($element = 'this', $js = '') + { + return $this->js->_mouseout($element, $js); + } + + // -------------------------------------------------------------------- + + /** + * Mouse Over + * + * Outputs a javascript library mouseover event + * + * @access public + * @param string The element to attach the event to + * @param string The code to execute + * @return string + */ + function mouseover($element = 'this', $js = '') + { + return $this->js->_mouseover($element, $js); + } + + // -------------------------------------------------------------------- + + /** + * Mouseup + * + * Outputs a javascript library mouseup event + * + * @access public + * @param string The element to attach the event to + * @param string The code to execute + * @return string + */ + function mouseup($element = 'this', $js = '') + { + return $this->js->_mouseup($element, $js); + } + + // -------------------------------------------------------------------- + + /** + * Output + * + * Outputs the called javascript to the screen + * + * @access public + * @param string The code to output + * @return string + */ + function output($js) + { + return $this->js->_output($js); + } + + // -------------------------------------------------------------------- + + /** + * Ready + * + * Outputs a javascript library mouseup event + * + * @access public + * @param string The element to attach the event to + * @param string The code to execute + * @return string + */ + function ready($js) + { + return $this->js->_document_ready($js); + } + + // -------------------------------------------------------------------- + + /** + * Resize + * + * Outputs a javascript library resize event + * + * @access public + * @param string The element to attach the event to + * @param string The code to execute + * @return string + */ + function resize($element = 'this', $js = '') + { + return $this->js->_resize($element, $js); + } + + // -------------------------------------------------------------------- + + /** + * Scroll + * + * Outputs a javascript library scroll event + * + * @access public + * @param string The element to attach the event to + * @param string The code to execute + * @return string + */ + function scroll($element = 'this', $js = '') + { + return $this->js->_scroll($element, $js); + } + + // -------------------------------------------------------------------- + + /** + * Unload + * + * Outputs a javascript library unload event + * + * @access public + * @param string The element to attach the event to + * @param string The code to execute + * @return string + */ + function unload($element = 'this', $js = '') + { + return $this->js->_unload($element, $js); + } + + // -------------------------------------------------------------------- + // Effects + // -------------------------------------------------------------------- + + + /** + * Add Class + * + * Outputs a javascript library addClass event + * + * @access public + * @param string - element + * @param string - Class to add + * @return string + */ + function addClass($element = 'this', $class = '') + { + return $this->js->_addClass($element, $class); + } + + // -------------------------------------------------------------------- + + /** + * Animate + * + * Outputs a javascript library animate 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 animate($element = 'this', $params = array(), $speed = '', $extra = '') + { + return $this->js->_animate($element, $params, $speed, $extra); + } + + // -------------------------------------------------------------------- + + /** + * Fade In + * + * Outputs a javascript library hide 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 fadeIn($element = 'this', $speed = '', $callback = '') + { + return $this->js->_fadeIn($element, $speed, $callback); + } + + // -------------------------------------------------------------------- + + /** + * Fade Out + * + * Outputs a javascript library hide 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 fadeOut($element = 'this', $speed = '', $callback = '') + { + return $this->js->_fadeOut($element, $speed, $callback); + } + // -------------------------------------------------------------------- + + /** + * Slide Up + * + * Outputs a javascript library slideUp 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 slideUp($element = 'this', $speed = '', $callback = '') + { + return $this->js->_slideUp($element, $speed, $callback); + + } + + // -------------------------------------------------------------------- + + /** + * Remove Class + * + * Outputs a javascript library removeClass event + * + * @access public + * @param string - element + * @param string - Class to add + * @return string + */ + function removeClass($element = 'this', $class = '') + { + return $this->js->_removeClass($element, $class); + } + + // -------------------------------------------------------------------- + + /** + * Slide Down + * + * Outputs a javascript library slideDown 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 slideDown($element = 'this', $speed = '', $callback = '') + { + return $this->js->_slideDown($element, $speed, $callback); + } + + // -------------------------------------------------------------------- + + /** + * Slide Toggle + * + * Outputs a javascript library 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 = '') + { + return $this->js->_slideToggle($element, $speed, $callback); + + } + + // -------------------------------------------------------------------- + + /** + * Hide + * + * Outputs a javascript library hide action + * + * @access public + * @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 = '') + { + return $this->js->_hide($element, $speed, $callback); + } + + // -------------------------------------------------------------------- + + /** + * Toggle + * + * Outputs a javascript library toggle event + * + * @access public + * @param string - element + * @return string + */ + function toggle($element = 'this') + { + return $this->js->_toggle($element); + + } + + // -------------------------------------------------------------------- + + /** + * Toggle Class + * + * Outputs a javascript library toggle class event + * + * @access public + * @param string - element + * @return string + */ + function toggleClass($element = 'this', $class='') + { + return $this->js->_toggleClass($element, $class); + } + + // -------------------------------------------------------------------- + + /** + * Show + * + * Outputs a javascript library show 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 show($element = 'this', $speed = '', $callback = '') + { + return $this->js->_show($element, $speed, $callback); + } + + + // -------------------------------------------------------------------- + + /** + * Compile + * + * gather together all script needing to be output + * + * @access public + * @param string The element to attach the event to + * @return string + */ + function compile($view_var = 'script_foot', $script_tags = TRUE) + { + $this->js->_compile($view_var, $script_tags); + } + + /** + * Clear Compile + * + * Clears any previous javascript collected for output + * + * @access public + * @return void + */ + function clear_compile() + { + $this->js->_clear_compile(); + } + + // -------------------------------------------------------------------- + + /** + * External + * + * Outputs a + * + * @access private + * @param string + * @return string + */ + function _close_script($extra = "\n") + { + return "$extra"; + } + + + // -------------------------------------------------------------------- + // -------------------------------------------------------------------- + // AJAX-Y STUFF - still a testbed + // -------------------------------------------------------------------- + // -------------------------------------------------------------------- + + /** + * Update + * + * Outputs a javascript library slideDown 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 update($element = 'this', $speed = '', $callback = '') + { + return $this->js->_updater($element, $speed, $callback); + } + + // -------------------------------------------------------------------- + + /** + * Generate JSON + * + * Can be passed a database result or associative array and returns a JSON formatted string + * + * @param mixed result set or array + * @param bool match array types (defaults to objects) + * @return string a json formatted string + */ + function generate_json($result = NULL, $match_array_type = FALSE) + { + // JSON data can optionally be passed to this function + // either as a database result object or an array, or a user supplied array + if ( ! is_null($result)) + { + if (is_object($result)) + { + $json_result = $result->result_array(); + } + elseif (is_array($result)) + { + $json_result = $result; + } + else + { + return $this->_prep_args($result); + } + } + else + { + return 'null'; + } + + $json = array(); + $_is_assoc = TRUE; + + if ( ! is_array($json_result) AND empty($json_result)) + { + show_error("Generate JSON Failed - Illegal key, value pair."); + } + elseif ($match_array_type) + { + $_is_assoc = $this->_is_associative_array($json_result); + } + + foreach ($json_result as $k => $v) + { + if ($_is_assoc) + { + $json[] = $this->_prep_args($k, TRUE).':'.$this->generate_json($v, $match_array_type); + } + else + { + $json[] = $this->generate_json($v, $match_array_type); + } + } + + $json = implode(',', $json); + + return $_is_assoc ? "{".$json."}" : "[".$json."]"; + + } + + // -------------------------------------------------------------------- + + /** + * Is associative array + * + * Checks for an associative array + * + * @access public + * @param type + * @return type + */ + function _is_associative_array($arr) + { + foreach (array_keys($arr) as $key => $val) + { + if ($key !== $val) + { + return TRUE; + } + } + + return FALSE; + } + + // -------------------------------------------------------------------- + + /** + * Prep Args + * + * Ensures a standard json value and escapes values + * + * @access public + * @param type + * @return type + */ + function _prep_args($result, $is_key = FALSE) + { + if (is_null($result)) + { + return 'null'; + } + elseif (is_bool($result)) + { + return ($result === TRUE) ? 'true' : 'false'; + } + elseif (is_string($result) OR $is_key) + { + return '"'.str_replace(array('\\', "\t", "\n", "\r", '"'), array('\\\\', '\\t', '\\n', "\\r", '\"'), $result).'"'; + } + elseif (is_scalar($result)) + { + return $result; + } + } +} + + +/* End of file Javascript.php */ +/* Location: ./system/libraries/Javascript.php */ \ No newline at end of file diff --git a/system/libraries/Jquery.php b/system/libraries/Jquery.php new file mode 100644 index 000000000..c63a74239 --- /dev/null +++ b/system/libraries/Jquery.php @@ -0,0 +1,1071 @@ +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; + } + +} + +/* End of file Jquery.php */ +/* Location: ./system/libraries/Jquery.php */ \ No newline at end of file -- cgit v1.2.3-24-g4f1b From 079303e4240ac6661f21d56bc22001c3963ab599 Mon Sep 17 00:00:00 2001 From: Derek Jones Date: Tue, 2 Mar 2010 18:16:23 -0600 Subject: adding HTTP_X_FORWARDED_FOR header to Profiler --- system/libraries/Profiler.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system') diff --git a/system/libraries/Profiler.php b/system/libraries/Profiler.php index ebadf8610..bf20f1722 100644 --- a/system/libraries/Profiler.php +++ b/system/libraries/Profiler.php @@ -380,7 +380,7 @@ class CI_Profiler { $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') as $header) + 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"; -- cgit v1.2.3-24-g4f1b From e701d76c5050b18d576523e5a997fa5ff4ba6251 Mon Sep 17 00:00:00 2001 From: Derek Jones Date: Tue, 2 Mar 2010 18:17:01 -0600 Subject: added Security library --- system/libraries/Security.php | 710 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 710 insertions(+) create mode 100644 system/libraries/Security.php (limited to 'system') diff --git a/system/libraries/Security.php b/system/libraries/Security.php new file mode 100644 index 000000000..93da59204 --- /dev/null +++ b/system/libraries/Security.php @@ -0,0 +1,710 @@ + '[removed]', + 'document.write' => '[removed]', + '.parentNode' => '[removed]', + '.innerHTML' => '[removed]', + 'window.location' => '[removed]', + '-moz-binding' => '[removed]', + '' => '-->', + ' '<![CDATA[' + ); + /* never allowed, regex replacement */ + var $never_allowed_regex = array( + "javascript\s*:" => '[removed]', + "expression\s*(\(|&\#40;)" => '[removed]', // CSS and IE + "vbscript\s*:" => '[removed]', // IE, surprise! + "Redirect\s+302" => '[removed]' + ); + + function CI_Security() + { + // Set the CSRF hash + $this->_csrf_set_hash(); + + log_message('debug', "Security Class Initialized"); + } + + // -------------------------------------------------------------------- + + /** + * Verify Cross Site Request Forgery Protection + * + * @access public + * @return null + */ + function csrf_verify() + { + // If no POST data exists we will set the CSRF cookie + if (count($_POST) == 0) + { + return $this->csrf_set_cookie(); + } + + // Do the tokens exist in both the _POST and _COOKIE arrays? + if ( ! isset($_POST[$this->csrf_token_name]) OR ! isset($_COOKIE[$this->csrf_token_name])) + { + $this->csrf_show_error(); + } + + // Do the tokens match? + if ($_POST[$this->csrf_token_name] != $_COOKIE[$this->csrf_token_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]); + + log_message('debug', "CSRF token verified "); + } + + // -------------------------------------------------------------------- + + /** + * Set Cross Site Request Forgery Protection Cookie + * + * @access public + * @return null + */ + function csrf_set_cookie() + { + $prefix = ( ! is_string(config_item('cookie_prefix'))) ? '' : config_item('cookie_prefix'); + + $expire = time() + $this->csrf_expire; + + setcookie($prefix.$this->csrf_token_name, $this->csrf_hash, $expire, config_item('cookie_path'), config_item('cookie_domain'), 0); + + log_message('debug', "CRSF cookie Set"); + } + + // -------------------------------------------------------------------- + + /** + * Set Cross Site Request Forgery Protection Cookie + * + * @access public + * @return null + */ + 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_token_name]) AND $_COOKIE[$this->csrf_token_name] != '') + { + $this->csrf_hash = $_COOKIE[$this->csrf_token_name]; + } + else + { + $this->csrf_hash = md5(uniqid(rand(), TRUE)); + } + } + + return $this->csrf_hash; + } + + // -------------------------------------------------------------------- + + /** + * Show CSRF Error + * + * @access public + * @return null + */ + function csrf_show_error() + { + show_error('The action you have requested is not allowed.'); + } + + // -------------------------------------------------------------------- + + /** + * 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 + * + * @access public + * @param mixed string or array + * @return string + */ + 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 = $this->_remove_invisible_characters($str); + + /* + * Protect GET variables in URLs + */ + + // 901119URL5918AMP18930PROTECT8198 + + $str = preg_replace('|\&([a-z\_0-9\-]+)\=([a-z\_0-9\-]+)|i', $this->xss_hash()."\\1=\\2", $str); + + /* + * Validate standard character entities + * + * Add a semicolon if missing. We do this to enable + * the conversion of entities to ASCII later. + * + */ + $str = preg_replace('#(&\#?[0-9a-z]{2,})([\x00-\x20])*;?#i', "\\1;\\2", $str); + + /* + * Validate UTF16 two byte encoding (x00) + * + * Just as above, adds a semicolon if missing. + * + */ + $str = preg_replace('#(&\#x?)([0-9A-F]+);?#i',"\\1\\2;",$str); + + /* + * Un-Protect GET variables in URLs + */ + $str = str_replace($this->xss_hash(), '&', $str); + + /* + * URL Decode + * + * Just in case stuff like this is submitted: + * + * Google + * + * Note: Use rawurldecode() so it does not remove plus signs + * + */ + $str = rawurldecode($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-z]+=([\'\"]).*?\\1/si", array($this, '_convert_attribute'), $str); + + $str = preg_replace_callback("/<\w+.*?(?=>|<|$)/si", array($this, '_decode_entity'), $str); + + /* + * Remove Invisible Characters Again! + */ + $str = $this->_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. + * + */ + + if (strpos($str, "\t") !== FALSE) + { + $str = str_replace("\t", ' ', $str); + } + + /* + * Capture converted string for later comparison + */ + $converted_string = $str; + + /* + * Not Allowed Under Any Conditions + */ + + foreach ($this->never_allowed_str as $key => $val) + { + $str = str_replace($key, $val, $str); + } + + foreach ($this->never_allowed_regex as $key => $val) + { + $str = preg_replace("#".$key."#i", $val, $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', 'script', 'applet', 'alert', 'document', 'write', 'cookie', 'window'); + foreach ($words as $word) + { + $temp = ''; + + for ($i = 0, $wordlen = strlen($word); $i < $wordlen; $i++) + { + $temp .= substr($word, $i, 1)."\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($temp, 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 for PHP5, but it is dog slow compared + * to these simplified non-capturing preg_match(), especially if the pattern exists in the string + */ + 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/i", $str) OR preg_match("/xss/i", $str)) + { + $str = preg_replace("#<(/*)(script|xss)(.*?)\>#si", '[removed]', $str); + } + } + while($original != $str); + + unset($original); + + /* + * Remove JavaScript Event Handlers + * + * Note: This code is a little blunt. It removes + * the event handler and anything up to the closing >, + * but it's unlikely to be a problem. + * + */ + $event_handlers = array('[^a-z_\-]on\w*','xmlns'); + + if ($is_image === TRUE) + { + /* + * Adobe Photoshop puts XML metadata into JFIF images, including namespacing, + * so we have to allow this for images. -Paul + */ + unset($event_handlers[array_search('xmlns', $event_handlers)]); + } + + $str = preg_replace("#<([^><]+?)(".implode('|', $event_handlers).")(\s*=\s*[^><]*)([><]*)#i", "<\\1\\4", $str); + + /* + * 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|applet|audio|basefont|base|behavior|bgsound|blink|body|embed|expression|form|frameset|frame|head|html|ilayer|iframe|input|isindex|layer|link|meta|object|plaintext|style|script|textarea|title|video|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|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 + * + */ + foreach ($this->never_allowed_str as $key => $val) + { + $str = str_replace($key, $val, $str); + } + + foreach ($this->never_allowed_regex as $key => $val) + { + $str = preg_replace("#".$key."#i", $val, $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) + { + if ($str == $converted_string) + { + return TRUE; + } + else + { + return FALSE; + } + } + + log_message('debug', "XSS Filtering completed"); + return $str; + } + + // -------------------------------------------------------------------- + + /** + * Random Hash for protecting URLs + * + * @access public + * @return string + */ + function xss_hash() + { + if ($this->xss_hash == '') + { + if (phpversion() >= 4.2) + mt_srand(); + else + mt_srand(hexdec(substr(md5(microtime()), -8)) & 0x7fffffff); + + $this->xss_hash = md5(time() + mt_rand(0, 1999999999)); + } + + return $this->xss_hash; + } + + // -------------------------------------------------------------------- + + /** + * Remove Invisible Characters + * + * This prevents sandwiching null characters + * between ascii characters, like Java\0script. + * + * @access public + * @param string + * @return string + */ + function _remove_invisible_characters($str) + { + static $non_displayables; + + if ( ! isset($non_displayables)) + { + // every control character except newline (dec 10), carriage return (dec 13), and horizontal tab (dec 09), + $non_displayables = array( + '/%0[0-8bcef]/', // url encoded 00-08, 11, 12, 14, 15 + '/%1[0-9a-f]/', // url encoded 16-31 + '/[\x00-\x08]/', // 00-08 + '/\x0b/', '/\x0c/', // 11, 12 + '/[\x0e-\x1f]/' // 14-31 + ); + } + + do + { + $cleaned = $str; + $str = preg_replace($non_displayables, '', $str); + } + while ($cleaned != $str); + + return $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 + * + * @access public + * @param type + * @return type + */ + function _compact_exploded_words($matches) + { + return preg_replace('/\s+/s', '', $matches[1]).$matches[2]; + } + + // -------------------------------------------------------------------- + + /** + * Sanitize Naughty HTML + * + * Callback function for xss_clean() to remove naughty HTML elements + * + * @access private + * @param array + * @return string + */ + function _sanitize_naughty_html($matches) + { + // encode opening brace + $str = '<'.$matches[1].$matches[2].$matches[3]; + + // encode captured opening or closing brace to prevent recursive vectors + $str .= str_replace(array('>', '<'), array('>', '<'), $matches[4]); + + return $str; + } + + // -------------------------------------------------------------------- + + /** + * 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 + * + * @access private + * @param array + * @return string + */ + function _js_link_removal($match) + { + $attributes = $this->_filter_attributes(str_replace(array('<', '>'), '', $match[1])); + return str_replace($match[1], preg_replace("#href=.*?(alert\(|alert&\#40;|javascript\:|charset\=|window\.|document\.|\.cookie|_filter_attributes(str_replace(array('<', '>'), '', $match[1])); + return str_replace($match[1], preg_replace("#src=.*?(alert\(|alert&\#40;|javascript\:|charset\=|window\.|document\.|\.cookie|', '<', '\\'), array('>', '<', '\\\\'), $match[0]); + } + + // -------------------------------------------------------------------- + + /** + * Filter Attributes + * + * Filters tag attributes for consistency and safety + * + * @access public + * @param string + * @return string + */ + 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 + * + * @access public + * @param array + * @return string + */ + function _decode_entity($match) + { + $CI =& get_instance(); + $CI->load->helper('typography'); + return entity_decode($match[0], strtoupper($CI->config->item('charset'))); + } + + // -------------------------------------------------------------------- + + /** + * Filename Security + * + * @access public + * @param string + * @return string + */ + function sanitize_filename($str) + { + $bad = array( + "../", + "./", + "", + "<", + ">", + "'", + '"', + '&', + '$', + '#', + '{', + '}', + '[', + ']', + '=', + ';', + '?', + '/', + "%20", + "%22", + "%3c", // < + "%253c", // < + "%3e", // > + "%0e", // > + "%28", // ( + "%29", // ) + "%2528", // ( + "%26", // & + "%24", // $ + "%3f", // ? + "%3b", // ; + "%3d" // = + ); + + return stripslashes(str_replace($bad, '', $str)); + } + +} +// END Security Class + +/* End of file Security.php */ +/* Location: ./system/libraries/Security.php */ \ No newline at end of file -- cgit v1.2.3-24-g4f1b From 7b5b0e2d4000fadabcdad894538e42c23ebb9ecd Mon Sep 17 00:00:00 2001 From: Derek Jones Date: Tue, 2 Mar 2010 22:48:53 -0600 Subject: expanded abilities of Table library --- system/libraries/Table.php | 138 +++++++++++++++++++++++++++++++++++++-------- 1 file changed, 113 insertions(+), 25 deletions(-) (limited to 'system') diff --git a/system/libraries/Table.php b/system/libraries/Table.php index 6d36121f2..1f920ea9e 100644 --- a/system/libraries/Table.php +++ b/system/libraries/Table.php @@ -35,7 +35,7 @@ class CI_Table { var $template = NULL; var $newline = "\n"; var $empty_cells = ""; - + var $function = FALSE; function CI_Table() { @@ -75,7 +75,7 @@ class CI_Table { function set_heading() { $args = func_get_args(); - $this->heading = (is_array($args[0])) ? $args[0] : $args; + $this->heading = $this->_prep_args($args); } // -------------------------------------------------------------------- @@ -110,7 +110,7 @@ class CI_Table { $new = array(); while(count($array) > 0) { - $temp = array_splice($array, 0, $col_limit); + $temp = array_splice($array, 0, $col_limit); if (count($temp) < $col_limit) { @@ -156,11 +156,59 @@ class CI_Table { function add_row() { $args = func_get_args(); - $this->rows[] = (is_array($args[0])) ? $args[0] : $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 * @@ -208,7 +256,9 @@ class CI_Table { // 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']; @@ -225,23 +275,40 @@ class CI_Table { // 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; + $out .= $this->newline; foreach($this->heading as $heading) { - $out .= $this->template['heading_cell_start']; - $out .= $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->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) { @@ -258,15 +325,33 @@ class CI_Table { foreach($row as $cell) { - $out .= $this->template['cell_'.$name.'start']; + $temp = $this->template['cell_'.$name.'start']; + + foreach ($cell as $key => $val) + { + if ($key != 'data') + { + $temp = str_replace('empty_cells; } else { - $out .= $cell; + if ($function !== FALSE && is_callable($function)) + { + $out .= $function($cell); + } + else + { + $out .= $cell; + } } $out .= $this->template['cell_'.$name.'end']; @@ -275,6 +360,9 @@ class CI_Table { $out .= $this->template['row_'.$name.'end']; $out .= $this->newline; } + + $out .= $this->template['tbody_close']; + $out .= $this->newline; } $out .= $this->template['table_close']; @@ -321,7 +409,7 @@ class CI_Table { return FALSE; } - $this->heading = $query->list_fields(); + $this->heading = $this->_prep_args($query->list_fields()); } // Next blast through the result array and build out the rows @@ -330,7 +418,7 @@ class CI_Table { { foreach ($query->result_array() as $row) { - $this->rows[] = $row; + $this->rows[] = $this->_prep_args($row); } } } @@ -353,21 +441,15 @@ class CI_Table { $i = 0; foreach ($data as $row) - { - if ( ! is_array($row)) - { - $this->rows[] = $data; - break; - } - + { // 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 = $row; + $this->heading = $this->_prep_args($row); } else { - $this->rows[] = $row; + $this->rows[] = $this->_prep_args($row); } $i++; @@ -391,7 +473,7 @@ class CI_Table { } $this->temp = $this->_default_template(); - foreach (array('table_open','heading_row_start', 'heading_row_end', 'heading_cell_start', 'heading_cell_end', 'row_start', 'row_end', 'cell_start', 'cell_end', 'row_alt_start', 'row_alt_end', 'cell_alt_start', 'cell_alt_end', 'table_close') as $val) + 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])) { @@ -412,12 +494,18 @@ class CI_Table { { return array ( 'table_open' => '
    ".$header."  ".$val."
    ', - + + 'thead_open' => '', + 'thead_close' => '', + 'heading_row_start' => '', 'heading_row_end' => '', 'heading_cell_start' => '', + 'tbody_open' => '', + 'tbody_close' => '', + 'row_start' => '', 'row_end' => '', 'cell_start' => '
    ', 'heading_cell_end' => '
    ', -- cgit v1.2.3-24-g4f1b From 5052e27db22d41c5d01c65d03ad515041def63a3 Mon Sep 17 00:00:00 2001 From: Derek Jones Date: Tue, 2 Mar 2010 22:53:38 -0600 Subject: changing casing on some booleans --- system/libraries/Trackback.php | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) (limited to 'system') diff --git a/system/libraries/Trackback.php b/system/libraries/Trackback.php index 9b1737c5f..a604c0b2d 100644 --- a/system/libraries/Trackback.php +++ b/system/libraries/Trackback.php @@ -128,7 +128,7 @@ class CI_Trackback { * Receive Trackback Data * * This function simply validates the incoming TB data. - * It returns false on failure and true on success. + * 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. * @@ -221,7 +221,7 @@ class CI_Trackback { * Process Trackback * * Opens a socket connection and passes the data to - * the server. Returns true on success, false on failure + * the server. Returns TRUE on success, FALSE on failure * * @access public * @param string @@ -267,6 +267,7 @@ class CI_Trackback { } @fclose($fp); + if (stristr($this->response, '0') === FALSE) { $message = 'An unknown error was encountered'; @@ -383,7 +384,7 @@ class CI_Trackback { if ( ! preg_match ("/^([0-9]+)$/", $tb_id)) { - return false; + return FALSE; } else { @@ -436,7 +437,7 @@ class CI_Trackback { { return $str; } - + $str = preg_replace("/\s+/", ' ', str_replace(array("\r\n", "\r", "\n"), ' ', $str)); if (strlen($str) <= $n) -- cgit v1.2.3-24-g4f1b From e12f64e70fad08c02668ab2fda00cd5d56b8116b Mon Sep 17 00:00:00 2001 From: Derek Jones Date: Tue, 2 Mar 2010 22:55:08 -0600 Subject: updating Upload features and use of security library --- system/libraries/Upload.php | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) (limited to 'system') diff --git a/system/libraries/Upload.php b/system/libraries/Upload.php index 5ff478269..ac9323c08 100644 --- a/system/libraries/Upload.php +++ b/system/libraries/Upload.php @@ -454,6 +454,11 @@ class CI_Upload { */ function set_allowed_types($types) { + if ( ! is_array($types) && $types == '*') + { + $this->allowed_types = '*'; + return; + } $this->allowed_types = explode('|', $types); } @@ -551,6 +556,11 @@ class CI_Upload { */ function is_allowed_filetype() { + if ($this->allowed_types == '*') + { + return TRUE; + } + if (count($this->allowed_types) == 0 OR ! is_array($this->allowed_types)) { $this->set_error('upload_no_file_types'); @@ -805,7 +815,7 @@ class CI_Upload { } $CI =& get_instance(); - $data = $CI->input->xss_clean($data); + $data = $CI->security->xss_clean($data); flock($fp, LOCK_EX); fwrite($fp, $data); -- cgit v1.2.3-24-g4f1b From a9647e8ed7eb19ca55e84fba9c5ee62e0045881d Mon Sep 17 00:00:00 2001 From: Derek Jones Date: Tue, 2 Mar 2010 22:59:07 -0600 Subject: updating XMLRPC class to use Security lib --- system/libraries/Xmlrpc.php | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) (limited to 'system') diff --git a/system/libraries/Xmlrpc.php b/system/libraries/Xmlrpc.php index 5a82391dd..c46d52cdb 100644 --- a/system/libraries/Xmlrpc.php +++ b/system/libraries/Xmlrpc.php @@ -513,7 +513,7 @@ class XML_RPC_Response } else { - $array[$key] = $CI->input->xss_clean($array[$key]); + $array[$key] = $CI->security->xss_clean($array[$key]); } } @@ -529,7 +529,7 @@ class XML_RPC_Response } else { - $result = $CI->input->xss_clean($result); + $result = $CI->security->xss_clean($result); } } @@ -1127,7 +1127,9 @@ class XML_RPC_Message extends CI_Xmlrpc } else { - $array[$key] = $CI->input->xss_clean($array[$key]); + // 'bits' is for the MetaWeblog API image bits + // @todo - this needs to be made more general purpose + $array[$key] = ($key == 'bits') ? $array[$key] : $CI->security->xss_clean($array[$key]); } } @@ -1147,7 +1149,7 @@ class XML_RPC_Message extends CI_Xmlrpc } else { - $parameters[] = $CI->input->xss_clean($a_param); + $parameters[] = $CI->security->xss_clean($a_param); } } } @@ -1322,7 +1324,7 @@ class XML_RPC_Values extends CI_Xmlrpc function serializedata($typ, $val) { $rs = ''; - + switch($this->xmlrpcTypes[$typ]) { case 3: -- cgit v1.2.3-24-g4f1b From c4c34ee996bfa583b45484b4bc7bbd7dc036bb29 Mon Sep 17 00:00:00 2001 From: Derek Jones Date: Tue, 2 Mar 2010 23:00:28 -0600 Subject: whitespace --- system/libraries/Xmlrpcs.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'system') diff --git a/system/libraries/Xmlrpcs.php b/system/libraries/Xmlrpcs.php index 429ab8472..fe1c99bf5 100644 --- a/system/libraries/Xmlrpcs.php +++ b/system/libraries/Xmlrpcs.php @@ -40,10 +40,10 @@ class CI_Xmlrpcs extends CI_Xmlrpc var $debug_msg = ''; // Debug Message var $system_methods = array(); // XML RPC Server methods var $controller_obj; - - var $object = FALSE; - + var $object = FALSE; + + //------------------------------------- // Constructor, more or less //------------------------------------- -- cgit v1.2.3-24-g4f1b From 22224b513bf5dcb3f34798f0a9568049966d7ee8 Mon Sep 17 00:00:00 2001 From: Derek Jones Date: Tue, 2 Mar 2010 23:06:53 -0600 Subject: modified cookie helper to use input class --- system/helpers/cookie_helper.php | 43 +--------------------------------------- 1 file changed, 1 insertion(+), 42 deletions(-) (limited to 'system') diff --git a/system/helpers/cookie_helper.php b/system/helpers/cookie_helper.php index 40afadb57..4be371efe 100644 --- a/system/helpers/cookie_helper.php +++ b/system/helpers/cookie_helper.php @@ -46,50 +46,9 @@ if ( ! function_exists('set_cookie')) { function set_cookie($name = '', $value = '', $expire = '', $domain = '', $path = '/', $prefix = '') { - if (is_array($name)) - { - foreach (array('value', 'expire', 'domain', 'path', 'prefix', 'name') as $item) - { - if (isset($name[$item])) - { - $$item = $name[$item]; - } - } - } - // Set the config file options $CI =& get_instance(); - - if ($prefix == '' AND $CI->config->item('cookie_prefix') != '') - { - $prefix = $CI->config->item('cookie_prefix'); - } - if ($domain == '' AND $CI->config->item('cookie_domain') != '') - { - $domain = $CI->config->item('cookie_domain'); - } - if ($path == '/' AND $CI->config->item('cookie_path') != '/') - { - $path = $CI->config->item('cookie_path'); - } - - if ( ! is_numeric($expire)) - { - $expire = time() - 86500; - } - else - { - if ($expire > 0) - { - $expire = time() + $expire; - } - else - { - $expire = 0; - } - } - - setcookie($prefix.$name, $value, $expire, $path, $domain, 0); + $CI->input->set_cookie($name, $value, $expire, $domain, $path, $prefix); } } -- cgit v1.2.3-24-g4f1b From 626d39f92bb9185ea85daafd6679529d054b85ab Mon Sep 17 00:00:00 2001 From: Derek Jones Date: Tue, 2 Mar 2010 23:14:56 -0600 Subject: code comments fix --- system/helpers/file_helper.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'system') diff --git a/system/helpers/file_helper.php b/system/helpers/file_helper.php index 2be06ac4f..274c4ad37 100644 --- a/system/helpers/file_helper.php +++ b/system/helpers/file_helper.php @@ -125,7 +125,7 @@ if ( ! function_exists('delete_files')) if ( ! $current_dir = @opendir($path)) { - return TRUE; + return FALSE; } while(FALSE !== ($filename = @readdir($current_dir))) @@ -218,7 +218,7 @@ if ( ! function_exists('get_filenames')) * * @access public * @param string path to source - * @param bool whether to include the path as part of the filename + * @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 */ -- cgit v1.2.3-24-g4f1b From aacfe480da6859cd74b70884de34d987c6682267 Mon Sep 17 00:00:00 2001 From: Greg Aker Date: Wed, 3 Mar 2010 12:26:31 -0600 Subject: Moving Jquery library to javascript/Jquery.php --- system/libraries/Javascript.php | 2 +- system/libraries/Jquery.php | 1071 -------------------------------- system/libraries/javascript/Jquery.php | 1071 ++++++++++++++++++++++++++++++++ 3 files changed, 1072 insertions(+), 1072 deletions(-) delete mode 100644 system/libraries/Jquery.php create mode 100644 system/libraries/javascript/Jquery.php (limited to 'system') diff --git a/system/libraries/Javascript.php b/system/libraries/Javascript.php index 3b7dcc6ff..af85e6509 100644 --- a/system/libraries/Javascript.php +++ b/system/libraries/Javascript.php @@ -23,7 +23,7 @@ class CI_Javascript { $this->CI =& get_instance(); // load the requested js library - $this->CI->load->library($js_library_driver, array('autoload' => $autoload)); + $this->CI->load->library('javsacript/'.$js_library_driver, array('autoload' => $autoload)); // make js to refer to current library $this->js =& $this->CI->$js_library_driver; diff --git a/system/libraries/Jquery.php b/system/libraries/Jquery.php deleted file mode 100644 index c63a74239..000000000 --- a/system/libraries/Jquery.php +++ /dev/null @@ -1,1071 +0,0 @@ -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; - } - -} - -/* End of file Jquery.php */ -/* Location: ./system/libraries/Jquery.php */ \ No newline at end of file diff --git a/system/libraries/javascript/Jquery.php b/system/libraries/javascript/Jquery.php new file mode 100644 index 000000000..f6b8dce69 --- /dev/null +++ b/system/libraries/javascript/Jquery.php @@ -0,0 +1,1071 @@ +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; + } + +} + +/* End of file Jquery.php */ +/* Location: ./system/libraries/Jquery.php */ \ No newline at end of file -- cgit v1.2.3-24-g4f1b From 9d653edd03fcc325e94a2c9da36eb250f2a8f889 Mon Sep 17 00:00:00 2001 From: Derek Jones Date: Fri, 5 Mar 2010 09:52:53 -0600 Subject: fixing docblock for Javascript class --- system/libraries/Javascript.php | 36 ++++++++++++++++++++++++++++++------ 1 file changed, 30 insertions(+), 6 deletions(-) (limited to 'system') diff --git a/system/libraries/Javascript.php b/system/libraries/Javascript.php index af85e6509..efaaab4bf 100644 --- a/system/libraries/Javascript.php +++ b/system/libraries/Javascript.php @@ -1,13 +1,35 @@ 'jquery', 'autoload' => TRUE); foreach ($defaults as $key => $val) @@ -23,7 +45,7 @@ class CI_Javascript { $this->CI =& get_instance(); // load the requested js library - $this->CI->load->library('javsacript/'.$js_library_driver, array('autoload' => $autoload)); + $this->CI->load->library('javascript/'.$js_library_driver, array('autoload' => $autoload)); // make js to refer to current library $this->js =& $this->CI->$js_library_driver; @@ -840,8 +862,10 @@ class CI_Javascript { return $result; } } + + // -------------------------------------------------------------------- } - +// END Javascript Class /* End of file Javascript.php */ /* Location: ./system/libraries/Javascript.php */ \ No newline at end of file -- cgit v1.2.3-24-g4f1b From 36591099aa01107294f8b2794351b078b7575a25 Mon Sep 17 00:00:00 2001 From: Derek Jones Date: Fri, 5 Mar 2010 10:05:51 -0600 Subject: little cleaner regex in human_to_unix() --- system/helpers/date_helper.php | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'system') diff --git a/system/helpers/date_helper.php b/system/helpers/date_helper.php index 0e9781666..2c60f0302 100644 --- a/system/helpers/date_helper.php +++ b/system/helpers/date_helper.php @@ -288,7 +288,7 @@ if ( ! function_exists('days_in_month')) return $days_in_month[$month - 1]; } } - + // ------------------------------------------------------------------------ /** @@ -343,7 +343,7 @@ if ( ! function_exists('gmt_to_local')) return $time; } } - + // ------------------------------------------------------------------------ /** @@ -440,14 +440,14 @@ if ( ! function_exists('human_to_unix')) } $datestr = trim($datestr); - $datestr = preg_replace("/\040+/", "\040", $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 = preg_split("/\040/", $datestr); + + $split = explode(' ', $datestr); $ex = explode("-", $split['0']); -- cgit v1.2.3-24-g4f1b From 68788d5577d9f101220e3e6e8fba0829feb136de Mon Sep 17 00:00:00 2001 From: Derek Jones Date: Fri, 5 Mar 2010 10:11:31 -0600 Subject: bringing form helper in sync --- system/helpers/form_helper.php | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) (limited to 'system') diff --git a/system/helpers/form_helper.php b/system/helpers/form_helper.php index 60d2631e9..5feb3ce66 100644 --- a/system/helpers/form_helper.php +++ b/system/helpers/form_helper.php @@ -66,7 +66,6 @@ if ( ! function_exists('form_open')) } } - // ------------------------------------------------------------------------ /** @@ -266,7 +265,7 @@ if ( ! function_exists('form_textarea')) * @param string * @return type */ -if (! function_exists('form_multiselect')) +if ( ! function_exists('form_multiselect')) { function form_multiselect($name = '', $options = array(), $selected = array(), $extra = '') { @@ -320,7 +319,7 @@ if ( ! function_exists('form_dropdown')) { $key = (string) $key; - if (is_array($val)) + if (is_array($val) && ! empty($val)) { $form .= ''."\n"; @@ -638,7 +637,7 @@ if ( ! function_exists('form_prep')) if ($field_name != '') { - $prepped_fields[$field_name] = $str; + $prepped_fields[$field_name] = $field_name; } return $str; -- cgit v1.2.3-24-g4f1b From d4433348afe653a0472cbe4d023db883fd142d11 Mon Sep 17 00:00:00 2001 From: Derek Jones Date: Fri, 5 Mar 2010 10:13:55 -0600 Subject: whitespace --- system/helpers/number_helper.php | 1 - 1 file changed, 1 deletion(-) (limited to 'system') diff --git a/system/helpers/number_helper.php b/system/helpers/number_helper.php index 1fdd30326..f7979215c 100644 --- a/system/helpers/number_helper.php +++ b/system/helpers/number_helper.php @@ -72,6 +72,5 @@ if ( ! function_exists('byte_format')) } - /* End of file number_helper.php */ /* Location: ./system/helpers/number_helper.php */ \ No newline at end of file -- cgit v1.2.3-24-g4f1b From 11b1e51f8df7a1e47d002a14a76748f6f629f988 Mon Sep 17 00:00:00 2001 From: Derek Jones Date: Fri, 5 Mar 2010 10:22:44 -0600 Subject: no in helpers, updated security lib to use Security class instead of Input --- system/helpers/security_helper.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'system') diff --git a/system/helpers/security_helper.php b/system/helpers/security_helper.php index 1f0a62906..654cfd100 100644 --- a/system/helpers/security_helper.php +++ b/system/helpers/security_helper.php @@ -40,7 +40,7 @@ if ( ! function_exists('xss_clean')) function xss_clean($str, $is_image = FALSE) { $CI =& get_instance(); - return $CI->input->xss_clean($str, $is_image); + return $CI->security->xss_clean($str, $is_image); } } @@ -56,7 +56,7 @@ if ( ! function_exists('dohash')) { function dohash($str, $type = 'sha1') { - return $this->do_hash($str, $type); + return do_hash($str, $type); } } -- cgit v1.2.3-24-g4f1b From 48822fa77cd02a7974a56cf92d989aefbd98e9af Mon Sep 17 00:00:00 2001 From: Derek Jones Date: Fri, 5 Mar 2010 10:23:39 -0600 Subject: updating attributes to lowercase and added CDATA block around js --- system/helpers/smiley_helper.php | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) (limited to 'system') diff --git a/system/helpers/smiley_helper.php b/system/helpers/smiley_helper.php index 931f1308d..775cc1b99 100644 --- a/system/helpers/smiley_helper.php +++ b/system/helpers/smiley_helper.php @@ -68,7 +68,6 @@ if ( ! function_exists('smiley_js')) $m = '{'.implode(',', $m).'}'; $r .= <<'.$r.''; + return ''; } } @@ -159,7 +158,7 @@ if ( ! function_exists('get_clickable_smileys')) continue; } - $link[] = "\"".$smileys[$key][3]."\""; + $link[] = "\"".$smileys[$key][3]."\""; $used[$smileys[$key][0]] = TRUE; } -- cgit v1.2.3-24-g4f1b From 1e1419229ea85b9928f2b0f7d2bad1f5cefc3946 Mon Sep 17 00:00:00 2001 From: Derek Jones Date: Fri, 5 Mar 2010 10:24:50 -0600 Subject: whitespace, code comments --- system/helpers/string_helper.php | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) (limited to 'system') diff --git a/system/helpers/string_helper.php b/system/helpers/string_helper.php index 4767f0b5f..60f6ed171 100644 --- a/system/helpers/string_helper.php +++ b/system/helpers/string_helper.php @@ -30,7 +30,7 @@ /** * Trim Slashes * - * Removes any leading/traling slashes from a string: + * Removes any leading/trailing slashes from a string: * * /this/that/theother/ * @@ -46,10 +46,10 @@ if ( ! function_exists('trim_slashes')) { function trim_slashes($str) { - return trim($str, '/'); - } + return trim($str, '/'); + } } - + // ------------------------------------------------------------------------ /** @@ -120,6 +120,7 @@ if ( ! function_exists('quotes_to_entities')) } // ------------------------------------------------------------------------ + /** * Reduce Double Slashes * @@ -143,7 +144,7 @@ if ( ! function_exists('reduce_double_slashes')) return preg_replace("#(^|[^:])//+#", "\\1/", $str); } } - + // ------------------------------------------------------------------------ /** @@ -173,7 +174,7 @@ if ( ! function_exists('reduce_multiples')) { $str = trim($str, $character); } - + return $str; } } @@ -238,6 +239,7 @@ if ( ! function_exists('random_string')) } } } + // ------------------------------------------------------------------------ /** -- cgit v1.2.3-24-g4f1b From daf9c01a2c25515eea87fb4f4c905f49c30d0214 Mon Sep 17 00:00:00 2001 From: Derek Jones Date: Fri, 5 Mar 2010 10:29:30 -0600 Subject: added convert_accented_characters() function to Text Helper --- system/application/config/foreign_chars.php | 64 +++++++++++++++++++++++++++++ system/helpers/text_helper.php | 48 +++++++++++++++++++--- 2 files changed, 107 insertions(+), 5 deletions(-) create mode 100644 system/application/config/foreign_chars.php (limited to 'system') diff --git a/system/application/config/foreign_chars.php b/system/application/config/foreign_chars.php new file mode 100644 index 000000000..8d70a2f62 --- /dev/null +++ b/system/application/config/foreign_chars.php @@ -0,0 +1,64 @@ + "ss", // ß + '224' => "a", + '225' => "a", + '226' => "a", + '229' => "a", + '227' => "ae", + '230' => "ae", + '228' => "ae", + '231' => "c", + '232' => "e", // è + '233' => "e", // é + '234' => "e", // ê + '235' => "e", // ë + '236' => "i", + '237' => "i", + '238' => "i", + '239' => "i", + '241' => "n", + '242' => "o", + '243' => "o", + '244' => "o", + '245' => "o", + '246' => "oe", // ö + '249' => "u", + '250' => "u", + '251' => "u", + '252' => "ue", // ü + '255' => "y", + '257' => "aa", + '269' => "ch", + '275' => "ee", + '291' => "gj", + '299' => "ii", + '311' => "kj", + '316' => "lj", + '326' => "nj", + '353' => "sh", + '363' => "uu", + '382' => "zh", + '256' => "aa", + '268' => "ch", + '274' => "ee", + '290' => "gj", + '298' => "ii", + '310' => "kj", + '315' => "lj", + '325' => "nj", + '352' => "sh", + '362' => "uu", + '381' => "zh", + ); + + +/* End of file foreign_chars.php */ +/* Location: ./system/application/config/foreign_chars.php */ \ No newline at end of file diff --git a/system/helpers/text_helper.php b/system/helpers/text_helper.php index 1e672937b..477260216 100644 --- a/system/helpers/text_helper.php +++ b/system/helpers/text_helper.php @@ -87,7 +87,7 @@ if ( ! function_exists('character_limiter')) { return $str; } - + $out = ""; foreach (explode(' ', trim($str)) as $val) { @@ -136,7 +136,7 @@ if ( ! function_exists('ascii_to_entities')) $out .= '&#'.array_shift($temp).';'; $count = 1; } - + $out .= $str[$i]; } else @@ -248,7 +248,7 @@ if ( ! function_exists('word_censor')) // \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 bookended by any of these characters. + // a bad word will be bookeneded by any of these characters. $delim = '[-_\'\"`(){}<>\[\]|!?@#%&,.:;^~*+=\/ 0-9\n\r\t]'; foreach ($censored as $badword) @@ -352,6 +352,44 @@ if ( ! function_exists('highlight_phrase')) return $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($match) + { + if ( ! file_exists(APPPATH.'config/foreign_chars'.EXT)) + { + return $match; + } + + include APPPATH.'config/foreign_chars'.EXT; + + if ( ! isset($foreign_characters)) + { + return $match; + } + + $ord = ord($match['1']); + + if (isset($foreign_characters[$ord])) + { + return $foreign_characters[$ord]; + } + else + { + return $match['1']; + } + } +} // ------------------------------------------------------------------------ @@ -431,7 +469,7 @@ if ( ! function_exists('word_wrap')) // word into smaller chunks so we'll add it back to our current line if ($temp != '') { - $output .= $temp . "\n" . $line; + $output .= $temp."\n".$line; } else { @@ -456,7 +494,7 @@ if ( ! function_exists('word_wrap')) return $output; } } - + /* End of file text_helper.php */ /* Location: ./system/helpers/text_helper.php */ \ No newline at end of file -- cgit v1.2.3-24-g4f1b From 2b7de06bd0e2184c9bffc971490f7f640c736a6a Mon Sep 17 00:00:00 2001 From: Derek Jones Date: Fri, 5 Mar 2010 10:31:08 -0600 Subject: added entity_decode() to Typography helper, updated auto_typography() --- system/helpers/typography_helper.php | 59 ++++++++++++++++++++++++++++++++++-- 1 file changed, 57 insertions(+), 2 deletions(-) (limited to 'system') diff --git a/system/helpers/typography_helper.php b/system/helpers/typography_helper.php index 5621e6dd0..712b57509 100644 --- a/system/helpers/typography_helper.php +++ b/system/helpers/typography_helper.php @@ -54,16 +54,71 @@ if ( ! function_exists('nl2br_except_pre')) * * @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, $reduce_linebreaks = FALSE) + 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, $reduce_linebreaks); + return $CI->typography->auto_typography($str, $strip_js_event_handlers, $reduce_linebreaks); + } +} + + +// -------------------------------------------------------------------- + +/** + * HTML Entities Decode + * + * This function is a replacement for html_entity_decode() + * + * In some versions of PHP the native function does not work + * when UTF-8 is the specified character set, so this gives us + * a work-around. More info here: + * http://bugs.php.net/bug.php?id=25670 + * + * NOTE: html_entity_decode() has a bug in some PHP versions when UTF-8 is the + * character set, and the PHP developers said they were not back porting the + * fix to versions other than PHP 5.x. + * + * @access public + * @param string + * @return string + */ +if ( ! function_exists('entity_decode')) +{ + function entity_decode($str, $charset='UTF-8') + { + if (stristr($str, '&') === FALSE) return $str; + + // 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. + + if (function_exists('html_entity_decode') && (strtolower($charset) != 'utf-8' OR version_compare(phpversion(), '5.0.0', '>='))) + { + $str = html_entity_decode($str, ENT_COMPAT, $charset); + $str = preg_replace('~&#x(0*[0-9a-f]{2,5})~ei', 'chr(hexdec("\\1"))', $str); + return preg_replace('~&#([0-9]{2,4})~e', 'chr(\\1)', $str); + } + + // Numeric Entities + $str = preg_replace('~&#x(0*[0-9a-f]{2,5});{0,1}~ei', 'chr(hexdec("\\1"))', $str); + $str = preg_replace('~&#([0-9]{2,4});{0,1}~e', 'chr(\\1)', $str); + + // Literal Entities - Slightly slow so we do another check + if (stristr($str, '&') === FALSE) + { + $str = strtr($str, array_flip(get_html_translation_table(HTML_ENTITIES))); + } + + return $str; } } -- cgit v1.2.3-24-g4f1b From 85b2bb7df5e5308b5283e24a3d83aadd1fa9d4de Mon Sep 17 00:00:00 2001 From: Derek Jones Date: Fri, 5 Mar 2010 10:32:03 -0600 Subject: improved xml_convert() of XML helper --- system/helpers/xml_helper.php | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) (limited to 'system') diff --git a/system/helpers/xml_helper.php b/system/helpers/xml_helper.php index 712f6777e..09b7aee49 100644 --- a/system/helpers/xml_helper.php +++ b/system/helpers/xml_helper.php @@ -36,25 +36,33 @@ */ if ( ! function_exists('xml_convert')) { - function xml_convert($str) + function xml_convert($str, $protect_all = FALSE) { $temp = '__TEMP_AMPERSANDS__'; // Replace entities to temporary markers so that - // ampersands won't get messed up + // ampersands won't get messed up $str = preg_replace("/&#(\d+);/", "$temp\\1;", $str); - $str = preg_replace("/&(\w+);/", "$temp\\1;", $str); + + if ($protect_all === TRUE) + { + $str = preg_replace("/&(\w+);/", "$temp\\1;", $str); + } $str = str_replace(array("&","<",">","\"", "'", "-"), - array("&", "<", ">", """, "'", "-"), - $str); + array("&", "<", ">", """, "'", "-"), + $str); // Decode the temp markers back to entities $str = preg_replace("/$temp(\d+);/","&#\\1;",$str); - $str = preg_replace("/$temp(\w+);/","&\\1;", $str); - + + if ($protect_all === TRUE) + { + $str = preg_replace("/$temp(\w+);/","&\\1;", $str); + } + return $str; - } + } } -- cgit v1.2.3-24-g4f1b From 99111e3abe02e9a40795fa96f33ea08e492eadcd Mon Sep 17 00:00:00 2001 From: Derek Jones Date: Fri, 5 Mar 2010 10:39:08 -0600 Subject: added end of function marker --- system/helpers/xml_helper.php | 1 + 1 file changed, 1 insertion(+) (limited to 'system') diff --git a/system/helpers/xml_helper.php b/system/helpers/xml_helper.php index 09b7aee49..56f5e0112 100644 --- a/system/helpers/xml_helper.php +++ b/system/helpers/xml_helper.php @@ -65,6 +65,7 @@ if ( ! function_exists('xml_convert')) } } +// ------------------------------------------------------------------------ /* End of file xml_helper.php */ /* Location: ./system/helpers/xml_helper.php */ \ No newline at end of file -- cgit v1.2.3-24-g4f1b From b41032d2df1e63566f1183533b388372538c46d0 Mon Sep 17 00:00:00 2001 From: Derek Jones Date: Fri, 5 Mar 2010 11:22:45 -0600 Subject: moved CAPTCHA plugin to a helper --- system/helpers/captcha_helper.php | 246 ++++++++++++++++++++++++++ system/plugins/captcha_pi.php | 355 -------------------------------------- 2 files changed, 246 insertions(+), 355 deletions(-) create mode 100644 system/helpers/captcha_helper.php delete mode 100644 system/plugins/captcha_pi.php (limited to 'system') diff --git a/system/helpers/captcha_helper.php b/system/helpers/captcha_helper.php new file mode 100644 index 000000000..a58789219 --- /dev/null +++ b/system/helpers/captcha_helper.php @@ -0,0 +1,246 @@ + '', '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); + } +} + +// ------------------------------------------------------------------------ + +/* End of file captcha_pi.php */ +/* Location: ./system/plugins/captcha_pi.php */ \ No newline at end of file diff --git a/system/plugins/captcha_pi.php b/system/plugins/captcha_pi.php deleted file mode 100644 index 7092f28e1..000000000 --- a/system/plugins/captcha_pi.php +++ /dev/null @@ -1,355 +0,0 @@ -load->plugin('captcha'); - -Once loaded you can generate a captcha like this: - - $vals = array( - 'word' => 'Random word', - 'img_path' => './captcha/', - 'img_url' => 'http://example.com/captcha/', - 'font_path' => './path/to/fonts/texb.ttf', - 'img_width' => '150', - 'img_height' => 30, - 'expiration' => 7200 - ); - - $cap = create_captcha($vals); - echo $cap['image']; - - -NOTES: - - The captcha function requires the GD image library. - - Only the img_path and img_url are required. - - If a "word" is not supplied, the function will generate a random - ASCII string. You might put together your own word library that - you can draw randomly from. - - If you do not specify a path to a TRUE TYPE font, the native ugly GD - font will be used. - - The "captcha" folder must be writable (666, or 777) - - The "expiration" (in seconds) signifies how long an image will - remain in the captcha folder before it will be deleted. The default - is two hours. - -RETURNED DATA - -The create_captcha() function returns an associative array with this data: - - [array] - ( - 'image' => IMAGE TAG - 'time' => TIMESTAMP (in microtime) - 'word' => CAPTCHA WORD - ) - -The "image" is the actual image tag: - - -The "time" is the micro timestamp used as the image name without the file -extension. It will be a number like this: 1139612155.3422 - -The "word" is the word that appears in the captcha image, which if not -supplied to the function, will be a random string. - - -ADDING A DATABASE - -In order for the captcha function to prevent someone from posting, you will need -to add the information returned from create_captcha() function to your database. -Then, when the data from the form is submitted by the user you will need to verify -that the data exists in the database and has not expired. - -Here is a table prototype: - - CREATE TABLE captcha ( - captcha_id bigint(13) unsigned NOT NULL auto_increment, - captcha_time int(10) unsigned NOT NULL, - ip_address varchar(16) default '0' NOT NULL, - word varchar(20) NOT NULL, - PRIMARY KEY `captcha_id` (`captcha_id`), - KEY `word` (`word`) - ) - - -Here is an example of usage with a DB. - -On the page where the captcha will be shown you'll have something like this: - - $this->load->plugin('captcha'); - $vals = array( - 'img_path' => './captcha/', - 'img_url' => 'http://example.com/captcha/' - ); - - $cap = create_captcha($vals); - - $data = array( - 'captcha_time' => $cap['time'], - 'ip_address' => $this->input->ip_address(), - 'word' => $cap['word'] - ); - - $query = $this->db->insert_string('captcha', $data); - $this->db->query($query); - - echo 'Submit the word you see below:'; - echo $cap['image']; - echo ''; - - -Then, on the page that accepts the submission you'll have something like this: - - // First, delete old captchas - $expiration = time()-7200; // Two hour limit - $this->db->query("DELETE FROM captcha WHERE captcha_time < ".$expiration); - - // Then see if a captcha exists: - $sql = "SELECT COUNT(*) AS count FROM captcha WHERE word = ? AND ip_address = ? AND date > ?"; - $binds = array($_POST['captcha'], $this->input->ip_address(), $expiration); - $query = $this->db->query($sql, $binds); - $row = $query->row(); - - if ($row->count == 0) - { - echo "You must submit the word that appears in the image"; - } - -*/ - - - -/** -|========================================================== -| Create Captcha -|========================================================== -| -*/ -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); - - 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); -} - - -/* End of file captcha_pi.php */ -/* Location: ./system/plugins/captcha_pi.php */ \ No newline at end of file -- cgit v1.2.3-24-g4f1b From 1c73f4e9a1b8d33e7eeda622b9ae44b9b2f41251 Mon Sep 17 00:00:00 2001 From: Derek Jones Date: Fri, 5 Mar 2010 11:27:41 -0600 Subject: fixed eof code comment --- system/helpers/captcha_helper.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'system') diff --git a/system/helpers/captcha_helper.php b/system/helpers/captcha_helper.php index a58789219..67db50947 100644 --- a/system/helpers/captcha_helper.php +++ b/system/helpers/captcha_helper.php @@ -242,5 +242,5 @@ if ( ! function_exists('create_captcha')) // ------------------------------------------------------------------------ -/* End of file captcha_pi.php */ -/* Location: ./system/plugins/captcha_pi.php */ \ No newline at end of file +/* End of file captcha_helper.php */ +/* Location: ./system/heleprs/captcha_helper.php */ \ No newline at end of file -- cgit v1.2.3-24-g4f1b From bb76839b9a2679475399420eaaf56ca7a2e49d39 Mon Sep 17 00:00:00 2001 From: Derek Jones Date: Fri, 5 Mar 2010 11:32:53 -0600 Subject: killing scaffolding trigger --- system/application/config/routes.php | 11 +---------- 1 file changed, 1 insertion(+), 10 deletions(-) (limited to 'system') diff --git a/system/application/config/routes.php b/system/application/config/routes.php index c2f1e99dd..4d9f340a5 100644 --- a/system/application/config/routes.php +++ b/system/application/config/routes.php @@ -23,25 +23,16 @@ | RESERVED ROUTES | ------------------------------------------------------------------------- | -| There are two reserved routes: +| There is one reserved routes: | | $route['default_controller'] = 'welcome'; | | This route indicates which controller class should be loaded if the | URI contains no data. In the above example, the "welcome" class | would be loaded. -| -| $route['scaffolding_trigger'] = 'scaffolding'; -| -| This route lets you set a "secret" word that will trigger the -| scaffolding feature for added security. Note: Scaffolding must be -| enabled in the controller in which you intend to use it. The reserved -| routes must come before any wildcard or regular expression routes. -| */ $route['default_controller'] = "welcome"; -$route['scaffolding_trigger'] = ""; /* End of file routes.php */ -- cgit v1.2.3-24-g4f1b From e659fbbffd63d019b1a3753a8e3b3dd74e1cb225 Mon Sep 17 00:00:00 2001 From: Derek Jones Date: Fri, 5 Mar 2010 11:34:09 -0600 Subject: moving js cal plugin to a helper --- system/helpers/js_calendar_helper.php | 629 ++++++++++++++++++++++++++++++++++ system/plugins/js_calendar_pi.php | 629 ---------------------------------- 2 files changed, 629 insertions(+), 629 deletions(-) create mode 100644 system/helpers/js_calendar_helper.php delete mode 100644 system/plugins/js_calendar_pi.php (limited to 'system') diff --git a/system/helpers/js_calendar_helper.php b/system/helpers/js_calendar_helper.php new file mode 100644 index 000000000..f722777b3 --- /dev/null +++ b/system/helpers/js_calendar_helper.php @@ -0,0 +1,629 @@ +load->plugin('js_calendar'); + +Once loaded you'll add the calendar script to the of your page like this: + + + +The above function will be passed the name of your form. + +Then to show the actual calendar you'll do this: + + +
    + +

    Today

    +
    + + +Note: The first parameter is the name of the field containing your date, the second parameter contains the "now" time, +and the third tells the calendar whether to highlight the current day or not. + +Lastly, you'll need some CSS for your calendar: + +.calendar { + border: 1px #6975A3 solid; + background-color: transparent; +} +.calheading { + background-color: #7C8BC0; + color: #fff; + font-family: Lucida Grande, Verdana, Geneva, Sans-serif; + font-size: 11px; + font-weight: bold; + text-align: center; +} +.calnavleft { + background-color: #7C8BC0; + font-family: Lucida Grande, Verdana, Geneva, Sans-serif; + font-size: 10px; + font-weight: bold; + color: #fff; + padding: 4px; + cursor: pointer; +} +.calnavright { + background-color: #7C8BC0; + font-family: Lucida Grande, Verdana, Geneva, Sans-serif; + font-size: 10px; + font-weight: bold; + color: #fff; + text-align: right; + padding: 4px; + cursor: pointer; +} +.caldayheading { + background-color: #000; + color: #fff; + font-family: Lucida Grande, Verdana, Geneva, Sans-serif; + font-size: 10px; + text-align: center; + padding: 6px 2px 6px 2px; +} +.caldaycells{ + color: #000; + background-color: #D1D7E6; + font-family: Lucida Grande, Verdana, Geneva, Sans-serif; + font-size: 11px; + text-align: center; + padding: 4px; + border: 1px #E0E5F1 solid; + cursor: pointer; +} +.caldaycellhover{ + color: #fff; + background-color: #B3BCD4; + font-family: Lucida Grande, Verdana, Geneva, Sans-serif; + font-size: 11px; + text-align: center; + padding: 4px; + border: 1px #B3BCD4 solid; + cursor: pointer; +} +.caldayselected{ + background-color: #737FAC; + color: #fff; + font-family: Lucida Grande, Verdana, Geneva, Sans-serif; + font-size: 11px; + font-weight: bold; + text-align: center; + border: 1px #566188 solid; + padding: 3px; + cursor: pointer; +} +.calblanktop { + background-color: #fff; + padding: 4px; +} +.calblankbot { + background-color: #fff; + padding: 4px; +} + + +*/ + +function js_calendar_script($form_name = 'entryform') +{ +$CI =& get_instance(); +$CI->load->language('calendar'); +ob_start(); +?> + + + var '.$field_id.' = new calendar("'.$field_id.'", '.$time.', '.(($highlight == TRUE) ? 'true' : 'false').'); + document.write('.$field_id.'.write()); + '; +} + + +/* End of file js_calendar_pi.php */ +/* Location: ./system/plugins/js_calendar_pi.php */ \ No newline at end of file diff --git a/system/plugins/js_calendar_pi.php b/system/plugins/js_calendar_pi.php deleted file mode 100644 index f722777b3..000000000 --- a/system/plugins/js_calendar_pi.php +++ /dev/null @@ -1,629 +0,0 @@ -load->plugin('js_calendar'); - -Once loaded you'll add the calendar script to the of your page like this: - - - -The above function will be passed the name of your form. - -Then to show the actual calendar you'll do this: - - -
    - -

    Today

    -
    - - -Note: The first parameter is the name of the field containing your date, the second parameter contains the "now" time, -and the third tells the calendar whether to highlight the current day or not. - -Lastly, you'll need some CSS for your calendar: - -.calendar { - border: 1px #6975A3 solid; - background-color: transparent; -} -.calheading { - background-color: #7C8BC0; - color: #fff; - font-family: Lucida Grande, Verdana, Geneva, Sans-serif; - font-size: 11px; - font-weight: bold; - text-align: center; -} -.calnavleft { - background-color: #7C8BC0; - font-family: Lucida Grande, Verdana, Geneva, Sans-serif; - font-size: 10px; - font-weight: bold; - color: #fff; - padding: 4px; - cursor: pointer; -} -.calnavright { - background-color: #7C8BC0; - font-family: Lucida Grande, Verdana, Geneva, Sans-serif; - font-size: 10px; - font-weight: bold; - color: #fff; - text-align: right; - padding: 4px; - cursor: pointer; -} -.caldayheading { - background-color: #000; - color: #fff; - font-family: Lucida Grande, Verdana, Geneva, Sans-serif; - font-size: 10px; - text-align: center; - padding: 6px 2px 6px 2px; -} -.caldaycells{ - color: #000; - background-color: #D1D7E6; - font-family: Lucida Grande, Verdana, Geneva, Sans-serif; - font-size: 11px; - text-align: center; - padding: 4px; - border: 1px #E0E5F1 solid; - cursor: pointer; -} -.caldaycellhover{ - color: #fff; - background-color: #B3BCD4; - font-family: Lucida Grande, Verdana, Geneva, Sans-serif; - font-size: 11px; - text-align: center; - padding: 4px; - border: 1px #B3BCD4 solid; - cursor: pointer; -} -.caldayselected{ - background-color: #737FAC; - color: #fff; - font-family: Lucida Grande, Verdana, Geneva, Sans-serif; - font-size: 11px; - font-weight: bold; - text-align: center; - border: 1px #566188 solid; - padding: 3px; - cursor: pointer; -} -.calblanktop { - background-color: #fff; - padding: 4px; -} -.calblankbot { - background-color: #fff; - padding: 4px; -} - - -*/ - -function js_calendar_script($form_name = 'entryform') -{ -$CI =& get_instance(); -$CI->load->language('calendar'); -ob_start(); -?> - - - var '.$field_id.' = new calendar("'.$field_id.'", '.$time.', '.(($highlight == TRUE) ? 'true' : 'false').'); - document.write('.$field_id.'.write()); - '; -} - - -/* End of file js_calendar_pi.php */ -/* Location: ./system/plugins/js_calendar_pi.php */ \ No newline at end of file -- cgit v1.2.3-24-g4f1b From b6de7d13eb06d7736d255eaa0b60391a4d2b4bf5 Mon Sep 17 00:00:00 2001 From: Derek Jones Date: Fri, 5 Mar 2010 11:34:34 -0600 Subject: REMOVING js calendar helper / plugin. No need with the prolific jQuery calendars --- system/helpers/js_calendar_helper.php | 629 ---------------------------------- 1 file changed, 629 deletions(-) delete mode 100644 system/helpers/js_calendar_helper.php (limited to 'system') diff --git a/system/helpers/js_calendar_helper.php b/system/helpers/js_calendar_helper.php deleted file mode 100644 index f722777b3..000000000 --- a/system/helpers/js_calendar_helper.php +++ /dev/null @@ -1,629 +0,0 @@ -load->plugin('js_calendar'); - -Once loaded you'll add the calendar script to the of your page like this: - - - -The above function will be passed the name of your form. - -Then to show the actual calendar you'll do this: - - -
    - -

    Today

    -
    - - -Note: The first parameter is the name of the field containing your date, the second parameter contains the "now" time, -and the third tells the calendar whether to highlight the current day or not. - -Lastly, you'll need some CSS for your calendar: - -.calendar { - border: 1px #6975A3 solid; - background-color: transparent; -} -.calheading { - background-color: #7C8BC0; - color: #fff; - font-family: Lucida Grande, Verdana, Geneva, Sans-serif; - font-size: 11px; - font-weight: bold; - text-align: center; -} -.calnavleft { - background-color: #7C8BC0; - font-family: Lucida Grande, Verdana, Geneva, Sans-serif; - font-size: 10px; - font-weight: bold; - color: #fff; - padding: 4px; - cursor: pointer; -} -.calnavright { - background-color: #7C8BC0; - font-family: Lucida Grande, Verdana, Geneva, Sans-serif; - font-size: 10px; - font-weight: bold; - color: #fff; - text-align: right; - padding: 4px; - cursor: pointer; -} -.caldayheading { - background-color: #000; - color: #fff; - font-family: Lucida Grande, Verdana, Geneva, Sans-serif; - font-size: 10px; - text-align: center; - padding: 6px 2px 6px 2px; -} -.caldaycells{ - color: #000; - background-color: #D1D7E6; - font-family: Lucida Grande, Verdana, Geneva, Sans-serif; - font-size: 11px; - text-align: center; - padding: 4px; - border: 1px #E0E5F1 solid; - cursor: pointer; -} -.caldaycellhover{ - color: #fff; - background-color: #B3BCD4; - font-family: Lucida Grande, Verdana, Geneva, Sans-serif; - font-size: 11px; - text-align: center; - padding: 4px; - border: 1px #B3BCD4 solid; - cursor: pointer; -} -.caldayselected{ - background-color: #737FAC; - color: #fff; - font-family: Lucida Grande, Verdana, Geneva, Sans-serif; - font-size: 11px; - font-weight: bold; - text-align: center; - border: 1px #566188 solid; - padding: 3px; - cursor: pointer; -} -.calblanktop { - background-color: #fff; - padding: 4px; -} -.calblankbot { - background-color: #fff; - padding: 4px; -} - - -*/ - -function js_calendar_script($form_name = 'entryform') -{ -$CI =& get_instance(); -$CI->load->language('calendar'); -ob_start(); -?> - - - var '.$field_id.' = new calendar("'.$field_id.'", '.$time.', '.(($highlight == TRUE) ? 'true' : 'false').'); - document.write('.$field_id.'.write()); - '; -} - - -/* End of file js_calendar_pi.php */ -/* Location: ./system/plugins/js_calendar_pi.php */ \ No newline at end of file -- cgit v1.2.3-24-g4f1b From 8dca04163a79701021043fcd3e267a5d965af993 Mon Sep 17 00:00:00 2001 From: Derek Jones Date: Fri, 5 Mar 2010 13:01:44 -0600 Subject: added Driver lib --- system/core/Loader.php | 23 +++++ system/libraries/Driver.php | 232 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 255 insertions(+) create mode 100644 system/libraries/Driver.php (limited to 'system') diff --git a/system/core/Loader.php b/system/core/Loader.php index f70ee0334..c399f296d 100644 --- a/system/core/Loader.php +++ b/system/core/Loader.php @@ -543,6 +543,29 @@ class CI_Loader { // -------------------------------------------------------------------- + /** + * 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 + */ + 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_once BASEPATH.'libraries/Driver'.EXT; + } + + return $this->library($library, $params, $object_name); + } + + // -------------------------------------------------------------------- + /** * Add Package Path * diff --git a/system/libraries/Driver.php b/system/libraries/Driver.php new file mode 100644 index 000000000..07ef2e724 --- /dev/null +++ b/system/libraries/Driver.php @@ -0,0 +1,232 @@ +lib_name)) + { + $this->lib_name = get_class($this); + } + + // The class will be prefixed with the parent lib + $child_class = $this->lib_name.'_'.$child; + + if (in_array(strtolower($child_class), 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 (array(APPPATH, BASEPATH) as $path) + { + // and check for case sensitivity of both the parent and child libs + foreach (array(ucfirst($this->lib_name), strtolower($this->lib_name)) as $lib) + { + // loves me some nesting! + foreach (array(ucfirst($child_class), strtolower($child_class)) as $class) + { + $filepath = $path.'libraries/'.$this->lib_name.'/drivers/'.$child_class.EXT; + + 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); + } + + // -------------------------------------------------------------------- + +} +// END CI_Driver_Library CLASS + + +/** + * CodeIgniter Driver Class + * + * 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 + * @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 + * + * @access public + * @param object + * @return void + */ + 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 + * + * @access public + * @param string + * @return mixed + */ + 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 + * + * @access public + * @param string + * @param array + * @return mixed + */ + function __set($var, $val) + { + if (in_array($var, $this->properties)) + { + $this->parent->$var = $val; + } + } + + // -------------------------------------------------------------------- + +} +// END CI_Driver CLASS + +/* End of file Driver.php */ +/* Location: ./system/libraries/Driver.php */ \ No newline at end of file -- cgit v1.2.3-24-g4f1b From c64ca0128ab0cc015ed37d1833bd79ee63e35eba Mon Sep 17 00:00:00 2001 From: Derek Jones Date: Sun, 7 Mar 2010 07:55:56 -0600 Subject: fixed load_class() call in Hooks to get Config from core --- system/core/Hooks.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system') diff --git a/system/core/Hooks.php b/system/core/Hooks.php index 5e017ccb7..3b063f792 100644 --- a/system/core/Hooks.php +++ b/system/core/Hooks.php @@ -52,7 +52,7 @@ class CI_Hooks { */ function _initialize() { - $CFG =& load_class('Config'); + $CFG =& load_class('Config', 'core'); // If hooks are not enabled in the config file // there is nothing else to do -- cgit v1.2.3-24-g4f1b From d5e0cb5fe94fb7a89cc12842511481a3c3d37d8e Mon Sep 17 00:00:00 2001 From: Derek Jones Date: Tue, 9 Mar 2010 20:20:46 -0600 Subject: sped up Driver loading slightly by predicting subfolder location --- system/core/Loader.php | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) (limited to 'system') diff --git a/system/core/Loader.php b/system/core/Loader.php index c399f296d..1726f0a53 100644 --- a/system/core/Loader.php +++ b/system/core/Loader.php @@ -558,7 +558,14 @@ class CI_Loader { if ( ! class_exists('CI_Driver_Library')) { // we aren't instantiating an object here, that'll be done by the Library itself - require_once BASEPATH.'libraries/Driver'.EXT; + require BASEPATH.'libraries/Driver'.EXT; + } + + // 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 = $library.'/'.$library; } return $this->library($library, $params, $object_name); -- cgit v1.2.3-24-g4f1b From c6da50384e06c60e242cb4442abb9c6c9b450674 Mon Sep 17 00:00:00 2001 From: Derek Jones Date: Tue, 9 Mar 2010 20:44:27 -0600 Subject: completely removed Plugins from CodeIgniter --- system/application/config/autoload.php | 19 ++-------- system/core/Loader.php | 67 ++-------------------------------- system/plugins/index.html | 10 ----- 3 files changed, 7 insertions(+), 89 deletions(-) delete mode 100644 system/plugins/index.html (limited to 'system') diff --git a/system/application/config/autoload.php b/system/application/config/autoload.php index 1745d5cae..e7c6f0db1 100644 --- a/system/application/config/autoload.php +++ b/system/application/config/autoload.php @@ -20,10 +20,9 @@ | | 1. Libraries | 2. Helper files -| 3. Plugins -| 4. Custom config files -| 5. Language files -| 6. Models +| 3. Custom config files +| 4. Language files +| 5. Models | */ @@ -54,18 +53,6 @@ $autoload['libraries'] = array(); $autoload['helper'] = array(); -/* -| ------------------------------------------------------------------- -| Auto-load Plugins -| ------------------------------------------------------------------- -| Prototype: -| -| $autoload['plugin'] = array('captcha', 'js_calendar'); -*/ - -$autoload['plugin'] = array(); - - /* | ------------------------------------------------------------------- | Auto-load Config files diff --git a/system/core/Loader.php b/system/core/Loader.php index 1726f0a53..976823f81 100644 --- a/system/core/Loader.php +++ b/system/core/Loader.php @@ -41,7 +41,6 @@ class CI_Loader { var $_ci_loaded_files = array(); var $_ci_models = array(); var $_ci_helpers = array(); - var $_ci_plugins = array(); var $_ci_varmap = array('unit_test' => 'unit', 'user_agent' => 'agent'); @@ -445,64 +444,6 @@ class CI_Loader { // -------------------------------------------------------------------- - /** - * Load Plugin - * - * This function loads the specified plugin. - * - * @access public - * @param array - * @return void - */ - function plugin($plugins = array()) - { - foreach ($this->_ci_prep_filename($plugins, '_pi') as $plugin) - { - if (isset($this->_ci_plugins[$plugin])) - { - continue; - } - - if (file_exists(APPPATH.'plugins/'.$plugin.EXT)) - { - include_once(APPPATH.'plugins/'.$plugin.EXT); - } - else - { - if (file_exists(BASEPATH.'plugins/'.$plugin.EXT)) - { - include_once(BASEPATH.'plugins/'.$plugin.EXT); - } - else - { - show_error('Unable to load the requested file: plugins/'.$plugin.EXT); - } - } - - $this->_ci_plugins[$plugin] = TRUE; - log_message('debug', 'Plugin loaded: '.$plugin); - } - } - - // -------------------------------------------------------------------- - - /** - * Load Plugins - * - * This is simply an alias to the above function in case the - * user has written the plural form of this function. - * - * @access public - * @param array - * @return void - */ - function plugins($plugins = array()) - { - $this->plugin($plugins); - } - - // -------------------------------------------------------------------- - /** * Loads a language file * @@ -987,7 +928,7 @@ class CI_Loader { * Autoloader * * The config/autoload.php file contains an array that permits sub-systems, - * libraries, plugins, and helpers to be loaded automatically. + * libraries, and helpers to be loaded automatically. * * @access private * @param array @@ -1012,8 +953,8 @@ class CI_Loader { } } - // Autoload plugins, helpers and languages - foreach (array('helper', 'plugin', 'language') as $type) + // Autoload helpers and languages + foreach (array('helper', 'language') as $type) { if (isset($autoload[$type]) AND count($autoload[$type]) > 0) { @@ -1058,7 +999,7 @@ class CI_Loader { /** * Assign to Models * - * Makes sure that anything loaded by the loader class (libraries, plugins, etc.) + * Makes sure that anything loaded by the loader class (libraries, etc.) * will be available to models, if any exist. * * @access private diff --git a/system/plugins/index.html b/system/plugins/index.html deleted file mode 100644 index c942a79ce..000000000 --- a/system/plugins/index.html +++ /dev/null @@ -1,10 +0,0 @@ - - - 403 Forbidden - - - -

    Directory access is forbidden.

    - - - \ No newline at end of file -- cgit v1.2.3-24-g4f1b From ee71c80dd20bcfc60169af3eb1f628229ca30d67 Mon Sep 17 00:00:00 2001 From: Derek Jones Date: Wed, 10 Mar 2010 10:05:05 -0600 Subject: added ability to enable/disable individual sections of the Profiler --- system/application/config/profiler.php | 17 +++++++ system/core/Output.php | 28 +++++++++++- system/language/english/profiler_lang.php | 1 + system/libraries/Profiler.php | 74 ++++++++++++++++++++++++++----- 4 files changed, 108 insertions(+), 12 deletions(-) create mode 100644 system/application/config/profiler.php (limited to 'system') diff --git a/system/application/config/profiler.php b/system/application/config/profiler.php new file mode 100644 index 000000000..f30432d9a --- /dev/null +++ b/system/application/config/profiler.php @@ -0,0 +1,17 @@ +enable_profiler = (is_bool($val)) ? $val : TRUE; } + // -------------------------------------------------------------------- + + /** + * 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; + } + } + // -------------------------------------------------------------------- /** @@ -258,7 +279,12 @@ class CI_Output { 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)) diff --git a/system/language/english/profiler_lang.php b/system/language/english/profiler_lang.php index bf2183004..7876331f9 100644 --- a/system/language/english/profiler_lang.php +++ b/system/language/english/profiler_lang.php @@ -16,6 +16,7 @@ $lang['profiler_no_post'] = 'No POST data exists'; $lang['profiler_no_get'] = 'No GET data exists'; $lang['profiler_no_uri'] = 'No URI data exists'; $lang['profiler_no_memory'] = 'Memory Usage Unavailable'; +$lang['profiler_no_profiles'] = 'No Profile data - all Profiler sections have been disabled.'; /* End of file profiler_lang.php */ /* Location: ./system/language/english/profiler_lang.php */ \ No newline at end of file diff --git a/system/libraries/Profiler.php b/system/libraries/Profiler.php index bf20f1722..b2c008fc0 100644 --- a/system/libraries/Profiler.php +++ b/system/libraries/Profiler.php @@ -34,14 +34,59 @@ class CI_Profiler { var $CI; - function CI_Profiler() + var $_available_sections = array( + 'benchmarks', + 'config', + 'controller_info', + 'get', + 'http_headers', + 'memory_usage', + 'post', + 'queries', + 'uri_string' + ); + + function CI_Profiler($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); } // -------------------------------------------------------------------- + /** + * Set Sections + * + * Sets the private _compile_* properties to enable/disable Profiler sections + * + * @access public + * @param mixed + * @return void + */ + 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 * @@ -49,7 +94,7 @@ class CI_Profiler { * 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 - * + * @PHP4 - all methods should be declared private * @access private * @return array */ @@ -438,16 +483,23 @@ class CI_Profiler { 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++; + } + } - $output .= $this->_compile_uri_string(); - $output .= $this->_compile_controller_info(); - $output .= $this->_compile_memory_usage(); - $output .= $this->_compile_benchmarks(); - $output .= $this->_compile_get(); - $output .= $this->_compile_post(); - $output .= $this->_compile_queries(); - $output .= $this->_compile_config(); - $output .= $this->_compile_http_headers(); + if ($fields_displayed == 0) + { + $output .= '

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

    '; + } + $output .= '
    '; return $output; -- cgit v1.2.3-24-g4f1b From ad1171a6797dc0054381327fb26a9e9e232a639e Mon Sep 17 00:00:00 2001 From: Derek Jones Date: Wed, 10 Mar 2010 14:18:38 -0600 Subject: added swap_pre, autoinit, and stricton database configuration explanations --- system/application/config/database.php | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'system') diff --git a/system/application/config/database.php b/system/application/config/database.php index 28dfff5c9..fcdefda71 100644 --- a/system/application/config/database.php +++ b/system/application/config/database.php @@ -26,6 +26,8 @@ | ['cachedir'] The path to the folder where cache files should be stored | ['char_set'] The character set used in communicating with the database | ['dbcollat'] The character collation used in communicating with the database +| ['swap_pre'] A default table prefix that should be swapped with the dbprefix +| ['autoinit'] Whether or not to automatically initialize the database. | ['stricton'] TRUE/FALSE - forces "Strict Mode" connections | - good for ensuring strict SQL while developing | @@ -51,6 +53,8 @@ $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; -- cgit v1.2.3-24-g4f1b From 2ede2f6e8e9f2cde7402a88906d091011f7885ec Mon Sep 17 00:00:00 2001 From: Derek Jones Date: Wed, 10 Mar 2010 15:00:18 -0600 Subject: added docs for application Packages, added third_party folder to the application folder --- system/application/third_party/index.html | 10 ++++++++++ 1 file changed, 10 insertions(+) create mode 100644 system/application/third_party/index.html (limited to 'system') diff --git a/system/application/third_party/index.html b/system/application/third_party/index.html new file mode 100644 index 000000000..c942a79ce --- /dev/null +++ b/system/application/third_party/index.html @@ -0,0 +1,10 @@ + + + 403 Forbidden + + + +

    Directory access is forbidden.

    + + + \ No newline at end of file -- cgit v1.2.3-24-g4f1b From cf579558fa8c1e20af748146e4fe196d7c772c34 Mon Sep 17 00:00:00 2001 From: Derek Jones Date: Thu, 11 Mar 2010 09:13:34 -0600 Subject: full on scaffolding removal --- system/database/DB_active_rec.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'system') diff --git a/system/database/DB_active_rec.php b/system/database/DB_active_rec.php index 88690a8f9..3e9923e6f 100644 --- a/system/database/DB_active_rec.php +++ b/system/database/DB_active_rec.php @@ -1916,7 +1916,7 @@ class CI_DB_active_record extends CI_DB_driver { foreach (get_object_vars($object) as $key => $val) { // There are some built in keys we need to ignore for this conversion - if ( ! is_object($val) && ! is_array($val) && $key != '_parent_name' && $key != '_ci_scaffolding' && $key != '_ci_scaff_table') + if ( ! is_object($val) && ! is_array($val) && $key != '_parent_name') { $array[$key] = $val; } @@ -1950,7 +1950,7 @@ class CI_DB_active_record extends CI_DB_driver { foreach ($fields as $val) { // There are some built in keys we need to ignore for this conversion - if ($val != '_parent_name' && $val != '_ci_scaffolding' && $val != '_ci_scaff_table') + if ($val != '_parent_name') { $i = 0; -- cgit v1.2.3-24-g4f1b From fc5c7e5e89d1ac8a84555b8d3971f14533abde03 Mon Sep 17 00:00:00 2001 From: Derek Jones Date: Thu, 11 Mar 2010 10:29:13 -0600 Subject: added @php4 tag to compat helper (thanks Phil) --- system/helpers/compatibility_helper.php | 1 + 1 file changed, 1 insertion(+) (limited to 'system') diff --git a/system/helpers/compatibility_helper.php b/system/helpers/compatibility_helper.php index e7b21c660..4d7d466f5 100644 --- a/system/helpers/compatibility_helper.php +++ b/system/helpers/compatibility_helper.php @@ -25,6 +25,7 @@ * well with CodeIgniter, so those functions have been refactored. * We cheat a little and use CI's _exception_handler() to output our own PHP errors * so that the behavior fully mimicks the PHP 5 counterparts. -- Derek Jones + * @PHP4 * * @package CodeIgniter * @subpackage Helpers -- cgit v1.2.3-24-g4f1b From 4e8d66aeea7f03b75df5a387a54fce1889834ded Mon Sep 17 00:00:00 2001 From: Derek Allard Date: Mon, 15 Mar 2010 12:23:27 -0400 Subject: code comment typo fix --- system/helpers/html_helper.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system') diff --git a/system/helpers/html_helper.php b/system/helpers/html_helper.php index d5bdd080c..4afa678a3 100644 --- a/system/helpers/html_helper.php +++ b/system/helpers/html_helper.php @@ -97,7 +97,7 @@ if ( ! function_exists('ol')) * @param string * @param mixed * @param mixed - * @param intiger + * @param integer * @return string */ if ( ! function_exists('_list')) -- cgit v1.2.3-24-g4f1b From 66a3fc0a7dc6ae84da4a1e852e4458fda7714567 Mon Sep 17 00:00:00 2001 From: Robin Sowell Date: Thu, 18 Mar 2010 09:44:55 -0400 Subject: Added a $xss_clean class variable to the XMLRPC library, enabling control over the use of the Security library's xss_clean() method. --- system/libraries/Xmlrpc.php | 9 +++++---- system/libraries/Xmlrpcs.php | 10 ++++++++++ 2 files changed, 15 insertions(+), 4 deletions(-) (limited to 'system') diff --git a/system/libraries/Xmlrpc.php b/system/libraries/Xmlrpc.php index c46d52cdb..2e0df5c9b 100644 --- a/system/libraries/Xmlrpc.php +++ b/system/libraries/Xmlrpc.php @@ -63,6 +63,7 @@ class CI_Xmlrpc { var $result; var $response = array(); // Response from remote server + var $xss_clean = TRUE; //------------------------------------- // VALUES THAT MULTIPLE CLASSES NEED @@ -513,7 +514,7 @@ class XML_RPC_Response } else { - $array[$key] = $CI->security->xss_clean($array[$key]); + $array[$key] = ($this->xss_clean) ? $CI->security->xss_clean($array[$key]) : $array[$key]; } } @@ -529,7 +530,7 @@ class XML_RPC_Response } else { - $result = $CI->security->xss_clean($result); + $result = ($this->xss_clean) ? $CI->security->xss_clean($result) : $result; } } @@ -1129,7 +1130,7 @@ class XML_RPC_Message extends CI_Xmlrpc { // 'bits' is for the MetaWeblog API image bits // @todo - this needs to be made more general purpose - $array[$key] = ($key == 'bits') ? $array[$key] : $CI->security->xss_clean($array[$key]); + $array[$key] = ($key == 'bits' OR $this->xss_clean == FALSE) ? $array[$key] : $CI->security->xss_clean($array[$key]); } } @@ -1149,7 +1150,7 @@ class XML_RPC_Message extends CI_Xmlrpc } else { - $parameters[] = $CI->security->xss_clean($a_param); + $parameters[] = ($this->xss_clean) ? $CI->security->xss_clean($a_param) : $a_param; } } } diff --git a/system/libraries/Xmlrpcs.php b/system/libraries/Xmlrpcs.php index fe1c99bf5..c1fe649f9 100644 --- a/system/libraries/Xmlrpcs.php +++ b/system/libraries/Xmlrpcs.php @@ -81,6 +81,11 @@ class CI_Xmlrpcs extends CI_Xmlrpc { $this->object = $config['object']; } + + if (isset($config['xss_clean'])) + { + $this->xss_clean = $config['xss_clean']; + } } //------------------------------------- @@ -247,6 +252,11 @@ class CI_Xmlrpcs extends CI_Xmlrpc // 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 //------------------------------------- -- cgit v1.2.3-24-g4f1b From 76b369e191f4432ceba51ba7d7993c4ea54579ae Mon Sep 17 00:00:00 2001 From: Robin Sowell Date: Fri, 19 Mar 2010 11:15:28 -0400 Subject: Changed a few strstr to strpos for consistency w performance guidelines and to mirror EE2. --- system/core/Input.php | 2 +- system/helpers/download_helper.php | 2 +- system/libraries/Email.php | 2 +- system/libraries/Trackback.php | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) (limited to 'system') diff --git a/system/core/Input.php b/system/core/Input.php index 0760dc830..2eef82458 100644 --- a/system/core/Input.php +++ b/system/core/Input.php @@ -288,7 +288,7 @@ class CI_Input { return $this->ip_address; } - if (strstr($this->ip_address, ',')) + if (strpos($this->ip_address, ',') !== FALSE) { $x = explode(',', $this->ip_address); $this->ip_address = trim(end($x)); diff --git a/system/helpers/download_helper.php b/system/helpers/download_helper.php index 638ebaa88..eac024fcb 100644 --- a/system/helpers/download_helper.php +++ b/system/helpers/download_helper.php @@ -71,7 +71,7 @@ if ( ! function_exists('force_download')) } // Generate the server headers - if (strstr($_SERVER['HTTP_USER_AGENT'], "MSIE")) + if (strpos($_SERVER['HTTP_USER_AGENT'], "MSIE") !== FALSE) { header('Content-Type: "'.$mime.'"'); header('Content-Disposition: attachment; filename="'.$filename.'"'); diff --git a/system/libraries/Email.php b/system/libraries/Email.php index 8014bd21e..09d1b8fb9 100644 --- a/system/libraries/Email.php +++ b/system/libraries/Email.php @@ -1865,7 +1865,7 @@ class CI_Email { elseif ($cip) $this->_IP = $cip; elseif ($fip) $this->_IP = $fip; - if (strstr($this->_IP, ',')) + if (strpos($this->_IP, ',') !== FALSE) { $x = explode(',', $this->_IP); $this->_IP = end($x); diff --git a/system/libraries/Trackback.php b/system/libraries/Trackback.php index a604c0b2d..a27914487 100644 --- a/system/libraries/Trackback.php +++ b/system/libraries/Trackback.php @@ -356,7 +356,7 @@ class CI_Trackback { { $tb_id = ""; - if (strstr($url, '?')) + if (strpos($url, '?') !== FALSE) { $tb_array = explode('/', $url); $tb_end = $tb_array[count($tb_array)-1]; -- cgit v1.2.3-24-g4f1b From 5ed19b477072edb77aa4337be71551fae5d9736d Mon Sep 17 00:00:00 2001 From: Greg Aker Date: Fri, 19 Mar 2010 12:13:14 -0500 Subject: Fixed a bug where files created with the Zip Library would result in file creation dates of 1980. Hat tip to JMous for a suggested fix on the forums. --- system/libraries/Zip.php | 60 +++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 49 insertions(+), 11 deletions(-) (limited to 'system') diff --git a/system/libraries/Zip.php b/system/libraries/Zip.php index aae62d74d..2c4bd255d 100644 --- a/system/libraries/Zip.php +++ b/system/libraries/Zip.php @@ -37,10 +37,13 @@ class CI_Zip { var $entries = 0; var $file_num = 0; var $offset = 0; + var $now; function CI_Zip() { log_message('debug', "Zip Compression Class Initialized"); + + $this->now = time(); } // -------------------------------------------------------------------- @@ -63,10 +66,33 @@ class CI_Zip { $dir .= '/'; } - $this->_add_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; + } + // -------------------------------------------------------------------- /** @@ -76,12 +102,14 @@ class CI_Zip { * @param string the directory name * @return void */ - function _add_dir($dir) - { + function _add_dir($dir, $file_mtime, $file_mdate) + { $dir = str_replace("\\", "/", $dir); $this->zipdata .= - "\x50\x4b\x03\x04\x0a\x00\x00\x00\x00\x00\x00\x00\x00\x00" + "\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 @@ -94,7 +122,9 @@ class CI_Zip { .pack('V', 0); // uncompressed filesize $this->directory .= - "\x50\x4b\x01\x02\x00\x00\x0a\x00\x00\x00\x00\x00\x00\x00\x00\x00" + "\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 @@ -126,17 +156,21 @@ class CI_Zip { * @return void */ function add_data($filepath, $data = NULL) - { + { if (is_array($filepath)) { foreach ($filepath as $path => $data) { - $this->_add_data($path, $data); + $file_data = $this->_get_mod_time($path); + + $this->_add_data($path, $data, $file_data['file_mtime'], $file_data['file_mdate']); } } else { - $this->_add_data($filepath, $data); + $file_data = $this->_get_mod_time($filepath); + + $this->_add_data($filepath, $data, $file_data['file_mtime'], $file_data['file_mdate']); } } @@ -150,7 +184,7 @@ class CI_Zip { * @param string the data to be encoded * @return void */ - function _add_data($filepath, $data) + function _add_data($filepath, $data, $file_mtime, $file_mdate) { $filepath = str_replace("\\", "/", $filepath); @@ -162,7 +196,9 @@ class CI_Zip { $compressed_size = strlen($gzdata); $this->zipdata .= - "\x50\x4b\x03\x04\x14\x00\x00\x00\x08\x00\x00\x00\x00\x00" + "\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) @@ -172,7 +208,9 @@ class CI_Zip { .$gzdata; // "file data" segment $this->directory .= - "\x50\x4b\x01\x02\x00\x00\x14\x00\x00\x00\x08\x00\x00\x00\x00\x00" + "\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) -- cgit v1.2.3-24-g4f1b From d99e603f47e10adc015d4b804352db71f0563062 Mon Sep 17 00:00:00 2001 From: Derek Jones Date: Fri, 19 Mar 2010 19:57:33 -0500 Subject: reordered logic in _display_cache() to eliminate a call to is_really_writable() on each page request unless it is_really_needed() --- system/core/Output.php | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) (limited to 'system') diff --git a/system/core/Output.php b/system/core/Output.php index 0dcf2e46f..ac4129405 100644 --- a/system/core/Output.php +++ b/system/core/Output.php @@ -377,12 +377,7 @@ class CI_Output { function _display_cache(&$CFG, &$URI) { $cache_path = ($CFG->item('cache_path') == '') ? BASEPATH.'cache/' : $CFG->item('cache_path'); - - if ( ! is_dir($cache_path) OR ! is_really_writable($cache_path)) - { - return FALSE; - } - + // Build the file path. The file name is an MD5 hash of the full URI $uri = $CFG->item('base_url'). $CFG->item('index_page'). @@ -410,7 +405,7 @@ class CI_Output { flock($fp, LOCK_UN); fclose($fp); - + // Strip out the embedded timestamp if ( ! preg_match("/(\d+TS--->)/", $cache, $match)) { @@ -419,10 +414,13 @@ class CI_Output { // Has the file expired? If so we'll delete it. if (time() >= trim(str_replace('TS--->', '', $match['1']))) - { - @unlink($filepath); - log_message('debug', "Cache file has expired. File deleted"); - return FALSE; + { + if (is_really_writable($cache_path)) + { + @unlink($filepath); + log_message('debug', "Cache file has expired. File deleted"); + return FALSE; + } } // Display the cache -- cgit v1.2.3-24-g4f1b From 3140ad543e26a0aa4e6bc57a3a85ecdb3dfcf0d5 Mon Sep 17 00:00:00 2001 From: Phil Sturgeon Date: Fri, 12 Mar 2010 00:22:42 +0000 Subject: Will check for sub-classes in core or libraries (which the original file is in) instead of always looking in libraries. Makes more sense to have them in the same folder wether in system or application. --- system/core/Common.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'system') diff --git a/system/core/Common.php b/system/core/Common.php index 47293a11b..6e2f72509 100644 --- a/system/core/Common.php +++ b/system/core/Common.php @@ -142,13 +142,13 @@ } // Is the request a class extension? If so we load it too - if (file_exists(APPPATH.'libraries/'.config_item('subclass_prefix').$class.EXT)) + if (file_exists(APPPATH.$directory.'/'.config_item('subclass_prefix').$class.EXT)) { $name = config_item('subclass_prefix').$class; if (class_exists($name) === FALSE) { - require(APPPATH.'libraries/'.config_item('subclass_prefix').$class.EXT); + require(APPPATH.$directory.'/'.config_item('subclass_prefix').$class.EXT); } } -- cgit v1.2.3-24-g4f1b From 726c8eb63eac6f64408536dd39b7854dfa000251 Mon Sep 17 00:00:00 2001 From: Phil Sturgeon Date: Fri, 12 Mar 2010 11:55:51 +0000 Subject: prep_url() will now not append http:// to string if a protocol is already used. That would really mess up itunes://, spotify://, telnet://, etc. --- system/helpers/url_helper.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system') diff --git a/system/helpers/url_helper.php b/system/helpers/url_helper.php index 90ea9207e..86caa278c 100644 --- a/system/helpers/url_helper.php +++ b/system/helpers/url_helper.php @@ -446,7 +446,7 @@ if ( ! function_exists('prep_url')) return ''; } - if (substr($str, 0, 7) != 'http://' && substr($str, 0, 8) != 'https://') + if (!preg_match('/^[a-z]{3,6}:\/\//', $str)) { $str = 'http://'.$str; } -- cgit v1.2.3-24-g4f1b From d265871dfe205a905cd6c39e8ac4371f13848e58 Mon Sep 17 00:00:00 2001 From: Derek Jones Date: Mon, 22 Mar 2010 11:05:01 -0500 Subject: expanded philsturgeon's bugfix to parse_url() and updated docs and changelog --- system/helpers/url_helper.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'system') diff --git a/system/helpers/url_helper.php b/system/helpers/url_helper.php index 86caa278c..7707d6854 100644 --- a/system/helpers/url_helper.php +++ b/system/helpers/url_helper.php @@ -431,7 +431,7 @@ if ( ! function_exists('auto_link')) /** * Prep URL * - * Simply adds the http:// part if missing + * Simply adds the http:// part if no scheme is included * * @access public * @param string the URL @@ -446,7 +446,7 @@ if ( ! function_exists('prep_url')) return ''; } - if (!preg_match('/^[a-z]{3,6}:\/\//', $str)) + if ( ! parse_url($str, PHP_URL_SCHEME)) { $str = 'http://'.$str; } -- cgit v1.2.3-24-g4f1b From 28b293729d2c2917c434c6296eafecd19f397303 Mon Sep 17 00:00:00 2001 From: Phil Sturgeon Date: Fri, 12 Mar 2010 00:43:28 +0000 Subject: Added FTP::download() and the accompanying lang line. This was first proposed in 2007, can we add it now pleeeeease? --- system/language/english/ftp_lang.php | 1 + system/libraries/Ftp.php | 42 ++++++++++++++++++++++++++++++++++++ 2 files changed, 43 insertions(+) (limited to 'system') diff --git a/system/language/english/ftp_lang.php b/system/language/english/ftp_lang.php index 42403b971..392b2b272 100644 --- a/system/language/english/ftp_lang.php +++ b/system/language/english/ftp_lang.php @@ -7,6 +7,7 @@ $lang['ftp_unable_to_makdir'] = "Unable to create the directory you have specif $lang['ftp_unable_to_changedir'] = "Unable to change directories."; $lang['ftp_unable_to_chmod'] = "Unable to set file permissions. Please check your path. Note: This feature is only available in PHP 5 or higher."; $lang['ftp_unable_to_upload'] = "Unable to upload the specified file. Please check your path."; +$lang['ftp_unable_to_download'] = "Unable to download the specified file. Please check your path."; $lang['ftp_no_source_file'] = "Unable to locate the source file. Please check your path."; $lang['ftp_unable_to_rename'] = "Unable to rename the file."; $lang['ftp_unable_to_delete'] = "Unable to delete the file."; diff --git a/system/libraries/Ftp.php b/system/libraries/Ftp.php index 16ad9ad43..07f4b1ff3 100644 --- a/system/libraries/Ftp.php +++ b/system/libraries/Ftp.php @@ -280,6 +280,48 @@ class CI_FTP { // -------------------------------------------------------------------- + /** + * Download a file from a remote server to the local server + * + * @access public + * @param string + * @param string + * @param string + * @return bool + */ + function download($rempath, $locpath, $mode = 'auto') + { + if ( ! $this->_is_conn()) + { + return FALSE; + } + + // Set the mode if not specified + if ($mode == 'auto') + { + // Get the file extension so we can set the upload type + $ext = $this->_getext($rempath); + $mode = $this->_settype($ext); + } + + $mode = ($mode == 'ascii') ? FTP_ASCII : FTP_BINARY; + + $result = @ftp_get($this->conn_id, $locpath, $rempath, $mode); + + if ($result === FALSE) + { + if ($this->debug == TRUE) + { + $this->_error('ftp_unable_to_download'); + } + return FALSE; + } + + return TRUE; + } + + // -------------------------------------------------------------------- + /** * Rename (or move) a file * -- cgit v1.2.3-24-g4f1b From fa281354b37feead98ab71cc4e6d68f9748a7b6c Mon Sep 17 00:00:00 2001 From: Greg Aker Date: Mon, 22 Mar 2010 14:41:27 -0500 Subject: Fix #10 , extending the CodeIgniter controller with MY_Controller will lead to a fatal PHP error. --- system/application/core/index.html | 10 ++++++++++ system/core/CodeIgniter.php | 5 +++++ 2 files changed, 15 insertions(+) create mode 100644 system/application/core/index.html (limited to 'system') diff --git a/system/application/core/index.html b/system/application/core/index.html new file mode 100644 index 000000000..c942a79ce --- /dev/null +++ b/system/application/core/index.html @@ -0,0 +1,10 @@ + + + 403 Forbidden + + + +

    Directory access is forbidden.

    + + + \ No newline at end of file diff --git a/system/core/CodeIgniter.php b/system/core/CodeIgniter.php index 488f9f3ce..295917c92 100644 --- a/system/core/CodeIgniter.php +++ b/system/core/CodeIgniter.php @@ -224,6 +224,11 @@ // Load the base controller class require BASEPATH.'core/Controller'.EXT; + if (file_exists(APPPATH.'core/'.$CFG->config['subclass_prefix'].'Controller'.EXT)) + { + require APPPATH.'core/'.$CFG->config['subclass_prefix'].'Controller'.EXT; + } + // 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. -- cgit v1.2.3-24-g4f1b From f0b3994f51937c643200a0547f70b1fa7d94f88a Mon Sep 17 00:00:00 2001 From: Derek Jones Date: Thu, 25 Mar 2010 10:08:20 -0500 Subject: moved application folder outside of the system folder --- system/application/config/autoload.php | 103 -------- system/application/config/config.php | 329 ------------------------- system/application/config/constants.php | 41 --- system/application/config/database.php | 62 ----- system/application/config/doctypes.php | 15 -- system/application/config/foreign_chars.php | 64 ----- system/application/config/hooks.php | 16 -- system/application/config/index.html | 10 - system/application/config/mimes.php | 105 -------- system/application/config/profiler.php | 17 -- system/application/config/routes.php | 39 --- system/application/config/smileys.php | 66 ----- system/application/config/user_agents.php | 177 ------------- system/application/controllers/index.html | 10 - system/application/controllers/welcome.php | 17 -- system/application/core/index.html | 10 - system/application/errors/error_404.php | 34 --- system/application/errors/error_db.php | 34 --- system/application/errors/error_general.php | 34 --- system/application/errors/error_php.php | 10 - system/application/errors/index.html | 10 - system/application/helpers/index.html | 10 - system/application/hooks/index.html | 10 - system/application/index.html | 10 - system/application/language/english/index.html | 10 - system/application/libraries/index.html | 10 - system/application/models/index.html | 10 - system/application/third_party/index.html | 10 - system/application/views/index.html | 10 - system/application/views/welcome_message.php | 62 ----- 30 files changed, 1345 deletions(-) delete mode 100644 system/application/config/autoload.php delete mode 100644 system/application/config/config.php delete mode 100644 system/application/config/constants.php delete mode 100644 system/application/config/database.php delete mode 100644 system/application/config/doctypes.php delete mode 100644 system/application/config/foreign_chars.php delete mode 100644 system/application/config/hooks.php delete mode 100644 system/application/config/index.html delete mode 100644 system/application/config/mimes.php delete mode 100644 system/application/config/profiler.php delete mode 100644 system/application/config/routes.php delete mode 100644 system/application/config/smileys.php delete mode 100644 system/application/config/user_agents.php delete mode 100644 system/application/controllers/index.html delete mode 100644 system/application/controllers/welcome.php delete mode 100644 system/application/core/index.html delete mode 100644 system/application/errors/error_404.php delete mode 100644 system/application/errors/error_db.php delete mode 100644 system/application/errors/error_general.php delete mode 100644 system/application/errors/error_php.php delete mode 100644 system/application/errors/index.html delete mode 100644 system/application/helpers/index.html delete mode 100644 system/application/hooks/index.html delete mode 100644 system/application/index.html delete mode 100644 system/application/language/english/index.html delete mode 100644 system/application/libraries/index.html delete mode 100644 system/application/models/index.html delete mode 100644 system/application/third_party/index.html delete mode 100644 system/application/views/index.html delete mode 100644 system/application/views/welcome_message.php (limited to 'system') diff --git a/system/application/config/autoload.php b/system/application/config/autoload.php deleted file mode 100644 index e7c6f0db1..000000000 --- a/system/application/config/autoload.php +++ /dev/null @@ -1,103 +0,0 @@ - '', - 'xhtml1-strict' => '', - 'xhtml1-trans' => '', - 'xhtml1-frame' => '', - 'html5' => '', - 'html4-strict' => '', - 'html4-trans' => '', - 'html4-frame' => '' - ); - -/* End of file doctypes.php */ -/* Location: application/config/doctypes.php */ \ No newline at end of file diff --git a/system/application/config/foreign_chars.php b/system/application/config/foreign_chars.php deleted file mode 100644 index 8d70a2f62..000000000 --- a/system/application/config/foreign_chars.php +++ /dev/null @@ -1,64 +0,0 @@ - "ss", // ß - '224' => "a", - '225' => "a", - '226' => "a", - '229' => "a", - '227' => "ae", - '230' => "ae", - '228' => "ae", - '231' => "c", - '232' => "e", // è - '233' => "e", // é - '234' => "e", // ê - '235' => "e", // ë - '236' => "i", - '237' => "i", - '238' => "i", - '239' => "i", - '241' => "n", - '242' => "o", - '243' => "o", - '244' => "o", - '245' => "o", - '246' => "oe", // ö - '249' => "u", - '250' => "u", - '251' => "u", - '252' => "ue", // ü - '255' => "y", - '257' => "aa", - '269' => "ch", - '275' => "ee", - '291' => "gj", - '299' => "ii", - '311' => "kj", - '316' => "lj", - '326' => "nj", - '353' => "sh", - '363' => "uu", - '382' => "zh", - '256' => "aa", - '268' => "ch", - '274' => "ee", - '290' => "gj", - '298' => "ii", - '310' => "kj", - '315' => "lj", - '325' => "nj", - '352' => "sh", - '362' => "uu", - '381' => "zh", - ); - - -/* End of file foreign_chars.php */ -/* Location: ./system/application/config/foreign_chars.php */ \ No newline at end of file diff --git a/system/application/config/hooks.php b/system/application/config/hooks.php deleted file mode 100644 index 5e98a9b46..000000000 --- a/system/application/config/hooks.php +++ /dev/null @@ -1,16 +0,0 @@ - - - 403 Forbidden - - - -

    Directory access is forbidden.

    - - - \ No newline at end of file diff --git a/system/application/config/mimes.php b/system/application/config/mimes.php deleted file mode 100644 index f31fff2ec..000000000 --- a/system/application/config/mimes.php +++ /dev/null @@ -1,105 +0,0 @@ - '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', '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'), - 'aif' => 'audio/x-aiff', - 'aiff' => 'audio/x-aiff', - 'aifc' => 'audio/x-aiff', - 'ram' => 'audio/x-pn-realaudio', - 'rm' => 'audio/x-pn-realaudio', - 'rpm' => 'audio/x-pn-realaudio-plugin', - 'ra' => 'audio/x-realaudio', - 'rv' => 'video/vnd.rn-realvideo', - 'wav' => 'audio/x-wav', - 'bmp' => 'image/bmp', - 'gif' => 'image/gif', - 'jpeg' => 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' => 'application/vnd.openxmlformats-officedocument.wordprocessingml.document', - 'xlsx' => 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet', - 'word' => array('application/msword', 'application/octet-stream'), - 'xl' => 'application/excel', - 'eml' => 'message/rfc822' - ); - - -/* End of file mimes.php */ -/* Location: ./application/config/mimes.php */ \ No newline at end of file diff --git a/system/application/config/profiler.php b/system/application/config/profiler.php deleted file mode 100644 index f30432d9a..000000000 --- a/system/application/config/profiler.php +++ /dev/null @@ -1,17 +0,0 @@ - array('grin.gif', '19', '19', 'grin'), - ':lol:' => array('lol.gif', '19', '19', 'LOL'), - ':cheese:' => array('cheese.gif', '19', '19', 'cheese'), - ':)' => array('smile.gif', '19', '19', 'smile'), - ';-)' => array('wink.gif', '19', '19', 'wink'), - ';)' => array('wink.gif', '19', '19', 'wink'), - ':smirk:' => array('smirk.gif', '19', '19', 'smirk'), - ':roll:' => array('rolleyes.gif', '19', '19', 'rolleyes'), - ':-S' => array('confused.gif', '19', '19', 'confused'), - ':wow:' => array('surprise.gif', '19', '19', 'surprised'), - ':bug:' => array('bigsurprise.gif', '19', '19', 'big surprise'), - ':-P' => array('tongue_laugh.gif', '19', '19', 'tongue laugh'), - '%-P' => array('tongue_rolleye.gif', '19', '19', 'tongue rolleye'), - ';-P' => array('tongue_wink.gif', '19', '19', 'tongue wink'), - ':P' => array('raspberry.gif', '19', '19', 'raspberry'), - ':blank:' => array('blank.gif', '19', '19', 'blank stare'), - ':long:' => array('longface.gif', '19', '19', 'long face'), - ':ohh:' => array('ohh.gif', '19', '19', 'ohh'), - ':grrr:' => array('grrr.gif', '19', '19', 'grrr'), - ':gulp:' => array('gulp.gif', '19', '19', 'gulp'), - '8-/' => array('ohoh.gif', '19', '19', 'oh oh'), - ':down:' => array('downer.gif', '19', '19', 'downer'), - ':red:' => array('embarrassed.gif', '19', '19', 'red face'), - ':sick:' => array('sick.gif', '19', '19', 'sick'), - ':shut:' => array('shuteye.gif', '19', '19', 'shut eye'), - ':-/' => array('hmm.gif', '19', '19', 'hmmm'), - '>:(' => array('mad.gif', '19', '19', 'mad'), - ':mad:' => array('mad.gif', '19', '19', 'mad'), - '>:-(' => array('angry.gif', '19', '19', 'angry'), - ':angry:' => array('angry.gif', '19', '19', 'angry'), - ':zip:' => array('zip.gif', '19', '19', 'zipper'), - ':kiss:' => array('kiss.gif', '19', '19', 'kiss'), - ':ahhh:' => array('shock.gif', '19', '19', 'shock'), - ':coolsmile:' => array('shade_smile.gif', '19', '19', 'cool smile'), - ':coolsmirk:' => array('shade_smirk.gif', '19', '19', 'cool smirk'), - ':coolgrin:' => array('shade_grin.gif', '19', '19', 'cool grin'), - ':coolhmm:' => array('shade_hmm.gif', '19', '19', 'cool hmm'), - ':coolmad:' => array('shade_mad.gif', '19', '19', 'cool mad'), - ':coolcheese:' => array('shade_cheese.gif', '19', '19', 'cool cheese'), - ':vampire:' => array('vampire.gif', '19', '19', 'vampire'), - ':snake:' => array('snake.gif', '19', '19', 'snake'), - ':exclaim:' => array('exclaim.gif', '19', '19', 'excaim'), - ':question:' => array('question.gif', '19', '19', 'question') // no comma after last item - - ); - -/* End of file smileys.php */ -/* Location: ./system/application/config/smileys.php */ \ No newline at end of file diff --git a/system/application/config/user_agents.php b/system/application/config/user_agents.php deleted file mode 100644 index a1c0b14b6..000000000 --- a/system/application/config/user_agents.php +++ /dev/null @@ -1,177 +0,0 @@ - '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' - ); - - -// 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' - ); - -$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' - - // Phones and Manufacturers - 'motorola' => "Motorola", - 'nokia' => "Nokia", - 'palm' => "Palm", - 'iphone' => "Apple iPhone", - '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", - - // Operating Systems - 'symbian' => "Symbian", - 'SymbianOS' => "SymbianOS", - 'elaine' => "Palm", - 'palm' => "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", - - // 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" - ); - -// 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' - ); - -/* End of file user_agents.php */ -/* Location: ./system/application/config/user_agents.php */ \ No newline at end of file diff --git a/system/application/controllers/index.html b/system/application/controllers/index.html deleted file mode 100644 index c942a79ce..000000000 --- a/system/application/controllers/index.html +++ /dev/null @@ -1,10 +0,0 @@ - - - 403 Forbidden - - - -

    Directory access is forbidden.

    - - - \ No newline at end of file diff --git a/system/application/controllers/welcome.php b/system/application/controllers/welcome.php deleted file mode 100644 index 20d48855e..000000000 --- a/system/application/controllers/welcome.php +++ /dev/null @@ -1,17 +0,0 @@ -load->view('welcome_message'); - } -} - -/* End of file welcome.php */ -/* Location: ./system/application/controllers/welcome.php */ \ No newline at end of file diff --git a/system/application/core/index.html b/system/application/core/index.html deleted file mode 100644 index c942a79ce..000000000 --- a/system/application/core/index.html +++ /dev/null @@ -1,10 +0,0 @@ - - - 403 Forbidden - - - -

    Directory access is forbidden.

    - - - \ No newline at end of file diff --git a/system/application/errors/error_404.php b/system/application/errors/error_404.php deleted file mode 100644 index 1c513a205..000000000 --- a/system/application/errors/error_404.php +++ /dev/null @@ -1,34 +0,0 @@ - - -404 Page Not Found - - - -
    -

    - -
    - - \ No newline at end of file diff --git a/system/application/errors/error_db.php b/system/application/errors/error_db.php deleted file mode 100644 index 1ce52dfc9..000000000 --- a/system/application/errors/error_db.php +++ /dev/null @@ -1,34 +0,0 @@ - - -Database Error - - - -
    -

    - -
    - - \ No newline at end of file diff --git a/system/application/errors/error_general.php b/system/application/errors/error_general.php deleted file mode 100644 index d8610702b..000000000 --- a/system/application/errors/error_general.php +++ /dev/null @@ -1,34 +0,0 @@ - - -Error - - - -
    -

    - -
    - - \ No newline at end of file diff --git a/system/application/errors/error_php.php b/system/application/errors/error_php.php deleted file mode 100644 index f085c2037..000000000 --- a/system/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/system/application/errors/index.html b/system/application/errors/index.html deleted file mode 100644 index c942a79ce..000000000 --- a/system/application/errors/index.html +++ /dev/null @@ -1,10 +0,0 @@ - - - 403 Forbidden - - - -

    Directory access is forbidden.

    - - - \ No newline at end of file diff --git a/system/application/helpers/index.html b/system/application/helpers/index.html deleted file mode 100644 index c942a79ce..000000000 --- a/system/application/helpers/index.html +++ /dev/null @@ -1,10 +0,0 @@ - - - 403 Forbidden - - - -

    Directory access is forbidden.

    - - - \ No newline at end of file diff --git a/system/application/hooks/index.html b/system/application/hooks/index.html deleted file mode 100644 index c942a79ce..000000000 --- a/system/application/hooks/index.html +++ /dev/null @@ -1,10 +0,0 @@ - - - 403 Forbidden - - - -

    Directory access is forbidden.

    - - - \ No newline at end of file diff --git a/system/application/index.html b/system/application/index.html deleted file mode 100644 index c942a79ce..000000000 --- a/system/application/index.html +++ /dev/null @@ -1,10 +0,0 @@ - - - 403 Forbidden - - - -

    Directory access is forbidden.

    - - - \ No newline at end of file diff --git a/system/application/language/english/index.html b/system/application/language/english/index.html deleted file mode 100644 index c942a79ce..000000000 --- a/system/application/language/english/index.html +++ /dev/null @@ -1,10 +0,0 @@ - - - 403 Forbidden - - - -

    Directory access is forbidden.

    - - - \ No newline at end of file diff --git a/system/application/libraries/index.html b/system/application/libraries/index.html deleted file mode 100644 index c942a79ce..000000000 --- a/system/application/libraries/index.html +++ /dev/null @@ -1,10 +0,0 @@ - - - 403 Forbidden - - - -

    Directory access is forbidden.

    - - - \ No newline at end of file diff --git a/system/application/models/index.html b/system/application/models/index.html deleted file mode 100644 index c942a79ce..000000000 --- a/system/application/models/index.html +++ /dev/null @@ -1,10 +0,0 @@ - - - 403 Forbidden - - - -

    Directory access is forbidden.

    - - - \ No newline at end of file diff --git a/system/application/third_party/index.html b/system/application/third_party/index.html deleted file mode 100644 index c942a79ce..000000000 --- a/system/application/third_party/index.html +++ /dev/null @@ -1,10 +0,0 @@ - - - 403 Forbidden - - - -

    Directory access is forbidden.

    - - - \ No newline at end of file diff --git a/system/application/views/index.html b/system/application/views/index.html deleted file mode 100644 index c942a79ce..000000000 --- a/system/application/views/index.html +++ /dev/null @@ -1,10 +0,0 @@ - - - 403 Forbidden - - - -

    Directory access is forbidden.

    - - - \ No newline at end of file diff --git a/system/application/views/welcome_message.php b/system/application/views/welcome_message.php deleted file mode 100644 index 653b62c74..000000000 --- a/system/application/views/welcome_message.php +++ /dev/null @@ -1,62 +0,0 @@ - - -Welcome to CodeIgniter - - - - - -

    Welcome to CodeIgniter!

    - -

    The page you are looking at is being generated dynamically by CodeIgniter.

    - -

    If you would like to edit this page you'll find it located at:

    -system/application/views/welcome_message.php - -

    The corresponding controller for this page is found at:

    -system/application/controllers/welcome.php - -

    If you are exploring CodeIgniter for the very first time, you should start by reading the User Guide.

    - - -


    Page rendered in {elapsed_time} seconds

    - - - \ No newline at end of file -- cgit v1.2.3-24-g4f1b From 6e50b856d30037a88d878a68d1055fd37a182008 Mon Sep 17 00:00:00 2001 From: Derek Jones Date: Thu, 25 Mar 2010 10:21:04 -0500 Subject: added .htaccess to application and system folder to help prevent public access if installed in web root --- system/.htaccess | 1 + 1 file changed, 1 insertion(+) create mode 100644 system/.htaccess (limited to 'system') diff --git a/system/.htaccess b/system/.htaccess new file mode 100644 index 000000000..14249c50b --- /dev/null +++ b/system/.htaccess @@ -0,0 +1 @@ +Deny from all \ No newline at end of file -- cgit v1.2.3-24-g4f1b From 6c1294b5c3c98e26eaa6cb5eaa83dd3921a30348 Mon Sep 17 00:00:00 2001 From: Derek Jones Date: Thu, 25 Mar 2010 10:32:22 -0500 Subject: code comment typo --- system/core/Controller.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system') diff --git a/system/core/Controller.php b/system/core/Controller.php index 2e44500a6..92f7f17f1 100644 --- a/system/core/Controller.php +++ b/system/core/Controller.php @@ -75,7 +75,7 @@ class Controller extends CI_Base { } } -// END _Controller class +// END Controller class /* End of file Controller.php */ /* Location: ./system/core/Controller.php */ \ No newline at end of file -- cgit v1.2.3-24-g4f1b From d25e66a1824a70c5a2ebfae69b759c3b8a2d02a6 Mon Sep 17 00:00:00 2001 From: Greg Aker Date: Sun, 28 Mar 2010 01:07:09 -0500 Subject: Change in the loader and driver docs to force ucfirst() on driver directory names to ensure compatibility on case sensitive file systems. --- system/core/Loader.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system') diff --git a/system/core/Loader.php b/system/core/Loader.php index 976823f81..292fdc955 100644 --- a/system/core/Loader.php +++ b/system/core/Loader.php @@ -506,7 +506,7 @@ class CI_Loader { // and typically identically named to the library if ( ! strpos($library, '/')) { - $library = $library.'/'.$library; + $library = ucfirst($library).'/'.$library; } return $this->library($library, $params, $object_name); -- cgit v1.2.3-24-g4f1b From 133e66626bb410571a8350376d3f81ed8bc9143f Mon Sep 17 00:00:00 2001 From: Derek Jones Date: Mon, 29 Mar 2010 11:36:42 -0500 Subject: fixed a bug where a PHP error would result when passing objects as values to the Session class --- system/libraries/Session.php | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) (limited to 'system') diff --git a/system/libraries/Session.php b/system/libraries/Session.php index bd9426818..cf6dc96e3 100644 --- a/system/libraries/Session.php +++ b/system/libraries/Session.php @@ -680,12 +680,18 @@ class CI_Session { { foreach ($data as $key => $val) { - $data[$key] = str_replace('\\', '{{slash}}', $val); + if (is_string($val)) + { + $data[$key] = str_replace('\\', '{{slash}}', $val); + } } } else { - $data = str_replace('\\', '{{slash}}', $data); + if (is_string($data)) + { + $data = str_replace('\\', '{{slash}}', $data); + } } return serialize($data); @@ -711,13 +717,16 @@ class CI_Session { { foreach ($data as $key => $val) { - $data[$key] = str_replace('{{slash}}', '\\', $val); + if (is_string($val)) + { + $data[$key] = str_replace('{{slash}}', '\\', $val); + } } return $data; } - return str_replace('{{slash}}', '\\', $data); + return (is_string($data)) ? str_replace('{{slash}}', '\\', $data) : $data; } // -------------------------------------------------------------------- -- cgit v1.2.3-24-g4f1b From 4bde110ec6769fe0fd0194be602fd3ed85c52bc7 Mon Sep 17 00:00:00 2001 From: Derek Jones Date: Tue, 30 Mar 2010 08:56:53 -0500 Subject: fixed a fatal PHP error in SQLite Forge _create_table() --- system/database/drivers/sqlite/sqlite_forge.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system') diff --git a/system/database/drivers/sqlite/sqlite_forge.php b/system/database/drivers/sqlite/sqlite_forge.php index b7d25e755..53b20a3c7 100644 --- a/system/database/drivers/sqlite/sqlite_forge.php +++ b/system/database/drivers/sqlite/sqlite_forge.php @@ -77,7 +77,7 @@ class CI_DB_sqlite_forge extends CI_DB_forge { $sql = 'CREATE TABLE '; // IF NOT EXISTS added to SQLite in 3.3.0 - if ($if_not_exists === TRUE && version_compare($this->_version(), '3.3.0', '>=') === TRUE) + if ($if_not_exists === TRUE && version_compare($this->db->_version(), '3.3.0', '>=') === TRUE) { $sql .= 'IF NOT EXISTS '; } -- cgit v1.2.3-24-g4f1b From a091147feb0331e758b74e7ea13f6ebcb645cd9b Mon Sep 17 00:00:00 2001 From: Derek Jones Date: Tue, 30 Mar 2010 10:33:09 -0500 Subject: moved entity_decode() to the Security library to handle an issue with HTML in input when the global XSS filter is enabled --- system/helpers/typography_helper.php | 38 ++----------------------- system/libraries/Security.php | 55 ++++++++++++++++++++++++++++++++++-- 2 files changed, 55 insertions(+), 38 deletions(-) (limited to 'system') diff --git a/system/helpers/typography_helper.php b/system/helpers/typography_helper.php index 712b57509..e45480e1a 100644 --- a/system/helpers/typography_helper.php +++ b/system/helpers/typography_helper.php @@ -76,15 +76,6 @@ if ( ! function_exists('auto_typography')) * * This function is a replacement for html_entity_decode() * - * In some versions of PHP the native function does not work - * when UTF-8 is the specified character set, so this gives us - * a work-around. More info here: - * http://bugs.php.net/bug.php?id=25670 - * - * NOTE: html_entity_decode() has a bug in some PHP versions when UTF-8 is the - * character set, and the PHP developers said they were not back porting the - * fix to versions other than PHP 5.x. - * * @access public * @param string * @return string @@ -93,32 +84,9 @@ if ( ! function_exists('entity_decode')) { function entity_decode($str, $charset='UTF-8') { - if (stristr($str, '&') === FALSE) return $str; - - // 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. - - if (function_exists('html_entity_decode') && (strtolower($charset) != 'utf-8' OR version_compare(phpversion(), '5.0.0', '>='))) - { - $str = html_entity_decode($str, ENT_COMPAT, $charset); - $str = preg_replace('~&#x(0*[0-9a-f]{2,5})~ei', 'chr(hexdec("\\1"))', $str); - return preg_replace('~&#([0-9]{2,4})~e', 'chr(\\1)', $str); - } - - // Numeric Entities - $str = preg_replace('~&#x(0*[0-9a-f]{2,5});{0,1}~ei', 'chr(hexdec("\\1"))', $str); - $str = preg_replace('~&#([0-9]{2,4});{0,1}~e', 'chr(\\1)', $str); - - // Literal Entities - Slightly slow so we do another check - if (stristr($str, '&') === FALSE) - { - $str = strtr($str, array_flip(get_html_translation_table(HTML_ENTITIES))); - } - - return $str; + $CI =& get_instance(); + $CI->load->library('security'); + return $CI->security->entity_decode($str, $charset); } } diff --git a/system/libraries/Security.php b/system/libraries/Security.php index 93da59204..60adf0a27 100644 --- a/system/libraries/Security.php +++ b/system/libraries/Security.php @@ -648,13 +648,62 @@ class CI_Security { */ function _decode_entity($match) { - $CI =& get_instance(); - $CI->load->helper('typography'); - return entity_decode($match[0], strtoupper($CI->config->item('charset'))); + return $this->entity_decode($match[0], strtoupper(config_item('charset'))); } // -------------------------------------------------------------------- + /** + * HTML Entities Decode + * + * This function is a replacement for html_entity_decode() + * + * In some versions of PHP the native function does not work + * when UTF-8 is the specified character set, so this gives us + * a work-around. More info here: + * http://bugs.php.net/bug.php?id=25670 + * + * NOTE: html_entity_decode() has a bug in some PHP versions when UTF-8 is the + * character set, and the PHP developers said they were not back porting the + * fix to versions other than PHP 5.x. + * + * @access public + * @param string + * @param string + * @return string + */ + function entity_decode($str, $charset='UTF-8') + { + if (stristr($str, '&') === FALSE) return $str; + + // 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. + + if (function_exists('html_entity_decode') && (strtolower($charset) != 'utf-8' OR is_php('5.0.0'))) + { + $str = html_entity_decode($str, ENT_COMPAT, $charset); + $str = preg_replace('~&#x(0*[0-9a-f]{2,5})~ei', 'chr(hexdec("\\1"))', $str); + return preg_replace('~&#([0-9]{2,4})~e', 'chr(\\1)', $str); + } + + // Numeric Entities + $str = preg_replace('~&#x(0*[0-9a-f]{2,5});{0,1}~ei', 'chr(hexdec("\\1"))', $str); + $str = preg_replace('~&#([0-9]{2,4});{0,1}~e', 'chr(\\1)', $str); + + // Literal Entities - Slightly slow so we do another check + if (stristr($str, '&') === FALSE) + { + $str = strtr($str, array_flip(get_html_translation_table(HTML_ENTITIES))); + } + + return $str; + } + + // -------------------------------------------------------------------- + /** * Filename Security * -- cgit v1.2.3-24-g4f1b From aaa19bce2b8fb549442a679cba1382510770ddff Mon Sep 17 00:00:00 2001 From: Greg Aker Date: Wed, 31 Mar 2010 21:43:21 -0500 Subject: Fixing Validation error in output profiler --- system/libraries/Profiler.php | 4 ---- 1 file changed, 4 deletions(-) (limited to 'system') diff --git a/system/libraries/Profiler.php b/system/libraries/Profiler.php index b2c008fc0..3285bc531 100644 --- a/system/libraries/Profiler.php +++ b/system/libraries/Profiler.php @@ -434,8 +434,6 @@ class CI_Profiler { $output .= "
    \n"; $output .= ""; - $output .= ""; - return $output; } @@ -467,8 +465,6 @@ class CI_Profiler { $output .= "
    \n"; $output .= ""; - $output .= ""; - return $output; } -- cgit v1.2.3-24-g4f1b From 3fff87d3c7f7374fae3c4013d4ba1c7ba10f17be Mon Sep 17 00:00:00 2001 From: Greg Aker Date: Wed, 7 Apr 2010 14:23:01 -0500 Subject: Fixing typo in XMLRpc error message: http://codeigniter.com/bug_tracker/bug/11556/ --- system/libraries/Xmlrpc.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system') diff --git a/system/libraries/Xmlrpc.php b/system/libraries/Xmlrpc.php index 2e0df5c9b..ee04400f5 100644 --- a/system/libraries/Xmlrpc.php +++ b/system/libraries/Xmlrpc.php @@ -112,7 +112,7 @@ class CI_Xmlrpc { $this->xmlrpcerr['unknown_method'] = '1'; $this->xmlrpcstr['unknown_method'] = 'This is not a known method for this XML-RPC Server'; $this->xmlrpcerr['invalid_return'] = '2'; - $this->xmlrpcstr['invalid_return'] = 'The XML data receieved was either invalid or not in the correct form for XML-RPC. Turn on debugging to examine the XML data further.'; + $this->xmlrpcstr['invalid_return'] = 'The XML data received was either invalid or not in the correct form for XML-RPC. Turn on debugging to examine the XML data further.'; $this->xmlrpcerr['incorrect_params'] = '3'; $this->xmlrpcstr['incorrect_params'] = 'Incorrect parameters were passed to method'; $this->xmlrpcerr['introspect_unknown'] = '4'; -- cgit v1.2.3-24-g4f1b From 73c19fc2e15bb542053bc347ee922ceb26114696 Mon Sep 17 00:00:00 2001 From: Robin Sowell Date: Fri, 9 Apr 2010 11:18:26 -0400 Subject: Modified get_file_info in the file helper, changing filectime() to filemtime() for dates. --- system/helpers/file_helper.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system') diff --git a/system/helpers/file_helper.php b/system/helpers/file_helper.php index 274c4ad37..448bf275f 100644 --- a/system/helpers/file_helper.php +++ b/system/helpers/file_helper.php @@ -305,7 +305,7 @@ if ( ! function_exists('get_file_info')) $fileinfo['size'] = filesize($file); break; case 'date': - $fileinfo['date'] = filectime($file); + $fileinfo['date'] = filemtime($file); break; case 'readable': $fileinfo['readable'] = is_readable($file); -- cgit v1.2.3-24-g4f1b From 676e1cda78b7bc4eede7cad509a8d9f015a51816 Mon Sep 17 00:00:00 2001 From: Pascal Kriete Date: Fri, 9 Apr 2010 21:16:16 +0200 Subject: Adding output library exceptions for servers with zlib.output_compression enabled. --- system/core/Output.php | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) (limited to 'system') diff --git a/system/core/Output.php b/system/core/Output.php index ac4129405..e25e62197 100644 --- a/system/core/Output.php +++ b/system/core/Output.php @@ -34,10 +34,13 @@ class CI_Output { var $enable_profiler = FALSE; var $parse_exec_vars = TRUE; // whether or not to parse variables like {elapsed_time} and {memory_usage} + var $_zlib_oc = FALSE; var $_profiler_sections = array(); function CI_Output() { + $this->_zlib_oc = @ini_get('zlib.output_compression'); + log_message('debug', "Output Class Initialized"); } @@ -111,6 +114,16 @@ class CI_Output { */ 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); } @@ -234,7 +247,7 @@ class CI_Output { // -------------------------------------------------------------------- // Is compression requested? - if ($CFG->item('compress_output') === TRUE) + if ($CFG->item('compress_output') === TRUE && $this->_zlib_oc == FALSE) { if (extension_loaded('zlib')) { -- cgit v1.2.3-24-g4f1b From ef88a906ed8b2050f4c6e6d8fbd73cc5b6adc7a3 Mon Sep 17 00:00:00 2001 From: Greg Aker Date: Wed, 14 Apr 2010 18:22:23 -0500 Subject: Removing deprecated Validation class. Form_validation going forward! Removed references to the validation classes documentation page in the changelog as well. --- system/libraries/Validation.php | 875 ---------------------------------------- 1 file changed, 875 deletions(-) delete mode 100644 system/libraries/Validation.php (limited to 'system') diff --git a/system/libraries/Validation.php b/system/libraries/Validation.php deleted file mode 100644 index a42b7760b..000000000 --- a/system/libraries/Validation.php +++ /dev/null @@ -1,875 +0,0 @@ -'; - var $_error_suffix = '

    '; - - - - /** - * Constructor - * - */ - function CI_Validation() - { - $this->CI =& get_instance(); - - if (function_exists('mb_internal_encoding')) - { - mb_internal_encoding($this->CI->config->item('charset')); - } - - log_message('debug', "Validation Class Initialized"); - } - - // -------------------------------------------------------------------- - - /** - * Set Fields - * - * This function takes an array of field names as input - * and generates class variables with the same name, which will - * either be blank or contain the $_POST value corresponding to it - * - * @access public - * @param string - * @param string - * @return void - */ - function set_fields($data = '', $field = '') - { - if ($data == '') - { - if (count($this->_fields) == 0) - { - return FALSE; - } - } - else - { - if ( ! is_array($data)) - { - $data = array($data => $field); - } - - if (count($data) > 0) - { - $this->_fields = $data; - } - } - - foreach($this->_fields as $key => $val) - { - $this->$key = ( ! isset($_POST[$key])) ? '' : $this->prep_for_form($_POST[$key]); - - $error = $key.'_error'; - if ( ! isset($this->$error)) - { - $this->$error = ''; - } - } - } - - // -------------------------------------------------------------------- - - /** - * Set Rules - * - * This function takes an array of field names and validation - * rules as input ad simply stores is for use later. - * - * @access public - * @param mixed - * @param string - * @return void - */ - function set_rules($data, $rules = '') - { - if ( ! is_array($data)) - { - if ($rules == '') - return; - - $data = array($data => $rules); - } - - foreach ($data as $key => $val) - { - $this->_rules[$key] = $val; - } - } - - // -------------------------------------------------------------------- - - /** - * Set Error Message - * - * Lets users set their own error messages on the fly. Note: The key - * name has to match the function name that it corresponds to. - * - * @access public - * @param string - * @param string - * @return string - */ - function set_message($lang, $val = '') - { - if ( ! is_array($lang)) - { - $lang = array($lang => $val); - } - - $this->_error_messages = array_merge($this->_error_messages, $lang); - } - - // -------------------------------------------------------------------- - - /** - * Set The Error Delimiter - * - * Permits a prefix/suffix to be added to each error message - * - * @access public - * @param string - * @param string - * @return void - */ - function set_error_delimiters($prefix = '

    ', $suffix = '

    ') - { - $this->_error_prefix = $prefix; - $this->_error_suffix = $suffix; - } - - // -------------------------------------------------------------------- - - /** - * Run the Validator - * - * This function does all the work. - * - * @access public - * @return bool - */ - function run() - { - // Do we even have any data to process? Mm? - if (count($_POST) == 0 OR count($this->_rules) == 0) - { - return FALSE; - } - - // Load the language file containing error messages - $this->CI->lang->load('validation'); - - // Cycle through the rules and test for errors - foreach ($this->_rules as $field => $rules) - { - //Explode out the rules! - $ex = explode('|', $rules); - - // Is the field required? If not, if the field is blank we'll move on to the next test - if ( ! in_array('required', $ex, TRUE)) - { - if ( ! isset($_POST[$field]) OR $_POST[$field] == '') - { - continue; - } - } - - /* - * Are we dealing with an "isset" rule? - * - * Before going further, we'll see if one of the rules - * is to check whether the item is set (typically this - * applies only to checkboxes). If so, we'll - * test for it here since there's not reason to go - * further - */ - if ( ! isset($_POST[$field])) - { - if (in_array('isset', $ex, TRUE) OR in_array('required', $ex)) - { - if ( ! isset($this->_error_messages['isset'])) - { - if (FALSE === ($line = $this->CI->lang->line('isset'))) - { - $line = 'The field was not set'; - } - } - else - { - $line = $this->_error_messages['isset']; - } - - // Build the error message - $mfield = ( ! isset($this->_fields[$field])) ? $field : $this->_fields[$field]; - $message = sprintf($line, $mfield); - - // Set the error variable. Example: $this->username_error - $error = $field.'_error'; - $this->$error = $this->_error_prefix.$message.$this->_error_suffix; - $this->_error_array[] = $message; - } - - continue; - } - - /* - * Set the current field - * - * The various prepping functions need to know the - * current field name so they can do this: - * - * $_POST[$this->_current_field] == 'bla bla'; - */ - $this->_current_field = $field; - - // Cycle through the rules! - foreach ($ex As $rule) - { - // Is the rule a callback? - $callback = FALSE; - if (substr($rule, 0, 9) == 'callback_') - { - $rule = substr($rule, 9); - $callback = TRUE; - } - - // Strip the parameter (if exists) from the rule - // Rules can contain a parameter: max_length[5] - $param = FALSE; - if (preg_match("/(.*?)\[(.*?)\]/", $rule, $match)) - { - $rule = $match[1]; - $param = $match[2]; - } - - // Call the function that corresponds to the rule - if ($callback === TRUE) - { - if ( ! method_exists($this->CI, $rule)) - { - continue; - } - - $result = $this->CI->$rule($_POST[$field], $param); - - // If the field isn't required and we just processed a callback we'll move on... - if ( ! in_array('required', $ex, TRUE) AND $result !== FALSE) - { - continue 2; - } - - } - else - { - if ( ! method_exists($this, $rule)) - { - /* - * Run the native PHP function if called for - * - * If our own wrapper function doesn't exist we see - * if a native PHP function does. Users can use - * any native PHP function call that has one param. - */ - if (function_exists($rule)) - { - $_POST[$field] = $rule($_POST[$field]); - $this->$field = $_POST[$field]; - } - - continue; - } - - $result = $this->$rule($_POST[$field], $param); - } - - // Did the rule test negatively? If so, grab the error. - if ($result === FALSE) - { - if ( ! isset($this->_error_messages[$rule])) - { - if (FALSE === ($line = $this->CI->lang->line($rule))) - { - $line = 'Unable to access an error message corresponding to your field name.'; - } - } - else - { - $line = $this->_error_messages[$rule]; - } - - // Build the error message - $mfield = ( ! isset($this->_fields[$field])) ? $field : $this->_fields[$field]; - $mparam = ( ! isset($this->_fields[$param])) ? $param : $this->_fields[$param]; - $message = sprintf($line, $mfield, $mparam); - - // Set the error variable. Example: $this->username_error - $error = $field.'_error'; - $this->$error = $this->_error_prefix.$message.$this->_error_suffix; - - // Add the error to the error array - $this->_error_array[] = $message; - continue 2; - } - } - - } - - $total_errors = count($this->_error_array); - - /* - * Recompile the class variables - * - * If any prepping functions were called the $_POST data - * might now be different then the corresponding class - * variables so we'll set them anew. - */ - if ($total_errors > 0) - { - $this->_safe_form_data = TRUE; - } - - $this->set_fields(); - - // Did we end up with any errors? - if ($total_errors == 0) - { - return TRUE; - } - - // Generate the error string - foreach ($this->_error_array as $val) - { - $this->error_string .= $this->_error_prefix.$val.$this->_error_suffix."\n"; - } - - return FALSE; - } - - // -------------------------------------------------------------------- - - /** - * Required - * - * @access public - * @param string - * @return bool - */ - function required($str) - { - if ( ! is_array($str)) - { - return (trim($str) == '') ? FALSE : TRUE; - } - else - { - return ( ! empty($str)); - } - } - - // -------------------------------------------------------------------- - - /** - * Match one field to another - * - * @access public - * @param string - * @param field - * @return bool - */ - function matches($str, $field) - { - if ( ! isset($_POST[$field])) - { - return FALSE; - } - - return ($str !== $_POST[$field]) ? FALSE : TRUE; - } - - // -------------------------------------------------------------------- - - /** - * Minimum Length - * - * @access public - * @param string - * @param value - * @return bool - */ - function min_length($str, $val) - { - if (preg_match("/[^0-9]/", $val)) - { - return FALSE; - } - - if (function_exists('mb_strlen')) - { - return (mb_strlen($str) < $val) ? FALSE : TRUE; - } - - return (strlen($str) < $val) ? FALSE : TRUE; - } - - // -------------------------------------------------------------------- - - /** - * Max Length - * - * @access public - * @param string - * @param value - * @return bool - */ - function max_length($str, $val) - { - if (preg_match("/[^0-9]/", $val)) - { - return FALSE; - } - - if (function_exists('mb_strlen')) - { - return (mb_strlen($str) > $val) ? FALSE : TRUE; - } - - return (strlen($str) > $val) ? FALSE : TRUE; - } - - // -------------------------------------------------------------------- - - /** - * Exact Length - * - * @access public - * @param string - * @param value - * @return bool - */ - function exact_length($str, $val) - { - if (preg_match("/[^0-9]/", $val)) - { - return FALSE; - } - - if (function_exists('mb_strlen')) - { - return (mb_strlen($str) != $val) ? FALSE : TRUE; - } - - return (strlen($str) != $val) ? FALSE : TRUE; - } - - // -------------------------------------------------------------------- - - /** - * Valid Email - * - * @access public - * @param string - * @return bool - */ - function valid_email($str) - { - return ( ! preg_match("/^([a-z0-9\+_\-]+)(\.[a-z0-9\+_\-]+)*@([a-z0-9\-]+\.)+[a-z]{2,6}$/ix", $str)) ? FALSE : TRUE; - } - - // -------------------------------------------------------------------- - - /** - * Valid Emails - * - * @access public - * @param string - * @return bool - */ - function valid_emails($str) - { - if (strpos($str, ',') === FALSE) - { - return $this->valid_email(trim($str)); - } - - foreach(explode(',', $str) as $email) - { - if (trim($email) != '' && $this->valid_email(trim($email)) === FALSE) - { - return FALSE; - } - } - - return TRUE; - } - - // -------------------------------------------------------------------- - - /** - * Validate IP Address - * - * @access public - * @param string - * @return string - */ - function valid_ip($ip) - { - return $this->CI->input->valid_ip($ip); - } - - // -------------------------------------------------------------------- - - /** - * Alpha - * - * @access public - * @param string - * @return bool - */ - function alpha($str) - { - return ( ! preg_match("/^([a-z])+$/i", $str)) ? FALSE : TRUE; - } - - // -------------------------------------------------------------------- - - /** - * Alpha-numeric - * - * @access public - * @param string - * @return bool - */ - function alpha_numeric($str) - { - return ( ! preg_match("/^([a-z0-9])+$/i", $str)) ? FALSE : TRUE; - } - - // -------------------------------------------------------------------- - - /** - * Alpha-numeric with underscores and dashes - * - * @access public - * @param string - * @return bool - */ - function alpha_dash($str) - { - return ( ! preg_match("/^([-a-z0-9_-])+$/i", $str)) ? FALSE : TRUE; - } - - // -------------------------------------------------------------------- - - /** - * Numeric - * - * @access public - * @param string - * @return bool - */ - function numeric($str) - { - return (bool)preg_match( '/^[\-+]?[0-9]*\.?[0-9]+$/', $str); - - } - - // -------------------------------------------------------------------- - - /** - * Is Numeric - * - * @access public - * @param string - * @return bool - */ - function is_numeric($str) - { - return ( ! is_numeric($str)) ? FALSE : TRUE; - } - - // -------------------------------------------------------------------- - - /** - * Integer - * - * @access public - * @param string - * @return bool - */ - function integer($str) - { - return (bool)preg_match( '/^[\-+]?[0-9]+$/', $str); - } - - // -------------------------------------------------------------------- - - /** - * Is a Natural number (0,1,2,3, etc.) - * - * @access public - * @param string - * @return bool - */ - function is_natural($str) - { - return (bool)preg_match( '/^[0-9]+$/', $str); - } - - // -------------------------------------------------------------------- - - /** - * Is a Natural number, but not a zero (1,2,3, etc.) - * - * @access public - * @param string - * @return bool - */ - function is_natural_no_zero($str) - { - if ( ! preg_match( '/^[0-9]+$/', $str)) - { - return FALSE; - } - - if ($str == 0) - { - return FALSE; - } - - return TRUE; - } - - // -------------------------------------------------------------------- - - /** - * Valid Base64 - * - * Tests a string for characters outside of the Base64 alphabet - * as defined by RFC 2045 http://www.faqs.org/rfcs/rfc2045 - * - * @access public - * @param string - * @return bool - */ - function valid_base64($str) - { - return (bool) ! preg_match('/[^a-zA-Z0-9\/\+=]/', $str); - } - - // -------------------------------------------------------------------- - - /** - * Set Select - * - * Enables pull-down lists to be set to the value the user - * selected in the event of an error - * - * @access public - * @param string - * @param string - * @return string - */ - function set_select($field = '', $value = '') - { - if ($field == '' OR $value == '' OR ! isset($_POST[$field])) - { - return ''; - } - - if ($_POST[$field] == $value) - { - return ' selected="selected"'; - } - } - - // -------------------------------------------------------------------- - - /** - * Set Radio - * - * Enables radio buttons to be set to the value the user - * selected in the event of an error - * - * @access public - * @param string - * @param string - * @return string - */ - function set_radio($field = '', $value = '') - { - if ($field == '' OR $value == '' OR ! isset($_POST[$field])) - { - return ''; - } - - if ($_POST[$field] == $value) - { - return ' checked="checked"'; - } - } - - // -------------------------------------------------------------------- - - /** - * Set Checkbox - * - * Enables checkboxes to be set to the value the user - * selected in the event of an error - * - * @access public - * @param string - * @param string - * @return string - */ - function set_checkbox($field = '', $value = '') - { - if ($field == '' OR $value == '' OR ! isset($_POST[$field])) - { - return ''; - } - - if ($_POST[$field] == $value) - { - return ' checked="checked"'; - } - } - - // -------------------------------------------------------------------- - - /** - * Prep data for form - * - * This function allows HTML to be safely shown in a form. - * Special characters are converted. - * - * @access public - * @param string - * @return string - */ - function prep_for_form($data = '') - { - if (is_array($data)) - { - foreach ($data as $key => $val) - { - $data[$key] = $this->prep_for_form($val); - } - - return $data; - } - - if ($this->_safe_form_data == FALSE OR $data == '') - { - return $data; - } - - return str_replace(array("'", '"', '<', '>'), array("'", """, '<', '>'), stripslashes($data)); - } - - // -------------------------------------------------------------------- - - /** - * Prep URL - * - * @access public - * @param string - * @return string - */ - function prep_url($str = '') - { - if ($str == 'http://' OR $str == '') - { - $_POST[$this->_current_field] = ''; - return; - } - - if (substr($str, 0, 7) != 'http://' && substr($str, 0, 8) != 'https://') - { - $str = 'http://'.$str; - } - - $_POST[$this->_current_field] = $str; - } - - // -------------------------------------------------------------------- - - /** - * Strip Image Tags - * - * @access public - * @param string - * @return string - */ - function strip_image_tags($str) - { - $_POST[$this->_current_field] = $this->CI->input->strip_image_tags($str); - } - - // -------------------------------------------------------------------- - - /** - * XSS Clean - * - * @access public - * @param string - * @return string - */ - function xss_clean($str) - { - $_POST[$this->_current_field] = $this->CI->input->xss_clean($str); - } - - // -------------------------------------------------------------------- - - /** - * Convert PHP tags to entities - * - * @access public - * @param string - * @return string - */ - function encode_php_tags($str) - { - $_POST[$this->_current_field] = str_replace(array(''), array('<?php', '<?PHP', '<?', '?>'), $str); - } - -} -// END Validation Class - -/* End of file Validation.php */ -/* Location: ./system/libraries/Validation.php */ \ No newline at end of file -- cgit v1.2.3-24-g4f1b From 757dda61aa0556aca8172dc2a8175596afe28ce2 Mon Sep 17 00:00:00 2001 From: Greg Aker Date: Wed, 14 Apr 2010 19:06:19 -0500 Subject: Fixing a bug where odbc/mssql/oci8 db drivers would encounter a PHP error due to a function being moved from the input to security class. Moving remove_invisible_characters() to Common.php so the entire class does not need to be instantiated in those database drivers. --- system/core/Common.php | 37 +++++++++++++++++++++++ system/database/drivers/mssql/mssql_driver.php | 5 +-- system/database/drivers/oci8/oci8_driver.php | 5 +-- system/database/drivers/odbc/odbc_driver.php | 5 +-- system/libraries/Security.php | 42 ++------------------------ 5 files changed, 42 insertions(+), 52 deletions(-) (limited to 'system') diff --git a/system/core/Common.php b/system/core/Common.php index 6e2f72509..9dee591e6 100644 --- a/system/core/Common.php +++ b/system/core/Common.php @@ -479,6 +479,43 @@ $_error->log_exception($severity, $message, $filepath, $line); } + // -------------------------------------------------------------------- + + /** + * Remove Invisible Characters + * + * This prevents sandwiching null characters + * between ascii characters, like Java\0script. + * + * @access public + * @param string + * @return string + */ + function remove_invisible_characters($str) + { + static $non_displayables; + + if ( ! isset($non_displayables)) + { + // every control character except newline (dec 10), carriage return (dec 13), and horizontal tab (dec 09), + $non_displayables = array( + '/%0[0-8bcef]/', // url encoded 00-08, 11, 12, 14, 15 + '/%1[0-9a-f]/', // url encoded 16-31 + '/[\x00-\x08]/', // 00-08 + '/\x0b/', '/\x0c/', // 11, 12 + '/[\x0e-\x1f]/' // 14-31 + ); + } + + do + { + $cleaned = $str; + $str = preg_replace($non_displayables, '', $str); + } + while ($cleaned != $str); + + return $str; + } /* End of file Common.php */ diff --git a/system/database/drivers/mssql/mssql_driver.php b/system/database/drivers/mssql/mssql_driver.php index 0c74726a2..40900e832 100644 --- a/system/database/drivers/mssql/mssql_driver.php +++ b/system/database/drivers/mssql/mssql_driver.php @@ -260,12 +260,9 @@ class CI_DB_mssql_driver extends CI_DB { return $str; } - - // Access the CI object - $CI =& get_instance(); // Escape single quotes - $str = str_replace("'", "''", $CI->input->_remove_invisible_characters($str)); + $str = str_replace("'", "''", remove_invisible_characters($str)); // escape LIKE condition wildcards if ($like === TRUE) diff --git a/system/database/drivers/oci8/oci8_driver.php b/system/database/drivers/oci8/oci8_driver.php index cd0e09577..6f317d2e6 100644 --- a/system/database/drivers/oci8/oci8_driver.php +++ b/system/database/drivers/oci8/oci8_driver.php @@ -403,10 +403,7 @@ class CI_DB_oci8_driver extends CI_DB { return $str; } - // Access the CI object - $CI =& get_instance(); - - $str = $CI->input->_remove_invisible_characters($str); + $str = remove_invisible_characters($str); // escape LIKE condition wildcards if ($like === TRUE) diff --git a/system/database/drivers/odbc/odbc_driver.php b/system/database/drivers/odbc/odbc_driver.php index d5df8ef8c..6e682313f 100644 --- a/system/database/drivers/odbc/odbc_driver.php +++ b/system/database/drivers/odbc/odbc_driver.php @@ -271,12 +271,9 @@ class CI_DB_odbc_driver extends CI_DB { return $str; } - - // Access the CI object - $CI =& get_instance(); // ODBC doesn't require escaping - $str = $CI->input->_remove_invisible_characters($str); + $str = remove_invisible_characters($str); // escape LIKE condition wildcards if ($like === TRUE) diff --git a/system/libraries/Security.php b/system/libraries/Security.php index 60adf0a27..cdae50168 100644 --- a/system/libraries/Security.php +++ b/system/libraries/Security.php @@ -198,7 +198,7 @@ class CI_Security { /* * Remove Invisible Characters */ - $str = $this->_remove_invisible_characters($str); + $str = remove_invisible_characters($str); /* * Protect GET variables in URLs @@ -258,7 +258,7 @@ class CI_Security { /* * Remove Invisible Characters Again! */ - $str = $this->_remove_invisible_characters($str); + $str = remove_invisible_characters($str); /* * Convert all tabs to spaces @@ -480,44 +480,6 @@ class CI_Security { // -------------------------------------------------------------------- - /** - * Remove Invisible Characters - * - * This prevents sandwiching null characters - * between ascii characters, like Java\0script. - * - * @access public - * @param string - * @return string - */ - function _remove_invisible_characters($str) - { - static $non_displayables; - - if ( ! isset($non_displayables)) - { - // every control character except newline (dec 10), carriage return (dec 13), and horizontal tab (dec 09), - $non_displayables = array( - '/%0[0-8bcef]/', // url encoded 00-08, 11, 12, 14, 15 - '/%1[0-9a-f]/', // url encoded 16-31 - '/[\x00-\x08]/', // 00-08 - '/\x0b/', '/\x0c/', // 11, 12 - '/[\x0e-\x1f]/' // 14-31 - ); - } - - do - { - $cleaned = $str; - $str = preg_replace($non_displayables, '', $str); - } - while ($cleaned != $str); - - return $str; - } - - // -------------------------------------------------------------------- - /** * Compact Exploded Words * -- cgit v1.2.3-24-g4f1b From f82e51cd8f46b112c3c400d43db9044854a8e805 Mon Sep 17 00:00:00 2001 From: Greg Aker Date: Wed, 14 Apr 2010 19:33:50 -0500 Subject: Update to File Upload library to return boolean on do_xss_clean(). --- system/libraries/Upload.php | 61 +++++++++++++++++++++++++++++++++++---------- 1 file changed, 48 insertions(+), 13 deletions(-) (limited to 'system') diff --git a/system/libraries/Upload.php b/system/libraries/Upload.php index ac9323c08..3131469de 100644 --- a/system/libraries/Upload.php +++ b/system/libraries/Upload.php @@ -276,9 +276,13 @@ class CI_Upload { * embedded within a file. Scripts can easily * be disguised as images or other file types. */ - if ($this->xss_clean == TRUE) + if ($this->xss_clean) { - $this->do_xss_clean(); + if ($this->do_xss_clean() === FALSE) + { + $this->set_error('upload_unable_to_write_file'); + return FALSE; + } } /* @@ -803,24 +807,55 @@ class CI_Upload { { return FALSE; } + + if (function_exists('memory_get_usage') && memory_get_usage() && ini_get('memory_limit') != '') + { + $current = ini_get('memory_limit') * 1024 * 1024; + + // There was a bug/behavioural change in PHP 5.2, where numbers over one million get output + // into scientific notation. number_format() ensures this number is an integer + // http://bugs.php.net/bug.php?id=43053 + + $new_memory = number_format(ceil(filesize($this->new_name) + $current), 0, '.', ''); + + ini_set('memory_limit', $new_memory); // When an integer is used, the value is measured in bytes. - PHP.net + } - if (($data = @file_get_contents($file)) === FALSE) + // If the file being uploaded is an image, then we should have no problem with XSS attacks (in theory), but + // IE can be fooled into mime-type detecting a malformed image as an html file, thus executing an XSS attack on anyone + // using IE who looks at the image. It does this by inspecting the first 255 bytes of an image. To get around this + // CI will itself look at the first 255 bytes of an image to determine its relative safety. This can save a lot of + // processor power and time if it is actually a clean image, as it will be in nearly all instances _except_ an + // attempted XSS attack. + + if (function_exists('getimagesize') && @getimagesize($file) !== FALSE) { - return FALSE; + if (($file = @fopen($file, 'rb')) === FALSE) // "b" to force binary + { + return FALSE; // Couldn't open the file, return FALSE + } + + $opening_bytes = fread($file, 256); + fclose($file); + + // These are known to throw IE into mime-type detection chaos + // ]/i', $opening_bytes)) + { + return TRUE; // its an image, no "triggers" detected in the first 256 bytes, we're good + } } - - if ( ! $fp = @fopen($file, FOPEN_READ_WRITE)) + + if (($data = @file_get_contents($file)) === FALSE) { return FALSE; } - $CI =& get_instance(); - $data = $CI->security->xss_clean($data); - - flock($fp, LOCK_EX); - fwrite($fp, $data); - flock($fp, LOCK_UN); - fclose($fp); + $CI =& get_instance(); + + return $CI->security->xss_clean($data, TRUE); } // -------------------------------------------------------------------- -- cgit v1.2.3-24-g4f1b From ff3ecaede7e7154d1897307a390919b655b15096 Mon Sep 17 00:00:00 2001 From: Robin Sowell Date: Fri, 16 Apr 2010 16:13:23 -0400 Subject: Added class var xss_clean to the XML_RPC_Response class to prevent php error. Not noted in changelog, as I figure it's covered by the original note about adding xss clean at all. --- system/libraries/Xmlrpc.php | 1 + 1 file changed, 1 insertion(+) (limited to 'system') diff --git a/system/libraries/Xmlrpc.php b/system/libraries/Xmlrpc.php index ee04400f5..e2b149b73 100644 --- a/system/libraries/Xmlrpc.php +++ b/system/libraries/Xmlrpc.php @@ -434,6 +434,7 @@ class XML_RPC_Response var $errno = 0; var $errstr = ''; var $headers = array(); + var $xss_clean = TRUE; function XML_RPC_Response($val, $code = 0, $fstr = '') { -- cgit v1.2.3-24-g4f1b From 60e78c75f9cb332dcd5a387bf4262c1566f32b8e Mon Sep 17 00:00:00 2001 From: Greg Aker Date: Tue, 20 Apr 2010 12:45:14 -0500 Subject: Modifying smiley_js() in the smiley helper to add optional third parameter to return only the javascript with no script tags. --- system/helpers/smiley_helper.php | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) (limited to 'system') diff --git a/system/helpers/smiley_helper.php b/system/helpers/smiley_helper.php index 775cc1b99..b9eb0a23e 100644 --- a/system/helpers/smiley_helper.php +++ b/system/helpers/smiley_helper.php @@ -40,7 +40,7 @@ */ if ( ! function_exists('smiley_js')) { - function smiley_js($alias = '', $field_id = '') + function smiley_js($alias = '', $field_id = '', $inline = TRUE) { static $do_setup = TRUE; @@ -108,7 +108,14 @@ EOF; } } - return ''; + if ($inline) + { + return ''; + } + else + { + return $r; + } } } -- cgit v1.2.3-24-g4f1b From 47cd452c91a3dc7dab4a8285136bee2048fc7bba Mon Sep 17 00:00:00 2001 From: Phil Sturgeon Date: Thu, 22 Apr 2010 12:34:13 +0100 Subject: Fixed Upload bug that would break when files and images were both included on an allowed filetype list in the wrong order: http://codeigniter.com/bug_tracker/bug/11552/ --- system/libraries/Upload.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system') diff --git a/system/libraries/Upload.php b/system/libraries/Upload.php index 3131469de..0e71aee6b 100644 --- a/system/libraries/Upload.php +++ b/system/libraries/Upload.php @@ -578,7 +578,7 @@ class CI_Upload { $mime = $this->mimes_types(strtolower($val)); // Images get some additional checks - if (in_array($val, $image_types)) + if ($this->file_ext == '.' . $val && in_array($val, $image_types)) { if (getimagesize($this->file_temp) === FALSE) { -- cgit v1.2.3-24-g4f1b From 52c592bb08ad5fbc4ded7aedaa81e2f3fb329b8c Mon Sep 17 00:00:00 2001 From: Derek Jones Date: Thu, 22 Apr 2010 16:36:40 -0500 Subject: tiny modification to whitespace from philsturgeon's bugfix to match CI style guidelines --- system/libraries/Upload.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system') diff --git a/system/libraries/Upload.php b/system/libraries/Upload.php index 0e71aee6b..b85663bcc 100644 --- a/system/libraries/Upload.php +++ b/system/libraries/Upload.php @@ -578,7 +578,7 @@ class CI_Upload { $mime = $this->mimes_types(strtolower($val)); // Images get some additional checks - if ($this->file_ext == '.' . $val && in_array($val, $image_types)) + if ($this->file_ext == '.'.$val && in_array($val, $image_types)) { if (getimagesize($this->file_temp) === FALSE) { -- cgit v1.2.3-24-g4f1b From dcae4490998dc111d265da11507c0dad660eb1b4 Mon Sep 17 00:00:00 2001 From: Phil Sturgeon Date: Thu, 22 Apr 2010 13:34:09 +0100 Subject: Some mime types are wrapped with " which breaks file type checking. This will remove any wrapping \ and " --- system/libraries/Upload.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system') diff --git a/system/libraries/Upload.php b/system/libraries/Upload.php index b85663bcc..751044968 100644 --- a/system/libraries/Upload.php +++ b/system/libraries/Upload.php @@ -190,7 +190,7 @@ class CI_Upload { $this->file_name = $this->_prep_filename($_FILES[$field]['name']); $this->file_size = $_FILES[$field]['size']; $this->file_type = preg_replace("/^(.+?);.*$/", "\\1", $_FILES[$field]['type']); - $this->file_type = strtolower($this->file_type); + $this->file_type = trim(stripslashes($this->file_type), '"'); $this->file_ext = $this->get_extension($_FILES[$field]['name']); // Convert the file size to kilobytes -- cgit v1.2.3-24-g4f1b From 616fb0281ba4bd2339accc47c0a94f7034c61a1a Mon Sep 17 00:00:00 2001 From: Derek Jones Date: Thu, 22 Apr 2010 16:52:18 -0500 Subject: reapplied strtolower() to ->file_type from philsturgeon's changeset 5fe3b04bdf44 to standardize input --- system/libraries/Upload.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system') diff --git a/system/libraries/Upload.php b/system/libraries/Upload.php index 751044968..3227c3747 100644 --- a/system/libraries/Upload.php +++ b/system/libraries/Upload.php @@ -190,7 +190,7 @@ class CI_Upload { $this->file_name = $this->_prep_filename($_FILES[$field]['name']); $this->file_size = $_FILES[$field]['size']; $this->file_type = preg_replace("/^(.+?);.*$/", "\\1", $_FILES[$field]['type']); - $this->file_type = trim(stripslashes($this->file_type), '"'); + $this->file_type = strtolower(trim(stripslashes($this->file_type), '"')); $this->file_ext = $this->get_extension($_FILES[$field]['name']); // Convert the file size to kilobytes -- cgit v1.2.3-24-g4f1b From 5640a7158559f4521911444b50798a6a9536f38b Mon Sep 17 00:00:00 2001 From: Derek Jones Date: Fri, 23 Apr 2010 11:22:40 -0500 Subject: ensured the security lib was loaded in a few calls to xss_clean() in other libraries. Fixes #35 --- system/libraries/Form_validation.php | 7 ++++++- system/libraries/Upload.php | 7 ++++++- system/libraries/Xmlrpc.php | 10 ++++++++++ 3 files changed, 22 insertions(+), 2 deletions(-) (limited to 'system') diff --git a/system/libraries/Form_validation.php b/system/libraries/Form_validation.php index bb70f0f7f..73cb6b853 100644 --- a/system/libraries/Form_validation.php +++ b/system/libraries/Form_validation.php @@ -1254,7 +1254,12 @@ class CI_Form_validation { */ function xss_clean($str) { - return $this->CI->input->xss_clean($str); + if ( ! is_object($this->CI->security)) + { + $this->CI->load('security'); + } + + return $this->CI->security->xss_clean($str); } // -------------------------------------------------------------------- diff --git a/system/libraries/Upload.php b/system/libraries/Upload.php index 3227c3747..d7cf236f8 100644 --- a/system/libraries/Upload.php +++ b/system/libraries/Upload.php @@ -854,7 +854,12 @@ class CI_Upload { } $CI =& get_instance(); - + + if ( ! is_object($CI->security)) + { + $CI->load('security'); + } + return $CI->security->xss_clean($data, TRUE); } diff --git a/system/libraries/Xmlrpc.php b/system/libraries/Xmlrpc.php index e2b149b73..ee65398ec 100644 --- a/system/libraries/Xmlrpc.php +++ b/system/libraries/Xmlrpc.php @@ -505,6 +505,11 @@ class XML_RPC_Response { $CI =& get_instance(); + if ($this->xss_clean && ! is_object($CI->security)) + { + $CI->load('security'); + } + if ($array !== FALSE && is_array($array)) { while (list($key) = each($array)) @@ -1119,6 +1124,11 @@ class XML_RPC_Message extends CI_Xmlrpc { $CI =& get_instance(); + if ($this->xss_clean && ! is_object($CI->security)) + { + $CI->load('security'); + } + if ($array !== FALSE && is_array($array)) { while (list($key) = each($array)) -- cgit v1.2.3-24-g4f1b From 78a1cf24831e067aae04531718a167e8ec144fda Mon Sep 17 00:00:00 2001 From: Roger Simms Date: Sun, 25 Apr 2010 12:50:53 +0100 Subject: Simple change to comment line 21: the=>that. --- system/core/Controller.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system') diff --git a/system/core/Controller.php b/system/core/Controller.php index 92f7f17f1..c9d797ca2 100644 --- a/system/core/Controller.php +++ b/system/core/Controller.php @@ -18,7 +18,7 @@ /** * CodeIgniter Application Controller Class * - * This class object is the super class the every library in + * This class object is the super class that every library in * CodeIgniter will be assigned to. * * @package CodeIgniter -- cgit v1.2.3-24-g4f1b From 30841679f57da9de8053c8291a665043f8f92c03 Mon Sep 17 00:00:00 2001 From: Derek Jones Date: Mon, 26 Apr 2010 09:09:21 -0500 Subject: fixed errant syntax in changeset 53ace78c4b45, fixes #37 --- system/libraries/Form_validation.php | 6 +++--- system/libraries/Upload.php | 2 +- system/libraries/Xmlrpc.php | 8 ++++---- 3 files changed, 8 insertions(+), 8 deletions(-) (limited to 'system') diff --git a/system/libraries/Form_validation.php b/system/libraries/Form_validation.php index 73cb6b853..64baaef25 100644 --- a/system/libraries/Form_validation.php +++ b/system/libraries/Form_validation.php @@ -1254,11 +1254,11 @@ class CI_Form_validation { */ function xss_clean($str) { - if ( ! is_object($this->CI->security)) + if ( ! isset($this->CI->security)) { - $this->CI->load('security'); + $this->CI->load->library('security'); } - + return $this->CI->security->xss_clean($str); } diff --git a/system/libraries/Upload.php b/system/libraries/Upload.php index d7cf236f8..b3c625eb1 100644 --- a/system/libraries/Upload.php +++ b/system/libraries/Upload.php @@ -855,7 +855,7 @@ class CI_Upload { $CI =& get_instance(); - if ( ! is_object($CI->security)) + if ( ! isset($CI->security)) { $CI->load('security'); } diff --git a/system/libraries/Xmlrpc.php b/system/libraries/Xmlrpc.php index ee65398ec..ff03a503a 100644 --- a/system/libraries/Xmlrpc.php +++ b/system/libraries/Xmlrpc.php @@ -505,9 +505,9 @@ class XML_RPC_Response { $CI =& get_instance(); - if ($this->xss_clean && ! is_object($CI->security)) + if ($this->xss_clean && ! isset($CI->security)) { - $CI->load('security'); + $CI->load->library('security'); } if ($array !== FALSE && is_array($array)) @@ -1124,9 +1124,9 @@ class XML_RPC_Message extends CI_Xmlrpc { $CI =& get_instance(); - if ($this->xss_clean && ! is_object($CI->security)) + if ($this->xss_clean && ! isset($CI->security)) { - $CI->load('security'); + $CI->load->library('security'); } if ($array !== FALSE && is_array($array)) -- cgit v1.2.3-24-g4f1b From 247f02925e04a8a45f2e6e9acbf72ccd6848fd32 Mon Sep 17 00:00:00 2001 From: Derek Jones Date: Mon, 26 Apr 2010 09:10:21 -0500 Subject: fixed errant syntax in changeset 53ace78c4b45, fixes #37 --- system/libraries/Upload.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system') diff --git a/system/libraries/Upload.php b/system/libraries/Upload.php index b3c625eb1..7a5eef0f3 100644 --- a/system/libraries/Upload.php +++ b/system/libraries/Upload.php @@ -857,7 +857,7 @@ class CI_Upload { if ( ! isset($CI->security)) { - $CI->load('security'); + $CI->load->library('security'); } return $CI->security->xss_clean($data, TRUE); -- cgit v1.2.3-24-g4f1b From e602683aa6362e2efeb03408cea749cfeaaeef4f Mon Sep 17 00:00:00 2001 From: Greg Aker Date: Thu, 29 Apr 2010 13:41:39 -0500 Subject: Changing order of available sections in the output profiler. --- system/libraries/Profiler.php | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) (limited to 'system') diff --git a/system/libraries/Profiler.php b/system/libraries/Profiler.php index 3285bc531..49a6774c1 100644 --- a/system/libraries/Profiler.php +++ b/system/libraries/Profiler.php @@ -36,14 +36,14 @@ class CI_Profiler { var $_available_sections = array( 'benchmarks', - 'config', - 'controller_info', 'get', - 'http_headers', 'memory_usage', 'post', + 'uri_string', + 'controller_info', 'queries', - 'uri_string' + 'http_headers', + 'config' ); function CI_Profiler($config = array()) @@ -459,6 +459,11 @@ class CI_Profiler { foreach($this->CI->config->config as $config=>$val) { + if (is_array($val)) + { + $val = print_r($val, TRUE); + } + $output .= "".$config."  ".$val."\n"; } -- cgit v1.2.3-24-g4f1b From 26872de184e4aa2ae92bae645782089e9656115d Mon Sep 17 00:00:00 2001 From: Phil Sturgeon Date: Tue, 11 May 2010 11:41:59 +0100 Subject: Added an option to remove the preceding trail of empty folders when creating a Zip archive. --- system/libraries/Zip.php | 49 ++++++++++++++++++++++++++++++++++-------------- 1 file changed, 35 insertions(+), 14 deletions(-) (limited to 'system') diff --git a/system/libraries/Zip.php b/system/libraries/Zip.php index 2c4bd255d..3ba3ddc83 100644 --- a/system/libraries/Zip.php +++ b/system/libraries/Zip.php @@ -270,27 +270,48 @@ class CI_Zip { * @access public * @param string path to source * @return bool - */ - function read_dir($path) - { - if ($fp = @opendir($path)) + */ + 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))) { - while (FALSE !== ($file = readdir($fp))) + if(substr($file, 0, 1) == '.') { - if (@is_dir($path.$file) && substr($file, 0, 1) != '.') - { - $this->read_dir($path.$file."/"); - } - elseif (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))) { - if (FALSE !== ($data = file_get_contents($path.$file))) - { - $this->add_data(str_replace("\\", "/", $path).$file, $data); + $name = str_replace("\\", "/", $path); + + if ($preserve_filepath === FALSE) + { + $name = str_replace($root_path, '', $name); } + + $this->add_data($name.$file, $data); } } - return TRUE; } + return TRUE; } // -------------------------------------------------------------------- -- cgit v1.2.3-24-g4f1b From 2735b3eeb3403ba813aac56ed6f10be536839ff6 Mon Sep 17 00:00:00 2001 From: Derek Jones Date: Tue, 11 May 2010 08:58:21 -0500 Subject: fixed whitespace, massaged Zip read_dir() docs --- system/libraries/Zip.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'system') diff --git a/system/libraries/Zip.php b/system/libraries/Zip.php index 3ba3ddc83..92dfc814d 100644 --- a/system/libraries/Zip.php +++ b/system/libraries/Zip.php @@ -273,7 +273,7 @@ class CI_Zip { */ function read_dir($path, $preserve_filepath = TRUE, $root_path = NULL) { - if (!$fp = @opendir($path)) + if ( ! $fp = @opendir($path)) { return FALSE; } @@ -295,7 +295,6 @@ class CI_Zip { { $this->read_dir($path.$file."/", $preserve_filepath, $root_path); } - else { if (FALSE !== ($data = file_get_contents($path.$file))) @@ -311,6 +310,7 @@ class CI_Zip { } } } + return TRUE; } -- cgit v1.2.3-24-g4f1b From 511e3d72b875401b5cc61a28df45fb65acfd689a Mon Sep 17 00:00:00 2001 From: Derek Jones Date: Thu, 13 May 2010 09:03:30 -0500 Subject: added htmlspecialchars to config item output, fixes #41 --- system/libraries/Profiler.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'system') diff --git a/system/libraries/Profiler.php b/system/libraries/Profiler.php index 49a6774c1..0900a300d 100644 --- a/system/libraries/Profiler.php +++ b/system/libraries/Profiler.php @@ -303,7 +303,7 @@ class CI_Profiler { $output .= "$_POST[".$key."]   "; if (is_array($val)) { - $output .= "
    " . htmlspecialchars(stripslashes(print_r($val, true))) . "
    "; + $output .= "
    " . htmlspecialchars(stripslashes(print_r($val, TRUE))) . "
    "; } else { @@ -464,7 +464,7 @@ class CI_Profiler { $val = print_r($val, TRUE); } - $output .= "".$config."  ".$val."\n"; + $output .= "".$config."  ".htmlspecialchars($val)."\n"; } $output .= "\n"; -- cgit v1.2.3-24-g4f1b From 23e796f7561832a929c1a78c1fb60667563b0756 Mon Sep 17 00:00:00 2001 From: Derek Jones Date: Fri, 21 May 2010 12:45:25 -0500 Subject: fixed a bug in the Parser where the regex would not correctly match pair variables, fixes #42 --- system/libraries/Parser.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system') diff --git a/system/libraries/Parser.php b/system/libraries/Parser.php index 9387f1a9a..41a438bac 100644 --- a/system/libraries/Parser.php +++ b/system/libraries/Parser.php @@ -197,7 +197,7 @@ class CI_Parser { */ 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)) + 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; } -- cgit v1.2.3-24-g4f1b From 2a6c1da49b38abb8767192a064b8c6b01d1e421e Mon Sep 17 00:00:00 2001 From: Robin Sowell Date: Mon, 24 May 2010 12:20:03 -0400 Subject: Added $prefix, $suffix and $first_url properties to Pagination library. --- system/libraries/Pagination.php | 36 ++++++++++++++++++++++++++++++------ 1 file changed, 30 insertions(+), 6 deletions(-) (limited to 'system') diff --git a/system/libraries/Pagination.php b/system/libraries/Pagination.php index d6321f41c..ccd3e8261 100644 --- a/system/libraries/Pagination.php +++ b/system/libraries/Pagination.php @@ -27,6 +27,9 @@ class CI_Pagination { var $base_url = ''; // The page we are linking to + var $prefix = ''; // A custom prefix added to the path. + var $suffix = ''; // A custom suffix added to the path. + var $total_rows = ''; // Total number of items (database results) var $per_page = 10; // Max number of items you want shown per page var $num_links = 2; // Number of "digit" links to show before/after the currently viewed page @@ -42,6 +45,7 @@ class CI_Pagination { var $first_tag_close = ' '; var $last_tag_open = ' '; var $last_tag_close = ''; + var $first_url = ''; // Alternative URL for the First Page. var $cur_tag_open = ' '; var $cur_tag_close = ''; var $next_tag_open = ' '; @@ -185,15 +189,25 @@ class CI_Pagination { // Render the "First" link if ($this->cur_page > ($this->num_links + 1)) { - $output .= $this->first_tag_open.''.$this->first_link.''.$this->first_tag_close; + $first_url = ($this->first_url == '') ? $this->base_url : $this->first_url; + $output .= $this->first_tag_open.''.$this->first_link.''.$this->first_tag_close; } // Render the "previous" link if ($this->cur_page != 1) { $i = $uri_page_number - $this->per_page; - if ($i == 0) $i = ''; - $output .= $this->prev_tag_open.''.$this->prev_link.''.$this->prev_tag_close; + + if ($i == 0 && $this->first_url != '') + { + $output .= $this->prev_tag_open.''.$this->prev_link.''.$this->prev_tag_close; + } + else + { + $i = ($i == 0) ? '' : $this->prefix.$i.$this->suffix; + $output .= $this->prev_tag_open.''.$this->prev_link.''.$this->prev_tag_close; + } + } // Write the digit links @@ -210,7 +224,17 @@ class CI_Pagination { else { $n = ($i == 0) ? '' : $i; - $output .= $this->num_tag_open.''.$loop.''.$this->num_tag_close; + + if ($n == '' && $this->first_url != '') + { + $output .= $this->num_tag_open.''.$loop.''.$this->num_tag_close; + } + else + { + $n = ($n == '') ? '' : $this->prefix.$n.$this->suffix; + + $output .= $this->num_tag_open.''.$loop.''.$this->num_tag_close; + } } } } @@ -218,14 +242,14 @@ class CI_Pagination { // Render the "next" link if ($this->cur_page < $num_pages) { - $output .= $this->next_tag_open.''.$this->next_link.''.$this->next_tag_close; + $output .= $this->next_tag_open.''.$this->next_link.''.$this->next_tag_close; } // Render the "Last" link if (($this->cur_page + $this->num_links) < $num_pages) { $i = (($num_pages * $this->per_page) - $this->per_page); - $output .= $this->last_tag_open.''.$this->last_link.''.$this->last_tag_close; + $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 -- cgit v1.2.3-24-g4f1b From c78a259b4af7430f237636b5f93d6eb59443a1e2 Mon Sep 17 00:00:00 2001 From: Greg Aker Date: Wed, 9 Jun 2010 11:45:32 -0500 Subject: Fixed an undefined variable PHP error in the do_xss_clean() method of the Upload library. --- system/libraries/Upload.php | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) (limited to 'system') diff --git a/system/libraries/Upload.php b/system/libraries/Upload.php index 7a5eef0f3..8bdb4be19 100644 --- a/system/libraries/Upload.php +++ b/system/libraries/Upload.php @@ -812,13 +812,13 @@ class CI_Upload { { $current = ini_get('memory_limit') * 1024 * 1024; - // There was a bug/behavioural change in PHP 5.2, where numbers over one million get output - // into scientific notation. number_format() ensures this number is an integer - // http://bugs.php.net/bug.php?id=43053 - - $new_memory = number_format(ceil(filesize($this->new_name) + $current), 0, '.', ''); - - ini_set('memory_limit', $new_memory); // When an integer is used, the value is measured in bytes. - PHP.net + // There was a bug/behavioural change in PHP 5.2, where numbers over one million get output + // into scientific notation. number_format() ensures this number is an integer + // http://bugs.php.net/bug.php?id=43053 + + $new_memory = number_format(ceil(filesize($file) + $current), 0, '.', ''); + + ini_set('memory_limit', $new_memory); // When an integer is used, the value is measured in bytes. - PHP.net } // If the file being uploaded is an image, then we should have no problem with XSS attacks (in theory), but -- cgit v1.2.3-24-g4f1b From a0905f33eabec71e411c837967750e15d6febf19 Mon Sep 17 00:00:00 2001 From: Derek Allard Date: Mon, 5 Jul 2010 08:11:33 -0400 Subject: img() will now generate an empty string as an alt attribute if one is not provided. --- system/helpers/html_helper.php | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'system') diff --git a/system/helpers/html_helper.php b/system/helpers/html_helper.php index 4afa678a3..cd7b4ce6b 100644 --- a/system/helpers/html_helper.php +++ b/system/helpers/html_helper.php @@ -199,6 +199,12 @@ if ( ! function_exists('img')) $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) -- cgit v1.2.3-24-g4f1b From 96bb75cd4e9b1cbd82fe7496e9b831054c8228f1 Mon Sep 17 00:00:00 2001 From: Derek Allard Date: Mon, 5 Jul 2010 10:54:30 -0400 Subject: Added the ability to suppress first, previous, next and last links by setting their values to FALSE in the pagination library. --- system/libraries/Pagination.php | 28 +++++++++++++++++----------- 1 file changed, 17 insertions(+), 11 deletions(-) (limited to 'system') diff --git a/system/libraries/Pagination.php b/system/libraries/Pagination.php index ccd3e8261..68c35a57e 100644 --- a/system/libraries/Pagination.php +++ b/system/libraries/Pagination.php @@ -56,6 +56,7 @@ class CI_Pagination { var $num_tag_close = ''; var $page_query_string = FALSE; var $query_string_segment = 'per_page'; + var $anchor_class = ''; /** * Constructor @@ -70,6 +71,11 @@ class CI_Pagination { $this->initialize($params); } + if ($this->anchor_class != '') + { + $this->anchor_class = 'class="'.$this->anchor_class.'" '; + } + log_message('debug', "Pagination Class Initialized"); } @@ -187,25 +193,25 @@ class CI_Pagination { $output = ''; // Render the "First" link - if ($this->cur_page > ($this->num_links + 1)) + 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.''.$this->first_link.''.$this->first_tag_close; + $output .= $this->first_tag_open.'anchor_class.'href="'.$first_url.'">'.$this->first_link.''.$this->first_tag_close; } // Render the "previous" link - if ($this->cur_page != 1) + if ($this->prev_link !== FALSE AND $this->cur_page != 1) { $i = $uri_page_number - $this->per_page; if ($i == 0 && $this->first_url != '') { - $output .= $this->prev_tag_open.''.$this->prev_link.''.$this->prev_tag_close; + $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.''.$this->prev_link.''.$this->prev_tag_close; + $output .= $this->prev_tag_open.'anchor_class.'href="'.$this->base_url.$i.'">'.$this->prev_link.''.$this->prev_tag_close; } } @@ -227,29 +233,29 @@ class CI_Pagination { if ($n == '' && $this->first_url != '') { - $output .= $this->num_tag_open.''.$loop.''.$this->num_tag_close; + $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.''.$loop.''.$this->num_tag_close; + $output .= $this->num_tag_open.'anchor_class.'href="'.$this->base_url.$n.'">'.$loop.''.$this->num_tag_close; } } } } // Render the "next" link - if ($this->cur_page < $num_pages) + if ($this->next_link !== FALSE AND $this->cur_page < $num_pages) { - $output .= $this->next_tag_open.''.$this->next_link.''.$this->next_tag_close; + $output .= $this->next_tag_open.'anchor_class.'href="'.$this->base_url.$this->prefix.($this->cur_page * $this->per_page).$this->suffix.'">'.$this->next_link.''.$this->next_tag_close; } // Render the "Last" link - if (($this->cur_page + $this->num_links) < $num_pages) + if ($this->last_link !== FALSE AND ($this->cur_page + $this->num_links) < $num_pages) { $i = (($num_pages * $this->per_page) - $this->per_page); - $output .= $this->last_tag_open.''.$this->last_link.''.$this->last_tag_close; + $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 -- cgit v1.2.3-24-g4f1b From e01fd0fc3b694d12dc6b968727bd7f21f8c1a0fb Mon Sep 17 00:00:00 2001 From: Derek Allard Date: Mon, 5 Jul 2010 11:06:07 -0400 Subject: suppress page list --- system/libraries/Pagination.php | 37 +++++++++++++++++++++---------------- 1 file changed, 21 insertions(+), 16 deletions(-) (limited to 'system') diff --git a/system/libraries/Pagination.php b/system/libraries/Pagination.php index 68c35a57e..3a0632d09 100644 --- a/system/libraries/Pagination.php +++ b/system/libraries/Pagination.php @@ -56,6 +56,7 @@ class CI_Pagination { var $num_tag_close = ''; var $page_query_string = FALSE; var $query_string_segment = 'per_page'; + var $display_pages = TRUE; var $anchor_class = ''; /** @@ -216,30 +217,34 @@ class CI_Pagination { } - // Write the digit links - for ($loop = $start -1; $loop <= $end; $loop++) + // Render the pages + if ($this->display_pages !== FALSE) { - $i = ($loop * $this->per_page) - $this->per_page; - - if ($i >= 0) + // Write the digit links + for ($loop = $start -1; $loop <= $end; $loop++) { - if ($this->cur_page == $loop) - { - $output .= $this->cur_tag_open.$loop.$this->cur_tag_close; // Current page - } - else + $i = ($loop * $this->per_page) - $this->per_page; + + if ($i >= 0) { - $n = ($i == 0) ? '' : $i; - - if ($n == '' && $this->first_url != '') + if ($this->cur_page == $loop) { - $output .= $this->num_tag_open.'anchor_class.'href="'.$this->first_url.'">'.$loop.''.$this->num_tag_close; + $output .= $this->cur_tag_open.$loop.$this->cur_tag_close; // Current page } else { - $n = ($n == '') ? '' : $this->prefix.$n.$this->suffix; + $n = ($i == 0) ? '' : $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; + $output .= $this->num_tag_open.'anchor_class.'href="'.$this->base_url.$n.'">'.$loop.''.$this->num_tag_close; + } } } } -- cgit v1.2.3-24-g4f1b From e9d723fb2c13585fa8a502fde7dd83dc334874ff Mon Sep 17 00:00:00 2001 From: Derek Jones Date: Mon, 12 Jul 2010 10:10:59 -0500 Subject: 201007 file upload bug fix --- system/libraries/Upload.php | 194 +++++++++++++++++++++++++------------------- 1 file changed, 109 insertions(+), 85 deletions(-) (limited to 'system') diff --git a/system/libraries/Upload.php b/system/libraries/Upload.php index 8bdb4be19..c94e4d448 100644 --- a/system/libraries/Upload.php +++ b/system/libraries/Upload.php @@ -26,31 +26,34 @@ */ class CI_Upload { - var $max_size = 0; - var $max_width = 0; - var $max_height = 0; - var $max_filename = 0; - var $allowed_types = ""; - var $file_temp = ""; - var $file_name = ""; - var $orig_name = ""; - var $file_type = ""; - var $file_size = ""; - var $file_ext = ""; - var $upload_path = ""; - var $overwrite = FALSE; - var $encrypt_name = FALSE; - var $is_image = FALSE; - var $image_width = ''; - var $image_height = ''; - var $image_type = ''; - var $image_size_str = ''; - var $error_msg = array(); - var $mimes = array(); - var $remove_spaces = TRUE; - var $xss_clean = FALSE; - var $temp_prefix = "temp_file_"; - + var $max_size = 0; + var $max_width = 0; + var $max_height = 0; + var $max_filename = 0; + var $allowed_types = ""; + var $file_temp = ""; + var $file_name = ""; + var $orig_name = ""; + var $file_type = ""; + var $file_size = ""; + var $file_ext = ""; + var $upload_path = ""; + var $overwrite = FALSE; + var $encrypt_name = FALSE; + var $is_image = FALSE; + var $image_width = ''; + var $image_height = ''; + var $image_type = ''; + var $image_size_str = ''; + var $error_msg = array(); + var $mimes = array(); + var $remove_spaces = TRUE; + var $xss_clean = FALSE; + var $temp_prefix = "temp_file_"; + var $client_name = ''; + + var $_file_name_override = ''; //@PHP4 (should be private) + /** * Constructor * @@ -75,6 +78,7 @@ class CI_Upload { * @param array * @return void */ + function initialize($config = array()) { $defaults = array( @@ -101,7 +105,8 @@ class CI_Upload { 'mimes' => array(), 'remove_spaces' => TRUE, 'xss_clean' => FALSE, - 'temp_prefix' => "temp_file_" + 'temp_prefix' => "temp_file_", + 'client_name' => '' ); @@ -124,6 +129,10 @@ class CI_Upload { $this->$key = $val; } } + + // if a file_name was provided in the config, use it instead of the user input + // supplied file name for all uploads until initialized again + $this->_file_name_override = $this->file_name; } // -------------------------------------------------------------------- @@ -185,20 +194,16 @@ class CI_Upload { return FALSE; } + // Set the uploaded data as class variables $this->file_temp = $_FILES[$field]['tmp_name']; - $this->file_name = $this->_prep_filename($_FILES[$field]['name']); - $this->file_size = $_FILES[$field]['size']; + $this->file_size = $_FILES[$field]['size']; $this->file_type = preg_replace("/^(.+?);.*$/", "\\1", $_FILES[$field]['type']); $this->file_type = strtolower(trim(stripslashes($this->file_type), '"')); - $this->file_ext = $this->get_extension($_FILES[$field]['name']); + $this->file_name = $this->_prep_filename($_FILES[$field]['name']); + $this->file_ext = $this->get_extension($this->file_name); + $this->client_name = $this->file_name; - // Convert the file size to kilobytes - if ($this->file_size > 0) - { - $this->file_size = round($this->file_size/1024, 2); - } - // Is the file type allowed to be uploaded? if ( ! $this->is_allowed_filetype()) { @@ -206,6 +211,25 @@ class CI_Upload { return FALSE; } + // if we're overriding, let's now make sure the new name and type is allowed + if ($this->_file_name_override != '') + { + $this->file_name = $this->_prep_filename($this->_file_name_override); + $this->file_ext = $this->get_extension($this->file_name); + + if ( ! $this->is_allowed_filetype(TRUE)) + { + $this->set_error('upload_invalid_filetype'); + return FALSE; + } + } + + // Convert the file size to kilobytes + if ($this->file_size > 0) + { + $this->file_size = round($this->file_size/1024, 2); + } + // Is the file size within the allowed maximum? if ( ! $this->is_allowed_filesize()) { @@ -254,6 +278,21 @@ class CI_Upload { } } + /* + * Run the file through the XSS hacking filter + * This helps prevent malicious code from being + * embedded within a file. Scripts can easily + * be disguised as images or other file types. + */ + if ($this->xss_clean) + { + if ($this->do_xss_clean() === FALSE) + { + $this->set_error('upload_unable_to_write_file'); + return FALSE; + } + } + /* * Move the file to the final destination * To deal with different server configurations @@ -269,21 +308,6 @@ class CI_Upload { return FALSE; } } - - /* - * Run the file through the XSS hacking filter - * This helps prevent malicious code from being - * embedded within a file. Scripts can easily - * be disguised as images or other file types. - */ - if ($this->xss_clean) - { - if ($this->do_xss_clean() === FALSE) - { - $this->set_error('upload_unable_to_write_file'); - return FALSE; - } - } /* * Set the finalized image dimensions @@ -316,6 +340,7 @@ class CI_Upload { 'full_path' => $this->upload_path.$this->file_name, 'raw_name' => str_replace($this->file_ext, '', $this->file_name), 'orig_name' => $this->orig_name, + 'client_name' => $this->client_name, 'file_ext' => $this->file_ext, 'file_size' => $this->file_size, 'is_image' => $this->is_image(), @@ -558,7 +583,7 @@ class CI_Upload { * @access public * @return bool */ - function is_allowed_filetype() + function is_allowed_filetype($ignore_mime = FALSE) { if ($this->allowed_types == '*') { @@ -570,36 +595,42 @@ class CI_Upload { $this->set_error('upload_no_file_types'); return FALSE; } + + $ext = strtolower(ltrim($this->file_ext, '.')); + + if ( ! in_array($ext, $this->allowed_types)) + { + return FALSE; + } + // Images get some additional checks $image_types = array('gif', 'jpg', 'jpeg', 'png', 'jpe'); - - foreach ($this->allowed_types as $val) + + if (in_array($ext, $image_types)) { - $mime = $this->mimes_types(strtolower($val)); - - // Images get some additional checks - if ($this->file_ext == '.'.$val && in_array($val, $image_types)) + if (getimagesize($this->file_temp) === FALSE) { - if (getimagesize($this->file_temp) === FALSE) - { - return FALSE; - } - } - - if (is_array($mime)) - { - if (in_array($this->file_type, $mime, TRUE)) - { - return TRUE; - } - } - else + return FALSE; + } + } + + if ($ignore_mime === TRUE) + { + return TRUE; + } + + $mime = $this->mimes_types($ext); + + if (is_array($mime)) + { + if (in_array($this->file_type, $mime, TRUE)) { - if ($mime == $this->file_type) - { - return TRUE; - } - } + return TRUE; + } + } + elseif ($mime == $this->file_type) + { + return TRUE; } return FALSE; @@ -801,7 +832,7 @@ class CI_Upload { */ function do_xss_clean() { - $file = $this->upload_path.$this->file_name; + $file = $this->file_temp; if (filesize($file) == 0) { @@ -968,7 +999,7 @@ class CI_Upload { foreach ($parts as $part) { - if ($this->mimes_types(strtolower($part)) === FALSE) + if ( ! in_array(strtolower($part), $this->allowed_types) OR $this->mimes_types(strtolower($part)) === FALSE) { $filename .= '.'.$part.'_'; } @@ -978,13 +1009,6 @@ class CI_Upload { } } - // file name override, since the exact name is provided, no need to - // run it through a $this->mimes check. - if ($this->file_name != '') - { - $filename = $this->file_name; - } - $filename .= '.'.$ext; return $filename; -- cgit v1.2.3-24-g4f1b From ce3129d277d2235f0584a937114d0e636349ee9c Mon Sep 17 00:00:00 2001 From: Greg Aker Date: Fri, 16 Jul 2010 10:01:48 -0500 Subject: Removing validation_lang.php file that was missed when removing the Validation library. --- system/language/english/validation_lang.php | 21 --------------------- 1 file changed, 21 deletions(-) delete mode 100644 system/language/english/validation_lang.php (limited to 'system') diff --git a/system/language/english/validation_lang.php b/system/language/english/validation_lang.php deleted file mode 100644 index 345341fe7..000000000 --- a/system/language/english/validation_lang.php +++ /dev/null @@ -1,21 +0,0 @@ - Date: Thu, 22 Jul 2010 11:04:58 -0500 Subject: Fixed a bug in the Upload class where a PHP error could occur when wildcards were used as the allowed_types. --- system/libraries/Upload.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'system') diff --git a/system/libraries/Upload.php b/system/libraries/Upload.php index c94e4d448..c18c178df 100644 --- a/system/libraries/Upload.php +++ b/system/libraries/Upload.php @@ -988,7 +988,7 @@ class CI_Upload { */ function _prep_filename($filename) { - if (strpos($filename, '.') === FALSE) + if (strpos($filename, '.') === FALSE OR $this->allowed_types == '*') { return $filename; } @@ -1020,4 +1020,4 @@ class CI_Upload { // END Upload Class /* End of file Upload.php */ -/* Location: ./system/libraries/Upload.php */ \ No newline at end of file +/* Location: ./system/libraries/Upload.php */ -- cgit v1.2.3-24-g4f1b From 958543a38c2c97b0ec4c10fc9faf4f0753143880 Mon Sep 17 00:00:00 2001 From: Derek Allard Date: Thu, 22 Jul 2010 14:10:26 -0400 Subject: Adding CSRF into config Adding CSRF token into form open() --- system/helpers/form_helper.php | 6 ++++++ system/libraries/Security.php | 16 +++++++++++----- 2 files changed, 17 insertions(+), 5 deletions(-) (limited to 'system') diff --git a/system/helpers/form_helper.php b/system/helpers/form_helper.php index 5feb3ce66..632f94505 100644 --- a/system/helpers/form_helper.php +++ b/system/helpers/form_helper.php @@ -62,6 +62,12 @@ if ( ! function_exists('form_open')) $form .= form_hidden($hidden); } + // CSRF + if ($CI->config->item('csrf_protection') === TRUE) + { + $form .= form_hidden($CI->security->csrf_token_name, $CI->security->csrf_hash); + } + return $form; } } diff --git a/system/libraries/Security.php b/system/libraries/Security.php index cdae50168..c8d435046 100644 --- a/system/libraries/Security.php +++ b/system/libraries/Security.php @@ -54,7 +54,7 @@ class CI_Security { { // Set the CSRF hash $this->_csrf_set_hash(); - + log_message('debug', "Security Class Initialized"); } @@ -67,21 +67,24 @@ class CI_Security { * @return null */ function csrf_verify() - { + { // If no POST data exists we will set the CSRF cookie if (count($_POST) == 0) { return $this->csrf_set_cookie(); } + // Append application specific cookie prefix to token name + $csrf_token_name = (config_item('cookie_prefix')) ? config_item('cookie_prefix').$this->csrf_token_name : $this->csrf_token_name; + // Do the tokens exist in both the _POST and _COOKIE arrays? - if ( ! isset($_POST[$this->csrf_token_name]) OR ! isset($_COOKIE[$this->csrf_token_name])) + if ( ! isset($_POST[$this->csrf_token_name]) OR ! isset($_COOKIE[$csrf_token_name])) { $this->csrf_show_error(); } // Do the tokens match? - if ($_POST[$this->csrf_token_name] != $_COOKIE[$this->csrf_token_name]) + if ($_POST[$this->csrf_token_name] != $_COOKIE[$csrf_token_name]) { $this->csrf_show_error(); } @@ -134,7 +137,10 @@ class CI_Security { $this->csrf_hash = md5(uniqid(rand(), TRUE)); } } - + + // Create the cookie before we finish up + $this->csrf_set_cookie(); + return $this->csrf_hash; } -- cgit v1.2.3-24-g4f1b From 4433f424d7a0dd7e5863ddd5393c13be377ed6ce Mon Sep 17 00:00:00 2001 From: Derek Allard Date: Fri, 23 Jul 2010 08:47:34 -0400 Subject: adding sanitize_filename() into the security helper --- system/helpers/security_helper.php | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) (limited to 'system') diff --git a/system/helpers/security_helper.php b/system/helpers/security_helper.php index 654cfd100..63f0e9cdb 100644 --- a/system/helpers/security_helper.php +++ b/system/helpers/security_helper.php @@ -44,6 +44,24 @@ if ( ! function_exists('xss_clean')) } } +// ------------------------------------------------------------------------ + +/** + * 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); + } +} + // -------------------------------------------------------------------- /** -- cgit v1.2.3-24-g4f1b From b3f10a23e4eb51f9236af0647eee4607776fee23 Mon Sep 17 00:00:00 2001 From: Derek Jones Date: Sun, 25 Jul 2010 19:11:26 -0500 Subject: separated the CSRF cookie name from the token, forced new token on successful POST --- system/libraries/Security.php | 29 +++++++++++++++-------------- 1 file changed, 15 insertions(+), 14 deletions(-) (limited to 'system') diff --git a/system/libraries/Security.php b/system/libraries/Security.php index c8d435046..29ac2612b 100644 --- a/system/libraries/Security.php +++ b/system/libraries/Security.php @@ -29,7 +29,8 @@ class CI_Security { var $csrf_hash = ''; var $csrf_expire = 7200; // Two hours (in seconds) var $csrf_token_name = 'ci_csrf_token'; - + var $csfr_cookie_name = 'ci_csrf_token'; + /* never allowed, string replacement */ var $never_allowed_str = array( 'document.cookie' => '[removed]', @@ -52,6 +53,9 @@ class CI_Security { function CI_Security() { + // Append application specific cookie prefix to token name + $this->csfr_cookie_name = (config_item('cookie_prefix')) ? config_item('cookie_prefix').$this->csrf_token_name : $this->csrf_token_name; + // Set the CSRF hash $this->_csrf_set_hash(); @@ -74,23 +78,25 @@ class CI_Security { return $this->csrf_set_cookie(); } - // Append application specific cookie prefix to token name - $csrf_token_name = (config_item('cookie_prefix')) ? config_item('cookie_prefix').$this->csrf_token_name : $this->csrf_token_name; - // Do the tokens exist in both the _POST and _COOKIE arrays? - if ( ! isset($_POST[$this->csrf_token_name]) OR ! isset($_COOKIE[$csrf_token_name])) + if ( ! isset($_POST[$this->csrf_token_name]) OR ! isset($_COOKIE[$this->csfr_cookie_name])) { $this->csrf_show_error(); } // Do the tokens match? - if ($_POST[$this->csrf_token_name] != $_COOKIE[$csrf_token_name]) + if ($_POST[$this->csrf_token_name] != $_COOKIE[$this->csfr_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->csfr_cookie_name]); + $this->_csrf_set_hash(); + $this->csrf_set_cookie(); log_message('debug', "CSRF token verified "); } @@ -105,11 +111,9 @@ class CI_Security { */ function csrf_set_cookie() { - $prefix = ( ! is_string(config_item('cookie_prefix'))) ? '' : config_item('cookie_prefix'); - $expire = time() + $this->csrf_expire; - setcookie($prefix.$this->csrf_token_name, $this->csrf_hash, $expire, config_item('cookie_path'), config_item('cookie_domain'), 0); + setcookie($this->csfr_cookie_name, $this->csrf_hash, $expire, config_item('cookie_path'), config_item('cookie_domain'), 0); log_message('debug', "CRSF cookie Set"); } @@ -128,9 +132,9 @@ class CI_Security { { // 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_token_name]) AND $_COOKIE[$this->csrf_token_name] != '') + if (isset($_COOKIE[$this->csfr_cookie_name]) AND $_COOKIE[$this->csfr_cookie_name] != '') { - $this->csrf_hash = $_COOKIE[$this->csrf_token_name]; + $this->csrf_hash = $_COOKIE[$this->csfr_cookie_name]; } else { @@ -138,9 +142,6 @@ class CI_Security { } } - // Create the cookie before we finish up - $this->csrf_set_cookie(); - return $this->csrf_hash; } -- cgit v1.2.3-24-g4f1b From 2ddc9496e9403a59a87b644d1c2b9a106b773e46 Mon Sep 17 00:00:00 2001 From: Derek Allard Date: Thu, 5 Aug 2010 10:08:33 -0400 Subject: Added an optional second parameter to show_404() to disable logging. --- system/core/Common.php | 4 ++-- system/core/Exceptions.php | 9 +++++++-- 2 files changed, 9 insertions(+), 4 deletions(-) (limited to 'system') diff --git a/system/core/Common.php b/system/core/Common.php index 9dee591e6..2b8ad26b1 100644 --- a/system/core/Common.php +++ b/system/core/Common.php @@ -317,10 +317,10 @@ * @access public * @return void */ - function show_404($page = '') + function show_404($page = '', $log_error = TRUE) { $_error =& load_class('Exceptions', 'core'); - $_error->show_404($page); + $_error->show_404($page, $log_error); exit; } diff --git a/system/core/Exceptions.php b/system/core/Exceptions.php index 503015dfd..419ea2b61 100644 --- a/system/core/Exceptions.php +++ b/system/core/Exceptions.php @@ -88,12 +88,17 @@ class CI_Exceptions { * @param string * @return string */ - function show_404($page = '') + function show_404($page = '', $log_error = TRUE) { $heading = "404 Page Not Found"; $message = "The page you requested was not found."; - log_message('error', '404 Page Not Found --> '.$page); + // 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; } -- cgit v1.2.3-24-g4f1b From cbe3247819be75c34231ea200874044735bd853b Mon Sep 17 00:00:00 2001 From: Greg Aker Date: Thu, 5 Aug 2010 14:09:20 -0500 Subject: Adding an ellipsize function to the text helper, and associated documentation to the user guide. --- system/helpers/text_helper.php | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) (limited to 'system') diff --git a/system/helpers/text_helper.php b/system/helpers/text_helper.php index 477260216..b7ade7a8f 100644 --- a/system/helpers/text_helper.php +++ b/system/helpers/text_helper.php @@ -495,6 +495,48 @@ if ( ! function_exists('word_wrap')) } } +// ------------------------------------------------------------------------ + +if ( ! function_exists('ellipsize')) +{ + /** + * Ellipsize String + * + * This function will strip tags from a string, split it at its max_length and ellipsize + * + * @param string string to ellipsize + * @param 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 + */ + 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; + } +} /* End of file text_helper.php */ /* Location: ./system/helpers/text_helper.php */ \ No newline at end of file -- cgit v1.2.3-24-g4f1b From 0f6b7c1ce0f0122ba162dc579a34a73438d4955a Mon Sep 17 00:00:00 2001 From: Greg Aker Date: Thu, 5 Aug 2010 14:11:14 -0500 Subject: moving code comment in text helper --- system/helpers/text_helper.php | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) (limited to 'system') diff --git a/system/helpers/text_helper.php b/system/helpers/text_helper.php index b7ade7a8f..b85e2aaef 100644 --- a/system/helpers/text_helper.php +++ b/system/helpers/text_helper.php @@ -497,19 +497,19 @@ if ( ! function_exists('word_wrap')) // ------------------------------------------------------------------------ +/** + * Ellipsize String + * + * This function will strip tags from a string, split it at its max_length and ellipsize + * + * @param string string to ellipsize + * @param 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')) { - /** - * 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 - */ function ellipsize($str, $max_length, $position = 1, $ellipsis = '…') { // Strip tags -- cgit v1.2.3-24-g4f1b From 88f8d9f4c9d590cc14e71cd77f34e5e2abe57e21 Mon Sep 17 00:00:00 2001 From: Greg Aker Date: Fri, 6 Aug 2010 13:01:38 -0500 Subject: Removing the following deprecated database methods: orwhere, orlike, groupby, orhaving, orderby, getwhere. --- system/database/DB_active_rec.php | 74 +-------------------------------------- 1 file changed, 1 insertion(+), 73 deletions(-) (limited to 'system') diff --git a/system/database/DB_active_rec.php b/system/database/DB_active_rec.php index 3e9923e6f..953cc9548 100644 --- a/system/database/DB_active_rec.php +++ b/system/database/DB_active_rec.php @@ -398,18 +398,6 @@ class CI_DB_active_record extends CI_DB_driver { // -------------------------------------------------------------------- - /** - * orwhere() is an alias of or_where() - * this function is here for backwards compatibility, as - * orwhere() has been deprecated - */ - function orwhere($key, $value = NULL, $escape = TRUE) - { - return $this->or_where($key, $value, $escape); - } - - // -------------------------------------------------------------------- - /** * Where * @@ -671,18 +659,6 @@ class CI_DB_active_record extends CI_DB_driver { // -------------------------------------------------------------------- - /** - * orlike() is an alias of or_like() - * this function is here for backwards compatibility, as - * orlike() has been deprecated - */ - function orlike($field, $match = '', $side = 'both') - { - return $this->or_like($field, $match, $side); - } - - // -------------------------------------------------------------------- - /** * Like * @@ -775,18 +751,6 @@ class CI_DB_active_record extends CI_DB_driver { // -------------------------------------------------------------------- - /** - * groupby() is an alias of group_by() - * this function is here for backwards compatibility, as - * groupby() has been deprecated - */ - function groupby($by) - { - return $this->group_by($by); - } - - // -------------------------------------------------------------------- - /** * Sets the HAVING value * @@ -801,19 +765,7 @@ class CI_DB_active_record extends CI_DB_driver { { return $this->_having($key, $value, 'AND ', $escape); } - - // -------------------------------------------------------------------- - - /** - * orhaving() is an alias of or_having() - * this function is here for backwards compatibility, as - * orhaving() has been deprecated - */ - - function orhaving($key, $value = '', $escape = TRUE) - { - return $this->or_having($key, $value, $escape); - } + // -------------------------------------------------------------------- /** @@ -938,18 +890,6 @@ class CI_DB_active_record extends CI_DB_driver { // -------------------------------------------------------------------- - /** - * orderby() is an alias of order_by() - * this function is here for backwards compatibility, as - * orderby() has been deprecated - */ - function orderby($orderby, $direction = '') - { - return $this->order_by($orderby, $direction); - } - - // -------------------------------------------------------------------- - /** * Sets the LIMIT value * @@ -1125,18 +1065,6 @@ class CI_DB_active_record extends CI_DB_driver { // -------------------------------------------------------------------- - /** - * getwhere() is an alias of get_where() - * this function is here for backwards compatibility, as - * getwhere() has been deprecated - */ - function getwhere($table = '', $where = null, $limit = null, $offset = null) - { - return $this->get_where($table, $where, $limit, $offset); - } - - // -------------------------------------------------------------------- - /** * Insert_Batch * -- cgit v1.2.3-24-g4f1b From c5b044b739234c1e1635d4a4647b3440c44f4fa3 Mon Sep 17 00:00:00 2001 From: Greg Aker Date: Fri, 6 Aug 2010 13:06:32 -0500 Subject: Removed deprecated _drop_database() and _create_database() functions from db utility drivers. --- system/database/drivers/mssql/mssql_utility.php | 35 ----------------- system/database/drivers/mysql/mysql_utility.php | 35 ----------------- system/database/drivers/mysqli/mysqli_utility.php | 36 ----------------- system/database/drivers/oci8/oci8_utility.php | 35 ----------------- system/database/drivers/odbc/odbc_utility.php | 45 ---------------------- .../database/drivers/postgre/postgre_utility.php | 36 ----------------- system/database/drivers/sqlite/sqlite_utility.php | 45 ---------------------- 7 files changed, 267 deletions(-) (limited to 'system') diff --git a/system/database/drivers/mssql/mssql_utility.php b/system/database/drivers/mssql/mssql_utility.php index da887b815..751be146c 100644 --- a/system/database/drivers/mssql/mssql_utility.php +++ b/system/database/drivers/mssql/mssql_utility.php @@ -82,42 +82,7 @@ class CI_DB_mssql_utility extends CI_DB_utility { return $this->db->display_error('db_unsuported_feature'); } - /** - * - * The functions below have been deprecated as of 1.6, and are only here for backwards - * compatibility. They now reside in dbforge(). The use of dbutils for database manipulation - * is STRONGLY discouraged in favour if using dbforge. - * - */ - - /** - * Create database - * - * @access private - * @param string the database name - * @return bool - */ - function _create_database($name) - { - return "CREATE DATABASE ".$name; - } - - // -------------------------------------------------------------------- - - /** - * Drop database - * - * @access private - * @param string the database name - * @return bool - */ - function _drop_database($name) - { - return "DROP DATABASE ".$name; - } - } - /* 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/mysql_utility.php b/system/database/drivers/mysql/mysql_utility.php index 3277b0ff7..c4a970cfd 100644 --- a/system/database/drivers/mysql/mysql_utility.php +++ b/system/database/drivers/mysql/mysql_utility.php @@ -204,41 +204,6 @@ class CI_DB_mysql_utility extends CI_DB_utility { return $output; } - - /** - * - * The functions below have been deprecated as of 1.6, and are only here for backwards - * compatibility. They now reside in dbforge(). The use of dbutils for database manipulation - * is STRONGLY discouraged in favour if using dbforge. - * - */ - - /** - * Create database - * - * @access private - * @param string the database name - * @return bool - */ - function _create_database($name) - { - return "CREATE DATABASE ".$name; - } - - // -------------------------------------------------------------------- - - /** - * Drop database - * - * @access private - * @param string the database name - * @return bool - */ - function _drop_database($name) - { - return "DROP DATABASE ".$name; - } - } /* End of file mysql_utility.php */ diff --git a/system/database/drivers/mysqli/mysqli_utility.php b/system/database/drivers/mysqli/mysqli_utility.php index 44fd0f7aa..3ba14d25a 100644 --- a/system/database/drivers/mysqli/mysqli_utility.php +++ b/system/database/drivers/mysqli/mysqli_utility.php @@ -81,42 +81,6 @@ class CI_DB_mysqli_utility extends CI_DB_utility { // Currently unsupported return $this->db->display_error('db_unsuported_feature'); } - - - /** - * - * The functions below have been deprecated as of 1.6, and are only here for backwards - * compatibility. They now reside in dbforge(). The use of dbutils for database manipulation - * is STRONGLY discouraged in favour if using dbforge. - * - */ - - /** - * Create database - * - * @access private - * @param string the database name - * @return bool - */ - function _create_database($name) - { - return "CREATE DATABASE ".$name; - } - - // -------------------------------------------------------------------- - - /** - * Drop database - * - * @access private - * @param string the database name - * @return bool - */ - function _drop_database($name) - { - return "DROP DATABASE ".$name; - } - } /* End of file mysqli_utility.php */ diff --git a/system/database/drivers/oci8/oci8_utility.php b/system/database/drivers/oci8/oci8_utility.php index 74670eaab..cc1793531 100644 --- a/system/database/drivers/oci8/oci8_utility.php +++ b/system/database/drivers/oci8/oci8_utility.php @@ -81,41 +81,6 @@ class CI_DB_oci8_utility extends CI_DB_utility { // Currently unsupported return $this->db->display_error('db_unsuported_feature'); } - - /** - * - * The functions below have been deprecated as of 1.6, and are only here for backwards - * compatibility. They now reside in dbforge(). The use of dbutils for database manipulation - * is STRONGLY discouraged in favour if using dbforge. - * - */ - - /** - * Create database - * - * @access public - * @param string the database name - * @return bool - */ - function _create_database($name) - { - return FALSE; - } - - // -------------------------------------------------------------------- - - /** - * Drop database - * - * @access private - * @param string the database name - * @return bool - */ - function _drop_database($name) - { - return FALSE; - } - } /* End of file oci8_utility.php */ diff --git a/system/database/drivers/odbc/odbc_utility.php b/system/database/drivers/odbc/odbc_utility.php index 4e6848e82..5b874d88f 100644 --- a/system/database/drivers/odbc/odbc_utility.php +++ b/system/database/drivers/odbc/odbc_utility.php @@ -96,52 +96,7 @@ class CI_DB_odbc_utility extends CI_DB_utility { // Currently unsupported return $this->db->display_error('db_unsuported_feature'); } - - /** - * - * The functions below have been deprecated as of 1.6, and are only here for backwards - * compatibility. They now reside in dbforge(). The use of dbutils for database manipulation - * is STRONGLY discouraged in favour if using dbforge. - * - */ - /** - * Create database - * - * @access private - * @param string the database name - * @return bool - */ - function _create_database() - { - // ODBC has no "create 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; - } - - // -------------------------------------------------------------------- - - /** - * 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; - } } /* End of file odbc_utility.php */ diff --git a/system/database/drivers/postgre/postgre_utility.php b/system/database/drivers/postgre/postgre_utility.php index dda22ddb0..84b089af0 100644 --- a/system/database/drivers/postgre/postgre_utility.php +++ b/system/database/drivers/postgre/postgre_utility.php @@ -81,42 +81,6 @@ class CI_DB_postgre_utility extends CI_DB_utility { // Currently unsupported return $this->db->display_error('db_unsuported_feature'); } - - /** - * - * The functions below have been deprecated as of 1.6, and are only here for backwards - * compatibility. They now reside in dbforge(). The use of dbutils for database manipulation - * is STRONGLY discouraged in favour if using dbforge. - * - */ - - /** - * Create database - * - * @access private - * @param string the database name - * @return bool - */ - function _create_database($name) - { - return "CREATE DATABASE ".$name; - } - - // -------------------------------------------------------------------- - - /** - * Drop database - * - * @access private - * @param string the database name - * @return bool - */ - function _drop_database($name) - { - return "DROP DATABASE ".$name; - } - - } diff --git a/system/database/drivers/sqlite/sqlite_utility.php b/system/database/drivers/sqlite/sqlite_utility.php index fe63362ee..956d2130f 100644 --- a/system/database/drivers/sqlite/sqlite_utility.php +++ b/system/database/drivers/sqlite/sqlite_utility.php @@ -90,51 +90,6 @@ class CI_DB_sqlite_utility extends CI_DB_utility { // Currently unsupported return $this->db->display_error('db_unsuported_feature'); } - - /** - * - * The functions below have been deprecated as of 1.6, and are only here for backwards - * compatibility. They now reside in dbforge(). The use of dbutils for database manipulation - * is STRONGLY discouraged in favour if using dbforge. - * - */ - - /** - * Create database - * - * @access public - * @param string the database name - * @return bool - */ - function _create_database() - { - // In SQLite, a database is created when you connect to the database. - // We'll return TRUE so that an error isn't generated - return TRUE; - } - - // -------------------------------------------------------------------- - - /** - * Drop database - * - * @access private - * @param string the database name - * @return bool - */ - function _drop_database($name) - { - if ( ! @file_exists($this->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; - } - } /* End of file sqlite_utility.php */ -- cgit v1.2.3-24-g4f1b From 4062d48ca89736c952e9be17bb395d36140f4668 Mon Sep 17 00:00:00 2001 From: Derek Jones Date: Tue, 10 Aug 2010 20:30:34 -0500 Subject: removed redundant upload lang file, after lang name changs, it was blocking the CI lang file from loading. Fixes #473 --- system/libraries/Upload.php | 3 +++ 1 file changed, 3 insertions(+) (limited to 'system') diff --git a/system/libraries/Upload.php b/system/libraries/Upload.php index c18c178df..0aa6d4c20 100644 --- a/system/libraries/Upload.php +++ b/system/libraries/Upload.php @@ -937,9 +937,12 @@ class CI_Upload { */ function display_errors($open = '

    ', $close = '

    ') { + $CI =& get_instance(); + $CI->lang->load('upload'); $str = ''; foreach ($this->error_msg as $val) { + $str .= '
    '.print_r($CI->lang->line($msg), TRUE).'
    '; $str .= $open.$val.$close; } -- cgit v1.2.3-24-g4f1b From 23b7776accc6ebfa377c9b54bd04baaaf0c00132 Mon Sep 17 00:00:00 2001 From: Derek Jones Date: Tue, 10 Aug 2010 20:38:43 -0500 Subject: undoing mistaken changes in rev 8c54b3b0402f --- system/libraries/Upload.php | 3 --- 1 file changed, 3 deletions(-) (limited to 'system') diff --git a/system/libraries/Upload.php b/system/libraries/Upload.php index 0aa6d4c20..c18c178df 100644 --- a/system/libraries/Upload.php +++ b/system/libraries/Upload.php @@ -937,12 +937,9 @@ class CI_Upload { */ function display_errors($open = '

    ', $close = '

    ') { - $CI =& get_instance(); - $CI->lang->load('upload'); $str = ''; foreach ($this->error_msg as $val) { - $str .= '
    '.print_r($CI->lang->line($msg), TRUE).'
    '; $str .= $open.$val.$close; } -- cgit v1.2.3-24-g4f1b From 595bfd1484ecc8212d6c3c028210b4d1ae78baba Mon Sep 17 00:00:00 2001 From: Derek Jones Date: Fri, 20 Aug 2010 10:28:22 -0500 Subject: Added ability in the Image Library to handle PNG transparency for resize operations when using the GD lib. --- system/libraries/Image_lib.php | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'system') diff --git a/system/libraries/Image_lib.php b/system/libraries/Image_lib.php index 21e0a709b..806d942ba 100644 --- a/system/libraries/Image_lib.php +++ b/system/libraries/Image_lib.php @@ -513,6 +513,13 @@ class CI_Image_lib { } $dst_img = $create($this->width, $this->height); + + if ($this->image_type == 3) // png we can actually preserve transparency + { + imagealphablending($dst_img, FALSE); + imagesavealpha($dst_img, TRUE); + } + $copy($dst_img, $src_img, 0, 0, $this->x_axis, $this->y_axis, $this->width, $this->height, $this->orig_width, $this->orig_height); // Show the image -- cgit v1.2.3-24-g4f1b From 60f8c395f24ba6db80d510892bcc53ce5bf9f4eb Mon Sep 17 00:00:00 2001 From: Pascal Kriete Date: Wed, 25 Aug 2010 18:03:28 +0200 Subject: Modified the database driver's display_error() method to show the filename and line number of the failed query. --- system/database/DB_driver.php | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) (limited to 'system') diff --git a/system/database/DB_driver.php b/system/database/DB_driver.php index dfef42757..8e6f88801 100644 --- a/system/database/DB_driver.php +++ b/system/database/DB_driver.php @@ -1169,6 +1169,24 @@ class CI_DB_driver { $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; -- cgit v1.2.3-24-g4f1b From 5485db50775d4e2f76a593ef8b3425f6a1b90666 Mon Sep 17 00:00:00 2001 From: Derek Jones Date: Mon, 30 Aug 2010 21:31:08 -0500 Subject: Added fatal error to Session class when no encryption key is set in the config file, for additional assurance that session manipulation can be prevented --- system/libraries/Session.php | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'system') diff --git a/system/libraries/Session.php b/system/libraries/Session.php index cf6dc96e3..f413c0d1b 100644 --- a/system/libraries/Session.php +++ b/system/libraries/Session.php @@ -65,6 +65,11 @@ class CI_Session { $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'); -- cgit v1.2.3-24-g4f1b From 7284f06585a689702ea86684893c999065621460 Mon Sep 17 00:00:00 2001 From: Derek Jones Date: Tue, 31 Aug 2010 00:30:21 -0500 Subject: changed key comparison to be loosely typed, so an error would be triggered when an empty string is attempted to be used as an encryption key --- system/libraries/Encrypt.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system') diff --git a/system/libraries/Encrypt.php b/system/libraries/Encrypt.php index c893fbf9e..44fdce03b 100644 --- a/system/libraries/Encrypt.php +++ b/system/libraries/Encrypt.php @@ -72,7 +72,7 @@ class CI_Encrypt { $CI =& get_instance(); $key = $CI->config->item('encryption_key'); - if ($key === FALSE) + if ($key == FALSE) { show_error('In order to use the encryption class requires that you set an encryption key in your config file.'); } -- cgit v1.2.3-24-g4f1b From 95b183addfb1683583d401e04f2684ceb86f8b96 Mon Sep 17 00:00:00 2001 From: Derek Jones Date: Tue, 31 Aug 2010 09:42:39 -0500 Subject: fixed spelling error in Security class property for the CSRF cookie --- system/libraries/Security.php | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) (limited to 'system') diff --git a/system/libraries/Security.php b/system/libraries/Security.php index 29ac2612b..9a1590b5c 100644 --- a/system/libraries/Security.php +++ b/system/libraries/Security.php @@ -29,7 +29,7 @@ class CI_Security { var $csrf_hash = ''; var $csrf_expire = 7200; // Two hours (in seconds) var $csrf_token_name = 'ci_csrf_token'; - var $csfr_cookie_name = 'ci_csrf_token'; + var $csrf_cookie_name = 'ci_csrf_token'; /* never allowed, string replacement */ var $never_allowed_str = array( @@ -54,7 +54,7 @@ class CI_Security { function CI_Security() { // Append application specific cookie prefix to token name - $this->csfr_cookie_name = (config_item('cookie_prefix')) ? config_item('cookie_prefix').$this->csrf_token_name : $this->csrf_token_name; + $this->csrf_cookie_name = (config_item('cookie_prefix')) ? config_item('cookie_prefix').$this->csrf_token_name : $this->csrf_token_name; // Set the CSRF hash $this->_csrf_set_hash(); @@ -79,13 +79,13 @@ class CI_Security { } // Do the tokens exist in both the _POST and _COOKIE arrays? - if ( ! isset($_POST[$this->csrf_token_name]) OR ! isset($_COOKIE[$this->csfr_cookie_name])) + if ( ! isset($_POST[$this->csrf_token_name]) OR ! isset($_COOKIE[$this->csrf_cookie_name])) { $this->csrf_show_error(); } // Do the tokens match? - if ($_POST[$this->csrf_token_name] != $_COOKIE[$this->csfr_cookie_name]) + if ($_POST[$this->csrf_token_name] != $_COOKIE[$this->csrf_cookie_name]) { $this->csrf_show_error(); } @@ -94,7 +94,7 @@ class CI_Security { unset($_POST[$this->csrf_token_name]); // Nothing should last forever - unset($_COOKIE[$this->csfr_cookie_name]); + unset($_COOKIE[$this->csrf_cookie_name]); $this->_csrf_set_hash(); $this->csrf_set_cookie(); @@ -113,7 +113,7 @@ class CI_Security { { $expire = time() + $this->csrf_expire; - setcookie($this->csfr_cookie_name, $this->csrf_hash, $expire, config_item('cookie_path'), config_item('cookie_domain'), 0); + setcookie($this->csrf_cookie_name, $this->csrf_hash, $expire, config_item('cookie_path'), config_item('cookie_domain'), 0); log_message('debug', "CRSF cookie Set"); } @@ -132,9 +132,9 @@ class CI_Security { { // 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->csfr_cookie_name]) AND $_COOKIE[$this->csfr_cookie_name] != '') + if (isset($_COOKIE[$this->csrf_cookie_name]) AND $_COOKIE[$this->csrf_cookie_name] != '') { - $this->csrf_hash = $_COOKIE[$this->csfr_cookie_name]; + $this->csrf_hash = $_COOKIE[$this->csrf_cookie_name]; } else { -- cgit v1.2.3-24-g4f1b From 09c7793b23ae77c54e25d12b63d8ca9c9232efeb Mon Sep 17 00:00:00 2001 From: Derek Jones Date: Tue, 31 Aug 2010 13:17:10 -0500 Subject: Significant changes to the Encryption library - Removed double-encoding with XOR scheme when Mcrypt is available. Additional obfuscation was not significantly aiding security, and came at a very high performance cost. - Changed the default encryption mode from ECB to CBC for much improved security - Added an encode_from_legacy() method to allow re-encoding of permanent data that was originally encoded with the older methods. --- system/libraries/Encrypt.php | 75 ++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 69 insertions(+), 6 deletions(-) (limited to 'system') diff --git a/system/libraries/Encrypt.php b/system/libraries/Encrypt.php index 44fdce03b..8beff75d6 100644 --- a/system/libraries/Encrypt.php +++ b/system/libraries/Encrypt.php @@ -116,12 +116,16 @@ class CI_Encrypt { function encode($string, $key = '') { $key = $this->get_key($key); - $enc = $this->_xor_encode($string, $key); - + if ($this->_mcrypt_exists === TRUE) { - $enc = $this->mcrypt_encode($enc, $key); + $enc = $this->mcrypt_encode($string, $key); + } + else + { + $enc = $this->_xor_encode($string, $key); } + return base64_encode($enc); } @@ -155,12 +159,71 @@ class CI_Encrypt { return FALSE; } } - - return $this->_xor_decode($dec, $key); + else + { + $dec = $this->_xor_decode($dec, $key); + } + + return $dec; } // -------------------------------------------------------------------- + + /** + * Encode from Legacy + * + * Takes an encoded string from the original Encryption class algorithms and + * returns a newly encoded string using the improved method added in 2.0.0 + * This allows for backwards compatibility and a method to transition to the + * new encryption algorithms. + * + * For more details, see http://codeigniter.com/user_guide/installation/upgrade_200.html#encryption + * + * @access public + * @param string + * @param int (mcrypt mode constant) + * @param string + * @return string + */ + function encode_from_legacy($string, $legacy_mode = MCRYPT_MODE_ECB, $key = '') + { + if ($this->_mcrypt_exists === FALSE) + { + log_message('error', 'Encoding from legacy is available only when Mcrypt is in use.'); + return FALSE; + } + + // decode it first + // set mode temporarily to what it was when string was encoded with the legacy + // algorithm - typically MCRYPT_MODE_ECB + $current_mode = $this->_get_mode(); + $this->set_mode($legacy_mode); + + $key = $this->get_key($key); + + if (preg_match('/[^a-zA-Z0-9\/\+=]/', $string)) + { + return FALSE; + } + + $dec = base64_decode($string); + + if (($dec = $this->mcrypt_decode($dec, $key)) === FALSE) + { + return FALSE; + } + + $dec = $this->_xor_decode($dec, $key); + // set the mcrypt mode back to what it should be, typically MCRYPT_MODE_CBC + $this->set_mode(MCRYPT_MODE_CBC); + + // and re-encode + return base64_encode($this->mcrypt_encode($dec, $key)); + } + + // -------------------------------------------------------------------- + /** * XOR Encode * @@ -412,7 +475,7 @@ class CI_Encrypt { { if ($this->_mcrypt_mode == '') { - $this->_mcrypt_mode = MCRYPT_MODE_ECB; + $this->_mcrypt_mode = MCRYPT_MODE_CBC; } return $this->_mcrypt_mode; -- cgit v1.2.3-24-g4f1b From d1606358ba51261150bc2f99bb9cb2b9117718e7 Mon Sep 17 00:00:00 2001 From: Derek Jones Date: Wed, 1 Sep 2010 11:16:07 -0500 Subject: fixes issue #109 where cc and bcc recipients were not reset when using the clear() method in the Email lib --- system/libraries/Email.php | 2 ++ 1 file changed, 2 insertions(+) (limited to 'system') diff --git a/system/libraries/Email.php b/system/libraries/Email.php index 09d1b8fb9..af48757bb 100644 --- a/system/libraries/Email.php +++ b/system/libraries/Email.php @@ -146,6 +146,8 @@ class CI_Email { $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(); -- cgit v1.2.3-24-g4f1b From eaa71ba1c19538af5416dceec288aa37cad2b7e6 Mon Sep 17 00:00:00 2001 From: Derek Jones Date: Thu, 2 Sep 2010 10:32:07 -0500 Subject: Added a new config item to the Session class (sess_expire_on_close) to allow sessions to auto-expire when the browser window is closed. --- system/libraries/Session.php | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) (limited to 'system') diff --git a/system/libraries/Session.php b/system/libraries/Session.php index f413c0d1b..fc3ee0542 100644 --- a/system/libraries/Session.php +++ b/system/libraries/Session.php @@ -30,6 +30,7 @@ class CI_Session { var $sess_use_database = FALSE; var $sess_table_name = ''; var $sess_expiration = 7200; + var $sess_expire_on_close = FALSE; var $sess_match_ip = FALSE; var $sess_match_useragent = TRUE; var $sess_cookie_name = 'ci_session'; @@ -655,12 +656,14 @@ class CI_Session { // if encryption is not used, we provide an md5 hash to prevent userside tampering $cookie_data = $cookie_data.md5($cookie_data.$this->encryption_key); } - + + $expire = ($this->sess_expire_on_close === TRUE) ? 0 : $this->sess_expiration + time(); + // Set the cookie setcookie( $this->sess_cookie_name, $cookie_data, - $this->sess_expiration + time(), + $expire, $this->cookie_path, $this->cookie_domain, 0 -- cgit v1.2.3-24-g4f1b From 092103e4d6a4a2bcd14274055f774e4eb01ecaa3 Mon Sep 17 00:00:00 2001 From: Derek Jones Date: Thu, 2 Sep 2010 11:11:58 -0500 Subject: fixed a spot where the encryption mode was still a hard coded constant instead of the fetched variable --- system/libraries/Encrypt.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system') diff --git a/system/libraries/Encrypt.php b/system/libraries/Encrypt.php index 8beff75d6..b27847a55 100644 --- a/system/libraries/Encrypt.php +++ b/system/libraries/Encrypt.php @@ -216,7 +216,7 @@ class CI_Encrypt { $dec = $this->_xor_decode($dec, $key); // set the mcrypt mode back to what it should be, typically MCRYPT_MODE_CBC - $this->set_mode(MCRYPT_MODE_CBC); + $this->set_mode($current_mode); // and re-encode return base64_encode($this->mcrypt_encode($dec, $key)); -- cgit v1.2.3-24-g4f1b From d2167a01ec5bd134a4138b50d76487caa72245c6 Mon Sep 17 00:00:00 2001 From: Robin Sowell Date: Tue, 14 Sep 2010 15:05:42 -0400 Subject: Fixed a bug in the URL Helper where prep_url() could cause a PHP error on PHP versions < 5.1.2. --- system/helpers/url_helper.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'system') diff --git a/system/helpers/url_helper.php b/system/helpers/url_helper.php index 7707d6854..dad761145 100644 --- a/system/helpers/url_helper.php +++ b/system/helpers/url_helper.php @@ -446,7 +446,9 @@ if ( ! function_exists('prep_url')) return ''; } - if ( ! parse_url($str, PHP_URL_SCHEME)) + $url = parse_url($str); + + if ( ! $url OR ! isset($url['scheme'])) { $str = 'http://'.$str; } -- cgit v1.2.3-24-g4f1b From a7f5a94d9ecc371a1ee9fb3b5ffe4bfdd90b5e2d Mon Sep 17 00:00:00 2001 From: Greg Aker Date: Tue, 14 Sep 2010 17:20:53 -0500 Subject: Added a log message in core/output if the cache directory config value was not found. --- system/core/Output.php | 1 + 1 file changed, 1 insertion(+) (limited to 'system') diff --git a/system/core/Output.php b/system/core/Output.php index e25e62197..7d3e2e180 100644 --- a/system/core/Output.php +++ b/system/core/Output.php @@ -346,6 +346,7 @@ class CI_Output { if ( ! is_dir($cache_path) OR ! is_really_writable($cache_path)) { + log_message('error', "Unable to write cache file: ".$cache_path); return; } -- cgit v1.2.3-24-g4f1b From c2950704d0cf8b7ae4d71900259b1c8ef3584c68 Mon Sep 17 00:00:00 2001 From: Greg Aker Date: Tue, 14 Sep 2010 17:52:26 -0500 Subject: Updates to output profiler html validation. http://bitbucket.org/ellislab/codeigniter/issue/111/profiler-output-does-not-validate --- system/libraries/Profiler.php | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'system') diff --git a/system/libraries/Profiler.php b/system/libraries/Profiler.php index 0900a300d..6bc3c8799 100644 --- a/system/libraries/Profiler.php +++ b/system/libraries/Profiler.php @@ -128,7 +128,7 @@ class CI_Profiler { foreach ($profile as $key => $val) { $key = ucwords(str_replace(array('_', '-'), ' ', $key)); - $output .= "".$key."  ".$val."\n"; + $output .= "".$key."  ".$val."\n"; } $output .= "\n"; @@ -165,8 +165,8 @@ class CI_Profiler { $output .= "\n"; $output .= '  '.$this->CI->lang->line('profiler_queries').'  '; $output .= "\n"; - $output .= "\n\n\n"; - $output .="\n"; + $output .= "\n\n
    ".$this->CI->lang->line('profiler_no_db')."
    \n"; + $output .="\n"; $output .= "
    ".$this->CI->lang->line('profiler_no_db')."
    \n"; $output .= ""; @@ -187,11 +187,11 @@ class CI_Profiler { $output .= "\n"; $output .= '  '.$this->CI->lang->line('profiler_database').':  '.$db->database.'   '.$this->CI->lang->line('profiler_queries').': '.count($this->CI->db->queries).'   '; $output .= "\n"; - $output .= "\n\n\n"; + $output .= "\n\n
    \n"; if (count($db->queries) == 0) { - $output .= "\n"; + $output .= "\n"; } else { @@ -206,7 +206,7 @@ class CI_Profiler { $val = str_replace($bold, ''.$bold.'', $val); } - $output .= "\n"; + $output .= "\n"; } } -- cgit v1.2.3-24-g4f1b From 3424bf77ce638a2fd8e64ea76e874d3b9ead7414 Mon Sep 17 00:00:00 2001 From: Greg Aker Date: Tue, 14 Sep 2010 17:53:10 -0500 Subject: Fixed http://bitbucket.org/ellislab/codeigniter/issue/38/slight-bug-with-profilerphp Slight tweak to SQL query display in output profiler. --- system/libraries/Profiler.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system') diff --git a/system/libraries/Profiler.php b/system/libraries/Profiler.php index 6bc3c8799..db179976b 100644 --- a/system/libraries/Profiler.php +++ b/system/libraries/Profiler.php @@ -177,7 +177,7 @@ class CI_Profiler { $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', '(', ')'); + $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"; -- cgit v1.2.3-24-g4f1b From fd2ba8836d74ded06cfe14f728387698c0532148 Mon Sep 17 00:00:00 2001 From: Greg Aker Date: Tue, 14 Sep 2010 18:45:42 -0500 Subject: Fix #96 html validation failure on csrf hidden input on form_open() in the form helper. Added
    ".$this->CI->lang->line('profiler_no_queries')."
    ".$this->CI->lang->line('profiler_no_queries')."
    ".$time."  ".$val."
    ".$time."  ".$val."
    ', - 'heading_row_start' => '', + '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' => '', + 'heading_next_cell' => '', + 'heading_row_end' => '', + 'week_row_start' => '', + 'week_day_cell' => '', + 'week_row_end' => '', + 'cal_row_start' => '', + 'cal_cell_start' => '', 'cal_row_end' => '', 'table_close' => '
    <<{heading}>>
    {week_day}
    ', + 'heading_title_cell' => '{heading}>>
    {week_day}
    ', 'cal_cell_start_today' => '', 'cal_cell_content' => '{day}', 'cal_cell_content_today' => '{day}', @@ -428,9 +428,9 @@ class CI_Calendar { 'cal_cell_end_today' => '
    ' - ); + ); } - + // -------------------------------------------------------------------- /** @@ -442,17 +442,17 @@ class CI_Calendar { * @access public * @return void */ - function parse_template() - { + function parse_template() + { $this->temp = $this->default_template(); - - if ($this->template == '') - { - return; - } - + + 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)) @@ -466,8 +466,8 @@ class CI_Calendar { $this->temp[$val] = $this->temp[str_replace('_today', '', $val)]; } } - } - } + } + } } diff --git a/system/libraries/Cart.php b/system/libraries/Cart.php index 643d2eca4..f3969ef2c 100644 --- a/system/libraries/Cart.php +++ b/system/libraries/Cart.php @@ -29,7 +29,7 @@ class CI_Cart { // These are the regular expression rules that we use to validate the product ID and product name var $product_id_rules = '\.a-z0-9_-'; // alpha-numeric, dashes, underscores, or periods var $product_name_rules = '\.\:\-_ a-z0-9'; // alpha-numeric, dashes, underscores, colons or periods - + // Private variables. Do not change! var $CI; var $_cart_contents = array(); @@ -39,12 +39,12 @@ class CI_Cart { * Shopping Class Constructor * * The constructor loads the Session class, used to store the shopping cart contents. - */ + */ function CI_Cart($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 = array(); if (count($params) > 0) @@ -54,10 +54,10 @@ class CI_Cart { $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) { @@ -66,15 +66,15 @@ class CI_Cart { else { // No cart exists so we'll set some base values - $this->_cart_contents['cart_total'] = 0; - $this->_cart_contents['total_items'] = 0; + $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 * @@ -90,15 +90,15 @@ class CI_Cart { 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, + + // 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; + + $save_cart = FALSE; if (isset($items['id'])) - { + { if ($this->_insert($items) == TRUE) { $save_cart = TRUE; @@ -114,7 +114,7 @@ class CI_Cart { { $save_cart = TRUE; } - } + } } } @@ -129,7 +129,7 @@ class CI_Cart { } // -------------------------------------------------------------------- - + /** * Insert * @@ -145,9 +145,9 @@ class CI_Cart { 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'])) { @@ -156,7 +156,7 @@ class CI_Cart { } // -------------------------------------------------------------------- - + // Prep the quantity. It can only be a number. Duh... $items['qty'] = trim(preg_replace('/([^0-9])/i', '', $items['qty'])); // Trim any leading zeros @@ -167,9 +167,9 @@ class CI_Cart { { 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. @@ -180,7 +180,7 @@ class CI_Cart { } // -------------------------------------------------------------------- - + // 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'])) @@ -195,7 +195,7 @@ class CI_Cart { $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'])) { @@ -204,13 +204,13 @@ class CI_Cart { } // -------------------------------------------------------------------- - + // 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 + // 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. @@ -225,19 +225,19 @@ class CI_Cart { // 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]); - + 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 + + // And add the new items to the cart array foreach ($items as $key => $val) { $this->_cart_contents[$rowid][$key] = $val; @@ -248,11 +248,11 @@ class CI_Cart { } // -------------------------------------------------------------------- - + /** * Update the cart * - * This function permits the quantity of a given item to be changed. + * 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. @@ -269,8 +269,8 @@ class CI_Cart { { return FALSE; } - - // You can either update a single product using a one-dimensional array, + + // 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 @@ -292,7 +292,7 @@ class CI_Cart { { $save_cart = TRUE; } - } + } } } @@ -307,11 +307,11 @@ class CI_Cart { } // -------------------------------------------------------------------- - + /** * Update the cart * - * This function permits the quantity of a given item to be changed. + * 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. @@ -319,7 +319,7 @@ class CI_Cart { * @access private * @param array * @return bool - */ + */ function _update($items = array()) { // Without these array indexes there is nothing we can do @@ -327,7 +327,7 @@ class CI_Cart { { return FALSE; } - + // Prep the quantity $items['qty'] = preg_replace('/([^0-9])/i', '', $items['qty']); @@ -336,7 +336,7 @@ class CI_Cart { { return FALSE; } - + // Is the new quantity different than what is already saved in the cart? // If it's the same there's nothing to do if ($this->_cart_contents[$items['rowid']]['qty'] == $items['qty']) @@ -348,18 +348,18 @@ class CI_Cart { // If the quantity is greater than zero we are updating if ($items['qty'] == 0) { - unset($this->_cart_contents[$items['rowid']]); + 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 * @@ -383,20 +383,20 @@ class CI_Cart { } $total += ($val['price'] * $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'] = count($this->_cart_contents); + $this->_cart_contents['total_items'] = count($this->_cart_contents); $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; } @@ -406,11 +406,11 @@ class CI_Cart { $this->CI->session->set_userdata(array('cart_contents' => $this->_cart_contents)); // Woot! - return TRUE; + return TRUE; } // -------------------------------------------------------------------- - + /** * Cart Total * @@ -423,7 +423,7 @@ class CI_Cart { } // -------------------------------------------------------------------- - + /** * Total Items * @@ -438,7 +438,7 @@ class CI_Cart { } // -------------------------------------------------------------------- - + /** * Cart Contents * @@ -450,16 +450,16 @@ class CI_Cart { 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 * @@ -475,12 +475,12 @@ class CI_Cart { { return FALSE; } - + return TRUE; } // -------------------------------------------------------------------- - + /** * Product options * @@ -500,7 +500,7 @@ class CI_Cart { } // -------------------------------------------------------------------- - + /** * Format Number * @@ -515,15 +515,15 @@ class CI_Cart { { 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 * @@ -535,9 +535,9 @@ class CI_Cart { function destroy() { unset($this->_cart_contents); - - $this->_cart_contents['cart_total'] = 0; - $this->_cart_contents['total_items'] = 0; + + $this->_cart_contents['cart_total'] = 0; + $this->_cart_contents['total_items'] = 0; $this->CI->session->unset_userdata('cart_contents'); } diff --git a/system/libraries/Driver.php b/system/libraries/Driver.php index 07ef2e724..1261b4c72 100644 --- a/system/libraries/Driver.php +++ b/system/libraries/Driver.php @@ -25,25 +25,25 @@ * @subpackage Libraries * @category Libraries * @author EllisLab Dev Team - * @link + * @link */ class CI_Driver_Library { protected $valid_drivers = array(); protected static $lib_name; - + // The first time a child is used it won't exist, so we instantiate it // subsequents calls will go straight to the proper child. function __get($child) { if (! isset($this->lib_name)) { - $this->lib_name = get_class($this); + $this->lib_name = get_class($this); } // The class will be prefixed with the parent lib $child_class = $this->lib_name.'_'.$child; - + if (in_array(strtolower($child_class), array_map('strtolower', $this->valid_drivers))) { // check and see if the driver is in a separate file @@ -64,11 +64,11 @@ class CI_Driver_Library { { include_once $filepath; break; - } + } } } } - + // it's a valid driver, but the file simply can't be found if ( ! class_exists($child_class)) { @@ -82,14 +82,14 @@ class CI_Driver_Library { $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); } - + // -------------------------------------------------------------------- - + } // END CI_Driver_Library CLASS @@ -104,11 +104,11 @@ class CI_Driver_Library { * @subpackage Libraries * @category Libraries * @author EllisLab Dev Team - * @link + * @link */ class CI_Driver { protected $parent; - + private $methods = array(); private $properties = array(); @@ -126,16 +126,16 @@ class CI_Driver { 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()) @@ -151,7 +151,7 @@ class CI_Driver { $this->properties[] = $prop->getName(); } } - + self::$reflections[$class_name] = array($this->methods, $this->properties); } else @@ -159,9 +159,9 @@ class CI_Driver { list($this->methods, $this->properties) = self::$reflections[$class_name]; } } - + // -------------------------------------------------------------------- - + /** * __call magic method * @@ -185,7 +185,7 @@ class CI_Driver { } // -------------------------------------------------------------------- - + /** * __get magic method * @@ -204,7 +204,7 @@ class CI_Driver { } // -------------------------------------------------------------------- - + /** * __set magic method * @@ -222,9 +222,9 @@ class CI_Driver { $this->parent->$var = $val; } } - + // -------------------------------------------------------------------- - + } // END CI_Driver CLASS diff --git a/system/libraries/Email.php b/system/libraries/Email.php index af48757bb..6c0309b0d 100644 --- a/system/libraries/Email.php +++ b/system/libraries/Email.php @@ -129,7 +129,7 @@ class CI_Email { $this->_smtp_auth = ($this->smtp_user == '' AND $this->smtp_pass == '') ? FALSE : TRUE; $this->_safe_mode = ((boolean)@ini_get("safe_mode") === FALSE) ? FALSE : TRUE; } - + // -------------------------------------------------------------------- /** @@ -161,7 +161,7 @@ class CI_Email { $this->_attach_disp = array(); } } - + // -------------------------------------------------------------------- /** @@ -202,7 +202,7 @@ class CI_Email { $this->_set_header('From', $name.' <'.$from.'>'); $this->_set_header('Return-Path', '<'.$from.'>'); } - + // -------------------------------------------------------------------- /** @@ -238,7 +238,7 @@ class CI_Email { $this->_set_header('Reply-To', $name.' <'.$replyto.'>'); $this->_replyto_flag = TRUE; } - + // -------------------------------------------------------------------- /** @@ -273,7 +273,7 @@ class CI_Email { break; } } - + // -------------------------------------------------------------------- /** @@ -300,7 +300,7 @@ class CI_Email { $this->_cc_array = $cc; } } - + // -------------------------------------------------------------------- /** @@ -336,7 +336,7 @@ class CI_Email { $this->_set_header('Bcc', implode(", ", $bcc)); } } - + // -------------------------------------------------------------------- /** @@ -351,7 +351,7 @@ class CI_Email { $subject = $this->_prep_q_encoding($subject); $this->_set_header('Subject', $subject); } - + // -------------------------------------------------------------------- /** @@ -365,7 +365,7 @@ class CI_Email { { $this->_body = stripslashes(rtrim(str_replace("\r", "", $body))); } - + // -------------------------------------------------------------------- /** @@ -396,7 +396,7 @@ class CI_Email { { $this->_headers[$header] = $value; } - + // -------------------------------------------------------------------- /** @@ -422,7 +422,7 @@ class CI_Email { } return $email; } - + // -------------------------------------------------------------------- /** @@ -436,7 +436,7 @@ class CI_Email { { $this->alt_message = ($str == '') ? '' : $str; } - + // -------------------------------------------------------------------- /** @@ -450,7 +450,7 @@ class CI_Email { { $this->mailtype = ($type == 'html') ? 'html' : 'text'; } - + // -------------------------------------------------------------------- /** @@ -464,7 +464,7 @@ class CI_Email { { $this->wordwrap = ($wordwrap === FALSE) ? FALSE : TRUE; } - + // -------------------------------------------------------------------- /** @@ -478,7 +478,7 @@ class CI_Email { { $this->protocol = ( ! in_array($protocol, $this->_protocols, TRUE)) ? 'mail' : strtolower($protocol); } - + // -------------------------------------------------------------------- /** @@ -504,7 +504,7 @@ class CI_Email { $this->priority = $n; } - + // -------------------------------------------------------------------- /** @@ -524,7 +524,7 @@ class CI_Email { $this->newline = $newline; } - + // -------------------------------------------------------------------- /** @@ -544,7 +544,7 @@ class CI_Email { $this->crlf = $crlf; } - + // -------------------------------------------------------------------- /** @@ -558,7 +558,7 @@ class CI_Email { $this->_alt_boundary = "B_ALT_".uniqid(''); // multipart/alternative $this->_atc_boundary = "B_ATC_".uniqid(''); // attachment boundary } - + // -------------------------------------------------------------------- /** @@ -575,7 +575,7 @@ class CI_Email { return "<".uniqid('').strstr($from, '@').">"; } - + // -------------------------------------------------------------------- /** @@ -595,7 +595,7 @@ class CI_Email { return $this->protocol; } } - + // -------------------------------------------------------------------- /** @@ -650,7 +650,7 @@ class CI_Email { return 'plain'; } } - + // -------------------------------------------------------------------- /** @@ -668,7 +668,7 @@ class CI_Email { return sprintf("%s %s%04d", date("D, j M Y H:i:s"), $operator, $timezone); } - + // -------------------------------------------------------------------- /** @@ -681,7 +681,7 @@ class CI_Email { { return "This is a multi-part message in MIME format.".$this->newline."Your email application may not support this format."; } - + // -------------------------------------------------------------------- /** @@ -710,7 +710,7 @@ class CI_Email { return TRUE; } - + // -------------------------------------------------------------------- /** @@ -724,7 +724,7 @@ class CI_Email { { return ( ! preg_match("/^([a-z0-9\+_\-]+)(\.[a-z0-9\+_\-]+)*@([a-z0-9\-]+\.)+[a-z]{2,6}$/ix", $address)) ? FALSE : TRUE; } - + // -------------------------------------------------------------------- /** @@ -740,11 +740,11 @@ class CI_Email { { if (preg_match('/\<(.*)\>/', $email, $match)) { - return $match['1']; + return $match['1']; } - else + else { - return $email; + return $email; } } @@ -754,17 +754,17 @@ class CI_Email { { if (preg_match( '/\<(.*)\>/', $addy, $match)) { - $clean_email[] = $match['1']; + $clean_email[] = $match['1']; } - else + else { - $clean_email[] = $addy; + $clean_email[] = $addy; } } return $clean_email; } - + // -------------------------------------------------------------------- /** @@ -804,7 +804,7 @@ class CI_Email { for ($x = 1; $x <= $i; $x ++) { - $n .= "\n"; + $n .= "\n"; } $body = str_replace($n, "\n\n", $body); @@ -812,7 +812,7 @@ class CI_Email { return $this->word_wrap($body, '76'); } - + // -------------------------------------------------------------------- /** @@ -908,7 +908,7 @@ class CI_Email { return $output; } - + // -------------------------------------------------------------------- /** @@ -926,7 +926,7 @@ class CI_Email { $this->_set_header('Message-ID', $this->_get_message_id()); $this->_set_header('Mime-Version', '1.0'); } - + // -------------------------------------------------------------------- /** @@ -961,7 +961,7 @@ class CI_Email { $this->_header_str = rtrim($this->_header_str); } } - + // -------------------------------------------------------------------- /** @@ -1150,7 +1150,7 @@ class CI_Email { return; } - + // -------------------------------------------------------------------- /** @@ -1245,7 +1245,7 @@ class CI_Email { } // -------------------------------------------------------------------- - + /** * Prep Q Encoding * @@ -1317,7 +1317,7 @@ class CI_Email { } // -------------------------------------------------------------------- - + /** * Send Email * @@ -1358,7 +1358,7 @@ class CI_Email { return TRUE; } } - + // -------------------------------------------------------------------- /** @@ -1416,7 +1416,7 @@ class CI_Email { $this->_spool_email(); } } - + // -------------------------------------------------------------------- /** @@ -1429,7 +1429,7 @@ class CI_Email { { $this->_finalbody = preg_replace_callback("/\{unwrap\}(.*?)\{\/unwrap\}/si", array($this, '_remove_nl_callback'), $this->_finalbody); } - + // -------------------------------------------------------------------- /** @@ -1447,7 +1447,7 @@ class CI_Email { return $matches[1]; } - + // -------------------------------------------------------------------- /** @@ -1492,7 +1492,7 @@ class CI_Email { $this->_set_error_message('email_sent', $this->_get_protocol()); return TRUE; } - + // -------------------------------------------------------------------- /** @@ -1528,7 +1528,7 @@ class CI_Email { } } } - + // -------------------------------------------------------------------- /** @@ -1550,12 +1550,12 @@ class CI_Email { fputs($fp, $this->_header_str); fputs($fp, $this->_finalbody); - $status = pclose($fp); - + $status = pclose($fp); + if (version_compare(PHP_VERSION, '4.2.3') == -1) { $status = $status >> 8 & 0xFF; - } + } if ($status != 0) { @@ -1566,7 +1566,7 @@ class CI_Email { return TRUE; } - + // -------------------------------------------------------------------- /** @@ -1635,7 +1635,7 @@ class CI_Email { $this->_send_command('quit'); return TRUE; } - + // -------------------------------------------------------------------- /** @@ -1662,7 +1662,7 @@ class CI_Email { $this->_set_error_message($this->_get_smtp_data()); return $this->_send_command('hello'); } - + // -------------------------------------------------------------------- /** @@ -1729,7 +1729,7 @@ class CI_Email { return TRUE; } - + // -------------------------------------------------------------------- /** @@ -1783,7 +1783,7 @@ class CI_Email { return TRUE; } - + // -------------------------------------------------------------------- /** @@ -1804,7 +1804,7 @@ class CI_Email { return TRUE; } } - + // -------------------------------------------------------------------- /** @@ -1829,7 +1829,7 @@ class CI_Email { return $data; } - + // -------------------------------------------------------------------- /** @@ -1842,7 +1842,7 @@ class CI_Email { { return (isset($_SERVER['SERVER_NAME'])) ? $_SERVER['SERVER_NAME'] : 'localhost.localdomain'; } - + // -------------------------------------------------------------------- /** @@ -1862,7 +1862,7 @@ class CI_Email { $rip = (isset($_SERVER['REMOTE_ADDR']) AND $_SERVER['REMOTE_ADDR'] != "") ? $_SERVER['REMOTE_ADDR'] : FALSE; $fip = (isset($_SERVER['HTTP_X_FORWARDED_FOR']) AND $_SERVER['HTTP_X_FORWARDED_FOR'] != "") ? $_SERVER['HTTP_X_FORWARDED_FOR'] : FALSE; - if ($cip && $rip) $this->_IP = $cip; + if ($cip && $rip) $this->_IP = $cip; elseif ($rip) $this->_IP = $rip; elseif ($cip) $this->_IP = $cip; elseif ($fip) $this->_IP = $fip; @@ -1884,7 +1884,7 @@ class CI_Email { return $this->_IP; } - + // -------------------------------------------------------------------- /** @@ -1908,7 +1908,7 @@ class CI_Email { $msg .= "
    ".$this->_header_str."\n".htmlspecialchars($this->_subject)."\n".htmlspecialchars($this->_finalbody).'
    '; return $msg; } - + // -------------------------------------------------------------------- /** @@ -1932,7 +1932,7 @@ class CI_Email { $this->_debug_msg[] = str_replace('%s', $val, $line)."
    "; } } - + // -------------------------------------------------------------------- /** diff --git a/system/libraries/Encrypt.php b/system/libraries/Encrypt.php index b27847a55..b95dd999c 100644 --- a/system/libraries/Encrypt.php +++ b/system/libraries/Encrypt.php @@ -144,7 +144,7 @@ class CI_Encrypt { function decode($string, $key = '') { $key = $this->get_key($key); - + if (preg_match('/[^a-zA-Z0-9\/\+=]/', $string)) { return FALSE; @@ -163,12 +163,12 @@ class CI_Encrypt { { $dec = $this->_xor_decode($dec, $key); } - + return $dec; } // -------------------------------------------------------------------- - + /** * Encode from Legacy * @@ -176,7 +176,7 @@ class CI_Encrypt { * returns a newly encoded string using the improved method added in 2.0.0 * This allows for backwards compatibility and a method to transition to the * new encryption algorithms. - * + * * For more details, see http://codeigniter.com/user_guide/installation/upgrade_200.html#encryption * * @access public @@ -192,22 +192,22 @@ class CI_Encrypt { log_message('error', 'Encoding from legacy is available only when Mcrypt is in use.'); return FALSE; } - + // decode it first // set mode temporarily to what it was when string was encoded with the legacy - // algorithm - typically MCRYPT_MODE_ECB + // algorithm - typically MCRYPT_MODE_ECB $current_mode = $this->_get_mode(); $this->set_mode($legacy_mode); - + $key = $this->get_key($key); - + if (preg_match('/[^a-zA-Z0-9\/\+=]/', $string)) { return FALSE; } $dec = base64_decode($string); - + if (($dec = $this->mcrypt_decode($dec, $key)) === FALSE) { return FALSE; @@ -223,7 +223,7 @@ class CI_Encrypt { } // -------------------------------------------------------------------- - + /** * XOR Encode * @@ -247,7 +247,7 @@ class CI_Encrypt { $enc = ''; for ($i = 0; $i < strlen($string); $i++) - { + { $enc .= substr($rand, ($i % strlen($rand)), 1).(substr($rand, ($i % strlen($rand)), 1) ^ substr($string, $i, 1)); } @@ -410,7 +410,7 @@ class CI_Encrypt { { $temp = $temp + 256; } - + $str .= chr($temp); } @@ -418,7 +418,7 @@ class CI_Encrypt { } // -------------------------------------------------------------------- - + /** * Set the Mcrypt Cipher * @@ -477,7 +477,7 @@ class CI_Encrypt { { $this->_mcrypt_mode = MCRYPT_MODE_CBC; } - + return $this->_mcrypt_mode; } @@ -503,7 +503,7 @@ class CI_Encrypt { * @access public * @param string * @return string - */ + */ function hash($str) { return ($this->_hash_type == 'sha1') ? $this->sha1($str) : md5($str); diff --git a/system/libraries/Form_validation.php b/system/libraries/Form_validation.php index 64baaef25..566655b12 100644 --- a/system/libraries/Form_validation.php +++ b/system/libraries/Form_validation.php @@ -25,29 +25,29 @@ * @link http://codeigniter.com/user_guide/libraries/form_validation.html */ class CI_Form_validation { - + var $CI; - var $_field_data = array(); + var $_field_data = array(); var $_config_rules = array(); var $_error_array = array(); - var $_error_messages = array(); + var $_error_messages = array(); var $_error_prefix = '

    '; var $_error_suffix = '

    '; var $error_string = ''; - var $_safe_form_data = FALSE; + var $_safe_form_data = FALSE; /** * Constructor * - */ + */ function CI_Form_validation($rules = array()) - { + { $this->CI =& get_instance(); - + // Validation rules can be stored in a config file. $this->_config_rules = $rules; - + // Automatically load the form helper $this->CI->load->helper('form'); @@ -56,12 +56,12 @@ class CI_Form_validation { { mb_internal_encoding($this->CI->config->item('charset')); } - + log_message('debug', "Form Validation Class Initialized"); } - + // -------------------------------------------------------------------- - + /** * Set Rules * @@ -80,7 +80,7 @@ class CI_Form_validation { { return; } - + // If an array was passed via the first parameter instead of indidual string // values we cycle through it and recursively call this function. if (is_array($field)) @@ -101,7 +101,7 @@ class CI_Form_validation { } return; } - + // No fields? Nothing to do... if ( ! is_string($field) OR ! is_string($rules) OR $field == '') { @@ -113,9 +113,9 @@ class CI_Form_validation { // Is the field name an array? We test for the existence of a bracket "[" in // the field name to determine this. If it is an array, we break it apart - // into its components so that we can fetch the corresponding POST data later + // into its components so that we can fetch the corresponding POST data later if (strpos($field, '[') !== FALSE AND preg_match_all('/\[(.*?)\]/', $field, $matches)) - { + { // Note: Due to a bug in current() that affects some versions // of PHP we can not pass function call directly into it $x = explode('[', $field); @@ -128,19 +128,19 @@ class CI_Form_validation { $indexes[] = $matches['1'][$i]; } } - + $is_array = TRUE; } else { - $indexes = array(); - $is_array = FALSE; + $indexes = array(); + $is_array = FALSE; } - - // Build our master array + + // Build our master array $this->_field_data[$field] = array( - 'field' => $field, - 'label' => $label, + 'field' => $field, + 'label' => $label, 'rules' => $rules, 'is_array' => $is_array, 'keys' => $indexes, @@ -150,7 +150,7 @@ class CI_Form_validation { } // -------------------------------------------------------------------- - + /** * Set Error Message * @@ -168,12 +168,12 @@ class CI_Form_validation { { $lang = array($lang => $val); } - + $this->_error_messages = array_merge($this->_error_messages, $lang); } - + // -------------------------------------------------------------------- - + /** * Set The Error Delimiter * @@ -183,7 +183,7 @@ class CI_Form_validation { * @param string * @param string * @return void - */ + */ function set_error_delimiters($prefix = '

    ', $suffix = '

    ') { $this->_error_prefix = $prefix; @@ -191,7 +191,7 @@ class CI_Form_validation { } // -------------------------------------------------------------------- - + /** * Get Error Message * @@ -200,14 +200,14 @@ class CI_Form_validation { * @access public * @param string the field name * @return void - */ + */ function error($field = '', $prefix = '', $suffix = '') - { + { if ( ! isset($this->_field_data[$field]['error']) OR $this->_field_data[$field]['error'] == '') { return ''; } - + if ($prefix == '') { $prefix = $this->_error_prefix; @@ -222,7 +222,7 @@ class CI_Form_validation { } // -------------------------------------------------------------------- - + /** * Error String * @@ -232,7 +232,7 @@ class CI_Form_validation { * @param string * @param string * @return str - */ + */ function error_string($prefix = '', $suffix = '') { // No errrors, validation passes! @@ -240,7 +240,7 @@ class CI_Form_validation { { return ''; } - + if ($prefix == '') { $prefix = $this->_error_prefix; @@ -250,7 +250,7 @@ class CI_Form_validation { { $suffix = $this->_error_suffix; } - + // Generate the error string $str = ''; foreach ($this->_error_array as $val) @@ -260,12 +260,12 @@ class CI_Form_validation { $str .= $prefix.$val.$suffix."\n"; } } - + return $str; } // -------------------------------------------------------------------- - + /** * Run the Validator * @@ -273,7 +273,7 @@ class CI_Form_validation { * * @access public * @return bool - */ + */ function run($group = '') { // Do we even have any data to process? Mm? @@ -281,7 +281,7 @@ class CI_Form_validation { { return FALSE; } - + // Does the _field_data array containing the validation rules exist? // If not, we look to see if they were assigned via a config file if (count($this->_field_data) == 0) @@ -291,10 +291,10 @@ class CI_Form_validation { { return FALSE; } - + // Is there a validation rule for the particular URI being accessed? $uri = ($group == '') ? trim($this->CI->uri->ruri_string(), '/') : $group; - + if ($uri != '' AND isset($this->_config_rules[$uri])) { $this->set_rules($this->_config_rules[$uri]); @@ -303,7 +303,7 @@ class CI_Form_validation { { $this->set_rules($this->_config_rules); } - + // We're we able to set the rules correctly? if (count($this->_field_data) == 0) { @@ -311,17 +311,17 @@ class CI_Form_validation { return FALSE; } } - + // Load the language file containing error messages $this->CI->lang->load('form_validation'); - - // Cycle through the rules for each field, match the + + // Cycle through the rules for each field, match the // corresponding $_POST item and test for errors foreach ($this->_field_data as $field => $row) - { + { // Fetch the data from the corresponding $_POST array and cache it in the _field_data array. // Depending on whether the field name is an array or a string will determine where we get it from. - + if ($row['is_array'] == TRUE) { $this->_field_data[$field]['postdata'] = $this->_reduce_array($_POST, $row['keys']); @@ -333,8 +333,8 @@ class CI_Form_validation { $this->_field_data[$field]['postdata'] = $_POST[$field]; } } - - $this->_execute($row, explode('|', $row['rules']), $this->_field_data[$field]['postdata']); + + $this->_execute($row, explode('|', $row['rules']), $this->_field_data[$field]['postdata']); } // Did we end up with any errors? @@ -347,7 +347,7 @@ class CI_Form_validation { // Now we need to re-set the POST data with the new, processed data $this->_reset_post_array(); - + // No errors, validation passes! if ($total_errors == 0) { @@ -359,7 +359,7 @@ class CI_Form_validation { } // -------------------------------------------------------------------- - + /** * Traverse a multidimensional $_POST array index until the data is found * @@ -368,7 +368,7 @@ class CI_Form_validation { * @param array * @param integer * @return mixed - */ + */ function _reduce_array($array, $keys, $i = 0) { if (is_array($array)) @@ -389,18 +389,18 @@ class CI_Form_validation { return $array; } } - + return $array; } // -------------------------------------------------------------------- - + /** * Re-populate the _POST array with our finalized and processed data * * @access private * @return null - */ + */ function _reset_post_array() { foreach ($this->_field_data as $field => $row) @@ -418,7 +418,7 @@ class CI_Form_validation { { // start with a reference $post_ref =& $_POST; - + // before we assign values, make a reference to the right POST key if (count($row['keys']) == 1) { @@ -452,7 +452,7 @@ class CI_Form_validation { } // -------------------------------------------------------------------- - + /** * Executes the Validation routines * @@ -462,21 +462,21 @@ class CI_Form_validation { * @param mixed * @param integer * @return mixed - */ + */ function _execute($row, $rules, $postdata = NULL, $cycles = 0) { // If the $_POST data is an array we will run a recursive call if (is_array($postdata)) - { + { foreach ($postdata as $key => $val) { $this->_execute($row, $rules, $val, $cycles); $cycles++; } - + return; } - + // -------------------------------------------------------------------- // If the field is blank, but NOT required, no further tests are necessary @@ -496,7 +496,7 @@ class CI_Form_validation { } // -------------------------------------------------------------------- - + // Isset Test. Typically this rule will only apply to checkboxes. if (is_null($postdata) AND $callback == FALSE) { @@ -504,31 +504,31 @@ class CI_Form_validation { { // Set the message type $type = (in_array('required', $rules)) ? 'required' : 'isset'; - + if ( ! isset($this->_error_messages[$type])) { if (FALSE === ($line = $this->CI->lang->line($type))) { $line = 'The field was not set'; - } + } } else { $line = $this->_error_messages[$type]; } - + // Build the error message $message = sprintf($line, $this->_translate_fieldname($row['label'])); // Save the error message $this->_field_data[$row['field']]['error'] = $message; - + if ( ! isset($this->_error_array[$row['field']])) { $this->_error_array[$row['field']] = $message; } } - + return; } @@ -538,7 +538,7 @@ class CI_Form_validation { foreach ($rules As $rule) { $_in_array = FALSE; - + // We set the $postdata variable with the current data in our master array so that // each cycle of the loop is dealing with the processed data from the last cycle if ($row['is_array'] == TRUE AND is_array($this->_field_data[$row['field']]['postdata'])) @@ -549,7 +549,7 @@ class CI_Form_validation { { continue; } - + $postdata = $this->_field_data[$row['field']]['postdata'][$cycles]; $_in_array = TRUE; } @@ -559,15 +559,15 @@ class CI_Form_validation { } // -------------------------------------------------------------------- - - // Is the rule a callback? + + // Is the rule a callback? $callback = FALSE; if (substr($rule, 0, 9) == 'callback_') { $rule = substr($rule, 9); $callback = TRUE; } - + // Strip the parameter (if exists) from the rule // Rules can contain a parameter: max_length[5] $param = FALSE; @@ -576,15 +576,15 @@ class CI_Form_validation { $rule = $match[1]; $param = $match[2]; } - + // Call the function that corresponds to the rule if ($callback === TRUE) { if ( ! method_exists($this->CI, $rule)) - { + { continue; } - + // Run the function and grab the result $result = $this->CI->$rule($postdata, $param); @@ -597,7 +597,7 @@ class CI_Form_validation { { $this->_field_data[$row['field']]['postdata'] = (is_bool($result)) ? $postdata : $result; } - + // If the field isn't required and we just processed a callback we'll move on... if ( ! in_array('required', $rules, TRUE) AND $result !== FALSE) { @@ -605,15 +605,15 @@ class CI_Form_validation { } } else - { + { if ( ! method_exists($this, $rule)) { - // If our own wrapper function doesn't exist we see if a native PHP function does. + // If our own wrapper function doesn't exist we see if a native PHP function does. // Users can use any native PHP function call that has one param. if (function_exists($rule)) { $result = $rule($postdata); - + if ($_in_array == TRUE) { $this->_field_data[$row['field']]['postdata'][$cycles] = (is_bool($result)) ? $postdata : $result; @@ -623,7 +623,7 @@ class CI_Form_validation { $this->_field_data[$row['field']]['postdata'] = (is_bool($result)) ? $postdata : $result; } } - + continue; } @@ -638,54 +638,54 @@ class CI_Form_validation { $this->_field_data[$row['field']]['postdata'] = (is_bool($result)) ? $postdata : $result; } } - + // Did the rule test negatively? If so, grab the error. if ($result === FALSE) - { + { if ( ! isset($this->_error_messages[$rule])) { if (FALSE === ($line = $this->CI->lang->line($rule))) { $line = 'Unable to access an error message corresponding to your field name.'; - } + } } else { $line = $this->_error_messages[$rule]; } - + // Is the parameter we are inserting into the error message the name // of another field? If so we need to grab its "field label" if (isset($this->_field_data[$param]) AND isset($this->_field_data[$param]['label'])) { $param = $this->_translate_fieldname($this->_field_data[$param]['label']); } - + // Build the error message $message = sprintf($line, $this->_translate_fieldname($row['label']), $param); // Save the error message $this->_field_data[$row['field']]['error'] = $message; - + if ( ! isset($this->_error_array[$row['field']])) { $this->_error_array[$row['field']] = $message; } - + return; } } } // -------------------------------------------------------------------- - + /** * Translate a field name * * @access private * @param string the field name * @return string - */ + */ function _translate_fieldname($fieldname) { // Do we need to translate the field name? @@ -693,8 +693,8 @@ class CI_Form_validation { if (substr($fieldname, 0, 5) == 'lang:') { // Grab the variable - $line = substr($fieldname, 5); - + $line = substr($fieldname, 5); + // Were we able to translate the field name? If not we use $line if (FALSE === ($fieldname = $this->CI->lang->line($line))) { @@ -706,7 +706,7 @@ class CI_Form_validation { } // -------------------------------------------------------------------- - + /** * Get the value from a form * @@ -717,19 +717,19 @@ class CI_Form_validation { * @param string the field name * @param string * @return void - */ + */ function set_value($field = '', $default = '') { if ( ! isset($this->_field_data[$field])) { return $default; } - + return $this->_field_data[$field]['postdata']; } - + // -------------------------------------------------------------------- - + /** * Set Select * @@ -740,9 +740,9 @@ class CI_Form_validation { * @param string * @param string * @return string - */ + */ function set_select($field = '', $value = '', $default = FALSE) - { + { if ( ! isset($this->_field_data[$field]) OR ! isset($this->_field_data[$field]['postdata'])) { if ($default === TRUE AND count($this->_field_data) === 0) @@ -751,9 +751,9 @@ class CI_Form_validation { } return ''; } - + $field = $this->_field_data[$field]['postdata']; - + if (is_array($field)) { if ( ! in_array($value, $field)) @@ -768,12 +768,12 @@ class CI_Form_validation { return ''; } } - + return ' selected="selected"'; } - + // -------------------------------------------------------------------- - + /** * Set Radio * @@ -784,7 +784,7 @@ class CI_Form_validation { * @param string * @param string * @return string - */ + */ function set_radio($field = '', $value = '', $default = FALSE) { if ( ! isset($this->_field_data[$field]) OR ! isset($this->_field_data[$field]['postdata'])) @@ -795,9 +795,9 @@ class CI_Form_validation { } return ''; } - + $field = $this->_field_data[$field]['postdata']; - + if (is_array($field)) { if ( ! in_array($value, $field)) @@ -812,12 +812,12 @@ class CI_Form_validation { return ''; } } - + return ' checked="checked"'; } - + // -------------------------------------------------------------------- - + /** * Set Checkbox * @@ -828,7 +828,7 @@ class CI_Form_validation { * @param string * @param string * @return string - */ + */ function set_checkbox($field = '', $value = '', $default = FALSE) { if ( ! isset($this->_field_data[$field]) OR ! isset($this->_field_data[$field]['postdata'])) @@ -839,9 +839,9 @@ class CI_Form_validation { } return ''; } - + $field = $this->_field_data[$field]['postdata']; - + if (is_array($field)) { if ( ! in_array($value, $field)) @@ -856,12 +856,12 @@ class CI_Form_validation { return ''; } } - + return ' checked="checked"'; } - + // -------------------------------------------------------------------- - + /** * Required * @@ -880,9 +880,9 @@ class CI_Form_validation { return ( ! empty($str)); } } - + // -------------------------------------------------------------------- - + /** * Match one field to another * @@ -895,16 +895,16 @@ class CI_Form_validation { { if ( ! isset($_POST[$field])) { - return FALSE; + return FALSE; } - + $field = $_POST[$field]; return ($str !== $field) ? FALSE : TRUE; } - + // -------------------------------------------------------------------- - + /** * Minimum Length * @@ -912,7 +912,7 @@ class CI_Form_validation { * @param string * @param value * @return bool - */ + */ function min_length($str, $val) { if (preg_match("/[^0-9]/", $val)) @@ -922,14 +922,14 @@ class CI_Form_validation { if (function_exists('mb_strlen')) { - return (mb_strlen($str) < $val) ? FALSE : TRUE; + return (mb_strlen($str) < $val) ? FALSE : TRUE; } - + return (strlen($str) < $val) ? FALSE : TRUE; } - + // -------------------------------------------------------------------- - + /** * Max Length * @@ -937,7 +937,7 @@ class CI_Form_validation { * @param string * @param value * @return bool - */ + */ function max_length($str, $val) { if (preg_match("/[^0-9]/", $val)) @@ -947,14 +947,14 @@ class CI_Form_validation { if (function_exists('mb_strlen')) { - return (mb_strlen($str) > $val) ? FALSE : TRUE; + return (mb_strlen($str) > $val) ? FALSE : TRUE; } - + return (strlen($str) > $val) ? FALSE : TRUE; } - + // -------------------------------------------------------------------- - + /** * Exact Length * @@ -962,7 +962,7 @@ class CI_Form_validation { * @param string * @param value * @return bool - */ + */ function exact_length($str, $val) { if (preg_match("/[^0-9]/", $val)) @@ -972,42 +972,42 @@ class CI_Form_validation { if (function_exists('mb_strlen')) { - return (mb_strlen($str) != $val) ? FALSE : TRUE; + return (mb_strlen($str) != $val) ? FALSE : TRUE; } - + return (strlen($str) != $val) ? FALSE : TRUE; } - + // -------------------------------------------------------------------- - + /** * Valid Email * * @access public * @param string * @return bool - */ + */ function valid_email($str) { return ( ! preg_match("/^([a-z0-9\+_\-]+)(\.[a-z0-9\+_\-]+)*@([a-z0-9\-]+\.)+[a-z]{2,6}$/ix", $str)) ? FALSE : TRUE; } // -------------------------------------------------------------------- - + /** * Valid Emails * * @access public * @param string * @return bool - */ + */ function valid_emails($str) { if (strpos($str, ',') === FALSE) { return $this->valid_email(trim($str)); } - + foreach(explode(',', $str) as $email) { if (trim($email) != '' && $this->valid_email(trim($email)) === FALSE) @@ -1015,12 +1015,12 @@ class CI_Form_validation { return FALSE; } } - + return TRUE; } // -------------------------------------------------------------------- - + /** * Validate IP Address * @@ -1034,56 +1034,56 @@ class CI_Form_validation { } // -------------------------------------------------------------------- - + /** * Alpha * * @access public * @param string * @return bool - */ + */ function alpha($str) { return ( ! preg_match("/^([a-z])+$/i", $str)) ? FALSE : TRUE; } - + // -------------------------------------------------------------------- - + /** * Alpha-numeric * * @access public * @param string * @return bool - */ + */ function alpha_numeric($str) { return ( ! preg_match("/^([a-z0-9])+$/i", $str)) ? FALSE : TRUE; } - + // -------------------------------------------------------------------- - + /** * Alpha-numeric with underscores and dashes * * @access public * @param string * @return bool - */ + */ function alpha_dash($str) { return ( ! preg_match("/^([-a-z0-9_-])+$/i", $str)) ? FALSE : TRUE; } - + // -------------------------------------------------------------------- - + /** * Numeric * * @access public * @param string * @return bool - */ + */ function numeric($str) { return (bool)preg_match( '/^[\-+]?[0-9]*\.?[0-9]+$/', $str); @@ -1092,72 +1092,72 @@ class CI_Form_validation { // -------------------------------------------------------------------- - /** - * Is Numeric - * - * @access public - * @param string - * @return bool - */ - function is_numeric($str) - { - return ( ! is_numeric($str)) ? FALSE : TRUE; - } + /** + * Is Numeric + * + * @access public + * @param string + * @return bool + */ + function is_numeric($str) + { + return ( ! is_numeric($str)) ? FALSE : TRUE; + } // -------------------------------------------------------------------- - + /** * Integer * * @access public * @param string * @return bool - */ + */ function integer($str) { return (bool)preg_match( '/^[\-+]?[0-9]+$/', $str); } - + // -------------------------------------------------------------------- - /** - * Is a Natural number (0,1,2,3, etc.) - * - * @access public - * @param string - * @return bool - */ - function is_natural($str) - { - return (bool)preg_match( '/^[0-9]+$/', $str); - } + /** + * Is a Natural number (0,1,2,3, etc.) + * + * @access public + * @param string + * @return bool + */ + function is_natural($str) + { + return (bool)preg_match( '/^[0-9]+$/', $str); + } // -------------------------------------------------------------------- - /** - * Is a Natural number, but not a zero (1,2,3, etc.) - * - * @access public - * @param string - * @return bool - */ + /** + * Is a Natural number, but not a zero (1,2,3, etc.) + * + * @access public + * @param string + * @return bool + */ function is_natural_no_zero($str) - { - if ( ! preg_match( '/^[0-9]+$/', $str)) - { - return FALSE; - } - - if ($str == 0) - { - return FALSE; - } - - return TRUE; - } - + { + if ( ! preg_match( '/^[0-9]+$/', $str)) + { + return FALSE; + } + + if ($str == 0) + { + return FALSE; + } + + return TRUE; + } + // -------------------------------------------------------------------- - + /** * Valid Base64 * @@ -1172,9 +1172,9 @@ class CI_Form_validation { { return (bool) ! preg_match('/[^a-zA-Z0-9\/\+=]/', $str); } - + // -------------------------------------------------------------------- - + /** * Prep data for form * @@ -1193,10 +1193,10 @@ class CI_Form_validation { { $data[$key] = $this->prep_for_form($val); } - + return $data; } - + if ($this->_safe_form_data == FALSE OR $data === '') { return $data; @@ -1204,54 +1204,54 @@ class CI_Form_validation { return str_replace(array("'", '"', '<', '>'), array("'", """, '<', '>'), stripslashes($data)); } - + // -------------------------------------------------------------------- - + /** * Prep URL * * @access public * @param string * @return string - */ + */ function prep_url($str = '') { if ($str == 'http://' OR $str == '') { return ''; } - + if (substr($str, 0, 7) != 'http://' && substr($str, 0, 8) != 'https://') { $str = 'http://'.$str; } - + return $str; } - + // -------------------------------------------------------------------- - + /** * Strip Image Tags * * @access public * @param string * @return string - */ + */ function strip_image_tags($str) { return $this->CI->input->strip_image_tags($str); } - + // -------------------------------------------------------------------- - + /** * XSS Clean * * @access public * @param string * @return string - */ + */ function xss_clean($str) { if ( ! isset($this->CI->security)) @@ -1261,16 +1261,16 @@ class CI_Form_validation { return $this->CI->security->xss_clean($str); } - + // -------------------------------------------------------------------- - + /** * Convert PHP tags to entities * * @access public * @param string * @return string - */ + */ function encode_php_tags($str) { return str_replace(array(''), array('<?php', '<?PHP', '<?', '?>'), $str); diff --git a/system/libraries/Ftp.php b/system/libraries/Ftp.php index 07f4b1ff3..fa2d3770b 100644 --- a/system/libraries/Ftp.php +++ b/system/libraries/Ftp.php @@ -295,7 +295,7 @@ class CI_FTP { { return FALSE; } - + // Set the mode if not specified if ($mode == 'auto') { @@ -303,9 +303,9 @@ class CI_FTP { $ext = $this->_getext($rempath); $mode = $this->_settype($ext); } - + $mode = ($mode == 'ascii') ? FTP_ASCII : FTP_BINARY; - + $result = @ftp_get($this->conn_id, $locpath, $rempath, $mode); if ($result === FALSE) @@ -314,11 +314,11 @@ class CI_FTP { { $this->_error('ftp_unable_to_download'); } - return FALSE; + return FALSE; } - + return TRUE; - } + } // -------------------------------------------------------------------- @@ -454,7 +454,7 @@ class CI_FTP { * Set file permissions * * @access public - * @param string the file path + * @param string the file path * @param string the permissions * @return bool */ diff --git a/system/libraries/Image_lib.php b/system/libraries/Image_lib.php index 806d942ba..99225600f 100644 --- a/system/libraries/Image_lib.php +++ b/system/libraries/Image_lib.php @@ -26,7 +26,7 @@ */ class CI_Image_lib { - var $image_library = 'gd2'; // Can be: imagemagick, netpbm, gd, gd2 + var $image_library = 'gd2'; // Can be: imagemagick, netpbm, gd, gd2 var $library_path = ''; var $dynamic_output = FALSE; // Whether to send to browser or write to disk var $source_image = ''; @@ -36,7 +36,7 @@ class CI_Image_lib { var $quality = '90'; var $create_thumb = FALSE; var $thumb_marker = '_thumb'; - var $maintain_ratio = TRUE; // Whether to maintain aspect ratio when resizing or use hard values + var $maintain_ratio = TRUE; // Whether to maintain aspect ratio when resizing or use hard values var $master_dim = 'auto'; // auto, height, or width. Determines what to use as the master dimension var $rotation_angle = ''; var $x_axis = ''; @@ -54,11 +54,11 @@ class CI_Image_lib { var $wm_hor_alignment = 'C'; // Horizontal alignment: L R C var $wm_padding = 0; // Padding around text var $wm_hor_offset = 0; // Lets you push text to the right - var $wm_vrt_offset = 0; // Lets you push text down + var $wm_vrt_offset = 0; // Lets you push text down var $wm_font_color = '#ffffff'; // Text color var $wm_shadow_color = ''; // Dropshadow color var $wm_shadow_distance = 2; // Dropshadow distance - var $wm_opacity = 50; // Image opacity: 1 - 100 Only works with image + var $wm_opacity = 50; // Image opacity: 1 - 100 Only works with image // Private Vars var $source_folder = ''; @@ -147,7 +147,7 @@ class CI_Image_lib { if ($this->source_image == '') { $this->set_error('imglib_source_image_required'); - return FALSE; + return FALSE; } /* @@ -190,7 +190,7 @@ class CI_Image_lib { // Set the Image Properties if ( ! $this->get_image_properties($this->source_folder.$this->source_image)) { - return FALSE; + return FALSE; } /* @@ -400,7 +400,7 @@ class CI_Image_lib { if ($this->rotation_angle == '' OR ! in_array($this->rotation_angle, $degs)) { $this->set_error('imglib_rotation_angle_required'); - return FALSE; + return FALSE; } // Reassign the width and height @@ -455,8 +455,8 @@ class CI_Image_lib { { if ($this->orig_width == $this->width AND $this->orig_height == $this->height) { - if ($this->source_image != $this->new_image) - { + if ($this->source_image != $this->new_image) + { if (@copy($this->full_src_path, $this->full_dst_path)) { @chmod($this->full_dst_path, FILE_WRITE_MODE); @@ -494,14 +494,14 @@ class CI_Image_lib { return FALSE; } - // Create The Image + // Create The Image // // old conditional which users report cause problems with shared GD libs who report themselves as "2.0 or greater" // it appears that this is no longer the issue that it was in 2004, so we've removed it, retaining it in the comment // below should that ever prove inaccurate. // // if ($this->image_library == 'gd2' AND function_exists('imagecreatetruecolor') AND $v2_override == FALSE) - if ($this->image_library == 'gd2' AND function_exists('imagecreatetruecolor')) + if ($this->image_library == 'gd2' AND function_exists('imagecreatetruecolor')) { $create = 'imagecreatetruecolor'; $copy = 'imagecopyresampled'; @@ -519,7 +519,7 @@ class CI_Image_lib { imagealphablending($dst_img, FALSE); imagesavealpha($dst_img, TRUE); } - + $copy($dst_img, $src_img, 0, 0, $this->x_axis, $this->y_axis, $this->width, $this->height, $this->orig_width, $this->orig_height); // Show the image @@ -584,9 +584,9 @@ class CI_Image_lib { { switch ($this->rotation_angle) { - case 'hor' : $angle = '-flop'; + case 'hor' : $angle = '-flop'; break; - case 'vrt' : $angle = '-flip'; + case 'vrt' : $angle = '-flip'; break; default : $angle = '-rotate '.$this->rotation_angle; break; @@ -664,7 +664,7 @@ class CI_Image_lib { break; case 180 : $angle = 'r180'; break; - case 270 : $angle = 'r90'; + case 270 : $angle = 'r90'; break; case 'vrt' : $angle = 'tb'; break; @@ -889,7 +889,7 @@ class CI_Image_lib { $this->get_image_properties(); // Fetch watermark image properties - $props = $this->get_image_properties($this->wm_overlay_path, TRUE); + $props = $this->get_image_properties($this->wm_overlay_path, TRUE); $wm_img_type = $props['image_type']; $wm_width = $props['width']; $wm_height = $props['height']; @@ -944,7 +944,7 @@ class CI_Image_lib { if ($wm_img_type == 3 AND function_exists('imagealphablending')) { @imagealphablending($src_img, TRUE); - } + } // Set RGB values for text and shadow $rgba = imagecolorat($wm_img, $this->wm_x_transp, $this->wm_y_transp); @@ -1266,7 +1266,7 @@ class CI_Image_lib { switch ($this->image_type) { - case 1 : imagegif($resource); + case 1 : imagegif($resource); break; case 2 : imagejpeg($resource, '', $this->quality); break; @@ -1384,8 +1384,8 @@ class CI_Image_lib { * new variable needs to be known * * $props = array( - * 'width' => $width, - * 'height' => $height, + * 'width' => $width, + * 'height' => $height, * 'new_width' => 40, * 'new_height' => '' * ); @@ -1446,7 +1446,7 @@ class CI_Image_lib { { $ext = strrchr($source_image, '.'); $name = ($ext === FALSE) ? $source_image : substr($source_image, 0, -strlen($ext)); - + return array('ext' => $ext, 'name' => $name); } diff --git a/system/libraries/Javascript.php b/system/libraries/Javascript.php index efaaab4bf..b4f33e309 100644 --- a/system/libraries/Javascript.php +++ b/system/libraries/Javascript.php @@ -29,9 +29,9 @@ class CI_Javascript { var $_javascript_location = 'js'; function CI_Javascript($params = array()) - { + { $defaults = array('js_library_driver' => 'jquery', 'autoload' => TRUE); - + foreach ($defaults as $key => $val) { if (isset($params[$key]) && $params[$key] !== "") @@ -39,7 +39,7 @@ class CI_Javascript { $defaults[$key] = $params[$key]; } } - + extract($defaults); $this->CI =& get_instance(); @@ -48,13 +48,13 @@ class CI_Javascript { $this->CI->load->library('javascript/'.$js_library_driver, array('autoload' => $autoload)); // make js to refer to current library $this->js =& $this->CI->$js_library_driver; - + log_message('debug', "Javascript Class Initialized and loaded. Driver used: $js_library_driver"); } - // -------------------------------------------------------------------- - // Event Code // -------------------------------------------------------------------- + // Event Code + // -------------------------------------------------------------------- /** * Blur @@ -70,9 +70,9 @@ class CI_Javascript { { return $this->js->_blur($element, $js); } - + // -------------------------------------------------------------------- - + /** * Change * @@ -87,9 +87,9 @@ class CI_Javascript { { return $this->js->_change($element, $js); } - + // -------------------------------------------------------------------- - + /** * Click * @@ -107,7 +107,7 @@ class CI_Javascript { } // -------------------------------------------------------------------- - + /** * Double Click * @@ -124,7 +124,7 @@ class CI_Javascript { } // -------------------------------------------------------------------- - + /** * Error * @@ -141,7 +141,7 @@ class CI_Javascript { } // -------------------------------------------------------------------- - + /** * Focus * @@ -158,7 +158,7 @@ class CI_Javascript { } // -------------------------------------------------------------------- - + /** * Hover * @@ -168,7 +168,7 @@ class CI_Javascript { * @param string - element * @param string - Javascript code for mouse over * @param string - Javascript code for mouse out - * @return string + * @return string */ function hover($element = 'this', $over, $out) { @@ -176,7 +176,7 @@ class CI_Javascript { } // -------------------------------------------------------------------- - + /** * Keydown * @@ -193,7 +193,7 @@ class CI_Javascript { } // -------------------------------------------------------------------- - + /** * Keyup * @@ -207,10 +207,10 @@ class CI_Javascript { function keyup($element = 'this', $js = '') { return $this->js->_keyup($element, $js); - } + } // -------------------------------------------------------------------- - + /** * Load * @@ -224,10 +224,10 @@ class CI_Javascript { function load($element = 'this', $js = '') { return $this->js->_load($element, $js); - } - + } + // -------------------------------------------------------------------- - + /** * Mousedown * @@ -244,7 +244,7 @@ class CI_Javascript { } // -------------------------------------------------------------------- - + /** * Mouse Out * @@ -261,7 +261,7 @@ class CI_Javascript { } // -------------------------------------------------------------------- - + /** * Mouse Over * @@ -360,7 +360,7 @@ class CI_Javascript { { return $this->js->_scroll($element, $js); } - + // -------------------------------------------------------------------- /** @@ -378,9 +378,9 @@ class CI_Javascript { return $this->js->_unload($element, $js); } - // -------------------------------------------------------------------- - // Effects // -------------------------------------------------------------------- + // Effects + // -------------------------------------------------------------------- /** @@ -391,14 +391,14 @@ class CI_Javascript { * @access public * @param string - element * @param string - Class to add - * @return string + * @return string */ function addClass($element = 'this', $class = '') { return $this->js->_addClass($element, $class); } - // -------------------------------------------------------------------- + // -------------------------------------------------------------------- /** * Animate @@ -409,7 +409,7 @@ class CI_Javascript { * @param string - element * @param string - One of 'slow', 'normal', 'fast', or time in milliseconds * @param string - Javascript callback function - * @return string + * @return string */ function animate($element = 'this', $params = array(), $speed = '', $extra = '') { @@ -417,7 +417,7 @@ class CI_Javascript { } // -------------------------------------------------------------------- - + /** * Fade In * @@ -427,15 +427,15 @@ class CI_Javascript { * @param string - element * @param string - One of 'slow', 'normal', 'fast', or time in milliseconds * @param string - Javascript callback function - * @return string + * @return string */ function fadeIn($element = 'this', $speed = '', $callback = '') { return $this->js->_fadeIn($element, $speed, $callback); } - + // -------------------------------------------------------------------- - + /** * Fade Out * @@ -445,14 +445,14 @@ class CI_Javascript { * @param string - element * @param string - One of 'slow', 'normal', 'fast', or time in milliseconds * @param string - Javascript callback function - * @return string + * @return string */ function fadeOut($element = 'this', $speed = '', $callback = '') { return $this->js->_fadeOut($element, $speed, $callback); } // -------------------------------------------------------------------- - + /** * Slide Up * @@ -462,14 +462,14 @@ class CI_Javascript { * @param string - element * @param string - One of 'slow', 'normal', 'fast', or time in milliseconds * @param string - Javascript callback function - * @return string + * @return string */ function slideUp($element = 'this', $speed = '', $callback = '') { return $this->js->_slideUp($element, $speed, $callback); } - + // -------------------------------------------------------------------- /** @@ -480,15 +480,15 @@ class CI_Javascript { * @access public * @param string - element * @param string - Class to add - * @return string + * @return string */ function removeClass($element = 'this', $class = '') { return $this->js->_removeClass($element, $class); } - // -------------------------------------------------------------------- - + // -------------------------------------------------------------------- + /** * Slide Down * @@ -498,7 +498,7 @@ class CI_Javascript { * @param string - element * @param string - One of 'slow', 'normal', 'fast', or time in milliseconds * @param string - Javascript callback function - * @return string + * @return string */ function slideDown($element = 'this', $speed = '', $callback = '') { @@ -506,7 +506,7 @@ class CI_Javascript { } // -------------------------------------------------------------------- - + /** * Slide Toggle * @@ -516,14 +516,14 @@ class CI_Javascript { * @param string - element * @param string - One of 'slow', 'normal', 'fast', or time in milliseconds * @param string - Javascript callback function - * @return string + * @return string */ function slideToggle($element = 'this', $speed = '', $callback = '') { return $this->js->_slideToggle($element, $speed, $callback); } - + // -------------------------------------------------------------------- /** @@ -535,15 +535,15 @@ class CI_Javascript { * @param string - element * @param string - One of 'slow', 'normal', 'fast', or time in milliseconds * @param string - Javascript callback function - * @return string + * @return string */ function hide($element = 'this', $speed = '', $callback = '') { return $this->js->_hide($element, $speed, $callback); } - + // -------------------------------------------------------------------- - + /** * Toggle * @@ -551,16 +551,16 @@ class CI_Javascript { * * @access public * @param string - element - * @return string + * @return string */ function toggle($element = 'this') { return $this->js->_toggle($element); } - + // -------------------------------------------------------------------- - + /** * Toggle Class * @@ -568,15 +568,15 @@ class CI_Javascript { * * @access public * @param string - element - * @return string + * @return string */ function toggleClass($element = 'this', $class='') { return $this->js->_toggleClass($element, $class); } - + // -------------------------------------------------------------------- - + /** * Show * @@ -586,7 +586,7 @@ class CI_Javascript { * @param string - element * @param string - One of 'slow', 'normal', 'fast', or time in milliseconds * @param string - Javascript callback function - * @return string + * @return string */ function show($element = 'this', $speed = '', $callback = '') { @@ -604,12 +604,12 @@ class CI_Javascript { * @access public * @param string The element to attach the event to * @return string - */ + */ function compile($view_var = 'script_foot', $script_tags = TRUE) { $this->js->_compile($view_var, $script_tags); } - + /** * Clear Compile * @@ -624,7 +624,7 @@ class CI_Javascript { } // -------------------------------------------------------------------- - + /** * External * @@ -645,16 +645,16 @@ class CI_Javascript { if ($this->CI->config->item('javascript_location') != '') { $this->_javascript_location = $this->CI->config->item('javascript_location'); - } + } } - + if ($relative === TRUE OR strncmp($external_file, 'http://', 7) == 0 OR strncmp($external_file, 'https://', 8) == 0) { - $str = $this->_open_script($external_file); + $str = $this->_open_script($external_file); } elseif (strpos($this->_javascript_location, 'http://') !== FALSE) { - $str = $this->_open_script($this->_javascript_location.$external_file); + $str = $this->_open_script($this->_javascript_location.$external_file); } else { @@ -664,13 +664,13 @@ class CI_Javascript { $str .= $this->_close_script(); return $str; } - + // -------------------------------------------------------------------- - + /** * Inline * - * Outputs a + * Outputs an closing * * @access private - * @param string + * @param string * @return string */ function _close_script($extra = "\n") { return "$extra"; } - - + + // -------------------------------------------------------------------- // -------------------------------------------------------------------- // AJAX-Y STUFF - still a testbed @@ -736,15 +736,15 @@ class CI_Javascript { * @param string - element * @param string - One of 'slow', 'normal', 'fast', or time in milliseconds * @param string - Javascript callback function - * @return string + * @return string */ function update($element = 'this', $speed = '', $callback = '') { return $this->js->_updater($element, $speed, $callback); } - + // -------------------------------------------------------------------- - + /** * Generate JSON * @@ -780,7 +780,7 @@ class CI_Javascript { $json = array(); $_is_assoc = TRUE; - + if ( ! is_array($json_result) AND empty($json_result)) { show_error("Generate JSON Failed - Illegal key, value pair."); @@ -805,11 +805,11 @@ class CI_Javascript { $json = implode(',', $json); return $_is_assoc ? "{".$json."}" : "[".$json."]"; - + } - + // -------------------------------------------------------------------- - + /** * Is associative array * @@ -828,12 +828,12 @@ class CI_Javascript { return TRUE; } } - + return FALSE; } - + // -------------------------------------------------------------------- - + /** * Prep Args * @@ -862,7 +862,7 @@ class CI_Javascript { return $result; } } - + // -------------------------------------------------------------------- } // END Javascript Class diff --git a/system/libraries/Log.php b/system/libraries/Log.php index 4e6b3bc39..99ed126f4 100644 --- a/system/libraries/Log.php +++ b/system/libraries/Log.php @@ -40,27 +40,27 @@ class CI_Log { function CI_Log() { $config =& get_config(); - + $this->log_path = ($config['log_path'] != '') ? $config['log_path'] : BASEPATH.'logs/'; - + if ( ! is_dir($this->log_path) OR ! is_really_writable($this->log_path)) { $this->_enabled = FALSE; } - + if (is_numeric($config['log_threshold'])) { $this->_threshold = $config['log_threshold']; } - + if ($config['log_date_format'] != '') { $this->_date_fmt = $config['log_date_format']; } } - + // -------------------------------------------------------------------- - + /** * Write Log File * @@ -71,42 +71,42 @@ class CI_Log { * @param string the error message * @param bool whether the error is a native PHP error * @return bool - */ + */ function write_log($level = 'error', $msg, $php_error = FALSE) - { + { if ($this->_enabled === FALSE) { return FALSE; } - + $level = strtoupper($level); - + if ( ! isset($this->_levels[$level]) OR ($this->_levels[$level] > $this->_threshold)) { return FALSE; } - + $filepath = $this->log_path.'log-'.date('Y-m-d').EXT; $message = ''; - + if ( ! file_exists($filepath)) { $message .= "<"."?php if ( ! defined('BASEPATH')) exit('No direct script access allowed'); ?".">\n\n"; } - + if ( ! $fp = @fopen($filepath, FOPEN_WRITE_CREATE)) { return FALSE; } $message .= $level.' '.(($level == 'INFO') ? ' -' : '-').' '.date($this->_date_fmt). ' --> '.$msg."\n"; - - flock($fp, LOCK_EX); + + flock($fp, LOCK_EX); fwrite($fp, $message); flock($fp, LOCK_UN); fclose($fp); - - @chmod($filepath, FILE_WRITE_MODE); + + @chmod($filepath, FILE_WRITE_MODE); return TRUE; } diff --git a/system/libraries/Pagination.php b/system/libraries/Pagination.php index 3a0632d09..b3175f997 100644 --- a/system/libraries/Pagination.php +++ b/system/libraries/Pagination.php @@ -30,11 +30,11 @@ class CI_Pagination { var $prefix = ''; // A custom prefix added to the path. var $suffix = ''; // A custom suffix added to the path. - var $total_rows = ''; // Total number of items (database results) - var $per_page = 10; // Max number of items you want shown per page + var $total_rows = ''; // Total number of items (database results) + var $per_page = 10; // Max number of items you want shown per page var $num_links = 2; // Number of "digit" links to show before/after the currently viewed page - var $cur_page = 0; // The current page being viewed - var $first_link = '‹ First'; + var $cur_page = 0; // The current page being viewed + var $first_link = '‹ First'; var $next_link = '>'; var $prev_link = '<'; var $last_link = 'Last ›'; @@ -190,7 +190,7 @@ class CI_Pagination { $this->base_url = rtrim($this->base_url, '/') .'/'; } - // And here we go... + // And here we go... $output = ''; // Render the "First" link @@ -204,17 +204,17 @@ class CI_Pagination { if ($this->prev_link !== FALSE AND $this->cur_page != 1) { $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; + $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 @@ -234,7 +234,7 @@ class CI_Pagination { else { $n = ($i == 0) ? '' : $i; - + if ($n == '' && $this->first_url != '') { $output .= $this->num_tag_open.'anchor_class.'href="'.$this->first_url.'">'.$loop.''.$this->num_tag_close; @@ -242,7 +242,7 @@ class CI_Pagination { 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; } } diff --git a/system/libraries/Parser.php b/system/libraries/Parser.php index 41a438bac..b969ce4d4 100644 --- a/system/libraries/Parser.php +++ b/system/libraries/Parser.php @@ -94,7 +94,7 @@ class CI_Parser { { if (is_array($val)) { - $template = $this->_parse_pair($key, $val, $template); + $template = $this->_parse_pair($key, $val, $template); } else { @@ -110,9 +110,9 @@ class CI_Parser { return $template; } - + // -------------------------------------------------------------------- - + /** * Set the left/right variable delimiters * @@ -126,9 +126,9 @@ class CI_Parser { $this->l_delim = $l; $this->r_delim = $r; } - + // -------------------------------------------------------------------- - + /** * Parse a single key/value * @@ -142,9 +142,9 @@ class CI_Parser { { return str_replace($this->l_delim.$key.$this->r_delim, $val, $string); } - + // -------------------------------------------------------------------- - + /** * Parse a tag pair * @@ -157,7 +157,7 @@ class CI_Parser { * @return string */ function _parse_pair($variable, $data, $string) - { + { if (FALSE === ($match = $this->_match_pair($string, $variable))) { return $string; @@ -178,15 +178,15 @@ class CI_Parser { $temp = $this->_parse_pair($key, $val, $temp); } } - + $str .= $temp; } - + return str_replace($match['0'], $str, $string); } - + // -------------------------------------------------------------------- - + /** * Matches a variable pair * @@ -201,7 +201,7 @@ class CI_Parser { { return FALSE; } - + return $match; } diff --git a/system/libraries/Profiler.php b/system/libraries/Profiler.php index db179976b..796db2d6b 100644 --- a/system/libraries/Profiler.php +++ b/system/libraries/Profiler.php @@ -33,7 +33,7 @@ class CI_Profiler { var $CI; - + var $_available_sections = array( 'benchmarks', 'get', @@ -46,11 +46,11 @@ class CI_Profiler { 'config' ); - function CI_Profiler($config = array()) - { - $this->CI =& get_instance(); - $this->CI->load->language('profiler'); - + function CI_Profiler($config = array()) + { + $this->CI =& get_instance(); + $this->CI->load->language('profiler'); + // default all sections to display foreach ($this->_available_sections as $section) { @@ -59,10 +59,10 @@ class CI_Profiler { $this->_compile_{$section} = TRUE; } } - + $this->set_sections($config); - } - + } + // -------------------------------------------------------------------- /** @@ -80,13 +80,13 @@ class CI_Profiler { { if (in_array($method, $this->_available_sections)) { - $this->_compile_{$method} = ($enable !== FALSE) ? TRUE : FALSE; + $this->_compile_{$method} = ($enable !== FALSE) ? TRUE : FALSE; } } } // -------------------------------------------------------------------- - + /** * Auto Profiler * @@ -98,45 +98,45 @@ class CI_Profiler { * @access private * @return array */ - 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); - } - } - } + 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"; $output .= "\n\n\n"; - + foreach ($profile as $key => $val) { $key = ucwords(str_replace(array('_', '-'), ' ', $key)); $output .= "\n"; } - + $output .= "
    ".$key."  ".$val."
    \n"; $output .= "
    "; - - return $output; - } - + + return $output; + } + // -------------------------------------------------------------------- /** @@ -144,7 +144,7 @@ class CI_Profiler { * * @access private * @return string - */ + */ function _compile_queries() { $dbs = array(); @@ -157,22 +157,22 @@ class CI_Profiler { $dbs[] = $CI_object; } } - + if (count($dbs) == 0) { $output = "\n\n"; $output .= '
    '; $output .= "\n"; $output .= '  '.$this->CI->lang->line('profiler_queries').'  '; - $output .= "\n"; + $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'); @@ -180,45 +180,45 @@ class CI_Profiler { $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"; - + foreach ($dbs as $db) { $output .= '
    '; $output .= "\n"; $output .= '  '.$this->CI->lang->line('profiler_database').':  '.$db->database.'   '.$this->CI->lang->line('profiler_queries').': '.count($this->CI->db->queries).'   '; - $output .= "\n"; + $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); + $val = str_replace($bold, ''.$bold.'', $val); } - + $output .= "\n"; } } - + $output .= "
    ".$this->CI->lang->line('profiler_no_queries')."
    ".$time."  ".$val."
    \n"; $output .= "
    "; - + } - + return $output; } - + // -------------------------------------------------------------------- /** @@ -226,15 +226,15 @@ class CI_Profiler { * * @access private * @return string - */ + */ 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')."
    "; @@ -242,14 +242,14 @@ class CI_Profiler { 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)) { @@ -261,30 +261,30 @@ class CI_Profiler { } $output .= "
    \n"; } $output .= "
    "; - return $output; + return $output; } - + // -------------------------------------------------------------------- - + /** * Compile $_POST Data * * @access private * @return string - */ + */ 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')."
    "; @@ -292,14 +292,14 @@ class CI_Profiler { 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)) { @@ -311,70 +311,70 @@ class CI_Profiler { } $output .= "
    \n"; } $output .= "
    "; - return $output; + return $output; } - + // -------------------------------------------------------------------- - + /** * Show query string * * @access private * @return string - */ + */ 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 .= "
    ".$this->CI->uri->uri_string."
    "; } - + $output .= "
    "; - return $output; + return $output; } // -------------------------------------------------------------------- - + /** * Show the controller and function that were called * * @access private * @return string - */ + */ 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 .= "
    ".$this->CI->router->fetch_class()."/".$this->CI->router->fetch_method()."
    "; + + $output .= "
    "; - return $output; + return $output; } // -------------------------------------------------------------------- - + /** * Compile memory usage * @@ -390,23 +390,23 @@ class CI_Profiler { $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_usage')."
    "; + $output .= "
    ".$this->CI->lang->line('profiler_no_memory_usage')."
    "; } - + $output .= ""; return $output; } // -------------------------------------------------------------------- - + /** * Compile header information * @@ -463,7 +463,7 @@ class CI_Profiler { { $val = print_r($val, TRUE); } - + $output .= "".$config."  ".htmlspecialchars($val)."\n"; } @@ -474,18 +474,18 @@ class CI_Profiler { } // -------------------------------------------------------------------- - + /** * Run the Profiler * * @access private * @return string - */ + */ function run() { $output = "
    "; $fields_displayed = 0; - + foreach ($this->_available_sections as $section) { if ($this->_compile_{$section} !== FALSE) @@ -500,7 +500,7 @@ class CI_Profiler { { $output .= '

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

    '; } - + $output .= '
    '; return $output; diff --git a/system/libraries/Security.php b/system/libraries/Security.php index 9a1590b5c..2db8ee9b3 100644 --- a/system/libraries/Security.php +++ b/system/libraries/Security.php @@ -25,12 +25,12 @@ * @link http://codeigniter.com/user_guide/libraries/sessions.html */ class CI_Security { - var $xss_hash = ''; - var $csrf_hash = ''; + var $xss_hash = ''; + var $csrf_hash = ''; var $csrf_expire = 7200; // Two hours (in seconds) var $csrf_token_name = 'ci_csrf_token'; var $csrf_cookie_name = 'ci_csrf_token'; - + /* never allowed, string replacement */ var $never_allowed_str = array( 'document.cookie' => '[removed]', @@ -63,7 +63,7 @@ class CI_Security { } // -------------------------------------------------------------------- - + /** * Verify Cross Site Request Forgery Protection * @@ -92,7 +92,7 @@ class CI_Security { // 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(); @@ -100,9 +100,9 @@ class CI_Security { log_message('debug', "CSRF token verified "); } - + // -------------------------------------------------------------------- - + /** * Set Cross Site Request Forgery Protection Cookie * @@ -114,12 +114,12 @@ class CI_Security { $expire = time() + $this->csrf_expire; setcookie($this->csrf_cookie_name, $this->csrf_hash, $expire, config_item('cookie_path'), config_item('cookie_domain'), 0); - - log_message('debug', "CRSF cookie Set"); + + log_message('debug', "CRSF cookie Set"); } - + // -------------------------------------------------------------------- - + /** * Set Cross Site Request Forgery Protection Cookie * @@ -146,7 +146,7 @@ class CI_Security { } // -------------------------------------------------------------------- - + /** * Show CSRF Error * @@ -159,7 +159,7 @@ class CI_Security { } // -------------------------------------------------------------------- - + /** * XSS Clean * @@ -198,7 +198,7 @@ class CI_Security { { $str[$key] = $this->xss_clean($str[$key]); } - + return $str; } @@ -210,9 +210,9 @@ class CI_Security { /* * Protect GET variables in URLs */ - + // 901119URL5918AMP18930PROTECT8198 - + $str = preg_replace('|\&([a-z\_0-9\-]+)\=([a-z\_0-9\-]+)|i', $this->xss_hash()."\\1=\\2", $str); /* @@ -225,7 +225,7 @@ class CI_Security { $str = preg_replace('#(&\#?[0-9a-z]{2,})([\x00-\x20])*;?#i', "\\1;\\2", $str); /* - * Validate UTF16 two byte encoding (x00) + * Validate UTF16 two byte encoding (x00) * * Just as above, adds a semicolon if missing. * @@ -248,9 +248,9 @@ class CI_Security { * */ $str = rawurldecode($str); - + /* - * Convert character entities to ASCII + * Convert character entities to ASCII * * This permits our tests below to work reliably. * We only convert entities that are within tags since @@ -259,14 +259,14 @@ class CI_Security { */ $str = preg_replace_callback("/[a-z]+=([\'\"]).*?\\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 * @@ -276,29 +276,29 @@ class CI_Security { * so we use str_replace. * */ - + if (strpos($str, "\t") !== FALSE) { $str = str_replace("\t", ' ', $str); } - + /* * Capture converted string for later comparison */ $converted_string = $str; - + /* * Not Allowed Under Any Conditions */ - + foreach ($this->never_allowed_str as $key => $val) { - $str = str_replace($key, $val, $str); + $str = str_replace($key, $val, $str); } - + foreach ($this->never_allowed_regex as $key => $val) { - $str = preg_replace("#".$key."#i", $val, $str); + $str = preg_replace("#".$key."#i", $val, $str); } /* @@ -321,7 +321,7 @@ class CI_Security { { $str = str_replace(array(''), array('<?', '?>'), $str); } - + /* * Compact any exploded words * @@ -333,7 +333,7 @@ class CI_Security { foreach ($words as $word) { $temp = ''; - + for ($i = 0, $wordlen = strlen($word); $i < $wordlen; $i++) { $temp .= substr($word, $i, 1)."\s*"; @@ -343,7 +343,7 @@ class CI_Security { // That way valid stuff like "dealer to" does not become "dealerto" $str = preg_replace_callback('#('.substr($temp, 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 for PHP5, but it is dog slow compared @@ -352,17 +352,17 @@ class CI_Security { 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/i", $str) OR preg_match("/xss/i", $str)) { $str = preg_replace("#<(/*)(script|xss)(.*?)\>#si", '[removed]', $str); @@ -385,14 +385,14 @@ class CI_Security { if ($is_image === TRUE) { /* - * Adobe Photoshop puts XML metadata into JFIF images, including namespacing, + * Adobe Photoshop puts XML metadata into JFIF images, including namespacing, * so we have to allow this for images. -Paul */ unset($event_handlers[array_search('xmlns', $event_handlers)]); } $str = preg_replace("#<([^><]+?)(".implode('|', $event_handlers).")(\s*=\s*[^><]*)([><]*)#i", "<\\1\\4", $str); - + /* * Sanitize naughty HTML elements * @@ -420,7 +420,7 @@ class CI_Security { * */ $str = preg_replace('#(alert|cmd|passthru|eval|exec|expression|system|fopen|fsockopen|file|file_get_contents|readfile|unlink)(\s*)\((.*?)\)#si', "\\1\\2(\\3)", $str); - + /* * Final clean up * @@ -430,9 +430,9 @@ class CI_Security { */ foreach ($this->never_allowed_str as $key => $val) { - $str = str_replace($key, $val, $str); + $str = str_replace($key, $val, $str); } - + foreach ($this->never_allowed_regex as $key => $val) { $str = preg_replace("#".$key."#i", $val, $str); @@ -457,13 +457,13 @@ class CI_Security { return FALSE; } } - + log_message('debug', "XSS Filtering completed"); return $str; } // -------------------------------------------------------------------- - + /** * Random Hash for protecting URLs * @@ -471,22 +471,22 @@ class CI_Security { * @return string */ function xss_hash() - { + { if ($this->xss_hash == '') { if (phpversion() >= 4.2) mt_srand(); else mt_srand(hexdec(substr(md5(microtime()), -8)) & 0x7fffffff); - + $this->xss_hash = md5(time() + mt_rand(0, 1999999999)); } - + return $this->xss_hash; } // -------------------------------------------------------------------- - + /** * Compact Exploded Words * @@ -501,9 +501,9 @@ class CI_Security { { return preg_replace('/\s+/s', '', $matches[1]).$matches[2]; } - + // -------------------------------------------------------------------- - + /** * Sanitize Naughty HTML * @@ -517,15 +517,15 @@ class CI_Security { { // encode opening brace $str = '<'.$matches[1].$matches[2].$matches[3]; - + // encode captured opening or closing brace to prevent recursive vectors $str .= str_replace(array('>', '<'), array('>', '<'), $matches[4]); - + return $str; } - + // -------------------------------------------------------------------- - + /** * JS Link Removal * @@ -543,7 +543,7 @@ class CI_Security { $attributes = $this->_filter_attributes(str_replace(array('<', '>'), '', $match[1])); return str_replace($match[1], preg_replace("#href=.*?(alert\(|alert&\#40;|javascript\:|charset\=|window\.|document\.|\.cookie|', '<', '\\'), array('>', '<', '\\\\'), $match[0]); } - + // -------------------------------------------------------------------- /** @@ -644,35 +644,35 @@ class CI_Security { function entity_decode($str, $charset='UTF-8') { if (stristr($str, '&') === FALSE) return $str; - + // 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. - + if (function_exists('html_entity_decode') && (strtolower($charset) != 'utf-8' OR is_php('5.0.0'))) { $str = html_entity_decode($str, ENT_COMPAT, $charset); $str = preg_replace('~&#x(0*[0-9a-f]{2,5})~ei', 'chr(hexdec("\\1"))', $str); return preg_replace('~&#([0-9]{2,4})~e', 'chr(\\1)', $str); } - + // Numeric Entities $str = preg_replace('~&#x(0*[0-9a-f]{2,5});{0,1}~ei', 'chr(hexdec("\\1"))', $str); $str = preg_replace('~&#([0-9]{2,4});{0,1}~e', 'chr(\\1)', $str); - + // Literal Entities - Slightly slow so we do another check if (stristr($str, '&') === FALSE) { $str = strtr($str, array_flip(get_html_translation_table(HTML_ENTITIES))); } - + return $str; } - + // -------------------------------------------------------------------- - + /** * Filename Security * @@ -705,16 +705,16 @@ class CI_Security { "%20", "%22", "%3c", // < - "%253c", // < - "%3e", // > - "%0e", // > - "%28", // ( - "%29", // ) - "%2528", // ( - "%26", // & - "%24", // $ - "%3f", // ? - "%3b", // ; + "%253c", // < + "%3e", // > + "%0e", // > + "%28", // ( + "%29", // ) + "%2528", // ( + "%26", // & + "%24", // $ + "%3f", // ? + "%3b", // ; "%3d" // = ); diff --git a/system/libraries/Session.php b/system/libraries/Session.php index fc3ee0542..342c301e3 100644 --- a/system/libraries/Session.php +++ b/system/libraries/Session.php @@ -39,7 +39,7 @@ class CI_Session { var $cookie_domain = ''; var $sess_time_to_update = 300; var $encryption_key = ''; - var $flashdata_key = 'flash'; + var $flashdata_key = 'flash'; var $time_reference = 'time'; var $gc_probability = 5; var $userdata = array(); @@ -96,7 +96,7 @@ class CI_Session { { $this->sess_expiration = (60*60*24*365*2); } - + // Set the cookie name $this->sess_cookie_name = $this->cookie_prefix.$this->sess_cookie_name; @@ -112,10 +112,10 @@ class CI_Session { } // Delete 'old' flashdata (from last request) - $this->_flashdata_sweep(); + $this->_flashdata_sweep(); // Mark all new flashdata as old (data will be deleted before next request) - $this->_flashdata_mark(); + $this->_flashdata_mark(); // Delete expired sessions if necessary $this->_sess_gc(); @@ -313,9 +313,9 @@ class CI_Session { $sessid .= $this->CI->input->ip_address(); $this->userdata = array( - 'session_id' => md5(uniqid($sessid, TRUE)), - 'ip_address' => $this->CI->input->ip_address(), - 'user_agent' => substr($this->CI->input->user_agent(), 0, 50), + 'session_id' => md5(uniqid($sessid, TRUE)), + 'ip_address' => $this->CI->input->ip_address(), + 'user_agent' => substr($this->CI->input->user_agent(), 0, 50), 'last_activity' => $this->now ); @@ -656,9 +656,9 @@ class CI_Session { // if encryption is not used, we provide an md5 hash to prevent userside tampering $cookie_data = $cookie_data.md5($cookie_data.$this->encryption_key); } - + $expire = ($this->sess_expire_on_close === TRUE) ? 0 : $this->sess_expiration + time(); - + // Set the cookie setcookie( $this->sess_cookie_name, @@ -690,7 +690,7 @@ class CI_Session { { if (is_string($val)) { - $data[$key] = str_replace('\\', '{{slash}}', $val); + $data[$key] = str_replace('\\', '{{slash}}', $val); } } } @@ -698,7 +698,7 @@ class CI_Session { { if (is_string($data)) { - $data = str_replace('\\', '{{slash}}', $data); + $data = str_replace('\\', '{{slash}}', $data); } } @@ -727,7 +727,7 @@ class CI_Session { { if (is_string($val)) { - $data[$key] = str_replace('{{slash}}', '\\', $val); + $data[$key] = str_replace('{{slash}}', '\\', $val); } } diff --git a/system/libraries/Sha1.php b/system/libraries/Sha1.php index f9611a8a5..ff7e72033 100644 --- a/system/libraries/Sha1.php +++ b/system/libraries/Sha1.php @@ -55,7 +55,7 @@ class CI_SHA { * @access public * @param string * @return string - */ + */ function generate($str) { $n = ((strlen($str) + 8) >> 6) + 1; @@ -117,7 +117,7 @@ class CI_SHA { return $this->_hex($a).$this->_hex($b).$this->_hex($c).$this->_hex($d).$this->_hex($e); } - + // -------------------------------------------------------------------- /** @@ -126,7 +126,7 @@ class CI_SHA { * @access private * @param string * @return string - */ + */ function _hex($str) { $str = dechex($str); @@ -138,7 +138,7 @@ class CI_SHA { return $str; } - + // -------------------------------------------------------------------- /** @@ -146,7 +146,7 @@ class CI_SHA { * * @access private * @return string - */ + */ function _ft($t, $b, $c, $d) { if ($t < 20) @@ -166,7 +166,7 @@ class CI_SHA { * * @access private * @return string - */ + */ function _kt($t) { if ($t < 20) @@ -186,7 +186,7 @@ class CI_SHA { return -899497514; } } - + // -------------------------------------------------------------------- /** @@ -194,7 +194,7 @@ class CI_SHA { * * @access private * @return string - */ + */ function _safe_add($x, $y) { $lsw = ($x & 0xFFFF) + ($y & 0xFFFF); @@ -202,7 +202,7 @@ class CI_SHA { return ($msw << 16) | ($lsw & 0xFFFF); } - + // -------------------------------------------------------------------- /** @@ -210,7 +210,7 @@ class CI_SHA { * * @access private * @return integer - */ + */ function _rol($num, $cnt) { return ($num << $cnt) | $this->_zero_fill($num, 32 - $cnt); @@ -223,7 +223,7 @@ class CI_SHA { * * @access private * @return string - */ + */ function _zero_fill($a, $b) { $bin = decbin($a); diff --git a/system/libraries/Table.php b/system/libraries/Table.php index 1f920ea9e..2fc1b634d 100644 --- a/system/libraries/Table.php +++ b/system/libraries/Table.php @@ -30,13 +30,13 @@ class CI_Table { var $rows = array(); var $heading = array(); - var $auto_heading = TRUE; - var $caption = NULL; - var $template = NULL; + var $auto_heading = TRUE; + var $caption = NULL; + var $template = NULL; var $newline = "\n"; var $empty_cells = ""; var $function = FALSE; - + function CI_Table() { log_message('debug', "Table Class Initialized"); @@ -57,7 +57,7 @@ class CI_Table { { return FALSE; } - + $this->template = $template; } @@ -97,21 +97,21 @@ class CI_Table { { return FALSE; } - - // Turn off the auto-heading feature since it's doubtful we + + // 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); - + { + $temp = array_splice($array, 0, $col_limit); + if (count($temp) < $col_limit) { for ($i = count($temp); $i < $col_limit; $i++) @@ -119,10 +119,10 @@ class CI_Table { $temp[] = ' '; } } - + $new[] = $temp; } - + return $new; } @@ -141,7 +141,7 @@ class CI_Table { { $this->empty_cells = $value; } - + // -------------------------------------------------------------------- /** @@ -160,7 +160,7 @@ class CI_Table { } // -------------------------------------------------------------------- - + /** * Prep Args * @@ -188,9 +188,9 @@ class CI_Table { } else { - $args[$key] = array('data' => $val); + $args[$key] = array('data' => $val); } - } + } } } else @@ -203,12 +203,12 @@ class CI_Table { } } } - + return $args; } // -------------------------------------------------------------------- - + /** * Add a table caption * @@ -219,7 +219,7 @@ class CI_Table { function set_caption($caption) { $this->caption = $caption; - } + } // -------------------------------------------------------------------- @@ -246,23 +246,23 @@ class CI_Table { $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; + $out .= $this->newline; // Add any caption here if ($this->caption) @@ -283,16 +283,16 @@ class CI_Table { 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']; } @@ -302,13 +302,13 @@ class CI_Table { $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) { @@ -316,25 +316,25 @@ class CI_Table { { break; } - + // We use modulus to alternate the row colors $name = (fmod($i++, 2)) ? '' : 'alt_'; - + $out .= $this->template['row_'.$name.'start']; - $out .= $this->newline; - + $out .= $this->newline; + foreach($row as $cell) { $temp = $this->template['cell_'.$name.'start']; - + foreach ($cell as $key => $val) { if ($key != 'data') { $temp = str_replace('template['cell_'.$name.'end']; } - + $out .= $this->template['row_'.$name.'end']; - $out .= $this->newline; + $out .= $this->newline; } - + $out .= $this->template['tbody_close']; $out .= $this->newline; } $out .= $this->template['table_close']; - + return $out; } - + // -------------------------------------------------------------------- /** @@ -382,9 +382,9 @@ class CI_Table { { $this->rows = array(); $this->heading = array(); - $this->auto_heading = TRUE; + $this->auto_heading = TRUE; } - + // -------------------------------------------------------------------- /** @@ -400,7 +400,7 @@ class CI_Table { { return FALSE; } - + // First generate the headings from the table column names if (count($this->heading) == 0) { @@ -408,12 +408,12 @@ class CI_Table { { 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) @@ -438,10 +438,10 @@ class CI_Table { { 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) { @@ -451,7 +451,7 @@ class CI_Table { { $this->rows[] = $this->_prep_args($row); } - + $i++; } } @@ -464,14 +464,14 @@ class CI_Table { * @access private * @return void */ - function _compile_template() - { - if ($this->template == NULL) - { - $this->template = $this->_default_template(); - return; - } - + 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) { @@ -479,9 +479,9 @@ class CI_Table { { $this->template[$val] = $this->temp[$val]; } - } - } - + } + } + // -------------------------------------------------------------------- /** @@ -493,33 +493,33 @@ class CI_Table { function _default_template() { return array ( - 'table_open' => '', - + 'table_open' => '
    ', + 'thead_open' => '', 'thead_close' => '', - - 'heading_row_start' => '', - 'heading_row_end' => '', + + 'heading_row_start' => '', + 'heading_row_end' => '', 'heading_cell_start' => '', 'tbody_open' => '', 'tbody_close' => '', - - 'row_start' => '', - 'row_end' => '', + + 'row_start' => '', + 'row_end' => '', 'cell_start' => '', - 'row_alt_start' => '', - 'row_alt_end' => '', + 'row_alt_start' => '', + 'row_alt_end' => '', 'cell_alt_start' => '', - 'table_close' => '
    ', 'heading_cell_end' => '
    ', 'cell_end' => '
    ', 'cell_alt_end' => '
    ' - ); + 'table_close' => '' + ); } - + } diff --git a/system/libraries/Trackback.php b/system/libraries/Trackback.php index a27914487..a8be8a877 100644 --- a/system/libraries/Trackback.php +++ b/system/libraries/Trackback.php @@ -27,7 +27,7 @@ * @link http://codeigniter.com/user_guide/libraries/trackback.html */ class CI_Trackback { - + var $time_format = 'local'; var $charset = 'UTF-8'; var $data = array('url' => '', 'title' => '', 'excerpt' => '', 'blog_name' => '', 'charset' => ''); @@ -44,24 +44,24 @@ class CI_Trackback { { 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) { @@ -70,14 +70,14 @@ class CI_Trackback { $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])))); + 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; @@ -103,9 +103,9 @@ class CI_Trackback { // 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) @@ -116,14 +116,14 @@ class CI_Trackback { { $return = FALSE; } - } + } } return $return; } - + // -------------------------------------------------------------------- - + /** * Receive Trackback Data * @@ -134,9 +134,9 @@ class CI_Trackback { * * @access public * @return bool - */ + */ function receive() - { + { foreach (array('url', 'title', 'blog_name', 'excerpt') as $val) { if ( ! isset($_POST[$val]) OR $_POST[$val] == '') @@ -144,29 +144,29 @@ class CI_Trackback { $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 * @@ -177,15 +177,15 @@ class CI_Trackback { * @access public * @param string * @return void - */ + */ function send_error($message = 'Incomplete Information') { echo "\n\n1\n".$message."\n"; exit; } - + // -------------------------------------------------------------------- - + /** * Send Trackback Success Message * @@ -194,29 +194,29 @@ class CI_Trackback { * * @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 * @@ -227,11 +227,11 @@ class CI_Trackback { * @param string * @param string * @return bool - */ + */ function process($url, $data) { $target = parse_url($url); - + // Open the socket if ( ! $fp = @fsockopen($target['host'], 80)) { @@ -241,7 +241,7 @@ class CI_Trackback { // 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 @@ -260,32 +260,32 @@ class CI_Trackback { // 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 * @@ -296,34 +296,34 @@ class CI_Trackback { * @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 * @@ -332,7 +332,7 @@ class CI_Trackback { * @access public * @param string * @return string - */ + */ function validate_url($url) { $url = trim($url); @@ -342,46 +342,46 @@ class CI_Trackback { $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; @@ -389,11 +389,11 @@ class CI_Trackback { else { return $tb_id; - } + } } - + // -------------------------------------------------------------------- - + /** * Convert Reserved XML characters to Entities * @@ -404,22 +404,22 @@ class CI_Trackback { 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); - + array("&", "<", ">", """, "'", "-"), + $str); + $str = preg_replace("/$temp(\d+);/","&#\\1;",$str); $str = preg_replace("/$temp(\w+);/","&\\1;", $str); - + return $str; - } - + } + // -------------------------------------------------------------------- - + /** * Character limiter * @@ -437,27 +437,27 @@ class CI_Trackback { { 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.' '; + $out .= $val.' '; if (strlen($out) >= $n) { return trim($out).$end_char; - } + } } } - + // -------------------------------------------------------------------- - + /** * High ASCII to Entities * @@ -470,58 +470,58 @@ class CI_Trackback { */ 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; + $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 * @@ -529,15 +529,15 @@ class CI_Trackback { * @param string * @param string * @return string - */ + */ function display_errors($open = '

    ', $close = '

    ') - { + { $str = ''; foreach ($this->error_msg as $val) { $str .= $open.$val.$close; } - + return $str; } diff --git a/system/libraries/Typography.php b/system/libraries/Typography.php index f058769ec..d8b295e7b 100644 --- a/system/libraries/Typography.php +++ b/system/libraries/Typography.php @@ -28,22 +28,22 @@ class CI_Typography { // Block level elements that should not be wrapped inside

    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; - + /** * Nothing to do here... * @@ -56,11 +56,11 @@ class CI_Typography { * 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 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 @@ -78,15 +78,15 @@ class CI_Typography { // Standardize Newlines to make matching easier if (strpos($str, "\r") !== FALSE) { - $str = str_replace(array("\r\n", "\r"), "\n", $str); + $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(); @@ -101,50 +101,50 @@ class CI_Typography { } } } - + // match and yank

     tags if they exist.  It's cheaper to do this separately since most content will
     		// not contain 
     tags, and it keeps the PCRE patterns below simpler and faster
     		if (strpos($str, '.*?
    #si", array($this, '_protect_characters'), $str); } - + // Convert quotes within tags to temporary markers. $str = preg_replace_callback("#<.+?>#si", array($this, '_protect_characters'), $str); // Do the same with braces if necessary if ($this->protect_braced_quotes === TRUE) { - $str = preg_replace_callback("#\{.+?\}#si", array($this, '_protect_characters'), $str); + $str = preg_replace_callback("#\{.+?\}#si", array($this, '_protect_characters'), $str); } - - // Convert "ignore" tags to temporary marker. The parser splits out the string at every tag - // it encounters. Certain inline tags, like image tags, links, span tags, etc. will be + + // Convert "ignore" tags to temporary marker. The parser splits out the string at every tag + // it encounters. Certain inline tags, like image tags, links, span tags, etc. will be // adversely affected if they are split out so we'll convert the opening bracket < temporarily to: {@TAG} $str = preg_replace("#<(/*)(".$this->inline_elements.")([ >])#i", "{@TAG}\\1\\2\\3", $str); // Split the string at every tag. This expression creates an array with this prototype: - // - // [array] - // { - // [0] = - // [1] = Content... - // [2] = - // Etc... - // } + // + // [array] + // { + // [0] = + // [1] = Content... + // [2] = + // Etc... + // } $chunks = preg_split('/(<(?:[^<>]+(?:"[^"]*"|\'[^\']*\')?)+>)/', $str, -1, PREG_SPLIT_DELIM_CAPTURE|PREG_SPLIT_NO_EMPTY); - - // Build our finalized string. We cycle through the array, skipping tags, and processing the contained text + + // Build our finalized string. We cycle through the array, skipping tags, and processing the contained text $str = ''; $process = TRUE; $paragraph = FALSE; $current_chunk = 0; $total_chunks = count($chunks); - + foreach ($chunks as $chunk) - { + { $current_chunk++; - + // Are we dealing with a tag? If so, we'll skip the processing for this cycle. // Well also set the "process" flag which allows us to skip
     tags and a few other things.
     			if (preg_match("#<(/*)(".$this->block_elements.").*?>#", $chunk, $match))
    @@ -153,7 +153,7 @@ class CI_Typography {
     				{
     					$process =  ($match[1] == '/') ? TRUE : FALSE;
     				}
    -				
    +
     				if ($match[1] == '')
     				{
     					$this->last_block_element = $match[2];
    @@ -162,32 +162,32 @@ class CI_Typography {
     				$str .= $chunk;
     				continue;
     			}
    -			
    +
     			if ($process == FALSE)
     			{
     				$str .= $chunk;
     				continue;
     			}
    -			
    +
     			//  Force a newline to make sure end tags get processed by _format_newlines()
     			if ($current_chunk == $total_chunks)
     			{
    -				$chunk .= "\n";  
    +				$chunk .= "\n";
     			}
    -			
    +
     			//  Convert Newlines into 

    and
    tags $str .= $this->_format_newlines($chunk); } - + // No opening block level tag? Add it if needed. if ( ! preg_match("/^\s*<(?:".$this->block_elements.")/i", $str)) { $str = preg_replace("/^(.*?)<(".$this->block_elements.")/i", '

    $1

    <$2', $str); } - + // Convert quotes, elipsis, em-dashes, non-breaking spaces, and ampersands $str = $this->format_characters($str); - + // restore HTML comments for ($i = 0, $total = count($html_comments); $i < $total; $i++) { @@ -196,18 +196,18 @@ class CI_Typography { // if '

    {@HC1}' then replace

    {@HC1}

    with the comment, else replace only {@HC1} with the comment $str = preg_replace('#(?(?=

    \{@HC'.$i.'\})

    \{@HC'.$i.'\}(\s*

    )|\{@HC'.$i.'\})#s', $html_comments[$i], $str); } - + // Final clean up $table = array( - + // If the user submitted their own paragraph tags within the text // we will retain them instead of using our tags. '/(*?]>)

    /' => '$1', // )+#' => '

    ', '/(

    \W*

    )+/' => '

    ', - + // Clean up stray paragraph tags that appear before block level elements '#

    <('.$this->block_elements.')#' => '<$1', @@ -223,15 +223,15 @@ class CI_Typography { // An unintended consequence of the _format_newlines function is that // some of the newlines get truncated, resulting in

    tags - // starting immediately after tags on the same line. + // starting immediately after tags on the same line. // This forces a newline after such occurrences, which looks much nicer. "/>

    \n/" => ">\n

    ", - + // Similarly, there might be cases where a closing will follow // a closing

    tag, so we'll correct it by adding a newline in between "#

    "

    \n

    #'] = '

     

    '; } - + return preg_replace(array_keys($table), $table, $str); } - + // -------------------------------------------------------------------- - + /** * Format Characters * @@ -264,10 +264,10 @@ class CI_Typography { function format_characters($str) { static $table; - + if ( ! isset($table)) { - $table = array( + $table = array( // nested smart quotes, opening and closing // note that rules for grammar (English) allow only for two levels deep // and that single quotes are _supposed_ to always be on the outside @@ -313,7 +313,7 @@ class CI_Typography { return preg_replace(array_keys($table), $table, $str); } - + // -------------------------------------------------------------------- /** @@ -324,25 +324,25 @@ class CI_Typography { * @access public * @param string * @return string - */ + */ function _format_newlines($str) { if ($str == '') { return $str; } - + if (strpos($str, "\n") === FALSE && ! in_array($this->last_block_element, $this->inner_block_required)) { return $str; } - + // Convert two consecutive newlines to paragraphs $str = str_replace("\n\n", "

    \n\n

    ", $str); - + // Convert single spaces to
    tags $str = preg_replace("/([^\n])(\n)([^\n])/", "\\1
    \\2\\3", $str); - + // Wrap the whole enchilada in enclosing paragraphs if ($str != "\n") { @@ -355,19 +355,19 @@ class CI_Typography { // Remove empty paragraphs if they are on the first line, as this // is a potential unintended consequence of the previous code $str = preg_replace("/

    <\/p>(.*)/", "\\1", $str, 1); - + return $str; } - + // ------------------------------------------------------------------------ - + /** * Protect Characters * * Protects special characters from being formatted later * We don't want quotes converted within tags so we'll temporarily convert them to {@DQ} and {@SQ} - * and we don't want double dashes converted to emdash entities, so they are marked with {@DD} - * likewise double spaces are converted to {@NBS} to prevent entity conversion + * and we don't want double dashes converted to emdash entities, so they are marked with {@DD} + * likewise double spaces are converted to {@NBS} to prevent entity conversion * * @access public * @param array @@ -379,19 +379,19 @@ class CI_Typography { } // -------------------------------------------------------------------- - + /** * Convert newlines to HTML line breaks except within PRE tags * * @access public * @param string * @return string - */ + */ function nl2br_except_pre($str) { $ex = explode("pre>",$str); $ct = count($ex); - + $newstr = ""; for ($i = 0; $i < $ct; $i++) { @@ -403,14 +403,14 @@ class CI_Typography { { $newstr .= $ex[$i]; } - + if ($ct - 1 != $i) $newstr .= "pre>"; } - + return $newstr; } - + } // END Typography Class diff --git a/system/libraries/Unit_test.php b/system/libraries/Unit_test.php index c47143637..9a90cb47c 100644 --- a/system/libraries/Unit_test.php +++ b/system/libraries/Unit_test.php @@ -29,9 +29,9 @@ class CI_Unit_test { var $active = TRUE; - var $results = array(); + var $results = array(); var $strict = FALSE; - var $_template = NULL; + var $_template = NULL; var $_template_rows = NULL; var $_test_items_visible = array(); @@ -82,32 +82,32 @@ class CI_Unit_test { * @param mixed * @param string * @return string - */ + */ function run($test, $expected = TRUE, $test_name = 'undefined', $notes = '') { if ($this->active == FALSE) { return FALSE; } - + if (in_array($expected, array('is_object', 'is_string', 'is_bool', 'is_true', 'is_false', 'is_int', 'is_numeric', 'is_float', 'is_double', 'is_array', 'is_null'), TRUE)) { $expected = str_replace('is_float', 'is_double', $expected); - $result = ($expected($test)) ? TRUE : FALSE; + $result = ($expected($test)) ? TRUE : FALSE; $extype = str_replace(array('true', 'false'), 'bool', str_replace('is_', '', $expected)); } else { if ($this->strict == TRUE) - $result = ($test === $expected) ? TRUE : FALSE; + $result = ($test === $expected) ? TRUE : FALSE; else - $result = ($test == $expected) ? TRUE : FALSE; - + $result = ($test == $expected) ? TRUE : FALSE; + $extype = gettype($expected); } - + $back = $this->_backtrace(); - + $report[] = array ( 'test_name' => $test_name, 'test_datatype' => gettype($test), @@ -124,7 +124,7 @@ class CI_Unit_test { } // -------------------------------------------------------------------- - + /** * Generate a report * @@ -175,9 +175,9 @@ class CI_Unit_test { return $r; } - + // -------------------------------------------------------------------- - + /** * Use strict comparison * @@ -191,9 +191,9 @@ class CI_Unit_test { { $this->strict = ($state == FALSE) ? FALSE : TRUE; } - + // -------------------------------------------------------------------- - + /** * Make Unit testing active * @@ -207,9 +207,9 @@ class CI_Unit_test { { $this->active = ($state == FALSE) ? FALSE : TRUE; } - + // -------------------------------------------------------------------- - + /** * Result Array * @@ -219,15 +219,15 @@ class CI_Unit_test { * @return array */ function result($results = array()) - { + { $CI =& get_instance(); $CI->load->language('unit_test'); - + if (count($results) == 0) { $results = $this->results; } - + $retval = array(); foreach ($results as $result) { @@ -246,8 +246,8 @@ class CI_Unit_test { if (FALSE !== ($line = $CI->lang->line(strtolower('ut_'.$v)))) { $v = $line; - } - $temp[$CI->lang->line('ut_'.$k)] = $v; + } + $temp[$CI->lang->line('ut_'.$k)] = $v; } } else @@ -255,19 +255,19 @@ class CI_Unit_test { if (FALSE !== ($line = $CI->lang->line(strtolower('ut_'.$val)))) { $val = $line; - } + } $temp[$CI->lang->line('ut_'.$key)] = $val; } } - + $retval[] = $temp; } - + return $retval; } - + // -------------------------------------------------------------------- - + /** * Set the template * @@ -276,14 +276,14 @@ class CI_Unit_test { * @access public * @param string * @return void - */ + */ function set_template($template) { $this->_template = $template; } - + // -------------------------------------------------------------------- - + /** * Generate a backtrace * @@ -297,17 +297,17 @@ class CI_Unit_test { if (function_exists('debug_backtrace')) { $back = debug_backtrace(); - + $file = ( ! isset($back['1']['file'])) ? '' : $back['1']['file']; $line = ( ! isset($back['1']['line'])) ? '' : $back['1']['line']; - + return array('file' => $file, 'line' => $line); } return array('file' => 'Unknown', 'line' => 'Unknown'); } // -------------------------------------------------------------------- - + /** * Get Default Template * @@ -315,17 +315,17 @@ class CI_Unit_test { * @return string */ function _default_template() - { + { $this->_template = "\n".''; $this->_template .= '{rows}'; $this->_template .= "\n".'
    '; - + $this->_template_rows = "\n\t".''; $this->_template_rows .= "\n\t\t".'{item}'; $this->_template_rows .= "\n\t\t".'{result}'; - $this->_template_rows .= "\n\t".''; + $this->_template_rows .= "\n\t".''; } - + // -------------------------------------------------------------------- /** @@ -336,29 +336,29 @@ class CI_Unit_test { * @access private * @return void */ - function _parse_template() - { - if ( ! is_null($this->_template_rows)) - { - return; - } - - if (is_null($this->_template)) - { - $this->_default_template(); - return; - } - + function _parse_template() + { + if ( ! is_null($this->_template_rows)) + { + return; + } + + if (is_null($this->_template)) + { + $this->_default_template(); + return; + } + if ( ! preg_match("/\{rows\}(.*?)\{\/rows\}/si", $this->_template, $match)) { - $this->_default_template(); - return; + $this->_default_template(); + return; } $this->_template_rows = $match['1']; - $this->_template = str_replace($match['0'], '{rows}', $this->_template); - } - + $this->_template = str_replace($match['0'], '{rows}', $this->_template); + } + } // END Unit_test Class diff --git a/system/libraries/Upload.php b/system/libraries/Upload.php index c18c178df..c83d0aeaa 100644 --- a/system/libraries/Upload.php +++ b/system/libraries/Upload.php @@ -25,7 +25,7 @@ * @link http://codeigniter.com/user_guide/libraries/file_uploading.html */ class CI_Upload { - + var $max_size = 0; var $max_width = 0; var $max_height = 0; @@ -51,9 +51,9 @@ class CI_Upload { var $xss_clean = FALSE; var $temp_prefix = "temp_file_"; var $client_name = ''; - + var $_file_name_override = ''; //@PHP4 (should be private) - + /** * Constructor * @@ -65,19 +65,19 @@ class CI_Upload { { $this->initialize($props); } - + log_message('debug', "Upload Class Initialized"); } - + // -------------------------------------------------------------------- - + /** * Initialize preferences * * @access public * @param array * @return void - */ + */ function initialize($config = array()) { @@ -107,9 +107,9 @@ class CI_Upload { 'xss_clean' => FALSE, 'temp_prefix' => "temp_file_", 'client_name' => '' - ); - - + ); + + foreach ($defaults as $key => $val) { if (isset($config[$key])) @@ -122,27 +122,27 @@ class CI_Upload { else { $this->$key = $config[$key]; - } + } } else { $this->$key = $val; } } - + // if a file_name was provided in the config, use it instead of the user input // supplied file name for all uploads until initialized again $this->_file_name_override = $this->file_name; } - + // -------------------------------------------------------------------- - + /** * Perform the file upload * * @access public * @return bool - */ + */ function do_upload($field = 'userfile') { // Is $_FILES[$field] set? If not, no reason to continue. @@ -151,7 +151,7 @@ class CI_Upload { $this->set_error('upload_no_file_selected'); return FALSE; } - + // Is the upload path valid? if ( ! $this->validate_upload_path()) { @@ -173,10 +173,10 @@ class CI_Upload { $this->set_error('upload_file_exceeds_form_limit'); break; case 3: // UPLOAD_ERR_PARTIAL - $this->set_error('upload_file_partial'); + $this->set_error('upload_file_partial'); break; case 4: // UPLOAD_ERR_NO_FILE - $this->set_error('upload_no_file_selected'); + $this->set_error('upload_no_file_selected'); break; case 6: // UPLOAD_ERR_NO_TMP_DIR $this->set_error('upload_no_temp_directory'); @@ -196,14 +196,14 @@ class CI_Upload { // Set the uploaded data as class variables - $this->file_temp = $_FILES[$field]['tmp_name']; - $this->file_size = $_FILES[$field]['size']; + $this->file_temp = $_FILES[$field]['tmp_name']; + $this->file_size = $_FILES[$field]['size']; $this->file_type = preg_replace("/^(.+?);.*$/", "\\1", $_FILES[$field]['type']); $this->file_type = strtolower(trim(stripslashes($this->file_type), '"')); $this->file_name = $this->_prep_filename($_FILES[$field]['name']); $this->file_ext = $this->get_extension($this->file_name); $this->client_name = $this->file_name; - + // Is the file type allowed to be uploaded? if ( ! $this->is_allowed_filetype()) { @@ -220,10 +220,10 @@ class CI_Upload { if ( ! $this->is_allowed_filetype(TRUE)) { $this->set_error('upload_invalid_filetype'); - return FALSE; + return FALSE; } } - + // Convert the file size to kilobytes if ($this->file_size > 0) { @@ -247,7 +247,7 @@ class CI_Upload { // Sanitize the file name for security $this->file_name = $this->clean_file_name($this->file_name); - + // Truncate the file name if it's too long if ($this->max_filename > 0) { @@ -271,7 +271,7 @@ class CI_Upload { if ($this->overwrite == FALSE) { $this->file_name = $this->set_filename($this->upload_path, $this->file_name); - + if ($this->file_name === FALSE) { return FALSE; @@ -304,8 +304,8 @@ class CI_Upload { { if ( ! @move_uploaded_file($this->file_temp, $this->upload_path.$this->file_name)) { - $this->set_error('upload_destination_error'); - return FALSE; + $this->set_error('upload_destination_error'); + return FALSE; } } @@ -319,18 +319,18 @@ class CI_Upload { return TRUE; } - + // -------------------------------------------------------------------- - + /** * Finalized Data Array - * + * * Returns an associative array containing all of the information * related to the upload, allowing the developer easy access in one array. * * @access public * @return array - */ + */ function data() { return array ( @@ -350,24 +350,24 @@ class CI_Upload { 'image_size_str' => $this->image_size_str, ); } - + // -------------------------------------------------------------------- - + /** * Set Upload Path * * @access public * @param string * @return void - */ + */ function set_upload_path($path) { // Make sure it has a trailing slash $this->upload_path = rtrim($path, '/').'/'; } - + // -------------------------------------------------------------------- - + /** * Set the file name * @@ -379,25 +379,25 @@ class CI_Upload { * @param string * @param string * @return string - */ + */ function set_filename($path, $filename) { if ($this->encrypt_name == TRUE) - { + { mt_srand(); - $filename = md5(uniqid(mt_rand())).$this->file_ext; + $filename = md5(uniqid(mt_rand())).$this->file_ext; } - + if ( ! file_exists($path.$filename)) { return $filename; } - + $filename = str_replace($this->file_ext, '', $filename); - + $new_filename = ''; for ($i = 1; $i < 100; $i++) - { + { if ( ! file_exists($path.$filename.$i.$this->file_ext)) { $new_filename = $filename.$i.$this->file_ext; @@ -415,72 +415,72 @@ class CI_Upload { return $new_filename; } } - + // -------------------------------------------------------------------- - + /** * Set Maximum File Size * * @access public * @param integer * @return void - */ + */ function set_max_filesize($n) { $this->max_size = ((int) $n < 0) ? 0: (int) $n; } - + // -------------------------------------------------------------------- - + /** * Set Maximum File Name Length * * @access public * @param integer * @return void - */ + */ function set_max_filename($n) { $this->max_filename = ((int) $n < 0) ? 0: (int) $n; } // -------------------------------------------------------------------- - + /** * Set Maximum Image Width * * @access public * @param integer * @return void - */ + */ function set_max_width($n) { $this->max_width = ((int) $n < 0) ? 0: (int) $n; } - + // -------------------------------------------------------------------- - + /** * Set Maximum Image Height * * @access public * @param integer * @return void - */ + */ function set_max_height($n) { $this->max_height = ((int) $n < 0) ? 0: (int) $n; } - + // -------------------------------------------------------------------- - + /** * Set Allowed File Types * * @access public * @param string * @return void - */ + */ function set_allowed_types($types) { if ( ! is_array($types) && $types == '*') @@ -490,9 +490,9 @@ class CI_Upload { } $this->allowed_types = explode('|', $types); } - + // -------------------------------------------------------------------- - + /** * Set Image Properties * @@ -501,7 +501,7 @@ class CI_Upload { * @access public * @param string * @return void - */ + */ function set_image_properties($path = '') { if ( ! $this->is_image()) @@ -512,7 +512,7 @@ class CI_Upload { if (function_exists('getimagesize')) { if (FALSE !== ($D = @getimagesize($path))) - { + { $types = array(1 => 'gif', 2 => 'jpeg', 3 => 'png'); $this->image_width = $D['0']; @@ -522,9 +522,9 @@ class CI_Upload { } } } - + // -------------------------------------------------------------------- - + /** * Set XSS Clean * @@ -539,15 +539,15 @@ class CI_Upload { { $this->xss_clean = ($flag == TRUE) ? TRUE : FALSE; } - + // -------------------------------------------------------------------- - + /** * Validate the image * * @access public * @return bool - */ + */ function is_image() { // IE will sometimes return odd mime-types during upload, so here we just standardize all @@ -555,12 +555,12 @@ class CI_Upload { $png_mimes = array('image/x-png'); $jpeg_mimes = array('image/jpg', 'image/jpe', 'image/jpeg', 'image/pjpeg'); - + if (in_array($this->file_type, $png_mimes)) { $this->file_type = 'image/png'; } - + if (in_array($this->file_type, $jpeg_mimes)) { $this->file_type = 'image/jpeg'; @@ -570,80 +570,80 @@ class CI_Upload { 'image/gif', 'image/jpeg', 'image/png', - ); + ); return (in_array($this->file_type, $img_mimes, TRUE)) ? TRUE : FALSE; } - + // -------------------------------------------------------------------- - + /** * Verify that the filetype is allowed * * @access public * @return bool - */ + */ function is_allowed_filetype($ignore_mime = FALSE) { if ($this->allowed_types == '*') { return TRUE; } - + if (count($this->allowed_types) == 0 OR ! is_array($this->allowed_types)) { $this->set_error('upload_no_file_types'); return FALSE; } - + $ext = strtolower(ltrim($this->file_ext, '.')); - + if ( ! in_array($ext, $this->allowed_types)) { return FALSE; } - // Images get some additional checks + // Images get some additional checks $image_types = array('gif', 'jpg', 'jpeg', 'png', 'jpe'); - + if (in_array($ext, $image_types)) { if (getimagesize($this->file_temp) === FALSE) { return FALSE; - } + } } - + if ($ignore_mime === TRUE) { return TRUE; } - + $mime = $this->mimes_types($ext); - + if (is_array($mime)) { if (in_array($this->file_type, $mime, TRUE)) { return TRUE; - } + } } elseif ($mime == $this->file_type) { return TRUE; } - + return FALSE; } - + // -------------------------------------------------------------------- - + /** * Verify that the file is within the allowed size * * @access public * @return bool - */ + */ function is_allowed_filesize() { if ($this->max_size != 0 AND $this->file_size > $this->max_size) @@ -655,15 +655,15 @@ class CI_Upload { return TRUE; } } - + // -------------------------------------------------------------------- - + /** * Verify that the image is within the allowed width/height * * @access public * @return bool - */ + */ function is_allowed_dimensions() { if ( ! $this->is_image()) @@ -690,9 +690,9 @@ class CI_Upload { return TRUE; } - + // -------------------------------------------------------------------- - + /** * Validate Upload Path * @@ -701,7 +701,7 @@ class CI_Upload { * * @access public * @return bool - */ + */ function validate_upload_path() { if ($this->upload_path == '') @@ -709,7 +709,7 @@ class CI_Upload { $this->set_error('upload_no_filepath'); return FALSE; } - + if (function_exists('realpath') AND @realpath($this->upload_path) !== FALSE) { $this->upload_path = str_replace("\\", "/", realpath($this->upload_path)); @@ -730,31 +730,31 @@ class CI_Upload { $this->upload_path = preg_replace("/(.+?)\/*$/", "\\1/", $this->upload_path); return TRUE; } - + // -------------------------------------------------------------------- - + /** * Extract the file extension * * @access public * @param string * @return string - */ + */ function get_extension($filename) { $x = explode('.', $filename); return '.'.end($x); - } - + } + // -------------------------------------------------------------------- - + /** * Clean the file name for security * * @access public * @param string * @return string - */ + */ function clean_file_name($filename) { $bad = array( @@ -773,40 +773,40 @@ class CI_Upload { "%20", "%22", "%3c", // < - "%253c", // < - "%3e", // > - "%0e", // > - "%28", // ( - "%29", // ) - "%2528", // ( - "%26", // & - "%24", // $ - "%3f", // ? - "%3b", // ; + "%253c", // < + "%3e", // > + "%0e", // > + "%28", // ( + "%29", // ) + "%2528", // ( + "%26", // & + "%24", // $ + "%3f", // ? + "%3b", // ; "%3d" // = ); - + $filename = str_replace($bad, '', $filename); return stripslashes($filename); } // -------------------------------------------------------------------- - + /** * Limit the File Name Length * * @access public * @param string * @return string - */ + */ function limit_filename_length($filename, $length) { if (strlen($filename) < $length) { return $filename; } - + $ext = ''; if (strpos($filename, '.') !== FALSE) { @@ -814,12 +814,12 @@ class CI_Upload { $ext = '.'.array_pop($parts); $filename = implode('.', $parts); } - + return substr($filename, 0, ($length - strlen($ext))).$ext; } // -------------------------------------------------------------------- - + /** * Runs the file through the XSS clean function * @@ -829,26 +829,26 @@ class CI_Upload { * * @access public * @return void - */ + */ function do_xss_clean() - { + { $file = $this->file_temp; - + if (filesize($file) == 0) { return FALSE; } - + if (function_exists('memory_get_usage') && memory_get_usage() && ini_get('memory_limit') != '') { $current = ini_get('memory_limit') * 1024 * 1024; - + // There was a bug/behavioural change in PHP 5.2, where numbers over one million get output // into scientific notation. number_format() ensures this number is an integer // http://bugs.php.net/bug.php?id=43053 - + $new_memory = number_format(ceil(filesize($file) + $current), 0, '.', ''); - + ini_set('memory_limit', $new_memory); // When an integer is used, the value is measured in bytes. - PHP.net } @@ -856,18 +856,18 @@ class CI_Upload { // IE can be fooled into mime-type detecting a malformed image as an html file, thus executing an XSS attack on anyone // using IE who looks at the image. It does this by inspecting the first 255 bytes of an image. To get around this // CI will itself look at the first 255 bytes of an image to determine its relative safety. This can save a lot of - // processor power and time if it is actually a clean image, as it will be in nearly all instances _except_ an + // processor power and time if it is actually a clean image, as it will be in nearly all instances _except_ an // attempted XSS attack. if (function_exists('getimagesize') && @getimagesize($file) !== FALSE) { - if (($file = @fopen($file, 'rb')) === FALSE) // "b" to force binary - { + if (($file = @fopen($file, 'rb')) === FALSE) // "b" to force binary + { return FALSE; // Couldn't open the file, return FALSE - } + } - $opening_bytes = fread($file, 256); - fclose($file); + $opening_bytes = fread($file, 256); + fclose($file); // These are known to throw IE into mime-type detection chaos // security)) { $CI->load->library('security'); } - + return $CI->security->xss_clean($data, TRUE); } - + // -------------------------------------------------------------------- - + /** * Set an error message * * @access public * @param string * @return void - */ + */ function set_error($msg) { - $CI =& get_instance(); + $CI =& get_instance(); $CI->lang->load('upload'); - + if (is_array($msg)) { foreach ($msg as $val) { - $msg = ($CI->lang->line($val) == FALSE) ? $val : $CI->lang->line($val); + $msg = ($CI->lang->line($val) == FALSE) ? $val : $CI->lang->line($val); $this->error_msg[] = $msg; log_message('error', $msg); - } + } } else { @@ -924,9 +924,9 @@ class CI_Upload { log_message('error', $msg); } } - + // -------------------------------------------------------------------- - + /** * Display the error message * @@ -934,7 +934,7 @@ class CI_Upload { * @param string * @param string * @return string - */ + */ function display_errors($open = '

    ', $close = '

    ') { $str = ''; @@ -942,12 +942,12 @@ class CI_Upload { { $str .= $open.$val.$close; } - + return $str; } - + // -------------------------------------------------------------------- - + /** * List of Mime Types * @@ -957,11 +957,11 @@ class CI_Upload { * @access public * @param string * @return string - */ + */ function mimes_types($mime) { global $mimes; - + if (count($this->mimes) == 0) { if (@require_once(APPPATH.'config/mimes'.EXT)) @@ -970,12 +970,12 @@ class CI_Upload { unset($mimes); } } - + return ( ! isset($this->mimes[$mime])) ? FALSE : $this->mimes[$mime]; } // -------------------------------------------------------------------- - + /** * Prep Filename * @@ -1010,7 +1010,7 @@ class CI_Upload { } $filename .= '.'.$ext; - + return $filename; } diff --git a/system/libraries/User_agent.php b/system/libraries/User_agent.php index a7c7a7609..00cbf6967 100644 --- a/system/libraries/User_agent.php +++ b/system/libraries/User_agent.php @@ -29,25 +29,25 @@ class CI_User_agent { var $agent = NULL; - + var $is_browser = FALSE; var $is_robot = FALSE; var $is_mobile = FALSE; var $languages = array(); var $charsets = array(); - + var $platforms = array(); var $browsers = array(); var $mobiles = array(); var $robots = array(); - + var $platform = ''; var $browser = ''; var $version = ''; var $mobile = ''; var $robot = ''; - + /** * Constructor * @@ -55,14 +55,14 @@ class CI_User_agent { * * @access public * @return void - */ + */ function CI_User_agent() { if (isset($_SERVER['HTTP_USER_AGENT'])) { $this->agent = trim($_SERVER['HTTP_USER_AGENT']); } - + if ( ! is_null($this->agent)) { if ($this->_load_agent_file()) @@ -70,27 +70,27 @@ class CI_User_agent { $this->_compile_data(); } } - + log_message('debug', "User Agent Class Initialized"); } - + // -------------------------------------------------------------------- - + /** * Compile the User Agent Data * * @access private * @return bool - */ + */ function _load_agent_file() { if ( ! @include(APPPATH.'config/user_agents'.EXT)) { return FALSE; } - + $return = FALSE; - + if (isset($platforms)) { $this->platforms = $platforms; @@ -111,7 +111,7 @@ class CI_User_agent { unset($mobiles); $return = TRUE; } - + if (isset($robots)) { $this->robots = $robots; @@ -121,36 +121,36 @@ class CI_User_agent { return $return; } - + // -------------------------------------------------------------------- - + /** * Compile the User Agent Data * * @access private * @return bool - */ + */ function _compile_data() { $this->_set_platform(); - + foreach (array('_set_browser', '_set_robot', '_set_mobile') as $function) { if ($this->$function() === TRUE) { break; } - } + } } - + // -------------------------------------------------------------------- - + /** * Set the Platform * * @access private * @return mixed - */ + */ function _set_platform() { if (is_array($this->platforms) AND count($this->platforms) > 0) @@ -168,19 +168,19 @@ class CI_User_agent { } // -------------------------------------------------------------------- - + /** * Set the Browser * * @access private * @return bool - */ + */ function _set_browser() { if (is_array($this->browsers) AND count($this->browsers) > 0) { foreach ($this->browsers as $key => $val) - { + { if (preg_match("|".preg_quote($key).".*?([0-9\.]+)|i", $this->agent, $match)) { $this->is_browser = TRUE; @@ -193,19 +193,19 @@ class CI_User_agent { } return FALSE; } - + // -------------------------------------------------------------------- - + /** * Set the Robot * * @access private * @return bool - */ + */ function _set_robot() { if (is_array($this->robots) AND count($this->robots) > 0) - { + { foreach ($this->robots as $key => $val) { if (preg_match("|".preg_quote($key)."|i", $this->agent)) @@ -220,17 +220,17 @@ class CI_User_agent { } // -------------------------------------------------------------------- - + /** * Set the Mobile Device * * @access private * @return bool - */ + */ function _set_mobile() { if (is_array($this->mobiles) AND count($this->mobiles) > 0) - { + { foreach ($this->mobiles as $key => $val) { if (FALSE !== (strpos(strtolower($this->agent), $key))) @@ -240,261 +240,261 @@ class CI_User_agent { return TRUE; } } - } + } return FALSE; } - + // -------------------------------------------------------------------- - + /** * Set the accepted languages * * @access private * @return void - */ + */ function _set_languages() { if ((count($this->languages) == 0) AND isset($_SERVER['HTTP_ACCEPT_LANGUAGE']) AND $_SERVER['HTTP_ACCEPT_LANGUAGE'] != '') { $languages = preg_replace('/(;q=[0-9\.]+)/i', '', strtolower(trim($_SERVER['HTTP_ACCEPT_LANGUAGE']))); - + $this->languages = explode(',', $languages); } - + if (count($this->languages) == 0) { $this->languages = array('Undefined'); - } + } } - + // -------------------------------------------------------------------- - + /** * Set the accepted character sets * * @access private * @return void - */ + */ function _set_charsets() - { + { if ((count($this->charsets) == 0) AND isset($_SERVER['HTTP_ACCEPT_CHARSET']) AND $_SERVER['HTTP_ACCEPT_CHARSET'] != '') { $charsets = preg_replace('/(;q=.+)/i', '', strtolower(trim($_SERVER['HTTP_ACCEPT_CHARSET']))); - + $this->charsets = explode(',', $charsets); } - + if (count($this->charsets) == 0) { $this->charsets = array('Undefined'); - } + } } // -------------------------------------------------------------------- - + /** * Is Browser * * @access public * @return bool - */ + */ function is_browser() { return $this->is_browser; } // -------------------------------------------------------------------- - + /** * Is Robot * * @access public * @return bool - */ + */ function is_robot() { return $this->is_robot; } // -------------------------------------------------------------------- - + /** * Is Mobile * * @access public * @return bool - */ + */ function is_mobile() { return $this->is_mobile; - } + } // -------------------------------------------------------------------- - + /** * Is this a referral from another site? * * @access public * @return bool - */ + */ function is_referral() { return ( ! isset($_SERVER['HTTP_REFERER']) OR $_SERVER['HTTP_REFERER'] == '') ? FALSE : TRUE; } // -------------------------------------------------------------------- - + /** * Agent String * * @access public * @return string - */ + */ function agent_string() { return $this->agent; } // -------------------------------------------------------------------- - + /** * Get Platform * * @access public * @return string - */ + */ function platform() { return $this->platform; } // -------------------------------------------------------------------- - + /** * Get Browser Name * * @access public * @return string - */ + */ function browser() { return $this->browser; } // -------------------------------------------------------------------- - + /** * Get the Browser Version * * @access public * @return string - */ + */ function version() { return $this->version; } // -------------------------------------------------------------------- - + /** * Get The Robot Name * * @access public * @return string - */ + */ function robot() { return $this->robot; } // -------------------------------------------------------------------- - + /** * Get the Mobile Device * * @access public * @return string - */ + */ function mobile() { return $this->mobile; } - + // -------------------------------------------------------------------- - + /** * Get the referrer * * @access public * @return bool - */ + */ function referrer() { return ( ! isset($_SERVER['HTTP_REFERER']) OR $_SERVER['HTTP_REFERER'] == '') ? '' : trim($_SERVER['HTTP_REFERER']); } // -------------------------------------------------------------------- - + /** * Get the accepted languages * * @access public * @return array - */ + */ function languages() { if (count($this->languages) == 0) { $this->_set_languages(); } - + return $this->languages; } // -------------------------------------------------------------------- - + /** * Get the accepted Character Sets * * @access public * @return array - */ + */ function charsets() { if (count($this->charsets) == 0) { $this->_set_charsets(); } - + return $this->charsets; } - + // -------------------------------------------------------------------- - + /** * Test for a particular language * * @access public * @return bool - */ + */ function accept_lang($lang = 'en') { return (in_array(strtolower($lang), $this->languages(), TRUE)) ? TRUE : FALSE; } - + // -------------------------------------------------------------------- - + /** * Test for a particular character set * * @access public * @return bool - */ + */ function accept_charset($charset = 'utf-8') { return (in_array(strtolower($charset), $this->charsets(), TRUE)) ? TRUE : FALSE; } - - + + } diff --git a/system/libraries/Xmlrpc.php b/system/libraries/Xmlrpc.php index ff03a503a..54ee70771 100644 --- a/system/libraries/Xmlrpc.php +++ b/system/libraries/Xmlrpc.php @@ -14,7 +14,7 @@ */ if ( ! function_exists('xml_parser_create')) -{ +{ show_error('Your PHP installation does not support XML'); } @@ -32,34 +32,34 @@ if ( ! function_exists('xml_parser_create')) */ class CI_Xmlrpc { - var $debug = FALSE; // Debugging on or off + var $debug = FALSE; // Debugging on or off var $xmlrpcI4 = 'i4'; var $xmlrpcInt = 'int'; var $xmlrpcBoolean = 'boolean'; - var $xmlrpcDouble = 'double'; + var $xmlrpcDouble = 'double'; var $xmlrpcString = 'string'; var $xmlrpcDateTime = 'dateTime.iso8601'; var $xmlrpcBase64 = 'base64'; var $xmlrpcArray = 'array'; var $xmlrpcStruct = 'struct'; - + var $xmlrpcTypes = array(); var $valid_parents = array(); var $xmlrpcerr = array(); // Response numbers var $xmlrpcstr = array(); // Response strings - + var $xmlrpc_defencoding = 'UTF-8'; var $xmlrpcName = 'XML-RPC for CodeIgniter'; var $xmlrpcVersion = '1.1'; var $xmlrpcerruser = 800; // Start of user errors var $xmlrpcerrxml = 100; // Start of XML Parse errors var $xmlrpc_backslash = ''; // formulate backslashes for escaping regexp - + var $client; var $method; var $data; var $message = ''; - var $error = ''; // Error string for request + var $error = ''; // Error string for request var $result; var $response = array(); // Response from remote server @@ -71,22 +71,22 @@ class CI_Xmlrpc { function CI_Xmlrpc ($config = array()) { - $this->xmlrpcName = $this->xmlrpcName; + $this->xmlrpcName = $this->xmlrpcName; $this->xmlrpc_backslash = chr(92).chr(92); - + // Types for info sent back and forth $this->xmlrpcTypes = array( - $this->xmlrpcI4 => '1', - $this->xmlrpcInt => '1', - $this->xmlrpcBoolean => '1', - $this->xmlrpcString => '1', - $this->xmlrpcDouble => '1', - $this->xmlrpcDateTime => '1', - $this->xmlrpcBase64 => '1', - $this->xmlrpcArray => '2', - $this->xmlrpcStruct => '3' + $this->xmlrpcI4 => '1', + $this->xmlrpcInt => '1', + $this->xmlrpcBoolean => '1', + $this->xmlrpcString => '1', + $this->xmlrpcDouble => '1', + $this->xmlrpcDateTime => '1', + $this->xmlrpcBase64 => '1', + $this->xmlrpcArray => '2', + $this->xmlrpcStruct => '3' ); - + // Array of Valid Parents for Various XML-RPC elements $this->valid_parents = array('BOOLEAN' => array('VALUE'), 'I4' => array('VALUE'), @@ -106,8 +106,8 @@ class CI_Xmlrpc { 'FAULT' => array('METHODRESPONSE'), 'VALUE' => array('MEMBER', 'DATA', 'PARAM', 'FAULT') ); - - + + // XML-RPC Responses $this->xmlrpcerr['unknown_method'] = '1'; $this->xmlrpcstr['unknown_method'] = 'This is not a known method for this XML-RPC Server'; @@ -121,13 +121,13 @@ class CI_Xmlrpc { $this->xmlrpcstr['http_error'] = "Did not receive a '200 OK' response from remote server."; $this->xmlrpcerr['no_data'] = '6'; $this->xmlrpcstr['no_data'] ='No data received from server.'; - + $this->initialize($config); - + log_message('debug', "XML-RPC Class Initialized"); } - - + + //------------------------------------- // Initialize Prefs //------------------------------------- @@ -140,13 +140,13 @@ class CI_Xmlrpc { { if (isset($this->$key)) { - $this->$key = $val; + $this->$key = $val; } } } } // END - + //------------------------------------- // Take URL and parse it //------------------------------------- @@ -157,20 +157,20 @@ class CI_Xmlrpc { { $url = "http://".$url; } - + $parts = parse_url($url); - + $path = ( ! isset($parts['path'])) ? '/' : $parts['path']; - + if (isset($parts['query']) && $parts['query'] != '') { $path .= '?'.$parts['query']; - } - + } + $this->client = new XML_RPC_Client($path, $parts['host'], $port); } // END - + //------------------------------------- // Set Timeout //------------------------------------- @@ -183,7 +183,7 @@ class CI_Xmlrpc { } } // END - + //------------------------------------- // Set Methods //------------------------------------- @@ -193,7 +193,7 @@ class CI_Xmlrpc { $this->method = $function; } // END - + //------------------------------------- // Take Array of Data and Create Objects //------------------------------------- @@ -204,17 +204,17 @@ class CI_Xmlrpc { { // Send Error } - + $this->data = array(); - + foreach($incoming as $key => $value) { $this->data[$key] = $this->values_parsing($value); } } // END - - + + //------------------------------------- // Set Debug //------------------------------------- @@ -223,7 +223,7 @@ class CI_Xmlrpc { { $this->debug = ($flag == TRUE) ? TRUE : FALSE; } - + //------------------------------------- // Values Parsing //------------------------------------- @@ -249,7 +249,7 @@ class CI_Xmlrpc { { $value['0'][$k] = $this->values_parsing($value['0'][$k], TRUE); } - + $temp = new XML_RPC_Values($value['0'], $value['1']); } else @@ -275,7 +275,7 @@ class CI_Xmlrpc { { $this->message = new XML_RPC_Message($this->method,$this->data); $this->message->debug = $this->debug; - + if ( ! $this->result = $this->client->send($this->message)) { $this->error = $this->result->errstr; @@ -286,13 +286,13 @@ class CI_Xmlrpc { $this->error = $this->result->errstr; return FALSE; } - + $this->response = $this->result->decode(); - + return TRUE; } // END - + //------------------------------------- // Returns Error //------------------------------------- @@ -302,7 +302,7 @@ class CI_Xmlrpc { return $this->error; } // END - + //------------------------------------- // Returns Remote Server Response //------------------------------------- @@ -312,37 +312,37 @@ class CI_Xmlrpc { return $this->response; } // END - + //------------------------------------- // Sends an Error Message for Server Request //------------------------------------- - + function send_error_message($number, $message) { return new XML_RPC_Response('0',$number, $message); } // END - - + + //------------------------------------- // Send Response for Server Request //------------------------------------- - + function send_response($response) { // $response should be array of values, which will be parsed // based on their data and type into a valid group of XML-RPC values - + $response = $this->values_parsing($response); - + return new XML_RPC_Response($response); } // END - + } // END XML_RPC Class - - + + /** * XML-RPC Client class * @@ -363,12 +363,12 @@ class XML_RPC_Client extends CI_Xmlrpc function XML_RPC_Client($path, $server, $port=80) { parent::CI_Xmlrpc(); - + $this->port = $port; $this->server = $server; $this->path = $path; } - + function send($msg) { if (is_array($msg)) @@ -382,22 +382,22 @@ class XML_RPC_Client extends CI_Xmlrpc } function sendPayload($msg) - { + { $fp = @fsockopen($this->server, $this->port,$this->errno, $this->errstr, $this->timeout); - + if ( ! is_resource($fp)) { error_log($this->xmlrpcstr['http_error']); $r = new XML_RPC_Response(0, $this->xmlrpcerr['http_error'],$this->xmlrpcstr['http_error']); return $r; } - + if(empty($msg->payload)) { // $msg = XML_RPC_Messages $msg->createPayload(); } - + $r = "\r\n"; $op = "POST {$this->path} HTTP/1.0$r"; $op .= "Host: {$this->server}$r"; @@ -405,7 +405,7 @@ class XML_RPC_Client extends CI_Xmlrpc $op .= "User-Agent: {$this->xmlrpcName}$r"; $op .= "Content-Length: ".strlen($msg->payload). "$r$r"; $op .= $msg->payload; - + if ( ! fputs($fp, $op, strlen($op))) { @@ -437,7 +437,7 @@ class XML_RPC_Response var $xss_clean = TRUE; function XML_RPC_Response($val, $code = 0, $fstr = '') - { + { if ($code != 0) { // error @@ -470,7 +470,7 @@ class XML_RPC_Response { return $this->val; } - + function prepare_response() { $result = "\n"; @@ -500,7 +500,7 @@ class XML_RPC_Response $result .= "\n"; return $result; } - + function decode($array=FALSE) { $CI =& get_instance(); @@ -523,13 +523,13 @@ class XML_RPC_Response $array[$key] = ($this->xss_clean) ? $CI->security->xss_clean($array[$key]) : $array[$key]; } } - + $result = $array; } else { $result = $this->xmlrpc_decoder($this->val); - + if (is_array($result)) { $result = $this->decode($result); @@ -539,12 +539,12 @@ class XML_RPC_Response $result = ($this->xss_clean) ? $CI->security->xss_clean($result) : $result; } } - + return $result; } - - + + //------------------------------------- // XML-RPC Object to PHP Types //------------------------------------- @@ -562,7 +562,7 @@ class XML_RPC_Response reset($xmlrpc_val->me); list($a,$b) = each($xmlrpc_val->me); $size = count($b); - + $arr = array(); for($i = 0; $i < $size; $i++) @@ -583,8 +583,8 @@ class XML_RPC_Response return $arr; } } - - + + //------------------------------------- // ISO-8601 time to server or UTC time //------------------------------------- @@ -602,7 +602,7 @@ class XML_RPC_Response } return $t; } - + } // End Response Class @@ -619,12 +619,12 @@ class XML_RPC_Message extends CI_Xmlrpc var $payload; var $method_name; var $params = array(); - var $xh = array(); + var $xh = array(); function XML_RPC_Message($method, $pars=0) { parent::CI_Xmlrpc(); - + $this->method_name = $method; if (is_array($pars) && count($pars) > 0) { @@ -635,51 +635,51 @@ class XML_RPC_Message extends CI_Xmlrpc } } } - + //------------------------------------- // Create Payload to Send //------------------------------------- - + function createPayload() { $this->payload = "\r\n\r\n"; $this->payload .= '' . $this->method_name . "\r\n"; $this->payload .= "\r\n"; - + for($i=0; $iparams); $i++) { // $p = XML_RPC_Values $p = $this->params[$i]; $this->payload .= "\r\n".$p->serialize_class()."\r\n"; } - + $this->payload .= "\r\n\r\n"; } - + //------------------------------------- // Parse External XML-RPC Server's Response //------------------------------------- - + function parseResponse($fp) { $data = ''; - + while($datum = fread($fp, 4096)) { $data .= $datum; } - + //------------------------------------- // DISPLAY HTTP CONTENT for DEBUGGING //------------------------------------- - + if ($this->debug === TRUE) { echo "
    ";
     			echo "---DATA---\n" . htmlspecialchars($data) . "\n---END DATA---\n\n";
     			echo "
    "; } - + //------------------------------------- // Check for data //------------------------------------- @@ -690,32 +690,32 @@ class XML_RPC_Message extends CI_Xmlrpc $r = new XML_RPC_Response(0, $this->xmlrpcerr['no_data'], $this->xmlrpcstr['no_data']); return $r; } - - + + //------------------------------------- // Check for HTTP 200 Response //------------------------------------- - + if (strncmp($data, 'HTTP', 4) == 0 && ! preg_match('/^HTTP\/[0-9\.]+ 200 /', $data)) { $errstr= substr($data, 0, strpos($data, "\n")-1); $r = new XML_RPC_Response(0, $this->xmlrpcerr['http_error'], $this->xmlrpcstr['http_error']. ' (' . $errstr . ')'); return $r; } - + //------------------------------------- // Create and Set Up XML Parser //------------------------------------- - + $parser = xml_parser_create($this->xmlrpc_defencoding); - $this->xh[$parser] = array(); - $this->xh[$parser]['isf'] = 0; - $this->xh[$parser]['ac'] = ''; - $this->xh[$parser]['headers'] = array(); - $this->xh[$parser]['stack'] = array(); - $this->xh[$parser]['valuestack'] = array(); - $this->xh[$parser]['isf_reason'] = 0; + $this->xh[$parser] = array(); + $this->xh[$parser]['isf'] = 0; + $this->xh[$parser]['ac'] = ''; + $this->xh[$parser]['headers'] = array(); + $this->xh[$parser]['stack'] = array(); + $this->xh[$parser]['valuestack'] = array(); + $this->xh[$parser]['isf_reason'] = 0; xml_set_object($parser, $this); xml_parser_set_option($parser, XML_OPTION_CASE_FOLDING, true); @@ -727,7 +727,7 @@ class XML_RPC_Message extends CI_Xmlrpc //------------------------------------- // GET HEADERS //------------------------------------- - + $lines = explode("\r\n", $data); while (($line = array_shift($lines))) { @@ -738,11 +738,11 @@ class XML_RPC_Message extends CI_Xmlrpc $this->xh[$parser]['headers'][] = $line; } $data = implode("\r\n", $lines); - - + + //------------------------------------- // PARSE XML DATA - //------------------------------------- + //------------------------------------- if ( ! xml_parse($parser, $data, count($data))) { @@ -755,11 +755,11 @@ class XML_RPC_Message extends CI_Xmlrpc return $r; } xml_parser_free($parser); - + // --------------------------------------- // Got Ourselves Some Badness, It Seems // --------------------------------------- - + if ($this->xh[$parser]['isf'] > 1) { if ($this->debug === TRUE) @@ -768,7 +768,7 @@ class XML_RPC_Message extends CI_Xmlrpc echo $this->xh[$parser]['isf_reason']; echo "---Invalid Return---\n\n"; } - + $r = new XML_RPC_Response(0, $this->xmlrpcerr['invalid_return'],$this->xmlrpcstr['invalid_return'].' '.$this->xh[$parser]['isf_reason']); return $r; } @@ -777,15 +777,15 @@ class XML_RPC_Message extends CI_Xmlrpc $r = new XML_RPC_Response(0, $this->xmlrpcerr['invalid_return'],$this->xmlrpcstr['invalid_return'].' '.$this->xh[$parser]['isf_reason']); return $r; } - + //------------------------------------- // DISPLAY XML CONTENT for DEBUGGING - //------------------------------------- - + //------------------------------------- + if ($this->debug === TRUE) { echo "
    ";
    -			
    +
     			if (count($this->xh[$parser]['headers'] > 0))
     			{
     				echo "---HEADERS---\n";
    @@ -795,20 +795,20 @@ class XML_RPC_Message extends CI_Xmlrpc
     				}
     				echo "---END HEADERS---\n\n";
     			}
    -			
    +
     			echo "---DATA---\n" . htmlspecialchars($data) . "\n---END DATA---\n\n";
    -			
    +
     			echo "---PARSED---\n" ;
     			var_dump($this->xh[$parser]['value']);
     			echo "\n---END PARSED---
    "; } - + //------------------------------------- // SEND RESPONSE //------------------------------------- - + $v = $this->xh[$parser]['value']; - + if ($this->xh[$parser]['isf']) { $errno_v = $v->me['struct']['faultCode']; @@ -831,11 +831,11 @@ class XML_RPC_Message extends CI_Xmlrpc $r->headers = $this->xh[$parser]['headers']; return $r; } - + // ------------------------------------ // Begin Return Message Parsing section // ------------------------------------ - + // quick explanation of components: // ac - used to accumulate values // isf - used to indicate a fault @@ -854,9 +854,9 @@ class XML_RPC_Message extends CI_Xmlrpc { // If invalid nesting, then return if ($this->xh[$the_parser]['isf'] > 1) return; - + // Evaluate and check for correct nesting of XML elements - + if (count($this->xh[$the_parser]['stack']) == 0) { if ($name != 'METHODRESPONSE' && $name != 'METHODCALL') @@ -876,16 +876,16 @@ class XML_RPC_Message extends CI_Xmlrpc return; } } - + switch($name) { case 'STRUCT': case 'ARRAY': // Creates array for child elements - + $cur_val = array('value' => array(), 'type' => $name); - + array_unshift($this->xh[$the_parser]['valuestack'], $cur_val); break; case 'METHODNAME': @@ -917,13 +917,13 @@ class XML_RPC_Message extends CI_Xmlrpc $this->xh[$the_parser]['isf_reason'] = "'Twas a $name element following a ".$this->xh[$the_parser]['vt']." element inside a single value"; return; } - + $this->xh[$the_parser]['ac'] = ''; break; case 'MEMBER': // Set name of to nothing to prevent errors later if no is found $this->xh[$the_parser]['valuestack'][0]['name'] = ''; - + // Set NULL value to check to see if value passed for this param/member $this->xh[$the_parser]['value'] = null; break; @@ -939,7 +939,7 @@ class XML_RPC_Message extends CI_Xmlrpc $this->xh[$the_parser]['isf_reason'] = "Invalid XML-RPC element found: $name"; break; } - + // Add current element name to stack, to allow validation of nesting array_unshift($this->xh[$the_parser]['stack'], $name); @@ -955,14 +955,14 @@ class XML_RPC_Message extends CI_Xmlrpc function closing_tag($the_parser, $name) { if ($this->xh[$the_parser]['isf'] > 1) return; - + // Remove current element from stack and set variable // NOTE: If the XML validates, then we do not have to worry about // the opening and closing of elements. Nesting is checked on the opening // tag so we be safe there as well. - + $curr_elem = array_shift($this->xh[$the_parser]['stack']); - + switch($name) { case 'STRUCT': @@ -982,7 +982,7 @@ class XML_RPC_Message extends CI_Xmlrpc case 'DATETIME.ISO8601': case 'BASE64': $this->xh[$the_parser]['vt'] = strtolower($name); - + if ($name == 'STRING') { $this->xh[$the_parser]['value'] = $this->xh[$the_parser]['ac']; @@ -1044,10 +1044,10 @@ class XML_RPC_Message extends CI_Xmlrpc $this->xh[$the_parser]['value'] = $this->xh[$the_parser]['ac']; $this->xh[$the_parser]['vt'] = $this->xmlrpcString; } - + // build the XML-RPC value out of the data received, and substitute it $temp = new XML_RPC_Values($this->xh[$the_parser]['value'], $this->xh[$the_parser]['vt']); - + if (count($this->xh[$the_parser]['valuestack']) && $this->xh[$the_parser]['valuestack'][0]['type'] == 'ARRAY') { // Array @@ -1061,7 +1061,7 @@ class XML_RPC_Message extends CI_Xmlrpc break; case 'MEMBER': $this->xh[$the_parser]['ac']=''; - + // If value add to array in the stack for the last element built if ($this->xh[$the_parser]['value']) { @@ -1099,7 +1099,7 @@ class XML_RPC_Message extends CI_Xmlrpc function character_data($the_parser, $data) { if ($this->xh[$the_parser]['isf'] > 1) return; // XML Fault found already - + // If a value has not been found if ($this->xh[$the_parser]['lv'] != 3) { @@ -1107,28 +1107,28 @@ class XML_RPC_Message extends CI_Xmlrpc { $this->xh[$the_parser]['lv'] = 2; // Found a value } - + if( ! @isset($this->xh[$the_parser]['ac'])) { $this->xh[$the_parser]['ac'] = ''; } - + $this->xh[$the_parser]['ac'] .= $data; } } - - + + function addParam($par) { $this->params[]=$par; } - + function output_parameters($array=FALSE) { - $CI =& get_instance(); + $CI =& get_instance(); if ($this->xss_clean && ! isset($CI->security)) { $CI->load->library('security'); } - + if ($array !== FALSE && is_array($array)) { while (list($key) = each($array)) @@ -1144,17 +1144,17 @@ class XML_RPC_Message extends CI_Xmlrpc $array[$key] = ($key == 'bits' OR $this->xss_clean == FALSE) ? $array[$key] : $CI->security->xss_clean($array[$key]); } } - + $parameters = $array; } else { $parameters = array(); - + for ($i = 0; $i < count($this->params); $i++) { $a_param = $this->decode_message($this->params[$i]); - + if (is_array($a_param)) { $parameters[] = $this->output_parameters($a_param); @@ -1163,13 +1163,13 @@ class XML_RPC_Message extends CI_Xmlrpc { $parameters[] = ($this->xss_clean) ? $CI->security->xss_clean($a_param) : $a_param; } - } + } } - + return $parameters; } - - + + function decode_message($param) { $kind = $param->kindOf(); @@ -1182,31 +1182,31 @@ class XML_RPC_Message extends CI_Xmlrpc { reset($param->me); list($a,$b) = each($param->me); - + $arr = array(); for($i = 0; $i < count($b); $i++) { $arr[] = $this->decode_message($param->me['array'][$i]); } - + return $arr; } elseif($kind == 'struct') { reset($param->me['struct']); - + $arr = array(); while(list($key,$value) = each($param->me['struct'])) { $arr[$key] = $this->decode_message($value); } - + return $arr; } } - + } // End XML_RPC_Messages class @@ -1220,17 +1220,17 @@ class XML_RPC_Message extends CI_Xmlrpc */ class XML_RPC_Values extends CI_Xmlrpc { - var $me = array(); + var $me = array(); var $mytype = 0; function XML_RPC_Values($val=-1, $type='') - { + { parent::CI_Xmlrpc(); - + if ($val != -1 OR $type != '') { $type = $type == '' ? 'string' : $type; - + if ($this->xmlrpcTypes[$type] == 1) { $this->addScalar($val,$type); @@ -1249,13 +1249,13 @@ class XML_RPC_Values extends CI_Xmlrpc function addScalar($val, $type='string') { $typeof = $this->xmlrpcTypes[$type]; - + if ($this->mytype==1) { echo 'XML_RPC_Values: scalar can have only one value
    '; return 0; } - + if ($typeof != 1) { echo 'XML_RPC_Values: not a scalar type (${typeof})
    '; @@ -1392,12 +1392,12 @@ class XML_RPC_Values extends CI_Xmlrpc { $ar = $o->me; reset($ar); - + list($typ, $val) = each($ar); $rs = "\n".$this->serializedata($typ, $val)."\n"; return $rs; } - + function scalarval() { reset($this->me); @@ -1409,11 +1409,11 @@ class XML_RPC_Values extends CI_Xmlrpc //------------------------------------- // Encode time in ISO-8601 form. //------------------------------------- - + // Useful for sending time in XML-RPC function iso8601_encode($time, $utc=0) - { + { if ($utc == 1) { $t = strftime("%Y%m%dT%H:%M:%S", $time); @@ -1427,7 +1427,7 @@ class XML_RPC_Values extends CI_Xmlrpc } return $t; } - + } // END XML_RPC_Values Class diff --git a/system/libraries/Xmlrpcs.php b/system/libraries/Xmlrpcs.php index c1fe649f9..56fd655df 100644 --- a/system/libraries/Xmlrpcs.php +++ b/system/libraries/Xmlrpcs.php @@ -14,7 +14,7 @@ */ if ( ! function_exists('xml_parser_create')) -{ +{ show_error('Your PHP installation does not support XML'); } @@ -36,11 +36,11 @@ if ( ! class_exists('CI_Xmlrpc')) */ class CI_Xmlrpcs extends CI_Xmlrpc { - var $methods = array(); //array of methods mapped to function names and signatures + var $methods = array(); //array of methods mapped to function names and signatures var $debug_msg = ''; // Debug Message - var $system_methods = array(); // XML RPC Server methods + var $system_methods = array(); // XML RPC Server methods var $controller_obj; - + var $object = FALSE; @@ -49,49 +49,49 @@ class CI_Xmlrpcs extends CI_Xmlrpc //------------------------------------- function CI_Xmlrpcs($config=array()) - { + { parent::CI_Xmlrpc(); $this->set_system_methods(); - + if (isset($config['functions']) && is_array($config['functions'])) { $this->methods = array_merge($this->methods, $config['functions']); } - + log_message('debug', "XML-RPC Server Class Initialized"); } - + //------------------------------------- // Initialize Prefs and Serve //------------------------------------- - + 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 //------------------------------------- - + function set_system_methods () { $this->methods = array( @@ -118,14 +118,14 @@ class CI_Xmlrpcs extends CI_Xmlrpc //------------------------------------- // Main Server Function //------------------------------------- - + function serve() { $r = $this->parseRequest(); $payload = 'xmlrpc_defencoding.'"?'.'>'."\n"; $payload .= $this->debug_msg; $payload .= $r->prepare_response(); - + header("Content-Type: text/xml"); header("Content-Length: ".strlen($payload)); exit($payload); @@ -134,7 +134,7 @@ class CI_Xmlrpcs extends CI_Xmlrpc //------------------------------------- // Add Method to Class //------------------------------------- - + function add_to_map($methodname,$function,$sig,$doc) { $this->methods[$methodname] = array( @@ -148,11 +148,11 @@ class CI_Xmlrpcs extends CI_Xmlrpc //------------------------------------- // Parse Server Request //------------------------------------- - + function parseRequest($data='') { global $HTTP_RAW_POST_DATA; - + //------------------------------------- // Get Data //------------------------------------- @@ -165,10 +165,10 @@ class CI_Xmlrpcs extends CI_Xmlrpc //------------------------------------- // Set up XML Parser //------------------------------------- - + $parser = xml_parser_create($this->xmlrpc_defencoding); $parser_object = new XML_RPC_Message("filler"); - + $parser_object->xh[$parser] = array(); $parser_object->xh[$parser]['isf'] = 0; $parser_object->xh[$parser]['isf_reason'] = ''; @@ -182,12 +182,12 @@ class CI_Xmlrpcs extends CI_Xmlrpc 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 @@ -205,53 +205,53 @@ class CI_Xmlrpcs extends CI_Xmlrpc else { xml_parser_free($parser); - + $m = new XML_RPC_Message($parser_object->xh[$parser]['method']); $plist=''; - + for($i=0; $i < count($parser_object->xh[$parser]['params']); $i++) { if ($this->debug === TRUE) { $plist .= "$i - " . print_r(get_object_vars($parser_object->xh[$parser]['params'][$i]), TRUE). ";\n"; } - + $m->addParam($parser_object->xh[$parser]['params'][$i]); } - + if ($this->debug === TRUE) { echo "
    ";
     				echo "---PLIST---\n" . $plist . "\n---PLIST END---\n\n";
     				echo "
    "; } - + $r = $this->_execute($m); } - + //------------------------------------- // SET DEBUGGING MESSAGE - //------------------------------------- - + //------------------------------------- + if ($this->debug === TRUE) { $this->debug_msg = "\n"; } - + return $r; } //------------------------------------- // Executes the Method //------------------------------------- - + 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; @@ -260,19 +260,19 @@ class CI_Xmlrpcs extends CI_Xmlrpc //------------------------------------- // 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']))) @@ -291,30 +291,30 @@ class CI_Xmlrpcs extends CI_Xmlrpc 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'] . @@ -354,22 +354,22 @@ class CI_Xmlrpcs extends CI_Xmlrpc return call_user_func($this->methods[$methName]['function'], $m); } } - - + + //------------------------------------- // Server Function: List Methods //------------------------------------- - + 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'); @@ -378,23 +378,23 @@ class CI_Xmlrpcs extends CI_Xmlrpc $v->addArray($output); return new XML_RPC_Response($v); } - + //------------------------------------- // Server Function: Return Signature for Method //------------------------------------- - + 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(); @@ -418,20 +418,20 @@ class CI_Xmlrpcs extends CI_Xmlrpc } return $r; } - + //------------------------------------- // Server Function: Doc String for Method //------------------------------------- - + 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 @@ -448,7 +448,7 @@ class CI_Xmlrpcs extends CI_Xmlrpc { // Disabled return new XML_RPC_Response(0, $this->xmlrpcerr['unknown_method'], $this->xmlrpcstr['unknown_method']); - + $parameters = $m->output_parameters(); $calls = $parameters[0]; @@ -457,15 +457,15 @@ class CI_Xmlrpcs extends CI_Xmlrpc 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) @@ -478,8 +478,8 @@ class CI_Xmlrpcs extends CI_Xmlrpc return new XML_RPC_Response(new XML_RPC_Values($result, 'array')); } - - + + //------------------------------------- // Multi-call Function: Error Handling //------------------------------------- @@ -488,28 +488,28 @@ class CI_Xmlrpcs extends CI_Xmlrpc { $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 //------------------------------------- - + 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') @@ -518,7 +518,7 @@ class CI_Xmlrpcs extends CI_Xmlrpc return $this->multicall_error('noparams'); elseif ($params->kindOf() != 'array') return $this->multicall_error('notarray'); - + list($a,$b)=each($params->me); $numParams = count($b); @@ -536,8 +536,8 @@ class CI_Xmlrpcs extends CI_Xmlrpc } return new XML_RPC_Values(array($result->value()), 'array'); - } - + } + } // END XML_RPC_Server class diff --git a/system/libraries/Zip.php b/system/libraries/Zip.php index 92dfc814d..da3e5eb63 100644 --- a/system/libraries/Zip.php +++ b/system/libraries/Zip.php @@ -32,17 +32,17 @@ */ class CI_Zip { - var $zipdata = ''; - var $directory = ''; - var $entries = 0; - var $file_num = 0; + var $zipdata = ''; + var $directory = ''; + var $entries = 0; + var $file_num = 0; var $offset = 0; var $now; function CI_Zip() { log_message('debug', "Zip Compression Class Initialized"); - + $this->now = time(); } @@ -72,24 +72,24 @@ class CI_Zip { } } - // -------------------------------------------------------------------- + // -------------------------------------------------------------------- /** * 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 + * @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); + $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; } @@ -103,7 +103,7 @@ class CI_Zip { * @return void */ function _add_dir($dir, $file_mtime, $file_mdate) - { + { $dir = str_replace("\\", "/", $dir); $this->zipdata .= @@ -140,7 +140,7 @@ class CI_Zip { $this->offset = strlen($this->zipdata); $this->entries++; } - + // -------------------------------------------------------------------- /** @@ -154,14 +154,14 @@ class CI_Zip { * @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); + $file_data = $this->_get_mod_time($path); $this->_add_data($path, $data, $file_data['file_mtime'], $file_data['file_mdate']); } @@ -169,7 +169,7 @@ class CI_Zip { else { $file_data = $this->_get_mod_time($filepath); - + $this->_add_data($filepath, $data, $file_data['file_mtime'], $file_data['file_mdate']); } } @@ -183,7 +183,7 @@ class CI_Zip { * @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); @@ -227,7 +227,7 @@ class CI_Zip { $this->entries++; $this->file_num++; } - + // -------------------------------------------------------------------- /** @@ -235,7 +235,7 @@ class CI_Zip { * * @access public * @return bool - */ + */ function read_file($path, $preserve_filepath = FALSE) { if ( ! file_exists($path)) @@ -246,7 +246,7 @@ class CI_Zip { if (FALSE !== ($data = file_get_contents($path))) { $name = str_replace("\\", "/", $path); - + if ($preserve_filepath === FALSE) { $name = preg_replace("|.*/(.+)|", "\\1", $name); @@ -259,7 +259,7 @@ class CI_Zip { } // ------------------------------------------------------------------------ - + /** * Read a directory and add it to the zip. * @@ -321,7 +321,7 @@ class CI_Zip { * * @access public * @return binary string - */ + */ function get_zip() { // Is there any data to return? @@ -340,7 +340,7 @@ class CI_Zip { return $zip_data; } - + // -------------------------------------------------------------------- /** @@ -351,7 +351,7 @@ class CI_Zip { * @access public * @param string the file name * @return bool - */ + */ function archive($filepath) { if ( ! ($fp = @fopen($filepath, FOPEN_WRITE_CREATE_DESTRUCTIVE))) @@ -359,12 +359,12 @@ class CI_Zip { return FALSE; } - flock($fp, LOCK_EX); + flock($fp, LOCK_EX); fwrite($fp, $this->get_zip()); flock($fp, LOCK_UN); fclose($fp); - return TRUE; + return TRUE; } // -------------------------------------------------------------------- @@ -404,7 +404,7 @@ class CI_Zip { * * @access public * @return void - */ + */ function clear_data() { $this->zipdata = ''; @@ -413,7 +413,7 @@ class CI_Zip { $this->file_num = 0; $this->offset = 0; } - + } /* End of file Zip.php */ diff --git a/system/libraries/javascript/Jquery.php b/system/libraries/javascript/Jquery.php index f6b8dce69..db80c1428 100644 --- a/system/libraries/javascript/Jquery.php +++ b/system/libraries/javascript/Jquery.php @@ -173,7 +173,7 @@ class CI_Jquery extends CI_Javascript { * @param string - element * @param string - Javascript code for mouse over * @param string - Javascript code for mouse out - * @return string + * @return string */ function _hover($element = 'this', $over, $out) { @@ -390,7 +390,7 @@ class CI_Jquery extends CI_Javascript { * * @access private * @param string - element - * @return string + * @return string */ function _addClass($element = 'this', $class='') { @@ -410,7 +410,7 @@ class CI_Jquery extends CI_Javascript { * @param string - element * @param string - One of 'slow', 'normal', 'fast', or time in milliseconds * @param string - Javascript callback function - * @return string + * @return string */ function _animate($element = 'this', $params = array(), $speed = '', $extra = '') { @@ -452,7 +452,7 @@ class CI_Jquery extends CI_Javascript { * @param string - element * @param string - One of 'slow', 'normal', 'fast', or time in milliseconds * @param string - Javascript callback function - * @return string + * @return string */ function _fadeIn($element = 'this', $speed = '', $callback = '') { @@ -480,7 +480,7 @@ class CI_Jquery extends CI_Javascript { * @param string - element * @param string - One of 'slow', 'normal', 'fast', or time in milliseconds * @param string - Javascript callback function - * @return string + * @return string */ function _fadeOut($element = 'this', $speed = '', $callback = '') { @@ -508,7 +508,7 @@ class CI_Jquery extends CI_Javascript { * @param string - element * @param string - One of 'slow', 'normal', 'fast', or time in milliseconds * @param string - Javascript callback function - * @return string + * @return string */ function _hide($element = 'this', $speed = '', $callback = '') { @@ -534,7 +534,7 @@ class CI_Jquery extends CI_Javascript { * * @access private * @param string - element - * @return string + * @return string */ function _removeClass($element = 'this', $class='') { @@ -554,7 +554,7 @@ class CI_Jquery extends CI_Javascript { * @param string - element * @param string - One of 'slow', 'normal', 'fast', or time in milliseconds * @param string - Javascript callback function - * @return string + * @return string */ function _slideUp($element = 'this', $speed = '', $callback = '') { @@ -582,7 +582,7 @@ class CI_Jquery extends CI_Javascript { * @param string - element * @param string - One of 'slow', 'normal', 'fast', or time in milliseconds * @param string - Javascript callback function - * @return string + * @return string */ function _slideDown($element = 'this', $speed = '', $callback = '') { @@ -610,7 +610,7 @@ class CI_Jquery extends CI_Javascript { * @param string - element * @param string - One of 'slow', 'normal', 'fast', or time in milliseconds * @param string - Javascript callback function - * @return string + * @return string */ function _slideToggle($element = 'this', $speed = '', $callback = '') { @@ -636,7 +636,7 @@ class CI_Jquery extends CI_Javascript { * * @access private * @param string - element - * @return string + * @return string */ function _toggle($element = 'this') { @@ -654,7 +654,7 @@ class CI_Jquery extends CI_Javascript { * * @access private * @param string - element - * @return string + * @return string */ function _toggleClass($element = 'this', $class='') { @@ -674,7 +674,7 @@ class CI_Jquery extends CI_Javascript { * @param string - element * @param string - One of 'slow', 'normal', 'fast', or time in milliseconds * @param string - Javascript callback function - * @return string + * @return string */ function _show($element = 'this', $speed = '', $callback = '') { @@ -884,7 +884,7 @@ class CI_Jquery extends CI_Javascript { } // -------------------------------------------------------------------- - + /** * Table Sorter Plugin * -- cgit v1.2.3-24-g4f1b From 71eee841e278ba5d08f836c047ef3c2e38fa34e1 Mon Sep 17 00:00:00 2001 From: Derek Jones Date: Tue, 5 Oct 2010 09:40:43 -0500 Subject: fixed bug where sess_expire_on_close was not being set from a config file, fixes #173 --- system/libraries/Session.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system') diff --git a/system/libraries/Session.php b/system/libraries/Session.php index fc3ee0542..7394e5897 100644 --- a/system/libraries/Session.php +++ b/system/libraries/Session.php @@ -61,7 +61,7 @@ class CI_Session { // 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_match_ip', 'sess_match_useragent', 'sess_cookie_name', 'cookie_path', 'cookie_domain', 'sess_time_to_update', 'time_reference', 'cookie_prefix', 'encryption_key') as $key) + foreach (array('sess_encrypt_cookie', 'sess_use_database', 'sess_table_name', 'sess_expiration', 'sess_expire_on_close', 'sess_match_ip', 'sess_match_useragent', 'sess_cookie_name', 'cookie_path', 'cookie_domain', 'sess_time_to_update', 'time_reference', 'cookie_prefix', 'encryption_key') as $key) { $this->$key = (isset($params[$key])) ? $params[$key] : $this->CI->config->item($key); } -- cgit v1.2.3-24-g4f1b From 2615e418539c3d6e2f912c66be99ffebfb8513ff Mon Sep 17 00:00:00 2001 From: Derek Jones Date: Wed, 6 Oct 2010 17:51:16 -0500 Subject: fixed a security issue which in certain cases could result in directory traversal --- system/core/Router.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'system') diff --git a/system/core/Router.php b/system/core/Router.php index b371d5241..d911eb224 100644 --- a/system/core/Router.php +++ b/system/core/Router.php @@ -345,7 +345,7 @@ class CI_Router { */ function set_class($class) { - $this->class = $class; + $this->class = str_replace(array('/', '.'), '', $class); } // -------------------------------------------------------------------- @@ -404,7 +404,7 @@ class CI_Router { */ function set_directory($dir) { - $this->directory = trim($dir, '/').'/'; + $this->directory = str_replace(array('/', '.'), '', $dir).'/'; } // -------------------------------------------------------------------- -- cgit v1.2.3-24-g4f1b From 2ef375969b77c5fdf84118d4a7a8e0bc97d9d2f6 Mon Sep 17 00:00:00 2001 From: Derek Jones Date: Wed, 6 Oct 2010 17:51:59 -0500 Subject: modified the security helper to assist in preventing directory traversal when using sanitize_filename() for user input --- system/libraries/Security.php | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) (limited to 'system') diff --git a/system/libraries/Security.php b/system/libraries/Security.php index 9a1590b5c..3c1e9cfba 100644 --- a/system/libraries/Security.php +++ b/system/libraries/Security.php @@ -680,11 +680,10 @@ class CI_Security { * @param string * @return string */ - function sanitize_filename($str) + function sanitize_filename($str, $relative_path = FALSE) { $bad = array( "../", - "./", "", "<", @@ -701,7 +700,6 @@ class CI_Security { '=', ';', '?', - '/', "%20", "%22", "%3c", // < @@ -717,6 +715,12 @@ class CI_Security { "%3b", // ; "%3d" // = ); + + if ( ! $relative_path) + { + $bad[] = './'; + $bad[] = '/'; + } return stripslashes(str_replace($bad, '', $str)); } -- cgit v1.2.3-24-g4f1b From 3a082fd3d6cb2e72612d51b9d8e54e93effb93eb Mon Sep 17 00:00:00 2001 From: Derek Jones Date: Thu, 7 Oct 2010 09:38:55 -0500 Subject: added elements() to the Array Helper to return elements from an array with specified keys only. Differs from array_intersect_assoc() in that a default value can be provided for keys that do not exist in the supplied array --- system/helpers/array_helper.php | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) (limited to 'system') diff --git a/system/helpers/array_helper.php b/system/helpers/array_helper.php index bd30b7c16..447ee1aa4 100644 --- a/system/helpers/array_helper.php +++ b/system/helpers/array_helper.php @@ -73,6 +73,46 @@ if ( ! function_exists('random_element')) } } +// -------------------------------------------------------------------- + +/** + * Elements + * + * Returns only the array items specified. Will return a default value if + * it is not set. + * + * @access public + * @param array + * @param array + * @param mixed + * @return mixed depends on what the array contains + */ +if ( ! function_exists('elements')) +{ + function elements($items, $array, $default = FALSE) + { + $return = array(); + + if ( ! is_array($items)) + { + $items = array($items); + } + + foreach ($items as $item) + { + if (isset($array[$item])) + { + $return[$item] = $array[$item]; + } + else + { + $return[$item] = $default; + } + } + + return $return; + } +} /* End of file array_helper.php */ /* Location: ./system/helpers/array_helper.php */ \ No newline at end of file -- cgit v1.2.3-24-g4f1b From bce1348820118ea750224c17d81846229dff4852 Mon Sep 17 00:00:00 2001 From: Greg Aker Date: Mon, 11 Oct 2010 15:37:16 -0500 Subject: Fixed a bug where CI_Model is always loaded in core/Loader.php, regardless of if the class is instantiated or not. --- system/core/Loader.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system') diff --git a/system/core/Loader.php b/system/core/Loader.php index 292fdc955..316985609 100644 --- a/system/core/Loader.php +++ b/system/core/Loader.php @@ -177,7 +177,7 @@ class CI_Loader { $CI->load->database($db_conn, FALSE, TRUE); } - if ( ! class_exists('Model')) + if ( ! class_exists('CI_Model')) { load_class('Model', 'core'); } -- cgit v1.2.3-24-g4f1b From ce43396cb7beb49558cd78cf7ef51956a74b8185 Mon Sep 17 00:00:00 2001 From: Greg Aker Date: Tue, 12 Oct 2010 09:29:35 -0500 Subject: Fix #83 where multiple libraries could not be loaded at once by passing an array to the load->library() function. --- system/core/Loader.php | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'system') diff --git a/system/core/Loader.php b/system/core/Loader.php index 316985609..e64006e93 100644 --- a/system/core/Loader.php +++ b/system/core/Loader.php @@ -78,6 +78,16 @@ class CI_Loader { */ function library($library = '', $params = NULL, $object_name = NULL) { + if (is_array($library)) + { + foreach($library as $read) + { + $this->library($read); + } + + return; + } + if ($library == '' OR isset($this->_base_classes[$library])) { return FALSE; -- cgit v1.2.3-24-g4f1b From 5b2d2da5ae2e97043c6bef53e565d30e50196e2b Mon Sep 17 00:00:00 2001 From: Pascal Kriete Date: Thu, 4 Nov 2010 17:23:40 -0400 Subject: Fixing the docblock on the unicode class. --- system/core/Unicode.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'system') diff --git a/system/core/Unicode.php b/system/core/Unicode.php index c8f1203f7..ec40c11ed 100644 --- a/system/core/Unicode.php +++ b/system/core/Unicode.php @@ -9,16 +9,16 @@ * @copyright Copyright (c) 2008 - 2010, EllisLab, Inc. * @license http://codeigniter.com/user_guide/license.html * @link http://codeigniter.com - * @since Version 1.0 + * @since Version 2.0 * @filesource */ // ------------------------------------------------------------------------ /** - * Output Class + * Unicode Class * - * Responsible for sending final output to browser + * Provides unicode support for UTF-8 environments * * @package CodeIgniter * @subpackage Libraries -- cgit v1.2.3-24-g4f1b From f566af5ffb8f2e8d49bd0b206c6ee29c8bc35a78 Mon Sep 17 00:00:00 2001 From: Pascal Kriete Date: Tue, 9 Nov 2010 13:03:26 -0500 Subject: Fixed a bug where silently failed to override if set_time_limit was in Suhosin's function blacklist. Simply moved the set_time_limit call down a bit. --- system/core/CodeIgniter.php | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) (limited to 'system') diff --git a/system/core/CodeIgniter.php b/system/core/CodeIgniter.php index f67bb8c10..e701cc323 100644 --- a/system/core/CodeIgniter.php +++ b/system/core/CodeIgniter.php @@ -67,12 +67,6 @@ @set_magic_quotes_runtime(0); // Kill magic quotes } - // Set a liberal script execution time limit - if (function_exists("set_time_limit") == TRUE AND @ini_get("safe_mode") == 0) - { - @set_time_limit(300); - } - /* * ------------------------------------------------------ * Set the subclass_prefix @@ -93,6 +87,16 @@ { get_config(array('subclass_prefix' => $assign_to_config['subclass_prefix'])); } + +/* + * ------------------------------------------------------ + * Set a liberal script execution time limit + * ------------------------------------------------------ + */ + if (function_exists("set_time_limit") == TRUE AND @ini_get("safe_mode") == 0) + { + @set_time_limit(300); + } /* * ------------------------------------------------------ -- cgit v1.2.3-24-g4f1b From 6b6c274e00fe2357004c0a4e38e6bdb0b2e0ddb4 Mon Sep 17 00:00:00 2001 From: Pascal Kriete Date: Tue, 9 Nov 2010 13:12:22 -0500 Subject: Normalizing package paths to include a single trailing slash. --- system/core/Loader.php | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'system') diff --git a/system/core/Loader.php b/system/core/Loader.php index 5a2175c2d..e2970613b 100644 --- a/system/core/Loader.php +++ b/system/core/Loader.php @@ -535,6 +535,8 @@ class CI_Loader { */ function add_package_path($path) { + $path = rtrim($path, '/').'/'; + array_unshift($this->_ci_library_paths, $path); array_unshift($this->_ci_model_paths, $path); array_unshift($this->_ci_helper_paths, $path); @@ -569,6 +571,8 @@ class CI_Loader { } 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) -- cgit v1.2.3-24-g4f1b From 63277b81edde11b77ff94cbf1c3e5db16c97c4bf Mon Sep 17 00:00:00 2001 From: Greg Aker Date: Tue, 9 Nov 2010 13:46:13 -0600 Subject: Fix #62 Adding CI_ prefix to Controller. --- system/core/CodeIgniter.php | 2 +- system/core/Controller.php | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) (limited to 'system') diff --git a/system/core/CodeIgniter.php b/system/core/CodeIgniter.php index e701cc323..3dfefc2ef 100644 --- a/system/core/CodeIgniter.php +++ b/system/core/CodeIgniter.php @@ -261,7 +261,7 @@ if ( ! class_exists($class) OR $method == 'controller' OR strncmp($method, '_', 1) == 0 - OR in_array(strtolower($method), array_map('strtolower', get_class_methods('Controller'))) + OR in_array(strtolower($method), array_map('strtolower', get_class_methods('CI_Controller'))) ) { show_404("{$class}/{$method}"); diff --git a/system/core/Controller.php b/system/core/Controller.php index 9bd9912dc..e250caf4b 100644 --- a/system/core/Controller.php +++ b/system/core/Controller.php @@ -27,17 +27,17 @@ * @author ExpressionEngine Dev Team * @link http://codeigniter.com/user_guide/general/controllers.html */ -class Controller extends CI_Base { +class CI_Controller extends CI_Base { /** * Constructor * * Calls the initialize() function */ - function Controller() + function CI_Controller() { parent::CI_Base(); - + // 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. -- cgit v1.2.3-24-g4f1b From 3431ae375f7e9283ccfe7e165f39bfc84d79f694 Mon Sep 17 00:00:00 2001 From: Pascal Kriete Date: Tue, 9 Nov 2010 15:19:50 -0500 Subject: Adding a second parameter to _remap that contains an array of the leftover segments. --- system/core/CodeIgniter.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system') diff --git a/system/core/CodeIgniter.php b/system/core/CodeIgniter.php index e701cc323..b52281918 100644 --- a/system/core/CodeIgniter.php +++ b/system/core/CodeIgniter.php @@ -299,7 +299,7 @@ // Is there a "remap" function? If so, we call it instead if (method_exists($CI, '_remap')) { - $CI->_remap($method); + $CI->_remap($method, array_slice($URI->rsegments, 2)); } else { -- cgit v1.2.3-24-g4f1b From f7d162a0784e0f5d08f55e71738bd1502d1ea8bc Mon Sep 17 00:00:00 2001 From: Greg Aker Date: Tue, 9 Nov 2010 14:52:28 -0600 Subject: Fix #95 bug in the html helper where too much white space was rendered between the src and alt tags in the img() function. --- system/helpers/html_helper.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'system') diff --git a/system/helpers/html_helper.php b/system/helpers/html_helper.php index 1c8603dbc..3010c6f8b 100644 --- a/system/helpers/html_helper.php +++ b/system/helpers/html_helper.php @@ -216,16 +216,16 @@ if ( ! function_exists('img')) if ($index_page === TRUE) { - $img .= ' src="'.$CI->config->site_url($v).'" '; + $img .= ' src="'.$CI->config->site_url($v).'"'; } else { - $img .= ' src="'.$CI->config->slash_item('base_url').$v.'" '; + $img .= ' src="'.$CI->config->slash_item('base_url').$v.'"'; } } else { - $img .= " $k=\"$v\" "; + $img .= " $k=\"$v\""; } } -- cgit v1.2.3-24-g4f1b From 485d74123d57c69d93d1c4fcd0deef7c873f4b68 Mon Sep 17 00:00:00 2001 From: Brandon Jones Date: Tue, 9 Nov 2010 16:38:17 -0500 Subject: Altered our mail() params to be inline with PHP documentation, fixes mailing on some hosts --- system/libraries/Email.php | 120 +++++++++++++++++++++------------------------ 1 file changed, 56 insertions(+), 64 deletions(-) (limited to 'system') diff --git a/system/libraries/Email.php b/system/libraries/Email.php index 6c0309b0d..043e14bc4 100644 --- a/system/libraries/Email.php +++ b/system/libraries/Email.php @@ -981,6 +981,7 @@ class CI_Email { $this->_write_headers(); $hdr = ($this->_get_protocol() == 'mail') ? $this->newline : ''; + $body = ''; switch ($this->_get_content_type()) { @@ -993,13 +994,12 @@ class CI_Email { { $this->_header_str .= $hdr; $this->_finalbody = $this->_body; - - return; } - - $hdr .= $this->newline . $this->newline . $this->_body; - - $this->_finalbody = $hdr; + else + { + $this->_finalbody = $hdr . $this->newline . $this->newline . $this->_body; + } + return; break; @@ -1013,93 +1013,81 @@ class CI_Email { else { $hdr .= "Content-Type: multipart/alternative; boundary=\"" . $this->_alt_boundary . "\"" . $this->newline . $this->newline; - $hdr .= $this->_get_mime_message() . $this->newline . $this->newline; - $hdr .= "--" . $this->_alt_boundary . $this->newline; - $hdr .= "Content-Type: text/plain; charset=" . $this->charset . $this->newline; - $hdr .= "Content-Transfer-Encoding: " . $this->_get_encoding() . $this->newline . $this->newline; - $hdr .= $this->_get_alt_message() . $this->newline . $this->newline . "--" . $this->_alt_boundary . $this->newline; + $body .= $this->_get_mime_message() . $this->newline . $this->newline; + $body .= "--" . $this->_alt_boundary . $this->newline; - $hdr .= "Content-Type: text/html; charset=" . $this->charset . $this->newline; - $hdr .= "Content-Transfer-Encoding: quoted-printable"; - } - - $this->_body = $this->_prep_quoted_printable($this->_body); + $body .= "Content-Type: text/plain; charset=" . $this->charset . $this->newline; + $body .= "Content-Transfer-Encoding: " . $this->_get_encoding() . $this->newline . $this->newline; + $body .= $this->_get_alt_message() . $this->newline . $this->newline . "--" . $this->_alt_boundary . $this->newline; + $body .= "Content-Type: text/html; charset=" . $this->charset . $this->newline; + $body .= "Content-Transfer-Encoding: quoted-printable" . $this->newline . $this->newline; + } + + $this->_finalbody = $body . $this->_prep_quoted_printable($this->_body) . $this->newline . $this->newline; + + if ($this->_get_protocol() == 'mail') { $this->_header_str .= $hdr; - $this->_finalbody = $this->_body . $this->newline . $this->newline; - - if ($this->send_multipart !== FALSE) - { - $this->_finalbody .= "--" . $this->_alt_boundary . "--"; - } - - return; + } + else + { + $this->_finalbody = $hdr . $this->_finalbody; } - $hdr .= $this->newline . $this->newline; - $hdr .= $this->_body . $this->newline . $this->newline; if ($this->send_multipart !== FALSE) { - $hdr .= "--" . $this->_alt_boundary . "--"; + $this->_finalbody .= "--" . $this->_alt_boundary . "--"; } - $this->_finalbody = $hdr; return; break; case 'plain-attach' : $hdr .= "Content-Type: multipart/".$this->multipart."; boundary=\"" . $this->_atc_boundary."\"" . $this->newline . $this->newline; - $hdr .= $this->_get_mime_message() . $this->newline . $this->newline; - $hdr .= "--" . $this->_atc_boundary . $this->newline; - - $hdr .= "Content-Type: text/plain; charset=" . $this->charset . $this->newline; - $hdr .= "Content-Transfer-Encoding: " . $this->_get_encoding(); if ($this->_get_protocol() == 'mail') { $this->_header_str .= $hdr; + } + + $body .= $this->_get_mime_message() . $this->newline . $this->newline; + $body .= "--" . $this->_atc_boundary . $this->newline; - $body = $this->_body . $this->newline . $this->newline; - } + $body .= "Content-Type: text/plain; charset=" . $this->charset . $this->newline; + $body .= "Content-Transfer-Encoding: " . $this->_get_encoding() . $this->newline . $this->newline; - $hdr .= $this->newline . $this->newline; - $hdr .= $this->_body . $this->newline . $this->newline; + $body .= $this->_body . $this->newline . $this->newline; break; case 'html-attach' : $hdr .= "Content-Type: multipart/".$this->multipart."; boundary=\"" . $this->_atc_boundary."\"" . $this->newline . $this->newline; - $hdr .= $this->_get_mime_message() . $this->newline . $this->newline; - $hdr .= "--" . $this->_atc_boundary . $this->newline; - - $hdr .= "Content-Type: multipart/alternative; boundary=\"" . $this->_alt_boundary . "\"" . $this->newline .$this->newline; - $hdr .= "--" . $this->_alt_boundary . $this->newline; - - $hdr .= "Content-Type: text/plain; charset=" . $this->charset . $this->newline; - $hdr .= "Content-Transfer-Encoding: " . $this->_get_encoding() . $this->newline . $this->newline; - $hdr .= $this->_get_alt_message() . $this->newline . $this->newline . "--" . $this->_alt_boundary . $this->newline; - - $hdr .= "Content-Type: text/html; charset=" . $this->charset . $this->newline; - $hdr .= "Content-Transfer-Encoding: quoted-printable"; - - $this->_body = $this->_prep_quoted_printable($this->_body); - + if ($this->_get_protocol() == 'mail') { $this->_header_str .= $hdr; - - $body = $this->_body . $this->newline . $this->newline; - $body .= "--" . $this->_alt_boundary . "--" . $this->newline . $this->newline; } - $hdr .= $this->newline . $this->newline; - $hdr .= $this->_body . $this->newline . $this->newline; - $hdr .= "--" . $this->_alt_boundary . "--" . $this->newline . $this->newline; + $body .= $this->_get_mime_message() . $this->newline . $this->newline; + $body .= "--" . $this->_atc_boundary . $this->newline; + + $body .= "Content-Type: multipart/alternative; boundary=\"" . $this->_alt_boundary . "\"" . $this->newline .$this->newline; + $body .= "--" . $this->_alt_boundary . $this->newline; + + $body .= "Content-Type: text/plain; charset=" . $this->charset . $this->newline; + $body .= "Content-Transfer-Encoding: " . $this->_get_encoding() . $this->newline . $this->newline; + $body .= $this->_get_alt_message() . $this->newline . $this->newline . "--" . $this->_alt_boundary . $this->newline; + + $body .= "Content-Type: text/html; charset=" . $this->charset . $this->newline; + $body .= "Content-Transfer-Encoding: quoted-printable" . $this->newline . $this->newline; + + $body .= $this->_prep_quoted_printable($this->_body) . $this->newline . $this->newline; + $body .= "--" . $this->_alt_boundary . "--" . $this->newline . $this->newline; break; } @@ -1139,15 +1127,18 @@ class CI_Email { fclose($fp); } + $body .= implode($this->newline, $attachment).$this->newline."--".$this->_atc_boundary."--"; + + if ($this->_get_protocol() == 'mail') { - $this->_finalbody = $body . implode($this->newline, $attachment).$this->newline."--".$this->_atc_boundary."--"; - - return; + $this->_finalbody = $body; } - - $this->_finalbody = $hdr.implode($this->newline, $attachment).$this->newline."--".$this->_atc_boundary."--"; - + else + { + $this->_finalbody = $hdr . $body; + } + return; } @@ -1518,6 +1509,7 @@ class CI_Email { { // most documentation of sendmail using the "-f" flag lacks a space after it, however // we've encountered servers that seem to require it to be in place. + if ( ! mail($this->_recipients, $this->_subject, $this->_finalbody, $this->_header_str, "-f ".$this->clean_email($this->_headers['From']))) { return FALSE; -- cgit v1.2.3-24-g4f1b From 287781e13232b9d8289e14b4f9642d088ed13d01 Mon Sep 17 00:00:00 2001 From: Pascal Kriete Date: Wed, 10 Nov 2010 15:43:49 -0500 Subject: Removing _assign_to_models and _assign_libraries from model related code in favor of __get(). --- system/core/Loader.php | 39 ++------------------------------------- system/core/Model.php | 40 ++++++---------------------------------- 2 files changed, 8 insertions(+), 71 deletions(-) (limited to 'system') diff --git a/system/core/Loader.php b/system/core/Loader.php index e2970613b..2324eca1e 100644 --- a/system/core/Loader.php +++ b/system/core/Loader.php @@ -109,8 +109,6 @@ class CI_Loader { { $this->_ci_load_class($library, $params, $object_name); } - - $this->_ci_assign_to_models(); } // -------------------------------------------------------------------- @@ -182,7 +180,9 @@ class CI_Loader { if ($db_conn !== FALSE AND ! class_exists('CI_DB')) { if ($db_conn === TRUE) + { $db_conn = ''; + } $CI->load->database($db_conn, FALSE, TRUE); } @@ -197,7 +197,6 @@ class CI_Loader { $model = ucfirst($model); $CI->$name = new $model(); - $CI->$name->_assign_libraries(); $this->_ci_models[] = $name; return; @@ -242,9 +241,6 @@ class CI_Loader { // Load the DB class $CI->db =& DB($params, $active_record); - - // Assign the DB object to any existing models - $this->_ci_assign_to_models(); } // -------------------------------------------------------------------- @@ -273,8 +269,6 @@ class CI_Loader { $class = 'CI_DB_'.$CI->db->dbdriver.'_utility'; $CI->dbutil =& instantiate_class(new $class()); - - $CI->load->_ci_assign_to_models(); } // -------------------------------------------------------------------- @@ -299,8 +293,6 @@ class CI_Loader { $class = 'CI_DB_'.$CI->db->dbdriver.'_forge'; $CI->dbforge = new $class(); - - $CI->load->_ci_assign_to_models(); } // -------------------------------------------------------------------- @@ -1005,33 +997,6 @@ class CI_Loader { { $this->model($autoload['model']); } - - } - - // -------------------------------------------------------------------- - - /** - * Assign to Models - * - * Makes sure that anything loaded by the loader class (libraries, etc.) - * will be available to models, if any exist. - * - * @access private - * @param object - * @return array - */ - function _ci_assign_to_models() - { - if (count($this->_ci_models) == 0) - { - return; - } - - foreach($this->_ci_models as $model) - { - $model = $this->_ci_get_component($model); - $model->_assign_libraries(); - } } // -------------------------------------------------------------------- diff --git a/system/core/Model.php b/system/core/Model.php index ebbb0fbe6..f6098d0cf 100644 --- a/system/core/Model.php +++ b/system/core/Model.php @@ -26,57 +26,29 @@ */ class CI_Model { - var $_parent_name = ''; - /** * Constructor * * @access public */ - function CI_Model() + function __construct() { - // If the magic __get() or __set() methods are used in a Model references can't be used. - $this->_assign_libraries( (method_exists($this, '__get') OR method_exists($this, '__set')) ? FALSE : TRUE ); - - // We don't want to assign the model object to itself when using the - // assign_libraries function below so we'll grab the name of the model parent - $this->_parent_name = ucfirst(get_class($this)); - log_message('debug', "Model Class Initialized"); } /** - * Assign Libraries + * __get * - * Creates local references to all currently instantiated objects - * so that any syntax that can be legally used in a controller - * can be used within models. + * Allows models to access CI's loaded classes using the same + * syntax as controllers. * * @access private */ - function _assign_libraries($use_reference = TRUE) + function __get($key) { $CI =& get_instance(); - foreach (array_keys(get_object_vars($CI)) as $key) - { - if ( ! isset($this->$key) AND $key != $this->_parent_name) - { - // In some cases using references can cause - // problems so we'll conditionally use them - if ($use_reference == TRUE) - { - // Needed to prevent reference errors with some configurations - $this->$key = ''; - $this->$key =& $CI->$key; - } - else - { - $this->$key = $CI->$key; - } - } - } + return $CI->$key; } - } // END Model Class -- cgit v1.2.3-24-g4f1b From 4abfa686ca53177b7dbbb7e1bac3febbbe27ec0f Mon Sep 17 00:00:00 2001 From: Greg Aker Date: Wed, 10 Nov 2010 14:44:26 -0600 Subject: Blasting the Base4/5 files. Updating Controller.php to inherit bits from the old Base5. If a constructor is needed in a controller, call parent::__contruct() --- system/core/Base4.php | 70 --------------------------------------------- system/core/Base5.php | 57 ------------------------------------ system/core/CodeIgniter.php | 20 ++++--------- system/core/Controller.php | 40 +++++++++----------------- 4 files changed, 18 insertions(+), 169 deletions(-) delete mode 100644 system/core/Base4.php delete mode 100644 system/core/Base5.php (limited to 'system') diff --git a/system/core/Base4.php b/system/core/Base4.php deleted file mode 100644 index ef7838d69..000000000 --- a/system/core/Base4.php +++ /dev/null @@ -1,70 +0,0 @@ -load->library('email') to instantiate - * classes that can then be used within controllers as $this->email->send() - * - * PHP 4 also has trouble referencing the CI super object within application - * constructors since objects do not exist until the class is fully - * instantiated. Basically PHP 4 sucks... - * - * Since PHP 5 doesn't suffer from this problem so we load one of - * two files based on the version of PHP being run. - * @PHP4 - * - * @package CodeIgniter - * @subpackage codeigniter - * @category front-controller - * @author ExpressionEngine Dev Team - * @link http://codeigniter.com/user_guide/ - */ - class CI_Base extends CI_Loader { - - function CI_Base() - { - // This allows syntax like $this->load->foo() to work - parent::CI_Loader(); - $this->load =& $this; - - // This allows resources used within controller constructors to work - global $OBJ; - $OBJ = $this->load; // Do NOT use a reference. - } -} - -function &get_instance() -{ - global $CI, $OBJ; - - if (is_object($CI)) - { - return $CI; - } - - return $OBJ->load; -} - - -/* End of file Base4.php */ -/* Location: ./system/core/Base4.php */ \ No newline at end of file diff --git a/system/core/Base5.php b/system/core/Base5.php deleted file mode 100644 index ac6c7f020..000000000 --- a/system/core/Base5.php +++ /dev/null @@ -1,57 +0,0 @@ -config['subclass_prefix'].'Controller'.EXT)) { diff --git a/system/core/Controller.php b/system/core/Controller.php index e250caf4b..c78be8724 100644 --- a/system/core/Controller.php +++ b/system/core/Controller.php @@ -2,7 +2,7 @@ /** * CodeIgniter * - * An open source application development framework for PHP 4.3.2 or newer + * An open source application development framework for PHP 5.1.6 or newer * * @package CodeIgniter * @author ExpressionEngine Dev Team @@ -27,16 +27,16 @@ * @author ExpressionEngine Dev Team * @link http://codeigniter.com/user_guide/general/controllers.html */ -class CI_Controller extends CI_Base { +class CI_Controller { + + private static $instance; /** * Constructor - * - * Calls the initialize() function */ - function CI_Controller() + public function __construct() { - parent::CI_Base(); + self::$instance =& $this; // Assign all the class objects that were instantiated by the // bootstrap file (CodeIgniter.php) to local class variables @@ -46,34 +46,20 @@ class CI_Controller extends CI_Base { $this->$var =& load_class($class); } - // In PHP 5 the Loader class is run as a discreet - // class. In PHP 4 it extends the Controller @PHP4 - if (is_php('5.0.0') == TRUE) - { - $this->load =& load_class('Loader', 'core'); - - $this->load->_base_classes =& is_loaded(); + $this->load =& load_class('Loader', 'core'); - $this->load->_ci_autoloader(); - } - else - { - $this->_ci_autoloader(); + $this->load->_base_classes =& is_loaded(); - // sync up the objects since PHP4 was working from a copy - foreach (array_keys(get_object_vars($this)) as $attribute) - { - if (is_object($this->$attribute)) - { - $this->load->$attribute =& $this->$attribute; - } - } - } + $this->load->_ci_autoloader(); log_message('debug', "Controller Class Initialized"); } + public static function &get_instance() + { + return self::$instance; + } } // END Controller class -- cgit v1.2.3-24-g4f1b From 3791853fa72c53062fd72b249efc733b311b3a80 Mon Sep 17 00:00:00 2001 From: Greg Aker Date: Wed, 10 Nov 2010 14:47:06 -0600 Subject: Removing the core/Compat.php file. :: poof :: --- system/core/Compat.php | 99 -------------------------------------------------- 1 file changed, 99 deletions(-) delete mode 100644 system/core/Compat.php (limited to 'system') diff --git a/system/core/Compat.php b/system/core/Compat.php deleted file mode 100644 index bd11b9836..000000000 --- a/system/core/Compat.php +++ /dev/null @@ -1,99 +0,0 @@ - Date: Wed, 10 Nov 2010 15:49:10 -0500 Subject: Removing _ci_is_instance from the loader. --- system/core/Loader.php | 44 ++++++-------------------------------------- 1 file changed, 6 insertions(+), 38 deletions(-) (limited to 'system') diff --git a/system/core/Loader.php b/system/core/Loader.php index 2324eca1e..57b05ab3e 100644 --- a/system/core/Loader.php +++ b/system/core/Loader.php @@ -34,7 +34,6 @@ class CI_Loader { var $_ci_library_paths = array(); var $_ci_model_paths = array(); var $_ci_helper_paths = array(); - var $_ci_is_instance = FALSE; // Whether we should use $this or $CI =& get_instance() var $_base_classes = array(); // Set by the controller class var $_ci_cached_vars = array(); var $_ci_classes = array(); @@ -627,17 +626,13 @@ class CI_Loader { // This allows anything loaded using $this->load (views, files, etc.) // to become accessible from within the Controller and Model functions. - // Only needed when running PHP 5 - if ($this->_ci_is_instance()) + $_ci_CI =& get_instance(); + foreach (get_object_vars($_ci_CI) as $_ci_key => $_ci_var) { - $_ci_CI =& get_instance(); - foreach (get_object_vars($_ci_CI) as $_ci_key => $_ci_var) + if ( ! isset($this->$_ci_key)) { - if ( ! isset($this->$_ci_key)) - { - $this->$_ci_key =& $_ci_CI->$_ci_key; - } + $this->$_ci_key =& $_ci_CI->$_ci_key; } } @@ -1017,26 +1012,6 @@ class CI_Loader { // -------------------------------------------------------------------- - /** - * Determines whether we should use the CI instance or $this - * @PHP4 - * - * @access private - * @return bool - */ - function _ci_is_instance() - { - if (is_php('5.0.0') == TRUE) - { - return TRUE; - } - - global $CI; - return (is_object($CI)) ? TRUE : FALSE; - } - - // -------------------------------------------------------------------- - /** * Get a reference to a specific library or model * @@ -1045,15 +1020,8 @@ class CI_Loader { */ function &_ci_get_component($component) { - if ($this->_ci_is_instance()) - { - $CI =& get_instance(); - return $CI->$component; - } - else - { - return $this->$component; - } + $CI =& get_instance(); + return $CI->$component; } // -------------------------------------------------------------------- -- cgit v1.2.3-24-g4f1b From 741de1c1319dd13de75348863cca591713dd46ce Mon Sep 17 00:00:00 2001 From: Greg Aker Date: Wed, 10 Nov 2010 14:52:57 -0600 Subject: Updating PHP requirements in files 5.1.6 --- system/core/Benchmark.php | 2 +- system/core/CodeIgniter.php | 2 +- system/core/Common.php | 2 +- system/core/Config.php | 2 +- system/core/Exceptions.php | 2 +- system/core/Hooks.php | 2 +- system/core/Input.php | 2 +- system/core/Lang.php | 2 +- system/core/Loader.php | 2 +- system/core/Model.php | 2 +- system/core/Output.php | 2 +- system/core/Router.php | 2 +- system/core/URI.php | 2 +- system/core/Unicode.php | 2 +- system/database/DB.php | 2 +- system/database/DB_active_rec.php | 2 +- system/database/DB_cache.php | 2 +- system/database/DB_driver.php | 2 +- system/database/DB_forge.php | 2 +- system/database/DB_result.php | 2 +- system/database/DB_utility.php | 2 +- system/database/drivers/mssql/mssql_driver.php | 2 +- system/database/drivers/mssql/mssql_forge.php | 2 +- system/database/drivers/mssql/mssql_result.php | 2 +- system/database/drivers/mssql/mssql_utility.php | 2 +- system/database/drivers/mysql/mysql_driver.php | 2 +- system/database/drivers/mysql/mysql_forge.php | 2 +- system/database/drivers/mysql/mysql_result.php | 2 +- system/database/drivers/mysql/mysql_utility.php | 2 +- system/database/drivers/mysqli/mysqli_driver.php | 2 +- system/database/drivers/mysqli/mysqli_forge.php | 2 +- system/database/drivers/mysqli/mysqli_result.php | 2 +- system/database/drivers/mysqli/mysqli_utility.php | 2 +- system/database/drivers/oci8/oci8_driver.php | 2 +- system/database/drivers/oci8/oci8_forge.php | 2 +- system/database/drivers/oci8/oci8_result.php | 2 +- system/database/drivers/oci8/oci8_utility.php | 2 +- system/database/drivers/odbc/odbc_driver.php | 2 +- system/database/drivers/odbc/odbc_forge.php | 2 +- system/database/drivers/odbc/odbc_result.php | 2 +- system/database/drivers/odbc/odbc_utility.php | 2 +- system/database/drivers/postgre/postgre_driver.php | 2 +- system/database/drivers/postgre/postgre_forge.php | 2 +- system/database/drivers/postgre/postgre_result.php | 2 +- system/database/drivers/postgre/postgre_utility.php | 2 +- system/database/drivers/sqlite/sqlite_driver.php | 2 +- system/database/drivers/sqlite/sqlite_forge.php | 2 +- system/database/drivers/sqlite/sqlite_result.php | 2 +- system/database/drivers/sqlite/sqlite_utility.php | 2 +- system/helpers/array_helper.php | 2 +- system/helpers/captcha_helper.php | 2 +- system/helpers/compatibility_helper.php | 2 +- system/helpers/cookie_helper.php | 2 +- system/helpers/date_helper.php | 2 +- system/helpers/directory_helper.php | 2 +- system/helpers/download_helper.php | 2 +- system/helpers/email_helper.php | 2 +- system/helpers/file_helper.php | 2 +- system/helpers/form_helper.php | 2 +- system/helpers/html_helper.php | 2 +- system/helpers/inflector_helper.php | 2 +- system/helpers/language_helper.php | 2 +- system/helpers/number_helper.php | 2 +- system/helpers/path_helper.php | 2 +- system/helpers/security_helper.php | 2 +- system/helpers/smiley_helper.php | 2 +- system/helpers/string_helper.php | 2 +- system/helpers/text_helper.php | 2 +- system/helpers/typography_helper.php | 2 +- system/helpers/url_helper.php | 2 +- system/helpers/xml_helper.php | 2 +- system/libraries/Calendar.php | 2 +- system/libraries/Cart.php | 2 +- system/libraries/Driver.php | 2 +- system/libraries/Email.php | 2 +- system/libraries/Encrypt.php | 2 +- system/libraries/Form_validation.php | 2 +- system/libraries/Ftp.php | 2 +- system/libraries/Image_lib.php | 2 +- system/libraries/Javascript.php | 2 +- system/libraries/Log.php | 2 +- system/libraries/Pagination.php | 2 +- system/libraries/Parser.php | 2 +- system/libraries/Profiler.php | 2 +- system/libraries/Security.php | 2 +- system/libraries/Session.php | 2 +- system/libraries/Sha1.php | 2 +- system/libraries/Table.php | 2 +- system/libraries/Trackback.php | 2 +- system/libraries/Typography.php | 2 +- system/libraries/Unit_test.php | 2 +- system/libraries/Upload.php | 2 +- system/libraries/User_agent.php | 2 +- system/libraries/Xmlrpc.php | 2 +- system/libraries/Xmlrpcs.php | 2 +- system/libraries/Zip.php | 2 +- 96 files changed, 96 insertions(+), 96 deletions(-) (limited to 'system') diff --git a/system/core/Benchmark.php b/system/core/Benchmark.php index 80933f424..d0e1fc683 100644 --- a/system/core/Benchmark.php +++ b/system/core/Benchmark.php @@ -2,7 +2,7 @@ /** * CodeIgniter * - * An open source application development framework for PHP 4.3.2 or newer + * An open source application development framework for PHP 5.1.6 or newer * * @package CodeIgniter * @author ExpressionEngine Dev Team diff --git a/system/core/CodeIgniter.php b/system/core/CodeIgniter.php index c50ae6d2b..be5a27120 100644 --- a/system/core/CodeIgniter.php +++ b/system/core/CodeIgniter.php @@ -2,7 +2,7 @@ /** * CodeIgniter * - * An open source application development framework for PHP 4.3.2 or newer + * An open source application development framework for PHP 5.1.6 or newer * * @package CodeIgniter * @author ExpressionEngine Dev Team diff --git a/system/core/Common.php b/system/core/Common.php index 90ba7c963..56fe713bd 100644 --- a/system/core/Common.php +++ b/system/core/Common.php @@ -2,7 +2,7 @@ /** * CodeIgniter * - * An open source application development framework for PHP 4.3.2 or newer + * An open source application development framework for PHP 5.1.6 or newer * * @package CodeIgniter * @author ExpressionEngine Dev Team diff --git a/system/core/Config.php b/system/core/Config.php index 24503ab5d..b7055c6c9 100644 --- a/system/core/Config.php +++ b/system/core/Config.php @@ -2,7 +2,7 @@ /** * CodeIgniter * - * An open source application development framework for PHP 4.3.2 or newer + * An open source application development framework for PHP 5.1.6 or newer * * @package CodeIgniter * @author ExpressionEngine Dev Team diff --git a/system/core/Exceptions.php b/system/core/Exceptions.php index 108861de7..26b24ef17 100644 --- a/system/core/Exceptions.php +++ b/system/core/Exceptions.php @@ -2,7 +2,7 @@ /** * CodeIgniter * - * An open source application development framework for PHP 4.3.2 or newer + * An open source application development framework for PHP 5.1.6 or newer * * @package CodeIgniter * @author ExpressionEngine Dev Team diff --git a/system/core/Hooks.php b/system/core/Hooks.php index 9026a5eb6..3f841943c 100644 --- a/system/core/Hooks.php +++ b/system/core/Hooks.php @@ -2,7 +2,7 @@ /** * CodeIgniter * - * An open source application development framework for PHP 4.3.2 or newer + * An open source application development framework for PHP 5.1.6 or newer * * @package CodeIgniter * @author ExpressionEngine Dev Team diff --git a/system/core/Input.php b/system/core/Input.php index df3be207c..f959b2890 100644 --- a/system/core/Input.php +++ b/system/core/Input.php @@ -2,7 +2,7 @@ /** * CodeIgniter * - * An open source application development framework for PHP 4.3.2 or newer + * An open source application development framework for PHP 5.1.6 or newer * * @package CodeIgniter * @author ExpressionEngine Dev Team diff --git a/system/core/Lang.php b/system/core/Lang.php index cbd4e38b8..a53a20215 100644 --- a/system/core/Lang.php +++ b/system/core/Lang.php @@ -2,7 +2,7 @@ /** * CodeIgniter * - * An open source application development framework for PHP 4.3.2 or newer + * An open source application development framework for PHP 5.1.6 or newer * * @package CodeIgniter * @author ExpressionEngine Dev Team diff --git a/system/core/Loader.php b/system/core/Loader.php index 2324eca1e..3fc9d4c4a 100644 --- a/system/core/Loader.php +++ b/system/core/Loader.php @@ -2,7 +2,7 @@ /** * CodeIgniter * - * An open source application development framework for PHP 4.3.2 or newer + * An open source application development framework for PHP 5.1.6 or newer * * @package CodeIgniter * @author ExpressionEngine Dev Team diff --git a/system/core/Model.php b/system/core/Model.php index f6098d0cf..80f4b04a1 100644 --- a/system/core/Model.php +++ b/system/core/Model.php @@ -2,7 +2,7 @@ /** * CodeIgniter * - * An open source application development framework for PHP 4.3.2 or newer + * An open source application development framework for PHP 5.1.6 or newer * * @package CodeIgniter * @author ExpressionEngine Dev Team diff --git a/system/core/Output.php b/system/core/Output.php index 04e452d2c..2ded2837e 100644 --- a/system/core/Output.php +++ b/system/core/Output.php @@ -2,7 +2,7 @@ /** * CodeIgniter * - * An open source application development framework for PHP 4.3.2 or newer + * An open source application development framework for PHP 5.1.6 or newer * * @package CodeIgniter * @author ExpressionEngine Dev Team diff --git a/system/core/Router.php b/system/core/Router.php index 918ea24bf..06c8d4846 100644 --- a/system/core/Router.php +++ b/system/core/Router.php @@ -2,7 +2,7 @@ /** * CodeIgniter * - * An open source application development framework for PHP 4.3.2 or newer + * An open source application development framework for PHP 5.1.6 or newer * * @package CodeIgniter * @author ExpressionEngine Dev Team diff --git a/system/core/URI.php b/system/core/URI.php index a3bd45091..b8d48c578 100644 --- a/system/core/URI.php +++ b/system/core/URI.php @@ -2,7 +2,7 @@ /** * CodeIgniter * - * An open source application development framework for PHP 4.3.2 or newer + * An open source application development framework for PHP 5.1.6 or newer * * @package CodeIgniter * @author ExpressionEngine Dev Team diff --git a/system/core/Unicode.php b/system/core/Unicode.php index 3aeb51b57..20605eecb 100644 --- a/system/core/Unicode.php +++ b/system/core/Unicode.php @@ -2,7 +2,7 @@ /** * CodeIgniter * - * An open source application development framework for PHP 4.3.2 or newer + * An open source application development framework for PHP 5.1.6 or newer * * @package CodeIgniter * @author ExpressionEngine Dev Team diff --git a/system/database/DB.php b/system/database/DB.php index 1b4eb8bec..b51995b68 100644 --- a/system/database/DB.php +++ b/system/database/DB.php @@ -2,7 +2,7 @@ /** * CodeIgniter * - * An open source application development framework for PHP 4.3.2 or newer + * An open source application development framework for PHP 5.1.6 or newer * * @package CodeIgniter * @author ExpressionEngine Dev Team diff --git a/system/database/DB_active_rec.php b/system/database/DB_active_rec.php index ce50479cc..dd46981b1 100644 --- a/system/database/DB_active_rec.php +++ b/system/database/DB_active_rec.php @@ -2,7 +2,7 @@ /** * CodeIgniter * - * An open source application development framework for PHP 4.3.2 or newer + * An open source application development framework for PHP 5.1.6 or newer * * @package CodeIgniter * @author ExpressionEngine Dev Team diff --git a/system/database/DB_cache.php b/system/database/DB_cache.php index 6eff5943e..6042e0673 100644 --- a/system/database/DB_cache.php +++ b/system/database/DB_cache.php @@ -2,7 +2,7 @@ /** * CodeIgniter * - * An open source application development framework for PHP 4.3.2 or newer + * An open source application development framework for PHP 5.1.6 or newer * * @package CodeIgniter * @author ExpressionEngine Dev Team diff --git a/system/database/DB_driver.php b/system/database/DB_driver.php index cbfa33e78..7fe5695b0 100644 --- a/system/database/DB_driver.php +++ b/system/database/DB_driver.php @@ -2,7 +2,7 @@ /** * CodeIgniter * - * An open source application development framework for PHP 4.3.2 or newer + * An open source application development framework for PHP 5.1.6 or newer * * @package CodeIgniter * @author ExpressionEngine Dev Team diff --git a/system/database/DB_forge.php b/system/database/DB_forge.php index 74aed8610..f40eac82d 100644 --- a/system/database/DB_forge.php +++ b/system/database/DB_forge.php @@ -2,7 +2,7 @@ /** * Code Igniter * - * An open source application development framework for PHP 4.3.2 or newer + * An open source application development framework for PHP 5.1.6 or newer * * @package CodeIgniter * @author ExpressionEngine Dev Team diff --git a/system/database/DB_result.php b/system/database/DB_result.php index 406afb1b8..05f06af66 100644 --- a/system/database/DB_result.php +++ b/system/database/DB_result.php @@ -2,7 +2,7 @@ /** * CodeIgniter * - * An open source application development framework for PHP 4.3.2 or newer + * An open source application development framework for PHP 5.1.6 or newer * * @package CodeIgniter * @author ExpressionEngine Dev Team diff --git a/system/database/DB_utility.php b/system/database/DB_utility.php index 2811d8802..c4d537a3b 100644 --- a/system/database/DB_utility.php +++ b/system/database/DB_utility.php @@ -2,7 +2,7 @@ /** * Code Igniter * - * An open source application development framework for PHP 4.3.2 or newer + * An open source application development framework for PHP 5.1.6 or newer * * @package CodeIgniter * @author ExpressionEngine Dev Team diff --git a/system/database/drivers/mssql/mssql_driver.php b/system/database/drivers/mssql/mssql_driver.php index 63f9e9cc3..eade10ee8 100644 --- a/system/database/drivers/mssql/mssql_driver.php +++ b/system/database/drivers/mssql/mssql_driver.php @@ -2,7 +2,7 @@ /** * CodeIgniter * - * An open source application development framework for PHP 4.3.2 or newer + * An open source application development framework for PHP 5.1.6 or newer * * @package CodeIgniter * @author ExpressionEngine Dev Team diff --git a/system/database/drivers/mssql/mssql_forge.php b/system/database/drivers/mssql/mssql_forge.php index 5aa4406b1..6b02e1eb2 100644 --- a/system/database/drivers/mssql/mssql_forge.php +++ b/system/database/drivers/mssql/mssql_forge.php @@ -2,7 +2,7 @@ /** * CodeIgniter * - * An open source application development framework for PHP 4.3.2 or newer + * An open source application development framework for PHP 5.1.6 or newer * * @package CodeIgniter * @author ExpressionEngine Dev Team diff --git a/system/database/drivers/mssql/mssql_result.php b/system/database/drivers/mssql/mssql_result.php index 09b1ec80b..c0a20dbde 100644 --- a/system/database/drivers/mssql/mssql_result.php +++ b/system/database/drivers/mssql/mssql_result.php @@ -2,7 +2,7 @@ /** * CodeIgniter * - * An open source application development framework for PHP 4.3.2 or newer + * An open source application development framework for PHP 5.1.6 or newer * * @package CodeIgniter * @author ExpressionEngine Dev Team diff --git a/system/database/drivers/mssql/mssql_utility.php b/system/database/drivers/mssql/mssql_utility.php index e58c7e0c3..b867dd7b1 100644 --- a/system/database/drivers/mssql/mssql_utility.php +++ b/system/database/drivers/mssql/mssql_utility.php @@ -2,7 +2,7 @@ /** * CodeIgniter * - * An open source application development framework for PHP 4.3.2 or newer + * An open source application development framework for PHP 5.1.6 or newer * * @package CodeIgniter * @author ExpressionEngine Dev Team diff --git a/system/database/drivers/mysql/mysql_driver.php b/system/database/drivers/mysql/mysql_driver.php index cb985a764..f27a1eef6 100644 --- a/system/database/drivers/mysql/mysql_driver.php +++ b/system/database/drivers/mysql/mysql_driver.php @@ -2,7 +2,7 @@ /** * CodeIgniter * - * An open source application development framework for PHP 4.3.2 or newer + * An open source application development framework for PHP 5.1.6 or newer * * @package CodeIgniter * @author ExpressionEngine Dev Team diff --git a/system/database/drivers/mysql/mysql_forge.php b/system/database/drivers/mysql/mysql_forge.php index 973f32dcb..8faf69550 100644 --- a/system/database/drivers/mysql/mysql_forge.php +++ b/system/database/drivers/mysql/mysql_forge.php @@ -2,7 +2,7 @@ /** * CodeIgniter * - * An open source application development framework for PHP 4.3.2 or newer + * An open source application development framework for PHP 5.1.6 or newer * * @package CodeIgniter * @author ExpressionEngine Dev Team diff --git a/system/database/drivers/mysql/mysql_result.php b/system/database/drivers/mysql/mysql_result.php index 0140ec647..c3aa4ccd7 100644 --- a/system/database/drivers/mysql/mysql_result.php +++ b/system/database/drivers/mysql/mysql_result.php @@ -2,7 +2,7 @@ /** * CodeIgniter * - * An open source application development framework for PHP 4.3.2 or newer + * An open source application development framework for PHP 5.1.6 or newer * * @package CodeIgniter * @author ExpressionEngine Dev Team diff --git a/system/database/drivers/mysql/mysql_utility.php b/system/database/drivers/mysql/mysql_utility.php index 3b574c6f4..1259fee6f 100644 --- a/system/database/drivers/mysql/mysql_utility.php +++ b/system/database/drivers/mysql/mysql_utility.php @@ -2,7 +2,7 @@ /** * CodeIgniter * - * An open source application development framework for PHP 4.3.2 or newer + * An open source application development framework for PHP 5.1.6 or newer * * @package CodeIgniter * @author ExpressionEngine Dev Team diff --git a/system/database/drivers/mysqli/mysqli_driver.php b/system/database/drivers/mysqli/mysqli_driver.php index 69e092839..b50fe5f77 100644 --- a/system/database/drivers/mysqli/mysqli_driver.php +++ b/system/database/drivers/mysqli/mysqli_driver.php @@ -2,7 +2,7 @@ /** * CodeIgniter * - * An open source application development framework for PHP 4.3.2 or newer + * An open source application development framework for PHP 5.1.6 or newer * * @package CodeIgniter * @author ExpressionEngine Dev Team diff --git a/system/database/drivers/mysqli/mysqli_forge.php b/system/database/drivers/mysqli/mysqli_forge.php index 85491a873..5d5b78089 100644 --- a/system/database/drivers/mysqli/mysqli_forge.php +++ b/system/database/drivers/mysqli/mysqli_forge.php @@ -2,7 +2,7 @@ /** * CodeIgniter * - * An open source application development framework for PHP 4.3.2 or newer + * An open source application development framework for PHP 5.1.6 or newer * * @package CodeIgniter * @author ExpressionEngine Dev Team diff --git a/system/database/drivers/mysqli/mysqli_result.php b/system/database/drivers/mysqli/mysqli_result.php index dd58ed878..16f57c079 100644 --- a/system/database/drivers/mysqli/mysqli_result.php +++ b/system/database/drivers/mysqli/mysqli_result.php @@ -2,7 +2,7 @@ /** * CodeIgniter * - * An open source application development framework for PHP 4.3.2 or newer + * An open source application development framework for PHP 5.1.6 or newer * * @package CodeIgniter * @author ExpressionEngine Dev Team diff --git a/system/database/drivers/mysqli/mysqli_utility.php b/system/database/drivers/mysqli/mysqli_utility.php index e0dbca7c0..84ff0daf4 100644 --- a/system/database/drivers/mysqli/mysqli_utility.php +++ b/system/database/drivers/mysqli/mysqli_utility.php @@ -2,7 +2,7 @@ /** * CodeIgniter * - * An open source application development framework for PHP 4.3.2 or newer + * An open source application development framework for PHP 5.1.6 or newer * * @package CodeIgniter * @author ExpressionEngine Dev Team diff --git a/system/database/drivers/oci8/oci8_driver.php b/system/database/drivers/oci8/oci8_driver.php index fb65ad8a1..44d5dec7e 100644 --- a/system/database/drivers/oci8/oci8_driver.php +++ b/system/database/drivers/oci8/oci8_driver.php @@ -2,7 +2,7 @@ /** * CodeIgniter * - * An open source application development framework for PHP 4.3.2 or newer + * An open source application development framework for PHP 5.1.6 or newer * * @package CodeIgniter * @author ExpressionEngine Dev Team diff --git a/system/database/drivers/oci8/oci8_forge.php b/system/database/drivers/oci8/oci8_forge.php index 1d369ae32..4bcb081b2 100644 --- a/system/database/drivers/oci8/oci8_forge.php +++ b/system/database/drivers/oci8/oci8_forge.php @@ -2,7 +2,7 @@ /** * CodeIgniter * - * An open source application development framework for PHP 4.3.2 or newer + * An open source application development framework for PHP 5.1.6 or newer * * @package CodeIgniter * @author ExpressionEngine Dev Team diff --git a/system/database/drivers/oci8/oci8_result.php b/system/database/drivers/oci8/oci8_result.php index 647ec6e43..058524f4c 100644 --- a/system/database/drivers/oci8/oci8_result.php +++ b/system/database/drivers/oci8/oci8_result.php @@ -2,7 +2,7 @@ /** * CodeIgniter * - * An open source application development framework for PHP 4.3.2 or newer + * An open source application development framework for PHP 5.1.6 or newer * * @package CodeIgniter * @author ExpressionEngine Dev Team diff --git a/system/database/drivers/oci8/oci8_utility.php b/system/database/drivers/oci8/oci8_utility.php index cc1793531..48d4acec8 100644 --- a/system/database/drivers/oci8/oci8_utility.php +++ b/system/database/drivers/oci8/oci8_utility.php @@ -2,7 +2,7 @@ /** * CodeIgniter * - * An open source application development framework for PHP 4.3.2 or newer + * An open source application development framework for PHP 5.1.6 or newer * * @package CodeIgniter * @author ExpressionEngine Dev Team diff --git a/system/database/drivers/odbc/odbc_driver.php b/system/database/drivers/odbc/odbc_driver.php index 0e2c7de5f..af90f0c7a 100644 --- a/system/database/drivers/odbc/odbc_driver.php +++ b/system/database/drivers/odbc/odbc_driver.php @@ -2,7 +2,7 @@ /** * CodeIgniter * - * An open source application development framework for PHP 4.3.2 or newer + * An open source application development framework for PHP 5.1.6 or newer * * @package CodeIgniter * @author ExpressionEngine Dev Team diff --git a/system/database/drivers/odbc/odbc_forge.php b/system/database/drivers/odbc/odbc_forge.php index 49a2401f1..602016ad4 100644 --- a/system/database/drivers/odbc/odbc_forge.php +++ b/system/database/drivers/odbc/odbc_forge.php @@ -2,7 +2,7 @@ /** * CodeIgniter * - * An open source application development framework for PHP 4.3.2 or newer + * An open source application development framework for PHP 5.1.6 or newer * * @package CodeIgniter * @author ExpressionEngine Dev Team diff --git a/system/database/drivers/odbc/odbc_result.php b/system/database/drivers/odbc/odbc_result.php index e2dc8415f..b673464b7 100644 --- a/system/database/drivers/odbc/odbc_result.php +++ b/system/database/drivers/odbc/odbc_result.php @@ -2,7 +2,7 @@ /** * CodeIgniter * - * An open source application development framework for PHP 4.3.2 or newer + * An open source application development framework for PHP 5.1.6 or newer * * @package CodeIgniter * @author ExpressionEngine Dev Team diff --git a/system/database/drivers/odbc/odbc_utility.php b/system/database/drivers/odbc/odbc_utility.php index deeb0320a..9f9ef5a3d 100644 --- a/system/database/drivers/odbc/odbc_utility.php +++ b/system/database/drivers/odbc/odbc_utility.php @@ -2,7 +2,7 @@ /** * CodeIgniter * - * An open source application development framework for PHP 4.3.2 or newer + * An open source application development framework for PHP 5.1.6 or newer * * @package CodeIgniter * @author ExpressionEngine Dev Team diff --git a/system/database/drivers/postgre/postgre_driver.php b/system/database/drivers/postgre/postgre_driver.php index cf865432b..b61a9d75b 100644 --- a/system/database/drivers/postgre/postgre_driver.php +++ b/system/database/drivers/postgre/postgre_driver.php @@ -2,7 +2,7 @@ /** * CodeIgniter * - * An open source application development framework for PHP 4.3.2 or newer + * An open source application development framework for PHP 5.1.6 or newer * * @package CodeIgniter * @author ExpressionEngine Dev Team diff --git a/system/database/drivers/postgre/postgre_forge.php b/system/database/drivers/postgre/postgre_forge.php index 12eef2923..41858f36e 100644 --- a/system/database/drivers/postgre/postgre_forge.php +++ b/system/database/drivers/postgre/postgre_forge.php @@ -2,7 +2,7 @@ /** * CodeIgniter * - * An open source application development framework for PHP 4.3.2 or newer + * An open source application development framework for PHP 5.1.6 or newer * * @package CodeIgniter * @author ExpressionEngine Dev Team diff --git a/system/database/drivers/postgre/postgre_result.php b/system/database/drivers/postgre/postgre_result.php index b60ad7dd3..126631201 100644 --- a/system/database/drivers/postgre/postgre_result.php +++ b/system/database/drivers/postgre/postgre_result.php @@ -2,7 +2,7 @@ /** * CodeIgniter * - * An open source application development framework for PHP 4.3.2 or newer + * An open source application development framework for PHP 5.1.6 or newer * * @package CodeIgniter * @author ExpressionEngine Dev Team diff --git a/system/database/drivers/postgre/postgre_utility.php b/system/database/drivers/postgre/postgre_utility.php index 84b089af0..f04c7f083 100644 --- a/system/database/drivers/postgre/postgre_utility.php +++ b/system/database/drivers/postgre/postgre_utility.php @@ -2,7 +2,7 @@ /** * CodeIgniter * - * An open source application development framework for PHP 4.3.2 or newer + * An open source application development framework for PHP 5.1.6 or newer * * @package CodeIgniter * @author ExpressionEngine Dev Team diff --git a/system/database/drivers/sqlite/sqlite_driver.php b/system/database/drivers/sqlite/sqlite_driver.php index ea0583e9e..d6c6897c6 100644 --- a/system/database/drivers/sqlite/sqlite_driver.php +++ b/system/database/drivers/sqlite/sqlite_driver.php @@ -2,7 +2,7 @@ /** * CodeIgniter * - * An open source application development framework for PHP 4.3.2 or newer + * An open source application development framework for PHP 5.1.6 or newer * * @package CodeIgniter * @author ExpressionEngine Dev Team diff --git a/system/database/drivers/sqlite/sqlite_forge.php b/system/database/drivers/sqlite/sqlite_forge.php index 7b5c894f6..0aa5d382a 100644 --- a/system/database/drivers/sqlite/sqlite_forge.php +++ b/system/database/drivers/sqlite/sqlite_forge.php @@ -2,7 +2,7 @@ /** * CodeIgniter * - * An open source application development framework for PHP 4.3.2 or newer + * An open source application development framework for PHP 5.1.6 or newer * * @package CodeIgniter * @author ExpressionEngine Dev Team diff --git a/system/database/drivers/sqlite/sqlite_result.php b/system/database/drivers/sqlite/sqlite_result.php index fd6d83d0c..9a86aa99c 100644 --- a/system/database/drivers/sqlite/sqlite_result.php +++ b/system/database/drivers/sqlite/sqlite_result.php @@ -2,7 +2,7 @@ /** * CodeIgniter * - * An open source application development framework for PHP 4.3.2 or newer + * An open source application development framework for PHP 5.1.6 or newer * * @package CodeIgniter * @author ExpressionEngine Dev Team diff --git a/system/database/drivers/sqlite/sqlite_utility.php b/system/database/drivers/sqlite/sqlite_utility.php index 956d2130f..b76c1b366 100644 --- a/system/database/drivers/sqlite/sqlite_utility.php +++ b/system/database/drivers/sqlite/sqlite_utility.php @@ -2,7 +2,7 @@ /** * CodeIgniter * - * An open source application development framework for PHP 4.3.2 or newer + * An open source application development framework for PHP 5.1.6 or newer * * @package CodeIgniter * @author ExpressionEngine Dev Team diff --git a/system/helpers/array_helper.php b/system/helpers/array_helper.php index 447ee1aa4..47c5f103d 100644 --- a/system/helpers/array_helper.php +++ b/system/helpers/array_helper.php @@ -2,7 +2,7 @@ /** * CodeIgniter * - * An open source application development framework for PHP 4.3.2 or newer + * An open source application development framework for PHP 5.1.6 or newer * * @package CodeIgniter * @author ExpressionEngine Dev Team diff --git a/system/helpers/captcha_helper.php b/system/helpers/captcha_helper.php index 3c80bb756..0f4e68c56 100644 --- a/system/helpers/captcha_helper.php +++ b/system/helpers/captcha_helper.php @@ -2,7 +2,7 @@ /** * CodeIgniter * - * An open source application development framework for PHP 4.3.2 or newer + * An open source application development framework for PHP 5.1.6 or newer * * @package CodeIgniter * @author ExpressionEngine Dev Team diff --git a/system/helpers/compatibility_helper.php b/system/helpers/compatibility_helper.php index 912eae6e2..6770d9a3b 100644 --- a/system/helpers/compatibility_helper.php +++ b/system/helpers/compatibility_helper.php @@ -2,7 +2,7 @@ /** * CodeIgniter * - * An open source application development framework for PHP 4.3.2 or newer + * An open source application development framework for PHP 5.1.6 or newer * * @package CodeIgniter * @author ExpressionEngine Dev Team diff --git a/system/helpers/cookie_helper.php b/system/helpers/cookie_helper.php index 2821fadb1..4283bfd01 100644 --- a/system/helpers/cookie_helper.php +++ b/system/helpers/cookie_helper.php @@ -2,7 +2,7 @@ /** * CodeIgniter * - * An open source application development framework for PHP 4.3.2 or newer + * An open source application development framework for PHP 5.1.6 or newer * * @package CodeIgniter * @author ExpressionEngine Dev Team diff --git a/system/helpers/date_helper.php b/system/helpers/date_helper.php index e762be007..c8680a1d8 100644 --- a/system/helpers/date_helper.php +++ b/system/helpers/date_helper.php @@ -2,7 +2,7 @@ /** * CodeIgniter * - * An open source application development framework for PHP 4.3.2 or newer + * An open source application development framework for PHP 5.1.6 or newer * * @package CodeIgniter * @author ExpressionEngine Dev Team diff --git a/system/helpers/directory_helper.php b/system/helpers/directory_helper.php index 574a5d8b0..30aaa6177 100644 --- a/system/helpers/directory_helper.php +++ b/system/helpers/directory_helper.php @@ -2,7 +2,7 @@ /** * CodeIgniter * - * An open source application development framework for PHP 4.3.2 or newer + * An open source application development framework for PHP 5.1.6 or newer * * @package CodeIgniter * @author ExpressionEngine Dev Team diff --git a/system/helpers/download_helper.php b/system/helpers/download_helper.php index 4a17e519e..ba9c0a3ca 100644 --- a/system/helpers/download_helper.php +++ b/system/helpers/download_helper.php @@ -2,7 +2,7 @@ /** * CodeIgniter * - * An open source application development framework for PHP 4.3.2 or newer + * An open source application development framework for PHP 5.1.6 or newer * * @package CodeIgniter * @author ExpressionEngine Dev Team diff --git a/system/helpers/email_helper.php b/system/helpers/email_helper.php index 7c8a610de..b6f7437e7 100644 --- a/system/helpers/email_helper.php +++ b/system/helpers/email_helper.php @@ -2,7 +2,7 @@ /** * CodeIgniter * - * An open source application development framework for PHP 4.3.2 or newer + * An open source application development framework for PHP 5.1.6 or newer * * @package CodeIgniter * @author ExpressionEngine Dev Team diff --git a/system/helpers/file_helper.php b/system/helpers/file_helper.php index c1ac167a0..9b9f9dca2 100644 --- a/system/helpers/file_helper.php +++ b/system/helpers/file_helper.php @@ -2,7 +2,7 @@ /** * CodeIgniter * - * An open source application development framework for PHP 4.3.2 or newer + * An open source application development framework for PHP 5.1.6 or newer * * @package CodeIgniter * @author ExpressionEngine Dev Team diff --git a/system/helpers/form_helper.php b/system/helpers/form_helper.php index e722a0758..b9381f7b5 100644 --- a/system/helpers/form_helper.php +++ b/system/helpers/form_helper.php @@ -2,7 +2,7 @@ /** * CodeIgniter * - * An open source application development framework for PHP 4.3.2 or newer + * An open source application development framework for PHP 5.1.6 or newer * * @package CodeIgniter * @author ExpressionEngine Dev Team diff --git a/system/helpers/html_helper.php b/system/helpers/html_helper.php index 3010c6f8b..0ba4eba2e 100644 --- a/system/helpers/html_helper.php +++ b/system/helpers/html_helper.php @@ -2,7 +2,7 @@ /** * CodeIgniter * - * An open source application development framework for PHP 4.3.2 or newer + * An open source application development framework for PHP 5.1.6 or newer * * @package CodeIgniter * @author ExpressionEngine Dev Team diff --git a/system/helpers/inflector_helper.php b/system/helpers/inflector_helper.php index cd05c8d6d..3d9acfcf0 100644 --- a/system/helpers/inflector_helper.php +++ b/system/helpers/inflector_helper.php @@ -2,7 +2,7 @@ /** * CodeIgniter * - * An open source application development framework for PHP 4.3.2 or newer + * An open source application development framework for PHP 5.1.6 or newer * * @package CodeIgniter * @author ExpressionEngine Dev Team diff --git a/system/helpers/language_helper.php b/system/helpers/language_helper.php index c6bbe8636..06428a76c 100644 --- a/system/helpers/language_helper.php +++ b/system/helpers/language_helper.php @@ -2,7 +2,7 @@ /** * CodeIgniter * - * An open source application development framework for PHP 4.3.2 or newer + * An open source application development framework for PHP 5.1.6 or newer * * @package CodeIgniter * @author ExpressionEngine Dev Team diff --git a/system/helpers/number_helper.php b/system/helpers/number_helper.php index e4535f620..e0d4a94b0 100644 --- a/system/helpers/number_helper.php +++ b/system/helpers/number_helper.php @@ -2,7 +2,7 @@ /** * CodeIgniter * - * An open source application development framework for PHP 4.3.2 or newer + * An open source application development framework for PHP 5.1.6 or newer * * @package CodeIgniter * @author ExpressionEngine Dev Team diff --git a/system/helpers/path_helper.php b/system/helpers/path_helper.php index 556e8c9a2..9dd5ded25 100644 --- a/system/helpers/path_helper.php +++ b/system/helpers/path_helper.php @@ -2,7 +2,7 @@ /** * CodeIgniter * - * An open source application development framework for PHP 4.3.2 or newer + * An open source application development framework for PHP 5.1.6 or newer * * @package CodeIgniter * @author ExpressionEngine Dev Team diff --git a/system/helpers/security_helper.php b/system/helpers/security_helper.php index 08dd48a85..9f44fa73c 100644 --- a/system/helpers/security_helper.php +++ b/system/helpers/security_helper.php @@ -2,7 +2,7 @@ /** * CodeIgniter * - * An open source application development framework for PHP 4.3.2 or newer + * An open source application development framework for PHP 5.1.6 or newer * * @package CodeIgniter * @author ExpressionEngine Dev Team diff --git a/system/helpers/smiley_helper.php b/system/helpers/smiley_helper.php index 3ebb61253..da3fd286d 100644 --- a/system/helpers/smiley_helper.php +++ b/system/helpers/smiley_helper.php @@ -2,7 +2,7 @@ /** * CodeIgniter * - * An open source application development framework for PHP 4.3.2 or newer + * An open source application development framework for PHP 5.1.6 or newer * * @package CodeIgniter * @author ExpressionEngine Dev Team diff --git a/system/helpers/string_helper.php b/system/helpers/string_helper.php index 544b3b42b..b0f0b8d82 100644 --- a/system/helpers/string_helper.php +++ b/system/helpers/string_helper.php @@ -2,7 +2,7 @@ /** * CodeIgniter * - * An open source application development framework for PHP 4.3.2 or newer + * An open source application development framework for PHP 5.1.6 or newer * * @package CodeIgniter * @author ExpressionEngine Dev Team diff --git a/system/helpers/text_helper.php b/system/helpers/text_helper.php index 8bc1cd5e5..58b08aaf8 100644 --- a/system/helpers/text_helper.php +++ b/system/helpers/text_helper.php @@ -2,7 +2,7 @@ /** * CodeIgniter * - * An open source application development framework for PHP 4.3.2 or newer + * An open source application development framework for PHP 5.1.6 or newer * * @package CodeIgniter * @author ExpressionEngine Dev Team diff --git a/system/helpers/typography_helper.php b/system/helpers/typography_helper.php index 1a71d1857..222c8fc1a 100644 --- a/system/helpers/typography_helper.php +++ b/system/helpers/typography_helper.php @@ -2,7 +2,7 @@ /** * CodeIgniter * - * An open source application development framework for PHP 4.3.2 or newer + * An open source application development framework for PHP 5.1.6 or newer * * @package CodeIgniter * @author ExpressionEngine Dev Team diff --git a/system/helpers/url_helper.php b/system/helpers/url_helper.php index e59efffec..53bcad562 100644 --- a/system/helpers/url_helper.php +++ b/system/helpers/url_helper.php @@ -2,7 +2,7 @@ /** * CodeIgniter * - * An open source application development framework for PHP 4.3.2 or newer + * An open source application development framework for PHP 5.1.6 or newer * * @package CodeIgniter * @author ExpressionEngine Dev Team diff --git a/system/helpers/xml_helper.php b/system/helpers/xml_helper.php index dcfbbdf74..e00cc9aa9 100644 --- a/system/helpers/xml_helper.php +++ b/system/helpers/xml_helper.php @@ -2,7 +2,7 @@ /** * CodeIgniter * - * An open source application development framework for PHP 4.3.2 or newer + * An open source application development framework for PHP 5.1.6 or newer * * @package CodeIgniter * @author ExpressionEngine Dev Team diff --git a/system/libraries/Calendar.php b/system/libraries/Calendar.php index 924333faa..752ce254b 100644 --- a/system/libraries/Calendar.php +++ b/system/libraries/Calendar.php @@ -2,7 +2,7 @@ /** * CodeIgniter * - * An open source application development framework for PHP 4.3.2 or newer + * An open source application development framework for PHP 5.1.6 or newer * * @package CodeIgniter * @author ExpressionEngine Dev Team diff --git a/system/libraries/Cart.php b/system/libraries/Cart.php index f3969ef2c..f2121bcac 100644 --- a/system/libraries/Cart.php +++ b/system/libraries/Cart.php @@ -2,7 +2,7 @@ /** * CodeIgniter * - * An open source application development framework for PHP 4.3.2 or newer + * An open source application development framework for PHP 5.1.6 or newer * * @package CodeIgniter * @author ExpressionEngine Dev Team diff --git a/system/libraries/Driver.php b/system/libraries/Driver.php index 1261b4c72..2eb9c1e5e 100644 --- a/system/libraries/Driver.php +++ b/system/libraries/Driver.php @@ -2,7 +2,7 @@ /** * CodeIgniter * - * An open source application development framework for PHP 4.3.2 or newer + * An open source application development framework for PHP 5.1.6 or newer * * @package CodeIgniter * @author EllisLab Dev Team diff --git a/system/libraries/Email.php b/system/libraries/Email.php index 043e14bc4..fbf494d32 100644 --- a/system/libraries/Email.php +++ b/system/libraries/Email.php @@ -2,7 +2,7 @@ /** * CodeIgniter * - * An open source application development framework for PHP 4.3.2 or newer + * An open source application development framework for PHP 5.1.6 or newer * * @package CodeIgniter * @author ExpressionEngine Dev Team diff --git a/system/libraries/Encrypt.php b/system/libraries/Encrypt.php index b95dd999c..f64c10c5d 100644 --- a/system/libraries/Encrypt.php +++ b/system/libraries/Encrypt.php @@ -2,7 +2,7 @@ /** * CodeIgniter * - * An open source application development framework for PHP 4.3.2 or newer + * An open source application development framework for PHP 5.1.6 or newer * * @package CodeIgniter * @author ExpressionEngine Dev Team diff --git a/system/libraries/Form_validation.php b/system/libraries/Form_validation.php index 566655b12..cab6f34fd 100644 --- a/system/libraries/Form_validation.php +++ b/system/libraries/Form_validation.php @@ -2,7 +2,7 @@ /** * CodeIgniter * - * An open source application development framework for PHP 4.3.2 or newer + * An open source application development framework for PHP 5.1.6 or newer * * @package CodeIgniter * @author ExpressionEngine Dev Team diff --git a/system/libraries/Ftp.php b/system/libraries/Ftp.php index fa2d3770b..4cf95ee0e 100644 --- a/system/libraries/Ftp.php +++ b/system/libraries/Ftp.php @@ -2,7 +2,7 @@ /** * CodeIgniter * - * An open source application development framework for PHP 4.3.2 or newer + * An open source application development framework for PHP 5.1.6 or newer * * @package CodeIgniter * @author ExpressionEngine Dev Team diff --git a/system/libraries/Image_lib.php b/system/libraries/Image_lib.php index 99225600f..c9c8ced0f 100644 --- a/system/libraries/Image_lib.php +++ b/system/libraries/Image_lib.php @@ -2,7 +2,7 @@ /** * CodeIgniter * - * An open source application development framework for PHP 4.3.2 or newer + * An open source application development framework for PHP 5.1.6 or newer * * @package CodeIgniter * @author ExpressionEngine Dev Team diff --git a/system/libraries/Javascript.php b/system/libraries/Javascript.php index 30b62e1c2..8b7efd2c4 100644 --- a/system/libraries/Javascript.php +++ b/system/libraries/Javascript.php @@ -2,7 +2,7 @@ /** * CodeIgniter * - * An open source application development framework for PHP 4.3.2 or newer + * An open source application development framework for PHP 5.1.6 or newer * * @package CodeIgniter * @author ExpressionEngine Dev Team diff --git a/system/libraries/Log.php b/system/libraries/Log.php index 99ed126f4..d4a687191 100644 --- a/system/libraries/Log.php +++ b/system/libraries/Log.php @@ -2,7 +2,7 @@ /** * CodeIgniter * - * An open source application development framework for PHP 4.3.2 or newer + * An open source application development framework for PHP 5.1.6 or newer * * @package CodeIgniter * @author ExpressionEngine Dev Team diff --git a/system/libraries/Pagination.php b/system/libraries/Pagination.php index b3175f997..e5a59ed76 100644 --- a/system/libraries/Pagination.php +++ b/system/libraries/Pagination.php @@ -2,7 +2,7 @@ /** * CodeIgniter * - * An open source application development framework for PHP 4.3.2 or newer + * An open source application development framework for PHP 5.1.6 or newer * * @package CodeIgniter * @author ExpressionEngine Dev Team diff --git a/system/libraries/Parser.php b/system/libraries/Parser.php index b969ce4d4..f7320c5a0 100644 --- a/system/libraries/Parser.php +++ b/system/libraries/Parser.php @@ -2,7 +2,7 @@ /** * CodeIgniter * - * An open source application development framework for PHP 4.3.2 or newer + * An open source application development framework for PHP 5.1.6 or newer * * @package CodeIgniter * @author ExpressionEngine Dev Team diff --git a/system/libraries/Profiler.php b/system/libraries/Profiler.php index 796db2d6b..0b73abd27 100644 --- a/system/libraries/Profiler.php +++ b/system/libraries/Profiler.php @@ -2,7 +2,7 @@ /** * CodeIgniter * - * An open source application development framework for PHP 4.3.2 or newer + * An open source application development framework for PHP 5.1.6 or newer * * @package CodeIgniter * @author ExpressionEngine Dev Team diff --git a/system/libraries/Security.php b/system/libraries/Security.php index fa5317ea3..0fa1428be 100644 --- a/system/libraries/Security.php +++ b/system/libraries/Security.php @@ -2,7 +2,7 @@ /** * CodeIgniter * - * An open source application development framework for PHP 4.3.2 or newer + * An open source application development framework for PHP 5.1.6 or newer * * @package CodeIgniter * @author ExpressionEngine Dev Team diff --git a/system/libraries/Session.php b/system/libraries/Session.php index 1e606de9c..e7842d847 100644 --- a/system/libraries/Session.php +++ b/system/libraries/Session.php @@ -2,7 +2,7 @@ /** * CodeIgniter * - * An open source application development framework for PHP 4.3.2 or newer + * An open source application development framework for PHP 5.1.6 or newer * * @package CodeIgniter * @author ExpressionEngine Dev Team diff --git a/system/libraries/Sha1.php b/system/libraries/Sha1.php index ff7e72033..d9f0e3952 100644 --- a/system/libraries/Sha1.php +++ b/system/libraries/Sha1.php @@ -2,7 +2,7 @@ /** * CodeIgniter * - * An open source application development framework for PHP 4.3.2 or newer + * An open source application development framework for PHP 5.1.6 or newer * * @package CodeIgniter * @author ExpressionEngine Dev Team diff --git a/system/libraries/Table.php b/system/libraries/Table.php index 2fc1b634d..82d0a3e9d 100644 --- a/system/libraries/Table.php +++ b/system/libraries/Table.php @@ -2,7 +2,7 @@ /** * CodeIgniter * - * An open source application development framework for PHP 4.3.2 or newer + * An open source application development framework for PHP 5.1.6 or newer * * @package CodeIgniter * @author ExpressionEngine Dev Team diff --git a/system/libraries/Trackback.php b/system/libraries/Trackback.php index a8be8a877..c2350947a 100644 --- a/system/libraries/Trackback.php +++ b/system/libraries/Trackback.php @@ -2,7 +2,7 @@ /** * CodeIgniter * - * An open source application development framework for PHP 4.3.2 or newer + * An open source application development framework for PHP 5.1.6 or newer * * @package CodeIgniter * @author ExpressionEngine Dev Team diff --git a/system/libraries/Typography.php b/system/libraries/Typography.php index d8b295e7b..e08708562 100644 --- a/system/libraries/Typography.php +++ b/system/libraries/Typography.php @@ -2,7 +2,7 @@ /** * CodeIgniter * - * An open source application development framework for PHP 4.3.2 or newer + * An open source application development framework for PHP 5.1.6 or newer * * @package CodeIgniter * @author ExpressionEngine Dev Team diff --git a/system/libraries/Unit_test.php b/system/libraries/Unit_test.php index 9a90cb47c..2f6067b5e 100644 --- a/system/libraries/Unit_test.php +++ b/system/libraries/Unit_test.php @@ -2,7 +2,7 @@ /** * CodeIgniter * - * An open source application development framework for PHP 4.3.2 or newer + * An open source application development framework for PHP 5.1.6 or newer * * @package CodeIgniter * @author ExpressionEngine Dev Team diff --git a/system/libraries/Upload.php b/system/libraries/Upload.php index c83d0aeaa..2e3d75832 100644 --- a/system/libraries/Upload.php +++ b/system/libraries/Upload.php @@ -2,7 +2,7 @@ /** * CodeIgniter * - * An open source application development framework for PHP 4.3.2 or newer + * An open source application development framework for PHP 5.1.6 or newer * * @package CodeIgniter * @author ExpressionEngine Dev Team diff --git a/system/libraries/User_agent.php b/system/libraries/User_agent.php index 00cbf6967..a780ec231 100644 --- a/system/libraries/User_agent.php +++ b/system/libraries/User_agent.php @@ -2,7 +2,7 @@ /** * CodeIgniter * - * An open source application development framework for PHP 4.3.2 or newer + * An open source application development framework for PHP 5.1.6 or newer * * @package CodeIgniter * @author ExpressionEngine Dev Team diff --git a/system/libraries/Xmlrpc.php b/system/libraries/Xmlrpc.php index 54ee70771..44cdffecd 100644 --- a/system/libraries/Xmlrpc.php +++ b/system/libraries/Xmlrpc.php @@ -2,7 +2,7 @@ /** * CodeIgniter * - * An open source application development framework for PHP 4.3.2 or newer + * An open source application development framework for PHP 5.1.6 or newer * * @package CodeIgniter * @author ExpressionEngine Dev Team diff --git a/system/libraries/Xmlrpcs.php b/system/libraries/Xmlrpcs.php index 56fd655df..14e10d22c 100644 --- a/system/libraries/Xmlrpcs.php +++ b/system/libraries/Xmlrpcs.php @@ -2,7 +2,7 @@ /** * CodeIgniter * - * An open source application development framework for PHP 4.3.2 or newer + * An open source application development framework for PHP 5.1.6 or newer * * @package CodeIgniter * @author ExpressionEngine Dev Team diff --git a/system/libraries/Zip.php b/system/libraries/Zip.php index da3e5eb63..aa5cf13b0 100644 --- a/system/libraries/Zip.php +++ b/system/libraries/Zip.php @@ -2,7 +2,7 @@ /** * CodeIgniter * - * An open source application development framework for PHP 4.3.2 or newer + * An open source application development framework for PHP 5.1.6 or newer * * @package CodeIgniter * @author ExpressionEngine Dev Team -- cgit v1.2.3-24-g4f1b From 2893f00bf042057b73435d65814906e1f5d2380d Mon Sep 17 00:00:00 2001 From: Greg Aker Date: Wed, 10 Nov 2010 14:55:46 -0600 Subject: Removing require Compat.php in CodeIgniter.php --- system/core/CodeIgniter.php | 7 ------- 1 file changed, 7 deletions(-) (limited to 'system') diff --git a/system/core/CodeIgniter.php b/system/core/CodeIgniter.php index be5a27120..fc334f050 100644 --- a/system/core/CodeIgniter.php +++ b/system/core/CodeIgniter.php @@ -41,13 +41,6 @@ */ require(BASEPATH.'core/Common'.EXT); -/* - * ------------------------------------------------------ - * Load the compatibility override functions - * ------------------------------------------------------ - */ - require(BASEPATH.'core/Compat'.EXT); - /* * ------------------------------------------------------ * Load the framework constants -- cgit v1.2.3-24-g4f1b From 68e30fd718b98a4cc6a449dbfbad368670efc25d Mon Sep 17 00:00:00 2001 From: Pascal Kriete Date: Wed, 10 Nov 2010 15:58:50 -0500 Subject: Removing the compatitibility helper. --- system/helpers/compatibility_helper.php | 499 -------------------------------- 1 file changed, 499 deletions(-) delete mode 100644 system/helpers/compatibility_helper.php (limited to 'system') diff --git a/system/helpers/compatibility_helper.php b/system/helpers/compatibility_helper.php deleted file mode 100644 index 6770d9a3b..000000000 --- a/system/helpers/compatibility_helper.php +++ /dev/null @@ -1,499 +0,0 @@ - 0) // 8 = FILE_APPEND flag - { - $mode = FOPEN_WRITE_CREATE; - } - else - { - $mode = FOPEN_WRITE_CREATE_DESTRUCTIVE; - } - - // Check if we're using the include path - if (($flags & 1) > 0) // 1 = FILE_USE_INCLUDE_PATH flag - { - $use_include_path = TRUE; - } - else - { - $use_include_path = FALSE; - } - - $fp = @fopen($filename, $mode, $use_include_path); - - if ($fp === FALSE) - { - $backtrace = debug_backtrace(); - _exception_handler(E_USER_WARNING, 'file_put_contents('.htmlentities($filename).') failed to open stream', $backtrace[0]['file'], $backtrace[0]['line']); - return FALSE; - } - - if (($flags & LOCK_EX) > 0) - { - if ( ! flock($fp, LOCK_EX)) - { - $backtrace = debug_backtrace(); - _exception_handler(E_USER_WARNING, 'file_put_contents('.htmlentities($filename).') unable to acquire an exclusive lock on file', $backtrace[0]['file'], $backtrace[0]['line']); - return FALSE; - } - } - - // write it - if (($written = @fwrite($fp, $data)) === FALSE) - { - $backtrace = debug_backtrace(); - _exception_handler(E_USER_WARNING, 'file_put_contents('.htmlentities($filename).') failed to write to '.htmlentities($filename), $backtrace[0]['file'], $backtrace[0]['line']); - } - - // Close the handle - @fclose($fp); - - // Return length - return $written; - } -} - -// ------------------------------------------------------------------------ - -/** - * fputcsv() - * - * Format line as CSV and write to file pointer - * http://us.php.net/manual/en/function.fputcsv.php - * - * @access public - * @param resource file pointer - * @param array data to be written - * @param string delimiter - * @param string enclosure - * @return int length of written string - */ -if ( ! function_exists('fputcsv')) -{ - function fputcsv($handle, $fields, $delimiter = ',', $enclosure = '"') - { - // Checking for a handle resource - if ( ! is_resource($handle)) - { - $backtrace = debug_backtrace(); - _exception_handler(E_USER_WARNING, 'fputcsv() expects parameter 1 to be stream resource, '.gettype($handle).' given', $backtrace[0]['file'], $backtrace[0]['line']); - return FALSE; - } - - // OK, it is a resource, but is it a stream? - if (get_resource_type($handle) !== 'stream') - { - $backtrace = debug_backtrace(); - _exception_handler(E_USER_WARNING, 'fputcsv() expects parameter 1 to be stream resource, '.get_resource_type($handle).' given', $backtrace[0]['file'], $backtrace[0]['line']); - return FALSE; - } - - // Checking for an array of fields - if ( ! is_array($fields)) - { - $backtrace = debug_backtrace(); - _exception_handler(E_USER_WARNING, 'fputcsv() expects parameter 2 to be array, '.gettype($fields).' given', $backtrace[0]['file'], $backtrace[0]['line']); - return FALSE; - } - - // validate delimiter - if (strlen($delimiter) > 1) - { - $delimiter = substr($delimiter, 0, 1); - $backtrace = debug_backtrace(); - _exception_handler(E_NOTICE, 'fputcsv() delimiter must be one character long, "'.htmlentities($delimiter).'" used', $backtrace[0]['file'], $backtrace[0]['line']); - } - - // validate enclosure - if (strlen($enclosure) > 1) - { - $enclosure = substr($enclosure, 0, 1); - $backtrace = debug_backtrace(); - _exception_handler(E_NOTICE, 'fputcsv() enclosure must be one character long, "'.htmlentities($enclosure).'" used', $backtrace[0]['file'], $backtrace[0]['line']); - - } - - $out = ''; - - foreach ($fields as $cell) - { - $cell = str_replace($enclosure, $enclosure.$enclosure, $cell); - - if (strpos($cell, $delimiter) !== FALSE OR strpos($cell, $enclosure) !== FALSE OR strpos($cell, "\n") !== FALSE) - { - $out .= $enclosure.$cell.$enclosure.$delimiter; - } - else - { - $out .= $cell.$delimiter; - } - } - - $length = @fwrite($handle, substr($out, 0, -1)."\n"); - - return $length; - } -} - -// ------------------------------------------------------------------------ - -/** - * stripos() - * - * Find position of first occurrence of a case-insensitive string - * http://us.php.net/manual/en/function.stripos.php - * - * @access public - * @param string haystack - * @param string needle - * @param int offset - * @return int numeric position of the first occurrence of needle in the haystack - */ -if ( ! function_exists('stripos')) -{ - function stripos($haystack, $needle, $offset = NULL) - { - // Cast non string scalar values - if (is_scalar($haystack)) - { - settype($haystack, 'STRING'); - } - - if ( ! is_string($haystack)) - { - $backtrace = debug_backtrace(); - _exception_handler(E_USER_WARNING, 'stripos() expects parameter 1 to be string, '.gettype($haystack).' given', $backtrace[0]['file'], $backtrace[0]['line']); - return FALSE; - } - - if ( ! is_scalar($needle)) - { - $backtrace = debug_backtrace(); - _exception_handler(E_USER_WARNING, 'stripos() needle is not a string or an integer in '.$backtrace[0]['file'], $backtrace[0]['line']); - return FALSE; - } - - if (is_float($offset)) - { - $offset = (int)$offset; - } - - if ( ! is_int($offset) && ! is_bool($offset) && ! is_null($offset)) - { - $backtrace = debug_backtrace(); - _exception_handler(E_USER_WARNING, 'stripos() expects parameter 3 to be long, '.gettype($offset).' given', $backtrace[0]['file'], $backtrace[0]['line']); - return NULL; - } - - return strpos(strtolower($haystack), strtolower($needle), $offset); - } -} - -// ------------------------------------------------------------------------ - -/** - * str_ireplace() - * - * Find position of first occurrence of a case-insensitive string - * http://us.php.net/manual/en/function.str-ireplace.php - * (parameter 4, $count, is not supported as to do so in PHP 4 would make - * it a required parameter) - * - * @access public - * @param mixed search - * @param mixed replace - * @param mixed subject - * @return int numeric position of the first occurrence of needle in the haystack - */ -if ( ! function_exists('str_ireplace')) -{ - function str_ireplace($search, $replace, $subject) - { - // Nothing to do here - if ($search === NULL OR $subject === NULL) - { - return $subject; - } - - // Crazy arguments - if (is_scalar($search) && is_array($replace)) - { - $backtrace = debug_backtrace(); - - if (is_object($replace)) - { - show_error('Object of class '.get_class($replace).' could not be converted to string in '.$backtrace[0]['file'].' on line '.$backtrace[0]['line']); - } - else - { - _exception_handler(E_USER_NOTICE, 'Array to string conversion in '.$backtrace[0]['file'], $backtrace[0]['line']); - } - } - - // Searching for an array - if (is_array($search)) - { - // Replacing with an array - if (is_array($replace)) - { - $search = array_values($search); - $replace = array_values($replace); - - if (count($search) >= count($replace)) - { - $replace = array_pad($replace, count($search), ''); - } - else - { - $replace = array_slice($replace, 0, count($search)); - } - } - else - { - // Replacing with a string all positions - $replace = array_fill(0, count($search), $replace); - } - } - else - { - //Searching for a string and replacing with a string. - $search = array((string)$search); - $replace = array((string)$replace); - } - - // Prepare the search array - foreach ($search as $search_key => $search_value) - { - $search[$search_key] = '/'.preg_quote($search_value, '/').'/i'; - } - - // Prepare the replace array (escape backreferences) - foreach ($replace as $k => $v) - { - $replace[$k] = str_replace(array(chr(92), '$'), array(chr(92).chr(92), '\$'), $v); - } - - // do the replacement - $result = preg_replace($search, $replace, (array)$subject); - - // Check if subject was initially a string and return it as a string - if ( ! is_array($subject)) - { - return current($result); - } - - // Otherwise, just return the array - return $result; - } -} - -// ------------------------------------------------------------------------ - -/** - * http_build_query() - * - * Generate URL-encoded query string - * http://us.php.net/manual/en/function.http-build-query.php - * - * @access public - * @param array form data - * @param string numeric prefix - * @param string argument separator - * @return string URL-encoded string - */ -if ( ! function_exists('http_build_query')) -{ - function http_build_query($formdata, $numeric_prefix = NULL, $separator = NULL) - { - // Check the data - if ( ! is_array($formdata) && ! is_object($formdata)) - { - $backtrace = debug_backtrace(); - _exception_handler(E_USER_WARNING, 'http_build_query() Parameter 1 expected to be Array or Object. Incorrect value given', $backtrace[0]['file'], $backtrace[0]['line']); - return FALSE; - } - - // Cast it as array - if (is_object($formdata)) - { - $formdata = get_object_vars($formdata); - } - - // If the array is empty, return NULL - if (empty($formdata)) - { - return NULL; - } - - // Argument separator - if ($separator === NULL) - { - $separator = ini_get('arg_separator.output'); - - if (strlen($separator) == 0) - { - $separator = '&'; - } - } - - // Start building the query - $tmp = array(); - - foreach ($formdata as $key => $val) - { - if ($val === NULL) - { - continue; - } - - if (is_integer($key) && $numeric_prefix != NULL) - { - $key = $numeric_prefix.$key; - } - - if (is_resource($val)) - { - return NULL; - } - - // hand it off to a recursive parser - $tmp[] = _http_build_query_helper($key, $val, $separator); - } - - return implode($separator, $tmp); - } - - - // Helper helper. Remind anyone of college? - // Required to handle recursion in nested arrays. - // - // You could shave fractions of fractions of a second by moving where - // the urlencoding takes place, but it's much less intuitive, and if - // your application has 10,000 form fields, well, you have other problems ;) - function _http_build_query_helper($key, $val, $separator = '&') - { - if (is_scalar($val)) - { - return urlencode($key).'='.urlencode($val); - } - else - { - // arrays please - if (is_object($val)) - { - $val = get_object_vars($val); - } - - foreach ($val as $k => $v) - { - $tmp[] = _http_build_query_helper($key.'['.$k.']', $v, $separator); - } - } - - return implode($separator, $tmp); - } -} - - -/* End of file compatibility_helper.php */ -/* Location: ./system/helpers/compatibility_helper.php */ \ No newline at end of file -- cgit v1.2.3-24-g4f1b From 5ac559479a621eb35ff11ab86c529910aed8c052 Mon Sep 17 00:00:00 2001 From: Greg Aker Date: Wed, 10 Nov 2010 14:59:47 -0600 Subject: Changing method visibility in the Profiler class --- system/libraries/Profiler.php | 39 ++++++++++++++------------------------- 1 file changed, 14 insertions(+), 25 deletions(-) (limited to 'system') diff --git a/system/libraries/Profiler.php b/system/libraries/Profiler.php index 0b73abd27..4441a9fbe 100644 --- a/system/libraries/Profiler.php +++ b/system/libraries/Profiler.php @@ -34,7 +34,7 @@ class CI_Profiler { var $CI; - var $_available_sections = array( + protected $_available_sections = array( 'benchmarks', 'get', 'memory_usage', @@ -46,7 +46,7 @@ class CI_Profiler { 'config' ); - function CI_Profiler($config = array()) + public function __construct($config = array()) { $this->CI =& get_instance(); $this->CI->load->language('profiler'); @@ -70,11 +70,10 @@ class CI_Profiler { * * Sets the private _compile_* properties to enable/disable Profiler sections * - * @access public * @param mixed * @return void */ - function set_sections($config) + public function set_sections($config) { foreach ($config as $method => $enable) { @@ -94,11 +93,10 @@ class CI_Profiler { * 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 - * @PHP4 - all methods should be declared private - * @access private + * * @return array */ - function _compile_benchmarks() + protected function _compile_benchmarks() { $profile = array(); foreach ($this->CI->benchmark->marker as $key => $val) @@ -142,10 +140,9 @@ class CI_Profiler { /** * Compile Queries * - * @access private * @return string */ - function _compile_queries() + protected function _compile_queries() { $dbs = array(); @@ -224,10 +221,9 @@ class CI_Profiler { /** * Compile $_GET Data * - * @access private * @return string */ - function _compile_get() + protected function _compile_get() { $output = "\n\n"; $output .= '
    '; @@ -274,10 +270,9 @@ class CI_Profiler { /** * Compile $_POST Data * - * @access private * @return string */ - function _compile_post() + protected function _compile_post() { $output = "\n\n"; $output .= '
    '; @@ -324,10 +319,9 @@ class CI_Profiler { /** * Show query string * - * @access private * @return string */ - function _compile_uri_string() + protected function _compile_uri_string() { $output = "\n\n"; $output .= '
    '; @@ -354,10 +348,9 @@ class CI_Profiler { /** * Show the controller and function that were called * - * @access private * @return string */ - function _compile_controller_info() + protected function _compile_controller_info() { $output = "\n\n"; $output .= '
    '; @@ -380,10 +373,9 @@ class CI_Profiler { * * Display total used memory * - * @access public * @return string */ - function _compile_memory_usage() + protected function _compile_memory_usage() { $output = "\n\n"; $output .= '
    '; @@ -412,10 +404,9 @@ class CI_Profiler { * * Lists HTTP headers * - * @access public * @return string */ - function _compile_http_headers() + protected function _compile_http_headers() { $output = "\n\n"; $output .= '
    '; @@ -444,10 +435,9 @@ class CI_Profiler { * * Lists developer config variables * - * @access public * @return string */ - function _compile_config() + protected function _compile_config() { $output = "\n\n"; $output .= '
    '; @@ -478,10 +468,9 @@ class CI_Profiler { /** * Run the Profiler * - * @access private * @return string */ - function run() + public function run() { $output = "
    "; $fields_displayed = 0; -- cgit v1.2.3-24-g4f1b From 585600207a79c1d9a7b0af5883bf384629b753a3 Mon Sep 17 00:00:00 2001 From: Pascal Kriete Date: Wed, 10 Nov 2010 16:01:20 -0500 Subject: Removing instantiate_class(), which was needed to make php 4 and 5.3 play together nicely. Removed all instantiations by reference. --- system/core/Common.php | 21 +-------------------- system/core/Loader.php | 2 +- system/database/DB.php | 2 +- 3 files changed, 3 insertions(+), 22 deletions(-) (limited to 'system') diff --git a/system/core/Common.php b/system/core/Common.php index 56fe713bd..6a3d5ac0a 100644 --- a/system/core/Common.php +++ b/system/core/Common.php @@ -163,29 +163,10 @@ // Keep track of what we just loaded is_loaded($class); - $_classes[$class] =& instantiate_class(new $name()); + $_classes[$class] = new $name(); return $_classes[$class]; } -// ------------------------------------------------------------------------ - -/** - * Instantiate Class - * - * Returns a new class object by reference, used by load_class() and the DB class. - * Required to retain PHP 4 compatibility and also not make PHP 5.3 cry. - * - * Use: $obj =& instantiate_class(new Foo()); - * - * @access public - * @param object - * @return object - */ - function &instantiate_class(&$class_object) - { - return $class_object; - } - // -------------------------------------------------------------------- /** diff --git a/system/core/Loader.php b/system/core/Loader.php index 69917648d..e97b18102 100644 --- a/system/core/Loader.php +++ b/system/core/Loader.php @@ -267,7 +267,7 @@ class CI_Loader { require_once(BASEPATH.'database/drivers/'.$CI->db->dbdriver.'/'.$CI->db->dbdriver.'_utility'.EXT); $class = 'CI_DB_'.$CI->db->dbdriver.'_utility'; - $CI->dbutil =& instantiate_class(new $class()); + $CI->dbutil = new $class(); } // -------------------------------------------------------------------- diff --git a/system/database/DB.php b/system/database/DB.php index b51995b68..60a67e821 100644 --- a/system/database/DB.php +++ b/system/database/DB.php @@ -130,7 +130,7 @@ function &DB($params = '', $active_record_override = NULL) // Instantiate the DB adapter $driver = 'CI_DB_'.$params['dbdriver'].'_driver'; - $DB =& instantiate_class(new $driver($params)); + $DB = new $driver($params); if ($DB->autoinit == TRUE) { -- cgit v1.2.3-24-g4f1b From 8adf8b03017cb0ca0c6e99ec9c1995b11f8237e6 Mon Sep 17 00:00:00 2001 From: Pascal Kriete Date: Wed, 10 Nov 2010 16:03:29 -0500 Subject: Removing a global call that was needed for php 4. --- system/core/Loader.php | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) (limited to 'system') diff --git a/system/core/Loader.php b/system/core/Loader.php index e97b18102..b64a6e6f4 100644 --- a/system/core/Loader.php +++ b/system/core/Loader.php @@ -703,9 +703,7 @@ class CI_Loader { } else { - // PHP 4 requires that we use a global - global $OUT; - $OUT->append_output(ob_get_contents()); + $_ci_CI->append_output(ob_get_contents()); @ob_end_clean(); } } -- cgit v1.2.3-24-g4f1b From c0af6c044570e0561afdea109f4101dba04e2510 Mon Sep 17 00:00:00 2001 From: Pascal Kriete Date: Wed, 10 Nov 2010 16:05:35 -0500 Subject: removing a few php 4 workarounds from the image lib. --- system/libraries/Image_lib.php | 13 ------------- 1 file changed, 13 deletions(-) (limited to 'system') diff --git a/system/libraries/Image_lib.php b/system/libraries/Image_lib.php index c9c8ced0f..dec5f34f6 100644 --- a/system/libraries/Image_lib.php +++ b/system/libraries/Image_lib.php @@ -712,14 +712,6 @@ class CI_Image_lib { */ function image_rotate_gd() { - // Is Image Rotation Supported? - // this function is only supported as of PHP 4.3 - if ( ! function_exists('imagerotate')) - { - $this->set_error('imglib_rotate_unsupported'); - return FALSE; - } - // Create the image handle if ( ! ($src_img = $this->image_create_gd())) { @@ -1215,11 +1207,6 @@ class CI_Image_lib { return FALSE; } - if (phpversion() == '4.4.1') - { - @touch($this->full_dst_path); // PHP 4.4.1 bug #35060 - workaround - } - if ( ! @imagejpeg($resource, $this->full_dst_path, $this->quality)) { $this->set_error('imglib_save_failed'); -- cgit v1.2.3-24-g4f1b From 58fdee85181b05c7303b1d2a5a26cb2f4e00f03f Mon Sep 17 00:00:00 2001 From: Greg Aker Date: Wed, 10 Nov 2010 15:07:09 -0600 Subject: setting var/function visibility in the UPload class --- system/libraries/Upload.php | 134 ++++++++++++++++++-------------------------- 1 file changed, 54 insertions(+), 80 deletions(-) (limited to 'system') diff --git a/system/libraries/Upload.php b/system/libraries/Upload.php index 2e3d75832..4ccbdde90 100644 --- a/system/libraries/Upload.php +++ b/system/libraries/Upload.php @@ -26,40 +26,40 @@ */ class CI_Upload { - var $max_size = 0; - var $max_width = 0; - var $max_height = 0; - var $max_filename = 0; - var $allowed_types = ""; - var $file_temp = ""; - var $file_name = ""; - var $orig_name = ""; - var $file_type = ""; - var $file_size = ""; - var $file_ext = ""; - var $upload_path = ""; - var $overwrite = FALSE; - var $encrypt_name = FALSE; - var $is_image = FALSE; - var $image_width = ''; - var $image_height = ''; - var $image_type = ''; - var $image_size_str = ''; - var $error_msg = array(); - var $mimes = array(); - var $remove_spaces = TRUE; - var $xss_clean = FALSE; - var $temp_prefix = "temp_file_"; - var $client_name = ''; - - var $_file_name_override = ''; //@PHP4 (should be private) + public $max_size = 0; + public $max_width = 0; + public $max_height = 0; + public $max_filename = 0; + public $allowed_types = ""; + public $file_temp = ""; + public $file_name = ""; + public $orig_name = ""; + public $file_type = ""; + public $file_size = ""; + public $file_ext = ""; + public $upload_path = ""; + public $overwrite = FALSE; + public $encrypt_name = FALSE; + public $is_image = FALSE; + public $image_width = ''; + public $image_height = ''; + public $image_type = ''; + public $image_size_str = ''; + public $error_msg = array(); + public $mimes = array(); + public $remove_spaces = TRUE; + public $xss_clean = FALSE; + public $temp_prefix = "temp_file_"; + public $client_name = ''; + + protected $_file_name_override = ''; /** * Constructor * * @access public */ - function CI_Upload($props = array()) + public function __construct($props = array()) { if (count($props) > 0) { @@ -74,12 +74,10 @@ class CI_Upload { /** * Initialize preferences * - * @access public * @param array * @return void */ - - function initialize($config = array()) + public function initialize($config = array()) { $defaults = array( 'max_size' => 0, @@ -140,10 +138,9 @@ class CI_Upload { /** * Perform the file upload * - * @access public * @return bool */ - function do_upload($field = 'userfile') + public function do_upload($field = 'userfile') { // Is $_FILES[$field] set? If not, no reason to continue. if ( ! isset($_FILES[$field])) @@ -328,10 +325,9 @@ class CI_Upload { * Returns an associative array containing all of the information * related to the upload, allowing the developer easy access in one array. * - * @access public * @return array */ - function data() + public function data() { return array ( 'file_name' => $this->file_name, @@ -356,11 +352,10 @@ class CI_Upload { /** * Set Upload Path * - * @access public * @param string * @return void */ - function set_upload_path($path) + public function set_upload_path($path) { // Make sure it has a trailing slash $this->upload_path = rtrim($path, '/').'/'; @@ -375,12 +370,11 @@ class CI_Upload { * existence of a file with the same name. If found, it will append a * number to the end of the filename to avoid overwriting a pre-existing file. * - * @access public * @param string * @param string * @return string */ - function set_filename($path, $filename) + public function set_filename($path, $filename) { if ($this->encrypt_name == TRUE) { @@ -421,11 +415,10 @@ class CI_Upload { /** * Set Maximum File Size * - * @access public * @param integer * @return void */ - function set_max_filesize($n) + public function set_max_filesize($n) { $this->max_size = ((int) $n < 0) ? 0: (int) $n; } @@ -435,11 +428,10 @@ class CI_Upload { /** * Set Maximum File Name Length * - * @access public * @param integer * @return void */ - function set_max_filename($n) + public function set_max_filename($n) { $this->max_filename = ((int) $n < 0) ? 0: (int) $n; } @@ -449,11 +441,10 @@ class CI_Upload { /** * Set Maximum Image Width * - * @access public * @param integer * @return void */ - function set_max_width($n) + public function set_max_width($n) { $this->max_width = ((int) $n < 0) ? 0: (int) $n; } @@ -463,11 +454,10 @@ class CI_Upload { /** * Set Maximum Image Height * - * @access public * @param integer * @return void */ - function set_max_height($n) + public function set_max_height($n) { $this->max_height = ((int) $n < 0) ? 0: (int) $n; } @@ -477,11 +467,10 @@ class CI_Upload { /** * Set Allowed File Types * - * @access public * @param string * @return void */ - function set_allowed_types($types) + public function set_allowed_types($types) { if ( ! is_array($types) && $types == '*') { @@ -498,11 +487,10 @@ class CI_Upload { * * Uses GD to determine the width/height/type of image * - * @access public * @param string * @return void */ - function set_image_properties($path = '') + public function set_image_properties($path = '') { if ( ! $this->is_image()) { @@ -531,11 +519,10 @@ class CI_Upload { * Enables the XSS flag so that the file that was uploaded * will be run through the XSS filter. * - * @access public * @param bool * @return void */ - function set_xss_clean($flag = FALSE) + public function set_xss_clean($flag = FALSE) { $this->xss_clean = ($flag == TRUE) ? TRUE : FALSE; } @@ -545,10 +532,9 @@ class CI_Upload { /** * Validate the image * - * @access public * @return bool */ - function is_image() + public function is_image() { // IE will sometimes return odd mime-types during upload, so here we just standardize all // jpegs or pngs to the same file type. @@ -580,10 +566,9 @@ class CI_Upload { /** * Verify that the filetype is allowed * - * @access public * @return bool */ - function is_allowed_filetype($ignore_mime = FALSE) + public function is_allowed_filetype($ignore_mime = FALSE) { if ($this->allowed_types == '*') { @@ -641,10 +626,9 @@ class CI_Upload { /** * Verify that the file is within the allowed size * - * @access public * @return bool */ - function is_allowed_filesize() + public function is_allowed_filesize() { if ($this->max_size != 0 AND $this->file_size > $this->max_size) { @@ -661,10 +645,9 @@ class CI_Upload { /** * Verify that the image is within the allowed width/height * - * @access public * @return bool */ - function is_allowed_dimensions() + public function is_allowed_dimensions() { if ( ! $this->is_image()) { @@ -699,10 +682,9 @@ class CI_Upload { * Verifies that it is a valid upload path with proper permissions. * * - * @access public * @return bool */ - function validate_upload_path() + public function validate_upload_path() { if ($this->upload_path == '') { @@ -736,11 +718,10 @@ class CI_Upload { /** * Extract the file extension * - * @access public * @param string * @return string */ - function get_extension($filename) + public function get_extension($filename) { $x = explode('.', $filename); return '.'.end($x); @@ -751,11 +732,10 @@ class CI_Upload { /** * Clean the file name for security * - * @access public * @param string * @return string */ - function clean_file_name($filename) + public function clean_file_name($filename) { $bad = array( "' => '-->', - ' '<![CDATA[' - ); - /* never allowed, regex replacement */ - public $never_allowed_regex = array( - "javascript\s*:" => '[removed]', - "expression\s*(\(|&\#40;)" => '[removed]', // CSS and IE - "vbscript\s*:" => '[removed]', // IE, surprise! - "Redirect\s+302" => '[removed]' - ); + protected $_never_allowed_str = array( + 'document.cookie' => '[removed]', + 'document.write' => '[removed]', + '.parentNode' => '[removed]', + '.innerHTML' => '[removed]', + 'window.location' => '[removed]', + '-moz-binding' => '[removed]', + '' => '-->', + ' '<![CDATA[' + ); + /* never allowed, regex replacement */ + protected $_never_allowed_regex = array( + "javascript\s*:" => '[removed]', + "expression\s*(\(|&\#40;)" => '[removed]', // CSS and IE + "vbscript\s*:" => '[removed]', // IE, surprise! + "Redirect\s+302" => '[removed]' + ); + + /** + * Constructor + */ public function __construct() { - $this->csrf_token_name = (config_item('csrf_token_name')) ? config_item('csrf_token_name') : 'csrf_token_name'; - $this->csrf_cookie_name = (config_item('csrf_cookie_name')) ? config_item('csrf_cookie_name') : 'csrf_cookie_name'; - $this->csrf_expire = (config_item('csrf_expire')) ? config_item('csrf_expire') : 7200; - // Append application specific cookie prefix to token name - $this->csrf_cookie_name = (config_item('cookie_prefix')) ? config_item('cookie_prefix').$this->csrf_token_name : $this->csrf_token_name; + $this->_csrf_cookie_name = (config_item('cookie_prefix')) ? config_item('cookie_prefix').$this->_csrf_token_name : $this->_csrf_token_name; // Set the CSRF hash $this->_csrf_set_hash(); @@ -72,8 +72,7 @@ class CI_Security { /** * Verify Cross Site Request Forgery Protection * - * @access public - * @return null + * @return object */ public function csrf_verify() { @@ -84,26 +83,30 @@ class CI_Security { } // Do the tokens exist in both the _POST and _COOKIE arrays? - if ( ! isset($_POST[$this->csrf_token_name]) OR ! isset($_COOKIE[$this->csrf_cookie_name])) + if ( ! isset($_POST[$this->_csrf_token_name]) OR + ! isset($_COOKIE[$this->_csrf_cookie_name])) { $this->csrf_show_error(); } // Do the tokens match? - if ($_POST[$this->csrf_token_name] != $_COOKIE[$this->csrf_cookie_name]) + 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]); + // 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]); + unset($_COOKIE[$this->_csrf_cookie_name]); $this->_csrf_set_hash(); $this->csrf_set_cookie(); log_message('debug', "CSRF token verified "); + + return $this; } // -------------------------------------------------------------------- @@ -111,57 +114,68 @@ class CI_Security { /** * Set Cross Site Request Forgery Protection Cookie * - * @access public - * @return null + * @return object */ public function csrf_set_cookie() { - $expire = time() + $this->csrf_expire; + $expire = time() + $this->_csrf_expire; $secure_cookie = (config_item('cookie_secure') === TRUE) ? 1 : 0; - setcookie($this->csrf_cookie_name, $this->csrf_hash, $expire, config_item('cookie_path'), config_item('cookie_domain'), $secure_cookie); + if ($secure_cookie) + { + $req = isset($_SERVER['HTTPS']) ? $_SERVER['HTTPS'] : FALSE; + + if ( ! $req OR $req == '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; } // -------------------------------------------------------------------- /** - * Set Cross Site Request Forgery Protection Cookie + * Show CSRF Error * - * @access private - * @return null + * @return void */ - private function _csrf_set_hash() + public function csrf_show_error() { - 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]) AND $_COOKIE[$this->csrf_cookie_name] != '') - { - $this->csrf_hash = $_COOKIE[$this->csrf_cookie_name]; - } - else - { - $this->csrf_hash = md5(uniqid(rand(), TRUE)); - } - } + show_error('The action you have requested is not allowed.'); + } - return $this->csrf_hash; + // -------------------------------------------------------------------- + + /** + * Get CSRF Hash + * + * Getter Method + * + * @return string self::_csrf_hash + */ + public function get_csrf_hash() + { + return $this->_csrf_hash; } // -------------------------------------------------------------------- /** - * Show CSRF Error + * Get CSRF Token Name * - * @access public - * @return null + * Getter Method + * + * @return string self::csrf_token_name */ - public function csrf_show_error() + public function get_csrf_token_name() { - show_error('The action you have requested is not allowed.'); + return $this->_csrf_token_name; } // -------------------------------------------------------------------- @@ -188,7 +202,6 @@ class CI_Security { * harvested from examining vulnerabilities in other programs: * http://ha.ckers.org/xss.html * - * @access public * @param mixed string or array * @return string */ @@ -213,35 +226,8 @@ class CI_Security { */ $str = remove_invisible_characters($str); - /* - * Protect GET variables in URLs - */ - - // 901119URL5918AMP18930PROTECT8198 - - $str = preg_replace('|\&([a-z\_0-9\-]+)\=([a-z\_0-9\-]+)|i', $this->xss_hash()."\\1=\\2", $str); - - /* - * Validate standard character entities - * - * Add a semicolon if missing. We do this to enable - * the conversion of entities to ASCII later. - * - */ - $str = preg_replace('#(&\#?[0-9a-z]{2,})([\x00-\x20])*;?#i', "\\1;\\2", $str); - - /* - * Validate UTF16 two byte encoding (x00) - * - * Just as above, adds a semicolon if missing. - * - */ - $str = preg_replace('#(&\#x?)([0-9A-F]+);?#i',"\\1\\2;",$str); - - /* - * Un-Protect GET variables in URLs - */ - $str = str_replace($this->xss_hash(), '&', $str); + // Validate Entities in URLs + $str = $this->_validate_entities($str); /* * URL Decode @@ -265,7 +251,7 @@ class CI_Security { */ $str = preg_replace_callback("/[a-z]+=([\'\"]).*?\\1/si", array($this, '_convert_attribute'), $str); - + $str = preg_replace_callback("/<\w+.*?(?=>|<|$)/si", array($this, '_decode_entity'), $str); /* @@ -278,9 +264,8 @@ class CI_Security { * * 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. - * + * NOTE: preg_replace was found to be amazingly slow here on + * large blocks of data, so we use str_replace. */ if (strpos($str, "\t") !== FALSE) @@ -293,34 +278,23 @@ class CI_Security { */ $converted_string = $str; - /* - * Not Allowed Under Any Conditions - */ - - foreach ($this->never_allowed_str as $key => $val) - { - $str = str_replace($key, $val, $str); - } - - foreach ($this->never_allowed_regex as $key => $val) - { - $str = preg_replace("#".$key."#i", $val, $str); - } + // Remove Strings that are never allowed + $str = $this->_do_never_allowed($str); /* * Makes PHP tags safe * - * Note: XML tags are inadvertently replaced too: + * Note: XML tags are inadvertently replaced too: * - * #si", '[removed]', $str); } } - while ($original != $str); + while($original != $str); unset($original); - /* - * Remove JavaScript Event Handlers - * - * Note: This code is a little blunt. It removes - * the event handler and anything up to the closing >, - * but it's unlikely to be a problem. - * - */ - $event_handlers = array('[^a-z_\-]on\w*','xmlns'); - - if ($is_image === TRUE) - { - /* - * Adobe Photoshop puts XML metadata into JFIF images, including namespacing, - * so we have to allow this for images. -Paul - */ - unset($event_handlers[array_search('xmlns', $event_handlers)]); - } - - $str = preg_replace("#<([^><]+?)(".implode('|', $event_handlers).")(\s*=\s*[^><]*)([><]*)#i", "<\\1\\4", $str); + // Remove evil attributes such as style, onclick and xmlns + $str = $this->_remove_evil_attributes($str, $is_image); /* * Sanitize naughty HTML elements @@ -407,7 +367,6 @@ class CI_Security { * * So this: * Becomes: <blink> - * */ $naughty = 'alert|applet|audio|basefont|base|behavior|bgsound|blink|body|embed|expression|form|frameset|frame|head|html|ilayer|iframe|input|isindex|layer|link|meta|object|plaintext|style|script|textarea|title|video|xml|xss'; $str = preg_replace_callback('#<(/*\s*)('.$naughty.')([^><]*)([><]*)#is', array($this, '_sanitize_naughty_html'), $str); @@ -423,45 +382,28 @@ class CI_Security { * * For example: eval('some code') * Becomes: eval('some code') - * */ $str = preg_replace('#(alert|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 - * - */ - foreach ($this->never_allowed_str as $key => $val) - { - $str = str_replace($key, $val, $str); - } - foreach ($this->never_allowed_regex as $key => $val) - { - $str = preg_replace("#".$key."#i", $val, $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. + * 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) { - if ($str == $converted_string) - { - return TRUE; - } - else - { - return FALSE; - } + return ($str == $converted_string) ? TRUE: FALSE; } log_message('debug', "XSS Filtering completed"); @@ -473,41 +415,190 @@ class CI_Security { /** * Random Hash for protecting URLs * - * @access public * @return string */ public function xss_hash() { - if ($this->xss_hash == '') + if ($this->_xss_hash == '') { if (phpversion() >= 4.2) + { mt_srand(); + } else + { mt_srand(hexdec(substr(md5(microtime()), -8)) & 0x7fffffff); + } - $this->xss_hash = md5(time() + mt_rand(0, 1999999999)); + $this->_xss_hash = md5(time() + mt_rand(0, 1999999999)); } - return $this->xss_hash; + return $this->_xss_hash; } // -------------------------------------------------------------------- + /** + * HTML Entities Decode + * + * This function is a replacement for html_entity_decode() + * + * In some versions of PHP the native function does not work + * when UTF-8 is the specified character set, so this gives us + * a work-around. More info here: + * http://bugs.php.net/bug.php?id=25670 + * + * NOTE: html_entity_decode() has a bug in some PHP versions when UTF-8 is the + * character set, and the PHP developers said they were not back porting the + * fix to versions other than PHP 5.x. + * + * @param string + * @param string + * @return string + */ + public function entity_decode($str, $charset='UTF-8') + { + if (stristr($str, '&') === FALSE) return $str; + + // 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. + + if (function_exists('html_entity_decode') && + (strtolower($charset) != 'utf-8')) + { + $str = html_entity_decode($str, ENT_COMPAT, $charset); + $str = preg_replace('~&#x(0*[0-9a-f]{2,5})~ei', 'chr(hexdec("\\1"))', $str); + return preg_replace('~&#([0-9]{2,4})~e', 'chr(\\1)', $str); + } + + // Numeric Entities + $str = preg_replace('~&#x(0*[0-9a-f]{2,5});{0,1}~ei', 'chr(hexdec("\\1"))', $str); + $str = preg_replace('~&#([0-9]{2,4});{0,1}~e', 'chr(\\1)', $str); + + // Literal Entities - Slightly slow so we do another check + if (stristr($str, '&') === FALSE) + { + $str = strtr($str, array_flip(get_html_translation_table(HTML_ENTITIES))); + } + + return $str; + } + + // -------------------------------------------------------------------- + + /** + * Filename Security + * + * @param string + * @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); + return stripslashes(str_replace($bad, '', $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 * - * @access private * @param type * @return type */ - private function _compact_exploded_words($matches) + 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'); + + 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 { + $str = preg_replace( + "#<(/?[^><]+?)([^A-Za-z\-])(".implode('|', $evil_attributes).")(\s*=\s*)([\"][^>]*?[\"]|[\'][^>]*?[\']|[^>]*?)([\s><])([><]*)#i", + "<$1$6", + $str, -1, $count + ); + } while ($count); + + return $str; + } + // -------------------------------------------------------------------- /** @@ -515,17 +606,17 @@ class CI_Security { * * Callback function for xss_clean() to remove naughty HTML elements * - * @access private * @param array * @return string */ - private function _sanitize_naughty_html($matches) + protected function _sanitize_naughty_html($matches) { // encode opening brace $str = '<'.$matches[1].$matches[2].$matches[3]; // encode captured opening or closing brace to prevent recursive vectors - $str .= str_replace(array('>', '<'), array('>', '<'), $matches[4]); + $str .= str_replace(array('>', '<'), array('>', '<'), + $matches[4]); return $str; } @@ -540,16 +631,18 @@ class CI_Security { * and prevents PREG_BACKTRACK_LIMIT_ERROR from being triggered in * PHP 5.2+ on link-heavy strings * - * @access private * @param array * @return string */ - private function _js_link_removal($match) + protected function _js_link_removal($match) { $attributes = $this->_filter_attributes(str_replace(array('<', '>'), '', $match[1])); - return str_replace($match[1], preg_replace("#href=.*?(alert\(|alert&\#40;|javascript\:|charset\=|window\.|document\.|\.cookie|_filter_attributes(str_replace(array('<', '>'), '', $match[1])); - return str_replace($match[1], preg_replace("#src=.*?(alert\(|alert&\#40;|javascript\:|charset\=|window\.|document\.|\.cookie|', '<', '\\'), array('>', '<', '\\\\'), $match[0]); } @@ -591,11 +683,10 @@ class CI_Security { * * Filters tag attributes for consistency and safety * - * @access private * @param string * @return string */ - private function _filter_attributes($str) + protected function _filter_attributes($str) { $out = ''; @@ -617,118 +708,109 @@ class CI_Security { * * Used as a callback for XSS Clean * - * @access private * @param array * @return string */ - private function _decode_entity($match) + protected function _decode_entity($match) { return $this->entity_decode($match[0], strtoupper(config_item('charset'))); } // -------------------------------------------------------------------- - + /** - * HTML Entities Decode - * - * This function is a replacement for html_entity_decode() - * - * In some versions of PHP the native function does not work - * when UTF-8 is the specified character set, so this gives us - * a work-around. More info here: - * http://bugs.php.net/bug.php?id=25670 + * Validate URL entities * - * NOTE: html_entity_decode() has a bug in some PHP versions when UTF-8 is the - * character set, and the PHP developers said they were not back porting the - * fix to versions other than PHP 5.x. + * Called by xss_clean() * - * @access public - * @param string - * @param string - * @return string + * @param string + * @return string */ - public function entity_decode($str, $charset='UTF-8') + protected function _validate_entities($str) { - if (stristr($str, '&') === FALSE) return $str; + /* + * Protect GET variables in URLs + */ + + // 901119URL5918AMP18930PROTECT8198 + + $str = preg_replace('|\&([a-z\_0-9\-]+)\=([a-z\_0-9\-]+)|i', $this->xss_hash()."\\1=\\2", $str); - // 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. + /* + * Validate standard character entities + * + * Add a semicolon if missing. We do this to enable + * the conversion of entities to ASCII later. + * + */ + $str = preg_replace('#(&\#?[0-9a-z]{2,})([\x00-\x20])*;?#i', "\\1;\\2", $str); - if (function_exists('html_entity_decode') && (strtolower($charset) != 'utf-8' OR is_php('5.0.0'))) - { - $str = html_entity_decode($str, ENT_COMPAT, $charset); - $str = preg_replace('~&#x(0*[0-9a-f]{2,5})~ei', 'chr(hexdec("\\1"))', $str); - return preg_replace('~&#([0-9]{2,4})~e', 'chr(\\1)', $str); - } + /* + * Validate UTF16 two byte encoding (x00) + * + * Just as above, adds a semicolon if missing. + * + */ + $str = preg_replace('#(&\#x?)([0-9A-F]+);?#i',"\\1\\2;",$str); - // Numeric Entities - $str = preg_replace('~&#x(0*[0-9a-f]{2,5});{0,1}~ei', 'chr(hexdec("\\1"))', $str); - $str = preg_replace('~&#([0-9]{2,4});{0,1}~e', 'chr(\\1)', $str); + /* + * Un-Protect GET variables in URLs + */ + $str = str_replace($this->xss_hash(), '&', $str); + + return $str; + } - // Literal Entities - Slightly slow so we do another check - if (stristr($str, '&') === FALSE) + // ---------------------------------------------------------------------- + + /** + * Do Never Allowed + * + * A utility function for xss_clean() + * + * @param string + * @return string + */ + protected function _do_never_allowed($str) + { + foreach ($this->_never_allowed_str as $key => $val) { - $str = strtr($str, array_flip(get_html_translation_table(HTML_ENTITIES))); + $str = str_replace($key, $val, $str); } + foreach ($this->_never_allowed_regex as $key => $val) + { + $str = preg_replace("#".$key."#i", $val, $str); + } + return $str; } // -------------------------------------------------------------------- /** - * Filename Security + * Set Cross Site Request Forgery Protection Cookie * - * @access public - * @param string * @return string */ - public function sanitize_filename($str, $relative_path = FALSE) + protected function _csrf_set_hash() { - $bad = array( - "../", - "", - "<", - ">", - "'", - '"', - '&', - '$', - '#', - '{', - '}', - '[', - ']', - '=', - ';', - '?', - "%20", - "%22", - "%3c", // < - "%253c", // < - "%3e", // > - "%0e", // > - "%28", // ( - "%29", // ) - "%2528", // ( - "%26", // & - "%24", // $ - "%3f", // ? - "%3b", // ; - "%3d" // = - ); - - if ( ! $relative_path) + if ($this->_csrf_hash == '') { - $bad[] = './'; - $bad[] = '/'; + // If the cookie exists we will use it's value. + // We don't necessarily want to regenerate it with + // each page load since a page could contain embedded + // sub-pages causing this feature to fail + if (isset($_COOKIE[$this->_csrf_cookie_name]) && + $_COOKIE[$this->_csrf_cookie_name] != '') + { + return $this->_csrf_hash = $_COOKIE[$this->_csrf_cookie_name]; + } + + return $this->_csrf_hash = md5(uniqid(rand(), TRUE)); } - return stripslashes(str_replace($bad, '', $str)); + return $this->_csrf_hash; } } -- cgit v1.2.3-24-g4f1b From 0ff50269e6bac31870a4d69bf4bc0bb895999f1f Mon Sep 17 00:00:00 2001 From: Pascal Kriete Date: Tue, 5 Apr 2011 14:52:03 -0400 Subject: tweaking remove_invisible_characters to make urlencoded character stripping optional --- system/core/Common.php | 28 +++++++++++++--------------- 1 file changed, 13 insertions(+), 15 deletions(-) (limited to 'system') diff --git a/system/core/Common.php b/system/core/Common.php index f424a2cc9..b4bd5b097 100644 --- a/system/core/Common.php +++ b/system/core/Common.php @@ -477,28 +477,26 @@ * @param string * @return string */ - function remove_invisible_characters($str) + function remove_invisible_characters($str, $url_encoded = TRUE) { - static $non_displayables; - - if ( ! isset($non_displayables)) + $non_displayables = array(); + + // every control character except newline (dec 10) + // carriage return (dec 13), and horizontal tab (dec 09) + + if ($url_encoded) { - // every control character except newline (dec 10), carriage return (dec 13), and horizontal tab (dec 09), - $non_displayables = array( - '/%0[0-8bcef]/', // url encoded 00-08, 11, 12, 14, 15 - '/%1[0-9a-f]/', // url encoded 16-31 - '/[\x00-\x08]/', // 00-08 - '/\x0b/', '/\x0c/', // 11, 12 - '/[\x0e-\x1f]/' // 14-31 - ); + $non_displayables[] = '/%0[0-8bcef]/'; // url encoded 00-08, 11, 12, 14, 15 + $non_displayables[] = '/%1[0-9a-f]/'; // url encoded 16-31 } + + $non_displayables[] = '/[\x00-\x08\x0B\x0C\x0E-\x1F\x7F]+/S'; // 00-08, 11, 12, 14-31, 127 do { - $cleaned = $str; - $str = preg_replace($non_displayables, '', $str); + $str = preg_replace($non_displayables, '', $str, -1, $count); } - while ($cleaned != $str); + while ($count); return $str; } -- cgit v1.2.3-24-g4f1b From 14a0ac63a9dfb72e4681c37f7727cd48882152bd Mon Sep 17 00:00:00 2001 From: Pascal Kriete Date: Tue, 5 Apr 2011 14:55:56 -0400 Subject: Moving security to core. --- system/core/CodeIgniter.php | 7 + system/core/Input.php | 16 +- system/core/Security.php | 820 ++++++++++++++++++++++++++++++++++++++++++ system/core/Utf8.php | 2 +- system/libraries/Security.php | 820 ------------------------------------------ 5 files changed, 835 insertions(+), 830 deletions(-) create mode 100644 system/core/Security.php delete mode 100644 system/libraries/Security.php (limited to 'system') diff --git a/system/core/CodeIgniter.php b/system/core/CodeIgniter.php index 39a4d7ffd..7f4595e68 100644 --- a/system/core/CodeIgniter.php +++ b/system/core/CodeIgniter.php @@ -196,6 +196,13 @@ } } +/* + * ----------------------------------------------------- + * Load the security class for xss and csrf support + * ----------------------------------------------------- + */ + $SEC =& load_class('Security', 'core'); + /* * ------------------------------------------------------ * Load the Input class and sanitize globals diff --git a/system/core/Input.php b/system/core/Input.php index 18131350f..dc7612e64 100644 --- a/system/core/Input.php +++ b/system/core/Input.php @@ -53,11 +53,8 @@ class CI_Input { $this->_enable_xss = (config_item('global_xss_filtering') === TRUE); $this->_enable_csrf = (config_item('csrf_protection') === TRUE); - // Do we need to load the security class? - if ($this->_enable_xss == TRUE OR $this->_enable_csrf == TRUE) - { - $this->security =& load_class('Security'); - } + global $SEC; + $this->security =& $SEC; // Do we need the UTF-8 class? if (UTF8_ENABLED === TRUE) @@ -92,8 +89,7 @@ class CI_Input { if ($xss_clean === TRUE) { - $_security =& load_class('Security'); - return $_security->xss_clean($array[$index]); + return $this->security->xss_clean($array[$index]); } return $array[$index]; @@ -527,6 +523,9 @@ class CI_Input { { $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) @@ -642,8 +641,7 @@ class CI_Input { if ($xss_clean === TRUE) { - $_security =& load_class('Security'); - return $_security->xss_clean($this->headers[$index]); + return $this->security->xss_clean($this->headers[$index]); } return $this->headers[$index]; diff --git a/system/core/Security.php b/system/core/Security.php new file mode 100644 index 000000000..ceef9779c --- /dev/null +++ b/system/core/Security.php @@ -0,0 +1,820 @@ + '[removed]', + 'document.write' => '[removed]', + '.parentNode' => '[removed]', + '.innerHTML' => '[removed]', + 'window.location' => '[removed]', + '-moz-binding' => '[removed]', + '' => '-->', + ' '<![CDATA[' + ); + + /* never allowed, regex replacement */ + protected $_never_allowed_regex = array( + "javascript\s*:" => '[removed]', + "expression\s*(\(|&\#40;)" => '[removed]', // CSS and IE + "vbscript\s*:" => '[removed]', // IE, surprise! + "Redirect\s+302" => '[removed]' + ); + + /** + * Constructor + */ + public function __construct() + { + // Append application specific cookie prefix to token name + $this->_csrf_cookie_name = (config_item('cookie_prefix')) ? config_item('cookie_prefix').$this->_csrf_token_name : $this->_csrf_token_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 no POST data exists we will set the CSRF cookie + if (count($_POST) == 0) + { + return $this->csrf_set_cookie(); + } + + // Do the tokens exist in both the _POST and _COOKIE arrays? + if ( ! isset($_POST[$this->_csrf_token_name]) OR + ! isset($_COOKIE[$this->_csrf_cookie_name])) + { + $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) + { + $req = isset($_SERVER['HTTPS']) ? $_SERVER['HTTPS'] : FALSE; + + if ( ! $req OR $req == '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 + * @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); + + // Validate Entities in URLs + $str = $this->_validate_entities($str); + + /* + * URL Decode + * + * Just in case stuff like this is submitted: + * + * Google + * + * Note: Use rawurldecode() so it does not remove plus signs + * + */ + $str = rawurldecode($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-z]+=([\'\"]).*?\\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. + */ + + if (strpos($str, "\t") !== FALSE) + { + $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', 'script', + 'applet', 'alert', 'document', 'write', 'cookie', 'window' + ); + + foreach ($words as $word) + { + $temp = ''; + + for ($i = 0, $wordlen = strlen($word); $i < $wordlen; $i++) + { + $temp .= substr($word, $i, 1)."\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($temp, 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 for PHP5, + * but it is dog slow compared to these simplified non-capturing + * preg_match(), especially if the pattern exists in the string + */ + 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/i", $str) OR preg_match("/xss/i", $str)) + { + $str = preg_replace("#<(/*)(script|xss)(.*?)\>#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|applet|audio|basefont|base|behavior|bgsound|blink|body|embed|expression|form|frameset|frame|head|html|ilayer|iframe|input|isindex|layer|link|meta|object|plaintext|style|script|textarea|title|video|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|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) ? TRUE: FALSE; + } + + log_message('debug', "XSS Filtering completed"); + return $str; + } + + // -------------------------------------------------------------------- + + /** + * Random Hash for protecting URLs + * + * @return string + */ + public function xss_hash() + { + if ($this->_xss_hash == '') + { + if (phpversion() >= 4.2) + { + mt_srand(); + } + else + { + mt_srand(hexdec(substr(md5(microtime()), -8)) & 0x7fffffff); + } + + $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() + * + * In some versions of PHP the native function does not work + * when UTF-8 is the specified character set, so this gives us + * a work-around. More info here: + * http://bugs.php.net/bug.php?id=25670 + * + * NOTE: html_entity_decode() has a bug in some PHP versions when UTF-8 is the + * character set, and the PHP developers said they were not back porting the + * fix to versions other than PHP 5.x. + * + * @param string + * @param string + * @return string + */ + public function entity_decode($str, $charset='UTF-8') + { + if (stristr($str, '&') === FALSE) return $str; + + // 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. + + if (function_exists('html_entity_decode') && + (strtolower($charset) != 'utf-8')) + { + $str = html_entity_decode($str, ENT_COMPAT, $charset); + $str = preg_replace('~&#x(0*[0-9a-f]{2,5})~ei', 'chr(hexdec("\\1"))', $str); + return preg_replace('~&#([0-9]{2,4})~e', 'chr(\\1)', $str); + } + + // Numeric Entities + $str = preg_replace('~&#x(0*[0-9a-f]{2,5});{0,1}~ei', 'chr(hexdec("\\1"))', $str); + $str = preg_replace('~&#([0-9]{2,4});{0,1}~e', 'chr(\\1)', $str); + + // Literal Entities - Slightly slow so we do another check + if (stristr($str, '&') === FALSE) + { + $str = strtr($str, array_flip(get_html_translation_table(HTML_ENTITIES))); + } + + return $str; + } + + // -------------------------------------------------------------------- + + /** + * Filename Security + * + * @param string + * @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); + return stripslashes(str_replace($bad, '', $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'); + + 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 { + $str = preg_replace( + "#<(/?[^><]+?)([^A-Za-z\-])(".implode('|', $evil_attributes).")(\s*=\s*)([\"][^>]*?[\"]|[\'][^>]*?[\']|[^>]*?)([\s><])([><]*)#i", + "<$1$6", + $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) + { + // encode opening brace + $str = '<'.$matches[1].$matches[2].$matches[3]; + + // encode captured opening or closing brace to prevent recursive vectors + $str .= str_replace(array('>', '<'), array('>', '<'), + $matches[4]); + + return $str; + } + + // -------------------------------------------------------------------- + + /** + * 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) + { + $attributes = $this->_filter_attributes(str_replace(array('<', '>'), '', $match[1])); + + return str_replace($match[1], preg_replace("#href=.*?(alert\(|alert&\#40;|javascript\:|livescript\:|mocha\:|charset\=|window\.|document\.|\.cookie|_filter_attributes(str_replace(array('<', '>'), '', $match[1])); + + return str_replace($match[1], preg_replace("#src=.*?(alert\(|alert&\#40;|javascript\:|livescript\:|mocha\:|charset\=|window\.|document\.|\.cookie|', '<', '\\'), 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) + { + return $this->entity_decode($match[0], strtoupper(config_item('charset'))); + } + + // -------------------------------------------------------------------- + + /** + * Validate URL entities + * + * Called by xss_clean() + * + * @param string + * @return string + */ + protected function _validate_entities($str) + { + /* + * Protect GET variables in URLs + */ + + // 901119URL5918AMP18930PROTECT8198 + + $str = preg_replace('|\&([a-z\_0-9\-]+)\=([a-z\_0-9\-]+)|i', $this->xss_hash()."\\1=\\2", $str); + + /* + * Validate standard character entities + * + * Add a semicolon if missing. We do this to enable + * the conversion of entities to ASCII later. + * + */ + $str = preg_replace('#(&\#?[0-9a-z]{2,})([\x00-\x20])*;?#i', "\\1;\\2", $str); + + /* + * Validate UTF16 two byte encoding (x00) + * + * Just as above, adds a semicolon if missing. + * + */ + $str = preg_replace('#(&\#x?)([0-9A-F]+);?#i',"\\1\\2;",$str); + + /* + * Un-Protect GET variables in URLs + */ + $str = str_replace($this->xss_hash(), '&', $str); + + return $str; + } + + // ---------------------------------------------------------------------- + + /** + * Do Never Allowed + * + * A utility function for xss_clean() + * + * @param string + * @return string + */ + protected function _do_never_allowed($str) + { + foreach ($this->_never_allowed_str as $key => $val) + { + $str = str_replace($key, $val, $str); + } + + foreach ($this->_never_allowed_regex as $key => $val) + { + $str = preg_replace("#".$key."#i", $val, $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]) && + $_COOKIE[$this->_csrf_cookie_name] != '') + { + return $this->_csrf_hash = $_COOKIE[$this->_csrf_cookie_name]; + } + + return $this->_csrf_hash = md5(uniqid(rand(), TRUE)); + } + + return $this->_csrf_hash; + } + +} +// END Security Class + +/* End of file Security.php */ +/* Location: ./system/libraries/Security.php */ \ No newline at end of file diff --git a/system/core/Utf8.php b/system/core/Utf8.php index 5d5a7ef72..2a27d1f35 100644 --- a/system/core/Utf8.php +++ b/system/core/Utf8.php @@ -107,7 +107,7 @@ class CI_Utf8 { */ function safe_ascii_for_xml($str) { - return preg_replace('/[\x00-\x08\x0B\x0C\x0E-\x1F\x7F]+/S', '', $str); + return remove_invisible_characters($str, FALSE); } // -------------------------------------------------------------------- diff --git a/system/libraries/Security.php b/system/libraries/Security.php deleted file mode 100644 index ceef9779c..000000000 --- a/system/libraries/Security.php +++ /dev/null @@ -1,820 +0,0 @@ - '[removed]', - 'document.write' => '[removed]', - '.parentNode' => '[removed]', - '.innerHTML' => '[removed]', - 'window.location' => '[removed]', - '-moz-binding' => '[removed]', - '' => '-->', - ' '<![CDATA[' - ); - - /* never allowed, regex replacement */ - protected $_never_allowed_regex = array( - "javascript\s*:" => '[removed]', - "expression\s*(\(|&\#40;)" => '[removed]', // CSS and IE - "vbscript\s*:" => '[removed]', // IE, surprise! - "Redirect\s+302" => '[removed]' - ); - - /** - * Constructor - */ - public function __construct() - { - // Append application specific cookie prefix to token name - $this->_csrf_cookie_name = (config_item('cookie_prefix')) ? config_item('cookie_prefix').$this->_csrf_token_name : $this->_csrf_token_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 no POST data exists we will set the CSRF cookie - if (count($_POST) == 0) - { - return $this->csrf_set_cookie(); - } - - // Do the tokens exist in both the _POST and _COOKIE arrays? - if ( ! isset($_POST[$this->_csrf_token_name]) OR - ! isset($_COOKIE[$this->_csrf_cookie_name])) - { - $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) - { - $req = isset($_SERVER['HTTPS']) ? $_SERVER['HTTPS'] : FALSE; - - if ( ! $req OR $req == '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 - * @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); - - // Validate Entities in URLs - $str = $this->_validate_entities($str); - - /* - * URL Decode - * - * Just in case stuff like this is submitted: - * - * Google - * - * Note: Use rawurldecode() so it does not remove plus signs - * - */ - $str = rawurldecode($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-z]+=([\'\"]).*?\\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. - */ - - if (strpos($str, "\t") !== FALSE) - { - $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', 'script', - 'applet', 'alert', 'document', 'write', 'cookie', 'window' - ); - - foreach ($words as $word) - { - $temp = ''; - - for ($i = 0, $wordlen = strlen($word); $i < $wordlen; $i++) - { - $temp .= substr($word, $i, 1)."\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($temp, 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 for PHP5, - * but it is dog slow compared to these simplified non-capturing - * preg_match(), especially if the pattern exists in the string - */ - 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/i", $str) OR preg_match("/xss/i", $str)) - { - $str = preg_replace("#<(/*)(script|xss)(.*?)\>#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|applet|audio|basefont|base|behavior|bgsound|blink|body|embed|expression|form|frameset|frame|head|html|ilayer|iframe|input|isindex|layer|link|meta|object|plaintext|style|script|textarea|title|video|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|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) ? TRUE: FALSE; - } - - log_message('debug', "XSS Filtering completed"); - return $str; - } - - // -------------------------------------------------------------------- - - /** - * Random Hash for protecting URLs - * - * @return string - */ - public function xss_hash() - { - if ($this->_xss_hash == '') - { - if (phpversion() >= 4.2) - { - mt_srand(); - } - else - { - mt_srand(hexdec(substr(md5(microtime()), -8)) & 0x7fffffff); - } - - $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() - * - * In some versions of PHP the native function does not work - * when UTF-8 is the specified character set, so this gives us - * a work-around. More info here: - * http://bugs.php.net/bug.php?id=25670 - * - * NOTE: html_entity_decode() has a bug in some PHP versions when UTF-8 is the - * character set, and the PHP developers said they were not back porting the - * fix to versions other than PHP 5.x. - * - * @param string - * @param string - * @return string - */ - public function entity_decode($str, $charset='UTF-8') - { - if (stristr($str, '&') === FALSE) return $str; - - // 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. - - if (function_exists('html_entity_decode') && - (strtolower($charset) != 'utf-8')) - { - $str = html_entity_decode($str, ENT_COMPAT, $charset); - $str = preg_replace('~&#x(0*[0-9a-f]{2,5})~ei', 'chr(hexdec("\\1"))', $str); - return preg_replace('~&#([0-9]{2,4})~e', 'chr(\\1)', $str); - } - - // Numeric Entities - $str = preg_replace('~&#x(0*[0-9a-f]{2,5});{0,1}~ei', 'chr(hexdec("\\1"))', $str); - $str = preg_replace('~&#([0-9]{2,4});{0,1}~e', 'chr(\\1)', $str); - - // Literal Entities - Slightly slow so we do another check - if (stristr($str, '&') === FALSE) - { - $str = strtr($str, array_flip(get_html_translation_table(HTML_ENTITIES))); - } - - return $str; - } - - // -------------------------------------------------------------------- - - /** - * Filename Security - * - * @param string - * @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); - return stripslashes(str_replace($bad, '', $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'); - - 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 { - $str = preg_replace( - "#<(/?[^><]+?)([^A-Za-z\-])(".implode('|', $evil_attributes).")(\s*=\s*)([\"][^>]*?[\"]|[\'][^>]*?[\']|[^>]*?)([\s><])([><]*)#i", - "<$1$6", - $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) - { - // encode opening brace - $str = '<'.$matches[1].$matches[2].$matches[3]; - - // encode captured opening or closing brace to prevent recursive vectors - $str .= str_replace(array('>', '<'), array('>', '<'), - $matches[4]); - - return $str; - } - - // -------------------------------------------------------------------- - - /** - * 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) - { - $attributes = $this->_filter_attributes(str_replace(array('<', '>'), '', $match[1])); - - return str_replace($match[1], preg_replace("#href=.*?(alert\(|alert&\#40;|javascript\:|livescript\:|mocha\:|charset\=|window\.|document\.|\.cookie|_filter_attributes(str_replace(array('<', '>'), '', $match[1])); - - return str_replace($match[1], preg_replace("#src=.*?(alert\(|alert&\#40;|javascript\:|livescript\:|mocha\:|charset\=|window\.|document\.|\.cookie|', '<', '\\'), 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) - { - return $this->entity_decode($match[0], strtoupper(config_item('charset'))); - } - - // -------------------------------------------------------------------- - - /** - * Validate URL entities - * - * Called by xss_clean() - * - * @param string - * @return string - */ - protected function _validate_entities($str) - { - /* - * Protect GET variables in URLs - */ - - // 901119URL5918AMP18930PROTECT8198 - - $str = preg_replace('|\&([a-z\_0-9\-]+)\=([a-z\_0-9\-]+)|i', $this->xss_hash()."\\1=\\2", $str); - - /* - * Validate standard character entities - * - * Add a semicolon if missing. We do this to enable - * the conversion of entities to ASCII later. - * - */ - $str = preg_replace('#(&\#?[0-9a-z]{2,})([\x00-\x20])*;?#i', "\\1;\\2", $str); - - /* - * Validate UTF16 two byte encoding (x00) - * - * Just as above, adds a semicolon if missing. - * - */ - $str = preg_replace('#(&\#x?)([0-9A-F]+);?#i',"\\1\\2;",$str); - - /* - * Un-Protect GET variables in URLs - */ - $str = str_replace($this->xss_hash(), '&', $str); - - return $str; - } - - // ---------------------------------------------------------------------- - - /** - * Do Never Allowed - * - * A utility function for xss_clean() - * - * @param string - * @return string - */ - protected function _do_never_allowed($str) - { - foreach ($this->_never_allowed_str as $key => $val) - { - $str = str_replace($key, $val, $str); - } - - foreach ($this->_never_allowed_regex as $key => $val) - { - $str = preg_replace("#".$key."#i", $val, $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]) && - $_COOKIE[$this->_csrf_cookie_name] != '') - { - return $this->_csrf_hash = $_COOKIE[$this->_csrf_cookie_name]; - } - - return $this->_csrf_hash = md5(uniqid(rand(), TRUE)); - } - - return $this->_csrf_hash; - } - -} -// END Security Class - -/* End of file Security.php */ -/* Location: ./system/libraries/Security.php */ \ No newline at end of file -- cgit v1.2.3-24-g4f1b From 6984aaf27f53b91ab1eafcdccd5fb871dfcd5f18 Mon Sep 17 00:00:00 2001 From: Pascal Kriete Date: Tue, 5 Apr 2011 14:58:04 -0400 Subject: Removing security loading calls. --- system/helpers/typography_helper.php | 5 ++--- system/libraries/Form_validation.php | 5 ----- system/libraries/Upload.php | 6 ------ system/libraries/Xmlrpc.php | 14 ++------------ 4 files changed, 4 insertions(+), 26 deletions(-) (limited to 'system') diff --git a/system/helpers/typography_helper.php b/system/helpers/typography_helper.php index 302bf45c5..19b4eec03 100644 --- a/system/helpers/typography_helper.php +++ b/system/helpers/typography_helper.php @@ -84,9 +84,8 @@ if ( ! function_exists('entity_decode')) { function entity_decode($str, $charset='UTF-8') { - $CI =& get_instance(); - $CI->load->library('security'); - return $CI->security->entity_decode($str, $charset); + global $SEC; + return $SEC->entity_decode($str, $charset); } } diff --git a/system/libraries/Form_validation.php b/system/libraries/Form_validation.php index adfd17db1..cfc02eda9 100644 --- a/system/libraries/Form_validation.php +++ b/system/libraries/Form_validation.php @@ -1336,11 +1336,6 @@ class CI_Form_validation { */ function xss_clean($str) { - if ( ! isset($this->CI->security)) - { - $this->CI->load->library('security'); - } - return $this->CI->security->xss_clean($str); } diff --git a/system/libraries/Upload.php b/system/libraries/Upload.php index 5816a5558..b62e0d73c 100644 --- a/system/libraries/Upload.php +++ b/system/libraries/Upload.php @@ -875,12 +875,6 @@ class CI_Upload { } $CI =& get_instance(); - - if ( ! isset($CI->security)) - { - $CI->load->library('security'); - } - return $CI->security->xss_clean($data, TRUE); } diff --git a/system/libraries/Xmlrpc.php b/system/libraries/Xmlrpc.php index a24bca9b6..5da6ea6ae 100644 --- a/system/libraries/Xmlrpc.php +++ b/system/libraries/Xmlrpc.php @@ -504,12 +504,7 @@ class XML_RPC_Response function decode($array=FALSE) { $CI =& get_instance(); - - if ($this->xss_clean && ! isset($CI->security)) - { - $CI->load->library('security'); - } - + if ($array !== FALSE && is_array($array)) { while (list($key) = each($array)) @@ -1121,12 +1116,7 @@ class XML_RPC_Message extends CI_Xmlrpc function output_parameters($array=FALSE) { $CI =& get_instance(); - - if ($this->xss_clean && ! isset($CI->security)) - { - $CI->load->library('security'); - } - + if ($array !== FALSE && is_array($array)) { while (list($key) = each($array)) -- cgit v1.2.3-24-g4f1b From 73598e3ced570c42128ec5e90d67f509bd24fa5d Mon Sep 17 00:00:00 2001 From: Pascal Kriete Date: Tue, 5 Apr 2011 15:01:05 -0400 Subject: Tightening up control character handling in urls --- system/core/URI.php | 57 ++++++++++++++++++++++++++++++++--------------------- 1 file changed, 34 insertions(+), 23 deletions(-) (limited to 'system') diff --git a/system/core/URI.php b/system/core/URI.php index c43cde005..80dc62e58 100644 --- a/system/core/URI.php +++ b/system/core/URI.php @@ -64,14 +64,14 @@ class CI_URI { // Is the request coming from the command line? if (defined('STDIN')) { - $this->uri_string = $this->_parse_cli_args(); + $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->uri_string = $uri; + $this->_set_uri_string($uri); return; } @@ -80,7 +80,7 @@ class CI_URI { $path = (isset($_SERVER['PATH_INFO'])) ? $_SERVER['PATH_INFO'] : @getenv('PATH_INFO'); if (trim($path, '/') != '' && $path != "/".SELF) { - $this->uri_string = $path; + $this->_set_uri_string($path); return; } @@ -88,43 +88,54 @@ class CI_URI { $path = (isset($_SERVER['QUERY_STRING'])) ? $_SERVER['QUERY_STRING'] : @getenv('QUERY_STRING'); if (trim($path, '/') != '') { - $this->uri_string = $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->uri_string = key($_GET); + $this->_set_uri_string(key($_GET)); return; } // We've exhausted all our options... $this->uri_string = ''; + return; } - else - { - $uri = strtoupper($this->config->item('uri_protocol')); - if ($uri == 'REQUEST_URI') - { - $this->uri_string = $this->_detect_uri(); - return; - } - elseif ($uri == 'CLI') - { - $this->uri_string = $this->_parse_cli_args(); - return; - } + $uri = strtoupper($this->config->item('uri_protocol')); - $this->uri_string = (isset($_SERVER[$uri])) ? $_SERVER[$uri] : @getenv($uri); + if ($uri == 'REQUEST_URI') + { + $this->_set_uri_string($this->_detect_uri()); + return; } - - // If the URI contains only a slash we'll kill it - if ($this->uri_string == '/') + elseif ($uri == 'CLI') { - $this->uri_string = ''; + $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 + * @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; } // -------------------------------------------------------------------- -- cgit v1.2.3-24-g4f1b From 6b488674368cf695a228e87e7d8e0f4f40fe4181 Mon Sep 17 00:00:00 2001 From: Pascal Kriete Date: Tue, 5 Apr 2011 15:02:15 -0400 Subject: Removing dohash and deprecating CI_SHA --- system/helpers/security_helper.php | 34 +--------------------------------- 1 file changed, 1 insertion(+), 33 deletions(-) (limited to 'system') diff --git a/system/helpers/security_helper.php b/system/helpers/security_helper.php index 61ebf46f9..678dac821 100644 --- a/system/helpers/security_helper.php +++ b/system/helpers/security_helper.php @@ -64,22 +64,6 @@ if ( ! function_exists('sanitize_filename')) // -------------------------------------------------------------------- -/** - * Hash encode a string - * - * This is simply an alias for do_hash() - * dohash() is now deprecated - */ -if ( ! function_exists('dohash')) -{ - function dohash($str, $type = 'sha1') - { - return do_hash($str, $type); - } -} - -// -------------------------------------------------------------------- - /** * Hash encode a string * @@ -93,23 +77,7 @@ if ( ! function_exists('do_hash')) { if ($type == 'sha1') { - if ( ! function_exists('sha1')) - { - if ( ! function_exists('mhash')) - { - require_once(BASEPATH.'libraries/Sha1'.EXT); - $SH = new CI_SHA; - return $SH->generate($str); - } - else - { - return bin2hex(mhash(MHASH_SHA1, $str)); - } - } - else - { - return sha1($str); - } + return sha1($str); } else { -- cgit v1.2.3-24-g4f1b From f1bd6fa78a3235ade2365a43bb5124ff72807c96 Mon Sep 17 00:00:00 2001 From: Pascal Kriete Date: Tue, 5 Apr 2011 15:04:28 -0400 Subject: Fixed a bug in the Javascript Library where improperly escaped characters could result in arbitrary javascript execution. --- system/libraries/Javascript.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system') diff --git a/system/libraries/Javascript.php b/system/libraries/Javascript.php index 167859abd..34e0d7001 100644 --- a/system/libraries/Javascript.php +++ b/system/libraries/Javascript.php @@ -855,7 +855,7 @@ class CI_Javascript { } elseif (is_string($result) OR $is_key) { - return '"'.str_replace(array('\\', "\t", "\n", "\r", '"'), array('\\\\', '\\t', '\\n', "\\r", '\"'), $result).'"'; + return '"'.str_replace(array('\\', "\t", "\n", "\r", '"', '/'), array('\\\\', '\\t', '\\n', "\\r", '\"', '\/'), $result).'"'; } elseif (is_scalar($result)) { -- cgit v1.2.3-24-g4f1b From 05fa61144667c85b0463f7e8baa6af00aa195dc6 Mon Sep 17 00:00:00 2001 From: Phil Sturgeon Date: Wed, 6 Apr 2011 22:57:43 +0100 Subject: Made Environment Support optional. Comment out or delete the constant to stop environment checks. --- system/core/CodeIgniter.php | 2 +- system/core/Common.php | 15 +++++++------- system/core/Config.php | 42 +++++++++++++++++++++++--------------- system/core/Hooks.php | 2 +- system/core/Loader.php | 6 +++--- system/core/Output.php | 2 +- system/core/Router.php | 2 +- system/database/DB.php | 13 ++++-------- system/helpers/download_helper.php | 2 +- system/helpers/file_helper.php | 2 +- system/helpers/html_helper.php | 2 +- system/helpers/smiley_helper.php | 15 +++++--------- system/helpers/text_helper.php | 2 +- system/libraries/Upload.php | 2 +- system/libraries/User_agent.php | 2 +- 15 files changed, 54 insertions(+), 57 deletions(-) (limited to 'system') diff --git a/system/core/CodeIgniter.php b/system/core/CodeIgniter.php index 39a4d7ffd..143faec15 100644 --- a/system/core/CodeIgniter.php +++ b/system/core/CodeIgniter.php @@ -53,7 +53,7 @@ * Load the framework constants * ------------------------------------------------------ */ - if (file_exists(APPPATH.'config/'.ENVIRONMENT.'/constants'.EXT)) + if (defined('ENVIRONMENT') AND file_exists(APPPATH.'config/'.ENVIRONMENT.'/constants'.EXT)) { require(APPPATH.'config/'.ENVIRONMENT.'/constants'.EXT); } diff --git a/system/core/Common.php b/system/core/Common.php index f424a2cc9..d7054ebe6 100644 --- a/system/core/Common.php +++ b/system/core/Common.php @@ -208,19 +208,18 @@ return $_config[0]; } - $file_path = APPPATH.'config/'.ENVIRONMENT.'/config'.EXT; + // Is the config file in the environment folder? + if ( ! defined('ENVIRONMENT') OR ! file_exists($file_path = APPPATH.'config/'.ENVIRONMENT.'/config'.EXT)) + { + $file_path = APPPATH.'config/config'.EXT; + } // Fetch the config file if ( ! file_exists($file_path)) { - $file_path = APPPATH.'config/config'.EXT; - - if ( ! file_exists($file_path)) - { - exit('The configuration file does not exist.'); - } + exit('The configuration file does not exist.'); } - + require($file_path); // Does the $config array exist in the file? diff --git a/system/core/Config.php b/system/core/Config.php index a2a7dd564..863c5ef4b 100644 --- a/system/core/Config.php +++ b/system/core/Config.php @@ -81,29 +81,37 @@ class CI_Config { function load($file = '', $use_sections = FALSE, $fail_gracefully = FALSE) { $file = ($file == '') ? 'config' : str_replace(EXT, '', $file); + $found = FALSE; $loaded = FALSE; foreach ($this->_config_paths as $path) - { - $file_path = $path.'config/'.ENVIRONMENT.'/'.$file.EXT; + { + $check_locations = defined('ENVIRONMENT') + ? array(ENVIRONMENT.'/'.$file, $file) + : array($file); - if (in_array($file_path, $this->is_loaded, TRUE)) + foreach ($check_locations as $location) { - $loaded = TRUE; - continue; - } + $file_path = $path.'config/'.$location.EXT; - if ( ! file_exists($file_path)) - { - log_message('debug', 'Config for '.ENVIRONMENT.' environment is not found. Trying global config.'); - $file_path = $path.'config/'.$file.EXT; - - if ( ! file_exists($file_path)) + if (in_array($file_path, $this->is_loaded, TRUE)) + { + $loaded = TRUE; + continue 2; + } + + if (file_exists($file_path)) { - continue; + $found = TRUE; + break; } } - + + if ($found === FALSE) + { + continue; + } + include($file_path); if ( ! isset($config) OR ! is_array($config)) @@ -144,9 +152,9 @@ class CI_Config { { return FALSE; } - show_error('The configuration file '.ENVIRONMENT.'/'.$file.EXT.' and '.$file.EXT.' do not exist.'); + show_error('The configuration file '.$file.EXT.' does not exist.'); } - + return TRUE; } @@ -318,4 +326,4 @@ class CI_Config { // END CI_Config class /* End of file Config.php */ -/* Location: ./system/core/Config.php */ +/* Location: ./system/core/Config.php */ \ No newline at end of file diff --git a/system/core/Hooks.php b/system/core/Hooks.php index d1e5586de..24fa1055b 100644 --- a/system/core/Hooks.php +++ b/system/core/Hooks.php @@ -65,7 +65,7 @@ class CI_Hooks { // Grab the "hooks" definition file. // If there are no hooks, we're done. - if (is_file(APPPATH.'config/'.ENVIRONMENT.'/hooks'.EXT)) + if (defined('ENVIRONMENT') AND is_file(APPPATH.'config/'.ENVIRONMENT.'/hooks'.EXT)) { include(APPPATH.'config/'.ENVIRONMENT.'/hooks'.EXT); } diff --git a/system/core/Loader.php b/system/core/Loader.php index 278a868e6..e75805d0e 100644 --- a/system/core/Loader.php +++ b/system/core/Loader.php @@ -872,12 +872,12 @@ class CI_Loader { // 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 (file_exists($path .'config/'.ENVIRONMENT.'/'.strtolower($class).EXT)) + if (defined('ENVIRONMENT') AND file_exists($path .'config/'.ENVIRONMENT.'/'.strtolower($class).EXT)) { include_once($path .'config/'.ENVIRONMENT.'/'.strtolower($class).EXT); break; } - elseif (file_exists($path .'config/'.ENVIRONMENT.'/'.ucfirst(strtolower($class)).EXT)) + elseif (defined('ENVIRONMENT') AND file_exists($path .'config/'.ENVIRONMENT.'/'.ucfirst(strtolower($class)).EXT)) { include_once($path .'config/'.ENVIRONMENT.'/'.ucfirst(strtolower($class)).EXT); break; @@ -965,7 +965,7 @@ class CI_Loader { */ function _ci_autoloader() { - if (file_exists(APPPATH.'config/'.ENVIRONMENT.'/autoload'.EXT)) + if (defined('ENVIRONMENT') AND file_exists(APPPATH.'config/'.ENVIRONMENT.'/autoload'.EXT)) { include_once(APPPATH.'config/'.ENVIRONMENT.'/autoload'.EXT); } diff --git a/system/core/Output.php b/system/core/Output.php index 5ec096a47..bcba2577a 100644 --- a/system/core/Output.php +++ b/system/core/Output.php @@ -42,7 +42,7 @@ class CI_Output { $this->_zlib_oc = @ini_get('zlib.output_compression'); // Get mime types for later - if (file_exists(APPPATH.'config/'.ENVIRONMENT.'/mimes'.EXT)) + if (defined('ENVIRONMENT') AND file_exists(APPPATH.'config/'.ENVIRONMENT.'/mimes'.EXT)) { include APPPATH.'config/'.ENVIRONMENT.'/mimes'.EXT; } diff --git a/system/core/Router.php b/system/core/Router.php index 2c78efe07..d451aab68 100644 --- a/system/core/Router.php +++ b/system/core/Router.php @@ -87,7 +87,7 @@ class CI_Router { } // Load the routes.php file. - if (is_file(APPPATH.'config/'.ENVIRONMENT.'/routes'.EXT)) + if (defined('ENVIRONMENT') AND is_file(APPPATH.'config/'.ENVIRONMENT.'/routes'.EXT)) { include(APPPATH.'config/'.ENVIRONMENT.'/routes'.EXT); } diff --git a/system/database/DB.php b/system/database/DB.php index 93ee3922a..8bf1ba8ba 100644 --- a/system/database/DB.php +++ b/system/database/DB.php @@ -27,17 +27,12 @@ function &DB($params = '', $active_record_override = NULL) // Load the DB config file if a DSN string wasn't passed if (is_string($params) AND strpos($params, '://') === FALSE) { - - $file_path = APPPATH.'config/'.ENVIRONMENT.'/database'.EXT; - - if ( ! file_exists($file_path)) + // Is the config file in the environment folder? + if ( ! defined('ENVIRONMENT') OR ! file_exists($file_path = APPPATH.'config/'.ENVIRONMENT.'/database'.EXT)) { - log_message('debug', 'Database config for '.ENVIRONMENT.' environment is not found. Trying global config.'); - $file_path = APPPATH.'config/database'.EXT; - - if ( ! file_exists($file_path)) + if ( ! file_exists($file_path = APPPATH.'config/database'.EXT)) { - continue; + show_error('The configuration file database'.EXT.' does not exist.'); } } diff --git a/system/helpers/download_helper.php b/system/helpers/download_helper.php index e537cdeca..f8073d238 100644 --- a/system/helpers/download_helper.php +++ b/system/helpers/download_helper.php @@ -58,7 +58,7 @@ if ( ! function_exists('force_download')) $extension = end($x); // Load the mime types - if (is_file(APPPATH.'config/'.ENVIRONMENT.'/mimes'.EXT)) + if (defined('ENVIRONMENT') AND is_file(APPPATH.'config/'.ENVIRONMENT.'/mimes'.EXT)) { include(APPPATH.'config/'.ENVIRONMENT.'/mimes'.EXT); } diff --git a/system/helpers/file_helper.php b/system/helpers/file_helper.php index 7a35c3fa1..44344947e 100644 --- a/system/helpers/file_helper.php +++ b/system/helpers/file_helper.php @@ -352,7 +352,7 @@ if ( ! function_exists('get_mime_by_extension')) if ( ! is_array($mimes)) { - if (is_file(APPPATH.'config/'.ENVIRONMENT.'/mimes'.EXT)) + if (defined('ENVIRONMENT') AND is_file(APPPATH.'config/'.ENVIRONMENT.'/mimes'.EXT)) { include(APPPATH.'config/'.ENVIRONMENT.'/mimes'.EXT); } diff --git a/system/helpers/html_helper.php b/system/helpers/html_helper.php index 53fc899a3..c6103ab6f 100644 --- a/system/helpers/html_helper.php +++ b/system/helpers/html_helper.php @@ -258,7 +258,7 @@ if ( ! function_exists('doctype')) if ( ! is_array($_doctypes)) { - if (is_file(APPPATH.'config/'.ENVIRONMENT.'/doctypes'.EXT)) + if (defined('ENVIRONMENT') AND is_file(APPPATH.'config/'.ENVIRONMENT.'/doctypes'.EXT)) { include(APPPATH.'config/'.ENVIRONMENT.'/doctypes'.EXT); } diff --git a/system/helpers/smiley_helper.php b/system/helpers/smiley_helper.php index 6c901515d..a2d1031b3 100644 --- a/system/helpers/smiley_helper.php +++ b/system/helpers/smiley_helper.php @@ -229,26 +229,21 @@ if ( ! function_exists('_get_smiley_array')) { function _get_smiley_array() { - if ( ! file_exists(APPPATH.'config/smileys'.EXT) AND ! file_exists(APPPATH.'config/'.ENVIRONMENT.'/smileys'.EXT)) - { - return FALSE; - } - - if (file_exists(APPPATH.'config/'.ENVIRONMENT.'/smileys'.EXT)) + if (defined('ENVIRONMENT') AND file_exists(APPPATH.'config/'.ENVIRONMENT.'/smileys'.EXT)) { include(APPPATH.'config/'.ENVIRONMENT.'/smileys'.EXT); } - else + elseif (file_exists(APPPATH.'config/smileys'.EXT)) { include(APPPATH.'config/smileys'.EXT); } - if ( ! isset($smileys) OR ! is_array($smileys)) + if (isset($smileys) AND is_array($smileys)) { - return FALSE; + return $smileys; } - return $smileys; + return FALSE; } } diff --git a/system/helpers/text_helper.php b/system/helpers/text_helper.php index 664408912..cca093976 100644 --- a/system/helpers/text_helper.php +++ b/system/helpers/text_helper.php @@ -366,7 +366,7 @@ if ( ! function_exists('convert_accented_characters')) { function convert_accented_characters($str) { - if (is_file(APPPATH.'config/'.ENVIRONMENT.'/foreign_chars'.EXT)) + if (defined('ENVIRONMENT') AND is_file(APPPATH.'config/'.ENVIRONMENT.'/foreign_chars'.EXT)) { include(APPPATH.'config/'.ENVIRONMENT.'/foreign_chars'.EXT); } diff --git a/system/libraries/Upload.php b/system/libraries/Upload.php index 5816a5558..3cd2e4fc1 100644 --- a/system/libraries/Upload.php +++ b/system/libraries/Upload.php @@ -951,7 +951,7 @@ class CI_Upload { if (count($this->mimes) == 0) { - if (is_file(APPPATH.'config/'.ENVIRONMENT.'/mimes'.EXT)) + if (defined('ENVIRONMENT') AND is_file(APPPATH.'config/'.ENVIRONMENT.'/mimes'.EXT)) { include(APPPATH.'config/'.ENVIRONMENT.'/mimes'.EXT); } diff --git a/system/libraries/User_agent.php b/system/libraries/User_agent.php index 11af21491..04cda7312 100644 --- a/system/libraries/User_agent.php +++ b/system/libraries/User_agent.php @@ -84,7 +84,7 @@ class CI_User_agent { */ private function _load_agent_file() { - if (is_file(APPPATH.'config/'.ENVIRONMENT.'/user_agents'.EXT)) + if (defined('ENVIRONMENT') AND is_file(APPPATH.'config/'.ENVIRONMENT.'/user_agents'.EXT)) { include(APPPATH.'config/'.ENVIRONMENT.'/user_agents'.EXT); } -- cgit v1.2.3-24-g4f1b From f2f4ea49cccc8a8a14ec5f1b71fdba54b1990603 Mon Sep 17 00:00:00 2001 From: Phil Sturgeon Date: Wed, 6 Apr 2011 23:26:10 +0100 Subject: Made in Output protected again, it was only ever made public by Eric to fix an issue with the Dwoo MY_Parser, which is no reason to change core files. That Parser doesn't really even need the acess. --- system/core/Output.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system') diff --git a/system/core/Output.php b/system/core/Output.php index bcba2577a..45a82f3cb 100644 --- a/system/core/Output.php +++ b/system/core/Output.php @@ -28,7 +28,6 @@ */ class CI_Output { - public $parse_exec_vars = TRUE; // whether or not to parse variables like {elapsed_time} and {memory_usage} protected $final_output; protected $cache_expiration = 0; protected $headers = array(); @@ -36,6 +35,7 @@ class CI_Output { protected $enable_profiler = FALSE; protected $_zlib_oc = FALSE; protected $_profiler_sections = array(); + protected $parse_exec_vars = TRUE; // whether or not to parse variables like {elapsed_time} and {memory_usage} function __construct() { -- cgit v1.2.3-24-g4f1b From 1f6f0abf0d17046a99fd9c9b3c60fb459b4531b1 Mon Sep 17 00:00:00 2001 From: Greg Aker Date: Thu, 7 Apr 2011 18:24:53 -0500 Subject: Fixing a bug in the form_helper where csrf_token_name and csrf_hash were referencing class properties in the Security class that were moved. --- system/helpers/form_helper.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system') diff --git a/system/helpers/form_helper.php b/system/helpers/form_helper.php index 8aa788c6c..acd75c239 100644 --- a/system/helpers/form_helper.php +++ b/system/helpers/form_helper.php @@ -67,7 +67,7 @@ if ( ! function_exists('form_open')) // CSRF if ($CI->config->item('csrf_protection') === TRUE) { - $hidden[$CI->security->csrf_token_name] = $CI->security->csrf_hash; + $hidden[$CI->security->get_csrf_token_name()] = $CI->security->get_csrf_hash(); } if (is_array($hidden) AND count($hidden) > 0) -- cgit v1.2.3-24-g4f1b From bfbcf74c94a47c643420efaa342cc525bce2ad2c Mon Sep 17 00:00:00 2001 From: Greg Aker Date: Thu, 7 Apr 2011 18:33:29 -0500 Subject: Fix: #192 CI version constant incorrect in core/CodeIgniter --- system/core/CodeIgniter.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system') diff --git a/system/core/CodeIgniter.php b/system/core/CodeIgniter.php index f3e1439ff..e022e1b46 100644 --- a/system/core/CodeIgniter.php +++ b/system/core/CodeIgniter.php @@ -32,7 +32,7 @@ * Define the CodeIgniter Version * ------------------------------------------------------ */ - define('CI_VERSION', '2.0.1'); + define('CI_VERSION', '2.0.2'); /* * ------------------------------------------------------ -- cgit v1.2.3-24-g4f1b From 48bac74ea9fcb8eecdf97597647f1ed492d97b43 Mon Sep 17 00:00:00 2001 From: patwork Date: Fri, 8 Apr 2011 13:46:47 +0200 Subject: Fix: codeigniter-reactor/193 incorrect driver filepaths --- system/libraries/Driver.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'system') diff --git a/system/libraries/Driver.php b/system/libraries/Driver.php index d1838f2c1..b942f539f 100644 --- a/system/libraries/Driver.php +++ b/system/libraries/Driver.php @@ -45,7 +45,7 @@ class CI_Driver_Library { $child_class = $this->lib_name.'_'.$child; // Remove the CI_ prefix and lowercase - $lib_name = strtolower(preg_replace('/^CI_/', '', $this->lib_name)); + $lib_name = ucfirst(strtolower(preg_replace('/^CI_/', '', $this->lib_name))); $driver_name = strtolower(preg_replace('/^CI_/', '', $child_class)); if (in_array($driver_name, array_map('strtolower', $this->valid_drivers))) @@ -226,4 +226,4 @@ class CI_Driver { // END CI_Driver CLASS /* End of file Driver.php */ -/* Location: ./system/libraries/Driver.php */ \ No newline at end of file +/* Location: ./system/libraries/Driver.php */ -- cgit v1.2.3-24-g4f1b From b07079827b084213463bdf576894faab172213f2 Mon Sep 17 00:00:00 2001 From: patwork Date: Fri, 8 Apr 2011 15:10:05 +0200 Subject: Deals with language errors after codeigniter-reactor commit r2307:c43c6dea56fb --- system/libraries/Email.php | 44 ++++++++++++++++++++++---------------------- 1 file changed, 22 insertions(+), 22 deletions(-) (limited to 'system') diff --git a/system/libraries/Email.php b/system/libraries/Email.php index 6c21f114d..cd89f8f3d 100644 --- a/system/libraries/Email.php +++ b/system/libraries/Email.php @@ -722,7 +722,7 @@ class CI_Email { { if ( ! is_array($email)) { - $this->_set_error_message('email_must_be_array'); + $this->_set_error_message('lang:email_must_be_array'); return FALSE; } @@ -730,7 +730,7 @@ class CI_Email { { if ( ! $this->valid_email($val)) { - $this->_set_error_message('email_invalid_address', $val); + $this->_set_error_message('lang:email_invalid_address', $val); return FALSE; } } @@ -1131,7 +1131,7 @@ class CI_Email { if ( ! file_exists($filename)) { - $this->_set_error_message('email_attachment_missing', $filename); + $this->_set_error_message('lang:email_attachment_missing', $filename); return FALSE; } @@ -1146,7 +1146,7 @@ class CI_Email { if ( ! $fp = fopen($filename, FOPEN_READ)) { - $this->_set_error_message('email_attachment_unreadable', $filename); + $this->_set_error_message('lang:email_attachment_unreadable', $filename); return FALSE; } @@ -1353,7 +1353,7 @@ class CI_Email { ( ! isset($this->_bcc_array) AND ! isset($this->_headers['Bcc'])) AND ( ! isset($this->_headers['Cc']))) { - $this->_set_error_message('email_no_recipients'); + $this->_set_error_message('lang:email_no_recipients'); return FALSE; } @@ -1484,7 +1484,7 @@ class CI_Email { if ( ! $this->_send_with_mail()) { - $this->_set_error_message('email_send_failure_phpmail'); + $this->_set_error_message('lang:email_send_failure_phpmail'); return FALSE; } break; @@ -1492,7 +1492,7 @@ class CI_Email { if ( ! $this->_send_with_sendmail()) { - $this->_set_error_message('email_send_failure_sendmail'); + $this->_set_error_message('lang:email_send_failure_sendmail'); return FALSE; } break; @@ -1500,14 +1500,14 @@ class CI_Email { if ( ! $this->_send_with_smtp()) { - $this->_set_error_message('email_send_failure_smtp'); + $this->_set_error_message('lang:email_send_failure_smtp'); return FALSE; } break; } - $this->_set_error_message('email_sent', $this->_get_protocol()); + $this->_set_error_message('lang:email_sent', $this->_get_protocol()); return TRUE; } @@ -1578,8 +1578,8 @@ class CI_Email { if ($status != 0) { - $this->_set_error_message('email_exit_status', $status); - $this->_set_error_message('email_no_socket'); + $this->_set_error_message('lang:email_exit_status', $status); + $this->_set_error_message('lang:email_no_socket'); return FALSE; } @@ -1598,7 +1598,7 @@ class CI_Email { { if ($this->smtp_host == '') { - $this->_set_error_message('email_no_hostname'); + $this->_set_error_message('lang:email_no_hostname'); return FALSE; } @@ -1647,7 +1647,7 @@ class CI_Email { if (strncmp($reply, '250', 3) != 0) { - $this->_set_error_message('email_smtp_error', $reply); + $this->_set_error_message('lang:email_smtp_error', $reply); return FALSE; } @@ -1674,7 +1674,7 @@ class CI_Email { if ( ! is_resource($this->_smtp_connect)) { - $this->_set_error_message('email_smtp_error', $errno." ".$errstr); + $this->_set_error_message('lang:email_smtp_error', $errno." ".$errstr); return FALSE; } @@ -1737,7 +1737,7 @@ class CI_Email { if (substr($reply, 0, 3) != $resp) { - $this->_set_error_message('email_smtp_error', $reply); + $this->_set_error_message('lang:email_smtp_error', $reply); return FALSE; } @@ -1766,7 +1766,7 @@ class CI_Email { if ($this->smtp_user == "" AND $this->smtp_pass == "") { - $this->_set_error_message('email_no_smtp_unpw'); + $this->_set_error_message('lang:email_no_smtp_unpw'); return FALSE; } @@ -1776,7 +1776,7 @@ class CI_Email { if (strncmp($reply, '334', 3) != 0) { - $this->_set_error_message('email_failed_smtp_login', $reply); + $this->_set_error_message('lang:email_failed_smtp_login', $reply); return FALSE; } @@ -1786,7 +1786,7 @@ class CI_Email { if (strncmp($reply, '334', 3) != 0) { - $this->_set_error_message('email_smtp_auth_un', $reply); + $this->_set_error_message('lang:email_smtp_auth_un', $reply); return FALSE; } @@ -1796,7 +1796,7 @@ class CI_Email { if (strncmp($reply, '235', 3) != 0) { - $this->_set_error_message('email_smtp_auth_pw', $reply); + $this->_set_error_message('lang:email_smtp_auth_pw', $reply); return FALSE; } @@ -1815,7 +1815,7 @@ class CI_Email { { if ( ! fwrite($this->_smtp_connect, $data . $this->newline)) { - $this->_set_error_message('email_smtp_data_failure', $data); + $this->_set_error_message('lang:email_smtp_data_failure', $data); return FALSE; } else @@ -1942,7 +1942,7 @@ class CI_Email { $CI =& get_instance(); $CI->lang->load('email'); - if (FALSE === ($line = $CI->lang->line($msg))) + if (substr($msg, 0, 5) != 'lang:' || FALSE === ($line = $CI->lang->line(substr($msg, 5)))) { $this->_debug_msg[] = str_replace('%s', $val, $msg)."
    "; } @@ -2059,4 +2059,4 @@ class CI_Email { // END CI_Email class /* End of file Email.php */ -/* Location: ./system/libraries/Email.php */ \ No newline at end of file +/* Location: ./system/libraries/Email.php */ -- cgit v1.2.3-24-g4f1b From 64e35cdcb9fd24787798c0f6ca3c0af45b0b904d Mon Sep 17 00:00:00 2001 From: patwork Date: Fri, 8 Apr 2011 15:25:31 +0200 Subject: There is absolutely no need to specify class name (it will validate anyway). --- system/helpers/form_helper.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'system') diff --git a/system/helpers/form_helper.php b/system/helpers/form_helper.php index acd75c239..bca0ff0c9 100644 --- a/system/helpers/form_helper.php +++ b/system/helpers/form_helper.php @@ -72,7 +72,7 @@ if ( ! function_exists('form_open')) if (is_array($hidden) AND count($hidden) > 0) { - $form .= sprintf("\n
    %s
    ", form_hidden($hidden)); + $form .= sprintf("\n
    %s
    ", form_hidden($hidden)); } return $form; @@ -1053,4 +1053,4 @@ if ( ! function_exists('_get_validation_object')) /* End of file form_helper.php */ -/* Location: ./system/helpers/form_helper.php */ \ No newline at end of file +/* Location: ./system/helpers/form_helper.php */ -- cgit v1.2.3-24-g4f1b From 02404a1f59e4f3ae8231d87d8be5b23488ea86d2 Mon Sep 17 00:00:00 2001 From: patwork Date: Fri, 8 Apr 2011 15:45:46 +0200 Subject: Fix: codeigniter-reactor/127 Form_validation rule error logging --- system/libraries/Form_validation.php | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'system') diff --git a/system/libraries/Form_validation.php b/system/libraries/Form_validation.php index cfc02eda9..6f79a554a 100644 --- a/system/libraries/Form_validation.php +++ b/system/libraries/Form_validation.php @@ -628,6 +628,10 @@ class CI_Form_validation { $this->_field_data[$row['field']]['postdata'] = (is_bool($result)) ? $postdata : $result; } } + else + { + log_message('debug', "Unable to find validation rule: ".$rule); + } continue; } @@ -1357,4 +1361,4 @@ class CI_Form_validation { // END Form Validation Class /* End of file Form_validation.php */ -/* Location: ./system/libraries/Form_validation.php */ \ No newline at end of file +/* Location: ./system/libraries/Form_validation.php */ -- cgit v1.2.3-24-g4f1b From ef1a55ad2875af3b2286a5b6eb9b65e997949f4d Mon Sep 17 00:00:00 2001 From: patwork Date: Sat, 9 Apr 2011 13:04:06 +0200 Subject: Fix: codeigniter-reactor/199 CSRF config in Security class is no longer ignored --- system/core/Security.php | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) (limited to 'system') diff --git a/system/core/Security.php b/system/core/Security.php index ceef9779c..73a3cfb31 100644 --- a/system/core/Security.php +++ b/system/core/Security.php @@ -58,6 +58,15 @@ class CI_Security { */ public function __construct() { + // 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 to token name $this->_csrf_cookie_name = (config_item('cookie_prefix')) ? config_item('cookie_prefix').$this->_csrf_token_name : $this->_csrf_token_name; @@ -817,4 +826,4 @@ class CI_Security { // END Security Class /* End of file Security.php */ -/* Location: ./system/libraries/Security.php */ \ No newline at end of file +/* Location: ./system/libraries/Security.php */ -- cgit v1.2.3-24-g4f1b From 571023b24f705d9c0bbaecf2e3cbbc06752390b4 Mon Sep 17 00:00:00 2001 From: patwork Date: Mon, 11 Apr 2011 11:56:41 +0200 Subject: Fix: codeigniter-reactor/32 unicorns are no longer mute --- system/core/Lang.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'system') diff --git a/system/core/Lang.php b/system/core/Lang.php index 0b926a303..cdadc7f41 100644 --- a/system/core/Lang.php +++ b/system/core/Lang.php @@ -129,19 +129,19 @@ class CI_Lang { */ function line($line = '') { - $line = ($line == '' OR ! isset($this->language[$line])) ? FALSE : $this->language[$line]; + $value = ($line == '' OR ! isset($this->language[$line])) ? FALSE : $this->language[$line]; // Because killer robots like unicorns! - if ($line === FALSE) + if ($value === FALSE) { log_message('error', 'Could not find the language line "'.$line.'"'); } - return $line; + return $value; } } // END Language Class /* End of file Lang.php */ -/* Location: ./system/core/Lang.php */ \ No newline at end of file +/* Location: ./system/core/Lang.php */ -- cgit v1.2.3-24-g4f1b From 9e2679849611ce050f5636c44b6c3279328d00f9 Mon Sep 17 00:00:00 2001 From: patwork Date: Mon, 11 Apr 2011 13:02:32 +0200 Subject: Fix: codeigniter-reactor/199 cookie name was overwritten with token name --- system/core/Security.php | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'system') diff --git a/system/core/Security.php b/system/core/Security.php index 73a3cfb31..4f91572ed 100644 --- a/system/core/Security.php +++ b/system/core/Security.php @@ -67,8 +67,10 @@ class CI_Security { } } - // Append application specific cookie prefix to token name - $this->_csrf_cookie_name = (config_item('cookie_prefix')) ? config_item('cookie_prefix').$this->_csrf_token_name : $this->_csrf_token_name; + // Append application specific cookie prefix + if (config_item('cookie_prefix')) { + $this->_csrf_cookie_name = config_item('cookie_prefix').$this->_csrf_cookie_name; + } // Set the CSRF hash $this->_csrf_set_hash(); -- cgit v1.2.3-24-g4f1b From e70e92bab1de57a0749a31f2889b55cafb46d58e Mon Sep 17 00:00:00 2001 From: Greg Aker Date: Mon, 25 Apr 2011 10:50:53 -0500 Subject: Fixing up a tabs vs spaces inconsistency in DB_Result --- system/database/DB_result.php | 83 +++++++++++++++++++++++-------------------- 1 file changed, 44 insertions(+), 39 deletions(-) (limited to 'system') diff --git a/system/database/DB_result.php b/system/database/DB_result.php index 06eec5124..e83228386 100644 --- a/system/database/DB_result.php +++ b/system/database/DB_result.php @@ -32,7 +32,7 @@ class CI_DB_result { var $result_id = NULL; var $result_array = array(); var $result_object = array(); - var $custom_result_object = array(); + var $custom_result_object = array(); var $current_row = 0; var $num_rows = 0; var $row_data = NULL; @@ -47,47 +47,52 @@ class CI_DB_result { */ function result($type = 'object') { - if ($type == 'array') return $this->result_array(); - else if ($type == 'object') return $this->result_object(); - else return $this->custom_result_object($type); + if ($type == 'array') return $this->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 - */ - 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(); + /** + * Custom query result. + * + * @param class_name A string that represents the type of object you want back + * @return array of objects + */ + 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; - } + { + $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; - } + // return the array + return $this->custom_result_object[$class_name] = $result_object; + } + + // -------------------------------------------------------------------- /** * Query result. "object" version. @@ -180,9 +185,9 @@ class CI_DB_result { $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); + 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); } // -------------------------------------------------------------------- @@ -219,7 +224,7 @@ class CI_DB_result { // -------------------------------------------------------------------- - /** + /** * Returns a single result row - custom object version * * @access public @@ -242,7 +247,7 @@ class CI_DB_result { return $result[$this->current_row]; } - /** + /** * Returns a single result row - object version * * @access public -- cgit v1.2.3-24-g4f1b From 26eebddda5438c3967bad74a05c3e990528e1182 Mon Sep 17 00:00:00 2001 From: Eric Barnes Date: Sun, 17 Apr 2011 23:45:41 -0400 Subject: Changed server check to ensure SCRIPT_NAME is defined. Fixes #57 --- system/core/URI.php | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'system') diff --git a/system/core/URI.php b/system/core/URI.php index 80dc62e58..d56548654 100644 --- a/system/core/URI.php +++ b/system/core/URI.php @@ -120,7 +120,7 @@ class CI_URI { $path = (isset($_SERVER[$uri])) ? $_SERVER[$uri] : @getenv($uri); $this->_set_uri_string($path); } - + // -------------------------------------------------------------------- /** @@ -133,7 +133,7 @@ class CI_URI { { // 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; } @@ -151,7 +151,7 @@ class CI_URI { */ private function _detect_uri() { - if ( ! isset($_SERVER['REQUEST_URI'])) + if ( ! isset($_SERVER['REQUEST_URI']) OR ! isset($_SERVER['SCRIPT_NAME'])) { return ''; } @@ -184,12 +184,12 @@ class CI_URI { $_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 -- cgit v1.2.3-24-g4f1b From bffb7769c6f31b7a47355d4eb66f5ac1d85c2a2e Mon Sep 17 00:00:00 2001 From: Eric Barnes Date: Mon, 18 Apr 2011 00:03:31 -0400 Subject: Changed path in footer comment of cache dummy. --- system/libraries/Cache/drivers/Cache_dummy.php | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) (limited to 'system') diff --git a/system/libraries/Cache/drivers/Cache_dummy.php b/system/libraries/Cache/drivers/Cache_dummy.php index de47acb43..f96a68e27 100644 --- a/system/libraries/Cache/drivers/Cache_dummy.php +++ b/system/libraries/Cache/drivers/Cache_dummy.php @@ -10,29 +10,29 @@ * @license http://codeigniter.com/user_guide/license.html * @link http://codeigniter.com * @since Version 2.0 - * @filesource + * @filesource */ // ------------------------------------------------------------------------ /** - * CodeIgniter Dummy Caching Class + * CodeIgniter Dummy Caching Class * * @package CodeIgniter * @subpackage Libraries * @category Core * @author ExpressionEngine Dev Team - * @link + * @link */ class CI_Cache_dummy extends CI_Driver { /** - * Get + * Get * * Since this is the dummy class, it's always going to return FALSE. * - * @param string + * @param string * @return Boolean FALSE */ public function get($id) @@ -40,8 +40,8 @@ class CI_Cache_dummy extends CI_Driver { return FALSE; } - // ------------------------------------------------------------------------ - + // ------------------------------------------------------------------------ + /** * Cache Save * @@ -55,7 +55,7 @@ class CI_Cache_dummy extends CI_Driver { { return TRUE; } - + // ------------------------------------------------------------------------ /** @@ -112,7 +112,7 @@ class CI_Cache_dummy extends CI_Driver { /** * Is this caching driver supported on the system? * Of course this one is. - * + * * @return TRUE; */ public function is_supported() @@ -121,9 +121,9 @@ class CI_Cache_dummy extends CI_Driver { } // ------------------------------------------------------------------------ - + } // End Class -/* End of file Cache_apc.php */ -/* Location: ./system/libraries/Cache/drivers/Cache_apc.php */ \ No newline at end of file +/* End of file Cache_dummy.php */ +/* Location: ./system/libraries/Cache/drivers/Cache_dummy.php */ \ No newline at end of file -- cgit v1.2.3-24-g4f1b From 826429cf40a9624788b92d2e6e4b7659e1b0d8a1 Mon Sep 17 00:00:00 2001 From: Greg Aker Date: Mon, 18 Apr 2011 09:40:19 -0500 Subject: Added an optional third parameter to heading() which allows adding html attributes to the rendered heading tag. --- system/helpers/html_helper.php | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'system') diff --git a/system/helpers/html_helper.php b/system/helpers/html_helper.php index c6103ab6f..a29204391 100644 --- a/system/helpers/html_helper.php +++ b/system/helpers/html_helper.php @@ -40,9 +40,10 @@ */ if ( ! function_exists('heading')) { - function heading($data = '', $h = '1') + function heading($data = '', $h = '1', $attributes = '') { - return "".$data.""; + $attributes = ($attributes != '') ? ' '.$attributes : $attributes; + return "".$data.""; } } -- cgit v1.2.3-24-g4f1b From 62df13125bd9ab22ff0c7f2565a42a6de13ed7e4 Mon Sep 17 00:00:00 2001 From: Greg Aker Date: Mon, 18 Apr 2011 11:18:02 -0500 Subject: Added Session Class userdata to the output profiler. Additionally, added a show/hide toggle on HTTP Headers, Session Data and Config Variables. --- system/language/english/profiler_lang.php | 3 +++ system/libraries/Profiler.php | 45 ++++++++++++++++++++++++++----- 2 files changed, 42 insertions(+), 6 deletions(-) (limited to 'system') diff --git a/system/language/english/profiler_lang.php b/system/language/english/profiler_lang.php index b6460fb83..1111158c8 100644 --- a/system/language/english/profiler_lang.php +++ b/system/language/english/profiler_lang.php @@ -9,6 +9,7 @@ $lang['profiler_post_data'] = 'POST DATA'; $lang['profiler_uri_string'] = 'URI STRING'; $lang['profiler_memory_usage'] = 'MEMORY USAGE'; $lang['profiler_config'] = 'CONFIG VARIABLES'; +$lang['profiler_session_data'] = 'SESSION DATA'; $lang['profiler_headers'] = 'HTTP HEADERS'; $lang['profiler_no_db'] = 'Database driver is not currently loaded'; $lang['profiler_no_queries'] = 'No queries were run'; @@ -17,6 +18,8 @@ $lang['profiler_no_get'] = 'No GET data exists'; $lang['profiler_no_uri'] = 'No URI data exists'; $lang['profiler_no_memory'] = 'Memory Usage Unavailable'; $lang['profiler_no_profiles'] = 'No Profile data - all Profiler sections have been disabled.'; +$lang['profiler_section_hide'] = 'Hide'; +$lang['profiler_section_show'] = 'Show'; /* End of file profiler_lang.php */ /* Location: ./system/language/english/profiler_lang.php */ \ No newline at end of file diff --git a/system/libraries/Profiler.php b/system/libraries/Profiler.php index 8a1f18ced..d1828b984 100644 --- a/system/libraries/Profiler.php +++ b/system/libraries/Profiler.php @@ -32,7 +32,7 @@ */ class CI_Profiler { - var $CI; + private $CI; protected $_available_sections = array( 'benchmarks', @@ -43,6 +43,7 @@ class CI_Profiler { 'controller_info', 'queries', 'http_headers', + 'session_data', 'config' ); @@ -410,10 +411,10 @@ class CI_Profiler { $output = "\n\n"; $output .= '
    '; $output .= "\n"; - $output .= '  '.$this->CI->lang->line('profiler_headers').'  '; + $output .= '  '.$this->CI->lang->line('profiler_headers').'  ('.$this->CI->lang->line('profiler_section_show').')'; $output .= "\n"; - $output .= "\n\n\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) { @@ -441,10 +442,10 @@ class CI_Profiler { $output = "\n\n"; $output .= '
    '; $output .= "\n"; - $output .= '  '.$this->CI->lang->line('profiler_config').'  '; + $output .= '  '.$this->CI->lang->line('profiler_config').'  ('.$this->CI->lang->line('profiler_section_show').')'; $output .= "\n"; - $output .= "\n\n
    \n"; + $output .= "\n\n
    \n"; foreach ($this->CI->config->config as $config=>$val) { @@ -464,6 +465,39 @@ class CI_Profiler { // -------------------------------------------------------------------- + /** + * 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)) + { + $val = print_r($val, TRUE); + } + + $output .= "\n"; + } + + $output .= ''; + $output .= "
    "; + return $output; + } + + // -------------------------------------------------------------------- + /** * Run the Profiler * @@ -493,7 +527,6 @@ class CI_Profiler { return $output; } - } // END CI_Profiler class -- cgit v1.2.3-24-g4f1b From 3403366d0f457c1dd449076b4177d1aff5cb176c Mon Sep 17 00:00:00 2001 From: Greg Aker Date: Mon, 18 Apr 2011 11:18:09 -0500 Subject: changeset: 2202:06a75a1bd622 tag: tip user: Greg Aker date: Mon Apr 18 11:10:37 2011 -0500 summary: Tweak to session class all_userdata() to just return the userdata array. Also documented previously undocumented all_userdata() method. --- system/libraries/Session.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'system') diff --git a/system/libraries/Session.php b/system/libraries/Session.php index 182294059..32317c2e6 100644 --- a/system/libraries/Session.php +++ b/system/libraries/Session.php @@ -435,11 +435,11 @@ class CI_Session { * Fetch all session data * * @access public - * @return mixed + * @return array */ function all_userdata() { - return ( ! isset($this->userdata)) ? FALSE : $this->userdata; + return $this->userdata; } // -------------------------------------------------------------------- -- cgit v1.2.3-24-g4f1b From e6e6e64ab078205153513af24dd4163157efb148 Mon Sep 17 00:00:00 2001 From: Greg Aker Date: Mon, 18 Apr 2011 15:54:13 -0500 Subject: changeset: 2204:37301a84c8be tag: tip user: Greg Aker date: Mon Apr 18 15:51:28 2011 -0500 summary: Adding toggle show/hide on database queries in the output profiler. Added a profiler config item to set a threshold of when to hide the queries by default. Additionally, fixed a bug I created earlier today by marking the $CI class var in CI_Profiler as private. --- system/libraries/Profiler.php | 35 +++++++++++++++++++++++++++++------ 1 file changed, 29 insertions(+), 6 deletions(-) (limited to 'system') diff --git a/system/libraries/Profiler.php b/system/libraries/Profiler.php index d1828b984..b73ddaf0d 100644 --- a/system/libraries/Profiler.php +++ b/system/libraries/Profiler.php @@ -32,8 +32,6 @@ */ class CI_Profiler { - private $CI; - protected $_available_sections = array( 'benchmarks', 'get', @@ -46,12 +44,24 @@ class CI_Profiler { 'session_data', 'config' ); + + protected $_query_toggle_count = 25; + + protected $CI; + // -------------------------------------------------------------------- + public function __construct($config = array()) { $this->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) { @@ -163,7 +173,7 @@ class CI_Profiler { $output .= "\n"; $output .= '  '.$this->CI->lang->line('profiler_queries').'  '; $output .= "\n"; - $output .= "\n\n\n"; + $output .= "\n\n
    \n"; $output .="\n"; $output .= "
    ".$this->CI->lang->line('profiler_no_db')."
    \n"; $output .= "
    "; @@ -178,14 +188,27 @@ class CI_Profiler { $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).'   '; + $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"; + $output .= "\n\n
    \n"; if (count($db->queries) == 0) { -- cgit v1.2.3-24-g4f1b From 3a746655e92ec59ee7e731c3535673a9aedc5d3e Mon Sep 17 00:00:00 2001 From: Greg Aker Date: Tue, 19 Apr 2011 10:59:47 -0500 Subject: Removing internal references to the EXT constant. Additionally, marked the constant as deprecated. Use ".php" instead. Also adding upgrade notes from 2.0.2 to 2.0.3. --- system/core/CodeIgniter.php | 22 ++++++------- system/core/Common.php | 14 ++++----- system/core/Config.php | 6 ++-- system/core/Exceptions.php | 4 +-- system/core/Hooks.php | 8 ++--- system/core/Lang.php | 4 +-- system/core/Loader.php | 64 +++++++++++++++++++------------------- system/core/Output.php | 6 ++-- system/core/Router.php | 14 ++++----- system/database/DB.php | 12 +++---- system/database/DB_driver.php | 6 ++-- system/helpers/download_helper.php | 8 ++--- system/helpers/file_helper.php | 8 ++--- system/helpers/html_helper.php | 8 ++--- system/helpers/smiley_helper.php | 8 ++--- system/helpers/text_helper.php | 8 ++--- system/libraries/Calendar.php | 2 +- system/libraries/Driver.php | 2 +- system/libraries/Encrypt.php | 2 +- system/libraries/Log.php | 2 +- system/libraries/Upload.php | 8 ++--- system/libraries/User_agent.php | 8 ++--- 22 files changed, 112 insertions(+), 112 deletions(-) (limited to 'system') diff --git a/system/core/CodeIgniter.php b/system/core/CodeIgniter.php index e022e1b46..03b25ab9e 100644 --- a/system/core/CodeIgniter.php +++ b/system/core/CodeIgniter.php @@ -46,20 +46,20 @@ * Load the global functions * ------------------------------------------------------ */ - require(BASEPATH.'core/Common'.EXT); + require(BASEPATH.'core/Common.php'); /* * ------------------------------------------------------ * Load the framework constants * ------------------------------------------------------ */ - if (defined('ENVIRONMENT') AND file_exists(APPPATH.'config/'.ENVIRONMENT.'/constants'.EXT)) + if (defined('ENVIRONMENT') AND file_exists(APPPATH.'config/'.ENVIRONMENT.'/constants.php')) { - require(APPPATH.'config/'.ENVIRONMENT.'/constants'.EXT); + require(APPPATH.'config/'.ENVIRONMENT.'/constants.php'); } else { - require(APPPATH.'config/constants'.EXT); + require(APPPATH.'config/constants.php'); } /* @@ -224,7 +224,7 @@ * */ // Load the base controller class - require BASEPATH.'core/Controller'.EXT; + require BASEPATH.'core/Controller.php'; function &get_instance() { @@ -232,20 +232,20 @@ } - if (file_exists(APPPATH.'core/'.$CFG->config['subclass_prefix'].'Controller'.EXT)) + if (file_exists(APPPATH.'core/'.$CFG->config['subclass_prefix'].'Controller.php')) { - require APPPATH.'core/'.$CFG->config['subclass_prefix'].'Controller'.EXT; + 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().EXT)) + 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().EXT); + include(APPPATH.'controllers/'.$RTR->fetch_directory().$RTR->fetch_class().'.php'); // Set a mark point for benchmarking $BM->mark('loading_time:_base_classes_end'); @@ -318,12 +318,12 @@ $method = (isset($x[1]) ? $x[1] : 'index'); if ( ! class_exists($class)) { - if ( ! file_exists(APPPATH.'controllers/'.$class.EXT)) + if ( ! file_exists(APPPATH.'controllers/'.$class.'.php')) { show_404("{$class}/{$method}"); } - include_once(APPPATH.'controllers/'.$class.EXT); + include_once(APPPATH.'controllers/'.$class.'.php'); unset($CI); $CI = new $class(); } diff --git a/system/core/Common.php b/system/core/Common.php index 1aca809ab..d1e8e77e9 100644 --- a/system/core/Common.php +++ b/system/core/Common.php @@ -128,13 +128,13 @@ // thenin the local application/libraries folder foreach (array(BASEPATH, APPPATH) as $path) { - if (file_exists($path.$directory.'/'.$class.EXT)) + if (file_exists($path.$directory.'/'.$class.'.php')) { $name = $prefix.$class; if (class_exists($name) === FALSE) { - require($path.$directory.'/'.$class.EXT); + require($path.$directory.'/'.$class.'.php'); } break; @@ -142,13 +142,13 @@ } // Is the request a class extension? If so we load it too - if (file_exists(APPPATH.$directory.'/'.config_item('subclass_prefix').$class.EXT)) + 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.EXT); + require(APPPATH.$directory.'/'.config_item('subclass_prefix').$class.'.php'); } } @@ -157,7 +157,7 @@ { // 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.EXT); + exit('Unable to locate the specified class: '.$class.'.php'); } // Keep track of what we just loaded @@ -209,9 +209,9 @@ } // Is the config file in the environment folder? - if ( ! defined('ENVIRONMENT') OR ! file_exists($file_path = APPPATH.'config/'.ENVIRONMENT.'/config'.EXT)) + if ( ! defined('ENVIRONMENT') OR ! file_exists($file_path = APPPATH.'config/'.ENVIRONMENT.'/config.php')) { - $file_path = APPPATH.'config/config'.EXT; + $file_path = APPPATH.'config/config.php'; } // Fetch the config file diff --git a/system/core/Config.php b/system/core/Config.php index 863c5ef4b..4493ff266 100644 --- a/system/core/Config.php +++ b/system/core/Config.php @@ -80,7 +80,7 @@ class CI_Config { */ function load($file = '', $use_sections = FALSE, $fail_gracefully = FALSE) { - $file = ($file == '') ? 'config' : str_replace(EXT, '', $file); + $file = ($file == '') ? 'config' : str_replace('.php', '', $file); $found = FALSE; $loaded = FALSE; @@ -92,7 +92,7 @@ class CI_Config { foreach ($check_locations as $location) { - $file_path = $path.'config/'.$location.EXT; + $file_path = $path.'config/'.$location.'.php'; if (in_array($file_path, $this->is_loaded, TRUE)) { @@ -152,7 +152,7 @@ class CI_Config { { return FALSE; } - show_error('The configuration file '.$file.EXT.' does not exist.'); + show_error('The configuration file '.$file.'.php'.' does not exist.'); } return TRUE; diff --git a/system/core/Exceptions.php b/system/core/Exceptions.php index f5659561c..bff86a92f 100644 --- a/system/core/Exceptions.php +++ b/system/core/Exceptions.php @@ -128,7 +128,7 @@ class CI_Exceptions { ob_end_flush(); } ob_start(); - include(APPPATH.'errors/'.$template.EXT); + include(APPPATH.'errors/'.$template.'.php'); $buffer = ob_get_contents(); ob_end_clean(); return $buffer; @@ -164,7 +164,7 @@ class CI_Exceptions { ob_end_flush(); } ob_start(); - include(APPPATH.'errors/error_php'.EXT); + include(APPPATH.'errors/error_php.php'); $buffer = ob_get_contents(); ob_end_clean(); echo $buffer; diff --git a/system/core/Hooks.php b/system/core/Hooks.php index 24fa1055b..fd6380f0a 100644 --- a/system/core/Hooks.php +++ b/system/core/Hooks.php @@ -65,13 +65,13 @@ class CI_Hooks { // Grab the "hooks" definition file. // If there are no hooks, we're done. - if (defined('ENVIRONMENT') AND is_file(APPPATH.'config/'.ENVIRONMENT.'/hooks'.EXT)) + if (defined('ENVIRONMENT') AND is_file(APPPATH.'config/'.ENVIRONMENT.'/hooks.php')) { - include(APPPATH.'config/'.ENVIRONMENT.'/hooks'.EXT); + include(APPPATH.'config/'.ENVIRONMENT.'/hooks.php'); } - elseif (is_file(APPPATH.'config/hooks'.EXT)) + elseif (is_file(APPPATH.'config/hooks.php')) { - include(APPPATH.'config/hooks'.EXT); + include(APPPATH.'config/hooks.php'); } diff --git a/system/core/Lang.php b/system/core/Lang.php index cdadc7f41..170e6c725 100644 --- a/system/core/Lang.php +++ b/system/core/Lang.php @@ -51,14 +51,14 @@ class CI_Lang { */ function load($langfile = '', $idiom = '', $return = FALSE, $add_suffix = TRUE, $alt_path = '') { - $langfile = str_replace(EXT, '', $langfile); + $langfile = str_replace('.php', '', $langfile); if ($add_suffix == TRUE) { $langfile = str_replace('_lang.', '', $langfile).'_lang'; } - $langfile .= EXT; + $langfile .= '.php'; if (in_array($langfile, $this->is_loaded, TRUE)) { diff --git a/system/core/Loader.php b/system/core/Loader.php index e75805d0e..59415b72a 100644 --- a/system/core/Loader.php +++ b/system/core/Loader.php @@ -161,7 +161,7 @@ class CI_Loader { foreach ($this->_ci_model_paths as $mod_path) { - if ( ! file_exists($mod_path.'models/'.$path.$model.EXT)) + if ( ! file_exists($mod_path.'models/'.$path.$model.'.php')) { continue; } @@ -181,7 +181,7 @@ class CI_Loader { load_class('Model', 'core'); } - require_once($mod_path.'models/'.$path.$model.EXT); + require_once($mod_path.'models/'.$path.$model.'.php'); $model = ucfirst($model); @@ -217,7 +217,7 @@ class CI_Loader { return FALSE; } - require_once(BASEPATH.'database/DB'.EXT); + require_once(BASEPATH.'database/DB.php'); if ($return === TRUE) { @@ -253,8 +253,8 @@ class CI_Loader { // this use is deprecated and strongly discouraged $CI->load->dbforge(); - require_once(BASEPATH.'database/DB_utility'.EXT); - require_once(BASEPATH.'database/drivers/'.$CI->db->dbdriver.'/'.$CI->db->dbdriver.'_utility'.EXT); + 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(); @@ -277,8 +277,8 @@ class CI_Loader { $CI =& get_instance(); - require_once(BASEPATH.'database/DB_forge'.EXT); - require_once(BASEPATH.'database/drivers/'.$CI->db->dbdriver.'/'.$CI->db->dbdriver.'_forge'.EXT); + 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(); @@ -375,16 +375,16 @@ class CI_Loader { continue; } - $ext_helper = APPPATH.'helpers/'.config_item('subclass_prefix').$helper.EXT; + $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.EXT; + $base_helper = BASEPATH.'helpers/'.$helper.'.php'; if ( ! file_exists($base_helper)) { - show_error('Unable to load the requested file: helpers/'.$helper.EXT); + show_error('Unable to load the requested file: helpers/'.$helper.'.php'); } include_once($ext_helper); @@ -398,9 +398,9 @@ class CI_Loader { // Try to load the helper foreach ($this->_ci_helper_paths as $path) { - if (file_exists($path.'helpers/'.$helper.EXT)) + if (file_exists($path.'helpers/'.$helper.'.php')) { - include_once($path.'helpers/'.$helper.EXT); + include_once($path.'helpers/'.$helper.'.php'); $this->_ci_helpers[$helper] = TRUE; log_message('debug', 'Helper loaded: '.$helper); @@ -411,7 +411,7 @@ class CI_Loader { // unable to load the helper if ( ! isset($this->_ci_helpers[$helper])) { - show_error('Unable to load the requested file: helpers/'.$helper.EXT); + show_error('Unable to load the requested file: helpers/'.$helper.'.php'); } } } @@ -490,7 +490,7 @@ class CI_Loader { 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'.EXT; + require BASEPATH.'libraries/Driver.php'; } // We can save the loader some time since Drivers will *always* be in a subfolder, @@ -616,7 +616,7 @@ class CI_Loader { if ($_ci_path == '') { $_ci_ext = pathinfo($_ci_view, PATHINFO_EXTENSION); - $_ci_file = ($_ci_ext == '') ? $_ci_view.EXT : $_ci_view; + $_ci_file = ($_ci_ext == '') ? $_ci_view.'.php' : $_ci_view; $_ci_path = $this->_ci_view_path.$_ci_file; } else @@ -732,7 +732,7 @@ class CI_Loader { // 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(EXT, '', trim($class, '/')); + $class = str_replace('.php', '', trim($class, '/')); // Was the path included with the class name? // We look for a slash to determine this @@ -749,12 +749,12 @@ class CI_Loader { // 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.EXT; + $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).EXT; + $baseclass = BASEPATH.'libraries/'.ucfirst($class).'.php'; if ( ! file_exists($baseclass)) { @@ -793,7 +793,7 @@ class CI_Loader { $is_duplicate = FALSE; foreach ($this->_ci_library_paths as $path) { - $filepath = $path.'libraries/'.$subdir.$class.EXT; + $filepath = $path.'libraries/'.$subdir.$class.'.php'; // Does the file exist? No? Bummer... if ( ! file_exists($filepath)) @@ -872,24 +872,24 @@ class CI_Loader { // 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).EXT)) + if (defined('ENVIRONMENT') AND file_exists($path .'config/'.ENVIRONMENT.'/'.strtolower($class).'.php')) { - include_once($path .'config/'.ENVIRONMENT.'/'.strtolower($class).EXT); + include_once($path .'config/'.ENVIRONMENT.'/'.strtolower($class).'.php'); break; } - elseif (defined('ENVIRONMENT') AND file_exists($path .'config/'.ENVIRONMENT.'/'.ucfirst(strtolower($class)).EXT)) + elseif (defined('ENVIRONMENT') AND file_exists($path .'config/'.ENVIRONMENT.'/'.ucfirst(strtolower($class)).'.php')) { - include_once($path .'config/'.ENVIRONMENT.'/'.ucfirst(strtolower($class)).EXT); + include_once($path .'config/'.ENVIRONMENT.'/'.ucfirst(strtolower($class)).'.php'); break; } - elseif (file_exists($path .'config/'.strtolower($class).EXT)) + elseif (file_exists($path .'config/'.strtolower($class).'.php')) { - include_once($path .'config/'.strtolower($class).EXT); + include_once($path .'config/'.strtolower($class).'.php'); break; } - elseif (file_exists($path .'config/'.ucfirst(strtolower($class)).EXT)) + elseif (file_exists($path .'config/'.ucfirst(strtolower($class)).'.php')) { - include_once($path .'config/'.ucfirst(strtolower($class)).EXT); + include_once($path .'config/'.ucfirst(strtolower($class)).'.php'); break; } } @@ -965,13 +965,13 @@ class CI_Loader { */ function _ci_autoloader() { - if (defined('ENVIRONMENT') AND file_exists(APPPATH.'config/'.ENVIRONMENT.'/autoload'.EXT)) + if (defined('ENVIRONMENT') AND file_exists(APPPATH.'config/'.ENVIRONMENT.'/autoload.php')) { - include_once(APPPATH.'config/'.ENVIRONMENT.'/autoload'.EXT); + include_once(APPPATH.'config/'.ENVIRONMENT.'/autoload.php'); } else { - include_once(APPPATH.'config/autoload'.EXT); + include_once(APPPATH.'config/autoload.php'); } @@ -1084,13 +1084,13 @@ class CI_Loader { { if ( ! is_array($filename)) { - return array(strtolower(str_replace(EXT, '', str_replace($extension, '', $filename)).$extension)); + return array(strtolower(str_replace('.php', '', str_replace($extension, '', $filename)).$extension)); } else { foreach ($filename as $key => $val) { - $filename[$key] = strtolower(str_replace(EXT, '', str_replace($extension, '', $val)).$extension); + $filename[$key] = strtolower(str_replace('.php', '', str_replace($extension, '', $val)).$extension); } return $filename; diff --git a/system/core/Output.php b/system/core/Output.php index 45a82f3cb..05ace919c 100644 --- a/system/core/Output.php +++ b/system/core/Output.php @@ -42,13 +42,13 @@ class CI_Output { $this->_zlib_oc = @ini_get('zlib.output_compression'); // Get mime types for later - if (defined('ENVIRONMENT') AND file_exists(APPPATH.'config/'.ENVIRONMENT.'/mimes'.EXT)) + if (defined('ENVIRONMENT') AND file_exists(APPPATH.'config/'.ENVIRONMENT.'/mimes.php')) { - include APPPATH.'config/'.ENVIRONMENT.'/mimes'.EXT; + include APPPATH.'config/'.ENVIRONMENT.'/mimes.php'; } else { - include APPPATH.'config/mimes'.EXT; + include APPPATH.'config/mimes.php'; } diff --git a/system/core/Router.php b/system/core/Router.php index d451aab68..5e92a04b1 100644 --- a/system/core/Router.php +++ b/system/core/Router.php @@ -87,13 +87,13 @@ class CI_Router { } // Load the routes.php file. - if (defined('ENVIRONMENT') AND is_file(APPPATH.'config/'.ENVIRONMENT.'/routes'.EXT)) + if (defined('ENVIRONMENT') AND is_file(APPPATH.'config/'.ENVIRONMENT.'/routes.php')) { - include(APPPATH.'config/'.ENVIRONMENT.'/routes'.EXT); + include(APPPATH.'config/'.ENVIRONMENT.'/routes.php'); } - elseif (is_file(APPPATH.'config/routes'.EXT)) + elseif (is_file(APPPATH.'config/routes.php')) { - include(APPPATH.'config/routes'.EXT); + include(APPPATH.'config/routes.php'); } $this->routes = ( ! isset($route) OR ! is_array($route)) ? array() : $route; @@ -227,7 +227,7 @@ class CI_Router { } // Does the requested controller exist in the root folder? - if (file_exists(APPPATH.'controllers/'.$segments[0].EXT)) + if (file_exists(APPPATH.'controllers/'.$segments[0].'.php')) { return $segments; } @@ -242,7 +242,7 @@ class CI_Router { if (count($segments) > 0) { // Does the requested controller exist in the sub-folder? - if ( ! file_exists(APPPATH.'controllers/'.$this->fetch_directory().$segments[0].EXT)) + if ( ! file_exists(APPPATH.'controllers/'.$this->fetch_directory().$segments[0].'.php')) { show_404($this->fetch_directory().$segments[0]); } @@ -264,7 +264,7 @@ class CI_Router { } // Does the default controller exist in the sub-folder? - if ( ! file_exists(APPPATH.'controllers/'.$this->fetch_directory().$this->default_controller.EXT)) + if ( ! file_exists(APPPATH.'controllers/'.$this->fetch_directory().$this->default_controller.'.php')) { $this->directory = ''; return array(); diff --git a/system/database/DB.php b/system/database/DB.php index 8bf1ba8ba..33207d885 100644 --- a/system/database/DB.php +++ b/system/database/DB.php @@ -28,11 +28,11 @@ function &DB($params = '', $active_record_override = NULL) if (is_string($params) AND strpos($params, '://') === FALSE) { // Is the config file in the environment folder? - if ( ! defined('ENVIRONMENT') OR ! file_exists($file_path = APPPATH.'config/'.ENVIRONMENT.'/database'.EXT)) + if ( ! defined('ENVIRONMENT') OR ! file_exists($file_path = APPPATH.'config/'.ENVIRONMENT.'/database.php')) { - if ( ! file_exists($file_path = APPPATH.'config/database'.EXT)) + if ( ! file_exists($file_path = APPPATH.'config/database.php')) { - show_error('The configuration file database'.EXT.' does not exist.'); + show_error('The configuration file database.php does not exist.'); } } @@ -116,11 +116,11 @@ function &DB($params = '', $active_record_override = NULL) $active_record = $active_record_override; } - require_once(BASEPATH.'database/DB_driver'.EXT); + require_once(BASEPATH.'database/DB_driver.php'); if ( ! isset($active_record) OR $active_record == TRUE) { - require_once(BASEPATH.'database/DB_active_rec'.EXT); + require_once(BASEPATH.'database/DB_active_rec.php'); if ( ! class_exists('CI_DB')) { @@ -135,7 +135,7 @@ function &DB($params = '', $active_record_override = NULL) } } - require_once(BASEPATH.'database/drivers/'.$params['dbdriver'].'/'.$params['dbdriver'].'_driver'.EXT); + require_once(BASEPATH.'database/drivers/'.$params['dbdriver'].'/'.$params['dbdriver'].'_driver.php'); // Instantiate the DB adapter $driver = 'CI_DB_'.$params['dbdriver'].'_driver'; diff --git a/system/database/DB_driver.php b/system/database/DB_driver.php index e7a9de475..10e8ed0c0 100644 --- a/system/database/DB_driver.php +++ b/system/database/DB_driver.php @@ -424,8 +424,8 @@ class CI_DB_driver { if ( ! class_exists($driver)) { - include_once(BASEPATH.'database/DB_result'.EXT); - include_once(BASEPATH.'database/drivers/'.$this->dbdriver.'/'.$this->dbdriver.'_result'.EXT); + include_once(BASEPATH.'database/DB_result.php'); + include_once(BASEPATH.'database/drivers/'.$this->dbdriver.'/'.$this->dbdriver.'_result.php'); } return $driver; @@ -1115,7 +1115,7 @@ class CI_DB_driver { if ( ! class_exists('CI_DB_Cache')) { - if ( ! @include(BASEPATH.'database/DB_cache'.EXT)) + if ( ! @include(BASEPATH.'database/DB_cache.php')) { return $this->cache_off(); } diff --git a/system/helpers/download_helper.php b/system/helpers/download_helper.php index f8073d238..1145688ae 100644 --- a/system/helpers/download_helper.php +++ b/system/helpers/download_helper.php @@ -58,13 +58,13 @@ if ( ! function_exists('force_download')) $extension = end($x); // Load the mime types - if (defined('ENVIRONMENT') AND is_file(APPPATH.'config/'.ENVIRONMENT.'/mimes'.EXT)) + if (defined('ENVIRONMENT') AND is_file(APPPATH.'config/'.ENVIRONMENT.'/mimes.php')) { - include(APPPATH.'config/'.ENVIRONMENT.'/mimes'.EXT); + include(APPPATH.'config/'.ENVIRONMENT.'/mimes.php'); } - elseif (is_file(APPPATH.'config/mimes'.EXT)) + elseif (is_file(APPPATH.'config/mimes.php')) { - include(APPPATH.'config/mimes'.EXT); + include(APPPATH.'config/mimes.php'); } // Set a default mime if we can't find it diff --git a/system/helpers/file_helper.php b/system/helpers/file_helper.php index 44344947e..3931667fd 100644 --- a/system/helpers/file_helper.php +++ b/system/helpers/file_helper.php @@ -352,13 +352,13 @@ if ( ! function_exists('get_mime_by_extension')) if ( ! is_array($mimes)) { - if (defined('ENVIRONMENT') AND is_file(APPPATH.'config/'.ENVIRONMENT.'/mimes'.EXT)) + if (defined('ENVIRONMENT') AND is_file(APPPATH.'config/'.ENVIRONMENT.'/mimes.php')) { - include(APPPATH.'config/'.ENVIRONMENT.'/mimes'.EXT); + include(APPPATH.'config/'.ENVIRONMENT.'/mimes.php'); } - elseif (is_file(APPPATH.'config/mimes'.EXT)) + elseif (is_file(APPPATH.'config/mimes.php')) { - include(APPPATH.'config/mimes'.EXT); + include(APPPATH.'config/mimes.php'); } if ( ! is_array($mimes)) diff --git a/system/helpers/html_helper.php b/system/helpers/html_helper.php index a29204391..080f622dd 100644 --- a/system/helpers/html_helper.php +++ b/system/helpers/html_helper.php @@ -259,13 +259,13 @@ if ( ! function_exists('doctype')) if ( ! is_array($_doctypes)) { - if (defined('ENVIRONMENT') AND is_file(APPPATH.'config/'.ENVIRONMENT.'/doctypes'.EXT)) + if (defined('ENVIRONMENT') AND is_file(APPPATH.'config/'.ENVIRONMENT.'/doctypes.php')) { - include(APPPATH.'config/'.ENVIRONMENT.'/doctypes'.EXT); + include(APPPATH.'config/'.ENVIRONMENT.'/doctypes.php'); } - elseif (is_file(APPPATH.'config/doctypes'.EXT)) + elseif (is_file(APPPATH.'config/doctypes.php')) { - include(APPPATH.'config/doctypes'.EXT); + include(APPPATH.'config/doctypes.php'); } if ( ! is_array($_doctypes)) diff --git a/system/helpers/smiley_helper.php b/system/helpers/smiley_helper.php index a2d1031b3..6d8889354 100644 --- a/system/helpers/smiley_helper.php +++ b/system/helpers/smiley_helper.php @@ -229,13 +229,13 @@ if ( ! function_exists('_get_smiley_array')) { function _get_smiley_array() { - if (defined('ENVIRONMENT') AND file_exists(APPPATH.'config/'.ENVIRONMENT.'/smileys'.EXT)) + if (defined('ENVIRONMENT') AND file_exists(APPPATH.'config/'.ENVIRONMENT.'/smileys.php')) { - include(APPPATH.'config/'.ENVIRONMENT.'/smileys'.EXT); + include(APPPATH.'config/'.ENVIRONMENT.'/smileys.php'); } - elseif (file_exists(APPPATH.'config/smileys'.EXT)) + elseif (file_exists(APPPATH.'config/smileys.php')) { - include(APPPATH.'config/smileys'.EXT); + include(APPPATH.'config/smileys.php'); } if (isset($smileys) AND is_array($smileys)) diff --git a/system/helpers/text_helper.php b/system/helpers/text_helper.php index cca093976..33d7fa2fd 100644 --- a/system/helpers/text_helper.php +++ b/system/helpers/text_helper.php @@ -366,13 +366,13 @@ if ( ! function_exists('convert_accented_characters')) { function convert_accented_characters($str) { - if (defined('ENVIRONMENT') AND is_file(APPPATH.'config/'.ENVIRONMENT.'/foreign_chars'.EXT)) + if (defined('ENVIRONMENT') AND is_file(APPPATH.'config/'.ENVIRONMENT.'/foreign_chars.php')) { - include(APPPATH.'config/'.ENVIRONMENT.'/foreign_chars'.EXT); + include(APPPATH.'config/'.ENVIRONMENT.'/foreign_chars.php'); } - elseif (is_file(APPPATH.'config/foreign_chars'.EXT)) + elseif (is_file(APPPATH.'config/foreign_chars.php')) { - include(APPPATH.'config/foreign_chars'.EXT); + include(APPPATH.'config/foreign_chars.php'); } if ( ! isset($foreign_characters)) diff --git a/system/libraries/Calendar.php b/system/libraries/Calendar.php index 72d228e73..df0fd6eeb 100644 --- a/system/libraries/Calendar.php +++ b/system/libraries/Calendar.php @@ -47,7 +47,7 @@ class CI_Calendar { { $this->CI =& get_instance(); - if ( ! in_array('calendar_lang'.EXT, $this->CI->lang->is_loaded, TRUE)) + if ( ! in_array('calendar_lang.php', $this->CI->lang->is_loaded, TRUE)) { $this->CI->lang->load('calendar'); } diff --git a/system/libraries/Driver.php b/system/libraries/Driver.php index b942f539f..d1925c0ec 100644 --- a/system/libraries/Driver.php +++ b/system/libraries/Driver.php @@ -59,7 +59,7 @@ class CI_Driver_Library { // loves me some nesting! foreach (array(ucfirst($driver_name), $driver_name) as $class) { - $filepath = $path.'libraries/'.$lib_name.'/drivers/'.$class.EXT; + $filepath = $path.'libraries/'.$lib_name.'/drivers/'.$class.'.php'; if (file_exists($filepath)) { diff --git a/system/libraries/Encrypt.php b/system/libraries/Encrypt.php index e5f65878a..b30a8cf0b 100644 --- a/system/libraries/Encrypt.php +++ b/system/libraries/Encrypt.php @@ -524,7 +524,7 @@ class CI_Encrypt { { if ( ! function_exists('mhash')) { - require_once(BASEPATH.'libraries/Sha1'.EXT); + require_once(BASEPATH.'libraries/Sha1.php'); $SH = new CI_SHA; return $SH->generate($str); } diff --git a/system/libraries/Log.php b/system/libraries/Log.php index fb2c5a49b..9f1db76ba 100644 --- a/system/libraries/Log.php +++ b/system/libraries/Log.php @@ -83,7 +83,7 @@ class CI_Log { return FALSE; } - $filepath = $this->_log_path.'log-'.date('Y-m-d').EXT; + $filepath = $this->_log_path.'log-'.date('Y-m-d').'.php'; $message = ''; if ( ! file_exists($filepath)) diff --git a/system/libraries/Upload.php b/system/libraries/Upload.php index e80049fa4..3177424c4 100644 --- a/system/libraries/Upload.php +++ b/system/libraries/Upload.php @@ -945,13 +945,13 @@ class CI_Upload { if (count($this->mimes) == 0) { - if (defined('ENVIRONMENT') AND is_file(APPPATH.'config/'.ENVIRONMENT.'/mimes'.EXT)) + if (defined('ENVIRONMENT') AND is_file(APPPATH.'config/'.ENVIRONMENT.'/mimes.php')) { - include(APPPATH.'config/'.ENVIRONMENT.'/mimes'.EXT); + include(APPPATH.'config/'.ENVIRONMENT.'/mimes.php'); } - elseif (is_file(APPPATH.'config/mimes'.EXT)) + elseif (is_file(APPPATH.'config/mimes.php')) { - include(APPPATH.'config//mimes'.EXT); + include(APPPATH.'config//mimes.php'); } else { diff --git a/system/libraries/User_agent.php b/system/libraries/User_agent.php index 04cda7312..016102a2a 100644 --- a/system/libraries/User_agent.php +++ b/system/libraries/User_agent.php @@ -84,13 +84,13 @@ class CI_User_agent { */ private function _load_agent_file() { - if (defined('ENVIRONMENT') AND is_file(APPPATH.'config/'.ENVIRONMENT.'/user_agents'.EXT)) + if (defined('ENVIRONMENT') AND is_file(APPPATH.'config/'.ENVIRONMENT.'/user_agents.php')) { - include(APPPATH.'config/'.ENVIRONMENT.'/user_agents'.EXT); + include(APPPATH.'config/'.ENVIRONMENT.'/user_agents.php'); } - elseif (is_file(APPPATH.'config/user_agents'.EXT)) + elseif (is_file(APPPATH.'config/user_agents.php')) { - include(APPPATH.'config/user_agents'.EXT); + include(APPPATH.'config/user_agents.php'); } else { -- cgit v1.2.3-24-g4f1b From 9ce4385cfc976e309ee12c53726abfd4f066ac3f Mon Sep 17 00:00:00 2001 From: Greg Aker Date: Tue, 19 Apr 2011 12:58:52 -0500 Subject: 1/2 reverting a previous change to the form_helper. Wrapping hidden form elements in
    instead of an empty div. If a user is styling form div {} they can run into display issues, so something is needed. --- system/helpers/form_helper.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system') diff --git a/system/helpers/form_helper.php b/system/helpers/form_helper.php index bca0ff0c9..a5cd97b82 100644 --- a/system/helpers/form_helper.php +++ b/system/helpers/form_helper.php @@ -72,7 +72,7 @@ if ( ! function_exists('form_open')) if (is_array($hidden) AND count($hidden) > 0) { - $form .= sprintf("\n
    %s
    ", form_hidden($hidden)); + $form .= sprintf("
    %s
    ", form_hidden($hidden)); } return $form; -- cgit v1.2.3-24-g4f1b From 6ae70cc8499499b5d77d77ec8974f95873edb861 Mon Sep 17 00:00:00 2001 From: Derek Jones Date: Tue, 19 Apr 2011 16:13:48 -0500 Subject: modified MySQL and MySQLi drivers to address a potential SQL injection attack vector when multi-byte character set connections are employed. (Does not impact Latin-1, UTF-8, etc. encodings) --- system/database/drivers/mysql/mysql_driver.php | 17 ++++++++++++++++- system/database/drivers/mysqli/mysqli_driver.php | 17 ++++++++++++++++- 2 files changed, 32 insertions(+), 2 deletions(-) (limited to 'system') diff --git a/system/database/drivers/mysql/mysql_driver.php b/system/database/drivers/mysql/mysql_driver.php index 4ff9b0a11..b7d547cc0 100644 --- a/system/database/drivers/mysql/mysql_driver.php +++ b/system/database/drivers/mysql/mysql_driver.php @@ -132,7 +132,22 @@ class CI_DB_mysql_driver extends CI_DB { */ function db_set_charset($charset, $collation) { - return @mysql_query("SET NAMES '".$this->escape_str($charset)."' COLLATE '".$this->escape_str($collation)."'", $this->conn_id); + static $use_set_names; + + if ( ! isset($use_set_names)) + { + // mysql_set_charset() requires PHP >= 5.2.3 and MySQL >= 5.0.7, use SET NAMES as fallback + $use_set_names = (version_compare(PHP_VERSION, '5.2.3', '>=') && version_compare(mysql_get_server_info(), '5.0.7', '>=')) ? FALSE : TRUE; + } + + if ($use_set_names) + { + 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); + } } // -------------------------------------------------------------------- diff --git a/system/database/drivers/mysqli/mysqli_driver.php b/system/database/drivers/mysqli/mysqli_driver.php index ccdabce1a..1949acb6e 100644 --- a/system/database/drivers/mysqli/mysqli_driver.php +++ b/system/database/drivers/mysqli/mysqli_driver.php @@ -132,7 +132,22 @@ class CI_DB_mysqli_driver extends CI_DB { */ function _db_set_charset($charset, $collation) { - return @mysqli_query($this->conn_id, "SET NAMES '".$this->escape_str($charset)."' COLLATE '".$this->escape_str($collation)."'"); + static $use_set_names; + + if ( ! isset($use_set_names)) + { + // mysqli_set_charset() requires MySQL >= 5.0.7, use SET NAMES as fallback + $use_set_names = (version_compare(mysql_get_server_info(), '5.0.7', '>=')) ? FALSE : TRUE; + } + + if ($use_set_names) + { + 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); + } } // -------------------------------------------------------------------- -- cgit v1.2.3-24-g4f1b From f5c840241084e03d49e521bfcb62d2adbe9fce7d Mon Sep 17 00:00:00 2001 From: Greg Aker Date: Tue, 19 Apr 2011 17:13:03 -0500 Subject: Altering the loader to be able to load views from packages when adding the package path with add_package_path(). --- system/core/Controller.php | 2 +- system/core/Loader.php | 110 ++++++++++++++++++++++++--------------------- 2 files changed, 59 insertions(+), 53 deletions(-) (limited to 'system') diff --git a/system/core/Controller.php b/system/core/Controller.php index 469663f09..fd9c8b580 100644 --- a/system/core/Controller.php +++ b/system/core/Controller.php @@ -50,7 +50,7 @@ class CI_Controller { $this->load->_base_classes =& is_loaded(); - $this->load->_ci_autoloader(); + $this->load->ci_autoloader(); log_message('debug', "Controller Class Initialized"); diff --git a/system/core/Loader.php b/system/core/Loader.php index 59415b72a..8146cd563 100644 --- a/system/core/Loader.php +++ b/system/core/Loader.php @@ -30,8 +30,8 @@ class CI_Loader { // All these are set automatically. Don't mess with them. var $_ci_ob_level; - var $_ci_view_path = ''; - var $_ci_library_paths = array(); + var $_ci_view_paths = array(); + protected $_ci_library_paths = array(); var $_ci_model_paths = array(); var $_ci_helper_paths = array(); var $_base_classes = array(); // Set by the controller class @@ -47,17 +47,15 @@ class CI_Loader { * Constructor * * Sets the path to the view files and gets the initial output buffering level - * - * @access public */ - function __construct() + public function __construct() { - $this->_ci_view_path = APPPATH.'views/'; $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"); } @@ -107,13 +105,12 @@ class CI_Loader { * * This function lets users load and instantiate models. * - * @access public * @param string the name of the class * @param string name for the model * @param bool database connection * @return void */ - function model($model, $name = '', $db_conn = FALSE) + public function model($model, $name = '', $db_conn = FALSE) { if (is_array($model)) { @@ -200,13 +197,12 @@ class CI_Loader { /** * Database Loader * - * @access public * @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 */ - function database($params = '', $return = FALSE, $active_record = NULL) + public function database($params = '', $return = FALSE, $active_record = NULL) { // Grab the super object $CI =& get_instance(); @@ -237,10 +233,9 @@ class CI_Loader { /** * Load the Utilities Class * - * @access public * @return string */ - function dbutil() + public function dbutil() { if ( ! class_exists('CI_DB')) { @@ -265,10 +260,9 @@ class CI_Loader { /** * Load the Database Forge Class * - * @access public * @return string */ - function dbforge() + public function dbforge() { if ( ! class_exists('CI_DB')) { @@ -297,13 +291,12 @@ class CI_Loader { * some cases it's advantageous to be able to return data so that * a developer can process it in some way. * - * @access public * @param string * @param array * @param bool * @return void */ - function view($view, $vars = array(), $return = FALSE) + 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)); } @@ -315,12 +308,11 @@ class CI_Loader { * * This is a generic file loader * - * @access public * @param string * @param bool * @return string */ - function file($path, $return = FALSE) + public function file($path, $return = FALSE) { return $this->_ci_load(array('_ci_path' => $path, '_ci_return' => $return)); } @@ -333,11 +325,10 @@ class CI_Loader { * Once variables are set they become available within * the controller class and its "view" files. * - * @access public * @param array * @return void */ - function vars($vars = array(), $val = '') + public function vars($vars = array(), $val = '') { if ($val != '' AND is_string($vars)) { @@ -362,11 +353,10 @@ class CI_Loader { * * This function loads the specified helper file. * - * @access public * @param mixed * @return void */ - function helper($helpers = array()) + public function helper($helpers = array()) { foreach ($this->_ci_prep_filename($helpers, '_helper') as $helper) { @@ -424,11 +414,10 @@ class CI_Loader { * This is simply an alias to the above function in case the * user has written the plural form of this function. * - * @access public * @param array * @return void */ - function helpers($helpers = array()) + public function helpers($helpers = array()) { $this->helper($helpers); } @@ -438,12 +427,11 @@ class CI_Loader { /** * Loads a language file * - * @access public * @param array * @param string * @return void */ - function language($file = array(), $lang = '') + public function language($file = array(), $lang = '') { $CI =& get_instance(); @@ -463,11 +451,10 @@ class CI_Loader { /** * Loads a config file * - * @access public * @param string * @return void */ - function config($file = '', $use_sections = FALSE, $fail_gracefully = FALSE) + public function config($file = '', $use_sections = FALSE, $fail_gracefully = FALSE) { $CI =& get_instance(); $CI->config->load($file, $use_sections, $fail_gracefully); @@ -485,7 +472,7 @@ class CI_Loader { * @param string an optional object name * @return void */ - function driver($library = '', $params = NULL, $object_name = NULL) + public function driver($library = '', $params = NULL, $object_name = NULL) { if ( ! class_exists('CI_Driver_Library')) { @@ -510,18 +497,20 @@ class CI_Loader { * * Prepends a parent path to the library, model, helper, and config path arrays * - * @access public * @param string + * @param boolean * @return void */ - function add_package_path($path) + 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); @@ -534,11 +523,10 @@ class CI_Loader { * * Return a list of all package paths, by default it will ignore BASEPATH. * - * @access public * @param string * @return void */ - function get_package_paths($include_base = FALSE) + public function get_package_paths($include_base = FALSE) { return $include_base === TRUE ? $this->_ci_library_paths : $this->_ci_model_paths; } @@ -551,11 +539,10 @@ class CI_Loader { * 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. * - * @access public * @param type * @return type */ - function remove_package_path($path = '', $remove_config_path = TRUE) + public function remove_package_path($path = '', $remove_config_path = TRUE) { $config =& $this->_ci_get_component('config'); @@ -564,12 +551,12 @@ class CI_Loader { $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) @@ -577,6 +564,11 @@ class CI_Loader { 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) { @@ -588,6 +580,7 @@ class CI_Loader { $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))); } @@ -600,24 +593,39 @@ class CI_Loader { * Variables are prefixed with _ci_ to avoid symbol collision with * variables made available to view files * - * @access private * @param array * @return void */ - function _ci_load($_ci_data) + 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_ext = pathinfo($_ci_view, PATHINFO_EXTENSION); $_ci_file = ($_ci_ext == '') ? $_ci_view.'.php' : $_ci_view; - $_ci_path = $this->_ci_view_path.$_ci_file; + + 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; + } + } } else { @@ -625,7 +633,7 @@ class CI_Loader { $_ci_file = end($_ci_x); } - if ( ! file_exists($_ci_path)) + if ( ! $file_exists && ! file_exists($_ci_path)) { show_error('Unable to load the requested file: '.$_ci_file); } @@ -721,13 +729,12 @@ class CI_Loader { * * This function loads the requested class. * - * @access private * @param string the item that is being loaded * @param mixed any additional parameters * @param string an optional object name * @return void */ - function _ci_load_class($class, $params = NULL, $object_name = NULL) + 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, @@ -959,11 +966,13 @@ class CI_Loader { * The config/autoload.php file contains an array that permits sub-systems, * libraries, and helpers to be loaded automatically. * - * @access private + * This function is public, as it's used in the CI_Controller class. + * However, there is no reason you should ever needs to use it. + * * @param array * @return void */ - function _ci_autoloader() + public function ci_autoloader() { if (defined('ENVIRONMENT') AND file_exists(APPPATH.'config/'.ENVIRONMENT.'/autoload.php')) { @@ -1046,11 +1055,10 @@ class CI_Loader { * * Takes an object as input and converts the class variables to array key/vals * - * @access private * @param object * @return array */ - function _ci_object_to_array($object) + protected function _ci_object_to_array($object) { return (is_object($object)) ? get_object_vars($object) : $object; } @@ -1060,10 +1068,9 @@ class CI_Loader { /** * Get a reference to a specific library or model * - * @access private * @return bool */ - function &_ci_get_component($component) + protected function &_ci_get_component($component) { $CI =& get_instance(); return $CI->$component; @@ -1076,11 +1083,10 @@ class CI_Loader { * * This function preps the name of various items to make loading them more reliable. * - * @access private * @param mixed * @return array */ - function _ci_prep_filename($filename, $extension) + protected function _ci_prep_filename($filename, $extension) { if ( ! is_array($filename)) { -- cgit v1.2.3-24-g4f1b From b3e614d8b2293c079bcfb9cfdf071c041cbc4722 Mon Sep 17 00:00:00 2001 From: Greg Aker Date: Tue, 19 Apr 2011 20:19:17 -0500 Subject: Change in core/Security.php to match coding standards. --- system/core/Security.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'system') diff --git a/system/core/Security.php b/system/core/Security.php index 4f91572ed..3617cadcc 100644 --- a/system/core/Security.php +++ b/system/core/Security.php @@ -68,7 +68,8 @@ class CI_Security { } // Append application specific cookie prefix - if (config_item('cookie_prefix')) { + if (config_item('cookie_prefix')) + { $this->_csrf_cookie_name = config_item('cookie_prefix').$this->_csrf_cookie_name; } -- cgit v1.2.3-24-g4f1b From 0c9ee4a348a9e0c9ee6d6c0085e463e098e453f4 Mon Sep 17 00:00:00 2001 From: Greg Aker Date: Wed, 20 Apr 2011 09:40:17 -0500 Subject: Refactoring the loader to set protected class variables. Moved _ci_autoload(), which is used in CI_Controller to be a public method. Also added CI_Loader::set_base_classes() to be called in the controller so we're not setting protected vars in another class. Also refactored in the form_helper so it's not trying to access protected vars in CI_Loader. Added the is_loaded() method to the loader to take care of the checks that were being done there. --- system/core/Controller.php | 7 ++-- system/core/Loader.php | 75 +++++++++++++++++++++++++++++++----------- system/helpers/form_helper.php | 24 +++++++------- 3 files changed, 69 insertions(+), 37 deletions(-) (limited to 'system') diff --git a/system/core/Controller.php b/system/core/Controller.php index fd9c8b580..ec86b7920 100644 --- a/system/core/Controller.php +++ b/system/core/Controller.php @@ -48,12 +48,9 @@ class CI_Controller { $this->load =& load_class('Loader', 'core'); - $this->load->_base_classes =& is_loaded(); - - $this->load->ci_autoloader(); - + $this->load->set_base_classes()->ci_autoloader(); + log_message('debug', "Controller Class Initialized"); - } public static function &get_instance() diff --git a/system/core/Loader.php b/system/core/Loader.php index 8146cd563..a52ef288a 100644 --- a/system/core/Loader.php +++ b/system/core/Loader.php @@ -29,19 +29,19 @@ class CI_Loader { // All these are set automatically. Don't mess with them. - var $_ci_ob_level; - var $_ci_view_paths = array(); + protected $_ci_ob_level; + protected $_ci_view_paths = array(); protected $_ci_library_paths = array(); - var $_ci_model_paths = array(); - var $_ci_helper_paths = array(); - var $_base_classes = array(); // Set by the controller class - var $_ci_cached_vars = array(); - var $_ci_classes = array(); - var $_ci_loaded_files = array(); - var $_ci_models = array(); - var $_ci_helpers = array(); - var $_ci_varmap = array('unit_test' => 'unit', 'user_agent' => 'agent'); - + protected $_ci_model_paths = array(); + protected $_ci_helper_paths = array(); + protected $_base_classes = array(); // Set by the controller class + protected $_ci_cached_vars = array(); + protected $_ci_classes = array(); + protected $_ci_loaded_files = array(); + protected $_ci_models = array(); + protected $_ci_helpers = array(); + protected $_ci_varmap = array('unit_test' => 'unit', + 'user_agent' => 'agent'); /** * Constructor @@ -59,6 +59,47 @@ class CI_Loader { log_message('debug', "Loader Class Initialized"); } + // -------------------------------------------------------------------- + + /** + * Set _base_classes variable + * + * This method is called once in CI_Controller. + * + * @param array + * @return object + */ + public function set_base_classes() + { + $this->_base_classes =& is_loaded(); + + 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; + } + // -------------------------------------------------------------------- /** @@ -67,13 +108,12 @@ class CI_Loader { * This function lets users load and instantiate classes. * It is designed to be called from a user's app controllers. * - * @access public * @param string the name of the class * @param mixed the optional parameters * @param string an optional object name * @return void */ - function library($library = '', $params = NULL, $object_name = NULL) + public function library($library = '', $params = NULL, $object_name = NULL) { if (is_array($library)) { @@ -856,13 +896,12 @@ class CI_Loader { /** * Instantiates a class * - * @access private * @param string * @param string * @param string an optional object name * @return null */ - function _ci_init_class($class, $prefix = '', $config = FALSE, $object_name = 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) @@ -1102,9 +1141,7 @@ class CI_Loader { return $filename; } } - - } /* End of file Loader.php */ -/* Location: ./system/core/Loader.php */ +/* Location: ./system/core/Loader.php */ \ No newline at end of file diff --git a/system/helpers/form_helper.php b/system/helpers/form_helper.php index a5cd97b82..51a9c6ca3 100644 --- a/system/helpers/form_helper.php +++ b/system/helpers/form_helper.php @@ -1032,22 +1032,20 @@ if ( ! function_exists('_get_validation_object')) { $CI =& get_instance(); - // We set this as a variable since we're returning by reference + // We set this as a variable since we're returning by reference. $return = FALSE; - - if ( ! isset($CI->load->_ci_classes) OR ! isset($CI->load->_ci_classes['form_validation'])) - { - return $return; - } - - $object = $CI->load->_ci_classes['form_validation']; - - if ( ! isset($CI->$object) OR ! is_object($CI->$object)) + + if ( ! ($object = $CI->load->is_loaded('form_validation'))) { - return $return; + if ( ! isset($CI->$object) OR ! is_object($CI->$object)) + { + return $return; + } + + return $CI->$object; } - - return $CI->$object; + + return $return; } } -- cgit v1.2.3-24-g4f1b From 50671cf8d67c805692fec49eda33d21227a21ec2 Mon Sep 17 00:00:00 2001 From: Greg Aker Date: Wed, 20 Apr 2011 11:36:45 -0500 Subject: Altered Session to use a longer match against the user_agent string. See upgrade notes if using database sessions.sess_match_useragent == TRUE AND trim($session['user_agent']) != trim(substr($this->CI->input->user_agent(), 0, 50))) + 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; @@ -316,7 +316,7 @@ class CI_Session { $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, 50), + 'user_agent' => substr($this->CI->input->user_agent(), 0, 120), 'last_activity' => $this->now ); -- cgit v1.2.3-24-g4f1b From e156c6eb4a018a91d3cfcaa2d1fd3b3e67dc2808 Mon Sep 17 00:00:00 2001 From: Greg Aker Date: Wed, 20 Apr 2011 16:03:04 -0500 Subject: Fixed a bug (Core #340) where when passing in the second parameter to $this->db->select(), column names in subsequent queries would not be properly escaped. --- system/database/DB_active_rec.php | 20 ++++++++------------ 1 file changed, 8 insertions(+), 12 deletions(-) (limited to 'system') diff --git a/system/database/DB_active_rec.php b/system/database/DB_active_rec.php index db8471364..9ceac0b76 100644 --- a/system/database/DB_active_rec.php +++ b/system/database/DB_active_rec.php @@ -58,6 +58,8 @@ class CI_DB_active_record extends CI_DB_driver { var $ar_cache_having = array(); var $ar_cache_orderby = array(); var $ar_cache_set = array(); + + var $ar_no_escape = array(); // -------------------------------------------------------------------- @@ -73,12 +75,6 @@ class CI_DB_active_record extends CI_DB_driver { */ function select($select = '*', $escape = NULL) { - // Set the global value if this was sepecified - if (is_bool($escape)) - { - $this->_protect_identifiers = $escape; - } - if (is_string($select)) { $select = explode(',', $select); @@ -91,6 +87,7 @@ class CI_DB_active_record extends CI_DB_driver { if ($val != '') { $this->ar_select[] = $val; + $this->ar_no_escape[] = $escape; if ($this->ar_caching === TRUE) { @@ -441,10 +438,10 @@ class CI_DB_active_record extends CI_DB_driver { $v = ' '.$this->escape($v); } - + if ( ! $this->_has_operator($k)) { - $k .= ' ='; + $k .= ' = '; } } else @@ -1718,7 +1715,7 @@ class CI_DB_active_record extends CI_DB_driver { // is because until the user calls the from() function we don't know if there are aliases foreach ($this->ar_select as $key => $val) { - $this->ar_select[$key] = $this->_protect_identifiers($val); + $this->ar_select[$key] = $this->_protect_identifiers($val, FALSE, $this->ar_no_escape[$key]); } $sql .= implode(', ', $this->ar_select); @@ -1753,9 +1750,7 @@ class CI_DB_active_record extends CI_DB_driver { if (count($this->ar_where) > 0 OR count($this->ar_like) > 0) { - $sql .= "\n"; - - $sql .= "WHERE "; + $sql .= "\nWHERE "; } $sql .= implode("\n", $this->ar_where); @@ -2032,6 +2027,7 @@ class CI_DB_active_record extends CI_DB_driver { 'ar_orderby' => array(), 'ar_wherein' => array(), 'ar_aliased_tables' => array(), + 'ar_no_escape' => array(), 'ar_distinct' => FALSE, 'ar_limit' => FALSE, 'ar_offset' => FALSE, -- cgit v1.2.3-24-g4f1b From 8807be35fe02a39624e62a412889e938b6a37691 Mon Sep 17 00:00:00 2001 From: Greg Aker Date: Thu, 21 Apr 2011 13:06:15 -0500 Subject: Flipping around contents of a conditional in _ci_load() so the small bits are on top. --- system/core/Loader.php | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'system') diff --git a/system/core/Loader.php b/system/core/Loader.php index a52ef288a..721c196cc 100644 --- a/system/core/Loader.php +++ b/system/core/Loader.php @@ -647,7 +647,12 @@ class CI_Loader { $file_exists = FALSE; // Set the path to the requested file - if ($_ci_path == '') + 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; @@ -667,11 +672,6 @@ class CI_Loader { } } } - else - { - $_ci_x = explode('/', $_ci_path); - $_ci_file = end($_ci_x); - } if ( ! $file_exists && ! file_exists($_ci_path)) { -- cgit v1.2.3-24-g4f1b From d127e611c64fd1cf6a750b20c4e35b1158e06e27 Mon Sep 17 00:00:00 2001 From: katzgrau Date: Fri, 22 Apr 2011 10:59:25 -0400 Subject: Fixed re-searching for config file even though one had been loaded ($found was set to true, never reset). Also fixes getsparks issue. --- system/core/Config.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'system') diff --git a/system/core/Config.php b/system/core/Config.php index 4493ff266..1096a9ea6 100644 --- a/system/core/Config.php +++ b/system/core/Config.php @@ -144,6 +144,7 @@ class CI_Config { $loaded = TRUE; log_message('debug', 'Config file loaded: '.$file_path); + break; } if ($loaded === FALSE) @@ -326,4 +327,4 @@ class CI_Config { // END CI_Config class /* End of file Config.php */ -/* Location: ./system/core/Config.php */ \ No newline at end of file +/* Location: ./system/core/Config.php */ -- cgit v1.2.3-24-g4f1b From c6d918ad24a8844e9de1e145f545bc9f2c7ca9a6 Mon Sep 17 00:00:00 2001 From: Greg Aker Date: Fri, 22 Apr 2011 10:17:32 -0500 Subject: Fix #233 Fixing a regression in _get_validation_object() in the form helper after some refactoring the other day. --- system/helpers/form_helper.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'system') diff --git a/system/helpers/form_helper.php b/system/helpers/form_helper.php index 51a9c6ca3..16eb4b2c9 100644 --- a/system/helpers/form_helper.php +++ b/system/helpers/form_helper.php @@ -898,7 +898,7 @@ if ( ! function_exists('validation_errors')) function validation_errors($prefix = '', $suffix = '') { if (FALSE === ($OBJ =& _get_validation_object())) - { + {var_dump(_get_validation_object()); exit; return ''; } @@ -1035,7 +1035,7 @@ if ( ! function_exists('_get_validation_object')) // We set this as a variable since we're returning by reference. $return = FALSE; - if ( ! ($object = $CI->load->is_loaded('form_validation'))) + if (FALSE !== ($object = $CI->load->is_loaded('form_validation'))) { if ( ! isset($CI->$object) OR ! is_object($CI->$object)) { -- cgit v1.2.3-24-g4f1b From c0b133c02e057b6506726b794ba4582bf18ed663 Mon Sep 17 00:00:00 2001 From: kenjis Date: Fri, 22 Apr 2011 19:58:43 +0900 Subject: default value of $total_rows in Pagination class should be number. And fix User Guide Pagination Class's Example which uses string to number variable. --- system/libraries/Pagination.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system') diff --git a/system/libraries/Pagination.php b/system/libraries/Pagination.php index 1113f862f..cc62e660b 100644 --- a/system/libraries/Pagination.php +++ b/system/libraries/Pagination.php @@ -30,7 +30,7 @@ class CI_Pagination { var $prefix = ''; // A custom prefix added to the path. var $suffix = ''; // A custom suffix added to the path. - var $total_rows = ''; // Total number of items (database results) + var $total_rows = 0; // Total number of items (database results) var $per_page = 10; // Max number of items you want shown per page var $num_links = 2; // Number of "digit" links to show before/after the currently viewed page var $cur_page = 0; // The current page being viewed -- cgit v1.2.3-24-g4f1b From ee21a0eebfac7f3de810d9f8c4f8271944b336bf Mon Sep 17 00:00:00 2001 From: Derek Jones Date: Fri, 22 Apr 2011 17:37:19 -0500 Subject: typo in modification to MySQLi driver. Fixes #236 --- system/database/drivers/mysqli/mysqli_driver.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system') diff --git a/system/database/drivers/mysqli/mysqli_driver.php b/system/database/drivers/mysqli/mysqli_driver.php index 1949acb6e..b8586c21d 100644 --- a/system/database/drivers/mysqli/mysqli_driver.php +++ b/system/database/drivers/mysqli/mysqli_driver.php @@ -137,7 +137,7 @@ class CI_DB_mysqli_driver extends CI_DB { if ( ! isset($use_set_names)) { // mysqli_set_charset() requires MySQL >= 5.0.7, use SET NAMES as fallback - $use_set_names = (version_compare(mysql_get_server_info(), '5.0.7', '>=')) ? FALSE : TRUE; + $use_set_names = (version_compare(mysqli_get_server_info($this->conn_id), '5.0.7', '>=')) ? FALSE : TRUE; } if ($use_set_names) -- cgit v1.2.3-24-g4f1b From c83bea665eb3a441b6e52528f75fa4c71ca1f8c2 Mon Sep 17 00:00:00 2001 From: Greg Aker Date: Sat, 23 Apr 2011 12:12:57 -0500 Subject: Removing debug code accidentally committed. --- system/helpers/form_helper.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system') diff --git a/system/helpers/form_helper.php b/system/helpers/form_helper.php index 16eb4b2c9..2925d3c7c 100644 --- a/system/helpers/form_helper.php +++ b/system/helpers/form_helper.php @@ -898,7 +898,7 @@ if ( ! function_exists('validation_errors')) function validation_errors($prefix = '', $suffix = '') { if (FALSE === ($OBJ =& _get_validation_object())) - {var_dump(_get_validation_object()); exit; + { return ''; } -- cgit v1.2.3-24-g4f1b From c24f49b54f47229aa89781c0cc06c3d9fa947937 Mon Sep 17 00:00:00 2001 From: Razican Date: Mon, 25 Apr 2011 13:43:57 +0200 Subject: Fixed #60. --- system/libraries/Profiler.php | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) (limited to 'system') diff --git a/system/libraries/Profiler.php b/system/libraries/Profiler.php index b73ddaf0d..082a5ee1d 100644 --- a/system/libraries/Profiler.php +++ b/system/libraries/Profiler.php @@ -44,13 +44,13 @@ class CI_Profiler { 'session_data', 'config' ); - + protected $_query_toggle_count = 25; - - protected $CI; + + protected $CI; // -------------------------------------------------------------------- - + public function __construct($config = array()) { $this->CI =& get_instance(); @@ -188,22 +188,22 @@ class CI_Profiler { $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.''; @@ -412,7 +412,7 @@ class CI_Profiler { } else { - $output .= "
    ".$this->CI->lang->line('profiler_no_memory_usage')."
    "; + $output .= "
    ".$this->CI->lang->line('profiler_no_memory')."
    "; } $output .= "
    "; -- cgit v1.2.3-24-g4f1b From 114ab0988e20ac6be39ad363ff897a1a3b85e565 Mon Sep 17 00:00:00 2001 From: Razican Date: Mon, 25 Apr 2011 17:26:45 +0200 Subject: Fixed double-space typo. --- system/core/Benchmark.php | 4 +- system/core/CodeIgniter.php | 68 +++---- system/core/Common.php | 28 +-- system/core/Config.php | 18 +- system/core/Controller.php | 6 +- system/core/Exceptions.php | 6 +- system/core/Hooks.php | 4 +- system/core/Input.php | 24 +-- system/core/Lang.php | 2 +- system/core/Loader.php | 60 +++--- system/core/Model.php | 2 +- system/core/Output.php | 20 +- system/core/Router.php | 26 +-- system/core/Security.php | 104 +++++----- system/core/URI.php | 14 +- system/core/Utf8.php | 2 +- system/database/DB.php | 16 +- system/database/DB_active_rec.php | 32 +-- system/database/DB_cache.php | 6 +- system/database/DB_driver.php | 34 ++-- system/database/DB_forge.php | 2 +- system/database/DB_result.php | 106 +++++----- system/database/DB_utility.php | 6 +- system/database/drivers/mssql/mssql_driver.php | 2 +- system/database/drivers/mssql/mssql_forge.php | 4 +- system/database/drivers/mssql/mssql_result.php | 4 +- system/database/drivers/mssql/mssql_utility.php | 2 +- system/database/drivers/mysql/mysql_driver.php | 14 +- system/database/drivers/mysql/mysql_forge.php | 4 +- system/database/drivers/mysql/mysql_result.php | 4 +- system/database/drivers/mysql/mysql_utility.php | 4 +- system/database/drivers/mysqli/mysqli_driver.php | 8 +- system/database/drivers/mysqli/mysqli_forge.php | 4 +- system/database/drivers/mysqli/mysqli_result.php | 4 +- system/database/drivers/mysqli/mysqli_utility.php | 2 +- system/database/drivers/oci8/oci8_driver.php | 138 ++++++------- system/database/drivers/oci8/oci8_forge.php | 4 +- system/database/drivers/oci8/oci8_result.php | 34 ++-- system/database/drivers/oci8/oci8_utility.php | 2 +- system/database/drivers/odbc/odbc_driver.php | 2 +- system/database/drivers/odbc/odbc_forge.php | 4 +- system/database/drivers/odbc/odbc_result.php | 4 +- system/database/drivers/odbc/odbc_utility.php | 2 +- system/database/drivers/postgre/postgre_driver.php | 2 +- system/database/drivers/postgre/postgre_forge.php | 10 +- system/database/drivers/postgre/postgre_result.php | 4 +- .../database/drivers/postgre/postgre_utility.php | 2 +- system/database/drivers/sqlite/sqlite_driver.php | 2 +- system/database/drivers/sqlite/sqlite_forge.php | 6 +- system/database/drivers/sqlite/sqlite_result.php | 4 +- system/database/drivers/sqlite/sqlite_utility.php | 4 +- system/helpers/array_helper.php | 8 +- system/helpers/captcha_helper.php | 20 +- system/helpers/cookie_helper.php | 6 +- system/helpers/date_helper.php | 22 +-- system/helpers/directory_helper.php | 4 +- system/helpers/download_helper.php | 2 +- system/helpers/email_helper.php | 2 +- system/helpers/file_helper.php | 4 +- system/helpers/form_helper.php | 18 +- system/helpers/html_helper.php | 10 +- system/helpers/inflector_helper.php | 14 +- system/helpers/language_helper.php | 2 +- system/helpers/number_helper.php | 2 +- system/helpers/path_helper.php | 4 +- system/helpers/security_helper.php | 4 +- system/helpers/smiley_helper.php | 12 +- system/helpers/string_helper.php | 8 +- system/helpers/text_helper.php | 10 +- system/helpers/typography_helper.php | 2 +- system/helpers/url_helper.php | 6 +- system/helpers/xml_helper.php | 4 +- system/language/english/email_lang.php | 6 +- system/language/english/imglib_lang.php | 10 +- system/libraries/Cache/Cache.php | 30 +-- system/libraries/Cache/drivers/Cache_apc.php | 24 +-- system/libraries/Cache/drivers/Cache_file.php | 40 ++-- system/libraries/Calendar.php | 18 +- system/libraries/Cart.php | 22 +-- system/libraries/Driver.php | 2 +- system/libraries/Email.php | 46 ++--- system/libraries/Encrypt.php | 2 +- system/libraries/Form_validation.php | 32 +-- system/libraries/Ftp.php | 8 +- system/libraries/Image_lib.php | 118 +++++------ system/libraries/Javascript.php | 12 +- system/libraries/Log.php | 8 +- system/libraries/Pagination.php | 18 +- system/libraries/Parser.php | 18 +- system/libraries/Profiler.php | 26 +-- system/libraries/Session.php | 30 +-- system/libraries/Sha1.php | 8 +- system/libraries/Table.php | 12 +- system/libraries/Trackback.php | 16 +- system/libraries/Typography.php | 36 ++-- system/libraries/Unit_test.php | 2 +- system/libraries/Upload.php | 28 +-- system/libraries/User_agent.php | 2 +- system/libraries/Xmlrpc.php | 90 ++++----- system/libraries/Xmlrpcs.php | 44 ++--- system/libraries/Zip.php | 12 +- system/libraries/javascript/Jquery.php | 218 ++++++++++----------- 102 files changed, 986 insertions(+), 986 deletions(-) (limited to 'system') diff --git a/system/core/Benchmark.php b/system/core/Benchmark.php index 515550e9f..3686c2d73 100644 --- a/system/core/Benchmark.php +++ b/system/core/Benchmark.php @@ -1,4 +1,4 @@ -_call_hook('pre_system'); /* * ------------------------------------------------------ - * Instantiate the config class + * Instantiate the config class * ------------------------------------------------------ */ $CFG =& load_class('Config', 'core'); @@ -143,7 +143,7 @@ /* * ------------------------------------------------------ - * Instantiate the UTF-8 class + * Instantiate the UTF-8 class * ------------------------------------------------------ * * Note: Order here is rather important as the UTF-8 @@ -157,14 +157,14 @@ /* * ------------------------------------------------------ - * Instantiate the URI class + * Instantiate the URI class * ------------------------------------------------------ */ $URI =& load_class('URI', 'core'); /* * ------------------------------------------------------ - * Instantiate the routing class and set the routing + * Instantiate the routing class and set the routing * ------------------------------------------------------ */ $RTR =& load_class('Router', 'core'); @@ -178,14 +178,14 @@ /* * ------------------------------------------------------ - * Instantiate the output class + * Instantiate the output class * ------------------------------------------------------ */ $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) @@ -205,21 +205,21 @@ /* * ------------------------------------------------------ - * Load the Input class and sanitize globals + * Load the Input class and sanitize globals * ------------------------------------------------------ */ $IN =& load_class('Input', 'core'); /* * ------------------------------------------------------ - * Load the Language class + * Load the Language class * ------------------------------------------------------ */ $LANG =& load_class('Lang', 'core'); /* * ------------------------------------------------------ - * Load the app controller and local controller + * Load the app controller and local controller * ------------------------------------------------------ * */ @@ -252,14 +252,14 @@ /* * ------------------------------------------------------ - * Security check + * Security check * ------------------------------------------------------ * - * 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 + * 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(); + $class = $RTR->fetch_class(); $method = $RTR->fetch_method(); if ( ! class_exists($class) @@ -272,14 +272,14 @@ /* * ------------------------------------------------------ - * Is there a "pre_controller" hook? + * Is there a "pre_controller" hook? * ------------------------------------------------------ */ $EXT->_call_hook('pre_controller'); /* * ------------------------------------------------------ - * Instantiate the requested controller + * Instantiate the requested controller * ------------------------------------------------------ */ // Mark a start point so we can benchmark the controller @@ -289,14 +289,14 @@ /* * ------------------------------------------------------ - * Is there a "post_controller_constructor" hook? + * Is there a "post_controller_constructor" hook? * ------------------------------------------------------ */ $EXT->_call_hook('post_controller_constructor'); /* * ------------------------------------------------------ - * Call the requested method + * Call the requested method * ------------------------------------------------------ */ // Is there a "remap" function? If so, we call it instead @@ -345,14 +345,14 @@ /* * ------------------------------------------------------ - * Is there a "post_controller" hook? + * Is there a "post_controller" hook? * ------------------------------------------------------ */ $EXT->_call_hook('post_controller'); /* * ------------------------------------------------------ - * Send the final rendered output to the browser + * Send the final rendered output to the browser * ------------------------------------------------------ */ if ($EXT->_call_hook('display_override') === FALSE) @@ -362,14 +362,14 @@ /* * ------------------------------------------------------ - * Is there a "post_system" hook? + * Is there a "post_system" hook? * ------------------------------------------------------ */ $EXT->_call_hook('post_system'); /* * ------------------------------------------------------ - * Close the DB connection if one exists + * Close the DB connection if one exists * ------------------------------------------------------ */ if (class_exists('CI_DB') AND isset($CI->db)) diff --git a/system/core/Common.php b/system/core/Common.php index d1e8e77e9..eb9e14425 100644 --- a/system/core/Common.php +++ b/system/core/Common.php @@ -1,4 +1,4 @@ -show_php_error($severity, $message, $filepath, $line); } - // Should we log the error? No? We're done... + // Should we log the error? No? We're done... if (config_item('log_threshold') == 0) { return; @@ -479,16 +479,16 @@ function remove_invisible_characters($str, $url_encoded = TRUE) { $non_displayables = array(); - + // every control character except newline (dec 10) // carriage return (dec 13), and horizontal tab (dec 09) - + if ($url_encoded) { $non_displayables[] = '/%0[0-8bcef]/'; // url encoded 00-08, 11, 12, 14, 15 $non_displayables[] = '/%1[0-9a-f]/'; // url encoded 16-31 } - + $non_displayables[] = '/[\x00-\x08\x0B\x0C\x0E-\x1F\x7F]+/S'; // 00-08, 11, 12, 14-31, 127 do diff --git a/system/core/Config.php b/system/core/Config.php index 1096a9ea6..fa71f4d3d 100644 --- a/system/core/Config.php +++ b/system/core/Config.php @@ -1,4 +1,4 @@ -load =& load_class('Loader', 'core'); $this->load->set_base_classes()->ci_autoloader(); - + log_message('debug', "Controller Class Initialized"); } diff --git a/system/core/Exceptions.php b/system/core/Exceptions.php index bff86a92f..2503c907f 100644 --- a/system/core/Exceptions.php +++ b/system/core/Exceptions.php @@ -1,4 +1,4 @@ -ob_level = ob_get_level(); - // Note: Do not log messages from this constructor. + // Note: Do not log messages from this constructor. } // -------------------------------------------------------------------- @@ -75,7 +75,7 @@ class CI_Exceptions { { $severity = ( ! isset($this->levels[$severity])) ? $severity : $this->levels[$severity]; - log_message('error', 'Severity: '.$severity.' --> '.$message. ' '.$filepath.' '.$line, TRUE); + log_message('error', 'Severity: '.$severity.' --> '.$message. ' '.$filepath.' '.$line, TRUE); } // -------------------------------------------------------------------- diff --git a/system/core/Hooks.php b/system/core/Hooks.php index fd6380f0a..ffb3258d8 100644 --- a/system/core/Hooks.php +++ b/system/core/Hooks.php @@ -1,4 +1,4 @@ -_fetch_from_array($_POST, $index, $xss_clean); } @@ -201,7 +201,7 @@ class CI_Input { * @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 domain. Usually: .yourdomain.com * @param string the cookie path * @param string the cookie prefix * @param bool true makes the cookie secure @@ -402,9 +402,9 @@ class CI_Input { function _sanitize_globals() { // It would be "wrong" to unset any of these GLOBALS. - $protected = array('_SERVER', '_GET', '_POST', '_FILES', '_REQUEST', + $protected = array('_SERVER', '_GET', '_POST', '_FILES', '_REQUEST', '_SESSION', '_ENV', 'GLOBALS', 'HTTP_RAW_POST_DATA', - 'system_folder', 'application_folder', 'BM', 'EXT', + 'system_folder', 'application_folder', 'BM', 'EXT', 'CFG', 'URI', 'RTR', 'OUT', 'IN'); // Unset globals for securiy. @@ -523,7 +523,7 @@ class CI_Input { { $str = $this->uni->clean_string($str); } - + // Remove control characters $str = remove_invisible_characters($str); @@ -579,7 +579,7 @@ class CI_Input { /** * Request Headers * - * In Apache, you can simply call apache_request_headers(), however for + * In Apache, you can simply call apache_request_headers(), however for * people running other webservers the function is undefined. * * @return array @@ -609,10 +609,10 @@ class CI_Input { { $key = str_replace('_', ' ', strtolower($key)); $key = str_replace(' ', '-', ucwords($key)); - + $this->headers[$key] = $val; } - + return $this->headers; } @@ -633,7 +633,7 @@ class CI_Input { { $this->request_headers(); } - + if ( ! isset($this->headers[$index])) { return FALSE; @@ -644,7 +644,7 @@ class CI_Input { return $this->security->xss_clean($this->headers[$index]); } - return $this->headers[$index]; + return $this->headers[$index]; } // -------------------------------------------------------------------- diff --git a/system/core/Lang.php b/system/core/Lang.php index 170e6c725..79eb443a0 100644 --- a/system/core/Lang.php +++ b/system/core/Lang.php @@ -1,4 +1,4 @@ - 'unit', + protected $_ci_varmap = array('unit_test' => 'unit', 'user_agent' => 'agent'); /** @@ -50,29 +50,29 @@ class CI_Loader { */ public function __construct() { - $this->_ci_ob_level = ob_get_level(); + $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"); } // -------------------------------------------------------------------- - + /** * Set _base_classes variable * * This method is called once in CI_Controller. * - * @param array + * @param array * @return object */ public function set_base_classes() { $this->_base_classes =& is_loaded(); - + return $this; } @@ -96,7 +96,7 @@ class CI_Loader { { return $this->_ci_classes[$class]; } - + return FALSE; } @@ -260,7 +260,7 @@ class CI_Loader { return DB($params, $active_record); } - // Initialize the db variable. Needed to prevent + // Initialize the db variable. Needed to prevent // reference errors with some configurations $CI->db = ''; @@ -323,11 +323,11 @@ class CI_Loader { /** * Load View * - * This function is used to load a "view" file. It has three parameters: + * 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 + * 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. * @@ -538,13 +538,13 @@ class CI_Loader { * Prepends a parent path to the library, model, helper, and config path arrays * * @param string - * @param boolean + * @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); @@ -604,7 +604,7 @@ class CI_Loader { unset($this->{$var}[$key]); } } - + if (isset($this->_ci_view_paths[$path.'views/'])) { unset($this->_ci_view_paths[$path.'views/']); @@ -643,7 +643,7 @@ class CI_Loader { { $$_ci_val = ( ! isset($_ci_data[$_ci_val])) ? FALSE : $_ci_data[$_ci_val]; } - + $file_exists = FALSE; // Set the path to the requested file @@ -665,11 +665,11 @@ class CI_Loader { $file_exists = TRUE; break; } - + if ( ! $cascade) { break; - } + } } } @@ -710,9 +710,9 @@ class CI_Loader { * We buffer the output for two reasons: * 1. Speed. You get a significant speed boost. * 2. So that the final rendered template can be - * post-processed by the output class. Why do we - * need post processing? For one thing, in order to - * show the elapsed page load time. Unless we + * 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. */ @@ -809,11 +809,11 @@ class CI_Loader { show_error("Unable to load the requested class: ".$class); } - // Safety: Was the class already loaded by a previous call? + // 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 + // if a custom object name is being supplied. If so, we'll // return a new instance of the object if ( ! is_null($object_name)) { @@ -842,17 +842,17 @@ class CI_Loader { { $filepath = $path.'libraries/'.$subdir.$class.'.php'; - // Does the file exist? No? Bummer... + // Does the file exist? No? Bummer... if ( ! file_exists($filepath)) { continue; } - // Safety: Was the class already loaded by a previous call? + // 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 + // if a custom object name is being supplied. If so, we'll // return a new instance of the object if ( ! is_null($object_name)) { @@ -875,7 +875,7 @@ class CI_Loader { } // END FOREACH - // One last attempt. Maybe the library is in a subdirectory, but it wasn't specified? + // One last attempt. Maybe the library is in a subdirectory, but it wasn't specified? if ($subdir == '') { $path = strtolower($class).'/'.$class; @@ -903,7 +903,7 @@ class CI_Loader { */ 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 + // 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 @@ -970,7 +970,7 @@ class CI_Loader { } // Set the variable name we will assign the class to - // Was a custom class name supplied? If so we'll use it + // Was a custom class name supplied? If so we'll use it $class = strtolower($class); if (is_null($object_name)) @@ -1005,7 +1005,7 @@ class CI_Loader { * The config/autoload.php file contains an array that permits sub-systems, * libraries, and helpers to be loaded automatically. * - * This function is public, as it's used in the CI_Controller class. + * This function is public, as it's used in the CI_Controller class. * However, there is no reason you should ever needs to use it. * * @param array @@ -1021,7 +1021,7 @@ class CI_Loader { { include_once(APPPATH.'config/autoload.php'); } - + if ( ! isset($autoload)) { diff --git a/system/core/Model.php b/system/core/Model.php index 8566a0b66..61c71b672 100644 --- a/system/core/Model.php +++ b/system/core/Model.php @@ -1,4 +1,4 @@ -final_output * * This function sends the finalized output data to the browser along - * with any server headers and profile data. It also stops the + * 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 @@ -269,7 +269,7 @@ class CI_Output { */ function _display($output = '') { - // Note: We use globals because we can't use $CI =& get_instance() + // 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; @@ -290,7 +290,7 @@ class CI_Output { // -------------------------------------------------------------------- - // Do we need to write a cache file? Only if the controller does not have its + // 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')) @@ -368,7 +368,7 @@ class CI_Output { // 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 = preg_replace("|.*?|is", '', $output); $output .= $CI->profiler->run(); $output .= ''; } @@ -381,14 +381,14 @@ class CI_Output { // -------------------------------------------------------------------- // Does the controller contain a function named _output()? - // If so send the output there. Otherwise, echo it. + // 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! + echo $output; // Send it to the browser! } log_message('debug', "Final output sent to browser"); @@ -458,7 +458,7 @@ class CI_Output { { $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 + // 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; diff --git a/system/core/Router.php b/system/core/Router.php index 5e92a04b1..a76a7bd0a 100644 --- a/system/core/Router.php +++ b/system/core/Router.php @@ -1,4 +1,4 @@ -routes = ( ! isset($route) OR ! is_array($route)) ? array() : $route; unset($route); @@ -103,7 +103,7 @@ class CI_Router { // 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. + // 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); @@ -212,7 +212,7 @@ class CI_Router { // -------------------------------------------------------------------- /** - * Validates the supplied segments. Attempts to determine the path to + * Validates the supplied segments. Attempts to determine the path to * the controller. * * @access private @@ -277,7 +277,7 @@ class CI_Router { // 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 + // controller class. We will now see if there is an override if ( ! empty($this->routes['404_override'])) { $x = explode('/', $this->routes['404_override']); @@ -296,7 +296,7 @@ class CI_Router { // -------------------------------------------------------------------- /** - * Parse Routes + * Parse Routes * * This function matches any routes that may exist in * the config/routes.php file against the URI to @@ -310,7 +310,7 @@ class CI_Router { // Turn the segment array into a URI string $uri = implode('/', $this->uri->segments); - // Is there a literal match? If so we're done + // Is there a literal match? If so we're done if (isset($this->routes[$uri])) { return $this->_set_request(explode('/', $this->routes[$uri])); @@ -370,7 +370,7 @@ class CI_Router { // -------------------------------------------------------------------- /** - * Set the method name + * Set the method name * * @access public * @param string @@ -384,7 +384,7 @@ class CI_Router { // -------------------------------------------------------------------- /** - * Fetch the current method + * Fetch the current method * * @access public * @return string @@ -402,7 +402,7 @@ class CI_Router { // -------------------------------------------------------------------- /** - * Set the directory name + * Set the directory name * * @access public * @param string @@ -416,7 +416,7 @@ class CI_Router { // -------------------------------------------------------------------- /** - * Fetch the sub-directory (if any) that contains the requested controller class + * Fetch the sub-directory (if any) that contains the requested controller class * * @access public * @return string @@ -429,7 +429,7 @@ class CI_Router { // -------------------------------------------------------------------- /** - * Set the controller overrides + * Set the controller overrides * * @access public * @param array diff --git a/system/core/Security.php b/system/core/Security.php index 3617cadcc..f5bfafd9b 100644 --- a/system/core/Security.php +++ b/system/core/Security.php @@ -1,4 +1,4 @@ - '[removed]', // IE, surprise! "Redirect\s+302" => '[removed]' ); - + /** * Constructor */ @@ -95,7 +95,7 @@ class CI_Security { } // Do the tokens exist in both the _POST and _COOKIE arrays? - if ( ! isset($_POST[$this->_csrf_token_name]) OR + if ( ! isset($_POST[$this->_csrf_token_name]) OR ! isset($_COOKIE[$this->_csrf_cookie_name])) { $this->csrf_show_error(); @@ -107,7 +107,7 @@ class CI_Security { $this->csrf_show_error(); } - // We kill this since we're done and we don't want to + // We kill this since we're done and we don't want to // polute the _POST array unset($_POST[$this->_csrf_token_name]); @@ -117,7 +117,7 @@ class CI_Security { $this->csrf_set_cookie(); log_message('debug', "CSRF token verified "); - + return $this; } @@ -146,7 +146,7 @@ class CI_Security { 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; } @@ -165,9 +165,9 @@ class CI_Security { // -------------------------------------------------------------------- /** - * Get CSRF Hash + * Get CSRF Hash * - * Getter Method + * Getter Method * * @return string self::_csrf_hash */ @@ -196,14 +196,14 @@ class CI_Security { * XSS Clean * * Sanitizes data so that Cross Site Scripting Hacks can be - * prevented. This function does a fair amount of work but + * 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, + * 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 + * 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 @@ -263,7 +263,7 @@ class CI_Security { */ $str = preg_replace_callback("/[a-z]+=([\'\"]).*?\\1/si", array($this, '_convert_attribute'), $str); - + $str = preg_replace_callback("/<\w+.*?(?=>|<|$)/si", array($this, '_decode_entity'), $str); /* @@ -276,7 +276,7 @@ class CI_Security { * * 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 + * NOTE: preg_replace was found to be amazingly slow here on * large blocks of data, so we use str_replace. */ @@ -304,27 +304,27 @@ class CI_Security { */ if ($is_image === TRUE) { - // Images have a tendency to have the PHP short opening and - // closing tags every so often so we skip those and only + // Images have a tendency to have the PHP short opening and + // closing tags every so often so we skip those and only // do the long opening tags. $str = preg_replace('/<\?(php)/i', "<?\\1", $str); } else { - $str = str_replace(array(''), array('<?', '?>'), $str); + $str = str_replace(array(''), array('<?', '?>'), $str); } /* * Compact any exploded words * - * This corrects words like: j a v a s c r i p t + * 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', 'script', + 'javascript', 'expression', 'vbscript', 'script', 'applet', 'alert', 'document', 'write', 'cookie', 'window' ); - + foreach ($words as $word) { $temp = ''; @@ -341,8 +341,8 @@ class CI_Security { /* * Remove disallowed Javascript in links or img tags - * We used to do some version comparisons and use of stripos for PHP5, - * but it is dog slow compared to these simplified non-capturing + * We used to do some version comparisons and use of stripos for PHP5, + * but it is dog slow compared to these simplified non-capturing * preg_match(), especially if the pattern exists in the string */ do @@ -388,7 +388,7 @@ class CI_Security { * * Similar to above, only instead of looking for * tags it looks for PHP and JavaScript commands - * that are disallowed. Rather than removing the + * that are disallowed. Rather than removing the * code, it simply converts the parenthesis to entities * rendering the code un-executable. * @@ -405,11 +405,11 @@ class CI_Security { /* * 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. + * - 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 + * 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. */ @@ -457,7 +457,7 @@ class CI_Security { * * In some versions of PHP the native function does not work * when UTF-8 is the specified character set, so this gives us - * a work-around. More info here: + * a work-around. More info here: * http://bugs.php.net/bug.php?id=25670 * * NOTE: html_entity_decode() has a bug in some PHP versions when UTF-8 is the @@ -475,10 +475,10 @@ class CI_Security { // 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 + // correctly. html_entity_decode() does not convert entities without // semicolons, so we are left with our own little solution here. Bummer. - if (function_exists('html_entity_decode') && + if (function_exists('html_entity_decode') && (strtolower($charset) != 'utf-8')) { $str = html_entity_decode($str, ENT_COMPAT, $charset); @@ -542,7 +542,7 @@ class CI_Security { "%3b", // ; "%3d" // = ); - + if ( ! $relative_path) { $bad[] = './'; @@ -570,7 +570,7 @@ class CI_Security { } // -------------------------------------------------------------------- - + /* * Remove Evil HTML Attributes (like evenhandlers and style) * @@ -578,7 +578,7 @@ class CI_Security { * - Everything up until a space * For example, everything between the pipes: * - * - Everything inside the quotes + * - Everything inside the quotes * For example, everything between the pipes: * * @@ -594,12 +594,12 @@ class CI_Security { if ($is_image === TRUE) { /* - * Adobe Photoshop puts XML metadata into JFIF images, + * 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 { $str = preg_replace( "#<(/?[^><]+?)([^A-Za-z\-])(".implode('|', $evil_attributes).")(\s*=\s*)([\"][^>]*?[\"]|[\'][^>]*?[\']|[^>]*?)([\s><])([><]*)#i", @@ -607,10 +607,10 @@ class CI_Security { $str, -1, $count ); } while ($count); - + return $str; } - + // -------------------------------------------------------------------- /** @@ -627,7 +627,7 @@ class CI_Security { $str = '<'.$matches[1].$matches[2].$matches[3]; // encode captured opening or closing brace to prevent recursive vectors - $str .= str_replace(array('>', '<'), array('>', '<'), + $str .= str_replace(array('>', '<'), array('>', '<'), $matches[4]); return $str; @@ -649,7 +649,7 @@ class CI_Security { protected function _js_link_removal($match) { $attributes = $this->_filter_attributes(str_replace(array('<', '>'), '', $match[1])); - + return str_replace($match[1], preg_replace("#href=.*?(alert\(|alert&\#40;|javascript\:|livescript\:|mocha\:|charset\=|window\.|document\.|\.cookie|_filter_attributes(str_replace(array('<', '>'), '', $match[1])); - + return str_replace($match[1], preg_replace("#src=.*?(alert\(|alert&\#40;|javascript\:|livescript\:|mocha\:|charset\=|window\.|document\.|\.cookie|xss_hash()."\\1=\\2", $str); /* * Validate standard character entities * - * Add a semicolon if missing. We do this to enable + * Add a semicolon if missing. We do this to enable * the conversion of entities to ASCII later. * */ @@ -769,7 +769,7 @@ class CI_Security { * Un-Protect GET variables in URLs */ $str = str_replace($this->xss_hash(), '&', $str); - + return $str; } @@ -794,7 +794,7 @@ class CI_Security { { $str = preg_replace("#".$key."#i", $val, $str); } - + return $str; } @@ -809,16 +809,16 @@ class CI_Security { { if ($this->_csrf_hash == '') { - // If the cookie exists we will use it's value. + // 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 + // each page load since a page could contain embedded // sub-pages causing this feature to fail - if (isset($_COOKIE[$this->_csrf_cookie_name]) && + if (isset($_COOKIE[$this->_csrf_cookie_name]) && $_COOKIE[$this->_csrf_cookie_name] != '') { return $this->_csrf_hash = $_COOKIE[$this->_csrf_cookie_name]; } - + return $this->_csrf_hash = md5(uniqid(rand(), TRUE)); } diff --git a/system/core/URI.php b/system/core/URI.php index d56548654..94fac59ac 100644 --- a/system/core/URI.php +++ b/system/core/URI.php @@ -1,4 +1,4 @@ -_set_uri_string($path); @@ -251,7 +251,7 @@ class CI_URI { */ function _remove_url_suffix() { - if ($this->config->item('url_suffix') != "") + if ($this->config->item('url_suffix') != "") { $this->uri_string = preg_replace("|".preg_quote($this->config->item('url_suffix'))."$|", "", $this->uri_string); } @@ -285,7 +285,7 @@ class CI_URI { * 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 + * 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. * @@ -323,7 +323,7 @@ class CI_URI { * Fetch a URI "routed" Segment * * This function returns the re-routed URI segment (assuming routing rules are used) - * based on the number provided. If there is no routing this function returns the + * based on the number provided. If there is no routing this function returns the * same result as $this->segment() * * @access public @@ -425,7 +425,7 @@ class CI_URI { $i = 0; $lastval = ''; - $retval = array(); + $retval = array(); foreach ($segments as $seg) { if ($i % 2) diff --git a/system/core/Utf8.php b/system/core/Utf8.php index 2a27d1f35..738d7e9d8 100644 --- a/system/core/Utf8.php +++ b/system/core/Utf8.php @@ -1,4 +1,4 @@ -_track_aliases($val); @@ -332,7 +332,7 @@ class CI_DB_active_record extends CI_DB_driver { } } - // Extract any aliases that might exist. We use this information + // 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); @@ -438,7 +438,7 @@ class CI_DB_active_record extends CI_DB_driver { $v = ' '.$this->escape($v); } - + if ( ! $this->_has_operator($k)) { $k .= ' = '; @@ -926,7 +926,7 @@ class CI_DB_active_record extends CI_DB_driver { // -------------------------------------------------------------------- /** - * The "set" function. Allows key/value pairs to be set for inserting or updating + * The "set" function. Allows key/value pairs to be set for inserting or updating * * @access public * @param mixed @@ -1084,7 +1084,7 @@ class CI_DB_active_record extends CI_DB_driver { { if ($this->db_debug) { - //No valid data array. Folds in cases where keys and values did not match up + //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; @@ -1124,7 +1124,7 @@ class CI_DB_active_record extends CI_DB_driver { // -------------------------------------------------------------------- /** - * The "set_insert_batch" function. Allows key/value pairs to be set for batch inserts + * The "set_insert_batch" function. Allows key/value pairs to be set for batch inserts * * @access public * @param mixed @@ -1158,7 +1158,7 @@ class CI_DB_active_record extends CI_DB_driver { if ($escape === FALSE) { - $this->ar_set[] = '('.implode(',', $row).')'; + $this->ar_set[] = '('.implode(',', $row).')'; } else { @@ -1169,7 +1169,7 @@ class CI_DB_active_record extends CI_DB_driver { $clean[] = $this->escape($value); } - $this->ar_set[] = '('.implode(',', $clean).')'; + $this->ar_set[] = '('.implode(',', $clean).')'; } } @@ -1399,7 +1399,7 @@ class CI_DB_active_record extends CI_DB_driver { // -------------------------------------------------------------------- /** - * The "set_update_batch" function. Allows key/value pairs to be set for batch updating + * The "set_update_batch" function. Allows key/value pairs to be set for batch updating * * @access public * @param array @@ -1652,7 +1652,7 @@ class CI_DB_active_record extends CI_DB_driver { return; } - // Does the string contain a comma? If so, we need to separate + // Does the string contain a comma? If so, we need to separate // the string into discreet statements if (strpos($table, ',') !== FALSE) { @@ -1682,7 +1682,7 @@ class CI_DB_active_record extends CI_DB_driver { * Compile the SELECT statement * * Generates a query string based on which functions were used. - * Should not be called directly. The get() function calls it. + * Should not be called directly. The get() function calls it. * * @access private * @return string @@ -1989,7 +1989,7 @@ class CI_DB_active_record extends CI_DB_driver { // -------------------------------------------------------------------- /** - * Resets the active record values. Called by the get() function + * Resets the active record values. Called by the get() function * * @access private * @param array An array of fields to reset @@ -2009,7 +2009,7 @@ class CI_DB_active_record extends CI_DB_driver { // -------------------------------------------------------------------- /** - * Resets the active record values. Called by the get() function + * Resets the active record values. Called by the get() function * * @access private * @return void diff --git a/system/database/DB_cache.php b/system/database/DB_cache.php index 3bf065ca5..3249e9d8e 100644 --- a/system/database/DB_cache.php +++ b/system/database/DB_cache.php @@ -1,4 +1,4 @@ -CI->uri->segment(1) == FALSE) ? 'default' : $this->CI->uri->segment(1); + $segment_one = ($this->CI->uri->segment(1) == FALSE) ? 'default' : $this->CI->uri->segment(1); } if ($segment_two == '') diff --git a/system/database/DB_driver.php b/system/database/DB_driver.php index 10e8ed0c0..40be2f903 100644 --- a/system/database/DB_driver.php +++ b/system/database/DB_driver.php @@ -1,4 +1,4 @@ -conn_id = ($this->pconnect == FALSE) ? $this->db_connect() : $this->db_pconnect(); - // No connection resource? Throw an error + // No connection resource? Throw an error if ( ! $this->conn_id) { log_message('error', 'Unable to connect to the database'); @@ -199,7 +199,7 @@ class CI_DB_driver { // -------------------------------------------------------------------- /** - * Database Version Number. Returns a string containing the + * Database Version Number. Returns a string containing the * version of the database being used * * @access public @@ -237,7 +237,7 @@ class CI_DB_driver { * Execute the query * * Accepts an SQL string as input and returns a result object upon - * successful execution of a "read" type query. Returns boolean TRUE + * successful execution of a "read" type query. Returns boolean TRUE * upon successful execution of a "write" type query. Returns boolean * FALSE upon failure, and if the $db_debug variable is set to TRUE * will raise an error. @@ -265,7 +265,7 @@ class CI_DB_driver { $sql = preg_replace("/(\W)".$this->swap_pre."(\S+?)/", "\\1".$this->dbprefix."\\2", $sql); } - // Is query caching enabled? If the query is a "read type" + // 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')) @@ -286,7 +286,7 @@ class CI_DB_driver { $sql = $this->compile_binds($sql, $binds); } - // Save the query for debugging + // Save the query for debugging if ($this->save_queries == TRUE) { $this->queries[] = $sql; @@ -314,7 +314,7 @@ class CI_DB_driver { $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 + // 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(); @@ -385,7 +385,7 @@ class CI_DB_driver { // oci8 vars must be set before calling this $RES->num_rows = $RES->num_rows(); - // Is query caching enabled? If so, we'll serialize the + // 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()) { @@ -435,7 +435,7 @@ class CI_DB_driver { /** * Simple Query - * This is a simplified version of the query() function. Internally + * This is a simplified version of the query() function. Internally * we only use it when running transaction commands since they do * not require all the features of the main query() function. * @@ -718,7 +718,7 @@ class CI_DB_driver { /** * Primary * - * Retrieves the primary key. It assumes that the row in the first + * Retrieves the primary key. It assumes that the row in the first * position is the primary key * * @access public @@ -1216,8 +1216,8 @@ class CI_DB_driver { * 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: + * 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 * @@ -1270,7 +1270,7 @@ class CI_DB_driver { // This is basically a bug fix for queries that use MAX, MIN, etc. // If a parenthesis is found we know that we do not need to - // escape the data or add a prefix. There's probably a more graceful + // escape the data or add a prefix. There's probably a more graceful // way to deal with this, but I'm not thinking of it -- Rick if (strpos($item, '(') !== FALSE) { @@ -1285,7 +1285,7 @@ class CI_DB_driver { $parts = explode('.', $item); // Does the first segment of the exploded item match - // one of the aliases previously identified? If so, + // one of the aliases previously identified? If so, // we have nothing more to do other than escape the item if (in_array($parts[0], $this->ar_aliased_tables)) { @@ -1304,7 +1304,7 @@ class CI_DB_driver { return $item.$alias; } - // Is there a table prefix defined in the config file? If not, no need to do anything + // Is there a table prefix defined in the config file? If not, no need to do anything if ($this->dbprefix != '') { // We now add the table prefix based on some logic. @@ -1358,7 +1358,7 @@ class CI_DB_driver { return $item.$alias; } - // Is there a table prefix? If not, no need to insert it + // Is there a table prefix? If not, no need to insert it if ($this->dbprefix != '') { // Verify table prefix and replace if necessary diff --git a/system/database/DB_forge.php b/system/database/DB_forge.php index a71fca78f..9730c7761 100644 --- a/system/database/DB_forge.php +++ b/system/database/DB_forge.php @@ -1,4 +1,4 @@ -result_array(); - else if ($type == 'object') return $this->result_object(); - else return $this->custom_result_object($type); + if ($type == 'array') return $this->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 - */ - 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(); + /** + * Custom query result. + * + * @param class_name A string that represents the type of object you want back + * @return array of objects + */ + 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; - } + { + $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; - } + // return the array + return $this->custom_result_object[$class_name] = $result_object; + } /** - * Query result. "object" version. + * Query result. "object" version. * * @access public * @return object @@ -122,7 +122,7 @@ class CI_DB_result { // -------------------------------------------------------------------- /** - * Query result. "array" version. + * Query result. "array" version. * * @access public * @return array @@ -154,7 +154,7 @@ class CI_DB_result { // -------------------------------------------------------------------- /** - * Query result. Acts as a wrapper function for the following functions. + * Query result. Acts as a wrapper function for the following functions. * * @access public * @param string @@ -180,9 +180,9 @@ class CI_DB_result { $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); + 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); } // -------------------------------------------------------------------- @@ -219,7 +219,7 @@ class CI_DB_result { // -------------------------------------------------------------------- - /** + /** * Returns a single result row - custom object version * * @access public @@ -242,7 +242,7 @@ class CI_DB_result { return $result[$this->current_row]; } - /** + /** * Returns a single result row - object version * * @access public @@ -383,9 +383,9 @@ class CI_DB_result { /** * 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. + * 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 + * 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. */ diff --git a/system/database/DB_utility.php b/system/database/DB_utility.php index a5f174f0a..a3c00a5a6 100644 --- a/system/database/DB_utility.php +++ b/system/database/DB_utility.php @@ -1,4 +1,4 @@ -db->db_debug) { diff --git a/system/database/drivers/mssql/mssql_driver.php b/system/database/drivers/mssql/mssql_driver.php index 65397ed8f..56ecf32d1 100644 --- a/system/database/drivers/mssql/mssql_driver.php +++ b/system/database/drivers/mssql/mssql_driver.php @@ -1,4 +1,4 @@ -db->_protect_identifiers($field); - $sql .= ' '.$attributes['TYPE']; + $sql .= ' '.$attributes['TYPE']; if (array_key_exists('CONSTRAINT', $attributes)) { diff --git a/system/database/drivers/mssql/mssql_result.php b/system/database/drivers/mssql/mssql_result.php index 2897ca5a5..f1f6dbb84 100644 --- a/system/database/drivers/mssql/mssql_result.php +++ b/system/database/drivers/mssql/mssql_result.php @@ -1,4 +1,4 @@ -= 5.2.3 and MySQL >= 5.0.7, use SET NAMES as fallback @@ -302,12 +302,12 @@ class CI_DB_mysql_driver extends CI_DB { if (is_array($str)) { foreach ($str as $key => $val) - { + { $str[$key] = $this->escape_str($val, $like); - } + } - return $str; - } + return $str; + } if (function_exists('mysql_real_escape_string') AND is_resource($this->conn_id)) { @@ -650,7 +650,7 @@ class CI_DB_mysql_driver extends CI_DB { { if ($field != $index) { - $final[$field][] = 'WHEN '.$index.' = '.$val[$index].' THEN '.$val[$field]; + $final[$field][] = 'WHEN '.$index.' = '.$val[$index].' THEN '.$val[$field]; } } } diff --git a/system/database/drivers/mysql/mysql_forge.php b/system/database/drivers/mysql/mysql_forge.php index 529ec980d..5328a7b4e 100644 --- a/system/database/drivers/mysql/mysql_forge.php +++ b/system/database/drivers/mysql/mysql_forge.php @@ -1,4 +1,4 @@ -= 5.0.7, use SET NAMES as fallback @@ -568,7 +568,7 @@ class CI_DB_mysqli_driver extends CI_DB { { return "INSERT INTO ".$table." (".implode(', ', $keys).") VALUES ".implode(', ', $values); } - + // -------------------------------------------------------------------- /** @@ -630,7 +630,7 @@ class CI_DB_mysqli_driver extends CI_DB { { if ($field != $index) { - $final[$field][] = 'WHEN '.$index.' = '.$val[$index].' THEN '.$val[$field]; + $final[$field][] = 'WHEN '.$index.' = '.$val[$index].' THEN '.$val[$field]; } } } diff --git a/system/database/drivers/mysqli/mysqli_forge.php b/system/database/drivers/mysqli/mysqli_forge.php index d5097335e..6450968dd 100644 --- a/system/database/drivers/mysqli/mysqli_forge.php +++ b/system/database/drivers/mysqli/mysqli_forge.php @@ -1,4 +1,4 @@ - format - * value no the value of the parameter. If this is an OUT or IN OUT parameter, + * 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 @@ -275,8 +275,8 @@ class CI_DB_oci8_driver extends CI_DB { /** * Bind parameters * - * @access private - * @return none + * @access private + * @return none */ function _bind_params($params) { @@ -386,10 +386,10 @@ class CI_DB_oci8_driver extends CI_DB { /** * Escape String * - * @access public - * @param string + * @access public + * @param string * @param bool whether or not the string will be used in a LIKE condition - * @return string + * @return string */ function escape_str($str, $like = FALSE) { @@ -421,8 +421,8 @@ class CI_DB_oci8_driver extends CI_DB { /** * Affected Rows * - * @access public - * @return integer + * @access public + * @return integer */ function affected_rows() { @@ -434,8 +434,8 @@ class CI_DB_oci8_driver extends CI_DB { /** * Insert ID * - * @access public - * @return integer + * @access public + * @return integer */ function insert_id() { @@ -451,9 +451,9 @@ class CI_DB_oci8_driver extends CI_DB { * Generates a platform-specific query string that counts all records in * the specified database * - * @access public - * @param string - * @return string + * @access public + * @param string + * @return string */ function count_all($table = '') { @@ -480,9 +480,9 @@ class CI_DB_oci8_driver extends CI_DB { * * Generates a platform-specific query string so that the table names can be fetched * - * @access private + * @access private * @param boolean - * @return string + * @return string */ function _list_tables($prefix_limit = FALSE) { @@ -503,9 +503,9 @@ class CI_DB_oci8_driver extends CI_DB { * * Generates a platform-specific query string so that the column names can be fetched * - * @access public - * @param string the table name - * @return string + * @access public + * @param string the table name + * @return string */ function _list_columns($table = '') { @@ -519,9 +519,9 @@ class CI_DB_oci8_driver extends CI_DB { * * Generates a platform-specific query so that the column data can be retrieved * - * @access public - * @param string the table name - * @return object + * @access public + * @param string the table name + * @return object */ function _field_data($table) { @@ -533,8 +533,8 @@ class CI_DB_oci8_driver extends CI_DB { /** * The error message string * - * @access private - * @return string + * @access private + * @return string */ function _error_message() { @@ -547,8 +547,8 @@ class CI_DB_oci8_driver extends CI_DB { /** * The error message number * - * @access private - * @return integer + * @access private + * @return integer */ function _error_number() { @@ -627,11 +627,11 @@ class CI_DB_oci8_driver extends CI_DB { * * Generates a platform-specific insert string from the supplied data * - * @access public - * @param string the table name - * @param array the insert keys - * @param array the insert values - * @return string + * @access public + * @param string the table name + * @param array the insert keys + * @param array the insert values + * @return string */ function _insert($table, $keys, $values) { @@ -732,11 +732,11 @@ class CI_DB_oci8_driver extends CI_DB { * * Generates a platform-specific LIMIT clause * - * @access public - * @param string the sql query string - * @param integer the number of rows to limit the query to - * @param integer the offset value - * @return string + * @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) { @@ -759,9 +759,9 @@ class CI_DB_oci8_driver extends CI_DB { /** * Close DB Connection * - * @access public - * @param resource - * @return void + * @access public + * @param resource + * @return void */ function _close($conn_id) { diff --git a/system/database/drivers/oci8/oci8_forge.php b/system/database/drivers/oci8/oci8_forge.php index 3cd17585a..589e3c29d 100644 --- a/system/database/drivers/oci8/oci8_forge.php +++ b/system/database/drivers/oci8/oci8_forge.php @@ -1,4 +1,4 @@ -db->_protect_identifiers($field); - $sql .= ' '.$attributes['TYPE']; + $sql .= ' '.$attributes['TYPE']; if (array_key_exists('CONSTRAINT', $attributes)) { diff --git a/system/database/drivers/oci8/oci8_result.php b/system/database/drivers/oci8/oci8_result.php index 88531b436..60d8396ef 100644 --- a/system/database/drivers/oci8/oci8_result.php +++ b/system/database/drivers/oci8/oci8_result.php @@ -1,4 +1,4 @@ -name = ocicolumnname($this->stmt_id, $c); $F->type = ocicolumntype($this->stmt_id, $c); - $F->max_length = ocicolumnsize($this->stmt_id, $c); + $F->max_length = ocicolumnsize($this->stmt_id, $c); $retval[] = $F; } @@ -145,8 +145,8 @@ class CI_DB_oci8_result extends CI_DB_result { * * Returns the result set as an array * - * @access private - * @return array + * @access private + * @return array */ function _fetch_assoc(&$row) { @@ -162,8 +162,8 @@ class CI_DB_oci8_result extends CI_DB_result { * * Returns the result set as an object * - * @access private - * @return object + * @access private + * @return object */ function _fetch_object() { @@ -202,10 +202,10 @@ class CI_DB_oci8_result extends CI_DB_result { // -------------------------------------------------------------------- /** - * Query result. "array" version. + * Query result. "array" version. * - * @access public - * @return array + * @access public + * @return array */ function result_array() { @@ -230,7 +230,7 @@ class CI_DB_oci8_result extends CI_DB_result { /** * Data Seek * - * Moves the internal pointer to the desired offset. We call + * Moves the internal pointer to the desired offset. We call * this internally before fetching results to make sure the * result set starts at zero * diff --git a/system/database/drivers/oci8/oci8_utility.php b/system/database/drivers/oci8/oci8_utility.php index 854b467e1..f1fe5dc00 100644 --- a/system/database/drivers/oci8/oci8_utility.php +++ b/system/database/drivers/oci8/oci8_utility.php @@ -1,4 +1,4 @@ -db->_protect_identifiers($field); - $sql .= ' '.$attributes['TYPE']; + $sql .= ' '.$attributes['TYPE']; if (array_key_exists('CONSTRAINT', $attributes)) { diff --git a/system/database/drivers/odbc/odbc_result.php b/system/database/drivers/odbc/odbc_result.php index 5d64a464f..d83b2e5f0 100644 --- a/system/database/drivers/odbc/odbc_result.php +++ b/system/database/drivers/odbc/odbc_result.php @@ -1,4 +1,4 @@ -db->_protect_identifiers($field); - $sql .= ' '.$attributes['TYPE']; + $sql .= ' '.$attributes['TYPE']; if (array_key_exists('CONSTRAINT', $attributes)) { @@ -172,7 +172,7 @@ class CI_DB_sqlite_forge extends CI_DB_forge { /** * Drop Table * - * Unsupported feature in SQLite + * Unsupported feature in SQLite * * @access private * @return bool diff --git a/system/database/drivers/sqlite/sqlite_result.php b/system/database/drivers/sqlite/sqlite_result.php index 7bd30db7c..62204946c 100644 --- a/system/database/drivers/sqlite/sqlite_result.php +++ b/system/database/drivers/sqlite/sqlite_result.php @@ -1,4 +1,4 @@ -text. To close fieldset + * Used to produce
    text. To close fieldset * use form_fieldset_close() * * @access public @@ -663,7 +663,7 @@ if ( ! function_exists('form_prep')) * 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 + * re-populate an input field or textarea. If Form Validation * is active it retrieves the info from the validation class * * @access public @@ -858,7 +858,7 @@ if ( ! function_exists('set_radio')) /** * Form Error * - * Returns the error for a specific form field. This is a helper for the + * Returns the error for a specific form field. This is a helper for the * form validation class. * * @access public @@ -885,7 +885,7 @@ if ( ! function_exists('form_error')) /** * Validation Error String * - * Returns all the errors associated with a form submission. This is a helper + * Returns all the errors associated with a form submission. This is a helper * function for the form validation class. * * @access public @@ -1034,17 +1034,17 @@ if ( ! function_exists('_get_validation_object')) // 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; } } diff --git a/system/helpers/html_helper.php b/system/helpers/html_helper.php index 080f622dd..bd66bc2d0 100644 --- a/system/helpers/html_helper.php +++ b/system/helpers/html_helper.php @@ -1,4 +1,4 @@ -\n"; - // Cycle through the list elements. If an array is + // Cycle through the list elements. If an array is // encountered we will recursively call _list() static $_last_list_item = ''; @@ -244,7 +244,7 @@ if ( ! function_exists('img')) * 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 + * html4-strict, html4-trans, and html4-frame. Values are saved in the * doctypes config file. * * @access public diff --git a/system/helpers/inflector_helper.php b/system/helpers/inflector_helper.php index c7c113b8a..2352b642e 100644 --- a/system/helpers/inflector_helper.php +++ b/system/helpers/inflector_helper.php @@ -1,4 +1,4 @@ -'), array('<?php', '<?PHP', '<?', '?>'), $str); + return str_replace(array(''), array('<?php', '<?PHP', '<?', '?>'), $str); } } diff --git a/system/helpers/smiley_helper.php b/system/helpers/smiley_helper.php index 6d8889354..22ca4df77 100644 --- a/system/helpers/smiley_helper.php +++ b/system/helpers/smiley_helper.php @@ -1,4 +1,4 @@ - $val) { // Keep duplicates from being used, which can happen if the - // mapping array contains multiple identical replacements. For example: + // 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]])) @@ -204,7 +204,7 @@ if ( ! function_exists('parse_smileys')) } // Add a trailing slash to the file path if needed - $image_url = preg_replace("/(.+?)\/*$/", "\\1/", $image_url); + $image_url = preg_replace("/(.+?)\/*$/", "\\1/", $image_url); foreach ($smileys as $key => $val) { @@ -231,13 +231,13 @@ if ( ! function_exists('_get_smiley_array')) { if (defined('ENVIRONMENT') AND file_exists(APPPATH.'config/'.ENVIRONMENT.'/smileys.php')) { - include(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; diff --git a/system/helpers/string_helper.php b/system/helpers/string_helper.php index 7765bba31..9f730bd10 100644 --- a/system/helpers/string_helper.php +++ b/system/helpers/string_helper.php @@ -1,4 +1,4 @@ - $val) { - $x[] = ' '.$key.'="'; + $x[] = ' '.$key.'="'; for ($i = 0; $i < strlen($val); $i++) { $x[] = "|".ord(substr($val, $i, 1)); @@ -363,7 +363,7 @@ if ( ! function_exists('safe_mailto')) * * 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 + * URLs or emails that end in a period. We'll strip these * off and add them after the link. * * @access public diff --git a/system/helpers/xml_helper.php b/system/helpers/xml_helper.php index cdd81ad70..2219d662a 100644 --- a/system/helpers/xml_helper.php +++ b/system/helpers/xml_helper.php @@ -1,4 +1,4 @@ -","\"", "'", "-"), diff --git a/system/language/english/email_lang.php b/system/language/english/email_lang.php index e3bd113cb..fe4276822 100644 --- a/system/language/english/email_lang.php +++ b/system/language/english/email_lang.php @@ -5,9 +5,9 @@ $lang['email_invalid_address'] = "Invalid email address: %s"; $lang['email_attachment_missing'] = "Unable to locate the following email attachment: %s"; $lang['email_attachment_unreadable'] = "Unable to open this attachment: %s"; $lang['email_no_recipients'] = "You must include recipients: To, Cc, or Bcc"; -$lang['email_send_failure_phpmail'] = "Unable to send email using PHP mail(). Your server might not be configured to send mail using this method."; -$lang['email_send_failure_sendmail'] = "Unable to send email using PHP Sendmail. Your server might not be configured to send mail using this method."; -$lang['email_send_failure_smtp'] = "Unable to send email using PHP SMTP. Your server might not be configured to send mail using this method."; +$lang['email_send_failure_phpmail'] = "Unable to send email using PHP mail(). Your server might not be configured to send mail using this method."; +$lang['email_send_failure_sendmail'] = "Unable to send email using PHP Sendmail. Your server might not be configured to send mail using this method."; +$lang['email_send_failure_smtp'] = "Unable to send email using PHP SMTP. Your server might not be configured to send mail using this method."; $lang['email_sent'] = "Your message has been successfully sent using the following protocol: %s"; $lang['email_no_socket'] = "Unable to open a socket to Sendmail. Please check settings."; $lang['email_no_hostname'] = "You did not specify a SMTP hostname."; diff --git a/system/language/english/imglib_lang.php b/system/language/english/imglib_lang.php index 66505da07..0a56fe0a5 100644 --- a/system/language/english/imglib_lang.php +++ b/system/language/english/imglib_lang.php @@ -4,20 +4,20 @@ $lang['imglib_source_image_required'] = "You must specify a source image in your $lang['imglib_gd_required'] = "The GD image library is required for this feature."; $lang['imglib_gd_required_for_props'] = "Your server must support the GD image library in order to determine the image properties."; $lang['imglib_unsupported_imagecreate'] = "Your server does not support the GD function required to process this type of image."; -$lang['imglib_gif_not_supported'] = "GIF images are often not supported due to licensing restrictions. You may have to use JPG or PNG images instead."; +$lang['imglib_gif_not_supported'] = "GIF images are often not supported due to licensing restrictions. You may have to use JPG or PNG images instead."; $lang['imglib_jpg_not_supported'] = "JPG images are not supported."; $lang['imglib_png_not_supported'] = "PNG images are not supported."; $lang['imglib_jpg_or_png_required'] = "The image resize protocol specified in your preferences only works with JPEG or PNG image types."; -$lang['imglib_copy_error'] = "An error was encountered while attempting to replace the file. Please make sure your file directory is writable."; +$lang['imglib_copy_error'] = "An error was encountered while attempting to replace the file. Please make sure your file directory is writable."; $lang['imglib_rotate_unsupported'] = "Image rotation does not appear to be supported by your server."; -$lang['imglib_libpath_invalid'] = "The path to your image library is not correct. Please set the correct path in your image preferences."; -$lang['imglib_image_process_failed'] = "Image processing failed. Please verify that your server supports the chosen protocol and that the path to your image library is correct."; +$lang['imglib_libpath_invalid'] = "The path to your image library is not correct. Please set the correct path in your image preferences."; +$lang['imglib_image_process_failed'] = "Image processing failed. Please verify that your server supports the chosen protocol and that the path to your image library is correct."; $lang['imglib_rotation_angle_required'] = "An angle of rotation is required to rotate the image."; $lang['imglib_writing_failed_gif'] = "GIF image."; $lang['imglib_invalid_path'] = "The path to the image is not correct."; $lang['imglib_copy_failed'] = "The image copy routine failed."; $lang['imglib_missing_font'] = "Unable to find a font to use."; -$lang['imglib_save_failed'] = "Unable to save the image. Please make sure the image and file directory are writable."; +$lang['imglib_save_failed'] = "Unable to save the image. Please make sure the image and file directory are writable."; /* End of file imglib_lang.php */ diff --git a/system/libraries/Cache/Cache.php b/system/libraries/Cache/Cache.php index 61e7aa761..938c80857 100644 --- a/system/libraries/Cache/Cache.php +++ b/system/libraries/Cache/Cache.php @@ -10,22 +10,22 @@ * @license http://codeigniter.com/user_guide/license.html * @link http://codeigniter.com * @since Version 2.0 - * @filesource + * @filesource */ // ------------------------------------------------------------------------ /** - * CodeIgniter Caching Class + * CodeIgniter Caching Class * * @package CodeIgniter * @subpackage Libraries * @category Core * @author ExpressionEngine Dev Team - * @link + * @link */ class CI_Cache extends CI_Driver_Library { - + protected $valid_drivers = array( 'cache_apc', 'cache_file', 'cache_memcached', 'cache_dummy' ); @@ -33,7 +33,7 @@ class CI_Cache extends CI_Driver_Library { protected $_cache_path = NULL; // Path of cache files (if file-based cache) protected $_adapter = 'dummy'; protected $_backup_driver; - + // ------------------------------------------------------------------------ /** @@ -52,16 +52,16 @@ class CI_Cache extends CI_Driver_Library { // ------------------------------------------------------------------------ /** - * Get + * Get * - * Look for a value in the cache. If it exists, return the data + * Look for a value in the cache. If it exists, return the data * if not, return FALSE * - * @param string + * @param string * @return mixed value that is stored/FALSE on failure */ public function get($id) - { + { return $this->{$this->_adapter}->get($id); } @@ -112,7 +112,7 @@ class CI_Cache extends CI_Driver_Library { * Cache Info * * @param string user/filehits - * @return mixed array on success, false on failure + * @return mixed array on success, false on failure */ public function cache_info($type = 'user') { @@ -120,7 +120,7 @@ class CI_Cache extends CI_Driver_Library { } // ------------------------------------------------------------------------ - + /** * Get Cache Metadata * @@ -131,7 +131,7 @@ class CI_Cache extends CI_Driver_Library { { return $this->{$this->_adapter}->get_metadata($id); } - + // ------------------------------------------------------------------------ /** @@ -139,11 +139,11 @@ class CI_Cache extends CI_Driver_Library { * * Initialize class properties based on the configuration array. * - * @param array + * @param array * @return void */ private function _initialize($config) - { + { $default_config = array( 'adapter', 'memcached' @@ -207,7 +207,7 @@ class CI_Cache extends CI_Driver_Library { return $obj; } - + // ------------------------------------------------------------------------ } // End Class diff --git a/system/libraries/Cache/drivers/Cache_apc.php b/system/libraries/Cache/drivers/Cache_apc.php index de75719c4..ea129eded 100644 --- a/system/libraries/Cache/drivers/Cache_apc.php +++ b/system/libraries/Cache/drivers/Cache_apc.php @@ -10,30 +10,30 @@ * @license http://codeigniter.com/user_guide/license.html * @link http://codeigniter.com * @since Version 2.0 - * @filesource + * @filesource */ // ------------------------------------------------------------------------ /** - * CodeIgniter APC Caching Class + * CodeIgniter APC Caching Class * * @package CodeIgniter * @subpackage Libraries * @category Core * @author ExpressionEngine Dev Team - * @link + * @link */ class CI_Cache_apc extends CI_Driver { /** - * Get + * Get * - * Look for a value in the cache. If it exists, return the data + * Look for a value in the cache. If it exists, return the data * if not, return FALSE * - * @param string + * @param string * @return mixed value that is stored/FALSE on failure */ public function get($id) @@ -43,8 +43,8 @@ class CI_Cache_apc extends CI_Driver { return (is_array($data)) ? $data[0] : FALSE; } - // ------------------------------------------------------------------------ - + // ------------------------------------------------------------------------ + /** * Cache Save * @@ -58,7 +58,7 @@ class CI_Cache_apc extends CI_Driver { { return apc_store($id, array($data, time(), $ttl), $ttl); } - + // ------------------------------------------------------------------------ /** @@ -90,7 +90,7 @@ class CI_Cache_apc extends CI_Driver { * Cache Info * * @param string user/filehits - * @return mixed array on success, false on failure + * @return mixed array on success, false on failure */ public function cache_info($type = NULL) { @@ -137,13 +137,13 @@ class CI_Cache_apc extends CI_Driver { log_message('error', 'The APC PHP extension must be loaded to use APC Cache.'); return FALSE; } - + return TRUE; } // ------------------------------------------------------------------------ - + } // End Class diff --git a/system/libraries/Cache/drivers/Cache_file.php b/system/libraries/Cache/drivers/Cache_file.php index 13e2d1af6..39dcd15c2 100644 --- a/system/libraries/Cache/drivers/Cache_file.php +++ b/system/libraries/Cache/drivers/Cache_file.php @@ -10,19 +10,19 @@ * @license http://codeigniter.com/user_guide/license.html * @link http://codeigniter.com * @since Version 2.0 - * @filesource + * @filesource */ // ------------------------------------------------------------------------ /** - * CodeIgniter Memcached Caching Class + * CodeIgniter Memcached Caching Class * * @package CodeIgniter * @subpackage Libraries * @category Core * @author ExpressionEngine Dev Team - * @link + * @link */ class CI_Cache_file extends CI_Driver { @@ -36,9 +36,9 @@ class CI_Cache_file extends CI_Driver { { $CI =& get_instance(); $CI->load->helper('file'); - + $path = $CI->config->item('cache_path'); - + $this->_cache_path = ($path == '') ? APPPATH.'cache/' : $path; } @@ -56,16 +56,16 @@ class CI_Cache_file extends CI_Driver { { return FALSE; } - + $data = read_file($this->_cache_path.$id); $data = unserialize($data); - - if (time() > $data['time'] + $data['ttl']) + + if (time() > $data['time'] + $data['ttl']) { unlink($this->_cache_path.$id); return FALSE; } - + return $data['data']; } @@ -76,22 +76,22 @@ class CI_Cache_file extends CI_Driver { * * @param string unique key * @param mixed data to store - * @param int length of time (in seconds) the cache is valid + * @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, + 'ttl' => $ttl, 'data' => $data ); - + if (write_file($this->_cache_path.$id, serialize($contents))) { @chmod($this->_cache_path.$id, 0777); - return TRUE; + return TRUE; } return FALSE; @@ -116,7 +116,7 @@ class CI_Cache_file extends CI_Driver { * Clean the Cache * * @return boolean false on failure/true on success - */ + */ public function clean() { return delete_files($this->_cache_path); @@ -151,10 +151,10 @@ class CI_Cache_file extends CI_Driver { { return FALSE; } - - $data = read_file($this->_cache_path.$id); + + $data = read_file($this->_cache_path.$id); $data = unserialize($data); - + if (is_array($data)) { $data = $data['data']; @@ -170,7 +170,7 @@ class CI_Cache_file extends CI_Driver { 'mtime' => $mtime ); } - + return FALSE; } @@ -180,7 +180,7 @@ class CI_Cache_file extends CI_Driver { * Is supported * * In the file driver, check to see that the cache directory is indeed writable - * + * * @return boolean */ public function is_supported() diff --git a/system/libraries/Calendar.php b/system/libraries/Calendar.php index df0fd6eeb..7dcbaab47 100644 --- a/system/libraries/Calendar.php +++ b/system/libraries/Calendar.php @@ -1,4 +1,4 @@ -local_time); + $year = date("Y", $this->local_time); if ($month == '') $month = date("m", $this->local_time); @@ -128,7 +128,7 @@ class CI_Calendar { // Set the starting day number $local_date = mktime(12, 0, 0, $month, 1, $year); $date = getdate($local_date); - $day = $start_day + 1 - $date["wday"]; + $day = $start_day + 1 - $date["wday"]; while ($day > 1) { @@ -157,8 +157,8 @@ class CI_Calendar { // "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); + // 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']); @@ -233,7 +233,7 @@ class CI_Calendar { $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']; + $out .= ($is_current_month == TRUE AND $day == $cur_day) ? $this->temp['cal_cell_end_today'] : $this->temp['cal_cell_end']; $day++; } @@ -287,7 +287,7 @@ class CI_Calendar { * Get Day Names * * Returns an array of day names (Sunday, Monday, etc.) based - * on the type. Options: long, short, abrev + * on the type. Options: long, short, abrev * * @access public * @param string @@ -404,7 +404,7 @@ class CI_Calendar { */ function default_template() { - return array ( + return array ( 'table_open' => '
    ', 'heading_row_start' => '', 'heading_previous_cell' => '', @@ -451,7 +451,7 @@ class CI_Calendar { $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) + 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)) { diff --git a/system/libraries/Cart.php b/system/libraries/Cart.php index 7f65b48b9..fbccfb3d9 100644 --- a/system/libraries/Cart.php +++ b/system/libraries/Cart.php @@ -1,4 +1,4 @@ -CI =& get_instance(); - // Are any config settings being passed manually? If so, set them + // Are any config settings being passed manually? If so, set them $config = array(); if (count($params) > 0) { @@ -148,7 +148,7 @@ class CI_Cart { // -------------------------------------------------------------------- - // Does the $items array contain an id, quantity, price, and name? These are required + // 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.'); @@ -157,7 +157,7 @@ class CI_Cart { // -------------------------------------------------------------------- - // Prep the quantity. It can only be a number. Duh... + // 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'])); @@ -175,7 +175,7 @@ class CI_Cart { // 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'); + log_message('error', 'Invalid product ID. The product ID can only contain alpha-numeric characters, dashes, and underscores'); return FALSE; } @@ -191,7 +191,7 @@ class CI_Cart { // -------------------------------------------------------------------- - // Prep the price. Remove anything that isn't a number or decimal point. + // 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'])); @@ -210,7 +210,7 @@ class CI_Cart { // 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 + // 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. @@ -271,7 +271,7 @@ class CI_Cart { } // You can either update a single product using a one-dimensional array, - // or multiple products using a multi-dimensional one. The way we + // 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; @@ -344,7 +344,7 @@ class CI_Cart { return FALSE; } - // Is the quantity zero? If so we will remove the item from the cart. + // 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) { @@ -392,7 +392,7 @@ class CI_Cart { $this->_cart_contents['total_items'] = count($this->_cart_contents); $this->_cart_contents['cart_total'] = $total; - // Is our cart empty? If so we delete it from the session + // Is our cart empty? If so we delete it from the session if (count($this->_cart_contents) <= 2) { $this->CI->session->unset_userdata('cart_contents'); diff --git a/system/libraries/Driver.php b/system/libraries/Driver.php index d1925c0ec..b90b5aba6 100644 --- a/system/libraries/Driver.php +++ b/system/libraries/Driver.php @@ -1,4 +1,4 @@ -_attach_name[] = $filename; $this->_attach_type[] = $this->_mime_types(next(explode('.', basename($filename)))); - $this->_attach_disp[] = $disposition; // Can also be 'inline' Not sure if it matters + $this->_attach_disp[] = $disposition; // Can also be 'inline' Not sure if it matters return $this; } @@ -600,7 +600,7 @@ class CI_Email { $from = str_replace(">", "", $from); $from = str_replace("<", "", $from); - return "<".uniqid('').strstr($from, '@').">"; + return "<".uniqid('').strstr($from, '@').">"; } // -------------------------------------------------------------------- @@ -660,15 +660,15 @@ class CI_Email { */ private function _get_content_type() { - if ($this->mailtype == 'html' && count($this->_attach_name) == 0) + if ($this->mailtype == 'html' && count($this->_attach_name) == 0) { return 'html'; } - elseif ($this->mailtype == 'html' && count($this->_attach_name) > 0) + elseif ($this->mailtype == 'html' && count($this->_attach_name) > 0) { return 'html-attach'; } - elseif ($this->mailtype == 'text' && count($this->_attach_name) > 0) + elseif ($this->mailtype == 'text' && count($this->_attach_name) > 0) { return 'plain-attach'; } @@ -881,7 +881,7 @@ class CI_Email { // Use PHP's native public function to do the initial wordwrap. // We set the cut flag to FALSE so that any individual words that are - // too long get left alone. In the next step we'll deal with them. + // too long get left alone. In the next step we'll deal with them. $str = wordwrap($str, $charlim, "\n", FALSE); // Split the string into individual lines of text and cycle through them @@ -999,7 +999,7 @@ class CI_Email { */ private function _build_message() { - if ($this->wordwrap === TRUE AND $this->mailtype != 'html') + if ($this->wordwrap === TRUE AND $this->mailtype != 'html') { $this->_body = $this->word_wrap($this->_body); } @@ -1135,7 +1135,7 @@ class CI_Email { return FALSE; } - $h = "--".$this->_atc_boundary.$this->newline; + $h = "--".$this->_atc_boundary.$this->newline; $h .= "Content-type: ".$ctype."; "; $h .= "name=\"".$basename."\"".$this->newline; $h .= "Content-Disposition: ".$this->_attach_disp[$i].";".$this->newline; @@ -1237,7 +1237,7 @@ class CI_Email { // encode = signs if ($ascii == '61') { - $char = $escape.strtoupper(sprintf('%02s', dechex($ascii))); // =3D + $char = $escape.strtoupper(sprintf('%02s', dechex($ascii))); // =3D } // If we're at the character limit, add the line to the output, @@ -1267,7 +1267,7 @@ class CI_Email { /** * Prep Q Encoding * - * Performs "Q Encoding" on a string for use in email headers. It's related + * Performs "Q Encoding" on a string for use in email headers. It's related * but not identical to quoted-printable, so it has its own method * * @access public @@ -1349,7 +1349,7 @@ class CI_Email { $this->reply_to($this->_headers['From']); } - if (( ! isset($this->_recipients) AND ! isset($this->_headers['To'])) AND + if (( ! isset($this->_recipients) AND ! isset($this->_headers['To'])) AND ( ! isset($this->_bcc_array) AND ! isset($this->_headers['Bcc'])) AND ( ! isset($this->_headers['Cc']))) { @@ -1359,7 +1359,7 @@ class CI_Email { $this->_build_headers(); - if ($this->bcc_batch_mode AND count($this->_bcc_array) > 0) + if ($this->bcc_batch_mode AND count($this->_bcc_array) > 0) { if (count($this->_bcc_array) > $this->bcc_batch_size) return $this->batch_bcc_send(); @@ -1380,7 +1380,7 @@ class CI_Email { // -------------------------------------------------------------------- /** - * Batch Bcc Send. Sends groups of BCCs in batches + * Batch Bcc Send. Sends groups of BCCs in batches * * @access public * @return bool @@ -1752,7 +1752,7 @@ class CI_Email { // -------------------------------------------------------------------- /** - * SMTP Authenticate + * SMTP Authenticate * * @access private * @return bool @@ -1764,7 +1764,7 @@ class CI_Email { return TRUE; } - if ($this->smtp_user == "" AND $this->smtp_pass == "") + if ($this->smtp_user == "" AND $this->smtp_pass == "") { $this->_set_error_message('lang:email_no_smtp_unpw'); return FALSE; diff --git a/system/libraries/Encrypt.php b/system/libraries/Encrypt.php index b30a8cf0b..2f7db6623 100644 --- a/system/libraries/Encrypt.php +++ b/system/libraries/Encrypt.php @@ -1,4 +1,4 @@ -_field_data) == 0) { - // No validation rules? We're done... + // No validation rules? We're done... if (count($this->_config_rules) == 0) { return FALSE; @@ -648,7 +648,7 @@ class CI_Form_validation { } } - // Did the rule test negatively? If so, grab the error. + // Did the rule test negatively? If so, grab the error. if ($result === FALSE) { if ( ! isset($this->_error_messages[$rule])) @@ -664,7 +664,7 @@ class CI_Form_validation { } // Is the parameter we are inserting into the error message the name - // of another field? If so we need to grab its "field label" + // of another field? If so we need to grab its "field label" if (isset($this->_field_data[$param]) AND isset($this->_field_data[$param]['label'])) { $param = $this->_translate_fieldname($this->_field_data[$param]['label']); @@ -704,7 +704,7 @@ class CI_Form_validation { // Grab the variable $line = substr($fieldname, 5); - // Were we able to translate the field name? If not we use $line + // Were we able to translate the field name? If not we use $line if (FALSE === ($fieldname = $this->CI->lang->line($line))) { return $line; @@ -735,7 +735,7 @@ class CI_Form_validation { } // If the data is an array output them one at a time. - // E.g: form_input('name[]', set_value('name[]'); + // E.g: form_input('name[]', set_value('name[]'); if (is_array($this->_field_data[$field]['postdata'])) { return array_shift($this->_field_data[$field]['postdata']); @@ -914,7 +914,7 @@ class CI_Form_validation { return FALSE; } - return TRUE; + return TRUE; } // -------------------------------------------------------------------- @@ -1207,7 +1207,7 @@ class CI_Form_validation { // -------------------------------------------------------------------- /** - * Is a Natural number (0,1,2,3, etc.) + * Is a Natural number (0,1,2,3, etc.) * * @access public * @param string @@ -1221,7 +1221,7 @@ class CI_Form_validation { // -------------------------------------------------------------------- /** - * Is a Natural number, but not a zero (1,2,3, etc.) + * Is a Natural number, but not a zero (1,2,3, etc.) * * @access public * @param string @@ -1354,7 +1354,7 @@ class CI_Form_validation { */ function encode_php_tags($str) { - return str_replace(array(''), array('<?php', '<?PHP', '<?', '?>'), $str); + return str_replace(array(''), array('<?php', '<?PHP', '<?', '?>'), $str); } } diff --git a/system/libraries/Ftp.php b/system/libraries/Ftp.php index d7a8b3b02..859cc9c30 100644 --- a/system/libraries/Ftp.php +++ b/system/libraries/Ftp.php @@ -1,4 +1,4 @@ -list_files($filepath); @@ -513,7 +513,7 @@ class CI_FTP { * Read a directory and recreate it remotely * * This function recursively reads a folder and everything it contains (including - * sub-folders) and creates a mirror via FTP based on it. Whatever the directory structure + * sub-folders) and creates a mirror via FTP based on it. Whatever the directory structure * of the original file path will be recreated on the server. * * @access public diff --git a/system/libraries/Image_lib.php b/system/libraries/Image_lib.php index 8902f524d..099a238dd 100644 --- a/system/libraries/Image_lib.php +++ b/system/libraries/Image_lib.php @@ -1,4 +1,4 @@ -source_image == '') { $this->set_error('imglib_source_image_required'); - return FALSE; + return FALSE; } /* * Is getimagesize() Available? * * We use it to determine the image properties (width/height). - * Note: We need to figure out how to determine image + * Note: We need to figure out how to determine image * properties using ImageMagick and NetPBM * */ @@ -189,7 +189,7 @@ class CI_Image_lib { // Set the Image Properties if ( ! $this->get_image_properties($this->source_folder.$this->source_image)) { - return FALSE; + return FALSE; } /* @@ -197,7 +197,7 @@ class CI_Image_lib { * * If the user has set a "new_image" name it means * we are making a copy of the source image. If not - * it means we are altering the original. We'll + * it means we are altering the original. We'll * set the destination filename and path accordingly. * */ @@ -267,7 +267,7 @@ class CI_Image_lib { * * When creating thumbs or copies, the target width/height * might not be in correct proportion with the source - * image's width/height. We'll recalculate it here. + * image's width/height. We'll recalculate it here. * */ if ($this->maintain_ratio === TRUE && ($this->width != '' AND $this->height != '')) @@ -399,7 +399,7 @@ class CI_Image_lib { if ($this->rotation_angle == '' OR ! in_array($this->rotation_angle, $degs)) { $this->set_error('imglib_rotation_angle_required'); - return FALSE; + return FALSE; } // Reassign the width and height @@ -469,8 +469,8 @@ class CI_Image_lib { // Let's set up our values based on the action if ($action == 'crop') { - // Reassign the source width/height if cropping - $this->orig_width = $this->width; + // Reassign the source width/height if cropping + $this->orig_width = $this->width; $this->orig_height = $this->height; // GD 2.0 has a cropping bug so we'll test for it @@ -487,19 +487,19 @@ class CI_Image_lib { $this->y_axis = 0; } - // Create the image handle + // Create the image handle if ( ! ($src_img = $this->image_create_gd())) { return FALSE; } - // Create The Image + // Create The Image // - // old conditional which users report cause problems with shared GD libs who report themselves as "2.0 or greater" - // it appears that this is no longer the issue that it was in 2004, so we've removed it, retaining it in the comment - // below should that ever prove inaccurate. + // old conditional which users report cause problems with shared GD libs who report themselves as "2.0 or greater" + // it appears that this is no longer the issue that it was in 2004, so we've removed it, retaining it in the comment + // below should that ever prove inaccurate. // - // if ($this->image_library == 'gd2' AND function_exists('imagecreatetruecolor') AND $v2_override == FALSE) + // if ($this->image_library == 'gd2' AND function_exists('imagecreatetruecolor') AND $v2_override == FALSE) if ($this->image_library == 'gd2' AND function_exists('imagecreatetruecolor')) { $create = 'imagecreatetruecolor'; @@ -521,7 +521,7 @@ class CI_Image_lib { $copy($dst_img, $src_img, 0, 0, $this->x_axis, $this->y_axis, $this->width, $this->height, $this->orig_width, $this->orig_height); - // Show the image + // Show the image if ($this->dynamic_output == TRUE) { $this->image_display_gd($dst_img); @@ -535,7 +535,7 @@ class CI_Image_lib { } } - // Kill the file handles + // Kill the file handles imagedestroy($dst_img); imagedestroy($src_img); @@ -558,7 +558,7 @@ class CI_Image_lib { */ function image_process_imagemagick($action = 'resize') { - // Do we have a vaild library path? + // Do we have a vaild library path? if ($this->library_path == '') { $this->set_error('imglib_libpath_invalid'); @@ -593,7 +593,7 @@ class CI_Image_lib { $cmd .= " ".$angle." \"$this->full_src_path\" \"$this->full_dst_path\" 2>&1"; } - else // Resize + else // Resize { $cmd .= " -resize ".$this->width."x".$this->height." \"$this->full_src_path\" \"$this->full_dst_path\" 2>&1"; } @@ -634,7 +634,7 @@ class CI_Image_lib { return FALSE; } - // Build the resizing command + // Build the resizing command switch ($this->image_type) { case 1 : @@ -684,7 +684,7 @@ class CI_Image_lib { @exec($cmd, $output, $retval); - // Did it work? + // Did it work? if ($retval > 0) { $this->set_error('imglib_image_process_failed'); @@ -711,7 +711,7 @@ class CI_Image_lib { */ function image_rotate_gd() { - // Create the image handle + // Create the image handle if ( ! ($src_img = $this->image_create_gd())) { return FALSE; @@ -724,10 +724,10 @@ class CI_Image_lib { $white = imagecolorallocate($src_img, 255, 255, 255); - // Rotate it! + // Rotate it! $dst_img = imagerotate($src_img, $this->rotation_angle, $white); - // Save the Image + // Save the Image if ($this->dynamic_output == TRUE) { $this->image_display_gd($dst_img); @@ -741,7 +741,7 @@ class CI_Image_lib { } } - // Kill the file handles + // Kill the file handles imagedestroy($dst_img); imagedestroy($src_img); @@ -769,14 +769,14 @@ class CI_Image_lib { return FALSE; } - $width = $this->orig_width; + $width = $this->orig_width; $height = $this->orig_height; if ($this->rotation_angle == 'hor') { for ($i = 0; $i < $height; $i++) { - $left = 0; + $left = 0; $right = $width-1; while ($left < $right) @@ -813,7 +813,7 @@ class CI_Image_lib { } } - // Show the image + // Show the image if ($this->dynamic_output == TRUE) { $this->image_display_gd($src_img); @@ -827,7 +827,7 @@ class CI_Image_lib { } } - // Kill the file handles + // Kill the file handles imagedestroy($src_img); // Set the file to 777 @@ -876,24 +876,24 @@ class CI_Image_lib { return FALSE; } - // Fetch source image properties + // Fetch source image properties $this->get_image_properties(); - // Fetch watermark image properties + // Fetch watermark image properties $props = $this->get_image_properties($this->wm_overlay_path, TRUE); $wm_img_type = $props['image_type']; $wm_width = $props['width']; $wm_height = $props['height']; - // Create two image resources - $wm_img = $this->image_create_gd($this->wm_overlay_path, $wm_img_type); + // Create two image resources + $wm_img = $this->image_create_gd($this->wm_overlay_path, $wm_img_type); $src_img = $this->image_create_gd($this->full_src_path); // Reverse the offset if necessary // When the image is positioned at the bottom // we don't want the vertical offset to push it - // further down. We want the reverse, so we'll - // invert the offset. Same with the horizontal + // further down. We want the reverse, so we'll + // invert the offset. Same with the horizontal // offset when the image is at the right $this->wm_vrt_alignment = strtoupper(substr($this->wm_vrt_alignment, 0, 1)); @@ -905,11 +905,11 @@ class CI_Image_lib { if ($this->wm_hor_alignment == 'R') $this->wm_hor_offset = $this->wm_hor_offset * -1; - // Set the base x and y axis values + // Set the base x and y axis values $x_axis = $this->wm_hor_offset + $this->wm_padding; $y_axis = $this->wm_vrt_offset + $this->wm_padding; - // Set the vertical position + // Set the vertical position switch ($this->wm_vrt_alignment) { case 'T': @@ -920,7 +920,7 @@ class CI_Image_lib { break; } - // Set the horizontal position + // Set the horizontal position switch ($this->wm_hor_alignment) { case 'L': @@ -931,7 +931,7 @@ class CI_Image_lib { break; } - // Build the finalized image + // Build the finalized image if ($wm_img_type == 3 AND function_exists('imagealphablending')) { @imagealphablending($src_img, TRUE); @@ -954,7 +954,7 @@ class CI_Image_lib { imagecopymerge($src_img, $wm_img, $x_axis, $y_axis, 0, 0, $wm_width, $wm_height, $this->wm_opacity); } - // Output the image + // Output the image if ($this->dynamic_output == TRUE) { $this->image_display_gd($src_img); @@ -994,7 +994,7 @@ class CI_Image_lib { return FALSE; } - // Fetch source image properties + // Fetch source image properties $this->get_image_properties(); // Set RGB values for text and shadow @@ -1015,8 +1015,8 @@ class CI_Image_lib { // Reverse the vertical offset // When the image is positioned at the bottom // we don't want the vertical offset to push it - // further down. We want the reverse, so we'll - // invert the offset. Note: The horizontal + // further down. We want the reverse, so we'll + // invert the offset. Note: The horizontal // offset flips itself automatically if ($this->wm_vrt_alignment == 'B') @@ -1033,13 +1033,13 @@ class CI_Image_lib { if ($this->wm_font_size == '') $this->wm_font_size = '17'; - $fontwidth = $this->wm_font_size-($this->wm_font_size/4); + $fontwidth = $this->wm_font_size-($this->wm_font_size/4); $fontheight = $this->wm_font_size; $this->wm_vrt_offset += $this->wm_font_size; } else { - $fontwidth = imagefontwidth($this->wm_font_size); + $fontwidth = imagefontwidth($this->wm_font_size); $fontheight = imagefontheight($this->wm_font_size); } @@ -1080,11 +1080,11 @@ class CI_Image_lib { case "C": if ($this->wm_use_drop_shadow) $x_shad += floor(($this->orig_width - $fontwidth*strlen($this->wm_text))/2); - $x_axis += floor(($this->orig_width -$fontwidth*strlen($this->wm_text))/2); + $x_axis += floor(($this->orig_width -$fontwidth*strlen($this->wm_text))/2); break; } - // Add the text to the source image + // Add the text to the source image if ($this->wm_use_truetype) { if ($this->wm_use_drop_shadow) @@ -1098,7 +1098,7 @@ class CI_Image_lib { imagestring($src_img, $this->wm_font_size, $x_axis, $y_axis, $this->wm_text, $txt_color); } - // Output the final image + // Output the final image if ($this->dynamic_output == TRUE) { $this->image_display_gd($src_img); @@ -1366,7 +1366,7 @@ class CI_Image_lib { * Size calculator * * This function takes a known width x height and - * recalculates it to a new size. Only one + * recalculates it to a new size. Only one * new variable needs to be known * * $props = array( @@ -1374,7 +1374,7 @@ class CI_Image_lib { * 'height' => $height, * 'new_width' => 40, * 'new_height' => '' - * ); + * ); * * @access public * @param array @@ -1418,10 +1418,10 @@ class CI_Image_lib { * Explode source_image * * This is a helper function that extracts the extension - * from the source_image. This function lets us deal with - * source_images with multiple periods, like: my.cool.jpg + * from the source_image. This function lets us deal with + * source_images with multiple periods, like: my.cool.jpg * It returns an associative array with two elements: - * $array['ext'] = '.jpg'; + * $array['ext'] = '.jpg'; * $array['name'] = 'my.cool'; * * @access public diff --git a/system/libraries/Javascript.php b/system/libraries/Javascript.php index 34e0d7001..9e42a4385 100644 --- a/system/libraries/Javascript.php +++ b/system/libraries/Javascript.php @@ -1,4 +1,4 @@ -js =& $this->CI->$js_library_driver; - log_message('debug', "Javascript Class Initialized and loaded. Driver used: $js_library_driver"); + log_message('debug', "Javascript Class Initialized and loaded. Driver used: $js_library_driver"); } - // -------------------------------------------------------------------- + // -------------------------------------------------------------------- // Event Code // -------------------------------------------------------------------- @@ -378,7 +378,7 @@ class CI_Javascript { return $this->js->_unload($element, $js); } - // -------------------------------------------------------------------- + // -------------------------------------------------------------------- // Effects // -------------------------------------------------------------------- @@ -685,7 +685,7 @@ class CI_Javascript { return $str; } - + // -------------------------------------------------------------------- /** @@ -855,7 +855,7 @@ class CI_Javascript { } elseif (is_string($result) OR $is_key) { - return '"'.str_replace(array('\\', "\t", "\n", "\r", '"', '/'), array('\\\\', '\\t', '\\n', "\\r", '\"', '\/'), $result).'"'; + return '"'.str_replace(array('\\', "\t", "\n", "\r", '"', '/'), array('\\\\', '\\t', '\\n', "\\r", '\"', '\/'), $result).'"'; } elseif (is_scalar($result)) { diff --git a/system/libraries/Log.php b/system/libraries/Log.php index 9f1db76ba..2505fc678 100644 --- a/system/libraries/Log.php +++ b/system/libraries/Log.php @@ -1,4 +1,4 @@ - '1', 'DEBUG' => '2', 'INFO' => '3', 'ALL' => '4'); + protected $_levels = array('ERROR' => '1', 'DEBUG' => '2', 'INFO' => '3', 'ALL' => '4'); /** * Constructor @@ -84,11 +84,11 @@ class CI_Log { } $filepath = $this->_log_path.'log-'.date('Y-m-d').'.php'; - $message = ''; + $message = ''; if ( ! file_exists($filepath)) { - $message .= "<"."?php if ( ! defined('BASEPATH')) exit('No direct script access allowed'); ?".">\n\n"; + $message .= "<"."?php if ( ! defined('BASEPATH')) exit('No direct script access allowed'); ?".">\n\n"; } if ( ! $fp = @fopen($filepath, FOPEN_WRITE_CREATE)) diff --git a/system/libraries/Pagination.php b/system/libraries/Pagination.php index cc62e660b..d9c22d501 100644 --- a/system/libraries/Pagination.php +++ b/system/libraries/Pagination.php @@ -1,4 +1,4 @@ -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; + $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 + // 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) { @@ -194,14 +194,14 @@ class CI_Pagination { $output = ''; // Render the "First" link - if ($this->first_link !== FALSE AND $this->cur_page > ($this->num_links + 1)) + 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->prev_link !== FALSE AND $this->cur_page != 1) { $i = $uri_page_number - $this->per_page; @@ -263,7 +263,7 @@ class CI_Pagination { $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 + // 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); diff --git a/system/libraries/Parser.php b/system/libraries/Parser.php index d223da020..f48f2a7e5 100644 --- a/system/libraries/Parser.php +++ b/system/libraries/Parser.php @@ -1,4 +1,4 @@ -'; $output .= "\n"; $output .= '  '.$this->CI->lang->line('profiler_benchmarks').'  '; @@ -168,7 +168,7 @@ class CI_Profiler { if (count($dbs) == 0) { - $output = "\n\n"; + $output = "\n\n"; $output .= '
    '; $output .= "\n"; $output .= '  '.$this->CI->lang->line('profiler_queries').'  '; @@ -187,7 +187,7 @@ class CI_Profiler { // 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"; + $output = "\n\n"; $count = 0; @@ -249,7 +249,7 @@ class CI_Profiler { */ protected function _compile_get() { - $output = "\n\n"; + $output = "\n\n"; $output .= '
    '; $output .= "\n"; $output .= '  '.$this->CI->lang->line('profiler_get_data').'  '; @@ -298,7 +298,7 @@ class CI_Profiler { */ protected function _compile_post() { - $output = "\n\n"; + $output = "\n\n"; $output .= '
    '; $output .= "\n"; $output .= '  '.$this->CI->lang->line('profiler_post_data').'  '; @@ -347,7 +347,7 @@ class CI_Profiler { */ protected function _compile_uri_string() { - $output = "\n\n"; + $output = "\n\n"; $output .= '
    '; $output .= "\n"; $output .= '  '.$this->CI->lang->line('profiler_uri_string').'  '; @@ -376,7 +376,7 @@ class CI_Profiler { */ protected function _compile_controller_info() { - $output = "\n\n"; + $output = "\n\n"; $output .= '
    '; $output .= "\n"; $output .= '  '.$this->CI->lang->line('profiler_controller_info').'  '; @@ -400,7 +400,7 @@ class CI_Profiler { */ protected function _compile_memory_usage() { - $output = "\n\n"; + $output = "\n\n"; $output .= '
    '; $output .= "\n"; $output .= '  '.$this->CI->lang->line('profiler_memory_usage').'  '; @@ -431,7 +431,7 @@ class CI_Profiler { */ protected function _compile_http_headers() { - $output = "\n\n"; + $output = "\n\n"; $output .= '
    '; $output .= "\n"; $output .= '  '.$this->CI->lang->line('profiler_headers').'  ('.$this->CI->lang->line('profiler_section_show').')'; @@ -462,7 +462,7 @@ class CI_Profiler { */ protected function _compile_config() { - $output = "\n\n"; + $output = "\n\n"; $output .= '
    '; $output .= "\n"; $output .= '  '.$this->CI->lang->line('profiler_config').'  ('.$this->CI->lang->line('profiler_section_show').')'; diff --git a/system/libraries/Session.php b/system/libraries/Session.php index 2c8a80163..76525dbb8 100644 --- a/system/libraries/Session.php +++ b/system/libraries/Session.php @@ -1,4 +1,4 @@ -CI->load->library('encrypt'); } - // Are we using a database? If so, load it + // 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 + // 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 @@ -97,12 +97,12 @@ class CI_Session { { $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. + // create a new one. If it does, we'll update it. if ( ! $this->sess_read()) { $this->sess_create(); @@ -137,7 +137,7 @@ class CI_Session { // Fetch the cookie $session = $this->CI->input->cookie($this->sess_cookie_name); - // No cookie? Goodbye cruel world!... + // No cookie? Goodbye cruel world!... if ($session === FALSE) { log_message('debug', 'A session cookie was not found.'); @@ -155,8 +155,8 @@ class CI_Session { $hash = substr($session, strlen($session)-32); // get last 32 chars $session = substr($session, 0, strlen($session)-32); - // Does the md5 hash match? This is to prevent manipulation of session data in userspace - if ($hash !== md5($session.$this->encryption_key)) + // Does the md5 hash match? This is to prevent manipulation of session data in userspace + if ($hash !== md5($session.$this->encryption_key)) { log_message('error', 'The session cookie data did not match what was expected. This could be a possible hacking attempt.'); $this->sess_destroy(); @@ -212,14 +212,14 @@ class CI_Session { $query = $this->CI->db->get($this->sess_table_name); - // No result? Kill it! + // 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 + // 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 != '') { @@ -252,7 +252,7 @@ class CI_Session { */ function sess_write() { - // Are we saving custom data to the DB? If not, all we do is update the cookie + // 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(); @@ -272,7 +272,7 @@ class CI_Session { $cookie_userdata[$val] = $this->userdata[$val]; } - // Did we find any custom data? If not, we turn the empty array into a string + // Did we find any custom data? If not, we turn the empty array into a string // since there's no reason to serialize and store an empty array in the DB if (count($custom_userdata) === 0) { @@ -288,7 +288,7 @@ class CI_Session { $this->CI->db->where('session_id', $this->userdata['session_id']); $this->CI->db->update($this->sess_table_name, array('last_activity' => $this->userdata['last_activity'], 'user_data' => $custom_userdata)); - // Write the cookie. Notice that we manually pass the cookie data array to the + // Write the cookie. Notice that we manually pass the cookie data array to the // _set_cookie() function. Normally that function will store $this->userdata, but // in this case that array contains custom data, which we do not want in the cookie. $this->_set_cookie($cookie_userdata); @@ -535,7 +535,7 @@ class CI_Session { */ function keep_flashdata($key) { - // 'old' flashdata gets removed. Here we mark all + // 'old' flashdata gets removed. Here we mark all // flashdata as 'new' to preserve it from _flashdata_sweep() // Note the function will return FALSE if the $key // provided cannot be found diff --git a/system/libraries/Sha1.php b/system/libraries/Sha1.php index 1a657572b..04e07d1c1 100644 --- a/system/libraries/Sha1.php +++ b/system/libraries/Sha1.php @@ -1,4 +1,4 @@ -heading) == 0 AND count($this->rows) == 0) { return 'Undefined table data'; @@ -376,7 +376,7 @@ class CI_Table { // -------------------------------------------------------------------- /** - * Clears the table arrays. Useful if multiple tables are being generated + * Clears the table arrays. Useful if multiple tables are being generated * * @access public * @return void @@ -495,7 +495,7 @@ class CI_Table { */ function _default_template() { - return array ( + return array ( 'table_open' => '
    <<
    ', 'thead_open' => '', diff --git a/system/libraries/Trackback.php b/system/libraries/Trackback.php index b0a767822..b0f8a9098 100644 --- a/system/libraries/Trackback.php +++ b/system/libraries/Trackback.php @@ -1,4 +1,4 @@ -","\"", "'", "-"), array("&", "<", ">", """, "'", "-"), diff --git a/system/libraries/Typography.php b/system/libraries/Typography.php index 734cec104..3ceb0b52b 100644 --- a/system/libraries/Typography.php +++ b/system/libraries/Typography.php @@ -1,4 +1,4 @@ - tags if they exist. It's cheaper to do this separately since most content will + // match and yank
     tags if they exist. It's cheaper to do this separately since most content will
     		// not contain 
     tags, and it keeps the PCRE patterns below simpler and faster
     		if (strpos($str, 'inline_elements.")([ >])#i", "{@TAG}\\1\\2\\3", $str);
     
    -		// Split the string at every tag.  This expression creates an array with this prototype:
    +		// Split the string at every tag. This expression creates an array with this prototype:
     		//
     		//	[array]
     		//	{
    @@ -126,7 +126,7 @@ class CI_Typography {
     		//	}
     		$chunks = preg_split('/(<(?:[^<>]+(?:"[^"]*"|\'[^\']*\')?)+>)/', $str, -1, PREG_SPLIT_DELIM_CAPTURE|PREG_SPLIT_NO_EMPTY);
     
    -		// Build our finalized string.  We cycle through the array, skipping tags, and processing the contained text
    +		// Build our finalized string. We cycle through the array, skipping tags, and processing the contained text
     		$str = '';
     		$process = TRUE;
     		$paragraph = FALSE;
    @@ -143,7 +143,7 @@ class CI_Typography {
     			{
     				if (preg_match("#".$this->skip_elements."#", $match[2]))
     				{
    -					$process =  ($match[1] == '/') ? TRUE : FALSE;
    +					$process = ($match[1] == '/') ? TRUE : FALSE;
     				}
     
     				if ($match[1] == '')
    @@ -161,17 +161,17 @@ class CI_Typography {
     				continue;
     			}
     
    -			//  Force a newline to make sure end tags get processed by _format_newlines()
    +			// Force a newline to make sure end tags get processed by _format_newlines()
     			if ($current_chunk == $total_chunks)
     			{
     				$chunk .= "\n";
     			}
     
    -			//  Convert Newlines into 

    and
    tags + // Convert Newlines into

    and
    tags $str .= $this->_format_newlines($chunk); } - // No opening block level tag? Add it if needed. + // No opening block level tag? Add it if needed. if ( ! preg_match("/^\s*<(?:".$this->block_elements.")/i", $str)) { $str = preg_replace("/^(.*?)<(".$this->block_elements.")/i", '

    $1

    <$2', $str); @@ -204,14 +204,14 @@ class CI_Typography { '#

    <('.$this->block_elements.')#' => '<$1', // Clean up stray non-breaking spaces preceeding block elements - '#( \s*)+<('.$this->block_elements.')#' => ' <$2', + '#( \s*)+<('.$this->block_elements.')#' => ' <$2', // Replace the temporary markers we added earlier '/\{@TAG\}/' => '<', '/\{@DQ\}/' => '"', '/\{@SQ\}/' => "'", '/\{@DD\}/' => '--', - '/\{@NBS\}/' => ' ', + '/\{@NBS\}/' => ' ', // An unintended consequence of the _format_newlines function is that // some of the newlines get truncated, resulting in

    tags @@ -296,7 +296,7 @@ class CI_Typography { '/(\w)\.{3}/' => '$1…', // double space after sentences - '/(\W) /' => '$1  ', + '/(\W) /' => '$1  ', // ampersands, if not a character entity '/&(?!#?[a-zA-Z0-9]{2,};)/' => '&' @@ -324,7 +324,7 @@ class CI_Typography { return $str; } - if (strpos($str, "\n") === FALSE && ! in_array($this->last_block_element, $this->inner_block_required)) + if (strpos($str, "\n") === FALSE && ! in_array($this->last_block_element, $this->inner_block_required)) { return $str; } @@ -341,7 +341,7 @@ class CI_Typography { // We trim off the right-side new line so that the closing

    tag // will be positioned immediately following the string, matching // the behavior of the opening

    tag - $str = '

    '.rtrim($str).'

    '; + $str = '

    '.rtrim($str).'

    '; } // Remove empty paragraphs if they are on the first line, as this @@ -367,7 +367,7 @@ class CI_Typography { */ function _protect_characters($match) { - return str_replace(array("'",'"','--',' '), array('{@SQ}', '{@DQ}', '{@DD}', '{@NBS}'), $match[0]); + return str_replace(array("'",'"','--',' '), array('{@SQ}', '{@DQ}', '{@DD}', '{@NBS}'), $match[0]); } // -------------------------------------------------------------------- diff --git a/system/libraries/Unit_test.php b/system/libraries/Unit_test.php index 5bd7e801a..c9012f646 100644 --- a/system/libraries/Unit_test.php +++ b/system/libraries/Unit_test.php @@ -1,4 +1,4 @@ -set_error('upload_stopped_by_extension'); break; - default : $this->set_error('upload_no_file_selected'); + default : $this->set_error('upload_no_file_selected'); break; } @@ -290,7 +290,7 @@ class CI_Upload { /* * Run the file through the XSS hacking filter * This helps prevent malicious code from being - * embedded within a file. Scripts can easily + * embedded within a file. Scripts can easily * be disguised as images or other file types. */ if ($this->xss_clean) @@ -305,8 +305,8 @@ class CI_Upload { /* * Move the file to the final destination * To deal with different server configurations - * we'll attempt to use copy() first. If that fails - * we'll use move_uploaded_file(). One of the two should + * we'll attempt to use copy() first. If that fails + * we'll use move_uploaded_file(). One of the two should * reliably work in most environments */ if ( ! @copy($this->file_temp, $this->upload_path.$this->file_name)) @@ -321,7 +321,7 @@ class CI_Upload { /* * Set the finalized image dimensions * This sets the image width/height (assuming the - * file was an image). We use this information + * file was an image). We use this information * in the "data" function. */ $this->set_image_properties($this->upload_path.$this->file_name); @@ -518,7 +518,7 @@ class CI_Upload { $this->image_width = $D['0']; $this->image_height = $D['1']; $this->image_type = ( ! isset($types[$D['2']])) ? 'unknown' : $types[$D['2']]; - $this->image_size_str = $D['3']; // string containing height and width + $this->image_size_str = $D['3']; // string containing height and width } } } @@ -551,7 +551,7 @@ class CI_Upload { // IE will sometimes return odd mime-types during upload, so here we just standardize all // jpegs or pngs to the same file type. - $png_mimes = array('image/x-png'); + $png_mimes = array('image/x-png'); $jpeg_mimes = array('image/jpg', 'image/jpe', 'image/jpeg', 'image/pjpeg'); if (in_array($this->file_type, $png_mimes)) @@ -642,7 +642,7 @@ class CI_Upload { */ public function is_allowed_filesize() { - if ($this->max_size != 0 AND $this->file_size > $this->max_size) + if ($this->max_size != 0 AND $this->file_size > $this->max_size) { return FALSE; } @@ -721,7 +721,7 @@ class CI_Upload { return FALSE; } - $this->upload_path = preg_replace("/(.+?)\/*$/", "\\1/", $this->upload_path); + $this->upload_path = preg_replace("/(.+?)\/*$/", "\\1/", $this->upload_path); return TRUE; } @@ -834,7 +834,7 @@ class CI_Upload { $current = ini_get('memory_limit') * 1024 * 1024; // There was a bug/behavioural change in PHP 5.2, where numbers over one million get output - // into scientific notation. number_format() ensures this number is an integer + // into scientific notation. number_format() ensures this number is an integer // http://bugs.php.net/bug.php?id=43053 $new_memory = number_format(ceil(filesize($file) + $current), 0, '.', ''); @@ -844,8 +844,8 @@ class CI_Upload { // If the file being uploaded is an image, then we should have no problem with XSS attacks (in theory), but // IE can be fooled into mime-type detecting a malformed image as an html file, thus executing an XSS attack on anyone - // using IE who looks at the image. It does this by inspecting the first 255 bytes of an image. To get around this - // CI will itself look at the first 255 bytes of an image to determine its relative safety. This can save a lot of + // using IE who looks at the image. It does this by inspecting the first 255 bytes of an image. To get around this + // CI will itself look at the first 255 bytes of an image to determine its relative safety. This can save a lot of // processor power and time if it is actually a clean image, as it will be in nearly all instances _except_ an // attempted XSS attack. @@ -933,7 +933,7 @@ class CI_Upload { /** * List of Mime Types * - * This is a list of mime types. We use it to validate + * This is a list of mime types. We use it to validate * the "allowed types" set by the developer * * @param string diff --git a/system/libraries/User_agent.php b/system/libraries/User_agent.php index 016102a2a..543d1d5a3 100644 --- a/system/libraries/User_agent.php +++ b/system/libraries/User_agent.php @@ -1,4 +1,4 @@ -xmlrpcerr['unknown_method'] = '1'; $this->xmlrpcstr['unknown_method'] = 'This is not a known method for this XML-RPC Server'; $this->xmlrpcerr['invalid_return'] = '2'; - $this->xmlrpcstr['invalid_return'] = 'The XML data received was either invalid or not in the correct form for XML-RPC. Turn on debugging to examine the XML data further.'; + $this->xmlrpcstr['invalid_return'] = 'The XML data received was either invalid or not in the correct form for XML-RPC. Turn on debugging to examine the XML data further.'; $this->xmlrpcerr['incorrect_params'] = '3'; $this->xmlrpcstr['incorrect_params'] = 'Incorrect parameters were passed to method'; $this->xmlrpcerr['introspect_unknown'] = '4'; @@ -129,7 +129,7 @@ class CI_Xmlrpc { //------------------------------------- - // Initialize Prefs + // Initialize Prefs //------------------------------------- function initialize($config = array()) @@ -148,7 +148,7 @@ class CI_Xmlrpc { // END //------------------------------------- - // Take URL and parse it + // Take URL and parse it //------------------------------------- function server($url, $port=80) @@ -172,7 +172,7 @@ class CI_Xmlrpc { // END //------------------------------------- - // Set Timeout + // Set Timeout //------------------------------------- function timeout($seconds=5) @@ -185,7 +185,7 @@ class CI_Xmlrpc { // END //------------------------------------- - // Set Methods + // Set Methods //------------------------------------- function method($function) @@ -195,7 +195,7 @@ class CI_Xmlrpc { // END //------------------------------------- - // Take Array of Data and Create Objects + // Take Array of Data and Create Objects //------------------------------------- function request($incoming) @@ -216,7 +216,7 @@ class CI_Xmlrpc { //------------------------------------- - // Set Debug + // Set Debug //------------------------------------- function set_debug($flag = TRUE) @@ -225,7 +225,7 @@ class CI_Xmlrpc { } //------------------------------------- - // Values Parsing + // Values Parsing //------------------------------------- function values_parsing($value, $return = FALSE) @@ -268,7 +268,7 @@ class CI_Xmlrpc { //------------------------------------- - // Sends XML-RPC Request + // Sends XML-RPC Request //------------------------------------- function send_request() @@ -294,7 +294,7 @@ class CI_Xmlrpc { // END //------------------------------------- - // Returns Error + // Returns Error //------------------------------------- function display_error() @@ -304,7 +304,7 @@ class CI_Xmlrpc { // END //------------------------------------- - // Returns Remote Server Response + // Returns Remote Server Response //------------------------------------- function display_response() @@ -314,7 +314,7 @@ class CI_Xmlrpc { // END //------------------------------------- - // Sends an Error Message for Server Request + // Sends an Error Message for Server Request //------------------------------------- function send_error_message($number, $message) @@ -325,7 +325,7 @@ class CI_Xmlrpc { //------------------------------------- - // Send Response for Server Request + // Send Response for Server Request //------------------------------------- function send_response($response) @@ -399,7 +399,7 @@ class XML_RPC_Client extends CI_Xmlrpc } $r = "\r\n"; - $op = "POST {$this->path} HTTP/1.0$r"; + $op = "POST {$this->path} HTTP/1.0$r"; $op .= "Host: {$this->server}$r"; $op .= "Content-Type: text/xml$r"; $op .= "User-Agent: {$this->xmlrpcName}$r"; @@ -447,7 +447,7 @@ class XML_RPC_Response else if ( ! is_object($val)) { // programmer error, not an object - error_log("Invalid type '" . gettype($val) . "' (value: $val) passed to XML_RPC_Response. Defaulting to empty value."); + error_log("Invalid type '" . gettype($val) . "' (value: $val) passed to XML_RPC_Response. Defaulting to empty value."); $this->val = new XML_RPC_Values(); } else @@ -504,7 +504,7 @@ class XML_RPC_Response function decode($array=FALSE) { $CI =& get_instance(); - + if ($array !== FALSE && is_array($array)) { while (list($key) = each($array)) @@ -541,7 +541,7 @@ class XML_RPC_Response //------------------------------------- - // XML-RPC Object to PHP Types + // XML-RPC Object to PHP Types //------------------------------------- function xmlrpc_decoder($xmlrpc_val) @@ -581,7 +581,7 @@ class XML_RPC_Response //------------------------------------- - // ISO-8601 time to server or UTC time + // ISO-8601 time to server or UTC time //------------------------------------- function iso8601_decode($time, $utc=0) @@ -630,7 +630,7 @@ class XML_RPC_Message extends CI_Xmlrpc } //------------------------------------- - // Create Payload to Send + // Create Payload to Send //------------------------------------- function createPayload() @@ -650,7 +650,7 @@ class XML_RPC_Message extends CI_Xmlrpc } //------------------------------------- - // Parse External XML-RPC Server's Response + // Parse External XML-RPC Server's Response //------------------------------------- function parseResponse($fp) @@ -663,7 +663,7 @@ class XML_RPC_Message extends CI_Xmlrpc } //------------------------------------- - // DISPLAY HTTP CONTENT for DEBUGGING + // DISPLAY HTTP CONTENT for DEBUGGING //------------------------------------- if ($this->debug === TRUE) @@ -674,7 +674,7 @@ class XML_RPC_Message extends CI_Xmlrpc } //------------------------------------- - // Check for data + // Check for data //------------------------------------- if ($data == "") @@ -686,7 +686,7 @@ class XML_RPC_Message extends CI_Xmlrpc //------------------------------------- - // Check for HTTP 200 Response + // Check for HTTP 200 Response //------------------------------------- if (strncmp($data, 'HTTP', 4) == 0 && ! preg_match('/^HTTP\/[0-9\.]+ 200 /', $data)) @@ -697,7 +697,7 @@ class XML_RPC_Message extends CI_Xmlrpc } //------------------------------------- - // Create and Set Up XML Parser + // Create and Set Up XML Parser //------------------------------------- $parser = xml_parser_create($this->xmlrpc_defencoding); @@ -718,7 +718,7 @@ class XML_RPC_Message extends CI_Xmlrpc //------------------------------------- - // GET HEADERS + // GET HEADERS //------------------------------------- $lines = explode("\r\n", $data); @@ -734,7 +734,7 @@ class XML_RPC_Message extends CI_Xmlrpc //------------------------------------- - // PARSE XML DATA + // PARSE XML DATA //------------------------------------- if ( ! xml_parse($parser, $data, count($data))) @@ -750,7 +750,7 @@ class XML_RPC_Message extends CI_Xmlrpc xml_parser_free($parser); // --------------------------------------- - // Got Ourselves Some Badness, It Seems + // Got Ourselves Some Badness, It Seems // --------------------------------------- if ($this->xh[$parser]['isf'] > 1) @@ -772,7 +772,7 @@ class XML_RPC_Message extends CI_Xmlrpc } //------------------------------------- - // DISPLAY XML CONTENT for DEBUGGING + // DISPLAY XML CONTENT for DEBUGGING //------------------------------------- if ($this->debug === TRUE) @@ -797,7 +797,7 @@ class XML_RPC_Message extends CI_Xmlrpc } //------------------------------------- - // SEND RESPONSE + // SEND RESPONSE //------------------------------------- $v = $this->xh[$parser]['value']; @@ -826,21 +826,21 @@ class XML_RPC_Message extends CI_Xmlrpc } // ------------------------------------ - // Begin Return Message Parsing section + // Begin Return Message Parsing section // ------------------------------------ // quick explanation of components: - // ac - used to accumulate values - // isf - used to indicate a fault - // lv - used to indicate "looking for a value": implements + // ac - used to accumulate values + // isf - used to indicate a fault + // lv - used to indicate "looking for a value": implements // the logic to allow values with no types to be strings - // params - used to store parameters in method calls - // method - used to store method name + // params - used to store parameters in method calls + // method - used to store method name // stack - array with parent tree of the xml element, // used to validate the nesting of elements //------------------------------------- - // Start Element Handler + // Start Element Handler //------------------------------------- function open_tag($the_parser, $name, $attrs) @@ -942,7 +942,7 @@ class XML_RPC_Message extends CI_Xmlrpc //------------------------------------- - // End Element Handler + // End Element Handler //------------------------------------- function closing_tag($the_parser, $name) @@ -951,7 +951,7 @@ class XML_RPC_Message extends CI_Xmlrpc // Remove current element from stack and set variable // NOTE: If the XML validates, then we do not have to worry about - // the opening and closing of elements. Nesting is checked on the opening + // the opening and closing of elements. Nesting is checked on the opening // tag so we be safe there as well. $curr_elem = array_shift($this->xh[$the_parser]['stack']); @@ -1080,13 +1080,13 @@ class XML_RPC_Message extends CI_Xmlrpc // We're all good kids with nuthin' to do break; default: - // End of an Invalid Element. Taken care of during the opening tag though + // End of an Invalid Element. Taken care of during the opening tag though break; } } //------------------------------------- - // Parses Character Data + // Parses Character Data //------------------------------------- function character_data($the_parser, $data) @@ -1116,7 +1116,7 @@ class XML_RPC_Message extends CI_Xmlrpc function output_parameters($array=FALSE) { $CI =& get_instance(); - + if ($array !== FALSE && is_array($array)) { while (list($key) = each($array)) diff --git a/system/libraries/Xmlrpcs.php b/system/libraries/Xmlrpcs.php index 9cd332147..88af60693 100644 --- a/system/libraries/Xmlrpcs.php +++ b/system/libraries/Xmlrpcs.php @@ -1,4 +1,4 @@ -parseRequest(); - $payload = 'xmlrpc_defencoding.'"?'.'>'."\n"; + $payload = 'xmlrpc_defencoding.'"?'.'>'."\n"; $payload .= $this->debug_msg; $payload .= $r->prepare_response(); @@ -156,7 +156,7 @@ class CI_Xmlrpcs extends CI_Xmlrpc function add_to_map($methodname, $function, $sig, $doc) { $this->methods[$methodname] = array( - 'function' => $function, + 'function' => $function, 'signature' => $sig, 'docstring' => $doc ); @@ -176,7 +176,7 @@ class CI_Xmlrpcs extends CI_Xmlrpc global $HTTP_RAW_POST_DATA; //------------------------------------- - // Get Data + // Get Data //------------------------------------- if ($data == '') @@ -185,7 +185,7 @@ class CI_Xmlrpcs extends CI_Xmlrpc } //------------------------------------- - // Set up XML Parser + // Set up XML Parser //------------------------------------- $parser = xml_parser_create($this->xmlrpc_defencoding); @@ -207,7 +207,7 @@ class CI_Xmlrpcs extends CI_Xmlrpc //------------------------------------- - // PARSE + PROCESS XML DATA + // PARSE + PROCESS XML DATA //------------------------------------- if ( ! xml_parse($parser, $data, 1)) @@ -235,7 +235,7 @@ class CI_Xmlrpcs extends CI_Xmlrpc { if ($this->debug === TRUE) { - $plist .= "$i - " . print_r(get_object_vars($parser_object->xh[$parser]['params'][$i]), TRUE). ";\n"; + $plist .= "$i - " . print_r(get_object_vars($parser_object->xh[$parser]['params'][$i]), TRUE). ";\n"; } $m->addParam($parser_object->xh[$parser]['params'][$i]); @@ -252,7 +252,7 @@ class CI_Xmlrpcs extends CI_Xmlrpc } //------------------------------------- - // SET DEBUGGING MESSAGE + // SET DEBUGGING MESSAGE //------------------------------------- if ($this->debug === TRUE) @@ -285,7 +285,7 @@ class CI_Xmlrpcs extends CI_Xmlrpc } //------------------------------------- - // Valid Method + // Valid Method //------------------------------------- if ( ! isset($this->methods[$methName]['function'])) @@ -294,7 +294,7 @@ class CI_Xmlrpcs extends CI_Xmlrpc } //------------------------------------- - // Check for Method (and Object) + // Check for Method (and Object) //------------------------------------- $method_parts = explode(".", $this->methods[$methName]['function']); @@ -320,7 +320,7 @@ class CI_Xmlrpcs extends CI_Xmlrpc } //------------------------------------- - // Checking Methods Signature + // Checking Methods Signature //------------------------------------- if (isset($this->methods[$methName]['signature'])) @@ -353,7 +353,7 @@ class CI_Xmlrpcs extends CI_Xmlrpc } //------------------------------------- - // Calls the Function + // Calls the Function //------------------------------------- if ($objectCall === TRUE) @@ -381,11 +381,11 @@ class CI_Xmlrpcs extends CI_Xmlrpc return call_user_func($this->methods[$methName]['function'], $m); } } - + // -------------------------------------------------------------------- /** - * Server Function: List Methods + * Server Function: List Methods * * @access public * @param mixed @@ -409,11 +409,11 @@ class CI_Xmlrpcs extends CI_Xmlrpc $v->addArray($output); return new XML_RPC_Response($v); } - + // -------------------------------------------------------------------- /** - * Server Function: Return Signature for Method + * Server Function: Return Signature for Method * * @access public * @param mixed @@ -458,7 +458,7 @@ class CI_Xmlrpcs extends CI_Xmlrpc // -------------------------------------------------------------------- /** - * Server Function: Doc String for Method + * Server Function: Doc String for Method * * @access public * @param mixed @@ -480,11 +480,11 @@ class CI_Xmlrpcs extends CI_Xmlrpc return new XML_RPC_Response(0, $this->xmlrpcerr['introspect_unknown'], $this->xmlrpcstr['introspect_unknown']); } } - + // -------------------------------------------------------------------- /** - * Server Function: Multi-call + * Server Function: Multi-call * * @access public * @param mixed @@ -528,7 +528,7 @@ class CI_Xmlrpcs extends CI_Xmlrpc // -------------------------------------------------------------------- /** - * Multi-call Function: Error Handling + * Multi-call Function: Error Handling * * @access public * @param mixed @@ -536,7 +536,7 @@ class CI_Xmlrpcs extends CI_Xmlrpc */ function multicall_error($err) { - $str = is_string($err) ? $this->xmlrpcstr["multicall_${err}"] : $err->faultString(); + $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'); @@ -548,7 +548,7 @@ class CI_Xmlrpcs extends CI_Xmlrpc // -------------------------------------------------------------------- /** - * Multi-call Function: Processes method + * Multi-call Function: Processes method * * @access public * @param mixed diff --git a/system/libraries/Zip.php b/system/libraries/Zip.php index 666327d5c..1ae3e7f25 100644 --- a/system/libraries/Zip.php +++ b/system/libraries/Zip.php @@ -1,4 +1,4 @@ -CI =& get_instance(); + $this->CI =& get_instance(); extract($params); if ($autoload === TRUE) { - $this->script(); + $this->script(); } - + log_message('debug', "Jquery Class Initialized"); } - - // -------------------------------------------------------------------- + + // -------------------------------------------------------------------- // Event Code - // -------------------------------------------------------------------- + // -------------------------------------------------------------------- /** * Blur @@ -65,9 +65,9 @@ class CI_Jquery extends CI_Javascript { { return $this->_add_event($element, $js, 'blur'); } - + // -------------------------------------------------------------------- - + /** * Change * @@ -82,9 +82,9 @@ class CI_Jquery extends CI_Javascript { { return $this->_add_event($element, $js, 'change'); } - + // -------------------------------------------------------------------- - + /** * Click * @@ -112,7 +112,7 @@ class CI_Jquery extends CI_Javascript { } // -------------------------------------------------------------------- - + /** * Double Click * @@ -129,7 +129,7 @@ class CI_Jquery extends CI_Javascript { } // -------------------------------------------------------------------- - + /** * Error * @@ -146,7 +146,7 @@ class CI_Jquery extends CI_Javascript { } // -------------------------------------------------------------------- - + /** * Focus * @@ -163,7 +163,7 @@ class CI_Jquery extends CI_Javascript { } // -------------------------------------------------------------------- - + /** * Hover * @@ -185,7 +185,7 @@ class CI_Jquery extends CI_Javascript { } // -------------------------------------------------------------------- - + /** * Keydown * @@ -202,7 +202,7 @@ class CI_Jquery extends CI_Javascript { } // -------------------------------------------------------------------- - + /** * Keyup * @@ -216,10 +216,10 @@ class CI_Jquery extends CI_Javascript { function _keyup($element = 'this', $js = '') { return $this->_add_event($element, $js, 'keyup'); - } + } // -------------------------------------------------------------------- - + /** * Load * @@ -233,10 +233,10 @@ class CI_Jquery extends CI_Javascript { function _load($element = 'this', $js = '') { return $this->_add_event($element, $js, 'load'); - } - + } + // -------------------------------------------------------------------- - + /** * Mousedown * @@ -253,7 +253,7 @@ class CI_Jquery extends CI_Javascript { } // -------------------------------------------------------------------- - + /** * Mouse Out * @@ -270,7 +270,7 @@ class CI_Jquery extends CI_Javascript { } // -------------------------------------------------------------------- - + /** * Mouse Over * @@ -321,7 +321,7 @@ class CI_Jquery extends CI_Javascript { { $array_js = array($array_js); } - + foreach ($array_js as $js) { $this->jquery_code_for_compile[] = "\t$js\n"; @@ -361,7 +361,7 @@ class CI_Jquery extends CI_Javascript { { return $this->_add_event($element, $js, 'scroll'); } - + // -------------------------------------------------------------------- /** @@ -379,10 +379,10 @@ class CI_Jquery extends CI_Javascript { return $this->_add_event($element, $js, 'unload'); } - // -------------------------------------------------------------------- + // -------------------------------------------------------------------- // Effects - // -------------------------------------------------------------------- - + // -------------------------------------------------------------------- + /** * Add Class * @@ -395,7 +395,7 @@ class CI_Jquery extends CI_Javascript { function _addClass($element = 'this', $class='') { $element = $this->_prep_element($element); - $str = "$({$element}).addClass(\"$class\");"; + $str = "$({$element}).addClass(\"$class\");"; return $str; } @@ -416,9 +416,9 @@ class CI_Jquery extends CI_Javascript { { $element = $this->_prep_element($element); $speed = $this->_validate_speed($speed); - + $animations = "\t\t\t"; - + foreach ($params as $param=>$value) { $animations .= $param.': \''.$value.'\', '; @@ -430,19 +430,19 @@ class CI_Jquery extends CI_Javascript { { $speed = ', '.$speed; } - + if ($extra != '') { $extra = ', '.$extra; } - - $str = "$({$element}).animate({\n$animations\n\t\t}".$speed.$extra.");"; - + + $str = "$({$element}).animate({\n$animations\n\t\t}".$speed.$extra.");"; + return $str; } // -------------------------------------------------------------------- - + /** * Fade In * @@ -456,21 +456,21 @@ class CI_Jquery extends CI_Javascript { */ function _fadeIn($element = 'this', $speed = '', $callback = '') { - $element = $this->_prep_element($element); + $element = $this->_prep_element($element); $speed = $this->_validate_speed($speed); - + if ($callback != '') { $callback = ", function(){\n{$callback}\n}"; } - - $str = "$({$element}).fadeIn({$speed}{$callback});"; - + + $str = "$({$element}).fadeIn({$speed}{$callback});"; + return $str; } - + // -------------------------------------------------------------------- - + /** * Fade Out * @@ -486,14 +486,14 @@ class CI_Jquery extends CI_Javascript { { $element = $this->_prep_element($element); $speed = $this->_validate_speed($speed); - + if ($callback != '') { $callback = ", function(){\n{$callback}\n}"; } - - $str = "$({$element}).fadeOut({$speed}{$callback});"; - + + $str = "$({$element}).fadeOut({$speed}{$callback});"; + return $str; } @@ -512,19 +512,19 @@ class CI_Jquery extends CI_Javascript { */ function _hide($element = 'this', $speed = '', $callback = '') { - $element = $this->_prep_element($element); + $element = $this->_prep_element($element); $speed = $this->_validate_speed($speed); - + if ($callback != '') { $callback = ", function(){\n{$callback}\n}"; } - - $str = "$({$element}).hide({$speed}{$callback});"; + + $str = "$({$element}).hide({$speed}{$callback});"; return $str; } - + // -------------------------------------------------------------------- /** @@ -539,12 +539,12 @@ class CI_Jquery extends CI_Javascript { function _removeClass($element = 'this', $class='') { $element = $this->_prep_element($element); - $str = "$({$element}).removeClass(\"$class\");"; + $str = "$({$element}).removeClass(\"$class\");"; return $str; } // -------------------------------------------------------------------- - + /** * Slide Up * @@ -558,21 +558,21 @@ class CI_Jquery extends CI_Javascript { */ function _slideUp($element = 'this', $speed = '', $callback = '') { - $element = $this->_prep_element($element); + $element = $this->_prep_element($element); $speed = $this->_validate_speed($speed); - + if ($callback != '') { $callback = ", function(){\n{$callback}\n}"; } - - $str = "$({$element}).slideUp({$speed}{$callback});"; - + + $str = "$({$element}).slideUp({$speed}{$callback});"; + return $str; } - + // -------------------------------------------------------------------- - + /** * Slide Down * @@ -588,19 +588,19 @@ class CI_Jquery extends CI_Javascript { { $element = $this->_prep_element($element); $speed = $this->_validate_speed($speed); - + if ($callback != '') { $callback = ", function(){\n{$callback}\n}"; } - - $str = "$({$element}).slideDown({$speed}{$callback});"; - + + $str = "$({$element}).slideDown({$speed}{$callback});"; + return $str; } // -------------------------------------------------------------------- - + /** * Slide Toggle * @@ -616,19 +616,19 @@ class CI_Jquery extends CI_Javascript { { $element = $this->_prep_element($element); $speed = $this->_validate_speed($speed); - + if ($callback != '') { $callback = ", function(){\n{$callback}\n}"; } - - $str = "$({$element}).slideToggle({$speed}{$callback});"; - + + $str = "$({$element}).slideToggle({$speed}{$callback});"; + return $str; } - + // -------------------------------------------------------------------- - + /** * Toggle * @@ -641,12 +641,12 @@ class CI_Jquery extends CI_Javascript { function _toggle($element = 'this') { $element = $this->_prep_element($element); - $str = "$({$element}).toggle();"; + $str = "$({$element}).toggle();"; return $str; } - + // -------------------------------------------------------------------- - + /** * Toggle Class * @@ -659,12 +659,12 @@ class CI_Jquery extends CI_Javascript { function _toggleClass($element = 'this', $class='') { $element = $this->_prep_element($element); - $str = "$({$element}).toggleClass(\"$class\");"; + $str = "$({$element}).toggleClass(\"$class\");"; return $str; } - + // -------------------------------------------------------------------- - + /** * Show * @@ -678,16 +678,16 @@ class CI_Jquery extends CI_Javascript { */ function _show($element = 'this', $speed = '', $callback = '') { - $element = $this->_prep_element($element); + $element = $this->_prep_element($element); $speed = $this->_validate_speed($speed); - + if ($callback != '') { $callback = ", function(){\n{$callback}\n}"; } - - $str = "$({$element}).show({$speed}{$callback});"; - + + $str = "$({$element}).show({$speed}{$callback});"; + return $str; } @@ -696,7 +696,7 @@ class CI_Jquery extends CI_Javascript { /** * Updater * - * An Ajax call that populates the designated DOM node with + * An Ajax call that populates the designated DOM node with * returned content * * @access private @@ -705,13 +705,13 @@ class CI_Jquery extends CI_Javascript { * @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') == '') { @@ -721,7 +721,7 @@ class CI_Jquery extends CI_Javascript { { $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 @@ -741,7 +741,7 @@ class CI_Jquery extends CI_Javascript { // -------------------------------------------------------------------- // Pre-written handy stuff // -------------------------------------------------------------------- - + /** * Zebra tables * @@ -753,8 +753,8 @@ class CI_Jquery extends CI_Javascript { function _zebraTables($class = '', $odd = 'odd', $hover = '') { $class = ($class != '') ? '.'.$class : ''; - - $zebra = "\t\$(\"table{$class} tbody tr:nth-child(even)\").addClass(\"{$odd}\");"; + + $zebra = "\t\$(\"table{$class} tbody tr:nth-child(even)\").addClass(\"{$odd}\");"; $this->jquery_code_for_compile[] = $zebra; @@ -771,7 +771,7 @@ class CI_Jquery extends CI_Javascript { // -------------------------------------------------------------------- // Plugins // -------------------------------------------------------------------- - + /** * Corner Plugin * @@ -793,7 +793,7 @@ class CI_Jquery extends CI_Javascript { return "$(" . $this->_prep_element($element) . ").corner(".$corner_style.");"; } - + // -------------------------------------------------------------------- /** @@ -805,7 +805,7 @@ class CI_Jquery extends CI_Javascript { * @return void */ function modal($src, $relative = FALSE) - { + { $this->jquery_code_for_load[] = $this->external($src, $relative); } @@ -897,7 +897,7 @@ class CI_Jquery extends CI_Javascript { { $this->jquery_code_for_compile[] = "\t$(" . $this->_prep_element($table) . ").tablesorter($options);\n"; } - + // -------------------------------------------------------------------- // Class functions // -------------------------------------------------------------------- @@ -912,7 +912,7 @@ class CI_Jquery extends CI_Javascript { * @param string The code to execute * @param string The event to pass * @return string - */ + */ function _add_event($element, $js, $event) { if (is_array($js)) @@ -953,15 +953,15 @@ class CI_Jquery extends CI_Javascript { $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 * @@ -976,7 +976,7 @@ class CI_Jquery extends CI_Javascript { } // -------------------------------------------------------------------- - + /** * Document Ready * @@ -992,7 +992,7 @@ class CI_Jquery extends CI_Javascript { $js = array ($js); } - + foreach ($js as $script) { $this->jquery_code_for_compile[] = $script; @@ -1016,7 +1016,7 @@ class CI_Jquery extends CI_Javascript { $this->jquery_code_for_load[] = $library_src; return $library_src; } - + // -------------------------------------------------------------------- /** @@ -1036,10 +1036,10 @@ class CI_Jquery extends CI_Javascript { { $element = '"'.$element.'"'; } - + return $element; } - + // -------------------------------------------------------------------- /** @@ -1050,7 +1050,7 @@ class CI_Jquery extends CI_Javascript { * @access private * @param string * @return string - */ + */ function _validate_speed($speed) { if (in_array($speed, array('slow', 'normal', 'fast'))) @@ -1061,7 +1061,7 @@ class CI_Jquery extends CI_Javascript { { $speed = ''; } - + return $speed; } -- cgit v1.2.3-24-g4f1b From 28bda7fd05d5261e0da1702e789cfedc6ab423b4 Mon Sep 17 00:00:00 2001 From: Greg Aker Date: Mon, 25 Apr 2011 15:00:45 -0500 Subject: swapping out preg_replace() in the driver library where str_replace() works just fine. --- system/libraries/Driver.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'system') diff --git a/system/libraries/Driver.php b/system/libraries/Driver.php index b90b5aba6..1e01fcc1f 100644 --- a/system/libraries/Driver.php +++ b/system/libraries/Driver.php @@ -43,11 +43,11 @@ class CI_Driver_Library { // 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(preg_replace('/^CI_/', '', $this->lib_name))); - $driver_name = strtolower(preg_replace('/^CI_/', '', $child_class)); - + $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 -- cgit v1.2.3-24-g4f1b From d97e12cb0e9c8b5e78e67780d1a9227da35e0da4 Mon Sep 17 00:00:00 2001 From: Eric Barnes Date: Tue, 26 Apr 2011 09:59:29 -0400 Subject: Automatic base_url generation was missing a ending slash. --- system/core/Config.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system') diff --git a/system/core/Config.php b/system/core/Config.php index fa71f4d3d..55c623b3c 100644 --- a/system/core/Config.php +++ b/system/core/Config.php @@ -55,7 +55,7 @@ class CI_Config { { $base_url = isset($_SERVER['HTTPS']) && strtolower($_SERVER['HTTPS']) !== 'off' ? 'https' : 'http'; $base_url .= '://'. $_SERVER['HTTP_HOST']; - $base_url .= str_replace(basename($_SERVER['SCRIPT_NAME']), '', $_SERVER['SCRIPT_NAME']); + $base_url .= str_replace(basename($_SERVER['SCRIPT_NAME']), '', $_SERVER['SCRIPT_NAME']).'/'; } else -- cgit v1.2.3-24-g4f1b From 32dbac2695490fb751fc8da645bba945bc8da718 Mon Sep 17 00:00:00 2001 From: Eric Barnes Date: Tue, 26 Apr 2011 22:51:32 -0400 Subject: Reverting last change. Don't know what I was thinking. :( --- system/core/Config.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system') diff --git a/system/core/Config.php b/system/core/Config.php index 55c623b3c..fa71f4d3d 100644 --- a/system/core/Config.php +++ b/system/core/Config.php @@ -55,7 +55,7 @@ class CI_Config { { $base_url = isset($_SERVER['HTTPS']) && strtolower($_SERVER['HTTPS']) !== 'off' ? 'https' : 'http'; $base_url .= '://'. $_SERVER['HTTP_HOST']; - $base_url .= str_replace(basename($_SERVER['SCRIPT_NAME']), '', $_SERVER['SCRIPT_NAME']).'/'; + $base_url .= str_replace(basename($_SERVER['SCRIPT_NAME']), '', $_SERVER['SCRIPT_NAME']); } else -- cgit v1.2.3-24-g4f1b From 60ef4ea72e169e174ff8dbb421609a178a3c0c48 Mon Sep 17 00:00:00 2001 From: Greg Aker Date: Wed, 27 Apr 2011 01:45:38 -0500 Subject: Added insert_batch() function to the PostgreSQL database driver. Thanks to epallerols for the patch. --- system/database/drivers/postgre/postgre_driver.php | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) (limited to 'system') diff --git a/system/database/drivers/postgre/postgre_driver.php b/system/database/drivers/postgre/postgre_driver.php index 47ff36246..140396885 100644 --- a/system/database/drivers/postgre/postgre_driver.php +++ b/system/database/drivers/postgre/postgre_driver.php @@ -553,6 +553,24 @@ class CI_DB_postgre_driver extends CI_DB { // -------------------------------------------------------------------- + /** + * 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 * -- cgit v1.2.3-24-g4f1b From 2e1837a3afabe7e6c71fc88d7a4f5e430fa96744 Mon Sep 17 00:00:00 2001 From: Greg Aker Date: Fri, 6 May 2011 12:17:04 -0500 Subject: Fix #275 -- regression in db::_compile_select(). Thanks @patwork for the patch --- system/database/DB_active_rec.php | 26 +++++++++++++++----------- 1 file changed, 15 insertions(+), 11 deletions(-) (limited to 'system') diff --git a/system/database/DB_active_rec.php b/system/database/DB_active_rec.php index 508f6bedf..d94d4a13c 100644 --- a/system/database/DB_active_rec.php +++ b/system/database/DB_active_rec.php @@ -60,7 +60,7 @@ class CI_DB_active_record extends CI_DB_driver { var $ar_cache_set = array(); var $ar_no_escape = array(); - + var $ar_cache_no_escape = array(); // -------------------------------------------------------------------- @@ -93,6 +93,7 @@ class CI_DB_active_record extends CI_DB_driver { { $this->ar_cache_select[] = $val; $this->ar_cache_exists[] = 'select'; + $this->ar_cache_no_escape[] = $escape; } } } @@ -1933,16 +1934,17 @@ class CI_DB_active_record extends CI_DB_driver { { $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_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() ) ); } @@ -1984,6 +1986,8 @@ class CI_DB_active_record extends CI_DB_driver { { $this->_track_aliases($this->ar_from); } + + $this->ar_no_escape = $this->ar_cache_no_escape; } // -------------------------------------------------------------------- -- cgit v1.2.3-24-g4f1b From 3ef65bd7491f847fecdab1acc9687f0e90eee09b Mon Sep 17 00:00:00 2001 From: Dan Horrigan Date: Sun, 8 May 2011 11:06:44 -0400 Subject: Wrapped all common functions to check if it already exists. This allows anyone to override a lot more of the core by simply defining these function prior to loading them. --- system/core/Common.php | 61 +++++++++++++++++++++++++++++++++++++++----------- 1 file changed, 48 insertions(+), 13 deletions(-) (limited to 'system') diff --git a/system/core/Common.php b/system/core/Common.php index eb9e14425..e50f7794a 100644 --- a/system/core/Common.php +++ b/system/core/Common.php @@ -39,6 +39,8 @@ * @param string * @return bool TRUE if the current version is $version or higher */ +if ( ! function_exists('is_php')) +{ function is_php($version = '5.0.0') { static $_is_php; @@ -51,6 +53,7 @@ return $_is_php[$version]; } +} // ------------------------------------------------------------------------ @@ -64,6 +67,8 @@ * @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 @@ -96,6 +101,7 @@ fclose($fp); return TRUE; } +} // ------------------------------------------------------------------------ @@ -112,6 +118,8 @@ * @param string the class name prefix * @return object */ +if ( ! function_exists('load_class')) +{ function &load_class($class, $directory = 'libraries', $prefix = 'CI_') { static $_classes = array(); @@ -166,6 +174,7 @@ $_classes[$class] = new $name(); return $_classes[$class]; } +} // -------------------------------------------------------------------- @@ -176,6 +185,8 @@ * @access public * @return array */ +if ( ! function_exists('is_loaded')) +{ function is_loaded($class = '') { static $_is_loaded = array(); @@ -187,6 +198,7 @@ return $_is_loaded; } +} // ------------------------------------------------------------------------ @@ -199,6 +211,8 @@ * @access private * @return array */ +if ( ! function_exists('get_config')) +{ function &get_config($replace = array()) { static $_config; @@ -242,6 +256,7 @@ return $_config[0] =& $config; } +} // ------------------------------------------------------------------------ @@ -251,6 +266,8 @@ * @access public * @return mixed */ +if ( ! function_exists('config_item')) +{ function config_item($item) { static $_config_item = array(); @@ -268,6 +285,7 @@ return $_config_item[$item]; } +} // ------------------------------------------------------------------------ @@ -283,12 +301,15 @@ * @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; } +} // ------------------------------------------------------------------------ @@ -302,12 +323,15 @@ * @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; } +} // ------------------------------------------------------------------------ @@ -320,6 +344,8 @@ * @access public * @return void */ +if ( ! function_exists('log_message')) +{ function log_message($level = 'error', $message, $php_error = FALSE) { static $_log; @@ -332,6 +358,7 @@ $_log =& load_class('Log'); $_log->write_log($level, $message, $php_error); } +} // ------------------------------------------------------------------------ @@ -343,6 +370,8 @@ * @param string * @return void */ +if ( ! function_exists('set_status_header')) +{ function set_status_header($code = 200, $text = '') { $stati = array( @@ -417,6 +446,7 @@ header("HTTP/1.1 {$code} {$text}", TRUE, $code); } } +} // -------------------------------------------------------------------- @@ -434,6 +464,8 @@ * @access private * @return void */ +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 @@ -463,19 +495,22 @@ $_error->log_exception($severity, $message, $filepath, $line); } +} - // -------------------------------------------------------------------- - - /** - * Remove Invisible Characters - * - * This prevents sandwiching null characters - * between ascii characters, like Java\0script. - * - * @access public - * @param string - * @return string - */ +// -------------------------------------------------------------------- + +/** + * 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(); @@ -499,7 +534,7 @@ return $str; } - +} /* End of file Common.php */ /* Location: ./system/core/Common.php */ \ No newline at end of file -- cgit v1.2.3-24-g4f1b From 4b9c62980599228f070b401c7673dce8085b0c61 Mon Sep 17 00:00:00 2001 From: Derek Jones Date: Fri, 1 Jul 2011 17:40:48 -0500 Subject: backed out 648b42a75739, which was a NON-trivial whitespace commit. It broke the Typography class's string replacements, for instance --- system/core/Benchmark.php | 4 +- system/core/CodeIgniter.php | 68 +++---- system/core/Common.php | 28 +-- system/core/Config.php | 18 +- system/core/Controller.php | 6 +- system/core/Exceptions.php | 6 +- system/core/Hooks.php | 4 +- system/core/Input.php | 24 +-- system/core/Lang.php | 2 +- system/core/Loader.php | 60 +++--- system/core/Model.php | 2 +- system/core/Output.php | 20 +- system/core/Router.php | 26 +-- system/core/Security.php | 104 +++++----- system/core/URI.php | 14 +- system/core/Utf8.php | 2 +- system/database/DB.php | 16 +- system/database/DB_active_rec.php | 32 +-- system/database/DB_cache.php | 6 +- system/database/DB_driver.php | 34 ++-- system/database/DB_forge.php | 2 +- system/database/DB_result.php | 106 +++++----- system/database/DB_utility.php | 6 +- system/database/drivers/mssql/mssql_driver.php | 2 +- system/database/drivers/mssql/mssql_forge.php | 4 +- system/database/drivers/mssql/mssql_result.php | 4 +- system/database/drivers/mssql/mssql_utility.php | 2 +- system/database/drivers/mysql/mysql_driver.php | 14 +- system/database/drivers/mysql/mysql_forge.php | 4 +- system/database/drivers/mysql/mysql_result.php | 4 +- system/database/drivers/mysql/mysql_utility.php | 4 +- system/database/drivers/mysqli/mysqli_driver.php | 8 +- system/database/drivers/mysqli/mysqli_forge.php | 4 +- system/database/drivers/mysqli/mysqli_result.php | 4 +- system/database/drivers/mysqli/mysqli_utility.php | 2 +- system/database/drivers/oci8/oci8_driver.php | 138 ++++++------- system/database/drivers/oci8/oci8_forge.php | 4 +- system/database/drivers/oci8/oci8_result.php | 34 ++-- system/database/drivers/oci8/oci8_utility.php | 2 +- system/database/drivers/odbc/odbc_driver.php | 2 +- system/database/drivers/odbc/odbc_forge.php | 4 +- system/database/drivers/odbc/odbc_result.php | 4 +- system/database/drivers/odbc/odbc_utility.php | 2 +- system/database/drivers/postgre/postgre_driver.php | 2 +- system/database/drivers/postgre/postgre_forge.php | 10 +- system/database/drivers/postgre/postgre_result.php | 4 +- .../database/drivers/postgre/postgre_utility.php | 2 +- system/database/drivers/sqlite/sqlite_driver.php | 2 +- system/database/drivers/sqlite/sqlite_forge.php | 6 +- system/database/drivers/sqlite/sqlite_result.php | 4 +- system/database/drivers/sqlite/sqlite_utility.php | 4 +- system/helpers/array_helper.php | 8 +- system/helpers/captcha_helper.php | 20 +- system/helpers/cookie_helper.php | 6 +- system/helpers/date_helper.php | 22 +-- system/helpers/directory_helper.php | 4 +- system/helpers/download_helper.php | 2 +- system/helpers/email_helper.php | 2 +- system/helpers/file_helper.php | 4 +- system/helpers/form_helper.php | 18 +- system/helpers/html_helper.php | 10 +- system/helpers/inflector_helper.php | 14 +- system/helpers/language_helper.php | 2 +- system/helpers/number_helper.php | 2 +- system/helpers/path_helper.php | 4 +- system/helpers/security_helper.php | 4 +- system/helpers/smiley_helper.php | 12 +- system/helpers/string_helper.php | 8 +- system/helpers/text_helper.php | 10 +- system/helpers/typography_helper.php | 2 +- system/helpers/url_helper.php | 6 +- system/helpers/xml_helper.php | 4 +- system/language/english/email_lang.php | 6 +- system/language/english/imglib_lang.php | 10 +- system/libraries/Cache/Cache.php | 30 +-- system/libraries/Cache/drivers/Cache_apc.php | 24 +-- system/libraries/Cache/drivers/Cache_file.php | 40 ++-- system/libraries/Calendar.php | 18 +- system/libraries/Cart.php | 22 +-- system/libraries/Driver.php | 2 +- system/libraries/Email.php | 46 ++--- system/libraries/Encrypt.php | 2 +- system/libraries/Form_validation.php | 32 +-- system/libraries/Ftp.php | 8 +- system/libraries/Image_lib.php | 118 +++++------ system/libraries/Javascript.php | 12 +- system/libraries/Log.php | 8 +- system/libraries/Pagination.php | 18 +- system/libraries/Parser.php | 18 +- system/libraries/Profiler.php | 26 +-- system/libraries/Session.php | 30 +-- system/libraries/Sha1.php | 8 +- system/libraries/Table.php | 12 +- system/libraries/Trackback.php | 16 +- system/libraries/Typography.php | 36 ++-- system/libraries/Unit_test.php | 2 +- system/libraries/Upload.php | 28 +-- system/libraries/User_agent.php | 2 +- system/libraries/Xmlrpc.php | 90 ++++----- system/libraries/Xmlrpcs.php | 44 ++--- system/libraries/Zip.php | 12 +- system/libraries/javascript/Jquery.php | 218 ++++++++++----------- 102 files changed, 986 insertions(+), 986 deletions(-) (limited to 'system') diff --git a/system/core/Benchmark.php b/system/core/Benchmark.php index 3686c2d73..515550e9f 100644 --- a/system/core/Benchmark.php +++ b/system/core/Benchmark.php @@ -1,4 +1,4 @@ -_call_hook('pre_system'); /* * ------------------------------------------------------ - * Instantiate the config class + * Instantiate the config class * ------------------------------------------------------ */ $CFG =& load_class('Config', 'core'); @@ -143,7 +143,7 @@ /* * ------------------------------------------------------ - * Instantiate the UTF-8 class + * Instantiate the UTF-8 class * ------------------------------------------------------ * * Note: Order here is rather important as the UTF-8 @@ -157,14 +157,14 @@ /* * ------------------------------------------------------ - * Instantiate the URI class + * Instantiate the URI class * ------------------------------------------------------ */ $URI =& load_class('URI', 'core'); /* * ------------------------------------------------------ - * Instantiate the routing class and set the routing + * Instantiate the routing class and set the routing * ------------------------------------------------------ */ $RTR =& load_class('Router', 'core'); @@ -178,14 +178,14 @@ /* * ------------------------------------------------------ - * Instantiate the output class + * Instantiate the output class * ------------------------------------------------------ */ $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) @@ -205,21 +205,21 @@ /* * ------------------------------------------------------ - * Load the Input class and sanitize globals + * Load the Input class and sanitize globals * ------------------------------------------------------ */ $IN =& load_class('Input', 'core'); /* * ------------------------------------------------------ - * Load the Language class + * Load the Language class * ------------------------------------------------------ */ $LANG =& load_class('Lang', 'core'); /* * ------------------------------------------------------ - * Load the app controller and local controller + * Load the app controller and local controller * ------------------------------------------------------ * */ @@ -252,14 +252,14 @@ /* * ------------------------------------------------------ - * Security check + * Security check * ------------------------------------------------------ * - * 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 + * 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(); + $class = $RTR->fetch_class(); $method = $RTR->fetch_method(); if ( ! class_exists($class) @@ -272,14 +272,14 @@ /* * ------------------------------------------------------ - * Is there a "pre_controller" hook? + * Is there a "pre_controller" hook? * ------------------------------------------------------ */ $EXT->_call_hook('pre_controller'); /* * ------------------------------------------------------ - * Instantiate the requested controller + * Instantiate the requested controller * ------------------------------------------------------ */ // Mark a start point so we can benchmark the controller @@ -289,14 +289,14 @@ /* * ------------------------------------------------------ - * Is there a "post_controller_constructor" hook? + * Is there a "post_controller_constructor" hook? * ------------------------------------------------------ */ $EXT->_call_hook('post_controller_constructor'); /* * ------------------------------------------------------ - * Call the requested method + * Call the requested method * ------------------------------------------------------ */ // Is there a "remap" function? If so, we call it instead @@ -345,14 +345,14 @@ /* * ------------------------------------------------------ - * Is there a "post_controller" hook? + * Is there a "post_controller" hook? * ------------------------------------------------------ */ $EXT->_call_hook('post_controller'); /* * ------------------------------------------------------ - * Send the final rendered output to the browser + * Send the final rendered output to the browser * ------------------------------------------------------ */ if ($EXT->_call_hook('display_override') === FALSE) @@ -362,14 +362,14 @@ /* * ------------------------------------------------------ - * Is there a "post_system" hook? + * Is there a "post_system" hook? * ------------------------------------------------------ */ $EXT->_call_hook('post_system'); /* * ------------------------------------------------------ - * Close the DB connection if one exists + * Close the DB connection if one exists * ------------------------------------------------------ */ if (class_exists('CI_DB') AND isset($CI->db)) diff --git a/system/core/Common.php b/system/core/Common.php index eb9e14425..d1e8e77e9 100644 --- a/system/core/Common.php +++ b/system/core/Common.php @@ -1,4 +1,4 @@ -show_php_error($severity, $message, $filepath, $line); } - // Should we log the error? No? We're done... + // Should we log the error? No? We're done... if (config_item('log_threshold') == 0) { return; @@ -479,16 +479,16 @@ function remove_invisible_characters($str, $url_encoded = TRUE) { $non_displayables = array(); - + // every control character except newline (dec 10) // carriage return (dec 13), and horizontal tab (dec 09) - + if ($url_encoded) { $non_displayables[] = '/%0[0-8bcef]/'; // url encoded 00-08, 11, 12, 14, 15 $non_displayables[] = '/%1[0-9a-f]/'; // url encoded 16-31 } - + $non_displayables[] = '/[\x00-\x08\x0B\x0C\x0E-\x1F\x7F]+/S'; // 00-08, 11, 12, 14-31, 127 do diff --git a/system/core/Config.php b/system/core/Config.php index fa71f4d3d..1096a9ea6 100644 --- a/system/core/Config.php +++ b/system/core/Config.php @@ -1,4 +1,4 @@ -load =& load_class('Loader', 'core'); $this->load->set_base_classes()->ci_autoloader(); - + log_message('debug', "Controller Class Initialized"); } diff --git a/system/core/Exceptions.php b/system/core/Exceptions.php index 2503c907f..bff86a92f 100644 --- a/system/core/Exceptions.php +++ b/system/core/Exceptions.php @@ -1,4 +1,4 @@ -ob_level = ob_get_level(); - // Note: Do not log messages from this constructor. + // Note: Do not log messages from this constructor. } // -------------------------------------------------------------------- @@ -75,7 +75,7 @@ class CI_Exceptions { { $severity = ( ! isset($this->levels[$severity])) ? $severity : $this->levels[$severity]; - log_message('error', 'Severity: '.$severity.' --> '.$message. ' '.$filepath.' '.$line, TRUE); + log_message('error', 'Severity: '.$severity.' --> '.$message. ' '.$filepath.' '.$line, TRUE); } // -------------------------------------------------------------------- diff --git a/system/core/Hooks.php b/system/core/Hooks.php index ffb3258d8..fd6380f0a 100644 --- a/system/core/Hooks.php +++ b/system/core/Hooks.php @@ -1,4 +1,4 @@ -_fetch_from_array($_POST, $index, $xss_clean); } @@ -201,7 +201,7 @@ class CI_Input { * @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 domain. Usually: .yourdomain.com * @param string the cookie path * @param string the cookie prefix * @param bool true makes the cookie secure @@ -402,9 +402,9 @@ class CI_Input { function _sanitize_globals() { // It would be "wrong" to unset any of these GLOBALS. - $protected = array('_SERVER', '_GET', '_POST', '_FILES', '_REQUEST', + $protected = array('_SERVER', '_GET', '_POST', '_FILES', '_REQUEST', '_SESSION', '_ENV', 'GLOBALS', 'HTTP_RAW_POST_DATA', - 'system_folder', 'application_folder', 'BM', 'EXT', + 'system_folder', 'application_folder', 'BM', 'EXT', 'CFG', 'URI', 'RTR', 'OUT', 'IN'); // Unset globals for securiy. @@ -523,7 +523,7 @@ class CI_Input { { $str = $this->uni->clean_string($str); } - + // Remove control characters $str = remove_invisible_characters($str); @@ -579,7 +579,7 @@ class CI_Input { /** * Request Headers * - * In Apache, you can simply call apache_request_headers(), however for + * In Apache, you can simply call apache_request_headers(), however for * people running other webservers the function is undefined. * * @return array @@ -609,10 +609,10 @@ class CI_Input { { $key = str_replace('_', ' ', strtolower($key)); $key = str_replace(' ', '-', ucwords($key)); - + $this->headers[$key] = $val; } - + return $this->headers; } @@ -633,7 +633,7 @@ class CI_Input { { $this->request_headers(); } - + if ( ! isset($this->headers[$index])) { return FALSE; @@ -644,7 +644,7 @@ class CI_Input { return $this->security->xss_clean($this->headers[$index]); } - return $this->headers[$index]; + return $this->headers[$index]; } // -------------------------------------------------------------------- diff --git a/system/core/Lang.php b/system/core/Lang.php index 79eb443a0..170e6c725 100644 --- a/system/core/Lang.php +++ b/system/core/Lang.php @@ -1,4 +1,4 @@ - 'unit', + protected $_ci_varmap = array('unit_test' => 'unit', 'user_agent' => 'agent'); /** @@ -50,29 +50,29 @@ class CI_Loader { */ public function __construct() { - $this->_ci_ob_level = ob_get_level(); + $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"); } // -------------------------------------------------------------------- - + /** * Set _base_classes variable * * This method is called once in CI_Controller. * - * @param array + * @param array * @return object */ public function set_base_classes() { $this->_base_classes =& is_loaded(); - + return $this; } @@ -96,7 +96,7 @@ class CI_Loader { { return $this->_ci_classes[$class]; } - + return FALSE; } @@ -260,7 +260,7 @@ class CI_Loader { return DB($params, $active_record); } - // Initialize the db variable. Needed to prevent + // Initialize the db variable. Needed to prevent // reference errors with some configurations $CI->db = ''; @@ -323,11 +323,11 @@ class CI_Loader { /** * Load View * - * This function is used to load a "view" file. It has three parameters: + * 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 + * 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. * @@ -538,13 +538,13 @@ class CI_Loader { * Prepends a parent path to the library, model, helper, and config path arrays * * @param string - * @param boolean + * @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); @@ -604,7 +604,7 @@ class CI_Loader { unset($this->{$var}[$key]); } } - + if (isset($this->_ci_view_paths[$path.'views/'])) { unset($this->_ci_view_paths[$path.'views/']); @@ -643,7 +643,7 @@ class CI_Loader { { $$_ci_val = ( ! isset($_ci_data[$_ci_val])) ? FALSE : $_ci_data[$_ci_val]; } - + $file_exists = FALSE; // Set the path to the requested file @@ -665,11 +665,11 @@ class CI_Loader { $file_exists = TRUE; break; } - + if ( ! $cascade) { break; - } + } } } @@ -710,9 +710,9 @@ class CI_Loader { * We buffer the output for two reasons: * 1. Speed. You get a significant speed boost. * 2. So that the final rendered template can be - * post-processed by the output class. Why do we - * need post processing? For one thing, in order to - * show the elapsed page load time. Unless we + * 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. */ @@ -809,11 +809,11 @@ class CI_Loader { show_error("Unable to load the requested class: ".$class); } - // Safety: Was the class already loaded by a previous call? + // 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 + // if a custom object name is being supplied. If so, we'll // return a new instance of the object if ( ! is_null($object_name)) { @@ -842,17 +842,17 @@ class CI_Loader { { $filepath = $path.'libraries/'.$subdir.$class.'.php'; - // Does the file exist? No? Bummer... + // Does the file exist? No? Bummer... if ( ! file_exists($filepath)) { continue; } - // Safety: Was the class already loaded by a previous call? + // 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 + // if a custom object name is being supplied. If so, we'll // return a new instance of the object if ( ! is_null($object_name)) { @@ -875,7 +875,7 @@ class CI_Loader { } // END FOREACH - // One last attempt. Maybe the library is in a subdirectory, but it wasn't specified? + // One last attempt. Maybe the library is in a subdirectory, but it wasn't specified? if ($subdir == '') { $path = strtolower($class).'/'.$class; @@ -903,7 +903,7 @@ class CI_Loader { */ 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 + // 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 @@ -970,7 +970,7 @@ class CI_Loader { } // Set the variable name we will assign the class to - // Was a custom class name supplied? If so we'll use it + // Was a custom class name supplied? If so we'll use it $class = strtolower($class); if (is_null($object_name)) @@ -1005,7 +1005,7 @@ class CI_Loader { * The config/autoload.php file contains an array that permits sub-systems, * libraries, and helpers to be loaded automatically. * - * This function is public, as it's used in the CI_Controller class. + * This function is public, as it's used in the CI_Controller class. * However, there is no reason you should ever needs to use it. * * @param array @@ -1021,7 +1021,7 @@ class CI_Loader { { include_once(APPPATH.'config/autoload.php'); } - + if ( ! isset($autoload)) { diff --git a/system/core/Model.php b/system/core/Model.php index 61c71b672..8566a0b66 100644 --- a/system/core/Model.php +++ b/system/core/Model.php @@ -1,4 +1,4 @@ -final_output * * This function sends the finalized output data to the browser along - * with any server headers and profile data. It also stops the + * 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 @@ -269,7 +269,7 @@ class CI_Output { */ function _display($output = '') { - // Note: We use globals because we can't use $CI =& get_instance() + // 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; @@ -290,7 +290,7 @@ class CI_Output { // -------------------------------------------------------------------- - // Do we need to write a cache file? Only if the controller does not have its + // 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')) @@ -368,7 +368,7 @@ class CI_Output { // 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 = preg_replace("|.*?|is", '', $output); $output .= $CI->profiler->run(); $output .= ''; } @@ -381,14 +381,14 @@ class CI_Output { // -------------------------------------------------------------------- // Does the controller contain a function named _output()? - // If so send the output there. Otherwise, echo it. + // 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! + echo $output; // Send it to the browser! } log_message('debug', "Final output sent to browser"); @@ -458,7 +458,7 @@ class CI_Output { { $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 + // 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; diff --git a/system/core/Router.php b/system/core/Router.php index a76a7bd0a..5e92a04b1 100644 --- a/system/core/Router.php +++ b/system/core/Router.php @@ -1,4 +1,4 @@ -routes = ( ! isset($route) OR ! is_array($route)) ? array() : $route; unset($route); @@ -103,7 +103,7 @@ class CI_Router { // 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. + // 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); @@ -212,7 +212,7 @@ class CI_Router { // -------------------------------------------------------------------- /** - * Validates the supplied segments. Attempts to determine the path to + * Validates the supplied segments. Attempts to determine the path to * the controller. * * @access private @@ -277,7 +277,7 @@ class CI_Router { // 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 + // controller class. We will now see if there is an override if ( ! empty($this->routes['404_override'])) { $x = explode('/', $this->routes['404_override']); @@ -296,7 +296,7 @@ class CI_Router { // -------------------------------------------------------------------- /** - * Parse Routes + * Parse Routes * * This function matches any routes that may exist in * the config/routes.php file against the URI to @@ -310,7 +310,7 @@ class CI_Router { // Turn the segment array into a URI string $uri = implode('/', $this->uri->segments); - // Is there a literal match? If so we're done + // Is there a literal match? If so we're done if (isset($this->routes[$uri])) { return $this->_set_request(explode('/', $this->routes[$uri])); @@ -370,7 +370,7 @@ class CI_Router { // -------------------------------------------------------------------- /** - * Set the method name + * Set the method name * * @access public * @param string @@ -384,7 +384,7 @@ class CI_Router { // -------------------------------------------------------------------- /** - * Fetch the current method + * Fetch the current method * * @access public * @return string @@ -402,7 +402,7 @@ class CI_Router { // -------------------------------------------------------------------- /** - * Set the directory name + * Set the directory name * * @access public * @param string @@ -416,7 +416,7 @@ class CI_Router { // -------------------------------------------------------------------- /** - * Fetch the sub-directory (if any) that contains the requested controller class + * Fetch the sub-directory (if any) that contains the requested controller class * * @access public * @return string @@ -429,7 +429,7 @@ class CI_Router { // -------------------------------------------------------------------- /** - * Set the controller overrides + * Set the controller overrides * * @access public * @param array diff --git a/system/core/Security.php b/system/core/Security.php index f5bfafd9b..3617cadcc 100644 --- a/system/core/Security.php +++ b/system/core/Security.php @@ -1,4 +1,4 @@ - '[removed]', // IE, surprise! "Redirect\s+302" => '[removed]' ); - + /** * Constructor */ @@ -95,7 +95,7 @@ class CI_Security { } // Do the tokens exist in both the _POST and _COOKIE arrays? - if ( ! isset($_POST[$this->_csrf_token_name]) OR + if ( ! isset($_POST[$this->_csrf_token_name]) OR ! isset($_COOKIE[$this->_csrf_cookie_name])) { $this->csrf_show_error(); @@ -107,7 +107,7 @@ class CI_Security { $this->csrf_show_error(); } - // We kill this since we're done and we don't want to + // We kill this since we're done and we don't want to // polute the _POST array unset($_POST[$this->_csrf_token_name]); @@ -117,7 +117,7 @@ class CI_Security { $this->csrf_set_cookie(); log_message('debug', "CSRF token verified "); - + return $this; } @@ -146,7 +146,7 @@ class CI_Security { 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; } @@ -165,9 +165,9 @@ class CI_Security { // -------------------------------------------------------------------- /** - * Get CSRF Hash + * Get CSRF Hash * - * Getter Method + * Getter Method * * @return string self::_csrf_hash */ @@ -196,14 +196,14 @@ class CI_Security { * XSS Clean * * Sanitizes data so that Cross Site Scripting Hacks can be - * prevented. This function does a fair amount of work but + * 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, + * 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 + * 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 @@ -263,7 +263,7 @@ class CI_Security { */ $str = preg_replace_callback("/[a-z]+=([\'\"]).*?\\1/si", array($this, '_convert_attribute'), $str); - + $str = preg_replace_callback("/<\w+.*?(?=>|<|$)/si", array($this, '_decode_entity'), $str); /* @@ -276,7 +276,7 @@ class CI_Security { * * 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 + * NOTE: preg_replace was found to be amazingly slow here on * large blocks of data, so we use str_replace. */ @@ -304,27 +304,27 @@ class CI_Security { */ if ($is_image === TRUE) { - // Images have a tendency to have the PHP short opening and - // closing tags every so often so we skip those and only + // Images have a tendency to have the PHP short opening and + // closing tags every so often so we skip those and only // do the long opening tags. $str = preg_replace('/<\?(php)/i', "<?\\1", $str); } else { - $str = str_replace(array(''), array('<?', '?>'), $str); + $str = str_replace(array(''), array('<?', '?>'), $str); } /* * Compact any exploded words * - * This corrects words like: j a v a s c r i p t + * 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', 'script', + 'javascript', 'expression', 'vbscript', 'script', 'applet', 'alert', 'document', 'write', 'cookie', 'window' ); - + foreach ($words as $word) { $temp = ''; @@ -341,8 +341,8 @@ class CI_Security { /* * Remove disallowed Javascript in links or img tags - * We used to do some version comparisons and use of stripos for PHP5, - * but it is dog slow compared to these simplified non-capturing + * We used to do some version comparisons and use of stripos for PHP5, + * but it is dog slow compared to these simplified non-capturing * preg_match(), especially if the pattern exists in the string */ do @@ -388,7 +388,7 @@ class CI_Security { * * Similar to above, only instead of looking for * tags it looks for PHP and JavaScript commands - * that are disallowed. Rather than removing the + * that are disallowed. Rather than removing the * code, it simply converts the parenthesis to entities * rendering the code un-executable. * @@ -405,11 +405,11 @@ class CI_Security { /* * 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. + * - 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 + * 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. */ @@ -457,7 +457,7 @@ class CI_Security { * * In some versions of PHP the native function does not work * when UTF-8 is the specified character set, so this gives us - * a work-around. More info here: + * a work-around. More info here: * http://bugs.php.net/bug.php?id=25670 * * NOTE: html_entity_decode() has a bug in some PHP versions when UTF-8 is the @@ -475,10 +475,10 @@ class CI_Security { // 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 + // correctly. html_entity_decode() does not convert entities without // semicolons, so we are left with our own little solution here. Bummer. - if (function_exists('html_entity_decode') && + if (function_exists('html_entity_decode') && (strtolower($charset) != 'utf-8')) { $str = html_entity_decode($str, ENT_COMPAT, $charset); @@ -542,7 +542,7 @@ class CI_Security { "%3b", // ; "%3d" // = ); - + if ( ! $relative_path) { $bad[] = './'; @@ -570,7 +570,7 @@ class CI_Security { } // -------------------------------------------------------------------- - + /* * Remove Evil HTML Attributes (like evenhandlers and style) * @@ -578,7 +578,7 @@ class CI_Security { * - Everything up until a space * For example, everything between the pipes: * - * - Everything inside the quotes + * - Everything inside the quotes * For example, everything between the pipes: * * @@ -594,12 +594,12 @@ class CI_Security { if ($is_image === TRUE) { /* - * Adobe Photoshop puts XML metadata into JFIF images, + * 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 { $str = preg_replace( "#<(/?[^><]+?)([^A-Za-z\-])(".implode('|', $evil_attributes).")(\s*=\s*)([\"][^>]*?[\"]|[\'][^>]*?[\']|[^>]*?)([\s><])([><]*)#i", @@ -607,10 +607,10 @@ class CI_Security { $str, -1, $count ); } while ($count); - + return $str; } - + // -------------------------------------------------------------------- /** @@ -627,7 +627,7 @@ class CI_Security { $str = '<'.$matches[1].$matches[2].$matches[3]; // encode captured opening or closing brace to prevent recursive vectors - $str .= str_replace(array('>', '<'), array('>', '<'), + $str .= str_replace(array('>', '<'), array('>', '<'), $matches[4]); return $str; @@ -649,7 +649,7 @@ class CI_Security { protected function _js_link_removal($match) { $attributes = $this->_filter_attributes(str_replace(array('<', '>'), '', $match[1])); - + return str_replace($match[1], preg_replace("#href=.*?(alert\(|alert&\#40;|javascript\:|livescript\:|mocha\:|charset\=|window\.|document\.|\.cookie|_filter_attributes(str_replace(array('<', '>'), '', $match[1])); - + return str_replace($match[1], preg_replace("#src=.*?(alert\(|alert&\#40;|javascript\:|livescript\:|mocha\:|charset\=|window\.|document\.|\.cookie|xss_hash()."\\1=\\2", $str); /* * Validate standard character entities * - * Add a semicolon if missing. We do this to enable + * Add a semicolon if missing. We do this to enable * the conversion of entities to ASCII later. * */ @@ -769,7 +769,7 @@ class CI_Security { * Un-Protect GET variables in URLs */ $str = str_replace($this->xss_hash(), '&', $str); - + return $str; } @@ -794,7 +794,7 @@ class CI_Security { { $str = preg_replace("#".$key."#i", $val, $str); } - + return $str; } @@ -809,16 +809,16 @@ class CI_Security { { if ($this->_csrf_hash == '') { - // If the cookie exists we will use it's value. + // 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 + // each page load since a page could contain embedded // sub-pages causing this feature to fail - if (isset($_COOKIE[$this->_csrf_cookie_name]) && + if (isset($_COOKIE[$this->_csrf_cookie_name]) && $_COOKIE[$this->_csrf_cookie_name] != '') { return $this->_csrf_hash = $_COOKIE[$this->_csrf_cookie_name]; } - + return $this->_csrf_hash = md5(uniqid(rand(), TRUE)); } diff --git a/system/core/URI.php b/system/core/URI.php index 94fac59ac..d56548654 100644 --- a/system/core/URI.php +++ b/system/core/URI.php @@ -1,4 +1,4 @@ -_set_uri_string($path); @@ -251,7 +251,7 @@ class CI_URI { */ function _remove_url_suffix() { - if ($this->config->item('url_suffix') != "") + if ($this->config->item('url_suffix') != "") { $this->uri_string = preg_replace("|".preg_quote($this->config->item('url_suffix'))."$|", "", $this->uri_string); } @@ -285,7 +285,7 @@ class CI_URI { * 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 + * 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. * @@ -323,7 +323,7 @@ class CI_URI { * Fetch a URI "routed" Segment * * This function returns the re-routed URI segment (assuming routing rules are used) - * based on the number provided. If there is no routing this function returns the + * based on the number provided. If there is no routing this function returns the * same result as $this->segment() * * @access public @@ -425,7 +425,7 @@ class CI_URI { $i = 0; $lastval = ''; - $retval = array(); + $retval = array(); foreach ($segments as $seg) { if ($i % 2) diff --git a/system/core/Utf8.php b/system/core/Utf8.php index 738d7e9d8..2a27d1f35 100644 --- a/system/core/Utf8.php +++ b/system/core/Utf8.php @@ -1,4 +1,4 @@ -_track_aliases($val); @@ -332,7 +332,7 @@ class CI_DB_active_record extends CI_DB_driver { } } - // Extract any aliases that might exist. We use this information + // 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); @@ -438,7 +438,7 @@ class CI_DB_active_record extends CI_DB_driver { $v = ' '.$this->escape($v); } - + if ( ! $this->_has_operator($k)) { $k .= ' = '; @@ -926,7 +926,7 @@ class CI_DB_active_record extends CI_DB_driver { // -------------------------------------------------------------------- /** - * The "set" function. Allows key/value pairs to be set for inserting or updating + * The "set" function. Allows key/value pairs to be set for inserting or updating * * @access public * @param mixed @@ -1084,7 +1084,7 @@ class CI_DB_active_record extends CI_DB_driver { { if ($this->db_debug) { - //No valid data array. Folds in cases where keys and values did not match up + //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; @@ -1124,7 +1124,7 @@ class CI_DB_active_record extends CI_DB_driver { // -------------------------------------------------------------------- /** - * The "set_insert_batch" function. Allows key/value pairs to be set for batch inserts + * The "set_insert_batch" function. Allows key/value pairs to be set for batch inserts * * @access public * @param mixed @@ -1158,7 +1158,7 @@ class CI_DB_active_record extends CI_DB_driver { if ($escape === FALSE) { - $this->ar_set[] = '('.implode(',', $row).')'; + $this->ar_set[] = '('.implode(',', $row).')'; } else { @@ -1169,7 +1169,7 @@ class CI_DB_active_record extends CI_DB_driver { $clean[] = $this->escape($value); } - $this->ar_set[] = '('.implode(',', $clean).')'; + $this->ar_set[] = '('.implode(',', $clean).')'; } } @@ -1399,7 +1399,7 @@ class CI_DB_active_record extends CI_DB_driver { // -------------------------------------------------------------------- /** - * The "set_update_batch" function. Allows key/value pairs to be set for batch updating + * The "set_update_batch" function. Allows key/value pairs to be set for batch updating * * @access public * @param array @@ -1652,7 +1652,7 @@ class CI_DB_active_record extends CI_DB_driver { return; } - // Does the string contain a comma? If so, we need to separate + // Does the string contain a comma? If so, we need to separate // the string into discreet statements if (strpos($table, ',') !== FALSE) { @@ -1682,7 +1682,7 @@ class CI_DB_active_record extends CI_DB_driver { * Compile the SELECT statement * * Generates a query string based on which functions were used. - * Should not be called directly. The get() function calls it. + * Should not be called directly. The get() function calls it. * * @access private * @return string @@ -1989,7 +1989,7 @@ class CI_DB_active_record extends CI_DB_driver { // -------------------------------------------------------------------- /** - * Resets the active record values. Called by the get() function + * Resets the active record values. Called by the get() function * * @access private * @param array An array of fields to reset @@ -2009,7 +2009,7 @@ class CI_DB_active_record extends CI_DB_driver { // -------------------------------------------------------------------- /** - * Resets the active record values. Called by the get() function + * Resets the active record values. Called by the get() function * * @access private * @return void diff --git a/system/database/DB_cache.php b/system/database/DB_cache.php index 3249e9d8e..3bf065ca5 100644 --- a/system/database/DB_cache.php +++ b/system/database/DB_cache.php @@ -1,4 +1,4 @@ -CI->uri->segment(1) == FALSE) ? 'default' : $this->CI->uri->segment(1); + $segment_one = ($this->CI->uri->segment(1) == FALSE) ? 'default' : $this->CI->uri->segment(1); } if ($segment_two == '') diff --git a/system/database/DB_driver.php b/system/database/DB_driver.php index 40be2f903..10e8ed0c0 100644 --- a/system/database/DB_driver.php +++ b/system/database/DB_driver.php @@ -1,4 +1,4 @@ -conn_id = ($this->pconnect == FALSE) ? $this->db_connect() : $this->db_pconnect(); - // No connection resource? Throw an error + // No connection resource? Throw an error if ( ! $this->conn_id) { log_message('error', 'Unable to connect to the database'); @@ -199,7 +199,7 @@ class CI_DB_driver { // -------------------------------------------------------------------- /** - * Database Version Number. Returns a string containing the + * Database Version Number. Returns a string containing the * version of the database being used * * @access public @@ -237,7 +237,7 @@ class CI_DB_driver { * Execute the query * * Accepts an SQL string as input and returns a result object upon - * successful execution of a "read" type query. Returns boolean TRUE + * successful execution of a "read" type query. Returns boolean TRUE * upon successful execution of a "write" type query. Returns boolean * FALSE upon failure, and if the $db_debug variable is set to TRUE * will raise an error. @@ -265,7 +265,7 @@ class CI_DB_driver { $sql = preg_replace("/(\W)".$this->swap_pre."(\S+?)/", "\\1".$this->dbprefix."\\2", $sql); } - // Is query caching enabled? If the query is a "read type" + // 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')) @@ -286,7 +286,7 @@ class CI_DB_driver { $sql = $this->compile_binds($sql, $binds); } - // Save the query for debugging + // Save the query for debugging if ($this->save_queries == TRUE) { $this->queries[] = $sql; @@ -314,7 +314,7 @@ class CI_DB_driver { $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 + // 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(); @@ -385,7 +385,7 @@ class CI_DB_driver { // oci8 vars must be set before calling this $RES->num_rows = $RES->num_rows(); - // Is query caching enabled? If so, we'll serialize the + // 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()) { @@ -435,7 +435,7 @@ class CI_DB_driver { /** * Simple Query - * This is a simplified version of the query() function. Internally + * This is a simplified version of the query() function. Internally * we only use it when running transaction commands since they do * not require all the features of the main query() function. * @@ -718,7 +718,7 @@ class CI_DB_driver { /** * Primary * - * Retrieves the primary key. It assumes that the row in the first + * Retrieves the primary key. It assumes that the row in the first * position is the primary key * * @access public @@ -1216,8 +1216,8 @@ class CI_DB_driver { * 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: + * 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 * @@ -1270,7 +1270,7 @@ class CI_DB_driver { // This is basically a bug fix for queries that use MAX, MIN, etc. // If a parenthesis is found we know that we do not need to - // escape the data or add a prefix. There's probably a more graceful + // escape the data or add a prefix. There's probably a more graceful // way to deal with this, but I'm not thinking of it -- Rick if (strpos($item, '(') !== FALSE) { @@ -1285,7 +1285,7 @@ class CI_DB_driver { $parts = explode('.', $item); // Does the first segment of the exploded item match - // one of the aliases previously identified? If so, + // one of the aliases previously identified? If so, // we have nothing more to do other than escape the item if (in_array($parts[0], $this->ar_aliased_tables)) { @@ -1304,7 +1304,7 @@ class CI_DB_driver { return $item.$alias; } - // Is there a table prefix defined in the config file? If not, no need to do anything + // Is there a table prefix defined in the config file? If not, no need to do anything if ($this->dbprefix != '') { // We now add the table prefix based on some logic. @@ -1358,7 +1358,7 @@ class CI_DB_driver { return $item.$alias; } - // Is there a table prefix? If not, no need to insert it + // Is there a table prefix? If not, no need to insert it if ($this->dbprefix != '') { // Verify table prefix and replace if necessary diff --git a/system/database/DB_forge.php b/system/database/DB_forge.php index 9730c7761..a71fca78f 100644 --- a/system/database/DB_forge.php +++ b/system/database/DB_forge.php @@ -1,4 +1,4 @@ -result_array(); - else if ($type == 'object') return $this->result_object(); - else return $this->custom_result_object($type); + if ($type == 'array') return $this->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 - */ - 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(); + /** + * Custom query result. + * + * @param class_name A string that represents the type of object you want back + * @return array of objects + */ + 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; - } + { + $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; - } + // return the array + return $this->custom_result_object[$class_name] = $result_object; + } /** - * Query result. "object" version. + * Query result. "object" version. * * @access public * @return object @@ -122,7 +122,7 @@ class CI_DB_result { // -------------------------------------------------------------------- /** - * Query result. "array" version. + * Query result. "array" version. * * @access public * @return array @@ -154,7 +154,7 @@ class CI_DB_result { // -------------------------------------------------------------------- /** - * Query result. Acts as a wrapper function for the following functions. + * Query result. Acts as a wrapper function for the following functions. * * @access public * @param string @@ -180,9 +180,9 @@ class CI_DB_result { $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); + 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); } // -------------------------------------------------------------------- @@ -219,7 +219,7 @@ class CI_DB_result { // -------------------------------------------------------------------- - /** + /** * Returns a single result row - custom object version * * @access public @@ -242,7 +242,7 @@ class CI_DB_result { return $result[$this->current_row]; } - /** + /** * Returns a single result row - object version * * @access public @@ -383,9 +383,9 @@ class CI_DB_result { /** * 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. + * 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 + * 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. */ diff --git a/system/database/DB_utility.php b/system/database/DB_utility.php index a3c00a5a6..a5f174f0a 100644 --- a/system/database/DB_utility.php +++ b/system/database/DB_utility.php @@ -1,4 +1,4 @@ -db->db_debug) { diff --git a/system/database/drivers/mssql/mssql_driver.php b/system/database/drivers/mssql/mssql_driver.php index 56ecf32d1..65397ed8f 100644 --- a/system/database/drivers/mssql/mssql_driver.php +++ b/system/database/drivers/mssql/mssql_driver.php @@ -1,4 +1,4 @@ -db->_protect_identifiers($field); - $sql .= ' '.$attributes['TYPE']; + $sql .= ' '.$attributes['TYPE']; if (array_key_exists('CONSTRAINT', $attributes)) { diff --git a/system/database/drivers/mssql/mssql_result.php b/system/database/drivers/mssql/mssql_result.php index f1f6dbb84..2897ca5a5 100644 --- a/system/database/drivers/mssql/mssql_result.php +++ b/system/database/drivers/mssql/mssql_result.php @@ -1,4 +1,4 @@ -= 5.2.3 and MySQL >= 5.0.7, use SET NAMES as fallback @@ -302,12 +302,12 @@ class CI_DB_mysql_driver extends CI_DB { if (is_array($str)) { foreach ($str as $key => $val) - { + { $str[$key] = $this->escape_str($val, $like); - } + } - return $str; - } + return $str; + } if (function_exists('mysql_real_escape_string') AND is_resource($this->conn_id)) { @@ -650,7 +650,7 @@ class CI_DB_mysql_driver extends CI_DB { { if ($field != $index) { - $final[$field][] = 'WHEN '.$index.' = '.$val[$index].' THEN '.$val[$field]; + $final[$field][] = 'WHEN '.$index.' = '.$val[$index].' THEN '.$val[$field]; } } } diff --git a/system/database/drivers/mysql/mysql_forge.php b/system/database/drivers/mysql/mysql_forge.php index 5328a7b4e..529ec980d 100644 --- a/system/database/drivers/mysql/mysql_forge.php +++ b/system/database/drivers/mysql/mysql_forge.php @@ -1,4 +1,4 @@ -= 5.0.7, use SET NAMES as fallback @@ -568,7 +568,7 @@ class CI_DB_mysqli_driver extends CI_DB { { return "INSERT INTO ".$table." (".implode(', ', $keys).") VALUES ".implode(', ', $values); } - + // -------------------------------------------------------------------- /** @@ -630,7 +630,7 @@ class CI_DB_mysqli_driver extends CI_DB { { if ($field != $index) { - $final[$field][] = 'WHEN '.$index.' = '.$val[$index].' THEN '.$val[$field]; + $final[$field][] = 'WHEN '.$index.' = '.$val[$index].' THEN '.$val[$field]; } } } diff --git a/system/database/drivers/mysqli/mysqli_forge.php b/system/database/drivers/mysqli/mysqli_forge.php index 6450968dd..d5097335e 100644 --- a/system/database/drivers/mysqli/mysqli_forge.php +++ b/system/database/drivers/mysqli/mysqli_forge.php @@ -1,4 +1,4 @@ - format - * value no the value of the parameter. If this is an OUT or IN OUT parameter, + * 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 @@ -275,8 +275,8 @@ class CI_DB_oci8_driver extends CI_DB { /** * Bind parameters * - * @access private - * @return none + * @access private + * @return none */ function _bind_params($params) { @@ -386,10 +386,10 @@ class CI_DB_oci8_driver extends CI_DB { /** * Escape String * - * @access public - * @param string + * @access public + * @param string * @param bool whether or not the string will be used in a LIKE condition - * @return string + * @return string */ function escape_str($str, $like = FALSE) { @@ -421,8 +421,8 @@ class CI_DB_oci8_driver extends CI_DB { /** * Affected Rows * - * @access public - * @return integer + * @access public + * @return integer */ function affected_rows() { @@ -434,8 +434,8 @@ class CI_DB_oci8_driver extends CI_DB { /** * Insert ID * - * @access public - * @return integer + * @access public + * @return integer */ function insert_id() { @@ -451,9 +451,9 @@ class CI_DB_oci8_driver extends CI_DB { * Generates a platform-specific query string that counts all records in * the specified database * - * @access public - * @param string - * @return string + * @access public + * @param string + * @return string */ function count_all($table = '') { @@ -480,9 +480,9 @@ class CI_DB_oci8_driver extends CI_DB { * * Generates a platform-specific query string so that the table names can be fetched * - * @access private + * @access private * @param boolean - * @return string + * @return string */ function _list_tables($prefix_limit = FALSE) { @@ -503,9 +503,9 @@ class CI_DB_oci8_driver extends CI_DB { * * Generates a platform-specific query string so that the column names can be fetched * - * @access public - * @param string the table name - * @return string + * @access public + * @param string the table name + * @return string */ function _list_columns($table = '') { @@ -519,9 +519,9 @@ class CI_DB_oci8_driver extends CI_DB { * * Generates a platform-specific query so that the column data can be retrieved * - * @access public - * @param string the table name - * @return object + * @access public + * @param string the table name + * @return object */ function _field_data($table) { @@ -533,8 +533,8 @@ class CI_DB_oci8_driver extends CI_DB { /** * The error message string * - * @access private - * @return string + * @access private + * @return string */ function _error_message() { @@ -547,8 +547,8 @@ class CI_DB_oci8_driver extends CI_DB { /** * The error message number * - * @access private - * @return integer + * @access private + * @return integer */ function _error_number() { @@ -627,11 +627,11 @@ class CI_DB_oci8_driver extends CI_DB { * * Generates a platform-specific insert string from the supplied data * - * @access public - * @param string the table name - * @param array the insert keys - * @param array the insert values - * @return string + * @access public + * @param string the table name + * @param array the insert keys + * @param array the insert values + * @return string */ function _insert($table, $keys, $values) { @@ -732,11 +732,11 @@ class CI_DB_oci8_driver extends CI_DB { * * Generates a platform-specific LIMIT clause * - * @access public - * @param string the sql query string - * @param integer the number of rows to limit the query to - * @param integer the offset value - * @return string + * @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) { @@ -759,9 +759,9 @@ class CI_DB_oci8_driver extends CI_DB { /** * Close DB Connection * - * @access public - * @param resource - * @return void + * @access public + * @param resource + * @return void */ function _close($conn_id) { diff --git a/system/database/drivers/oci8/oci8_forge.php b/system/database/drivers/oci8/oci8_forge.php index 589e3c29d..3cd17585a 100644 --- a/system/database/drivers/oci8/oci8_forge.php +++ b/system/database/drivers/oci8/oci8_forge.php @@ -1,4 +1,4 @@ -db->_protect_identifiers($field); - $sql .= ' '.$attributes['TYPE']; + $sql .= ' '.$attributes['TYPE']; if (array_key_exists('CONSTRAINT', $attributes)) { diff --git a/system/database/drivers/oci8/oci8_result.php b/system/database/drivers/oci8/oci8_result.php index 60d8396ef..88531b436 100644 --- a/system/database/drivers/oci8/oci8_result.php +++ b/system/database/drivers/oci8/oci8_result.php @@ -1,4 +1,4 @@ -name = ocicolumnname($this->stmt_id, $c); $F->type = ocicolumntype($this->stmt_id, $c); - $F->max_length = ocicolumnsize($this->stmt_id, $c); + $F->max_length = ocicolumnsize($this->stmt_id, $c); $retval[] = $F; } @@ -145,8 +145,8 @@ class CI_DB_oci8_result extends CI_DB_result { * * Returns the result set as an array * - * @access private - * @return array + * @access private + * @return array */ function _fetch_assoc(&$row) { @@ -162,8 +162,8 @@ class CI_DB_oci8_result extends CI_DB_result { * * Returns the result set as an object * - * @access private - * @return object + * @access private + * @return object */ function _fetch_object() { @@ -202,10 +202,10 @@ class CI_DB_oci8_result extends CI_DB_result { // -------------------------------------------------------------------- /** - * Query result. "array" version. + * Query result. "array" version. * - * @access public - * @return array + * @access public + * @return array */ function result_array() { @@ -230,7 +230,7 @@ class CI_DB_oci8_result extends CI_DB_result { /** * Data Seek * - * Moves the internal pointer to the desired offset. We call + * Moves the internal pointer to the desired offset. We call * this internally before fetching results to make sure the * result set starts at zero * diff --git a/system/database/drivers/oci8/oci8_utility.php b/system/database/drivers/oci8/oci8_utility.php index f1fe5dc00..854b467e1 100644 --- a/system/database/drivers/oci8/oci8_utility.php +++ b/system/database/drivers/oci8/oci8_utility.php @@ -1,4 +1,4 @@ -db->_protect_identifiers($field); - $sql .= ' '.$attributes['TYPE']; + $sql .= ' '.$attributes['TYPE']; if (array_key_exists('CONSTRAINT', $attributes)) { diff --git a/system/database/drivers/odbc/odbc_result.php b/system/database/drivers/odbc/odbc_result.php index d83b2e5f0..5d64a464f 100644 --- a/system/database/drivers/odbc/odbc_result.php +++ b/system/database/drivers/odbc/odbc_result.php @@ -1,4 +1,4 @@ -db->_protect_identifiers($field); - $sql .= ' '.$attributes['TYPE']; + $sql .= ' '.$attributes['TYPE']; if (array_key_exists('CONSTRAINT', $attributes)) { @@ -172,7 +172,7 @@ class CI_DB_sqlite_forge extends CI_DB_forge { /** * Drop Table * - * Unsupported feature in SQLite + * Unsupported feature in SQLite * * @access private * @return bool diff --git a/system/database/drivers/sqlite/sqlite_result.php b/system/database/drivers/sqlite/sqlite_result.php index 62204946c..7bd30db7c 100644 --- a/system/database/drivers/sqlite/sqlite_result.php +++ b/system/database/drivers/sqlite/sqlite_result.php @@ -1,4 +1,4 @@ -text. To close fieldset + * Used to produce
    text. To close fieldset * use form_fieldset_close() * * @access public @@ -663,7 +663,7 @@ if ( ! function_exists('form_prep')) * 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 + * re-populate an input field or textarea. If Form Validation * is active it retrieves the info from the validation class * * @access public @@ -858,7 +858,7 @@ if ( ! function_exists('set_radio')) /** * Form Error * - * Returns the error for a specific form field. This is a helper for the + * Returns the error for a specific form field. This is a helper for the * form validation class. * * @access public @@ -885,7 +885,7 @@ if ( ! function_exists('form_error')) /** * Validation Error String * - * Returns all the errors associated with a form submission. This is a helper + * Returns all the errors associated with a form submission. This is a helper * function for the form validation class. * * @access public @@ -1034,17 +1034,17 @@ if ( ! function_exists('_get_validation_object')) // 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; } } diff --git a/system/helpers/html_helper.php b/system/helpers/html_helper.php index bd66bc2d0..080f622dd 100644 --- a/system/helpers/html_helper.php +++ b/system/helpers/html_helper.php @@ -1,4 +1,4 @@ -\n"; - // Cycle through the list elements. If an array is + // Cycle through the list elements. If an array is // encountered we will recursively call _list() static $_last_list_item = ''; @@ -244,7 +244,7 @@ if ( ! function_exists('img')) * 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 + * html4-strict, html4-trans, and html4-frame. Values are saved in the * doctypes config file. * * @access public diff --git a/system/helpers/inflector_helper.php b/system/helpers/inflector_helper.php index 2352b642e..c7c113b8a 100644 --- a/system/helpers/inflector_helper.php +++ b/system/helpers/inflector_helper.php @@ -1,4 +1,4 @@ -'), array('<?php', '<?PHP', '<?', '?>'), $str); + return str_replace(array(''), array('<?php', '<?PHP', '<?', '?>'), $str); } } diff --git a/system/helpers/smiley_helper.php b/system/helpers/smiley_helper.php index 22ca4df77..6d8889354 100644 --- a/system/helpers/smiley_helper.php +++ b/system/helpers/smiley_helper.php @@ -1,4 +1,4 @@ - $val) { // Keep duplicates from being used, which can happen if the - // mapping array contains multiple identical replacements. For example: + // 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]])) @@ -204,7 +204,7 @@ if ( ! function_exists('parse_smileys')) } // Add a trailing slash to the file path if needed - $image_url = preg_replace("/(.+?)\/*$/", "\\1/", $image_url); + $image_url = preg_replace("/(.+?)\/*$/", "\\1/", $image_url); foreach ($smileys as $key => $val) { @@ -231,13 +231,13 @@ if ( ! function_exists('_get_smiley_array')) { if (defined('ENVIRONMENT') AND file_exists(APPPATH.'config/'.ENVIRONMENT.'/smileys.php')) { - include(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; diff --git a/system/helpers/string_helper.php b/system/helpers/string_helper.php index 9f730bd10..7765bba31 100644 --- a/system/helpers/string_helper.php +++ b/system/helpers/string_helper.php @@ -1,4 +1,4 @@ - $val) { - $x[] = ' '.$key.'="'; + $x[] = ' '.$key.'="'; for ($i = 0; $i < strlen($val); $i++) { $x[] = "|".ord(substr($val, $i, 1)); @@ -363,7 +363,7 @@ if ( ! function_exists('safe_mailto')) * * 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 + * URLs or emails that end in a period. We'll strip these * off and add them after the link. * * @access public diff --git a/system/helpers/xml_helper.php b/system/helpers/xml_helper.php index 2219d662a..cdd81ad70 100644 --- a/system/helpers/xml_helper.php +++ b/system/helpers/xml_helper.php @@ -1,4 +1,4 @@ -","\"", "'", "-"), diff --git a/system/language/english/email_lang.php b/system/language/english/email_lang.php index fe4276822..e3bd113cb 100644 --- a/system/language/english/email_lang.php +++ b/system/language/english/email_lang.php @@ -5,9 +5,9 @@ $lang['email_invalid_address'] = "Invalid email address: %s"; $lang['email_attachment_missing'] = "Unable to locate the following email attachment: %s"; $lang['email_attachment_unreadable'] = "Unable to open this attachment: %s"; $lang['email_no_recipients'] = "You must include recipients: To, Cc, or Bcc"; -$lang['email_send_failure_phpmail'] = "Unable to send email using PHP mail(). Your server might not be configured to send mail using this method."; -$lang['email_send_failure_sendmail'] = "Unable to send email using PHP Sendmail. Your server might not be configured to send mail using this method."; -$lang['email_send_failure_smtp'] = "Unable to send email using PHP SMTP. Your server might not be configured to send mail using this method."; +$lang['email_send_failure_phpmail'] = "Unable to send email using PHP mail(). Your server might not be configured to send mail using this method."; +$lang['email_send_failure_sendmail'] = "Unable to send email using PHP Sendmail. Your server might not be configured to send mail using this method."; +$lang['email_send_failure_smtp'] = "Unable to send email using PHP SMTP. Your server might not be configured to send mail using this method."; $lang['email_sent'] = "Your message has been successfully sent using the following protocol: %s"; $lang['email_no_socket'] = "Unable to open a socket to Sendmail. Please check settings."; $lang['email_no_hostname'] = "You did not specify a SMTP hostname."; diff --git a/system/language/english/imglib_lang.php b/system/language/english/imglib_lang.php index 0a56fe0a5..66505da07 100644 --- a/system/language/english/imglib_lang.php +++ b/system/language/english/imglib_lang.php @@ -4,20 +4,20 @@ $lang['imglib_source_image_required'] = "You must specify a source image in your $lang['imglib_gd_required'] = "The GD image library is required for this feature."; $lang['imglib_gd_required_for_props'] = "Your server must support the GD image library in order to determine the image properties."; $lang['imglib_unsupported_imagecreate'] = "Your server does not support the GD function required to process this type of image."; -$lang['imglib_gif_not_supported'] = "GIF images are often not supported due to licensing restrictions. You may have to use JPG or PNG images instead."; +$lang['imglib_gif_not_supported'] = "GIF images are often not supported due to licensing restrictions. You may have to use JPG or PNG images instead."; $lang['imglib_jpg_not_supported'] = "JPG images are not supported."; $lang['imglib_png_not_supported'] = "PNG images are not supported."; $lang['imglib_jpg_or_png_required'] = "The image resize protocol specified in your preferences only works with JPEG or PNG image types."; -$lang['imglib_copy_error'] = "An error was encountered while attempting to replace the file. Please make sure your file directory is writable."; +$lang['imglib_copy_error'] = "An error was encountered while attempting to replace the file. Please make sure your file directory is writable."; $lang['imglib_rotate_unsupported'] = "Image rotation does not appear to be supported by your server."; -$lang['imglib_libpath_invalid'] = "The path to your image library is not correct. Please set the correct path in your image preferences."; -$lang['imglib_image_process_failed'] = "Image processing failed. Please verify that your server supports the chosen protocol and that the path to your image library is correct."; +$lang['imglib_libpath_invalid'] = "The path to your image library is not correct. Please set the correct path in your image preferences."; +$lang['imglib_image_process_failed'] = "Image processing failed. Please verify that your server supports the chosen protocol and that the path to your image library is correct."; $lang['imglib_rotation_angle_required'] = "An angle of rotation is required to rotate the image."; $lang['imglib_writing_failed_gif'] = "GIF image."; $lang['imglib_invalid_path'] = "The path to the image is not correct."; $lang['imglib_copy_failed'] = "The image copy routine failed."; $lang['imglib_missing_font'] = "Unable to find a font to use."; -$lang['imglib_save_failed'] = "Unable to save the image. Please make sure the image and file directory are writable."; +$lang['imglib_save_failed'] = "Unable to save the image. Please make sure the image and file directory are writable."; /* End of file imglib_lang.php */ diff --git a/system/libraries/Cache/Cache.php b/system/libraries/Cache/Cache.php index 938c80857..61e7aa761 100644 --- a/system/libraries/Cache/Cache.php +++ b/system/libraries/Cache/Cache.php @@ -10,22 +10,22 @@ * @license http://codeigniter.com/user_guide/license.html * @link http://codeigniter.com * @since Version 2.0 - * @filesource + * @filesource */ // ------------------------------------------------------------------------ /** - * CodeIgniter Caching Class + * CodeIgniter Caching Class * * @package CodeIgniter * @subpackage Libraries * @category Core * @author ExpressionEngine Dev Team - * @link + * @link */ class CI_Cache extends CI_Driver_Library { - + protected $valid_drivers = array( 'cache_apc', 'cache_file', 'cache_memcached', 'cache_dummy' ); @@ -33,7 +33,7 @@ class CI_Cache extends CI_Driver_Library { protected $_cache_path = NULL; // Path of cache files (if file-based cache) protected $_adapter = 'dummy'; protected $_backup_driver; - + // ------------------------------------------------------------------------ /** @@ -52,16 +52,16 @@ class CI_Cache extends CI_Driver_Library { // ------------------------------------------------------------------------ /** - * Get + * Get * - * Look for a value in the cache. If it exists, return the data + * Look for a value in the cache. If it exists, return the data * if not, return FALSE * - * @param string + * @param string * @return mixed value that is stored/FALSE on failure */ public function get($id) - { + { return $this->{$this->_adapter}->get($id); } @@ -112,7 +112,7 @@ class CI_Cache extends CI_Driver_Library { * Cache Info * * @param string user/filehits - * @return mixed array on success, false on failure + * @return mixed array on success, false on failure */ public function cache_info($type = 'user') { @@ -120,7 +120,7 @@ class CI_Cache extends CI_Driver_Library { } // ------------------------------------------------------------------------ - + /** * Get Cache Metadata * @@ -131,7 +131,7 @@ class CI_Cache extends CI_Driver_Library { { return $this->{$this->_adapter}->get_metadata($id); } - + // ------------------------------------------------------------------------ /** @@ -139,11 +139,11 @@ class CI_Cache extends CI_Driver_Library { * * Initialize class properties based on the configuration array. * - * @param array + * @param array * @return void */ private function _initialize($config) - { + { $default_config = array( 'adapter', 'memcached' @@ -207,7 +207,7 @@ class CI_Cache extends CI_Driver_Library { return $obj; } - + // ------------------------------------------------------------------------ } // End Class diff --git a/system/libraries/Cache/drivers/Cache_apc.php b/system/libraries/Cache/drivers/Cache_apc.php index ea129eded..de75719c4 100644 --- a/system/libraries/Cache/drivers/Cache_apc.php +++ b/system/libraries/Cache/drivers/Cache_apc.php @@ -10,30 +10,30 @@ * @license http://codeigniter.com/user_guide/license.html * @link http://codeigniter.com * @since Version 2.0 - * @filesource + * @filesource */ // ------------------------------------------------------------------------ /** - * CodeIgniter APC Caching Class + * CodeIgniter APC Caching Class * * @package CodeIgniter * @subpackage Libraries * @category Core * @author ExpressionEngine Dev Team - * @link + * @link */ class CI_Cache_apc extends CI_Driver { /** - * Get + * Get * - * Look for a value in the cache. If it exists, return the data + * Look for a value in the cache. If it exists, return the data * if not, return FALSE * - * @param string + * @param string * @return mixed value that is stored/FALSE on failure */ public function get($id) @@ -43,8 +43,8 @@ class CI_Cache_apc extends CI_Driver { return (is_array($data)) ? $data[0] : FALSE; } - // ------------------------------------------------------------------------ - + // ------------------------------------------------------------------------ + /** * Cache Save * @@ -58,7 +58,7 @@ class CI_Cache_apc extends CI_Driver { { return apc_store($id, array($data, time(), $ttl), $ttl); } - + // ------------------------------------------------------------------------ /** @@ -90,7 +90,7 @@ class CI_Cache_apc extends CI_Driver { * Cache Info * * @param string user/filehits - * @return mixed array on success, false on failure + * @return mixed array on success, false on failure */ public function cache_info($type = NULL) { @@ -137,13 +137,13 @@ class CI_Cache_apc extends CI_Driver { log_message('error', 'The APC PHP extension must be loaded to use APC Cache.'); return FALSE; } - + return TRUE; } // ------------------------------------------------------------------------ - + } // End Class diff --git a/system/libraries/Cache/drivers/Cache_file.php b/system/libraries/Cache/drivers/Cache_file.php index 39dcd15c2..13e2d1af6 100644 --- a/system/libraries/Cache/drivers/Cache_file.php +++ b/system/libraries/Cache/drivers/Cache_file.php @@ -10,19 +10,19 @@ * @license http://codeigniter.com/user_guide/license.html * @link http://codeigniter.com * @since Version 2.0 - * @filesource + * @filesource */ // ------------------------------------------------------------------------ /** - * CodeIgniter Memcached Caching Class + * CodeIgniter Memcached Caching Class * * @package CodeIgniter * @subpackage Libraries * @category Core * @author ExpressionEngine Dev Team - * @link + * @link */ class CI_Cache_file extends CI_Driver { @@ -36,9 +36,9 @@ class CI_Cache_file extends CI_Driver { { $CI =& get_instance(); $CI->load->helper('file'); - + $path = $CI->config->item('cache_path'); - + $this->_cache_path = ($path == '') ? APPPATH.'cache/' : $path; } @@ -56,16 +56,16 @@ class CI_Cache_file extends CI_Driver { { return FALSE; } - + $data = read_file($this->_cache_path.$id); $data = unserialize($data); - - if (time() > $data['time'] + $data['ttl']) + + if (time() > $data['time'] + $data['ttl']) { unlink($this->_cache_path.$id); return FALSE; } - + return $data['data']; } @@ -76,22 +76,22 @@ class CI_Cache_file extends CI_Driver { * * @param string unique key * @param mixed data to store - * @param int length of time (in seconds) the cache is valid + * @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, + 'ttl' => $ttl, 'data' => $data ); - + if (write_file($this->_cache_path.$id, serialize($contents))) { @chmod($this->_cache_path.$id, 0777); - return TRUE; + return TRUE; } return FALSE; @@ -116,7 +116,7 @@ class CI_Cache_file extends CI_Driver { * Clean the Cache * * @return boolean false on failure/true on success - */ + */ public function clean() { return delete_files($this->_cache_path); @@ -151,10 +151,10 @@ class CI_Cache_file extends CI_Driver { { return FALSE; } - - $data = read_file($this->_cache_path.$id); + + $data = read_file($this->_cache_path.$id); $data = unserialize($data); - + if (is_array($data)) { $data = $data['data']; @@ -170,7 +170,7 @@ class CI_Cache_file extends CI_Driver { 'mtime' => $mtime ); } - + return FALSE; } @@ -180,7 +180,7 @@ class CI_Cache_file extends CI_Driver { * Is supported * * In the file driver, check to see that the cache directory is indeed writable - * + * * @return boolean */ public function is_supported() diff --git a/system/libraries/Calendar.php b/system/libraries/Calendar.php index 7dcbaab47..df0fd6eeb 100644 --- a/system/libraries/Calendar.php +++ b/system/libraries/Calendar.php @@ -1,4 +1,4 @@ -local_time); + $year = date("Y", $this->local_time); if ($month == '') $month = date("m", $this->local_time); @@ -128,7 +128,7 @@ class CI_Calendar { // Set the starting day number $local_date = mktime(12, 0, 0, $month, 1, $year); $date = getdate($local_date); - $day = $start_day + 1 - $date["wday"]; + $day = $start_day + 1 - $date["wday"]; while ($day > 1) { @@ -157,8 +157,8 @@ class CI_Calendar { // "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); + // 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']); @@ -233,7 +233,7 @@ class CI_Calendar { $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']; + $out .= ($is_current_month == TRUE AND $day == $cur_day) ? $this->temp['cal_cell_end_today'] : $this->temp['cal_cell_end']; $day++; } @@ -287,7 +287,7 @@ class CI_Calendar { * Get Day Names * * Returns an array of day names (Sunday, Monday, etc.) based - * on the type. Options: long, short, abrev + * on the type. Options: long, short, abrev * * @access public * @param string @@ -404,7 +404,7 @@ class CI_Calendar { */ function default_template() { - return array ( + return array ( 'table_open' => '
    ', 'heading_row_start' => '', 'heading_previous_cell' => '', @@ -451,7 +451,7 @@ class CI_Calendar { $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) + 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)) { diff --git a/system/libraries/Cart.php b/system/libraries/Cart.php index fbccfb3d9..7f65b48b9 100644 --- a/system/libraries/Cart.php +++ b/system/libraries/Cart.php @@ -1,4 +1,4 @@ -CI =& get_instance(); - // Are any config settings being passed manually? If so, set them + // Are any config settings being passed manually? If so, set them $config = array(); if (count($params) > 0) { @@ -148,7 +148,7 @@ class CI_Cart { // -------------------------------------------------------------------- - // Does the $items array contain an id, quantity, price, and name? These are required + // 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.'); @@ -157,7 +157,7 @@ class CI_Cart { // -------------------------------------------------------------------- - // Prep the quantity. It can only be a number. Duh... + // 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'])); @@ -175,7 +175,7 @@ class CI_Cart { // 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'); + log_message('error', 'Invalid product ID. The product ID can only contain alpha-numeric characters, dashes, and underscores'); return FALSE; } @@ -191,7 +191,7 @@ class CI_Cart { // -------------------------------------------------------------------- - // Prep the price. Remove anything that isn't a number or decimal point. + // 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'])); @@ -210,7 +210,7 @@ class CI_Cart { // 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 + // 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. @@ -271,7 +271,7 @@ class CI_Cart { } // You can either update a single product using a one-dimensional array, - // or multiple products using a multi-dimensional one. The way we + // 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; @@ -344,7 +344,7 @@ class CI_Cart { return FALSE; } - // Is the quantity zero? If so we will remove the item from the cart. + // 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) { @@ -392,7 +392,7 @@ class CI_Cart { $this->_cart_contents['total_items'] = count($this->_cart_contents); $this->_cart_contents['cart_total'] = $total; - // Is our cart empty? If so we delete it from the session + // Is our cart empty? If so we delete it from the session if (count($this->_cart_contents) <= 2) { $this->CI->session->unset_userdata('cart_contents'); diff --git a/system/libraries/Driver.php b/system/libraries/Driver.php index b90b5aba6..d1925c0ec 100644 --- a/system/libraries/Driver.php +++ b/system/libraries/Driver.php @@ -1,4 +1,4 @@ -_attach_name[] = $filename; $this->_attach_type[] = $this->_mime_types(next(explode('.', basename($filename)))); - $this->_attach_disp[] = $disposition; // Can also be 'inline' Not sure if it matters + $this->_attach_disp[] = $disposition; // Can also be 'inline' Not sure if it matters return $this; } @@ -600,7 +600,7 @@ class CI_Email { $from = str_replace(">", "", $from); $from = str_replace("<", "", $from); - return "<".uniqid('').strstr($from, '@').">"; + return "<".uniqid('').strstr($from, '@').">"; } // -------------------------------------------------------------------- @@ -660,15 +660,15 @@ class CI_Email { */ private function _get_content_type() { - if ($this->mailtype == 'html' && count($this->_attach_name) == 0) + if ($this->mailtype == 'html' && count($this->_attach_name) == 0) { return 'html'; } - elseif ($this->mailtype == 'html' && count($this->_attach_name) > 0) + elseif ($this->mailtype == 'html' && count($this->_attach_name) > 0) { return 'html-attach'; } - elseif ($this->mailtype == 'text' && count($this->_attach_name) > 0) + elseif ($this->mailtype == 'text' && count($this->_attach_name) > 0) { return 'plain-attach'; } @@ -881,7 +881,7 @@ class CI_Email { // Use PHP's native public function to do the initial wordwrap. // We set the cut flag to FALSE so that any individual words that are - // too long get left alone. In the next step we'll deal with them. + // too long get left alone. In the next step we'll deal with them. $str = wordwrap($str, $charlim, "\n", FALSE); // Split the string into individual lines of text and cycle through them @@ -999,7 +999,7 @@ class CI_Email { */ private function _build_message() { - if ($this->wordwrap === TRUE AND $this->mailtype != 'html') + if ($this->wordwrap === TRUE AND $this->mailtype != 'html') { $this->_body = $this->word_wrap($this->_body); } @@ -1135,7 +1135,7 @@ class CI_Email { return FALSE; } - $h = "--".$this->_atc_boundary.$this->newline; + $h = "--".$this->_atc_boundary.$this->newline; $h .= "Content-type: ".$ctype."; "; $h .= "name=\"".$basename."\"".$this->newline; $h .= "Content-Disposition: ".$this->_attach_disp[$i].";".$this->newline; @@ -1237,7 +1237,7 @@ class CI_Email { // encode = signs if ($ascii == '61') { - $char = $escape.strtoupper(sprintf('%02s', dechex($ascii))); // =3D + $char = $escape.strtoupper(sprintf('%02s', dechex($ascii))); // =3D } // If we're at the character limit, add the line to the output, @@ -1267,7 +1267,7 @@ class CI_Email { /** * Prep Q Encoding * - * Performs "Q Encoding" on a string for use in email headers. It's related + * Performs "Q Encoding" on a string for use in email headers. It's related * but not identical to quoted-printable, so it has its own method * * @access public @@ -1349,7 +1349,7 @@ class CI_Email { $this->reply_to($this->_headers['From']); } - if (( ! isset($this->_recipients) AND ! isset($this->_headers['To'])) AND + if (( ! isset($this->_recipients) AND ! isset($this->_headers['To'])) AND ( ! isset($this->_bcc_array) AND ! isset($this->_headers['Bcc'])) AND ( ! isset($this->_headers['Cc']))) { @@ -1359,7 +1359,7 @@ class CI_Email { $this->_build_headers(); - if ($this->bcc_batch_mode AND count($this->_bcc_array) > 0) + if ($this->bcc_batch_mode AND count($this->_bcc_array) > 0) { if (count($this->_bcc_array) > $this->bcc_batch_size) return $this->batch_bcc_send(); @@ -1380,7 +1380,7 @@ class CI_Email { // -------------------------------------------------------------------- /** - * Batch Bcc Send. Sends groups of BCCs in batches + * Batch Bcc Send. Sends groups of BCCs in batches * * @access public * @return bool @@ -1752,7 +1752,7 @@ class CI_Email { // -------------------------------------------------------------------- /** - * SMTP Authenticate + * SMTP Authenticate * * @access private * @return bool @@ -1764,7 +1764,7 @@ class CI_Email { return TRUE; } - if ($this->smtp_user == "" AND $this->smtp_pass == "") + if ($this->smtp_user == "" AND $this->smtp_pass == "") { $this->_set_error_message('lang:email_no_smtp_unpw'); return FALSE; diff --git a/system/libraries/Encrypt.php b/system/libraries/Encrypt.php index 2f7db6623..b30a8cf0b 100644 --- a/system/libraries/Encrypt.php +++ b/system/libraries/Encrypt.php @@ -1,4 +1,4 @@ -_field_data) == 0) { - // No validation rules? We're done... + // No validation rules? We're done... if (count($this->_config_rules) == 0) { return FALSE; @@ -648,7 +648,7 @@ class CI_Form_validation { } } - // Did the rule test negatively? If so, grab the error. + // Did the rule test negatively? If so, grab the error. if ($result === FALSE) { if ( ! isset($this->_error_messages[$rule])) @@ -664,7 +664,7 @@ class CI_Form_validation { } // Is the parameter we are inserting into the error message the name - // of another field? If so we need to grab its "field label" + // of another field? If so we need to grab its "field label" if (isset($this->_field_data[$param]) AND isset($this->_field_data[$param]['label'])) { $param = $this->_translate_fieldname($this->_field_data[$param]['label']); @@ -704,7 +704,7 @@ class CI_Form_validation { // Grab the variable $line = substr($fieldname, 5); - // Were we able to translate the field name? If not we use $line + // Were we able to translate the field name? If not we use $line if (FALSE === ($fieldname = $this->CI->lang->line($line))) { return $line; @@ -735,7 +735,7 @@ class CI_Form_validation { } // If the data is an array output them one at a time. - // E.g: form_input('name[]', set_value('name[]'); + // E.g: form_input('name[]', set_value('name[]'); if (is_array($this->_field_data[$field]['postdata'])) { return array_shift($this->_field_data[$field]['postdata']); @@ -914,7 +914,7 @@ class CI_Form_validation { return FALSE; } - return TRUE; + return TRUE; } // -------------------------------------------------------------------- @@ -1207,7 +1207,7 @@ class CI_Form_validation { // -------------------------------------------------------------------- /** - * Is a Natural number (0,1,2,3, etc.) + * Is a Natural number (0,1,2,3, etc.) * * @access public * @param string @@ -1221,7 +1221,7 @@ class CI_Form_validation { // -------------------------------------------------------------------- /** - * Is a Natural number, but not a zero (1,2,3, etc.) + * Is a Natural number, but not a zero (1,2,3, etc.) * * @access public * @param string @@ -1354,7 +1354,7 @@ class CI_Form_validation { */ function encode_php_tags($str) { - return str_replace(array(''), array('<?php', '<?PHP', '<?', '?>'), $str); + return str_replace(array(''), array('<?php', '<?PHP', '<?', '?>'), $str); } } diff --git a/system/libraries/Ftp.php b/system/libraries/Ftp.php index 859cc9c30..d7a8b3b02 100644 --- a/system/libraries/Ftp.php +++ b/system/libraries/Ftp.php @@ -1,4 +1,4 @@ -list_files($filepath); @@ -513,7 +513,7 @@ class CI_FTP { * Read a directory and recreate it remotely * * This function recursively reads a folder and everything it contains (including - * sub-folders) and creates a mirror via FTP based on it. Whatever the directory structure + * sub-folders) and creates a mirror via FTP based on it. Whatever the directory structure * of the original file path will be recreated on the server. * * @access public diff --git a/system/libraries/Image_lib.php b/system/libraries/Image_lib.php index 099a238dd..8902f524d 100644 --- a/system/libraries/Image_lib.php +++ b/system/libraries/Image_lib.php @@ -1,4 +1,4 @@ -source_image == '') { $this->set_error('imglib_source_image_required'); - return FALSE; + return FALSE; } /* * Is getimagesize() Available? * * We use it to determine the image properties (width/height). - * Note: We need to figure out how to determine image + * Note: We need to figure out how to determine image * properties using ImageMagick and NetPBM * */ @@ -189,7 +189,7 @@ class CI_Image_lib { // Set the Image Properties if ( ! $this->get_image_properties($this->source_folder.$this->source_image)) { - return FALSE; + return FALSE; } /* @@ -197,7 +197,7 @@ class CI_Image_lib { * * If the user has set a "new_image" name it means * we are making a copy of the source image. If not - * it means we are altering the original. We'll + * it means we are altering the original. We'll * set the destination filename and path accordingly. * */ @@ -267,7 +267,7 @@ class CI_Image_lib { * * When creating thumbs or copies, the target width/height * might not be in correct proportion with the source - * image's width/height. We'll recalculate it here. + * image's width/height. We'll recalculate it here. * */ if ($this->maintain_ratio === TRUE && ($this->width != '' AND $this->height != '')) @@ -399,7 +399,7 @@ class CI_Image_lib { if ($this->rotation_angle == '' OR ! in_array($this->rotation_angle, $degs)) { $this->set_error('imglib_rotation_angle_required'); - return FALSE; + return FALSE; } // Reassign the width and height @@ -469,8 +469,8 @@ class CI_Image_lib { // Let's set up our values based on the action if ($action == 'crop') { - // Reassign the source width/height if cropping - $this->orig_width = $this->width; + // Reassign the source width/height if cropping + $this->orig_width = $this->width; $this->orig_height = $this->height; // GD 2.0 has a cropping bug so we'll test for it @@ -487,19 +487,19 @@ class CI_Image_lib { $this->y_axis = 0; } - // Create the image handle + // Create the image handle if ( ! ($src_img = $this->image_create_gd())) { return FALSE; } - // Create The Image + // Create The Image // - // old conditional which users report cause problems with shared GD libs who report themselves as "2.0 or greater" - // it appears that this is no longer the issue that it was in 2004, so we've removed it, retaining it in the comment - // below should that ever prove inaccurate. + // old conditional which users report cause problems with shared GD libs who report themselves as "2.0 or greater" + // it appears that this is no longer the issue that it was in 2004, so we've removed it, retaining it in the comment + // below should that ever prove inaccurate. // - // if ($this->image_library == 'gd2' AND function_exists('imagecreatetruecolor') AND $v2_override == FALSE) + // if ($this->image_library == 'gd2' AND function_exists('imagecreatetruecolor') AND $v2_override == FALSE) if ($this->image_library == 'gd2' AND function_exists('imagecreatetruecolor')) { $create = 'imagecreatetruecolor'; @@ -521,7 +521,7 @@ class CI_Image_lib { $copy($dst_img, $src_img, 0, 0, $this->x_axis, $this->y_axis, $this->width, $this->height, $this->orig_width, $this->orig_height); - // Show the image + // Show the image if ($this->dynamic_output == TRUE) { $this->image_display_gd($dst_img); @@ -535,7 +535,7 @@ class CI_Image_lib { } } - // Kill the file handles + // Kill the file handles imagedestroy($dst_img); imagedestroy($src_img); @@ -558,7 +558,7 @@ class CI_Image_lib { */ function image_process_imagemagick($action = 'resize') { - // Do we have a vaild library path? + // Do we have a vaild library path? if ($this->library_path == '') { $this->set_error('imglib_libpath_invalid'); @@ -593,7 +593,7 @@ class CI_Image_lib { $cmd .= " ".$angle." \"$this->full_src_path\" \"$this->full_dst_path\" 2>&1"; } - else // Resize + else // Resize { $cmd .= " -resize ".$this->width."x".$this->height." \"$this->full_src_path\" \"$this->full_dst_path\" 2>&1"; } @@ -634,7 +634,7 @@ class CI_Image_lib { return FALSE; } - // Build the resizing command + // Build the resizing command switch ($this->image_type) { case 1 : @@ -684,7 +684,7 @@ class CI_Image_lib { @exec($cmd, $output, $retval); - // Did it work? + // Did it work? if ($retval > 0) { $this->set_error('imglib_image_process_failed'); @@ -711,7 +711,7 @@ class CI_Image_lib { */ function image_rotate_gd() { - // Create the image handle + // Create the image handle if ( ! ($src_img = $this->image_create_gd())) { return FALSE; @@ -724,10 +724,10 @@ class CI_Image_lib { $white = imagecolorallocate($src_img, 255, 255, 255); - // Rotate it! + // Rotate it! $dst_img = imagerotate($src_img, $this->rotation_angle, $white); - // Save the Image + // Save the Image if ($this->dynamic_output == TRUE) { $this->image_display_gd($dst_img); @@ -741,7 +741,7 @@ class CI_Image_lib { } } - // Kill the file handles + // Kill the file handles imagedestroy($dst_img); imagedestroy($src_img); @@ -769,14 +769,14 @@ class CI_Image_lib { return FALSE; } - $width = $this->orig_width; + $width = $this->orig_width; $height = $this->orig_height; if ($this->rotation_angle == 'hor') { for ($i = 0; $i < $height; $i++) { - $left = 0; + $left = 0; $right = $width-1; while ($left < $right) @@ -813,7 +813,7 @@ class CI_Image_lib { } } - // Show the image + // Show the image if ($this->dynamic_output == TRUE) { $this->image_display_gd($src_img); @@ -827,7 +827,7 @@ class CI_Image_lib { } } - // Kill the file handles + // Kill the file handles imagedestroy($src_img); // Set the file to 777 @@ -876,24 +876,24 @@ class CI_Image_lib { return FALSE; } - // Fetch source image properties + // Fetch source image properties $this->get_image_properties(); - // Fetch watermark image properties + // Fetch watermark image properties $props = $this->get_image_properties($this->wm_overlay_path, TRUE); $wm_img_type = $props['image_type']; $wm_width = $props['width']; $wm_height = $props['height']; - // Create two image resources - $wm_img = $this->image_create_gd($this->wm_overlay_path, $wm_img_type); + // Create two image resources + $wm_img = $this->image_create_gd($this->wm_overlay_path, $wm_img_type); $src_img = $this->image_create_gd($this->full_src_path); // Reverse the offset if necessary // When the image is positioned at the bottom // we don't want the vertical offset to push it - // further down. We want the reverse, so we'll - // invert the offset. Same with the horizontal + // further down. We want the reverse, so we'll + // invert the offset. Same with the horizontal // offset when the image is at the right $this->wm_vrt_alignment = strtoupper(substr($this->wm_vrt_alignment, 0, 1)); @@ -905,11 +905,11 @@ class CI_Image_lib { if ($this->wm_hor_alignment == 'R') $this->wm_hor_offset = $this->wm_hor_offset * -1; - // Set the base x and y axis values + // Set the base x and y axis values $x_axis = $this->wm_hor_offset + $this->wm_padding; $y_axis = $this->wm_vrt_offset + $this->wm_padding; - // Set the vertical position + // Set the vertical position switch ($this->wm_vrt_alignment) { case 'T': @@ -920,7 +920,7 @@ class CI_Image_lib { break; } - // Set the horizontal position + // Set the horizontal position switch ($this->wm_hor_alignment) { case 'L': @@ -931,7 +931,7 @@ class CI_Image_lib { break; } - // Build the finalized image + // Build the finalized image if ($wm_img_type == 3 AND function_exists('imagealphablending')) { @imagealphablending($src_img, TRUE); @@ -954,7 +954,7 @@ class CI_Image_lib { imagecopymerge($src_img, $wm_img, $x_axis, $y_axis, 0, 0, $wm_width, $wm_height, $this->wm_opacity); } - // Output the image + // Output the image if ($this->dynamic_output == TRUE) { $this->image_display_gd($src_img); @@ -994,7 +994,7 @@ class CI_Image_lib { return FALSE; } - // Fetch source image properties + // Fetch source image properties $this->get_image_properties(); // Set RGB values for text and shadow @@ -1015,8 +1015,8 @@ class CI_Image_lib { // Reverse the vertical offset // When the image is positioned at the bottom // we don't want the vertical offset to push it - // further down. We want the reverse, so we'll - // invert the offset. Note: The horizontal + // further down. We want the reverse, so we'll + // invert the offset. Note: The horizontal // offset flips itself automatically if ($this->wm_vrt_alignment == 'B') @@ -1033,13 +1033,13 @@ class CI_Image_lib { if ($this->wm_font_size == '') $this->wm_font_size = '17'; - $fontwidth = $this->wm_font_size-($this->wm_font_size/4); + $fontwidth = $this->wm_font_size-($this->wm_font_size/4); $fontheight = $this->wm_font_size; $this->wm_vrt_offset += $this->wm_font_size; } else { - $fontwidth = imagefontwidth($this->wm_font_size); + $fontwidth = imagefontwidth($this->wm_font_size); $fontheight = imagefontheight($this->wm_font_size); } @@ -1080,11 +1080,11 @@ class CI_Image_lib { case "C": if ($this->wm_use_drop_shadow) $x_shad += floor(($this->orig_width - $fontwidth*strlen($this->wm_text))/2); - $x_axis += floor(($this->orig_width -$fontwidth*strlen($this->wm_text))/2); + $x_axis += floor(($this->orig_width -$fontwidth*strlen($this->wm_text))/2); break; } - // Add the text to the source image + // Add the text to the source image if ($this->wm_use_truetype) { if ($this->wm_use_drop_shadow) @@ -1098,7 +1098,7 @@ class CI_Image_lib { imagestring($src_img, $this->wm_font_size, $x_axis, $y_axis, $this->wm_text, $txt_color); } - // Output the final image + // Output the final image if ($this->dynamic_output == TRUE) { $this->image_display_gd($src_img); @@ -1366,7 +1366,7 @@ class CI_Image_lib { * Size calculator * * This function takes a known width x height and - * recalculates it to a new size. Only one + * recalculates it to a new size. Only one * new variable needs to be known * * $props = array( @@ -1374,7 +1374,7 @@ class CI_Image_lib { * 'height' => $height, * 'new_width' => 40, * 'new_height' => '' - * ); + * ); * * @access public * @param array @@ -1418,10 +1418,10 @@ class CI_Image_lib { * Explode source_image * * This is a helper function that extracts the extension - * from the source_image. This function lets us deal with - * source_images with multiple periods, like: my.cool.jpg + * from the source_image. This function lets us deal with + * source_images with multiple periods, like: my.cool.jpg * It returns an associative array with two elements: - * $array['ext'] = '.jpg'; + * $array['ext'] = '.jpg'; * $array['name'] = 'my.cool'; * * @access public diff --git a/system/libraries/Javascript.php b/system/libraries/Javascript.php index 9e42a4385..34e0d7001 100644 --- a/system/libraries/Javascript.php +++ b/system/libraries/Javascript.php @@ -1,4 +1,4 @@ -js =& $this->CI->$js_library_driver; - log_message('debug', "Javascript Class Initialized and loaded. Driver used: $js_library_driver"); + log_message('debug', "Javascript Class Initialized and loaded. Driver used: $js_library_driver"); } - // -------------------------------------------------------------------- + // -------------------------------------------------------------------- // Event Code // -------------------------------------------------------------------- @@ -378,7 +378,7 @@ class CI_Javascript { return $this->js->_unload($element, $js); } - // -------------------------------------------------------------------- + // -------------------------------------------------------------------- // Effects // -------------------------------------------------------------------- @@ -685,7 +685,7 @@ class CI_Javascript { return $str; } - + // -------------------------------------------------------------------- /** @@ -855,7 +855,7 @@ class CI_Javascript { } elseif (is_string($result) OR $is_key) { - return '"'.str_replace(array('\\', "\t", "\n", "\r", '"', '/'), array('\\\\', '\\t', '\\n', "\\r", '\"', '\/'), $result).'"'; + return '"'.str_replace(array('\\', "\t", "\n", "\r", '"', '/'), array('\\\\', '\\t', '\\n', "\\r", '\"', '\/'), $result).'"'; } elseif (is_scalar($result)) { diff --git a/system/libraries/Log.php b/system/libraries/Log.php index 2505fc678..9f1db76ba 100644 --- a/system/libraries/Log.php +++ b/system/libraries/Log.php @@ -1,4 +1,4 @@ - '1', 'DEBUG' => '2', 'INFO' => '3', 'ALL' => '4'); + protected $_levels = array('ERROR' => '1', 'DEBUG' => '2', 'INFO' => '3', 'ALL' => '4'); /** * Constructor @@ -84,11 +84,11 @@ class CI_Log { } $filepath = $this->_log_path.'log-'.date('Y-m-d').'.php'; - $message = ''; + $message = ''; if ( ! file_exists($filepath)) { - $message .= "<"."?php if ( ! defined('BASEPATH')) exit('No direct script access allowed'); ?".">\n\n"; + $message .= "<"."?php if ( ! defined('BASEPATH')) exit('No direct script access allowed'); ?".">\n\n"; } if ( ! $fp = @fopen($filepath, FOPEN_WRITE_CREATE)) diff --git a/system/libraries/Pagination.php b/system/libraries/Pagination.php index d9c22d501..cc62e660b 100644 --- a/system/libraries/Pagination.php +++ b/system/libraries/Pagination.php @@ -1,4 +1,4 @@ -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; + $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 + // 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) { @@ -194,14 +194,14 @@ class CI_Pagination { $output = ''; // Render the "First" link - if ($this->first_link !== FALSE AND $this->cur_page > ($this->num_links + 1)) + 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->prev_link !== FALSE AND $this->cur_page != 1) { $i = $uri_page_number - $this->per_page; @@ -263,7 +263,7 @@ class CI_Pagination { $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 + // 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); diff --git a/system/libraries/Parser.php b/system/libraries/Parser.php index f48f2a7e5..d223da020 100644 --- a/system/libraries/Parser.php +++ b/system/libraries/Parser.php @@ -1,4 +1,4 @@ -'; $output .= "\n"; $output .= '  '.$this->CI->lang->line('profiler_benchmarks').'  '; @@ -168,7 +168,7 @@ class CI_Profiler { if (count($dbs) == 0) { - $output = "\n\n"; + $output = "\n\n"; $output .= '
    '; $output .= "\n"; $output .= '  '.$this->CI->lang->line('profiler_queries').'  '; @@ -187,7 +187,7 @@ class CI_Profiler { // 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"; + $output = "\n\n"; $count = 0; @@ -249,7 +249,7 @@ class CI_Profiler { */ protected function _compile_get() { - $output = "\n\n"; + $output = "\n\n"; $output .= '
    '; $output .= "\n"; $output .= '  '.$this->CI->lang->line('profiler_get_data').'  '; @@ -298,7 +298,7 @@ class CI_Profiler { */ protected function _compile_post() { - $output = "\n\n"; + $output = "\n\n"; $output .= '
    '; $output .= "\n"; $output .= '  '.$this->CI->lang->line('profiler_post_data').'  '; @@ -347,7 +347,7 @@ class CI_Profiler { */ protected function _compile_uri_string() { - $output = "\n\n"; + $output = "\n\n"; $output .= '
    '; $output .= "\n"; $output .= '  '.$this->CI->lang->line('profiler_uri_string').'  '; @@ -376,7 +376,7 @@ class CI_Profiler { */ protected function _compile_controller_info() { - $output = "\n\n"; + $output = "\n\n"; $output .= '
    '; $output .= "\n"; $output .= '  '.$this->CI->lang->line('profiler_controller_info').'  '; @@ -400,7 +400,7 @@ class CI_Profiler { */ protected function _compile_memory_usage() { - $output = "\n\n"; + $output = "\n\n"; $output .= '
    '; $output .= "\n"; $output .= '  '.$this->CI->lang->line('profiler_memory_usage').'  '; @@ -431,7 +431,7 @@ class CI_Profiler { */ protected function _compile_http_headers() { - $output = "\n\n"; + $output = "\n\n"; $output .= '
    '; $output .= "\n"; $output .= '  '.$this->CI->lang->line('profiler_headers').'  ('.$this->CI->lang->line('profiler_section_show').')'; @@ -462,7 +462,7 @@ class CI_Profiler { */ protected function _compile_config() { - $output = "\n\n"; + $output = "\n\n"; $output .= '
    '; $output .= "\n"; $output .= '  '.$this->CI->lang->line('profiler_config').'  ('.$this->CI->lang->line('profiler_section_show').')'; diff --git a/system/libraries/Session.php b/system/libraries/Session.php index 76525dbb8..2c8a80163 100644 --- a/system/libraries/Session.php +++ b/system/libraries/Session.php @@ -1,4 +1,4 @@ -CI->load->library('encrypt'); } - // Are we using a database? If so, load it + // 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 + // 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 @@ -97,12 +97,12 @@ class CI_Session { { $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. + // create a new one. If it does, we'll update it. if ( ! $this->sess_read()) { $this->sess_create(); @@ -137,7 +137,7 @@ class CI_Session { // Fetch the cookie $session = $this->CI->input->cookie($this->sess_cookie_name); - // No cookie? Goodbye cruel world!... + // No cookie? Goodbye cruel world!... if ($session === FALSE) { log_message('debug', 'A session cookie was not found.'); @@ -155,8 +155,8 @@ class CI_Session { $hash = substr($session, strlen($session)-32); // get last 32 chars $session = substr($session, 0, strlen($session)-32); - // Does the md5 hash match? This is to prevent manipulation of session data in userspace - if ($hash !== md5($session.$this->encryption_key)) + // Does the md5 hash match? This is to prevent manipulation of session data in userspace + if ($hash !== md5($session.$this->encryption_key)) { log_message('error', 'The session cookie data did not match what was expected. This could be a possible hacking attempt.'); $this->sess_destroy(); @@ -212,14 +212,14 @@ class CI_Session { $query = $this->CI->db->get($this->sess_table_name); - // No result? Kill it! + // 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 + // 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 != '') { @@ -252,7 +252,7 @@ class CI_Session { */ function sess_write() { - // Are we saving custom data to the DB? If not, all we do is update the cookie + // 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(); @@ -272,7 +272,7 @@ class CI_Session { $cookie_userdata[$val] = $this->userdata[$val]; } - // Did we find any custom data? If not, we turn the empty array into a string + // Did we find any custom data? If not, we turn the empty array into a string // since there's no reason to serialize and store an empty array in the DB if (count($custom_userdata) === 0) { @@ -288,7 +288,7 @@ class CI_Session { $this->CI->db->where('session_id', $this->userdata['session_id']); $this->CI->db->update($this->sess_table_name, array('last_activity' => $this->userdata['last_activity'], 'user_data' => $custom_userdata)); - // Write the cookie. Notice that we manually pass the cookie data array to the + // Write the cookie. Notice that we manually pass the cookie data array to the // _set_cookie() function. Normally that function will store $this->userdata, but // in this case that array contains custom data, which we do not want in the cookie. $this->_set_cookie($cookie_userdata); @@ -535,7 +535,7 @@ class CI_Session { */ function keep_flashdata($key) { - // 'old' flashdata gets removed. Here we mark all + // 'old' flashdata gets removed. Here we mark all // flashdata as 'new' to preserve it from _flashdata_sweep() // Note the function will return FALSE if the $key // provided cannot be found diff --git a/system/libraries/Sha1.php b/system/libraries/Sha1.php index 04e07d1c1..1a657572b 100644 --- a/system/libraries/Sha1.php +++ b/system/libraries/Sha1.php @@ -1,4 +1,4 @@ -heading) == 0 AND count($this->rows) == 0) { return 'Undefined table data'; @@ -376,7 +376,7 @@ class CI_Table { // -------------------------------------------------------------------- /** - * Clears the table arrays. Useful if multiple tables are being generated + * Clears the table arrays. Useful if multiple tables are being generated * * @access public * @return void @@ -495,7 +495,7 @@ class CI_Table { */ function _default_template() { - return array ( + return array ( 'table_open' => '
    <<
    ', 'thead_open' => '', diff --git a/system/libraries/Trackback.php b/system/libraries/Trackback.php index b0f8a9098..b0a767822 100644 --- a/system/libraries/Trackback.php +++ b/system/libraries/Trackback.php @@ -1,4 +1,4 @@ -","\"", "'", "-"), array("&", "<", ">", """, "'", "-"), diff --git a/system/libraries/Typography.php b/system/libraries/Typography.php index 3ceb0b52b..734cec104 100644 --- a/system/libraries/Typography.php +++ b/system/libraries/Typography.php @@ -1,4 +1,4 @@ - tags if they exist. It's cheaper to do this separately since most content will + // match and yank
     tags if they exist.  It's cheaper to do this separately since most content will
     		// not contain 
     tags, and it keeps the PCRE patterns below simpler and faster
     		if (strpos($str, 'inline_elements.")([ >])#i", "{@TAG}\\1\\2\\3", $str);
     
    -		// Split the string at every tag. This expression creates an array with this prototype:
    +		// Split the string at every tag.  This expression creates an array with this prototype:
     		//
     		//	[array]
     		//	{
    @@ -126,7 +126,7 @@ class CI_Typography {
     		//	}
     		$chunks = preg_split('/(<(?:[^<>]+(?:"[^"]*"|\'[^\']*\')?)+>)/', $str, -1, PREG_SPLIT_DELIM_CAPTURE|PREG_SPLIT_NO_EMPTY);
     
    -		// Build our finalized string. We cycle through the array, skipping tags, and processing the contained text
    +		// Build our finalized string.  We cycle through the array, skipping tags, and processing the contained text
     		$str = '';
     		$process = TRUE;
     		$paragraph = FALSE;
    @@ -143,7 +143,7 @@ class CI_Typography {
     			{
     				if (preg_match("#".$this->skip_elements."#", $match[2]))
     				{
    -					$process = ($match[1] == '/') ? TRUE : FALSE;
    +					$process =  ($match[1] == '/') ? TRUE : FALSE;
     				}
     
     				if ($match[1] == '')
    @@ -161,17 +161,17 @@ class CI_Typography {
     				continue;
     			}
     
    -			// Force a newline to make sure end tags get processed by _format_newlines()
    +			//  Force a newline to make sure end tags get processed by _format_newlines()
     			if ($current_chunk == $total_chunks)
     			{
     				$chunk .= "\n";
     			}
     
    -			// Convert Newlines into 

    and
    tags + // Convert Newlines into

    and
    tags $str .= $this->_format_newlines($chunk); } - // No opening block level tag? Add it if needed. + // No opening block level tag? Add it if needed. if ( ! preg_match("/^\s*<(?:".$this->block_elements.")/i", $str)) { $str = preg_replace("/^(.*?)<(".$this->block_elements.")/i", '

    $1

    <$2', $str); @@ -204,14 +204,14 @@ class CI_Typography { '#

    <('.$this->block_elements.')#' => '<$1', // Clean up stray non-breaking spaces preceeding block elements - '#( \s*)+<('.$this->block_elements.')#' => ' <$2', + '#( \s*)+<('.$this->block_elements.')#' => ' <$2', // Replace the temporary markers we added earlier '/\{@TAG\}/' => '<', '/\{@DQ\}/' => '"', '/\{@SQ\}/' => "'", '/\{@DD\}/' => '--', - '/\{@NBS\}/' => ' ', + '/\{@NBS\}/' => ' ', // An unintended consequence of the _format_newlines function is that // some of the newlines get truncated, resulting in

    tags @@ -296,7 +296,7 @@ class CI_Typography { '/(\w)\.{3}/' => '$1…', // double space after sentences - '/(\W) /' => '$1  ', + '/(\W) /' => '$1  ', // ampersands, if not a character entity '/&(?!#?[a-zA-Z0-9]{2,};)/' => '&' @@ -324,7 +324,7 @@ class CI_Typography { return $str; } - if (strpos($str, "\n") === FALSE && ! in_array($this->last_block_element, $this->inner_block_required)) + if (strpos($str, "\n") === FALSE && ! in_array($this->last_block_element, $this->inner_block_required)) { return $str; } @@ -341,7 +341,7 @@ class CI_Typography { // We trim off the right-side new line so that the closing

    tag // will be positioned immediately following the string, matching // the behavior of the opening

    tag - $str = '

    '.rtrim($str).'

    '; + $str = '

    '.rtrim($str).'

    '; } // Remove empty paragraphs if they are on the first line, as this @@ -367,7 +367,7 @@ class CI_Typography { */ function _protect_characters($match) { - return str_replace(array("'",'"','--',' '), array('{@SQ}', '{@DQ}', '{@DD}', '{@NBS}'), $match[0]); + return str_replace(array("'",'"','--',' '), array('{@SQ}', '{@DQ}', '{@DD}', '{@NBS}'), $match[0]); } // -------------------------------------------------------------------- diff --git a/system/libraries/Unit_test.php b/system/libraries/Unit_test.php index c9012f646..5bd7e801a 100644 --- a/system/libraries/Unit_test.php +++ b/system/libraries/Unit_test.php @@ -1,4 +1,4 @@ -set_error('upload_stopped_by_extension'); break; - default : $this->set_error('upload_no_file_selected'); + default : $this->set_error('upload_no_file_selected'); break; } @@ -290,7 +290,7 @@ class CI_Upload { /* * Run the file through the XSS hacking filter * This helps prevent malicious code from being - * embedded within a file. Scripts can easily + * embedded within a file. Scripts can easily * be disguised as images or other file types. */ if ($this->xss_clean) @@ -305,8 +305,8 @@ class CI_Upload { /* * Move the file to the final destination * To deal with different server configurations - * we'll attempt to use copy() first. If that fails - * we'll use move_uploaded_file(). One of the two should + * we'll attempt to use copy() first. If that fails + * we'll use move_uploaded_file(). One of the two should * reliably work in most environments */ if ( ! @copy($this->file_temp, $this->upload_path.$this->file_name)) @@ -321,7 +321,7 @@ class CI_Upload { /* * Set the finalized image dimensions * This sets the image width/height (assuming the - * file was an image). We use this information + * file was an image). We use this information * in the "data" function. */ $this->set_image_properties($this->upload_path.$this->file_name); @@ -518,7 +518,7 @@ class CI_Upload { $this->image_width = $D['0']; $this->image_height = $D['1']; $this->image_type = ( ! isset($types[$D['2']])) ? 'unknown' : $types[$D['2']]; - $this->image_size_str = $D['3']; // string containing height and width + $this->image_size_str = $D['3']; // string containing height and width } } } @@ -551,7 +551,7 @@ class CI_Upload { // IE will sometimes return odd mime-types during upload, so here we just standardize all // jpegs or pngs to the same file type. - $png_mimes = array('image/x-png'); + $png_mimes = array('image/x-png'); $jpeg_mimes = array('image/jpg', 'image/jpe', 'image/jpeg', 'image/pjpeg'); if (in_array($this->file_type, $png_mimes)) @@ -642,7 +642,7 @@ class CI_Upload { */ public function is_allowed_filesize() { - if ($this->max_size != 0 AND $this->file_size > $this->max_size) + if ($this->max_size != 0 AND $this->file_size > $this->max_size) { return FALSE; } @@ -721,7 +721,7 @@ class CI_Upload { return FALSE; } - $this->upload_path = preg_replace("/(.+?)\/*$/", "\\1/", $this->upload_path); + $this->upload_path = preg_replace("/(.+?)\/*$/", "\\1/", $this->upload_path); return TRUE; } @@ -834,7 +834,7 @@ class CI_Upload { $current = ini_get('memory_limit') * 1024 * 1024; // There was a bug/behavioural change in PHP 5.2, where numbers over one million get output - // into scientific notation. number_format() ensures this number is an integer + // into scientific notation. number_format() ensures this number is an integer // http://bugs.php.net/bug.php?id=43053 $new_memory = number_format(ceil(filesize($file) + $current), 0, '.', ''); @@ -844,8 +844,8 @@ class CI_Upload { // If the file being uploaded is an image, then we should have no problem with XSS attacks (in theory), but // IE can be fooled into mime-type detecting a malformed image as an html file, thus executing an XSS attack on anyone - // using IE who looks at the image. It does this by inspecting the first 255 bytes of an image. To get around this - // CI will itself look at the first 255 bytes of an image to determine its relative safety. This can save a lot of + // using IE who looks at the image. It does this by inspecting the first 255 bytes of an image. To get around this + // CI will itself look at the first 255 bytes of an image to determine its relative safety. This can save a lot of // processor power and time if it is actually a clean image, as it will be in nearly all instances _except_ an // attempted XSS attack. @@ -933,7 +933,7 @@ class CI_Upload { /** * List of Mime Types * - * This is a list of mime types. We use it to validate + * This is a list of mime types. We use it to validate * the "allowed types" set by the developer * * @param string diff --git a/system/libraries/User_agent.php b/system/libraries/User_agent.php index 543d1d5a3..016102a2a 100644 --- a/system/libraries/User_agent.php +++ b/system/libraries/User_agent.php @@ -1,4 +1,4 @@ -xmlrpcerr['unknown_method'] = '1'; $this->xmlrpcstr['unknown_method'] = 'This is not a known method for this XML-RPC Server'; $this->xmlrpcerr['invalid_return'] = '2'; - $this->xmlrpcstr['invalid_return'] = 'The XML data received was either invalid or not in the correct form for XML-RPC. Turn on debugging to examine the XML data further.'; + $this->xmlrpcstr['invalid_return'] = 'The XML data received was either invalid or not in the correct form for XML-RPC. Turn on debugging to examine the XML data further.'; $this->xmlrpcerr['incorrect_params'] = '3'; $this->xmlrpcstr['incorrect_params'] = 'Incorrect parameters were passed to method'; $this->xmlrpcerr['introspect_unknown'] = '4'; @@ -129,7 +129,7 @@ class CI_Xmlrpc { //------------------------------------- - // Initialize Prefs + // Initialize Prefs //------------------------------------- function initialize($config = array()) @@ -148,7 +148,7 @@ class CI_Xmlrpc { // END //------------------------------------- - // Take URL and parse it + // Take URL and parse it //------------------------------------- function server($url, $port=80) @@ -172,7 +172,7 @@ class CI_Xmlrpc { // END //------------------------------------- - // Set Timeout + // Set Timeout //------------------------------------- function timeout($seconds=5) @@ -185,7 +185,7 @@ class CI_Xmlrpc { // END //------------------------------------- - // Set Methods + // Set Methods //------------------------------------- function method($function) @@ -195,7 +195,7 @@ class CI_Xmlrpc { // END //------------------------------------- - // Take Array of Data and Create Objects + // Take Array of Data and Create Objects //------------------------------------- function request($incoming) @@ -216,7 +216,7 @@ class CI_Xmlrpc { //------------------------------------- - // Set Debug + // Set Debug //------------------------------------- function set_debug($flag = TRUE) @@ -225,7 +225,7 @@ class CI_Xmlrpc { } //------------------------------------- - // Values Parsing + // Values Parsing //------------------------------------- function values_parsing($value, $return = FALSE) @@ -268,7 +268,7 @@ class CI_Xmlrpc { //------------------------------------- - // Sends XML-RPC Request + // Sends XML-RPC Request //------------------------------------- function send_request() @@ -294,7 +294,7 @@ class CI_Xmlrpc { // END //------------------------------------- - // Returns Error + // Returns Error //------------------------------------- function display_error() @@ -304,7 +304,7 @@ class CI_Xmlrpc { // END //------------------------------------- - // Returns Remote Server Response + // Returns Remote Server Response //------------------------------------- function display_response() @@ -314,7 +314,7 @@ class CI_Xmlrpc { // END //------------------------------------- - // Sends an Error Message for Server Request + // Sends an Error Message for Server Request //------------------------------------- function send_error_message($number, $message) @@ -325,7 +325,7 @@ class CI_Xmlrpc { //------------------------------------- - // Send Response for Server Request + // Send Response for Server Request //------------------------------------- function send_response($response) @@ -399,7 +399,7 @@ class XML_RPC_Client extends CI_Xmlrpc } $r = "\r\n"; - $op = "POST {$this->path} HTTP/1.0$r"; + $op = "POST {$this->path} HTTP/1.0$r"; $op .= "Host: {$this->server}$r"; $op .= "Content-Type: text/xml$r"; $op .= "User-Agent: {$this->xmlrpcName}$r"; @@ -447,7 +447,7 @@ class XML_RPC_Response else if ( ! is_object($val)) { // programmer error, not an object - error_log("Invalid type '" . gettype($val) . "' (value: $val) passed to XML_RPC_Response. Defaulting to empty value."); + error_log("Invalid type '" . gettype($val) . "' (value: $val) passed to XML_RPC_Response. Defaulting to empty value."); $this->val = new XML_RPC_Values(); } else @@ -504,7 +504,7 @@ class XML_RPC_Response function decode($array=FALSE) { $CI =& get_instance(); - + if ($array !== FALSE && is_array($array)) { while (list($key) = each($array)) @@ -541,7 +541,7 @@ class XML_RPC_Response //------------------------------------- - // XML-RPC Object to PHP Types + // XML-RPC Object to PHP Types //------------------------------------- function xmlrpc_decoder($xmlrpc_val) @@ -581,7 +581,7 @@ class XML_RPC_Response //------------------------------------- - // ISO-8601 time to server or UTC time + // ISO-8601 time to server or UTC time //------------------------------------- function iso8601_decode($time, $utc=0) @@ -630,7 +630,7 @@ class XML_RPC_Message extends CI_Xmlrpc } //------------------------------------- - // Create Payload to Send + // Create Payload to Send //------------------------------------- function createPayload() @@ -650,7 +650,7 @@ class XML_RPC_Message extends CI_Xmlrpc } //------------------------------------- - // Parse External XML-RPC Server's Response + // Parse External XML-RPC Server's Response //------------------------------------- function parseResponse($fp) @@ -663,7 +663,7 @@ class XML_RPC_Message extends CI_Xmlrpc } //------------------------------------- - // DISPLAY HTTP CONTENT for DEBUGGING + // DISPLAY HTTP CONTENT for DEBUGGING //------------------------------------- if ($this->debug === TRUE) @@ -674,7 +674,7 @@ class XML_RPC_Message extends CI_Xmlrpc } //------------------------------------- - // Check for data + // Check for data //------------------------------------- if ($data == "") @@ -686,7 +686,7 @@ class XML_RPC_Message extends CI_Xmlrpc //------------------------------------- - // Check for HTTP 200 Response + // Check for HTTP 200 Response //------------------------------------- if (strncmp($data, 'HTTP', 4) == 0 && ! preg_match('/^HTTP\/[0-9\.]+ 200 /', $data)) @@ -697,7 +697,7 @@ class XML_RPC_Message extends CI_Xmlrpc } //------------------------------------- - // Create and Set Up XML Parser + // Create and Set Up XML Parser //------------------------------------- $parser = xml_parser_create($this->xmlrpc_defencoding); @@ -718,7 +718,7 @@ class XML_RPC_Message extends CI_Xmlrpc //------------------------------------- - // GET HEADERS + // GET HEADERS //------------------------------------- $lines = explode("\r\n", $data); @@ -734,7 +734,7 @@ class XML_RPC_Message extends CI_Xmlrpc //------------------------------------- - // PARSE XML DATA + // PARSE XML DATA //------------------------------------- if ( ! xml_parse($parser, $data, count($data))) @@ -750,7 +750,7 @@ class XML_RPC_Message extends CI_Xmlrpc xml_parser_free($parser); // --------------------------------------- - // Got Ourselves Some Badness, It Seems + // Got Ourselves Some Badness, It Seems // --------------------------------------- if ($this->xh[$parser]['isf'] > 1) @@ -772,7 +772,7 @@ class XML_RPC_Message extends CI_Xmlrpc } //------------------------------------- - // DISPLAY XML CONTENT for DEBUGGING + // DISPLAY XML CONTENT for DEBUGGING //------------------------------------- if ($this->debug === TRUE) @@ -797,7 +797,7 @@ class XML_RPC_Message extends CI_Xmlrpc } //------------------------------------- - // SEND RESPONSE + // SEND RESPONSE //------------------------------------- $v = $this->xh[$parser]['value']; @@ -826,21 +826,21 @@ class XML_RPC_Message extends CI_Xmlrpc } // ------------------------------------ - // Begin Return Message Parsing section + // Begin Return Message Parsing section // ------------------------------------ // quick explanation of components: - // ac - used to accumulate values - // isf - used to indicate a fault - // lv - used to indicate "looking for a value": implements + // ac - used to accumulate values + // isf - used to indicate a fault + // lv - used to indicate "looking for a value": implements // the logic to allow values with no types to be strings - // params - used to store parameters in method calls - // method - used to store method name + // params - used to store parameters in method calls + // method - used to store method name // stack - array with parent tree of the xml element, // used to validate the nesting of elements //------------------------------------- - // Start Element Handler + // Start Element Handler //------------------------------------- function open_tag($the_parser, $name, $attrs) @@ -942,7 +942,7 @@ class XML_RPC_Message extends CI_Xmlrpc //------------------------------------- - // End Element Handler + // End Element Handler //------------------------------------- function closing_tag($the_parser, $name) @@ -951,7 +951,7 @@ class XML_RPC_Message extends CI_Xmlrpc // Remove current element from stack and set variable // NOTE: If the XML validates, then we do not have to worry about - // the opening and closing of elements. Nesting is checked on the opening + // the opening and closing of elements. Nesting is checked on the opening // tag so we be safe there as well. $curr_elem = array_shift($this->xh[$the_parser]['stack']); @@ -1080,13 +1080,13 @@ class XML_RPC_Message extends CI_Xmlrpc // We're all good kids with nuthin' to do break; default: - // End of an Invalid Element. Taken care of during the opening tag though + // End of an Invalid Element. Taken care of during the opening tag though break; } } //------------------------------------- - // Parses Character Data + // Parses Character Data //------------------------------------- function character_data($the_parser, $data) @@ -1116,7 +1116,7 @@ class XML_RPC_Message extends CI_Xmlrpc function output_parameters($array=FALSE) { $CI =& get_instance(); - + if ($array !== FALSE && is_array($array)) { while (list($key) = each($array)) diff --git a/system/libraries/Xmlrpcs.php b/system/libraries/Xmlrpcs.php index 88af60693..9cd332147 100644 --- a/system/libraries/Xmlrpcs.php +++ b/system/libraries/Xmlrpcs.php @@ -1,4 +1,4 @@ -parseRequest(); - $payload = 'xmlrpc_defencoding.'"?'.'>'."\n"; + $payload = 'xmlrpc_defencoding.'"?'.'>'."\n"; $payload .= $this->debug_msg; $payload .= $r->prepare_response(); @@ -156,7 +156,7 @@ class CI_Xmlrpcs extends CI_Xmlrpc function add_to_map($methodname, $function, $sig, $doc) { $this->methods[$methodname] = array( - 'function' => $function, + 'function' => $function, 'signature' => $sig, 'docstring' => $doc ); @@ -176,7 +176,7 @@ class CI_Xmlrpcs extends CI_Xmlrpc global $HTTP_RAW_POST_DATA; //------------------------------------- - // Get Data + // Get Data //------------------------------------- if ($data == '') @@ -185,7 +185,7 @@ class CI_Xmlrpcs extends CI_Xmlrpc } //------------------------------------- - // Set up XML Parser + // Set up XML Parser //------------------------------------- $parser = xml_parser_create($this->xmlrpc_defencoding); @@ -207,7 +207,7 @@ class CI_Xmlrpcs extends CI_Xmlrpc //------------------------------------- - // PARSE + PROCESS XML DATA + // PARSE + PROCESS XML DATA //------------------------------------- if ( ! xml_parse($parser, $data, 1)) @@ -235,7 +235,7 @@ class CI_Xmlrpcs extends CI_Xmlrpc { if ($this->debug === TRUE) { - $plist .= "$i - " . print_r(get_object_vars($parser_object->xh[$parser]['params'][$i]), TRUE). ";\n"; + $plist .= "$i - " . print_r(get_object_vars($parser_object->xh[$parser]['params'][$i]), TRUE). ";\n"; } $m->addParam($parser_object->xh[$parser]['params'][$i]); @@ -252,7 +252,7 @@ class CI_Xmlrpcs extends CI_Xmlrpc } //------------------------------------- - // SET DEBUGGING MESSAGE + // SET DEBUGGING MESSAGE //------------------------------------- if ($this->debug === TRUE) @@ -285,7 +285,7 @@ class CI_Xmlrpcs extends CI_Xmlrpc } //------------------------------------- - // Valid Method + // Valid Method //------------------------------------- if ( ! isset($this->methods[$methName]['function'])) @@ -294,7 +294,7 @@ class CI_Xmlrpcs extends CI_Xmlrpc } //------------------------------------- - // Check for Method (and Object) + // Check for Method (and Object) //------------------------------------- $method_parts = explode(".", $this->methods[$methName]['function']); @@ -320,7 +320,7 @@ class CI_Xmlrpcs extends CI_Xmlrpc } //------------------------------------- - // Checking Methods Signature + // Checking Methods Signature //------------------------------------- if (isset($this->methods[$methName]['signature'])) @@ -353,7 +353,7 @@ class CI_Xmlrpcs extends CI_Xmlrpc } //------------------------------------- - // Calls the Function + // Calls the Function //------------------------------------- if ($objectCall === TRUE) @@ -381,11 +381,11 @@ class CI_Xmlrpcs extends CI_Xmlrpc return call_user_func($this->methods[$methName]['function'], $m); } } - + // -------------------------------------------------------------------- /** - * Server Function: List Methods + * Server Function: List Methods * * @access public * @param mixed @@ -409,11 +409,11 @@ class CI_Xmlrpcs extends CI_Xmlrpc $v->addArray($output); return new XML_RPC_Response($v); } - + // -------------------------------------------------------------------- /** - * Server Function: Return Signature for Method + * Server Function: Return Signature for Method * * @access public * @param mixed @@ -458,7 +458,7 @@ class CI_Xmlrpcs extends CI_Xmlrpc // -------------------------------------------------------------------- /** - * Server Function: Doc String for Method + * Server Function: Doc String for Method * * @access public * @param mixed @@ -480,11 +480,11 @@ class CI_Xmlrpcs extends CI_Xmlrpc return new XML_RPC_Response(0, $this->xmlrpcerr['introspect_unknown'], $this->xmlrpcstr['introspect_unknown']); } } - + // -------------------------------------------------------------------- /** - * Server Function: Multi-call + * Server Function: Multi-call * * @access public * @param mixed @@ -528,7 +528,7 @@ class CI_Xmlrpcs extends CI_Xmlrpc // -------------------------------------------------------------------- /** - * Multi-call Function: Error Handling + * Multi-call Function: Error Handling * * @access public * @param mixed @@ -536,7 +536,7 @@ class CI_Xmlrpcs extends CI_Xmlrpc */ function multicall_error($err) { - $str = is_string($err) ? $this->xmlrpcstr["multicall_${err}"] : $err->faultString(); + $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'); @@ -548,7 +548,7 @@ class CI_Xmlrpcs extends CI_Xmlrpc // -------------------------------------------------------------------- /** - * Multi-call Function: Processes method + * Multi-call Function: Processes method * * @access public * @param mixed diff --git a/system/libraries/Zip.php b/system/libraries/Zip.php index 1ae3e7f25..666327d5c 100644 --- a/system/libraries/Zip.php +++ b/system/libraries/Zip.php @@ -1,4 +1,4 @@ -CI =& get_instance(); + $this->CI =& get_instance(); extract($params); if ($autoload === TRUE) { - $this->script(); + $this->script(); } - + log_message('debug', "Jquery Class Initialized"); } - - // -------------------------------------------------------------------- + + // -------------------------------------------------------------------- // Event Code - // -------------------------------------------------------------------- + // -------------------------------------------------------------------- /** * Blur @@ -65,9 +65,9 @@ class CI_Jquery extends CI_Javascript { { return $this->_add_event($element, $js, 'blur'); } - + // -------------------------------------------------------------------- - + /** * Change * @@ -82,9 +82,9 @@ class CI_Jquery extends CI_Javascript { { return $this->_add_event($element, $js, 'change'); } - + // -------------------------------------------------------------------- - + /** * Click * @@ -112,7 +112,7 @@ class CI_Jquery extends CI_Javascript { } // -------------------------------------------------------------------- - + /** * Double Click * @@ -129,7 +129,7 @@ class CI_Jquery extends CI_Javascript { } // -------------------------------------------------------------------- - + /** * Error * @@ -146,7 +146,7 @@ class CI_Jquery extends CI_Javascript { } // -------------------------------------------------------------------- - + /** * Focus * @@ -163,7 +163,7 @@ class CI_Jquery extends CI_Javascript { } // -------------------------------------------------------------------- - + /** * Hover * @@ -185,7 +185,7 @@ class CI_Jquery extends CI_Javascript { } // -------------------------------------------------------------------- - + /** * Keydown * @@ -202,7 +202,7 @@ class CI_Jquery extends CI_Javascript { } // -------------------------------------------------------------------- - + /** * Keyup * @@ -216,10 +216,10 @@ class CI_Jquery extends CI_Javascript { function _keyup($element = 'this', $js = '') { return $this->_add_event($element, $js, 'keyup'); - } + } // -------------------------------------------------------------------- - + /** * Load * @@ -233,10 +233,10 @@ class CI_Jquery extends CI_Javascript { function _load($element = 'this', $js = '') { return $this->_add_event($element, $js, 'load'); - } - + } + // -------------------------------------------------------------------- - + /** * Mousedown * @@ -253,7 +253,7 @@ class CI_Jquery extends CI_Javascript { } // -------------------------------------------------------------------- - + /** * Mouse Out * @@ -270,7 +270,7 @@ class CI_Jquery extends CI_Javascript { } // -------------------------------------------------------------------- - + /** * Mouse Over * @@ -321,7 +321,7 @@ class CI_Jquery extends CI_Javascript { { $array_js = array($array_js); } - + foreach ($array_js as $js) { $this->jquery_code_for_compile[] = "\t$js\n"; @@ -361,7 +361,7 @@ class CI_Jquery extends CI_Javascript { { return $this->_add_event($element, $js, 'scroll'); } - + // -------------------------------------------------------------------- /** @@ -379,10 +379,10 @@ class CI_Jquery extends CI_Javascript { return $this->_add_event($element, $js, 'unload'); } - // -------------------------------------------------------------------- + // -------------------------------------------------------------------- // Effects - // -------------------------------------------------------------------- - + // -------------------------------------------------------------------- + /** * Add Class * @@ -395,7 +395,7 @@ class CI_Jquery extends CI_Javascript { function _addClass($element = 'this', $class='') { $element = $this->_prep_element($element); - $str = "$({$element}).addClass(\"$class\");"; + $str = "$({$element}).addClass(\"$class\");"; return $str; } @@ -416,9 +416,9 @@ class CI_Jquery extends CI_Javascript { { $element = $this->_prep_element($element); $speed = $this->_validate_speed($speed); - + $animations = "\t\t\t"; - + foreach ($params as $param=>$value) { $animations .= $param.': \''.$value.'\', '; @@ -430,19 +430,19 @@ class CI_Jquery extends CI_Javascript { { $speed = ', '.$speed; } - + if ($extra != '') { $extra = ', '.$extra; } - - $str = "$({$element}).animate({\n$animations\n\t\t}".$speed.$extra.");"; - + + $str = "$({$element}).animate({\n$animations\n\t\t}".$speed.$extra.");"; + return $str; } // -------------------------------------------------------------------- - + /** * Fade In * @@ -456,21 +456,21 @@ class CI_Jquery extends CI_Javascript { */ function _fadeIn($element = 'this', $speed = '', $callback = '') { - $element = $this->_prep_element($element); + $element = $this->_prep_element($element); $speed = $this->_validate_speed($speed); - + if ($callback != '') { $callback = ", function(){\n{$callback}\n}"; } - - $str = "$({$element}).fadeIn({$speed}{$callback});"; - + + $str = "$({$element}).fadeIn({$speed}{$callback});"; + return $str; } - + // -------------------------------------------------------------------- - + /** * Fade Out * @@ -486,14 +486,14 @@ class CI_Jquery extends CI_Javascript { { $element = $this->_prep_element($element); $speed = $this->_validate_speed($speed); - + if ($callback != '') { $callback = ", function(){\n{$callback}\n}"; } - - $str = "$({$element}).fadeOut({$speed}{$callback});"; - + + $str = "$({$element}).fadeOut({$speed}{$callback});"; + return $str; } @@ -512,19 +512,19 @@ class CI_Jquery extends CI_Javascript { */ function _hide($element = 'this', $speed = '', $callback = '') { - $element = $this->_prep_element($element); + $element = $this->_prep_element($element); $speed = $this->_validate_speed($speed); - + if ($callback != '') { $callback = ", function(){\n{$callback}\n}"; } - - $str = "$({$element}).hide({$speed}{$callback});"; + + $str = "$({$element}).hide({$speed}{$callback});"; return $str; } - + // -------------------------------------------------------------------- /** @@ -539,12 +539,12 @@ class CI_Jquery extends CI_Javascript { function _removeClass($element = 'this', $class='') { $element = $this->_prep_element($element); - $str = "$({$element}).removeClass(\"$class\");"; + $str = "$({$element}).removeClass(\"$class\");"; return $str; } // -------------------------------------------------------------------- - + /** * Slide Up * @@ -558,21 +558,21 @@ class CI_Jquery extends CI_Javascript { */ function _slideUp($element = 'this', $speed = '', $callback = '') { - $element = $this->_prep_element($element); + $element = $this->_prep_element($element); $speed = $this->_validate_speed($speed); - + if ($callback != '') { $callback = ", function(){\n{$callback}\n}"; } - - $str = "$({$element}).slideUp({$speed}{$callback});"; - + + $str = "$({$element}).slideUp({$speed}{$callback});"; + return $str; } - + // -------------------------------------------------------------------- - + /** * Slide Down * @@ -588,19 +588,19 @@ class CI_Jquery extends CI_Javascript { { $element = $this->_prep_element($element); $speed = $this->_validate_speed($speed); - + if ($callback != '') { $callback = ", function(){\n{$callback}\n}"; } - - $str = "$({$element}).slideDown({$speed}{$callback});"; - + + $str = "$({$element}).slideDown({$speed}{$callback});"; + return $str; } // -------------------------------------------------------------------- - + /** * Slide Toggle * @@ -616,19 +616,19 @@ class CI_Jquery extends CI_Javascript { { $element = $this->_prep_element($element); $speed = $this->_validate_speed($speed); - + if ($callback != '') { $callback = ", function(){\n{$callback}\n}"; } - - $str = "$({$element}).slideToggle({$speed}{$callback});"; - + + $str = "$({$element}).slideToggle({$speed}{$callback});"; + return $str; } - + // -------------------------------------------------------------------- - + /** * Toggle * @@ -641,12 +641,12 @@ class CI_Jquery extends CI_Javascript { function _toggle($element = 'this') { $element = $this->_prep_element($element); - $str = "$({$element}).toggle();"; + $str = "$({$element}).toggle();"; return $str; } - + // -------------------------------------------------------------------- - + /** * Toggle Class * @@ -659,12 +659,12 @@ class CI_Jquery extends CI_Javascript { function _toggleClass($element = 'this', $class='') { $element = $this->_prep_element($element); - $str = "$({$element}).toggleClass(\"$class\");"; + $str = "$({$element}).toggleClass(\"$class\");"; return $str; } - + // -------------------------------------------------------------------- - + /** * Show * @@ -678,16 +678,16 @@ class CI_Jquery extends CI_Javascript { */ function _show($element = 'this', $speed = '', $callback = '') { - $element = $this->_prep_element($element); + $element = $this->_prep_element($element); $speed = $this->_validate_speed($speed); - + if ($callback != '') { $callback = ", function(){\n{$callback}\n}"; } - - $str = "$({$element}).show({$speed}{$callback});"; - + + $str = "$({$element}).show({$speed}{$callback});"; + return $str; } @@ -696,7 +696,7 @@ class CI_Jquery extends CI_Javascript { /** * Updater * - * An Ajax call that populates the designated DOM node with + * An Ajax call that populates the designated DOM node with * returned content * * @access private @@ -705,13 +705,13 @@ class CI_Jquery extends CI_Javascript { * @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') == '') { @@ -721,7 +721,7 @@ class CI_Jquery extends CI_Javascript { { $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 @@ -741,7 +741,7 @@ class CI_Jquery extends CI_Javascript { // -------------------------------------------------------------------- // Pre-written handy stuff // -------------------------------------------------------------------- - + /** * Zebra tables * @@ -753,8 +753,8 @@ class CI_Jquery extends CI_Javascript { function _zebraTables($class = '', $odd = 'odd', $hover = '') { $class = ($class != '') ? '.'.$class : ''; - - $zebra = "\t\$(\"table{$class} tbody tr:nth-child(even)\").addClass(\"{$odd}\");"; + + $zebra = "\t\$(\"table{$class} tbody tr:nth-child(even)\").addClass(\"{$odd}\");"; $this->jquery_code_for_compile[] = $zebra; @@ -771,7 +771,7 @@ class CI_Jquery extends CI_Javascript { // -------------------------------------------------------------------- // Plugins // -------------------------------------------------------------------- - + /** * Corner Plugin * @@ -793,7 +793,7 @@ class CI_Jquery extends CI_Javascript { return "$(" . $this->_prep_element($element) . ").corner(".$corner_style.");"; } - + // -------------------------------------------------------------------- /** @@ -805,7 +805,7 @@ class CI_Jquery extends CI_Javascript { * @return void */ function modal($src, $relative = FALSE) - { + { $this->jquery_code_for_load[] = $this->external($src, $relative); } @@ -897,7 +897,7 @@ class CI_Jquery extends CI_Javascript { { $this->jquery_code_for_compile[] = "\t$(" . $this->_prep_element($table) . ").tablesorter($options);\n"; } - + // -------------------------------------------------------------------- // Class functions // -------------------------------------------------------------------- @@ -912,7 +912,7 @@ class CI_Jquery extends CI_Javascript { * @param string The code to execute * @param string The event to pass * @return string - */ + */ function _add_event($element, $js, $event) { if (is_array($js)) @@ -953,15 +953,15 @@ class CI_Jquery extends CI_Javascript { $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 * @@ -976,7 +976,7 @@ class CI_Jquery extends CI_Javascript { } // -------------------------------------------------------------------- - + /** * Document Ready * @@ -992,7 +992,7 @@ class CI_Jquery extends CI_Javascript { $js = array ($js); } - + foreach ($js as $script) { $this->jquery_code_for_compile[] = $script; @@ -1016,7 +1016,7 @@ class CI_Jquery extends CI_Javascript { $this->jquery_code_for_load[] = $library_src; return $library_src; } - + // -------------------------------------------------------------------- /** @@ -1036,10 +1036,10 @@ class CI_Jquery extends CI_Javascript { { $element = '"'.$element.'"'; } - + return $element; } - + // -------------------------------------------------------------------- /** @@ -1050,7 +1050,7 @@ class CI_Jquery extends CI_Javascript { * @access private * @param string * @return string - */ + */ function _validate_speed($speed) { if (in_array($speed, array('slow', 'normal', 'fast'))) @@ -1061,7 +1061,7 @@ class CI_Jquery extends CI_Javascript { { $speed = ''; } - + return $speed; } -- cgit v1.2.3-24-g4f1b From db726c67ef1235aecf8f996306489e2febb700ec Mon Sep 17 00:00:00 2001 From: Derek Jones Date: Sun, 3 Jul 2011 07:20:58 -0500 Subject: reverted texb.ttf font which had been compromised in 982b43c3590a by a another massive whitespace 'cleanup' commit --- system/fonts/texb.ttf | Bin 152992 -> 143830 bytes 1 file changed, 0 insertions(+), 0 deletions(-) (limited to 'system') diff --git a/system/fonts/texb.ttf b/system/fonts/texb.ttf index 6792342a3..383c88b86 100644 Binary files a/system/fonts/texb.ttf and b/system/fonts/texb.ttf differ -- cgit v1.2.3-24-g4f1b From 26b9ae2f500da7658074619af9c6dd982b77d0b8 Mon Sep 17 00:00:00 2001 From: Phil Sturgeon Date: Fri, 15 Jul 2011 15:14:05 -0600 Subject: Was working on this file so PHP5ified the method visibility scopes. Pointless, but was adding... --- system/database/DB_active_rec.php | 260 ++++++++++++++++---------------------- 1 file changed, 106 insertions(+), 154 deletions(-) (limited to 'system') diff --git a/system/database/DB_active_rec.php b/system/database/DB_active_rec.php index 52bad260a..7ddf20d07 100644 --- a/system/database/DB_active_rec.php +++ b/system/database/DB_active_rec.php @@ -69,11 +69,10 @@ class CI_DB_active_record extends CI_DB_driver { * * Generates the SELECT portion of the query * - * @access public * @param string * @return object */ - function select($select = '*', $escape = NULL) + public function select($select = '*', $escape = NULL) { if (is_string($select)) { @@ -107,12 +106,11 @@ class CI_DB_active_record extends CI_DB_driver { * * Generates a SELECT MAX(field) portion of a query * - * @access public * @param string the field * @param string an alias * @return object */ - function select_max($select = '', $alias = '') + public function select_max($select = '', $alias = '') { return $this->_max_min_avg_sum($select, $alias, 'MAX'); } @@ -124,12 +122,11 @@ class CI_DB_active_record extends CI_DB_driver { * * Generates a SELECT MIN(field) portion of a query * - * @access public * @param string the field * @param string an alias * @return object */ - function select_min($select = '', $alias = '') + public function select_min($select = '', $alias = '') { return $this->_max_min_avg_sum($select, $alias, 'MIN'); } @@ -141,12 +138,11 @@ class CI_DB_active_record extends CI_DB_driver { * * Generates a SELECT AVG(field) portion of a query * - * @access public * @param string the field * @param string an alias * @return object */ - function select_avg($select = '', $alias = '') + public function select_avg($select = '', $alias = '') { return $this->_max_min_avg_sum($select, $alias, 'AVG'); } @@ -158,12 +154,11 @@ class CI_DB_active_record extends CI_DB_driver { * * Generates a SELECT SUM(field) portion of a query * - * @access public * @param string the field * @param string an alias * @return object */ - function select_sum($select = '', $alias = '') + public function select_sum($select = '', $alias = '') { return $this->_max_min_avg_sum($select, $alias, 'SUM'); } @@ -178,12 +173,11 @@ class CI_DB_active_record extends CI_DB_driver { * select_avg() * select_sum() * - * @access public * @param string the field * @param string an alias * @return object */ - function _max_min_avg_sum($select = '', $alias = '', $type = 'MAX') + protected function _max_min_avg_sum($select = '', $alias = '', $type = 'MAX') { if ( ! is_string($select) OR $select == '') { @@ -220,11 +214,10 @@ class CI_DB_active_record extends CI_DB_driver { /** * Determines the alias name based on the table * - * @access private * @param string * @return string */ - function _create_alias_from_table($item) + protected function _create_alias_from_table($item) { if (strpos($item, '.') !== FALSE) { @@ -241,11 +234,10 @@ class CI_DB_active_record extends CI_DB_driver { * * Sets a flag which tells the query string compiler to add DISTINCT * - * @access public * @param bool * @return object */ - function distinct($val = TRUE) + public function distinct($val = TRUE) { $this->ar_distinct = (is_bool($val)) ? $val : TRUE; return $this; @@ -258,11 +250,10 @@ class CI_DB_active_record extends CI_DB_driver { * * Generates the FROM portion of the query * - * @access public * @param mixed can be a string or array * @return object */ - function from($from) + public function from($from) { foreach ((array)$from as $val) { @@ -311,13 +302,12 @@ class CI_DB_active_record extends CI_DB_driver { * * Generates the JOIN portion of the query * - * @access public * @param string * @param string the join condition * @param string the type of join * @return object */ - function join($table, $cond, $type = '') + public function join($table, $cond, $type = '') { if ($type != '') { @@ -367,12 +357,11 @@ class CI_DB_active_record extends CI_DB_driver { * Generates the WHERE portion of the query. Separates * multiple calls with AND * - * @access public * @param mixed * @param mixed * @return object */ - function where($key, $value = NULL, $escape = TRUE) + public function where($key, $value = NULL, $escape = TRUE) { return $this->_where($key, $value, 'AND ', $escape); } @@ -385,12 +374,11 @@ class CI_DB_active_record extends CI_DB_driver { * Generates the WHERE portion of the query. Separates * multiple calls with OR * - * @access public * @param mixed * @param mixed * @return object */ - function or_where($key, $value = NULL, $escape = TRUE) + public function or_where($key, $value = NULL, $escape = TRUE) { return $this->_where($key, $value, 'OR ', $escape); } @@ -400,15 +388,14 @@ class CI_DB_active_record extends CI_DB_driver { /** * Where * - * Called by where() or orwhere() + * Called by where() or or_where() * - * @access private * @param mixed * @param mixed * @param string * @return object */ - function _where($key, $value = NULL, $type = 'AND ', $escape = NULL) + protected function _where($key, $value = NULL, $type = 'AND ', $escape = NULL) { if ( ! is_array($key)) { @@ -471,12 +458,11 @@ class CI_DB_active_record extends CI_DB_driver { * Generates a WHERE field IN ('item', 'item') SQL query joined with * AND if appropriate * - * @access public * @param string The field to search * @param array The values searched on * @return object */ - function where_in($key = NULL, $values = NULL) + public function where_in($key = NULL, $values = NULL) { return $this->_where_in($key, $values); } @@ -489,12 +475,11 @@ class CI_DB_active_record extends CI_DB_driver { * Generates a WHERE field IN ('item', 'item') SQL query joined with * OR if appropriate * - * @access public * @param string The field to search * @param array The values searched on * @return object */ - function or_where_in($key = NULL, $values = NULL) + public function or_where_in($key = NULL, $values = NULL) { return $this->_where_in($key, $values, FALSE, 'OR '); } @@ -507,12 +492,11 @@ class CI_DB_active_record extends CI_DB_driver { * Generates a WHERE field NOT IN ('item', 'item') SQL query joined * with AND if appropriate * - * @access public * @param string The field to search * @param array The values searched on * @return object */ - function where_not_in($key = NULL, $values = NULL) + public function where_not_in($key = NULL, $values = NULL) { return $this->_where_in($key, $values, TRUE); } @@ -525,12 +509,11 @@ class CI_DB_active_record extends CI_DB_driver { * Generates a WHERE field NOT IN ('item', 'item') SQL query joined * with OR if appropriate * - * @access public * @param string The field to search * @param array The values searched on * @return object */ - function or_where_not_in($key = NULL, $values = NULL) + public function or_where_not_in($key = NULL, $values = NULL) { return $this->_where_in($key, $values, TRUE, 'OR '); } @@ -542,14 +525,13 @@ class CI_DB_active_record extends CI_DB_driver { * * Called by where_in, where_in_or, where_not_in, where_not_in_or * - * @access public * @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 */ - function _where_in($key = NULL, $values = NULL, $not = FALSE, $type = 'AND ') + protected function _where_in($key = NULL, $values = NULL, $not = FALSE, $type = 'AND ') { if ($key === NULL OR $values === NULL) { @@ -592,12 +574,11 @@ class CI_DB_active_record extends CI_DB_driver { * Generates a %LIKE% portion of the query. Separates * multiple calls with AND * - * @access public * @param mixed * @param mixed * @return object */ - function like($field, $match = '', $side = 'both') + public function like($field, $match = '', $side = 'both') { return $this->_like($field, $match, 'AND ', $side); } @@ -610,12 +591,11 @@ class CI_DB_active_record extends CI_DB_driver { * Generates a NOT LIKE portion of the query. Separates * multiple calls with AND * - * @access public * @param mixed * @param mixed * @return object */ - function not_like($field, $match = '', $side = 'both') + public function not_like($field, $match = '', $side = 'both') { return $this->_like($field, $match, 'AND ', $side, 'NOT'); } @@ -628,12 +608,11 @@ class CI_DB_active_record extends CI_DB_driver { * Generates a %LIKE% portion of the query. Separates * multiple calls with OR * - * @access public * @param mixed * @param mixed * @return object */ - function or_like($field, $match = '', $side = 'both') + public function or_like($field, $match = '', $side = 'both') { return $this->_like($field, $match, 'OR ', $side); } @@ -646,12 +625,11 @@ class CI_DB_active_record extends CI_DB_driver { * Generates a NOT LIKE portion of the query. Separates * multiple calls with OR * - * @access public * @param mixed * @param mixed * @return object */ - function or_not_like($field, $match = '', $side = 'both') + public function or_not_like($field, $match = '', $side = 'both') { return $this->_like($field, $match, 'OR ', $side, 'NOT'); } @@ -663,13 +641,12 @@ class CI_DB_active_record extends CI_DB_driver { * * Called by like() or orlike() * - * @access private * @param mixed * @param mixed * @param string * @return object */ - function _like($field, $match = '', $type = 'AND ', $side = 'both', $not = '') + protected function _like($field, $match = '', $type = 'AND ', $side = 'both', $not = '') { if ( ! is_array($field)) { @@ -719,11 +696,10 @@ class CI_DB_active_record extends CI_DB_driver { /** * GROUP BY * - * @access public * @param string * @return object */ - function group_by($by) + public function group_by($by) { if (is_string($by)) { @@ -755,12 +731,11 @@ class CI_DB_active_record extends CI_DB_driver { * * Separates multiple calls with AND * - * @access public * @param string * @param string * @return object */ - function having($key, $value = '', $escape = TRUE) + public function having($key, $value = '', $escape = TRUE) { return $this->_having($key, $value, 'AND ', $escape); } @@ -772,12 +747,11 @@ class CI_DB_active_record extends CI_DB_driver { * * Separates multiple calls with OR * - * @access public * @param string * @param string * @return object */ - function or_having($key, $value = '', $escape = TRUE) + public function or_having($key, $value = '', $escape = TRUE) { return $this->_having($key, $value, 'OR ', $escape); } @@ -789,12 +763,11 @@ class CI_DB_active_record extends CI_DB_driver { * * Called by having() or or_having() * - * @access private * @param string * @param string * @return object */ - function _having($key, $value = '', $type = 'AND ', $escape = TRUE) + protected function _having($key, $value = '', $type = 'AND ', $escape = TRUE) { if ( ! is_array($key)) { @@ -836,12 +809,11 @@ class CI_DB_active_record extends CI_DB_driver { /** * Sets the ORDER BY value * - * @access public * @param string * @param string direction: asc or desc * @return object */ - function order_by($orderby, $direction = '') + public function order_by($orderby, $direction = '') { if (strtolower($direction) == 'random') { @@ -892,12 +864,11 @@ class CI_DB_active_record extends CI_DB_driver { /** * Sets the LIMIT value * - * @access public * @param integer the limit value * @param integer the offset value * @return object */ - function limit($value, $offset = '') + public function limit($value, $offset = '') { $this->ar_limit = $value; @@ -914,11 +885,10 @@ class CI_DB_active_record extends CI_DB_driver { /** * Sets the OFFSET value * - * @access public * @param integer the offset value * @return object */ - function offset($offset) + public function offset($offset) { $this->ar_offset = $offset; return $this; @@ -929,13 +899,12 @@ class CI_DB_active_record extends CI_DB_driver { /** * The "set" function. Allows key/value pairs to be set for inserting or updating * - * @access public * @param mixed * @param string * @param boolean * @return object */ - function set($key, $value = '', $escape = TRUE) + public function set($key, $value = '', $escape = TRUE) { $key = $this->_object_to_array($key); @@ -967,13 +936,12 @@ class CI_DB_active_record extends CI_DB_driver { * Compiles the select statement based on the other functions called * and runs the query * - * @access public * @param string the table * @param string the limit clause * @param string the offset clause * @return object */ - function get($table = '', $limit = null, $offset = null) + public function get($table = '', $limit = null, $offset = null) { if ($table != '') { @@ -999,11 +967,10 @@ class CI_DB_active_record extends CI_DB_driver { * Generates a platform-specific query string that counts all records * returned by an Active Record query. * - * @access public * @param string * @return string */ - function count_all_results($table = '') + public function count_all_results($table = '') { if ($table != '') { @@ -1032,13 +999,12 @@ class CI_DB_active_record extends CI_DB_driver { * * Allows the where clause, limit and offset to be added directly * - * @access public * @param string the where clause * @param string the limit clause * @param string the offset clause * @return object */ - function get_where($table = '', $where = null, $limit = null, $offset = null) + public function get_where($table = '', $where = null, $limit = null, $offset = null) { if ($table != '') { @@ -1069,12 +1035,11 @@ class CI_DB_active_record extends CI_DB_driver { * * Compiles batch insert strings and runs the queries * - * @access public * @param string the table to retrieve the results from * @param array an associative array of insert values * @return object */ - function insert_batch($table = '', $set = NULL) + public function insert_batch($table = '', $set = NULL) { if ( ! is_null($set)) { @@ -1127,14 +1092,12 @@ class CI_DB_active_record extends CI_DB_driver { /** * The "set_insert_batch" function. Allows key/value pairs to be set for batch inserts * - * @access public * @param mixed * @param string * @param boolean * @return object */ - - function set_insert_batch($key, $value = '', $escape = TRUE) + public function set_insert_batch($key, $value = '', $escape = TRUE) { $key = $this->_object_to_array_batch($key); @@ -1189,8 +1152,7 @@ class CI_DB_active_record extends CI_DB_driver { * * Compiles an insert string and runs the query * - * @access public - * @param string the table to retrieve the results from + * @param string the table to insert data into * @param array an associative array of insert values * @return object */ @@ -1230,7 +1192,18 @@ class CI_DB_active_record extends CI_DB_driver { return $this->query($sql); } - function replace($table = '', $set = NULL) + // -------------------------------------------------------------------- + + /** + * 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)) { @@ -1273,13 +1246,12 @@ class CI_DB_active_record extends CI_DB_driver { * * Compiles an update string and runs the query * - * @access public * @param string the table to retrieve the results from * @param array an associative array of update values * @param mixed the where clause * @return object */ - function update($table = '', $set = NULL, $where = NULL, $limit = NULL) + public function update($table = '', $set = NULL, $where = NULL, $limit = NULL) { // Combine any cached components with the current statements $this->_merge_cache(); @@ -1336,13 +1308,12 @@ class CI_DB_active_record extends CI_DB_driver { * * Compiles an update string and runs the query * - * @access public * @param string the table to retrieve the results from * @param array an associative array of update values * @param string the where key * @return object */ - function update_batch($table = '', $set = NULL, $index = NULL) + public function update_batch($table = '', $set = NULL, $index = NULL) { // Combine any cached components with the current statements $this->_merge_cache(); @@ -1402,14 +1373,12 @@ class CI_DB_active_record extends CI_DB_driver { /** * The "set_update_batch" function. Allows key/value pairs to be set for batch updating * - * @access public * @param array * @param string * @param boolean * @return object */ - - function set_update_batch($key, $index = '', $escape = TRUE) + public function set_update_batch($key, $index = '', $escape = TRUE) { $key = $this->_object_to_array_batch($key); @@ -1462,11 +1431,10 @@ class CI_DB_active_record extends CI_DB_driver { * * Compiles a delete string and runs "DELETE FROM table" * - * @access public * @param string the table to empty * @return object */ - function empty_table($table = '') + public function empty_table($table = '') { if ($table == '') { @@ -1502,11 +1470,10 @@ class CI_DB_active_record extends CI_DB_driver { * If the database does not support the truncate() command * This function maps to "DELETE FROM table" * - * @access public * @param string the table to truncate * @return object */ - function truncate($table = '') + public function truncate($table = '') { if ($table == '') { @@ -1540,14 +1507,13 @@ class CI_DB_active_record extends CI_DB_driver { * * Compiles a delete string and runs the query * - * @access public * @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 */ - function delete($table = '', $where = '', $limit = NULL, $reset_data = TRUE) + public function delete($table = '', $where = '', $limit = NULL, $reset_data = TRUE) { // Combine any cached components with the current statements $this->_merge_cache(); @@ -1617,11 +1583,10 @@ class CI_DB_active_record extends CI_DB_driver { * * Prepends a database prefix if one exists in configuration * - * @access public * @param string the table * @return string */ - function dbprefix($table = '') + public function dbprefix($table = '') { if ($table == '') { @@ -1638,11 +1603,10 @@ class CI_DB_active_record extends CI_DB_driver { * * Used to track SQL statements written with aliased tables. * - * @access private * @param string The table to inspect * @return string */ - function _track_aliases($table) + protected function _track_aliases($table) { if (is_array($table)) { @@ -1685,10 +1649,9 @@ class CI_DB_active_record extends CI_DB_driver { * Generates a query string based on which functions were used. * Should not be called directly. The get() function calls it. * - * @access private * @return string */ - function _compile_select($select_override = FALSE) + protected function _compile_select($select_override = FALSE) { // Combine any cached components with the current statements $this->_merge_cache(); @@ -1826,11 +1789,10 @@ class CI_DB_active_record extends CI_DB_driver { * * Takes an object as input and converts the class variables to array key/vals * - * @access public * @param object * @return array */ - function _object_to_array($object) + public function _object_to_array($object) { if ( ! is_object($object)) { @@ -1857,11 +1819,10 @@ class CI_DB_active_record extends CI_DB_driver { * * Takes an object as input and converts the class variables to array key/vals * - * @access public * @param object * @return array */ - function _object_to_array_batch($object) + public function _object_to_array_batch($object) { if ( ! is_object($object)) { @@ -1897,10 +1858,9 @@ class CI_DB_active_record extends CI_DB_driver { * * Starts AR caching * - * @access public * @return void */ - function start_cache() + public function start_cache() { $this->ar_caching = TRUE; } @@ -1912,10 +1872,9 @@ class CI_DB_active_record extends CI_DB_driver { * * Stops AR caching * - * @access public * @return void */ - function stop_cache() + public function stop_cache() { $this->ar_caching = FALSE; } @@ -1930,23 +1889,21 @@ class CI_DB_active_record extends CI_DB_driver { * @access public * @return void */ - function flush_cache() + 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() - ) - ); + $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() + )); } // -------------------------------------------------------------------- @@ -1957,10 +1914,9 @@ class CI_DB_active_record extends CI_DB_driver { * When called, this function merges any cached AR arrays with * locally called ones. * - * @access private * @return void */ - function _merge_cache() + protected function _merge_cache() { if (count($this->ar_cache_exists) == 0) { @@ -1995,11 +1951,10 @@ class CI_DB_active_record extends CI_DB_driver { /** * Resets the active record values. Called by the get() function * - * @access private * @param array An array of fields to reset * @return void */ - function _reset_run($ar_reset_items) + protected function _reset_run($ar_reset_items) { foreach ($ar_reset_items as $item => $default_value) { @@ -2015,28 +1970,27 @@ class CI_DB_active_record extends CI_DB_driver { /** * Resets the active record values. Called by the get() function * - * @access private * @return void */ - function _reset_select() + 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, - ); + '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); } @@ -2048,25 +2002,23 @@ class CI_DB_active_record extends CI_DB_driver { * * Called by the insert() update() insert_batch() update_batch() and delete() functions * - * @access private * @return void */ - function _reset_write() + 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 - ); + '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 */ -- cgit v1.2.3-24-g4f1b From 5025929d76172efd6dd3a7b0f4da7611a3df9391 Mon Sep 17 00:00:00 2001 From: Phil Sturgeon Date: Fri, 15 Jul 2011 15:25:15 -0600 Subject: Fixed conflicted changelog. --- system/database/DB_active_rec.php | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'system') diff --git a/system/database/DB_active_rec.php b/system/database/DB_active_rec.php index 7ddf20d07..bc11ff436 100644 --- a/system/database/DB_active_rec.php +++ b/system/database/DB_active_rec.php @@ -1598,6 +1598,21 @@ class CI_DB_active_record extends CI_DB_driver { // -------------------------------------------------------------------- + /** + * 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 * -- cgit v1.2.3-24-g4f1b From 72038ba6fd2e8196623bf1bd1a38756ad41ce905 Mon Sep 17 00:00:00 2001 From: MarcosCoelho Date: Mon, 18 Jul 2011 16:12:47 -0300 Subject: sync total items count and total amount price; by sum of quantity of each item in cart --- system/libraries/Cart.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'system') diff --git a/system/libraries/Cart.php b/system/libraries/Cart.php index 7f65b48b9..b2eaa9ad7 100644 --- a/system/libraries/Cart.php +++ b/system/libraries/Cart.php @@ -374,6 +374,7 @@ class CI_Cart { // 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 @@ -383,13 +384,14 @@ class CI_Cart { } $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'] = count($this->_cart_contents); + $this->_cart_contents['total_items'] = $items; $this->_cart_contents['cart_total'] = $total; // Is our cart empty? If so we delete it from the session -- cgit v1.2.3-24-g4f1b From e0df07950b101316c07ccec882ae00f930bca0c6 Mon Sep 17 00:00:00 2001 From: Phil Sturgeon Date: Fri, 22 Jul 2011 16:11:34 -0600 Subject: Fixed conflict in changelog. --- system/core/Loader.php | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'system') diff --git a/system/core/Loader.php b/system/core/Loader.php index 721c196cc..7c8b298ac 100644 --- a/system/core/Loader.php +++ b/system/core/Loader.php @@ -388,6 +388,21 @@ class CI_Loader { // -------------------------------------------------------------------- + /** + * 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 * -- cgit v1.2.3-24-g4f1b From b13a0dd78f0d0449e3ee9eb350ac06594beb3252 Mon Sep 17 00:00:00 2001 From: Eric Barnes Date: Mon, 18 Jul 2011 00:13:07 -0400 Subject: Fixed issue #199 - Attributes passed as string does not include a space between it and the opening tag. --- system/helpers/html_helper.php | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'system') diff --git a/system/helpers/html_helper.php b/system/helpers/html_helper.php index 080f622dd..b64b60650 100644 --- a/system/helpers/html_helper.php +++ b/system/helpers/html_helper.php @@ -124,6 +124,10 @@ if ( ! function_exists('_list')) } $attributes = $atts; } + elseif (is_string($attributes) AND strlen($attributes) > 0) + { + $attributes = ' '. $attributes; + } // Write the opening list tag $out .= "<".$type.$attributes.">\n"; -- cgit v1.2.3-24-g4f1b From 40b28e9139f3486971fe6f13594d3f615a37862c Mon Sep 17 00:00:00 2001 From: Adam Jackett Date: Sat, 23 Jul 2011 11:45:05 -0400 Subject: Fixed having method to insert quotes. --- system/database/DB_active_rec.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system') diff --git a/system/database/DB_active_rec.php b/system/database/DB_active_rec.php index bc11ff436..0a25b3cb5 100644 --- a/system/database/DB_active_rec.php +++ b/system/database/DB_active_rec.php @@ -790,7 +790,7 @@ class CI_DB_active_record extends CI_DB_driver { if ($v != '') { - $v = ' '.$this->escape_str($v); + $v = ' '.$this->escape($v); } $this->ar_having[] = $prefix.$k.$v; -- cgit v1.2.3-24-g4f1b From c5961e7d778d5a9361df4cfbc7da5fc4370d883f Mon Sep 17 00:00:00 2001 From: Adam Jackett Date: Sat, 23 Jul 2011 09:50:34 -0400 Subject: Fixed mysql and mysqli drivers to set NOT NULL as default for creating fields. All other drivers were correct. --- system/database/drivers/mysql/mysql_forge.php | 8 ++++++-- system/database/drivers/mysqli/mysqli_forge.php | 8 ++++++-- 2 files changed, 12 insertions(+), 4 deletions(-) (limited to 'system') diff --git a/system/database/drivers/mysql/mysql_forge.php b/system/database/drivers/mysql/mysql_forge.php index 529ec980d..c1cae136c 100644 --- a/system/database/drivers/mysql/mysql_forge.php +++ b/system/database/drivers/mysql/mysql_forge.php @@ -119,9 +119,13 @@ class CI_DB_mysql_forge extends CI_DB_forge { $sql .= ' DEFAULT \''.$attributes['DEFAULT'].'\''; } - if (array_key_exists('NULL', $attributes)) + if (array_key_exists('NULL', $attributes) && $attributes['NULL'] === TRUE) { - $sql .= ($attributes['NULL'] === TRUE) ? ' NULL' : ' NOT NULL'; + $sql .= ' NULL'; + } + else + { + $sql .= ' NOT NULL'; } if (array_key_exists('AUTO_INCREMENT', $attributes) && $attributes['AUTO_INCREMENT'] === TRUE) diff --git a/system/database/drivers/mysqli/mysqli_forge.php b/system/database/drivers/mysqli/mysqli_forge.php index d5097335e..260549457 100644 --- a/system/database/drivers/mysqli/mysqli_forge.php +++ b/system/database/drivers/mysqli/mysqli_forge.php @@ -104,9 +104,13 @@ class CI_DB_mysqli_forge extends CI_DB_forge { $sql .= ' DEFAULT \''.$attributes['DEFAULT'].'\''; } - if (array_key_exists('NULL', $attributes)) + if (array_key_exists('NULL', $attributes) && $attributes['NULL'] === TRUE) { - $sql .= ($attributes['NULL'] === TRUE) ? ' NULL' : ' NOT NULL'; + $sql .= ' NULL'; + } + else + { + $sql .= ' NOT NULL'; } if (array_key_exists('AUTO_INCREMENT', $attributes) && $attributes['AUTO_INCREMENT'] === TRUE) -- cgit v1.2.3-24-g4f1b From 76e621786007907192c3e84cbde3e1a12dbf83fb Mon Sep 17 00:00:00 2001 From: Phil Sturgeon Date: Tue, 9 Aug 2011 16:03:49 -0600 Subject: Fixed conflict in changelog. --- system/database/DB_active_rec.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'system') diff --git a/system/database/DB_active_rec.php b/system/database/DB_active_rec.php index 0a25b3cb5..2af3553ed 100644 --- a/system/database/DB_active_rec.php +++ b/system/database/DB_active_rec.php @@ -1694,7 +1694,8 @@ class CI_DB_active_record extends CI_DB_driver { // is because until the user calls the from() function we don't know if there are aliases foreach ($this->ar_select as $key => $val) { - $this->ar_select[$key] = $this->_protect_identifiers($val, FALSE, $this->ar_no_escape[$key]); + $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); -- cgit v1.2.3-24-g4f1b From 99f6c8c4d71714e62a86cee5d2f7fbfa496a3c5a Mon Sep 17 00:00:00 2001 From: Phil Sturgeon Date: Sat, 13 Aug 2011 10:26:04 -0600 Subject: Improved logic for plural() and singular() as words like "tax" would become "taxs" and it was tough to code in new rules. --- system/helpers/inflector_helper.php | 115 +++++++++++++++++++++--------------- 1 file changed, 67 insertions(+), 48 deletions(-) (limited to 'system') diff --git a/system/helpers/inflector_helper.php b/system/helpers/inflector_helper.php index c7c113b8a..7b99bc5b4 100644 --- a/system/helpers/inflector_helper.php +++ b/system/helpers/inflector_helper.php @@ -41,30 +41,48 @@ if ( ! function_exists('singular')) { function singular($str) { - $str = trim($str); - $end = substr($str, -3); - - $str = preg_replace('/(.*)?([s|c]h)es/i','$1$2',$str); - - if (strtolower($end) == 'ies') + $result = strval($str); + + $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', + '/([^u])s$/' => '\1', + ); + + foreach ($singular_rules as $rule => $replacement) { - $str = substr($str, 0, strlen($str)-3).(preg_match('/[a-z]/',$end) ? 'y' : 'Y'); - } - elseif (strtolower($end) == 'ses') - { - $str = substr($str, 0, strlen($str)-2); - } - else - { - $end = strtolower(substr($str, -1)); - - if ($end == 's') + if (preg_match($rule, $result)) { - $str = substr($str, 0, strlen($str)-1); + $result = preg_replace($rule, $replacement, $result); + break; } } - return $str; + return $result; } } @@ -83,40 +101,41 @@ if ( ! function_exists('singular')) if ( ! function_exists('plural')) { function plural($str, $force = FALSE) - { - $str = trim($str); - $end = substr($str, -1); - - if (preg_match('/y/i',$end)) - { - // Y preceded by vowel => regular plural - $vowels = array('a', 'e', 'i', 'o', 'u', 'A', 'E', 'I', 'O', 'U'); - $str = in_array(substr($str, -2, 1), $vowels) ? $str.'s' : substr($str, 0, -1).'ies'; - } - elseif (preg_match('/h/i',$end)) - { - if(preg_match('/^[c|s]h$/i',substr($str, -2))) - { - $str .= 'es'; - } - else - { - $str .= 's'; - } - } - elseif (preg_match('/s/i',$end)) + { + $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 ($force == TRUE) + if (preg_match($rule, $result)) { - $str .= 'es'; + $result = preg_replace($rule, $replacement, $result); + break; } } - else - { - $str .= 's'; - } - return $str; + return $result; } } -- cgit v1.2.3-24-g4f1b From fe1d45a023b08753f4c5f1d908d54ae842277558 Mon Sep 17 00:00:00 2001 From: Phil Sturgeon Date: Sat, 13 Aug 2011 11:06:57 -0600 Subject: Fixed conflicts. --- system/core/Input.php | 2 +- system/core/URI.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'system') diff --git a/system/core/Input.php b/system/core/Input.php index dc7612e64..cfbef942d 100644 --- a/system/core/Input.php +++ b/system/core/Input.php @@ -672,7 +672,7 @@ class CI_Input { */ public function is_cli_request() { - return (bool) defined('STDIN'); + return (php_sapi_name() == 'cli') or defined('STDIN'); } } diff --git a/system/core/URI.php b/system/core/URI.php index d56548654..20f0f006b 100644 --- a/system/core/URI.php +++ b/system/core/URI.php @@ -62,7 +62,7 @@ class CI_URI { if (strtoupper($this->config->item('uri_protocol')) == 'AUTO') { // Is the request coming from the command line? - if (defined('STDIN')) + if (php_sapi_name() == 'cli' or defined('STDIN')) { $this->_set_uri_string($this->_parse_cli_args()); return; -- cgit v1.2.3-24-g4f1b From 9d887b32a1fe998cbb0307a5e678ac3ba5076a1e Mon Sep 17 00:00:00 2001 From: Phil Sturgeon Date: Wed, 10 Aug 2011 08:06:37 -0600 Subject: Fixed conflicts in changelog. --- system/libraries/Email.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system') diff --git a/system/libraries/Email.php b/system/libraries/Email.php index cd89f8f3d..03eccea09 100644 --- a/system/libraries/Email.php +++ b/system/libraries/Email.php @@ -395,7 +395,7 @@ class CI_Email { public function attach($filename, $disposition = 'attachment') { $this->_attach_name[] = $filename; - $this->_attach_type[] = $this->_mime_types(next(explode('.', basename($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; } -- cgit v1.2.3-24-g4f1b From 4c76272593d82f45761c24917e69b42983f26171 Mon Sep 17 00:00:00 2001 From: Phil Sturgeon Date: Sat, 13 Aug 2011 11:31:22 -0600 Subject: Bumped the version number. Can somebody with a working find and replace fix up the docs? --- system/core/CodeIgniter.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system') diff --git a/system/core/CodeIgniter.php b/system/core/CodeIgniter.php index 03b25ab9e..94fecb5c0 100644 --- a/system/core/CodeIgniter.php +++ b/system/core/CodeIgniter.php @@ -32,7 +32,7 @@ * Define the CodeIgniter Version * ------------------------------------------------------ */ - define('CI_VERSION', '2.0.2'); + define('CI_VERSION', '2.0.3'); /* * ------------------------------------------------------ -- cgit v1.2.3-24-g4f1b