Skip to content

Commit

Permalink
Release version 1.0.4 (#20)
Browse files Browse the repository at this point in the history
Merge pull request #20 from resmushit/updates
  • Loading branch information
pdobrescu authored Sep 23, 2024
2 parents 46073ec + 04fec37 commit ad84fc7
Show file tree
Hide file tree
Showing 7 changed files with 84 additions and 29 deletions.
40 changes: 31 additions & 9 deletions classes/resmushit.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,12 @@ public static function authorizedExtensions() {
*/
public static function getPictureQualitySetting() {
if(get_option( 'resmushit_qlty' )) {
return apply_filters('resmushit_image_quality', get_option( 'resmushit_qlty'));
return (int) apply_filters('resmushit_image_quality', get_option( 'resmushit_qlty'));
} else {
if (!defined('RESMUSHIT_QLTY')) {
return RESMUSHIT_DEFAULT_QLTY;
return (int) RESMUSHIT_DEFAULT_QLTY;
}
return RESMUSHIT_QLTY;
return (int) RESMUSHIT_QLTY;
}
}

Expand Down Expand Up @@ -152,14 +152,25 @@ public static function revert($id, $generateThumbnails = true) {
delete_post_meta($attachment_id, 'resmushed_cumulated_original_sizes');
delete_post_meta($attachment_id, 'resmushed_cumulated_optimized_sizes');

$fs = Resmush()->fs();


$basepath = dirname(get_attached_file( $attachment_id )) . '/';
$fileInfo = pathinfo(get_attached_file( $attachment_id ));
$originalFile = $basepath . $fileInfo['filename'] . '-unsmushed.' . $fileInfo['extension'];
$backupFile = $basepath . $fileInfo['filename'] . '-unsmushed.' . $fileInfo['extension'];


$backupFileObj = $fs->getFile($backupFile);
$targetFileObj = $fs->getFile(get_attached_file( $attachment_id ));
Log::addDebug('Revert original image for : ' . str_replace(ABSPATH, '/', get_attached_file( $attachment_id )));

if(file_exists($originalFile)) {
copy($originalFile, get_attached_file( $attachment_id ));
if($backupFileObj->exists()) {
Log::addTemp('moving ' . $backupFileObj->getFullPath() . ' to ' . $targetFileObj->getFullPath() );
$res = $backupFileObj->move($targetFileObj);
}
else {
Log::addWarn('BackupFile not existing', $backupFileObj->getFullPath());
}

//Regenerate thumbnails
if($generateThumbnails) {
Expand Down Expand Up @@ -358,10 +369,10 @@ public static function getNonOptimizedPictures($id_only = FALSE){
) as ATTACHMENTS
WHERE
(ATTACHMENTS.qlty != '%s' OR ATTACHMENTS.qlty IS NULL)
( ATTACHMENTS.qlty IS NULL)
AND ATTACHMENTS.disabled IS NULL
LIMIT %d",
array('_wp_attachment_metadata','resmushed_quality','resmushed_disabled','attachment', self::getPictureQualitySetting(), self::MAX_ATTACHMENTS_REQ)
array('_wp_attachment_metadata','resmushed_quality','resmushed_disabled','attachment', self::MAX_ATTACHMENTS_REQ)
);
// Get the images in the attachement table
//
Expand Down Expand Up @@ -420,7 +431,6 @@ public static function updateDisabledState($id, $state){
//if we do not want this attachment to be resmushed.
if($state == "true"){
update_post_meta($id, 'resmushed_disabled', 'disabled');
self::revert($id);
return 'true';
} else {
delete_post_meta($id, 'resmushed_disabled');
Expand All @@ -443,6 +453,18 @@ public static function getDisabledState($attachment_id){
return false;
}

/* Of course stupid function. In due time all this doing should be replaced with an Image class, where all this informatie is normally bundled */
public static function isImageOptimized($attachment_id)
{
$optimized = get_post_meta($attachment_id, 'resmushed_cumulated_optimized_sizes', true);
if ($optimized !== false && is_numeric($optimized))
{
return true;
}

return false;
}

/**
*
* Detect unsmushed files by browsing the library directory
Expand Down
32 changes: 23 additions & 9 deletions classes/resmushitUI.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ public static function fullWidthPanelEndWrapper() {
*/
public static function headerPanel() {
//$html = "<img src='". RESMUSHIT_BASE_URL . "images/header.png' />";
$html = sprintf(esc_html__("%s By %s ShortPixel %s"), '<span class="byline">', '<a href="https://shortpixel.com/" target="_blank">', '</a></span>');
$html = sprintf(esc_html__("%s By %s ShortPixel %s", 'resmushit-image-optimizer' ), '<span class="byline">', '<a href="https://shortpixel.com/" target="_blank">', '</a></span>');
self::fullWidthPanel('reSmush.it', $html);
}

Expand Down Expand Up @@ -128,7 +128,7 @@ public static function settingsPanel() {
$new_quality_values = array(87, 80, 74, 65, 58);

if (!in_array($current_quality, $new_quality_values)) {
echo '<div class="update-nag">Please select one of the 5 new image quality settings below. Your current quality settings will be kept for previously uploaded images. If you need to set a value outside those 5 values, you can add a filter.</div>';
echo '<div class="update-nag">' . esc_html__( 'Please select one of the 5 new image quality settings below. Your current quality settings will be kept for previously uploaded images. If you need to set a value outside those 5 values, you can add a filter.', 'resmushit-image-optimizer' ) . '</div>';
}


Expand All @@ -140,9 +140,9 @@ public static function settingsPanel() {
. self::addSetting("checkbox", __("Preserve EXIF", 'resmushit-image-optimizer'), __("Activate this option to retain the original EXIF data in the images.", 'resmushit-image-optimizer'), "resmushit_preserve_exif")
. self::addSetting("checkbox", __("Deactivate backup", 'resmushit-image-optimizer'), sprintf(__("If you select this option, you choose not to keep the original version of the images. This is helpful to save disk space, but we strongly recommend having a backup of the entire website on hand. <a href='%s' title='Should I remove backups?' target='_blank'>More information</a>.", "resmushit-image-optimizer"), "https://resmush.it/why-preserving-backup-files/"), "resmushit_remove_unsmushed")
. self::addSetting("checkbox", __("Optimize images using CRON", 'resmushit-image-optimizer'), sprintf(__("Image optimization is performed automatically via CRON tasks. <a href='%s' title='How to configure Cronjobs?' target='_blank'>More information</a>", 'resmushit-image-optimizer'), 'https://resmush.it/how-to-configure-cronjobs/'), "resmushit_cron")

. self::addSetting("checkbox", __("Generate WebP/AVIF", 'resmushit-image-optimizer'), sprintf(__("Create WebP/AVIF versions of the images. %s Request access %s ", 'resmushit-image-optimizer'), '<a href="https://resmush.it/contact/" target="_blank">', '</a>'), "resmushit_webpavif")

. self::addSetting("checkbox", __("Generate WebP/AVIF", 'resmushit-image-optimizer'), sprintf(__("Create WebP/AVIF versions of the images. %s Premium Conversion Access %s ", 'resmushit-image-optimizer'), '<a href="https://shortpixel.com/compare/resmushit-vs-shortpixel" target="_blank">', '</a>'), "resmushit_webpavif")
. self::addSetting("checkbox", __("CDN Delivery", 'resmushit-image-optimizer'), sprintf(__("Deliver optimized images using our CDN. %s Get CDN Access %s ", 'resmushit-image-optimizer'), '<a href="https://shortpixel.com/compare/resmushit-vs-shortpixel" target="_blank">', '</a>'), "resmushit_webpavif")
. self::addSetting("checkbox", __("SmartCropping", 'resmushit-image-optimizer'), sprintf(__("Generate subject-centered thumbnails using ShortPixel's AI Engine. %s Get Access %s ", 'resmushit-image-optimizer'), '<a href="https://shortpixel.com/compare/resmushit-vs-shortpixel" target="_blank">', '</a>'), "resmushit_webpavif")

. self::addSetting("checkbox", __("Activate statistics", 'resmushit-image-optimizer'), __("Generates statistics about optimized images.", 'resmushit-image-optimizer'), "resmushit_statistics")
. '</table>';
Expand Down Expand Up @@ -636,6 +636,10 @@ public static function mediaListCustomValuesDisable($id, $return = false) {
if ( !preg_match("/image.*/", $post->post_mime_type) )
return;

if (reSmushit::isImageOptimized($id) === true)
{ return;
}

global $wpdb;
$query = $wpdb->prepare(
"select
Expand Down Expand Up @@ -671,23 +675,33 @@ public static function mediaListCustomValuesStatus($attachment_id, $return = fal
if ( !preg_match("/image.*/", $post->post_mime_type) )
return; //

//var_dump(reSmushit::getAttachmentQuality($attachment_id));
//var_dump(reSmushit::getPictureQualitySetting());



$current_quality = reSmushit::getAttachmentQuality($attachment_id);
$setting_quality = reSmushit::getPictureQualitySetting();

if(reSmushit::getDisabledState($attachment_id)){
$output = __('Image excluded from optimization','resmushit-image-optimizer');
}
else if(reSmushit::getAttachmentQuality($attachment_id) != reSmushit::getPictureQualitySetting())
else if(is_null($current_quality))
$output = '<button type="button" data-csrf="' . wp_create_nonce( 'single_attachment' ) . '" class="rsmt-trigger--optimize-attachment button media-button select-mode-toggle-button" name="resmushit" data-attachment-id="'. $attachment_id .'" class="button wp-smush-send">'. __('Optimize', 'resmushit-image-optimizer') .'</button>';
else{
$statistics = reSmushit::getStatistics($attachment_id);
$output = __('Reduced by', 'resmushit-image-optimizer') . " ". $statistics['total_saved_size_nice'] ." <br>(". $statistics['percent_reduction'] . ' ' . __('saved', 'resmushit-image-optimizer') . ")";

if (reSmushit::hasBackup($attachment_id)) {
$output .= '<p><button type="button" data-csrf="' . wp_create_nonce( 'single_attachment' ) . '" class="rsmt-trigger--optimize-attachment button media-button select-mode-toggle-button" name="resmushit" data-attachment-id="'. $attachment_id .'" class="button wp-smush-send">'. __('Force re-optimize', 'resmushit-image-optimizer') .'</button></p>';
$output .= '<p><button type="button" data-csrf="' . wp_create_nonce('single_attachment') . '" class="rsmt-trigger--restore-attachment button media-button select-mode-toggle-button" name="resmushit" data-attachment-id="' . $attachment_id . '" class="button wp-smush-send">' . __('Restore', 'resmushit-image-optimizer') . '</button></p>';
$output .= '<p><button type="button" data-csrf="' . wp_create_nonce('single_attachment') . '" class="rsmt-trigger--restore-attachment button media-button select-mode-toggle-button" name="resmushit" data-attachment-id="' . $attachment_id . '" class="button wp-smush-send">' .
__('Restore', 'resmushit-image-optimizer') . '</button></p>';

if ($current_quality <> $setting_quality)
{
$output .= "<div>" . sprintf(__('The optimized quality (%s) differs from the setting (%s). You can change the optimization to the current setting by clicking on "Force re-optimize". ', 'resmushit-image-optimizer'), $current_quality, $setting_quality) . '</div>';
}

}

}

if($return)
Expand Down
2 changes: 1 addition & 1 deletion css/resmush_admin.css.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

28 changes: 23 additions & 5 deletions readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ Contributors: ShortPixel, resmushit
Donate link: https://ko-fi.com/resmushit
Tags: image, optimizer, image optimization, smush, free image optimization
Requires at least: 4.0.0
Tested up to: 6.5
Requires PHP: 5.6
Stable tag: 1.0.3
Tested up to: 6.6
Requires PHP: 7.4
Stable tag: 1.0.4
License: GPLv2 or later
License URI: http://www.gnu.org/licenses/gpl-2.0.html

Expand All @@ -32,6 +32,15 @@ reSmush.it has earned the reputation of being the best free, fast and easy image
- Image statistics
- File logging for developers

**Other plugins by [ShortPixel](https://shortpixel.com):**

* [FastPixel Caching](https://wordpress.org/plugins/fastpixel-website-accelerator/) - WP Optimization made easy
* [ShortPixel Image Optimizer](https://wordpress.org/plugins/shortpixel-image-optimiser/) - Image optimization & compression for all the images on your website, including WebP & AVIF delivery
* [ShortPixel Adaptive Images](https://wordpress.org/plugins/shortpixel-adaptive-images/) - On-the-fly image optimization & CDN delivery
* [Enable Media Replace](https://wordpress.org/plugins/enable-media-replace/) - Easily replace images or files in Media Library
* [reGenerate Thumbnails Advanced](https://wordpress.org/plugins/regenerate-thumbnails-advanced/) - Easily regenerate thumbnails
* [Resize Image After Upload](https://wordpress.org/plugins/resize-image-after-upload/) - Automatically resize each uploaded image
* [WP SVG Images](https://wordpress.org/plugins/wp-svg-images/) - Secure upload of SVG files to Media Library

== Installation ==

Expand Down Expand Up @@ -65,11 +74,11 @@ Yes, you can optimize your images with cronjobs for large (and also for small) m

= Can I choose an optimization level? =

Yes, by default the optimization level is set to 82. However, you can further optimize your images by reducing the optimization level.
Yes, by default the optimization level is set to "Balanced". However, you can further optimize your images by changing the optimization level to one of the other four options.

= Can I return to my original images? =

Yes, by excluding/reverting an image, you will have your original image available again.
Yes, by restoring an image, you will have your original image available again.

= Is it possible to exclude some images from the optimizer? =

Expand All @@ -92,6 +101,15 @@ Please report security bugs found in the source code of the reSmush.it Image Opt
1. The simple interface

== Changelog ==

= 1.0.4 =
Release date September 23, 2024
* Tweak: After changing the optimization level, the plugin no longer suggests to re-optimize the entire Media Library;
* Fix: The backup files are correctly removed after restore in all situations;
* Fix: The exclusion check is hidden if the image is already optimized;
* Fix: More links without the correct namespace can now be translated;
* Fix: The texts in the settings have been improved;

= 1.0.3 =
Release date June 7, 2024
* Tweak: Added 5 compression options to choose from and a filter instead of the numeric quality selector;
Expand Down
6 changes: 3 additions & 3 deletions resmushit.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
* Plugin Name: reSmush.it Image Optimizer
* Plugin URI: https://wordpress.org/plugins/resmushit-image-optimizer/
* Description: 100% Free Image Optimizer and Compressor plugin. Fast JPEG/PNG and GIF compression.
* Version: 1.0.3
* Timestamp: 2024.03.29
* Version: 1.0.4
* Timestamp: 2024.09.23
* Author: reSmush.it
* Author URI: https://resmush.it
* Author: Charles Bourgeaux, ShortPixel
Expand All @@ -24,7 +24,7 @@

require('resmushit.inc.php');

define( 'RESMUSH_PLUGIN_VERSION', '1.0.3');
define( 'RESMUSH_PLUGIN_VERSION', '1.0.4');
define( 'RESMUSH_PLUGIN_FILE', __FILE__ );
define( 'RESMUSH_PLUGIN_PATH', plugin_dir_path(__FILE__) );

Expand Down
4 changes: 2 additions & 2 deletions resmushit.settings.php
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<?php

define('RESMUSHIT_ENDPOINT', 'http://api.resmush.it/');
define('RESMUSHIT_VERSION', '1.0.3');
define('RESMUSHIT_DEFAULT_QLTY', '82');
define('RESMUSHIT_VERSION', '1.0.4');
define('RESMUSHIT_DEFAULT_QLTY', '74');
define('RESMUSHIT_TIMEOUT', '10');
define('RESMUSHIT_NEWSFEED', 'https://feed.resmush.it/');
define('RESMUSHIT_FEEDBACK_URL', 'https://resmush.it/contact/');
Expand Down
1 change: 1 addition & 0 deletions scss/_mixins.scss
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,5 @@

}


@keyframes kofi-wiggle{0%{transform:rotate(0) scale(1)}60%{transform:rotate(0) scale(1)}75%{transform:rotate(0) scale(1.12)}80%{transform:rotate(0) scale(1.1)}84%{transform:rotate(-10deg) scale(1.1)}88%{transform:rotate(10deg) scale(1.1)}92%{transform:rotate(-10deg) scale(1.1)}96%{transform:rotate(10deg) scale(1.1)}100%{transform:rotate(0) scale(1)}}

0 comments on commit ad84fc7

Please sign in to comment.