Version Description
- Add CRON feature
- Code refactoring
- Fix issue for big Media library, with a limitation while fetching attachments
- Fix log path issues
Download this release
Release Info
Developer | resmushit |
Plugin | reSmush.it Image Optimizer |
Version | 0.2.0 |
Comparing to | |
See all releases |
Code changes from version 0.1.23 to 0.2.0
- classes/resmushit.class.php +51 -70
- classes/resmushitUI.class.php +74 -11
- css/resmushit.css +19 -2
- readme.txt +14 -4
- resmushit.admin.php +35 -3
- resmushit.inc.php +65 -8
- resmushit.php +101 -7
- resmushit.settings.php +5 -3
classes/resmushit.class.php
CHANGED
@@ -11,6 +11,7 @@
|
|
11 |
Class reSmushit {
|
12 |
|
13 |
const MAX_FILESIZE = 5242880;
|
|
|
14 |
|
15 |
/**
|
16 |
*
|
@@ -52,7 +53,7 @@ Class reSmushit {
|
|
52 |
global $wp_version;
|
53 |
|
54 |
if(filesize($file_path) > self::MAX_FILESIZE){
|
55 |
-
rlog('Error! Picture ' . $file_path . ' cannot be optimized, file size is above 5MB ('. reSmushitUI::sizeFormat(filesize($file_path)) .')');
|
56 |
return false;
|
57 |
}
|
58 |
|
@@ -97,14 +98,14 @@ Class reSmushit {
|
|
97 |
copy($file_path, $newPath);
|
98 |
}
|
99 |
file_put_contents($file_path, $data);
|
100 |
-
rlog("
|
101 |
return $json;
|
102 |
}
|
103 |
} else {
|
104 |
-
rlog("Webservice returned the following error while optimizing $file_path : Code #" . $json->error . " - " . $json->error_long);
|
105 |
}
|
106 |
} else {
|
107 |
-
rlog("Cannot establish connection with reSmush.it webservice while optimizing $file_path (timeout of " . RESMUSHIT_TIMEOUT . "sec.)");
|
108 |
}
|
109 |
return false;
|
110 |
}
|
@@ -132,7 +133,7 @@ Class reSmushit {
|
|
132 |
$fileInfo = pathinfo(get_attached_file( $attachment_id ));
|
133 |
|
134 |
$originalFile = $basepath . $fileInfo['filename'] . '-unsmushed.' . $fileInfo['extension'];
|
135 |
-
rlog('Revert original image for : ' . get_attached_file( $attachment_id ));
|
136 |
|
137 |
if(file_exists($originalFile))
|
138 |
copy($originalFile, get_attached_file( $attachment_id ));
|
@@ -145,9 +146,6 @@ Class reSmushit {
|
|
145 |
|
146 |
|
147 |
|
148 |
-
|
149 |
-
|
150 |
-
|
151 |
/**
|
152 |
*
|
153 |
* Delete Original file (-unsmushed)
|
@@ -263,8 +261,6 @@ Class reSmushit {
|
|
263 |
|
264 |
|
265 |
|
266 |
-
|
267 |
-
|
268 |
/**
|
269 |
*
|
270 |
* Get a list of non optimized pictures
|
@@ -272,7 +268,7 @@ Class reSmushit {
|
|
272 |
* @param none
|
273 |
* @return json of unsmushed pictures attachments ID
|
274 |
*/
|
275 |
-
public static function getNonOptimizedPictures(){
|
276 |
global $wpdb;
|
277 |
$tmp = array();
|
278 |
$unsmushed_images = array();
|
@@ -280,70 +276,55 @@ Class reSmushit {
|
|
280 |
$already_optimized_images_array = array();
|
281 |
$disabled_images_array = array();
|
282 |
$files_not_found = array();
|
283 |
-
|
284 |
-
$
|
285 |
-
"
|
286 |
-
|
287 |
-
$wpdb->posts.guid as guid,
|
288 |
-
$wpdb->postmeta.meta_value as file_meta
|
289 |
-
from $wpdb->posts
|
290 |
-
inner join $wpdb->postmeta on $wpdb->posts.ID = $wpdb->postmeta.post_id and $wpdb->postmeta.meta_key = %s
|
291 |
-
where $wpdb->posts.post_type = %s
|
292 |
-
and $wpdb->posts.post_mime_type like %s
|
293 |
-
and ($wpdb->posts.post_mime_type = 'image/jpeg' OR $wpdb->posts.post_mime_type = 'image/gif' OR $wpdb->posts.post_mime_type = 'image/png')",
|
294 |
-
array('_wp_attachment_metadata','attachment', 'image%')
|
295 |
-
);
|
296 |
-
|
297 |
-
$queryAlreadyOptimizedPictures = $wpdb->prepare(
|
298 |
-
"select
|
299 |
-
$wpdb->posts.ID as ID
|
300 |
-
from $wpdb->posts
|
301 |
-
inner join $wpdb->postmeta on $wpdb->posts.ID = $wpdb->postmeta.post_id and $wpdb->postmeta.meta_key = %s
|
302 |
-
where $wpdb->postmeta.meta_value = %s",
|
303 |
-
array('resmushed_quality', self::getPictureQualitySetting())
|
304 |
-
);
|
305 |
-
|
306 |
-
$queryDisabledPictures = $wpdb->prepare(
|
307 |
-
"select
|
308 |
-
$wpdb->posts.ID as ID
|
309 |
-
from $wpdb->posts
|
310 |
-
inner join $wpdb->postmeta on $wpdb->posts.ID = $wpdb->postmeta.post_id and $wpdb->postmeta.meta_key = %s",
|
311 |
-
array('resmushed_disabled')
|
312 |
-
);
|
313 |
-
|
314 |
|
315 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
316 |
// Get the images in the attachement table
|
317 |
-
$all_images = $wpdb->get_results($
|
318 |
-
$already_optimized_images = $wpdb->get_results($queryAlreadyOptimizedPictures);
|
319 |
-
$disabled_images = $wpdb->get_results($queryDisabledPictures);
|
320 |
-
|
321 |
-
foreach($already_optimized_images as $image)
|
322 |
-
$already_optimized_images_array[] = $image->ID;
|
323 |
-
|
324 |
-
foreach($disabled_images as $image)
|
325 |
-
$disabled_images_array[] = $image->ID;
|
326 |
-
|
327 |
|
328 |
foreach($all_images as $image){
|
329 |
-
|
330 |
-
|
331 |
-
|
332 |
-
|
333 |
-
|
334 |
-
|
335 |
-
|
336 |
-
|
337 |
-
|
338 |
-
|
339 |
-
|
340 |
-
|
341 |
-
continue;
|
342 |
-
}
|
343 |
-
|
344 |
-
$unsmushed_images[] = $tmp;
|
345 |
}
|
346 |
-
|
|
|
347 |
}
|
348 |
return json_encode(array('nonoptimized' => $unsmushed_images, 'filestoobig' => $files_too_big, 'filesnotfound' => $files_not_found));
|
349 |
}
|
11 |
Class reSmushit {
|
12 |
|
13 |
const MAX_FILESIZE = 5242880;
|
14 |
+
const MAX_ATTACHMENTS_REQ = 1000;
|
15 |
|
16 |
/**
|
17 |
*
|
53 |
global $wp_version;
|
54 |
|
55 |
if(filesize($file_path) > self::MAX_FILESIZE){
|
56 |
+
rlog('Error! Picture ' . str_replace(ABSPATH, '/', $file_path) . ' cannot be optimized, file size is above 5MB ('. reSmushitUI::sizeFormat(filesize($file_path)) .')', 'WARNING');
|
57 |
return false;
|
58 |
}
|
59 |
|
98 |
copy($file_path, $newPath);
|
99 |
}
|
100 |
file_put_contents($file_path, $data);
|
101 |
+
rlog("Optimized file " . str_replace(ABSPATH, '/', $file_path) . " from " . reSmushitUI::sizeFormat($json->src_size) . " to " . reSmushitUI::sizeFormat($json->dest_size));
|
102 |
return $json;
|
103 |
}
|
104 |
} else {
|
105 |
+
rlog("Webservice returned the following error while optimizing $file_path : Code #" . $json->error . " - " . $json->error_long, 'ERROR');
|
106 |
}
|
107 |
} else {
|
108 |
+
rlog("Cannot establish connection with reSmush.it webservice while optimizing $file_path (timeout of " . RESMUSHIT_TIMEOUT . "sec.)", 'ERROR');
|
109 |
}
|
110 |
return false;
|
111 |
}
|
133 |
$fileInfo = pathinfo(get_attached_file( $attachment_id ));
|
134 |
|
135 |
$originalFile = $basepath . $fileInfo['filename'] . '-unsmushed.' . $fileInfo['extension'];
|
136 |
+
rlog('Revert original image for : ' . str_replace(ABSPATH, '/', get_attached_file( $attachment_id )));
|
137 |
|
138 |
if(file_exists($originalFile))
|
139 |
copy($originalFile, get_attached_file( $attachment_id ));
|
146 |
|
147 |
|
148 |
|
|
|
|
|
|
|
149 |
/**
|
150 |
*
|
151 |
* Delete Original file (-unsmushed)
|
261 |
|
262 |
|
263 |
|
|
|
|
|
264 |
/**
|
265 |
*
|
266 |
* Get a list of non optimized pictures
|
268 |
* @param none
|
269 |
* @return json of unsmushed pictures attachments ID
|
270 |
*/
|
271 |
+
public static function getNonOptimizedPictures($id_only = FALSE){
|
272 |
global $wpdb;
|
273 |
$tmp = array();
|
274 |
$unsmushed_images = array();
|
276 |
$already_optimized_images_array = array();
|
277 |
$disabled_images_array = array();
|
278 |
$files_not_found = array();
|
279 |
+
$extra_select = "";
|
280 |
+
if($id_only == FALSE) {
|
281 |
+
$extra_select = ",POSTS.guid as guid, METAATTACH.meta_value as file_meta";
|
282 |
+
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
283 |
|
284 |
+
$queryUnoptimizedPicture = $wpdb->prepare(
|
285 |
+
"SELECT ATTACHMENTS.* FROM (
|
286 |
+
select
|
287 |
+
POSTS.ID as ID, METAQLTY.meta_value as qlty, METADISABLED.meta_value as disabled
|
288 |
+
$extra_select
|
289 |
+
from wp_posts as POSTS
|
290 |
+
inner join
|
291 |
+
wp_postmeta as METAATTACH on POSTS.ID = METAATTACH.post_id
|
292 |
+
and METAATTACH.meta_key = %s
|
293 |
+
left join
|
294 |
+
wp_postmeta as METAQLTY on POSTS.ID = METAQLTY.post_id
|
295 |
+
and METAQLTY.meta_key = %s
|
296 |
+
left join
|
297 |
+
wp_postmeta as METADISABLED on POSTS.ID = METADISABLED.post_id
|
298 |
+
and METADISABLED.meta_key = %s
|
299 |
+
where
|
300 |
+
POSTS.post_type = %s
|
301 |
+
and (POSTS.post_mime_type = 'image/jpeg' OR POSTS.post_mime_type = 'image/gif' OR POSTS.post_mime_type = 'image/png')
|
302 |
+
) as ATTACHMENTS
|
303 |
+
WHERE
|
304 |
+
(ATTACHMENTS.qlty != '%s' OR ATTACHMENTS.qlty IS NULL)
|
305 |
+
AND ATTACHMENTS.disabled IS NULL
|
306 |
+
LIMIT %d",
|
307 |
+
array('_wp_attachment_metadata','resmushed_quality','resmushed_disabled','attachment', self::getPictureQualitySetting(), self::MAX_ATTACHMENTS_REQ)
|
308 |
+
);
|
309 |
// Get the images in the attachement table
|
310 |
+
$all_images = $wpdb->get_results($queryUnoptimizedPicture);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
311 |
|
312 |
foreach($all_images as $image){
|
313 |
+
$tmp = array();
|
314 |
+
$tmp['ID'] = $image->ID;
|
315 |
+
$tmp['attachment_metadata'] = unserialize($image->file_meta);
|
316 |
+
|
317 |
+
if( !file_exists(get_attached_file( $image->ID )) ) {
|
318 |
+
$files_not_found[] = $tmp;
|
319 |
+
continue;
|
320 |
+
}
|
321 |
+
//If filesize > 5MB, we do not optimize this picture
|
322 |
+
if( filesize(get_attached_file( $image->ID )) > self::MAX_FILESIZE ){
|
323 |
+
$files_too_big[] = $tmp;
|
324 |
+
continue;
|
|
|
|
|
|
|
|
|
325 |
}
|
326 |
+
|
327 |
+
$unsmushed_images[] = $tmp;
|
328 |
}
|
329 |
return json_encode(array('nonoptimized' => $unsmushed_images, 'filestoobig' => $files_too_big, 'filesnotfound' => $files_not_found));
|
330 |
}
|
classes/resmushitUI.class.php
CHANGED
@@ -88,7 +88,7 @@ Class reSmushitUI {
|
|
88 |
*/
|
89 |
public static function settingsPanel() {
|
90 |
self::fullWidthPanelWrapper(__('Settings', 'resmushit'), null, 'orange');
|
91 |
-
|
92 |
echo '<div class="rsmt-settings">
|
93 |
<form method="post" action="options.php" id="rsmt-options-form">';
|
94 |
settings_fields( 'resmushit-settings' );
|
@@ -99,6 +99,7 @@ Class reSmushitUI {
|
|
99 |
. self::addSetting("checkbox", __("Optimize on upload", 'resmushit'), __("All future images uploaded will be automatically optimized", 'resmushit'), "resmushit_on_upload")
|
100 |
. self::addSetting("checkbox", __("Enable statistics", 'resmushit'), __("Generates statistics about optimized pictures", 'resmushit'), "resmushit_statistics")
|
101 |
. self::addSetting("checkbox", __("Enable logs", 'resmushit'), __("Enable file logging (for developers)", 'resmushit'), "resmushit_logs")
|
|
|
102 |
. '</table>';
|
103 |
submit_button();
|
104 |
echo '</form></div>';
|
@@ -124,20 +125,39 @@ Class reSmushitUI {
|
|
124 |
if(!$countNonOptimizedPictures) {
|
125 |
$additionnalClassNeedOptimization = 'disabled';
|
126 |
$additionnalClassNoNeedOptimization = NULL;
|
127 |
-
}
|
|
|
|
|
128 |
|
129 |
-
echo "<div class='rsmt-bulk'><div class='non-optimized-wrapper $additionnalClassNeedOptimization'><h3 class='icon_message warning'>"
|
130 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
131 |
. " <em>$countNonOptimizedPictures "
|
132 |
. __('non optimized pictures', 'resmushit')
|
133 |
. "</em>.</h3><p>"
|
134 |
-
. __('This action will resmush all pictures which have not been optimized to the good Image Quality Rate.', 'resmushit')
|
135 |
-
|
136 |
-
|
137 |
-
|
138 |
-
|
139 |
-
|
140 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
141 |
self::fullWidthPanelEndWrapper();
|
142 |
}
|
143 |
|
@@ -312,6 +332,49 @@ Class reSmushitUI {
|
|
312 |
}
|
313 |
|
314 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
315 |
|
316 |
|
317 |
/**
|
88 |
*/
|
89 |
public static function settingsPanel() {
|
90 |
self::fullWidthPanelWrapper(__('Settings', 'resmushit'), null, 'orange');
|
91 |
+
$new_label = "<span class='new'>" . __("New!", 'resmushit') . "</span>";
|
92 |
echo '<div class="rsmt-settings">
|
93 |
<form method="post" action="options.php" id="rsmt-options-form">';
|
94 |
settings_fields( 'resmushit-settings' );
|
99 |
. self::addSetting("checkbox", __("Optimize on upload", 'resmushit'), __("All future images uploaded will be automatically optimized", 'resmushit'), "resmushit_on_upload")
|
100 |
. self::addSetting("checkbox", __("Enable statistics", 'resmushit'), __("Generates statistics about optimized pictures", 'resmushit'), "resmushit_statistics")
|
101 |
. self::addSetting("checkbox", __("Enable logs", 'resmushit'), __("Enable file logging (for developers)", 'resmushit'), "resmushit_logs")
|
102 |
+
. self::addSetting("checkbox", $new_label . __("Process optimize on CRON", 'resmushit'), __("Will perform image optimization process through CRON tasks", 'resmushit'), "resmushit_cron")
|
103 |
. '</table>';
|
104 |
submit_button();
|
105 |
echo '</form></div>';
|
125 |
if(!$countNonOptimizedPictures) {
|
126 |
$additionnalClassNeedOptimization = 'disabled';
|
127 |
$additionnalClassNoNeedOptimization = NULL;
|
128 |
+
} else if ($countNonOptimizedPictures == reSmushit::MAX_ATTACHMENTS_REQ) {
|
129 |
+
$countNonOptimizedPictures .= '+';
|
130 |
+
}
|
131 |
|
132 |
+
echo "<div class='rsmt-bulk'><div class='non-optimized-wrapper $additionnalClassNeedOptimization'><h3 class='icon_message warning'>";
|
133 |
+
|
134 |
+
if(get_option('resmushit_cron') && get_option('resmushit_cron') == 1) {
|
135 |
+
echo "<em>$countNonOptimizedPictures "
|
136 |
+
. __('non optimized pictures will be automatically optimized', 'resmushit')
|
137 |
+
. "</em>.</h3><p>"
|
138 |
+
. __('These pictures will be automatically using schedule tasks (cronjobs).', 'resmushit')
|
139 |
+
. " "
|
140 |
+
. __('Image optimization process can be launched <b>manually</b> by clicking on the button below :', 'resmushit');
|
141 |
+
} else {
|
142 |
+
echo __('There is currently', 'resmushit')
|
143 |
. " <em>$countNonOptimizedPictures "
|
144 |
. __('non optimized pictures', 'resmushit')
|
145 |
. "</em>.</h3><p>"
|
146 |
+
. __('This action will resmush all pictures which have not been optimized to the good Image Quality Rate.', 'resmushit');
|
147 |
+
}
|
148 |
+
|
149 |
+
echo "</p><p class='submit' id='bulk-resize-examine-button'><button class='button-primary' onclick='resmushit_bulk_resize(\"bulk_resize_image_list\");'>";
|
150 |
+
|
151 |
+
if(get_option('resmushit_cron') && get_option('resmushit_cron') == 1) {
|
152 |
+
echo __('Optimize all pictures manually', 'resmushit');
|
153 |
+
} else {
|
154 |
+
echo __('Optimize all pictures', 'resmushit');
|
155 |
+
}
|
156 |
+
|
157 |
+
echo "</button></p><div id='bulk_resize_image_list'></div></div>"
|
158 |
+
. "<div class='optimized-wrapper $additionnalClassNoNeedOptimization'><h3 class='icon_message ok'>"
|
159 |
+
. __('Congrats ! All your pictures are correctly optimized', 'resmushit')
|
160 |
+
. "</h3></div></div>";
|
161 |
self::fullWidthPanelEndWrapper();
|
162 |
}
|
163 |
|
332 |
}
|
333 |
|
334 |
|
335 |
+
/**
|
336 |
+
*
|
337 |
+
* Generate ALERT panel
|
338 |
+
*
|
339 |
+
* @param none
|
340 |
+
* @return none
|
341 |
+
*/
|
342 |
+
public static function alertPanel() {
|
343 |
+
if (resmushit_get_cron_status() == 'DISABLED' || resmushit_get_cron_status() == 'OK') {
|
344 |
+
return TRUE;
|
345 |
+
}
|
346 |
+
|
347 |
+
self::fullWidthPanelWrapper(__('Important informations', 'resmushit'), null, 'red');
|
348 |
+
echo "<div class='rsmt-alert'>";
|
349 |
+
|
350 |
+
|
351 |
+
echo "<h3 class='icon_message warning'>"
|
352 |
+
. __('Cronjobs seems incorrectly configured', 'resmushit')
|
353 |
+
. "</h3>";
|
354 |
+
|
355 |
+
if (resmushit_get_cron_status() == 'MISCONFIGURED') {
|
356 |
+
echo "<p>"
|
357 |
+
. __('Cronjobs are not correctly configured. The variable <em>DISABLE_WP_CRON</em> must be set to <em>TRUE</em> in <em>wp-config.php</em>. Please install them by reading the following <a href="https://resmush.it/wordpress/howto-configure-cronjobs" target="_blank">instruction page</a>.', 'resmushit')
|
358 |
+
. "</p><p>"
|
359 |
+
. __('We advice to disable Remush.it option "Process optimize on CRON" as long as Cron jobs are incorrectly set up.', 'resmushit')
|
360 |
+
. "</p>";
|
361 |
+
} else if (resmushit_get_cron_status() == 'NEVER_RUN') {
|
362 |
+
echo "<p>"
|
363 |
+
. __('Cronjobs seems to have never been launched. Please install them by reading the following <a href="https://resmush.it/wordpress/howto-configure-cronjobs" target="_blank">instruction page</a>.', 'resmushit')
|
364 |
+
. "</p>";
|
365 |
+
} else if (resmushit_get_cron_status() == 'NO_LATELY_RUN') {
|
366 |
+
echo "<p>"
|
367 |
+
. __('Cronjobs seems not to have run lately. Please read the following <a href="https://resmush.it/wordpress/howto-configure-cronjobs" target="_blank">instruction page</a> to install them correctly.', 'resmushit')
|
368 |
+
. "<ul><li><em>" . __('Expected Frequency :', 'resmushit') . "</em> " . __('Every', 'resmushit') . " " . time_elapsed_string(RESMUSHIT_CRON_FREQUENCY) . "</li>"
|
369 |
+
. "<ul><li><em>" . __('Last run :', 'resmushit') . "</em> " . time_elapsed_string(time() - get_option('resmushit_cron_lastrun')) . " " . __('ago', 'resmushit') . "</li>"
|
370 |
+
. "</p>";
|
371 |
+
}
|
372 |
+
echo "</div>";
|
373 |
+
|
374 |
+
self::fullWidthPanelEndWrapper();
|
375 |
+
}
|
376 |
+
|
377 |
+
|
378 |
|
379 |
|
380 |
/**
|
css/resmushit.css
CHANGED
@@ -46,11 +46,25 @@
|
|
46 |
.rsmt-panels img{
|
47 |
max-width: 100%;
|
48 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
49 |
|
50 |
|
51 |
.rsmt-settings .setting-row{
|
52 |
margin-bottom: 20px;
|
53 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
54 |
.rsmt-settings .setting-row.type-checkbox{
|
55 |
display: flex;
|
56 |
}
|
@@ -87,6 +101,7 @@
|
|
87 |
display: none;
|
88 |
}
|
89 |
.rsmt-bigfiles .icon_message,
|
|
|
90 |
.rsmt-bulk .icon_message{
|
91 |
background-repeat: no-repeat;
|
92 |
padding: 13px 0 0 60px;
|
@@ -95,10 +110,12 @@
|
|
95 |
-moz-box-sizing: border-box;
|
96 |
box-sizing: border-box;
|
97 |
}
|
98 |
-
.rsmt-bulk .warning
|
|
|
99 |
background-image: url(../images/warning.png);
|
100 |
}
|
101 |
-
.rsmt-bulk .ok
|
|
|
102 |
background-image: url(../images/ok.png);
|
103 |
}
|
104 |
.rsmt-bulk .bulk--back-progressionbar{
|
46 |
.rsmt-panels img{
|
47 |
max-width: 100%;
|
48 |
}
|
49 |
+
.rsmt-panels em{
|
50 |
+
font-weight: bold;
|
51 |
+
font-style: normal;
|
52 |
+
}
|
53 |
+
.rsmt-panels ul {
|
54 |
+
list-style-type: disc;
|
55 |
+
list-style-position: inside;
|
56 |
+
}
|
57 |
|
58 |
|
59 |
.rsmt-settings .setting-row{
|
60 |
margin-bottom: 20px;
|
61 |
}
|
62 |
+
.rsmt-settings .new {
|
63 |
+
background-color: #c30000;
|
64 |
+
color: white;
|
65 |
+
padding: 1px 3px;
|
66 |
+
margin-right: 5px;
|
67 |
+
}
|
68 |
.rsmt-settings .setting-row.type-checkbox{
|
69 |
display: flex;
|
70 |
}
|
101 |
display: none;
|
102 |
}
|
103 |
.rsmt-bigfiles .icon_message,
|
104 |
+
.rsmt-alert .icon_message,
|
105 |
.rsmt-bulk .icon_message{
|
106 |
background-repeat: no-repeat;
|
107 |
padding: 13px 0 0 60px;
|
110 |
-moz-box-sizing: border-box;
|
111 |
box-sizing: border-box;
|
112 |
}
|
113 |
+
.rsmt-bulk .warning,
|
114 |
+
.rsmt-alert .warning{
|
115 |
background-image: url(../images/warning.png);
|
116 |
}
|
117 |
+
.rsmt-bulk .ok,
|
118 |
+
.rsmt-alert .ok{
|
119 |
background-image: url(../images/ok.png);
|
120 |
}
|
121 |
.rsmt-bulk .bulk--back-progressionbar{
|
readme.txt
CHANGED
@@ -2,12 +2,12 @@
|
|
2 |
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.3.
|
6 |
-
Stable tag: 0.
|
7 |
License: GPLv2 or later
|
8 |
License URI: http://www.gnu.org/licenses/gpl-2.0.html
|
9 |
|
10 |
-
Use reSmush.it Image Optimizer for FREE to optimize your pictures file sizes. Improve your performances by using reSmush.it, the
|
11 |
|
12 |
== Description ==
|
13 |
|
@@ -34,12 +34,16 @@ This plugin has initially been developped by [Maecia Agency](http://www.maecia.c
|
|
34 |
|
35 |
= How great is reSmush.it ? =
|
36 |
|
37 |
-
Since we've optimized more than
|
38 |
|
39 |
= Is there an "Optimize on upload" feature ? =
|
40 |
|
41 |
Absolutely, this feature is enabled for all new pictures to be added, and can be disabled on will.
|
42 |
|
|
|
|
|
|
|
|
|
43 |
= Can I choose an optimisation level ? =
|
44 |
|
45 |
Yes, by default the optimization level is set at 92. But you can optimize more your pictures by reducing this optimization level.
|
@@ -66,6 +70,12 @@ Yes ! Absolutely free, the only restriction is to send images below 5MB.
|
|
66 |
|
67 |
== Changelog ==
|
68 |
|
|
|
|
|
|
|
|
|
|
|
|
|
69 |
= 0.1.23 =
|
70 |
* Add Settings link to Plugin page
|
71 |
* Limit reSmush.it options to image attachments only
|
2 |
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.3.2
|
6 |
+
Stable tag: 0.2.0
|
7 |
License: GPLv2 or later
|
8 |
License URI: http://www.gnu.org/licenses/gpl-2.0.html
|
9 |
|
10 |
+
Use reSmush.it Image Optimizer for FREE to optimize your pictures file sizes. Improve your performances by using reSmush.it, the 7 billion images API optimizer.
|
11 |
|
12 |
== Description ==
|
13 |
|
34 |
|
35 |
= How great is reSmush.it ? =
|
36 |
|
37 |
+
Since we've optimized more than 7,000,000,000 pictures, we've risen new skills. Our service is still in development to bring you new crazy functionalities.
|
38 |
|
39 |
= Is there an "Optimize on upload" feature ? =
|
40 |
|
41 |
Absolutely, this feature is enabled for all new pictures to be added, and can be disabled on will.
|
42 |
|
43 |
+
= Is there a CRON feature ? =
|
44 |
+
|
45 |
+
Yes, for big (and even for small) media Libraries, you can optimize your pictures using Cronjobs.
|
46 |
+
|
47 |
= Can I choose an optimisation level ? =
|
48 |
|
49 |
Yes, by default the optimization level is set at 92. But you can optimize more your pictures by reducing this optimization level.
|
70 |
|
71 |
== Changelog ==
|
72 |
|
73 |
+
= 0.2.0 =
|
74 |
+
* Add CRON feature
|
75 |
+
* Code refactoring
|
76 |
+
* Fix issue for big Media library, with a limitation while fetching attachments
|
77 |
+
* Fix log path issues
|
78 |
+
|
79 |
= 0.1.23 =
|
80 |
* Add Settings link to Plugin page
|
81 |
* Limit reSmush.it options to image attachments only
|
resmushit.admin.php
CHANGED
@@ -14,8 +14,6 @@ add_action( 'admin_menu','resmushit_create_menu');
|
|
14 |
|
15 |
|
16 |
|
17 |
-
|
18 |
-
|
19 |
/**
|
20 |
*
|
21 |
* Declares settings entries
|
@@ -28,11 +26,19 @@ function resmushit_settings_declare() {
|
|
28 |
register_setting( 'resmushit-settings', 'resmushit_qlty' );
|
29 |
register_setting( 'resmushit-settings', 'resmushit_statistics' );
|
30 |
register_setting( 'resmushit-settings', 'resmushit_logs' );
|
|
|
31 |
}
|
32 |
add_action( 'admin_init', 'resmushit_settings_declare' );
|
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');
|
@@ -41,6 +47,14 @@ function resmushit_media_list_add_column( $columns ) {
|
|
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";
|
@@ -49,6 +63,15 @@ function resmushit_media_list_sort_column( $columns ) {
|
|
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);
|
@@ -58,7 +81,15 @@ function resmushit_media_list_add_column_value( $column_name, $id ) {
|
|
58 |
add_action( 'manage_media_custom_column', 'resmushit_media_list_add_column_value', 10, 2 );
|
59 |
|
60 |
|
61 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
62 |
function resmushit_image_attachment_add_status_button($form_fields, $post) {
|
63 |
if ( !preg_match("/image.*/", $post->post_mime_type) )
|
64 |
return $form_fields;
|
@@ -94,6 +125,7 @@ function resmushit_settings_page() {
|
|
94 |
<div class='rsmt-panels'>
|
95 |
<div class="rsmt-cols w66 iln-block">
|
96 |
<?php reSmushitUI::headerPanel();?>
|
|
|
97 |
<?php reSmushitUI::bulkPanel();?>
|
98 |
<?php reSmushitUI::bigFilesPanel();?>
|
99 |
<?php reSmushitUI::statisticsPanel();?>
|
14 |
|
15 |
|
16 |
|
|
|
|
|
17 |
/**
|
18 |
*
|
19 |
* Declares settings entries
|
26 |
register_setting( 'resmushit-settings', 'resmushit_qlty' );
|
27 |
register_setting( 'resmushit-settings', 'resmushit_statistics' );
|
28 |
register_setting( 'resmushit-settings', 'resmushit_logs' );
|
29 |
+
register_setting( 'resmushit-settings', 'resmushit_cron' );
|
30 |
}
|
31 |
add_action( 'admin_init', 'resmushit_settings_declare' );
|
32 |
|
33 |
|
34 |
|
35 |
+
/**
|
36 |
+
*
|
37 |
+
* Add Columns to the media panel
|
38 |
+
*
|
39 |
+
* @param array $columns
|
40 |
+
* @return $columns
|
41 |
+
*/
|
42 |
function resmushit_media_list_add_column( $columns ) {
|
43 |
$columns["resmushit_disable"] = __('Disable of reSmush.it', 'resmushit');
|
44 |
$columns["resmushit_status"] = __('reSmush.it status', 'resmushit');
|
47 |
add_filter( 'manage_media_columns', 'resmushit_media_list_add_column' );
|
48 |
|
49 |
|
50 |
+
|
51 |
+
/**
|
52 |
+
*
|
53 |
+
* Sort Columns to the media panel
|
54 |
+
*
|
55 |
+
* @param array $columns
|
56 |
+
* @return $columns
|
57 |
+
*/
|
58 |
function resmushit_media_list_sort_column( $columns ) {
|
59 |
$columns["resmushit_disable"] = "resmushit_disable";
|
60 |
$columns["resmushit_status"] = "resmushit_status";
|
63 |
add_filter( 'manage_upload_sortable_columns', 'resmushit_media_list_sort_column' );
|
64 |
|
65 |
|
66 |
+
|
67 |
+
/**
|
68 |
+
*
|
69 |
+
* Add Value to Columns of the media panel
|
70 |
+
*
|
71 |
+
* @param string $column_name
|
72 |
+
* @param string $identifier of the column
|
73 |
+
* @return none
|
74 |
+
*/
|
75 |
function resmushit_media_list_add_column_value( $column_name, $id ) {
|
76 |
if ( $column_name == "resmushit_disable" )
|
77 |
reSmushitUI::mediaListCustomValuesDisable($id);
|
81 |
add_action( 'manage_media_custom_column', 'resmushit_media_list_add_column_value', 10, 2 );
|
82 |
|
83 |
|
84 |
+
|
85 |
+
/**
|
86 |
+
*
|
87 |
+
* Add custom field to attachment
|
88 |
+
*
|
89 |
+
* @param array $form_fields
|
90 |
+
* @param object $post
|
91 |
+
* @return array
|
92 |
+
*/
|
93 |
function resmushit_image_attachment_add_status_button($form_fields, $post) {
|
94 |
if ( !preg_match("/image.*/", $post->post_mime_type) )
|
95 |
return $form_fields;
|
125 |
<div class='rsmt-panels'>
|
126 |
<div class="rsmt-cols w66 iln-block">
|
127 |
<?php reSmushitUI::headerPanel();?>
|
128 |
+
<?php reSmushitUI::alertPanel();?>
|
129 |
<?php reSmushitUI::bulkPanel();?>
|
130 |
<?php reSmushitUI::bigFilesPanel();?>
|
131 |
<?php reSmushitUI::statisticsPanel();?>
|
resmushit.inc.php
CHANGED
@@ -14,19 +14,33 @@ require('resmushit.admin.php');
|
|
14 |
* @param string $str text to log in file
|
15 |
* @return none
|
16 |
*/
|
17 |
-
function rlog($str) {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
18 |
if(get_option('resmushit_logs') == 0)
|
19 |
return FALSE;
|
20 |
|
21 |
-
if( !is_writable(
|
22 |
return FALSE;
|
23 |
}
|
24 |
-
|
25 |
// Preserve file size under a reasonable value
|
26 |
-
if(file_exists(
|
27 |
-
if(filesize(
|
28 |
-
$logtailed = logtail(
|
29 |
-
$fp = fopen(
|
30 |
fwrite($fp, $logtailed);
|
31 |
fclose($fp);
|
32 |
}
|
@@ -34,7 +48,7 @@ function rlog($str) {
|
|
34 |
|
35 |
$str = "[".date('d-m-Y H:i:s')."] " . $str;
|
36 |
$str = print_r($str, true) . "\n";
|
37 |
-
$fp = fopen(
|
38 |
fwrite($fp, $str);
|
39 |
fclose($fp);
|
40 |
}
|
@@ -78,3 +92,46 @@ function logtail($filepath, $lines = 1, $adaptive = true) {
|
|
78 |
fclose($f);
|
79 |
return trim($output);
|
80 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
14 |
* @param string $str text to log in file
|
15 |
* @return none
|
16 |
*/
|
17 |
+
function rlog($str, $level = 'SUCCESS') {
|
18 |
+
global $is_cron;
|
19 |
+
|
20 |
+
if(isset($is_cron) && $is_cron) {
|
21 |
+
switch ($level) {
|
22 |
+
case 'WARNING':
|
23 |
+
$prefix = "[\033[33m!\033[0m]"; break;
|
24 |
+
case 'ERROR':
|
25 |
+
$prefix = "[\033[31m!\033[0m]"; break;
|
26 |
+
default:
|
27 |
+
case 'SUCCESS':
|
28 |
+
$prefix = "[\033[32m+\033[0m]"; break;
|
29 |
+
}
|
30 |
+
echo "$prefix $str\n";
|
31 |
+
}
|
32 |
+
|
33 |
if(get_option('resmushit_logs') == 0)
|
34 |
return FALSE;
|
35 |
|
36 |
+
if( !is_writable(ABSPATH . RESMUSHIT_LOGS_PATH) ) {
|
37 |
return FALSE;
|
38 |
}
|
|
|
39 |
// Preserve file size under a reasonable value
|
40 |
+
if(file_exists(ABSPATH . RESMUSHIT_LOGS_PATH)){
|
41 |
+
if(filesize(ABSPATH . RESMUSHIT_LOGS_PATH) > RESMUSHIT_LOGS_MAX_FILESIZE) {
|
42 |
+
$logtailed = logtail(ABSPATH . RESMUSHIT_LOGS_PATH, 20);
|
43 |
+
$fp = fopen(ABSPATH . RESMUSHIT_LOGS_PATH, 'w');
|
44 |
fwrite($fp, $logtailed);
|
45 |
fclose($fp);
|
46 |
}
|
48 |
|
49 |
$str = "[".date('d-m-Y H:i:s')."] " . $str;
|
50 |
$str = print_r($str, true) . "\n";
|
51 |
+
$fp = fopen(ABSPATH . RESMUSHIT_LOGS_PATH, 'a+');
|
52 |
fwrite($fp, $str);
|
53 |
fclose($fp);
|
54 |
}
|
92 |
fclose($f);
|
93 |
return trim($output);
|
94 |
}
|
95 |
+
|
96 |
+
|
97 |
+
/**
|
98 |
+
*
|
99 |
+
* Calculates time ago
|
100 |
+
*
|
101 |
+
* @param string $datetime time input
|
102 |
+
* @param boolean $full number of lines to keep
|
103 |
+
* @param string $adaptative will preserve line memory
|
104 |
+
* @return string
|
105 |
+
* @author Glavić
|
106 |
+
* @link https://stackoverflow.com/questions/1416697/converting-timestamp-to-time-ago-in-php-e-g-1-day-ago-2-days-ago
|
107 |
+
*/
|
108 |
+
function time_elapsed_string($duration, $full = false) {
|
109 |
+
$datetime = "@" . (time() - $duration);
|
110 |
+
|
111 |
+
$now = new DateTime;
|
112 |
+
$ago = new DateTime($datetime);
|
113 |
+
$diff = $now->diff($ago);
|
114 |
+
|
115 |
+
$diff->w = floor($diff->d / 7);
|
116 |
+
$diff->d -= $diff->w * 7;
|
117 |
+
|
118 |
+
$string = array(
|
119 |
+
'y' => __('year', 'resmushit'),
|
120 |
+
'm' => __('month', 'resmushit'),
|
121 |
+
'w' => __('week', 'resmushit'),
|
122 |
+
'd' => __('day', 'resmushit'),
|
123 |
+
'h' => __('hour', 'resmushit'),
|
124 |
+
'i' => __('minute', 'resmushit'),
|
125 |
+
's' => __('second', 'resmushit'),
|
126 |
+
);
|
127 |
+
foreach ($string as $k => &$v) {
|
128 |
+
if ($diff->$k) {
|
129 |
+
$v = $diff->$k . ' ' . $v . ($diff->$k > 1 ? 's' : '');
|
130 |
+
} else {
|
131 |
+
unset($string[$k]);
|
132 |
+
}
|
133 |
+
}
|
134 |
+
|
135 |
+
if (!$full) $string = array_slice($string, 0, 1);
|
136 |
+
return $string ? implode(', ', $string) : __('just now', 'resmushit');
|
137 |
+
}
|
resmushit.php
CHANGED
@@ -10,8 +10,8 @@
|
|
10 |
* Plugin Name: reSmush.it Image Optimizer
|
11 |
* Plugin URI: https://resmush.it
|
12 |
* Description: Image Optimization API. Provides image size optimization
|
13 |
-
* Version: 0.
|
14 |
-
* Timestamp: 2019.12.
|
15 |
* Author: reSmush.it
|
16 |
* Author URI: https://resmush.it
|
17 |
* Author: Charles Bourgeaux
|
@@ -20,13 +20,9 @@
|
|
20 |
* Domain Path: /languages
|
21 |
*/
|
22 |
|
23 |
-
|
24 |
require('resmushit.inc.php');
|
25 |
|
26 |
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
/**
|
31 |
*
|
32 |
* Registering language plugin
|
@@ -60,10 +56,16 @@ function resmushit_activate() {
|
|
60 |
update_option( 'resmushit_statistics', '1' );
|
61 |
if(!get_option('resmushit_total_optimized'))
|
62 |
update_option( 'resmushit_total_optimized', '0' );
|
|
|
|
|
|
|
|
|
|
|
|
|
63 |
}
|
64 |
}
|
65 |
register_activation_hook( __FILE__, 'resmushit_activate' );
|
66 |
-
|
67 |
|
68 |
|
69 |
|
@@ -267,3 +269,95 @@ function resmushit_add_plugin_page_settings_link($links) {
|
|
267 |
return $links;
|
268 |
}
|
269 |
add_filter('plugin_action_links_'.plugin_basename(__FILE__), 'resmushit_add_plugin_page_settings_link');
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
10 |
* Plugin Name: reSmush.it Image Optimizer
|
11 |
* Plugin URI: https://resmush.it
|
12 |
* Description: Image Optimization API. Provides image size optimization
|
13 |
+
* Version: 0.2.0
|
14 |
+
* Timestamp: 2019.12.21
|
15 |
* Author: reSmush.it
|
16 |
* Author URI: https://resmush.it
|
17 |
* Author: Charles Bourgeaux
|
20 |
* Domain Path: /languages
|
21 |
*/
|
22 |
|
|
|
23 |
require('resmushit.inc.php');
|
24 |
|
25 |
|
|
|
|
|
|
|
26 |
/**
|
27 |
*
|
28 |
* Registering language plugin
|
56 |
update_option( 'resmushit_statistics', '1' );
|
57 |
if(!get_option('resmushit_total_optimized'))
|
58 |
update_option( 'resmushit_total_optimized', '0' );
|
59 |
+
if(!get_option('resmushit_cron'))
|
60 |
+
update_option( 'resmushit_cron', 0 );
|
61 |
+
if(!get_option('resmushit_cron_lastrun'))
|
62 |
+
update_option( 'resmushit_cron_lastrun', 0 );
|
63 |
+
if(!get_option('resmushit_cron_firstactivation'))
|
64 |
+
update_option( 'resmushit_cron_firstactivation', 0 );
|
65 |
}
|
66 |
}
|
67 |
register_activation_hook( __FILE__, 'resmushit_activate' );
|
68 |
+
add_action( 'admin_init', 'resmushit_activate' );
|
69 |
|
70 |
|
71 |
|
269 |
return $links;
|
270 |
}
|
271 |
add_filter('plugin_action_links_'.plugin_basename(__FILE__), 'resmushit_add_plugin_page_settings_link');
|
272 |
+
|
273 |
+
|
274 |
+
|
275 |
+
/**
|
276 |
+
* Trigger when the cron are activated for the first time
|
277 |
+
* @param mixed old value for cron_activation option
|
278 |
+
* @param mixed new value for cron_activation option
|
279 |
+
*/
|
280 |
+
|
281 |
+
function resmushit_on_cron_activation($old_value, $value) {
|
282 |
+
if($value == 1 && (!get_option('resmushit_cron_firstactivation') || get_option('resmushit_cron_firstactivation') === 0)) {
|
283 |
+
update_option( 'resmushit_cron_firstactivation', time() );
|
284 |
+
}
|
285 |
+
}
|
286 |
+
add_action('update_option_resmushit_cron', 'resmushit_on_cron_activation', 100, 2);
|
287 |
+
|
288 |
+
|
289 |
+
|
290 |
+
/**
|
291 |
+
* Declare a new time interval to run Cron
|
292 |
+
* @param array $schedules
|
293 |
+
* @return array
|
294 |
+
*/
|
295 |
+
function resmushit_add_cron_interval( $schedules ) {
|
296 |
+
$schedules['resmushit_interval'] = array(
|
297 |
+
'interval' => RESMUSHIT_CRON_FREQUENCY,
|
298 |
+
'display' => esc_html__( 'Every ' . time_elapsed_string(RESMUSHIT_CRON_FREQUENCY) ),
|
299 |
+
);
|
300 |
+
return $schedules;
|
301 |
+
}
|
302 |
+
add_filter( 'cron_schedules', 'resmushit_add_cron_interval' );
|
303 |
+
|
304 |
+
if(!get_option('resmushit_cron') || get_option('resmushit_cron') === 0) {
|
305 |
+
if (wp_next_scheduled ( 'resmushit_optimize' )) {
|
306 |
+
wp_clear_scheduled_hook('resmushit_optimize');
|
307 |
+
}
|
308 |
+
} else {
|
309 |
+
if (! wp_next_scheduled ( 'resmushit_optimize' )) {
|
310 |
+
wp_schedule_event(time(), 'resmushit_interval', 'resmushit_optimize');
|
311 |
+
}
|
312 |
+
}
|
313 |
+
|
314 |
+
|
315 |
+
|
316 |
+
/**
|
317 |
+
* Declare a new crontask for optimization bulk
|
318 |
+
*/
|
319 |
+
function resmushit_cron_process() {
|
320 |
+
global $is_cron;
|
321 |
+
$is_cron = TRUE;
|
322 |
+
update_option( 'resmushit_cron_lastrun', time() );
|
323 |
+
|
324 |
+
// required if launch through wp-cron.php
|
325 |
+
include_once( ABSPATH . 'wp-admin/includes/image.php' );
|
326 |
+
|
327 |
+
add_filter('wp_generate_attachment_metadata', 'resmushit_process_images');
|
328 |
+
rlog('Gathering unoptimized pictures from CRON');
|
329 |
+
$unoptimized_pictures = json_decode(reSmushit::getNonOptimizedPictures(TRUE));
|
330 |
+
rlog('Found ' . count($unoptimized_pictures->nonoptimized) . ' attachments');
|
331 |
+
foreach($unoptimized_pictures->nonoptimized as $el) {
|
332 |
+
if (wp_next_scheduled ( 'resmushit_optimize' )) {
|
333 |
+
//avoid to collapse two crons
|
334 |
+
wp_unschedule_event(wp_next_scheduled('resmushit_optimize'), 'resmushit_optimize');
|
335 |
+
}
|
336 |
+
rlog('CRON Processing attachments #' . $el->ID);
|
337 |
+
reSmushit::revert($el->ID);
|
338 |
+
}
|
339 |
+
}
|
340 |
+
add_action('resmushit_optimize', 'resmushit_cron_process');
|
341 |
+
|
342 |
+
|
343 |
+
|
344 |
+
/**
|
345 |
+
* Return the RESMUSHIT CRON status according to last_execution variables
|
346 |
+
* @return string
|
347 |
+
*/
|
348 |
+
function resmushit_get_cron_status() {
|
349 |
+
if(get_option('resmushit_cron') == 0) {
|
350 |
+
return 'DISABLED';
|
351 |
+
}
|
352 |
+
if(!defined('DISABLE_WP_CRON') OR DISABLE_WP_CRON == false) {
|
353 |
+
return 'MISCONFIGURED';
|
354 |
+
}
|
355 |
+
|
356 |
+
if(get_option('resmushit_cron_lastrun') == 0 && (time() - get_option('resmushit_cron_firstactivation') > 2*RESMUSHIT_CRON_FREQUENCY)) {
|
357 |
+
return 'NEVER_RUN';
|
358 |
+
}
|
359 |
+
if(get_option('resmushit_cron_lastrun') != 0 && (time() - get_option('resmushit_cron_lastrun') > 2*RESMUSHIT_CRON_FREQUENCY)) {
|
360 |
+
return 'NO_LATELY_RUN';
|
361 |
+
}
|
362 |
+
return 'OK';
|
363 |
+
}
|
resmushit.settings.php
CHANGED
@@ -1,11 +1,13 @@
|
|
1 |
<?php
|
2 |
|
3 |
-
|
4 |
define('RESMUSHIT_ENDPOINT', 'http://api.resmush.it/');
|
5 |
-
define('RESMUSHIT_VERSION', '0.
|
6 |
define('RESMUSHIT_DEFAULT_QLTY', '92');
|
7 |
define('RESMUSHIT_TIMEOUT', '10');
|
8 |
define('RESMUSHIT_LOGS_PATH', 'resmushit.log');
|
9 |
define('RESMUSHIT_LOGS_MAX_FILESIZE', '102400');
|
10 |
define('RESMUSHIT_NEWSFEED', 'https://feed.resmush.it/');
|
11 |
-
define('RESMUSHIT_BASE_URL', plugin_dir_url( __FILE__ ));
|
|
|
|
|
|
1 |
<?php
|
2 |
|
|
|
3 |
define('RESMUSHIT_ENDPOINT', 'http://api.resmush.it/');
|
4 |
+
define('RESMUSHIT_VERSION', '0.2.0');
|
5 |
define('RESMUSHIT_DEFAULT_QLTY', '92');
|
6 |
define('RESMUSHIT_TIMEOUT', '10');
|
7 |
define('RESMUSHIT_LOGS_PATH', 'resmushit.log');
|
8 |
define('RESMUSHIT_LOGS_MAX_FILESIZE', '102400');
|
9 |
define('RESMUSHIT_NEWSFEED', 'https://feed.resmush.it/');
|
10 |
+
define('RESMUSHIT_BASE_URL', plugin_dir_url( __FILE__ ));
|
11 |
+
define('RESMUSHIT_CRON_FREQUENCY', 600);
|
12 |
+
|
13 |
+
global $is_cron;
|