reSmush.it Image Optimizer - Version 0.1.6

Version Description

  • Bug fix when images uploaded > 5MB
  • List of files above 5MB
  • Translation minor corrections
Download this release

Release Info

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

Code changes from version 0.1.5 to 0.1.6

classes/resmushit.class.php CHANGED
@@ -36,8 +36,10 @@ Class reSmushit {
36
  public static function optimize($file_path = NULL, $is_original = TRUE) {
37
  global $wp_version;
38
 
39
- if(filesize($file_path) > self::MAX_FILESIZE)
 
40
  return false;
 
41
 
42
  $ch = curl_init();
43
  curl_setopt($ch, CURLOPT_URL, RESMUSHIT_ENDPOINT);
@@ -114,7 +116,7 @@ Class reSmushit {
114
 
115
  //Regenerate thumbnails
116
  wp_generate_attachment_metadata($attachment_id, get_attached_file( $attachment_id ));
117
-
118
  return self::wasSuccessfullyUpdated( $attachment_id );
119
  }
120
 
@@ -251,6 +253,7 @@ Class reSmushit {
251
  global $wpdb;
252
  $tmp = array();
253
  $unsmushed_images = array();
 
254
  $already_optimized_images_array = array();
255
  $disabled_images_array = array();
256
 
@@ -303,11 +306,19 @@ Class reSmushit {
303
  $tmp = array();
304
  $tmp['ID'] = $image->ID;
305
  $tmp['attachment_metadata'] = unserialize($image->file_meta);
 
 
 
 
 
 
 
 
306
  $unsmushed_images[] = $tmp;
307
  }
308
 
309
  }
310
- return json_encode($unsmushed_images);
311
  }
312
 
313
 
@@ -320,7 +331,7 @@ Class reSmushit {
320
  */
321
  public static function getCountNonOptimizedPictures(){
322
  $data = json_decode(self::getNonOptimizedPictures());
323
- return sizeof($data);
324
  }
325
 
326
 
@@ -385,9 +396,13 @@ Class reSmushit {
385
  * @return string $status
386
  */
387
  public static function wasSuccessfullyUpdated($attachment_id){
388
- if(self::getDisabledState( $attachment_id ))
389
  return 'disabled';
390
 
 
 
 
 
391
  if( self::getPictureQualitySetting() != self::getAttachmentQuality( $attachment_id ))
392
  return 'failed';
393
  return 'success';
36
  public static function optimize($file_path = NULL, $is_original = TRUE) {
37
  global $wp_version;
38
 
39
+ if(filesize($file_path) > self::MAX_FILESIZE){
40
+ rlog('Error! Picture ' . $file_path . ' cannot be optimized, file size is above 5MB ('. reSmushitUI::sizeFormat(filesize($file_path)) .')');
41
  return false;
42
+ }
43
 
44
  $ch = curl_init();
45
  curl_setopt($ch, CURLOPT_URL, RESMUSHIT_ENDPOINT);
116
 
117
  //Regenerate thumbnails
118
  wp_generate_attachment_metadata($attachment_id, get_attached_file( $attachment_id ));
119
+
120
  return self::wasSuccessfullyUpdated( $attachment_id );
121
  }
122
 
253
  global $wpdb;
254
  $tmp = array();
255
  $unsmushed_images = array();
256
+ $files_too_big = array();
257
  $already_optimized_images_array = array();
258
  $disabled_images_array = array();
259
 
306
  $tmp = array();
307
  $tmp['ID'] = $image->ID;
308
  $tmp['attachment_metadata'] = unserialize($image->file_meta);
309
+
310
+
311
+ //If filesize > 5MB, we do not optimize this picture
312
+ if( filesize(get_attached_file( $image->ID )) > self::MAX_FILESIZE){
313
+ $files_too_big[] = $tmp;
314
+ continue;
315
+ }
316
+
317
  $unsmushed_images[] = $tmp;
318
  }
319
 
320
  }
321
+ return json_encode(array('nonoptimized' => $unsmushed_images, 'filestoobig' => $files_too_big));
322
  }
323
 
324
 
331
  */
332
  public static function getCountNonOptimizedPictures(){
333
  $data = json_decode(self::getNonOptimizedPictures());
334
+ return array('nonoptimized' => sizeof($data->nonoptimized), 'filestoobig' => sizeof($data->filestoobig));
335
  }
336
 
337
 
396
  * @return string $status
397
  */
398
  public static function wasSuccessfullyUpdated($attachment_id){
399
+ if( self::getDisabledState( $attachment_id ))
400
  return 'disabled';
401
 
402
+ if( filesize(get_attached_file( $attachment_id )) > self::MAX_FILESIZE){
403
+ return 'file_too_big';
404
+ }
405
+
406
  if( self::getPictureQualitySetting() != self::getAttachmentQuality( $attachment_id ))
407
  return 'failed';
408
  return 'success';
classes/resmushitUI.class.php CHANGED
@@ -115,7 +115,8 @@ Class reSmushitUI {
115
  * @return none
116
  */
117
  public static function bulkPanel() {
118
- $countNonOptimizedPictures = reSmushit::getCountNonOptimizedPictures();
 
119
  self::fullWidthPanelWrapper(__('Optimize unsmushed pictures', 'resmushit'), null, 'blue');
120
  ?>
121
 
@@ -137,6 +138,50 @@ Class reSmushitUI {
137
  }
138
 
139
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
140
 
141
 
142
  /**
115
  * @return none
116
  */
117
  public static function bulkPanel() {
118
+ $dataCountNonOptimizedPictures = reSmushit::getCountNonOptimizedPictures();
119
+ $countNonOptimizedPictures = $dataCountNonOptimizedPictures['nonoptimized'];
120
  self::fullWidthPanelWrapper(__('Optimize unsmushed pictures', 'resmushit'), null, 'blue');
121
  ?>
122
 
138
  }
139
 
140
 
141
+ /**
142
+ *
143
+ * Generate Bulk panel
144
+ *
145
+ * @param none
146
+ * @return none
147
+ */
148
+ public static function bigFilesPanel() {
149
+ $getNonOptimizedPictures = json_decode(reSmushit::getNonOptimizedPictures());
150
+ ;
151
+ $countfilesTooBigPictures = sizeof($getNonOptimizedPictures->filestoobig);
152
+ if(!$countfilesTooBigPictures)
153
+ return false;
154
+
155
+ self::fullWidthPanelWrapper(__('Files non optimized', 'resmushit'), null, 'grey');
156
+ ?>
157
+
158
+ <div class="rsmt-bigfiles">
159
+ <div class="optimized-wrapper <?php if(!$countfilesTooBigPictures) echo 'disabled' ?>">
160
+ <h3 class="icon_message info">
161
+ <?php if($countfilesTooBigPictures > 1): ?>
162
+ <?php echo $countfilesTooBigPictures . ' ' ?><?php _e('pictures are too big (> 5MB) for the optimizer', 'resmushit') ?>
163
+ <?php else: ?>
164
+ <?php echo $countfilesTooBigPictures . ' ' ?><?php _e('picture is too big (> 5MB) for the optimizer', 'resmushit') ?>
165
+ <?php endif ?>
166
+ </h3>
167
+ <div class="list-accordion">
168
+ <h4><?php _e('List of files above 5MB', 'resmushit') ?></h4>
169
+ <ul>
170
+ <?php foreach($getNonOptimizedPictures->filestoobig as $file): ?>
171
+ <?php
172
+ $fileInfo = pathinfo(get_attached_file( $file->ID ));
173
+ $filesize = reSmushitUI::sizeFormat(filesize(get_attached_file( $file->ID )));
174
+ ?>
175
+ <li><a href="<?php echo wp_get_attachment_url( $file->ID ); ?>" target="_blank"><?php echo wp_get_attachment_image($file->ID, 'thumbnail'); ?><span><?php echo $fileInfo['basename'] . ' (' . $filesize . ').' ?></span></a></li>
176
+ <?php endforeach; ?>
177
+ </ul>
178
+ </div>
179
+ </div>
180
+ </div>
181
+ <?php self::fullWidthPanelEndWrapper();
182
+ }
183
+
184
+
185
 
186
 
187
  /**
css/resmushit.css CHANGED
@@ -34,6 +34,9 @@
34
  .rsmt-panels .brdr-red{
35
  border-left: 4px solid #9E2F29
36
  }
 
 
 
37
  .rsmt-panels h2{
38
  text-transform: uppercase;
39
  font-family: 'Roboto Slab', serif;
@@ -83,6 +86,7 @@
83
  .rsmt-bulk .disabled{
84
  display: none;
85
  }
 
86
  .rsmt-bulk .icon_message{
87
  background-repeat: no-repeat;
88
  padding: 13px 0 0 60px;
@@ -153,6 +157,37 @@
153
  display: none;
154
  }
155
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
156
 
157
  .rsmt-news .news-item{
158
  margin-bottom: 25px;
34
  .rsmt-panels .brdr-red{
35
  border-left: 4px solid #9E2F29
36
  }
37
+ .rsmt-panels .brdr-grey{
38
+ border-left: 4px solid #a2a2a2
39
+ }
40
  .rsmt-panels h2{
41
  text-transform: uppercase;
42
  font-family: 'Roboto Slab', serif;
86
  .rsmt-bulk .disabled{
87
  display: none;
88
  }
89
+ .rsmt-bigfiles .icon_message,
90
  .rsmt-bulk .icon_message{
91
  background-repeat: no-repeat;
92
  padding: 13px 0 0 60px;
157
  display: none;
158
  }
159
 
160
+ .rsmt-bigfiles .info{
161
+ background-image: url(../images/info.png);
162
+
163
+ }
164
+ .rsmt-bigfiles h4{
165
+ cursor: pointer;
166
+ background-image: url(../images/toggle.png);
167
+ background-repeat: no-repeat;
168
+ padding-left: 20px;
169
+ background-position: 0 1px;
170
+ }
171
+ .rsmt-bigfiles .opened h4{
172
+ background-position: 0 -13px;
173
+ }
174
+ .rsmt-bigfiles ul{
175
+ display: none;
176
+ }
177
+ .rsmt-bigfiles ul{
178
+ margin-left:10px;
179
+ }
180
+
181
+ .rsmt-bigfiles ul li *{
182
+ display: inline-block;
183
+ vertical-align: middle;
184
+ }
185
+ .rsmt-bigfiles ul li img{
186
+ height: auto;
187
+ width: 50px;
188
+ border: 1px solid #666;
189
+ margin-right: 15px;
190
+ }
191
 
192
  .rsmt-news .news-item{
193
  margin-bottom: 25px;
images/info.png ADDED
Binary file
images/toggle.png ADDED
Binary file
js/script.js CHANGED
@@ -5,6 +5,7 @@
5
  var bulkCounter = 0;
6
  var bulkTotalimages = 0;
7
  var next_index = 0;
 
8
 
9
 
10
  /**
@@ -19,6 +20,18 @@ jQuery("#rsmt-options-form").submit(function(){
19
  }
20
  });
21
 
 
 
 
 
 
 
 
 
 
 
 
 
22
  updateDisabledState();
23
  optimizeSingleAttachment();
24
 
@@ -37,6 +50,8 @@ function resmushit_bulk_process(bulk, item){
37
  function(response) {
38
  if(response == 'failed')
39
  error_occured = true;
 
 
40
 
41
  if(!flag_removed){
42
  jQuery('#bulk_resize_target').remove();
@@ -57,8 +72,16 @@ function resmushit_bulk_process(bulk, item){
57
  jQuery('.non-optimized-wrapper h3').text('An error occured when contacting webservice. Please try again later.');
58
  jQuery('.non-optimized-wrapper > p').remove();
59
  jQuery('.non-optimized-wrapper > div').remove();
60
- }
61
- else{
 
 
 
 
 
 
 
 
62
  jQuery('.non-optimized-wrapper').addClass('disabled');
63
  jQuery('.optimized-wrapper').removeClass('disabled');
64
  updateStatistics();
@@ -90,15 +113,15 @@ function resmushit_bulk_resize(container_id) {
90
  { action: 'resmushit_bulk_get_images' },
91
  function(response) {
92
  var images = JSON.parse(response);
93
- if (images.length > 0) {
94
- bulkTotalimages = images.length;
95
 
96
 
97
  flag_removed = false;
98
  //start treating all pictures
99
- resmushit_bulk_process(images, 0);
100
  } else {
101
- target.html('<div>There are no existing attachments that require Smushing.</div>');
102
  }
103
  }
104
  );
5
  var bulkCounter = 0;
6
  var bulkTotalimages = 0;
7
  var next_index = 0;
8
+ var file_too_big_count = 0;
9
 
10
 
11
  /**
20
  }
21
  });
22
 
23
+
24
+ jQuery( ".list-accordion h4" ).on('click', function(){
25
+ if(jQuery(this).parent().hasClass('opened')){
26
+ jQuery(".list-accordion ul").slideUp();
27
+ jQuery('.list-accordion').removeClass('opened');
28
+
29
+ } else {
30
+ jQuery(".list-accordion ul").slideDown();
31
+ jQuery('.list-accordion').addClass('opened');
32
+ }
33
+ });
34
+
35
  updateDisabledState();
36
  optimizeSingleAttachment();
37
 
50
  function(response) {
51
  if(response == 'failed')
52
  error_occured = true;
53
+ else if(response == 'file_too_big')
54
+ file_too_big_count++;
55
 
56
  if(!flag_removed){
57
  jQuery('#bulk_resize_target').remove();
72
  jQuery('.non-optimized-wrapper h3').text('An error occured when contacting webservice. Please try again later.');
73
  jQuery('.non-optimized-wrapper > p').remove();
74
  jQuery('.non-optimized-wrapper > div').remove();
75
+ } else if(file_too_big_count){
76
+
77
+ var message = file_too_big_count + ' picture cannot be optimized (> 5MB). All others have been optimized';
78
+ if(file_too_big_count > 1)
79
+ var message = file_too_big_count + ' pictures cannot be optimized (> 5MB). All others have been optimized';
80
+
81
+ jQuery('.non-optimized-wrapper h3').text(message);
82
+ jQuery('.non-optimized-wrapper > p').remove();
83
+ jQuery('.non-optimized-wrapper > div').remove();
84
+ } else{
85
  jQuery('.non-optimized-wrapper').addClass('disabled');
86
  jQuery('.optimized-wrapper').removeClass('disabled');
87
  updateStatistics();
113
  { action: 'resmushit_bulk_get_images' },
114
  function(response) {
115
  var images = JSON.parse(response);
116
+ if (images.nonoptimized.length > 0) {
117
+ bulkTotalimages = images.nonoptimized.length;
118
 
119
 
120
  flag_removed = false;
121
  //start treating all pictures
122
+ resmushit_bulk_process(images.nonoptimized, 0);
123
  } else {
124
+ target.html('<div>There are no existing attachments that requires optimization.</div>');
125
  }
126
  }
127
  );
languages/resmushit-fr_FR.mo CHANGED
Binary file
languages/resmushit-fr_FR.po CHANGED
@@ -7,16 +7,16 @@ msgid ""
7
  msgstr ""
8
  "Project-Id-Version: \n"
9
  "Report-Msgid-Bugs-To: \n"
10
- "POT-Creation-Date: 2016-08-08 16:29+0200\n"
11
- "PO-Revision-Date: 2016-08-09 12:31+0200\n"
 
12
  "Language-Team: \n"
 
13
  "MIME-Version: 1.0\n"
14
  "Content-Type: text/plain; charset=UTF-8\n"
15
  "Content-Transfer-Encoding: 8bit\n"
16
- "X-Generator: Poedit 1.8.8\n"
17
- "Last-Translator: \n"
18
  "Plural-Forms: nplurals=2; plural=(n > 1);\n"
19
- "Language: fr\n"
20
 
21
  #: resmushit.admin.php:37 resmushit.admin.php:64
22
  msgid "Disable of reSmush.it"
@@ -57,8 +57,7 @@ msgstr "Activer les statistiques"
57
 
58
  #: classes/resmushitUI.class.php:99
59
  msgid "Generates statistics about optimized pictures"
60
- msgstr ""
61
- "Génère des statistiques à partir des images optimisées via reSmush.it"
62
 
63
  #: classes/resmushitUI.class.php:100
64
  msgid "Enable logs"
@@ -70,7 +69,7 @@ msgstr "Activation de la journalisation d'erreurs (pour développeurs)"
70
 
71
  #: classes/resmushitUI.class.php:119
72
  msgid "Optimize unsmushed pictures"
73
- msgstr "Optimizer les images via reSmush.it"
74
 
75
  #: classes/resmushitUI.class.php:124
76
  msgid "There is currently"
@@ -155,3 +154,19 @@ msgstr "Réduction de"
155
  #: classes/resmushitUI.class.php:308
156
  msgid "saved"
157
  msgstr "gagné"
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
7
  msgstr ""
8
  "Project-Id-Version: \n"
9
  "Report-Msgid-Bugs-To: \n"
10
+ "POT-Creation-Date: 2016-09-08 15:05+0200\n"
11
+ "PO-Revision-Date: 2016-09-08 15:06+0200\n"
12
+ "Last-Translator: \n"
13
  "Language-Team: \n"
14
+ "Language: fr\n"
15
  "MIME-Version: 1.0\n"
16
  "Content-Type: text/plain; charset=UTF-8\n"
17
  "Content-Transfer-Encoding: 8bit\n"
18
+ "X-Generator: Poedit 1.8.9\n"
 
19
  "Plural-Forms: nplurals=2; plural=(n > 1);\n"
 
20
 
21
  #: resmushit.admin.php:37 resmushit.admin.php:64
22
  msgid "Disable of reSmush.it"
57
 
58
  #: classes/resmushitUI.class.php:99
59
  msgid "Generates statistics about optimized pictures"
60
+ msgstr "Génère des statistiques à partir des images optimisées via reSmush.it"
 
61
 
62
  #: classes/resmushitUI.class.php:100
63
  msgid "Enable logs"
69
 
70
  #: classes/resmushitUI.class.php:119
71
  msgid "Optimize unsmushed pictures"
72
+ msgstr "Optimiser les images via reSmush.it"
73
 
74
  #: classes/resmushitUI.class.php:124
75
  msgid "There is currently"
154
  #: classes/resmushitUI.class.php:308
155
  msgid "saved"
156
  msgstr "gagné"
157
+
158
+ #: classes/resmushitUI.class.php:155
159
+ msgid "Files non optimized"
160
+ msgstr "Fichiers non optimisés"
161
+
162
+ #: classes/resmushitUI.class.php:162
163
+ msgid "pictures are too big (> 5MB) for the optimizer"
164
+ msgstr "images sont trop lourdes (> 5 Mo) pour reSmush.it"
165
+
166
+ #: classes/resmushitUI.class.php:164
167
+ msgid "picture is too big (> 5MB) for the optimizer"
168
+ msgstr "image est trop lourde (> 5 Mo) pour reSmush.it"
169
+
170
+ #: classes/resmushitUI.class.php:168
171
+ msgid "List of files above 5MB"
172
+ msgstr "Liste des fichiers de plus de 5 Mo"
languages/resmushit.pot CHANGED
@@ -146,3 +146,19 @@ msgstr ""
146
  #: classes/resmushitUI.class.php:308
147
  msgid "saved"
148
  msgstr ""
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
146
  #: classes/resmushitUI.class.php:308
147
  msgid "saved"
148
  msgstr ""
149
+
150
+ #: classes/resmushitUI.class.php:155
151
+ msgid "Files non optimized"
152
+ msgstr ""
153
+
154
+ #: classes/resmushitUI.class.php:162
155
+ msgid "pictures are too big (> 5MB) for the optimizer"
156
+ msgstr ""
157
+
158
+ #: classes/resmushitUI.class.php:164
159
+ msgid "picture is too big (> 5MB) for the optimizer"
160
+ msgstr ""
161
+
162
+ #: classes/resmushitUI.class.php:168
163
+ msgid "List of files above 5MB"
164
+ msgstr ""
readme.txt CHANGED
@@ -2,8 +2,8 @@
2
  Contributors: maecia
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.6.0
6
- Stable tag: 0.1.5
7
  License: GPLv2 or later
8
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
9
 
@@ -41,6 +41,11 @@ Yes ! Absolutely free, the only restriction is to send images below 5MB.
41
 
42
  == Changelog ==
43
 
 
 
 
 
 
44
  = 0.1.5 =
45
  * Error management if webservice not reachable
46
  * Filesize limitation increased from 2MB to 5MB
2
  Contributors: maecia
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.6.1
6
+ Stable tag: 0.1.6
7
  License: GPLv2 or later
8
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
9
 
41
 
42
  == Changelog ==
43
 
44
+ = 0.1.6 =
45
+ * Bug fix when images uploaded > 5MB
46
+ * List of files above 5MB
47
+ * Translation minor corrections
48
+
49
  = 0.1.5 =
50
  * Error management if webservice not reachable
51
  * Filesize limitation increased from 2MB to 5MB
resmushit.admin.php CHANGED
@@ -92,6 +92,7 @@ function resmushit_settings_page() {
92
  <div class="rsmt-cols w66 iln-block">
93
  <?php reSmushitUI::headerPanel();?>
94
  <?php reSmushitUI::bulkPanel();?>
 
95
  <?php reSmushitUI::statisticsPanel();?>
96
  </div>
97
  <div class="rsmt-cols w33 iln-block">
92
  <div class="rsmt-cols w66 iln-block">
93
  <?php reSmushitUI::headerPanel();?>
94
  <?php reSmushitUI::bulkPanel();?>
95
+ <?php reSmushitUI::bigFilesPanel();?>
96
  <?php reSmushitUI::statisticsPanel();?>
97
  </div>
98
  <div class="rsmt-cols w33 iln-block">
resmushit.php CHANGED
@@ -10,8 +10,8 @@
10
  * Plugin Name: reSmush.it Image Optimizer
11
  * Plugin URI: http://www.resmush.it
12
  * Description: Image Optimization API. Provides image size optimization
13
- * Version: 0.1.5
14
- * Timestamp: 2016.08.10
15
  * Author: Maecia
16
  * Author URI: https://www.maecia.com
17
  * Author: Charles Bourgeaux
10
  * Plugin Name: reSmush.it Image Optimizer
11
  * Plugin URI: http://www.resmush.it
12
  * Description: Image Optimization API. Provides image size optimization
13
+ * Version: 0.1.6
14
+ * Timestamp: 2016.09.08
15
  * Author: Maecia
16
  * Author URI: https://www.maecia.com
17
  * Author: Charles Bourgeaux
resmushit.settings.php CHANGED
@@ -2,7 +2,7 @@
2
 
3
 
4
  define('RESMUSHIT_ENDPOINT', 'http://api.resmush.it/');
5
- define('RESMUSHIT_VERSION', '0.1.5');
6
  define('RESMUSHIT_DEFAULT_QLTY', '92');
7
  define('RESMUSHIT_TIMEOUT', '5');
8
  define('RESMUSHIT_LOGS_PATH', 'resmushit.log');
2
 
3
 
4
  define('RESMUSHIT_ENDPOINT', 'http://api.resmush.it/');
5
+ define('RESMUSHIT_VERSION', '0.1.6');
6
  define('RESMUSHIT_DEFAULT_QLTY', '92');
7
  define('RESMUSHIT_TIMEOUT', '5');
8
  define('RESMUSHIT_LOGS_PATH', 'resmushit.log');