Version Description
- Change: Require PHP 5.5
- Change: Using AJAX for getting optimizer scan info
Download this release
Release Info
Developer | webdorado |
Plugin | Image Optimizer by 10web – Image Optimizer and Compression plugin |
Version | 1.0.2 |
Comparing to | |
See all releases |
Code changes from version 1.0.1 to 1.0.2
- .gitignore +0 -3
- assets/js/admin_main.js +1 -1
- assets/js/api.js +17 -4
- assets/js/settings.js +68 -0
- includes/iowd-ajax.php +55 -0
- includes/iowd-amazon-s3.php +5 -4
- includes/iowd-optimize.php +293 -183
- includes/iowd-settings.php +22 -19
- io-wd.php +1 -1
- iowd_class.php +5 -3
- readme.txt +5 -1
- views/iowd_settings_display.php +87 -120
.gitignore
DELETED
@@ -1,3 +0,0 @@
|
|
1 |
-
# Created by .ignore support plugin (hsz.mobi)
|
2 |
-
/vendor/
|
3 |
-
.idea/*
|
|
|
|
|
|
assets/js/admin_main.js
CHANGED
@@ -85,7 +85,7 @@ jQuery(document).ready(function () {
|
|
85 |
jQuery.post(iowd.ajaxURL, data, function () {
|
86 |
}).done(function (response) {
|
87 |
response = JSON.parse(response);
|
88 |
-
if(response.status == "error"){
|
89 |
window.location.href = "admin.php?page=iowd_settings";
|
90 |
return false;
|
91 |
}
|
85 |
jQuery.post(iowd.ajaxURL, data, function () {
|
86 |
}).done(function (response) {
|
87 |
response = JSON.parse(response);
|
88 |
+
if(response.status == "error" || response.data_count == 0){
|
89 |
window.location.href = "admin.php?page=iowd_settings";
|
90 |
return false;
|
91 |
}
|
assets/js/api.js
CHANGED
@@ -4,6 +4,8 @@ var iowdAPI = (function () {
|
|
4 |
// constructor
|
5 |
var api = function () {
|
6 |
this._apiURL = null;
|
|
|
|
|
7 |
this._postData = null;
|
8 |
this.error = {
|
9 |
error_number: null,
|
@@ -45,10 +47,21 @@ var iowdAPI = (function () {
|
|
45 |
}
|
46 |
|
47 |
}).fail(function() {
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
52 |
});
|
53 |
};
|
54 |
|
4 |
// constructor
|
5 |
var api = function () {
|
6 |
this._apiURL = null;
|
7 |
+
this._triesCount = 25;
|
8 |
+
this._triesIteration = 0;
|
9 |
this._postData = null;
|
10 |
this.error = {
|
11 |
error_number: null,
|
47 |
}
|
48 |
|
49 |
}).fail(function() {
|
50 |
+
if (thisAPI._triesIteration < thisAPI._triesCount) {
|
51 |
+
console.log('Something went wrong. IO will retry.');
|
52 |
+
setTimeout(function () {
|
53 |
+
thisAPI.ajaxCall(data, callback);
|
54 |
+
}, 1000);
|
55 |
+
thisAPI._triesIteration++;
|
56 |
+
} else {
|
57 |
+
var abortedData = {
|
58 |
+
action: "abort",
|
59 |
+
nonce_iowd: data.nonce_iowd
|
60 |
+
};
|
61 |
+
jQuery.post(thisAPI._apiURL, abortedData, function () {
|
62 |
+
window.location.href = "admin.php?page=iowd_settings";
|
63 |
+
});
|
64 |
+
}
|
65 |
});
|
66 |
};
|
67 |
|
assets/js/settings.js
CHANGED
@@ -349,6 +349,8 @@ jQuery(document).ready(function () {
|
|
349 |
window.location.href = "admin.php?page=iowd_settings";
|
350 |
});
|
351 |
});
|
|
|
|
|
352 |
|
353 |
});
|
354 |
|
@@ -470,5 +472,71 @@ function iowdDisable(changedElem, disabledElem) {
|
|
470 |
}
|
471 |
}
|
472 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
473 |
|
474 |
|
349 |
window.location.href = "admin.php?page=iowd_settings";
|
350 |
});
|
351 |
});
|
352 |
+
jQuery(".iowd-butn-ajax-container").closest(".iowd-main").append('<img src="http://devops.web-dorado.info/Sergey/wp4/wp-content/plugins/image-optimizer-wd/assets/img/spinner.gif" class="iowd-spinner iowd-loading-spinner-ajax" style="display:inline-block; vertical-align:sub;">');
|
353 |
+
iowdScan(0);
|
354 |
|
355 |
});
|
356 |
|
472 |
}
|
473 |
}
|
474 |
|
475 |
+
function iowdScan(limit) {
|
476 |
+
var data = {
|
477 |
+
action: "scan",
|
478 |
+
nonce_iowd: iowd.nonce,
|
479 |
+
limit: limit
|
480 |
+
};
|
481 |
+
|
482 |
+
jQuery.post(iowd.ajaxURL, data, function (response) {
|
483 |
+
response = JSON.parse(response);
|
484 |
+
if(response["status"] != "done"){
|
485 |
+
limit = limit + 2000;
|
486 |
+
iowdScan(limit);
|
487 |
+
} else{
|
488 |
+
var data = {
|
489 |
+
action: "scan_all",
|
490 |
+
nonce_iowd: iowd.nonce,
|
491 |
+
limit : limit
|
492 |
+
};
|
493 |
+
|
494 |
+
jQuery.post(iowd.ajaxURL, data, function (response) {
|
495 |
+
response = JSON.parse(response);
|
496 |
+
iowdLoadBlocks(response);
|
497 |
+
});
|
498 |
+
}
|
499 |
+
|
500 |
+
});
|
501 |
+
}
|
502 |
+
|
503 |
+
function iowdLoadBlocks(scan) {
|
504 |
+
jQuery(".iowd-loading-spinner-ajax").remove();
|
505 |
+
if(scan["not_optimized_data"] > 0 || scan["not_optimized_data_sizes"] > 0){
|
506 |
+
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");
|
507 |
+
}
|
508 |
+
|
509 |
+
dataAttachments = jQuery(".iowd-butn-ajax-container").attr("data-attachments");
|
510 |
+
if(dataAttachments == "1" || scan["not_optimized_data"] > 0 || scan["not_optimized_data_sizes"] > 0){
|
511 |
+
jQuery(".iowd-butn-ajax-container").show();
|
512 |
+
} else{
|
513 |
+
if (scan["optimized_data"]) {
|
514 |
+
jQuery(".iowd-optimized-ajax-text").html('<strong class="iowd-up-to-date">All images are optimized and up to date.</strong>');
|
515 |
+
} else {
|
516 |
+
jQuery(".iowd-optimized-ajax-text").html('<strong>There are no images for optimizing.</strong>');
|
517 |
+
}
|
518 |
+
jQuery(".iowd-optimized-ajax-text").show();
|
519 |
+
}
|
520 |
+
|
521 |
+
//statistics
|
522 |
+
|
523 |
+
if (scan["not_optimized_data"] > 0 || scan["not_optimized_data_sizes"] > 0) {
|
524 |
+
ratio = "<span class='iowd_opt_data'>" + scan["optimized_data_sizes"] + "</span>/<span class='iowd_all_data'>" + scan["all_data_sizes"] + "</span>";
|
525 |
+
width = (scan["optimized_data_sizes"] / scan["all_data_sizes"]) * 100;
|
526 |
+
style = 'width:' + width + '%';
|
527 |
+
} else {
|
528 |
+
ratio = "<span class='iowd_opt_data'>" + scan["optimized_data_sizes"] + "</span>/<span class='iowd_all_data'>" + scan["optimized_data_sizes"] + "</span>";
|
529 |
+
if (scan["optimized_data_sizes"] == 0) {
|
530 |
+
style = 'width:0%';
|
531 |
+
} else {
|
532 |
+
style = 'width:100%';
|
533 |
+
}
|
534 |
+
}
|
535 |
+
|
536 |
+
jQuery(".iowd-stat-ratio").html(ratio);
|
537 |
+
jQuery(".iowd-stat-progress-bar-inner").attr("style", style);
|
538 |
+
|
539 |
+
}
|
540 |
+
|
541 |
|
542 |
|
includes/iowd-ajax.php
CHANGED
@@ -285,6 +285,61 @@ class IOWD_Ajax
|
|
285 |
//wp_die();
|
286 |
}
|
287 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
288 |
}
|
289 |
|
290 |
|
285 |
//wp_die();
|
286 |
}
|
287 |
|
288 |
+
public static function scan()
|
289 |
+
{
|
290 |
+
$optimizer = new IOWD_Optimize();
|
291 |
+
$limit = isset($_POST["limit"]) ? $_POST["limit"] : 0;
|
292 |
+
|
293 |
+
$data = $optimizer->get_attachments(array(), false, array(), null, $limit);
|
294 |
+
if ($data) {
|
295 |
+
$response = array("status" => "pending");
|
296 |
+
} else {
|
297 |
+
$data = $optimizer->get_attachments(array(), true, array(), null, $limit);
|
298 |
+
$response = array("status" => "done");
|
299 |
+
}
|
300 |
+
|
301 |
+
echo json_encode($response);
|
302 |
+
wp_die();
|
303 |
+
|
304 |
+
}
|
305 |
+
|
306 |
+
public static function scan_all()
|
307 |
+
{
|
308 |
+
$optimizer = new IOWD_Optimize();
|
309 |
+
$limit = isset($_POST["limit"]) ? $_POST["limit"] : 0;
|
310 |
+
|
311 |
+
$media = array();
|
312 |
+
$other = array();
|
313 |
+
$media_sizes = array();
|
314 |
+
$attachments = array();
|
315 |
+
for($i=0; $i <= $limit; $i+=2000){
|
316 |
+
$db_attachments = get_site_transient("iowd_temp_scan_data_".$i);
|
317 |
+
$media_attachments = isset($db_attachments["media"]) ? $db_attachments["media"] : array();
|
318 |
+
$media_sizes_attachments = isset($db_attachments["media_sizes"]) ? $db_attachments["media_sizes"] : array();
|
319 |
+
$other_attachments = isset($db_attachments["other"]) ? $db_attachments["other"] : array();
|
320 |
+
$u_attachments = isset($db_attachments["attachments"]) ? $db_attachments["attachments"] : array();
|
321 |
+
|
322 |
+
$media = $media + $media_attachments;
|
323 |
+
$other = $other + $other_attachments;
|
324 |
+
$media_sizes = $media_sizes + $media_sizes_attachments;
|
325 |
+
$attachments = $attachments + $u_attachments;
|
326 |
+
|
327 |
+
delete_site_transient("iowd_temp_scan_data_".$i);
|
328 |
+
}
|
329 |
+
$all_attachments = array(
|
330 |
+
"media" => $media,
|
331 |
+
"media_sizes" => $media_sizes,
|
332 |
+
"other" => $other,
|
333 |
+
"attachments" => $attachments,
|
334 |
+
);
|
335 |
+
|
336 |
+
|
337 |
+
$data = $optimizer->scan($all_attachments);
|
338 |
+
echo json_encode($data);
|
339 |
+
wp_die();
|
340 |
+
|
341 |
+
}
|
342 |
+
|
343 |
}
|
344 |
|
345 |
|
includes/iowd-amazon-s3.php
CHANGED
@@ -9,8 +9,7 @@ use Aws\S3\S3Client;
|
|
9 |
|
10 |
class IOWD_Amazon_S3
|
11 |
{
|
12 |
-
|
13 |
-
const S3_CREDENTIALS_PATH = IOWD_API_URL . '/s3credentials';
|
14 |
|
15 |
public $errors = array();
|
16 |
public $sub_folder_name = null;
|
@@ -22,16 +21,18 @@ class IOWD_Amazon_S3
|
|
22 |
|
23 |
public function __construct($id = '')
|
24 |
{
|
|
|
|
|
25 |
$this->sub_folder_name = md5("TWlop45&&Kn1)@" . time());
|
26 |
$this->folder_name = md5(site_url());
|
27 |
-
|
28 |
$credentials = get_option("iowd_crd_" . $id);
|
29 |
$config = array(
|
30 |
'version' => 'latest',
|
31 |
'region' => $this->region,
|
32 |
'credentials' => $credentials,
|
33 |
'http' => array(
|
34 |
-
'verify' =>
|
35 |
),
|
36 |
);
|
37 |
$this->credentials = $credentials;
|
9 |
|
10 |
class IOWD_Amazon_S3
|
11 |
{
|
12 |
+
private $cacert_path = null;
|
|
|
13 |
|
14 |
public $errors = array();
|
15 |
public $sub_folder_name = null;
|
21 |
|
22 |
public function __construct($id = '')
|
23 |
{
|
24 |
+
$this->cacert_path = IOWD_DIR . '/cacert-2017-06-07.pem';
|
25 |
+
|
26 |
$this->sub_folder_name = md5("TWlop45&&Kn1)@" . time());
|
27 |
$this->folder_name = md5(site_url());
|
28 |
+
|
29 |
$credentials = get_option("iowd_crd_" . $id);
|
30 |
$config = array(
|
31 |
'version' => 'latest',
|
32 |
'region' => $this->region,
|
33 |
'credentials' => $credentials,
|
34 |
'http' => array(
|
35 |
+
'verify' => $this->cacert_path,
|
36 |
),
|
37 |
);
|
38 |
$this->credentials = $credentials;
|
includes/iowd-optimize.php
CHANGED
@@ -65,14 +65,13 @@ class IOWD_Optimize
|
|
65 |
return array("status" => "error", "error" => __("Empty credentials, please try again.", IOWD_PREFIX));
|
66 |
}
|
67 |
|
68 |
-
|
69 |
-
$images_data = $this->get_attachments($ids, false, $meta, $response["remained"]);
|
70 |
-
} else {
|
71 |
-
$images_data = $this->scan($ids, $other, $response["remained"]);
|
72 |
-
$images_data = $images_data["attachments_data"];
|
73 |
-
}
|
74 |
|
75 |
$data_count = count($images_data);
|
|
|
|
|
|
|
|
|
76 |
// add temp data
|
77 |
add_option("iowd_image_temp_data_" . $id, $images_data);
|
78 |
add_option("iowd_data_count_" . $id, $data_count);
|
@@ -80,85 +79,125 @@ class IOWD_Optimize
|
|
80 |
return array("status" => "ok", "data_count" => $data_count);
|
81 |
}
|
82 |
|
83 |
-
public function get_attachments($ids = array(), $include_others = false, $meta = array(), $remained = null)
|
84 |
{
|
85 |
-
ini_set('
|
|
|
86 |
clearstatcache();
|
87 |
$options = $this->options;
|
88 |
$image_data = array();
|
89 |
|
|
|
|
|
90 |
|
91 |
$optimize_thumbs = explode(",", $options["optimize_thumbs"]);
|
92 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
93 |
|
94 |
-
$args = array(
|
95 |
-
'post_type' => 'attachment',
|
96 |
-
'post__in' => $ids,
|
97 |
-
'numberposts' => -1
|
98 |
-
);
|
99 |
-
$attachments = get_posts($args);
|
100 |
|
|
|
101 |
if (empty($attachments) === false) {
|
102 |
foreach ($attachments as $attachment) {
|
103 |
-
if (
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
104 |
continue;
|
105 |
}
|
106 |
-
$
|
107 |
$type = pathinfo($file_name, PATHINFO_EXTENSION);
|
108 |
$size = filesize($file_name);
|
109 |
-
|
110 |
// check type
|
111 |
if (!in_array(strtolower($type), $this->allowed_types) || $this->check_optimization_level($type) === false) {
|
112 |
continue;
|
113 |
}
|
114 |
|
115 |
if (($this->skip_small_images($size) === true && $this->skip_large_images($size) === true && $options["exclude_full_size"] == 0) || $this->is_single == true) {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
116 |
|
117 |
-
$image = array();
|
118 |
-
$image["path"] = $path;
|
119 |
-
$image["file"] = $file_name;
|
120 |
-
$image["post_id"] = $attachment->ID;
|
121 |
-
$image["size"] = "full";
|
122 |
-
$image["image_size"] = $size;
|
123 |
-
$image["media"] = 1;
|
124 |
-
$image["converted"] = 0;
|
125 |
-
$image["resized"] = 0;
|
126 |
-
$image["single"] = $this->is_single;
|
127 |
-
$image["transparent"] = $type == "png" && IOWD_Util::is_transparent_png($file_name) ? 1 : 0;
|
128 |
-
|
129 |
-
$image_data[] = $image;
|
130 |
}
|
131 |
$attachment_root_url = str_replace(basename($path), "", $path);
|
132 |
-
$attachment_root_dir = str_replace(basename(
|
133 |
-
|
134 |
-
$meta = wp_get_attachment_metadata($attachment->ID) ? wp_get_attachment_metadata($attachment->ID) : $meta;
|
135 |
-
$sizes = isset($meta["sizes"]) ? $meta["sizes"] : array();
|
136 |
|
137 |
foreach ($sizes as $size => $file) {
|
138 |
if (in_array($size, $optimize_thumbs)) {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
139 |
$image_size = filesize($attachment_root_dir . $file["file"]);
|
140 |
if (($this->skip_small_images($image_size) === true && $this->skip_large_images($image_size) === true) || $this->is_single == true) {
|
141 |
-
|
142 |
-
|
143 |
-
|
144 |
-
|
145 |
-
|
146 |
-
|
147 |
-
|
148 |
-
|
149 |
-
|
150 |
-
|
151 |
-
|
152 |
-
|
153 |
-
|
154 |
-
|
|
|
|
|
|
|
|
|
155 |
}
|
156 |
}
|
157 |
}
|
158 |
}
|
159 |
}
|
|
|
|
|
160 |
|
161 |
-
if ($include_others == true) {
|
162 |
|
163 |
$protocaol = isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] != 'off' ? 'https' : 'http';
|
164 |
|
@@ -183,6 +222,13 @@ class IOWD_Optimize
|
|
183 |
$max_iowd_post = $max_iowd_post ? substr($max_iowd_post->post_id, 5) + 1 : 1;
|
184 |
|
185 |
foreach ($other_images as $other_image) {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
186 |
$other_path = str_replace($protocaol . '://' . $_SERVER['SERVER_NAME'], $_SERVER['DOCUMENT_ROOT'], $other_image);
|
187 |
|
188 |
if (!file_exists($other_path)) {
|
@@ -194,43 +240,206 @@ class IOWD_Optimize
|
|
194 |
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)) {
|
195 |
continue;
|
196 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
197 |
|
198 |
-
$image = array();
|
199 |
-
$image["path"] = $other_image;
|
200 |
-
$image["file"] = str_replace($protocaol . '://' . $_SERVER['SERVER_NAME'], $_SERVER['DOCUMENT_ROOT'], $other_image);
|
201 |
-
$image["post_id"] = "iowd_" . $max_iowd_post;
|
202 |
-
$image["size"] = "full";
|
203 |
-
|
204 |
-
$image["image_size"] = $size;
|
205 |
-
$image["media"] = 0;
|
206 |
-
$image["converted"] = 0;
|
207 |
-
$image["resized"] = 0;
|
208 |
-
$image["single"] = $this->is_single;
|
209 |
-
$image["transparent"] = $type == "png" && IOWD_Util::is_transparent_png($image["file"]) ? 1 : 0;
|
210 |
-
|
211 |
-
$image_data[] = $image;
|
212 |
$i++;
|
213 |
$max_iowd_post++;
|
214 |
}
|
215 |
}
|
216 |
}
|
217 |
|
218 |
-
if (
|
219 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
220 |
}
|
221 |
|
222 |
-
|
223 |
-
|
224 |
-
|
225 |
-
|
226 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
227 |
}
|
|
|
228 |
} else {
|
229 |
-
$
|
230 |
}
|
231 |
|
232 |
-
|
233 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
234 |
}
|
235 |
|
236 |
private function check_optimization_level($mime_type)
|
@@ -287,112 +496,6 @@ class IOWD_Optimize
|
|
287 |
return true;
|
288 |
}
|
289 |
|
290 |
-
public function scan($ids = array(), $include_others = false, $remained = null)
|
291 |
-
{
|
292 |
-
$options = $this->options;
|
293 |
-
$attachments = $this->get_attachments($ids, $include_others);
|
294 |
-
|
295 |
-
global $wpdb;
|
296 |
-
$where = "";
|
297 |
-
$rows = $wpdb->get_results("SELECT * FROM " . $wpdb->prefix . "iowd_images " . $where);
|
298 |
-
$optimized_data = array();
|
299 |
-
|
300 |
-
$all_data_count = array();
|
301 |
-
$optimized_data_count = array();
|
302 |
-
$all_data = array();
|
303 |
-
|
304 |
-
$for_checking = array();
|
305 |
-
for ($i = 0; $i < count($attachments); $i++) {
|
306 |
-
foreach ($attachments[$i] as $attachment) {
|
307 |
-
if (!in_array($attachment["path"], $for_checking)) {
|
308 |
-
if ($attachment["media"] == 1) {
|
309 |
-
$all_data[$attachment["post_id"] . ":" . $attachment["size"]] = $attachment["post_id"] . ":" . $attachment["size"];
|
310 |
-
$all_data_count[$attachment["post_id"]] = $attachment["post_id"];
|
311 |
-
} else {
|
312 |
-
$all_data["iowd_" . $attachment["path"]] = "iowd_" . $attachment["path"];
|
313 |
-
$all_data_count[$attachment["path"]] = $attachment["path"];
|
314 |
-
}
|
315 |
-
}
|
316 |
-
$for_checking[] = $attachment["path"];
|
317 |
-
}
|
318 |
-
}
|
319 |
-
|
320 |
-
foreach ($rows as $row) {
|
321 |
-
$optimization_type = $this->get_current_opt_level($row->path);
|
322 |
-
$already_optimized = explode(",", $row->already_optimized);
|
323 |
-
$already_optimized = array_unique($already_optimized);
|
324 |
-
|
325 |
-
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)))) {
|
326 |
-
continue;
|
327 |
-
}
|
328 |
-
|
329 |
-
if ($row->media == 1) {
|
330 |
-
$optimized_data[$row->post_id . ":" . $row->size] = $row->post_id . ":" . $row->size;
|
331 |
-
$optimized_data_count[$row->post_id] = $row->post_id;
|
332 |
-
} else {
|
333 |
-
$optimized_data["iowd_" . $row->path] = "iowd_" . $row->path;
|
334 |
-
$optimized_data_count[$row->path] = $row->path;
|
335 |
-
}
|
336 |
-
}
|
337 |
-
|
338 |
-
$optimize_all_diff = array_diff($optimized_data, $all_data);
|
339 |
-
$not_optimized_data = array_diff($all_data, $optimized_data);
|
340 |
-
$all_data = $all_data + $optimize_all_diff;
|
341 |
-
|
342 |
-
|
343 |
-
$optimize_all_diff_count = array_diff($optimized_data_count, $all_data_count);
|
344 |
-
$not_optimized_data_count = array_diff($all_data_count, $optimized_data_count);
|
345 |
-
$all_data_count = $all_data_count + $optimize_all_diff_count;
|
346 |
-
|
347 |
-
|
348 |
-
$not_optimized_data_other = array_filter($not_optimized_data, function ($elem) {
|
349 |
-
if (strpos($elem, "iowd_") !== false) {
|
350 |
-
return $elem;
|
351 |
-
}
|
352 |
-
});
|
353 |
-
|
354 |
-
$not_optimized_data_media_count = count($not_optimized_data_count) - count($not_optimized_data_other);
|
355 |
-
$not_optimized_data_media = count($not_optimized_data) - count($not_optimized_data_other);
|
356 |
-
|
357 |
-
$image_data = array();
|
358 |
-
|
359 |
-
for ($i = 0; $i < count($attachments); $i++) {
|
360 |
-
foreach ($attachments[$i] as $attachment) {
|
361 |
-
if (in_array($attachment["post_id"] . ":" . $attachment["size"], $not_optimized_data) || in_array("iowd_" . $attachment["path"], $not_optimized_data)) {
|
362 |
-
$image_data[] = $attachment;
|
363 |
-
}
|
364 |
-
}
|
365 |
-
}
|
366 |
-
|
367 |
-
if (!is_null($remained)) {
|
368 |
-
$image_data = array_slice($image_data, 0, $remained);
|
369 |
-
}
|
370 |
-
|
371 |
-
$images_count = count($image_data);
|
372 |
-
$attachments_data = array();
|
373 |
-
if ($images_count > $this->images_count) {
|
374 |
-
for ($i = 0; $i < ceil($images_count / $this->images_count); $i++) {
|
375 |
-
$attachments_data[$i] = array_slice($image_data, $i * $this->images_count, $this->images_count);
|
376 |
-
}
|
377 |
-
} else {
|
378 |
-
$attachments_data[0] = $image_data;
|
379 |
-
}
|
380 |
-
|
381 |
-
|
382 |
-
return array(
|
383 |
-
"optimized_data" => count($optimized_data_count),
|
384 |
-
"optimized_data_sizes" => count($optimized_data),
|
385 |
-
"not_optimized_data" => count($not_optimized_data_count),
|
386 |
-
"not_optimized_data_sizes" => count($not_optimized_data),
|
387 |
-
"not_optimized_data_media" => $not_optimized_data_media_count,
|
388 |
-
"not_optimized_data_media_sizes" => $not_optimized_data_media,
|
389 |
-
"not_optimized_data_other" => count($not_optimized_data_other),
|
390 |
-
"all_data" => count($all_data_count),
|
391 |
-
"all_data_sizes" => count($all_data),
|
392 |
-
"attachments_data" => $attachments_data
|
393 |
-
);
|
394 |
-
}
|
395 |
-
|
396 |
private function get_current_opt_level($path)
|
397 |
{
|
398 |
$options = $this->options;
|
@@ -424,6 +527,9 @@ class IOWD_Optimize
|
|
424 |
$post_ids = array();
|
425 |
for ($i = 0; $i < count($images_data); $i++) {
|
426 |
$image_data = $images_data[$i];
|
|
|
|
|
|
|
427 |
// if enable resizing
|
428 |
if ($options["enable_resizing"] == 1 || $options["enable_resizing_other"] == 1) {
|
429 |
$resize_data = $this->resize($image_data, $meta);
|
@@ -456,7 +562,7 @@ class IOWD_Optimize
|
|
456 |
$db_post_ids = array_unique($db_post_ids);
|
457 |
set_transient("iowd_optimizing_post_ids", $db_post_ids);
|
458 |
|
459 |
-
GuzzleHttp\Promise\
|
460 |
$response = $this->api_call_ajax($data, $s3->folder_name, $s3->sub_folder_name, $s3->credentials, $iteration, $id);
|
461 |
if (isset($response["status"]) && $response["status"] == "error") {
|
462 |
set_transient("iowd_response_error", $response["error"]);
|
@@ -492,9 +598,6 @@ class IOWD_Optimize
|
|
492 |
|
493 |
if ($resized == 0) {
|
494 |
$iowd_image->load_image($item["file"]);
|
495 |
-
if ($options["keep_originals"] == 1) {
|
496 |
-
$this->keep_originals($item["file"]);
|
497 |
-
}
|
498 |
$flag = false;
|
499 |
list($width) = @getimagesize($item["file"]);
|
500 |
if ($item["media"] == 1 && $options["resize_media_images_width"] && $options["resize_media_images_height"] && $width > $options["resize_media_images_width"] && $options["enable_resizing"] == 1 && $item["size"] == "full") {
|
@@ -596,6 +699,7 @@ class IOWD_Optimize
|
|
596 |
$_image_size = 0;
|
597 |
$_image_orig_size = 0;
|
598 |
$_image_count = 0;
|
|
|
599 |
for ($i = 0; $i < count($request); $i++) {
|
600 |
$request_row = $request[$i];
|
601 |
$response_row = isset($body[$request_row["post_id"] . ":" . $request_row["size"]]) ? $body[$request_row["post_id"] . ":" . $request_row["size"]] : false;
|
@@ -647,6 +751,7 @@ class IOWD_Optimize
|
|
647 |
$_image_size += $row_data["image_size"];
|
648 |
$_image_orig_size += $img_orig_size;
|
649 |
$_image_count += 1;
|
|
|
650 |
}
|
651 |
|
652 |
$last_optimized_data = get_site_transient("iowd_last_optimized_data");
|
@@ -661,6 +766,11 @@ class IOWD_Optimize
|
|
661 |
|
662 |
set_site_transient("iowd_last_optimized_data", json_encode($last_optimized_data));
|
663 |
|
|
|
|
|
|
|
|
|
|
|
664 |
}
|
665 |
|
666 |
|
65 |
return array("status" => "error", "error" => __("Empty credentials, please try again.", IOWD_PREFIX));
|
66 |
}
|
67 |
|
68 |
+
$images_data = $this->get_attachments($ids, $other, $meta, $response["remained"]);
|
|
|
|
|
|
|
|
|
|
|
69 |
|
70 |
$data_count = count($images_data);
|
71 |
+
if($data_count == 0){
|
72 |
+
set_transient("iowd_response_error", 'no_image_data');
|
73 |
+
return array("status" => "error", "data_count" => $data_count);
|
74 |
+
}
|
75 |
// add temp data
|
76 |
add_option("iowd_image_temp_data_" . $id, $images_data);
|
77 |
add_option("iowd_data_count_" . $id, $data_count);
|
79 |
return array("status" => "ok", "data_count" => $data_count);
|
80 |
}
|
81 |
|
82 |
+
public function get_attachments($ids = array(), $include_others = false, $meta = array(), $remained = null, $limit = null)
|
83 |
{
|
84 |
+
ini_set('max_execution_time', 300);
|
85 |
+
|
86 |
clearstatcache();
|
87 |
$options = $this->options;
|
88 |
$image_data = array();
|
89 |
|
90 |
+
$optimized_data = get_site_transient("iowd_optimized");
|
91 |
+
$optimized_data = $optimized_data ? $optimized_data : array();
|
92 |
|
93 |
$optimize_thumbs = explode(",", $options["optimize_thumbs"]);
|
94 |
+
$uploads = wp_get_upload_dir();
|
95 |
+
|
96 |
+
$limitation = IOWD_Helper::limitation();
|
97 |
+
|
98 |
+
global $wpdb;
|
99 |
+
|
100 |
+
$where_ids = $ids ? "AND ID IN (" . implode(",", $ids) . ")" : "";
|
101 |
+
$limit_by = $limit !== null ? ' LIMIT ' . $limit . ', 2000' : '';
|
102 |
+
|
103 |
+
$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
|
104 |
+
T_POSTS.ID = T_POSTMETA.post_id AND T_POSTMETA.meta_key = '_wp_attachment_metadata' WHERE post_type='attachment' " . $where_ids . $limit_by);
|
105 |
|
|
|
|
|
|
|
|
|
|
|
|
|
106 |
|
107 |
+
$for_checking = array();
|
108 |
if (empty($attachments) === false) {
|
109 |
foreach ($attachments as $attachment) {
|
110 |
+
if (count($image_data) > $limitation["limit"] && is_null($limit)) {
|
111 |
+
break;
|
112 |
+
}
|
113 |
+
$meta = $attachment->meta_value ? unserialize($attachment->meta_value) : $meta;
|
114 |
+
$sizes = isset($meta["sizes"]) ? $meta["sizes"] : array();
|
115 |
+
$file = isset($meta["file"]) ? $meta["file"] : "no_file";
|
116 |
+
$file_name = $uploads['basedir'] . "/" . $file;
|
117 |
+
$path = $uploads['baseurl'] . "/" . $file;
|
118 |
+
|
119 |
+
//check for getting correct data
|
120 |
+
if (!$ids) {
|
121 |
+
if (in_array($path, $optimized_data) && in_array($attachment->ID . "_full", array_keys($optimized_data))) {
|
122 |
+
continue;
|
123 |
+
}
|
124 |
+
}
|
125 |
+
|
126 |
+
if (!file_exists($file_name) || in_array($file_name, $for_checking)) {
|
127 |
continue;
|
128 |
}
|
129 |
+
$for_checking[] = $file_name;
|
130 |
$type = pathinfo($file_name, PATHINFO_EXTENSION);
|
131 |
$size = filesize($file_name);
|
132 |
+
|
133 |
// check type
|
134 |
if (!in_array(strtolower($type), $this->allowed_types) || $this->check_optimization_level($type) === false) {
|
135 |
continue;
|
136 |
}
|
137 |
|
138 |
if (($this->skip_small_images($size) === true && $this->skip_large_images($size) === true && $options["exclude_full_size"] == 0) || $this->is_single == true) {
|
139 |
+
if (is_null($limit)) {
|
140 |
+
$image = array();
|
141 |
+
$image["path"] = $path;
|
142 |
+
$image["file"] = $file_name;
|
143 |
+
$image["post_id"] = $attachment->ID;
|
144 |
+
$image["size"] = "full";
|
145 |
+
$image["image_size"] = $size;
|
146 |
+
$image["media"] = 1;
|
147 |
+
$image["converted"] = 0;
|
148 |
+
$image["resized"] = 0;
|
149 |
+
$image["single"] = $this->is_single;
|
150 |
+
$image["transparent"] = $type == "png" && IOWD_Util::is_transparent_png($file_name) ? 1 : 0;
|
151 |
+
|
152 |
+
$image_data[] = $image;
|
153 |
+
} else {
|
154 |
+
$image_data["media"][$attachment->ID . "_full"] = $path;
|
155 |
+
$image_data["attachments"][$attachment->ID] = $attachment->ID;
|
156 |
+
}
|
157 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
158 |
}
|
159 |
$attachment_root_url = str_replace(basename($path), "", $path);
|
160 |
+
$attachment_root_dir = str_replace(basename($file_name), "", $file_name);
|
|
|
|
|
|
|
161 |
|
162 |
foreach ($sizes as $size => $file) {
|
163 |
if (in_array($size, $optimize_thumbs)) {
|
164 |
+
if (in_array($attachment_root_dir . $file["file"], $for_checking) || !file_exists($attachment_root_dir . $file["file"]) ) {
|
165 |
+
continue;
|
166 |
+
}
|
167 |
+
if (!$ids) {
|
168 |
+
if (in_array($attachment_root_url . $file["file"], $optimized_data) && in_array($attachment->ID . "_" . $size, array_keys($optimized_data))) {
|
169 |
+
continue;
|
170 |
+
}
|
171 |
+
}
|
172 |
$image_size = filesize($attachment_root_dir . $file["file"]);
|
173 |
if (($this->skip_small_images($image_size) === true && $this->skip_large_images($image_size) === true) || $this->is_single == true) {
|
174 |
+
if (is_null($limit)) {
|
175 |
+
$image = array();
|
176 |
+
$image["path"] = $attachment_root_url . $file["file"];
|
177 |
+
$image["file"] = $attachment_root_dir . $file["file"];
|
178 |
+
$image["post_id"] = $attachment->ID;
|
179 |
+
$image["size"] = $size;
|
180 |
+
$image["image_size"] = $image_size;
|
181 |
+
$image["media"] = 1;
|
182 |
+
$image["converted"] = 0;
|
183 |
+
$image["resized"] = 0;
|
184 |
+
$image["single"] = $this->is_single;
|
185 |
+
$image["transparent"] = $type == "png" && IOWD_Util::is_transparent_png($attachment_root_dir . $file["file"]) ? 1 : 0;
|
186 |
+
$image_data[] = $image;
|
187 |
+
} else {
|
188 |
+
$image_data["media_sizes"][$attachment->ID . "_" . $size] = $attachment_root_url . $file["file"];
|
189 |
+
$image_data["attachments"][$attachment->ID] = $attachment->ID;
|
190 |
+
}
|
191 |
+
$for_checking[] = $attachment_root_dir . $file["file"];
|
192 |
}
|
193 |
}
|
194 |
}
|
195 |
}
|
196 |
}
|
197 |
+
// free memory
|
198 |
+
unset($for_checking);
|
199 |
|
200 |
+
if ($include_others == true && ((count($image_data) < $limitation["limit"] && is_null($limit)) || $limit !== null)) {
|
201 |
|
202 |
$protocaol = isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] != 'off' ? 'https' : 'http';
|
203 |
|
222 |
$max_iowd_post = $max_iowd_post ? substr($max_iowd_post->post_id, 5) + 1 : 1;
|
223 |
|
224 |
foreach ($other_images as $other_image) {
|
225 |
+
if (count($image_data) > $limitation["limit"] && is_null($limit)) {
|
226 |
+
break;
|
227 |
+
}
|
228 |
+
if (in_array($other_image, $optimized_data)) {
|
229 |
+
continue;
|
230 |
+
}
|
231 |
+
|
232 |
$other_path = str_replace($protocaol . '://' . $_SERVER['SERVER_NAME'], $_SERVER['DOCUMENT_ROOT'], $other_image);
|
233 |
|
234 |
if (!file_exists($other_path)) {
|
240 |
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)) {
|
241 |
continue;
|
242 |
}
|
243 |
+
if(is_null($limit)){
|
244 |
+
$image = array();
|
245 |
+
$image["path"] = $other_image;
|
246 |
+
$image["file"] = str_replace($protocaol . '://' . $_SERVER['SERVER_NAME'], $_SERVER['DOCUMENT_ROOT'], $other_image);
|
247 |
+
$image["post_id"] = "iowd_" . $max_iowd_post;
|
248 |
+
$image["size"] = "full";
|
249 |
+
|
250 |
+
$image["image_size"] = $size;
|
251 |
+
$image["media"] = 0;
|
252 |
+
$image["converted"] = 0;
|
253 |
+
$image["resized"] = 0;
|
254 |
+
$image["single"] = $this->is_single;
|
255 |
+
$image["transparent"] = $type == "png" && IOWD_Util::is_transparent_png($image["file"]) ? 1 : 0;
|
256 |
+
|
257 |
+
$image_data[] = $image;
|
258 |
+
} else{
|
259 |
+
$image_data["other"]["iowd_" . $max_iowd_post . "_full"] = $other_image;
|
260 |
+
}
|
261 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
262 |
$i++;
|
263 |
$max_iowd_post++;
|
264 |
}
|
265 |
}
|
266 |
}
|
267 |
|
268 |
+
if (is_null($limit)) {
|
269 |
+
if (!is_null($remained)) {
|
270 |
+
$image_data = array_slice($image_data, 0, $remained);
|
271 |
+
}
|
272 |
+
|
273 |
+
$images_count = count($image_data);
|
274 |
+
|
275 |
+
$attachments_data = array();
|
276 |
+
if ($images_count > 0) {
|
277 |
+
if ($images_count > $this->images_count) {
|
278 |
+
for ($i = 0; $i < ceil($images_count / $this->images_count); $i++) {
|
279 |
+
$attachments_data[$i] = array_slice($image_data, $i * $this->images_count, $this->images_count);
|
280 |
+
}
|
281 |
+
} else {
|
282 |
+
$attachments_data[0] = $image_data;
|
283 |
+
}
|
284 |
+
}
|
285 |
+
return $attachments_data;
|
286 |
+
} else {
|
287 |
+
set_site_transient("iowd_temp_scan_data_".$limit, $image_data);
|
288 |
+
return $image_data ? true : false;
|
289 |
}
|
290 |
|
291 |
+
}
|
292 |
+
|
293 |
+
|
294 |
+
public function scan($all_attachments)
|
295 |
+
{
|
296 |
+
$db_optimized_data = get_site_transient("iowd_optimized");
|
297 |
+
$db_optimized_data = $db_optimized_data ? $db_optimized_data : array();
|
298 |
+
|
299 |
+
|
300 |
+
// all data
|
301 |
+
$media = isset($all_attachments["media"]) ? $all_attachments["media"] : array();
|
302 |
+
$media_sizes = isset($all_attachments["media_sizes"]) ? $all_attachments["media_sizes"] : array();
|
303 |
+
$other = isset($all_attachments["other"]) ? $all_attachments["other"] : array();
|
304 |
+
$unique_attachments = isset($all_attachments["attachments"]) ? $all_attachments["attachments"] : 0;
|
305 |
+
|
306 |
+
$all_media_sizes = array_merge($media, $media_sizes);
|
307 |
+
$all_data_sizes = array_merge($all_media_sizes, $other);
|
308 |
+
$all_data = array_unique(array_merge($media, $other));
|
309 |
+
|
310 |
+
$optimized_data_other = array();
|
311 |
+
$optimized_data_media = array();
|
312 |
+
$optimized_data_media_sizes = array();
|
313 |
+
|
314 |
+
|
315 |
+
if ($db_optimized_data) {
|
316 |
+
foreach ($db_optimized_data as $post_id => $path) {
|
317 |
+
$parts = explode("_", $post_id);
|
318 |
+
|
319 |
+
if (count($parts) == 3 && $parts[0] == "iowd") {
|
320 |
+
$optimized_data_other[$post_id] = $path;
|
321 |
+
} else {
|
322 |
+
if ($parts[1] == "full") {
|
323 |
+
$optimized_data_media[$post_id] = $path;
|
324 |
+
}
|
325 |
+
$optimized_data_media_sizes[$post_id] = $path;
|
326 |
+
}
|
327 |
}
|
328 |
+
|
329 |
} else {
|
330 |
+
$db_optimized_data = array();
|
331 |
}
|
332 |
|
333 |
+
$optimized_data = array_merge($optimized_data_other ,$optimized_data_media);
|
334 |
|
335 |
+
$not_optimized_data = array_diff($all_data, $optimized_data);
|
336 |
+
$not_optimized_data_sizes = array_diff($all_data_sizes, $db_optimized_data);
|
337 |
+
$not_optimized_data_media = array_diff($media, $optimized_data_media);
|
338 |
+
$not_optimized_data_media_sizes = array_diff($all_media_sizes, $optimized_data_media_sizes);
|
339 |
+
$not_optimized_data_other = array_diff($other, $optimized_data_other);
|
340 |
+
|
341 |
+
$all_data_sizes = array_merge($all_data_sizes,$db_optimized_data);
|
342 |
+
$all_data = array_merge($all_data, $optimized_data);
|
343 |
+
|
344 |
+
|
345 |
+
|
346 |
+
return array(
|
347 |
+
"optimized_data" => count($optimized_data),
|
348 |
+
"optimized_data_sizes" => count($db_optimized_data),
|
349 |
+
"not_optimized_data" => count($not_optimized_data),
|
350 |
+
"not_optimized_data_sizes" => count($not_optimized_data_sizes),
|
351 |
+
"not_optimized_data_media" => count($unique_attachments),
|
352 |
+
"not_optimized_data_media_sizes" => count($not_optimized_data_media_sizes),
|
353 |
+
"not_optimized_data_other" => count($not_optimized_data_other),
|
354 |
+
"all_data_sizes" => count($all_data_sizes),
|
355 |
+
"all_data" => count($all_data),
|
356 |
+
);
|
357 |
+
}
|
358 |
+
|
359 |
+
public function scanOld()
|
360 |
+
{
|
361 |
+
$options = $this->options;
|
362 |
+
$db_optimized_data = get_site_transient("iowd_optimized");
|
363 |
+
$db_optimized_data = $db_optimized_data ? $db_optimized_data : array();
|
364 |
+
|
365 |
+
// all data
|
366 |
+
global $wpdb;
|
367 |
+
$attachments = $wpdb->get_col("SELECT T_POSTMETA.meta_value FROM ". $wpdb->prefix . "posts AS T_POSTS LEFT JOIN ". $wpdb->prefix . "postmeta AS T_POSTMETA ON
|
368 |
+
T_POSTS.ID = T_POSTMETA.post_id AND T_POSTMETA.meta_key = '_wp_attachment_metadata' WHERE post_type='attachment' ");
|
369 |
+
|
370 |
+
|
371 |
+
$all_dirs = $options["other_folders"] ? json_decode(htmlspecialchars_decode(stripslashes($options["other_folders"])), true) : array();
|
372 |
+
|
373 |
+
$other_images = array();
|
374 |
+
if (empty($all_dirs) === false) {
|
375 |
+
foreach ($all_dirs as $dir => $image_path) {
|
376 |
+
foreach ($image_path as $path) {
|
377 |
+
$other_images[] = $path;
|
378 |
+
}
|
379 |
+
}
|
380 |
+
}
|
381 |
+
$other_images = count(array_unique($other_images));
|
382 |
+
|
383 |
+
|
384 |
+
$optimized_data_other = 0;
|
385 |
+
$optimized_data_media = 0;
|
386 |
+
$optimized_data_media_sizes = 0;
|
387 |
+
|
388 |
+
$all_data = count($attachments) + $other_images;
|
389 |
+
$all_media_sizes = array_reduce($attachments, function($initial, $value){
|
390 |
+
|
391 |
+
$value = unserialize($value);
|
392 |
+
$initial += 1 + count($value["sizes"]);
|
393 |
+
|
394 |
+
return $initial;
|
395 |
+
});
|
396 |
+
|
397 |
+
$post_ids = array();
|
398 |
+
if($db_optimized_data){
|
399 |
+
foreach($db_optimized_data as $post_id => $path){
|
400 |
+
$parts = explode("_", $post_id);
|
401 |
+
$post_id = $parts[1];
|
402 |
+
|
403 |
+
if(count($parts) == 3 && $parts[0] == "iowd"){
|
404 |
+
$post_id = $path;
|
405 |
+
$optimized_data_other++;
|
406 |
+
} else {
|
407 |
+
if($parts[1] == "full"){
|
408 |
+
$optimized_data_media++;
|
409 |
+
}
|
410 |
+
$optimized_data_media_sizes++;
|
411 |
+
}
|
412 |
+
|
413 |
+
$post_ids[] = $post_id;
|
414 |
+
}
|
415 |
+
$db_optimized_data = count($db_optimized_data);
|
416 |
+
} else {
|
417 |
+
$db_optimized_data = 0;
|
418 |
+
}
|
419 |
+
|
420 |
+
$optimized_data = count($post_ids);
|
421 |
+
$optimized_data_sizes = $db_optimized_data;
|
422 |
+
|
423 |
+
$not_optimized_data = $all_data - $optimized_data;
|
424 |
+
$not_optimized_data_sizes = $all_media_sizes + $other_images - $optimized_data_sizes;
|
425 |
+
|
426 |
+
$not_optimized_data_media = count($attachments) - $optimized_data_media;
|
427 |
+
$not_optimized_data_media_sizes = $all_media_sizes - $optimized_data_media_sizes;
|
428 |
+
|
429 |
+
$not_optimized_data_other = $other_images - $optimized_data_other;
|
430 |
+
$all_data_sizes = $all_media_sizes + $other_images;
|
431 |
+
|
432 |
+
return array(
|
433 |
+
"optimized_data" => $optimized_data,
|
434 |
+
"optimized_data_sizes" => $optimized_data_sizes,
|
435 |
+
"not_optimized_data" => $not_optimized_data,
|
436 |
+
"not_optimized_data_sizes" => $not_optimized_data_sizes,
|
437 |
+
"not_optimized_data_media" => $not_optimized_data_media,
|
438 |
+
"not_optimized_data_media_sizes" => $not_optimized_data_media_sizes,
|
439 |
+
"not_optimized_data_other" => $not_optimized_data_other,
|
440 |
+
"all_data" => $all_data,
|
441 |
+
"all_data_sizes" => $all_data_sizes,
|
442 |
+
);
|
443 |
}
|
444 |
|
445 |
private function check_optimization_level($mime_type)
|
496 |
return true;
|
497 |
}
|
498 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
499 |
private function get_current_opt_level($path)
|
500 |
{
|
501 |
$options = $this->options;
|
527 |
$post_ids = array();
|
528 |
for ($i = 0; $i < count($images_data); $i++) {
|
529 |
$image_data = $images_data[$i];
|
530 |
+
if ($options["keep_originals"] == 1) {
|
531 |
+
$this->keep_originals($image_data["file"]);
|
532 |
+
}
|
533 |
// if enable resizing
|
534 |
if ($options["enable_resizing"] == 1 || $options["enable_resizing_other"] == 1) {
|
535 |
$resize_data = $this->resize($image_data, $meta);
|
562 |
$db_post_ids = array_unique($db_post_ids);
|
563 |
set_transient("iowd_optimizing_post_ids", $db_post_ids);
|
564 |
|
565 |
+
GuzzleHttp\Promise\settle($response)->wait();
|
566 |
$response = $this->api_call_ajax($data, $s3->folder_name, $s3->sub_folder_name, $s3->credentials, $iteration, $id);
|
567 |
if (isset($response["status"]) && $response["status"] == "error") {
|
568 |
set_transient("iowd_response_error", $response["error"]);
|
598 |
|
599 |
if ($resized == 0) {
|
600 |
$iowd_image->load_image($item["file"]);
|
|
|
|
|
|
|
601 |
$flag = false;
|
602 |
list($width) = @getimagesize($item["file"]);
|
603 |
if ($item["media"] == 1 && $options["resize_media_images_width"] && $options["resize_media_images_height"] && $width > $options["resize_media_images_width"] && $options["enable_resizing"] == 1 && $item["size"] == "full") {
|
699 |
$_image_size = 0;
|
700 |
$_image_orig_size = 0;
|
701 |
$_image_count = 0;
|
702 |
+
$paths = array();
|
703 |
for ($i = 0; $i < count($request); $i++) {
|
704 |
$request_row = $request[$i];
|
705 |
$response_row = isset($body[$request_row["post_id"] . ":" . $request_row["size"]]) ? $body[$request_row["post_id"] . ":" . $request_row["size"]] : false;
|
751 |
$_image_size += $row_data["image_size"];
|
752 |
$_image_orig_size += $img_orig_size;
|
753 |
$_image_count += 1;
|
754 |
+
$paths[$request_row["post_id"] . "_" . $request_row["size"]] = $request_row["path"];
|
755 |
}
|
756 |
|
757 |
$last_optimized_data = get_site_transient("iowd_last_optimized_data");
|
766 |
|
767 |
set_site_transient("iowd_last_optimized_data", json_encode($last_optimized_data));
|
768 |
|
769 |
+
$db_paths = get_site_transient("iowd_optimized");
|
770 |
+
$db_paths = $db_paths ? $db_paths : array();
|
771 |
+
$paths = array_merge($db_paths, $paths);
|
772 |
+
set_site_transient("iowd_optimized", $paths);
|
773 |
+
|
774 |
}
|
775 |
|
776 |
|
includes/iowd-settings.php
CHANGED
@@ -479,24 +479,27 @@ class IOWD_Settings
|
|
479 |
|
480 |
public static function save_settings()
|
481 |
{
|
482 |
-
|
483 |
-
if (isset($_POST["standard_setting"]) && $_POST["standard_setting"]) {
|
484 |
-
self::save_standard_settings();
|
485 |
-
} else {
|
486 |
-
$old_settings = json_decode(get_option(IOWD_PREFIX . "_options"), true);
|
487 |
-
$new_settings = array();
|
488 |
-
foreach ($old_settings as $setting_key => $setting) {
|
489 |
-
$new_settings[$setting_key] = isset($_POST[$setting_key]) ? esc_html($_POST[$setting_key]) : $setting;
|
490 |
-
}
|
491 |
-
if ($new_settings["scheduled_optimization"] == "0") {
|
492 |
-
wp_clear_scheduled_hook('iowd_optimize');
|
493 |
-
}
|
494 |
|
495 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
496 |
}
|
497 |
-
$iowd_tabs_active = isset($_POST["iowd_tabs_active"]) ? $_POST["iowd_tabs_active"] : "general";
|
498 |
-
$ids = isset($_POST["ids"]) ? $_POST["ids"] : "";
|
499 |
-
IOWD_Helper::redirect(array("page" => "iowd_settings", "msg" => "1", "iowd_tabs_active" => $iowd_tabs_active, "ids" => $ids));
|
500 |
}
|
501 |
|
502 |
public static function save_standard_settings()
|
@@ -555,9 +558,7 @@ class IOWD_Settings
|
|
555 |
$other_folders = json_decode(htmlspecialchars_decode(stripslashes($options["other_folders"])), true);
|
556 |
|
557 |
$other = empty($other_folders) === false && is_array($other_folders) ? true : false;
|
558 |
-
|
559 |
-
$scan = $optimize->scan(array(), $other);
|
560 |
-
|
561 |
$iowd_tabs_active = isset($_REQUEST["iowd_tabs_active"]) ? $_REQUEST["iowd_tabs_active"] : "general";
|
562 |
$iowd_sizes = IOWD_Helper::wp_get_image_sizes();
|
563 |
|
@@ -606,6 +607,8 @@ class IOWD_Settings
|
|
606 |
$msg = __("No agreement found.", IOWD_PREFIX);
|
607 |
} else if ($error == "empty_credentials") {
|
608 |
$msg = __("Empty credentials, please try again.", IOWD_PREFIX);
|
|
|
|
|
609 |
}
|
610 |
|
611 |
if ($msg) {
|
479 |
|
480 |
public static function save_settings()
|
481 |
{
|
482 |
+
if(isset($_POST["action"]) && $_POST["action"] == "save_settings") {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
483 |
|
484 |
+
check_admin_referer('nonce_' . IOWD_PREFIX, 'nonce_' . IOWD_PREFIX);
|
485 |
+
if (isset($_POST["standard_setting"]) && $_POST["standard_setting"]) {
|
486 |
+
self::save_standard_settings();
|
487 |
+
} else {
|
488 |
+
$old_settings = json_decode(get_option(IOWD_PREFIX . "_options"), true);
|
489 |
+
$new_settings = array();
|
490 |
+
foreach ($old_settings as $setting_key => $setting) {
|
491 |
+
$new_settings[$setting_key] = isset($_POST[$setting_key]) ? esc_html($_POST[$setting_key]) : $setting;
|
492 |
+
}
|
493 |
+
if ($new_settings["scheduled_optimization"] == "0") {
|
494 |
+
wp_clear_scheduled_hook('iowd_optimize');
|
495 |
+
}
|
496 |
+
|
497 |
+
update_option(IOWD_PREFIX . "_options", json_encode($new_settings));
|
498 |
+
}
|
499 |
+
$iowd_tabs_active = isset($_POST["iowd_tabs_active"]) ? $_POST["iowd_tabs_active"] : "general";
|
500 |
+
$ids = isset($_POST["ids"]) ? $_POST["ids"] : "";
|
501 |
+
IOWD_Helper::redirect(array("page" => "iowd_settings", "msg" => "1", "iowd_tabs_active" => $iowd_tabs_active, "ids" => $ids));
|
502 |
}
|
|
|
|
|
|
|
503 |
}
|
504 |
|
505 |
public static function save_standard_settings()
|
558 |
$other_folders = json_decode(htmlspecialchars_decode(stripslashes($options["other_folders"])), true);
|
559 |
|
560 |
$other = empty($other_folders) === false && is_array($other_folders) ? true : false;
|
561 |
+
|
|
|
|
|
562 |
$iowd_tabs_active = isset($_REQUEST["iowd_tabs_active"]) ? $_REQUEST["iowd_tabs_active"] : "general";
|
563 |
$iowd_sizes = IOWD_Helper::wp_get_image_sizes();
|
564 |
|
607 |
$msg = __("No agreement found.", IOWD_PREFIX);
|
608 |
} else if ($error == "empty_credentials") {
|
609 |
$msg = __("Empty credentials, please try again.", IOWD_PREFIX);
|
610 |
+
} else if ($error == "no_image_data"){
|
611 |
+
$msg = __("No images found, please check your options.", IOWD_PREFIX);
|
612 |
}
|
613 |
|
614 |
if ($msg) {
|
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.
|
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.2
|
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.
|
12 |
private static $page;
|
13 |
private $reg_autoloader = false;
|
14 |
private $options = array();
|
@@ -19,8 +19,8 @@ class IOWD
|
|
19 |
self::$page = isset($_GET["page"]) ? $_GET["page"] : 'iowd';
|
20 |
$this->options = json_decode(get_option(IOWD_PREFIX . "_options"), true);
|
21 |
|
22 |
-
add_action('
|
23 |
-
|
24 |
|
25 |
// ajax
|
26 |
add_action('wp_ajax_choose_dirs', array($this, 'ajax'));
|
@@ -38,6 +38,8 @@ class IOWD
|
|
38 |
add_action('admin_notices', array($this, 'notice'));
|
39 |
|
40 |
add_action('wp_ajax_get_subdirs', array($this, 'ajax'));
|
|
|
|
|
41 |
|
42 |
// autoloder
|
43 |
add_action('init', array($this, 'register_autoloader'));
|
8 |
{
|
9 |
|
10 |
protected static $instance = null;
|
11 |
+
private static $version = '1.0.2';
|
12 |
private static $page;
|
13 |
private $reg_autoloader = false;
|
14 |
private $options = array();
|
19 |
self::$page = isset($_GET["page"]) ? $_GET["page"] : 'iowd';
|
20 |
$this->options = json_decode(get_option(IOWD_PREFIX . "_options"), true);
|
21 |
|
22 |
+
add_action('admin_init', array('IOWD_Settings', 'save_settings'));
|
23 |
+
// add_action('admin_post_nopriv_save_settings', array('IOWD_Settings', 'save_settings'));
|
24 |
|
25 |
// ajax
|
26 |
add_action('wp_ajax_choose_dirs', array($this, 'ajax'));
|
38 |
add_action('admin_notices', array($this, 'notice'));
|
39 |
|
40 |
add_action('wp_ajax_get_subdirs', array($this, 'ajax'));
|
41 |
+
add_action('wp_ajax_scan', array($this, 'ajax'));
|
42 |
+
add_action('wp_ajax_scan_all', array($this, 'ajax'));
|
43 |
|
44 |
// autoloder
|
45 |
add_action('init', array($this, 'register_autoloader'));
|
readme.txt
CHANGED
@@ -4,7 +4,7 @@ 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.8
|
7 |
-
Stable tag: 1.0.
|
8 |
License: GPLv2 or later
|
9 |
License URI: http://www.gnu.org/licenses/gpl-2.0.html
|
10 |
|
@@ -54,6 +54,10 @@ Upgrade to [Image Optimizer WD Pro](https://web-dorado.com/products/wordpress-im
|
|
54 |
|
55 |
== Changelog ==
|
56 |
|
|
|
|
|
|
|
|
|
57 |
= 1.0.1 =
|
58 |
* Added: Check required PHP version
|
59 |
|
4 |
Tags: : compress, image, images optimization, performance, photos, lossless, optimize
|
5 |
Requires at least: 3.9
|
6 |
Tested up to: 4.8
|
7 |
+
Stable tag: 1.0.2
|
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.2 =
|
58 |
+
* Change: Require PHP 5.5
|
59 |
+
* Change: Using AJAX for getting optimizer scan info
|
60 |
+
|
61 |
= 1.0.1 =
|
62 |
* Added: Check required PHP version
|
63 |
|
views/iowd_settings_display.php
CHANGED
@@ -23,7 +23,7 @@ require_once IOWD_DIR_VIEWS . '/iowd_how_it_works_display.php';
|
|
23 |
<form
|
24 |
method="post"
|
25 |
id="settings_form"
|
26 |
-
action="
|
27 |
<?php wp_nonce_field('nonce_' . IOWD_PREFIX, 'nonce_' . IOWD_PREFIX); ?>
|
28 |
<div
|
29 |
class="iowd_header">
|
@@ -89,7 +89,8 @@ require_once IOWD_DIR_VIEWS . '/iowd_how_it_works_display.php';
|
|
89 |
data-value="balanced"><?php _e("BALANCED", IOWD_PREFIX); ?></div>
|
90 |
<div
|
91 |
class="iowd-standart-cell iowd-btn-disabled"
|
92 |
-
data-value="extreme"
|
|
|
93 |
<?php _e("EXTREME", IOWD_PREFIX); ?>
|
94 |
</div>
|
95 |
</div>
|
@@ -124,116 +125,95 @@ require_once IOWD_DIR_VIEWS . '/iowd_how_it_works_display.php';
|
|
124 |
</div>
|
125 |
<?php
|
126 |
} else {
|
127 |
-
|
128 |
-
|
129 |
-
|
130 |
-
|
131 |
-
|
132 |
-
|
133 |
-
|
134 |
-
|
135 |
-
|
136 |
-
|
137 |
-
|
138 |
-
|
139 |
-
|
140 |
-
$
|
141 |
-
|
142 |
-
|
143 |
-
|
144 |
-
|
145 |
-
|
146 |
-
|
147 |
-
|
148 |
-
|
149 |
-
|
150 |
-
|
151 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
152 |
}
|
153 |
?>
|
154 |
-
<
|
155 |
-
class="iowd-
|
156 |
-
|
157 |
-
</div>
|
158 |
-
<div
|
159 |
-
class="iowd-main iowd-media-seleced">
|
160 |
<?php
|
161 |
-
|
162 |
-
?>
|
163 |
-
</div>
|
164 |
-
<?php } ?>
|
165 |
-
<div
|
166 |
-
class="iowd-main">
|
167 |
-
<?php if ($scan["not_optimized_data"] > 0 || $scan["not_optimized_data_sizes"] > 0 || empty($attachments) === false) {
|
168 |
-
if ($limitation["already_optimized"] < $limitation["limit"]) {
|
169 |
-
$optimize_btn_class = "iowd-btn-primary";
|
170 |
-
$optimize_btn_id = "iowd_optimizing";
|
171 |
-
$return_false = "";
|
172 |
-
} else {
|
173 |
-
$optimize_btn_class = "iowd-btn-disabled";
|
174 |
-
$optimize_btn_id = "";
|
175 |
-
$return_false = "onclick='return false;'";
|
176 |
-
}
|
177 |
?>
|
178 |
-
|
179 |
-
|
180 |
-
|
181 |
-
|
182 |
-
|
183 |
-
|
184 |
-
|
185 |
-
_e("Bulk Optimizing", IOWD_PREFIX);
|
186 |
-
}
|
187 |
-
?>
|
188 |
-
</button>
|
189 |
-
<img
|
190 |
-
src="<?php echo IOWD_URL_IMG . '/spinner.gif'; ?>"
|
191 |
-
class="iowd-spinner"
|
192 |
-
style="display:none; vertical-align:sub;"/>
|
193 |
-
<?php if (empty($attachments) === true) { ?>
|
194 |
-
<div
|
195 |
-
class="iowd-help iowd-help-from-media">
|
196 |
-
<?php _e("You can optimize individual images via your ", IOWD_PREFIX); ?>
|
197 |
-
<strong><a
|
198 |
-
href="<?php echo admin_url("upload.php"); ?>"><?php _e("Media Library", IOWD_PREFIX); ?></a></strong>.
|
199 |
-
</div>
|
200 |
-
<?php } else {
|
201 |
-
?>
|
202 |
-
<a href="upload.php?page=iowd_settings"
|
203 |
-
class="iowd-btn iowd-btn-secondary iowd-cancel"
|
204 |
-
data-cancel-type="<?php echo empty($attachments) === true ? 1 : 0; ?>"><?php _e("Cancel", IOWD_PREFIX); ?></a>
|
205 |
-
<div
|
206 |
-
class="iowd-respose-status"></div>
|
207 |
-
<?php }
|
208 |
-
} else { ?>
|
209 |
<div
|
210 |
-
class="iowd-
|
211 |
-
|
212 |
-
|
213 |
-
|
214 |
-
echo '<strong class="iowd-up-to-date">';
|
215 |
-
_e("All images are optimized and up to date.", IOWD_PREFIX);
|
216 |
-
echo '</strong>';
|
217 |
-
} else {
|
218 |
-
echo '<strong>';
|
219 |
-
_e("Nothing is optimized yet.", IOWD_PREFIX);
|
220 |
-
echo '</strong>';
|
221 |
-
}
|
222 |
-
?>
|
223 |
-
|
224 |
</div>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
225 |
<?php } ?>
|
|
|
|
|
|
|
|
|
|
|
|
|
226 |
<div
|
227 |
-
class="iowd-loading-bar">
|
228 |
-
<div
|
229 |
-
class="iowd-loading-bar-inner"></div>
|
230 |
-
</div>
|
231 |
-
<a href="#"
|
232 |
-
class="iowd-abort">
|
233 |
-
<?php _e("Cancel", IOWD_PREFIX); ?>
|
234 |
-
</a>
|
235 |
</div>
|
236 |
-
|
|
|
|
|
|
|
|
|
|
|
237 |
}
|
238 |
if ($mode == "advanced") {
|
239 |
require_once(IOWD_DIR_VIEWS . '/iowd_settings_form_display.php');
|
@@ -249,7 +229,8 @@ require_once IOWD_DIR_VIEWS . '/iowd_how_it_works_display.php';
|
|
249 |
class="iowd-open-dir-tree-btn iowd-btn iowd-btn-small iowd-btn-primary"><?php _e("Select Directory", IOWD_PREFIX); ?></button>
|
250 |
<img
|
251 |
class="iowd_update_dirs"
|
252 |
-
src="<?php echo IOWD_URL_IMG . "/reset.png"; ?>"
|
|
|
253 |
<img
|
254 |
src="<?php echo IOWD_URL_IMG; ?>/spinner.gif"
|
255 |
class="iowd-spinner-select"
|
@@ -267,29 +248,15 @@ require_once IOWD_DIR_VIEWS . '/iowd_how_it_works_display.php';
|
|
267 |
<div
|
268 |
class="iowd_stat_content">
|
269 |
<h2><?php _e("Statistics", IOWD_PREFIX); ?></h2>
|
270 |
-
<?php
|
271 |
-
if ($scan["not_optimized_data"] > 0 || $scan["not_optimized_data_sizes"] > 0) {
|
272 |
-
$ratio = "<span class='iowd_opt_data'>" . $scan["optimized_data_sizes"] . "</span>/<span class='iowd_all_data'>" . $scan["all_data_sizes"] . "</span>";
|
273 |
-
$width = ($scan["optimized_data_sizes"] / $scan["all_data_sizes"]) * 100;
|
274 |
-
$style = 'style="width:' . $width . '%; "';
|
275 |
-
} else {
|
276 |
-
$ratio = "<span class='iowd_opt_data'>" . $scan["optimized_data_sizes"] . "</span>/<span class='iowd_all_data'>" . $scan["optimized_data_sizes"] . "</span>";
|
277 |
-
if($scan["optimized_data_sizes"] == 0){
|
278 |
-
$style = 'style="width:0%; "';
|
279 |
-
} else {
|
280 |
-
$style = 'style="width:100%; "';
|
281 |
-
}
|
282 |
-
}
|
283 |
-
?>
|
284 |
<div
|
285 |
class="iowd_stat-row">
|
286 |
<div
|
287 |
class="iowd-stat-progress-bar">
|
288 |
<div
|
289 |
-
class="iowd-stat-progress-bar-inner"
|
290 |
</div>
|
291 |
<div
|
292 |
-
class="iowd-stat-ratio"
|
293 |
</div>
|
294 |
<div
|
295 |
class="iowd_stat-row">
|
23 |
<form
|
24 |
method="post"
|
25 |
id="settings_form"
|
26 |
+
action="">
|
27 |
<?php wp_nonce_field('nonce_' . IOWD_PREFIX, 'nonce_' . IOWD_PREFIX); ?>
|
28 |
<div
|
29 |
class="iowd_header">
|
89 |
data-value="balanced"><?php _e("BALANCED", IOWD_PREFIX); ?></div>
|
90 |
<div
|
91 |
class="iowd-standart-cell iowd-btn-disabled"
|
92 |
+
data-value="extreme"
|
93 |
+
title="<?php _e("This option is disabled in free version.", IOWD_PREFIX); ?>">
|
94 |
<?php _e("EXTREME", IOWD_PREFIX); ?>
|
95 |
</div>
|
96 |
</div>
|
125 |
</div>
|
126 |
<?php
|
127 |
} else {
|
128 |
+
if (empty($attachments) === true) { ?>
|
129 |
+
<div
|
130 |
+
class="iowd-main iowd-stat-ajax">
|
131 |
+
<span><b> </b></span>
|
132 |
+
</div>
|
133 |
+
<?php } ?>
|
134 |
+
<?php if (empty($attachments) === false) {
|
135 |
+
$attachment_rows = "";
|
136 |
+
$all_images_count = 0;
|
137 |
+
for ($i = 0; $i < count($attachments); $i++) {
|
138 |
+
foreach ($attachments[$i] as $attachment) {
|
139 |
+
$attachment_rows .= '<div class="attachment-row attachment-row-' . $attachment["post_id"] . '">';
|
140 |
+
$attachment_rows .= basename($attachment["path"]);
|
141 |
+
if ($attachment["size"] == "full") {
|
142 |
+
$attachment_rows .= '<span class="iowd_remove_attachment" data-id="' . $attachment["post_id"] . '"> × </span>';
|
143 |
+
}
|
144 |
+
$attachment_rows .= '</div>';
|
145 |
+
$all_images_count++;
|
146 |
+
}
|
147 |
+
}
|
148 |
+
?>
|
149 |
+
<div
|
150 |
+
class="iowd-media-seleced-b">
|
151 |
+
<b><?php echo sprintf(__("You are going to optimize %d (totally %d) media images ", IOWD_PREFIX), count($ids), $all_images_count); ?></b>
|
152 |
+
</div>
|
153 |
+
<div
|
154 |
+
class="iowd-main iowd-media-seleced">
|
155 |
+
<?php
|
156 |
+
echo $attachment_rows;
|
157 |
+
?>
|
158 |
+
</div>
|
159 |
+
<?php } ?>
|
160 |
+
<div
|
161 |
+
class="iowd-main">
|
162 |
+
<div class="iowd-butn-ajax-container"
|
163 |
+
data-attachments="<?php echo empty($attachments) ? 0 : 1; ?>" style="display:none;">
|
164 |
+
<?php
|
165 |
+
if ($limitation["already_optimized"] < $limitation["limit"]) {
|
166 |
+
$optimize_btn_class = "iowd-btn-primary";
|
167 |
+
$optimize_btn_id = "iowd_optimizing";
|
168 |
+
$return_false = "";
|
169 |
+
} else {
|
170 |
+
$optimize_btn_class = "iowd-btn-disabled";
|
171 |
+
$optimize_btn_id = "";
|
172 |
+
$return_false = "onclick='return false;'";
|
173 |
}
|
174 |
?>
|
175 |
+
<button
|
176 |
+
class="iowd-btn <?php echo $optimize_btn_class; ?>"
|
177 |
+
id="<?php echo $optimize_btn_id; ?>" <?php echo $return_false; ?>>
|
|
|
|
|
|
|
178 |
<?php
|
179 |
+
_e("Bulk Optimizing", IOWD_PREFIX);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
180 |
?>
|
181 |
+
</button>
|
182 |
+
|
183 |
+
<img
|
184 |
+
src="<?php echo IOWD_URL_IMG . '/spinner.gif'; ?>"
|
185 |
+
class="iowd-spinner"
|
186 |
+
style="display:none; vertical-align:sub;"/>
|
187 |
+
<?php if (empty($attachments) === true) { ?>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
188 |
<div
|
189 |
+
class="iowd-help iowd-help-from-media">
|
190 |
+
<?php _e("You can optimize individual images via your ", IOWD_PREFIX); ?>
|
191 |
+
<strong><a
|
192 |
+
href="<?php echo admin_url("upload.php"); ?>"><?php _e("Media Library", IOWD_PREFIX); ?></a></strong>.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
193 |
</div>
|
194 |
+
<?php } else {
|
195 |
+
?>
|
196 |
+
<a href="upload.php?page=iowd_settings"
|
197 |
+
class="iowd-btn iowd-btn-secondary iowd-cancel"
|
198 |
+
data-cancel-type="<?php echo empty($attachments) === true ? 1 : 0; ?>"><?php _e("Cancel", IOWD_PREFIX); ?></a>
|
199 |
+
<div
|
200 |
+
class="iowd-respose-status"></div>
|
201 |
<?php } ?>
|
202 |
+
</div>
|
203 |
+
<div
|
204 |
+
class="iowd-optimized-txt iowd-optimized-ajax-text" style="display:none;">
|
205 |
+
</div>
|
206 |
+
<div
|
207 |
+
class="iowd-loading-bar">
|
208 |
<div
|
209 |
+
class="iowd-loading-bar-inner"></div>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
210 |
</div>
|
211 |
+
<a href="#"
|
212 |
+
class="iowd-abort">
|
213 |
+
<?php _e("Cancel", IOWD_PREFIX); ?>
|
214 |
+
</a>
|
215 |
+
</div>
|
216 |
+
<?php
|
217 |
}
|
218 |
if ($mode == "advanced") {
|
219 |
require_once(IOWD_DIR_VIEWS . '/iowd_settings_form_display.php');
|
229 |
class="iowd-open-dir-tree-btn iowd-btn iowd-btn-small iowd-btn-primary"><?php _e("Select Directory", IOWD_PREFIX); ?></button>
|
230 |
<img
|
231 |
class="iowd_update_dirs"
|
232 |
+
src="<?php echo IOWD_URL_IMG . "/reset.png"; ?>"
|
233 |
+
title="<?php _e("Update data", IOWD_PREFIX); ?>">
|
234 |
<img
|
235 |
src="<?php echo IOWD_URL_IMG; ?>/spinner.gif"
|
236 |
class="iowd-spinner-select"
|
248 |
<div
|
249 |
class="iowd_stat_content">
|
250 |
<h2><?php _e("Statistics", IOWD_PREFIX); ?></h2>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
251 |
<div
|
252 |
class="iowd_stat-row">
|
253 |
<div
|
254 |
class="iowd-stat-progress-bar">
|
255 |
<div
|
256 |
+
class="iowd-stat-progress-bar-inner"></div>
|
257 |
</div>
|
258 |
<div
|
259 |
+
class="iowd-stat-ratio"></div>
|
260 |
</div>
|
261 |
<div
|
262 |
class="iowd_stat-row">
|