From a92b903c0e6c2faa2a9480e23e2d3e4b6308878f Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Sat, 24 Dec 2011 19:05:58 +0200 Subject: Improve the Image manipulation library --- system/libraries/Image_lib.php | 150 ++++++++++++++---------------------- user_guide_src/source/changelog.rst | 1 + 2 files changed, 59 insertions(+), 92 deletions(-) diff --git a/system/libraries/Image_lib.php b/system/libraries/Image_lib.php index 20ca1f055..70a127987 100644 --- a/system/libraries/Image_lib.php +++ b/system/libraries/Image_lib.php @@ -1,4 +1,4 @@ -y_axis = ($this->y_axis == '' OR ! is_numeric($this->y_axis)) ? 0 : $this->y_axis; // Watermark-related Stuff... - if ($this->wm_font_color != '') + if ($this->wm_font_color != '' AND strlen($this->wm_font_color) === 6) { - if (strlen($this->wm_font_color) == 6) - { - $this->wm_font_color = '#'.$this->wm_font_color; - } + $this->wm_font_color = '#'.$this->wm_font_color; } - if ($this->wm_shadow_color != '') + if ($this->wm_shadow_color != '' AND strlen($this->wm_shadow_color) === 6) { - if (strlen($this->wm_shadow_color) == 6) - { - $this->wm_shadow_color = '#'.$this->wm_shadow_color; - } + $this->wm_shadow_color = '#'.$this->wm_shadow_color; } if ($this->wm_overlay_path != '') @@ -381,13 +375,7 @@ class CI_Image_lib { */ public function resize() { - $protocol = 'image_process_'.$this->image_library; - - if (preg_match('/gd2$/i', $protocol)) - { - $protocol = 'image_process_gd'; - } - + $protocol = (strtolower(substr($this->image_library, 0, -3)) === 'gd2') ? 'image_process_gd' : 'image_process_'.$this->image_library; return $this->$protocol('resize'); } @@ -404,13 +392,7 @@ class CI_Image_lib { */ public function crop() { - $protocol = 'image_process_'.$this->image_library; - - if (preg_match('/gd2$/i', $protocol)) - { - $protocol = 'image_process_gd'; - } - + $protocol = (strtolower(substr($this->image_library, 0, -3)) === 'gd2') ? 'image_process_gd' : 'image_process_'.$this->image_library; return $this->$protocol('crop'); } @@ -453,7 +435,6 @@ class CI_Image_lib { if ($this->image_library == 'imagemagick' OR $this->image_library == 'netpbm') { $protocol = 'image_process_'.$this->image_library; - return $this->$protocol('rotate'); } @@ -484,20 +465,14 @@ 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) + if ($this->dynamic_output === FALSE AND $this->orig_width == $this->width AND $this->orig_height == $this->height) { - if ($this->orig_width == $this->width AND $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) - { - if (@copy($this->full_src_path, $this->full_dst_path)) - { - @chmod($this->full_dst_path, FILE_WRITE_MODE); - } - } - - return TRUE; + @chmod($this->full_dst_path, FILE_WRITE_MODE); } + + return TRUE; } // Let's set up our values based on the action @@ -601,9 +576,7 @@ class CI_Image_lib { if ( ! preg_match("/convert$/i", $this->library_path)) { - $this->library_path = rtrim($this->library_path, '/').'/'; - - $this->library_path .= 'convert'; + $this->library_path = rtrim($this->library_path, '/').'/convert'; } // Execute the command @@ -808,11 +781,8 @@ class CI_Image_lib { if ($this->rotation_angle == 'hor') { - for ($i = 0; $i < $height; $i++) + for ($i = 0; $i < $height; $i++, $left = 0, $right = $width-1) { - $left = 0; - $right = $width-1; - while ($left < $right) { $cl = imagecolorat($src_img, $left, $i); @@ -828,11 +798,8 @@ class CI_Image_lib { } else { - for ($i = 0; $i < $width; $i++) + for ($i = 0; $i < $width; $i++, $top = 0, $bot = $height-1) { - $top = 0; - $bot = $height-1; - while ($top < $bot) { $ct = imagecolorat($src_img, $i, $top); @@ -993,12 +960,9 @@ class CI_Image_lib { { $this->image_display_gd($src_img); } - else + elseif ( ! $this->image_save_gd($src_img)) { - if ( ! $this->image_save_gd($src_img)) - { - return FALSE; - } + return FALSE; } imagedestroy($src_img); @@ -1065,7 +1029,9 @@ class CI_Image_lib { if ($this->wm_use_truetype == TRUE) { if ($this->wm_font_size == '') - $this->wm_font_size = '17'; + { + $this->wm_font_size = 17; + } $fontwidth = $this->wm_font_size-($this->wm_font_size/4); $fontheight = $this->wm_font_size; @@ -1090,11 +1056,11 @@ class CI_Image_lib { switch ($this->wm_vrt_alignment) { - case "T" : + case 'T': break; - case "M": $y_axis += ($this->orig_height/2)+($fontheight/2); + 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)); + case 'B': $y_axis += ($this->orig_height - $fontheight - $this->wm_shadow_distance - ($fontheight/2)); break; } @@ -1104,32 +1070,34 @@ class CI_Image_lib { // Set horizontal alignment switch ($this->wm_hor_alignment) { - case "L": + 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)); + 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); + 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; } // Add the text to the source image - if ($this->wm_use_truetype) + if ($this->wm_use_truetype AND $this->wm_use_drop_shadow) { - if ($this->wm_use_drop_shadow) - imagettftext($src_img, $this->wm_font_size, 0, $x_shad, $y_shad, $drp_color, $this->wm_font_path, $this->wm_text); - imagettftext($src_img, $this->wm_font_size, 0, $x_axis, $y_axis, $txt_color, $this->wm_font_path, $this->wm_text); + imagettftext($src_img, $this->wm_font_size, 0, $x_shad, $y_shad, $drp_color, $this->wm_font_path, $this->wm_text); + imagettftext($src_img, $this->wm_font_size, 0, $x_axis, $y_axis, $txt_color, $this->wm_font_path, $this->wm_text); } - else + elseif ($this->wm_use_drop_shadow) { - if ($this->wm_use_drop_shadow) - imagestring($src_img, $this->wm_font_size, $x_shad, $y_shad, $this->wm_text, $drp_color); - imagestring($src_img, $this->wm_font_size, $x_axis, $y_axis, $this->wm_text, $txt_color); + imagestring($src_img, $this->wm_font_size, $x_shad, $y_shad, $this->wm_text, $drp_color); + imagestring($src_img, $this->wm_font_size, $x_axis, $y_axis, $this->wm_text, $txt_color); } // Output the final image @@ -1369,26 +1337,24 @@ class CI_Image_lib { } $vals = getimagesize($path); - $types = array(1 => 'gif', 2 => 'jpeg', 3 => 'png'); - - $mime = (isset($types[$vals['2']])) ? 'image/'.$types[$vals['2']] : 'image/jpg'; + $mime = (isset($types[$vals[2]])) ? 'image/'.$types[$vals[2]] : 'image/jpg'; if ($return == TRUE) { - $v['width'] = $vals['0']; - $v['height'] = $vals['1']; - $v['image_type'] = $vals['2']; - $v['size_str'] = $vals['3']; - $v['mime_type'] = $mime; - - return $v; + return array( + 'width' => $vals[0], + 'height' => $vals[1], + 'image_type' => $vals[2], + 'size_str' => $vals[3], + 'mime_type' => $mime + ); } - $this->orig_width = $vals['0']; - $this->orig_height = $vals['1']; - $this->image_type = $vals['2']; - $this->size_str = $vals['3']; + $this->orig_width = $vals[0]; + $this->orig_height = $vals[1]; + $this->image_type = $vals[2]; + $this->size_str = $vals[3]; $this->mime_type = $mime; return TRUE; @@ -1482,10 +1448,10 @@ class CI_Image_lib { { if ( ! extension_loaded('gd')) { - if ( ! dl('gd.so')) - { - return FALSE; - } + /* 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 TRUE; diff --git a/user_guide_src/source/changelog.rst b/user_guide_src/source/changelog.rst index 8a7109feb..6c80be569 100644 --- a/user_guide_src/source/changelog.rst +++ b/user_guide_src/source/changelog.rst @@ -76,6 +76,7 @@ Bug fixes for 3.0 - Bug #795 - Fixed form method and accept-charset when passing an empty array. - Bug #797 - timespan was using incorrect seconds for year and month. - Fixed a bug in CI_Cart::contents() where if called without a TRUE (or equal) parameter, it would fail due to a typo. +- Fixed a bug in CI_Image_lib::gd_loaded() where it was possible for the script execution to end or a PHP E_WARNING message to be emitted. Version 2.1.0 ============= -- cgit v1.2.3-24-g4f1b From 41dd4938306b173fdcc57049f610af4c42949268 Mon Sep 17 00:00:00 2001 From: Andrew Bergal Date: Sat, 24 Dec 2011 22:27:21 -0500 Subject: Fix news item href --- user_guide_src/source/tutorial/news_section.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/user_guide_src/source/tutorial/news_section.rst b/user_guide_src/source/tutorial/news_section.rst index fe8e41607..38e4214ca 100644 --- a/user_guide_src/source/tutorial/news_section.rst +++ b/user_guide_src/source/tutorial/news_section.rst @@ -149,7 +149,7 @@ and add the next piece of code.
-

View article

+

View article

-- cgit v1.2.3-24-g4f1b From 5342e8b0d8e4c0b585a4757d60f0fd7127704755 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Tue, 27 Dec 2011 02:57:52 +0200 Subject: Remove access lines from method descriptions --- system/libraries/Image_lib.php | 24 ------------------------ 1 file changed, 24 deletions(-) diff --git a/system/libraries/Image_lib.php b/system/libraries/Image_lib.php index 70a127987..2737503a8 100644 --- a/system/libraries/Image_lib.php +++ b/system/libraries/Image_lib.php @@ -111,7 +111,6 @@ class CI_Image_lib { * * Resets values in case this class is used in a loop * - * @access public * @return void */ public function clear() @@ -154,7 +153,6 @@ class CI_Image_lib { /** * initialize image preferences * - * @access public * @param array * @return bool */ @@ -370,7 +368,6 @@ class CI_Image_lib { * This is a wrapper function that chooses the proper * resize function based on the protocol specified * - * @access public * @return bool */ public function resize() @@ -387,7 +384,6 @@ class CI_Image_lib { * This is a wrapper function that chooses the proper * cropping function based on the protocol specified * - * @access public * @return bool */ public function crop() @@ -404,7 +400,6 @@ class CI_Image_lib { * This is a wrapper function that chooses the proper * rotation function based on the protocol specified * - * @access public * @return bool */ public function rotate() @@ -455,7 +450,6 @@ class CI_Image_lib { * * This function will resize or crop * - * @access public * @param string * @return bool */ @@ -561,7 +555,6 @@ class CI_Image_lib { * * This function will resize, crop or rotate * - * @access public * @param string * @return bool */ @@ -629,7 +622,6 @@ class CI_Image_lib { * * This function will resize, crop or rotate * - * @access public * @param string * @return bool */ @@ -713,7 +705,6 @@ class CI_Image_lib { /** * Image Rotate Using GD * - * @access public * @return bool */ public function image_rotate_gd() @@ -766,7 +757,6 @@ class CI_Image_lib { * * This function will flip horizontal or vertical * - * @access public * @return bool */ public function image_mirror_gd() @@ -845,7 +835,6 @@ class CI_Image_lib { * This is a wrapper function that chooses the type * of watermarking based on the specified preference. * - * @access public * @param string * @return bool */ @@ -866,7 +855,6 @@ class CI_Image_lib { /** * Watermark - Graphic Version * - * @access public * @return bool */ public function overlay_watermark() @@ -976,7 +964,6 @@ class CI_Image_lib { /** * Watermark - Text Version * - * @access public * @return bool */ public function text_watermark() @@ -1123,7 +1110,6 @@ class CI_Image_lib { * This simply creates an image resource handle * based on the type of image being processed * - * @access public * @param string * @return resource */ @@ -1180,7 +1166,6 @@ class CI_Image_lib { * Takes an image resource as input and writes the file * to the specified destination * - * @access public * @param resource * @return bool */ @@ -1241,7 +1226,6 @@ class CI_Image_lib { /** * Dynamically outputs an image * - * @access public * @param resource * @return void */ @@ -1277,7 +1261,6 @@ class CI_Image_lib { * This function lets us re-proportion the width/height * if users choose to maintain the aspect ratio when resizing. * - * @access public * @return void */ public function image_reproportion() @@ -1318,7 +1301,6 @@ class CI_Image_lib { * * A helper function that gets info about the file * - * @access public * @param string * @return mixed */ @@ -1376,7 +1358,6 @@ class CI_Image_lib { * 'new_height' => '' * ); * - * @access public * @param array * @return array */ @@ -1424,7 +1405,6 @@ class CI_Image_lib { * $array['ext'] = '.jpg'; * $array['name'] = 'my.cool'; * - * @access public * @param array * @return array */ @@ -1441,7 +1421,6 @@ class CI_Image_lib { /** * Is GD Installed? * - * @access public * @return bool */ public function gd_loaded() @@ -1462,7 +1441,6 @@ class CI_Image_lib { /** * Get GD version * - * @access public * @return mixed */ public function gd_version() @@ -1483,7 +1461,6 @@ class CI_Image_lib { /** * Set error message * - * @access public * @param string * @return void */ @@ -1515,7 +1492,6 @@ class CI_Image_lib { /** * Show error messages * - * @access public * @param string * @return string */ -- cgit v1.2.3-24-g4f1b From 7219c07e9e6be839cbf9931a17d587ef4b2895b1 Mon Sep 17 00:00:00 2001 From: WanWizard Date: Wed, 28 Dec 2011 14:09:05 +0100 Subject: added query grouping to Active Record this is a feature that has been lacking for a very long time. lots of people complained about it over the years, but it never got added so you'd have to resort to handcrafted queries when you needed this feature. This is a port of code from DataMapper, in use since CI 1.6. --- system/database/DB_active_rec.php | 258 ++++++++++++++++------- user_guide_src/source/database/active_record.rst | 170 +++++++++------ 2 files changed, 295 insertions(+), 133 deletions(-) diff --git a/system/database/DB_active_rec.php b/system/database/DB_active_rec.php index 530b44e09..b7f43945c 100644 --- a/system/database/DB_active_rec.php +++ b/system/database/DB_active_rec.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: @@ -40,42 +40,44 @@ */ class CI_DB_active_record extends CI_DB_driver { - protected $return_delete_sql = FALSE; - protected $reset_delete_data = FALSE; - - protected $ar_select = array(); - protected $ar_distinct = FALSE; - protected $ar_from = array(); - protected $ar_join = array(); - protected $ar_where = array(); - protected $ar_like = array(); - protected $ar_groupby = array(); - protected $ar_having = array(); - protected $ar_keys = array(); - protected $ar_limit = FALSE; - protected $ar_offset = FALSE; - protected $ar_order = FALSE; - protected $ar_orderby = array(); - protected $ar_set = array(); - protected $ar_wherein = array(); - protected $ar_aliased_tables = array(); - protected $ar_store_array = array(); + protected $return_delete_sql = FALSE; + protected $reset_delete_data = FALSE; + + protected $ar_select = array(); + protected $ar_distinct = FALSE; + protected $ar_from = array(); + protected $ar_join = array(); + protected $ar_where = array(); + protected $ar_like = array(); + protected $ar_groupby = array(); + protected $ar_having = array(); + protected $ar_keys = array(); + protected $ar_limit = FALSE; + protected $ar_offset = FALSE; + protected $ar_order = FALSE; + protected $ar_orderby = array(); + protected $ar_set = array(); + protected $ar_wherein = array(); + protected $ar_aliased_tables = array(); + protected $ar_store_array = array(); + protected $ar_where_group_started = FALSE; + protected $ar_where_group_count = 0; // Active Record Caching variables - protected $ar_caching = FALSE; - protected $ar_cache_exists = array(); - protected $ar_cache_select = array(); - protected $ar_cache_from = array(); - protected $ar_cache_join = array(); - protected $ar_cache_where = array(); - protected $ar_cache_like = array(); - protected $ar_cache_groupby = array(); - protected $ar_cache_having = array(); - protected $ar_cache_orderby = array(); - protected $ar_cache_set = array(); - - protected $ar_no_escape = array(); - protected $ar_cache_no_escape = array(); + protected $ar_caching = FALSE; + protected $ar_cache_exists = array(); + protected $ar_cache_select = array(); + protected $ar_cache_from = array(); + protected $ar_cache_join = array(); + protected $ar_cache_where = array(); + protected $ar_cache_like = array(); + protected $ar_cache_groupby = array(); + protected $ar_cache_having = array(); + protected $ar_cache_orderby = array(); + protected $ar_cache_set = array(); + + protected $ar_no_escape = array(); + protected $ar_cache_no_escape = array(); // -------------------------------------------------------------------- @@ -412,6 +414,8 @@ class CI_DB_active_record extends CI_DB_driver { */ protected function _where($key, $value = NULL, $type = 'AND ', $escape = NULL) { + $type = $this->_group_get_type($type); + if ( ! is_array($key)) { $key = array($key => $value); @@ -441,7 +445,7 @@ class CI_DB_active_record extends CI_DB_driver { $v = ' '.$this->escape($v); } - + if ( ! $this->_has_operator($k)) { $k .= ' = '; @@ -553,6 +557,8 @@ class CI_DB_active_record extends CI_DB_driver { return; } + $type = $this->_group_get_type($type); + if ( ! is_array($values)) { $values = array($values); @@ -663,6 +669,8 @@ class CI_DB_active_record extends CI_DB_driver { */ protected function _like($field, $match = '', $type = 'AND ', $side = 'both', $not = '') { + $type = $this->_group_get_type($type); + if ( ! is_array($field)) { $field = array($field => $match); @@ -712,6 +720,112 @@ class CI_DB_active_record extends CI_DB_driver { // -------------------------------------------------------------------- + /** + * Starts a query group. + * + * @param string (Internal use only) + * @param string (Internal use only) + * @return object + */ + public function group_start($not = '', $type = 'AND ') + { + $type = $this->_group_get_type($type); + + $this->ar_where_group_started = TRUE; + + $prefix = (count($this->ar_where) == 0 AND count($this->ar_cache_where) == 0) ? '' : $type; + $value = $prefix . $not . str_repeat(' ', ++$this->ar_where_group_count) . ' ('; + + $this->ar_where[] = $value; + if ($this->ar_caching) + { + $this->ar_cache_where[] = $value; + } + + return $this; + } + + // -------------------------------------------------------------------- + + /** + * Starts a query group, but ORs the group + * + * @return object + */ + public function or_group_start() + { + return $this->group_start('', 'OR '); + } + + // -------------------------------------------------------------------- + + /** + * Starts a query group, but NOTs the group + * + * @return object + */ + public function not_group_start() + { + return $this->group_start('NOT ', 'AND '); + } + + // -------------------------------------------------------------------- + + /** + * Starts a query group, but OR NOTs the group + * + * @return object + */ + public function or_not_group_start() + { + return $this->group_start('NOT ', 'OR '); + } + + // -------------------------------------------------------------------- + + /** + * Ends a query group + * + * @return object + */ + public function group_end() + { + $value = str_repeat(' ', $this->ar_where_group_count--) . ')'; + + $this->ar_where[] = $value; + if ($this->ar_caching) + { + $this->ar_cache_where[] = $value; + } + + $this->ar_where_group_started = FALSE; + + return $this; + } + + // -------------------------------------------------------------------- + + /** + * Group_get_type + * + * Called by group_start(), _like(), _where() and _where_in() + * + * @param string + * @return string + */ + protected function _group_get_type($type) + { + if ($this->ar_where_group_started) + { + $type = ''; + $this->ar_where_group_started = FALSE; + } + + return $type; + } + + // -------------------------------------------------------------------- + /** * GROUP BY * @@ -950,7 +1064,7 @@ class CI_DB_active_record extends CI_DB_driver { return $this; } - + // -------------------------------------------------------------------- /** @@ -963,24 +1077,24 @@ class CI_DB_active_record extends CI_DB_driver { * @param boolean TRUE: resets AR values; FALSE: leave AR vaules alone * @return string */ - public function get_compiled_select($table = '', $reset = TRUE) + public function get_compiled_select($table = '', $reset = TRUE) { if ($table != '') { $this->_track_aliases($table); $this->from($table); } - + $select = $this->_compile_select(); - + if ($reset === TRUE) { $this->_reset_select(); } - + return $select; } - + // -------------------------------------------------------------------- /** @@ -1197,7 +1311,7 @@ class CI_DB_active_record extends CI_DB_driver { return $this; } - + // -------------------------------------------------------------------- /** @@ -1211,25 +1325,25 @@ class CI_DB_active_record extends CI_DB_driver { * @return string */ public function get_compiled_insert($table = '', $reset = TRUE) - { + { if ($this->_validate_insert($table) === FALSE) { return FALSE; } - + $sql = $this->_insert( $this->_protect_identifiers( $this->ar_from[0], TRUE, NULL, FALSE ), - array_keys($this->ar_set), + array_keys($this->ar_set), array_values($this->ar_set) ); - + if ($reset === TRUE) { $this->_reset_write(); } - + return $sql; } @@ -1251,24 +1365,24 @@ class CI_DB_active_record extends CI_DB_driver { { $this->set($set); } - + if ($this->_validate_insert($table) === FALSE) { return FALSE; } - + $sql = $this->_insert( $this->_protect_identifiers( $this->ar_from[0], TRUE, NULL, FALSE - ), - array_keys($this->ar_set), + ), + array_keys($this->ar_set), array_values($this->ar_set) ); $this->_reset_write(); return $this->query($sql); } - + // -------------------------------------------------------------------- /** @@ -1282,7 +1396,7 @@ class CI_DB_active_record extends CI_DB_driver { * @param string the table to insert data into * @return string */ - protected function _validate_insert($table = '') + protected function _validate_insert($table = '') { if (count($this->ar_set) == 0) { @@ -1308,7 +1422,7 @@ class CI_DB_active_record extends CI_DB_driver { { $this->ar_from[0] = $table; } - + return TRUE; } @@ -1358,7 +1472,7 @@ class CI_DB_active_record extends CI_DB_driver { $this->_reset_write(); return $this->query($sql); } - + // -------------------------------------------------------------------- /** @@ -1375,22 +1489,22 @@ class CI_DB_active_record extends CI_DB_driver { { // Combine any cached components with the current statements $this->_merge_cache(); - + if ($this->_validate_update($table) === FALSE) { return FALSE; } - + $sql = $this->_update($this->_protect_identifiers($this->ar_from[0], TRUE, NULL, FALSE), $this->ar_set, $this->ar_where, $this->ar_orderby, $this->ar_limit); - + if ($reset === TRUE) { $this->_reset_write(); } - + return $sql; } - + // -------------------------------------------------------------------- /** @@ -1433,7 +1547,7 @@ class CI_DB_active_record extends CI_DB_driver { $this->_reset_write(); return $this->query($sql); } - + // -------------------------------------------------------------------- /** @@ -1474,7 +1588,7 @@ class CI_DB_active_record extends CI_DB_driver { $this->ar_from[0] = $table; } } - + // -------------------------------------------------------------------- /** @@ -1673,7 +1787,7 @@ class CI_DB_active_record extends CI_DB_driver { return $this->query($sql); } - + // -------------------------------------------------------------------- /** @@ -1693,7 +1807,7 @@ class CI_DB_active_record extends CI_DB_driver { $this->return_delete_sql = FALSE; return $sql; } - + // -------------------------------------------------------------------- /** @@ -1766,7 +1880,7 @@ class CI_DB_active_record extends CI_DB_driver { { $this->_reset_write(); } - + if ($this->return_delete_sql === true) { return $sql; @@ -1774,7 +1888,7 @@ class CI_DB_active_record extends CI_DB_driver { return $this->query($sql); } - + // -------------------------------------------------------------------- /** @@ -1854,7 +1968,7 @@ class CI_DB_active_record extends CI_DB_driver { } } } - + // -------------------------------------------------------------------- /** @@ -2160,12 +2274,12 @@ class CI_DB_active_record extends CI_DB_driver { $this->ar_no_escape = $this->ar_cache_no_escape; } - + // -------------------------------------------------------------------- /** * Reset Active Record values. - * + * * Publicly-visible method to reset the AR values. * * @access public @@ -2253,4 +2367,4 @@ class CI_DB_active_record extends CI_DB_driver { } /* End of file DB_active_rec.php */ -/* Location: ./system/database/DB_active_rec.php */ \ No newline at end of file +/* Location: ./system/database/DB_active_rec.php */ diff --git a/user_guide_src/source/database/active_record.rst b/user_guide_src/source/database/active_record.rst index 1600f0bd9..c04e67d2a 100644 --- a/user_guide_src/source/database/active_record.rst +++ b/user_guide_src/source/database/active_record.rst @@ -45,7 +45,7 @@ You'll notice that the above function is assigned to a variable named $query, which can be used to show the results:: $query = $this->db->get('mytable'); - + foreach ($query->result() as $row) { echo $row->title; @@ -57,31 +57,31 @@ discussion regarding result generation. $this->db->get_compiled_select() ================================ -Compiles the selection query just like `$this->db->get()`_ but does not *run* +Compiles the selection query just like `$this->db->get()`_ but does not *run* the query. This method simply returns the SQL query as a string. Example:: $sql = $this->db->get_compiled_select('mytable'); echo $sql; - + // Produces string: SELECT * FROM mytable - -The second parameter enables you to set whether or not the active record query + +The second parameter enables you to set whether or not the active record query will be reset (by default it will be—just like `$this->db->get()`):: echo $this->db->limit(10,20)->get_compiled_select('mytable', FALSE); - // Produces string: SELECT * FROM mytable LIMIT 20, 10 + // Produces string: SELECT * FROM mytable LIMIT 20, 10 // (in MySQL. Other databases have slightly different syntax) - + echo $this->db->select('title, content, date')->get_compiled_select(); // Produces string: SELECT title, content, date FROM mytable - -The key thing to notice in the above example is that the second query did not -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 + +The key thing to notice in the above example is that the second query did not +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()`_. @@ -116,7 +116,7 @@ with backticks. This is useful if you need a compound select statement. :: - $this->db->select('(SELECT SUM(payments.amount) FROM payments WHERE payments.invoice_id=4') AS amount_paid', FALSE); + $this->db->select('(SELECT SUM(payments.amount) FROM payments WHERE payments.invoice_id=4') AS amount_paid', FALSE); $query = $this->db->get('mytable'); @@ -130,7 +130,7 @@ include a second parameter to rename the resulting field. $this->db->select_max('age'); $query = $this->db->get('members'); // Produces: SELECT MAX(age) as age FROM members - + $this->db->select_max('age', 'member_age'); $query = $this->db->get('members'); // Produces: SELECT MAX(age) as member_age FROM members @@ -195,7 +195,7 @@ Permits you to write the JOIN portion of your query:: $this->db->from('blogs'); $this->db->join('comments', 'comments.id = blogs.id'); $query = $this->db->get(); - + // Produces: // SELECT * FROM blogs JOIN comments ON comments.id = blogs.id @@ -224,7 +224,7 @@ methods: :: - $this->db->where('name', $name); // Produces: WHERE name = 'Joe' + $this->db->where('name', $name); // Produces: WHERE name = 'Joe' Notice that the equal sign is added for you. @@ -236,7 +236,7 @@ methods: $this->db->where('name', $name); $this->db->where('title', $title); $this->db->where('status', $status); - // WHERE name = 'Joe' AND title = 'boss' AND status = 'active' + // WHERE name = 'Joe' AND title = 'boss' AND status = 'active' #. **Custom key/value method:** You can include an operator in the first parameter in order to @@ -245,7 +245,7 @@ methods: :: $this->db->where('name !=', $name); - $this->db->where('id <', $id); // Produces: WHERE name != 'Joe' AND id < 45 + $this->db->where('id <', $id); // Produces: WHERE name != 'Joe' AND id < 45 #. **Associative array method:** @@ -253,7 +253,7 @@ methods: $array = array('name' => $name, 'title' => $title, 'status' => $status); $this->db->where($array); - // Produces: WHERE name = 'Joe' AND title = 'boss' AND status = 'active' + // Produces: WHERE name = 'Joe' AND title = 'boss' AND status = 'active' You can include your own operators using this method as well: @@ -354,7 +354,7 @@ searches. :: - $this->db->like('title', 'match'); // Produces: WHERE title LIKE '%match%' + $this->db->like('title', 'match'); // Produces: WHERE title LIKE '%match%' If you use multiple function calls they will be chained together with AND between them:: @@ -371,7 +371,7 @@ searches. $this->db->like('title', 'match', 'before'); // Produces: WHERE title LIKE '%match' $this->db->like('title', 'match', 'after'); // Produces: WHERE title LIKE 'match%' - $this->db->like('title', 'match', 'both'); // Produces: WHERE title LIKE '%match%' + $this->db->like('title', 'match', 'both'); // Produces: WHERE title LIKE '%match%' #. **Associative array method:** @@ -443,7 +443,7 @@ Permits you to write the HAVING portion of your query. There are 2 possible syntaxes, 1 argument or 2:: $this->db->having('user_id = 45'); // Produces: HAVING user_id = 45 - $this->db->having('user_id', 45); // Produces: HAVING user_id = 45 + $this->db->having('user_id', 45); // Produces: HAVING user_id = 45 You can also pass an array of multiple values as well:: @@ -486,7 +486,7 @@ Or multiple function calls can be made if you need multiple fields. :: $this->db->order_by("title", "desc"); - $this->db->order_by("name", "asc"); // Produces: ORDER BY title DESC, name ASC + $this->db->order_by("name", "asc"); // Produces: ORDER BY title DESC, name ASC .. note:: order_by() was formerly known as orderby(), which has been @@ -518,7 +518,7 @@ where(), or_where(), like(), or_like(), etc. Example:: echo $this->db->count_all_results('my_table'); // Produces an integer, like 25 $this->db->like('title', 'match'); $this->db->from('my_table'); - echo $this->db->count_all_results(); // Produces an integer, like 17 + echo $this->db->count_all_results(); // Produces an integer, like 17 $this->db->count_all() ====================== @@ -528,6 +528,54 @@ Submit the table name in the first parameter. Example:: echo $this->db->count_all('my_table'); // Produces an integer, like 25 +************** +Query grouping +************** + +Query grouping allows you to create groups of WHERE clauses by enclosing them in parentheses. This will allow +you to create queries with complex WHERE clauses. Nested groups are supported. Example: + + $this->db->select('*')->from('my_table') + ->group_start() + ->where('a', 'a') + ->or_group_start() + ->where('b', 'b') + ->where('c', 'c') + ->group_end() + ->group_end() + ->where('d', 'd') + ->get(); + + // Generates: + // SELECT * FROM (`my_table`) WHERE ( `a` = 'a' OR ( `b` = 'b' AND `c` = 'c' ) ) AND `d` = 'd' + +.. note:: groups need to be balanced, make sure every group_start() is matched by a group_end(). + +$this->db->group_start() +======================== + +Starts a new group by adding an opening parenthesis to the WHERE clause of the query. + +$this->db->or_group_start() +=========================== + +Starts a new group by adding an opening parenthesis to the WHERE clause of the query, prefixing it with 'OR'. + +$this->db->not_group_start() +============================ + +Starts a new group by adding an opening parenthesis to the WHERE clause of the query, prefixing it with 'NOT'. + +$this->db->or_not_group_start() +=============================== + +Starts a new group by adding an opening parenthesis to the WHERE clause of the query, prefixing it with 'OR NOT'. + +$this->db->group_end() +====================== + +Ends the current group by adding an closing parenthesis to the WHERE clause of the query. + ************** Inserting Data ************** @@ -544,7 +592,7 @@ function. Here is an example using an array:: 'name' => 'My Name', 'date' => 'My date' ); - + $this->db->insert('mytable', $data); // Produces: INSERT INTO mytable (title, name, date) VALUES ('My title', 'My name', 'My date') @@ -560,7 +608,7 @@ Here is an example using an object:: var $date = 'My Date'; } */ - + $object = new Myclass; $this->db->insert('mytable', $object); // Produces: INSERT INTO mytable (title, content, date) VALUES ('My Title', 'My Content', 'My Date') @@ -572,7 +620,7 @@ object. $this->db->get_compiled_insert() ================================ -Compiles the insertion query just like `$this->db->insert()`_ but does not +Compiles the insertion query just like `$this->db->insert()`_ but does not *run* the query. This method simply returns the SQL query as a string. Example:: @@ -582,27 +630,27 @@ Example:: 'name' => 'My Name', 'date' => 'My date' ); - + $sql = $this->db->set($data)->get_compiled_insert('mytable'); echo $sql; - + // Produces string: INSERT INTO mytable (title, name, date) VALUES ('My title', 'My name', 'My date') -The second parameter enables you to set whether or not the active record query +The second parameter enables you to set whether or not the active record query will be reset (by default it will be--just like `$this->db->insert()`_):: - + echo $this->db->set('title', 'My Title')->get_compiled_insert('mytable', FALSE); - + // Produces string: INSERT INTO mytable (title) VALUES ('My Title') - + echo $this->db->set('content', 'My Content')->get_compiled_insert(); // Produces string: INSERT INTO mytable (title, content) VALUES ('My Title', 'My Content') - -The key thing to notice in the above example is that the second query did not -utlize `$this->db->from()`_ nor did it pass a table name into the first -parameter. The reason this worked is because the query has not been executed -using `$this->db->insert()`_ which resets values or reset directly using + +The key thing to notice in the above example is that the second query did not +utlize `$this->db->from()`_ nor did it pass a table name into the first +parameter. The reason this worked is because the query has not been executed +using `$this->db->insert()`_ which resets values or reset directly using `$this->db->reset_query()`_. $this->db->insert_batch() @@ -624,7 +672,7 @@ function. Here is an example using an array:: 'date' => 'Another date' ) ); - + $this->db->insert_batch('mytable', $data); // Produces: INSERT INTO mytable (title, name, date) VALUES ('My title', 'My name', 'My date'), ('Another title', 'Another name', 'Another date') @@ -652,7 +700,7 @@ based on whether you are doing an insert or an update:: $this->db->set('name', $name); $this->db->set('title', $title); $this->db->set('status', $status); - $this->db->insert('mytable'); + $this->db->insert('mytable'); **set()** will also accept an optional third parameter ($escape), that will prevent data from being escaped if set to FALSE. To illustrate the @@ -674,7 +722,7 @@ You can also pass an associative array to this function:: 'title' => $title, 'status' => $status ); - + $this->db->set($array); $this->db->insert('mytable'); @@ -687,7 +735,7 @@ Or an object:: var $date = 'My Date'; } */ - + $object = new Myclass; $this->db->set($object); $this->db->insert('mytable'); @@ -709,7 +757,7 @@ is an example using an array:: 'name' => $name, 'date' => $date ); - + $this->db->where('id', $id); $this->db->update('mytable', $data); // Produces: // UPDATE mytable // SET title = '{$title}', name = '{$name}', date = '{$date}' // WHERE id = $id @@ -723,7 +771,7 @@ Or you can supply an object:: var $date = 'My Date'; } */ - + $object = new Myclass; $this->db->where('id', $id); $this->db->update('mytable', $object); @@ -764,14 +812,14 @@ Here is an example using an array:: ) ); - $this->db->update_batch('mytable', $data, 'title'); + $this->db->update_batch('mytable', $data, 'title'); - // Produces: + // Produces: // UPDATE `mytable` SET `name` = CASE // WHEN `title` = 'My title' THEN 'My Name 2' // WHEN `title` = 'Another title' THEN 'Another Name 2' // ELSE `name` END, - // `date` = CASE + // `date` = CASE // WHEN `title` = 'My title' THEN 'My date 2' // WHEN `title` = 'Another title' THEN 'Another date 2' // ELSE `date` END @@ -810,7 +858,7 @@ the data to the second parameter of the function:: $this->db->where('id', $id); $this->db->delete('mytable'); - + // Produces: // DELETE FROM mytable // WHERE id = $id @@ -847,17 +895,17 @@ Generates a truncate SQL string and runs the query. $this->db->from('mytable'); $this->db->truncate(); - - // or - + + // or + $this->db->truncate('mytable'); - + // Produce: - // TRUNCATE mytable + // TRUNCATE mytable .. note:: If the TRUNCATE command isn't available, truncate() will execute as "DELETE FROM table". - + $this->db->get_compiled_delete() ================================ This works exactly the same way as ``$this->db->get_compiled_insert()`` except @@ -917,11 +965,11 @@ Here's a usage example:: $this->db->stop_cache(); $this->db->get('tablename'); //Generates: SELECT `field1` FROM (`tablename`) - + $this->db->select('field2'); $this->db->get('tablename'); //Generates: SELECT `field1`, `field2` FROM (`tablename`) - + $this->db->flush_cache(); $this->db->select('field2'); $this->db->get('tablename'); @@ -935,13 +983,13 @@ Here's a usage example:: $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(). -Just like the methods that execute a query, this will *not* reset items you've +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(). +Just like the methods that execute a query, this will *not* reset items you've cached using `Active Record Caching`_. -This is useful in situations where you are using Active Record to generate SQL -(ex. ``$this->db->get_compiled_select()``) but then choose to, for instance, +This is useful in situations where you are using Active Record to generate SQL +(ex. ``$this->db->get_compiled_select()``) but then choose to, for instance, run the query:: // Note that the second parameter of the get_compiled_select method is FALSE -- cgit v1.2.3-24-g4f1b From dd35b159593917fc517dab35312c9bd108896e59 Mon Sep 17 00:00:00 2001 From: Brandon Jones Date: Wed, 28 Dec 2011 15:57:07 -0500 Subject: Updating Moscow and Samoa timezones --- system/language/english/date_lang.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/system/language/english/date_lang.php b/system/language/english/date_lang.php index 515feec83..631cfa325 100644 --- a/system/language/english/date_lang.php +++ b/system/language/english/date_lang.php @@ -41,7 +41,7 @@ $lang['date_second'] = "Second"; $lang['date_seconds'] = "Seconds"; $lang['UM12'] = '(UTC -12:00) Baker/Howland Island'; -$lang['UM11'] = '(UTC -11:00) Samoa Time Zone, Niue'; +$lang['UM11'] = '(UTC -11:00) Niue'; $lang['UM10'] = '(UTC -10:00) Hawaii-Aleutian Standard Time, Cook Islands, Tahiti'; $lang['UM95'] = '(UTC -9:30) Marquesas Islands'; $lang['UM9'] = '(UTC -9:00) Alaska Standard Time, Gambier Islands'; @@ -58,9 +58,9 @@ $lang['UM1'] = '(UTC -1:00) Azores, Cape Verde Islands'; $lang['UTC'] = '(UTC) Greenwich Mean Time, Western European Time'; $lang['UP1'] = '(UTC +1:00) Central European Time, West Africa Time'; $lang['UP2'] = '(UTC +2:00) Central Africa Time, Eastern European Time, Kaliningrad Time'; -$lang['UP3'] = '(UTC +3:00) Moscow Time, East Africa Time'; +$lang['UP3'] = '(UTC +3:00) East Africa Time, Arabia Standard Time'; $lang['UP35'] = '(UTC +3:30) Iran Standard Time'; -$lang['UP4'] = '(UTC +4:00) Azerbaijan Standard Time, Samara Time'; +$lang['UP4'] = '(UTC +4:00) Moscow Time, Azerbaijan Standard Time'; $lang['UP45'] = '(UTC +4:30) Afghanistan'; $lang['UP5'] = '(UTC +5:00) Pakistan Standard Time, Yekaterinburg Time'; $lang['UP55'] = '(UTC +5:30) Indian Standard Time, Sri Lanka Time'; @@ -78,7 +78,7 @@ $lang['UP11'] = '(UTC +11:00) Magadan Time, Solomon Islands, Vanuatu'; $lang['UP115'] = '(UTC +11:30) Norfolk Island'; $lang['UP12'] = '(UTC +12:00) Fiji, Gilbert Islands, Kamchatka Time, New Zealand Standard Time'; $lang['UP1275'] = '(UTC +12:45) Chatham Islands Standard Time'; -$lang['UP13'] = '(UTC +13:00) Phoenix Islands Time, Tonga'; +$lang['UP13'] = '(UTC +13:00) Samoa Time Zone, Phoenix Islands Time, Tonga'; $lang['UP14'] = '(UTC +14:00) Line Islands'; -- cgit v1.2.3-24-g4f1b From 64dbdfb60e0556177061db2eecdf899111ae4ac9 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Fri, 30 Dec 2011 14:14:07 +0200 Subject: Added support for 3-length hex color values format and a number of validation improvements --- system/libraries/Image_lib.php | 87 +++++++++++++++------------ user_guide_src/source/changelog.rst | 5 ++ user_guide_src/source/libraries/image_lib.rst | 10 ++- 3 files changed, 58 insertions(+), 44 deletions(-) diff --git a/system/libraries/Image_lib.php b/system/libraries/Image_lib.php index 2737503a8..d4fb51923 100644 --- a/system/libraries/Image_lib.php +++ b/system/libraries/Image_lib.php @@ -67,8 +67,8 @@ class CI_Image_lib { public $wm_padding = 0; // Padding around text public $wm_hor_offset = 0; // Lets you push text to the right public $wm_vrt_offset = 0; // Lets you push text down - public $wm_font_color = '#ffffff'; // Text color - public $wm_shadow_color = ''; // Dropshadow color + protected $wm_font_color = '#ffffff'; // Text color + protected $wm_shadow_color = ''; // Dropshadow color public $wm_shadow_distance = 2; // Dropshadow distance public $wm_opacity = 50; // Image opacity: 1 - 100 Only works with image @@ -85,7 +85,7 @@ class CI_Image_lib { public $create_fnc = 'imagecreatetruecolor'; public $copy_fnc = 'imagecopyresampled'; public $error_msg = array(); - public $wm_use_drop_shadow = FALSE; + protected $wm_use_drop_shadow = FALSE; public $wm_use_truetype = FALSE; /** @@ -165,7 +165,30 @@ class CI_Image_lib { { foreach ($props as $key => $val) { - $this->$key = $val; + if (property_exists($this, $key)) + { + if (in_array($key, array('wm_font_color', 'wm_shadow_color'))) + { + if ($val != '' AND preg_match('/^#?([0-9a-f]{3}|[0-9a-f]{6})$/i', $val, $matches)) + { + if (strlen($matches[1]) === 6) + { + $val = '#'.$val; + } + else + { + $val = str_split($val, 1); + $val = '#'.$val[0].$val[0].$val[1].$val[1].$val[2].$val[2]; + } + } + else + { + continue; + } + } + + $this->$key = $val; + } } } @@ -332,16 +355,6 @@ class CI_Image_lib { $this->y_axis = ($this->y_axis == '' OR ! is_numeric($this->y_axis)) ? 0 : $this->y_axis; // Watermark-related Stuff... - if ($this->wm_font_color != '' AND strlen($this->wm_font_color) === 6) - { - $this->wm_font_color = '#'.$this->wm_font_color; - } - - if ($this->wm_shadow_color != '' AND strlen($this->wm_shadow_color) === 6) - { - $this->wm_shadow_color = '#'.$this->wm_shadow_color; - } - if ($this->wm_overlay_path != '') { $this->wm_overlay_path = str_replace("\\", "/", realpath($this->wm_overlay_path)); @@ -351,6 +364,10 @@ class CI_Image_lib { { $this->wm_use_drop_shadow = TRUE; } + elseif ($this->wm_use_drop_shadow == TRUE AND $this->wm_shadow_color == '') + { + $this->wm_use_drop_shadow = FALSE; + } if ($this->wm_font_path != '') { @@ -982,21 +999,6 @@ class CI_Image_lib { // Fetch source image properties $this->get_image_properties(); - // Set RGB values for text and shadow - $this->wm_font_color = str_replace('#', '', $this->wm_font_color); - $this->wm_shadow_color = str_replace('#', '', $this->wm_shadow_color); - - $R1 = hexdec(substr($this->wm_font_color, 0, 2)); - $G1 = hexdec(substr($this->wm_font_color, 2, 2)); - $B1 = hexdec(substr($this->wm_font_color, 4, 2)); - - $R2 = hexdec(substr($this->wm_shadow_color, 0, 2)); - $G2 = hexdec(substr($this->wm_shadow_color, 2, 2)); - $B2 = hexdec(substr($this->wm_shadow_color, 4, 2)); - - $txt_color = imagecolorclosest($src_img, $R1, $G1, $B1); - $drp_color = imagecolorclosest($src_img, $R2, $G2, $B2); - // Reverse the vertical offset // When the image is positioned at the bottom // we don't want the vertical offset to push it @@ -1075,16 +1077,25 @@ class CI_Image_lib { break; } - // Add the text to the source image - if ($this->wm_use_truetype AND $this->wm_use_drop_shadow) - { - imagettftext($src_img, $this->wm_font_size, 0, $x_shad, $y_shad, $drp_color, $this->wm_font_path, $this->wm_text); - imagettftext($src_img, $this->wm_font_size, 0, $x_axis, $y_axis, $txt_color, $this->wm_font_path, $this->wm_text); - } - elseif ($this->wm_use_drop_shadow) + if ($this->wm_use_drop_shadow) { - imagestring($src_img, $this->wm_font_size, $x_shad, $y_shad, $this->wm_text, $drp_color); - imagestring($src_img, $this->wm_font_size, $x_axis, $y_axis, $this->wm_text, $txt_color); + // Set RGB values for text and shadow + $txt_color = str_split(substr($this->wm_font_color, 1, 6)); + $txt_color = imagecolorclosest($src_img, hexdec($txt_color[0]), hexdec($txt_color[1]), hexdec($txt_color[2])); + $drp_color = str_split(substr($this->wm_shadow_color, 1, 6)); + $drp_color = imagecolorclosest($src_img, hexdec($drp_color[0]), hexdec($drp_color[2]), hexdec($drp_color[3])); + + // 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); + imagettftext($src_img, $this->wm_font_size, 0, $x_axis, $y_axis, $txt_color, $this->wm_font_path, $this->wm_text); + } + else + { + imagestring($src_img, $this->wm_font_size, $x_shad, $y_shad, $this->wm_text, $drp_color); + imagestring($src_img, $this->wm_font_size, $x_axis, $y_axis, $this->wm_text, $txt_color); + } } // Output the final image diff --git a/user_guide_src/source/changelog.rst b/user_guide_src/source/changelog.rst index a9673de88..927705b63 100644 --- a/user_guide_src/source/changelog.rst +++ b/user_guide_src/source/changelog.rst @@ -53,6 +53,11 @@ Release Date: Not Released - It now auto-increments quantity's instead of just resetting it, this is the default behaviour of large e-commerce sites. - Product Name strictness can be disabled via the Cart Library by switching "$product_name_safe" - Added function remove() to remove a cart item, updating with quantity of 0 seemed like a hack but has remained to retain compatability + - Image manipulation library changes include: + - The initialize() method now only sets existing class properties. + - 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. - Minor speed optimizations and method & property visibility declarations in the Calendar Library. - Core diff --git a/user_guide_src/source/libraries/image_lib.rst b/user_guide_src/source/libraries/image_lib.rst index 14bd128a6..ed6575c62 100644 --- a/user_guide_src/source/libraries/image_lib.rst +++ b/user_guide_src/source/libraries/image_lib.rst @@ -390,13 +390,11 @@ Preference Default Value Options Description **wm_font_size** 16 None The size of the text. Note: If you are not using the True Type option above, the number is set using a range of 1 - 5. Otherwise, you can use any valid pixel size for the font you're using. -**wm_font_color** ffffff None The font color, specified in hex. Note, you must use the full 6 - character hex value (ie, 993300), rather than the three character - abbreviated version (ie fff). +**wm_font_color** ffffff None The font color, specified in hex. Both the full 6-length (ie, 993300) and + the short three character abbreviated version (ie, fff) are supported. **wm_shadow_color** None None The color of the drop shadow, specified in hex. If you leave this blank - a drop shadow will not be used. Note, you must use the full 6 character - hex value (ie, 993300), rather than the three character abbreviated - version (ie fff). + a drop shadow will not be used. Both the full 6-length (ie, 993300) and + the short three character abbreviated version (ie, fff) are supported. **wm_shadow_distance** 3 None The distance (in pixels) from the font that the drop shadow should appear. ======================= =================== =================== ========================================================================== -- cgit v1.2.3-24-g4f1b From a948f07bde83e149d9fc75e9aaf7260efba39b55 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Fri, 30 Dec 2011 14:22:50 +0200 Subject: Remove a str_split() from the previous commit - we can access string characters like we do in an indexed array anyways --- system/libraries/Image_lib.php | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-) diff --git a/system/libraries/Image_lib.php b/system/libraries/Image_lib.php index d4fb51923..72621c9b4 100644 --- a/system/libraries/Image_lib.php +++ b/system/libraries/Image_lib.php @@ -171,15 +171,7 @@ class CI_Image_lib { { if ($val != '' AND preg_match('/^#?([0-9a-f]{3}|[0-9a-f]{6})$/i', $val, $matches)) { - if (strlen($matches[1]) === 6) - { - $val = '#'.$val; - } - else - { - $val = str_split($val, 1); - $val = '#'.$val[0].$val[0].$val[1].$val[1].$val[2].$val[2]; - } + $val = (strlen($matches[1]) === 6) ? '#'.$val : '#'.$val[0].$val[0].$val[1].$val[1].$val[2].$val[2]; } else { -- cgit v1.2.3-24-g4f1b From 1d97f291fa1988794b0e6ac2b90a0b1f8c83df25 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Fri, 30 Dec 2011 14:24:59 +0200 Subject: Another fix on a previous commit from this request --- system/libraries/Image_lib.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/system/libraries/Image_lib.php b/system/libraries/Image_lib.php index 72621c9b4..609cb7f98 100644 --- a/system/libraries/Image_lib.php +++ b/system/libraries/Image_lib.php @@ -171,7 +171,8 @@ class CI_Image_lib { { if ($val != '' AND preg_match('/^#?([0-9a-f]{3}|[0-9a-f]{6})$/i', $val, $matches)) { - $val = (strlen($matches[1]) === 6) ? '#'.$val : '#'.$val[0].$val[0].$val[1].$val[1].$val[2].$val[2]; + $val = (strlen($matches[1]) === 6) ? + '#'.$matches[1] : '#'.$matches[1][0].$matches[1][0].$matches[1][1].$matches[1][1].$matches[1][2].$matches[1][2]; } else { -- cgit v1.2.3-24-g4f1b From 665af0cbb98372f8521298aafcde9e0c9023123e Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Fri, 30 Dec 2011 14:39:29 +0200 Subject: Some alignment for readability --- system/libraries/Image_lib.php | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/system/libraries/Image_lib.php b/system/libraries/Image_lib.php index 609cb7f98..7beac0ba0 100644 --- a/system/libraries/Image_lib.php +++ b/system/libraries/Image_lib.php @@ -171,8 +171,9 @@ class CI_Image_lib { { if ($val != '' AND preg_match('/^#?([0-9a-f]{3}|[0-9a-f]{6})$/i', $val, $matches)) { - $val = (strlen($matches[1]) === 6) ? - '#'.$matches[1] : '#'.$matches[1][0].$matches[1][0].$matches[1][1].$matches[1][1].$matches[1][2].$matches[1][2]; + $val = (strlen($matches[1]) === 6) + ? '#'.$matches[1] + : '#'.$matches[1][0].$matches[1][0].$matches[1][1].$matches[1][1].$matches[1][2].$matches[1][2]; } else { -- cgit v1.2.3-24-g4f1b From d268eda6c2b502cc7fa352072482d1924e36127e Mon Sep 17 00:00:00 2001 From: Phil Sturgeon Date: Sat, 31 Dec 2011 16:20:11 +0000 Subject: Added SELECT version to migrations to make the query a billionth faster. --- system/libraries/Migration.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/system/libraries/Migration.php b/system/libraries/Migration.php index eb5161d76..f89391c0d 100644 --- a/system/libraries/Migration.php +++ b/system/libraries/Migration.php @@ -322,7 +322,7 @@ class CI_Migration { */ protected function _get_version() { - $row = $this->db->get($this->_migration_table)->row(); + $row = $this->db->select('version')->get($this->_migration_table)->row(); return $row ? $row->version : 0; } -- cgit v1.2.3-24-g4f1b