Merge pull request #735 from tomasz154/develop

Made an "innocuous SQL statement" more innocuous
SELECT * FROM was running in the PostgreSQL drivers just for the sake of returning valid SQL, which could of course be insanely slow on large tables.
diff --git a/system/libraries/Form_validation.php b/system/libraries/Form_validation.php
index 5663da9..918f690 100644
--- a/system/libraries/Form_validation.php
+++ b/system/libraries/Form_validation.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:
@@ -949,7 +949,7 @@
 
 		return ($str !== $field) ? FALSE : TRUE;
 	}
-	
+
 	// --------------------------------------------------------------------
 
 	/**
@@ -962,10 +962,13 @@
 	 */
 	public function is_unique($str, $field)
 	{
-		list($table, $field)=explode('.', $field);
-		$query = $this->CI->db->limit(1)->get_where($table, array($field => $str));
-		
-		return $query->num_rows() === 0;
+		list($table, $field) = explode('.', $field);
+		if (isset($this->CI->db))
+		{
+			$query = $this->CI->db->limit(1)->get_where($table, array($field => $str));
+			return $query->num_rows() === 0;
+		}
+		return FALSE;
     }
 
 	// --------------------------------------------------------------------
diff --git a/system/libraries/Image_lib.php b/system/libraries/Image_lib.php
index beb463b..2ed488c 100644
--- a/system/libraries/Image_lib.php
+++ b/system/libraries/Image_lib.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:
@@ -116,15 +116,37 @@
 	 */
 	function clear()
 	{
-		$props = array('source_folder', 'dest_folder', 'source_image', 'full_src_path', 'full_dst_path', 'new_image', 'image_type', 'size_str', 'quality', 'orig_width', 'orig_height', 'rotation_angle', 'x_axis', 'y_axis', 'create_fnc', 'copy_fnc', 'wm_overlay_path', 'wm_use_truetype', 'dynamic_output', 'wm_font_size', 'wm_text', 'wm_vrt_alignment', 'wm_hor_alignment', 'wm_padding', 'wm_hor_offset', 'wm_vrt_offset', 'wm_font_color', 'wm_use_drop_shadow', 'wm_shadow_color', 'wm_shadow_distance', 'wm_opacity');
+		$props = array('library_path', 'source_image', 'new_image', 'width', 'height', 'rotation_angle', 'x_axis', 'y_axis', 'wm_text', 'wm_overlay_path', 'wm_font_path', 'wm_shadow_color', 'source_folder', 'dest_folder', 'mime_type', 'orig_width', 'orig_height', 'image_type', 'size_str', 'full_src_path', 'full_dst_path');
 
 		foreach ($props as $val)
 		{
 			$this->$val = '';
 		}
 
-		// special consideration for master_dim
-		$this->master_dim = 'auto';
+		$this->image_library 		= 'gd2';
+		$this->dynamic_output 		= FALSE;
+		$this->quality 				= '90';
+		$this->create_thumb 		= FALSE;
+		$this->thumb_marker 		= '_thumb';
+		$this->maintain_ratio 		= TRUE;
+		$this->master_dim 			= 'auto';
+		$this->wm_type 				= 'text';
+		$this->wm_x_transp 			= 4;
+		$this->wm_y_transp 			= 4;
+		$this->wm_font_size 		= 17;
+		$this->wm_vrt_alignment 	= 'B';
+		$this->wm_hor_alignment 	= 'C';
+		$this->wm_padding 			= 0;
+		$this->wm_hor_offset 		= 0;
+		$this->wm_vrt_offset 		= 0;
+		$this->wm_font_color		= '#ffffff';
+		$this->wm_shadow_distance 	= 2;
+		$this->wm_opacity 			= 50;
+		$this->create_fnc 			= 'imagecreatetruecolor';
+		$this->copy_fnc 			= 'imagecopyresampled';
+		$this->error_msg 			= array();
+		$this->wm_use_drop_shadow 	= FALSE;
+		$this->wm_use_truetype 		= FALSE;
 	}
 
 	// --------------------------------------------------------------------
@@ -158,7 +180,7 @@
 		if ($this->source_image == '')
 		{
 			$this->set_error('imglib_source_image_required');
-			return FALSE;	
+			return FALSE;
 		}
 
 		/*
@@ -201,7 +223,7 @@
 		// Set the Image Properties
 		if ( ! $this->get_image_properties($this->source_folder.$this->source_image))
 		{
-			return FALSE;	
+			return FALSE;
 		}
 
 		/*
@@ -411,7 +433,7 @@
 		if ($this->rotation_angle == '' OR ! in_array($this->rotation_angle, $degs))
 		{
 			$this->set_error('imglib_rotation_angle_required');
-			return FALSE;	
+			return FALSE;
 		}
 
 		// Reassign the width and height
diff --git a/system/libraries/Log.php b/system/libraries/Log.php
index 6ea905f..46c5b6e 100644
--- a/system/libraries/Log.php
+++ b/system/libraries/Log.php
@@ -111,6 +111,7 @@
 
 		if ( ! file_exists($filepath))
 		{
+			$newfile = TRUE;
 			$message .= "<"."?php  if ( ! defined('BASEPATH')) exit('No direct script access allowed'); ?".">\n\n";
 		}
 
@@ -126,7 +127,10 @@
 		flock($fp, LOCK_UN);
 		fclose($fp);
 
-		@chmod($filepath, FILE_WRITE_MODE);
+		if (isset($newfile) AND $newfile === TRUE)
+		{
+			@chmod($filepath, FILE_WRITE_MODE);
+		}
 		return TRUE;
 	}
 
@@ -134,4 +138,4 @@
 // END Log Class
 
 /* End of file Log.php */
-/* Location: ./system/libraries/Log.php */
\ No newline at end of file
+/* Location: ./system/libraries/Log.php */
diff --git a/system/libraries/Pagination.php b/system/libraries/Pagination.php
index f470deb..eea953a 100644
--- a/system/libraries/Pagination.php
+++ b/system/libraries/Pagination.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:
@@ -38,39 +38,38 @@
  */
 class CI_Pagination {
 
-	var $base_url			= ''; // The page we are linking to
-	var $prefix				= ''; // A custom prefix added to the path.
-	var $suffix				= ''; // A custom suffix added to the path.
-
-	var $total_rows			=  0; // Total number of items (database results)
-	var $per_page			= 10; // Max number of items you want shown per page
-	var $num_links			=  2; // Number of "digit" links to show before/after the currently viewed page
-	var $cur_page			=  0; // The current page being viewed
-	var $use_page_numbers	= FALSE; // Use page number for segment instead of offset
-	var $first_link			= '&lsaquo; First';
-	var $next_link			= '&gt;';
-	var $prev_link			= '&lt;';
-	var $last_link			= 'Last &rsaquo;';
-	var $uri_segment		= 3;
-	var $full_tag_open		= '';
-	var $full_tag_close		= '';
-	var $first_tag_open		= '';
-	var $first_tag_close	= '&nbsp;';
-	var $last_tag_open		= '&nbsp;';
-	var $last_tag_close		= '';
-	var $first_url			= ''; // Alternative URL for the First Page.
-	var $cur_tag_open		= '&nbsp;<strong>';
-	var $cur_tag_close		= '</strong>';
-	var $next_tag_open		= '&nbsp;';
-	var $next_tag_close		= '&nbsp;';
-	var $prev_tag_open		= '&nbsp;';
-	var $prev_tag_close		= '';
-	var $num_tag_open		= '&nbsp;';
-	var $num_tag_close		= '';
-	var $page_query_string	= FALSE;
-	var $query_string_segment = 'per_page';
-	var $display_pages		= TRUE;
-	var $anchor_class		= '';
+	protected $base_url				= ''; // The page we are linking to
+	protected $prefix				= ''; // A custom prefix added to the path.
+	protected $suffix				= ''; // A custom suffix added to the path.
+	protected $total_rows			= 0; // Total number of items (database results)
+	protected $per_page				= 10; // Max number of items you want shown per page
+	protected $num_links			= 2; // Number of "digit" links to show before/after the currently viewed page
+	protected $cur_page				= 0; // The current page being viewed
+	protected $use_page_numbers		= FALSE; // Use page number for segment instead of offset
+	protected $first_link			= '&lsaquo; First';
+	protected $next_link			= '&gt;';
+	protected $prev_link			= '&lt;';
+	protected $last_link			= 'Last &rsaquo;';
+	protected $uri_segment			= 3;
+	protected $full_tag_open		= '';
+	protected $full_tag_close		= '';
+	protected $first_tag_open		= '';
+	protected $first_tag_close		= '&nbsp;';
+	protected $last_tag_open		= '&nbsp;';
+	protected $last_tag_close		= '';
+	protected $first_url			= ''; // Alternative URL for the First Page.
+	protected $cur_tag_open			= '&nbsp;<strong>';
+	protected $cur_tag_close		= '</strong>';
+	protected $next_tag_open		= '&nbsp;';
+	protected $next_tag_close		= '&nbsp;';
+	protected $prev_tag_open		= '&nbsp;';
+	protected $prev_tag_close		= '';
+	protected $num_tag_open			= '&nbsp;';
+	protected $num_tag_close		= '';
+	protected $page_query_string	= FALSE;
+	protected $query_string_segment = 'per_page';
+	protected $display_pages		= TRUE;
+	protected $anchor_class			= '';
 
 	/**
 	 * Constructor
@@ -80,16 +79,7 @@
 	 */
 	public function __construct($params = array())
 	{
-		if (count($params) > 0)
-		{
-			$this->initialize($params);
-		}
-
-		if ($this->anchor_class != '')
-		{
-			$this->anchor_class = 'class="'.$this->anchor_class.'" ';
-		}
-
+		$this->initialize($params);
 		log_message('debug', "Pagination Class Initialized");
 	}
 
@@ -102,7 +92,7 @@
 	 * @param	array	initialization parameters
 	 * @return	void
 	 */
-	function initialize($params = array())
+	public function initialize($params = array())
 	{
 		if (count($params) > 0)
 		{
@@ -114,6 +104,11 @@
 				}
 			}
 		}
+
+		if ($this->anchor_class != '')
+		{
+			$this->anchor_class = 'class="'.$this->anchor_class.'" ';
+		}
 	}
 
 	// --------------------------------------------------------------------
@@ -124,7 +119,7 @@
 	 * @access	public
 	 * @return	string
 	 */
-	function create_links()
+	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)
@@ -167,7 +162,7 @@
 				$this->cur_page = (int) $this->cur_page;
 			}
 		}
-		
+
 		// Set current page to 1 if using page numbers instead of offset
 		if ($this->use_page_numbers AND $this->cur_page == 0)
 		{
@@ -204,7 +199,7 @@
 		}
 
 		$uri_page_number = $this->cur_page;
-		
+
 		if ( ! $this->use_page_numbers)
 		{
 			$this->cur_page = floor(($this->cur_page/$this->per_page) + 1);
diff --git a/system/libraries/Zip.php b/system/libraries/Zip.php
index 9101eec..52f1bc3 100644
--- a/system/libraries/Zip.php
+++ b/system/libraries/Zip.php
@@ -99,9 +99,9 @@
 	 */
 	function _get_mod_time($dir)
 	{
-		// filemtime() will return false, but it does raise an error.
-		$date = (@filemtime($dir)) ? filemtime($dir) : getdate($this->now);
-
+		// filemtime() may return false, but raises an error for non-existing files
+		$date = (file_exists($dir)) ? filemtime($dir): getdate($this->now);
+		
 		$time['file_mtime'] = ($date['hours'] << 11) + ($date['minutes'] << 5) + $date['seconds'] / 2;
 		$time['file_mdate'] = (($date['year'] - 1980) << 9) + ($date['mon'] << 5) + $date['mday'];
 
diff --git a/user_guide_src/source/changelog.rst b/user_guide_src/source/changelog.rst
index 5c7fd8d..8dfe249 100644
--- a/user_guide_src/source/changelog.rst
+++ b/user_guide_src/source/changelog.rst
@@ -27,6 +27,7 @@
    -  Added support pgp and gpg to mimes.php.
    -  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.
 
 -  Helpers
 
@@ -59,7 +60,12 @@
 -  Fixed a bug (#181) where a mis-spelling was in the form validation
    language file.
 -  Fixed a bug (#159, #163) that mishandled Active Record nested transactions because _trans_depth was not getting incremented.
+-  Fixed a bug (#737, #75) where pagination anchor class was not set properly when using initialize method.
 -  Bug #419 - auto_link() now recognizes URLs that come after a word boundary.
+-  Bug #724 - is_unique in form validation now checks that you are connected to a database.
+-  Bug #647 - _get_mod_time() in Zip library no longer generates stat failed errors
+-  Bug #608 - Fixes an issue with the Image_lib class not clearing properties completely
+-  Fixed bugs (#157 and #174) - the Image_lib clear() function now resets all variables to their default values.
 
 Version 2.1.0
 =============