Image Optimizer by 10web – Image Optimizer and Compression plugin - Version 1.0.6

Version Description

  • Changed: Optimized images count per request
Download this release

Release Info

Developer webdorado
Plugin Icon 128x128 Image Optimizer by 10web – Image Optimizer and Compression plugin
Version 1.0.6
Comparing to
See all releases

Code changes from version 1.0.4 to 1.0.6

assets/js/settings.js CHANGED
@@ -503,7 +503,7 @@ function iowdCickSettings(name, value) {
503
  };
504
 
505
  jQuery.post(iowd.ajaxURL, data, function (response) {
506
- if (name = "optimize_gallery") {
507
  if (value == 1) {
508
  getGalleryDir();
509
  } else {
@@ -605,14 +605,13 @@ function iowdScan(limit) {
605
 
606
  function iowdLoadBlocks(scan) {
607
  jQuery(".iowd-loading-spinner-ajax").remove();
608
- if (scan["not_optimized_data"] > 0 || scan["not_optimized_data_sizes"] > 0) {
609
  jQuery(".iowd-stat-ajax span b").html("There are " + scan["not_optimized_data_media"] + " full-size ( totally " + scan["not_optimized_data_media_sizes"] + " ) images from media library and " + scan["not_optimized_data_other"] + " from other directories ready for optimize");
610
  }
611
 
612
  dataAttachments = jQuery(".iowd-butn-ajax-container").attr("data-attachments");
613
- if (dataAttachments == "1" || scan["not_optimized_data"] > 0 || scan["not_optimized_data_sizes"] > 0) {
614
  jQuery(".iowd-butn-ajax-container").show();
615
- jQuery(".iowd-optimized-ajax-text").hide();
616
  } else {
617
  if (scan["optimized_data"]) {
618
  jQuery(".iowd-optimized-ajax-text").html('<strong class="iowd-up-to-date">All images are optimized and up to date.</strong>');
@@ -624,7 +623,7 @@ function iowdLoadBlocks(scan) {
624
 
625
  //statistics
626
 
627
- if (scan["not_optimized_data"] > 0 || scan["not_optimized_data_sizes"] > 0) {
628
  ratio = "<span class='iowd_opt_data'>" + scan["optimized_data_sizes"] + "</span>/<span class='iowd_all_data'>" + scan["all_data_sizes"] + "</span>";
629
  width = (scan["optimized_data_sizes"] / scan["all_data_sizes"]) * 100;
630
  style = 'width:' + width + '%';
503
  };
504
 
505
  jQuery.post(iowd.ajaxURL, data, function (response) {
506
+ if (name == "optimize_gallery") {
507
  if (value == 1) {
508
  getGalleryDir();
509
  } else {
605
 
606
  function iowdLoadBlocks(scan) {
607
  jQuery(".iowd-loading-spinner-ajax").remove();
608
+ if (scan["not_optimized_data_media"] > 0 || scan["not_optimized_data_media_sizes"] > 0 || scan["not_optimized_data_other"] > 0) {
609
  jQuery(".iowd-stat-ajax span b").html("There are " + scan["not_optimized_data_media"] + " full-size ( totally " + scan["not_optimized_data_media_sizes"] + " ) images from media library and " + scan["not_optimized_data_other"] + " from other directories ready for optimize");
610
  }
611
 
612
  dataAttachments = jQuery(".iowd-butn-ajax-container").attr("data-attachments");
613
+ if (dataAttachments == "1" || scan["not_optimized_data_media"] > 0 || scan["not_optimized_data_media_sizes"] > 0 || scan["not_optimized_data_other"] > 0) {
614
  jQuery(".iowd-butn-ajax-container").show();
 
615
  } else {
616
  if (scan["optimized_data"]) {
617
  jQuery(".iowd-optimized-ajax-text").html('<strong class="iowd-up-to-date">All images are optimized and up to date.</strong>');
623
 
624
  //statistics
625
 
626
+ if (scan["not_optimized_data_media_sizes"] > 0 || scan["not_optimized_data_media"] > 0 || scan["not_optimized_data_other"] > 0) {
627
  ratio = "<span class='iowd_opt_data'>" + scan["optimized_data_sizes"] + "</span>/<span class='iowd_all_data'>" + scan["all_data_sizes"] + "</span>";
628
  width = (scan["optimized_data_sizes"] / scan["all_data_sizes"]) * 100;
629
  style = 'width:' + width + '%';
includes/iowd-amazon-s3.php CHANGED
@@ -3,7 +3,7 @@
3
  if (!defined('ABSPATH')) {
4
  exit;
5
  }
6
-
7
  use Aws\S3\Exception\S3Exception;
8
  use Aws\S3\S3Client;
9
 
@@ -37,7 +37,11 @@ class IOWD_Amazon_S3
37
  );
38
  $this->credentials = $credentials;
39
 
40
- $this->s3_client = new S3Client($config);
 
 
 
 
41
  }
42
 
43
  public function upload($file_key)
3
  if (!defined('ABSPATH')) {
4
  exit;
5
  }
6
+ require_once(IOWD_DIR . '/vendor/autoload.php');
7
  use Aws\S3\Exception\S3Exception;
8
  use Aws\S3\S3Client;
9
 
37
  );
38
  $this->credentials = $credentials;
39
 
40
+ try {
41
+ $this->s3_client = new S3Client($config);
42
+ } catch (\Exception $e) {
43
+
44
+ }
45
  }
46
 
47
  public function upload($file_key)
includes/iowd-optimize.php CHANGED
@@ -9,7 +9,7 @@ class IOWD_Optimize
9
  private $options;
10
  private $is_single = false;
11
  private $allowed_types = array("jpg", "jpeg", "png", "gif");
12
- private $images_count = 10;
13
 
14
 
15
  public function __construct($single = false)
@@ -86,13 +86,24 @@ class IOWD_Optimize
86
  clearstatcache();
87
  $options = $this->options;
88
  $image_data = array();
89
-
90
- $optimized_data = array();
91
  global $wpdb;
92
- $_optimized_data = $wpdb->get_results("SELECT path, post_id, size FROM " . $wpdb->prefix . "iowd_images");
93
-
94
- foreach($_optimized_data as $data){
95
- $optimized_data[ $data->post_id . "_" . $data->size] = $data->path;
 
 
 
 
 
 
 
 
 
 
 
 
 
96
  }
97
 
98
  $optimize_thumbs = explode(",", $options["optimize_thumbs"]);
@@ -108,8 +119,6 @@ class IOWD_Optimize
108
  $attachments = $wpdb->get_results("SELECT T_POSTS.ID, T_POSTMETA.meta_value FROM " . $wpdb->prefix . "posts AS T_POSTS LEFT JOIN " . $wpdb->prefix . "postmeta AS T_POSTMETA ON
109
  T_POSTS.ID = T_POSTMETA.post_id AND T_POSTMETA.meta_key = '_wp_attachment_metadata' WHERE post_type='attachment' " . $where_ids . $limit_by);
110
 
111
-
112
- $for_checking = array();
113
  if (empty($attachments) === false) {
114
  foreach ($attachments as $attachment) {
115
  if (count($image_data) > $limitation["limit"] && is_null($limit)) {
@@ -123,15 +132,13 @@ class IOWD_Optimize
123
 
124
  //check for getting correct data
125
  if (!$ids) {
126
- if (in_array($path, $optimized_data) && in_array($attachment->ID . "_full", array_keys($optimized_data))) {
127
  continue;
128
  }
129
  }
130
-
131
- if (!file_exists($file_name) || in_array($file_name, $for_checking)) {
132
  continue;
133
  }
134
- $for_checking[] = $file_name;
135
  $type = pathinfo($file_name, PATHINFO_EXTENSION);
136
  $size = filesize($file_name);
137
 
@@ -166,11 +173,11 @@ class IOWD_Optimize
166
 
167
  foreach ($sizes as $size => $file) {
168
  if (in_array($size, $optimize_thumbs)) {
169
- if (in_array($attachment_root_dir . $file["file"], $for_checking) || !file_exists($attachment_root_dir . $file["file"]) ) {
170
  continue;
171
  }
172
  if (!$ids) {
173
- if (in_array($attachment_root_url . $file["file"], $optimized_data) && in_array($attachment->ID . "_" . $size, array_keys($optimized_data))) {
174
  continue;
175
  }
176
  }
@@ -193,14 +200,11 @@ class IOWD_Optimize
193
  $image_data["media_sizes"][$attachment->ID . "_" . $size] = $attachment_root_url . $file["file"];
194
  $image_data["attachments"][$attachment->ID] = $attachment->ID;
195
  }
196
- $for_checking[] = $attachment_root_dir . $file["file"];
197
  }
198
  }
199
  }
200
  }
201
  }
202
- // free memory
203
- unset($for_checking);
204
 
205
  if ($include_others == true && ((count($image_data) < $limitation["limit"] && is_null($limit)) || $limit !== null)) {
206
 
@@ -233,8 +237,7 @@ class IOWD_Optimize
233
  if (in_array($other_image, $optimized_data)) {
234
  continue;
235
  }
236
-
237
- if($options["exclude_full_size"] == "1" && strpos($other_image, ".original") !== false){
238
  continue;
239
  }
240
 
@@ -249,7 +252,7 @@ class IOWD_Optimize
249
  if ($this->check_optimization_level($type) === false || $this->skip_small_images($size) === false || $this->skip_large_images($size) === false || !in_array(strtolower($type), $this->allowed_types)) {
250
  continue;
251
  }
252
- if(is_null($limit)){
253
  $image = array();
254
  $image["path"] = $other_image;
255
  $image["file"] = str_replace($protocaol . '://' . $_SERVER['SERVER_NAME'], $_SERVER['DOCUMENT_ROOT'], $other_image);
@@ -264,7 +267,7 @@ class IOWD_Optimize
264
  $image["transparent"] = $type == "png" && IOWD_Util::is_transparent_png($image["file"]) ? 1 : 0;
265
 
266
  $image_data[] = $image;
267
- } else{
268
  $image_data["other"]["iowd_" . $max_iowd_post . "_full"] = $other_image;
269
  }
270
 
@@ -291,9 +294,11 @@ class IOWD_Optimize
291
  $attachments_data[0] = $image_data;
292
  }
293
  }
 
294
  return $attachments_data;
295
  } else {
296
- set_site_transient("iowd_temp_scan_data_".$limit, $image_data);
 
297
  return $image_data ? true : false;
298
  }
299
 
@@ -303,7 +308,8 @@ class IOWD_Optimize
303
  public function scan($all_attachments)
304
  {
305
  global $wpdb;
306
- $_db_optimized_data = $wpdb->get_results("SELECT `path`, `post_id`, `size` FROM " . $wpdb->prefix . "iowd_images");
 
307
 
308
  // all data
309
  $media = isset($all_attachments["media"]) ? $all_attachments["media"] : array();
@@ -311,9 +317,9 @@ class IOWD_Optimize
311
  $other = isset($all_attachments["other"]) ? $all_attachments["other"] : array();
312
  $unique_attachments = isset($all_attachments["attachments"]) ? $all_attachments["attachments"] : array();
313
 
314
- $not_optimized_data_media_sizes = array_merge($media, $media_sizes);
315
- $not_optimized_data_sizes = array_merge($not_optimized_data_media_sizes, $other);
316
- $not_optimized_data = array_unique(array_merge($media, $other));
317
 
318
  $optimized_data_other = array();
319
  $optimized_data_media = array();
@@ -323,6 +329,13 @@ class IOWD_Optimize
323
  $db_optimized_data = array();
324
  if ($_db_optimized_data) {
325
  foreach ($_db_optimized_data as $data) {
 
 
 
 
 
 
 
326
  $post_id = $data->post_id;
327
  $path = $data->path;
328
 
@@ -339,7 +352,7 @@ class IOWD_Optimize
339
 
340
  }
341
 
342
- $optimized_data = array_merge($optimized_data_other ,$optimized_data_media);
343
 
344
  /*$not_optimized_data = array_diff($all_data, $optimized_data);
345
  $not_optimized_data_sizes = array_diff($all_data_sizes, $db_optimized_data);
@@ -347,18 +360,15 @@ class IOWD_Optimize
347
  $not_optimized_data_media_sizes = array_diff($all_media_sizes, $optimized_data_media_sizes);
348
  $not_optimized_data_other = array_diff($other, $optimized_data_other);*/
349
 
350
- $all_data_sizes = array_merge($not_optimized_data_sizes,$db_optimized_data);
351
- $all_data = array_merge($not_optimized_data, $optimized_data);
352
-
353
 
354
 
355
  return array(
356
  "optimized_data" => count($optimized_data),
357
  "optimized_data_sizes" => count($db_optimized_data),
358
- "not_optimized_data" => count($not_optimized_data),
359
- "not_optimized_data_sizes" => count($not_optimized_data_sizes),
360
  "not_optimized_data_media" => count($unique_attachments),
361
- "not_optimized_data_media_sizes" => count($not_optimized_data_media_sizes),
362
  "not_optimized_data_other" => count($other),
363
  "all_data_sizes" => count($all_data_sizes),
364
  "all_data" => count($all_data),
@@ -488,7 +498,7 @@ class IOWD_Optimize
488
  private function skip_small_images($size)
489
  {
490
  $options = $this->options;
491
- if ($size < (int)$options["skip_small_images"] * 1048576 && $options["skip_small_images"]) {
492
  return false;
493
  }
494
 
@@ -498,7 +508,7 @@ class IOWD_Optimize
498
  private function skip_large_images($size)
499
  {
500
  $options = $this->options;
501
- if ($size > (int)$options["skip_large_images"] * 1048576 && $options["skip_large_images"]) {
502
  return false;
503
  }
504
 
9
  private $options;
10
  private $is_single = false;
11
  private $allowed_types = array("jpg", "jpeg", "png", "gif");
12
+ private $images_count = 60;
13
 
14
 
15
  public function __construct($single = false)
86
  clearstatcache();
87
  $options = $this->options;
88
  $image_data = array();
 
 
89
  global $wpdb;
90
+ $optimized_data = array();
91
+ $optimized_data_ids = array();
92
+ $_optimized_data = $wpdb->get_results("SELECT path, post_id, size, already_optimized FROM " . $wpdb->prefix . "iowd_images");
93
+ foreach ($_optimized_data as $data) {
94
+ $optimization_type = $this->get_current_opt_level($data->path);
95
+ $already_optimized = explode(",", $data->already_optimized);
96
+ $already_optimized = array_unique($already_optimized);
97
+
98
+ if ($options["optimize_once_more"] == "1" && (($optimization_type == "losselss" && empty($already_optimized) == true) || ($optimization_type == "lossy40" && ($already_optimized == array("lossless") || empty($already_optimized) == true)) || ($optimization_type == "lossy" && !in_array("lossy", $already_optimized)))) {
99
+ continue;
100
+ }
101
+ $optimized_data[$data->post_id . "_" . $data->size] = $data->path;
102
+ if (isset($optimized_data_ids[$data->path])) {
103
+ $optimized_data_ids[$data->path][] = $data->post_id;
104
+ } else {
105
+ $optimized_data_ids[$data->path] = array($data->post_id);
106
+ }
107
  }
108
 
109
  $optimize_thumbs = explode(",", $options["optimize_thumbs"]);
119
  $attachments = $wpdb->get_results("SELECT T_POSTS.ID, T_POSTMETA.meta_value FROM " . $wpdb->prefix . "posts AS T_POSTS LEFT JOIN " . $wpdb->prefix . "postmeta AS T_POSTMETA ON
120
  T_POSTS.ID = T_POSTMETA.post_id AND T_POSTMETA.meta_key = '_wp_attachment_metadata' WHERE post_type='attachment' " . $where_ids . $limit_by);
121
 
 
 
122
  if (empty($attachments) === false) {
123
  foreach ($attachments as $attachment) {
124
  if (count($image_data) > $limitation["limit"] && is_null($limit)) {
132
 
133
  //check for getting correct data
134
  if (!$ids) {
135
+ if (in_array($path, $optimized_data) && in_array($attachment->ID, $optimized_data_ids[$path])) {
136
  continue;
137
  }
138
  }
139
+ if (!file_exists($file_name)) {
 
140
  continue;
141
  }
 
142
  $type = pathinfo($file_name, PATHINFO_EXTENSION);
143
  $size = filesize($file_name);
144
 
173
 
174
  foreach ($sizes as $size => $file) {
175
  if (in_array($size, $optimize_thumbs)) {
176
+ if (!file_exists($attachment_root_dir . $file["file"])) {
177
  continue;
178
  }
179
  if (!$ids) {
180
+ if (in_array($attachment_root_url . $file["file"], $optimized_data) && in_array($attachment->ID , $optimized_data_ids[$attachment_root_url . $file["file"]]) ) {
181
  continue;
182
  }
183
  }
200
  $image_data["media_sizes"][$attachment->ID . "_" . $size] = $attachment_root_url . $file["file"];
201
  $image_data["attachments"][$attachment->ID] = $attachment->ID;
202
  }
 
203
  }
204
  }
205
  }
206
  }
207
  }
 
 
208
 
209
  if ($include_others == true && ((count($image_data) < $limitation["limit"] && is_null($limit)) || $limit !== null)) {
210
 
237
  if (in_array($other_image, $optimized_data)) {
238
  continue;
239
  }
240
+ if ($options["exclude_full_size"] == "1" && strpos($other_image, ".original") !== false) {
 
241
  continue;
242
  }
243
 
252
  if ($this->check_optimization_level($type) === false || $this->skip_small_images($size) === false || $this->skip_large_images($size) === false || !in_array(strtolower($type), $this->allowed_types)) {
253
  continue;
254
  }
255
+ if (is_null($limit)) {
256
  $image = array();
257
  $image["path"] = $other_image;
258
  $image["file"] = str_replace($protocaol . '://' . $_SERVER['SERVER_NAME'], $_SERVER['DOCUMENT_ROOT'], $other_image);
267
  $image["transparent"] = $type == "png" && IOWD_Util::is_transparent_png($image["file"]) ? 1 : 0;
268
 
269
  $image_data[] = $image;
270
+ } else {
271
  $image_data["other"]["iowd_" . $max_iowd_post . "_full"] = $other_image;
272
  }
273
 
294
  $attachments_data[0] = $image_data;
295
  }
296
  }
297
+
298
  return $attachments_data;
299
  } else {
300
+ set_site_transient("iowd_temp_scan_data_" . $limit, $image_data);
301
+
302
  return $image_data ? true : false;
303
  }
304
 
308
  public function scan($all_attachments)
309
  {
310
  global $wpdb;
311
+ $options = $this->options;
312
+ $_db_optimized_data = $wpdb->get_results("SELECT `path`, `post_id`, `size`, `already_optimized` FROM " . $wpdb->prefix . "iowd_images");
313
 
314
  // all data
315
  $media = isset($all_attachments["media"]) ? $all_attachments["media"] : array();
317
  $other = isset($all_attachments["other"]) ? $all_attachments["other"] : array();
318
  $unique_attachments = isset($all_attachments["attachments"]) ? $all_attachments["attachments"] : array();
319
 
320
+ $all_media_sizes = array_merge($media, $media_sizes);
321
+ $all_data_sizes = array_merge($all_media_sizes, $other);
322
+ $all_data = array_unique(array_merge($media, $other));
323
 
324
  $optimized_data_other = array();
325
  $optimized_data_media = array();
329
  $db_optimized_data = array();
330
  if ($_db_optimized_data) {
331
  foreach ($_db_optimized_data as $data) {
332
+ $optimization_type = $this->get_current_opt_level($data->path);
333
+ $already_optimized = explode(",", $data->already_optimized);
334
+ $already_optimized = array_unique($already_optimized);
335
+
336
+ if ($options["optimize_once_more"] == "1" && (($optimization_type == "losselss" && empty($already_optimized) == true) || ($optimization_type == "lossy40" && ($already_optimized == array("lossless") || empty($already_optimized) == true)) || ($optimization_type == "lossy" && !in_array("lossy", $already_optimized)))) {
337
+ continue;
338
+ }
339
  $post_id = $data->post_id;
340
  $path = $data->path;
341
 
352
 
353
  }
354
 
355
+ $optimized_data = array_merge($optimized_data_other, $optimized_data_media);
356
 
357
  /*$not_optimized_data = array_diff($all_data, $optimized_data);
358
  $not_optimized_data_sizes = array_diff($all_data_sizes, $db_optimized_data);
360
  $not_optimized_data_media_sizes = array_diff($all_media_sizes, $optimized_data_media_sizes);
361
  $not_optimized_data_other = array_diff($other, $optimized_data_other);*/
362
 
363
+ $all_data_sizes = array_merge($all_data_sizes, $db_optimized_data);
364
+ $all_data = array_merge($all_data, $optimized_data);
 
365
 
366
 
367
  return array(
368
  "optimized_data" => count($optimized_data),
369
  "optimized_data_sizes" => count($db_optimized_data),
 
 
370
  "not_optimized_data_media" => count($unique_attachments),
371
+ "not_optimized_data_media_sizes" => count($all_media_sizes),
372
  "not_optimized_data_other" => count($other),
373
  "all_data_sizes" => count($all_data_sizes),
374
  "all_data" => count($all_data),
498
  private function skip_small_images($size)
499
  {
500
  $options = $this->options;
501
+ if ($size < floatval($options["skip_small_images"]) * 1048576 && $options["skip_small_images"]) {
502
  return false;
503
  }
504
 
508
  private function skip_large_images($size)
509
  {
510
  $options = $this->options;
511
+ if ($size > floatval($options["skip_large_images"]) * 1048576 && $options["skip_large_images"]) {
512
  return false;
513
  }
514
 
io-wd.php CHANGED
@@ -4,7 +4,7 @@
4
  * Plugin Name: Image Optimizer WD
5
  * Plugin URI: https://web-dorado.com/products/wordpress-image-optimizer.html
6
  * Description: Image Optimizer WordPress plugin enables you to resize, compress and optimize PNG, JPG, GIF files while maintaining image quality.
7
- * Version: 1.0.4
8
  * Author: WebDorado
9
  * Author URI: https://web-dorado.com/
10
  * License: GNU/GPLv3 http://www.gnu.org/licenses/gpl-3.0.html
4
  * Plugin Name: Image Optimizer WD
5
  * Plugin URI: https://web-dorado.com/products/wordpress-image-optimizer.html
6
  * Description: Image Optimizer WordPress plugin enables you to resize, compress and optimize PNG, JPG, GIF files while maintaining image quality.
7
+ * Version: 1.0.6
8
  * Author: WebDorado
9
  * Author URI: https://web-dorado.com/
10
  * License: GNU/GPLv3 http://www.gnu.org/licenses/gpl-3.0.html
iowd_class.php CHANGED
@@ -8,7 +8,7 @@ class IOWD
8
  {
9
 
10
  protected static $instance = null;
11
- private static $version = '1.0.4';
12
  private static $page;
13
  private $reg_autoloader = false;
14
  private $options = array();
8
  {
9
 
10
  protected static $instance = null;
11
+ private static $version = '1.0.6';
12
  private static $page;
13
  private $reg_autoloader = false;
14
  private $options = array();
readme.txt CHANGED
@@ -1,11 +1,10 @@
1
- === Image Optimizer WD - WordPress Image Optimizer ===
2
  Contributors: webdorado
3
- Donate link: https://web-dorado.com/products/wordpress-image-optimizer.html
4
  Tags: : compress, image, images optimization, performance, photos, lossless, optimize
5
  Requires at least: 3.9
6
  Tested up to: 4.9
7
  Requires PHP: 5.5
8
- Stable tag: 1.0.4
9
  License: GPLv2 or later
10
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
11
 
@@ -55,6 +54,12 @@ Upgrade to [Image Optimizer WD Pro](https://web-dorado.com/products/wordpress-im
55
 
56
  == Changelog ==
57
 
 
 
 
 
 
 
58
  = 1.0.4 =
59
  * Fixed: Minor bug
60
  * Changed: Deactivation popup
1
+ === Image Optimizer by WD - Image Optimizer and Compression plugin ===
2
  Contributors: webdorado
 
3
  Tags: : compress, image, images optimization, performance, photos, lossless, optimize
4
  Requires at least: 3.9
5
  Tested up to: 4.9
6
  Requires PHP: 5.5
7
+ Stable tag: 1.0.6
8
  License: GPLv2 or later
9
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
 
54
 
55
  == Changelog ==
56
 
57
+ = 1.0.6 =
58
+ * Changed: Optimized images count per request
59
+
60
+ = 1.0.5 =
61
+ * Fixed: Bug on autooptimize
62
+
63
  = 1.0.4 =
64
  * Fixed: Minor bug
65
  * Changed: Deactivation popup