Merge pull request #811 from narfbg/develop-email

Improve the Email library
diff --git a/system/libraries/Cart.php b/system/libraries/Cart.php
index 717ccd9..01a0cb8 100644
--- a/system/libraries/Cart.php
+++ b/system/libraries/Cart.php
@@ -1,13 +1,13 @@
-<?php  if ( ! defined('BASEPATH')) exit('No direct script access allowed');
+<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
 /**
  * CodeIgniter
  *
  * An open source application development framework for PHP 5.1.6 or newer
  *
  * NOTICE OF LICENSE
- * 
+ *
  * Licensed under the Open Software License version 3.0
- * 
+ *
  * This source file is subject to the Open Software License (OSL 3.0) that is
  * bundled with this package in the files license.txt / license.rst.  It is
  * also available through the world wide web at this URL:
@@ -39,13 +39,13 @@
 class CI_Cart {
 
 	// These are the regular expression rules that we use to validate the product ID and product name
-	var $product_id_rules	= '\.a-z0-9_-'; // alpha-numeric, dashes, underscores, or periods
-	var $product_name_rules	= '\.\:\-_ a-z0-9'; // alpha-numeric, dashes, underscores, colons or periods
-	var $product_name_safe  = true; // only allow safe product names
+	public $product_id_rules	= '\.a-z0-9_-'; // alpha-numeric, dashes, underscores, or periods
+	public $product_name_rules	= '\.\:\-_ a-z0-9'; // alpha-numeric, dashes, underscores, colons or periods
+	public $product_name_safe  = true; // only allow safe product names
 
 	// Private variables.  Do not change!
-	var $CI;
-	var $_cart_contents	= array();
+	private $CI;
+	private $_cart_contents	= array();
 
 
 	/**
@@ -59,28 +59,17 @@
 		$this->CI =& get_instance();
 
 		// Are any config settings being passed manually?  If so, set them
-		$config = array();
-		if (count($params) > 0)
-		{
-			foreach ($params as $key => $val)
-			{
-				$config[$key] = $val;
-			}
-		}
+		$config = is_array($params) ? $params : array();
 
 		// Load the Sessions class
 		$this->CI->load->library('session', $config);
 
-		// Grab the shopping cart array from the session table, if it exists
-		if ($this->CI->session->userdata('cart_contents') !== FALSE)
-		{
-			$this->_cart_contents = $this->CI->session->userdata('cart_contents');
-		}
-		else
+		// Grab the shopping cart array from the session table
+		$this->_cart_contents = $this->CI->session->userdata('cart_contents');
+		if ($this->_cart_contents === FALSE)
 		{
 			// No cart exists so we'll set some base values
-			$this->_cart_contents['cart_total'] = 0;
-			$this->_cart_contents['total_items'] = 0;
+			$this->_cart_contents = array('cart_total' => 0, 'total_items' => 0);
 		}
 
 		log_message('debug', "Cart Class Initialized");
@@ -95,10 +84,10 @@
 	 * @param	array
 	 * @return	bool
 	 */
-	function insert($items = array())
+	public function insert($items = array())
 	{
 		// Was any cart data passed? No? Bah...
-		if ( ! is_array($items) OR count($items) == 0)
+		if ( ! is_array($items) OR count($items) === 0)
 		{
 			log_message('error', 'The insert method must be passed an array containing data.');
 			return FALSE;
@@ -132,7 +121,7 @@
 		}
 
 		// Save the cart data if the insert was successful
-		if ($save_cart == TRUE)
+		if ($save_cart === TRUE)
 		{
 			$this->_save_cart();
 			return isset($rowid) ? $rowid : TRUE;
@@ -150,10 +139,10 @@
 	 * @param	array
 	 * @return	bool
 	 */
-	function _insert($items = array())
+	private function _insert($items = array())
 	{
 		// Was any cart data passed? No? Bah...
-		if ( ! is_array($items) OR count($items) == 0)
+		if ( ! is_array($items) OR count($items) === 0)
 		{
 			log_message('error', 'The insert method must be passed an array containing data.');
 			return FALSE;
@@ -170,10 +159,8 @@
 
 		// --------------------------------------------------------------------
 
-		// Prep the quantity. It can only be a number.  Duh...
-		$items['qty'] = trim(preg_replace('/([^0-9])/i', '', $items['qty']));
-		// Trim any leading zeros
-		$items['qty'] = trim(preg_replace('/(^[0]+)/i', '', $items['qty']));
+		// Prep the quantity. It can only be a number.  Duh... also trim any leading zeros
+		$items['qty'] = (float) $items['qty'];
 
 		// If the quantity is zero or blank there's nothing for us to do
 		if ( ! is_numeric($items['qty']) OR $items['qty'] == 0)
@@ -186,7 +173,7 @@
 		// Validate the product ID. It can only be alpha-numeric, dashes, underscores or periods
 		// Not totally sure we should impose this rule, but it seems prudent to standardize IDs.
 		// Note: These can be user-specified by setting the $this->product_id_rules variable.
-		if ( ! preg_match("/^[".$this->product_id_rules."]+$/i", $items['id']))
+		if ( ! preg_match('/^['.$this->product_id_rules.']+$/i', $items['id']))
 		{
 			log_message('error', 'Invalid product ID.  The product ID can only contain alpha-numeric characters, dashes, and underscores');
 			return FALSE;
@@ -196,7 +183,7 @@
 
 		// Validate the product name. It can only be alpha-numeric, dashes, underscores, colons or periods.
 		// Note: These can be user-specified by setting the $this->product_name_rules variable.
-		if ( $this->product_name_safe && ! preg_match("/^[".$this->product_name_rules."]+$/i", $items['name']))
+		if ($this->product_name_safe && ! preg_match('/^['.$this->product_name_rules.']+$/i', $items['name']))
 		{
 			log_message('error', 'An invalid name was submitted as the product name: '.$items['name'].' The name can only contain alpha-numeric characters, dashes, underscores, colons, and spaces');
 			return FALSE;
@@ -204,10 +191,8 @@
 
 		// --------------------------------------------------------------------
 
-		// Prep the price.  Remove anything that isn't a number or decimal point.
-		$items['price'] = trim(preg_replace('/([^0-9\.])/i', '', $items['price']));
-		// Trim any leading zeros
-		$items['price'] = trim(preg_replace('/(^[0]+)/i', '', $items['price']));
+		// Prep the price. Remove leading zeros and anything that isn't a number or decimal point.
+		$items['price'] = (float) $items['price'];
 
 		// Is the price a valid number?
 		if ( ! is_numeric($items['price']))
@@ -244,33 +229,13 @@
 
 		// Now that we have our unique "row ID", we'll add our cart items to the master array
 		// grab quantity if it's already there and add it on
-		if (isset($this->_cart_contents[$rowid]['qty']))
-		{
-			// set our old quantity
-			$old_quantity = (int)$this->_cart_contents[$rowid]['qty'];
-		}
-		else
-		{
-			// we have no old quantity but - we don't want to throw an error
-			$old_quantity = 0;
-		}
-		
-		// let's unset this first, just to make sure our index contains only the data from this submission
-		unset($this->_cart_contents[$rowid]);
+		$old_quantity = isset($this->_cart_contents[$rowid]['qty']) ? (int) $this->_cart_contents[$rowid]['qty'] : 0;
 
-		// Create a new index with our new row ID
-		$this->_cart_contents[$rowid]['rowid'] = $rowid;
+		// Re-create the entry, just to make sure our index contains only the data from this submission
+		$items['rowid'] = $rowid;
+		$items['qty'] += $old_quantity;
+		$this->_cart_contents[$rowid] = $items;
 
-		// And add the new items to the cart array
-		foreach ($items as $key => $val)
-		{
-			$this->_cart_contents[$rowid][$key] = $val;
-		}
-		
-		// add old quantity back in
-		$this->_cart_contents[$rowid]['qty'] = ($this->_cart_contents[$rowid]['qty'] + $old_quantity);
-		
-		// Woot!
 		return $rowid;
 	}
 
@@ -289,10 +254,10 @@
 	 * @param	string
 	 * @return	bool
 	 */
-	function update($items = array())
+	public function update($items = array())
 	{
 		// Was any cart data passed?
-		if ( ! is_array($items) OR count($items) == 0)
+		if ( ! is_array($items) OR count($items) === 0)
 		{
 			return FALSE;
 		}
@@ -302,9 +267,9 @@
 		// determine the array type is by looking for a required array key named "id".
 		// If it's not found we assume it's a multi-dimensional array
 		$save_cart = FALSE;
-		if (isset($items['rowid']) AND isset($items['qty']))
+		if (isset($items['rowid'], $items['qty']))
 		{
-			if ($this->_update($items) == TRUE)
+			if ($this->_update($items) === TRUE)
 			{
 				$save_cart = TRUE;
 			}
@@ -313,9 +278,9 @@
 		{
 			foreach ($items as $val)
 			{
-				if (is_array($val) AND isset($val['rowid']) AND isset($val['qty']))
+				if (is_array($val) && isset($val['rowid'], $val['qty']))
 				{
-					if ($this->_update($val) == TRUE)
+					if ($this->_update($val) === TRUE)
 					{
 						$save_cart = TRUE;
 					}
@@ -324,7 +289,7 @@
 		}
 
 		// Save the cart data if the insert was successful
-		if ($save_cart == TRUE)
+		if ($save_cart === TRUE)
 		{
 			$this->_save_cart();
 			return TRUE;
@@ -347,7 +312,7 @@
 	 * @param	array
 	 * @return	bool
 	 */
-	function _update($items = array())
+	private function _update($items = array())
 	{
 		// Without these array indexes there is nothing we can do
 		if ( ! isset($items['qty']) OR ! isset($items['rowid']) OR ! isset($this->_cart_contents[$items['rowid']]))
@@ -356,7 +321,7 @@
 		}
 
 		// Prep the quantity
-		$items['qty'] = preg_replace('/([^0-9])/i', '', $items['qty']);
+		$items['qty'] = (float) $items['qty'];
 
 		// Is the quantity a number?
 		if ( ! is_numeric($items['qty']))
@@ -393,15 +358,10 @@
 	 * @access	private
 	 * @return	bool
 	 */
-	function _save_cart()
+	private function _save_cart()
 	{
-		// Unset these so our total can be calculated correctly below
-		unset($this->_cart_contents['total_items']);
-		unset($this->_cart_contents['cart_total']);
-
 		// Lets add up the individual prices and set the cart sub-total
-		$total = 0;
-		$items = 0;
+		$this->_cart_contents['total_items'] = $this->_cart_contents['cart_total'] = 0;
 		foreach ($this->_cart_contents as $key => $val)
 		{
 			// We make sure the array contains the proper indexes
@@ -410,17 +370,11 @@
 				continue;
 			}
 
-			$total += ($val['price'] * $val['qty']);
-			$items += $val['qty'];
-
-			// Set the subtotal
+			$this->_cart_contents['cart_total'] += ($val['price'] * $val['qty']);
+			$this->_cart_contents['total_items'] += $val['qty'];
 			$this->_cart_contents[$key]['subtotal'] = ($this->_cart_contents[$key]['price'] * $this->_cart_contents[$key]['qty']);
 		}
 
-		// Set the cart total and total items.
-		$this->_cart_contents['total_items'] = $items;
-		$this->_cart_contents['cart_total'] = $total;
-
 		// Is our cart empty?  If so we delete it from the session
 		if (count($this->_cart_contents) <= 2)
 		{
@@ -446,13 +400,13 @@
 	 * @access	public
 	 * @return	integer
 	 */
-	function total()
+	public function total()
 	{
 		return $this->_cart_contents['cart_total'];
 	}
-	
+
 	// --------------------------------------------------------------------
-	
+
 	/**
 	 * Remove Item
 	 *
@@ -463,16 +417,12 @@
 	 */
 	 public function remove($rowid)
 	 {
-		// just do an unset 
+		// unset & save
 		unset($this->_cart_contents[$rowid]);
-		
-		// we need to save the cart now we've made our changes
 		$this->_save_cart();
-		
-		// completed
-		return true;
+		return TRUE;
 	 }
-	 
+
 	// --------------------------------------------------------------------
 
 	/**
@@ -483,7 +433,7 @@
 	 * @access	public
 	 * @return	integer
 	 */
-	function total_items()
+	public function total_items()
 	{
 		return $this->_cart_contents['total_items'];
 	}
@@ -498,19 +448,10 @@
 	 * @access	public
 	 * @return	array
 	 */
-	function contents($newest_first = false)
+	public function contents($newest_first = FALSE)
 	{
 		// do we want the newest first?
-		if($newest_first)
-		{
-			// reverse the array
-			$cart = array_reverse($this->_cart_contents);
-		}
-		else
-		{
-			// just added first to last
-			$cart = $this->_cast_contents;
-		}
+		$cart = ($newest_first) ? array_reverse($this->_cart_contents) : $this->_cart_contents;
 
 		// Remove these so they don't create a problem when showing the cart table
 		unset($cart['total_items']);
@@ -528,16 +469,11 @@
 	 * that has options associated with it.
 	 *
 	 * @access	public
-	 * @return	array
+	 * @return	bool
 	 */
-	function has_options($rowid = '')
+	public function has_options($rowid = '')
 	{
-		if ( ! isset($this->_cart_contents[$rowid]['options']) OR count($this->_cart_contents[$rowid]['options']) === 0)
-		{
-			return FALSE;
-		}
-
-		return TRUE;
+		return (isset($this->_cart_contents[$rowid]['options']) && count($this->_cart_contents[$rowid]['options']) !== 0) ? TRUE : FALSE;
 	}
 
 	// --------------------------------------------------------------------
@@ -550,14 +486,9 @@
 	 * @access	public
 	 * @return	array
 	 */
-	function product_options($rowid = '')
+	public function product_options($rowid = '')
 	{
-		if ( ! isset($this->_cart_contents[$rowid]['options']))
-		{
-			return array();
-		}
-
-		return $this->_cart_contents[$rowid]['options'];
+		return isset($this->_cart_contents[$rowid]['options']) ? $this->_cart_contents[$rowid]['options'] : array();
 	}
 
 	// --------------------------------------------------------------------
@@ -568,9 +499,9 @@
 	 * Returns the supplied number with commas and a decimal point.
 	 *
 	 * @access	public
-	 * @return	integer
+	 * @return	string
 	 */
-	function format_number($n = '')
+	public function format_number($n = '')
 	{
 		if ($n == '')
 		{
@@ -578,7 +509,7 @@
 		}
 
 		// Remove anything that isn't a number or decimal point.
-		$n = trim(preg_replace('/([^0-9\.])/i', '', $n));
+		$n = (float) $n;
 
 		return number_format($n, 2, '.', ',');
 	}
@@ -591,15 +522,11 @@
 	 * Empties the cart and kills the session
 	 *
 	 * @access	public
-	 * @return	null
+	 * @return	void
 	 */
-	function destroy()
+	public function destroy()
 	{
-		unset($this->_cart_contents);
-
-		$this->_cart_contents['cart_total'] = 0;
-		$this->_cart_contents['total_items'] = 0;
-
+		$this->_cart_contents = array('cart_total' => 0, 'total_items' => 0);
 		$this->CI->session->unset_userdata('cart_contents');
 	}
 
@@ -608,4 +535,4 @@
 // END Cart Class
 
 /* End of file Cart.php */
-/* Location: ./system/libraries/Cart.php */
\ No newline at end of file
+/* Location: ./system/libraries/Cart.php */
diff --git a/system/libraries/Driver.php b/system/libraries/Driver.php
index 8df137e..183a959 100644
--- a/system/libraries/Driver.php
+++ b/system/libraries/Driver.php
@@ -1,13 +1,13 @@
-<?php  if ( ! defined('BASEPATH')) exit('No direct script access allowed');
+<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
 /**
  * CodeIgniter
  *
  * An open source application development framework for PHP 5.1.6 or newer
  *
  * NOTICE OF LICENSE
- * 
+ *
  * Licensed under the Open Software License version 3.0
- * 
+ *
  * This source file is subject to the Open Software License (OSL 3.0) that is
  * bundled with this package in the files license.txt / license.rst.  It is
  * also available through the world wide web at this URL:
@@ -46,7 +46,7 @@
 
 	// The first time a child is used it won't exist, so we instantiate it
 	// subsequents calls will go straight to the proper child.
-	function __get($child)
+	public function __get($child)
 	{
 		if ( ! isset($this->lib_name))
 		{
@@ -55,11 +55,11 @@
 
 		// The class will be prefixed with the parent lib
 		$child_class = $this->lib_name.'_'.$child;
-	
+
 		// Remove the CI_ prefix and lowercase
 		$lib_name = ucfirst(strtolower(str_replace('CI_', '', $this->lib_name)));
 		$driver_name = strtolower(str_replace('CI_', '', $child_class));
-		
+
 		if (in_array($driver_name, array_map('strtolower', $this->valid_drivers)))
 		{
 			// check and see if the driver is in a separate file
@@ -119,6 +119,7 @@
  * @link
  */
 class CI_Driver {
+
 	protected $parent;
 
 	private $methods = array();
@@ -238,4 +239,4 @@
 // END CI_Driver CLASS
 
 /* End of file Driver.php */
-/* Location: ./system/libraries/Driver.php */
\ No newline at end of file
+/* Location: ./system/libraries/Driver.php */
diff --git a/system/libraries/Ftp.php b/system/libraries/Ftp.php
index 70d7fc8..99850a9 100644
--- a/system/libraries/Ftp.php
+++ b/system/libraries/Ftp.php
@@ -1,13 +1,13 @@
-<?php  if ( ! defined('BASEPATH')) exit('No direct script access allowed');
+<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
 /**
  * CodeIgniter
  *
  * An open source application development framework for PHP 5.1.6 or newer
  *
  * NOTICE OF LICENSE
- * 
+ *
  * Licensed under the Open Software License version 3.0
- * 
+ *
  * This source file is subject to the Open Software License (OSL 3.0) that is
  * bundled with this package in the files license.txt / license.rst.  It is
  * also available through the world wide web at this URL:
@@ -38,13 +38,13 @@
  */
 class CI_FTP {
 
-	var $hostname	= '';
-	var $username	= '';
-	var $password	= '';
-	var $port		= 21;
-	var $passive	= TRUE;
-	var $debug		= FALSE;
-	var $conn_id	= FALSE;
+	public $hostname	= '';
+	public $username	= '';
+	public $password	= '';
+	public $port		= 21;
+	public $passive	= TRUE;
+	public $debug		= FALSE;
+	public $conn_id	= FALSE;
 
 
 	/**
@@ -71,7 +71,7 @@
 	 * @param	array
 	 * @return	void
 	 */
-	function initialize($config = array())
+	public function initialize($config = array())
 	{
 		foreach ($config as $key => $val)
 		{
@@ -94,7 +94,7 @@
 	 * @param	array	 the connection values
 	 * @return	bool
 	 */
-	function connect($config = array())
+	public function connect($config = array())
 	{
 		if (count($config) > 0)
 		{
@@ -136,7 +136,7 @@
 	 * @access	private
 	 * @return	bool
 	 */
-	function _login()
+	private function _login()
 	{
 		return @ftp_login($this->conn_id, $this->username, $this->password);
 	}
@@ -149,7 +149,7 @@
 	 * @access	private
 	 * @return	bool
 	 */
-	function _is_conn()
+	private function _is_conn()
 	{
 		if ( ! is_resource($this->conn_id))
 		{
@@ -179,7 +179,7 @@
 	 * @param	bool
 	 * @return	bool
 	 */
-	function changedir($path = '', $supress_debug = FALSE)
+	public function changedir($path = '', $supress_debug = FALSE)
 	{
 		if ($path == '' OR ! $this->_is_conn())
 		{
@@ -209,7 +209,7 @@
 	 * @param	string
 	 * @return	bool
 	 */
-	function mkdir($path = '', $permissions = NULL)
+	public function mkdir($path = '', $permissions = NULL)
 	{
 		if ($path == '' OR ! $this->_is_conn())
 		{
@@ -247,7 +247,7 @@
 	 * @param	string
 	 * @return	bool
 	 */
-	function upload($locpath, $rempath, $mode = 'auto', $permissions = NULL)
+	public function upload($locpath, $rempath, $mode = 'auto', $permissions = NULL)
 	{
 		if ( ! $this->_is_conn())
 		{
@@ -261,14 +261,14 @@
 		}
 
 		// Set the mode if not specified
-		if ($mode == 'auto')
+		if ($mode === 'auto')
 		{
 			// Get the file extension so we can set the upload type
 			$ext = $this->_getext($locpath);
 			$mode = $this->_settype($ext);
 		}
 
-		$mode = ($mode == 'ascii') ? FTP_ASCII : FTP_BINARY;
+		$mode = ($mode === 'ascii') ? FTP_ASCII : FTP_BINARY;
 
 		$result = @ftp_put($this->conn_id, $rempath, $locpath, $mode);
 
@@ -301,7 +301,7 @@
 	 * @param	string
 	 * @return	bool
 	 */
-	function download($rempath, $locpath, $mode = 'auto')
+	public function download($rempath, $locpath, $mode = 'auto')
 	{
 		if ( ! $this->_is_conn())
 		{
@@ -309,14 +309,14 @@
 		}
 
 		// Set the mode if not specified
-		if ($mode == 'auto')
+		if ($mode === 'auto')
 		{
 			// Get the file extension so we can set the upload type
 			$ext = $this->_getext($rempath);
 			$mode = $this->_settype($ext);
 		}
 
-		$mode = ($mode == 'ascii') ? FTP_ASCII : FTP_BINARY;
+		$mode = ($mode === 'ascii') ? FTP_ASCII : FTP_BINARY;
 
 		$result = @ftp_get($this->conn_id, $locpath, $rempath, $mode);
 
@@ -343,7 +343,7 @@
 	 * @param	bool
 	 * @return	bool
 	 */
-	function rename($old_file, $new_file, $move = FALSE)
+	public function rename($old_file, $new_file, $move = FALSE)
 	{
 		if ( ! $this->_is_conn())
 		{
@@ -356,9 +356,7 @@
 		{
 			if ($this->debug == TRUE)
 			{
-				$msg = ($move == FALSE) ? 'ftp_unable_to_rename' : 'ftp_unable_to_move';
-
-				$this->_error($msg);
+				$this->_error('ftp_unable_to_' . ($move == FALSE ? 'rename' : 'move'));
 			}
 			return FALSE;
 		}
@@ -376,7 +374,7 @@
 	 * @param	string
 	 * @return	bool
 	 */
-	function move($old_file, $new_file)
+	public function move($old_file, $new_file)
 	{
 		return $this->rename($old_file, $new_file, TRUE);
 	}
@@ -390,7 +388,7 @@
 	 * @param	string
 	 * @return	bool
 	 */
-	function delete_file($filepath)
+	public function delete_file($filepath)
 	{
 		if ( ! $this->_is_conn())
 		{
@@ -421,7 +419,7 @@
 	 * @param	string
 	 * @return	bool
 	 */
-	function delete_dir($filepath)
+	public function delete_dir($filepath)
 	{
 		if ( ! $this->_is_conn())
 		{
@@ -470,23 +468,13 @@
 	 * @param	string	the permissions
 	 * @return	bool
 	 */
-	function chmod($path, $perm)
+	public function chmod($path, $perm)
 	{
 		if ( ! $this->_is_conn())
 		{
 			return FALSE;
 		}
 
-		// Permissions can only be set when running PHP 5
-		if ( ! function_exists('ftp_chmod'))
-		{
-			if ($this->debug == TRUE)
-			{
-				$this->_error('ftp_unable_to_chmod');
-			}
-			return FALSE;
-		}
-
 		$result = @ftp_chmod($this->conn_id, $perm, $path);
 
 		if ($result === FALSE)
@@ -509,7 +497,7 @@
 	 * @access	public
 	 * @return	array
 	 */
-	function list_files($path = '.')
+	public function list_files($path = '.')
 	{
 		if ( ! $this->_is_conn())
 		{
@@ -533,7 +521,7 @@
 	 * @param	string	path to destination - include the base folder with trailing slash
 	 * @return	bool
 	 */
-	function mirror($locpath, $rempath)
+	public function mirror($locpath, $rempath)
 	{
 		if ( ! $this->_is_conn())
 		{
@@ -543,24 +531,20 @@
 		// Open the local file path
 		if ($fp = @opendir($locpath))
 		{
-			// Attempt to open the remote file path.
-			if ( ! $this->changedir($rempath, TRUE))
+			// Attempt to open the remote file path and try to create it, if it doesn't exist
+			if ( ! $this->changedir($rempath, TRUE) AND ( ! $this->mkdir($rempath) OR ! $this->changedir($rempath)))
 			{
-				// If it doesn't exist we'll attempt to create the direcotory
-				if ( ! $this->mkdir($rempath) OR ! $this->changedir($rempath))
-				{
-					return FALSE;
-				}
+				return FALSE;
 			}
 
 			// Recursively read the local directory
 			while (FALSE !== ($file = readdir($fp)))
 			{
-				if (@is_dir($locpath.$file) && substr($file, 0, 1) != '.')
+				if (@is_dir($locpath.$file) && $file[0] !== '.')
 				{
 					$this->mirror($locpath.$file."/", $rempath.$file."/");
 				}
-				elseif (substr($file, 0, 1) != ".")
+				elseif ($file[0] !== ".")
 				{
 					// Get the file extension so we can se the upload type
 					$ext = $this->_getext($file);
@@ -585,7 +569,7 @@
 	 * @param	string
 	 * @return	string
 	 */
-	function _getext($filename)
+	private function _getext($filename)
 	{
 		if (FALSE === strpos($filename, '.'))
 		{
@@ -606,7 +590,7 @@
 	 * @param	string
 	 * @return	string
 	 */
-	function _settype($ext)
+	private function _settype($ext)
 	{
 		$text_types = array(
 							'txt',
@@ -634,18 +618,16 @@
 	 * Close the connection
 	 *
 	 * @access	public
-	 * @param	string	path to source
-	 * @param	string	path to destination
 	 * @return	bool
 	 */
-	function close()
+	public function close()
 	{
 		if ( ! $this->_is_conn())
 		{
 			return FALSE;
 		}
 
-		@ftp_close($this->conn_id);
+		return @ftp_close($this->conn_id);
 	}
 
 	// ------------------------------------------------------------------------
@@ -655,9 +637,9 @@
 	 *
 	 * @access	private
 	 * @param	string
-	 * @return	bool
+	 * @return	void
 	 */
-	function _error($line)
+	private function _error($line)
 	{
 		$CI =& get_instance();
 		$CI->lang->load('ftp');
@@ -669,4 +651,4 @@
 // END FTP Class
 
 /* End of file Ftp.php */
-/* Location: ./system/libraries/Ftp.php */
\ No newline at end of file
+/* Location: ./system/libraries/Ftp.php */
diff --git a/user_guide_src/source/changelog.rst b/user_guide_src/source/changelog.rst
index 62f60b1..8a7109f 100644
--- a/user_guide_src/source/changelog.rst
+++ b/user_guide_src/source/changelog.rst
@@ -75,6 +75,7 @@
 -  Fixed a bug where using $this->dbforge->create_table() with PostgreSQL database could lead to fetching whole table.
 -  Bug #795 - Fixed form method and accept-charset when passing an empty array.
 -  Bug #797 - timespan was using incorrect seconds for year and month.
+-  Fixed a bug in CI_Cart::contents() where if called without a TRUE (or equal) parameter, it would fail due to a typo.
 
 Version 2.1.0
 =============