diff options
170 files changed, 5517 insertions, 4297 deletions
diff --git a/.travis.yml b/.travis.yml index 2584e8ac2..84029b964 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,16 +1,23 @@ language: php php: - - 5.2 - 5.3 - 5.4 +env: + - DB=mysql + - DB=pgsql + - DB=sqlite + before_script: - pyrus channel-discover pear.php-tools.net - pyrus install http://pear.php-tools.net/get/vfsStream-0.11.2.tgz - phpenv rehash + - sh -c "if [ '$DB' = 'pgsql' ]; then psql -c 'DROP DATABASE IF EXISTS ci_test;' -U postgres; fi" + - sh -c "if [ '$DB' = 'pgsql' ]; then psql -c 'create database ci_test;' -U postgres; fi" + - sh -c "if [ '$DB' = 'mysql' ]; then mysql -e 'create database IF NOT EXISTS ci_test;'; fi" -script: phpunit --configuration tests/phpunit.xml +script: phpunit --configuration tests/travis/$DB.phpunit.xml branches: only: diff --git a/application/config/autoload.php b/application/config/autoload.php index e8c999334..b3e63cbf6 100644 --- a/application/config/autoload.php +++ b/application/config/autoload.php @@ -1,13 +1,13 @@ -<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed'); +<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed'); /** * CodeIgniter * * An open source application development framework for PHP 5.2.4 or newer * * NOTICE OF LICENSE - * + * * Licensed under the Academic Free License version 3.0 - * + * * This source file is subject to the Academic Free License (AFL 3.0) that is * bundled with this package in the files license_afl.txt / license_afl.rst. * It is also available through the world wide web at this URL: diff --git a/application/config/config.php b/application/config/config.php index 2ffbb6693..2628885f0 100644 --- a/application/config/config.php +++ b/application/config/config.php @@ -1,13 +1,13 @@ -<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed'); +<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed'); /** * CodeIgniter * * An open source application development framework for PHP 5.2.4 or newer * * NOTICE OF LICENSE - * + * * Licensed under the Academic Free License version 3.0 - * + * * This source file is subject to the Academic Free License (AFL 3.0) that is * bundled with this package in the files license_afl.txt / license_afl.rst. * It is also available through the world wide web at this URL: diff --git a/application/config/constants.php b/application/config/constants.php index fce101320..d22d2963e 100644 --- a/application/config/constants.php +++ b/application/config/constants.php @@ -1,13 +1,13 @@ -<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed'); +<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed'); /** * CodeIgniter * * An open source application development framework for PHP 5.2.4 or newer * * NOTICE OF LICENSE - * + * * Licensed under the Academic Free License version 3.0 - * + * * This source file is subject to the Academic Free License (AFL 3.0) that is * bundled with this package in the files license_afl.txt / license_afl.rst. * It is also available through the world wide web at this URL: @@ -66,8 +66,8 @@ define('FOPEN_READ_WRITE_CREATE_STRICT', 'x+b'); | Display Debug backtrace |-------------------------------------------------------------------------- | -| If set to TRUE, a backtrace will be displayed along with php errors. If -| error_reporting is disabled, the backtrace will not display, regardless +| If set to TRUE, a backtrace will be displayed along with php errors. If +| error_reporting is disabled, the backtrace will not display, regardless | of this setting | */ diff --git a/application/config/database.php b/application/config/database.php index 154638d1f..8c06dd2e6 100644 --- a/application/config/database.php +++ b/application/config/database.php @@ -1,13 +1,13 @@ -<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed'); +<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed'); /** * CodeIgniter * * An open source application development framework for PHP 5.2.4 or newer * * NOTICE OF LICENSE - * + * * Licensed under the Academic Free License version 3.0 - * + * * This source file is subject to the Academic Free License (AFL 3.0) that is * bundled with this package in the files license_afl.txt / license_afl.rst. * It is also available through the world wide web at this URL: @@ -75,23 +75,25 @@ $active_group = 'default'; $active_record = TRUE; -$db['default']['dsn'] = ''; -$db['default']['hostname'] = 'localhost'; -$db['default']['username'] = ''; -$db['default']['password'] = ''; -$db['default']['database'] = ''; -$db['default']['dbdriver'] = 'mysql'; -$db['default']['dbprefix'] = ''; -$db['default']['pconnect'] = FALSE; -$db['default']['db_debug'] = TRUE; -$db['default']['cache_on'] = FALSE; -$db['default']['cachedir'] = ''; -$db['default']['char_set'] = 'utf8'; -$db['default']['dbcollat'] = 'utf8_general_ci'; -$db['default']['swap_pre'] = ''; -$db['default']['autoinit'] = TRUE; -$db['default']['stricton'] = FALSE; -$db['default']['failover'] = array(); +$db['default'] = array( + 'dsn' => '', + 'hostname' => 'localhost', + 'username' => '', + 'password' => '', + 'database' => '', + 'dbdriver' => 'mysqli', + 'dbprefix' => '', + 'pconnect' => FALSE, + 'db_debug' => TRUE, + 'cache_on' => FALSE, + 'cachedir' => '', + 'char_set' => 'utf8', + 'dbcollat' => 'utf8_general_ci', + 'swap_pre' => '', + 'autoinit' => TRUE, + 'stricton' => FALSE, + 'failover' => array() +); /* End of file database.php */ /* Location: ./application/config/database.php */
\ No newline at end of file diff --git a/application/config/doctypes.php b/application/config/doctypes.php index e5e70daf6..c7f5b55c2 100644 --- a/application/config/doctypes.php +++ b/application/config/doctypes.php @@ -1,13 +1,13 @@ -<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed'); +<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed'); /** * CodeIgniter * * An open source application development framework for PHP 5.2.4 or newer * * NOTICE OF LICENSE - * + * * Licensed under the Academic Free License version 3.0 - * + * * This source file is subject to the Academic Free License (AFL 3.0) that is * bundled with this package in the files license_afl.txt / license_afl.rst. * It is also available through the world wide web at this URL: @@ -26,15 +26,25 @@ */ $_doctypes = array( - 'xhtml11' => '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">', - 'xhtml1-strict' => '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">', - 'xhtml1-trans' => '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">', - 'xhtml1-frame' => '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Frameset//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-frameset.dtd">', - 'xhtml-basic11' => '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML Basic 1.1//EN" "http://www.w3.org/TR/xhtml-basic/xhtml-basic11.dtd">', - 'html5' => '<!DOCTYPE html>', - 'html4-strict' => '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">', - 'html4-trans' => '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">', - 'html4-frame' => '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Frameset//EN" "http://www.w3.org/TR/html4/frameset.dtd">' + 'xhtml11' => '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">', + 'xhtml1-strict' => '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">', + 'xhtml1-trans' => '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">', + 'xhtml1-frame' => '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Frameset//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-frameset.dtd">', + 'xhtml-basic11' => '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML Basic 1.1//EN" "http://www.w3.org/TR/xhtml-basic/xhtml-basic11.dtd">', + 'html5' => '<!DOCTYPE html>', + 'html4-strict' => '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">', + 'html4-trans' => '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">', + 'html4-frame' => '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Frameset//EN" "http://www.w3.org/TR/html4/frameset.dtd">', + 'mathml1' => '<!DOCTYPE math SYSTEM "http://www.w3.org/Math/DTD/mathml1/mathml.dtd">', + 'mathml2' => '<!DOCTYPE math PUBLIC "-//W3C//DTD MathML 2.0//EN" "http://www.w3.org/Math/DTD/mathml2/mathml2.dtd">', + 'svg10' => '<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.0//EN" "http://www.w3.org/TR/2001/REC-SVG-20010904/DTD/svg10.dtd">', + 'svg11' => '<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">', + 'svg11-basic' => '<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1 Basic//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11-basic.dtd">', + 'svg11-tiny' => '<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1 Tiny//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11-tiny.dtd">', + 'xhtml-math-svg-xh' => '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1 plus MathML 2.0 plus SVG 1.1//EN" "http://www.w3.org/2002/04/xhtml-math-svg/xhtml-math-svg.dtd">', + 'xhtml-math-svg-sh' => '<!DOCTYPE svg:svg PUBLIC "-//W3C//DTD XHTML 1.1 plus MathML 2.0 plus SVG 1.1//EN" "http://www.w3.org/2002/04/xhtml-math-svg/xhtml-math-svg.dtd">', + 'xhtml-rdfa-1' => '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML+RDFa 1.0//EN" "http://www.w3.org/MarkUp/DTD/xhtml-rdfa-1.dtd">', + 'xhtml-rdfa-2' => '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML+RDFa 1.1//EN" "http://www.w3.org/MarkUp/DTD/xhtml-rdfa-2.dtd">' ); /* End of file doctypes.php */ diff --git a/application/config/foreign_chars.php b/application/config/foreign_chars.php index d3713fe98..e2d3f236e 100644 --- a/application/config/foreign_chars.php +++ b/application/config/foreign_chars.php @@ -1,13 +1,13 @@ -<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed'); +<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed'); /** * CodeIgniter * * An open source application development framework for PHP 5.2.4 or newer * * NOTICE OF LICENSE - * + * * Licensed under the Academic Free License version 3.0 - * + * * This source file is subject to the Academic Free License (AFL 3.0) that is * bundled with this package in the files license_afl.txt / license_afl.rst. * It is also available through the world wide web at this URL: diff --git a/application/config/hooks.php b/application/config/hooks.php index 1b10fc27d..350050370 100644 --- a/application/config/hooks.php +++ b/application/config/hooks.php @@ -1,13 +1,13 @@ -<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed'); +<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed'); /** * CodeIgniter * * An open source application development framework for PHP 5.2.4 or newer * * NOTICE OF LICENSE - * + * * Licensed under the Academic Free License version 3.0 - * + * * This source file is subject to the Academic Free License (AFL 3.0) that is * bundled with this package in the files license_afl.txt / license_afl.rst. * It is also available through the world wide web at this URL: @@ -37,6 +37,5 @@ */ - /* End of file hooks.php */ /* Location: ./application/config/hooks.php */
\ No newline at end of file diff --git a/application/config/migration.php b/application/config/migration.php index e1ce1ae6f..88e398243 100644 --- a/application/config/migration.php +++ b/application/config/migration.php @@ -1,4 +1,4 @@ -<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed'); +<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed'); /** * CodeIgniter * @@ -89,5 +89,5 @@ $config['migration_version'] = 0; */ $config['migration_path'] = APPPATH . 'migrations/'; - -/* End of file migration.php */
\ No newline at end of file +/* End of file migration.php */ +/* Location: ./application/config/migration.php */
\ No newline at end of file diff --git a/application/config/mimes.php b/application/config/mimes.php index 7ec782b60..02e12c011 100644 --- a/application/config/mimes.php +++ b/application/config/mimes.php @@ -34,7 +34,8 @@ | */ -$mimes = array('hqx' => array('application/mac-binhex40', 'application/mac-binhex', 'application/x-binhex40', 'application/x-mac-binhex40'), +$mimes = array( + 'hqx' => array('application/mac-binhex40', 'application/mac-binhex', 'application/x-binhex40', 'application/x-mac-binhex40'), 'cpt' => 'application/mac-compactpro', 'csv' => array('text/x-comma-separated-values', 'text/comma-separated-values', 'application/octet-stream', 'application/vnd.ms-excel', 'application/x-csv', 'text/x-csv', 'text/csv', 'application/csv', 'application/excel', 'application/vnd.msexcel'), 'bin' => array('application/macbinary', 'application/mac-binary', 'application/octet-stream', 'application/x-binary', 'application/x-macbinary'), @@ -165,4 +166,4 @@ $mimes = array('hqx' => array('application/mac-binhex40', 'application/mac-binhe ); /* End of file mimes.php */ -/* Location: ./application/config/mimes.php */ +/* Location: ./application/config/mimes.php */
\ No newline at end of file diff --git a/application/config/profiler.php b/application/config/profiler.php index 53391892d..c161a4d59 100644 --- a/application/config/profiler.php +++ b/application/config/profiler.php @@ -1,13 +1,13 @@ -<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed'); +<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed'); /** * CodeIgniter * * An open source application development framework for PHP 5.2.4 or newer * * NOTICE OF LICENSE - * + * * Licensed under the Academic Free License version 3.0 - * + * * This source file is subject to the Academic Free License (AFL 3.0) that is * bundled with this package in the files license_afl.txt / license_afl.rst. * It is also available through the world wide web at this URL: @@ -38,6 +38,5 @@ */ - /* End of file profiler.php */ /* Location: ./application/config/profiler.php */
\ No newline at end of file diff --git a/application/config/routes.php b/application/config/routes.php index 686573deb..474bda969 100644 --- a/application/config/routes.php +++ b/application/config/routes.php @@ -1,13 +1,13 @@ -<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed'); +<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed'); /** * CodeIgniter * * An open source application development framework for PHP 5.2.4 or newer * * NOTICE OF LICENSE - * + * * Licensed under the Academic Free License version 3.0 - * + * * This source file is subject to the Academic Free License (AFL 3.0) that is * bundled with this package in the files license_afl.txt / license_afl.rst. * It is also available through the world wide web at this URL: @@ -67,6 +67,5 @@ $route['default_controller'] = "welcome"; $route['404_override'] = ''; - /* End of file routes.php */ /* Location: ./application/config/routes.php */
\ No newline at end of file diff --git a/application/config/smileys.php b/application/config/smileys.php index 8e3844a89..baefe5380 100644 --- a/application/config/smileys.php +++ b/application/config/smileys.php @@ -1,13 +1,13 @@ -<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed'); +<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed'); /** * CodeIgniter * * An open source application development framework for PHP 5.2.4 or newer * * NOTICE OF LICENSE - * + * * Licensed under the Academic Free License version 3.0 - * + * * This source file is subject to the Academic Free License (AFL 3.0) that is * bundled with this package in the files license_afl.txt / license_afl.rst. * It is also available through the world wide web at this URL: diff --git a/application/config/user_agents.php b/application/config/user_agents.php index 0baa25220..60f256e01 100644 --- a/application/config/user_agents.php +++ b/application/config/user_agents.php @@ -1,4 +1,4 @@ -<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed'); +<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed'); /** * CodeIgniter * @@ -211,4 +211,4 @@ $robots = array( ); /* End of file user_agents.php */ -/* Location: ./application/config/user_agents.php */ +/* Location: ./application/config/user_agents.php */
\ No newline at end of file diff --git a/application/controllers/welcome.php b/application/controllers/welcome.php index 2451d9776..1ed82d2a7 100644 --- a/application/controllers/welcome.php +++ b/application/controllers/welcome.php @@ -1,13 +1,13 @@ -<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed'); +<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed'); /** * CodeIgniter * * An open source application development framework for PHP 5.2.4 or newer * * NOTICE OF LICENSE - * + * * Licensed under the Academic Free License version 3.0 - * + * * This source file is subject to the Academic Free License (AFL 3.0) that is * bundled with this package in the files license_afl.txt / license_afl.rst. * It is also available through the world wide web at this URL: @@ -32,10 +32,10 @@ class Welcome extends CI_Controller { * * Maps to the following URL * http://example.com/index.php/welcome - * - or - + * - or - * http://example.com/index.php/welcome/index * - or - - * Since this controller is set as the default controller in + * Since this controller is set as the default controller in * config/routes.php, it's displayed at http://example.com/ * * So any other public methods not prefixed with an underscore will diff --git a/application/errors/error_404.php b/application/errors/error_404.php index 9af9e39de..746032956 100644 --- a/application/errors/error_404.php +++ b/application/errors/error_404.php @@ -1,13 +1,13 @@ -<?php +<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed'); /** * CodeIgniter * * An open source application development framework for PHP 5.2.4 or newer * * NOTICE OF LICENSE - * + * * Licensed under the Academic Free License version 3.0 - * + * * This source file is subject to the Academic Free License (AFL 3.0) that is * bundled with this package in the files license_afl.txt / license_afl.rst. * It is also available through the world wide web at this URL: @@ -24,9 +24,7 @@ * @since Version 1.0 * @filesource */ -?> - -<!DOCTYPE html> +?><!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> diff --git a/application/errors/error_db.php b/application/errors/error_db.php index 81ff02adb..eb3a75260 100644 --- a/application/errors/error_db.php +++ b/application/errors/error_db.php @@ -1,13 +1,13 @@ -<?php +<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed'); /** * CodeIgniter * * An open source application development framework for PHP 5.2.4 or newer * * NOTICE OF LICENSE - * + * * Licensed under the Academic Free License version 3.0 - * + * * This source file is subject to the Academic Free License (AFL 3.0) that is * bundled with this package in the files license_afl.txt / license_afl.rst. * It is also available through the world wide web at this URL: @@ -24,9 +24,7 @@ * @since Version 1.0 * @filesource */ -?> - -<!DOCTYPE html> +?><!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> diff --git a/application/errors/error_general.php b/application/errors/error_general.php index 8efcfd991..59896e1ea 100644 --- a/application/errors/error_general.php +++ b/application/errors/error_general.php @@ -1,13 +1,13 @@ -<?php +<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed'); /** * CodeIgniter * * An open source application development framework for PHP 5.2.4 or newer * * NOTICE OF LICENSE - * + * * Licensed under the Academic Free License version 3.0 - * + * * This source file is subject to the Academic Free License (AFL 3.0) that is * bundled with this package in the files license_afl.txt / license_afl.rst. * It is also available through the world wide web at this URL: @@ -24,9 +24,7 @@ * @since Version 1.0 * @filesource */ -?> - -<!DOCTYPE html> +?><!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> diff --git a/application/errors/error_php.php b/application/errors/error_php.php index 42e5f5a28..3855720de 100644 --- a/application/errors/error_php.php +++ b/application/errors/error_php.php @@ -1,13 +1,13 @@ -<?php +<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed'); /** * CodeIgniter * * An open source application development framework for PHP 5.2.4 or newer * * NOTICE OF LICENSE - * + * * Licensed under the Academic Free License version 3.0 - * + * * This source file is subject to the Academic Free License (AFL 3.0) that is * bundled with this package in the files license_afl.txt / license_afl.rst. * It is also available through the world wide web at this URL: @@ -35,11 +35,11 @@ <p>Filename: <?php echo $filepath; ?></p> <p>Line Number: <?php echo $line; ?></p> -<?php if(defined('SHOW_DEBUG_BACKTRACE') && SHOW_DEBUG_BACKTRACE === TRUE): ?> - +<?php if (defined('SHOW_DEBUG_BACKTRACE') && SHOW_DEBUG_BACKTRACE === TRUE): ?> + <p>Backtrace: </p> <?php foreach(debug_backtrace() as $error): ?> - + <?php if(isset($error['file']) && ! stristr($error['file'], SYSDIR)): ?> <p style="margin-left:10px"> File: <?php echo $error['file'] ?><br /> @@ -47,7 +47,7 @@ Function: <?php echo $error['function'] ?> </p> <?php endif ?> - + <?php endforeach ?></p> <?php endif ?> diff --git a/application/views/welcome_message.php b/application/views/welcome_message.php index 0dd892441..45360da60 100644 --- a/application/views/welcome_message.php +++ b/application/views/welcome_message.php @@ -1,13 +1,13 @@ -<?php +<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed'); /** * CodeIgniter * * An open source application development framework for PHP 5.2.4 or newer * * NOTICE OF LICENSE - * + * * Licensed under the Academic Free License version 3.0 - * + * * This source file is subject to the Academic Free License (AFL 3.0) that is * bundled with this package in the files license_afl.txt / license_afl.rst. * It is also available through the world wide web at this URL: @@ -24,9 +24,7 @@ * @since Version 1.0 * @filesource */ -?> - -<!DOCTYPE html> +?><!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> @@ -75,7 +73,7 @@ #body{ margin: 0 15px 0 15px; } - + p.footer{ text-align: right; font-size: 11px; @@ -84,7 +82,7 @@ padding: 0 10px 0 10px; margin: 20px 0 0 0; } - + #container{ margin: 10px; border: 1px solid #D0D0D0; diff --git a/system/core/CodeIgniter.php b/system/core/CodeIgniter.php index a79a69590..4885f310c 100755 --- a/system/core/CodeIgniter.php +++ b/system/core/CodeIgniter.php @@ -133,7 +133,7 @@ * Is there a "pre_system" hook? * ------------------------------------------------------ */ - $EXT->_call_hook('pre_system'); + $EXT->call_hook('pre_system'); /* * ------------------------------------------------------ @@ -194,7 +194,7 @@ * Is there a valid cache file? If so, we're done... * ------------------------------------------------------ */ - if ($EXT->_call_hook('cache_override') === FALSE + if ($EXT->call_hook('cache_override') === FALSE && $OUT->_display_cache($CFG, $URI) == TRUE) { exit; @@ -297,7 +297,7 @@ * Is there a "pre_controller" hook? * ------------------------------------------------------ */ - $EXT->_call_hook('pre_controller'); + $EXT->call_hook('pre_controller'); /* * ------------------------------------------------------ @@ -314,7 +314,7 @@ * Is there a "post_controller_constructor" hook? * ------------------------------------------------------ */ - $EXT->_call_hook('post_controller_constructor'); + $EXT->call_hook('post_controller_constructor'); /* * ------------------------------------------------------ @@ -369,14 +369,14 @@ * 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) + if ($EXT->call_hook('display_override') === FALSE) { $OUT->_display(); } @@ -386,7 +386,7 @@ * Is there a "post_system" hook? * ------------------------------------------------------ */ - $EXT->_call_hook('post_system'); + $EXT->call_hook('post_system'); /* * ------------------------------------------------------ diff --git a/system/core/Common.php b/system/core/Common.php index f20acafd4..aeb784bbe 100644 --- a/system/core/Common.php +++ b/system/core/Common.php @@ -25,8 +25,6 @@ * @filesource */ -// ------------------------------------------------------------------------ - /** * Common Functions * @@ -42,15 +40,14 @@ // ------------------------------------------------------------------------ /** -* 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 -* @param string -* @return bool TRUE if the current version is $version or higher -*/ + * 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. + * + * @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') @@ -76,7 +73,7 @@ if ( ! function_exists('is_php')) * the file, based on the read-only attribute. is_writable() is also unreliable * on Unix servers if safe_mode is on. * - * @access public + * @param string * @return void */ if ( ! function_exists('is_really_writable')) @@ -118,18 +115,17 @@ if ( ! function_exists('is_really_writable')) // ------------------------------------------------------------------------ /** -* Class registry -* -* This function acts as a singleton. If the requested class does not -* exist it is instantiated and set to a static variable. If it has -* previously been instantiated the variable is returned. -* -* @access public -* @param string the class name being requested -* @param string the directory where the class should be found -* @param string the class name prefix -* @return object -*/ + * Class registry + * + * This function acts as a singleton. If the requested class does not + * exist it is instantiated and set to a static variable. If it has + * previously been instantiated the variable is returned. + * + * @param string the class name being requested + * @param string the directory where the class should be found + * @param string the class name prefix + * @return object + */ if ( ! function_exists('load_class')) { function &load_class($class, $directory = 'libraries', $prefix = 'CI_') @@ -192,12 +188,12 @@ if ( ! function_exists('load_class')) // -------------------------------------------------------------------- /** -* Keeps track of which libraries have been loaded. This function is -* called by the load_class() function above -* -* @access public -* @return array -*/ + * Keeps track of which libraries have been loaded. This function is + * called by the load_class() function above + * + * @param string + * @return array + */ if ( ! function_exists('is_loaded')) { function &is_loaded($class = '') @@ -216,14 +212,14 @@ if ( ! function_exists('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 -*/ + * Loads the main config.php file + * + * This function lets us grab the config file even if the Config class + * hasn't been instantiated yet + * + * @param array + * @return array + */ if ( ! function_exists('get_config')) { function &get_config($replace = array()) @@ -276,11 +272,11 @@ if ( ! function_exists('get_config')) // ------------------------------------------------------------------------ /** -* Returns the specified config item -* -* @access public -* @return mixed -*/ + * Returns the specified config item + * + * @param string + * @return mixed + */ if ( ! function_exists('config_item')) { function config_item($item) @@ -305,17 +301,19 @@ if ( ! function_exists('config_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 -*/ + * 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. + * + * @param string + * @param int + * @param string + * @return void + */ if ( ! function_exists('show_error')) { function show_error($message, $status_code = 500, $heading = 'An Error Was Encountered') @@ -329,15 +327,16 @@ if ( ! function_exists('show_error')) // ------------------------------------------------------------------------ /** -* 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 -*/ + * 404 Page Handler + * + * This function is similar to the show_error() function above + * However, instead of the standard error template it displays + * 404 errors. + * + * @param string + * @param bool + * @return void + */ if ( ! function_exists('show_404')) { function show_404($page = '', $log_error = TRUE) @@ -351,14 +350,16 @@ if ( ! function_exists('show_404')) // ------------------------------------------------------------------------ /** -* 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 -*/ + * Error Logging Interface + * + * We use this as a simple mechanism to access the logging + * class and send messages to be logged. + * + * @param string + * @param string + * @param bool + * @return void + */ if ( ! function_exists('log_message')) { function log_message($level = 'error', $message, $php_error = FALSE) @@ -380,8 +381,7 @@ if ( ! function_exists('log_message')) /** * Set HTTP Status Header * - * @access public - * @param int the status code + * @param int the status code * @param string * @return void */ @@ -467,19 +467,22 @@ if ( ! function_exists('set_status_header')) // -------------------------------------------------------------------- /** -* Exception Handler -* -* This is the custom exception handler that is declaired at the top -* of Codeigniter.php. The main reason we use this is to permit -* PHP errors to be logged in our own log files since the user may -* not have access to server logs. Since this function -* effectively intercepts PHP errors, however, we also need -* to display errors based on the current error_reporting level. -* We do that with the use of a PHP error template. -* -* @access private -* @return void -*/ + * Exception Handler + * + * This is the custom exception handler that is declaired at the top + * of Codeigniter.php. The main reason we use this is to permit + * PHP errors to be logged in our own log files since the user may + * not have access to server logs. Since this function + * effectively intercepts PHP errors, however, we also need + * to display errors based on the current error_reporting level. + * We do that with the use of a PHP error template. + * + * @param int + * @param string + * @param string + * @param int + * @return void + */ if ( ! function_exists('_exception_handler')) { function _exception_handler($severity, $message, $filepath, $line) @@ -521,8 +524,8 @@ if ( ! function_exists('_exception_handler')) * This prevents sandwiching null characters * between ascii characters, like Java\0script. * - * @access public * @param string + * @param bool * @return string */ if ( ! function_exists('remove_invisible_characters')) @@ -554,12 +557,11 @@ if ( ! function_exists('remove_invisible_characters')) // ------------------------------------------------------------------------ /** -* Returns HTML escaped variable -* -* @access public -* @param mixed -* @return mixed -*/ + * Returns HTML escaped variable + * + * @param mixed + * @return mixed + */ if ( ! function_exists('html_escape')) { function html_escape($var) @@ -571,4 +573,4 @@ if ( ! function_exists('html_escape')) } /* End of file Common.php */ -/* Location: ./system/core/Common.php */ +/* Location: ./system/core/Common.php */
\ No newline at end of file diff --git a/system/core/Exceptions.php b/system/core/Exceptions.php index d7282b1f3..f36b31598 100755 --- a/system/core/Exceptions.php +++ b/system/core/Exceptions.php @@ -25,8 +25,6 @@ * @filesource */ -// ------------------------------------------------------------------------ - /** * Exceptions Class * @@ -163,7 +161,7 @@ class CI_Exceptions { * @param string the error line number * @return string */ - function show_php_error($severity, $message, $filepath, $line) + public function show_php_error($severity, $message, $filepath, $line) { $severity = ( ! isset($this->levels[$severity])) ? $severity : $this->levels[$severity]; $filepath = str_replace('\\', '/', $filepath); @@ -189,4 +187,4 @@ class CI_Exceptions { } /* End of file Exceptions.php */ -/* Location: ./system/core/Exceptions.php */ +/* Location: ./system/core/Exceptions.php */
\ No newline at end of file diff --git a/system/core/Hooks.php b/system/core/Hooks.php index 493822f36..68e30ef0f 100755 --- a/system/core/Hooks.php +++ b/system/core/Hooks.php @@ -25,8 +25,6 @@ * @filesource */ -// ------------------------------------------------------------------------ - /** * CodeIgniter Hooks Class * @@ -51,7 +49,7 @@ class CI_Hooks { * * @var array */ - public $hooks = array(); + public $hooks = array(); /** * Determines wether hook is in progress, used to prevent infinte loops * @@ -59,23 +57,17 @@ class CI_Hooks { */ public $in_progress = FALSE; - public function __construct() - { - $this->_initialize(); - log_message('debug', 'Hooks Class Initialized'); - } - - // -------------------------------------------------------------------- - /** * Initialize the Hooks Preferences * * @return void */ - private function _initialize() + public function __construct() { $CFG =& load_class('Config', 'core'); + log_message('debug', 'Hooks Class Initialized'); + // If hooks are not enabled in the config file // there is nothing else to do if ($CFG->item('enable_hooks') == FALSE) @@ -84,7 +76,7 @@ class CI_Hooks { } // Grab the "hooks" definition file. - if (defined('ENVIRONMENT') AND is_file(APPPATH.'config/'.ENVIRONMENT.'/hooks.php')) + if (defined('ENVIRONMENT') && is_file(APPPATH.'config/'.ENVIRONMENT.'/hooks.php')) { include(APPPATH.'config/'.ENVIRONMENT.'/hooks.php'); } @@ -113,14 +105,14 @@ class CI_Hooks { * @param string the hook name * @return mixed */ - public function _call_hook($which = '') + public 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])) + if (isset($this->hooks[$which][0]) && is_array($this->hooks[$which][0])) { foreach ($this->hooks[$which] as $val) { @@ -167,7 +159,7 @@ class CI_Hooks { // Set file path // ----------------------------------- - if ( ! isset($data['filepath']) OR ! isset($data['filename'])) + if ( ! isset($data['filepath'], $data['filename'])) { return FALSE; } @@ -187,12 +179,12 @@ class CI_Hooks { $function = FALSE; $params = ''; - if (isset($data['class']) AND $data['class'] != '') + if ( ! empty($data['class'])) { $class = $data['class']; } - if (isset($data['function'])) + if ( ! empty($data['function'])) { $function = $data['function']; } @@ -202,7 +194,7 @@ class CI_Hooks { $params = $data['params']; } - if ($class === FALSE AND $function === FALSE) + if ($class === FALSE && $function === FALSE) { return FALSE; } @@ -244,4 +236,4 @@ class CI_Hooks { } /* End of file Hooks.php */ -/* Location: ./system/core/Hooks.php */ +/* Location: ./system/core/Hooks.php */
\ No newline at end of file diff --git a/system/core/Loader.php b/system/core/Loader.php index 9b9cc2fef..027ed20e5 100644 --- a/system/core/Loader.php +++ b/system/core/Loader.php @@ -25,8 +25,6 @@ * @filesource */ -// ------------------------------------------------------------------------ - /** * Loader Class * @@ -281,7 +279,7 @@ class CI_Loader { continue; } - if ($db_conn !== FALSE AND ! class_exists('CI_DB')) + if ($db_conn !== FALSE && ! class_exists('CI_DB')) { if ($db_conn === TRUE) { @@ -324,7 +322,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 == NULL AND isset($CI->db) AND is_object($CI->db)) + if (class_exists('CI_DB') && $return == FALSE && $active_record == NULL && isset($CI->db) && is_object($CI->db)) { return FALSE; } @@ -399,13 +397,13 @@ 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 - * some cases it's advantageous to be able to return data so that - * a developer can process it in some way. + * 3. TRUE/FALSE - whether to return the data or load it. In + * some cases it's advantageous to be able to return data so that + * a developer can process it in some way. * * @param string * @param array @@ -447,14 +445,14 @@ class CI_Loader { */ public function vars($vars = array(), $val = '') { - if ($val != '' AND is_string($vars)) + if ($val != '' && is_string($vars)) { $vars = array($vars => $val); } $vars = $this->_ci_object_to_array($vars); - if (is_array($vars) AND count($vars) > 0) + if (is_array($vars) && count($vars) > 0) { foreach ($vars as $key => $val) { @@ -660,7 +658,7 @@ class CI_Loader { * Prepends a parent path to the library, model, helper, and config path arrays * * @param string - * @param boolean + * @param bool * @return void */ public function add_package_path($path, $view_cascade=TRUE) @@ -701,9 +699,9 @@ 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. * - * @param type + * @param string * @param bool - * @return type + * @return void */ public function remove_package_path($path = '', $remove_config_path = TRUE) { @@ -764,7 +762,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]) ? $_ci_data[$_ci_val] : FALSE; } $file_exists = FALSE; @@ -1019,11 +1017,11 @@ class CI_Loader { * @param string * @param bool * @param string an optional object name - * @return null + * @return void */ 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 @@ -1038,24 +1036,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).'.php')) + if (defined('ENVIRONMENT') && file_exists($path.'config/'.ENVIRONMENT.'/'.strtolower($class).'.php')) { - include($path .'config/'.ENVIRONMENT.'/'.strtolower($class).'.php'); + include($path.'config/'.ENVIRONMENT.'/'.strtolower($class).'.php'); break; } - elseif (defined('ENVIRONMENT') AND file_exists($path .'config/'.ENVIRONMENT.'/'.ucfirst(strtolower($class)).'.php')) + elseif (defined('ENVIRONMENT') && file_exists($path.'config/'.ENVIRONMENT.'/'.ucfirst(strtolower($class)).'.php')) { - include($path .'config/'.ENVIRONMENT.'/'.ucfirst(strtolower($class)).'.php'); + include($path.'config/'.ENVIRONMENT.'/'.ucfirst(strtolower($class)).'.php'); break; } - elseif (file_exists($path .'config/'.strtolower($class).'.php')) + elseif (file_exists($path.'config/'.strtolower($class).'.php')) { - include($path .'config/'.strtolower($class).'.php'); + include($path.'config/'.strtolower($class).'.php'); break; } - elseif (file_exists($path .'config/'.ucfirst(strtolower($class)).'.php')) + elseif (file_exists($path.'config/'.ucfirst(strtolower($class)).'.php')) { - include($path .'config/'.ucfirst(strtolower($class)).'.php'); + include($path.'config/'.ucfirst(strtolower($class)).'.php'); break; } } @@ -1095,7 +1093,7 @@ class CI_Loader { if (is_null($object_name)) { - $classvar = ( ! isset($this->_ci_varmap[$class])) ? $class : $this->_ci_varmap[$class]; + $classvar = isset($this->_ci_varmap[$class]) ? $this->_ci_varmap[$class] : $class; } else { @@ -1113,7 +1111,7 @@ class CI_Loader { } else { - $CI->$classvar = new $name; + $CI->$classvar = new $name(); } } @@ -1130,7 +1128,7 @@ class CI_Loader { */ protected function _ci_autoloader() { - if (defined('ENVIRONMENT') AND file_exists(APPPATH.'config/'.ENVIRONMENT.'/autoload.php')) + if (defined('ENVIRONMENT') && file_exists(APPPATH.'config/'.ENVIRONMENT.'/autoload.php')) { include(APPPATH.'config/'.ENVIRONMENT.'/autoload.php'); } @@ -1166,14 +1164,14 @@ class CI_Loader { // Autoload helpers and languages foreach (array('helper', 'language') as $type) { - if (isset($autoload[$type]) AND count($autoload[$type]) > 0) + if (isset($autoload[$type]) && count($autoload[$type]) > 0) { $this->$type($autoload[$type]); } } // Load libraries - if (isset($autoload['libraries']) AND count($autoload['libraries']) > 0) + if (isset($autoload['libraries']) && count($autoload['libraries']) > 0) { // Load the database driver. if (in_array('database', $autoload['libraries'])) @@ -1208,7 +1206,7 @@ class CI_Loader { */ protected function _ci_object_to_array($object) { - return (is_object($object)) ? get_object_vars($object) : $object; + return is_object($object) ? get_object_vars($object) : $object; } // -------------------------------------------------------------------- @@ -1252,7 +1250,8 @@ 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/core/Output.php b/system/core/Output.php index faebbbe72..01fd1d867 100755 --- a/system/core/Output.php +++ b/system/core/Output.php @@ -25,8 +25,6 @@ * @filesource */ -// ------------------------------------------------------------------------ - /** * Output Class * @@ -94,7 +92,7 @@ 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.php')) + if (defined('ENVIRONMENT') && file_exists(APPPATH.'config/'.ENVIRONMENT.'/mimes.php')) { include APPPATH.'config/'.ENVIRONMENT.'/mimes.php'; } @@ -226,10 +224,30 @@ class CI_Output { // -------------------------------------------------------------------- /** + * Get Current Content Type Header + * + * @return string 'text/html', if not already set + */ + public function get_content_type() + { + for ($i = 0, $c = count($this->headers); $i < $c; $i++) + { + if (preg_match('/^Content-Type:\s(.+)$/', $this->headers[$i][0], $matches)) + { + return $matches[1]; + } + } + + return 'text/html'; + } + + // -------------------------------------------------------------------- + + /** * Set HTTP Status Header * moved to Common procedural functions in 1.7.2 * - * @param int the status code + * @param int the status code * @param string * @return void */ @@ -249,7 +267,7 @@ class CI_Output { */ public function enable_profiler($val = TRUE) { - $this->enable_profiler = (is_bool($val)) ? $val : TRUE; + $this->enable_profiler = is_bool($val) ? $val : TRUE; return $this; } @@ -267,7 +285,7 @@ class CI_Output { { foreach ($sections as $section => $enable) { - $this->_profiler_sections[$section] = ($enable !== FALSE) ? TRUE : FALSE; + $this->_profiler_sections[$section] = ($enable !== FALSE); } return $this; @@ -278,12 +296,12 @@ class CI_Output { /** * Set Cache * - * @param integer + * @param int * @return void */ public function cache($time) { - $this->cache_expiration = ( ! is_numeric($time)) ? 0 : $time; + $this->cache_expiration = is_numeric($time) ? $time : 0; return $this; } @@ -297,7 +315,7 @@ class CI_Output { * $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 + * with any server headers and profile data. It also stops the * benchmark timer so the page rendering speed and memory usage can be shown. * * @param string @@ -343,7 +361,7 @@ class CI_Output { if ($this->parse_exec_vars === TRUE) { - $memory = ( ! function_exists('memory_get_usage')) ? '0' : round(memory_get_usage()/1024/1024, 2).'MB'; + $memory = function_exists('memory_get_usage') ? round(memory_get_usage()/1024/1024, 2).'MB' : '0'; $output = str_replace(array('{elapsed_time}', '{memory_usage}'), array($elapsed, $memory), $output); } @@ -520,4 +538,4 @@ class CI_Output { } /* End of file Output.php */ -/* Location: ./system/core/Output.php */ +/* Location: ./system/core/Output.php */
\ No newline at end of file diff --git a/system/core/Router.php b/system/core/Router.php index b251abb4b..5477fed5d 100755 --- a/system/core/Router.php +++ b/system/core/Router.php @@ -25,8 +25,6 @@ * @filesource */ -// ------------------------------------------------------------------------ - /** * Router Class * @@ -111,7 +109,7 @@ class CI_Router { // since URI segments are more search-engine friendly, but they can optionally be used. // If this feature is enabled, we will gather the directory/class/method a little differently $segments = array(); - if ($this->config->item('enable_query_strings') === TRUE AND isset($_GET[$this->config->item('controller_trigger')])) + if ($this->config->item('enable_query_strings') === TRUE && isset($_GET[$this->config->item('controller_trigger')])) { if (isset($_GET[$this->config->item('directory_trigger')])) { @@ -133,7 +131,7 @@ class CI_Router { } // Load the routes.php file. - if (defined('ENVIRONMENT') AND is_file(APPPATH.'config/'.ENVIRONMENT.'/routes.php')) + if (defined('ENVIRONMENT') && is_file(APPPATH.'config/'.ENVIRONMENT.'/routes.php')) { include(APPPATH.'config/'.ENVIRONMENT.'/routes.php'); } @@ -147,7 +145,7 @@ 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 = empty($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) @@ -248,8 +246,8 @@ class CI_Router { // -------------------------------------------------------------------- /** - * Validates the supplied segments. Attempts to determine the path to - * the controller. + * Validates the supplied segments. + * Attempts to determine the path to the controller. * * @param array * @return array @@ -340,7 +338,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 @@ -369,7 +367,7 @@ class CI_Router { if (preg_match('#^'.$key.'$#', $uri)) { // Do we have a back-reference? - if (strpos($val, '$') !== FALSE AND strpos($key, '(') !== FALSE) + if (strpos($val, '$') !== FALSE && strpos($key, '(') !== FALSE) { $val = preg_replace('#^'.$key.'$#', $val, $uri); } @@ -411,7 +409,7 @@ class CI_Router { // -------------------------------------------------------------------- /** - * Set the method name + * Set the method name * * @param string * @return void @@ -424,7 +422,7 @@ class CI_Router { // -------------------------------------------------------------------- /** - * Fetch the current method + * Fetch the current method * * @return string */ @@ -441,7 +439,7 @@ class CI_Router { // -------------------------------------------------------------------- /** - * Set the directory name + * Set the directory name * * @param string * @return void @@ -454,7 +452,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 * * @return string */ @@ -466,10 +464,10 @@ class CI_Router { // -------------------------------------------------------------------- /** - * Set the controller overrides + * Set the controller overrides * * @param array - * @return null + * @return void */ public function _set_overrides($routing) { @@ -483,7 +481,7 @@ class CI_Router { $this->set_directory($routing['directory']); } - if (isset($routing['controller']) AND $routing['controller'] != '') + if (isset($routing['controller']) && $routing['controller'] != '') { $this->set_class($routing['controller']); } @@ -498,4 +496,4 @@ class CI_Router { } /* End of file Router.php */ -/* Location: ./system/core/Router.php */ +/* Location: ./system/core/Router.php */
\ No newline at end of file diff --git a/system/database/DB.php b/system/database/DB.php index 116116bf4..0d81e40d3 100755 --- a/system/database/DB.php +++ b/system/database/DB.php @@ -37,11 +37,11 @@ function &DB($params = '', $active_record_override = NULL) { // Load the DB config file if a DSN string wasn't passed - if (is_string($params) AND strpos($params, '://') === FALSE) + if (is_string($params) && strpos($params, '://') === FALSE) { // Is the config file in the environment folder? if (( ! defined('ENVIRONMENT') OR ! file_exists($file_path = APPPATH.'config/'.ENVIRONMENT.'/database.php')) - AND ! file_exists($file_path = APPPATH.'config/database.php')) + && ! file_exists($file_path = APPPATH.'config/database.php')) { show_error('The configuration file database.php does not exist.'); } @@ -74,34 +74,30 @@ function &DB($params = '', $active_record_override = NULL) * parameter. DSNs must have this prototype: * $dsn = 'driver://username:password@hostname/database'; */ - if (($dns = @parse_url($params)) === FALSE) + if (($dsn = @parse_url($params)) === FALSE) { show_error('Invalid DB Connection String'); } $params = array( - 'dbdriver' => $dns['scheme'], - 'hostname' => (isset($dns['host'])) ? rawurldecode($dns['host']) : '', - 'port' => (isset($dns['port'])) ? rawurldecode($dns['port']) : '', - 'username' => (isset($dns['user'])) ? rawurldecode($dns['user']) : '', - 'password' => (isset($dns['pass'])) ? rawurldecode($dns['pass']) : '', - 'database' => (isset($dns['path'])) ? rawurldecode(substr($dns['path'], 1)) : '' + 'dbdriver' => $dsn['scheme'], + 'hostname' => isset($dsn['host']) ? rawurldecode($dsn['host']) : '', + 'port' => isset($dsn['port']) ? rawurldecode($dsn['port']) : '', + 'username' => isset($dsn['user']) ? rawurldecode($dsn['user']) : '', + 'password' => isset($dsn['pass']) ? rawurldecode($dsn['pass']) : '', + 'database' => isset($dsn['path']) ? rawurldecode(substr($dsn['path'], 1)) : '' ); // were additional config items set? - if (isset($dns['query'])) + if (isset($dsn['query'])) { - parse_str($dns['query'], $extra); + parse_str($dsn['query'], $extra); + foreach ($extra as $key => $val) { - // booleans please - if (strtoupper($val) === 'TRUE') - { - $val = TRUE; - } - elseif (strtoupper($val) === 'FALSE') + if (is_string($val) && in_array(strtoupper($val), array('TRUE', 'FALSE', 'NULL'))) { - $val = FALSE; + $val = var_export($val); } $params[$key] = $val; @@ -138,7 +134,12 @@ function &DB($params = '', $active_record_override = NULL) class CI_DB extends CI_DB_driver { } } - require_once(BASEPATH.'database/drivers/'.$params['dbdriver'].'/'.$params['dbdriver'].'_driver.php'); + // Load the DB driver + $driver_file = BASEPATH.'database/drivers/'.$params['dbdriver'].'/'.$params['dbdriver'].'_driver.php'; + + if ( ! file_exists($driver_file)) show_error('Invalid DB driver'); + + require_once($driver_file); // Instantiate the DB adapter $driver = 'CI_DB_'.$params['dbdriver'].'_driver'; @@ -158,4 +159,4 @@ function &DB($params = '', $active_record_override = NULL) } /* End of file DB.php */ -/* Location: ./system/database/DB.php */ +/* Location: ./system/database/DB.php */
\ No newline at end of file diff --git a/system/database/DB_active_rec.php b/system/database/DB_active_rec.php index fe591dda1..a19f9bedd 100644 --- a/system/database/DB_active_rec.php +++ b/system/database/DB_active_rec.php @@ -25,8 +25,6 @@ * @filesource */ -// ------------------------------------------------------------------------ - /** * Active Record Class * @@ -422,7 +420,7 @@ abstract class CI_DB_active_record extends CI_DB_driver { foreach ($key as $k => $v) { - $prefix = (count($this->ar_where) === 0 AND count($this->ar_cache_where) === 0) ? '' : $type; + $prefix = (count($this->ar_where) === 0 && count($this->ar_cache_where) === 0) ? '' : $type; if (is_null($v) && ! $this->_has_operator($k)) { @@ -537,7 +535,7 @@ abstract class CI_DB_active_record extends CI_DB_driver { * * @param string The field to search * @param array The values searched on - * @param boolean If the statement would be IN or NOT IN + * @param bool If the statement would be IN or NOT IN * @param string * @return object */ @@ -719,7 +717,7 @@ abstract class CI_DB_active_record extends CI_DB_driver { { $type = $this->_group_get_type($type); $this->ar_where_group_started = TRUE; - $prefix = (count($this->ar_where) === 0 AND count($this->ar_cache_where) === 0) ? '' : $type; + $prefix = (count($this->ar_where) === 0 && count($this->ar_cache_where) === 0) ? '' : $type; $this->ar_where[] = $value = $prefix.$not.str_repeat(' ', ++$this->ar_where_group_count).' ('; if ($this->ar_caching) @@ -984,8 +982,8 @@ abstract class CI_DB_active_record extends CI_DB_driver { /** * Sets the LIMIT value * - * @param integer the limit value - * @param integer the offset value + * @param int the limit value + * @param int the offset value * @return object */ public function limit($value, $offset = NULL) @@ -1005,7 +1003,7 @@ abstract class CI_DB_active_record extends CI_DB_driver { /** * Sets the OFFSET value * - * @param integer the offset value + * @param int the offset value * @return object */ public function offset($offset) @@ -1021,7 +1019,7 @@ abstract class CI_DB_active_record extends CI_DB_driver { * * @param mixed * @param string - * @param boolean + * @param bool * @return object */ public function set($key, $value = '', $escape = TRUE) @@ -1055,9 +1053,8 @@ abstract class CI_DB_active_record extends CI_DB_driver { * * Compiles a SELECT query string and returns the sql. * - * @access public * @param string the table name to select from (optional) - * @param boolean TRUE: resets AR values; FALSE: leave AR vaules alone + * @param bool TRUE: resets AR values; FALSE: leave AR vaules alone * @return string */ public function get_compiled_select($table = '', $reset = TRUE) @@ -1222,11 +1219,28 @@ abstract class CI_DB_active_record extends CI_DB_driver { // -------------------------------------------------------------------- /** + * Insert_batch statement + * + * Generates a platform-specific insert string from the supplied data. + * + * @param string the table name + * @param array the insert keys + * @param array the insert values + * @return string + */ + protected function _insert_batch($table, $keys, $values) + { + return 'INSERT INTO '.$table.' ('.implode(', ', $keys).') VALUES '.implode(', ', $values); + } + + // -------------------------------------------------------------------- + + /** * The "set_insert_batch" function. Allows key/value pairs to be set for batch inserts * * @param mixed * @param string - * @param boolean + * @param bool * @return object */ public function set_insert_batch($key, $value = '', $escape = TRUE) @@ -1283,9 +1297,8 @@ abstract class CI_DB_active_record extends CI_DB_driver { * * Compiles an insert query and returns the sql * - * @access public * @param string the table to insert into - * @param boolean TRUE: reset AR values; FALSE: leave AR values alone + * @param bool TRUE: reset AR values; FALSE: leave AR values alone * @return string */ public function get_compiled_insert($table = '', $reset = TRUE) @@ -1316,7 +1329,6 @@ abstract class CI_DB_active_record extends CI_DB_driver { * * Compiles an insert string and runs the query * - * @access public * @param string the table to insert data into * @param array an associative array of insert values * @return object @@ -1346,13 +1358,29 @@ abstract class CI_DB_active_record extends CI_DB_driver { // -------------------------------------------------------------------- /** + * Insert statement + * + * Generates a platform-specific insert string from the supplied data + * + * @param string the table name + * @param array the insert keys + * @param array the insert values + * @return string + */ + protected function _insert($table, $keys, $values) + { + return 'INSERT INTO '.$table.' ('.implode(', ', $keys).') VALUES ('.implode(', ', $values).')'; + } + + // -------------------------------------------------------------------- + + /** * Validate Insert * * This method is used by both insert() and get_compiled_insert() to * validate that the there data is actually being set and that table * has been chosen to be inserted into. * - * @access public * @param string the table to insert data into * @return string */ @@ -1419,13 +1447,29 @@ abstract class CI_DB_active_record extends CI_DB_driver { // -------------------------------------------------------------------- /** + * Replace statement + * + * Generates a platform-specific replace string from the supplied data + * + * @param string the table name + * @param array the insert keys + * @param array the insert values + * @return string + */ + protected function _replace($table, $keys, $values) + { + return 'REPLACE INTO '.$table.' ('.implode(', ', $keys).') VALUES ('.implode(', ', $values).')'; + } + + // -------------------------------------------------------------------- + + /** * Get UPDATE query string * * Compiles an update query and returns the sql * - * @access public * @param string the table to update - * @param boolean TRUE: reset AR values; FALSE: leave AR values alone + * @param bool TRUE: reset AR values; FALSE: leave AR values alone * @return string */ public function get_compiled_update($table = '', $reset = TRUE) @@ -1493,13 +1537,39 @@ abstract class CI_DB_active_record extends CI_DB_driver { // -------------------------------------------------------------------- /** + * Update statement + * + * Generates a platform-specific update string from the supplied data + * + * @param string the table name + * @param array the update data + * @param array the where clause + * @param array the orderby clause + * @param array the limit clause + * @return string + */ + protected function _update($table, $values, $where, $orderby = array(), $limit = FALSE) + { + foreach ($values as $key => $val) + { + $valstr[] = $key.' = '.$val; + } + + return 'UPDATE '.$table.' SET '.implode(', ', $valstr) + .(($where != '' && count($where) > 0) ? ' WHERE '.implode(' ', $where) : '') + .(count($orderby) > 0 ? ' ORDER BY '.implode(', ', $orderby) : '') + .($limit ? ' LIMIT '.$limit : ''); + } + + // -------------------------------------------------------------------- + + /** * Validate Update * * This method is used by both update() and get_compiled_update() to * validate that data is actually being set and that a table has been * chosen to be update. * - * @access public * @param string the table to update data on * @return bool */ @@ -1584,7 +1654,7 @@ abstract class CI_DB_active_record extends CI_DB_driver { * * @param array * @param string - * @param boolean + * @param bool * @return object */ public function set_update_batch($key, $index = '', $escape = TRUE) @@ -1692,13 +1762,30 @@ abstract class CI_DB_active_record extends CI_DB_driver { // -------------------------------------------------------------------- /** + * Truncate statement + * + * Generates a platform-specific truncate string from the supplied data + * + * If the database does not support the truncate() command, + * then this method maps to 'DELETE FROM table' + * + * @param string the table name + * @return string + */ + protected function _truncate($table) + { + return 'TRUNCATE '.$table; + } + + // -------------------------------------------------------------------- + + /** * Get DELETE query string * * Compiles a delete query string and returns the sql * - * @access public * @param string the table to delete from - * @param boolean TRUE: reset AR values; FALSE: leave AR values alone + * @param bool TRUE: reset AR values; FALSE: leave AR values alone * @return string */ public function get_compiled_delete($table = '', $reset = TRUE) @@ -1719,7 +1806,7 @@ abstract class CI_DB_active_record extends CI_DB_driver { * @param mixed the table(s) to delete from. String or array * @param mixed the where clause * @param mixed the limit clause - * @param boolean + * @param bool * @return object */ public function delete($table = '', $where = '', $limit = NULL, $reset_data = TRUE) @@ -2062,7 +2149,6 @@ abstract class CI_DB_active_record extends CI_DB_driver { * * Empties the AR cache * - * @access public * @return void */ public function flush_cache() @@ -2114,7 +2200,7 @@ abstract class CI_DB_active_record extends CI_DB_driver { // If we are "protecting identifiers" we need to examine the "from" // portion of the query to determine if there are any aliases - if ($this->_protect_identifiers === TRUE AND count($this->ar_cache_from) > 0) + if ($this->_protect_identifiers === TRUE && count($this->ar_cache_from) > 0) { $this->_track_aliases($this->ar_from); } diff --git a/system/database/DB_cache.php b/system/database/DB_cache.php index 58e6968c0..ff942856b 100644 --- a/system/database/DB_cache.php +++ b/system/database/DB_cache.php @@ -177,7 +177,7 @@ class CI_DB_Cache { */ public function delete_all() { - delete_files($this->db->cachedir, TRUE); + delete_files($this->db->cachedir, TRUE, 0, TRUE); } } diff --git a/system/database/DB_driver.php b/system/database/DB_driver.php index 9f1a0b895..8b030af77 100644 --- a/system/database/DB_driver.php +++ b/system/database/DB_driver.php @@ -99,9 +99,13 @@ abstract class CI_DB_driver { */ public function initialize() { - // If an existing connection resource is available - // there is no need to connect and select the database - if (is_resource($this->conn_id) OR is_object($this->conn_id)) + /* If an established connection is available, then there's + * no need to connect and select the database. + * + * Depending on the database driver, conn_id can be either + * boolean TRUE, a resource or an object. + */ + if ($this->conn_id) { return TRUE; } @@ -188,10 +192,24 @@ abstract class CI_DB_driver { // -------------------------------------------------------------------- /** + * Select database + * + * This is just a dummy method to allow drivers without such + * functionality to not declare it, while others will override it. + * + * @return bool + */ + public function db_select() + { + return TRUE; + } + + // -------------------------------------------------------------------- + + /** * Set client character set * * @param string - * @param string * @return bool */ public function db_set_charset($charset) @@ -283,17 +301,13 @@ abstract class CI_DB_driver { { log_message('error', 'Invalid query: '.$sql); - if ($this->db_debug) - { - return $this->display_error('db_invalid_query'); - } - return FALSE; + return ($this->db_debug) ? $this->display_error('db_invalid_query') : FALSE; } // Verify table prefix and replace if necessary - if ( ($this->dbprefix != '' AND $this->swap_pre != '') AND ($this->dbprefix != $this->swap_pre) ) + if ($this->dbprefix != '' && $this->swap_pre != '' && $this->dbprefix != $this->swap_pre) { - $sql = preg_replace("/(\W)".$this->swap_pre."(\S+?)/", "\\1".$this->dbprefix."\\2", $sql); + $sql = preg_replace('/(\W)'.$this->swap_pre.'(\S+?)/', '\\1'.$this->dbprefix.'\\2', $sql); } // Compile binds if needed @@ -305,15 +319,12 @@ abstract class CI_DB_driver { // Is query caching enabled? If the query is a "read type" // we will load the caching class and return the previously // cached query if it exists - if ($this->cache_on == TRUE AND stristr($sql, 'SELECT')) + if ($this->cache_on == TRUE && stripos($sql, 'SELECT') !== FALSE && $this->_cache_init()) { - if ($this->_cache_init()) + $this->load_rdriver(); + if (FALSE !== ($cache = $this->CACHE->read($sql))) { - $this->load_rdriver(); - if (FALSE !== ($cache = $this->CACHE->read($sql))) - { - return $cache; - } + return $cache; } } @@ -352,13 +363,7 @@ abstract class CI_DB_driver { $this->trans_complete(); // Display errors - return $this->display_error( - array( - 'Error Number: '.$error['code'], - $error['message'], - $sql - ) - ); + return $this->display_error(array('Error Number: '.$error['code'], $error['message'], $sql)); } return FALSE; @@ -382,7 +387,7 @@ abstract 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_autodel == TRUE AND $this->_cache_init()) + if ($this->cache_on == TRUE && $this->cache_autodel == TRUE && $this->_cache_init()) { $this->CACHE->delete(); } @@ -402,11 +407,9 @@ abstract class CI_DB_driver { $driver = $this->load_rdriver(); $RES = new $driver($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()) + if ($this->cache_on == TRUE && $this->_cache_init()) { // We'll create a new instance of the result object // only without the platform specific driver since @@ -415,9 +418,9 @@ abstract class CI_DB_driver { // 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(); + $CR->num_rows = $RES->num_rows(); // Reset these since cached objects can not utilize resource IDs. $CR->conn_id = NULL; @@ -608,7 +611,8 @@ abstract class CI_DB_driver { // 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)) { + if (count($binds) >= count($segments)) + { $binds = array_slice($binds, 0, count($segments)-1); } @@ -617,8 +621,7 @@ abstract class CI_DB_driver { $i = 0; foreach ($binds as $bind) { - $result .= $this->escape($bind); - $result .= $segments[++$i]; + $result .= $this->escape($bind).$segments[++$i]; } return $result; @@ -689,15 +692,15 @@ abstract class CI_DB_driver { { if (is_string($str) OR method_exists($str, '__toString')) { - $str = "'".$this->escape_str($str)."'"; + return "'".$this->escape_str($str)."'"; } elseif (is_bool($str)) { - $str = ($str === FALSE) ? 0 : 1; + return ($str === FALSE) ? 0 : 1; } elseif (is_null($str)) { - $str = 'NULL'; + return 'NULL'; } return $str; @@ -733,13 +736,7 @@ abstract class CI_DB_driver { public function primary($table = '') { $fields = $this->list_fields($table); - - if ( ! is_array($fields)) - { - return FALSE; - } - - return current($fields); + return is_array($fields) ? current($fields) : FALSE; } // -------------------------------------------------------------------- @@ -759,35 +756,40 @@ abstract class CI_DB_driver { if (FALSE === ($sql = $this->_list_tables($constrain_by_prefix))) { - if ($this->db_debug) - { - return $this->display_error('db_unsupported_function'); - } - return FALSE; + return ($this->db_debug) ? $this->display_error('db_unsupported_function') : FALSE; } - $retval = array(); + $this->data_cache['table_names'] = array(); $query = $this->query($sql); - if ($query->num_rows() > 0) + foreach ($query->result_array() as $row) { - $table = FALSE; - $rows = $query->result_array(); - $key = (($row = current($rows)) && in_array('table_name', array_map('strtolower', array_keys($row)))); - - if ($key) + // Do we know from which column to get the table name? + if ( ! isset($key)) { - $table = array_key_exists('TABLE_NAME', $row) ? 'TABLE_NAME' : 'table_name'; + if (isset($row['table_name'])) + { + $key = 'table_name'; + } + elseif (isset($row['TABLE_NAME'])) + { + $key = 'TABLE_NAME'; + } + else + { + /* We have no other choice but to just get the first element's key. + * Due to array_shift() accepting it's argument by reference, if + * E_STRICT is on, this would trigger a warning. So we'll have to + * assign it first. + */ + $key = array_keys($row); + $key = array_shift($key); + } } - foreach ($rows as $row) - { - $retval[] = ( ! $table) ? current($row) : $row[$table]; - } + $this->data_cache['table_names'][] = $row[$key]; } - $this->data_cache['table_names'] = $retval; - return $this->data_cache['table_names']; } @@ -821,38 +823,45 @@ abstract class CI_DB_driver { if ($table == '') { - if ($this->db_debug) - { - return $this->display_error('db_field_param_missing'); - } - return FALSE; + return ($this->db_debug) ? $this->display_error('db_field_param_missing') : FALSE; } if (FALSE === ($sql = $this->_list_columns($table))) { - if ($this->db_debug) - { - return $this->display_error('db_unsupported_function'); - } - return FALSE; + return ($this->db_debug) ? $this->display_error('db_unsupported_function') : FALSE; } $query = $this->query($sql); + $this->data_cache['field_names'][$table] = array(); - $retval = array(); foreach ($query->result_array() as $row) { - if (isset($row['COLUMN_NAME'])) - { - $retval[] = $row['COLUMN_NAME']; - } - else + // Do we know from where to get the column's name? + if ( ! isset($key)) { - $retval[] = current($row); + if (isset($row['column_name'])) + { + $key = 'column_name'; + } + elseif (isset($row['COLUMN_NAME'])) + { + $key = 'COLUMN_NAME'; + } + else + { + /* We have no other choice but to just get the first element's key. + * Due to array_shift() accepting it's argument by reference, if + * E_STRICT is on, this would trigger a warning. So we'll have to + * assign it first. + */ + $key = array_keys($row); + $key = array_shift($key); + } } + + $this->data_cache['field_names'][$table][] = $row[$key]; } - $this->data_cache['field_names'][$table] = $retval; return $this->data_cache['field_names'][$table]; } @@ -867,7 +876,7 @@ abstract class CI_DB_driver { */ public 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)); } // -------------------------------------------------------------------- @@ -882,16 +891,48 @@ abstract class CI_DB_driver { { if ($table == '') { - if ($this->db_debug) + return ($this->db_debug) ? $this->display_error('db_field_param_missing') : FALSE; + } + + $query = $this->query($this->_field_data($this->protect_identifiers($table, TRUE, NULL, FALSE))); + return $query->field_data(); + } + + // -------------------------------------------------------------------- + + /** + * Escape the SQL Identifiers + * + * This function escapes column and table names + * + * @param string + * @return string + */ + public function escape_identifiers($item) + { + if ($this->_escape_char == '') + { + return $item; + } + + foreach ($this->_reserved_identifiers as $id) + { + if (strpos($item, '.'.$id) !== FALSE) { - return $this->display_error('db_field_param_missing'); + $item = str_replace('.', $this->_escape_char.'.', $item); + + // remove duplicates if the user already included the escape + return preg_replace('/['.$this->_escape_char.']+/', $this->_escape_char, $this->_escape_char.$item); } - return FALSE; } - $query = $this->query($this->_field_data($this->protect_identifiers($table, TRUE, NULL, FALSE))); + if (strpos($item, '.') !== FALSE) + { + $item = str_replace('.', $this->_escape_char.'.'.$this->_escape_char, $item); + } - return $query->field_data(); + // remove duplicates if the user already included the escape + return preg_replace('/['.$this->_escape_char.']+/', $this->_escape_char, $this->_escape_char.$item.$this->_escape_char); } // -------------------------------------------------------------------- @@ -905,12 +946,11 @@ abstract class CI_DB_driver { */ public function insert_string($table, $data) { - $fields = array(); - $values = array(); + $fields = $values = array(); foreach ($data as $key => $val) { - $fields[] = $this->_escape_identifiers($key); + $fields[] = $this->escape_identifiers($key); $values[] = $this->escape($val); } @@ -979,13 +1019,7 @@ abstract class CI_DB_driver { */ protected function _has_operator($str) { - $str = trim($str); - if ( ! preg_match("/(\s|<|>|!|=|is null|is not null)/i", $str)) - { - return FALSE; - } - - return TRUE; + return (bool) preg_match('/(\s|<|>|!|=|IS NULL|IS NOT NULL)/i', trim($str)); } // -------------------------------------------------------------------- @@ -1008,25 +1042,12 @@ abstract class CI_DB_driver { if ( ! function_exists($function)) { - if ($this->db_debug) - { - return $this->display_error('db_unsupported_function'); - } - return FALSE; + return ($this->db_debug) ? $this->display_error('db_unsupported_function') : FALSE; } - else - { - $args = (func_num_args() > 1) ? array_splice(func_get_args(), 1) : null; - if (is_null($args)) - { - return call_user_func($function); - } - else - { - return call_user_func_array($function, $args); - } - } + return (func_num_args() > 1) + ? call_user_func_array($function, array_splice(func_get_args(), 1)) + : call_user_func($function); } // -------------------------------------------------------------------- @@ -1051,8 +1072,7 @@ abstract class CI_DB_driver { */ public function cache_on() { - $this->cache_on = TRUE; - return TRUE; + return $this->cache_on = TRUE; } // -------------------------------------------------------------------- @@ -1064,8 +1084,7 @@ abstract class CI_DB_driver { */ public function cache_off() { - $this->cache_on = FALSE; - return FALSE; + return $this->cache_on = FALSE; } @@ -1078,11 +1097,9 @@ abstract class CI_DB_driver { */ public function cache_delete($segment_one = '', $segment_two = '') { - if ( ! $this->_cache_init()) - { - return FALSE; - } - return $this->CACHE->delete($segment_one, $segment_two); + return ($this->_cache_init()) + ? $this->CACHE->delete($segment_one, $segment_two) + : FALSE; } // -------------------------------------------------------------------- @@ -1094,12 +1111,9 @@ abstract class CI_DB_driver { */ public function cache_delete_all() { - if ( ! $this->_cache_init()) - { - return FALSE; - } - - return $this->CACHE->delete_all(); + return ($this->_cache_init()) + ? $this->CACHE->delete_all() + : FALSE; } // -------------------------------------------------------------------- @@ -1111,18 +1125,17 @@ abstract class CI_DB_driver { */ protected function _cache_init() { - if (is_object($this->CACHE) AND class_exists('CI_DB_Cache')) + if (class_exists('CI_DB_Cache')) { - return TRUE; - } - - if ( ! class_exists('CI_DB_Cache')) - { - if ( ! @include(BASEPATH.'database/DB_cache.php')) + if (is_object($this->CACHE)) { - return $this->cache_off(); + return TRUE; } } + elseif ( ! @include_once(BASEPATH.'database/DB_cache.php')) + { + return $this->cache_off(); + } $this->CACHE = new CI_DB_Cache($this); // pass db object to support multiple db connections and returned db objects return TRUE; @@ -1137,11 +1150,11 @@ abstract class CI_DB_driver { */ public function close() { - if (is_resource($this->conn_id) OR is_object($this->conn_id)) + if ($this->conn_id) { $this->_close($this->conn_id); + $this->conn_id = FALSE; } - $this->conn_id = FALSE; } // -------------------------------------------------------------------- @@ -1173,9 +1186,7 @@ abstract class CI_DB_driver { // 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) @@ -1183,7 +1194,6 @@ abstract class CI_DB_driver { // Found it - use a relative path for safety $message[] = 'Filename: '.str_replace(array(BASEPATH, APPPATH), '', $call['file']); $message[] = 'Line Number: '.$call['line']; - break; } } @@ -1201,7 +1211,7 @@ abstract 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 + * 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 @@ -1244,12 +1254,15 @@ abstract class CI_DB_driver { // If the item has an alias declaration we remove it and set it aside. // Basically we remove everything to the right of the first space - $alias = ''; if (strpos($item, ' ') !== FALSE) { - $alias = strstr($item, " "); + $alias = strstr($item, ' '); $item = substr($item, 0, - strlen($alias)); } + else + { + $alias = ''; + } // This is basically a bug fix for queries that use MAX, MIN, etc. // If a parenthesis is found we know that we do not need to @@ -1278,12 +1291,13 @@ abstract class CI_DB_driver { { if ( ! in_array($val, $this->_reserved_identifiers)) { - $parts[$key] = $this->_escape_identifiers($val); + $parts[$key] = $this->escape_identifiers($val); } } $item = implode('.', $parts); } + return $item.$alias; } @@ -1318,13 +1332,12 @@ abstract class CI_DB_driver { } // Verify table prefix and replace if necessary - if ($this->swap_pre != '' && strncmp($parts[$i], $this->swap_pre, strlen($this->swap_pre)) === 0) + if ($this->swap_pre != '' && strpos($parts[$i], $this->swap_pre) === 0) { - $parts[$i] = preg_replace("/^".$this->swap_pre."(\S+?)/", $this->dbprefix."\\1", $parts[$i]); + $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) + elseif (strpos($parts[$i], $this->dbprefix) !== 0) { $parts[$i] = $this->dbprefix.$parts[$i]; } @@ -1335,7 +1348,7 @@ abstract class CI_DB_driver { if ($protect_identifiers === TRUE) { - $item = $this->_escape_identifiers($item); + $item = $this->escape_identifiers($item); } return $item.$alias; @@ -1345,21 +1358,20 @@ abstract class CI_DB_driver { if ($this->dbprefix != '') { // Verify table prefix and replace if necessary - if ($this->swap_pre != '' && strncmp($item, $this->swap_pre, strlen($this->swap_pre)) === 0) + if ($this->swap_pre != '' && strpos($item, $this->swap_pre) === 0) { - $item = preg_replace("/^".$this->swap_pre."(\S+?)/", $this->dbprefix."\\1", $item); + $item = preg_replace('/^'.$this->swap_pre.'(\S+?)/', $this->dbprefix.'\\1', $item); } - // Do we prefix an item with no segments? - if ($prefix_single == TRUE AND substr($item, 0, strlen($this->dbprefix)) != $this->dbprefix) + elseif ($prefix_single == TRUE && strpos($item, $this->dbprefix) !== 0) { $item = $this->dbprefix.$item; } } - if ($protect_identifiers === TRUE AND ! in_array($item, $this->_reserved_identifiers)) + if ($protect_identifiers === TRUE && ! in_array($item, $this->_reserved_identifiers)) { - $item = $this->_escape_identifiers($item); + $item = $this->escape_identifiers($item); } return $item.$alias; @@ -1374,7 +1386,9 @@ abstract class CI_DB_driver { * * @return void */ - abstract protected function _reset_select(); + protected function _reset_select() + { + } } diff --git a/system/database/DB_result.php b/system/database/DB_result.php index 04f964fb1..bb09c014c 100644 --- a/system/database/DB_result.php +++ b/system/database/DB_result.php @@ -57,7 +57,7 @@ class CI_DB_result { * Query result. Acts as a wrapper function for the following functions. * * @param string can be "object" or "array" - * @return mixed either a result object or array + * @return object */ public function result($type = 'object') { @@ -108,9 +108,9 @@ class CI_DB_result { // -------------------------------------------------------------------- /** - * Query result. "object" version. + * Query result. "object" version. * - * @return object + * @return array */ public function result_object() { @@ -224,7 +224,7 @@ class CI_DB_result { return; } - if ($key != '' AND ! is_null($value)) + if ($key != '' && ! is_null($value)) { $this->row_data[$key] = $value; } @@ -245,7 +245,7 @@ class CI_DB_result { return $result; } - if ($n != $this->current_row AND isset($result[$n])) + if ($n != $this->current_row && isset($result[$n])) { $this->current_row = $n; } @@ -266,7 +266,7 @@ class CI_DB_result { return $result; } - if ($n != $this->current_row AND isset($result[$n])) + if ($n != $this->current_row && isset($result[$n])) { $this->current_row = $n; } @@ -289,7 +289,7 @@ class CI_DB_result { return $result; } - if ($n != $this->current_row AND isset($result[$n])) + if ($n != $this->current_row && isset($result[$n])) { $this->current_row = $n; } @@ -297,7 +297,6 @@ class CI_DB_result { return $result[$this->current_row]; } - // -------------------------------------------------------------------- /** @@ -374,9 +373,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. */ @@ -384,7 +383,7 @@ class CI_DB_result { public function num_fields() { return 0; } public function list_fields() { return array(); } public function field_data() { return array(); } - public function free_result() { return TRUE; } + public function free_result() { $this->result_id = FALSE; } protected function _data_seek() { return TRUE; } protected function _fetch_assoc() { return array(); } protected function _fetch_object() { return array(); } diff --git a/system/database/drivers/cubrid/cubrid_driver.php b/system/database/drivers/cubrid/cubrid_driver.php index bed3d8685..74d1a850a 100644 --- a/system/database/drivers/cubrid/cubrid_driver.php +++ b/system/database/drivers/cubrid/cubrid_driver.php @@ -159,22 +159,6 @@ class CI_DB_cubrid_driver extends CI_DB { // -------------------------------------------------------------------- /** - * Select the database - * - * @return resource - */ - public function db_select() - { - // In CUBRID there is no need to select a database as the database - // is chosen at the connection time. - // So, to determine if the database is "selected", all we have to - // do is ping the server and return that value. - return cubrid_ping($this->conn_id); - } - - // -------------------------------------------------------------------- - - /** * Database version number * * @return string @@ -451,45 +435,6 @@ class CI_DB_cubrid_driver extends CI_DB { return array('code' => cubrid_errno($this->conn_id), 'message' => cubrid_error($this->conn_id)); } - /** - * Escape the SQL Identifiers - * - * This function escapes column and table names - * - * @param string - * @return string - */ - public function _escape_identifiers($item) - { - if ($this->_escape_char == '') - { - return $item; - } - - foreach ($this->_reserved_identifiers as $id) - { - if (strpos($item, '.'.$id) !== FALSE) - { - $str = $this->_escape_char. str_replace('.', $this->_escape_char.'.', $item); - - // remove duplicates if the user already included the escape - return preg_replace('/['.$this->_escape_char.']+/', $this->_escape_char, $str); - } - } - - if (strpos($item, '.') !== FALSE) - { - $str = $this->_escape_char.str_replace('.', $this->_escape_char.'.'.$this->_escape_char, $item).$this->_escape_char; - } - else - { - $str = $this->_escape_char.$item.$this->_escape_char; - } - - // remove duplicates if the user already included the escape - return preg_replace('/['.$this->_escape_char.']+/', $this->_escape_char, $str); - } - // -------------------------------------------------------------------- /** @@ -514,94 +459,6 @@ class CI_DB_cubrid_driver extends CI_DB { // -------------------------------------------------------------------- /** - * Insert statement - * - * Generates a platform-specific insert string from the supplied data - * - * @param string the table name - * @param array the insert keys - * @param array the insert values - * @return string - */ - protected function _insert($table, $keys, $values) - { - return "INSERT INTO ".$table." (\"".implode('", "', $keys)."\") VALUES (".implode(', ', $values).")"; - } - - // -------------------------------------------------------------------- - - - /** - * Replace statement - * - * Generates a platform-specific replace string from the supplied data - * - * @param string the table name - * @param array the insert keys - * @param array the insert values - * @return string - */ - protected function _replace($table, $keys, $values) - { - return "REPLACE INTO ".$table." (\"".implode('", "', $keys)."\") VALUES (".implode(', ', $values).")"; - } - - // -------------------------------------------------------------------- - - /** - * Insert_batch statement - * - * Generates a platform-specific insert string from the supplied data - * - * @param string the table name - * @param array the insert keys - * @param array the insert values - * @return string - */ - protected function _insert_batch($table, $keys, $values) - { - return "INSERT INTO ".$table." (\"".implode('", "', $keys)."\") VALUES ".implode(', ', $values); - } - - // -------------------------------------------------------------------- - - - /** - * Update statement - * - * Generates a platform-specific update string from the supplied data - * - * @param string the table name - * @param array the update data - * @param array the where clause - * @param array the orderby clause - * @param array the limit clause - * @return string - */ - protected function _update($table, $values, $where, $orderby = array(), $limit = FALSE) - { - foreach ($values as $key => $val) - { - $valstr[] = sprintf('"%s" = %s', $key, $val); - } - - $limit = ( ! $limit) ? '' : ' LIMIT '.$limit; - - $orderby = (count($orderby) >= 1)?' ORDER BY '.implode(", ", $orderby):''; - - $sql = "UPDATE ".$table." SET ".implode(', ', $valstr); - - $sql .= ($where != '' AND count($where) >=1) ? " WHERE ".implode(" ", $where) : ''; - - $sql .= $orderby.$limit; - - return $sql; - } - - // -------------------------------------------------------------------- - - - /** * Update_Batch statement * * Generates a platform-specific batch update string from the supplied data @@ -653,23 +510,6 @@ class CI_DB_cubrid_driver extends CI_DB { // -------------------------------------------------------------------- /** - * Truncate statement - * - * Generates a platform-specific truncate string from the supplied data - * If the database does not support the truncate() command - * This function maps to "DELETE FROM table" - * - * @param string the table name - * @return string - */ - protected function _truncate($table) - { - return "TRUNCATE ".$table; - } - - // -------------------------------------------------------------------- - - /** * Delete statement * * Generates a platform-specific delete string from the supplied data diff --git a/system/database/drivers/cubrid/cubrid_forge.php b/system/database/drivers/cubrid/cubrid_forge.php index bbda484c4..f83dc97f4 100644 --- a/system/database/drivers/cubrid/cubrid_forge.php +++ b/system/database/drivers/cubrid/cubrid_forge.php @@ -184,9 +184,7 @@ class CI_DB_cubrid_forge extends CI_DB_forge { // As of version 8.4.0 CUBRID does not support this SQL syntax. } - $sql .= $this->db->_escape_identifiers($table)." ("; - - $sql .= $this->_process_fields($fields); + $sql .= $this->db->escape_identifiers($table).' ('.$this->_process_fields($fields); // If there is a PK defined if (count($primary_keys) > 0) @@ -230,7 +228,7 @@ class CI_DB_cubrid_forge extends CI_DB_forge { */ public function _drop_table($table) { - return "DROP TABLE IF EXISTS ".$this->db->_escape_identifiers($table); + return 'DROP TABLE IF EXISTS '.$this->db->escape_identifiers($table); } // -------------------------------------------------------------------- diff --git a/system/database/drivers/interbase/interbase_driver.php b/system/database/drivers/interbase/interbase_driver.php index d8b6ae571..88638a21a 100644 --- a/system/database/drivers/interbase/interbase_driver.php +++ b/system/database/drivers/interbase/interbase_driver.php @@ -85,19 +85,6 @@ class CI_DB_interbase_driver extends CI_DB { // -------------------------------------------------------------------- /** - * Select the database - * - * @return bool - */ - public function db_select() - { - // Connection selects the database - return TRUE; - } - - // -------------------------------------------------------------------- - - /** * Database version number * * @return string @@ -356,38 +343,6 @@ class CI_DB_interbase_driver extends CI_DB { // -------------------------------------------------------------------- /** - * Escape the SQL Identifiers - * - * This public function escapes column and table names - * - * @param string - * @return string - */ - protected function _escape_identifiers($item) - { - foreach ($this->_reserved_identifiers as $id) - { - if (strpos($item, '.'.$id) !== FALSE) - { - $item = str_replace('.', $this->_escape_char.'.', $item); - - // remove duplicates if the user already included the escape - return preg_replace('/['.$this->_escape_char.']+/', $this->_escape_char, $this->_escape_char.$item); - } - } - - if (strpos($item, '.') !== FALSE) - { - $item = str_replace('.', $this->_escape_char.'.'.$this->_escape_char, $item); - } - - // remove duplicates if the user already included the escape - return preg_replace('/['.$this->_escape_char.']+/', $this->_escape_char, $this->_escape_char.$item.$this->_escape_char); - } - - // -------------------------------------------------------------------- - - /** * From Tables * * This public function implicitly groups FROM tables so there is no confusion @@ -410,23 +365,6 @@ class CI_DB_interbase_driver extends CI_DB { // -------------------------------------------------------------------- /** - * Insert statement - * - * Generates a platform-specific insert string from the supplied data - * - * @param string the table name - * @param array the insert keys - * @param array the insert values - * @return string - */ - protected function _insert($table, $keys, $values) - { - return 'INSERT INTO '.$table.' ('.implode(', ', $keys).') VALUES ('.implode(', ', $values).')'; - } - - // -------------------------------------------------------------------- - - /** * Update statement * * Generates a platform-specific update string from the supplied data @@ -459,15 +397,16 @@ class CI_DB_interbase_driver extends CI_DB { * Truncate statement * * Generates a platform-specific truncate string from the supplied data - * If the database does not support the truncate() command - * This public function maps to "DELETE FROM table" + * + * If the database does not support the truncate() command, + * then this method maps to 'DELETE FROM table' * * @param string the table name * @return string */ protected function _truncate($table) { - return $this->_delete($table); + return 'DELETE FROM '.$table; } // -------------------------------------------------------------------- diff --git a/system/database/drivers/mssql/mssql_driver.php b/system/database/drivers/mssql/mssql_driver.php index f2933fe43..ae3b843ee 100644 --- a/system/database/drivers/mssql/mssql_driver.php +++ b/system/database/drivers/mssql/mssql_driver.php @@ -52,10 +52,10 @@ class CI_DB_mssql_driver extends CI_DB { /** * The syntax to count rows is slightly different across different * database engines, so this string appears in each driver and is - * used for the count_all() and count_all_results() functions. + * used for the count_all() and count_all_results() methods. */ protected $_count_string = 'SELECT COUNT(*) AS '; - protected $_random_keyword = ' ASC'; // not currently supported + protected $_random_keyword = ' NEWID()'; /** * Non-persistent database connection @@ -404,47 +404,6 @@ class CI_DB_mssql_driver extends CI_DB { // -------------------------------------------------------------------- /** - * Escape the SQL Identifiers - * - * This function escapes column and table names - * - * @param string - * @return string - */ - public function _escape_identifiers($item) - { - if ($this->_escape_char == '') - { - return $item; - } - - foreach ($this->_reserved_identifiers as $id) - { - if (strpos($item, '.'.$id) !== FALSE) - { - $str = $this->_escape_char. str_replace('.', $this->_escape_char.'.', $item); - - // remove duplicates if the user already included the escape - return preg_replace('/['.$this->_escape_char.']+/', $this->_escape_char, $str); - } - } - - if (strpos($item, '.') !== FALSE) - { - $str = $this->_escape_char.str_replace('.', $this->_escape_char.'.'.$this->_escape_char, $item).$this->_escape_char; - } - else - { - $str = $this->_escape_char.$item.$this->_escape_char; - } - - // remove duplicates if the user already included the escape - return preg_replace('/['.$this->_escape_char.']+/', $this->_escape_char, $str); - } - - // -------------------------------------------------------------------- - - /** * From Tables * * This function implicitly groups FROM tables so there is no confusion @@ -466,70 +425,19 @@ class CI_DB_mssql_driver extends CI_DB { // -------------------------------------------------------------------- /** - * Insert statement - * - * Generates a platform-specific insert string from the supplied data - * - * @param string the table name - * @param array the insert keys - * @param array the insert values - * @return string - */ - protected function _insert($table, $keys, $values) - { - return "INSERT INTO ".$table." (".implode(', ', $keys).") VALUES (".implode(', ', $values).")"; - } - - // -------------------------------------------------------------------- - - /** - * Update statement - * - * Generates a platform-specific update string from the supplied data - * - * @param string the table name - * @param array the update data - * @param array the where clause - * @param array the orderby clause - * @param array the limit clause - * @return string - */ - protected function _update($table, $values, $where, $orderby = array(), $limit = FALSE) - { - foreach ($values as $key => $val) - { - $valstr[] = $key." = ".$val; - } - - $limit = ( ! $limit) ? '' : ' LIMIT '.$limit; - - $orderby = (count($orderby) >= 1)?' ORDER BY '.implode(", ", $orderby):''; - - $sql = "UPDATE ".$table." SET ".implode(', ', $valstr); - - $sql .= ($where != '' AND count($where) >=1) ? " WHERE ".implode(" ", $where) : ''; - - $sql .= $orderby.$limit; - - return $sql; - } - - - // -------------------------------------------------------------------- - - /** * Truncate statement * * Generates a platform-specific truncate string from the supplied data - * If the database does not support the truncate() command - * This function maps to "DELETE FROM table" + * + * If the database does not support the truncate() command, + * then this method maps to 'DELETE FROM table' * * @param string the table name * @return string */ protected function _truncate($table) { - return "TRUNCATE ".$table; + return 'TRUNCATE TABLE '.$table; } // -------------------------------------------------------------------- @@ -539,13 +447,12 @@ class CI_DB_mssql_driver extends CI_DB { * * Generates a platform-specific delete string from the supplied data * - * @access public * @param string the table name * @param array the where clause * @param string the limit clause * @return string */ - function _delete($table, $where = array(), $like = array(), $limit = FALSE) + protected function _delete($table, $where = array(), $like = array(), $limit = FALSE) { $conditions = ''; diff --git a/system/database/drivers/mssql/mssql_forge.php b/system/database/drivers/mssql/mssql_forge.php index 2e3e314ed..d787b3764 100644 --- a/system/database/drivers/mssql/mssql_forge.php +++ b/system/database/drivers/mssql/mssql_forge.php @@ -68,7 +68,7 @@ class CI_DB_mssql_forge extends CI_DB_forge { */ public function _drop_table($table) { - return "DROP TABLE ".$this->db->_escape_identifiers($table); + return 'DROP TABLE '.$this->db->escape_identifiers($table); } // -------------------------------------------------------------------- @@ -92,7 +92,7 @@ class CI_DB_mssql_forge extends CI_DB_forge { $sql .= 'IF NOT EXISTS '; } - $sql .= $this->db->_escape_identifiers($table)." ("; + $sql .= $this->db->escape_identifiers($table).' ('; $current_field_count = 0; foreach ($fields as $field => $attributes) diff --git a/system/database/drivers/mysql/mysql_driver.php b/system/database/drivers/mysql/mysql_driver.php index bef4111c3..28020d3e6 100644 --- a/system/database/drivers/mysql/mysql_driver.php +++ b/system/database/drivers/mysql/mysql_driver.php @@ -439,43 +439,6 @@ class CI_DB_mysql_driver extends CI_DB { // -------------------------------------------------------------------- /** - * Escape the SQL Identifiers - * - * This function escapes column and table names - * - * @param string - * @return string - */ - public function _escape_identifiers($item) - { - if ($this->_escape_char == '') - { - return $item; - } - - foreach ($this->_reserved_identifiers as $id) - { - if (strpos($item, '.'.$id) !== FALSE) - { - $item = str_replace('.', $this->_escape_char.'.', $item); - - // remove duplicates if the user already included the escape - return preg_replace('/['.$this->_escape_char.']+/', $this->_escape_char, $this->_escape_char.$item); - } - } - - if (strpos($item, '.') !== FALSE) - { - $item = str_replace('.', $this->_escape_char.'.'.$this->_escape_char, $item); - } - - // remove duplicates if the user already included the escape - return preg_replace('/['.$this->_escape_char.']+/', $this->_escape_char, $this->_escape_char.$item.$this->_escape_char); - } - - // -------------------------------------------------------------------- - - /** * From Tables * * This function implicitly groups FROM tables so there is no confusion @@ -497,59 +460,6 @@ class CI_DB_mysql_driver extends CI_DB { // -------------------------------------------------------------------- /** - * Insert statement - * - * Generates a platform-specific insert string from the supplied data - * - * @param string the table name - * @param array the insert keys - * @param array the insert values - * @return string - */ - protected function _insert($table, $keys, $values) - { - return 'INSERT INTO '.$table.' ('.implode(', ', $keys).') VALUES ('.implode(', ', $values).')'; - } - - // -------------------------------------------------------------------- - - - /** - * Replace statement - * - * Generates a platform-specific replace string from the supplied data - * - * @param string the table name - * @param array the insert keys - * @param array the insert values - * @return string - */ - protected function _replace($table, $keys, $values) - { - return 'REPLACE INTO '.$table.' ('.implode(', ', $keys).') VALUES ('.implode(', ', $values).')'; - } - - // -------------------------------------------------------------------- - - /** - * Insert_batch statement - * - * Generates a platform-specific insert string from the supplied data - * - * @param string the table name - * @param array the insert keys - * @param array the insert values - * @return string - */ - protected function _insert_batch($table, $keys, $values) - { - return 'INSERT INTO '.$table.' ('.implode(', ', $keys).') VALUES '.implode(', ', $values); - } - - // -------------------------------------------------------------------- - - - /** * Update statement * * Generates a platform-specific update string from the supplied data @@ -624,23 +534,6 @@ class CI_DB_mysql_driver extends CI_DB { // -------------------------------------------------------------------- /** - * Truncate statement - * - * Generates a platform-specific truncate string from the supplied data - * If the database does not support the truncate() command - * This function maps to "DELETE FROM table" - * - * @param string the table name - * @return string - */ - protected function _truncate($table) - { - return 'TRUNCATE '.$table; - } - - // -------------------------------------------------------------------- - - /** * Delete statement * * Generates a platform-specific delete string from the supplied data diff --git a/system/database/drivers/mysql/mysql_forge.php b/system/database/drivers/mysql/mysql_forge.php index 11172b41b..9e19de1bb 100644 --- a/system/database/drivers/mysql/mysql_forge.php +++ b/system/database/drivers/mysql/mysql_forge.php @@ -42,7 +42,7 @@ class CI_DB_mysql_forge extends CI_DB_forge { */ public function _create_database($name) { - return 'CREATE DATABASE '.$name; + return 'CREATE DATABASE '.$name.' CHARACTER SET '.$this->db->char_set.' COLLATE '.$this->db->dbcollat; } // -------------------------------------------------------------------- diff --git a/system/database/drivers/mysqli/mysqli_driver.php b/system/database/drivers/mysqli/mysqli_driver.php index 4c5d52127..50e213641 100644 --- a/system/database/drivers/mysqli/mysqli_driver.php +++ b/system/database/drivers/mysqli/mysqli_driver.php @@ -72,8 +72,8 @@ class CI_DB_mysqli_driver extends CI_DB { public function db_connect() { return ($this->port != '') - ? @mysqli_connect($this->hostname, $this->username, $this->password, $this->database, $this->port) - : @mysqli_connect($this->hostname, $this->username, $this->password, $this->database); + ? @new mysqli($this->hostname, $this->username, $this->password, $this->database, $this->port) + : @new mysqli($this->hostname, $this->username, $this->password, $this->database); } // -------------------------------------------------------------------- @@ -92,8 +92,8 @@ class CI_DB_mysqli_driver extends CI_DB { } return ($this->port != '') - ? @mysqli_connect('p:'.$this->hostname, $this->username, $this->password, $this->database, $this->port) - : @mysqli_connect('p:'.$this->hostname, $this->username, $this->password, $this->database); + ? @new mysqli('p:'.$this->hostname, $this->username, $this->password, $this->database, $this->port) + : @new mysqli('p:'.$this->hostname, $this->username, $this->password, $this->database); } // -------------------------------------------------------------------- @@ -108,7 +108,7 @@ class CI_DB_mysqli_driver extends CI_DB { */ public function reconnect() { - if (mysqli_ping($this->conn_id) === FALSE) + if ($this->conn_id !== FALSE && $this->conn_id->ping() === FALSE) { $this->conn_id = FALSE; } @@ -129,7 +129,7 @@ class CI_DB_mysqli_driver extends CI_DB { $database = $this->database; } - if (@mysqli_select_db($this->conn_id, $database)) + if (@$this->conn_id->select_db($database)) { $this->database = $database; return TRUE; @@ -148,7 +148,7 @@ class CI_DB_mysqli_driver extends CI_DB { */ protected function _db_set_charset($charset) { - return @mysqli_set_charset($this->conn_id, $charset); + return @$this->conn_id->set_charset($charset); } // -------------------------------------------------------------------- @@ -162,7 +162,7 @@ class CI_DB_mysqli_driver extends CI_DB { { return isset($this->data_cache['version']) ? $this->data_cache['version'] - : $this->data_cache['version'] = @mysqli_get_server_info($this->conn_id); + : $this->data_cache['version'] = $this->conn_id->server_info; } // -------------------------------------------------------------------- @@ -175,7 +175,7 @@ class CI_DB_mysqli_driver extends CI_DB { */ protected function _execute($sql) { - return @mysqli_query($this->conn_id, $this->_prep_query($sql)); + return @$this->conn_id->query($this->_prep_query($sql)); } // -------------------------------------------------------------------- @@ -286,7 +286,7 @@ class CI_DB_mysqli_driver extends CI_DB { return $str; } - $str = is_object($this->conn_id) ? mysqli_real_escape_string($this->conn_id, $str) : addslashes($str); + $str = is_object($this->conn_id) ? $this->conn_id->real_escape_string($str) : addslashes($str); // escape LIKE condition wildcards if ($like === TRUE) @@ -306,7 +306,7 @@ class CI_DB_mysqli_driver extends CI_DB { */ public function affected_rows() { - return @mysqli_affected_rows($this->conn_id); + return $this->conn_id->affected_rows; } // -------------------------------------------------------------------- @@ -318,7 +318,7 @@ class CI_DB_mysqli_driver extends CI_DB { */ public function insert_id() { - return @mysqli_insert_id($this->conn_id); + return $this->conn_id->insert_id; } // -------------------------------------------------------------------- @@ -357,7 +357,6 @@ class CI_DB_mysqli_driver extends CI_DB { * * Generates a platform-specific query string so that the table names can be fetched * - * @access private * @param bool * @return string */ @@ -434,44 +433,7 @@ class CI_DB_mysqli_driver extends CI_DB { */ public function error() { - return array('code' => mysqli_errno($this->conn_id), 'message' => mysqli_error($this->conn_id)); - } - - // -------------------------------------------------------------------- - - /** - * Escape the SQL Identifiers - * - * This function escapes column and table names - * - * @param string - * @return string - */ - public function _escape_identifiers($item) - { - if ($this->_escape_char == '') - { - return $item; - } - - foreach ($this->_reserved_identifiers as $id) - { - if (strpos($item, '.'.$id) !== FALSE) - { - $item = str_replace('.', $this->_escape_char.'.', $item); - - // remove duplicates if the user already included the escape - return preg_replace('/['.$this->_escape_char.']+/', $this->_escape_char, $this->_escape_char.$item); - } - } - - if (strpos($item, '.') !== FALSE) - { - $item = str_replace('.', $this->_escape_char.'.'.$this->_escape_char, $item); - } - - // remove duplicates if the user already included the escape - return preg_replace('/['.$this->_escape_char.']+/', $this->_escape_char, $this->_escape_char.$item.$this->_escape_char); + return array('code' => $this->conn_id->errno, 'message' => $this->conn_id->error); } // -------------------------------------------------------------------- @@ -498,85 +460,6 @@ class CI_DB_mysqli_driver extends CI_DB { // -------------------------------------------------------------------- /** - * Insert statement - * - * Generates a platform-specific insert string from the supplied data - * - * @param string the table name - * @param array the insert keys - * @param array the insert values - * @return string - */ - protected function _insert($table, $keys, $values) - { - return 'INSERT INTO '.$table.' ('.implode(', ', $keys).') VALUES ('.implode(', ', $values).')'; - } - - // -------------------------------------------------------------------- - - /** - * Insert_batch statement - * - * Generates a platform-specific insert string from the supplied data - * - * @param string the table name - * @param array the insert keys - * @param array the insert values - * @return string - */ - protected function _insert_batch($table, $keys, $values) - { - return 'INSERT INTO '.$table.' ('.implode(', ', $keys).') VALUES '.implode(', ', $values); - } - - // -------------------------------------------------------------------- - - - /** - * Replace statement - * - * Generates a platform-specific replace string from the supplied data - * - * @param string the table name - * @param array the insert keys - * @param array the insert values - * @return string - */ - protected function _replace($table, $keys, $values) - { - return 'REPLACE INTO '.$table.' ('.implode(', ', $keys).') VALUES ('.implode(', ', $values).')'; - } - - // -------------------------------------------------------------------- - - /** - * Update statement - * - * Generates a platform-specific update string from the supplied data - * - * @param string the table name - * @param array the update data - * @param array the where clause - * @param array the orderby clause - * @param array the limit clause - * @return string - */ - protected function _update($table, $values, $where, $orderby = array(), $limit = FALSE) - { - foreach ($values as $key => $val) - { - $valstr[] = $key.' = '.$val; - } - - return 'UPDATE '.$table.' SET '.implode(', ', $valstr) - .(($where != '' && count($where) > 0) ? ' WHERE '.implode(' ', $where) : '') - .(count($orderby) > 0 ? ' ORDER BY '.implode(', ', $orderby) : '') - .( ! $limit ? '' : ' LIMIT '.$limit); - } - - // -------------------------------------------------------------------- - - /** * Update_Batch statement * * Generates a platform-specific batch update string from the supplied data @@ -620,23 +503,6 @@ class CI_DB_mysqli_driver extends CI_DB { // -------------------------------------------------------------------- /** - * Truncate statement - * - * Generates a platform-specific truncate string from the supplied data - * If the database does not support the truncate() command - * This function maps to "DELETE FROM table" - * - * @param string the table name - * @return string - */ - protected function _truncate($table) - { - return 'TRUNCATE '.$table; - } - - // -------------------------------------------------------------------- - - /** * Delete statement * * Generates a platform-specific delete string from the supplied data @@ -691,7 +557,8 @@ class CI_DB_mysqli_driver extends CI_DB { */ protected function _close($conn_id) { - @mysqli_close($conn_id); + $this->conn_id->close(); + $this->conn_id = FALSE; } } diff --git a/system/database/drivers/mysqli/mysqli_forge.php b/system/database/drivers/mysqli/mysqli_forge.php index 8cf0ae1fd..4b6939e2a 100644 --- a/system/database/drivers/mysqli/mysqli_forge.php +++ b/system/database/drivers/mysqli/mysqli_forge.php @@ -42,7 +42,7 @@ class CI_DB_mysqli_forge extends CI_DB_forge { */ public function _create_database($name) { - return 'CREATE DATABASE '.$name; + return 'CREATE DATABASE '.$name.' CHARACTER SET '.$this->db->char_set.' COLLATE '.$this->db->dbcollat; } // -------------------------------------------------------------------- @@ -148,7 +148,7 @@ class CI_DB_mysqli_forge extends CI_DB_forge { $sql .= 'IF NOT EXISTS '; } - $sql .= $this->db->_escape_identifiers($table).' ('.$this->_process_fields($fields); + $sql .= $this->db->escape_identifiers($table).' ('.$this->_process_fields($fields); if (count($primary_keys) > 0) { @@ -187,7 +187,7 @@ class CI_DB_mysqli_forge extends CI_DB_forge { */ public function _drop_table($table) { - return 'DROP TABLE IF EXISTS '.$this->db->_escape_identifiers($table); + return 'DROP TABLE IF EXISTS '.$this->db->escape_identifiers($table); } // -------------------------------------------------------------------- diff --git a/system/database/drivers/mysqli/mysqli_result.php b/system/database/drivers/mysqli/mysqli_result.php index 83d88aae3..cf0362217 100644 --- a/system/database/drivers/mysqli/mysqli_result.php +++ b/system/database/drivers/mysqli/mysqli_result.php @@ -43,7 +43,7 @@ class CI_DB_mysqli_result extends CI_DB_result { */ public function num_rows() { - return @mysqli_num_rows($this->result_id); + return $this->result_id->num_rows; } // -------------------------------------------------------------------- @@ -55,7 +55,7 @@ class CI_DB_mysqli_result extends CI_DB_result { */ public function num_fields() { - return @mysqli_num_fields($this->result_id); + return $this->result_id->field_count; } // -------------------------------------------------------------------- @@ -70,7 +70,7 @@ class CI_DB_mysqli_result extends CI_DB_result { public function list_fields() { $field_names = array(); - while ($field = mysqli_fetch_field($this->result_id)) + while ($field = $this->result_id->fetch_field()) { $field_names[] = $field->name; } @@ -90,7 +90,7 @@ class CI_DB_mysqli_result extends CI_DB_result { public function field_data() { $retval = array(); - $field_data = mysqli_fetch_fields($this->result_id); + $field_data = $this->result_id->fetch_fields(); for ($i = 0, $c = count($field_data); $i < $c; $i++) { $retval[$i] = new stdClass(); @@ -115,7 +115,7 @@ class CI_DB_mysqli_result extends CI_DB_result { { if (is_object($this->result_id)) { - mysqli_free_result($this->result_id); + $this->result_id->free(); $this->result_id = FALSE; } } @@ -133,7 +133,7 @@ class CI_DB_mysqli_result extends CI_DB_result { */ protected function _data_seek($n = 0) { - return mysqli_data_seek($this->result_id, $n); + return $this->result_id->data_seek($n); } // -------------------------------------------------------------------- @@ -147,7 +147,7 @@ class CI_DB_mysqli_result extends CI_DB_result { */ protected function _fetch_assoc() { - return mysqli_fetch_assoc($this->result_id); + return $this->result_id->fetch_assoc(); } // -------------------------------------------------------------------- @@ -161,7 +161,7 @@ class CI_DB_mysqli_result extends CI_DB_result { */ protected function _fetch_object() { - return mysqli_fetch_object($this->result_id); + return $this->result_id->fetch_object(); } } diff --git a/system/database/drivers/mysqli/mysqli_utility.php b/system/database/drivers/mysqli/mysqli_utility.php index 4d7002e78..cb3f86b8b 100644 --- a/system/database/drivers/mysqli/mysqli_utility.php +++ b/system/database/drivers/mysqli/mysqli_utility.php @@ -56,7 +56,7 @@ class CI_DB_mysqli_utility extends CI_DB_utility { */ public function _optimize_table($table) { - return 'OPTIMIZE TABLE '.$this->db->_escape_identifiers($table); + return 'OPTIMIZE TABLE '.$this->db->escape_identifiers($table); } // -------------------------------------------------------------------- @@ -71,7 +71,7 @@ class CI_DB_mysqli_utility extends CI_DB_utility { */ public function _repair_table($table) { - return 'REPAIR TABLE '.$this->db->_escape_identifiers($table); + return 'REPAIR TABLE '.$this->db->escape_identifiers($table); } // -------------------------------------------------------------------- diff --git a/system/database/drivers/oci8/oci8_driver.php b/system/database/drivers/oci8/oci8_driver.php index c9e791d63..6e225ee1f 100644 --- a/system/database/drivers/oci8/oci8_driver.php +++ b/system/database/drivers/oci8/oci8_driver.php @@ -46,7 +46,6 @@ * permit access to oracle databases * * @author Kelly McArdle - * */ class CI_DB_oci8_driver extends CI_DB { @@ -68,7 +67,7 @@ class CI_DB_oci8_driver extends CI_DB { protected $_random_keyword = ' ASC'; // not currently supported // Set "auto commit" by default - protected $_commit = OCI_COMMIT_ON_SUCCESS; + public $commit_mode = OCI_COMMIT_ON_SUCCESS; // need to track statement id and cursor id public $stmt_id; @@ -78,6 +77,85 @@ class CI_DB_oci8_driver extends CI_DB { // throw off num_fields later public $limit_used; + public function __construct($params) + { + parent::__construct($params); + + $valid_dsns = array( + 'tns' => '/^\(DESCRIPTION=(\(.+\)){2,}\)$/', // TNS + // Easy Connect string (Oracle 10g+) + 'ec' => '/^(\/\/)?[a-z0-9.:_-]+(:[1-9][0-9]{0,4})?(\/[a-z0-9$_]+)?(:[^\/])?(\/[a-z0-9$_]+)?$/i', + 'in' => '/^[a-z0-9$_]+$/i' // Instance name (defined in tnsnames.ora) + ); + + /* Space characters don't have any effect when actually + * connecting, but can be a hassle while validating the DSN. + */ + $this->dsn = str_replace(array("\n", "\r", "\t", ' '), '', $this->dsn); + + if ($this->dsn !== '') + { + foreach ($valid_dsns as $regexp) + { + if (preg_match($regexp, $this->dsn)) + { + return; + } + } + } + + // Legacy support for TNS in the hostname configuration field + $this->hostname = str_replace(array("\n", "\r", "\t", ' '), '', $this->hostname); + if (preg_match($valid_dsns['tns'], $this->hostname)) + { + $this->dsn = $this->hostname; + return; + } + elseif ($this->hostname !== '' && strpos($this->hostname, '/') === FALSE && strpos($this->hostname, ':') === FALSE + && (( ! empty($this->port) && ctype_digit($this->port)) OR $this->database !== '')) + { + /* If the hostname field isn't empty, doesn't contain + * ':' and/or '/' and if port and/or database aren't + * empty, then the hostname field is most likely indeed + * just a hostname. Therefore we'll try and build an + * Easy Connect string from these 3 settings, assuming + * that the database field is a service name. + */ + $this->dsn = $this->hostname + .(( ! empty($this->port) && ctype_digit($this->port)) ? ':'.$this->port : '') + .($this->database !== '' ? '/'.ltrim($this->database, '/') : ''); + + if (preg_match($valid_dsns['ec'], $this->dsn)) + { + return; + } + } + + /* At this point, we can only try and validate the hostname and + * database fields separately as DSNs. + */ + if (preg_match($valid_dsns['ec'], $this->hostname) OR preg_match($valid_dsns['in'], $this->hostname)) + { + $this->dsn = $this->hostname; + return; + } + + $this->database = str_replace(array("\n", "\r", "\t", ' '), '', $this->database); + foreach ($valid_dsns as $regexp) + { + if (preg_match($regexp, $this->database)) + { + return; + } + } + + /* Well - OK, an empty string should work as well. + * PHP will try to use environment variables to + * determine which Oracle instance to connect to. + */ + $this->dsn = ''; + } + /** * Non-persistent database connection * @@ -85,7 +163,9 @@ class CI_DB_oci8_driver extends CI_DB { */ public function db_connect() { - return @oci_connect($this->username, $this->password, $this->hostname, $this->char_set); + return ( ! empty($this->char_set)) + ? @oci_connect($this->username, $this->password, $this->dsn, $this->char_set) + : @oci_connect($this->username, $this->password, $this->dsn); } // -------------------------------------------------------------------- @@ -97,20 +177,9 @@ class CI_DB_oci8_driver extends CI_DB { */ public function db_pconnect() { - return @oci_pconnect($this->username, $this->password, $this->hostname, $this->char_set); - } - - // -------------------------------------------------------------------- - - /** - * Select the database - * - * @return resource - */ - public function db_select() - { - // Not in Oracle - schemas are actually usernames - return TRUE; + return ( ! empty($this->char_set)) + ? @oci_pconnect($this->username, $this->password, $this->dsn, $this->char_set) + : @oci_pconnect($this->username, $this->password, $this->dsn); } // -------------------------------------------------------------------- @@ -137,12 +206,13 @@ class CI_DB_oci8_driver extends CI_DB { */ protected function _execute($sql) { - // oracle must parse the query before it is run. All of the actions with - // the query are based on the statement id returned by ociparse + /* Oracle must parse the query before it is run. All of the actions with + * the query are based on the statement id returned by oci_parse(). + */ $this->stmt_id = FALSE; $this->_set_stmt_id($sql); oci_set_prefetch($this->stmt_id, 1000); - return @oci_execute($this->stmt_id, $this->_commit); + return @oci_execute($this->stmt_id, $this->commit_mode); } /** @@ -168,8 +238,7 @@ class CI_DB_oci8_driver extends CI_DB { */ public function get_cursor() { - $this->curs_id = oci_new_cursor($this->conn_id); - return $this->curs_id; + return $this->curs_id = oci_new_cursor($this->conn_id); } // -------------------------------------------------------------------- @@ -177,19 +246,19 @@ class CI_DB_oci8_driver extends CI_DB { /** * Stored Procedure. Executes a stored procedure * - * @param string package stored procedure is in - * @param string stored procedure to execute + * @param string package name in which the stored procedure is in + * @param string stored procedure name to execute * @param array parameters - * @return object + * @return mixed * * params array keys * * KEY OPTIONAL NOTES - * name no the name of the parameter should be in :<param_name> 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 + * name no the name of the parameter should be in :<param_name> format + * value no the value of the parameter. If this is an OUT or IN OUT parameter, + * this should be a reference to a variable + * type yes the type of the parameter + * length yes the max size of the parameter */ public function stored_procedure($package, $procedure, $params) { @@ -204,24 +273,24 @@ class CI_DB_oci8_driver extends CI_DB { } // build the query string - $sql = "begin $package.$procedure("; + $sql = 'BEGIN '.$package.'.'.$procedure.'('; $have_cursor = FALSE; foreach ($params as $param) { - $sql .= $param['name'] . ","; + $sql .= $param['name'].','; - if (array_key_exists('type', $param) && ($param['type'] === OCI_B_CURSOR)) + if (isset($param['type']) && $param['type'] === OCI_B_CURSOR) { $have_cursor = TRUE; } } - $sql = trim($sql, ",") . "); end;"; + $sql = trim($sql, ',') . '); END;'; $this->stmt_id = FALSE; $this->_set_stmt_id($sql); $this->_bind_params($params); - $this->query($sql, FALSE, $have_cursor); + return $this->query($sql, FALSE, $have_cursor); } // -------------------------------------------------------------------- @@ -277,7 +346,7 @@ class CI_DB_oci8_driver extends CI_DB { // even if the queries produce a successful result. $this->_trans_failure = ($test_mode === TRUE) ? TRUE : FALSE; - $this->_commit = OCI_DEFAULT; + $this->commit_mode = (is_php('5.3.2')) ? OCI_NO_AUTO_COMMIT : OCI_DEFAULT; return TRUE; } @@ -301,9 +370,8 @@ class CI_DB_oci8_driver extends CI_DB { return TRUE; } - $ret = oci_commit($this->conn_id); - $this->_commit = OCI_COMMIT_ON_SUCCESS; - return $ret; + $this->commit_mode = OCI_COMMIT_ON_SUCCESS; + return oci_commit($this->conn_id); } // -------------------------------------------------------------------- @@ -315,20 +383,14 @@ class CI_DB_oci8_driver extends CI_DB { */ public function trans_rollback() { - if ( ! $this->trans_enabled) - { - return TRUE; - } - // When transactions are nested we only begin/commit/rollback the outermost ones - if ($this->_trans_depth > 0) + if ( ! $this->trans_enabled OR $this->_trans_depth > 0) { return TRUE; } - $ret = oci_rollback($this->conn_id); - $this->_commit = OCI_COMMIT_ON_SUCCESS; - return $ret; + $this->commit_mode = OCI_COMMIT_ON_SUCCESS; + return oci_rollback($this->conn_id); } // -------------------------------------------------------------------- @@ -399,7 +461,7 @@ class CI_DB_oci8_driver extends CI_DB { * the specified database * * @param string - * @return string + * @return int */ public function count_all($table = '') { @@ -431,11 +493,11 @@ class CI_DB_oci8_driver extends CI_DB { */ protected function _list_tables($prefix_limit = FALSE) { - $sql = "SELECT TABLE_NAME FROM ALL_TABLES"; + $sql = 'SELECT TABLE_NAME FROM ALL_TABLES'; - if ($prefix_limit !== FALSE AND $this->dbprefix != '') + if ($prefix_limit !== FALSE && $this->dbprefix != '') { - $sql .= " WHERE TABLE_NAME LIKE '".$this->escape_like_str($this->dbprefix)."%' ".sprintf($this->_like_escape_str, $this->_like_escape_chr); + return $sql." WHERE TABLE_NAME LIKE '".$this->escape_like_str($this->dbprefix)."%' ".sprintf($this->_like_escape_str, $this->_like_escape_chr); } return $sql; @@ -453,7 +515,7 @@ class CI_DB_oci8_driver extends CI_DB { */ protected function _list_columns($table = '') { - return "SELECT COLUMN_NAME FROM all_tab_columns WHERE table_name = '$table'"; + return 'SELECT COLUMN_NAME FROM all_tab_columns WHERE table_name = \''.$table.'\''; } // -------------------------------------------------------------------- @@ -468,7 +530,7 @@ class CI_DB_oci8_driver extends CI_DB { */ protected function _field_data($table) { - return "SELECT * FROM ".$table." where rownum = 1"; + return 'SELECT * FROM '.$table.' WHERE rownum = 1'; } // -------------------------------------------------------------------- @@ -505,47 +567,6 @@ class CI_DB_oci8_driver extends CI_DB { // -------------------------------------------------------------------- /** - * Escape the SQL Identifiers - * - * This function escapes column and table names - * - * @param string - * @return string - */ - public function _escape_identifiers($item) - { - if ($this->_escape_char == '') - { - return $item; - } - - foreach ($this->_reserved_identifiers as $id) - { - if (strpos($item, '.'.$id) !== FALSE) - { - $str = $this->_escape_char. str_replace('.', $this->_escape_char.'.', $item); - - // remove duplicates if the user already included the escape - return preg_replace('/['.$this->_escape_char.']+/', $this->_escape_char, $str); - } - } - - if (strpos($item, '.') !== FALSE) - { - $str = $this->_escape_char.str_replace('.', $this->_escape_char.'.'.$this->_escape_char, $item).$this->_escape_char; - } - else - { - $str = $this->_escape_char.$item.$this->_escape_char; - } - - // remove duplicates if the user already included the escape - return preg_replace('/['.$this->_escape_char.']+/', $this->_escape_char, $str); - } - - // -------------------------------------------------------------------- - - /** * From Tables * * This function implicitly groups FROM tables so there is no confusion @@ -556,29 +577,7 @@ class CI_DB_oci8_driver extends CI_DB { */ protected function _from_tables($tables) { - if ( ! is_array($tables)) - { - $tables = array($tables); - } - - return implode(', ', $tables); - } - - // -------------------------------------------------------------------- - - /** - * Insert statement - * - * Generates a platform-specific insert string from the supplied data - * - * @param string the table name - * @param array the insert keys - * @param array the insert values - * @return string - */ - protected function _insert($table, $keys, $values) - { - return "INSERT INTO ".$table." (".implode(', ', $keys).") VALUES (".implode(', ', $values).")"; + return is_array($tables) ? implode(', ', $tables) : $tables; } // -------------------------------------------------------------------- @@ -600,46 +599,10 @@ class CI_DB_oci8_driver extends CI_DB { for ($i = 0, $c = count($values); $i < $c; $i++) { - $sql .= ' INTO ' . $table . ' (' . $keys . ') VALUES ' . $values[$i] . "\n"; + $sql .= ' INTO '.$table.' ('.$keys.') VALUES '.$values[$i]."\n"; } - $sql .= 'SELECT * FROM dual'; - - return $sql; - } - - // -------------------------------------------------------------------- - - /** - * Update statement - * - * Generates a platform-specific update string from the supplied data - * - * @param string the table name - * @param array the update data - * @param array the where clause - * @param array the orderby clause - * @param array the limit clause - * @return string - */ - protected function _update($table, $values, $where, $orderby = array(), $limit = FALSE) - { - foreach ($values as $key => $val) - { - $valstr[] = $key." = ".$val; - } - - $limit = ( ! $limit) ? '' : ' LIMIT '.$limit; - - $orderby = (count($orderby) >= 1)?' ORDER BY '.implode(", ", $orderby):''; - - $sql = "UPDATE ".$table." SET ".implode(', ', $valstr); - - $sql .= ($where != '' AND count($where) >=1) ? " WHERE ".implode(" ", $where) : ''; - - $sql .= $orderby.$limit; - - return $sql; + return $sql.'SELECT * FROM dual'; } // -------------------------------------------------------------------- @@ -648,15 +611,16 @@ class CI_DB_oci8_driver extends CI_DB { * Truncate statement * * Generates a platform-specific truncate string from the supplied data - * If the database does not support the truncate() command - * This function maps to "DELETE FROM table" + * + * If the database does not support the truncate() command, + * then this method maps to 'DELETE FROM table' * * @param string the table name * @return string */ protected function _truncate($table) { - return "TRUNCATE TABLE ".$table; + return 'TRUNCATE TABLE '.$table; } // -------------------------------------------------------------------- @@ -674,22 +638,18 @@ class CI_DB_oci8_driver extends CI_DB { protected function _delete($table, $where = array(), $like = array(), $limit = FALSE) { $conditions = ''; - if (count($where) > 0 OR count($like) > 0) { - $conditions = "\nWHERE "; - $conditions .= implode("\n", $this->ar_where); + $conditions = "\nWHERE ".implode("\n", $this->ar_where); if (count($where) > 0 && count($like) > 0) { - $conditions .= " AND "; + $conditions .= ' AND '; } $conditions .= implode("\n", $like); } - $limit = ( ! $limit) ? '' : ' LIMIT '.$limit; - - return "DELETE FROM ".$table.$conditions.$limit; + return 'DELETE FROM '.$table.$conditions.( ! $limit ? '' : ' LIMIT '.$limit); } // -------------------------------------------------------------------- @@ -706,18 +666,9 @@ class CI_DB_oci8_driver extends CI_DB { */ protected function _limit($sql, $limit, $offset) { - $limit = $offset + $limit; - $newsql = "SELECT * FROM (select inner_query.*, rownum rnum FROM ($sql) inner_query WHERE rownum < $limit)"; - - if ($offset != 0) - { - $newsql .= " WHERE rnum >= $offset"; - } - - // remember that we used limits $this->limit_used = TRUE; - - return $newsql; + return 'SELECT * FROM (SELECT inner_query.*, rownum rnum FROM ('.$sql.') inner_query WHERE rownum < '.($offset + $limit).')' + .($offset != 0 ? ' WHERE rnum >= '.$offset : ''); } // -------------------------------------------------------------------- diff --git a/system/database/drivers/oci8/oci8_forge.php b/system/database/drivers/oci8/oci8_forge.php index 8285a29d2..033e618e7 100644 --- a/system/database/drivers/oci8/oci8_forge.php +++ b/system/database/drivers/oci8/oci8_forge.php @@ -42,6 +42,7 @@ class CI_DB_oci8_forge extends CI_DB_forge { */ public function _create_database($name) { + // Not supported - schemas in Oracle are actual usernames return FALSE; } @@ -55,6 +56,7 @@ class CI_DB_oci8_forge extends CI_DB_forge { */ public function _drop_database($name) { + // Not supported - schemas in Oracle are actual usernames return FALSE; } @@ -68,7 +70,7 @@ class CI_DB_oci8_forge extends CI_DB_forge { * @param mixed primary key(s) * @param mixed key(s) * @param bool should 'IF NOT EXISTS' be added to the SQL - * @return bool + * @return string */ public function _create_table($table, $fields, $primary_keys, $keys, $if_not_exists) { @@ -79,7 +81,7 @@ class CI_DB_oci8_forge extends CI_DB_forge { $sql .= 'IF NOT EXISTS '; } - $sql .= $this->db->_escape_identifiers($table).' ('; + $sql .= $this->db->escape_identifiers($table).' ('; $current_field_count = 0; foreach ($fields as $field => $attributes) @@ -128,7 +130,7 @@ class CI_DB_oci8_forge extends CI_DB_forge { $key = array($this->db->protect_identifiers($key)); } - $sql .= ",\n\tUNIQUE COLUMNS (".implode(', ', $key).")"; + $sql .= ",\n\tUNIQUE COLUMNS (".implode(', ', $key).')'; } } @@ -140,11 +142,11 @@ class CI_DB_oci8_forge extends CI_DB_forge { /** * Drop Table * - * @return bool + * @return string */ public function _drop_table($table) { - return FALSE; + return 'DROP TABLE '.$this->db->protect_identifiers($table); } // -------------------------------------------------------------------- @@ -169,33 +171,15 @@ class CI_DB_oci8_forge extends CI_DB_forge { $sql = 'ALTER TABLE '.$this->db->protect_identifiers($table).' '.$alter_type.' '.$this->db->protect_identifiers($column_name); // DROP has everything it needs now. - if ($alter_type == 'DROP') + if ($alter_type === 'DROP') { return $sql; } - $sql .= " $column_definition"; - - if ($default_value != '') - { - $sql .= " DEFAULT \"$default_value\""; - } - - if ($null === NULL) - { - $sql .= ' NULL'; - } - else - { - $sql .= ' NOT NULL'; - } - - if ($after_field != '') - { - return $sql.' AFTER '.$this->db->protect_identifiers($after_field); - } - - return $sql; + return $sql.' '.$column_definition + .($default_value != '' ? ' DEFAULT "'.$default_value.'"' : '') + .($null === NULL ? ' NULL' : ' NOT NULL') + .($after_field != '' ? ' AFTER '.$this->db->protect_identifiers($after_field) : ''); } diff --git a/system/database/drivers/oci8/oci8_result.php b/system/database/drivers/oci8/oci8_result.php index c3f775730..aad24cfd9 100644 --- a/system/database/drivers/oci8/oci8_result.php +++ b/system/database/drivers/oci8/oci8_result.php @@ -39,6 +39,12 @@ class CI_DB_oci8_result extends CI_DB_result { public $stmt_id; public $curs_id; public $limit_used; + public $commit_mode; + + /* Overwriting the parent here, so we have a way to know if it's + * already called or not: + */ + public $num_rows; public function __construct(&$driver_object) { @@ -46,28 +52,32 @@ class CI_DB_oci8_result extends CI_DB_result { $this->stmt_id = $driver_object->stmt_id; $this->curs_id = $driver_object->curs_id; $this->limit_used = $driver_object->limit_used; + $this->commit_mode =& $driver_object->commit_mode; $driver_object->stmt_id = FALSE; } /** * Number of rows in the result set. * - * Oracle doesn't have a graceful way to retun the number of rows + * Oracle doesn't have a graceful way to return the number of rows * so we have to use what amounts to a hack. * * @return int */ public function num_rows() { - if ($this->num_rows === 0 && count($this->result_array()) > 0) + if ( ! is_int($this->num_rows)) { - $this->num_rows = count($this->result_array()); - @oci_execute($this->stmt_id, OCI_DEFAULT); - - if ($this->curs_id) + if (count($this->result_array) > 0) + { + return $this->num_rows = count($this->result_array); + } + elseif (count($this->result_object) > 0) { - @oci_execute($this->curs_id, OCI_DEFAULT); + return $this->num_rows = count($this->result_object); } + + return $this->num_rows = count($this->result_array()); } return $this->num_rows; @@ -85,12 +95,7 @@ class CI_DB_oci8_result extends CI_DB_result { $count = @oci_num_fields($this->stmt_id); // if we used a limit we subtract it - if ($this->limit_used) - { - $count = $count - 1; - } - - return $count; + return ($this->limit_used) ? $count - 1 : $count; } // -------------------------------------------------------------------- @@ -126,10 +131,10 @@ class CI_DB_oci8_result extends CI_DB_result { $retval = array(); for ($c = 1, $fieldCount = $this->num_fields(); $c <= $fieldCount; $c++) { - $F = new stdClass(); - $F->name = oci_field_name($this->stmt_id, $c); - $F->type = oci_field_type($this->stmt_id, $c); - $F->max_length = oci_field_size($this->stmt_id, $c); + $F = new stdClass(); + $F->name = oci_field_name($this->stmt_id, $c); + $F->type = oci_field_type($this->stmt_id, $c); + $F->max_length = oci_field_size($this->stmt_id, $c); $retval[] = $F; } @@ -151,6 +156,17 @@ class CI_DB_oci8_result extends CI_DB_result { oci_free_statement($this->result_id); $this->result_id = FALSE; } + + if (is_resource($this->stmt_id)) + { + oci_free_statement($this->stmt_id); + } + + if (is_resource($this->curs_id)) + { + oci_cancel($this->curs_id); + $this->curs_id = NULL; + } } // -------------------------------------------------------------------- @@ -180,13 +196,13 @@ class CI_DB_oci8_result extends CI_DB_result { protected function _fetch_object() { $id = ($this->curs_id) ? $this->curs_id : $this->stmt_id; - return @oci_fetch_object($id); + return oci_fetch_object($id); } // -------------------------------------------------------------------- /** - * Query result. "array" version. + * Query result. Array version. * * @return array */ @@ -196,14 +212,433 @@ class CI_DB_oci8_result extends CI_DB_result { { return $this->result_array; } + elseif (count($this->result_object) > 0) + { + for ($i = 0, $c = count($this->result_object); $i < $c; $i++) + { + $this->result_array[$i] = (array) $this->result_object[$i]; + } + + return $this->result_array; + } + elseif (is_array($this->row_data)) + { + if (count($this->row_data) === 0) + { + return $this->result_array; + } + else + { + $row_index = count($this->row_data); + } + } + else + { + $row_index = 0; + $this->row_data = array(); + } $row = NULL; while ($row = $this->_fetch_assoc()) { - $this->result_array[] = $row; + $this->row_data[$row_index++] = $row; + } + + // Un-comment the following line, in case it becomes needed + // $this->_data_seek(); + return $this->result_array = $this->row_data; + } + + // -------------------------------------------------------------------- + + /** + * Query result. "object" version. + * + * @return array + */ + public function result_object() + { + if (count($this->result_object) > 0) + { + return $this->result_object; + } + elseif (count($this->result_array) > 0) + { + for ($i = 0, $c = count($this->result_array); $i < $c; $i++) + { + $this->result_object[] = (object) $this->result_array[$i]; + } + + return $this->result_object; + } + elseif (is_array($this->row_data)) + { + if (count($this->row_data) === 0) + { + return $this->result_object; + } + else + { + $row_index = count($this->row_data); + for ($i = 0; $i < $row_index; $i++) + { + $this->result_object[$i] = (object) $this->row_data[$i]; + } + } + } + else + { + $row_index = 0; + $this->row_data = array(); + } + + $row = NULL; + while ($row = $this->_fetch_object()) + { + $this->row_data[$row_index] = (array) $row; + $this->result_object[$row_index++] = $row; + } + + // Un-comment the following line, in case it becomes needed + // $this->_data_seek(); + return $this->result_object; + } + + // -------------------------------------------------------------------- + + /** + * Query result. Custom object version. + * + * @param string class name used to instantiate rows to + * @return array + */ + public function custom_result_object($class_name) + { + if (isset($this->custom_result_object[$class_name])) + { + return $this->custom_result_object[$class_name]; + } + + if ( ! class_exists($class_name) OR $this->result_id === FALSE OR $this->num_rows() === 0) + { + return array(); + } + + /* Even if we didn't have result_array or result_object + * set prior to custom_result_object() being called, + * num_rows() has already done so. + * Pass by reference, as we don't know how + * large it might be and we don't want 1000 row + * sets being copied. + */ + if (count($this->result_array) > 0) + { + $data = &$this->result_array; + } + elseif (count($this->result_object) > 0) + { + $data = &$this->result_object; + } + + $this->custom_result_object[$class_name] = array(); + for ($i = 0, $c = count($data); $i < $c; $i++) + { + $this->custom_result_object[$class_name][$i] = new $class_name(); + foreach ($data[$i] as $key => $value) + { + $this->custom_result_object[$class_name][$i]->$key = $value; + } + } + + return $this->custom_result_object[$class_name]; + } + + // -------------------------------------------------------------------- + + /* Single row result. + * + * Acts as a wrapper for row_object(), row_array() + * and custom_row_object(). Also used by first_row(), next_row() + * and previous_row(). + * + * @param int row index + * @param string ('object', 'array' or a custom class name) + * @return mixed whatever was passed to the second parameter + */ + public function row($n = 0, $type = 'object') + { + if ($type === 'object') + { + return $this->row_object($n); + } + elseif ($type === 'array') + { + return $this->row_array($n); + } + + return $this->custom_row_object($n, $type); + } + + // -------------------------------------------------------------------- + + /* Single row result. Array version. + * + * @param int row index + * @return array + */ + public function row_array($n = 0) + { + // Make sure $n is not a string + if ( ! is_int($n)) + { + $n = (int) $n; + } + + /* If row_data is initialized, it means that we've already tried + * (at least) to fetch some data, so ... check if we already have + * this row. + */ + if (is_array($this->row_data)) + { + /* If we already have row_data[$n] - return it. + * + * If we enter the elseif, there's a number of reasons to + * return an empty array: + * + * - count($this->row_data) === 0 means there are no results + * - num_rows being set, result_array and/or result_object + * having count() > 0 means that we've already fetched all + * data and $n is greater than our highest row index available + * - $n < $this->current_row means that if such row existed, + * we would've already returned it, therefore $n is an + * invalid index + */ + if (isset($this->row_data[$n])) // We already have this row + { + $this->current_row = $n; + return $this->row_data[$n]; + } + elseif (count($this->row_data) === 0 OR is_int($this->num_rows) + OR count($this->result_array) > 0 OR count($this->result_object) > 0 + OR $n < $this->current_row) + { + // No such row exists + return array(); + } + + // Get the next row index that would actually need to be fetched + $current_row = ($this->current_row < count($this->row_data)) ? count($this->row_data) : $this->current_row + 1; + } + else + { + $current_row = $this->current_row = 0; + $this->row_data = array(); + } + + /* Fetch more data, if available + * + * NOTE: Operator precedence is important here, if you change + * 'AND' with '&&' - it WILL BREAK the results, as + * $row will be assigned the scalar value of both + * expressions! + */ + while ($row = $this->_fetch_assoc() AND $current_row <= $n) + { + $this->row_data[$current_row++] = $row; } - return $this->result_array; + // This would mean that there's no (more) data to fetch + if ( ! is_array($this->row_data) OR ! isset($this->row_data[$n])) + { + // Cache what we already have + if (is_array($this->row_data)) + { + $this->num_rows = count($this->row_data); + /* Usually, row_data could have less elements than result_array, + * but at this point - they should be exactly the same. + */ + $this->result_array = $this->row_data; + } + else + { + $this->num_rows = 0; + } + + return array(); + } + + $this->current_row = $n; + return $this->row_data[$n]; + } + + // -------------------------------------------------------------------- + + /* Single row result. Object version. + * + * @param int row index + * @return mixed object if row found; empty array if not + */ + public function row_object($n = 0) + { + // Make sure $n is not a string + if ( ! is_int($n)) + { + $n = (int) $n; + } + /* Logic here is exactly the same as in row_array, + * except we have to cast row_data[$n] to an object. + * + * If we already have result_object though - we can + * directly return from it. + */ + if (isset($this->result_object[$n])) + { + $this->current_row = $n; + // Set this, if not already done. + if ( ! is_int($this->num_rows)) + { + $this->num_rows = count($this->result_object); + } + + return $this->result_object[$n]; + } + + $row = $this->row_array($n); + // Cast only if the row exists + if (count($row) > 0) + { + $this->current_row = $n; + return (object) $row; + } + + return array(); + } + + // -------------------------------------------------------------------- + + /* Single row result. Custom object version. + * + * @param int row index + * @param string custom class name + * @return mixed custom object if row found; empty array otherwise + */ + public function custom_row_object($n = 0, $class_name) + { + // Make sure $n is not a string + if ( ! is_int($n)) + { + $n = (int) $n; + } + + if (array_key_exists($class_name, $this->custom_result_object)) + { + /* We already have a the whole result set with this class_name, + * return the specified row if it exists, and an empty array if + * it doesn't. + */ + if (isset($this->custom_result_object[$class_name][$n])) + { + $this->current_row = $n; + return $this->custom_result_object[$class_name][$n]; + } + else + { + return array(); + } + } + elseif ( ! class_exists($class_name)) // No such class exists + { + return array(); + } + + $row = $this->row_array($n); + // An array would mean that the row doesn't exist + if (is_array($row)) + { + return $row; + } + + // Convert to the desired class and return + $row_object = new $class_name(); + foreach ($row as $key => $value) + { + $row_object->$key = $value; + } + + $this->current_row = $n; + return $row_object; + } + + // -------------------------------------------------------------------- + + /* First row result. + * + * @param string ('object', 'array' or a custom class name) + * @return mixed whatever was passed to the second parameter + */ + public function first_row($type = 'object') + { + return $this->row(0, $type); + } + + // -------------------------------------------------------------------- + + /* Last row result. + * + * @param string ('object', 'array' or a custom class name) + * @return mixed whatever was passed to the second parameter + */ + public function last_row($type = 'object') + { + $result = &$this->result($type); + if ( ! isset($this->num_rows)) + { + $this->num_rows = count($result); + } + $this->current_row = $this->num_rows - 1; + return $result[$this->current_row]; + } + + // -------------------------------------------------------------------- + + /* Next row result. + * + * @param string ('object', 'array' or a custom class name) + * @return mixed whatever was passed to the second parameter + */ + public function next_row($type = 'object') + { + if (is_array($this->row_data)) + { + $count = count($this->row_data); + if ($this->current_row > $count OR ($this->current_row === 0 && $count === 0)) + { + $n = $count; + } + else + { + $n = $this->current_row + 1; + } + } + else + { + $n = 0; + } + + return $this->row($n, $type); + } + + // -------------------------------------------------------------------- + + /* Previous row result. + * + * @param string ('object', 'array' or a custom class name) + * @return mixed whatever was passed to the second parameter + */ + public function previous_row($type = 'object') + { + $n = ($this->current_row !== 0) ? $this->current_row - 1 : 0; + return $this->row($n, $type); } // -------------------------------------------------------------------- @@ -213,13 +648,54 @@ class CI_DB_oci8_result extends CI_DB_result { * * Moves the internal pointer to the desired offset. We call * this internally before fetching results to make sure the - * result set starts at zero + * result set starts at zero. * - * @return array + * Oracle's PHP extension doesn't have an easy way of doing this + * and the only workaround is to (re)execute the statement or cursor + * in order to go to the first (zero) index of the result set. + * Then, we would need to "dummy" fetch ($n - 1) rows to get to the + * right one. + * + * This is as ridiculous as it sounds and it's the reason why every + * other method that is fetching data tries to use an already "cached" + * result set. Keeping this just in case it becomes needed at + * some point in the future, but it will only work for resetting the + * pointer to zero. + * + * @return bool */ - protected function _data_seek($n = 0) + protected function _data_seek() { - return FALSE; // Not needed + /* The PHP manual says that if OCI_NO_AUTO_COMMIT mode + * is used, and oci_rollback() and/or oci_commit() are + * not subsequently called - this will cause an unnecessary + * rollback to be triggered at the end of the script execution. + * + * Therefore we'll try to avoid using that mode flag + * if we're not currently in the middle of a transaction. + */ + if ($this->commit_mode !== OCI_COMMIT_ON_SUCCESS) + { + $result = @oci_execute($this->stmt_id, $this->commit_mode); + } + else + { + $result = @oci_execute($this->stmt_id); + } + + if ($result && $this->curs_id) + { + if ($this->commit_mode !== OCI_COMMIT_ON_SUCCESS) + { + return @oci_execute($this->curs_id, $this->commit_mode); + } + else + { + return @oci_execute($this->curs_id); + } + } + + return $result; } } diff --git a/system/database/drivers/oci8/oci8_utility.php b/system/database/drivers/oci8/oci8_utility.php index e303fb6cb..efb4bca02 100644 --- a/system/database/drivers/oci8/oci8_utility.php +++ b/system/database/drivers/oci8/oci8_utility.php @@ -37,11 +37,14 @@ class CI_DB_oci8_utility extends CI_DB_utility { /** * List databases * - * @return bool + * Generates a platform-specific query so that we get a list of schemas + * Those are actually usernames in Oracle. + * + * @return string */ public function _list_databases() { - return FALSE; + return 'SELECT username FROM dba_users'; } // -------------------------------------------------------------------- @@ -56,7 +59,7 @@ class CI_DB_oci8_utility extends CI_DB_utility { */ public function _optimize_table($table) { - return FALSE; // Is this supported in Oracle? + return FALSE; // Not supported in Oracle } // -------------------------------------------------------------------- @@ -71,7 +74,7 @@ class CI_DB_oci8_utility extends CI_DB_utility { */ public function _repair_table($table) { - return FALSE; // Is this supported in Oracle? + return FALSE; // Not supported in Oracle } // -------------------------------------------------------------------- diff --git a/system/database/drivers/odbc/odbc_driver.php b/system/database/drivers/odbc/odbc_driver.php index f77851821..bfd53ba59 100644 --- a/system/database/drivers/odbc/odbc_driver.php +++ b/system/database/drivers/odbc/odbc_driver.php @@ -95,19 +95,6 @@ class CI_DB_odbc_driver extends CI_DB { // -------------------------------------------------------------------- /** - * Select the database - * - * @return resource - */ - public function db_select() - { - // Not needed for ODBC - return TRUE; - } - - // -------------------------------------------------------------------- - - /** * Execute the query * * @param string an SQL query @@ -339,43 +326,6 @@ class CI_DB_odbc_driver extends CI_DB { // -------------------------------------------------------------------- /** - * Escape the SQL Identifiers - * - * This function escapes column and table names - * - * @param string - * @return string - */ - public function _escape_identifiers($item) - { - if ($this->_escape_char == '') - { - return $item; - } - - foreach ($this->_reserved_identifiers as $id) - { - if (strpos($item, '.'.$id) !== FALSE) - { - $item = str_replace('.', $this->_escape_char.'.', $item); - - // remove duplicates if the user already included the escape - return preg_replace('/['.$this->_escape_char.']+/', $this->_escape_char, $this->_escape_char.$item); - } - } - - if (strpos($item, '.') !== FALSE) - { - $item = str_replace('.', $this->_escape_char.'.'.$this->_escape_char, $item); - } - - // remove duplicates if the user already included the escape - return preg_replace('/['.$this->_escape_char.']+/', $this->_escape_char, $this->_escape_char.$item.$this->_escape_char); - } - - // -------------------------------------------------------------------- - - /** * From Tables * * This function implicitly groups FROM tables so there is no confusion @@ -397,63 +347,19 @@ class CI_DB_odbc_driver extends CI_DB { // -------------------------------------------------------------------- /** - * Insert statement - * - * Generates a platform-specific insert string from the supplied data - * - * @param string the table name - * @param array the insert keys - * @param array the insert values - * @return string - */ - protected function _insert($table, $keys, $values) - { - return 'INSERT INTO '.$table.' ('.implode(', ', $keys).') VALUES ('.implode(', ', $values).')'; - } - - // -------------------------------------------------------------------- - - /** - * Update statement - * - * Generates a platform-specific update string from the supplied data - * - * @param string the table name - * @param array the update data - * @param array the where clause - * @param array the orderby clause - * @param array the limit clause - * @return string - */ - protected function _update($table, $values, $where, $orderby = array(), $limit = FALSE) - { - foreach ($values as $key => $val) - { - $valstr[] = $key.' = '.$val; - } - - return 'UPDATE '.$table.' SET '.implode(', ', $valstr) - .(($where != '' && count($where) > 0) ? ' WHERE '.implode(' ', $where) : '') - .(count($orderby) > 0 ? ' ORDER BY '.implode(', ', $orderby) : '') - .( ! $limit ? '' : ' LIMIT '.$limit); - } - - - // -------------------------------------------------------------------- - - /** * Truncate statement * * Generates a platform-specific truncate string from the supplied data - * If the database does not support the truncate() command - * This function maps to "DELETE FROM table" + * + * If the database does not support the truncate() command, + * then this method maps to 'DELETE FROM table' * * @param string the table name * @return string */ protected function _truncate($table) { - return $this->_delete($table); + return 'DELETE FROM '.$table; } // -------------------------------------------------------------------- diff --git a/system/database/drivers/odbc/odbc_forge.php b/system/database/drivers/odbc/odbc_forge.php index 26ff9a0fb..5b76b1cea 100644 --- a/system/database/drivers/odbc/odbc_forge.php +++ b/system/database/drivers/odbc/odbc_forge.php @@ -83,7 +83,7 @@ class CI_DB_odbc_forge extends CI_DB_forge { $sql .= 'IF NOT EXISTS '; } - $sql .= $this->db->_escape_identifiers($table).' ('; + $sql .= $this->db->escape_identifiers($table).' ('; $current_field_count = 0; foreach ($fields as $field => $attributes) diff --git a/system/database/drivers/pdo/pdo_driver.php b/system/database/drivers/pdo/pdo_driver.php index 19338e30f..919bb9c00 100644 --- a/system/database/drivers/pdo/pdo_driver.php +++ b/system/database/drivers/pdo/pdo_driver.php @@ -46,8 +46,8 @@ class CI_DB_pdo_driver extends CI_DB { protected $_escape_char = ''; // clause and character used for LIKE escape sequences - protected $_like_escape_str; - protected $_like_escape_chr; + protected $_like_escape_str = " ESCAPE '%s' "; + protected $_like_escape_chr = '!'; /** * The syntax to count rows is slightly different across different @@ -81,18 +81,17 @@ class CI_DB_pdo_driver extends CI_DB { // this one depends on the driver being used if ($this->pdodriver == 'mysql') { + $this->_escape_char = '`'; $this->_like_escape_str = ''; $this->_like_escape_chr = ''; } elseif ($this->pdodriver == 'odbc') { $this->_like_escape_str = " {escape '%s'} "; - $this->_like_escape_chr = '!'; } - else + elseif ( ! in_array($this->pdodriver, array('sqlsrv', 'mssql', 'dblib', 'sybase'))) { - $this->_like_escape_str = " ESCAPE '%s' "; - $this->_like_escape_chr = '!'; + $this->_escape_char = '"'; } $this->trans_enabled = FALSE; @@ -247,19 +246,6 @@ class CI_DB_pdo_driver extends CI_DB { // -------------------------------------------------------------------- /** - * Select the database - * - * @return resource - */ - public function db_select() - { - // Not needed for PDO - return TRUE; - } - - // -------------------------------------------------------------------- - - /** * Database version number * * @return string @@ -281,8 +267,6 @@ class CI_DB_pdo_driver extends CI_DB { */ protected function _execute($sql) { - $sql = $this->_prep_query($sql); - $result_id = $this->conn_id->query($sql); if (is_object($result_id)) @@ -300,32 +284,6 @@ class CI_DB_pdo_driver extends CI_DB { // -------------------------------------------------------------------- /** - * Prep the query - * - * If needed, each database adapter can prep the query string - * - * @param string an SQL query - * @return string - */ - protected function _prep_query($sql) - { - if ($this->pdodriver === 'pgsql') - { - // Change the backtick(s) for Postgre - $sql = str_replace('`', '"', $sql); - } - elseif ($this->pdodriver === 'sqlite') - { - // Change the backtick(s) for SQLite - $sql = str_replace('`', '', $sql); - } - - return $sql; - } - - // -------------------------------------------------------------------- - - /** * Begin Transaction * * @return bool @@ -484,7 +442,7 @@ class CI_DB_pdo_driver extends CI_DB { * @param string * @return string */ - function count_all($table = '') + public function count_all($table = '') { if ($table == '') { @@ -529,7 +487,7 @@ class CI_DB_pdo_driver extends CI_DB { } else { - $sql = "SHOW TABLES FROM `".$this->database."`"; + $sql = 'SHOW TABLES FROM '.$this->escape_identifiers($this->database); } if ($prefix_limit !== FALSE AND $this->dbprefix != '') @@ -552,7 +510,7 @@ class CI_DB_pdo_driver extends CI_DB { */ protected function _list_columns($table = '') { - return 'SHOW COLUMNS FROM '.$this->_from_tables($table); + return 'SHOW COLUMNS FROM '.$this->escape_identifiers($table); } // -------------------------------------------------------------------- @@ -570,20 +528,20 @@ class CI_DB_pdo_driver extends CI_DB { if ($this->pdodriver == 'mysql' or $this->pdodriver == 'pgsql') { // Analog function for mysql and postgre - return 'SELECT * FROM '.$this->_from_tables($table).' LIMIT 1'; + return 'SELECT * FROM '.$this->escape_identifiers($table).' LIMIT 1'; } elseif ($this->pdodriver == 'oci') { // Analog function for oci - return 'SELECT * FROM '.$this->_from_tables($table).' WHERE ROWNUM <= 1'; + return 'SELECT * FROM '.$this->escape_identifiers($table).' WHERE ROWNUM <= 1'; } elseif ($this->pdodriver == 'sqlite') { // Analog function for sqlite - return 'PRAGMA table_info('.$this->_from_tables($table).')'; + return 'PRAGMA table_info('.$this->escape_identifiers($table).')'; } - return 'SELECT TOP 1 FROM '.$this->_from_tables($table); + return 'SELECT TOP 1 FROM '.$this->escape_identifiers($table); } // -------------------------------------------------------------------- @@ -618,48 +576,6 @@ class CI_DB_pdo_driver extends CI_DB { // -------------------------------------------------------------------- /** - * Escape the SQL Identifiers - * - * This function escapes column and table names - * - * @param string - * @return string - */ - public function _escape_identifiers($item) - { - if ($this->_escape_char == '') - { - return $item; - } - - foreach ($this->_reserved_identifiers as $id) - { - if (strpos($item, '.'.$id) !== FALSE) - { - $str = $this->_escape_char. str_replace('.', $this->_escape_char.'.', $item); - - // remove duplicates if the user already included the escape - return preg_replace('/['.$this->_escape_char.']+/', $this->_escape_char, $str); - } - } - - if (strpos($item, '.') !== FALSE) - { - $str = $this->_escape_char.str_replace('.', $this->_escape_char.'.'.$this->_escape_char, $item); - $str .= $this->_escape_char; - } - else - { - $str = $this->_escape_char.$item.$this->_escape_char; - } - - // remove duplicates if the user already included the escape - return preg_replace('/['.$this->_escape_char.']+/', $this->_escape_char, $str); - } - - // -------------------------------------------------------------------- - - /** * From Tables * * This function implicitly groups FROM tables so there is no confusion @@ -675,72 +591,7 @@ class CI_DB_pdo_driver extends CI_DB { $tables = array($tables); } - return (count($tables) == 1) ? '`'.$tables[0].'`' : '('.implode(', ', $tables).')'; - } - - // -------------------------------------------------------------------- - - /** - * Insert statement - * - * Generates a platform-specific insert string from the supplied data - * - * @param string the table name - * @param array the insert keys - * @param array the insert values - * @return string - */ - protected function _insert($table, $keys, $values) - { - return 'INSERT INTO '.$this->_from_tables($table).' ('.implode(', ', $keys).') VALUES ('.implode(', ', $values).')'; - } - - // -------------------------------------------------------------------- - - /** - * Insert_batch statement - * - * Generates a platform-specific insert string from the supplied data - * - * @param string the table name - * @param array the insert keys - * @param array the insert values - * @return string - */ - protected function _insert_batch($table, $keys, $values) - { - return 'INSERT INTO '.$this->_from_tables($table).' ('.implode(', ', $keys).') VALUES '.implode(', ', $values); - } - - // -------------------------------------------------------------------- - - /** - * Update statement - * - * Generates a platform-specific update string from the supplied data - * - * @param string the table name - * @param array the update data - * @param array the where clause - * @param array the orderby clause - * @param array the limit clause - * @return string - */ - protected function _update($table, $values, $where, $orderby = array(), $limit = FALSE) - { - foreach ($values as $key => $val) - { - $valstr[] = $key." = ".$val; - } - - $limit = ( ! $limit) ? '' : ' LIMIT '.$limit; - $orderby = (count($orderby) >= 1) ? ' ORDER BY '.implode(', ', $orderby) : ''; - - $sql = 'UPDATE '.$this->_from_tables($table).' SET '.implode(', ', $valstr); - $sql .= ($where != '' && count($where) >= 1) ? ' WHERE '.implode(' ', $where) : ''; - $sql .= $orderby.$limit; - - return $sql; + return (count($tables) === 1) ? $tables[0] : '('.implode(', ', $tables).')'; } // -------------------------------------------------------------------- @@ -773,7 +624,7 @@ class CI_DB_pdo_driver extends CI_DB { } } - $sql = 'UPDATE '.$this->_from_tables($table).' SET '; + $sql = 'UPDATE '.$table.' SET '; $cases = ''; foreach ($final as $k => $v) @@ -800,15 +651,16 @@ class CI_DB_pdo_driver extends CI_DB { * Truncate statement * * Generates a platform-specific truncate string from the supplied data - * If the database does not support the truncate() command - * This function maps to "DELETE FROM table" + * + * If the database does not support the truncate() command, + * then this method maps to 'DELETE FROM table' * * @param string the table name * @return string */ protected function _truncate($table) { - return $this->_delete($table); + return 'DELETE FROM '.$table; } // -------------------------------------------------------------------- @@ -842,7 +694,7 @@ class CI_DB_pdo_driver extends CI_DB { $limit = ( ! $limit) ? '' : ' LIMIT '.$limit; - return 'DELETE FROM '.$this->_from_tables($table).$conditions.$limit; + return 'DELETE FROM '.$table.$conditions.$limit; } // -------------------------------------------------------------------- diff --git a/system/database/drivers/pdo/pdo_forge.php b/system/database/drivers/pdo/pdo_forge.php index 6bff3542f..9635e4c9a 100644 --- a/system/database/drivers/pdo/pdo_forge.php +++ b/system/database/drivers/pdo/pdo_forge.php @@ -91,10 +91,10 @@ class CI_DB_pdo_forge extends CI_DB_forge { $sql .= 'IF NOT EXISTS '; } - $sql .= '`'.$this->db->_escape_identifiers($table).'` ('; + $sql .= $this->db->escape_identifiers($table).' ('; $current_field_count = 0; - foreach ($fields as $field=>$attributes) + foreach ($fields as $field => $attributes) { // Numeric field names aren't allowed in databases, so if the key is // numeric, we know it was assigned by PHP and the developer manually diff --git a/system/database/drivers/postgre/postgre_driver.php b/system/database/drivers/postgre/postgre_driver.php index 3e2d05ce8..1e96452b4 100644 --- a/system/database/drivers/postgre/postgre_driver.php +++ b/system/database/drivers/postgre/postgre_driver.php @@ -80,16 +80,16 @@ class CI_DB_postgre_driver extends CI_DB { $this->port = ''; } - $this->hostname === '' OR $this->dsn = 'host='.$this->hostname; + $this->hostname === '' OR $this->dsn = 'host='.$this->hostname.' '; if ( ! empty($this->port) && ctype_digit($this->port)) { - $this->dsn .= 'host='.$this->port.' '; + $this->dsn .= 'port='.$this->port.' '; } if ($this->username !== '') { - $this->dsn .= 'username='.$this->username.' '; + $this->dsn .= 'user='.$this->username.' '; /* An empty password is valid! * @@ -162,19 +162,6 @@ class CI_DB_postgre_driver extends CI_DB { // -------------------------------------------------------------------- /** - * Select the database - * - * @return resource - */ - public function db_select() - { - // Not needed for Postgre so we'll return TRUE - return TRUE; - } - - // -------------------------------------------------------------------- - - /** * Set client character set * * @param string @@ -470,47 +457,6 @@ class CI_DB_postgre_driver extends CI_DB { // -------------------------------------------------------------------- /** - * Escape the SQL Identifiers - * - * This function escapes column and table names - * - * @param string - * @return string - */ - public function _escape_identifiers($item) - { - if ($this->_escape_char == '') - { - return $item; - } - - foreach ($this->_reserved_identifiers as $id) - { - if (strpos($item, '.'.$id) !== FALSE) - { - $str = $this->_escape_char. str_replace('.', $this->_escape_char.'.', $item); - - // remove duplicates if the user already included the escape - return preg_replace('/['.$this->_escape_char.']+/', $this->_escape_char, $str); - } - } - - if (strpos($item, '.') !== FALSE) - { - $str = $this->_escape_char.str_replace('.', $this->_escape_char.'.'.$this->_escape_char, $item).$this->_escape_char; - } - else - { - $str = $this->_escape_char.$item.$this->_escape_char; - } - - // remove duplicates if the user already included the escape - return preg_replace('/['.$this->_escape_char.']+/', $this->_escape_char, $str); - } - - // -------------------------------------------------------------------- - - /** * From Tables * * This function implicitly groups FROM tables so there is no confusion @@ -532,40 +478,6 @@ class CI_DB_postgre_driver extends CI_DB { // -------------------------------------------------------------------- /** - * Insert statement - * - * Generates a platform-specific insert string from the supplied data - * - * @param string the table name - * @param array the insert keys - * @param array the insert values - * @return string - */ - protected function _insert($table, $keys, $values) - { - return "INSERT INTO ".$table." (".implode(', ', $keys).") VALUES (".implode(', ', $values).")"; - } - - // -------------------------------------------------------------------- - - /** - * Insert_batch statement - * - * Generates a platform-specific insert string from the supplied data - * - * @param string the table name - * @param array the insert keys - * @param array the insert values - * @return string - */ - protected function _insert_batch($table, $keys, $values) - { - return "INSERT INTO ".$table." (".implode(', ', $keys).") VALUES ".implode(', ', $values); - } - - // -------------------------------------------------------------------- - - /** * Update statement * * Generates a platform-specific update string from the supplied data @@ -594,23 +506,6 @@ class CI_DB_postgre_driver extends CI_DB { // -------------------------------------------------------------------- /** - * Truncate statement - * - * Generates a platform-specific truncate string from the supplied data - * If the database does not support the truncate() command - * This function maps to "DELETE FROM table" - * - * @param string the table name - * @return string - */ - protected function _truncate($table) - { - return "TRUNCATE ".$table; - } - - // -------------------------------------------------------------------- - - /** * Delete statement * * Generates a platform-specific delete string from the supplied data diff --git a/system/database/drivers/postgre/postgre_forge.php b/system/database/drivers/postgre/postgre_forge.php index a72449820..f7d59284a 100644 --- a/system/database/drivers/postgre/postgre_forge.php +++ b/system/database/drivers/postgre/postgre_forge.php @@ -193,8 +193,7 @@ class CI_DB_postgre_forge extends CI_DB_forge { } } - $sql .= $this->db->_escape_identifiers($table)." ("; - $sql .= $this->_process_fields($fields, $primary_keys); + $sql .= $this->db->escape_identifiers($table).' ('.$this->_process_fields($fields, $primary_keys); if (count($primary_keys) > 0) { @@ -237,11 +236,12 @@ class CI_DB_postgre_forge extends CI_DB_forge { /** * Drop Table * + * @param string table name * @return string */ public function _drop_table($table) { - return "DROP TABLE IF EXISTS ".$this->db->_escape_identifiers($table)." CASCADE"; + return 'DROP TABLE IF EXISTS '.$this->db->escape_identifiers($table).' CASCADE'; } // -------------------------------------------------------------------- diff --git a/system/database/drivers/postgre/postgre_result.php b/system/database/drivers/postgre/postgre_result.php index 8b22564b3..394b8b6fd 100644 --- a/system/database/drivers/postgre/postgre_result.php +++ b/system/database/drivers/postgre/postgre_result.php @@ -70,7 +70,7 @@ class CI_DB_postgre_result extends CI_DB_result { public function list_fields() { $field_names = array(); - for ($i = 0; $i < $this->num_fields(); $i++) + for ($i = 0, $c = $this->num_fields(); $i < $c; $i++) { $field_names[] = pg_field_name($this->result_id, $i); } @@ -90,16 +90,14 @@ class CI_DB_postgre_result extends CI_DB_result { public function field_data() { $retval = array(); - for ($i = 0; $i < $this->num_fields(); $i++) + for ($i = 0, $c = $this->num_fields(); $i < $c; $i++) { - $F = new stdClass(); - $F->name = pg_field_name($this->result_id, $i); - $F->type = pg_field_type($this->result_id, $i); - $F->max_length = pg_field_size($this->result_id, $i); - $F->primary_key = 0; - $F->default = ''; - - $retval[] = $F; + $retval[$i] = new stdClass(); + $retval[$i]->name = pg_field_name($this->result_id, $i); + $retval[$i]->type = pg_field_type($this->result_id, $i); + $retval[$i]->max_length = pg_field_size($this->result_id, $i); + $retval[$i]->primary_key = 0; + $retval[$i]->default = ''; } return $retval; diff --git a/system/database/drivers/sqlite/sqlite_driver.php b/system/database/drivers/sqlite/sqlite_driver.php index 102c79bb3..3a986d0a8 100644 --- a/system/database/drivers/sqlite/sqlite_driver.php +++ b/system/database/drivers/sqlite/sqlite_driver.php @@ -106,18 +106,6 @@ class CI_DB_sqlite_driver extends CI_DB { // -------------------------------------------------------------------- /** - * Select the database - * - * @return resource - */ - public function db_select() - { - return TRUE; - } - - // -------------------------------------------------------------------- - - /** * Database version number * * @return string @@ -378,47 +366,6 @@ class CI_DB_sqlite_driver extends CI_DB { // -------------------------------------------------------------------- /** - * Escape the SQL Identifiers - * - * This function escapes column and table names - * - * @param string - * @return string - */ - public function _escape_identifiers($item) - { - if ($this->_escape_char == '') - { - return $item; - } - - foreach ($this->_reserved_identifiers as $id) - { - if (strpos($item, '.'.$id) !== FALSE) - { - $str = $this->_escape_char. str_replace('.', $this->_escape_char.'.', $item); - - // remove duplicates if the user already included the escape - return preg_replace('/['.$this->_escape_char.']+/', $this->_escape_char, $str); - } - } - - if (strpos($item, '.') !== FALSE) - { - $str = $this->_escape_char.str_replace('.', $this->_escape_char.'.'.$this->_escape_char, $item).$this->_escape_char; - } - else - { - $str = $this->_escape_char.$item.$this->_escape_char; - } - - // remove duplicates if the user already included the escape - return preg_replace('/['.$this->_escape_char.']+/', $this->_escape_char, $str); - } - - // -------------------------------------------------------------------- - - /** * From Tables * * This function implicitly groups FROM tables so there is no confusion @@ -440,70 +387,36 @@ class CI_DB_sqlite_driver extends CI_DB { // -------------------------------------------------------------------- /** - * Insert statement + * Replace statement * - * Generates a platform-specific insert string from the supplied data + * Generates a platform-specific replace string from the supplied data * * @param string the table name * @param array the insert keys * @param array the insert values * @return string */ - protected function _insert($table, $keys, $values) - { - return "INSERT INTO ".$table." (".implode(', ', $keys).") VALUES (".implode(', ', $values).")"; - } - - // -------------------------------------------------------------------- - - /** - * Update statement - * - * Generates a platform-specific update string from the supplied data - * - * @param string the table name - * @param array the update data - * @param array the where clause - * @param array the orderby clause - * @param array the limit clause - * @return string - */ - protected function _update($table, $values, $where, $orderby = array(), $limit = FALSE) + protected function _replace($table, $keys, $values) { - foreach ($values as $key => $val) - { - $valstr[] = $key." = ".$val; - } - - $limit = ( ! $limit) ? '' : ' LIMIT '.$limit; - - $orderby = (count($orderby) >= 1)?' ORDER BY '.implode(", ", $orderby):''; - - $sql = "UPDATE ".$table." SET ".implode(', ', $valstr); - - $sql .= ($where != '' AND count($where) >=1) ? " WHERE ".implode(" ", $where) : ''; - - $sql .= $orderby.$limit; - - return $sql; + return 'INSERT OR '.parent::_replace($table, $keys, $values); } - // -------------------------------------------------------------------- /** * Truncate statement * * Generates a platform-specific truncate string from the supplied data - * If the database does not support the truncate() command - * This function maps to "DELETE FROM table" + * + * If the database does not support the truncate() command, + * then this function maps to 'DELETE FROM table' * * @param string the table name * @return string */ protected function _truncate($table) { - return $this->_delete($table); + return 'DELETE FROM '.$table; } // -------------------------------------------------------------------- diff --git a/system/database/drivers/sqlite/sqlite_forge.php b/system/database/drivers/sqlite/sqlite_forge.php index 068a556ed..a62e8d9ae 100644 --- a/system/database/drivers/sqlite/sqlite_forge.php +++ b/system/database/drivers/sqlite/sqlite_forge.php @@ -90,10 +90,10 @@ class CI_DB_sqlite_forge extends CI_DB_forge { $sql .= 'IF NOT EXISTS '; } - $sql .= $this->db->_escape_identifiers($table)."("; + $sql .= $this->db->escape_identifiers($table).' ('; $current_field_count = 0; - foreach ($fields as $field=>$attributes) + foreach ($fields as $field => $attributes) { // Numeric field names aren't allowed in databases, so if the key is // numeric, we know it was assigned by PHP and the developer manually diff --git a/system/database/drivers/sqlite/sqlite_result.php b/system/database/drivers/sqlite/sqlite_result.php index b002aeff1..4af80abf7 100644 --- a/system/database/drivers/sqlite/sqlite_result.php +++ b/system/database/drivers/sqlite/sqlite_result.php @@ -70,9 +70,9 @@ class CI_DB_sqlite_result extends CI_DB_result { public function list_fields() { $field_names = array(); - for ($i = 0; $i < $this->num_fields(); $i++) + for ($i = 0, $c = $this->num_fields(); $i < $c; $i++) { - $field_names[] = sqlite_field_name($this->result_id, $i); + $field_names[$i] = sqlite_field_name($this->result_id, $i); } return $field_names; @@ -90,16 +90,14 @@ class CI_DB_sqlite_result extends CI_DB_result { public function field_data() { $retval = array(); - for ($i = 0; $i < $this->num_fields(); $i++) + for ($i = 0, $c = $this->num_fields(); $i < $c; $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; + $retval[$i] = new stdClass(); + $retval[$i]->name = sqlite_field_name($this->result_id, $i); + $retval[$i]->type = 'varchar'; + $retval[$i]->max_length = 0; + $retval[$i]->primary_key = 0; + $retval[$i]->default = ''; } return $retval; @@ -108,18 +106,6 @@ class CI_DB_sqlite_result extends CI_DB_result { // -------------------------------------------------------------------- /** - * Free the result - * - * @return void - */ - public function free_result() - { - // Not implemented in SQLite - } - - // -------------------------------------------------------------------- - - /** * Data Seek * * Moves the internal pointer to the desired offset. We call @@ -162,17 +148,9 @@ class CI_DB_sqlite_result extends CI_DB_result { { return sqlite_fetch_object($this->result_id); } - else - { - $arr = sqlite_fetch_array($this->result_id, SQLITE_ASSOC); - if (is_array($arr)) - { - $obj = (object) $arr; - return $obj; - } else { - return NULL; - } - } + + $arr = sqlite_fetch_array($this->result_id, SQLITE_ASSOC); + return is_array($arr) ? (object) $arr : FALSE; } } diff --git a/system/database/drivers/sqlite3/index.html b/system/database/drivers/sqlite3/index.html new file mode 100644 index 000000000..c942a79ce --- /dev/null +++ b/system/database/drivers/sqlite3/index.html @@ -0,0 +1,10 @@ +<html> +<head> + <title>403 Forbidden</title> +</head> +<body> + +<p>Directory access is forbidden.</p> + +</body> +</html>
\ No newline at end of file diff --git a/system/database/drivers/sqlite3/sqlite3_driver.php b/system/database/drivers/sqlite3/sqlite3_driver.php new file mode 100644 index 000000000..12354e1bc --- /dev/null +++ b/system/database/drivers/sqlite3/sqlite3_driver.php @@ -0,0 +1,459 @@ +<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed'); +/** + * CodeIgniter + * + * An open source application development framework for PHP 5.2.4 or newer + * + * NOTICE OF LICENSE + * + * Licensed under the Open Software License version 3.0 + * + * This source file is subject to the Open Software License (OSL 3.0) that is + * bundled with this package in the files license.txt / license.rst. It is + * also available through the world wide web at this URL: + * http://opensource.org/licenses/OSL-3.0 + * If you did not receive a copy of the license and are unable to obtain it + * through the world wide web, please send an email to + * licensing@ellislab.com so we can send you a copy immediately. + * + * @package CodeIgniter + * @author EllisLab Dev Team + * @copyright Copyright (c) 2008 - 2012, EllisLab, Inc. (http://ellislab.com/) + * @license http://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0) + * @link http://codeigniter.com + * @since Version 1.0 + * @filesource + */ + +/** + * SQLite3 Database Adapter Class + * + * Note: _DB is an extender class that the app controller + * creates dynamically based on whether the active record + * class is being used or not. + * + * @package CodeIgniter + * @subpackage Drivers + * @category Database + * @author Andrey Andreev + * @link http://codeigniter.com/user_guide/database/ + * @since Version 3.0 + */ +class CI_DB_sqlite3_driver extends CI_DB { + + public $dbdriver = 'sqlite3'; + + // The character used for escaping + protected $_escape_char = '"'; + + // clause and character used for LIKE escape sequences + protected $_like_escape_str = ' ESCAPE \'%s\' '; + protected $_like_escape_chr = '!'; + + /** + * The syntax to count rows is slightly different across different + * database engines, so this string appears in each driver and is + * used for the count_all() and count_all_results() functions. + */ + protected $_count_string = 'SELECT COUNT(*) AS '; + protected $_random_keyword = ' RANDOM()'; + + /** + * Non-persistent database connection + * + * @return object type SQLite3 + */ + public function db_connect() + { + try + { + return ( ! $this->password) + ? new SQLite3($this->database) + : new SQLite3($this->database, SQLITE3_OPEN_READWRITE | SQLITE3_OPEN_CREATE, $this->password); + } + catch (Exception $e) + { + return FALSE; + } + } + + // -------------------------------------------------------------------- + + /** + * Persistent database connection + * + * @return object type SQLite3 + */ + public function db_pconnect() + { + log_message('debug', 'SQLite3 doesn\'t support persistent connections'); + return $this->db_pconnect(); + } + + // -------------------------------------------------------------------- + + /** + * Database version number + * + * @return string + */ + public function version() + { + if (isset($this->data_cache['version'])) + { + return $this->data_cache['version']; + } + + $version = $this->conn_id->version(); + return $this->data_cache['version'] = $version['versionString']; + } + + // -------------------------------------------------------------------- + + /** + * Execute the query + * + * @param string an SQL query + * @return mixed SQLite3Result object or bool + */ + protected function _execute($sql) + { + // TODO: Implement use of SQLite3::querySingle(), if needed + + return $this->is_write_type($sql) + ? $this->conn_id->exec($sql) + : $this->conn_id->query($sql); + } + + // -------------------------------------------------------------------- + + /** + * Begin Transaction + * + * @return bool + */ + public function trans_begin($test_mode = FALSE) + { + // When transactions are nested we only begin/commit/rollback the outermost ones + if ( ! $this->trans_enabled OR $this->_trans_depth > 0) + { + return TRUE; + } + + // Reset the transaction failure flag. + // If the $test_mode flag is set to TRUE transactions will be rolled back + // even if the queries produce a successful result. + $this->_trans_failure = ($test_mode === TRUE); + + return $this->conn_id->exec('BEGIN TRANSACTION'); + } + + // -------------------------------------------------------------------- + + /** + * Commit Transaction + * + * @return bool + */ + public function trans_commit() + { + // When transactions are nested we only begin/commit/rollback the outermost ones + if ( ! $this->trans_enabled OR $this->_trans_depth > 0) + { + return TRUE; + } + + return $this->conn_id->exec('END TRANSACTION'); + } + + // -------------------------------------------------------------------- + + /** + * Rollback Transaction + * + * @return bool + */ + public function trans_rollback() + { + // When transactions are nested we only begin/commit/rollback the outermost ones + if ( ! $this->trans_enabled OR $this->_trans_depth > 0) + { + return TRUE; + } + + return $this->conn_id->exec('ROLLBACK'); + } + + // -------------------------------------------------------------------- + + /** + * Escape String + * + * @param string + * @param bool whether or not the string will be used in a LIKE condition + * @return string + */ + public function escape_str($str, $like = FALSE) + { + if (is_array($str)) + { + foreach ($str as $key => $val) + { + $str[$key] = $this->escape_str($val, $like); + } + + return $str; + } + + $str = $this->conn_id->escapeString(remove_invisible_characters($str)); + + // escape LIKE condition wildcards + if ($like === TRUE) + { + return str_replace(array($this->_like_escape_chr, '%', '_'), + array($this->_like_escape_chr.$this->_like_escape_chr, $this->_like_escape_chr.'%', $this->_like_escape_chr.'_'), + $str); + } + + return $str; + } + + // -------------------------------------------------------------------- + + /** + * Affected Rows + * + * @return int + */ + public function affected_rows() + { + return $this->conn_id->changes(); + } + + // -------------------------------------------------------------------- + + /** + * Insert ID + * + * @return int + */ + public function insert_id() + { + return $this->conn_id->lastInsertRowID(); + } + + // -------------------------------------------------------------------- + + /** + * "Count All" query + * + * Generates a platform-specific query string that counts all records in + * the specified database + * + * @param string + * @return int + */ + public function count_all($table = '') + { + if ($table == '') + { + return 0; + } + + $result = $this->conn_id->querySingle($this->_count_string.$this->protect_identifiers('numrows') + .' FROM '.$this->protect_identifiers($table, TRUE, NULL, FALSE)); + + return empty($result) ? 0 : (int) $result; + } + + // -------------------------------------------------------------------- + + /** + * Show table query + * + * Generates a platform-specific query string so that the table names can be fetched + * + * @param bool + * @return string + */ + protected function _list_tables($prefix_limit = FALSE) + { + return 'SELECT "NAME" FROM "SQLITE_MASTER" WHERE "TYPE" = \'table\'' + .(($prefix_limit !== FALSE && $this->dbprefix != '') + ? ' AND "NAME" LIKE \''.$this->escape_like_str($this->dbprefix).'%\' '.sprintf($this->_like_escape_str, $this->_like_escape_chr) + : ''); + } + + // -------------------------------------------------------------------- + + /** + * Show column query + * + * Generates a platform-specific query string so that the column names can be fetched + * + * @param string the table name + * @return string + */ + protected function _list_columns($table = '') + { + // Not supported + return FALSE; + } + + // -------------------------------------------------------------------- + + /** + * Field data query + * + * Generates a platform-specific query so that the column data can be retrieved + * + * @param string the table name + * @return string + */ + protected function _field_data($table) + { + return 'SELECT * FROM '.$table.' LIMIT 0,1'; + } + + // -------------------------------------------------------------------- + + /** + * The error message string + * + * @return string + */ + protected function _error_message() + { + return $this->conn_id->lastErrorMsg(); + } + + // -------------------------------------------------------------------- + + /** + * The error message number + * + * @return int + */ + protected function _error_number() + { + return $this->conn_id->lastErrorCode(); + } + + // -------------------------------------------------------------------- + + /** + * From Tables + * + * This function implicitly groups FROM tables so there is no confusion + * about operator precedence in harmony with SQL standards + * + * @param string + * @return string + */ + protected function _from_tables($tables) + { + if ( ! is_array($tables)) + { + $tables = array($tables); + } + + return '('.implode(', ', $tables).')'; + } + + // -------------------------------------------------------------------- + + /** + * Replace statement + * + * Generates a platform-specific replace string from the supplied data + * + * @param string the table name + * @param array the insert keys + * @param array the insert values + * @return string + */ + protected function _replace($table, $keys, $values) + { + return 'INSERT OR '.parent::_replace($table, $keys, $values); + } + + // -------------------------------------------------------------------- + + /** + * Truncate statement + * + * Generates a platform-specific truncate string from the supplied data + * + * If the database does not support the truncate() command, then, + * then this method maps to 'DELETE FROM table' + * + * @param string the table name + * @return string + */ + protected function _truncate($table) + { + return 'DELETE FROM '.$table; + } + + // -------------------------------------------------------------------- + + /** + * Delete statement + * + * Generates a platform-specific delete string from the supplied data + * + * @param string the table name + * @param array the where clause + * @param string the limit clause + * @return string + */ + protected function _delete($table, $where = array(), $like = array(), $limit = FALSE) + { + $conditions = ''; + if (count($where) > 0 OR count($like) > 0) + { + $conditions .= "\nWHERE ".implode("\n", $this->ar_where); + + if (count($where) > 0 && count($like) > 0) + { + $conditions .= ' AND '; + } + $conditions .= implode("\n", $like); + } + + return 'DELETE FROM '.$table.$conditions.( ! $limit ? '' : ' LIMIT '.$limit); + } + + // -------------------------------------------------------------------- + + /** + * Limit string + * + * Generates a platform-specific LIMIT clause + * + * @param string the sql query string + * @param int the number of rows to limit the query to + * @param int the offset value + * @return string + */ + protected function _limit($sql, $limit, $offset) + { + return $sql.' LIMIT '.($offset ? $offset.',' : '').$limit; + } + + // -------------------------------------------------------------------- + + /** + * Close DB Connection + * + * @return void + */ + protected function _close() + { + $this->conn_id->close(); + } + +} + +/* End of file sqlite3_driver.php */ +/* Location: ./system/database/drivers/sqlite3/sqlite3_driver.php */
\ No newline at end of file diff --git a/system/database/drivers/sqlite3/sqlite3_forge.php b/system/database/drivers/sqlite3/sqlite3_forge.php new file mode 100644 index 000000000..3a2060c3b --- /dev/null +++ b/system/database/drivers/sqlite3/sqlite3_forge.php @@ -0,0 +1,223 @@ +<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed'); +/** + * CodeIgniter + * + * An open source application development framework for PHP 5.1.6 or newer + * + * NOTICE OF LICENSE + * + * Licensed under the Open Software License version 3.0 + * + * This source file is subject to the Open Software License (OSL 3.0) that is + * bundled with this package in the files license.txt / license.rst. It is + * also available through the world wide web at this URL: + * http://opensource.org/licenses/OSL-3.0 + * If you did not receive a copy of the license and are unable to obtain it + * through the world wide web, please send an email to + * licensing@ellislab.com so we can send you a copy immediately. + * + * @package CodeIgniter + * @author EllisLab Dev Team + * @copyright Copyright (c) 2008 - 2012, EllisLab, Inc. (http://ellislab.com/) + * @license http://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0) + * @link http://codeigniter.com + * @since Version 1.0 + * @filesource + */ + +/** + * SQLite3 Forge Class + * + * @category Database + * @author Andrey Andreev + * @link http://codeigniter.com/user_guide/database/ + */ +class CI_DB_sqlite3_forge extends CI_DB_forge { + + /** + * Create database + * + * @param string the database name + * @return bool + */ + public function _create_database() + { + // In SQLite, a database is created when you connect to the database. + // We'll return TRUE so that an error isn't generated + return TRUE; + } + + // -------------------------------------------------------------------- + + /** + * Drop database + * + * @param string the database name + * @return bool + */ + public function _drop_database($name) + { + // In SQLite, a database is dropped when we delete a file + if (@file_exists($this->db->database)) + { + // We need to close the pseudo-connection first + $this->db->close(); + if ( ! @unlink($this->db->database)) + { + return $this->db->db_debug ? $this->db->display_error('db_unable_to_drop') : FALSE; + } + + return TRUE; + } + + return $this->db->db_debug ? $this->db->display_error('db_unable_to_drop') : FALSE; + } + + // -------------------------------------------------------------------- + + /** + * Create Table + * + * @param string the table name + * @param array the fields + * @param mixed primary key(s) + * @param mixed key(s) + * @param bool should 'IF NOT EXISTS' be added to the SQL + * @return bool + */ + public function _create_table($table, $fields, $primary_keys, $keys, $if_not_exists) + { + $sql = 'CREATE TABLE '; + + // IF NOT EXISTS added to SQLite in 3.3.0 + if ($if_not_exists === TRUE && version_compare($this->db->version(), '3.3.0', '>=') === TRUE) + { + $sql .= 'IF NOT EXISTS '; + } + + $sql .= $this->db->escape_identifiers($table).' ('; + $current_field_count = 0; + + foreach ($fields as $field => $attributes) + { + // Numeric field names aren't allowed in databases, so if the key is + // numeric, we know it was assigned by PHP and the developer manually + // entered the field information, so we'll simply add it to the list + if (is_numeric($field)) + { + $sql .= "\n\t".$attributes; + } + else + { + $attributes = array_change_key_case($attributes, CASE_UPPER); + + $sql .= "\n\t".$this->db->protect_identifiers($field) + .' '.$attributes['TYPE'] + .( ! empty($attributes['CONSTRAINT']) ? '('.$attributes['CONSTRAINT'].')' : '') + .(( ! empty($attributes['UNSIGNED']) && $attributes['UNSIGNED'] === TRUE) ? ' UNSIGNED' : '') + .(isset($attributes['DEFAULT']) ? ' DEFAULT \''.$attributes['DEFAULT'].'\'' : '') + .(( ! empty($attributes['NULL']) && $attributes['NULL'] === TRUE) ? ' NULL' : ' NOT NULL') + .(( ! empty($attributes['AUTO_INCREMENT']) && $attributes['AUTO_INCREMENT'] === TRUE) ? ' AUTO_INCREMENT' : ''); + } + + // don't add a comma on the end of the last field + if (++$current_field_count < count($fields)) + { + $sql .= ','; + } + } + + if (count($primary_keys) > 0) + { + $primary_keys = $this->db->protect_identifiers($primary_keys); + $sql .= ",\n\tPRIMARY KEY (".implode(', ', $primary_keys).')'; + } + + if (is_array($keys) && count($keys) > 0) + { + foreach ($keys as $key) + { + if (is_array($key)) + { + $key = $this->db->protect_identifiers($key); + } + else + { + $key = array($this->db->protect_identifiers($key)); + } + + $sql .= ",\n\tUNIQUE (".implode(', ', $key).')'; + } + } + + return $sql."\n)"; + } + + // -------------------------------------------------------------------- + + /** + * Drop Table + * + * @param string the table name + * @return string + */ + public function _drop_table($table) + { + return 'DROP TABLE '.$table.' IF EXISTS'; + } + + // -------------------------------------------------------------------- + + /** + * Alter table query + * + * Generates a platform-specific query so that a table can be altered + * Called by add_column(), drop_column(), and column_alter(), + * + * @param string the ALTER type (ADD, DROP, CHANGE) + * @param string the column name + * @param string the table name + * @param string the column definition + * @param string the default value + * @param bool should 'NOT NULL' be added + * @param string the field after which we should add the new field + * @return string + */ + public function _alter_table($alter_type, $table, $column_name, $column_definition = '', $default_value = '', $null = '', $after_field = '') + { + /* SQLite only supports adding new columns and it does + * NOT support the AFTER statement. Each new column will + * be added as the last one in the table. + */ + if ($alter_type !== 'ADD COLUMN') + { + // Not supported + return FALSE; + } + + return 'ALTER TABLE '.$this->db->protect_identifiers($table).' '.$alter_type.' '.$this->db->protect_identifiers($column_name) + .' '.$column_definition + .($default_value != '' ? ' DEFAULT '.$default_value : '') + // If NOT NULL is specified, the field must have a DEFAULT value other than NULL + .(($null !== NULL && $default_value !== 'NULL') ? ' NOT NULL' : ' NULL'); + } + + // -------------------------------------------------------------------- + + /** + * Rename a table + * + * Generates a platform-specific query so that a table can be renamed + * + * @param string the old table name + * @param string the new table name + * @return string + */ + public function _rename_table($table_name, $new_table_name) + { + return 'ALTER TABLE '.$this->db->protect_identifiers($table_name).' RENAME TO '.$this->db->protect_identifiers($new_table_name); + } +} + +/* End of file sqlite3_forge.php */ +/* Location: ./system/database/drivers/sqlite3/sqlite3_forge.php */
\ No newline at end of file diff --git a/system/database/drivers/sqlite3/sqlite3_result.php b/system/database/drivers/sqlite3/sqlite3_result.php new file mode 100644 index 000000000..ddf59dbd0 --- /dev/null +++ b/system/database/drivers/sqlite3/sqlite3_result.php @@ -0,0 +1,619 @@ +<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed'); +/** + * CodeIgniter + * + * An open source application development framework for PHP 5.1.6 or newer + * + * NOTICE OF LICENSE + * + * Licensed under the Open Software License version 3.0 + * + * This source file is subject to the Open Software License (OSL 3.0) that is + * bundled with this package in the files license.txt / license.rst. It is + * also available through the world wide web at this URL: + * http://opensource.org/licenses/OSL-3.0 + * If you did not receive a copy of the license and are unable to obtain it + * through the world wide web, please send an email to + * licensing@ellislab.com so we can send you a copy immediately. + * + * @package CodeIgniter + * @author EllisLab Dev Team + * @copyright Copyright (c) 2008 - 2012, EllisLab, Inc. (http://ellislab.com/) + * @license http://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0) + * @link http://codeigniter.com + * @since Version 1.0 + * @filesource + */ + +/** + * SQLite Result Class + * + * This class extends the parent result class: CI_DB_result + * + * @category Database + * @author Andrey Andreev + * @link http://codeigniter.com/user_guide/database/ + */ +class CI_DB_sqlite3_result extends CI_DB_result { + + // Overwriting the parent here, so we have a way to know if it's already set + public $num_rows; + + // num_fields() might be called multiple times, so we'll use this one to cache it's result + protected $_num_fields; + + /** + * Number of rows in the result set + * + * @return int + */ + public function num_rows() + { + /* The SQLite3 driver doesn't have a graceful way to do this, + * so we'll have to do it on our own. + */ + return is_int($this->num_rows) + ? $this->num_rows + : $this->num_rows = count($this->result_array()); + } + + // -------------------------------------------------------------------- + + /** + * Number of fields in the result set + * + * @return int + */ + public function num_fields() + { + return ( ! is_int($this->_num_fields)) + ? $this->_num_fields = $this->result_id->numColumns() + : $this->_num_fields; + } + + // -------------------------------------------------------------------- + + /** + * Fetch Field Names + * + * Generates an array of column names + * + * @return array + */ + public function list_fields() + { + $field_names = array(); + for ($i = 0, $c = $this->num_fields(); $i < $c; $i++) + { + $field_names[] = $this->result_id->columnName($i); + } + + return $field_names; + } + + // -------------------------------------------------------------------- + + /** + * Field data + * + * Generates an array of objects containing field meta-data + * + * @return array + */ + public function field_data() + { + $retval = array(); + for ($i = 0, $c = $this->num_fields(); $i < $this->num_fields(); $i++) + { + $retval[$i] = new stdClass(); + $retval[$i]->name = $this->result_id->columnName($i); + $retval[$i]->type = 'varchar'; + $retval[$i]->max_length = 0; + $retval[$i]->primary_key = 0; + $retval[$i]->default = ''; + } + + return $retval; + } + + // -------------------------------------------------------------------- + + /** + * Free the result + * + * @return void + */ + public function free_result() + { + if (is_object($this->result_id)) + { + $this->result_id->finalize(); + $this->result_id = NULL; + } + } + + // -------------------------------------------------------------------- + + /** + * Result - associative array + * + * Returns the result set as an array + * + * @return array + */ + protected function _fetch_assoc() + { + return $this->result_id->fetchArray(SQLITE3_ASSOC); + } + + // -------------------------------------------------------------------- + + /** + * Result - object + * + * Returns the result set as an object + * + * @return object + */ + protected function _fetch_object() + { + // No native support for fetching as an object + $row = $this->_fetch_assoc(); + return ($row !== FALSE) ? (object) $row : FALSE; + } + + // -------------------------------------------------------------------- + + /** + * Query result. "array" version. + * + * return array + */ + public function result_array() + { + if (count($this->result_array) > 0) + { + return $this->result_array; + } + elseif (is_array($this->row_data)) + { + if (count($this->row_data) === 0) + { + return $this->result_array; + } + else + { + $row_index = count($this->row_data); + } + } + else + { + $row_index = 0; + $this->row_data = array(); + } + + $row = NULL; + while ($row = $this->_fetch_assoc()) + { + $this->row_data[$row_index++] = $row; + } + + // Un-comment the following line, in case it becomes needed + // $this->_data_seek(); + return $this->result_array = $this->row_data; + } + + // -------------------------------------------------------------------- + + /** + * Query result. "object" version. + * + * @return array + */ + public function result_object() + { + if (count($this->result_object) > 0) + { + return $this->result_object; + } + elseif (count($this->result_array) > 0) + { + for ($i = 0, $c = count($this->result_array); $i < $c; $i++) + { + $this->result_object[] = (object) $this->result_array[$i]; + } + + return $this->result_object; + } + elseif (is_array($this->row_data)) + { + if (count($this->row_data) === 0) + { + return $this->result_object; + } + else + { + $row_index = count($this->row_data); + for ($i = 0; $i < $row_index; $i++) + { + $this->result_object[$i] = (object) $this->row_data[$i]; + } + } + } + else + { + $row_index = 0; + $this->row_data = array(); + } + + $row = NULL; + while ($row = $this->_fetch_assoc()) + { + $this->row_data[$row_index] = $row; + $this->result_object[$row_index++] = (object) $row; + } + + $this->result_array = $this->row_data; + + /* As described for the num_rows() method - there's no easy + * way to get the number of rows selected. Our work-around + * solution (as in here as well) first checks if result_array + * exists and returns its count. It doesn't however check for + * custom_object_result, so - do it here. + */ + if ( ! is_int($this->num_rows)) + { + $this->num_rows = count($this->result_object); + } + + // Un-comment the following line, in case it becomes needed + // $this->_data_seek(); + return $this->result_object; + } + + // -------------------------------------------------------------------- + + /** + * Query result. Custom object version. + * + * @param string class name used to instantiate rows to + * @return array + */ + public function custom_result_object($class_name) + { + if (array_key_exists($class_name, $this->custom_result_object)) + { + return $this->custom_result_object[$class_name]; + } + + if ( ! class_exists($class_name) OR ! is_object($this->result_id) OR $this->num_rows() === 0) + { + return array(); + } + + /* Even if result_array hasn't been set prior to custom_result_object being called, + * num_rows() has done it. + */ + $data = &$this->result_array; + + $result_object = array(); + for ($i = 0, $c = count($data); $i < $c; $i++) + { + $result_object[$i] = new $class_name(); + foreach ($data[$i] as $key => $value) + { + $result_object[$i]->$key = $value; + } + } + + /* As described for the num_rows() method - there's no easy + * way to get the number of rows selected. Our work-around + * solution (as in here as well) first checks if result_array + * exists and returns its count. It doesn't however check for + * custom_object_result, so - do it here. + */ + if ( ! is_int($this->num_rows)) + { + $this->num_rows = count($result_object); + } + + // Cache and return the array + return $this->custom_result_object[$class_name] = $result_object; + } + + // -------------------------------------------------------------------- + + /* Single row result. + * + * Acts as a wrapper for row_object(), row_array() + * and custom_row_object(). Also used by first_row(), next_row() + * and previous_row(). + * + * @param int row index + * @param string ('object', 'array' or a custom class name) + * @return mixed whatever was passed to the second parameter + */ + public function row($n = 0, $type = 'object') + { + if ($type === 'object') + { + return $this->row_object($n); + } + elseif ($type === 'array') + { + return $this->row_array($n); + } + + return $this->custom_row_object($n, $type); + } + + // -------------------------------------------------------------------- + + /* Single row result. Array version. + * + * @param int row index + * @return array + */ + public function row_array($n = 0) + { + // Make sure $n is not a string + if ( ! is_int($n)) + { + $n = (int) $n; + } + + /* If row_data is initialized, it means that we've already tried + * (at least) to fetch some data, so ... check if we already have + * this row. + */ + if (is_array($this->row_data)) + { + /* If we already have row_data[$n] - return it. + * + * If we enter the elseif, there's a number of reasons to + * return an empty array: + * + * - count($this->row_data) === 0 means there are no results + * - num_rows being set or result_array having count() > 0 means + * that we've already fetched all data and $n is greater than + * our highest row index available + * - $n < $this->current_row means that if such row existed, + * we would've already returned it, therefore $n is an + * invalid index + */ + if (isset($this->row_data[$n])) // We already have this row + { + $this->current_row = $n; + return $this->row_data[$n]; + } + elseif (count($this->row_data) === 0 OR is_int($this->num_rows) + OR count($this->result_array) > 0 OR $n < $this->current_row) + { + // No such row exists + return array(); + } + + // Get the next row index that would actually need to be fetched + $current_row = ($this->current_row < count($this->row_data)) ? count($this->row_data) : $this->current_row + 1; + } + else + { + $current_row = $this->current_row = 0; + $this->row_data = array(); + } + + /* Fetch more data, if available + * + * NOTE: Operator precedence is important here, if you change + * 'AND' with '&&' - it WILL BREAK the results, as + * $row will be assigned the scalar value of both + * expressions! + */ + while ($row = $this->_fetch_assoc() AND $current_row <= $n) + { + $this->row_data[$current_row++] = $row; + } + + // This would mean that there's no (more) data to fetch + if ( ! is_array($this->row_data) OR ! isset($this->row_data[$n])) + { + // Cache what we already have + if (is_array($this->row_data)) + { + $this->num_rows = count($this->row_data); + /* Usually, row_data could have less elements than result_array, + * but at this point - they should be exactly the same. + */ + $this->result_array = $this->row_data; + } + else + { + $this->num_rows = 0; + } + + return array(); + } + + $this->current_row = $n; + return $this->row_data[$n]; + } + + // -------------------------------------------------------------------- + + /* Single row result. Object version. + * + * @param int row index + * @return mixed object if row found; empty array if not + */ + public function row_object($n = 0) + { + // Make sure $n is not a string + if ( ! is_int($n)) + { + $n = (int) $n; + } + + /* Logic here is exactly the same as in row_array, + * except we have to cast row_data[$n] to an object. + * + * If we already have result_object though - we can + * directly return from it. + */ + if (isset($this->result_object[$n])) + { + $this->current_row = $n; + return $this->result_object[$n]; + } + + $row = $this->row_array($n); + // Cast only if the row exists + if (count($row) > 0) + { + $this->current_row = $n; + return (object) $row; + } + + return array(); + } + + // -------------------------------------------------------------------- + + /* Single row result. Custom object version. + * + * @param int row index + * @param string custom class name + * @return mixed custom object if row found; empty array otherwise + */ + public function custom_row_object($n = 0, $class_name) + { + // Make sure $n is not a string + if ( ! is_int($n)) + { + $n = (int) $n; + } + + if (array_key_exists($class_name, $this->custom_result_object)) + { + /* We already have a the whole result set with this class_name, + * return the specified row if it exists, and an empty array if + * it doesn't. + */ + if (isset($this->custom_result_object[$class_name][$n])) + { + $this->current_row = $n; + return $this->custom_result_object[$class_name][$n]; + } + else + { + return array(); + } + } + elseif ( ! class_exists($class_name)) // No such class exists + { + return array(); + } + + $row = $this->row_array($n); + // An array would mean that the row doesn't exist + if (is_array($row)) + { + return $row; + } + + // Convert to the desired class and return + $row_object = new $class_name(); + foreach ($row as $key => $value) + { + $row_object->$key = $value; + } + + $this->current_row = $n; + return $row_object; + } + + // -------------------------------------------------------------------- + + /* First row result. + * + * @param string ('object', 'array' or a custom class name) + * @return mixed whatever was passed to the second parameter + */ + public function first_row($type = 'object') + { + return $this->row(0, $type); + } + + // -------------------------------------------------------------------- + + /* Last row result. + * + * @param string ('object', 'array' or a custom class name) + * @return mixed whatever was passed to the second parameter + */ + public function last_row($type = 'object') + { + $result = &$this->result($type); + if ( ! isset($this->num_rows)) + { + $this->num_rows = count($result); + } + $this->current_row = $this->num_rows - 1; + return $result[$this->current_row]; + } + + // -------------------------------------------------------------------- + + /* Next row result. + * + * @param string ('object', 'array' or a custom class name) + * @return mixed whatever was passed to the second parameter + */ + public function next_row($type = 'object') + { + if (is_array($this->row_data)) + { + $count = count($this->row_data); + $n = ($this->current_row > $count OR ($this->current_row === 0 && $count === 0)) ? $count : $this->current_row + 1; + } + else + { + $n = 0; + } + + return $this->row($n, $type); + } + + // -------------------------------------------------------------------- + + /* Previous row result. + * + * @param string ('object', 'array' or a custom class name) + * @return mixed whatever was passed to the second parameter + */ + public function previous_row($type = 'object') + { + $n = ($this->current_row !== 0) ? $this->current_row - 1 : 0; + return $this->row($n, $type); + } + + // -------------------------------------------------------------------- + + /** + * Data Seek + * + * Moves the internal pointer to the desired offset. We call + * this internally before fetching results to make sure the + * result set starts at zero + * + * @return array + */ + protected function _data_seek($n = 0) + { + // Only resetting to the start of the result set is supported + return $this->result_id->reset(); + } + +} + +/* End of file sqlite3_result.php */ +/* Location: ./system/database/drivers/sqlite3/sqlite3_result.php */
\ No newline at end of file diff --git a/system/database/drivers/sqlite3/sqlite3_utility.php b/system/database/drivers/sqlite3/sqlite3_utility.php new file mode 100644 index 000000000..a4dc875e1 --- /dev/null +++ b/system/database/drivers/sqlite3/sqlite3_utility.php @@ -0,0 +1,103 @@ +<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed'); +/** + * CodeIgniter + * + * An open source application development framework for PHP 5.1.6 or newer + * + * NOTICE OF LICENSE + * + * Licensed under the Open Software License version 3.0 + * + * This source file is subject to the Open Software License (OSL 3.0) that is + * bundled with this package in the files license.txt / license.rst. It is + * also available through the world wide web at this URL: + * http://opensource.org/licenses/OSL-3.0 + * If you did not receive a copy of the license and are unable to obtain it + * through the world wide web, please send an email to + * licensing@ellislab.com so we can send you a copy immediately. + * + * @package CodeIgniter + * @author EllisLab Dev Team + * @copyright Copyright (c) 2008 - 2012, EllisLab, Inc. (http://ellislab.com/) + * @license http://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0) + * @link http://codeigniter.com + * @since Version 1.0 + * @filesource + */ + +/** + * SQLite3 Utility Class + * + * @category Database + * @author Andrey Andreev + * @link http://codeigniter.com/user_guide/database/ + */ +class CI_DB_sqlite3_utility extends CI_DB_utility { + + /** + * List databases + * + * @return bool + */ + public function _list_databases() + { + // Not supported + return FALSE; + + // Do we use this? + if ($this->db_debug) + { + return $this->db->display_error('db_unsuported_feature'); + } + } + + // -------------------------------------------------------------------- + + /** + * Optimize table query + * + * Is optimization even supported in SQLite? + * + * @param string the table name + * @return bool + */ + public function _optimize_table($table) + { + // Not supported + return FALSE; + } + + // -------------------------------------------------------------------- + + /** + * Repair table query + * + * Are table repairs even supported in SQLite? + * + * @param string the table name + * @return object + */ + public function _repair_table($table) + { + // Not supported + return FALSE; + } + + // -------------------------------------------------------------------- + + /** + * SQLite Export + * + * @param array Preferences + * @return mixed + */ + public function _backup($params = array()) + { + // Not supported + return $this->db->display_error('db_unsuported_feature'); + } + +} + +/* End of file sqlite3_utility.php */ +/* Location: ./system/database/drivers/sqlite3/sqlite3_utility.php */
\ No newline at end of file diff --git a/system/database/drivers/sqlsrv/sqlsrv_driver.php b/system/database/drivers/sqlsrv/sqlsrv_driver.php index 9f2f88699..f4eab8f28 100644 --- a/system/database/drivers/sqlsrv/sqlsrv_driver.php +++ b/system/database/drivers/sqlsrv/sqlsrv_driver.php @@ -55,7 +55,7 @@ class CI_DB_sqlsrv_driver extends CI_DB { * used for the count_all() and count_all_results() functions. */ protected $_count_string = 'SELECT COUNT(*) AS '; - protected $_random_keyword = ' ASC'; // not currently supported + protected $_random_keyword = ' NEWID()'; // not currently supported /** * Non-persistent database connection @@ -68,12 +68,12 @@ class CI_DB_sqlsrv_driver extends CI_DB { $character_set = (0 === strcasecmp('utf8', $this->char_set)) ? 'UTF-8' : $this->char_set; $connection = array( - 'UID' => empty($this->username) ? '' : $this->username, - 'PWD' => empty($this->password) ? '' : $this->password, - 'Database' => $this->database, - 'ConnectionPooling' => $pooling ? 1 : 0, + 'UID' => empty($this->username) ? '' : $this->username, + 'PWD' => empty($this->password) ? '' : $this->password, + 'Database' => $this->database, + 'ConnectionPooling' => $pooling ? 1 : 0, 'CharacterSet' => $character_set, - 'ReturnDatesAsStrings' => 1 + 'ReturnDatesAsStrings' => 1 ); // If the username and password are both empty, assume this is a @@ -259,23 +259,6 @@ class CI_DB_sqlsrv_driver extends CI_DB { // -------------------------------------------------------------------- /** - * Parse major version - * - * Grabs the major version number from the - * database server version string passed in. - * - * @param string $version - * @return int major version number - */ - protected function _parse_major_version($version) - { - preg_match('/([0-9]+)\.([0-9]+)\.([0-9]+)/', $version, $ver_info); - return $ver_info[1]; // return the major version b/c that's all we're interested in. - } - - // -------------------------------------------------------------------- - - /** * Database version number * * @return string @@ -410,21 +393,6 @@ class CI_DB_sqlsrv_driver extends CI_DB { // -------------------------------------------------------------------- /** - * Escape the SQL Identifiers - * - * This function escapes column and table names - * - * @param string - * @return string - */ - public function _escape_identifiers($item) - { - return $item; - } - - // -------------------------------------------------------------------- - - /** * From Tables * * This function implicitly groups FROM tables so there is no confusion @@ -446,23 +414,6 @@ class CI_DB_sqlsrv_driver extends CI_DB { // -------------------------------------------------------------------- /** - * Insert statement - * - * Generates a platform-specific insert string from the supplied data - * - * @param string the table name - * @param array the insert keys - * @param array the insert values - * @return string - */ - protected function _insert($table, $keys, $values) - { - return 'INSERT INTO '.$table.' ('.implode(', ', $keys).') VALUES ('.implode(', ', $values).')'; - } - - // -------------------------------------------------------------------- - - /** * Update statement * * Generates a platform-specific update string from the supplied data @@ -490,15 +441,16 @@ class CI_DB_sqlsrv_driver extends CI_DB { * Truncate statement * * Generates a platform-specific truncate string from the supplied data - * If the database does not support the truncate() command - * This function maps to "DELETE FROM table" + * + * If the database does not support the truncate() command, + * then this method maps to 'DELETE FROM table' * * @param string the table name * @return string */ protected function _truncate($table) { - return "TRUNCATE ".$table; + return 'TRUNCATE TABLE '.$table; } // -------------------------------------------------------------------- diff --git a/system/database/drivers/sqlsrv/sqlsrv_forge.php b/system/database/drivers/sqlsrv/sqlsrv_forge.php index 0dc7b5242..377dcf154 100644 --- a/system/database/drivers/sqlsrv/sqlsrv_forge.php +++ b/system/database/drivers/sqlsrv/sqlsrv_forge.php @@ -63,11 +63,12 @@ class CI_DB_sqlsrv_forge extends CI_DB_forge { /** * Drop Table * - * @return bool + * @param string table name + * @return string */ public function _drop_table($table) { - return "DROP TABLE ".$this->db->_escape_identifiers($table); + return 'DROP TABLE '.$this->db->escape_identifiers($table); } // -------------------------------------------------------------------- @@ -91,7 +92,7 @@ class CI_DB_sqlsrv_forge extends CI_DB_forge { $sql .= 'IF NOT EXISTS '; } - $sql .= $this->db->_escape_identifiers($table)." ("; + $sql .= $this->db->escape_identifiers($table).' ('; $current_field_count = 0; foreach ($fields as $field => $attributes) diff --git a/system/helpers/array_helper.php b/system/helpers/array_helper.php index 464d1d112..6f56d9db9 100644 --- a/system/helpers/array_helper.php +++ b/system/helpers/array_helper.php @@ -103,4 +103,4 @@ if ( ! function_exists('elements')) } /* End of file array_helper.php */ -/* Location: ./system/helpers/array_helper.php */ +/* Location: ./system/helpers/array_helper.php */
\ No newline at end of file diff --git a/system/helpers/captcha_helper.php b/system/helpers/captcha_helper.php index 578796573..bdbc62097 100644 --- a/system/helpers/captcha_helper.php +++ b/system/helpers/captcha_helper.php @@ -1,4 +1,4 @@ -<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed'); +<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed'); /** * CodeIgniter * @@ -25,8 +25,6 @@ * @filesource */ -// ------------------------------------------------------------------------ - /** * CodeIgniter CAPTCHA Helper * @@ -42,7 +40,6 @@ /** * Create CAPTCHA * - * @access public * @param array array of data for the CAPTCHA * @param string path to create the image in * @param string URL to the CAPTCHA image folder @@ -57,35 +54,19 @@ if ( ! function_exists('create_captcha')) foreach ($defaults as $key => $val) { - if ( ! is_array($data)) + if ( ! is_array($data) && empty($$key)) { - if ( ! isset($$key) OR $$key == '') - { - $$key = $val; - } + $$key = $val; } else { - $$key = ( ! isset($data[$key])) ? $val : $data[$key]; + $$key = isset($data[$key]) ? $data[$key] : $val; } } - 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')) + if ($img_path == '' OR $img_url == '' + OR ! @is_dir($img_path) OR ! is_writeable($img_path) + OR ! extension_loaded('gd')) { return FALSE; } @@ -97,17 +78,12 @@ if ( ! function_exists('create_captcha')) $now = microtime(TRUE); $current_dir = @opendir($img_path); - while ($filename = @readdir($current_dir)) { - if ($filename != '.' && $filename != '..' && $filename != 'index.html') + if ($filename !== '.' && $filename !== '..' && $filename !== 'index.html' + && (str_replace('.jpg', '', $filename) + $expiration) < $now) { - $name = str_replace('.jpg', '', $filename); - - if (($name + $expiration) < $now) - { - @unlink($img_path.$filename); - } + @unlink($img_path.$filename); } } @@ -117,141 +93,114 @@ if ( ! function_exists('create_captcha')) // Do we have a "word" yet? // ----------------------------------- - if ($word == '') - { + if ($word == '') + { $pool = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'; - - $str = ''; - for ($i = 0; $i < 8; $i++) + $word = ''; + for ($i = 0, $mt_rand_max = strlen($pool) - 1; $i < 8; $i++) { - $str .= substr($pool, mt_rand(0, strlen($pool) -1), 1); + $word .= $pool[mt_rand(0, $mt_rand_max)]; } - - $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); + $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); - } + $im = function_exists('imagecreatetruecolor') + ? imagecreatetruecolor($img_width, $img_height) + : 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); + $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++) + for ($i = 0, $cp = ($circles * $points) - 1; $i < $cp; $i++) { - $theta = $theta + $thetac; - $rad = $radius * ($i / $points ); + $theta += $thetac; + $rad = $radius * ($i / $points); $x = ($rad * cos($theta)) + $x_axis; $y = ($rad * sin($theta)) + $y_axis; - $theta = $theta + $thetac; + $theta += $thetac; $rad1 = $radius * (($i + 1) / $points); $x1 = ($rad1 * cos($theta)) + $x_axis; - $y1 = ($rad1 * sin($theta )) + $y_axis; + $y1 = ($rad1 * sin($theta)) + $y_axis; imageline($im, $x, $y, $x1, $y1, $grid_color); - $theta = $theta - $thetac; + $theta -= $thetac; } // ----------------------------------- // Write the text // ----------------------------------- - $use_font = ($font_path != '' && file_exists($font_path) && function_exists('imagettftext')) ? TRUE : FALSE; - - if ($use_font == FALSE) + $use_font = ($font_path != '' && file_exists($font_path) && function_exists('imagettftext')); + if ($use_font === FALSE) { $font_size = 5; - $x = rand(0, $img_width/($length/3)); + $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; + $font_size = 16; + $x = rand(0, $img_width / ($length / 1.5)); + $y = $font_size + 2; } - for ($i = 0; $i < strlen($word); $i++) + for ($i = 0; $i < $length; $i++) { - if ($use_font == FALSE) + 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); + $y = rand(0 , $img_height / 2); + imagestring($im, $font_size, $x, $y, $word[$i], $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)); + $y = rand($img_height / 2, $img_height - 3); + imagettftext($im, $font_size, $angle, $x, $y, $text_color, $font_path, $word[$i]); $x += $font_size; } } - // ----------------------------------- - // Create the border - // ----------------------------------- - - imagerectangle($im, 0, 0, $img_width-1, $img_height-1, $border_color); + // 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 = "<img src=\"$img_url$img_name\" width=\"$img_width\" height=\"$img_height\" style=\"border:0;\" alt=\" \" />"; - + $img = '<img src="'.$img_url.$img_name.'" style="width: '.$img_width.'; height: '.$img_height .'; border: 0;" alt=" " />'; ImageDestroy($im); return array('word' => $word, 'time' => $now, 'image' => $img); } } -// ------------------------------------------------------------------------ - /* End of file captcha_helper.php */ /* Location: ./system/helpers/captcha_helper.php */
\ No newline at end of file diff --git a/system/helpers/cookie_helper.php b/system/helpers/cookie_helper.php index ec8aa3250..06560e723 100644 --- a/system/helpers/cookie_helper.php +++ b/system/helpers/cookie_helper.php @@ -102,4 +102,4 @@ if ( ! function_exists('delete_cookie')) } /* End of file cookie_helper.php */ -/* Location: ./system/helpers/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 d54553292..f1ba364f5 100644 --- a/system/helpers/date_helper.php +++ b/system/helpers/date_helper.php @@ -1,4 +1,4 @@ -<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed'); +<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed'); /** * CodeIgniter * @@ -25,8 +25,6 @@ * @filesource */ -// ------------------------------------------------------------------------ - /** * CodeIgniter Date Helpers * @@ -44,8 +42,7 @@ * * Returns time() or its GMT equivalent based on the config file preference * - * @access public - * @return integer + * @return int */ if ( ! function_exists('now')) { @@ -85,10 +82,9 @@ if ( ! function_exists('now')) * have to worry about escaping your text letters that * match the date codes. * - * @access public * @param string - * @param integer - * @return integer + * @param int + * @return int */ if ( ! function_exists('mdate')) { @@ -118,9 +114,8 @@ if ( ! function_exists('mdate')) * * Returns a date formatted according to the submitted standard. * - * @access public * @param string the chosen format - * @param integer Unix timestamp + * @param int Unix timestamp * @return string */ if ( ! function_exists('standard_date')) @@ -157,10 +152,9 @@ if ( ! function_exists('standard_date')) * 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 - * @param integer a number of display units + * @param int a number of seconds + * @param int Unix timestamp + * @param int a number of display units * @return string */ if ( ! function_exists('timespan')) @@ -273,10 +267,9 @@ if ( ! function_exists('timespan')) * 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 + * @param int a numeric month + * @param int a numeric year + * @return int */ if ( ! function_exists('days_in_month')) { @@ -294,7 +287,7 @@ if ( ! function_exists('days_in_month')) if ($month == 2) { - if ($year % 400 == 0 OR ($year % 4 == 0 AND $year % 100 != 0)) + if ($year % 400 == 0 OR ($year % 4 == 0 && $year % 100 != 0)) { return 29; } @@ -310,9 +303,8 @@ if ( ! function_exists('days_in_month')) /** * Converts a local Unix timestamp to GMT * - * @access public - * @param integer Unix timestamp - * @return integer + * @param int Unix timestamp + * @return int */ if ( ! function_exists('local_to_gmt')) { @@ -343,11 +335,10 @@ if ( ! function_exists('local_to_gmt')) * at the local value based on the timezone and DST setting * submitted * - * @access public - * @param integer Unix timestamp + * @param int Unix timestamp * @param string timezone * @param bool whether DST is active - * @return integer + * @return int */ if ( ! function_exists('gmt_to_local')) { @@ -374,9 +365,8 @@ if ( ! function_exists('gmt_to_local')) /** * Converts a MySQL Timestamp to Unix * - * @access public - * @param integer Unix timestamp - * @return integer + * @param int Unix timestamp + * @return int */ if ( ! function_exists('mysql_to_unix')) { @@ -409,8 +399,7 @@ if ( ! function_exists('mysql_to_unix')) * * Formats Unix timestamp to the following prototype: 2006-08-21 11:35 PM * - * @access public - * @param integer Unix timestamp + * @param int Unix timestamp * @param bool whether to show seconds * @param string format: us or euro * @return string @@ -451,9 +440,8 @@ if ( ! function_exists('unix_to_human')) * * Reverses the above process * - * @access public * @param string format: us or euro - * @return integer + * @return int */ if ( ! function_exists('human_to_unix')) { @@ -499,12 +487,12 @@ if ( ! function_exists('human_to_unix')) { $ampm = strtolower($split['2']); - if (substr($ampm, 0, 1) == 'p' AND $hour < 12) + if (substr($ampm, 0, 1) === 'p' && $hour < 12) { $hour = $hour + 12; } - if (substr($ampm, 0, 1) == 'a' AND $hour == 12) + if (substr($ampm, 0, 1) === 'a' && $hour == 12) { $hour = '00'; } @@ -525,10 +513,9 @@ if ( ! function_exists('human_to_unix')) * Turns many "reasonably-date-like" strings into something * that is actually useful. This only works for dates after unix epoch. * - * @access public - * @param string The terribly formatted date-like string - * @param string Date format to return (same as php date function) - * @return string + * @param string The terribly formatted date-like string + * @param string Date format to return (same as php date function) + * @return string */ if ( ! function_exists('nice_date')) { @@ -593,7 +580,6 @@ if ( ! function_exists('nice_date')) * * Generates a drop-down menu of timezones. * - * @access public * @param string timezone * @param string classname * @param string menu name @@ -634,10 +620,9 @@ if ( ! function_exists('timezone_menu')) /** * Timezones * - * Returns an array of timezones. This is a helper function + * Returns an array of timezones. This is a helper function * for various other ones in this library * - * @access public * @param string timezone * @return string */ @@ -698,7 +683,7 @@ if ( ! function_exists('timezones')) $tz = ($tz == 'GMT') ? 'UTC' : $tz; - return ( ! isset($zones[$tz])) ? 0 : $zones[$tz]; + return isset($zones[$tz]) ? $zones[$tz] : 0; } } diff --git a/system/helpers/directory_helper.php b/system/helpers/directory_helper.php index d7ca13e85..4044ace11 100644 --- a/system/helpers/directory_helper.php +++ b/system/helpers/directory_helper.php @@ -85,4 +85,4 @@ if ( ! function_exists('directory_map')) } /* End of file directory_helper.php */ -/* Location: ./system/helpers/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 96ff29dec..19192a147 100644 --- a/system/helpers/download_helper.php +++ b/system/helpers/download_helper.php @@ -42,7 +42,6 @@ * * Generates headers that force a download to happen * - * @access public * @param string filename * @param mixed the data to be downloaded * @param bool wether to try and send the actual file MIME type @@ -125,4 +124,4 @@ if ( ! function_exists('force_download')) } /* End of file download_helper.php */ -/* Location: ./system/helpers/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 b87bce674..497625c10 100644 --- a/system/helpers/email_helper.php +++ b/system/helpers/email_helper.php @@ -25,8 +25,6 @@ * @filesource */ -// ------------------------------------------------------------------------ - /** * CodeIgniter Email Helpers * @@ -42,7 +40,7 @@ /** * Validate email address * - * @access public + * @param string * @return bool */ if ( ! function_exists('valid_email')) @@ -58,7 +56,9 @@ if ( ! function_exists('valid_email')) /** * Send an email * - * @access public + * @param string + * @param string + * @param string * @return bool */ if ( ! function_exists('send_email')) @@ -70,4 +70,4 @@ if ( ! function_exists('send_email')) } /* End of file email_helper.php */ -/* Location: ./system/helpers/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 3fd6b82e1..3a373efd3 100644 --- a/system/helpers/file_helper.php +++ b/system/helpers/file_helper.php @@ -25,8 +25,6 @@ * @filesource */ -// ------------------------------------------------------------------------ - /** * CodeIgniter File Helpers * @@ -44,7 +42,6 @@ * * Opens the file specfied in the path and returns it as a string. * - * @access public * @param string path to file * @return string */ @@ -90,7 +87,6 @@ if ( ! function_exists('read_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 @@ -123,14 +119,15 @@ if ( ! function_exists('write_file')) * 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 + * @param int + * @param bool whether to skip deleting .htaccess and index page files * @return bool */ if ( ! function_exists('delete_files')) { - function delete_files($path, $del_dir = FALSE, $level = 0) + function delete_files($path, $del_dir = FALSE, $level = 0, $htdocs = FALSE) { // Trim the trailing slash $path = rtrim($path, DIRECTORY_SEPARATOR); @@ -142,21 +139,21 @@ if ( ! function_exists('delete_files')) while (FALSE !== ($filename = @readdir($current_dir))) { - if ($filename !== '.' and $filename !== '..') + if ($filename !== '.' && $filename !== '..') { if (is_dir($path.DIRECTORY_SEPARATOR.$filename) && $filename[0] !== '.') { - delete_files($path.DIRECTORY_SEPARATOR.$filename, $del_dir, $level + 1); + delete_files($path.DIRECTORY_SEPARATOR.$filename, $del_dir, $level + 1, $htdocs); } - else + elseif ($htdocs === TRUE && ! preg_match('/^(\.htaccess|index\.(html|htm|php))$/', $filename)) { - unlink($path.DIRECTORY_SEPARATOR.$filename); + @unlink($path.DIRECTORY_SEPARATOR.$filename); } } } @closedir($current_dir); - if ($del_dir == TRUE AND $level > 0) + if ($del_dir == TRUE && $level > 0) { return @rmdir($path); } @@ -173,7 +170,6 @@ if ( ! function_exists('delete_files')) * Reads the specified directory and builds an array containing the filenames. * Any sub-folders contained within the specified path are read as well. * - * @access public * @param string path to source * @param bool whether to include the path as part of the filename * @param bool internal variable to determine recursion status - do not use in calls @@ -224,7 +220,6 @@ if ( ! function_exists('get_filenames')) * * Any sub-folders contained within the specified path are read as well. * - * @access public * @param string path to source * @param bool Look only at the top level directory specified? * @param bool internal variable to determine recursion status - do not use in calls @@ -278,7 +273,6 @@ 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 @@ -345,7 +339,6 @@ if ( ! function_exists('get_file_info')) * 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 */ @@ -399,7 +392,6 @@ if ( ! function_exists('get_mime_by_extension')) * Takes a numeric value representing a file's permissions and returns * standard symbolic notation representing that value * - * @access public * @param int * @return string */ @@ -467,7 +459,6 @@ if ( ! function_exists('symbolic_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 */ @@ -480,4 +471,4 @@ if ( ! function_exists('octal_permissions')) } /* End of file file_helper.php */ -/* Location: ./system/helpers/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 37337d975..e5b487608 100644 --- a/system/helpers/form_helper.php +++ b/system/helpers/form_helper.php @@ -24,8 +24,6 @@ * @since Version 1.0 */ -// ------------------------------------------------------------------------ - /** * CodeIgniter Form Helpers * @@ -43,7 +41,6 @@ * * Creates the opening portion of the form. * - * @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 @@ -71,15 +68,15 @@ if ( ! function_exists('form_open')) $form = '<form action="'.$action.'"'._attributes_to_string($attributes, TRUE).">\n"; - // Add CSRF field if enabled, but leave it out for GET requests and requests to external websites - if ($CI->config->item('csrf_protection') === TRUE AND ! (strpos($action, $CI->config->base_url()) === FALSE OR strpos($form, 'method="get"'))) + // Add CSRF field if enabled, but leave it out for GET requests and requests to external websites + if ($CI->config->item('csrf_protection') === TRUE && ! (strpos($action, $CI->config->base_url()) === FALSE OR strpos($form, 'method="get"'))) { $hidden[$CI->security->get_csrf_token_name()] = $CI->security->get_csrf_hash(); } - if (is_array($hidden) AND count($hidden) > 0) + if (is_array($hidden) && count($hidden) > 0) { - $form .= sprintf("<div style=\"display:none\">%s</div>", form_hidden($hidden)); + $form .= sprintf('<div style="display:none;">%s</div>', form_hidden($hidden)); } return $form; @@ -93,7 +90,6 @@ if ( ! function_exists('form_open')) * * 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 @@ -121,10 +117,9 @@ if ( ! function_exists('form_open_multipart')) /** * Hidden Input Field * - * Generates hidden fields. You can pass a simple key/value string or an associative - * array with multiple values. + * 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 @@ -157,7 +152,7 @@ if ( ! function_exists('form_hidden')) { foreach ($value as $k => $v) { - $k = (is_int($k)) ? '' : $k; + $k = is_int($k) ? '' : $k; form_hidden($name.'['.$k.']', $v, TRUE); } } @@ -171,7 +166,6 @@ if ( ! function_exists('form_hidden')) /** * Text Input Field * - * @access public * @param mixed * @param string * @param string @@ -181,7 +175,7 @@ if ( ! function_exists('form_input')) { function form_input($data = '', $value = '', $extra = '') { - $defaults = array('type' => 'text', 'name' => (( ! is_array($data)) ? $data : ''), 'value' => $value); + $defaults = array('type' => 'text', 'name' => ( ! is_array($data) ? $data : ''), 'value' => $value); return '<input '._parse_form_attributes($data, $defaults).$extra." />\n"; } @@ -194,7 +188,6 @@ if ( ! function_exists('form_input')) * * Identical to the input function but adds the "password" type * - * @access public * @param mixed * @param string * @param string @@ -221,7 +214,6 @@ if ( ! function_exists('form_password')) * * Identical to the input function but adds the "file" type * - * @access public * @param mixed * @param string * @param string @@ -246,7 +238,6 @@ if ( ! function_exists('form_upload')) /** * Textarea field * - * @access public * @param mixed * @param string * @param string @@ -256,7 +247,7 @@ if ( ! function_exists('form_textarea')) { function form_textarea($data = '', $value = '', $extra = '') { - $defaults = array('name' => (( ! is_array($data)) ? $data : ''), 'cols' => '40', 'rows' => '10'); + $defaults = array('name' => ( ! is_array($data) ? $data : ''), 'cols' => '40', 'rows' => '10'); if ( ! is_array($data) OR ! isset($data['value'])) { @@ -268,7 +259,7 @@ if ( ! function_exists('form_textarea')) unset($data['value']); // textareas don't use the value attribute } - $name = (is_array($data)) ? $data['name'] : $data; + $name = is_array($data) ? $data['name'] : $data; return '<textarea '._parse_form_attributes($data, $defaults).$extra.'>'.form_prep($val, $name)."</textarea>\n"; } } @@ -278,12 +269,11 @@ if ( ! function_exists('form_textarea')) /** * Multi-select menu * - * @access public * @param string * @param array * @param mixed * @param string - * @return type + * @return string */ if ( ! function_exists('form_multiselect')) { @@ -303,7 +293,6 @@ if ( ! function_exists('form_multiselect')) /** * Drop-down Menu * - * @access public * @param string * @param array * @param string @@ -314,28 +303,16 @@ if ( ! function_exists('form_dropdown')) { function form_dropdown($name = '', $options = array(), $selected = array(), $extra = '') { - // If name is really an array then we'll call the function again using the array - if (is_array($name) && isset($name['name'])) - { - - if ( ! isset($name['options'])) - { - $name['options'] = array(); - } - - if ( ! isset($name['selected'])) - { - $name['selected'] = array(); - } - - if ( ! isset($name['extra'])) - { - $name['extra'] = ''; - } - - return form_dropdown($name['name'], $name['options'], $name['selected'], $name['extra']); - } - + // If name is really an array then we'll call the function again using the array + if (is_array($name) && isset($name['name'])) + { + isset($name['options']) OR $name['options'] = array(); + isset($name['selected']) OR $name['selected'] = array(); + isset($name['extra']) OR $name['extra'] = array(); + + return form_dropdown($name['name'], $name['options'], $name['selected'], $name['extra']); + } + if ( ! is_array($selected)) { $selected = array($selected); @@ -363,11 +340,11 @@ if ( ! function_exists('form_dropdown')) foreach ($val as $optgroup_key => $optgroup_val) { - $sel = (in_array($optgroup_key, $selected)) ? ' selected="selected"' : ''; + $sel = in_array($optgroup_key, $selected) ? ' selected="selected"' : ''; $form .= '<option value="'.$optgroup_key.'"'.$sel.'>'.(string) $optgroup_val."</option>\n"; } - $form .= '</optgroup>'."\n"; + $form .= "</optgroup>\n"; } else { @@ -375,9 +352,7 @@ if ( ! function_exists('form_dropdown')) } } - $form .= "</select>\n"; - - return $form; + return $form."</select>\n"; } } @@ -386,7 +361,6 @@ if ( ! function_exists('form_dropdown')) /** * Checkbox Field * - * @access public * @param mixed * @param string * @param bool @@ -397,9 +371,9 @@ if ( ! function_exists('form_checkbox')) { function form_checkbox($data = '', $value = '', $checked = FALSE, $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)) + if (is_array($data) && array_key_exists('checked', $data)) { $checked = $data['checked']; @@ -431,7 +405,6 @@ if ( ! function_exists('form_checkbox')) /** * Radio Button * - * @access public * @param mixed * @param string * @param bool @@ -457,7 +430,6 @@ if ( ! function_exists('form_radio')) /** * Submit Button * - * @access public * @param mixed * @param string * @param string @@ -467,7 +439,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 '<input '._parse_form_attributes($data, $defaults).$extra." />\n"; } } @@ -477,7 +449,6 @@ if ( ! function_exists('form_submit')) /** * Reset Button * - * @access public * @param mixed * @param string * @param string @@ -487,7 +458,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 '<input '._parse_form_attributes($data, $defaults).$extra." />\n"; } } @@ -497,7 +468,6 @@ if ( ! function_exists('form_reset')) /** * Form Button * - * @access public * @param mixed * @param string * @param string @@ -507,8 +477,8 @@ if ( ! function_exists('form_button')) { function form_button($data = '', $content = '', $extra = '') { - $defaults = array('name' => (( ! is_array($data)) ? $data : ''), 'type' => 'button'); - if ( is_array($data) AND isset($data['content'])) + $defaults = array('name' => ( ! is_array($data) ? $data : ''), 'type' => 'button'); + if (is_array($data) && isset($data['content'])) { $content = $data['content']; unset($data['content']); // content is not an attribute @@ -523,7 +493,6 @@ if ( ! function_exists('form_button')) /** * Form Label Tag * - * @access public * @param string The text to appear onscreen * @param string The id the label applies to * @param string Additional attributes @@ -538,10 +507,10 @@ if ( ! function_exists('form_label')) if ($id != '') { - $label .= " for=\"$id\""; + $label .= ' for="'.$id.'"'; } - if (is_array($attributes) AND count($attributes) > 0) + if (is_array($attributes) && count($attributes) > 0) { foreach ($attributes as $key => $val) { @@ -549,7 +518,7 @@ if ( ! function_exists('form_label')) } } - return $label .= ">$label_text</label>"; + return $label.'>'.$label_text.'</label>'; } } @@ -560,7 +529,6 @@ if ( ! function_exists('form_label')) * Used to produce <fieldset><legend>text</legend>. To close fieldset * use form_fieldset_close() * - * @access public * @param string The legend text * @param string Additional attributes * @return string @@ -572,7 +540,7 @@ if ( ! function_exists('form_fieldset')) $fieldset = '<fieldset'._attributes_to_string($attributes, FALSE).">\n"; if ($legend_text != '') { - $fieldset .= "<legend>$legend_text</legend>\n"; + return $fieldset.'<legend>'.$legend_text."</legend>\n"; } return $fieldset; @@ -584,7 +552,6 @@ if ( ! function_exists('form_fieldset')) /** * Fieldset Close Tag * - * @access public * @param string * @return string */ @@ -592,7 +559,7 @@ if ( ! function_exists('form_fieldset_close')) { function form_fieldset_close($extra = '') { - return "</fieldset>".$extra; + return '</fieldset>'.$extra; } } @@ -601,7 +568,6 @@ if ( ! function_exists('form_fieldset_close')) /** * Form Close Tag * - * @access public * @param string * @return string */ @@ -609,7 +575,7 @@ if ( ! function_exists('form_close')) { function form_close($extra = '') { - return "</form>".$extra; + return '</form>'.$extra; } } @@ -620,7 +586,6 @@ if ( ! function_exists('form_close')) * * 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 */ @@ -670,10 +635,9 @@ 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 * @param string * @return mixed */ @@ -703,7 +667,6 @@ if ( ! function_exists('set_value')) * Let's you set the selected value of a <select> menu via data in the POST array. * If Form Validation is active it retrieves the info from the validation class * - * @access public * @param string * @param string * @param bool @@ -719,7 +682,7 @@ if ( ! function_exists('set_select')) { if ( ! isset($_POST[$field])) { - if (count($_POST) === 0 AND $default == TRUE) + if (count($_POST) === 0 && $default == TRUE) { return ' selected="selected"'; } @@ -735,12 +698,9 @@ if ( ! function_exists('set_select')) return ''; } } - else + elseif (($field == '' OR $value == '') OR ($field != $value)) { - if (($field == '' OR $value == '') OR ($field != $value)) - { - return ''; - } + return ''; } return ' selected="selected"'; @@ -758,7 +718,6 @@ if ( ! function_exists('set_select')) * Let's you set the selected value of a checkbox via the value in the POST array. * If Form Validation is active it retrieves the info from the validation class * - * @access public * @param string * @param string * @param bool @@ -774,7 +733,7 @@ if ( ! function_exists('set_checkbox')) { if ( ! isset($_POST[$field])) { - if (count($_POST) === 0 AND $default == TRUE) + if (count($_POST) === 0 && $default == TRUE) { return ' checked="checked"'; } @@ -790,12 +749,9 @@ if ( ! function_exists('set_checkbox')) return ''; } } - else + elseif (($field == '' OR $value == '') OR ($field != $value)) { - if (($field == '' OR $value == '') OR ($field != $value)) - { - return ''; - } + return ''; } return ' checked="checked"'; @@ -813,7 +769,6 @@ if ( ! function_exists('set_checkbox')) * Let's you set the selected value of a radio field via info in the POST array. * If Form Validation is active it retrieves the info from the validation class * - * @access public * @param string * @param string * @param bool @@ -829,7 +784,7 @@ if ( ! function_exists('set_radio')) { if ( ! isset($_POST[$field])) { - if (count($_POST) === 0 AND $default == TRUE) + if (count($_POST) === 0 && $default == TRUE) { return ' checked="checked"'; } @@ -865,10 +820,9 @@ 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 * @param string * @param string * @param string @@ -892,10 +846,9 @@ 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 * @param string * @param string * @return string @@ -920,7 +873,6 @@ if ( ! function_exists('validation_errors')) * * Helper function used by some of the form helpers * - * @access private * @param array * @param array * @return string @@ -955,7 +907,7 @@ if ( ! function_exists('_parse_form_attributes')) $val = form_prep($val, $default['name']); } - $att .= $key . '="' . $val . '" '; + $att .= $key.'="'.$val.'" '; } return $att; @@ -969,7 +921,6 @@ if ( ! function_exists('_parse_form_attributes')) * * Helper function used by some of the form helpers * - * @access private * @param mixed * @param bool * @return string @@ -978,14 +929,14 @@ if ( ! function_exists('_attributes_to_string')) { function _attributes_to_string($attributes, $formtag = FALSE) { - if (is_string($attributes) AND strlen($attributes) > 0) + if (is_string($attributes) && strlen($attributes) > 0) { - if ($formtag == TRUE AND strpos($attributes, 'method=') === FALSE) + if ($formtag == TRUE && strpos($attributes, 'method=') === FALSE) { $attributes .= ' method="post"'; } - if ($formtag == TRUE AND strpos($attributes, 'accept-charset=') === FALSE) + if ($formtag == TRUE && strpos($attributes, 'accept-charset=') === FALSE) { $attributes .= ' accept-charset="'.strtolower(config_item('charset')).'"'; } @@ -993,21 +944,21 @@ if ( ! function_exists('_attributes_to_string')) return ' '.$attributes; } - if (is_object($attributes) AND count($attributes) > 0) + if (is_object($attributes) && count($attributes) > 0) { - $attributes = (array)$attributes; + $attributes = (array) $attributes; } - if (is_array($attributes) AND ($formtag === TRUE OR count($attributes) > 0)) + if (is_array($attributes) && ($formtag === TRUE OR count($attributes) > 0)) { $atts = ''; - if ( ! isset($attributes['method']) AND $formtag === TRUE) + if ( ! isset($attributes['method']) && $formtag === TRUE) { $atts .= ' method="post"'; } - if ( ! isset($attributes['accept-charset']) AND $formtag === TRUE) + if ( ! isset($attributes['accept-charset']) && $formtag === TRUE) { $atts .= ' accept-charset="'.strtolower(config_item('charset')).'"'; } @@ -1030,7 +981,6 @@ if ( ! function_exists('_attributes_to_string')) * Determines what the form validation class was instantiated as, fetches * the object and returns it. * - * @access private * @return mixed */ if ( ! function_exists('_get_validation_object')) @@ -1057,4 +1007,4 @@ if ( ! function_exists('_get_validation_object')) } /* End of file form_helper.php */ -/* Location: ./system/helpers/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 b8c4f36f6..0417bd253 100644 --- a/system/helpers/html_helper.php +++ b/system/helpers/html_helper.php @@ -25,8 +25,6 @@ * @filesource */ -// ------------------------------------------------------------------------ - /** * CodeIgniter HTML Helpers * @@ -42,12 +40,10 @@ /** * Heading * - * Generates an HTML heading tag. First param is the data. - * Second param is the size of the heading tag. + * Generates an HTML heading tag. * - * @access public - * @param string - * @param integer + * @param string content + * @param int heading level * @return string */ if ( ! function_exists('heading')) @@ -65,7 +61,6 @@ if ( ! function_exists('heading')) * * Generates an HTML unordered list from an single or multi-dimensional array. * - * @access public * @param array * @param mixed * @return string @@ -85,7 +80,6 @@ if ( ! function_exists('ul')) * * Generates an HTML ordered list from an single or multi-dimensional array. * - * @access public * @param array * @param mixed * @return string @@ -105,11 +99,10 @@ if ( ! function_exists('ol')) * * Generates an HTML ordered list from an single or multi-dimensional array. * - * @access private * @param string * @param mixed * @param mixed - * @param integer + * @param int * @return string */ if ( ! function_exists('_list')) @@ -131,13 +124,13 @@ if ( ! function_exists('_list')) $atts = ''; foreach ($attributes as $key => $val) { - $atts .= ' ' . $key . '="' . $val . '"'; + $atts .= ' '.$key.'="'.$val.'"'; } $attributes = $atts; } - elseif (is_string($attributes) AND strlen($attributes) > 0) + elseif (is_string($attributes) && strlen($attributes) > 0) { - $attributes = ' '. $attributes; + $attributes = ' '.$attributes; } // Write the opening list tag @@ -175,8 +168,7 @@ if ( ! function_exists('_list')) /** * Generates HTML BR tags based on number supplied * - * @access public - * @param integer + * @param int * @return string */ if ( ! function_exists('br')) @@ -194,8 +186,8 @@ if ( ! function_exists('br')) * * Generates an <img /> element * - * @access public * @param mixed + * @param bool * @return string */ if ( ! function_exists('img')) @@ -217,7 +209,7 @@ if ( ! function_exists('img')) foreach ($src as $k => $v) { - if ($k === 'src' AND strpos($v, '://') === FALSE) + if ($k === 'src' && strpos($v, '://') === FALSE) { $CI =& get_instance(); @@ -232,7 +224,7 @@ if ( ! function_exists('img')) } else { - $img .= " $k=\"$v\""; + $img .= ' '.$k.'="'.$v.'"'; } } @@ -248,10 +240,9 @@ 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 * @param string type The doctype to be generated * @return string */ @@ -263,7 +254,7 @@ if ( ! function_exists('doctype')) if ( ! is_array($_doctypes)) { - if (defined('ENVIRONMENT') AND is_file(APPPATH.'config/'.ENVIRONMENT.'/doctypes.php')) + if (defined('ENVIRONMENT') && is_file(APPPATH.'config/'.ENVIRONMENT.'/doctypes.php')) { include(APPPATH.'config/'.ENVIRONMENT.'/doctypes.php'); } @@ -278,7 +269,7 @@ if ( ! function_exists('doctype')) } } - return (isset($_doctypes[$type])) ? $_doctypes[$type] : FALSE; + return isset($_doctypes[$type]) ? $_doctypes[$type] : FALSE; } } @@ -289,13 +280,12 @@ if ( ! function_exists('doctype')) * * Generates link to a CSS file * - * @access public * @param mixed stylesheet hrefs or an array * @param string rel * @param string type * @param string title * @param string media - * @param boolean should index_page be added to the css path + * @param bool should index_page be added to the css path * @return string */ if ( ! function_exists('link_tag')) @@ -309,7 +299,7 @@ if ( ! function_exists('link_tag')) { foreach ($href as $k => $v) { - if ($k === 'href' AND strpos($v, '://') === FALSE) + if ($k === 'href' && strpos($v, '://') === FALSE) { if ($index_page === TRUE) { @@ -322,11 +312,9 @@ if ( ! function_exists('link_tag')) } else { - $link .= "$k=\"$v\" "; + $link .= $k.'="'.$v.'" '; } } - - $link .= '/>'; } else { @@ -354,11 +342,9 @@ if ( ! function_exists('link_tag')) { $link .= 'title="'.$title.'" '; } - - $link .= '/>'; } - return $link."\n"; + return $link."/>\n"; } } @@ -367,8 +353,10 @@ if ( ! function_exists('link_tag')) /** * Generates meta tags from an array of key/values * - * @access public * @param array + * @param string + * @param string + * @param string * @return string */ if ( ! function_exists('meta')) @@ -381,13 +369,10 @@ if ( ! function_exists('meta')) { $name = array(array('name' => $name, 'content' => $content, 'type' => $type, 'newline' => $newline)); } - else + elseif (isset($name['name'])) { // Turn single array into multidimensional - if (isset($name['name'])) - { - $name = array($name); - } + $name = array($name); } $str = ''; @@ -410,8 +395,7 @@ if ( ! function_exists('meta')) /** * Generates non-breaking space entities based on number supplied * - * @access public - * @param integer + * @param int * @return string */ if ( ! function_exists('nbs')) @@ -423,4 +407,4 @@ if ( ! function_exists('nbs')) } /* End of file html_helper.php */ -/* Location: ./system/helpers/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 485806b20..feeaf57d7 100644 --- a/system/helpers/inflector_helper.php +++ b/system/helpers/inflector_helper.php @@ -199,8 +199,8 @@ if ( ! function_exists('underscore')) * * Takes multiple words separated by the separator and changes them to spaces * - * @param string $str - * @param string $separator + * @param string $str + * @param string $separator * @return str */ if ( ! function_exists('humanize')) @@ -214,19 +214,21 @@ if ( ! function_exists('humanize')) /** * Checks if the given word has a plural version. * - * @param string the word to check - * @return bool if the word is countable + * @param string the word to check + * @return bool if the word is countable */ if ( ! function_exists('is_countable')) { function is_countable($word) { - return ! (in_array(strtolower(strval($word)), array( - 'equipment', 'information', 'rice', 'money', - 'species', 'series', 'fish', 'meta' - ))); + return ! in_array(strtolower(strval($word)), + array( + 'equipment', 'information', 'rice', 'money', + 'species', 'series', 'fish', 'meta' + ) + ); } } /* End of file inflector_helper.php */ -/* Location: ./system/helpers/inflector_helper.php */ +/* Location: ./system/helpers/inflector_helper.php */
\ No newline at end of file diff --git a/system/helpers/language_helper.php b/system/helpers/language_helper.php index 1d66df59f..b31c97107 100644 --- a/system/helpers/language_helper.php +++ b/system/helpers/language_helper.php @@ -25,8 +25,6 @@ * @filesource */ -// ------------------------------------------------------------------------ - /** * CodeIgniter Language Helpers * @@ -44,7 +42,6 @@ * * Fetches a language variable and optionally outputs a form label * - * @access public * @param string the language line * @param string the id of the form element * @return string @@ -58,7 +55,7 @@ if ( ! function_exists('lang')) if ($id != '') { - $line = '<label for="'.$id.'">'.$line."</label>"; + $line = '<label for="'.$id.'">'.$line.'</label>'; } return $line; @@ -66,4 +63,4 @@ if ( ! function_exists('lang')) } /* End of file language_helper.php */ -/* Location: ./system/helpers/language_helper.php */ +/* Location: ./system/helpers/language_helper.php */
\ No newline at end of file diff --git a/system/helpers/number_helper.php b/system/helpers/number_helper.php index b6c823d8b..40da6e7bf 100644 --- a/system/helpers/number_helper.php +++ b/system/helpers/number_helper.php @@ -25,8 +25,6 @@ * @filesource */ -// ------------------------------------------------------------------------ - /** * CodeIgniter Number Helpers * @@ -42,7 +40,6 @@ /** * Formats a numbers as bytes, based on size, and adds the appropriate suffix * - * @access public * @param mixed // will be cast as int * @return string */ @@ -84,4 +81,4 @@ if ( ! function_exists('byte_format')) } /* End of file number_helper.php */ -/* Location: ./system/helpers/number_helper.php */ +/* Location: ./system/helpers/number_helper.php */
\ No newline at end of file diff --git a/system/helpers/path_helper.php b/system/helpers/path_helper.php index c31f0bdc5..6ee99072c 100644 --- a/system/helpers/path_helper.php +++ b/system/helpers/path_helper.php @@ -40,7 +40,6 @@ /** * Set Realpath * - * @access public * @param string * @param bool checks to see if the path exists * @return string @@ -71,4 +70,4 @@ if ( ! function_exists('set_realpath')) } /* End of file path_helper.php */ -/* Location: ./system/helpers/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 8c7adea46..d6f134c9f 100644 --- a/system/helpers/security_helper.php +++ b/system/helpers/security_helper.php @@ -124,4 +124,4 @@ if ( ! function_exists('encode_php_tags')) } /* End of file security_helper.php */ -/* Location: ./system/helpers/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 cc903bc1c..8dba74e73 100644 --- a/system/helpers/smiley_helper.php +++ b/system/helpers/smiley_helper.php @@ -1,13 +1,13 @@ -<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed'); +<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed'); /** * CodeIgniter * * An open source application development framework for PHP 5.2.4 or newer * * NOTICE OF LICENSE - * + * * Licensed under the Open Software License version 3.0 - * + * * This source file is subject to the Open Software License (OSL 3.0) that is * bundled with this package in the files license.txt / license.rst. It is * also available through the world wide web at this URL: @@ -25,8 +25,6 @@ * @filesource */ -// ------------------------------------------------------------------------ - /** * CodeIgniter Smiley Helpers * @@ -45,7 +43,6 @@ * 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 mixed alias name or array of alias->field_id pairs * @param string field_id if alias name was passed in * @return array @@ -139,7 +136,6 @@ EOF; * 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 */ @@ -193,7 +189,6 @@ if ( ! function_exists('get_clickable_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 @@ -234,14 +229,13 @@ if ( ! function_exists('parse_smileys')) * * Fetches the config/smiley.php file * - * @access private * @return mixed */ if ( ! function_exists('_get_smiley_array')) { function _get_smiley_array() { - if (defined('ENVIRONMENT') AND file_exists(APPPATH.'config/'.ENVIRONMENT.'/smileys.php')) + if (defined('ENVIRONMENT') && file_exists(APPPATH.'config/'.ENVIRONMENT.'/smileys.php')) { include(APPPATH.'config/'.ENVIRONMENT.'/smileys.php'); } @@ -249,8 +243,8 @@ if ( ! function_exists('_get_smiley_array')) { include(APPPATH.'config/smileys.php'); } - - if (isset($smileys) AND is_array($smileys)) + + if (isset($smileys) && is_array($smileys)) { return $smileys; } @@ -268,7 +262,6 @@ if ( ! function_exists('_get_smiley_array')) * * DEPRECATED as of version 1.7.2, use smiley_js instead * - * @access public * @param string form name * @param string field name * @return string @@ -288,6 +281,5 @@ EOF; } } - /* End of file smiley_helper.php */ /* Location: ./system/helpers/smiley_helper.php */
\ No newline at end of file diff --git a/system/helpers/string_helper.php b/system/helpers/string_helper.php index 607a12bcb..aed35c157 100644 --- a/system/helpers/string_helper.php +++ b/system/helpers/string_helper.php @@ -1,13 +1,13 @@ -<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed'); +<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed'); /** * CodeIgniter * * An open source application development framework for PHP 5.2.4 or newer * * NOTICE OF LICENSE - * + * * Licensed under the Open Software License version 3.0 - * + * * This source file is subject to the Open Software License (OSL 3.0) that is * bundled with this package in the files license.txt / license.rst. It is * also available through the world wide web at this URL: @@ -25,8 +25,6 @@ * @filesource */ -// ------------------------------------------------------------------------ - /** * CodeIgniter String Helpers * @@ -50,7 +48,6 @@ * * this/that/theother * - * @access public * @param string * @return string */ @@ -69,7 +66,6 @@ if ( ! function_exists('trim_slashes')) * * Removes slashes contained in a string or in an array * - * @access public * @param mixed string or array * @return mixed string or array */ @@ -100,7 +96,6 @@ if ( ! function_exists('strip_slashes')) * * Removes single and double quotes from a string * - * @access public * @param string * @return string */ @@ -119,7 +114,6 @@ if ( ! function_exists('strip_quotes')) * * Converts single and double quotes to entities * - * @access public * @param string * @return string */ @@ -145,7 +139,6 @@ if ( ! function_exists('quotes_to_entities')) * * http://www.some-site.com/index.php * - * @access public * @param string * @return string */ @@ -153,7 +146,7 @@ if ( ! function_exists('reduce_double_slashes')) { function reduce_double_slashes($str) { - return preg_replace("#(^|[^:])//+#", "\\1/", $str); + return preg_replace('#(^|[^:])//+#', '\\1/', $str); } } @@ -170,7 +163,6 @@ if ( ! function_exists('reduce_double_slashes')) * * 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 @@ -184,7 +176,7 @@ if ( ! function_exists('reduce_multiples')) if ($trim === TRUE) { - $str = trim($str, $character); + return trim($str, $character); } return $str; @@ -198,9 +190,8 @@ if ( ! function_exists('reduce_multiples')) * * Useful for generating passwords or hashes. * - * @access public * @param string type of random string. basic, alpha, alunum, numeric, nozero, unique, md5, encrypt and sha1 - * @param integer number of characters + * @param int number of characters * @return string */ if ( ! function_exists('random_string')) @@ -227,9 +218,9 @@ if ( ! function_exists('random_string')) case 'nozero' : $pool = '123456789'; break; } - + $str = substr(str_shuffle(str_repeat($pool, ceil($len/strlen($pool)))),0,$len); - + return $str; break; case 'unique' : @@ -254,16 +245,19 @@ if ( ! function_exists('random_string')) /** * Add's _1 to a string or increment the ending number to allow _2, _3, etc * - * @param string $str required - * @param string $separator What should the duplicate number be appended with - * @param string $first Which number should be used for the first dupe increment - * @return string + * @param string required + * @param string What should the duplicate number be appended with + * @param string Which number should be used for the first dupe increment + * @return string */ -function increment_string($str, $separator = '_', $first = 1) +if ( ! function_exists('increment_string')) { - preg_match('/(.+)'.$separator.'([0-9]+)$/', $str, $match); + function increment_string($str, $separator = '_', $first = 1) + { + preg_match('/(.+)'.$separator.'([0-9]+)$/', $str, $match); - return isset($match[2]) ? $match[1].$separator.($match[2] + 1) : $str.$separator.$first; + return isset($match[2]) ? $match[1].$separator.($match[2] + 1) : $str.$separator.$first; + } } // ------------------------------------------------------------------------ @@ -271,9 +265,8 @@ function increment_string($str, $separator = '_', $first = 1) /** * Alternator * - * Allows strings to be alternated. See docs... + * Allows strings to be alternated. See docs... * - * @access public * @param string (as many parameters as needed) * @return string */ @@ -298,19 +291,17 @@ if ( ! function_exists('alternator')) /** * Repeater function * - * @access public * @param string - * @param integer number of repeats + * @param int number of repeats * @return string */ if ( ! function_exists('repeater')) { function repeater($data, $num = 1) { - return (($num > 0) ? str_repeat($data, $num) : ''); + 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 7591bac5f..cc501c334 100644 --- a/system/helpers/text_helper.php +++ b/system/helpers/text_helper.php @@ -1,13 +1,13 @@ -<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed'); +<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed'); /** * CodeIgniter * * An open source application development framework for PHP 5.2.4 or newer * * NOTICE OF LICENSE - * + * * Licensed under the Open Software License version 3.0 - * + * * This source file is subject to the Open Software License (OSL 3.0) that is * bundled with this package in the files license.txt / license.rst. It is * also available through the world wide web at this URL: @@ -25,8 +25,6 @@ * @filesource */ -// ------------------------------------------------------------------------ - /** * CodeIgniter Text Helpers * @@ -44,9 +42,8 @@ * * Limits a string to X number of words. * - * @access public * @param string - * @param integer + * @param int * @param string the end character. Usually an ellipsis * @return string */ @@ -78,9 +75,8 @@ if ( ! function_exists('word_limiter')) * Limits the string based on the character count. Preserves complete words * so the character count may not be exactly as specified. * - * @access public * @param string - * @param integer + * @param int * @param string the end character. Usually an ellipsis * @return string */ @@ -121,7 +117,6 @@ if ( ! function_exists('character_limiter')) * * Converts High ascii text and MS Word special characters to character entities * - * @access public * @param string * @return string */ @@ -182,7 +177,6 @@ if ( ! function_exists('ascii_to_entities')) * * Converts character entities back to ASCII * - * @access public * @param string * @param bool * @return string @@ -240,7 +234,6 @@ if ( ! function_exists('entities_to_ascii')) * 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 @@ -286,7 +279,6 @@ if ( ! function_exists('word_censor')) * * Colorizes code strings * - * @access public * @param string the text string * @return string */ @@ -330,7 +322,6 @@ if ( ! function_exists('highlight_code')) * * 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 @@ -360,7 +351,6 @@ if ( ! function_exists('highlight_phrase')) /** * Convert Accented Foreign Characters to ASCII * - * @access public * @param string the text string * @return string */ @@ -368,7 +358,7 @@ if ( ! function_exists('convert_accented_characters')) { function convert_accented_characters($str) { - if (defined('ENVIRONMENT') AND is_file(APPPATH.'config/'.ENVIRONMENT.'/foreign_chars.php')) + if (defined('ENVIRONMENT') && is_file(APPPATH.'config/'.ENVIRONMENT.'/foreign_chars.php')) { include(APPPATH.'config/'.ENVIRONMENT.'/foreign_chars.php'); } @@ -395,9 +385,8 @@ if ( ! function_exists('convert_accented_characters')) * 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 + * @param int the number of characters to wrap at * @return string */ if ( ! function_exists('word_wrap')) @@ -497,11 +486,11 @@ if ( ! function_exists('word_wrap')) * * 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 + * @param string string to ellipsize + * @param int max length of string + * @param mixed int (1|0) or float, .5, .2, etc for position to split + * @param string ellipsis ; Default '...' + * @return string ellipsized string */ if ( ! function_exists('ellipsize')) { @@ -534,4 +523,4 @@ if ( ! function_exists('ellipsize')) } /* End of file text_helper.php */ -/* Location: ./system/helpers/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 9b19c7c2d..7a3db5d6b 100644 --- a/system/helpers/typography_helper.php +++ b/system/helpers/typography_helper.php @@ -25,8 +25,6 @@ * @filesource */ -// ------------------------------------------------------------------------ - /** * CodeIgniter Typography Helpers * @@ -42,7 +40,6 @@ /** * Convert newlines to HTML line breaks except within PRE tags * - * @access public * @param string * @return string */ @@ -61,8 +58,6 @@ if ( ! function_exists('nl2br_except_pre')) /** * Auto Typography Wrapper Function * - * - * @access public * @param string * @param bool whether to allow javascript event handlers * @param bool whether to reduce multiple instances of double newlines to two @@ -86,7 +81,6 @@ if ( ! function_exists('auto_typography')) * * This function is a replacement for html_entity_decode() * - * @access public * @param string * @param string * @return string @@ -101,4 +95,4 @@ if ( ! function_exists('entity_decode')) } /* End of file typography_helper.php */ -/* Location: ./system/helpers/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 2ae1fd37b..5576c2748 100644 --- a/system/helpers/url_helper.php +++ b/system/helpers/url_helper.php @@ -25,8 +25,6 @@ * @filesource */ -// ------------------------------------------------------------------------ - /** * CodeIgniter URL Helpers * @@ -45,7 +43,6 @@ * Create a local URL based on your basepath. Segments can be passed via the * first parameter either as a string or an array. * - * @access public * @param string * @return string */ @@ -67,8 +64,7 @@ if ( ! function_exists('site_url')) * Segments can be passed in as a string or an array, same as site_url * or a URL to a file can be passed in, e.g. to an image file. * - * @access public - * @param string + * @param string * @return string */ if ( ! function_exists('base_url')) @@ -88,7 +84,6 @@ if ( ! function_exists('base_url')) * Returns the full URL (including segments) of the page where this * function is placed * - * @access public * @return string */ if ( ! function_exists('current_url')) @@ -106,7 +101,6 @@ if ( ! function_exists('current_url')) * * Returns the URI segments. * - * @access public * @return string */ if ( ! function_exists('uri_string')) @@ -125,7 +119,6 @@ if ( ! function_exists('uri_string')) * * Returns the "index_page" from your config file * - * @access public * @return string */ if ( ! function_exists('index_page')) @@ -144,7 +137,6 @@ if ( ! function_exists('index_page')) * * Creates an anchor based on the local URL. * - * @access public * @param string the URL * @param string the link title * @param mixed any attributes @@ -158,7 +150,7 @@ if ( ! function_exists('anchor')) if ( ! is_array($uri)) { - $site_url = ( ! preg_match('!^\w+://! i', $uri)) ? site_url($uri) : $uri; + $site_url = preg_match('!^\w+://! i', $uri) ? $uri : site_url($uri); } else { @@ -187,7 +179,6 @@ if ( ! function_exists('anchor')) * 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 @@ -198,7 +189,7 @@ 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) ? $uri : site_url($uri); if ($title == '') { @@ -207,7 +198,7 @@ if ( ! function_exists('anchor_popup')) if ($attributes === FALSE) { - return "<a href='javascript:void(0);' onclick=\"window.open('".$site_url."', '_blank');\">".$title."</a>"; + return "<a href='javascript:void(0);' onclick=\"window.open('".$site_url."', '_blank');\">".$title.'</a>'; } if ( ! is_array($attributes)) @@ -217,7 +208,7 @@ if ( ! function_exists('anchor_popup')) 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]) ? $attributes[$key] : $val; unset($attributes[$key]); } @@ -226,7 +217,7 @@ if ( ! function_exists('anchor_popup')) $attributes = _parse_attributes($attributes); } - return "<a href='javascript:void(0);' onclick=\"window.open('".$site_url."', '_blank', '"._parse_attributes($atts, TRUE)."');\"$attributes>".$title."</a>"; + return "<a href='javascript:void(0);' onclick=\"window.open('".$site_url."', '_blank', '"._parse_attributes($atts, TRUE)."');\"".$attributes.'>'.$title.'</a>'; } } @@ -235,7 +226,6 @@ if ( ! function_exists('anchor_popup')) /** * Mailto Link * - * @access public * @param string the email address * @param string the link title * @param mixed any attributes @@ -263,7 +253,6 @@ if ( ! function_exists('mailto')) * * 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 @@ -373,10 +362,9 @@ 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 * @param string the string * @param string the type: email, url, or both * @param bool whether to create pop-up links @@ -440,7 +428,6 @@ if ( ! function_exists('auto_link')) * * Simply adds the http:// part if no scheme is included * - * @access public * @param string the URL * @return string */ @@ -470,12 +457,12 @@ if ( ! function_exists('prep_url')) * Create URL Title * * Takes a "title" string as input and creates a - * human-friendly URL string with a "separator" string + * human-friendly URL string with a "separator" string * as the word separator. * - * @access public * @param string the string * @param string the separator + * @param bool * @return string */ if ( ! function_exists('url_title')) @@ -484,21 +471,21 @@ if ( ! function_exists('url_title')) { if ($separator === 'dash') { - $separator = '-'; + $separator = '-'; } - else if ($separator == 'underscore') + elseif ($separator === 'underscore') { - $separator = '_'; + $separator = '_'; } - + $q_separator = preg_quote($separator); $trans = array( - '&.+?;' => '', - '[^a-z0-9 _-]' => '', - '\s+' => $separator, - '('.$q_separator.')+' => $separator - ); + '&.+?;' => '', + '[^a-z0-9 _-]' => '', + '\s+' => $separator, + '('.$q_separator.')+' => $separator + ); $str = strip_tags($str); foreach ($trans as $key => $val) @@ -524,7 +511,6 @@ if ( ! function_exists('url_title')) * 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 refresh * @return string @@ -564,7 +550,6 @@ if ( ! function_exists('redirect')) * * Some of the functions use this * - * @access private * @param array * @param bool * @return string @@ -583,15 +568,15 @@ if ( ! function_exists('_parse_attributes')) { if ($javascript == TRUE) { - $att .= $key . '=' . $val . ','; + $att .= $key.'='.$val.','; } else { - $att .= ' ' . $key . '="' . $val . '"'; + $att .= ' '.$key.'="'.$val.'"'; } } - if ($javascript == TRUE AND $att != '') + if ($javascript == TRUE && $att != '') { return substr($att, 0, -1); } @@ -601,4 +586,4 @@ if ( ! function_exists('_parse_attributes')) } /* End of file url_helper.php */ -/* Location: ./system/helpers/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 f3ff5764c..67fd34b97 100644 --- a/system/helpers/xml_helper.php +++ b/system/helpers/xml_helper.php @@ -25,8 +25,6 @@ * @filesource */ -// ------------------------------------------------------------------------ - /** * CodeIgniter XML Helpers * @@ -42,8 +40,8 @@ /** * Convert Reserved XML characters to Entities * - * @access public * @param string + * @param bool * @return string */ if ( ! function_exists('xml_convert')) @@ -54,11 +52,11 @@ if ( ! function_exists('xml_convert')) // Replace entities to temporary markers so that // ampersands won't get messed up - $str = preg_replace("/&#(\d+);/", "$temp\\1;", $str); + $str = preg_replace('/&#(\d+);/', $temp.'\\1;', $str); if ($protect_all == TRUE) { - $str = preg_replace('/&(\w+);/', "$temp\\1;", $str); + $str = preg_replace('/&(\w+);/', $temp.'\\1;', $str); } $str = str_replace(array('&', '<', '>', '"', "'", '-'), @@ -66,11 +64,11 @@ if ( ! function_exists('xml_convert')) $str); // Decode the temp markers back to entities - $str = preg_replace('/$temp(\d+);/', '&#\\1;', $str); + $str = preg_replace('/'.$temp.'(\d+);/', '&#\\1;', $str); if ($protect_all == TRUE) { - return preg_replace("/$temp(\w+);/", '&\\1;', $str); + return preg_replace('/'.$temp.'(\w+);/', '&\\1;', $str); } return $str; @@ -78,4 +76,4 @@ if ( ! function_exists('xml_convert')) } /* End of file xml_helper.php */ -/* Location: ./system/helpers/xml_helper.php */ +/* Location: ./system/helpers/xml_helper.php */
\ No newline at end of file diff --git a/system/libraries/Cache/Cache.php b/system/libraries/Cache/Cache.php index 7642a5270..f98241617 100644 --- a/system/libraries/Cache/Cache.php +++ b/system/libraries/Cache/Cache.php @@ -25,8 +25,6 @@ * @filesource */ -// ------------------------------------------------------------------------ - /** * CodeIgniter Caching Class * @@ -50,11 +48,37 @@ class CI_Cache extends CI_Driver_Library { protected $_adapter = 'dummy'; protected $_backup_driver; + /** + * Constructor + * + * Initialize class properties based on the configuration array. + * + * @param array + * @return void + */ public function __construct($config = array()) { - if ( ! empty($config)) + $default_config = array( + 'adapter', + 'memcached' + ); + + foreach ($default_config as $key) { - $this->_initialize($config); + if (isset($config[$key])) + { + $param = '_'.$key; + + $this->{$param} = $config[$key]; + } + } + + if (isset($config['backup'])) + { + if (in_array('cache_'.$config['backup'], $this->valid_drivers)) + { + $this->_backup_driver = $config['backup']; + } } } @@ -63,11 +87,11 @@ class CI_Cache extends CI_Driver_Library { /** * 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 - * @return mixed value that is stored/FALSE on failure + * @param string + * @return mixed value that is stored/FALSE on failure */ public function get($id) { @@ -79,11 +103,10 @@ class CI_Cache extends CI_Driver_Library { /** * Cache Save * - * @param string Unique Key - * @param mixed Data to store - * @param int Length of time (in seconds) to cache the data - * - * @return boolean true on success/false on failure + * @param string Unique Key + * @param mixed Data to store + * @param int Length of time (in seconds) to cache the data + * @return bool true on success/false on failure */ public function save($id, $data, $ttl = 60) { @@ -95,8 +118,8 @@ class CI_Cache extends CI_Driver_Library { /** * Delete from Cache * - * @param mixed unique identifier of the item in the cache - * @return boolean true on success/false on failure + * @param mixed unique identifier of the item in the cache + * @return bool true on success/false on failure */ public function delete($id) { @@ -108,7 +131,7 @@ class CI_Cache extends CI_Driver_Library { /** * Clean the cache * - * @return boolean false on failure/true on success + * @return bool false on failure/true on success */ public function clean() { @@ -120,8 +143,8 @@ class CI_Cache extends CI_Driver_Library { /** * Cache Info * - * @param string user/filehits - * @return mixed array on success, false on failure + * @param string user/filehits + * @return mixed array on success, false on failure */ public function cache_info($type = 'user') { @@ -133,8 +156,8 @@ class CI_Cache extends CI_Driver_Library { /** * Get Cache Metadata * - * @param mixed key to get cache metadata on - * @return mixed return value from child method + * @param mixed key to get cache metadata on + * @return mixed return value from child method */ public function get_metadata($id) { @@ -144,46 +167,10 @@ class CI_Cache extends CI_Driver_Library { // ------------------------------------------------------------------------ /** - * Initialize - * - * Initialize class properties based on the configuration array. - * - * @param array - * @return void - */ - private function _initialize($config) - { - $default_config = array( - 'adapter', - 'memcached' - ); - - foreach ($default_config as $key) - { - if (isset($config[$key])) - { - $param = '_'.$key; - - $this->{$param} = $config[$key]; - } - } - - if (isset($config['backup'])) - { - if (in_array('cache_'.$config['backup'], $this->valid_drivers)) - { - $this->_backup_driver = $config['backup']; - } - } - } - - // ------------------------------------------------------------------------ - - /** * Is the requested driver supported in this environment? * - * @param string The driver to test. - * @return array + * @param string The driver to test. + * @return array */ public function is_supported($driver) { @@ -202,8 +189,8 @@ class CI_Cache extends CI_Driver_Library { /** * __get() * - * @param child - * @return object + * @param child + * @return object */ public function __get($child) { @@ -217,9 +204,7 @@ class CI_Cache extends CI_Driver_Library { return $obj; } - // ------------------------------------------------------------------------ } -// End Class /* End of file Cache.php */ -/* Location: ./system/libraries/Cache/Cache.php */ +/* Location: ./system/libraries/Cache/Cache.php */
\ No newline at end of file diff --git a/system/libraries/Cache/drivers/Cache_apc.php b/system/libraries/Cache/drivers/Cache_apc.php index c387a30fc..59ab67533 100644 --- a/system/libraries/Cache/drivers/Cache_apc.php +++ b/system/libraries/Cache/drivers/Cache_apc.php @@ -25,8 +25,6 @@ * @filesource */ -// ------------------------------------------------------------------------ - /** * CodeIgniter APC Caching Class * @@ -36,23 +34,22 @@ * @author EllisLab Dev Team * @link */ - class CI_Cache_apc extends CI_Driver { /** * 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 - * @return mixed value that is stored/FALSE on failure + * @param string + * @return mixed value that is stored/FALSE on failure */ public function get($id) { $data = apc_fetch($id); - return (is_array($data)) ? $data[0] : FALSE; + return is_array($data) ? $data[0] : FALSE; } // ------------------------------------------------------------------------ @@ -60,11 +57,11 @@ class CI_Cache_apc extends CI_Driver { /** * Cache Save * - * @param string Unique Key - * @param mixed Data to store - * @param int Length of time (in seconds) to cache the data + * @param string Unique Key + * @param mixed Data to store + * @param int Length of time (in seconds) to cache the data * - * @return boolean true on success/false on failure + * @return bool true on success/false on failure */ public function save($id, $data, $ttl = 60) { @@ -77,8 +74,8 @@ class CI_Cache_apc extends CI_Driver { /** * Delete from Cache * - * @param mixed unique identifier of the item in the cache - * @param boolean true on success/false on failure + * @param mixed unique identifier of the item in the cache + * @param bool true on success/false on failure */ public function delete($id) { @@ -90,7 +87,7 @@ class CI_Cache_apc extends CI_Driver { /** * Clean the cache * - * @return boolean false on failure/true on success + * @return bool false on failure/true on success */ public function clean() { @@ -102,8 +99,8 @@ class CI_Cache_apc extends CI_Driver { /** * Cache Info * - * @param string user/filehits - * @return mixed array on success, false on failure + * @param string user/filehits + * @return mixed array on success, false on failure */ public function cache_info($type = NULL) { @@ -115,8 +112,8 @@ class CI_Cache_apc extends CI_Driver { /** * Get Cache Metadata * - * @param mixed key to get cache metadata on - * @return mixed array on success/false on failure + * @param mixed key to get cache metadata on + * @return mixed array on success/false on failure */ public function get_metadata($id) { @@ -142,10 +139,12 @@ class CI_Cache_apc extends CI_Driver { * is_supported() * * Check to see if APC is available on this system, bail if it isn't. + * + * @return bool */ public function is_supported() { - if ( ! extension_loaded('apc') OR ini_get('apc.enabled') != "1") + if ( ! extension_loaded('apc') OR ! (bool) @ini_get('apc.enabled')) { log_message('error', 'The APC PHP extension must be loaded to use APC Cache.'); return FALSE; @@ -154,11 +153,7 @@ class CI_Cache_apc extends CI_Driver { return TRUE; } - // ------------------------------------------------------------------------ - - } -// End Class /* End of file Cache_apc.php */ -/* Location: ./system/libraries/Cache/drivers/Cache_apc.php */ +/* Location: ./system/libraries/Cache/drivers/Cache_apc.php */
\ No newline at end of file diff --git a/system/libraries/Cache/drivers/Cache_dummy.php b/system/libraries/Cache/drivers/Cache_dummy.php index c9767e401..e8b791c5b 100644 --- a/system/libraries/Cache/drivers/Cache_dummy.php +++ b/system/libraries/Cache/drivers/Cache_dummy.php @@ -25,8 +25,6 @@ * @filesource */ -// ------------------------------------------------------------------------ - /** * CodeIgniter Dummy Caching Class * @@ -36,7 +34,6 @@ * @author EllisLab Dev Team * @link */ - class CI_Cache_dummy extends CI_Driver { /** @@ -44,8 +41,8 @@ class CI_Cache_dummy extends CI_Driver { * * Since this is the dummy class, it's always going to return FALSE. * - * @param string - * @return Boolean FALSE + * @param string + * @return bool FALSE */ public function get($id) { @@ -57,11 +54,10 @@ class CI_Cache_dummy extends CI_Driver { /** * Cache Save * - * @param string Unique Key - * @param mixed Data to store - * @param int Length of time (in seconds) to cache the data - * - * @return boolean TRUE, Simulating success + * @param string Unique Key + * @param mixed Data to store + * @param int Length of time (in seconds) to cache the data + * @return bool TRUE, Simulating success */ public function save($id, $data, $ttl = 60) { @@ -73,8 +69,8 @@ class CI_Cache_dummy extends CI_Driver { /** * Delete from Cache * - * @param mixed unique identifier of the item in the cache - * @param boolean TRUE, simulating success + * @param mixed unique identifier of the item in the cache + * @param bool TRUE, simulating success */ public function delete($id) { @@ -86,7 +82,7 @@ class CI_Cache_dummy extends CI_Driver { /** * Clean the cache * - * @return boolean TRUE, simulating success + * @return bool TRUE, simulating success */ public function clean() { @@ -98,8 +94,8 @@ class CI_Cache_dummy extends CI_Driver { /** * Cache Info * - * @param string user/filehits - * @return boolean FALSE + * @param string user/filehits + * @return bool FALSE */ public function cache_info($type = NULL) { @@ -111,8 +107,8 @@ class CI_Cache_dummy extends CI_Driver { /** * Get Cache Metadata * - * @param mixed key to get cache metadata on - * @return boolean FALSE + * @param mixed key to get cache metadata on + * @return bool FALSE */ public function get_metadata($id) { @@ -125,17 +121,14 @@ class CI_Cache_dummy extends CI_Driver { * Is this caching driver supported on the system? * Of course this one is. * - * @return TRUE; + * @return bool TRUE */ public function is_supported() { return TRUE; } - // ------------------------------------------------------------------------ - } -// End Class /* End of file Cache_dummy.php */ -/* Location: ./system/libraries/Cache/drivers/Cache_dummy.php */ +/* Location: ./system/libraries/Cache/drivers/Cache_dummy.php */
\ No newline at end of file diff --git a/system/libraries/Cache/drivers/Cache_file.php b/system/libraries/Cache/drivers/Cache_file.php index c0be0def4..dd27aa90e 100644 --- a/system/libraries/Cache/drivers/Cache_file.php +++ b/system/libraries/Cache/drivers/Cache_file.php @@ -25,8 +25,6 @@ * @filesource */ -// ------------------------------------------------------------------------ - /** * CodeIgniter Memcached Caching Class * @@ -36,14 +34,10 @@ * @author EllisLab Dev Team * @link */ - class CI_Cache_file extends CI_Driver { protected $_cache_path; - /** - * Constructor - */ public function __construct() { $CI =& get_instance(); @@ -57,8 +51,8 @@ class CI_Cache_file extends CI_Driver { /** * Fetch from cache * - * @param mixed unique key id - * @return mixed data on success/false on failure + * @param mixed unique key id + * @return mixed data on success/false on failure */ public function get($id) { @@ -83,11 +77,11 @@ class CI_Cache_file extends CI_Driver { /** * Save into cache * - * @param string unique key - * @param mixed data to store - * @param int length of time (in seconds) the cache is valid - * - Default is 60 seconds - * @return boolean true on success/false on failure + * @param string unique key + * @param mixed data to store + * @param int length of time (in seconds) the cache is valid + * - Default is 60 seconds + * @return bool true on success/false on failure */ public function save($id, $data, $ttl = 60) { @@ -111,12 +105,12 @@ class CI_Cache_file extends CI_Driver { /** * Delete from Cache * - * @param mixed unique identifier of item in cache - * @return boolean true on success/false on failure + * @param mixed unique identifier of item in cache + * @return bool true on success/false on failure */ public function delete($id) { - return (file_exists($this->_cache_path.$id)) ? unlink($this->_cache_path.$id) : FALSE; + return file_exists($this->_cache_path.$id) ? unlink($this->_cache_path.$id) : FALSE; } // ------------------------------------------------------------------------ @@ -124,7 +118,7 @@ class CI_Cache_file extends CI_Driver { /** * Clean the Cache * - * @return boolean false on failure/true on success + * @return bool false on failure/true on success */ public function clean() { @@ -138,8 +132,8 @@ class CI_Cache_file extends CI_Driver { * * Not supported by file-based caching * - * @param string user/filehits - * @return mixed FALSE + * @param string user/filehits + * @return mixed FALSE */ public function cache_info($type = NULL) { @@ -151,8 +145,8 @@ class CI_Cache_file extends CI_Driver { /** * Get Cache Metadata * - * @param mixed key to get cache metadata on - * @return mixed FALSE on failure, array on success. + * @param mixed key to get cache metadata on + * @return mixed FALSE on failure, array on success. */ public function get_metadata($id) { @@ -188,16 +182,14 @@ class CI_Cache_file extends CI_Driver { * * In the file driver, check to see that the cache directory is indeed writable * - * @return boolean + * @return bool */ public function is_supported() { return is_really_writable($this->_cache_path); } - // ------------------------------------------------------------------------ } -// End Class /* End of file Cache_file.php */ -/* Location: ./system/libraries/Cache/drivers/Cache_file.php */ +/* Location: ./system/libraries/Cache/drivers/Cache_file.php */
\ No newline at end of file diff --git a/system/libraries/Cache/drivers/Cache_memcached.php b/system/libraries/Cache/drivers/Cache_memcached.php index b8f2d7e4c..4cd5f3d6f 100644 --- a/system/libraries/Cache/drivers/Cache_memcached.php +++ b/system/libraries/Cache/drivers/Cache_memcached.php @@ -25,8 +25,6 @@ * @filesource */ -// ------------------------------------------------------------------------ - /** * CodeIgniter Memcached Caching Class * @@ -36,12 +34,11 @@ * @author EllisLab Dev Team * @link */ - class CI_Cache_memcached extends CI_Driver { - private $_memcached; // Holds the memcached object + protected $_memcached; // Holds the memcached object - protected $_memcache_conf = array( + protected $_memcache_conf = array( 'default' => array( 'default_host' => '127.0.0.1', 'default_port' => 11211, @@ -49,19 +46,17 @@ class CI_Cache_memcached extends CI_Driver { ) ); - // ------------------------------------------------------------------------ - /** * Fetch from cache * - * @param mixed unique key id - * @return mixed data on success/false on failure + * @param mixed unique key id + * @return mixed data on success/false on failure */ public function get($id) { $data = $this->_memcached->get($id); - return (is_array($data)) ? $data[0] : FALSE; + return is_array($data) ? $data[0] : FALSE; } // ------------------------------------------------------------------------ @@ -69,18 +64,18 @@ class CI_Cache_memcached extends CI_Driver { /** * Save * - * @param string unique identifier - * @param mixed data being cached - * @param int time to live - * @return boolean true on success, false on failure + * @param string unique identifier + * @param mixed data being cached + * @param int time to live + * @return bool true on success, false on failure */ public function save($id, $data, $ttl = 60) { - if (get_class($this->_memcached) == 'Memcached') + if (get_class($this->_memcached) === 'Memcached') { return $this->_memcached->set($id, array($data, time(), $ttl), $ttl); } - else if (get_class($this->_memcached) == 'Memcache') + elseif (get_class($this->_memcached) === 'Memcache') { return $this->_memcached->set($id, array($data, time(), $ttl), 0, $ttl); } @@ -93,8 +88,8 @@ class CI_Cache_memcached extends CI_Driver { /** * Delete from Cache * - * @param mixed key to be deleted. - * @return boolean true on success, false on failure + * @param mixed key to be deleted. + * @return bool true on success, false on failure */ public function delete($id) { @@ -106,7 +101,7 @@ class CI_Cache_memcached extends CI_Driver { /** * Clean the Cache * - * @return boolean false on failure/true on success + * @return bool false on failure/true on success */ public function clean() { @@ -118,10 +113,9 @@ class CI_Cache_memcached extends CI_Driver { /** * Cache Info * - * @param null type not supported in memcached - * @return mixed array on success, false on failure + * @return mixed array on success, false on failure */ - public function cache_info($type = NULL) + public function cache_info() { return $this->_memcached->getStats(); } @@ -131,8 +125,8 @@ class CI_Cache_memcached extends CI_Driver { /** * Get Cache Metadata * - * @param mixed key to get cache metadata on - * @return mixed FALSE on failure, array on success. + * @param mixed key to get cache metadata on + * @return mixed FALSE on failure, array on success. */ public function get_metadata($id) { @@ -156,8 +150,10 @@ class CI_Cache_memcached extends CI_Driver { /** * Setup memcached. + * + * @return bool */ - private function _setup_memcached() + protected function _setup_memcached() { // Try to load memcached server info from the config file. $CI =& get_instance(); @@ -179,14 +175,13 @@ class CI_Cache_memcached extends CI_Driver { { $this->_memcached = new Memcached(); } - else if (class_exists('Memcache')) + elseif (class_exists('Memcache')) { $this->_memcached = new Memcache(); } else { log_message('error', 'Failed to create object for Memcached Cache; extension not loaded?'); - return FALSE; } @@ -194,17 +189,17 @@ class CI_Cache_memcached extends CI_Driver { { if ( ! array_key_exists('hostname', $cache_server)) { - $cache_server['hostname'] = $this->_default_options['default_host']; + $cache_server['hostname'] = $this->_memcache_conf['default']['default_host']; } if ( ! array_key_exists('port', $cache_server)) { - $cache_server['port'] = $this->_default_options['default_port']; + $cache_server['port'] = $this->_memcache_conf['default']['default_port']; } if ( ! array_key_exists('weight', $cache_server)) { - $cache_server['weight'] = $this->_default_options['default_weight']; + $cache_server['weight'] = $this->_memcache_conf['default']['default_weight']; } if (get_class($this->_memcached) == 'Memcache') @@ -237,23 +232,21 @@ class CI_Cache_memcached extends CI_Driver { * * Returns FALSE if memcached is not supported on the system. * If it is, we setup the memcached object & return TRUE + * + * @return bool */ public function is_supported() { if ( ! extension_loaded('memcached') && ! extension_loaded('memcache')) { log_message('error', 'The Memcached Extension must be loaded to use Memcached Cache.'); - return FALSE; } return $this->_setup_memcached(); } - // ------------------------------------------------------------------------ - } -// End Class /* End of file Cache_memcached.php */ -/* Location: ./system/libraries/Cache/drivers/Cache_memcached.php */ +/* Location: ./system/libraries/Cache/drivers/Cache_memcached.php */
\ No newline at end of file diff --git a/system/libraries/Cache/drivers/Cache_wincache.php b/system/libraries/Cache/drivers/Cache_wincache.php index df619d4e6..b32e66a46 100644 --- a/system/libraries/Cache/drivers/Cache_wincache.php +++ b/system/libraries/Cache/drivers/Cache_wincache.php @@ -25,8 +25,6 @@ * @filesource */ -// ------------------------------------------------------------------------ - /** * CodeIgniter Wincache Caching Class * @@ -39,7 +37,6 @@ * @author Mike Murkovic * @link */ - class CI_Cache_wincache extends CI_Driver { /** @@ -68,7 +65,7 @@ class CI_Cache_wincache extends CI_Driver { * @param string Unique Key * @param mixed Data to store * @param int Length of time (in seconds) to cache the data - * @return bool true on success/false on failure + * @return bool true on success/false on failure */ public function save($id, $data, $ttl = 60) { @@ -162,4 +159,4 @@ class CI_Cache_wincache extends CI_Driver { } /* End of file Cache_wincache.php */ -/* Location: ./system/libraries/Cache/drivers/Cache_wincache.php */ +/* Location: ./system/libraries/Cache/drivers/Cache_wincache.php */
\ No newline at end of file diff --git a/system/libraries/Calendar.php b/system/libraries/Calendar.php index 6c04de8a2..b6f145d95 100644 --- a/system/libraries/Calendar.php +++ b/system/libraries/Calendar.php @@ -25,8 +25,6 @@ * @filesource */ -// ------------------------------------------------------------------------ - /** * CodeIgniter Calendar Class * @@ -40,7 +38,7 @@ */ class CI_Calendar { - private $CI; + protected $CI; public $lang; public $local_time; public $template = ''; @@ -54,6 +52,9 @@ class CI_Calendar { * Constructor * * Loads the calendar language file and sets the default time reference + * + * @param array + * @return void */ public function __construct($config = array()) { @@ -71,7 +72,7 @@ class CI_Calendar { $this->initialize($config); } - log_message('debug', "Calendar Class Initialized"); + log_message('debug', 'Calendar Class Initialized'); } // -------------------------------------------------------------------- @@ -81,7 +82,6 @@ class CI_Calendar { * * Accepts an associative array as input, containing display preferences * - * @access public * @param array config preferences * @return void */ @@ -101,9 +101,8 @@ class CI_Calendar { /** * Generate the calendar * - * @access public - * @param integer the year - * @param integer the month + * @param int the year + * @param int the month * @param array the data to be shown in the calendar cells * @return string */ @@ -147,7 +146,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) { @@ -160,7 +159,7 @@ class CI_Calendar { $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; + $is_current_month = ($cur_year == $year && $cur_month == $month); // Generate the template data array $this->parse_template(); @@ -172,7 +171,7 @@ class CI_Calendar { 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); + $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'])."\n"; @@ -213,21 +212,21 @@ class CI_Calendar { 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']; + $out .= ($is_current_month === TRUE && $day == $cur_day) ? $this->temp['cal_cell_start_today'] : $this->temp['cal_cell_start']; - if ($day > 0 AND $day <= $total_days) + if ($day > 0 && $day <= $total_days) { if (isset($data[$day])) { // Cells with content - $temp = ($is_current_month === TRUE AND $day == $cur_day) ? + $temp = ($is_current_month === TRUE && $day == $cur_day) ? $this->temp['cal_cell_content_today'] : $this->temp['cal_cell_content']; $out .= str_replace(array('{content}', '{day}'), array($data[$day], $day), $temp); } else { // Cells with no content - $temp = ($is_current_month === TRUE AND $day == $cur_day) ? + $temp = ($is_current_month === TRUE && $day == $cur_day) ? $this->temp['cal_cell_no_content_today'] : $this->temp['cal_cell_no_content']; $out .= str_replace('{day}', $day, $temp); } @@ -238,7 +237,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 && $day == $cur_day) ? $this->temp['cal_cell_end_today'] : $this->temp['cal_cell_end']; $day++; } @@ -258,8 +257,7 @@ class CI_Calendar { * Generates a textual month name based on the numeric * month provided. * - * @access public - * @param integer the month + * @param int the month * @return string */ public function get_month_name($month) @@ -289,9 +287,8 @@ 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 * @return array */ @@ -333,9 +330,8 @@ class CI_Calendar { * 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 + * @param int the month + * @param int the year * @return array */ public function adjust_date($month, $year) @@ -370,10 +366,9 @@ class CI_Calendar { /** * Total days in a given month * - * @access public - * @param integer the month - * @param integer the year - * @return integer + * @param int the month + * @param int the year + * @return int */ public function get_total_days($month, $year) { @@ -387,7 +382,7 @@ class CI_Calendar { // Is the year a leap year? if ($month == 2) { - if ($year % 400 == 0 OR ($year % 4 == 0 AND $year % 100 != 0)) + if ($year % 400 == 0 OR ($year % 4 == 0 && $year % 100 != 0)) { return 29; } @@ -403,8 +398,7 @@ class CI_Calendar { * * This is used in the event that the user has not created their own template * - * @access public - * @return array + * @return array */ public function default_template() { @@ -441,7 +435,6 @@ class CI_Calendar { * Harvests the data within the template {pseudo-variables} * used to display the calendar * - * @access public * @return void */ public function parse_template() @@ -457,7 +450,7 @@ class CI_Calendar { 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)) + if (preg_match('/\{'.$val.'\}(.*?)\{\/'.$val.'\}/si', $this->template, $match)) { $this->temp[$val] = $match[1]; } @@ -470,7 +463,5 @@ class CI_Calendar { } -// END CI_Calendar class - /* End of file Calendar.php */ -/* Location: ./system/libraries/Calendar.php */ +/* Location: ./system/libraries/Calendar.php */
\ No newline at end of file diff --git a/system/libraries/Cart.php b/system/libraries/Cart.php index 60a1e52fe..ca7be555e 100644 --- a/system/libraries/Cart.php +++ b/system/libraries/Cart.php @@ -25,8 +25,6 @@ * @filesource */ -// ------------------------------------------------------------------------ - /** * Shopping Cart Class * @@ -41,12 +39,11 @@ class CI_Cart { // These are the regular expression rules that we use to validate the product ID and product name public $product_id_rules = '\.a-z0-9_-'; // alpha-numeric, dashes, underscores, or periods public $product_name_rules = '\.\:\-_ a-z0-9'; // alpha-numeric, dashes, underscores, colons or periods - public $product_name_safe = true; // only allow safe product names - - // Private variables. Do not change! - private $CI; - private $_cart_contents = array(); + public $product_name_safe = TRUE; // only allow safe product names + // Protected variables. Do not change! + protected $CI; + protected $_cart_contents = array(); /** * Shopping Class Constructor @@ -72,7 +69,7 @@ class CI_Cart { $this->_cart_contents = array('cart_total' => 0, 'total_items' => 0); } - log_message('debug', "Cart Class Initialized"); + log_message('debug', 'Cart Class Initialized'); } // -------------------------------------------------------------------- @@ -80,7 +77,6 @@ class CI_Cart { /** * Insert items into the cart and save it to the session table * - * @access public * @param array * @return bool */ @@ -110,7 +106,7 @@ class CI_Cart { { foreach ($items as $val) { - if (is_array($val) AND isset($val['id'])) + if (is_array($val) && isset($val['id'])) { if ($this->_insert($val)) { @@ -135,11 +131,10 @@ class CI_Cart { /** * Insert * - * @access private * @param array * @return bool */ - private function _insert($items = array()) + protected function _insert($items = array()) { // Was any cart data passed? No? Bah... if ( ! is_array($items) OR count($items) === 0) @@ -213,7 +208,7 @@ class CI_Cart { // Internally, we need to treat identical submissions, but with different options, as a unique product. // Our solution is to convert the options array to a string and MD5 it along with the product ID. // This becomes the unique "row ID" - if (isset($items['options']) AND count($items['options']) > 0) + if (isset($items['options']) && count($items['options']) > 0) { $rowid = md5($items['id'].implode('', $items['options'])); } @@ -249,7 +244,6 @@ class CI_Cart { * changes to the quantity before checkout. That array must contain the * product ID and quantity for each item. * - * @access public * @param array * @param string * @return bool @@ -308,11 +302,10 @@ class CI_Cart { * changes to the quantity before checkout. That array must contain the * product ID and quantity for each item. * - * @access private * @param array * @return bool */ - private function _update($items = array()) + protected function _update($items = array()) { // Without these array indexes there is nothing we can do if ( ! isset($items['qty']) OR ! isset($items['rowid']) OR ! isset($this->_cart_contents[$items['rowid']])) @@ -348,10 +341,9 @@ class CI_Cart { /** * Save the cart array to the session DB * - * @access private * @return bool */ - private function _save_cart() + protected function _save_cart() { // Lets add up the individual prices and set the cart sub-total $this->_cart_contents['total_items'] = $this->_cart_contents['cart_total'] = 0; @@ -390,8 +382,7 @@ class CI_Cart { /** * Cart Total * - * @access public - * @return integer + * @return int */ public function total() { @@ -405,8 +396,7 @@ class CI_Cart { * * Removes an item from the cart * - * @access public - * @return boolean + * @return bool */ public function remove($rowid) { @@ -423,8 +413,7 @@ class CI_Cart { * * Returns the total item count * - * @access public - * @return integer + * @return int */ public function total_items() { @@ -438,7 +427,6 @@ class CI_Cart { * * Returns the entire cart array * - * @access public * @return array */ public function contents($newest_first = FALSE) @@ -461,7 +449,6 @@ class CI_Cart { * Returns TRUE if the rowid passed to this function correlates to an item * that has options associated with it. * - * @access public * @return bool */ public function has_options($rowid = '') @@ -476,7 +463,7 @@ class CI_Cart { * * Returns the an array of options, for a particular product row ID * - * @access public + * @param int * @return array */ public function product_options($rowid = '') @@ -491,7 +478,7 @@ class CI_Cart { * * Returns the supplied number with commas and a decimal point. * - * @access public + * @param float * @return string */ public function format_number($n = '') @@ -514,7 +501,6 @@ class CI_Cart { * * Empties the cart and kills the session * - * @access public * @return void */ public function destroy() @@ -523,9 +509,7 @@ class CI_Cart { $this->CI->session->unset_userdata('cart_contents'); } - } -// END Cart Class /* End of file Cart.php */ -/* Location: ./system/libraries/Cart.php */ +/* Location: ./system/libraries/Cart.php */
\ No newline at end of file diff --git a/system/libraries/Driver.php b/system/libraries/Driver.php index 9a073b336..f409f47d4 100644 --- a/system/libraries/Driver.php +++ b/system/libraries/Driver.php @@ -25,8 +25,6 @@ * @filesource */ -// ------------------------------------------------------------------------ - /** * CodeIgniter Driver Library Class * @@ -84,8 +82,8 @@ class CI_Driver_Library { // 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); + log_message('error', 'Unable to load the requested driver: '.$child_class); + show_error('Unable to load the requested driver: '.$child_class); } } @@ -96,15 +94,11 @@ class CI_Driver_Library { } // The requested driver isn't valid! - log_message('error', "Invalid driver requested: ".$child_class); - show_error("Invalid driver requested: ".$child_class); + log_message('error', 'Invalid driver requested: '.$child_class); + show_error('Invalid driver requested: '.$child_class); } - // -------------------------------------------------------------------- - } -// END CI_Driver_Library CLASS - /** * CodeIgniter Driver Class @@ -120,12 +114,12 @@ class CI_Driver_Library { */ class CI_Driver { - protected $parent; + protected $_parent; - private $methods = array(); - private $properties = array(); + protected $_methods = array(); + protected $_properties = array(); - private static $reflections = array(); + protected static $_reflections = array(); /** * Decorate @@ -137,14 +131,14 @@ class CI_Driver { */ public function decorate($parent) { - $this->parent = $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])) + if ( ! isset(self::$_reflections[$class_name])) { $r = new ReflectionObject($parent); @@ -152,7 +146,7 @@ class CI_Driver { { if ($method->isPublic()) { - $this->methods[] = $method->getName(); + $this->_methods[] = $method->getName(); } } @@ -160,15 +154,15 @@ class CI_Driver { { if ($prop->isPublic()) { - $this->properties[] = $prop->getName(); + $this->_properties[] = $prop->getName(); } } - self::$reflections[$class_name] = array($this->methods, $this->properties); + self::$_reflections[$class_name] = array($this->_methods, $this->_properties); } else { - list($this->methods, $this->properties) = self::$reflections[$class_name]; + list($this->_methods, $this->_properties) = self::$_reflections[$class_name]; } } @@ -179,16 +173,15 @@ class CI_Driver { * * 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)) + if (in_array($method, $this->_methods)) { - return call_user_func_array(array($this->parent, $method), $args); + return call_user_func_array(array($this->_parent, $method), $args); } $trace = debug_backtrace(); @@ -208,9 +201,9 @@ class CI_Driver { */ public function __get($var) { - if (in_array($var, $this->properties)) + if (in_array($var, $this->_properties)) { - return $this->parent->$var; + return $this->_parent->$var; } } @@ -227,16 +220,13 @@ class CI_Driver { */ public function __set($var, $val) { - if (in_array($var, $this->properties)) + if (in_array($var, $this->_properties)) { - $this->parent->$var = $val; + $this->_parent->$var = $val; } } - // -------------------------------------------------------------------- - } -// END CI_Driver CLASS /* End of file Driver.php */ -/* Location: ./system/libraries/Driver.php */ +/* Location: ./system/libraries/Driver.php */
\ No newline at end of file diff --git a/system/libraries/Email.php b/system/libraries/Email.php index 8f383c939..48c3bf3ab 100644 --- a/system/libraries/Email.php +++ b/system/libraries/Email.php @@ -407,11 +407,11 @@ class CI_Email { * @param string * @return object */ - public function attach($filename, $disposition = '', $newname = NULL) + public function attach($filename, $disposition = '', $newname = NULL, $mime = '') { $this->_attach_name[] = array($filename, $newname); - $this->_attach_type[] = $this->_mime_types(pathinfo($filename, PATHINFO_EXTENSION)); $this->_attach_disp[] = empty($disposition) ? 'attachment' : $disposition; // Can also be 'inline' Not sure if it matters + $this->_attach_type[] = $mime; return $this; } @@ -1049,29 +1049,39 @@ class CI_Email { $filename = $this->_attach_name[$i][0]; $basename = (is_null($this->_attach_name[$i][1])) ? basename($filename) : $this->_attach_name[$i][1]; $ctype = $this->_attach_type[$i]; + $file_content = ''; - if ( ! file_exists($filename)) + if ($this->_attach_type[$i] == '') { - $this->_set_error_message('lang:email_attachment_missing', $filename); - return FALSE; - } + if ( ! file_exists($filename)) + { + $this->_set_error_message('lang:email_attachment_missing', $filename); + return FALSE; + } + + $file = filesize($filename) +1; + if ( ! $fp = fopen($filename, FOPEN_READ)) + { + $this->_set_error_message('lang:email_attachment_unreadable', $filename); + return FALSE; + } + + $ctype = $this->_mime_types(pathinfo($filename, PATHINFO_EXTENSION)); + $file_content = fread($fp, $file); + fclose($fp); + } + else + { + $file_content =& $this->_attach_content[$i]; + } $attachment[$z++] = "--".$this->_atc_boundary.$this->newline . "Content-type: ".$ctype."; " . "name=\"".$basename."\"".$this->newline . "Content-Disposition: ".$this->_attach_disp[$i].";".$this->newline . "Content-Transfer-Encoding: base64".$this->newline; - $file = filesize($filename) +1; - - if ( ! $fp = fopen($filename, FOPEN_READ)) - { - $this->_set_error_message('lang:email_attachment_unreadable', $filename); - return FALSE; - } - - $attachment[$z++] = chunk_split(base64_encode(fread($fp, $file))); - fclose($fp); + $attachment[$z++] = chunk_split(base64_encode($file_content)); } $body .= implode($this->newline, $attachment).$this->newline."--".$this->_atc_boundary."--"; diff --git a/system/libraries/Encrypt.php b/system/libraries/Encrypt.php index b29eb470e..54b5bf737 100644 --- a/system/libraries/Encrypt.php +++ b/system/libraries/Encrypt.php @@ -38,15 +38,15 @@ */ class CI_Encrypt { - public $encryption_key = ''; - protected $_hash_type = 'sha1'; - protected $_mcrypt_exists = FALSE; + public $encryption_key = ''; + protected $_hash_type = 'sha1'; + protected $_mcrypt_exists = FALSE; protected $_mcrypt_cipher; protected $_mcrypt_mode; public function __construct() { - $this->_mcrypt_exists = ( ! function_exists('mcrypt_encrypt')) ? FALSE : TRUE; + $this->_mcrypt_exists = function_exists('mcrypt_encrypt'); log_message('debug', 'Encrypt Class Initialized'); } @@ -349,8 +349,8 @@ class CI_Encrypt { * * Function description * - * @param type - * @return type + * @param string + * @return string */ protected function _remove_cipher_noise($data, $key) { @@ -382,8 +382,8 @@ class CI_Encrypt { /** * Set the Mcrypt Cipher * - * @param constant - * @return string + * @param int + * @return object */ public function set_cipher($cipher) { @@ -396,8 +396,8 @@ class CI_Encrypt { /** * Set the Mcrypt Mode * - * @param constant - * @return string + * @param int + * @return object */ public function set_mode($mode) { @@ -410,7 +410,7 @@ class CI_Encrypt { /** * Get Mcrypt cipher Value * - * @return string + * @return int */ protected function _get_cipher() { @@ -427,7 +427,7 @@ class CI_Encrypt { /** * Get Mcrypt Mode Value * - * @return string + * @return int */ protected function _get_mode() { @@ -464,7 +464,8 @@ class CI_Encrypt { { return ($this->_hash_type === 'sha1') ? sha1($str) : md5($str); } + } /* End of file Encrypt.php */ -/* Location: ./system/libraries/Encrypt.php */ +/* Location: ./system/libraries/Encrypt.php */
\ No newline at end of file diff --git a/system/libraries/Form_validation.php b/system/libraries/Form_validation.php index 3e0c72e84..22bc7ddf3 100644 --- a/system/libraries/Form_validation.php +++ b/system/libraries/Form_validation.php @@ -25,8 +25,6 @@ * @filesource */ -// ------------------------------------------------------------------------ - /** * Form Validation Class * @@ -39,15 +37,15 @@ class CI_Form_validation { protected $CI; - protected $_field_data = array(); - protected $_config_rules = array(); - protected $_error_array = array(); - protected $_error_messages = array(); - protected $_error_prefix = '<p>'; - protected $_error_suffix = '</p>'; - protected $error_string = ''; - protected $_safe_form_data = FALSE; - protected $validation_data = array(); + protected $_field_data = array(); + protected $_config_rules = array(); + protected $_error_array = array(); + protected $_error_messages = array(); + protected $_error_prefix = '<p>'; + protected $_error_suffix = '</p>'; + protected $error_string = ''; + protected $_safe_form_data = FALSE; + protected $validation_data = array(); public function __construct($rules = array()) { @@ -64,7 +62,7 @@ class CI_Form_validation { $this->_error_suffix = $rules['error_suffix']; unset($rules['error_suffix']); } - + // Validation rules can be stored in a config file. $this->_config_rules = $rules; @@ -90,7 +88,7 @@ class CI_Form_validation { * * @param mixed * @param string - * @return void + * @return object */ public function set_rules($field, $label = '', $rules = '') { @@ -108,17 +106,18 @@ class CI_Form_validation { foreach ($field as $row) { // Houston, we have a problem... - if ( ! isset($row['field']) OR ! isset($row['rules'])) + if ( ! isset($row['field'], $row['rules'])) { continue; } // If the field label wasn't passed we use the field name - $label = ( ! isset($row['label'])) ? $row['field'] : $row['label']; + $label = isset($row['label']) ? $row['label'] : $row['field']; // Here we go! $this->set_rules($row['field'], $label, $row['rules']); } + return $this; } @@ -198,12 +197,12 @@ class CI_Form_validation { /** * 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. + * Lets users set their own error messages on the fly. Note: + * The key name has to match the function name that it corresponds to. * + * @param array * @param string - * @param string - * @return string + * @return object */ public function set_message($lang, $val = '') { @@ -213,7 +212,6 @@ class CI_Form_validation { } $this->_error_messages = array_merge($this->_error_messages, $lang); - return $this; } @@ -226,13 +224,12 @@ class CI_Form_validation { * * @param string * @param string - * @return void + * @return object */ public function set_error_delimiters($prefix = '<p>', $suffix = '</p>') { $this->_error_prefix = $prefix; $this->_error_suffix = $suffix; - return $this; } @@ -244,11 +241,11 @@ class CI_Form_validation { * Gets the error message associated with a particular field * * @param string the field name - * @return void + * @return string */ public function error($field = '', $prefix = '', $suffix = '') { - if ( ! isset($this->_field_data[$field]['error']) OR $this->_field_data[$field]['error'] == '') + if (empty($this->_field_data[$field]['error'])) { return ''; } @@ -289,7 +286,7 @@ class CI_Form_validation { * * @param string * @param string - * @return str + * @return string */ public function error_string($prefix = '', $suffix = '') { @@ -334,7 +331,7 @@ class CI_Form_validation { public function run($group = '') { // Do we even have any data to process? Mm? - $validation_array = ( ! empty($this->validation_data)) ? $this->validation_data : $_POST; + $validation_array = empty($this->validation_data) ? $_POST : $this->validation_data; if (count($validation_array) === 0) { return FALSE; @@ -353,7 +350,7 @@ class CI_Form_validation { // 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])) + if ($uri != '' && isset($this->_config_rules[$uri])) { $this->set_rules($this->_config_rules[$uri]); } @@ -362,10 +359,10 @@ class CI_Form_validation { $this->set_rules($this->_config_rules); } - // We're we able to set the rules correctly? + // Were we able to set the rules correctly? if (count($this->_field_data) === 0) { - log_message('debug', "Unable to find validation rules"); + log_message('debug', 'Unable to find validation rules'); return FALSE; } } @@ -379,17 +376,13 @@ class CI_Form_validation { { // Fetch the data from the corresponding $_POST or validation array and cache it in the _field_data array. // Depending on whether the field name is an array or a string will determine where we get it from. - if ($row['is_array'] === TRUE) { $this->_field_data[$field]['postdata'] = $this->_reduce_array($validation_array, $row['keys']); } - else + elseif ( ! empty($validation_array[$field])) { - if (isset($validation_array[$field]) AND $validation_array[$field] != "") - { - $this->_field_data[$field]['postdata'] = $validation_array[$field]; - } + $this->_field_data[$field]['postdata'] = $validation_array[$field]; } $this->_execute($row, explode('|', $row['rules']), $this->_field_data[$field]['postdata']); @@ -397,7 +390,6 @@ class CI_Form_validation { // Did we end up with any errors? $total_errors = count($this->_error_array); - if ($total_errors > 0) { $this->_safe_form_data = TRUE; @@ -416,7 +408,7 @@ class CI_Form_validation { * * @param array * @param array - * @param integer + * @param int * @return mixed */ protected function _reduce_array($array, $keys, $i = 0) @@ -434,7 +426,7 @@ class CI_Form_validation { /** * Re-populate the _POST array with our finalized and processed data * - * @return null + * @return void */ protected function _reset_post_array() { @@ -494,7 +486,7 @@ class CI_Form_validation { * @param array * @param array * @param mixed - * @param integer + * @param int * @return mixed */ protected function _execute($row, $rules, $postdata = NULL, $cycles = 0) @@ -511,17 +503,15 @@ class CI_Form_validation { 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)) + if ( ! in_array('required', $rules) && is_null($postdata)) { // Before we bail out, does the rule contain a callback? - if (preg_match("/(callback_\w+(\[.*?\])?)/", implode(' ', $rules), $match)) + if (preg_match('/(callback_\w+(\[.*?\])?)/', implode(' ', $rules), $match)) { $callback = TRUE; - $rules = (array('1' => $match[1])); + $rules = array(1 => $match[1]); } else { @@ -529,15 +519,13 @@ class CI_Form_validation { } } - // -------------------------------------------------------------------- - // Isset Test. Typically this rule will only apply to checkboxes. - if (is_null($postdata) AND $callback === FALSE) + if (is_null($postdata) && $callback === FALSE) { if (in_array('isset', $rules, TRUE) OR in_array('required', $rules)) { // Set the message type - $type = (in_array('required', $rules)) ? 'required' : 'isset'; + $type = in_array('required', $rules) ? 'required' : 'isset'; if ( ! isset($this->_error_messages[$type])) { @@ -569,13 +557,13 @@ class CI_Form_validation { // -------------------------------------------------------------------- // Cycle through each rule and run it - foreach ($rules As $rule) + 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'])) + if ($row['is_array'] == TRUE && is_array($this->_field_data[$row['field']]['postdata'])) { // We shouldn't need this safety, but just in case there isn't an array index // associated with this cycle we'll bail out @@ -592,11 +580,9 @@ class CI_Form_validation { $postdata = $this->_field_data[$row['field']]['postdata']; } - // -------------------------------------------------------------------- - // Is the rule a callback? $callback = FALSE; - if (substr($rule, 0, 9) == 'callback_') + if (strpos($rule, 'callback_') === 0) { $rule = substr($rule, 9); $callback = TRUE; @@ -605,7 +591,7 @@ class CI_Form_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)) { $rule = $match[1]; $param = $match[2]; @@ -616,68 +602,69 @@ class CI_Form_validation { { if ( ! method_exists($this->CI, $rule)) { - continue; + log_message('debug', 'Unable to find callback validation rule: '.$rule); + $result = FALSE; + } + else + { + // Run the function and grab the result + $result = $this->CI->$rule($postdata, $param); } - - // 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; + $this->_field_data[$row['field']]['postdata'][$cycles] = is_bool($result) ? $postdata : $result; } else { - $this->_field_data[$row['field']]['postdata'] = (is_bool($result)) ? $postdata : $result; + $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) + if ( ! in_array('required', $rules, TRUE) && $result !== FALSE) { continue; } } - else + elseif ( ! method_exists($this, $rule)) { - 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)) { - // 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); + $result = ($param !== FALSE) ? $rule($postdata, $param) : $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; - } + if ($_in_array === TRUE) + { + $this->_field_data[$row['field']]['postdata'][$cycles] = is_bool($result) ? $postdata : $result; } else { - log_message('debug', "Unable to find validation rule: ".$rule); + $this->_field_data[$row['field']]['postdata'] = is_bool($result) ? $postdata : $result; } - - continue; } - + else + { + log_message('debug', 'Unable to find validation rule: '.$rule); + $result = FALSE; + } + } + else + { $result = $this->$rule($postdata, $param); if ($_in_array === TRUE) { - $this->_field_data[$row['field']]['postdata'][$cycles] = (is_bool($result)) ? $postdata : $result; + $this->_field_data[$row['field']]['postdata'][$cycles] = is_bool($result) ? $postdata : $result; } else { - $this->_field_data[$row['field']]['postdata'] = (is_bool($result)) ? $postdata : $result; + $this->_field_data[$row['field']]['postdata'] = is_bool($result) ? $postdata : $result; } } - // 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])) @@ -693,7 +680,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], $this->_field_data[$param]['label'])) { $param = $this->_translate_fieldname($this->_field_data[$param]['label']); @@ -727,7 +714,7 @@ class CI_Form_validation { { // Do we need to translate the field name? // We look for the prefix lang: to determine this - if (substr($fieldname, 0, 5) === 'lang:') + if (strpos($fieldname, 'lang:') === 0) { // Grab the variable $line = substr($fieldname, 5); @@ -791,7 +778,6 @@ class CI_Form_validation { } $field = $this->_field_data[$field]['postdata']; - if (is_array($field)) { if ( ! in_array($value, $field)) @@ -827,7 +813,6 @@ class CI_Form_validation { } $field = $this->_field_data[$field]['postdata']; - if (is_array($field)) { if ( ! in_array($value, $field)) @@ -835,12 +820,9 @@ class CI_Form_validation { return ''; } } - else + elseif (($field == '' OR $value == '') OR ($field != $value)) { - if (($field == '' OR $value == '') OR ($field != $value)) - { - return ''; - } + return ''; } return ' checked="checked"'; @@ -874,7 +856,7 @@ class CI_Form_validation { */ public function required($str) { - return ( ! is_array($str)) ? (trim($str) !== '') : ( ! empty($str)); + return is_array($str) ? (bool) count($str) : (trim($str) !== ''); } // -------------------------------------------------------------------- @@ -883,7 +865,7 @@ class CI_Form_validation { * Performs a Regular Expression match test. * * @param string - * @param regex + * @param string regex * @return bool */ public function regex_match($str, $regex) @@ -897,12 +879,12 @@ class CI_Form_validation { * Match one field to another * * @param string - * @param field + * @param string field * @return bool */ public function matches($str, $field) { - $validation_array = ( ! empty($this->validation_data)) ? $this->validation_data : $_POST; + $validation_array = empty($this->validation_data) ? $_POST : $this->validation_data; if ( ! isset($validation_array[$field])) { return FALSE; @@ -920,7 +902,7 @@ class CI_Form_validation { * in the specified database field. * * @param string - * @param field + * @param string field * @return bool */ public function is_unique($str, $field) @@ -940,7 +922,7 @@ class CI_Form_validation { * Minimum Length * * @param string - * @param value + * @param int * @return bool */ public function min_length($str, $val) @@ -950,12 +932,9 @@ class CI_Form_validation { return FALSE; } - if (MB_ENABLED === TRUE) - { - return ! (mb_strlen($str) < $val); - } - - return ! (strlen($str) < $val); + return (MB_ENABLED === TRUE) + ? ($val <= mb_strlen($str)) + : ($val <= strlen(str)); } // -------------------------------------------------------------------- @@ -964,7 +943,7 @@ class CI_Form_validation { * Max Length * * @param string - * @param value + * @param int * @return bool */ public function max_length($str, $val) @@ -974,12 +953,9 @@ class CI_Form_validation { return FALSE; } - if (MB_ENABLED === TRUE) - { - return ! (mb_strlen($str) > $val); - } - - return ! (strlen($str) > $val); + return (MB_ENABLED === TRUE) + ? ($val >= mb_strlen($str)) + : ($val >= strlen($str)); } // -------------------------------------------------------------------- @@ -988,7 +964,7 @@ class CI_Form_validation { * Exact Length * * @param string - * @param value + * @param int * @return bool */ public function exact_length($str, $val) @@ -998,12 +974,9 @@ class CI_Form_validation { return FALSE; } - if (MB_ENABLED === TRUE) - { - return (mb_strlen($str) == $val); - } - - return (strlen($str) == $val); + return (MB_ENABLED === TRUE) + ? (mb_strlen($str) == $val) + : (strlen($str) == $val); } // -------------------------------------------------------------------- @@ -1114,19 +1087,6 @@ class CI_Form_validation { // -------------------------------------------------------------------- /** - * Is Numeric - * - * @param string - * @return bool - */ - public function is_numeric($str) - { - return is_numeric($str); - } - - // -------------------------------------------------------------------- - - /** * Integer * * @param string @@ -1160,11 +1120,7 @@ class CI_Form_validation { */ public function greater_than($str, $min) { - if ( ! is_numeric($str)) - { - return FALSE; - } - return $str > $min; + return is_numeric($str) ? ($str > $min) : FALSE; } // -------------------------------------------------------------------- @@ -1177,11 +1133,7 @@ class CI_Form_validation { */ public function greater_than_equal_to($str, $min) { - if ( ! is_numeric($str)) - { - return FALSE; - } - return $str >= $min; + return is_numeric($str) ? ($str >= $min) : FALSE; } // -------------------------------------------------------------------- @@ -1194,11 +1146,7 @@ class CI_Form_validation { */ public function less_than($str, $max) { - if ( ! is_numeric($str)) - { - return FALSE; - } - return $str < $max; + return is_numeric($str) ? ($str < $max) : FALSE; } // -------------------------------------------------------------------- @@ -1211,11 +1159,7 @@ class CI_Form_validation { */ public function less_than_equal_to($str, $max) { - if ( ! is_numeric($str)) - { - return FALSE; - } - return $str <= $max; + return is_numeric($str) ? ($str <= $max) : FALSE; } // -------------------------------------------------------------------- @@ -1301,14 +1245,14 @@ class CI_Form_validation { */ public function prep_url($str = '') { - if ($str == 'http://' OR $str == '') + if ($str === 'http://' OR $str == '') { return ''; } - if (substr($str, 0, 7) !== 'http://' && substr($str, 0, 8) !== 'https://') + if (strpos($str, 'http://') !== 0 && strpos($str, 'https://') !== 0) { - $str = 'http://'.$str; + return 'http://'.$str; } return $str; @@ -1375,4 +1319,4 @@ class CI_Form_validation { } /* End of file Form_validation.php */ -/* Location: ./system/libraries/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 4d96c00cc..8aa1650d2 100644 --- a/system/libraries/Ftp.php +++ b/system/libraries/Ftp.php @@ -25,8 +25,6 @@ * @filesource */ -// ------------------------------------------------------------------------ - /** * FTP Class * @@ -42,16 +40,11 @@ class CI_FTP { public $username = ''; public $password = ''; public $port = 21; - public $passive = TRUE; + public $passive = TRUE; public $debug = FALSE; - public $conn_id = FALSE; + public $conn_id = FALSE; - /** - * Constructor - Sets Preferences - * - * The constructor can be passed an array of config values - */ public function __construct($config = array()) { if (count($config) > 0) @@ -59,7 +52,7 @@ class CI_FTP { $this->initialize($config); } - log_message('debug', "FTP Class Initialized"); + log_message('debug', 'FTP Class Initialized'); } // -------------------------------------------------------------------- @@ -67,7 +60,6 @@ class CI_FTP { /** * Initialize preferences * - * @access public * @param array * @return void */ @@ -90,7 +82,6 @@ class CI_FTP { /** * FTP Connect * - * @access public * @param array the connection values * @return bool */ @@ -133,10 +124,9 @@ class CI_FTP { /** * FTP Login * - * @access private * @return bool */ - private function _login() + protected function _login() { return @ftp_login($this->conn_id, $this->username, $this->password); } @@ -146,10 +136,9 @@ class CI_FTP { /** * Validates the connection ID * - * @access private * @return bool */ - private function _is_conn() + protected function _is_conn() { if ( ! is_resource($this->conn_id)) { @@ -164,17 +153,15 @@ class CI_FTP { // -------------------------------------------------------------------- - /** * Change directory * * The second parameter lets us momentarily turn off debugging so that * 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() + * 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 parameter is only used by the "mirror" function below. * - * @access public * @param string * @param bool * @return bool @@ -190,7 +177,7 @@ class CI_FTP { if ($result === FALSE) { - if ($this->debug == TRUE AND $supress_debug == FALSE) + if ($this->debug == TRUE && $supress_debug == FALSE) { $this->_error('ftp_unable_to_changedir'); } @@ -205,8 +192,8 @@ class CI_FTP { /** * Create a directory * - * @access public * @param string + * @param int * @return bool */ public function mkdir($path = '', $permissions = NULL) @@ -230,7 +217,7 @@ class CI_FTP { // Set file permissions if needed if ( ! is_null($permissions)) { - $this->chmod($path, (int)$permissions); + $this->chmod($path, (int) $permissions); } return TRUE; @@ -241,10 +228,10 @@ class CI_FTP { /** * Upload a file to the server * - * @access public * @param string * @param string * @param string + * @param int * @return bool */ public function upload($locpath, $rempath, $mode = 'auto', $permissions = NULL) @@ -284,7 +271,7 @@ class CI_FTP { // Set file permissions if needed if ( ! is_null($permissions)) { - $this->chmod($rempath, (int)$permissions); + $this->chmod($rempath, (int) $permissions); } return TRUE; @@ -295,7 +282,6 @@ class CI_FTP { /** * Download a file from a remote server to the local server * - * @access public * @param string * @param string * @param string @@ -337,7 +323,6 @@ class CI_FTP { /** * Rename (or move) a file * - * @access public * @param string * @param string * @param bool @@ -369,7 +354,6 @@ class CI_FTP { /** * Move a file * - * @access public * @param string * @param string * @return bool @@ -384,7 +368,6 @@ class CI_FTP { /** * Rename (or move) a file * - * @access public * @param string * @return bool */ @@ -415,7 +398,6 @@ class CI_FTP { * Delete a folder and recursively delete everything (including sub-folders) * containted within it. * - * @access public * @param string * @return bool */ @@ -427,11 +409,11 @@ class CI_FTP { } // Add a trailing slash to the file path if needed - $filepath = preg_replace("/(.+?)\/*$/", "\\1/", $filepath); + $filepath = preg_replace('/(.+?)\/*$/', '\\1/', $filepath); $list = $this->list_files($filepath); - if ($list !== FALSE AND count($list) > 0) + if ($list !== FALSE && count($list) > 0) { foreach ($list as $item) { @@ -463,7 +445,6 @@ class CI_FTP { /** * Set file permissions * - * @access public * @param string the file path * @param string the permissions * @return bool @@ -494,7 +475,6 @@ class CI_FTP { /** * FTP List files in the specified directory * - * @access public * @return array */ public function list_files($path = '.') @@ -512,11 +492,11 @@ 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 - * of the original file path will be recreated on the server. + * 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 @@ -532,7 +512,7 @@ class CI_FTP { if ($fp = @opendir($locpath)) { // Attempt to open the remote file path and try to create it, if it doesn't exist - if ( ! $this->changedir($rempath, TRUE) AND ( ! $this->mkdir($rempath) OR ! $this->changedir($rempath))) + if ( ! $this->changedir($rempath, TRUE) && ( ! $this->mkdir($rempath) OR ! $this->changedir($rempath))) { return FALSE; } @@ -542,9 +522,9 @@ class CI_FTP { { if (@is_dir($locpath.$file) && $file[0] !== '.') { - $this->mirror($locpath.$file."/", $rempath.$file."/"); + $this->mirror($locpath.$file.'/', $rempath.$file.'/'); } - elseif ($file[0] !== ".") + elseif ($file[0] !== '.') { // Get the file extension so we can se the upload type $ext = $this->_getext($file); @@ -565,11 +545,10 @@ class CI_FTP { /** * Extract the file extension * - * @access private * @param string * @return string */ - private function _getext($filename) + protected function _getext($filename) { if (FALSE === strpos($filename, '.')) { @@ -580,36 +559,34 @@ class CI_FTP { return end($x); } - // -------------------------------------------------------------------- /** * Set the upload type * - * @access private * @param string * @return string */ - private function _settype($ext) + protected 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'; + 'txt', + 'text', + 'php', + 'phps', + 'php4', + 'js', + 'css', + 'htm', + 'html', + 'phtml', + 'shtml', + 'log', + 'xml' + ); + + + return in_array($ext, $text_types) ? 'ascii' : 'binary'; } // ------------------------------------------------------------------------ @@ -617,7 +594,6 @@ class CI_FTP { /** * Close the connection * - * @access public * @return bool */ public function close() @@ -635,20 +611,17 @@ class CI_FTP { /** * Display error message * - * @access private * @param string * @return void */ - private function _error($line) + protected 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 */ +/* Location: ./system/libraries/Ftp.php */
\ No newline at end of file diff --git a/system/libraries/Image_lib.php b/system/libraries/Image_lib.php index 86b77bf07..1ab8b23e0 100644 --- a/system/libraries/Image_lib.php +++ b/system/libraries/Image_lib.php @@ -251,7 +251,7 @@ class CI_Image_lib { } else { - if (strpos($this->new_image, '/') === FALSE AND strpos($this->new_image, '\\') === FALSE) + if (strpos($this->new_image, '/') === FALSE && strpos($this->new_image, '\\') === FALSE) { $full_dest_path = str_replace('\\', '/', realpath($this->new_image)); } @@ -1462,4 +1462,4 @@ class CI_Image_lib { } /* End of file Image_lib.php */ -/* Location: ./system/libraries/Image_lib.php */ +/* Location: ./system/libraries/Image_lib.php */
\ No newline at end of file diff --git a/system/libraries/Javascript.php b/system/libraries/Javascript.php index 9ba93000b..629a3adfe 100644 --- a/system/libraries/Javascript.php +++ b/system/libraries/Javascript.php @@ -25,8 +25,6 @@ * @filesource */ -// ------------------------------------------------------------------------ - /** * Javascript Class * @@ -46,7 +44,7 @@ class CI_Javascript { foreach ($defaults as $key => $val) { - if (isset($params[$key]) && $params[$key] !== "") + if (isset($params[$key]) && $params[$key] !== '') { $defaults[$key] = $params[$key]; } @@ -61,7 +59,7 @@ class CI_Javascript { // 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"); + log_message('debug', 'Javascript Class Initialized and loaded. Driver used: '.$js_library_driver); } // -------------------------------------------------------------------- @@ -107,7 +105,7 @@ class CI_Javascript { * * @param string The element to attach the event to * @param string The code to execute - * @param boolean whether or not to return false + * @param bool whether or not to return false * @return string */ public function click($element = 'this', $js = '', $ret_false = TRUE) @@ -375,7 +373,6 @@ class CI_Javascript { // Effects // -------------------------------------------------------------------- - /** * Add Class * @@ -618,12 +615,9 @@ class CI_Javascript { { $this->_javascript_location = $external_file; } - else + elseif ($this->CI->config->item('javascript_location') != '') { - if ($this->CI->config->item('javascript_location') != '') - { - $this->_javascript_location = $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) @@ -650,13 +644,13 @@ class CI_Javascript { * Outputs a <script> tag * * @param string The element to attach the event to - * @param boolean If a CDATA section should be added + * @param bool If a CDATA section should be added * @return string */ public function inline($script, $cdata = TRUE) { return $this->_open_script() - . ($cdata ? "\n// <![CDATA[\n{$script}\n// ]]>\n" : "\n{$script}\n") + . ($cdata ? "\n// <![CDATA[\n".$script."\n// ]]>\n" : "\n".$script."\n") . $this->_close_script(); } @@ -673,7 +667,7 @@ class CI_Javascript { protected function _open_script($src = '') { return '<script type="text/javascript" charset="'.strtolower($this->CI->config->item('charset')).'"' - . ($src == '' ? '>' : ' src="'.$src.'">'); + .($src == '' ? '>' : ' src="'.$src.'">'); } // -------------------------------------------------------------------- @@ -688,15 +682,12 @@ class CI_Javascript { */ protected function _close_script($extra = "\n") { - return "</script>$extra"; + return '</script>'.$extra; } - - // -------------------------------------------------------------------- // -------------------------------------------------------------------- // AJAX-Y STUFF - still a testbed // -------------------------------------------------------------------- - // -------------------------------------------------------------------- /** * Update @@ -751,9 +742,9 @@ class CI_Javascript { $json = array(); $_is_assoc = TRUE; - if ( ! is_array($json_result) AND empty($json_result)) + if ( ! is_array($json_result) && empty($json_result)) { - show_error("Generate JSON Failed - Illegal key, value pair."); + show_error('Generate JSON Failed - Illegal key, value pair.'); } elseif ($match_array_type) { @@ -774,7 +765,7 @@ class CI_Javascript { $json = implode(',', $json); - return $_is_assoc ? "{".$json."}" : "[".$json."]"; + return $_is_assoc ? '{'.$json.'}' : '['.$json.']'; } @@ -785,8 +776,8 @@ class CI_Javascript { * * Checks for an associative array * - * @param type - * @return type + * @param array + * @return bool */ protected function _is_associative_array($arr) { @@ -808,8 +799,8 @@ class CI_Javascript { * * Ensures a standard json value and escapes values * - * @param type - * @return type + * @param mixed + * @return string */ protected function _prep_args($result, $is_key = FALSE) { @@ -831,9 +822,7 @@ class CI_Javascript { } } - // -------------------------------------------------------------------- } -// END Javascript Class /* End of file Javascript.php */ -/* Location: ./system/libraries/Javascript.php */ +/* Location: ./system/libraries/Javascript.php */
\ No newline at end of file diff --git a/system/libraries/Log.php b/system/libraries/Log.php index 955277acc..66f9ebff9 100644 --- a/system/libraries/Log.php +++ b/system/libraries/Log.php @@ -25,8 +25,6 @@ * @filesource */ -// ------------------------------------------------------------------------ - /** * Logging Class * @@ -43,12 +41,9 @@ class CI_Log { protected $_threshold_max = 0; protected $_threshold_array = array(); protected $_date_fmt = 'Y-m-d H:i:s'; - protected $_enabled = TRUE; - protected $_levels = array('ERROR' => 1, 'DEBUG' => 2, 'INFO' => 3, 'ALL' => 4); + protected $_enabled = TRUE; + protected $_levels = array('ERROR' => 1, 'DEBUG' => 2, 'INFO' => 3, 'ALL' => 4); - /** - * Constructor - */ public function __construct() { $config =& get_config(); @@ -98,7 +93,7 @@ class CI_Log { $level = strtoupper($level); if (( ! isset($this->_levels[$level]) OR ($this->_levels[$level] > $this->_threshold)) - AND ! isset($this->_threshold_array[$this->_levels[$level]])) + && ! isset($this->_threshold_array[$this->_levels[$level]])) { return FALSE; } @@ -125,15 +120,15 @@ class CI_Log { flock($fp, LOCK_UN); fclose($fp); - if (isset($newfile) AND $newfile === TRUE) + if (isset($newfile) && $newfile === TRUE) { @chmod($filepath, FILE_WRITE_MODE); } + return TRUE; } } -// END Log Class /* End of file Log.php */ -/* Location: ./system/libraries/Log.php */ +/* Location: ./system/libraries/Log.php */
\ No newline at end of file diff --git a/system/libraries/Migration.php b/system/libraries/Migration.php index c045ac0e2..a18fcb9f1 100644 --- a/system/libraries/Migration.php +++ b/system/libraries/Migration.php @@ -25,8 +25,6 @@ * @filesource */ -// ------------------------------------------------------------------------ - /** * Migration Class * @@ -71,7 +69,7 @@ class CI_Migration { } // If not set, set it - $this->_migration_path == '' AND $this->_migration_path = APPPATH.'migrations/'; + $this->_migration_path != '' OR $this->_migration_path = APPPATH.'migrations/'; // Add trailing slash if not set $this->_migration_path = rtrim($this->_migration_path, '/').'/'; @@ -101,7 +99,7 @@ class CI_Migration { } // Do we auto migrate to the latest migration? - if ($this->_migration_auto_latest === TRUE AND ! $this->latest()) + if ($this->_migration_auto_latest === TRUE && ! $this->latest()) { show_error($this->error_string()); } @@ -115,8 +113,7 @@ class CI_Migration { * Calls each migration step required to get to the schema version of * choice * - * @access public - * @param $version integer Target schema version + * @param int Target schema version * @return mixed TRUE if already latest, FALSE if failed, int if upgraded */ public function version($target_version) @@ -241,7 +238,6 @@ class CI_Migration { /** * Set's the schema to the latest migration * - * @access public * @return mixed true if already latest, false if failed, int if upgraded */ public function latest() @@ -264,7 +260,6 @@ class CI_Migration { /** * Set's the schema to the migration version set in config * - * @access public * @return mixed true if already current, false if failed, int if upgraded */ public function current() @@ -277,7 +272,6 @@ class CI_Migration { /** * Error string * - * @access public * @return string Error message returned as a string */ public function error_string() @@ -290,7 +284,6 @@ class CI_Migration { /** * Set's the schema to the latest migration * - * @access protected * @return mixed true if already latest, false if failed, int if upgraded */ protected function find_migrations() @@ -317,8 +310,7 @@ class CI_Migration { /** * Retrieves current schema version * - * @access protected - * @return integer Current Migration + * @return int Current Migration */ protected function _get_version() { @@ -331,9 +323,8 @@ class CI_Migration { /** * Stores the current schema version * - * @access protected - * @param $migrations integer Migration reached - * @return void Outputs a report of the migration + * @param int Migration reached + * @return void Outputs a report of the migration */ protected function _update_version($migrations) { @@ -347,8 +338,7 @@ class CI_Migration { /** * Enable the use of CI super-global * - * @access public - * @param $var + * @param $var * @return mixed */ public function __get($var) @@ -358,4 +348,4 @@ class CI_Migration { } /* End of file Migration.php */ -/* Location: ./system/libraries/Migration.php */ +/* Location: ./system/libraries/Migration.php */
\ No newline at end of file diff --git a/system/libraries/Pagination.php b/system/libraries/Pagination.php index 86b8d79fa..0fe73d69f 100644 --- a/system/libraries/Pagination.php +++ b/system/libraries/Pagination.php @@ -25,8 +25,6 @@ * @filesource */ -// ------------------------------------------------------------------------ - /** * Pagination Class * @@ -74,13 +72,12 @@ class CI_Pagination { /** * Constructor * - * @access public * @param array initialization parameters */ public function __construct($params = array()) { $this->initialize($params); - log_message('debug', "Pagination Class Initialized"); + log_message('debug', 'Pagination Class Initialized'); } // -------------------------------------------------------------------- @@ -88,7 +85,6 @@ class CI_Pagination { /** * Initialize Preferences * - * @access public * @param array initialization parameters * @return void */ @@ -116,7 +112,6 @@ class CI_Pagination { /** * Generate the pagination links * - * @access public * @return string */ public function create_links() @@ -155,13 +150,13 @@ class CI_Pagination { $this->cur_page = (int) $CI->input->get($this->query_string_segment); } } - elseif ( ! $this->cur_page AND $CI->uri->segment($this->uri_segment) != $base_page) + elseif ( ! $this->cur_page && $CI->uri->segment($this->uri_segment) != $base_page) { $this->cur_page = (int) $CI->uri->segment($this->uri_segment); } // Set current page to 1 if it's not valid or if using page numbers instead of offset - if ( ! is_numeric($this->cur_page) OR ($this->use_page_numbers AND $this->cur_page == 0)) + if ( ! is_numeric($this->cur_page) OR ($this->use_page_numbers && $this->cur_page == 0)) { $this->cur_page = $base_page; } @@ -182,12 +177,9 @@ class CI_Pagination { $this->cur_page = $num_pages; } } - else + elseif ($this->cur_page > $this->total_rows) { - if ($this->cur_page > $this->total_rows) - { - $this->cur_page = ($num_pages - 1) * $this->per_page; - } + $this->cur_page = ($num_pages - 1) * $this->per_page; } $uri_page_number = $this->cur_page; @@ -199,10 +191,10 @@ class CI_Pagination { // 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; + $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 + // 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) { @@ -217,18 +209,18 @@ 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 && $this->cur_page > ($this->num_links + 1)) { $first_url = ($this->first_url == '') ? $this->base_url : $this->first_url; $output .= $this->first_tag_open.'<a '.$this->anchor_class.'href="'.$first_url.'">'.$this->first_link.'</a>'.$this->first_tag_close; } // Render the "previous" link - if ($this->prev_link !== FALSE AND $this->cur_page != 1) + if ($this->prev_link !== FALSE && $this->cur_page != 1) { $i = ($this->use_page_numbers) ? $uri_page_number - 1 : $uri_page_number - $this->per_page; - if ($i == $base_page AND $this->first_url != '') + if ($i == $base_page && $this->first_url != '') { $output .= $this->prev_tag_open.'<a '.$this->anchor_class.'href="'.$this->first_url.'">'.$this->prev_link.'</a>'.$this->prev_tag_close; } @@ -274,7 +266,7 @@ class CI_Pagination { } // Render the "next" link - if ($this->next_link !== FALSE AND $this->cur_page < $num_pages) + if ($this->next_link !== FALSE && $this->cur_page < $num_pages) { $i = ($this->use_page_numbers) ? $this->cur_page + 1 : $this->cur_page * $this->per_page; @@ -282,7 +274,7 @@ class CI_Pagination { } // Render the "Last" link - if ($this->last_link !== FALSE AND ($this->cur_page + $this->num_links) < $num_pages) + if ($this->last_link !== FALSE && ($this->cur_page + $this->num_links) < $num_pages) { $i = ($this->use_page_numbers) ? $num_pages : ($num_pages * $this->per_page) - $this->per_page; @@ -291,15 +283,13 @@ 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 slashes. - $output = preg_replace("#([^:])//+#", "\\1/", $output); + $output = preg_replace('#([^:])//+#', '\\1/', $output); // Add the wrapper HTML if exists - $output = $this->full_tag_open.$output.$this->full_tag_close; - - return $output; + return $this->full_tag_open.$output.$this->full_tag_close; } + } -// END Pagination Class /* End of file Pagination.php */ -/* Location: ./system/libraries/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 290e17fc0..d1b5b764b 100644 --- a/system/libraries/Parser.php +++ b/system/libraries/Parser.php @@ -25,8 +25,6 @@ * @filesource */ -// ------------------------------------------------------------------------ - /** * Parser Class * @@ -41,15 +39,14 @@ class CI_Parser { public $l_delim = '{'; public $r_delim = '}'; public $object; - private $CI; + protected $CI; /** - * Parse a template + * Parse a template * * Parses pseudo-variables contained in the specified template view, * replacing them with the data in the second param * - * @access public * @param string * @param array * @param bool @@ -66,12 +63,11 @@ class CI_Parser { // -------------------------------------------------------------------- /** - * Parse a String + * 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 @@ -85,18 +81,17 @@ class CI_Parser { // -------------------------------------------------------------------- /** - * Parse a template + * Parse a template * * Parses pseudo-variables contained in the specified template, * replacing them with the data in the second param * - * @access private * @param string * @param array * @param bool * @return string */ - private function _parse($template, $data, $return = FALSE) + protected function _parse($template, $data, $return = FALSE) { if ($template == '') { @@ -126,9 +121,8 @@ class CI_Parser { // -------------------------------------------------------------------- /** - * Set the left/right variable delimiters + * Set the left/right variable delimiters * - * @access public * @param string * @param string * @return void @@ -142,15 +136,14 @@ class CI_Parser { // -------------------------------------------------------------------- /** - * Parse a single key/value + * Parse a single key/value * - * @access private * @param string * @param string * @param string * @return string */ - private function _parse_single($key, $val, $string) + protected function _parse_single($key, $val, $string) { return str_replace($this->l_delim.$key.$this->r_delim, (string) $val, $string); } @@ -158,17 +151,16 @@ class CI_Parser { // -------------------------------------------------------------------- /** - * Parse a tag pair + * Parse a tag pair * - * Parses tag pairs: {some_tag} string... {/some_tag} + * Parses tag pairs: {some_tag} string... {/some_tag} * - * @access private * @param string * @param array * @param string * @return string */ - private function _parse_pair($variable, $data, $string) + protected function _parse_pair($variable, $data, $string) { if (FALSE === ($match = $this->_match_pair($string, $variable))) { @@ -200,25 +192,20 @@ class CI_Parser { // -------------------------------------------------------------------- /** - * Matches a variable pair + * Matches a variable pair * - * @access private * @param string * @param string * @return mixed */ - private function _match_pair($string, $variable) + protected function _match_pair($string, $variable) { - if ( ! preg_match("|" . preg_quote($this->l_delim) . $variable . preg_quote($this->r_delim) . "(.+?)". preg_quote($this->l_delim) . '/' . $variable . preg_quote($this->r_delim) . "|s", $string, $match)) - { - return FALSE; - } - - return $match; + return 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) + ? $match : FALSE; } } -// END Parser Class /* End of file Parser.php */ -/* Location: ./system/libraries/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 d84e5d3fc..6320ab50d 100644 --- a/system/libraries/Profiler.php +++ b/system/libraries/Profiler.php @@ -25,8 +25,6 @@ * @filesource */ -// ------------------------------------------------------------------------ - /** * CodeIgniter Profiler Class * @@ -45,24 +43,22 @@ class CI_Profiler { protected $_available_sections = array( - 'benchmarks', - 'get', - 'memory_usage', - 'post', - 'uri_string', - 'controller_info', - 'queries', - 'http_headers', - 'session_data', - 'config' - ); + 'benchmarks', + 'get', + 'memory_usage', + 'post', + 'uri_string', + 'controller_info', + 'queries', + 'http_headers', + 'session_data', + 'config' + ); protected $_query_toggle_count = 25; protected $CI; - // -------------------------------------------------------------------- - public function __construct($config = array()) { $this->CI =& get_instance(); @@ -102,7 +98,7 @@ class CI_Profiler { { if (in_array($method, $this->_available_sections)) { - $this->_compile_{$method} = ($enable !== FALSE) ? TRUE : FALSE; + $this->_compile_{$method} = ($enable !== FALSE); } } } @@ -127,7 +123,7 @@ class CI_Profiler { // 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) - AND isset($this->CI->benchmark->marker[$match[1].'_end'], $this->CI->benchmark->marker[$match[1].'_start'])) + && isset($this->CI->benchmark->marker[$match[1].'_end'], $this->CI->benchmark->marker[$match[1].'_start'])) { $profile[$match[1]] = $this->CI->benchmark->elapsed_time($match[1].'_start', $key); } @@ -135,18 +131,20 @@ class CI_Profiler { // 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 + // be modified. We also might want to make this data available to be logged $output = "\n\n" - . '<fieldset id="ci_profiler_benchmarks" style="border:1px solid #900;padding:6px 10px 10px 10px;margin:20px 0 20px 0;background-color:#eee">' - . "\n" - . '<legend style="color:#900;"> '.$this->CI->lang->line('profiler_benchmarks').' </legend>' - . "\n\n\n<table style='width:100%'>\n"; + .'<fieldset id="ci_profiler_benchmarks" style="border:1px solid #900;padding:6px 10px 10px 10px;margin:20px 0 20px 0;background-color:#eee;">' + ."\n" + .'<legend style="color:#900;"> '.$this->CI->lang->line('profiler_benchmarks')." </legend>" + ."\n\n\n<table style=\"width:100%;\">\n"; foreach ($profile as $key => $val) { $key = ucwords(str_replace(array('_', '-'), ' ', $key)); - $output .= "<tr><td style='padding:5px;width:50%;color:#000;font-weight:bold;background-color:#ddd;'>".$key." </td><td style='padding:5px;width:50%;color:#900;font-weight:normal;background-color:#ddd;'>".$val."</td></tr>\n"; + $output .= '<tr><td style="padding:5px;width:50%;color:#000;font-weight:bold;background-color:#ddd;">' + .$key.' </td><td style="padding:5px;width:50%;color:#900;font-weight:normal;background-color:#ddd;">' + .$val."</td></tr>\n"; } return $output."</table>\n</fieldset>"; @@ -166,7 +164,7 @@ class CI_Profiler { // Let's determine which databases are currently connected to foreach (get_object_vars($this->CI) as $CI_object) { - if (is_object($CI_object) && is_subclass_of(get_class($CI_object), 'CI_DB') ) + if (is_object($CI_object) && is_subclass_of(get_class($CI_object), 'CI_DB')) { $dbs[] = $CI_object; } @@ -175,13 +173,13 @@ class CI_Profiler { if (count($dbs) === 0) { return "\n\n" - . '<fieldset id="ci_profiler_queries" style="border:1px solid #0000FF;padding:6px 10px 10px 10px;margin:20px 0 20px 0;background-color:#eee;">' - . "\n" - . '<legend style="color:#0000FF;"> '.$this->CI->lang->line('profiler_queries').' </legend>' - . "\n\n\n<table style='border:none; width:100%;'>\n" - . '<tr><td style="width:100%;color:#0000FF;font-weight:normal;background-color:#eee;padding:5px;">' - . $this->CI->lang->line('profiler_no_db') - . "</td></tr>\n</table>\n</fieldset>"; + .'<fieldset id="ci_profiler_queries" style="border:1px solid #0000FF;padding:6px 10px 10px 10px;margin:20px 0 20px 0;background-color:#eee;">' + ."\n" + .'<legend style="color:#0000FF;"> '.$this->CI->lang->line('profiler_queries').' </legend>' + ."\n\n\n<table style=\"border:none; width:100%;\">\n" + .'<tr><td style="width:100%;color:#0000FF;font-weight:normal;background-color:#eee;padding:5px;">' + .$this->CI->lang->line('profiler_no_db') + ."</td></tr>\n</table>\n</fieldset>"; } // Load the text helper so we can highlight the SQL @@ -191,7 +189,6 @@ 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) @@ -205,21 +202,23 @@ class CI_Profiler { $show_hide_js = '(<span style="cursor: pointer;" onclick="var s=document.getElementById(\'ci_profiler_queries_db_'.$count.'\').style;s.display=s.display==\'none\'?\'\':\'none\';this.innerHTML=this.innerHTML==\''.$this->CI->lang->line('profiler_section_show').'\'?\''.$this->CI->lang->line('profiler_section_hide').'\':\''.$this->CI->lang->line('profiler_section_show').'\';">'.$this->CI->lang->line('profiler_section_show').'</span>)'; } - $output .= '<fieldset style="border:1px solid #0000FF;padding:6px 10px 10px 10px;margin:20px 0 20px 0;background-color:#eee">' - . "\n" - . '<legend style="color:#0000FF;"> '.$this->CI->lang->line('profiler_database').': '.$db->database.' '.$this->CI->lang->line('profiler_queries').': '.count($db->queries).' '.$show_hide_js.'</legend>' - . "\n\n\n<table style='width:100%;{$hide_queries}' id='ci_profiler_queries_db_{$count}'>\n"; + $output .= '<fieldset style="border:1px solid #0000FF;padding:6px 10px 10px 10px;margin:20px 0 20px 0;background-color:#eee;">' + ."\n" + .'<legend style="color:#0000FF;"> '.$this->CI->lang->line('profiler_database') + .': '.$db->database.' '.$this->CI->lang->line('profiler_queries') + .': '.count($db->queries).' '.$show_hide_js."</legend>\n\n\n" + .'<table style="width:100%;'.$hide_queries.'" id="ci_profiler_queries_db_'.$count."\">\n"; if (count($db->queries) === 0) { - $output .= "<tr><td style='width:100%;color:#0000FF;font-weight:normal;background-color:#eee;padding:5px;'>".$this->CI->lang->line('profiler_no_queries')."</td></tr>\n"; + $output .= '<tr><td style="width:100%;color:#0000FF;font-weight:normal;background-color:#eee;padding:5px;">' + .$this->CI->lang->line('profiler_no_queries')."</td></tr>\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) @@ -227,18 +226,18 @@ class CI_Profiler { $val = str_replace($bold, '<strong>'.$bold.'</strong>', $val); } - $output .= "<tr><td style='padding:5px; vertical-align: top;width:1%;color:#900;font-weight:normal;background-color:#ddd;'>".$time." </td><td style='padding:5px; color:#000;font-weight:normal;background-color:#ddd;'>".$val."</td></tr>\n"; + $output .= '<tr><td style="padding:5px;vertical-align:top;width:1%;color:#900;font-weight:normal;background-color:#ddd;">' + .$time.' </td><td style="padding:5px;color:#000;font-weight:normal;background-color:#ddd;">' + .$val."</td></tr>\n"; } } $output .= "</table>\n</fieldset>"; - } return $output; } - // -------------------------------------------------------------------- /** @@ -248,19 +247,18 @@ class CI_Profiler { */ protected function _compile_get() { - $output = "\n\n" - . '<fieldset id="ci_profiler_get" style="border:1px solid #cd6e00;padding:6px 10px 10px 10px;margin:20px 0 20px 0;background-color:#eee">' - . "\n" - . '<legend style="color:#cd6e00;"> '.$this->CI->lang->line('profiler_get_data').' </legend>' - . "\n"; + $output = "\n\n" + .'<fieldset id="ci_profiler_get" style="border:1px solid #cd6e00;padding:6px 10px 10px 10px;margin:20px 0 20px 0;background-color:#eee;">' + ."\n" + .'<legend style="color:#cd6e00;"> '.$this->CI->lang->line('profiler_get_data')." </legend>\n"; if (count($_GET) === 0) { - $output .= "<div style='color:#cd6e00;font-weight:normal;padding:4px 0 4px 0'>".$this->CI->lang->line('profiler_no_get')."</div>"; + $output .= '<div style="color:#cd6e00;font-weight:normal;padding:4px 0 4px 0;">'.$this->CI->lang->line('profiler_no_get').'</div>'; } else { - $output .= "\n\n<table style='width:100%; border:none'>\n"; + $output .= "\n\n<table style=\"width:100%;border:none;\">\n"; foreach ($_GET as $key => $val) { @@ -269,9 +267,10 @@ class CI_Profiler { $key = "'".$key."'"; } - $output .= "<tr><td style='width:50%;color:#000;background-color:#ddd;padding:5px'>$_GET[".$key."] </td><td style='width:50%;padding:5px;color:#cd6e00;font-weight:normal;background-color:#ddd;'>" - . ((is_array($val) OR is_object($val)) ? "<pre>" . htmlspecialchars(stripslashes(print_r($val, true))) . "</pre>" : htmlspecialchars(stripslashes($val))) - . "</td></tr>\n"; + $output .= '<tr><td style="width:50%;color:#000;background-color:#ddd;padding:5px;">$_GET[' + .$key.'] </td><td style="width:50%;padding:5px;color:#cd6e00;font-weight:normal;background-color:#ddd;">' + .((is_array($val) OR is_object($val)) ? '<pre>'.htmlspecialchars(stripslashes(print_r($val, TRUE))).'</pre>' : htmlspecialchars(stripslashes($val))) + ."</td></tr>\n"; } $output .= "</table>\n"; @@ -290,18 +289,17 @@ class CI_Profiler { protected function _compile_post() { $output = "\n\n" - . '<fieldset id="ci_profiler_post" style="border:1px solid #009900;padding:6px 10px 10px 10px;margin:20px 0 20px 0;background-color:#eee">' - . "\n" - . '<legend style="color:#009900;"> '.$this->CI->lang->line('profiler_post_data').' </legend>' - . "\n"; + .'<fieldset id="ci_profiler_post" style="border:1px solid #009900;padding:6px 10px 10px 10px;margin:20px 0 20px 0;background-color:#eee;">' + ."\n" + .'<legend style="color:#009900;"> '.$this->CI->lang->line('profiler_post_data')." </legend>\n"; if (count($_POST) == 0) { - $output .= "<div style='color:#009900;font-weight:normal;padding:4px 0 4px 0'>".$this->CI->lang->line('profiler_no_post')."</div>"; + $output .= '<div style="color:#009900;font-weight:normal;padding:4px 0 4px 0;">'.$this->CI->lang->line('profiler_no_post').'</div>'; } else { - $output .= "\n\n<table style='width:100%'>\n"; + $output .= "\n\n<table style=\"width:100%;\">\n"; foreach ($_POST as $key => $val) { @@ -310,15 +308,18 @@ class CI_Profiler { $key = "'".$key."'"; } - $output .= "<tr><td style='width:50%;padding:5px;color:#000;background-color:#ddd;'>$_POST[".$key."] </td><td style='width:50%;padding:5px;color:#009900;font-weight:normal;background-color:#ddd;'>"; + $output .= '<tr><td style="width:50%;padding:5px;color:#000;background-color:#ddd;">$_POST[' + .$key.'] </td><td style="width:50%;padding:5px;color:#009900;font-weight:normal;background-color:#ddd;">'; + if (is_array($val) OR is_object($val)) { - $output .= "<pre>" . htmlspecialchars(stripslashes(print_r($val, TRUE))) . "</pre>"; + $output .= '<pre>'.htmlspecialchars(stripslashes(print_r($val, TRUE))).'</pre>'; } else { $output .= htmlspecialchars(stripslashes($val)); } + $output .= "</td></tr>\n"; } @@ -338,12 +339,12 @@ class CI_Profiler { protected function _compile_uri_string() { return "\n\n" - . '<fieldset id="ci_profiler_uri_string" style="border:1px solid #000;padding:6px 10px 10px 10px;margin:20px 0 20px 0;background-color:#eee">' - . "\n" - . '<legend style="color:#000;"> '.$this->CI->lang->line('profiler_uri_string').' </legend>' - . "\n<div style='color:#000;font-weight:normal;padding:4px 0 4px 0'>" - . ($this->CI->uri->uri_string == '' ? $this->CI->lang->line('profiler_no_uri') : $this->CI->uri->uri_string) - . '</div></fieldset>'; + .'<fieldset id="ci_profiler_uri_string" style="border:1px solid #000;padding:6px 10px 10px 10px;margin:20px 0 20px 0;background-color:#eee;">' + ."\n" + .'<legend style="color:#000;"> '.$this->CI->lang->line('profiler_uri_string')." </legend>\n" + .'<div style="color:#000;font-weight:normal;padding:4px 0 4px 0;">' + .($this->CI->uri->uri_string == '' ? $this->CI->lang->line('profiler_no_uri') : $this->CI->uri->uri_string) + .'</div></fieldset>'; } // -------------------------------------------------------------------- @@ -356,11 +357,11 @@ class CI_Profiler { protected function _compile_controller_info() { return "\n\n" - . '<fieldset id="ci_profiler_controller_info" style="border:1px solid #995300;padding:6px 10px 10px 10px;margin:20px 0 20px 0;background-color:#eee">' - . "\n" - . '<legend style="color:#995300;"> '.$this->CI->lang->line('profiler_controller_info').' </legend>' - . "\n<div style='color:#995300;font-weight:normal;padding:4px 0 4px 0'>".$this->CI->router->fetch_class().'/'.$this->CI->router->fetch_method() - . '</div></fieldset>'; + .'<fieldset id="ci_profiler_controller_info" style="border:1px solid #995300;padding:6px 10px 10px 10px;margin:20px 0 20px 0;background-color:#eee;">' + ."\n" + .'<legend style="color:#995300;"> '.$this->CI->lang->line('profiler_controller_info')." </legend>\n" + .'<div style="color:#995300;font-weight:normal;padding:4px 0 4px 0;">'.$this->CI->router->fetch_class().'/'.$this->CI->router->fetch_method() + .'</div></fieldset>'; } // -------------------------------------------------------------------- @@ -375,12 +376,12 @@ class CI_Profiler { protected function _compile_memory_usage() { return "\n\n" - . '<fieldset id="ci_profiler_memory_usage" style="border:1px solid #5a0099;padding:6px 10px 10px 10px;margin:20px 0 20px 0;background-color:#eee">' - . "\n" - . '<legend style="color:#5a0099;"> '.$this->CI->lang->line('profiler_memory_usage').' </legend>' - . "\n<div style='color:#5a0099;font-weight:normal;padding:4px 0 4px 0'>" - . ((function_exists('memory_get_usage') && ($usage = memory_get_usage()) != '') ? number_format($usage).' bytes' : $this->CI->lang->line('profiler_no_memory')) - . '</div></fieldset>'; + .'<fieldset id="ci_profiler_memory_usage" style="border:1px solid #5a0099;padding:6px 10px 10px 10px;margin:20px 0 20px 0;background-color:#eee;">' + ."\n" + .'<legend style="color:#5a0099;"> '.$this->CI->lang->line('profiler_memory_usage')." </legend>\n" + .'<div style="color:#5a0099;font-weight:normal;padding:4px 0 4px 0;">' + .((function_exists('memory_get_usage') && ($usage = memory_get_usage()) != '') ? number_format($usage).' bytes' : $this->CI->lang->line('profiler_no_memory')) + .'</div></fieldset>'; } // -------------------------------------------------------------------- @@ -395,15 +396,17 @@ class CI_Profiler { protected function _compile_http_headers() { $output = "\n\n" - . '<fieldset id="ci_profiler_http_headers" style="border:1px solid #000;padding:6px 10px 10px 10px;margin:20px 0 20px 0;background-color:#eee">' - . "\n" - . '<legend style="color:#000;"> '.$this->CI->lang->line('profiler_headers').' (<span style="cursor: pointer;" onclick="var s=document.getElementById(\'ci_profiler_httpheaders_table\').style;s.display=s.display==\'none\'?\'\':\'none\';this.innerHTML=this.innerHTML==\''.$this->CI->lang->line('profiler_section_show').'\'?\''.$this->CI->lang->line('profiler_section_hide').'\':\''.$this->CI->lang->line('profiler_section_show').'\';">'.$this->CI->lang->line('profiler_section_show').'</span>)</legend>' - . "\n\n\n<table style='width:100%;display:none' id='ci_profiler_httpheaders_table'>\n"; + .'<fieldset id="ci_profiler_http_headers" style="border:1px solid #000;padding:6px 10px 10px 10px;margin:20px 0 20px 0;background-color:#eee;">' + ."\n" + .'<legend style="color:#000;"> '.$this->CI->lang->line('profiler_headers') + .' (<span style="cursor: pointer;" onclick="var s=document.getElementById(\'ci_profiler_httpheaders_table\').style;s.display=s.display==\'none\'?\'\':\'none\';this.innerHTML=this.innerHTML==\''.$this->CI->lang->line('profiler_section_show').'\'?\''.$this->CI->lang->line('profiler_section_hide').'\':\''.$this->CI->lang->line('profiler_section_show').'\';">'.$this->CI->lang->line('profiler_section_show')."</span>)</legend>\n\n\n" + .'<table style="width:100%;display:none;" id="ci_profiler_httpheaders_table">'."\n"; foreach (array('HTTP_ACCEPT', 'HTTP_USER_AGENT', 'HTTP_CONNECTION', 'SERVER_PORT', 'SERVER_NAME', 'REMOTE_ADDR', 'SERVER_SOFTWARE', 'HTTP_ACCEPT_LANGUAGE', 'SCRIPT_NAME', 'REQUEST_METHOD',' HTTP_HOST', 'REMOTE_HOST', 'CONTENT_TYPE', 'SERVER_PROTOCOL', 'QUERY_STRING', 'HTTP_ACCEPT_ENCODING', 'HTTP_X_FORWARDED_FOR') as $header) { - $val = (isset($_SERVER[$header])) ? $_SERVER[$header] : ''; - $output .= "<tr><td style='vertical-align: top;width:50%;padding:5px;color:#900;background-color:#ddd;'>".$header." </td><td style='width:50%;padding:5px;color:#000;background-color:#ddd;'>".$val."</td></tr>\n"; + $val = isset($_SERVER[$header]) ? $_SERVER[$header] : ''; + $output .= '<tr><td style="vertical-align:top;width:50%;padding:5px;color:#900;background-color:#ddd;">' + .$header.' </td><td style="width:50%;padding:5px;color:#000;background-color:#ddd;">'.$val."</td></tr>\n"; } return $output."</table>\n</fieldset>"; @@ -421,10 +424,10 @@ class CI_Profiler { protected function _compile_config() { $output = "\n\n" - . '<fieldset id="ci_profiler_config" style="border:1px solid #000;padding:6px 10px 10px 10px;margin:20px 0 20px 0;background-color:#eee">' - . "\n" - . '<legend style="color:#000;"> '.$this->CI->lang->line('profiler_config').' (<span style="cursor: pointer;" onclick="var s=document.getElementById(\'ci_profiler_config_table\').style;s.display=s.display==\'none\'?\'\':\'none\';this.innerHTML=this.innerHTML==\''.$this->CI->lang->line('profiler_section_show').'\'?\''.$this->CI->lang->line('profiler_section_hide').'\':\''.$this->CI->lang->line('profiler_section_show').'\';">'.$this->CI->lang->line('profiler_section_show').'</span>)</legend>' - . "\n\n\n<table style='width:100%; display:none' id='ci_profiler_config_table'>\n"; + .'<fieldset id="ci_profiler_config" style="border:1px solid #000;padding:6px 10px 10px 10px;margin:20px 0 20px 0;background-color:#eee;">' + ."\n" + .'<legend style="color:#000;"> '.$this->CI->lang->line('profiler_config').' (<span style="cursor: pointer;" onclick="var s=document.getElementById(\'ci_profiler_config_table\').style;s.display=s.display==\'none\'?\'\':\'none\';this.innerHTML=this.innerHTML==\''.$this->CI->lang->line('profiler_section_show').'\'?\''.$this->CI->lang->line('profiler_section_hide').'\':\''.$this->CI->lang->line('profiler_section_show').'\';">'.$this->CI->lang->line('profiler_section_show')."</span>)</legend>\n\n\n" + .'<table style="width:100%;display:none;" id="ci_profiler_config_table">'."\n"; foreach ($this->CI->config->config as $config => $val) { @@ -433,7 +436,8 @@ class CI_Profiler { $val = print_r($val, TRUE); } - $output .= "<tr><td style='padding:5px; vertical-align: top;color:#900;background-color:#ddd;'>".$config." </td><td style='padding:5px; color:#000;background-color:#ddd;'>".htmlspecialchars($val)."</td></tr>\n"; + $output .= '<tr><td style="padding:5px;vertical-align:top;color:#900;background-color:#ddd;">' + .$config.' </td><td style="padding:5px;color:#000;background-color:#ddd;">'.htmlspecialchars($val)."</td></tr>\n"; } return $output."</table>\n</fieldset>"; @@ -453,9 +457,9 @@ class CI_Profiler { return; } - $output = '<fieldset id="ci_profiler_csession" style="border:1px solid #000;padding:6px 10px 10px 10px;margin:20px 0 20px 0;background-color:#eee">' - . '<legend style="color:#000;"> '.$this->CI->lang->line('profiler_session_data').' (<span style="cursor: pointer;" onclick="var s=document.getElementById(\'ci_profiler_session_data\').style;s.display=s.display==\'none\'?\'\':\'none\';this.innerHTML=this.innerHTML==\''.$this->CI->lang->line('profiler_section_show').'\'?\''.$this->CI->lang->line('profiler_section_hide').'\':\''.$this->CI->lang->line('profiler_section_show').'\';">'.$this->CI->lang->line('profiler_section_show').'</span>)</legend>' - . "<table style='width:100%;display:none' id='ci_profiler_session_data'>"; + $output = '<fieldset id="ci_profiler_csession" style="border:1px solid #000;padding:6px 10px 10px 10px;margin:20px 0 20px 0;background-color:#eee;">' + .'<legend style="color:#000;"> '.$this->CI->lang->line('profiler_session_data').' (<span style="cursor: pointer;" onclick="var s=document.getElementById(\'ci_profiler_session_data\').style;s.display=s.display==\'none\'?\'\':\'none\';this.innerHTML=this.innerHTML==\''.$this->CI->lang->line('profiler_section_show').'\'?\''.$this->CI->lang->line('profiler_section_hide').'\':\''.$this->CI->lang->line('profiler_section_show').'\';">'.$this->CI->lang->line('profiler_section_show').'</span>)</legend>' + .'<table style="width:100%;display:none;" id="ci_profiler_session_data">'; foreach ($this->CI->session->all_userdata() as $key => $val) { @@ -464,7 +468,8 @@ class CI_Profiler { $val = print_r($val, TRUE); } - $output .= "<tr><td style='padding:5px; vertical-align: top;color:#900;background-color:#ddd;'>".$key." </td><td style='padding:5px; color:#000;background-color:#ddd;'>".htmlspecialchars($val)."</td></tr>\n"; + $output .= '<tr><td style="padding:5px;vertical-align:top;color:#900;background-color:#ddd;">' + .$key.' </td><td style="padding:5px;color:#000;background-color:#ddd;">'.htmlspecialchars($val)."</td></tr>\n"; } return $output."</table>\n</fieldset>"; @@ -479,14 +484,14 @@ class CI_Profiler { */ public function run() { - $output = "<div id='codeigniter_profiler' style='clear:both;background-color:#fff;padding:10px;'>"; + $output = '<div id="codeigniter_profiler" style="clear:both;background-color:#fff;padding:10px;">'; $fields_displayed = 0; foreach ($this->_available_sections as $section) { if ($this->_compile_{$section} !== FALSE) { - $func = "_compile_{$section}"; + $func = '_compile_'.$section; $output .= $this->{$func}(); $fields_displayed++; } @@ -494,7 +499,8 @@ class CI_Profiler { if ($fields_displayed === 0) { - $output .= '<p style="border:1px solid #5a0099;padding:10px;margin:20px 0;background-color:#eee">'.$this->CI->lang->line('profiler_no_profiles').'</p>'; + $output .= '<p style="border:1px solid #5a0099;padding:10px;margin:20px 0;background-color:#eee;">' + .$this->CI->lang->line('profiler_no_profiles').'</p>'; } return $output.'</div>'; @@ -502,4 +508,4 @@ class CI_Profiler { } /* End of file Profiler.php */ -/* Location: ./system/libraries/Profiler.php */ +/* Location: ./system/libraries/Profiler.php */
\ No newline at end of file diff --git a/system/libraries/Session.php b/system/libraries/Session.php index 3a80c1626..3515764ce 100644 --- a/system/libraries/Session.php +++ b/system/libraries/Session.php @@ -469,21 +469,21 @@ class CI_Session { { return $this->userdata; } - + // -------------------------------------------------------------------------- - + /** * Fetch all flashdata - * + * * @return array */ public function all_flashdata() { $out = array(); - + // loop through all userdata foreach ($this->all_userdata() as $key => $val) - { + { // if it contains flashdata, add it if (strpos($key, 'flash:old:') !== FALSE) { @@ -816,4 +816,4 @@ class CI_Session { } /* End of file Session.php */ -/* Location: ./system/libraries/Session.php */ +/* Location: ./system/libraries/Session.php */
\ No newline at end of file diff --git a/system/libraries/Table.php b/system/libraries/Table.php index 11a4858a9..3777d29ff 100644 --- a/system/libraries/Table.php +++ b/system/libraries/Table.php @@ -38,14 +38,14 @@ */ class CI_Table { - public $rows = array(); - public $heading = array(); - public $auto_heading = TRUE; - public $caption = NULL; - public $template = NULL; - public $newline = "\n"; - public $empty_cells = ''; - public $function = FALSE; + public $rows = array(); + public $heading = array(); + public $auto_heading = TRUE; + public $caption = NULL; + public $template = NULL; + public $newline = "\n"; + public $empty_cells = ''; + public $function = FALSE; /** * Set the template from the table config file if it exists @@ -55,13 +55,13 @@ class CI_Table { */ public function __construct($config = array()) { - log_message('debug', 'Table Class Initialized'); - // initialize config foreach ($config as $key => $val) { $this->template[$key] = $val; } + + log_message('debug', 'Table Class Initialized'); } // -------------------------------------------------------------------- @@ -70,7 +70,7 @@ class CI_Table { * Set the template * * @param array - * @return void + * @return bool */ public function set_template($template) { @@ -80,6 +80,7 @@ class CI_Table { } $this->template = $template; + return TRUE; } // -------------------------------------------------------------------- @@ -101,9 +102,9 @@ class CI_Table { // -------------------------------------------------------------------- /** - * Set columns. Takes a one-dimensional array as input and creates + * 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 + * columns. This allows a single array with many elements to be * displayed in a table that has a fixed column count. * * @param array @@ -184,29 +185,22 @@ class CI_Table { * * Ensures a standard associative array format for all cell data * - * @param type - * @return type + * @param array + * @return array */ protected function _prep_args($args) { // If there is no $args[0], skip this and treat as an associative array // This can happen if there is only a single key, for example this is passed to table->generate // array(array('foo'=>'bar')) - if (isset($args[0]) AND (count($args) === 1 && is_array($args[0]))) + if (isset($args[0]) && 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); - } + $args[$key] = (is_array($val) && isset($val['data'])) ? $val : array('data' => $val); } } } @@ -257,13 +251,13 @@ class CI_Table { } elseif (is_array($table_data)) { - $set_heading = (count($this->heading) === 0 AND $this->auto_heading == FALSE) ? FALSE : TRUE; + $set_heading = (count($this->heading) !== 0 OR $this->auto_heading != FALSE); $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) + // Is there anything to display? No? Smite them! + if (count($this->heading) === 0 && count($this->rows) === 0) { return 'Undefined table data'; } @@ -297,7 +291,7 @@ class CI_Table { { if ($key != 'data') { - $temp = str_replace('<th', "<th $key='$val'", $temp); + $temp = str_replace('<th', '<th '.$key.'="'.$val.'"', $temp); } } @@ -321,7 +315,7 @@ class CI_Table { } // We use modulus to alternate the row colors - $name = (fmod($i++, 2)) ? '' : 'alt_'; + $name = fmod($i++, 2) ? '' : 'alt_'; $out .= $this->template['row_'.$name.'start'].$this->newline; @@ -333,27 +327,24 @@ class CI_Table { { if ($key !== 'data') { - $temp = str_replace('<td', "<td $key='$val'", $temp); + $temp = str_replace('<td', '<td '.$key.'="'.$val.'"', $temp); } } $cell = isset($cell['data']) ? $cell['data'] : ''; $out .= $temp; - if ($cell === "" OR $cell === NULL) + if ($cell === '' OR $cell === NULL) { $out .= $this->empty_cells; } + elseif ($function !== FALSE && is_callable($function)) + { + $out .= call_user_func($function, $cell); + } else { - if ($function !== FALSE && is_callable($function)) - { - $out .= call_user_func($function, $cell); - } - else - { - $out .= $cell; - } + $out .= $cell; } $out .= $this->template['cell_'.$name.'end']; @@ -382,9 +373,9 @@ class CI_Table { */ public function clear() { - $this->rows = array(); - $this->heading = array(); - $this->auto_heading = TRUE; + $this->rows = array(); + $this->heading = array(); + $this->auto_heading = TRUE; } // -------------------------------------------------------------------- @@ -399,7 +390,7 @@ class CI_Table { { if ( ! is_object($query)) { - return FALSE; + return; } // First generate the headings from the table column names @@ -407,14 +398,13 @@ class CI_Table { { if ( ! is_callable(array($query, 'list_fields'))) { - return FALSE; + return; } $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) @@ -443,7 +433,7 @@ class CI_Table { foreach ($data as $row) { // If a heading hasn't already been set we'll use the first row of the array as the heading - if ($i++ === 0 AND count($data) > 1 AND count($this->heading) === 0 AND $set_heading == TRUE) + if ($i++ === 0 && count($data) > 1 && count($this->heading) === 0 && $set_heading == TRUE) { $this->heading = $this->_prep_args($row); } @@ -488,36 +478,35 @@ class CI_Table { */ protected function _default_template() { - return array ( - 'table_open' => '<table border="0" cellpadding="4" cellspacing="0">', + return array( + 'table_open' => '<table border="0" cellpadding="4" cellspacing="0">', - 'thead_open' => '<thead>', - 'thead_close' => '</thead>', + 'thead_open' => '<thead>', + 'thead_close' => '</thead>', - 'heading_row_start' => '<tr>', - 'heading_row_end' => '</tr>', - 'heading_cell_start' => '<th>', - 'heading_cell_end' => '</th>', + 'heading_row_start' => '<tr>', + 'heading_row_end' => '</tr>', + 'heading_cell_start' => '<th>', + 'heading_cell_end' => '</th>', - 'tbody_open' => '<tbody>', - 'tbody_close' => '</tbody>', + 'tbody_open' => '<tbody>', + 'tbody_close' => '</tbody>', - 'row_start' => '<tr>', - 'row_end' => '</tr>', - 'cell_start' => '<td>', - 'cell_end' => '</td>', + 'row_start' => '<tr>', + 'row_end' => '</tr>', + 'cell_start' => '<td>', + 'cell_end' => '</td>', - 'row_alt_start' => '<tr>', - 'row_alt_end' => '</tr>', - 'cell_alt_start' => '<td>', - 'cell_alt_end' => '</td>', + 'row_alt_start' => '<tr>', + 'row_alt_end' => '</tr>', + 'cell_alt_start' => '<td>', + 'cell_alt_end' => '</td>', - 'table_close' => '</table>' - ); + 'table_close' => '</table>' + ); } - } /* End of file Table.php */ -/* Location: ./system/libraries/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 be1de6f3f..6761f63a5 100644 --- a/system/libraries/Trackback.php +++ b/system/libraries/Trackback.php @@ -25,8 +25,6 @@ * @filesource */ -// ------------------------------------------------------------------------ - /** * Trackback Class * @@ -49,7 +47,7 @@ class CI_Trackback { public function __construct() { - log_message('debug', "Trackback Class Initialized"); + log_message('debug', 'Trackback Class Initialized'); } // -------------------------------------------------------------------- @@ -97,9 +95,10 @@ class CI_Trackback { } // Build the Trackback data string - $charset = ( ! isset($tb_data['charset'])) ? $this->charset : $tb_data['charset']; + $charset = isset($tb_data['charset']) ? $tb_data['charset'] : $this->charset; - $data = "url=".rawurlencode($url)."&title=".rawurlencode($title)."&blog_name=".rawurlencode($blog_name)."&excerpt=".rawurlencode($excerpt)."&charset=".rawurlencode($charset); + $data = 'url='.rawurlencode($url).'&title='.rawurlencode($title).'&blog_name='.rawurlencode($blog_name) + .'&excerpt='.rawurlencode($excerpt).'&charset='.rawurlencode($charset); // Send Trackback(s) $return = TRUE; @@ -139,7 +138,7 @@ class CI_Trackback { return FALSE; } - $this->data['charset'] = ( ! isset($_POST['charset'])) ? 'auto' : strtoupper(trim($_POST['charset'])); + $this->data['charset'] = isset($_POST['charset']) ? strtoupper(trim($_POST['charset'])) : 'auto'; if ($val != 'url' && MB_ENABLED === TRUE) { @@ -164,7 +163,7 @@ class CI_Trackback { /** * Send Trackback Error Message * - * Allows custom errors 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. * @@ -173,7 +172,7 @@ class CI_Trackback { */ public function send_error($message = 'Incomplete Information') { - echo "<?xml version=\"1.0\" encoding=\"utf-8\"?".">\n<response>\n<error>1</error>\n<message>".$message."</message>\n</response>"; + echo '<?xml version="1.0" encoding="utf-8"?'.">\n<response>\n<error>1</error>\n<message>".$message."</message>\n</response>"; exit; } @@ -189,7 +188,7 @@ class CI_Trackback { */ public function send_success() { - echo "<?xml version=\"1.0\" encoding=\"utf-8\"?".">\n<response>\n<error>0</error>\n</response>"; + echo '<?xml version="1.0" encoding="utf-8"?'.">\n<response>\n<error>0</error>\n</response>"; exit; } @@ -203,7 +202,7 @@ class CI_Trackback { */ public function data($item) { - return ( ! isset($this->data[$item])) ? '' : $this->data[$item]; + return isset($this->data[$item]) ? $this->data[$item] : ''; } // -------------------------------------------------------------------- @@ -212,7 +211,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 * * @param string * @param string @@ -230,37 +229,36 @@ class CI_Trackback { } // Build the path - $ppath = ( ! isset($target['path'])) ? $url : $target['path']; + $ppath = isset($target['path']) ? $target['path'] : $url; - $path = (isset($target['query']) && $target['query'] != "") ? $ppath.'?'.$target['query'] : $ppath; + $path = empty($target['query']) ? $ppath : $ppath.'?'.$target['query']; // Add the Trackback ID to the data string if ($id = $this->get_id($url)) { - $data = "tb_id=".$id."&".$data; + $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); + 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 = ""; + $this->response = ''; while ( ! feof($fp)) { $this->response .= fgets($fp, 128); } @fclose($fp); - if (stripos($this->response, '<error>0</error>') === FALSE) { - $message = (preg_match('/<message>(.*?)<\/message>/is', $this->response, $match)) ? trim($match[1]) : 'An unknown error was encountered'; + $message = preg_match('/<message>(.*?)<\/message>/is', $this->response, $match) ? trim($match[1]) : 'An unknown error was encountered'; $this->set_error($message); return FALSE; } @@ -282,11 +280,8 @@ class CI_Trackback { */ public 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 the pesky white space and replace with a comma, then replace doubles. + $urls = str_replace(',,', ',', preg_replace('/\s*(\S+)\s*/', '\\1,', $urls)); // Remove any comma that might be at the end if (substr($urls, -1) === ',') @@ -294,11 +289,8 @@ class CI_Trackback { $urls = substr($urls, 0, -1); } - // Break into an array via commas - $urls = preg_split('/[,]/', $urls); - - // Removes duplicates - $urls = array_unique($urls); + // Break into an array via commas and remove duplicates + $urls = array_unique(preg_split('/[,]/', $urls)); array_walk($urls, array($this, 'validate_url')); @@ -313,9 +305,9 @@ class CI_Trackback { * Simply adds "http://" if missing * * @param string - * @return string + * @return void */ - public function validate_url($url) + public function validate_url(&$url) { $url = trim($url); @@ -335,7 +327,7 @@ class CI_Trackback { */ public function get_id($url) { - $tb_id = ""; + $tb_id = ''; if (strpos($url, '?') !== FALSE) { @@ -359,18 +351,11 @@ class CI_Trackback { if ( ! is_numeric($tb_id)) { - $tb_id = $tb_array[count($tb_array)-2]; + $tb_id = $tb_array[count($tb_array)-2]; } } - if ( ! preg_match ("/^([0-9]+)$/", $tb_id)) - { - return FALSE; - } - else - { - return $tb_id; - } + return preg_match('/^[0-9]+$/', $tb_id) ? $tb_id : FALSE; } // -------------------------------------------------------------------- @@ -385,15 +370,13 @@ class CI_Trackback { { $temp = '__TEMP_AMPERSANDS__'; - $str = preg_replace(array('/&#(\d+);/', '/&(\w+);/'), "$temp\\1;", $str); - - $str = str_replace(array("&","<",">","\"", "'", "-"), - array("&", "<", ">", """, "'", "-"), - $str); + $str = preg_replace(array('/&#(\d+);/', '/&(\w+);/'), $temp.'\\1;', $str); - $str = preg_replace(array("/$temp(\d+);/", "/$temp(\w+);/"), array('&#\\1;', '&\\1;'), $str); + $str = str_replace(array('&', '<', '>', '"', "'", '-'), + array('&', '<', '>', '"', ''', '-'), + $str); - return $str; + return preg_replace(array('/'.$temp.'(\d+);/', '/'.$temp.'(\w+);/'), array('&#\\1;', '&\\1;'), $str); } // -------------------------------------------------------------------- @@ -404,7 +387,7 @@ class CI_Trackback { * Limits the string based on the character count. Will preserve complete words. * * @param string - * @param integer + * @param int * @param string * @return string */ @@ -415,7 +398,7 @@ class CI_Trackback { return $str; } - $str = preg_replace("/\s+/", ' ', str_replace(array("\r\n", "\r", "\n"), ' ', $str)); + $str = preg_replace('/\s+/', ' ', str_replace(array("\r\n", "\r", "\n"), ' ', $str)); if (strlen($str) <= $n) { @@ -469,7 +452,9 @@ class CI_Trackback { 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); + $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; @@ -506,11 +491,10 @@ class CI_Trackback { */ public function display_errors($open = '<p>', $close = '</p>') { - return (count($this->error_msg) > 0) ? $open . implode($close . $open, $this->error_msg) . $close : ''; + return (count($this->error_msg) > 0) ? $open.implode($close.$open, $this->error_msg).$close : ''; } } -// END Trackback Class /* End of file Trackback.php */ -/* Location: ./system/libraries/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 65e30b089..21bbad038 100644 --- a/system/libraries/Typography.php +++ b/system/libraries/Typography.php @@ -25,13 +25,11 @@ * @filesource */ -// ------------------------------------------------------------------------ - /** * Typography Class * - * - * @access protected + * @package CodeIgniter + * @subpackage Libraries * @category Helpers * @author EllisLab Dev Team * @link http://codeigniter.com/user_guide/libraries/typography.html @@ -67,7 +65,6 @@ class CI_Typography { * - 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 @@ -94,15 +91,12 @@ class CI_Typography { // 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, '<!--') !== FALSE) + if (strpos($str, '<!--') !== FALSE && preg_match_all('#(<!\-\-.*?\-\->)#s', $str, $matches)) { - if (preg_match_all("#(<!\-\-.*?\-\->)#s", $str, $matches)) + for ($i = 0, $total = count($matches[0]); $i < $total; $i++) { - for ($i = 0, $total = count($matches[0]); $i < $total; $i++) - { - $html_comments[] = $matches[0][$i]; - $str = str_replace($matches[0][$i], '{@HC'.$i.'}', $str); - } + $html_comments[] = $matches[0][$i]; + $str = str_replace($matches[0][$i], '{@HC'.$i.'}', $str); } } @@ -110,22 +104,22 @@ class CI_Typography { // not contain <pre> tags, and it keeps the PCRE patterns below simpler and faster if (strpos($str, '<pre') !== FALSE) { - $str = preg_replace_callback("#<pre.*?>.*?</pre>#si", array($this, '_protect_characters'), $str); + $str = preg_replace_callback('#<pre.*?>.*?</pre>#si', array($this, '_protect_characters'), $str); } // Convert quotes within tags to temporary markers. - $str = preg_replace_callback("#<.+?>#si", array($this, '_protect_characters'), $str); + $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 // 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); + $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: * @@ -148,9 +142,9 @@ 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 <pre> tags and a few other things. - if (preg_match("#<(/*)(".$this->block_elements.").*?>#", $chunks[$i], $match)) + if (preg_match('#<(/*)('.$this->block_elements.').*?>#', $chunks[$i], $match)) { - if (preg_match("#".$this->skip_elements."#", $match[2])) + if (preg_match('#'.$this->skip_elements.'#', $match[2])) { $process = ($match[1] === '/'); } @@ -180,10 +174,10 @@ class CI_Typography { $str .= $this->_format_newlines($chunks[$i]); } - // No opening block level tag? Add it if needed. - if ( ! preg_match("/^\s*<(?:".$this->block_elements.")/i", $str)) + // 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", '<p>$1</p><$2', $str); + $str = preg_replace('/^(.*?)<('.$this->block_elements.')/i', '<p>$1</p><$2', $str); } // Convert quotes, elipsis, em-dashes, non-breaking spaces, and ampersands @@ -230,7 +224,7 @@ class CI_Typography { // Similarly, there might be cases where a closing </block> will follow // a closing </p> tag, so we'll correct it by adding a newline in between - "#</p></#" => "</p>\n</" + '#</p></#' => "</p>\n</" ); // Do we need to reduce empty lines? @@ -258,7 +252,6 @@ class CI_Typography { * to curly entities, but it also converts em-dashes, * double spaces, and ampersands * - * @access public * @param string * @return string */ @@ -322,13 +315,12 @@ class CI_Typography { * * Converts newline characters into either <p> tags or <br /> * - * @access protected * @param string * @return string */ protected function _format_newlines($str) { - if ($str == '' OR (strpos($str, "\n") === FALSE AND ! in_array($this->last_block_element, $this->inner_block_required))) + if ($str == '' OR (strpos($str, "\n") === FALSE && ! in_array($this->last_block_element, $this->inner_block_required))) { return $str; } @@ -337,7 +329,7 @@ class CI_Typography { $str = str_replace("\n\n", "</p>\n\n<p>", $str); // Convert single spaces to <br /> tags - $str = preg_replace("/([^\n])(\n)([^\n])/", "\\1<br />\\2\\3", $str); + $str = preg_replace("/([^\n])(\n)([^\n])/", '\\1<br />\\2\\3', $str); // Wrap the whole enchilada in enclosing paragraphs if ($str != "\n") @@ -350,9 +342,7 @@ 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><\/p>(.*)/", "\\1", $str, 1); - - return $str; + return preg_replace('/<p><\/p>(.*)/', '\\1', $str, 1); } // ------------------------------------------------------------------------ @@ -365,7 +355,6 @@ class CI_Typography { * 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 protected * @param array * @return string */ @@ -379,7 +368,6 @@ class CI_Typography { /** * Convert newlines to HTML line breaks except within PRE tags * - * @access public * @param string * @return string */ @@ -399,7 +387,6 @@ class CI_Typography { } } -// END Typography Class /* End of file Typography.php */ -/* Location: ./system/libraries/Typography.php */ +/* Location: ./system/libraries/Typography.php */
\ No newline at end of file diff --git a/system/libraries/Unit_test.php b/system/libraries/Unit_test.php index 2eb8df356..0f6e2dfdd 100644 --- a/system/libraries/Unit_test.php +++ b/system/libraries/Unit_test.php @@ -25,8 +25,6 @@ * @filesource */ -// ------------------------------------------------------------------------ - /** * Unit Testing Class * @@ -60,7 +58,7 @@ class CI_Unit_test { 'notes' ); - log_message('debug', "Unit Testing Class Initialized"); + log_message('debug', 'Unit Testing Class Initialized'); } // -------------------------------------------------------------------- @@ -75,7 +73,7 @@ class CI_Unit_test { */ public function set_test_items($items = array()) { - if ( ! empty($items) AND is_array($items)) + if ( ! empty($items) && is_array($items)) { $this->_test_items_visible = $items; } @@ -102,8 +100,8 @@ class CI_Unit_test { 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; + $expected = str_replace('is_double', 'is_float', $expected); + $result = $expected($test); $extype = str_replace(array('true', 'false'), 'bool', str_replace('is_', '', $expected)); } else @@ -186,7 +184,7 @@ class CI_Unit_test { * Causes the evaluation to use === rather than == * * @param bool - * @return null + * @return void */ public function use_strict($state = TRUE) { @@ -201,7 +199,7 @@ class CI_Unit_test { * Enables/disables unit testing * * @param bool - * @return null + * @return void */ public function active($state = TRUE) { @@ -311,10 +309,10 @@ class CI_Unit_test { */ protected function _default_template() { - $this->_template = "\n".'<table style="width:100%; font-size:small; margin:10px 0; border-collapse:collapse; border:1px solid #CCC;">{rows}'."\n".'</table>'; + $this->_template = "\n".'<table style="width:100%; font-size:small; margin:10px 0; border-collapse:collapse; border:1px solid #CCC;">{rows}'."\n</table>"; $this->_template_rows = "\n\t<tr>\n\t\t".'<th style="text-align: left; border-bottom:1px solid #CCC;">{item}</th>' - . "\n\t\t".'<td style="border-bottom:1px solid #CCC;">{result}</td>'."\n\t</tr>"; + ."\n\t\t".'<td style="border-bottom:1px solid #CCC;">{result}</td>'."\n\t</tr>"; } // -------------------------------------------------------------------- @@ -333,7 +331,7 @@ class CI_Unit_test { return; } - if (is_null($this->_template) OR ! preg_match("/\{rows\}(.*?)\{\/rows\}/si", $this->_template, $match)) + if (is_null($this->_template) OR ! preg_match('/\{rows\}(.*?)\{\/rows\}/si', $this->_template, $match)) { $this->_default_template(); return; @@ -344,7 +342,6 @@ class CI_Unit_test { } } -// END Unit_test Class /** * Helper functions to test boolean true/false @@ -353,13 +350,12 @@ class CI_Unit_test { */ function is_true($test) { - return (is_bool($test) AND $test === TRUE) ? TRUE : FALSE; + return (is_bool($test) && $test === TRUE); } function is_false($test) { - return (is_bool($test) AND $test === FALSE) ? TRUE : FALSE; + return (is_bool($test) && $test === FALSE); } - /* End of file Unit_test.php */ -/* Location: ./system/libraries/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 42664a587..8ad67050d 100644 --- a/system/libraries/Upload.php +++ b/system/libraries/Upload.php @@ -25,8 +25,6 @@ * @filesource */ -// ------------------------------------------------------------------------ - /** * File Uploading Class * @@ -38,39 +36,40 @@ */ class CI_Upload { - public $max_size = 0; - public $max_width = 0; - public $max_height = 0; - public $max_filename = 0; + public $max_size = 0; + public $max_width = 0; + public $max_height = 0; + public $max_filename = 0; public $max_filename_increment = 100; - 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 = ''; + 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 + * @param array + * @return void */ public function __construct($props = array()) { @@ -79,7 +78,7 @@ class CI_Upload { $this->initialize($props); } - log_message('debug', "Upload Class Initialized"); + log_message('debug', 'Upload Class Initialized'); } // -------------------------------------------------------------------- @@ -93,33 +92,33 @@ class CI_Upload { public function initialize($config = array()) { $defaults = array( - 'max_size' => 0, - 'max_width' => 0, - 'max_height' => 0, - 'max_filename' => 0, - 'max_filename_increment' => 100, - '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_", - 'client_name' => '' - ); + 'max_size' => 0, + 'max_width' => 0, + 'max_height' => 0, + 'max_filename' => 0, + 'max_filename_increment' => 100, + '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_', + 'client_name' => '' + ); foreach ($defaults as $key => $val) @@ -156,8 +155,7 @@ class CI_Upload { */ public function do_upload($field = 'userfile') { - - // Is $_FILES[$field] set? If not, no reason to continue. + // Is $_FILES[$field] set? If not, no reason to continue. if ( ! isset($_FILES[$field])) { $this->set_error('upload_no_file_selected'); @@ -176,7 +174,7 @@ class CI_Upload { { $error = ( ! isset($_FILES[$field]['error'])) ? 4 : $_FILES[$field]['error']; - switch($error) + switch ($error) { case 1: // UPLOAD_ERR_INI_SIZE $this->set_error('upload_file_exceeds_limit'); @@ -199,19 +197,19 @@ class CI_Upload { case 8: // UPLOAD_ERR_EXTENSION $this->set_error('upload_stopped_by_extension'); break; - default : $this->set_error('upload_no_file_selected'); + 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_size = $_FILES[$field]['size']; $this->_file_mime_type($_FILES[$field]); - $this->file_type = preg_replace("/^(.+?);.*$/", "\\1", $this->file_type); + $this->file_type = preg_replace('/^(.+?);.*$/', '\\1', $this->file_type); $this->file_type = strtolower(trim(stripslashes($this->file_type), '"')); $this->file_name = $this->_prep_filename($_FILES[$field]['name']); $this->file_ext = $this->get_extension($this->file_name); @@ -234,11 +232,10 @@ class CI_Upload { { $this->file_name .= $this->file_ext; } - - // An extension was provided, lets have it! else { - $this->file_ext = $this->get_extension($this->_file_name_override); + // An extension was provided, lets have it! + $this->file_ext = $this->get_extension($this->_file_name_override); } if ( ! $this->is_allowed_filetype(TRUE)) @@ -281,7 +278,7 @@ class CI_Upload { // Remove white spaces in the name if ($this->remove_spaces == TRUE) { - $this->file_name = preg_replace("/\s+/", "_", $this->file_name); + $this->file_name = preg_replace('/\s+/', '_', $this->file_name); } /* @@ -305,23 +302,20 @@ 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) + if ($this->xss_clean && $this->do_xss_clean() === FALSE) { - if ($this->do_xss_clean() === FALSE) - { - $this->set_error('upload_unable_to_write_file'); - return FALSE; - } + $this->set_error('upload_unable_to_write_file'); + 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 + * 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)) @@ -336,7 +330,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); @@ -356,22 +350,22 @@ class CI_Upload { */ public 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, - 'client_name' => $this->client_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, - ); + 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, + 'client_name' => $this->client_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, + ); } // -------------------------------------------------------------------- @@ -442,12 +436,12 @@ class CI_Upload { /** * Set Maximum File Size * - * @param integer + * @param int * @return void */ public function set_max_filesize($n) { - $this->max_size = ((int) $n < 0) ? 0: (int) $n; + $this->max_size = ((int) $n < 0) ? 0 : (int) $n; } // -------------------------------------------------------------------- @@ -455,12 +449,12 @@ class CI_Upload { /** * Set Maximum File Name Length * - * @param integer + * @param int * @return void */ public function set_max_filename($n) { - $this->max_filename = ((int) $n < 0) ? 0: (int) $n; + $this->max_filename = ((int) $n < 0) ? 0 : (int) $n; } // -------------------------------------------------------------------- @@ -468,12 +462,12 @@ class CI_Upload { /** * Set Maximum Image Width * - * @param integer + * @param int * @return void */ public function set_max_width($n) { - $this->max_width = ((int) $n < 0) ? 0: (int) $n; + $this->max_width = ((int) $n < 0) ? 0 : (int) $n; } // -------------------------------------------------------------------- @@ -481,12 +475,12 @@ class CI_Upload { /** * Set Maximum Image Height * - * @param integer + * @param int * @return void */ public function set_max_height($n) { - $this->max_height = ((int) $n < 0) ? 0: (int) $n; + $this->max_height = ((int) $n < 0) ? 0 : (int) $n; } // -------------------------------------------------------------------- @@ -499,7 +493,7 @@ class CI_Upload { */ public function set_allowed_types($types) { - if ( ! is_array($types) && $types == '*') + if ( ! is_array($types) && $types === '*') { $this->allowed_types = '*'; return; @@ -530,10 +524,10 @@ class CI_Upload { { $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 + $this->image_width = $D[0]; + $this->image_height = $D[1]; + $this->image_type = isset($types[$D[2]]) ? $types[$D[2]] : 'unknown'; + $this->image_size_str = $D[3]; // string containing height and width } } } @@ -551,7 +545,7 @@ class CI_Upload { */ public function set_xss_clean($flag = FALSE) { - $this->xss_clean = ($flag == TRUE) ? TRUE : FALSE; + $this->xss_clean = ($flag == TRUE); } // -------------------------------------------------------------------- @@ -573,19 +567,14 @@ class CI_Upload { { $this->file_type = 'image/png'; } - - if (in_array($this->file_type, $jpeg_mimes)) + elseif (in_array($this->file_type, $jpeg_mimes)) { $this->file_type = 'image/jpeg'; } - $img_mimes = array( - 'image/gif', - 'image/jpeg', - 'image/png', - ); + $img_mimes = array('image/gif', 'image/jpeg', 'image/png'); - return (in_array($this->file_type, $img_mimes, TRUE)) ? TRUE : FALSE; + return in_array($this->file_type, $img_mimes, TRUE); } // -------------------------------------------------------------------- @@ -631,16 +620,13 @@ class CI_Upload { $mime = $this->mimes_types($ext); - if (is_array($mime)) + if (is_array($mime) && in_array($this->file_type, $mime, TRUE)) { - if (in_array($this->file_type, $mime, TRUE)) - { - return TRUE; - } + return TRUE; } elseif ($mime === $this->file_type) { - return TRUE; + return TRUE; } return FALSE; @@ -655,14 +641,7 @@ class CI_Upload { */ public function is_allowed_filesize() { - if ($this->max_size != 0 AND $this->file_size > $this->max_size) - { - return FALSE; - } - else - { - return TRUE; - } + return ($this->max_size == 0 OR $this->max_size > $this->file_size); } // -------------------------------------------------------------------- @@ -683,17 +662,15 @@ class CI_Upload { { $D = @getimagesize($this->file_temp); - if ($this->max_width > 0 AND $D['0'] > $this->max_width) + if ($this->max_width > 0 && $D[0] > $this->max_width) { return FALSE; } - if ($this->max_height > 0 AND $D['1'] > $this->max_height) + if ($this->max_height > 0 && $D[1] > $this->max_height) { return FALSE; } - - return TRUE; } return TRUE; @@ -706,7 +683,6 @@ class CI_Upload { * * Verifies that it is a valid upload path with proper permissions. * - * * @return bool */ public function validate_upload_path() @@ -717,9 +693,9 @@ class CI_Upload { return FALSE; } - if (function_exists('realpath') AND @realpath($this->upload_path) !== FALSE) + if (function_exists('realpath') && @realpath($this->upload_path) !== FALSE) { - $this->upload_path = str_replace("\\", "/", realpath($this->upload_path)); + $this->upload_path = str_replace('\\', '/', realpath($this->upload_path)); } if ( ! @is_dir($this->upload_path)) @@ -734,7 +710,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; } @@ -763,37 +739,31 @@ class CI_Upload { public 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); + '<!--', '-->', + "'", '"', + '<', '>', + '&', '$', + '=', + ';', + '?', + '/', + '%20', + '%22', + '%3c', // < + '%253c', // < + '%3e', // > + '%0e', // > + '%28', // ( + '%29', // ) + '%2528', // ( + '%26', // & + '%24', // $ + '%3f', // ? + '%3b', // ; + '%3d' // = + ); + + return stripslashes(str_replace($bad, '', $filename)); } // -------------------------------------------------------------------- @@ -847,7 +817,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, '.', ''); @@ -857,8 +827,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. @@ -932,7 +902,7 @@ class CI_Upload { */ public function display_errors($open = '<p>', $close = '</p>') { - return (count($this->error_msg) > 0) ? $open . implode($close . $open, $this->error_msg) . $close : ''; + return (count($this->error_msg) > 0) ? $open.implode($close.$open, $this->error_msg).$close : ''; } // -------------------------------------------------------------------- @@ -940,7 +910,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 @@ -952,7 +922,7 @@ class CI_Upload { if (count($this->mimes) == 0) { - if (defined('ENVIRONMENT') AND is_file(APPPATH.'config/'.ENVIRONMENT.'/mimes.php')) + if (defined('ENVIRONMENT') && is_file(APPPATH.'config/'.ENVIRONMENT.'/mimes.php')) { include(APPPATH.'config/'.ENVIRONMENT.'/mimes.php'); } @@ -966,10 +936,9 @@ class CI_Upload { } $this->mimes = $mimes; - unset($mimes); } - return ( ! isset($this->mimes[$mime])) ? FALSE : $this->mimes[$mime]; + return isset($this->mimes[$mime]) ? $this->mimes[$mime] : FALSE; } // -------------------------------------------------------------------- @@ -1006,9 +975,7 @@ class CI_Upload { } } - $filename .= '.'.$ext; - - return $filename; + return $filename.'.'.$ext; } // -------------------------------------------------------------------- @@ -1129,10 +1096,7 @@ class CI_Upload { $this->file_type = $file['type']; } - // -------------------------------------------------------------------- - } -// END Upload Class /* End of file Upload.php */ -/* Location: ./system/libraries/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 9109edd0f..b8e0d37fb 100644 --- a/system/libraries/User_agent.php +++ b/system/libraries/User_agent.php @@ -25,8 +25,6 @@ * @filesource */ -// ------------------------------------------------------------------------ - /** * User Agent Class * @@ -74,15 +72,12 @@ class CI_User_agent { $this->agent = trim($_SERVER['HTTP_USER_AGENT']); } - if ( ! is_null($this->agent)) + if ( ! is_null($this->agent) && $this->_load_agent_file()) { - if ($this->_load_agent_file()) - { - $this->_compile_data(); - } + $this->_compile_data(); } - log_message('debug', "User Agent Class Initialized"); + log_message('debug', 'User Agent Class Initialized'); } // -------------------------------------------------------------------- @@ -94,7 +89,7 @@ class CI_User_agent { */ protected function _load_agent_file() { - if (defined('ENVIRONMENT') AND is_file(APPPATH.'config/'.ENVIRONMENT.'/user_agents.php')) + if (defined('ENVIRONMENT') && is_file(APPPATH.'config/'.ENVIRONMENT.'/user_agents.php')) { include(APPPATH.'config/'.ENVIRONMENT.'/user_agents.php'); } @@ -165,22 +160,24 @@ class CI_User_agent { /** * Set the Platform * - * @return mixed + * @return bool */ protected function _set_platform() { - if (is_array($this->platforms) AND count($this->platforms) > 0) + if (is_array($this->platforms) && count($this->platforms) > 0) { foreach ($this->platforms as $key => $val) { - if (preg_match("|".preg_quote($key)."|i", $this->agent)) + if (preg_match('|'.preg_quote($key).'|i', $this->agent)) { $this->platform = $val; return TRUE; } } } + $this->platform = 'Unknown Platform'; + return FALSE; } // -------------------------------------------------------------------- @@ -192,11 +189,11 @@ class CI_User_agent { */ protected function _set_browser() { - if (is_array($this->browsers) AND count($this->browsers) > 0) + if (is_array($this->browsers) && count($this->browsers) > 0) { foreach ($this->browsers as $key => $val) { - if (preg_match("|".preg_quote($key).".*?([0-9\.]+)|i", $this->agent, $match)) + if (preg_match('|'.preg_quote($key).'.*?([0-9\.]+)|i', $this->agent, $match)) { $this->is_browser = TRUE; $this->version = $match[1]; @@ -206,6 +203,7 @@ class CI_User_agent { } } } + return FALSE; } @@ -218,11 +216,11 @@ class CI_User_agent { */ protected function _set_robot() { - if (is_array($this->robots) AND count($this->robots) > 0) + if (is_array($this->robots) && count($this->robots) > 0) { foreach ($this->robots as $key => $val) { - if (preg_match("|".preg_quote($key)."|i", $this->agent)) + if (preg_match('|'.preg_quote($key).'|i', $this->agent)) { $this->is_robot = TRUE; $this->robot = $val; @@ -230,6 +228,7 @@ class CI_User_agent { } } } + return FALSE; } @@ -242,7 +241,7 @@ class CI_User_agent { */ protected function _set_mobile() { - if (is_array($this->mobiles) AND count($this->mobiles) > 0) + if (is_array($this->mobiles) && count($this->mobiles) > 0) { foreach ($this->mobiles as $key => $val) { @@ -254,6 +253,7 @@ class CI_User_agent { } } } + return FALSE; } @@ -266,7 +266,7 @@ class CI_User_agent { */ protected function _set_languages() { - if ((count($this->languages) === 0) AND isset($_SERVER['HTTP_ACCEPT_LANGUAGE']) AND $_SERVER['HTTP_ACCEPT_LANGUAGE'] != '') + if ((count($this->languages) === 0) && ! empty($_SERVER['HTTP_ACCEPT_LANGUAGE'])) { $this->languages = explode(',', preg_replace('/(;q=[0-9\.]+)/i', '', strtolower(trim($_SERVER['HTTP_ACCEPT_LANGUAGE'])))); } @@ -286,7 +286,7 @@ class CI_User_agent { */ protected function _set_charsets() { - if ((count($this->charsets) === 0) AND isset($_SERVER['HTTP_ACCEPT_CHARSET']) AND $_SERVER['HTTP_ACCEPT_CHARSET'] != '') + if ((count($this->charsets) === 0) && ! empty($_SERVER['HTTP_ACCEPT_CHARSET'])) { $this->charsets = explode(',', preg_replace('/(;q=.+)/i', '', strtolower(trim($_SERVER['HTTP_ACCEPT_CHARSET'])))); } @@ -318,7 +318,7 @@ class CI_User_agent { } // Check for a specific browser - return array_key_exists($key, $this->browsers) AND $this->browser === $this->browsers[$key]; + return (isset($this->browsers[$key]) && $this->browser === $this->browsers[$key]); } // -------------------------------------------------------------------- @@ -342,7 +342,7 @@ class CI_User_agent { } // Check for a specific robot - return array_key_exists($key, $this->robots) AND $this->robot === $this->robots[$key]; + return (isset($this->robots[$key]) && $this->robot === $this->robots[$key]); } // -------------------------------------------------------------------- @@ -366,7 +366,7 @@ class CI_User_agent { } // Check for a specific robot - return array_key_exists($key, $this->mobiles) AND $this->mobile === $this->mobiles[$key]; + return (isset($this->mobiles[$key]) && $this->mobile === $this->mobiles[$key]); } // -------------------------------------------------------------------- @@ -378,7 +378,7 @@ class CI_User_agent { */ public function is_referral() { - return ( ! isset($_SERVER['HTTP_REFERER']) OR $_SERVER['HTTP_REFERER'] == '') ? FALSE : TRUE; + return ! empty($_SERVER['HTTP_REFERER']); } // -------------------------------------------------------------------- @@ -461,7 +461,7 @@ class CI_User_agent { */ public function referrer() { - return ( ! isset($_SERVER['HTTP_REFERER']) OR $_SERVER['HTTP_REFERER'] == '') ? '' : trim($_SERVER['HTTP_REFERER']); + return empty($_SERVER['HTTP_REFERER']) ? '' : trim($_SERVER['HTTP_REFERER']); } // -------------------------------------------------------------------- @@ -507,7 +507,7 @@ class CI_User_agent { */ public function accept_lang($lang = 'en') { - return (in_array(strtolower($lang), $this->languages(), TRUE)); + return in_array(strtolower($lang), $this->languages(), TRUE); } // -------------------------------------------------------------------- @@ -519,10 +519,10 @@ class CI_User_agent { */ public function accept_charset($charset = 'utf-8') { - return (in_array(strtolower($charset), $this->charsets(), TRUE)); + return in_array(strtolower($charset), $this->charsets(), TRUE); } } /* End of file User_agent.php */ -/* Location: ./system/libraries/User_agent.php */ +/* Location: ./system/libraries/User_agent.php */
\ No newline at end of file diff --git a/system/libraries/Xmlrpc.php b/system/libraries/Xmlrpc.php index 32e2e523b..fea560c2e 100644 --- a/system/libraries/Xmlrpc.php +++ b/system/libraries/Xmlrpc.php @@ -25,14 +25,6 @@ * @filesource */ -if ( ! function_exists('xml_parser_create')) -{ - show_error('Your PHP installation does not support XML'); -} - - -// ------------------------------------------------------------------------ - /** * XML-RPC request handler class * @@ -42,6 +34,14 @@ if ( ! function_exists('xml_parser_create')) * @author EllisLab Dev Team * @link http://codeigniter.com/user_guide/libraries/xmlrpc.html */ + +if ( ! function_exists('xml_parser_create')) +{ + show_error('Your PHP installation does not support XML'); +} + +// ------------------------------------------------------------------------ + class CI_Xmlrpc { public $debug = FALSE; // Debugging on or off @@ -77,13 +77,17 @@ class CI_Xmlrpc { public $xss_clean = TRUE; - //------------------------------------- - // VALUES THAT MULTIPLE CLASSES NEED - //------------------------------------- + /** + * Constructor + * + * Initializes property default values + * + * @param array + * @return void + */ public function __construct($config = array()) { - $this->xmlrpcName = $this->xmlrpcName; $this->xmlrpc_backslash = chr(92).chr(92); // Types for info sent back and forth @@ -136,14 +140,17 @@ class CI_Xmlrpc { $this->initialize($config); - log_message('debug', "XML-RPC Class Initialized"); + log_message('debug', 'XML-RPC Class Initialized'); } + // -------------------------------------------------------------------- - //------------------------------------- - // Initialize Prefs - //------------------------------------- - + /** + * Initialize + * + * @param array + * @return void + */ public function initialize($config = array()) { if (count($config) > 0) @@ -157,36 +164,43 @@ class CI_Xmlrpc { } } } - // END - //------------------------------------- - // Take URL and parse it - //------------------------------------- + // -------------------------------------------------------------------- - public function server($url, $port=80) + /** + * Parse server URL + * + * @param string url + * @param int port + * @return void + */ + public function server($url, $port = 80) { if (strpos($url, 'http') !== 0) { - $url = "http://".$url; + $url = 'http://'.$url; } $parts = parse_url($url); - $path = ( ! isset($parts['path'])) ? '/' : $parts['path']; + $path = isset($parts['path']) ? $parts['path'] : '/'; - if (isset($parts['query']) && $parts['query'] != '') + if ( ! empty($parts['query'])) { $path .= '?'.$parts['query']; } $this->client = new XML_RPC_Client($path, $parts['host'], $port); } - // END - //------------------------------------- - // Set Timeout - //------------------------------------- + // -------------------------------------------------------------------- + /** + * Set Timeout + * + * @param int seconds + * @return void + */ public function timeout($seconds = 5) { if ( ! is_null($this->client) && is_int($seconds)) @@ -194,27 +208,34 @@ class CI_Xmlrpc { $this->client->timeout = $seconds; } } - // END - //------------------------------------- - // Set Methods - //------------------------------------- + // -------------------------------------------------------------------- + /** + * Set Methods + * + * @param string method name + * @return void + */ public function method($function) { $this->method = $function; } - // END - //------------------------------------- - // Take Array of Data and Create Objects - //------------------------------------- + // -------------------------------------------------------------------- + /** + * Take Array of Data and Create Objects + * + * @param array + * @return void + */ public function request($incoming) { if ( ! is_array($incoming)) { // Send Error + return; } $this->data = array(); @@ -224,27 +245,33 @@ class CI_Xmlrpc { $this->data[$key] = $this->values_parsing($value); } } - // END - - //------------------------------------- - // Set Debug - //------------------------------------- + // -------------------------------------------------------------------- + /** + * Set Debug + * + * @param bool + * @return void + */ public function set_debug($flag = TRUE) { $this->debug = ($flag == TRUE); } - //------------------------------------- - // Values Parsing - //------------------------------------- + // -------------------------------------------------------------------- - public function values_parsing($value, $return = FALSE) + /** + * Values Parsing + * + * @param mixed + * @return object + */ + public function values_parsing($value) { if (is_array($value) && array_key_exists(0, $value)) { - if ( ! isset($value[1]) OR ( ! isset($this->xmlrpcTypes[$value[1]]))) + if ( ! isset($value[1], $this->xmlrpcTypes[$value[1]])) { $temp = new XML_RPC_Values($value[0], (is_array($value[0]) ? 'array' : 'string')); } @@ -268,16 +295,17 @@ class CI_Xmlrpc { return $temp; } - // END - - //------------------------------------- - // Sends XML-RPC Request - //------------------------------------- + // -------------------------------------------------------------------- + /** + * Sends XML-RPC Request + * + * @return bool + */ public function send_request() { - $this->message = new XML_RPC_Message($this->method,$this->data); + $this->message = new XML_RPC_Message($this->method, $this->data); $this->message->debug = $this->debug; if ( ! $this->result = $this->client->send($this->message) OR ! is_object($this->result->val)) @@ -289,55 +317,62 @@ class CI_Xmlrpc { $this->response = $this->result->decode(); return TRUE; } - // END - //------------------------------------- - // Returns Error - //------------------------------------- + // -------------------------------------------------------------------- + /** + * Returns Error + * + * @return string + */ public function display_error() { return $this->error; } - // END - //------------------------------------- - // Returns Remote Server Response - //------------------------------------- + // -------------------------------------------------------------------- + /** + * Returns Remote Server Response + * + * @return string + */ public function display_response() { return $this->response; } - // END - //------------------------------------- - // Sends an Error Message for Server Request - //------------------------------------- + // -------------------------------------------------------------------- + /** + * Sends an Error Message for Server Request + * + * @param int + * @param string + * @return object + */ public function send_error_message($number, $message) { return new XML_RPC_Response(0, $number, $message); } - // END + // -------------------------------------------------------------------- - //------------------------------------- - // Send Response for Server Request - //------------------------------------- - + /** + * Send Response for Server Request + * + * @param array + * @return object + */ public 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 return new XML_RPC_Response($this->values_parsing($response)); } - // END } // END XML_RPC Class - - /** * XML-RPC Client class * @@ -355,7 +390,15 @@ class XML_RPC_Client extends CI_Xmlrpc public $timeout = 5; public $no_multicall = FALSE; - public function __construct($path, $server, $port=80) + /** + * Constructor + * + * @param string + * @param object + * @param int + * @return void + */ + public function __construct($path, $server, $port = 80) { parent::__construct(); @@ -364,18 +407,33 @@ class XML_RPC_Client extends CI_Xmlrpc $this->path = $path; } + // -------------------------------------------------------------------- + + /** + * Send message + * + * @param mixed + * @return object + */ public 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 new XML_RPC_Response(0, $this->xmlrpcerr['multicall_recursion'], $this->xmlrpcstr['multicall_recursion']); } return $this->sendPayload($msg); } + // -------------------------------------------------------------------- + + /** + * Send payload + * + * @param object + * @return object + */ public function sendPayload($msg) { $fp = @fsockopen($this->server, $this->port,$this->errno, $this->errstr, $this->timeout); @@ -383,8 +441,7 @@ class XML_RPC_Client extends CI_Xmlrpc 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; + return new XML_RPC_Response(0, $this->xmlrpcerr['http_error'], $this->xmlrpcstr['http_error']); } if (empty($msg->payload)) @@ -394,27 +451,25 @@ class XML_RPC_Client extends CI_Xmlrpc } $r = "\r\n"; - $op = "POST {$this->path} HTTP/1.0$r" - . "Host: {$this->server}$r" - . "Content-Type: text/xml$r" - . "User-Agent: {$this->xmlrpcName}$r" - . "Content-Length: ".strlen($msg->payload)."$r$r" - . $msg->payload; - + $op = 'POST '.$this->path.' HTTP/1.0'.$r + .'Host: '.$this->server.$r + .'Content-Type: text/xml'.$r + .'User-Agent: '.$this->xmlrpcName.$r + .'Content-Length: '.strlen($msg->payload).$r.$r + .$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; + return new XML_RPC_Response(0, $this->xmlrpcerr['http_error'], $this->xmlrpcstr['http_error']); } + $resp = $msg->parseResponse($fp); fclose($fp); return $resp; } -} -// end class XML_RPC_Client +} // END XML_RPC_Client Class /** * XML-RPC Response class @@ -425,31 +480,34 @@ class XML_RPC_Client extends CI_Xmlrpc */ class XML_RPC_Response { - public $val = 0; - public $errno = 0; - public $errstr = ''; - public $headers = array(); - public $xss_clean = TRUE; - + public $val = 0; + public $errno = 0; + public $errstr = ''; + public $headers = array(); + public $xss_clean = TRUE; + + /** + * Constructor + * + * @param mixed + * @param int + * @param string + * @return void + */ public function __construct($val, $code = 0, $fstr = '') { if ($code != 0) { // error $this->errno = $code; - if ( ! is_php('5.4')) - { - $this->errstr = htmlspecialchars($fstr, ENT_NOQUOTES, 'UTF-8'); - } - else - { - $this->errstr = htmlspecialchars($fstr, ENT_XML1 | ENT_NOQUOTES, 'UTF-8'); - } + $this->errstr = htmlspecialchars($fstr, + (is_php('5.4') ? ENT_XML1 | ENT_NOQUOTES : ENT_NOQUOTES), + 'UTF-8'); } - else if ( ! is_object($val)) + elseif ( ! 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 @@ -458,43 +516,79 @@ class XML_RPC_Response } } + // -------------------------------------------------------------------- + + /** + * Fault code + * + * @return int + */ public function faultCode() { return $this->errno; } + // -------------------------------------------------------------------- + + /** + * Fault string + * + * @return string + */ public function faultString() { return $this->errstr; } + // -------------------------------------------------------------------- + + /** + * Value + * + * @return mixed + */ public function value() { return $this->val; } + // -------------------------------------------------------------------- + + /** + * Prepare response + * + * @return string xml + */ public function prepare_response() { return "<methodResponse>\n" - . ($this->errno - ? '<fault> + .($this->errno + ? '<fault> <value> <struct> <member> <name>faultCode</name> - <value><int>' . $this->errno . '</int></value> + <value><int>'.$this->errno.'</int></value> </member> <member> <name>faultString</name> - <value><string>' . $this->errstr . '</string></value> + <value><string>'.$this->errstr.'</string></value> </member> </struct> </value> </fault>' - : "<params>\n<param>\n".$this->val->serialize_class()."</param>\n</params>") - . "\n</methodResponse>"; + : "<params>\n<param>\n".$this->val->serialize_class()."</param>\n</params>") + ."\n</methodResponse>"; } + // -------------------------------------------------------------------- + + /** + * Decode + * + * @param mixed + * @return array + */ public function decode($array = FALSE) { $CI =& get_instance(); @@ -513,31 +607,31 @@ class XML_RPC_Response } } - $result = $array; + return $array; + } + + $result = $this->xmlrpc_decoder($this->val); + + if (is_array($result)) + { + $result = $this->decode($result); } else { - $result = $this->xmlrpc_decoder($this->val); - - if (is_array($result)) - { - $result = $this->decode($result); - } - else - { - $result = ($this->xss_clean) ? $CI->security->xss_clean($result) : $result; - } + $result = ($this->xss_clean) ? $CI->security->xss_clean($result) : $result; } return $result; } + // -------------------------------------------------------------------- - - //------------------------------------- - // XML-RPC Object to PHP Types - //------------------------------------- - + /** + * XML-RPC Object to PHP Types + * + * @param object + * @return array + */ public function xmlrpc_decoder($xmlrpc_val) { $kind = $xmlrpc_val->kindOf(); @@ -571,25 +665,28 @@ class XML_RPC_Response } } + // -------------------------------------------------------------------- - //------------------------------------- - // ISO-8601 time to server or UTC time - //------------------------------------- - - public function iso8601_decode($time, $utc = 0) + /** + * ISO-8601 time to server or UTC time + * + * @param string + * @param bool + * @return int unix timestamp + */ + public function iso8601_decode($time, $utc = FALSE) { - // return a timet in the localtime, or UTC + // return a time 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)) { - $fnc = ($utc == 1) ? 'gmmktime' : 'mktime'; + $fnc = ($utc == TRUE) ? 'gmmktime' : 'mktime'; $t = $fnc($regs[4], $regs[5], $regs[6], $regs[2], $regs[3], $regs[1]); } return $t; } -} -// End Response Class +} // END XML_RPC_Response Class /** * XML-RPC Message class @@ -602,10 +699,17 @@ class XML_RPC_Message extends CI_Xmlrpc { public $payload; public $method_name; - public $params = array(); - public $xh = array(); - - public function __construct($method, $pars=0) + public $params = array(); + public $xh = array(); + + /** + * Constructor + * + * @param string method name + * @param array + * @return void + */ + public function __construct($method, $pars = FALSE) { parent::__construct(); @@ -620,15 +724,18 @@ class XML_RPC_Message extends CI_Xmlrpc } } - //------------------------------------- - // Create Payload to Send - //------------------------------------- + // -------------------------------------------------------------------- + /** + * Create Payload to Send + * + * @return void + */ public function createPayload() { - $this->payload = "<?xml version=\"1.0\"?".">\r\n<methodCall>\r\n" - . '<methodName>'.$this->method_name."</methodName>\r\n" - . "<params>\r\n"; + $this->payload = '<?xml version="1.0"?'.">\r\n<methodCall>\r\n" + .'<methodName>'.$this->method_name."</methodName>\r\n" + ."<params>\r\n"; for ($i = 0, $c = count($this->params); $i < $c; $i++) { @@ -640,10 +747,14 @@ class XML_RPC_Message extends CI_Xmlrpc $this->payload .= "</params>\r\n</methodCall>\r\n"; } - //------------------------------------- - // Parse External XML-RPC Server's Response - //------------------------------------- + // -------------------------------------------------------------------- + /** + * Parse External XML-RPC Server's Response + * + * @param resource + * @return object + */ public function parseResponse($fp) { $data = ''; @@ -653,36 +764,24 @@ class XML_RPC_Message extends CI_Xmlrpc $data .= $datum; } - //------------------------------------- - // DISPLAY HTTP CONTENT for DEBUGGING - //------------------------------------- - + // Display HTTP content for debugging if ($this->debug === TRUE) { echo "<pre>---DATA---\n".htmlspecialchars($data)."\n---END DATA---\n\n</pre>"; } - //------------------------------------- - // Check for data - //------------------------------------- - + // 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; + return new XML_RPC_Response(0, $this->xmlrpcerr['no_data'], $this->xmlrpcstr['no_data']); } - - //------------------------------------- - // Check for HTTP 200 Response - //------------------------------------- - + // 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; + $errstr = substr($data, 0, strpos($data, "\n")-1); + return new XML_RPC_Response(0, $this->xmlrpcerr['http_error'], $this->xmlrpcstr['http_error'].' ('.$errstr.')'); } //------------------------------------- @@ -692,25 +791,21 @@ class XML_RPC_Message extends CI_Xmlrpc $parser = xml_parser_create($this->xmlrpc_defencoding); $this->xh[$parser] = array( - 'isf' => 0, - 'ac' => '', - 'headers' => array(), - 'stack' => array(), - 'valuestack' => array(), - 'isf_reason' => 0 + 'isf' => 0, + 'ac' => '', + 'headers' => array(), + 'stack' => array(), + 'valuestack' => array(), + 'isf_reason' => 0 ); xml_set_object($parser, $this); - xml_parser_set_option($parser, XML_OPTION_CASE_FOLDING, true); + xml_parser_set_option($parser, XML_OPTION_CASE_FOLDING, TRUE); xml_set_element_handler($parser, 'open_tag', 'closing_tag'); xml_set_character_data_handler($parser, 'character_data'); //xml_set_default_handler($parser, 'default_handler'); - - //------------------------------------- - // GET HEADERS - //------------------------------------- - + // Get headers $lines = explode("\r\n", $data); while (($line = array_shift($lines))) { @@ -722,16 +817,12 @@ class XML_RPC_Message extends CI_Xmlrpc } $data = implode("\r\n", $lines); - - //------------------------------------- - // PARSE XML DATA - //------------------------------------- - + // Parse XML data if ( ! xml_parse($parser, $data, count($data))) { $errstr = sprintf('XML error: %s at line %d', - xml_error_string(xml_get_error_code($parser)), - xml_get_current_line_number($parser)); + 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); @@ -739,10 +830,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) { if ($this->debug === TRUE) @@ -750,29 +838,24 @@ class XML_RPC_Message extends CI_Xmlrpc echo "---Invalid Return---\n".$this->xh[$parser]['isf_reason']."---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; + return new XML_RPC_Response(0, $this->xmlrpcerr['invalid_return'], $this->xmlrpcstr['invalid_return'].' '.$this->xh[$parser]['isf_reason']); } 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; + return new XML_RPC_Response(0, $this->xmlrpcerr['invalid_return'], $this->xmlrpcstr['invalid_return'].' '.$this->xh[$parser]['isf_reason']); } - //------------------------------------- - // DISPLAY XML CONTENT for DEBUGGING - //------------------------------------- - + // Display XML content for debugging if ($this->debug === TRUE) { - echo "<pre>"; + echo '<pre>'; if (count($this->xh[$parser]['headers'] > 0)) { echo "---HEADERS---\n"; foreach ($this->xh[$parser]['headers'] as $header) { - echo "$header\n"; + echo $header."\n"; } echo "---END HEADERS---\n\n"; } @@ -782,10 +865,7 @@ class XML_RPC_Message extends CI_Xmlrpc echo "\n---END PARSED---</pre>"; } - //------------------------------------- - // SEND RESPONSE - //------------------------------------- - + // Send response $v = $this->xh[$parser]['value']; if ($this->xh[$parser]['isf']) { @@ -810,6 +890,8 @@ class XML_RPC_Message extends CI_Xmlrpc return $r; } + // -------------------------------------------------------------------- + // ------------------------------------ // Begin Return Message Parsing section // ------------------------------------ @@ -824,17 +906,21 @@ class XML_RPC_Message extends CI_Xmlrpc // stack - array with parent tree of the xml element, // used to validate the nesting of elements - //------------------------------------- - // Start Element Handler - //------------------------------------- + // -------------------------------------------------------------------- - public function open_tag($the_parser, $name, $attrs) + /** + * Start Element Handler + * + * @param string + * @param string + * @return void + */ + public function open_tag($the_parser, $name) { // 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') @@ -844,43 +930,37 @@ class XML_RPC_Message extends CI_Xmlrpc return; } } - else + // not top level element: see if parent is OK + elseif ( ! in_array($this->xh[$the_parser]['stack'][0], $this->valid_parents[$name], TRUE)) { - // 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; - } + $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) + switch ($name) { case 'STRUCT': case 'ARRAY': // Creates array for child elements - - $cur_val = array('value' => array(), - 'type' => $name); - + $cur_val = array('value' => array(), 'type' => $name); array_unshift($this->xh[$the_parser]['valuestack'], $cur_val); - break; + break; case 'METHODNAME': case 'NAME': $this->xh[$the_parser]['ac'] = ''; - break; + break; case 'FAULT': $this->xh[$the_parser]['isf'] = 1; - break; + break; case 'PARAM': $this->xh[$the_parser]['value'] = NULL; - break; + break; case 'VALUE': $this->xh[$the_parser]['vt'] = 'value'; $this->xh[$the_parser]['ac'] = ''; $this->xh[$the_parser]['lv'] = 1; - break; + break; case 'I4': case 'INT': case 'STRING': @@ -892,66 +972,70 @@ class XML_RPC_Message extends CI_Xmlrpc { //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"; + $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; + break; case 'MEMBER': // Set name of <member> to nothing to prevent errors later if no <name> 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; + break; case 'DATA': case 'METHODCALL': case 'METHODRESPONSE': case 'PARAMS': // valid elements that add little to processing - break; + 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; + $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; + $name == 'VALUE' OR $this->xh[$the_parser]['lv'] = 0; } - // END - - //------------------------------------- - // End Element Handler - //------------------------------------- + // -------------------------------------------------------------------- + /** + * End Element Handler + * + * @param string + * @param string + * @return void + */ public 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 + // 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) + 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]['value'] = isset($cur_val['values']) ? $cur_val['values'] : array(); $this->xh[$the_parser]['vt'] = strtolower($name); - break; + break; case 'NAME': $this->xh[$the_parser]['valuestack'][0]['name'] = $this->xh[$the_parser]['ac']; - break; + break; case 'BOOLEAN': case 'I4': case 'INT': @@ -965,56 +1049,39 @@ class XML_RPC_Message extends CI_Xmlrpc { $this->xh[$the_parser]['value'] = $this->xh[$the_parser]['ac']; } - elseif ($name=='DATETIME.ISO8601') + elseif ($name == 'DATETIME.ISO8601') { $this->xh[$the_parser]['vt'] = $this->xmlrpcDateTime; $this->xh[$the_parser]['value'] = $this->xh[$the_parser]['ac']; } - elseif ($name=='BASE64') + elseif ($name == 'BASE64') { $this->xh[$the_parser]['value'] = base64_decode($this->xh[$the_parser]['ac']); } - elseif ($name=='BOOLEAN') + elseif ($name == 'BOOLEAN') { // Translated BOOLEAN values to TRUE AND FALSE - if ($this->xh[$the_parser]['ac'] == '1') - { - $this->xh[$the_parser]['value'] = TRUE; - } - else - { - $this->xh[$the_parser]['value'] = FALSE; - } + $this->xh[$the_parser]['value'] = (bool) $this->xh[$the_parser]['ac']; } elseif ($name=='DOUBLE') { // we have a DOUBLE // we must check that only 0123456789-.<space> 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']; - } + $this->xh[$the_parser]['value'] = preg_match('/^[+-]?[eE0-9\t \.]+$/', $this->xh[$the_parser]['ac']) + ? (float) $this->xh[$the_parser]['ac'] + : 'ERROR_NON_NUMERIC_FOUND'; } else { // we have an I4/INT // we must check that only 0123456789-<space> 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]['value'] = preg_match('/^[+-]?[0-9\t ]+$/', $this->xh[$the_parser]['ac']) + ? (int) $this->xh[$the_parset]['ac'] + : 'ERROR_NON_NUMERIC_FOUND'; } $this->xh[$the_parser]['ac'] = ''; $this->xh[$the_parser]['lv'] = 3; // indicate we've found a value - break; + break; case 'VALUE': // This if() detects if no scalar was inside <VALUE></VALUE> if ($this->xh[$the_parser]['vt']=='value') @@ -1036,44 +1103,49 @@ class XML_RPC_Message extends CI_Xmlrpc // Struct $this->xh[$the_parser]['value'] = $temp; } - break; + break; case 'MEMBER': - $this->xh[$the_parser]['ac']=''; + $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; + break; case 'DATA': - $this->xh[$the_parser]['ac']=''; - break; + $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; + break; case 'METHODNAME': $this->xh[$the_parser]['method'] = ltrim($this->xh[$the_parser]['ac']); - break; + break; case 'PARAMS': case 'FAULT': case 'METHODCALL': case 'METHORESPONSE': // We're all good kids with nuthin' to do - break; + break; default: - // End of an Invalid Element. Taken care of during the opening tag though - break; + // End of an Invalid Element. Taken care of during the opening tag though + break; } } - //------------------------------------- - // Parses Character Data - //------------------------------------- + // -------------------------------------------------------------------- + /** + * Parse character data + * + * @param string + * @param string + * @return void + */ public function character_data($the_parser, $data) { if ($this->xh[$the_parser]['isf'] > 1) return; // XML Fault found already @@ -1086,7 +1158,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'] = ''; } @@ -1095,12 +1167,27 @@ class XML_RPC_Message extends CI_Xmlrpc } } + // -------------------------------------------------------------------- + /** + * Add parameter + * + * @param mixed + * @return void + */ public function addParam($par) { $this->params[] = $par; } + // -------------------------------------------------------------------- + + /** + * Output parameters + * + * @param array + * @return array + */ public function output_parameters($array = FALSE) { $CI =& get_instance(); @@ -1121,31 +1208,36 @@ class XML_RPC_Message extends CI_Xmlrpc } } - $parameters = $array; + return $array; } - else + + $parameters = array(); + + for ($i = 0, $c = count($this->params); $i < $c; $i++) { - $parameters = array(); + $a_param = $this->decode_message($this->params[$i]); - for ($i = 0, $c = count($this->params); $i < $c; $i++) + if (is_array($a_param)) { - $a_param = $this->decode_message($this->params[$i]); - - if (is_array($a_param)) - { - $parameters[] = $this->output_parameters($a_param); - } - else - { - $parameters[] = ($this->xss_clean) ? $CI->security->xss_clean($a_param) : $a_param; - } + $parameters[] = $this->output_parameters($a_param); + } + else + { + $parameters[] = ($this->xss_clean) ? $CI->security->xss_clean($a_param) : $a_param; } } return $parameters; } + // -------------------------------------------------------------------- + /** + * Decode message + * + * @param object + * @return mixed + */ public function decode_message($param) { $kind = $param->kindOf(); @@ -1160,7 +1252,7 @@ class XML_RPC_Message extends CI_Xmlrpc $b = current($param->me); $arr = array(); - for($i = 0, $c = count($b); $i < $c; $i++) + for ($i = 0, $c = count($b); $i < $c; $i++) { $arr[] = $this->decode_message($param->me['array'][$i]); } @@ -1181,8 +1273,7 @@ class XML_RPC_Message extends CI_Xmlrpc } } -} -// End XML_RPC_Messages class +} // END XML_RPC_Message Class /** * XML-RPC Values class @@ -1196,6 +1287,13 @@ class XML_RPC_Values extends CI_Xmlrpc public $me = array(); public $mytype = 0; + /** + * Constructor + * + * @param mixed + * @param string + * @return void + */ public function __construct($val = -1, $type = '') { parent::__construct(); @@ -1219,11 +1317,20 @@ class XML_RPC_Values extends CI_Xmlrpc } } + // -------------------------------------------------------------------- + + /** + * Add scalar value + * + * @param scalar + * @param string + * @return int + */ public function addScalar($val, $type = 'string') { $typeof = $this->xmlrpcTypes[$type]; - if ($this->mytype==1) + if ($this->mytype == 1) { echo '<strong>XML_RPC_Values</strong>: scalar can have only one value<br />'; return 0; @@ -1237,7 +1344,7 @@ class XML_RPC_Values extends CI_Xmlrpc if ($type == $this->xmlrpcBoolean) { - $val = (strcasecmp($val,'true') === 0 OR $val == 1 OR ($val == true && strcasecmp($val, 'false'))) ? 1 : 0; + $val = (int) (strcasecmp($val,'true') === 0 OR $val === 1 OR ($val === TRUE && strcasecmp($val, 'false'))); } if ($this->mytype == 2) @@ -1253,9 +1360,18 @@ class XML_RPC_Values extends CI_Xmlrpc $this->me[$type] = $val; $this->mytype = $typeof; } + return 1; } + // -------------------------------------------------------------------- + + /** + * Add array value + * + * @param array + * @return int + */ public function addArray($vals) { if ($this->mytype != 0) @@ -1269,6 +1385,14 @@ class XML_RPC_Values extends CI_Xmlrpc return 1; } + // -------------------------------------------------------------------- + + /** + * Add struct value + * + * @param object + * @return int + */ public function addStruct($vals) { if ($this->mytype != 0) @@ -1281,29 +1405,37 @@ class XML_RPC_Values extends CI_Xmlrpc return 1; } + // -------------------------------------------------------------------- + + /** + * Get value type + * + * @return string + */ public function kindOf() { - switch($this->mytype) + switch ($this->mytype) { - case 3: - return 'struct'; - break; - case 2: - return 'array'; - break; - case 1: - return 'scalar'; - break; - default: - return 'undef'; + case 3: return 'struct'; + case 2: return 'array'; + case 1: return 'scalar'; + default: return 'undef'; } } + // -------------------------------------------------------------------- + + /** + * Serialize data + * + * @param string + * @param mixed + */ public function serializedata($typ, $val) { $rs = ''; - switch($this->xmlrpcTypes[$typ]) + switch ($this->xmlrpcTypes[$typ]) { case 3: // struct @@ -1314,11 +1446,11 @@ class XML_RPC_Values extends CI_Xmlrpc $rs .= "<member>\n<name>{$key2}</name>\n".$this->serializeval($val2)."</member>\n"; } $rs .= '</struct>'; - break; + break; case 2: // array $rs .= "<array>\n<data>\n"; - for($i = 0, $c = count($val); $i < $c; $i++) + for ($i = 0, $c = count($val); $i < $c; $i++) { $rs .= $this->serializeval($val[$i]); } @@ -1329,29 +1461,45 @@ class XML_RPC_Values extends CI_Xmlrpc switch ($typ) { case $this->xmlrpcBase64: - $rs .= "<{$typ}>" . base64_encode((string)$val) . "</{$typ}>\n"; - break; + $rs .= '<'.$typ.'>'.base64_encode( (string) $val).'</'.$typ.">\n"; + break; case $this->xmlrpcBoolean: - $rs .= "<{$typ}>" . ((bool)$val ? '1' : '0') . "</{$typ}>\n"; - break; + $rs .= '<'.$typ.'>'.( (bool) $val ? '1' : '0').'</'.$typ.">\n"; + break; case $this->xmlrpcString: - $rs .= "<{$typ}>" . htmlspecialchars((string)$val). "</{$typ}>\n"; - break; + $rs .= '<'.$typ.'>'.htmlspecialchars( (string) $val).'</'.$typ.">\n"; + break; default: - $rs .= "<{$typ}>{$val}</{$typ}>\n"; - break; + $rs .= '<'.$typ.'>'.$val.'</'.$typ.">\n"; + break; } default: - break; + break; } + return $rs; } + // -------------------------------------------------------------------- + + /** + * Serialize class + * + * @return string + */ public function serialize_class() { return $this->serializeval($this); } + // -------------------------------------------------------------------- + + /** + * Serialize value + * + * @param object + * @return string + */ public function serializeval($o) { $ar = $o->me; @@ -1361,26 +1509,35 @@ class XML_RPC_Values extends CI_Xmlrpc return "<value>\n".$this->serializedata($typ, $val)."</value>\n"; } + // -------------------------------------------------------------------- + + /** + * Scalar value + * + * @return mixed + */ public function scalarval() { reset($this->me); return current($this->me); } - - //------------------------------------- - // Encode time in ISO-8601 form. - //------------------------------------- - - // Useful for sending time in XML-RPC - - public function iso8601_encode($time, $utc = 0) + // -------------------------------------------------------------------- + + /** + * Encode time in ISO-8601 form. + * Useful for sending time in XML-RPC + * + * @param int unix timestamp + * @param bool + * @return string + */ + public function iso8601_encode($time, $utc = FALSE) { return ($utc) ? strftime('%Y%m%dT%H:%i:%s', $time) : gmstrftime('%Y%m%dT%H:%i:%s', $time); } -} -// END XML_RPC_Values Class +} // END XML_RPC_Values Class /* End of file Xmlrpc.php */ -/* Location: ./system/libraries/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 fc41444bc..6d270c2ea 100644 --- a/system/libraries/Xmlrpcs.php +++ b/system/libraries/Xmlrpcs.php @@ -54,10 +54,7 @@ class CI_Xmlrpcs extends CI_Xmlrpc public $controller_obj; public $object = FALSE; - /** - * Constructor - */ - public function __construct($config=array()) + public function __construct($config = array()) { parent::__construct(); $this->set_system_methods(); @@ -67,7 +64,7 @@ class CI_Xmlrpcs extends CI_Xmlrpc $this->methods = array_merge($this->methods, $config['functions']); } - log_message('debug', "XML-RPC Server Class Initialized"); + log_message('debug', 'XML-RPC Server Class Initialized'); } // -------------------------------------------------------------------- @@ -75,7 +72,6 @@ class CI_Xmlrpcs extends CI_Xmlrpc /** * Initialize Prefs and Serve * - * @access public * @param mixed * @return void */ @@ -107,7 +103,6 @@ class CI_Xmlrpcs extends CI_Xmlrpc /** * Setting of System Methods * - * @access public * @return void */ public function set_system_methods() @@ -137,7 +132,6 @@ class CI_Xmlrpcs extends CI_Xmlrpc /** * Main Server Function * - * @access public * @return void */ public function serve() @@ -145,8 +139,8 @@ class CI_Xmlrpcs extends CI_Xmlrpc $r = $this->parseRequest(); $payload = '<?xml version="1.0" encoding="'.$this->xmlrpc_defencoding.'"?'.'>'."\n".$this->debug_msg.$r->prepare_response(); - header("Content-Type: text/xml"); - header("Content-Length: ".strlen($payload)); + header('Content-Type: text/xml'); + header('Content-Length: '.strlen($payload)); exit($payload); } @@ -155,7 +149,6 @@ class CI_Xmlrpcs extends CI_Xmlrpc /** * Add Method to Class * - * @access public * @param string method name * @param string function * @param string signature @@ -176,7 +169,6 @@ class CI_Xmlrpcs extends CI_Xmlrpc /** * Parse Server Request * - * @access public * @param string data * @return object xmlrpc response */ @@ -198,7 +190,7 @@ class CI_Xmlrpcs extends CI_Xmlrpc //------------------------------------- $parser = xml_parser_create($this->xmlrpc_defencoding); - $parser_object = new XML_RPC_Message("filler"); + $parser_object = new XML_RPC_Message('filler'); $parser_object->xh[$parser] = array( 'isf' => 0, @@ -215,7 +207,6 @@ class CI_Xmlrpcs extends CI_Xmlrpc xml_set_character_data_handler($parser, 'character_data'); //xml_set_default_handler($parser, 'default_handler'); - //------------------------------------- // PARSE + PROCESS XML DATA //------------------------------------- @@ -245,7 +236,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]); @@ -276,7 +267,6 @@ class CI_Xmlrpcs extends CI_Xmlrpc /** * Executes the Method * - * @access protected * @param object * @return mixed */ @@ -305,7 +295,7 @@ class CI_Xmlrpcs extends CI_Xmlrpc // Check for Method (and Object) //------------------------------------- - $method_parts = explode(".", $this->methods[$methName]['function']); + $method_parts = explode('.', $this->methods[$methName]['function']); $objectCall = (isset($method_parts[1]) && $method_parts[1] != ''); if ($system_call === TRUE) @@ -315,14 +305,11 @@ class CI_Xmlrpcs extends CI_Xmlrpc return new XML_RPC_Response(0, $this->xmlrpcerr['unknown_method'], $this->xmlrpcstr['unknown_method']); } } - else + elseif (($objectCall && ! is_callable(array($method_parts[0], $method_parts[1]))) + OR ( ! $objectCall && ! is_callable($this->methods[$methName]['function'])) + ) { - if (($objectCall AND ! is_callable(array($method_parts[0], $method_parts[1]))) - OR ( ! $objectCall AND ! 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']); } //------------------------------------- @@ -351,7 +338,7 @@ class CI_Xmlrpcs extends CI_Xmlrpc return new XML_RPC_Response(0, $this->xmlrpcerr['incorrect_params'], $this->xmlrpcstr['incorrect_params'] . - ": Wanted {$wanted}, got {$pt} at param {$pno})"); + ': Wanted '.$wanted.', got '.$pt.' at param '.$pno.')'); } } } @@ -393,7 +380,6 @@ class CI_Xmlrpcs extends CI_Xmlrpc /** * Server Function: List Methods * - * @access public * @param mixed * @return object */ @@ -409,7 +395,7 @@ class CI_Xmlrpcs extends CI_Xmlrpc foreach ($this->system_methods as $key => $value) { - $output[]= new XML_RPC_Values($key, 'string'); + $output[] = new XML_RPC_Values($key, 'string'); } $v->addArray($output); @@ -421,7 +407,6 @@ class CI_Xmlrpcs extends CI_Xmlrpc /** * Server Function: Return Signature for Method * - * @access public * @param mixed * @return object */ @@ -447,18 +432,14 @@ class CI_Xmlrpcs extends CI_Xmlrpc } $sigs[] = new XML_RPC_Values($cursig, 'array'); } - $r = new XML_RPC_Response(new XML_RPC_Values($sigs, 'array')); - } - else - { - $r = new XML_RPC_Response(new XML_RPC_Values('undef', 'string')); + + return new XML_RPC_Response(new XML_RPC_Values($sigs, 'array')); } + + return new XML_RPC_Response(new XML_RPC_Values('undef', 'string')); } - else - { - $r = new XML_RPC_Response(0,$this->xmlrpcerr['introspect_unknown'], $this->xmlrpcstr['introspect_unknown']); - } - return $r; + + return new XML_RPC_Response(0,$this->xmlrpcerr['introspect_unknown'], $this->xmlrpcstr['introspect_unknown']); } // -------------------------------------------------------------------- @@ -466,7 +447,6 @@ class CI_Xmlrpcs extends CI_Xmlrpc /** * Server Function: Doc String for Method * - * @access public * @param mixed * @return object */ @@ -492,7 +472,6 @@ class CI_Xmlrpcs extends CI_Xmlrpc /** * Server Function: Multi-call * - * @access public * @param mixed * @return object */ @@ -536,7 +515,6 @@ class CI_Xmlrpcs extends CI_Xmlrpc /** * Multi-call Function: Error Handling * - * @access public * @param mixed * @return object */ @@ -556,7 +534,6 @@ class CI_Xmlrpcs extends CI_Xmlrpc /** * Multi-call Function: Processes method * - * @access public * @param mixed * @return object */ @@ -610,7 +587,6 @@ class CI_Xmlrpcs extends CI_Xmlrpc } } -// END XML_RPC_Server class /* End of file Xmlrpcs.php */ -/* Location: ./system/libraries/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 e33eb4e5a..80438546b 100644 --- a/system/libraries/Zip.php +++ b/system/libraries/Zip.php @@ -1,13 +1,13 @@ -<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed'); +<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed'); /** * CodeIgniter * * An open source application development framework for PHP 5.2.4 or newer * * NOTICE OF LICENSE - * + * * Licensed under the Open Software License version 3.0 - * + * * This source file is subject to the Open Software License (OSL 3.0) that is * bundled with this package in the files license.txt / license.rst. It is * also available through the world wide web at this URL: @@ -25,8 +25,6 @@ * @filesource */ -// ------------------------------------------------------------------------ - /** * Zip Compression Class * @@ -44,21 +42,17 @@ */ class CI_Zip { - var $zipdata = ''; - var $directory = ''; - var $entries = 0; - var $file_num = 0; - var $offset = 0; - var $now; + public $zipdata = ''; + public $directory = ''; + public $entries = 0; + public $file_num = 0; + public $offset = 0; + public $now; - /** - * Constructor - */ public function __construct() { - log_message('debug', "Zip Compression Class Initialized"); - $this->now = time(); + log_message('debug', 'Zip Compression Class Initialized'); } // -------------------------------------------------------------------- @@ -68,21 +62,19 @@ class CI_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) + public function add_dir($directory) { - foreach ((array)$directory as $dir) + foreach ( (array) $directory as $dir) { - if ( ! preg_match("|.+/$|", $dir)) + if ( ! preg_match('|.+/$|', $dir)) { $dir .= '/'; } $dir_time = $this->_get_mod_time($dir); - $this->_add_dir($dir, $dir_time['file_mtime'], $dir_time['file_mdate']); } } @@ -90,22 +82,22 @@ class CI_Zip { // -------------------------------------------------------------------- /** - * Get file/directory modification time + * Get file/directory modification time * - * If this is a newly created file/dir, we will set the time to 'now' + * If this is a newly created file/dir, we will set the time to 'now' * - * @param string path to file - * @return array filemtime/filemdate + * @param string path to file + * @return array filemtime/filemdate */ - function _get_mod_time($dir) + protected function _get_mod_time($dir) { // filemtime() may return false, but raises an error for non-existing files - $date = (file_exists($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']; + $date = file_exists($dir) ? filemtime($dir) : getdate($this->now); - return $time; + return array( + 'file_mtime' => ($date['hours'] << 11) + ($date['minutes'] << 5) + $date['seconds'] / 2, + 'file_mdate' => (($date['year'] - 1980) << 9) + ($date['mon'] << 5) + $date['mday'] + ); } // -------------------------------------------------------------------- @@ -113,13 +105,14 @@ class CI_Zip { /** * Add Directory * - * @access private * @param string the directory name + * @param int + * @param int * @return void */ - function _add_dir($dir, $file_mtime, $file_mdate) + protected function _add_dir($dir, $file_mtime, $file_mdate) { - $dir = str_replace("\\", "/", $dir); + $dir = str_replace('\\', '/', $dir); $this->zipdata .= "\x50\x4b\x03\x04\x0a\x00\x00\x00\x00\x00" @@ -162,29 +155,26 @@ class CI_Zip { * 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 + * 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) + public function add_data($filepath, $data = NULL) { if (is_array($filepath)) { foreach ($filepath as $path => $data) { $file_data = $this->_get_mod_time($path); - $this->_add_data($path, $data, $file_data['file_mtime'], $file_data['file_mdate']); } } else { $file_data = $this->_get_mod_time($filepath); - $this->_add_data($filepath, $data, $file_data['file_mtime'], $file_data['file_mdate']); } } @@ -194,20 +184,19 @@ class CI_Zip { /** * Add Data to Zip * - * @access private * @param string the file name/path * @param string the data to be encoded + * @param int + * @param int * @return void */ - function _add_data($filepath, $data, $file_mtime, $file_mdate) + protected function _add_data($filepath, $data, $file_mtime, $file_mdate) { - $filepath = str_replace("\\", "/", $filepath); + $filepath = str_replace('\\', '/', $filepath); $uncompressed_size = strlen($data); $crc32 = crc32($data); - - $gzdata = gzcompress($data); - $gzdata = substr($gzdata, 2, -4); + $gzdata = substr(gzcompress($data), 2, -4); $compressed_size = strlen($gzdata); $this->zipdata .= @@ -248,10 +237,11 @@ class CI_Zip { /** * Read the contents of a file and add it to the zip * - * @access public + * @param string + * @param bool * @return bool */ - function read_file($path, $preserve_filepath = FALSE) + public function read_file($path, $preserve_filepath = FALSE) { if ( ! file_exists($path)) { @@ -260,16 +250,16 @@ class CI_Zip { if (FALSE !== ($data = file_get_contents($path))) { - $name = str_replace("\\", "/", $path); - + $name = str_replace('\\', '/', $path); if ($preserve_filepath === FALSE) { - $name = preg_replace("|.*/(.+)|", "\\1", $name); + $name = preg_replace('|.*/(.+)|', '\\1', $name); } $this->add_data($name, $data); return TRUE; } + return FALSE; } @@ -279,15 +269,17 @@ class CI_Zip { * 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 + * 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 + * @param bool + * @param bool * @return bool */ - function read_dir($path, $preserve_filepath = TRUE, $root_path = NULL) + public function read_dir($path, $preserve_filepath = TRUE, $root_path = NULL) { + $path = rtrim($path, '/\\').DIRECTORY_SEPARATOR; if ( ! $fp = @opendir($path)) { return FALSE; @@ -296,36 +288,32 @@ class CI_Zip { // Set the original directory root for child dir's to use as relative if ($root_path === NULL) { - $root_path = dirname($path).'/'; + $root_path = dirname($path).DIRECTORY_SEPARATOR; } while (FALSE !== ($file = readdir($fp))) { - if (substr($file, 0, 1) == '.') + if ($file[0] === '.') { continue; } if (@is_dir($path.$file)) { - $this->read_dir($path.$file."/", $preserve_filepath, $root_path); + $this->read_dir($path.$file.DIRECTORY_SEPARATOR, $preserve_filepath, $root_path); } - else + elseif (FALSE !== ($data = file_get_contents($path.$file))) { - if (FALSE !== ($data = file_get_contents($path.$file))) + $name = str_replace(array('\\', '/'), DIRECTORY_SEPARATOR, $path); + if ($preserve_filepath === FALSE) { - $name = str_replace("\\", "/", $path); - - if ($preserve_filepath === FALSE) - { - $name = str_replace($root_path, '', $name); - } - - $this->add_data($name.$file, $data); + $name = str_replace($root_path, '', $name); } + $this->add_data($name.$file, $data); } } + closedir($fp); return TRUE; } @@ -334,26 +322,23 @@ class CI_Zip { /** * Get the Zip file * - * @access public - * @return binary string + * @return string (binary encoded) */ - function get_zip() + public function get_zip() { // Is there any data to return? - if ($this->entries == 0) + 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; + return $this->zipdata + .$this->directory."\x50\x4b\x05\x06\x00\x00\x00\x00" + .pack('v', $this->entries) // total # of entries "on this disk" + .pack('v', $this->entries) // total # of entries overall + .pack('V', strlen($this->directory)) // size of central dir + .pack('V', strlen($this->zipdata)) // offset to start of central dir + ."\x00\x00"; // .zip file comment length } // -------------------------------------------------------------------- @@ -363,11 +348,10 @@ class CI_Zip { * * Lets you write a file * - * @access public * @param string the file name * @return bool */ - function archive($filepath) + public function archive($filepath) { if ( ! ($fp = @fopen($filepath, FOPEN_WRITE_CREATE_DESTRUCTIVE))) { @@ -387,23 +371,19 @@ class CI_Zip { /** * Download * - * @access public * @param string the file name - * @param string the data to be encoded - * @return bool + * @return void */ - function download($filename = 'backup.zip') + public function download($filename = 'backup.zip') { - if ( ! preg_match("|.+?\.zip$|", $filename)) + if ( ! preg_match('|.+?\.zip$|', $filename)) { $filename .= '.zip'; } $CI =& get_instance(); $CI->load->helper('download'); - $get_zip = $this->get_zip(); - $zip_content =& $get_zip; force_download($filename, $zip_content); @@ -414,19 +394,19 @@ class CI_Zip { /** * Initialize Data * - * Lets you clear current zip data. Useful if you need to create + * Lets you clear current zip data. Useful if you need to create * multiple zips with different data. * - * @access public - * @return void + * @return object */ - function clear_data() + public function clear_data() { $this->zipdata = ''; $this->directory = ''; $this->entries = 0; $this->file_num = 0; $this->offset = 0; + return $this; } } diff --git a/tests/Bootstrap.php b/tests/Bootstrap.php index 39c24b219..9f89d1be8 100644 --- a/tests/Bootstrap.php +++ b/tests/Bootstrap.php @@ -6,16 +6,16 @@ error_reporting(E_ALL | E_STRICT); $dir = realpath(dirname(__FILE__)); - // Path constants define('PROJECT_BASE', realpath($dir.'/../').'/'); define('BASEPATH', PROJECT_BASE.'system/'); define('APPPATH', PROJECT_BASE.'application/'); define('VIEWPATH', PROJECT_BASE.''); - // Prep our test environment -require_once $dir.'/lib/common.php'; -require_once $dir.'/lib/ci_testcase.php'; +require_once 'vfsStream/vfsStream.php'; +include_once $dir.'/mocks/core/common.php'; +include_once $dir.'/mocks/autoloader.php'; +spl_autoload_register('autoload'); unset($dir);
\ No newline at end of file diff --git a/tests/codeigniter/core/Common_test.php b/tests/codeigniter/core/Common_test.php index cec12982d..dded2e824 100644 --- a/tests/codeigniter/core/Common_test.php +++ b/tests/codeigniter/core/Common_test.php @@ -1,9 +1,6 @@ <?php -require_once(BASEPATH.'helpers/email_helper.php'); - -class Common_test extends CI_TestCase -{ +class Common_test extends CI_TestCase { // ------------------------------------------------------------------------ diff --git a/tests/codeigniter/core/Loader_test.php b/tests/codeigniter/core/Loader_test.php index b86fd3477..43008651e 100644 --- a/tests/codeigniter/core/Loader_test.php +++ b/tests/codeigniter/core/Loader_test.php @@ -1,38 +1,5 @@ <?php -require_once 'vfsStream/vfsStream.php'; -require_once BASEPATH.'/core/Loader.php'; - -class Extended_Loader extends CI_Loader { - - /** - * Since we use paths to load up models, views, etc, we need the ability to - * mock up the file system so when core tests are run, we aren't mucking - * in the application directory. this will give finer grained control over - * these tests. So yeah, while this looks odd, I need to overwrite protected - * class vars in the loader. So here we go... - * - * @covers CI_Loader::__construct() - */ - public function __construct() - { - vfsStreamWrapper::register(); - vfsStreamWrapper::setRoot(new vfsStreamDirectory('application')); - - $this->models_dir = vfsStream::newDirectory('models')->at(vfsStreamWrapper::getRoot()); - $this->libs_dir = vfsStream::newDirectory('libraries')->at(vfsStreamWrapper::getRoot()); - $this->helpers_dir = vfsStream::newDirectory('helpers')->at(vfsStreamWrapper::getRoot()); - $this->views_dir = vfsStream::newDirectory('views')->at(vfsStreamWrapper::getRoot()); - - $this->_ci_ob_level = ob_get_level(); - $this->_ci_library_paths = array(vfsStream::url('application').'/', BASEPATH); - $this->_ci_helper_paths = array(vfsStream::url('application').'/', BASEPATH); - $this->_ci_model_paths = array(vfsStream::url('application').'/'); - $this->_ci_view_paths = array(vfsStream::url('application').'/views/' => TRUE); - } -} - - class Loader_test extends CI_TestCase { private $ci_obj; @@ -40,7 +7,7 @@ class Loader_test extends CI_TestCase { public function set_up() { // Instantiate a new loader - $this->load = new Extended_Loader(); + $this->load = new Mock_Core_Loader(); // mock up a ci instance $this->ci_obj = new StdClass; @@ -265,7 +232,4 @@ class Loader_test extends CI_TestCase { // -------------------------------------------------------------------- - - - } diff --git a/tests/codeigniter/core/URI_test.php b/tests/codeigniter/core/URI_test.php index 40252aa14..e340ddf73 100644 --- a/tests/codeigniter/core/URI_test.php +++ b/tests/codeigniter/core/URI_test.php @@ -1,41 +1,10 @@ <?php -require BASEPATH.'core/URI.php'; - -/** - * Extend the URI class - * - override contructor - * - override CLI detection - */ -class URI_extended extends CI_URI { - - public function __construct() - { - $test = CI_TestCase::instance(); - $cls =& $test->ci_core_class('cfg'); - - // set predictable config values - $test->ci_set_config(array( - 'index_page' => 'index.php', - 'base_url' => 'http://example.com/', - 'subclass_prefix' => 'MY_' - )); - - $this->config = new $cls; - - } - - protected function _is_cli_request() - { - return FALSE; - } -} - class URI_test extends CI_TestCase { public function set_up() { - $this->uri = new URI_extended(); + $this->uri = new Mock_Core_URI(); } // -------------------------------------------------------------------- diff --git a/tests/codeigniter/database/DB_test.php b/tests/codeigniter/database/DB_test.php new file mode 100644 index 000000000..9b93e223d --- /dev/null +++ b/tests/codeigniter/database/DB_test.php @@ -0,0 +1,49 @@ +<?php + +class DB_test extends CI_TestCase { + + // ------------------------------------------------------------------------ + + public function test_db_invalid() + { + $connection = new Mock_Database_DB(array( + 'undefined' => array( + 'dsn' => '', + 'hostname' => 'undefined', + 'username' => 'undefined', + 'password' => 'undefined', + 'database' => 'undefined', + 'dbdriver' => 'undefined', + ), + )); + + $this->setExpectedException('InvalidArgumentException', 'CI Error: Invalid DB driver'); + + Mock_Database_DB::DB($connection->set_dsn('undefined'), TRUE); + } + + // ------------------------------------------------------------------------ + + public function test_db_valid() + { + $config = Mock_Database_DB::config(DB_DRIVER); + $connection = new Mock_Database_DB($config); + $db = Mock_Database_DB::DB($connection->set_dsn(DB_DRIVER), TRUE); + + $this->assertTrue($db instanceof CI_DB); + $this->assertTrue($db instanceof CI_DB_Driver); + } + + // ------------------------------------------------------------------------ + + public function test_db_failover() + { + $config = Mock_Database_DB::config(DB_DRIVER); + $connection = new Mock_Database_DB($config); + $db = Mock_Database_DB::DB($connection->set_dsn(DB_DRIVER.'_failover'), TRUE); + + $this->assertTrue($db instanceof CI_DB); + $this->assertTrue($db instanceof CI_DB_Driver); + } + +}
\ No newline at end of file diff --git a/tests/codeigniter/database/query_builder/.gitkeep b/tests/codeigniter/database/query_builder/.gitkeep new file mode 100644 index 000000000..e69de29bb --- /dev/null +++ b/tests/codeigniter/database/query_builder/.gitkeep diff --git a/tests/codeigniter/helpers/array_helper_test.php b/tests/codeigniter/helpers/array_helper_test.php index 62559de83..9cd15960f 100644 --- a/tests/codeigniter/helpers/array_helper_test.php +++ b/tests/codeigniter/helpers/array_helper_test.php @@ -1,13 +1,11 @@ <?php -// OLD TEST FORMAT: DO NOT COPY - -require_once(BASEPATH.'helpers/array_helper.php'); - -class Array_helper_test extends CI_TestCase -{ +class Array_helper_test extends CI_TestCase { + public function set_up() { + $this->helper('array'); + $this->my_array = array( 'foo' => 'bar', 'sally' => 'jim', diff --git a/tests/codeigniter/helpers/date_helper_test.php b/tests/codeigniter/helpers/date_helper_test.php index 662d16485..17d1ef21e 100644 --- a/tests/codeigniter/helpers/date_helper_test.php +++ b/tests/codeigniter/helpers/date_helper_test.php @@ -1,8 +1,12 @@ <?php -require_once BASEPATH.'helpers/date_helper.php'; -class Date_helper_test extends CI_TestCase -{ +class Date_helper_test extends CI_TestCase { + + public function set_up() + { + $this->helper('date'); + } + // ------------------------------------------------------------------------ public function test_now_local() diff --git a/tests/codeigniter/helpers/directory_helper_test.php b/tests/codeigniter/helpers/directory_helper_test.php index 3fae81b82..3937d2913 100644 --- a/tests/codeigniter/helpers/directory_helper_test.php +++ b/tests/codeigniter/helpers/directory_helper_test.php @@ -1,12 +1,11 @@ <?php -require_once 'vfsStream/vfsStream.php'; -require BASEPATH.'helpers/directory_helper.php'; - -class Directory_helper_test extends CI_TestCase -{ +class Directory_helper_test extends CI_TestCase { + public function set_up() { + $this->helper('directory'); + vfsStreamWrapper::register(); vfsStreamWrapper::setRoot(new vfsStreamDirectory('testDir')); diff --git a/tests/codeigniter/helpers/email_helper_test.php b/tests/codeigniter/helpers/email_helper_test.php index 7324e8109..a01f3d5af 100644 --- a/tests/codeigniter/helpers/email_helper_test.php +++ b/tests/codeigniter/helpers/email_helper_test.php @@ -1,10 +1,12 @@ <?php -require_once(BASEPATH.'helpers/email_helper.php'); +class Email_helper_test extends CI_TestCase { + + public function set_up() + { + $this->helper('email'); + } -class Email_helper_test extends CI_TestCase -{ - public function test_valid_email() { $this->assertEquals(FALSE, valid_email('test')); diff --git a/tests/codeigniter/helpers/file_helper_test.php b/tests/codeigniter/helpers/file_helper_test.php index a596a0375..4b9c29485 100644 --- a/tests/codeigniter/helpers/file_helper_test.php +++ b/tests/codeigniter/helpers/file_helper_test.php @@ -1,12 +1,11 @@ <?php -require_once 'vfsStream/vfsStream.php'; -require BASEPATH.'helpers/file_helper.php'; +class File_helper_Test extends CI_TestCase { -class File_helper_Test extends CI_TestCase -{ public function set_up() { + $this->helper('file'); + vfsStreamWrapper::register(); vfsStreamWrapper::setRoot(new vfsStreamDirectory('testDir')); diff --git a/tests/codeigniter/helpers/form_helper_test.php b/tests/codeigniter/helpers/form_helper_test.php new file mode 100644 index 000000000..80bace9d1 --- /dev/null +++ b/tests/codeigniter/helpers/form_helper_test.php @@ -0,0 +1,252 @@ +<?php + +require BASEPATH . 'core/Common.php'; +require BASEPATH . 'helpers/form_helper.php'; + +class Form_helper_test extends CI_TestCase +{ + public function test_form_hidden() + { + $expected = <<<EOH + +<input type="hidden" name="username" value="johndoe" /> + +EOH; + + $this->assertEquals($expected, form_hidden('username', 'johndoe')); + } + + public function test_form_input() + { + $expected = <<<EOH +<input type="text" name="username" value="johndoe" id="username" maxlength="100" size="50" style="width:50%" /> + +EOH; + + $data = array( + 'name' => 'username', + 'id' => 'username', + 'value' => 'johndoe', + 'maxlength' => '100', + 'size' => '50', + 'style' => 'width:50%', + ); + + $this->assertEquals($expected, form_input($data)); + } + + public function test_form_password() + { + $expected = <<<EOH +<input type="password" name="password" value="" /> + +EOH; + + $this->assertEquals($expected, form_password('password')); + } + + public function test_form_upload() + { + $expected = <<<EOH +<input type="file" name="attachment" value="" /> + +EOH; + + $this->assertEquals($expected, form_upload('attachment')); + } + + public function test_form_textarea() + { + $expected = <<<EOH +<textarea name="notes" cols="40" rows="10" >Notes</textarea> + +EOH; + + $this->assertEquals($expected, form_textarea('notes', 'Notes')); + } + + public function test_form_dropdown() + { + $expected = <<<EOH +<select name="shirts"> +<option value="small">Small Shirt</option> +<option value="med">Medium Shirt</option> +<option value="large" selected="selected">Large Shirt</option> +<option value="xlarge">Extra Large Shirt</option> +</select> + +EOH; + + $options = array( + 'small' => 'Small Shirt', + 'med' => 'Medium Shirt', + 'large' => 'Large Shirt', + 'xlarge' => 'Extra Large Shirt', + ); + + $this->assertEquals($expected, form_dropdown('shirts', $options, 'large')); + + $expected = <<<EOH +<select name="shirts" multiple="multiple"> +<option value="small" selected="selected">Small Shirt</option> +<option value="med">Medium Shirt</option> +<option value="large" selected="selected">Large Shirt</option> +<option value="xlarge">Extra Large Shirt</option> +</select> + +EOH; + + $shirts_on_sale = array('small', 'large'); + + $this->assertEquals($expected, form_dropdown('shirts', $options, $shirts_on_sale)); + + $options = array( + 'Swedish Cars' => array( + 'volvo' => 'Volvo', + 'saab' => 'Saab' + ), + 'German Cars' => array( + 'mercedes' => 'Mercedes', + 'audi' => 'Audi' + ) + ); + + $expected = <<<EOH +<select name="cars" multiple="multiple"> +<optgroup label="Swedish Cars"> +<option value="volvo" selected="selected">Volvo</option> +<option value="saab">Saab</option> +</optgroup> +<optgroup label="German Cars"> +<option value="mercedes">Mercedes</option> +<option value="audi" selected="selected">Audi</option> +</optgroup> +</select> + +EOH; + + $cars_on_sale = array('volvo', 'audi'); + + $this->assertEquals($expected, form_dropdown('cars', $options, $cars_on_sale)); + + } + + public function test_form_multiselect() + { + $expected = <<<EOH +<select name="shirts[]" multiple="multiple"> +<option value="small">Small Shirt</option> +<option value="med" selected="selected">Medium Shirt</option> +<option value="large" selected="selected">Large Shirt</option> +<option value="xlarge">Extra Large Shirt</option> +</select> + +EOH; + + $options = array( + 'small' => 'Small Shirt', + 'med' => 'Medium Shirt', + 'large' => 'Large Shirt', + 'xlarge' => 'Extra Large Shirt', + ); + + $this->assertEquals($expected, form_multiselect('shirts[]', $options, array('med', 'large'))); + } + + public function test_form_fieldset() + { + $expected = <<<EOH +<fieldset> +<legend>Address Information</legend> + +EOH; + + $this->assertEquals($expected, form_fieldset('Address Information')); + } + + public function test_form_fieldset_close() + { + $expected = <<<EOH +</fieldset></div></div> +EOH; + + $this->assertEquals($expected, form_fieldset_close('</div></div>')); + } + + public function test_form_checkbox() + { + $expected = <<<EOH +<input type="checkbox" name="newsletter" value="accept" checked="checked" /> + +EOH; + + $this->assertEquals($expected, form_checkbox('newsletter', 'accept', TRUE)); + } + + public function test_form_radio() + { + $expected = <<<EOH +<input type="radio" name="newsletter" value="accept" checked="checked" /> + +EOH; + + $this->assertEquals($expected, form_radio('newsletter', 'accept', TRUE)); + } + + public function test_form_submit() + { + $expected = <<<EOH +<input type="submit" name="mysubmit" value="Submit Post!" /> + +EOH; + + $this->assertEquals($expected, form_submit('mysubmit', 'Submit Post!')); + } + + public function test_form_label() + { + $expected = <<<EOH +<label for="username">What is your Name</label> +EOH; + + $this->assertEquals($expected, form_label('What is your Name', 'username')); + } + + public function test_form_reset() + { + $expected = <<<EOH +<input type="reset" name="myreset" value="Reset" /> + +EOH; + + $this->assertEquals($expected, form_reset('myreset', 'Reset')); + } + + public function test_form_button() + { + $expected = <<<EOH +<button name="name" type="button" >content</button> + +EOH; + + $this->assertEquals($expected, form_button('name','content')); + } + + public function test_form_close() + { + $expected = <<<EOH +</form></div></div> +EOH; + + $this->assertEquals($expected, form_close('</div></div>')); + } + + public function test_form_prep() + { + $expected = "Here is a string containing "quoted" text."; + + $this->assertEquals($expected, form_prep('Here is a string containing "quoted" text.')); + } +} + +/* End of file form_helper_test.php */
\ No newline at end of file diff --git a/tests/codeigniter/helpers/html_helper_test.php b/tests/codeigniter/helpers/html_helper_test.php index 553fc2bb1..28974b0f8 100644 --- a/tests/codeigniter/helpers/html_helper_test.php +++ b/tests/codeigniter/helpers/html_helper_test.php @@ -1,9 +1,11 @@ <?php -require_once(BASEPATH.'helpers/html_helper.php'); +class Html_helper_test extends CI_TestCase { -class Html_helper_test extends CI_TestCase -{ + public function set_up() + { + $this->helper('html'); + } // ------------------------------------------------------------------------ diff --git a/tests/codeigniter/helpers/inflector_helper_test.php b/tests/codeigniter/helpers/inflector_helper_test.php index 472e28adb..9e9478711 100644 --- a/tests/codeigniter/helpers/inflector_helper_test.php +++ b/tests/codeigniter/helpers/inflector_helper_test.php @@ -1,9 +1,11 @@ <?php -require_once(BASEPATH.'helpers/inflector_helper.php'); - class Inflector_helper_test extends CI_TestCase { + public function set_up() + { + $this->helper('inflector'); + } public function test_singular() { diff --git a/tests/codeigniter/helpers/number_helper_test.php b/tests/codeigniter/helpers/number_helper_test.php index 3322b2475..4bb9a918a 100644 --- a/tests/codeigniter/helpers/number_helper_test.php +++ b/tests/codeigniter/helpers/number_helper_test.php @@ -1,12 +1,11 @@ <?php -require_once BASEPATH.'helpers/number_helper.php'; - -class Number_helper_test extends CI_TestCase -{ +class Number_helper_test extends CI_TestCase { public function set_up() { + $this->helper('number'); + // Grab the core lang class $lang_cls = $this->ci_core_class('lang'); diff --git a/tests/codeigniter/helpers/path_helper_test.php b/tests/codeigniter/helpers/path_helper_test.php index 2e6cc6391..632f57501 100644 --- a/tests/codeigniter/helpers/path_helper_test.php +++ b/tests/codeigniter/helpers/path_helper_test.php @@ -1,9 +1,12 @@ <?php -require BASEPATH . 'helpers/path_helper.php'; +class Path_helper_test extends CI_TestCase { + + public function set_up() + { + $this->helper('path'); + } -class Path_helper_test extends CI_TestCase -{ public function test_set_realpath() { $expected = getcwd() . DIRECTORY_SEPARATOR; diff --git a/tests/codeigniter/helpers/string_helper_test.php b/tests/codeigniter/helpers/string_helper_test.php index a884d6284..29c3d6594 100644 --- a/tests/codeigniter/helpers/string_helper_test.php +++ b/tests/codeigniter/helpers/string_helper_test.php @@ -1,9 +1,12 @@ <?php -require_once(BASEPATH.'helpers/string_helper.php'); +class String_helper_test extends CI_TestCase { + + public function set_up() + { + $this->helper('string'); + } -class String_helper_test extends CI_TestCase -{ public function test_strip_slashes() { $expected = array( diff --git a/tests/codeigniter/helpers/text_helper_test.php b/tests/codeigniter/helpers/text_helper_test.php index a0866e638..584066b0c 100644 --- a/tests/codeigniter/helpers/text_helper_test.php +++ b/tests/codeigniter/helpers/text_helper_test.php @@ -1,13 +1,13 @@ <?php -require_once(BASEPATH.'helpers/text_helper.php'); +class Text_helper_test extends CI_TestCase { -class Text_helper_test extends CI_TestCase -{ private $_long_string; public function set_up() { + $this->helper('text'); + $this->_long_string = 'Once upon a time, a framework had no tests. It sad. So some nice people began to write tests. The more time that went on, the happier it became. Everyone was happy.'; } diff --git a/tests/codeigniter/helpers/url_helper_test.php b/tests/codeigniter/helpers/url_helper_test.php index 51a8cc7c0..c561809ce 100644 --- a/tests/codeigniter/helpers/url_helper_test.php +++ b/tests/codeigniter/helpers/url_helper_test.php @@ -1,9 +1,12 @@ <?php -require_once(BASEPATH.'helpers/url_helper.php'); +class Url_helper_test extends CI_TestCase { + + public function set_up() + { + $this->helper('url'); + } -class Url_helper_test extends CI_TestCase -{ public function test_url_title() { $words = array( diff --git a/tests/codeigniter/helpers/xml_helper_test.php b/tests/codeigniter/helpers/xml_helper_test.php index 49f49e166..a83fef91e 100644 --- a/tests/codeigniter/helpers/xml_helper_test.php +++ b/tests/codeigniter/helpers/xml_helper_test.php @@ -1,9 +1,11 @@ <?php -require_once(BASEPATH.'helpers/xml_helper.php'); +class Xml_helper_test extends CI_TestCase { -class Xml_helper_test extends CI_TestCase -{ + public function set_up() + { + $this->helper('xml'); + } public function test_xml_convert() { diff --git a/tests/codeigniter/libraries/Parser_test.php b/tests/codeigniter/libraries/Parser_test.php index b4580a4b1..c3d88fa85 100644 --- a/tests/codeigniter/libraries/Parser_test.php +++ b/tests/codeigniter/libraries/Parser_test.php @@ -1,14 +1,11 @@ <?php -require BASEPATH.'libraries/Parser.php'; - -class Parser_test extends CI_TestCase -{ +class Parser_test extends CI_TestCase { public function set_up() { $obj = new StdClass; - $obj->parser = new CI_Parser(); + $obj->parser = new Mock_Libraries_Parser(); $this->ci_instance($obj); diff --git a/tests/codeigniter/libraries/Table_test.php b/tests/codeigniter/libraries/Table_test.php index 0208a465a..13f338c6b 100644 --- a/tests/codeigniter/libraries/Table_test.php +++ b/tests/codeigniter/libraries/Table_test.php @@ -1,14 +1,11 @@ <?php -require BASEPATH.'libraries/Table.php'; - -class Table_test extends CI_TestCase -{ +class Table_test extends CI_TestCase { public function set_up() { $obj = new StdClass; - $obj->table = new CI_table(); + $obj->table = new Mock_Libraries_Table(); $this->ci_instance($obj); @@ -103,53 +100,23 @@ class Table_test extends CI_TestCase array('data' => 'size') ); - // test what would be discreet args, - // basically means a single array as the calling method - // will use func_get_args() - - $reflectionOfTable = new ReflectionClass($this->table); - $method = $reflectionOfTable->getMethod('_prep_args'); - - $method->setAccessible(true); - $this->assertEquals( $expected, - $method->invokeArgs( - $this->table, array(array('name', 'color', 'size'), 'discreet') - ) + $this->table->prep_args(array('name', 'color', 'size')) ); - - // test what would be a single array argument. Again, nested - // due to func_get_args on calling methods - $this->assertEquals( - $expected, - $method->invokeArgs( - $this->table, array(array('name', 'color', 'size'), 'array') - ) - ); - - + // with cell attributes - // need to add that new argument row to our expected outcome $expected[] = array('data' => 'weight', 'class' => 'awesome'); $this->assertEquals( $expected, - $method->invokeArgs( - $this->table, array(array('name', 'color', 'size', array('data' => 'weight', 'class' => 'awesome')), 'attributes') - ) + $this->table->prep_args(array('name', 'color', 'size', array('data' => 'weight', 'class' => 'awesome'))) ); } public function test_default_template_keys() { - $reflectionOfTable = new ReflectionClass($this->table); - $method = $reflectionOfTable->getMethod('_default_template'); - - $method->setAccessible(true); - - $deft_template = $method->invoke($this->table); $keys = array( 'table_open', 'thead_open', 'thead_close', @@ -162,29 +129,24 @@ class Table_test extends CI_TestCase foreach ($keys as $key) { - $this->assertArrayHasKey($key, $deft_template); + $this->assertArrayHasKey($key, $this->table->default_template()); } } public function test_compile_template() { - $reflectionOfTable = new ReflectionClass($this->table); - $method = $reflectionOfTable->getMethod('_compile_template'); - - $method->setAccessible(true); - $this->assertFalse($this->table->set_template('invalid_junk')); // non default key $this->table->set_template(array('nonsense' => 'foo')); - $method->invoke($this->table); + $this->table->compile_template(); $this->assertArrayHasKey('nonsense', $this->table->template); $this->assertEquals('foo', $this->table->template['nonsense']); // override default $this->table->set_template(array('table_close' => '</table junk>')); - $method->invoke($this->table); + $this->table->compile_template(); $this->assertArrayHasKey('table_close', $this->table->template); $this->assertEquals('</table junk>', $this->table->template['table_close']); @@ -250,13 +212,8 @@ class Table_test extends CI_TestCase public function test_set_from_array() { - $reflectionOfTable = new ReflectionClass($this->table); - $method = $reflectionOfTable->getMethod('_set_from_array'); - - $method->setAccessible(true); - - $this->assertFalse($method->invokeArgs($this->table, array('bogus'))); - $this->assertFalse($method->invoke($this->table, array())); + $this->assertFalse($this->table->set_from_array('bogus')); + $this->assertFalse($this->table->set_from_array(NULL)); $data = array( array('name', 'color', 'number'), @@ -264,7 +221,7 @@ class Table_test extends CI_TestCase array('Katie', 'Blue') ); - $method->invokeArgs($this->table, array($data, FALSE)); + $this->table->set_from_array($data, FALSE); $this->assertEmpty($this->table->heading); $this->table->clear(); @@ -280,7 +237,7 @@ class Table_test extends CI_TestCase array('data' => 'Blue'), ); - $method->invokeArgs($this->table, array($data)); + $this->table->set_from_array($data); $this->assertEquals(count($this->table->rows), 2); $this->assertEquals( @@ -296,11 +253,6 @@ class Table_test extends CI_TestCase function test_set_from_object() { - $reflectionOfTable = new ReflectionClass($this->table); - $method = $reflectionOfTable->getMethod('_set_from_object'); - - $method->setAccessible(true); - // Make a stub of query instance $query = new CI_TestCase(); $query->list_fields = function(){ @@ -326,7 +278,7 @@ class Table_test extends CI_TestCase 'email' => array('data' => 'foo@bar.com'), ); - $method->invokeArgs($this->table, array($query)); + $this->table->set_from_object($query); $this->assertEquals( $expected_heading, diff --git a/tests/codeigniter/libraries/Typography_test.php b/tests/codeigniter/libraries/Typography_test.php index a0533bae0..250aefb24 100644 --- a/tests/codeigniter/libraries/Typography_test.php +++ b/tests/codeigniter/libraries/Typography_test.php @@ -1,14 +1,11 @@ <?php -require BASEPATH.'libraries/Typography.php'; - -class Typography_test extends CI_TestCase -{ +class Typography_test extends CI_TestCase { public function set_up() { $obj = new StdClass; - $obj->type = new CI_Typography(); + $obj->type = new Mock_Libraries_Typography(); $this->ci_instance($obj); diff --git a/tests/codeigniter/libraries/User_agent_test.php b/tests/codeigniter/libraries/Useragent_test.php index 6f9e87196..7dad7ac54 100644 --- a/tests/codeigniter/libraries/User_agent_test.php +++ b/tests/codeigniter/libraries/Useragent_test.php @@ -1,11 +1,7 @@ <?php -require BASEPATH.'libraries/User_agent.php'; - -// This class needs some work... - -class UserAgent_test extends CI_TestCase -{ +class UserAgent_test extends CI_TestCase { + protected $_user_agent = 'Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_6_7; en-us) AppleWebKit/533.20.25 (KHTML, like Gecko) Version/5.0.4 Safari/533.20.27'; protected $_mobile_ua = 'Mozilla/5.0 (iPhone; U; CPU iPhone OS 4_1 like Mac OS X; en-us) AppleWebKit/532.9 (KHTML, like Gecko) Version/4.0.5 Mobile/8B117 Safari/6531.22.7'; @@ -15,7 +11,7 @@ class UserAgent_test extends CI_TestCase $_SERVER['HTTP_USER_AGENT'] = $this->_user_agent; $obj = new StdClass; - $obj->agent = new CI_User_agent(); + $obj->agent = new Mock_Libraries_UserAgent(); $this->ci_instance($obj); diff --git a/tests/mocks/autoloader.php b/tests/mocks/autoloader.php new file mode 100644 index 000000000..dd5929206 --- /dev/null +++ b/tests/mocks/autoloader.php @@ -0,0 +1,79 @@ +<?php + +// This autoloader provide convinient way to working with mock object +// make the test looks natural. This autoloader support cascade file loading as well +// within mocks directory. +// +// Prototype : +// +// include_once('Mock_Core_Loader') // Will load ./mocks/core/loader.php +// $mock_table = new Mock_Libraries_Table(); // Will load ./mocks/libraries/table.php +// $mock_database_driver = new Mock_Database_Driver(); // Will load ./mocks/database/driver.php +// and so on... +function autoload($class) +{ + $dir = realpath(dirname(__FILE__)).DIRECTORY_SEPARATOR; + + $ci_core = array( + 'Benchmark', 'Config', 'Controller', + 'Exceptions', 'Hooks', 'Input', + 'Lang', 'Loader', 'Model', + 'Output', 'Router', 'Security', + 'URI', 'Utf8', + ); + + $ci_libraries = array( + 'Calendar', 'Cart', 'Driver', + 'Email', 'Encrypt', 'Form_validation', + 'Ftp', 'Image_lib', 'Javascript', + 'Log', 'Migration', 'Pagination', + 'Parser', 'Profiler', 'Session', + 'Table', 'Trackback', 'Typography', + 'Unit_test', 'Upload', 'User_agent', + 'Xmlrpc', 'Zip', + ); + + if (strpos($class, 'Mock_') === 0) + { + $class = str_replace(array('Mock_', '_'), array('', DIRECTORY_SEPARATOR), $class); + $class = strtolower($class); + } + elseif (strpos($class, 'CI_') === 0) + { + $fragments = explode('_', $class, 2); + $subclass = next($fragments); + + if (in_array($subclass, $ci_core)) + { + $dir = BASEPATH.'core'.DIRECTORY_SEPARATOR; + $class = $subclass; + } + elseif (in_array($subclass, $ci_libraries)) + { + $dir = BASEPATH.'libraries'.DIRECTORY_SEPARATOR; + $class = $subclass; + } + else + { + $class = strtolower($class); + } + } + + $file = $dir.$class.'.php'; + + if ( ! file_exists($file)) + { + $trace = debug_backtrace(); + + // If the autoload call came from `class_exists` or `file_exists`, + // we skipped and return FALSE + if ($trace[2]['function'] == 'class_exists' OR $trace[2]['function'] == 'file_exists') + { + return FALSE; + } + + throw new InvalidArgumentException("Unable to load $class."); + } + + include_once($file); +}
\ No newline at end of file diff --git a/tests/lib/ci_testcase.php b/tests/mocks/ci_testcase.php index afccee017..f327e6b07 100644 --- a/tests/lib/ci_testcase.php +++ b/tests/mocks/ci_testcase.php @@ -1,9 +1,5 @@ <?php - -// Need a way to change dependencies (core libs and laoded libs) -// Need a way to set the CI class - class CI_TestCase extends PHPUnit_Framework_TestCase { protected $ci_config; @@ -20,7 +16,6 @@ class CI_TestCase extends PHPUnit_Framework_TestCase { 'security' => 'sec', 'input' => 'in', 'lang' => 'lang', - // @todo the loader is an edge case 'loader' => 'load', 'model' => 'model' ); @@ -53,6 +48,13 @@ class CI_TestCase extends PHPUnit_Framework_TestCase { $this->tear_down(); } } + + // -------------------------------------------------------------------- + + public static function instance() + { + return self::$ci_test_instance; + } // -------------------------------------------------------------------- @@ -67,6 +69,13 @@ class CI_TestCase extends PHPUnit_Framework_TestCase { $this->ci_config[$key] = $val; } } + + // -------------------------------------------------------------------- + + function ci_get_config() + { + return $this->ci_config; + } // -------------------------------------------------------------------- @@ -158,19 +167,12 @@ class CI_TestCase extends PHPUnit_Framework_TestCase { self::$ci_test_instance = $this; parent::runBare(); } - - // -------------------------------------------------------------------- - - public static function instance() - { - return self::$ci_test_instance; - } - + // -------------------------------------------------------------------- - function ci_get_config() + function helper($name) { - return $this->ci_config; + require_once(BASEPATH.'helpers/'.$name.'_helper.php'); } // -------------------------------------------------------------------- diff --git a/tests/lib/common.php b/tests/mocks/core/common.php index 4a832587d..fc94d7fff 100644 --- a/tests/lib/common.php +++ b/tests/mocks/core/common.php @@ -129,4 +129,4 @@ function set_status_header($code = 200, $text = '') return TRUE; } -// EOF +// EOF
\ No newline at end of file diff --git a/tests/mocks/core/loader.php b/tests/mocks/core/loader.php new file mode 100644 index 000000000..d4b29bb3d --- /dev/null +++ b/tests/mocks/core/loader.php @@ -0,0 +1,30 @@ +<?php + +class Mock_Core_Loader extends CI_Loader { + + /** + * Since we use paths to load up models, views, etc, we need the ability to + * mock up the file system so when core tests are run, we aren't mucking + * in the application directory. this will give finer grained control over + * these tests. So yeah, while this looks odd, I need to overwrite protected + * class vars in the loader. So here we go... + * + * @covers CI_Loader::__construct() + */ + public function __construct() + { + vfsStreamWrapper::register(); + vfsStreamWrapper::setRoot(new vfsStreamDirectory('application')); + + $this->models_dir = vfsStream::newDirectory('models')->at(vfsStreamWrapper::getRoot()); + $this->libs_dir = vfsStream::newDirectory('libraries')->at(vfsStreamWrapper::getRoot()); + $this->helpers_dir = vfsStream::newDirectory('helpers')->at(vfsStreamWrapper::getRoot()); + $this->views_dir = vfsStream::newDirectory('views')->at(vfsStreamWrapper::getRoot()); + + $this->_ci_ob_level = ob_get_level(); + $this->_ci_library_paths = array(vfsStream::url('application').'/', BASEPATH); + $this->_ci_helper_paths = array(vfsStream::url('application').'/', BASEPATH); + $this->_ci_model_paths = array(vfsStream::url('application').'/'); + $this->_ci_view_paths = array(vfsStream::url('application').'/views/' => TRUE); + } +}
\ No newline at end of file diff --git a/tests/mocks/core/uri.php b/tests/mocks/core/uri.php new file mode 100644 index 000000000..b6946091e --- /dev/null +++ b/tests/mocks/core/uri.php @@ -0,0 +1,25 @@ +<?php + +class Mock_Core_URI extends CI_URI { + + public function __construct() + { + $test = CI_TestCase::instance(); + $cls =& $test->ci_core_class('cfg'); + + // set predictable config values + $test->ci_set_config(array( + 'index_page' => 'index.php', + 'base_url' => 'http://example.com/', + 'subclass_prefix' => 'MY_' + )); + + $this->config = new $cls; + + } + + protected function _is_cli_request() + { + return FALSE; + } +}
\ No newline at end of file diff --git a/tests/mocks/database/ci_test.sqlite b/tests/mocks/database/ci_test.sqlite Binary files differnew file mode 100755 index 000000000..37ce4f870 --- /dev/null +++ b/tests/mocks/database/ci_test.sqlite diff --git a/tests/mocks/database/config/mysql.php b/tests/mocks/database/config/mysql.php new file mode 100644 index 000000000..ace0a31b1 --- /dev/null +++ b/tests/mocks/database/config/mysql.php @@ -0,0 +1,34 @@ +<?php + +return array( + + // Typical Database configuration + 'mysql' => array( + 'dsn' => '', + 'hostname' => 'localhost', + 'username' => 'travis', + 'password' => '', + 'database' => 'ci_test', + 'dbdriver' => 'mysql', + ), + + // Database configuration with failover + 'mysql_failover' => array( + 'dsn' => '', + 'hostname' => 'localhost', + 'username' => 'not_travis', + 'password' => 'wrong password', + 'database' => 'not_ci_test', + 'dbdriver' => 'mysql', + 'failover' => array( + array( + 'dsn' => '', + 'hostname' => 'localhost', + 'username' => 'travis', + 'password' => '', + 'database' => 'ci_test', + 'dbdriver' => 'mysql', + ), + ), + ), +);
\ No newline at end of file diff --git a/tests/mocks/database/config/pgsql.php b/tests/mocks/database/config/pgsql.php new file mode 100644 index 000000000..c06af8ce0 --- /dev/null +++ b/tests/mocks/database/config/pgsql.php @@ -0,0 +1,34 @@ +<?php + +return array( + + // Typical Database configuration + 'pgsql' => array( + 'dsn' => '', + 'hostname' => 'localhost', + 'username' => 'postgres', + 'password' => '', + 'database' => 'ci_test', + 'dbdriver' => 'postgre', + ), + + // Database configuration with failover + 'pgsql_failover' => array( + 'dsn' => '', + 'hostname' => 'localhost', + 'username' => 'not_travis', + 'password' => 'wrong password', + 'database' => 'not_ci_test', + 'dbdriver' => 'postgre', + 'failover' => array( + array( + 'dsn' => '', + 'hostname' => 'localhost', + 'username' => 'postgres', + 'password' => '', + 'database' => 'ci_test', + 'dbdriver' => 'postgre', + ), + ), + ), +);
\ No newline at end of file diff --git a/tests/mocks/database/config/sqlite.php b/tests/mocks/database/config/sqlite.php new file mode 100644 index 000000000..8665e208d --- /dev/null +++ b/tests/mocks/database/config/sqlite.php @@ -0,0 +1,35 @@ +<?php +$dbdriver = is_php('5.4') ? 'sqlite3' : 'sqlite'; + +return array( + + // Typical Database configuration + 'sqlite' => array( + 'dsn' => '', + 'hostname' => 'localhost', + 'username' => 'sqlite', + 'password' => 'sqlite', + 'database' => realpath(__DIR__.'/..').'/ci_test.sqlite', + 'dbdriver' => $dbdriver, + ), + + // Database configuration with failover + 'sqlite_failover' => array( + 'dsn' => '', + 'hostname' => 'localhost', + 'username' => 'sqlite', + 'password' => 'sqlite', + 'database' => '../not_exists.sqlite', + 'dbdriver' => $dbdriver, + 'failover' => array( + array( + 'dsn' => '', + 'hostname' => 'localhost', + 'username' => 'sqlite', + 'password' => 'sqlite', + 'database' => realpath(__DIR__.'/..').'/ci_testf.sqlite', + 'dbdriver' => $dbdriver, + ), + ), + ), +);
\ No newline at end of file diff --git a/tests/mocks/database/db.php b/tests/mocks/database/db.php new file mode 100644 index 000000000..43a0d391f --- /dev/null +++ b/tests/mocks/database/db.php @@ -0,0 +1,101 @@ +<?php + +class Mock_Database_DB { + + /** + * @var array DB configuration + */ + private $config = array(); + + /** + * Prepare database configuration skeleton + * + * @param array DB configuration to set + * @return void + */ + public function __construct($config = array()) + { + $this->config = $config; + } + + /** + * Build DSN connection string for DB driver instantiate process + * + * @param string Group name + * @return string DSN Connection string + */ + public function set_dsn($group = 'default') + { + if ( ! isset($this->config[$group])) + { + throw new InvalidArgumentException('Group '.$group.' not exists'); + } + + $params = array( + 'dbprefix' => '', + 'pconnect' => FALSE, + 'db_debug' => FALSE, + 'cache_on' => FALSE, + 'cachedir' => '', + 'char_set' => 'utf8', + 'dbcollat' => 'utf8_general_ci', + 'swap_pre' => '', + 'autoinit' => TRUE, + 'stricton' => FALSE, + ); + + $config = array_merge($this->config[$group], $params); + + if ( ! empty($config['dsn'])) + { + $dsn = $config['dsn']; + } + else + { + $dsn = $config['dbdriver'].'://'.$config['username'].':'.$config['password'] + .'@'.$config['hostname'].'/'.$config['database']; + + } + + $other_params = array_slice($config, 6); + + return $dsn.'?'.http_build_query($other_params); + } + + /** + * Return a database config array + * + * @see ./config + * @param string Driver based configuration + * @return array + */ + public static function config($driver) + { + $dir = realpath(dirname(__FILE__)).DIRECTORY_SEPARATOR; + + return include($dir.'config'.DIRECTORY_SEPARATOR.$driver.'.php'); + } + + /** + * Main DB method wrapper + * + * @param string Group or DSN string + * @param bool + * @return object + */ + public static function DB($group, $query_builder = FALSE) + { + include_once(BASEPATH.'database/DB.php'); + + try + { + $db = DB($group, $query_builder); + } + catch (Exception $e) + { + throw new InvalidArgumentException($e->getMessage()); + } + + return $db; + } +}
\ No newline at end of file diff --git a/tests/mocks/database/schema/.gitkeep b/tests/mocks/database/schema/.gitkeep new file mode 100644 index 000000000..e69de29bb --- /dev/null +++ b/tests/mocks/database/schema/.gitkeep diff --git a/tests/mocks/libraries/parser.php b/tests/mocks/libraries/parser.php new file mode 100644 index 000000000..81dcfb37e --- /dev/null +++ b/tests/mocks/libraries/parser.php @@ -0,0 +1,3 @@ +<?php + +class Mock_Libraries_Parser extends CI_Parser {}
\ No newline at end of file diff --git a/tests/mocks/libraries/table.php b/tests/mocks/libraries/table.php new file mode 100644 index 000000000..1a6ff8d35 --- /dev/null +++ b/tests/mocks/libraries/table.php @@ -0,0 +1,15 @@ +<?php + +class Mock_Libraries_Table extends CI_Table { + + // Overide inaccesible private or protected method + public function __call($method, $params) + { + if (is_callable(array($this, '_'.$method))) + { + return call_user_func_array(array($this, '_'.$method), $params); + } + + throw new BadMethodCallException('Method '.$method.' was not found'); + } +}
\ No newline at end of file diff --git a/tests/mocks/libraries/typography.php b/tests/mocks/libraries/typography.php new file mode 100644 index 000000000..0f76c5745 --- /dev/null +++ b/tests/mocks/libraries/typography.php @@ -0,0 +1,3 @@ +<?php + +class Mock_Libraries_Typography extends CI_Typography {}
\ No newline at end of file diff --git a/tests/mocks/libraries/useragent.php b/tests/mocks/libraries/useragent.php new file mode 100644 index 000000000..c957cde5b --- /dev/null +++ b/tests/mocks/libraries/useragent.php @@ -0,0 +1,3 @@ +<?php + +class Mock_Libraries_UserAgent extends CI_User_agent {}
\ No newline at end of file diff --git a/tests/phpunit.xml b/tests/travis/mysql.phpunit.xml index abb9881b9..44d6d6ed9 100644 --- a/tests/phpunit.xml +++ b/tests/travis/mysql.phpunit.xml @@ -1,7 +1,7 @@ <?xml version="1.0" encoding="UTF-8"?> <phpunit - bootstrap="Bootstrap.php" + bootstrap="../Bootstrap.php" colors="true" convertNoticesToExceptions="true" convertWarningsToExceptions="true" @@ -9,17 +9,16 @@ stopOnFailure="false" stopOnIncomplete="false" stopOnSkipped="false"> + <php> + <const name="DB_DRIVER" value="mysql"/> + </php> <testsuites> <testsuite name="CodeIgniter Core Test Suite"> - <file>codeigniter/Setup_test.php</file> - <directory suffix="test.php">codeigniter/core</directory> - <directory suffix="test.php">codeigniter/helpers</directory> - <directory suffix="test.php">codeigniter/libraries</directory> - <!-- We'll worry about these later ... - <directory suffix="test.php">codeigniter/libraries</directory> - <directory suffix="test.php">codeigniter/helpers</directory> - --> - + <file>../codeigniter/Setup_test.php</file> + <directory suffix="test.php">../codeigniter/core</directory> + <directory suffix="test.php">../codeigniter/helpers</directory> + <directory suffix="test.php">../codeigniter/libraries</directory> + <directory suffix="test.php">../codeigniter/database</directory> </testsuite> </testsuites> <filters> @@ -27,7 +26,7 @@ <directory suffix=".php">PEAR_INSTALL_DIR</directory> <directory suffix=".php">PHP_LIBDIR</directory> <directory suffix=".php">PROJECT_BASE.'tests'</directory> - <directory suffix=".php">'../system/core/CodeIgniter.php'</directory> + <directory suffix=".php">'../../system/core/CodeIgniter.php'</directory> </blacklist> <whitelist> <!-- diff --git a/tests/travis/pgsql.phpunit.xml b/tests/travis/pgsql.phpunit.xml new file mode 100644 index 000000000..9f52b40ae --- /dev/null +++ b/tests/travis/pgsql.phpunit.xml @@ -0,0 +1,37 @@ +<?xml version="1.0" encoding="UTF-8"?> + +<phpunit + bootstrap="../Bootstrap.php" + colors="true" + convertNoticesToExceptions="true" + convertWarningsToExceptions="true" + stopOnError="false" + stopOnFailure="false" + stopOnIncomplete="false" + stopOnSkipped="false"> + <php> + <const name="DB_DRIVER" value="pgsql"/> + </php> + <testsuites> + <testsuite name="CodeIgniter Core Test Suite"> + <file>../codeigniter/Setup_test.php</file> + <directory suffix="test.php">../codeigniter/core</directory> + <directory suffix="test.php">../codeigniter/helpers</directory> + <directory suffix="test.php">../codeigniter/libraries</directory> + <directory suffix="test.php">../codeigniter/database</directory> + </testsuite> + </testsuites> + <filters> + <blacklist> + <directory suffix=".php">PEAR_INSTALL_DIR</directory> + <directory suffix=".php">PHP_LIBDIR</directory> + <directory suffix=".php">PROJECT_BASE.'tests'</directory> + <directory suffix=".php">'../../system/core/CodeIgniter.php'</directory> + </blacklist> + <whitelist> + <!-- + <directory suffix=".php">'../system/core'</directory> + --> + </whitelist> + </filters> +</phpunit>
\ No newline at end of file diff --git a/tests/travis/sqlite.phpunit.xml b/tests/travis/sqlite.phpunit.xml new file mode 100644 index 000000000..74ebb482b --- /dev/null +++ b/tests/travis/sqlite.phpunit.xml @@ -0,0 +1,37 @@ +<?xml version="1.0" encoding="UTF-8"?> + +<phpunit + bootstrap="../Bootstrap.php" + colors="true" + convertNoticesToExceptions="true" + convertWarningsToExceptions="true" + stopOnError="false" + stopOnFailure="false" + stopOnIncomplete="false" + stopOnSkipped="false"> + <php> + <const name="DB_DRIVER" value="sqlite"/> + </php> + <testsuites> + <testsuite name="CodeIgniter Core Test Suite"> + <file>../codeigniter/Setup_test.php</file> + <directory suffix="test.php">../codeigniter/core</directory> + <directory suffix="test.php">../codeigniter/helpers</directory> + <directory suffix="test.php">../codeigniter/libraries</directory> + <directory suffix="test.php">../codeigniter/database</directory> + </testsuite> + </testsuites> + <filters> + <blacklist> + <directory suffix=".php">PEAR_INSTALL_DIR</directory> + <directory suffix=".php">PHP_LIBDIR</directory> + <directory suffix=".php">PROJECT_BASE.'tests'</directory> + <directory suffix=".php">'../../system/core/CodeIgniter.php'</directory> + </blacklist> + <whitelist> + <!-- + <directory suffix=".php">'../system/core'</directory> + --> + </whitelist> + </filters> +</phpunit>
\ No newline at end of file diff --git a/user_guide_src/source/changelog.rst b/user_guide_src/source/changelog.rst index 42d468eed..3ad930ed1 100644 --- a/user_guide_src/source/changelog.rst +++ b/user_guide_src/source/changelog.rst @@ -35,6 +35,8 @@ Release Date: Not Released - Removed previously deprecated SHA1 Library. - Removed previously deprecated use of ``$autoload['core']`` in application/config/autoload.php. Only entries in ``$autoload['libraries']`` are auto-loaded now. + - Added some more doctypes. + - Updated all classes to be written in PHP 5 style, with visibility declarations and no ``var`` usage for properties. - Helpers @@ -48,6 +50,7 @@ Release Date: Not Released - form_dropdown() will now also take an array for unity with other form helpers. - set_realpath() can now also handle file paths as opposed to just directories. - do_hash() now uses PHP's native hash() function, supporting more algorithms. + - Added an optional paramater to ``delete_files()`` to enable it to skip deleting files such as .htaccess and index.html. - Database @@ -56,9 +59,11 @@ Release Date: Not Released get_compiled_insert(), get_compiled_update(), get_compiled_delete(). - Taking care of LIKE condition when used with MySQL UPDATE statement. - Adding $escape parameter to the order_by function, this enables ordering by custom fields. - - MySQLi driver now uses mysqli_get_server_info() for server version checking. - - MySQLi driver now supports persistent connections when running on PHP >= 5.3. - - Added dsn if the group connections in the config use PDO or any driver which need DSN. + - Improved support for the MySQLi driver, including: + - OOP style of the PHP extension is now used, instead of the procedural aliases. + - Server version checking is now done via ``mysqli::$server_info`` instead of running an SQL query. + - Added persistent connections support for PHP >= 5.3. + - Added 'dsn' configuration setting for drivers that support DSN strings (PDO, PostgreSQL, Oracle, ODBC, CUBRID). - Improved PDO database support. - Added Interbase/Firebird database support via the "interbase" driver - Added an optional database name parameter to db_select(). @@ -70,22 +75,35 @@ Release Date: Not Released - Added _optimize_table() support for the :doc:`Database Utility Class <database/utilities>` (rebuilds table indexes). - Added a constructor to the DB_result class and moved all driver-specific properties and logic out of the base DB_driver class to allow better abstraction. - Removed limit() and order_by() support for UPDATE and DELETE queries in PostgreSQL driver. Postgres does not support those features. - - Removed protect_identifiers() and renamed _protect_identifiers() to it instead - it was just an alias. + - Removed protect_identifiers() and renamed internal method _protect_identifiers() to it instead - it was just an alias. - MySQL and MySQLi drivers now require at least MySQL version 5.1. - db_set_charset() now only requires one parameter (collation was only needed due to legacy support for MySQL versions prior to 5.1). - Added DSN string support for CUBRID. - Added persistent connections support for CUBRID. + - Added random ordering support for MSSQL. + - Added random ordering support for SQLSRV. + - Added support for SQLite3 database driver. + - Improved support of the Oracle (OCI8) driver, including: + - Added DSN string support (Easy Connect and TNS). + - Added support for dropping tables to :doc:`Database Forge <database/forge>`. + - Added support for listing database schemas to :doc:`Database Utilities <database/utilities>`. + - Generally improved for speed and cleaned up all of its components. + - *Row* result methods now really only fetch only the needed number of rows, instead of depending entirely on result(). + - num_rows() is now only called explicitly by the developer and no longer re-executes statements. + - Added replace() support for SQLite. + - Renamed internal method _escape_identifiers() to escape_identifiers(). - Libraries - Added max_filename_increment config setting for Upload library. - CI_Loader::_ci_autoloader() is now a protected method. - - Added custom filename to Email::attach() as $this->email->attach($filename, $disposition, $newname) + - Added custom filename to Email::attach() as $this->email->attach($filename, $disposition, $newname). + - Added possibility to send attachment as buffer string in Email::attach() as $this->email->attach($buffer, $disposition, $newname, $mime). - Cart library changes include: - It now auto-increments quantity's instead of just resetting it, this is the default behaviour of large e-commerce sites. - Product Name strictness can be disabled via the Cart Library by switching "$product_name_safe" - Added function remove() to remove a cart item, updating with quantity of 0 seemed like a hack but has remained to retain compatability - - Image manipulation library changes include: + - :doc:`Image Manipulation library <libraries/image_lib>` changes include: - The initialize() method now only sets existing class properties. - Added support for 3-length hex color values for wm_font_color and wm_shadow_color properties, as well as validation for them. - Class properties wm_font_color, wm_shadow_color and wm_use_drop_shadow are now protected, to avoid breaking the text_watermark() method @@ -94,14 +112,18 @@ Release Date: Not Released - Minor speed optimizations and method & property visibility declarations in the Calendar Library. - Removed SHA1 function in the :doc:`Encryption Library <libraries/encryption>`. - Added $config['csrf_regeneration'] to the CSRF protection in the :doc:`Security library <libraries/security>`, which makes token regeneration optional. + - :doc:`Form Validation library <libraries/form_validation>` changes include: + - Added method error_array() to return all error messages as an array. + - Added method set_data() to set an alternative data array to be validated instead of the default $_POST. + - Added method reset_validation(), which resets internal validation variables in case of multiple validation routines. + - Added support for setting error delimiters in the config file via $config['error_prefix'] and $config['error_suffix']. + - _execute() now considers input data to be invalid if a specified rule is not found. + - Removed method is_numeric() as it exists as a native PHP function and _execute() will find and use that (the 'is_numeric' rule itself is deprecated since 1.6.1). + - Native PHP functions used as rules can now accept an additional parameter, other than the data itself. + - Changed the :doc:`Session Library <libraries/sessions>` to select only one row when using database sessions. - Added all_flashdata() method to session class. Returns an associative array of only flashdata. - Allowed for setting table class defaults in a config file. - - Form Validation library now allows setting of error delimiters in the config file via $config['error_prefix'] and $config['error_suffix']. - - Added function error_array() to return all error messages as an array in the Form_validation class. - - Added function set_data() to Form_validation library, which can be used in place of the default $_POST array. - - Added function reset_validation() to form validation library, which resets internal validation variables in case of multiple validation routines. - - Changed the Session library to select only one row when using database sessions. - - Added a Wincache driver to the `Caching Library <libraries/caching>`. + - Added a Wincache driver to the :doc:`Caching Library <libraries/caching>`. - Added dsn (delivery status notification) option to the :doc:`Email Library <libraries/email>`. - Core @@ -114,6 +136,8 @@ Release Date: Not Released - Added method() to CI_Input to retrieve $_SERVER['REQUEST_METHOD']. - Modified valid_ip() to use PHP's filter_var() in the :doc:`Input Library <libraries/input>`. - Added support for HTTP-Only cookies with new config option ``cookie_httponly`` (default FALSE). + - Renamed method _call_hook() to call_hook() in the :doc:`Hooks Library <general/hooks>`. + - Added get_content_type() method to the :doc:`Output Library <libraries/output>`. Bug fixes for 3.0 ------------------ @@ -166,11 +190,20 @@ Bug fixes for 3.0 - Fixed a bug (#501) - set_rules() to check if the request method is not 'POST' before aborting, instead of depending on count($_POST) in the :doc:`Form Validation Library <libraries/form_validation>`. - Fixed a bug (#940) - csrf_verify() used to set the CSRF cookie while processing a POST request with no actual POST data, which resulted in validating a request that should be considered invalid. - Fixed a bug in PostgreSQL's escape_str() where it didn't properly escape LIKE wild characters. +- Fixed a bug in the library loader where some PHP versions wouldn't execute the class constructor. +- Fixed a bug (#88) - An unexisting property was used for configuration of the Memcache cache driver. +- Fixed a bug (#14) - create_database() method in the :doc:`Database Forge Library <database/forge>` didn't utilize the configured database character set. +- Fixed a bug (#1238) - delete_all() in the `Database Caching Library <database/caching>` used to delete .htaccess and index.html files, which is a potential security risk. +- Fixed a bug in :doc:`Trackback Library <libraries/trackback>` method validate_url() where it didn't actually do anything, due to input not being passed by reference. +- Fixed a bug (#11, #183, #863) - CI_Form_validation::_execute() silently continued to the next rule, if a rule method/function is not found. +- Fixed a bug (#1242) - read_dir() in the :doc:`Zip Library <libraries/zip>` wasn't compatible with Windows. +- Fixed a bug (#306) - ODBC driver didn't have an _insert_batch() method, which resulted in fatal error being triggered when insert_batch() is used with it. +- Fixed a bug in MSSQL and SQLSrv's _truncate() where the TABLE keyword was missing. Version 2.1.1 ============= -Release Date: Not Released +Release Date: November 14, 2011 - General Changes - Fixed support for docx, xlsx files in mimes.php. @@ -251,11 +284,9 @@ Release Date: November 14, 2011 override them. - Removed CI_CORE boolean constant from CodeIgniter.php (no longer Reactor and Core versions). - Bug fixes for 2.1.0 ------------------- - - Fixed #378 Robots identified as regular browsers by the User Agent class. - If a config class was loaded first then a library with the same name @@ -1254,7 +1285,7 @@ Bug fixes for 1.6.3 - Added a language key for valid_emails in validation_lang.php. - Amended fixes for bug (#3419) with parsing DSN database connections. -- Moved the _has_operators() function (#4535) into DB_driver from +- Moved the _has_operator() function (#4535) into DB_driver from DB_active_rec. - Fixed a syntax error in upload_lang.php. - Fixed a bug (#4542) with a regular expression in the Image library. diff --git a/user_guide_src/source/conf.py b/user_guide_src/source/conf.py index 593ceaf1c..e972a388b 100644 --- a/user_guide_src/source/conf.py +++ b/user_guide_src/source/conf.py @@ -121,7 +121,7 @@ html_theme_path = ["./_themes"] # Add any paths that contain custom static files (such as style sheets) here, # relative to this directory. They are copied after the builtin static files, # so a file named "default.css" will overwrite the builtin "default.css". -html_static_path = ['_static'] +#html_static_path = ['_static'] # If not '', a 'Last updated on:' timestamp is inserted at every page bottom, # using the given strftime format. diff --git a/user_guide_src/source/database/configuration.rst b/user_guide_src/source/database/configuration.rst index 040e7e33f..3f3bae336 100644 --- a/user_guide_src/source/database/configuration.rst +++ b/user_guide_src/source/database/configuration.rst @@ -132,7 +132,7 @@ Explanation of Values: **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, postgres, odbc, etc. Must be specified in lower case. +**dbdriver** The database type. ie: mysql, postgre, odbc, etc. Must be specified in lower case. **dbprefix** An optional table prefix which will added to the table name when running :doc: `Active Record <active_record>` queries. This permits multiple CodeIgniter installations to share one database. @@ -166,8 +166,8 @@ Explanation of Values: $db['default']['port'] = 5432; ====================== ================================================================================================== -.. note:: Depending on what database platform you are using (MySQL, - Postgres, etc.) not all values will be needed. For example, when using - SQLite you will not need to supply a username or password, and the - database name will be the path to your database file. The information - above assumes you are using MySQL. +.. note:: Depending on what database platform you are using (MySQL, PostgreSQL, + etc.) not all values will be needed. For example, when using SQLite you + will not need to supply a username or password, and the database name + will be the path to your database file. The information above assumes + you are using MySQL. diff --git a/user_guide_src/source/database/utilities.rst b/user_guide_src/source/database/utilities.rst index 3805ffb87..4e83929b2 100644 --- a/user_guide_src/source/database/utilities.rst +++ b/user_guide_src/source/database/utilities.rst @@ -117,7 +117,7 @@ query. Example:: echo $this->dbutil->csv_from_result($query); The second, third, and fourth parameters allow you to set the delimiter -newline, and enclosure characters respectively. By default tabs are +newline, and enclosure characters respectively. By default commas are used as the delimiter, "\n" is used as a new line, and a double-quote is used as the enclosure. Example:: diff --git a/user_guide_src/source/general/requirements.rst b/user_guide_src/source/general/requirements.rst index 05e87961a..d97b7b4b2 100644 --- a/user_guide_src/source/general/requirements.rst +++ b/user_guide_src/source/general/requirements.rst @@ -5,4 +5,4 @@ Server Requirements - `PHP <http://www.php.net/>`_ version 5.2.4 or newer. - A Database is required for most web application programming. Current supported databases are MySQL (5.1+), MySQLi, MS SQL, SQLSRV, Oracle, - PostgreSQL, SQLite, CUBRID, Interbase, ODBC and PDO. + PostgreSQL, SQLite, SQLite3, CUBRID, Interbase, ODBC and PDO. diff --git a/user_guide_src/source/general/styleguide.rst b/user_guide_src/source/general/styleguide.rst index d8bdd0531..2b91d1cc0 100644 --- a/user_guide_src/source/general/styleguide.rst +++ b/user_guide_src/source/general/styleguide.rst @@ -94,7 +94,7 @@ overly long and verbose names. class Super_class { - function __construct() + public function __construct() { } @@ -168,7 +168,6 @@ picked up by IDEs:: /** * Encodes string for use in XML * - * @access public * @param string * @return string */ diff --git a/user_guide_src/source/general/views.rst b/user_guide_src/source/general/views.rst index dc65f6c4f..9b7c9daaa 100644 --- a/user_guide_src/source/general/views.rst +++ b/user_guide_src/source/general/views.rst @@ -49,7 +49,7 @@ replace the echo statement with the view loading function:: <?php class Blog extends CI_Controller { - function index() + public function index() { $this->load->view('blogview'); } @@ -74,14 +74,14 @@ might look something like this:: class Page extends CI_Controller { - function index() - { - $data['page_title'] = 'Your title'; - $this->load->view('header'); - $this->load->view('menu'); - $this->load->view('content', $data); - $this->load->view('footer'); - } + public function index() + { + $data['page_title'] = 'Your title'; + $this->load->view('header'); + $this->load->view('menu'); + $this->load->view('content', $data); + $this->load->view('footer'); + } } ?> @@ -126,7 +126,7 @@ Let's try it with your controller file. Open it add this code:: <?php class Blog extends CI_Controller { - function index() + public function index() { $data['title'] = "My Real Title"; $data['heading'] = "My Real Heading"; @@ -164,7 +164,7 @@ Here's a simple example. Add this to your controller:: <?php class Blog extends CI_Controller { - function index() + public function index() { $data['todo_list'] = array('Clean House', 'Call Mom', 'Run Errands'); diff --git a/user_guide_src/source/helpers/html_helper.rst b/user_guide_src/source/helpers/html_helper.rst index 2e217898e..17c28cd2a 100644 --- a/user_guide_src/source/helpers/html_helper.rst +++ b/user_guide_src/source/helpers/html_helper.rst @@ -325,24 +325,44 @@ Strict is used by default, but many doctypes are available. The following is a list of doctype choices. These are configurable, and pulled from application/config/doctypes.php -+------------------------+--------------------------+---------------------------------------------------------------------------------------------------------------------------+ -| Doctype | Option | Result | -+========================+==========================+===========================================================================================================================+ -| XHTML 1.1 | doctype('xhtml11') | <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"> | -+------------------------+--------------------------+---------------------------------------------------------------------------------------------------------------------------+ -| XHTML 1.0 Strict | doctype('xhtml1-strict') | <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> | -+------------------------+--------------------------+---------------------------------------------------------------------------------------------------------------------------+ -| XHTML 1.0 Transitional | doctype('xhtml1-trans') | <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> | -+------------------------+--------------------------+---------------------------------------------------------------------------------------------------------------------------+ -| XHTML 1.0 Frameset | doctype('xhtml1-frame') | <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Frameset//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-frameset.dtd"> | -+------------------------+--------------------------+---------------------------------------------------------------------------------------------------------------------------+ -| XHTML Basic 1.1 | doctype('xhtml-basic11') | <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML Basic 1.1//EN" "http://www.w3.org/TR/xhtml-basic/xhtml-basic11.dtd"> | -+------------------------+--------------------------+---------------------------------------------------------------------------------------------------------------------------+ -| HTML 5 | doctype('html5') | <!DOCTYPE html> | -+------------------------+--------------------------+---------------------------------------------------------------------------------------------------------------------------+ -| HTML 4 Strict | doctype('html4-strict') | <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> | -+------------------------+--------------------------+---------------------------------------------------------------------------------------------------------------------------+ -| HTML 4 Transitional | doctype('html4-trans') | <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> | -+------------------------+--------------------------+---------------------------------------------------------------------------------------------------------------------------+ -| HTML 4 Frameset | doctype('html4-frame') | <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Frameset//EN" "http://www.w3.org/TR/html4/frameset.dtd"> | -+------------------------+--------------------------+---------------------------------------------------------------------------------------------------------------------------+ ++-------------------------------+------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------+ +| Doctype | Option | Result | ++===============================+==============================+==================================================================================================================================================+ +| XHTML 1.1 | doctype('xhtml11') | <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"> | ++-------------------------------+------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------+ +| XHTML 1.0 Strict | doctype('xhtml1-strict') | <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> | ++-------------------------------+------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------+ +| XHTML 1.0 Transitional | doctype('xhtml1-trans') | <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> | ++-------------------------------+------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------+ +| XHTML 1.0 Frameset | doctype('xhtml1-frame') | <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Frameset//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-frameset.dtd"> | ++-------------------------------+------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------+ +| XHTML Basic 1.1 | doctype('xhtml-basic11') | <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML Basic 1.1//EN" "http://www.w3.org/TR/xhtml-basic/xhtml-basic11.dtd"> | ++-------------------------------+------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------+ +| HTML 5 | doctype('html5') | <!DOCTYPE html> | ++-------------------------------+------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------+ +| HTML 4 Strict | doctype('html4-strict') | <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> | ++-------------------------------+------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------+ +| HTML 4 Transitional | doctype('html4-trans') | <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> | ++-------------------------------+------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------+ +| HTML 4 Frameset | doctype('html4-frame') | <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Frameset//EN" "http://www.w3.org/TR/html4/frameset.dtd"> | ++-------------------------------+------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------+ +| MathML 1.01 | doctype('mathml1') | <!DOCTYPE math SYSTEM "http://www.w3.org/Math/DTD/mathml1/mathml.dtd"> | ++-------------------------------+------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------+ +| MathML 2.0 | doctype('mathml2') | <!DOCTYPE math PUBLIC "-//W3C//DTD MathML 2.0//EN" "http://www.w3.org/Math/DTD/mathml2/mathml2.dtd"> | ++-------------------------------+------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------+ +| SVG 1.0 | doctype('svg10') | <!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.0//EN" "http://www.w3.org/TR/2001/REC-SVG-20010904/DTD/svg10.dtd"> | ++-------------------------------+------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------+ +| SVG 1.1 Full | doctype('svg11') | <!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd"> | ++-------------------------------+------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------+ +| SVG 1.1 Basic | doctype('svg11-basic') | <!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1 Basic//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11-basic.dtd"> | ++-------------------------------+------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------+ +| SVG 1.1 Tiny | doctype('svg11-tiny') | <!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1 Tiny//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11-tiny.dtd"> | ++-------------------------------+------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------+ +| XHTML+MathML+SVG (XHTML host) | doctype('xhtml-math-svg-xh') | <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1 plus MathML 2.0 plus SVG 1.1//EN" "http://www.w3.org/2002/04/xhtml-math-svg/xhtml-math-svg.dtd"> | ++-------------------------------+------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------+ +| XHTML+MathML+SVG (SVG host) | doctype('xhtml-math-svg-sh') | <!DOCTYPE svg:svg PUBLIC "-//W3C//DTD XHTML 1.1 plus MathML 2.0 plus SVG 1.1//EN" "http://www.w3.org/2002/04/xhtml-math-svg/xhtml-math-svg.dtd"> | ++-------------------------------+------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------+ +| XHTML+RDFa 1.0 | doctype('xhtml-rdfa-1') | <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML+RDFa 1.0//EN" "http://www.w3.org/MarkUp/DTD/xhtml-rdfa-1.dtd"> | ++-------------------------------+------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------+ +| XHTML+RDFa 1.1 | doctype('xhtml-rdfa-2') | <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML+RDFa 1.1//EN" "http://www.w3.org/MarkUp/DTD/xhtml-rdfa-2.dtd"> | ++-------------------------------+------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------+
\ No newline at end of file diff --git a/user_guide_src/source/libraries/email.rst b/user_guide_src/source/libraries/email.rst index d7e40f5c4..daf000907 100644 --- a/user_guide_src/source/libraries/email.rst +++ b/user_guide_src/source/libraries/email.rst @@ -229,11 +229,20 @@ use the function multiple times. For example:: $this->email->attach('/path/to/photo2.jpg'); $this->email->attach('/path/to/photo3.jpg'); -If you'd like to change the disposition or add a custom file name, you can use the second and third paramaters. To use the default disposition (attachment), leave the second parameter blank. Here's an example:: - - $this->email->attach('/path/to/photo1.jpg', 'inline'); - $this->email->attach('/path/to/photo1.jpg', '', 'birthday.jpg'); - +To use the default disposition (attachment), leave the second parameter blank, +otherwise use a custom disposition:: + + $this->email->attach('image.jpg', 'inline'); + +If you'd like to use a custom file name, you can use the third paramater:: + + $this->email->attach('filename.pdf', 'attachment', 'report.pdf'); + +If you need to use a buffer string instead of a real - physical - file you can +use the first parameter as buffer, the third parameter as file name and the fourth +parameter as mime-type:: + + $this->email->attach($buffer, 'attachment', 'report.pdf', 'application/pdf'); $this->email->print_debugger() ------------------------------- diff --git a/user_guide_src/source/libraries/file_uploading.rst b/user_guide_src/source/libraries/file_uploading.rst index 90efca95d..d573fc770 100644 --- a/user_guide_src/source/libraries/file_uploading.rst +++ b/user_guide_src/source/libraries/file_uploading.rst @@ -90,24 +90,24 @@ this code and save it to your applications/controllers/ folder:: class Upload extends CI_Controller { - function __construct() + public function __construct() { parent::__construct(); $this->load->helper(array('form', 'url')); } - function index() + public function index() { $this->load->view('upload_form', array('error' => ' ' )); } - function do_upload() + public function do_upload() { - $config['upload_path'] = './uploads/'; - $config['allowed_types'] = 'gif|jpg|png'; - $config['max_size'] = '100'; - $config['max_width'] = '1024'; - $config['max_height'] = '768'; + $config['upload_path'] = './uploads/'; + $config['allowed_types'] = 'gif|jpg|png'; + $config['max_size'] = 100; + $config['max_width'] = 1024; + $config['max_height'] = 768; $this->load->library('upload', $config); diff --git a/user_guide_src/source/libraries/form_validation.rst b/user_guide_src/source/libraries/form_validation.rst index 5d7368ccb..028b61c4c 100644 --- a/user_guide_src/source/libraries/form_validation.rst +++ b/user_guide_src/source/libraries/form_validation.rst @@ -123,7 +123,7 @@ this code and save it to your applications/controllers/ folder:: class Form extends CI_Controller { - function index() + public function index() { $this->load->helper(array('form', 'url')); @@ -219,7 +219,7 @@ Your controller should now look like this:: class Form extends CI_Controller { - function index() + public function index() { $this->load->helper(array('form', 'url')); @@ -321,7 +321,7 @@ password to MD5, and running the username through the "xss_clean" function, which removes malicious data. **Any native PHP function that accepts one parameter can be used as a -rule, like htmlspecialchars, trim, MD5, etc.** +rule, like htmlspecialchars, trim, md5, etc.** .. note:: You will generally want to use the prepping functions **after** the validation rules so if there is an error, the original @@ -608,7 +608,7 @@ call the reset_validation() function before setting up rules and validating the For more info please see the :ref:`function-reference` section below. --.. _saving-groups: +.. _saving-groups: ************************************************ Saving Sets of Validation Rules to a Config File @@ -892,8 +892,9 @@ Rule Parameter Description $this->form_validation->required($string); -.. note:: You can also use any native PHP functions that permit one - parameter. +.. note:: You can also use any native PHP functions that permit up + to two parameters, where at least one is required (to pass + the field data). ****************** Prepping Reference @@ -976,7 +977,7 @@ $this->form_validation->set_data(); $_POST array. $this->form_validation->reset_validation(); -======================================== +=========================================== .. php:method:: reset_validation () diff --git a/user_guide_src/source/libraries/output.rst b/user_guide_src/source/libraries/output.rst index 2cf7c0854..baceaae7b 100644 --- a/user_guide_src/source/libraries/output.rst +++ b/user_guide_src/source/libraries/output.rst @@ -49,6 +49,15 @@ data, JPEG's, XML, etc easily. .. important:: Make sure any non-mime string you pass to this method exists in config/mimes.php or it will have no effect. +$this->output->get_content_type(); +========================================== + +Returns the Content-Type HTTP header that's currently in use. + + $mime = $this->output->get_content_type(); + +.. note:: If not set, the default return value is 'text/html'. + $this->output->get_output(); ============================= diff --git a/user_guide_src/source/libraries/xmlrpc.rst b/user_guide_src/source/libraries/xmlrpc.rst index 3b945769f..dfb88114e 100644 --- a/user_guide_src/source/libraries/xmlrpc.rst +++ b/user_guide_src/source/libraries/xmlrpc.rst @@ -184,10 +184,10 @@ server will expect a class to exist with this prototype:: class My_blog extends CI_Controller { - function new_post($request) - { + public function new_post($request) + { - } + } } The $request variable is an object compiled by the Server, which @@ -304,7 +304,7 @@ folder:: class Xmlrpc_client extends CI_Controller { - function index() + public function index() { $this->load->helper('url'); $server_url = site_url('xmlrpc_server'); @@ -345,7 +345,7 @@ folder:: class Xmlrpc_server extends CI_Controller { - function index() + public function index() { $this->load->library('xmlrpc'); $this->load->library('xmlrpcs'); @@ -357,15 +357,17 @@ folder:: } - function process($request) + public function process($request) { $parameters = $request->output_parameters(); $response = array( - array( - 'you_said' => $parameters['0'], - 'i_respond' => 'Not bad at all.'), - 'struct'); + array( + 'you_said' => $parameters[0], + 'i_respond' => 'Not bad at all.' + ), + 'struct' + ); return $this->xmlrpc->send_response($response); } @@ -419,9 +421,9 @@ the Server. :: $parameters = $request->output_parameters(); - $name = $parameters['0']['name']; - $size = $parameters['1']['size']; - $size = $parameters['1']['shape']; + $name = $parameters[0]['name']; + $size = $parameters[1]['size']; + $size = $parameters[1]['shape']; ************************** XML-RPC Function Reference |