Пример #1
0
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__);
}
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 
}
function ewww_image_optimizer_notice_utils()
{
    global $ewww_debug;
    $ewww_debug .= "<b>ewww_image_optimizer_notice_utils()</b><br>";
    // Check if exec is disabled
    if (ewww_image_optimizer_exec_check()) {
        //display a warning if exec() is disabled, can't run much of anything without it
        echo "<div id='ewww-image-optimizer-warning-opt-png' class='error'><p>" . __('EWWW Image Optimizer requires exec(). Your system administrator has disabled this function.', EWWW_IMAGE_OPTIMIZER_DOMAIN) . "</p></div>";
        define('EWWW_IMAGE_OPTIMIZER_NOEXEC', true);
        ewww_image_optimizer_disable_tools();
        return;
        // otherwise, query the php settings for safe mode
    } elseif (ewww_image_optimizer_safemode_check()) {
        // display a warning to the user
        echo "<div id='ewww-image-optimizer-warning-opt-png' class='error'><p>" . __('Safe Mode is turned on for PHP. This plugin cannot operate in Safe Mode.', EWWW_IMAGE_OPTIMIZER_DOMAIN) . "</p></div>";
        define('EWWW_IMAGE_OPTIMIZER_NOEXEC', true);
        ewww_image_optimizer_disable_tools();
        return;
    } else {
        define('EWWW_IMAGE_OPTIMIZER_NOEXEC', false);
    }
    // attempt to retrieve values for utility paths, and store them in the appropriate variables
    $required = ewww_image_optimizer_path_check();
    // set the variables false otherwise
    $skip_jpegtran_check = false;
    $skip_optipng_check = false;
    $skip_gifsicle_check = false;
    $skip_pngout_check = false;
    $skip_pngquant_check = true;
    $skip_webp_check = true;
    // if the user has disabled a variable, we aren't going to bother checking to see if it is there
    if (ewww_image_optimizer_get_option('ewww_image_optimizer_disable_jpegtran')) {
        $skip_jpegtran_check = true;
    }
    if (ewww_image_optimizer_get_option('ewww_image_optimizer_disable_optipng')) {
        $skip_optipng_check = true;
    }
    if (ewww_image_optimizer_get_option('ewww_image_optimizer_disable_gifsicle')) {
        $skip_gifsicle_check = true;
    }
    if (ewww_image_optimizer_get_option('ewww_image_optimizer_disable_pngout')) {
        $skip_pngout_check = true;
    }
    if (ewww_image_optimizer_get_option('ewww_image_optimizer_png_lossy')) {
        $skip_pngquant_check = false;
    }
    if (ewww_image_optimizer_get_option('ewww_image_optimizer_webp')) {
        $skip_webp_check = false;
    }
    // we are going to store our validation results in $missing
    $missing = array();
    // go through each of the required tools
    foreach ($required as $key => $req) {
        // if the tool wasn't found, add it to the $missing array if we are supposed to check the tool in question
        switch ($key) {
            case 'JPEGTRAN':
                if (!$skip_jpegtran_check && empty($req)) {
                    $missing[] = 'jpegtran';
                    $req = false;
                }
                define('EWWW_IMAGE_OPTIMIZER_' . $key, $req);
                break;
            case 'OPTIPNG':
                if (!$skip_optipng_check && empty($req)) {
                    $missing[] = 'optipng';
                    $req = false;
                }
                define('EWWW_IMAGE_OPTIMIZER_' . $key, $req);
                break;
            case 'GIFSICLE':
                if (!$skip_gifsicle_check && empty($req)) {
                    $missing[] = 'gifsicle';
                    $req = false;
                }
                define('EWWW_IMAGE_OPTIMIZER_' . $key, $req);
                break;
            case 'PNGOUT':
                if (!$skip_pngout_check && empty($req)) {
                    $missing[] = 'pngout';
                    $req = false;
                }
                define('EWWW_IMAGE_OPTIMIZER_' . $key, $req);
                break;
            case 'PNGQUANT':
                if (!$skip_pngquant_check && empty($req)) {
                    $missing[] = 'pngquant';
                    $req = false;
                }
                define('EWWW_IMAGE_OPTIMIZER_' . $key, $req);
                break;
            case 'WEBP':
                if (!$skip_webp_check && empty($req)) {
                    $missing[] = 'webp';
                    $req = false;
                }
                define('EWWW_IMAGE_OPTIMIZER_' . $key, $req);
                break;
        }
    }
    // expand the missing utilities list for use in the error message
    $msg = implode(', ', $missing);
    // if there is a message, display the warning
    if (!empty($msg)) {
        echo "<div id='ewww-image-optimizer-warning-opt-png' class='error'><p>" . sprintf(__('EWWW Image Optimizer uses %1$s, %2$s, %3$s, %4$s, %5$s, and %6$s. You are missing: %7$s. Please install via the %8$s or the %9$s.', EWWW_IMAGE_OPTIMIZER_DOMAIN), "<a href='http://jpegclub.org/jpegtran/'>jpegtran</a>", "<a href='http://optipng.sourceforge.net/'>optipng</a>", "<a href='http://advsys.net/ken/utils.htm'>pngout</a>", "<a href='http://pngquant.org/'>pngquant</a>", "<a href='http://www.lcdf.org/gifsicle/'>gifsicle</a>", "<a href='https://developers.google.com/speed/webp/'>cwebp</a>", $msg, "<a href='options-general.php?page=" . EWWW_IMAGE_OPTIMIZER_PLUGIN_FILE_REL . "'>" . __('Settings Page', EWWW_IMAGE_OPTIMIZER_DOMAIN) . "</a>", "<a href='http://wordpress.org/extend/plugins/ewww-image-optimizer/installation/'>" . __('Installation Instructions', EWWW_IMAGE_OPTIMIZER_DOMAIN) . "</a>") . "</p></div>";
    }
}
Пример #4
0
/**
 * Process an image.
 *
 * Returns an array of the $file, $results, $converted to tell us if an image changes formats, and the $original file if it did.
 *
 * @param   string $file		Full absolute path to the image file
 * @param   int $gallery_type		1=wordpress, 2=nextgen, 3=flagallery, 4=aux_images, 5=image editor, 6=imagestore, 7=retina
 * @param   boolean $converted		tells us if this is a resize and the full image was converted to a new format
 * @param   boolean $new		tells the optimizer that this is a new image, so it should attempt conversion regardless of previous results
 * @param   boolean $fullsize		tells the optimizer this is a full size image
 * @returns array
 */
function ewww_image_optimizer($file, $gallery_type = 4, $converted = false, $new = false, $fullsize = false)
{
    global $ewww_debug;
    $ewww_debug .= "<b>ewww_image_optimizer()</b><br>";
    // if the plugin gets here without initializing, we need to run through some things first
    if (!defined('EWWW_IMAGE_OPTIMIZER_CLOUD')) {
        ewww_image_optimizer_init();
    }
    $bypass_optimization = apply_filters('ewww_image_optimizer_bypass', false, $file);
    if (true === $bypass_optimization) {
        // tell the user optimization was skipped
        $msg = __("Optimization skipped", EWWW_IMAGE_OPTIMIZER_DOMAIN);
        $ewww_debug .= "optimization bypassed: {$file} <br>";
        // send back the above message
        return array(false, $msg, $converted, $file);
    }
    // initialize the original filename
    $original = $file;
    $result = '';
    // check that the file exists
    if (FALSE === file_exists($file)) {
        // tell the user we couldn't find the file
        $msg = sprintf(__('Could not find %s', EWWW_IMAGE_OPTIMIZER_DOMAIN), "<span class='code'>{$file}</span>");
        $ewww_debug .= "file doesn't appear to exist: {$file} <br>";
        // send back the above message
        return array(false, $msg, $converted, $original);
    }
    // check that the file is writable
    if (FALSE === is_writable($file)) {
        // tell the user we can't write to the file
        $msg = sprintf(__('%s is not writable', EWWW_IMAGE_OPTIMIZER_DOMAIN), "<span class='code'>{$file}</span>");
        $ewww_debug .= "couldn't write to the file {$file}<br>";
        // send back the above message
        return array(false, $msg, $converted, $original);
    }
    if (function_exists('fileperms')) {
        $file_perms = substr(sprintf('%o', fileperms($file)), -4);
    }
    $file_owner = 'unknown';
    $file_group = 'unknown';
    if (function_exists('posix_getpwuid')) {
        $file_owner = posix_getpwuid(fileowner($file));
        $file_owner = $file_owner['name'];
    }
    if (function_exists('posix_getgrgid')) {
        $file_group = posix_getgrgid(filegroup($file));
        $file_group = $file_group['name'];
    }
    $ewww_debug .= "permissions: {$file_perms}, owner: {$file_owner}, group: {$file_group} <br>";
    $type = ewww_image_optimizer_mimetype($file, 'i');
    if (strpos($type, 'image') === FALSE) {
        //otherwise we store an error message since we couldn't get the mime-type
        $msg = __('Missing finfo_file(), getimagesize() and mime_content_type() PHP functions', EWWW_IMAGE_OPTIMIZER_DOMAIN);
        $ewww_debug .= "couldn't find any functions for mimetype detection<br>";
        return array(false, $msg, $converted, $original);
    }
    if (!EWWW_IMAGE_OPTIMIZER_CLOUD) {
        // check to see if 'nice' exists
        $nice = ewww_image_optimizer_find_binary('nice', 'n');
        if (!defined('EWWW_IMAGE_OPTIMIZER_NOEXEC')) {
            // Check if exec is disabled
            if (ewww_image_optimizer_exec_check()) {
                define('EWWW_IMAGE_OPTIMIZER_NOEXEC', true);
                $ewww_debug .= 'exec seems to be disabled<br>';
                ewww_image_optimizer_disable_tools();
                // otherwise, query the php settings for safe mode
            } elseif (ewww_image_optimizer_safemode_check()) {
                define('EWWW_IMAGE_OPTIMIZER_NOEXEC', true);
                $ewww_debug .= 'safe mode appears to be enabled<br>';
                ewww_image_optimizer_disable_tools();
            } else {
                define('EWWW_IMAGE_OPTIMIZER_NOEXEC', false);
            }
        }
    }
    // if the user has disabled the utility checks
    if (ewww_image_optimizer_get_option('ewww_image_optimizer_skip_check') == TRUE || EWWW_IMAGE_OPTIMIZER_CLOUD) {
        $skip_jpegtran_check = true;
        $skip_optipng_check = true;
        $skip_gifsicle_check = true;
        $skip_pngout_check = true;
    } else {
        // otherwise we set the variables to false
        $skip_jpegtran_check = false;
        $skip_optipng_check = false;
        $skip_gifsicle_check = false;
        $skip_pngout_check = false;
    }
    if (ewww_image_optimizer_get_option('ewww_image_optimizer_cloud_jpg')) {
        $skip_jpegtran_check = true;
    }
    if (ewww_image_optimizer_get_option('ewww_image_optimizer_cloud_png')) {
        $skip_optipng_check = true;
        $skip_pngout_check = true;
    }
    if (ewww_image_optimizer_get_option('ewww_image_optimizer_cloud_gif')) {
        $skip_gifsicle_check = true;
    }
    if (ewww_image_optimizer_get_option('ewww_image_optimizer_metadata_skip_full') && $fullsize) {
        $keep_metadata = true;
    } else {
        $keep_metadata = false;
    }
    if (ewww_image_optimizer_get_option('ewww_image_optimizer_lossy_skip_full') && $fullsize) {
        $skip_lossy = true;
    } else {
        $skip_lossy = false;
    }
    if (ini_get('max_execution_time') < 90 && ewww_image_optimizer_stl_check()) {
        set_time_limit(0);
    }
    // if the full-size image was converted
    if ($converted) {
        $ewww_debug .= "full-size image was converted, need to rebuild filename for meta<br>";
        $filenum = $converted;
        // grab the file extension
        preg_match('/\\.\\w+$/', $file, $fileext);
        // strip the file extension
        $filename = str_replace($fileext[0], '', $file);
        // grab the dimensions
        preg_match('/-\\d+x\\d+(-\\d+)*$/', $filename, $fileresize);
        // strip the dimensions
        $filename = str_replace($fileresize[0], '', $filename);
        // reconstruct the filename with the same increment (stored in $converted) as the full version
        $refile = $filename . '-' . $filenum . $fileresize[0] . $fileext[0];
        // rename the file
        rename($file, $refile);
        $ewww_debug .= "moved {$file} to {$refile}<br>";
        // and set $file to the new filename
        $file = $refile;
        $original = $file;
    }
    // get the original image size
    $orig_size = filesize($file);
    $ewww_debug .= "original filesize: {$orig_size}<br>";
    if ($orig_size < ewww_image_optimizer_get_option('ewww_image_optimizer_skip_size')) {
        // tell the user optimization was skipped
        $msg = __("Optimization skipped", EWWW_IMAGE_OPTIMIZER_DOMAIN);
        $ewww_debug .= "optimization bypassed due to filesize: {$file} <br>";
        // send back the above message
        return array(false, $msg, $converted, $file);
    }
    if ($type == 'image/png' && ewww_image_optimizer_get_option('ewww_image_optimizer_skip_png_size') && $orig_size > ewww_image_optimizer_get_option('ewww_image_optimizer_skip_png_size')) {
        // tell the user optimization was skipped
        $msg = __("Optimization skipped", EWWW_IMAGE_OPTIMIZER_DOMAIN);
        $ewww_debug .= "optimization bypassed due to filesize: {$file} <br>";
        // send back the above message
        return array($file, $msg, $converted, $file);
    }
    // initialize $new_size with the original size, HOW ABOUT A ZERO...
    //$new_size = $orig_size;
    $new_size = 0;
    // set the optimization process to OFF
    $optimize = false;
    // toggle the convert process to ON
    $convert = true;
    // run the appropriate optimization/conversion for the mime-type
    switch ($type) {
        case 'image/jpeg':
            $png_size = 0;
            // if jpg2png conversion is enabled, and this image is in the wordpress media library
            if (ewww_image_optimizer_get_option('ewww_image_optimizer_jpg_to_png') && $gallery_type == 1 || !empty($_GET['ewww_convert'])) {
                // generate the filename for a PNG
                // if this is a resize version
                if ($converted) {
                    // just change the file extension
                    $pngfile = preg_replace('/\\.\\w+$/', '.png', $file);
                    // if this is a full size image
                } else {
                    // get a unique filename for the png image
                    list($pngfile, $filenum) = ewww_image_optimizer_unique_filename($file, '.png');
                }
            } else {
                // otherwise, set it to OFF
                $convert = false;
                $pngfile = '';
            }
            // check for previous optimization, so long as the force flag is on and this isn't a new image that needs converting
            if (empty($_REQUEST['ewww_force']) && !($new && $convert)) {
                if ($results_msg = ewww_image_optimizer_check_table($file, $orig_size)) {
                    return array($file, $results_msg, $converted, $original);
                }
            }
            if (ewww_image_optimizer_get_option('ewww_image_optimizer_cloud_jpg')) {
                list($file, $converted, $result, $new_size) = ewww_image_optimizer_cloud_optimizer($file, $type, $convert, $pngfile, 'image/png', $skip_lossy);
                if ($converted) {
                    $converted = $filenum;
                    ewww_image_optimizer_webp_create($file, $new_size, 'image/png', null);
                } else {
                    ewww_image_optimizer_webp_create($file, $new_size, $type, null);
                }
                break;
            }
            if ($convert) {
                $tools = ewww_image_optimizer_path_check(true, true, false, true, ewww_image_optimizer_get_option('ewww_image_optimizer_png_lossy'), ewww_image_optimizer_get_option('ewww_image_optimizer_webp'));
            } else {
                $tools = ewww_image_optimizer_path_check(true, false, false, false, false, ewww_image_optimizer_get_option('ewww_image_optimizer_webp'));
            }
            // if jpegtran optimization is disabled
            if (ewww_image_optimizer_get_option('ewww_image_optimizer_disable_jpegtran')) {
                // store an appropriate message in $result
                $result = sprintf(__('%s is disabled', EWWW_IMAGE_OPTIMIZER_DOMAIN), 'jpegtran');
                // otherwise, if we aren't skipping the utility verification and jpegtran doesn't exist
            } elseif (!$skip_jpegtran_check && !$tools['JPEGTRAN']) {
                // store an appropriate message in $result
                $result = sprintf(__('%s is missing', EWWW_IMAGE_OPTIMIZER_DOMAIN), '<em>jpegtran</em>');
                // otherwise, things should be good, so...
            } else {
                // set the optimization process to ON
                $optimize = true;
            }
            // if optimization is turned ON
            if ($optimize && !ewww_image_optimizer_get_option('ewww_image_optimizer_cloud_jpg')) {
                $ewww_debug .= "attempting to optimize JPG...<br>";
                // generate temporary file-names:
                $tempfile = $file . ".tmp";
                //non-progressive jpeg
                $progfile = $file . ".prog";
                // progressive jpeg
                // check to see if we are supposed to strip metadata (badly named)
                if (ewww_image_optimizer_get_option('ewww_image_optimizer_jpegtran_copy') && !$keep_metadata) {
                    // don't copy metadata
                    $copy_opt = 'none';
                } else {
                    // copy all the metadata
                    $copy_opt = 'all';
                }
                // run jpegtran - non-progressive
                exec("{$nice} " . $tools['JPEGTRAN'] . " -copy {$copy_opt} -optimize -outfile " . ewww_image_optimizer_escapeshellarg($tempfile) . " " . ewww_image_optimizer_escapeshellarg($file));
                // run jpegtran - progressive
                exec("{$nice} " . $tools['JPEGTRAN'] . " -copy {$copy_opt} -optimize -progressive -outfile " . ewww_image_optimizer_escapeshellarg($progfile) . " " . ewww_image_optimizer_escapeshellarg($file));
                if (is_file($tempfile)) {
                    // check the filesize of the non-progressive JPG
                    $non_size = filesize($tempfile);
                } else {
                    $non_size = 0;
                }
                if (is_file($progfile)) {
                    // check the filesize of the progressive JPG
                    $prog_size = filesize($progfile);
                } else {
                    $prog_size = 0;
                }
                $ewww_debug .= "optimized JPG (non-progresive) size: {$non_size}<br>";
                $ewww_debug .= "optimized JPG (progresive) size: {$prog_size}<br>";
                if ($non_size === false || $prog_size === false) {
                    $result = __('Unable to write file', EWWW_IMAGE_OPTIMIZER_DOMAIN);
                    $new_size = 0;
                } elseif (!$non_size || !$prog_size) {
                    $result = __('Optimization failed', EWWW_IMAGE_OPTIMIZER_DOMAIN);
                    $new_size = 0;
                } else {
                    // if the progressive file is bigger
                    if ($prog_size > $non_size) {
                        // store the size of the non-progessive JPG
                        $new_size = $non_size;
                        if (is_file($progfile)) {
                            // delete the progressive file
                            unlink($progfile);
                        }
                        // if the progressive file is smaller or the same
                    } else {
                        // store the size of the progressive JPG
                        $new_size = $prog_size;
                        // replace the non-progressive with the progressive file
                        rename($progfile, $tempfile);
                    }
                }
                $ewww_debug .= "optimized JPG size: {$new_size}<br>";
                // if the best-optimized is smaller than the original JPG, and we didn't create an empty JPG
                if ($orig_size > $new_size && $new_size != 0 && ewww_image_optimizer_mimetype($tempfile, 'i') == $type) {
                    // replace the original with the optimized file
                    rename($tempfile, $file);
                    // store the results of the optimization
                    $result = "{$orig_size} vs. {$new_size}";
                    // if the optimization didn't produce a smaller JPG
                } else {
                    if (is_file($tempfile)) {
                        // delete the optimized file
                        unlink($tempfile);
                    }
                    // store the results
                    $result = 'unchanged';
                    $new_size = $orig_size;
                }
                // if conversion and optimization are both turned OFF, finish the JPG processing
            } elseif (!$convert) {
                ewww_image_optimizer_webp_create($file, $orig_size, $type, $tools['WEBP']);
                break;
            }
            // if the conversion process is turned ON, or if this is a resize and the full-size was converted
            if ($convert && !ewww_image_optimizer_get_option('ewww_image_optimizer_cloud_jpg')) {
                $ewww_debug .= "attempting to convert JPG to PNG: {$pngfile} <br>";
                if (empty($new_size)) {
                    $new_size = $orig_size;
                }
                // retrieve version info for ImageMagick
                $convert_path = ewww_image_optimizer_find_binary('convert', 'i');
                // convert the JPG to PNG
                if (!empty($convert_path)) {
                    $ewww_debug .= "converting with ImageMagick<br>";
                    exec($convert_path . " " . ewww_image_optimizer_escapeshellarg($file) . " -strip " . ewww_image_optimizer_escapeshellarg($pngfile));
                } elseif (ewww_image_optimizer_gd_support()) {
                    $ewww_debug .= "converting with GD<br>";
                    imagepng(imagecreatefromjpeg($file), $pngfile);
                }
                // if lossy optimization is ON and full-size exclusion is not active
                if (ewww_image_optimizer_get_option('ewww_image_optimizer_png_lossy') && $tools['PNGQUANT'] && !$skip_lossy) {
                    $ewww_debug .= "attempting lossy reduction<br>";
                    exec("{$nice} " . $tools['PNGQUANT'] . " " . ewww_image_optimizer_escapeshellarg($pngfile));
                    $quantfile = preg_replace('/\\.\\w+$/', '-fs8.png', $pngfile);
                    if (file_exists($quantfile) && filesize($pngfile) > filesize($quantfile)) {
                        $ewww_debug .= "lossy reduction is better: original - " . filesize($pngfile) . " vs. lossy - " . filesize($quantfile) . "<br>";
                        rename($quantfile, $pngfile);
                    } elseif (file_exists($quantfile)) {
                        $ewww_debug .= "lossy reduction is worse: original - " . filesize($pngfile) . " vs. lossy - " . filesize($quantfile) . "<br>";
                        unlink($quantfile);
                    } else {
                        $ewww_debug .= "pngquant did not produce any output<br>";
                    }
                }
                // if optipng isn't disabled
                if (!ewww_image_optimizer_get_option('ewww_image_optimizer_disable_optipng')) {
                    // retrieve the optipng optimization level
                    $optipng_level = ewww_image_optimizer_get_option('ewww_image_optimizer_optipng_level');
                    if (ewww_image_optimizer_get_option('ewww_image_optimizer_jpegtran_copy') && preg_match('/0.7/', ewww_image_optimizer_tool_found($tools['OPTIPNG'], 'o')) && !$keep_metadata) {
                        $strip = '-strip all ';
                    } else {
                        $strip = '';
                    }
                    // if the PNG file was created
                    if (file_exists($pngfile)) {
                        $ewww_debug .= "optimizing converted PNG with optipng<br>";
                        // run optipng on the new PNG
                        exec("{$nice} " . $tools['OPTIPNG'] . " -o{$optipng_level} -quiet {$strip} " . ewww_image_optimizer_escapeshellarg($pngfile));
                    }
                }
                // if pngout isn't disabled
                if (!ewww_image_optimizer_get_option('ewww_image_optimizer_disable_pngout')) {
                    // retrieve the pngout optimization level
                    $pngout_level = ewww_image_optimizer_get_option('ewww_image_optimizer_pngout_level');
                    // if the PNG file was created
                    if (file_exists($pngfile)) {
                        $ewww_debug .= "optimizing converted PNG with pngout<br>";
                        // run pngout on the new PNG
                        exec("{$nice} " . $tools['PNGOUT'] . " -s{$pngout_level} -q " . ewww_image_optimizer_escapeshellarg($pngfile));
                    }
                }
                if (is_file($pngfile)) {
                    // find out the size of the new PNG file
                    $png_size = filesize($pngfile);
                } else {
                    $png_size = 0;
                }
                $ewww_debug .= "converted PNG size: {$png_size}<br>";
                // if the PNG is smaller than the original JPG, and we didn't end up with an empty file
                if ($new_size > $png_size && $png_size != 0 && ewww_image_optimizer_mimetype($pngfile, 'i') == 'image/png') {
                    $ewww_debug .= "converted PNG is better: {$png_size} vs. {$new_size}<br>";
                    // store the size of the converted PNG
                    $new_size = $png_size;
                    // check to see if the user wants the originals deleted
                    if (ewww_image_optimizer_get_option('ewww_image_optimizer_delete_originals') == TRUE) {
                        // delete the original JPG
                        unlink($file);
                    }
                    // store the location of the PNG file
                    $file = $pngfile;
                    // let webp know what we're dealing with now
                    $type = 'image/png';
                    // successful conversion and we store the increment
                    $converted = $filenum;
                } else {
                    $ewww_debug .= "converted PNG is no good<br>";
                    // otherwise delete the PNG
                    $converted = FALSE;
                    if (is_file($pngfile)) {
                        unlink($pngfile);
                    }
                }
            }
            ewww_image_optimizer_webp_create($file, $new_size, $type, $tools['WEBP']);
            break;
        case 'image/png':
            // png2jpg conversion is turned on, and the image is in the wordpress media library
            if ((ewww_image_optimizer_get_option('ewww_image_optimizer_png_to_jpg') || !empty($_GET['ewww_convert'])) && $gallery_type == 1 && !$skip_lossy) {
                $ewww_debug .= "PNG to JPG conversion turned on<br>";
                // if the user set a fill background for transparency
                $background = '';
                if ($background = ewww_image_optimizer_jpg_background()) {
                    // set background color for GD
                    $r = hexdec('0x' . strtoupper(substr($background, 0, 2)));
                    $g = hexdec('0x' . strtoupper(substr($background, 2, 2)));
                    $b = hexdec('0x' . strtoupper(substr($background, 4, 2)));
                    // set the background flag for 'convert'
                    $background = "-background " . '"' . "#{$background}" . '"';
                } else {
                    $r = '';
                    $g = '';
                    $b = '';
                }
                // if the user manually set the JPG quality
                if ($quality = ewww_image_optimizer_jpg_quality()) {
                    // set the quality for GD
                    $gquality = $quality;
                    // set the quality flag for 'convert'
                    $cquality = "-quality {$quality}";
                } else {
                    $cquality = '';
                    $gquality = '92';
                }
                // if this is a resize version
                if ($converted) {
                    // just replace the file extension with a .jpg
                    $jpgfile = preg_replace('/\\.\\w+$/', '.jpg', $file);
                    // if this is a full version
                } else {
                    // construct the filename for the new JPG
                    list($jpgfile, $filenum) = ewww_image_optimizer_unique_filename($file, '.jpg');
                }
            } else {
                $ewww_debug .= "PNG to JPG conversion turned off<br>";
                // turn the conversion process OFF
                $convert = false;
                $jpgfile = '';
                $r = null;
                $g = null;
                $b = null;
                $gquality = null;
            }
            // check for previous optimization, so long as the force flag is on and this isn't a new image that needs converting
            if (empty($_REQUEST['ewww_force']) && !($new && $convert)) {
                if ($results_msg = ewww_image_optimizer_check_table($file, $orig_size)) {
                    return array($file, $results_msg, $converted, $original);
                }
            }
            if (ewww_image_optimizer_get_option('ewww_image_optimizer_cloud_png')) {
                list($file, $converted, $result, $new_size) = ewww_image_optimizer_cloud_optimizer($file, $type, $convert, $jpgfile, 'image/jpeg', $skip_lossy, array('r' => $r, 'g' => $g, 'b' => $b, 'quality' => $gquality));
                if ($converted) {
                    $converted = $filenum;
                    ewww_image_optimizer_webp_create($file, $new_size, 'image/jpeg', null);
                } else {
                    ewww_image_optimizer_webp_create($file, $new_size, $type, null);
                }
                break;
            }
            if ($convert) {
                $tools = ewww_image_optimizer_path_check(true, true, false, true, ewww_image_optimizer_get_option('ewww_image_optimizer_png_lossy'), ewww_image_optimizer_get_option('ewww_image_optimizer_webp'));
            } else {
                $tools = ewww_image_optimizer_path_check(false, true, false, true, ewww_image_optimizer_get_option('ewww_image_optimizer_png_lossy'), ewww_image_optimizer_get_option('ewww_image_optimizer_webp'));
            }
            // if pngout and optipng are disabled
            if (ewww_image_optimizer_get_option('ewww_image_optimizer_disable_optipng') && ewww_image_optimizer_get_option('ewww_image_optimizer_disable_pngout')) {
                // tell the user all PNG tools are disabled
                $result = __('png tools are disabled', EWWW_IMAGE_OPTIMIZER_DOMAIN);
                // if the utility checking is on, optipng is enabled, but optipng cannot be found
            } elseif (!$skip_optipng_check && !$tools['OPTIPNG'] && !ewww_image_optimizer_get_option('ewww_image_optimizer_disable_optipng')) {
                // tell the user optipng is missing
                $result = sprintf(__('%s is missing', EWWW_IMAGE_OPTIMIZER_DOMAIN), '<em>optipng</em>');
                // if the utility checking is on, pngout is enabled, but pngout cannot be found
            } elseif (!$skip_pngout_check && !$tools['PNGOUT'] && !ewww_image_optimizer_get_option('ewww_image_optimizer_disable_pngout')) {
                // tell the user pngout is missing
                $result = sprintf(__('%s is missing', EWWW_IMAGE_OPTIMIZER_DOMAIN), '<em>pngout</em>');
            } else {
                // turn optimization on if we made it through all the checks
                $optimize = true;
            }
            // if optimization is turned on
            if ($optimize) {
                // if lossy optimization is ON and full-size exclusion is not active
                if (ewww_image_optimizer_get_option('ewww_image_optimizer_png_lossy') && $tools['PNGQUANT'] && !$skip_lossy) {
                    $ewww_debug .= "attempting lossy reduction<br>";
                    exec("{$nice} " . $tools['PNGQUANT'] . " " . ewww_image_optimizer_escapeshellarg($file));
                    $quantfile = preg_replace('/\\.\\w+$/', '-fs8.png', $file);
                    if (file_exists($quantfile) && filesize($file) > filesize($quantfile) && ewww_image_optimizer_mimetype($quantfile, 'i') == $type) {
                        $ewww_debug .= "lossy reduction is better: original - " . filesize($file) . " vs. lossy - " . filesize($quantfile) . "<br>";
                        rename($quantfile, $file);
                    } elseif (file_exists($quantfile)) {
                        $ewww_debug .= "lossy reduction is worse: original - " . filesize($file) . " vs. lossy - " . filesize($quantfile) . "<br>";
                        unlink($quantfile);
                    } else {
                        $ewww_debug .= "pngquant did not produce any output<br>";
                    }
                }
                $tempfile = $file . '.tmp.png';
                copy($file, $tempfile);
                // if optipng is enabled
                if (!ewww_image_optimizer_get_option('ewww_image_optimizer_disable_optipng')) {
                    // retrieve the optimization level for optipng
                    $optipng_level = ewww_image_optimizer_get_option('ewww_image_optimizer_optipng_level');
                    if (ewww_image_optimizer_get_option('ewww_image_optimizer_jpegtran_copy') && preg_match('/0.7/', ewww_image_optimizer_tool_found($tools['OPTIPNG'], 'o')) && !$keep_metadata) {
                        $strip = '-strip all ';
                    } else {
                        $strip = '';
                    }
                    // run optipng on the PNG file
                    exec("{$nice} " . $tools['OPTIPNG'] . " -o{$optipng_level} -quiet {$strip} " . ewww_image_optimizer_escapeshellarg($tempfile));
                }
                // if pngout is enabled
                if (!ewww_image_optimizer_get_option('ewww_image_optimizer_disable_pngout')) {
                    // retrieve the optimization level for pngout
                    $pngout_level = ewww_image_optimizer_get_option('ewww_image_optimizer_pngout_level');
                    // run pngout on the PNG file
                    exec("{$nice} " . $tools['PNGOUT'] . " -s{$pngout_level} -q " . ewww_image_optimizer_escapeshellarg($tempfile));
                }
                // retrieve the filesize of the temporary PNG
                $new_size = filesize($tempfile);
                // if the new PNG is smaller
                if ($orig_size > $new_size && $new_size != 0 && ewww_image_optimizer_mimetype($tempfile, 'i') == $type) {
                    // replace the original with the optimized file
                    rename($tempfile, $file);
                    // store the results of the optimization
                    $result = "{$orig_size} vs. {$new_size}";
                    // if the optimization didn't produce a smaller PNG
                } else {
                    if (is_file($tempfile)) {
                        // delete the optimized file
                        unlink($tempfile);
                    }
                    // store the results
                    $result = 'unchanged';
                    $new_size = $orig_size;
                }
                // if conversion and optimization are both disabled we are done here
            } elseif (!$convert) {
                $ewww_debug .= "calling webp, but neither convert or optimize<br>";
                ewww_image_optimizer_webp_create($file, $orig_size, $type, $tools['WEBP']);
                break;
            }
            // flush the cache for filesize
            clearstatcache();
            // retrieve the new filesize of the PNG
            $new_size = filesize($file);
            // if conversion is on and the PNG doesn't have transparency or the user set a background color to replace transparency
            if ($convert && (!ewww_image_optimizer_png_alpha($file) || ewww_image_optimizer_jpg_background())) {
                $ewww_debug .= "attempting to convert PNG to JPG: {$jpgfile} <br>";
                if (empty($new_size)) {
                    $new_size = $orig_size;
                }
                // retrieve version info for ImageMagick
                $convert_path = ewww_image_optimizer_find_binary('convert', 'i');
                // convert the PNG to a JPG with all the proper options
                if (!empty($convert_path)) {
                    $ewww_debug .= "converting with ImageMagick<br>";
                    $ewww_debug .= "using command: {$convert_path} {$background} -flatten {$cquality} {$file} {$jpgfile}";
                    exec("{$convert_path} {$background} -flatten {$cquality} " . ewww_image_optimizer_escapeshellarg($file) . " " . ewww_image_optimizer_escapeshellarg($jpgfile));
                } elseif (ewww_image_optimizer_gd_support()) {
                    $ewww_debug .= "converting with GD<br>";
                    // retrieve the data from the PNG
                    $input = imagecreatefrompng($file);
                    // retrieve the dimensions of the PNG
                    list($width, $height) = getimagesize($file);
                    // create a new image with those dimensions
                    $output = imagecreatetruecolor($width, $height);
                    if ($r === '') {
                        $r = 255;
                        $g = 255;
                        $b = 255;
                    }
                    // allocate the background color
                    $rgb = imagecolorallocate($output, $r, $g, $b);
                    // fill the new image with the background color
                    imagefilledrectangle($output, 0, 0, $width, $height, $rgb);
                    // copy the original image to the new image
                    imagecopy($output, $input, 0, 0, 0, 0, $width, $height);
                    // output the JPG with the quality setting
                    imagejpeg($output, $jpgfile, $gquality);
                }
                if (is_file($jpgfile)) {
                    // retrieve the filesize of the new JPG
                    $jpg_size = filesize($jpgfile);
                    $ewww_debug .= "converted JPG filesize: {$jpg_size}<br>";
                } else {
                    $jpg_size = 0;
                    $ewww_debug .= "unable to convert to JPG<br>";
                }
                // next we need to optimize that JPG if jpegtran is enabled
                if (!ewww_image_optimizer_get_option('ewww_image_optimizer_disable_jpegtran') && file_exists($jpgfile)) {
                    // generate temporary file-names:
                    $tempfile = $jpgfile . ".tmp";
                    //non-progressive jpeg
                    $progfile = $jpgfile . ".prog";
                    // progressive jpeg
                    // check to see if we are supposed to strip metadata (badly named)
                    if (ewww_image_optimizer_get_option('ewww_image_optimizer_jpegtran_copy') && !$keep_metadata) {
                        // don't copy metadata
                        $copy_opt = 'none';
                    } else {
                        // copy all the metadata
                        $copy_opt = 'all';
                    }
                    // run jpegtran - non-progressive
                    exec("{$nice} " . $tools['JPEGTRAN'] . " -copy {$copy_opt} -optimize -outfile " . ewww_image_optimizer_escapeshellarg($tempfile) . " " . ewww_image_optimizer_escapeshellarg($jpgfile));
                    // run jpegtran - progressive
                    exec("{$nice} " . $tools['JPEGTRAN'] . " -copy {$copy_opt} -optimize -progressive -outfile " . ewww_image_optimizer_escapeshellarg($progfile) . " " . ewww_image_optimizer_escapeshellarg($jpgfile));
                    if (is_file($tempfile)) {
                        // check the filesize of the non-progressive JPG
                        $non_size = filesize($tempfile);
                        $ewww_debug .= "non-progressive JPG filesize: {$non_size}<br>";
                    } else {
                        $non_size = 0;
                    }
                    if (is_file($progfile)) {
                        // check the filesize of the progressive JPG
                        $prog_size = filesize($progfile);
                        $ewww_debug .= "progressive JPG filesize: {$prog_size}<br>";
                    } else {
                        $prog_size = 0;
                    }
                    // if the progressive file is bigger
                    if ($prog_size > $non_size) {
                        // store the size of the non-progessive JPG
                        $opt_jpg_size = $non_size;
                        if (is_file($progfile)) {
                            // delete the progressive file
                            unlink($progfile);
                        }
                        $ewww_debug .= "keeping non-progressive JPG<br>";
                        // if the progressive file is smaller or the same
                    } else {
                        // store the size of the progressive JPG
                        $opt_jpg_size = $prog_size;
                        // replace the non-progressive with the progressive file
                        rename($progfile, $tempfile);
                        $ewww_debug .= "keeping progressive JPG<br>";
                    }
                    // if the best-optimized is smaller than the original JPG, and we didn't create an empty JPG
                    if ($jpg_size > $opt_jpg_size && $opt_jpg_size != 0) {
                        // replace the original with the optimized file
                        rename($tempfile, $jpgfile);
                        // store the size of the optimized JPG
                        $jpg_size = $opt_jpg_size;
                        $ewww_debug .= "optimized JPG was smaller than un-optimized version<br>";
                        // if the optimization didn't produce a smaller JPG
                    } elseif (is_file($tempfile)) {
                        // delete the optimized file
                        unlink($tempfile);
                    }
                }
                $ewww_debug .= "converted JPG size: {$jpg_size}<br>";
                // if the new JPG is smaller than the original PNG
                if ($new_size > $jpg_size && $jpg_size != 0 && ewww_image_optimizer_mimetype($jpgfile, 'i') == 'image/jpeg') {
                    // store the size of the JPG as the new filesize
                    $new_size = $jpg_size;
                    // if the user wants originals delted after a conversion
                    if (ewww_image_optimizer_get_option('ewww_image_optimizer_delete_originals') == TRUE) {
                        // delete the original PNG
                        unlink($file);
                    }
                    // update the $file location to the new JPG
                    $file = $jpgfile;
                    // let webp know what we're dealing with now
                    $type = 'image/jpeg';
                    // successful conversion, so we store the increment
                    $converted = $filenum;
                } else {
                    $converted = FALSE;
                    if (is_file($jpgfile)) {
                        // otherwise delete the new JPG
                        unlink($jpgfile);
                    }
                }
            }
            ewww_image_optimizer_webp_create($file, $new_size, $type, $tools['WEBP']);
            break;
        case 'image/gif':
            // if gif2png is turned on, and the image is in the wordpress media library
            if (ewww_image_optimizer_get_option('ewww_image_optimizer_gif_to_png') && $gallery_type == 1 || !empty($_GET['ewww_convert'])) {
                // generate the filename for a PNG
                // if this is a resize version
                if ($converted) {
                    // just change the file extension
                    $pngfile = preg_replace('/\\.\\w+$/', '.png', $file);
                    // if this is the full version
                } else {
                    // construct the filename for the new PNG
                    list($pngfile, $filenum) = ewww_image_optimizer_unique_filename($file, '.png');
                }
            } else {
                // turn conversion OFF
                $convert = false;
                $pngfile = '';
            }
            // check for previous optimization, so long as the force flag is on and this isn't a new image that needs converting
            if (empty($_REQUEST['ewww_force']) && !($new && $convert)) {
                if ($results_msg = ewww_image_optimizer_check_table($file, $orig_size)) {
                    return array($file, $results_msg, $converted, $original);
                }
            }
            if (ewww_image_optimizer_get_option('ewww_image_optimizer_cloud_gif')) {
                list($file, $converted, $result, $new_size) = ewww_image_optimizer_cloud_optimizer($file, $type, $convert, $pngfile, 'image/png', $skip_lossy);
                if ($converted) {
                    $converted = $filenum;
                    ewww_image_optimizer_webp_create($file, $new_size, 'image/png', null);
                }
                break;
            }
            if ($convert) {
                $tools = ewww_image_optimizer_path_check(false, true, true, true, ewww_image_optimizer_get_option('ewww_image_optimizer_png_lossy'), ewww_image_optimizer_get_option('ewww_image_optimizer_webp'));
            } else {
                $tools = ewww_image_optimizer_path_check(false, false, true, false, false, false);
            }
            // if gifsicle is disabled
            if (ewww_image_optimizer_get_option('ewww_image_optimizer_disable_gifsicle')) {
                // return an appropriate message
                $result = sprintf(__('%s is disabled', EWWW_IMAGE_OPTIMIZER_DOMAIN), 'gifsicle');
                // if utility checking is on, and gifsicle is not installed
            } elseif (!$skip_gifsicle_check && !$tools['GIFSICLE']) {
                // return an appropriate message
                $result = sprintf(__('%s is missing', EWWW_IMAGE_OPTIMIZER_DOMAIN), '<em>gifsicle</em>');
            } else {
                // otherwise, turn optimization ON
                $optimize = true;
            }
            // if optimization is turned ON
            if ($optimize) {
                $tempfile = $file . '.tmp';
                //temporary GIF output
                // run gifsicle on the GIF
                exec("{$nice} " . $tools['GIFSICLE'] . " -b -O3 --careful -o {$tempfile} " . ewww_image_optimizer_escapeshellarg($file));
                if (file_exists($tempfile)) {
                    // retrieve the filesize of the temporary GIF
                    $new_size = filesize($tempfile);
                    // if the new GIF is smaller
                    if ($orig_size > $new_size && $new_size != 0 && ewww_image_optimizer_mimetype($tempfile, 'i') == $type) {
                        // replace the original with the optimized file
                        rename($tempfile, $file);
                        // store the results of the optimization
                        $result = "{$orig_size} vs. {$new_size}";
                        // if the optimization didn't produce a smaller GIF
                    } else {
                        if (is_file($tempfile)) {
                            // delete the optimized file
                            unlink($tempfile);
                        }
                        // store the results
                        $result = 'unchanged';
                        $new_size = $orig_size;
                    }
                }
                // if conversion and optimization are both turned OFF, we are done here
            } elseif (!$convert) {
                break;
            }
            // flush the cache for filesize
            clearstatcache();
            // get the new filesize for the GIF
            $new_size = filesize($file);
            // if conversion is ON and the GIF isn't animated
            if ($convert && !ewww_image_optimizer_is_animated($file)) {
                if (empty($new_size)) {
                    $new_size = $orig_size;
                }
                // if optipng is enabled
                if (!ewww_image_optimizer_get_option('ewww_image_optimizer_disable_optipng') && $tools['OPTIPNG']) {
                    // retrieve the optipng optimization level
                    $optipng_level = ewww_image_optimizer_get_option('ewww_image_optimizer_optipng_level');
                    if (ewww_image_optimizer_get_option('ewww_image_optimizer_jpegtran_copy') && preg_match('/0.7/', ewww_image_optimizer_tool_found($tools['OPTIPNG'], 'o')) && !$keep_metadata) {
                        $strip = '-strip all ';
                    } else {
                        $strip = '';
                    }
                    // run optipng on the GIF file
                    exec("{$nice} " . $tools['OPTIPNG'] . " -out " . ewww_image_optimizer_escapeshellarg($pngfile) . " -o{$optipng_level} -quiet {$strip} " . ewww_image_optimizer_escapeshellarg($file));
                }
                // if pngout is enabled
                if (!ewww_image_optimizer_get_option('ewww_image_optimizer_disable_pngout') && $tools['PNGOUT']) {
                    // retrieve the pngout optimization level
                    $pngout_level = ewww_image_optimizer_get_option('ewww_image_optimizer_pngout_level');
                    // if $pngfile exists (which means optipng was run already)
                    if (file_exists($pngfile)) {
                        // run pngout on the PNG file
                        exec("{$nice} " . $tools['PNGOUT'] . " -s{$pngout_level} -q " . ewww_image_optimizer_escapeshellarg($pngfile));
                    } else {
                        // run pngout on the GIF file
                        exec("{$nice} " . $tools['PNGOUT'] . " -s{$pngout_level} -q " . ewww_image_optimizer_escapeshellarg($file) . " " . ewww_image_optimizer_escapeshellarg($pngfile));
                    }
                }
                // if a PNG file was created
                if (file_exists($pngfile)) {
                    // retrieve the filesize of the PNG
                    $png_size = filesize($pngfile);
                    // if the new PNG is smaller than the original GIF
                    if ($new_size > $png_size && $png_size != 0 && ewww_image_optimizer_mimetype($pngfile, 'i') == 'image/png') {
                        // store the PNG size as the new filesize
                        $new_size = $png_size;
                        // if the user wants original GIFs deleted after successful conversion
                        if (ewww_image_optimizer_get_option('ewww_image_optimizer_delete_originals') == TRUE) {
                            // delete the original GIF
                            unlink($file);
                        }
                        // update the $file location with the new PNG
                        $file = $pngfile;
                        // let webp know what we're dealing with now
                        $type = 'image/png';
                        // normally this would be at the end of the section, but we only want to do webp if the image was successfully converted to a png
                        ewww_image_optimizer_webp_create($file, $new_size, $type, $tools['WEBP']);
                        // successful conversion (for now), so we store the increment
                        $converted = $filenum;
                    } else {
                        $converted = FALSE;
                        if (is_file($pngfile)) {
                            unlink($pngfile);
                        }
                    }
                }
            }
            break;
        default:
            // if not a JPG, PNG, or GIF, tell the user we don't work with strangers
            return array($file, __('Unknown type: ' . $type, EWWW_IMAGE_OPTIMIZER_DOMAIN), $converted, $original);
    }
    // if their cloud api license limit has been exceeded
    if ($result == 'exceeded') {
        return array($file, __('License exceeded', EWWW_IMAGE_OPTIMIZER_DOMAIN), $converted, $original);
    }
    if (!empty($new_size)) {
        $results_msg = ewww_image_optimizer_update_table($file, $new_size, $orig_size, $new);
        ewwwio_memory(__FUNCTION__);
        return array($file, $results_msg, $converted, $original);
    }
    ewwwio_memory(__FUNCTION__);
    // otherwise, send back the filename, the results (some sort of error message), the $converted flag, and the name of the original image
    return array($file, $result, $converted, $original);
}
Пример #5
0
function ewww_image_optimizer_options()
{
    ewwwio_debug_message('<b>' . __FUNCTION__ . '()</b>');
    ewwwio_debug_message('ABSPATH: ' . ABSPATH);
    ewwwio_debug_message('WP_CONTENT_DIR: ' . WP_CONTENT_DIR);
    ewwwio_debug_message('home url: ' . get_home_url());
    ewwwio_debug_message('site url: ' . get_site_url());
    if (!function_exists('is_plugin_active_for_network') && is_multisite()) {
        // need to include the plugin library for the is_plugin_active function
        require_once ABSPATH . 'wp-admin/includes/plugin.php';
    }
    $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>' . esc_html__('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(esc_html__('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[] = "<h1>EWWW Image Optimizer</h1>\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/'>" . esc_html__('Plugin Home Page', EWWW_IMAGE_OPTIMIZER_DOMAIN) . "</a> | " . "<a href='https://wordpress.org/extend/plugins/ewww-image-optimizer/installation/'>" . esc_html__('Installation Instructions', EWWW_IMAGE_OPTIMIZER_DOMAIN) . "</a> | " . "<a href='https://wordpress.org/support/plugin/ewww-image-optimizer'>" . esc_html__('Plugin Support', EWWW_IMAGE_OPTIMIZER_DOMAIN) . "</a> | " . "<a href='https://ewww.io/status/'>" . esc_html__('Cloud Status', EWWW_IMAGE_OPTIMIZER_DOMAIN) . "</a> | " . "<a href='https://ewww.io/downloads/s3-image-optimizer/'>" . esc_html__('S3 Image Optimizer', EWWW_IMAGE_OPTIMIZER_DOMAIN) . "</a></p>\n";
    if (is_multisite() && is_plugin_active_for_network(EWWW_IMAGE_OPTIMIZER_PLUGIN_FILE_REL)) {
        $bulk_link = esc_html__('Media Library', EWWW_IMAGE_OPTIMIZER_DOMAIN) . ' -> ' . esc_html__('Bulk Optimize', EWWW_IMAGE_OPTIMIZER_DOMAIN);
    } else {
        $bulk_link = '<a href="upload.php?page=ewww-image-optimizer-bulk">' . esc_html__('Bulk Optimize', EWWW_IMAGE_OPTIMIZER_DOMAIN) . '</a>';
    }
    $output[] = "<p>" . wp_kses(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), array('a' => array('href' => array()))) . " " . wp_kses(__('Images stored in an Amazon S3 bucket can be optimized using our <a href="https://ewww.io/downloads/s3-image-optimizer/">S3 Image Optimizer</a>.'), array('a' => array('href' => array()))) . "</p>\n";
    //if ( EWWW_IMAGE_OPTIMIZER_CLOUD ) {
    if (ewww_image_optimizer_full_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" . "<button type='button' class='handlediv button-link' aria-expanded='true'>" . "<span class='screen-reader-text'>" . esc_html__('Click to toggle', EWWW_IMAGE_OPTIMIZER_DOMAIN) . "</span>" . "<span class='toggle-indicator' aria-hidden='true'></span>" . "</button>" . "<h2 class='hndle'>" . esc_html__('Plugin Status', EWWW_IMAGE_OPTIMIZER_DOMAIN) . "&emsp;" . "<span id='ewww-status-ok' style='display: none; color: green;'>" . esc_html__('All Clear', EWWW_IMAGE_OPTIMIZER_DOMAIN) . "</span>" . "<span id='ewww-status-attention' style='color: red;'>" . esc_html__('Requires Attention', EWWW_IMAGE_OPTIMIZER_DOMAIN) . "</span>" . "</h2>\n" . "<div class='inside'>" . "<b>" . esc_html__('Total Savings:', EWWW_IMAGE_OPTIMIZER_DOMAIN) . "</b> <span id='ewww-total-savings'>" . size_format(ewww_image_optimizer_savings(), 2) . "</span><br>";
    $collapsible = true;
    if (ewww_image_optimizer_get_option('ewww_image_optimizer_cloud_key')) {
        $output[] = '<p><b>' . esc_html__('Cloud optimization API Key', EWWW_IMAGE_OPTIMIZER_DOMAIN) . ":</b> ";
        $verify_cloud = ewww_image_optimizer_cloud_verify();
        if (preg_match('/great/', $verify_cloud)) {
            $output[] = '<span style="color: green">' . esc_html__('Verified,', EWWW_IMAGE_OPTIMIZER_DOMAIN) . ' </span>' . ewww_image_optimizer_cloud_quota();
        } elseif (preg_match('/exceeded/', $verify_cloud)) {
            $output[] = '<span style="color: orange">' . esc_html__('Verified,', EWWW_IMAGE_OPTIMIZER_DOMAIN) . ' </span>' . ewww_image_optimizer_cloud_quota();
            $collapsible = false;
        } else {
            $output[] = '<span style="color: red">' . esc_html__('Not Verified', EWWW_IMAGE_OPTIMIZER_DOMAIN) . '</span>';
            $collapsible = false;
        }
        $output[] = "</p>\n";
        $disable_level = '';
    } else {
        if (EWWW_IMAGE_OPTIMIZER_DOMAIN == 'ewww-image-optimizer-cloud') {
            $collapsible = false;
        }
        $disable_level = "disabled='disabled'";
    }
    if (ewww_image_optimizer_detect_wpsf_location_lock()) {
        $output = '<p><span style="color: orange">' . esc_html__('WARNING:', EWWW_IMAGE_OPTIMIZER_DOMAIN) . '</span> ' . esc_html__("You are using Shield's Lock to Location feature, which prevents the use of Background & Parallel Optimization for faster processing time.", EWWW_IMAGE_OPTIMIZER_DOMAIN) . '</p>';
        // this one inactive
        $output2[] = '<p><span style="color: orange">' . esc_html__('NOTICE:', EWWW_IMAGE_OPTIMIZER_DOMAIN) . '</span> ' . esc_html__("You are using Shield's User Management feature, which prevents the use of Background & Parallel Optimization for faster processing time.", EWWW_IMAGE_OPTIMIZER_DOMAIN) . '</p>';
        $collapsible = false;
    }
    if (ewww_image_optimizer_get_option('ewww_image_optimizer_skip_bundle') && !ewww_image_optimizer_full_cloud() && !EWWW_IMAGE_OPTIMIZER_NOEXEC) {
        $output[] = "<p>" . esc_html__('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>*" . esc_html__('Updates are optional, but may contain increased optimization or security patches', EWWW_IMAGE_OPTIMIZER_DOMAIN) . "</i></p>\n";
    } elseif (!ewww_image_optimizer_full_cloud() && !EWWW_IMAGE_OPTIMIZER_NOEXEC) {
        $output[] = "<p>" . sprintf(esc_html__('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>*" . esc_html__('Updates are optional, but may contain increased optimization or security patches', EWWW_IMAGE_OPTIMIZER_DOMAIN) . "</i></p>\n";
    }
    if (!ewww_image_optimizer_full_cloud() && !EWWW_IMAGE_OPTIMIZER_NOEXEC) {
        list($jpegtran_src, $optipng_src, $gifsicle_src, $jpegtran_dst, $optipng_dst, $gifsicle_dst) = ewww_image_optimizer_install_paths();
    }
    $skip = ewww_image_optimizer_skip_tools();
    $output[] = "<p>\n";
    if (!$skip['jpegtran'] && !EWWW_IMAGE_OPTIMIZER_NOEXEC) {
        $output[] = "<b>jpegtran:</b> ";
        if (EWWW_IMAGE_OPTIMIZER_JPEGTRAN) {
            $jpegtran_installed = ewww_image_optimizer_tool_found(EWWW_IMAGE_OPTIMIZER_JPEGTRAN, 'j');
            if (!$jpegtran_installed) {
                $jpegtran_installed = ewww_image_optimizer_tool_found(EWWW_IMAGE_OPTIMIZER_JPEGTRAN, 'jb');
            }
        }
        if (!empty($jpegtran_installed)) {
            $output[] = '<span style="color: green; font-weight: bolder">' . esc_html__('Installed', EWWW_IMAGE_OPTIMIZER_DOMAIN) . '</span>&emsp;' . esc_html__('version', EWWW_IMAGE_OPTIMIZER_DOMAIN) . ': ' . $jpegtran_installed . "<br />\n";
        } else {
            $output[] = '<span style="color: red; font-weight: bolder">' . esc_html__('Missing', EWWW_IMAGE_OPTIMIZER_DOMAIN) . '</span><br />' . "\n";
            $collapsible = false;
        }
    }
    if (!$skip['optipng'] && !EWWW_IMAGE_OPTIMIZER_NOEXEC) {
        $output[] = "<b>optipng:</b> ";
        if (EWWW_IMAGE_OPTIMIZER_OPTIPNG) {
            $optipng_version = ewww_image_optimizer_tool_found(EWWW_IMAGE_OPTIMIZER_OPTIPNG, 'o');
            if (!$optipng_version) {
                $optipng_version = ewww_image_optimizer_tool_found(EWWW_IMAGE_OPTIMIZER_OPTIPNG, 'ob');
            }
        }
        if (!empty($optipng_version)) {
            $output[] = '<span style="color: green; font-weight: bolder">' . esc_html__('Installed', EWWW_IMAGE_OPTIMIZER_DOMAIN) . '</span>&emsp;' . esc_html__('version', EWWW_IMAGE_OPTIMIZER_DOMAIN) . ': ' . $optipng_version . "<br />\n";
        } else {
            $output[] = '<span style="color: red; font-weight: bolder">' . esc_html__('Missing', EWWW_IMAGE_OPTIMIZER_DOMAIN) . '</span><br />' . "\n";
            $collapsible = false;
        }
    }
    if (!$skip['pngout'] && !EWWW_IMAGE_OPTIMIZER_NOEXEC) {
        $output[] = "<b>pngout:</b> ";
        if (EWWW_IMAGE_OPTIMIZER_PNGOUT) {
            $pngout_version = ewww_image_optimizer_tool_found(EWWW_IMAGE_OPTIMIZER_PNGOUT, 'p');
            if (!$pngout_version) {
                $pngout_version = ewww_image_optimizer_tool_found(EWWW_IMAGE_OPTIMIZER_PNGOUT, 'pb');
            }
        }
        if (!empty($pngout_version)) {
            $output[] = '<span style="color: green; font-weight: bolder">' . esc_html__('Installed', EWWW_IMAGE_OPTIMIZER_DOMAIN) . '</span>&emsp;' . esc_html__('version', EWWW_IMAGE_OPTIMIZER_DOMAIN) . ': ' . preg_replace('/PNGOUT \\[.*\\)\\s*?/', '', $pngout_version) . "<br />\n";
        } else {
            $output[] = '<span style="color: red; font-weight: bolder">' . esc_html__('Missing', EWWW_IMAGE_OPTIMIZER_DOMAIN) . '</span>&emsp;<b>' . esc_html__('Install', EWWW_IMAGE_OPTIMIZER_DOMAIN) . ' <a href="admin.php?action=ewww_image_optimizer_install_pngout">' . esc_html__('automatically', EWWW_IMAGE_OPTIMIZER_DOMAIN) . '</a> | <a href="http://advsys.net/ken/utils.htm">' . esc_html__('manually', EWWW_IMAGE_OPTIMIZER_DOMAIN) . '</a></b> - ' . esc_html__('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 ($skip['pngout'] && ewww_image_optimizer_get_option('ewww_image_optimizer_png_level') == 10) {
        $output[] = '<b>pngout:</b> ' . esc_html__('Not installed, enable in Advanced Settings', EWWW_IMAGE_OPTIMIZER_DOMAIN) . "<br />\n";
    }
    if (!$skip['gifsicle'] && !EWWW_IMAGE_OPTIMIZER_NOEXEC) {
        $output[] = "<b>gifsicle:</b> ";
        if (EWWW_IMAGE_OPTIMIZER_GIFSICLE) {
            $gifsicle_version = ewww_image_optimizer_tool_found(EWWW_IMAGE_OPTIMIZER_GIFSICLE, 'g');
            if (!$gifsicle_version) {
                $gifsicle_version = ewww_image_optimizer_tool_found(EWWW_IMAGE_OPTIMIZER_GIFSICLE, 'gb');
            }
        }
        if (!empty($gifsicle_version)) {
            $output[] = '<span style="color: green; font-weight: bolder">' . esc_html__('Installed', EWWW_IMAGE_OPTIMIZER_DOMAIN) . '</span>&emsp;' . esc_html__('version', EWWW_IMAGE_OPTIMIZER_DOMAIN) . ': ' . $gifsicle_version . "<br />\n";
        } else {
            $output[] = '<span style="color: red; font-weight: bolder">' . esc_html__('Missing', EWWW_IMAGE_OPTIMIZER_DOMAIN) . '</span><br />' . "\n";
            $collapsible = false;
        }
    }
    if (!$skip['pngquant'] && !EWWW_IMAGE_OPTIMIZER_NOEXEC) {
        $output[] = "<b>pngquant:</b> ";
        if (EWWW_IMAGE_OPTIMIZER_PNGQUANT) {
            $pngquant_version = ewww_image_optimizer_tool_found(EWWW_IMAGE_OPTIMIZER_PNGQUANT, 'q');
            if (!$pngquant_version) {
                $pngquant_version = ewww_image_optimizer_tool_found(EWWW_IMAGE_OPTIMIZER_PNGQUANT, 'qb');
            }
        }
        if (!empty($pngquant_version)) {
            $output[] = '<span style="color: green; font-weight: bolder">' . esc_html__('Installed', EWWW_IMAGE_OPTIMIZER_DOMAIN) . '</span>&emsp;' . esc_html__('version', EWWW_IMAGE_OPTIMIZER_DOMAIN) . ': ' . $pngquant_version . "<br />\n";
        } else {
            $output[] = '<span style="color: red; font-weight: bolder">' . esc_html__('Missing', EWWW_IMAGE_OPTIMIZER_DOMAIN) . '</span><br />' . "\n";
            $collapsible = false;
        }
    }
    if (EWWW_IMAGE_OPTIMIZER_WEBP && !$skip['webp'] && !EWWW_IMAGE_OPTIMIZER_NOEXEC) {
        $output[] = "<b>webp:</b> ";
        if (EWWW_IMAGE_OPTIMIZER_WEBP) {
            $webp_version = ewww_image_optimizer_tool_found(EWWW_IMAGE_OPTIMIZER_WEBP, 'w');
            if (!$webp_version) {
                $webp_version = ewww_image_optimizer_tool_found(EWWW_IMAGE_OPTIMIZER_WEBP, 'wb');
            }
        }
        if (!empty($webp_version)) {
            $output[] = '<span style="color: green; font-weight: bolder">' . esc_html__('Installed', EWWW_IMAGE_OPTIMIZER_DOMAIN) . '</span>&emsp;' . esc_html__('version', EWWW_IMAGE_OPTIMIZER_DOMAIN) . ': ' . $webp_version . "<br />\n";
        } else {
            $output[] = '<span style="color: red; font-weight: bolder">' . esc_html__('Missing', EWWW_IMAGE_OPTIMIZER_DOMAIN) . '</span><br />' . "\n";
            $collapsible = false;
        }
    }
    if (!ewww_image_optimizer_full_cloud() && !EWWW_IMAGE_OPTIMIZER_NOEXEC) {
        if (ewww_image_optimizer_safemode_check()) {
            $output[] = 'safe mode: <span style="color: red; font-weight: bolder">' . esc_html__('On', EWWW_IMAGE_OPTIMIZER_DOMAIN) . '</span>&emsp;&emsp;';
            $collapsible = false;
        } else {
            $output[] = 'safe mode: <span style="color: green; font-weight: bolder">' . esc_html__('Off', EWWW_IMAGE_OPTIMIZER_DOMAIN) . '</span>&emsp;&emsp;';
        }
        if (ewww_image_optimizer_exec_check()) {
            $output[] = 'exec(): <span style="color: red; font-weight: bolder">' . esc_html__('Disabled', EWWW_IMAGE_OPTIMIZER_DOMAIN) . '</span>&emsp;&emsp;';
            $collapsible = false;
        } else {
            $output[] = 'exec(): <span style="color: green; font-weight: bolder">' . esc_html__('Enabled', EWWW_IMAGE_OPTIMIZER_DOMAIN) . '</span>&emsp;&emsp;';
        }
        $output[] = "<br />\n";
        $output[] = wp_kses(sprintf(__("%s only need one, used for conversion, not optimization", EWWW_IMAGE_OPTIMIZER_DOMAIN), '<b>' . __('Graphics libraries', EWWW_IMAGE_OPTIMIZER_DOMAIN) . '</b> - '), array('b' => array()));
        $output[] = '<br>';
        $toolkit_found = false;
        if (ewww_image_optimizer_gd_support()) {
            $output[] = 'GD: <span style="color: green; font-weight: bolder">' . esc_html__('Installed', EWWW_IMAGE_OPTIMIZER_DOMAIN);
            $toolkit_found = true;
        } else {
            $output[] = 'GD: <span style="color: red; font-weight: bolder">' . esc_html__('Missing', EWWW_IMAGE_OPTIMIZER_DOMAIN);
        }
        $output[] = '</span>&emsp;&emsp;' . "Gmagick: ";
        if (ewww_image_optimizer_gmagick_support()) {
            $output[] = '<span style="color: green; font-weight: bolder">' . esc_html__('Installed', EWWW_IMAGE_OPTIMIZER_DOMAIN);
            $toolkit_found = true;
        } else {
            $output[] = '<span style="color: red; font-weight: bolder">' . esc_html__('Missing', EWWW_IMAGE_OPTIMIZER_DOMAIN);
        }
        $output[] = '</span>&emsp;&emsp;' . "Imagick: ";
        if (ewww_image_optimizer_imagick_support()) {
            $output[] = '<span style="color: green; font-weight: bolder">' . esc_html__('Installed', EWWW_IMAGE_OPTIMIZER_DOMAIN);
            $toolkit_found = true;
        } else {
            $output[] = '<span style="color: red; font-weight: bolder">' . esc_html__('Missing', EWWW_IMAGE_OPTIMIZER_DOMAIN);
        }
        $output[] = "</span>&emsp;&emsp;Imagemagick 'convert': ";
        if ('WINNT' == PHP_OS && ewww_image_optimizer_find_win_binary('convert', 'i')) {
            $output[] = '<span style="color: green; font-weight: bolder">' . esc_html__('Installed', EWWW_IMAGE_OPTIMIZER_DOMAIN) . '</span>';
            $toolkit_found = true;
        } elseif ('WINNT' != PHP_OS && ewww_image_optimizer_find_nix_binary('convert', 'i')) {
            $output[] = '<span style="color: green; font-weight: bolder">' . esc_html__('Installed', EWWW_IMAGE_OPTIMIZER_DOMAIN) . '</span>';
            $toolkit_found = true;
        } else {
            $output[] = '<span style="color: red; font-weight: bolder">' . esc_html__('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>' . esc_html__('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">' . esc_html__('Installed', EWWW_IMAGE_OPTIMIZER_DOMAIN) . '</span>&emsp;&emsp;';
        $file_command_check = false;
    } else {
        $output[] = 'finfo: <span style="color: red; font-weight: bolder">' . esc_html__('Missing', EWWW_IMAGE_OPTIMIZER_DOMAIN) . '</span>&emsp;&emsp;';
    }
    if (function_exists('getimagesize')) {
        $output[] = 'getimagesize(): <span style="color: green; font-weight: bolder">' . esc_html__('Installed', EWWW_IMAGE_OPTIMIZER_DOMAIN) . '</span>&emsp;&emsp;';
        if (ewww_image_optimizer_full_cloud() || EWWW_IMAGE_OPTIMIZER_NOEXEC || PHP_OS == 'WINNT') {
            $file_command_check = false;
        }
    } else {
        $output[] = 'getimagesize(): <span style="color: red; font-weight: bolder">' . esc_html__('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">' . esc_html__('Installed', EWWW_IMAGE_OPTIMIZER_DOMAIN) . '</span><br />' . "\n";
        $file_command_check = false;
    } else {
        $output[] = 'mime_content_type(): <span style="color: red; font-weight: bolder">' . esc_html__('Missing', EWWW_IMAGE_OPTIMIZER_DOMAIN) . '</span><br />' . "\n";
    }
    if (PHP_OS != 'WINNT' && !ewww_image_optimizer_full_cloud() && !EWWW_IMAGE_OPTIMIZER_NOEXEC) {
        if ($file_command_check && !ewww_image_optimizer_find_nix_binary('file', 'f')) {
            $output[] = '<span style="color: red; font-weight: bolder">file: ' . esc_html__('command not found on your system', EWWW_IMAGE_OPTIMIZER_DOMAIN) . '</span><br />';
            $collapsible = false;
        }
        if (!ewww_image_optimizer_find_nix_binary('nice', 'n')) {
            $output[] = '<span style="color: orange; font-weight: bolder">nice: ' . esc_html__('command not found on your system', EWWW_IMAGE_OPTIMIZER_DOMAIN) . ' (' . esc_html__('not required', EWWW_IMAGE_OPTIMIZER_DOMAIN) . ')</span><br />';
        }
        if (!ewww_image_optimizer_get_option('ewww_image_optimizer_disable_pngout') && !$skip['pngout'] && PHP_OS != 'SunOS' && !ewww_image_optimizer_find_nix_binary('tar', 't')) {
            $output[] = '<span style="color: red; font-weight: bolder">tar: ' . esc_html__('command not found on your system', EWWW_IMAGE_OPTIMIZER_DOMAIN) . ' (' . esc_html__('required for automatic pngout installer', EWWW_IMAGE_OPTIMIZER_DOMAIN) . ')</span><br />';
            $collapsible = false;
        }
    } elseif ($file_command_check) {
        $collapsible = false;
    }
    $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-general-nav'><span class='ewww-tab-hidden'><a class='ewww-general-nav' href='#'>" . esc_html__('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='#'>" . esc_html__('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='#'>" . esc_html__('Conversion Settings', EWWW_IMAGE_OPTIMIZER_DOMAIN) . "</a></span></li>\n" . "</ul>\n";
    if (is_multisite() && 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-general-settings'>\n";
    $output[] = "<p class='nocloud'>" . esc_html__('To unlock additional compression levels below, you may purchase an API key for our cloud optimization service.', EWWW_IMAGE_OPTIMIZER_DOMAIN) . " <a href='https://ewww.io/plans/'>" . esc_html__('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'>" . esc_html__('Cloud optimization API Key', EWWW_IMAGE_OPTIMIZER_DOMAIN) . "</label></th><td><input type='password' 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' /> " . esc_html__('API Key will be validated when you save your settings.', EWWW_IMAGE_OPTIMIZER_DOMAIN) . " <a href='https://ewww.io/plans/'>" . esc_html__('Purchase an API key.', EWWW_IMAGE_OPTIMIZER_DOMAIN) . "</a></td></tr>\n";
    $output[] = "<tr><th><label for='ewww_image_optimizer_debug'>" . esc_html__('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'" : "") . " /> " . esc_html__('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'>" . esc_html__('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'" : "") . " /> " . esc_html__('This will remove ALL metadata: EXIF and comments.', EWWW_IMAGE_OPTIMIZER_DOMAIN) . "</td></tr>\n";
    ewwwio_debug_message("remove metadata: " . (ewww_image_optimizer_get_option('ewww_image_optimizer_jpegtran_copy') == TRUE ? "on" : "off"));
    $output[] = "<tr><th>&nbsp;</th><td><p class='description'>" . esc_html__('Lossless compression keeps the original quality of the image.', EWWW_IMAGE_OPTIMIZER_DOMAIN) . ' ' . esc_html__('While most users will not notice a difference in image quality, lossy means there IS a loss in image quality.', EWWW_IMAGE_OPTIMIZER_DOMAIN) . "</p></td></tr>\n";
    $output[] = "<tr><th><label for='ewww_image_optimizer_jpg_level'>" . esc_html__('JPG Optimization Level', EWWW_IMAGE_OPTIMIZER_DOMAIN) . "</label></th>\n" . "<td><span><select id='ewww_image_optimizer_jpg_level' name='ewww_image_optimizer_jpg_level'>\n" . "<option value='0'" . (ewww_image_optimizer_get_option('ewww_image_optimizer_jpg_level') == 0 ? " selected='selected'" : "") . '>' . esc_html__('No Compression', EWWW_IMAGE_OPTIMIZER_DOMAIN) . "</option>\n";
    if (EWWW_IMAGE_OPTIMIZER_DOMAIN !== 'ewww-image-optimizer-cloud') {
        $output[] = "<option value='10'" . (ewww_image_optimizer_get_option('ewww_image_optimizer_jpg_level') == 10 ? " selected='selected'" : "") . '>' . esc_html__('Lossless Compression', EWWW_IMAGE_OPTIMIZER_DOMAIN) . "</option>\n";
    }
    $output[] = "<option {$disable_level} value='20'" . (ewww_image_optimizer_get_option('ewww_image_optimizer_jpg_level') == 20 ? " selected='selected'" : "") . '>' . esc_html__('Maximum Lossless Compression', EWWW_IMAGE_OPTIMIZER_DOMAIN) . "</option>\n" . "<option {$disable_level} value='30'" . (ewww_image_optimizer_get_option('ewww_image_optimizer_jpg_level') == 30 ? " selected='selected'" : "") . '>' . esc_html__('Lossy Compression', EWWW_IMAGE_OPTIMIZER_DOMAIN) . "</option>\n" . "<option {$disable_level} value='40'" . (ewww_image_optimizer_get_option('ewww_image_optimizer_jpg_level') == 40 ? " selected='selected'" : "") . '>' . esc_html__('Maximum Lossy Compression', EWWW_IMAGE_OPTIMIZER_DOMAIN) . "</option>\n" . "</select></td></tr>\n";
    ewwwio_debug_message("jpg level: " . ewww_image_optimizer_get_option('ewww_image_optimizer_jpg_level'));
    $output[] = "<tr><th><label for='ewww_image_optimizer_png_level'>" . esc_html__('PNG Optimization Level', EWWW_IMAGE_OPTIMIZER_DOMAIN) . "</label></th>\n" . "<td><span><select id='ewww_image_optimizer_png_level' name='ewww_image_optimizer_png_level'>\n" . "<option value='0'" . (ewww_image_optimizer_get_option('ewww_image_optimizer_png_level') == 0 ? " selected='selected'" : "") . '>' . esc_html__('No Compression', EWWW_IMAGE_OPTIMIZER_DOMAIN) . "</option>\n";
    if (EWWW_IMAGE_OPTIMIZER_DOMAIN !== 'ewww-image-optimizer-cloud') {
        $output[] = "<option value='10'" . (ewww_image_optimizer_get_option('ewww_image_optimizer_png_level') == 10 ? " selected='selected'" : "") . '>' . esc_html__('Lossless Compression', EWWW_IMAGE_OPTIMIZER_DOMAIN) . "</option>\n";
    }
    $output[] = "<option {$disable_level} value='20'" . (ewww_image_optimizer_get_option('ewww_image_optimizer_png_level') == 20 ? " selected='selected'" : "") . '>' . esc_html__('Better Lossless Compression', EWWW_IMAGE_OPTIMIZER_DOMAIN) . "</option>\n" . "<option {$disable_level} value='30'" . (ewww_image_optimizer_get_option('ewww_image_optimizer_png_level') == 30 ? " selected='selected'" : "") . '>' . esc_html__('Maximum Lossless Compression', EWWW_IMAGE_OPTIMIZER_DOMAIN) . "</option>\n" . "<option value='40'" . (ewww_image_optimizer_get_option('ewww_image_optimizer_png_level') == 40 ? " selected='selected'" : "") . '>' . esc_html__('Lossy Compression', EWWW_IMAGE_OPTIMIZER_DOMAIN) . "</option>\n" . "<option {$disable_level} value='50'" . (ewww_image_optimizer_get_option('ewww_image_optimizer_png_level') == 50 ? " selected='selected'" : "") . '>' . esc_html__('Maximum Lossy Compression', EWWW_IMAGE_OPTIMIZER_DOMAIN) . "</option>\n" . "</select></td></tr>\n";
    ewwwio_debug_message("png level: " . ewww_image_optimizer_get_option('ewww_image_optimizer_png_level'));
    $output[] = "<tr><th><label for='ewww_image_optimizer_gif_level'>" . esc_html__('GIF Optimization Level', EWWW_IMAGE_OPTIMIZER_DOMAIN) . "</label></th>\n" . "<td><span><select id='ewww_image_optimizer_gif_level' name='ewww_image_optimizer_gif_level'>\n" . "<option value='0'" . (ewww_image_optimizer_get_option('ewww_image_optimizer_gif_level') == 0 ? " selected='selected'" : "") . '>' . esc_html__('No Compression', EWWW_IMAGE_OPTIMIZER_DOMAIN) . "</option>\n" . "<option value='10'" . (ewww_image_optimizer_get_option('ewww_image_optimizer_gif_level') == 10 ? " selected='selected'" : "") . '>' . esc_html__('Lossless Compression', EWWW_IMAGE_OPTIMIZER_DOMAIN) . "</option>\n" . "</select></td></tr>\n";
    ewwwio_debug_message("gif level: " . ewww_image_optimizer_get_option('ewww_image_optimizer_gif_level'));
    $output[] = "<tr><th><label for='ewww_image_optimizer_pdf_level'>" . esc_html__('PDF Optimization Level', EWWW_IMAGE_OPTIMIZER_DOMAIN) . "</label></th>\n" . "<td><span><select id='ewww_image_optimizer_pdf_level' name='ewww_image_optimizer_pdf_level'>\n" . "<option value='0'" . (ewww_image_optimizer_get_option('ewww_image_optimizer_pdf_level') == 0 ? " selected='selected'" : "") . '>' . esc_html__('No Compression', EWWW_IMAGE_OPTIMIZER_DOMAIN) . "</option>\n" . "<option {$disable_level} value='10'" . (ewww_image_optimizer_get_option('ewww_image_optimizer_pdf_level') == 10 ? " selected='selected'" : "") . '>' . esc_html__('Lossless Compression', EWWW_IMAGE_OPTIMIZER_DOMAIN) . "</option>\n" . "<option {$disable_level} value='20'" . (ewww_image_optimizer_get_option('ewww_image_optimizer_pdf_level') == 20 ? " selected='selected'" : "") . '>' . esc_html__('Lossy Compression', EWWW_IMAGE_OPTIMIZER_DOMAIN) . "</option>\n" . "</select></td></tr>\n";
    ewwwio_debug_message("pdf level: " . ewww_image_optimizer_get_option('ewww_image_optimizer_pdf_level'));
    $output[] = "<tr><th><label for='ewww_image_optimizer_delay'>" . esc_html__('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') . "'> " . esc_html__('Choose how long to pause between images (in seconds, 0 = disabled)', EWWW_IMAGE_OPTIMIZER_DOMAIN) . "</td></tr>\n";
    ewwwio_debug_message("bulk delay: " . ewww_image_optimizer_get_option('ewww_image_optimizer_delay'));
    if (class_exists('Cloudinary') && Cloudinary::config_get('api_secret')) {
        $output[] = "<tr><th><label for='ewww_image_optimizer_enable_cloudinary'>" . esc_html__('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'" : "") . " /> " . esc_html__('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";
        ewwwio_debug_message("cloudinary upload: " . (ewww_image_optimizer_get_option('ewww_image_optimizer_enable_cloudinary') == TRUE ? "on" : "off"));
    }
    $output[] = "</table>\n</div>\n";
    $output[] = "<div id='ewww-optimization-settings'>\n";
    $output[] = "<table class='form-table'>\n";
    if (ewww_image_optimizer_full_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'>" . esc_html__('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(esc_html__('Level %d', EWWW_IMAGE_OPTIMIZER_DOMAIN), 1) . ': ' . sprintf(esc_html__('%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(esc_html__('Level %d', EWWW_IMAGE_OPTIMIZER_DOMAIN), 2) . ': ' . sprintf(esc_html__('%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(esc_html__('Level %d', EWWW_IMAGE_OPTIMIZER_DOMAIN), 3) . ': ' . sprintf(esc_html__('%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(esc_html__('Level %d', EWWW_IMAGE_OPTIMIZER_DOMAIN), 4) . ': ' . sprintf(esc_html__('%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(esc_html__('Level %d', EWWW_IMAGE_OPTIMIZER_DOMAIN), 5) . ': ' . sprintf(esc_html__('%d trials', EWWW_IMAGE_OPTIMIZER_DOMAIN), 48) . "</option>\n" . "</select> (" . esc_html__('default', EWWW_IMAGE_OPTIMIZER_DOMAIN) . "=2)</span>\n" . "<p class='description'>" . esc_html__('Levels 4 and above are unlikely to yield any additional savings.', EWWW_IMAGE_OPTIMIZER_DOMAIN) . "</p></td></tr>\n";
        ewwwio_debug_message("optipng level: " . ewww_image_optimizer_get_option('ewww_image_optimizer_optipng_level'));
        //				$output[] = "<tr class='nocloud'><th><label for='ewww_image_optimizer_disable_optipng'>" . esc_html__('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";
        //				ewwwio_debug_message( "optipng disabled: " . ( ewww_image_optimizer_get_option('ewww_image_optimizer_disable_optipng') == TRUE ? "yes" : "no" ) );
        $output[] = "<tr class='nocloud'><th><label for='ewww_image_optimizer_disable_pngout'>" . esc_html__('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";
        ewwwio_debug_message("pngout disabled: " . (ewww_image_optimizer_get_option('ewww_image_optimizer_disable_pngout') == TRUE ? "yes" : "no"));
        $output[] = "<tr class='nocloud'><th><label for='ewww_image_optimizer_pngout_level'>" . esc_html__('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(esc_html__('Level %d', EWWW_IMAGE_OPTIMIZER_DOMAIN), 0) . ': ' . esc_html__('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(esc_html__('Level %d', EWWW_IMAGE_OPTIMIZER_DOMAIN), 1) . ': ' . esc_html__('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(esc_html__('Level %d', EWWW_IMAGE_OPTIMIZER_DOMAIN), 2) . ': ' . esc_html__('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(esc_html__('Level %d', EWWW_IMAGE_OPTIMIZER_DOMAIN), 3) . ': ' . esc_html__('Huffman Only (Faster)', EWWW_IMAGE_OPTIMIZER_DOMAIN) . "</option>\n" . "</select> (" . esc_html__('default', EWWW_IMAGE_OPTIMIZER_DOMAIN) . "=2)</span>\n" . "<p class='description'>" . sprintf(esc_html__('If you have CPU cycles to spare, go with level %d', EWWW_IMAGE_OPTIMIZER_DOMAIN), 0) . "</p></td></tr>\n";
        ewwwio_debug_message("pngout level: " . ewww_image_optimizer_get_option('ewww_image_optimizer_pngout_level'));
    }
    //	$output[] = "<tr><th><label for='ewww_image_optimizer_defer'>" . esc_html__( 'Deferred Optimization', EWWW_IMAGE_OPTIMIZER_DOMAIN ) . "</label></th><td><input type='checkbox' id='ewww_image_optimizer_defer' name='ewww_image_optimizer_defer' value='true' " . ( ewww_image_optimizer_get_option( 'ewww_image_optimizer_defer' ) == TRUE ? "checked='true'" : "" ) . " /> " . esc_html__( 'Optimize images later via wp_cron, after image upload or generation is complete.', EWWW_IMAGE_OPTIMIZER_DOMAIN ) . "</td></tr>\n";
    //	ewwwio_debug_message( "deferred optimization: " . ( ewww_image_optimizer_get_option('ewww_image_optimizer_defer') == TRUE ? "on" : "off" ) );
    $output[] = "<tr><th><span><label for='ewww_image_optimizer_jpg_quality'>" . esc_html__('JPG quality level:', EWWW_IMAGE_OPTIMIZER_DOMAIN) . "</label></th><td><input type='text' id='ewww_image_optimizer_jpg_quality' name='ewww_image_optimizer_jpg_quality' class='small-text' value='" . ewww_image_optimizer_jpg_quality() . "' /> " . esc_html__('Valid values are 1-100.', EWWW_IMAGE_OPTIMIZER_DOMAIN) . "\n<p class='description'>" . esc_html__('Use this to override the default WordPress quality level of 82. This only applies to edited images, resizes, and converted PNG files. Original images are uploaded unmodified.', EWWW_IMAGE_OPTIMIZER_DOMAIN) . "</p></td></tr>\n";
    $output[] = "<tr><th><label for='ewww_image_optimizer_parallel_optimization'>" . esc_html__('Parallel optimization', EWWW_IMAGE_OPTIMIZER_DOMAIN) . "</label></th><td><input type='checkbox' id='ewww_image_optimizer_parallel_optimization' name='ewww_image_optimizer_parallel_optimization' value='true' " . (ewww_image_optimizer_get_option('ewww_image_optimizer_parallel_optimization') == TRUE ? "checked='true'" : "") . " /> " . esc_html__('All resizes generated from a single upload are optimized in parallel for faster optimization. If this is causing performance issues, disable parallel optimization to reduce the load on your server.', EWWW_IMAGE_OPTIMIZER_DOMAIN) . "</td></tr>\n";
    ewwwio_debug_message("parallel optimization: " . (ewww_image_optimizer_get_option('ewww_image_optimizer_parallel_optimization') == TRUE ? "on" : "off"));
    $output[] = "<tr><th><label for='ewww_image_optimizer_auto'>" . esc_html__('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'" : "") . " /> " . esc_html__('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";
    ewwwio_debug_message("scheduled optimization: " . (ewww_image_optimizer_get_option('ewww_image_optimizer_auto') == TRUE ? "on" : "off"));
    $output[] = "<tr><th><label for='ewww_image_optimizer_aux_paths'>" . esc_html__('Folders to optimize', EWWW_IMAGE_OPTIMIZER_DOMAIN) . "</label></th><td>" . sprintf(esc_html__('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'>" . esc_html__('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";
    if (!empty($aux_paths)) {
        ewwwio_debug_message("folders to optimize:");
        foreach ($aux_paths as $aux_path) {
            ewwwio_debug_message($aux_path);
        }
    }
    $output[] = "<tr><th><label for='ewww_image_optimizer_include_media_paths'>" . esc_html__('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'" : "") . " /> " . esc_html__('Include the latest two folders from the Media Library in Scheduled Optimization and Optimize Everything Else.', EWWW_IMAGE_OPTIMIZER_DOMAIN) . "</td></tr>\n";
    ewwwio_debug_message("include media library: " . (ewww_image_optimizer_get_option('ewww_image_optimizer_include_media_paths') == TRUE ? "on" : "off"));
    $output[] = "<tr><th>" . esc_html__('Resize Media Images', EWWW_IMAGE_OPTIMIZER_DOMAIN) . "</th><td><label for='ewww_image_optimizer_maxmediawidth'>" . esc_html__('Max Width', EWWW_IMAGE_OPTIMIZER_DOMAIN) . "</label> <input type='number' step='1' min='0' class='small-text' id='ewww_image_optimizer_maxmediawidth' name='ewww_image_optimizer_maxmediawidth' value='" . ewww_image_optimizer_get_option('ewww_image_optimizer_maxmediawidth') . "' /> <label for='ewww_image_optimizer_maxmediaheight'>" . esc_html__('Max Height', EWWW_IMAGE_OPTIMIZER_DOMAIN) . "</label> <input type='number' step='1' min='0' class='small-text' id='ewww_image_optimizer_maxmediaheight' name='ewww_image_optimizer_maxmediaheight' value='" . ewww_image_optimizer_get_option('ewww_image_optimizer_maxmediaheight') . "' />\n" . "<p class='description'>" . esc_html__('Resizes images uploaded directly to the Media Library and those uploaded within a post or page.', EWWW_IMAGE_OPTIMIZER_DOMAIN) . "</td></tr>\n";
    ewwwio_debug_message("max media dimensions: " . ewww_image_optimizer_get_option('ewww_image_optimizer_maxmediawidth') . ' x ' . ewww_image_optimizer_get_option('ewww_image_optimizer_maxmediaheight'));
    $output[] = "<tr><th>" . esc_html__('Resize Other Images', EWWW_IMAGE_OPTIMIZER_DOMAIN) . "</th><td><label for='ewww_image_optimizer_maxotherwidth'>" . esc_html__('Max Width', EWWW_IMAGE_OPTIMIZER_DOMAIN) . "</label> <input type='number' step='1' min='0' class='small-text' id='ewww_image_optimizer_maxotherwidth' name='ewww_image_optimizer_maxotherwidth' value='" . ewww_image_optimizer_get_option('ewww_image_optimizer_maxotherwidth') . "' /> <label for='ewww_image_optimizer_maxotherheight'>" . esc_html__('Max Height', EWWW_IMAGE_OPTIMIZER_DOMAIN) . "</label> <input type='number' step='1' min='0' class='small-text' id='ewww_image_optimizer_maxotherheight' name='ewww_image_optimizer_maxotherheight' value='" . ewww_image_optimizer_get_option('ewww_image_optimizer_maxotherheight') . "' />\n" . "<p class='description'>" . esc_html__('Resizes images uploaded indirectly to the Media Library, like theme images or front-end uploads.', EWWW_IMAGE_OPTIMIZER_DOMAIN) . "</td></tr>\n";
    ewwwio_debug_message("max other dimensions: " . ewww_image_optimizer_get_option('ewww_image_optimizer_maxotherwidth') . ' x ' . ewww_image_optimizer_get_option('ewww_image_optimizer_maxotherheight'));
    $output[] = "<tr><th><label for='ewww_image_optimizer_resize_existing'>" . esc_html__('Resize Existing Images', EWWW_IMAGE_OPTIMIZER_DOMAIN) . "</label></th><td><input type='checkbox' id='ewww_image_optimizer_resize_existing' name='ewww_image_optimizer_resize_existing' value='true' " . (ewww_image_optimizer_get_option('ewww_image_optimizer_resize_existing') == TRUE ? "checked='true'" : "") . " /> " . esc_html__('Allow resizing of existing Media Library images.', EWWW_IMAGE_OPTIMIZER_DOMAIN) . "</td></tr>\n";
    ewwwio_debug_message('resize existing images: ' . (ewww_image_optimizer_get_option('ewww_image_optimizer_resize_existing') == TRUE ? 'on' : 'off'));
    $output[] = "<tr><th>" . esc_html__('Disable Resizes', EWWW_IMAGE_OPTIMIZER_DOMAIN) . "</th><td><p>" . esc_html__('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";
    $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>' . esc_html__('Disable Optimization', EWWW_IMAGE_OPTIMIZER_DOMAIN) . '</th><th>' . esc_html__('Disable Creation', EWWW_IMAGE_OPTIMIZER_DOMAIN) . "</th></tr>\n";
    ewwwio_debug_message('disabled resizes:');
    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";
        }
        ewwwio_debug_message($size . ': ' . (!empty($disabled_sizes_opt[$size]) ? "optimization=disabled " : "optimization=enabled ") . (!empty($disabled_sizes[$size]) ? "creation=disabled" : "creation=enabled"));
    }
    $output[] = "</table>\n";
    $output[] = "</td></tr>\n";
    $output[] = "<tr><th><label for='ewww_image_optimizer_skip_size'>" . esc_html__('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') . "'> " . esc_html__('Do not optimize images smaller than this (in bytes)', EWWW_IMAGE_OPTIMIZER_DOMAIN) . "</td></tr>\n";
    ewwwio_debug_message("skip images smaller than: " . ewww_image_optimizer_get_option('ewww_image_optimizer_skip_size') . " bytes");
    $output[] = "<tr><th><label for='ewww_image_optimizer_skip_png_size'>" . esc_html__('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') . "'> " . esc_html__('Do not optimize PNG images larger than this (in bytes)', EWWW_IMAGE_OPTIMIZER_DOMAIN) . "</td></tr>\n";
    ewwwio_debug_message("skip PNG images larger than: " . ewww_image_optimizer_get_option('ewww_image_optimizer_skip_png_size') . " bytes");
    $output[] = "<tr><th><label for='ewww_image_optimizer_lossy_skip_full'>" . esc_html__('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";
    ewwwio_debug_message("exclude originals from lossy: " . (ewww_image_optimizer_get_option('ewww_image_optimizer_lossy_skip_full') == TRUE ? "on" : "off"));
    $output[] = "<tr><th><label for='ewww_image_optimizer_metadata_skip_full'>" . esc_html__('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";
    ewwwio_debug_message("exclude originals from metadata removal: " . (ewww_image_optimizer_get_option('ewww_image_optimizer_metadata_skip_full') == TRUE ? "on" : "off"));
    $output[] = "<tr class='nocloud'><th><label for='ewww_image_optimizer_skip_bundle'>" . esc_html__('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(esc_html__('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";
    ewwwio_debug_message("use system binaries: " . (ewww_image_optimizer_get_option('ewww_image_optimizer_skip_bundle') == TRUE ? "yes" : "no"));
    $output[] = "</table>\n</div>\n";
    $output[] = "<div id='ewww-conversion-settings'>\n";
    $output[] = "<p>" . esc_html__('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>" . esc_html__('NOTE:', EWWW_IMAGE_OPTIMIZER_DOMAIN) . "</b> " . esc_html__('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'>" . esc_html__('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'" : "") . " /> " . esc_html__('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'>" . esc_html__('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'" : "") . " /> " . esc_html__('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'>" . esc_html__('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>" . esc_html__('WARNING:', EWWW_IMAGE_OPTIMIZER_DOMAIN) . '</b> ' . esc_html__('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'>" . esc_html__('Originals are never deleted, and WebP images should only be served to supported browsers.', EWWW_IMAGE_OPTIMIZER_DOMAIN) . " <a href='#webp-rewrite'>" . (ewww_image_optimizer_get_option('ewww_image_optimizer_webp') && !ewww_image_optimizer_get_option('ewww_image_optimizer_webp_for_cdn') ? esc_html__('You can use the rewrite rules below to serve WebP images with Apache.', EWWW_IMAGE_OPTIMIZER_DOMAIN) : '') . "</a></td></tr>\n";
    ewwwio_debug_message("webp conversion: " . (ewww_image_optimizer_get_option('ewww_image_optimizer_webp') == TRUE ? "on" : "off"));
    if (!ewww_image_optimizer_ce_webp_enabled()) {
        $output[] = "<tr><th><label for='ewww_image_optimizer_webp_for_cdn'>" . esc_html__('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'" : "") . " /> " . esc_html__('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) . ' ' . sprintf(esc_html('Sites using a CDN may also use the WebP option in the %s plugin.', EWWW_IMAGE_OPTIMIZER_DOMAIN), '<a href="https://wordpress.org/plugins/cache-enabler/">Cache Enabler</a>') . "</span></td></tr>";
    }
    ewwwio_debug_message("alt webp rewriting: " . (ewww_image_optimizer_get_option('ewww_image_optimizer_webp_for_cdn') == TRUE ? "on" : "off"));
    //				$output[] = "<tr><th><label for='ewww_image_optimizer_webp_cdn_path'>" . esc_html__('WebP CDN URL', EWWW_IMAGE_OPTIMIZER_DOMAIN) . "</label></th><td><span><input type='checkbox' id='ewww_image_optimizer_webp_cdn_path' name='ewww_image_optimizer_webp_cdn_path' value='true' " . ( ewww_image_optimizer_get_option('ewww_image_optimizer_webp_for_cdn') == TRUE ? "checked='true'" : "" ) . " /> " . esc_html__('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(esc_html__('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>" . esc_html__('WARNING:', EWWW_IMAGE_OPTIMIZER_DOMAIN) . "</b> " . esc_html__('Removes metadata and increases cpu usage dramatically.', EWWW_IMAGE_OPTIMIZER_DOMAIN) . "</span>\n" . "<p class='description'>" . esc_html__('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";
    ewwwio_debug_message("jpg2png: " . (ewww_image_optimizer_get_option('ewww_image_optimizer_jpg_to_png') == TRUE ? "on" : "off"));
    $output[] = "<tr><th><label for='ewww_image_optimizer_png_to_jpg'>" . sprintf(esc_html__('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>" . esc_html__('WARNING:', EWWW_IMAGE_OPTIMIZER_DOMAIN) . "</b> " . esc_html__('This is not a lossless conversion.', EWWW_IMAGE_OPTIMIZER_DOMAIN) . "</span>\n" . "<p class='description'>" . esc_html__('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'> " . esc_html__('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> " . esc_html__('HEX format (#123def)', EWWW_IMAGE_OPTIMIZER_DOMAIN) . ".</span>\n" . "<p class='description'>" . esc_html__('Background color is used only if the PNG has transparency. Leave this value blank to skip PNGs with transparency.', EWWW_IMAGE_OPTIMIZER_DOMAIN) . "</p></td></tr>\n";
    //	"<span><label for='ewww_image_optimizer_jpg_quality'>" . esc_html__('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() . "' /> " . esc_html__('Valid values are 1-100.', EWWW_IMAGE_OPTIMIZER_DOMAIN) . "</span>\n" .
    //				"<p class='description'>" . esc_html__('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";
    ewwwio_debug_message("png2jpg: " . (ewww_image_optimizer_get_option('ewww_image_optimizer_png_to_jpg') == TRUE ? "on" : "off"));
    $output[] = "<tr><th><label for='ewww_image_optimizer_gif_to_png'>" . sprintf(esc_html__('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'" : "") . " /> " . esc_html__('No warnings here, just do it.', EWWW_IMAGE_OPTIMIZER_DOMAIN) . "</span>\n" . "<p class='description'> " . esc_html__('PNG is generally better than GIF, but animated images cannot be converted.', EWWW_IMAGE_OPTIMIZER_DOMAIN) . "</p></td></tr>\n";
    ewwwio_debug_message("gif2png: " . (ewww_image_optimizer_get_option('ewww_image_optimizer_gif_to_png') == TRUE ? "on" : "off"));
    $output[] = "</table>\n</div>\n";
    $output[] = "<p class='submit'><input type='submit' class='button-primary' value='" . esc_attr__('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') && !ewww_image_optimizer_ce_webp_enabled()) {
        $output[] = "<form id='ewww-webp-rewrite'>\n";
        $output[] = "<p>" . esc_html__('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('/images/test.png', __FILE__) . "' style='float: right; padding: 0 0 10px 10px;'>\n" . "<p id='ewww-webp-rewrite-status'><b>" . esc_html__('Rules verified successfully', EWWW_IMAGE_OPTIMIZER_DOMAIN) . "</b></p>\n";
            ewwwio_debug_message('webp .htaccess rewriting enabled');
        } 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('/images/test.png', __FILE__) . "' style='float: right; padding-left: 10px;'>\n" . "<p id='ewww-webp-rewrite-status'>" . esc_html__('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'>" . esc_html__('Insert Rewrite Rules', EWWW_IMAGE_OPTIMIZER_DOMAIN) . "</button>\n";
            ewwwio_debug_message('webp .htaccess rules not detected');
        }
        $output[] = "</form>\n";
    }
    $output[] = "</div><!-- end container left -->\n";
    $output[] = "<div id='ewww-container-right' 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" . "<h2>" . esc_html__('Support EWWW I.O.', EWWW_IMAGE_OPTIMIZER_DOMAIN) . "</h2>\n" . "<p>" . esc_html__('Would you like to help support development of this plugin?', EWWW_IMAGE_OPTIMIZER_DOMAIN) . "</p>\n" . "<p><a href='https://translate.wordpress.org/projects/wp-plugins/ewww-image-optimizer/'>" . esc_html__('Help translate EWWW I.O.', EWWW_IMAGE_OPTIMIZER_DOMAIN) . "</a></p>\n" . "<p><a href='https://wordpress.org/support/view/plugin-reviews/ewww-image-optimizer#postform'>" . esc_html__('Write a review.', EWWW_IMAGE_OPTIMIZER_DOMAIN) . "</a></p>\n" . "<p>" . wp_kses(sprintf(__('Contribute directly via %s.', EWWW_IMAGE_OPTIMIZER_DOMAIN), "<a href='https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&amp;hosted_button_id=MKMQKCBFFG3WW'>Paypal</a>"), array('a' => array('href' => array()))) . "</p>\n" . "<p>" . esc_html__('Use any of these referral links to show your appreciation:', EWWW_IMAGE_OPTIMIZER_DOMAIN) . "</p>\n" . "<p><b>" . esc_html__('Web Hosting:', EWWW_IMAGE_OPTIMIZER_DOMAIN) . "</b><br>\n" . "<a href='https://partners.a2hosting.com/solutions.php?id=5959&url=638'>A2 Hosting:</a> " . esc_html_x('with automatic EWWW IO setup', 'A2 Hosting:', EWWW_IMAGE_OPTIMIZER_DOMAIN) . "<br>\n" . "<a href='http://www.bluehost.com/track/nosilver4u'>Bluehost</a><br>\n" . "<a href='http://www.dreamhost.com/r.cgi?132143'>Dreamhost</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>" . esc_html_x('VPS:', 'abbreviation for Virtual Private Server', EWWW_IMAGE_OPTIMIZER_DOMAIN) . "</b><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" . "</p>\n" . "<p><b>" . esc_html_x('CDN:', 'abbreviation for Content Delivery Network', EWWW_IMAGE_OPTIMIZER_DOMAIN) . "</b><br><a target='_blank' href='http://tracking.maxcdn.com/c/91625/36539/378'>" . esc_html__('Add MaxCDN to increase website speeds dramatically! Sign Up Now and Save 25%.', EWWW_IMAGE_OPTIMIZER_DOMAIN) . "</a> " . esc_html__('Integrate MaxCDN within Wordpress using the W3 Total Cache plugin.', EWWW_IMAGE_OPTIMIZER_DOMAIN) . "</p>\n" . "</div>\n" . "</div>\n";
    ewwwio_debug_message('max_execution_time: ' . ini_get('max_execution_time'));
    echo apply_filters('ewww_image_optimizer_settings', $output);
    if (ewww_image_optimizer_get_option('ewww_image_optimizer_debug')) {
        ?>
<script type="text/javascript">
    function selectText(containerid) {
        if (document.selection) {
            var range = document.body.createTextRange();
            range.moveToElementText(document.getElementById(containerid));
            range.select();
        } else if (window.getSelection) {
            var range = document.createRange();
            range.selectNode(document.getElementById(containerid));
            window.getSelection().addRange(range);
        }
    }
</script>
		<?php 
        global $ewww_debug;
        echo '<p style="clear:both"><b>' . esc_html__('Debugging Information', EWWW_IMAGE_OPTIMIZER_DOMAIN) . ':</b> <button onclick="selectText(' . "'ewww-debug-info'" . ')">' . esc_html__('Select All', EWWW_IMAGE_OPTIMIZER_DOMAIN) . '</button></p>';
        echo '<div id="ewww-debug-info" style="background:#ffff99;margin-left:-20px;padding:10px" contenteditable="true">' . $ewww_debug . '</div>';
    }
    ewwwio_memory(__FUNCTION__);
    ewww_image_optimizer_debug_log();
}