function ewww_ngg_bulk_preview() { if (!empty($_REQUEST['doaction'])) { // if there is no requested bulk action, do nothing if (empty($_REQUEST['bulkaction'])) { return; } // if there is no media to optimize, do nothing if (empty($_REQUEST['doaction']) || !is_array($_REQUEST['doaction'])) { return; } } list($fullsize_count, $unoptimized_count, $resize_count, $unoptimized_resize_count) = ewww_image_optimizer_count_optimized('ngg'); // make sure there are some attachments to process if ($fullsize_count < 1) { echo '<p>' . esc_html__('You do not appear to have uploaded any images yet.', EWWW_IMAGE_OPTIMIZER_DOMAIN) . '</p>'; return; } ?> <div class="wrap"> <h1><?php esc_html_e('Bulk Optimize', EWWW_IMAGE_OPTIMIZER_DOMAIN); if (ewww_image_optimizer_get_option('ewww_image_optimizer_cloud_key')) { $verify_cloud = ewww_image_optimizer_cloud_verify(false); echo '<a id="ewww-bulk-credits-available" target="_blank" class="page-title-action" style="float:right;" href="https://ewww.io/my-account/">' . esc_html__('Image credits available:', EWWW_IMAGE_OPTIMIZER_DOMAIN) . ' ' . ewww_image_optimizer_cloud_quota() . '</a>'; } echo '</h1>'; // Retrieve the value of the 'bulk resume' option and set the button text for the form to use $resume = get_option('ewww_image_optimizer_bulk_ngg_resume'); if (empty($resume)) { $button_text = esc_attr__('Start optimizing', EWWW_IMAGE_OPTIMIZER_DOMAIN); } else { $button_text = esc_attr__('Resume previous bulk operation', EWWW_IMAGE_OPTIMIZER_DOMAIN); } ?> <div id="ewww-bulk-loading"></div> <div id="ewww-bulk-progressbar"></div> <div id="ewww-bulk-counter"></div> <form id="ewww-bulk-stop" style="display:none;" method="post" action=""> <br /><input type="submit" class="button-secondary action" value="<?php esc_attr_e('Stop Optimizing', EWWW_IMAGE_OPTIMIZER_DOMAIN); ?> " /> </form> <div id="ewww-bulk-widgets" class="metabox-holder" style="display:none"> <div class="meta-box-sortables"> <div id="ewww-bulk-last" class="postbox"> <button type="button" class="handlediv button-link" aria-expanded="true"> <span class="screen-reader-text"><?php esc_html_e('Click to toggle', EWWW_IMAGE_OPTIMIZER_DOMAIN); ?> </span> <span class="toggle-indicator" aria-hidden="true"></span> </button> <h2 class="hndle"><span><?php esc_html_e('Last Image Optimized', EWWW_IMAGE_OPTIMIZER_DOMAIN); ?> </span></h2> <div class="inside"></div> </div> </div> <div class="meta-box-sortables"> <div id="ewww-bulk-status" class="postbox"> <button type="button" class="handlediv button-link" aria-expanded="true"> <span class="screen-reader-text"><?php esc_html_e('Click to toggle', EWWW_IMAGE_OPTIMIZER_DOMAIN); ?> </span> <span class="toggle-indicator" aria-hidden="true"></span> </button> <h2 class="hndle"><span><?php esc_html_e('Optimization Log', EWWW_IMAGE_OPTIMIZER_DOMAIN); ?> </span></h2> <div class="inside"></div> </div> </div> </div> <form class="ewww-bulk-form"> <p><label for="ewww-force" style="font-weight: bold"><?php esc_html_e('Force re-optimize', EWWW_IMAGE_OPTIMIZER_DOMAIN); ?> </label> <input type="checkbox" id="ewww-force" name="ewww-force"></p> <p><label for="ewww-delay" style="font-weight: bold"><?php esc_html_e('Choose how long to pause between images (in seconds, 0 = disabled)', EWWW_IMAGE_OPTIMIZER_DOMAIN); ?> </label> <input type="text" id="ewww-delay" name="ewww-delay" value="<?php if ($delay = ewww_image_optimizer_get_option('ewww_image_optimizer_delay')) { echo $delay; } else { echo 0; } ?> "></p> <div id="ewww-delay-slider" style="width:50%"></div> </form> <div id="ewww-bulk-forms"> <p class="ewww-bulk-info"><?php printf(esc_html__('%1$d images have been selected (%2$d unoptimized), with %3$d resizes (%4$d unoptimized).', EWWW_IMAGE_OPTIMIZER_DOMAIN), $fullsize_count, $unoptimized_count, $resize_count, $unoptimized_resize_count); ?> <br /> <?php esc_html_e('Previously optimized images will be skipped by default.', EWWW_IMAGE_OPTIMIZER_DOMAIN); ?> </p> <form id="ewww-bulk-start" class="ewww-bulk-form" method="post" action=""> <input type="submit" class="button-secondary action" value="<?php echo $button_text; ?> " /> </form> <?php // if there is a previous bulk operation to resume, give the user the option to reset the resume flag if (!empty($resume)) { ?> <p class="ewww-bulk-info"><?php esc_html_e('If you would like to start over again, press the Reset Status button to reset the bulk operation status.', EWWW_IMAGE_OPTIMIZER_DOMAIN); ?> </p> <form id="ewww-bulk-reset" class="ewww-bulk-form" method="post" action=""> <?php wp_nonce_field('ewww-image-optimizer-bulk-reset', 'ewww_wpnonce'); ?> <input type="hidden" name="ewww_reset" value="1"> <input type="submit" class="button-secondary action" value="<?php esc_attr_e('Reset Status', EWWW_IMAGE_OPTIMIZER_DOMAIN); ?> " /> </form> <?php } echo '</div></div>'; if (ewww_image_optimizer_get_option('ewww_image_optimizer_debug')) { global $ewww_debug; echo '<div style="background-color:#ffff99;">' . $ewww_debug . '</div>'; } if (!empty($_REQUEST['ewww_inline'])) { die; } return; }
function ewww_image_optimizer_display_unoptimized_media() { global $ewww_debug; $ewww_debug .= "<b>ewww_image_optimizer_display_unoptimized_media()</b><br>"; $attachments = ewww_image_optimizer_count_optimized('media', true); echo "<div class='wrap'><h3>" . __('Unoptimized Images', EWWW_IMAGE_OPTIMIZER_DOMAIN) . "</h3>"; printf('<p>' . __('We have %d images to optimize.', EWWW_IMAGE_OPTIMIZER_DOMAIN) . '</p>', count($attachments)); if (count($attachments) != 0) { sort($attachments, SORT_NUMERIC); $image_string = implode(',', $attachments); echo '<form method="post" action="upload.php?page=ewww-image-optimizer-bulk">' . "<input type='hidden' name='ids' value='{$image_string}' />" . '<input type="submit" class="button-secondary action" value="' . __('Optimize All Images', EWWW_IMAGE_OPTIMIZER_DOMAIN) . '" />' . '</form>'; if (count($attachments) < 500) { sort($attachments, SORT_NUMERIC); $image_string = implode(',', $attachments); echo '<table class="wp-list-table widefat media" cellspacing="0"><thead><tr><th>ID</th><th> </th><th>' . __('Title', EWWW_IMAGE_OPTIMIZER_DOMAIN) . '</th><th>' . __('Image Optimizer', EWWW_IMAGE_OPTIMIZER_DOMAIN) . '</th></tr></thead>'; $alternate = true; foreach ($attachments as $ID) { $image_name = get_the_title($ID); ?> <tr<?php if ($alternate) { echo " class='alternate'"; } ?> ><td><?php echo $ID; ?> </td> <?php echo "<td style='width:80px' class='column-icon'>" . wp_get_attachment_image($ID, 'thumbnail') . "</td>"; echo "<td class='title'>{$image_name}</td>"; echo "<td>"; ewww_image_optimizer_custom_column('ewww-image-optimizer', $ID); echo "</td></tr>"; $alternate = !$alternate; } echo '</table>'; } else { echo '<p>' . __('There are too many images to display.', EWWW_IMAGE_OPTIMIZER_DOMAIN) . '</p>'; } } echo '</div>'; return; }
/** * Bulk Optimize Images * * ## OPTIONS * * <library> * : valid values are 'all' (default), 'media', 'nextgen', 'flagallery', and 'other' * : media: Media Library only * : nextgen: Nextcellent and NextGEN 2.x * : flagallery: Grand FlaGallery * : other: everything else including theme images and other specified folders * * <delay> * : optional, number of seconds to pause between images * * <force> * : optional, should the plugin re-optimize images that have already been processed. * * <reset> * : optional, start the optimizer back at the beginning instead of resuming from last position * * <noprompt> * : do not prompt, just start optimizing * * ## EXAMPLES * * wp-cli ewwwio optimize media 5 --force --reset --noprompt * * @synopsis <library> [<delay>] [--force] [--reset] [--noprompt] */ function optimize($args, $assoc_args) { global $ewww_defer; $ewww_defer = false; // because NextGEN hasn't flushed it's buffers... while (@ob_end_flush()) { } $library = $args[0]; if (empty($args[1])) { $delay = ewww_image_optimizer_get_option('ewww_image_optimizer_delay'); } else { $delay = $args[1]; } $ewww_reset = false; if (!empty($assoc_args['reset'])) { $ewww_reset = true; } if (!empty($assoc_args['force'])) { WP_CLI::line(__('Forcing re-optimization of previously processed images.', EWWW_IMAGE_OPTIMIZER_DOMAIN)); $_REQUEST['ewww_force'] = true; } WP_CLI::line(sprintf(_x('Optimizing %1$s with a %2$d second pause between images.', 'string will be something like "media" or "nextgen"', EWWW_IMAGE_OPTIMIZER_DOMAIN), $library, $delay)); // let's get started, shall we? ewww_image_optimizer_admin_init(); // and what shall we do? switch ($library) { case 'all': if ($ewww_reset) { update_option('ewww_image_optimizer_bulk_resume', ''); update_option('ewww_image_optimizer_aux_resume', ''); update_option('ewww_image_optimizer_bulk_ngg_resume', ''); update_option('ewww_image_optimizer_bulk_flag_resume', ''); WP_CLI::line(__('Bulk status has been reset, starting from the beginning.', EWWW_IMAGE_OPTIMIZER_DOMAIN)); } WP_CLI::line(__('Scanning, this could take a while', EWWW_IMAGE_OPTIMIZER_DOMAIN)); list($fullsize_count, $unoptimized_count, $resize_count, $unoptimized_resize_count) = ewww_image_optimizer_count_optimized('media'); WP_CLI::line(sprintf(__('%1$d images in the Media Library have been selected (%2$d unoptimized), with %3$d resizes (%4$d unoptimized).', EWWW_IMAGE_OPTIMIZER_DOMAIN), $fullsize_count, $unoptimized_count, $resize_count, $unoptimized_resize_count)); if (class_exists('EwwwNgg')) { global $ngg; if (preg_match('/^2/', $ngg->version)) { list($fullsize_count, $unoptimized_count, $resize_count, $unoptimized_resize_count) = ewww_image_optimizer_count_optimized('ngg'); WP_CLI::line('Nextgen: ' . sprintf(__('%1$d images have been selected (%2$d unoptimized), with %3$d resizes (%4$d unoptimized).', EWWW_IMAGE_OPTIMIZER_DOMAIN), $fullsize_count, $unoptimized_count, $resize_count, $unoptimized_resize_count)); } else { $attachments = ewww_image_optimizer_scan_next(); WP_CLI::line('Nextgen: ' . sprintf(__('We have %d images to optimize.', EWWW_IMAGE_OPTIMIZER_DOMAIN), count($attachments))); } } if (class_exists('ewwwflag')) { list($fullsize_count, $unoptimized_count, $resize_count, $unoptimized_resize_count) = ewww_image_optimizer_count_optimized('flag'); WP_CLI::line('Flagallery: ' . sprintf(__('%1$d images have been selected (%2$d unoptimized), with %3$d resizes (%4$d unoptimized).', EWWW_IMAGE_OPTIMIZER_DOMAIN), $fullsize_count, $unoptimized_count, $resize_count, $unoptimized_resize_count)); } $other_attachments = ewww_image_optimizer_scan_other(); if (empty($assoc_args['noprompt'])) { WP_CLI::confirm(sprintf(__('%1$d images in other folders need optimizing.', EWWW_IMAGE_OPTIMIZER_DOMAIN), count($other_attachments))); } ewww_image_optimizer_bulk_media($delay); if (class_exists('Ewwwngg')) { global $ngg; if (preg_match('/^2/', $ngg->version)) { ewww_image_optimizer_bulk_ngg($delay); } else { $attachments = ewww_image_optimizer_scan_next(); ewww_image_optimizer_bulk_next($delay, $attachments); } } if (class_exists('ewwwflag')) { ewww_image_optimizer_bulk_flag($delay); } ewww_image_optimizer_bulk_other($delay, $other_attachments); break; case 'media': if ($ewww_reset) { update_option('ewww_image_optimizer_bulk_resume', ''); WP_CLI::line(__('Bulk status has been reset, starting from the beginning.', EWWW_IMAGE_OPTIMIZER_DOMAIN)); } list($fullsize_count, $unoptimized_count, $resize_count, $unoptimized_resize_count) = ewww_image_optimizer_count_optimized('media'); if (empty($assoc_args['noprompt'])) { WP_CLI::confirm(sprintf(__('%1$d images in the Media Library have been selected (%2$d unoptimized), with %3$d resizes (%4$d unoptimized).', EWWW_IMAGE_OPTIMIZER_DOMAIN), $fullsize_count, $unoptimized_count, $resize_count, $unoptimized_resize_count)); } ewww_image_optimizer_bulk_media($delay); break; case 'nextgen': if ($ewww_reset) { update_option('ewww_image_optimizer_bulk_ngg_resume', ''); WP_CLI::line(__('Bulk status has been reset, starting from the beginning.', EWWW_IMAGE_OPTIMIZER_DOMAIN)); } if (class_exists('EwwwNgg')) { global $ngg; if (preg_match('/^2/', $ngg->version)) { list($fullsize_count, $unoptimized_count, $resize_count, $unoptimized_resize_count) = ewww_image_optimizer_count_optimized('ngg'); if (empty($assoc_args['noprompt'])) { WP_CLI::confirm(sprintf(__('%1$d images have been selected (%2$d unoptimized), with %3$d resizes (%4$d unoptimized).', EWWW_IMAGE_OPTIMIZER_DOMAIN), $fullsize_count, $unoptimized_count, $resize_count, $unoptimized_resize_count)); } ewww_image_optimizer_bulk_ngg($delay); } else { $attachments = ewww_image_optimizer_scan_next(); if (empty($assoc_args['noprompt'])) { WP_CLI::confirm(sprintf(__('We have %d images to optimize.', EWWW_IMAGE_OPTIMIZER_DOMAIN), count($attachments))); } ewww_image_optimizer_bulk_next($delay, $attachments); } } else { WP_CLI::error(__('NextGEN/Nextcellent not installed.', EWWW_IMAGE_OPTIMIZER_DOMAIN)); } break; case 'flagallery': if ($ewww_reset) { update_option('ewww_image_optimizer_bulk_flag_resume', ''); WP_CLI::line(__('Bulk status has been reset, starting from the beginning.', EWWW_IMAGE_OPTIMIZER_DOMAIN)); } if (class_exists('ewwwflag')) { list($fullsize_count, $unoptimized_count, $resize_count, $unoptimized_resize_count) = ewww_image_optimizer_count_optimized('flag'); if (empty($assoc_args['noprompt'])) { WP_CLI::confirm(sprintf(__('%1$d images have been selected (%2$d unoptimized), with %3$d resizes (%4$d unoptimized).', EWWW_IMAGE_OPTIMIZER_DOMAIN), $fullsize_count, $unoptimized_count, $resize_count, $unoptimized_resize_count)); } ewww_image_optimizer_bulk_flag($delay); } else { WP_CLI::error(__('Grand Flagallery not installed.', EWWW_IMAGE_OPTIMIZER_DOMAIN)); } break; case 'other': if ($ewww_reset) { update_option('ewww_image_optimizer_aux_resume', ''); WP_CLI::line(__('Bulk status has been reset, starting from the beginning.', EWWW_IMAGE_OPTIMIZER_DOMAIN)); } WP_CLI::line(__('Scanning, this could take a while', EWWW_IMAGE_OPTIMIZER_DOMAIN)); $other_attachments = ewww_image_optimizer_scan_other(); if (empty($assoc_args['noprompt'])) { WP_CLI::confirm(sprintf(__('%1$d images in other folders need optimizing.', EWWW_IMAGE_OPTIMIZER_DOMAIN), count($other_attachments))); } ewww_image_optimizer_bulk_other($delay, $other_attachments); break; default: if ($ewww_reset) { update_option('ewww_image_optimizer_bulk_resume', ''); update_option('ewww_image_optimizer_aux_resume', ''); update_option('ewww_image_optimizer_bulk_ngg_resume', ''); update_option('ewww_image_optimizer_bulk_flag_resume', ''); WP_CLI::success(__('Bulk status has been reset, the next bulk operation will start from the beginning.', EWWW_IMAGE_OPTIMIZER_DOMAIN)); } else { WP_CLI::line(__('Please specify a valid library option, see "wp-cli help ewwwio optimize" for more information.', EWWW_IMAGE_OPTIMIZER_DOMAIN)); } } }
function ewww_flag_bulk() { // if there is POST data, make sure bulkaction and doaction are the values we want if (!empty($_POST) && empty($_REQUEST['reset'])) { // if there is no requested bulk action, do nothing if (empty($_REQUEST['bulkaction'])) { return; } // if there is no media to optimize, do nothing if (empty($_REQUEST['doaction']) || !is_array($_REQUEST['doaction'])) { return; } if (!preg_match('/^bulk_optimize/', $_REQUEST['bulkaction'])) { return; } } list($fullsize_count, $unoptimized_count, $resize_count, $unoptimized_resize_count) = ewww_image_optimizer_count_optimized('flag'); // bail-out if there aren't any images to optimize if ($fullsize_count < 1) { echo '<p>' . __('You do not appear to have uploaded any images yet.', EWWW_IMAGE_OPTIMIZER_DOMAIN) . '</p>'; return; } ewww_image_optimizer_cloud_verify(false); ?> <div class="wrap"><div id="icon-upload" class="icon32"></div><h2>GRAND FlAGallery <?php _e('Bulk Optimize', EWWW_IMAGE_OPTIMIZER_DOMAIN); ?> </h2> <?php // Retrieve the value of the 'bulk resume' option and set the button text for the form to use $resume = get_option('ewww_image_optimizer_bulk_flag_resume'); if (empty($resume)) { $button_text = __('Start optimizing', EWWW_IMAGE_OPTIMIZER_DOMAIN); } else { $button_text = __('Resume previous bulk operation', EWWW_IMAGE_OPTIMIZER_DOMAIN); } ?> <div id="bulk-loading"></div> <div id="bulk-progressbar"></div> <div id="bulk-counter"></div> <form id="bulk-stop" style="display:none;" method="post" action=""> <br /><input type="submit" class="button-secondary action" value="<?php _e('Stop Optimizing', EWWW_IMAGE_OPTIMIZER_DOMAIN); ?> " /> </form> <div id="bulk-status"></div> <form class="bulk-form"> <p><label for="ewww-force" style="font-weight: bold"><?php _e('Force re-optimize', EWWW_IMAGE_OPTIMIZER_DOMAIN); ?> </label> <input type="checkbox" id="ewww-force" name="ewww-force"></p> <p><label for="ewww-delay" style="font-weight: bold"><?php _e('Choose how long to pause between images (in seconds, 0 = disabled)', EWWW_IMAGE_OPTIMIZER_DOMAIN); ?> </label> <input type="text" id="ewww-delay" name="ewww-delay" value="<?php if ($delay = ewww_image_optimizer_get_option('ewww_image_optimizer_delay')) { echo $delay; } else { echo 0; } ?> "></p> <div id="ewww-delay-slider" style="width:50%"></div> <!-- <p><label for="ewww-interval" style="font-weight: bold"><?php _e('Choose how many images should be processed before each delay', EWWW_IMAGE_OPTIMIZER_DOMAIN); ?> </label> <input type="text" id="ewww-interval" name="ewww-interval" value="<?php if ($interval = ewww_image_optimizer_get_option('ewww_image_optimizer_interval')) { echo $interval; } else { echo 1; } ?> "></p> <div id="ewww-interval-slider" style="width:50%"></div>--> </form> <div id="bulk-forms"> <p class="bulk-info"><?php printf(__('%1$d images have been selected (%2$d unoptimized), with %3$d resizes (%4$d unoptimized).', EWWW_IMAGE_OPTIMIZER_DOMAIN), $fullsize_count, $unoptimized_count, $resize_count, $unoptimized_resize_count); ?> <br /> <?php _e('Previously optimized images will be skipped by default.', EWWW_IMAGE_OPTIMIZER_DOMAIN); ?> </p> <form id="bulk-start" class="bulk-form" method="post" action=""> <input type="submit" class="button-secondary action" value="<?php echo $button_text; ?> " /> </form> <?php // if there was a previous operation, offer the option to reset the option in the db if (!empty($resume)) { ?> <p class="bulk-info"><?php _e('If you would like to start over again, press the Reset Status button to reset the bulk operation status.', EWWW_IMAGE_OPTIMIZER_DOMAIN); ?> </p> <form method="post" class="bulk-form" action=""> <?php wp_nonce_field('ewww-image-optimizer-bulk', '_wpnonce'); ?> <input type="hidden" name="reset" value="1"> <button id="bulk-reset" type="submit" class="button-secondary action"><?php _e('Reset Status', EWWW_IMAGE_OPTIMIZER_DOMAIN); ?> </button> </form> <?php } echo '</div></div>'; }
function ewww_image_optimizer_bulk_preview() { global $ewww_debug; $ewww_debug .= "<b>ewww_image_optimizer_bulk_preview()</b><br>"; // retrieve the attachment IDs that were pre-loaded in the database list($fullsize_count, $unoptimized_count, $resize_count, $unoptimized_resize_count) = ewww_image_optimizer_count_optimized('media'); // $upload_import = get_option('ewww_image_optimizer_imported'); $upload_import = true; ?> <div class="wrap"> <div id="icon-upload" class="icon32"><br /></div><h2><?php _e('Bulk Optimize', EWWW_IMAGE_OPTIMIZER_DOMAIN); ?> </h2> <?php // Retrieve the value of the 'bulk resume' option and set the button text for the form to use $resume = get_option('ewww_image_optimizer_bulk_resume'); if (empty($resume)) { $button_text = __('Start optimizing', EWWW_IMAGE_OPTIMIZER_DOMAIN); } else { $button_text = __('Resume previous bulk operation', EWWW_IMAGE_OPTIMIZER_DOMAIN); } $loading_image = plugins_url('/wpspin.gif', __FILE__); // create the html for the bulk optimize form and status divs ?> <div id="ewww-bulk-loading"> <p id="ewww-loading" class="ewww-bulk-info" style="display:none"><?php _e('Importing', EWWW_IMAGE_OPTIMIZER_DOMAIN); ?> <img src='<?php echo $loading_image; ?> ' /></p> </div> <div id="ewww-bulk-progressbar"></div> <div id="ewww-bulk-counter"></div> <form id="ewww-bulk-stop" style="display:none;" method="post" action=""> <br /><input type="submit" class="button-secondary action" value="<?php _e('Stop Optimizing', EWWW_IMAGE_OPTIMIZER_DOMAIN); ?> " /> </form> <div id="ewww-bulk-status"></div> <?php if (empty($upload_import)) { ?> <p class="ewww-bulk-info"><?php _e('You should import Media Library images into the table to prevent duplicate optimization.', EWWW_IMAGE_OPTIMIZER_DOMAIN); ?> </p> <form id="import-start" class="bulk-form" method="post" action=""> <input type="submit" class="button-secondary action" value="<?php _e('Import Images', EWWW_IMAGE_OPTIMIZER_DOMAIN); ?> " /> </form> </div> <?php return; } ?> <form class="ewww-bulk-form"> <p><label for="ewww-force" style="font-weight: bold"><?php _e('Force re-optimize', EWWW_IMAGE_OPTIMIZER_DOMAIN); ?> </label> <input type="checkbox" id="ewww-force" name="ewww-force"></p> <p><label for="ewww-delay" style="font-weight: bold"><?php _e('Choose how long to pause between images (in seconds, 0 = disabled)', EWWW_IMAGE_OPTIMIZER_DOMAIN); ?> </label> <input type="text" id="ewww-delay" name="ewww-delay" value="<?php if ($delay = ewww_image_optimizer_get_option('ewww_image_optimizer_delay')) { echo $delay; } else { echo 0; } ?> "></p> <div id="ewww-delay-slider" style="width:50%"></div> </form> <h3><?php _e('Optimize Media Library', EWWW_IMAGE_OPTIMIZER_DOMAIN); ?> </h3> <?php if ($fullsize_count < 1) { echo '<p>' . __('You do not appear to have uploaded any images yet.', EWWW_IMAGE_OPTIMIZER_DOMAIN) . '</p>'; } else { ?> <div id="ewww-bulk-forms"> <?php if (!$resize_count && !$unoptimized_count && !$unoptimized_resize_count) { ?> <p class="ewww-media-info ewww-bulk-info"><?php printf(__('%1$d images in the Media Library have been selected, unable to determine how many resizes and how many are unoptimized.', EWWW_IMAGE_OPTIMIZER_DOMAIN), $fullsize_count); ?> <br /> <?php } else { ?> <p class="ewww-media-info ewww-bulk-info"><?php printf(__('%1$d images in the Media Library have been selected (%2$d unoptimized), with %3$d resizes (%4$d unoptimized).', EWWW_IMAGE_OPTIMIZER_DOMAIN), $fullsize_count, $unoptimized_count, $resize_count, $unoptimized_resize_count); ?> <br /> <?php } ?> <?php _e('Previously optimized images will be skipped by default.', EWWW_IMAGE_OPTIMIZER_DOMAIN); ?> </p> <form id="ewww-bulk-start" class="ewww-bulk-form" method="post" action=""> <input id="ewww-bulk-first" type="submit" class="button-secondary action" value="<?php echo $button_text; ?> " /> <input id="ewww-bulk-again" type="submit" class="button-secondary action" style="display:none" value="<?php _e('Optimize Again', EWWW_IMAGE_OPTIMIZER_DOMAIN); ?> " /> </form> <?php } // if the 'bulk resume' option was not empty, offer to reset it so the user can start back from the beginning if (!empty($resume)) { ?> <p class="ewww-media-info ewww-bulk-info"><?php _e('If you would like to start over again, press the Reset Status button to reset the bulk operation status.', EWWW_IMAGE_OPTIMIZER_DOMAIN); ?> </p> <form class="ewww-bulk-form" method="post" action=""> <?php wp_nonce_field('ewww-image-optimizer-bulk', 'ewww_wpnonce'); ?> <input type="hidden" name="ewww_reset" value="1"> <button id="ewww-bulk-reset" type="submit" class="button-secondary action"><?php _e('Reset Status', EWWW_IMAGE_OPTIMIZER_DOMAIN); ?> </button> </form> <?php } echo '</div>'; ewwwio_memory(__FUNCTION__); ewww_image_optimizer_aux_images(); }
function ewww_image_optimizer_bulk_preview() { ewwwio_debug_message('<b>' . __FUNCTION__ . '()</b>'); // retrieve the attachment IDs that were pre-loaded in the database list($fullsize_count, $unoptimized_count, $resize_count, $unoptimized_resize_count) = ewww_image_optimizer_count_optimized('media'); ?> <div class="wrap"> <h1> <?php esc_html_e('Bulk Optimize', EWWW_IMAGE_OPTIMIZER_DOMAIN); if (ewww_image_optimizer_get_option('ewww_image_optimizer_cloud_key')) { ewww_image_optimizer_cloud_verify(); echo '<span><a id="ewww-bulk-credits-available" target="_blank" class="page-title-action" style="float:right;" href="https://ewww.io/my-account/">' . esc_html__('Image credits available:', EWWW_IMAGE_OPTIMIZER_DOMAIN) . ' ' . ewww_image_optimizer_cloud_quota() . '</a></span>'; } echo '</h1>'; // Retrieve the value of the 'bulk resume' option and set the button text for the form to use $resume = get_option('ewww_image_optimizer_bulk_resume'); if (empty($resume)) { $button_text = esc_attr__('Start optimizing', EWWW_IMAGE_OPTIMIZER_DOMAIN); } else { $button_text = esc_attr__('Resume previous optimization', EWWW_IMAGE_OPTIMIZER_DOMAIN); } $loading_image = plugins_url('/images/wpspin.gif', __FILE__); // create the html for the bulk optimize form and status divs ?> <div id="ewww-bulk-loading"> <p id="ewww-loading" class="ewww-bulk-info" style="display:none"><?php esc_html_e('Importing', EWWW_IMAGE_OPTIMIZER_DOMAIN); ?> <img src='<?php echo $loading_image; ?> ' /></p> </div> <div id="ewww-bulk-progressbar"></div> <div id="ewww-bulk-counter"></div> <form id="ewww-bulk-stop" style="display:none;" method="post" action=""> <br /><input type="submit" class="button-secondary action" value="<?php esc_attr_e('Stop Optimizing', EWWW_IMAGE_OPTIMIZER_DOMAIN); ?> " /> </form> <div id="ewww-bulk-widgets" class="metabox-holder" style="display:none"> <div class="meta-box-sortables"> <div id="ewww-bulk-last" class="postbox"> <button type="button" class="handlediv button-link" aria-expanded="true"> <span class="screen-reader-text"><?php esc_html_e('Click to toggle', EWWW_IMAGE_OPTIMIZER_DOMAIN); ?> </span> <span class="toggle-indicator" aria-hidden="true"></span> </button> <h2 class="hndle"><span><?php esc_html_e('Last Image Optimized', EWWW_IMAGE_OPTIMIZER_DOMAIN); ?> </span></h2> <div class="inside"></div> </div> </div> <div class="meta-box-sortables"> <div id="ewww-bulk-status" class="postbox"> <button type="button" class="handlediv button-link" aria-expanded="true"> <span class="screen-reader-text"><?php esc_html_e('Click to toggle', EWWW_IMAGE_OPTIMIZER_DOMAIN); ?> </span> <span class="toggle-indicator" aria-hidden="true"></span> </button> <h2 class="hndle"><span><?php esc_html_e('Optimization Log', EWWW_IMAGE_OPTIMIZER_DOMAIN); ?> </span></h2> <div class="inside"></div> </div> </div> </div> <form class="ewww-bulk-form"> <p><label for="ewww-force" style="font-weight: bold"><?php esc_html_e('Force re-optimize', EWWW_IMAGE_OPTIMIZER_DOMAIN); ?> </label> <input type="checkbox" id="ewww-force" name="ewww-force"></p> <p><label for="ewww-delay" style="font-weight: bold"><?php esc_html_e('Choose how long to pause between images (in seconds, 0 = disabled)', EWWW_IMAGE_OPTIMIZER_DOMAIN); ?> </label> <input type="text" id="ewww-delay" name="ewww-delay" value="<?php if ($delay = ewww_image_optimizer_get_option('ewww_image_optimizer_delay')) { echo $delay; } else { echo 0; } ?> "></p> <div id="ewww-delay-slider" style="width:50%"></div> </form> <h2 class="ewww-bulk-media"><?php esc_html_e('Optimize Media Library', EWWW_IMAGE_OPTIMIZER_DOMAIN); ?> </h2> <?php if ($fullsize_count < 1) { echo '<p>' . esc_html__('You do not appear to have uploaded any images yet.', EWWW_IMAGE_OPTIMIZER_DOMAIN) . '</p>'; } else { ?> <div id="ewww-bulk-forms"> <?php if (!$resize_count && !$unoptimized_count && !$unoptimized_resize_count) { if (ewww_image_optimizer_get_option('ewww_image_optimizer_cloud_key')) { $credits_needed = $fullsize_count * (count(get_intermediate_image_sizes()) + 1); } ?> <p class="ewww-media-info ewww-bulk-info"><?php printf(esc_html__('%1$d images in the Media Library have been selected, unable to determine how many resizes and how many are unoptimized.', EWWW_IMAGE_OPTIMIZER_DOMAIN), $fullsize_count); ?> <?php if (ewww_image_optimizer_get_option('ewww_image_optimizer_cloud_key') && $credits_needed > 0) { printf(esc_html__('This could require approximately %d image credits to complete.', EWWW_IMAGE_OPTIMIZER_DOMAIN), $credits_needed); } ?> <br /> <?php } else { if (ewww_image_optimizer_get_option('ewww_image_optimizer_cloud_key')) { $credits_needed = $unoptimized_count + $unoptimized_resize_count; } ?> <p class="ewww-media-info ewww-bulk-info"><?php printf(esc_html__('%1$d images in the Media Library have been selected (%2$d unoptimized), with %3$d resizes (%4$d unoptimized).', EWWW_IMAGE_OPTIMIZER_DOMAIN), $fullsize_count, $unoptimized_count, $resize_count, $unoptimized_resize_count); ?> <?php if (ewww_image_optimizer_get_option('ewww_image_optimizer_cloud_key') && $credits_needed > 0) { printf(esc_html__('This could require approximately %d image credits to complete.', EWWW_IMAGE_OPTIMIZER_DOMAIN), $credits_needed); } ?> <br /> <?php } ?> <?php esc_html_e('Previously optimized images will be skipped by default.', EWWW_IMAGE_OPTIMIZER_DOMAIN); ?> </p> <form id="ewww-bulk-start" class="ewww-bulk-form" method="post" action=""> <input id="ewww-bulk-first" type="submit" class="button-secondary action" value="<?php echo $button_text; ?> " /> <input id="ewww-bulk-again" type="submit" class="button-secondary action" style="display:none" value="<?php esc_attr_e('Optimize Again', EWWW_IMAGE_OPTIMIZER_DOMAIN); ?> " /> </form> <?php } // if the 'bulk resume' option was not empty, offer to reset it so the user can start back from the beginning if (!empty($resume)) { ?> <p class="ewww-media-info ewww-bulk-info"><?php esc_html_e('If you would like to start over again, press the Reset Status button to reset the bulk operation status.', EWWW_IMAGE_OPTIMIZER_DOMAIN); ?> </p> <form class="ewww-bulk-form" method="post" action=""> <?php wp_nonce_field('ewww-image-optimizer-bulk-reset', 'ewww_wpnonce'); ?> <input type="hidden" name="ewww_reset" value="1"> <button id="ewww-bulk-reset" type="submit" class="button-secondary action"><?php esc_html_e('Reset Status', EWWW_IMAGE_OPTIMIZER_DOMAIN); ?> </button> </form> <?php } echo '</div>'; ewwwio_memory(__FUNCTION__); ewww_image_optimizer_aux_images(); }
function ewww_ngg_bulk_preview() { global $ewww_debug; if (!empty($_POST['doaction'])) { // if there is no requested bulk action, do nothing if (empty($_REQUEST['bulkaction'])) { return; } // if there is no media to optimize, do nothing if (empty($_REQUEST['doaction']) || !is_array($_REQUEST['doaction'])) { return; } } list($fullsize_count, $unoptimized_count, $resize_count, $unoptimized_resize_count) = ewww_image_optimizer_count_optimized('ngg'); // make sure there are some attachments to process if ($fullsize_count < 1) { echo '<p>' . __('You do not appear to have uploaded any images yet.', EWWW_IMAGE_OPTIMIZER_DOMAIN) . '</p>'; return; } // ewww_image_optimizer_cloud_verify(false); ?> <div class="wrap"> <div id="icon-upload" class="icon32"></div><h2><?php _e('Bulk Optimize', EWWW_IMAGE_OPTIMIZER_DOMAIN); ?> </h2> <?php // Retrieve the value of the 'bulk resume' option and set the button text for the form to use $resume = get_option('ewww_image_optimizer_bulk_ngg_resume'); if (empty($resume)) { $button_text = __('Start optimizing', EWWW_IMAGE_OPTIMIZER_DOMAIN); } else { $button_text = __('Resume previous bulk operation', EWWW_IMAGE_OPTIMIZER_DOMAIN); } ?> <div id="ewww-bulk-loading"></div> <div id="ewww-bulk-progressbar"></div> <div id="ewww-bulk-counter"></div> <form id="ewww-bulk-stop" style="display:none;" method="post" action=""> <br /><input type="submit" class="button-secondary action" value="<?php _e('Stop Optimizing', EWWW_IMAGE_OPTIMIZER_DOMAIN); ?> " /> </form> <div id="ewww-bulk-status"></div> <form class="ewww-bulk-form"> <p><label for="ewww-force" style="font-weight: bold"><?php _e('Force re-optimize', EWWW_IMAGE_OPTIMIZER_DOMAIN); ?> </label> <input type="checkbox" id="ewww-force" name="ewww-force"></p> <p><label for="ewww-delay" style="font-weight: bold"><?php _e('Choose how long to pause between images (in seconds, 0 = disabled)', EWWW_IMAGE_OPTIMIZER_DOMAIN); ?> </label> <input type="text" id="ewww-delay" name="ewww-delay" value="<?php if ($delay = ewww_image_optimizer_get_option('ewww_image_optimizer_delay')) { echo $delay; } else { echo 0; } ?> "></p> <div id="ewww-delay-slider" style="width:50%"></div> </form> <div id="ewww-bulk-forms"> <p class="ewww-bulk-info"><?php printf(__('%1$d images have been selected (%2$d unoptimized), with %3$d resizes (%4$d unoptimized).', EWWW_IMAGE_OPTIMIZER_DOMAIN), $fullsize_count, $unoptimized_count, $resize_count, $unoptimized_resize_count); ?> <br /> <?php _e('Previously optimized images will be skipped by default.', EWWW_IMAGE_OPTIMIZER_DOMAIN); ?> </p> <form id="ewww-bulk-start" class="ewww-bulk-form" method="post" action=""> <input type="submit" class="button-secondary action" value="<?php echo $button_text; ?> " /> </form> <?php // if there is a previous bulk operation to resume, give the user the option to reset the resume flag if (!empty($resume)) { ?> <p class="ewww-bulk-info"><?php _e('If you would like to start over again, press the Reset Status button to reset the bulk operation status.', EWWW_IMAGE_OPTIMIZER_DOMAIN); ?> </p> <form id="ewww-bulk-reset" class="ewww-bulk-form" method="post" action=""> <?php wp_nonce_field('ewww-image-optimizer-bulk-reset', 'ewww_wpnonce'); ?> <input type="hidden" name="ewww_reset" value="1"> <input type="submit" class="button-secondary action" value="<?php _e('Reset Status', EWWW_IMAGE_OPTIMIZER_DOMAIN); ?> " /> </form> <?php } echo '</div></div>'; if (ewww_image_optimizer_get_option('ewww_image_optimizer_debug')) { echo '<div style="background-color:#ffff99;">' . $ewww_debug . '</div>'; } if (!empty($_REQUEST['ewww_inline'])) { die; } return; }