From 8e70b7935181ff56a340a3388080bf4ac6f3428f Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Thu, 12 Jan 2012 20:19:24 +0200 Subject: CI_Image_lib::image_reproportion() to work if only one of either width or height are set --- system/libraries/Image_lib.php | 195 ++++++++++++++++-------------------- user_guide_src/source/changelog.rst | 1 + 2 files changed, 89 insertions(+), 107 deletions(-) diff --git a/system/libraries/Image_lib.php b/system/libraries/Image_lib.php index a226ae8f8..8430d60df 100644 --- a/system/libraries/Image_lib.php +++ b/system/libraries/Image_lib.php @@ -88,12 +88,6 @@ class CI_Image_lib { protected $wm_use_drop_shadow = FALSE; public $wm_use_truetype = FALSE; - /** - * Constructor - * - * @param string - * @return void - */ public function __construct($props = array()) { if (count($props) > 0) @@ -101,7 +95,7 @@ class CI_Image_lib { $this->initialize($props); } - log_message('debug', "Image Lib Class Initialized"); + log_message('debug', 'Image Lib Class Initialized'); } // -------------------------------------------------------------------- @@ -158,9 +152,7 @@ class CI_Image_lib { */ public function initialize($props = array()) { - /* - * Convert array elements into class variables - */ + // Convert array elements into class variables if (count($props) > 0) { foreach ($props as $key => $val) @@ -199,7 +191,6 @@ class CI_Image_lib { * Is there a source image? * * If not, there's no reason to continue - * */ if ($this->source_image == '') { @@ -213,7 +204,6 @@ class CI_Image_lib { * We use it to determine the image properties (width/height). * Note: We need to figure out how to determine image * properties using ImageMagick and NetPBM - * */ if ( ! function_exists('getimagesize')) { @@ -229,11 +219,10 @@ class CI_Image_lib { * The source image may or may not contain a path. * Either way, we'll try use realpath to generate the * full server path in order to more reliably read it. - * */ - if (function_exists('realpath') AND @realpath($this->source_image) !== FALSE) + if (function_exists('realpath') && @realpath($this->source_image) !== FALSE) { - $full_source_path = str_replace("\\", "/", realpath($this->source_image)); + $full_source_path = str_replace('\\', '/', realpath($this->source_image)); } else { @@ -257,7 +246,6 @@ class CI_Image_lib { * we are making a copy of the source image. If not * it means we are altering the original. We'll * set the destination filename and path accordingly. - * */ if ($this->new_image == '') { @@ -273,9 +261,9 @@ class CI_Image_lib { } else { - if (function_exists('realpath') AND @realpath($this->new_image) !== FALSE) + if (function_exists('realpath') && @realpath($this->new_image) !== FALSE) { - $full_dest_path = str_replace("\\", "/", realpath($this->new_image)); + $full_dest_path = str_replace('\\', '/', realpath($this->new_image)); } else { @@ -283,7 +271,7 @@ class CI_Image_lib { } // Is there a file name? - if ( ! preg_match("#\.(jpg|jpeg|gif|png)$#i", $full_dest_path)) + if ( ! preg_match('#\.(jpg|jpeg|gif|png)$#i', $full_dest_path)) { $this->dest_folder = $full_dest_path.'/'; $this->dest_image = $this->source_image; @@ -305,7 +293,6 @@ class CI_Image_lib { * full server path to the destination image. * We'll also split the destination image name * so we can insert the thumbnail marker if needed. - * */ if ($this->create_thumb === FALSE OR $this->thumb_marker == '') { @@ -325,10 +312,9 @@ class CI_Image_lib { * * When creating thumbs or copies, the target width/height * might not be in correct proportion with the source - * image's width/height. We'll recalculate it here. - * + * image's width/height. We'll recalculate it here. */ - if ($this->maintain_ratio === TRUE && ($this->width != '' AND $this->height != '')) + if ($this->maintain_ratio === TRUE && ($this->width != 0 OR $this->height != 0)) { $this->image_reproportion(); } @@ -339,35 +325,40 @@ class CI_Image_lib { * If the destination width/height was * not submitted we will use the values * from the actual file - * */ if ($this->width == '') + { $this->width = $this->orig_width; + } if ($this->height == '') + { $this->height = $this->orig_height; + } // Set the quality - $this->quality = trim(str_replace("%", "", $this->quality)); + $this->quality = trim(str_replace('%', '', $this->quality)); - if ($this->quality == '' OR $this->quality == 0 OR ! is_numeric($this->quality)) + if ($this->quality == '' OR $this->quality == 0 OR ! preg_match('/^[0-9]+$/', $this->quality)) + { $this->quality = 90; + } // Set the x/y coordinates - $this->x_axis = ($this->x_axis == '' OR ! is_numeric($this->x_axis)) ? 0 : $this->x_axis; - $this->y_axis = ($this->y_axis == '' OR ! is_numeric($this->y_axis)) ? 0 : $this->y_axis; + $this->x_axis = ($this->x_axis == '' OR ! preg_match('/^[0-9]+$/', $this->x_axis)) ? 0 : $this->x_axis; + $this->y_axis = ($this->y_axis == '' OR ! preg_match('/^[0-9]+$/', $this->y_axis)) ? 0 : $this->y_axis; // Watermark-related Stuff... if ($this->wm_overlay_path != '') { - $this->wm_overlay_path = str_replace("\\", "/", realpath($this->wm_overlay_path)); + $this->wm_overlay_path = str_replace('\\', '/', realpath($this->wm_overlay_path)); } if ($this->wm_shadow_color != '') { $this->wm_use_drop_shadow = TRUE; } - elseif ($this->wm_use_drop_shadow == TRUE AND $this->wm_shadow_color == '') + elseif ($this->wm_use_drop_shadow == TRUE && $this->wm_shadow_color == '') { $this->wm_use_drop_shadow = FALSE; } @@ -445,7 +436,6 @@ class CI_Image_lib { $this->height = $this->orig_height; } - // Choose resizing function if ($this->image_library == 'imagemagick' OR $this->image_library == 'netpbm') { @@ -479,9 +469,9 @@ class CI_Image_lib { // If the target width/height match the source, AND if the new file name is not equal to the old file name // we'll simply make a copy of the original with the new name... assuming dynamic rendering is off. - if ($this->dynamic_output === FALSE AND $this->orig_width == $this->width AND $this->orig_height == $this->height) + if ($this->dynamic_output === FALSE && $this->orig_width == $this->width && $this->orig_height == $this->height) { - if ($this->source_image != $this->new_image AND @copy($this->full_src_path, $this->full_dst_path)) + if ($this->source_image != $this->new_image && @copy($this->full_src_path, $this->full_dst_path)) { @chmod($this->full_dst_path, FILE_WRITE_MODE); } @@ -523,7 +513,7 @@ class CI_Image_lib { // below should that ever prove inaccurate. // // if ($this->image_library == 'gd2' AND function_exists('imagecreatetruecolor') AND $v2_override == FALSE) - if ($this->image_library == 'gd2' AND function_exists('imagecreatetruecolor')) + if ($this->image_library === 'gd2' && function_exists('imagecreatetruecolor')) { $create = 'imagecreatetruecolor'; $copy = 'imagecopyresampled'; @@ -587,7 +577,7 @@ class CI_Image_lib { return FALSE; } - if ( ! preg_match("/convert$/i", $this->library_path)) + if ( ! preg_match('/convert$/i', $this->library_path)) { $this->library_path = rtrim($this->library_path, '/').'/convert'; } @@ -597,7 +587,7 @@ class CI_Image_lib { if ($action == 'crop') { - $cmd .= " -crop ".$this->width."x".$this->height."+".$this->x_axis."+".$this->y_axis." \"$this->full_src_path\" \"$this->full_dst_path\" 2>&1"; + $cmd .= ' -crop '.$this->width.'x'.$this->height.'+'.$this->x_axis.'+'.$this->y_axis.' "'.$this->full_src_path.'" "'.$this->full_dst_path .'" 2>&1'; } elseif ($action == 'rotate') { @@ -611,18 +601,17 @@ class CI_Image_lib { break; } - $cmd .= " ".$angle." \"$this->full_src_path\" \"$this->full_dst_path\" 2>&1"; + $cmd .= ' '.$angle.' "'.$this->full_src_path.'" "'.$this->full_dst_path.'" 2>&1'; } - else // Resize + else // Resize { - $cmd .= " -resize ".$this->width."x".$this->height." \"$this->full_src_path\" \"$this->full_dst_path\" 2>&1"; + $cmd .= ' -resize '.$this->width.'x'.$this->height.'" "'.$this->full_src_path.'" "'.$this->full_dst_path.'" 2>&1'; } $retval = 1; - @exec($cmd, $output, $retval); - // Did it work? + // Did it work? if ($retval > 0) { $this->set_error('imglib_image_process_failed'); @@ -700,10 +689,9 @@ class CI_Image_lib { $cmd = $this->library_path.$cmd_in.' '.$this->full_src_path.' | '.$cmd_inner.' | '.$cmd_out.' > '.$this->dest_folder.'netpbm.tmp'; $retval = 1; - @exec($cmd, $output, $retval); - // Did it work? + // Did it work? if ($retval > 0) { $this->set_error('imglib_image_process_failed'); @@ -742,29 +730,24 @@ class CI_Image_lib { $white = imagecolorallocate($src_img, 255, 255, 255); - // Rotate it! + // Rotate it! $dst_img = imagerotate($src_img, $this->rotation_angle, $white); - // Save the Image + // Show the image if ($this->dynamic_output == TRUE) { $this->image_display_gd($dst_img); } - else + elseif ( ! $this->image_save_gd($dst_img)) // ... or save it { - // Or save it - if ( ! $this->image_save_gd($dst_img)) - { - return FALSE; - } + return FALSE; } - // Kill the file handles + // Kill the file handles imagedestroy($dst_img); imagedestroy($src_img); // Set the file to 777 - @chmod($this->full_dst_path, FILE_WRITE_MODE); return TRUE; @@ -824,21 +807,17 @@ class CI_Image_lib { } } - // Show the image + // Show the image if ($this->dynamic_output == TRUE) { $this->image_display_gd($src_img); } - else + elseif ( ! $this->image_save_gd($src_img)) // ... or save it { - // Or save it - if ( ! $this->image_save_gd($src_img)) - { - return FALSE; - } + return FALSE; } - // Kill the file handles + // Kill the file handles imagedestroy($src_img); // Set the file to 777 @@ -860,14 +839,7 @@ class CI_Image_lib { */ public function watermark() { - if ($this->wm_type == 'overlay') - { - return $this->overlay_watermark(); - } - else - { - return $this->text_watermark(); - } + return ($this->wm_type == 'overlay') ? $this->overlay_watermark() : $this->text_watermark(); } // -------------------------------------------------------------------- @@ -885,28 +857,28 @@ class CI_Image_lib { return FALSE; } - // Fetch source image properties + // Fetch source image properties $this->get_image_properties(); - // Fetch watermark image properties + // Fetch watermark image properties $props = $this->get_image_properties($this->wm_overlay_path, TRUE); $wm_img_type = $props['image_type']; $wm_width = $props['width']; $wm_height = $props['height']; - // Create two image resources + // Create two image resources $wm_img = $this->image_create_gd($this->wm_overlay_path, $wm_img_type); $src_img = $this->image_create_gd($this->full_src_path); // Reverse the offset if necessary // When the image is positioned at the bottom // we don't want the vertical offset to push it - // further down. We want the reverse, so we'll - // invert the offset. Same with the horizontal + // further down. We want the reverse, so we'll + // invert the offset. Same with the horizontal // offset when the image is at the right - $this->wm_vrt_alignment = strtoupper(substr($this->wm_vrt_alignment, 0, 1)); - $this->wm_hor_alignment = strtoupper(substr($this->wm_hor_alignment, 0, 1)); + $this->wm_vrt_alignment = strtoupper($this->wm_vrt_alignment[0]); + $this->wm_hor_alignment = strtoupper($this->wm_hor_alignment[0]); if ($this->wm_vrt_alignment == 'B') $this->wm_vrt_offset = $this->wm_vrt_offset * -1; @@ -914,11 +886,11 @@ class CI_Image_lib { if ($this->wm_hor_alignment == 'R') $this->wm_hor_offset = $this->wm_hor_offset * -1; - // Set the base x and y axis values + // Set the base x and y axis values $x_axis = $this->wm_hor_offset + $this->wm_padding; $y_axis = $this->wm_vrt_offset + $this->wm_padding; - // Set the vertical position + // Set the vertical position switch ($this->wm_vrt_alignment) { case 'T': @@ -929,7 +901,7 @@ class CI_Image_lib { break; } - // Set the horizontal position + // Set the horizontal position switch ($this->wm_hor_alignment) { case 'L': @@ -941,7 +913,7 @@ class CI_Image_lib { } // Build the finalized image - if ($wm_img_type == 3 AND function_exists('imagealphablending')) + if ($wm_img_type == 3 && function_exists('imagealphablending')) { @imagealphablending($src_img, TRUE); } @@ -993,20 +965,20 @@ class CI_Image_lib { return FALSE; } - if ($this->wm_use_truetype == TRUE AND ! file_exists($this->wm_font_path)) + if ($this->wm_use_truetype == TRUE && ! file_exists($this->wm_font_path)) { $this->set_error('imglib_missing_font'); return FALSE; } - // Fetch source image properties + // Fetch source image properties $this->get_image_properties(); // Reverse the vertical offset // When the image is positioned at the bottom // we don't want the vertical offset to push it // further down. We want the reverse, so we'll - // invert the offset. Note: The horizontal + // invert the offset. Note: The horizontal // offset flips itself automatically if ($this->wm_vrt_alignment == 'B') @@ -1093,7 +1065,7 @@ class CI_Image_lib { $drp_color = str_split(substr($this->wm_shadow_color, 1, 6), 2); $drp_color = imagecolorclosest($src_img, hexdec($drp_color[0]), hexdec($drp_color[1]), hexdec($drp_color[2])); - // Add the text to the source image + // Add the text to the source image if ($this->wm_use_truetype) { imagettftext($src_img, $this->wm_font_size, 0, $x_shad, $y_shad, $drp_color, $this->wm_font_path, $this->wm_text); @@ -1106,7 +1078,7 @@ class CI_Image_lib { } } - // Output the final image + // Output the final image if ($this->dynamic_output == TRUE) { $this->image_display_gd($src_img); @@ -1284,33 +1256,43 @@ class CI_Image_lib { */ public function image_reproportion() { - if ( ! is_numeric($this->width) OR ! is_numeric($this->height) OR $this->width == 0 OR $this->height == 0) - return; - - if ( ! is_numeric($this->orig_width) OR ! is_numeric($this->orig_height) OR $this->orig_width == 0 OR $this->orig_height == 0) - return; - - $new_width = ceil($this->orig_width*$this->height/$this->orig_height); - $new_height = ceil($this->width*$this->orig_height/$this->orig_width); - - $ratio = (($this->orig_height/$this->orig_width) - ($this->height/$this->width)); - - if ($this->master_dim != 'width' AND $this->master_dim != 'height') + if (($this->width == 0 && $this->height == 0) OR $this->orig_width == 0 OR $this->orig_height == 0 + OR ( ! preg_match('/^[0-9]+$/', $this->width) && ! preg_match('/^[0-9]+$/', $this->height)) + OR ! preg_match('/^[0-9]+$/', $this->orig_width) OR ! preg_match('/^[0-9]+$/', $this->orig_height)) { - $this->master_dim = ($ratio < 0) ? 'width' : 'height'; + return; } - if (($this->width != $new_width) AND ($this->height != $new_height)) + // Sanitize so we don't call preg_match() anymore + $this->width = (int) $this->width; + $this->height = (int) $this->height; + + if ($this->master_dim !== 'width' && $this->master_dim !== 'height') { - if ($this->master_dim == 'height') + if ($this->width > 0 && $this->height > 0) { - $this->width = $new_width; + $this->master_dim = ((($this->orig_height/$this->orig_width) - ($this->height/$this->width)) < 0) + ? 'width' : 'height'; } else { - $this->height = $new_height; + $this->master_dim = ($this->height === 0) ? 'width' : 'height'; } } + elseif (($this->master_dim === 'width' && $this->width === 0) + OR ($this->master_dim === 'height' && $this->height === 0)) + { + return; + } + + if ($this->master_dim === 'width') + { + $this->height = (int) ceil($this->width*$this->orig_height/$this->orig_width); + } + else + { + $this->width = (int) ceil($this->orig_width*$this->height/$this->orig_height); + } } // -------------------------------------------------------------------- @@ -1329,7 +1311,9 @@ class CI_Image_lib { // find a way to determine this using IM or NetPBM if ($path == '') + { $path = $this->full_src_path; + } if ( ! file_exists($path)) { @@ -1449,7 +1433,7 @@ class CI_Image_lib { /* As it is stated in the PHP manual, dl() is not always available * and even if so - it could generate an E_WARNING message on failure */ - return (function_exists('dl') AND @dl('gd.so')); + return (function_exists('dl') && @dl('gd.so')); } return TRUE; @@ -1467,9 +1451,7 @@ class CI_Image_lib { if (function_exists('gd_info')) { $gd_version = @gd_info(); - $gd_version = preg_replace("/\D/", "", $gd_version['GD Version']); - - return $gd_version; + return preg_replace('/\D/', '', $gd_version['GD Version']); } return FALSE; @@ -1520,7 +1502,6 @@ class CI_Image_lib { } } -// END Image_lib Class /* End of file Image_lib.php */ /* Location: ./system/libraries/Image_lib.php */ diff --git a/user_guide_src/source/changelog.rst b/user_guide_src/source/changelog.rst index 48011f208..c6d5e30f6 100644 --- a/user_guide_src/source/changelog.rst +++ b/user_guide_src/source/changelog.rst @@ -63,6 +63,7 @@ Release Date: Not Released - Added support for 3-length hex color values for wm_font_color and wm_shadow_color properties, as well as validation for them. - Class properties wm_font_color, wm_shadow_color and wm_use_drop_shadow are now protected, to avoid breaking the text_watermark() method if they are set manually after initialization. + - If property maintain_ratio is set to TRUE, image_reproportion() now doesn't need both width and height to be specified. - Minor speed optimizations and method & property visibility declarations in the Calendar Library. - Removed SHA1 function in the :doc:`Encryption Library `. - Added $config['csrf_regeneration'] to the CSRF protection in the :doc:`Security library `, which makes token regeneration optional. -- cgit v1.2.3-24-g4f1b From e46363083ad18c93c73a200c9a97934608bb5bab Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Thu, 12 Jan 2012 20:23:27 +0200 Subject: Remove a quote --- system/libraries/Image_lib.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/system/libraries/Image_lib.php b/system/libraries/Image_lib.php index 8430d60df..fd3cd0edb 100644 --- a/system/libraries/Image_lib.php +++ b/system/libraries/Image_lib.php @@ -605,7 +605,7 @@ class CI_Image_lib { } else // Resize { - $cmd .= ' -resize '.$this->width.'x'.$this->height.'" "'.$this->full_src_path.'" "'.$this->full_dst_path.'" 2>&1'; + $cmd .= ' -resize '.$this->width.'x'.$this->height.' "'.$this->full_src_path.'" "'.$this->full_dst_path.'" 2>&1'; } $retval = 1; -- cgit v1.2.3-24-g4f1b From c357f5ecb0794fc59802ab7a9779453ee2b003c7 Mon Sep 17 00:00:00 2001 From: Wilbur Suero Date: Tue, 17 Jan 2012 00:17:35 -0400 Subject: Fixed error in inflector_helper.php in the singular function. The function was excepting $singluar_rules and got $singular_values. --- system/helpers/inflector_helper.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/system/helpers/inflector_helper.php b/system/helpers/inflector_helper.php index 0bd1e112f..2069a1927 100644 --- a/system/helpers/inflector_helper.php +++ b/system/helpers/inflector_helper.php @@ -85,7 +85,7 @@ if ( ! function_exists('singular')) '/([^u])s$/' => '\1', ); - return preg_replace(array_keys($singular_values), $singular_values, $result); + return preg_replace(array_keys($singular_rules), $singular_rules, $result); } } -- cgit v1.2.3-24-g4f1b From 2c8baeb0ecdd3f5db299dc8d66edc2f157b64f23 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Thu, 19 Jan 2012 15:45:28 +0200 Subject: Some more cleaning --- system/libraries/Image_lib.php | 250 +++++++++++++++++------------------------ 1 file changed, 104 insertions(+), 146 deletions(-) diff --git a/system/libraries/Image_lib.php b/system/libraries/Image_lib.php index fd3cd0edb..065f479e8 100644 --- a/system/libraries/Image_lib.php +++ b/system/libraries/Image_lib.php @@ -9,7 +9,7 @@ * 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 + * 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 @@ -25,8 +25,6 @@ * @filesource */ -// ------------------------------------------------------------------------ - /** * Image Manipulation class * @@ -187,22 +185,17 @@ class CI_Image_lib { } } - /* - * Is there a source image? - * - * If not, there's no reason to continue - */ + // Is there a source image? If not, there's no reason to continue if ($this->source_image == '') { $this->set_error('imglib_source_image_required'); return FALSE; } - /* - * Is getimagesize() Available? + /* Is getimagesize() available? * * We use it to determine the image properties (width/height). - * Note: We need to figure out how to determine image + * Note: We need to figure out how to determine image * properties using ImageMagick and NetPBM */ if ( ! function_exists('getimagesize')) @@ -213,8 +206,7 @@ class CI_Image_lib { $this->image_library = strtolower($this->image_library); - /* - * Set the full server path + /* Set the full server path * * The source image may or may not contain a path. * Either way, we'll try use realpath to generate the @@ -244,7 +236,7 @@ class CI_Image_lib { * * If the user has set a "new_image" name it means * we are making a copy of the source image. If not - * it means we are altering the original. We'll + * it means we are altering the original. We'll * set the destination filename and path accordingly. */ if ($this->new_image == '') @@ -252,41 +244,37 @@ class CI_Image_lib { $this->dest_image = $this->source_image; $this->dest_folder = $this->source_folder; } + elseif (strpos($this->new_image, '/') === FALSE) + { + $this->dest_folder = $this->source_folder; + $this->dest_image = $this->new_image; + } else { - if (strpos($this->new_image, '/') === FALSE) + if (function_exists('realpath') && @realpath($this->new_image) !== FALSE) { - $this->dest_folder = $this->source_folder; - $this->dest_image = $this->new_image; + $full_dest_path = str_replace('\\', '/', realpath($this->new_image)); } else { - if (function_exists('realpath') && @realpath($this->new_image) !== FALSE) - { - $full_dest_path = str_replace('\\', '/', realpath($this->new_image)); - } - else - { - $full_dest_path = $this->new_image; - } + $full_dest_path = $this->new_image; + } - // Is there a file name? - if ( ! preg_match('#\.(jpg|jpeg|gif|png)$#i', $full_dest_path)) - { - $this->dest_folder = $full_dest_path.'/'; - $this->dest_image = $this->source_image; - } - else - { - $x = explode('/', $full_dest_path); - $this->dest_image = end($x); - $this->dest_folder = str_replace($this->dest_image, '', $full_dest_path); - } + // Is there a file name? + if ( ! preg_match('#\.(jpg|jpeg|gif|png)$#i', $full_dest_path)) + { + $this->dest_folder = $full_dest_path.'/'; + $this->dest_image = $this->source_image; + } + else + { + $x = explode('/', $full_dest_path); + $this->dest_image = end($x); + $this->dest_folder = str_replace($this->dest_image, '', $full_dest_path); } } - /* - * Compile the finalized filenames/paths + /* Compile the finalized filenames/paths * * We'll create two master strings containing the * full server path to the source image and the @@ -299,7 +287,7 @@ class CI_Image_lib { $this->thumb_marker = ''; } - $xp = $this->explode_name($this->dest_image); + $xp = $this->explode_name($this->dest_image); $filename = $xp['name']; $file_ext = $xp['ext']; @@ -307,8 +295,7 @@ class CI_Image_lib { $this->full_src_path = $this->source_folder.$this->source_image; $this->full_dst_path = $this->dest_folder.$filename.$this->thumb_marker.$file_ext; - /* - * Should we maintain image proportions? + /* Should we maintain image proportions? * * When creating thumbs or copies, the target width/height * might not be in correct proportion with the source @@ -319,12 +306,10 @@ class CI_Image_lib { $this->image_reproportion(); } - /* - * Was a width and height specified? + /* Was a width and height specified? * - * If the destination width/height was - * not submitted we will use the values - * from the actual file + * If the destination width/height was not submitted we + * will use the values from the actual file */ if ($this->width == '') { @@ -437,20 +422,15 @@ class CI_Image_lib { } // Choose resizing function - if ($this->image_library == 'imagemagick' OR $this->image_library == 'netpbm') + if ($this->image_library === 'imagemagick' OR $this->image_library === 'netpbm') { $protocol = 'image_process_'.$this->image_library; return $this->$protocol('rotate'); } - if ($this->rotation_angle == 'hor' OR $this->rotation_angle == 'vrt') - { - return $this->image_mirror_gd(); - } - else - { - return $this->image_rotate_gd(); - } + return ($this->rotation_angle === 'hor' OR $this->rotation_angle === 'vrt') + ? $this->image_mirror_gd() + : $this->image_rotate_gd(); } // -------------------------------------------------------------------- @@ -482,7 +462,7 @@ class CI_Image_lib { // Let's set up our values based on the action if ($action == 'crop') { - // Reassign the source width/height if cropping + // Reassign the source width/height if cropping $this->orig_width = $this->width; $this->orig_height = $this->height; @@ -506,13 +486,14 @@ class CI_Image_lib { return FALSE; } - // Create The Image - // - // old conditional which users report cause problems with shared GD libs who report themselves as "2.0 or greater" - // it appears that this is no longer the issue that it was in 2004, so we've removed it, retaining it in the comment - // below should that ever prove inaccurate. - // - // if ($this->image_library == 'gd2' AND function_exists('imagecreatetruecolor') AND $v2_override == FALSE) + /* Create the image + * + * Old conditional which users report cause problems with shared GD libs who report themselves as "2.0 or greater" + * it appears that this is no longer the issue that it was in 2004, so we've removed it, retaining it in the comment + * below should that ever prove inaccurate. + * + * if ($this->image_library === 'gd2' && function_exists('imagecreatetruecolor') && $v2_override == FALSE) + */ if ($this->image_library === 'gd2' && function_exists('imagecreatetruecolor')) { $create = 'imagecreatetruecolor'; @@ -534,21 +515,17 @@ class CI_Image_lib { $copy($dst_img, $src_img, 0, 0, $this->x_axis, $this->y_axis, $this->width, $this->height, $this->orig_width, $this->orig_height); - // Show the image + // Show the image if ($this->dynamic_output == TRUE) { $this->image_display_gd($dst_img); } - else + elseif ( ! $this->image_save_gd($dst_img)) // Or save it { - // Or save it - if ( ! $this->image_save_gd($dst_img)) - { - return FALSE; - } + return FALSE; } - // Kill the file handles + // Kill the file handles imagedestroy($dst_img); imagedestroy($src_img); @@ -583,7 +560,7 @@ class CI_Image_lib { } // Execute the command - $cmd = $this->library_path." -quality ".$this->quality; + $cmd = $this->library_path.' -quality '.$this->quality; if ($action == 'crop') { @@ -591,15 +568,8 @@ class CI_Image_lib { } elseif ($action == 'rotate') { - switch ($this->rotation_angle) - { - case 'hor' : $angle = '-flop'; - break; - case 'vrt' : $angle = '-flip'; - break; - default : $angle = '-rotate '.$this->rotation_angle; - break; - } + $angle = ($this->rotation_angle === 'hor' OR $this->rotation_angle === 'vrt') + ? '-flop' : '-rotate '.$this->rotation_angle; $cmd .= ' '.$angle.' "'.$this->full_src_path.'" "'.$this->full_dst_path.'" 2>&1'; } @@ -642,7 +612,7 @@ class CI_Image_lib { return FALSE; } - // Build the resizing command + // Build the resizing command switch ($this->image_type) { case 1 : @@ -702,7 +672,7 @@ class CI_Image_lib { // If you try manipulating the original it fails so // we have to rename the temp file. copy ($this->dest_folder.'netpbm.tmp', $this->full_dst_path); - unlink ($this->dest_folder.'netpbm.tmp'); + unlink($this->dest_folder.'netpbm.tmp'); @chmod($this->full_dst_path, FILE_WRITE_MODE); return TRUE; @@ -717,7 +687,7 @@ class CI_Image_lib { */ public function image_rotate_gd() { - // Create the image handle + // Create the image handle if ( ! ($src_img = $this->image_create_gd())) { return FALSE; @@ -772,7 +742,7 @@ class CI_Image_lib { $width = $this->orig_width; $height = $this->orig_height; - if ($this->rotation_angle == 'hor') + if ($this->rotation_angle === 'hor') { for ($i = 0; $i < $height; $i++, $left = 0, $right = $width-1) { @@ -839,7 +809,7 @@ class CI_Image_lib { */ public function watermark() { - return ($this->wm_type == 'overlay') ? $this->overlay_watermark() : $this->text_watermark(); + return ($this->wm_type === 'overlay') ? $this->overlay_watermark() : $this->text_watermark(); } // -------------------------------------------------------------------- @@ -861,10 +831,10 @@ class CI_Image_lib { $this->get_image_properties(); // Fetch watermark image properties - $props = $this->get_image_properties($this->wm_overlay_path, TRUE); + $props = $this->get_image_properties($this->wm_overlay_path, TRUE); $wm_img_type = $props['image_type']; - $wm_width = $props['width']; - $wm_height = $props['height']; + $wm_width = $props['width']; + $wm_height = $props['height']; // Create two image resources $wm_img = $this->image_create_gd($this->wm_overlay_path, $wm_img_type); @@ -891,25 +861,23 @@ class CI_Image_lib { $y_axis = $this->wm_vrt_offset + $this->wm_padding; // Set the vertical position - switch ($this->wm_vrt_alignment) + if ($this->wm_vrt_alignment === 'M') { - case 'T': - break; - case 'M': $y_axis += ($this->orig_height / 2) - ($wm_height / 2); - break; - case 'B': $y_axis += $this->orig_height - $wm_height; - break; + $y_axis += ($this->orig_height / 2) - ($wm_height / 2); + } + elseif ($this->wm_vrt_alignment === 'B') + { + $y_axis += $this->orig_height - $wm_height; } // Set the horizontal position - switch ($this->wm_hor_alignment) + if ($this->wm_hor_alignment === 'C') { - case 'L': - break; - case 'C': $x_axis += ($this->orig_width / 2) - ($wm_width / 2); - break; - case 'R': $x_axis += $this->orig_width - $wm_width; - break; + $x_axis += ($this->orig_width / 2) - ($wm_width / 2); + } + elseif ($this->wm_hor_alignment === 'R') + { + $x_axis += $this->orig_width - $wm_width; } // Build the finalized image @@ -935,12 +903,12 @@ class CI_Image_lib { imagecopymerge($src_img, $wm_img, $x_axis, $y_axis, 0, 0, $wm_width, $wm_height, $this->wm_opacity); } - // Output the image + // Output the image if ($this->dynamic_output == TRUE) { $this->image_display_gd($src_img); } - elseif ( ! $this->image_save_gd($src_img)) + elseif ( ! $this->image_save_gd($src_img)) // ... or save it { return FALSE; } @@ -977,7 +945,7 @@ class CI_Image_lib { // Reverse the vertical offset // When the image is positioned at the bottom // we don't want the vertical offset to push it - // further down. We want the reverse, so we'll + // further down. We want the reverse, so we'll // invert the offset. Note: The horizontal // offset flips itself automatically @@ -1011,49 +979,39 @@ class CI_Image_lib { $x_axis = $this->wm_hor_offset + $this->wm_padding; $y_axis = $this->wm_vrt_offset + $this->wm_padding; - // Set verticle alignment if ($this->wm_use_drop_shadow == FALSE) $this->wm_shadow_distance = 0; $this->wm_vrt_alignment = strtoupper(substr($this->wm_vrt_alignment, 0, 1)); $this->wm_hor_alignment = strtoupper(substr($this->wm_hor_alignment, 0, 1)); - switch ($this->wm_vrt_alignment) + // Set verticle alignment + if ($this->wm_vrt_alignment === 'M') { - case 'T': - break; - case 'M': $y_axis += ($this->orig_height/2)+($fontheight/2); - break; - case 'B': $y_axis += ($this->orig_height - $fontheight - $this->wm_shadow_distance - ($fontheight/2)); - break; + $y_axis += ($this->orig_height / 2) + ($fontheight / 2); + } + elseif ($this->wm_vrt_alignment === 'B') + { + $y_axis += $this->orig_height - $fontheight - $this->wm_shadow_distance - ($fontheight / 2); } $x_shad = $x_axis + $this->wm_shadow_distance; $y_shad = $y_axis + $this->wm_shadow_distance; - // Set horizontal alignment - switch ($this->wm_hor_alignment) - { - case 'L': - break; - case 'R': - if ($this->wm_use_drop_shadow) - { - $x_shad += ($this->orig_width - $fontwidth*strlen($this->wm_text)); - $x_axis += ($this->orig_width - $fontwidth*strlen($this->wm_text)); - } - break; - case 'C': - if ($this->wm_use_drop_shadow) - { - $x_shad += floor(($this->orig_width - $fontwidth*strlen($this->wm_text))/2); - $x_axis += floor(($this->orig_width - $fontwidth*strlen($this->wm_text))/2); - } - break; - } - if ($this->wm_use_drop_shadow) { + // Set horizontal alignment + if ($this->wm_hor_alignment === 'R') + { + $x_shad += $this->orig_width - ($fontwidth * strlen($this->wm_text)); + $x_axis += $this->orig_width - ($fontwidth * strlen($this->wm_text)); + } + elseif ($this->wm_hor_alignment === 'C') + { + $x_shad += floor(($this->orig_width - ($fontwidth * strlen($this->wm_text))) / 2); + $x_axis += floor(($this->orig_width - ($fontwidth * strlen($this->wm_text))) / 2); + } + /* Set RGB values for text and shadow * * First character is #, so we don't really need it. @@ -1222,8 +1180,8 @@ class CI_Image_lib { */ public function image_display_gd($resource) { - header("Content-Disposition: filename={$this->source_image};"); - header("Content-Type: {$this->mime_type}"); + header('Content-Disposition: filename='.$this->source_image.';'); + header('Content-Type: '.$this->mime_type); header('Content-Transfer-Encoding: binary'); header('Last-Modified: '.gmdate('D, d M Y H:i:s', time()).' GMT'); @@ -1351,15 +1309,15 @@ class CI_Image_lib { * Size calculator * * This function takes a known width x height and - * recalculates it to a new size. Only one + * recalculates it to a new size. Only one * new variable needs to be known * * $props = array( - * 'width' => $width, - * 'height' => $height, - * 'new_width' => 40, - * 'new_height' => '' - * ); + * 'width' => $width, + * 'height' => $height, + * 'new_width' => 40, + * 'new_height' => '' + * ); * * @param array * @return array @@ -1403,7 +1361,7 @@ class CI_Image_lib { * * This is a helper function that extracts the extension * from the source_image. This function lets us deal with - * source_images with multiple periods, like: my.cool.jpg + * source_images with multiple periods, like: my.cool.jpg * It returns an associative array with two elements: * $array['ext'] = '.jpg'; * $array['name'] = 'my.cool'; @@ -1498,7 +1456,7 @@ class CI_Image_lib { */ public function display_errors($open = '

', $close = '

') { - return (count($this->error_msg) > 0) ? $open . implode($close . $open, $this->error_msg) . $close : ''; + return (count($this->error_msg) > 0) ? $open.implode($close.$open, $this->error_msg).$close : ''; } } -- cgit v1.2.3-24-g4f1b From a3d19c4ac63c4af1c2b823b0962e6be79e89d186 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Tue, 24 Jan 2012 15:29:29 +0200 Subject: Revert a space in the license agreement :) --- system/libraries/Image_lib.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/system/libraries/Image_lib.php b/system/libraries/Image_lib.php index 065f479e8..5ea830fb1 100644 --- a/system/libraries/Image_lib.php +++ b/system/libraries/Image_lib.php @@ -9,7 +9,7 @@ * 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 + * 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 -- cgit v1.2.3-24-g4f1b From 1c175c8d9697d6e8163770c45643f97e557149e6 Mon Sep 17 00:00:00 2001 From: Timothy Warren Date: Fri, 10 Feb 2012 08:37:45 -0500 Subject: Fixed old-style pdo connection string --- system/database/drivers/pdo/pdo_driver.php | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/system/database/drivers/pdo/pdo_driver.php b/system/database/drivers/pdo/pdo_driver.php index fc378daeb..5e5c01ef9 100644 --- a/system/database/drivers/pdo/pdo_driver.php +++ b/system/database/drivers/pdo/pdo_driver.php @@ -117,7 +117,11 @@ class CI_DB_pdo_driver extends CI_DB { // $db['hostname'] = 'pdodriver:host(/Server(/DSN))=hostname(/DSN);'; // We need to get the prefix (pdodriver used by PDO). $this->dsn = $this->hostname; - $this->pdodriver = substr($this->hostname, 0, strpos($this->hostname, ':')); + $split_dsn = explode(":", $this->hostname); + $this->pdodriver = $split_dsn[0]; + + // End this part of the dsn with a semicolon + $this->dsn .= rtrim(';', $this->dsn) . ';'; } else { -- cgit v1.2.3-24-g4f1b From 7d7b304bd98b310957d5077048899ea6e908583a Mon Sep 17 00:00:00 2001 From: Timothy Warren Date: Fri, 10 Feb 2012 09:11:59 -0500 Subject: Changed double quotes to single --- system/database/drivers/pdo/pdo_driver.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/system/database/drivers/pdo/pdo_driver.php b/system/database/drivers/pdo/pdo_driver.php index 5e5c01ef9..e84c1aaaf 100644 --- a/system/database/drivers/pdo/pdo_driver.php +++ b/system/database/drivers/pdo/pdo_driver.php @@ -117,7 +117,7 @@ class CI_DB_pdo_driver extends CI_DB { // $db['hostname'] = 'pdodriver:host(/Server(/DSN))=hostname(/DSN);'; // We need to get the prefix (pdodriver used by PDO). $this->dsn = $this->hostname; - $split_dsn = explode(":", $this->hostname); + $split_dsn = explode(':', $this->hostname); $this->pdodriver = $split_dsn[0]; // End this part of the dsn with a semicolon -- cgit v1.2.3-24-g4f1b From 9c2947a339f24e13aaf85f115bcea9f27fa10a83 Mon Sep 17 00:00:00 2001 From: Taufan Aditya Date: Mon, 13 Feb 2012 04:04:56 +0700 Subject: Fixed rtrim issue in hostname fragment, for backward compability --- system/database/drivers/pdo/pdo_driver.php | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/system/database/drivers/pdo/pdo_driver.php b/system/database/drivers/pdo/pdo_driver.php index e84c1aaaf..2138ed665 100644 --- a/system/database/drivers/pdo/pdo_driver.php +++ b/system/database/drivers/pdo/pdo_driver.php @@ -117,11 +117,7 @@ class CI_DB_pdo_driver extends CI_DB { // $db['hostname'] = 'pdodriver:host(/Server(/DSN))=hostname(/DSN);'; // We need to get the prefix (pdodriver used by PDO). $this->dsn = $this->hostname; - $split_dsn = explode(':', $this->hostname); - $this->pdodriver = $split_dsn[0]; - - // End this part of the dsn with a semicolon - $this->dsn .= rtrim(';', $this->dsn) . ';'; + $this->pdodriver = current(explode(':', $this->hostname)); } else { @@ -179,6 +175,8 @@ class CI_DB_pdo_driver extends CI_DB { // Add charset to the DSN, if needed if ( ! empty($this->char_set) && in_array($this->pdodriver, array('4D', 'mysql', 'sybase', 'mssql', 'dblib', 'oci'))) { + // End dsn with a semicolon for extra backward compability + $this->dsn .= rtrim($this->dsn, ';').';'; $this->dsn .= 'charset='.$this->char_set.';'; } } -- cgit v1.2.3-24-g4f1b From 6b58e5611dc7668da86a5a71b11256d342804301 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Mon, 13 Feb 2012 01:46:56 +0200 Subject: Fix a changelog entry --- user_guide_src/source/changelog.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/user_guide_src/source/changelog.rst b/user_guide_src/source/changelog.rst index 98bb43f7d..faea35872 100644 --- a/user_guide_src/source/changelog.rst +++ b/user_guide_src/source/changelog.rst @@ -57,7 +57,7 @@ Release Date: Not Released - Added max_filename_increment config setting for Upload library. - 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 `. - - Added custom filename to Email::attach() as $this->email->attach($filename, $disposition, $newname) + - 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" -- cgit v1.2.3-24-g4f1b From 5dcdbc30649d8f8320953f3eb728a3eb5a7f7765 Mon Sep 17 00:00:00 2001 From: Taufan Aditya Date: Mon, 13 Feb 2012 21:15:56 +0700 Subject: Semicolon automatically added if not exists after hostname, if only database was not empty --- system/database/drivers/pdo/pdo_driver.php | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/system/database/drivers/pdo/pdo_driver.php b/system/database/drivers/pdo/pdo_driver.php index 2138ed665..5991586c7 100644 --- a/system/database/drivers/pdo/pdo_driver.php +++ b/system/database/drivers/pdo/pdo_driver.php @@ -118,6 +118,13 @@ class CI_DB_pdo_driver extends CI_DB { // We need to get the prefix (pdodriver used by PDO). $this->dsn = $this->hostname; $this->pdodriver = current(explode(':', $this->hostname)); + + // End dsn with a semicolon for extra backward compability + // if database property was not empty. + if ( ! empty($this->database)) + { + $this->dsn .= rtrim($this->dsn, ';').';'; + } } else { @@ -175,8 +182,6 @@ class CI_DB_pdo_driver extends CI_DB { // Add charset to the DSN, if needed if ( ! empty($this->char_set) && in_array($this->pdodriver, array('4D', 'mysql', 'sybase', 'mssql', 'dblib', 'oci'))) { - // End dsn with a semicolon for extra backward compability - $this->dsn .= rtrim($this->dsn, ';').';'; $this->dsn .= 'charset='.$this->char_set.';'; } } -- cgit v1.2.3-24-g4f1b From 928d83ce1590f14aadfa7a1805c00bb84bd9ef1c Mon Sep 17 00:00:00 2001 From: Timothy Warren Date: Mon, 13 Feb 2012 14:07:57 -0500 Subject: Refixed Old-style pdo connection string --- system/database/drivers/pdo/pdo_driver.php | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/system/database/drivers/pdo/pdo_driver.php b/system/database/drivers/pdo/pdo_driver.php index 5991586c7..c5940ddc8 100644 --- a/system/database/drivers/pdo/pdo_driver.php +++ b/system/database/drivers/pdo/pdo_driver.php @@ -116,15 +116,12 @@ class CI_DB_pdo_driver extends CI_DB { // hostname generally would have this prototype // $db['hostname'] = 'pdodriver:host(/Server(/DSN))=hostname(/DSN);'; // We need to get the prefix (pdodriver used by PDO). - $this->dsn = $this->hostname; - $this->pdodriver = current(explode(':', $this->hostname)); + $dsnarray = explode(':', $this->hostname); + $this->pdodriver = $dsnarray[0]; // End dsn with a semicolon for extra backward compability // if database property was not empty. - if ( ! empty($this->database)) - { - $this->dsn .= rtrim($this->dsn, ';').';'; - } + $this->dsn .= rtrim($this->hostname, ';').';'; } else { @@ -139,7 +136,9 @@ class CI_DB_pdo_driver extends CI_DB { $this->dsn = $this->pdodriver.':'; // Add hostname to the DSN for databases that need it - if ( ! empty($this->hostname) && in_array($this->pdodriver, array('informix', 'mysql', 'pgsql', 'sybase', 'mssql', 'dblib', 'cubrid'))) + if ( ! empty($this->hostname) + && strpos($this->hostname, ':') === FALSE + && in_array($this->pdodriver, array('informix', 'mysql', 'pgsql', 'sybase', 'mssql', 'dblib', 'cubrid'))) { $this->dsn .= 'host='.$this->hostname.';'; } -- cgit v1.2.3-24-g4f1b From 25dc75595dd3550a6c20f3d34d8f5259465b545f Mon Sep 17 00:00:00 2001 From: Timothy Warren Date: Mon, 13 Feb 2012 14:12:35 -0500 Subject: Re-added if ! empty clause --- system/database/drivers/pdo/pdo_driver.php | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/system/database/drivers/pdo/pdo_driver.php b/system/database/drivers/pdo/pdo_driver.php index c5940ddc8..8516cc6fe 100644 --- a/system/database/drivers/pdo/pdo_driver.php +++ b/system/database/drivers/pdo/pdo_driver.php @@ -121,7 +121,10 @@ class CI_DB_pdo_driver extends CI_DB { // End dsn with a semicolon for extra backward compability // if database property was not empty. - $this->dsn .= rtrim($this->hostname, ';').';'; + if( ! empty($this->database)) + { + $this->dsn .= rtrim($this->hostname, ';').';'; + } } else { -- cgit v1.2.3-24-g4f1b From f4524694418b0203e93c6b0ca1a9f28a9c6e4ba7 Mon Sep 17 00:00:00 2001 From: Timothy Warren Date: Mon, 13 Feb 2012 14:13:28 -0500 Subject: Added missing space --- system/database/drivers/pdo/pdo_driver.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/system/database/drivers/pdo/pdo_driver.php b/system/database/drivers/pdo/pdo_driver.php index 8516cc6fe..de2b0abeb 100644 --- a/system/database/drivers/pdo/pdo_driver.php +++ b/system/database/drivers/pdo/pdo_driver.php @@ -121,7 +121,7 @@ class CI_DB_pdo_driver extends CI_DB { // End dsn with a semicolon for extra backward compability // if database property was not empty. - if( ! empty($this->database)) + if ( ! empty($this->database)) { $this->dsn .= rtrim($this->hostname, ';').';'; } -- cgit v1.2.3-24-g4f1b From 93cac5cc7bd1537788506d577c69852b4895a932 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Tue, 14 Feb 2012 14:45:02 +0200 Subject: Fix issue #1039 --- system/database/drivers/mysql/mysql_forge.php | 4 ++-- system/database/drivers/mysql/mysql_utility.php | 15 ++++++++------- user_guide_src/source/changelog.rst | 1 + 3 files changed, 11 insertions(+), 9 deletions(-) diff --git a/system/database/drivers/mysql/mysql_forge.php b/system/database/drivers/mysql/mysql_forge.php index d3107134e..0f251b086 100644 --- a/system/database/drivers/mysql/mysql_forge.php +++ b/system/database/drivers/mysql/mysql_forge.php @@ -147,7 +147,7 @@ class CI_DB_mysql_forge extends CI_DB_forge { $sql .= 'IF NOT EXISTS '; } - $sql .= $this->db->_escape_identifiers($table).' ('.$this->_process_fields($fields); + $sql .= $this->db->protect_identifiers($table).' ('.$this->_process_fields($fields); if (count($primary_keys) > 0) { @@ -187,7 +187,7 @@ class CI_DB_mysql_forge extends CI_DB_forge { */ public function _drop_table($table) { - return 'DROP TABLE IF EXISTS '.$this->db->_escape_identifiers($table); + return 'DROP TABLE IF EXISTS '.$this->db->protect_identifiers($table); } // -------------------------------------------------------------------- diff --git a/system/database/drivers/mysql/mysql_utility.php b/system/database/drivers/mysql/mysql_utility.php index 0e7c18e16..538aaa0f7 100644 --- a/system/database/drivers/mysql/mysql_utility.php +++ b/system/database/drivers/mysql/mysql_utility.php @@ -56,7 +56,7 @@ class CI_DB_mysql_utility extends CI_DB_utility { */ public function _optimize_table($table) { - return 'OPTIMIZE TABLE '.$this->db->_escape_identifiers($table); + return 'OPTIMIZE TABLE '.$this->db->protect_identifiers($table); } // -------------------------------------------------------------------- @@ -71,7 +71,7 @@ class CI_DB_mysql_utility extends CI_DB_utility { */ public function _repair_table($table) { - return 'REPAIR TABLE '.$this->db->_escape_identifiers($table); + return 'REPAIR TABLE '.$this->db->protect_identifiers($table); } // -------------------------------------------------------------------- @@ -102,7 +102,7 @@ class CI_DB_mysql_utility extends CI_DB_utility { } // Get the table schema - $query = $this->db->query('SHOW CREATE TABLE `'.$this->db->database.'`.`'.$table.'`'); + $query = $this->db->query('SHOW CREATE TABLE '.$this->db->protect_identifiers($this->db->database).'.'.$this->db->protect_identifiers($table)); // No result means the table name was invalid if ($query === FALSE) @@ -115,7 +115,7 @@ class CI_DB_mysql_utility extends CI_DB_utility { if ($add_drop == TRUE) { - $output .= 'DROP TABLE IF EXISTS '.$table.';'.$newline.$newline; + $output .= 'DROP TABLE IF EXISTS '.($this->db->protect_identifiers($table).';'.$newline.$newline; } $i = 0; @@ -135,7 +135,7 @@ class CI_DB_mysql_utility extends CI_DB_utility { } // Grab all the data from the current table - $query = $this->db->query('SELECT * FROM '.$table); + $query = $this->db->query('SELECT * FROM '.$this->db->protect_identifiers($table)); if ($query->num_rows() == 0) { @@ -157,7 +157,7 @@ class CI_DB_mysql_utility extends CI_DB_utility { TRUE); // Create a string of field names - $field_str .= '`'.$field->name.'`, '; + $field_str .= $this->db->protect_identifiers($field->name).', '; $i++; } @@ -192,7 +192,7 @@ class CI_DB_mysql_utility extends CI_DB_utility { $val_str = preg_replace('/, $/' , '', $val_str); // Build the INSERT string - $output .= 'INSERT INTO '.$table.' ('.$field_str.') VALUES ('.$val_str.');'.$newline; + $output .= 'INSERT INTO '.$this->db->protect_identifiers($table).' ('.$field_str.') VALUES ('.$val_str.');'.$newline; } return $output.$newline.$newline; @@ -200,6 +200,7 @@ class CI_DB_mysql_utility extends CI_DB_utility { return $output; } + } /* End of file mysql_utility.php */ diff --git a/user_guide_src/source/changelog.rst b/user_guide_src/source/changelog.rst index faea35872..a4904fceb 100644 --- a/user_guide_src/source/changelog.rst +++ b/user_guide_src/source/changelog.rst @@ -105,6 +105,7 @@ Bug fixes for 3.0 - Fixed a hosting edge case where an empty $_SERVER['HTTPS'] variable would evaluate to 'on' - Fixed a bug (#154) - ``CI_Session::sess_update()`` caused the session to be destroyed on pages where multiple AJAX requests were executed at once. - Fixed a possible bug in ``CI_Input::is_ajax_request()`` where some clients might not send the X-Requested-With HTTP header value exactly as 'XmlHttpRequest'. +- Fixed a bug (#1039) - MySQL's _backup() method failed due to a table name not being escaped. Version 2.1.0 ============= -- cgit v1.2.3-24-g4f1b From c51816da79d4b7a1c517142d7380234a9d8bae77 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Tue, 14 Feb 2012 16:55:42 +0200 Subject: Fix another issue --- system/database/drivers/mysql/mysql_utility.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/system/database/drivers/mysql/mysql_utility.php b/system/database/drivers/mysql/mysql_utility.php index 538aaa0f7..9d7cb679c 100644 --- a/system/database/drivers/mysql/mysql_utility.php +++ b/system/database/drivers/mysql/mysql_utility.php @@ -195,7 +195,7 @@ class CI_DB_mysql_utility extends CI_DB_utility { $output .= 'INSERT INTO '.$this->db->protect_identifiers($table).' ('.$field_str.') VALUES ('.$val_str.');'.$newline; } - return $output.$newline.$newline; + $output .= $newline.$newline; } return $output; -- cgit v1.2.3-24-g4f1b From 6e09f238acfa8f3d1180ff3f640c65aeffbc4379 Mon Sep 17 00:00:00 2001 From: Yorick Peterse Date: Wed, 15 Feb 2012 18:23:08 +0100 Subject: Lowered the file permissions for file caches. See #1045 for more information. Signed-off-by: Yorick Peterse --- system/libraries/Cache/drivers/Cache_file.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/system/libraries/Cache/drivers/Cache_file.php b/system/libraries/Cache/drivers/Cache_file.php index 4a81b0422..a960730d7 100644 --- a/system/libraries/Cache/drivers/Cache_file.php +++ b/system/libraries/Cache/drivers/Cache_file.php @@ -99,7 +99,7 @@ class CI_Cache_file extends CI_Driver { if (write_file($this->_cache_path.$id, serialize($contents))) { - @chmod($this->_cache_path.$id, 0777); + @chmod($this->_cache_path.$id, 0660); return TRUE; } -- cgit v1.2.3-24-g4f1b From 287dd450911251c3dc4d744c2e03fcd5d8a5b173 Mon Sep 17 00:00:00 2001 From: Marcos Garcia Date: Fri, 17 Feb 2012 02:26:22 +0100 Subject: Fixed issue #960 --- system/libraries/Cart.php | 7 ------- 1 file changed, 7 deletions(-) diff --git a/system/libraries/Cart.php b/system/libraries/Cart.php index ba8d69be2..10b5362a5 100644 --- a/system/libraries/Cart.php +++ b/system/libraries/Cart.php @@ -329,13 +329,6 @@ class CI_Cart { return FALSE; } - // Is the new quantity different than what is already saved in the cart? - // If it's the same there's nothing to do - if ($this->_cart_contents[$items['rowid']]['qty'] == $items['qty']) - { - return FALSE; - } - // Is the quantity zero? If so we will remove the item from the cart. // If the quantity is greater than zero we are updating if ($items['qty'] == 0) -- cgit v1.2.3-24-g4f1b From 24dd2f9c5cc4476f19c67fe8df6b3ae9cc8a4bb3 Mon Sep 17 00:00:00 2001 From: Taufan Aditya Date: Fri, 17 Feb 2012 17:08:31 +0700 Subject: Syntax error, causing MySQL utility could not used --- system/database/drivers/mysql/mysql_utility.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/system/database/drivers/mysql/mysql_utility.php b/system/database/drivers/mysql/mysql_utility.php index 9d7cb679c..952f887fe 100644 --- a/system/database/drivers/mysql/mysql_utility.php +++ b/system/database/drivers/mysql/mysql_utility.php @@ -115,7 +115,7 @@ class CI_DB_mysql_utility extends CI_DB_utility { if ($add_drop == TRUE) { - $output .= 'DROP TABLE IF EXISTS '.($this->db->protect_identifiers($table).';'.$newline.$newline; + $output .= 'DROP TABLE IF EXISTS '.$this->db->protect_identifiers($table).';'.$newline.$newline; } $i = 0; -- cgit v1.2.3-24-g4f1b From 11454e039fd82f2fd4ee2f186ad0317e3435f187 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Wed, 22 Feb 2012 16:05:47 +0200 Subject: Add an optional database name parameter to db_select() --- system/database/drivers/mssql/mssql_driver.php | 10 +++++----- system/database/drivers/mysql/mysql_driver.php | 5 +++-- system/database/drivers/mysqli/mysqli_driver.php | 5 +++-- system/database/drivers/sqlsrv/sqlsrv_driver.php | 10 +++++----- user_guide_src/source/changelog.rst | 1 + user_guide_src/source/database/connecting.rst | 6 ++++++ 6 files changed, 23 insertions(+), 14 deletions(-) diff --git a/system/database/drivers/mssql/mssql_driver.php b/system/database/drivers/mssql/mssql_driver.php index 2a1098932..27b492f96 100644 --- a/system/database/drivers/mssql/mssql_driver.php +++ b/system/database/drivers/mssql/mssql_driver.php @@ -114,14 +114,14 @@ class CI_DB_mssql_driver extends CI_DB { /** * Select the database * - * @access private called by the base class - * @return resource + * @param string database name + * @return bool */ - function db_select() + public function db_select($database = '') { // Note: The brackets are required in the event that the DB name // contains reserved characters - return @mssql_select_db('['.$this->database.']', $this->conn_id); + return @mssql_select_db('['.($database == '' ? $this->database : $database).']', $this->conn_id); } // -------------------------------------------------------------------- @@ -676,4 +676,4 @@ class CI_DB_mssql_driver extends CI_DB { /* End of file mssql_driver.php */ -/* Location: ./system/database/drivers/mssql/mssql_driver.php */ \ No newline at end of file +/* Location: ./system/database/drivers/mssql/mssql_driver.php */ diff --git a/system/database/drivers/mysql/mysql_driver.php b/system/database/drivers/mysql/mysql_driver.php index 067710ff0..207a68f14 100644 --- a/system/database/drivers/mysql/mysql_driver.php +++ b/system/database/drivers/mysql/mysql_driver.php @@ -119,11 +119,12 @@ class CI_DB_mysql_driver extends CI_DB { /** * Select the database * + * @param string database name * @return bool */ - public function db_select() + public function db_select($database = '') { - return @mysql_select_db($this->database, $this->conn_id); + return @mysql_select_db(($database == '' ? $this->database : $database), $this->conn_id); } // -------------------------------------------------------------------- diff --git a/system/database/drivers/mysqli/mysqli_driver.php b/system/database/drivers/mysqli/mysqli_driver.php index a79b2a4ad..0b80f55be 100644 --- a/system/database/drivers/mysqli/mysqli_driver.php +++ b/system/database/drivers/mysqli/mysqli_driver.php @@ -119,11 +119,12 @@ class CI_DB_mysqli_driver extends CI_DB { /** * Select the database * + * @param string database name * @return bool */ - public function db_select() + public function db_select($database = '') { - return @mysqli_select_db($this->conn_id, $this->database); + return @mysqli_select_db($this->conn_id, ($database == '' ? $this->database : $database)); } // -------------------------------------------------------------------- diff --git a/system/database/drivers/sqlsrv/sqlsrv_driver.php b/system/database/drivers/sqlsrv/sqlsrv_driver.php index 6fd52ef70..390840094 100644 --- a/system/database/drivers/sqlsrv/sqlsrv_driver.php +++ b/system/database/drivers/sqlsrv/sqlsrv_driver.php @@ -122,12 +122,12 @@ class CI_DB_sqlsrv_driver extends CI_DB { /** * Select the database * - * @access private called by the base class - * @return resource + * @param string database name + * @return bool */ - function db_select() + public function db_select($database = '') { - return $this->_execute('USE ' . $this->database); + return $this->_execute('USE '.($database == '' ? $this->database : $database)); } // -------------------------------------------------------------------- @@ -608,4 +608,4 @@ class CI_DB_sqlsrv_driver extends CI_DB { /* End of file mssql_driver.php */ -/* Location: ./system/database/drivers/mssql/mssql_driver.php */ \ No newline at end of file +/* Location: ./system/database/drivers/mssql/mssql_driver.php */ diff --git a/user_guide_src/source/changelog.rst b/user_guide_src/source/changelog.rst index a4904fceb..6142d8bfb 100644 --- a/user_guide_src/source/changelog.rst +++ b/user_guide_src/source/changelog.rst @@ -51,6 +51,7 @@ Release Date: Not Released - MySQLi driver now supports persistent connections when running on PHP >= 5.3. - Added dsn if the group connections in the config use PDO or any driver which need DSN. - Improved PDO database support. + - An optional database name parameter was added db_select(). - Libraries diff --git a/user_guide_src/source/database/connecting.rst b/user_guide_src/source/database/connecting.rst index a834cc0f7..fb4524116 100644 --- a/user_guide_src/source/database/connecting.rst +++ b/user_guide_src/source/database/connecting.rst @@ -122,6 +122,12 @@ return the database object. | $DB1->result(); | etc... +.. note:: You don't need to create separate database configurations if you + only need to use a different database on the same connection. You + can switch to a different database when you need to, like this: + + | $this->db->db_select($database2_name); + Reconnecting / Keeping the Connection Alive =========================================== -- cgit v1.2.3-24-g4f1b From 82e8ac19d0ffeb3edd56b09d7a272d13903af7cc Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Wed, 22 Feb 2012 19:35:34 +0200 Subject: Fix issue 1070 --- system/database/DB_driver.php | 34 ++++++++++------------------------ user_guide_src/source/changelog.rst | 1 + 2 files changed, 11 insertions(+), 24 deletions(-) diff --git a/system/database/DB_driver.php b/system/database/DB_driver.php index b829bbe46..271a70ec4 100644 --- a/system/database/DB_driver.php +++ b/system/database/DB_driver.php @@ -107,11 +107,9 @@ class CI_DB_driver { /** * Initialize Database Settings * - * @access private Called by the constructor - * @param mixed - * @return void + * @return bool */ - function initialize() + public function initialize() { // If an existing connection resource is available // there is no need to connect and select the database @@ -125,7 +123,7 @@ class CI_DB_driver { // Connect to the database and set the connection ID $this->conn_id = ($this->pconnect == FALSE) ? $this->db_connect() : $this->db_pconnect(); - // No connection resource? Check if there is a failover else throw an error + // No connection resource? Check if there is a failover else throw an error if ( ! $this->conn_id) { // Check if there is a failover set @@ -167,31 +165,19 @@ class CI_DB_driver { // ---------------------------------------------------------------- // Select the DB... assuming a database name is specified in the config file - if ($this->database != '') + if ($this->database !== '' && ! $this->db_select()) { - if ( ! $this->db_select()) - { - log_message('error', 'Unable to select database: '.$this->database); + log_message('error', 'Unable to select database: '.$this->database); - if ($this->db_debug) - { - $this->display_error('db_unable_to_select', $this->database); - } - return FALSE; - } - else + if ($this->db_debug) { - // We've selected the DB. Now we set the character set - if ( ! $this->db_set_charset($this->char_set, $this->dbcollat)) - { - return FALSE; - } - - return TRUE; + $this->display_error('db_unable_to_select', $this->database); } + return FALSE; } - return TRUE; + // Now we set the character set and that's all + return $this->db_set_charset($this->char_set, $this->dbcollat); } // -------------------------------------------------------------------- diff --git a/user_guide_src/source/changelog.rst b/user_guide_src/source/changelog.rst index a4904fceb..00d70f323 100644 --- a/user_guide_src/source/changelog.rst +++ b/user_guide_src/source/changelog.rst @@ -106,6 +106,7 @@ Bug fixes for 3.0 - Fixed a bug (#154) - ``CI_Session::sess_update()`` caused the session to be destroyed on pages where multiple AJAX requests were executed at once. - Fixed a possible bug in ``CI_Input::is_ajax_request()`` where some clients might not send the X-Requested-With HTTP header value exactly as 'XmlHttpRequest'. - Fixed a bug (#1039) - MySQL's _backup() method failed due to a table name not being escaped. +- Fixed a bug (#1070) - CI_DB_driver::initialize() didn't set a character set if a database is not selected. Version 2.1.0 ============= -- cgit v1.2.3-24-g4f1b From 024ba2dffd49e26f68468acd69feebd685f63f68 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Fri, 24 Feb 2012 11:40:36 +0200 Subject: Update database property when switching to a new one --- system/database/drivers/mssql/mssql_driver.php | 13 ++++++++++++- system/database/drivers/mysql/mysql_driver.php | 13 ++++++++++++- system/database/drivers/mysqli/mysqli_driver.php | 13 ++++++++++++- system/database/drivers/sqlsrv/sqlsrv_driver.php | 13 ++++++++++++- 4 files changed, 48 insertions(+), 4 deletions(-) diff --git a/system/database/drivers/mssql/mssql_driver.php b/system/database/drivers/mssql/mssql_driver.php index 27b492f96..25a32f364 100644 --- a/system/database/drivers/mssql/mssql_driver.php +++ b/system/database/drivers/mssql/mssql_driver.php @@ -119,9 +119,20 @@ class CI_DB_mssql_driver extends CI_DB { */ public function db_select($database = '') { + if ($database === '') + { + $database = $this->database; + } + // Note: The brackets are required in the event that the DB name // contains reserved characters - return @mssql_select_db('['.($database == '' ? $this->database : $database).']', $this->conn_id); + if (@mssql_select_db('['.$database.']', $this->conn_id)) + { + $this->database = $database; + return TRUE; + } + + return FALSE; } // -------------------------------------------------------------------- diff --git a/system/database/drivers/mysql/mysql_driver.php b/system/database/drivers/mysql/mysql_driver.php index 207a68f14..c88a8a766 100644 --- a/system/database/drivers/mysql/mysql_driver.php +++ b/system/database/drivers/mysql/mysql_driver.php @@ -124,7 +124,18 @@ class CI_DB_mysql_driver extends CI_DB { */ public function db_select($database = '') { - return @mysql_select_db(($database == '' ? $this->database : $database), $this->conn_id); + if ($database === '') + { + $database = $this->database; + } + + if (@mysql_select_db($database, $this->conn_id)) + { + $this->database = $database; + return TRUE; + } + + return FALSE; } // -------------------------------------------------------------------- diff --git a/system/database/drivers/mysqli/mysqli_driver.php b/system/database/drivers/mysqli/mysqli_driver.php index 0b80f55be..dbba12e15 100644 --- a/system/database/drivers/mysqli/mysqli_driver.php +++ b/system/database/drivers/mysqli/mysqli_driver.php @@ -124,7 +124,18 @@ class CI_DB_mysqli_driver extends CI_DB { */ public function db_select($database = '') { - return @mysqli_select_db($this->conn_id, ($database == '' ? $this->database : $database)); + if ($database === '') + { + $database = $this->database; + } + + if (@mysqli_select_db($this->conn_id, $database)) + { + $this->database = $database; + return TRUE; + } + + return FALSE; } // -------------------------------------------------------------------- diff --git a/system/database/drivers/sqlsrv/sqlsrv_driver.php b/system/database/drivers/sqlsrv/sqlsrv_driver.php index 390840094..9c50209ec 100644 --- a/system/database/drivers/sqlsrv/sqlsrv_driver.php +++ b/system/database/drivers/sqlsrv/sqlsrv_driver.php @@ -127,7 +127,18 @@ class CI_DB_sqlsrv_driver extends CI_DB { */ public function db_select($database = '') { - return $this->_execute('USE '.($database == '' ? $this->database : $database)); + if ($database === '') + { + $database = $this->database; + } + + if ($this->_execute('USE '.$database)) + { + $this->database = $database; + return TRUE; + } + + return FALSE; } // -------------------------------------------------------------------- -- cgit v1.2.3-24-g4f1b