This commit is contained in:
2024-05-20 15:37:46 +03:00
commit 00b7dbd0b7
10404 changed files with 3285853 additions and 0 deletions

View File

@@ -0,0 +1,672 @@
<?php
/**
* Bulk compress page.
*
* @since 2.9.0
* @package Smush\App\Pages
*/
namespace Smush\App\Pages;
use Smush\App\Abstract_Summary_Page;
use Smush\App\Interface_Page;
use Smush\Core\Array_Utils;
use Smush\Core\Core;
use Smush\Core\Settings;
use Smush\Core\Stats\Global_Stats;
use WP_Smush;
use Smush\Core\Backups\Backups;
if ( ! defined( 'WPINC' ) ) {
die;
}
/**
* Class Bulk
*/
class Bulk extends Abstract_Summary_Page implements Interface_Page {
/**
* Function triggered when the page is loaded before render any content.
*/
public function on_load() {
parent::on_load();
// If a free user, update the limits.
if ( ! WP_Smush::is_pro() ) {
// Reset transient.
Core::check_bulk_limit( true );
add_action( 'smush_setting_column_tag', array( $this, 'add_pro_tag' ) );
}
add_action( 'smush_setting_column_tag', array( $this, 'add_lossy_new_tag' ) );
add_action( 'smush_setting_column_right_inside', array( $this, 'settings_desc' ), 10, 2 );
add_action( 'smush_setting_column_right_inside', array( $this, 'auto_smush' ), 15, 2 );
add_action( 'smush_setting_column_right_outside', array( $this, 'image_sizes' ), 15, 2 );
add_action( 'smush_setting_column_right_additional', array( $this, 'resize_settings' ), 20 );
add_action( 'smush_setting_column_right_outside', array( $this, 'full_size_options' ), 20, 2 );
add_action( 'smush_setting_column_right_outside', array( $this, 'scale_options' ), 20, 2 );
add_action( 'wp_smush_render_setting_row', array( $this, 'set_background_email_setting_visibility' ) );
}
public function enqueue_scripts( $hook ) {
parent::enqueue_scripts( $hook );
$this->enqueue_lib_scanner_scripts();
}
protected function enqueue_lib_scanner_scripts() {
wp_enqueue_script(
'smush-library-scanner',
WP_SMUSH_URL . 'app/assets/js/smush-library-scanner.min.js',
array( 'wp-i18n' ),
WP_SMUSH_VERSION,
true
);
wp_localize_script( 'smush-library-scanner', 'mediaLibraryScan', array(
'nonce' => wp_create_nonce( 'wp_smush_media_library_scanner' ),
) );
}
/**
* Register meta boxes.
*/
public function register_meta_boxes() {
if ( ! is_network_admin() ) {
$this->add_meta_box(
'recheck-images-notice',
null,
array( $this, 'recheck_images_notice_meta_box' ),
null,
null,
'main',
array(
'box_class' => 'sui-box wp-smush-recheck-images-notice-box sui-hidden',
'box_content_class' => false,
)
);
}
parent::register_meta_boxes();
if ( ! is_network_admin() ) {
$this->add_meta_box(
'bulk',
__( 'Bulk Smush', 'wp-smushit' ),
array( $this, 'bulk_smush_metabox' ),
null,
null,
'main',
array(
'box_class' => 'sui-box bulk-smush-wrapper',
)
);
}
$class = WP_Smush::is_pro() ? 'wp-smush-pro' : '';
$this->add_meta_box(
'bulk-settings',
__( 'Settings', 'wp-smushit' ),
array( $this, 'bulk_settings_meta_box' ),
null,
array( $this, 'common_meta_box_footer' ),
'main',
array(
'box_class' => "sui-box smush-settings-wrapper {$class}",
)
);
$this->modals['restore-images'] = array();
}
/**
* Prints Dimensions required for Resizing
*
* @param string $name Setting name.
*/
public function resize_settings( $name = '' ) {
// Add only to full size settings.
if ( 'resize' !== $name ) {
return;
}
// Dimensions.
$resize_sizes = $this->settings->get_setting(
'wp-smush-resize_sizes',
array(
'width' => '',
'height' => '',
)
);
// Get max dimensions.
$max_sizes = WP_Smush::get_instance()->core()->get_max_image_dimensions();
$setting_status = $this->settings->get( 'resize' );
?>
<div tabindex="0" class="sui-toggle-content">
<div class="sui-border-frame<?php echo $setting_status ? '' : ' sui-hidden'; ?>" id="smush-resize-settings-wrap" style="margin-bottom: 10px;">
<div class="sui-row">
<div class="sui-col-md-6">
<div class="sui-form-field">
<label aria-labelledby="wp-smush-label-max-width" for="<?php echo 'wp-smush-' . esc_attr( $name ) . '_width'; ?>" class="sui-label">
<?php esc_html_e( 'Max width', 'wp-smushit' ); ?>
</label>
<input aria-required="true" type="number" class="sui-form-control wp-smush-resize-input"
aria-describedby="wp-smush-resize-note"
id="<?php echo 'wp-smush-' . esc_attr( $name ) . '_width'; ?>"
name="<?php echo 'wp-smush-' . esc_attr( $name ) . '_width'; ?>"
value="<?php echo isset( $resize_sizes['width'] ) && ! empty( $resize_sizes['width'] ) ? absint( $resize_sizes['width'] ) : 2560; ?>">
</div>
</div>
<div class="sui-col-md-6">
<div class="sui-form-field">
<label aria-labelledby="wp-smush-label-max-height" for="<?php echo 'wp-smush-' . esc_attr( $name ) . '_height'; ?>" class="sui-label">
<?php esc_html_e( 'Max height', 'wp-smushit' ); ?>
</label>
<input aria-required="true" type="number" class="sui-form-control wp-smush-resize-input"
aria-describedby="wp-smush-resize-note"
id="<?php echo 'wp-smush-' . esc_attr( $name ) . '_height'; ?>"
name="<?php echo 'wp-smush-' . esc_attr( $name ) . '_height'; ?>"
value="<?php echo isset( $resize_sizes['height'] ) && ! empty( $resize_sizes['height'] ) ? absint( $resize_sizes['height'] ) : 2560; ?>">
</div>
</div>
</div>
<div class="sui-description" id="wp-smush-resize-note">
<?php
printf( /* translators: %1$s: strong tag, %2$d: max width size, %3$s: tag, %4$d: max height size, %5$s: closing strong tag */
esc_html__( 'Currently, your largest image size is set at %1$s%2$dpx wide %3$s %4$dpx high%5$s.', 'wp-smushit' ),
'<strong>',
esc_html( $max_sizes['width'] ),
'&times;',
esc_html( $max_sizes['height'] ),
'</strong>'
);
?>
<div class="sui-notice sui-notice-info wp-smush-update-width sui-no-margin-bottom sui-hidden">
<div class="sui-notice-content">
<div class="sui-notice-message">
<i class="sui-notice-icon sui-icon-info sui-md" aria-hidden="true"></i>
<p><?php esc_html_e( "Just to let you know, the width you've entered is less than your largest image and may result in pixelation.", 'wp-smushit' ); ?></p>
</div>
</div>
</div>
<div class="sui-notice sui-notice-info wp-smush-update-height sui-no-margin-bottom sui-hidden">
<div class="sui-notice-content">
<div class="sui-notice-message">
<i class="sui-notice-icon sui-icon-info sui-md" aria-hidden="true"></i>
<p><?php esc_html_e( 'Just to let you know, the height youve entered is less than your largest image and may result in pixelation.', 'wp-smushit' ); ?></p>
</div>
</div>
</div>
</div>
</div>
<span class="sui-description">
<?php
printf( /* translators: %s: link to gifgifs.com */
esc_html__(
'Note: Image resizing happens automatically when you upload attachments. To support retina devices, we recommend using 2x the dimensions of your image size. Animated GIFs will not be resized as they will lose their animation, please use a tool such as %s to resize then re-upload.',
'wp-smushit'
),
'<a href="http://gifgifs.com/resizer/" target="_blank">http://gifgifs.com/resizer/</a>'
);
?>
</span>
</div>
<?php
}
/**
* Show additional descriptions for settings.
*
* @param string $setting_key Setting key.
*/
public function settings_desc( $setting_key = '' ) {
if ( empty( $setting_key ) || ! in_array(
$setting_key,
array( 'resize', 'original', 'strip_exif', 'png_to_jpg', 'background_email' ),
true
) ) {
return;
}
if ( 'png_to_jpg' === $setting_key ) {
?>
<div class="sui-toggle-content">
<div class="sui-notice sui-notice-info" style="margin-top: 10px">
<div class="sui-notice-content">
<div class="sui-notice-message smush-png2jpg-setting-note">
<i class="sui-notice-icon sui-icon-info sui-md" aria-hidden="true"></i>
<p>
<?php
/* translators: 1: <strong> 2: </strong> */
printf( esc_html__( 'Note: Any PNGs with transparency will be ignored. Smush will only convert PNGs if it results in a smaller file size. The original PNG file will be deleted, and the resulting file will have a new filename and extension (JPEG). %1$sAny hard-coded URLs on your site that contain the original PNG filename will need to be updated manually.%2$s', 'wp-smushit' ), '<strong>', '</strong>' ); ?>
<br/>
<span>
<?php
/* translators: 1: <strong> 2: </strong> */
printf( esc_html__( '%1$sBackup original images%2$s must be enabled if you wish to retain the original PNG image as a backup.', 'wp-smushit' ), '<strong>', '</strong>' );
?>
</span>
</p>
</div>
</div>
</div>
</div>
<?php
return;
}
global $wp_version;
?>
<span class="sui-description sui-toggle-description" id="<?php echo esc_attr( $setting_key . '-desc' ); ?>">
<?php
switch ( $setting_key ) {
case 'resize':
if ( version_compare( $wp_version, '5.2.999', '>' ) ) {
esc_html_e( 'As of WordPress 5.3, large image uploads are resized down to a specified max width and height. If you require images larger than 2560px, you can override this setting here.', 'wp-smushit' );
} else {
esc_html_e( 'Save a ton of space by not storing over-sized images on your server. Set a maximum height and width for all images uploaded to your site so that any unnecessarily large images are automatically resized before they are added to the media gallery. This setting does not apply to images smushed using Directory Smush feature.', 'wp-smushit' );
}
break;
case 'original':
esc_html_e( 'By default, WordPress will only compress the generated attachments when you upload images, not the original ones. Enable this feature to compress the original images.', 'wp-smushit' );
break;
case 'strip_exif':
esc_html_e(
'Note: This data adds to the size of the image. While this information might be important to photographers, its unnecessary for most users and safe to remove.',
'wp-smushit'
);
break;
case 'background_email':
$bg_optimization = WP_Smush::get_instance()->core()->mod->bg_optimization;
if ( $bg_optimization->can_use_background() ) {
/* translators: %s: Email address. */
$bg_email_desc = sprintf( __( 'You will receive an email at <strong>%s</strong> when the bulk smush has completed.', 'wp-smushit' ), $bg_optimization->get_mail_recipient() );
} else {
$bulk_upgrade_url = $this->get_utm_link(
array(
'utm_campaign' => 'smush_bulk_smush_BO_email_toggle',
)
);
$bg_email_desc = sprintf(
/* translators: 1: Open link tag <a>, 2: Close link tag </a> */
esc_html__( 'Get the email notification as part of the Background Optimization feature. You dont have to keep the bulk smush page open when it is in progress. Be notified when Background Optimization completes. %1$sUnlock now with Pro%2$s', 'wp-smushit' ),
'<a href="' . esc_url( $bulk_upgrade_url ) . '" class="smush-upsell-link" target="_blank">',
'</a>'
);
}
echo wp_kses_post( $bg_email_desc );
break;
default:
break;
}
?>
</span>
<?php
}
/**
* Prints notice after auto compress settings.
*
* @since 3.2.1
*
* @param string $name Setting key.
*/
public function auto_smush( $name = '' ) {
// Add only to auto smush settings.
if ( 'auto' !== $name ) {
return;
}
?>
<div class="sui-toggle-content">
<div class="sui-notice <?php echo $this->settings->get( 'auto' ) ? '' : ' sui-hidden'; ?>" style="margin-top: 10px">
<div class="sui-notice-content">
<div class="sui-notice-message">
<i class="sui-notice-icon sui-icon-info sui-md" aria-hidden="true"></i>
<p><?php esc_html_e( 'Note: We will only automatically compress the image sizes selected above.', 'wp-smushit' ); ?></p>
</div>
</div>
</div>
</div>
<?php
}
/**
* Prints all the registered image sizes, to be selected/unselected for smushing.
*
* @param string $name Setting key.
*
* @return void
*/
public function image_sizes( $name = '' ) {
// Add only to bulk smush settings.
if ( 'bulk' !== $name ) {
return;
}
// Additional image sizes.
$image_sizes = $this->settings->get_setting( 'wp-smush-image_sizes' );
$sizes = WP_Smush::get_instance()->core()->image_dimensions();
$all_selected = false === $image_sizes || count( $image_sizes ) === count( $sizes );
?>
<?php if ( ! empty( $sizes ) ) : ?>
<div class="sui-side-tabs sui-tabs">
<div data-tabs="">
<label for="all-image-sizes" class="sui-tab-item <?php echo $all_selected ? 'active' : ''; ?>">
<input type="radio" name="wp-smush-auto-image-sizes" value="all" id="all-image-sizes" <?php checked( $all_selected ); ?>>
<?php esc_html_e( 'All', 'wp-smushit' ); ?>
</label>
<label for="custom-image-sizes" class="sui-tab-item <?php echo $all_selected ? '' : 'active'; ?>">
<input type="radio" name="wp-smush-auto-image-sizes" value="custom" id="custom-image-sizes" <?php checked( $all_selected, false ); ?>>
<?php esc_html_e( 'Custom', 'wp-smushit' ); ?>
</label>
</div><!-- end data-tabs -->
<div data-panes>
<div class="sui-tab-boxed <?php echo $all_selected ? 'active' : ''; ?>" style="display:none"></div>
<div class="sui-tab-boxed <?php echo $all_selected ? '' : 'active'; ?>">
<span class="sui-label"><?php esc_html_e( 'Included image sizes', 'wp-smushit' ); ?></span>
<?php
foreach ( $sizes as $size_k => $size ) {
// If image sizes array isn't set, mark all checked ( Default Values ).
if ( false === $image_sizes ) {
$checked = true;
} else {
// WPMDUDEV hosting support: cast $size_k to string to properly work with object cache.
$checked = is_array( $image_sizes ) && in_array( (string) $size_k, $image_sizes, true );
}
?>
<label class="sui-checkbox sui-checkbox-stacked sui-checkbox-sm">
<input type="checkbox" <?php checked( $checked, true ); ?>
id="wp-smush-size-<?php echo esc_attr( $size_k ); ?>"
name="wp-smush-image_sizes[]"
value="<?php echo esc_attr( $size_k ); ?>">
<span aria-hidden="true">&nbsp;</span>
<span>
<?php if ( isset( $size['width'], $size['height'] ) ) : ?>
<?php echo esc_html( $size_k . ' (' . $size['width'] . 'x' . $size['height'] . ') ' ); ?>
<?php else : ?>
<?php echo esc_attr( $size_k ); ?>
<?php endif; ?>
</span>
</label>
<?php
}
?>
</div>
</div>
</div>
<?php endif;
}
/**
* Prints Resize, Smush Original, and Backup settings.
*
* @param string $name Name of the current setting being processed.
*/
public function full_size_options( $name = '' ) {
// Continue only if original image option.
if ( 'original' !== $name ) {
return;
}
$value = $this->settings->get( 'backup' );
?>
<div class="sui-form-field">
<label for="backup" class="sui-toggle">
<input
type="checkbox"
value="1"
id="backup"
name="backup"
aria-labelledby="backup-label"
aria-describedby="backup-desc"
<?php checked( $value, 1 ); ?>
/>
<span class="sui-toggle-slider" aria-hidden="true"></span>
<span id="backup-label" class="sui-toggle-label">
<?php echo esc_html( Settings::get_setting_data( 'backup', 'label' ) ); ?>
</span>
<span class="sui-description sui-toggle-description" id="backup-desc">
<?php echo esc_html( Settings::get_setting_data( 'backup', 'desc' ) ); ?>
</span>
</label>
<div class="sui-toggle-content <?php echo $this->settings->get( 'original' ) ? 'sui-hidden' : ''; ?>" id="backup-notice">
<div class="sui-notice" style="margin-top: 10px">
<div class="sui-notice-content">
<div class="sui-notice-message">
<i class="sui-notice-icon sui-icon-info sui-md" aria-hidden="true"></i>
<p>
<?php
printf( /* translators: %1$s - <strong>, %2$s - </strong> */
esc_html__( '%1$sCompress original images%2$s is disabled, which means that enabling %1$sBackup original images%2$s wont yield additional benefits and will use more storage space. We recommend enabling %1$sBackup original images%2$s only if %1$sCompress original images%2$s is also enabled.', 'wp-smushit' ),
'<strong>',
'</strong>'
);
?>
</p>
</div>
</div>
</div>
</div>
</div>
<?php
}
/**
* Add scale image settings.
*
* @since 3.9.1
*
* @param string $name Name of the current setting being processed.
*/
public function scale_options( $name = '' ) {
if ( 'resize' !== $name ) {
return;
}
// Not available on WordPress before 5.3.
global $wp_version;
if ( version_compare( $wp_version, '5.3', '<' ) ) {
return;
}
$value = $this->settings->get( 'no_scale' );
?>
<div class="sui-form-field">
<label for="no_scale" class="sui-toggle">
<input
type="checkbox"
value="1"
id="no_scale"
name="no_scale"
aria-labelledby="no_scale-label"
aria-describedby="no_scale-desc"
<?php checked( $value, 1 ); ?>
/>
<span class="sui-toggle-slider" aria-hidden="true"></span>
<span id="no_scale-label" class="sui-toggle-label">
<?php echo esc_html( Settings::get_setting_data( 'no_scale', 'label' ) ); ?>
</span>
<span class="sui-description sui-toggle-description" id="no_scale-desc">
<?php echo esc_html( Settings::get_setting_data( 'no_scale', 'desc' ) ); ?>
</span>
</label>
</div>
<?php
}
/**************************
* META BOXES
*/
/**
* Common footer meta box.
*
* @since 3.2.0
*/
public function common_meta_box_footer() {
$this->view( 'meta-box-footer', array(), 'common' );
}
/**
* Bulk smush meta box.
*
* Container box to handle bulk smush actions. Show progress bars,
* bulk smush action buttons etc. in this box.
*/
public function bulk_smush_metabox() {
$core = WP_Smush::get_instance()->core();
$global_stats = $core->get_global_stats();
$array_utils = new Array_Utils();
$bulk_upgrade_url = $this->get_utm_link(
array(
'utm_campaign' => 'smush_bulk_smush_complete_global',
)
);
$in_progress_upsell_url = $this->get_utm_link(
array(
'utm_campaign' => 'smush_bulk_smush_progress_BO',
)
);
$upsell_cdn_url = $this->get_utm_link(
array(
'utm_campaign' => 'smush_bulksmush_cdn',
)
);
$bg_optimization = WP_Smush::get_instance()->core()->mod->bg_optimization;
$background_processing_enabled = $bg_optimization->should_use_background();
$background_in_processing = $background_processing_enabled && $bg_optimization->is_in_processing();
if ( $bg_optimization->can_use_background() ) {
$upsell_text = '';
} else {
$upsell_text = sprintf(
/* translators: %s: Upsell Link */
__( 'Want to exit the page? Background Optimization is available with Smush Pro, allowing you to leave while Smush continues to work its magic. %s', 'wp-smushit' ),
'<a class="smush-upsell-link" target="_blank" href="' . esc_url( $in_progress_upsell_url ) . '"><strong>' . esc_html__( 'Upgrade to Pro and get 60% off', 'wp-smushit' ) . '</strong></a>'
);
}
$in_processing_notice = sprintf(
/* translators: %s: Upsell text */
__( 'Bulk Smush is currently running. Please keep this page open until the process is complete. %s', 'wp-smushit' ),
$upsell_text
);
$this->view(
'bulk/meta-box',
array(
'core' => $core,
'can_use_background' => $bg_optimization->can_use_background(),
'is_pro' => WP_Smush::is_pro(),
'unsmushed_count' => (int) $array_utils->get_array_value( $global_stats, 'count_unsmushed' ),
'resmush_count' => (int) $array_utils->get_array_value( $global_stats, 'count_resmush' ),
'remaining_count' => (int) $array_utils->get_array_value( $global_stats, 'remaining_count' ),
'total_count' => (int) $array_utils->get_array_value( $global_stats, 'count_total' ),
'bulk_upgrade_url' => $bulk_upgrade_url,
'upsell_cdn_url' => $upsell_cdn_url,
'background_processing_enabled' => $background_processing_enabled,
'background_in_processing' => $background_in_processing,
'background_in_processing_notice' => $bg_optimization->get_in_process_notice(),
'in_processing_notice' => $in_processing_notice,
)
);
}
/**
* Settings meta box.
*
* Free and pro version settings are shown in same section. For free users, pro settings won't be shown.
* To print full size smush, resize and backup in group, we hook at `smush_setting_column_right_end`.
*/
public function bulk_settings_meta_box() {
$fields = $this->settings->get_bulk_fields();
// Remove backups setting, as it's added separately.
$key = array_search( 'backup', $fields, true );
if ( false !== $key ) {
unset( $fields[ $key ] );
}
// Remove no_scale setting, as it's added separately.
$key = array_search( 'no_scale', $fields, true );
if ( false !== $key ) {
unset( $fields[ $key ] );
}
$backups = new Backups();
$backup_exists = $backups->items_with_backup_exist();
$this->view(
'bulk-settings/meta-box',
array(
'basic_features' => Settings::$basic_features,
'cdn_enabled' => $this->settings->get( 'cdn' ),
'grouped_settings' => $fields,
'settings' => $this->settings->get(),
'backup_exists' => $backup_exists,
)
);
}
/**
* Show a "new" tag near the super-smush option for free users.
*
* @since 3.10.0
* @since 3.14.0 Showing the new tag for all users after adding Ultra level.
*
* @param string $name Option name.
*
* @return void
*/
public function add_lossy_new_tag( $name ) {
if ( 'lossy' !== $name ) {
return;
}
?>
<span class="sui-tag smush-sui-tag-new"><?php esc_html_e( 'New', 'wp-smushit' ); ?></span>
<?php
}
public function add_pro_tag( $name ) {
$settings = Settings::get_instance();
if ( ! $settings->is_pro_field( $name ) || $settings->can_access_pro_field( $name ) ) {
return;
}
?>
<span class="sui-tag sui-tag-pro"><?php esc_html_e( 'Pro', 'wp-smushit' ); ?></span>
<?php
}
function set_background_email_setting_visibility( $name ) {
if ( $name !== 'background_email' ) {
return;
}
$bg_optimization = WP_Smush::get_instance()->core()->mod->bg_optimization;
$is_background_enabled = $bg_optimization->should_use_background();
if ( ! $is_background_enabled && $bg_optimization->can_use_background() ) {
?>
<style>
.background_email-settings-row {
display: none !important;
}
</style>
<?php
}
}
public function recheck_images_notice_meta_box() {
$this->view(
'recheck-images-notice',
array(),
'common'
);
}
}

View File

@@ -0,0 +1,139 @@
<?php
/**
* CDN page.
*
* @package Smush\App\Pages
*/
namespace Smush\App\Pages;
use Smush\App\Abstract_Summary_Page;
use Smush\App\Interface_Page;
use WP_Smush;
if ( ! defined( 'WPINC' ) ) {
die;
}
/**
* Class CDN
*/
class CDN extends Abstract_Summary_Page implements Interface_Page {
/**
* Register meta boxes.
*/
public function register_meta_boxes() {
parent::register_meta_boxes();
if ( ! WP_Smush::is_pro() ) {
$this->add_meta_box(
'cdn/upsell',
__( 'CDN', 'wp-smushit' )
);
return;
}
if ( ! $this->settings->get( 'cdn' ) ) {
$this->add_meta_box(
'cdn/disabled',
__( 'CDN', 'wp-smushit' ),
null,
array( $this, 'header_meta_box' )
);
return;
}
$this->add_meta_box(
'cdn',
__( 'CDN', 'wp-smushit' ),
array( $this, 'cdn_meta_box' ),
array( $this, 'header_meta_box' ),
array( $this, 'common_meta_box_footer' )
);
}
/**
* Common footer meta box.
*
* @since 3.2.0
*/
public function common_meta_box_footer() {
$this->view( 'meta-box-footer', array(), 'common' );
}
/**
* Header CDN with notification.
*
* @since 3.9.6
*/
public function header_meta_box() {
$this->view( 'cdn/meta-box-header' );
}
/**
* CDN meta box.
*
* @since 3.0
*/
public function cdn_meta_box() {
$status = WP_Smush::get_instance()->core()->mod->cdn->status();
// Available values: warning (inactive), success (active) or error (expired).
$status_msg = array(
'enabled' => __(
'Your media is currently being served from the WPMU DEV CDN. Bulk and Directory smush features are treated separately and will continue to run independently.',
'wp-smushit'
),
'disabled' => __( 'CDN is not yet active. Configure your settings below and click Activate.', 'wp-smushit' ),
'activating' => __(
'Your settings have been saved and changes are now propagating to the CDN. Changes can take up to 30 minutes to take effect but your images will continue to be served in the meantime, please be patient.',
'wp-smushit'
),
'upgrade' => sprintf(
__(
/* translators: %1$s - starting a tag, %2$s - closing a tag */
"You're almost through your CDN bandwidth limit. Please contact your administrator to upgrade your Smush CDN plan to ensure you don't lose this service. %1\$sUpgrade now%2\$s",
'wp-smushit'
),
'<a href="https://wpmudev.com/hub/account/" target="_blank">',
'</a>'
),
'overcap' => sprintf(
__(
/* translators: %1$s - starting a tag, %2$s - closing a tag */
"You've gone through your CDN bandwidth limit, so weve stopped serving your images via the CDN. Contact your administrator to upgrade your Smush CDN plan to reactivate this service. %1\$sUpgrade now%2\$s",
'wp-smushit'
),
'<a href="https://wpmudev.com/hub/account/" target="_blank">',
'</a>'
),
);
$status_color = array(
'enabled' => 'success',
'disabled' => 'error',
'activating' => 'warning',
'upgrade' => 'warning',
'overcap' => 'error',
);
// Disable CDN on staging.
if ( isset( $_SERVER['WPMUDEV_HOSTING_ENV'] ) && 'staging' === $_SERVER['WPMUDEV_HOSTING_ENV'] ) {
$status_msg['disabled'] = __( 'Your Staging environments media is currently being served from your local server. If you move your Staging files into Production, your Production environments media will automatically be served from the Smush CDN.', 'wp-smushit' );
$status_color['disabled'] = 'warning';
}
$this->view(
'cdn/meta-box',
array(
'cdn_group' => $this->settings->get_cdn_fields(),
'settings' => $this->settings->get(),
'status_msg' => $status_msg[ $status ],
'class' => $status_color[ $status ],
'status' => $status,
)
);
}
}

View File

@@ -0,0 +1,406 @@
<?php
/**
* Dashboard page class: Dashboard extends Abstract_Page.
*
* @since 3.8.6
* @package Smush\App\Pages
*/
namespace Smush\App\Pages;
use Smush\App\Abstract_Summary_Page;
use Smush\App\Interface_Page;
use Smush\Core\Array_Utils;
use Smush\Core\Resize\Resize_Optimization;
use Smush\Core\Settings;
use Smush\Core\Stats\Global_Stats;
use WP_Smush;
if ( ! defined( 'WPINC' ) ) {
die;
}
/**
* Class Dashboard
*/
class Dashboard extends Abstract_Summary_Page implements Interface_Page {
/**
* Function triggered when the page is loaded before render any content.
*/
public function on_load() {}
/**
* Enqueue scripts.
*
* @since 3.9.0
*
* @param string $hook Hook from where the call is made.
*/
public function enqueue_scripts( $hook ) {
// Scripts for Configs.
$this->enqueue_configs_scripts();
// Scripts for Tutorials.
$this->enqueue_tutorials_scripts();
}
/**
* Register meta boxes.
*/
public function register_meta_boxes() {
if ( ! is_multisite() || ( is_multisite() && ! is_network_admin() ) ) {
$this->add_meta_box(
'dashboard/summary',
null,
array( $this, 'summary_meta_box' ),
null,
null,
'summary',
array(
'box_class' => 'sui-box sui-summary sui-summary-smush-metabox',
'box_content_class' => false,
)
);
}
/**
* Meta boxes on the left side.
*/
if ( self::should_render( 'bulk' ) ) {
$this->add_meta_box(
'dashboard/bulk',
__( 'Bulk Smush', 'wp-smushit' ),
array( $this, 'bulk_compress_meta_box' ),
null,
null,
'box-dashboard-left'
);
}
if ( self::should_render( 'integrations' ) ) {
$this->add_meta_box(
'dashboard/integrations',
__( 'Integrations', 'wp-smushit' ),
array( $this, 'integrations_meta_box' ),
null,
null,
'box-dashboard-left'
);
}
if ( self::should_render( 'cdn' ) ) {
$this->add_meta_box(
'dashboard/cdn',
__( 'CDN', 'wp-smushit' ),
array( $this, 'cdn_meta_box' ),
array( $this, 'cdn_meta_box_header' ),
null,
'box-dashboard-left'
);
}
/**
* Meta boxes on the right side.
*/
if ( ! WP_Smush::is_pro() ) {
$this->add_meta_box(
'dashboard/upsell/upsell',
__( 'Smush Pro', 'wp-smushit' ),
array( $this, 'upsell_meta_box' ),
array( $this, 'upsell_meta_box_header' ),
null,
'box-dashboard-right'
);
}
if ( self::should_render( 'directory' ) ) {
$this->add_meta_box(
'dashboard/directory',
__( 'Directory Smush', 'wp-smushit' ),
array( $this, 'directory_compress_meta_box' ),
null,
null,
'box-dashboard-right'
);
}
if ( self::should_render( 'lazy_load' ) ) {
$this->add_meta_box(
'dashboard/lazy-load',
__( 'Lazy Load', 'wp-smushit' ),
array( $this, 'lazy_load_meta_box' ),
null,
null,
'box-dashboard-right'
);
}
if ( self::should_render( 'webp' ) ) {
$this->add_meta_box(
'dashboard/webp',
__( 'Local WebP', 'wp-smushit' ),
array( $this, 'local_webp_meta_box' ),
array( $this, 'local_webp_meta_box_header' ),
null,
'box-dashboard-right'
);
}
}
/**
* Summary meta box.
*
* @since 3.8.6
*/
public function summary_meta_box() {
$upsell_url_cdn = add_query_arg(
array(
'utm_source' => 'smush',
'utm_medium' => 'plugin',
'utm_campaign' => 'summary_cdn',
),
$this->upgrade_url
);
$upsell_url_webp = add_query_arg(
array(
'utm_source' => 'smush',
'utm_medium' => 'plugin',
'utm_campaign' => 'summary_local_webp',
),
$this->upgrade_url
);
$core = WP_Smush::get_instance()->core();
$array_utils = new Array_Utils();
$global_stats = $core->get_global_stats();
$args = array(
'human_bytes' => $array_utils->get_array_value( $global_stats, 'human_bytes' ),
'cdn_status' => WP_Smush::get_instance()->core()->mod->cdn->status(),
'is_cdn' => $this->settings->get( 'cdn' ),
'is_lazy_load' => $this->settings->get( 'lazy_load' ),
'is_local_webp' => $this->settings->get( 'webp_mod' ),
'resize_count' => $array_utils->get_array_value( $global_stats, 'count_resize' ),
'total_optimized' => $array_utils->get_array_value( $global_stats, 'count_images' ),
'stats_percent' => $array_utils->get_array_value( $global_stats, 'savings_percent' ),
'upsell_url_cdn' => $upsell_url_cdn,
'upsell_url_webp' => $upsell_url_webp,
'webp_configured' => true === WP_Smush::get_instance()->core()->mod->webp->is_configured(),
'percent_grade' => $array_utils->get_array_value( $global_stats, 'percent_grade' ),
'percent_metric' => $array_utils->get_array_value( $global_stats, 'percent_metric' ),
'percent_optimized' => $array_utils->get_array_value( $global_stats, 'percent_optimized' ),
);
$this->view( 'dashboard/summary-meta-box', $args );
}
/**
* Bulk compress meta box.
*
* @since 3.8.6
*/
public function bulk_compress_meta_box() {
$array_utils = new Array_Utils();
$core = WP_Smush::get_instance()->core();
$global_stats = $core->get_global_stats();
$upsell_url = add_query_arg(
array(
'utm_source' => 'smush',
'utm_medium' => 'plugin',
'utm_campaign' => 'dashboard_bulk_smush',
),
$this->upgrade_url
);
$bg_optimization = WP_Smush::get_instance()->core()->mod->bg_optimization;
$background_processing_enabled = $bg_optimization->should_use_background();
$background_in_processing = $background_processing_enabled && $bg_optimization->is_in_processing();
$args = array(
'total_count' => (int) $array_utils->get_array_value( $global_stats, 'count_total' ),
'uncompressed' => (int) $array_utils->get_array_value( $global_stats, 'remaining_count' ),
'upsell_url' => $upsell_url,
'background_processing_enabled' => $background_processing_enabled,
'background_in_processing' => $background_in_processing,
'background_in_processing_notice' => $bg_optimization->get_in_process_notice(),
);
$this->view( 'dashboard/bulk/meta-box', $args );
}
/**
* Integrations meta box.
*
* @since 3.8.6
*/
public function integrations_meta_box() {
$upsell_url = add_query_arg(
array(
'utm_source' => 'smush',
'utm_medium' => 'plugin',
'utm_campaign' => 'dashboard_integrations',
),
$this->upgrade_url
);
$integration_fields = $this->settings->get_integrations_fields();
$key = array_search( 'js_builder', $integration_fields, true );
if ( $key ) {
unset( $integration_fields[ $key ] );
}
$args = array(
'basic_features' => Settings::$basic_features,
'fields' => $integration_fields,
'is_pro' => WP_Smush::is_pro(),
'settings' => $this->settings->get(),
'upsell_url' => $upsell_url,
);
$this->view( 'dashboard/integrations-meta-box', $args );
}
/**
* Local WebP meta box.
*
* @since 3.8.6
*/
public function local_webp_meta_box() {
$upsell_url = add_query_arg(
array(
'utm_source' => 'smush',
'utm_medium' => 'plugin',
'utm_campaign' => 'smush-dashboard-local-webp-upsell',
),
$this->upgrade_url
);
$webp = WP_Smush::get_instance()->core()->mod->webp;
$args = array(
'is_configured' => $webp->get_is_configured_with_error_message(),
'is_webp_active' => $this->settings->get( 'webp_mod' ),
'upsell_url' => $upsell_url,
);
$this->view( 'dashboard/webp/meta-box', $args );
}
/**
* Local WebP meta box footer.
*
* @since 3.8.6
*/
public function local_webp_meta_box_header() {
$title = __( 'Local WebP', 'wp-smushit' );
$this->view( 'dashboard/webp/meta-box-header', compact( 'title' ) );
}
/**
* Toole meta box.
*
* @since 3.8.6
*/
public function tools_meta_box() {
$is_resize_detection = $this->settings->get( 'detection' );
$this->view( 'dashboard/tools-meta-box', compact( 'is_resize_detection' ) );
}
/**
* Directory compress meta box.
*
* @since 3.8.6
*/
public function directory_compress_meta_box() {
$images = WP_Smush::get_instance()->core()->mod->dir->get_image_errors();
$args = array(
'images' => array_slice( $images, 0, 4 ),
'errors' => WP_Smush::get_instance()->core()->mod->dir->get_image_errors_count(),
);
$this->view( 'dashboard/directory-meta-box', $args );
}
/**
* Upsell meta box.
*
* @since 3.8.6
*/
public function upsell_meta_box() {
$upsell_url = add_query_arg(
array(
'utm_source' => 'smush',
'utm_medium' => 'plugin',
'utm_campaign' => 'smush-dashboard-upsell',
),
$this->upgrade_url
);
$this->view( 'dashboard/upsell/meta-box', compact( 'upsell_url' ) );
}
/**
* Upsell meta box header.
*
* @since 3.8.6
*/
public function upsell_meta_box_header() {
$title = esc_html__( 'Smush Pro', 'wp-smushit' );
$this->view( 'dashboard/upsell/meta-box-header', compact( 'title' ) );
}
/**
* Lazy load meta box.
*
* @since 3.8.6
*/
public function lazy_load_meta_box() {
$settings = $this->settings->get_setting( 'wp-smush-lazy_load' );
$args = array(
'is_lazy_load' => $this->settings->get( 'lazy_load' ),
'media_types' => isset( $settings['format'] ) ? $settings['format'] : array(),
);
$this->view( 'dashboard/lazy-load-meta-box', $args );
}
/**
* CDN meta box.
*
* @since 3.8.6
*/
public function cdn_meta_box() {
$upsell_url = add_query_arg(
array(
'utm_source' => 'smush',
'utm_medium' => 'plugin',
'utm_campaign' => 'smush-dashboard-cdn-upsell',
),
$this->upgrade_url
);
$args = array(
'cdn_status' => WP_Smush::get_instance()->core()->mod->cdn->status(),
'is_webp' => $this->settings->get( 'webp' ),
'upsell_url' => $upsell_url,
);
$this->view( 'dashboard/cdn/meta-box', $args );
}
/**
* CDN meta box header.
*
* @since 3.8.6
*/
public function cdn_meta_box_header() {
$title = esc_html__( 'CDN', 'wp-smushit' );
$this->view( 'dashboard/cdn/meta-box-header', compact( 'title' ) );
}
}

View File

@@ -0,0 +1,187 @@
<?php
/**
* Compress directory page.
*
* @package Smush\App\Pages
*/
namespace Smush\App\Pages;
use Smush\App\Abstract_Summary_Page;
use Smush\App\Interface_Page;
use Smush\Core\Core;
use WP_Smush;
if ( ! defined( 'WPINC' ) ) {
die;
}
/**
* Class Directory
*/
class Directory extends Abstract_Summary_Page implements Interface_Page {
/**
* Register meta boxes.
*/
public function register_meta_boxes() {
parent::register_meta_boxes();
$this->add_meta_box(
'directory',
__( 'Directory Smush', 'wp-smushit' ),
array( $this, 'directory_smush_meta_box' ),
null,
null,
'main',
array(
'box_class' => 'sui-box sui-message sui-no-padding',
)
);
// Modal for the "Choose Directory" link in the summary box.
$this->modals['directory-list'] = array();
$this->modals['progress-dialog'] = array();
}
/**
* Directory Smush meta box.
*/
public function directory_smush_meta_box() {
// Reset the bulk limit transient.
if ( ! WP_Smush::is_pro() ) {
Core::check_bulk_limit( true, 'dir_sent_count' );
}
$core = WP_Smush::get_instance()->core();
$upgrade_url = add_query_arg(
array(
'utm_source' => 'smush',
'utm_medium' => 'plugin',
'utm_campaign' => 'smush_directory_smush_paused_50_limit',
),
$this->upgrade_url
);
$errors = 0;
$images = array();
$scan = filter_input( INPUT_GET, 'scan', FILTER_SANITIZE_SPECIAL_CHARS );
if ( 'done' === $scan ) {
$images = $core->mod->dir->get_image_errors();
$errors = $core->mod->dir->get_image_errors_count();
}
$this->view(
'directory/meta-box',
array(
'errors' => $errors,
'images' => $images,
'upgrade_url' => $upgrade_url,
)
);
}
/**
* Show directory smush result notice.
*
* If we are redirected from a directory smush finish page,
* show the result notice if success/fail count is available.
*
* @since 2.9.0
*/
public function smush_result_notice() {
// Get the counts from transient.
$items = (int) get_transient( 'wp-smush-show-dir-scan-notice' );
$failed_items = (int) get_transient( 'wp-smush-dir-scan-failed-items' );
$skipped_items = (int) get_transient( 'wp-smush-dir-scan-skipped-items' ); // Skipped because already optimized.
$notice_message = esc_html__( 'Image compression complete.', 'wp-smushit' ) . ' ';
$notice_class = 'error';
$total = $items + $failed_items + $skipped_items;
/**
* 1 image was successfully optimized / 10 images were successfully optimized
* 1 image was skipped because it was already optimized / 5/10 images were skipped because they were already optimized
* 1 image resulted in an error / 5/10 images resulted in an error, check the logs for more information
*
* 2/10 images were skipped because they were already optimized and 4/10 resulted in an error
*/
if ( 0 === $failed_items && 0 === $skipped_items ) {
$notice_message .= sprintf(
/* translators: %d - number of images */
_n(
'%d image was successfully optimized',
'%d images were successfully optimized',
$items,
'wp-smushit'
),
$items
);
$notice_class = 'success';
} elseif ( 0 <= $skipped_items && 0 === $failed_items ) {
$notice_message .= sprintf(
/* translators: %1$d - number of skipped images, %2$d - total number of images */
_n(
'%d image was skipped because it was already optimized',
'%1$d/%2$d images were skipped because they were already optimized',
$skipped_items,
'wp-smushit'
),
$skipped_items,
$total
);
$notice_class = 'success';
} elseif ( 0 === $skipped_items && 0 <= $failed_items ) {
$notice_message .= sprintf(
/* translators: %1$d - number of failed images, %2$d - total number of images */
_n(
'%d resulted in an error',
'%1$d/%2$d images resulted in an error, check the logs for more information',
$failed_items,
'wp-smushit'
),
$failed_items,
$total
);
} elseif ( 0 <= $skipped_items && 0 <= $failed_items ) {
$notice_message .= sprintf(
/* translators: %1$d - number of skipped images, %2$d - total number of images, %3$d - number of failed images */
esc_html__( '%1$d/%2$d images were skipped because they were already optimized and %3$d/%2$d images resulted in an error', 'wp-smushit' ),
$skipped_items,
$total,
$failed_items
);
$notice_class = 'warning';
}
// If we have counts, show the notice.
if ( 0 < $total ) {
// Delete the transients.
delete_transient( 'wp-smush-show-dir-scan-notice' );
delete_transient( 'wp-smush-dir-scan-failed-items' );
delete_transient( 'wp-smush-dir-scan-skipped-items' );
?>
<script>
document.addEventListener("DOMContentLoaded", function() {
window.SUI.openNotice(
'wp-smush-ajax-notice',
'<p><?php echo wp_kses_post( $notice_message ); ?></p>',
{
type: '<?php echo esc_attr( $notice_class ); ?>',
icon: 'info',
dismiss: {
show: true,
label: '<?php esc_html_e( 'Dismiss', 'wp-smushit' ); ?>',
tooltip: '<?php esc_html_e( 'Dismiss', 'wp-smushit' ); ?>',
},
}
);
});
</script>
<?php
}
}
}

View File

@@ -0,0 +1,92 @@
<?php
/**
* Integrations page.
*
* @package Smush\App\Pages
*/
namespace Smush\App\Pages;
use Smush\App\Abstract_Page;
use Smush\App\Interface_Page;
use Smush\Core\Settings;
use WP_Smush;
if ( ! defined( 'WPINC' ) ) {
die;
}
/**
* Class Integrations
*/
class Integrations extends Abstract_Page implements Interface_Page {
/**
* Function triggered when the page is loaded before render any content.
*/
public function on_load() {
add_action( 'smush_setting_column_right_inside', array( $this, 'settings_desc' ), 10, 2 );
}
/**
* Register meta boxes.
*/
public function register_meta_boxes() {
$class = WP_Smush::is_pro() ? 'smush-integrations-wrapper wp-smush-pro' : 'smush-integrations-wrapper';
$this->add_meta_box(
'integrations',
__( 'Integrations', 'wp-smushit' ),
array( $this, 'integrations_meta_box' ),
null,
array( $this, 'common_meta_box_footer' ),
'main',
array(
'box_class' => "sui-box {$class}",
'box_content_class' => 'sui-box-body sui-upsell-items',
)
);
}
/**
* Common footer meta box.
*
* @since 3.2.0
*/
public function common_meta_box_footer() {
$this->view( 'meta-box-footer', array(), 'common' );
}
/**
* Integrations meta box.
*
* Free and pro version settings are shown in same section. For free users, pro settings won't be shown.
* To print full size smush, resize and backup in group, we hook at `smush_setting_column_right_end`.
*/
public function integrations_meta_box() {
$this->view(
'integrations/meta-box',
array(
'basic_features' => Settings::$basic_features,
'is_pro' => WP_Smush::is_pro(),
'integration_group' => $this->settings->get_integrations_fields(),
'settings' => $this->settings->get(),
)
);
}
/**
* Show additional descriptions for settings.
*
* @param string $setting_key Setting key.
*/
public function settings_desc( $setting_key = '' ) {
if ( empty( $setting_key ) || 's3' !== $setting_key ) {
return;
}
?>
<span class="sui-description sui-toggle-description" id="s3-desc">
<?php esc_html_e( 'Note: For this process to happen automatically you need automatic smushing enabled.', 'wp-smushit' ); ?>
</span>
<?php
}
}

View File

@@ -0,0 +1,82 @@
<?php
/**
* Lazy load page.
*
* @package Smush\App\Pages
*/
namespace Smush\App\Pages;
use Smush\App\Abstract_Summary_Page;
use Smush\App\Interface_Page;
if ( ! defined( 'WPINC' ) ) {
die;
}
/**
* Class Lazy
*/
class Lazy extends Abstract_Summary_Page implements Interface_Page {
/**
* Register meta boxes.
*/
public function register_meta_boxes() {
parent::register_meta_boxes();
if ( ! $this->settings->get( 'lazy_load' ) ) {
$this->add_meta_box(
'lazyload/disabled',
__( 'Lazy Load', 'wp-smushit' ),
null,
null,
null,
'main',
array(
'box_class' => 'sui-box sui-message sui-no-padding',
)
);
return;
}
$this->add_meta_box(
'lazyload',
__( 'Lazy Load', 'wp-smushit' ),
array( $this, 'lazy_load_meta_box' ),
null,
array( $this, 'common_meta_box_footer' )
);
}
/**
* Common footer meta box.
*
* @since 3.2.0
*/
public function common_meta_box_footer() {
$this->view( 'meta-box-footer', array(), 'common' );
}
/**
* Lazy loading meta box.
*
* @since 3.2.0
*/
public function lazy_load_meta_box() {
$this->view(
'lazyload/meta-box',
array(
'conflicts' => get_transient( 'wp-smush-conflict_check' ),
'settings' => $this->settings->get_setting( 'wp-smush-lazy_load' ),
'cpts' => get_post_types( // custom post types.
array(
'public' => true,
'_builtin' => false,
),
'objects'
),
)
);
}
}

View File

@@ -0,0 +1,142 @@
<?php
/**
* NextGen admin view: Nextgen class
*
* @package Smush\App\Pages
*/
namespace Smush\App\Pages;
use Smush\App\Abstract_Page;
use Smush\App\Admin;
use WP_Smush;
if ( ! defined( 'WPINC' ) ) {
die;
}
/**
* Class Nextgen
*/
class Nextgen extends Abstract_Page {
/**
* Function triggered when the page is loaded before render any content.
*/
public function on_load() {
// Localize variables for NextGen Manage gallery page.
add_action( 'admin_enqueue_scripts', array( $this, 'enqueue' ) );
}
/**
* Render inner content.
*/
public function render_inner_content() {
$this->view( 'smush-nextgen-page' );
}
/**
* Register meta boxes.
*/
public function register_meta_boxes() {
$this->add_meta_box(
'summary',
null,
array( $this, 'dashboard_summary_metabox' ),
null,
null,
'summary',
array(
'box_class' => 'sui-box sui-summary sui-summary-smush-metabox sui-summary-smush-nextgen',
'box_content_class' => false,
)
);
$this->add_meta_box(
'bulk',
__( 'Bulk Smush', 'wp-smushit' ),
array( $this, 'bulk_metabox' ),
array( $this, 'bulk_header_metabox' ),
null,
'bulk',
array(
'box_class' => 'sui-box bulk-smush-wrapper',
)
);
}
/**
* Enqueue Scripts on Manage Gallery page
*/
public function enqueue() {
$current_screen = get_current_screen();
if ( ! empty( $current_screen ) && in_array( $current_screen->base, Admin::$plugin_pages, true ) ) {
WP_Smush::get_instance()->core()->nextgen->ng_admin->localize();
}
}
/**
* NextGen summary meta box.
*/
public function dashboard_summary_metabox() {
$ng_stats = WP_Smush::get_instance()->core()->nextgen->ng_stats;
$global_stats = $ng_stats->get_global_stats();
$lossy_enabled = $this->settings->get( 'lossy' );
$this->view(
'nextgen/summary-meta-box',
array(
'lossy_enabled' => $lossy_enabled,
'image_count' => $ng_stats->get_array_value( $global_stats, 'count_images' ),
'smushed_image_count' => $ng_stats->get_array_value( $global_stats, 'count_smushed' ),
'super_smushed_count' => $ng_stats->get_array_value( $global_stats, 'count_supersmushed' ),
'stats_human' => $ng_stats->get_array_value( $global_stats, 'human_bytes' ),
'stats_percent' => $ng_stats->get_array_value( $global_stats, 'savings_percent'),
'total_count' => $ng_stats->get_array_value( $global_stats, 'count_total' ),
'percent_grade' => $ng_stats->get_array_value( $global_stats, 'percent_grade' ),
'percent_metric' => $ng_stats->get_array_value( $global_stats, 'percent_metric' ),
'percent_optimized' => $ng_stats->get_array_value( $global_stats, 'percent_optimized' ),
)
);
}
/**
* NextGen bulk Smush header meta box.
*/
public function bulk_header_metabox() {
$this->view(
'nextgen/meta-box-header',
array(
'title' => __( 'Bulk Smush', 'wp-smushit' ),
)
);
}
/**
* NextGen bulk Smush meta box.
*/
public function bulk_metabox() {
$ng_stats = WP_Smush::get_instance()->core()->nextgen->ng_stats;
$global_stats = $ng_stats->get_global_stats();
$url = add_query_arg(
array(
'page' => 'smush#wp-smush-settings-box',
),
admin_url( 'upload.php' )
);
$this->view(
'nextgen/meta-box',
array(
'total_images_to_smush' => $ng_stats->get_array_value( $global_stats, 'remaining_count' ),
'unsmushed_count' => $ng_stats->get_array_value( $global_stats, 'count_unsmushed'),
'resmush_count' => $ng_stats->get_array_value( $global_stats, 'count_resmush'),
'total_count' => $ng_stats->get_array_value( $global_stats, 'count_total'),
'url' => $url,
)
);
}
}

View File

@@ -0,0 +1,268 @@
<?php
/**
* Settings page.
*
* @package Smush\App\Pages
*/
namespace Smush\App\Pages;
use Smush\App\Abstract_Page;
use Smush\App\Interface_Page;
use WP_Smush;
if ( ! defined( 'WPINC' ) ) {
die;
}
/**
* Class Settings
*/
class Settings extends Abstract_Page implements Interface_Page {
/**
* Function triggered when the page is loaded before render any content.
*/
public function on_load() {
// Init the tabs.
$this->tabs = apply_filters(
'smush_setting_tabs',
array(
'general' => __( 'General', 'wp-smushit' ),
'configs' => __( 'Configs', 'wp-smushit' ),
'permissions' => __( 'Permissions', 'wp-smushit' ),
'data' => __( 'Data & Settings', 'wp-smushit' ),
'accessibility' => __( 'Accessibility', 'wp-smushit' ),
)
);
// Disabled on all subsites.
if ( ! is_multisite() || ! is_network_admin() ) {
unset( $this->tabs['permissions'] );
}
add_action( 'smush_setting_column_right_inside', array( $this, 'usage_settings' ), 25, 2 );
add_action( 'smush_setting_column_right_inside', array( $this, 'detection_settings' ), 25, 2 );
}
/**
* Enqueue scripts.
*
* @since 3.9.0
*
* @param string $hook Hook from where the call is made.
*/
public function enqueue_scripts( $hook ) {
// Scripts for Configs.
$this->enqueue_configs_scripts();
}
/**
* Register meta boxes.
*/
public function register_meta_boxes() {
$this->add_meta_box(
'settings/general',
__( 'General', 'wp-smushit' ),
array( $this, 'general_meta_box' ),
null,
array( $this, 'common_meta_box_footer' ),
'general'
);
if ( is_multisite() && is_network_admin() ) {
$this->add_meta_box(
'settings/permissions',
__( 'Permissions', 'wp-smushit' ),
array( $this, 'permissions_meta_box' ),
null,
array( $this, 'common_meta_box_footer' ),
'permissions'
);
}
$this->add_meta_box(
'settings/data',
__( 'Data & Settings', 'wp-smushit' ),
array( $this, 'data_meta_box' ),
null,
array( $this, 'common_meta_box_footer' ),
'data'
);
$this->add_meta_box(
'settings/accessibility',
__( 'Accessibility', 'wp-smushit' ),
array( $this, 'accessibility_meta_box' ),
null,
array( $this, 'common_meta_box_footer' ),
'accessibility'
);
if ( 'data' === $this->get_current_tab() ) {
$this->modals['reset-settings'] = array();
}
}
/**
* Display a description in Settings - Usage Tracking.
*
* @since 3.1.0
*
* @param string $name Setting name.
*/
public function usage_settings( $name ) {
// Add only to full size settings.
if ( 'usage' !== $name ) {
return;
}
?>
<span class="sui-description sui-toggle-description">
<?php
esc_html_e( 'Note: Usage tracking is completely anonymous. We are only tracking what features you are/arent using to make our feature decisions more informed.', 'wp-smushit' );
?>
</span>
<?php
}
/**
* Display a description in Settings - Image Resize Detection.
*
* @since 3.2.1
*
* @param string $name Setting name.
*/
public function detection_settings( $name ) {
// Add only to full size settings.
if ( 'detection' !== $name ) {
return;
}
?>
<span class="sui-description sui-toggle-description">
<?php esc_html_e( 'Note: The highlighting will only be visible to administrators visitors wont see the highlighting.', 'wp-smushit' ); ?>
<?php if ( $this->settings->get( 'detection' ) ) : ?>
<?php if ( $this->settings->get( 'cdn' ) && $this->settings->get( 'auto_resize' ) ) : ?>
<div class="sui-notice smush-highlighting-notice">
<div class="sui-notice-content">
<div class="sui-notice-message">
<i class="sui-notice-icon sui-icon-info sui-md" aria-hidden="true"></i>
<p>
<?php
esc_html_e(
'Note: Images served via the Smush CDN are automatically resized to fit their containers, these will be skipped.',
'wp-smushit'
);
?>
</p>
</div>
</div>
</div>
<?php else : ?>
<div class="sui-notice sui-notice-info smush-highlighting-notice">
<div class="sui-notice-content">
<div class="sui-notice-message">
<i class="sui-notice-icon sui-icon-info sui-md" aria-hidden="true"></i>
<p>
<?php
printf(
/* translators: %1$s: opening a tag, %2$s: closing a tag */
esc_html__(
'Incorrect image size highlighting is active. %1$sView the frontend%2$s of your website to see if any images aren\'t the correct size for their containers.',
'wp-smushit'
),
'<a href="' . esc_url( home_url() ) . '" target="_blank">',
'</a>'
);
?>
</p>
</div>
</div>
</div>
<?php endif; ?>
<?php else : ?>
<div class="sui-notice sui-notice-warning smush-highlighting-warning sui-hidden">
<div class="sui-notice-content">
<div class="sui-notice-message">
<i class="sui-notice-icon sui-icon-info sui-md" aria-hidden="true"></i>
<p><?php esc_html_e( 'Almost there! To finish activating this feature you must save your settings.', 'wp-smushit' ); ?></p>
</div>
</div>
</div>
<?php endif; ?>
</span>
<?php
}
/**
* Common footer meta box.
*
* @since 3.2.0
*/
public function common_meta_box_footer() {
$this->view( 'meta-box-footer', array(), 'common' );
}
/**
* General settings meta box.
*/
public function general_meta_box() {
$link = WP_Smush::is_pro() ? 'https://wpmudev.com/translate/projects/wp-smushit/' : 'https://translate.wordpress.org/projects/wp-plugins/wp-smushit';
$site_locale = get_locale();
if ( 'en' === $site_locale || 'en_US' === $site_locale ) {
$site_language = 'English';
} else {
require_once ABSPATH . 'wp-admin/includes/translation-install.php';
$translations = wp_get_available_translations();
$site_language = isset( $translations[ $site_locale ] ) ? $translations[ $site_locale ]['native_name'] : __( 'Error detecting language', 'wp-smushit' );
}
$this->view(
'settings/general-meta-box',
array(
'detection' => $this->settings->get( 'detection' ),
'site_language' => $site_language,
'tracking' => (bool) $this->settings->get( 'usage' ),
'translation_link' => $link,
)
);
}
/**
* Permissions meta box.
*/
public function permissions_meta_box() {
$this->view(
'settings/permissions-meta-box',
array(
'networkwide' => get_site_option( 'wp-smush-networkwide' ),
)
);
}
/**
* Data & Settings meta box.
*/
public function data_meta_box() {
$this->view(
'settings/data-meta-box',
array(
'keep_data' => (bool) $this->settings->get( 'keep_data' ),
)
);
}
/**
* Accessibility meta box.
*/
public function accessibility_meta_box() {
$this->view(
'settings/accessibility-meta-box',
array(
'accessible_colors' => (bool) $this->settings->get( 'accessible_colors' ),
)
);
}
}

View File

@@ -0,0 +1,66 @@
<?php
/**
* Tutorials page
*
* @package Smush\App\Pages
*/
namespace Smush\App\Pages;
use Smush\App\Abstract_Page;
use Smush\App\Interface_Page;
if ( ! defined( 'WPINC' ) ) {
die;
}
/**
* Class Tutorials
*/
class Tutorials extends Abstract_Page implements Interface_Page {
/**
* Function triggered when the page is loaded before render any content.
*/
public function on_load() {}
/**
* Enqueue scripts.
*
* @since 3.9.0
*
* @param string $hook Hook from where the call is made.
*/
public function enqueue_scripts( $hook ) {
$this->enqueue_tutorials_scripts();
}
/**
* Render page header.
*/
public function render_page_header() {
$tutorials = add_query_arg(
array(
'utm_source' => 'smush',
'utm_medium' => 'plugin',
'utm_campaign' => 'smush_tutorials_page',
),
esc_url( 'https://wpmudev.com/blog/tutorials/tutorial-category/smush-pro/' )
);
?>
<div class="sui-header">
<h1 class="sui-header-title"><?php echo esc_html( get_admin_page_title() ); ?></h1>
<div class="sui-actions-right">
<?php if ( ! apply_filters( 'wpmudev_branding_hide_doc_link', false ) ) : ?>
<a href="<?php echo esc_url( $tutorials ); ?>" target="_blank" class="sui-button sui-button-ghost">
<span class="sui-icon-open-new-window" aria-hidden="true"></span>
<?php esc_html_e( 'View All', 'wp-smushit' ); ?>
</a>
<?php endif; ?>
</div>
</div>
<?php
}
}

View File

@@ -0,0 +1,61 @@
<?php
/**
* Smush upgrade page class: Upgrade extends Abstract_Page.
*
* @since 3.2.3
* @package Smush\App\Pages
*/
namespace Smush\App\Pages;
use Smush\App\Abstract_Page;
if ( ! defined( 'WPINC' ) ) {
die;
}
/**
* Class Upgrade
*/
class Upgrade extends Abstract_Page {
/**
* Render the page.
*/
public function render() {
?>
<div class="<?php echo $this->settings->get( 'accessible_colors' ) ? 'sui-wrap sui-color-accessible' : 'sui-wrap'; ?>">
<?php $this->render_inner_content(); ?>
</div>
<?php
}
/**
* Render inner content.
*/
public function render_inner_content() {
$this->view( 'smush-upgrade-page' );
}
/**
* On load actions.
*/
public function on_load() {
add_action(
'admin_enqueue_scripts',
function() {
wp_enqueue_script( 'smush-sui', WP_SMUSH_URL . 'app/assets/js/smush-sui.min.js', array( 'jquery', 'clipboard' ), WP_SHARED_UI_VERSION, true );
wp_enqueue_script( 'smush-wistia', '//fast.wistia.com/assets/external/E-v1.js', array(), WP_SMUSH_VERSION, true );
wp_enqueue_style( 'smush-admin', WP_SMUSH_URL . 'app/assets/css/smush-admin.min.css', array(), WP_SMUSH_VERSION );
}
);
}
/**
* Common hooks for all screens.
*/
public function add_action_hooks() {
add_filter( 'admin_body_class', array( $this, 'smush_body_classes' ) );
}
}

View File

@@ -0,0 +1,163 @@
<?php
/**
* Local WebP page.
*
* @package Smush\App\Pages
*/
namespace Smush\App\Pages;
use Smush\App\Abstract_Summary_Page;
use Smush\App\Interface_Page;
use WP_Smush;
if ( ! defined( 'WPINC' ) ) {
die;
}
/**
* Class WebP
*/
class WebP extends Abstract_Summary_Page implements Interface_Page {
/**
* Enqueue scripts.
*
* @since 3.9.0
*
* @param string $hook Hook from where the call is made.
*/
public function enqueue_scripts( $hook ) {
// We only need this script for the wizard.
if ( ! $this->is_wizard() ) {
return;
}
wp_enqueue_script(
'smush-react-webp',
WP_SMUSH_URL . 'app/assets/js/smush-react-webp.min.js',
array( 'wp-i18n', 'smush-sui', 'clipboard' ),
WP_SMUSH_VERSION,
true
);
wp_add_inline_script(
'smush-react-webp',
'wp.i18n.setLocaleData( ' . wp_json_encode( $this->get_locale_data() ) . ', "wp-smushit" );',
'before'
);
$webp = WP_Smush::get_instance()->core()->mod->webp;
// Defining this here to esc_html before using dangerouslySetInnerHTML on frontend.
$third_step_message = ! is_multisite()
? sprintf(
/* translators: 1. opening 'b' tag, 2. closing 'b' tag */
esc_html__(
'WebP versions of existing images in the Media Library can only be created by smushing the originals via the Bulk Smush page. Click %1$sConvert Now%2$s to be redirected to the Bulk Smush page to start smushing your images.',
'wp-smushit'
),
'<b>',
'</b>'
)
: sprintf(
/* translators: 1. opening 'b' tag, 2. closing 'b' tag */
esc_html__(
'WebP versions of existing images in the Media Library can only be created by smushing the originals using the %1$sBulk Smush%2$s tool on each subsite.',
'wp-smushit'
),
'<b>',
'</b>'
);
wp_localize_script(
'smush-react-webp',
'smushReact',
array(
'nonce' => wp_create_nonce( 'wp-smush-webp-nonce' ),
'isPro' => WP_Smush::is_pro(),
'detectedServer' => $webp->get_server_type(),
'apacheRules' => $webp->get_apache_code_to_print(),
'nginxRules' => $webp->get_nginx_code(),
'startStep' => true !== $webp->is_configured() || ! WP_Smush::is_pro() ? 1 : 3,
'isMultisite' => is_multisite(),
'isWpmudevHost' => isset( $_SERVER['WPMUDEV_HOSTED'] ),
'isWhitelabel' => apply_filters( 'wpmudev_branding_hide_doc_link', false ),
'isS3Enabled' => $this->settings->get( 's3' ) && ! WP_Smush::get_instance()->core()->s3->setting_status(),
'thirdStepMsg' => $third_step_message,
'urls' => array(
'bulkPage' => esc_url( admin_url( 'admin.php?page=smush-bulk' ) ),
'support' => 'https://wpmudev.com/hub2/support/#get-support',
'freeImg' => esc_url( WP_SMUSH_URL . 'app/assets/images/graphic-smush-webp-free-tier.png' ),
'freeImg2x' => esc_url( WP_SMUSH_URL . 'app/assets/images/graphic-smush-webp-free-tier@2x.png' ),
'webpDoc' => 'https://wpmudev.com/blog/local-webp-support-smush/',
'upsell' => add_query_arg(
array(
'utm_source' => 'smush',
'utm_medium' => 'plugin',
'utm_campaign' => 'smush_webp_upgrade_button',
),
$this->upgrade_url
),
),
)
);
}
/**
* Register meta boxes.
*/
public function register_meta_boxes() {
parent::register_meta_boxes();
if ( $this->is_wizard() ) {
return;
}
if ( ! $this->settings->get( 'webp_mod' ) ) {
$this->add_meta_box(
'webp/disabled',
__( 'Local WebP', 'wp-smushit' ),
null,
array( $this, 'webp_meta_box_header' )
);
return;
}
$this->add_meta_box(
'webp/webp',
__( 'Local WebP', 'wp-smushit' ),
null,
array( $this, 'webp_meta_box_header' )
);
$this->modals['webp-delete-all'] = array();
}
/**
* WebP meta box header.
*
* @since 3.8.0
*/
public function webp_meta_box_header() {
$this->view(
'webp/meta-box-header',
array(
'is_disabled' => ! $this->settings->get( 'webp_mod' ),
'is_configured' => true === WP_Smush::get_instance()->core()->mod->webp->is_configured(),
)
);
}
/**
* Whether the wizard should be displayed.
*
* @since 3.9.0
*
* @return bool
*/
protected function is_wizard() {
return ( ! WP_Smush::is_pro() || ( $this->settings->get( 'webp_mod' ) && ! get_site_option( 'wp-smush-webp_hide_wizard' ) ) );
}
}