Version Description
- fix not processing the images in the custom image folders if they had uppercase extensions
- remove the deprecated mcrypt calls.
- fix jQuery 3.x incompatibility when calling .unload() by using on("beforeunload" .. ) instead
Download this release
Release Info
| Developer | ShortPixel |
| Plugin | |
| Version | 4.2.4 |
| Comparing to | |
| See all releases | |
Code changes from version 4.2.2 to 4.2.4
- class/db/shortpixel-custom-meta-dao.php +10 -5
- class/db/shortpixel-meta-facade.php +33 -10
- class/db/wp-shortpixel-db.php +4 -1
- class/model/shortpixel-folder.php +5 -5
- class/view/shortpixel-list-table.php +9 -9
- class/view/shortpixel_view.php +20 -8
- readme.txt +15 -2
- res/css/short-pixel.css +10 -0
- res/js/short-pixel.js +2 -2
- wp-shortpixel.php +62 -39
class/db/shortpixel-custom-meta-dao.php
CHANGED
|
@@ -189,13 +189,18 @@ class ShortPixelCustomMetaDao {
|
|
| 189 |
public function newFolderFromPath($path, $uploadPath, $rootPath) {
|
| 190 |
WpShortPixelDb::checkCustomTables(); // check if custom tables are created, if not, create them
|
| 191 |
$addedFolder = ShortPixelFolder::checkFolder($path, $uploadPath);
|
| 192 |
-
$
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 193 |
if($this->getFolder($addedFolder)) {
|
| 194 |
return __('Folder already added.','shortpixel-image-optimiser');
|
| 195 |
}
|
| 196 |
-
if(strpos($addedFolder, $rootPath) !== 0) {
|
| 197 |
-
return( sprintf(__('The %s folder cannot be processed as it\'s not inside the root path of your website (%s).','shortpixel-image-optimiser'),$addedFolder, $rootPath));
|
| 198 |
-
}
|
| 199 |
$folder = new ShortPixelFolder(array("path" => $addedFolder));
|
| 200 |
try {
|
| 201 |
$folder->setFileCount($folder->countFiles());
|
|
@@ -320,7 +325,7 @@ class ShortPixelCustomMetaDao {
|
|
| 320 |
return $this->db->query("SELECT sm.id from {$this->db->getPrefix()}shortpixel_meta sm "
|
| 321 |
. "INNER JOIN {$this->db->getPrefix()}shortpixel_folders sf on sm.folder_id = sf.id "
|
| 322 |
. "WHERE sf.status <> -1 AND sm.status <> 3 AND ( sm.status = 0 OR sm.status = 1 OR (sm.status < 0 AND sm.retries < 3)) "
|
| 323 |
-
. "ORDER BY
|
| 324 |
}
|
| 325 |
|
| 326 |
public function getFolderOptimizationStatus($folderId) {
|
| 189 |
public function newFolderFromPath($path, $uploadPath, $rootPath) {
|
| 190 |
WpShortPixelDb::checkCustomTables(); // check if custom tables are created, if not, create them
|
| 191 |
$addedFolder = ShortPixelFolder::checkFolder($path, $uploadPath);
|
| 192 |
+
$addedFolderReal = realpath($addedFolder);
|
| 193 |
+
$addedFolder = wp_normalize_path($addedFolder); $addedFolderReal = wp_normalize_path($addedFolderReal); $rootPath = wp_normalize_path($rootPath);
|
| 194 |
+
if(strpos($addedFolder, $rootPath) !== 0) {
|
| 195 |
+
if(strpos($addedFolderReal, $rootPath) !== 0) {
|
| 196 |
+
return( sprintf(__('The %s folder cannot be processed as it\'s not inside the root path of your website (%s).','shortpixel-image-optimiser'),$addedFolder, $rootPath));
|
| 197 |
+
} else {
|
| 198 |
+
$addedFolder = $addedFolderReal; //addedFolder is a symlink inside the root to a folder outside root - addedFolderReal. Use the inside symlink
|
| 199 |
+
}
|
| 200 |
+
}
|
| 201 |
if($this->getFolder($addedFolder)) {
|
| 202 |
return __('Folder already added.','shortpixel-image-optimiser');
|
| 203 |
}
|
|
|
|
|
|
|
|
|
|
| 204 |
$folder = new ShortPixelFolder(array("path" => $addedFolder));
|
| 205 |
try {
|
| 206 |
$folder->setFileCount($folder->countFiles());
|
| 325 |
return $this->db->query("SELECT sm.id from {$this->db->getPrefix()}shortpixel_meta sm "
|
| 326 |
. "INNER JOIN {$this->db->getPrefix()}shortpixel_folders sf on sm.folder_id = sf.id "
|
| 327 |
. "WHERE sf.status <> -1 AND sm.status <> 3 AND ( sm.status = 0 OR sm.status = 1 OR (sm.status < 0 AND sm.retries < 3)) "
|
| 328 |
+
. "ORDER BY sm.id DESC LIMIT $count");
|
| 329 |
}
|
| 330 |
|
| 331 |
public function getFolderOptimizationStatus($folderId) {
|
class/db/shortpixel-meta-facade.php
CHANGED
|
@@ -189,20 +189,32 @@ class ShortPixelMetaFacade {
|
|
| 189 |
$this->rawMeta['ShortPixelImprovement'] = $this->meta->getMessage();
|
| 190 |
unset($this->rawMeta['ShortPixel']['WaitingProcessing']);
|
| 191 |
wp_update_attachment_metadata($this->ID, $this->rawMeta);
|
| 192 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
| 193 |
}
|
| 194 |
|
| 195 |
public function getURLsAndPATHs($processThumbnails, $onlyThumbs = false, $addRetina = true) {
|
| 196 |
if($this->type == self::CUSTOM_TYPE) {
|
| 197 |
$meta = $this->getMeta();
|
| 198 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 199 |
$filePaths[] = $meta->getPath();
|
| 200 |
} else {
|
|
|
|
|
|
|
|
|
|
|
|
|
| 201 |
if ( !parse_url(WP_CONTENT_URL, PHP_URL_SCHEME) ) {//no absolute URLs used -> we implement a hack
|
| 202 |
-
$url = get_site_url() .
|
| 203 |
}
|
| 204 |
else {
|
| 205 |
-
$url =
|
| 206 |
}
|
| 207 |
$urlList[] = $url;
|
| 208 |
$path = get_attached_file($this->ID);//get the full file PATH
|
|
@@ -240,12 +252,15 @@ class ShortPixelMetaFacade {
|
|
| 240 |
}
|
| 241 |
|
| 242 |
//convert the + which are replaced with spaces by wp_remote_post
|
| 243 |
-
array_walk($urlList,
|
| 244 |
-
|
| 245 |
-
});
|
| 246 |
return array("URLs" => $urlList, "PATHs" => $filePaths);
|
| 247 |
}
|
| 248 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 249 |
protected function addRetina($path, $url, &$fileList, &$urlList) {
|
| 250 |
$ext = pathinfo($path, PATHINFO_EXTENSION);
|
| 251 |
$retinaPath = substr($path, 0, strlen($path) - 1 - strlen($ext)) . "@2x." . $ext;
|
|
@@ -289,7 +304,7 @@ class ShortPixelMetaFacade {
|
|
| 289 |
public static function pathToWebPath($path) {
|
| 290 |
//$upl = wp_upload_dir();
|
| 291 |
//return str_replace($upl["basedir"], $upl["baseurl"], $path);
|
| 292 |
-
return
|
| 293 |
}
|
| 294 |
|
| 295 |
public static function pathToRootRelative($path) {
|
|
@@ -297,11 +312,19 @@ class ShortPixelMetaFacade {
|
|
| 297 |
$pathParts = explode('/', $path);
|
| 298 |
unset($pathParts[count($pathParts) - 1]);
|
| 299 |
$path = implode('/', $pathParts);
|
| 300 |
-
return
|
| 301 |
}
|
| 302 |
|
| 303 |
public static function filenameToRootRelative($path) {
|
| 304 |
-
return
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 305 |
}
|
| 306 |
|
| 307 |
public static function getMaxMediaId() {
|
| 189 |
$this->rawMeta['ShortPixelImprovement'] = $this->meta->getMessage();
|
| 190 |
unset($this->rawMeta['ShortPixel']['WaitingProcessing']);
|
| 191 |
wp_update_attachment_metadata($this->ID, $this->rawMeta);
|
| 192 |
+
}
|
| 193 |
+
}
|
| 194 |
+
|
| 195 |
+
public static function getHomeUrl() {
|
| 196 |
+
return trailingslashit((function_exists("is_multisite") && is_multisite()) ? network_site_url("/") : home_url());
|
| 197 |
}
|
| 198 |
|
| 199 |
public function getURLsAndPATHs($processThumbnails, $onlyThumbs = false, $addRetina = true) {
|
| 200 |
if($this->type == self::CUSTOM_TYPE) {
|
| 201 |
$meta = $this->getMeta();
|
| 202 |
+
|
| 203 |
+
//fix for situations where site_url is lala.com/en and home_url is lala.com - if using the site_url will get a duplicated /en in the URL
|
| 204 |
+
$homeUrl = self::getHomeUrl();
|
| 205 |
+
$urlList[] = self::replaceHomePath($meta->getPath(), $homeUrl);
|
| 206 |
+
|
| 207 |
$filePaths[] = $meta->getPath();
|
| 208 |
} else {
|
| 209 |
+
$attURL = wp_get_attachment_url($this->ID);
|
| 210 |
+
if(!$attURL || !strlen($attURL)) {
|
| 211 |
+
throw new Exception("Post metadata is corrupt (No attachment URL)");
|
| 212 |
+
}
|
| 213 |
if ( !parse_url(WP_CONTENT_URL, PHP_URL_SCHEME) ) {//no absolute URLs used -> we implement a hack
|
| 214 |
+
$url = get_site_url() . $attURL;//get the file URL
|
| 215 |
}
|
| 216 |
else {
|
| 217 |
+
$url = $attURL;//get the file URL
|
| 218 |
}
|
| 219 |
$urlList[] = $url;
|
| 220 |
$path = get_attached_file($this->ID);//get the full file PATH
|
| 252 |
}
|
| 253 |
|
| 254 |
//convert the + which are replaced with spaces by wp_remote_post
|
| 255 |
+
array_walk($urlList, array( &$this, 'replacePlusChar') );
|
| 256 |
+
|
|
|
|
| 257 |
return array("URLs" => $urlList, "PATHs" => $filePaths);
|
| 258 |
}
|
| 259 |
|
| 260 |
+
protected function replacePlusChar(&$url) {
|
| 261 |
+
$url = str_replace("+", "%2B", $url);
|
| 262 |
+
}
|
| 263 |
+
|
| 264 |
protected function addRetina($path, $url, &$fileList, &$urlList) {
|
| 265 |
$ext = pathinfo($path, PATHINFO_EXTENSION);
|
| 266 |
$retinaPath = substr($path, 0, strlen($path) - 1 - strlen($ext)) . "@2x." . $ext;
|
| 304 |
public static function pathToWebPath($path) {
|
| 305 |
//$upl = wp_upload_dir();
|
| 306 |
//return str_replace($upl["basedir"], $upl["baseurl"], $path);
|
| 307 |
+
return self::replaceHomePath($path, site_url()."/");
|
| 308 |
}
|
| 309 |
|
| 310 |
public static function pathToRootRelative($path) {
|
| 312 |
$pathParts = explode('/', $path);
|
| 313 |
unset($pathParts[count($pathParts) - 1]);
|
| 314 |
$path = implode('/', $pathParts);
|
| 315 |
+
return self::filenameToRootRelative($path);
|
| 316 |
}
|
| 317 |
|
| 318 |
public static function filenameToRootRelative($path) {
|
| 319 |
+
return self::replaceHomePath($path, "");
|
| 320 |
+
}
|
| 321 |
+
|
| 322 |
+
private static function replaceHomePath($path, $with) {
|
| 323 |
+
if(strpos($path, get_home_path()) === 0) {
|
| 324 |
+
return str_replace(get_home_path(), $with, $path);
|
| 325 |
+
} else { //try also the realpath
|
| 326 |
+
return str_replace(trailingslashit(realpath(get_home_path())), $with, $path);
|
| 327 |
+
}
|
| 328 |
}
|
| 329 |
|
| 330 |
public static function getMaxMediaId() {
|
class/db/wp-shortpixel-db.php
CHANGED
|
@@ -21,8 +21,11 @@ class WpShortPixelDb implements ShortPixelDb {
|
|
| 21 |
public static function checkCustomTables() {
|
| 22 |
global $wpdb;
|
| 23 |
if(function_exists("is_multisite") && is_multisite()) {
|
| 24 |
-
$sites = wp_get_sites();
|
| 25 |
foreach($sites as $site) {
|
|
|
|
|
|
|
|
|
|
| 26 |
$prefix = $wpdb->get_blog_prefix($site['blog_id']);
|
| 27 |
$spMetaDao = new ShortPixelCustomMetaDao(new WpShortPixelDb($prefix));
|
| 28 |
$spMetaDao->createUpdateShortPixelTables();
|
| 21 |
public static function checkCustomTables() {
|
| 22 |
global $wpdb;
|
| 23 |
if(function_exists("is_multisite") && is_multisite()) {
|
| 24 |
+
$sites = function_exists("get_sites") ? get_sites() : wp_get_sites();
|
| 25 |
foreach($sites as $site) {
|
| 26 |
+
if(!is_array($site)) {
|
| 27 |
+
$site = (array)$site;
|
| 28 |
+
}
|
| 29 |
$prefix = $wpdb->get_blog_prefix($site['blog_id']);
|
| 30 |
$spMetaDao = new ShortPixelCustomMetaDao(new WpShortPixelDb($prefix));
|
| 31 |
$spMetaDao->createUpdateShortPixelTables();
|
class/model/shortpixel-folder.php
CHANGED
|
@@ -22,9 +22,9 @@ class ShortPixelFolder extends ShortPixelEntity{
|
|
| 22 |
$folder = '/' . $folder;
|
| 23 |
}
|
| 24 |
if(is_dir($folder)) {
|
| 25 |
-
return
|
| 26 |
} elseif(is_dir($base . $folder)) {
|
| 27 |
-
return
|
| 28 |
}
|
| 29 |
return false;
|
| 30 |
}
|
|
@@ -81,7 +81,7 @@ class ShortPixelFolder extends ShortPixelEntity{
|
|
| 81 |
if(in_array($t, $ignore)) continue;
|
| 82 |
if (is_dir($tpath)) {
|
| 83 |
$size += $this->countFiles($tpath);
|
| 84 |
-
} elseif(
|
| 85 |
$size++;
|
| 86 |
}
|
| 87 |
}
|
|
@@ -111,7 +111,7 @@ class ShortPixelFolder extends ShortPixelEntity{
|
|
| 111 |
$tpath = trailingslashit($path) . $t;
|
| 112 |
if (is_dir($tpath)) {
|
| 113 |
self::getFileListRecursive($tpath, $fileHandle, $onlyNewerThan);
|
| 114 |
-
} elseif($add &&
|
| 115 |
fwrite($fileHandle, $tpath . "\n");
|
| 116 |
}
|
| 117 |
}
|
|
@@ -132,7 +132,7 @@ class ShortPixelFolder extends ShortPixelEntity{
|
|
| 132 |
$tpath = trailingslashit($path) . $t;
|
| 133 |
if (is_dir($tpath)) {
|
| 134 |
self::checkFolderContentsRecursive($tpath, $callback);
|
| 135 |
-
} elseif(
|
| 136 |
&& !(in_array($tpath, $reference) && $reference[$tpath]->compressedSize == filesize($tpath))) {
|
| 137 |
$changed[] = $tpath;
|
| 138 |
}
|
| 22 |
$folder = '/' . $folder;
|
| 23 |
}
|
| 24 |
if(is_dir($folder)) {
|
| 25 |
+
return $folder;
|
| 26 |
} elseif(is_dir($base . $folder)) {
|
| 27 |
+
return $base . $folder;
|
| 28 |
}
|
| 29 |
return false;
|
| 30 |
}
|
| 81 |
if(in_array($t, $ignore)) continue;
|
| 82 |
if (is_dir($tpath)) {
|
| 83 |
$size += $this->countFiles($tpath);
|
| 84 |
+
} elseif(WPShortPixel::isProcessablePath($tpath)) {
|
| 85 |
$size++;
|
| 86 |
}
|
| 87 |
}
|
| 111 |
$tpath = trailingslashit($path) . $t;
|
| 112 |
if (is_dir($tpath)) {
|
| 113 |
self::getFileListRecursive($tpath, $fileHandle, $onlyNewerThan);
|
| 114 |
+
} elseif($add && WPShortPixel::isProcessablePath($tpath)) {
|
| 115 |
fwrite($fileHandle, $tpath . "\n");
|
| 116 |
}
|
| 117 |
}
|
| 132 |
$tpath = trailingslashit($path) . $t;
|
| 133 |
if (is_dir($tpath)) {
|
| 134 |
self::checkFolderContentsRecursive($tpath, $callback);
|
| 135 |
+
} elseif( WPShortPixel::isProcessablePath($tpath)
|
| 136 |
&& !(in_array($tpath, $reference) && $reference[$tpath]->compressedSize == filesize($tpath))) {
|
| 137 |
$changed[] = $tpath;
|
| 138 |
}
|
class/view/shortpixel-list-table.php
CHANGED
|
@@ -47,22 +47,22 @@ class ShortPixelListTable extends WP_List_Table {
|
|
| 47 |
|
| 48 |
$url = ShortPixelMetaFacade::pathToWebPath($item->folder);
|
| 49 |
$actions = array(
|
| 50 |
-
'optimize' => sprintf( '<a href="?page=%s&action=%s&image=%s&_wpnonce=%s">%s</a>',
|
| 51 |
esc_attr( $_REQUEST['page'] ), 'optimize', absint( $item->id ), wp_create_nonce( 'sp_optimize_image' ),
|
| 52 |
__('Optimize','shortpixel-image-optimiser')),
|
| 53 |
-
'retry' => sprintf( '<a href="?page=%s&action=%s&image=%s&_wpnonce=%s">%s</a>',
|
| 54 |
esc_attr( $_REQUEST['page'] ), 'optimize', absint( $item->id ), wp_create_nonce( 'sp_optimize_image' ),
|
| 55 |
__('Retry','shortpixel-image-optimiser')),
|
| 56 |
-
'restore' => sprintf( '<a href="?page=%s&action=%s&image=%s&_wpnonce=%s">%s</a>',
|
| 57 |
esc_attr( $_REQUEST['page'] ), 'restore', absint( $item->id ), wp_create_nonce( 'sp_restore_image' ),
|
| 58 |
__('Restore','shortpixel-image-optimiser')),
|
| 59 |
-
'redolossless' => sprintf( '<a href="?page=%s&action=%s&image=%s&_wpnonce=%s">%s</a>',
|
| 60 |
esc_attr( $_REQUEST['page'] ), 'redo', absint( $item->id ), wp_create_nonce( 'sp_redo_image' ),
|
| 61 |
__('Re-optimize lossless','shortpixel-image-optimiser')),
|
| 62 |
-
'redolossy' => sprintf( '<a href="?page=%s&action=%s&image=%s&_wpnonce=%s">%s</a>',
|
| 63 |
esc_attr( $_REQUEST['page'] ), 'redo', absint( $item->id ), wp_create_nonce( 'sp_redo_image' ),
|
| 64 |
__('Re-optimize lossy','shortpixel-image-optimiser')),
|
| 65 |
-
'quota' => sprintf( '<a href="?page=%s&action=%s&image=%s&_wpnonce=%s">%s</a>',
|
| 66 |
esc_attr( $_REQUEST['page'] ), 'quota', absint( $item->id ), wp_create_nonce( 'sp_check_quota' ),
|
| 67 |
__('Check quota','shortpixel-image-optimiser')),
|
| 68 |
'view' => sprintf( '<a href="%s" target="_blank">%s</a>', $url, __('View','shortpixel-image-optimiser'))
|
|
@@ -192,7 +192,7 @@ class ShortPixelListTable extends WP_List_Table {
|
|
| 192 |
die('Error.');
|
| 193 |
} else {
|
| 194 |
$this->action_optimize_image(absint($_GET['image']));
|
| 195 |
-
wp_redirect(esc_url(
|
| 196 |
exit;
|
| 197 |
}
|
| 198 |
break;
|
|
@@ -201,7 +201,7 @@ class ShortPixelListTable extends WP_List_Table {
|
|
| 201 |
die('Error.');
|
| 202 |
} else {
|
| 203 |
$this->action_restore_image(absint($_GET['image']));
|
| 204 |
-
wp_redirect(esc_url(
|
| 205 |
exit;
|
| 206 |
}
|
| 207 |
break;
|
|
@@ -210,7 +210,7 @@ class ShortPixelListTable extends WP_List_Table {
|
|
| 210 |
die('Error.');
|
| 211 |
} else {
|
| 212 |
$this->action_redo_image(absint($_GET['image']));
|
| 213 |
-
wp_redirect(esc_url(
|
| 214 |
exit;
|
| 215 |
}
|
| 216 |
break;
|
| 47 |
|
| 48 |
$url = ShortPixelMetaFacade::pathToWebPath($item->folder);
|
| 49 |
$actions = array(
|
| 50 |
+
'optimize' => sprintf( '<a href="?page=%s&action=%s&image=%s&_wpnonce=%s&noheader=true">%s</a>',
|
| 51 |
esc_attr( $_REQUEST['page'] ), 'optimize', absint( $item->id ), wp_create_nonce( 'sp_optimize_image' ),
|
| 52 |
__('Optimize','shortpixel-image-optimiser')),
|
| 53 |
+
'retry' => sprintf( '<a href="?page=%s&action=%s&image=%s&_wpnonce=%s&noheader=true">%s</a>',
|
| 54 |
esc_attr( $_REQUEST['page'] ), 'optimize', absint( $item->id ), wp_create_nonce( 'sp_optimize_image' ),
|
| 55 |
__('Retry','shortpixel-image-optimiser')),
|
| 56 |
+
'restore' => sprintf( '<a href="?page=%s&action=%s&image=%s&_wpnonce=%s&noheader=true">%s</a>',
|
| 57 |
esc_attr( $_REQUEST['page'] ), 'restore', absint( $item->id ), wp_create_nonce( 'sp_restore_image' ),
|
| 58 |
__('Restore','shortpixel-image-optimiser')),
|
| 59 |
+
'redolossless' => sprintf( '<a href="?page=%s&action=%s&image=%s&_wpnonce=%s&noheader=true">%s</a>',
|
| 60 |
esc_attr( $_REQUEST['page'] ), 'redo', absint( $item->id ), wp_create_nonce( 'sp_redo_image' ),
|
| 61 |
__('Re-optimize lossless','shortpixel-image-optimiser')),
|
| 62 |
+
'redolossy' => sprintf( '<a href="?page=%s&action=%s&image=%s&_wpnonce=%s&noheader=true">%s</a>',
|
| 63 |
esc_attr( $_REQUEST['page'] ), 'redo', absint( $item->id ), wp_create_nonce( 'sp_redo_image' ),
|
| 64 |
__('Re-optimize lossy','shortpixel-image-optimiser')),
|
| 65 |
+
'quota' => sprintf( '<a href="?page=%s&action=%s&image=%s&_wpnonce=%s&noheader=true">%s</a>',
|
| 66 |
esc_attr( $_REQUEST['page'] ), 'quota', absint( $item->id ), wp_create_nonce( 'sp_check_quota' ),
|
| 67 |
__('Check quota','shortpixel-image-optimiser')),
|
| 68 |
'view' => sprintf( '<a href="%s" target="_blank">%s</a>', $url, __('View','shortpixel-image-optimiser'))
|
| 192 |
die('Error.');
|
| 193 |
} else {
|
| 194 |
$this->action_optimize_image(absint($_GET['image']));
|
| 195 |
+
wp_redirect(esc_url(remove_query_arg(array('action', 'image', '_wpnonce'))));
|
| 196 |
exit;
|
| 197 |
}
|
| 198 |
break;
|
| 201 |
die('Error.');
|
| 202 |
} else {
|
| 203 |
$this->action_restore_image(absint($_GET['image']));
|
| 204 |
+
wp_redirect(esc_url(remove_query_arg(array('action', 'image', '_wpnonce'))));
|
| 205 |
exit;
|
| 206 |
}
|
| 207 |
break;
|
| 210 |
die('Error.');
|
| 211 |
} else {
|
| 212 |
$this->action_redo_image(absint($_GET['image']));
|
| 213 |
+
wp_redirect(esc_url(remove_query_arg(array('action', 'image', '_wpnonce'))));
|
| 214 |
exit;
|
| 215 |
}
|
| 216 |
break;
|
class/view/shortpixel_view.php
CHANGED
|
@@ -121,7 +121,7 @@ class ShortPixelView {
|
|
| 121 |
<div class="bulk-val"><?php echo(number_format($quotaData['totalProcessedMlFiles'] - $quotaData['mainProcessedMlFiles']));?></div><br>
|
| 122 |
<?php } ?>
|
| 123 |
<div class="bulk-label bulk-total"><?php _e('Total to be optimized','shortpixel-image-optimiser');?></div>
|
| 124 |
-
<div class="bulk-val bulk-total" id='displayTotal'><?php echo(number_format($quotaData['totalMlFiles'] - $quotaData['totalProcessedMlFiles']));?></div>
|
| 125 |
|
| 126 |
<?php if($customCount > 0) { ?>
|
| 127 |
<h3 style='margin-bottom:10px;'><?php _e('Your custom folders','shortpixel-image-optimiser');?></h3>
|
|
@@ -129,7 +129,7 @@ class ShortPixelView {
|
|
| 129 |
<div class="bulk-val bulk-total" id='displayTotal'><?php echo(number_format($customCount));?></div>
|
| 130 |
<?php } ?>
|
| 131 |
</div>
|
| 132 |
-
<?php if($quotaData['
|
| 133 |
<div class="bulk-play">
|
| 134 |
<input type='hidden' name='bulkProcess' id='bulkProcess' value='Start Optimizing'/>
|
| 135 |
<a href='javascript:void(0);' onclick="document.getElementById('startBulk').submit();" class='button'>
|
|
@@ -140,8 +140,8 @@ class ShortPixelView {
|
|
| 140 |
<div class="bulk-btn-txt">
|
| 141 |
<?php printf(__('<span class="label">Start Optimizing</span><br> <span class="total">%s</span> images','shortpixel-image-optimiser'),
|
| 142 |
$this->ctrl->processThumbnails() ?
|
| 143 |
-
number_format($quotaData['
|
| 144 |
-
number_format($quotaData['
|
| 145 |
</div>
|
| 146 |
<div class="bulk-btn-img" class="bulk-btn-img">
|
| 147 |
<img src='<?php echo(plugins_url( 'shortpixel-image-optimiser/res/img/arrow.png' ));?>'/>
|
|
@@ -306,7 +306,7 @@ class ShortPixelView {
|
|
| 306 |
_e('Some have errors:','shortpixel-image-optimiser'); echo(' ');
|
| 307 |
foreach($quotaData['filesWithErrors'] as $id => $data) {
|
| 308 |
if(ShortPixelMetaFacade::isCustomQueuedId($id)) {
|
| 309 |
-
echo('<a href="'.
|
| 310 |
} else {
|
| 311 |
echo('<a href="post.php?post='.$id.'&action=edit" title="'.$data['Message'].'">'.$data['Name'].'</a>, ');
|
| 312 |
}
|
|
@@ -366,6 +366,18 @@ class ShortPixelView {
|
|
| 366 |
<div class="wrap short-pixel-bulk-page">
|
| 367 |
<h1><?php _e('Bulk Image Optimization by ShortPixel','shortpixel-image-optimiser');?></h1>
|
| 368 |
<?php $this->displayBulkProgressBar(true, $percent, $message, $remainingQuota, $averageCompression, $type);?>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 369 |
<div class="sp-floating-block notice bulk-notices-parent">
|
| 370 |
<div class="bulk-notice-container">
|
| 371 |
<div class="bulk-notice-msg bulk-lengthy">
|
|
@@ -496,7 +508,7 @@ class ShortPixelView {
|
|
| 496 |
<?php foreach($failed as $fail) {
|
| 497 |
if($fail->type == ShortPixelMetaFacade::CUSTOM_TYPE) {
|
| 498 |
$meta = $fail->meta;
|
| 499 |
-
?> <div class="label"><a href="<?php echo(
|
| 500 |
<?php } else {
|
| 501 |
$meta = wp_get_attachment_metadata($fail);
|
| 502 |
?> <div class="label"><a href="/wp-admin/post.php?post=<?php echo($fail->id);?>&action=edit"><?php echo(substr($fail->meta["file"], 0, 80));?> - ID: <?php echo($fail->id);?></a></div><br/>
|
|
@@ -516,7 +528,7 @@ class ShortPixelView {
|
|
| 516 |
<a href="https://shortpixel.com/<?php echo($this->ctrl->getVerifiedKey() ? "login/".$this->ctrl->getApiKey() : "pricing");?>" target="_blank" style="font-size:18px">
|
| 517 |
<?php _e('Upgrade now','shortpixel-image-optimiser');?>
|
| 518 |
</a> |
|
| 519 |
-
<a href="https://shortpixel.com/contact/<?php echo($this->ctrl->getEncryptedData());?>" target="_blank" style="font-size:18px"><?php _e('Support','shortpixel-image-optimiser');?> </a>
|
| 520 |
</p>
|
| 521 |
<?php if($notice !== null) { ?>
|
| 522 |
<br/>
|
|
@@ -815,7 +827,7 @@ class ShortPixelView {
|
|
| 815 |
<input type="hidden" name="recheckFolder" id="removeFolder"/>
|
| 816 |
<input type="text" name="addCustomFolderView" id="addCustomFolderView" class="regular-text" value="<?php echo($addedFolder);?>" disabled style="width: 50em;max-width: 70%;">
|
| 817 |
<input type="hidden" name="addCustomFolder" id="addCustomFolder" value="<?php echo($addedFolder);?>"/>
|
| 818 |
-
<input type="hidden" id="customFolderBase" value="<?php echo
|
| 819 |
<a class="button button-primary select-folder-button" title="<?php _e('Select the images folder on your server.','shortpixel-image-optimiser');?>" href="javascript:void(0);">
|
| 820 |
<?php _e('Select ...','shortpixel-image-optimiser');?>
|
| 821 |
</a>
|
| 121 |
<div class="bulk-val"><?php echo(number_format($quotaData['totalProcessedMlFiles'] - $quotaData['mainProcessedMlFiles']));?></div><br>
|
| 122 |
<?php } ?>
|
| 123 |
<div class="bulk-label bulk-total"><?php _e('Total to be optimized','shortpixel-image-optimiser');?></div>
|
| 124 |
+
<div class="bulk-val bulk-total" id='displayTotal'><?php echo(number_format(max( 0, $quotaData['totalMlFiles'] - $quotaData['totalProcessedMlFiles'])));?></div>
|
| 125 |
|
| 126 |
<?php if($customCount > 0) { ?>
|
| 127 |
<h3 style='margin-bottom:10px;'><?php _e('Your custom folders','shortpixel-image-optimiser');?></h3>
|
| 129 |
<div class="bulk-val bulk-total" id='displayTotal'><?php echo(number_format($customCount));?></div>
|
| 130 |
<?php } ?>
|
| 131 |
</div>
|
| 132 |
+
<?php if(max(0, $quotaData['totalMlFiles'] - $quotaData['totalProcessedMlFiles']) + $customCount > 0) { ?>
|
| 133 |
<div class="bulk-play">
|
| 134 |
<input type='hidden' name='bulkProcess' id='bulkProcess' value='Start Optimizing'/>
|
| 135 |
<a href='javascript:void(0);' onclick="document.getElementById('startBulk').submit();" class='button'>
|
| 140 |
<div class="bulk-btn-txt">
|
| 141 |
<?php printf(__('<span class="label">Start Optimizing</span><br> <span class="total">%s</span> images','shortpixel-image-optimiser'),
|
| 142 |
$this->ctrl->processThumbnails() ?
|
| 143 |
+
number_format(max(0, $quotaData['totalMlFiles'] - $quotaData['totalProcessedMlFiles']) + $customCount) :
|
| 144 |
+
number_format(max(0, $quotaData['mainMlFiles'] - $quotaData['mainProcessedMlFiles']) + $customCount));?>
|
| 145 |
</div>
|
| 146 |
<div class="bulk-btn-img" class="bulk-btn-img">
|
| 147 |
<img src='<?php echo(plugins_url( 'shortpixel-image-optimiser/res/img/arrow.png' ));?>'/>
|
| 306 |
_e('Some have errors:','shortpixel-image-optimiser'); echo(' ');
|
| 307 |
foreach($quotaData['filesWithErrors'] as $id => $data) {
|
| 308 |
if(ShortPixelMetaFacade::isCustomQueuedId($id)) {
|
| 309 |
+
echo('<a href="'. ShortPixelMetaFacade::getHomeUrl() . ShortPixelMetaFacade::filenameToRootRelative($data['Path']).'" title="'.$data['Message'].'" target="_blank">'.$data['Name'].'</a>, ');
|
| 310 |
} else {
|
| 311 |
echo('<a href="post.php?post='.$id.'&action=edit" title="'.$data['Message'].'">'.$data['Name'].'</a>, ');
|
| 312 |
}
|
| 366 |
<div class="wrap short-pixel-bulk-page">
|
| 367 |
<h1><?php _e('Bulk Image Optimization by ShortPixel','shortpixel-image-optimiser');?></h1>
|
| 368 |
<?php $this->displayBulkProgressBar(true, $percent, $message, $remainingQuota, $averageCompression, $type);?>
|
| 369 |
+
|
| 370 |
+
<!-- Partners: SQUIRLY -->
|
| 371 |
+
<?php if(false) { ?>
|
| 372 |
+
<div class="sp-notice sp-notice-info bulk-progress bulk-progress-partners sp-floating-block sp-full-width">
|
| 373 |
+
<div style="float:right"><a href=""><?php _e('Dismiss','shortpixel-image-optimiser');?></a></div>
|
| 374 |
+
<a href="https://my.squirrly.co/go120073/squirrly.co/short-pixel-seo" target="_blank">
|
| 375 |
+
<img src="<?php echo(plugins_url( 'shortpixel-image-optimiser/res/img/squirrly.png' ));?>" height="50">
|
| 376 |
+
<div><?php _e('While you wait for your images to optimize, check out Squirrly, a great plugin for further boosting your SEO.','shortpixel-image-optimiser');?></div>
|
| 377 |
+
</a>
|
| 378 |
+
</div>
|
| 379 |
+
<?php } ?>
|
| 380 |
+
|
| 381 |
<div class="sp-floating-block notice bulk-notices-parent">
|
| 382 |
<div class="bulk-notice-container">
|
| 383 |
<div class="bulk-notice-msg bulk-lengthy">
|
| 508 |
<?php foreach($failed as $fail) {
|
| 509 |
if($fail->type == ShortPixelMetaFacade::CUSTOM_TYPE) {
|
| 510 |
$meta = $fail->meta;
|
| 511 |
+
?> <div class="label"><a href="<?php echo(ShortPixelMetaFacade::getHomeUrl() . $fail->meta->getWebPath());?>"><?php echo(substr($fail->meta->getName(), 0, 80));?> - ID: C-<?php echo($fail->id);?></a></div><br/>
|
| 512 |
<?php } else {
|
| 513 |
$meta = wp_get_attachment_metadata($fail);
|
| 514 |
?> <div class="label"><a href="/wp-admin/post.php?post=<?php echo($fail->id);?>&action=edit"><?php echo(substr($fail->meta["file"], 0, 80));?> - ID: <?php echo($fail->id);?></a></div><br/>
|
| 528 |
<a href="https://shortpixel.com/<?php echo($this->ctrl->getVerifiedKey() ? "login/".$this->ctrl->getApiKey() : "pricing");?>" target="_blank" style="font-size:18px">
|
| 529 |
<?php _e('Upgrade now','shortpixel-image-optimiser');?>
|
| 530 |
</a> |
|
| 531 |
+
<a href="https://shortpixel.com/contact/<?php //echo($this->ctrl->getEncryptedData());?>" target="_blank" style="font-size:18px"><?php _e('Support','shortpixel-image-optimiser');?> </a>
|
| 532 |
</p>
|
| 533 |
<?php if($notice !== null) { ?>
|
| 534 |
<br/>
|
| 827 |
<input type="hidden" name="recheckFolder" id="removeFolder"/>
|
| 828 |
<input type="text" name="addCustomFolderView" id="addCustomFolderView" class="regular-text" value="<?php echo($addedFolder);?>" disabled style="width: 50em;max-width: 70%;">
|
| 829 |
<input type="hidden" name="addCustomFolder" id="addCustomFolder" value="<?php echo($addedFolder);?>"/>
|
| 830 |
+
<input type="hidden" id="customFolderBase" value="<?php echo WPShortPixel::getCustomFolderBase(); ?>">
|
| 831 |
<a class="button button-primary select-folder-button" title="<?php _e('Select the images folder on your server.','shortpixel-image-optimiser');?>" href="javascript:void(0);">
|
| 832 |
<?php _e('Select ...','shortpixel-image-optimiser');?>
|
| 833 |
</a>
|
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.7
|
| 8 |
-
Stable tag: 4.2.
|
| 9 |
License: GPLv2 or later
|
| 10 |
License URI: http://www.gnu.org/licenses/gpl-2.0.html
|
| 11 |
|
|
@@ -13,7 +13,7 @@ Speed up your website and boost your SEO by compressing old & new images and PDF
|
|
| 13 |
|
| 14 |
== Description ==
|
| 15 |
|
| 16 |
-
**
|
| 17 |
|
| 18 |
Increase your website's SEO ranking, number of visitors and ultimately your sales by optimizing any image or PDF document on your website.
|
| 19 |
ShortPixel is an easy to use, lightweight, install-and-forget-about-it <a rel="friend" href="https://shortpixel.com" target="_blank">image optimization</a> plugin that can compress all your past images and PDF documents with a single click. New images are automatically resized/rescaled and optimized on the fly, in the background.
|
|
@@ -192,6 +192,19 @@ The ShortPixel team is here to help. <a href="https://shortpixel.com/contact">Co
|
|
| 192 |
|
| 193 |
== Changelog ==
|
| 194 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 195 |
= 4.2.2 =
|
| 196 |
|
| 197 |
* offer to generate the API key directly from ShortPixel settings.
|
| 5 |
|
| 6 |
Requires at least: 3.2.0
|
| 7 |
Tested up to: 4.7
|
| 8 |
+
Stable tag: 4.2.4
|
| 9 |
License: GPLv2 or later
|
| 10 |
License URI: http://www.gnu.org/licenses/gpl-2.0.html
|
| 11 |
|
| 13 |
|
| 14 |
== Description ==
|
| 15 |
|
| 16 |
+
**A freeemium easy to use, comprehensive, stable and frequently updated image optimization plugin supported by the friendly team that created it. :)**
|
| 17 |
|
| 18 |
Increase your website's SEO ranking, number of visitors and ultimately your sales by optimizing any image or PDF document on your website.
|
| 19 |
ShortPixel is an easy to use, lightweight, install-and-forget-about-it <a rel="friend" href="https://shortpixel.com" target="_blank">image optimization</a> plugin that can compress all your past images and PDF documents with a single click. New images are automatically resized/rescaled and optimized on the fly, in the background.
|
| 192 |
|
| 193 |
== Changelog ==
|
| 194 |
|
| 195 |
+
= 4.2.4 =
|
| 196 |
+
|
| 197 |
+
* fix not processing the images in the custom image folders if they had uppercase extensions
|
| 198 |
+
* remove the deprecated mcrypt calls.
|
| 199 |
+
* fix jQuery 3.x incompatibility when calling .unload() by using on("beforeunload" .. ) instead
|
| 200 |
+
|
| 201 |
+
= 4.2.3 =
|
| 202 |
+
|
| 203 |
+
* fix compatibility with older PHP by not using closure
|
| 204 |
+
* fix order of optimization of other media - by id not by added timestamp
|
| 205 |
+
* fix js error for manual optimization from js-generated button
|
| 206 |
+
* change call to obsolete get_currentuserinfo method
|
| 207 |
+
|
| 208 |
= 4.2.2 =
|
| 209 |
|
| 210 |
* offer to generate the API key directly from ShortPixel settings.
|
res/css/short-pixel.css
CHANGED
|
@@ -48,6 +48,16 @@ div.bulk-progress div.sp-h2 {
|
|
| 48 |
padding: 9px 15px 4px 0;
|
| 49 |
line-height: 29px;
|
| 50 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 51 |
div.bulk-progress .bulk-progress-indicator,
|
| 52 |
div.sp-quota-exceeded-alert .bulk-progress-indicator {
|
| 53 |
display: inline-block;
|
| 48 |
padding: 9px 15px 4px 0;
|
| 49 |
line-height: 29px;
|
| 50 |
}
|
| 51 |
+
div.bulk-progress-partners {
|
| 52 |
+
margin-top: 20px;
|
| 53 |
+
}
|
| 54 |
+
div.bulk-progress.bulk-progress-partners a div {
|
| 55 |
+
display: inline-block;
|
| 56 |
+
vertical-align: top;
|
| 57 |
+
line-height: 50px;
|
| 58 |
+
margin-left: 30px;
|
| 59 |
+
font-size: 1.2em;
|
| 60 |
+
}
|
| 61 |
div.bulk-progress .bulk-progress-indicator,
|
| 62 |
div.sp-quota-exceeded-alert .bulk-progress-indicator {
|
| 63 |
display: inline-block;
|
res/js/short-pixel.js
CHANGED
|
@@ -19,7 +19,7 @@ jQuery(document).ready(function($){
|
|
| 19 |
+ '</p></div>');
|
| 20 |
}
|
| 21 |
//
|
| 22 |
-
jQuery(window).
|
| 23 |
if(ShortPixel.bulkProcessor == true) {
|
| 24 |
clearBulkProcessor();
|
| 25 |
}
|
|
@@ -486,7 +486,7 @@ function checkBulkProcessingCallApi(){
|
|
| 486 |
ShortPixel.otherMediaUpdateActions(id, ['quota','view']);
|
| 487 |
break;
|
| 488 |
case ShortPixel.STATUS_FAIL:
|
| 489 |
-
setCellMessage(id, data["Message"], "<a class='button button-smaller button-primary' href=\"javascript:manualOptimization('
|
| 490 |
+ _spTr.retry + "</a>");
|
| 491 |
if(isBulkPage) {
|
| 492 |
ShortPixel.bulkShowError(id, data["Message"], data["Filename"], data["CustomImageLink"]);
|
| 19 |
+ '</p></div>');
|
| 20 |
}
|
| 21 |
//
|
| 22 |
+
jQuery(window).on('beforeunload', function(){
|
| 23 |
if(ShortPixel.bulkProcessor == true) {
|
| 24 |
clearBulkProcessor();
|
| 25 |
}
|
| 486 |
ShortPixel.otherMediaUpdateActions(id, ['quota','view']);
|
| 487 |
break;
|
| 488 |
case ShortPixel.STATUS_FAIL:
|
| 489 |
+
setCellMessage(id, data["Message"], "<a class='button button-smaller button-primary' href=\"javascript:manualOptimization('" + id + "', false)\">"
|
| 490 |
+ _spTr.retry + "</a>");
|
| 491 |
if(isBulkPage) {
|
| 492 |
ShortPixel.bulkShowError(id, data["Message"], data["Filename"], data["CustomImageLink"]);
|
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 > ShortPixel</a> page on how to start optimizing your image library and make your website load faster.
|
| 6 |
-
* Version: 4.2.
|
| 7 |
* Author: ShortPixel
|
| 8 |
* Author URI: https://shortpixel.com
|
| 9 |
* Text Domain: shortpixel-image-optimiser
|
|
@@ -14,7 +14,7 @@ define('SP_RESET_ON_ACTIVATE', false); //if true TODO set false
|
|
| 14 |
|
| 15 |
define('SP_AFFILIATE_CODE', '');
|
| 16 |
|
| 17 |
-
define('PLUGIN_VERSION', "4.2.
|
| 18 |
define('SP_MAX_TIMEOUT', 10);
|
| 19 |
define('SP_VALIDATE_MAX_TIMEOUT', 15);
|
| 20 |
define('SP_BACKUP', 'ShortpixelBackups');
|
|
@@ -233,13 +233,12 @@ class WPShortPixel {
|
|
| 233 |
if($this->_settings->mediaLibraryViewMode === false)
|
| 234 |
{
|
| 235 |
$this->_settings->mediaLibraryViewMode = 1;
|
| 236 |
-
|
| 237 |
-
|
| 238 |
-
|
| 239 |
-
|
| 240 |
-
|
| 241 |
-
|
| 242 |
-
}
|
| 243 |
}
|
| 244 |
|
| 245 |
}
|
|
@@ -269,7 +268,7 @@ class WPShortPixel {
|
|
| 269 |
WP_ADMIN_URL: '<?php echo admin_url(); ?>',
|
| 270 |
API_KEY: "<?php echo $this->_settings->apiKey; ?>",
|
| 271 |
MEDIA_ALERT: '<?php echo $this->_settings->mediaAlert ? "done" : "todo"; ?>',
|
| 272 |
-
FRONT_BOOTSTRAP: <?php echo $this->_settings->frontBootstrap && (time() - $this->_settings->lastBackAction > 600) ? 1 : 0; ?>,
|
| 273 |
AJAX_URL: '<?php echo admin_url('admin-ajax.php'); ?>'
|
| 274 |
};
|
| 275 |
</script> <?php
|
|
@@ -396,7 +395,12 @@ class WPShortPixel {
|
|
| 396 |
&& !is_plugin_active('easy-watermark/index.php')) {
|
| 397 |
$itemHandler = new ShortPixelMetaFacade($ID);
|
| 398 |
$itemHandler->setRawMeta($meta);
|
| 399 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 400 |
//send a processing request right after a file was uploaded, do NOT wait for response
|
| 401 |
$this->_apiInterface->doRequests($URLsAndPATHs['URLs'], false, $ID);
|
| 402 |
//self::log("IMG: sent: " . json_encode($URLsAndPATHs));
|
|
@@ -619,6 +623,26 @@ class WPShortPixel {
|
|
| 619 |
// var_dump($ids);
|
| 620 |
// die("za stop 2");
|
| 621 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 622 |
if ($ids === false || count( $ids ) == 0 ){
|
| 623 |
//if searching, than the script is searching for not processed items and found none yet, should be relaunced
|
| 624 |
if(isset($res['searching']) && $res['searching']) {
|
|
@@ -639,20 +663,6 @@ class WPShortPixel {
|
|
| 639 |
die(json_encode($response));
|
| 640 |
}
|
| 641 |
|
| 642 |
-
self::log("HIP: 1 Prio Queue: ".json_encode($this->prioQ->get()));
|
| 643 |
-
self::log("HIP: 1 Selected IDs count: ".count($ids));
|
| 644 |
-
|
| 645 |
-
//2: Send up to 3 files to the server for processing
|
| 646 |
-
for($i = 0; $i < min(3, count($ids)); $i++) {
|
| 647 |
-
$itemHandler = $ids[$i];
|
| 648 |
-
$tmpMeta = $itemHandler->getMeta();
|
| 649 |
-
$compType = ($tmpMeta->getCompressionType() !== null ? $tmpMeta->getCompressionType() : $this->_settings->compressionType);
|
| 650 |
-
$URLsAndPATHs = $this->sendToProcessing($itemHandler, $compType, $tmpMeta->getThumbsTodo());
|
| 651 |
-
if($i == 0) { //save for later use
|
| 652 |
-
$firstUrlAndPaths = $URLsAndPATHs;
|
| 653 |
-
}
|
| 654 |
-
}
|
| 655 |
-
|
| 656 |
self::log("HIP: 2 Prio Queue: ".json_encode($this->prioQ->get()));
|
| 657 |
//3: Retrieve the file for the first element of the list
|
| 658 |
$itemHandler = $ids[0];
|
|
@@ -731,7 +741,7 @@ class WPShortPixel {
|
|
| 731 |
}
|
| 732 |
elseif( is_array($customIds)) { // this item is from custom bulk
|
| 733 |
foreach($customIds as $customId) {
|
| 734 |
-
$rootUrl =
|
| 735 |
if($customId->id == $itemHandler->getId()) {
|
| 736 |
if('pdf' == strtolower(pathinfo($meta->getName(), PATHINFO_EXTENSION))) {
|
| 737 |
$result["Thumb"] = plugins_url( 'shortpixel-image-optimiser/res/img/logo-pdf.png' );
|
|
@@ -777,7 +787,7 @@ class WPShortPixel {
|
|
| 777 |
}
|
| 778 |
$this->advanceBulk($meta->getId(), $result);
|
| 779 |
if($itemHandler->getType() == ShortPixelMetaFacade::CUSTOM_TYPE) {
|
| 780 |
-
$result["CustomImageLink"] =
|
| 781 |
}
|
| 782 |
}
|
| 783 |
elseif ($this->prioQ->isPrio($itemId) && $result["Status"] == ShortPixelAPI::STATUS_QUOTA_EXCEEDED) {
|
|
@@ -793,7 +803,7 @@ class WPShortPixel {
|
|
| 793 |
self::log("HIP: 5 Prio Skipped: ".json_encode($this->prioQ->getSkipped()));
|
| 794 |
}
|
| 795 |
elseif($result["Status"] == ShortPixelAPI::STATUS_RETRY && is_array($customIds)) {
|
| 796 |
-
$result["CustomImageLink"] = $thumb =
|
| 797 |
}
|
| 798 |
|
| 799 |
if($result["Status"] !== ShortPixelAPI::STATUS_RETRY) {
|
|
@@ -872,10 +882,17 @@ class WPShortPixel {
|
|
| 872 |
public function optimizeNowHook($imageId) {
|
| 873 |
if(self::isProcessable($imageId)) {
|
| 874 |
$this->prioQ->push($imageId);
|
| 875 |
-
$
|
| 876 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 877 |
} else {
|
| 878 |
-
$ret = array("Status" => ShortPixelAPI::STATUS_SKIP, "
|
| 879 |
}
|
| 880 |
die(json_encode($ret));
|
| 881 |
}
|
|
@@ -1168,6 +1185,11 @@ class WPShortPixel {
|
|
| 1168 |
$this->prioQ->push(ShortPixelMetaFacade::queuedId(ShortPixelMetaFacade::CUSTOM_TYPE, $_REQUEST['image']));
|
| 1169 |
}
|
| 1170 |
$customMediaListTable = new ShortPixelListTable($this, $this->spMetaDao, $this->hasNextGen);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1171 |
?>
|
| 1172 |
<div class="wrap shortpixel-other-media">
|
| 1173 |
<h2>
|
|
@@ -1185,7 +1207,6 @@ class WPShortPixel {
|
|
| 1185 |
<div class="meta-box-sortables ui-sortable">
|
| 1186 |
<form method="post" class="shortpixel-table">
|
| 1187 |
<?php
|
| 1188 |
-
$items = $customMediaListTable->prepare_items();
|
| 1189 |
$customMediaListTable->display();
|
| 1190 |
//push to the processing list the pending ones, just in case
|
| 1191 |
$count = $this->spMetaDao->getCustomMetaCount();
|
|
@@ -1358,7 +1379,7 @@ class WPShortPixel {
|
|
| 1358 |
wp_die(__('You do not have sufficient permissions to access this page.','shortpixel-image-optimiser'));
|
| 1359 |
}
|
| 1360 |
|
| 1361 |
-
$root =
|
| 1362 |
|
| 1363 |
$postDir = rawurldecode($root.(isset($_POST['dir']) ? $_POST['dir'] : null ));
|
| 1364 |
|
|
@@ -1398,7 +1419,7 @@ class WPShortPixel {
|
|
| 1398 |
die();
|
| 1399 |
}
|
| 1400 |
|
| 1401 |
-
public function getCustomFolderBase() {
|
| 1402 |
if(is_main_site()) {
|
| 1403 |
$base = get_home_path();
|
| 1404 |
return realpath(rtrim($base, '/'));
|
|
@@ -1577,7 +1598,7 @@ class WPShortPixel {
|
|
| 1577 |
$this->_settings->includeNextGen = 0;
|
| 1578 |
}
|
| 1579 |
if(isset($_POST['addCustomFolder']) && strlen($_POST['addCustomFolder']) > 0) {
|
| 1580 |
-
$folderMsg = $this->spMetaDao->newFolderFromPath(stripslashes($_POST['addCustomFolder']), $uploadPath,
|
| 1581 |
if(!$folderMsg) {
|
| 1582 |
$notice = array("status" => "success", "msg" => __('Folder added successfully.','shortpixel-image-optimiser'));
|
| 1583 |
}
|
|
@@ -1666,7 +1687,7 @@ class WPShortPixel {
|
|
| 1666 |
//add the NextGen galleries to custom folders
|
| 1667 |
$ngGalleries = ShortPixelNextGenAdapter::getGalleries();
|
| 1668 |
foreach($ngGalleries as $gallery) {
|
| 1669 |
-
$folderMsg = $this->spMetaDao->newFolderFromPath($gallery, get_home_path(),
|
| 1670 |
$this->_settings->hasCustomFolders = true;
|
| 1671 |
}
|
| 1672 |
$customFolders = $this->spMetaDao->getFolders();
|
|
@@ -2151,13 +2172,15 @@ class WPShortPixel {
|
|
| 2151 |
return array('width' => $width, 'height' => $height);
|
| 2152 |
}
|
| 2153 |
|
| 2154 |
-
public function getEncryptedData() {
|
| 2155 |
return base64_encode(self::encrypt($this->getApiKey() . "|" . get_site_url(), "sh0r+Pix3l8im1N3r"));
|
| 2156 |
}
|
|
|
|
|
|
|
| 2157 |
/**
|
| 2158 |
* Returns an encrypted & utf8-encoded
|
| 2159 |
*/
|
| 2160 |
-
public static function encrypt($pure_string, $encryption_key)
|
| 2161 |
{
|
| 2162 |
if(!function_exists("mcrypt_get_iv_size") || !function_exists('utf8_encode')) {
|
| 2163 |
return "";
|
|
@@ -2167,7 +2190,7 @@ class WPShortPixel {
|
|
| 2167 |
$encrypted_string = \mcrypt_encrypt(MCRYPT_BLOWFISH, $encryption_key, utf8_encode($pure_string), MCRYPT_MODE_ECB, $iv);
|
| 2168 |
return $encrypted_string;
|
| 2169 |
}
|
| 2170 |
-
|
| 2171 |
|
| 2172 |
public function getApiKey() {
|
| 2173 |
return $this->_settings->apiKey;
|
| 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 > ShortPixel</a> page on how to start optimizing your image library and make your website load faster.
|
| 6 |
+
* Version: 4.2.4
|
| 7 |
* Author: ShortPixel
|
| 8 |
* Author URI: https://shortpixel.com
|
| 9 |
* Text Domain: shortpixel-image-optimiser
|
| 14 |
|
| 15 |
define('SP_AFFILIATE_CODE', '');
|
| 16 |
|
| 17 |
+
define('PLUGIN_VERSION', "4.2.4");
|
| 18 |
define('SP_MAX_TIMEOUT', 10);
|
| 19 |
define('SP_VALIDATE_MAX_TIMEOUT', 15);
|
| 20 |
define('SP_BACKUP', 'ShortpixelBackups');
|
| 233 |
if($this->_settings->mediaLibraryViewMode === false)
|
| 234 |
{
|
| 235 |
$this->_settings->mediaLibraryViewMode = 1;
|
| 236 |
+
$currentUserID = false;
|
| 237 |
+
if ( function_exists('wp_get_current_user') ) {
|
| 238 |
+
$current_user = wp_get_current_user();
|
| 239 |
+
$currentUserID = $current_user->ID;
|
| 240 |
+
update_user_meta($currentUserID, "wp_media_library_mode", "list");
|
| 241 |
+
}
|
|
|
|
| 242 |
}
|
| 243 |
|
| 244 |
}
|
| 268 |
WP_ADMIN_URL: '<?php echo admin_url(); ?>',
|
| 269 |
API_KEY: "<?php echo $this->_settings->apiKey; ?>",
|
| 270 |
MEDIA_ALERT: '<?php echo $this->_settings->mediaAlert ? "done" : "todo"; ?>',
|
| 271 |
+
FRONT_BOOTSTRAP: <?php echo $this->_settings->frontBootstrap && (!isset($this->_settings->lastBackAction) || (time() - $this->_settings->lastBackAction > 600)) ? 1 : 0; ?>,
|
| 272 |
AJAX_URL: '<?php echo admin_url('admin-ajax.php'); ?>'
|
| 273 |
};
|
| 274 |
</script> <?php
|
| 395 |
&& !is_plugin_active('easy-watermark/index.php')) {
|
| 396 |
$itemHandler = new ShortPixelMetaFacade($ID);
|
| 397 |
$itemHandler->setRawMeta($meta);
|
| 398 |
+
try {
|
| 399 |
+
$URLsAndPATHs = $this->getURLsAndPATHs($itemHandler);
|
| 400 |
+
} catch(Exception $e) {
|
| 401 |
+
$meta['ShortPixelImprovement'] = $e->getMessage();
|
| 402 |
+
return $meta;
|
| 403 |
+
}
|
| 404 |
//send a processing request right after a file was uploaded, do NOT wait for response
|
| 405 |
$this->_apiInterface->doRequests($URLsAndPATHs['URLs'], false, $ID);
|
| 406 |
//self::log("IMG: sent: " . json_encode($URLsAndPATHs));
|
| 623 |
// var_dump($ids);
|
| 624 |
// die("za stop 2");
|
| 625 |
|
| 626 |
+
self::log("HIP: 1 Prio Queue: ".json_encode($this->prioQ->get()));
|
| 627 |
+
self::log("HIP: 1 Selected IDs count: ".count($ids));
|
| 628 |
+
|
| 629 |
+
//2: Send up to 3 files to the server for processing
|
| 630 |
+
for($i = 0, $first = true; $ids !== false && $i < min(3, count($ids)); $i++) {
|
| 631 |
+
$itemHandler = $ids[$i];
|
| 632 |
+
$tmpMeta = $itemHandler->getMeta();
|
| 633 |
+
$compType = ($tmpMeta->getCompressionType() !== null ? $tmpMeta->getCompressionType() : $this->_settings->compressionType);
|
| 634 |
+
try {
|
| 635 |
+
$URLsAndPATHs = $this->sendToProcessing($itemHandler, $compType, $tmpMeta->getThumbsTodo());
|
| 636 |
+
} catch(Exception $e) { // Exception("Post metadata is corrupt (No attachment URL)")
|
| 637 |
+
$meta = $itemHandler->setError(ShortPixelAPI::ERR_FILE_NOT_FOUND, $e->getMessage());
|
| 638 |
+
unset($ids[$i]);
|
| 639 |
+
}
|
| 640 |
+
if($first) { //save for later use
|
| 641 |
+
$firstUrlAndPaths = $URLsAndPATHs;
|
| 642 |
+
$first = false;
|
| 643 |
+
}
|
| 644 |
+
}
|
| 645 |
+
|
| 646 |
if ($ids === false || count( $ids ) == 0 ){
|
| 647 |
//if searching, than the script is searching for not processed items and found none yet, should be relaunced
|
| 648 |
if(isset($res['searching']) && $res['searching']) {
|
| 663 |
die(json_encode($response));
|
| 664 |
}
|
| 665 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 666 |
self::log("HIP: 2 Prio Queue: ".json_encode($this->prioQ->get()));
|
| 667 |
//3: Retrieve the file for the first element of the list
|
| 668 |
$itemHandler = $ids[0];
|
| 741 |
}
|
| 742 |
elseif( is_array($customIds)) { // this item is from custom bulk
|
| 743 |
foreach($customIds as $customId) {
|
| 744 |
+
$rootUrl = ShortPixelMetaFacade::getHomeUrl();
|
| 745 |
if($customId->id == $itemHandler->getId()) {
|
| 746 |
if('pdf' == strtolower(pathinfo($meta->getName(), PATHINFO_EXTENSION))) {
|
| 747 |
$result["Thumb"] = plugins_url( 'shortpixel-image-optimiser/res/img/logo-pdf.png' );
|
| 787 |
}
|
| 788 |
$this->advanceBulk($meta->getId(), $result);
|
| 789 |
if($itemHandler->getType() == ShortPixelMetaFacade::CUSTOM_TYPE) {
|
| 790 |
+
$result["CustomImageLink"] = ShortPixelMetaFacade::getHomeUrl() . $meta->getWebPath();
|
| 791 |
}
|
| 792 |
}
|
| 793 |
elseif ($this->prioQ->isPrio($itemId) && $result["Status"] == ShortPixelAPI::STATUS_QUOTA_EXCEEDED) {
|
| 803 |
self::log("HIP: 5 Prio Skipped: ".json_encode($this->prioQ->getSkipped()));
|
| 804 |
}
|
| 805 |
elseif($result["Status"] == ShortPixelAPI::STATUS_RETRY && is_array($customIds)) {
|
| 806 |
+
$result["CustomImageLink"] = $thumb = ShortPixelMetaFacade::getHomeUrl() . $meta->getWebPath();
|
| 807 |
}
|
| 808 |
|
| 809 |
if($result["Status"] !== ShortPixelAPI::STATUS_RETRY) {
|
| 882 |
public function optimizeNowHook($imageId) {
|
| 883 |
if(self::isProcessable($imageId)) {
|
| 884 |
$this->prioQ->push($imageId);
|
| 885 |
+
$itemHandler = new ShortPixelMetaFacade($imageId);
|
| 886 |
+
try {
|
| 887 |
+
$this->sendToProcessing($itemHandler);
|
| 888 |
+
$ret = array("Status" => ShortPixelAPI::STATUS_SUCCESS, "Message" => "");
|
| 889 |
+
} catch(Exception $e) { // Exception("Post metadata is corrupt (No attachment URL)")
|
| 890 |
+
$itemHandler->getMeta();
|
| 891 |
+
$itemHandler->setError(ShortPixelAPI::ERR_FILE_NOT_FOUND, $e->getMessage());
|
| 892 |
+
$ret = array("Status" => ShortPixelAPI::STATUS_FAIL, "Message" => $e->getMessage());
|
| 893 |
+
}
|
| 894 |
} else {
|
| 895 |
+
$ret = array("Status" => ShortPixelAPI::STATUS_SKIP, "Message" => $imageId);
|
| 896 |
}
|
| 897 |
die(json_encode($ret));
|
| 898 |
}
|
| 1185 |
$this->prioQ->push(ShortPixelMetaFacade::queuedId(ShortPixelMetaFacade::CUSTOM_TYPE, $_REQUEST['image']));
|
| 1186 |
}
|
| 1187 |
$customMediaListTable = new ShortPixelListTable($this, $this->spMetaDao, $this->hasNextGen);
|
| 1188 |
+
$items = $customMediaListTable->prepare_items();
|
| 1189 |
+
if ( isset($_GET['noheader']) ) {
|
| 1190 |
+
require_once(ABSPATH . 'wp-admin/admin-header.php');
|
| 1191 |
+
}
|
| 1192 |
+
|
| 1193 |
?>
|
| 1194 |
<div class="wrap shortpixel-other-media">
|
| 1195 |
<h2>
|
| 1207 |
<div class="meta-box-sortables ui-sortable">
|
| 1208 |
<form method="post" class="shortpixel-table">
|
| 1209 |
<?php
|
|
|
|
| 1210 |
$customMediaListTable->display();
|
| 1211 |
//push to the processing list the pending ones, just in case
|
| 1212 |
$count = $this->spMetaDao->getCustomMetaCount();
|
| 1379 |
wp_die(__('You do not have sufficient permissions to access this page.','shortpixel-image-optimiser'));
|
| 1380 |
}
|
| 1381 |
|
| 1382 |
+
$root = self::getCustomFolderBase();
|
| 1383 |
|
| 1384 |
$postDir = rawurldecode($root.(isset($_POST['dir']) ? $_POST['dir'] : null ));
|
| 1385 |
|
| 1419 |
die();
|
| 1420 |
}
|
| 1421 |
|
| 1422 |
+
public static function getCustomFolderBase() {
|
| 1423 |
if(is_main_site()) {
|
| 1424 |
$base = get_home_path();
|
| 1425 |
return realpath(rtrim($base, '/'));
|
| 1598 |
$this->_settings->includeNextGen = 0;
|
| 1599 |
}
|
| 1600 |
if(isset($_POST['addCustomFolder']) && strlen($_POST['addCustomFolder']) > 0) {
|
| 1601 |
+
$folderMsg = $this->spMetaDao->newFolderFromPath(stripslashes($_POST['addCustomFolder']), $uploadPath, self::getCustomFolderBase());
|
| 1602 |
if(!$folderMsg) {
|
| 1603 |
$notice = array("status" => "success", "msg" => __('Folder added successfully.','shortpixel-image-optimiser'));
|
| 1604 |
}
|
| 1687 |
//add the NextGen galleries to custom folders
|
| 1688 |
$ngGalleries = ShortPixelNextGenAdapter::getGalleries();
|
| 1689 |
foreach($ngGalleries as $gallery) {
|
| 1690 |
+
$folderMsg = $this->spMetaDao->newFolderFromPath($gallery, get_home_path(), self::getCustomFolderBase());
|
| 1691 |
$this->_settings->hasCustomFolders = true;
|
| 1692 |
}
|
| 1693 |
$customFolders = $this->spMetaDao->getFolders();
|
| 2172 |
return array('width' => $width, 'height' => $height);
|
| 2173 |
}
|
| 2174 |
|
| 2175 |
+
/* public function getEncryptedData() {
|
| 2176 |
return base64_encode(self::encrypt($this->getApiKey() . "|" . get_site_url(), "sh0r+Pix3l8im1N3r"));
|
| 2177 |
}
|
| 2178 |
+
*/
|
| 2179 |
+
|
| 2180 |
/**
|
| 2181 |
* Returns an encrypted & utf8-encoded
|
| 2182 |
*/
|
| 2183 |
+
/* public static function encrypt($pure_string, $encryption_key)
|
| 2184 |
{
|
| 2185 |
if(!function_exists("mcrypt_get_iv_size") || !function_exists('utf8_encode')) {
|
| 2186 |
return "";
|
| 2190 |
$encrypted_string = \mcrypt_encrypt(MCRYPT_BLOWFISH, $encryption_key, utf8_encode($pure_string), MCRYPT_MODE_ECB, $iv);
|
| 2191 |
return $encrypted_string;
|
| 2192 |
}
|
| 2193 |
+
*/
|
| 2194 |
|
| 2195 |
public function getApiKey() {
|
| 2196 |
return $this->_settings->apiKey;
|
