ShortPixel Image Optimizer - Version 3.1.3

Version Description

  • fix problems with activating the keys on some systems that do not allow post requests
Download this release

Release Info

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

Code changes from version 3.1.2 to 3.1.3

Files changed (4) hide show
  1. js/short-pixel.js +20 -13
  2. readme.txt +5 -1
  3. shortpixel_api.php +2 -1
  4. wp-shortpixel.php +24 -11
js/short-pixel.js CHANGED
@@ -34,25 +34,30 @@ var ShortPixel = function() {
34
  }();
35
 
36
  function showToolBarAlert($status, $message) {
 
37
  switch($status) {
38
  case ShortPixel.STATUS_QUOTA_EXCEEDED:
39
- jQuery("li.shortpixel-toolbar-processing").addClass("shortpixel-alert");
40
- jQuery("li.shortpixel-toolbar-processing").addClass("shortpixel-quota-exceeded");
41
- jQuery("li.shortpixel-toolbar-processing a").attr("href", "http://shortpixel.com/login/" + ShortPixel.API_KEY);
42
- jQuery("li.shortpixel-toolbar-processing a").attr("target", "_blank");
43
- jQuery("li.shortpixel-toolbar-processing a div").attr("title", "ShortPixel quota exceeded. Click to top-up");
44
  break;
45
  case ShortPixel.STATUS_FAIL:
46
- jQuery("li.shortpixel-toolbar-processing").addClass("shortpixel-alert shortpixel-processing");
47
- jQuery("li.shortpixel-toolbar-processing a div").attr("title", $message);
48
  break;
49
  case ShortPixel.STATUS_NO_KEY:
50
- jQuery("li.shortpixel-toolbar-processing").addClass("shortpixel-alert");
51
- jQuery("li.shortpixel-toolbar-processing").addClass("shortpixel-quota-exceeded");
52
- jQuery("li.shortpixel-toolbar-processing a").attr("href", "http://shortpixel.com/wp-apikey");
53
- jQuery("li.shortpixel-toolbar-processing a").attr("target", "_blank");
54
- jQuery("li.shortpixel-toolbar-processing a div").attr("title", "Get API Key");
55
  break;
 
 
 
 
56
  }
57
  jQuery("li.shortpixel-toolbar-processing").removeClass("shortpixel-hide");
58
  }
@@ -174,16 +179,18 @@ function checkBulkProcessingCallApi(){
174
  if(0 + data['ThumbsCount'] > 0) {
175
  cellMsg += "<br>+" + data['ThumbsCount'] + " thumbnails optimized";
176
  }
 
177
  setCellMessage(id, cellMsg);
178
  var animator = new PercentageAnimator("#sp-msg-" + id + " span.percent", percent);
179
  animator.animate(percent);
180
- if(isBulkPage && typeof data["Thumb"] !== 'undefined' && data["PercentImprovement"] > 0) {
181
  progressUpdate(data["BulkPercent"], data["BulkMsg"]);
182
  if(data["Thumb"].length > 0){
183
  sliderUpdate(id, data["Thumb"], data["BkThumb"], data["PercentImprovement"]);
184
  }
185
  }
186
  //fall through
 
187
  case ShortPixel.STATUS_ERROR: //for error and skip also we retry
188
  case ShortPixel.STATUS_SKIP:
189
  console.log('Server response: ' + response);
34
  }();
35
 
36
  function showToolBarAlert($status, $message) {
37
+ var robo = jQuery("li.shortpixel-toolbar-processing");
38
  switch($status) {
39
  case ShortPixel.STATUS_QUOTA_EXCEEDED:
40
+ robo.addClass("shortpixel-alert");
41
+ robo.addClass("shortpixel-quota-exceeded");
42
+ jQuery("a", robo).attr("href", "http://shortpixel.com/login/" + ShortPixel.API_KEY);
43
+ jQuery("a", robo).attr("target", "_blank");
44
+ jQuery("a div", robo).attr("title", "ShortPixel quota exceeded. Click to top-up");
45
  break;
46
  case ShortPixel.STATUS_FAIL:
47
+ robo.addClass("shortpixel-alert shortpixel-processing");
48
+ jQuery("a div", robo).attr("title", $message);
49
  break;
50
  case ShortPixel.STATUS_NO_KEY:
51
+ robo.addClass("shortpixel-alert");
52
+ robo.addClass("shortpixel-quota-exceeded");
53
+ jQuery("a", robo).attr("href", "http://shortpixel.com/wp-apikey");
54
+ jQuery("a", robo).attr("target", "_blank");
55
+ jQuery("a div", robo).attr("title", "Get API Key");
56
  break;
57
+ case ShortPixel.STATUS_SUCCESS:
58
+ robo.removeClass("shortpixel-alert");
59
+ jQuery("a", robo).removeAttr("target");
60
+ jQuery("a", robo).attr("href", jQuery("a img", robo).attr("success-url"));
61
  }
62
  jQuery("li.shortpixel-toolbar-processing").removeClass("shortpixel-hide");
63
  }
179
  if(0 + data['ThumbsCount'] > 0) {
180
  cellMsg += "<br>+" + data['ThumbsCount'] + " thumbnails optimized";
181
  }
182
+ showToolBarAlert(ShortPixel.STATUS_SUCCESS, "");
183
  setCellMessage(id, cellMsg);
184
  var animator = new PercentageAnimator("#sp-msg-" + id + " span.percent", percent);
185
  animator.animate(percent);
186
+ if(isBulkPage && typeof data["Thumb"] !== 'undefined') { // && data["PercentImprovement"] > 0) {
187
  progressUpdate(data["BulkPercent"], data["BulkMsg"]);
188
  if(data["Thumb"].length > 0){
189
  sliderUpdate(id, data["Thumb"], data["BkThumb"], data["PercentImprovement"]);
190
  }
191
  }
192
  //fall through
193
+ case ShortPixel.STATUS_RETRY:
194
  case ShortPixel.STATUS_ERROR: //for error and skip also we retry
195
  case ShortPixel.STATUS_SKIP:
196
  console.log('Server response: ' + response);
readme.txt CHANGED
@@ -5,7 +5,7 @@ Tags: picture, optimization, image editor, pngout, upload speed, shortpixel, co
5
 
6
  Requires at least: 3.0.1
7
  Tested up to: 4.3
8
- Stable tag: 3.1.2
9
  License: GPLv2 or later
10
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
11
 
@@ -168,6 +168,10 @@ The ShortPixel team is here to help. <a href="https://shortpixel.com/contact">Co
168
 
169
  == Changelog ==
170
 
 
 
 
 
171
  = 3.1.2 =
172
 
173
  * bulk runs now only on media and post pages
5
 
6
  Requires at least: 3.0.1
7
  Tested up to: 4.3
8
+ Stable tag: 3.1.3
9
  License: GPLv2 or later
10
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
11
 
168
 
169
  == Changelog ==
170
 
171
+ = 3.1.3 =
172
+
173
+ * fix problems with activating the keys on some systems that do not allow post requests
174
+
175
  = 3.1.2 =
176
 
177
  * bulk runs now only on media and post pages
shortpixel_api.php CHANGED
@@ -13,6 +13,7 @@ class ShortPixelAPI {
13
  const STATUS_SKIP = -4;
14
  const STATUS_NOT_FOUND = -5;
15
  const STATUS_NO_KEY = -6;
 
16
 
17
  private $_apiKey = '';
18
  private $_compressionType = '';
@@ -146,7 +147,7 @@ class ShortPixelAPI {
146
  {//we'll try again next time user visits a page on admin panel
147
  $apiRetries++;
148
  update_option('wp-short-pixel-api-retries', $apiRetries);
149
- return array("Status" => self::STATUS_ERROR, "Message" => 'Timed out while processing. (pass '.$apiRetries.')');
150
  }
151
  }
152
  $response = $this->doRequests($URLs, true, $ID);//send requests to API
13
  const STATUS_SKIP = -4;
14
  const STATUS_NOT_FOUND = -5;
15
  const STATUS_NO_KEY = -6;
16
+ const STATUS_RETRY = -7;
17
 
18
  private $_apiKey = '';
19
  private $_compressionType = '';
147
  {//we'll try again next time user visits a page on admin panel
148
  $apiRetries++;
149
  update_option('wp-short-pixel-api-retries', $apiRetries);
150
+ return array("Status" => self::STATUS_RETRY, "Message" => 'Timed out while processing. (pass '.$apiRetries.')');
151
  }
152
  }
153
  $response = $this->doRequests($URLs, true, $ID);//send requests to API
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.1.2
7
  * Author: ShortPixel
8
  * Author URI: https://shortpixel.com
9
  */
@@ -21,7 +21,7 @@ define('SP_RESET_ON_ACTIVATE', false);
21
 
22
  define('SP_AFFILIATE_CODE', '');
23
 
24
- define('PLUGIN_VERSION', "3.1.2");
25
  define('SP_MAX_TIMEOUT', 10);
26
  define('SP_BACKUP', 'ShortpixelBackups');
27
  define('SP_BACKUP_FOLDER', WP_CONTENT_DIR . DIRECTORY_SEPARATOR . 'uploads' . DIRECTORY_SEPARATOR . SP_BACKUP);
@@ -246,6 +246,7 @@ class WPShortPixel {
246
  STATUS_QUOTA_EXCEEDED: <?= ShortPixelAPI::STATUS_QUOTA_EXCEEDED ?>,
247
  STATUS_SKIP: <?= ShortPixelAPI::STATUS_SKIP ?>,
248
  STATUS_NO_KEY: <?= ShortPixelAPI::STATUS_NO_KEY ?>,
 
249
  WP_PLUGIN_URL: '<?= plugins_url( '', __FILE__ ) ?>',
250
  API_KEY: "<?= $this->_apiKey ?>"
251
  });
@@ -260,7 +261,7 @@ class WPShortPixel {
260
  $extraClasses = " shortpixel-hide";
261
  $tooltip = "ShortPixel optimizing...";
262
  $icon = "shortpixel.png";
263
- $link = current_user_can( 'edit_others_posts')? 'upload.php?page=wp-short-pixel-bulk' : 'upload.php';
264
  $blank = "";
265
  if($this->prioQ->processing()) {
266
  $extraClasses = " shortpixel-processing";
@@ -284,7 +285,7 @@ class WPShortPixel {
284
  $args = array(
285
  'id' => 'shortpixel_processing',
286
  'title' => '<div title="' . $tooltip . '" ><img src="'
287
- . plugins_url( 'img/'.$icon, __FILE__ ) . '"><span class="shp-alert">!</span></div>',
288
  'href' => $link,
289
  'meta' => array('target'=> $blank, 'class' => 'shortpixel-toolbar-processing' . $extraClasses)
290
  );
@@ -445,7 +446,7 @@ class WPShortPixel {
445
  }
446
 
447
  public function handleImageProcessing($ID = null) {
448
- //die("stop");
449
  //0: check key
450
  if( $this->_verifiedKey == false) {
451
  if($ID == null){
@@ -998,25 +999,30 @@ class WPShortPixel {
998
  'sslverify' => false,
999
  'body' => array('key' => $apiKey)
1000
  );
 
1001
 
1002
  if($appendUserAgent) {
1003
  $args['body']['useragent'] = "Agent" . urlencode($_SERVER['HTTP_USER_AGENT']);
 
1004
  }
1005
  if($validate) {
1006
  $args['body']['DomainCheck'] = get_site_url();
1007
  $imageCount = $this->countAllProcessableFiles();
1008
  $args['body']['ImagesCount'] = $imageCount['mainFiles'];
1009
  $args['body']['ThumbsCount'] = $imageCount['totalFiles'] - $imageCount['mainFiles'];
 
1010
  }
1011
 
 
1012
  $response = wp_remote_post($requestURL, $args);
1013
-
1014
- if(is_wp_error( $response )) //some hosting providers won't allow https:// POST connections so we try http:// as well
1015
  $response = wp_remote_post(str_replace('https://', 'http://', $requestURL), $args);
1016
-
1017
- if(is_wp_error( $response ))
1018
- $response = wp_remote_get(str_replace('https://', 'http://', $requestURL), $args);
1019
-
 
1020
  $defaultData = array(
1021
  "APIKeyValid" => false,
1022
  "Message" => 'API Key could not be validated due to a connectivity error.<BR>Your firewall may be blocking us. Please contact your hosting provider and ask them to allow connections from your site to IP 176.9.106.46.<BR> If you still cannot validate your API Key after this, please <a href="https://shortpixel.com/contact" target="_blank">contact us</a> and we will try to help. ',
@@ -1052,6 +1058,13 @@ class WPShortPixel {
1052
  update_option('wp-short-pixel-quota-exceeded',0);
1053
  else
1054
  update_option('wp-short-pixel-quota-exceeded',1);//activate quota limiting
 
 
 
 
 
 
 
1055
  return array(
1056
  "APIKeyValid" => true,
1057
  "APICallsMade" => number_format($data->APICallsMade) . ' images',
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.1.3
7
  * Author: ShortPixel
8
  * Author URI: https://shortpixel.com
9
  */
21
 
22
  define('SP_AFFILIATE_CODE', '');
23
 
24
+ define('PLUGIN_VERSION', "3.1.3");
25
  define('SP_MAX_TIMEOUT', 10);
26
  define('SP_BACKUP', 'ShortpixelBackups');
27
  define('SP_BACKUP_FOLDER', WP_CONTENT_DIR . DIRECTORY_SEPARATOR . 'uploads' . DIRECTORY_SEPARATOR . SP_BACKUP);
246
  STATUS_QUOTA_EXCEEDED: <?= ShortPixelAPI::STATUS_QUOTA_EXCEEDED ?>,
247
  STATUS_SKIP: <?= ShortPixelAPI::STATUS_SKIP ?>,
248
  STATUS_NO_KEY: <?= ShortPixelAPI::STATUS_NO_KEY ?>,
249
+ STATUS_RETRY: <?= ShortPixelAPI::STATUS_RETRY ?>,
250
  WP_PLUGIN_URL: '<?= plugins_url( '', __FILE__ ) ?>',
251
  API_KEY: "<?= $this->_apiKey ?>"
252
  });
261
  $extraClasses = " shortpixel-hide";
262
  $tooltip = "ShortPixel optimizing...";
263
  $icon = "shortpixel.png";
264
+ $successLink = $link = current_user_can( 'edit_others_posts')? 'upload.php?page=wp-short-pixel-bulk' : 'upload.php';
265
  $blank = "";
266
  if($this->prioQ->processing()) {
267
  $extraClasses = " shortpixel-processing";
285
  $args = array(
286
  'id' => 'shortpixel_processing',
287
  'title' => '<div title="' . $tooltip . '" ><img src="'
288
+ . plugins_url( 'img/'.$icon, __FILE__ ) . '" success-url="' . $successLink . '"><span class="shp-alert">!</span></div>',
289
  'href' => $link,
290
  'meta' => array('target'=> $blank, 'class' => 'shortpixel-toolbar-processing' . $extraClasses)
291
  );
446
  }
447
 
448
  public function handleImageProcessing($ID = null) {
449
+ die("stop");
450
  //0: check key
451
  if( $this->_verifiedKey == false) {
452
  if($ID == null){
999
  'sslverify' => false,
1000
  'body' => array('key' => $apiKey)
1001
  );
1002
+ $argsStr = "?key=".$apiKey;
1003
 
1004
  if($appendUserAgent) {
1005
  $args['body']['useragent'] = "Agent" . urlencode($_SERVER['HTTP_USER_AGENT']);
1006
+ $argsStr .= "&useragent=Agent".$args['body']['useragent'];
1007
  }
1008
  if($validate) {
1009
  $args['body']['DomainCheck'] = get_site_url();
1010
  $imageCount = $this->countAllProcessableFiles();
1011
  $args['body']['ImagesCount'] = $imageCount['mainFiles'];
1012
  $args['body']['ThumbsCount'] = $imageCount['totalFiles'] - $imageCount['mainFiles'];
1013
+ $argsStr .= "&DomainCheck={$args['body']['DomainCheck']}&ImagesCount={$imageCount['mainFiles']}&ThumbsCount={$args['body']['ThumbsCount']}";
1014
  }
1015
 
1016
+ //Try first HTTPS post
1017
  $response = wp_remote_post($requestURL, $args);
1018
+ //some hosting providers won't allow https:// POST connections so we try http:// as well
1019
+ if(is_wp_error( $response ))
1020
  $response = wp_remote_post(str_replace('https://', 'http://', $requestURL), $args);
1021
+ //Second fallback to HTTP get
1022
+ if(is_wp_error( $response )){
1023
+ $args['body'] = array();
1024
+ $response = wp_remote_get(str_replace('https://', 'http://', $requestURL).$argsStr, $args);
1025
+ }
1026
  $defaultData = array(
1027
  "APIKeyValid" => false,
1028
  "Message" => 'API Key could not be validated due to a connectivity error.<BR>Your firewall may be blocking us. Please contact your hosting provider and ask them to allow connections from your site to IP 176.9.106.46.<BR> If you still cannot validate your API Key after this, please <a href="https://shortpixel.com/contact" target="_blank">contact us</a> and we will try to help. ',
1058
  update_option('wp-short-pixel-quota-exceeded',0);
1059
  else
1060
  update_option('wp-short-pixel-quota-exceeded',1);//activate quota limiting
1061
+
1062
+ //if a not valid status exists, delete it
1063
+ $lastStatus = self::getOpt( 'wp-short-pixel-bulk-last-status', array('Status' => ShortPixelAPI::STATUS_SUCCESS));
1064
+ if($lastStatus['Status'] == ShortPixelAPI::STATUS_NO_KEY) {
1065
+ delete_option('wp-short-pixel-bulk-last-status');
1066
+ }
1067
+
1068
  return array(
1069
  "APIKeyValid" => true,
1070
  "APICallsMade" => number_format($data->APICallsMade) . ' images',