Merge pull request #826 from EllisLab/feature/abstract-config-load

Abstracting the loading of files in the config directory depending on environments
diff --git a/system/core/Utf8.php b/system/core/Utf8.php
index 7abe4e4..1bcf526 100644
--- a/system/core/Utf8.php
+++ b/system/core/Utf8.php
@@ -44,19 +44,18 @@
 	 * Constructor
 	 *
 	 * Determines if UTF-8 support is to be enabled
-	 *
 	 */
-	function __construct()
+	public function __construct()
 	{
 		log_message('debug', "Utf8 Class Initialized");
 
 		global $CFG;
 
 		if (
-			preg_match('/./u', 'é') === 1					// PCRE must support UTF-8
-			AND function_exists('iconv')					// iconv must be installed
-			AND ini_get('mbstring.func_overload') != 1		// Multibyte string function overloading cannot be enabled
-			AND $CFG->item('charset') == 'UTF-8'			// Application charset must be UTF-8
+			@preg_match('/./u', 'é') === 1		// PCRE must support UTF-8
+			&& function_exists('iconv')			// iconv must be installed
+			&& ini_get('mbstring.func_overload') !== 1	// Multibyte string function overloading cannot be enabled
+			&& $CFG->item('charset') == 'UTF-8'			// Application charset must be UTF-8
 			)
 		{
 			log_message('debug', "UTF-8 Support Enabled");
@@ -90,11 +89,10 @@
 	 *
 	 * Ensures strings are UTF-8
 	 *
-	 * @access	public
 	 * @param	string
 	 * @return	string
 	 */
-	function clean_string($str)
+	public function clean_string($str)
 	{
 		if ($this->_is_ascii($str) === FALSE)
 		{
@@ -113,11 +111,10 @@
 	 * line feeds, and carriage returns, as all others can cause
 	 * problems in XML
 	 *
-	 * @access	public
 	 * @param	string
 	 * @return	string
 	 */
-	function safe_ascii_for_xml($str)
+	public function safe_ascii_for_xml($str)
 	{
 		return remove_invisible_characters($str, FALSE);
 	}
@@ -129,12 +126,11 @@
 	 *
 	 * Attempts to convert a string to UTF-8
 	 *
-	 * @access	public
 	 * @param	string
 	 * @param	string	- input encoding
 	 * @return	string
 	 */
-	function convert_to_utf8($str, $encoding)
+	public function convert_to_utf8($str, $encoding)
 	{
 		if (function_exists('iconv'))
 		{
@@ -159,13 +155,12 @@
 	 *
 	 * Tests if a string is standard 7-bit ASCII or not
 	 *
-	 * @access	public
 	 * @param	string
 	 * @return	bool
 	 */
-	function _is_ascii($str)
+	protected function _is_ascii($str)
 	{
-		return (preg_match('/[^\x00-\x7F]/S', $str) == 0);
+		return (preg_match('/[^\x00-\x7F]/S', $str) === 0);
 	}
 
 	// --------------------------------------------------------------------
diff --git a/system/database/drivers/sqlsrv/sqlsrv_driver.php b/system/database/drivers/sqlsrv/sqlsrv_driver.php
index 0f9f578..340cd3a 100644
--- a/system/database/drivers/sqlsrv/sqlsrv_driver.php
+++ b/system/database/drivers/sqlsrv/sqlsrv_driver.php
@@ -98,7 +98,7 @@
 	 */
 	function db_pconnect()
 	{
-		$this->db_connect(TRUE);
+		return $this->db_connect(TRUE);
 	}
 
 	// --------------------------------------------------------------------
diff --git a/system/libraries/Cache/Cache.php b/system/libraries/Cache/Cache.php
index c296fa7..8725373 100644
--- a/system/libraries/Cache/Cache.php
+++ b/system/libraries/Cache/Cache.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:
@@ -22,22 +22,22 @@
  * @license		http://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0)
  * @link		http://codeigniter.com
  * @since		Version 2.0
- * @filesource	
+ * @filesource
  */
 
 // ------------------------------------------------------------------------
 
 /**
- * CodeIgniter Caching Class 
+ * CodeIgniter Caching Class
  *
  * @package		CodeIgniter
  * @subpackage	Libraries
  * @category	Core
  * @author		EllisLab Dev Team
- * @link		
+ * @link
  */
 class CI_Cache extends CI_Driver_Library {
-	
+
 	protected $valid_drivers 	= array(
 		'cache_apc', 'cache_file', 'cache_memcached', 'cache_dummy'
 	);
@@ -45,7 +45,7 @@
 	protected $_cache_path		= NULL;		// Path of cache files (if file-based cache)
 	protected $_adapter			= 'dummy';
 	protected $_backup_driver;
-	
+
 	// ------------------------------------------------------------------------
 
 	/**
@@ -64,16 +64,16 @@
 	// ------------------------------------------------------------------------
 
 	/**
-	 * Get 
+	 * Get
 	 *
-	 * Look for a value in the cache.  If it exists, return the data 
+	 * Look for a value in the cache.  If it exists, return the data
 	 * if not, return FALSE
 	 *
-	 * @param 	string	
+	 * @param 	string
 	 * @return 	mixed		value that is stored/FALSE on failure
 	 */
 	public function get($id)
-	{	
+	{
 		return $this->{$this->_adapter}->get($id);
 	}
 
@@ -124,7 +124,7 @@
 	 * Cache Info
 	 *
 	 * @param 	string		user/filehits
-	 * @return 	mixed		array on success, false on failure	
+	 * @return 	mixed		array on success, false on failure
 	 */
 	public function cache_info($type = 'user')
 	{
@@ -132,7 +132,7 @@
 	}
 
 	// ------------------------------------------------------------------------
-	
+
 	/**
 	 * Get Cache Metadata
 	 *
@@ -143,7 +143,7 @@
 	{
 		return $this->{$this->_adapter}->get_metadata($id);
 	}
-	
+
 	// ------------------------------------------------------------------------
 
 	/**
@@ -151,7 +151,7 @@
 	 *
 	 * Initialize class properties based on the configuration array.
 	 *
-	 * @param	array 	
+	 * @param	array
 	 * @return 	void
 	 */
 	private function _initialize($config)
@@ -219,10 +219,10 @@
 
 		return $obj;
 	}
-	
+
 	// ------------------------------------------------------------------------
 }
 // End Class
 
 /* End of file Cache.php */
-/* Location: ./system/libraries/Cache/Cache.php */
\ No newline at end of file
+/* Location: ./system/libraries/Cache/Cache.php */
diff --git a/system/libraries/Cache/drivers/Cache_apc.php b/system/libraries/Cache/drivers/Cache_apc.php
index f15cf85..90b6868 100644
--- a/system/libraries/Cache/drivers/Cache_apc.php
+++ b/system/libraries/Cache/drivers/Cache_apc.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:
@@ -22,30 +22,30 @@
  * @license		http://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0)
  * @link		http://codeigniter.com
  * @since		Version 2.0
- * @filesource	
+ * @filesource
  */
 
 // ------------------------------------------------------------------------
 
 /**
- * CodeIgniter APC Caching Class 
+ * CodeIgniter APC Caching Class
  *
  * @package		CodeIgniter
  * @subpackage	Libraries
  * @category	Core
  * @author		EllisLab Dev Team
- * @link		
+ * @link
  */
 
 class CI_Cache_apc extends CI_Driver {
 
 	/**
-	 * Get 
+	 * Get
 	 *
-	 * Look for a value in the cache.  If it exists, return the data 
+	 * Look for a value in the cache.  If it exists, return the data
 	 * if not, return FALSE
 	 *
-	 * @param 	string	
+	 * @param 	string
 	 * @return 	mixed		value that is stored/FALSE on failure
 	 */
 	public function get($id)
@@ -55,8 +55,8 @@
 		return (is_array($data)) ? $data[0] : FALSE;
 	}
 
-	// ------------------------------------------------------------------------	
-	
+	// ------------------------------------------------------------------------
+
 	/**
 	 * Cache Save
 	 *
@@ -70,7 +70,7 @@
 	{
 		return apc_store($id, array($data, time(), $ttl), $ttl);
 	}
-	
+
 	// ------------------------------------------------------------------------
 
 	/**
@@ -102,7 +102,7 @@
 	 * Cache Info
 	 *
 	 * @param 	string		user/filehits
-	 * @return 	mixed		array on success, false on failure	
+	 * @return 	mixed		array on success, false on failure
 	 */
 	 public function cache_info($type = NULL)
 	 {
@@ -149,13 +149,13 @@
 			log_message('error', 'The APC PHP extension must be loaded to use APC Cache.');
 			return FALSE;
 		}
-		
+
 		return TRUE;
 	}
 
 	// ------------------------------------------------------------------------
 
-	
+
 }
 // End Class
 
diff --git a/system/libraries/Cache/drivers/Cache_dummy.php b/system/libraries/Cache/drivers/Cache_dummy.php
index 965bb2b..ff787e9 100644
--- a/system/libraries/Cache/drivers/Cache_dummy.php
+++ b/system/libraries/Cache/drivers/Cache_dummy.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:
@@ -138,4 +138,4 @@
 // End Class
 
 /* End of file Cache_dummy.php */
-/* Location: ./system/libraries/Cache/drivers/Cache_dummy.php */
\ No newline at end of file
+/* Location: ./system/libraries/Cache/drivers/Cache_dummy.php */
diff --git a/system/libraries/Cache/drivers/Cache_file.php b/system/libraries/Cache/drivers/Cache_file.php
index be392d3..1942797 100644
--- a/system/libraries/Cache/drivers/Cache_file.php
+++ b/system/libraries/Cache/drivers/Cache_file.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:
@@ -22,19 +22,19 @@
  * @license		http://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0)
  * @link		http://codeigniter.com
  * @since		Version 2.0
- * @filesource	
+ * @filesource
  */
 
 // ------------------------------------------------------------------------
 
 /**
- * CodeIgniter Memcached Caching Class 
+ * CodeIgniter Memcached Caching Class
  *
  * @package		CodeIgniter
  * @subpackage	Libraries
  * @category	Core
  * @author		EllisLab Dev Team
- * @link		
+ * @link
  */
 
 class CI_Cache_file extends CI_Driver {
@@ -48,9 +48,7 @@
 	{
 		$CI =& get_instance();
 		$CI->load->helper('file');
-		
 		$path = $CI->config->item('cache_path');
-	
 		$this->_cache_path = ($path == '') ? APPPATH.'cache/' : $path;
 	}
 
@@ -68,16 +66,15 @@
 		{
 			return FALSE;
 		}
-		
-		$data = read_file($this->_cache_path.$id);
-		$data = unserialize($data);
-		
+
+		$data = unserialize(read_file($this->_cache_path.$id));
+
 		if (time() >  $data['time'] + $data['ttl'])
 		{
 			unlink($this->_cache_path.$id);
 			return FALSE;
 		}
-		
+
 		return $data['data'];
 	}
 
@@ -88,22 +85,22 @@
 	 *
 	 * @param 	string		unique key
 	 * @param 	mixed		data to store
-	 * @param 	int			length of time (in seconds) the cache is valid 
+	 * @param 	int			length of time (in seconds) the cache is valid
 	 *						- Default is 60 seconds
 	 * @return 	boolean		true on success/false on failure
 	 */
 	public function save($id, $data, $ttl = 60)
-	{		
+	{
 		$contents = array(
 				'time'		=> time(),
-				'ttl'		=> $ttl,			
+				'ttl'		=> $ttl,
 				'data'		=> $data
 			);
-		
+
 		if (write_file($this->_cache_path.$id, serialize($contents)))
 		{
 			@chmod($this->_cache_path.$id, 0777);
-			return TRUE;			
+			return TRUE;
 		}
 
 		return FALSE;
@@ -119,14 +116,7 @@
 	 */
 	public function delete($id)
 	{
-		if (file_exists($this->_cache_path.$id))
-		{
-			return unlink($this->_cache_path.$id);
-		}
-		else
-		{
-			return FALSE;
-		}
+		return (file_exists($this->_cache_path.$id)) ? unlink($this->_cache_path.$id) : FALSE;
 	}
 
 	// ------------------------------------------------------------------------
@@ -135,7 +125,7 @@
 	 * Clean the Cache
 	 *
 	 * @return 	boolean		false on failure/true on success
-	 */	
+	 */
 	public function clean()
 	{
 		return delete_files($this->_cache_path);
@@ -170,10 +160,9 @@
 		{
 			return FALSE;
 		}
-		
-		$data = read_file($this->_cache_path.$id);		
-		$data = unserialize($data);
-		
+
+		$data = unserialize(read_file($this->_cache_path.$id));
+
 		if (is_array($data))
 		{
 			$mtime = filemtime($this->_cache_path.$id);
@@ -188,7 +177,7 @@
 				'mtime'	 => $mtime
 			);
 		}
-		
+
 		return FALSE;
 	}
 
@@ -198,7 +187,7 @@
 	 * Is supported
 	 *
 	 * In the file driver, check to see that the cache directory is indeed writable
-	 * 
+	 *
 	 * @return boolean
 	 */
 	public function is_supported()
diff --git a/system/libraries/Cache/drivers/Cache_memcached.php b/system/libraries/Cache/drivers/Cache_memcached.php
index 78cab25..0037e67 100644
--- a/system/libraries/Cache/drivers/Cache_memcached.php
+++ b/system/libraries/Cache/drivers/Cache_memcached.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:
@@ -84,7 +84,7 @@
 		{
 			return $this->_memcached->set($id, array($data, time(), $ttl), 0, $ttl);
 		}
-		
+
 		return FALSE;
 	}
 
@@ -256,4 +256,4 @@
 // End Class
 
 /* End of file Cache_memcached.php */
-/* Location: ./system/libraries/Cache/drivers/Cache_memcached.php */
\ No newline at end of file
+/* Location: ./system/libraries/Cache/drivers/Cache_memcached.php */
diff --git a/system/libraries/Encrypt.php b/system/libraries/Encrypt.php
index c2cb808..92b0b3c 100644
--- a/system/libraries/Encrypt.php
+++ b/system/libraries/Encrypt.php
@@ -40,22 +40,19 @@
  */
 class CI_Encrypt {
 
-	var $CI;
-	var $encryption_key	= '';
-	var $_hash_type	= 'sha1';
-	var $_mcrypt_exists = FALSE;
-	var $_mcrypt_cipher;
-	var $_mcrypt_mode;
+	public $encryption_key	= '';
+	protected $_hash_type	= 'sha1';
+	protected $_mcrypt_exists = FALSE;
+	protected $_mcrypt_cipher;
+	protected $_mcrypt_mode;
 
 	/**
 	 * Constructor
 	 *
 	 * Simply determines whether the mcrypt library exists.
-	 *
 	 */
 	public function __construct()
 	{
-		$this->CI =& get_instance();
 		$this->_mcrypt_exists = ( ! function_exists('mcrypt_encrypt')) ? FALSE : TRUE;
 		log_message('debug', "Encrypt Class Initialized");
 	}
@@ -68,11 +65,10 @@
 	 * Returns it as MD5 in order to have an exact-length 128 bit key.
 	 * Mcrypt is sensitive to keys that are not the correct length
 	 *
-	 * @access	public
 	 * @param	string
 	 * @return	string
 	 */
-	function get_key($key = '')
+	public function get_key($key = '')
 	{
 		if ($key == '')
 		{
@@ -84,7 +80,7 @@
 			$CI =& get_instance();
 			$key = $CI->config->item('encryption_key');
 
-			if ($key == FALSE)
+			if ($key === FALSE)
 			{
 				show_error('In order to use the encryption class requires that you set an encryption key in your config file.');
 			}
@@ -98,13 +94,13 @@
 	/**
 	 * Set the encryption key
 	 *
-	 * @access	public
 	 * @param	string
 	 * @return	void
 	 */
-	function set_key($key = '')
+	public function set_key($key = '')
 	{
 		$this->encryption_key = $key;
+		return $this;
 	}
 
 	// --------------------------------------------------------------------
@@ -120,12 +116,11 @@
 	 * that is randomized with each call to this function,
 	 * even if the supplied message and key are the same.
 	 *
-	 * @access	public
 	 * @param	string	the string to encode
 	 * @param	string	the key
 	 * @return	string
 	 */
-	function encode($string, $key = '')
+	public function encode($string, $key = '')
 	{
 		$key = $this->get_key($key);
 
@@ -148,12 +143,11 @@
 	 *
 	 * Reverses the above process
 	 *
-	 * @access	public
 	 * @param	string
 	 * @param	string
 	 * @return	string
 	 */
-	function decode($string, $key = '')
+	public function decode($string, $key = '')
 	{
 		$key = $this->get_key($key);
 
@@ -191,13 +185,12 @@
 	 *
 	 * For more details, see http://codeigniter.com/user_guide/installation/upgrade_200.html#encryption
 	 *
-	 * @access	public
 	 * @param	string
 	 * @param	int		(mcrypt mode constant)
 	 * @param	string
 	 * @return	string
 	 */
-	function encode_from_legacy($string, $legacy_mode = MCRYPT_MODE_ECB, $key = '')
+	public function encode_from_legacy($string, $legacy_mode = MCRYPT_MODE_ECB, $key = '')
 	{
 		if ($this->_mcrypt_exists === FALSE)
 		{
@@ -242,12 +235,11 @@
 	 * Takes a plain-text string and key as input and generates an
 	 * encoded bit-string using XOR
 	 *
-	 * @access	private
 	 * @param	string
 	 * @param	string
 	 * @return	string
 	 */
-	function _xor_encode($string, $key)
+	protected function _xor_encode($string, $key)
 	{
 		$rand = '';
 		while (strlen($rand) < 32)
@@ -274,12 +266,11 @@
 	 * Takes an encoded string and key as input and generates the
 	 * plain-text original message
 	 *
-	 * @access	private
 	 * @param	string
 	 * @param	string
 	 * @return	string
 	 */
-	function _xor_decode($string, $key)
+	protected function _xor_decode($string, $key)
 	{
 		$string = $this->_xor_merge($string, $key);
 
@@ -299,12 +290,11 @@
 	 *
 	 * Takes a string and key as input and computes the difference using XOR
 	 *
-	 * @access	private
 	 * @param	string
 	 * @param	string
 	 * @return	string
 	 */
-	function _xor_merge($string, $key)
+	protected function _xor_merge($string, $key)
 	{
 		$hash = $this->hash($key);
 		$str = '';
@@ -321,12 +311,11 @@
 	/**
 	 * Encrypt using Mcrypt
 	 *
-	 * @access	public
 	 * @param	string
 	 * @param	string
 	 * @return	string
 	 */
-	function mcrypt_encode($data, $key)
+	public function mcrypt_encode($data, $key)
 	{
 		$init_size = mcrypt_get_iv_size($this->_get_cipher(), $this->_get_mode());
 		$init_vect = mcrypt_create_iv($init_size, MCRYPT_RAND);
@@ -338,12 +327,11 @@
 	/**
 	 * Decrypt using Mcrypt
 	 *
-	 * @access	public
 	 * @param	string
 	 * @param	string
 	 * @return	string
 	 */
-	function mcrypt_decode($data, $key)
+	public function mcrypt_decode($data, $key)
 	{
 		$data = $this->_remove_cipher_noise($data, $key);
 		$init_size = mcrypt_get_iv_size($this->_get_cipher(), $this->_get_mode());
@@ -365,14 +353,11 @@
 	 * against Man-in-the-middle attacks on CBC mode ciphers
 	 * http://www.ciphersbyritter.com/GLOSSARY.HTM#IV
 	 *
-	 * Function description
-	 *
-	 * @access	private
 	 * @param	string
 	 * @param	string
 	 * @return	string
 	 */
-	function _add_cipher_noise($data, $key)
+	protected function _add_cipher_noise($data, $key)
 	{
 		$keyhash = $this->hash($key);
 		$keylen = strlen($keyhash);
@@ -399,11 +384,10 @@
 	 *
 	 * Function description
 	 *
-	 * @access	public
 	 * @param	type
 	 * @return	type
 	 */
-	function _remove_cipher_noise($data, $key)
+	protected function _remove_cipher_noise($data, $key)
 	{
 		$keyhash = $this->hash($key);
 		$keylen = strlen($keyhash);
@@ -434,13 +418,13 @@
 	/**
 	 * Set the Mcrypt Cipher
 	 *
-	 * @access	public
 	 * @param	constant
 	 * @return	string
 	 */
-	function set_cipher($cipher)
+	public function set_cipher($cipher)
 	{
 		$this->_mcrypt_cipher = $cipher;
+		return $this;
 	}
 
 	// --------------------------------------------------------------------
@@ -448,13 +432,13 @@
 	/**
 	 * Set the Mcrypt Mode
 	 *
-	 * @access	public
 	 * @param	constant
 	 * @return	string
 	 */
 	function set_mode($mode)
 	{
 		$this->_mcrypt_mode = $mode;
+		return $this;
 	}
 
 	// --------------------------------------------------------------------
@@ -462,10 +446,9 @@
 	/**
 	 * Get Mcrypt cipher Value
 	 *
-	 * @access	private
 	 * @return	string
 	 */
-	function _get_cipher()
+	protected function _get_cipher()
 	{
 		if ($this->_mcrypt_cipher == '')
 		{
@@ -480,10 +463,9 @@
 	/**
 	 * Get Mcrypt Mode Value
 	 *
-	 * @access	private
 	 * @return	string
 	 */
-	function _get_mode()
+	protected function _get_mode()
 	{
 		if ($this->_mcrypt_mode == '')
 		{
@@ -498,11 +480,10 @@
 	/**
 	 * Set the Hash type
 	 *
-	 * @access	public
 	 * @param	string
 	 * @return	string
 	 */
-	function set_hash($type = 'sha1')
+	public function set_hash($type = 'sha1')
 	{
 		$this->_hash_type = ($type != 'sha1' AND $type != 'md5') ? 'sha1' : $type;
 	}
@@ -512,45 +493,13 @@
 	/**
 	 * Hash encode a string
 	 *
-	 * @access	public
 	 * @param	string
 	 * @return	string
 	 */
-	function hash($str)
+	public function hash($str)
 	{
-		return ($this->_hash_type == 'sha1') ? $this->sha1($str) : md5($str);
+		return ($this->_hash_type == 'sha1') ? sha1($str) : md5($str);
 	}
-
-	// --------------------------------------------------------------------
-
-	/**
-	 * Generate an SHA1 Hash
-	 *
-	 * @access	public
-	 * @param	string
-	 * @return	string
-	 */
-	function sha1($str)
-	{
-		if ( ! function_exists('sha1'))
-		{
-			if ( ! function_exists('mhash'))
-			{
-				require_once(BASEPATH.'libraries/Sha1.php');
-				$SH = new CI_SHA;
-				return $SH->generate($str);
-			}
-			else
-			{
-				return bin2hex(mhash(MHASH_SHA1, $str));
-			}
-		}
-		else
-		{
-			return sha1($str);
-		}
-	}
-
 }
 
 // END CI_Encrypt class
diff --git a/system/libraries/Sha1.php b/system/libraries/Sha1.php
deleted file mode 100644
index 477b92b..0000000
--- a/system/libraries/Sha1.php
+++ /dev/null
@@ -1,263 +0,0 @@
-<?php  if ( ! defined('BASEPATH')) exit('No direct script access allowed');
-/**
- * CodeIgniter
- *
- * An open source application development framework for PHP 5.1.6 or newer
- *
- * NOTICE OF LICENSE
- * 
- * Licensed under the Open Software License version 3.0
- * 
- * This source file is subject to the Open Software License (OSL 3.0) that is
- * bundled with this package in the files license.txt / license.rst.  It is
- * also available through the world wide web at this URL:
- * http://opensource.org/licenses/OSL-3.0
- * If you did not receive a copy of the license and are unable to obtain it
- * through the world wide web, please send an email to
- * licensing@ellislab.com so we can send you a copy immediately.
- *
- * @package		CodeIgniter
- * @author		EllisLab Dev Team
- * @copyright	Copyright (c) 2008 - 2011, EllisLab, Inc. (http://ellislab.com/)
- * @license		http://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0)
- * @link		http://codeigniter.com
- * @since		Version 1.0
- * @filesource
- */
-
-// ------------------------------------------------------------------------
-
-/**
- * SHA1 Encoding Class
- *
- * Purpose: Provides 160 bit hashing using The Secure Hash Algorithm
- * developed at the National Institute of Standards and Technology. The 40
- * character SHA1 message hash is computationally infeasible to crack.
- *
- * This class is a fallback for servers that are not running PHP greater than
- * 4.3, or do not have the MHASH library.
- *
- * This class is based on two scripts:
- *
- * Marcus Campbell's PHP implementation (GNU license)
- * http://www.tecknik.net/sha-1/
- *
- * ...which is based on Paul Johnston's JavaScript version
- * (BSD license). http://pajhome.org.uk/
- *
- * I encapsulated the functions and wrote one additional method to fix
- * a hex conversion bug. - Rick Ellis
- *
- * @package		CodeIgniter
- * @subpackage	Libraries
- * @category	Encryption
- * @author		EllisLab Dev Team
- * @link		http://codeigniter.com/user_guide/libraries/encryption.html
- */
-class CI_SHA1 {
-
-	public function __construct()
-	{
-		log_message('debug', "SHA1 Class Initialized");
-	}
-
-	/**
-	 * Generate the Hash
-	 *
-	 * @access	public
-	 * @param	string
-	 * @return	string
-	 */
-	function generate($str)
-	{
-		$n = ((strlen($str) + 8) >> 6) + 1;
-
-		for ($i = 0; $i < $n * 16; $i++)
-		{
-			$x[$i] = 0;
-		}
-
-		for ($i = 0; $i < strlen($str); $i++)
-		{
-			$x[$i >> 2] |= ord(substr($str, $i, 1)) << (24 - ($i % 4) * 8);
-		}
-
-		$x[$i >> 2] |= 0x80 << (24 - ($i % 4) * 8);
-
-		$x[$n * 16 - 1] = strlen($str) * 8;
-
-		$a =  1732584193;
-		$b = -271733879;
-		$c = -1732584194;
-		$d =  271733878;
-		$e = -1009589776;
-
-		for ($i = 0; $i < count($x); $i += 16)
-		{
-			$olda = $a;
-			$oldb = $b;
-			$oldc = $c;
-			$oldd = $d;
-			$olde = $e;
-
-			for ($j = 0; $j < 80; $j++)
-			{
-				if ($j < 16)
-				{
-					$w[$j] = $x[$i + $j];
-				}
-				else
-				{
-					$w[$j] = $this->_rol($w[$j - 3] ^ $w[$j - 8] ^ $w[$j - 14] ^ $w[$j - 16], 1);
-				}
-
-				$t = $this->_safe_add($this->_safe_add($this->_rol($a, 5), $this->_ft($j, $b, $c, $d)), $this->_safe_add($this->_safe_add($e, $w[$j]), $this->_kt($j)));
-
-				$e = $d;
-				$d = $c;
-				$c = $this->_rol($b, 30);
-				$b = $a;
-				$a = $t;
-			}
-
-			$a = $this->_safe_add($a, $olda);
-			$b = $this->_safe_add($b, $oldb);
-			$c = $this->_safe_add($c, $oldc);
-			$d = $this->_safe_add($d, $oldd);
-			$e = $this->_safe_add($e, $olde);
-		}
-
-		return $this->_hex($a).$this->_hex($b).$this->_hex($c).$this->_hex($d).$this->_hex($e);
-	}
-
-	// --------------------------------------------------------------------
-
-	/**
-	 * Convert a decimal to hex
-	 *
-	 * @access	private
-	 * @param	string
-	 * @return	string
-	 */
-	function _hex($str)
-	{
-		$str = dechex($str);
-
-		if (strlen($str) == 7)
-		{
-			$str = '0'.$str;
-		}
-
-		return $str;
-	}
-
-	// --------------------------------------------------------------------
-
-	/**
-	 *  Return result based on iteration
-	 *
-	 * @access	private
-	 * @return	string
-	 */
-	function _ft($t, $b, $c, $d)
-	{
-		if ($t < 20)
-			return ($b & $c) | ((~$b) & $d);
-		if ($t < 40)
-			return $b ^ $c ^ $d;
-		if ($t < 60)
-			return ($b & $c) | ($b & $d) | ($c & $d);
-
-		return $b ^ $c ^ $d;
-	}
-
-	// --------------------------------------------------------------------
-
-	/**
-	 * Determine the additive constant
-	 *
-	 * @access	private
-	 * @return	string
-	 */
-	function _kt($t)
-	{
-		if ($t < 20)
-		{
-			return 1518500249;
-		}
-		else if ($t < 40)
-		{
-			return 1859775393;
-		}
-		else if ($t < 60)
-		{
-			return -1894007588;
-		}
-		else
-		{
-			return -899497514;
-		}
-	}
-
-	// --------------------------------------------------------------------
-
-	/**
-	 * Add integers, wrapping at 2^32
-	 *
-	 * @access	private
-	 * @return	string
-	 */
-	function _safe_add($x, $y)
-	{
-		$lsw = ($x & 0xFFFF) + ($y & 0xFFFF);
-		$msw = ($x >> 16) + ($y >> 16) + ($lsw >> 16);
-
-		return ($msw << 16) | ($lsw & 0xFFFF);
-	}
-
-	// --------------------------------------------------------------------
-
-	/**
-	 * Bitwise rotate a 32-bit number
-	 *
-	 * @access	private
-	 * @return	integer
-	 */
-	function _rol($num, $cnt)
-	{
-		return ($num << $cnt) | $this->_zero_fill($num, 32 - $cnt);
-	}
-
-	// --------------------------------------------------------------------
-
-	/**
-	 * Pad string with zero
-	 *
-	 * @access	private
-	 * @return	string
-	 */
-	function _zero_fill($a, $b)
-	{
-		$bin = decbin($a);
-
-		if (strlen($bin) < $b)
-		{
-			$bin = 0;
-		}
-		else
-		{
-			$bin = substr($bin, 0, strlen($bin) - $b);
-		}
-
-		for ($i=0; $i < $b; $i++)
-		{
-			$bin = "0".$bin;
-		}
-
-		return bindec($bin);
-	}
-}
-// END CI_SHA
-
-/* End of file Sha1.php */
-/* Location: ./system/libraries/Sha1.php */
diff --git a/system/libraries/Typography.php b/system/libraries/Typography.php
index af6ca2b..651ba7b 100644
--- a/system/libraries/Typography.php
+++ b/system/libraries/Typography.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:
@@ -31,7 +31,7 @@
  * Typography Class
  *
  *
- * @access		private
+ * @access		protected
  * @category	Helpers
  * @author		EllisLab Dev Team
  * @link		http://codeigniter.com/user_guide/libraries/typography.html
@@ -39,22 +39,22 @@
 class CI_Typography {
 
 	// Block level elements that should not be wrapped inside <p> tags
-	var $block_elements = 'address|blockquote|div|dl|fieldset|form|h\d|hr|noscript|object|ol|p|pre|script|table|ul';
+	public $block_elements = 'address|blockquote|div|dl|fieldset|form|h\d|hr|noscript|object|ol|p|pre|script|table|ul';
 
 	// Elements that should not have <p> and <br /> tags within them.
-	var $skip_elements	= 'p|pre|ol|ul|dl|object|table|h\d';
+	public $skip_elements	= 'p|pre|ol|ul|dl|object|table|h\d';
 
 	// Tags we want the parser to completely ignore when splitting the string.
-	var $inline_elements = 'a|abbr|acronym|b|bdo|big|br|button|cite|code|del|dfn|em|i|img|ins|input|label|map|kbd|q|samp|select|small|span|strong|sub|sup|textarea|tt|var';
+	public $inline_elements = 'a|abbr|acronym|b|bdo|big|br|button|cite|code|del|dfn|em|i|img|ins|input|label|map|kbd|q|samp|select|small|span|strong|sub|sup|textarea|tt|var';
 
 	// array of block level elements that require inner content to be within another block level element
-	var $inner_block_required = array('blockquote');
+	public $inner_block_required = array('blockquote');
 
 	// the last block element parsed
-	var $last_block_element = '';
+	public $last_block_element = '';
 
 	// whether or not to protect quotes within { curly braces }
-	var $protect_braced_quotes = FALSE;
+	public $protect_braced_quotes = FALSE;
 
 	/**
 	 * Auto Typography
@@ -72,7 +72,7 @@
 	 * @param	bool	whether to reduce more then two consecutive newlines to two
 	 * @return	string
 	 */
-	function auto_typography($str, $reduce_linebreaks = FALSE)
+	public function auto_typography($str, $reduce_linebreaks = FALSE)
 	{
 		if ($str == '')
 		{
@@ -127,35 +127,32 @@
 		// adversely affected if they are split out so we'll convert the opening bracket < temporarily to: {@TAG}
 		$str = preg_replace("#<(/*)(".$this->inline_elements.")([ >])#i", "{@TAG}\\1\\2\\3", $str);
 
-		// Split the string at every tag.  This expression creates an array with this prototype:
-		//
-		//	[array]
-		//	{
-		//		[0] = <opening tag>
-		//		[1] = Content...
-		//		[2] = <closing tag>
-		//		Etc...
-		//	}
+		/* Split the string at every tag. This expression creates an array with this prototype:
+		 *
+		 *	[array]
+		 *	{
+		 *		[0] = <opening tag>
+		 *		[1] = Content...
+		 *		[2] = <closing tag>
+		 *		Etc...
+		 *	}
+		 */
 		$chunks = preg_split('/(<(?:[^<>]+(?:"[^"]*"|\'[^\']*\')?)+>)/', $str, -1, PREG_SPLIT_DELIM_CAPTURE|PREG_SPLIT_NO_EMPTY);
 
 		// Build our finalized string.  We cycle through the array, skipping tags, and processing the contained text
 		$str = '';
 		$process = TRUE;
 		$paragraph = FALSE;
-		$current_chunk = 0;
-		$total_chunks = count($chunks);
 
-		foreach ($chunks as $chunk)
+		for ($i = 1, $c = count($chunks); $i <= $c; $i++)
 		{
-			$current_chunk++;
-
 			// Are we dealing with a tag? If so, we'll skip the processing for this cycle.
 			// Well also set the "process" flag which allows us to skip <pre> tags and a few other things.
-			if (preg_match("#<(/*)(".$this->block_elements.").*?>#", $chunk, $match))
+			if (preg_match("#<(/*)(".$this->block_elements.").*?>#", $chunks[$i], $match))
 			{
 				if (preg_match("#".$this->skip_elements."#", $match[2]))
 				{
-					$process =  ($match[1] == '/') ? TRUE : FALSE;
+					$process = ($match[1] === '/');
 				}
 
 				if ($match[1] == '')
@@ -163,24 +160,24 @@
 					$this->last_block_element = $match[2];
 				}
 
-				$str .= $chunk;
+				$str .= $chunks[$i];
 				continue;
 			}
 
-			if ($process == FALSE)
+			if ($process === FALSE)
 			{
-				$str .= $chunk;
+				$str .= $chunks[$i];
 				continue;
 			}
 
 			//  Force a newline to make sure end tags get processed by _format_newlines()
-			if ($current_chunk == $total_chunks)
+			if ($i === $c)
 			{
-				$chunk .= "\n";
+				$chunks[$i] .= "\n";
 			}
 
 			//  Convert Newlines into <p> and <br /> tags
-			$str .= $this->_format_newlines($chunk);
+			$str .= $this->_format_newlines($chunks[$i]);
 		}
 
 		// No opening block level tag?  Add it if needed.
@@ -265,7 +262,7 @@
 	 * @param	string
 	 * @return	string
 	 */
-	function format_characters($str)
+	public function format_characters($str)
 	{
 		static $table;
 
@@ -325,18 +322,13 @@
 	 *
 	 * Converts newline characters into either <p> tags or <br />
 	 *
-	 * @access	public
+	 * @access	protected
 	 * @param	string
 	 * @return	string
 	 */
-	function _format_newlines($str)
+	protected function _format_newlines($str)
 	{
-		if ($str == '')
-		{
-			return $str;
-		}
-
-		if (strpos($str, "\n") === FALSE  && ! in_array($this->last_block_element, $this->inner_block_required))
+		if ($str == '' OR (strpos($str, "\n") === FALSE AND ! in_array($this->last_block_element, $this->inner_block_required)))
 		{
 			return $str;
 		}
@@ -373,11 +365,11 @@
 	 * and we don't want double dashes converted to emdash entities, so they are marked with {@DD}
 	 * likewise double spaces are converted to {@NBS} to prevent entity conversion
 	 *
-	 * @access	public
+	 * @access	protected
 	 * @param	array
 	 * @return	string
 	 */
-	function _protect_characters($match)
+	protected function _protect_characters($match)
 	{
 		return str_replace(array("'",'"','--','  '), array('{@SQ}', '{@DQ}', '{@DD}', '{@NBS}'), $match[0]);
 	}
@@ -391,25 +383,16 @@
 	 * @param	string
 	 * @return	string
 	 */
-	function nl2br_except_pre($str)
+	public function nl2br_except_pre($str)
 	{
-		$ex = explode("pre>",$str);
-		$ct = count($ex);
-
-		$newstr = "";
-		for ($i = 0; $i < $ct; $i++)
+		$newstr = '';
+		for ($ex = explode('pre>', $str), $ct = count($ex), $i = 0; $i < $ct; $i++)
 		{
-			if (($i % 2) == 0)
+			$newstr .= (($i % 2) === 0) ? nl2br($ex[$i]) : $ex[$i];
+			if ($ct - 1 !== $i)
 			{
-				$newstr .= nl2br($ex[$i]);
+				$newstr .= 'pre>';
 			}
-			else
-			{
-				$newstr .= $ex[$i];
-			}
-
-			if ($ct - 1 != $i)
-				$newstr .= "pre>";
 		}
 
 		return $newstr;
diff --git a/system/libraries/Xmlrpcs.php b/system/libraries/Xmlrpcs.php
index 587b750..893e518 100644
--- a/system/libraries/Xmlrpcs.php
+++ b/system/libraries/Xmlrpcs.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:
@@ -48,12 +48,11 @@
  */
 class CI_Xmlrpcs extends CI_Xmlrpc
 {
-	var $methods		= array();	//array of methods mapped to function names and signatures
-	var $debug_msg		= '';		// Debug Message
-	var $system_methods = array();	// XML RPC Server methods
-	var $controller_obj;
-
-	var $object			= FALSE;
+	public $methods		= array();	//array of methods mapped to function names and signatures
+	public $debug_msg	= '';		// Debug Message
+	public $system_methods	= array();	// XML RPC Server methods
+	public $controller_obj;
+	public $object		= FALSE;
 
 	/**
 	 * Constructor
@@ -80,7 +79,7 @@
 	 * @param	mixed
 	 * @return	void
 	 */
-	function initialize($config=array())
+	public function initialize($config = array())
 	{
 		if (isset($config['functions']) && is_array($config['functions']))
 		{
@@ -111,26 +110,26 @@
 	 * @access	public
 	 * @return	void
 	 */
-	function set_system_methods()
+	public function set_system_methods()
 	{
 		$this->methods = array(
 					'system.listMethods'	 => array(
-													'function' => 'this.listMethods',
-													'signature' => array(array($this->xmlrpcArray, $this->xmlrpcString), array($this->xmlrpcArray)),
-													'docstring' => 'Returns an array of available methods on this server'),
-					'system.methodHelp'		 => array(
-													'function' => 'this.methodHelp',
-													'signature' => array(array($this->xmlrpcString, $this->xmlrpcString)),
-													'docstring' => 'Returns a documentation string for the specified method'),
+										'function' => 'this.listMethods',
+										'signature' => array(array($this->xmlrpcArray, $this->xmlrpcString), array($this->xmlrpcArray)),
+										'docstring' => 'Returns an array of available methods on this server'),
+					'system.methodHelp'	 => array(
+										'function' => 'this.methodHelp',
+										'signature' => array(array($this->xmlrpcString, $this->xmlrpcString)),
+										'docstring' => 'Returns a documentation string for the specified method'),
 					'system.methodSignature' => array(
-													'function' => 'this.methodSignature',
-													'signature' => array(array($this->xmlrpcArray, $this->xmlrpcString)),
-													'docstring' => 'Returns an array describing the return type and required parameters of a method'),
-					'system.multicall'		 => array(
-												'function' => 'this.multicall',
-												'signature' => array(array($this->xmlrpcArray, $this->xmlrpcArray)),
-												'docstring' => 'Combine multiple RPC calls in one request. See http://www.xmlrpc.com/discuss/msgReader$1208 for details')
-					);
+										'function' => 'this.methodSignature',
+										'signature' => array(array($this->xmlrpcArray, $this->xmlrpcString)),
+										'docstring' => 'Returns an array describing the return type and required parameters of a method'),
+					'system.multicall'	 => array(
+										'function' => 'this.multicall',
+										'signature' => array(array($this->xmlrpcArray, $this->xmlrpcArray)),
+										'docstring' => 'Combine multiple RPC calls in one request. See http://www.xmlrpc.com/discuss/msgReader$1208 for details')
+				);
 	}
 
 	// --------------------------------------------------------------------
@@ -141,12 +140,10 @@
 	 * @access	public
 	 * @return	void
 	 */
-	function serve()
+	public function serve()
 	{
 		$r = $this->parseRequest();
-		$payload  = '<?xml version="1.0" encoding="'.$this->xmlrpc_defencoding.'"?'.'>'."\n";
-		$payload .= $this->debug_msg;
-		$payload .= $r->prepare_response();
+		$payload = '<?xml version="1.0" encoding="'.$this->xmlrpc_defencoding.'"?'.'>'."\n".$this->debug_msg.$r->prepare_response();
 
 		header("Content-Type: text/xml");
 		header("Content-Length: ".strlen($payload));
@@ -165,7 +162,7 @@
 	 * @param	string	docstring
 	 * @return	void
 	 */
-	function add_to_map($methodname, $function, $sig, $doc)
+	public function add_to_map($methodname, $function, $sig, $doc)
 	{
 		$this->methods[$methodname] = array(
 			'function'  => $function,
@@ -183,7 +180,7 @@
 	 * @param	string	data
 	 * @return	object	xmlrpc response
 	 */
-	function parseRequest($data='')
+	public function parseRequest($data = '')
 	{
 		global $HTTP_RAW_POST_DATA;
 
@@ -203,13 +200,14 @@
 		$parser = xml_parser_create($this->xmlrpc_defencoding);
 		$parser_object = new XML_RPC_Message("filler");
 
-		$parser_object->xh[$parser]					= array();
-		$parser_object->xh[$parser]['isf']			= 0;
-		$parser_object->xh[$parser]['isf_reason']	= '';
-		$parser_object->xh[$parser]['params']		= array();
-		$parser_object->xh[$parser]['stack']		= array();
-		$parser_object->xh[$parser]['valuestack']	= array();
-		$parser_object->xh[$parser]['method']		= '';
+		$parser_object->xh[$parser] = array(
+							'isf' =>	0,
+							'isf_reason' =>	'',
+							'params' =>	array(),
+							'stack' =>	array(),
+							'valuestack' =>	array(),
+							'method' =>	''
+						);
 
 		xml_set_object($parser, $parser_object);
 		xml_parser_set_option($parser, XML_OPTION_CASE_FOLDING, true);
@@ -243,7 +241,7 @@
 			$m = new XML_RPC_Message($parser_object->xh[$parser]['method']);
 			$plist='';
 
-			for ($i=0; $i < count($parser_object->xh[$parser]['params']); $i++)
+			for ($i = 0, $c = count($parser_object->xh[$parser]['params']); $i < $c; $i++)
 			{
 				if ($this->debug === TRUE)
 				{
@@ -255,9 +253,7 @@
 
 			if ($this->debug === TRUE)
 			{
-				echo "<pre>";
-				echo "---PLIST---\n" . $plist . "\n---PLIST END---\n\n";
-				echo "</pre>";
+				echo "<pre>---PLIST---\n".$plist."\n---PLIST END---\n\n</pre>";
 			}
 
 			$r = $this->_execute($m);
@@ -284,12 +280,12 @@
 	 * @param	object
 	 * @return	mixed
 	 */
-	function _execute($m)
+	protected function _execute($m)
 	{
 		$methName = $m->method_name;
 
 		// Check to see if it is a system call
-		$system_call = (strncmp($methName, 'system', 5) == 0) ? TRUE : FALSE;
+		$system_call = (strncmp($methName, 'system', 5) === 0);
 
 		if ($this->xss_clean == FALSE)
 		{
@@ -310,22 +306,20 @@
 		//-------------------------------------
 
 		$method_parts = explode(".", $this->methods[$methName]['function']);
-		$objectCall = (isset($method_parts['1']) && $method_parts['1'] != "") ? TRUE : FALSE;
+		$objectCall = (isset($method_parts[1]) && $method_parts[1] != '');
 
 		if ($system_call === TRUE)
 		{
-			if ( ! is_callable(array($this,$method_parts['1'])))
+			if ( ! is_callable(array($this,$method_parts[1])))
 			{
 				return new XML_RPC_Response(0, $this->xmlrpcerr['unknown_method'], $this->xmlrpcstr['unknown_method']);
 			}
 		}
 		else
 		{
-			if ($objectCall && ! is_callable(array($method_parts['0'],$method_parts['1'])))
-			{
-				return new XML_RPC_Response(0, $this->xmlrpcerr['unknown_method'], $this->xmlrpcstr['unknown_method']);
-			}
-			elseif ( ! $objectCall && ! is_callable($this->methods[$methName]['function']))
+			if (($objectCall AND ! is_callable(array($method_parts[0], $method_parts[1])))
+				OR ( ! $objectCall AND ! is_callable($this->methods[$methName]['function']))
+			)
 			{
 				return new XML_RPC_Response(0, $this->xmlrpcerr['unknown_method'], $this->xmlrpcstr['unknown_method']);
 			}
@@ -338,13 +332,13 @@
 		if (isset($this->methods[$methName]['signature']))
 		{
 			$sig = $this->methods[$methName]['signature'];
-			for ($i=0; $i<count($sig); $i++)
+			for ($i = 0, $c = count($sig); $i < $c; $i++)
 			{
 				$current_sig = $sig[$i];
 
-				if (count($current_sig) == count($m->params)+1)
+				if (count($current_sig) === count($m->params)+1)
 				{
-					for ($n=0; $n < count($m->params); $n++)
+					for ($n = 0, $mc = count($m->params); $n < $mc; $n++)
 					{
 						$p = $m->params[$n];
 						$pt = ($p->kindOf() == 'scalar') ? $p->scalarval() : $p->kindOf();
@@ -370,7 +364,7 @@
 
 		if ($objectCall === TRUE)
 		{
-			if ($method_parts[0] == "this" && $system_call == TRUE)
+			if ($method_parts[0] === 'this' && $system_call === TRUE)
 			{
 				return call_user_func(array($this, $method_parts[1]), $m);
 			}
@@ -379,11 +373,11 @@
 				if ($this->object === FALSE)
 				{
 					$CI =& get_instance();
-					return $CI->$method_parts['1']($m);
+					return $CI->$method_parts[1]($m);
 				}
 				else
 				{
-					return $this->object->$method_parts['1']($m);
+					return $this->object->$method_parts[1]($m);
 					//return call_user_func(array(&$method_parts['0'],$method_parts['1']), $m);
 				}
 			}
@@ -393,7 +387,7 @@
 			return call_user_func($this->methods[$methName]['function'], $m);
 		}
 	}
-	
+
 	// --------------------------------------------------------------------
 
 	/**
@@ -403,7 +397,7 @@
 	 * @param	mixed
 	 * @return	object
 	 */
-	function listMethods($m)
+	public function listMethods($m)
 	{
 		$v = new XML_RPC_Values();
 		$output = array();
@@ -421,7 +415,7 @@
 		$v->addArray($output);
 		return new XML_RPC_Response($v);
 	}
-	
+
 	// --------------------------------------------------------------------
 
 	/**
@@ -431,7 +425,7 @@
 	 * @param	mixed
 	 * @return	object
 	 */
-	function methodSignature($m)
+	public function methodSignature($m)
 	{
 		$parameters = $m->output_parameters();
 		$method_name = $parameters[0];
@@ -443,15 +437,15 @@
 				$sigs = array();
 				$signature = $this->methods[$method_name]['signature'];
 
-				for ($i=0; $i < count($signature); $i++)
+				for ($i = 0, $c = count($signature); $i < $c; $i++)
 				{
 					$cursig = array();
 					$inSig = $signature[$i];
-					for ($j=0; $j<count($inSig); $j++)
+					for ($j = 0, $jc = count($inSig); $j < $jc; $j++)
 					{
 						$cursig[]= new XML_RPC_Values($inSig[$j], 'string');
 					}
-					$sigs[]= new XML_RPC_Values($cursig, 'array');
+					$sigs[] = new XML_RPC_Values($cursig, 'array');
 				}
 				$r = new XML_RPC_Response(new XML_RPC_Values($sigs, 'array'));
 			}
@@ -476,7 +470,7 @@
 	 * @param	mixed
 	 * @return	object
 	 */
-	function methodHelp($m)
+	public function methodHelp($m)
 	{
 		$parameters = $m->output_parameters();
 		$method_name = $parameters[0];
@@ -492,7 +486,7 @@
 			return new XML_RPC_Response(0, $this->xmlrpcerr['introspect_unknown'], $this->xmlrpcstr['introspect_unknown']);
 		}
 	}
-	
+
 	// --------------------------------------------------------------------
 
 	/**
@@ -502,7 +496,7 @@
 	 * @param	mixed
 	 * @return	object
 	 */
-	function multicall($m)
+	public function multicall($m)
 	{
 		// Disabled
 		return new XML_RPC_Response(0, $this->xmlrpcerr['unknown_method'], $this->xmlrpcstr['unknown_method']);
@@ -519,7 +513,7 @@
 			$m = new XML_RPC_Message($value[0]);
 			$plist='';
 
-			for ($i=0; $i < count($value[1]); $i++)
+			for ($i = 0, $c = count($value[1]); $i < $c; $i++)
 			{
 				$m->addParam(new XML_RPC_Values($value[1][$i], 'string'));
 			}
@@ -546,7 +540,7 @@
 	 * @param	mixed
 	 * @return	object
 	 */
-	function multicall_error($err)
+	public function multicall_error($err)
 	{
 		$str  = is_string($err) ? $this->xmlrpcstr["multicall_${err}"] : $err->faultString();
 		$code = is_string($err) ? $this->xmlrpcerr["multicall_${err}"] : $err->faultCode();
@@ -566,7 +560,7 @@
 	 * @param	mixed
 	 * @return	object
 	 */
-	function do_multicall($call)
+	public function do_multicall($call)
 	{
 		if ($call->kindOf() != 'struct')
 		{
@@ -597,11 +591,10 @@
 			return $this->multicall_error('notarray');
 		}
 
-		list($a,$b)=each($params->me);
-		$numParams = count($b);
+		list($a,$b) = each($params->me);
 
 		$msg = new XML_RPC_Message($scalar_value);
-		for ($i = 0; $i < $numParams; $i++)
+		for ($i = 0, $numParams = count($b); $i < $numParams; $i++)
 		{
 			$msg->params[] = $params->me['array'][$i];
 		}
@@ -619,6 +612,5 @@
 }
 // END XML_RPC_Server class
 
-
 /* End of file Xmlrpcs.php */
-/* Location: ./system/libraries/Xmlrpcs.php */
\ No newline at end of file
+/* Location: ./system/libraries/Xmlrpcs.php */
diff --git a/user_guide_src/source/changelog.rst b/user_guide_src/source/changelog.rst
index 4f060a4..60425a4 100644
--- a/user_guide_src/source/changelog.rst
+++ b/user_guide_src/source/changelog.rst
@@ -28,6 +28,7 @@
    -  Added support 3gp, 3g2, mp4, wmv, f4v, vlc Video files to mimes.php.
    -  Added support m4a, aac, m4u, xspf, au, ac3, flac, ogg Audio files to mimes.php.
    -  Changed logger to only chmod when file is first created.
+   -  Removed previously deprecated SHA1 Library.
 
 -  Helpers
 
@@ -54,6 +55,7 @@
 	 -  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
    -  Minor speed optimizations and method & property visibility declarations in the Calendar Library.
+   -  Removed SHA1 function in the :doc:`Encryption Library <libraries/encryption>`.
 
 -  Core
 
@@ -79,6 +81,7 @@
 -  Fixed a 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.
 -  Fixed a bug (#696) - make oci_execute calls inside num_rows non-committing, since they are only there to reset which row is next in line for oci_fetch calls and thus don't need to be committed.
+-  Fixed a bug (#406) - sqlsrv DB driver not reuturning resource on <samp>db_pconnect()</samp>.
 
 Version 2.1.0
 =============
@@ -177,6 +180,7 @@
 -  Fixed a bug (#537) - Support for all wav type in browser.
 -  Fixed a bug (#576) - Using ini_get() function to detect if apc is enabled or not.
 -  Fixed invalid date time format in :doc:`Date helper <helpers/date_helper>` and :doc:`XMLRPC library <libraries/xmlrpc>`.
+-  Fixed a bug (#200) - MySQL queries would be malformed after calling count_all() then db->get().
 
 Version 2.0.3
 =============
diff --git a/user_guide_src/source/database/active_record.rst b/user_guide_src/source/database/active_record.rst
index 228d1d5..1600f0b 100644
--- a/user_guide_src/source/database/active_record.rst
+++ b/user_guide_src/source/database/active_record.rst
@@ -82,7 +82,7 @@
 utilize `$this->db->from()`_ and did not pass a table name into the first 
 parameter. The reason for this outcome is because the query has not been 
 executed using `$this->db->get()`_ which resets values or reset directly 
-using `$this-db->reset_query()`_.
+using `$this->db->reset_query()`_.
 
 
 $this->db->get_where()
@@ -96,8 +96,7 @@
 
 Please read the about the where function below for more information.
 
-.. note:: get_where() was formerly known as getwhere(), which has been
-removed
+.. note:: get_where() was formerly known as getwhere(), which has been removed
 
 $this->db->select()
 ===================
@@ -789,7 +788,7 @@
 This works exactly the same way as ``$this->db->get_compiled_insert()`` except
 that it produces an UPDATE SQL string instead of an INSERT SQL string.
 
-For more information view documentation for `$this->get_compiled_insert()`_.
+For more information view documentation for `$this->db->get_compiled_insert()`_.
 
 
 *************
@@ -864,7 +863,7 @@
 This works exactly the same way as ``$this->db->get_compiled_insert()`` except
 that it produces a DELETE SQL string instead of an INSERT SQL string.
 
-For more information view documentation for `$this->get_compiled_insert()`_.
+For more information view documentation for `$this->db->get_compiled_insert()`_.
 
 ***************
 Method Chaining
@@ -933,10 +932,8 @@
 	where, like, group_by, having, order_by, set
 
 
-
-*******************
-Reset Active Record
-*******************
+$this->db->reset_query()
+========================
 
 Resetting Active Record allows you to start fresh with your query without 
 executing it first using a method like $this->db->get() or $this->db->insert(). 
diff --git a/user_guide_src/source/database/configuration.rst b/user_guide_src/source/database/configuration.rst
index 433c671..4f88c25 100644
--- a/user_guide_src/source/database/configuration.rst
+++ b/user_guide_src/source/database/configuration.rst
@@ -158,6 +158,7 @@
 			while developing an application.
 **port**		The database port number. To use this value you have to add a line to the database config array.
 			::
+			
 				$db['default']['port'] =  5432;
 ======================  ==================================================================================================
 
diff --git a/user_guide_src/source/libraries/cart.rst b/user_guide_src/source/libraries/cart.rst
index fbf7778..6594b3b 100644
--- a/user_guide_src/source/libraries/cart.rst
+++ b/user_guide_src/source/libraries/cart.rst
@@ -257,7 +257,7 @@
 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.
 
@@ -267,12 +267,12 @@
 Displays the total amount in the cart.
 
 $this->cart->total_items();
-****************************
+***************************
 
 Displays the total number of items in the cart.
 
 $this->cart->contents(boolean);
-************************
+*******************************
 
 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
@@ -280,7 +280,7 @@
 first added to the basket to last added to the basket.
 
 $this->cart->has_options(rowid);
-*********************************
+********************************
 
 Returns TRUE (boolean) if a particular row in the cart contains options.
 This function is designed to be used in a loop with
@@ -288,7 +288,7 @@
 as shown in the Displaying the Cart example above.
 
 $this->cart->product_options(rowid);
-*************************************
+************************************
 
 Returns an array of options for a particular product. This function is
 designed to be used in a loop with $this->cart->contents(), since you
diff --git a/user_guide_src/source/libraries/encryption.rst b/user_guide_src/source/libraries/encryption.rst
index 80b45e4..28bdca2 100644
--- a/user_guide_src/source/libraries/encryption.rst
+++ b/user_guide_src/source/libraries/encryption.rst
@@ -126,21 +126,6 @@
 Please visit php.net for a list of `available
 modes <http://php.net/mcrypt>`_.
 
-$this->encrypt->sha1();
-=======================
-
-SHA1 encoding function. Provide a string and it will return a 160 bit
-one way hash. Note: SHA1, just like MD5 is non-decodable. Example::
-
-	$hash = $this->encrypt->sha1('Some string');
-
-Many PHP installations have SHA1 support by default so if all you need
-is to encode a hash it's simpler to use the native function::
-
-	$hash = sha1('Some string');
-
-If your server does not support SHA1 you can use the provided function.
-
 $this->encrypt->encode_from_legacy($orig_data, $legacy_mode = MCRYPT_MODE_ECB, $key = '');
 ==========================================================================================