reSmush.it Image Optimizer - Version 0.4.0

Version Description

  • New option to restore all original pictures
Download this release

Release Info

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

Code changes from version 0.3.12 to 0.4.0

classes/resmushit.class.php CHANGED
@@ -126,7 +126,7 @@ Class reSmushit {
126
  * @param int $attachment_id ID of the attachment to revert
127
  * @return none
128
  */
129
- public static function revert($id) {
130
  global $wp_version;
131
  global $attachment_id;
132
  $attachment_id = $id;
@@ -141,12 +141,15 @@ Class reSmushit {
141
  $originalFile = $basepath . $fileInfo['filename'] . '-unsmushed.' . $fileInfo['extension'];
142
  rlog('Revert original image for : ' . str_replace(ABSPATH, '/', get_attached_file( $attachment_id )));
143
 
144
- if(file_exists($originalFile))
145
  copy($originalFile, get_attached_file( $attachment_id ));
 
146
 
147
  //Regenerate thumbnails
148
- wp_generate_attachment_metadata($attachment_id, get_attached_file( $attachment_id ));
149
-
 
 
150
  return self::wasSuccessfullyUpdated( $attachment_id );
151
  }
152
 
126
  * @param int $attachment_id ID of the attachment to revert
127
  * @return none
128
  */
129
+ public static function revert($id, $generateThumbnails = true) {
130
  global $wp_version;
131
  global $attachment_id;
132
  $attachment_id = $id;
141
  $originalFile = $basepath . $fileInfo['filename'] . '-unsmushed.' . $fileInfo['extension'];
142
  rlog('Revert original image for : ' . str_replace(ABSPATH, '/', get_attached_file( $attachment_id )));
143
 
144
+ if(file_exists($originalFile)) {
145
  copy($originalFile, get_attached_file( $attachment_id ));
146
+ }
147
 
148
  //Regenerate thumbnails
149
+ if($generateThumbnails) {
150
+ wp_generate_attachment_metadata($attachment_id, get_attached_file( $attachment_id ));
151
+ }
152
+
153
  return self::wasSuccessfullyUpdated( $attachment_id );
154
  }
155
 
classes/resmushitUI.class.php CHANGED
@@ -265,6 +265,29 @@ Class reSmushitUI {
265
  }
266
 
267
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
268
 
269
  /**
270
  *
265
  }
266
 
267
 
268
+ /**
269
+ *
270
+ * Generate Statistics panel
271
+ *
272
+ * @param none
273
+ * @return none
274
+ */
275
+ public static function restorePanel() {
276
+ if(get_option('resmushit_remove_unsmushed') == 1 ){
277
+ return FALSE;
278
+ }
279
+ self::fullWidthPanelWrapper(__('Restore Media Library', 'resmushit-image-optimizer'), null, 'black');
280
+
281
+ echo "<div class='rsmt-restore'>";
282
+
283
+ echo
284
+ '<p><strong>'
285
+ . __('Warning! By clicking the button below, you will restore all the original pictures, as before reSmush.it Image Optimizer installation. You will not have your pictures optimized! We strongly advice to be sure to have a complete backup of your website before performing this action', 'resmushit-image-optimizer')
286
+ . '</strong></p><p>'
287
+ . '<input type="button" value="'. __('Restore ALL my original pictures', 'resmushit-image-optimizer') .'" class="rsmt-trigger--restore-backup-files button media-button select-mode-toggle-button" name="resmushit" class="button wp-smush-send" />';
288
+ echo "</div>";
289
+ self::fullWidthPanelEndWrapper();
290
+ }
291
 
292
  /**
293
  *
css/resmushit.css CHANGED
@@ -37,6 +37,9 @@
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;
37
  .rsmt-panels .brdr-grey{
38
  border-left: 4px solid #a2a2a2
39
  }
40
+ .rsmt-panels .brdr-black{
41
+ border-left: 4px solid #222222
42
+ }
43
  .rsmt-panels h2{
44
  text-transform: uppercase;
45
  font-family: 'Roboto Slab', serif;
js/script.js CHANGED
@@ -35,6 +35,7 @@ jQuery( ".list-accordion h4" ).on('click', function(){
35
  updateDisabledState();
36
  optimizeSingleAttachment();
37
  removeBackupFiles();
 
38
 
39
 
40
  /**
@@ -235,4 +236,29 @@ function removeBackupFiles() {
235
  );
236
  }
237
  });
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
238
  }
35
  updateDisabledState();
36
  optimizeSingleAttachment();
37
  removeBackupFiles();
38
+ restoreBackupFiles();
39
 
40
 
41
  /**
236
  );
237
  }
238
  });
239
+ }
240
+
241
+
242
+ /**
243
+ * ajax to Optimize a single picture
244
+ */
245
+ function restoreBackupFiles() {
246
+ jQuery(document).delegate(".rsmt-trigger--restore-backup-files","mouseup",function(e){
247
+ if ( confirm( "You're about to restore ALL your original image files. Are you sure to perform this operation ?" ) ) {
248
+
249
+ e.preventDefault();
250
+ var current = this;
251
+ jQuery(current).val('Restoring backups...');
252
+ jQuery(current).prop('disabled', true);
253
+ jQuery.post(
254
+ ajaxurl, {
255
+ action: 'resmushit_restore_backup_files'
256
+ },
257
+ function(response) {
258
+ var data = jQuery.parseJSON(response);
259
+ jQuery(current).val(data.success + ' images successfully restored');
260
+ }
261
+ );
262
+ }
263
+ });
264
  }
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: 5.7.1
6
- Stable tag: 0.3.12
7
  License: GPLv2 or later
8
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
9
 
@@ -76,6 +76,9 @@ Yes ! Absolutely free, the only restriction is to send images below 5MB.
76
 
77
  == Changelog ==
78
 
 
 
 
79
  = 0.3.12 =
80
  * Fix : Default value assignment
81
  * Test on WP 5.7.1
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: 5.7.1
6
+ Stable tag: 0.4.0
7
  License: GPLv2 or later
8
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
9
 
76
 
77
  == Changelog ==
78
 
79
+ = 0.4.0 =
80
+ * New option to restore all original pictures
81
+
82
  = 0.3.12 =
83
  * Fix : Default value assignment
84
  * Test on WP 5.7.1
resmushit.admin.php CHANGED
@@ -131,6 +131,7 @@ function resmushit_settings_page() {
131
  <?php reSmushitUI::bulkPanel();?>
132
  <?php reSmushitUI::bigFilesPanel();?>
133
  <?php reSmushitUI::statisticsPanel();?>
 
134
  </div>
135
  <div class="rsmt-cols w33 iln-block">
136
  <?php reSmushitUI::settingsPanel();?>
131
  <?php reSmushitUI::bulkPanel();?>
132
  <?php reSmushitUI::bigFilesPanel();?>
133
  <?php reSmushitUI::statisticsPanel();?>
134
+ <?php reSmushitUI::restorePanel();?>
135
  </div>
136
  <div class="rsmt-cols w33 iln-block">
137
  <?php reSmushitUI::settingsPanel();?>
resmushit.php CHANGED
@@ -10,8 +10,8 @@
10
  * Plugin Name: reSmush.it Image Optimizer
11
  * Plugin URI: https://wordpress.org/plugins/resmushit-image-optimizer/
12
  * Description: Image Optimization API. Provides image size optimization
13
- * Version: 0.3.12
14
- * Timestamp: 2021.05.02
15
  * Author: reSmush.it
16
  * Author URI: https://resmush.it
17
  * Author: Charles Bourgeaux
@@ -445,3 +445,48 @@ function resmushit_remove_backup_files() {
445
  die();
446
  }
447
  add_action( 'wp_ajax_resmushit_remove_backup_files', 'resmushit_remove_backup_files' );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
10
  * Plugin Name: reSmush.it Image Optimizer
11
  * Plugin URI: https://wordpress.org/plugins/resmushit-image-optimizer/
12
  * Description: Image Optimization API. Provides image size optimization
13
+ * Version: 0.4.0
14
+ * Timestamp: 2021.05.08
15
  * Author: reSmush.it
16
  * Author URI: https://resmush.it
17
  * Author: Charles Bourgeaux
445
  die();
446
  }
447
  add_action( 'wp_ajax_resmushit_remove_backup_files', 'resmushit_remove_backup_files' );
448
+
449
+
450
+ /**
451
+ *
452
+ * retrieve Attachment ID from Path
453
+ * from : https://pippinsplugins.com/retrieve-attachment-id-from-image-url/
454
+ *
455
+ * @param imageURL
456
+ * @return json object
457
+ */
458
+ function resmushit_get_image_id($image_url) {
459
+ global $wpdb;
460
+ $attachment = $wpdb->get_col($wpdb->prepare("SELECT ID FROM $wpdb->posts WHERE guid='%s';", $image_url ));
461
+ return $attachment[0];
462
+ }
463
+
464
+ /**
465
+ *
466
+ * add Ajax action to restore backups (-unsmushed) from the filesystem
467
+ *
468
+ * @param none
469
+ * @return json object
470
+ */
471
+ function resmushit_restore_backup_files() {
472
+ $files=detect_unsmushed_files();
473
+ $return = array('success' => 0);
474
+ $wp_upload_dir=wp_upload_dir();
475
+
476
+ foreach($files as $f) {
477
+ $dest = str_replace('-unsmushed', '', $f);
478
+ $pictureURL = str_replace($wp_upload_dir['basedir'], $wp_upload_dir['baseurl'], $dest);
479
+ $attachementID = resmushit_get_image_id($pictureURL);
480
+
481
+ if(reSmushit::revert($attachementID, true)) {
482
+ if(unlink($f)) {
483
+ $return['success']++;
484
+ }
485
+ }
486
+ }
487
+ echo json_encode($return);
488
+ //update_option( 'resmushit_has_no_backup_files', 1);
489
+
490
+ die();
491
+ }
492
+ add_action( 'wp_ajax_resmushit_restore_backup_files', 'resmushit_restore_backup_files' );
resmushit.settings.php CHANGED
@@ -1,7 +1,7 @@
1
  <?php
2
 
3
  define('RESMUSHIT_ENDPOINT', 'http://api.resmush.it/');
4
- define('RESMUSHIT_VERSION', '0.3.12');
5
  define('RESMUSHIT_DEFAULT_QLTY', '92');
6
  define('RESMUSHIT_TIMEOUT', '10');
7
  define('RESMUSHIT_LOGS_PATH', 'resmushit.log');
1
  <?php
2
 
3
  define('RESMUSHIT_ENDPOINT', 'http://api.resmush.it/');
4
+ define('RESMUSHIT_VERSION', '0.4.0');
5
  define('RESMUSHIT_DEFAULT_QLTY', '92');
6
  define('RESMUSHIT_TIMEOUT', '10');
7
  define('RESMUSHIT_LOGS_PATH', 'resmushit.log');