*
* @copyright (c) 2016, Incsub (http://incsub.com)
*/
if ( ! class_exists( 'WpSmushBulkUi' ) ) {
/**
* Class WpSmushBulkUi
*
* Handle the UI part for the plugin.
*/
class WpSmushBulkUi {
/**
* Settings group for resize options.
*
* @var array
*/
public $resize_group = array(
'detection',
);
/**
* Settings group for full size image options.
*
* @var array
*/
public $full_size_group = array(
'backup',
);
/**
* Settings group for integration options.
*
* @var array
*/
public $intgration_group = array();
/**
* Tabs that can be shown in network admin networkwide.
*
* @var array
*/
public $network_tabs = array(
'bulk',
'integrations',
'cdn',
);
/**
* Tabs that can be shown in subsites if networkwide.
*
* @var array
*/
public $subsite_tabs = array(
'bulk',
'directory',
);
/**
* Setting tabs.
*
* @var array
*/
public $tabs = array();
/**
* Current tab.
*
* @var string
*/
public $current_tab = 'bulk';
/**
* WpSmushBulkUi constructor.
*/
public function __construct() {
add_action( 'smush_setting_column_right_inside', array( $this, 'settings_desc' ), 10, 2 );
add_action( 'smush_setting_column_right_inside', array( $this, 'image_sizes' ), 15, 2 );
add_action( 'smush_setting_column_right_inside', array( $this, 'resize_settings' ), 20, 2 );
add_action( 'smush_setting_column_right_outside', array( $this, 'full_size_options' ), 20, 2 );
add_action( 'smush_setting_column_right_outside', array( $this, 'detect_size_options' ), 25, 2 );
add_action( 'smush_settings_ui_bottom', array( $this, 'pro_features_container' ) );
// Add stats to stats box.
add_action( 'stats_ui_after_resize_savings', array( $this, 'pro_savings_stats' ), 15 );
add_action( 'stats_ui_after_resize_savings', array( $this, 'conversion_savings_stats' ), 15 );
}
/**
* Display the whole admin page ui.
*
* Load all sub sections such as stats container, settings
* bulk smush container, integrations CDN etc, under this function.
* This function directory echo the output.
*
* @return void
*/
public function ui() {
global $wp_smush, $wpsmushit_admin, $wpsmush_settings;
// Hook into integration settings.
$this->intgration_group = apply_filters( 'wp_smush_integration_settings', array() );
// Set current active tab.
$this->set_current_tab();
// If a free user, update the limits.
if ( ! $wp_smush->validate_install() ) {
// Reset transient.
$wpsmushit_admin->check_bulk_limit( true );
}
// Shared UI wrapper.
echo '
';
// Load page header.
$this->smush_page_header();
// Check if current page network admin page.
$is_network = is_network_admin();
$is_networkwide = $wpsmush_settings->settings['networkwide'];
// Show stats section only to subsite admins.
if ( ! $is_network ) {
// Show configure screen for only a new installation and for only network admins.
if ( ( '1' !== get_site_option( 'skip-smush-setup' ) && '1' !== get_option( 'wp-smush-hide_smush_welcome' ) ) && '1' !== get_option( 'hide_smush_features' ) && is_super_admin() ) {
$this->quick_setup();
}
// Show status box.
$this->smush_stats_container();
// If not a pro user.
if ( ! $wp_smush->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' );
}
}
// Start the nav bar for settings.
echo '
';
// Load the settings nav.
$this->settings_nav();
// Nonce field.
wp_nonce_field( 'save_wp_smush_options', 'wp_smush_options_nonce', '' );
// If network wide option is disabled, show only bulk page.
if ( $is_network && ! $is_networkwide ) {
// Show settings box.
$this->settings_container();
} else {
switch ( $this->current_tab ) {
case 'directory':
// Action hook to add settings to directory smush.
do_action( 'smush_directory_settings_ui' );
break;
case 'integrations':
// Show integrations box.
$this->integrations_ui();
break;
case 'cdn':
// Action hook to add settings to cdn section.
do_action( 'smush_cdn_settings_ui' );
break;
case 'bulk':
default:
// Show bulk smush box if a subsite admin.
if ( ! $is_network ) {
// Bulk smush box.
$this->bulk_smush_container();
}
if ( $is_network || ! $is_networkwide ) {
// Show settings box.
$this->settings_container();
}
break;
}
} // End if().
// Close nav bar box.
echo '
';
/**
* Action hook to add extra containers at bottom of admin UI.
*/
do_action( 'smush_admin_ui_bottom' );
// Close shared ui wrapper.
echo '
';
}
/**
* Prints the header section for a container as per the Shared UI
*
* @param string $heading Box Heading.
* @param string $sub_heading Any additional text to be shown by the side of Heading.
*
* @return string
*/
public function container_header( $heading = '', $sub_heading = '' ) {
if ( empty( $heading ) ) {
return '';
} ?>
', ''
);
// Class for bulk smush box.
$class = $wp_smush->validate_install() ? 'bulk-smush-wrapper wp-smush-pro-install' : 'bulk-smush-wrapper';
echo '
';
}
/**
* All the settings for basic and advanced users.
*
* @return void
*/
public function settings_container() {
global $wp_smush;
// Class for box.
$class = $wp_smush->validate_install() ? 'smush-settings-wrapper wp-smush-pro' : 'smush-settings-wrapper';
echo '
';
// Footer content including buttons.
$div_end = '' . esc_html__( 'Smush will automatically check for any images that need re-smushing.', 'wp-smushit' ) . '';
// Container footer.
$this->container_footer( '', $div_end );
// Close settings container.
echo '
';
/**
* Action hook to add extra containers after settings.
*/
do_action( 'smush_settings_ui_bottom' );
}
/**
* Integration settings for Smush.
*
* All integrations suhc as S3, NextGen can be added to this container.
*
* @return void
*/
public function integrations_ui() {
global $wp_smush;
// If no integration settings found, bail.
if ( empty( $this->intgration_group ) ) {
return;
}
$is_pro = $wp_smush->validate_install();
// Container box class.
$class = $is_pro ? 'smush-integrations-wrapper wp-smush-pro' : 'smush-integrations-wrapper';
echo '
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( '%1$s, you have %2$s%3$s%4$d%5$s attachment%6$s that needs re-compressing!', '%1$s, you have %2$s%3$s%4$d%5$s attachments%6$s that need re-compressing!', $count, 'wp-smushit' ), $wpsmushit_admin->get_user_name(), '', '', $count, '', '' ) . '
';
}
}
/**
* Pro features list box to show after settings.
*
* @return void
*/
public function pro_features_container() {
global $wp_smush, $wpsmush_settings, $wpsmushit_admin;
// Do not show if pro user.
if ( $wp_smush->validate_install() || ( is_network_admin() && ! $wpsmush_settings->settings['networkwide'] ) ) {
return;
}
// Upgrade url with analytics keys.
$upgrade_url = add_query_arg(
array(
'utm_source' => 'smush',
'utm_medium' => 'plugin',
'utm_campaign' => 'smush_advancedsettings_profeature_tag',
),
$wpsmushit_admin->upgrade_url
);
// Upgrade url for upsell.
$upsell_url = add_query_arg(
array(
'utm_source' => 'smush',
'utm_medium' => 'plugin',
'utm_campaign' => 'smush-advanced-settings-upsell',
),
$wpsmushit_admin->upgrade_url
);
?>
http://gifgifs.com/resizer/' ); ?>
smushed_count > 0 ? 'existing' : 'new';
update_site_option( 'wp-smush-install-type', $install_type );
}
// Prepare notice.
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 join WPMU DEV for a free 30 day trial and get access to even more features!', 'wp-smushit' );
$button_content = esc_html__( 'Try Smush Pro Free', 'wp-smushit' );
} else {
$notice_heading = esc_html__( 'Thanks for upgrading Smush!', 'wp-smushit' );
$notice_content = esc_html__( 'Did you know she has secret super powers? Yes, she can super-smush images for double the savings, store original images, and bulk smush thousands of images in one go. Get started with a free WPMU DEV trial to access these advanced features.', 'wp-smushit' );
$button_content = esc_html__( 'Try Smush Pro Free', 'wp-smushit' );
}
$upgrade_url = add_query_arg(
array(
'utm_source' => 'smush',
'utm_medium' => 'plugin',
'utm_campaign' => 'smush_dashboard_upgrade_notice',
),
$wpsmushit_admin->upgrade_url
);
?>