Merge pull request #752 from toopay/pdo_sqlite

Fix for PDO driver, exception for sqlite in DSN spec
diff --git a/system/helpers/inflector_helper.php b/system/helpers/inflector_helper.php
index 513a9c5..3393bda 100644
--- a/system/helpers/inflector_helper.php
+++ b/system/helpers/inflector_helper.php
@@ -5,9 +5,9 @@
  * 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:
@@ -84,7 +84,7 @@
 			'/(n)ews$/'             => '\1\2ews',
 			'/([^u])s$/'            => '\1',
 		);
-		
+
 		foreach ($singular_rules as $rule => $replacement)
 		{
 			if (preg_match($rule, $result))
@@ -115,7 +115,7 @@
 	function plural($str, $force = FALSE)
 	{
 		$result = strval($str);
-	
+
 		$plural_rules = array(
 			'/^(ox)$/'                 => '\1\2en',     // ox
 			'/([m|l])ouse$/'           => '\1ice',      // mouse, louse
@@ -196,20 +196,20 @@
 /**
  * Humanize
  *
- * Takes multiple words separated by underscores and changes them to spaces
+ * Takes multiple words separated by the separator and changes them to spaces
  *
  * @access	public
- * @param	string
+ * @param	string $str
+ * @param 	string $separator
  * @return	str
  */
 if ( ! function_exists('humanize'))
 {
-	function humanize($str)
+	function humanize($str, $separator = '_')
 	{
-		return ucwords(preg_replace('/[_]+/', ' ', strtolower(trim($str))));
+		return ucwords(preg_replace('/['.$separator.']+/', ' ', strtolower(trim($str))));
 	}
 }
 
-
 /* End of file inflector_helper.php */
 /* Location: ./system/helpers/inflector_helper.php */
\ No newline at end of file
diff --git a/system/libraries/Cart.php b/system/libraries/Cart.php
index a0e1bb9..717ccd9 100644
--- a/system/libraries/Cart.php
+++ b/system/libraries/Cart.php
@@ -41,6 +41,7 @@
 	// 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
 
 	// Private variables.  Do not change!
 	var $CI;
@@ -195,7 +196,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 ( ! 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;
@@ -242,7 +243,18 @@
 		// --------------------------------------------------------------------
 
 		// 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]);
 
@@ -254,7 +266,10 @@
 		{
 			$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;
 	}
@@ -435,7 +450,29 @@
 	{
 		return $this->_cart_contents['cart_total'];
 	}
-
+	
+	// --------------------------------------------------------------------
+	
+	/**
+	 * Remove Item
+	 *
+	 * Removes an item from the cart
+	 *
+	 * @access	public
+	 * @return	boolean
+	 */
+	 public function remove($rowid)
+	 {
+		// just do an unset 
+		unset($this->_cart_contents[$rowid]);
+		
+		// we need to save the cart now we've made our changes
+		$this->_save_cart();
+		
+		// completed
+		return true;
+	 }
+	 
 	// --------------------------------------------------------------------
 
 	/**
@@ -461,9 +498,19 @@
 	 * @access	public
 	 * @return	array
 	 */
-	function contents()
+	function contents($newest_first = false)
 	{
-		$cart = $this->_cart_contents;
+		// 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;
+		}
 
 		// Remove these so they don't create a problem when showing the cart table
 		unset($cart['total_items']);
diff --git a/user_guide_src/source/changelog.rst b/user_guide_src/source/changelog.rst
index 205b087..72b7f7e 100644
--- a/user_guide_src/source/changelog.rst
+++ b/user_guide_src/source/changelog.rst
@@ -33,6 +33,7 @@
 
    -  url_title() will now trim extra dashes from beginning and end.
    -  Added XHTML Basic 1.1 doctype to :doc:`HTML Helper <helpers/html_helper>`.
+   -  Changed humanize to include a second param for the separator.
 
 -  Database
 
@@ -46,6 +47,10 @@
    -  CI_Loader::_ci_autoloader() is now a protected method.
    -  Modified valid_ip() to use PHP's filter_var() when possible (>= PHP 5.2) in the :doc:`Form Validation library <libraries/form_validation>`.
 	 -  Added custom filename to Email::attach() as $this->email->attach($filename, $disposition, $newname)
+   -  Cart library changes include;
+	 -  It now auto-increments quantity's instead of just resetting it, this is the default behaviour of large e-commerce sites.
+	 -  Product Name strictness can be disabled via the Cart Library by switching "$product_name_safe"
+	 -  Added function remove() to remove a cart item, updating with quantity of 0 seemed like a hack but has remained to retain compatability
 
 -  Core
 
diff --git a/user_guide_src/source/helpers/inflector_helper.rst b/user_guide_src/source/helpers/inflector_helper.rst
index cf246b9..cc46a18 100644
--- a/user_guide_src/source/helpers/inflector_helper.rst
+++ b/user_guide_src/source/helpers/inflector_helper.rst
@@ -77,3 +77,9 @@
 	$word = "my_dog_spot";
 	echo humanize($word); // Returns "My Dog Spot"
 
+To use dashes instead of underscores
+
+::
+
+	$word = "my-dog-spot";
+	echo humanize($word, '-'); // Returns "My Dog Spot"
\ No newline at end of file
diff --git a/user_guide_src/source/helpers/text_helper.rst b/user_guide_src/source/helpers/text_helper.rst
index e976432..8cb2d6f 100644
--- a/user_guide_src/source/helpers/text_helper.rst
+++ b/user_guide_src/source/helpers/text_helper.rst
@@ -46,6 +46,9 @@
 The third parameter is an optional suffix added to the string, if
 undeclared this helper uses an ellipsis.
 
+**Note:** If you need to truncate to an exact number of characters please see
+the :ref:`ellipsize` function below.
+
 ascii_to_entities()
 ===================
 
@@ -136,6 +139,8 @@
 
 	// Would produce:  Here is a simple string of text that will help us demonstrate this function
 
+.. _ellipsize:
+
 ellipsize()
 ===========
 
diff --git a/user_guide_src/source/libraries/cart.rst b/user_guide_src/source/libraries/cart.rst
index 850d7e9..fbf7778 100644
--- a/user_guide_src/source/libraries/cart.rst
+++ b/user_guide_src/source/libraries/cart.rst
@@ -256,6 +256,11 @@
 
 Permits you to update items in the shopping cart, as outlined above.
 
+$this->cart->remove(rowid);
+**********************
+
+Allows you to remove an item from the shopping cart by passing it the rowid.
+
 $this->cart->total();
 *********************
 
@@ -266,10 +271,13 @@
 
 Displays the total number of items in the cart.
 
-$this->cart->contents();
+$this->cart->contents(boolean);
 ************************
 
-Returns an array containing everything in the cart.
+Returns an array containing everything in the cart. You can sort the order,
+by which this is returned by passing it "true" where the contents will be sorted
+from newest to oldest, by leaving this function blank, you'll automatically just get
+first added to the basket to last added to the basket.
 
 $this->cart->has_options(rowid);
 *********************************
diff --git a/user_guide_src/source/tutorial/create_news_items.rst b/user_guide_src/source/tutorial/create_news_items.rst
index 003b94b..794b67e 100644
--- a/user_guide_src/source/tutorial/create_news_items.rst
+++ b/user_guide_src/source/tutorial/create_news_items.rst
@@ -2,7 +2,7 @@
 Create news items
 #################
 
-You now know how you can read data from a database using CodeIgnite, but
+You now know how you can read data from a database using CodeIgniter, but
 you haven't written any information to the database yet. In this section
 you'll expand your news controller and model created earlier to include
 this functionality.