* * @copyright (c) 2016, Incsub (http://incsub.com) */ if ( ! class_exists( 'WpSmushBulkUi' ) ) { /** * Show settings in Media settings and add column to media library * */ /** * Class WpSmushBulkUi */ class WpSmushBulkUi { /** * Prints the Header Section for a container as per the Shared UI * * @param string $classes Any additional classes that needs to be added to section * @param string $heading Box Heading * @param string $sub_heading Any additional text to be shown by the side of Heading * @param bool $dismissible If the Box is dimissible * * @return string */ function container_header( $classes = '', $id = '', $heading = '', $sub_heading = '', $dismissible = false ) { if ( empty( $heading ) ) { return ''; } echo '
'; ?>

container_header( 'wp-smush-welcome', 'wp-smush-welcome-box', esc_html__( "WELCOME", "wp-smushit" ), '', true ); //Settings Page heading $plugin_name = $WpSmush->validate_install() ? "WP Smush Pro" : "WP Smush"; ?>

', '', $plugin_name ); ?>

"; } /** * Bulk Smush UI and Progress bar */ function bulk_smush_container() { global $WpSmush; //Subheading content $smush_individual_msg = sprintf( esc_html__( "Smush individual images via your %sMedia Library%s", "wp-smushit" ), '', '' ); $class = $WpSmush->validate_install() ? 'bulk-smush-wrapper wp-smush-pro-install' : 'bulk-smush-wrapper'; //Contianer Header $this->container_header( $class, 'wp-smush-bulk-wrap-box', esc_html__( "BULK SMUSH", "wp-smushit" ), $smush_individual_msg ); ?>
bulk_smush_content(); ?>
"; } /** * All the settings for Basic and Advanced Users */ function settings_ui() { global $WpSmush; $class = $WpSmush->validate_install() ? 'smush-settings-wrapper wp-smush-pro' : 'smush-settings-wrapper'; $this->container_header( $class, 'wp-smush-settings-box', esc_html__( "SETTINGS", "wp-smushit" ), '' ); // display the options $this->options_ui(); } /** * Outputs the Smush stats for the site * @todo: Divide the function into parts, way too big * */ function smush_stats_container() { global $WpSmush, $wpsmushit_admin, $wpsmush_db, $wpsmush_settings; //@todo: Move this to Stats section, In order to have a proper count somewhere //If we have resmush list, smushed_count = totalcount - resmush count, else smushed_count $smushed_count = ( $resmush_count = count( $wpsmushit_admin->resmush_ids ) ) > 0 ? $wpsmushit_admin->total_count - ( $resmush_count + $wpsmushit_admin->remaining_count ) : $wpsmushit_admin->smushed_count; $smushed_count = $smushed_count > 0 ? $smushed_count : 0; $button = ''; $this->container_header( 'smush-stats-wrapper', 'wp-smush-stats-box', esc_html__( "STATS", "wp-smushit" ), $button ); $dasharray = 125.663706144; $dash_offset = $wpsmushit_admin->total_count > 0 ? $dasharray - ( $dasharray * ( $smushed_count / $wpsmushit_admin->total_count) ) : $dasharray; $tooltip = $wpsmushit_admin->stats['total_images'] > 0 ? 'tooltip="' . sprintf( esc_html__("You've smushed %d images in total", "wp-smushit"), $wpsmushit_admin->stats['total_images'] ) . '"' : ''; ?>
stats['total_images']; ?>

stats['human'] > 0 ? $wpsmushit_admin->stats['human'] : "0MB"; ?> / stats['percent'] > 0 ? number_format_i18n( $wpsmushit_admin->stats['percent'], 1, '.', '' ) : 0; ?>%
validate_install() && apply_filters( 'wp_smush_show_lossy_stats', true ) ) { $wpsmushit_admin->super_smushed = $wpsmush_db->super_smushed_count(); ?>
lossy_enabled ) { echo '' . intval( $wpsmushit_admin->super_smushed ) . '/' . $wpsmushit_admin->total_count; } else { printf( esc_html__( "%sENABLE SUPER-SMUSH%s", "wp-smushit" ), '' ); } ?>

stats['resize_savings'] ) && $wpsmushit_admin->stats['resize_savings'] > 0 ) { echo $wpsmushit_admin->stats['resize_savings']; }else{ if( !$wpsmush_settings->get_setting( WP_SMUSH_PREFIX . 'resize' ) ) { //If Not enabled, Add a enable button printf( esc_html__( "%sENABLE IMAGE RESIZING%s", "wp-smushit" ), '' ); }else{ printf( esc_html__( "%sNO RESIZE SAVINGS AVAILABLE%s", "wp-smushit" ), '', '' ); } } ?>
validate_install() && !empty( $wpsmushit_admin->stats['conversion_savings'] ) && $wpsmushit_admin->stats['conversion_savings'] > 0 ) { ?>
stats['conversion_savings'] > 0 ? $wpsmushit_admin->stats['conversion_savings'] : "0MB"; ?>
validate_install() ) { //Initialize pro savings if not set already if( empty( $wpsmushit_admin->stats) || empty( $wpsmushit_admin->stats['pro_savings'] ) ) { $wpsmushit_admin->set_pro_savings(); } $pro_savings = $wpsmushit_admin->stats['pro_savings']; $show_pro_savings = $pro_savings['savings'] > 0 ? true : false; //If we have any savings $upgrade_url = add_query_arg( array( 'utm_source' => 'Smush-Free', 'utm_medium' => 'Banner', 'utm_campaign'=> 'pro-only-stats' ), $wpsmushit_admin->upgrade_url ); $pro_only = sprintf( esc_html__( '%sTRY PRO FREE%s', 'wp-smushit' ), '', '' ); ?>
>
"> / %
"; } /** * Outputs the advanced settings for Pro users, Disabled for basic users by default */ function advanced_settings( $configure_screen = false ) { global $WpSmush, $wpsmushit_admin, $wpsmush_settings; //Content for the End of box container $div_end = $this->save_button( $configure_screen ); //For Basic User, Show advanced settings in a separate box if ( ! $WpSmush->validate_install() ) { echo $div_end; do_action('wp_smush_before_advanced_settings'); //Network settings wrapper if( is_multisite() && is_network_admin() ) { $class = get_site_option( WP_SMUSH_PREFIX . 'networkwide', 1 ) ? '' : ' hidden'; ?>
'Smush-Free', 'utm_medium' => 'Banner', 'utm_campaign'=> 'pro-only-advanced-settings' ), $wpsmushit_admin->upgrade_url ); $pro_only = sprintf( esc_html__( '%sTRY PRO FEATURES FREE%s', 'wp-smushit' ), '', '' ); $this->container_header( 'wp-smush-premium', 'wp-smush-pro-settings-box', esc_html__( "ADVANCED SETTINGS", "wp-smushit" ), $pro_only, false ); ?>
validate_install() ) { echo "
"; } //Iterate Over all the available settings, and print a row for each of them foreach ( $pro_settings as $setting_key ) { if ( isset( $wpsmushit_admin->settings[ $setting_key ] ) ) { $setting_m_key = WP_SMUSH_PREFIX . $setting_key; $setting_val = $WpSmush->validate_install() ? $wpsmush_settings->get_setting( $setting_m_key, false ) : 0; ?>
value="1" name="" tabindex= "0">

validate_install() ) { echo $div_end; } else { echo "
"; } //Close wrapper div if( is_multisite() && is_network_admin() && !$WpSmush->validate_install() ) { echo "
"; } } /** * Process and display the options form */ function options_ui( $configure_screen = false ) { global $wpsmushit_admin, $wpsmush_settings; echo '
'; //Get max. dimesnions $max_sizes = $wpsmushit_admin->get_max_image_dimensions(); //Placeholder width and Height $p_width = $p_height = 2048; //Use settings networkwide,@uses get_site_option() and not get_option $opt_networkwide = WP_SMUSH_PREFIX . 'networkwide'; $opt_networkwide_val = get_site_option( $opt_networkwide, true ); //Smush auto key $opt_auto = WP_SMUSH_PREFIX . 'auto'; //Auto value $opt_auto_val = $wpsmush_settings->get_setting( $opt_auto, false ); //If value is not set for auto smushing set it to 1 if ( $opt_auto_val === false ) { //default to checked $opt_auto_val = 1; } //Keep Exif $opt_keep_exif = WP_SMUSH_PREFIX . 'keep_exif'; $opt_keep_exif_val = $wpsmush_settings->get_setting( $opt_keep_exif, false ); //Resize images $opt_resize = WP_SMUSH_PREFIX . 'resize'; $opt_resize_val = $wpsmush_settings->get_setting( $opt_resize, false ); //Dimensions $resize_sizes = $wpsmush_settings->get_setting( WP_SMUSH_PREFIX . 'resize_sizes', array( 'width' => '', 'height' => '' ) ); //Additional Image sizes $image_sizes = $wpsmush_settings->get_setting( WP_SMUSH_PREFIX . 'image_sizes', false ); $sizes = $wpsmushit_admin->image_dimensions(); //Option to enable/disable networkwide settings if( is_multisite() && is_network_admin() ) { $class = get_site_option( WP_SMUSH_PREFIX . 'networkwide', 1 ) ? '' : ' hidden'; ?>
value="1" tabindex="0">

value="1" tabindex="0">

$size ) { //If image sizes array isn't set, mark all checked ( Default Values ) if ( false === $image_sizes ) { $checked = true; }else{ $checked = is_array( $image_sizes ) ? in_array( $size_k, $image_sizes ) : false; } ?>

value="1" name="" tabindex="0">

value="1" name="" tabindex="0">
', $max_sizes['width'], $max_sizes['height'], '' ); ?>
advanced_settings( $configure_screen ); } else{ echo "
"; echo $this->save_button( $configure_screen ); echo "
"; } } /** * Display the Whole page ui, Call all the other functions under this */ function ui() { global $WpSmush, $wpsmushit_admin; if( !$WpSmush->validate_install() ) { //Reset Transient $wpsmushit_admin->check_bulk_limit( true ); } $this->smush_page_header(); $is_network = is_network_admin(); if( !$is_network ) { //Show Configure screen for only a new installation and for only network admins if ( ( 1 != get_site_option( 'wp-smush-hide_smush_welcome' ) && 1 != get_option( 'wp-smush-hide_smush_welcome' ) ) && 1 != get_option( 'hide_smush_features' ) && 0 >= $wpsmushit_admin->smushed_count && is_super_admin() ) { echo '
'; $this->welcome_screen(); echo '
'; } ?>
bulk_smush_container(); ?>
smush_stats_container(); if ( ! $WpSmush->validate_install() ) { /** * Allows to Hook in Additional Containers after Stats Box for free version * Pro Version has a full width settings box, so we don't want to do it there */ do_action( 'wp_smush_after_stats_box' ); } ?>
share_widget(); ?>
settings_ui(); } do_action('smush_settings_ui_bottom'); //Validate Membership if( !$wpsmushit_admin->validate_install() ) {?>
wp_smush_promo();?>
wp_smush_hummingbird_promo(); ?>
smush_page_footer(); } /** * Pro Version */ function wp_smush_promo() { global $wpsmushit_admin; $this->container_header( 'wp-smush-pro-adv', 'wp-smush-pro-promo', "FANCY A FREE SUPER SMUSH?" ); $upgrade_url = add_query_arg( array( 'utm_source' => 'Smush-Free', 'utm_medium' => 'Banner', 'utm_campaign' => 'settings-sidebar' ), $wpsmushit_admin->upgrade_url ); ?>

You can now get Smush Pro... for FREE!

No obligation, no contracts, no catches. You'll get Smush Pro plus 100+ WPMU DEV plugins, Defender, Hummingbird & 24/7 WP support. Try it today absolutely free.

FIND OUT MORE
"; } /** * HummingBird Promo */ function wp_smush_hummingbird_promo() { //Plugin Already Installed if ( class_exists( 'WP_Hummingbird' ) ) { return; } $this->container_header( 'wp-smush-hb-adv', 'wp-smush-hb-promo', "OH YEAH, SMUSHING ON STEROIDS!" ); ?>
<?php esc_html_e( ">

Hummingbird goes beyond Smush compression with minification, caching, performance monitoring and more - every millisecond counts!

" class="button button-cta button-yellow" target="_blank">TRY HUMMINGBIRD FOR FREE
"; } /** * Outputs the Content for Bulk Smush Div */ function bulk_smush_content() { global $WpSmush, $wpsmushit_admin; $all_done = ( $wpsmushit_admin->smushed_count == $wpsmushit_admin->total_count ) && 0 == count( $wpsmushit_admin->resmush_ids ); echo $this->bulk_resmush_content(); //If there are no images in Media Library if ( 0 >= $wpsmushit_admin->total_count ) { ?> <?php esc_html_e( ">

', '' ); ?>

remaining_count > 0 ) { $class = count( $wpsmushit_admin->resmush_ids ) > 0 ? ' hidden' : ''; $upgrade_url = add_query_arg( array( 'utm_source' => 'Smush-Free', 'utm_medium' => 'Banner', 'utm_campaign' => 'yellow-bulk-smush-upsell' ), $wpsmushit_admin->upgrade_url ); ?>
remaining_count, "wp-smushit" ), $wpsmushit_admin->get_user_name(), '', '', $wpsmushit_admin->remaining_count, '', '' ); if( !$WpSmush->validate_install() ) { printf( esc_html__(" %sUpgrade to Pro%s to bulk smush all your images with one click.", "wp-smushit") , '', '' ); esc_html_e(" Free users can smush 50 images with each click.", "wp-smushit"); }?>

validate_install() && ! $WpSmush->lossy_enabled ) { ?>

progress_bar( $wpsmushit_admin ); $this->super_smush_promo(); } } /** * Content for showing Progress Bar */ function progress_bar( $count ) { //If we have resmush list, smushed_count = totalcount - resmush count, else smushed_count $smushed_count = ( $resmush_count = count( $count->resmush_ids ) ) > 0 ? ( $count->total_count - ( $count->remaining_count + $resmush_count ) ) : $count->smushed_count; // calculate %ages, avoid divide by zero error with no attachments if ( $count->total_count > 0 && $count->smushed_count > 0 ) { $smushed_pc = $smushed_count / $count->total_count * 100; } else { $smushed_pc = 0; } ?> 0 ? true : false; //Get the Actual remainaing count if ( ! isset( $wpsmushit_admin->remaining_count ) ) { $wpsmushit_admin->setup_global_stats(); } $count += $wpsmushit_admin->remaining_count; } } //Show only if we have any images to ber resmushed if ( $show ) { return '
' . sprintf( _n( "%s, you have %s%s%d%s attachment%s that needs re-compressing!", "%s, you have %s%s%d%s attachments%s that need re-compressing!", $count, "wp-smushit" ), $wpsmushit_admin->get_user_name(), '', '', $count, '', '' ) . '
'; } } /** * Displays a admin notice for settings update */ function settings_updated() { global $wpsmushit_admin, $wpsmush_settings; //Check if Networkwide settings are enabled, Do not show settings updated message if( is_multisite() && get_site_option( WP_SMUSH_PREFIX . 'networkwide', 1 ) && !is_network_admin() ) { return; } //Show Setttings Saved message if ( 1 == $wpsmush_settings->get_setting( 'wp-smush-settings_updated', false ) ) { //Default message $message = esc_html__( "Your settings have been updated!", "wp-smushit" ); //Additonal message if we got work to do! $resmush_count = is_array( $wpsmushit_admin->resmush_ids ) && count( $wpsmushit_admin->resmush_ids ) > 0; $smush_count = is_array( $wpsmushit_admin->remaining_count ) && $wpsmushit_admin->remaining_count > 0; if ( $smush_count || $resmush_count ) { $message .= ' ' . sprintf( esc_html__( "You have images that need smushing. %sBulk smush now!%s", "wp-smushit" ), '', '' ); } echo '
' . $message . '
'; //Remove the option $wpsmush_settings->delete_setting( 'wp-smush-settings_updated' ); } } /** * Prints out the page header for Bulk Smush Page */ function smush_page_header() { global $WpSmush, $wpsmushit_admin; //Include Shared UI require_once WP_SMUSH_DIR . 'assets/shared-ui/plugin-ui.php'; if( $wpsmushit_admin->remaining_count == 0 || $wpsmushit_admin->smushed_count == 0 ) { //Initialize global Stats $wpsmushit_admin->setup_global_stats(); } //Page Heading for Free and Pro Version $page_heading = $WpSmush->validate_install() ? esc_html__( 'WP Smush Pro', 'wp-smushit' ) : esc_html__( 'WP Smush', 'wp-smushit' ); $auto_smush_message = $WpSmush->is_auto_smush_enabled() ? sprintf( esc_html__( "Automatic smushing is %senabled%s. Newly uploaded images will be automagically compressed." ), '', '' ) : sprintf( esc_html__( "Automatic smushing is %sdisabled%s. Newly uploaded images will need to be manually smushed." ), '', '' ); //User API check, and display a message if not valid $user_validation = $this->get_user_validation_message(); //Re-Check images notice $recheck_notice = $this->get_recheck_message(); echo '
'; //Check if settings were updated and shoe a notice $this->settings_updated(); echo '
'; } /** * Content of the Install/ Upgrade notice based on Free or Pro version */ function installation_notice() { global $wpsmushit_admin; //Whether New/Existing Installation $install_type = get_site_option('wp-smush-install-type', false ); if( !$install_type ) { $install_type = $wpsmushit_admin->smushed_count > 0 ? 'existing' : 'new'; update_site_option( 'wp-smush-install-type', $install_type ); } if ( 'new' == $install_type ) { $notice_heading = esc_html__( "Thanks for installing Smush. We hope you like it!", "wp-smushit" ); $notice_content = esc_html__( "And hey, if you do, you can now try out Smush Pro for double the smushy goodness (benchmarked), entirely for free!", "wp-smushit" ); $button_content = esc_html__( "Try Smush Pro for Free", "wp-smushit" ); } else { $notice_heading = esc_html__( "Thanks for updating Smush. Did you know that you can now try the Smush Pro for FREE?!", "wp-smushit" ); $notice_content = '
' . esc_html__( "Yep, Super Smush your images for double the savings, save originals and batch Smush thousands of images all at once.... no charge!", "wp-smushit" ); $button_content = esc_html__( "Try Smush Pro for Free", "wp-smushit" ); } $upgrade_url = add_query_arg( array( 'utm_source' => 'Smush-Free', 'utm_medium' => 'Banner', 'utm_campaign' => 'try-pro-free' ), $wpsmushit_admin->upgrade_url );?> validate_install() ) { return; } $upgrade_url = add_query_arg( array( 'utm_source' => 'Smush-Free', 'utm_medium' => 'Banner', 'utm_campaign' => 'smush-lady-upgrade' ), $wpsmushit_admin->upgrade_url ); ?>
', '' ); ?>
'; } /** * Returns a Warning message if API key is not validated * * @return string Warning Message to be displayed on Bulk Smush Page * */ function get_user_validation_message( $notice = false ) { $notice_class = $notice ? ' notice' : ''; $wpmu_contact = sprintf( '', esc_url("https://premium.wpmudev.org/contact") ); $attr_message = esc_html__("Validating..", "wp-smushit"); $recheck_link = ''; $message = sprintf( esc_html__( "It looks like Smush couldn’t verify your WPMU DEV membership so Pro features like Super-Smush may not work correctly. If you think this is an error, run a %sre-check%s or get in touch with our %ssupport team%s.", "wp-smushit"), $recheck_link, '', $wpmu_contact, '' ) ; $content = sprintf( '
%s
', $attr_message, $message ); return $content; } /** * * @param $configure_screen * * @return string * */ function save_button( $configure_screen = false ) { $div_end = ''; //Close wrapper div if( is_multisite() && is_network_admin() ) { $div_end .= "
"; } $div_end .= '
'; //For Configuration screen we need to show the advanced settings in single box if ( ! $configure_screen ) { $div_end .= '
'; } return $div_end; } function get_recheck_message() { //Return if not multisite, or on network settings page, Netowrkwide settings is disabled if( ! is_multisite() || is_network_admin() || ! get_site_option( WP_SMUSH_PREFIX . 'networkwide' ) ) { return; } global $wpsmush_settings, $wpsmushit_admin; //Check the last settings stored in db $settings = $wpsmush_settings->get_setting( WP_SMUSH_PREFIX . 'last_settings', '' ); //Get current settings $c_settings = $wpsmushit_admin->get_serialised_settings(); //If not same, Display notice if( $settings == $c_settings ) { return; } $message = '
' . esc_html__( "Smush settings were updated, performing a quick scan to check if any of the images need to be Smushed again.", "wp-smushit") . '
'; return $message; } } }