From a756125436884dd622fdeff67084f3a62fc71b98 Mon Sep 17 00:00:00 2001 From: Derek Jones Date: Sun, 21 Jul 2013 14:21:41 -0700 Subject: Updating Calendar lib docs --- system/libraries/Calendar.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system/libraries') diff --git a/system/libraries/Calendar.php b/system/libraries/Calendar.php index 23d8ffb42..9c68c94c1 100644 --- a/system/libraries/Calendar.php +++ b/system/libraries/Calendar.php @@ -329,7 +329,7 @@ class CI_Calendar { * Get Day Names * * Returns an array of day names (Sunday, Monday, etc.) based - * on the type. Options: long, short, abrev + * on the type. Options: long, short, abr * * @param string * @return array -- cgit v1.2.3-24-g4f1b From 88f41dff43e8e787ab553d86715aca130abf9e51 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Mon, 23 Sep 2013 15:24:43 +0300 Subject: [ci skip] Update Zip library docblocks --- system/libraries/Zip.php | 38 +++++++++++++++++++------------------- 1 file changed, 19 insertions(+), 19 deletions(-) (limited to 'system/libraries') diff --git a/system/libraries/Zip.php b/system/libraries/Zip.php index 6608f050e..2ce457844 100644 --- a/system/libraries/Zip.php +++ b/system/libraries/Zip.php @@ -103,12 +103,12 @@ class CI_Zip { * * Lets you add a virtual directory into which you can place files. * - * @param mixed the directory name. Can be string or array + * @param mixed $directory the directory name. Can be string or array * @return void */ public function add_dir($directory) { - foreach ( (array) $directory as $dir) + foreach ((array) $directory as $dir) { if ( ! preg_match('|.+/$|', $dir)) { @@ -127,7 +127,7 @@ class CI_Zip { * * If this is a newly created file/dir, we will set the time to 'now' * - * @param string path to file + * @param string $dir path to file * @return array filemtime/filemdate */ protected function _get_mod_time($dir) @@ -146,9 +146,9 @@ class CI_Zip { /** * Add Directory * - * @param string the directory name - * @param int - * @param int + * @param string $dir the directory name + * @param int $file_mtime + * @param int $file_mdate * @return void */ protected function _add_dir($dir, $file_mtime, $file_mdate) @@ -199,8 +199,8 @@ class CI_Zip { * in the filename it will be placed within a directory. Make * sure you use add_dir() first to create the folder. * - * @param mixed - * @param string + * @param mixed $filepath A single filepath or an array of file => data pairs + * @param string $data Single file contents * @return void */ public function add_data($filepath, $data = NULL) @@ -225,10 +225,10 @@ class CI_Zip { /** * Add Data to Zip * - * @param string the file name/path - * @param string the data to be encoded - * @param int - * @param int + * @param string $filepath the file name/path + * @param string $data the data to be encoded + * @param int $file_mtime + * @param int $file_mdate * @return void */ protected function _add_data($filepath, $data, $file_mtime, $file_mdate) @@ -278,8 +278,8 @@ class CI_Zip { /** * Read the contents of a file and add it to the zip * - * @param string - * @param bool + * @param string $path + * @param bool $preserve_filepath * @return bool */ public function read_file($path, $preserve_filepath = FALSE) @@ -313,9 +313,9 @@ class CI_Zip { * sub-folders) and creates a zip based on it. Whatever directory structure * is in the original file path will be recreated in the zip file. * - * @param string path to source - * @param bool - * @param bool + * @param string $path path to source directory + * @param bool $preserve_filepath + * @param string $root_path * @return bool */ public function read_dir($path, $preserve_filepath = TRUE, $root_path = NULL) @@ -389,7 +389,7 @@ class CI_Zip { * * Lets you write a file * - * @param string the file name + * @param string $filepath the file name * @return bool */ public function archive($filepath) @@ -412,7 +412,7 @@ class CI_Zip { /** * Download * - * @param string the file name + * @param string $filename the file name * @return void */ public function download($filename = 'backup.zip') -- cgit v1.2.3-24-g4f1b From 06fa739406e5103298ca72fc67cc41f0f8c6b6f4 Mon Sep 17 00:00:00 2001 From: David Cox Jr Date: Wed, 25 Sep 2013 01:56:10 -0400 Subject: fix issue #2617 simply adds the $_FILES array to profiler output of POST data --- system/libraries/Profiler.php | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) (limited to 'system/libraries') diff --git a/system/libraries/Profiler.php b/system/libraries/Profiler.php index 9e9e7d08d..80130eb48 100644 --- a/system/libraries/Profiler.php +++ b/system/libraries/Profiler.php @@ -338,7 +338,7 @@ class CI_Profiler { ."\n" .'  '.$this->CI->lang->line('profiler_post_data')."  \n"; - if (count($_POST) === 0) + if (count($_POST) === 0 AND count($_FILES) === 0) { $output .= '
'.$this->CI->lang->line('profiler_no_post').'
'; } @@ -368,9 +368,29 @@ class CI_Profiler { $output .= "\n"; } + foreach ($_FILES as $key => $val) + { + if ( ! is_numeric($key)) + { + $key = "'".$key."'"; + } + + $output .= '$_FILES[' + .$key.']   '; + + if (is_array($val) OR is_object($val)) + { + $output .= '
'.htmlspecialchars(stripslashes(print_r($val, TRUE))).'
'; + } + + $output .= "\n"; + } + $output .= "\n"; } + + return $output.''; } -- cgit v1.2.3-24-g4f1b From b367f7ba9302f00926f6b923ca1ca741b351ae96 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Mon, 14 Oct 2013 12:27:00 +0300 Subject: Fix #2674 --- system/libraries/Pagination.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'system/libraries') diff --git a/system/libraries/Pagination.php b/system/libraries/Pagination.php index 10fb29dbd..c6ffd03d4 100644 --- a/system/libraries/Pagination.php +++ b/system/libraries/Pagination.php @@ -354,7 +354,8 @@ class CI_Pagination { public function create_links() { // If our item count or per-page total is zero there is no need to continue. - if ($this->total_rows === 0 OR $this->per_page === 0) + // Note: DO NOT change the operator to === here! + if ($this->total_rows == 0 OR $this->per_page == 0) { return ''; } -- cgit v1.2.3-24-g4f1b From abcb67c76ccb384ea213f9c4f42a392b15b3e15e Mon Sep 17 00:00:00 2001 From: David Cox Jr Date: Wed, 16 Oct 2013 14:43:52 -0400 Subject: req. changes: cleaned up conditionals added changelog note regarding profiler updated as per styleguide --- system/libraries/Profiler.php | 19 ++++--------------- 1 file changed, 4 insertions(+), 15 deletions(-) (limited to 'system/libraries') diff --git a/system/libraries/Profiler.php b/system/libraries/Profiler.php index 80130eb48..50ba1673f 100644 --- a/system/libraries/Profiler.php +++ b/system/libraries/Profiler.php @@ -307,10 +307,7 @@ class CI_Profiler { foreach ($_GET as $key => $val) { - if ( ! is_numeric($key)) - { - $key = "'".$key."'"; - } + is_int($key) OR $key = "'".$key."'"; $output .= '$_GET[' .$key.']   ' @@ -338,7 +335,7 @@ class CI_Profiler { ."\n" .'  '.$this->CI->lang->line('profiler_post_data')."  \n"; - if (count($_POST) === 0 AND count($_FILES) === 0) + if (count($_POST) === 0 && count($_FILES) === 0) { $output .= '
'.$this->CI->lang->line('profiler_no_post').'
'; } @@ -348,10 +345,7 @@ class CI_Profiler { foreach ($_POST as $key => $val) { - if ( ! is_numeric($key)) - { - $key = "'".$key."'"; - } + is_int($key) OR $key = "'".$key."'"; $output .= '$_POST[' .$key.']   '; @@ -370,10 +364,7 @@ class CI_Profiler { foreach ($_FILES as $key => $val) { - if ( ! is_numeric($key)) - { - $key = "'".$key."'"; - } + is_int($key) OR $key = "'".$key."'"; $output .= '$_FILES[' .$key.']   '; @@ -389,8 +380,6 @@ class CI_Profiler { $output .= "\n"; } - - return $output.''; } -- cgit v1.2.3-24-g4f1b From 32c7212edb0488524a0eece98cb1e2321ee90c29 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Mon, 21 Oct 2013 15:35:05 +0300 Subject: Add CI_Upload:: option --- system/libraries/Upload.php | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) (limited to 'system/libraries') diff --git a/system/libraries/Upload.php b/system/libraries/Upload.php index 060973847..7989d113e 100644 --- a/system/libraries/Upload.php +++ b/system/libraries/Upload.php @@ -233,6 +233,13 @@ class CI_Upload { */ public $xss_clean = FALSE; + /** + * Apache mod_mime fix flag + * + * @var bool + */ + public $mod_mime_fix = TRUE; + /** * Temporary filename prefix * @@ -314,6 +321,7 @@ class CI_Upload { 'remove_spaces' => TRUE, 'detect_mime' => TRUE, 'xss_clean' => FALSE, + 'mod_mime_fix' => TRUE, 'temp_prefix' => 'temp_file_', 'client_name' => '' ); @@ -1148,7 +1156,7 @@ class CI_Upload { */ protected function _prep_filename($filename) { - if (strpos($filename, '.') === FALSE OR $this->allowed_types === '*') + if ($this->mod_mime_fix === FALSE OR $this->allowed_types === '*' OR strpos($filename, '.') === FALSE) { return $filename; } -- cgit v1.2.3-24-g4f1b From a587a939ce0b8e7d1dfe0830ac83d881e151d6e0 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Wed, 23 Oct 2013 19:57:46 +0300 Subject: Fix issue #2695 --- system/libraries/Form_validation.php | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) (limited to 'system/libraries') diff --git a/system/libraries/Form_validation.php b/system/libraries/Form_validation.php index 8b9bfa897..5ea2f81af 100644 --- a/system/libraries/Form_validation.php +++ b/system/libraries/Form_validation.php @@ -898,12 +898,19 @@ class CI_Form_validation { } $field = $this->_field_data[$field]['postdata']; + $value = (string) $value; if (is_array($field)) { - if ( ! in_array($value, $field)) + // Note: in_array('', array(0)) returns TRUE, do not use it + foreach ($field as &$v) { - return ''; + if ($value === $v) + { + return ' selected="selected"'; + } } + + return ''; } elseif (($field === '' OR $value === '') OR ($field !== $value)) { @@ -934,12 +941,19 @@ class CI_Form_validation { } $field = $this->_field_data[$field]['postdata']; + $value = (string) $value; if (is_array($field)) { - if ( ! in_array($value, $field)) + // Note: in_array('', array(0)) returns TRUE, do not use it + foreach ($field as &$v) { - return ''; + if ($value === $v) + { + return ' checked="checked"'; + } } + + return ''; } elseif (($field === '' OR $value === '') OR ($field !== $value)) { -- cgit v1.2.3-24-g4f1b From 80d663aa81eec7bc0894efe1012faec7f6d452b0 Mon Sep 17 00:00:00 2001 From: Kakysha Date: Mon, 28 Oct 2013 01:39:17 +0400 Subject: Added option to connect through unix socket in redis cache driver --- system/libraries/Cache/drivers/Cache_redis.php | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) (limited to 'system/libraries') diff --git a/system/libraries/Cache/drivers/Cache_redis.php b/system/libraries/Cache/drivers/Cache_redis.php index 40823fcb4..8daed8bc3 100644 --- a/system/libraries/Cache/drivers/Cache_redis.php +++ b/system/libraries/Cache/drivers/Cache_redis.php @@ -44,6 +44,7 @@ class CI_Cache_redis extends CI_Driver * @var array */ protected static $_default_config = array( + 'socket_type' => 'tcp', 'host' => '127.0.0.1', 'password' => NULL, 'port' => 6379, @@ -200,7 +201,13 @@ class CI_Cache_redis extends CI_Driver try { - $this->_redis->connect($config['host'], $config['port'], $config['timeout']); + if ($config['socket_type'] === 'unix') + { + $v = $this->_redis->connect($config['socket']); + } else // tcp socket + { + $this->_redis->connect($config['host'], $config['port'], $config['timeout']); + } } catch (RedisException $e) { -- cgit v1.2.3-24-g4f1b From 2d14673d1a513a372a5921775aa3987f8444477e Mon Sep 17 00:00:00 2001 From: Kakysha Date: Mon, 28 Oct 2013 20:20:24 +0400 Subject: Correct Redis connection troubleshooting --- system/libraries/Cache/drivers/Cache_redis.php | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) (limited to 'system/libraries') diff --git a/system/libraries/Cache/drivers/Cache_redis.php b/system/libraries/Cache/drivers/Cache_redis.php index 8daed8bc3..b0315a3ab 100644 --- a/system/libraries/Cache/drivers/Cache_redis.php +++ b/system/libraries/Cache/drivers/Cache_redis.php @@ -164,8 +164,7 @@ class CI_Cache_redis extends CI_Driver { if (extension_loaded('redis')) { - $this->_setup_redis(); - return TRUE; + return $this->_setup_redis(); } else { @@ -206,18 +205,26 @@ class CI_Cache_redis extends CI_Driver $v = $this->_redis->connect($config['socket']); } else // tcp socket { - $this->_redis->connect($config['host'], $config['port'], $config['timeout']); + $v = $this->_redis->connect($config['host'], $config['port'], $config['timeout']); + } + if (!$v) + { + log_message('debug','Redis connection refused. Check the config.'); + return FALSE; } } catch (RedisException $e) { - show_error('Redis connection refused. ' . $e->getMessage()); + log_message('debug','Redis connection refused. ' . $e->getMessage()); + return FALSE; } if (isset($config['password'])) { $this->_redis->auth($config['password']); } + + return TRUE; } // ------------------------------------------------------------------------ -- cgit v1.2.3-24-g4f1b From ffe2130b00bffb2f43debf82c34586642c831b0b Mon Sep 17 00:00:00 2001 From: Kakysha Date: Mon, 28 Oct 2013 21:30:05 +0400 Subject: some code rewrite --- system/libraries/Cache/drivers/Cache_redis.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'system/libraries') diff --git a/system/libraries/Cache/drivers/Cache_redis.php b/system/libraries/Cache/drivers/Cache_redis.php index b0315a3ab..0bbd5b05c 100644 --- a/system/libraries/Cache/drivers/Cache_redis.php +++ b/system/libraries/Cache/drivers/Cache_redis.php @@ -202,12 +202,12 @@ class CI_Cache_redis extends CI_Driver { if ($config['socket_type'] === 'unix') { - $v = $this->_redis->connect($config['socket']); + $success = $this->_redis->connect($config['socket']); } else // tcp socket { - $v = $this->_redis->connect($config['host'], $config['port'], $config['timeout']); + $success = $this->_redis->connect($config['host'], $config['port'], $config['timeout']); } - if (!$v) + if ( ! $success) { log_message('debug','Redis connection refused. Check the config.'); return FALSE; -- cgit v1.2.3-24-g4f1b From 8f3f1f9a6dd7c4feb77ffc040b37799fc101e470 Mon Sep 17 00:00:00 2001 From: Kakysha Date: Mon, 28 Oct 2013 23:14:08 +0400 Subject: Code cleanup --- system/libraries/Cache/drivers/Cache_redis.php | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'system/libraries') diff --git a/system/libraries/Cache/drivers/Cache_redis.php b/system/libraries/Cache/drivers/Cache_redis.php index 0bbd5b05c..194745fe0 100644 --- a/system/libraries/Cache/drivers/Cache_redis.php +++ b/system/libraries/Cache/drivers/Cache_redis.php @@ -203,10 +203,12 @@ class CI_Cache_redis extends CI_Driver if ($config['socket_type'] === 'unix') { $success = $this->_redis->connect($config['socket']); - } else // tcp socket + } + else // tcp socket { $success = $this->_redis->connect($config['host'], $config['port'], $config['timeout']); } + if ( ! $success) { log_message('debug','Redis connection refused. Check the config.'); @@ -215,7 +217,7 @@ class CI_Cache_redis extends CI_Driver } catch (RedisException $e) { - log_message('debug','Redis connection refused. ' . $e->getMessage()); + log_message('debug','Cache: Redis connection refused ('.$e->getMessage().')'); return FALSE; } -- cgit v1.2.3-24-g4f1b From 333b69b029c4d694f1f77aaefeb9c4deeeca47b9 Mon Sep 17 00:00:00 2001 From: Kakysha Date: Tue, 29 Oct 2013 03:49:56 +0400 Subject: Spaces, log message --- system/libraries/Cache/drivers/Cache_redis.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'system/libraries') diff --git a/system/libraries/Cache/drivers/Cache_redis.php b/system/libraries/Cache/drivers/Cache_redis.php index 194745fe0..f13e4479f 100644 --- a/system/libraries/Cache/drivers/Cache_redis.php +++ b/system/libraries/Cache/drivers/Cache_redis.php @@ -211,13 +211,13 @@ class CI_Cache_redis extends CI_Driver if ( ! $success) { - log_message('debug','Redis connection refused. Check the config.'); + log_message('debug', 'Cache: Redis connection refused. Check the config.'); return FALSE; } } catch (RedisException $e) { - log_message('debug','Cache: Redis connection refused ('.$e->getMessage().')'); + log_message('debug', 'Cache: Redis connection refused ('.$e->getMessage().')'); return FALSE; } -- cgit v1.2.3-24-g4f1b From f964b16f3db95d655420dfae2012ee9fbb98a1a8 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Tue, 12 Nov 2013 17:04:55 +0200 Subject: Deprecate CI_Input::is_cli_request() and add common function is_cli() to replace it Calls to this function are often needed before the Input library is available --- system/libraries/Session/Session.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'system/libraries') diff --git a/system/libraries/Session/Session.php b/system/libraries/Session/Session.php index 659a0269e..19de97994 100644 --- a/system/libraries/Session/Session.php +++ b/system/libraries/Session/Session.php @@ -102,10 +102,10 @@ class CI_Session extends CI_Driver_Library { */ public function __construct(array $params = array()) { - $CI =& get_instance(); + $_config =& get_instance()->config; // No sessions under CLI - if ($CI->input->is_cli_request()) + if (is_cli()) { return; } @@ -113,7 +113,7 @@ class CI_Session extends CI_Driver_Library { log_message('debug', 'CI_Session Class Initialized'); // Add possible extra entries to our valid drivers list - $drivers = isset($params['sess_valid_drivers']) ? $params['sess_valid_drivers'] : $CI->config->item('sess_valid_drivers'); + $drivers = isset($params['sess_valid_drivers']) ? $params['sess_valid_drivers'] : $_config->item('sess_valid_drivers'); if ( ! empty($drivers)) { $drivers = array_map('strtolower', (array) $drivers); @@ -121,7 +121,7 @@ class CI_Session extends CI_Driver_Library { } // Get driver to load - $driver = isset($params['sess_driver']) ? $params['sess_driver'] : $CI->config->item('sess_driver'); + $driver = isset($params['sess_driver']) ? $params['sess_driver'] : $_config->item('sess_driver'); if ( ! $driver) { log_message('debug', "Session: No driver name is configured, defaulting to 'cookie'."); -- cgit v1.2.3-24-g4f1b From 3ca060a00e5039aa00d4180ded52b1af49939114 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Wed, 27 Nov 2013 16:30:31 +0200 Subject: [ci skip] Remove a few more spaces --- system/libraries/Ftp.php | 2 +- system/libraries/Xmlrpc.php | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) (limited to 'system/libraries') diff --git a/system/libraries/Ftp.php b/system/libraries/Ftp.php index dc6bbd226..2489f490f 100644 --- a/system/libraries/Ftp.php +++ b/system/libraries/Ftp.php @@ -392,7 +392,7 @@ class CI_FTP { { if ($this->debug === TRUE) { - $this->_error('ftp_unable_to_' . ($move === FALSE ? 'rename' : 'move')); + $this->_error('ftp_unable_to_'.($move === FALSE ? 'rename' : 'move')); } return FALSE; } diff --git a/system/libraries/Xmlrpc.php b/system/libraries/Xmlrpc.php index 16c5b0ed8..fe9781b28 100644 --- a/system/libraries/Xmlrpc.php +++ b/system/libraries/Xmlrpc.php @@ -1684,7 +1684,7 @@ class XML_RPC_Values extends CI_Xmlrpc { if ($this->mytype !== 0) { - echo 'XML_RPC_Values: already initialized as a [' . $this->kindOf() . ']
'; + echo 'XML_RPC_Values: already initialized as a ['.$this->kindOf().']
'; return 0; } @@ -1705,7 +1705,7 @@ class XML_RPC_Values extends CI_Xmlrpc { if ($this->mytype !== 0) { - echo 'XML_RPC_Values: already initialized as a [' . $this->kindOf() . ']
'; + echo 'XML_RPC_Values: already initialized as a ['.$this->kindOf().']
'; return 0; } $this->mytype = $this->xmlrpcTypes['struct']; -- cgit v1.2.3-24-g4f1b From 74c5f2668d31f7384ea5f014014356144059cbf3 Mon Sep 17 00:00:00 2001 From: Tyler Brownell Date: Fri, 13 Dec 2013 00:23:12 -0500 Subject: Issue #2763 - Fixes Session GC Probability Calculation This should resolve issue #2763 where the cookie session garbage collection was running every request. --- system/libraries/Session/drivers/Session_cookie.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system/libraries') diff --git a/system/libraries/Session/drivers/Session_cookie.php b/system/libraries/Session/drivers/Session_cookie.php index d3d22d03a..cd8074474 100644 --- a/system/libraries/Session/drivers/Session_cookie.php +++ b/system/libraries/Session/drivers/Session_cookie.php @@ -841,7 +841,7 @@ class CI_Session_cookie extends CI_Session_driver { $probability = ini_get('session.gc_probability'); $divisor = ini_get('session.gc_divisor'); - if ((mt_rand(0, $divisor) / $divisor) < $probability) + if (mt_rand(1, $divisor) <= $probability) { $expire = $this->now - $this->sess_expiration; $this->CI->db->delete($this->sess_table_name, 'last_activity < '.$expire); -- cgit v1.2.3-24-g4f1b From 0612e92461bb725835b4731a55d7f76588cd4cf9 Mon Sep 17 00:00:00 2001 From: Cristian Riffo Huez Date: Fri, 13 Dec 2013 22:09:44 -0300 Subject: Added post-increment for $count It has been added the missing post-increment for variable $count. --- system/libraries/Profiler.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'system/libraries') diff --git a/system/libraries/Profiler.php b/system/libraries/Profiler.php index 50ba1673f..7c889dd96 100644 --- a/system/libraries/Profiler.php +++ b/system/libraries/Profiler.php @@ -278,6 +278,7 @@ class CI_Profiler { } $output .= "\n"; + $count++; } return $output; @@ -563,4 +564,4 @@ class CI_Profiler { } /* End of file Profiler.php */ -/* Location: ./system/libraries/Profiler.php */ \ No newline at end of file +/* Location: ./system/libraries/Profiler.php */ -- cgit v1.2.3-24-g4f1b From 5d6b9c597a9870f55a65bcfcb301d19d83447078 Mon Sep 17 00:00:00 2001 From: Jordan Eldredge Date: Sat, 21 Dec 2013 13:56:41 -0800 Subject: Remove unneeded manual escaping of session data --- .../libraries/Session/drivers/Session_cookie.php | 63 ++-------------------- 1 file changed, 3 insertions(+), 60 deletions(-) (limited to 'system/libraries') diff --git a/system/libraries/Session/drivers/Session_cookie.php b/system/libraries/Session/drivers/Session_cookie.php index cd8074474..124e0098e 100644 --- a/system/libraries/Session/drivers/Session_cookie.php +++ b/system/libraries/Session/drivers/Session_cookie.php @@ -739,86 +739,29 @@ class CI_Session_cookie extends CI_Session_driver { /** * Serialize an array * - * This function first converts any slashes found in the array to a temporary - * marker, so when it gets unserialized the slashes will be preserved + * This function serializes an array * * @param mixed Data to serialize * @return string Serialized data */ protected function _serialize($data) { - if (is_array($data)) - { - array_walk_recursive($data, array(&$this, '_escape_slashes')); - } - elseif (is_string($data)) - { - $data = str_replace('\\', '{{slash}}', $data); - } - return serialize($data); } // ------------------------------------------------------------------------ - /** - * Escape slashes - * - * This function converts any slashes found into a temporary marker - * - * @param string Value - * @param string Key - * @return void - */ - protected function _escape_slashes(&$val, $key) - { - if (is_string($val)) - { - $val = str_replace('\\', '{{slash}}', $val); - } - } - - // ------------------------------------------------------------------------ - /** * Unserialize * - * This function unserializes a data string, then converts any - * temporary slash markers back to actual slashes + * This function unserializes a data string * * @param mixed Data to unserialize * @return mixed Unserialized data */ protected function _unserialize($data) { - $data = @unserialize(trim($data)); - - if (is_array($data)) - { - array_walk_recursive($data, array(&$this, '_unescape_slashes')); - return $data; - } - - return is_string($data) ? str_replace('{{slash}}', '\\', $data) : $data; - } - - // ------------------------------------------------------------------------ - - /** - * Unescape slashes - * - * This function converts any slash markers back into actual slashes - * - * @param string Value - * @param string Key - * @return void - */ - protected function _unescape_slashes(&$val, $key) - { - if (is_string($val)) - { - $val = str_replace('{{slash}}', '\\', $val); - } + return @unserialize(trim($data)); } // ------------------------------------------------------------------------ -- cgit v1.2.3-24-g4f1b From 5306cad2e40596a3a6fcac787e54689a7095e769 Mon Sep 17 00:00:00 2001 From: Jordan Eldredge Date: Mon, 23 Dec 2013 11:10:51 -0800 Subject: Remove _serialize() and _unserialize() methods Since removing the unneeded manual escaping code, there is no-longer any reason to have the serialization functions abstracted. This also allows us to only suppress errors when unserializing cookie data, and only trim when we are unserializing database data (see commit 6b8312). --- .../libraries/Session/drivers/Session_cookie.php | 38 +++------------------- 1 file changed, 4 insertions(+), 34 deletions(-) (limited to 'system/libraries') diff --git a/system/libraries/Session/drivers/Session_cookie.php b/system/libraries/Session/drivers/Session_cookie.php index 124e0098e..dc75d8e8e 100644 --- a/system/libraries/Session/drivers/Session_cookie.php +++ b/system/libraries/Session/drivers/Session_cookie.php @@ -397,7 +397,7 @@ class CI_Session_cookie extends CI_Session_driver { } // Unserialize the session array - $session = $this->_unserialize($session); + $session = @unserialize($session); // Is the session data we unserialized an array with the correct format? if ( ! is_array($session) OR ! isset($session['session_id'], $session['ip_address'], $session['user_agent'], $session['last_activity'])) @@ -472,7 +472,7 @@ class CI_Session_cookie extends CI_Session_driver { $row = $query->row(); if ( ! empty($row->user_data)) { - $custom_data = $this->_unserialize($row->user_data); + $custom_data = unserialize(trim($row->user_data)); if (is_array($custom_data)) { @@ -608,7 +608,7 @@ class CI_Session_cookie extends CI_Session_driver { if ( ! empty($userdata)) { // Serialize the custom data array so we can store it - $set['user_data'] = $this->_serialize($userdata); + $set['user_data'] = serialize($userdata); } // Reset query builder values. @@ -696,7 +696,7 @@ class CI_Session_cookie extends CI_Session_driver { : $this->userdata; // Serialize the userdata for the cookie - $cookie_data = $this->_serialize($cookie_data); + $cookie_data = serialize($cookie_data); if ($this->sess_encrypt_cookie === TRUE) { @@ -736,36 +736,6 @@ class CI_Session_cookie extends CI_Session_driver { // ------------------------------------------------------------------------ - /** - * Serialize an array - * - * This function serializes an array - * - * @param mixed Data to serialize - * @return string Serialized data - */ - protected function _serialize($data) - { - return serialize($data); - } - - // ------------------------------------------------------------------------ - - /** - * Unserialize - * - * This function unserializes a data string - * - * @param mixed Data to unserialize - * @return mixed Unserialized data - */ - protected function _unserialize($data) - { - return @unserialize(trim($data)); - } - - // ------------------------------------------------------------------------ - /** * Garbage collection * -- cgit v1.2.3-24-g4f1b From 430b14cccd8e05de5b6b1268239e492ddea8f308 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Fri, 3 Jan 2014 17:31:26 +0200 Subject: Make CI_FTP::mkdir()'s first parameter mandatory (optional doesn't make sense) --- system/libraries/Ftp.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system/libraries') diff --git a/system/libraries/Ftp.php b/system/libraries/Ftp.php index 2489f490f..84ecf133c 100644 --- a/system/libraries/Ftp.php +++ b/system/libraries/Ftp.php @@ -247,7 +247,7 @@ class CI_FTP { * @param int $permissions * @return bool */ - public function mkdir($path = '', $permissions = NULL) + public function mkdir($path, $permissions = NULL) { if ($path === '' OR ! $this->_is_conn()) { -- cgit v1.2.3-24-g4f1b From b4c62180ea70fba546aa8fe1813685dd72e4a406 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Fri, 3 Jan 2014 17:39:26 +0200 Subject: FTP class improvements - Make changedir()'s first parameter mandatory (optional doesn't make sense) - Fix a few typos (langfile included) --- system/libraries/Ftp.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'system/libraries') diff --git a/system/libraries/Ftp.php b/system/libraries/Ftp.php index 84ecf133c..4be2d0a21 100644 --- a/system/libraries/Ftp.php +++ b/system/libraries/Ftp.php @@ -214,10 +214,10 @@ class CI_FTP { * Internally, this parameter is only used by the "mirror" function below. * * @param string $path - * @param bool $supress_debug + * @param bool $suppress_debug * @return bool */ - public function changedir($path = '', $supress_debug = FALSE) + public function changedir($path, $suppress_debug = FALSE) { if ($path === '' OR ! $this->_is_conn()) { @@ -228,7 +228,7 @@ class CI_FTP { if ($result === FALSE) { - if ($this->debug === TRUE && $supress_debug === FALSE) + if ($this->debug === TRUE && $suppress_debug === FALSE) { $this->_error('ftp_unable_to_changedir'); } @@ -260,7 +260,7 @@ class CI_FTP { { if ($this->debug === TRUE) { - $this->_error('ftp_unable_to_makdir'); + $this->_error('ftp_unable_to_mkdir'); } return FALSE; } -- cgit v1.2.3-24-g4f1b From a6eae87d14efe3169156a12ad3706852ff70e2c4 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Fri, 3 Jan 2014 18:25:20 +0200 Subject: [ci skip] Some spaces & docblock fixes --- system/libraries/Profiler.php | 2 +- system/libraries/Unit_test.php | 26 ++++++++++++-------------- 2 files changed, 13 insertions(+), 15 deletions(-) (limited to 'system/libraries') diff --git a/system/libraries/Profiler.php b/system/libraries/Profiler.php index 7c889dd96..4e556b23d 100644 --- a/system/libraries/Profiler.php +++ b/system/libraries/Profiler.php @@ -564,4 +564,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/Unit_test.php b/system/libraries/Unit_test.php index 7a67c7276..53e4dfac4 100644 --- a/system/libraries/Unit_test.php +++ b/system/libraries/Unit_test.php @@ -81,7 +81,15 @@ class CI_Unit_test { * * @var array */ - protected $_test_items_visible = array(); + protected $_test_items_visible = array( + 'test_name', + 'test_datatype', + 'res_datatype', + 'result', + 'file', + 'line', + 'notes' + ); // -------------------------------------------------------------------- @@ -92,17 +100,6 @@ class CI_Unit_test { */ public function __construct() { - // These are the default items visible when a test is run. - $this->_test_items_visible = array ( - 'test_name', - 'test_datatype', - 'res_datatype', - 'result', - 'file', - 'line', - 'notes' - ); - log_message('debug', 'Unit Testing Class Initialized'); } @@ -230,7 +227,7 @@ class CI_Unit_test { * * Causes the evaluation to use === rather than == * - * @param bool + * @param bool $state * @return void */ public function use_strict($state = TRUE) @@ -288,6 +285,7 @@ class CI_Unit_test { { $val = $line; } + $temp[$CI->lang->line('ut_'.$key, FALSE)] = $val; } @@ -396,4 +394,4 @@ function is_false($test) } /* End of file Unit_test.php */ -/* Location: ./system/libraries/Unit_test.php */ +/* Location: ./system/libraries/Unit_test.php */ \ No newline at end of file -- cgit v1.2.3-24-g4f1b From cb663676e63c7a4c792181dabea3fd834514cea2 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Fri, 3 Jan 2014 18:45:37 +0200 Subject: Make CI_Unit_test::set_test_items()'s parameter mandatory (optional doesn't make sense) --- system/libraries/Unit_test.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'system/libraries') diff --git a/system/libraries/Unit_test.php b/system/libraries/Unit_test.php index 53e4dfac4..e412b9858 100644 --- a/system/libraries/Unit_test.php +++ b/system/libraries/Unit_test.php @@ -110,10 +110,10 @@ class CI_Unit_test { * * Runs the supplied tests * - * @param array + * @param array $items * @return void */ - public function set_test_items($items = array()) + public function set_test_items($items) { if ( ! empty($items) && is_array($items)) { -- cgit v1.2.3-24-g4f1b From a4712f562c27cdb2f2fcb15b37731e948f57276a Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Mon, 6 Jan 2014 11:25:46 +0200 Subject: Make CI_Form_validation::error()'s first parameter mandatory and add a typehint for CI_Form_validation::error() --- system/libraries/Form_validation.php | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'system/libraries') diff --git a/system/libraries/Form_validation.php b/system/libraries/Form_validation.php index 5ea2f81af..c02abbbcb 100644 --- a/system/libraries/Form_validation.php +++ b/system/libraries/Form_validation.php @@ -248,9 +248,9 @@ class CI_Form_validation { * @param array $data * @return void */ - public function set_data($data = '') + public function set_data(array $data) { - if ( ! empty($data) && is_array($data)) + if ( ! empty($data)) { $this->validation_data = $data; } @@ -304,12 +304,12 @@ class CI_Form_validation { * * Gets the error message associated with a particular field * - * @param string the field name - * @param string the html start tag - * @param strign the html end tag + * @param string $field Field name + * @param string $prefix HTML start tag + * @param strign $suffix HTML end tag * @return string */ - public function error($field = '', $prefix = '', $suffix = '') + public function error($field, $prefix = '', $suffix = '') { if (empty($this->_field_data[$field]['error'])) { -- cgit v1.2.3-24-g4f1b From 868301a5e10986c87717311432bf867386434ef0 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Mon, 6 Jan 2014 12:29:50 +0200 Subject: [ci skip] Fix a docblock typo --- system/libraries/Form_validation.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system/libraries') diff --git a/system/libraries/Form_validation.php b/system/libraries/Form_validation.php index c02abbbcb..e8bd25b58 100644 --- a/system/libraries/Form_validation.php +++ b/system/libraries/Form_validation.php @@ -306,7 +306,7 @@ class CI_Form_validation { * * @param string $field Field name * @param string $prefix HTML start tag - * @param strign $suffix HTML end tag + * @param string $suffix HTML end tag * @return string */ public function error($field, $prefix = '', $suffix = '') -- cgit v1.2.3-24-g4f1b From e6376aa4a95b7641a5d0cc5101118b9307be75bc Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Mon, 6 Jan 2014 13:11:30 +0200 Subject: Make CI_Session's set_userdata(), set_flashdata(), set_tempdata(), unset_userdata() and unset_flashdata()'s first parameter mandatory --- system/libraries/Session/Session.php | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'system/libraries') diff --git a/system/libraries/Session/Session.php b/system/libraries/Session/Session.php index 19de97994..ac97b944c 100644 --- a/system/libraries/Session/Session.php +++ b/system/libraries/Session/Session.php @@ -288,7 +288,7 @@ class CI_Session extends CI_Driver_Library { * @param string Item value or empty string * @return void */ - public function set_userdata($newdata = array(), $newval = '') + public function set_userdata($newdata, $newval = '') { // Wrap params as array if singular if (is_string($newdata)) @@ -317,7 +317,7 @@ class CI_Session extends CI_Driver_Library { * @param mixed Item name or array of item names * @return void */ - public function unset_userdata($newdata = array()) + public function unset_userdata($newdata) { // Wrap single name as array if (is_string($newdata)) @@ -360,7 +360,7 @@ class CI_Session extends CI_Driver_Library { * @param string Item value or empty string * @return void */ - public function set_flashdata($newdata = array(), $newval = '') + public function set_flashdata($newdata, $newval = '') { // Wrap item as array if singular if (is_string($newdata)) @@ -434,7 +434,7 @@ class CI_Session extends CI_Driver_Library { * @param int Item lifetime in seconds or 0 for default * @return void */ - public function set_tempdata($newdata = array(), $newval = '', $expire = 0) + public function set_tempdata($newdata, $newval = '', $expire = 0) { // Set expiration time $expire = time() + ($expire ? $expire : self::TEMP_EXP_DEF); @@ -475,7 +475,7 @@ class CI_Session extends CI_Driver_Library { * @param mixed Item name or array of item names * @return void */ - public function unset_tempdata($newdata = array()) + public function unset_tempdata($newdata) { // Get expirations list $expirations = $this->userdata(self::EXPIRATION_KEY); -- cgit v1.2.3-24-g4f1b From 45549a2919892e31782fc4381d7db8c6f3293bcb Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Mon, 6 Jan 2014 13:55:38 +0200 Subject: Remove a redudant value check --- system/libraries/Ftp.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system/libraries') diff --git a/system/libraries/Ftp.php b/system/libraries/Ftp.php index 4be2d0a21..73a68441a 100644 --- a/system/libraries/Ftp.php +++ b/system/libraries/Ftp.php @@ -219,7 +219,7 @@ class CI_FTP { */ public function changedir($path, $suppress_debug = FALSE) { - if ($path === '' OR ! $this->_is_conn()) + if ( ! $this->_is_conn()) { return FALSE; } -- cgit v1.2.3-24-g4f1b From a9c7d18dc4ba53507d6e606221f06aa3fafeaa8e Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Mon, 6 Jan 2014 14:38:00 +0200 Subject: Fix #2237: Parser library failed if the same tag pair is used more than once within a template (manually applying PR #2238 + updated unit tests) --- system/libraries/Parser.php | 30 +++++++++++++++++++----------- 1 file changed, 19 insertions(+), 11 deletions(-) (limited to 'system/libraries') diff --git a/system/libraries/Parser.php b/system/libraries/Parser.php index c1f1ad73b..399131cdd 100644 --- a/system/libraries/Parser.php +++ b/system/libraries/Parser.php @@ -187,26 +187,34 @@ class CI_Parser { */ protected function _parse_pair($variable, $data, $string) { - if (FALSE === ($match = $this->_match_pair($string, $variable))) + if (FALSE === ($matches = $this->_match_pair($string, $variable))) { return $string; } $str = ''; - foreach ($data as $row) + $search = $replace = array(); + foreach ($matches as $match) { - $temp = $match[1]; - foreach ($row as $key => $val) + $str = ''; + foreach ($data as $row) { - $temp = is_array($val) + $temp = $match[1]; + foreach ($row as $key => $val) + { + $temp = is_array($val) ? $this->_parse_pair($key, $val, $temp) : $this->_parse_single($key, $val, $temp); + } + + $str .= $temp; } - $str .= $temp; + $search[] = $match[0]; + $replace[] = $str; } - return str_replace($match[0], $str, $string); + return str_replace($search, $replace, $string); } // -------------------------------------------------------------------- @@ -214,14 +222,14 @@ class CI_Parser { /** * Matches a variable pair * - * @param string - * @param string + * @param string $string + * @param string $variable * @return mixed */ protected function _match_pair($string, $variable) { - 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) + return preg_match_all('|'.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, PREG_SET_ORDER) ? $match : FALSE; } -- cgit v1.2.3-24-g4f1b From dc53d7b68adc6fdc8d0917ee2d29f5670ff82b45 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Tue, 7 Jan 2014 12:12:11 +0200 Subject: Add Basic HTTP authentication support to the XML-RPC library (based on PR #1716) --- system/libraries/Xmlrpc.php | 31 ++++++++++++++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) (limited to 'system/libraries') diff --git a/system/libraries/Xmlrpc.php b/system/libraries/Xmlrpc.php index fe9781b28..bd59c933d 100644 --- a/system/libraries/Xmlrpc.php +++ b/system/libraries/Xmlrpc.php @@ -348,6 +348,11 @@ class CI_Xmlrpc { $parts = parse_url($url); + if (isset($parts['user'], $parts['pass'])) + { + $parts['host'] = $parts['user'].':'.$parts['pass'].'@'.$parts['host']; + } + $path = isset($parts['path']) ? $parts['path'] : '/'; if ( ! empty($parts['query'])) @@ -568,6 +573,21 @@ class XML_RPC_Client extends CI_Xmlrpc */ public $port = 80; + /** + * + * Server username + * + * @var string + */ + public $username; + + /** + * Server password + * + * @var string + */ + public $password; + /** * Proxy hostname * @@ -626,8 +646,16 @@ class XML_RPC_Client extends CI_Xmlrpc { parent::__construct(); + $url = parse_url('http://'.$server); + + if (isset($url['user'], $url['pass'])) + { + $this->username = $url['user']; + $this->password = $url['pass']; + } + $this->port = $port; - $this->server = $server; + $this->server = $url['host']; $this->path = $path; $this->proxy = $proxy; $this->proxy_port = $proxy_port; @@ -691,6 +719,7 @@ class XML_RPC_Client extends CI_Xmlrpc $op = 'POST '.$this->path.' HTTP/1.0'.$r .'Host: '.$this->server.$r .'Content-Type: text/xml'.$r + .(isset($this->username, $this->password) ? 'Authorization: Basic '.base64_encode($this->username.':'.$this->password).$r : '') .'User-Agent: '.$this->xmlrpcName.$r .'Content-Length: '.strlen($msg->payload).$r.$r .$msg->payload; -- cgit v1.2.3-24-g4f1b From 3b2803ef6ddd72772bf5bcb130ace207bc10d60e Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Tue, 7 Jan 2014 14:46:38 +0200 Subject: Fix #2143 When trying to load rules from a configuration file, the Form validation library matched against ruri_string() as opposed to 'controller/method' like described in the manual. Since ruri_string() also makes sense, now both are being checked with ruri_string() having a higher precedence. Supersedes PR #2224 --- system/libraries/Form_validation.php | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) (limited to 'system/libraries') diff --git a/system/libraries/Form_validation.php b/system/libraries/Form_validation.php index e8bd25b58..852fc7144 100644 --- a/system/libraries/Form_validation.php +++ b/system/libraries/Form_validation.php @@ -414,18 +414,15 @@ class CI_Form_validation { return FALSE; } - // Is there a validation rule for the particular URI being accessed? - $uri = ($group === '') ? trim($this->CI->uri->ruri_string(), '/') : $group; - - if ($uri !== '' && isset($this->_config_rules[$uri])) + if (empty($group)) { - $this->set_rules($this->_config_rules[$uri]); - } - else - { - $this->set_rules($this->_config_rules); + // Is there a validation rule for the particular URI being accessed? + $group = trim($this->CI->uri->ruri_string(), '/'); + isset($this->_config_rules[$group]) OR $group = $this->CI->router->class.'/'.$this->CI->router->method; } + $this->set_rules(isset($this->_config_rules[$group]) ? $this->_config_rules[$group] : $this->_config_rules); + // Were we able to set the rules correctly? if (count($this->_field_data) === 0) { -- cgit v1.2.3-24-g4f1b From a20ec975e653f501cca8e1cf57a9ea244417990f Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Tue, 7 Jan 2014 15:23:10 +0200 Subject: Add ability for changing the original file path/name in CI_Zip::read_file() Supersedes PR #884 --- system/libraries/Zip.php | 25 ++++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-) (limited to 'system/libraries') diff --git a/system/libraries/Zip.php b/system/libraries/Zip.php index 2ce457844..229b1ecbc 100644 --- a/system/libraries/Zip.php +++ b/system/libraries/Zip.php @@ -279,22 +279,25 @@ class CI_Zip { * Read the contents of a file and add it to the zip * * @param string $path - * @param bool $preserve_filepath + * @param bool $archive_filepath * @return bool */ - public function read_file($path, $preserve_filepath = FALSE) + public function read_file($path, $archive_filepath = FALSE) { - if ( ! file_exists($path)) - { - return FALSE; - } - - if (FALSE !== ($data = file_get_contents($path))) + if (file_exists($path) && FALSE !== ($data = file_get_contents($path))) { - $name = str_replace('\\', '/', $path); - if ($preserve_filepath === FALSE) + if (is_string($archive_filepath)) { - $name = preg_replace('|.*/(.+)|', '\\1', $name); + $name = str_replace('\\', '/', $archive_filepath); + } + else + { + $name = str_replace('\\', '/', $path); + + if ($preserve_filepath === FALSE) + { + $name = preg_replace('|.*/(.+)|', '\\1', $name); + } } $this->add_data($name, $data); -- cgit v1.2.3-24-g4f1b From e417f0439440246a66e02296da701e84c6c37866 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Wed, 8 Jan 2014 14:48:01 +0200 Subject: Some small improvements to the Xmlrpc class --- system/libraries/Xmlrpc.php | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) (limited to 'system/libraries') diff --git a/system/libraries/Xmlrpc.php b/system/libraries/Xmlrpc.php index bd59c933d..2fd12599e 100644 --- a/system/libraries/Xmlrpc.php +++ b/system/libraries/Xmlrpc.php @@ -884,10 +884,10 @@ class XML_RPC_Response /** * Decode * - * @param mixed + * @param mixed $array * @return array */ - public function decode($array = FALSE) + public function decode($array = NULL) { $CI =& get_instance(); @@ -899,9 +899,9 @@ class XML_RPC_Response { $array[$key] = $this->decode($array[$key]); } - else + elseif ($this->xss_clean) { - $array[$key] = ($this->xss_clean) ? $CI->security->xss_clean($array[$key]) : $array[$key]; + $array[$key] = $CI->security->xss_clean($array[$key]); } } @@ -914,9 +914,9 @@ class XML_RPC_Response { $result = $this->decode($result); } - else + elseif ($this->xss_clean) { - $result = ($this->xss_clean) ? $CI->security->xss_clean($result) : $result; + $result = $CI->security->xss_clean($result); } return $result; @@ -1509,14 +1509,14 @@ class XML_RPC_Message extends CI_Xmlrpc /** * Output parameters * - * @param array + * @param array $array * @return array */ - public function output_parameters($array = FALSE) + public function output_parameters(array $array = array()) { $CI =& get_instance(); - if (is_array($array)) + if ( ! empty($array)) { while (list($key) = each($array)) { @@ -1524,11 +1524,11 @@ class XML_RPC_Message extends CI_Xmlrpc { $array[$key] = $this->output_parameters($array[$key]); } - else + elseif ($key !== 'bits' && $this->xss_clean) { // 'bits' is for the MetaWeblog API image bits // @todo - this needs to be made more general purpose - $array[$key] = ($key === 'bits' OR $this->xss_clean === FALSE) ? $array[$key] : $CI->security->xss_clean($array[$key]); + $array[$key] = $CI->security->xss_clean($array[$key]); } } -- cgit v1.2.3-24-g4f1b From cab3e1813f71bddfe8f045772e5cb42e76a4d347 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Wed, 8 Jan 2014 14:51:56 +0200 Subject: A tiny improvement in CI_Upload::do_xss_clean() --- system/libraries/Upload.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'system/libraries') diff --git a/system/libraries/Upload.php b/system/libraries/Upload.php index 7989d113e..67a65501e 100644 --- a/system/libraries/Upload.php +++ b/system/libraries/Upload.php @@ -1081,8 +1081,7 @@ class CI_Upload { return FALSE; } - $CI =& get_instance(); - return $CI->security->xss_clean($data, TRUE); + return get_instance()->security->xss_clean($data, TRUE); } // -------------------------------------------------------------------- -- cgit v1.2.3-24-g4f1b From 119d8a7547e155edaaa53682b9247cd7e80d8c9d Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Wed, 8 Jan 2014 15:27:53 +0200 Subject: Optimize get_instance() calls/assignments --- system/libraries/Cache/drivers/Cache_redis.php | 4 ++-- system/libraries/Upload.php | 23 +++++++++++++---------- system/libraries/Xmlrpcs.php | 14 +++++--------- system/libraries/Zip.php | 3 +-- 4 files changed, 21 insertions(+), 23 deletions(-) (limited to 'system/libraries') diff --git a/system/libraries/Cache/drivers/Cache_redis.php b/system/libraries/Cache/drivers/Cache_redis.php index f13e4479f..48c803d7e 100644 --- a/system/libraries/Cache/drivers/Cache_redis.php +++ b/system/libraries/Cache/drivers/Cache_redis.php @@ -208,7 +208,7 @@ class CI_Cache_redis extends CI_Driver { $success = $this->_redis->connect($config['host'], $config['port'], $config['timeout']); } - + if ( ! $success) { log_message('debug', 'Cache: Redis connection refused. Check the config.'); @@ -225,7 +225,7 @@ class CI_Cache_redis extends CI_Driver { $this->_redis->auth($config['password']); } - + return TRUE; } diff --git a/system/libraries/Upload.php b/system/libraries/Upload.php index 67a65501e..525880f62 100644 --- a/system/libraries/Upload.php +++ b/system/libraries/Upload.php @@ -263,6 +263,13 @@ class CI_Upload { */ protected $_file_name_override = ''; + /** + * CI Singleton + * + * @var object + */ + protected $CI; + // -------------------------------------------------------------------- /** @@ -279,6 +286,7 @@ class CI_Upload { } $this->mimes =& get_mimes(); + $this->CI =& get_instance(); log_message('debug', 'Upload Class Initialized'); } @@ -479,8 +487,7 @@ class CI_Upload { } // Sanitize the file name for security - $CI =& get_instance(); - $this->file_name = $CI->security->sanitize_filename($this->file_name); + $this->file_name = $this->CI->security->sanitize_filename($this->file_name); // Truncate the file name if it's too long if ($this->max_filename > 0) @@ -1081,7 +1088,7 @@ class CI_Upload { return FALSE; } - return get_instance()->security->xss_clean($data, TRUE); + return $this->CI->security->xss_clean($data, TRUE); } // -------------------------------------------------------------------- @@ -1094,17 +1101,13 @@ class CI_Upload { */ public function set_error($msg) { - $CI =& get_instance(); - $CI->lang->load('upload'); + $this->CI->lang->load('upload'); - if ( ! is_array($msg)) - { - $msg = array($msg); - } + is_array($msg) OR $msg = array($msg); foreach ($msg as $val) { - $msg = ($CI->lang->line($val) === FALSE) ? $val : $CI->lang->line($val); + $msg = ($this->CI->lang->line($val) === FALSE) ? $val : $this->CI->lang->line($val); $this->error_msg[] = $msg; log_message('error', $msg); } diff --git a/system/libraries/Xmlrpcs.php b/system/libraries/Xmlrpcs.php index d263d789d..50ff423f2 100644 --- a/system/libraries/Xmlrpcs.php +++ b/system/libraries/Xmlrpcs.php @@ -384,17 +384,13 @@ class CI_Xmlrpcs extends CI_Xmlrpc { { return call_user_func(array($this, $method_parts[1]), $m); } + elseif ($this->object === FALSE) + { + return get_instance()->$method_parts[1]($m); + } else { - if ($this->object === FALSE) - { - $CI =& get_instance(); - return $CI->$method_parts[1]($m); - } - else - { - return $this->object->$method_parts[1]($m); - } + return $this->object->$method_parts[1]($m); } } else diff --git a/system/libraries/Zip.php b/system/libraries/Zip.php index 229b1ecbc..250ee02cd 100644 --- a/system/libraries/Zip.php +++ b/system/libraries/Zip.php @@ -425,8 +425,7 @@ class CI_Zip { $filename .= '.zip'; } - $CI =& get_instance(); - $CI->load->helper('download'); + get_instance()->load->helper('download'); $get_zip = $this->get_zip(); $zip_content =& $get_zip; -- cgit v1.2.3-24-g4f1b From bfb635b276d880336db795f1a603de66ccfc80f6 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Wed, 8 Jan 2014 18:32:05 +0200 Subject: Make newline standardization configurable Added ['standardize_newlines'] Also altered the Session cookie driver, which experienced issues with this feature due to it's HMAC verification failing after the Input class alters newlines in non-encrypted session cookies. Supersedes PR #2470 --- .../libraries/Session/drivers/Session_cookie.php | 25 +++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) (limited to 'system/libraries') diff --git a/system/libraries/Session/drivers/Session_cookie.php b/system/libraries/Session/drivers/Session_cookie.php index dc75d8e8e..65debcb44 100644 --- a/system/libraries/Session/drivers/Session_cookie.php +++ b/system/libraries/Session/drivers/Session_cookie.php @@ -165,6 +165,8 @@ class CI_Session_cookie extends CI_Session_driver { */ public $now; + // ------------------------------------------------------------------------ + /** * Default userdata keys * @@ -184,6 +186,15 @@ class CI_Session_cookie extends CI_Session_driver { */ protected $data_dirty = FALSE; + /** + * Standardize newlines flag + * + * @var bool + */ + protected $_standardize_newlines; + + // ------------------------------------------------------------------------ + /** * Initialize session driver object * @@ -209,9 +220,11 @@ class CI_Session_cookie extends CI_Session_driver { 'sess_time_to_update', 'time_reference', 'cookie_prefix', - 'encryption_key' + 'encryption_key', ); + $this->_standardize_newlines = (bool) $config['standardize_newlines']; + foreach ($prefs as $key) { $this->$key = isset($this->_parent->params[$key]) @@ -695,6 +708,16 @@ class CI_Session_cookie extends CI_Session_driver { ? array_intersect_key($this->userdata, $this->defaults) : $this->userdata; + // The Input class will do this and since we use HMAC verification, + // unless we standardize here as well, the hash won't match. + if ($this->_standardize_newlines) + { + foreach (array_keys($this->userdata) as $key) + { + $this->userdata[$key] = preg_replace('/(?:\r\n|[\r\n])/', PHP_EOL, $this->userdata[$key]); + } + } + // Serialize the userdata for the cookie $cookie_data = serialize($cookie_data); -- cgit v1.2.3-24-g4f1b From 7977e1d4859d48be00bb11250446d9abeff6ac35 Mon Sep 17 00:00:00 2001 From: Marcos SF Filho Date: Wed, 8 Jan 2014 15:34:11 -0200 Subject: Update the Calendar Class --- system/libraries/Calendar.php | 54 ++++++++++++++++++++++++++++++++++++++----- 1 file changed, 48 insertions(+), 6 deletions(-) (limited to 'system/libraries') diff --git a/system/libraries/Calendar.php b/system/libraries/Calendar.php index 23d8ffb42..a2d9db14b 100644 --- a/system/libraries/Calendar.php +++ b/system/libraries/Calendar.php @@ -95,6 +95,13 @@ class CI_Calendar { */ public $next_prev_url = ''; + /** + * Show days of other months + * + * @var bool + */ + public $show_other_days = FALSE; + /** * Class constructor * @@ -143,6 +150,15 @@ class CI_Calendar { $this->$key = $val; } } + + // Set the next_prev_url to the controller if required but not defined + if ($this->show_next_prev === TRUE) + { + if (empty($this->next_prev_url)) + { + $this->next_prev_url = rtrim($this->CI->config->site_url($this->CI->router->class . '/' . $this->CI->router->method), '/') . '/'; + } + } } // -------------------------------------------------------------------- @@ -261,10 +277,10 @@ class CI_Calendar { for ($i = 0; $i < 7; $i++) { - $out .= ($is_current_month === TRUE && $day == $cur_day) ? $this->temp['cal_cell_start_today'] : $this->temp['cal_cell_start']; - if ($day > 0 && $day <= $total_days) { + $out .= ($is_current_month === TRUE && $day == $cur_day) ? $this->temp['cal_cell_start_today'] : $this->temp['cal_cell_start']; + if (isset($data[$day])) { // Cells with content @@ -279,14 +295,37 @@ class CI_Calendar { $this->temp['cal_cell_no_content_today'] : $this->temp['cal_cell_no_content']; $out .= str_replace('{day}', $day, $temp); } + + $out .= ($is_current_month === TRUE && $day == $cur_day) ? $this->temp['cal_cell_end_today'] : $this->temp['cal_cell_end']; } else { - // Blank cells - $out .= $this->temp['cal_cell_blank']; + if ($this->show_other_days === TRUE) + { + $out .= $this->temp['cal_cell_start_other']; + + if ($day <= 0) + { + // Day of previous month + $prev_month = $this->adjust_date(((int) $month) - 1, $year); + $prev_month_days = $this->get_total_days($prev_month['month'], $prev_month['year']); + $out .= str_replace('{day}', $prev_month_days + $day, $this->temp['cal_cell_other']); + } + else + { + // Day of next month + $out .= str_replace('{day}', $day - $total_days, $this->temp['cal_cell_other']); + } + + $out .= $this->temp['cal_cell_end_other']; + } + else + { + // Blank cells + $out .= $this->temp['cal_cell_start'] . $this->temp['cal_cell_blank'] . $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++; } @@ -457,13 +496,16 @@ class CI_Calendar { 'cal_row_start' => '', 'cal_cell_start' => '', 'cal_cell_start_today' => '', + 'cal_cell_start_other' => '', 'cal_cell_content' => '{day}', 'cal_cell_content_today' => '{day}', 'cal_cell_no_content' => '{day}', 'cal_cell_no_content_today' => '{day}', 'cal_cell_blank' => ' ', + 'cal_cell_other' => '{day}', 'cal_cell_end' => '', 'cal_cell_end_today' => '', + 'cal_cell_end_other' => '', 'cal_row_end' => '', 'table_close' => '' ); @@ -490,7 +532,7 @@ class CI_Calendar { $today = array('cal_cell_start_today', 'cal_cell_content_today', 'cal_cell_no_content_today', 'cal_cell_end_today'); - foreach (array('table_open', 'table_close', 'heading_row_start', 'heading_previous_cell', 'heading_title_cell', 'heading_next_cell', 'heading_row_end', 'week_row_start', 'week_day_cell', 'week_row_end', 'cal_row_start', 'cal_cell_start', 'cal_cell_content', 'cal_cell_no_content', 'cal_cell_blank', 'cal_cell_end', 'cal_row_end', 'cal_cell_start_today', 'cal_cell_content_today', 'cal_cell_no_content_today', 'cal_cell_end_today') as $val) + foreach (array('table_open', 'table_close', 'heading_row_start', 'heading_previous_cell', 'heading_title_cell', 'heading_next_cell', 'heading_row_end', 'week_row_start', 'week_day_cell', 'week_row_end', 'cal_row_start', 'cal_cell_start', 'cal_cell_content', 'cal_cell_no_content', 'cal_cell_blank', 'cal_cell_end', 'cal_row_end', 'cal_cell_start_today', 'cal_cell_content_today', 'cal_cell_no_content_today', 'cal_cell_end_today', 'cal_cell_start_other', 'cal_cell_other', 'cal_cell_end_other') as $val) { if (preg_match('/\{'.$val.'\}(.*?)\{\/'.$val.'\}/si', $this->template, $match)) { -- cgit v1.2.3-24-g4f1b From 42b40006fe8b740b416a8e8fd9acb0666349e222 Mon Sep 17 00:00:00 2001 From: Ahmedul Haque Abid Date: Thu, 9 Jan 2014 01:10:25 +0600 Subject: Added custom error messages functionality for individual fields. --- system/libraries/Form_validation.php | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) (limited to 'system/libraries') diff --git a/system/libraries/Form_validation.php b/system/libraries/Form_validation.php index 852fc7144..e140bc46d 100644 --- a/system/libraries/Form_validation.php +++ b/system/libraries/Form_validation.php @@ -144,14 +144,16 @@ class CI_Form_validation { * Set Rules * * This function takes an array of field names and validation - * rules as input, validates the info, and stores it + * rules as input, any custom error messages, validates the info, + * and stores it * * @param mixed $field * @param string $label * @param mixed $rules + * @param array $error_msg * @return CI_Form_validation */ - public function set_rules($field, $label = '', $rules = '') + public function set_rules($field, $label = '', $rules = '', $error_msg = array()) { // No reason to set rules if we have no POST data // or a validation array has not been specified @@ -175,6 +177,9 @@ class CI_Form_validation { // If the field label wasn't passed we use the field name $label = isset($row['label']) ? $row['label'] : $row['field']; + // Add the custom error message array + $error_msg = (isset($row['error_msg']) && is_array($row['error_msg']) ) ? $row['error_msg'] : array(); + // Here we go! $this->set_rules($row['field'], $label, $row['rules']); } @@ -224,6 +229,7 @@ class CI_Form_validation { 'field' => $field, 'label' => $label, 'rules' => $rules, + 'error_msg' => $error_msg, 'is_array' => $is_array, 'keys' => $indexes, 'postdata' => NULL, @@ -602,7 +608,12 @@ class CI_Form_validation { // Set the message type $type = in_array('required', $rules) ? 'required' : 'isset'; - if (isset($this->_error_messages[$type])) + // Check if a custom message defined, else use default one + if (isset($this->_field_data[$row['field']]['error_msg'][$type])) + { + $line = $this->_field_data[$row['field']]['error_msg'][$type]; + } + elseif (isset($this->_error_messages[$type])) { $line = $this->_error_messages[$type]; } @@ -746,7 +757,12 @@ class CI_Form_validation { // Did the rule test negatively? If so, grab the error. if ($result === FALSE) { - if ( ! isset($this->_error_messages[$rule])) + // Check if a custom message defined, else use default one + if(isset($this->_field_data[$row['field']]['error_msg'][$rule])) + { + $line = $this->_field_data[$row['field']]['error_msg'][$rule]; + } + elseif ( ! isset($this->_error_messages[$rule])) { if (FALSE === ($line = $this->CI->lang->line('form_validation_'.$rule)) // DEPRECATED support for non-prefixed keys -- cgit v1.2.3-24-g4f1b From 4ea76cc2216b19bfae38dbbfe7104c21ee278d81 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Wed, 8 Jan 2014 21:49:23 +0200 Subject: Fix 2 errors caused by recent commits --- system/libraries/Session/drivers/Session_cookie.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system/libraries') diff --git a/system/libraries/Session/drivers/Session_cookie.php b/system/libraries/Session/drivers/Session_cookie.php index 65debcb44..971dfeabe 100644 --- a/system/libraries/Session/drivers/Session_cookie.php +++ b/system/libraries/Session/drivers/Session_cookie.php @@ -223,7 +223,7 @@ class CI_Session_cookie extends CI_Session_driver { 'encryption_key', ); - $this->_standardize_newlines = (bool) $config['standardize_newlines']; + $this->_standardize_newlines = (bool) config_item('standardize_newlines'); foreach ($prefs as $key) { -- cgit v1.2.3-24-g4f1b From a593e3eb218002a630b7d0cf90002ec4a6fd1db3 Mon Sep 17 00:00:00 2001 From: Marcos SF Filho Date: Wed, 8 Jan 2014 18:22:12 -0200 Subject: Code Corrections for the Calendar Pull Request --- system/libraries/Calendar.php | 39 ++++++++++++++++++--------------------- 1 file changed, 18 insertions(+), 21 deletions(-) (limited to 'system/libraries') diff --git a/system/libraries/Calendar.php b/system/libraries/Calendar.php index a2d9db14b..efaa49a34 100644 --- a/system/libraries/Calendar.php +++ b/system/libraries/Calendar.php @@ -156,7 +156,7 @@ class CI_Calendar { { if (empty($this->next_prev_url)) { - $this->next_prev_url = rtrim($this->CI->config->site_url($this->CI->router->class . '/' . $this->CI->router->method), '/') . '/'; + $this->next_prev_url = rtrim($this->CI->config->site_url($this->CI->router->class.'/'.$this->CI->router->method), '/').'/'; } } } @@ -298,32 +298,29 @@ class CI_Calendar { $out .= ($is_current_month === TRUE && $day == $cur_day) ? $this->temp['cal_cell_end_today'] : $this->temp['cal_cell_end']; } - else + elseif ($this->show_other_days === TRUE) { - if ($this->show_other_days === TRUE) + $out .= $this->temp['cal_cell_start_other']; + + if ($day <= 0) { - $out .= $this->temp['cal_cell_start_other']; - - if ($day <= 0) - { - // Day of previous month - $prev_month = $this->adjust_date(((int) $month) - 1, $year); - $prev_month_days = $this->get_total_days($prev_month['month'], $prev_month['year']); - $out .= str_replace('{day}', $prev_month_days + $day, $this->temp['cal_cell_other']); - } - else - { - // Day of next month - $out .= str_replace('{day}', $day - $total_days, $this->temp['cal_cell_other']); - } - - $out .= $this->temp['cal_cell_end_other']; + // Day of previous month + $prev_month = $this->adjust_date(((int) $month) - 1, $year); + $prev_month_days = $this->get_total_days($prev_month['month'], $prev_month['year']); + $out .= str_replace('{day}', $prev_month_days + $day, $this->temp['cal_cell_other']); } else { - // Blank cells - $out .= $this->temp['cal_cell_start'] . $this->temp['cal_cell_blank'] . $this->temp['cal_cell_end']; + // Day of next month + $out .= str_replace('{day}', $day - $total_days, $this->temp['cal_cell_other']); } + + $out .= $this->temp['cal_cell_end_other']; + } + else + { + // Blank cells + $out .= $this->temp['cal_cell_start'].$this->temp['cal_cell_blank'].$this->temp['cal_cell_end']; } $day++; -- cgit v1.2.3-24-g4f1b From c4f661613eefb6ea15b4109beb61c823d9ec51cc Mon Sep 17 00:00:00 2001 From: Marcos SF Filho Date: Wed, 8 Jan 2014 18:57:09 -0200 Subject: Join two if statement into one --- system/libraries/Calendar.php | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) (limited to 'system/libraries') diff --git a/system/libraries/Calendar.php b/system/libraries/Calendar.php index efaa49a34..e393345df 100644 --- a/system/libraries/Calendar.php +++ b/system/libraries/Calendar.php @@ -152,12 +152,9 @@ class CI_Calendar { } // Set the next_prev_url to the controller if required but not defined - if ($this->show_next_prev === TRUE) + if ($this->show_next_prev === TRUE && empty($this->next_prev_url)) { - if (empty($this->next_prev_url)) - { - $this->next_prev_url = rtrim($this->CI->config->site_url($this->CI->router->class.'/'.$this->CI->router->method), '/').'/'; - } + $this->next_prev_url = rtrim($this->CI->config->site_url($this->CI->router->class.'/'.$this->CI->router->method), '/').'/'; } } -- cgit v1.2.3-24-g4f1b From 0cd7c92ee59b4b03588e45229944d4b83eea3d8e Mon Sep 17 00:00:00 2001 From: Marcos SF Filho Date: Wed, 8 Jan 2014 19:38:00 -0200 Subject: Unnecessary rtrim and update docs for Calendar class --- system/libraries/Calendar.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system/libraries') diff --git a/system/libraries/Calendar.php b/system/libraries/Calendar.php index e393345df..de77e3d7f 100644 --- a/system/libraries/Calendar.php +++ b/system/libraries/Calendar.php @@ -154,7 +154,7 @@ class CI_Calendar { // Set the next_prev_url to the controller if required but not defined if ($this->show_next_prev === TRUE && empty($this->next_prev_url)) { - $this->next_prev_url = rtrim($this->CI->config->site_url($this->CI->router->class.'/'.$this->CI->router->method), '/').'/'; + $this->next_prev_url = $this->CI->config->site_url($this->CI->router->class.'/'.$this->CI->router->method); } } -- cgit v1.2.3-24-g4f1b From 10925d27adac84634cc527d7298b1add0d54ba7c Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Thu, 9 Jan 2014 00:16:46 +0200 Subject: Remove preg_quote() call from CI_User_agent::_set_browser() and add another pattern for Opera Input comes from a configuration file that is barely touched by anyone and the default values only contain letters, so it is safe to not quote them. This enables us to add a more advanced pattern in config/user_agents.php for Opera 10+, which ... quote: Opera/9.80 is hard coded at the beginning of the user agent string because of broken browser sniffing scripts which detect 'Opera/10' and above as Opera 1. (reference: http://my.opera.com/community/openweb/idopera/) Instead, latests versions of Opera append ' Version/' to the end of the user agent string. Fixes issue #555 (incorrect browser detection for Opera) --- system/libraries/User_agent.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system/libraries') diff --git a/system/libraries/User_agent.php b/system/libraries/User_agent.php index 50ac9be98..e13bf8513 100644 --- a/system/libraries/User_agent.php +++ b/system/libraries/User_agent.php @@ -282,7 +282,7 @@ class CI_User_agent { { foreach ($this->browsers as $key => $val) { - if (preg_match('|'.preg_quote($key).'.*?([0-9\.]+)|i', $this->agent, $match)) + if (preg_match('|'.$key.'.*?([0-9\.]+)|i', $this->agent, $match)) { $this->is_browser = TRUE; $this->version = $match[1]; -- cgit v1.2.3-24-g4f1b From 27e91a07ed66308ba02833b104ca8ca6a05e7be8 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Thu, 9 Jan 2014 01:00:48 +0200 Subject: Add CI_User_agent::parse() to allow parsing a custom user-agent string Based on PR #970 --- system/libraries/User_agent.php | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) (limited to 'system/libraries') diff --git a/system/libraries/User_agent.php b/system/libraries/User_agent.php index e13bf8513..3a6b6bc98 100644 --- a/system/libraries/User_agent.php +++ b/system/libraries/User_agent.php @@ -634,6 +634,34 @@ class CI_User_agent { return in_array(strtolower($charset), $this->charsets(), TRUE); } + // -------------------------------------------------------------------- + + /** + * Parse a custom user-agent string + * + * @param string $string + * @return void + */ + public function parse($string) + { + // Reset values + $this->is_browser = FALSE; + $this->is_robot = FALSE; + $this->is_mobile = FALSE; + $this->browser = ''; + $this->version = ''; + $this->mobile = ''; + $this->robot = ''; + + // Set the new user-agent string and parse it, unless empty + $this->agent = $string; + + if ( ! empty($string)) + { + $this->_compile_data(); + } + } + } /* End of file User_agent.php */ -- cgit v1.2.3-24-g4f1b From 0742fad5cb283693bf1ef0a63aa90bb6cb2927d8 Mon Sep 17 00:00:00 2001 From: Ahmedul Haque Abid Date: Thu, 9 Jan 2014 07:51:10 +0600 Subject: Changed $error_msg to $errors --- system/libraries/Form_validation.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'system/libraries') diff --git a/system/libraries/Form_validation.php b/system/libraries/Form_validation.php index e140bc46d..55ef28c80 100644 --- a/system/libraries/Form_validation.php +++ b/system/libraries/Form_validation.php @@ -150,10 +150,10 @@ class CI_Form_validation { * @param mixed $field * @param string $label * @param mixed $rules - * @param array $error_msg + * @param array $errors * @return CI_Form_validation */ - public function set_rules($field, $label = '', $rules = '', $error_msg = array()) + public function set_rules($field, $label = '', $rules = '', $errors = array()) { // No reason to set rules if we have no POST data // or a validation array has not been specified @@ -178,7 +178,7 @@ class CI_Form_validation { $label = isset($row['label']) ? $row['label'] : $row['field']; // Add the custom error message array - $error_msg = (isset($row['error_msg']) && is_array($row['error_msg']) ) ? $row['error_msg'] : array(); + $errors = (isset($row['error_msg']) && is_array($row['error_msg']) ) ? $row['error_msg'] : array(); // Here we go! $this->set_rules($row['field'], $label, $row['rules']); @@ -229,7 +229,7 @@ class CI_Form_validation { 'field' => $field, 'label' => $label, 'rules' => $rules, - 'error_msg' => $error_msg, + 'error_msg' => $errors, 'is_array' => $is_array, 'keys' => $indexes, 'postdata' => NULL, -- cgit v1.2.3-24-g4f1b From bc1cbad058f052e5f5dda85602056c26be94094c Mon Sep 17 00:00:00 2001 From: Ahmedul Haque Abid Date: Thu, 9 Jan 2014 07:53:34 +0600 Subject: Fixed a missed variable $errors in set_rules(). --- system/libraries/Form_validation.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system/libraries') diff --git a/system/libraries/Form_validation.php b/system/libraries/Form_validation.php index 55ef28c80..3ec03ae16 100644 --- a/system/libraries/Form_validation.php +++ b/system/libraries/Form_validation.php @@ -181,7 +181,7 @@ class CI_Form_validation { $errors = (isset($row['error_msg']) && is_array($row['error_msg']) ) ? $row['error_msg'] : array(); // Here we go! - $this->set_rules($row['field'], $label, $row['rules']); + $this->set_rules($row['field'], $label, $row['rules'], $errors); } return $this; -- cgit v1.2.3-24-g4f1b From 557c6ec87c6d83b20d773d2a5fc84b6a6aebd80f Mon Sep 17 00:00:00 2001 From: Ahmedul Haque Abid Date: Thu, 9 Jan 2014 07:55:04 +0600 Subject: Removed extra space between closing parenthesis. --- system/libraries/Form_validation.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system/libraries') diff --git a/system/libraries/Form_validation.php b/system/libraries/Form_validation.php index 3ec03ae16..5c3c7c6e3 100644 --- a/system/libraries/Form_validation.php +++ b/system/libraries/Form_validation.php @@ -178,7 +178,7 @@ class CI_Form_validation { $label = isset($row['label']) ? $row['label'] : $row['field']; // Add the custom error message array - $errors = (isset($row['error_msg']) && is_array($row['error_msg']) ) ? $row['error_msg'] : array(); + $errors = (isset($row['error_msg']) && is_array($row['error_msg'])) ? $row['error_msg'] : array(); // Here we go! $this->set_rules($row['field'], $label, $row['rules'], $errors); -- cgit v1.2.3-24-g4f1b From b07a428a804eaa898b00ec50a8893233229def38 Mon Sep 17 00:00:00 2001 From: Ahmedul Haque Abid Date: Thu, 9 Jan 2014 07:57:27 +0600 Subject: Updated comment messages. --- system/libraries/Form_validation.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'system/libraries') diff --git a/system/libraries/Form_validation.php b/system/libraries/Form_validation.php index 5c3c7c6e3..9efa9f33c 100644 --- a/system/libraries/Form_validation.php +++ b/system/libraries/Form_validation.php @@ -608,7 +608,7 @@ class CI_Form_validation { // Set the message type $type = in_array('required', $rules) ? 'required' : 'isset'; - // Check if a custom message defined, else use default one + // Check if a custom message defined if (isset($this->_field_data[$row['field']]['error_msg'][$type])) { $line = $this->_field_data[$row['field']]['error_msg'][$type]; @@ -757,7 +757,7 @@ class CI_Form_validation { // Did the rule test negatively? If so, grab the error. if ($result === FALSE) { - // Check if a custom message defined, else use default one + // Check if a custom message defined if(isset($this->_field_data[$row['field']]['error_msg'][$rule])) { $line = $this->_field_data[$row['field']]['error_msg'][$rule]; -- cgit v1.2.3-24-g4f1b From e9b0ccc3a686772b5b26c5b6d0ae2f35d48fb4c3 Mon Sep 17 00:00:00 2001 From: Ahmedul Haque Abid Date: Thu, 9 Jan 2014 15:58:51 +0600 Subject: Added the missing "is" in the comment --- system/libraries/Form_validation.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system/libraries') diff --git a/system/libraries/Form_validation.php b/system/libraries/Form_validation.php index 9efa9f33c..2bebd2f9a 100644 --- a/system/libraries/Form_validation.php +++ b/system/libraries/Form_validation.php @@ -608,7 +608,7 @@ class CI_Form_validation { // Set the message type $type = in_array('required', $rules) ? 'required' : 'isset'; - // Check if a custom message defined + // Check if a custom message is defined if (isset($this->_field_data[$row['field']]['error_msg'][$type])) { $line = $this->_field_data[$row['field']]['error_msg'][$type]; -- cgit v1.2.3-24-g4f1b From ea29488b99f28b32887f0cb1e939c5f34e418d0d Mon Sep 17 00:00:00 2001 From: Ahmedul Haque Abid Date: Thu, 9 Jan 2014 16:01:31 +0600 Subject: Changed the rest of 'error_msg' to 'errors' --- system/libraries/Form_validation.php | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'system/libraries') diff --git a/system/libraries/Form_validation.php b/system/libraries/Form_validation.php index 2bebd2f9a..c410e4228 100644 --- a/system/libraries/Form_validation.php +++ b/system/libraries/Form_validation.php @@ -178,7 +178,7 @@ class CI_Form_validation { $label = isset($row['label']) ? $row['label'] : $row['field']; // Add the custom error message array - $errors = (isset($row['error_msg']) && is_array($row['error_msg'])) ? $row['error_msg'] : array(); + $errors = (isset($row['errors']) && is_array($row['errors'])) ? $row['errors'] : array(); // Here we go! $this->set_rules($row['field'], $label, $row['rules'], $errors); @@ -229,7 +229,7 @@ class CI_Form_validation { 'field' => $field, 'label' => $label, 'rules' => $rules, - 'error_msg' => $errors, + 'errors' => $errors, 'is_array' => $is_array, 'keys' => $indexes, 'postdata' => NULL, @@ -609,9 +609,9 @@ class CI_Form_validation { $type = in_array('required', $rules) ? 'required' : 'isset'; // Check if a custom message is defined - if (isset($this->_field_data[$row['field']]['error_msg'][$type])) + if (isset($this->_field_data[$row['field']]['errors'][$type])) { - $line = $this->_field_data[$row['field']]['error_msg'][$type]; + $line = $this->_field_data[$row['field']]['errors'][$type]; } elseif (isset($this->_error_messages[$type])) { @@ -758,9 +758,9 @@ class CI_Form_validation { if ($result === FALSE) { // Check if a custom message defined - if(isset($this->_field_data[$row['field']]['error_msg'][$rule])) + if(isset($this->_field_data[$row['field']]['errors'][$rule])) { - $line = $this->_field_data[$row['field']]['error_msg'][$rule]; + $line = $this->_field_data[$row['field']]['errors'][$rule]; } elseif ( ! isset($this->_error_messages[$rule])) { -- cgit v1.2.3-24-g4f1b From d8a3716f2055cabfcdebd0dcbc96b0783785df32 Mon Sep 17 00:00:00 2001 From: Ahmedul Haque Abid Date: Thu, 9 Jan 2014 16:03:43 +0600 Subject: Added space after 'if' condition --- system/libraries/Form_validation.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system/libraries') diff --git a/system/libraries/Form_validation.php b/system/libraries/Form_validation.php index c410e4228..5be2b5e9d 100644 --- a/system/libraries/Form_validation.php +++ b/system/libraries/Form_validation.php @@ -758,7 +758,7 @@ class CI_Form_validation { if ($result === FALSE) { // Check if a custom message defined - if(isset($this->_field_data[$row['field']]['errors'][$rule])) + if (isset($this->_field_data[$row['field']]['errors'][$rule])) { $line = $this->_field_data[$row['field']]['errors'][$rule]; } -- cgit v1.2.3-24-g4f1b From 7945d30c0c936a553311e7418d388acb4d3fb1af Mon Sep 17 00:00:00 2001 From: Ahmedul Haque Abid Date: Thu, 9 Jan 2014 16:50:23 +0600 Subject: Fixed the comment and array alignment. --- system/libraries/Form_validation.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'system/libraries') diff --git a/system/libraries/Form_validation.php b/system/libraries/Form_validation.php index 5be2b5e9d..58485916c 100644 --- a/system/libraries/Form_validation.php +++ b/system/libraries/Form_validation.php @@ -229,7 +229,7 @@ class CI_Form_validation { 'field' => $field, 'label' => $label, 'rules' => $rules, - 'errors' => $errors, + 'errors' => $errors, 'is_array' => $is_array, 'keys' => $indexes, 'postdata' => NULL, @@ -757,7 +757,7 @@ class CI_Form_validation { // Did the rule test negatively? If so, grab the error. if ($result === FALSE) { - // Check if a custom message defined + // Check if a custom message is defined if (isset($this->_field_data[$row['field']]['errors'][$rule])) { $line = $this->_field_data[$row['field']]['errors'][$rule]; -- cgit v1.2.3-24-g4f1b From 2e914b7dc6acaf2938fac4c332ff682a033b93d7 Mon Sep 17 00:00:00 2001 From: Marcos SF Filho Date: Thu, 9 Jan 2014 09:20:55 -0200 Subject: Updates for the Calendar Pull Request --- system/libraries/Calendar.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system/libraries') diff --git a/system/libraries/Calendar.php b/system/libraries/Calendar.php index de77e3d7f..711d23bec 100644 --- a/system/libraries/Calendar.php +++ b/system/libraries/Calendar.php @@ -302,7 +302,7 @@ class CI_Calendar { if ($day <= 0) { // Day of previous month - $prev_month = $this->adjust_date(((int) $month) - 1, $year); + $prev_month = $this->adjust_date($month - 1, $year); $prev_month_days = $this->get_total_days($prev_month['month'], $prev_month['year']); $out .= str_replace('{day}', $prev_month_days + $day, $this->temp['cal_cell_other']); } -- cgit v1.2.3-24-g4f1b From 43d7fa73534c07d10a88ec120c0938d0d00a184e Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Thu, 9 Jan 2014 17:29:45 +0200 Subject: Implement atomic increment/decrement in Cache library Requested via issue #109 Supersedes PR #241 --- system/libraries/Cache/Cache.php | 39 +++++++- system/libraries/Cache/drivers/Cache_apc.php | 57 +++++++++-- system/libraries/Cache/drivers/Cache_dummy.php | 31 +++++- system/libraries/Cache/drivers/Cache_file.php | 108 ++++++++++++++++----- system/libraries/Cache/drivers/Cache_memcached.php | 54 +++++++++-- system/libraries/Cache/drivers/Cache_redis.php | 49 ++++++++-- system/libraries/Cache/drivers/Cache_wincache.php | 47 +++++++-- 7 files changed, 324 insertions(+), 61 deletions(-) (limited to 'system/libraries') diff --git a/system/libraries/Cache/Cache.php b/system/libraries/Cache/Cache.php index 537897eaf..2dffa350c 100644 --- a/system/libraries/Cache/Cache.php +++ b/system/libraries/Cache/Cache.php @@ -150,14 +150,15 @@ class CI_Cache extends CI_Driver_Library { /** * Cache Save * - * @param string $id Cache ID - * @param mixed $data Data to store - * @param int $ttl = 60 Cache TTL (in seconds) + * @param string $id Cache ID + * @param mixed $data Data to store + * @param int $ttl Cache TTL (in seconds) + * @param bool $raw Whether to store the raw value * @return bool TRUE on success, FALSE on failure */ - public function save($id, $data, $ttl = 60) + public function save($id, $data, $ttl = 60, $raw = FALSE) { - return $this->{$this->_adapter}->save($this->key_prefix.$id, $data, $ttl); + return $this->{$this->_adapter}->save($this->key_prefix.$id, $data, $ttl, $raw); } // ------------------------------------------------------------------------ @@ -175,6 +176,34 @@ class CI_Cache extends CI_Driver_Library { // ------------------------------------------------------------------------ + /** + * Increment a raw value + * + * @param string $id Cache ID + * @param int $offset Step/value to add + * @return mixed New value on success or FALSE on failure + */ + public function increment($id, $offset = 1) + { + return $this->{$this->_adapter}->increment($id, $offset); + } + + // ------------------------------------------------------------------------ + + /** + * Decrement a raw value + * + * @param string $id Cache ID + * @param int $offset Step/value to reduce by + * @return mixed New value on success or FALSE on failure + */ + public function decrement($id, $offset = 1) + { + return $this->{$this->_adapter}->decrement($id, $offset); + } + + // ------------------------------------------------------------------------ + /** * Clean the cache * diff --git a/system/libraries/Cache/drivers/Cache_apc.php b/system/libraries/Cache/drivers/Cache_apc.php index a84e7d2d3..b5381ddaf 100644 --- a/system/libraries/Cache/drivers/Cache_apc.php +++ b/system/libraries/Cache/drivers/Cache_apc.php @@ -51,8 +51,14 @@ class CI_Cache_apc extends CI_Driver { $success = FALSE; $data = apc_fetch($id, $success); - return ($success === TRUE && is_array($data)) - ? unserialize($data[0]) : FALSE; + if ($success === TRUE) + { + return is_array($data) + ? unserialize($data[0]) + : $data; + } + + return FALSE; } // ------------------------------------------------------------------------ @@ -60,16 +66,21 @@ 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 - * - * @return bool true on success/false on failure + * @param string $id Cache ID + * @param mixed $data Data to store + * @param int $ttol Length of time (in seconds) to cache the data + * @param bool $raw Whether to store the raw value + * @return bool TRUE on success, FALSE on failure */ - public function save($id, $data, $ttl = 60) + public function save($id, $data, $ttl = 60, $raw = FALSE) { $ttl = (int) $ttl; - return apc_store($id, array(serialize($data), time(), $ttl), $ttl); + + return apc_store( + $id, + ($raw === TRUE ? $data : array(serialize($data), time(), $ttl)), + $ttl + ); } // ------------------------------------------------------------------------ @@ -87,6 +98,34 @@ class CI_Cache_apc extends CI_Driver { // ------------------------------------------------------------------------ + /** + * Increment a raw value + * + * @param string $id Cache ID + * @param int $offset Step/value to add + * @return mixed New value on success or FALSE on failure + */ + public function increment($id, $offset = 1) + { + return apc_inc($id, $offset); + } + + // ------------------------------------------------------------------------ + + /** + * Decrement a raw value + * + * @param string $id Cache ID + * @param int $offset Step/value to reduce by + * @return mixed New value on success or FALSE on failure + */ + public function decrement($id, $offset = 1) + { + return apc_dec($id, $offset); + } + + // ------------------------------------------------------------------------ + /** * Clean the cache * diff --git a/system/libraries/Cache/drivers/Cache_dummy.php b/system/libraries/Cache/drivers/Cache_dummy.php index d9af3773b..7e2b907a6 100644 --- a/system/libraries/Cache/drivers/Cache_dummy.php +++ b/system/libraries/Cache/drivers/Cache_dummy.php @@ -58,9 +58,10 @@ class CI_Cache_dummy extends CI_Driver { * @param string Unique Key * @param mixed Data to store * @param int Length of time (in seconds) to cache the data + * @param bool Whether to store the raw value * @return bool TRUE, Simulating success */ - public function save($id, $data, $ttl = 60) + public function save($id, $data, $ttl = 60, $raw = FALSE) { return TRUE; } @@ -80,6 +81,34 @@ class CI_Cache_dummy extends CI_Driver { // ------------------------------------------------------------------------ + /** + * Increment a raw value + * + * @param string $id Cache ID + * @param int $offset Step/value to add + * @return mixed New value on success or FALSE on failure + */ + public function increment($id, $offset = 1) + { + return TRUE; + } + + // ------------------------------------------------------------------------ + + /** + * Decrement a raw value + * + * @param string $id Cache ID + * @param int $offset Step/value to reduce by + * @return mixed New value on success or FALSE on failure + */ + public function decrement($id, $offset = 1) + { + return TRUE; + } + + // ------------------------------------------------------------------------ + /** * Clean the cache * diff --git a/system/libraries/Cache/drivers/Cache_file.php b/system/libraries/Cache/drivers/Cache_file.php index 769bd5a26..8c99c5ef3 100644 --- a/system/libraries/Cache/drivers/Cache_file.php +++ b/system/libraries/Cache/drivers/Cache_file.php @@ -62,25 +62,13 @@ class CI_Cache_file extends CI_Driver { /** * Fetch from cache * - * @param mixed unique key id - * @return mixed data on success/false on failure + * @param string $id Cache ID + * @return mixed Data on success, FALSE on failure */ public function get($id) { - if ( ! file_exists($this->_cache_path.$id)) - { - return FALSE; - } - - $data = unserialize(file_get_contents($this->_cache_path.$id)); - - if ($data['ttl'] > 0 && time() > $data['time'] + $data['ttl']) - { - unlink($this->_cache_path.$id); - return FALSE; - } - - return $data['data']; + $data = $this->_get($id); + return is_array($data) ? $data['data'] : FALSE; } // ------------------------------------------------------------------------ @@ -88,13 +76,13 @@ 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 bool true on success/false on failure + * @param string $id Cache ID + * @param mixed $data Data to store + * @param int $ttl Time to live in seconds + * @param bool $raw Whether to store the raw value (unused) + * @return bool TRUE on success, FALSE on failure */ - public function save($id, $data, $ttl = 60) + public function save($id, $data, $ttl = 60, $raw = FALSE) { $contents = array( 'time' => time(), @@ -126,6 +114,54 @@ class CI_Cache_file extends CI_Driver { // ------------------------------------------------------------------------ + /** + * Increment a raw value + * + * @param string $id Cache ID + * @param int $offset Step/value to add + * @return New value on success, FALSE on failure + */ + public function increment($id, $offset = 1) + { + $data = $this->_get($id); + + if ($data === FALSE OR ! is_int($data['data'])) + { + return FALSE; + } + + $new_value = $data['data'] + $offset; + return $this->save($id, $new_value, $data['ttl']) + ? $new_value + : FALSE; + } + + // ------------------------------------------------------------------------ + + /** + * Decrement a raw value + * + * @param string $id Cache ID + * @param int $offset Step/value to reduce by + * @return New value on success, FALSE on failure + */ + public function decrement($id, $offset = 1) + { + $data = $this->_get($id); + + if ($data === FALSE OR ! is_int($data['data'])) + { + return FALSE; + } + + $new_value = $data['data'] - $offset; + return $this->save($id, $new_value, $data['ttl']) + ? $new_value + : FALSE; + } + + // ------------------------------------------------------------------------ + /** * Clean the Cache * @@ -200,6 +236,34 @@ class CI_Cache_file extends CI_Driver { return is_really_writable($this->_cache_path); } + // ------------------------------------------------------------------------ + + /** + * Get all data + * + * Internal method to get all the relevant data about a cache item + * + * @param string $id Cache ID + * @return mixed Data array on success or FALSE on failure + */ + protected function _get($id) + { + if ( ! file_exists($this->_cache_path.$id)) + { + return FALSE; + } + + $data = unserialize(file_get_contents($this->_cache_path.$id)); + + if ($data['ttl'] > 0 && time() > $data['time'] + $data['ttl']) + { + unlink($this->_cache_path.$id); + return FALSE; + } + + return $data; + } + } /* End of file Cache_file.php */ diff --git a/system/libraries/Cache/drivers/Cache_memcached.php b/system/libraries/Cache/drivers/Cache_memcached.php index d2a3a489d..886357e57 100644 --- a/system/libraries/Cache/drivers/Cache_memcached.php +++ b/system/libraries/Cache/drivers/Cache_memcached.php @@ -60,14 +60,14 @@ class CI_Cache_memcached extends CI_Driver { /** * Fetch from cache * - * @param mixed unique key id - * @return mixed data on success/false on failure + * @param string $id Cache ID + * @return mixed Data on success, FALSE on failure */ public function get($id) { $data = $this->_memcached->get($id); - return is_array($data) ? $data[0] : FALSE; + return is_array($data) ? $data[0] : $data; } // ------------------------------------------------------------------------ @@ -75,20 +75,26 @@ class CI_Cache_memcached extends CI_Driver { /** * Save * - * @param string unique identifier - * @param mixed data being cached - * @param int time to live - * @return bool true on success, false on failure + * @param string $id Cache ID + * @param mixed $data Data being cached + * @param int $ttl Time to live + * @param bool $raw Whether to store the raw value + * @return bool TRUE on success, FALSE on failure */ - public function save($id, $data, $ttl = 60) + public function save($id, $data, $ttl = 60, $raw = FALSE) { + if ($raw !== TRUE) + { + $data = array($data, time, $ttl); + } + if (get_class($this->_memcached) === 'Memcached') { - return $this->_memcached->set($id, array($data, time(), $ttl), $ttl); + return $this->_memcached->set($id, $data, $ttl); } elseif (get_class($this->_memcached) === 'Memcache') { - return $this->_memcached->set($id, array($data, time(), $ttl), 0, $ttl); + return $this->_memcached->set($id, $data, 0, $ttl); } return FALSE; @@ -109,6 +115,34 @@ class CI_Cache_memcached extends CI_Driver { // ------------------------------------------------------------------------ + /** + * Increment a raw value + * + * @param string $id Cache ID + * @param int $offset Step/value to add + * @return mixed New value on success or FALSE on failure + */ + public function increment($id, $offset = 1) + { + return $this->_memcached->increment($id, $offset); + } + + // ------------------------------------------------------------------------ + + /** + * Decrement a raw value + * + * @param string $id Cache ID + * @param int $offset Step/value to reduce by + * @return mixed New value on success or FALSE on failure + */ + public function decrement($id, $offset = 1) + { + return $this->_memcached->decrement($id, $offset); + } + + // ------------------------------------------------------------------------ + /** * Clean the Cache * diff --git a/system/libraries/Cache/drivers/Cache_redis.php b/system/libraries/Cache/drivers/Cache_redis.php index 48c803d7e..b6fddf035 100644 --- a/system/libraries/Cache/drivers/Cache_redis.php +++ b/system/libraries/Cache/drivers/Cache_redis.php @@ -63,7 +63,7 @@ class CI_Cache_redis extends CI_Driver /** * Get cache * - * @param string Cache key identifier + * @param string Cache ID * @return mixed */ public function get($key) @@ -76,16 +76,17 @@ class CI_Cache_redis extends CI_Driver /** * Save cache * - * @param string Cache key identifier - * @param mixed Data to save - * @param int Time to live - * @return bool + * @param string $id Cache ID + * @param mixed $data Data to save + * @param int $ttl Time to live in seconds + * @param bool $raw Whether to store the raw value (unused) + * @return bool TRUE on success, FALSE on failure */ - public function save($key, $value, $ttl = NULL) + public function save($id, $data, $ttl = 60, $raw = FALSE) { return ($ttl) - ? $this->_redis->setex($key, $ttl, $value) - : $this->_redis->set($key, $value); + ? $this->_redis->setex($id, $ttl, $data) + : $this->_redis->set($id, $data); } // ------------------------------------------------------------------------ @@ -103,6 +104,38 @@ class CI_Cache_redis extends CI_Driver // ------------------------------------------------------------------------ + /** + * Increment a raw value + * + * @param string $id Cache ID + * @param int $offset Step/value to add + * @return mixed New value on success or FALSE on failure + */ + public function increment($id, $offset = 1) + { + return $this->_redis->exists($id) + ? $this->_redis->incr($id, $offset) + : FALSE; + } + + // ------------------------------------------------------------------------ + + /** + * Decrement a raw value + * + * @param string $id Cache ID + * @param int $offset Step/value to reduce by + * @return mixed New value on success or FALSE on failure + */ + public function decrement($id, $offset = 1) + { + return $this->_redis->exists($id) + ? $this->_redis->decr($id, $offset) + : FALSE; + } + + // ------------------------------------------------------------------------ + /** * Clean cache * diff --git a/system/libraries/Cache/drivers/Cache_wincache.php b/system/libraries/Cache/drivers/Cache_wincache.php index 80d3ac13d..25c18ab58 100644 --- a/system/libraries/Cache/drivers/Cache_wincache.php +++ b/system/libraries/Cache/drivers/Cache_wincache.php @@ -46,8 +46,8 @@ class CI_Cache_wincache extends CI_Driver { * 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 $id Cache Ide + * @return mixed Value that is stored/FALSE on failure */ public function get($id) { @@ -63,12 +63,13 @@ class CI_Cache_wincache 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 $id Cache ID + * @param mixed $data Data to store + * @param int $ttl Time to live (in seconds) + * @param bool $raw Whether to store the raw value (unused) * @return bool true on success/false on failure */ - public function save($id, $data, $ttl = 60) + public function save($id, $data, $ttl = 60, $raw = FALSE) { return wincache_ucache_set($id, $data, $ttl); } @@ -88,6 +89,40 @@ class CI_Cache_wincache extends CI_Driver { // ------------------------------------------------------------------------ + /** + * Increment a raw value + * + * @param string $id Cache ID + * @param int $offset Step/value to add + * @return mixed New value on success or FALSE on failure + */ + public function increment($id, $offset = 1) + { + $success = FALSE; + $value = wincache_ucache_inc($id, $offset, $success); + + return ($success === TRUE) ? $value : FALSE; + } + + // ------------------------------------------------------------------------ + + /** + * Decrement a raw value + * + * @param string $id Cache ID + * @param int $offset Step/value to reduce by + * @return mixed New value on success or FALSE on failure + */ + public function decrement($id, $offset = 1) + { + $success = FALSE; + $value = wincache_ucache_dec($id, $offset, $success); + + return ($success === TRUE) ? $value : FALSE; + } + + // ------------------------------------------------------------------------ + /** * Clean the cache * -- cgit v1.2.3-24-g4f1b From 300e3f04404e771de89351e410699e447759175a Mon Sep 17 00:00:00 2001 From: Petr Heralecky Date: Fri, 10 Jan 2014 11:49:11 +0100 Subject: Added Email::attach_cid() returning CID --- system/libraries/Email.php | 87 +++++++++++++++++++++++++++++----------------- 1 file changed, 55 insertions(+), 32 deletions(-) (limited to 'system/libraries') diff --git a/system/libraries/Email.php b/system/libraries/Email.php index efdbfd7c1..b84518bbd 100644 --- a/system/libraries/Email.php +++ b/system/libraries/Email.php @@ -718,14 +718,63 @@ class CI_Email { */ public function attach($filename, $disposition = '', $newname = NULL, $mime = '') { + if ($mime === '') + { + if ( ! file_exists($filename)) + { + $this->_set_error_message('lang:email_attachment_missing', $filename); + return FALSE; + } + + if ( ! $fp = fopen($filename, FOPEN_READ)) + { + $this->_set_error_message('lang:email_attachment_unreadable', $filename); + return FALSE; + } + $file_content = stream_get_contents($fp); + $mime = $this->_mime_types(pathinfo($filename, PATHINFO_EXTENSION)); + } + else + { + $file_content =& $filename; // buffered file + } + $this->_attachments[] = array( 'name' => array($filename, $newname), 'disposition' => empty($disposition) ? 'attachment' : $disposition, // Can also be 'inline' Not sure if it matters - 'type' => $mime + 'type' => $mime, + 'content' => chunk_split(base64_encode($file_content)) ); - + + fclose($fp); + return $this; } + + // -------------------------------------------------------------------- + + /** + * Sets and return id of attachment (useful for attached inline pictures) + * + * @param string + * @return string + */ + public function attach_cid($filename) + { + if($this->multipart != 'related') + { + $this->multipart = 'related'; // Thunderbird need this for inline images + } + foreach($this->_attachments as $ind => $attach) + { + if($attach['name'][0] == $filename) + { + $this->_attachments[$ind]['cid'] = uniqid(basename($this->_attachments[$ind]['name'][0]) . "@"); + return $this->_attachments[$ind]['cid']; + } + } + return FALSE; + } // -------------------------------------------------------------------- @@ -1361,41 +1410,15 @@ class CI_Email { $filename = $this->_attachments[$i]['name'][0]; $basename = ($this->_attachments[$i]['name'][1] === NULL) ? basename($filename) : $this->_attachments[$i]['name'][1]; - $ctype = $this->_attachments[$i]['type']; - $file_content = ''; - - if ($ctype === '') - { - 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->_attachments[$i]['name'][0]; - } $attachment[$z++] = '--'.$this->_atc_boundary.$this->newline - .'Content-type: '.$ctype.'; ' + .'Content-type: '.$this->_attachments[$i]['type'].'; ' .'name="'.$basename.'"'.$this->newline .'Content-Disposition: '.$this->_attachments[$i]['disposition'].';'.$this->newline - .'Content-Transfer-Encoding: base64'.$this->newline; + .'Content-Transfer-Encoding: base64'.$this->newline + .(!empty($this->_attachments[$i]['cid']) ? "Content-ID: <".$this->_attachments[$i]['cid'].">".$this->newline : ''); - $attachment[$z++] = chunk_split(base64_encode($file_content)); + $attachment[$z++] = $this->_attachments[$i]['content']; } $body .= implode($this->newline, $attachment).$this->newline.'--'.$this->_atc_boundary.'--'; -- cgit v1.2.3-24-g4f1b From de88615b7245f00d086d97a9fb5ea8b307d34c4f Mon Sep 17 00:00:00 2001 From: Petr Heralecky Date: Fri, 10 Jan 2014 12:52:56 +0100 Subject: styleguided --- system/libraries/Email.php | 26 ++++++++++++++++---------- 1 file changed, 16 insertions(+), 10 deletions(-) (limited to 'system/libraries') diff --git a/system/libraries/Email.php b/system/libraries/Email.php index b84518bbd..20eac72fc 100644 --- a/system/libraries/Email.php +++ b/system/libraries/Email.php @@ -731,8 +731,10 @@ class CI_Email { $this->_set_error_message('lang:email_attachment_unreadable', $filename); return FALSE; } + $file_content = stream_get_contents($fp); $mime = $this->_mime_types(pathinfo($filename, PATHINFO_EXTENSION)); + fclose($fp); } else { @@ -746,7 +748,7 @@ class CI_Email { 'content' => chunk_split(base64_encode($file_content)) ); - fclose($fp); + return $this; } @@ -754,25 +756,29 @@ class CI_Email { // -------------------------------------------------------------------- /** - * Sets and return id of attachment (useful for attached inline pictures) + * Set and return id of attachment + * + * useful for attached inline pictures * - * @param string - * @return string + * @param string $filename + * @return string */ public function attach_cid($filename) { - if($this->multipart != 'related') + if ($this->multipart !== 'related') { $this->multipart = 'related'; // Thunderbird need this for inline images } - foreach($this->_attachments as $ind => $attach) + + for ($i = 0, $c = count($this->_attachments); $i < $c; $i++) { - if($attach['name'][0] == $filename) + if ($attach['name'][0] === $filename) { - $this->_attachments[$ind]['cid'] = uniqid(basename($this->_attachments[$ind]['name'][0]) . "@"); - return $this->_attachments[$ind]['cid']; + $this->_attachments[$ind]['cid'] = uniqid(basename($this->_attachments[$i]['name'][0]).'@'); + return $this->_attachments[$i]['cid']; } } + return FALSE; } @@ -1416,7 +1422,7 @@ class CI_Email { .'name="'.$basename.'"'.$this->newline .'Content-Disposition: '.$this->_attachments[$i]['disposition'].';'.$this->newline .'Content-Transfer-Encoding: base64'.$this->newline - .(!empty($this->_attachments[$i]['cid']) ? "Content-ID: <".$this->_attachments[$i]['cid'].">".$this->newline : ''); + .(empty($this->_attachments[$i]['cid']) ? '' : 'Content-ID: <'.$this->_attachments[$i]['cid'].'>'.$this->newline); $attachment[$z++] = $this->_attachments[$i]['content']; } -- cgit v1.2.3-24-g4f1b From 230fca38f3f7481686d9d9c2989ad7d0a1a4874f Mon Sep 17 00:00:00 2001 From: Petr Heralecky Date: Fri, 10 Jan 2014 12:55:57 +0100 Subject: styleguided 2 --- system/libraries/Email.php | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) (limited to 'system/libraries') diff --git a/system/libraries/Email.php b/system/libraries/Email.php index 20eac72fc..01dbfbe19 100644 --- a/system/libraries/Email.php +++ b/system/libraries/Email.php @@ -748,8 +748,6 @@ class CI_Email { 'content' => chunk_split(base64_encode($file_content)) ); - - return $this; } @@ -774,7 +772,7 @@ class CI_Email { { if ($attach['name'][0] === $filename) { - $this->_attachments[$ind]['cid'] = uniqid(basename($this->_attachments[$i]['name'][0]).'@'); + $this->_attachments[$i]['cid'] = uniqid(basename($this->_attachments[$i]['name'][0]).'@'); return $this->_attachments[$i]['cid']; } } -- cgit v1.2.3-24-g4f1b From 9ad2fff4492e1e216aad0b03714ddfcb7a06d697 Mon Sep 17 00:00:00 2001 From: Petr Heralecky Date: Fri, 10 Jan 2014 13:25:34 +0100 Subject: variable repair --- system/libraries/Email.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'system/libraries') diff --git a/system/libraries/Email.php b/system/libraries/Email.php index 01dbfbe19..a41884f7d 100644 --- a/system/libraries/Email.php +++ b/system/libraries/Email.php @@ -747,7 +747,7 @@ class CI_Email { 'type' => $mime, 'content' => chunk_split(base64_encode($file_content)) ); - + return $this; } @@ -770,7 +770,7 @@ class CI_Email { for ($i = 0, $c = count($this->_attachments); $i < $c; $i++) { - if ($attach['name'][0] === $filename) + if ($this->_attachments[$i]['name'][0] === $filename) { $this->_attachments[$i]['cid'] = uniqid(basename($this->_attachments[$i]['name'][0]).'@'); return $this->_attachments[$i]['cid']; -- cgit v1.2.3-24-g4f1b From c809726558cc5364713e49c7404e43989203c4af Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Fri, 10 Jan 2014 14:45:31 +0200 Subject: Further changes related to PR #2807 --- system/libraries/Email.php | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) (limited to 'system/libraries') diff --git a/system/libraries/Email.php b/system/libraries/Email.php index a41884f7d..739b76ccb 100644 --- a/system/libraries/Email.php +++ b/system/libraries/Email.php @@ -725,13 +725,13 @@ class CI_Email { $this->_set_error_message('lang:email_attachment_missing', $filename); return FALSE; } - + if ( ! $fp = fopen($filename, FOPEN_READ)) { $this->_set_error_message('lang:email_attachment_unreadable', $filename); return FALSE; } - + $file_content = stream_get_contents($fp); $mime = $this->_mime_types(pathinfo($filename, PATHINFO_EXTENSION)); fclose($fp); @@ -740,7 +740,7 @@ class CI_Email { { $file_content =& $filename; // buffered file } - + $this->_attachments[] = array( 'name' => array($filename, $newname), 'disposition' => empty($disposition) ? 'attachment' : $disposition, // Can also be 'inline' Not sure if it matters @@ -750,24 +750,24 @@ class CI_Email { return $this; } - + // -------------------------------------------------------------------- - + /** - * Set and return id of attachment - * - * useful for attached inline pictures + * Set and return attachment Content-ID + * + * Useful for attached inline pictures * * @param string $filename * @return string */ - public function attach_cid($filename) + public function attachment_cid($filename) { if ($this->multipart !== 'related') { $this->multipart = 'related'; // Thunderbird need this for inline images } - + for ($i = 0, $c = count($this->_attachments); $i < $c; $i++) { if ($this->_attachments[$i]['name'][0] === $filename) @@ -776,7 +776,7 @@ class CI_Email { return $this->_attachments[$i]['cid']; } } - + return FALSE; } @@ -1429,6 +1429,7 @@ class CI_Email { $this->_finalbody = ($this->_get_protocol() === 'mail') ? $body : $hdr.$this->newline.$this->newline.$body; + return TRUE; } -- cgit v1.2.3-24-g4f1b From 232ea658e1f31d6c82a9ed9dae1bb3b292b6eb24 Mon Sep 17 00:00:00 2001 From: Petr Heralecky Date: Fri, 10 Jan 2014 15:21:18 +0100 Subject: attach files by absolute url --- system/libraries/Email.php | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) (limited to 'system/libraries') diff --git a/system/libraries/Email.php b/system/libraries/Email.php index 739b76ccb..71edc3b41 100644 --- a/system/libraries/Email.php +++ b/system/libraries/Email.php @@ -710,39 +710,39 @@ class CI_Email { /** * Assign file attachments * - * @param string $filename + * @param string $src can be path, url or buffered content * @param string $disposition = 'attachment' * @param string $newname = NULL * @param string $mime = '' * @return CI_Email */ - public function attach($filename, $disposition = '', $newname = NULL, $mime = '') + public function attach($src, $disposition = '', $newname = NULL, $mime = '') { if ($mime === '') { - if ( ! file_exists($filename)) + if (strpos($src,'http://')!==0 && ! file_exists($src) ) { - $this->_set_error_message('lang:email_attachment_missing', $filename); + $this->_set_error_message('lang:email_attachment_missing', $src); return FALSE; } - if ( ! $fp = fopen($filename, FOPEN_READ)) + if ( ! $fp = @fopen($src, FOPEN_READ)) { - $this->_set_error_message('lang:email_attachment_unreadable', $filename); + $this->_set_error_message('lang:email_attachment_unreadable', $src); return FALSE; } - + $file_content = stream_get_contents($fp); - $mime = $this->_mime_types(pathinfo($filename, PATHINFO_EXTENSION)); + $mime = $this->_mime_types(pathinfo($src, PATHINFO_EXTENSION)); fclose($fp); } else { - $file_content =& $filename; // buffered file + $file_content =& $src; // buffered file } $this->_attachments[] = array( - 'name' => array($filename, $newname), + 'name' => array($src, $newname), 'disposition' => empty($disposition) ? 'attachment' : $disposition, // Can also be 'inline' Not sure if it matters 'type' => $mime, 'content' => chunk_split(base64_encode($file_content)) -- cgit v1.2.3-24-g4f1b From ceb03af631c145d0694ef6f72e84517e18b7b092 Mon Sep 17 00:00:00 2001 From: Petr Heralecky Date: Fri, 10 Jan 2014 16:40:54 +0100 Subject: rename src to file --- system/libraries/Email.php | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) (limited to 'system/libraries') diff --git a/system/libraries/Email.php b/system/libraries/Email.php index 71edc3b41..37a628259 100644 --- a/system/libraries/Email.php +++ b/system/libraries/Email.php @@ -710,39 +710,39 @@ class CI_Email { /** * Assign file attachments * - * @param string $src can be path, url or buffered content + * @param string $file can be path, url or buffered content * @param string $disposition = 'attachment' * @param string $newname = NULL * @param string $mime = '' * @return CI_Email */ - public function attach($src, $disposition = '', $newname = NULL, $mime = '') + public function attach($file, $disposition = '', $newname = NULL, $mime = '') { if ($mime === '') { - if (strpos($src,'http://')!==0 && ! file_exists($src) ) + if (strpos($file,'http://')!==0 && ! file_exists($file) ) { - $this->_set_error_message('lang:email_attachment_missing', $src); + $this->_set_error_message('lang:email_attachment_missing', $file); return FALSE; } - if ( ! $fp = @fopen($src, FOPEN_READ)) + if ( ! $fp = @fopen($file, FOPEN_READ)) { - $this->_set_error_message('lang:email_attachment_unreadable', $src); + $this->_set_error_message('lang:email_attachment_unreadable', $file); return FALSE; } $file_content = stream_get_contents($fp); - $mime = $this->_mime_types(pathinfo($src, PATHINFO_EXTENSION)); + $mime = $this->_mime_types(pathinfo($file, PATHINFO_EXTENSION)); fclose($fp); } else { - $file_content =& $src; // buffered file + $file_content =& $file; // buffered file } $this->_attachments[] = array( - 'name' => array($src, $newname), + 'name' => array($file, $newname), 'disposition' => empty($disposition) ? 'attachment' : $disposition, // Can also be 'inline' Not sure if it matters 'type' => $mime, 'content' => chunk_split(base64_encode($file_content)) -- cgit v1.2.3-24-g4f1b From 1dbdf72c555d0ea4d7c526e56e79472331eedc2a Mon Sep 17 00:00:00 2001 From: Petr Heralecky Date: Fri, 10 Jan 2014 16:54:51 +0100 Subject: condition repair and comments --- system/libraries/Email.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'system/libraries') diff --git a/system/libraries/Email.php b/system/libraries/Email.php index 37a628259..7e80ffbca 100644 --- a/system/libraries/Email.php +++ b/system/libraries/Email.php @@ -710,7 +710,7 @@ class CI_Email { /** * Assign file attachments * - * @param string $file can be path, url or buffered content + * @param string $file Can be local path, URL or buffered content * @param string $disposition = 'attachment' * @param string $newname = NULL * @param string $mime = '' @@ -720,7 +720,7 @@ class CI_Email { { if ($mime === '') { - if (strpos($file,'http://')!==0 && ! file_exists($file) ) + if (strpos($file, '://') === FALSE && ! file_exists($file)) { $this->_set_error_message('lang:email_attachment_missing', $file); return FALSE; @@ -731,7 +731,7 @@ class CI_Email { $this->_set_error_message('lang:email_attachment_unreadable', $file); return FALSE; } - + $file_content = stream_get_contents($fp); $mime = $this->_mime_types(pathinfo($file, PATHINFO_EXTENSION)); fclose($fp); -- cgit v1.2.3-24-g4f1b From 3d215207ceff44193e3c1888b868fc3f691718c0 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Wed, 15 Jan 2014 11:08:47 +0200 Subject: Fix incorrect checks for the fwrite() return value ! fwrite() could trigger false-positives as it is possible for it to return 0 instead of boolean FALSE. (issue #2822) Also removed an unnecessary log level check that caused an extra space to be inserted for the INFO level. (proposed in PR #2821) --- system/libraries/Email.php | 2 +- system/libraries/Xmlrpc.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'system/libraries') diff --git a/system/libraries/Email.php b/system/libraries/Email.php index 7e80ffbca..9487ad486 100644 --- a/system/libraries/Email.php +++ b/system/libraries/Email.php @@ -2097,7 +2097,7 @@ class CI_Email { */ protected function _send_data($data) { - if ( ! fwrite($this->_smtp_connect, $data.$this->newline)) + if (fwrite($this->_smtp_connect, $data.$this->newline) === FALSE) { $this->_set_error_message('lang:email_smtp_data_failure', $data); return FALSE; diff --git a/system/libraries/Xmlrpc.php b/system/libraries/Xmlrpc.php index 2fd12599e..1f93e6981 100644 --- a/system/libraries/Xmlrpc.php +++ b/system/libraries/Xmlrpc.php @@ -724,7 +724,7 @@ class XML_RPC_Client extends CI_Xmlrpc .'Content-Length: '.strlen($msg->payload).$r.$r .$msg->payload; - if ( ! fwrite($fp, $op, strlen($op))) + if (fwrite($fp, $op, strlen($op)) === FALSE) { error_log($this->xmlrpcstr['http_error']); return new XML_RPC_Response(0, $this->xmlrpcerr['http_error'], $this->xmlrpcstr['http_error']); -- cgit v1.2.3-24-g4f1b From d8b1ad31cf7ee205ddf3cf396b1d1bfa45af49fa Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Wed, 15 Jan 2014 17:42:52 +0200 Subject: Fix #2822: Incorrect usage of fwrite() We only used to check (and not always) if the return value of fwrite() is boolean FALSE, while it is possible that the otherwise returned bytecount is less than the length of data that we're trying to write. This allowed incomplete writes over network streams and possibly a few other edge cases. --- system/libraries/Email.php | 11 ++++++++++- system/libraries/Xmlrpc.php | 10 +++++++++- system/libraries/Zip.php | 12 ++++++++++-- 3 files changed, 29 insertions(+), 4 deletions(-) (limited to 'system/libraries') diff --git a/system/libraries/Email.php b/system/libraries/Email.php index 9487ad486..f4efff882 100644 --- a/system/libraries/Email.php +++ b/system/libraries/Email.php @@ -2097,7 +2097,16 @@ class CI_Email { */ protected function _send_data($data) { - if (fwrite($this->_smtp_connect, $data.$this->newline) === FALSE) + $data .= $this->newline; + for ($written = 0, $length = strlen($data); $written < $length; $written += $result) + { + if (($result = fwrite($this->_smtp_connect, substr($data, $written))) === FALSE) + { + break; + } + } + + if ($result === FALSE) { $this->_set_error_message('lang:email_smtp_data_failure', $data); return FALSE; diff --git a/system/libraries/Xmlrpc.php b/system/libraries/Xmlrpc.php index 1f93e6981..ab907e706 100644 --- a/system/libraries/Xmlrpc.php +++ b/system/libraries/Xmlrpc.php @@ -724,7 +724,15 @@ class XML_RPC_Client extends CI_Xmlrpc .'Content-Length: '.strlen($msg->payload).$r.$r .$msg->payload; - if (fwrite($fp, $op, strlen($op)) === FALSE) + for ($written = 0, $length = strlen($op); $written < $length; $written += $result) + { + if (($result = fwrite($fp, substr($op, $written))) === FALSE) + { + break; + } + } + + if ($result === FALSE) { error_log($this->xmlrpcstr['http_error']); return new XML_RPC_Response(0, $this->xmlrpcerr['http_error'], $this->xmlrpcstr['http_error']); diff --git a/system/libraries/Zip.php b/system/libraries/Zip.php index 250ee02cd..b10b0bb0f 100644 --- a/system/libraries/Zip.php +++ b/system/libraries/Zip.php @@ -403,11 +403,19 @@ class CI_Zip { } flock($fp, LOCK_EX); - fwrite($fp, $this->get_zip()); + + for ($written = 0, $data = $this->get_zip(), $length = strlen($data); $written < $length; $written += $result) + { + if (($result = fwrite($fp, substr($data, $written))) === FALSE) + { + break; + } + } + flock($fp, LOCK_UN); fclose($fp); - return TRUE; + return is_int($result); } // -------------------------------------------------------------------- -- cgit v1.2.3-24-g4f1b From a9938a09e8214b778b8ab11f60501661bb2ac623 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Fri, 17 Jan 2014 14:55:56 +0200 Subject: Minor changes related to CI_User_agent Fixed a bug where both accept_charset() and accept_lang() improperly parsed headers if they contained spaces between data separators (which is valid). Also made is_referral() testable by replacing its static cache var with a class property and added some more unit tests for the library as a whole. --- system/libraries/User_agent.php | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) (limited to 'system/libraries') diff --git a/system/libraries/User_agent.php b/system/libraries/User_agent.php index 3a6b6bc98..1dfa3e72d 100644 --- a/system/libraries/User_agent.php +++ b/system/libraries/User_agent.php @@ -144,6 +144,15 @@ class CI_User_agent { */ public $robot = ''; + /** + * HTTP Referer + * + * @var mixed + */ + public $referer; + + // -------------------------------------------------------------------- + /** * Constructor * @@ -358,7 +367,7 @@ class CI_User_agent { { 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'])))); + $this->languages = explode(',', preg_replace('/(;\s?q=[0-9\.]+)|\s/i', '', strtolower(trim($_SERVER['HTTP_ACCEPT_LANGUAGE'])))); } if (count($this->languages) === 0) @@ -378,7 +387,7 @@ class CI_User_agent { { if ((count($this->charsets) === 0) && ! empty($_SERVER['HTTP_ACCEPT_CHARSET'])) { - $this->charsets = explode(',', preg_replace('/(;q=.+)/i', '', strtolower(trim($_SERVER['HTTP_ACCEPT_CHARSET'])))); + $this->charsets = explode(',', preg_replace('/(;\s?q=.+)|\s/i', '', strtolower(trim($_SERVER['HTTP_ACCEPT_CHARSET'])))); } if (count($this->charsets) === 0) @@ -471,24 +480,22 @@ class CI_User_agent { */ public function is_referral() { - static $result; - - if ( ! isset($result)) + if ( ! isset($this->referer)) { if (empty($_SERVER['HTTP_REFERER'])) { - $result = FALSE; + $this->referer = FALSE; } else { $referer_host = @parse_url($_SERVER['HTTP_REFERER'], PHP_URL_HOST); $own_host = parse_url(config_item('base_url'), PHP_URL_HOST); - $result = ($referer_host && $referer_host !== $own_host); + $this->referer = ($referer_host && $referer_host !== $own_host); } } - return $result; + return $this->referer; } // -------------------------------------------------------------------- -- cgit v1.2.3-24-g4f1b From b2a0e70585367e59bf2d106629c0e9c3ab1370c2 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Sat, 18 Jan 2014 16:54:51 +0200 Subject: Fix #2825 --- system/libraries/Cache/drivers/Cache_memcached.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system/libraries') diff --git a/system/libraries/Cache/drivers/Cache_memcached.php b/system/libraries/Cache/drivers/Cache_memcached.php index 886357e57..d59847752 100644 --- a/system/libraries/Cache/drivers/Cache_memcached.php +++ b/system/libraries/Cache/drivers/Cache_memcached.php @@ -85,7 +85,7 @@ class CI_Cache_memcached extends CI_Driver { { if ($raw !== TRUE) { - $data = array($data, time, $ttl); + $data = array($data, time(), $ttl); } if (get_class($this->_memcached) === 'Memcached') -- cgit v1.2.3-24-g4f1b From 3aecedbbb017567925f76ae68b726bd22b4cc80c Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Mon, 20 Jan 2014 10:39:08 +0200 Subject: Fix #2737 --- system/libraries/Xmlrpc.php | 48 +++++++++++++++++++++++++-------------------- 1 file changed, 27 insertions(+), 21 deletions(-) (limited to 'system/libraries') diff --git a/system/libraries/Xmlrpc.php b/system/libraries/Xmlrpc.php index ab907e706..d0f6d83b3 100644 --- a/system/libraries/Xmlrpc.php +++ b/system/libraries/Xmlrpc.php @@ -1121,15 +1121,15 @@ 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 - ); + $pname = (string) $parser; + $this->xh[$pname] = array( + '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); @@ -1145,7 +1145,7 @@ class XML_RPC_Message extends CI_Xmlrpc { break; } - $this->xh[$parser]['headers'][] = $line; + $this->xh[$pname]['headers'][] = $line; } $data = implode("\r\n", $lines); @@ -1163,18 +1163,18 @@ class XML_RPC_Message extends CI_Xmlrpc xml_parser_free($parser); // Got ourselves some badness, it seems - if ($this->xh[$parser]['isf'] > 1) + if ($this->xh[$pname]['isf'] > 1) { if ($this->debug === TRUE) { - echo "---Invalid Return---\n".$this->xh[$parser]['isf_reason']."---Invalid Return---\n\n"; + echo "---Invalid Return---\n".$this->xh[$pname]['isf_reason']."---Invalid Return---\n\n"; } - return new XML_RPC_Response(0, $this->xmlrpcerr['invalid_return'], $this->xmlrpcstr['invalid_return'].' '.$this->xh[$parser]['isf_reason']); + return new XML_RPC_Response(0, $this->xmlrpcerr['invalid_return'], $this->xmlrpcstr['invalid_return'].' '.$this->xh[$pname]['isf_reason']); } - elseif ( ! is_object($this->xh[$parser]['value'])) + elseif ( ! is_object($this->xh[$pname]['value'])) { - return new XML_RPC_Response(0, $this->xmlrpcerr['invalid_return'], $this->xmlrpcstr['invalid_return'].' '.$this->xh[$parser]['isf_reason']); + return new XML_RPC_Response(0, $this->xmlrpcerr['invalid_return'], $this->xmlrpcstr['invalid_return'].' '.$this->xh[$pname]['isf_reason']); } // Display XML content for debugging @@ -1182,10 +1182,10 @@ class XML_RPC_Message extends CI_Xmlrpc { echo '
';
 
-			if (count($this->xh[$parser]['headers'] > 0))
+			if (count($this->xh[$pname]['headers'] > 0))
 			{
 				echo "---HEADERS---\n";
-				foreach ($this->xh[$parser]['headers'] as $header)
+				foreach ($this->xh[$pname]['headers'] as $header)
 				{
 					echo $header."\n";
 				}
@@ -1193,13 +1193,13 @@ class XML_RPC_Message extends CI_Xmlrpc
 			}
 
 			echo "---DATA---\n".htmlspecialchars($data)."\n---END DATA---\n\n---PARSED---\n";
-			var_dump($this->xh[$parser]['value']);
+			var_dump($this->xh[$pname]['value']);
 			echo "\n---END PARSED---
"; } // Send response - $v = $this->xh[$parser]['value']; - if ($this->xh[$parser]['isf']) + $v = $this->xh[$pname]['value']; + if ($this->xh[$pname]['isf']) { $errno_v = $v->me['struct']['faultCode']; $errstr_v = $v->me['struct']['faultString']; @@ -1218,7 +1218,7 @@ class XML_RPC_Message extends CI_Xmlrpc $r = new XML_RPC_Response($v); } - $r->headers = $this->xh[$parser]['headers']; + $r->headers = $this->xh[$pname]['headers']; return $r; } @@ -1249,6 +1249,8 @@ class XML_RPC_Message extends CI_Xmlrpc */ public function open_tag($the_parser, $name) { + $the_parser = (string) $the_parser; + // If invalid nesting, then return if ($this->xh[$the_parser]['isf'] > 1) return; @@ -1348,6 +1350,8 @@ class XML_RPC_Message extends CI_Xmlrpc */ public function closing_tag($the_parser, $name) { + $the_parser = (string) $the_parser; + if ($this->xh[$the_parser]['isf'] > 1) return; // Remove current element from stack and set variable @@ -1480,6 +1484,8 @@ class XML_RPC_Message extends CI_Xmlrpc */ public function character_data($the_parser, $data) { + $the_parser = (string) $the_parser; + if ($this->xh[$the_parser]['isf'] > 1) return; // XML Fault found already // If a value has not been found -- cgit v1.2.3-24-g4f1b From ecc260e0be0cdb55c4e4802b78ddd78b0d8b0ebc Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Fri, 24 Jan 2014 14:20:13 +0200 Subject: Righting a wrong in the Session library - Change userdata(), flashdata(), tempdata() to return all the respective data when no parameter is passed. - Revert the addition of all_flashdata(). - Deprecate all_userdata(). - Fix related changelog entries that were all inconsistent. --- system/libraries/Profiler.php | 2 +- system/libraries/Session/Session.php | 89 ++++++++++++++++++++---------------- 2 files changed, 50 insertions(+), 41 deletions(-) (limited to 'system/libraries') diff --git a/system/libraries/Profiler.php b/system/libraries/Profiler.php index 4e556b23d..4796e8416 100644 --- a/system/libraries/Profiler.php +++ b/system/libraries/Profiler.php @@ -516,7 +516,7 @@ class CI_Profiler { .'  '.$this->CI->lang->line('profiler_session_data').'  ('.$this->CI->lang->line('profiler_section_show').')' .''; - foreach ($this->CI->session->all_userdata() as $key => $val) + foreach ($this->CI->session->userdata() as $key => $val) { if (is_array($val) OR is_object($val)) { diff --git a/system/libraries/Session/Session.php b/system/libraries/Session/Session.php index ac97b944c..d9f2f506f 100644 --- a/system/libraries/Session/Session.php +++ b/system/libraries/Session/Session.php @@ -238,9 +238,14 @@ class CI_Session extends CI_Driver_Library { * @param string Item key * @return string Item value or NULL if not found */ - public function userdata($item) + public function userdata($item = NULL) { - return isset($this->userdata[$item]) ? $this->userdata[$item] : NULL; + if (isset($item)) + { + return isset($this->userdata[$item]) ? $this->userdata[$item] : NULL; + } + + return isset($this->userdata) ? $this->userdata : array(); } // ------------------------------------------------------------------------ @@ -248,35 +253,12 @@ class CI_Session extends CI_Driver_Library { /** * Fetch all session data * + * @deprecated 3.0.0 Use userdata() with no parameters instead * @return array User data array */ public function all_userdata() { - return isset($this->userdata) ? $this->userdata : NULL; - } - - // ------------------------------------------------------------------------ - - /** - * Fetch all flashdata - * - * @return array Flash data array - */ - public function all_flashdata() - { - $out = array(); - - // loop through all userdata - foreach ($this->all_userdata() as $key => $val) - { - // if it contains flashdata, add it - if (strpos($key, self::FLASHDATA_KEY.self::FLASHDATA_OLD) !== FALSE) - { - $key = str_replace(self::FLASHDATA_KEY.self::FLASHDATA_OLD, '', $key); - $out[$key] = $val; - } - } - return $out; + return isset($this->userdata) ? $this->userdata : array(); } // ------------------------------------------------------------------------ @@ -417,11 +399,25 @@ class CI_Session extends CI_Driver_Library { * @param string Item key * @return string */ - public function flashdata($key) + public function flashdata($key = NULL) { - // Prepend key and retrieve value - $flashdata_key = self::FLASHDATA_KEY.self::FLASHDATA_OLD.$key; - return $this->userdata($flashdata_key); + if (isset($key)) + { + return $this->userdata(self::FLASHDATA_KEY.self::FLASHDATA_OLD.$key); + } + + // Get our flashdata items from userdata + $out = array(); + foreach ($this->userdata() as $key => $val) + { + if (strpos($key, self::FLASHDATA_KEY.self::FLASHDATA_OLD) !== FALSE) + { + $key = str_replace(self::FLASHDATA_KEY.self::FLASHDATA_OLD, '', $key); + $out[$key] = $val; + } + } + + return $out; } // ------------------------------------------------------------------------ @@ -514,11 +510,25 @@ class CI_Session extends CI_Driver_Library { * @param string Item key * @return string */ - public function tempdata($key) + public function tempdata($key = NULL) { - // Prepend key and return value - $tempdata_key = self::FLASHDATA_KEY.self::FLASHDATA_EXP.$key; - return $this->userdata($tempdata_key); + if (isset($key)) + { + return $this->userdata(self::FLASHDATA_KEY.self::FLASHDATA_EXP.$key); + } + + // Get our tempdata items from userdata + $out = array(); + foreach ($this->userdata() as $key => $val) + { + if (strpos($key, self::FLASHDATA_KEY.self::FLASHDATA_EXP) !== FALSE) + { + $key = str_replace(self::FLASHDATA_KEY.self::FLASHDATA_EXP, '', $key); + $out[$key] = $val; + } + } + + return $out; } // ------------------------------------------------------------------------ @@ -531,13 +541,12 @@ class CI_Session extends CI_Driver_Library { */ protected function _flashdata_mark() { - foreach ($this->all_userdata() as $name => $value) + foreach ($this->userdata() as $name => $value) { $parts = explode(self::FLASHDATA_NEW, $name); if (count($parts) === 2) { - $new_name = self::FLASHDATA_KEY.self::FLASHDATA_OLD.$parts[1]; - $this->set_userdata($new_name, $value); + $this->set_userdata(self::FLASHDATA_KEY.self::FLASHDATA_OLD.$parts[1], $value); $this->unset_userdata($name); } } @@ -552,7 +561,7 @@ class CI_Session extends CI_Driver_Library { */ protected function _flashdata_sweep() { - $userdata = $this->all_userdata(); + $userdata = $this->userdata(); foreach (array_keys($userdata) as $key) { if (strpos($key, self::FLASHDATA_OLD)) @@ -581,7 +590,7 @@ class CI_Session extends CI_Driver_Library { // Unset expired elements $now = time(); - $userdata = $this->all_userdata(); + $userdata = $this->userdata(); foreach (array_keys($userdata) as $key) { if (strpos($key, self::FLASHDATA_EXP) && $expirations[$key] < $now) -- cgit v1.2.3-24-g4f1b From aa9a4f7e59143a3a187e415e646c966aaf786380 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Tue, 28 Jan 2014 12:05:51 +0200 Subject: Fix #2844 --- system/libraries/Zip.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system/libraries') diff --git a/system/libraries/Zip.php b/system/libraries/Zip.php index b10b0bb0f..58f06455c 100644 --- a/system/libraries/Zip.php +++ b/system/libraries/Zip.php @@ -294,7 +294,7 @@ class CI_Zip { { $name = str_replace('\\', '/', $path); - if ($preserve_filepath === FALSE) + if ($archive_filepath === FALSE) { $name = preg_replace('|.*/(.+)|', '\\1', $name); } -- cgit v1.2.3-24-g4f1b From 818aedb6ca46ee8498624d49403e5ff1404bc692 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Mon, 3 Feb 2014 11:30:25 +0200 Subject: Introducing CI_Encryption (a CI_Encrypt replacement) --- system/libraries/Encryption.php | 718 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 718 insertions(+) create mode 100644 system/libraries/Encryption.php (limited to 'system/libraries') diff --git a/system/libraries/Encryption.php b/system/libraries/Encryption.php new file mode 100644 index 000000000..76569f281 --- /dev/null +++ b/system/libraries/Encryption.php @@ -0,0 +1,718 @@ +_drivers = array( + 'mcrypt' => extension_loaded('mcrypt'), + // While OpenSSL is available for PHP 5.3.0, an IV parameter + // for the encrypt/decrypt functions is only available since 5.3.3 + 'openssl' => (is_php('5.3.3') && extension_loaded('openssl')) + ); + + if ( ! $this->_drivers['mcrypt'] && ! $this->_drivers['openssl']) + { + return show_error('Encryption: Unable to find an available encryption driver.'); + } + + $this->initialize($params); + + if (empty($this->_driver)) + { + $this->_driver = ($this->_drivers['mcrypt'] === TRUE) + ? 'mcrypt' + : 'openssl'; + + log_message('debug', "Encryption: Auto-configured driver '".$params['driver']."'."); + } + + isset($this->_key) OR $this->_key = config_item('encryption_key'); + if (empty($this->_key)) + { + return show_error('Encryption: You are required to set an encryption key in your configuration.'); + } + + log_message('debug', 'Encryption Class Initialized'); + } + + // -------------------------------------------------------------------- + + /** + * Initialize + * + * @param array $params Configuration parameters + * @return CI_Encryption + */ + public function initialize(array $params) + { + if ( ! empty($params['driver'])) + { + if (isset($this->_drivers[$params['driver']])) + { + if ($this->_driver[$params['driver']]) + { + $this->_driver = $params['driver']; + } + else + { + log_message('error', "Encryption: Driver '".$params['driver']."' is not available."); + } + } + else + { + log_message('error', "Encryption: Unknown driver '".$params['driver']."' cannot be configured."); + } + } + + empty($params['key']) OR $this->_key = $params['key']; + $this->{'_'.$this->_driver.'_initialize'}($params); + return $this; + } + + // -------------------------------------------------------------------- + + /** + * Initialize MCrypt + * + * @param array $params Configuration parameters + * @return void + */ + protected function _mcrypt_initialize($params) + { + if ( ! empty($params['cipher'])) + { + $params['cipher'] = strtolower($params['cipher']); + $this->_cipher_alias($params['cipher']); + + if ( ! in_array($params['cipher'], mcrypt_list_algorithms(), TRUE)) + { + log_message('error', 'Encryption: MCrypt cipher '.strtoupper($params['cipher']).' is not available.'); + } + else + { + $this->_cipher = $params['cipher']; + } + } + + if ( ! empty($params['mode'])) + { + if ( ! defined('MCRYPT_MODE_'.$params['mode'])) + { + log_message('error', 'Encryption: MCrypt mode '.strtotupper($params['mode']).' is not available.'); + } + else + { + $this->_mode = constant('MCRYPT_MODE_'.$params['mode']); + } + } + + if (isset($this->_cipher, $this->_mode)) + { + if (is_resource($this->_handle) + && (strtolower(mcrypt_enc_get_algorithms_name($this->_handle)) !== $this->_cipher + OR strtolower(mcrypt_enc_get_modes_name($this->_handle)) !== $this->_mode) + ) + { + mcrypt_module_close($this->_handle); + } + + if ($this->_handle = mcrypt_module_open($this->_cipher, '', $this->_mode, '')) + { + log_message('debug', 'Encryption: MCrypt cipher '.strtoupper($this->_cipher).' initialized in '.strtoupper($this->_mode).' mode.'); + } + else + { + log_message('error', 'Encryption: Unable to initialize MCrypt with cipher '.strtoupper($this->_cipher).' in '.strtoupper($this->_mode).' mode.'); + } + } + } + + // -------------------------------------------------------------------- + + /** + * Initialize OpenSSL + * + * @param array $params Configuration parameters + * @return void + */ + protected function _openssl_initialize($params) + { + if ( ! empty($params['cipher'])) + { + $params['cipher'] = strtolower($params['cipher']); + $this->_cipher_alias($params['cipher']); + $this->_cipher = $params['cipher']; + } + + if ( ! empty($params['mode'])) + { + $this->_mode = strtolower($params['mode']); + } + + if (isset($this->_cipher, $this->_mode)) + { + // OpenSSL methods aren't suffixed with '-stream' for this mode + $handle = ($this->_mode === 'stream') + ? $this->_cipher + : $this->_cipher.'-'.$this->_mode; + + if ( ! in_array($handle, openssl_get_cipher_methods, TRUE)) + { + $this->_handle = NULL; + log_message('error', 'Encryption: Unable to initialize OpenSSL with method '.strtoupper($handle).'.'); + } + else + { + $this->_handle = $handle; + log_message('debug', 'Encryption: OpenSSL initialized with method '.strtoupper($handle).'.'); + } + } + } + + // -------------------------------------------------------------------- + + /** + * Encrypt + * + * @param string $data Input data + * @param array $params Input parameters + * @return string + */ + public function encrypt($data, array $params = NULL) + { + if (($params = $this->{'_'.$this->_driver.'_get_params'}($params)) === FALSE) + { + return FALSE; + } + elseif ( ! isset($params['iv'])) + { + $params['iv'] = ($iv_size = $this->{'_'.$this->_driver.'_get_iv_size'}($params['handle'])) + ? $this->{'_'.$this->_driver.'_get_iv'}($iv_size) + : NULL; + } + + if (($data = $this->{'_'.$this->_driver.'_encrypt'}($data, $params)) === FALSE) + { + return FALSE; + } + + return ($params['base64']) + ? base64_encode($data) + : $data; + } + + // -------------------------------------------------------------------- + + /** + * Encrypt via MCrypt + * + * @param string $data Input data + * @param array $params Input parameters + * @return string + */ + protected function _mcrypt_encrypt($data, $params) + { + if (mcrypt_generic_init($params['handle'], $params['key'], $params['iv']) < 0) + { + if ($params['handle'] !== $this->_handle) + { + mcrypt_module_close($params['handle']); + } + + return FALSE; + } + + // Use PKCS#7 padding in order to ensure compatibility with OpenSSL + // and other implementations outside of PHP + $block_size = mcrypt_enc_get_block_size($params['handle']); + $pad = $block_size - (strlen($data) % $block_size); + $data .= str_repeat(chr($pad), $pad); + + $data = $params['iv'].mcrypt_generic($params['handle'], $data); + + mcrypt_generic_deinit($params['handle']); + if ($params['handle'] !== $this->_handle) + { + mcrypt_module_close($handle); + } + + return $data; + } + + // -------------------------------------------------------------------- + + /** + * Encrypt via OpenSSL + * + * @param string $data Input data + * @param array $params Input parameters + * @return string + */ + protected function _openssl_encrypt($data, $params) + { + $data = openssl_encrypt( + $data, + $params['handle'], + $params['key'], + 1, // DO NOT TOUCH! + $params['iv'] + ); + + if ($data === FALSE) + { + return FALSE; + } + + return $params['iv'].$data; + } + + // -------------------------------------------------------------------- + + /** + * Decrypt + * + * @param string $data Encrypted data + * @param array $params Input parameters + * @return string + */ + public function decrypt($data, array $params = NULL) + { + if (($params = $this->{'_'.$this->_driver.'_get_params'}($params)) === FALSE) + { + return FALSE; + } + elseif ($params['base64']) + { + $data = base64_decode($data); + } + + if ( ! isset($params['iv'])) + { + if ($iv_size) + { + $params['iv'] = substr($data, 0, $iv_size); + $data = substr($data, $iv_size); + } + else + { + $params['iv'] = NULL; + } + } + elseif (strncmp($params['iv'], $data, $iv_size = strlen($params['iv'])) === 0) + { + $data = substr($data, $iv_size); + } + + return $this->{'_'.$this->_driver.'_decrypt'}($data, $params); + } + + // -------------------------------------------------------------------- + + /** + * Decrypt via MCrypt + * + * @param string $data Encrypted data + * @param array $params Input parameters + * @return string + */ + protected function _mcrypt_decrypt($data, $params) + { + if (mcrypt_generic_init($params['handle'], $params['key'], $params['iv']) < 0) + { + if ($params['handle'] !== $this->_handle) + { + mcrypt_module_close($params['handle']); + } + + return FALSE; + } + + $data = mdecrypt_generic($params['handle'], $data); + + mcrypt_generic_deinit($params['handle']); + if ($params['handle'] !== $this->_handle) + { + mcrypt_module_close($handle); + } + + // Remove PKCS#7 padding + return substr($data, 0, -ord($data[strlen($data)-1])); + } + + // -------------------------------------------------------------------- + + /** + * Decrypt via OpenSSL + * + * @param string $data Encrypted data + * @param array $params Input parameters + * @return string + */ + protected function _openssl_decrypt($data, $params) + { + return openssl_decrypt( + $data, + $params['handle'], + $params['key'], + 1, // DO NOT TOUCH! + $params['iv'] + ); + } + + // -------------------------------------------------------------------- + + /** + * Get IV size via MCrypt + * + * @param resource $handle MCrypt module resource + * @return int + */ + protected function _mcrypt_get_iv_size($handle) + { + return mcrypt_enc_get_iv_size($handle); + } + + // -------------------------------------------------------------------- + + /** + * Get IV size via OpenSSL + * + * @param string $handle OpenSSL cipher method + * @return int + */ + protected function _openssl_get_iv_size($handle) + { + return openssl_cipher_iv_length($handle); + } + + // -------------------------------------------------------------------- + + /** + * Get IV via MCrypt + * + * @param int $size + * @return int + */ + protected function _mcrypt_get_iv($size) + { + // If /dev/urandom is available - use it, otherwise there's + // also /dev/random, but it is highly unlikely that it would + // be available while /dev/urandom is not and it is known to be + // blocking anyway. + if (defined(MCRYPT_DEV_URANDOM)) + { + $source = MCRYPT_DEV_URANDOM; + } + else + { + $source = MCRYPT_RAND; + is_php('5.3') OR srand(microtime(TRUE)); + } + + return mcrypt_create_iv($size, $source); + } + + // -------------------------------------------------------------------- + + /** + * Get IV via OpenSSL + * + * @param int $size IV size + * @return int + */ + protected function _openssl_get_iv($size) + { + return openssl_random_pseudo_bytes($size); + } + + // -------------------------------------------------------------------- + + /** + * Get MCrypt parameters + * + * @param array $params Input parameters + * @return array + */ + protected function _mcrypt_get_params($params) + { + if (empty($params)) + { + if ( ! isset($this->_cipher, $this->_mode, $params->_key, $this->_handle) OR ! is_resource($this->_handle)) + { + return FALSE; + } + + return array( + 'handle' => $this->_handle, + 'cipher' => $this->_cipher, + 'mode' => $this->_mode, + 'key' => $this->_key, + 'base64' => TRUE + ); + } + + $params = array( + 'handle' => NULL, + 'cipher' => isset($params['cipher']) ? $params['cipher'] : $this->_cipher, + 'mode' => isset($params['mode']) ? $params['mode'] : $this->_mode, + 'key' => isset($params['key']) ? $params['key'] : $this->_key, + 'iv' => isset($params['iv']) ? $params['iv'] : NULL, + 'base64' => isset($params['base64']) ? $params['base64'] : TRUE + ); + + if ( ! isset($params['cipher'], $params['mode'], $params['key'])) + { + return FALSE; + } + + $this->_cipher_alias($params['cipher']); + + if ($params['cipher'] !== $this->_cipher OR $params['mode'] !== $this->_mode) + { + if (($params['handle'] = mcrypt_module_open($params['cipher'], '', $params['mode'], '')) === FALSE) + { + return FALSE; + } + } + else + { + if ( ! is_resource($this->_handle)) + { + return FALSE; + } + + $params['handle'] = $this->_handle; + } + + return $params; + } + + // -------------------------------------------------------------------- + + /** + * Get OpenSSL parameters + * + * @param array $params Input parameters + * @return array + */ + protected function _openssl_get_params($params) + { + if (empty($params)) + { + if ( ! isset($this->_cipher, $this->_mode, $params->_key, $this->_handle)) + { + return FALSE; + } + + return array( + 'handle' => $this->_handle, + 'cipher' => $this->_cipher, + 'mode' => $this->_mode, + 'key' => $this->_key, + 'base64' => TRUE + ); + } + + $params = array( + 'handle' => NULL, + 'cipher' => isset($params['cipher']) ? $params['cipher'] : $this->_cipher, + 'mode' => isset($params['mode']) ? $params['mode'] : $this->_mode, + 'key' => isset($params['key']) ? $params['key'] : $this->_key, + 'iv' => isset($params['iv']) ? $params['iv'] : NULL, + 'base64' => isset($params['base64']) ? $params['base64'] : TRUE + ); + + if ( ! isset($params['cipher'], $params['mode'], $params['key'])) + { + return FALSE; + } + + $this->_cipher_alias($params['cipher']); + + if ($params['cipher'] !== $this->_cipher OR $params['mode'] !== $this->_mode) + { + // OpenSSL methods aren't suffixed with '-stream' for this mode + $params['handle'] = ($params['mode'] === 'stream') + ? $params['cipher'] + : $params['cipher'].'-'.$params['mode']; + $params['handle'] = $params['cipher'].'-'.$params['mode']; + } + else + { + if (empty($this->_handle)) + { + return FALSE; + } + + $params['handle'] = $this->_handle; + } + + return $params; + } + + // -------------------------------------------------------------------- + + /** + * Cipher alias + * + * Tries to translate cipher names between MCrypt and OpenSSL's "dialects". + * + * @param string $cipher Cipher name + * @return void + */ + protected function _cipher_alias(&$cipher) + { + static $dictionary; + + if (empty($dictionary)) + { + $dictionary = array( + 'mcrypt' => array( + 'rijndael-128', + 'tripledes', + 'arcfour' + ), + 'openssl' => array( + 'aes-128', + 'des-ede3', + 'rc4-40' + ) + ); + + // Notes regarding other seemingly matching ciphers between + // MCrypt and OpenSSL: + // + // - DES is compatible, but doesn't need an alias + // - Blowfish is NOT compatible + // mcrypt: 'blowfish', 'blowfish-compat' + // openssl: 'bf' + // - CAST-128/CAST5 is NOT compatible + // mcrypt: 'cast-128' + // openssl: 'cast5' + // - RC2 is NOT compatible + // mcrypt: 'rc2' + // openssl: 'rc2', 'rc2-40', 'rc2-64' + // + // To avoid any other confusion due to a popular (but incorrect) + // belief, it should also be noted that Rijndael-192/256 are NOT + // the same ciphers as AES-192/256 like Rijndael-128 and AES-256 is. + // + // All compatibility tests were done in CBC mode. + } + + $dialect = ($this->_driver === 'mcrypt') + ? 'openssl' + : 'mcrypt'; + if (($index = array_search($cipher, $dictionary[$dialect], TRUE)) !== FALSE) + { + $cipher = $dictionary[$this->_driver][$index]; + } + } + + // -------------------------------------------------------------------- + + /** + * __get() magic + * + * @param string $key Property name + * @return mixed + */ + public function __get($key) + { + return in_array($key, array('cipher', 'mode', 'driver', 'drivers'), TRUE) + ? $this->{'_'.$key} + : NULL; + } + +} + +/* End of file Encryption.php */ +/* Location: ./system/libraries/Encryption.php */ \ No newline at end of file -- cgit v1.2.3-24-g4f1b From 29cade43cc0a86c4a1a531c2649c4830d29ac2fc Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Tue, 4 Feb 2014 14:05:58 +0200 Subject: CI_Encryption improvements - HMAC authentication by default. - HKDF support. - Reduce code repetition. --- system/libraries/Encryption.php | 298 +++++++++++++++++++++++++++------------- 1 file changed, 199 insertions(+), 99 deletions(-) (limited to 'system/libraries') diff --git a/system/libraries/Encryption.php b/system/libraries/Encryption.php index 76569f281..6e71d6ee1 100644 --- a/system/libraries/Encryption.php +++ b/system/libraries/Encryption.php @@ -81,6 +81,20 @@ class CI_Encryption { */ protected $_drivers = array(); + /** + * List of supported HMAC algorightms + * + * name => digest size pairs + * + * @var array + */ + protected $_digests = array( + 'sha224' => 28, + 'sha256' => 32, + 'sha384' => 48, + 'sha512' => 64 + ); + // -------------------------------------------------------------------- /** @@ -102,6 +116,12 @@ class CI_Encryption { { return show_error('Encryption: Unable to find an available encryption driver.'); } + // Our configuration validates against the existence of MCRYPT_MODE_* constants, + // but MCrypt supports CTR mode without actually having a constant for it, so ... + elseif ($this->_drivers['mcrypt'] && ! defined('MCRYPT_MODE_CTR')) + { + define('MCRYPT_MODE_CTR', 'ctr'); + } $this->initialize($params); @@ -268,7 +288,7 @@ class CI_Encryption { */ public function encrypt($data, array $params = NULL) { - if (($params = $this->{'_'.$this->_driver.'_get_params'}($params)) === FALSE) + if (($params = $this->_get_params($params)) === FALSE) { return FALSE; } @@ -284,9 +304,28 @@ class CI_Encryption { return FALSE; } - return ($params['base64']) - ? base64_encode($data) - : $data; + if ($params['base64']) + { + $data = base64_encode($data); + } + + if ($params['hmac'] !== FALSE) + { + if ( ! isset($params['hmac']['key'])) + { + $params['hmac']['key'] = $this->hkdf( + $params['key'], + $params['hmac']['digest'], + NULL, + NULL, + 'authentication' + ); + } + + return hash_hmac($params['hmac']['digest'], $data, $params['hmac']['key'], $params['base64']).$data; + } + + return $data; } // -------------------------------------------------------------------- @@ -300,7 +339,11 @@ class CI_Encryption { */ protected function _mcrypt_encrypt($data, $params) { - if (mcrypt_generic_init($params['handle'], $params['key'], $params['iv']) < 0) + if ( ! is_resource($params['handle'])) + { + return FALSE; + } + elseif (mcrypt_generic_init($params['handle'], $params['key'], $params['iv']) < 0) { if ($params['handle'] !== $this->_handle) { @@ -338,6 +381,11 @@ class CI_Encryption { */ protected function _openssl_encrypt($data, $params) { + if (empty($params['handle'])) + { + return FALSE; + } + $data = openssl_encrypt( $data, $params['handle'], @@ -365,11 +413,39 @@ class CI_Encryption { */ public function decrypt($data, array $params = NULL) { - if (($params = $this->{'_'.$this->_driver.'_get_params'}($params)) === FALSE) + if (($params = $this->_get_params($params)) === FALSE) { return FALSE; } - elseif ($params['base64']) + + if ($params['hmac'] !== FALSE) + { + if ( ! isset($params['hmac']['key'])) + { + $params['hmac']['key'] = $this->hkdf( + $params['key'], + $params['hmac']['digest'], + NULL, + NULL, + 'authentication' + ); + } + + // This might look illogical, but it is done during encryption as well ... + // The 'base64' value is effectively a "raw data" parameter + $digest_size = ($params['base64']) + ? $this->_digests[$params['hmac']['digest']] * 2 + : $this->_digests[$params['hmac']['digest']]; + $hmac = substr($data, 0, $digest_size); + $data = substr($data, $digest_size); + + if ($hmac !== hash_hmac($params['hmac']['digest'], $data, $params['hmac']['key'], $params['base64'])) + { + return FALSE; + } + } + + if ($params['base64']) { $data = base64_decode($data); } @@ -405,7 +481,11 @@ class CI_Encryption { */ protected function _mcrypt_decrypt($data, $params) { - if (mcrypt_generic_init($params['handle'], $params['key'], $params['iv']) < 0) + if ( ! is_resource($params['handle'])) + { + return FALSE; + } + elseif (mcrypt_generic_init($params['handle'], $params['key'], $params['iv']) < 0) { if ($params['handle'] !== $this->_handle) { @@ -438,13 +518,15 @@ class CI_Encryption { */ protected function _openssl_decrypt($data, $params) { - return openssl_decrypt( - $data, - $params['handle'], - $params['key'], - 1, // DO NOT TOUCH! - $params['iv'] - ); + return empty($params['handle']) + ? FALSE + : openssl_decrypt( + $data, + $params['handle'], + $params['key'], + 1, // DO NOT TOUCH! + $params['iv'] + ); } // -------------------------------------------------------------------- @@ -516,88 +598,52 @@ class CI_Encryption { // -------------------------------------------------------------------- /** - * Get MCrypt parameters + * Get params * * @param array $params Input parameters * @return array */ - protected function _mcrypt_get_params($params) + protected function _get_params($params) { if (empty($params)) { - if ( ! isset($this->_cipher, $this->_mode, $params->_key, $this->_handle) OR ! is_resource($this->_handle)) - { - return FALSE; - } - - return array( - 'handle' => $this->_handle, - 'cipher' => $this->_cipher, - 'mode' => $this->_mode, - 'key' => $this->_key, - 'base64' => TRUE - ); + return isset($this->_cipher, $this->_mode, $params->_key, $this->_handle) + ? array( + 'handle' => $this->_handle, + 'cipher' => $this->_cipher, + 'mode' => $this->_mode, + 'key' => $this->_key, + 'base64' => TRUE, + 'hmac' => $this->_mode === 'gcm' ? FALSE : array('digest' => 'sha512', 'key' => NULL) + ) + : FALSE; } - - $params = array( - 'handle' => NULL, - 'cipher' => isset($params['cipher']) ? $params['cipher'] : $this->_cipher, - 'mode' => isset($params['mode']) ? $params['mode'] : $this->_mode, - 'key' => isset($params['key']) ? $params['key'] : $this->_key, - 'iv' => isset($params['iv']) ? $params['iv'] : NULL, - 'base64' => isset($params['base64']) ? $params['base64'] : TRUE - ); - - if ( ! isset($params['cipher'], $params['mode'], $params['key'])) + elseif ( ! isset($params['cipher'], $params['mode'], $params['key'])) { return FALSE; } - $this->_cipher_alias($params['cipher']); - - if ($params['cipher'] !== $this->_cipher OR $params['mode'] !== $this->_mode) + if ($params['mode'] === 'gcm') { - if (($params['handle'] = mcrypt_module_open($params['cipher'], '', $params['mode'], '')) === FALSE) - { - return FALSE; - } + $params['hmac'] = FALSE; } - else + elseif ( ! isset($params['hmac']) OR ( ! is_array($params['hmac']) && $params['hmac'] !== FALSE)) { - if ( ! is_resource($this->_handle)) - { - return FALSE; - } - - $params['handle'] = $this->_handle; + $params['hmac'] = array( + 'digest' => 'sha512', + 'key' => NULL + ); } - - return $params; - } - - // -------------------------------------------------------------------- - - /** - * Get OpenSSL parameters - * - * @param array $params Input parameters - * @return array - */ - protected function _openssl_get_params($params) - { - if (empty($params)) + elseif (is_array($params['hmac'])) { - if ( ! isset($this->_cipher, $this->_mode, $params->_key, $this->_handle)) + if (isset($params['hmac']['digest']) && ! isset($this->_digests[$params['hmac']['digest']])) { return FALSE; } - return array( - 'handle' => $this->_handle, - 'cipher' => $this->_cipher, - 'mode' => $this->_mode, - 'key' => $this->_key, - 'base64' => TRUE + $params['hmac'] = array( + 'digest' => isset($params['hmac']['digest']) ? $params['hmac']['digest'] : 'sha512', + 'key' => isset($params['hmac']['key']) ? $params['hmac']['key'] : NULL ); } @@ -607,35 +653,47 @@ class CI_Encryption { 'mode' => isset($params['mode']) ? $params['mode'] : $this->_mode, 'key' => isset($params['key']) ? $params['key'] : $this->_key, 'iv' => isset($params['iv']) ? $params['iv'] : NULL, - 'base64' => isset($params['base64']) ? $params['base64'] : TRUE + 'base64' => isset($params['base64']) ? $params['base64'] : TRUE, + 'hmac' => $params['hmac'] ); - if ( ! isset($params['cipher'], $params['mode'], $params['key'])) - { - return FALSE; - } - $this->_cipher_alias($params['cipher']); + $params['handle'] = ($params['cipher'] !== $this->_cipher OR $params['mode'] !== $this->_mode) + ? $this->{'_'.$this->_driver.'_get_handle'}($params['cipher'], $params['mode']) + : $this->_handle; - if ($params['cipher'] !== $this->_cipher OR $params['mode'] !== $this->_mode) - { - // OpenSSL methods aren't suffixed with '-stream' for this mode - $params['handle'] = ($params['mode'] === 'stream') - ? $params['cipher'] - : $params['cipher'].'-'.$params['mode']; - $params['handle'] = $params['cipher'].'-'.$params['mode']; - } - else - { - if (empty($this->_handle)) - { - return FALSE; - } + return $params; + } - $params['handle'] = $this->_handle; - } + // -------------------------------------------------------------------- - return $params; + /** + * Get MCrypt handle + * + * @param string $cipher Cipher name + * @param string $mode Encryption mode + * @return resource + */ + protected function _mcrypt_get_handle($cipher, $mode) + { + return mcrypt_module_open($cipher, '', $mode, ''); + } + + // -------------------------------------------------------------------- + + /** + * Get OpenSSL handle + * + * @param string $cipher Cipher name + * @param string $mode Encryption mode + * @return string + */ + protected function _openssl_get_handle($cipher, $mode) + { + // OpenSSL methods aren't suffixed with '-stream' for this mode + return ($mode === 'stream') + ? $cipher + : $cipher.'-'.$mode; } // -------------------------------------------------------------------- @@ -699,6 +757,48 @@ class CI_Encryption { // -------------------------------------------------------------------- + /** + * HKDF + * + * @link https://tools.ietf.org/rfc/rfc5869.txt + * @param $key Input key + * @param $digest A SHA-2 hashing algorithm + * @param $salt Optional salt + * @param $info Optional context/application-specific info + * @param $length Output length (defaults to the selected digest size) + * @return string A pseudo-random key + */ + public function hkdf($key, $digest = 'sha512', $salt = NULL, $length = NULL, $info = '') + { + if ( ! isset($this->_digests[$digest])) + { + return FALSE; + } + + if (empty($length) OR ! is_int($length)) + { + $length = $this->_digests[$digest]; + } + elseif ($length > (255 * $this->_digests[$digest])) + { + return FALSE; + } + + isset($salt) OR $salt = str_repeat("\0", $this->_digests[$digest]); + + $prk = hash_hmac($digest, $key, $salt, TRUE); + $key = ''; + for ($key_block = '', $block_index = 1; strlen($key) < $length; $block_index++) + { + $key_block = hash_hmac($digest, $key_block.$info.chr($block_index), $prk, TRUE); + $key .= $key_block; + } + + return substr($key, 0, $length); + } + + // -------------------------------------------------------------------- + /** * __get() magic * -- cgit v1.2.3-24-g4f1b From 912831f589862c205d5b9837b710aa391460e08d Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Tue, 4 Feb 2014 17:21:37 +0200 Subject: CI_Encryption: Fix some errors and add unit tests for hkdf() --- system/libraries/Encryption.php | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) (limited to 'system/libraries') diff --git a/system/libraries/Encryption.php b/system/libraries/Encryption.php index 6e71d6ee1..4258aee53 100644 --- a/system/libraries/Encryption.php +++ b/system/libraries/Encryption.php @@ -125,15 +125,6 @@ class CI_Encryption { $this->initialize($params); - if (empty($this->_driver)) - { - $this->_driver = ($this->_drivers['mcrypt'] === TRUE) - ? 'mcrypt' - : 'openssl'; - - log_message('debug', "Encryption: Auto-configured driver '".$params['driver']."'."); - } - isset($this->_key) OR $this->_key = config_item('encryption_key'); if (empty($this->_key)) { @@ -172,6 +163,15 @@ class CI_Encryption { } } + if (empty($this->_driver)) + { + $this->_driver = ($this->_drivers['mcrypt'] === TRUE) + ? 'mcrypt' + : 'openssl'; + + log_message('debug', "Encryption: Auto-configured driver '".$this->_driver."'."); + } + empty($params['key']) OR $this->_key = $params['key']; $this->{'_'.$this->_driver.'_initialize'}($params); return $this; @@ -807,7 +807,7 @@ class CI_Encryption { */ public function __get($key) { - return in_array($key, array('cipher', 'mode', 'driver', 'drivers'), TRUE) + return in_array($key, array('cipher', 'mode', 'driver', 'drivers', 'digests'), TRUE) ? $this->{'_'.$key} : NULL; } -- cgit v1.2.3-24-g4f1b From 177144ff7d7c8afcfd4469efabf4733879a2e570 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Tue, 4 Feb 2014 18:07:34 +0200 Subject: Fix a logical error in CI_Encryption --- system/libraries/Encryption.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'system/libraries') diff --git a/system/libraries/Encryption.php b/system/libraries/Encryption.php index 4258aee53..3c1347523 100644 --- a/system/libraries/Encryption.php +++ b/system/libraries/Encryption.php @@ -322,7 +322,7 @@ class CI_Encryption { ); } - return hash_hmac($params['hmac']['digest'], $data, $params['hmac']['key'], $params['base64']).$data; + return hash_hmac($params['hmac']['digest'], $data, $params['hmac']['key'], ! $params['base64']).$data; } return $data; @@ -432,14 +432,14 @@ class CI_Encryption { } // This might look illogical, but it is done during encryption as well ... - // The 'base64' value is effectively a "raw data" parameter + // The 'base64' value is effectively an inverted "raw data" parameter $digest_size = ($params['base64']) ? $this->_digests[$params['hmac']['digest']] * 2 : $this->_digests[$params['hmac']['digest']]; $hmac = substr($data, 0, $digest_size); $data = substr($data, $digest_size); - if ($hmac !== hash_hmac($params['hmac']['digest'], $data, $params['hmac']['key'], $params['base64'])) + if ($hmac !== hash_hmac($params['hmac']['digest'], $data, $params['hmac']['key'], ! $params['base64'])) { return FALSE; } -- cgit v1.2.3-24-g4f1b From 50ccc38a8c07b412aad0c26afb0775a0d9be18ee Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Tue, 4 Feb 2014 23:30:06 +0200 Subject: CI_Encryption: Fix more errors and add a 'portability' test case --- system/libraries/Encryption.php | 34 +++++++++++++++++----------------- 1 file changed, 17 insertions(+), 17 deletions(-) (limited to 'system/libraries') diff --git a/system/libraries/Encryption.php b/system/libraries/Encryption.php index 3c1347523..2d3f82dc8 100644 --- a/system/libraries/Encryption.php +++ b/system/libraries/Encryption.php @@ -148,7 +148,7 @@ class CI_Encryption { { if (isset($this->_drivers[$params['driver']])) { - if ($this->_driver[$params['driver']]) + if ($this->_drivers[$params['driver']]) { $this->_driver = $params['driver']; } @@ -264,7 +264,7 @@ class CI_Encryption { ? $this->_cipher : $this->_cipher.'-'.$this->_mode; - if ( ! in_array($handle, openssl_get_cipher_methods, TRUE)) + if ( ! in_array($handle, openssl_get_cipher_methods(), TRUE)) { $this->_handle = NULL; log_message('error', 'Encryption: Unable to initialize OpenSSL with method '.strtoupper($handle).'.'); @@ -364,7 +364,7 @@ class CI_Encryption { mcrypt_generic_deinit($params['handle']); if ($params['handle'] !== $this->_handle) { - mcrypt_module_close($handle); + mcrypt_module_close($params['handle']); } return $data; @@ -452,7 +452,8 @@ class CI_Encryption { if ( ! isset($params['iv'])) { - if ($iv_size) + $iv_size = $this->{'_'.$this->_driver.'_get_iv_size'}($params['handle']); + if ($iv_size = $this->{'_'.$this->_driver.'_get_iv_size'}($params['handle'])) { $params['iv'] = substr($data, 0, $iv_size); $data = substr($data, $iv_size); @@ -500,7 +501,7 @@ class CI_Encryption { mcrypt_generic_deinit($params['handle']); if ($params['handle'] !== $this->_handle) { - mcrypt_module_close($handle); + mcrypt_module_close($params['handle']); } // Remove PKCS#7 padding @@ -607,7 +608,7 @@ class CI_Encryption { { if (empty($params)) { - return isset($this->_cipher, $this->_mode, $params->_key, $this->_handle) + return isset($this->_cipher, $this->_mode, $this->_key, $this->_handle) ? array( 'handle' => $this->_handle, 'cipher' => $this->_cipher, @@ -714,14 +715,16 @@ class CI_Encryption { { $dictionary = array( 'mcrypt' => array( - 'rijndael-128', - 'tripledes', - 'arcfour' + 'aes-128' => 'rijndael-128', + 'aes-192' => 'rijndael-128', + 'aes-256' => 'rijndael-128', + 'des3-ede3' => 'tripledes', + 'rc4-40' => 'arcfour' ), 'openssl' => array( - 'aes-128', - 'des-ede3', - 'rc4-40' + 'rijndael-128' => 'aes-128', + 'tripledes' => 'des-ede3', + 'arcfour' => 'rc4-40' ) ); @@ -746,12 +749,9 @@ class CI_Encryption { // All compatibility tests were done in CBC mode. } - $dialect = ($this->_driver === 'mcrypt') - ? 'openssl' - : 'mcrypt'; - if (($index = array_search($cipher, $dictionary[$dialect], TRUE)) !== FALSE) + if (isset($dictionary[$this->_driver][$cipher])) { - $cipher = $dictionary[$this->_driver][$index]; + $cipher = $dictionary[$this->_driver][$cipher]; } } -- cgit v1.2.3-24-g4f1b From 9108dd4e33cf139337e83ff969b2d38fee5ae2f8 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Tue, 4 Feb 2014 23:33:41 +0200 Subject: CI_Encryption: Remove ARCFour from aliased ciphers due ... Seems like there are some issues with it --- system/libraries/Encryption.php | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) (limited to 'system/libraries') diff --git a/system/libraries/Encryption.php b/system/libraries/Encryption.php index 2d3f82dc8..503fb64e3 100644 --- a/system/libraries/Encryption.php +++ b/system/libraries/Encryption.php @@ -718,13 +718,11 @@ class CI_Encryption { 'aes-128' => 'rijndael-128', 'aes-192' => 'rijndael-128', 'aes-256' => 'rijndael-128', - 'des3-ede3' => 'tripledes', - 'rc4-40' => 'arcfour' + 'des3-ede3' => 'tripledes' ), 'openssl' => array( 'rijndael-128' => 'aes-128', - 'tripledes' => 'des-ede3', - 'arcfour' => 'rc4-40' + 'tripledes' => 'des-ede3' ) ); -- cgit v1.2.3-24-g4f1b From 4a2918a33c756ac7cc9defc2e6acd371e4412af6 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Wed, 5 Feb 2014 01:03:46 +0200 Subject: Integrate CI_Encryption into the framework TODO: Add documentation in user_guide_src/source/libraries/encryption.rst --- .../libraries/Session/drivers/Session_cookie.php | 55 ++++++++++++---------- 1 file changed, 30 insertions(+), 25 deletions(-) (limited to 'system/libraries') diff --git a/system/libraries/Session/drivers/Session_cookie.php b/system/libraries/Session/drivers/Session_cookie.php index 971dfeabe..5d338fc04 100644 --- a/system/libraries/Session/drivers/Session_cookie.php +++ b/system/libraries/Session/drivers/Session_cookie.php @@ -240,7 +240,7 @@ class CI_Session_cookie extends CI_Session_driver { // Do we need encryption? If so, load the encryption class if ($this->sess_encrypt_cookie === TRUE) { - $this->CI->load->library('encrypt'); + $this->CI->load->library('encryption'); } // Check for database @@ -383,30 +383,33 @@ class CI_Session_cookie extends CI_Session_driver { return FALSE; } - $len = strlen($session) - 40; - - if ($len < 0) + if ($this->sess_encrypt_cookie === TRUE) { - log_message('debug', 'The session cookie was not signed.'); - return FALSE; + $session = $this->CI->encryption->decrypt($session); + if ($session === FALSE) + { + log_message('error', 'Session: Unable to decrypt the session cookie, possibly due to a HMAC mismatch.'); + return FALSE; + } } - - // Check cookie authentication - $hmac = substr($session, $len); - $session = substr($session, 0, $len); - - if ($hmac !== hash_hmac('sha1', $session, $this->encryption_key)) + else { - log_message('error', 'The session cookie data did not match what was expected.'); - $this->sess_destroy(); - return FALSE; - } + if (($len = strlen($session) - 40) <= 0) + { + log_message('error', 'Session: The session cookie was not signed.'); + return FALSE; + } - // Check for encryption - if ($this->sess_encrypt_cookie === TRUE) - { - // Decrypt the cookie data - $session = $this->CI->encrypt->decode($session); + // Check cookie authentication + $hmac = substr($session, $len); + $session = substr($session, 0, $len); + + if ($hmac !== hash_hmac('sha1', $session, $this->encryption_key)) + { + log_message('error', 'Session: HMAC mismatch. The session cookie data did not match what was expected.'); + $this->sess_destroy(); + return FALSE; + } } // Unserialize the session array @@ -723,11 +726,13 @@ class CI_Session_cookie extends CI_Session_driver { if ($this->sess_encrypt_cookie === TRUE) { - $cookie_data = $this->CI->encrypt->encode($cookie_data); + $cookie_data = $this->CI->encryption->encrypt($cookie_data); + } + else + { + // Require message authentication + $cookie_data .= hash_hmac('sha1', $cookie_data, $this->encryption_key); } - - // Require message authentication - $cookie_data .= hash_hmac('sha1', $cookie_data, $this->encryption_key); $expire = ($this->sess_expire_on_close === TRUE) ? 0 : $this->sess_expiration + time(); -- cgit v1.2.3-24-g4f1b From e7516b09402580c4fe0bf0ff537f367c1ba0efd2 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Wed, 5 Feb 2014 13:45:31 +0200 Subject: CI_Encryption: Work around MCrypt's dumb behavior in ECB mode --- system/libraries/Encryption.php | 114 +++++++++++++++++++++++----------------- 1 file changed, 65 insertions(+), 49 deletions(-) (limited to 'system/libraries') diff --git a/system/libraries/Encryption.php b/system/libraries/Encryption.php index 503fb64e3..2228ca3a6 100644 --- a/system/libraries/Encryption.php +++ b/system/libraries/Encryption.php @@ -292,12 +292,6 @@ class CI_Encryption { { return FALSE; } - elseif ( ! isset($params['iv'])) - { - $params['iv'] = ($iv_size = $this->{'_'.$this->_driver.'_get_iv_size'}($params['handle'])) - ? $this->{'_'.$this->_driver.'_get_iv'}($iv_size) - : NULL; - } if (($data = $this->{'_'.$this->_driver.'_encrypt'}($data, $params)) === FALSE) { @@ -343,7 +337,15 @@ class CI_Encryption { { return FALSE; } - elseif (mcrypt_generic_init($params['handle'], $params['key'], $params['iv']) < 0) + elseif ( ! isset($params['iv'])) + { + $params['iv'] = ($iv_size = mcrypt_enc_get_iv_size($params['handle'])) + ? $this->_mcrypt_get_iv($iv_size) + : NULL; + } + + + if (mcrypt_generic_init($params['handle'], $params['key'], $params['iv']) < 0) { if ($params['handle'] !== $this->_handle) { @@ -359,7 +361,20 @@ class CI_Encryption { $pad = $block_size - (strlen($data) % $block_size); $data .= str_repeat(chr($pad), $pad); - $data = $params['iv'].mcrypt_generic($params['handle'], $data); + // Work-around for yet another strange behavior in MCrypt. + // + // When encrypting in ECB mode, the IV is ignored. Yet + // mcrypt_enc_get_iv_size() returns a value larger than 0 + // even if ECB is used AND mcrypt_generic_init() complains + // if you don't pass an IV with length equal to the said + // return value. + // + // This probably would've been fine (even though still wasteful), + // but OpenSSL isn't that dumb and we need to make the process + // portable, so ... + $data = (mcrypt_enc_get_modes_name($params['handle']) !== 'ECB') + ? $params['iv'].mcrypt_generic($params['handle'], $data) + : mcrypt_generic($params['handle'], $data); mcrypt_generic_deinit($params['handle']); if ($params['handle'] !== $this->_handle) @@ -385,6 +400,12 @@ class CI_Encryption { { return FALSE; } + elseif ( ! isset($params['iv'])) + { + $params['iv'] = ($iv_size = openssl_cipher_iv_length($params['handle'])) + ? $this->_openssl_get_iv($iv_size) + : NULL; + } $data = openssl_encrypt( $data, @@ -450,20 +471,7 @@ class CI_Encryption { $data = base64_decode($data); } - if ( ! isset($params['iv'])) - { - $iv_size = $this->{'_'.$this->_driver.'_get_iv_size'}($params['handle']); - if ($iv_size = $this->{'_'.$this->_driver.'_get_iv_size'}($params['handle'])) - { - $params['iv'] = substr($data, 0, $iv_size); - $data = substr($data, $iv_size); - } - else - { - $params['iv'] = NULL; - } - } - elseif (strncmp($params['iv'], $data, $iv_size = strlen($params['iv'])) === 0) + if (isset($params['iv']) && strncmp($params['iv'], $data, $iv_size = strlen($params['iv'])) === 0) { $data = substr($data, $iv_size); } @@ -486,7 +494,28 @@ class CI_Encryption { { return FALSE; } - elseif (mcrypt_generic_init($params['handle'], $params['key'], $params['iv']) < 0) + elseif ( ! isset($params['iv'])) + { + if ($iv_size = mcrypt_enc_get_iv_size($params['handle'])) + { + if (mcrypt_enc_get_modes_name($params['handle']) !== 'ECB') + { + $params['iv'] = substr($data, 0, $iv_size); + $data = substr($data, $iv_size); + } + else + { + // MCrypt is dumb and this is ignored, only size matters + $params['iv'] = str_repeat("\x0", $iv_size); + } + } + else + { + $params['iv'] = NULL; + } + } + + if (mcrypt_generic_init($params['handle'], $params['key'], $params['iv']) < 0) { if ($params['handle'] !== $this->_handle) { @@ -519,6 +548,19 @@ class CI_Encryption { */ protected function _openssl_decrypt($data, $params) { + if ( ! isset($params['iv'])) + { + if ($iv_size = openssl_cipher_iv_length($params['handle'])) + { + $params['iv'] = substr($data, 0, $iv_size); + $data = substr($data, $iv_size); + } + else + { + $params['iv'] = NULL; + } + } + return empty($params['handle']) ? FALSE : openssl_decrypt( @@ -532,32 +574,6 @@ class CI_Encryption { // -------------------------------------------------------------------- - /** - * Get IV size via MCrypt - * - * @param resource $handle MCrypt module resource - * @return int - */ - protected function _mcrypt_get_iv_size($handle) - { - return mcrypt_enc_get_iv_size($handle); - } - - // -------------------------------------------------------------------- - - /** - * Get IV size via OpenSSL - * - * @param string $handle OpenSSL cipher method - * @return int - */ - protected function _openssl_get_iv_size($handle) - { - return openssl_cipher_iv_length($handle); - } - - // -------------------------------------------------------------------- - /** * Get IV via MCrypt * -- cgit v1.2.3-24-g4f1b From d9a48da095e2b76c65b1b9ebd26b6f06c94cb0e5 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Wed, 5 Feb 2014 14:10:28 +0200 Subject: CI_Encryption: Add Blowfish to compatibility list --- system/libraries/Encryption.php | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) (limited to 'system/libraries') diff --git a/system/libraries/Encryption.php b/system/libraries/Encryption.php index 2228ca3a6..d1aed7399 100644 --- a/system/libraries/Encryption.php +++ b/system/libraries/Encryption.php @@ -734,21 +734,25 @@ class CI_Encryption { 'aes-128' => 'rijndael-128', 'aes-192' => 'rijndael-128', 'aes-256' => 'rijndael-128', - 'des3-ede3' => 'tripledes' + 'des3-ede3' => 'tripledes', + 'bf' => 'blowfish', ), 'openssl' => array( 'rijndael-128' => 'aes-128', - 'tripledes' => 'des-ede3' + 'tripledes' => 'des-ede3', + 'blowfish' => 'bf' ) ); - // Notes regarding other seemingly matching ciphers between - // MCrypt and OpenSSL: + // Notes: + // + // - Blowfish is said to be supporting key sizes between + // 4 and 56 bytes, but it appears that between MCrypt and + // OpenSSL, only those of 16 and more bytes are compatible. + // + // Other seemingly matching ciphers between MCrypt, OpenSSL: // // - DES is compatible, but doesn't need an alias - // - Blowfish is NOT compatible - // mcrypt: 'blowfish', 'blowfish-compat' - // openssl: 'bf' // - CAST-128/CAST5 is NOT compatible // mcrypt: 'cast-128' // openssl: 'cast5' -- cgit v1.2.3-24-g4f1b From f401767c04a24677e11a3b6c4e3590e8b2e06e88 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Wed, 5 Feb 2014 18:51:15 +0200 Subject: CI_Encryption: More MCrypt/OpenSSL compatibility and get rid of the MCRYPT_MODE_* constants --- system/libraries/Encryption.php | 86 +++++++++++++++++++++++++++++++++-------- 1 file changed, 69 insertions(+), 17 deletions(-) (limited to 'system/libraries') diff --git a/system/libraries/Encryption.php b/system/libraries/Encryption.php index d1aed7399..51e390c91 100644 --- a/system/libraries/Encryption.php +++ b/system/libraries/Encryption.php @@ -81,6 +81,35 @@ class CI_Encryption { */ protected $_drivers = array(); + /** + * List of available modes + * + * @var array + */ + protected $_modes = array( + 'mcrypt' => array( + 'cbc' => 'cbc', + 'ecb' => 'ecb', + 'ofb' => 'nofb', + 'ofb8' => 'ofb', + 'cfb' => 'ncfb', + 'cfb8' => 'cfb', + 'ctr' => 'ctr', + 'stream' => 'stream' + ), + 'openssl' => array( + 'cbc' => 'cbc', + 'ecb' => 'ecb', + 'ofb' => 'ofb', + 'cfb' => 'cfb', + 'cfb8' => 'cfb8', + 'ctr' => 'ctr', + 'stream' => '', + 'gcm' => 'gcm', + 'xts' => 'xts' + ) + ); + /** * List of supported HMAC algorightms * @@ -116,12 +145,6 @@ class CI_Encryption { { return show_error('Encryption: Unable to find an available encryption driver.'); } - // Our configuration validates against the existence of MCRYPT_MODE_* constants, - // but MCrypt supports CTR mode without actually having a constant for it, so ... - elseif ($this->_drivers['mcrypt'] && ! defined('MCRYPT_MODE_CTR')) - { - define('MCRYPT_MODE_CTR', 'ctr'); - } $this->initialize($params); @@ -204,13 +227,14 @@ class CI_Encryption { if ( ! empty($params['mode'])) { - if ( ! defined('MCRYPT_MODE_'.$params['mode'])) + $params['mode'] = strtolower($params['mode']); + if ( ! isset($this->_modes['mcrypt'][$params['mode']])) { log_message('error', 'Encryption: MCrypt mode '.strtotupper($params['mode']).' is not available.'); } else { - $this->_mode = constant('MCRYPT_MODE_'.$params['mode']); + $this->_mode = $this->_modes['mcrypt'][$params['mode']]; } } @@ -254,13 +278,21 @@ class CI_Encryption { if ( ! empty($params['mode'])) { - $this->_mode = strtolower($params['mode']); + $params['mode'] = strtolower($params['mode']); + if ( ! isset($this->_modes['openssl'][$params['mode']])) + { + log_message('error', 'Encryption: OpenSSL mode '.strtotupper($params['mode']).' is not available.'); + } + else + { + $this->_mode = $this->_modes['openssl'][$params['mode']]; + } } if (isset($this->_cipher, $this->_mode)) { - // OpenSSL methods aren't suffixed with '-stream' for this mode - $handle = ($this->_mode === 'stream') + // This is mostly for the stream mode, which doesn't get suffixed in OpenSSL + $handle = empty($this->_mode) ? $this->_cipher : $this->_cipher.'-'.$this->_mode; @@ -356,10 +388,13 @@ class CI_Encryption { } // Use PKCS#7 padding in order to ensure compatibility with OpenSSL - // and other implementations outside of PHP - $block_size = mcrypt_enc_get_block_size($params['handle']); - $pad = $block_size - (strlen($data) % $block_size); - $data .= str_repeat(chr($pad), $pad); + // and other implementations outside of PHP. + if (in_array(strtolower(mcrypt_enc_get_modes_name($params['handle'])), array('cbc', 'ecb'), TRUE)) + { + $block_size = mcrypt_enc_get_block_size($params['handle']); + $pad = $block_size - (strlen($data) % $block_size); + $data .= str_repeat(chr($pad), $pad); + } // Work-around for yet another strange behavior in MCrypt. // @@ -526,6 +561,11 @@ class CI_Encryption { } $data = mdecrypt_generic($params['handle'], $data); + // Remove PKCS#7 padding, if necessary + if (in_array(strtolower(mcrypt_enc_get_modes_name($params['handle'])), array('cbc', 'ecb'), TRUE)) + { + $data = substr($data, 0, -ord($data[strlen($data)-1])); + } mcrypt_generic_deinit($params['handle']); if ($params['handle'] !== $this->_handle) @@ -533,8 +573,7 @@ class CI_Encryption { mcrypt_module_close($params['handle']); } - // Remove PKCS#7 padding - return substr($data, 0, -ord($data[strlen($data)-1])); + return $data; } // -------------------------------------------------------------------- @@ -664,6 +703,19 @@ class CI_Encryption { ); } + if (isset($params['mode'])) + { + $params['mode'] = strtolower($params['mode']); + if ( ! isset($this->_modes[$this->_driver][$params['mode']])) + { + return FALSE; + } + else + { + $params['mode'] = $this->_modes[$this->_driver][$params['mode']]; + } + } + $params = array( 'handle' => NULL, 'cipher' => isset($params['cipher']) ? $params['cipher'] : $this->_cipher, -- cgit v1.2.3-24-g4f1b From 8e20216f25624524d7d6e0322e85e6ccb47e3778 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Wed, 5 Feb 2014 18:59:55 +0200 Subject: More CI_Encryption improvements - Make OpenSSL the default driver if available (because MCrypt is stupid). - Require MCRYPT_DEV_URANDOM for the MCrypt availability check (because security; also, incidentally - it's faster that way ;)). --- system/libraries/Encryption.php | 52 +++++------------------------------------ 1 file changed, 6 insertions(+), 46 deletions(-) (limited to 'system/libraries') diff --git a/system/libraries/Encryption.php b/system/libraries/Encryption.php index 51e390c91..fe177fce3 100644 --- a/system/libraries/Encryption.php +++ b/system/libraries/Encryption.php @@ -135,7 +135,7 @@ class CI_Encryption { public function __construct(array $params = array()) { $this->_drivers = array( - 'mcrypt' => extension_loaded('mcrypt'), + 'mcrypt' => defined('MCRYPT_DEV_URANDOM'), // While OpenSSL is available for PHP 5.3.0, an IV parameter // for the encrypt/decrypt functions is only available since 5.3.3 'openssl' => (is_php('5.3.3') && extension_loaded('openssl')) @@ -188,9 +188,9 @@ class CI_Encryption { if (empty($this->_driver)) { - $this->_driver = ($this->_drivers['mcrypt'] === TRUE) - ? 'mcrypt' - : 'openssl'; + $this->_driver = ($this->_drivers['openssl'] === TRUE) + ? 'openssl' + : 'mcrypt'; log_message('debug', "Encryption: Auto-configured driver '".$this->_driver."'."); } @@ -372,7 +372,7 @@ class CI_Encryption { elseif ( ! isset($params['iv'])) { $params['iv'] = ($iv_size = mcrypt_enc_get_iv_size($params['handle'])) - ? $this->_mcrypt_get_iv($iv_size) + ? mcrypt_create_iv($iv_size, MCRYPT_DEV_URANDOM) : NULL; } @@ -438,7 +438,7 @@ class CI_Encryption { elseif ( ! isset($params['iv'])) { $params['iv'] = ($iv_size = openssl_cipher_iv_length($params['handle'])) - ? $this->_openssl_get_iv($iv_size) + ? openssl_random_pseudo_bytes($iv_size) : NULL; } @@ -613,46 +613,6 @@ class CI_Encryption { // -------------------------------------------------------------------- - /** - * Get IV via MCrypt - * - * @param int $size - * @return int - */ - protected function _mcrypt_get_iv($size) - { - // If /dev/urandom is available - use it, otherwise there's - // also /dev/random, but it is highly unlikely that it would - // be available while /dev/urandom is not and it is known to be - // blocking anyway. - if (defined(MCRYPT_DEV_URANDOM)) - { - $source = MCRYPT_DEV_URANDOM; - } - else - { - $source = MCRYPT_RAND; - is_php('5.3') OR srand(microtime(TRUE)); - } - - return mcrypt_create_iv($size, $source); - } - - // -------------------------------------------------------------------- - - /** - * Get IV via OpenSSL - * - * @param int $size IV size - * @return int - */ - protected function _openssl_get_iv($size) - { - return openssl_random_pseudo_bytes($size); - } - - // -------------------------------------------------------------------- - /** * Get params * -- cgit v1.2.3-24-g4f1b From 8d33a9a4a8ac924678ae5bba6387ca7fce206f4b Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Wed, 5 Feb 2014 23:11:23 +0200 Subject: CI_Encryption: HMAC to not be derived from the encryption key --- system/libraries/Encryption.php | 114 ++++++++++++++++++++-------------------- 1 file changed, 56 insertions(+), 58 deletions(-) (limited to 'system/libraries') diff --git a/system/libraries/Encryption.php b/system/libraries/Encryption.php index fe177fce3..36975e585 100644 --- a/system/libraries/Encryption.php +++ b/system/libraries/Encryption.php @@ -324,31 +324,27 @@ class CI_Encryption { { return FALSE; } + elseif ( ! isset($params['key'])) + { + if ( ! isset($this->_key)) + { + return show_error('Encryption: You are required to set an encryption key in your configuration.'); + } + + $params['key'] = $this->hkdf($this->_key, 'sha512', NULL, strlen($this->_key), 'encryption'); + } if (($data = $this->{'_'.$this->_driver.'_encrypt'}($data, $params)) === FALSE) { return FALSE; } - if ($params['base64']) - { - $data = base64_encode($data); - } + $params['base64'] && $data = base64_encode($data); - if ($params['hmac'] !== FALSE) + if (isset($params['hmac_digest'])) { - if ( ! isset($params['hmac']['key'])) - { - $params['hmac']['key'] = $this->hkdf( - $params['key'], - $params['hmac']['digest'], - NULL, - NULL, - 'authentication' - ); - } - - return hash_hmac($params['hmac']['digest'], $data, $params['hmac']['key'], ! $params['base64']).$data; + isset($params['hmac_key']) OR $params['hmac_key'] = $this->hkdf($this->_key, 'sha512', NULL, NULL, 'authentication'); + return hash_hmac($params['hmac_digest'], $data, $params['hmac_key'], ! $params['base64']).$data; } return $data; @@ -473,29 +469,29 @@ class CI_Encryption { { return FALSE; } - - if ($params['hmac'] !== FALSE) + elseif ( ! isset($params['key'])) { - if ( ! isset($params['hmac']['key'])) + if ( ! isset($this->_key)) { - $params['hmac']['key'] = $this->hkdf( - $params['key'], - $params['hmac']['digest'], - NULL, - NULL, - 'authentication' - ); + return show_error('Encryption: You are required to set an encryption key in your configuration.'); } + $params['key'] = $this->hkdf($this->_key, 'sha512', NULL, strlen($this->_key), 'encryption'); + } + + if (isset($params['hmac_digest'])) + { + isset($params['hmac_key']) OR $params['hmac_key'] = $this->hkdf($this->_key, 'sha512', NULL, NULL, 'authentication'); + // This might look illogical, but it is done during encryption as well ... // The 'base64' value is effectively an inverted "raw data" parameter $digest_size = ($params['base64']) - ? $this->_digests[$params['hmac']['digest']] * 2 - : $this->_digests[$params['hmac']['digest']]; + ? $this->_digests[$params['hmac_digest']] * 2 + : $this->_digests[$params['hmac_digest']]; $hmac = substr($data, 0, $digest_size); $data = substr($data, $digest_size); - if ($hmac !== hash_hmac($params['hmac']['digest'], $data, $params['hmac']['key'], ! $params['base64'])) + if ($hmac !== hash_hmac($params['hmac_digest'], $data, $params['hmac_key'], ! $params['base64'])) { return FALSE; } @@ -628,9 +624,10 @@ class CI_Encryption { 'handle' => $this->_handle, 'cipher' => $this->_cipher, 'mode' => $this->_mode, - 'key' => $this->_key, + 'key' => NULL, 'base64' => TRUE, - 'hmac' => $this->_mode === 'gcm' ? FALSE : array('digest' => 'sha512', 'key' => NULL) + 'hmac_digest' => ($this->_mode !== 'gcm' ? 'sha512' : NULL), + 'hmac_key' => NULL ) : FALSE; } @@ -639,51 +636,52 @@ class CI_Encryption { return FALSE; } - if ($params['mode'] === 'gcm') - { - $params['hmac'] = FALSE; - } - elseif ( ! isset($params['hmac']) OR ( ! is_array($params['hmac']) && $params['hmac'] !== FALSE)) - { - $params['hmac'] = array( - 'digest' => 'sha512', - 'key' => NULL - ); - } - elseif (is_array($params['hmac'])) + if (isset($params['mode'])) { - if (isset($params['hmac']['digest']) && ! isset($this->_digests[$params['hmac']['digest']])) + $params['mode'] = strtolower($params['mode']); + if ( ! isset($this->_modes[$this->_driver][$params['mode']])) { return FALSE; } - - $params['hmac'] = array( - 'digest' => isset($params['hmac']['digest']) ? $params['hmac']['digest'] : 'sha512', - 'key' => isset($params['hmac']['key']) ? $params['hmac']['key'] : NULL - ); + else + { + $params['mode'] = $this->_modes[$this->_driver][$params['mode']]; + } } - if (isset($params['mode'])) + if ($params['mode'] === 'gcm' OR isset($params['hmac']) && $params['hmac'] === FALSE) { - $params['mode'] = strtolower($params['mode']); - if ( ! isset($this->_modes[$this->_driver][$params['mode']])) + $params['hmac_digest'] = $params['hmac_key'] = NULL; + } + else + { + if ( ! isset($params['hmac_key'])) { return FALSE; } + elseif (isset($params['hmac_digest'])) + { + $params['hmac_digest'] = strtolower($params['hmac_digest']); + if ( ! isset($this->_digests[$params['hmac_digest']])) + { + return FALSE; + } + } else { - $params['mode'] = $this->_modes[$this->_driver][$params['mode']]; + $params['hmac_digest'] = 'sha512'; } } $params = array( 'handle' => NULL, - 'cipher' => isset($params['cipher']) ? $params['cipher'] : $this->_cipher, - 'mode' => isset($params['mode']) ? $params['mode'] : $this->_mode, - 'key' => isset($params['key']) ? $params['key'] : $this->_key, + 'cipher' => $params['cipher'], + 'mode' => $params['mode'], + 'key' => $params['key'], 'iv' => isset($params['iv']) ? $params['iv'] : NULL, 'base64' => isset($params['base64']) ? $params['base64'] : TRUE, - 'hmac' => $params['hmac'] + 'hmac_digest' => $params['hmac_digest'], + 'hmac_key' => $params['hmac_key'] ); $this->_cipher_alias($params['cipher']); -- cgit v1.2.3-24-g4f1b From 7c5544817de29222aa2d79ac7445122d57ad62c6 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Thu, 6 Feb 2014 02:38:27 +0200 Subject: CI_Encryption: Time-attack-safe HMAC verification --- system/libraries/Encryption.php | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) (limited to 'system/libraries') diff --git a/system/libraries/Encryption.php b/system/libraries/Encryption.php index 36975e585..f5950ee46 100644 --- a/system/libraries/Encryption.php +++ b/system/libraries/Encryption.php @@ -481,17 +481,31 @@ class CI_Encryption { if (isset($params['hmac_digest'])) { - isset($params['hmac_key']) OR $params['hmac_key'] = $this->hkdf($this->_key, 'sha512', NULL, NULL, 'authentication'); - // This might look illogical, but it is done during encryption as well ... // The 'base64' value is effectively an inverted "raw data" parameter $digest_size = ($params['base64']) ? $this->_digests[$params['hmac_digest']] * 2 : $this->_digests[$params['hmac_digest']]; - $hmac = substr($data, 0, $digest_size); + + if (strlen($data) <= $digest_size) + { + return FALSE; + } + + $hmac_input = substr($data, 0, $digest_size); $data = substr($data, $digest_size); - if ($hmac !== hash_hmac($params['hmac_digest'], $data, $params['hmac_key'], ! $params['base64'])) + isset($params['hmac_key']) OR $params['hmac_key'] = $this->hkdf($this->_key, 'sha512', NULL, NULL, 'authentication'); + $hmac_check = hash_hmac($params['hmac_digest'], $data, $params['hmac_key'], ! $params['base64']); + + // Time-attack-safe comparison + $diff = 0; + for ($i = 0; $i < $digest_size; $i++) + { + $diff |= ord($hmac_input[$i]) ^ ord($hmac_check[$i]); + } + + if ($diff !== 0) { return FALSE; } -- cgit v1.2.3-24-g4f1b From e8088d693d6bd8b08c1cdc397bbdebd7067844a5 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Thu, 6 Feb 2014 05:01:48 +0200 Subject: CI_Encryption: CAST-128/CAST5 and RC4/ARCFour compatibility --- system/libraries/Encryption.php | 65 +++++++++++++++++++++++++++++++---------- 1 file changed, 50 insertions(+), 15 deletions(-) (limited to 'system/libraries') diff --git a/system/libraries/Encryption.php b/system/libraries/Encryption.php index f5950ee46..583ddac3b 100644 --- a/system/libraries/Encryption.php +++ b/system/libraries/Encryption.php @@ -367,11 +367,21 @@ class CI_Encryption { } elseif ( ! isset($params['iv'])) { - $params['iv'] = ($iv_size = mcrypt_enc_get_iv_size($params['handle'])) + // The greater-than-1 comparison is mostly a work-around for a bug, + // where 1 is returned for ARCFour instead of 0. + $params['iv'] = (($iv_size = mcrypt_enc_get_iv_size($params['handle'])) > 1) ? mcrypt_create_iv($iv_size, MCRYPT_DEV_URANDOM) : NULL; } + // CAST-128 compatibility (http://tools.ietf.org/rfc/rfc2144.txt) + // + // RFC2144 says that keys shorter than 16 bytes are to be padded with + // zero bytes to 16 bytes, but (surprise) MCrypt doesn't do that. + if ($params['cipher'] === 'cast-128' && ($kl = strlen($params['key'])) < 16) + { + $params['key'] .= str_repeat("\x0", 16 - $kl); + } if (mcrypt_generic_init($params['handle'], $params['key'], $params['iv']) < 0) { @@ -541,7 +551,9 @@ class CI_Encryption { } elseif ( ! isset($params['iv'])) { - if ($iv_size = mcrypt_enc_get_iv_size($params['handle'])) + // The greater-than-1 comparison is mostly a work-around for a bug, + // where 1 is returned for ARCFour instead of 0. + if (($iv_size = mcrypt_enc_get_iv_size($params['handle'])) > 1) { if (mcrypt_enc_get_modes_name($params['handle']) !== 'ECB') { @@ -560,6 +572,15 @@ class CI_Encryption { } } + // CAST-128 compatibility (http://tools.ietf.org/rfc/rfc2144.txt) + // + // RFC2144 says that keys shorter than 16 bytes are to be padded with + // zero bytes to 16 bytes, but (surprise) MCrypt doesn't do that. + if ($params['cipher'] === 'cast-128' && ($kl = strlen($params['key'])) < 16) + { + $params['key'] .= str_repeat("\x0", 16 - $kl); + } + if (mcrypt_generic_init($params['handle'], $params['key'], $params['iv']) < 0) { if ($params['handle'] !== $this->_handle) @@ -760,35 +781,49 @@ class CI_Encryption { 'aes-256' => 'rijndael-128', 'des3-ede3' => 'tripledes', 'bf' => 'blowfish', + 'cast5' => 'cast-128', + 'rc4' => 'arcfour', + 'rc4-40' => 'arcfour' ), 'openssl' => array( 'rijndael-128' => 'aes-128', 'tripledes' => 'des-ede3', - 'blowfish' => 'bf' + 'blowfish' => 'bf', + 'cast-128' => 'cast5', + 'arcfour' => 'rc4-40', + 'rc4' => 'rc4-40' ) ); // Notes: // + // - Rijndael-128 is, at the same time all three of AES-128, + // AES-192 and AES-256. The only difference between them is + // the key size. Rijndael-192, Rijndael-256 on the other hand + // also have different block sizes and are NOT AES-compatible. + // // - Blowfish is said to be supporting key sizes between // 4 and 56 bytes, but it appears that between MCrypt and // OpenSSL, only those of 16 and more bytes are compatible. + // Also, don't know what MCrypt's 'blowfish-compat' is. // - // Other seemingly matching ciphers between MCrypt, OpenSSL: + // - CAST-128/CAST5 produces a longer cipher when encrypted via + // OpenSSL, but (strangely enough) can be decrypted by either + // extension anyway. + // Also, RFC2144 says that the cipher supports key sizes + // between 5 and 16 bytes by the implementation actually + // zero-padding them to 16 bytes, but MCrypt doesn't do that. // - // - DES is compatible, but doesn't need an alias - // - CAST-128/CAST5 is NOT compatible - // mcrypt: 'cast-128' - // openssl: 'cast5' - // - RC2 is NOT compatible - // mcrypt: 'rc2' - // openssl: 'rc2', 'rc2-40', 'rc2-64' + // - RC4 (ARCFour) has a strange implementation under OpenSSL. + // Its 'rc4-40' cipher method seems to work flawlessly, yet + // there's another one, 'rc4' that only works with a 16-byte key. // - // To avoid any other confusion due to a popular (but incorrect) - // belief, it should also be noted that Rijndael-192/256 are NOT - // the same ciphers as AES-192/256 like Rijndael-128 and AES-256 is. + // - DES is compatible, but doesn't need an alias. + // + // Other seemingly matching ciphers between MCrypt, OpenSSL: // - // All compatibility tests were done in CBC mode. + // - RC2 is NOT compatible and only an obscure forum post + // confirms that it is MCrypt's fault. } if (isset($dictionary[$this->_driver][$cipher])) -- cgit v1.2.3-24-g4f1b From 3aa781a65267d72000009df0fa2feee5cb3bdd8d Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Thu, 6 Feb 2014 05:34:19 +0200 Subject: Make CI_Session's HMAC comparison time-attack-safe --- system/libraries/Session/drivers/Session_cookie.php | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) (limited to 'system/libraries') diff --git a/system/libraries/Session/drivers/Session_cookie.php b/system/libraries/Session/drivers/Session_cookie.php index 971dfeabe..c8dfad6c9 100644 --- a/system/libraries/Session/drivers/Session_cookie.php +++ b/system/libraries/Session/drivers/Session_cookie.php @@ -395,7 +395,15 @@ class CI_Session_cookie extends CI_Session_driver { $hmac = substr($session, $len); $session = substr($session, 0, $len); - if ($hmac !== hash_hmac('sha1', $session, $this->encryption_key)) + // Time-attack-safe comparison + $hmac_check = hash_hmac('sha1', $session, $this->encryption_key); + $diff = 0; + for ($i = 0; $i < 40; $i++) + { + $diff |= ord($hmac[$i]) ^ ord($hmac_check[$i]); + } + + if ($diff !== 0) { log_message('error', 'The session cookie data did not match what was expected.'); $this->sess_destroy(); -- cgit v1.2.3-24-g4f1b From 81e10644861c86437cf197b54af096894b41cd63 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Fri, 7 Feb 2014 01:43:36 +0200 Subject: CI_Encryption: Optimizations and test cases --- system/libraries/Encryption.php | 44 +++++++++++++++++------------------------ 1 file changed, 18 insertions(+), 26 deletions(-) (limited to 'system/libraries') diff --git a/system/libraries/Encryption.php b/system/libraries/Encryption.php index 583ddac3b..e03e278fa 100644 --- a/system/libraries/Encryption.php +++ b/system/libraries/Encryption.php @@ -44,7 +44,7 @@ class CI_Encryption { * * @var string */ - protected $_cipher = 'rijndael-128'; + protected $_cipher = 'aes-128'; /** * Cipher mode @@ -147,11 +147,9 @@ class CI_Encryption { } $this->initialize($params); - - isset($this->_key) OR $this->_key = config_item('encryption_key'); - if (empty($this->_key)) + if ( ! isset($this->_key) && strlen($key = config_item('encryption_key')) > 0) { - return show_error('Encryption: You are required to set an encryption key in your configuration.'); + $this->_key = $key; } log_message('debug', 'Encryption Class Initialized'); @@ -324,15 +322,8 @@ class CI_Encryption { { return FALSE; } - elseif ( ! isset($params['key'])) - { - if ( ! isset($this->_key)) - { - return show_error('Encryption: You are required to set an encryption key in your configuration.'); - } - $params['key'] = $this->hkdf($this->_key, 'sha512', NULL, strlen($this->_key), 'encryption'); - } + isset($params['key']) OR $params['key'] = $this->hkdf($this->_key, 'sha512', NULL, strlen($this->_key), 'encryption'); if (($data = $this->{'_'.$this->_driver.'_encrypt'}($data, $params)) === FALSE) { @@ -479,15 +470,6 @@ class CI_Encryption { { return FALSE; } - elseif ( ! isset($params['key'])) - { - if ( ! isset($this->_key)) - { - return show_error('Encryption: You are required to set an encryption key in your configuration.'); - } - - $params['key'] = $this->hkdf($this->_key, 'sha512', NULL, strlen($this->_key), 'encryption'); - } if (isset($params['hmac_digest'])) { @@ -531,6 +513,8 @@ class CI_Encryption { $data = substr($data, $iv_size); } + isset($params['key']) OR $params['key'] = $this->hkdf($this->_key, 'sha512', NULL, strlen($this->_key), 'encryption'); + return $this->{'_'.$this->_driver.'_decrypt'}($data, $params); } @@ -684,7 +668,7 @@ class CI_Encryption { } } - if ($params['mode'] === 'gcm' OR isset($params['hmac']) && $params['hmac'] === FALSE) + if ($params['mode'] === 'gcm' OR (isset($params['hmac']) && $params['hmac'] === FALSE)) { $params['hmac_digest'] = $params['hmac_key'] = NULL; } @@ -884,9 +868,17 @@ class CI_Encryption { */ public function __get($key) { - return in_array($key, array('cipher', 'mode', 'driver', 'drivers', 'digests'), TRUE) - ? $this->{'_'.$key} - : NULL; + // Because aliases + if ($key === 'mode') + { + return array_search($this->_mode, $this->_modes[$this->_driver], TRUE); + } + elseif (in_array($key, array('cipher', 'driver', 'drivers', 'digests'), TRUE)) + { + return $this->{'_'.$key}; + } + + return NULL; } } -- cgit v1.2.3-24-g4f1b From 505b3d6b42d608b8555b62b78134f697a1f6d09f Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Sat, 8 Feb 2014 18:24:00 +0200 Subject: Make CI_Email::set_alt_message() parameter mandatory (optional doesn't make sense) --- system/libraries/Email.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system/libraries') diff --git a/system/libraries/Email.php b/system/libraries/Email.php index f4efff882..88925e03f 100644 --- a/system/libraries/Email.php +++ b/system/libraries/Email.php @@ -822,7 +822,7 @@ class CI_Email { * @param string * @return CI_Email */ - public function set_alt_message($str = '') + public function set_alt_message($str) { $this->alt_message = (string) $str; return $this; -- cgit v1.2.3-24-g4f1b From a89c1dabd11e8628106b1629f76ec9fc65c20085 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Sat, 8 Feb 2014 19:03:35 +0200 Subject: Method chaining support for FV set_data(), reset_validation() --- system/libraries/Form_validation.php | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) (limited to 'system/libraries') diff --git a/system/libraries/Form_validation.php b/system/libraries/Form_validation.php index 58485916c..7c441409f 100644 --- a/system/libraries/Form_validation.php +++ b/system/libraries/Form_validation.php @@ -252,7 +252,7 @@ class CI_Form_validation { * each array due to the limitations of CI's singleton * * @param array $data - * @return void + * @return CI_Form_validation */ public function set_data(array $data) { @@ -260,6 +260,8 @@ class CI_Form_validation { { $this->validation_data = $data; } + + return $this; } // -------------------------------------------------------------------- @@ -1536,7 +1538,7 @@ class CI_Form_validation { * Prevents subsequent validation routines from being affected by the * results of any previous validation routine due to the CI singleton. * - * @return void + * @return CI_Form_validation */ public function reset_validation() { @@ -1545,6 +1547,7 @@ class CI_Form_validation { $this->_error_array = array(); $this->_error_messages = array(); $this->error_string = ''; + return $this; } } -- cgit v1.2.3-24-g4f1b From 6f6102c805198101fad36024b82692ebce20f2c8 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Sat, 8 Feb 2014 19:11:40 +0200 Subject: Add method chaining support to Calendar & Pagination libs --- system/libraries/Calendar.php | 10 +++++++--- system/libraries/Pagination.php | 4 +++- 2 files changed, 10 insertions(+), 4 deletions(-) (limited to 'system/libraries') diff --git a/system/libraries/Calendar.php b/system/libraries/Calendar.php index fc6599931..610b427cf 100644 --- a/system/libraries/Calendar.php +++ b/system/libraries/Calendar.php @@ -139,7 +139,7 @@ class CI_Calendar { * Accepts an associative array as input, containing display preferences * * @param array config preferences - * @return void + * @return CI_Calendar */ public function initialize($config = array()) { @@ -156,6 +156,8 @@ class CI_Calendar { { $this->next_prev_url = $this->CI->config->site_url($this->CI->router->class.'/'.$this->CI->router->method); } + + return $this; } // -------------------------------------------------------------------- @@ -513,7 +515,7 @@ class CI_Calendar { * Harvests the data within the template {pseudo-variables} * used to display the calendar * - * @return void + * @return CI_Calendar */ public function parse_template() { @@ -521,7 +523,7 @@ class CI_Calendar { if ($this->template === '') { - return; + return $this; } $today = array('cal_cell_start_today', 'cal_cell_content_today', 'cal_cell_no_content_today', 'cal_cell_end_today'); @@ -537,6 +539,8 @@ class CI_Calendar { $this->temp[$val] = $this->temp[substr($val, 0, -6)]; } } + + return $this; } } diff --git a/system/libraries/Pagination.php b/system/libraries/Pagination.php index c6ffd03d4..f67cb47f8 100644 --- a/system/libraries/Pagination.php +++ b/system/libraries/Pagination.php @@ -314,7 +314,7 @@ class CI_Pagination { * Initialize Preferences * * @param array $params Initialization parameters - * @return void + * @return CI_Pagination */ public function initialize($params = array()) { @@ -342,6 +342,8 @@ class CI_Pagination { } } } + + return $this; } // -------------------------------------------------------------------- -- cgit v1.2.3-24-g4f1b From 1f5909527f5a4984d4fa0a1f3bd51aa5bd850406 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Sat, 8 Feb 2014 19:50:26 +0200 Subject: Add method chaining support to CI_Table --- system/libraries/Table.php | 72 ++++++++++++++++++++++++---------------------- 1 file changed, 38 insertions(+), 34 deletions(-) (limited to 'system/libraries') diff --git a/system/libraries/Table.php b/system/libraries/Table.php index b77fcf19d..1d4320855 100644 --- a/system/libraries/Table.php +++ b/system/libraries/Table.php @@ -117,7 +117,7 @@ class CI_Table { /** * Set the template * - * @param array + * @param array $template * @return bool */ public function set_template($template) @@ -139,12 +139,13 @@ class CI_Table { * Can be passed as an array or discreet params * * @param mixed - * @return void + * @return CI_Table */ public function set_heading($args = array()) { $args = func_get_args(); $this->heading = $this->_prep_args($args); + return $this; } // -------------------------------------------------------------------- @@ -155,9 +156,9 @@ class CI_Table { * columns. This allows a single array with many elements to be * displayed in a table that has a fixed column count. * - * @param array - * @param int - * @return void + * @param array $array + * @param int $col_limit + * @return array */ public function make_columns($array = array(), $col_limit = 0) { @@ -202,12 +203,13 @@ class CI_Table { * * Can be passed as an array or discreet params * - * @param mixed - * @return void + * @param mixed $value + * @return CI_Table */ public function set_empty($value) { $this->empty_cells = $value; + return $this; } // -------------------------------------------------------------------- @@ -218,12 +220,13 @@ class CI_Table { * Can be passed as an array or discreet params * * @param mixed - * @return void + * @return CI_Table */ public function add_row($args = array()) { $args = func_get_args(); $this->rows[] = $this->_prep_args($args); + return $this; } // -------------------------------------------------------------------- @@ -271,8 +274,8 @@ class CI_Table { /** * Add a table caption * - * @param string - * @return void + * @param string $caption + * @return CI_Table */ public function set_caption($caption) { @@ -284,7 +287,7 @@ class CI_Table { /** * Generate the table * - * @param mixed + * @param mixed $table_data * @return string */ public function generate($table_data = NULL) @@ -417,13 +420,14 @@ class CI_Table { /** * Clears the table arrays. Useful if multiple tables are being generated * - * @return void + * @return 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; + return $this; } // -------------------------------------------------------------------- @@ -528,31 +532,31 @@ class CI_Table { protected function _default_template() { return array( - 'table_open' => '', + 'table_open' => '
', - 'thead_open' => '', - 'thead_close' => '', + 'thead_open' => '', + 'thead_close' => '', - 'heading_row_start' => '', - 'heading_row_end' => '', - 'heading_cell_start' => '', + 'heading_row_start' => '', + 'heading_row_end' => '', + 'heading_cell_start' => '', - 'tbody_open' => '', - 'tbody_close' => '', + 'tbody_open' => '', + 'tbody_close' => '', - 'row_start' => '', - 'row_end' => '', - 'cell_start' => '', + 'row_start' => '', + 'row_end' => '', + 'cell_start' => '', - 'row_alt_start' => '', - 'row_alt_end' => '', - 'cell_alt_start' => '', + 'row_alt_start' => '', + 'row_alt_end' => '', + 'cell_alt_start' => '', - 'table_close' => '
', - 'heading_cell_end' => '
', + 'heading_cell_end' => '
', - 'cell_end' => '
', + 'cell_end' => '
', - 'cell_alt_end' => '
', + 'cell_alt_end' => '
' - ); + 'table_close' => '' + ); } } -- cgit v1.2.3-24-g4f1b From d8a561a9cd12317342dd2f28aea8d76e93efce0d Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Sat, 8 Feb 2014 20:14:52 +0200 Subject: [ci skip] Deprecate the Javascript library --- system/libraries/Javascript.php | 1 + 1 file changed, 1 insertion(+) (limited to 'system/libraries') diff --git a/system/libraries/Javascript.php b/system/libraries/Javascript.php index 26a16850c..34a216c22 100644 --- a/system/libraries/Javascript.php +++ b/system/libraries/Javascript.php @@ -34,6 +34,7 @@ defined('BASEPATH') OR exit('No direct script access allowed'); * @category Javascript * @author EllisLab Dev Team * @link http://codeigniter.com/user_guide/libraries/javascript.html + * @deprecated 3.0.0 This was never a good idea in the first place. */ class CI_Javascript { -- cgit v1.2.3-24-g4f1b From 4b450651ed3b9413be0245401da706c218850f53 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Mon, 10 Feb 2014 06:59:54 +0200 Subject: CI_Encryption: Rename 'base64' parameter to 'raw_data' and add docs --- system/libraries/Encryption.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'system/libraries') diff --git a/system/libraries/Encryption.php b/system/libraries/Encryption.php index e03e278fa..3a5409839 100644 --- a/system/libraries/Encryption.php +++ b/system/libraries/Encryption.php @@ -698,7 +698,7 @@ class CI_Encryption { 'mode' => $params['mode'], 'key' => $params['key'], 'iv' => isset($params['iv']) ? $params['iv'] : NULL, - 'base64' => isset($params['base64']) ? $params['base64'] : TRUE, + 'base64' => isset($params['raw_data']) ? ! $params['raw_data'] : FALSE, 'hmac_digest' => $params['hmac_digest'], 'hmac_key' => $params['hmac_key'] ); @@ -825,8 +825,8 @@ class CI_Encryption { * @param $key Input key * @param $digest A SHA-2 hashing algorithm * @param $salt Optional salt - * @param $info Optional context/application-specific info * @param $length Output length (defaults to the selected digest size) + * @param $info Optional context/application-specific info * @return string A pseudo-random key */ public function hkdf($key, $digest = 'sha512', $salt = NULL, $length = NULL, $info = '') -- cgit v1.2.3-24-g4f1b From e52fc267a93fd3627951ddc7c5109b573a871727 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Tue, 11 Feb 2014 13:27:01 +0200 Subject: Fix issue #43 --- system/libraries/Image_lib.php | 71 +++++++++++++++++++++++++----------------- 1 file changed, 43 insertions(+), 28 deletions(-) (limited to 'system/libraries') diff --git a/system/libraries/Image_lib.php b/system/libraries/Image_lib.php index b6a11a3a5..bb0ea7b50 100644 --- a/system/libraries/Image_lib.php +++ b/system/libraries/Image_lib.php @@ -1245,22 +1245,37 @@ class CI_Image_lib { // offset flips itself automatically if ($this->wm_vrt_alignment === 'B') + { $this->wm_vrt_offset = $this->wm_vrt_offset * -1; + } if ($this->wm_hor_alignment === 'R') + { $this->wm_hor_offset = $this->wm_hor_offset * -1; + } // Set font width and height // These are calculated differently depending on // whether we are using the true type font or not if ($this->wm_use_truetype === TRUE) { - if ($this->wm_font_size === '') + if (empty($this->wm_font_size)) { $this->wm_font_size = 17; } - $fontwidth = $this->wm_font_size-($this->wm_font_size/4); + if (function_exists('imagettfbbox')) + { + $temp = imagettfbbox($this->wm_font_size, 0, $this->wm_font_path, $this->wm_text); + $temp = $temp[2] - $temp[0]; + + $fontwidth = $temp / strlen($this->wm_text); + } + else + { + $fontwidth = $this->wm_font_size - ($this->wm_font_size / 4); + } + $fontheight = $this->wm_font_size; $this->wm_vrt_offset += $this->wm_font_size; } @@ -1368,45 +1383,45 @@ class CI_Image_lib { public function image_create_gd($path = '', $image_type = '') { if ($path === '') + { $path = $this->full_src_path; + } if ($image_type === '') + { $image_type = $this->image_type; + } switch ($image_type) { - case 1 : - if ( ! function_exists('imagecreatefromgif')) - { - $this->set_error(array('imglib_unsupported_imagecreate', 'imglib_gif_not_supported')); - return FALSE; - } + case 1 : + if ( ! function_exists('imagecreatefromgif')) + { + $this->set_error(array('imglib_unsupported_imagecreate', 'imglib_gif_not_supported')); + return FALSE; + } - return imagecreatefromgif($path); - break; + return imagecreatefromgif($path); case 2 : - if ( ! function_exists('imagecreatefromjpeg')) - { - $this->set_error(array('imglib_unsupported_imagecreate', 'imglib_jpg_not_supported')); - return FALSE; - } + if ( ! function_exists('imagecreatefromjpeg')) + { + $this->set_error(array('imglib_unsupported_imagecreate', 'imglib_jpg_not_supported')); + return FALSE; + } - return imagecreatefromjpeg($path); - break; + return imagecreatefromjpeg($path); case 3 : - if ( ! function_exists('imagecreatefrompng')) - { - $this->set_error(array('imglib_unsupported_imagecreate', 'imglib_png_not_supported')); - return FALSE; - } - - return imagecreatefrompng($path); - break; + if ( ! function_exists('imagecreatefrompng')) + { + $this->set_error(array('imglib_unsupported_imagecreate', 'imglib_png_not_supported')); + return FALSE; + } + return imagecreatefrompng($path); + default: + $this->set_error(array('imglib_unsupported_imagecreate')); + return FALSE; } - - $this->set_error(array('imglib_unsupported_imagecreate')); - return FALSE; } // -------------------------------------------------------------------- -- cgit v1.2.3-24-g4f1b From 05983fcb5b8f04fb895c025e28ef6ffc44a5f602 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Tue, 11 Feb 2014 16:51:43 +0200 Subject: A bug fix and optimizations in CI_Table --- system/libraries/Table.php | 76 ++++++++++++++++------------------------------ 1 file changed, 27 insertions(+), 49 deletions(-) (limited to 'system/libraries') diff --git a/system/libraries/Table.php b/system/libraries/Table.php index 1d4320855..58016e9b8 100644 --- a/system/libraries/Table.php +++ b/system/libraries/Table.php @@ -294,21 +294,20 @@ class CI_Table { { // The table data can optionally be passed to this function // either as a database result object or an array - if ($table_data !== NULL) + if ( ! empty($table_data)) { - if (is_object($table_data)) + if ($table_data instanceof CI_DB_result) { - $this->_set_from_object($table_data); + $this->_set_from_db_result($table_data); } elseif (is_array($table_data)) { - $set_heading = (count($this->heading) !== 0 OR $this->auto_heading !== FALSE); - $this->_set_from_array($table_data, $set_heading); + $this->_set_from_array($table_data); } } // Is there anything to display? No? Smite them! - if (count($this->heading) === 0 && count($this->rows) === 0) + if (empty($this->heading) && empty($this->rows)) { return 'Undefined table data'; } @@ -316,8 +315,11 @@ class CI_Table { // Compile and validate the template date $this->_compile_template(); - // set a custom cell manipulation function to a locally scoped variable so its callable - $function = $this->function; + // Validate a possibly existing custom cell manipulation function + if ($this->function !== FALSE && ! is_callable($this->function)) + { + $this->function = FALSE; + } // Build the table! @@ -326,11 +328,11 @@ class CI_Table { // Add any caption here if ($this->caption) { - $out .= $this->newline.''.$this->caption.''.$this->newline; + $out .= ''.$this->caption.''.$this->newline; } // Is there a table heading to display? - if (count($this->heading) > 0) + if ( ! empty($this->heading)) { $out .= $this->template['thead_open'].$this->newline.$this->template['heading_row_start'].$this->newline; @@ -353,7 +355,7 @@ class CI_Table { } // Build the table rows - if (count($this->rows) > 0) + if ( ! empty($this->rows)) { $out .= $this->template['tbody_open'].$this->newline; @@ -389,9 +391,9 @@ class CI_Table { { $out .= $this->empty_cells; } - elseif ($function !== FALSE && is_callable($function)) + elseif ($this->function !== FALSE) { - $out .= call_user_func($function, $cell); + $out .= call_user_func($this->function, $cell); } else { @@ -435,34 +437,20 @@ class CI_Table { /** * Set table data from a database result object * - * @param object + * @param CI_DB_result $db_result Database result object * @return void */ - protected function _set_from_object($query) + protected function _set_from_db_result($object) { - if ( ! is_object($query)) - { - return; - } - // First generate the headings from the table column names - if (count($this->heading) === 0) + if ($this->auto_heading === TRUE && empty($this->heading)) { - if ( ! is_callable(array($query, 'list_fields'))) - { - return; - } - - $this->heading = $this->_prep_args($query->list_fields()); + $this->heading = $this->_prep_args($object->list_fields()); } - // Next blast through the result array and build out the rows - if ($query->num_rows() > 0) + foreach ($object->result_array() as $row) { - foreach ($query->result_array() as $row) - { - $this->rows[] = $this->_prep_args($row); - } + $this->rows[] = $this->_prep_args($row); } } @@ -471,29 +459,19 @@ class CI_Table { /** * Set table data from an array * - * @param array - * @param bool + * @param array $data * @return void */ - protected function _set_from_array($data, $set_heading = TRUE) + protected function _set_from_array($data) { - if ( ! is_array($data) OR count($data) === 0) + if ($this->auto_heading === TRUE && empty($this->heading)) { - return FALSE; + $this->heading = $this->_prep_args(array_shift($data)); } - $i = 0; - foreach ($data as $row) + foreach ($data as &$row) { - // If a heading hasn't already been set we'll use the first row of the array as the heading - if ($i++ === 0 && count($data) > 1 && count($this->heading) === 0 && $set_heading === TRUE) - { - $this->heading = $this->_prep_args($row); - } - else - { - $this->rows[] = $this->_prep_args($row); - } + $this->rows[] = $this->_prep_args($row); } } -- cgit v1.2.3-24-g4f1b From a49c8adbc24d904b3473cc301f0f56818acdddcb Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Tue, 11 Feb 2014 17:15:07 +0200 Subject: Change CI_Table:: to NULL Because semantics --- system/libraries/Table.php | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'system/libraries') diff --git a/system/libraries/Table.php b/system/libraries/Table.php index 58016e9b8..1a3aa9a2b 100644 --- a/system/libraries/Table.php +++ b/system/libraries/Table.php @@ -93,7 +93,7 @@ class CI_Table { * * @var function */ - public $function = FALSE; + public $function = NULL; /** * Set the template from the table config file if it exists @@ -138,10 +138,10 @@ class CI_Table { * * Can be passed as an array or discreet params * - * @param mixed + * @param mixed $array * @return CI_Table */ - public function set_heading($args = array()) + public function set_heading($args = array(), $attributes = array()) { $args = func_get_args(); $this->heading = $this->_prep_args($args); @@ -316,9 +316,9 @@ class CI_Table { $this->_compile_template(); // Validate a possibly existing custom cell manipulation function - if ($this->function !== FALSE && ! is_callable($this->function)) + if (isset($this->function) && ! is_callable($this->function)) { - $this->function = FALSE; + $this->function = NULL; } // Build the table! @@ -391,7 +391,7 @@ class CI_Table { { $out .= $this->empty_cells; } - elseif ($this->function !== FALSE) + elseif (isset($this->function)) { $out .= call_user_func($this->function, $cell); } -- cgit v1.2.3-24-g4f1b From 3fcc3f6160ca7cd6fd30b3deb6f58d6a95c9c5e2 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Tue, 11 Feb 2014 17:28:36 +0200 Subject: Another tiny optimization in CI_Table + remove an accidental addition --- system/libraries/Table.php | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) (limited to 'system/libraries') diff --git a/system/libraries/Table.php b/system/libraries/Table.php index 1a3aa9a2b..79632b3da 100644 --- a/system/libraries/Table.php +++ b/system/libraries/Table.php @@ -138,13 +138,12 @@ class CI_Table { * * Can be passed as an array or discreet params * - * @param mixed $array + * @param mixed * @return CI_Table */ - public function set_heading($args = array(), $attributes = array()) + public function set_heading($args = array()) { - $args = func_get_args(); - $this->heading = $this->_prep_args($args); + $this->heading = $this->_prep_args(func_get_args()); return $this; } @@ -224,8 +223,7 @@ class CI_Table { */ public function add_row($args = array()) { - $args = func_get_args(); - $this->rows[] = $this->_prep_args($args); + $this->rows[] = $this->_prep_args(func_get_args()); return $this; } -- cgit v1.2.3-24-g4f1b From f0b69a85e306266bcaa7d6b7f363cc9d64b7b8f7 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Tue, 11 Feb 2014 17:56:44 +0200 Subject: More code reduced from CI_Table --- system/libraries/Table.php | 22 +++++----------------- 1 file changed, 5 insertions(+), 17 deletions(-) (limited to 'system/libraries') diff --git a/system/libraries/Table.php b/system/libraries/Table.php index 79632b3da..179eb8de7 100644 --- a/system/libraries/Table.php +++ b/system/libraries/Table.php @@ -242,26 +242,14 @@ class CI_Table { // If there is no $args[0], skip this and treat as an associative array // This can happen if there is only a single key, for example this is passed to table->generate // array(array('foo'=>'bar')) - if (isset($args[0]) && count($args) === 1 && is_array($args[0])) + if (isset($args[0]) && count($args) === 1 && is_array($args[0]) && ! isset($args[0]['data'])) { - // args sent as indexed array - if ( ! isset($args[0]['data'])) - { - foreach ($args[0] as $key => $val) - { - $args[$key] = (is_array($val) && isset($val['data'])) ? $val : array('data' => $val); - } - } + $args = $args[0]; } - else + + foreach ($args as $key => $val) { - foreach ($args as $key => $val) - { - if ( ! is_array($val)) - { - $args[$key] = array('data' => $val); - } - } + is_array($val) OR $args[$key] = array('data' => $val); } return $args; -- cgit v1.2.3-24-g4f1b From 871754af60251993d640981e107d2def5f2db396 Mon Sep 17 00:00:00 2001 From: darwinel Date: Tue, 11 Feb 2014 17:34:57 +0100 Subject: 2013 > 2014 Update copyright notices from 2013 to 2014. And update one calendar example in user_guide from year 2013/2014 to 2014/2015. --- system/libraries/Cache/Cache.php | 2 +- system/libraries/Cache/drivers/Cache_apc.php | 2 +- system/libraries/Cache/drivers/Cache_dummy.php | 2 +- system/libraries/Cache/drivers/Cache_file.php | 2 +- system/libraries/Cache/drivers/Cache_memcached.php | 2 +- system/libraries/Cache/drivers/Cache_redis.php | 2 +- system/libraries/Cache/drivers/Cache_wincache.php | 2 +- system/libraries/Calendar.php | 2 +- system/libraries/Cart.php | 2 +- system/libraries/Driver.php | 2 +- system/libraries/Email.php | 2 +- system/libraries/Encrypt.php | 2 +- system/libraries/Encryption.php | 2 +- system/libraries/Form_validation.php | 2 +- system/libraries/Ftp.php | 2 +- system/libraries/Image_lib.php | 2 +- system/libraries/Javascript.php | 2 +- system/libraries/Javascript/Jquery.php | 2 +- system/libraries/Migration.php | 2 +- system/libraries/Pagination.php | 2 +- system/libraries/Parser.php | 2 +- system/libraries/Profiler.php | 2 +- system/libraries/Session/Session.php | 2 +- system/libraries/Session/drivers/Session_cookie.php | 2 +- system/libraries/Session/drivers/Session_native.php | 2 +- system/libraries/Table.php | 2 +- system/libraries/Trackback.php | 2 +- system/libraries/Typography.php | 2 +- system/libraries/Unit_test.php | 2 +- system/libraries/Upload.php | 2 +- system/libraries/User_agent.php | 2 +- system/libraries/Xmlrpc.php | 2 +- system/libraries/Xmlrpcs.php | 2 +- system/libraries/Zip.php | 2 +- 34 files changed, 34 insertions(+), 34 deletions(-) (limited to 'system/libraries') diff --git a/system/libraries/Cache/Cache.php b/system/libraries/Cache/Cache.php index 2dffa350c..f9768b10c 100644 --- a/system/libraries/Cache/Cache.php +++ b/system/libraries/Cache/Cache.php @@ -18,7 +18,7 @@ * * @package CodeIgniter * @author EllisLab Dev Team - * @copyright Copyright (c) 2008 - 2013, EllisLab, Inc. (http://ellislab.com/) + * @copyright Copyright (c) 2008 - 2014, EllisLab, Inc. (http://ellislab.com/) * @license http://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0) * @link http://codeigniter.com * @since Version 2.0 diff --git a/system/libraries/Cache/drivers/Cache_apc.php b/system/libraries/Cache/drivers/Cache_apc.php index b5381ddaf..d062103bd 100644 --- a/system/libraries/Cache/drivers/Cache_apc.php +++ b/system/libraries/Cache/drivers/Cache_apc.php @@ -18,7 +18,7 @@ * * @package CodeIgniter * @author EllisLab Dev Team - * @copyright Copyright (c) 2008 - 2013, EllisLab, Inc. (http://ellislab.com/) + * @copyright Copyright (c) 2008 - 2014, EllisLab, Inc. (http://ellislab.com/) * @license http://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0) * @link http://codeigniter.com * @since Version 2.0 diff --git a/system/libraries/Cache/drivers/Cache_dummy.php b/system/libraries/Cache/drivers/Cache_dummy.php index 7e2b907a6..521b9e6dd 100644 --- a/system/libraries/Cache/drivers/Cache_dummy.php +++ b/system/libraries/Cache/drivers/Cache_dummy.php @@ -18,7 +18,7 @@ * * @package CodeIgniter * @author EllisLab Dev Team - * @copyright Copyright (c) 2008 - 2013, EllisLab, Inc. (http://ellislab.com/) + * @copyright Copyright (c) 2008 - 2014, EllisLab, Inc. (http://ellislab.com/) * @license http://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0) * @link http://codeigniter.com * @since Version 2.0 diff --git a/system/libraries/Cache/drivers/Cache_file.php b/system/libraries/Cache/drivers/Cache_file.php index 8c99c5ef3..c6aa848fe 100644 --- a/system/libraries/Cache/drivers/Cache_file.php +++ b/system/libraries/Cache/drivers/Cache_file.php @@ -18,7 +18,7 @@ * * @package CodeIgniter * @author EllisLab Dev Team - * @copyright Copyright (c) 2008 - 2013, EllisLab, Inc. (http://ellislab.com/) + * @copyright Copyright (c) 2008 - 2014, EllisLab, Inc. (http://ellislab.com/) * @license http://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0) * @link http://codeigniter.com * @since Version 2.0 diff --git a/system/libraries/Cache/drivers/Cache_memcached.php b/system/libraries/Cache/drivers/Cache_memcached.php index d59847752..bed606afb 100644 --- a/system/libraries/Cache/drivers/Cache_memcached.php +++ b/system/libraries/Cache/drivers/Cache_memcached.php @@ -18,7 +18,7 @@ * * @package CodeIgniter * @author EllisLab Dev Team - * @copyright Copyright (c) 2008 - 2013, EllisLab, Inc. (http://ellislab.com/) + * @copyright Copyright (c) 2008 - 2014, EllisLab, Inc. (http://ellislab.com/) * @license http://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0) * @link http://codeigniter.com * @since Version 2.0 diff --git a/system/libraries/Cache/drivers/Cache_redis.php b/system/libraries/Cache/drivers/Cache_redis.php index b6fddf035..1c76426c5 100644 --- a/system/libraries/Cache/drivers/Cache_redis.php +++ b/system/libraries/Cache/drivers/Cache_redis.php @@ -18,7 +18,7 @@ * * @package CodeIgniter * @author EllisLab Dev Team - * @copyright Copyright (c) 2008 - 2013, EllisLab, Inc. (http://ellislab.com/) + * @copyright Copyright (c) 2008 - 2014, EllisLab, Inc. (http://ellislab.com/) * @license http://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0) * @link http://codeigniter.com * @since Version 3.0 diff --git a/system/libraries/Cache/drivers/Cache_wincache.php b/system/libraries/Cache/drivers/Cache_wincache.php index 25c18ab58..f412a538d 100644 --- a/system/libraries/Cache/drivers/Cache_wincache.php +++ b/system/libraries/Cache/drivers/Cache_wincache.php @@ -18,7 +18,7 @@ * * @package CodeIgniter * @author EllisLab Dev Team - * @copyright Copyright (c) 2008 - 2013, EllisLab, Inc. (http://ellislab.com/) + * @copyright Copyright (c) 2008 - 2014, EllisLab, Inc. (http://ellislab.com/) * @license http://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0) * @link http://codeigniter.com * @since Version 3.0 diff --git a/system/libraries/Calendar.php b/system/libraries/Calendar.php index 610b427cf..30f393318 100644 --- a/system/libraries/Calendar.php +++ b/system/libraries/Calendar.php @@ -18,7 +18,7 @@ * * @package CodeIgniter * @author EllisLab Dev Team - * @copyright Copyright (c) 2008 - 2013, EllisLab, Inc. (http://ellislab.com/) + * @copyright Copyright (c) 2008 - 2014, 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 diff --git a/system/libraries/Cart.php b/system/libraries/Cart.php index edc300bd7..5a31a1d45 100644 --- a/system/libraries/Cart.php +++ b/system/libraries/Cart.php @@ -18,7 +18,7 @@ * * @package CodeIgniter * @author EllisLab Dev Team - * @copyright Copyright (c) 2006 - 2013, EllisLab, Inc. (http://ellislab.com/) + * @copyright Copyright (c) 2006 - 2014, 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 diff --git a/system/libraries/Driver.php b/system/libraries/Driver.php index 1bc365cbc..d2e41d6dd 100644 --- a/system/libraries/Driver.php +++ b/system/libraries/Driver.php @@ -18,7 +18,7 @@ * * @package CodeIgniter * @author EllisLab Dev Team - * @copyright Copyright (c) 2006 - 2013, EllisLab, Inc. (http://ellislab.com/) + * @copyright Copyright (c) 2006 - 2014, 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 diff --git a/system/libraries/Email.php b/system/libraries/Email.php index 88925e03f..7d13a4645 100644 --- a/system/libraries/Email.php +++ b/system/libraries/Email.php @@ -18,7 +18,7 @@ * * @package CodeIgniter * @author EllisLab Dev Team - * @copyright Copyright (c) 2008 - 2013, EllisLab, Inc. (http://ellislab.com/) + * @copyright Copyright (c) 2008 - 2014, 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 diff --git a/system/libraries/Encrypt.php b/system/libraries/Encrypt.php index 8ac5420de..f72bd2302 100644 --- a/system/libraries/Encrypt.php +++ b/system/libraries/Encrypt.php @@ -18,7 +18,7 @@ * * @package CodeIgniter * @author EllisLab Dev Team - * @copyright Copyright (c) 2008 - 2013, EllisLab, Inc. (http://ellislab.com/) + * @copyright Copyright (c) 2008 - 2014, 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 diff --git a/system/libraries/Encryption.php b/system/libraries/Encryption.php index 3a5409839..3ce9f1b95 100644 --- a/system/libraries/Encryption.php +++ b/system/libraries/Encryption.php @@ -18,7 +18,7 @@ * * @package CodeIgniter * @author EllisLab Dev Team - * @copyright Copyright (c) 2008 - 2013, EllisLab, Inc. (http://ellislab.com/) + * @copyright Copyright (c) 2008 - 2014, EllisLab, Inc. (http://ellislab.com/) * @license http://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0) * @link http://codeigniter.com * @since Version 3.0 diff --git a/system/libraries/Form_validation.php b/system/libraries/Form_validation.php index 7c441409f..0c4f94914 100644 --- a/system/libraries/Form_validation.php +++ b/system/libraries/Form_validation.php @@ -18,7 +18,7 @@ * * @package CodeIgniter * @author EllisLab Dev Team - * @copyright Copyright (c) 2008 - 2013, EllisLab, Inc. (http://ellislab.com/) + * @copyright Copyright (c) 2008 - 2014, 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 diff --git a/system/libraries/Ftp.php b/system/libraries/Ftp.php index 73a68441a..ef3b7d70d 100644 --- a/system/libraries/Ftp.php +++ b/system/libraries/Ftp.php @@ -18,7 +18,7 @@ * * @package CodeIgniter * @author EllisLab Dev Team - * @copyright Copyright (c) 2008 - 2013, EllisLab, Inc. (http://ellislab.com/) + * @copyright Copyright (c) 2008 - 2014, 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 diff --git a/system/libraries/Image_lib.php b/system/libraries/Image_lib.php index bb0ea7b50..db45a80fc 100644 --- a/system/libraries/Image_lib.php +++ b/system/libraries/Image_lib.php @@ -18,7 +18,7 @@ * * @package CodeIgniter * @author EllisLab Dev Team - * @copyright Copyright (c) 2008 - 2013, EllisLab, Inc. (http://ellislab.com/) + * @copyright Copyright (c) 2008 - 2014, 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 diff --git a/system/libraries/Javascript.php b/system/libraries/Javascript.php index 34a216c22..c71a4204e 100644 --- a/system/libraries/Javascript.php +++ b/system/libraries/Javascript.php @@ -18,7 +18,7 @@ * * @package CodeIgniter * @author EllisLab Dev Team - * @copyright Copyright (c) 2008 - 2013, EllisLab, Inc. (http://ellislab.com/) + * @copyright Copyright (c) 2008 - 2014, 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 diff --git a/system/libraries/Javascript/Jquery.php b/system/libraries/Javascript/Jquery.php index ab78e8b2e..1cc3d2c21 100644 --- a/system/libraries/Javascript/Jquery.php +++ b/system/libraries/Javascript/Jquery.php @@ -18,7 +18,7 @@ * * @package CodeIgniter * @author EllisLab Dev Team - * @copyright Copyright (c) 2008 - 2013, EllisLab, Inc. (http://ellislab.com/) + * @copyright Copyright (c) 2008 - 2014, 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 diff --git a/system/libraries/Migration.php b/system/libraries/Migration.php index cc6fe48f0..932b06ef0 100644 --- a/system/libraries/Migration.php +++ b/system/libraries/Migration.php @@ -18,7 +18,7 @@ * * @package CodeIgniter * @author EllisLab Dev Team - * @copyright Copyright (c) 2006 - 2013, EllisLab, Inc. (http://ellislab.com/) + * @copyright Copyright (c) 2006 - 2014, EllisLab, Inc. (http://ellislab.com/) * @license http://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0) * @link http://codeigniter.com * @since Version 3.0 diff --git a/system/libraries/Pagination.php b/system/libraries/Pagination.php index f67cb47f8..da4b89232 100644 --- a/system/libraries/Pagination.php +++ b/system/libraries/Pagination.php @@ -18,7 +18,7 @@ * * @package CodeIgniter * @author EllisLab Dev Team - * @copyright Copyright (c) 2008 - 2013, EllisLab, Inc. (http://ellislab.com/) + * @copyright Copyright (c) 2008 - 2014, 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 diff --git a/system/libraries/Parser.php b/system/libraries/Parser.php index 399131cdd..d23a53423 100644 --- a/system/libraries/Parser.php +++ b/system/libraries/Parser.php @@ -18,7 +18,7 @@ * * @package CodeIgniter * @author EllisLab Dev Team - * @copyright Copyright (c) 2008 - 2013, EllisLab, Inc. (http://ellislab.com/) + * @copyright Copyright (c) 2008 - 2014, 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 diff --git a/system/libraries/Profiler.php b/system/libraries/Profiler.php index 4796e8416..810a025a4 100644 --- a/system/libraries/Profiler.php +++ b/system/libraries/Profiler.php @@ -18,7 +18,7 @@ * * @package CodeIgniter * @author EllisLab Dev Team - * @copyright Copyright (c) 2008 - 2013, EllisLab, Inc. (http://ellislab.com/) + * @copyright Copyright (c) 2008 - 2014, 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 diff --git a/system/libraries/Session/Session.php b/system/libraries/Session/Session.php index d9f2f506f..905352bb3 100644 --- a/system/libraries/Session/Session.php +++ b/system/libraries/Session/Session.php @@ -18,7 +18,7 @@ * * @package CodeIgniter * @author EllisLab Dev Team - * @copyright Copyright (c) 2008 - 2013, EllisLab, Inc. (http://ellislab.com/) + * @copyright Copyright (c) 2008 - 2014, EllisLab, Inc. (http://ellislab.com/) * @license http://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0) * @link http://codeigniter.com * @since Version 2.0 diff --git a/system/libraries/Session/drivers/Session_cookie.php b/system/libraries/Session/drivers/Session_cookie.php index 79712ad94..566c40bd8 100644 --- a/system/libraries/Session/drivers/Session_cookie.php +++ b/system/libraries/Session/drivers/Session_cookie.php @@ -18,7 +18,7 @@ * * @package CodeIgniter * @author EllisLab Dev Team - * @copyright Copyright (c) 2008 - 2013, EllisLab, Inc. (http://ellislab.com/) + * @copyright Copyright (c) 2008 - 2014, 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 diff --git a/system/libraries/Session/drivers/Session_native.php b/system/libraries/Session/drivers/Session_native.php index c237ad059..4104652b8 100644 --- a/system/libraries/Session/drivers/Session_native.php +++ b/system/libraries/Session/drivers/Session_native.php @@ -18,7 +18,7 @@ * * @package CodeIgniter * @author EllisLab Dev Team - * @copyright Copyright (c) 2008 - 2013, EllisLab, Inc. (http://ellislab.com/) + * @copyright Copyright (c) 2008 - 2014, 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 diff --git a/system/libraries/Table.php b/system/libraries/Table.php index 79632b3da..ea36db9b0 100644 --- a/system/libraries/Table.php +++ b/system/libraries/Table.php @@ -18,7 +18,7 @@ * * @package CodeIgniter * @author EllisLab Dev Team - * @copyright Copyright (c) 2008 - 2013, EllisLab, Inc. (http://ellislab.com/) + * @copyright Copyright (c) 2008 - 2014, 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.3.1 diff --git a/system/libraries/Trackback.php b/system/libraries/Trackback.php index 5a45be8dd..7bcb2aa21 100644 --- a/system/libraries/Trackback.php +++ b/system/libraries/Trackback.php @@ -18,7 +18,7 @@ * * @package CodeIgniter * @author EllisLab Dev Team - * @copyright Copyright (c) 2008 - 2013, EllisLab, Inc. (http://ellislab.com/) + * @copyright Copyright (c) 2008 - 2014, 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 diff --git a/system/libraries/Typography.php b/system/libraries/Typography.php index dd79e850a..d5e4ee06b 100644 --- a/system/libraries/Typography.php +++ b/system/libraries/Typography.php @@ -18,7 +18,7 @@ * * @package CodeIgniter * @author EllisLab Dev Team - * @copyright Copyright (c) 2008 - 2013, EllisLab, Inc. (http://ellislab.com/) + * @copyright Copyright (c) 2008 - 2014, 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 diff --git a/system/libraries/Unit_test.php b/system/libraries/Unit_test.php index e412b9858..cc882bc72 100644 --- a/system/libraries/Unit_test.php +++ b/system/libraries/Unit_test.php @@ -18,7 +18,7 @@ * * @package CodeIgniter * @author EllisLab Dev Team - * @copyright Copyright (c) 2008 - 2013, EllisLab, Inc. (http://ellislab.com/) + * @copyright Copyright (c) 2008 - 2014, 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.3.1 diff --git a/system/libraries/Upload.php b/system/libraries/Upload.php index 525880f62..983d832fd 100644 --- a/system/libraries/Upload.php +++ b/system/libraries/Upload.php @@ -18,7 +18,7 @@ * * @package CodeIgniter * @author EllisLab Dev Team - * @copyright Copyright (c) 2008 - 2013, EllisLab, Inc. (http://ellislab.com/) + * @copyright Copyright (c) 2008 - 2014, 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 diff --git a/system/libraries/User_agent.php b/system/libraries/User_agent.php index 1dfa3e72d..9bab8666e 100644 --- a/system/libraries/User_agent.php +++ b/system/libraries/User_agent.php @@ -18,7 +18,7 @@ * * @package CodeIgniter * @author EllisLab Dev Team - * @copyright Copyright (c) 2008 - 2013, EllisLab, Inc. (http://ellislab.com/) + * @copyright Copyright (c) 2008 - 2014, 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 diff --git a/system/libraries/Xmlrpc.php b/system/libraries/Xmlrpc.php index d0f6d83b3..83dc00e45 100644 --- a/system/libraries/Xmlrpc.php +++ b/system/libraries/Xmlrpc.php @@ -18,7 +18,7 @@ * * @package CodeIgniter * @author EllisLab Dev Team - * @copyright Copyright (c) 2008 - 2013, EllisLab, Inc. (http://ellislab.com/) + * @copyright Copyright (c) 2008 - 2014, 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 diff --git a/system/libraries/Xmlrpcs.php b/system/libraries/Xmlrpcs.php index 50ff423f2..e8e06d756 100644 --- a/system/libraries/Xmlrpcs.php +++ b/system/libraries/Xmlrpcs.php @@ -18,7 +18,7 @@ * * @package CodeIgniter * @author EllisLab Dev Team - * @copyright Copyright (c) 2008 - 2013, EllisLab, Inc. (http://ellislab.com/) + * @copyright Copyright (c) 2008 - 2014, 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 diff --git a/system/libraries/Zip.php b/system/libraries/Zip.php index 58f06455c..40b661abc 100644 --- a/system/libraries/Zip.php +++ b/system/libraries/Zip.php @@ -18,7 +18,7 @@ * * @package CodeIgniter * @author EllisLab Dev Team - * @copyright Copyright (c) 2008 - 2013, EllisLab, Inc. (http://ellislab.com/) + * @copyright Copyright (c) 2008 - 2014, 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 -- cgit v1.2.3-24-g4f1b From be1496d1a8618ef186047468009c7e3e0640183b Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Tue, 11 Feb 2014 22:48:45 +0200 Subject: Utf8/iconv/mbstring-related changes --- system/libraries/Email.php | 6 +++--- system/libraries/Trackback.php | 9 ++++++++- 2 files changed, 11 insertions(+), 4 deletions(-) (limited to 'system/libraries') diff --git a/system/libraries/Email.php b/system/libraries/Email.php index 7d13a4645..93c19de5e 100644 --- a/system/libraries/Email.php +++ b/system/libraries/Email.php @@ -1544,7 +1544,7 @@ class CI_Email { { return mb_encode_mimeheader($str, $this->charset, 'Q', $this->crlf); } - elseif (extension_loaded('iconv')) + elseif (ICONV_ENABLED === TRUE) { $output = @iconv_mime_encode('', $str, array( @@ -1573,9 +1573,9 @@ class CI_Email { isset($chars) OR $chars = strlen($str); $output = '=?'.$this->charset.'?Q?'; - for ($i = 0, $length = strlen($output), $iconv = extension_loaded('iconv'); $i < $chars; $i++) + for ($i = 0, $length = strlen($output); $i < $chars; $i++) { - $chr = ($this->charset === 'UTF-8' && $iconv === TRUE) + $chr = ($this->charset === 'UTF-8' && ICONV_ENABLED === TRUE) ? '='.implode('=', str_split(strtoupper(bin2hex(iconv_substr($str, $i, 1, $this->charset))), 2)) : '='.strtoupper(bin2hex($str[$i])); diff --git a/system/libraries/Trackback.php b/system/libraries/Trackback.php index 7bcb2aa21..9fa4a8edb 100644 --- a/system/libraries/Trackback.php +++ b/system/libraries/Trackback.php @@ -181,7 +181,14 @@ class CI_Trackback { if ($val !== 'url' && MB_ENABLED === TRUE) { - $_POST[$val] = mb_convert_encoding($_POST[$val], $this->charset, $this->data['charset']); + if (MB_ENABLED === TRUE) + { + $_POST[$val] = mb_convert_encoding($_POST[$val], $this->charset, $this->data['charset']); + } + elseif (ICONV_ENABLED === TRUE) + { + $_POST[$val] = @iconv($this->data['charset'], $this->charset.'//IGNORE', $_POST[$val]); + } } $_POST[$val] = ($val !== 'url') ? $this->convert_xml(strip_tags($_POST[$val])) : strip_tags($_POST[$val]); -- cgit v1.2.3-24-g4f1b From f69f1822558645aa00944b436558fb6948f42aa9 Mon Sep 17 00:00:00 2001 From: Ahmad Anbar Date: Tue, 11 Feb 2014 22:55:47 +0200 Subject: Allow updating all properties for an item. --- system/libraries/Cart.php | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'system/libraries') diff --git a/system/libraries/Cart.php b/system/libraries/Cart.php index 5a31a1d45..b00ccd862 100644 --- a/system/libraries/Cart.php +++ b/system/libraries/Cart.php @@ -350,7 +350,11 @@ class CI_Cart { } else { - $this->_cart_contents[$items['rowid']]['qty'] = $items['qty']; + // find updatable keys + $keys = array_intersect(array_keys($this->_cart_contents[$items['rowid']]), array_keys($items)); + foreach ( $keys as $key ) { + $this->_cart_contents[$items['rowid']][$key] = $items[$key]; + } } return TRUE; -- cgit v1.2.3-24-g4f1b From 7d16de620a46f84ffeb52a54ae82439a06f89c74 Mon Sep 17 00:00:00 2001 From: Ahmad Anbar Date: Thu, 13 Feb 2014 01:45:27 +0200 Subject: Fixed code style & added few extra checks. Updated cart documentation. --- system/libraries/Cart.php | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) (limited to 'system/libraries') diff --git a/system/libraries/Cart.php b/system/libraries/Cart.php index b00ccd862..f5e85b715 100644 --- a/system/libraries/Cart.php +++ b/system/libraries/Cart.php @@ -323,10 +323,10 @@ class CI_Cart { /** * Update the cart * - * This function permits the quantity of a given item to be changed. + * This function permits changing item properties. * Typically it is called from the "view cart" page if a user makes * changes to the quantity before checkout. That array must contain the - * product ID and quantity for each item. + * rowid and qty for each item. * * @param array * @return bool @@ -352,7 +352,18 @@ class CI_Cart { { // find updatable keys $keys = array_intersect(array_keys($this->_cart_contents[$items['rowid']]), array_keys($items)); - foreach ( $keys as $key ) { + // if a price was passed, make sure it contains valid data + if (isset($keys['price'])) + { + $keys['price'] = (float) $keys['price']; + } + + // product name & id shouldn't be changed + unset($keys['name']); + unset($keys['id']); + + foreach ($keys as $key) + { $this->_cart_contents[$items['rowid']][$key] = $items[$key]; } } -- cgit v1.2.3-24-g4f1b From 11db7a7da940a6ab0168a70b71194f078cdf953d Mon Sep 17 00:00:00 2001 From: Ahmad Anbar Date: Thu, 13 Feb 2014 02:40:45 +0200 Subject: Delete by values, not keys --- system/libraries/Cart.php | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) (limited to 'system/libraries') diff --git a/system/libraries/Cart.php b/system/libraries/Cart.php index f5e85b715..8a2516f1c 100644 --- a/system/libraries/Cart.php +++ b/system/libraries/Cart.php @@ -353,14 +353,13 @@ class CI_Cart { // find updatable keys $keys = array_intersect(array_keys($this->_cart_contents[$items['rowid']]), array_keys($items)); // if a price was passed, make sure it contains valid data - if (isset($keys['price'])) + if (isset($items['price'])) { - $keys['price'] = (float) $keys['price']; + $items['price'] = (float) $items['price']; } // product name & id shouldn't be changed - unset($keys['name']); - unset($keys['id']); + $keys = array_diff($keys, array('id', 'name')); foreach ($keys as $key) { -- cgit v1.2.3-24-g4f1b From 576439fda03d4e81cb5b0cfed371f7776a73fe3a Mon Sep 17 00:00:00 2001 From: Ahmad Anbar Date: Thu, 13 Feb 2014 06:16:31 +0200 Subject: Added changelog entry. An example to the docs. Tidy code a little bit. --- system/libraries/Cart.php | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) (limited to 'system/libraries') diff --git a/system/libraries/Cart.php b/system/libraries/Cart.php index 8a2516f1c..ec67d9b4a 100644 --- a/system/libraries/Cart.php +++ b/system/libraries/Cart.php @@ -358,10 +358,8 @@ class CI_Cart { $items['price'] = (float) $items['price']; } - // product name & id shouldn't be changed - $keys = array_diff($keys, array('id', 'name')); - - foreach ($keys as $key) + // product id & name shouldn't be changed + foreach (array_diff($keys, array('id', 'name')) as $key) { $this->_cart_contents[$items['rowid']][$key] = $items[$key]; } -- cgit v1.2.3-24-g4f1b From da2bdf2b95a55f03aadfb6a1d21a90a0fff627db Mon Sep 17 00:00:00 2001 From: Ahmad Anbar Date: Thu, 13 Feb 2014 12:59:18 +0200 Subject: Re-arranged documentation, fixed comment. --- system/libraries/Cart.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system/libraries') diff --git a/system/libraries/Cart.php b/system/libraries/Cart.php index ec67d9b4a..389b1b77e 100644 --- a/system/libraries/Cart.php +++ b/system/libraries/Cart.php @@ -326,7 +326,7 @@ class CI_Cart { * This function permits changing item properties. * Typically it is called from the "view cart" page if a user makes * changes to the quantity before checkout. That array must contain the - * rowid and qty for each item. + * rowid and quantity for each item. * * @param array * @return bool -- cgit v1.2.3-24-g4f1b From 0bd390c660290b7dc478955da6a8a7fbb3ca9fd6 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Thu, 13 Feb 2014 14:26:50 +0200 Subject: [ci skip] Polish changes from #2874 --- system/libraries/Cart.php | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) (limited to 'system/libraries') diff --git a/system/libraries/Cart.php b/system/libraries/Cart.php index 389b1b77e..5b05974e4 100644 --- a/system/libraries/Cart.php +++ b/system/libraries/Cart.php @@ -60,8 +60,6 @@ class CI_Cart { */ public $product_name_safe = TRUE; - // -------------------------------------------------------------------------- - // Protected variables. Do not change! // -------------------------------------------------------------------------- /** @@ -357,9 +355,9 @@ class CI_Cart { { $items['price'] = (float) $items['price']; } - - // product id & name shouldn't be changed - foreach (array_diff($keys, array('id', 'name')) as $key) + + // product id & name shouldn't be changed + foreach (array_diff($keys, array('id', 'name')) as $key) { $this->_cart_contents[$items['rowid']][$key] = $items[$key]; } -- cgit v1.2.3-24-g4f1b From aef63e532bcede1d455bc27f0fc6f369ab74f203 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Thu, 13 Feb 2014 14:49:55 +0200 Subject: Add language translation support to CI_Pagination (#1589) --- system/libraries/Pagination.php | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) (limited to 'system/libraries') diff --git a/system/libraries/Pagination.php b/system/libraries/Pagination.php index da4b89232..2f1bcfbad 100644 --- a/system/libraries/Pagination.php +++ b/system/libraries/Pagination.php @@ -304,6 +304,16 @@ class CI_Pagination { */ public function __construct($params = array()) { + $CI =& get_instance(); + $CI->load->language('paginaton'); + foreach (array('first_link', 'next_link', 'prev_link', 'last_link') as $key) + { + if (($val = $CI->lang->line('pagination_'.$key)) !== FALSE) + { + $this->$key = $val; + } + } + $this->initialize($params); log_message('debug', 'Pagination Class Initialized'); } @@ -316,7 +326,7 @@ class CI_Pagination { * @param array $params Initialization parameters * @return CI_Pagination */ - public function initialize($params = array()) + public function initialize(array $params = array()) { if (isset($params['attributes']) && is_array($params['attributes'])) { @@ -332,14 +342,11 @@ class CI_Pagination { unset($params['anchor_class']); } - if (count($params) > 0) + foreach ($params as $key => $val) { - foreach ($params as $key => $val) + if (property_exists($this, $this->$key)) { - if (isset($this->$key)) - { - $this->$key = $val; - } + $this->$key = $val; } } -- cgit v1.2.3-24-g4f1b From b1616b8c3370d59135275b6945ed1b80cfe99653 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Thu, 13 Feb 2014 15:12:43 +0200 Subject: Fix #2364 --- system/libraries/Pagination.php | 40 +++++++++++++++++++++------------------- 1 file changed, 21 insertions(+), 19 deletions(-) (limited to 'system/libraries') diff --git a/system/libraries/Pagination.php b/system/libraries/Pagination.php index 2f1bcfbad..06cc0c378 100644 --- a/system/libraries/Pagination.php +++ b/system/libraries/Pagination.php @@ -403,30 +403,32 @@ class CI_Pagination { } // Put together our base and first URLs. - $this->base_url = trim($this->base_url); + // Note: DO NOT append to the properties as that would break successive calls + $base_url = trim($this->base_url); + $first_url = $this->first_url; $query_string = ''; - $query_string_sep = (strpos($this->base_url, '?') === FALSE) ? '?' : '&'; + $query_string_sep = (strpos($base_url, '?') === FALSE) ? '?' : '&'; // Are we using query strings? if ($CI->config->item('enable_query_strings') === TRUE OR $this->page_query_string === TRUE) { // If a custom first_url hasn't been specified, we'll create one from // the base_url, but without the page item. - if ($this->first_url === '') + if ($first_url === '') { - $this->first_url = $this->base_url; + $first_url = $base_url; // If we saved any GET items earlier, make sure they're appended. if ( ! empty($get)) { - $this->first_url .= $query_string_sep.http_build_query($get); + $first_url .= $query_string_sep.http_build_query($get); } } // Add the page segment to the end of the query string, where the // page number will be appended. - $this->base_url .= $query_string_sep.http_build_query(array_merge($get, array($this->query_string_segment => ''))); + $base_url .= $query_string_sep.http_build_query(array_merge($get, array($this->query_string_segment => ''))); } else { @@ -440,17 +442,17 @@ class CI_Pagination { // Does the base_url have the query string in it? // If we're supposed to save it, remove it so we can append it later. - if ($this->reuse_query_string === TRUE && ($base_query_pos = strpos($this->base_url, '?')) !== FALSE) + if ($this->reuse_query_string === TRUE && ($base_query_pos = strpos($base_url, '?')) !== FALSE) { - $this->base_url = substr($this->base_url, 0, $base_query_pos); + $base_url = substr($base_url, 0, $base_query_pos); } - if ($this->first_url === '') + if ($first_url === '') { - $this->first_url = $this->base_url.$query_string; + $first_url = $base_url.$query_string; } - $this->base_url = rtrim($this->base_url, '/').'/'; + $base_url = rtrim($base_url, '/').'/'; } // Determine the current page number. @@ -526,8 +528,8 @@ class CI_Pagination { // Take the general parameters, and squeeze this pagination-page attr in for JS frameworks. $attributes = sprintf('%s %s="%d"', $this->_attributes, $this->data_page_attr, 1); - $output .= $this->first_tag_open.'_attr_rel('start').'>' - .$this->first_link.''.$this->first_tag_close; + $output .= $this->first_tag_open.'_attr_rel('start').'>' + .$first_link.''.$this->first_tag_close; } // Render the "Previous" link. @@ -540,13 +542,13 @@ class CI_Pagination { if ($i === $base_page) { // First page - $output .= $this->prev_tag_open.'_attr_rel('prev').'>' + $output .= $this->prev_tag_open.'_attr_rel('prev').'>' .$this->prev_link.''.$this->prev_tag_close; } else { $append = $this->prefix.$i.$this->suffix; - $output .= $this->prev_tag_open.'_attr_rel('prev').'>' + $output .= $this->prev_tag_open.'_attr_rel('prev').'>' .$this->prev_link.''.$this->prev_tag_close; } @@ -572,13 +574,13 @@ class CI_Pagination { elseif ($i === $base_page) { // First page - $output .= $this->num_tag_open.'_attr_rel('start').'>' + $output .= $this->num_tag_open.'_attr_rel('start').'>' .$loop.''.$this->num_tag_close; } else { $append = $this->prefix.$i.$this->suffix; - $output .= $this->num_tag_open.'_attr_rel('start').'>' + $output .= $this->num_tag_open.'_attr_rel('start').'>' .$loop.''.$this->num_tag_close; } } @@ -592,7 +594,7 @@ class CI_Pagination { $attributes = sprintf('%s %s="%d"', $this->_attributes, $this->data_page_attr, (int) $i); - $output .= $this->next_tag_open.'next_tag_open.'_attr_rel('next').'>'.$this->next_link.''.$this->next_tag_close; } @@ -603,7 +605,7 @@ class CI_Pagination { $attributes = sprintf('%s %s="%d"', $this->_attributes, $this->data_page_attr, (int) $i); - $output .= $this->last_tag_open.'' + $output .= $this->last_tag_open.'' .$this->last_link.''.$this->last_tag_close; } -- cgit v1.2.3-24-g4f1b From 526ded927a607b4dfab0ec00f1d52efa3df0d887 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Thu, 13 Feb 2014 16:29:52 +0200 Subject: Fix #2878 --- system/libraries/Pagination.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system/libraries') diff --git a/system/libraries/Pagination.php b/system/libraries/Pagination.php index 06cc0c378..f2d38a852 100644 --- a/system/libraries/Pagination.php +++ b/system/libraries/Pagination.php @@ -305,7 +305,7 @@ class CI_Pagination { public function __construct($params = array()) { $CI =& get_instance(); - $CI->load->language('paginaton'); + $CI->load->language('pagination'); foreach (array('first_link', 'next_link', 'prev_link', 'last_link') as $key) { if (($val = $CI->lang->line('pagination_'.$key)) !== FALSE) -- cgit v1.2.3-24-g4f1b