Skip to content

Commit

Permalink
Release version 4.1.4 (#98)
Browse files Browse the repository at this point in the history
Merge pull request #98 from short-pixel-optimizer/updates
  • Loading branch information
pdobrescu authored Sep 22, 2023
2 parents dfa8b51 + 93b2f0b commit 3cde582
Show file tree
Hide file tree
Showing 10 changed files with 69 additions and 991 deletions.
17 changes: 11 additions & 6 deletions build/shortpixel/log/src/ShortPixelLogger.php
Original file line number Diff line number Diff line change
Expand Up @@ -106,14 +106,19 @@ public function initView()

if ($this->is_active && $this->is_manual_request && $user_is_administrator )
{
$content_url = content_url();
$logPath = $this->logPath;
$pathpos = strpos($logPath, 'wp-content') + strlen('wp-content');
$logPart = substr($logPath, $pathpos);
$logLink = $content_url . $logPart;

$logPath = $this->logPath;
$uploads = wp_get_upload_dir();


if ( 0 === strpos( $logPath, $uploads['basedir'] ) ) { // Simple as it should, filepath and basedir share.
// Replace file location with url location.
$logLink = str_replace( $uploads['basedir'], $uploads['baseurl'], $logPath );
}


$this->view = new \stdClass;
$this->view->logLink = $logLink;
$this->view->logLink = 'view-source:' . esc_url($logLink);
add_action('admin_footer', array($this, 'loadView'));
}
}
Expand Down
2 changes: 1 addition & 1 deletion build/shortpixel/log/src/view-debug-box.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@

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

</div>
Expand Down
28 changes: 23 additions & 5 deletions build/shortpixel/replacer/src/Replacer.php
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ private function doReplaceQuery($base_url, $search_urls, $replace_urls)

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

if ($replaced_content !== $post_content)
{
Expand Down Expand Up @@ -311,14 +311,25 @@ private function handleMetaData($url, $search_urls, $replace_urls)
* @param $search String Search string
* @param $replace String Replacement String
* @param $in_deep Boolean. This is use to prevent serialization of sublevels. Only pass back serialized from top.
* @param $strict_check Boolean . If true, remove all classes from serialization check and fail. This should be done on post_content, not on metadata.
*/
private function replaceContent($content, $search, $replace, $in_deep = false)
private function replaceContent($content, $search, $replace, $in_deep = false, $strict_check = false)
{
//$is_serial = false;
if ( true === is_serialized($content))
{
$serialized_content = $content; // use to return content back if incomplete classes are found, prevent destroying the original information
$content = Unserialize::unserialize($content, array('allowed_classes' => false));

if (true === $strict_check)
{
$args = array('allowed_classes' => false);
}
else
{
$args = array('allowed_classes' => true);
}

$content = Unserialize::unserialize($content, $args);
// bail directly on incomplete classes. In < PHP 7.2 is_object is false on incomplete objects!
if (true === $this->checkIncomplete($content))
{
Expand Down Expand Up @@ -362,7 +373,14 @@ private function replaceContent($content, $search, $replace, $in_deep = false)
// bail directly on incomplete classes.
if (true === $this->checkIncomplete($content))
{
return $serialized_content;
// if it was serialized, return the original as not to corrupt data.
if (isset($serialized_content))
{
return $serialized_content;
}
else { // else just return the content.
return $content;
}
}
foreach($content as $key => $value)
{
Expand Down Expand Up @@ -493,7 +511,7 @@ private function findNearestSize($sizeName)
/* Check if given content is JSON format. */
private function isJSON($content)
{
if (is_array($content) || is_object($content))
if (is_array($content) || is_object($content) || is_null($content))
return false; // can never be.

$json = json_decode($content);
Expand Down
2 changes: 1 addition & 1 deletion classes/Controller/ReplaceController.php
Original file line number Diff line number Diff line change
Expand Up @@ -437,7 +437,7 @@ protected function getNewExcerpt($meta)
return $excerpt;
}

protected function getSourceUrl()
public function getSourceUrl()
{
if (function_exists('wp_get_original_image_url')) // WP 5.3+
{
Expand Down
6 changes: 4 additions & 2 deletions classes/api.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
namespace EnableMediaReplace;

use EnableMediaReplace\ShortPixelLogger\ShortPixelLogger as Log;
use EnableMediaReplace\Controller\ReplaceController as ReplaceController;


use Exception;
use stdClass;
Expand Down Expand Up @@ -74,8 +76,8 @@ public function request( array $posted_data ) {
return $result;
}

$replacer = new Replacer($attachment_id);
$url = $replacer->getSourceUrl();
$replaceController = new ReplaceController($attachment_id);
$url = $replaceController->getSourceUrl();

$settings = get_option('enable_media_replace', array()); // save settings and show last loaded.
$settings['bg_type'] = isset($_POST['background']['type']) ? sanitize_text_field($_POST['background']['type']) : false;
Expand Down
2 changes: 1 addition & 1 deletion classes/emr-plugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ public static function get()
if (Log::debugIsActive()) {
$uploaddir = wp_upload_dir(null, false, false);
if (isset($uploaddir['basedir'])) {
$log->setLogPath($uploaddir['basedir'] . "/emr_log");
$log->setLogPath( trailingslashit($uploaddir['basedir']) . "emr_log");
}
}
return self::$instance;
Expand Down
Loading

0 comments on commit 3cde582

Please sign in to comment.