Imsanity - Version 2.3.10

Version Description

  • fixed: undefined notice for query during ajax operation
  • fixed: stale metadata could prevent further resizing
Download this release

Release Info

Developer nosilver4u
Plugin Icon 128x128 Imsanity
Version 2.3.10
Comparing to
See all releases

Code changes from version 2.3.9 to 2.3.10

Files changed (3) hide show
  1. ajax.php +11 -19
  2. imsanity.php +17 -13
  3. readme.txt +6 -2
ajax.php CHANGED
@@ -39,22 +39,7 @@ function imsanity_get_images()
39
  $maxH = imsanity_get_option( 'imsanity_max_height', IMSANITY_DEFAULT_MAX_HEIGHT );
40
  $count = 0;
41
 
42
- while( $images = $wpdb->get_results( "SELECT metas.meta_value as file_meta,metas.post_id as ID FROM $wpdb->postmeta metas INNER JOIN $wpdb->posts posts ON posts.ID = metas.post_id WHERE posts.post_type LIKE 'attachment' AND posts.post_mime_type LIKE 'image%%' AND posts.post_mime_type NOT LIKE 'image/bmp' AND metas.meta_key = '_wp_attachment_metadata' $attachment_query LIMIT $offset,$limit" ) ) {
43
- /* $query = $wpdb->prepare(
44
- "select
45
- $wpdb->posts.ID as ID,
46
- $wpdb->postmeta.meta_value as file_meta
47
- from $wpdb->posts
48
- inner join $wpdb->postmeta on $wpdb->posts.ID = $wpdb->postmeta.post_id and $wpdb->postmeta.meta_key = %s
49
- where $wpdb->posts.post_type = %s
50
- and $wpdb->posts.post_mime_type like %s
51
- and $wpdb->posts.post_mime_type != %s",
52
- array( '_wp_attachment_metadata', 'attachment', 'image%', 'image/bmp' )
53
- );
54
-
55
- $images = $wpdb->get_results($query);*/
56
-
57
- // if ( $images ) {
58
 
59
  foreach ( $images as $image ) {
60
  $meta = unserialize( $image->file_meta );
@@ -74,7 +59,6 @@ function imsanity_get_images()
74
  if ( $count >= IMSANITY_AJAX_MAX_RECORDS ) break 2;
75
  }
76
  $offset += $limit;
77
- // }
78
  } // endwhile
79
  die( json_encode( $results ) );
80
  }
@@ -95,7 +79,6 @@ function imsanity_resize_image()
95
  die( json_encode( array( 'success' => false, 'message' => esc_html__( 'Missing ID Parameter', 'imsanity' ) ) ) );
96
  }
97
 
98
- //$images = $wpdb->get_results( $query );
99
  $meta = wp_get_attachment_metadata( $id );
100
 
101
  if ( $meta && is_array( $meta ) ) {
@@ -169,7 +152,16 @@ function imsanity_resize_image()
169
  );
170
  }
171
  } else {
172
- $results = array('success'=>true,'id'=> $id, 'message' => sprintf( esc_html__( 'SKIPPED: %s (Resize not required)', 'imsanity' ) , $oldPath ) );
 
 
 
 
 
 
 
 
 
173
  }
174
  } else {
175
  $results = array( 'success' => false, 'id'=> $id, 'message' => sprintf( esc_html__( 'ERROR: Attachment with ID of %s not found', 'imsanity' ) , htmlentities( $id ) ) );
39
  $maxH = imsanity_get_option( 'imsanity_max_height', IMSANITY_DEFAULT_MAX_HEIGHT );
40
  $count = 0;
41
 
42
+ while( $images = $wpdb->get_results( "SELECT metas.meta_value as file_meta,metas.post_id as ID FROM $wpdb->postmeta metas INNER JOIN $wpdb->posts posts ON posts.ID = metas.post_id WHERE posts.post_type LIKE 'attachment' AND posts.post_mime_type LIKE 'image%%' AND posts.post_mime_type NOT LIKE 'image/bmp' AND metas.meta_key = '_wp_attachment_metadata' LIMIT $offset,$limit" ) ) {
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
43
 
44
  foreach ( $images as $image ) {
45
  $meta = unserialize( $image->file_meta );
59
  if ( $count >= IMSANITY_AJAX_MAX_RECORDS ) break 2;
60
  }
61
  $offset += $limit;
 
62
  } // endwhile
63
  die( json_encode( $results ) );
64
  }
79
  die( json_encode( array( 'success' => false, 'message' => esc_html__( 'Missing ID Parameter', 'imsanity' ) ) ) );
80
  }
81
 
 
82
  $meta = wp_get_attachment_metadata( $id );
83
 
84
  if ( $meta && is_array( $meta ) ) {
152
  );
153
  }
154
  } else {
155
+ $results = array('success'=>true,'id'=> $id, 'message' => sprintf( esc_html__( 'SKIPPED: %s (Resize not required)', 'imsanity' ) , $oldPath ) . " -- $oldW x $oldH" );
156
+ if ( empty( $meta['width'] ) || empty( $meta['height'] ) ) {
157
+ if ( empty( $meta['width'] ) || $meta['width'] > $oldW ) {
158
+ $meta['width'] = $oldW;
159
+ }
160
+ if ( empty( $meta['height'] ) || $meta['height'] > $oldH ) {
161
+ $meta['height'] = $oldH;
162
+ }
163
+ wp_update_attachment_metadata( $id, $meta );
164
+ }
165
  }
166
  } else {
167
  $results = array( 'success' => false, 'id'=> $id, 'message' => sprintf( esc_html__( 'ERROR: Attachment with ID of %s not found', 'imsanity' ) , htmlentities( $id ) ) );
imsanity.php CHANGED
@@ -4,13 +4,13 @@ Plugin Name: Imsanity
4
  Plugin URI: https://wordpress.org/plugins/imsanity/
5
  Description: Imsanity stops insanely huge image uploads
6
  Author: Shane Bishop
7
- Version: 2.3.9
8
  Author URI: https://ewww.io/
9
  Text Domain: imsanity
10
  License: GPLv3
11
  */
12
 
13
- define( 'IMSANITY_VERSION', '2.3.9' );
14
  define( 'IMSANITY_SCHEMA_VERSION', '1.1' );
15
 
16
  define( 'IMSANITY_DEFAULT_MAX_WIDTH', 2048 );
@@ -35,11 +35,11 @@ function imsanity_init() {
35
  }
36
 
37
  /**
38
- * import supporting libraries
39
  */
40
- include_once( plugin_dir_path(__FILE__) . 'libs/utils.php' );
41
- include_once( plugin_dir_path(__FILE__) . 'settings.php' );
42
- include_once( plugin_dir_path(__FILE__) . 'ajax.php' );
43
 
44
  /**
45
  * Inspects the request and determines where the upload came from.
@@ -47,16 +47,20 @@ include_once( plugin_dir_path(__FILE__) . 'ajax.php' );
47
  * @return IMSANITY_SOURCE_POST | IMSANITY_SOURCE_LIBRARY | IMSANITY_SOURCE_OTHER
48
  */
49
  function imsanity_get_source() {
50
- $id = array_key_exists('post_id', $_REQUEST) ? $_REQUEST['post_id'] : '';
51
- $action = array_key_exists('action', $_REQUEST) ? $_REQUEST['action'] : '';
52
 
53
- // a post_id indicates image is attached to a post
54
- if ($id > 0) return IMSANITY_SOURCE_POST;
 
 
55
 
56
- // post_id of 0 is 3.x otherwise use the action parameter
57
- if ( $id === 0 || $id === '0' || $action == 'upload-attachment' ) return IMSANITY_SOURCE_LIBRARY;
 
 
58
 
59
- // we don't know where this one came from but $_REQUEST['_wp_http_referer'] may contain info
60
  return IMSANITY_SOURCE_OTHER;
61
  }
62
 
4
  Plugin URI: https://wordpress.org/plugins/imsanity/
5
  Description: Imsanity stops insanely huge image uploads
6
  Author: Shane Bishop
7
+ Version: 2.3.10
8
  Author URI: https://ewww.io/
9
  Text Domain: imsanity
10
  License: GPLv3
11
  */
12
 
13
+ define( 'IMSANITY_VERSION', '2.3.10' );
14
  define( 'IMSANITY_SCHEMA_VERSION', '1.1' );
15
 
16
  define( 'IMSANITY_DEFAULT_MAX_WIDTH', 2048 );
35
  }
36
 
37
  /**
38
+ * Import supporting libraries.
39
  */
40
+ include_once( plugin_dir_path( __FILE__ ) . 'libs/utils.php' );
41
+ include_once( plugin_dir_path( __FILE__ ) . 'settings.php' );
42
+ include_once( plugin_dir_path( __FILE__ ) . 'ajax.php' );
43
 
44
  /**
45
  * Inspects the request and determines where the upload came from.
47
  * @return IMSANITY_SOURCE_POST | IMSANITY_SOURCE_LIBRARY | IMSANITY_SOURCE_OTHER
48
  */
49
  function imsanity_get_source() {
50
+ $id = array_key_exists( 'post_id', $_REQUEST ) ? $_REQUEST['post_id'] : '';
51
+ $action = array_key_exists( 'action', $_REQUEST ) ? $_REQUEST['action'] : '';
52
 
53
+ // A post_id indicates image is attached to a post.
54
+ if ( $id > 0 ) {
55
+ return IMSANITY_SOURCE_POST;
56
+ }
57
 
58
+ // Post_id of 0 is 3.x otherwise use the action parameter.
59
+ if ( 0 === $id || '0' === $id || 'upload-attachment' == $action ) {
60
+ return IMSANITY_SOURCE_LIBRARY;
61
+ }
62
 
63
+ // We don't know where this one came from but $_REQUEST['_wp_http_referer'] may contain info.
64
  return IMSANITY_SOURCE_OTHER;
65
  }
66
 
readme.txt CHANGED
@@ -3,8 +3,8 @@ Contributors: nosilver4u,verysimple
3
  Donate link: https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=MKMQKCBFFG3WW
4
  Tags: image, scale, resize, space saver, quality
5
  Requires at least: 4.0
6
- Tested up to: 4.7.4
7
- Stable tag: 2.3.9
8
 
9
  Imsanity automatically resizes huge image uploads. Are contributors uploading huge photos? Tired of manually scaling? Imsanity to the rescue!
10
 
@@ -144,6 +144,10 @@ Questions may be posted on the support forum at https://wordpress.org/support/pl
144
 
145
  == Changelog ==
146
 
 
 
 
 
147
  = 2.3.9 =
148
  * fixed: PNG to JPG filled transparency with black instead of white
149
  * fixed: auto-rotation causes incorrect scaling
3
  Donate link: https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=MKMQKCBFFG3WW
4
  Tags: image, scale, resize, space saver, quality
5
  Requires at least: 4.0
6
+ Tested up to: 4.9.4
7
+ Stable tag: 2.3.10
8
 
9
  Imsanity automatically resizes huge image uploads. Are contributors uploading huge photos? Tired of manually scaling? Imsanity to the rescue!
10
 
144
 
145
  == Changelog ==
146
 
147
+ = 2.3.10 =
148
+ * fixed: undefined notice for query during ajax operation
149
+ * fixed: stale metadata could prevent further resizing
150
+
151
  = 2.3.9 =
152
  * fixed: PNG to JPG filled transparency with black instead of white
153
  * fixed: auto-rotation causes incorrect scaling