Skip to content

Commit 3cde582

Browse files
authored
Release version 4.1.4 (#98)
Merge pull request #98 from short-pixel-optimizer/updates
2 parents dfa8b51 + 93b2f0b commit 3cde582

File tree

10 files changed

+69
-991
lines changed

10 files changed

+69
-991
lines changed

build/shortpixel/log/src/ShortPixelLogger.php

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -106,14 +106,19 @@ public function initView()
106106

107107
if ($this->is_active && $this->is_manual_request && $user_is_administrator )
108108
{
109-
$content_url = content_url();
110-
$logPath = $this->logPath;
111-
$pathpos = strpos($logPath, 'wp-content') + strlen('wp-content');
112-
$logPart = substr($logPath, $pathpos);
113-
$logLink = $content_url . $logPart;
109+
110+
$logPath = $this->logPath;
111+
$uploads = wp_get_upload_dir();
112+
113+
114+
if ( 0 === strpos( $logPath, $uploads['basedir'] ) ) { // Simple as it should, filepath and basedir share.
115+
// Replace file location with url location.
116+
$logLink = str_replace( $uploads['basedir'], $uploads['baseurl'], $logPath );
117+
}
118+
114119

115120
$this->view = new \stdClass;
116-
$this->view->logLink = $logLink;
121+
$this->view->logLink = 'view-source:' . esc_url($logLink);
117122
add_action('admin_footer', array($this, 'loadView'));
118123
}
119124
}

build/shortpixel/log/src/view-debug-box.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@
5050

5151
<div class='sp_debug_box'>
5252
<div class='header'><?php echo esc_html($view->namespace) ?> Debug Box </div>
53-
<a target="_blank" href='<?php echo esc_url($view->logLink) ?>'>Logfile</a>
53+
<a target="_blank" href='<?php echo $view->logLink ?>'>Logfile</a>
5454
<div class='content_box'>
5555

5656
</div>

build/shortpixel/replacer/src/Replacer.php

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,7 @@ private function doReplaceQuery($base_url, $search_urls, $replace_urls)
216216

217217
$post_content = $rows["post_content"];
218218
$post_id = $rows['ID'];
219-
$replaced_content = $this->replaceContent($post_content, $search_urls, $replace_urls);
219+
$replaced_content = $this->replaceContent($post_content, $search_urls, $replace_urls, false, true);
220220

221221
if ($replaced_content !== $post_content)
222222
{
@@ -311,14 +311,25 @@ private function handleMetaData($url, $search_urls, $replace_urls)
311311
* @param $search String Search string
312312
* @param $replace String Replacement String
313313
* @param $in_deep Boolean. This is use to prevent serialization of sublevels. Only pass back serialized from top.
314+
* @param $strict_check Boolean . If true, remove all classes from serialization check and fail. This should be done on post_content, not on metadata.
314315
*/
315-
private function replaceContent($content, $search, $replace, $in_deep = false)
316+
private function replaceContent($content, $search, $replace, $in_deep = false, $strict_check = false)
316317
{
317318
//$is_serial = false;
318319
if ( true === is_serialized($content))
319320
{
320321
$serialized_content = $content; // use to return content back if incomplete classes are found, prevent destroying the original information
321-
$content = Unserialize::unserialize($content, array('allowed_classes' => false));
322+
323+
if (true === $strict_check)
324+
{
325+
$args = array('allowed_classes' => false);
326+
}
327+
else
328+
{
329+
$args = array('allowed_classes' => true);
330+
}
331+
332+
$content = Unserialize::unserialize($content, $args);
322333
// bail directly on incomplete classes. In < PHP 7.2 is_object is false on incomplete objects!
323334
if (true === $this->checkIncomplete($content))
324335
{
@@ -362,7 +373,14 @@ private function replaceContent($content, $search, $replace, $in_deep = false)
362373
// bail directly on incomplete classes.
363374
if (true === $this->checkIncomplete($content))
364375
{
365-
return $serialized_content;
376+
// if it was serialized, return the original as not to corrupt data.
377+
if (isset($serialized_content))
378+
{
379+
return $serialized_content;
380+
}
381+
else { // else just return the content.
382+
return $content;
383+
}
366384
}
367385
foreach($content as $key => $value)
368386
{
@@ -493,7 +511,7 @@ private function findNearestSize($sizeName)
493511
/* Check if given content is JSON format. */
494512
private function isJSON($content)
495513
{
496-
if (is_array($content) || is_object($content))
514+
if (is_array($content) || is_object($content) || is_null($content))
497515
return false; // can never be.
498516

499517
$json = json_decode($content);

classes/Controller/ReplaceController.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -437,7 +437,7 @@ protected function getNewExcerpt($meta)
437437
return $excerpt;
438438
}
439439

440-
protected function getSourceUrl()
440+
public function getSourceUrl()
441441
{
442442
if (function_exists('wp_get_original_image_url')) // WP 5.3+
443443
{

classes/api.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
namespace EnableMediaReplace;
66

77
use EnableMediaReplace\ShortPixelLogger\ShortPixelLogger as Log;
8+
use EnableMediaReplace\Controller\ReplaceController as ReplaceController;
9+
810

911
use Exception;
1012
use stdClass;
@@ -74,8 +76,8 @@ public function request( array $posted_data ) {
7476
return $result;
7577
}
7678

77-
$replacer = new Replacer($attachment_id);
78-
$url = $replacer->getSourceUrl();
79+
$replaceController = new ReplaceController($attachment_id);
80+
$url = $replaceController->getSourceUrl();
7981

8082
$settings = get_option('enable_media_replace', array()); // save settings and show last loaded.
8183
$settings['bg_type'] = isset($_POST['background']['type']) ? sanitize_text_field($_POST['background']['type']) : false;

classes/emr-plugin.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ public static function get()
103103
if (Log::debugIsActive()) {
104104
$uploaddir = wp_upload_dir(null, false, false);
105105
if (isset($uploaddir['basedir'])) {
106-
$log->setLogPath($uploaddir['basedir'] . "/emr_log");
106+
$log->setLogPath( trailingslashit($uploaddir['basedir']) . "emr_log");
107107
}
108108
}
109109
return self::$instance;

0 commit comments

Comments
 (0)