コード例 #1
0
 function ewwwngg()
 {
     add_action('admin_init', array(&$this, 'admin_init'));
     add_filter('ngg_manage_images_columns', array(&$this, 'ewww_manage_images_columns'));
     add_action('ngg_manage_image_custom_column', array(&$this, 'ewww_manage_image_custom_column'), 10, 2);
     if (!ewww_image_optimizer_get_option('ewww_image_optimizer_noauto')) {
         add_action('ngg_added_new_image', array(&$this, 'ewww_added_new_image'));
     }
     add_action('admin_action_ewww_ngg_manual', array(&$this, 'ewww_ngg_manual'));
     add_action('admin_menu', array(&$this, 'ewww_ngg_bulk_menu'));
     $i18ngg = strtolower(_n('Gallery', 'Galleries', 1, 'nggallery'));
     add_action('admin_head-' . $i18ngg . '_page_nggallery-manage-gallery', array(&$this, 'ewww_ngg_bulk_actions_script'));
     add_action('admin_enqueue_scripts', array(&$this, 'ewww_ngg_bulk_script'));
     add_action('wp_ajax_bulk_ngg_preview', array(&$this, 'ewww_ngg_bulk_preview'));
     add_action('wp_ajax_bulk_ngg_init', array(&$this, 'ewww_ngg_bulk_init'));
     add_action('wp_ajax_bulk_ngg_filename', array(&$this, 'ewww_ngg_bulk_filename'));
     add_action('wp_ajax_bulk_ngg_loop', array(&$this, 'ewww_ngg_bulk_loop'));
     add_action('wp_ajax_bulk_ngg_cleanup', array(&$this, 'ewww_ngg_bulk_cleanup'));
     add_action('wp_ajax_ewww_ngg_thumbs', array(&$this, 'ewww_ngg_thumbs_only'));
     add_action('ngg_after_new_images_added', array(&$this, 'ewww_ngg_new_thumbs'), 10, 2);
 }
コード例 #2
0
function ewww_image_optimizer_options()
{
    global $ewww_debug;
    $ewww_debug .= "<b>ewww_image_optimizer_options()</b><br>";
    if (isset($_REQUEST['pngout'])) {
        if ($_REQUEST['pngout'] == 'success') {
            ?>
			<div id='ewww-image-optimizer-pngout-success' class='updated fade'>
				<p><?php 
            _e('Pngout was successfully installed, check the Plugin Status area for version information.', EWWW_IMAGE_OPTIMIZER_DOMAIN);
            ?>
</p>
			</div>
<?php 
        }
        if ($_REQUEST['pngout'] == 'failed') {
            ?>
			<div id='ewww-image-optimizer-pngout-failure' class='error'>
				<p><?php 
            printf(__('Pngout was not installed: %1$s. Make sure this folder is writable: %2$s', EWWW_IMAGE_OPTIMIZER_DOMAIN), $_REQUEST['error'], EWWW_IMAGE_OPTIMIZER_TOOL_PATH);
            ?>
</p>
			</div>
<?php 
        }
    }
    ?>
	<script type='text/javascript'>
		jQuery(document).ready(function($) {$('.fade').fadeTo(5000,1).fadeOut(3000);});
	</script>
	<div class="wrap">
		<div id="icon-options-general" class="icon32"><br /></div>
		<h2>EWWW <?php 
    _e('Image Optimizer Settings', EWWW_IMAGE_OPTIMIZER_DOMAIN);
    ?>
</h2>
		<p><a href="http://wordpress.org/extend/plugins/ewww-image-optimizer/"><?php 
    _e('Plugin Home Page', EWWW_IMAGE_OPTIMIZER_DOMAIN);
    ?>
</a> |
		<a href="http://wordpress.org/extend/plugins/ewww-image-optimizer/installation/"><?php 
    _e('Installation Instructions', EWWW_IMAGE_OPTIMIZER_DOMAIN);
    ?>
</a> | 
		<a href="http://wordpress.org/support/plugin/ewww-image-optimizer"><?php 
    _e('Plugin Support', EWWW_IMAGE_OPTIMIZER_DOMAIN);
    ?>
</a> | 
		<a href="http://stats.pingdom.com/w89y81bhecp4"><?php 
    _e('Cloud Status', EWWW_IMAGE_OPTIMIZER_DOMAIN);
    ?>
</a></p>
<?php 
    if (function_exists('is_plugin_active_for_network') && is_plugin_active_for_network('ewww-image-optimizer/ewww-image-optimizer.php')) {
        $bulk_link = __('Media Library') . ' -> ' . __('Bulk Optimize', EWWW_IMAGE_OPTIMIZER_DOMAIN);
    } else {
        $bulk_link = '<a href="upload.php?page=ewww-image-optimizer-bulk">' . __('Bulk Optimize', EWWW_IMAGE_OPTIMIZER_DOMAIN) . '</a>';
    }
    ?>
		<p><?php 
    printf(__('New images uploaded to the Media Library will be optimized automatically. If you have existing images you would like to optimize, you can use the %s tool.', EWWW_IMAGE_OPTIMIZER_DOMAIN), $bulk_link);
    ?>
</p>
		<div id="status" style="border: 1px solid #ccc; padding: 0 8px; border-radius: 12px;">
			<h3>Plugin Status</h3>
			<?php 
    if (ewww_image_optimizer_get_option('ewww_image_optimizer_cloud_key')) {
        echo '<p><b>Cloud API Key:</b> ';
        $verify_cloud = ewww_image_optimizer_cloud_verify(false);
        if (preg_match('/great/', $verify_cloud)) {
            echo '<span style="color: green">' . __('Verified,', EWWW_IMAGE_OPTIMIZER_DOMAIN) . ' </span>';
            echo ewww_image_optimizer_cloud_quota();
        } elseif (preg_match('/exceeded/', $verify_cloud)) {
            echo '<span style="color: orange">' . __('Verified,', EWWW_IMAGE_OPTIMIZER_DOMAIN) . ' </span>';
            echo ewww_image_optimizer_cloud_quota();
        } else {
            echo '<span style="color: red">' . __('Not Verified', EWWW_IMAGE_OPTIMIZER_DOMAIN) . '</span>';
        }
        echo '</p>';
    }
    if (ewww_image_optimizer_get_option('ewww_image_optimizer_skip_bundle') && !EWWW_IMAGE_OPTIMIZER_CLOUD && !EWWW_IMAGE_OPTIMIZER_NOEXEC) {
        ?>
				<p><?php 
        _e('If updated versions are available below you may either download the newer versions and install them yourself, or uncheck "Use System Paths" and use the bundled tools.', EWWW_IMAGE_OPTIMIZER_DOMAIN);
        ?>
<br />
				<i>*<?php 
        _e('Updates are optional, but may contain increased optimization or security patches', EWWW_IMAGE_OPTIMIZER_DOMAIN);
        ?>
</i></p>
			<?php 
    } elseif (!EWWW_IMAGE_OPTIMIZER_CLOUD && !EWWW_IMAGE_OPTIMIZER_NOEXEC) {
        ?>
				<p><?php 
        printf(__('If updated versions are available below, you may need to enable write permission on the %s folder to use the automatic installs.', EWWW_IMAGE_OPTIMIZER_DOMAIN), '<i>' . EWWW_IMAGE_OPTIMIZER_TOOL_PATH . '</i>');
        ?>
<br />
				<i>*<?php 
        _e('Updates are optional, but may contain increased optimization or security patches', EWWW_IMAGE_OPTIMIZER_DOMAIN);
        ?>
</i></p>
			<?php 
    }
    if (!EWWW_IMAGE_OPTIMIZER_CLOUD && !EWWW_IMAGE_OPTIMIZER_NOEXEC) {
        list($jpegtran_src, $optipng_src, $gifsicle_src, $jpegtran_dst, $optipng_dst, $gifsicle_dst) = ewww_image_optimizer_install_paths();
    }
    if (!ewww_image_optimizer_get_option('ewww_image_optimizer_disable_jpegtran') && !ewww_image_optimizer_get_option('ewww_image_optimizer_cloud_jpg') && !EWWW_IMAGE_OPTIMIZER_NOEXEC) {
        echo "\n", '<b>jpegtran: </b>';
        $jpegtran_installed = ewww_image_optimizer_tool_found(EWWW_IMAGE_OPTIMIZER_JPEGTRAN, 'j');
        if (!empty($jpegtran_installed)) {
            echo '<span style="color: green; font-weight: bolder">OK</span>&emsp;version: ' . $jpegtran_installed . '<br />';
        } else {
            echo '<span style="color: red; font-weight: bolder">MISSING</span><br />';
        }
    }
    if (!ewww_image_optimizer_get_option('ewww_image_optimizer_disable_optipng') && !ewww_image_optimizer_get_option('ewww_image_optimizer_cloud_png') && !EWWW_IMAGE_OPTIMIZER_NOEXEC) {
        echo "\n", '<b>optipng:</b> ';
        $optipng_version = ewww_image_optimizer_tool_found(EWWW_IMAGE_OPTIMIZER_OPTIPNG, 'o');
        if (!empty($optipng_version)) {
            echo '<span style="color: green; font-weight: bolder">OK</span>&emsp;version: ' . $optipng_version . '<br />';
        } else {
            echo '<span style="color: red; font-weight: bolder">MISSING</span><br />';
        }
    }
    if (!ewww_image_optimizer_get_option('ewww_image_optimizer_disable_gifsicle') && !ewww_image_optimizer_get_option('ewww_image_optimizer_cloud_gif') && !EWWW_IMAGE_OPTIMIZER_NOEXEC) {
        echo "\n", '<b>gifsicle:</b> ';
        $gifsicle_version = ewww_image_optimizer_tool_found(EWWW_IMAGE_OPTIMIZER_GIFSICLE, 'g');
        if (!empty($gifsicle_version) && preg_match('/LCDF Gifsicle/', $gifsicle_version)) {
            echo '<span style="color: green; font-weight: bolder">OK</span>&emsp;version: ' . $gifsicle_version . '<br />';
        } else {
            echo '<span style="color: red; font-weight: bolder">MISSING</span><br />';
        }
    }
    if (!ewww_image_optimizer_get_option('ewww_image_optimizer_disable_pngout') && !ewww_image_optimizer_get_option('ewww_image_optimizer_cloud_png') && !EWWW_IMAGE_OPTIMIZER_NOEXEC) {
        echo "\n", '<b>pngout:</b> ';
        $pngout_version = ewww_image_optimizer_tool_found(EWWW_IMAGE_OPTIMIZER_PNGOUT, 'p');
        if (!empty($pngout_version) && preg_match('/PNGOUT/', $pngout_version)) {
            echo '<span style="color: green; font-weight: bolder">OK</span>&emsp;version: ' . preg_replace('/PNGOUT \\[.*\\)\\s*?/', '', $pngout_version) . '<br />';
        } else {
            echo '<span style="color: red; font-weight: bolder">MISSING</span>&emsp;<b>' . __('Install', EWWW_IMAGE_OPTIMIZER_DOMAIN) . ' <a href="admin.php?action=ewww_image_optimizer_install_pngout">' . __('automatically', EWWW_IMAGE_OPTIMIZER_DOMAIN) . '</a> | <a href="http://advsys.net/ken/utils.htm">' . __('manually', EWWW_IMAGE_OPTIMIZER_DOMAIN) . '</a></b> - ' . __('Pngout is free closed-source software that can produce drastically reduced filesizes for PNGs, but can be very time consuming to process images', EWWW_IMAGE_OPTIMIZER_DOMAIN) . '<br />';
        }
    }
    echo "\n";
    if (!EWWW_IMAGE_OPTIMIZER_CLOUD && !EWWW_IMAGE_OPTIMIZER_NOEXEC) {
        printf(__("%s only need one, used for conversion, not optimization: ", EWWW_IMAGE_OPTIMIZER_DOMAIN), '<b>' . __('Graphics libraries', EWWW_IMAGE_OPTIMIZER_DOMAIN) . '</b> - ');
        if (ewww_image_optimizer_gd_support()) {
            echo 'GD: <span style="color: green; font-weight: bolder">OK';
        } else {
            echo 'GD: <span style="color: red; font-weight: bolder">MISSING';
        }
        ?>
</span>&emsp;&emsp;
				Imagemagick 'convert': <?php 
        if (ewww_image_optimizer_find_binary('convert', 'i')) {
            echo '<span style="color: green; font-weight: bolder">OK</span>';
        } else {
            echo '<span style="color: red; font-weight: bolder">MISSING</span>';
        }
        echo "<br />\n";
        if (ewww_image_optimizer_safemode_check()) {
            echo 'safe mode: <span style="color: red; font-weight: bolder">On</span>&emsp;&emsp;';
        } else {
            echo 'safe mode: <span style="color: green; font-weight: bolder">Off</span>&emsp;&emsp;';
        }
        if (ewww_image_optimizer_exec_check()) {
            echo 'exec(): <span style="color: red; font-weight: bolder">DISABLED</span>&emsp;&emsp;';
        } else {
            echo 'exec(): <span style="color: green; font-weight: bolder">OK</span>&emsp;&emsp;';
        }
        echo "<br />\n";
    }
    echo '<b>' . __('Only need one of these:', EWWW_IMAGE_OPTIMIZER_DOMAIN) . ' </b>';
    // initialize this variable to check for the 'file' command if we don't have any php libraries we can use
    $file_command_check = true;
    if (function_exists('finfo_file')) {
        echo 'finfo: <span style="color: green; font-weight: bolder">OK</span>&emsp;&emsp;';
        $file_command_check = false;
    } else {
        echo 'finfo: <span style="color: red; font-weight: bolder">MISSING</span>&emsp;&emsp;';
    }
    if (function_exists('getimagesize')) {
        echo 'getimagesize(): <span style="color: green; font-weight: bolder">OK</span>&emsp;&emsp;';
    } else {
        echo 'getimagesize(): <span style="color: red; font-weight: bolder">MISSING</span>&emsp;&emsp;';
    }
    if (function_exists('mime_content_type')) {
        echo 'mime_content_type(): <span style="color: green; font-weight: bolder">OK</span><br>';
        $file_command_check = false;
    } else {
        echo 'mime_content_type(): <span style="color: red; font-weight: bolder">MISSING</span><br>';
    }
    if (PHP_OS != 'WINNT' && !EWWW_IMAGE_OPTIMIZER_CLOUD && !EWWW_IMAGE_OPTIMIZER_NOEXEC) {
        if ($file_command_check && !ewww_image_optimizer_find_binary('file', 'f')) {
            echo '<span style="color: red; font-weight: bolder">file ' . __('command not found on your system', EWWW_IMAGE_OPTIMIZER_DOMAIN) . '</span><br>';
        }
        if (!ewww_image_optimizer_find_binary('nice', 'n')) {
            echo '<span style="color: orange; font-weight: bolder">nice ' . __('command not found on your system', EWWW_IMAGE_OPTIMIZER_DOMAIN) . ' (' . __('not required', EWWW_IMAGE_OPTIMIZER_DOMAIN) . ')</span><br>';
        }
        if (PHP_OS != 'SunOS' && !ewww_image_optimizer_find_binary('tar', 't')) {
            echo '<span style="color: red; font-weight: bolder">tar ' . __('command not found on your system', EWWW_IMAGE_OPTIMIZER_DOMAIN) . ' (' . __('required for automatic pngout installer', EWWW_IMAGE_OPTIMIZER_DOMAIN) . ')</span><br>';
        }
    }
    ?>
</p>
		</div>
<?php 
    if (function_exists('is_plugin_active_for_network') && is_plugin_active_for_network('ewww-image-optimizer/ewww-image-optimizer.php')) {
        ?>
		<form method="post" action="">
<?php 
    } else {
        ?>
		<form method="post" action="options.php">
			<?php 
        settings_fields('ewww_image_optimizer_options');
    }
    ?>
			<div id="ewww-accordion">
			<h3><?php 
    _e('Cloud Settings', EWWW_IMAGE_OPTIMIZER_DOMAIN);
    ?>
</h3>
			<div>
			<p><?php 
    _e('If exec() is disabled for security reasons (and enabling it is not an option), or you would like to offload image optimization to a third-party server, you may purchase an API key for our cloud optimization service. The API key should be entered below, and cloud optimization must be enabled for each image format individually.', EWWW_IMAGE_OPTIMIZER_DOMAIN);
    ?>
 <a href="http://www.exactlywww.com/cloud/"><?php 
    _e('Purchase an API key.', EWWW_IMAGE_OPTIMIZER_DOMAIN);
    ?>
</a></p>
			<table class="form-table">
				<tr><th><label for="ewww_image_optimizer_cloud_key"><?php 
    _e('Cloud optimization API Key', EWWW_IMAGE_OPTIMIZER_DOMAIN);
    ?>
</label></th><td><input type="text" id="ewww_image_optimizer_cloud_key" name="ewww_image_optimizer_cloud_key" value="<?php 
    echo ewww_image_optimizer_get_option('ewww_image_optimizer_cloud_key');
    ?>
" size="32" /> <?php 
    _e('API Key will be validated when you save your settings.', EWWW_IMAGE_OPTIMIZER_DOMAIN);
    ?>
 <a href="http://www.exactlywww.com/cloud/"><?php 
    _e('Purchase a key.', EWWW_IMAGE_OPTIMIZER_DOMAIN);
    ?>
</a></td></tr>
				<tr><th><label for="ewww_image_optimizer_cloud_jpg">JPG <?php 
    _e('cloud optimization', EWWW_IMAGE_OPTIMIZER_DOMAIN);
    ?>
</label></th><td><input type="checkbox" id="ewww_image_optimizer_cloud_jpg" name="ewww_image_optimizer_cloud_jpg" value="true" <?php 
    if (ewww_image_optimizer_get_option('ewww_image_optimizer_cloud_jpg') == TRUE) {
        ?>
checked="true"<?php 
    }
    ?>
 /></td></tr>
				<tr><th><label for="ewww_image_optimizer_cloud_png">PNG <?php 
    _e('cloud optimization', EWWW_IMAGE_OPTIMIZER_DOMAIN);
    ?>
</label></th><td><input type="checkbox" id="ewww_image_optimizer_cloud_png" name="ewww_image_optimizer_cloud_png" value="true" <?php 
    if (ewww_image_optimizer_get_option('ewww_image_optimizer_cloud_png') == TRUE) {
        ?>
checked="true"<?php 
    }
    ?>
 />&emsp;&emsp;
					<label for="ewww_image_optimizer_cloud_png_compress"><?php 
    _e('extra compression (slower)', EWWW_IMAGE_OPTIMIZER_DOMAIN);
    ?>
</label> <input type="checkbox" id="ewww_image_optimizer_cloud_png_compress" name="ewww_image_optimizer_cloud_png_compress" value="true" <?php 
    if (ewww_image_optimizer_get_option('ewww_image_optimizer_cloud_png_compress') == TRUE) {
        ?>
checked="true"<?php 
    }
    ?>
 /></td></tr>
				<tr><th><label for="ewww_image_optimizer_cloud_gif">GIF <?php 
    _e('cloud optimization', EWWW_IMAGE_OPTIMIZER_DOMAIN);
    ?>
</label></th><td><input type="checkbox" id="ewww_image_optimizer_cloud_gif" name="ewww_image_optimizer_cloud_gif" value="true" <?php 
    if (ewww_image_optimizer_get_option('ewww_image_optimizer_cloud_gif') == TRUE) {
        ?>
checked="true"<?php 
    }
    ?>
 /></td></tr>
			</table>
			</div>
			<h3><?php 
    _e('General Settings', EWWW_IMAGE_OPTIMIZER_DOMAIN);
    ?>
</h3>
			<div>
			<p class="nocloud"><?php 
    _e('The plugin performs a check to make sure your system has the programs we use for optimization: jpegtran, optipng, pngout, and gifsicle. In some rare cases, these checks may falsely report that you are missing the required utilities even though you have them installed.', EWWW_IMAGE_OPTIMIZER_DOMAIN);
    ?>
</p>
			<table class="form-table">
				<tr><th><label for="ewww_image_optimizer_debug"><?php 
    _e('Debugging', EWWW_IMAGE_OPTIMIZER_DOMAIN);
    ?>
</label></th><td><input type="checkbox" id="ewww_image_optimizer_debug" name="ewww_image_optimizer_debug" value="true" <?php 
    if (ewww_image_optimizer_get_option('ewww_image_optimizer_debug') == TRUE) {
        ?>
checked="true"<?php 
    }
    ?>
 /> <?php 
    _e('Use this to provide information for support purposes, or if you feel comfortable digging around in the code to fix a problem you are experiencing.', EWWW_IMAGE_OPTIMIZER_DOMAIN);
    ?>
</td></tr>
				<tr><th><label for="ewww_image_optimizer_auto"><?php 
    _e('Scheduled optimization', EWWW_IMAGE_OPTIMIZER_DOMAIN);
    ?>
</label></th><td><input type="checkbox" id="ewww_image_optimizer_auto" name="ewww_image_optimizer_auto" value="true" <?php 
    if (ewww_image_optimizer_get_option('ewww_image_optimizer_auto') == TRUE) {
        ?>
checked="true"<?php 
    }
    ?>
 /> <?php 
    _e('This will enable scheduled optimization of unoptimized images for your theme, buddypress, and any additional folders you have configured below. Runs hourly: wp_cron only runs when your site is visited, so it may be even longer between optimizations.', EWWW_IMAGE_OPTIMIZER_DOMAIN);
    ?>
</td></tr>
				<tr><th><label for="ewww_image_optimizer_aux_paths"><?php 
    _e('Folders to optimize', EWWW_IMAGE_OPTIMIZER_DOMAIN);
    ?>
</label></th><td><?php 
    printf(__('One path per line, must be within %s. Use full paths, not relative paths.', EWWW_IMAGE_OPTIMIZER_DOMAIN), ABSPATH);
    ?>
<br />
					<textarea id="ewww_image_optimizer_aux_paths" name="ewww_image_optimizer_aux_paths" rows="3" cols="60"><?php 
    if ($aux_paths = ewww_image_optimizer_get_option('ewww_image_optimizer_aux_paths')) {
        foreach ($aux_paths as $path) {
            echo "{$path}\n";
        }
    }
    ?>
</textarea>
					<p class="description">Provide paths containing images to be optimized using scheduled optimization or 'Optimize More' in the Tools menu.<br>
					<b><a href="http://wordpress.org/support/plugin/ewww-image-optimizer"><?php 
    _e('Please submit a support request in the forums to have folders created by a particular plugin auto-included in the future.', EWWW_IMAGE_OPTIMIZER_DOMAIN);
    ?>
</a></b></p></td></tr>
				<tr><th><label for="ewww_image_optimizer_delay"><?php 
    _e('Bulk Delay', EWWW_IMAGE_OPTIMIZER_DOMAIN);
    ?>
</label></th><td><input type="text" id="ewww_image_optimizer_delay" name="ewww_image_optimizer_delay" size="5" value="<?php 
    echo ewww_image_optimizer_get_option('ewww_image_optimizer_delay');
    ?>
"> <?php 
    _e('Choose how long to pause between images (in seconds, 0 = disabled)', EWWW_IMAGE_OPTIMIZER_DOMAIN);
    ?>
</td></tr>
<!--				<tr><th><label for="ewww_image_optimizer_interval"><?php 
    _e('Image Batch Size', EWWW_IMAGE_OPTIMIZER_DOMAIN);
    ?>
</label></th><td><input type="text" id="ewww_image_optimizer_interval" name="ewww_image_optimizer_interval" size="5" value="<?php 
    echo ewww_image_optimizer_get_option('ewww_image_optimizer_interval');
    ?>
"> <?php 
    _e('Choose how many images should be processed before each delay', EWWW_IMAGE_OPTIMIZER_DOMAIN);
    ?>
</td></tr>-->
				<tr class="nocloud"><th><label for="ewww_image_optimizer_skip_bundle"><?php 
    _e('Use System Paths', EWWW_IMAGE_OPTIMIZER_DOMAIN);
    ?>
</label></th><td><input type="checkbox" id="ewww_image_optimizer_skip_bundle" name="ewww_image_optimizer_skip_bundle" value="true" <?php 
    if (ewww_image_optimizer_get_option('ewww_image_optimizer_skip_bundle') == TRUE) {
        ?>
checked="true"<?php 
    }
    ?>
 /> <?php 
    printf(__('If you have already installed the utilities in a system location, such as %s or %s, use this to force the plugin to use those versions and skip the auto-installers.', EWWW_IMAGE_OPTIMIZER_DOMAIN), '/usr/local/bin', '/usr/bin');
    ?>
</td></tr>
				<tr class="nocloud"><th><label for="ewww_image_optimizer_disable_jpegtran"><?php 
    _e('disable', EWWW_IMAGE_OPTIMIZER_DOMAIN);
    ?>
 jpegtran</label></th><td><input type="checkbox" id="ewww_image_optimizer_disable_jpegtran" name="ewww_image_optimizer_disable_jpegtran" <?php 
    if (ewww_image_optimizer_get_option('ewww_image_optimizer_disable_jpegtran') == TRUE) {
        ?>
checked="true"<?php 
    }
    ?>
 /></td></tr>
				<tr class="nocloud"><th><label for="ewww_image_optimizer_disable_optipng"><?php 
    _e('disable', EWWW_IMAGE_OPTIMIZER_DOMAIN);
    ?>
 optipng</label></th><td><input type="checkbox" id="ewww_image_optimizer_disable_optipng" name="ewww_image_optimizer_disable_optipng" <?php 
    if (ewww_image_optimizer_get_option('ewww_image_optimizer_disable_optipng') == TRUE) {
        ?>
checked="true"<?php 
    }
    ?>
 /></td></tr>
				<tr class="nocloud"><th><label for="ewww_image_optimizer_disable_pngout"><?php 
    _e('disable', EWWW_IMAGE_OPTIMIZER_DOMAIN);
    ?>
 pngout</label></th><td><input type="checkbox" id="ewww_image_optimizer_disable_pngout" name="ewww_image_optimizer_disable_pngout" <?php 
    if (ewww_image_optimizer_get_option('ewww_image_optimizer_disable_pngout') == TRUE) {
        ?>
checked="true"<?php 
    }
    ?>
 /></td><tr>
				<tr class="nocloud"><th><label for="ewww_image_optimizer_disable_gifsicle"><?php 
    _e('disable', EWWW_IMAGE_OPTIMIZER_DOMAIN);
    ?>
 gifsicle</label></th><td><input type="checkbox" id="ewww_image_optimizer_disable_gifsicle" name="ewww_image_optimizer_disable_gifsicle" <?php 
    if (ewww_image_optimizer_get_option('ewww_image_optimizer_disable_gifsicle') == TRUE) {
        ?>
checked="true"<?php 
    }
    ?>
 /></td></tr>
<?php 
    if (class_exists('Cloudinary') && Cloudinary::config_get("api_secret")) {
        ?>
				<tr><th><label for="ewww_image_optimizer_enable_cloudinary"><?php 
        _e('Automatic Cloudinary upload', EWWW_IMAGE_OPTIMIZER_DOMAIN);
        ?>
</label></th><td><input type="checkbox" id="ewww_image_optimizer_enable_cloudinary" name="ewww_image_optimizer_enable_cloudinary" value="true" <?php 
        if (ewww_image_optimizer_get_option('ewww_image_optimizer_enable_cloudinary') == TRUE) {
            ?>
checked="true"<?php 
        }
        ?>
 /> <?php 
        _e('When enabled, uploads to the Media Library will be transferred to Cloudinary after optimization. Cloudinary generates resizes, so only the full-size image is uploaded.', EWWW_IMAGE_OPTIMIZER_DOMAIN);
        ?>
</td></tr>
<?php 
    }
    ?>
			</table>
			</div>
			<h3><?php 
    _e('Optimization Settings', EWWW_IMAGE_OPTIMIZER_DOMAIN);
    ?>
</h3>
			<div>
			<table class="form-table">
				<tr><th><label for="ewww_image_optimizer_jpegtran_copy"><?php 
    _e('Remove metadata', EWWW_IMAGE_OPTIMIZER_DOMAIN);
    ?>
</label></th>
				<td><input type="checkbox" id="ewww_image_optimizer_jpegtran_copy" name="ewww_image_optimizer_jpegtran_copy" value="true" <?php 
    if (ewww_image_optimizer_get_option('ewww_image_optimizer_jpegtran_copy') == TRUE) {
        ?>
checked="true"<?php 
    }
    ?>
 /> <?php 
    _e('This wil remove ALL metadata: EXIF and comments.', EWWW_IMAGE_OPTIMIZER_DOMAIN);
    ?>
</td></tr>
				<tr class="nocloud"><th><label for="ewww_image_optimizer_optipng_level">optipng <?php 
    _e('optimization level', EWWW_IMAGE_OPTIMIZER_DOMAIN);
    ?>
</label></th>
				<td><span><select id="ewww_image_optimizer_optipng_level" name="ewww_image_optimizer_optipng_level">
				<option value="1"<?php 
    if (ewww_image_optimizer_get_option('ewww_image_optimizer_optipng_level') == 1) {
        echo ' selected="selected"';
    }
    echo '>' . sprintf(__('Level %d', EWWW_IMAGE_OPTIMIZER_DOMAIN), 1) . ': ' . sprintf(__('%d trial', EWWW_IMAGE_OPTIMIZER_DOMAIN), 1);
    ?>
</option>
				<option value="2"<?php 
    if (ewww_image_optimizer_get_option('ewww_image_optimizer_optipng_level') == 2) {
        echo ' selected="selected"';
    }
    echo '>' . sprintf(__('Level %d', EWWW_IMAGE_OPTIMIZER_DOMAIN), 2) . ': ' . sprintf(__('%d trials', EWWW_IMAGE_OPTIMIZER_DOMAIN), 8);
    ?>
</option>
				<option value="3"<?php 
    if (ewww_image_optimizer_get_option('ewww_image_optimizer_optipng_level') == 3) {
        echo ' selected="selected"';
    }
    echo '>' . sprintf(__('Level %d', EWWW_IMAGE_OPTIMIZER_DOMAIN), 3) . ': ' . sprintf(__('%d trials', EWWW_IMAGE_OPTIMIZER_DOMAIN), 16);
    ?>
</option>
				<option value="4"<?php 
    if (ewww_image_optimizer_get_option('ewww_image_optimizer_optipng_level') == 4) {
        echo ' selected="selected"';
    }
    echo '>' . sprintf(__('Level %d', EWWW_IMAGE_OPTIMIZER_DOMAIN), 4) . ': ' . sprintf(__('%d trials', EWWW_IMAGE_OPTIMIZER_DOMAIN), 24);
    ?>
</option>
				<option value="5"<?php 
    if (ewww_image_optimizer_get_option('ewww_image_optimizer_optipng_level') == 5) {
        echo ' selected="selected"';
    }
    echo '>' . sprintf(__('Level %d', EWWW_IMAGE_OPTIMIZER_DOMAIN), 5) . ': ' . sprintf(__('%d trials', EWWW_IMAGE_OPTIMIZER_DOMAIN), 48);
    ?>
</option>
				<option value="6"<?php 
    if (ewww_image_optimizer_get_option('ewww_image_optimizer_optipng_level') == 6) {
        echo ' selected="selected"';
    }
    echo '>' . sprintf(__('Level %d', EWWW_IMAGE_OPTIMIZER_DOMAIN), 6) . ': ' . sprintf(__('%d trials', EWWW_IMAGE_OPTIMIZER_DOMAIN), 120);
    ?>
</option>
				<option value="7"<?php 
    if (ewww_image_optimizer_get_option('ewww_image_optimizer_optipng_level') == 7) {
        echo ' selected="selected"';
    }
    echo '>' . sprintf(__('Level %d', EWWW_IMAGE_OPTIMIZER_DOMAIN), 7) . ': ' . sprintf(__('%d trials', EWWW_IMAGE_OPTIMIZER_DOMAIN), 240);
    ?>
</option>
				</select> (<?php 
    _e('default', EWWW_IMAGE_OPTIMIZER_DOMAIN);
    ?>
=2)</span>
				<p class="description"><?php 
    _e('According to the author of optipng, 10 trials should satisfy most people, 30 trials should satisfy everyone.', EWWW_IMAGE_OPTIMIZER_DOMAIN);
    ?>
</p></td></tr>
				<tr class="nocloud"><th><label for="ewww_image_optimizer_pngout_level">pngout <?php 
    _e('optimization level', EWWW_IMAGE_OPTIMIZER_DOMAIN);
    ?>
</label></th>
				<td><span><select id="ewww_image_optimizer_pngout_level" name="ewww_image_optimizer_pngout_level">
				<option value="0"<?php 
    if (ewww_image_optimizer_get_option('ewww_image_optimizer_pngout_level') == 0) {
        echo ' selected="selected"';
    }
    echo '>' . sprintf(__('Level %d', EWWW_IMAGE_OPTIMIZER_DOMAIN), 0) . ': ' . __('Xtreme! (Slowest)', EWWW_IMAGE_OPTIMIZER_DOMAIN);
    ?>
</option>
				<option value="1"<?php 
    if (ewww_image_optimizer_get_option('ewww_image_optimizer_pngout_level') == 1) {
        echo ' selected="selected"';
    }
    echo '>' . sprintf(__('Level %d', EWWW_IMAGE_OPTIMIZER_DOMAIN), 1) . ': ' . __('Intense (Slow)', EWWW_IMAGE_OPTIMIZER_DOMAIN);
    ?>
</option>
				<option value="2"<?php 
    if (ewww_image_optimizer_get_option('ewww_image_optimizer_pngout_level') == 2) {
        echo ' selected="selected"';
    }
    echo '>' . sprintf(__('Level %d', EWWW_IMAGE_OPTIMIZER_DOMAIN), 2) . ': ' . __('Longest Match (Fast)', EWWW_IMAGE_OPTIMIZER_DOMAIN);
    ?>
</option>
				<option value="3"<?php 
    if (ewww_image_optimizer_get_option('ewww_image_optimizer_pngout_level') == 3) {
        echo ' selected="selected"';
    }
    echo '>' . sprintf(__('Level %d', EWWW_IMAGE_OPTIMIZER_DOMAIN), 3) . ': ' . __('Huffman Only (Faster)', EWWW_IMAGE_OPTIMIZER_DOMAIN);
    ?>
</option>
				</select> (<?php 
    _e('default', EWWW_IMAGE_OPTIMIZER_DOMAIN);
    ?>
=2)</span>
				<p class="description"><?php 
    printf(__('If you have CPU cycles to spare, go with level %d', EWWW_IMAGE_OPTIMIZER_DOMAIN), 0);
    ?>
</p></td></tr>
				<tr><th><label for="ewww_image_optimizer_png_lossy"><?php 
    _e('Lossy PNG optimization', EWWW_IMAGE_OPTIMIZER_DOMAIN);
    ?>
</label></th><td><input type="checkbox" id="ewww_image_optimizer_png_lossy" name="ewww_image_optimizer_png_lossy" value="true" <?php 
    if (ewww_image_optimizer_get_option('ewww_image_optimizer_png_lossy') == TRUE) {
        ?>
checked="true"<?php 
    }
    ?>
 /> <b><?php 
    _e('WARNING:', EWWW_IMAGE_OPTIMIZER_DOMAIN);
    ?>
</b> <?php 
    _e('While most users will not notice a difference in image quality, lossy means there IS a loss in image quality.', EWWW_IMAGE_OPTIMIZER_DOMAIN);
    ?>
</td></tr>
				<tr><th><label for="ewww_image_optimizer_lossy_skip_full"><?php 
    _e('Exclude full-size images from lossy optimization', EWWW_IMAGE_OPTIMIZER_DOMAIN);
    ?>
</label></th><td><input type="checkbox" id="ewww_image_optimizer_lossy_skip_full" name="ewww_image_optimizer_lossy_skip_full" value="true" <?php 
    if (ewww_image_optimizer_get_option('ewww_image_optimizer_lossy_skip_full') == TRUE) {
        ?>
checked="true"<?php 
    }
    ?>
 /></td></tr>
			</table>
			</div>
			<h3><?php 
    _e('Conversion Settings', EWWW_IMAGE_OPTIMIZER_DOMAIN);
    ?>
</h3>
			<div>
			<p><?php 
    _e('Conversion is only available for images in the Media Library. By default, all images have a link available in the Media Library for one-time conversion. Turning on individual conversion operations below will enable conversion filters any time an image is uploaded or modified.', EWWW_IMAGE_OPTIMIZER_DOMAIN);
    ?>
<br />
				<b><?php 
    _e('NOTE:', EWWW_IMAGE_OPTIMIZER_DOMAIN);
    ?>
</b> <?php 
    _e('The plugin will attempt to update image locations for any posts that contain the images. You may still need to manually update locations/urls for converted images.', EWWW_IMAGE_OPTIMIZER_DOMAIN);
    ?>
 
			</p>
			<table class="form-table">
				<tr><th><label for="ewww_image_optimizer_disable_convert_links"><?php 
    _e('Hide Conversion Links', EWWW_IMAGE_OPTIMIZER_DOMAIN);
    ?>
</label</th><td><input type="checkbox" id="ewww_image_optimizer_disable_convert_links" name="ewww_image_optimizer_disable_convert_links" <?php 
    if (ewww_image_optimizer_get_option('ewww_image_optimizer_disable_convert_links') == TRUE) {
        ?>
checked="true"<?php 
    }
    ?>
 /> <?php 
    _e('Site or Network admins can use this to prevent other users from using the conversion links in the Media Library which bypass the settings below.', EWWW_IMAGE_OPTIMIZER_DOMAIN);
    ?>
</td></tr>
				<tr><th><label for="ewww_image_optimizer_delete_originals"><?php 
    _e('Delete originals', EWWW_IMAGE_OPTIMIZER_DOMAIN);
    ?>
</label></th><td><input type="checkbox" id="ewww_image_optimizer_delete_originals" name="ewww_image_optimizer_delete_originals" <?php 
    if (ewww_image_optimizer_get_option('ewww_image_optimizer_delete_originals') == TRUE) {
        ?>
checked="true"<?php 
    }
    ?>
 /> <?php 
    _e('This will remove the original image from the server after a successful conversion.', EWWW_IMAGE_OPTIMIZER_DOMAIN);
    ?>
</td></tr>
				<tr><th><label for="ewww_image_optimizer_jpg_to_png"><?php 
    printf(__('enable %s to %s conversion', EWWW_IMAGE_OPTIMIZER_DOMAIN), 'JPG', 'PNG');
    ?>
</label></th><td><span><input type="checkbox" id="ewww_image_optimizer_jpg_to_png" name="ewww_image_optimizer_jpg_to_png" <?php 
    if (ewww_image_optimizer_get_option('ewww_image_optimizer_jpg_to_png') == TRUE) {
        ?>
checked="true"<?php 
    }
    ?>
 /> <b><?php 
    _e('WARNING:', EWWW_IMAGE_OPTIMIZER_DOMAIN);
    ?>
</b> <?php 
    _e('Removes metadata and increases cpu usage dramatically.', EWWW_IMAGE_OPTIMIZER_DOMAIN);
    ?>
</span>
				<p class="description"><?php 
    _e('PNG is generally much better than JPG for logos and other images with a limited range of colors. Checking this option will slow down JPG processing significantly, and you may want to enable it only temporarily.', EWWW_IMAGE_OPTIMIZER_DOMAIN);
    ?>
</p></td></tr>
				<tr><th><label for="ewww_image_optimizer_png_to_jpg"><?php 
    printf(__('enable %s to %s conversion', EWWW_IMAGE_OPTIMIZER_DOMAIN), 'PNG', 'JPG');
    ?>
</label></th><td><span><input type="checkbox" id="ewww_image_optimizer_png_to_jpg" name="ewww_image_optimizer_png_to_jpg" <?php 
    if (ewww_image_optimizer_get_option('ewww_image_optimizer_png_to_jpg') == TRUE) {
        ?>
checked="true"<?php 
    }
    ?>
 /> <b><?php 
    _e('WARNING:', EWWW_IMAGE_OPTIMIZER_DOMAIN);
    ?>
</b> <?php 
    _e('This is not a lossless conversion.', EWWW_IMAGE_OPTIMIZER_DOMAIN);
    ?>
</span>
				<p class="description"><?php 
    _e('JPG is generally much better than PNG for photographic use because it compresses the image and discards data. PNGs with transparency are not converted by default.', EWWW_IMAGE_OPTIMIZER_DOMAIN);
    ?>
</p>
				<span><label for="ewww_image_optimizer_jpg_background"> <?php 
    _e('JPG background color:', EWWW_IMAGE_OPTIMIZER_DOMAIN);
    ?>
</label> #<input type="text" id="ewww_image_optimizer_jpg_background" name="ewww_image_optimizer_jpg_background" class="small-text" value="<?php 
    echo ewww_image_optimizer_jpg_background();
    ?>
" /> <span style="padding-left: 12px; font-size: 12px; border: solid 1px #555555; background-color: #<?php 
    echo ewww_image_optimizer_jpg_background();
    ?>
">&nbsp;</span> <?php 
    _e('HEX format (#123def)', EWWW_IMAGE_OPTIMIZER_DOMAIN);
    ?>
.</span>
				<p class="description"><?php 
    _e('Background color is used only if the PNG has transparency. Leave this value blank to skip PNGs with transparency.', EWWW_IMAGE_OPTIMIZER_DOMAIN);
    ?>
</p>
				<span><label for="ewww_image_optimizer_jpg_quality"><?php 
    _e('JPG quality level:', EWWW_IMAGE_OPTIMIZER_DOMAIN);
    ?>
</label> <input type="text" id="ewww_image_optimizer_jpg_quality" name="ewww_image_optimizer_jpg_quality" class="small-text" value="<?php 
    echo ewww_image_optimizer_jpg_quality();
    ?>
" /> <?php 
    _e('Valid values are 1-100.', EWWW_IMAGE_OPTIMIZER_DOMAIN);
    ?>
</span>
				<p class="description"><?php 
    _e('If JPG quality is blank, the plugin will attempt to set the optimal quality level or default to 92. Remember, this is a lossy conversion, so you are losing pixels, and it is not recommended to actually set the level here unless you want noticable loss of image quality.', EWWW_IMAGE_OPTIMIZER_DOMAIN);
    ?>
</p></td></tr>
				<tr><th><label for="ewww_image_optimizer_gif_to_png"><?php 
    printf(__('enable %s to %s conversion', EWWW_IMAGE_OPTIMIZER_DOMAIN), 'GIF', 'PNG');
    ?>
</label></th><td><span><input type="checkbox" id="ewww_image_optimizer_gif_to_png" name="ewww_image_optimizer_gif_to_png" <?php 
    if (ewww_image_optimizer_get_option('ewww_image_optimizer_gif_to_png') == TRUE) {
        ?>
checked="true"<?php 
    }
    ?>
 /> <?php 
    _e('No warnings here, just do it.', EWWW_IMAGE_OPTIMIZER_DOMAIN);
    ?>
</span>
				<p class="description"> <?php 
    _e('PNG is generally better than GIF, but animated images cannot be converted.', EWWW_IMAGE_OPTIMIZER_DOMAIN);
    ?>
</p></td></tr>
			</table>
			</div></div>
			<p class="submit"><input type="submit" class="button-primary" value="<?php 
    _e('Save Changes', EWWW_IMAGE_OPTIMIZER_DOMAIN);
    ?>
" /></p>
		</form>
		<p>I recommend hosting your Wordpress site with <a href="http://www.dreamhost.com/r.cgi?132143">Dreamhost.com</a> or <a href="http://www.bluehost.com/track/nosilver4u">Bluehost.com</a>. Using these referral links will allow you to support future development of this plugin: <a href=http://www.dreamhost.com/r.cgi?132143">Dreamhost</a> | <a href="http://www.bluehost.com/track/nosilver4u">Bluehost</a>. Alternatively, you can contribute directly by <a href="https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=MKMQKCBFFG3WW">donating with Paypal</a>.</p>
	</div>
	<?php 
}
コード例 #3
0
ファイル: bulk.php プロジェクト: Rudchyk/wp-framework
function ewww_image_optimizer_bulk_loop()
{
    global $ewww_debug;
    global $ewww_exceed;
    // verify that an authorized user has started the optimizer
    $permissions = apply_filters('ewww_image_optimizer_bulk_permissions', '');
    if (!wp_verify_nonce($_REQUEST['ewww_wpnonce'], 'ewww-image-optimizer-bulk') || !current_user_can($permissions)) {
        wp_die(__('Cheatin&#8217; eh?', EWWW_IMAGE_OPTIMIZER_DOMAIN));
    }
    if (!empty($_REQUEST['ewww_sleep'])) {
        sleep($_REQUEST['ewww_sleep']);
    }
    // retrieve the time when the optimizer starts
    $started = microtime(true);
    // get the attachment ID of the current attachment
    $attachment = $_POST['ewww_attachment'];
    // get the 'bulk attachments' with a list of IDs remaining
    $attachments = get_option('ewww_image_optimizer_bulk_attachments');
    $meta = wp_get_attachment_metadata($attachment, true);
    // do the optimization for the current attachment (including resizes)
    $meta = ewww_image_optimizer_resize_from_meta_data($meta, $attachment, false);
    if (!empty($ewww_exceed)) {
        echo '-9exceeded';
        die;
    }
    if (!empty($meta['file'])) {
        // output the filename (and path relative to 'uploads' folder)
        printf("<p>" . __('Optimized image:', EWWW_IMAGE_OPTIMIZER_DOMAIN) . " <strong>%s</strong><br>", esc_html($meta['file']));
    } else {
        printf("<p>" . __('Skipped image, ID:', EWWW_IMAGE_OPTIMIZER_DOMAIN) . " <strong>%s</strong><br>", $attachment);
    }
    if (!empty($meta['ewww_image_optimizer'])) {
        // tell the user what the results were for the original image
        printf(__('Full size – %s', EWWW_IMAGE_OPTIMIZER_DOMAIN) . "<br>", $meta['ewww_image_optimizer']);
    }
    // check to see if there are resized version of the image
    if (isset($meta['sizes']) && is_array($meta['sizes'])) {
        // cycle through each resize
        foreach ($meta['sizes'] as $size) {
            if (!empty($size['ewww_image_optimizer'])) {
                // output the results for the current resized version
                printf("%s – %s<br>", $size['file'], $size['ewww_image_optimizer']);
            }
        }
    }
    // calculate how much time has elapsed since we started
    $elapsed = microtime(true) - $started;
    // output how much time has elapsed since we started
    printf(__('Elapsed: %.3f seconds', EWWW_IMAGE_OPTIMIZER_DOMAIN) . "</p>", $elapsed);
    global $ewww_attachment;
    $ewww_attachment['id'] = $attachment;
    $ewww_attachment['meta'] = $meta;
    add_filter('w3tc_cdn_update_attachment_metadata', 'ewww_image_optimizer_w3tc_update_files');
    // update the metadata for the current attachment
    wp_update_attachment_metadata($attachment, $meta);
    // remove the first element from the $attachments array
    if (!empty($attachments)) {
        array_shift($attachments);
    }
    // store the updated list of attachment IDs back in the 'bulk_attachments' option
    update_option('ewww_image_optimizer_bulk_attachments', $attachments);
    if (ewww_image_optimizer_get_option('ewww_image_optimizer_debug')) {
        echo '<div style="background-color:#ffff99;">' . $ewww_debug . '</div>';
    }
    ewww_image_optimizer_debug_log();
    ewwwio_memory(__FUNCTION__);
    die;
}
コード例 #4
0
function ewww_image_optimizer_webp_create($file, $orig_size, $type, $tool)
{
    global $ewww_debug;
    $ewww_debug .= '<b>ewww_image_optimizer_webp_create()</b><br>';
    // change the file extension
    $webpfile = $file . '.webp';
    if (file_exists($webpfile) || !ewww_image_optimizer_get_option('ewww_image_optimizer_webp')) {
        return;
    }
    if (empty($tool)) {
        ewww_image_optimizer_cloud_optimizer($file, $type, false, $webpfile, 'image/webp');
    } else {
        // check to see if 'nice' exists
        $nice = ewww_image_optimizer_find_binary('nice', 'n');
        switch ($type) {
            case 'image/jpeg':
                exec("{$nice} " . $tool . " -q  85 -quiet " . ewww_image_optimizer_escapeshellarg($file) . " -o " . ewww_image_optimizer_escapeshellarg($webpfile) . ' 2>&1', $cli_output);
                break;
            case 'image/png':
                exec("{$nice} " . $tool . " -lossless -quiet " . ewww_image_optimizer_escapeshellarg($file) . " -o " . ewww_image_optimizer_escapeshellarg($webpfile) . ' 2>&1', $cli_output);
                break;
        }
    }
    if (file_exists($webpfile) && $orig_size < filesize($webpfile)) {
        $ewww_debug .= 'webp file was too big, deleting<br>';
        unlink($webpfile);
    }
    ewwwio_memory(__FUNCTION__);
}
コード例 #5
0
        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')) {
                ewww_image_optimizer_cloud_verify();
                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>&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>
                <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;
        }
コード例 #6
0
ファイル: background.php プロジェクト: kanei/vantuch.cz
 protected function task($item)
 {
     session_write_close();
     $max_attempts = 15;
     if (empty($item['attempts'])) {
         $item['attempts'] = 0;
     }
     $id = $item['id'];
     ewwwio_debug_message("background processing nextgen2: {$id}");
     // creating the 'registry' object for working with nextgen
     $registry = C_Component_Registry::get_instance();
     // creating a database storage object from the 'registry' object
     $storage = $registry->get_utility('I_Gallery_Storage');
     // get an image object
     $image = $storage->object->_image_mapper->find($id);
     if (!is_object($image) && $item['attempts'] < $max_attempts) {
         $item['attempts']++;
         sleep(4);
         ewwwio_debug_message("could not retrieve image, requeueing {$item['attempts']}");
         ewww_image_optimizer_debug_log();
         return $item;
     } elseif (empty($image)) {
         ewwwio_debug_message("could not retrieve image, out of attempts");
         ewww_image_optimizer_debug_log();
         delete_transient('ewwwio-background-in-progress-ngg-' . $id);
         return false;
     }
     global $ewwwngg;
     $ewwwngg->ewww_added_new_image($image, $storage);
     delete_transient('ewwwio-background-in-progress-ngg-' . $id);
     sleep(ewww_image_optimizer_get_option('ewww_image_optimizer_delay'));
     ewww_image_optimizer_debug_log();
     return false;
 }
コード例 #7
0
 function generate_image_size($image, $size, $params = null, $skip_defaults = false)
 {
     ewwwio_debug_message('<b>' . __FUNCTION__ . '()</b>');
     global $ewww_defer;
     if (!defined('EWWW_IMAGE_OPTIMIZER_CLOUD')) {
         ewww_image_optimizer_init();
     }
     $success = $this->call_parent('generate_image_size', $image, $size, $params, $skip_defaults);
     if ($success) {
         $filename = $success->fileName;
         if ($ewww_defer && ewww_image_optimizer_get_option('ewww_image_optimizer_defer')) {
             ewww_image_optimizer_add_deferred_attachment("file,{$filename}");
             return $saved;
         }
         ewww_image_optimizer($filename);
         ewwwio_debug_message("nextgen dynamic thumb saved: {$filename}");
         $image_size = ewww_image_optimizer_filesize($filename);
         ewwwio_debug_message("optimized size: {$image_size}");
     }
     ewww_image_optimizer_debug_log();
     ewwwio_memory(__FUNCTION__);
     return $success;
 }
コード例 #8
0
 function ewww_manage_image_custom_column($column_name, $id)
 {
     // check to make sure we're outputing our custom column
     if ($column_name == 'ewww_image_optimizer') {
         // get the metadata
         $meta = new flagMeta($id);
         if (ewww_image_optimizer_get_option('ewww_image_optimizer_debug')) {
             $print_meta = print_r($meta->image->meta_data, TRUE);
             $print_meta = preg_replace(array('/ /', '/\\n+/'), array('&nbsp;', '<br />'), $print_meta);
             echo '<div style="background-color:#ffff99;font-size: 10px;padding: 10px;margin:-10px -10px 10px;line-height: 1.1em">' . $print_meta . '</div>';
         }
         // grab the image status from the meta
         $status = $meta->image->meta_data['ewww_image_optimizer'];
         $msg = '';
         // get the image path from the meta
         $file_path = $meta->image->imagePath;
         // get the mimetype
         $type = ewww_image_optimizer_mimetype($file_path, 'i');
         // get the file size
         $file_size = size_format(filesize($file_path), 2);
         $file_size = str_replace('B ', 'B', $file_size);
         $valid = true;
         // if we don't have a valid tool for the image type, output the appropriate message
         switch ($type) {
             case 'image/jpeg':
                 if (!EWWW_IMAGE_OPTIMIZER_JPEGTRAN && !EWWW_IMAGE_OPTIMIZER_CLOUD) {
                     $valid = false;
                     $msg = '<br>' . sprintf(__('%s is missing', EWWW_IMAGE_OPTIMIZER_DOMAIN), '<em>jpegtran</em>');
                 }
                 break;
             case 'image/png':
                 if (!EWWW_IMAGE_OPTIMIZER_PNGOUT && !EWWW_IMAGE_OPTIMIZER_OPTIPNG && !EWWW_IMAGE_OPTIMIZER_CLOUD) {
                     $valid = false;
                     $msg = '<br>' . sprintf(__('%s is missing', EWWW_IMAGE_OPTIMIZER_DOMAIN), '<em>optipng/pngout</em>');
                 }
                 break;
             case 'image/gif':
                 if (!EWWW_IMAGE_OPTIMIZER_GIFSICLE && !EWWW_IMAGE_OPTIMIZER_CLOUD) {
                     $valid = false;
                     $msg = '<br>' . sprintf(__('%s is missing', EWWW_IMAGE_OPTIMIZER_DOMAIN), '<em>gifsicle</em>');
                 }
                 break;
             default:
                 $valid = false;
         }
         // let user know if the file type is unsupported
         if ($valid == false) {
             _e('Unsupported file type', EWWW_IMAGE_OPTIMIZER_DOMAIN);
             return;
         }
         // output the image status if we know it
         if (!empty($status)) {
             echo $status;
             echo "<br>" . sprintf(__('Image Size: %s', EWWW_IMAGE_OPTIMIZER_DOMAIN), $file_size);
             printf("<br><a href=\"admin.php?action=ewww_flag_manual&amp;force=1&amp;attachment_ID=%d\">%s</a>", $id, __('Re-optimize', EWWW_IMAGE_OPTIMIZER_DOMAIN));
             // otherwise, tell the user that they can optimize the image now
         } else {
             _e('Not processed', EWWW_IMAGE_OPTIMIZER_DOMAIN);
             echo "<br>" . sprintf(__('Image Size: %s', EWWW_IMAGE_OPTIMIZER_DOMAIN), $file_size);
             printf("<br><a href=\"admin.php?action=ewww_flag_manual&amp;attachment_ID=%d\">%s</a>", $id, __('Optimize now!', EWWW_IMAGE_OPTIMIZER_DOMAIN));
         }
     }
 }
コード例 #9
0
    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>&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>
                <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;
    }
コード例 #10
0
function ewww_image_optimizer_aux_images_script($hook)
{
    // make sure we are being called from the proper page
    if ('ewww-image-optimizer-auto' !== $hook && empty($_REQUEST['scan'])) {
        return;
    }
    global $ewww_debug;
    global $wpdb;
    $ewww_debug .= "<b>ewww_image_optimizer_aux_images_script()</b><br>";
    // initialize the $attachments variable for auxiliary images
    $attachments = null;
    // check the 'bulk resume' option
    $resume = get_option('ewww_image_optimizer_aux_resume');
    // check if there is a previous bulk operation to resume
    if (!empty($resume)) {
        // retrieve the attachment IDs that have not been finished from the 'bulk attachments' option
        $attachments = get_option('ewww_image_optimizer_aux_attachments');
    } else {
        // collect a list of images from the current theme
        $child_path = get_stylesheet_directory();
        $parent_path = get_template_directory();
        $attachments = ewww_image_optimizer_image_scan($child_path);
        if ($child_path !== $parent_path) {
            $attachments = array_merge($attachments, ewww_image_optimizer_image_scan($parent_path));
        }
        // collect a list of images in auxiliary folders provided by user
        if ($aux_paths = ewww_image_optimizer_get_option('ewww_image_optimizer_aux_paths')) {
            foreach ($aux_paths as $aux_path) {
                $attachments = array_merge($attachments, ewww_image_optimizer_image_scan($aux_path));
            }
        }
        // collect a list of images for buddypress
        if (is_plugin_active('buddypress/bp-loader.php') || function_exists('is_plugin_active_for_network') && is_plugin_active_for_network('buddypress/bp-loader.php')) {
            // get the value of the wordpress upload directory
            $upload_dir = wp_upload_dir();
            // scan the 'avatars' and 'group-avatars' folders for images
            $attachments = array_merge($attachments, ewww_image_optimizer_image_scan($upload_dir['basedir'] . '/avatars'), ewww_image_optimizer_image_scan($upload_dir['basedir'] . '/group-avatars'));
        }
        if (is_plugin_active('buddypress-activity-plus/bpfb.php') || function_exists('is_plugin_active_for_network') && is_plugin_active_for_network('buddypress-activity-plus/bpfb.php')) {
            // get the value of the wordpress upload directory
            $upload_dir = wp_upload_dir();
            // scan the 'avatars' and 'group-avatars' folders for images
            $attachments = array_merge($attachments, ewww_image_optimizer_image_scan($upload_dir['basedir'] . '/bpfb'));
        }
        if (is_plugin_active('wp-symposium/wp-symposium.php') || function_exists('is_plugin_active_for_network') && is_plugin_active_for_network('wp-symposium/wp-symposium.php')) {
            $attachments = array_merge($attachments, ewww_image_optimizer_image_scan(get_option('symposium_img_path')));
        }
        if (is_plugin_active('ml-slider/ml-slider.php') || function_exists('is_plugin_active_for_network') && is_plugin_active_for_network('ml-slider/ml-slider.php')) {
            $slide_paths = array();
            $sliders = get_posts(array('numberposts' => -1, 'post_type' => 'ml-slider', 'post_status' => 'any', 'fields' => 'ids'));
            foreach ($sliders as $slider) {
                $slides = get_posts(array('numberposts' => -1, 'orderby' => 'menu_order', 'order' => 'ASC', 'post_type' => 'attachment', 'post_status' => 'inherit', 'fields' => 'ids', 'tax_query' => array(array('taxonomy' => 'ml-slider', 'field' => 'slug', 'terms' => $slider))));
                foreach ($slides as $slide) {
                    $backup_sizes = get_post_meta($slide, '_wp_attachment_backup_sizes', true);
                    $type = get_post_meta($slide, 'ml-slider_type', true);
                    $type = $type ? $type : 'image';
                    // backwards compatibility, fall back to 'image'
                    if ($type === 'image') {
                        foreach ($backup_sizes as $backup_size => $meta) {
                            if (preg_match('/resized-/', $backup_size)) {
                                $path = $meta['path'];
                                $image_size = filesize($path);
                                $query = $wpdb->prepare("SELECT id FROM {$wpdb->ewwwio_images} WHERE BINARY path LIKE %s AND image_size LIKE '{$image_size}'", $path);
                                $already_optimized = $wpdb->get_results($query);
                                $mimetype = ewww_image_optimizer_mimetype($path, 'i');
                                if (preg_match('/^image\\/(jpeg|png|gif)/', $mimetype) && empty($already_optimized)) {
                                    $slide_paths[] = $path;
                                }
                            }
                        }
                    }
                }
            }
            $attachments = array_merge($attachments, $slide_paths);
        }
        // store the filenames we retrieved in the 'bulk_attachments' option so we can keep track of our progress in the database
        update_option('ewww_image_optimizer_aux_attachments', $attachments);
    }
    ewww_image_optimizer_debug_log();
    // submit a couple variables to the javascript to work with
    $attachments = json_encode($attachments);
    if (!empty($_REQUEST['scan'])) {
        if (empty($attachments)) {
            _e('Nothing to optimize', EWWW_IMAGE_OPTIMIZER_DOMAIN);
        } else {
            echo $attachments;
        }
        die;
    } else {
        return;
    }
}
コード例 #11
0
ファイル: aux-optimize.php プロジェクト: kanei/vantuch.cz
function ewww_image_optimizer_aux_images_script($hook)
{
    ewwwio_debug_message('<b>' . __FUNCTION__ . '()</b>');
    // make sure we are being called from the proper page
    if ('ewww-image-optimizer-auto' !== $hook && empty($_REQUEST['ewww_scan'])) {
        return;
    }
    session_write_close();
    global $wpdb;
    if (!empty($_REQUEST['ewww_force'])) {
        ewwwio_debug_message('forcing re-optimize: true');
    }
    // initialize the $attachments variable for auxiliary images
    $attachments = null;
    // check the 'bulk resume' option
    $resume = get_option('ewww_image_optimizer_aux_resume');
    // check if there is a previous bulk operation to resume
    if (!empty($resume)) {
        ewwwio_debug_message('resuming from where we left off, no scanning needed');
        // retrieve the attachment IDs that have not been finished from the 'bulk attachments' option
        $attachments = get_option('ewww_image_optimizer_aux_attachments');
    } else {
        ewwwio_debug_message('getting fresh list of files to optimize');
        $attachments = array();
        // collect a list of images from the current theme
        $child_path = get_stylesheet_directory();
        $parent_path = get_template_directory();
        $attachments = ewww_image_optimizer_image_scan($child_path);
        if ($child_path !== $parent_path) {
            $attachments = array_merge($attachments, ewww_image_optimizer_image_scan($parent_path));
        }
        if (!function_exists('is_plugin_active')) {
            // need to include the plugin library for the is_plugin_active function
            require_once ABSPATH . 'wp-admin/includes/plugin.php';
        }
        // collect a list of images for buddypress
        if (is_plugin_active('buddypress/bp-loader.php') || is_plugin_active_for_network('buddypress/bp-loader.php')) {
            // get the value of the wordpress upload directory
            $upload_dir = wp_upload_dir();
            // scan the 'avatars' and 'group-avatars' folders for images
            $attachments = array_merge($attachments, ewww_image_optimizer_image_scan($upload_dir['basedir'] . '/avatars'), ewww_image_optimizer_image_scan($upload_dir['basedir'] . '/group-avatars'));
        }
        if (is_plugin_active('buddypress-activity-plus/bpfb.php') || is_plugin_active_for_network('buddypress-activity-plus/bpfb.php')) {
            // get the value of the wordpress upload directory
            $upload_dir = wp_upload_dir();
            // scan the 'avatars' and 'group-avatars' folders for images
            $attachments = array_merge($attachments, ewww_image_optimizer_image_scan($upload_dir['basedir'] . '/bpfb'));
        }
        if (is_plugin_active('grand-media/grand-media.php') || is_plugin_active_for_network('grand-media/grand-media.php')) {
            // scan the grand media folder for images
            $attachments = array_merge($attachments, ewww_image_optimizer_image_scan(WP_CONTENT_DIR . '/grand-media'));
        }
        if (is_plugin_active('wp-symposium/wp-symposium.php') || is_plugin_active_for_network('wp-symposium/wp-symposium.php')) {
            $attachments = array_merge($attachments, ewww_image_optimizer_image_scan(get_option('symposium_img_path')));
        }
        if (is_plugin_active('ml-slider/ml-slider.php') || is_plugin_active_for_network('ml-slider/ml-slider.php')) {
            $slide_paths = array();
            $slides = $wpdb->get_col("\n\t\t\t\tSELECT wpposts.ID \n\t\t\t\tFROM {$wpdb->posts} wpposts \n\t\t\t\tINNER JOIN {$wpdb->term_relationships} term_relationships\n\t\t\t\t\t\tON wpposts.ID = term_relationships.object_id\n\t\t\t\tINNER JOIN {$wpdb->terms} wpterms \n\t\t\t\t\t\tON term_relationships.term_taxonomy_id = wpterms.term_id\n\t\t\t\tINNER JOIN {$wpdb->term_taxonomy} term_taxonomy\n\t\t\t\t\t\tON wpterms.term_id = term_taxonomy.term_id\n\t\t\t\tWHERE \tterm_taxonomy.taxonomy = 'ml-slider'\n\t\t\t\t\tAND wpposts.post_type = 'attachment'\n\t\t\t\t");
            foreach ($slides as $slide) {
                $backup_sizes = get_post_meta($slide, '_wp_attachment_backup_sizes', true);
                $type = get_post_meta($slide, 'ml-slider_type', true);
                $type = $type ? $type : 'image';
                // backwards compatibility, fall back to 'image'
                if ($type === 'image') {
                    foreach ($backup_sizes as $backup_size => $meta) {
                        if (preg_match('/resized-/', $backup_size)) {
                            $path = $meta['path'];
                            $image_size = ewww_image_optimizer_filesize($path);
                            if (!$image_size) {
                                continue;
                            }
                            $already_optimized = ewww_image_optimizer_find_already_optimized($path);
                            $mimetype = ewww_image_optimizer_mimetype($path, 'i');
                            if (preg_match('/^image\\/(jpeg|png|gif)/', $mimetype) && empty($already_optimized)) {
                                $slide_paths[] = $path;
                            }
                        }
                    }
                }
            }
            $attachments = array_merge($attachments, $slide_paths);
        }
        // collect a list of images in auxiliary folders provided by user
        if ($aux_paths = ewww_image_optimizer_get_option('ewww_image_optimizer_aux_paths')) {
            foreach ($aux_paths as $aux_path) {
                $attachments = array_merge($attachments, ewww_image_optimizer_image_scan($aux_path));
            }
        }
        // scan images in two most recent media library folders if the option is enabled, and this is a scheduled optimization
        if ('ewww-image-optimizer-auto' == $hook && ewww_image_optimizer_get_option('ewww_image_optimizer_include_media_paths')) {
            // retrieve the location of the wordpress upload folder
            $upload_dir = wp_upload_dir();
            // retrieve the path of the upload folder
            $upload_path = $upload_dir['basedir'];
            $this_month = date('m');
            $this_year = date('Y');
            $attachments = array_merge($attachments, ewww_image_optimizer_image_scan("{$upload_path}/{$this_year}/{$this_month}/"));
            if (class_exists('DateTime')) {
                $date = new DateTime();
                $date->sub(new DateInterval('P1M'));
                $last_year = $date->format('Y');
                $last_month = $date->format('m');
                $attachments = array_merge($attachments, ewww_image_optimizer_image_scan("{$upload_path}/{$last_year}/{$last_month}/"));
            }
        }
        // store the filenames we retrieved in the 'bulk_attachments' option so we can keep track of our progress in the database
        update_option('ewww_image_optimizer_aux_attachments', $attachments);
        ewwwio_debug_message('found ' . count($attachments) . ' images to optimize while scanning');
    }
    ewww_image_optimizer_debug_log();
    if (!empty($_REQUEST['ewww_scan'])) {
        echo count($attachments);
        ewwwio_memory(__FUNCTION__);
        die;
    } else {
        ewwwio_memory(__FUNCTION__);
        return;
    }
}
コード例 #12
0
        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;
                }
            }
            // retrieve the attachments array from the db
            $attachments = get_option('ewww_image_optimizer_bulk_ngg_attachments');
            // make sure there are some attachments to process
            if (count($attachments) < 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>
                <div id="ewww-bulk-forms">
                <p class="ewww-bulk-info"><?php 
            printf(esc_html__('We have %d images to optimize.', EWWW_IMAGE_OPTIMIZER_DOMAIN), count($attachments));
            ?>
<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="hidden" id="ewww-delay" name="ewww-delay" value="0">
                        <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 (!empty($_REQUEST['ewww_inline'])) {
                die;
            }
            return;
        }
コード例 #13
0
ファイル: aux-optimize.php プロジェクト: jrald1291/atu
function ewww_image_optimizer_aux_images_script($hook)
{
    // make sure we are being called from the proper page
    if ('ewww-image-optimizer-auto' !== $hook && empty($_REQUEST['ewww_scan'])) {
        return;
    }
    global $ewww_debug;
    global $wpdb;
    $ewww_debug .= "<b>ewww_image_optimizer_aux_images_script()</b><br>";
    if (!empty($_REQUEST['ewww_force'])) {
        $ewww_debug .= "forcing re-optimize: true<br>";
    }
    // initialize the $attachments variable for auxiliary images
    $attachments = null;
    // check the 'bulk resume' option
    $resume = get_option('ewww_image_optimizer_aux_resume');
    // check if there is a previous bulk operation to resume
    if (!empty($resume)) {
        // retrieve the attachment IDs that have not been finished from the 'bulk attachments' option
        $attachments = get_option('ewww_image_optimizer_aux_attachments');
    } else {
        $attachments = array();
        // collect a list of images from the current theme
        $child_path = get_stylesheet_directory();
        $parent_path = get_template_directory();
        $attachments = ewww_image_optimizer_image_scan($child_path);
        if ($child_path !== $parent_path) {
            $attachments = array_merge($attachments, ewww_image_optimizer_image_scan($parent_path));
        }
        if (!function_exists('is_plugin_active')) {
            // need to include the plugin library for the is_plugin_active function
            require_once ABSPATH . 'wp-admin/includes/plugin.php';
        }
        // collect a list of images for buddypress
        if (is_plugin_active('buddypress/bp-loader.php') || function_exists('is_plugin_active_for_network') && is_plugin_active_for_network('buddypress/bp-loader.php')) {
            // get the value of the wordpress upload directory
            $upload_dir = wp_upload_dir();
            // scan the 'avatars' and 'group-avatars' folders for images
            $attachments = array_merge($attachments, ewww_image_optimizer_image_scan($upload_dir['basedir'] . '/avatars'), ewww_image_optimizer_image_scan($upload_dir['basedir'] . '/group-avatars'));
        }
        if (is_plugin_active('buddypress-activity-plus/bpfb.php') || function_exists('is_plugin_active_for_network') && is_plugin_active_for_network('buddypress-activity-plus/bpfb.php')) {
            // get the value of the wordpress upload directory
            $upload_dir = wp_upload_dir();
            // scan the 'avatars' and 'group-avatars' folders for images
            $attachments = array_merge($attachments, ewww_image_optimizer_image_scan($upload_dir['basedir'] . '/bpfb'));
        }
        if (is_plugin_active('grand-media/grand-media.php') || function_exists('is_plugin_active_for_network') && is_plugin_active_for_network('grand-media/grand-media.php')) {
            // scan the grand media folder for images
            $attachments = array_merge($attachments, ewww_image_optimizer_image_scan(WP_CONTENT_DIR . '/grand-media'));
        }
        if (is_plugin_active('wp-symposium/wp-symposium.php') || function_exists('is_plugin_active_for_network') && is_plugin_active_for_network('wp-symposium/wp-symposium.php')) {
            $attachments = array_merge($attachments, ewww_image_optimizer_image_scan(get_option('symposium_img_path')));
        }
        if (is_plugin_active('ml-slider/ml-slider.php') || function_exists('is_plugin_active_for_network') && is_plugin_active_for_network('ml-slider/ml-slider.php')) {
            $slide_paths = array();
            $sliders = get_posts(array('numberposts' => -1, 'post_type' => 'ml-slider', 'post_status' => 'any', 'fields' => 'ids'));
            foreach ($sliders as $slider) {
                $slides = get_posts(array('numberposts' => -1, 'orderby' => 'menu_order', 'order' => 'ASC', 'post_type' => 'attachment', 'post_status' => 'inherit', 'fields' => 'ids', 'tax_query' => array(array('taxonomy' => 'ml-slider', 'field' => 'slug', 'terms' => $slider))));
                foreach ($slides as $slide) {
                    $backup_sizes = get_post_meta($slide, '_wp_attachment_backup_sizes', true);
                    $type = get_post_meta($slide, 'ml-slider_type', true);
                    $type = $type ? $type : 'image';
                    // backwards compatibility, fall back to 'image'
                    if ($type === 'image') {
                        foreach ($backup_sizes as $backup_size => $meta) {
                            if (preg_match('/resized-/', $backup_size)) {
                                $path = $meta['path'];
                                $image_size = filesize($path);
                                $query = $wpdb->prepare("SELECT id FROM {$wpdb->ewwwio_images} WHERE path LIKE %s AND image_size LIKE '{$image_size}'", $path);
                                $optimized_query = $wpdb->get_results($query, ARRAY_A);
                                if (!empty($optimized_query)) {
                                    foreach ($optimized_query as $image) {
                                        if ($image['path'] != $path) {
                                            $ewww_debug .= "{$image['path']} does not match {$path}, continuing our search<br>";
                                        } else {
                                            $already_optimized = $image;
                                        }
                                    }
                                }
                                $mimetype = ewww_image_optimizer_mimetype($path, 'i');
                                if (preg_match('/^image\\/(jpeg|png|gif)/', $mimetype) && empty($already_optimized)) {
                                    $slide_paths[] = $path;
                                }
                            }
                        }
                    }
                }
            }
            $attachments = array_merge($attachments, $slide_paths);
        }
        // collect a list of images in auxiliary folders provided by user
        if ($aux_paths = ewww_image_optimizer_get_option('ewww_image_optimizer_aux_paths')) {
            foreach ($aux_paths as $aux_path) {
                $attachments = array_merge($attachments, ewww_image_optimizer_image_scan($aux_path));
            }
        }
        // scan images in two most recent media library folders if the option is enabled, and this is a scheduled optimization
        if ('ewww-image-optimizer-auto' == $hook && ewww_image_optimizer_get_option('ewww_image_optimizer_include_media_paths')) {
            // retrieve the location of the wordpress upload folder
            $upload_dir = wp_upload_dir();
            // retrieve the path of the upload folder
            $upload_path = $upload_dir['basedir'];
            $this_month = date('m');
            $this_year = date('Y');
            $attachments = array_merge($attachments, ewww_image_optimizer_image_scan("{$upload_path}/{$this_year}/{$this_month}/"));
            if (class_exists('DateTime')) {
                $date = new DateTime();
                $date->sub(new DateInterval('P1M'));
                $last_year = $date->format('Y');
                $last_month = $date->format('m');
                $attachments = array_merge($attachments, ewww_image_optimizer_image_scan("{$upload_path}/{$last_year}/{$last_month}/"));
            }
        }
        // store the filenames we retrieved in the 'bulk_attachments' option so we can keep track of our progress in the database
        update_option('ewww_image_optimizer_aux_attachments', $attachments);
    }
    ewww_image_optimizer_debug_log();
    // submit a couple variables to the javascript to work with
    $attachments = json_encode($attachments);
    if (!empty($_REQUEST['ewww_scan'])) {
        if (empty($attachments)) {
            _e('Nothing to optimize', EWWW_IMAGE_OPTIMIZER_DOMAIN);
        } else {
            echo $attachments;
        }
        ewwwio_memory(__FUNCTION__);
        die;
    } else {
        ewwwio_memory(__FUNCTION__);
        return;
    }
}
コード例 #14
0
function ewwwio_debug_message($message)
{
    if (ewww_image_optimizer_get_option('ewww_image_optimizer_debug')) {
        global $ewww_debug;
        $ewww_debug .= "{$message}<br>";
    }
}
コード例 #15
0
 function ewww_ngg_bulk_loop()
 {
     if (!wp_verify_nonce($_REQUEST['_wpnonce'], 'ewww-image-optimizer-bulk') || !current_user_can('edit_others_posts')) {
         wp_die(__('Cheatin&#8217; eh?', EWWW_IMAGE_OPTIMIZER_DOMAIN));
     }
     // need this file to work with metadata
     require_once WP_CONTENT_DIR . '/plugins/nextgen-gallery/lib/meta.php';
     // find out what time we started, in microseconds
     $started = microtime(true);
     $id = $_POST['attachment'];
     // get the metadata
     $meta = new nggMeta($id);
     // retrieve the filepath
     $file_path = $meta->image->imagePath;
     // run the optimizer on the current image
     $fres = ewww_image_optimizer($file_path, 2, false, false, ewww_image_optimizer_get_option('ewww_image_optimizer_lossy_skip_full'));
     // update the metadata of the optimized image
     nggdb::update_image_meta($id, array('ewww_image_optimizer' => $fres[1]));
     // output the results of the optimization
     printf("<p>" . __('Optimized image:', EWWW_IMAGE_OPTIMIZER_DOMAIN) . " <strong>%s</strong><br>", $meta->image->filename);
     printf(__('Full size - %s', EWWW_IMAGE_OPTIMIZER_DOMAIN) . "<br>", $fres[1]);
     // get the filepath of the thumbnail image
     $thumb_path = $meta->image->thumbPath;
     // run the optimization on the thumbnail
     $tres = ewww_image_optimizer($thumb_path, 2, false, true);
     // output the results of the thumb optimization
     printf(__('Thumbnail - %s', EWWW_IMAGE_OPTIMIZER_DOMAIN) . "<br>", $tres[1]);
     // outupt how much time we spent
     $elapsed = microtime(true) - $started;
     printf(__('Elapsed: %.3f seconds', EWWW_IMAGE_OPTIMIZER_DOMAIN) . "</p>", $elapsed);
     // get the list of attachments remaining from the db
     $attachments = get_option('ewww_image_optimizer_bulk_ngg_attachments');
     // remove the first item
     if (!empty($attachments)) {
         array_shift($attachments);
     }
     // and store the list back in the db
     update_option('ewww_image_optimizer_bulk_ngg_attachments', $attachments);
     die;
 }
コード例 #16
0
 function ewww_manage_image_custom_column($column_name, $id)
 {
     // check to make sure we're outputing our custom column
     if ($column_name == 'ewww_image_optimizer') {
         // get the metadata
         $meta = new flagMeta($id);
         if (ewww_image_optimizer_get_option('ewww_image_optimizer_debug')) {
             $print_meta = print_r($meta->image->meta_data, TRUE);
             $print_meta = preg_replace(array('/ /', '/\\n+/'), array('&nbsp;', '<br />'), esc_html($print_meta));
             echo '<div style="background-color:#ffff99;font-size: 10px;padding: 10px;margin:-10px -10px 10px;line-height: 1.1em">' . $print_meta . '</div>';
         }
         // grab the image status from the meta
         if (empty($meta->image->meta_data['ewww_image_optimizer'])) {
             $status = '';
         } else {
             $status = $meta->image->meta_data['ewww_image_optimizer'];
         }
         $msg = '';
         // get the image path from the meta
         $file_path = $meta->image->imagePath;
         // get the mimetype
         $type = ewww_image_optimizer_mimetype($file_path, 'i');
         // get the file size
         $file_size = size_format(ewww_image_optimizer_filesize($file_path), 2);
         $file_size = str_replace('B ', 'B', $file_size);
         $valid = true;
         // if we don't have a valid tool for the image type, output the appropriate message
         $skip = ewww_image_optimizer_skip_tools();
         switch ($type) {
             case 'image/jpeg':
                 if (!EWWW_IMAGE_OPTIMIZER_JPEGTRAN && !$skip['jpegtran']) {
                     $valid = false;
                     $msg = '<br>' . wp_kses(sprintf(__('%s is missing', EWWW_IMAGE_OPTIMIZER_DOMAIN), '<em>jpegtran</em>'), array('em' => array()));
                 }
                 break;
             case 'image/png':
                 if (!EWWW_IMAGE_OPTIMIZER_PNGOUT && !EWWW_IMAGE_OPTIMIZER_OPTIPNG && !$skip['optipng'] && !$skip['pngout']) {
                     $valid = false;
                     $msg = '<br>' . wp_kses(sprintf(__('%s is missing', EWWW_IMAGE_OPTIMIZER_DOMAIN), '<em>optipng/pngout</em>'), array('em' => array()));
                 }
                 break;
             case 'image/gif':
                 if (!EWWW_IMAGE_OPTIMIZER_GIFSICLE && !$skip['gifsicle']) {
                     $valid = false;
                     $msg = '<br>' . wp_kses(sprintf(__('%s is missing', EWWW_IMAGE_OPTIMIZER_DOMAIN), '<em>gifsicle</em>'), array('em' => array()));
                 }
                 break;
             default:
                 $valid = false;
         }
         // let user know if the file type is unsupported
         if ($valid == false) {
             esc_html_e('Unsupported file type', EWWW_IMAGE_OPTIMIZER_DOMAIN);
             return;
         }
         $ewww_manual_nonce = wp_create_nonce("ewww-manual-" . $id);
         // output the image status if we know it
         if (!empty($status)) {
             echo esc_html($status);
             echo "<br>" . sprintf(esc_html__('Image Size: %s', EWWW_IMAGE_OPTIMIZER_DOMAIN), $file_size);
             if (current_user_can(apply_filters('ewww_image_optimizer_manual_permissions', ''))) {
                 printf("<br><a href=\"admin.php?action=ewww_flag_manual&amp;ewww_manual_nonce={$ewww_manual_nonce}&amp;ewww_force=1&amp;ewww_attachment_ID=%d\">%s</a>", $id, esc_html__('Re-optimize', EWWW_IMAGE_OPTIMIZER_DOMAIN));
             }
         } elseif (get_transient('ewwwio-background-in-progress-flag-' . $id)) {
             esc_html_e('In Progress', EWWW_IMAGE_OPTIMIZER_DOMAIN);
             // otherwise, tell the user that they can optimize the image now
         } else {
             esc_html_e('Not processed', EWWW_IMAGE_OPTIMIZER_DOMAIN);
             echo "<br>" . sprintf(esc_html__('Image Size: %s', EWWW_IMAGE_OPTIMIZER_DOMAIN), $file_size);
             if (current_user_can(apply_filters('ewww_image_optimizer_manual_permissions', ''))) {
                 printf("<br><a href=\"admin.php?action=ewww_flag_manual&amp;ewww_manual_nonce={$ewww_manual_nonce}&amp;ewww_attachment_ID=%d\">%s</a>", $id, esc_html__('Optimize now!', EWWW_IMAGE_OPTIMIZER_DOMAIN));
             }
         }
     }
 }
コード例 #17
0
        function ewww_ngg_bulk_preview()
        {
            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;
                }
            }
            // retrieve the attachments array from the db
            $attachments = get_option('ewww_image_optimizer_bulk_ngg_attachments');
            // make sure there are some attachments to process
            if (count($attachments) < 1) {
                echo '<p>' . __('You do not appear to have uploaded any images yet.', EWWW_IMAGE_OPTIMIZER_DOMAIN) . '</p>';
                return;
            }
            ?>
		<div class="wrap">
                <div id="icon-upload" class="icon32"></div><h1><?php 
            _e('Bulk Optimize', EWWW_IMAGE_OPTIMIZER_DOMAIN);
            ?>
</h1>
                <?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>
                <div id="ewww-bulk-forms">
                <p class="ewww-bulk-info"><?php 
            printf(__('We have %d images to optimize.', EWWW_IMAGE_OPTIMIZER_DOMAIN), count($attachments));
            ?>
<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="hidden" id="ewww-delay" name="ewww-delay" value="0">
                        <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')) {
                global $ewww_debug;
                echo '<div style="background-color:#ffff99;">' . $ewww_debug . '</div>';
            }
            if (!empty($_REQUEST['ewww_inline'])) {
                die;
            }
            return;
        }
コード例 #18
0
ファイル: iocli.php プロジェクト: aaronfrey/PepperLillie-CVM
 /**
  * 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));
             }
     }
 }
コード例 #19
0
function ewww_image_optimizer_webp_create($file, $orig_size, $type, $tool, $recreate = false)
{
    ewwwio_debug_message('<b>' . __FUNCTION__ . '()</b>');
    // change the file extension
    $webpfile = $file . '.webp';
    if (!ewww_image_optimizer_get_option('ewww_image_optimizer_webp')) {
        return;
    } elseif (is_file($webpfile) && empty($_REQUEST['ewww_force']) && !$recreate) {
        ewwwio_debug_message('webp file exists, not forcing or recreating');
        return;
    }
    if (empty($tool)) {
        ewww_image_optimizer_cloud_optimizer($file, $type, false, $webpfile, 'image/webp');
    } else {
        // check to see if 'nice' exists
        $nice = ewww_image_optimizer_find_nix_binary('nice', 'n');
        switch ($type) {
            case 'image/jpeg':
                exec("{$nice} " . $tool . " -q  85 -quiet " . ewww_image_optimizer_escapeshellarg($file) . " -o " . ewww_image_optimizer_escapeshellarg($webpfile) . ' 2>&1', $cli_output);
                break;
            case 'image/png':
                exec("{$nice} " . $tool . " -lossless -quiet " . ewww_image_optimizer_escapeshellarg($file) . " -o " . ewww_image_optimizer_escapeshellarg($webpfile) . ' 2>&1', $cli_output);
                break;
        }
    }
    $webp_size = ewww_image_optimizer_filesize($webpfile);
    ewwwio_debug_message("webp is {$webp_size} vs. {$type} is {$orig_size}");
    if (is_file($webpfile) && $orig_size < $webp_size) {
        ewwwio_debug_message('webp file was too big, deleting');
        unlink($webpfile);
    } elseif (is_file($webpfile)) {
        // Set correct file permissions
        $stat = stat(dirname($webpfile));
        $perms = $stat['mode'] & 0666;
        //same permissions as parent folder, strip off the executable bits
        @chmod($webpfile, $perms);
    }
    ewwwio_memory(__FUNCTION__);
}
コード例 #20
0
ファイル: common.php プロジェクト: goodbayscott/wwr-temp
function ewww_image_optimizer_options()
{
    global $ewww_debug;
    $ewww_debug .= '<b>ewww_image_optimizer_options()</b><br>';
    $output = array();
    if (isset($_REQUEST['ewww_pngout'])) {
        if ($_REQUEST['ewww_pngout'] == 'success') {
            $output[] = "<div id='ewww-image-optimizer-pngout-success' class='updated fade'>\n";
            $output[] = '<p>' . __('Pngout was successfully installed, check the Plugin Status area for version information.', EWWW_IMAGE_OPTIMIZER_DOMAIN) . "</p>\n";
            $output[] = "</div>\n";
        }
        if ($_REQUEST['ewww_pngout'] == 'failed') {
            $output[] = "<div id='ewww-image-optimizer-pngout-failure' class='error'>\n";
            $output[] = '<p>' . sprintf(__('Pngout was not installed: %1$s. Make sure this folder is writable: %2$s', EWWW_IMAGE_OPTIMIZER_DOMAIN), sanitize_text_field($_REQUEST['ewww_error']), EWWW_IMAGE_OPTIMIZER_TOOL_PATH) . "</p>\n";
            $output[] = "</div>\n";
        }
    }
    $output[] = "<script type='text/javascript'>\n" . 'jQuery(document).ready(function($) {$(".fade").fadeTo(5000,1).fadeOut(3000);$(".updated").fadeTo(5000,1).fadeOut(3000);});' . "\n" . "</script>\n";
    $output[] = "<style>\n" . ".ewww-tab a { font-size: 15px; font-weight: 700; color: #555; text-decoration: none; line-height: 36px; padding: 0 10px; }\n" . ".ewww-tab a:hover { color: #464646; }\n" . ".ewww-tab { margin: 0 0 0 5px; padding: 0px; border-width: 1px 1px 1px; border-style: solid solid none; border-image: none; border-color: #ccc; display: inline-block; background-color: #e4e4e4 }\n" . ".ewww-tab:hover { background-color: #fff }\n" . ".ewww-selected { background-color: #f1f1f1; margin-bottom: -1px; border-bottom: 1px solid #f1f1f1 }\n" . ".ewww-selected a { color: #000; }\n" . ".ewww-selected:hover { background-color: #f1f1f1; }\n" . ".ewww-tab-nav { list-style: none; margin: 10px 0 0; padding-left: 5px; border-bottom: 1px solid #ccc; }\n" . "</style>\n";
    $output[] = "<div class='wrap'>\n";
    $output[] = "<h2>EWWW Image Optimizer</h2>\n";
    $output[] = "<div id='ewww-container-left' style='float: left; margin-right: 225px;'>\n";
    $output[] = "<p><a href='https://wordpress.org/extend/plugins/ewww-image-optimizer/'>" . __('Plugin Home Page', EWWW_IMAGE_OPTIMIZER_DOMAIN) . "</a> | " . "<a href='https://wordpress.org/extend/plugins/ewww-image-optimizer/installation/'>" . __('Installation Instructions', EWWW_IMAGE_OPTIMIZER_DOMAIN) . "</a> | " . "<a href='https://wordpress.org/support/plugin/ewww-image-optimizer'>" . __('Plugin Support', EWWW_IMAGE_OPTIMIZER_DOMAIN) . "</a> | " . "<a href='https://ewww.io/status/'>" . __('Cloud Status', EWWW_IMAGE_OPTIMIZER_DOMAIN) . "</a></p>\n";
    if (function_exists('is_plugin_active_for_network') && is_plugin_active_for_network(EWWW_IMAGE_OPTIMIZER_PLUGIN_FILE_REL)) {
        $bulk_link = __('Media Library') . ' -> ' . __('Bulk Optimize', EWWW_IMAGE_OPTIMIZER_DOMAIN);
    } else {
        $bulk_link = '<a href="upload.php?page=ewww-image-optimizer-bulk">' . __('Bulk Optimize', EWWW_IMAGE_OPTIMIZER_DOMAIN) . '</a>';
    }
    $output[] = "<p>" . sprintf(__('New images uploaded to the Media Library will be optimized automatically. If you have existing images you would like to optimize, you can use the %s tool.', EWWW_IMAGE_OPTIMIZER_DOMAIN), $bulk_link) . "</p>\n";
    if (EWWW_IMAGE_OPTIMIZER_CLOUD) {
        $collapsed = '';
    } else {
        $collapsed = "\$('#ewww-status').toggleClass('closed');\n";
    }
    $output[] = "<div id='ewww-widgets' class='metabox-holder'><div class='meta-box-sortables'><div id='ewww-status' class='postbox'>\n" . "<div class='handlediv' title='" . esc_attr__('Click to toggle') . "'><br></div>" . "<h3 class='hndle'>" . __('Plugin Status', EWWW_IMAGE_OPTIMIZER_DOMAIN) . "&emsp;" . "<span id='ewww-status-ok' style='display: none; color: green;'>" . __('All Clear', EWWW_IMAGE_OPTIMIZER_DOMAIN) . "</span>" . "<span id='ewww-status-attention' style='color: red;'>" . __('Requires Attention', EWWW_IMAGE_OPTIMIZER_DOMAIN) . "</span>" . "</h3>\n" . "<div class='inside'>" . "<b>" . __('Total Savings:', EWWW_IMAGE_OPTIMIZER_DOMAIN) . "</b> <span id='ewww-total-savings'>" . size_format(ewww_image_optimizer_savings(), 2) . "</span><br>";
    if (ewww_image_optimizer_get_option('ewww_image_optimizer_cloud_key')) {
        $output[] = '<p><b>' . __('Cloud optimization API Key', EWWW_IMAGE_OPTIMIZER_DOMAIN) . ":</b> ";
        $verify_cloud = ewww_image_optimizer_cloud_verify(false);
        if (preg_match('/great/', $verify_cloud)) {
            $output[] = '<span style="color: green">' . __('Verified,', EWWW_IMAGE_OPTIMIZER_DOMAIN) . ' </span>' . ewww_image_optimizer_cloud_quota();
        } elseif (preg_match('/exceeded/', $verify_cloud)) {
            $output[] = '<span style="color: orange">' . __('Verified,', EWWW_IMAGE_OPTIMIZER_DOMAIN) . ' </span>' . ewww_image_optimizer_cloud_quota();
        } else {
            $output[] = '<span style="color: red">' . __('Not Verified', EWWW_IMAGE_OPTIMIZER_DOMAIN) . '</span>';
        }
        $output[] = "</p>\n";
    }
    $collapsible = true;
    if (!EWWW_IMAGE_OPTIMIZER_CLOUD) {
        /*	$output[] = "<div id='ewww-status-expand' style='display: none;'><a href='#'>" . __('Expand', EWWW_IMAGE_OPTIMIZER_DOMAIN) . "</a></div>\n" .
        			"<div id='ewww-status-collapse' style='display: none;'><a href='#'>" . __('Collapse', EWWW_IMAGE_OPTIMIZER_DOMAIN) . "</a></div>\n" .
        			"<div id='ewww-collapsible-status'>\n";*/
        //				$output[] = "<div id='ewww-collapsible-status'>\n";
    }
    if (ewww_image_optimizer_get_option('ewww_image_optimizer_skip_bundle') && !EWWW_IMAGE_OPTIMIZER_CLOUD && !EWWW_IMAGE_OPTIMIZER_NOEXEC) {
        $output[] = "<p>" . __('If updated versions are available below you may either download the newer versions and install them yourself, or uncheck "Use System Paths" and use the bundled tools.', EWWW_IMAGE_OPTIMIZER_DOMAIN) . "<br />\n" . "<i>*" . __('Updates are optional, but may contain increased optimization or security patches', EWWW_IMAGE_OPTIMIZER_DOMAIN) . "</i></p>\n";
    } elseif (!EWWW_IMAGE_OPTIMIZER_CLOUD && !EWWW_IMAGE_OPTIMIZER_NOEXEC) {
        $output[] = "<p>" . sprintf(__('If updated versions are available below, you may need to enable write permission on the %s folder to use the automatic installs.', EWWW_IMAGE_OPTIMIZER_DOMAIN), '<i>' . EWWW_IMAGE_OPTIMIZER_TOOL_PATH . '</i>') . "<br />\n" . "<i>*" . __('Updates are optional, but may contain increased optimization or security patches', EWWW_IMAGE_OPTIMIZER_DOMAIN) . "</i></p>\n";
    }
    if (!EWWW_IMAGE_OPTIMIZER_CLOUD && !EWWW_IMAGE_OPTIMIZER_NOEXEC) {
        list($jpegtran_src, $optipng_src, $gifsicle_src, $jpegtran_dst, $optipng_dst, $gifsicle_dst) = ewww_image_optimizer_install_paths();
    }
    $output[] = "<p>\n";
    if (!ewww_image_optimizer_get_option('ewww_image_optimizer_disable_jpegtran') && !ewww_image_optimizer_get_option('ewww_image_optimizer_cloud_jpg') && !EWWW_IMAGE_OPTIMIZER_NOEXEC) {
        $output[] = "<b>jpegtran:</b> ";
        $jpegtran_installed = ewww_image_optimizer_tool_found(EWWW_IMAGE_OPTIMIZER_JPEGTRAN, 'j');
        if (!empty($jpegtran_installed)) {
            $output[] = '<span style="color: green; font-weight: bolder">' . __('Installed', EWWW_IMAGE_OPTIMIZER_DOMAIN) . '</span>&emsp;' . __('version', EWWW_IMAGE_OPTIMIZER_DOMAIN) . ': ' . $jpegtran_installed . "<br />\n";
        } else {
            $output[] = '<span style="color: red; font-weight: bolder">' . __('Missing', EWWW_IMAGE_OPTIMIZER_DOMAIN) . '</span><br />' . "\n";
            $collapsible = false;
        }
    }
    if (!ewww_image_optimizer_get_option('ewww_image_optimizer_disable_optipng') && !ewww_image_optimizer_get_option('ewww_image_optimizer_cloud_png') && !EWWW_IMAGE_OPTIMIZER_NOEXEC) {
        $output[] = "<b>optipng:</b> ";
        $optipng_version = ewww_image_optimizer_tool_found(EWWW_IMAGE_OPTIMIZER_OPTIPNG, 'o');
        if (!empty($optipng_version)) {
            $output[] = '<span style="color: green; font-weight: bolder">' . __('Installed', EWWW_IMAGE_OPTIMIZER_DOMAIN) . '</span>&emsp;' . __('version', EWWW_IMAGE_OPTIMIZER_DOMAIN) . ': ' . $optipng_version . "<br />\n";
        } else {
            $output[] = '<span style="color: red; font-weight: bolder">' . __('Missing', EWWW_IMAGE_OPTIMIZER_DOMAIN) . '</span><br />' . "\n";
            $collapsible = false;
        }
    }
    if (!ewww_image_optimizer_get_option('ewww_image_optimizer_disable_gifsicle') && !ewww_image_optimizer_get_option('ewww_image_optimizer_cloud_gif') && !EWWW_IMAGE_OPTIMIZER_NOEXEC) {
        $output[] = "<b>gifsicle:</b> ";
        $gifsicle_version = ewww_image_optimizer_tool_found(EWWW_IMAGE_OPTIMIZER_GIFSICLE, 'g');
        if (!empty($gifsicle_version) && preg_match('/LCDF Gifsicle/', $gifsicle_version)) {
            $output[] = '<span style="color: green; font-weight: bolder">' . __('Installed', EWWW_IMAGE_OPTIMIZER_DOMAIN) . '</span>&emsp;' . __('version', EWWW_IMAGE_OPTIMIZER_DOMAIN) . ': ' . $gifsicle_version . "<br />\n";
        } else {
            $output[] = '<span style="color: red; font-weight: bolder">' . __('Missing', EWWW_IMAGE_OPTIMIZER_DOMAIN) . '</span><br />' . "\n";
            $collapsible = false;
        }
    }
    if (!ewww_image_optimizer_get_option('ewww_image_optimizer_disable_pngout') && !ewww_image_optimizer_get_option('ewww_image_optimizer_cloud_png') && !EWWW_IMAGE_OPTIMIZER_NOEXEC) {
        $output[] = "<b>pngout:</b> ";
        $pngout_version = ewww_image_optimizer_tool_found(EWWW_IMAGE_OPTIMIZER_PNGOUT, 'p');
        if (!empty($pngout_version) && preg_match('/PNGOUT/', $pngout_version)) {
            $output[] = '<span style="color: green; font-weight: bolder">' . __('Installed', EWWW_IMAGE_OPTIMIZER_DOMAIN) . '</span>&emsp;' . __('version', EWWW_IMAGE_OPTIMIZER_DOMAIN) . ': ' . preg_replace('/PNGOUT \\[.*\\)\\s*?/', '', $pngout_version) . "<br />\n";
        } else {
            $output[] = '<span style="color: red; font-weight: bolder">' . __('Missing', EWWW_IMAGE_OPTIMIZER_DOMAIN) . '</span>&emsp;<b>' . __('Install', EWWW_IMAGE_OPTIMIZER_DOMAIN) . ' <a href="admin.php?action=ewww_image_optimizer_install_pngout">' . __('automatically', EWWW_IMAGE_OPTIMIZER_DOMAIN) . '</a> | <a href="http://advsys.net/ken/utils.htm">' . __('manually', EWWW_IMAGE_OPTIMIZER_DOMAIN) . '</a></b> - ' . __('Pngout is free closed-source software that can produce drastically reduced filesizes for PNGs, but can be very time consuming to process images', EWWW_IMAGE_OPTIMIZER_DOMAIN) . "<br />\n";
            $collapsible = false;
        }
    }
    if (ewww_image_optimizer_get_option('ewww_image_optimizer_png_lossy') && !ewww_image_optimizer_get_option('ewww_image_optimizer_cloud_png') && !EWWW_IMAGE_OPTIMIZER_NOEXEC) {
        $output[] = "<b>pngquant:</b> ";
        $pngquant_version = ewww_image_optimizer_tool_found(EWWW_IMAGE_OPTIMIZER_PNGQUANT, 'q');
        if (!empty($pngquant_version)) {
            $output[] = '<span style="color: green; font-weight: bolder">' . __('Installed', EWWW_IMAGE_OPTIMIZER_DOMAIN) . '</span>&emsp;' . __('version', EWWW_IMAGE_OPTIMIZER_DOMAIN) . ': ' . $pngquant_version . "<br />\n";
        } else {
            $output[] = '<span style="color: red; font-weight: bolder">' . __('Missing', EWWW_IMAGE_OPTIMIZER_DOMAIN) . '</span><br />' . "\n";
            $collapsible = false;
        }
    }
    if (ewww_image_optimizer_get_option('ewww_image_optimizer_webp') && !ewww_image_optimizer_get_option('ewww_image_optimizer_cloud_png') && !ewww_image_optimizer_get_option('ewww_image_optimizer_cloud_jpg') && !EWWW_IMAGE_OPTIMIZER_NOEXEC) {
        $output[] = "<b>webp:</b> ";
        $webp_version = ewww_image_optimizer_tool_found(EWWW_IMAGE_OPTIMIZER_WEBP, 'w');
        if (!empty($webp_version)) {
            $output[] = '<span style="color: green; font-weight: bolder">' . __('Installed', EWWW_IMAGE_OPTIMIZER_DOMAIN) . '</span>&emsp;' . __('version', EWWW_IMAGE_OPTIMIZER_DOMAIN) . ': ' . $webp_version . "<br />\n";
        } else {
            $output[] = '<span style="color: red; font-weight: bolder">' . __('Missing', EWWW_IMAGE_OPTIMIZER_DOMAIN) . '</span><br />' . "\n";
            $collapsible = false;
        }
    }
    if (!EWWW_IMAGE_OPTIMIZER_CLOUD && !EWWW_IMAGE_OPTIMIZER_NOEXEC) {
        if (ewww_image_optimizer_safemode_check()) {
            $output[] = 'safe mode: <span style="color: red; font-weight: bolder">' . __('On', EWWW_IMAGE_OPTIMIZER_DOMAIN) . '</span>&emsp;&emsp;';
            $collapsible = false;
        } else {
            $output[] = 'safe mode: <span style="color: green; font-weight: bolder">' . __('Off', EWWW_IMAGE_OPTIMIZER_DOMAIN) . '</span>&emsp;&emsp;';
        }
        if (ewww_image_optimizer_exec_check()) {
            $output[] = 'exec(): <span style="color: red; font-weight: bolder">' . __('Disabled', EWWW_IMAGE_OPTIMIZER_DOMAIN) . '</span>&emsp;&emsp;';
            $collapsible = false;
        } else {
            $output[] = 'exec(): <span style="color: green; font-weight: bolder">' . __('Enabled', EWWW_IMAGE_OPTIMIZER_DOMAIN) . '</span>&emsp;&emsp;';
        }
        $output[] = "<br />\n";
        $output[] = sprintf(__("%s only need one, used for conversion, not optimization", EWWW_IMAGE_OPTIMIZER_DOMAIN), '<b>' . __('Graphics libraries', EWWW_IMAGE_OPTIMIZER_DOMAIN) . '</b> - ');
        $output[] = '<br>';
        $toolkit_found = false;
        if (ewww_image_optimizer_gd_support()) {
            $output[] = 'GD: <span style="color: green; font-weight: bolder">' . __('Installed', EWWW_IMAGE_OPTIMIZER_DOMAIN);
            $toolkit_found = true;
        } else {
            $output[] = 'GD: <span style="color: red; font-weight: bolder">' . __('Missing', EWWW_IMAGE_OPTIMIZER_DOMAIN);
        }
        $output[] = '</span>&emsp;&emsp;' . "Imagemagick 'convert':";
        if (ewww_image_optimizer_find_binary('convert', 'i')) {
            $output[] = '<span style="color: green; font-weight: bolder"> ' . __('Installed', EWWW_IMAGE_OPTIMIZER_DOMAIN) . '</span>';
            $toolkit_found = true;
        } else {
            $output[] = '<span style="color: red; font-weight: bolder"> ' . __('Missing', EWWW_IMAGE_OPTIMIZER_DOMAIN) . '</span>';
        }
        if (!$toolkit_found && (ewww_image_optimizer_get_option('ewww_image_optimizer_png_to_jpg') || ewww_image_optimizer_get_option('ewww_image_optimizer_jpg_to_png'))) {
            $collapsible = false;
        }
        $output[] = "<br />\n";
    }
    $output[] = '<b>' . __('Only need one of these:', EWWW_IMAGE_OPTIMIZER_DOMAIN) . ' </b><br>';
    // initialize this variable to check for the 'file' command if we don't have any php libraries we can use
    $file_command_check = true;
    if (function_exists('finfo_file')) {
        $output[] = 'finfo: <span style="color: green; font-weight: bolder">' . __('Installed', EWWW_IMAGE_OPTIMIZER_DOMAIN) . '</span>&emsp;&emsp;';
        $file_command_check = false;
    } else {
        $output[] = 'finfo: <span style="color: red; font-weight: bolder">' . __('Missing', EWWW_IMAGE_OPTIMIZER_DOMAIN) . '</span>&emsp;&emsp;';
    }
    if (function_exists('getimagesize')) {
        $output[] = 'getimagesize(): <span style="color: green; font-weight: bolder">' . __('Installed', EWWW_IMAGE_OPTIMIZER_DOMAIN) . '</span>&emsp;&emsp;';
        if (EWWW_IMAGE_OPTIMIZER_CLOUD || EWWW_IMAGE_OPTIMIZER_NOEXEC || PHP_OS == 'WINNT') {
            $file_command_check = false;
        }
    } else {
        $output[] = 'getimagesize(): <span style="color: red; font-weight: bolder">' . __('Missing', EWWW_IMAGE_OPTIMIZER_DOMAIN) . '</span>&emsp;&emsp;';
    }
    if (function_exists('mime_content_type')) {
        $output[] = 'mime_content_type(): <span style="color: green; font-weight: bolder">' . __('Installed', EWWW_IMAGE_OPTIMIZER_DOMAIN) . '</span><br />' . "\n";
        $file_command_check = false;
    } else {
        $output[] = 'mime_content_type(): <span style="color: red; font-weight: bolder">' . __('Missing', EWWW_IMAGE_OPTIMIZER_DOMAIN) . '</span><br />' . "\n";
    }
    if (PHP_OS != 'WINNT' && !EWWW_IMAGE_OPTIMIZER_CLOUD && !EWWW_IMAGE_OPTIMIZER_NOEXEC) {
        if ($file_command_check && !ewww_image_optimizer_find_binary('file', 'f')) {
            $output[] = '<span style="color: red; font-weight: bolder">file ' . __('command not found on your system', EWWW_IMAGE_OPTIMIZER_DOMAIN) . '</span><br />';
            $collapsible = false;
        }
        if (!ewww_image_optimizer_find_binary('nice', 'n')) {
            $output[] = '<span style="color: orange; font-weight: bolder">nice ' . __('command not found on your system', EWWW_IMAGE_OPTIMIZER_DOMAIN) . ' (' . __('not required', EWWW_IMAGE_OPTIMIZER_DOMAIN) . ')</span><br />';
        }
        if (!ewww_image_optimizer_get_option('ewww_image_optimizer_disable_pngout') && !ewww_image_optimizer_get_option('ewww_image_optimizer_cloud_png') && PHP_OS != 'SunOS' && !ewww_image_optimizer_find_binary('tar', 't')) {
            $output[] = '<span style="color: red; font-weight: bolder">tar ' . __('command not found on your system', EWWW_IMAGE_OPTIMIZER_DOMAIN) . ' (' . __('required for automatic pngout installer', EWWW_IMAGE_OPTIMIZER_DOMAIN) . ')</span><br />';
            $collapsible = false;
        }
    } elseif ($file_command_check) {
        $collapsible = false;
    }
    if (!EWWW_IMAGE_OPTIMIZER_CLOUD) {
        //				$output[] = '</div><!-- end collapsible -->';
    }
    $output[] = '</div><!-- end .inside -->';
    if ($collapsible) {
        $output[] = "<script type='text/javascript'>\n" . "jQuery(document).ready(function(\$) {\n" . $collapsed . "\$('#ewww-status-attention').hide();\n" . "\$('#ewww-status-ok').show();\n" . "});\n" . "</script>\n";
    }
    $output[] = "</div></div></div>\n";
    $output[] = "<ul class='ewww-tab-nav'>\n" . "<li class='ewww-tab ewww-cloud-nav'><span class='ewww-tab-hidden'><a class='ewww-cloud-nav' href='#'>" . __('Cloud Settings', EWWW_IMAGE_OPTIMIZER_DOMAIN) . "</a></span></li>\n" . "<li class='ewww-tab ewww-general-nav'><span class='ewww-tab-hidden'><a class='ewww-general-nav' href='#'>" . __('Basic Settings', EWWW_IMAGE_OPTIMIZER_DOMAIN) . "</a></span></li>\n" . "<li class='ewww-tab ewww-optimization-nav'><span class='ewww-tab-hidden'><a class='ewww-optimization-nav' href='#'>" . __('Advanced Settings', EWWW_IMAGE_OPTIMIZER_DOMAIN) . "</a></span></li>\n" . "<li class='ewww-tab ewww-conversion-nav'><span class='ewww-tab-hidden'><a class='ewww-conversion-nav' href='#'>" . __('Conversion Settings', EWWW_IMAGE_OPTIMIZER_DOMAIN) . "</a></span></li>\n" . "</ul>\n";
    if (function_exists('is_plugin_active_for_network') && is_plugin_active_for_network(EWWW_IMAGE_OPTIMIZER_PLUGIN_FILE_REL)) {
        $output[] = "<form method='post' action=''>\n";
    } else {
        $output[] = "<form method='post' action='options.php'>\n";
    }
    $output[] = "<input type='hidden' name='option_page' value='ewww_image_optimizer_options' />\n";
    $output[] = "<input type='hidden' name='action' value='update' />\n";
    $output[] = wp_nonce_field("ewww_image_optimizer_options-options", '_wpnonce', true, false) . "\n";
    $output[] = "<div id='ewww-cloud-settings'>\n";
    $output[] = "<p>" . __('If exec() is disabled for security reasons (and enabling it is not an option), or you would like to offload image optimization to a third-party server, you may purchase an API key for our cloud optimization service. The API key should be entered below, and cloud optimization must be enabled for each image format individually.', EWWW_IMAGE_OPTIMIZER_DOMAIN) . " <a href='https://ewww.io/plans/'>" . __('Purchase an API key.', EWWW_IMAGE_OPTIMIZER_DOMAIN) . "</a></p>\n";
    $output[] = "<table class='form-table'>\n";
    $output[] = "<tr><th><label for='ewww_image_optimizer_cloud_key'>" . __('Cloud optimization API Key', EWWW_IMAGE_OPTIMIZER_DOMAIN) . "</label></th><td><input type='text' id='ewww_image_optimizer_cloud_key' name='ewww_image_optimizer_cloud_key' value='" . ewww_image_optimizer_get_option('ewww_image_optimizer_cloud_key') . "' size='32' /> " . __('API Key will be validated when you save your settings.', EWWW_IMAGE_OPTIMIZER_DOMAIN) . " <a href='https://ewww.io/plans/'>" . __('Purchase an API key.', EWWW_IMAGE_OPTIMIZER_DOMAIN) . "</a></td></tr>\n";
    $output[] = "<tr><th><label for='ewww_image_optimizer_cloud_jpg'>" . __('JPG cloud optimization', EWWW_IMAGE_OPTIMIZER_DOMAIN) . "</label></th><td><input type='checkbox' id='ewww_image_optimizer_cloud_jpg' name='ewww_image_optimizer_cloud_jpg' value='true' " . (ewww_image_optimizer_get_option('ewww_image_optimizer_cloud_jpg') == TRUE ? "checked='true'" : "") . " /></td></tr>\n";
    $output[] = "<tr><th><label for='ewww_image_optimizer_cloud_png'>" . __('PNG cloud optimization', EWWW_IMAGE_OPTIMIZER_DOMAIN) . "</label></th><td><input type='checkbox' id='ewww_image_optimizer_cloud_png' name='ewww_image_optimizer_cloud_png' value='true' " . (ewww_image_optimizer_get_option('ewww_image_optimizer_cloud_png') == TRUE ? "checked='true'" : "") . " /></td></tr>";
    $output[] = "<tr><td>&nbsp;</td><td><input type='checkbox' id='ewww_image_optimizer_cloud_png_compress' name='ewww_image_optimizer_cloud_png_compress' value='true' " . (ewww_image_optimizer_get_option('ewww_image_optimizer_cloud_png_compress') == TRUE ? "checked='true'" : "") . " /><label for='ewww_image_optimizer_cloud_png_compress'>" . __('extra PNG compression (slower)', EWWW_IMAGE_OPTIMIZER_DOMAIN) . "</label></td></tr>\n";
    $output[] = "<tr><th><label for='ewww_image_optimizer_cloud_gif'>" . __('GIF cloud optimization', EWWW_IMAGE_OPTIMIZER_DOMAIN) . "</label></th><td><input type='checkbox' id='ewww_image_optimizer_cloud_gif' name='ewww_image_optimizer_cloud_gif' value='true' " . (ewww_image_optimizer_get_option('ewww_image_optimizer_cloud_gif') == TRUE ? "checked='true'" : "") . " /></td></tr>\n";
    $output[] = "<tr><th><label for='ewww_image_optimizer_lossy_fast'>" . __('Faster lossy optimization', EWWW_IMAGE_OPTIMIZER_DOMAIN) . "</label></th><td><input type='checkbox' id='ewww_image_optimizer_lossy_fast' name='ewww_image_optimizer_lossy_fast' value='true' " . (ewww_image_optimizer_get_option('ewww_image_optimizer_lossy_fast') == TRUE ? "checked='true'" : "") . " /> " . __('Speed up the lossy operations by performing less compression.', EWWW_IMAGE_OPTIMIZER_DOMAIN) . "</td></tr>\n";
    $output[] = "</table>\n</div>\n";
    $output[] = "<div id='ewww-general-settings'>\n";
    $output[] = "<table class='form-table'>\n";
    $output[] = "<tr><th><label for='ewww_image_optimizer_debug'>" . __('Debugging', EWWW_IMAGE_OPTIMIZER_DOMAIN) . "</label></th><td><input type='checkbox' id='ewww_image_optimizer_debug' name='ewww_image_optimizer_debug' value='true' " . (ewww_image_optimizer_get_option('ewww_image_optimizer_debug') == TRUE ? "checked='true'" : "") . " /> " . __('Use this to provide information for support purposes, or if you feel comfortable digging around in the code to fix a problem you are experiencing.', EWWW_IMAGE_OPTIMIZER_DOMAIN) . "</td></tr>\n";
    $output[] = "<tr><th><label for='ewww_image_optimizer_jpegtran_copy'>" . __('Remove metadata', EWWW_IMAGE_OPTIMIZER_DOMAIN) . "</label></th>\n" . "<td><input type='checkbox' id='ewww_image_optimizer_jpegtran_copy' name='ewww_image_optimizer_jpegtran_copy' value='true' " . (ewww_image_optimizer_get_option('ewww_image_optimizer_jpegtran_copy') == TRUE ? "checked='true'" : "") . " /> " . __('This will remove ALL metadata: EXIF and comments.', EWWW_IMAGE_OPTIMIZER_DOMAIN) . "</td></tr>\n";
    $output[] = "<tr><th><label for='ewww_image_optimizer_jpg_lossy'>" . __('Lossy JPG optimization', EWWW_IMAGE_OPTIMIZER_DOMAIN) . "</label></th><td><input type='checkbox' id='ewww_image_optimizer_jpg_lossy' name='ewww_image_optimizer_jpg_lossy' value='true' " . (ewww_image_optimizer_get_option('ewww_image_optimizer_jpg_lossy') == TRUE ? "checked='true'" : "") . " /> <b>" . __('WARNING:', EWWW_IMAGE_OPTIMIZER_DOMAIN) . "</b> " . __('While most users will not notice a difference in image quality, lossy means there IS a loss in image quality.', EWWW_IMAGE_OPTIMIZER_DOMAIN) . "\n" . "<p class='description'>" . __('Requires an EWWW Image Optimizer Cloud Subscription.', EWWW_IMAGE_OPTIMIZER_DOMAIN) . " <a href='https://ewww.io/plans/'>" . __('Purchase an API key.', EWWW_IMAGE_OPTIMIZER_DOMAIN) . "</a></p></td></tr>\n";
    $output[] = "<tr><th><label for='ewww_image_optimizer_png_lossy'>" . __('Lossy PNG optimization', EWWW_IMAGE_OPTIMIZER_DOMAIN) . "</label></th><td><input type='checkbox' id='ewww_image_optimizer_png_lossy' name='ewww_image_optimizer_png_lossy' value='true' " . (ewww_image_optimizer_get_option('ewww_image_optimizer_png_lossy') == TRUE ? "checked='true'" : "") . " /> <b>" . __('WARNING:', EWWW_IMAGE_OPTIMIZER_DOMAIN) . "</b> " . __('While most users will not notice a difference in image quality, lossy means there IS a loss in image quality.', EWWW_IMAGE_OPTIMIZER_DOMAIN) . "\n" . "<p class='description'>" . __('Uses pngquant locally. Use EWWW I.O. Cloud for even better lossy compression.', EWWW_IMAGE_OPTIMIZER_DOMAIN) . " <a href='https://ewww.io/plans/'>" . __('Purchase an API key.', EWWW_IMAGE_OPTIMIZER_DOMAIN) . "</a></p></td></tr>\n";
    $output[] = "<tr><th><label for='ewww_image_optimizer_delay'>" . __('Bulk Delay', EWWW_IMAGE_OPTIMIZER_DOMAIN) . "</label></th><td><input type='text' id='ewww_image_optimizer_delay' name='ewww_image_optimizer_delay' size='5' value='" . ewww_image_optimizer_get_option('ewww_image_optimizer_delay') . "'> " . __('Choose how long to pause between images (in seconds, 0 = disabled)', EWWW_IMAGE_OPTIMIZER_DOMAIN) . "</td></tr>\n";
    if (class_exists('Cloudinary') && Cloudinary::config_get("api_secret")) {
        $output[] = "<tr><th><label for='ewww_image_optimizer_enable_cloudinary'>" . __('Automatic Cloudinary upload', EWWW_IMAGE_OPTIMIZER_DOMAIN) . "</label></th><td><input type='checkbox' id='ewww_image_optimizer_enable_cloudinary' name='ewww_image_optimizer_enable_cloudinary' value='true' " . (ewww_image_optimizer_get_option('ewww_image_optimizer_enable_cloudinary') == TRUE ? "checked='true'" : "") . " /> " . __('When enabled, uploads to the Media Library will be transferred to Cloudinary after optimization. Cloudinary generates resizes, so only the full-size image is uploaded.', EWWW_IMAGE_OPTIMIZER_DOMAIN) . "</td></tr>\n";
    }
    $output[] = "</table>\n</div>\n";
    $output[] = "<div id='ewww-optimization-settings'>\n";
    $output[] = "<table class='form-table'>\n";
    if (EWWW_IMAGE_OPTIMIZER_CLOUD) {
        $output[] = "<input id='ewww_image_optimizer_optipng_level' name='ewww_image_optimizer_optipng_level' type='hidden' value='2'>\n" . "<input id='ewww_image_optimizer_pngout_level' name='ewww_image_optimizer_pngout_level' type='hidden' value='2'>\n";
    } else {
        $output[] = "<tr class='nocloud'><th><label for='ewww_image_optimizer_optipng_level'>" . __('optipng optimization level', EWWW_IMAGE_OPTIMIZER_DOMAIN) . "</label></th>\n" . "<td><span><select id='ewww_image_optimizer_optipng_level' name='ewww_image_optimizer_optipng_level'>\n" . "<option value='1'" . (ewww_image_optimizer_get_option('ewww_image_optimizer_optipng_level') == 1 ? " selected='selected'" : "") . '>' . sprintf(__('Level %d', EWWW_IMAGE_OPTIMIZER_DOMAIN), 1) . ': ' . sprintf(__('%d trial', EWWW_IMAGE_OPTIMIZER_DOMAIN), 1) . "</option>\n" . "<option value='2'" . (ewww_image_optimizer_get_option('ewww_image_optimizer_optipng_level') == 2 ? " selected='selected'" : "") . '>' . sprintf(__('Level %d', EWWW_IMAGE_OPTIMIZER_DOMAIN), 2) . ': ' . sprintf(__('%d trials', EWWW_IMAGE_OPTIMIZER_DOMAIN), 8) . "</option>\n" . "<option value='3'" . (ewww_image_optimizer_get_option('ewww_image_optimizer_optipng_level') == 3 ? " selected='selected'" : "") . '>' . sprintf(__('Level %d', EWWW_IMAGE_OPTIMIZER_DOMAIN), 3) . ': ' . sprintf(__('%d trials', EWWW_IMAGE_OPTIMIZER_DOMAIN), 16) . "</option>\n" . "<option value='4'" . (ewww_image_optimizer_get_option('ewww_image_optimizer_optipng_level') == 4 ? " selected='selected'" : "") . '>' . sprintf(__('Level %d', EWWW_IMAGE_OPTIMIZER_DOMAIN), 4) . ': ' . sprintf(__('%d trials', EWWW_IMAGE_OPTIMIZER_DOMAIN), 24) . "</option>\n" . "<option value='5'" . (ewww_image_optimizer_get_option('ewww_image_optimizer_optipng_level') == 5 ? " selected='selected'" : "") . '>' . sprintf(__('Level %d', EWWW_IMAGE_OPTIMIZER_DOMAIN), 5) . ': ' . sprintf(__('%d trials', EWWW_IMAGE_OPTIMIZER_DOMAIN), 48) . "</option>\n" . "<option value='6'" . (ewww_image_optimizer_get_option('ewww_image_optimizer_optipng_level') == 6 ? " selected='selected'" : "") . '>' . sprintf(__('Level %d', EWWW_IMAGE_OPTIMIZER_DOMAIN), 6) . ': ' . sprintf(__('%d trials', EWWW_IMAGE_OPTIMIZER_DOMAIN), 120) . "</option>\n" . "<option value='7'" . (ewww_image_optimizer_get_option('ewww_image_optimizer_optipng_level') == 7 ? " selected='selected'" : "") . '>' . sprintf(__('Level %d', EWWW_IMAGE_OPTIMIZER_DOMAIN), 7) . ': ' . sprintf(__('%d trials', EWWW_IMAGE_OPTIMIZER_DOMAIN), 240) . "</option>\n" . "</select> (" . __('default', EWWW_IMAGE_OPTIMIZER_DOMAIN) . "=2)</span>\n" . "<p class='description'>" . __('According to the author of optipng, 10 trials should satisfy most people, 30 trials should satisfy everyone.', EWWW_IMAGE_OPTIMIZER_DOMAIN) . "</p></td></tr>\n";
        $output[] = "<tr class='nocloud'><th><label for='ewww_image_optimizer_pngout_level'>" . __('pngout optimization level', EWWW_IMAGE_OPTIMIZER_DOMAIN) . "</label></th>\n" . "<td><span><select id='ewww_image_optimizer_pngout_level' name='ewww_image_optimizer_pngout_level'>\n" . "<option value='0'" . (ewww_image_optimizer_get_option('ewww_image_optimizer_pngout_level') == 0 ? " selected='selected'" : "") . '>' . sprintf(__('Level %d', EWWW_IMAGE_OPTIMIZER_DOMAIN), 0) . ': ' . __('Xtreme! (Slowest)', EWWW_IMAGE_OPTIMIZER_DOMAIN) . "</option>\n" . "<option value='1'" . (ewww_image_optimizer_get_option('ewww_image_optimizer_pngout_level') == 1 ? " selected='selected'" : "") . '>' . sprintf(__('Level %d', EWWW_IMAGE_OPTIMIZER_DOMAIN), 1) . ': ' . __('Intense (Slow)', EWWW_IMAGE_OPTIMIZER_DOMAIN) . "</option>\n" . "<option value='2'" . (ewww_image_optimizer_get_option('ewww_image_optimizer_pngout_level') == 2 ? " selected='selected'" : "") . '>' . sprintf(__('Level %d', EWWW_IMAGE_OPTIMIZER_DOMAIN), 2) . ': ' . __('Longest Match (Fast)', EWWW_IMAGE_OPTIMIZER_DOMAIN) . "</option>\n" . "<option value='3'" . (ewww_image_optimizer_get_option('ewww_image_optimizer_pngout_level') == 3 ? " selected='selected'" : "") . '>' . sprintf(__('Level %d', EWWW_IMAGE_OPTIMIZER_DOMAIN), 3) . ': ' . __('Huffman Only (Faster)', EWWW_IMAGE_OPTIMIZER_DOMAIN) . "</option>\n" . "</select> (" . __('default', EWWW_IMAGE_OPTIMIZER_DOMAIN) . "=2)</span>\n" . "<p class='description'>" . sprintf(__('If you have CPU cycles to spare, go with level %d', EWWW_IMAGE_OPTIMIZER_DOMAIN), 0) . "</p></td></tr>\n";
    }
    $output[] = "<tr><th><label for='ewww_image_optimizer_auto'>" . __('Scheduled optimization', EWWW_IMAGE_OPTIMIZER_DOMAIN) . "</label></th><td><input type='checkbox' id='ewww_image_optimizer_auto' name='ewww_image_optimizer_auto' value='true' " . (ewww_image_optimizer_get_option('ewww_image_optimizer_auto') == TRUE ? "checked='true'" : "") . " /> " . __('This will enable scheduled optimization of unoptimized images for your theme, buddypress, and any additional folders you have configured below. Runs hourly: wp_cron only runs when your site is visited, so it may be even longer between optimizations.', EWWW_IMAGE_OPTIMIZER_DOMAIN) . "</td></tr>\n";
    $output[] = "<tr><th><label for='ewww_image_optimizer_aux_paths'>" . __('Folders to optimize', EWWW_IMAGE_OPTIMIZER_DOMAIN) . "</label></th><td>" . sprintf(__('One path per line, must be within %s. Use full paths, not relative paths.', EWWW_IMAGE_OPTIMIZER_DOMAIN), ABSPATH) . "<br>\n";
    $output[] = "<textarea id='ewww_image_optimizer_aux_paths' name='ewww_image_optimizer_aux_paths' rows='3' cols='60'>" . (($aux_paths = ewww_image_optimizer_get_option('ewww_image_optimizer_aux_paths')) ? implode("\n", $aux_paths) : "") . "</textarea>\n";
    $output[] = "<p class='description'>" . __('Provide paths containing images to be optimized using "Scan and Optimize" on the Bulk Optimize page or by Scheduled Optimization.', EWWW_IMAGE_OPTIMIZER_DOMAIN) . "</p></td></tr>\n";
    //				$output[] = "<b><a href='https://wordpress.org/support/plugin/ewww-image-optimizer'>" . __('Please submit a support request in the forums to have folders created by a particular plugin auto-included in the future.', EWWW_IMAGE_OPTIMIZER_DOMAIN) . "</a></b></p></td></tr>\n";
    $output[] = "<tr><th><label for='ewww_image_optimizer_noauto'>" . __('Disable Automatic Optimization', EWWW_IMAGE_OPTIMIZER_DOMAIN) . "</label></th><td><input type='checkbox' id='ewww_image_optimizer_noauto' name='ewww_image_optimizer_noauto' value='true' " . (ewww_image_optimizer_get_option('ewww_image_optimizer_noauto') == TRUE ? "checked='true'" : "") . " /> " . __('Images will not be optimized on upload. Images may be optimized with the Bulk Optimize tools or with Scheduled optimization.', EWWW_IMAGE_OPTIMIZER_DOMAIN) . "</td></tr>\n";
    $output[] = "<tr><th><label for='ewww_image_optimizer_include_media_paths'>" . __('Include Media Library Folders', EWWW_IMAGE_OPTIMIZER_DOMAIN) . "</label></th><td><input type='checkbox' id='ewww_image_optimizer_include_media_paths' name='ewww_image_optimizer_include_media_paths' value='true' " . (ewww_image_optimizer_get_option('ewww_image_optimizer_include_media_paths') == TRUE ? "checked='true'" : "") . " /> " . __('If you have disabled automatic optimization, enable this if you want Scheduled Optimization to include the latest two folders from the Media Library.', EWWW_IMAGE_OPTIMIZER_DOMAIN) . "</td></tr>\n";
    //$output[] = "<tr><th>" . __( 'Disable Resize Optimization', EWWW_IMAGE_OPTIMIZER_DOMAIN ) . "</th><td><p>" . __( 'Wordpress, your theme, and other plugins generate various image sizes. Checked sizes will NOT be optimized.', EWWW_IMAGE_OPTIMIZER_DOMAIN ) . "</p>";
    $output[] = "<tr><th>" . __('Disable Resizes', EWWW_IMAGE_OPTIMIZER_DOMAIN) . "</th><td><p>" . __('Wordpress, your theme, and other plugins generate various image sizes. You may disable optimization for certain sizes, or completely prevent those sizes from being created.', EWWW_IMAGE_OPTIMIZER_DOMAIN) . "</p>\n";
    //	$output[] = "<p class='description'>" . __( 'The Thumbnail Settings on the Wordpress Image Editor will control which sizes get optimized after saving image edits.', EWWW_IMAGE_OPTIMIZER_DOMAIN ) . "</p>";
    $image_sizes = ewww_image_optimizer_get_image_sizes();
    $disabled_sizes = ewww_image_optimizer_get_option('ewww_image_optimizer_disable_resizes');
    $disabled_sizes_opt = ewww_image_optimizer_get_option('ewww_image_optimizer_disable_resizes_opt');
    $output[] = '<table><tr><th>' . __('Disable Optimization', EWWW_IMAGE_OPTIMIZER_DOMAIN) . '</th><th>' . __('Disable Creation', EWWW_IMAGE_OPTIMIZER_DOMAIN) . "</th></tr>\n";
    foreach ($image_sizes as $size => $dimensions) {
        if ($size != 'thumbnail') {
            $output[] = "<tr><td><input type='checkbox' id='ewww_image_optimizer_disable_resizes_opt_{$size}' name='ewww_image_optimizer_disable_resizes_opt[{$size}]' value='true' " . (!empty($disabled_sizes_opt[$size]) ? "checked='true'" : "") . " /></td><td><input type='checkbox' id='ewww_image_optimizer_disable_resizes_{$size}' name='ewww_image_optimizer_disable_resizes[{$size}]' value='true' " . (!empty($disabled_sizes[$size]) ? "checked='true'" : "") . " /></td><td><label for='ewww_image_optimizer_disable_resizes_{$size}'>{$size} - {$dimensions['width']}x{$dimensions['height']}</label></td></tr>\n";
        } else {
            $output[] = "<tr><td><input type='checkbox' id='ewww_image_optimizer_disable_resizes_opt_{$size}' name='ewww_image_optimizer_disable_resizes_opt[{$size}]' value='true' " . (!empty($disabled_sizes_opt[$size]) ? "checked='true'" : "") . " /></td><td><input type='checkbox' id='ewww_image_optimizer_disable_resizes_{$size}' name='ewww_image_optimizer_disable_resizes[{$size}]' value='true' disabled /></td><td><label for='ewww_image_optimizer_disable_resizes_{$size}'>{$size} - {$dimensions['width']}x{$dimensions['height']}</label></td></tr>\n";
        }
    }
    $output[] = "</table>\n";
    $output[] = "</td></tr>\n";
    $output[] = "<tr><th><label for='ewww_image_optimizer_skip_size'>" . __('Skip Small Images', EWWW_IMAGE_OPTIMIZER_DOMAIN) . "</label></th><td><input type='text' id='ewww_image_optimizer_skip_size' name='ewww_image_optimizer_skip_size' size='8' value='" . ewww_image_optimizer_get_option('ewww_image_optimizer_skip_size') . "'> " . __('Do not optimize images smaller than this (in bytes)', EWWW_IMAGE_OPTIMIZER_DOMAIN) . "</td></tr>\n";
    $output[] = "<tr><th><label for='ewww_image_optimizer_skip_png_size'>" . __('Skip Large PNG Images', EWWW_IMAGE_OPTIMIZER_DOMAIN) . "</label></th><td><input type='text' id='ewww_image_optimizer_skip_png_size' name='ewww_image_optimizer_skip_png_size' size='8' value='" . ewww_image_optimizer_get_option('ewww_image_optimizer_skip_png_size') . "'> " . __('Do not optimize PNG images larger than this (in bytes)', EWWW_IMAGE_OPTIMIZER_DOMAIN) . "</td></tr>\n";
    $output[] = "<tr><th><label for='ewww_image_optimizer_lossy_skip_full'>" . __('Exclude full-size images from lossy optimization', EWWW_IMAGE_OPTIMIZER_DOMAIN) . "</label></th><td><input type='checkbox' id='ewww_image_optimizer_lossy_skip_full' name='ewww_image_optimizer_lossy_skip_full' value='true' " . (ewww_image_optimizer_get_option('ewww_image_optimizer_lossy_skip_full') == TRUE ? "checked='true'" : "") . " /></td></tr>\n";
    $output[] = "<tr><th><label for='ewww_image_optimizer_metadata_skip_full'>" . __('Exclude full-size images from metadata removal', EWWW_IMAGE_OPTIMIZER_DOMAIN) . "</label></th><td><input type='checkbox' id='ewww_image_optimizer_metadata_skip_full' name='ewww_image_optimizer_metadata_skip_full' value='true' " . (ewww_image_optimizer_get_option('ewww_image_optimizer_metadata_skip_full') == TRUE ? "checked='true'" : "") . " /></td></tr>\n";
    $output[] = "<tr class='nocloud'><th><label for='ewww_image_optimizer_skip_bundle'>" . __('Use System Paths', EWWW_IMAGE_OPTIMIZER_DOMAIN) . "</label></th><td><input type='checkbox' id='ewww_image_optimizer_skip_bundle' name='ewww_image_optimizer_skip_bundle' value='true' " . (ewww_image_optimizer_get_option('ewww_image_optimizer_skip_bundle') == TRUE ? "checked='true'" : "") . " /> " . sprintf(__('If you have already installed the utilities in a system location, such as %s or %s, use this to force the plugin to use those versions and skip the auto-installers.', EWWW_IMAGE_OPTIMIZER_DOMAIN), '/usr/local/bin', '/usr/bin') . "</td></tr>\n";
    $output[] = "<tr class='nocloud'><th><label for='ewww_image_optimizer_disable_jpegtran'>" . __('disable', EWWW_IMAGE_OPTIMIZER_DOMAIN) . " jpegtran</label></th><td><input type='checkbox' id='ewww_image_optimizer_disable_jpegtran' name='ewww_image_optimizer_disable_jpegtran' " . (ewww_image_optimizer_get_option('ewww_image_optimizer_disable_jpegtran') == TRUE ? "checked='true'" : "") . " /></td></tr>\n";
    $output[] = "<tr class='nocloud'><th><label for='ewww_image_optimizer_disable_optipng'>" . __('disable', EWWW_IMAGE_OPTIMIZER_DOMAIN) . " optipng</label></th><td><input type='checkbox' id='ewww_image_optimizer_disable_optipng' name='ewww_image_optimizer_disable_optipng' " . (ewww_image_optimizer_get_option('ewww_image_optimizer_disable_optipng') == TRUE ? "checked='true'" : "") . " /></td></tr>\n";
    $output[] = "<tr class='nocloud'><th><label for='ewww_image_optimizer_disable_pngout'>" . __('disable', EWWW_IMAGE_OPTIMIZER_DOMAIN) . " pngout</label></th><td><input type='checkbox' id='ewww_image_optimizer_disable_pngout' name='ewww_image_optimizer_disable_pngout' " . (ewww_image_optimizer_get_option('ewww_image_optimizer_disable_pngout') == TRUE ? "checked='true'" : "") . " /></td><tr>\n";
    $output[] = "<tr class='nocloud'><th><label for='ewww_image_optimizer_disable_gifsicle'>" . __('disable', EWWW_IMAGE_OPTIMIZER_DOMAIN) . " gifsicle</label></th><td><input type='checkbox' id='ewww_image_optimizer_disable_gifsicle' name='ewww_image_optimizer_disable_gifsicle' " . (ewww_image_optimizer_get_option('ewww_image_optimizer_disable_gifsicle') == TRUE ? "checked='true'" : "") . " /></td></tr>\n";
    $output[] = "</table>\n</div>\n";
    $output[] = "<div id='ewww-conversion-settings'>\n";
    $output[] = "<p>" . __('Conversion is only available for images in the Media Library (except WebP). By default, all images have a link available in the Media Library for one-time conversion. Turning on individual conversion operations below will enable conversion filters any time an image is uploaded or modified.', EWWW_IMAGE_OPTIMIZER_DOMAIN) . "<br />\n" . "<b>" . __('NOTE:', EWWW_IMAGE_OPTIMIZER_DOMAIN) . "</b> " . __('The plugin will attempt to update image locations for any posts that contain the images. You may still need to manually update locations/urls for converted images.', EWWW_IMAGE_OPTIMIZER_DOMAIN) . "\n" . "</p>\n";
    $output[] = "<table class='form-table'>\n";
    $output[] = "<tr><th><label for='ewww_image_optimizer_disable_convert_links'>" . __('Hide Conversion Links', EWWW_IMAGE_OPTIMIZER_DOMAIN) . "</label</th><td><input type='checkbox' id='ewww_image_optimizer_disable_convert_links' name='ewww_image_optimizer_disable_convert_links' " . (ewww_image_optimizer_get_option('ewww_image_optimizer_disable_convert_links') == TRUE ? "checked='true'" : "") . " /> " . __('Site or Network admins can use this to prevent other users from using the conversion links in the Media Library which bypass the settings below.', EWWW_IMAGE_OPTIMIZER_DOMAIN) . "</td></tr>\n";
    $output[] = "<tr><th><label for='ewww_image_optimizer_delete_originals'>" . __('Delete originals', EWWW_IMAGE_OPTIMIZER_DOMAIN) . "</label></th><td><input type='checkbox' id='ewww_image_optimizer_delete_originals' name='ewww_image_optimizer_delete_originals' " . (ewww_image_optimizer_get_option('ewww_image_optimizer_delete_originals') == TRUE ? "checked='true'" : "") . " /> " . __('This will remove the original image from the server after a successful conversion.', EWWW_IMAGE_OPTIMIZER_DOMAIN) . "</td></tr>\n";
    $output[] = "<tr><th><label for='ewww_image_optimizer_webp'>" . __('JPG/PNG to WebP', EWWW_IMAGE_OPTIMIZER_DOMAIN) . "</label></th><td><span><input type='checkbox' id='ewww_image_optimizer_webp' name='ewww_image_optimizer_webp' value='true' " . (ewww_image_optimizer_get_option('ewww_image_optimizer_webp') == TRUE ? "checked='true'" : "") . " /> <b>" . __('WARNING:', EWWW_IMAGE_OPTIMIZER_DOMAIN) . '</b> ' . __('JPG to WebP conversion is lossy, but quality loss is minimal. PNG to WebP conversion is lossless.', EWWW_IMAGE_OPTIMIZER_DOMAIN) . "</span>\n" . "<p class='description'>" . __('Originals are never deleted, and WebP images should only be served to supported browsers.', EWWW_IMAGE_OPTIMIZER_DOMAIN) . " <a href='#webp-rewrite'>" . __('You can use the rewrite rules below to serve WebP images with Apache.', EWWW_IMAGE_OPTIMIZER_DOMAIN) . "</a></td></tr>\n";
    $output[] = "<tr><th><label for='ewww_image_optimizer_webp_for_cdn'>" . __('Alternative WebP Rewriting', EWWW_IMAGE_OPTIMIZER_DOMAIN) . "</label></th><td><span><input type='checkbox' id='ewww_image_optimizer_webp_for_cdn' name='ewww_image_optimizer_webp_for_cdn' value='true' " . (ewww_image_optimizer_get_option('ewww_image_optimizer_webp_for_cdn') == TRUE ? "checked='true'" : "") . " /> " . __('Uses output buffering and libxml functionality from PHP. Use this if the Apache rewrite rules do not work, or if your images are served from a CDN.', EWWW_IMAGE_OPTIMIZER_DOMAIN) . "</span></td></tr>";
    $output[] = "<tr><th><label for='ewww_image_optimizer_jpg_to_png'>" . sprintf(__('enable %s to %s conversion', EWWW_IMAGE_OPTIMIZER_DOMAIN), 'JPG', 'PNG') . "</label></th><td><span><input type='checkbox' id='ewww_image_optimizer_jpg_to_png' name='ewww_image_optimizer_jpg_to_png' " . (ewww_image_optimizer_get_option('ewww_image_optimizer_jpg_to_png') == TRUE ? "checked='true'" : "") . " /> <b>" . __('WARNING:', EWWW_IMAGE_OPTIMIZER_DOMAIN) . "</b> " . __('Removes metadata and increases cpu usage dramatically.', EWWW_IMAGE_OPTIMIZER_DOMAIN) . "</span>\n" . "<p class='description'>" . __('PNG is generally much better than JPG for logos and other images with a limited range of colors. Checking this option will slow down JPG processing significantly, and you may want to enable it only temporarily.', EWWW_IMAGE_OPTIMIZER_DOMAIN) . "</p></td></tr>\n";
    $output[] = "<tr><th><label for='ewww_image_optimizer_png_to_jpg'>" . sprintf(__('enable %s to %s conversion', EWWW_IMAGE_OPTIMIZER_DOMAIN), 'PNG', 'JPG') . "</label></th><td><span><input type='checkbox' id='ewww_image_optimizer_png_to_jpg' name='ewww_image_optimizer_png_to_jpg' " . (ewww_image_optimizer_get_option('ewww_image_optimizer_png_to_jpg') == TRUE ? "checked='true'" : "") . " /> <b>" . __('WARNING:', EWWW_IMAGE_OPTIMIZER_DOMAIN) . "</b> " . __('This is not a lossless conversion.', EWWW_IMAGE_OPTIMIZER_DOMAIN) . "</span>\n" . "<p class='description'>" . __('JPG is generally much better than PNG for photographic use because it compresses the image and discards data. PNGs with transparency are not converted by default.', EWWW_IMAGE_OPTIMIZER_DOMAIN) . "</p>\n" . "<span><label for='ewww_image_optimizer_jpg_background'> " . __('JPG background color:', EWWW_IMAGE_OPTIMIZER_DOMAIN) . "</label> #<input type='text' id='ewww_image_optimizer_jpg_background' name='ewww_image_optimizer_jpg_background' size='6' value='" . ewww_image_optimizer_jpg_background() . "' /> <span style='padding-left: 12px; font-size: 12px; border: solid 1px #555555; background-color: #" . ewww_image_optimizer_jpg_background() . "'>&nbsp;</span> " . __('HEX format (#123def)', EWWW_IMAGE_OPTIMIZER_DOMAIN) . ".</span>\n" . "<p class='description'>" . __('Background color is used only if the PNG has transparency. Leave this value blank to skip PNGs with transparency.', EWWW_IMAGE_OPTIMIZER_DOMAIN) . "</p>\n" . "<span><label for='ewww_image_optimizer_jpg_quality'>" . __('JPG quality level:', EWWW_IMAGE_OPTIMIZER_DOMAIN) . "</label> <input type='text' id='ewww_image_optimizer_jpg_quality' name='ewww_image_optimizer_jpg_quality' class='small-text' value='" . ewww_image_optimizer_jpg_quality() . "' /> " . __('Valid values are 1-100.', EWWW_IMAGE_OPTIMIZER_DOMAIN) . "</span>\n" . "<p class='description'>" . __('If JPG quality is blank, the plugin will attempt to set the optimal quality level or default to 92. Remember, this is a lossy conversion, so you are losing pixels, and it is not recommended to actually set the level here unless you want noticable loss of image quality.', EWWW_IMAGE_OPTIMIZER_DOMAIN) . "</p></td></tr>\n";
    $output[] = "<tr><th><label for='ewww_image_optimizer_gif_to_png'>" . sprintf(__('enable %s to %s conversion', EWWW_IMAGE_OPTIMIZER_DOMAIN), 'GIF', 'PNG') . "</label></th><td><span><input type='checkbox' id='ewww_image_optimizer_gif_to_png' name='ewww_image_optimizer_gif_to_png' " . (ewww_image_optimizer_get_option('ewww_image_optimizer_gif_to_png') == TRUE ? "checked='true'" : "") . " /> " . __('No warnings here, just do it.', EWWW_IMAGE_OPTIMIZER_DOMAIN) . "</span>\n" . "<p class='description'> " . __('PNG is generally better than GIF, but animated images cannot be converted.', EWWW_IMAGE_OPTIMIZER_DOMAIN) . "</p></td></tr>\n";
    $output[] = "</table>\n</div>\n";
    $output[] = "<p class='submit'><input type='submit' class='button-primary' value='" . __('Save Changes', EWWW_IMAGE_OPTIMIZER_DOMAIN) . "' /></p>\n";
    $output[] = "</form>\n";
    if (ewww_image_optimizer_get_option('ewww_image_optimizer_webp') && !ewww_image_optimizer_get_option('ewww_image_optimizer_webp_for_cdn')) {
        $output[] = "<form id='ewww-webp-rewrite'>\n";
        $output[] = "<p>" . __('There are many ways to serve WebP images to visitors with supported browsers. You may choose any you wish, but it is recommended to serve them with an .htaccess file using mod_rewrite and mod_headers. The plugin can insert the rules for you if the file is writable, or you can edit .htaccess yourself.', EWWW_IMAGE_OPTIMIZER_DOMAIN) . "</p>\n";
        if (!ewww_image_optimizer_webp_rewrite_verify()) {
            $output[] = "<img id='webp-image' src='" . plugins_url('/test.png', __FILE__) . "' style='float: right; padding: 0 0 10px 10px;'>\n" . "<p id='ewww-webp-rewrite-status'><b>" . __('Rules verified successfully', EWWW_IMAGE_OPTIMIZER_DOMAIN) . "</b></p>\n";
        } else {
            $output[] = "<pre id='webp-rewrite-rules' style='background: white; font-color: black; border: 1px solid black; clear: both; padding: 10px;'>\n" . "&lt;IfModule mod_rewrite.c&gt;\n" . "RewriteEngine On\n" . "RewriteCond %{HTTP_ACCEPT} image/webp\n" . "RewriteCond %{REQUEST_FILENAME} (.*)\\.(jpe?g|png)\$\n" . "RewriteCond %{REQUEST_FILENAME}\\.webp -f\n" . "RewriteRule (.+)\\.(jpe?g|png)\$ %{REQUEST_FILENAME}.webp [T=image/webp,E=accept:1]\n" . "&lt;/IfModule&gt;\n" . "&lt;IfModule mod_headers.c&gt;\n" . "Header append Vary Accept env=REDIRECT_accept\n" . "&lt;/IfModule&gt;\n" . "AddType image/webp .webp</pre>\n" . "<img id='webp-image' src='" . plugins_url('/test.png', __FILE__) . "' style='float: right; padding-left: 10px;'>\n" . "<p id='ewww-webp-rewrite-status'>" . __('The image to the right will display a WebP image with WEBP in white text, if your site is serving WebP images and your browser supports WebP.', EWWW_IMAGE_OPTIMIZER_DOMAIN) . "</p>\n" . "<button type='submit' class='button-secondary action'>" . __('Insert Rewrite Rules', EWWW_IMAGE_OPTIMIZER_DOMAIN) . "</button>\n";
        }
        $output[] = "</form>\n";
    }
    $output[] = "</div><!-- end container left -->\n";
    $output[] = "<div id='ewww-container-right' class='nocloud' style='border: 1px solid #e5e5e5; float: right; margin-left: -215px; padding: 0em 1.5em 1em; background-color: #fff; box-shadow: 0 1px 1px rgba(0, 0, 0, 0.04); display: inline-block; width: 174px;'>\n" . "<h3>Support EWWW I.O.</h3>\n" . "<p>Would you like to help support development of this plugin?<br />\n" . "<p>Contribute directly by <a href='https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&amp;hosted_button_id=MKMQKCBFFG3WW'>donating with Paypal</a>.</p>\n" . "<b>OR</b><br />\n" . "Use any of these referral links to show your appreciation:</p>\n" . "<p><b>Web Hosting:</b><br>\n" . "<a href='https://partners.a2hosting.com/solutions.php?id=5959&url=638'>A2 Hosting</a> with automatic EWWW IO setup<br>\n" . "<a href='http://www.dreamhost.com/r.cgi?132143'>Dreamhost</a><br>\n" . "<a href='http://www.bluehost.com/track/nosilver4u'>Bluehost</a><!-- <br>\n" . "<a href='http://www.liquidweb.com/?RID=nosilver4u'>liquidweb</a><br>\n" . "<a href='http://www.stormondemand.com/?RID=nosilver4u'>Storm on Demand</a>-->\n" . "</p>\n" . "<p><b>VPS:</b><br>\n" . "<a href='http://www.bluehost.com/track/nosilver4u?page=/vps'>Bluehost</a><br>\n" . "<a href='https://www.digitalocean.com/?refcode=89ef0197ec7e'>DigitalOcean</a><br>\n" . "<a href='https://clientarea.ramnode.com/aff.php?aff=1469'>RamNode</a><br>\n" . "<a href='http://www.vultr.com/?ref=6814210'>VULTR</a>\n" . "</p>\n" . "<p><b>CDN Network:</b><br>Add MaxCDN to increase website speeds dramatically! <a target='_blank' href='http://tracking.maxcdn.com/c/91625/36539/378'>Sign Up Now and Save 25%</a> (100% Money Back Guarantee for 30 days). Integrate it within Wordpress using the W3 Total Cache plugin.</p>\n" . "</div>\n" . "</div>\n";
    $ewww_debug .= '--' . ini_get('max_execution_time') . '--<br>';
    echo apply_filters('ewww_image_optimizer_settings', $output);
    ewwwio_memory(__FUNCTION__);
}
コード例 #21
0
ファイル: bulk.php プロジェクト: crazyyy/bessarabia
function ewww_image_optimizer_bulk_loop()
{
    ewwwio_debug_message('<b>' . __FUNCTION__ . '()</b>');
    global $ewww_defer;
    $ewww_defer = false;
    $output = array();
    // verify that an authorized user has started the optimizer
    $permissions = apply_filters('ewww_image_optimizer_bulk_permissions', '');
    if (!wp_verify_nonce($_REQUEST['ewww_wpnonce'], 'ewww-image-optimizer-bulk') || !current_user_can($permissions)) {
        $output['error'] = esc_html__('Access token has expired, please reload the page.', EWWW_IMAGE_OPTIMIZER_DOMAIN);
        echo json_encode($output);
        die;
    }
    session_write_close();
    // retrieve the time when the optimizer starts
    $started = microtime(true);
    if (ewww_image_optimizer_stl_check() && ini_get('max_execution_time')) {
        set_time_limit(0);
    }
    // find out if our nonce is on it's last leg/tick
    $tick = wp_verify_nonce($_REQUEST['ewww_wpnonce'], 'ewww-image-optimizer-bulk');
    if ($tick === 2) {
        $output['new_nonce'] = wp_create_nonce('ewww-image-optimizer-bulk');
    } else {
        $output['new_nonce'] = '';
    }
    // get the 'bulk attachments' with a list of IDs remaining
    $attachments = get_option('ewww_image_optimizer_bulk_attachments');
    $attachment = array_shift($attachments);
    $meta = wp_get_attachment_metadata($attachment, true);
    // do the optimization for the current attachment (including resizes)
    $meta = ewww_image_optimizer_resize_from_meta_data($meta, $attachment, false);
    $ewww_status = get_transient('ewww_image_optimizer_cloud_status');
    if (!empty($ewww_status) && preg_match('/exceeded/', $ewww_status)) {
        $output['error'] = esc_html__('License Exceeded', EWWW_IMAGE_OPTIMIZER_DOMAIN);
        echo json_encode($output);
        die;
    }
    if (!empty($meta['file'])) {
        // output the filename (and path relative to 'uploads' folder)
        $output['results'] = sprintf("<p>" . esc_html__('Optimized', EWWW_IMAGE_OPTIMIZER_DOMAIN) . " <strong>%s</strong><br>", esc_html($meta['file']));
    } else {
        $output['results'] = sprintf("<p>" . esc_html__('Skipped image, ID:', EWWW_IMAGE_OPTIMIZER_DOMAIN) . " <strong>%s</strong><br>", esc_html($attachment));
    }
    if (!empty($meta['ewww_image_optimizer'])) {
        // tell the user what the results were for the original image
        $output['results'] .= sprintf(esc_html__('Full size – %s', EWWW_IMAGE_OPTIMIZER_DOMAIN) . "<br>", esc_html($meta['ewww_image_optimizer']));
    }
    // check to see if there are resized version of the image
    if (isset($meta['sizes']) && is_array($meta['sizes'])) {
        // cycle through each resize
        foreach ($meta['sizes'] as $size) {
            if (!empty($size['ewww_image_optimizer'])) {
                // output the results for the current resized version
                $output['results'] .= sprintf("%s – %s<br>", esc_html($size['file']), esc_html($size['ewww_image_optimizer']));
            }
        }
    }
    // calculate how much time has elapsed since we started
    $elapsed = microtime(true) - $started;
    // output how much time has elapsed since we started
    $output['results'] .= sprintf(esc_html__('Elapsed: %.3f seconds', EWWW_IMAGE_OPTIMIZER_DOMAIN) . "</p>", $elapsed);
    global $ewww_attachment;
    $ewww_attachment['id'] = $attachment;
    $ewww_attachment['meta'] = $meta;
    add_filter('w3tc_cdn_update_attachment_metadata', 'ewww_image_optimizer_w3tc_update_files');
    // update the metadata for the current attachment
    wp_update_attachment_metadata($attachment, $meta);
    // store the updated list of attachment IDs back in the 'bulk_attachments' option
    update_option('ewww_image_optimizer_bulk_attachments', $attachments);
    if (ewww_image_optimizer_get_option('ewww_image_optimizer_debug')) {
        global $ewww_debug;
        $output['results'] .= '<div style="background-color:#ffff99;">' . $ewww_debug . '</div>';
    }
    if (!empty($attachments)) {
        $next_attachment = array_shift($attachments);
        $next_file = ewww_image_optimizer_bulk_filename($next_attachment);
        // generate the WP spinner image for display
        $loading_image = plugins_url('/images/wpspin.gif', __FILE__);
        if ($next_file) {
            $output['next_file'] = "<p>" . esc_html__('Optimizing', EWWW_IMAGE_OPTIMIZER_DOMAIN) . " <b>{$next_file}</b>&nbsp;<img src='{$loading_image}' /></p>";
        } else {
            $output['next_file'] = "<p>" . esc_html__('Optimizing', EWWW_IMAGE_OPTIMIZER_DOMAIN) . "&nbsp;<img src='{$loading_image}' /></p>";
        }
    }
    echo json_encode($output);
    ewww_image_optimizer_debug_log();
    ewwwio_memory(__FUNCTION__);
    die;
}
コード例 #22
0
 function ewww_manage_image_custom_column($column_name, $id)
 {
     // once we've found our custom column
     if ($column_name == 'ewww_image_optimizer') {
         // get the metadata for the image
         $meta = new nggMeta($id);
         // get the optimization status for the image
         $status = $meta->get_META('ewww_image_optimizer');
         $msg = '';
         // get the file path of the image
         $file_path = $meta->image->imagePath;
         // get the mimetype of the image
         $type = ewww_image_optimizer_mimetype($file_path, 'i');
         // retrieve the human-readable filesize of the image
         $file_size = size_format(ewww_image_optimizer_filesize($file_path), 2);
         $file_size = str_replace('B ', 'B', $file_size);
         //$file_size = ewww_image_optimizer_format_bytes(filesize($file_path));
         $valid = true;
         // check to see if we have a tool to handle the mimetype detected
         switch ($type) {
             case 'image/jpeg':
                 // if jpegtran is missing, tell the user
                 if (!EWWW_IMAGE_OPTIMIZER_JPEGTRAN && !ewww_image_optimizer_get_option('ewww_image_optimizer_cloud_jpg')) {
                     $valid = false;
                     $msg = '<br>' . sprintf(__('%s is missing', EWWW_IMAGE_OPTIMIZER_DOMAIN), '<em>jpegtran</em>');
                 }
                 break;
             case 'image/png':
                 // if the PNG tools are missing, tell the user
                 if (!EWWW_IMAGE_OPTIMIZER_PNGOUT && !EWWW_IMAGE_OPTIMIZER_OPTIPNG && !ewww_image_optimizer_get_option('ewww_image_optimizer_cloud_png')) {
                     $valid = false;
                     $msg = '<br>' . sprintf(__('%s is missing', EWWW_IMAGE_OPTIMIZER_DOMAIN), '<em>optipng/pngout</em>');
                 }
                 break;
             case 'image/gif':
                 // if gifsicle is missing, tell the user
                 if (!EWWW_IMAGE_OPTIMIZER_GIFSICLE && !ewww_image_optimizer_get_option('ewww_image_optimizer_cloud_gif')) {
                     $valid = false;
                     $msg = '<br>' . sprintf(__('%s is missing', EWWW_IMAGE_OPTIMIZER_DOMAIN), '<em>gifsicle</em>');
                 }
                 break;
             default:
                 $valid = false;
         }
         // file isn't in a format we can work with, we don't work with strangers
         if ($valid == false) {
             print __('Unsupported file type', EWWW_IMAGE_OPTIMIZER_DOMAIN) . $msg;
             return;
         }
         // if we have a valid status, display it, the image size, and give a re-optimize link
         if ($status && !empty($status)) {
             echo $status;
             echo "<br>" . sprintf(__('Image Size: %s', EWWW_IMAGE_OPTIMIZER_DOMAIN), $file_size);
             printf("<br><a href=\"admin.php?action=ewww_ngg_manual&amp;ewww_force=1&amp;ewww_attachment_ID=%d\">%s</a>", $id, __('Re-optimize', EWWW_IMAGE_OPTIMIZER_DOMAIN));
             // otherwise, give the image size, and a link to optimize right now
         } else {
             _e('Not processed', EWWW_IMAGE_OPTIMIZER_DOMAIN);
             echo "<br>" . sprintf(__('Image Size: %s', EWWW_IMAGE_OPTIMIZER_DOMAIN), $file_size);
             printf("<br><a href=\"admin.php?action=ewww_ngg_manual&amp;ewww_attachment_ID=%d\">%s</a>", $id, __('Optimize now!', EWWW_IMAGE_OPTIMIZER_DOMAIN));
         }
     }
 }
コード例 #23
0
/**
 * Print column data for optimizer results in the media library using
 * the `manage_media_custom_column` hook.
 */
function ewww_image_optimizer_custom_column($column_name, $id)
{
    global $ewww_debug;
    $ewww_debug .= "<b>ewww_image_optimizer_custom_column()</b><br>";
    // once we get to the EWWW IO custom column
    if ($column_name == 'ewww-image-optimizer') {
        // retrieve the metadata
        $meta = wp_get_attachment_metadata($id);
        if (ewww_image_optimizer_get_option('ewww_image_optimizer_debug')) {
            $print_meta = print_r($meta, TRUE);
            $print_meta = preg_replace(array('/ /', '/\\n+/'), array('&nbsp;', '<br />'), $print_meta);
            echo '<div style="background-color:#ffff99;font-size: 10px;padding: 10px;margin:-10px -10px 10px;line-height: 1.1em">' . $print_meta . '</div>';
        }
        if (!empty($meta['cloudinary'])) {
            _e('Cloudinary image', EWWW_IMAGE_OPTIMIZER_DOMAIN);
            return;
        }
        // if the filepath isn't set in the metadata
        if (empty($meta['file'])) {
            if (isset($meta['file'])) {
                unset($meta['file']);
                if (strpos($meta['ewww_image_optimizer'], 'Could not find') === 0) {
                    unset($meta['ewww_image_optimizer']);
                }
                wp_update_attachment_metadata($id, $meta);
            }
        }
        list($file_path, $upload_path) = ewww_image_optimizer_attachment_path($meta, $id);
        // if the file does not exist
        if (empty($file_path)) {
            _e('Could not retrieve file path.', EWWW_IMAGE_OPTIMIZER_DOMAIN);
            return;
        }
        $msg = '';
        // retrieve the mimetype of the attachment
        $type = ewww_image_optimizer_mimetype($file_path, 'i');
        // get a human readable filesize
        $file_size = size_format(filesize($file_path), 2);
        $file_size = preg_replace('/\\.00 B /', ' B', $file_size);
        // run the appropriate code based on the mimetype
        switch ($type) {
            case 'image/jpeg':
                // if jpegtran is missing, tell them that
                if (!EWWW_IMAGE_OPTIMIZER_JPEGTRAN && !EWWW_IMAGE_OPTIMIZER_CLOUD) {
                    $valid = false;
                    $msg = '<br>' . sprintf(__('%s is missing', EWWW_IMAGE_OPTIMIZER_DOMAIN), '<em>jpegtran</em>');
                } else {
                    $convert_link = __('JPG to PNG', EWWW_IMAGE_OPTIMIZER_DOMAIN);
                    $class_type = 'jpg';
                    $convert_desc = __('WARNING: Removes metadata. Requires GD or ImageMagick. PNG is generally much better than JPG for logos and other images with a limited range of colors.', EWWW_IMAGE_OPTIMIZER_DOMAIN);
                }
                break;
            case 'image/png':
                // if pngout and optipng are missing, tell the user
                if (!EWWW_IMAGE_OPTIMIZER_PNGOUT && !EWWW_IMAGE_OPTIMIZER_OPTIPNG && !EWWW_IMAGE_OPTIMIZER_CLOUD) {
                    $valid = false;
                    $msg = '<br>' . sprintf(__('%s is missing', EWWW_IMAGE_OPTIMIZER_DOMAIN), '<em>optipng/pngout</em>');
                } else {
                    $convert_link = __('PNG to JPG', EWWW_IMAGE_OPTIMIZER_DOMAIN);
                    $class_type = 'png';
                    $convert_desc = __('WARNING: This is not a lossless conversion and requires GD or ImageMagick. JPG is much better than PNG for photographic use because it compresses the image and discards data. Transparent images will only be converted if a background color has been set.', EWWW_IMAGE_OPTIMIZER_DOMAIN);
                }
                break;
            case 'image/gif':
                // if gifsicle is missing, tell the user
                if (!EWWW_IMAGE_OPTIMIZER_GIFSICLE && !EWWW_IMAGE_OPTIMIZER_CLOUD) {
                    $valid = false;
                    $msg = '<br>' . sprintf(__('%s is missing', EWWW_IMAGE_OPTIMIZER_DOMAIN), '<em>gifsicle</em>');
                } else {
                    $convert_link = __('GIF to PNG', EWWW_IMAGE_OPTIMIZER_DOMAIN);
                    $class_type = 'gif';
                    $convert_desc = __('PNG is generally better than GIF, but does not support animation. Animated images will not be converted.', EWWW_IMAGE_OPTIMIZER_DOMAIN);
                }
                break;
            default:
                // not a supported mimetype
                _e('Unsupported file type', EWWW_IMAGE_OPTIMIZER_DOMAIN);
                return;
        }
        // if the optimizer metadata exists
        if (isset($meta['ewww_image_optimizer']) && !empty($meta['ewww_image_optimizer'])) {
            // output the optimizer results
            echo $meta['ewww_image_optimizer'];
            // output the filesize
            echo "<br>" . sprintf(__('Image Size: %s', EWWW_IMAGE_OPTIMIZER_DOMAIN), $file_size);
            // output a link to re-optimize manually
            printf("<br><a href=\"admin.php?action=ewww_image_optimizer_manual_optimize&amp;force=1&amp;attachment_ID=%d\">%s</a>", $id, __('Re-optimize', EWWW_IMAGE_OPTIMIZER_DOMAIN));
            if (!ewww_image_optimizer_get_option('ewww_image_optimizer_disable_convert_links') && 'ims_image' != get_post_type($id)) {
                echo " | <a class='ewww-convert' title='{$convert_desc}' href='admin.php?action=ewww_image_optimizer_manual_optimize&amp;attachment_ID={$id}&amp;convert=1&amp;force=1'>{$convert_link}</a>";
            }
            $restorable = false;
            if (!empty($meta['converted'])) {
                if (!empty($meta['orig_file']) && file_exists($meta['orig_file'])) {
                    $restorable = true;
                }
            }
            if (isset($meta['sizes'])) {
                // meta sizes don't contain a path, so we calculate one
                $base_dir = dirname($file_path) . '/';
                foreach ($meta['sizes'] as $size => $data) {
                    if (!empty($data['converted'])) {
                        if (!empty($data['orig_file']) && file_exists($base_dir . $data['orig_file'])) {
                            $restorable = true;
                        }
                    }
                }
            }
            if ($restorable) {
                printf("<br><a href=\"admin.php?action=ewww_image_optimizer_manual_restore&amp;attachment_ID=%d\">%s</a>", $id, __('Restore original', EWWW_IMAGE_OPTIMIZER_DOMAIN));
            }
        } else {
            // otherwise, this must be an image we haven't processed
            _e('Not processed', EWWW_IMAGE_OPTIMIZER_DOMAIN);
            // tell them the filesize
            echo "<br>" . sprintf(__('Image Size: %s', EWWW_IMAGE_OPTIMIZER_DOMAIN), $file_size);
            // and give the user the option to optimize the image right now
            printf("<br><a href=\"admin.php?action=ewww_image_optimizer_manual_optimize&amp;attachment_ID=%d\">%s</a>", $id, __('Optimize now!', EWWW_IMAGE_OPTIMIZER_DOMAIN));
            if (!ewww_image_optimizer_get_option('ewww_image_optimizer_disable_convert_links') && 'ims_image' != get_post_type($id)) {
                echo " | <a class='ewww-convert' title='{$convert_desc}' href='admin.php?action=ewww_image_optimizer_manual_optimize&amp;attachment_ID={$id}&amp;convert=1&amp;force=1'>{$convert_link}</a>";
            }
        }
    }
}