/**
  * Returns number of images of larger than 1Mb size
  *
  * @return int
  */
 function get_exceeding_items_count()
 {
     $count = 0;
     $bulk = new WpSmushitBulk();
     $attachments = $bulk->get_attachments();
     //Check images bigger than 1Mb, used to display the count of images that can't be smushed
     foreach ($attachments as $attachment) {
         if (file_exists(get_attached_file($attachment))) {
             $size = filesize(get_attached_file($attachment));
         }
         if (empty($size) || !($size / WP_SMUSH_MAX_BYTES > 1)) {
             continue;
         }
         $count++;
     }
     return $count;
 }
 /**
  * Returns number of images of larger than 1Mb size
  *
  * @return int
  */
 function get_exceeding_items_count($force_update = false)
 {
     $count = wp_cache_get('exceeding_items', 'wp_smush');
     if (!$count || $force_update) {
         $count = 0;
         $bulk = new WpSmushitBulk();
         $attachments = $bulk->get_attachments();
         //Check images bigger than 1Mb, used to display the count of images that can't be smushed
         foreach ($attachments as $attachment) {
             if (file_exists(get_attached_file($attachment))) {
                 $size = filesize(get_attached_file($attachment));
             }
             if (empty($size) || !($size / WP_SMUSH_MAX_BYTES > 1)) {
                 continue;
             }
             $count++;
         }
         wp_cache_set('exceeding_items', $count, 'wp_smush', 3000);
     }
     return $count;
 }
        function progress_ui()
        {
            $bulk = new WpSmushitBulk();
            $total = count($bulk->get_attachments());
            $total = $total ? $total : 1;
            ?>

			<div id="progress-ui">
				<div id="smush-status" style="margin: 0 0 5px;"><?php 
            printf(__('Smushing <span id="smushed-count">1</span> of <span id="smushing-total">%d</span>', WP_SMUSHIT_DOMAIN), $total);
            ?>
</div>
				<div id="wp-smushit-progress-wrap">
					<div id="wp-smushit-smush-progress" class="wp-smushit-progressbar">
						<div></div>
					</div>
				</div>
			</div> <?php 
        }
 /**
  * Localize Translations
  */
 function localize()
 {
     global $current_screen;
     $current_page = !empty($current_screen) ? $current_screen->base : '';
     $bulk = new WpSmushitBulk();
     $handle = 'wp-smushit-admin-js';
     $wp_smush_msgs = array('resmush' => esc_html__('Super-Smush', 'wp-smushit'), 'smush_now' => esc_html__('Smush Now', 'wp-smushit'), 'error_in_bulk' => esc_html__('{{errors}} image(s) were skipped due to an error.', 'wp-smushit'), 'all_resmushed' => esc_html__('All images are fully optimised.', 'wp-smushit'), 'restore' => esc_html__("Restoring image..", "wp-smushit"), 'smushing' => esc_html__("Smushing image..", "wp-smushit"), 'checking' => esc_html__("Checking images..", "wp-smushit"));
     wp_localize_script($handle, 'wp_smush_msgs', $wp_smush_msgs);
     //Load the stats on selected screens only
     if ($current_page == 'media_page_wp-smush-bulk') {
         $this->attachments = $bulk->get_attachments();
         //Setup all the stats
         $this->setup_global_stats();
         //Localize smushit_ids variable, if there are fix number of ids
         $this->ids = !empty($_REQUEST['ids']) ? array_map('intval', explode(',', $_REQUEST['ids'])) : $this->attachments;
         //Get resmush list, If we have a resmush list already, localize those ids
         if ($resmush_ids = get_option("wp-smush-resmush-list")) {
             //get the attachments, and get lossless count
             $this->resmush_ids = $resmush_ids;
         }
         //Array of all smushed, unsmushed and lossless ids
         $data = array('count_smushed' => $this->smushed_count, 'count_total' => $this->total_count, 'unsmushed' => $this->ids, 'resmush' => $this->resmush_ids);
     } else {
         $data = array('count_smushed' => '', 'count_total' => '', 'unsmushed' => '', 'resmush' => '');
     }
     $data['timeout'] = WP_SMUSH_TIMEOUT * 1000;
     //Convert it into ms
     wp_localize_script('wp-smushit-admin-js', 'wp_smushit_data', $data);
 }
 /**
  * Localize Translations
  */
 function localize()
 {
     global $current_screen, $wpsmush_settings;
     $current_page = !empty($current_screen) ? $current_screen->base : '';
     $bulk = new WpSmushitBulk();
     $handle = 'wp-smushit-admin-js';
     $wp_smush_msgs = array('resmush' => esc_html__('Super-Smush', 'wp-smushit'), 'smush_now' => esc_html__('Smush Now', 'wp-smushit'), 'error_in_bulk' => esc_html__('{{errors}} image(s) were skipped due to an error.', 'wp-smushit'), 'all_resmushed' => esc_html__('All images are fully optimised.', 'wp-smushit'), 'restore' => esc_html__("Restoring image..", "wp-smushit"), 'smushing' => esc_html__("Smushing image..", "wp-smushit"), 'checking' => esc_html__("Checking images..", "wp-smushit"), 'membership_valid' => esc_html__("We successfully verified your membership, all the Pro features should work completely. ", "wp-smushit"), 'membership_invalid' => esc_html__("Your membership couldn't be verified.", "wp-smushit"));
     wp_localize_script($handle, 'wp_smush_msgs', $wp_smush_msgs);
     //Load the stats on selected screens only
     if ($current_page == 'media_page_wp-smush-bulk') {
         //Setup all the stats
         $this->setup_global_stats(true);
         //Get attachments if all the images are not smushed
         $this->attachments = $this->remaining_count > 0 ? $bulk->get_attachments() : array();
         //Localize smushit_ids variable, if there are fix number of ids
         $this->ids = !empty($_REQUEST['ids']) ? array_map('intval', explode(',', $_REQUEST['ids'])) : $this->attachments;
         //Get resmush list, If we have a resmush list already, localize those ids
         if ($resmush_ids = get_option("wp-smush-resmush-list")) {
             //get the attachments, and get lossless count
             $this->resmush_ids = $resmush_ids;
         }
         //Array of all smushed, unsmushed and lossless ids
         $data = array('count_smushed' => $this->smushed_count, 'count_total' => $this->total_count, 'unsmushed' => $this->ids, 'resmush' => $this->resmush_ids);
     } else {
         $data = array('count_smushed' => '', 'count_total' => '', 'unsmushed' => '', 'resmush' => '');
     }
     $data['resize_sizes'] = $this->get_max_image_dimensions();
     $data['timeout'] = WP_SMUSH_TIMEOUT * 1000;
     //Convert it into ms
     wp_localize_script('wp-smushit-admin-js', 'wp_smushit_data', $data);
     //Check if settings were changed for a multisite, and localize whether to run re-check on page load
     if (is_multisite() && get_site_option(WP_SMUSH_PREFIX . 'networkwide') && !is_network_admin()) {
         //Check the last settings stored in db
         $settings = $wpsmush_settings->get_setting(WP_SMUSH_PREFIX . 'last_settings', '');
         //Get current settings
         $c_settings = $this->get_serialised_settings();
         //If not same, Set a variable to run re-check on page load
         if ($settings != $c_settings) {
             wp_localize_script('wp-smushit-admin-js', 'wp_smush_run_re_check', array(1));
         }
     }
 }