ShortPixel Image Optimizer - Version 4.0.2

Version Description

  • fix compatibility with PHP 5.2
  • fix for URLs like domain.com/CamelCasePath
Download this release

Release Info

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

Code changes from version 4.0.1 to 4.0.2

class/db/shortpixel-custom-meta-dao.php CHANGED
@@ -223,9 +223,9 @@ class ShortPixelCustomMetaDao {
223
  if(ShortPixelFolder::checkFolderIsSubfolder(SP_BACKUP_FOLDER, $addedPath)) {
224
  return "This folder contains the ShortPixel Backups. Please select a different folder.";
225
  }
226
- $customFolderPaths = array_map(function($item){return $item->getPath();}, $this->getFolders());
227
  $allFolders = $this->getFolders(true);
228
- $customAllFolderPaths = array_map(function($item){return $item->getPath();}, $allFolders);
229
  $parent = ShortPixelFolder::checkFolderIsSubfolder($addedPath, $customFolderPaths);
230
  if(!$parent){
231
  $sub = ShortPixelFolder::checkFolderIsParent($addedPath, $customAllFolderPaths);
@@ -366,8 +366,10 @@ class ShortPixelCustomMetaDao {
366
 
367
  public function update($meta) {
368
  $metaClass = get_class($meta);
369
- $sql = "UPDATE {$this->db->getPrefix()}shortpixel_" . $metaClass::TABLE_SUFFIX . " SET ";
370
- foreach(self::$fields[$metaClass::TABLE_SUFFIX] as $field => $type) {
 
 
371
  $getter = "get" . ShortPixelTools::snakeToCamel($field);
372
  $val = $meta->$getter();
373
  if($meta->$getter() !== null) {
@@ -387,7 +389,9 @@ class ShortPixelCustomMetaDao {
387
 
388
  public function delete($meta) {
389
  $metaClass = get_class($meta);
390
- $sql = "DELETE FROM {$this->db->getPrefix()}shortpixel_" . $metaClass::TABLE_SUFFIX . " WHERE id = %d";
 
 
391
  $this->db->query($sql, array($meta->getId()));
392
  }
393
 
223
  if(ShortPixelFolder::checkFolderIsSubfolder(SP_BACKUP_FOLDER, $addedPath)) {
224
  return "This folder contains the ShortPixel Backups. Please select a different folder.";
225
  }
226
+ $customFolderPaths = array_map(array('ShortPixelFolder','path'), $this->getFolders());
227
  $allFolders = $this->getFolders(true);
228
+ $customAllFolderPaths = array_map(array('ShortPixelFolder','path'), $allFolders);
229
  $parent = ShortPixelFolder::checkFolderIsSubfolder($addedPath, $customFolderPaths);
230
  if(!$parent){
231
  $sub = ShortPixelFolder::checkFolderIsParent($addedPath, $customAllFolderPaths);
366
 
367
  public function update($meta) {
368
  $metaClass = get_class($meta);
369
+ $tableSuffix = "";
370
+ eval( '$tableSuffix = ' . $metaClass . '::TABLE_SUFFIX;');
371
+ $sql = "UPDATE {$this->db->getPrefix()}shortpixel_" . $tableSuffix . " SET ";
372
+ foreach(self::$fields[$tableSuffix] as $field => $type) {
373
  $getter = "get" . ShortPixelTools::snakeToCamel($field);
374
  $val = $meta->$getter();
375
  if($meta->$getter() !== null) {
389
 
390
  public function delete($meta) {
391
  $metaClass = get_class($meta);
392
+ $tableSuffix = "";
393
+ eval( '$tableSuffix = ' . $metaClass . '::TABLE_SUFFIX;');
394
+ $sql = "DELETE FROM {$this->db->getPrefix()}shortpixel_" . $tableSuffix . " WHERE id = %d";
395
  $this->db->query($sql, array($meta->getId()));
396
  }
397
 
class/db/shortpixel-meta-facade.php CHANGED
@@ -21,6 +21,10 @@ class ShortPixelMetaFacade {
21
  $this->spMetaDao = new ShortPixelCustomMetaDao(new WpShortPixelDb());
22
  }
23
 
 
 
 
 
24
  function setRawMeta($rawMeta) {
25
  if($this->type == self::MEDIA_LIBRARY_TYPE) {
26
  $this->rawMeta = $rawMeta;
21
  $this->spMetaDao = new ShortPixelCustomMetaDao(new WpShortPixelDb());
22
  }
23
 
24
+ public static function getNewFromRow($item) {
25
+ return new ShortPixelMetaFacade("C-" . $item->id);
26
+ }
27
+
28
  function setRawMeta($rawMeta) {
29
  if($this->type == self::MEDIA_LIBRARY_TYPE) {
30
  $this->rawMeta = $rawMeta;
class/db/shortpixel-nextgen-adapter.php CHANGED
@@ -3,8 +3,7 @@
3
  class ShortPixelNextGenAdapter {
4
  public static function getGalleries () {
5
  global $wpdb;
6
- return array_map(function($item){return $item->path;}, $wpdb->get_results("SELECT path FROM {$wpdb->prefix}ngg_gallery"));
7
-
8
  }
9
 
10
  public static function hasNextGen() {
@@ -30,4 +29,12 @@ class ShortPixelNextGenAdapter {
30
  $image->meta_data['full'] = $size_meta;
31
  $mapper->save($image);
32
  }
 
 
 
 
 
 
 
 
33
  }
3
  class ShortPixelNextGenAdapter {
4
  public static function getGalleries () {
5
  global $wpdb;
6
+ return array_map(array('ShortPixelNextGenAdapter','path'), $wpdb->get_results("SELECT path FROM {$wpdb->prefix}ngg_gallery"));
 
7
  }
8
 
9
  public static function hasNextGen() {
29
  $image->meta_data['full'] = $size_meta;
30
  $mapper->save($image);
31
  }
32
+
33
+ public static function pathToAbsolute($item) {
34
+ return str_replace(DIRECTORY_SEPARATOR.DIRECTORY_SEPARATOR, DIRECTORY_SEPARATOR, get_home_path() . $item);
35
+ }
36
+
37
+ public static function path($item) {
38
+ return $item->path;
39
+ }
40
  }
class/model/shortpixel-folder.php CHANGED
@@ -195,4 +195,12 @@ class ShortPixelFolder extends ShortPixelEntity{
195
  $this->tsUpdated = $tsUpdated;
196
  }
197
 
 
 
 
 
 
 
 
 
198
  }
195
  $this->tsUpdated = $tsUpdated;
196
  }
197
 
198
+ /**
199
+ * needed as callback
200
+ * @param type $item
201
+ */
202
+ public static function path($item) {
203
+ return $item->getPath();
204
+ }
205
+
206
  }
class/view/shortpixel-list-table.php CHANGED
@@ -11,11 +11,11 @@ class ShortPixelListTable extends WP_List_Table {
11
  protected $hasNextGen;
12
 
13
  public function __construct($ctrl, $spMetaDao, $hasNextGen) {
14
- parent::__construct( [
15
  'singular' => 'Image', //singular name of the listed records
16
  'plural' => 'Images', //plural name of the listed records
17
  'ajax' => false //should this table support ajax?
18
- ] );
19
  $this->ctrl = $ctrl;
20
  $this->spMetaDao = $spMetaDao;
21
  $this->hasNextGen = $hasNextGen;
@@ -48,10 +48,10 @@ class ShortPixelListTable extends WP_List_Table {
48
  $actions = array();
49
  if($item->status <= 1) {
50
  // create the image web path
51
- $actions = [
52
  'optimize' => sprintf( '<a href="?page=%s&action=%s&image=%s&_wpnonce=%s">' . ($item->status == 0 ? 'Optimize' : 'Retry') . '</a>',
53
  esc_attr( $_REQUEST['page'] ), 'optimize', absint( $item->id ), wp_create_nonce( 'sp_optimize_image' ) )
54
- ];
55
  }
56
  $url = ShortPixelMetaFacade::pathToWebPath($item->folder);
57
  $actions['view'] = sprintf( '<a href="%s" target="_blank">View</a>', $url );
@@ -122,10 +122,10 @@ class ShortPixelListTable extends WP_List_Table {
122
  $currentPage = $this->get_pagenum();
123
  $total_items = $this->record_count();
124
 
125
- $this->set_pagination_args( [
126
  'total_items' => $total_items, //WE have to calculate the total number of items
127
  'per_page' => $perPage //WE have to determine how many items to show on a page
128
- ] );
129
 
130
  $orderby = ( ! empty( $_GET['orderby'] ) ) ? $_GET['orderby'] : 'ts_added';
131
  // If no order, default to asc
11
  protected $hasNextGen;
12
 
13
  public function __construct($ctrl, $spMetaDao, $hasNextGen) {
14
+ parent::__construct( array(
15
  'singular' => 'Image', //singular name of the listed records
16
  'plural' => 'Images', //plural name of the listed records
17
  'ajax' => false //should this table support ajax?
18
+ ));
19
  $this->ctrl = $ctrl;
20
  $this->spMetaDao = $spMetaDao;
21
  $this->hasNextGen = $hasNextGen;
48
  $actions = array();
49
  if($item->status <= 1) {
50
  // create the image web path
51
+ $actions = array(
52
  'optimize' => sprintf( '<a href="?page=%s&action=%s&image=%s&_wpnonce=%s">' . ($item->status == 0 ? 'Optimize' : 'Retry') . '</a>',
53
  esc_attr( $_REQUEST['page'] ), 'optimize', absint( $item->id ), wp_create_nonce( 'sp_optimize_image' ) )
54
+ );
55
  }
56
  $url = ShortPixelMetaFacade::pathToWebPath($item->folder);
57
  $actions['view'] = sprintf( '<a href="%s" target="_blank">View</a>', $url );
122
  $currentPage = $this->get_pagenum();
123
  $total_items = $this->record_count();
124
 
125
+ $this->set_pagination_args( array(
126
  'total_items' => $total_items, //WE have to calculate the total number of items
127
  'per_page' => $perPage //WE have to determine how many items to show on a page
128
+ ));
129
 
130
  $orderby = ( ! empty( $_GET['orderby'] ) ) ? $_GET['orderby'] : 'ts_added';
131
  // If no order, default to asc
readme.txt CHANGED
@@ -5,7 +5,7 @@ Tags: image optimizer, image optimization, compress pdf, compress jpeg, compress
5
 
6
  Requires at least: 3.2.0
7
  Tested up to: 4.6
8
- Stable tag: 4.0.1
9
  License: GPLv2 or later
10
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
11
 
@@ -201,6 +201,12 @@ The ShortPixel team is here to help. <a href="https://shortpixel.com/contact">Co
201
 
202
  == Changelog ==
203
 
 
 
 
 
 
 
204
  = 4.0.1 =
205
 
206
  * Optimize from the front-end option
5
 
6
  Requires at least: 3.2.0
7
  Tested up to: 4.6
8
+ Stable tag: 4.0.2
9
  License: GPLv2 or later
10
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
11
 
201
 
202
  == Changelog ==
203
 
204
+
205
+ = 4.0.2 =
206
+
207
+ * fix compatibility with PHP 5.2
208
+ * fix for URLs like domain.com/CamelCasePath
209
+
210
  = 4.0.1 =
211
 
212
  * Optimize from the front-end option
res/js/short-pixel.js CHANGED
@@ -294,13 +294,14 @@ function checkQuotaExceededAlert() {
294
  * calls itself until receives an Empty queue message
295
  */
296
  function checkBulkProgress() {
297
- if( window.location.href.search(ShortPixel.WP_ADMIN_URL + "upload.php") < 0
298
- && window.location.href.search(ShortPixel.WP_ADMIN_URL + "edit.php") < 0
299
- && window.location.href.search(ShortPixel.WP_ADMIN_URL + "edit-tags.php") < 0
300
- && window.location.href.search(ShortPixel.WP_ADMIN_URL + "post-new.php") < 0
301
- && window.location.href.search(ShortPixel.WP_ADMIN_URL + "post.php") < 0
302
- && window.location.href.search("page=nggallery-manage-gallery") < 0
303
- && (ShortPixel.FRONT_BOOTSTRAP == 0 || window.location.href.search(ShortPixel.WP_ADMIN_URL) == 0)
 
304
  ) {
305
  hideToolBarAlert();
306
  return;
294
  * calls itself until receives an Empty queue message
295
  */
296
  function checkBulkProgress() {
297
+ var url = window.location.href.toLowerCase();
298
+ if( url.search(ShortPixel.WP_ADMIN_URL + "upload.php") < 0
299
+ && url.search(ShortPixel.WP_ADMIN_URL + "edit.php") < 0
300
+ && url.search(ShortPixel.WP_ADMIN_URL + "edit-tags.php") < 0
301
+ && url.search(ShortPixel.WP_ADMIN_URL + "post-new.php") < 0
302
+ && url.search(ShortPixel.WP_ADMIN_URL + "post.php") < 0
303
+ && url.search("page=nggallery-manage-gallery") < 0
304
+ && (ShortPixel.FRONT_BOOTSTRAP == 0 || url.search(ShortPixel.WP_ADMIN_URL) == 0)
305
  ) {
306
  hideToolBarAlert();
307
  return;
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: 4.0.1
7
  * Author: ShortPixel
8
  * Author URI: https://shortpixel.com
9
  */
@@ -12,7 +12,7 @@ define('SP_RESET_ON_ACTIVATE', false); //if true TODO set false
12
 
13
  define('SP_AFFILIATE_CODE', '');
14
 
15
- define('PLUGIN_VERSION', "4.0.1");
16
  define('SP_MAX_TIMEOUT', 10);
17
  define('SP_VALIDATE_MAX_TIMEOUT', 15);
18
  define('SP_BACKUP', 'ShortpixelBackups');
@@ -568,9 +568,7 @@ class WPShortPixel {
568
  { //take from custom images if any left to optimize - only if bulk was ever started
569
  $customIds = $this->spMetaDao->getPendingMetas( 3 - count($ids));
570
  if(is_array($customIds)) {
571
- $ids = array_merge($ids, array_map(function($item) {
572
- return new ShortPixelMetaFacade("C-" . $item->id);
573
- }, $customIds));
574
  }
575
  }
576
  // var_dump($ids);
@@ -1511,9 +1509,7 @@ class WPShortPixel {
1511
  $quotaData = $this->checkQuotaAndAlert(isset($validityData) ? $validityData : null);
1512
 
1513
  if($this->hasNextGen) {
1514
- $ngg = array_map(function($item){
1515
- return str_replace(DIRECTORY_SEPARATOR.DIRECTORY_SEPARATOR, DIRECTORY_SEPARATOR, get_home_path() . $item);
1516
- }, ShortPixelNextGenAdapter::getGalleries());
1517
  //die(var_dump($ngg));
1518
  for($i = 0; $i < count($customFolders); $i++) {
1519
  if(in_array($customFolders[$i]->getPath(), $ngg )) {
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: 4.0.2
7
  * Author: ShortPixel
8
  * Author URI: https://shortpixel.com
9
  */
12
 
13
  define('SP_AFFILIATE_CODE', '');
14
 
15
+ define('PLUGIN_VERSION', "4.0.2");
16
  define('SP_MAX_TIMEOUT', 10);
17
  define('SP_VALIDATE_MAX_TIMEOUT', 15);
18
  define('SP_BACKUP', 'ShortpixelBackups');
568
  { //take from custom images if any left to optimize - only if bulk was ever started
569
  $customIds = $this->spMetaDao->getPendingMetas( 3 - count($ids));
570
  if(is_array($customIds)) {
571
+ $ids = array_merge($ids, array_map(array('ShortPixelMetaFacade', 'getNewFromRow'), $customIds));
 
 
572
  }
573
  }
574
  // var_dump($ids);
1509
  $quotaData = $this->checkQuotaAndAlert(isset($validityData) ? $validityData : null);
1510
 
1511
  if($this->hasNextGen) {
1512
+ $ngg = array_map(array('ShortPixelNextGenAdapter','pathToAbsolute'), ShortPixelNextGenAdapter::getGalleries());
 
 
1513
  //die(var_dump($ngg));
1514
  for($i = 0; $i < count($customFolders); $i++) {
1515
  if(in_array($customFolders[$i]->getPath(), $ngg )) {