reSmush.it Image Optimizer - Version 0.1.2

Version Description

  • Delete also original file when deleting an attachment
  • Exclusion of an attachment of the reSmush.it optimization (checkboxes)
  • Adding french translation
  • Code optimizations
  • 4.6.x check
  • Minor bugs corrections
Download this release

Release Info

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

Code changes from version 0.1.1 to 0.1.2

classes/resmushit.class.php CHANGED
@@ -19,7 +19,7 @@ Class reSmushit {
19
  * @param string $file_path the path to the file on the server
20
  * @return bool TRUE if the resmush operation worked
21
  */
22
- public static function getPictureQuality() {
23
  if(get_option( 'resmushit_qlty' ))
24
  return get_option( 'resmushit_qlty' );
25
  else
@@ -55,7 +55,7 @@ Class reSmushit {
55
  );
56
  }
57
 
58
- $arg['qlty'] = self::getPictureQuality();
59
  curl_setopt($ch, CURLOPT_POSTFIELDS, $arg);
60
 
61
  $data = curl_exec($ch);
@@ -86,22 +86,78 @@ Class reSmushit {
86
 
87
 
88
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
89
  /**
90
  *
91
  * Return optimization statistics
92
  *
93
- * @param none
94
  * @return array of statistics
95
  */
96
- public static function getStatistics(){
97
  global $wpdb;
98
  $output = array();
 
 
 
99
 
100
  $query = $wpdb->prepare(
101
  "select
102
  $wpdb->posts.ID as ID, $wpdb->postmeta.meta_value
103
  from $wpdb->posts
104
- inner join $wpdb->postmeta on $wpdb->posts.ID = $wpdb->postmeta.post_id and $wpdb->postmeta.meta_key = %s",
105
  array('resmushed_cumulated_original_sizes')
106
  );
107
  $original_sizes = $wpdb->get_results($query);
@@ -114,7 +170,7 @@ Class reSmushit {
114
  "select
115
  $wpdb->posts.ID as ID, $wpdb->postmeta.meta_value
116
  from $wpdb->posts
117
- inner join $wpdb->postmeta on $wpdb->posts.ID = $wpdb->postmeta.post_id and $wpdb->postmeta.meta_key = %s",
118
  array('resmushed_cumulated_optimized_sizes')
119
  );
120
  $optimized_sizes = $wpdb->get_results($query);
@@ -124,18 +180,26 @@ Class reSmushit {
124
  }
125
 
126
 
127
- $output['total_original_size'] = $total_original_size;
128
- $output['total_optimized_size'] = $total_optimized_size;
129
- $output['total_saved_size'] = $total_original_size - $total_optimized_size;
 
 
 
 
130
  if($total_original_size == 0)
131
- $output['percent_reduction'] = 0;
132
  else
133
- $output['percent_reduction'] = 100*round(($total_original_size - $total_optimized_size)/$total_original_size,4) . ' %';
134
  //number of thumbnails + original picture
135
- $output['files_optimized'] = sizeof($optimized_sizes) * (sizeof(get_intermediate_image_sizes()) + 1);
136
- $output['total_optimizations'] = get_option('resmushit_total_optimized');
137
- $output['total_pictures'] = self::getCountAllPictures() * (sizeof(get_intermediate_image_sizes()) + 1);
138
 
 
 
 
 
 
139
  return $output;
140
  }
141
 
@@ -186,6 +250,7 @@ Class reSmushit {
186
  $tmp = array();
187
  $unsmushed_images = array();
188
  $already_optimized_images_array = array();
 
189
 
190
  $queryAllPictures = $wpdb->prepare(
191
  "select
@@ -206,19 +271,33 @@ Class reSmushit {
206
  from $wpdb->posts
207
  inner join $wpdb->postmeta on $wpdb->posts.ID = $wpdb->postmeta.post_id and $wpdb->postmeta.meta_key = %s
208
  where $wpdb->postmeta.meta_value = %s",
209
- array('resmushed_quality', self::getPictureQuality())
 
 
 
 
 
 
 
 
210
  );
 
 
211
 
212
  // Get the images in the attachement table
213
  $all_images = $wpdb->get_results($queryAllPictures);
214
  $already_optimized_images = $wpdb->get_results($queryAlreadyOptimizedPictures);
 
215
 
216
  foreach($already_optimized_images as $image)
217
  $already_optimized_images_array[] = $image->ID;
 
 
 
218
 
219
 
220
  foreach($all_images as $image){
221
- if(!in_array($image->ID, $already_optimized_images_array)){
222
  $tmp = array();
223
  $tmp['ID'] = $image->ID;
224
  $tmp['attachment_metadata'] = unserialize($image->file_meta);
@@ -239,6 +318,58 @@ Class reSmushit {
239
  */
240
  public static function getCountNonOptimizedPictures(){
241
  $data = json_decode(self::getNonOptimizedPictures());
242
- return sizeof($data) * (sizeof(get_intermediate_image_sizes()) + 1);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
243
  }
244
  }
19
  * @param string $file_path the path to the file on the server
20
  * @return bool TRUE if the resmush operation worked
21
  */
22
+ public static function getPictureQualitySetting() {
23
  if(get_option( 'resmushit_qlty' ))
24
  return get_option( 'resmushit_qlty' );
25
  else
55
  );
56
  }
57
 
58
+ $arg['qlty'] = self::getPictureQualitySetting();
59
  curl_setopt($ch, CURLOPT_POSTFIELDS, $arg);
60
 
61
  $data = curl_exec($ch);
86
 
87
 
88
 
89
+
90
+ /**
91
+ *
92
+ * Revert original file and regenerates attachment thumbnails
93
+ *
94
+ * @param int $attachment_id ID of the attachment to revert
95
+ * @return none
96
+ */
97
+ public static function revert($id) {
98
+ global $wp_version;
99
+ global $attachment_id;
100
+ $attachment_id = $id;
101
+
102
+ delete_post_meta($attachment_id, 'resmushed_quality');
103
+ delete_post_meta($attachment_id, 'resmushed_cumulated_original_sizes');
104
+ delete_post_meta($attachment_id, 'resmushed_cumulated_optimized_sizes');
105
+
106
+ $basepath = dirname(get_attached_file( $attachment_id )) . '/';
107
+ $fileInfo = pathinfo(get_attached_file( $attachment_id ));
108
+
109
+ $originalFile = $basepath . $fileInfo['filename'] . '-unsmushed.' . $fileInfo['extension'];
110
+ rlog('Revert original image for : ' . get_attached_file( $attachment_id ));
111
+
112
+ if(file_exists($originalFile))
113
+ copy($originalFile, get_attached_file( $attachment_id ));
114
+
115
+ //Regenerate thumbnails
116
+ wp_generate_attachment_metadata($attachment_id, get_attached_file( $attachment_id ));
117
+ }
118
+
119
+
120
+
121
+
122
+
123
+
124
+ /**
125
+ *
126
+ * Delete Original file (-unsmushed)
127
+ *
128
+ * @param int $attachment_id ID of the attachment
129
+ * @return none
130
+ */
131
+ public static function deleteOriginalFile($attachment_id) {
132
+ $basepath = dirname(get_attached_file( $attachment_id )) . '/';
133
+ $fileInfo = pathinfo(get_attached_file( $attachment_id ));
134
+
135
+ $originalFile = $basepath . $fileInfo['filename'] . '-unsmushed.' . $fileInfo['extension'];
136
+ rlog('Delete original image for : ' . get_attached_file( $attachment_id ));
137
+ if(file_exists($originalFile))
138
+ unlink($originalFile);
139
+ }
140
+
141
+
142
  /**
143
  *
144
  * Return optimization statistics
145
  *
146
+ * @param int $attachment_id (optional)
147
  * @return array of statistics
148
  */
149
+ public static function getStatistics($attachment_id = null){
150
  global $wpdb;
151
  $output = array();
152
+ $extraSQL = null;
153
+ if($attachment_id)
154
+ $extraSQL = "where $wpdb->postmeta.post_id = ". $attachment_id;
155
 
156
  $query = $wpdb->prepare(
157
  "select
158
  $wpdb->posts.ID as ID, $wpdb->postmeta.meta_value
159
  from $wpdb->posts
160
+ inner join $wpdb->postmeta on $wpdb->posts.ID = $wpdb->postmeta.post_id and $wpdb->postmeta.meta_key = %s $extraSQL",
161
  array('resmushed_cumulated_original_sizes')
162
  );
163
  $original_sizes = $wpdb->get_results($query);
170
  "select
171
  $wpdb->posts.ID as ID, $wpdb->postmeta.meta_value
172
  from $wpdb->posts
173
+ inner join $wpdb->postmeta on $wpdb->posts.ID = $wpdb->postmeta.post_id and $wpdb->postmeta.meta_key = %s $extraSQL",
174
  array('resmushed_cumulated_optimized_sizes')
175
  );
176
  $optimized_sizes = $wpdb->get_results($query);
180
  }
181
 
182
 
183
+ $output['total_original_size'] = $total_original_size;
184
+ $output['total_optimized_size'] = $total_optimized_size;
185
+ $output['total_saved_size'] = $total_original_size - $total_optimized_size;
186
+
187
+ $output['total_original_size_nice'] = reSmushitUI::sizeFormat($total_original_size);
188
+ $output['total_optimized_size_nice'] = reSmushitUI::sizeFormat($total_optimized_size);
189
+ $output['total_saved_size_nice'] = reSmushitUI::sizeFormat($total_original_size - $total_optimized_size);
190
  if($total_original_size == 0)
191
+ $output['percent_reduction'] = 0;
192
  else
193
+ $output['percent_reduction'] = 100*round(($total_original_size - $total_optimized_size)/$total_original_size,4) . ' %';
194
  //number of thumbnails + original picture
195
+ $output['files_optimized'] = sizeof($optimized_sizes);
196
+ $output['files_optimized_with_thumbnails'] = sizeof($optimized_sizes) * (sizeof(get_intermediate_image_sizes()) + 1);
 
197
 
198
+ if(!$attachment_id){
199
+ $output['total_optimizations'] = get_option('resmushit_total_optimized');
200
+ $output['total_pictures'] = self::getCountAllPictures();
201
+ $output['total_pictures_with_thumbnails'] = self::getCountAllPictures() * (sizeof(get_intermediate_image_sizes()) + 1);
202
+ }
203
  return $output;
204
  }
205
 
250
  $tmp = array();
251
  $unsmushed_images = array();
252
  $already_optimized_images_array = array();
253
+ $disabled_images_array = array();
254
 
255
  $queryAllPictures = $wpdb->prepare(
256
  "select
271
  from $wpdb->posts
272
  inner join $wpdb->postmeta on $wpdb->posts.ID = $wpdb->postmeta.post_id and $wpdb->postmeta.meta_key = %s
273
  where $wpdb->postmeta.meta_value = %s",
274
+ array('resmushed_quality', self::getPictureQualitySetting())
275
+ );
276
+
277
+ $queryDisabledPictures = $wpdb->prepare(
278
+ "select
279
+ $wpdb->posts.ID as ID
280
+ from $wpdb->posts
281
+ inner join $wpdb->postmeta on $wpdb->posts.ID = $wpdb->postmeta.post_id and $wpdb->postmeta.meta_key = %s",
282
+ array('resmushed_disabled')
283
  );
284
+
285
+
286
 
287
  // Get the images in the attachement table
288
  $all_images = $wpdb->get_results($queryAllPictures);
289
  $already_optimized_images = $wpdb->get_results($queryAlreadyOptimizedPictures);
290
+ $disabled_images = $wpdb->get_results($queryDisabledPictures);
291
 
292
  foreach($already_optimized_images as $image)
293
  $already_optimized_images_array[] = $image->ID;
294
+
295
+ foreach($disabled_images as $image)
296
+ $disabled_images_array[] = $image->ID;
297
 
298
 
299
  foreach($all_images as $image){
300
+ if(!in_array($image->ID, $already_optimized_images_array) && !in_array($image->ID, $disabled_images_array)){
301
  $tmp = array();
302
  $tmp['ID'] = $image->ID;
303
  $tmp['attachment_metadata'] = unserialize($image->file_meta);
318
  */
319
  public static function getCountNonOptimizedPictures(){
320
  $data = json_decode(self::getNonOptimizedPictures());
321
+ return sizeof($data);
322
+ }
323
+
324
+
325
+ /**
326
+ *
327
+ * Record in DB new status for optimization disabled state
328
+ *
329
+ * @param int $id ID of postID
330
+ * @param string $state state of disable
331
+ * @return none
332
+ */
333
+ public static function updateDisabledState($id, $state){
334
+ //if we do not want this attachment to be resmushed.
335
+ if($state == "true"){
336
+ update_post_meta($id, 'resmushed_disabled', 'disabled');
337
+ self::revert($id);
338
+ return 'true';
339
+ } else {
340
+ delete_post_meta($id, 'resmushed_disabled');
341
+ return 'false';
342
+ }
343
+ }
344
+
345
+
346
+
347
+ /**
348
+ *
349
+ * Get Disabled State
350
+ *
351
+ * @param int $attachment_id Post ID
352
+ * @return boolean true if attachment is disabled
353
+ */
354
+ public static function getDisabledState($attachment_id){
355
+ if(get_post_meta($attachment_id, 'resmushed_disabled'))
356
+ return true;
357
+ return false;
358
+ }
359
+
360
+
361
+
362
+ /**
363
+ *
364
+ * Get Last Quality Factor attached to a picture
365
+ *
366
+ * @param int $attachment_id Post ID
367
+ * @return int quality setting for this attachment
368
+ */
369
+ public static function getAttachmentQuality($attachment_id){
370
+ $attachmentQuality = get_post_meta($attachment_id, 'resmushed_quality');
371
+ if(isset($attachmentQuality[0]))
372
+ return $attachmentQuality[0];
373
+ return null;
374
  }
375
  }
classes/resmushitUI.class.php CHANGED
@@ -87,17 +87,17 @@ Class reSmushitUI {
87
  * @return none
88
  */
89
  public static function settingsPanel() {
90
- self::fullWidthPanelWrapper('Settings', null, 'orange');
91
  ?>
92
  <div class="rsmt-settings">
93
  <form method="post" action="options.php" id="rsmt-options-form">
94
  <?php settings_fields( 'resmushit-settings' ); ?>
95
  <?php do_settings_sections( 'resmushit-settings' ); ?>
96
  <table class="form-table">
97
- <?php self::addSetting("text", "Image quality", "Default value is 92. The quality factor must be between 0 (very week) and 100 (best quality)", "resmushit_qlty") ?>
98
- <?php self::addSetting("checkbox", "Optimize on upload", "All future images uploaded will be automatically optimized", "resmushit_on_upload") ?>
99
- <?php self::addSetting("checkbox", "Enable statistics", "Create statistics about optimized pictures", "resmushit_statistics") ?>
100
- <?php self::addSetting("checkbox", "Enable logs", "Enable file logging (for developers)", "resmushit_logs") ?>
101
  </table>
102
  <?php submit_button(); ?>
103
  </form>
@@ -116,21 +116,21 @@ Class reSmushitUI {
116
  */
117
  public static function bulkPanel() {
118
  $countNonOptimizedPictures = reSmushit::getCountNonOptimizedPictures();
119
- self::fullWidthPanelWrapper('Optimize unsmushed pictures', null, 'blue');
120
  ?>
121
 
122
  <div class="rsmt-bulk">
123
  <div class="non-optimized-wrapper <?php if(!$countNonOptimizedPictures) echo 'disabled' ?>">
124
- <h3 class="icon_message warning">There is currently <em><?php echo $countNonOptimizedPictures; ?> non optimized pictures</em>.</h3>
125
- <p>This action will resmush all pictures which have not been optimized to the good Image Quality Rate.</p>
126
  <p class="submit" id="bulk-resize-examine-button">
127
- <button class="button-primary" onclick="resmushit_bulk_resize('bulk_resize_image_list');">Optimize all pictures</button>
128
  </p>
129
  <div id='bulk_resize_image_list'></div>
130
  </div>
131
 
132
  <div class="optimized-wrapper <?php if($countNonOptimizedPictures) echo 'disabled' ?>">
133
- <h3 class="icon_message ok">Congrats ! All your pictures are correctly optimized</h3>
134
  </div>
135
  </div>
136
  <?php self::fullWidthPanelEndWrapper();
@@ -149,19 +149,20 @@ Class reSmushitUI {
149
  public static function statisticsPanel() {
150
  if(!get_option('resmushit_statistics'))
151
  return false;
152
- self::fullWidthPanelWrapper('Statistics', null, 'green');
153
  ?>
154
 
155
  <div class="rsmt-statistics">
156
  <?php $resmushit_stat = reSmushit::getStatistics();
157
  if($resmushit_stat['files_optimized'] != 0):
158
  ?>
159
- <p><strong>Space saved :</strong> <span id="rsmt-statistics-space-saved"><?php echo self::sizeFormat($resmushit_stat['total_saved_size'])?></span></p>
160
- <p><strong>Total reduction :</strong> <span id="rsmt-statistics-percent-reduction"><?php echo $resmushit_stat['percent_reduction'] ?></span></p>
161
- <p><strong>Images optimized :</strong> <span id="rsmt-statistics-files-optimized"><?php echo $resmushit_stat['files_optimized'] ?></span>/<span id="rsmt-statistics-total-pictures"><?php echo $resmushit_stat['total_pictures'] ?></span></p>
162
- <p><strong>Total images optimized :</strong> <span id="rsmt-statistics-total-optimizations"><?php echo $resmushit_stat['total_optimizations'] ?></span></p>
 
163
  <?php else: ?>
164
- <p>No picture has been optimized yet ! Add pictures to your Wordpress Media Library.</p>
165
  <?php endif; ?>
166
  </div>
167
  <?php self::fullWidthPanelEndWrapper();
@@ -182,7 +183,7 @@ Class reSmushitUI {
182
  <div class="rsmt-news">
183
 
184
  <?php
185
- self::fullWidthPanelWrapper('News', null, 'red');
186
  $ch = curl_init();
187
  curl_setopt($ch, CURLOPT_URL, RESMUSHIT_NEWSFEED);
188
  curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
@@ -211,13 +212,13 @@ Class reSmushitUI {
211
  <?php endforeach; ?>
212
  <?php endif; ?>
213
  <div class="social">
214
- <a class="social-maecia" title="Maecia Agency - Paris France" href="https://www.maecia.com" target="_blank">
215
  <img src="<?php echo RESMUSHIT_BASE_URL ?>images/maecia.png" />
216
  </a>
217
- <a class="social-resmushit" title="Visit resmush.it for more informations" href="https://www.resmush.it" target="_blank">
218
  <img src="<?php echo RESMUSHIT_BASE_URL ?>images/logo.png" />
219
  </a>
220
- <a class="social-twitter" title="Follow reSmush.it on Twitter" href="https://www.twitter.com/resmushit" target="_blank">
221
  <img src="<?php echo RESMUSHIT_BASE_URL ?>images/twitter.png" />
222
  </a>
223
  </div>
@@ -256,6 +257,65 @@ Class reSmushitUI {
256
 
257
 
258
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
259
  /**
260
  *
261
  * Helper to format size in bytes
87
  * @return none
88
  */
89
  public static function settingsPanel() {
90
+ self::fullWidthPanelWrapper(__('Settings', 'resmushit'), null, 'orange');
91
  ?>
92
  <div class="rsmt-settings">
93
  <form method="post" action="options.php" id="rsmt-options-form">
94
  <?php settings_fields( 'resmushit-settings' ); ?>
95
  <?php do_settings_sections( 'resmushit-settings' ); ?>
96
  <table class="form-table">
97
+ <?php self::addSetting("text", __("Image quality", 'resmushit'), __("Default value is 92. The quality factor must be between 0 (very weak) and 100 (best quality)", 'resmushit'), "resmushit_qlty") ?>
98
+ <?php self::addSetting("checkbox", __("Optimize on upload", 'resmushit'), __("All future images uploaded will be automatically optimized", 'resmushit'), "resmushit_on_upload") ?>
99
+ <?php self::addSetting("checkbox", __("Enable statistics", 'resmushit'), __("Generates statistics about optimized pictures", 'resmushit'), "resmushit_statistics") ?>
100
+ <?php self::addSetting("checkbox", __("Enable logs", 'resmushit'), __("Enable file logging (for developers)", 'resmushit'), "resmushit_logs") ?>
101
  </table>
102
  <?php submit_button(); ?>
103
  </form>
116
  */
117
  public static function bulkPanel() {
118
  $countNonOptimizedPictures = reSmushit::getCountNonOptimizedPictures();
119
+ self::fullWidthPanelWrapper(__('Optimize unsmushed pictures', 'resmushit'), null, 'blue');
120
  ?>
121
 
122
  <div class="rsmt-bulk">
123
  <div class="non-optimized-wrapper <?php if(!$countNonOptimizedPictures) echo 'disabled' ?>">
124
+ <h3 class="icon_message warning"><?php _e('There is currently', 'resmushit') ?> <em><?php echo $countNonOptimizedPictures; ?> <?php _e('non optimized pictures', 'resmushit') ?></em>.</h3>
125
+ <p><?php _e('This action will resmush all pictures which have not been optimized to the good Image Quality Rate.', 'resmushit') ?></p>
126
  <p class="submit" id="bulk-resize-examine-button">
127
+ <button class="button-primary" onclick="resmushit_bulk_resize('bulk_resize_image_list');"><?php _e('Optimize all pictures', 'resmushit') ?></button>
128
  </p>
129
  <div id='bulk_resize_image_list'></div>
130
  </div>
131
 
132
  <div class="optimized-wrapper <?php if($countNonOptimizedPictures) echo 'disabled' ?>">
133
+ <h3 class="icon_message ok"><?php _e('Congrats ! All your pictures are correctly optimized', 'resmushit') ?></h3>
134
  </div>
135
  </div>
136
  <?php self::fullWidthPanelEndWrapper();
149
  public static function statisticsPanel() {
150
  if(!get_option('resmushit_statistics'))
151
  return false;
152
+ self::fullWidthPanelWrapper(__('Statistics', 'resmushit'), null, 'green');
153
  ?>
154
 
155
  <div class="rsmt-statistics">
156
  <?php $resmushit_stat = reSmushit::getStatistics();
157
  if($resmushit_stat['files_optimized'] != 0):
158
  ?>
159
+ <p><strong><?php _e('Space saved :', 'resmushit') ?></strong> <span id="rsmt-statistics-space-saved"><?php echo self::sizeFormat($resmushit_stat['total_saved_size'])?></span></p>
160
+ <p><strong><?php _e('Total reduction :', 'resmushit') ?></strong> <span id="rsmt-statistics-percent-reduction"><?php echo $resmushit_stat['percent_reduction'] ?></span></p>
161
+ <p><strong><?php _e('Attachments optimized :', 'resmushit') ?></strong> <span id="rsmt-statistics-files-optimized"><?php echo $resmushit_stat['files_optimized'] ?></span>/<span id="rsmt-statistics-total-pictures"><?php echo $resmushit_stat['total_pictures'] ?></span></p>
162
+ <p><strong><?php _e('Image optimized (including thumbnails) :', 'resmushit') ?></strong> <span id="rsmt-statistics-files-optimized"><?php echo $resmushit_stat['files_optimized_with_thumbnails'] ?></span>/<span id="rsmt-statistics-total-pictures"><?php echo $resmushit_stat['total_pictures_with_thumbnails'] ?></span></p>
163
+ <p><strong><?php _e('Total images optimized :', 'resmushit') ?></strong> <span id="rsmt-statistics-total-optimizations"><?php echo $resmushit_stat['total_optimizations'] ?></span></p>
164
  <?php else: ?>
165
+ <p><?php _e('No picture has been optimized yet ! Add pictures to your Wordpress Media Library.', 'resmushit') ?></p>
166
  <?php endif; ?>
167
  </div>
168
  <?php self::fullWidthPanelEndWrapper();
183
  <div class="rsmt-news">
184
 
185
  <?php
186
+ self::fullWidthPanelWrapper(__('News', 'resmushit'), null, 'red');
187
  $ch = curl_init();
188
  curl_setopt($ch, CURLOPT_URL, RESMUSHIT_NEWSFEED);
189
  curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
212
  <?php endforeach; ?>
213
  <?php endif; ?>
214
  <div class="social">
215
+ <a class="social-maecia" title="<?php _e('Maecia Agency - Paris France', 'resmushit') ?>" href="https://www.maecia.com" target="_blank">
216
  <img src="<?php echo RESMUSHIT_BASE_URL ?>images/maecia.png" />
217
  </a>
218
+ <a class="social-resmushit" title="<?php _e('Visit resmush.it for more informations', 'resmushit') ?>" href="https://www.resmush.it" target="_blank">
219
  <img src="<?php echo RESMUSHIT_BASE_URL ?>images/logo.png" />
220
  </a>
221
+ <a class="social-twitter" title="<?php _e('Follow reSmush.it on Twitter', 'resmushit') ?>" href="https://www.twitter.com/resmushit" target="_blank">
222
  <img src="<?php echo RESMUSHIT_BASE_URL ?>images/twitter.png" />
223
  </a>
224
  </div>
257
 
258
 
259
 
260
+
261
+
262
+ /**
263
+ *
264
+ * Generate checkbox "disabled" on media list
265
+ *
266
+ * @param int $id Post ID associated to postmetas
267
+ * @return none
268
+ */
269
+ public static function mediaListCustomValuesDisable($id, $return = false) {
270
+ global $wpdb;
271
+ $query = $wpdb->prepare(
272
+ "select
273
+ $wpdb->posts.ID as ID, $wpdb->postmeta.meta_value
274
+ from $wpdb->posts
275
+ inner join $wpdb->postmeta on $wpdb->posts.ID = $wpdb->postmeta.post_id and $wpdb->postmeta.meta_key = %s and $wpdb->postmeta.post_id = %s",
276
+ array('resmushed_disabled', $id)
277
+ );
278
+ $attachment_resmushit_disabled = null;
279
+ if($wpdb->get_results($query))
280
+ $attachment_resmushit_disabled = 'checked';
281
+
282
+ $output = '<input type="checkbox" data-attachment-id="'. $id .'"" class="rsmt-trigger--disabled-checkbox" '. $attachment_resmushit_disabled .' />';
283
+
284
+ if($return)
285
+ return $output;
286
+ echo $output;
287
+ }
288
+
289
+
290
+
291
+
292
+
293
+ /**
294
+ *
295
+ * Generate status info OR button on media list
296
+ *
297
+ * @param int $attachment_id Post ID associated to postmetas
298
+ * @return none
299
+ */
300
+ public static function mediaListCustomValuesStatus($attachment_id, $return = false) {
301
+ if(reSmushit::getDisabledState($attachment_id)){
302
+ $output = '-';
303
+ }
304
+ else if(reSmushit::getAttachmentQuality($attachment_id) != reSmushit::getPictureQualitySetting())
305
+ $output = '<input type="button" value="'. __('Optimize', 'resmushit') .'" class="rsmt-trigger--optimize-attachment button media-button select-mode-toggle-button" name="resmushit" data-attachment-id="'. $attachment_id .'" class="button wp-smush-send" />';
306
+ else{
307
+ $statistics = reSmushit::getStatistics($attachment_id);
308
+ $output = __('Reduced by', 'resmushit') . " ". $statistics['total_saved_size_nice'] ." (". $statistics['percent_reduction'] . ' ' . __('saved', 'resmushit') . ")";
309
+ }
310
+
311
+ if($return)
312
+ return $output;
313
+ echo $output;
314
+ }
315
+
316
+
317
+
318
+
319
  /**
320
  *
321
  * Helper to format size in bytes
css/resmushit.css CHANGED
@@ -197,7 +197,17 @@
197
  opacity: 0.8;
198
  }
199
 
200
-
 
 
 
 
 
 
 
 
 
 
201
 
202
 
203
  @media screen and (max-width: 1100px) {
197
  opacity: 0.8;
198
  }
199
 
200
+ input[type=radio], input[type=checkbox].rsmt-disable-loader{
201
+ border:none;
202
+ height: 16px;
203
+ width: 16px;
204
+ display: inline-block;
205
+ background-image: url(../images/loading.gif);
206
+ background-repeat: no-repeat;
207
+ }
208
+ input[type=radio], input[type=checkbox].rsmt-disable-loader:checked:before{
209
+ content: "";
210
+ }
211
 
212
 
213
  @media screen and (max-width: 1100px) {
images/loading.gif ADDED
Binary file
js/script.js CHANGED
@@ -19,6 +19,8 @@ jQuery("#rsmt-options-form").submit(function(){
19
  }
20
  });
21
 
 
 
22
 
23
 
24
 
@@ -40,12 +42,11 @@ function resmushit_bulk_process(bulk, item){
40
  flag_removed = true;
41
  }
42
 
43
- var results_target = jQuery('#smush_results');
44
  bulkCounter++;
45
  jQuery('.resmushit--progress--bar').html('<p>'+ Math.round((bulkCounter*100/bulkTotalimages)) +'%</p>');
46
  jQuery('.resmushit--progress--bar').animate({'width': Math.round((bulkCounter*100/bulkTotalimages))+'%'}, 0);
47
 
48
- if(item < bulk.length)
49
  resmushit_bulk_process(bulk, item + 1);
50
  else{
51
  jQuery('.non-optimized-wrapper').addClass('disabled');
@@ -110,4 +111,71 @@ function updateStatistics() {
110
  jQuery('#rsmt-statistics-total-optimizations').text(statistics.total_optimizations);
111
  }
112
  );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
113
  }
19
  }
20
  });
21
 
22
+ updateDisabledState();
23
+ optimizeSingleAttachment();
24
 
25
 
26
 
42
  flag_removed = true;
43
  }
44
 
 
45
  bulkCounter++;
46
  jQuery('.resmushit--progress--bar').html('<p>'+ Math.round((bulkCounter*100/bulkTotalimages)) +'%</p>');
47
  jQuery('.resmushit--progress--bar').animate({'width': Math.round((bulkCounter*100/bulkTotalimages))+'%'}, 0);
48
 
49
+ if(item < bulk.length - 1)
50
  resmushit_bulk_process(bulk, item + 1);
51
  else{
52
  jQuery('.non-optimized-wrapper').addClass('disabled');
111
  jQuery('#rsmt-statistics-total-optimizations').text(statistics.total_optimizations);
112
  }
113
  );
114
+ }
115
+
116
+
117
+ /**
118
+ * ajax post to disabled status (or remove)
119
+ */
120
+ function updateDisabledState() {
121
+ jQuery('.rsmt-trigger--disabled-checkbox').change(function(){
122
+ var current = this;
123
+ jQuery(current).addClass('rsmt-disable-loader');
124
+ jQuery(current).prop('disabled', true);
125
+ var disabledState = jQuery(current).is(':checked');
126
+ var postID = jQuery(current).attr('data-attachment-id');
127
+
128
+ jQuery.post(
129
+ ajaxurl, {
130
+ action: 'resmushit_update_disabled_state',
131
+ data: {id: postID, disabled: disabledState}
132
+ },
133
+ function(response) {
134
+ jQuery(current).removeClass('rsmt-disable-loader');
135
+ jQuery(current).prop('disabled', false);
136
+
137
+ if(jQuery(current).parent().hasClass('field')){
138
+ var selector = jQuery(current).parent().parent().next('tr').find('td.field');
139
+ } else {
140
+ var selector = jQuery(current).parent().next('td');
141
+ }
142
+
143
+ if(disabledState == true){
144
+ selector.empty().append('-');
145
+ } else {
146
+ selector.empty().append('<input type="button" value="Optimize" class="rsmt-trigger--optimize-attachment button media-button select-mode-toggle-button" name="resmushit" data-attachment-id="' + postID + '" class="button wp-smush-send" />');
147
+ }
148
+ optimizeSingleAttachment();
149
+ }
150
+ );
151
+ });
152
+ }
153
+
154
+
155
+
156
+ /**
157
+ * ajax to Optimize a single picture
158
+ */
159
+ function optimizeSingleAttachment() {
160
+ jQuery('.rsmt-trigger--optimize-attachment').each(function(){
161
+ jQuery(this).on('mouseup', function(e){
162
+ var current = this;
163
+ jQuery(current).val('Optimizing...');
164
+ jQuery(current).prop('disabled', true);
165
+ var disabledState = jQuery(current).is(':checked');
166
+ var postID = jQuery(current).attr('data-attachment-id');
167
+ jQuery.post(
168
+ ajaxurl, {
169
+ action: 'resmushit_optimize_single_attachment',
170
+ data: {id: postID}
171
+ },
172
+ function(response) {
173
+ var statistics = jQuery.parseJSON(response);
174
+ jQuery(current).parent().empty().append('Reduced by ' + statistics.total_saved_size_nice + ' (' + statistics.percent_reduction + ' saved)');
175
+ }
176
+ );
177
+
178
+ e.preventDefault();
179
+ });
180
+ });
181
  }
languages/resmushit-fr_FR.mo ADDED
Binary file
languages/resmushit-fr_FR.po ADDED
@@ -0,0 +1,157 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # SOME DESCRIPTIVE TITLE.
2
+ # Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER
3
+ # This file is distributed under the same license as the PACKAGE package.
4
+ # FIRST AUTHOR <EMAIL@ADDRESS>, YEAR.
5
+ #
6
+ 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-08 17:00+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"
23
+ msgstr "Désactiver l'optimisation reSmush.it"
24
+
25
+ #: resmushit.admin.php:38 resmushit.admin.php:71
26
+ msgid "reSmush.it status"
27
+ msgstr "Statut de reSmush.it"
28
+
29
+ #: classes/resmushitUI.class.php:90
30
+ msgid "Settings"
31
+ msgstr "Paramêtres"
32
+
33
+ #: classes/resmushitUI.class.php:97
34
+ msgid "Image quality"
35
+ msgstr "Qualité d’image"
36
+
37
+ #: classes/resmushitUI.class.php:97
38
+ msgid ""
39
+ "Default value is 92. The quality factor must be between 0 (very weak) and "
40
+ "100 (best quality)"
41
+ msgstr ""
42
+ "La valeur par défaut est de 92. Le facteur de qualité doit être comprise "
43
+ "entre 0 (mauvaise) et 100 (meilleure qualité)"
44
+
45
+ #: classes/resmushitUI.class.php:98
46
+ msgid "Optimize on upload"
47
+ msgstr "Optimiser à l'upload"
48
+
49
+ #: classes/resmushitUI.class.php:98
50
+ msgid "All future images uploaded will be automatically optimized"
51
+ msgstr ""
52
+ "Toutes les futures images téléchargées seront automatiquement optimisées"
53
+
54
+ #: classes/resmushitUI.class.php:99
55
+ msgid "Enable statistics"
56
+ 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"
65
+ msgstr "Activer les journaux"
66
+
67
+ #: classes/resmushitUI.class.php:100
68
+ msgid "Enable file logging (for developers)"
69
+ 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"
77
+ msgstr "Il y a actuellement"
78
+
79
+ #: classes/resmushitUI.class.php:124
80
+ msgid "non optimized pictures"
81
+ msgstr "images non optimisées"
82
+
83
+ #: classes/resmushitUI.class.php:125
84
+ msgid ""
85
+ "This action will resmush all pictures which have not been optimized to the "
86
+ "good Image Quality Rate."
87
+ msgstr ""
88
+ "Cette action va optimiser toutes les images qui ne l'ont pas été avec le "
89
+ "nouveau facteur de qualité."
90
+
91
+ #: classes/resmushitUI.class.php:127
92
+ msgid "Optimize all pictures"
93
+ msgstr "Optimiser toutes les images"
94
+
95
+ #: classes/resmushitUI.class.php:133
96
+ msgid "Congrats ! All your pictures are correctly optimized"
97
+ msgstr "Félicitations ! Toutes les images ont été correctement optimisées"
98
+
99
+ #: classes/resmushitUI.class.php:152
100
+ msgid "Statistics"
101
+ msgstr "Statistiques"
102
+
103
+ #: classes/resmushitUI.class.php:159
104
+ msgid "Space saved :"
105
+ msgstr "Poids gagné"
106
+
107
+ #: classes/resmushitUI.class.php:160
108
+ msgid "Total reduction :"
109
+ msgstr "Total réduit"
110
+
111
+ #: classes/resmushitUI.class.php:161
112
+ msgid "Attachments optimized :"
113
+ msgstr "Nombre d'attachements optimisés"
114
+
115
+ #: classes/resmushitUI.class.php:162
116
+ msgid "Image optimized (including thumbnails) :"
117
+ msgstr "Images optimisées (incluant les vignettes)"
118
+
119
+ #: classes/resmushitUI.class.php:163
120
+ msgid "Total images optimized :"
121
+ msgstr "Nombre total de fichiers optimisés"
122
+
123
+ #: classes/resmushitUI.class.php:165
124
+ msgid ""
125
+ "No picture has been optimized yet ! Add pictures to your Wordpress Media "
126
+ "Library."
127
+ msgstr ""
128
+ "Aucune image n'a été optimisée pour le moment ! Ajoutez des images à votre "
129
+ "médiathèque Wordpress."
130
+
131
+ #: classes/resmushitUI.class.php:186
132
+ msgid "News"
133
+ msgstr "Actualités"
134
+
135
+ #: classes/resmushitUI.class.php:215
136
+ msgid "Maecia Agency - Paris France"
137
+ msgstr "Agence Maecia - Paris, France"
138
+
139
+ #: classes/resmushitUI.class.php:218
140
+ msgid "Visit resmush.it for more informations"
141
+ msgstr "Visitez resmush.it pour plus d'informations"
142
+
143
+ #: classes/resmushitUI.class.php:221
144
+ msgid "Follow reSmush.it on Twitter"
145
+ msgstr "Suivez reSmush.it sur Twitter"
146
+
147
+ #: classes/resmushitUI.class.php:305
148
+ msgid "Optimize"
149
+ msgstr "Optimiser"
150
+
151
+ #: classes/resmushitUI.class.php:308
152
+ msgid "Reduced by"
153
+ msgstr "Réduction de"
154
+
155
+ #: classes/resmushitUI.class.php:308
156
+ msgid "saved"
157
+ msgstr "gagné"
languages/resmushit.pot ADDED
@@ -0,0 +1,148 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # SOME DESCRIPTIVE TITLE.
2
+ # Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER
3
+ # This file is distributed under the same license as the PACKAGE package.
4
+ # FIRST AUTHOR <EMAIL@ADDRESS>, YEAR.
5
+ #
6
+ #, fuzzy
7
+ msgid ""
8
+ msgstr ""
9
+ "Project-Id-Version: PACKAGE VERSION\n"
10
+ "Report-Msgid-Bugs-To: \n"
11
+ "POT-Creation-Date: 2016-08-08 16:26+0200\n"
12
+ "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
13
+ "Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
14
+ "Language-Team: LANGUAGE <LL@li.org>\n"
15
+ "Language: \n"
16
+ "MIME-Version: 1.0\n"
17
+ "Content-Type: text/plain; charset=CHARSET\n"
18
+ "Content-Transfer-Encoding: 8bit\n"
19
+
20
+ #: resmushit.admin.php:37 resmushit.admin.php:64
21
+ msgid "Disable of reSmush.it"
22
+ msgstr ""
23
+
24
+ #: resmushit.admin.php:38 resmushit.admin.php:71
25
+ msgid "reSmush.it status"
26
+ msgstr ""
27
+
28
+ #: classes/resmushitUI.class.php:90
29
+ msgid "Settings"
30
+ msgstr ""
31
+
32
+ #: classes/resmushitUI.class.php:97
33
+ msgid "Image quality"
34
+ msgstr ""
35
+
36
+ #: classes/resmushitUI.class.php:97
37
+ msgid ""
38
+ "Default value is 92. The quality factor must be between 0 (very weak) and "
39
+ "100 (best quality)"
40
+ msgstr ""
41
+
42
+ #: classes/resmushitUI.class.php:98
43
+ msgid "Optimize on upload"
44
+ msgstr ""
45
+
46
+ #: classes/resmushitUI.class.php:98
47
+ msgid "All future images uploaded will be automatically optimized"
48
+ msgstr ""
49
+
50
+ #: classes/resmushitUI.class.php:99
51
+ msgid "Enable statistics"
52
+ msgstr ""
53
+
54
+ #: classes/resmushitUI.class.php:99
55
+ msgid "Generates statistics about optimized pictures"
56
+ msgstr ""
57
+
58
+ #: classes/resmushitUI.class.php:100
59
+ msgid "Enable logs"
60
+ msgstr ""
61
+
62
+ #: classes/resmushitUI.class.php:100
63
+ msgid "Enable file logging (for developers)"
64
+ msgstr ""
65
+
66
+ #: classes/resmushitUI.class.php:119
67
+ msgid "Optimize unsmushed pictures"
68
+ msgstr ""
69
+
70
+ #: classes/resmushitUI.class.php:124
71
+ msgid "There is currently"
72
+ msgstr ""
73
+
74
+ #: classes/resmushitUI.class.php:124
75
+ msgid "non optimized pictures"
76
+ msgstr ""
77
+
78
+ #: classes/resmushitUI.class.php:125
79
+ msgid ""
80
+ "This action will resmush all pictures which have not been optimized to the "
81
+ "good Image Quality Rate."
82
+ msgstr ""
83
+
84
+ #: classes/resmushitUI.class.php:127
85
+ msgid "Optimize all pictures"
86
+ msgstr ""
87
+
88
+ #: classes/resmushitUI.class.php:133
89
+ msgid "Congrats ! All your pictures are correctly optimized"
90
+ msgstr ""
91
+
92
+ #: classes/resmushitUI.class.php:152
93
+ msgid "Statistics"
94
+ msgstr ""
95
+
96
+ #: classes/resmushitUI.class.php:159
97
+ msgid "Space saved :"
98
+ msgstr ""
99
+
100
+ #: classes/resmushitUI.class.php:160
101
+ msgid "Total reduction :"
102
+ msgstr ""
103
+
104
+ #: classes/resmushitUI.class.php:161
105
+ msgid "Attachments optimized :"
106
+ msgstr ""
107
+
108
+ #: classes/resmushitUI.class.php:162
109
+ msgid "Image optimized (including thumbnails) :"
110
+ msgstr ""
111
+
112
+ #: classes/resmushitUI.class.php:163
113
+ msgid "Total images optimized :"
114
+ msgstr ""
115
+
116
+ #: classes/resmushitUI.class.php:165
117
+ msgid ""
118
+ "No picture has been optimized yet ! Add pictures to your Wordpress Media "
119
+ "Library."
120
+ msgstr ""
121
+
122
+ #: classes/resmushitUI.class.php:186
123
+ msgid "News"
124
+ msgstr ""
125
+
126
+ #: classes/resmushitUI.class.php:215
127
+ msgid "Maecia Agency - Paris France"
128
+ msgstr ""
129
+
130
+ #: classes/resmushitUI.class.php:218
131
+ msgid "Visit resmush.it for more informations"
132
+ msgstr ""
133
+
134
+ #: classes/resmushitUI.class.php:221
135
+ msgid "Follow reSmush.it on Twitter"
136
+ msgstr ""
137
+
138
+ #: classes/resmushitUI.class.php:305
139
+ msgid "Optimize"
140
+ msgstr ""
141
+
142
+ #: classes/resmushitUI.class.php:308
143
+ msgid "Reduced by"
144
+ msgstr ""
145
+
146
+ #: classes/resmushitUI.class.php:308
147
+ msgid "saved"
148
+ msgstr ""
readme.txt CHANGED
@@ -1,9 +1,9 @@
1
  === reSmush.it Image Optimizer ===
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.5.3
6
- Stable tag: 0.1.1
7
  License: GPLv2 or later
8
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
9
 
@@ -37,6 +37,14 @@ Yes ! Absolutely free, the only restriction is to send images below 2MB.
37
 
38
  == Changelog ==
39
 
 
 
 
 
 
 
 
 
40
  = 0.1.1 =
41
  * Optimize on upload
42
  * Statistics
1
  === reSmush.it Image Optimizer ===
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.2
7
  License: GPLv2 or later
8
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
9
 
37
 
38
  == Changelog ==
39
 
40
+ = 0.1.2 =
41
+ * Delete also original file when deleting an attachment
42
+ * Exclusion of an attachment of the reSmush.it optimization (checkboxes)
43
+ * Adding french translation
44
+ * Code optimizations
45
+ * 4.6.x check
46
+ * Minor bugs corrections
47
+
48
  = 0.1.1 =
49
  * Optimize on upload
50
  * Statistics
resmushit.admin.php CHANGED
@@ -33,6 +33,50 @@ add_action( 'admin_init', 'resmushit_settings_declare' );
33
 
34
 
35
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
36
 
37
 
38
  /**
33
 
34
 
35
 
36
+ function resmushit_media_list_add_column( $columns ) {
37
+ $columns["resmushit_disable"] = __('Disable of reSmush.it', 'resmushit');
38
+ $columns["resmushit_status"] = __('reSmush.it status', 'resmushit');
39
+ return $columns;
40
+ }
41
+ add_filter( 'manage_media_columns', 'resmushit_media_list_add_column' );
42
+
43
+
44
+ function resmushit_media_list_sort_column( $columns ) {
45
+ $columns["resmushit_disable"] = "resmushit_disable";
46
+ $columns["resmushit_status"] = "resmushit_status";
47
+ return $columns;
48
+ }
49
+ add_filter( 'manage_upload_sortable_columns', 'resmushit_media_list_sort_column' );
50
+
51
+
52
+ function resmushit_media_list_add_column_value( $column_name, $id ) {
53
+ if ( $column_name == "resmushit_disable" )
54
+ reSmushitUI::mediaListCustomValuesDisable($id);
55
+ else if ( $column_name == "resmushit_status" )
56
+ reSmushitUI::mediaListCustomValuesStatus($id);
57
+ }
58
+ add_action( 'manage_media_custom_column', 'resmushit_media_list_add_column_value', 10, 2 );
59
+
60
+
61
+ /* Add custom field to attachment */
62
+ function resmushit_image_attachment_add_status_button($form_fields, $post) {
63
+ $form_fields["rsmt-disabled-checkbox"] = array(
64
+ "label" => __("Disable of reSmush.it"),
65
+ "input" => "html",
66
+ "value" => '',
67
+ "html" => reSmushitUI::mediaListCustomValuesDisable($post->ID, true)
68
+ );
69
+
70
+ $form_fields["rsmt-status-button"] = array(
71
+ "label" => __("reSmush.it status"),
72
+ "input" => "html",
73
+ "value" => '',
74
+ "html" => reSmushitUI::mediaListCustomValuesStatus($post->ID, true)
75
+ );
76
+ return $form_fields;
77
+ }
78
+ add_filter("attachment_fields_to_edit", "resmushit_image_attachment_add_status_button", null, 2);
79
+
80
 
81
 
82
  /**
resmushit.php CHANGED
@@ -11,14 +11,15 @@
11
  * Plugin Name: reSmush.it Image Optimizer
12
  * Plugin URI: http://www.resmush.it
13
  * Description: Image Optimization API. Provides image size optimization
14
- * Version: 0.1.1
15
- * Timestamp: 2016.05.13
16
  * Author: Maecia
17
  * Author URI: https://www.maecia.com
18
  * Author: Charles Bourgeaux
19
  * Author: Tedj Ferhati
20
  * License: GPL-2.0+
21
  * License URI: http://www.gnu.org/licenses/gpl-2.0.txt
 
22
  */
23
 
24
 
@@ -27,6 +28,23 @@ require('resmushit.inc.php');
27
 
28
 
29
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
30
  /**
31
  *
32
  * Registering settings on plugin installation
@@ -65,6 +83,8 @@ function resmushit_process_images($attachments, $force_keep_original = TRUE) {
65
  $cumulated_original_sizes = 0;
66
  $cumulated_optimized_sizes = 0;
67
 
 
 
68
 
69
  $basepath = dirname(get_attached_file( $attachment_id )) . '/';
70
  $basefile = basename($attachments[ 'file' ]);
@@ -82,11 +102,10 @@ function resmushit_process_images($attachments, $force_keep_original = TRUE) {
82
  $count++;
83
  }
84
  }
85
-
86
  $optimizations_successful_count = get_option('resmushit_total_optimized');
87
  update_option( 'resmushit_total_optimized', $optimizations_successful_count + $count );
88
 
89
- update_post_meta($attachment_id,'resmushed_quality', resmushit::getPictureQuality());
90
  if(get_option('resmushit_statistics')){
91
  update_post_meta($attachment_id,'resmushed_cumulated_original_sizes', $cumulated_original_sizes);
92
  update_post_meta($attachment_id,'resmushed_cumulated_optimized_sizes', $cumulated_optimized_sizes);
@@ -101,6 +120,23 @@ if(get_option('resmushit_on_upload'))
101
 
102
 
103
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
104
  /**
105
  *
106
  * Make current attachment available
@@ -136,32 +172,55 @@ add_action( 'wp_ajax_resmushit_bulk_get_images', 'resmushit_bulk_get_images' );
136
 
137
 
138
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
139
 
140
  /**
141
  *
142
- * add Ajax action to optimize a picture according to attachment ID
143
  *
144
  * @param none
145
- * @return boolean
146
- */
147
- function resmushit_bulk_process_image() {
148
- global $attachment_id;
 
 
 
 
 
 
149
 
150
 
151
- $attachment_id = $_POST['data']['ID'];
152
 
153
- $basepath = dirname(get_attached_file( $attachment_id )) . '/';
154
- $basefile = basename(get_attached_file( $attachment_id ));
155
- $fileInfo = pathinfo(get_attached_file( $attachment_id ));
156
 
157
- $originalFile = $basepath . $fileInfo['filename'] . '-unsmushed.' . $fileInfo['extension'];
158
- rlog('Bulk optimization launched for file : ' . get_attached_file( $attachment_id ));
159
-
160
- if(file_exists($originalFile))
161
- copy($originalFile, get_attached_file( $attachment_id ));
162
-
163
- //Regenerate thumbnails
164
- wp_generate_attachment_metadata($attachment_id, get_attached_file( $attachment_id ));
 
 
 
165
  die();
166
  }
167
  add_action( 'wp_ajax_resmushit_bulk_process_image', 'resmushit_bulk_process_image' );
11
  * Plugin Name: reSmush.it Image Optimizer
12
  * Plugin URI: http://www.resmush.it
13
  * Description: Image Optimization API. Provides image size optimization
14
+ * Version: 0.1.2
15
+ * Timestamp: 2016.08.08
16
  * Author: Maecia
17
  * Author URI: https://www.maecia.com
18
  * Author: Charles Bourgeaux
19
  * Author: Tedj Ferhati
20
  * License: GPL-2.0+
21
  * License URI: http://www.gnu.org/licenses/gpl-2.0.txt
22
+ * Domain Path: /languages
23
  */
24
 
25
 
28
 
29
 
30
 
31
+
32
+ /**
33
+ *
34
+ * Registering language plugin
35
+ *
36
+ * @param none
37
+ * @return none
38
+ */
39
+ function resmushit_load_plugin_textdomain() {
40
+ load_plugin_textdomain( 'resmushit', FALSE, plugin_basename( dirname( __FILE__ ) ) . '/languages' );
41
+ }
42
+ add_action( 'plugins_loaded', 'resmushit_load_plugin_textdomain' );
43
+
44
+
45
+
46
+
47
+
48
  /**
49
  *
50
  * Registering settings on plugin installation
83
  $cumulated_original_sizes = 0;
84
  $cumulated_optimized_sizes = 0;
85
 
86
+ if(reSmushit::getDisabledState($attachment_id))
87
+ return $attachments;
88
 
89
  $basepath = dirname(get_attached_file( $attachment_id )) . '/';
90
  $basefile = basename($attachments[ 'file' ]);
102
  $count++;
103
  }
104
  }
 
105
  $optimizations_successful_count = get_option('resmushit_total_optimized');
106
  update_option( 'resmushit_total_optimized', $optimizations_successful_count + $count );
107
 
108
+ update_post_meta($attachment_id,'resmushed_quality', resmushit::getPictureQualitySetting());
109
  if(get_option('resmushit_statistics')){
110
  update_post_meta($attachment_id,'resmushed_cumulated_original_sizes', $cumulated_original_sizes);
111
  update_post_meta($attachment_id,'resmushed_cumulated_optimized_sizes', $cumulated_optimized_sizes);
120
 
121
 
122
 
123
+
124
+ /**
125
+ *
126
+ * Delete also -unsmushed file (ie. Original file) when deleting an attachment
127
+ *
128
+ * @param int postID
129
+ * @return none
130
+ */
131
+ function resmushit_delete_attachment($postid) {
132
+ reSmushit::deleteOriginalFile($postid);
133
+ }
134
+ add_action( 'delete_attachment', 'resmushit_delete_attachment' );
135
+
136
+
137
+
138
+
139
+
140
  /**
141
  *
142
  * Make current attachment available
172
 
173
 
174
 
175
+ /**
176
+ *
177
+ * add Ajax action to change disabled state for an attachment
178
+ *
179
+ * @param none
180
+ * @return json object
181
+ */
182
+ function resmushit_update_disabled_state() {
183
+ if(isset($_POST['data']['id']) && $_POST['data']['id'] != null && isset($_POST['data']['disabled'])){
184
+ echo reSmushit::updateDisabledState(sanitize_text_field($_POST['data']['id']), sanitize_text_field($_POST['data']['disabled']));
185
+ }
186
+ die();
187
+ }
188
+ add_action( 'wp_ajax_resmushit_update_disabled_state', 'resmushit_update_disabled_state' );
189
+
190
+
191
+
192
+
193
 
194
  /**
195
  *
196
+ * add Ajax action to optimize a single attachment in the library
197
  *
198
  * @param none
199
+ * @return json object
200
+ */
201
+ function resmushit_optimize_single_attachment() {
202
+ if(isset($_POST['data']['id']) && $_POST['data']['id'] != null){
203
+ reSmushit::revert(sanitize_text_field($_POST['data']['id']));
204
+ echo json_encode(reSmushit::getStatistics($_POST['data']['id']));
205
+ }
206
+ die();
207
+ }
208
+ add_action( 'wp_ajax_resmushit_optimize_single_attachment', 'resmushit_optimize_single_attachment' );
209
 
210
 
 
211
 
 
 
 
212
 
213
+
214
+ /**
215
+ *
216
+ * add Ajax action to optimize a picture according to attachment ID
217
+ *
218
+ * @param none
219
+ * @return boolean
220
+ */
221
+ function resmushit_bulk_process_image() {
222
+ rlog('Bulk optimization launched for file : ' . get_attached_file( sanitize_text_field($_POST['data']['ID']) ));
223
+ reSmushit::revert(sanitize_text_field($_POST['data']['ID']));
224
  die();
225
  }
226
  add_action( 'wp_ajax_resmushit_bulk_process_image', 'resmushit_bulk_process_image' );
resmushit.settings.php CHANGED
@@ -2,7 +2,7 @@
2
 
3
 
4
  define('RESMUSHIT_ENDPOINT', 'http://api.resmush.it/');
5
- define('RESMUSHIT_VERSION', '0.1.1');
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.2');
6
  define('RESMUSHIT_DEFAULT_QLTY', '92');
7
  define('RESMUSHIT_TIMEOUT', '5');
8
  define('RESMUSHIT_LOGS_PATH', 'resmushit.log');