ShortPixel Image Optimizer - Version 3.2.0

Version Description

  • ICC color profile is always preserved.
  • possibility to hide the API key in a multisite install.
  • detection of best protocol to use: https / http.
Download this release

Release Info

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

Code changes from version 3.1.9 to 3.2.0

js/short-pixel.js CHANGED
@@ -106,11 +106,11 @@ function checkQuotaExceededAlert() {
106
  * calls itself until receives an Empty queue message
107
  */
108
  function checkBulkProgress() {
109
- if( window.location.href.search("wp-admin/upload.php") < 0
110
- && window.location.href.search("wp-admin/edit.php") < 0
111
- && window.location.href.search("wp-admin/edit-tags.php") < 0
112
- && window.location.href.search("wp-admin/post-new.php") < 0
113
- && window.location.href.search("wp-admin/post.php") < 0) {
114
  hideToolBarAlert();
115
  return;
116
  }
106
  * calls itself until receives an Empty queue message
107
  */
108
  function checkBulkProgress() {
109
+ if( window.location.href.search(ShortPixel.WP_ADMIN_URL + "upload.php") < 0
110
+ && window.location.href.search(ShortPixel.WP_ADMIN_URL + "edit.php") < 0
111
+ && window.location.href.search(ShortPixel.WP_ADMIN_URL + "edit-tags.php") < 0
112
+ && window.location.href.search(ShortPixel.WP_ADMIN_URL + "post-new.php") < 0
113
+ && window.location.href.search(ShortPixel.WP_ADMIN_URL + "post.php") < 0) {
114
  hideToolBarAlert();
115
  return;
116
  }
readme.txt CHANGED
@@ -5,7 +5,7 @@ Tags: picture, optimization, image editor, pngout, upload speed, shortpixel, co
5
 
6
  Requires at least: 3.2.0
7
  Tested up to: 4.4
8
- Stable tag: 3.1.9
9
  License: GPLv2 or later
10
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
11
 
@@ -124,6 +124,8 @@ As an alternative, you can edit wp-config.php and add this line
124
  define('SHORTPIXEL_API_KEY', 'APIKEY')
125
  where 'APIKEY' is the API Key received upon sign up.
126
 
 
 
127
  = How does Bulk Optimization work? =
128
 
129
  The Bulk option makes ShortPixel optimize all your images at once (not one by one). You can do this in the Media > Bulk ShortPixel section by clicking on the **Compress all your images** button.
@@ -168,11 +170,16 @@ The ShortPixel team is here to help. <a href="https://shortpixel.com/contact">Co
168
 
169
  == Changelog ==
170
 
 
 
 
 
 
 
171
  = 3.1.9 =
172
 
173
  * option to keep the EXIF data and ICC profile.
174
  * more explanations on settings.
175
- *
176
 
177
  = 3.1.8 =
178
 
5
 
6
  Requires at least: 3.2.0
7
  Tested up to: 4.4
8
+ Stable tag: 3.2.0
9
  License: GPLv2 or later
10
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
11
 
124
  define('SHORTPIXEL_API_KEY', 'APIKEY')
125
  where 'APIKEY' is the API Key received upon sign up.
126
 
127
+ If configured that way, the API key will be used for all the sites of the multisite but will only be visible on the main site's Settings page, being hidden for the rest of the sites.
128
+
129
  = How does Bulk Optimization work? =
130
 
131
  The Bulk option makes ShortPixel optimize all your images at once (not one by one). You can do this in the Media > Bulk ShortPixel section by clicking on the **Compress all your images** button.
170
 
171
  == Changelog ==
172
 
173
+ = 3.2.0 =
174
+
175
+ * ICC color profile is always preserved.
176
+ * possibility to hide the API key in a multisite install.
177
+ * detection of best protocol to use: https / http.
178
+
179
  = 3.1.9 =
180
 
181
  * option to keep the EXIF data and ICC profile.
182
  * more explanations on settings.
 
183
 
184
  = 3.1.8 =
185
 
shortpixel_api.php CHANGED
@@ -17,11 +17,12 @@ class ShortPixelAPI {
17
 
18
  private $_settings;
19
  private $_maxAttempts = 10;
20
- private $_apiEndPoint = 'https://api.shortpixel.com/v2/reducer_dev.php';
21
 
22
 
23
  public function __construct($settings) {
24
  $this->_settings = $settings;
 
25
  add_action('processImageAction', array(&$this, 'processImageAction'), 10, 4);
26
  }
27
 
@@ -153,9 +154,11 @@ class ShortPixelAPI {
153
  default:
154
  //handle error
155
  if ( !file_exists($PATHs[0]) )
156
- return array("Status" => self::STATUS_NOT_FOUND, "Message" => "File not found on disk.");
157
- elseif ( isset($APIresponse[0]->Status->Message) )
158
- return array("Status" => self::STATUS_FAIL, "Message" => "There was an error and your request was not processed (" . $APIresponse[0]->Status->Message . ").");
 
 
159
 
160
  return array("Status" => self::STATUS_FAIL, "Message" => "There was an error and your request was not processed");
161
  break;
17
 
18
  private $_settings;
19
  private $_maxAttempts = 10;
20
+ private $_apiEndPoint;
21
 
22
 
23
  public function __construct($settings) {
24
  $this->_settings = $settings;
25
+ $this->_apiEndPoint = $this->_settings->httpProto . '://api.shortpixel.com/v2/reducer_dev.php';
26
  add_action('processImageAction', array(&$this, 'processImageAction'), 10, 4);
27
  }
28
 
154
  default:
155
  //handle error
156
  if ( !file_exists($PATHs[0]) )
157
+ return array("Status" => self::STATUS_NOT_FOUND, "Message" => "File not found on disk. Image ID: " .$ID);
158
+ elseif ( isset($APIresponse[0]->Status->Message) ) {
159
+ //return array("Status" => self::STATUS_FAIL, "Message" => "There was an error and your request was not processed (" . $APIresponse[0]->Status->Message . "). REQ: " . json_encode($URLs));
160
+ return array("Status" => self::STATUS_FAIL, "Message" => "There was an error and your request was not processed (" . $APIresponse[0]->Status->Message . ")");
161
+ }
162
 
163
  return array("Status" => self::STATUS_FAIL, "Message" => "There was an error and your request was not processed");
164
  break;
shortpixel_queue.php CHANGED
@@ -176,7 +176,7 @@ class ShortPixelQueue {
176
  $this->bulkAlreadyDoneCount = $res["mainFiles"];
177
  $this->settings->setOpt("wp-short-pixel-bulk-done-count", $this->bulkAlreadyDoneCount);
178
  //percent already done
179
- $this->bulkPreviousPercent = round($this->bulkAlreadyDoneCount / $this->bulkCount *100);
180
  $this->settings->setOpt("wp-short-pixel-bulk-previous-percent", $this->bulkPreviousPercent);
181
  }
182
 
176
  $this->bulkAlreadyDoneCount = $res["mainFiles"];
177
  $this->settings->setOpt("wp-short-pixel-bulk-done-count", $this->bulkAlreadyDoneCount);
178
  //percent already done
179
+ $this->bulkPreviousPercent = round($this->bulkAlreadyDoneCount / ($this->bulkCount ?: 1) * 100);
180
  $this->settings->setOpt("wp-short-pixel-bulk-previous-percent", $this->bulkPreviousPercent);
181
  }
182
 
shortpixel_view.php CHANGED
@@ -18,18 +18,18 @@ class ShortPixelView {
18
  <br/>
19
  <div class="wrap sp-quota-exceeded-alert">
20
  <h3>Quota Exceeded</h3>
21
- <p>The plugin has optimized <strong><?=number_format($quotaData['APICallsMadeNumeric'] + $quotaData['APICallsMadeOneTimeNumeric'])?> images</strong> and stopped because it reached the available quota limit.
22
  <?php if($quotaData['totalProcessedFiles'] < $quotaData['totalFiles']) { ?>
23
- <strong><?=number_format($quotaData['mainFiles'] - $quotaData['mainProcessedFiles'])?> images and
24
- <?=number_format(($quotaData['totalFiles'] - $quotaData['mainFiles']) - ($quotaData['totalProcessedFiles'] - $quotaData['mainProcessedFiles']))?> thumbnails</strong> are not yet optimized by ShortPixel.
25
  <?php } ?></p>
26
  <div> <!-- style='float:right;margin-top:20px;'> -->
27
- <a class='button button-primary' href='https://shortpixel.com/login/<?=$this->ctrl->getApiKey()?>' target='_blank'>Upgrade</a>
28
  <input type='button' name='checkQuota' class='button' value='Confirm New Quota' onclick="javascript:window.location.reload();">
29
  </div>
30
- <!-- <p>It’s simple to upgrade, just <a href='https://shortpixel.com/login/<?=$this->ctrl->getApiKey()?>' target='_blank'>log into your account</a> and see the available options.
31
  You can immediately start processing 5,000 images/month for &#36;4,99, choose another plan that suits you or <a href='https://shortpixel.com/contact' target='_blank'>contact us</a> for larger compression needs.</p> -->
32
- <p>Get more image credits by referring ShortPixel to your friends! <a href="https://shortpixel.com/login/<?=$this->ctrl->getApiKey()?>/tell-a-friend" target="_blank">Check your account</a> for your unique referral link. For each user that joins, you will receive +100 additional image credits/month.</p>
33
 
34
  </div> <?php
35
  }
@@ -43,9 +43,9 @@ class ShortPixelView {
43
  }
44
 
45
  public static function displayActivationNotice($when = 'activate') { ?>
46
- <div class='notice notice-warning' id='short-pixel-notice-<?=$when?>'>
47
  <?php if($when != 'activate') { ?>
48
- <div style="float:right;"><a href="javascript:dismissShortPixelNotice('<?=$when?>')" class="button" style="margin-top:10px;">Dismiss</a></div>
49
  <?php } ?>
50
  <h3>ShortPixel Optimization</h3> <?php
51
  switch($when) {
@@ -72,27 +72,27 @@ class ShortPixelView {
72
  if ( !$bulkRan ) {
73
  ?>
74
  <form class='start' action='' method='POST' id='startBulk'>
75
- <input type='hidden' id='mainToProcess' value='<?=$quotaData['mainFiles'] - $quotaData['mainProcessedFiles']?>'/>
76
- <input type='hidden' id='totalToProcess' value='<?=$quotaData['totalFiles'] - $quotaData['totalProcessedFiles']?>'/>
77
  <div class="bulk-stats-container">
78
  <h3 style='margin-top:0;'>Your image library</h3>
79
  <div class="bulk-label">Original images</div>
80
- <div class="bulk-val"><?=number_format($quotaData['mainFiles'])?></div><br>
81
  <div class="bulk-label">Smaller thumbnails</div>
82
- <div class="bulk-val"><?=number_format($quotaData['totalFiles'] - $quotaData['mainFiles'])?></div>
83
  <div style='width:165px; display:inline-block; padding-left: 5px'>
84
- <input type='checkbox' id='thumbnails' name='thumbnails' onclick='ShortPixel.checkThumbsUpdTotal(this)' <?=$this->ctrl->processThumbnails() ? "checked":""?>> Include thumbnails
85
  </div><br>
86
  <?php if($quotaData["totalProcessedFiles"] > 0) { ?>
87
  <div class="bulk-label bulk-total">Total images</div>
88
- <div class="bulk-val bulk-total"><?=number_format($quotaData['totalFiles'])?></div>
89
  <br><div class="bulk-label">Already optimized originals</div>
90
- <div class="bulk-val"><?=number_format($quotaData['mainProcessedFiles'])?></div><br>
91
  <div class="bulk-label">Already optimized thumbnails</div>
92
- <div class="bulk-val"><?=number_format($quotaData['totalProcessedFiles'] - $quotaData['mainProcessedFiles'])?></div><br>
93
  <?php } ?>
94
  <div class="bulk-label bulk-total">Total to be optimized</div>
95
- <div class="bulk-val bulk-total" id='displayTotal'><?=number_format($quotaData['totalFiles'] - $quotaData['totalProcessedFiles'])?></div>
96
  </div>
97
  <?php if($quotaData['totalFiles'] - $quotaData['totalProcessedFiles'] > 0) { ?>
98
  <div class="bulk-play">
@@ -104,10 +104,10 @@ class ShortPixelView {
104
  </div>
105
  <div class="bulk-btn-txt">
106
  <span class="label">Start Optimizing</span><br>
107
- <span class='total'><?=number_format($quotaData['totalFiles'] - $quotaData['totalProcessedFiles'])?></span> images
108
  </div>
109
  <div class="bulk-btn-img" class="bulk-btn-img">
110
- <img src='<?=plugins_url( 'img/arrow.png', __FILE__ )?>'/>
111
  </div>
112
  </div>
113
  </a>
@@ -133,19 +133,19 @@ class ShortPixelView {
133
  <h3>How does it work?</h3>
134
  <p>The plugin processes images starting with the newest ones you uploaded in your Media Library.</p>
135
  <p>You will be able to pause the process anytime.</p>
136
- <p><?=$this->ctrl->backupImages() ? "<p>Your original images will be stored in a separate back-up folder.</p>" : ""?></p>
137
  <p>You can watch the images being processed live, right here, after you start optimizing.</p>
138
  </div>
139
  <?php
140
  } elseif($percent) // bulk is paused
141
  { ?>
142
  <p>Bulk processing is paused until you resume the optimization process.</p>
143
- <?=$this->displayBulkProgressBar(false, $percent, "")?>
144
  <p>Please see below the optimization status so far:</p>
145
- <?=$this->displayBulkStats($quotaData['totalProcessedFiles'], $quotaData['mainProcessedFiles'], $under5PercentCount, $averageCompression, $savedSpace)?>
146
  <?php if($quotaData['totalProcessedFiles'] < $quotaData['totalFiles']) { ?>
147
- <p><?=number_format($quotaData['mainFiles'] - $quotaData['mainProcessedFiles'])?> images and
148
- <?=number_format(($quotaData['totalFiles'] - $quotaData['mainFiles']) - ($quotaData['totalProcessedFiles'] - $quotaData['mainProcessedFiles']))?> thumbnails are not yet optimized by ShortPixel.</p>
149
  <?php } ?>
150
  <p>You can continue optimizing your Media Gallery from where you left, by clicking the Resume processing button. Already optimized images will not be reprocessed.</p>
151
  <?php
@@ -155,7 +155,7 @@ class ShortPixelView {
155
  </p>
156
  <div style='display:inline-block;margin-left: 20px;'>
157
  <a href="https://twitter.com/share" class="twitter-share-button" data-url="https://shortpixel.com"
158
- data-text="I just optimized my images<?=0+$averageCompression>20 ? " by ".round($averageCompression) ."%" : ""?><?=false && (0+$savedSpace>0 ? " saving $savedSpace" : "")?> with @ShortPixel, a great plugin for increasing #WordPress page speed:" data-size='large'>Tweet</a>
159
  <script>
160
  !function(d,s,id){//Just optimized my site with ShortPixel image optimization plugin
161
  var js,
@@ -167,20 +167,20 @@ class ShortPixelView {
167
  </script>
168
  </div>
169
  </div>
170
- <?=$this->displayBulkStats($quotaData['totalProcessedFiles'], $quotaData['mainProcessedFiles'], $under5PercentCount, $averageCompression, $savedSpace)?>
171
- <p>Go to the ShortPixel <a href='<?=get_admin_url()?>options-general.php?page=wp-shortpixel#stats'>Stats</a> and see all your websites' optimized stats. Download your detailed <a href="https://api.shortpixel.com/v2/report.php?key=<?=$this->ctrl->getApiKey()?>">Optimization Report</a> to check your image optimization statistics for the last 40 days</p>
172
  <?php if($quotaData['totalProcessedFiles'] < $quotaData['totalFiles']) { ?>
173
- <p><?=number_format($quotaData['mainFiles'] - $quotaData['mainProcessedFiles'])?> images and
174
- <?=number_format(($quotaData['totalFiles'] - $quotaData['mainFiles']) - ($quotaData['totalProcessedFiles'] - $quotaData['mainProcessedFiles']))?> thumbnails are not yet optimized by ShortPixel.</p>
175
  <?php }
176
  $failed = $this->ctrl->getPrioQ()->getFailed();
177
  if(count($failed)) { ?>
178
  <p>The following images could not be processed because of their limited write rights. This usually happens if you have changed your hosting provider. Please restart the optimization process after you granted write rights to all the files below.</p>
179
- <?=$this->displayFailed($failed)?>
180
  <?php } ?>
181
  <p>Restart the optimization process for new images added to your library by clicking the button below. Already optimized images will not be reprocessed.
182
  <form action='' method='POST' >
183
- <input type='checkbox' name='thumbnails' <?=$this->ctrl->processThumbnails() ? "checked":""?>> Include thumbnails<br><br>
184
  <input type='submit' name='bulkProcess' id='bulkProcess' class='button button-primary' value='Restart Optimizing'>
185
  </form>
186
  <?php } ?>
@@ -194,9 +194,9 @@ class ShortPixelView {
194
  <h1>Bulk Image Optimization by ShortPixel</h1>
195
  <p>Bulk optimization has started.<br>
196
  This process will take some time, depending on the number of images in your library. In the meantime, you can continue using
197
- the admin as usual, <a href='<?=get_admin_url()?>' target='_blank'>in a different browser window or tab</a>.<br>
198
  However, <strong>if you close this window, the bulk processing will pause</strong> until you open the media gallery or the ShortPixel bulk page again. </p>
199
- <?=$this->displayBulkProgressBar(true, $percent, $message)?>
200
  <div class="bulk-progress bulk-slider-container">
201
  <div style="margin-bottom: 10px;"><span class="short-pixel-block-title">Just optimized:</span></div>
202
  <div class="bulk-slider">
@@ -230,18 +230,18 @@ class ShortPixelView {
230
  ?>
231
  <div class="bulk-progress">
232
  <div id="bulk-progress" class="progress" >
233
- <div class="progress-img" style="left: <?=$percent?>%;">
234
- <img src="<?=plugins_url( 'img/slider.png', __FILE__ )?>">
235
- <span><?=$percentAfter?></span>
236
  </div>
237
- <div class="progress-left" style="width: <?=$percent?>%"><?=$percentBefore?></div>
238
  </div>
239
  <div class="bulk-estimate">
240
- &nbsp;<?=$message?>
241
  </div>
242
  <form action='' method='POST' style="display:inline;">
243
  <input type="submit" class="button button-primary bulk-cancel" onclick="clearBulkProcessor();"
244
- name="<?=$running ? "bulkProcessPause" : "bulkProcessResume"?>" value="<?=$running ? "Pause" : "Resume Processing"?>"/>
245
  </form>
246
  </div>
247
  <?php
@@ -249,14 +249,14 @@ class ShortPixelView {
249
 
250
  public function displayBulkStats($totalOptimized, $mainOptimized, $under5PercentCount, $averageCompression, $savedSpace) {?>
251
  <div class="bulk-progress bulk-stats">
252
- <div class="label">Processed Images and PDFs:</div><div class="stat-value"><?=number_format($mainOptimized)?></div><br>
253
- <div class="label">Processed Thumbnails:</div><div class="stat-value"><?=number_format($totalOptimized - $mainOptimized)?></div><br>
254
- <div class="label totals">Total files processed:</div><div class="stat-value"><?=number_format($totalOptimized)?></div><br>
255
- <div class="label totals">Minus files with <5% optimization (free):</div><div class="stat-value"><?=number_format($under5PercentCount)?></div><br><br>
256
- <div class="label totals">Used quota:</div><div class="stat-value"><?=number_format($totalOptimized - $under5PercentCount)?></div><br>
257
  <br>
258
- <div class="label">Average optimization:</div><div class="stat-value"><?=$averageCompression?>%</div><br>
259
- <div class="label">Saved space:</div><div class="stat-value"><?=$savedSpace?></div>
260
  </div>
261
  <?php
262
  }
@@ -269,35 +269,35 @@ class ShortPixelView {
269
  if(isset($meta["ShortPixelImprovement"]) && is_numeric($meta["ShortPixelImprovement"])){
270
  $this->ctrl->getPrioQ()->removeFromFailed($fail);
271
  } else {
272
- ?> <div class="label"><a href="/wp-admin/post.php?post=<?=$fail?>&action=edit"><?=substr($meta["file"], 0, 80)?> - ID: <?=$fail?></a></div><br/>
273
  <?php }
274
  }?>
275
  </div>
276
  <?php
277
  }
278
 
279
- function displaySettings($quotaData, $notice, $resources = null, $averageCompression = null, $savedSpace = null, $savedBandwidth = null,
280
  $remainingImages = null, $totalCallsMade = null, $fileCount = null, $backupFolderSize = null) {
281
  //wp_enqueue_script('jquery.idTabs.js', plugins_url('/js/jquery.idTabs.js',__FILE__) );
282
  ?>
283
  <h1>ShortPixel Plugin Settings</h1>
284
  <p style="font-size:18px">
285
- <a href="https://shortpixel.com/<?=$this->ctrl->getVerifiedKey() ? "login/".$this->ctrl->getApiKey() : "pricing"?>" target="_blank" style="font-size:18px">
286
  Upgrade now
287
  </a> |
288
  <a href="https://shortpixel.com/contact" target="_blank" style="font-size:18px">Support </a>
289
  </p>
290
  <?php if($notice !== null) { ?>
291
  <br/>
292
- <div style="background-color: #fff; border-left: 4px solid <?=$notice['status'] == 'error' ? '#ff0000' : ($notice['status'] == 'warn' ? '#FFC800' : '#7ad03a')?>; box-shadow: 0 1px 1px 0 rgba(0, 0, 0, 0.1); padding: 1px 12px;;width: 95%">
293
- <p><?=$notice['msg']?></p>
294
  </div>
295
  <?php } ?>
296
 
297
  <article class="tabs">
298
  <section class='sel-tab' id="tab-settings">
299
  <h2><a class='tab-link' href='javascript:void(0);' data-id="tab-settings">Settings</a></h2>
300
- <?php $this->displaySettingsForm($quotaData);?>
301
  </section> <?php
302
  if($averageCompression !== null) {?>
303
  <section id="tab-stats">
@@ -310,7 +310,7 @@ class ShortPixelView {
310
  if($resources !== null) {?>
311
  <section id="tab-resources">
312
  <h2><a class='tab-link' href='javascript:void(0);' data-id="tab-resources">WP Resources</a></h2>
313
- <?=(isset($resources['body']) ? $resources['body'] : "Please reload")?>
314
  </section>
315
  <?php } ?>
316
  </article>
@@ -326,7 +326,7 @@ class ShortPixelView {
326
  <?php
327
  }
328
 
329
- public function displaySettingsForm($quotaData) {
330
  $settings = $this->ctrl->getSettings();
331
  $checked = ($this->ctrl->processThumbnails() ? 'checked' : '');
332
  $checkedBackupImages = ($this->ctrl->backupImages() ? 'checked' : '');
@@ -338,22 +338,33 @@ class ShortPixelView {
338
  $thumbnailsToProcess = isset($quotaData['totalFiles']) ? ($quotaData['totalFiles'] - $quotaData['mainFiles']) - ($quotaData['totalProcessedFiles'] - $quotaData['mainProcessedFiles']) : 0;
339
  ?>
340
  <?php if($this->ctrl->getVerifiedKey()) { ?>
341
- <p>New images uploaded to the Media Library will be optimized automatically.<br/>If you have existing images you would like to optimize, you can use the <a href="<?=get_admin_url()?>upload.php?page=wp-short-pixel-bulk">Bulk Optimization Tool</a>.</p>
342
- <?php } else { ?>
 
343
  <h3>Step 1:</h3>
344
- <p style='font-size: 14px'>If you don't have an API Key, <a href="https://shortpixel.com/wp-apikey<?= $this->ctrl->getAffiliateSufix() ?>" target="_blank">sign up here.</a> It's free and it only takes one minute, we promise!</p>
345
  <h3>Step 2:</h3>
346
  <p style='font-size: 14px'>Please enter here the API Key you received by email and press Validate.</p>
347
- <?php } ?>
 
348
  <form name='wp_shortpixel_options' action='options-general.php?page=wp-shortpixel&noheader=true' method='post' id='wp_shortpixel_options'>
349
  <table class="form-table">
350
  <tbody>
351
  <tr>
352
  <th scope="row"><label for="key">API Key:</label></th>
353
- <td><input name="key" type="text" id="key" value="<?= $this->ctrl->getApiKey() ?>" class="regular-text">
 
 
 
 
 
 
 
 
 
354
  <input type="hidden" name="validate" id="valid" value=""/>
355
  <button type="button" id="validate" class="button button-primary" title="Validate the provided API key"
356
- onclick="validateKey()">Validate</button>
357
  </td>
358
  </tr>
359
  <?php if (!$this->ctrl->getVerifiedKey()) { //if invalid key we display the link to the API Key ?>
@@ -366,11 +377,11 @@ class ShortPixelView {
366
  <label for="compressionType">Compression type:</label>
367
  </th>
368
  <td>
369
- <input type="radio" name="compressionType" value="1" <?= $this->ctrl->getCompressionType() == 1 ? "checked" : "" ?>>Lossy (recommended)</br>
370
  <p class="settings-info"> <b>Lossy compression: </b>lossy has a better compression rate than lossless compression.</br>While the resulting image
371
  is not 100% identical with the original, in the vast majority of cases the difference is not noticeable. You can
372
  <a href="https://shortpixel.com/online-image-compression" target="_blank">freely test your images</a> for lossy optimization.</p></br>
373
- <input type="radio" name="compressionType" value="0" <?= $this->ctrl->getCompressionType() != 1 ? "checked" : "" ?>>Lossless
374
  <p class="settings-info"><b>Lossless compression: </b> the shrunk image will be identical with the original and smaller in size.</br>In some rare cases you will need to use
375
  this type of compression. Some technical drawings or images from vector graphics are possible situations.</p>
376
  </td>
@@ -381,41 +392,40 @@ class ShortPixelView {
381
  <tbody>
382
  <tr>
383
  <th scope="row"><label for="thumbnails">Also include thumbnails:</label></th>
384
- <td><input name="thumbnails" type="checkbox" id="thumbnails" <?= $checked ?>> Apply compression also to
385
- <strong><?=$thumbnailsToProcess ? number_format($thumbnailsToProcess) : ""?> image thumbnails.</strong>
386
  <p class="settings-info">It is highly recommended that you optimize the thumbnails as they are usually the images most viewed by end users and can generate most traffic.<br>Please note that thumbnails count up to your total quota.</p>
387
  </td>
388
  </tr>
389
  <tr>
390
  <th scope="row"><label for="backupImages">Image backup</label></th>
391
  <td>
392
- <input name="backupImages" type="checkbox" id="backupImages" <?= $checkedBackupImages ?>> Save and keep a backup of your original images in a separate folder.
393
  <p class="settings-info">Usually recommended for safety.</p>
394
  </td>
395
  </tr>
396
  <tr>
397
  <th scope="row"><label for="cmyk2rgb">CMYK to RGB conversion</label></th>
398
  <td>
399
- <input name="cmyk2rgb" type="checkbox" id="cmyk2rgb" <?= $cmyk2rgb ?>>Adjust your images for computer and mobile screen display.
400
  </td>
401
  </tr>
402
  <tr>
403
  <th scope="row"><label for="removeExif">Remove EXIF</label></th>
404
  <td>
405
- <input name="removeExif" type="checkbox" id="removeExif" <?= $removeExif ?>>Remove the EXIF tag and ICC profile of the image (recommended).
406
- <p class="settings-info"> EXIF is a set of various pieces of information that are automatically embedded into the image upon creation. This can include GPS position, camera manufacturer, date and time, etc.
407
- ICC profile specifies the color profile that is used by the image.
408
  Unless you really need that data to be kept we recommend you removing it as it can lead to <a href="http://blog.shortpixel.com/how-much-smaller-can-be-images-without-exif-icc" target="_blank">better compression rates</a>.</p></br>
409
  </td>
410
  </tr>
411
  <tr>
412
  <th scope="row"><label for="resize">Resize large images</label></th>
413
  <td>
414
- <input name="resize" type="checkbox" id="resize" <?= $resize ?>> to maximum
415
- <input type="text" name="width" id="width" style="width:70px" value="<?= max($this->ctrl->getResizeWidth(), min(1024, $minSizes['width'])) ?>" <?= $resizeDisabled ?>/> pixels wide &times;
416
- <input type="text" name="height" id="height" style="width:70px" value="<?= max($this->ctrl->getResizeHeight(), min(1024, $minSizes['height'])) ?>" <?= $resizeDisabled ?>/> pixels high (original aspect ratio is preserved)
417
  <p class="settings-info"> Recommended for large photos, like the ones taken with your phone. Saved space can go up to 80% or more after resizing.<br/>
418
- The new resolution should not be less than your largest thumbnail size, which is <?=$minSizes['width']?> &times; <?=$minSizes['height']?> pixels.</p>
419
  </td>
420
  </tr>
421
  </tbody>
@@ -428,15 +438,15 @@ class ShortPixelView {
428
  <script>
429
  var rad = document.wp_shortpixel_options.compressionType;
430
  var prev = null;
431
- var minWidth = Math.min(1024, <?=$minSizes['width']?>),
432
- minHeight = Math.min(1024, <?=$minSizes['height']?>);
433
  for(var i = 0; i < rad.length; i++) {
434
  rad[i].onclick = function() {
435
 
436
  if(this !== prev) {
437
  prev = this;
438
  }
439
- alert('This type of optimization will apply to new uploaded images.\\nImages that were already processed will not be re-optimized.');
440
  };
441
  }
442
  function enableResize(elm) {
@@ -478,15 +488,15 @@ class ShortPixelView {
478
  <tbody>
479
  <tr>
480
  <th scope="row"><label for="averagCompression">Average compression of your files:</label></th>
481
- <td><?=$averageCompression?>%</td>
482
  </tr>
483
  <tr>
484
  <th scope="row"><label for="savedSpace">Saved disk space by ShortPixel</label></th>
485
- <td><?=$savedSpace?></td>
486
  </tr>
487
  <tr>
488
  <th scope="row"><label for="savedBandwidth">Bandwith* saved with ShortPixel:</label></th>
489
- <td><?=$savedBandwidth?></td>
490
  </tr>
491
  </tbody>
492
  </table>
@@ -499,39 +509,39 @@ class ShortPixelView {
499
  <tr>
500
  <th scope="row" bgcolor="#ffffff"><label for="apiQuota">Your ShortPixel plan</label></th>
501
  <td bgcolor="#ffffff">
502
- <?=$quotaData['APICallsQuota']?>/month, renews in <?=floor(30 + (strtotime($quotaData['APILastRenewalDate']) - time()) / 86400)?> days, on <?=date('M d, Y', strtotime($quotaData['APILastRenewalDate']. ' + 30 days'))?> ( <a href="https://shortpixel.com/login/<?=$this->ctrl->getApiKey();?>" target="_blank">Need More? See the options available</a> )<br/>
503
- <a href="https://shortpixel.com/login/<?=$this->ctrl->getApiKey()?>/tell-a-friend" target="_blank">Join our friend referral system</a> to win more credits. For each user that joins, you receive +100 images credits/month.
504
  </td>
505
  </tr>
506
  <tr>
507
  <th scope="row"><label for="usedQUota">One time credits:</label></th>
508
- <td><?= number_format($quotaData['APICallsQuotaOneTimeNumeric'])?></td>
509
  </tr>
510
  <tr>
511
  <th scope="row"><label for="usedQUota">Number of images processed this month:</label></th>
512
- <td><?=$totalCallsMade?> (<a href="https://api.shortpixel.com/v2/report.php?key=<?=$this->ctrl->getApiKey()?>" target="_blank">see report</a>)</td>
513
  </tr>
514
  <tr>
515
  <th scope="row"><label for="remainingImages">Remaining** images in your plan: </label></th>
516
- <td><?=$remainingImages?> images</td>
517
  </tr>
518
  </tbody>
519
  </table>
520
 
521
- <p style="padding-top: 0px; color: #818181;" >** Increase your image quota by <a href="https://shortpixel.com/login/<?=$this->ctrl->getApiKey()?>" target="_blank">upgrading your ShortPixel plan.</a></p>
522
 
523
  <table class="form-table">
524
  <tbody>
525
  <tr>
526
  <th scope="row"><label for="totalFiles">Total number of processed files:</label></th>
527
- <td><?=$fileCount?></td>
528
  </tr>
529
  <?php if($this->ctrl->backupImages()) { ?>
530
  <tr>
531
  <th scope="row"><label for="sizeBackup">Original images are stored in a backup folder. Your backup folder size is now:</label></th>
532
  <td>
533
  <form action="" method="POST">
534
- <?=$backupFolderSize?>
535
  <input type="submit" style="margin-left: 15px; vertical-align: middle;" class="button button-secondary" name="emptyBackup" value="Empty backups"/>
536
  </form>
537
  </td>
18
  <br/>
19
  <div class="wrap sp-quota-exceeded-alert">
20
  <h3>Quota Exceeded</h3>
21
+ <p>The plugin has optimized <strong><?php echo(number_format($quotaData['APICallsMadeNumeric'] + $quotaData['APICallsMadeOneTimeNumeric']));?> images</strong> and stopped because it reached the available quota limit.
22
  <?php if($quotaData['totalProcessedFiles'] < $quotaData['totalFiles']) { ?>
23
+ <strong><?php echo(number_format($quotaData['mainFiles'] - $quotaData['mainProcessedFiles']));?> images and
24
+ <?php echo(number_format(($quotaData['totalFiles'] - $quotaData['mainFiles']) - ($quotaData['totalProcessedFiles'] - $quotaData['mainProcessedFiles'])));?> thumbnails</strong> are not yet optimized by ShortPixel.
25
  <?php } ?></p>
26
  <div> <!-- style='float:right;margin-top:20px;'> -->
27
+ <a class='button button-primary' href='https://shortpixel.com/login/<?php echo($this->ctrl->getApiKey());?>' target='_blank'>Upgrade</a>
28
  <input type='button' name='checkQuota' class='button' value='Confirm New Quota' onclick="javascript:window.location.reload();">
29
  </div>
30
+ <!-- <p>It’s simple to upgrade, just <a href='https://shortpixel.com/login/<?php echo($this->ctrl->getApiKey());?>' target='_blank'>log into your account</a> and see the available options.
31
  You can immediately start processing 5,000 images/month for &#36;4,99, choose another plan that suits you or <a href='https://shortpixel.com/contact' target='_blank'>contact us</a> for larger compression needs.</p> -->
32
+ <p>Get more image credits by referring ShortPixel to your friends! <a href="https://shortpixel.com/login/<?php echo($this->ctrl->getApiKey());?>/tell-a-friend" target="_blank">Check your account</a> for your unique referral link. For each user that joins, you will receive +100 additional image credits/month.</p>
33
 
34
  </div> <?php
35
  }
43
  }
44
 
45
  public static function displayActivationNotice($when = 'activate') { ?>
46
+ <div class='notice notice-warning' id='short-pixel-notice-<?php echo($when);?>'>
47
  <?php if($when != 'activate') { ?>
48
+ <div style="float:right;"><a href="javascript:dismissShortPixelNotice('<?php echo($when);?>')" class="button" style="margin-top:10px;">Dismiss</a></div>
49
  <?php } ?>
50
  <h3>ShortPixel Optimization</h3> <?php
51
  switch($when) {
72
  if ( !$bulkRan ) {
73
  ?>
74
  <form class='start' action='' method='POST' id='startBulk'>
75
+ <input type='hidden' id='mainToProcess' value='<?php echo($quotaData['mainFiles'] - $quotaData['mainProcessedFiles']);?>'/>
76
+ <input type='hidden' id='totalToProcess' value='<?php echo($quotaData['totalFiles'] - $quotaData['totalProcessedFiles']);?>'/>
77
  <div class="bulk-stats-container">
78
  <h3 style='margin-top:0;'>Your image library</h3>
79
  <div class="bulk-label">Original images</div>
80
+ <div class="bulk-val"><?php echo(number_format($quotaData['mainFiles']));?></div><br>
81
  <div class="bulk-label">Smaller thumbnails</div>
82
+ <div class="bulk-val"><?php echo(number_format($quotaData['totalFiles'] - $quotaData['mainFiles']));?></div>
83
  <div style='width:165px; display:inline-block; padding-left: 5px'>
84
+ <input type='checkbox' id='thumbnails' name='thumbnails' onclick='ShortPixel.checkThumbsUpdTotal(this)' <?php echo($this->ctrl->processThumbnails() ? "checked":"");?>> Include thumbnails
85
  </div><br>
86
  <?php if($quotaData["totalProcessedFiles"] > 0) { ?>
87
  <div class="bulk-label bulk-total">Total images</div>
88
+ <div class="bulk-val bulk-total"><?php echo(number_format($quotaData['totalFiles']));?></div>
89
  <br><div class="bulk-label">Already optimized originals</div>
90
+ <div class="bulk-val"><?php echo(number_format($quotaData['mainProcessedFiles']));?></div><br>
91
  <div class="bulk-label">Already optimized thumbnails</div>
92
+ <div class="bulk-val"><?php echo(number_format($quotaData['totalProcessedFiles'] - $quotaData['mainProcessedFiles']));?></div><br>
93
  <?php } ?>
94
  <div class="bulk-label bulk-total">Total to be optimized</div>
95
+ <div class="bulk-val bulk-total" id='displayTotal'><?php echo(number_format($quotaData['totalFiles'] - $quotaData['totalProcessedFiles']));?></div>
96
  </div>
97
  <?php if($quotaData['totalFiles'] - $quotaData['totalProcessedFiles'] > 0) { ?>
98
  <div class="bulk-play">
104
  </div>
105
  <div class="bulk-btn-txt">
106
  <span class="label">Start Optimizing</span><br>
107
+ <span class='total'><?php echo(number_format($quotaData['totalFiles'] - $quotaData['totalProcessedFiles']));?></span> images
108
  </div>
109
  <div class="bulk-btn-img" class="bulk-btn-img">
110
+ <img src='<?php echo(plugins_url( 'img/arrow.png', __FILE__ ));?>'/>
111
  </div>
112
  </div>
113
  </a>
133
  <h3>How does it work?</h3>
134
  <p>The plugin processes images starting with the newest ones you uploaded in your Media Library.</p>
135
  <p>You will be able to pause the process anytime.</p>
136
+ <p><?php echo($this->ctrl->backupImages() ? "<p>Your original images will be stored in a separate back-up folder.</p>" : "");?></p>
137
  <p>You can watch the images being processed live, right here, after you start optimizing.</p>
138
  </div>
139
  <?php
140
  } elseif($percent) // bulk is paused
141
  { ?>
142
  <p>Bulk processing is paused until you resume the optimization process.</p>
143
+ <?php echo($this->displayBulkProgressBar(false, $percent, ""));?>
144
  <p>Please see below the optimization status so far:</p>
145
+ <?php $this->displayBulkStats($quotaData['totalProcessedFiles'], $quotaData['mainProcessedFiles'], $under5PercentCount, $averageCompression, $savedSpace);?>
146
  <?php if($quotaData['totalProcessedFiles'] < $quotaData['totalFiles']) { ?>
147
+ <p><?php echo(number_format($quotaData['mainFiles'] - $quotaData['mainProcessedFiles']));?> images and
148
+ <?php echo(number_format(($quotaData['totalFiles'] - $quotaData['mainFiles']) - ($quotaData['totalProcessedFiles'] - $quotaData['mainProcessedFiles'])));?> thumbnails are not yet optimized by ShortPixel.</p>
149
  <?php } ?>
150
  <p>You can continue optimizing your Media Gallery from where you left, by clicking the Resume processing button. Already optimized images will not be reprocessed.</p>
151
  <?php
155
  </p>
156
  <div style='display:inline-block;margin-left: 20px;'>
157
  <a href="https://twitter.com/share" class="twitter-share-button" data-url="https://shortpixel.com"
158
+ data-text="I just optimized my images<?php echo(0+$averageCompression>20 ? " by ".round($averageCompression) ."%" : "");?><?php echo(false && (0+$savedSpace>0) ? " saving $savedSpace" : "");?> with @ShortPixel, a great plugin for increasing #WordPress page speed:" data-size='large'>Tweet</a>
159
  <script>
160
  !function(d,s,id){//Just optimized my site with ShortPixel image optimization plugin
161
  var js,
167
  </script>
168
  </div>
169
  </div>
170
+ <?php $this->displayBulkStats($quotaData['totalProcessedFiles'], $quotaData['mainProcessedFiles'], $under5PercentCount, $averageCompression, $savedSpace);?>
171
+ <p>Go to the ShortPixel <a href='<?php echo(get_admin_url());?>options-general.php?page=wp-shortpixel#stats'>Stats</a> and see all your websites' optimized stats. Download your detailed <a href="https://api.shortpixel.com/v2/report.php?key=<?php echo($this->ctrl->getApiKey());?>">Optimization Report</a> to check your image optimization statistics for the last 40 days</p>
172
  <?php if($quotaData['totalProcessedFiles'] < $quotaData['totalFiles']) { ?>
173
+ <p><?php echo(number_format($quotaData['mainFiles'] - $quotaData['mainProcessedFiles']));?> images and
174
+ <?php echo(number_format(($quotaData['totalFiles'] - $quotaData['mainFiles']) - ($quotaData['totalProcessedFiles'] - $quotaData['mainProcessedFiles'])));?> thumbnails are not yet optimized by ShortPixel.</p>
175
  <?php }
176
  $failed = $this->ctrl->getPrioQ()->getFailed();
177
  if(count($failed)) { ?>
178
  <p>The following images could not be processed because of their limited write rights. This usually happens if you have changed your hosting provider. Please restart the optimization process after you granted write rights to all the files below.</p>
179
+ <?php $this->displayFailed($failed);?>
180
  <?php } ?>
181
  <p>Restart the optimization process for new images added to your library by clicking the button below. Already optimized images will not be reprocessed.
182
  <form action='' method='POST' >
183
+ <input type='checkbox' name='thumbnails' <?php echo($this->ctrl->processThumbnails() ? "checked":"");?>> Include thumbnails<br><br>
184
  <input type='submit' name='bulkProcess' id='bulkProcess' class='button button-primary' value='Restart Optimizing'>
185
  </form>
186
  <?php } ?>
194
  <h1>Bulk Image Optimization by ShortPixel</h1>
195
  <p>Bulk optimization has started.<br>
196
  This process will take some time, depending on the number of images in your library. In the meantime, you can continue using
197
+ the admin as usual, <a href='<?php echo(get_admin_url());?>' target='_blank'>in a different browser window or tab</a>.<br>
198
  However, <strong>if you close this window, the bulk processing will pause</strong> until you open the media gallery or the ShortPixel bulk page again. </p>
199
+ <?php $this->displayBulkProgressBar(true, $percent, $message);?>
200
  <div class="bulk-progress bulk-slider-container">
201
  <div style="margin-bottom: 10px;"><span class="short-pixel-block-title">Just optimized:</span></div>
202
  <div class="bulk-slider">
230
  ?>
231
  <div class="bulk-progress">
232
  <div id="bulk-progress" class="progress" >
233
+ <div class="progress-img" style="left: <?php echo($percent);?>%;">
234
+ <img src="<?php echo(plugins_url( 'img/slider.png', __FILE__ ));?>">
235
+ <span><?php echo($percentAfter);?></span>
236
  </div>
237
+ <div class="progress-left" style="width: <?php echo($percent);?>%"><?php echo($percentBefore);?></div>
238
  </div>
239
  <div class="bulk-estimate">
240
+ &nbsp;<?php echo($message);?>
241
  </div>
242
  <form action='' method='POST' style="display:inline;">
243
  <input type="submit" class="button button-primary bulk-cancel" onclick="clearBulkProcessor();"
244
+ name="<?php echo($running ? "bulkProcessPause" : "bulkProcessResume");?>" value="<?php echo($running ? "Pause" : "Resume Processing");?>"/>
245
  </form>
246
  </div>
247
  <?php
249
 
250
  public function displayBulkStats($totalOptimized, $mainOptimized, $under5PercentCount, $averageCompression, $savedSpace) {?>
251
  <div class="bulk-progress bulk-stats">
252
+ <div class="label">Processed Images and PDFs:</div><div class="stat-value"><?php echo(number_format($mainOptimized));?></div><br>
253
+ <div class="label">Processed Thumbnails:</div><div class="stat-value"><?php echo(number_format($totalOptimized - $mainOptimized));?></div><br>
254
+ <div class="label totals">Total files processed:</div><div class="stat-value"><?php echo(number_format($totalOptimized));?></div><br>
255
+ <div class="label totals">Minus files with <5% optimization (free):</div><div class="stat-value"><?php echo(number_format($under5PercentCount));?></div><br><br>
256
+ <div class="label totals">Used quota:</div><div class="stat-value"><?php echo(number_format($totalOptimized - $under5PercentCount));?></div><br>
257
  <br>
258
+ <div class="label">Average optimization:</div><div class="stat-value"><?php echo($averageCompression);?>%</div><br>
259
+ <div class="label">Saved space:</div><div class="stat-value"><?php echo($savedSpace);?></div>
260
  </div>
261
  <?php
262
  }
269
  if(isset($meta["ShortPixelImprovement"]) && is_numeric($meta["ShortPixelImprovement"])){
270
  $this->ctrl->getPrioQ()->removeFromFailed($fail);
271
  } else {
272
+ ?> <div class="label"><a href="/wp-admin/post.php?post=<?php echo($fail);?>&action=edit"><?php echo(substr($meta["file"], 0, 80));?> - ID: <?php echo($fail);?></a></div><br/>
273
  <?php }
274
  }?>
275
  </div>
276
  <?php
277
  }
278
 
279
+ function displaySettings($showApiKey, $quotaData, $notice, $resources = null, $averageCompression = null, $savedSpace = null, $savedBandwidth = null,
280
  $remainingImages = null, $totalCallsMade = null, $fileCount = null, $backupFolderSize = null) {
281
  //wp_enqueue_script('jquery.idTabs.js', plugins_url('/js/jquery.idTabs.js',__FILE__) );
282
  ?>
283
  <h1>ShortPixel Plugin Settings</h1>
284
  <p style="font-size:18px">
285
+ <a href="https://shortpixel.com/<?php echo($this->ctrl->getVerifiedKey() ? "login/".$this->ctrl->getApiKey() : "pricing");?>" target="_blank" style="font-size:18px">
286
  Upgrade now
287
  </a> |
288
  <a href="https://shortpixel.com/contact" target="_blank" style="font-size:18px">Support </a>
289
  </p>
290
  <?php if($notice !== null) { ?>
291
  <br/>
292
+ <div style="background-color: #fff; border-left: 4px solid <?php echo($notice['status'] == 'error' ? '#ff0000' : ($notice['status'] == 'warn' ? '#FFC800' : '#7ad03a'));?>; box-shadow: 0 1px 1px 0 rgba(0, 0, 0, 0.1); padding: 1px 12px;;width: 95%">
293
+ <p><?php echo($notice['msg']);?></p>
294
  </div>
295
  <?php } ?>
296
 
297
  <article class="tabs">
298
  <section class='sel-tab' id="tab-settings">
299
  <h2><a class='tab-link' href='javascript:void(0);' data-id="tab-settings">Settings</a></h2>
300
+ <?php $this->displaySettingsForm($showApiKey, $quotaData);?>
301
  </section> <?php
302
  if($averageCompression !== null) {?>
303
  <section id="tab-stats">
310
  if($resources !== null) {?>
311
  <section id="tab-resources">
312
  <h2><a class='tab-link' href='javascript:void(0);' data-id="tab-resources">WP Resources</a></h2>
313
+ <?php echo((isset($resources['body']) ? $resources['body'] : "Please reload"));?>
314
  </section>
315
  <?php } ?>
316
  </article>
326
  <?php
327
  }
328
 
329
+ public function displaySettingsForm($showApiKey, $quotaData) {
330
  $settings = $this->ctrl->getSettings();
331
  $checked = ($this->ctrl->processThumbnails() ? 'checked' : '');
332
  $checkedBackupImages = ($this->ctrl->backupImages() ? 'checked' : '');
338
  $thumbnailsToProcess = isset($quotaData['totalFiles']) ? ($quotaData['totalFiles'] - $quotaData['mainFiles']) - ($quotaData['totalProcessedFiles'] - $quotaData['mainProcessedFiles']) : 0;
339
  ?>
340
  <?php if($this->ctrl->getVerifiedKey()) { ?>
341
+ <p>New images uploaded to the Media Library will be optimized automatically.<br/>If you have existing images you would like to optimize, you can use the <a href="<?php echo(get_admin_url());?>upload.php?page=wp-short-pixel-bulk">Bulk Optimization Tool</a>.</p>
342
+ <?php } else {
343
+ if($showApiKey) {?>
344
  <h3>Step 1:</h3>
345
+ <p style='font-size: 14px'>If you don't have an API Key, <a href="https://shortpixel.com/wp-apikey<?php echo( $this->ctrl->getAffiliateSufix() );?>" target="_blank">sign up here.</a> It's free and it only takes one minute, we promise!</p>
346
  <h3>Step 2:</h3>
347
  <p style='font-size: 14px'>Please enter here the API Key you received by email and press Validate.</p>
348
+ <?php }
349
+ }?>
350
  <form name='wp_shortpixel_options' action='options-general.php?page=wp-shortpixel&noheader=true' method='post' id='wp_shortpixel_options'>
351
  <table class="form-table">
352
  <tbody>
353
  <tr>
354
  <th scope="row"><label for="key">API Key:</label></th>
355
+ <td>
356
+ <?php
357
+ $canValidate = false;
358
+ if($showApiKey) {
359
+ $canValidate = true;?>
360
+ <input name="key" type="text" id="key" value="<?php echo( $this->ctrl->getApiKey() );?>" class="regular-text">
361
+ <?php } elseif(defined("SHORTPIXEL_API_KEY")) {
362
+ $canValidate = true;?>
363
+ <input name="key" type="text" id="key" disabled="true" placeholder="Multisite API Key" class="regular-text">
364
+ <?php }?>
365
  <input type="hidden" name="validate" id="valid" value=""/>
366
  <button type="button" id="validate" class="button button-primary" title="Validate the provided API key"
367
+ onclick="validateKey()" <?php echo $canValidate ? "" : "disabled"?>>Validate</button>
368
  </td>
369
  </tr>
370
  <?php if (!$this->ctrl->getVerifiedKey()) { //if invalid key we display the link to the API Key ?>
377
  <label for="compressionType">Compression type:</label>
378
  </th>
379
  <td>
380
+ <input type="radio" name="compressionType" value="1" <?php echo( $this->ctrl->getCompressionType() == 1 ? "checked" : "" );?>>Lossy (recommended)</br>
381
  <p class="settings-info"> <b>Lossy compression: </b>lossy has a better compression rate than lossless compression.</br>While the resulting image
382
  is not 100% identical with the original, in the vast majority of cases the difference is not noticeable. You can
383
  <a href="https://shortpixel.com/online-image-compression" target="_blank">freely test your images</a> for lossy optimization.</p></br>
384
+ <input type="radio" name="compressionType" value="0" <?php echo( $this->ctrl->getCompressionType() != 1 ? "checked" : "" );?>>Lossless
385
  <p class="settings-info"><b>Lossless compression: </b> the shrunk image will be identical with the original and smaller in size.</br>In some rare cases you will need to use
386
  this type of compression. Some technical drawings or images from vector graphics are possible situations.</p>
387
  </td>
392
  <tbody>
393
  <tr>
394
  <th scope="row"><label for="thumbnails">Also include thumbnails:</label></th>
395
+ <td><input name="thumbnails" type="checkbox" id="thumbnails" <?php echo( $checked );?>> Apply compression also to
396
+ <strong><?php echo($thumbnailsToProcess ? number_format($thumbnailsToProcess) : "");?> image thumbnails.</strong>
397
  <p class="settings-info">It is highly recommended that you optimize the thumbnails as they are usually the images most viewed by end users and can generate most traffic.<br>Please note that thumbnails count up to your total quota.</p>
398
  </td>
399
  </tr>
400
  <tr>
401
  <th scope="row"><label for="backupImages">Image backup</label></th>
402
  <td>
403
+ <input name="backupImages" type="checkbox" id="backupImages" <?php echo( $checkedBackupImages );?>> Save and keep a backup of your original images in a separate folder.
404
  <p class="settings-info">Usually recommended for safety.</p>
405
  </td>
406
  </tr>
407
  <tr>
408
  <th scope="row"><label for="cmyk2rgb">CMYK to RGB conversion</label></th>
409
  <td>
410
+ <input name="cmyk2rgb" type="checkbox" id="cmyk2rgb" <?php echo( $cmyk2rgb );?>>Adjust your images for computer and mobile screen display.
411
  </td>
412
  </tr>
413
  <tr>
414
  <th scope="row"><label for="removeExif">Remove EXIF</label></th>
415
  <td>
416
+ <input name="removeExif" type="checkbox" id="removeExif" <?php echo( $removeExif );?>>Remove the EXIF tag of the image (recommended).
417
+ <p class="settings-info"> EXIF is a set of various pieces of information that are automatically embedded into the image upon creation. This can include GPS position, camera manufacturer, date and time, etc.
 
418
  Unless you really need that data to be kept we recommend you removing it as it can lead to <a href="http://blog.shortpixel.com/how-much-smaller-can-be-images-without-exif-icc" target="_blank">better compression rates</a>.</p></br>
419
  </td>
420
  </tr>
421
  <tr>
422
  <th scope="row"><label for="resize">Resize large images</label></th>
423
  <td>
424
+ <input name="resize" type="checkbox" id="resize" <?php echo( $resize );?>> to maximum
425
+ <input type="text" name="width" id="width" style="width:70px" value="<?php echo( max($this->ctrl->getResizeWidth(), min(1024, $minSizes['width'])) );?>" <?php echo( $resizeDisabled );?>/> pixels wide &times;
426
+ <input type="text" name="height" id="height" style="width:70px" value="<?php echo( max($this->ctrl->getResizeHeight(), min(1024, $minSizes['height'])) );?>" <?php echo( $resizeDisabled );?>/> pixels high (original aspect ratio is preserved)
427
  <p class="settings-info"> Recommended for large photos, like the ones taken with your phone. Saved space can go up to 80% or more after resizing.<br/>
428
+ The new resolution should not be less than your largest thumbnail size, which is <?php echo($minSizes['width']);?> &times; <?php echo($minSizes['height']);?> pixels.</p>
429
  </td>
430
  </tr>
431
  </tbody>
438
  <script>
439
  var rad = document.wp_shortpixel_options.compressionType;
440
  var prev = null;
441
+ var minWidth = Math.min(1024, <?php echo($minSizes['width']);?>),
442
+ minHeight = Math.min(1024, <?php echo($minSizes['height']);?>);
443
  for(var i = 0; i < rad.length; i++) {
444
  rad[i].onclick = function() {
445
 
446
  if(this !== prev) {
447
  prev = this;
448
  }
449
+ alert('This type of optimization will apply to new uploaded images.\nImages that were already processed will not be re-optimized.');
450
  };
451
  }
452
  function enableResize(elm) {
488
  <tbody>
489
  <tr>
490
  <th scope="row"><label for="averagCompression">Average compression of your files:</label></th>
491
+ <td><?php echo($averageCompression);?>%</td>
492
  </tr>
493
  <tr>
494
  <th scope="row"><label for="savedSpace">Saved disk space by ShortPixel</label></th>
495
+ <td><?php echo($savedSpace);?></td>
496
  </tr>
497
  <tr>
498
  <th scope="row"><label for="savedBandwidth">Bandwith* saved with ShortPixel:</label></th>
499
+ <td><?php echo($savedBandwidth);?></td>
500
  </tr>
501
  </tbody>
502
  </table>
509
  <tr>
510
  <th scope="row" bgcolor="#ffffff"><label for="apiQuota">Your ShortPixel plan</label></th>
511
  <td bgcolor="#ffffff">
512
+ <?php echo($quotaData['APICallsQuota']);?>/month, renews in <?php echo(floor(30 + (strtotime($quotaData['APILastRenewalDate']) - time()) / 86400));?> days, on <?php echo(date('M d, Y', strtotime($quotaData['APILastRenewalDate']. ' + 30 days')));?> ( <a href="https://shortpixel.com/login/<?php echo($this->ctrl->getApiKey());?>" target="_blank">Need More? See the options available</a> )<br/>
513
+ <a href="https://shortpixel.com/login/<?php echo($this->ctrl->getApiKey());?>/tell-a-friend" target="_blank">Join our friend referral system</a> to win more credits. For each user that joins, you receive +100 images credits/month.
514
  </td>
515
  </tr>
516
  <tr>
517
  <th scope="row"><label for="usedQUota">One time credits:</label></th>
518
+ <td><?php echo( number_format($quotaData['APICallsQuotaOneTimeNumeric']));?></td>
519
  </tr>
520
  <tr>
521
  <th scope="row"><label for="usedQUota">Number of images processed this month:</label></th>
522
+ <td><?php echo($totalCallsMade);?> (<a href="https://api.shortpixel.com/v2/report.php?key=<?php echo($this->ctrl->getApiKey());?>" target="_blank">see report</a>)</td>
523
  </tr>
524
  <tr>
525
  <th scope="row"><label for="remainingImages">Remaining** images in your plan: </label></th>
526
+ <td><?php echo($remainingImages);?> images</td>
527
  </tr>
528
  </tbody>
529
  </table>
530
 
531
+ <p style="padding-top: 0px; color: #818181;" >** Increase your image quota by <a href="https://shortpixel.com/login/<?php echo($this->ctrl->getApiKey());?>" target="_blank">upgrading your ShortPixel plan.</a></p>
532
 
533
  <table class="form-table">
534
  <tbody>
535
  <tr>
536
  <th scope="row"><label for="totalFiles">Total number of processed files:</label></th>
537
+ <td><?php echo($fileCount);?></td>
538
  </tr>
539
  <?php if($this->ctrl->backupImages()) { ?>
540
  <tr>
541
  <th scope="row"><label for="sizeBackup">Original images are stored in a backup folder. Your backup folder size is now:</label></th>
542
  <td>
543
  <form action="" method="POST">
544
+ <?php echo($backupFolderSize);?>
545
  <input type="submit" style="margin-left: 15px; vertical-align: middle;" class="button button-secondary" name="emptyBackup" value="Empty backups"/>
546
  </form>
547
  </td>
wp-shortpixel-settings.php CHANGED
@@ -33,10 +33,7 @@ class WPShortPixelSettings {
33
  'totalOptimized' => 'wp-short-pixel-total-optimized',
34
  'totalOriginal' => 'wp-short-pixel-total-original',
35
  'quotaExceeded' => 'wp-short-pixel-quota-exceeded',
36
- '' => '',
37
- '' => '',
38
- '' => '',
39
- '' => '',
40
  '' => '',
41
  );
42
 
@@ -137,7 +134,7 @@ class WPShortPixelSettings {
137
  }
138
  }
139
 
140
- public function getOpt($key, $default = null) {
141
  if(get_option($key) === false) {
142
  add_option( $key, $default, '', 'yes' );
143
  }
33
  'totalOptimized' => 'wp-short-pixel-total-optimized',
34
  'totalOriginal' => 'wp-short-pixel-total-original',
35
  'quotaExceeded' => 'wp-short-pixel-quota-exceeded',
36
+ 'httpProto' => 'wp-short-pixel-protocol',
 
 
 
37
  '' => '',
38
  );
39
 
134
  }
135
  }
136
 
137
+ public static function getOpt($key, $default = null) {
138
  if(get_option($key) === false) {
139
  add_option( $key, $default, '', 'yes' );
140
  }
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.9
7
  * Author: ShortPixel
8
  * Author URI: https://shortpixel.com
9
  */
@@ -22,9 +22,9 @@ define('SP_RESET_ON_ACTIVATE', false); //if true TODO set false
22
 
23
  define('SP_AFFILIATE_CODE', '');
24
 
25
- define('PLUGIN_VERSION', "3.1.9");
26
  define('SP_MAX_TIMEOUT', 10);
27
- define('SP_VALIDATE_MAX_TIMEOUT', 60);
28
  define('SP_BACKUP', 'ShortpixelBackups');
29
  define('SP_BACKUP_FOLDER', WP_CONTENT_DIR . DIRECTORY_SEPARATOR . 'uploads' . DIRECTORY_SEPARATOR . SP_BACKUP);
30
  define('MAX_API_RETRIES', 50);
@@ -182,16 +182,17 @@ class WPShortPixel {
182
  jQuery(document).ready(function($){
183
  if(typeof ShortPixel !== 'undefined') {
184
  ShortPixel.setOptions({
185
- STATUS_SUCCESS: <?= ShortPixelAPI::STATUS_SUCCESS ?>,
186
- STATUS_EMPTY_QUEUE: <?= self::BULK_EMPTY_QUEUE ?>,
187
- STATUS_ERROR: <?= ShortPixelAPI::STATUS_ERROR ?>,
188
- STATUS_FAIL: <?= ShortPixelAPI::STATUS_FAIL ?>,
189
- STATUS_QUOTA_EXCEEDED: <?= ShortPixelAPI::STATUS_QUOTA_EXCEEDED ?>,
190
- STATUS_SKIP: <?= ShortPixelAPI::STATUS_SKIP ?>,
191
- STATUS_NO_KEY: <?= ShortPixelAPI::STATUS_NO_KEY ?>,
192
- STATUS_RETRY: <?= ShortPixelAPI::STATUS_RETRY ?>,
193
- WP_PLUGIN_URL: '<?= plugins_url( '', __FILE__ ) ?>',
194
- API_KEY: "<?= $this->_settings->apiKey ?>"
 
195
  });
196
  }
197
  });
@@ -470,14 +471,27 @@ class WPShortPixel {
470
  $percent = $meta["ShortPixelImprovement"];
471
 
472
  $filePath = explode("/", $meta["file"]);
473
- $uploadsUrl = content_url() . "/uploads/";
474
- $urlPath = implode("/", array_slice($filePath, 0, count($filePath) - 1));
475
- $urlBkPath = $this->_apiInterface->returnSubDir(get_attached_file($ID));
476
- $thumb = (isset($meta["sizes"]["medium"]) ? $meta["sizes"]["medium"]["file"] : (isset($meta["sizes"]["thumbnail"]) ? $meta["sizes"]["thumbnail"]["file"]: ""));
 
 
 
 
 
 
 
 
477
  if(strlen($thumb) && get_option('wp-short-backup_images') && $this->_settings->processThumbnails) {
478
- $bkThumb = $uploadsUrl . SP_BACKUP . "/" . $urlBkPath . "/" . $thumb;
 
 
479
  }
480
  if(strlen($thumb)) {
 
 
 
481
  $thumb = $uploadsUrl . $urlPath . "/" . $thumb;
482
  }
483
  $result["Thumb"] = $thumb;
@@ -781,10 +795,10 @@ class WPShortPixel {
781
  $notice = null;
782
 
783
  //by default we try to fetch the API Key from wp-config.php (if defined)
784
- if ( !isset($_POST['save']) && !get_option('wp-short-pixel-verifiedKey') && defined("SHORTPIXEL_API_KEY") && strlen(SHORTPIXEL_API_KEY) == 20 )
785
  {
786
  $_POST['validate'] = "validate";
787
- $_POST['key'] = SHORTPIXEL_API_KEY;
788
  }
789
 
790
  if(isset($_POST['save']) || (isset($_POST['validate']) && $_POST['validate'] == "validate")) {
@@ -880,11 +894,13 @@ class WPShortPixel {
880
  $remainingImages = ( $remainingImages < 0 ) ? 0 : number_format($remainingImages);
881
  $totalCallsMade = number_format($quotaData['APICallsMadeNumeric'] + $quotaData['APICallsMadeOneTimeNumeric']);
882
 
883
- $resources = wp_remote_get("https://shortpixel.com/resources-frag");
884
- $this->view->displaySettings($quotaData, $notice, $resources, $averageCompression, $savedSpace, $savedBandwidth,
885
- $remainingImages, $totalCallsMade, $fileCount, $backupFolderSize);
 
886
  } else {
887
- $this->view->displaySettings($quotaData, $notice);
 
888
  }
889
 
890
  }
@@ -905,9 +921,12 @@ class WPShortPixel {
905
  public function getQuotaInformation($apiKey = null, $appendUserAgent = false, $validate = false) {
906
 
907
  if(is_null($apiKey)) { $apiKey = $this->_settings->apiKey; }
 
 
908
 
909
- $requestURL = 'https://api.shortpixel.com/v2/api-status.php';
910
- $args = array('timeout'=> SP_VALIDATE_MAX_TIMEOUT,
 
911
  'sslverify' => false,
912
  'body' => array('key' => $apiKey)
913
  );
@@ -928,13 +947,24 @@ class WPShortPixel {
928
  //Try first HTTPS post
929
  $response = wp_remote_post($requestURL, $args);
930
  //some hosting providers won't allow https:// POST connections so we try http:// as well
931
- if(is_wp_error( $response ))
932
- $response = wp_remote_post(str_replace('https://', 'http://', $requestURL), $args);
 
 
 
 
 
 
 
 
 
 
 
933
  //Second fallback to HTTP get
934
  if(is_wp_error( $response )){
935
  $args['body'] = null;
936
  $requestURL .= $argsStr;
937
- $response = wp_remote_get(str_replace('https://', 'http://', $requestURL), $args);
938
  }
939
  $defaultData = array(
940
  "APIKeyValid" => false,
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.2.0
7
  * Author: ShortPixel
8
  * Author URI: https://shortpixel.com
9
  */
22
 
23
  define('SP_AFFILIATE_CODE', '');
24
 
25
+ define('PLUGIN_VERSION', "3.2.0");
26
  define('SP_MAX_TIMEOUT', 10);
27
+ define('SP_VALIDATE_MAX_TIMEOUT', 15);
28
  define('SP_BACKUP', 'ShortpixelBackups');
29
  define('SP_BACKUP_FOLDER', WP_CONTENT_DIR . DIRECTORY_SEPARATOR . 'uploads' . DIRECTORY_SEPARATOR . SP_BACKUP);
30
  define('MAX_API_RETRIES', 50);
182
  jQuery(document).ready(function($){
183
  if(typeof ShortPixel !== 'undefined') {
184
  ShortPixel.setOptions({
185
+ STATUS_SUCCESS: <?php echo ShortPixelAPI::STATUS_SUCCESS; ?>,
186
+ STATUS_EMPTY_QUEUE: <?php echo self::BULK_EMPTY_QUEUE; ?>,
187
+ STATUS_ERROR: <?php echo ShortPixelAPI::STATUS_ERROR; ?>,
188
+ STATUS_FAIL: <?php echo ShortPixelAPI::STATUS_FAIL; ?>,
189
+ STATUS_QUOTA_EXCEEDED: <?php echo ShortPixelAPI::STATUS_QUOTA_EXCEEDED; ?>,
190
+ STATUS_SKIP: <?php echo ShortPixelAPI::STATUS_SKIP; ?>,
191
+ STATUS_NO_KEY: <?php echo ShortPixelAPI::STATUS_NO_KEY; ?>,
192
+ STATUS_RETRY: <?php echo ShortPixelAPI::STATUS_RETRY; ?>,
193
+ WP_PLUGIN_URL: '<?php echo plugins_url( '', __FILE__ ); ?>',
194
+ WP_ADMIN_URL: '<?php echo admin_url(); ?>',
195
+ API_KEY: "<?php echo $this->_settings->apiKey; ?>"
196
  });
197
  }
198
  });
471
  $percent = $meta["ShortPixelImprovement"];
472
 
473
  $filePath = explode("/", $meta["file"]);
474
+
475
+ //Get a suitable thumb
476
+ if(isset($meta["sizes"]) && count($meta["sizes"])) {
477
+ $thumb = (isset($meta["sizes"]["medium"]) ? $meta["sizes"]["medium"]["file"] : (isset($meta["sizes"]["thumbnail"]) ? $meta["sizes"]["thumbnail"]["file"]: ""));
478
+ if(!strlen($thumb)) { //fallback to the first in the list
479
+ $sizes = isset($meta["sizes"]) ? array_values($meta["sizes"]) : array();
480
+ $thumb = count($sizes) ? $sizes[0]['file'] : '';
481
+ }
482
+ } else { //fallback to the image itself
483
+ $thumb = $meta["file"];
484
+ }
485
+
486
  if(strlen($thumb) && get_option('wp-short-backup_images') && $this->_settings->processThumbnails) {
487
+ $backupUrl = content_url() . "/uploads/" . SP_BACKUP . "/";
488
+ $urlBkPath = $this->_apiInterface->returnSubDir(get_attached_file($ID));
489
+ $bkThumb = $backupUrl . $urlBkPath . "/" . $thumb;
490
  }
491
  if(strlen($thumb)) {
492
+ $uploadDir = wp_upload_dir();
493
+ $uploadsUrl = $uploadDir["baseurl"] . "/";
494
+ $urlPath = implode("/", array_slice($filePath, 0, count($filePath) - 1));
495
  $thumb = $uploadsUrl . $urlPath . "/" . $thumb;
496
  }
497
  $result["Thumb"] = $thumb;
795
  $notice = null;
796
 
797
  //by default we try to fetch the API Key from wp-config.php (if defined)
798
+ if ( !isset($_POST['save']) && defined("SHORTPIXEL_API_KEY") && strlen(SHORTPIXEL_API_KEY) == 20 )
799
  {
800
  $_POST['validate'] = "validate";
801
+ $_POST['key'] = SHORTPIXEL_API_KEY;
802
  }
803
 
804
  if(isset($_POST['save']) || (isset($_POST['validate']) && $_POST['validate'] == "validate")) {
894
  $remainingImages = ( $remainingImages < 0 ) ? 0 : number_format($remainingImages);
895
  $totalCallsMade = number_format($quotaData['APICallsMadeNumeric'] + $quotaData['APICallsMadeOneTimeNumeric']);
896
 
897
+ $resources = wp_remote_get($this->_settings->httpProto . "://shortpixel.com/resources-frag");
898
+ $this->view->displaySettings(is_main_site() || (is_multisite() && !defined("SHORTPIXEL_API_KEY")),
899
+ $quotaData, $notice, $resources, $averageCompression, $savedSpace, $savedBandwidth,
900
+ $remainingImages, $totalCallsMade, $fileCount, $backupFolderSize);
901
  } else {
902
+ $this->view->displaySettings(is_main_site() || (is_multisite() && !defined("SHORTPIXEL_API_KEY")),
903
+ $quotaData, $notice);
904
  }
905
 
906
  }
921
  public function getQuotaInformation($apiKey = null, $appendUserAgent = false, $validate = false) {
922
 
923
  if(is_null($apiKey)) { $apiKey = $this->_settings->apiKey; }
924
+
925
+ //$this->_settings->httpProto = 'https';
926
 
927
+ $requestURL = $this->_settings->httpProto . '://api.shortpixel.com/v2/api-status.php';
928
+ $args = array(
929
+ 'timeout'=> SP_VALIDATE_MAX_TIMEOUT,
930
  'sslverify' => false,
931
  'body' => array('key' => $apiKey)
932
  );
947
  //Try first HTTPS post
948
  $response = wp_remote_post($requestURL, $args);
949
  //some hosting providers won't allow https:// POST connections so we try http:// as well
950
+ if(is_wp_error( $response )) {
951
+ //echo("protocol " . $this->_settings->httpProto . " failed. switching...");
952
+ $requestURL = $this->_settings->httpProto == 'https' ?
953
+ str_replace('https://', 'http://', $requestURL) :
954
+ str_replace('http://', 'https://', $requestURL);
955
+ $response = wp_remote_post($requestURL, $args);
956
+ if(!is_wp_error( $response )){
957
+ $this->_settings->httpProto = ($this->_settings->httpProto == 'https' ? 'http' : 'https');
958
+ //echo("protocol " . $this->_settings->httpProto . " succeeded");
959
+ } else {
960
+ //echo("protocol " . $this->_settings->httpProto . " failed too");
961
+ }
962
+ }
963
  //Second fallback to HTTP get
964
  if(is_wp_error( $response )){
965
  $args['body'] = null;
966
  $requestURL .= $argsStr;
967
+ $response = wp_remote_get($requestURL, $args);
968
  }
969
  $defaultData = array(
970
  "APIKeyValid" => false,