ShortPixel Image Optimizer - Version 3.3.6

Version Description

  • When quota exceeded, download the images that are already processed on the server
Download this release

Release Info

Developer ShortPixel
Plugin Icon 128x128 ShortPixel Image Optimizer
Version 3.3.6
Comparing to
See all releases

Code changes from version 3.3.5 to 3.3.6

js/short-pixel.js CHANGED
@@ -224,6 +224,9 @@ function checkBulkProcessingCallApi(){
224
  + "<a class='button button-smaller' href='admin.php?action=shortpixel_check_quota'>Check&nbsp;&nbsp;Quota</a></div>"
225
  + "<div class='sp-column-info'>" + data["Message"] + "</div>" );
226
  showToolBarAlert(ShortPixel.STATUS_QUOTA_EXCEEDED);
 
 
 
227
  break;
228
  case ShortPixel.STATUS_FAIL:
229
  setCellMessage(id, data["Message"]);
224
  + "<a class='button button-smaller' href='admin.php?action=shortpixel_check_quota'>Check&nbsp;&nbsp;Quota</a></div>"
225
  + "<div class='sp-column-info'>" + data["Message"] + "</div>" );
226
  showToolBarAlert(ShortPixel.STATUS_QUOTA_EXCEEDED);
227
+ if(data['Stop'] == false) { //there are other items in queue maybe already optimized
228
+ setTimeout(checkBulkProgress, 5000);
229
+ }
230
  break;
231
  case ShortPixel.STATUS_FAIL:
232
  setCellMessage(id, data["Message"]);
readme.txt CHANGED
@@ -4,8 +4,8 @@ Contributors: AlexSP
4
  Tags: image optimizer, image optimization, compress pdf, compress jpeg, compress png, image compression, wp smush, compress images, optimize images, shrink jpeg, optimize photos, tinypng
5
 
6
  Requires at least: 3.2.0
7
- Tested up to: 4.5
8
- Stable tag: 3.3.5
9
  License: GPLv2 or later
10
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
11
 
@@ -193,8 +193,13 @@ The ShortPixel team is here to help. <a href="https://shortpixel.com/contact">Co
193
 
194
  == Changelog ==
195
 
 
 
 
 
196
  = 3.3.5 =
197
- * fix tabbed layout height on settings page with API key not validated
 
198
 
199
  = 3.3.4 =
200
 
4
  Tags: image optimizer, image optimization, compress pdf, compress jpeg, compress png, image compression, wp smush, compress images, optimize images, shrink jpeg, optimize photos, tinypng
5
 
6
  Requires at least: 3.2.0
7
+ Tested up to: 4.6
8
+ Stable tag: 3.3.6
9
  License: GPLv2 or later
10
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
11
 
193
 
194
  == Changelog ==
195
 
196
+ = 3.3.6 =
197
+
198
+ * When quota exceeded, download the images that are already processed on the server
199
+
200
  = 3.3.5 =
201
+
202
+ * fix the size problem of the settings tabs when not yet activated
203
 
204
  = 3.3.4 =
205
 
shortpixel_api.php CHANGED
@@ -159,7 +159,9 @@ class ShortPixelAPI {
159
  {
160
  case 2:
161
  //handle image has been processed
162
- update_option( 'wp-short-pixel-quota-exceeded', 0);//reset the quota exceeded flag
 
 
163
  return $this->handleSuccess($APIresponse, $URLs, $PATHs, $ID, $compressionType);
164
  break;
165
  default:
@@ -338,7 +340,22 @@ class ShortPixelAPI {
338
  foreach ( $tempFiles as $tempFileID => $tempFilePATH )
339
  {
340
  if ( file_exists($tempFilePATH) && file_exists($PATHs[$tempFileID]) && is_writable($PATHs[$tempFileID]) ) {
 
 
 
 
 
 
 
 
 
 
341
  copy($tempFilePATH, $PATHs[$tempFileID]);
 
 
 
 
 
342
  } else {
343
  $writeFailed++;
344
  }
159
  {
160
  case 2:
161
  //handle image has been processed
162
+ if(!isset($firstImage->Status->quotaExceeded)) {
163
+ $this->_settings->quotaExceeded = 0;//reset the quota exceeded flag
164
+ }
165
  return $this->handleSuccess($APIresponse, $URLs, $PATHs, $ID, $compressionType);
166
  break;
167
  default:
340
  foreach ( $tempFiles as $tempFileID => $tempFilePATH )
341
  {
342
  if ( file_exists($tempFilePATH) && file_exists($PATHs[$tempFileID]) && is_writable($PATHs[$tempFileID]) ) {
343
+ /*
344
+ echo("COPY FROM " . $tempFilePATH . " TO " . $PATHs[$tempFileID] . " TIME " . date("Y-m-d H:i:s"));
345
+ if(file_exists($PATHs[$tempFileID])) {
346
+ echo " TARGET IS THERE, SIZE " . filesize($PATHs[$tempFileID]) . ", FILEMTIME: " . date("Y-m-d H:i:s", filemtime($PATHs[$tempFileID])) . ", UNLINKING ... "
347
+ }
348
+ unlink($PATHs[$tempFileID]);
349
+ if(file_exists($PATHs[$tempFileID])) {
350
+ echo " NOT UNLINKED ";
351
+ }
352
+ */
353
  copy($tempFilePATH, $PATHs[$tempFileID]);
354
+ /*
355
+ if(file_exists($PATHs[$tempFileID])) {
356
+ echo " FILE COPIED, SIZE " . filesize($PATHs[$tempFileID]) . ", FILEMTIME: " . date("Y-m-d H:i:s", filemtime($PATHs[$tempFileID])) . " ";
357
+ }
358
+ */
359
  } else {
360
  $writeFailed++;
361
  }
shortpixel_queue.php CHANGED
@@ -59,7 +59,41 @@ class ShortPixelQueue {
59
  return $_SESSION["wp-short-pixel-priorityQueue"];//get_option("wp-short-pixel-priorityQueue");
60
  }
61
 
62
- public function push($ID)//add an ID to priority queue
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
63
  {
64
  $priorityQueue = $_SESSION["wp-short-pixel-priorityQueue"]; //get_option("wp-short-pixel-priorityQueue");
65
  WPShortPixel::log("PUSH: Push ID $ID into queue ".json_encode($priorityQueue));
59
  return $_SESSION["wp-short-pixel-priorityQueue"];//get_option("wp-short-pixel-priorityQueue");
60
  }
61
 
62
+ public function skip($id) {
63
+ if(is_array($this->settings->prioritySkip)) {
64
+ $this->settings->prioritySkip = array_merge($this->settings->prioritySkip, array($id));
65
+ } else {
66
+ $this->settings->prioritySkip = array($id);
67
+ }
68
+ }
69
+
70
+ public function allSkipped() {
71
+ if( !is_array($this->settings->prioritySkip) ) return false;
72
+ count(array_diff($_SESSION["wp-short-pixel-priorityQueue"], $this->settings->prioritySkip));
73
+ }
74
+
75
+ public function skippedCount() {
76
+ return is_array($this->settings->prioritySkip) ? count($this->settings->prioritySkip) : 0;
77
+ }
78
+
79
+ public function isSkipped($id) {
80
+ return is_array($this->settings->prioritySkip) && in_array($id, $this->settings->prioritySkip);
81
+ }
82
+
83
+ public function isPrio($id) {
84
+ return is_array($_SESSION["wp-short-pixel-priorityQueue"]) && in_array($id, $_SESSION["wp-short-pixel-priorityQueue"]);
85
+ }
86
+
87
+ public function getSkipped() {
88
+ return $this->settings->prioritySkip;
89
+ }
90
+
91
+ public function reverse() {
92
+ $this->settings->priorityQueue = $_SESSION["wp-short-pixel-priorityQueue"] = array_reverse($_SESSION["wp-short-pixel-priorityQueue"]);
93
+
94
+ }
95
+
96
+ public function push($ID)//add an ID to priority queue
97
  {
98
  $priorityQueue = $_SESSION["wp-short-pixel-priorityQueue"]; //get_option("wp-short-pixel-priorityQueue");
99
  WPShortPixel::log("PUSH: Push ID $ID into queue ".json_encode($priorityQueue));
wp-shortpixel-settings.php CHANGED
@@ -38,6 +38,7 @@ class WPShortPixelSettings {
38
  'mediaAlert' => 'wp-short-pixel-media-alert',
39
  'siteAuthUser' => 'wp-short-pixel-site-auth-user',
40
  'siteAuthPass' => 'wp-short-pixel-site-auth-pass',
 
41
  '' => '',
42
  );
43
 
38
  'mediaAlert' => 'wp-short-pixel-media-alert',
39
  'siteAuthUser' => 'wp-short-pixel-site-auth-user',
40
  'siteAuthPass' => 'wp-short-pixel-site-auth-pass',
41
+ 'prioritySkip' => 'wp-short-pixel-prioritySkip',
42
  '' => '',
43
  );
44
 
wp-shortpixel.php CHANGED
@@ -3,7 +3,7 @@
3
  * Plugin Name: ShortPixel Image Optimizer
4
  * Plugin URI: https://shortpixel.com/
5
  * Description: ShortPixel optimizes images automatically, while guarding the quality of your images. Check your <a href="options-general.php?page=wp-shortpixel" target="_blank">Settings &gt; ShortPixel</a> page on how to start optimizing your image library and make your website load faster.
6
- * Version: 3.3.5
7
  * Author: ShortPixel
8
  * Author URI: https://shortpixel.com
9
  */
@@ -22,7 +22,7 @@ define('SP_RESET_ON_ACTIVATE', false); //if true TODO set false
22
 
23
  define('SP_AFFILIATE_CODE', '');
24
 
25
- define('PLUGIN_VERSION', "3.3.5");
26
  define('SP_MAX_TIMEOUT', 10);
27
  define('SP_VALIDATE_MAX_TIMEOUT', 15);
28
  define('SP_BACKUP', 'ShortpixelBackups');
@@ -78,6 +78,8 @@ class WPShortPixel {
78
  //Media custom column
79
  add_filter( 'manage_media_columns', array( &$this, 'columns' ) );//add media library column header
80
  add_action( 'manage_media_custom_column', array( &$this, 'generateCustomColumn' ), 10, 2 );//generate the media library column
 
 
81
 
82
  if($isAdminUser) {
83
  //add settings page
@@ -417,10 +419,10 @@ class WPShortPixel {
417
  $idsPrio = $this->prioQ->get();
418
  for($i = count($idsPrio) - 1, $cnt = 0; $i>=0 && $cnt < 3; $i--) {
419
  $id = $idsPrio[$i];
420
- if(wp_get_attachment_url($id)) {
421
  $ids[] = $id; //valid ID
422
- } else {
423
- $removeIds[] = $id;//absent, to remove
424
  }
425
  }
426
  foreach($removeIds as $rId){
@@ -571,7 +573,19 @@ class WPShortPixel {
571
  }
572
  $this->advanceBulk($ID, $result);
573
  }
574
- if($result["Status"] !== ShortPixelAPI::STATUS_RETRY) {
 
 
 
 
 
 
 
 
 
 
 
 
575
  update_option( 'wp-short-pixel-bulk-last-status', $result);
576
  }
577
  die(json_encode($result));
@@ -598,9 +612,14 @@ class WPShortPixel {
598
  }
599
 
600
  public function handleManualOptimization() {
601
-
602
  $imageId = intval($_GET['image_id']);
 
 
603
 
 
 
 
 
604
  if(self::isProcessable($imageId)) {
605
  $this->prioQ->push($imageId);
606
  $this->sendToProcessing($imageId);
@@ -807,7 +826,8 @@ class WPShortPixel {
807
  //$quotaData['mainProcessedFiles'] = $imageCount['mainProcessedFiles'];
808
 
809
  if($quotaData['APICallsQuotaNumeric'] + $quotaData['APICallsQuotaOneTimeNumeric'] > $quotaData['APICallsMadeNumeric'] + $quotaData['APICallsMadeOneTimeNumeric']) {
810
- update_option('wp-short-pixel-quota-exceeded','0');
 
811
  ?><script>var shortPixelQuotaExceeded = 0;</script><?php
812
  }
813
  else {
3
  * Plugin Name: ShortPixel Image Optimizer
4
  * Plugin URI: https://shortpixel.com/
5
  * Description: ShortPixel optimizes images automatically, while guarding the quality of your images. Check your <a href="options-general.php?page=wp-shortpixel" target="_blank">Settings &gt; ShortPixel</a> page on how to start optimizing your image library and make your website load faster.
6
+ * Version: 3.3.6
7
  * Author: ShortPixel
8
  * Author URI: https://shortpixel.com
9
  */
22
 
23
  define('SP_AFFILIATE_CODE', '');
24
 
25
+ define('PLUGIN_VERSION', "3.3.6");
26
  define('SP_MAX_TIMEOUT', 10);
27
  define('SP_VALIDATE_MAX_TIMEOUT', 15);
28
  define('SP_BACKUP', 'ShortpixelBackups');
78
  //Media custom column
79
  add_filter( 'manage_media_columns', array( &$this, 'columns' ) );//add media library column header
80
  add_action( 'manage_media_custom_column', array( &$this, 'generateCustomColumn' ), 10, 2 );//generate the media library column
81
+ //custom hook
82
+ add_action( 'shortpixel-optimize-now', array( &$this, 'optimizeNowHook' ), 10, 1);
83
 
84
  if($isAdminUser) {
85
  //add settings page
419
  $idsPrio = $this->prioQ->get();
420
  for($i = count($idsPrio) - 1, $cnt = 0; $i>=0 && $cnt < 3; $i--) {
421
  $id = $idsPrio[$i];
422
+ if(!$this->prioQ->isSkipped($id) && wp_get_attachment_url($id)) {
423
  $ids[] = $id; //valid ID
424
+ } elseif(!$this->prioQ->isSkipped($id)) {
425
+ $removeIds[] = $id;//not skipped, url not found, means it's absent, to remove
426
  }
427
  }
428
  foreach($removeIds as $rId){
573
  }
574
  $this->advanceBulk($ID, $result);
575
  }
576
+ elseif ($this->prioQ->isPrio($ID) && $result["Status"] == ShortPixelAPI::STATUS_QUOTA_EXCEEDED) {
577
+ if(!$this->prioQ->skippedCount()) {
578
+ $this->prioQ->reverse(); //for the first prio item with quota exceeded, revert the prio queue as probably the bottom ones were processed
579
+ }
580
+ if($this->prioQ->allSkipped()) {
581
+ $result["Stop"] = true;
582
+ } else {
583
+ $result["Stop"] = false;
584
+ $this->prioQ->skip($ID);
585
+ }
586
+ self::log("HIP: 5 Prio Skipped: ".json_encode($this->prioQ->getSkipped()));
587
+ }
588
+ if($result["Status"] !== ShortPixelAPI::STATUS_RETRY) {
589
  update_option( 'wp-short-pixel-bulk-last-status', $result);
590
  }
591
  die(json_encode($result));
612
  }
613
 
614
  public function handleManualOptimization() {
 
615
  $imageId = intval($_GET['image_id']);
616
+ $this->optimizeNowHook($imageId);
617
+ //do_action('shortpixel-optimize-now', $imageId);
618
 
619
+ }
620
+
621
+ //custom hook
622
+ public function optimizeNowHook($imageId) {
623
  if(self::isProcessable($imageId)) {
624
  $this->prioQ->push($imageId);
625
  $this->sendToProcessing($imageId);
826
  //$quotaData['mainProcessedFiles'] = $imageCount['mainProcessedFiles'];
827
 
828
  if($quotaData['APICallsQuotaNumeric'] + $quotaData['APICallsQuotaOneTimeNumeric'] > $quotaData['APICallsMadeNumeric'] + $quotaData['APICallsMadeOneTimeNumeric']) {
829
+ $this->_settings->quotaExceeded = '0';
830
+ $this->_settings->prioritySkip = NULL;
831
  ?><script>var shortPixelQuotaExceeded = 0;</script><?php
832
  }
833
  else {