Version Description
- fix path problems on multisite on Windows
Download this release
Release Info
| Developer | ShortPixel |
| Plugin | |
| Version | 4.1.4 |
| Comparing to | |
| See all releases | |
Code changes from version 4.1.3 to 4.1.4
- class/db/shortpixel-custom-meta-dao.php +1 -1
- class/db/shortpixel-meta-facade.php +5 -5
- class/db/shortpixel-nextgen-adapter.php +1 -1
- class/model/shortpixel-folder.php +8 -8
- readme.txt +6 -3
- shortpixel_api.php +6 -6
- wp-shortpixel.php +25 -25
class/db/shortpixel-custom-meta-dao.php
CHANGED
|
@@ -278,7 +278,7 @@ class ShortPixelCustomMetaDao {
|
|
| 278 |
$values = ''; $inserted = 0;
|
| 279 |
$sql = "INSERT IGNORE INTO {$this->db->getPrefix()}shortpixel_meta(folder_id, path, name, path_md5, status) VALUES ";
|
| 280 |
for ($i = 0; ($path = fgets($pathsFileHandle)) !== false; $i++) {
|
| 281 |
-
$pathParts = explode(
|
| 282 |
$namePrep = $this->db->prepare("%s",$pathParts[count($pathParts) - 1]);
|
| 283 |
$values .= (strlen($values) ? ", ": "") . "(" . $folderId . ", ". $this->db->prepare("%s", trim($path)) . ", ". $namePrep .", '". md5($path) ."', 0)";
|
| 284 |
if($i % 1000 == 999) {
|
| 278 |
$values = ''; $inserted = 0;
|
| 279 |
$sql = "INSERT IGNORE INTO {$this->db->getPrefix()}shortpixel_meta(folder_id, path, name, path_md5, status) VALUES ";
|
| 280 |
for ($i = 0; ($path = fgets($pathsFileHandle)) !== false; $i++) {
|
| 281 |
+
$pathParts = explode('/', trim($path));
|
| 282 |
$namePrep = $this->db->prepare("%s",$pathParts[count($pathParts) - 1]);
|
| 283 |
$values .= (strlen($values) ? ", ": "") . "(" . $folderId . ", ". $this->db->prepare("%s", trim($path)) . ", ". $namePrep .", '". md5($path) ."', 0)";
|
| 284 |
if($i % 1000 == 999) {
|
class/db/shortpixel-meta-facade.php
CHANGED
|
@@ -261,9 +261,9 @@ class ShortPixelMetaFacade {
|
|
| 261 |
|
| 262 |
public static function pathToRootRelative($path) {
|
| 263 |
//$upl = wp_upload_dir();
|
| 264 |
-
$pathParts = explode(
|
| 265 |
unset($pathParts[count($pathParts) - 1]);
|
| 266 |
-
$path = implode(
|
| 267 |
return str_replace(get_home_path(), "", $path);
|
| 268 |
}
|
| 269 |
|
|
@@ -334,9 +334,9 @@ class ShortPixelMetaFacade {
|
|
| 334 |
} else {
|
| 335 |
$path = (substr($file, 1));
|
| 336 |
}
|
| 337 |
-
$pathArr = explode(
|
| 338 |
unset($pathArr[count($pathArr) - 1]);
|
| 339 |
-
return implode(
|
| 340 |
}
|
| 341 |
|
| 342 |
public static function isMediaSubfolder($path) {
|
|
@@ -349,7 +349,7 @@ class ShortPixelMetaFacade {
|
|
| 349 |
}
|
| 350 |
//contains one of the year subfolders of the media library
|
| 351 |
if(strpos($path, $uploadPath) == 0) {
|
| 352 |
-
$pathArr = explode(
|
| 353 |
if( count($pathArr) >= 1
|
| 354 |
&& is_numeric($pathArr[0]) && $pathArr[0] > 1900 && $pathArr[0] < 2100 //contains the year subfolder
|
| 355 |
&& ( count($pathArr) == 1 //if there is another subfolder then it's the month subfolder
|
| 261 |
|
| 262 |
public static function pathToRootRelative($path) {
|
| 263 |
//$upl = wp_upload_dir();
|
| 264 |
+
$pathParts = explode('/', $path);
|
| 265 |
unset($pathParts[count($pathParts) - 1]);
|
| 266 |
+
$path = implode('/', $pathParts);
|
| 267 |
return str_replace(get_home_path(), "", $path);
|
| 268 |
}
|
| 269 |
|
| 334 |
} else {
|
| 335 |
$path = (substr($file, 1));
|
| 336 |
}
|
| 337 |
+
$pathArr = explode('/', $path);
|
| 338 |
unset($pathArr[count($pathArr) - 1]);
|
| 339 |
+
return implode('/', $pathArr) . '/';
|
| 340 |
}
|
| 341 |
|
| 342 |
public static function isMediaSubfolder($path) {
|
| 349 |
}
|
| 350 |
//contains one of the year subfolders of the media library
|
| 351 |
if(strpos($path, $uploadPath) == 0) {
|
| 352 |
+
$pathArr = explode('/', str_replace($uploadBase . '/', "", $path));
|
| 353 |
if( count($pathArr) >= 1
|
| 354 |
&& is_numeric($pathArr[0]) && $pathArr[0] > 1900 && $pathArr[0] < 2100 //contains the year subfolder
|
| 355 |
&& ( count($pathArr) == 1 //if there is another subfolder then it's the month subfolder
|
class/db/shortpixel-nextgen-adapter.php
CHANGED
|
@@ -31,7 +31,7 @@ class ShortPixelNextGenAdapter {
|
|
| 31 |
}
|
| 32 |
|
| 33 |
public static function pathToAbsolute($item) {
|
| 34 |
-
return str_replace(
|
| 35 |
}
|
| 36 |
|
| 37 |
public static function path($item) {
|
| 31 |
}
|
| 32 |
|
| 33 |
public static function pathToAbsolute($item) {
|
| 34 |
+
return str_replace('//', '/', get_home_path() . $item);
|
| 35 |
}
|
| 36 |
|
| 37 |
public static function path($item) {
|
class/model/shortpixel-folder.php
CHANGED
|
@@ -18,8 +18,8 @@ class ShortPixelFolder extends ShortPixelEntity{
|
|
| 18 |
}
|
| 19 |
|
| 20 |
public static function checkFolder($folder, $base) {
|
| 21 |
-
if(substr($folder, 0, 1) !==
|
| 22 |
-
$folder =
|
| 23 |
}
|
| 24 |
if(is_dir($folder)) {
|
| 25 |
return realpath($folder);
|
|
@@ -40,7 +40,7 @@ class ShortPixelFolder extends ShortPixelEntity{
|
|
| 40 |
$parents = array($parents);
|
| 41 |
}
|
| 42 |
foreach($parents as $parent) {
|
| 43 |
-
if(strpos($folder, $parent) === 0 && (strlen($parent) == strlen($folder) || substr($folder, strlen($parent), 1) ==
|
| 44 |
return $parent;
|
| 45 |
}
|
| 46 |
}
|
|
@@ -58,7 +58,7 @@ class ShortPixelFolder extends ShortPixelEntity{
|
|
| 58 |
$subfolders[] = $subfolders;
|
| 59 |
}
|
| 60 |
foreach($subfolders as $sub) {
|
| 61 |
-
if(strpos($sub, $folder) === 0 && (strlen($folder) == strlen($sub) || substr($sub, strlen($folder) - 1, 1) ==
|
| 62 |
return $sub;
|
| 63 |
}
|
| 64 |
}
|
|
@@ -77,7 +77,7 @@ class ShortPixelFolder extends ShortPixelEntity{
|
|
| 77 |
}
|
| 78 |
$files = scandir($path);
|
| 79 |
foreach($files as $t) {
|
| 80 |
-
$tpath = rtrim($path,
|
| 81 |
if(in_array($t, $ignore)) continue;
|
| 82 |
if (is_dir($tpath)) {
|
| 83 |
$size += $this->countFiles($tpath);
|
|
@@ -90,7 +90,7 @@ class ShortPixelFolder extends ShortPixelEntity{
|
|
| 90 |
|
| 91 |
public function getFileList($onlyNewerThan = 0) {
|
| 92 |
$upl = wp_upload_dir();
|
| 93 |
-
$fileListPath = tempnam($upl["basedir"] .
|
| 94 |
$fileHandle = fopen($fileListPath, 'w+');
|
| 95 |
self::getFileListRecursive($this->getPath(), $fileHandle, $onlyNewerThan);
|
| 96 |
fclose($fileHandle);
|
|
@@ -108,7 +108,7 @@ class ShortPixelFolder extends ShortPixelEntity{
|
|
| 108 |
*/
|
| 109 |
foreach($files as $t) {
|
| 110 |
if(in_array($t, $ignore)) continue;
|
| 111 |
-
$tpath = rtrim($path,
|
| 112 |
if (is_dir($tpath)) {
|
| 113 |
self::getFileListRecursive($tpath, $fileHandle, $onlyNewerThan);
|
| 114 |
} elseif($add && in_array(pathinfo($t, PATHINFO_EXTENSION), WPShortPixel::$PROCESSABLE_EXTENSIONS)) {
|
|
@@ -130,7 +130,7 @@ class ShortPixelFolder extends ShortPixelEntity{
|
|
| 130 |
$mtime = max($mtime, filemtime($path));
|
| 131 |
foreach($files as $t) {
|
| 132 |
if(in_array($t, $ignore)) continue;
|
| 133 |
-
$tpath = rtrim($path,
|
| 134 |
if (is_dir($tpath)) {
|
| 135 |
$mtime = max($mtime, filemtime($tpath));
|
| 136 |
self::getFolderContentsChangeDateRecursive($tpath, $mtime, $refMtime);
|
| 18 |
}
|
| 19 |
|
| 20 |
public static function checkFolder($folder, $base) {
|
| 21 |
+
if(substr($folder, 0, 1) !== '/') {
|
| 22 |
+
$folder = '/' . $folder;
|
| 23 |
}
|
| 24 |
if(is_dir($folder)) {
|
| 25 |
return realpath($folder);
|
| 40 |
$parents = array($parents);
|
| 41 |
}
|
| 42 |
foreach($parents as $parent) {
|
| 43 |
+
if(strpos($folder, $parent) === 0 && (strlen($parent) == strlen($folder) || substr($folder, strlen($parent), 1) == '/')) {
|
| 44 |
return $parent;
|
| 45 |
}
|
| 46 |
}
|
| 58 |
$subfolders[] = $subfolders;
|
| 59 |
}
|
| 60 |
foreach($subfolders as $sub) {
|
| 61 |
+
if(strpos($sub, $folder) === 0 && (strlen($folder) == strlen($sub) || substr($sub, strlen($folder) - 1, 1) == '/')) {
|
| 62 |
return $sub;
|
| 63 |
}
|
| 64 |
}
|
| 77 |
}
|
| 78 |
$files = scandir($path);
|
| 79 |
foreach($files as $t) {
|
| 80 |
+
$tpath = rtrim($path, '/') . '/' . $t;
|
| 81 |
if(in_array($t, $ignore)) continue;
|
| 82 |
if (is_dir($tpath)) {
|
| 83 |
$size += $this->countFiles($tpath);
|
| 90 |
|
| 91 |
public function getFileList($onlyNewerThan = 0) {
|
| 92 |
$upl = wp_upload_dir();
|
| 93 |
+
$fileListPath = tempnam($upl["basedir"] . '/', 'sp_');
|
| 94 |
$fileHandle = fopen($fileListPath, 'w+');
|
| 95 |
self::getFileListRecursive($this->getPath(), $fileHandle, $onlyNewerThan);
|
| 96 |
fclose($fileHandle);
|
| 108 |
*/
|
| 109 |
foreach($files as $t) {
|
| 110 |
if(in_array($t, $ignore)) continue;
|
| 111 |
+
$tpath = rtrim($path, '/') . '/' . $t;
|
| 112 |
if (is_dir($tpath)) {
|
| 113 |
self::getFileListRecursive($tpath, $fileHandle, $onlyNewerThan);
|
| 114 |
} elseif($add && in_array(pathinfo($t, PATHINFO_EXTENSION), WPShortPixel::$PROCESSABLE_EXTENSIONS)) {
|
| 130 |
$mtime = max($mtime, filemtime($path));
|
| 131 |
foreach($files as $t) {
|
| 132 |
if(in_array($t, $ignore)) continue;
|
| 133 |
+
$tpath = rtrim($path, '/') . '/' . $t;
|
| 134 |
if (is_dir($tpath)) {
|
| 135 |
$mtime = max($mtime, filemtime($tpath));
|
| 136 |
self::getFolderContentsChangeDateRecursive($tpath, $mtime, $refMtime);
|
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.1.
|
| 9 |
License: GPLv2 or later
|
| 10 |
License URI: http://www.gnu.org/licenses/gpl-2.0.html
|
| 11 |
|
|
@@ -62,8 +62,7 @@ Check out <a rel="friend" href="https://shortpixel.com/pricing" target="_blank">
|
|
| 62 |
> ★★★★★ **The secret sauce for a WordPress website.** [mark1mark](https://wordpress.org/support/topic/the-secret-sauce-for-a-wordpress-website/)
|
| 63 |
> ★★★★★ **A must have plugin, great support!** [ElColo13](https://wordpress.org/support/topic/a-must-have-plugin-great-support/)
|
| 64 |
> ★★★★★ **Excellent Plugin! Even Better Customer Service!** [scaliendo](https://wordpress.org/support/topic/great-plugin-great-support-508/)
|
| 65 |
-
> ★★★★★ **Great image compression, solid plugin, equally great support.** [matters1959](https://wordpress.org/support/topic/support-shortpixel-image-optimizer/)
|
| 66 |
-
>
|
| 67 |
> [more testimonials](https://wordpress.org/support/plugin/shortpixel-image-optimiser/reviews/?filter=5)
|
| 68 |
|
| 69 |
|
|
@@ -179,6 +178,10 @@ The ShortPixel team is here to help. <a href="https://shortpixel.com/contact">Co
|
|
| 179 |
|
| 180 |
== Changelog ==
|
| 181 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 182 |
= 4.1.3 =
|
| 183 |
|
| 184 |
* fix debug mode too intrusive
|
| 5 |
|
| 6 |
Requires at least: 3.2.0
|
| 7 |
Tested up to: 4.6
|
| 8 |
+
Stable tag: 4.1.4
|
| 9 |
License: GPLv2 or later
|
| 10 |
License URI: http://www.gnu.org/licenses/gpl-2.0.html
|
| 11 |
|
| 62 |
> ★★★★★ **The secret sauce for a WordPress website.** [mark1mark](https://wordpress.org/support/topic/the-secret-sauce-for-a-wordpress-website/)
|
| 63 |
> ★★★★★ **A must have plugin, great support!** [ElColo13](https://wordpress.org/support/topic/a-must-have-plugin-great-support/)
|
| 64 |
> ★★★★★ **Excellent Plugin! Even Better Customer Service!** [scaliendo](https://wordpress.org/support/topic/great-plugin-great-support-508/)
|
| 65 |
+
> ★★★★★ **Great image compression, solid plugin, equally great support.** [matters1959](https://wordpress.org/support/topic/support-shortpixel-image-optimizer/)
|
|
|
|
| 66 |
> [more testimonials](https://wordpress.org/support/plugin/shortpixel-image-optimiser/reviews/?filter=5)
|
| 67 |
|
| 68 |
|
| 178 |
|
| 179 |
== Changelog ==
|
| 180 |
|
| 181 |
+
= 4.1.4 =
|
| 182 |
+
|
| 183 |
+
* fix path problems on multisite on Windows
|
| 184 |
+
|
| 185 |
= 4.1.3 =
|
| 186 |
|
| 187 |
* fix debug mode too intrusive
|
shortpixel_api.php
CHANGED
|
@@ -233,7 +233,7 @@ class ShortPixelAPI {
|
|
| 233 |
if($meta->getRetries() >= MAX_FAIL_RETRIES) {
|
| 234 |
$meta->setStatus($APIresponse[0]->Status->Code);
|
| 235 |
$meta->setMessage($APIresponse[0]->Status->Message);
|
| 236 |
-
$itemHandler->updateMeta();
|
| 237 |
}
|
| 238 |
return $err;
|
| 239 |
}
|
|
@@ -396,7 +396,7 @@ class ShortPixelAPI {
|
|
| 396 |
|
| 397 |
//figure out in what SubDir files should land
|
| 398 |
//#$SubDir = $this->returnSubDir(get_attached_file($ID));
|
| 399 |
-
$fullSubDir = str_replace(get_home_path(), "", dirname($itemHandler->getMeta()->getPath())) .
|
| 400 |
//die("Uploads base: " . SP_UPLOADS_BASE . " FullSubDir: ". $fullSubDir . " PATH: " . dirname($itemHandler->getMeta()->getPath()));
|
| 401 |
$SubDir = ShortPixelMetaFacade::returnSubDir($itemHandler->getMeta()->getPath(), $itemHandler->getType());
|
| 402 |
|
|
@@ -409,13 +409,13 @@ class ShortPixelAPI {
|
|
| 409 |
return array("Status" => self::STATUS_FAIL, "Message" => "Backup folder does not exist and it cannot be created");
|
| 410 |
}
|
| 411 |
//create subdir in backup folder if needed
|
| 412 |
-
@mkdir( SP_BACKUP_FOLDER .
|
| 413 |
|
| 414 |
foreach ( $source as $fileID => $filePATH )//create destination files array
|
| 415 |
{
|
| 416 |
-
$destination[$fileID] = SP_BACKUP_FOLDER .
|
| 417 |
}
|
| 418 |
-
//die("IZ BACKUP: " . SP_BACKUP_FOLDER .
|
| 419 |
|
| 420 |
//now that we have original files and where we should back them up we attempt to do just that
|
| 421 |
if(is_writable(SP_BACKUP_FOLDER))
|
|
@@ -462,7 +462,7 @@ class ShortPixelAPI {
|
|
| 462 |
$targetFile = $PATHs[$tempFileID];
|
| 463 |
copy($tempFilePATH, $targetFile);
|
| 464 |
if(file_exists($tempWebpFilePATH)) {
|
| 465 |
-
$targetWebPFile = dirname($targetFile) .
|
| 466 |
copy($tempWebpFilePATH, $targetWebPFile);
|
| 467 |
}
|
| 468 |
if($firstImage) { //this is the main image
|
| 233 |
if($meta->getRetries() >= MAX_FAIL_RETRIES) {
|
| 234 |
$meta->setStatus($APIresponse[0]->Status->Code);
|
| 235 |
$meta->setMessage($APIresponse[0]->Status->Message);
|
| 236 |
+
$itemHandler->updateMeta($meta);
|
| 237 |
}
|
| 238 |
return $err;
|
| 239 |
}
|
| 396 |
|
| 397 |
//figure out in what SubDir files should land
|
| 398 |
//#$SubDir = $this->returnSubDir(get_attached_file($ID));
|
| 399 |
+
$fullSubDir = str_replace(wp_normalize_path(get_home_path()), "", wp_normalize_path(dirname($itemHandler->getMeta()->getPath()))) . '/';
|
| 400 |
//die("Uploads base: " . SP_UPLOADS_BASE . " FullSubDir: ". $fullSubDir . " PATH: " . dirname($itemHandler->getMeta()->getPath()));
|
| 401 |
$SubDir = ShortPixelMetaFacade::returnSubDir($itemHandler->getMeta()->getPath(), $itemHandler->getType());
|
| 402 |
|
| 409 |
return array("Status" => self::STATUS_FAIL, "Message" => "Backup folder does not exist and it cannot be created");
|
| 410 |
}
|
| 411 |
//create subdir in backup folder if needed
|
| 412 |
+
@mkdir( SP_BACKUP_FOLDER . '/' . $fullSubDir, 0777, true);
|
| 413 |
|
| 414 |
foreach ( $source as $fileID => $filePATH )//create destination files array
|
| 415 |
{
|
| 416 |
+
$destination[$fileID] = SP_BACKUP_FOLDER . '/' . $fullSubDir . self::MB_basename($source[$fileID]);
|
| 417 |
}
|
| 418 |
+
//die("IZ BACKUP: " . SP_BACKUP_FOLDER . '/' . $SubDir . var_dump($destination));
|
| 419 |
|
| 420 |
//now that we have original files and where we should back them up we attempt to do just that
|
| 421 |
if(is_writable(SP_BACKUP_FOLDER))
|
| 462 |
$targetFile = $PATHs[$tempFileID];
|
| 463 |
copy($tempFilePATH, $targetFile);
|
| 464 |
if(file_exists($tempWebpFilePATH)) {
|
| 465 |
+
$targetWebPFile = dirname($targetFile) . '/' . basename($targetFile, '.' . pathinfo($targetFile, PATHINFO_EXTENSION)) . ".webp";
|
| 466 |
copy($tempWebpFilePATH, $targetWebPFile);
|
| 467 |
}
|
| 468 |
if($firstImage) { //this is the main image
|
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.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.1.
|
| 16 |
define('SP_MAX_TIMEOUT', 10);
|
| 17 |
define('SP_VALIDATE_MAX_TIMEOUT', 15);
|
| 18 |
define('SP_BACKUP', 'ShortpixelBackups');
|
|
@@ -28,7 +28,7 @@ define('SP_UPLOADS_BASE', $sp__uploads['basedir']);
|
|
| 28 |
define('SP_UPLOADS_NAME', basename(is_main_site() ? SP_UPLOADS_BASE : dirname(dirname(SP_UPLOADS_BASE))));
|
| 29 |
define('SP_UPLOADS_BASE_REL', str_replace(get_home_path(),"", $sp__uploads['basedir']));
|
| 30 |
$sp__backupBase = is_main_site() ? SP_UPLOADS_BASE : dirname(dirname(SP_UPLOADS_BASE));
|
| 31 |
-
define('SP_BACKUP_FOLDER', $sp__backupBase .
|
| 32 |
|
| 33 |
/*
|
| 34 |
if ( is_numeric($MAX_EXECUTION_TIME) && $MAX_EXECUTION_TIME > 10 )
|
|
@@ -386,7 +386,7 @@ class WPShortPixel {
|
|
| 386 |
$folderId = $folder->getId();
|
| 387 |
self::log("NG Image Upload: created folder from path $galleryPath : Folder info: " . json_encode($folder));
|
| 388 |
}
|
| 389 |
-
$pathParts = explode(
|
| 390 |
//Add the main image
|
| 391 |
$meta = new ShortPixelMeta();
|
| 392 |
$meta->setPath($imageFsPath);
|
|
@@ -405,7 +405,7 @@ class WPShortPixel {
|
|
| 405 |
//add the thumb image if exists
|
| 406 |
$pathParts[] = "thumbs_" . $pathParts[count($pathParts) - 1];
|
| 407 |
$pathParts[count($pathParts) - 2] = "thumbs";
|
| 408 |
-
$thumbPath = implode(
|
| 409 |
if(file_exists($thumbPath)) {
|
| 410 |
$metaThumb = new ShortPixelMeta();
|
| 411 |
$metaThumb->setPath($thumbPath);
|
|
@@ -856,13 +856,13 @@ class WPShortPixel {
|
|
| 856 |
$SubDir = ShortPixelMetaFacade::returnSubDir($file, ShortPixelMetaFacade::MEDIA_LIBRARY_TYPE);
|
| 857 |
|
| 858 |
//sometimes the month of original file and backup can differ
|
| 859 |
-
if ( !file_exists(SP_BACKUP_FOLDER .
|
| 860 |
$SubDir = date("Y") . "/" . date("m") . "/";
|
| 861 |
-
if( !file_exists(SP_BACKUP_FOLDER .
|
| 862 |
return false;
|
| 863 |
}
|
| 864 |
}
|
| 865 |
-
return SP_BACKUP_FOLDER .
|
| 866 |
}
|
| 867 |
|
| 868 |
protected function setFilePerms($file) {
|
|
@@ -899,7 +899,7 @@ class WPShortPixel {
|
|
| 899 |
foreach($meta["sizes"] as $size => $imageData) {
|
| 900 |
$source = $bkFolder . $imageData['file'];
|
| 901 |
if(!file_exists($source)) continue; // if thumbs were not optimized, then the backups will not be there.
|
| 902 |
-
$thumbsPaths[$source] = $pathInfo['dirname'] .
|
| 903 |
if(! $this->setFilePerms($source)) return false;
|
| 904 |
}
|
| 905 |
}
|
|
@@ -948,8 +948,8 @@ class WPShortPixel {
|
|
| 948 |
if(!$meta || $meta->getStatus() != 2) return false;
|
| 949 |
|
| 950 |
$file = $meta->getPath();
|
| 951 |
-
$fullSubDir = str_replace(get_home_path(), "", dirname($file)) .
|
| 952 |
-
$bkFile = SP_BACKUP_FOLDER .
|
| 953 |
|
| 954 |
if(file_exists($bkFile)) {
|
| 955 |
@rename($bkFile, $file);
|
|
@@ -1047,11 +1047,11 @@ class WPShortPixel {
|
|
| 1047 |
try {
|
| 1048 |
$SubDir = ShortPixelMetaFacade::returnSubDir($file, ShortPixelMetaFacade::MEDIA_LIBRARY_TYPE);
|
| 1049 |
|
| 1050 |
-
@unlink(SP_BACKUP_FOLDER .
|
| 1051 |
|
| 1052 |
if ( !empty($meta['file']) )
|
| 1053 |
{
|
| 1054 |
-
$filesPath = SP_BACKUP_FOLDER .
|
| 1055 |
//remove thumbs thumbnails
|
| 1056 |
if(isset($meta["sizes"])) {
|
| 1057 |
foreach($meta["sizes"] as $size => $imageData) {
|
|
@@ -1353,7 +1353,7 @@ class WPShortPixel {
|
|
| 1353 |
public function getCustomFolderBase() {
|
| 1354 |
if(is_main_site()) {
|
| 1355 |
$base = get_home_path();
|
| 1356 |
-
return rtrim($base,
|
| 1357 |
} else {
|
| 1358 |
$up = wp_upload_dir();
|
| 1359 |
return $up['basedir'];
|
|
@@ -1461,7 +1461,7 @@ class WPShortPixel {
|
|
| 1461 |
//test that the "uploads" have the right rights and also we can create the backup dir for ShortPixel
|
| 1462 |
if ( !file_exists(SP_BACKUP_FOLDER) && !@mkdir(SP_BACKUP_FOLDER, 0777, true) )
|
| 1463 |
$notice = array("status" => "error", "msg" => "There is something preventing us to create a new folder for backing up your original files.<BR>
|
| 1464 |
-
Please make sure that folder <b>" . WP_CONTENT_DIR .
|
| 1465 |
} else {
|
| 1466 |
if(isset($_POST['validate'])) {
|
| 1467 |
//display notification
|
|
@@ -1911,8 +1911,8 @@ class WPShortPixel {
|
|
| 1911 |
|
| 1912 |
|
| 1913 |
public static function deleteDir($dirPath) {
|
| 1914 |
-
if (substr($dirPath, strlen($dirPath) - 1, 1) !=
|
| 1915 |
-
$dirPath .=
|
| 1916 |
}
|
| 1917 |
$files = glob($dirPath . '*', GLOB_MARK);
|
| 1918 |
foreach ($files as $file) {
|
|
@@ -1932,7 +1932,7 @@ class WPShortPixel {
|
|
| 1932 |
} else {
|
| 1933 |
return $total_size;
|
| 1934 |
}
|
| 1935 |
-
$cleanPath = rtrim($path,
|
| 1936 |
foreach($files as $t) {
|
| 1937 |
if ($t<>"." && $t<>"..")
|
| 1938 |
{
|
|
@@ -1951,7 +1951,7 @@ class WPShortPixel {
|
|
| 1951 |
}
|
| 1952 |
|
| 1953 |
public function migrateBackupFolder() {
|
| 1954 |
-
$oldBackupFolder = WP_CONTENT_DIR .
|
| 1955 |
|
| 1956 |
if(file_exists($oldBackupFolder)) { //if old backup folder does not exist then there is nothing to do
|
| 1957 |
|
|
@@ -1962,7 +1962,7 @@ class WPShortPixel {
|
|
| 1962 |
|
| 1963 |
$scannedDirectory = array_diff(scandir($oldBackupFolder), array('..', '.'));
|
| 1964 |
foreach($scannedDirectory as $file) {
|
| 1965 |
-
@rename($oldBackupFolder.
|
| 1966 |
}
|
| 1967 |
$scannedDirectory = array_diff(scandir($oldBackupFolder), array('..', '.'));
|
| 1968 |
if(empty($scannedDirectory)) {
|
|
@@ -1970,20 +1970,20 @@ class WPShortPixel {
|
|
| 1970 |
}
|
| 1971 |
}
|
| 1972 |
//now if the backup folder does not contain the uploads level, create it
|
| 1973 |
-
if( !is_dir(SP_BACKUP_FOLDER .
|
| 1974 |
-
&& !is_dir(SP_BACKUP_FOLDER .
|
| 1975 |
@rename(SP_BACKUP_FOLDER, SP_BACKUP_FOLDER."_tmp");
|
| 1976 |
@mkdir(SP_BACKUP_FOLDER);
|
| 1977 |
-
@rename(SP_BACKUP_FOLDER."_tmp", SP_BACKUP_FOLDER.
|
| 1978 |
if(!file_exists(SP_BACKUP_FOLDER)) {//just in case..
|
| 1979 |
@rename(SP_BACKUP_FOLDER."_tmp", SP_BACKUP_FOLDER);
|
| 1980 |
}
|
| 1981 |
}
|
| 1982 |
//then create the wp-content level if not present
|
| 1983 |
-
if(!is_dir(SP_BACKUP_FOLDER .
|
| 1984 |
@rename(SP_BACKUP_FOLDER, SP_BACKUP_FOLDER."_tmp");
|
| 1985 |
@mkdir(SP_BACKUP_FOLDER);
|
| 1986 |
-
@rename(SP_BACKUP_FOLDER."_tmp", SP_BACKUP_FOLDER.
|
| 1987 |
if(!file_exists(SP_BACKUP_FOLDER)) {//just in case..
|
| 1988 |
@rename(SP_BACKUP_FOLDER."_tmp", SP_BACKUP_FOLDER);
|
| 1989 |
}
|
| 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.1.4
|
| 7 |
* Author: ShortPixel
|
| 8 |
* Author URI: https://shortpixel.com
|
| 9 |
*/
|
| 12 |
|
| 13 |
define('SP_AFFILIATE_CODE', '');
|
| 14 |
|
| 15 |
+
define('PLUGIN_VERSION', "4.1.4");
|
| 16 |
define('SP_MAX_TIMEOUT', 10);
|
| 17 |
define('SP_VALIDATE_MAX_TIMEOUT', 15);
|
| 18 |
define('SP_BACKUP', 'ShortpixelBackups');
|
| 28 |
define('SP_UPLOADS_NAME', basename(is_main_site() ? SP_UPLOADS_BASE : dirname(dirname(SP_UPLOADS_BASE))));
|
| 29 |
define('SP_UPLOADS_BASE_REL', str_replace(get_home_path(),"", $sp__uploads['basedir']));
|
| 30 |
$sp__backupBase = is_main_site() ? SP_UPLOADS_BASE : dirname(dirname(SP_UPLOADS_BASE));
|
| 31 |
+
define('SP_BACKUP_FOLDER', $sp__backupBase . '/' . SP_BACKUP);
|
| 32 |
|
| 33 |
/*
|
| 34 |
if ( is_numeric($MAX_EXECUTION_TIME) && $MAX_EXECUTION_TIME > 10 )
|
| 386 |
$folderId = $folder->getId();
|
| 387 |
self::log("NG Image Upload: created folder from path $galleryPath : Folder info: " . json_encode($folder));
|
| 388 |
}
|
| 389 |
+
$pathParts = explode('/', trim($imageFsPath));
|
| 390 |
//Add the main image
|
| 391 |
$meta = new ShortPixelMeta();
|
| 392 |
$meta->setPath($imageFsPath);
|
| 405 |
//add the thumb image if exists
|
| 406 |
$pathParts[] = "thumbs_" . $pathParts[count($pathParts) - 1];
|
| 407 |
$pathParts[count($pathParts) - 2] = "thumbs";
|
| 408 |
+
$thumbPath = implode('/', $pathParts);
|
| 409 |
if(file_exists($thumbPath)) {
|
| 410 |
$metaThumb = new ShortPixelMeta();
|
| 411 |
$metaThumb->setPath($thumbPath);
|
| 856 |
$SubDir = ShortPixelMetaFacade::returnSubDir($file, ShortPixelMetaFacade::MEDIA_LIBRARY_TYPE);
|
| 857 |
|
| 858 |
//sometimes the month of original file and backup can differ
|
| 859 |
+
if ( !file_exists(SP_BACKUP_FOLDER . '/' . $SubDir . ShortPixelAPI::MB_basename($file)) ) {
|
| 860 |
$SubDir = date("Y") . "/" . date("m") . "/";
|
| 861 |
+
if( !file_exists(SP_BACKUP_FOLDER . '/' . $SubDir . ShortPixelAPI::MB_basename($file)) ) {
|
| 862 |
return false;
|
| 863 |
}
|
| 864 |
}
|
| 865 |
+
return SP_BACKUP_FOLDER . '/' . $SubDir;
|
| 866 |
}
|
| 867 |
|
| 868 |
protected function setFilePerms($file) {
|
| 899 |
foreach($meta["sizes"] as $size => $imageData) {
|
| 900 |
$source = $bkFolder . $imageData['file'];
|
| 901 |
if(!file_exists($source)) continue; // if thumbs were not optimized, then the backups will not be there.
|
| 902 |
+
$thumbsPaths[$source] = $pathInfo['dirname'] . '/' . $imageData['file'];
|
| 903 |
if(! $this->setFilePerms($source)) return false;
|
| 904 |
}
|
| 905 |
}
|
| 948 |
if(!$meta || $meta->getStatus() != 2) return false;
|
| 949 |
|
| 950 |
$file = $meta->getPath();
|
| 951 |
+
$fullSubDir = str_replace(get_home_path(), "", dirname($file)) . '/';
|
| 952 |
+
$bkFile = SP_BACKUP_FOLDER . '/' . $fullSubDir . ShortPixelAPI::MB_basename($file);
|
| 953 |
|
| 954 |
if(file_exists($bkFile)) {
|
| 955 |
@rename($bkFile, $file);
|
| 1047 |
try {
|
| 1048 |
$SubDir = ShortPixelMetaFacade::returnSubDir($file, ShortPixelMetaFacade::MEDIA_LIBRARY_TYPE);
|
| 1049 |
|
| 1050 |
+
@unlink(SP_BACKUP_FOLDER . '/' . $SubDir . ShortPixelAPI::MB_basename($file));
|
| 1051 |
|
| 1052 |
if ( !empty($meta['file']) )
|
| 1053 |
{
|
| 1054 |
+
$filesPath = SP_BACKUP_FOLDER . '/' . $SubDir;//base BACKUP path
|
| 1055 |
//remove thumbs thumbnails
|
| 1056 |
if(isset($meta["sizes"])) {
|
| 1057 |
foreach($meta["sizes"] as $size => $imageData) {
|
| 1353 |
public function getCustomFolderBase() {
|
| 1354 |
if(is_main_site()) {
|
| 1355 |
$base = get_home_path();
|
| 1356 |
+
return rtrim($base, '/');
|
| 1357 |
} else {
|
| 1358 |
$up = wp_upload_dir();
|
| 1359 |
return $up['basedir'];
|
| 1461 |
//test that the "uploads" have the right rights and also we can create the backup dir for ShortPixel
|
| 1462 |
if ( !file_exists(SP_BACKUP_FOLDER) && !@mkdir(SP_BACKUP_FOLDER, 0777, true) )
|
| 1463 |
$notice = array("status" => "error", "msg" => "There is something preventing us to create a new folder for backing up your original files.<BR>
|
| 1464 |
+
Please make sure that folder <b>" . WP_CONTENT_DIR . '/' . SP_UPLOADS_NAME . "</b> has the necessary write and read rights.");
|
| 1465 |
} else {
|
| 1466 |
if(isset($_POST['validate'])) {
|
| 1467 |
//display notification
|
| 1911 |
|
| 1912 |
|
| 1913 |
public static function deleteDir($dirPath) {
|
| 1914 |
+
if (substr($dirPath, strlen($dirPath) - 1, 1) != '/') {
|
| 1915 |
+
$dirPath .= '/';
|
| 1916 |
}
|
| 1917 |
$files = glob($dirPath . '*', GLOB_MARK);
|
| 1918 |
foreach ($files as $file) {
|
| 1932 |
} else {
|
| 1933 |
return $total_size;
|
| 1934 |
}
|
| 1935 |
+
$cleanPath = rtrim($path, '/'). '/';
|
| 1936 |
foreach($files as $t) {
|
| 1937 |
if ($t<>"." && $t<>"..")
|
| 1938 |
{
|
| 1951 |
}
|
| 1952 |
|
| 1953 |
public function migrateBackupFolder() {
|
| 1954 |
+
$oldBackupFolder = WP_CONTENT_DIR . '/' . SP_BACKUP;
|
| 1955 |
|
| 1956 |
if(file_exists($oldBackupFolder)) { //if old backup folder does not exist then there is nothing to do
|
| 1957 |
|
| 1962 |
|
| 1963 |
$scannedDirectory = array_diff(scandir($oldBackupFolder), array('..', '.'));
|
| 1964 |
foreach($scannedDirectory as $file) {
|
| 1965 |
+
@rename($oldBackupFolder.'/'.$file, SP_BACKUP_FOLDER.'/'.$file);
|
| 1966 |
}
|
| 1967 |
$scannedDirectory = array_diff(scandir($oldBackupFolder), array('..', '.'));
|
| 1968 |
if(empty($scannedDirectory)) {
|
| 1970 |
}
|
| 1971 |
}
|
| 1972 |
//now if the backup folder does not contain the uploads level, create it
|
| 1973 |
+
if( !is_dir(SP_BACKUP_FOLDER . '/' . SP_UPLOADS_NAME )
|
| 1974 |
+
&& !is_dir(SP_BACKUP_FOLDER . '/' . basename(WP_CONTENT_DIR))) {
|
| 1975 |
@rename(SP_BACKUP_FOLDER, SP_BACKUP_FOLDER."_tmp");
|
| 1976 |
@mkdir(SP_BACKUP_FOLDER);
|
| 1977 |
+
@rename(SP_BACKUP_FOLDER."_tmp", SP_BACKUP_FOLDER.'/'.SP_UPLOADS_NAME);
|
| 1978 |
if(!file_exists(SP_BACKUP_FOLDER)) {//just in case..
|
| 1979 |
@rename(SP_BACKUP_FOLDER."_tmp", SP_BACKUP_FOLDER);
|
| 1980 |
}
|
| 1981 |
}
|
| 1982 |
//then create the wp-content level if not present
|
| 1983 |
+
if(!is_dir(SP_BACKUP_FOLDER . '/' . basename(WP_CONTENT_DIR))) {
|
| 1984 |
@rename(SP_BACKUP_FOLDER, SP_BACKUP_FOLDER."_tmp");
|
| 1985 |
@mkdir(SP_BACKUP_FOLDER);
|
| 1986 |
+
@rename(SP_BACKUP_FOLDER."_tmp", SP_BACKUP_FOLDER.'/' . basename(WP_CONTENT_DIR));
|
| 1987 |
if(!file_exists(SP_BACKUP_FOLDER)) {//just in case..
|
| 1988 |
@rename(SP_BACKUP_FOLDER."_tmp", SP_BACKUP_FOLDER);
|
| 1989 |
}
|
