Пример #1
0
 function ewww_added_new_image($image, $storage = null)
 {
     global $ewww_debug;
     $ewww_debug .= "<b>ewww_added_new_image()</b><br>";
     if (empty($storage)) {
         // creating the 'registry' object for working with nextgen
         $registry = C_Component_Registry::get_instance();
         // creating a database storage object from the 'registry' object
         $storage = $registry->get_utility('I_Gallery_Storage');
     }
     // find the image id
     $image_id = $storage->object->_get_image_id($image);
     $ewww_debug .= "image id: {$image_id}<br>";
     // get an array of sizes available for the $image
     $sizes = $storage->get_image_sizes();
     // run the optimizer on the image for each $size
     foreach ($sizes as $size) {
         if ($size === 'full') {
             $full_size = true;
         } else {
             $full_size = false;
         }
         // get the absolute path
         $file_path = $storage->get_image_abspath($image, $size);
         $ewww_debug .= "optimizing (nextgen): {$file_path}<br>";
         // optimize the image and grab the results
         $res = ewww_image_optimizer($file_path, 2, false, false, $full_size);
         $ewww_debug .= "results " . $res[1] . "<br>";
         // only if we're dealing with the full-size original
         if ($size === 'full') {
             // update the metadata for the optimized image
             $image->meta_data['ewww_image_optimizer'] = $res[1];
         } else {
             $image->meta_data[$size]['ewww_image_optimizer'] = $res[1];
         }
         nggdb::update_image_meta($image_id, $image->meta_data);
         $ewww_debug .= 'storing results for full size image<br>';
     }
     ewww_image_optimizer_debug_log();
     return $image;
 }
Пример #2
0
/**
 * Update the attachment's meta data after being converted 
 */
function ewww_image_optimizer_update_attachment($meta, $ID)
{
    ewwwio_debug_message('<b>' . __FUNCTION__ . '()</b>');
    global $wpdb;
    // update the file location in the post metadata based on the new path stored in the attachment metadata
    update_attached_file($ID, $meta['file']);
    $guid = wp_get_attachment_url($ID);
    if (empty($meta['real_orig_file'])) {
        $old_guid = dirname($guid) . "/" . basename($meta['orig_file']);
    } else {
        $old_guid = dirname($guid) . "/" . basename($meta['real_orig_file']);
        unset($meta['real_orig_file']);
    }
    // construct the new guid based on the filename from the attachment metadata
    ewwwio_debug_message("old guid: {$old_guid}");
    ewwwio_debug_message("new guid: {$guid}");
    if (substr($old_guid, -1) == '/' || substr($guid, -1) == '/') {
        ewwwio_debug_message('could not obtain full url for current and previous image, bailing');
        return $meta;
    }
    // retrieve any posts that link the image
    $esql = $wpdb->prepare("SELECT ID, post_content FROM {$wpdb->posts} WHERE post_content LIKE '%%%s%%'", $old_guid);
    ewwwio_debug_message("using query: {$esql}");
    // while there are posts to process
    $rows = $wpdb->get_results($esql, ARRAY_A);
    foreach ($rows as $row) {
        // replace all occurences of the old guid with the new guid
        $post_content = str_replace($old_guid, $guid, $row['post_content']);
        ewwwio_debug_message("replacing {$old_guid} with {$guid} in post " . $row['ID']);
        // send the updated content back to the database
        $wpdb->update($wpdb->posts, array('post_content' => $post_content), array('ID' => $row['ID']));
    }
    if (isset($meta['sizes'])) {
        // for each resized version
        foreach ($meta['sizes'] as $size => $data) {
            // if the resize was converted
            if (isset($data['converted'])) {
                // generate the url for the old image
                if (empty($data['real_orig_file'])) {
                    $old_sguid = dirname($old_guid) . "/" . basename($data['orig_file']);
                } else {
                    $old_sguid = dirname($old_guid) . "/" . basename($data['real_orig_file']);
                    unset($meta['sizes'][$size]['real_orig_file']);
                }
                ewwwio_debug_message("processing: {$size}");
                ewwwio_debug_message("old sguid: {$old_sguid}");
                // generate the url for the new image
                $sguid = dirname($old_guid) . "/" . basename($data['file']);
                ewwwio_debug_message("new sguid: {$sguid}");
                if (substr($old_sguid, -1) == '/' || substr($sguid, -1) == '/') {
                    ewwwio_debug_message('could not obtain full url for current and previous resized image, bailing');
                    continue;
                }
                // retrieve any posts that link the resize
                $ersql = $wpdb->prepare("SELECT ID, post_content FROM {$wpdb->posts} WHERE post_content LIKE '%%%s%%'", $old_sguid);
                //ewwwio_debug_message( "using query: $ersql" );
                $rows = $wpdb->get_results($ersql, ARRAY_A);
                // while there are posts to process
                foreach ($rows as $row) {
                    // replace all occurences of the old guid with the new guid
                    $post_content = str_replace($old_sguid, $sguid, $row['post_content']);
                    ewwwio_debug_message("replacing {$old_sguid} with {$sguid} in post " . $row['ID']);
                    // send the updated content back to the database
                    $wpdb->update($wpdb->posts, array('post_content' => $post_content), array('ID' => $row['ID']));
                }
            }
        }
    }
    // if the new image is a JPG
    if (preg_match('/.jpg$/i', basename($meta['file']))) {
        // set the mimetype to JPG
        $mime = 'image/jpg';
    }
    // if the new image is a PNG
    if (preg_match('/.png$/i', basename($meta['file']))) {
        // set the mimetype to PNG
        $mime = 'image/png';
    }
    if (preg_match('/.gif$/i', basename($meta['file']))) {
        // set the mimetype to GIF
        $mime = 'image/gif';
    }
    // update the attachment post with the new mimetype and id
    wp_update_post(array('ID' => $ID, 'post_mime_type' => $mime));
    ewww_image_optimizer_debug_log();
    ewwwio_memory(__FUNCTION__);
    return $meta;
}
Пример #3
0
 function ewww_added_new_image($image)
 {
     ewwwio_debug_message('<b>' . __FUNCTION__ . '()</b>');
     global $ewww_defer;
     // make sure the image path is set
     if (isset($image->imagePath)) {
         // get the image ID
         $pid = $image->pid;
         if ($ewww_defer && ewww_image_optimizer_get_option('ewww_image_optimizer_defer')) {
             ewww_image_optimizer_add_deferred_attachment("flag,{$pid}");
             return;
         }
         // optimize the full size
         $res = ewww_image_optimizer($image->imagePath, 3, false, false, true);
         // optimize the web optimized version
         $wres = ewww_image_optimizer($image->webimagePath, 3, false, true);
         // optimize the thumbnail
         $tres = ewww_image_optimizer($image->thumbPath, 3, false, true);
         // retrieve the metadata for the image ID
         $meta = new flagMeta($pid);
         ewwwio_debug_message(print_r($meta->image->meta_data, TRUE));
         $meta->image->meta_data['ewww_image_optimizer'] = $res[1];
         if (!empty($meta->image->meta_data['webview'])) {
             $meta->image->meta_data['webview']['ewww_image_optimizer'] = $wres[1];
         }
         $meta->image->meta_data['thumbnail']['ewww_image_optimizer'] = $tres[1];
         // update the image metadata in the db
         flagdb::update_image_meta($pid, $meta->image->meta_data);
     }
     ewww_image_optimizer_debug_log();
 }
Пример #4
0
function ewww_image_optimizer_bulk_loop()
{
    global $ewww_debug;
    global $ewww_exceed;
    // verify that an authorized user has started the optimizer
    $permissions = apply_filters('ewww_image_optimizer_bulk_permissions', '');
    if (!wp_verify_nonce($_REQUEST['ewww_wpnonce'], 'ewww-image-optimizer-bulk') || !current_user_can($permissions)) {
        wp_die(__('Cheatin&#8217; eh?', EWWW_IMAGE_OPTIMIZER_DOMAIN));
    }
    if (!empty($_REQUEST['ewww_sleep'])) {
        sleep($_REQUEST['ewww_sleep']);
    }
    // retrieve the time when the optimizer starts
    $started = microtime(true);
    // get the attachment ID of the current attachment
    $attachment = $_POST['ewww_attachment'];
    // get the 'bulk attachments' with a list of IDs remaining
    $attachments = get_option('ewww_image_optimizer_bulk_attachments');
    $meta = wp_get_attachment_metadata($attachment, true);
    // do the optimization for the current attachment (including resizes)
    $meta = ewww_image_optimizer_resize_from_meta_data($meta, $attachment, false);
    if (!empty($ewww_exceed)) {
        echo '-9exceeded';
        die;
    }
    if (!empty($meta['file'])) {
        // output the filename (and path relative to 'uploads' folder)
        printf("<p>" . __('Optimized image:', EWWW_IMAGE_OPTIMIZER_DOMAIN) . " <strong>%s</strong><br>", esc_html($meta['file']));
    } else {
        printf("<p>" . __('Skipped image, ID:', EWWW_IMAGE_OPTIMIZER_DOMAIN) . " <strong>%s</strong><br>", $attachment);
    }
    if (!empty($meta['ewww_image_optimizer'])) {
        // tell the user what the results were for the original image
        printf(__('Full size – %s', EWWW_IMAGE_OPTIMIZER_DOMAIN) . "<br>", $meta['ewww_image_optimizer']);
    }
    // check to see if there are resized version of the image
    if (isset($meta['sizes']) && is_array($meta['sizes'])) {
        // cycle through each resize
        foreach ($meta['sizes'] as $size) {
            if (!empty($size['ewww_image_optimizer'])) {
                // output the results for the current resized version
                printf("%s – %s<br>", $size['file'], $size['ewww_image_optimizer']);
            }
        }
    }
    // calculate how much time has elapsed since we started
    $elapsed = microtime(true) - $started;
    // output how much time has elapsed since we started
    printf(__('Elapsed: %.3f seconds', EWWW_IMAGE_OPTIMIZER_DOMAIN) . "</p>", $elapsed);
    global $ewww_attachment;
    $ewww_attachment['id'] = $attachment;
    $ewww_attachment['meta'] = $meta;
    add_filter('w3tc_cdn_update_attachment_metadata', 'ewww_image_optimizer_w3tc_update_files');
    // update the metadata for the current attachment
    wp_update_attachment_metadata($attachment, $meta);
    // remove the first element from the $attachments array
    if (!empty($attachments)) {
        array_shift($attachments);
    }
    // store the updated list of attachment IDs back in the 'bulk_attachments' option
    update_option('ewww_image_optimizer_bulk_attachments', $attachments);
    if (ewww_image_optimizer_get_option('ewww_image_optimizer_debug')) {
        echo '<div style="background-color:#ffff99;">' . $ewww_debug . '</div>';
    }
    ewww_image_optimizer_debug_log();
    ewwwio_memory(__FUNCTION__);
    die;
}
Пример #5
0
 function ewww_added_new_image($image)
 {
     global $ewww_debug;
     $ewww_debug .= "<b>ewww_flag::ewww_added_new_image()</b><br>";
     // make sure the image path is set
     if (isset($image->imagePath)) {
         // optimize the full size
         $res = ewww_image_optimizer($image->imagePath, 3, false, false, true);
         // optimize the web optimized version
         $wres = ewww_image_optimizer($image->webimagePath, 3, false, true);
         // optimize the thumbnail
         $tres = ewww_image_optimizer($image->thumbPath, 3, false, true);
         // get the image ID
         $pid = $image->pid;
         // retrieve the metadata for the image ID
         $meta = new flagMeta($pid);
         $ewww_debug .= print_r($meta->image->meta_data, TRUE) . "<br>";
         $meta->image->meta_data['ewww_image_optimizer'] = $res[1];
         if (!empty($meta->image->meta_data['webview'])) {
             $meta->image->meta_data['webview']['ewww_image_optimizer'] = $wres[1];
         }
         $meta->image->meta_data['thumbnail']['ewww_image_optimizer'] = $tres[1];
         // update the image metadata in the db
         flagdb::update_image_meta($pid, $meta->image->meta_data);
     }
     ewww_image_optimizer_debug_log();
 }
Пример #6
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();
}
Пример #7
0
/**
 * Update the attachment's meta data after being converted 
 */
function ewww_image_optimizer_update_attachment($meta, $ID)
{
    global $ewww_debug;
    global $wpdb;
    $ewww_debug .= "<b>ewww_image_optimizer_update_attachment()</b><br>";
    // update the file location in the post metadata based on the new path stored in the attachment metadata
    update_attached_file($ID, $meta['file']);
    // retrieve the post information based on the $ID
    $post = get_post($ID);
    // save the previous attachment address
    $old_guid = $post->guid;
    // construct the new guid based on the filename from the attachment metadata
    $guid = dirname($post->guid) . "/" . basename($meta['file']);
    // retrieve any posts that link the image
    $esql = $wpdb->prepare("SELECT ID, post_content FROM {$wpdb->posts} WHERE post_content LIKE '%%%s%%'", $old_guid);
    // while there are posts to process
    $rows = $wpdb->get_results($esql, ARRAY_A);
    foreach ($rows as $row) {
        // replace all occurences of the old guid with the new guid
        $post_content = str_replace($old_guid, $guid, $row['post_content']);
        $ewww_debug .= "replacing {$old_guid} with {$guid} in post " . $row['ID'] . '<br>';
        // send the updated content back to the database
        $wpdb->update($wpdb->posts, array('post_content' => $post_content), array('ID' => $row['ID']));
    }
    if (isset($meta['sizes'])) {
        // for each resized version
        foreach ($meta['sizes'] as $size => $data) {
            // if the resize was converted
            if (isset($data['converted'])) {
                // generate the url for the old image
                if (empty($data['real_orig_file'])) {
                    $old_sguid = dirname($post->guid) . "/" . basename($data['orig_file']);
                } else {
                    $old_sguid = dirname($post->guid) . "/" . basename($data['real_orig_file']);
                    unset($meta['sizes'][$size]['real_orig_file']);
                }
                $ewww_debug .= "processing: {$size}<br>";
                $ewww_debug .= "old guid: {$old_sguid} <br>";
                // generate the url for the new image
                $sguid = dirname($post->guid) . "/" . basename($data['file']);
                $ewww_debug .= "new guid: {$sguid} <br>";
                // retrieve any posts that link the resize
                $ersql = $wpdb->prepare("SELECT ID, post_content FROM {$wpdb->posts} WHERE post_content LIKE '%%%s%%'", $old_sguid);
                $ewww_debug .= "using query: {$ersql}<br>";
                $rows = $wpdb->get_results($ersql, ARRAY_A);
                // while there are posts to process
                foreach ($rows as $row) {
                    // replace all occurences of the old guid with the new guid
                    $post_content = str_replace($old_sguid, $sguid, $row['post_content']);
                    $ewww_debug .= "replacing {$old_sguid} with {$sguid} in post " . $row['ID'] . '<br>';
                    // send the updated content back to the database
                    $wpdb->update($wpdb->posts, array('post_content' => $post_content), array('ID' => $row['ID']));
                }
            }
        }
    }
    // if the new image is a JPG
    if (preg_match('/.jpg$/i', basename($meta['file']))) {
        // set the mimetype to JPG
        $mime = 'image/jpg';
    }
    // if the new image is a PNG
    if (preg_match('/.png$/i', basename($meta['file']))) {
        // set the mimetype to PNG
        $mime = 'image/png';
    }
    if (preg_match('/.gif$/i', basename($meta['file']))) {
        // set the mimetype to GIF
        $mime = 'image/gif';
    }
    // update the attachment post with the new mimetype and guid
    wp_update_post(array('ID' => $ID, 'post_mime_type' => $mime, 'guid' => $guid));
    ewww_image_optimizer_debug_log();
    ewwwio_memory(__FUNCTION__);
    return $meta;
}
Пример #8
0
 protected function _save($image, $filename = null, $mime_type = null)
 {
     global $ewww_debug;
     if (!defined('EWWW_IMAGE_OPTIMIZER_DOMAIN')) {
         require_once plugin_dir_path(__FILE__) . 'ewww-image-optimizer.php';
     }
     if (!defined('EWWW_IMAGE_OPTIMIZER_JPEGTRAN')) {
         ewww_image_optimizer_init();
     }
     list($filename, $extension, $mime_type) = $this->get_output_format($filename, $mime_type);
     if (!$filename) {
         $filename = $this->generate_filename(null, null, $extension);
     }
     try {
         // Store initial Format
         $orig_format = $this->image->getimageformat();
         $this->image->setimageformat(strtoupper($this->get_extension($mime_type)));
         $this->make_image($filename, array($image, 'writeImage'), array($filename));
         // Reset original Format
         $this->image->setimageformat($orig_format);
     } catch (Exception $e) {
         return new WP_Error('image_save_error', $e->getMessage(), $filename);
     }
     // Set correct file permissions
     $stat = stat(dirname($filename));
     $perms = $stat['mode'] & 0666;
     //same permissions as parent folder, strip off the executable bits
     @chmod($filename, $perms);
     ewww_image_optimizer_aux_images_loop($filename, true);
     $ewww_debug = "{$ewww_debug} image editor (gmagick) saved : {$filename} <br>";
     $image_size = filesize($filename);
     $ewww_debug = "{$ewww_debug} image editor size: {$image_size} <br>";
     ewww_image_optimizer_debug_log();
     $ewww_debug = '';
     return array('path' => $filename, 'file' => wp_basename(apply_filters('image_make_intermediate_size', $filename)), 'width' => $this->size['width'], 'height' => $this->size['height'], 'mime-type' => $mime_type);
 }
Пример #9
0
function ewww_image_optimizer_aux_images_script($hook)
{
    // make sure we are being called from the proper page
    if ('ewww-image-optimizer-auto' !== $hook && empty($_REQUEST['scan'])) {
        return;
    }
    global $ewww_debug;
    global $wpdb;
    $ewww_debug .= "<b>ewww_image_optimizer_aux_images_script()</b><br>";
    // initialize the $attachments variable for auxiliary images
    $attachments = null;
    // check the 'bulk resume' option
    $resume = get_option('ewww_image_optimizer_aux_resume');
    // check if there is a previous bulk operation to resume
    if (!empty($resume)) {
        // retrieve the attachment IDs that have not been finished from the 'bulk attachments' option
        $attachments = get_option('ewww_image_optimizer_aux_attachments');
    } else {
        // collect a list of images from the current theme
        $child_path = get_stylesheet_directory();
        $parent_path = get_template_directory();
        $attachments = ewww_image_optimizer_image_scan($child_path);
        if ($child_path !== $parent_path) {
            $attachments = array_merge($attachments, ewww_image_optimizer_image_scan($parent_path));
        }
        // collect a list of images in auxiliary folders provided by user
        if ($aux_paths = ewww_image_optimizer_get_option('ewww_image_optimizer_aux_paths')) {
            foreach ($aux_paths as $aux_path) {
                $attachments = array_merge($attachments, ewww_image_optimizer_image_scan($aux_path));
            }
        }
        // collect a list of images for buddypress
        if (is_plugin_active('buddypress/bp-loader.php') || function_exists('is_plugin_active_for_network') && is_plugin_active_for_network('buddypress/bp-loader.php')) {
            // get the value of the wordpress upload directory
            $upload_dir = wp_upload_dir();
            // scan the 'avatars' and 'group-avatars' folders for images
            $attachments = array_merge($attachments, ewww_image_optimizer_image_scan($upload_dir['basedir'] . '/avatars'), ewww_image_optimizer_image_scan($upload_dir['basedir'] . '/group-avatars'));
        }
        if (is_plugin_active('buddypress-activity-plus/bpfb.php') || function_exists('is_plugin_active_for_network') && is_plugin_active_for_network('buddypress-activity-plus/bpfb.php')) {
            // get the value of the wordpress upload directory
            $upload_dir = wp_upload_dir();
            // scan the 'avatars' and 'group-avatars' folders for images
            $attachments = array_merge($attachments, ewww_image_optimizer_image_scan($upload_dir['basedir'] . '/bpfb'));
        }
        if (is_plugin_active('wp-symposium/wp-symposium.php') || function_exists('is_plugin_active_for_network') && is_plugin_active_for_network('wp-symposium/wp-symposium.php')) {
            $attachments = array_merge($attachments, ewww_image_optimizer_image_scan(get_option('symposium_img_path')));
        }
        if (is_plugin_active('ml-slider/ml-slider.php') || function_exists('is_plugin_active_for_network') && is_plugin_active_for_network('ml-slider/ml-slider.php')) {
            $slide_paths = array();
            $sliders = get_posts(array('numberposts' => -1, 'post_type' => 'ml-slider', 'post_status' => 'any', 'fields' => 'ids'));
            foreach ($sliders as $slider) {
                $slides = get_posts(array('numberposts' => -1, 'orderby' => 'menu_order', 'order' => 'ASC', 'post_type' => 'attachment', 'post_status' => 'inherit', 'fields' => 'ids', 'tax_query' => array(array('taxonomy' => 'ml-slider', 'field' => 'slug', 'terms' => $slider))));
                foreach ($slides as $slide) {
                    $backup_sizes = get_post_meta($slide, '_wp_attachment_backup_sizes', true);
                    $type = get_post_meta($slide, 'ml-slider_type', true);
                    $type = $type ? $type : 'image';
                    // backwards compatibility, fall back to 'image'
                    if ($type === 'image') {
                        foreach ($backup_sizes as $backup_size => $meta) {
                            if (preg_match('/resized-/', $backup_size)) {
                                $path = $meta['path'];
                                $image_size = filesize($path);
                                $query = $wpdb->prepare("SELECT id FROM {$wpdb->ewwwio_images} WHERE BINARY path LIKE %s AND image_size LIKE '{$image_size}'", $path);
                                $already_optimized = $wpdb->get_results($query);
                                $mimetype = ewww_image_optimizer_mimetype($path, 'i');
                                if (preg_match('/^image\\/(jpeg|png|gif)/', $mimetype) && empty($already_optimized)) {
                                    $slide_paths[] = $path;
                                }
                            }
                        }
                    }
                }
            }
            $attachments = array_merge($attachments, $slide_paths);
        }
        // store the filenames we retrieved in the 'bulk_attachments' option so we can keep track of our progress in the database
        update_option('ewww_image_optimizer_aux_attachments', $attachments);
    }
    ewww_image_optimizer_debug_log();
    // submit a couple variables to the javascript to work with
    $attachments = json_encode($attachments);
    if (!empty($_REQUEST['scan'])) {
        if (empty($attachments)) {
            _e('Nothing to optimize', EWWW_IMAGE_OPTIMIZER_DOMAIN);
        } else {
            echo $attachments;
        }
        die;
    } else {
        return;
    }
}
Пример #10
0
 function generate_image_size($image, $size, $params = null, $skip_defaults = false)
 {
     global $ewww_debug;
     if (!defined('EWWW_IMAGE_OPTIMIZER_CLOUD')) {
         ewww_image_optimizer_init();
     }
     $success = $this->call_parent('generate_image_size', $image, $size, $params, $skip_defaults);
     if ($success) {
         //$filename = $this->object->get_image_abspath($image, $size);
         $filename = $success->fileName;
         ewww_image_optimizer_aux_images_loop($filename, true);
         $ewww_debug .= "nextgen dynamic thumb saved: {$filename} <br>";
         $image_size = filesize($filename);
         $ewww_debug .= "optimized size: {$image_size} <br>";
     }
     ewww_image_optimizer_debug_log();
     ewwwio_memory(__FUNCTION__);
     return $success;
 }
Пример #11
0
function ewww_image_optimizer_aux_images_script($hook)
{
    ewwwio_debug_message('<b>' . __FUNCTION__ . '()</b>');
    // make sure we are being called from the proper page
    if ('ewww-image-optimizer-auto' !== $hook && empty($_REQUEST['ewww_scan'])) {
        return;
    }
    session_write_close();
    global $wpdb;
    if (!empty($_REQUEST['ewww_force'])) {
        ewwwio_debug_message('forcing re-optimize: true');
    }
    // initialize the $attachments variable for auxiliary images
    $attachments = null;
    // check the 'bulk resume' option
    $resume = get_option('ewww_image_optimizer_aux_resume');
    // check if there is a previous bulk operation to resume
    if (!empty($resume)) {
        ewwwio_debug_message('resuming from where we left off, no scanning needed');
        // retrieve the attachment IDs that have not been finished from the 'bulk attachments' option
        $attachments = get_option('ewww_image_optimizer_aux_attachments');
    } else {
        ewwwio_debug_message('getting fresh list of files to optimize');
        $attachments = array();
        // collect a list of images from the current theme
        $child_path = get_stylesheet_directory();
        $parent_path = get_template_directory();
        $attachments = ewww_image_optimizer_image_scan($child_path);
        if ($child_path !== $parent_path) {
            $attachments = array_merge($attachments, ewww_image_optimizer_image_scan($parent_path));
        }
        if (!function_exists('is_plugin_active')) {
            // need to include the plugin library for the is_plugin_active function
            require_once ABSPATH . 'wp-admin/includes/plugin.php';
        }
        // collect a list of images for buddypress
        if (is_plugin_active('buddypress/bp-loader.php') || is_plugin_active_for_network('buddypress/bp-loader.php')) {
            // get the value of the wordpress upload directory
            $upload_dir = wp_upload_dir();
            // scan the 'avatars' and 'group-avatars' folders for images
            $attachments = array_merge($attachments, ewww_image_optimizer_image_scan($upload_dir['basedir'] . '/avatars'), ewww_image_optimizer_image_scan($upload_dir['basedir'] . '/group-avatars'));
        }
        if (is_plugin_active('buddypress-activity-plus/bpfb.php') || is_plugin_active_for_network('buddypress-activity-plus/bpfb.php')) {
            // get the value of the wordpress upload directory
            $upload_dir = wp_upload_dir();
            // scan the 'avatars' and 'group-avatars' folders for images
            $attachments = array_merge($attachments, ewww_image_optimizer_image_scan($upload_dir['basedir'] . '/bpfb'));
        }
        if (is_plugin_active('grand-media/grand-media.php') || is_plugin_active_for_network('grand-media/grand-media.php')) {
            // scan the grand media folder for images
            $attachments = array_merge($attachments, ewww_image_optimizer_image_scan(WP_CONTENT_DIR . '/grand-media'));
        }
        if (is_plugin_active('wp-symposium/wp-symposium.php') || is_plugin_active_for_network('wp-symposium/wp-symposium.php')) {
            $attachments = array_merge($attachments, ewww_image_optimizer_image_scan(get_option('symposium_img_path')));
        }
        if (is_plugin_active('ml-slider/ml-slider.php') || is_plugin_active_for_network('ml-slider/ml-slider.php')) {
            $slide_paths = array();
            $slides = $wpdb->get_col("\n\t\t\t\tSELECT wpposts.ID \n\t\t\t\tFROM {$wpdb->posts} wpposts \n\t\t\t\tINNER JOIN {$wpdb->term_relationships} term_relationships\n\t\t\t\t\t\tON wpposts.ID = term_relationships.object_id\n\t\t\t\tINNER JOIN {$wpdb->terms} wpterms \n\t\t\t\t\t\tON term_relationships.term_taxonomy_id = wpterms.term_id\n\t\t\t\tINNER JOIN {$wpdb->term_taxonomy} term_taxonomy\n\t\t\t\t\t\tON wpterms.term_id = term_taxonomy.term_id\n\t\t\t\tWHERE \tterm_taxonomy.taxonomy = 'ml-slider'\n\t\t\t\t\tAND wpposts.post_type = 'attachment'\n\t\t\t\t");
            foreach ($slides as $slide) {
                $backup_sizes = get_post_meta($slide, '_wp_attachment_backup_sizes', true);
                $type = get_post_meta($slide, 'ml-slider_type', true);
                $type = $type ? $type : 'image';
                // backwards compatibility, fall back to 'image'
                if ($type === 'image') {
                    foreach ($backup_sizes as $backup_size => $meta) {
                        if (preg_match('/resized-/', $backup_size)) {
                            $path = $meta['path'];
                            $image_size = ewww_image_optimizer_filesize($path);
                            if (!$image_size) {
                                continue;
                            }
                            $already_optimized = ewww_image_optimizer_find_already_optimized($path);
                            $mimetype = ewww_image_optimizer_mimetype($path, 'i');
                            if (preg_match('/^image\\/(jpeg|png|gif)/', $mimetype) && empty($already_optimized)) {
                                $slide_paths[] = $path;
                            }
                        }
                    }
                }
            }
            $attachments = array_merge($attachments, $slide_paths);
        }
        // collect a list of images in auxiliary folders provided by user
        if ($aux_paths = ewww_image_optimizer_get_option('ewww_image_optimizer_aux_paths')) {
            foreach ($aux_paths as $aux_path) {
                $attachments = array_merge($attachments, ewww_image_optimizer_image_scan($aux_path));
            }
        }
        // scan images in two most recent media library folders if the option is enabled, and this is a scheduled optimization
        if ('ewww-image-optimizer-auto' == $hook && ewww_image_optimizer_get_option('ewww_image_optimizer_include_media_paths')) {
            // retrieve the location of the wordpress upload folder
            $upload_dir = wp_upload_dir();
            // retrieve the path of the upload folder
            $upload_path = $upload_dir['basedir'];
            $this_month = date('m');
            $this_year = date('Y');
            $attachments = array_merge($attachments, ewww_image_optimizer_image_scan("{$upload_path}/{$this_year}/{$this_month}/"));
            if (class_exists('DateTime')) {
                $date = new DateTime();
                $date->sub(new DateInterval('P1M'));
                $last_year = $date->format('Y');
                $last_month = $date->format('m');
                $attachments = array_merge($attachments, ewww_image_optimizer_image_scan("{$upload_path}/{$last_year}/{$last_month}/"));
            }
        }
        // store the filenames we retrieved in the 'bulk_attachments' option so we can keep track of our progress in the database
        update_option('ewww_image_optimizer_aux_attachments', $attachments);
        ewwwio_debug_message('found ' . count($attachments) . ' images to optimize while scanning');
    }
    ewww_image_optimizer_debug_log();
    if (!empty($_REQUEST['ewww_scan'])) {
        echo count($attachments);
        ewwwio_memory(__FUNCTION__);
        die;
    } else {
        ewwwio_memory(__FUNCTION__);
        return;
    }
}
Пример #12
0
function ewww_image_optimizer_webp_loop()
{
    ewwwio_debug_message('<b>' . __FUNCTION__ . '()</b>');
    $permissions = apply_filters('ewww_image_optimizer_admin_permissions', '');
    if (!wp_verify_nonce($_REQUEST['ewww_wpnonce'], 'ewww-image-optimizer-webp') || !current_user_can($permissions)) {
        wp_die(esc_html__('Access token has expired, please reload the page.', EWWW_IMAGE_OPTIMIZER_DOMAIN));
    }
    // retrieve the time when the migration starts
    $started = microtime(true);
    // allow 50 seconds for each loop
    set_time_limit(50);
    $images = array();
    ewwwio_debug_message('renaming images now');
    $images_processed = 0;
    $images_skipped = '';
    $images = get_option('ewww_image_optimizer_webp_images');
    if ($images) {
        printf(esc_html__('%d Webp images left to rename.', EWWW_IMAGE_OPTIMIZER_DOMAIN), count($images));
        echo "<br>";
    }
    while ($images) {
        $images_processed++;
        ewwwio_debug_message("processed {$images_processed} images so far");
        if ($images_processed > 1000) {
            ewwwio_debug_message('hit 1000, breaking loop');
            break;
        }
        $image = array_pop($images);
        $replace_base = '';
        $skip = true;
        $pngfile = preg_replace('/webp$/', 'png', $image);
        $PNGfile = preg_replace('/webp$/', 'PNG', $image);
        $jpgfile = preg_replace('/webp$/', 'jpg', $image);
        $jpegfile = preg_replace('/webp$/', 'jpeg', $image);
        $JPGfile = preg_replace('/webp$/', 'JPG', $image);
        if (file_exists($pngfile)) {
            $replace_base = $pngfile;
            $skip = false;
        }
        if (file_exists($PNGfile)) {
            if (empty($replace_base)) {
                $replace_base = $PNGfile;
                $skip = false;
            } else {
                $skip = true;
            }
        }
        if (file_exists($jpgfile)) {
            if (empty($replace_base)) {
                $replace_base = $jpgfile;
                $skip = false;
            } else {
                $skip = true;
            }
        }
        if (file_exists($jpegfile)) {
            if (empty($replace_base)) {
                $replace_base = $jpegfile;
                $skip = false;
            } else {
                $skip = true;
            }
        }
        if (file_exists($JPGfile)) {
            if (empty($replace_base)) {
                $replace_base = $JPGfile;
                $skip = false;
            } else {
                $skip = true;
            }
        }
        if ($skip) {
            if ($replace_base) {
                ewwwio_debug_message("multiple replacement options for {$image}, not renaming");
            } else {
                ewwwio_debug_message("no match found for {$image}, strange...");
            }
            $images_skipped .= "{$image}<br>";
        } else {
            ewwwio_debug_message("renaming {$image} with match of {$replace_base}");
            rename($image, $replace_base . '.webp');
        }
    }
    if ($images_skipped) {
        update_option('ewww_image_optimizer_webp_skipped', get_option('ewww_image_optimizer_webp_skipped') . $images_skipped);
    }
    // calculate how much time has elapsed since we started
    $elapsed = microtime(true) - $started;
    ewwwio_debug_message("took {$elapsed} seconds this time around");
    // store the updated list of images back in the database
    update_option('ewww_image_optimizer_webp_images', $images);
    ewww_image_optimizer_debug_log();
    die;
}
Пример #13
0
function ewww_image_optimizer_aux_images_script($hook)
{
    // make sure we are being called from the proper page
    if ('ewww-image-optimizer-auto' !== $hook && empty($_REQUEST['ewww_scan'])) {
        return;
    }
    global $ewww_debug;
    global $wpdb;
    $ewww_debug .= "<b>ewww_image_optimizer_aux_images_script()</b><br>";
    if (!empty($_REQUEST['ewww_force'])) {
        $ewww_debug .= "forcing re-optimize: true<br>";
    }
    // initialize the $attachments variable for auxiliary images
    $attachments = null;
    // check the 'bulk resume' option
    $resume = get_option('ewww_image_optimizer_aux_resume');
    // check if there is a previous bulk operation to resume
    if (!empty($resume)) {
        // retrieve the attachment IDs that have not been finished from the 'bulk attachments' option
        $attachments = get_option('ewww_image_optimizer_aux_attachments');
    } else {
        $attachments = array();
        // collect a list of images from the current theme
        $child_path = get_stylesheet_directory();
        $parent_path = get_template_directory();
        $attachments = ewww_image_optimizer_image_scan($child_path);
        if ($child_path !== $parent_path) {
            $attachments = array_merge($attachments, ewww_image_optimizer_image_scan($parent_path));
        }
        if (!function_exists('is_plugin_active')) {
            // need to include the plugin library for the is_plugin_active function
            require_once ABSPATH . 'wp-admin/includes/plugin.php';
        }
        // collect a list of images for buddypress
        if (is_plugin_active('buddypress/bp-loader.php') || function_exists('is_plugin_active_for_network') && is_plugin_active_for_network('buddypress/bp-loader.php')) {
            // get the value of the wordpress upload directory
            $upload_dir = wp_upload_dir();
            // scan the 'avatars' and 'group-avatars' folders for images
            $attachments = array_merge($attachments, ewww_image_optimizer_image_scan($upload_dir['basedir'] . '/avatars'), ewww_image_optimizer_image_scan($upload_dir['basedir'] . '/group-avatars'));
        }
        if (is_plugin_active('buddypress-activity-plus/bpfb.php') || function_exists('is_plugin_active_for_network') && is_plugin_active_for_network('buddypress-activity-plus/bpfb.php')) {
            // get the value of the wordpress upload directory
            $upload_dir = wp_upload_dir();
            // scan the 'avatars' and 'group-avatars' folders for images
            $attachments = array_merge($attachments, ewww_image_optimizer_image_scan($upload_dir['basedir'] . '/bpfb'));
        }
        if (is_plugin_active('grand-media/grand-media.php') || function_exists('is_plugin_active_for_network') && is_plugin_active_for_network('grand-media/grand-media.php')) {
            // scan the grand media folder for images
            $attachments = array_merge($attachments, ewww_image_optimizer_image_scan(WP_CONTENT_DIR . '/grand-media'));
        }
        if (is_plugin_active('wp-symposium/wp-symposium.php') || function_exists('is_plugin_active_for_network') && is_plugin_active_for_network('wp-symposium/wp-symposium.php')) {
            $attachments = array_merge($attachments, ewww_image_optimizer_image_scan(get_option('symposium_img_path')));
        }
        if (is_plugin_active('ml-slider/ml-slider.php') || function_exists('is_plugin_active_for_network') && is_plugin_active_for_network('ml-slider/ml-slider.php')) {
            $slide_paths = array();
            $sliders = get_posts(array('numberposts' => -1, 'post_type' => 'ml-slider', 'post_status' => 'any', 'fields' => 'ids'));
            foreach ($sliders as $slider) {
                $slides = get_posts(array('numberposts' => -1, 'orderby' => 'menu_order', 'order' => 'ASC', 'post_type' => 'attachment', 'post_status' => 'inherit', 'fields' => 'ids', 'tax_query' => array(array('taxonomy' => 'ml-slider', 'field' => 'slug', 'terms' => $slider))));
                foreach ($slides as $slide) {
                    $backup_sizes = get_post_meta($slide, '_wp_attachment_backup_sizes', true);
                    $type = get_post_meta($slide, 'ml-slider_type', true);
                    $type = $type ? $type : 'image';
                    // backwards compatibility, fall back to 'image'
                    if ($type === 'image') {
                        foreach ($backup_sizes as $backup_size => $meta) {
                            if (preg_match('/resized-/', $backup_size)) {
                                $path = $meta['path'];
                                $image_size = filesize($path);
                                $query = $wpdb->prepare("SELECT id FROM {$wpdb->ewwwio_images} WHERE path LIKE %s AND image_size LIKE '{$image_size}'", $path);
                                $optimized_query = $wpdb->get_results($query, ARRAY_A);
                                if (!empty($optimized_query)) {
                                    foreach ($optimized_query as $image) {
                                        if ($image['path'] != $path) {
                                            $ewww_debug .= "{$image['path']} does not match {$path}, continuing our search<br>";
                                        } else {
                                            $already_optimized = $image;
                                        }
                                    }
                                }
                                $mimetype = ewww_image_optimizer_mimetype($path, 'i');
                                if (preg_match('/^image\\/(jpeg|png|gif)/', $mimetype) && empty($already_optimized)) {
                                    $slide_paths[] = $path;
                                }
                            }
                        }
                    }
                }
            }
            $attachments = array_merge($attachments, $slide_paths);
        }
        // collect a list of images in auxiliary folders provided by user
        if ($aux_paths = ewww_image_optimizer_get_option('ewww_image_optimizer_aux_paths')) {
            foreach ($aux_paths as $aux_path) {
                $attachments = array_merge($attachments, ewww_image_optimizer_image_scan($aux_path));
            }
        }
        // scan images in two most recent media library folders if the option is enabled, and this is a scheduled optimization
        if ('ewww-image-optimizer-auto' == $hook && ewww_image_optimizer_get_option('ewww_image_optimizer_include_media_paths')) {
            // retrieve the location of the wordpress upload folder
            $upload_dir = wp_upload_dir();
            // retrieve the path of the upload folder
            $upload_path = $upload_dir['basedir'];
            $this_month = date('m');
            $this_year = date('Y');
            $attachments = array_merge($attachments, ewww_image_optimizer_image_scan("{$upload_path}/{$this_year}/{$this_month}/"));
            if (class_exists('DateTime')) {
                $date = new DateTime();
                $date->sub(new DateInterval('P1M'));
                $last_year = $date->format('Y');
                $last_month = $date->format('m');
                $attachments = array_merge($attachments, ewww_image_optimizer_image_scan("{$upload_path}/{$last_year}/{$last_month}/"));
            }
        }
        // store the filenames we retrieved in the 'bulk_attachments' option so we can keep track of our progress in the database
        update_option('ewww_image_optimizer_aux_attachments', $attachments);
    }
    ewww_image_optimizer_debug_log();
    // submit a couple variables to the javascript to work with
    $attachments = json_encode($attachments);
    if (!empty($_REQUEST['ewww_scan'])) {
        if (empty($attachments)) {
            _e('Nothing to optimize', EWWW_IMAGE_OPTIMIZER_DOMAIN);
        } else {
            echo $attachments;
        }
        ewwwio_memory(__FUNCTION__);
        die;
    } else {
        ewwwio_memory(__FUNCTION__);
        return;
    }
}
Пример #14
0
 /**
  * Cancel Process
  *
  * Stop processing queue items, clear cronjob and delete batch.
  *
  */
 public function cancel_process()
 {
     ewwwio_debug_message('cancelling background process');
     if (!$this->is_queue_empty()) {
         $batch = $this->get_batch();
         ewwwio_debug_message('retrieved key ' . $batch->key);
         $this->delete($batch->key);
         wp_clear_scheduled_hook($this->cron_hook_identifier);
     }
     ewww_image_optimizer_debug_log();
 }
Пример #15
0
function ewww_image_optimizer_savings_loop()
{
    // verify that an authorized user has started the optimizer
    if (!wp_verify_nonce($_REQUEST['ewww_wpnonce'], 'ewww-image-optimizer-settings')) {
        wp_die(__('Cheatin&#8217; eh?', EWWW_IMAGE_OPTIMIZER_DOMAIN));
    }
    global $ewww_debug;
    global $wpdb;
    if ($_REQUEST['ewww_savings_todo'] < 1000) {
        $records_needed = $_REQUEST['ewww_savings_todo'];
    } else {
        $records_needed = 1000;
    }
    if (function_exists('is_plugin_active_for_network') && is_plugin_active_for_network(EWWW_IMAGE_OPTIMIZER_PLUGIN_FILE_REL)) {
        if (function_exists('wp_get_sites')) {
            add_filter('wp_is_large_network', 'ewww_image_optimizer_large_network', 20, 0);
            $blogs = wp_get_sites(array('network_id' => $wpdb->siteid, 'limit' => 10000));
            remove_filter('wp_is_large_network', 'ewww_image_optimizer_large_network', 20, 0);
        } else {
            $query = "SELECT blog_id FROM {$wpdb->blogs} WHERE site_id = '{$wpdb->siteid}' ";
            $blogs = $wpdb->get_results($query, ARRAY_A);
        }
        $total_savings = 0;
        $savings_done = $_REQUEST['ewww_savings_counter'];
        foreach ($blogs as $blog) {
            switch_to_blog($blog['blog_id']);
            $total_query = "SELECT orig_size-image_size FROM {$wpdb->ewwwio_images} LIMIT {$_REQUEST['ewww_savings_counter']}, {$records_needed}";
            $ewww_debug .= "querying {$records_needed} records, starting at {$_REQUEST['ewww_savings_counter']}<br>";
            $savings = $wpdb->get_results($total_query, ARRAY_N);
            $records_needed -= count($savings);
            foreach ($savings as $saved) {
                $total_savings += $saved[0];
            }
            if ($records_needed) {
                $savings_done -= $wpdb->get_var("SELECT COUNT(id) FROM {$wpdb->ewwwio_images}");
            } else {
                break;
            }
        }
        restore_current_blog();
    } else {
        $total_query = "SELECT orig_size-image_size FROM {$wpdb->ewwwio_images} LIMIT {$_REQUEST['ewww_savings_counter']}, {$records_needed}";
        $ewww_debug .= "querying {$records_needed} records, starting at {$_REQUEST['ewww_savings_counter']}<br>";
        $savings = $wpdb->get_results($total_query, ARRAY_N);
        $total_savings = 0;
        foreach ($savings as $saved) {
            $total_savings += $saved[0];
        }
    }
    ewww_image_optimizer_debug_log();
    echo $total_savings;
    ewwwio_memory(__FUNCTION__);
    die;
}
Пример #16
0
 function ewww_added_new_image_slow($image)
 {
     ewwwio_debug_message('<b>' . __FUNCTION__ . '()</b>');
     // make sure the image path is set
     if (isset($image->imagePath)) {
         // optimize the full size
         $res = ewww_image_optimizer($image->imagePath, 3, false, false, true);
         // optimize the web optimized version
         $wres = ewww_image_optimizer($image->webimagePath, 3, false, true);
         // optimize the thumbnail
         $tres = ewww_image_optimizer($image->thumbPath, 3, false, true);
         if (!class_exists('flagMeta')) {
             require_once FLAG_ABSPATH . 'lib/meta.php';
         }
         // retrieve the metadata for the image ID
         $pid = $image->pid;
         $meta = new flagMeta($pid);
         //			ewwwio_debug_message( print_r( $meta->image->meta_data, TRUE ) );
         $meta->image->meta_data['ewww_image_optimizer'] = $res[1];
         if (!empty($meta->image->meta_data['webview'])) {
             $meta->image->meta_data['webview']['ewww_image_optimizer'] = $wres[1];
         }
         $meta->image->meta_data['thumbnail']['ewww_image_optimizer'] = $tres[1];
         // update the image metadata in the db
         flagdb::update_image_meta($pid, $meta->image->meta_data);
     }
     ewww_image_optimizer_debug_log();
 }
Пример #17
0
function ewww_image_optimizer_webp_loop()
{
    global $ewww_debug;
    // verify that an authorized user has started the migration
    if (!wp_verify_nonce($_REQUEST['ewww_wpnonce'], 'ewww-image-optimizer-webp') || !current_user_can('edit_others_posts')) {
        wp_die(__('Cheatin&#8217; eh?', EWWW_IMAGE_OPTIMIZER_DOMAIN));
    }
    // retrieve the time when the migration starts
    $started = microtime(true);
    // allow 50 seconds for each loop
    set_time_limit(50);
    $images = array();
    $ewww_debug .= 'renaming images now<br>';
    $images_processed = 0;
    $images_skipped = '';
    $images = get_option('ewww_image_optimizer_webp_images');
    if ($images) {
        printf(__('%d Webp images left to rename.', EWWW_IMAGE_OPTIMIZER_DOMAIN), count($images));
        echo "<br>";
    }
    while ($images) {
        $images_processed++;
        $ewww_debug .= "processed {$images_processed} images so far<br>";
        if ($images_processed > 1000) {
            $ewww_debug .= "hit 1000, breaking loop";
            break;
        }
        $image = array_pop($images);
        $replace_base = '';
        $skip = true;
        $pngfile = preg_replace('/webp$/', 'png', $image);
        $PNGfile = preg_replace('/webp$/', 'PNG', $image);
        $jpgfile = preg_replace('/webp$/', 'jpg', $image);
        $jpegfile = preg_replace('/webp$/', 'jpeg', $image);
        $JPGfile = preg_replace('/webp$/', 'JPG', $image);
        if (file_exists($pngfile)) {
            $replace_base = $pngfile;
            $skip = false;
        }
        if (file_exists($PNGfile)) {
            if (empty($replace_base)) {
                $replace_base = $PNGfile;
                $skip = false;
            } else {
                $skip = true;
            }
        }
        if (file_exists($jpgfile)) {
            if (empty($replace_base)) {
                $replace_base = $jpgfile;
                $skip = false;
            } else {
                $skip = true;
            }
        }
        if (file_exists($jpegfile)) {
            if (empty($replace_base)) {
                $replace_base = $jpegfile;
                $skip = false;
            } else {
                $skip = true;
            }
        }
        if (file_exists($JPGfile)) {
            if (empty($replace_base)) {
                $replace_base = $JPGfile;
                $skip = false;
            } else {
                $skip = true;
            }
        }
        if ($skip) {
            if ($replace_base) {
                $ewww_debug .= "multiple replacement options for {$image}, not renaming<br>";
            } else {
                $ewww_debug .= "no match found for {$image}, strange...<br>";
            }
            $images_skipped .= "{$image}<br>";
        } else {
            $ewww_debug .= "renaming {$image} with match of {$replace_base}<br>";
            rename($image, $replace_base . '.webp');
        }
    }
    if ($images_skipped) {
        update_option('ewww_image_optimizer_webp_skipped', get_option('ewww_image_optimizer_webp_skipped') . $images_skipped);
    }
    // calculate how much time has elapsed since we started
    $elapsed = microtime(true) - $started;
    $ewww_debug .= "took {$elapsed} seconds this time around<br>";
    // store the updated list of images back in the database
    update_option('ewww_image_optimizer_webp_images', $images);
    //	$ewww_debug .= "peak memory usage: " . memory_get_peak_usage(true) . "<br>";
    ewww_image_optimizer_debug_log();
    die;
}
 function ewww_ngg_manual()
 {
     // check permission of current user
     $permissions = apply_filters('ewww_image_optimizer_manual_permissions', '');
     if (FALSE === current_user_can($permissions)) {
         wp_die(__('You don\'t have permission to work with uploaded files.', EWWW_IMAGE_OPTIMIZER_DOMAIN));
     }
     // make sure function wasn't called without an attachment to work with
     if (FALSE === isset($_GET['ewww_attachment_ID'])) {
         wp_die(__('No attachment ID was provided.', EWWW_IMAGE_OPTIMIZER_DOMAIN));
     }
     // store the attachment $id
     $id = intval($_GET['ewww_attachment_ID']);
     $this->ewww_ngg_optimize($id);
     ewww_image_optimizer_debug_log();
     // get the referring page, and send the user back there
     $sendback = wp_get_referer();
     $sendback = preg_replace('|[^a-z0-9-~+_.?#=&;,/:]|i', '', $sendback);
     wp_redirect($sendback);
     exit(0);
 }
Пример #19
0
 function generate_image_size($image, $size, $params = null, $skip_defaults = false)
 {
     ewwwio_debug_message('<b>' . __FUNCTION__ . '()</b>');
     global $ewww_defer;
     if (!defined('EWWW_IMAGE_OPTIMIZER_CLOUD')) {
         ewww_image_optimizer_init();
     }
     $success = $this->call_parent('generate_image_size', $image, $size, $params, $skip_defaults);
     if ($success) {
         $filename = $success->fileName;
         if ($ewww_defer && ewww_image_optimizer_get_option('ewww_image_optimizer_defer')) {
             ewww_image_optimizer_add_deferred_attachment("file,{$filename}");
             return $saved;
         }
         ewww_image_optimizer($filename);
         ewwwio_debug_message("nextgen dynamic thumb saved: {$filename}");
         $image_size = ewww_image_optimizer_filesize($filename);
         ewwwio_debug_message("optimized size: {$image_size}");
     }
     ewww_image_optimizer_debug_log();
     ewwwio_memory(__FUNCTION__);
     return $success;
 }
Пример #20
0
function ewww_image_optimizer_bulk_loop()
{
    ewwwio_debug_message('<b>' . __FUNCTION__ . '()</b>');
    global $ewww_defer;
    $ewww_defer = false;
    $output = array();
    // verify that an authorized user has started the optimizer
    $permissions = apply_filters('ewww_image_optimizer_bulk_permissions', '');
    if (!wp_verify_nonce($_REQUEST['ewww_wpnonce'], 'ewww-image-optimizer-bulk') || !current_user_can($permissions)) {
        $output['error'] = esc_html__('Access token has expired, please reload the page.', EWWW_IMAGE_OPTIMIZER_DOMAIN);
        echo json_encode($output);
        die;
    }
    session_write_close();
    // retrieve the time when the optimizer starts
    $started = microtime(true);
    if (ewww_image_optimizer_stl_check() && ini_get('max_execution_time')) {
        set_time_limit(0);
    }
    // find out if our nonce is on it's last leg/tick
    $tick = wp_verify_nonce($_REQUEST['ewww_wpnonce'], 'ewww-image-optimizer-bulk');
    if ($tick === 2) {
        $output['new_nonce'] = wp_create_nonce('ewww-image-optimizer-bulk');
    } else {
        $output['new_nonce'] = '';
    }
    // get the 'bulk attachments' with a list of IDs remaining
    $attachments = get_option('ewww_image_optimizer_bulk_attachments');
    $attachment = array_shift($attachments);
    $meta = wp_get_attachment_metadata($attachment, true);
    // do the optimization for the current attachment (including resizes)
    $meta = ewww_image_optimizer_resize_from_meta_data($meta, $attachment, false);
    $ewww_status = get_transient('ewww_image_optimizer_cloud_status');
    if (!empty($ewww_status) && preg_match('/exceeded/', $ewww_status)) {
        $output['error'] = esc_html__('License Exceeded', EWWW_IMAGE_OPTIMIZER_DOMAIN);
        echo json_encode($output);
        die;
    }
    if (!empty($meta['file'])) {
        // output the filename (and path relative to 'uploads' folder)
        $output['results'] = sprintf("<p>" . esc_html__('Optimized', EWWW_IMAGE_OPTIMIZER_DOMAIN) . " <strong>%s</strong><br>", esc_html($meta['file']));
    } else {
        $output['results'] = sprintf("<p>" . esc_html__('Skipped image, ID:', EWWW_IMAGE_OPTIMIZER_DOMAIN) . " <strong>%s</strong><br>", esc_html($attachment));
    }
    if (!empty($meta['ewww_image_optimizer'])) {
        // tell the user what the results were for the original image
        $output['results'] .= sprintf(esc_html__('Full size – %s', EWWW_IMAGE_OPTIMIZER_DOMAIN) . "<br>", esc_html($meta['ewww_image_optimizer']));
    }
    // check to see if there are resized version of the image
    if (isset($meta['sizes']) && is_array($meta['sizes'])) {
        // cycle through each resize
        foreach ($meta['sizes'] as $size) {
            if (!empty($size['ewww_image_optimizer'])) {
                // output the results for the current resized version
                $output['results'] .= sprintf("%s – %s<br>", esc_html($size['file']), esc_html($size['ewww_image_optimizer']));
            }
        }
    }
    // calculate how much time has elapsed since we started
    $elapsed = microtime(true) - $started;
    // output how much time has elapsed since we started
    $output['results'] .= sprintf(esc_html__('Elapsed: %.3f seconds', EWWW_IMAGE_OPTIMIZER_DOMAIN) . "</p>", $elapsed);
    global $ewww_attachment;
    $ewww_attachment['id'] = $attachment;
    $ewww_attachment['meta'] = $meta;
    add_filter('w3tc_cdn_update_attachment_metadata', 'ewww_image_optimizer_w3tc_update_files');
    // update the metadata for the current attachment
    wp_update_attachment_metadata($attachment, $meta);
    // store the updated list of attachment IDs back in the 'bulk_attachments' option
    update_option('ewww_image_optimizer_bulk_attachments', $attachments);
    if (ewww_image_optimizer_get_option('ewww_image_optimizer_debug')) {
        global $ewww_debug;
        $output['results'] .= '<div style="background-color:#ffff99;">' . $ewww_debug . '</div>';
    }
    if (!empty($attachments)) {
        $next_attachment = array_shift($attachments);
        $next_file = ewww_image_optimizer_bulk_filename($next_attachment);
        // generate the WP spinner image for display
        $loading_image = plugins_url('/images/wpspin.gif', __FILE__);
        if ($next_file) {
            $output['next_file'] = "<p>" . esc_html__('Optimizing', EWWW_IMAGE_OPTIMIZER_DOMAIN) . " <b>{$next_file}</b>&nbsp;<img src='{$loading_image}' /></p>";
        } else {
            $output['next_file'] = "<p>" . esc_html__('Optimizing', EWWW_IMAGE_OPTIMIZER_DOMAIN) . "&nbsp;<img src='{$loading_image}' /></p>";
        }
    }
    echo json_encode($output);
    ewww_image_optimizer_debug_log();
    ewwwio_memory(__FUNCTION__);
    die;
}
Пример #21
0
 protected function handle()
 {
     session_write_close();
     if (empty($_POST['ewwwio_test_verify'])) {
         return;
     }
     $item = $_POST['ewwwio_test_verify'];
     ewwwio_debug_message("testing async handling, received {$item}");
     if (ewww_image_optimizer_detect_wpsf_location_lock()) {
         ewwwio_debug_message('detected location lock, not enabling background opt');
         ewww_image_optimizer_debug_log();
         return;
     }
     if ($item != '949c34123cf2a4e4ce2f985135830df4a1b2adc24905f53d2fd3f5df5b162932') {
         ewwwio_debug_message('wrong item received, not enabling background opt');
         ewww_image_optimizer_debug_log();
         return;
     }
     ewww_image_optimizer_set_option('ewww_image_optimizer_background_optimization', true);
     ewww_image_optimizer_debug_log();
 }
Пример #22
0
 protected function handle()
 {
     ewww_image_optimizer_cloud_verify(false);
     ewww_image_optimizer_debug_log();
     session_write_close();
 }