reSmush.it Image Optimizer - Version 0.1.18

Version Description

  • Avoid filesize () : stat failed errors if a picture file is missing
  • Log check file permissions
  • Check extensions on upload (avoid using reSmush.it API if it's not a picture)
  • Increase API Timeout for big pictures (10 secs)
Download this release

Release Info

Developer resmushit
Plugin Icon 128x128 reSmush.it Image Optimizer
Version 0.1.18
Comparing to
See all releases

Code changes from version 0.1.17 to 0.1.18

classes/resmushit.class.php CHANGED
@@ -12,6 +12,17 @@ Class reSmushit {
12
 
13
  const MAX_FILESIZE = 5242880;
14
 
 
 
 
 
 
 
 
 
 
 
 
15
  /**
16
  *
17
  * Optimize a picture according to a filepath.
@@ -315,9 +326,12 @@ Class reSmushit {
315
  $tmp['ID'] = $image->ID;
316
  $tmp['attachment_metadata'] = unserialize($image->file_meta);
317
 
318
-
 
 
 
319
  //If filesize > 5MB, we do not optimize this picture
320
- if( filesize(get_attached_file( $image->ID )) > self::MAX_FILESIZE){
321
  $files_too_big[] = $tmp;
322
  continue;
323
  }
@@ -326,7 +340,7 @@ Class reSmushit {
326
  }
327
 
328
  }
329
- return json_encode(array('nonoptimized' => $unsmushed_images, 'filestoobig' => $files_too_big));
330
  }
331
 
332
 
@@ -339,7 +353,7 @@ Class reSmushit {
339
  */
340
  public static function getCountNonOptimizedPictures(){
341
  $data = json_decode(self::getNonOptimizedPictures());
342
- return array('nonoptimized' => sizeof($data->nonoptimized), 'filestoobig' => sizeof($data->filestoobig));
343
  }
344
 
345
 
12
 
13
  const MAX_FILESIZE = 5242880;
14
 
15
+ /**
16
+ *
17
+ * returns the list of supported extensions by the API
18
+ *
19
+ * @return array List of extensions
20
+ */
21
+ public static function authorizedExtensions() {
22
+ return array('jpg', 'jpeg', 'gif', 'png', 'bmp', 'tif', 'tiff');
23
+ }
24
+
25
+
26
  /**
27
  *
28
  * Optimize a picture according to a filepath.
326
  $tmp['ID'] = $image->ID;
327
  $tmp['attachment_metadata'] = unserialize($image->file_meta);
328
 
329
+ if( !file_exists(get_attached_file( $image->ID )) ) {
330
+ $files_not_found[] = $tmp;
331
+ continue;
332
+ }
333
  //If filesize > 5MB, we do not optimize this picture
334
+ if( filesize(get_attached_file( $image->ID )) > self::MAX_FILESIZE ){
335
  $files_too_big[] = $tmp;
336
  continue;
337
  }
340
  }
341
 
342
  }
343
+ return json_encode(array('nonoptimized' => $unsmushed_images, 'filestoobig' => $files_too_big, 'filesnotfound' => $files_not_found));
344
  }
345
 
346
 
353
  */
354
  public static function getCountNonOptimizedPictures(){
355
  $data = json_decode(self::getNonOptimizedPictures());
356
+ return array('nonoptimized' => sizeof($data->nonoptimized), 'filestoobig' => sizeof($data->filestoobig), 'filesnotfound' => sizeof($data->filesnotfound));
357
  }
358
 
359
 
readme.txt CHANGED
@@ -3,7 +3,7 @@ Contributors: resmushit
3
  Tags: image, optimizer, image optimization, resmush.it, smush, jpg, png, gif, optimization, compression, Compress, Images, Pictures, Reduce Image Size, Smush, Smush.it
4
  Requires at least: 4.0.0
5
  Tested up to: 4.9.8
6
- Stable tag: 0.1.17
7
  License: GPLv2 or later
8
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
9
 
@@ -14,7 +14,7 @@ Use reSmush.it Image Optimizer for FREE to optimize your pictures file sizes. Im
14
  reSmush.it Image Optimizer allow to use **free Image optimization** based on [reSmush.it API](http://www.resmush.it/ "Image Optimization API, developped by Charles Bourgeaux"). reSmush.it provides image size reduction based on several advanced algorithms. The API accept JPG, PNG and GIF files up to **5MB**.
15
 
16
  This plugin includes a bulk operation to optimize all your pictures in 2 clicks ! Change your image optimization level to fit your needs !
17
- This service is used by more than **300,000** websites on different CMS (Drupal, Joomla, Magento, Prestashop...).
18
 
19
  The plugin includes an option to exclude some pictures of the optimizer.
20
 
@@ -66,6 +66,12 @@ Yes ! Absolutely free, the only restriction is to send images below 5MB.
66
 
67
  == Changelog ==
68
 
 
 
 
 
 
 
69
  = 0.1.17 =
70
  * Fix bug (non-working optimization) on bulk upload when "Optimize on upload" isn't selected
71
  * New header banner for 4 billionth images optimized
3
  Tags: image, optimizer, image optimization, resmush.it, smush, jpg, png, gif, optimization, compression, Compress, Images, Pictures, Reduce Image Size, Smush, Smush.it
4
  Requires at least: 4.0.0
5
  Tested up to: 4.9.8
6
+ Stable tag: 0.1.18
7
  License: GPLv2 or later
8
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
9
 
14
  reSmush.it Image Optimizer allow to use **free Image optimization** based on [reSmush.it API](http://www.resmush.it/ "Image Optimization API, developped by Charles Bourgeaux"). reSmush.it provides image size reduction based on several advanced algorithms. The API accept JPG, PNG and GIF files up to **5MB**.
15
 
16
  This plugin includes a bulk operation to optimize all your pictures in 2 clicks ! Change your image optimization level to fit your needs !
17
+ This service is used by more than **300,000** websites on different CMS (Wordpress, Drupal, Joomla, Magento, Prestashop...).
18
 
19
  The plugin includes an option to exclude some pictures of the optimizer.
20
 
66
 
67
  == Changelog ==
68
 
69
+ = 0.1.18 =
70
+ * Avoid `filesize () : stat failed` errors if a picture file is missing
71
+ * Log check file permissions
72
+ * Check extensions on upload (avoid using reSmush.it API if it's not a picture)
73
+ * Increase API Timeout for big pictures (10 secs)
74
+
75
  = 0.1.17 =
76
  * Fix bug (non-working optimization) on bulk upload when "Optimize on upload" isn't selected
77
  * New header banner for 4 billionth images optimized
resmushit.inc.php CHANGED
@@ -16,7 +16,11 @@ require('resmushit.admin.php');
16
  */
17
  function rlog($str) {
18
  if(get_option('resmushit_logs') == 0)
19
- return false;
 
 
 
 
20
 
21
  // Preserve file size under a reasonable value
22
  if(file_exists('../' . RESMUSHIT_LOGS_PATH)){
16
  */
17
  function rlog($str) {
18
  if(get_option('resmushit_logs') == 0)
19
+ return FALSE;
20
+
21
+ if( !is_writable('../' . RESMUSHIT_LOGS_PATH) ) {
22
+ return FALSE;
23
+ }
24
 
25
  // Preserve file size under a reasonable value
26
  if(file_exists('../' . RESMUSHIT_LOGS_PATH)){
resmushit.php CHANGED
@@ -10,7 +10,7 @@
10
  * Plugin Name: reSmush.it Image Optimizer
11
  * Plugin URI: https://resmush.it
12
  * Description: Image Optimization API. Provides image size optimization
13
- * Version: 0.1.17
14
  * Timestamp: 2018.11.04
15
  * Author: reSmush.it
16
  * Author URI: https://resmush.it
@@ -85,9 +85,16 @@ function resmushit_process_images($attachments, $force_keep_original = TRUE) {
85
  if(reSmushit::getDisabledState($attachment_id))
86
  return $attachments;
87
 
88
- $basepath = dirname(get_attached_file( $attachment_id )) . '/';
 
 
89
  $basefile = basename($attachments[ 'file' ]);
90
 
 
 
 
 
 
91
  $statistics[] = reSmushit::optimize($basepath . $basefile, $force_keep_original );
92
 
93
  foreach($attachments['sizes'] as $image_style)
10
  * Plugin Name: reSmush.it Image Optimizer
11
  * Plugin URI: https://resmush.it
12
  * Description: Image Optimization API. Provides image size optimization
13
+ * Version: 0.1.18
14
  * Timestamp: 2018.11.04
15
  * Author: reSmush.it
16
  * Author URI: https://resmush.it
85
  if(reSmushit::getDisabledState($attachment_id))
86
  return $attachments;
87
 
88
+ $fileInfo = pathinfo(get_attached_file( $attachment_id ));
89
+ $basepath = $fileInfo['dirname'] . '/';
90
+ $extension = isset($fileInfo['extension']) ? $fileInfo['extension'] : NULL;
91
  $basefile = basename($attachments[ 'file' ]);
92
 
93
+ // Optimize only pictures/files accepted by the API
94
+ if( !in_array($extension, resmushit::authorizedExtensions()) ) {
95
+ return TRUE;
96
+ }
97
+
98
  $statistics[] = reSmushit::optimize($basepath . $basefile, $force_keep_original );
99
 
100
  foreach($attachments['sizes'] as $image_style)
resmushit.settings.php CHANGED
@@ -2,9 +2,9 @@
2
 
3
 
4
  define('RESMUSHIT_ENDPOINT', 'http://api.resmush.it/');
5
- define('RESMUSHIT_VERSION', '0.1.17');
6
  define('RESMUSHIT_DEFAULT_QLTY', '92');
7
- define('RESMUSHIT_TIMEOUT', '5');
8
  define('RESMUSHIT_LOGS_PATH', 'resmushit.log');
9
  define('RESMUSHIT_LOGS_MAX_FILESIZE', '102400');
10
  define('RESMUSHIT_NEWSFEED', 'https://feed.resmush.it/');
2
 
3
 
4
  define('RESMUSHIT_ENDPOINT', 'http://api.resmush.it/');
5
+ define('RESMUSHIT_VERSION', '0.1.18');
6
  define('RESMUSHIT_DEFAULT_QLTY', '92');
7
+ define('RESMUSHIT_TIMEOUT', '10');
8
  define('RESMUSHIT_LOGS_PATH', 'resmushit.log');
9
  define('RESMUSHIT_LOGS_MAX_FILESIZE', '102400');
10
  define('RESMUSHIT_NEWSFEED', 'https://feed.resmush.it/');