Exemple #1
0
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);
    ?>
&nbsp;<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>&emsp;<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>&emsp;<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();
}
Exemple #2
0
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);
    ?>
&nbsp;<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>&emsp;<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>&emsp;<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();
}