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;
 }
Beispiel #2
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();
 }
Beispiel #3
0
function ewww_image_optimizer_dynamic_image_debug()
{
    ewwwio_debug_message('<b>' . __FUNCTION__ . '()</b>');
    echo "<div class='wrap'><h1>" . esc_html__('Dynamic Image Debugging', EWWW_IMAGE_OPTIMIZER_DOMAIN) . "</h1>";
    global $wpdb;
    $debug_images = $wpdb->get_results("SELECT path,updates,updated,trace FROM {$wpdb->ewwwio_images} WHERE trace IS NOT NULL ORDER BY updated DESC LIMIT 100");
    if (count($debug_images) != 0) {
        foreach ($debug_images as $image) {
            $trace = unserialize($image->trace);
            echo '<p><b>' . esc_html__('File path', EWWW_IMAGE_OPTIMIZER_DOMAIN) . ': ' . $image->path . '</b><br>';
            echo esc_html__('Number of attempted optimizations', EWWW_IMAGE_OPTIMIZER_DOMAIN) . ': ' . $image->updates . '<br>';
            echo esc_html__('Last attempted', EWWW_IMAGE_OPTIMIZER_DOMAIN) . ': ' . $image->updated . '<br>';
            echo esc_html__('PHP trace', EWWW_IMAGE_OPTIMIZER_DOMAIN) . ':<br>';
            $i = 0;
            foreach ($trace as $function) {
                if (!empty($function['file']) && !empty($function['line'])) {
                    echo "#{$i} {$function['function']}() called at {$function['file']}:{$function['line']}<br>";
                } else {
                    echo "#{$i} {$function['function']}() called<br>";
                }
                $i++;
            }
            echo '</p>';
        }
    }
    echo '</div>';
    return;
}
 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();
 }
Beispiel #5
0
function ewww_image_optimizer_bulk_loop()
{
    ewwwio_debug_message('<b>' . __FUNCTION__ . '()</b>');
    global $ewww_exceed;
    global $ewww_defer;
    $ewww_defer = false;
    // 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(__('Access token has expired, please reload the page.', 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')) {
        global $ewww_debug;
        echo '<div style="background-color:#ffff99;">' . $ewww_debug . '</div>';
    }
    ewww_image_optimizer_debug_log();
    ewwwio_memory(__FUNCTION__);
    die;
}
Beispiel #6
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();
 }
function ewww_image_optimizer_install_pngout()
{
    ewwwio_debug_message('<b>' . __FUNCTION__ . '()</b>');
    $permissions = apply_filters('ewww_image_optimizer_admin_permissions', '');
    if (FALSE === current_user_can($permissions)) {
        wp_die(esc_html__('You do not have permission to install image optimizer utilities.', EWWW_IMAGE_OPTIMIZER_DOMAIN));
    }
    if (PHP_OS != 'WINNT') {
        $tar = ewww_image_optimizer_find_nix_binary('tar', 't');
    }
    if (empty($tar) && PHP_OS != 'WINNT') {
        $pngout_error = __('tar command not found', EWWW_IMAGE_OPTIMIZER_DOMAIN);
    }
    if (PHP_OS == 'Linux') {
        $os_string = 'linux';
    }
    if (PHP_OS == 'FreeBSD') {
        $os_string = 'bsd';
    }
    $latest = '20150319';
    if (empty($pngout_error)) {
        if (PHP_OS == 'Linux' || PHP_OS == 'FreeBSD') {
            $download_result = ewww_image_optimizer_escapeshellarg(download_url('http://static.jonof.id.au/dl/kenutils/pngout-' . $latest . '-' . $os_string . '-static.tar.gz'));
            if (is_wp_error($download_result)) {
                $pngout_error = $download_result->get_error_message();
            } else {
                $arch_type = php_uname('m');
                exec("{$tar} xzf {$download_result} -C " . ewww_image_optimizer_escapeshellarg(EWWW_IMAGE_OPTIMIZER_BINARY_PATH) . ' pngout-' . $latest . '-' . $os_string . '-static/' . $arch_type . '/pngout-static');
                if (file_exists(EWWW_IMAGE_OPTIMIZER_BINARY_PATH . 'pngout-' . $latest . '-' . $os_string . '-static/' . $arch_type . '/pngout-static')) {
                    if (!rename(EWWW_IMAGE_OPTIMIZER_BINARY_PATH . 'pngout-' . $latest . '-' . $os_string . '-static/' . $arch_type . '/pngout-static', EWWW_IMAGE_OPTIMIZER_TOOL_PATH . 'pngout-static')) {
                        if (empty($pngout_error)) {
                            $pngout_error = __("could not move pngout", EWWW_IMAGE_OPTIMIZER_DOMAIN);
                        }
                    }
                    if (!chmod(EWWW_IMAGE_OPTIMIZER_TOOL_PATH . 'pngout-static', 0755)) {
                        if (empty($pngout_error)) {
                            $pngout_error = __("could not set permissions", EWWW_IMAGE_OPTIMIZER_DOMAIN);
                        }
                    }
                    $pngout_version = ewww_image_optimizer_tool_found(ewww_image_optimizer_escapeshellarg(EWWW_IMAGE_OPTIMIZER_TOOL_PATH) . 'pngout-static', 'p');
                } else {
                    $pngout_error = __('extraction of files failed', EWWW_IMAGE_OPTIMIZER_DOMAIN);
                }
            }
        }
        if (PHP_OS == 'Darwin') {
            $download_result = ewww_image_optimizer_escapeshellarg(download_url('http://static.jonof.id.au/dl/kenutils/pngout-' . $latest . '-darwin.tar.gz'));
            if (is_wp_error($download_result)) {
                $pngout_error = $download_result->get_error_message();
            } else {
                exec("{$tar} xzf {$download_result} -C " . ewww_image_optimizer_escapeshellarg(EWWW_IMAGE_OPTIMIZER_BINARY_PATH) . ' pngout-' . $latest . '-darwin/pngout');
                if (file_exists(EWWW_IMAGE_OPTIMIZER_BINARY_PATH . 'pngout-' . $latest . '-' . $os_string . '-static/' . $arch_type . '/pngout-static')) {
                    if (!rename(EWWW_IMAGE_OPTIMIZER_BINARY_PATH . 'pngout-' . $latest . '-darwin/pngout', EWWW_IMAGE_OPTIMIZER_TOOL_PATH . 'pngout-static')) {
                        if (empty($pngout_error)) {
                            $pngout_error = __('could not move pngout', EWWW_IMAGE_OPTIMIZER_DOMAIN);
                        }
                    }
                    if (!chmod(EWWW_IMAGE_OPTIMIZER_TOOL_PATH . 'pngout-static', 0755)) {
                        if (empty($pngout_error)) {
                            $pngout_error = __('could not set permissions', EWWW_IMAGE_OPTIMIZER_DOMAIN);
                        }
                    }
                    $pngout_version = ewww_image_optimizer_tool_found(ewww_image_optimizer_escapeshellarg(EWWW_IMAGE_OPTIMIZER_TOOL_PATH) . 'pngout-static', 'p');
                } else {
                    $pngout_error = __('extraction of files failed', EWWW_IMAGE_OPTIMIZER_DOMAIN);
                }
            }
        }
    }
    if (PHP_OS == 'WINNT') {
        $download_result = download_url('http://advsys.net/ken/util/pngout.exe');
        if (is_wp_error($download_result)) {
            $pngout_error = $download_result->get_error_message();
        } else {
            if (!rename($download_result, EWWW_IMAGE_OPTIMIZER_TOOL_PATH . 'pngout.exe')) {
                if (empty($pngout_error)) {
                    $pngout_error = __("could not move pngout", EWWW_IMAGE_OPTIMIZER_DOMAIN);
                }
            }
            $pngout_version = ewww_image_optimizer_tool_found('"' . EWWW_IMAGE_OPTIMIZER_TOOL_PATH . 'pngout.exe"', 'p');
        }
    }
    if (!empty($pngout_version)) {
        $sendback = add_query_arg('ewww_pngout', 'success', remove_query_arg(array('ewww_pngout', 'ewww_error'), wp_get_referer()));
    }
    if (!isset($sendback)) {
        $sendback = add_query_arg(array('ewww_pngout' => 'failed', 'ewww_error' => urlencode($pngout_error)), remove_query_arg(array('ewww_pngout', 'ewww_error'), wp_get_referer()));
    }
    wp_redirect(esc_url_raw($sendback));
    ewwwio_memory(__FUNCTION__);
    exit(0);
}
Beispiel #8
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;
}
Beispiel #9
0
function ewww_image_optimizer_aux_images_cleanup($auto = false)
{
    ewwwio_debug_message('<b>' . __FUNCTION__ . '()</b>');
    // verify that an authorized user has started the optimizer
    $permissions = apply_filters('ewww_image_optimizer_bulk_permissions', '');
    if (!$auto && (!wp_verify_nonce($_REQUEST['ewww_wpnonce'], 'ewww-image-optimizer-bulk') || !current_user_can($permissions))) {
        wp_die(esc_html__('Access denied.', EWWW_IMAGE_OPTIMIZER_DOMAIN));
    }
    $stored_last = get_option('ewww_image_optimizer_aux_last');
    update_option('ewww_image_optimizer_aux_last', array(time(), $stored_last[1]));
    // all done, so we can update the bulk options with empty values
    update_option('ewww_image_optimizer_aux_resume', '');
    update_option('ewww_image_optimizer_aux_attachments', '');
    if (!$auto) {
        // and let the user know we are done
        echo '<p><b>' . esc_html__('Finished', EWWW_IMAGE_OPTIMIZER_DOMAIN) . '</b></p>';
        ewwwio_memory(__FUNCTION__);
        die;
    }
}
 function ewww_ngg_bulk_script($hook)
 {
     ewwwio_debug_message('<b>' . __FUNCTION__ . '()</b>');
     //		$i18ngg = strtolower ( _n( 'Gallery', 'Galleries', 1, 'nggallery' ) );
     $i18ngg = strtolower(__('Galleries', 'nggallery'));
     ewwwio_debug_message("i18n string for galleries: {$i18ngg}");
     // make sure we are on a legitimate page and that we have the proper POST variables if necessary
     if ($hook != $i18ngg . '_page_ewww-ngg-bulk' && $hook != $i18ngg . '_page_nggallery-manage-gallery') {
         return;
     }
     if ($hook == $i18ngg . '_page_nggallery-manage-gallery' && (empty($_REQUEST['bulkaction']) || $_REQUEST['bulkaction'] != 'bulk_optimize')) {
         return;
     }
     if ($hook == $i18ngg . '_page_nggallery-manage-gallery' && (empty($_REQUEST['doaction']) || !is_array($_REQUEST['doaction']))) {
         return;
     }
     $images = null;
     // see if the user wants to reset the previous bulk status
     if (!empty($_REQUEST['ewww_reset']) && wp_verify_nonce($_REQUEST['ewww_wpnonce'], 'ewww-image-optimizer-bulk-reset')) {
         update_option('ewww_image_optimizer_bulk_ngg_resume', '');
     }
     // see if there is a previous operation to resume
     $resume = get_option('ewww_image_optimizer_bulk_ngg_resume');
     // if we've been given a bulk action to perform
     if (!empty($_REQUEST['doaction'])) {
         // if we are optimizing a specific group of images
         if ($_REQUEST['page'] == 'manage-images' && $_REQUEST['bulkaction'] == 'bulk_optimize') {
             ewwwio_debug_message('optimizing a group of images');
             check_admin_referer('ngg_updategallery');
             // reset the resume status, not allowed here
             update_option('ewww_image_optimizer_bulk_ngg_resume', '');
             // retrieve the image IDs from POST
             $images = array_map('intval', $_REQUEST['doaction']);
         }
         // if we are optimizing a specific group of galleries
         if ($_REQUEST['page'] == 'manage-galleries' && $_REQUEST['bulkaction'] == 'bulk_optimize') {
             ewwwio_debug_message('optimizing a group of galleries');
             check_admin_referer('ngg_bulkgallery');
             global $nggdb;
             // reset the resume status, not allowed here
             update_option('ewww_image_optimizer_bulk_ngg_resume', '');
             $ids = array();
             // for each gallery we are given
             foreach ($_REQUEST['doaction'] as $gid) {
                 // get a list of IDs
                 $gallery_list = $nggdb->get_gallery($gid);
                 // for each ID
                 foreach ($gallery_list as $image) {
                     // add it to the array
                     $images[] = $image->pid;
                 }
             }
         }
         // otherwise, if we have an operation to resume
     } elseif (!empty($resume)) {
         ewwwio_debug_message('resuming a previous operation (maybe)');
         // get the list of attachment IDs from the db
         $images = get_option('ewww_image_optimizer_bulk_ngg_attachments');
         // otherwise, if we are on the standard bulk page, get all the images in the db
     } elseif ($hook == $i18ngg . '_page_ewww-ngg-bulk') {
         ewwwio_debug_message('starting from scratch, grabbing all the images');
         global $wpdb;
         $images = $wpdb->get_col("SELECT pid FROM {$wpdb->nggpictures} ORDER BY sortorder ASC");
     } else {
         ewwwio_debug_message($hook);
     }
     // store the image IDs to process in the db
     update_option('ewww_image_optimizer_bulk_ngg_attachments', $images);
     // add the EWWW IO script
     wp_enqueue_script('ewwwbulkscript', plugins_url('/eio.js', __FILE__), array('jquery', 'jquery-ui-progressbar', 'jquery-ui-slider'));
     // replacing the built-in nextgen styling rules for progressbar
     wp_register_style('ngg-jqueryui', plugins_url('jquery-ui-1.10.1.custom.css', __FILE__));
     // enqueue the progressbar styling
     wp_enqueue_style('ngg-jqueryui');
     //, plugins_url('jquery-ui-1.10.1.custom.css', __FILE__));
     // prep the $images for use by javascript
     $images = json_encode($images);
     // include all the vars we need for javascript
     wp_localize_script('ewwwbulkscript', 'ewww_vars', array('_wpnonce' => wp_create_nonce('ewww-image-optimizer-bulk'), 'gallery' => 'nextgen', 'attachments' => $images, 'license_exceeded' => __('License Exceeded', EWWW_IMAGE_OPTIMIZER_DOMAIN), 'operation_stopped' => __('Optimization stopped, reload page to resume.', EWWW_IMAGE_OPTIMIZER_DOMAIN), 'operation_interrupted' => __('Operation Interrupted', EWWW_IMAGE_OPTIMIZER_DOMAIN), 'temporary_failure' => __('Temporary failure, seconds left to retry:', EWWW_IMAGE_OPTIMIZER_DOMAIN), 'remove_failed' => __('Could not remove image from table.', EWWW_IMAGE_OPTIMIZER_DOMAIN)));
 }
Beispiel #11
0
function ewww_image_optimizer_options()
{
    ewwwio_debug_message('<b>' . __FUNCTION__ . '()</b>');
    ewwwio_debug_message('ABSPATH: ' . ABSPATH);
    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
        ewww_image_optimizer_require(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>' . __('Pngout was successfully installed, check the Plugin Status area for version information.', EWWW_IMAGE_OPTIMIZER_DOMAIN) . "</p>\n";
            $output[] = "</div>\n";
        }
        if ($_REQUEST['ewww_pngout'] == 'failed') {
            $output[] = "<div id='ewww-image-optimizer-pngout-failure' class='error'>\n";
            $output[] = '<p>' . sprintf(__('Pngout was not installed: %1$s. Make sure this folder is writable: %2$s', EWWW_IMAGE_OPTIMIZER_DOMAIN), sanitize_text_field($_REQUEST['ewww_error']), EWWW_IMAGE_OPTIMIZER_TOOL_PATH) . "</p>\n";
            $output[] = "</div>\n";
        }
    }
    $output[] = "<script type='text/javascript'>\n" . 'jQuery(document).ready(function($) {$(".fade").fadeTo(5000,1).fadeOut(3000);$(".updated").fadeTo(5000,1).fadeOut(3000);});' . "\n" . "</script>\n";
    $output[] = "<style>\n" . ".ewww-tab a { font-size: 15px; font-weight: 700; color: #555; text-decoration: none; line-height: 36px; padding: 0 10px; }\n" . ".ewww-tab a:hover { color: #464646; }\n" . ".ewww-tab { margin: 0 0 0 5px; padding: 0px; border-width: 1px 1px 1px; border-style: solid solid none; border-image: none; border-color: #ccc; display: inline-block; background-color: #e4e4e4 }\n" . ".ewww-tab:hover { background-color: #fff }\n" . ".ewww-selected { background-color: #f1f1f1; margin-bottom: -1px; border-bottom: 1px solid #f1f1f1 }\n" . ".ewww-selected a { color: #000; }\n" . ".ewww-selected:hover { background-color: #f1f1f1; }\n" . ".ewww-tab-nav { list-style: none; margin: 10px 0 0; padding-left: 5px; border-bottom: 1px solid #ccc; }\n" . "</style>\n";
    $output[] = "<div class='wrap'>\n";
    $output[] = "<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/'>" . __('Plugin Home Page', EWWW_IMAGE_OPTIMIZER_DOMAIN) . "</a> | " . "<a href='https://wordpress.org/extend/plugins/ewww-image-optimizer/installation/'>" . __('Installation Instructions', EWWW_IMAGE_OPTIMIZER_DOMAIN) . "</a> | " . "<a href='https://wordpress.org/support/plugin/ewww-image-optimizer'>" . __('Plugin Support', EWWW_IMAGE_OPTIMIZER_DOMAIN) . "</a> | " . "<a href='https://ewww.io/status/'>" . __('Cloud Status', EWWW_IMAGE_OPTIMIZER_DOMAIN) . "</a> | " . "<a href='https://ewww.io/downloads/s3-image-optimizer/'>" . __('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 = __('Media Library') . ' -> ' . __('Bulk Optimize', EWWW_IMAGE_OPTIMIZER_DOMAIN);
    } else {
        $bulk_link = '<a href="upload.php?page=ewww-image-optimizer-bulk">' . __('Bulk Optimize', EWWW_IMAGE_OPTIMIZER_DOMAIN) . '</a>';
    }
    $output[] = "<p>" . sprintf(__('New images uploaded to the Media Library will be optimized automatically. If you have existing images you would like to optimize, you can use the %s tool.', EWWW_IMAGE_OPTIMIZER_DOMAIN), $bulk_link) . " " . __('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>.') . "</p>\n";
    if (EWWW_IMAGE_OPTIMIZER_CLOUD) {
        $collapsed = '';
    } else {
        $collapsed = "\$('#ewww-status').toggleClass('closed');\n";
    }
    $output[] = "<div id='ewww-widgets' class='metabox-holder'><div class='meta-box-sortables'><div id='ewww-status' class='postbox'>\n" . "<div class='handlediv' title='" . esc_attr__('Click to toggle') . "'><br></div>" . "<h2 class='hndle'>" . __('Plugin Status', EWWW_IMAGE_OPTIMIZER_DOMAIN) . "&emsp;" . "<span id='ewww-status-ok' style='display: none; color: green;'>" . __('All Clear', EWWW_IMAGE_OPTIMIZER_DOMAIN) . "</span>" . "<span id='ewww-status-attention' style='color: red;'>" . __('Requires Attention', EWWW_IMAGE_OPTIMIZER_DOMAIN) . "</span>" . "</h2>\n" . "<div class='inside'>" . "<b>" . __('Total Savings:', EWWW_IMAGE_OPTIMIZER_DOMAIN) . "</b> <span id='ewww-total-savings'>" . size_format(ewww_image_optimizer_savings(), 2) . "</span><br>";
    if (ewww_image_optimizer_get_option('ewww_image_optimizer_cloud_key')) {
        $output[] = '<p><b>' . __('Cloud optimization API Key', EWWW_IMAGE_OPTIMIZER_DOMAIN) . ":</b> ";
        $verify_cloud = ewww_image_optimizer_cloud_verify(false);
        if (preg_match('/great/', $verify_cloud)) {
            $output[] = '<span style="color: green">' . __('Verified,', EWWW_IMAGE_OPTIMIZER_DOMAIN) . ' </span>' . ewww_image_optimizer_cloud_quota();
        } elseif (preg_match('/exceeded/', $verify_cloud)) {
            $output[] = '<span style="color: orange">' . __('Verified,', EWWW_IMAGE_OPTIMIZER_DOMAIN) . ' </span>' . ewww_image_optimizer_cloud_quota();
        } else {
            $output[] = '<span style="color: red">' . __('Not Verified', EWWW_IMAGE_OPTIMIZER_DOMAIN) . '</span>';
        }
        $output[] = "</p>\n";
    }
    $collapsible = true;
    if (!EWWW_IMAGE_OPTIMIZER_CLOUD) {
        /*	$output[] = "<div id='ewww-status-expand' style='display: none;'><a href='#'>" . __('Expand', EWWW_IMAGE_OPTIMIZER_DOMAIN) . "</a></div>\n" .
        			"<div id='ewww-status-collapse' style='display: none;'><a href='#'>" . __('Collapse', EWWW_IMAGE_OPTIMIZER_DOMAIN) . "</a></div>\n" .
        			"<div id='ewww-collapsible-status'>\n";*/
        //				$output[] = "<div id='ewww-collapsible-status'>\n";
    }
    if (ewww_image_optimizer_get_option('ewww_image_optimizer_skip_bundle') && !EWWW_IMAGE_OPTIMIZER_CLOUD && !EWWW_IMAGE_OPTIMIZER_NOEXEC) {
        $output[] = "<p>" . __('If updated versions are available below you may either download the newer versions and install them yourself, or uncheck "Use System Paths" and use the bundled tools.', EWWW_IMAGE_OPTIMIZER_DOMAIN) . "<br />\n" . "<i>*" . __('Updates are optional, but may contain increased optimization or security patches', EWWW_IMAGE_OPTIMIZER_DOMAIN) . "</i></p>\n";
    } elseif (!EWWW_IMAGE_OPTIMIZER_CLOUD && !EWWW_IMAGE_OPTIMIZER_NOEXEC) {
        $output[] = "<p>" . sprintf(__('If updated versions are available below, you may need to enable write permission on the %s folder to use the automatic installs.', EWWW_IMAGE_OPTIMIZER_DOMAIN), '<i>' . EWWW_IMAGE_OPTIMIZER_TOOL_PATH . '</i>') . "<br />\n" . "<i>*" . __('Updates are optional, but may contain increased optimization or security patches', EWWW_IMAGE_OPTIMIZER_DOMAIN) . "</i></p>\n";
    }
    if (!EWWW_IMAGE_OPTIMIZER_CLOUD && !EWWW_IMAGE_OPTIMIZER_NOEXEC) {
        list($jpegtran_src, $optipng_src, $gifsicle_src, $jpegtran_dst, $optipng_dst, $gifsicle_dst) = ewww_image_optimizer_install_paths();
    }
    $output[] = "<p>\n";
    if (!ewww_image_optimizer_get_option('ewww_image_optimizer_disable_jpegtran') && !ewww_image_optimizer_get_option('ewww_image_optimizer_cloud_jpg') && !EWWW_IMAGE_OPTIMIZER_NOEXEC) {
        $output[] = "<b>jpegtran:</b> ";
        $jpegtran_installed = ewww_image_optimizer_tool_found(EWWW_IMAGE_OPTIMIZER_JPEGTRAN, 'j');
        if (!empty($jpegtran_installed)) {
            $output[] = '<span style="color: green; font-weight: bolder">' . __('Installed', EWWW_IMAGE_OPTIMIZER_DOMAIN) . '</span>&emsp;' . __('version', EWWW_IMAGE_OPTIMIZER_DOMAIN) . ': ' . $jpegtran_installed . "<br />\n";
        } else {
            $output[] = '<span style="color: red; font-weight: bolder">' . __('Missing', EWWW_IMAGE_OPTIMIZER_DOMAIN) . '</span><br />' . "\n";
            $collapsible = false;
        }
    }
    if (!ewww_image_optimizer_get_option('ewww_image_optimizer_disable_optipng') && !ewww_image_optimizer_get_option('ewww_image_optimizer_cloud_png') && !EWWW_IMAGE_OPTIMIZER_NOEXEC) {
        $output[] = "<b>optipng:</b> ";
        $optipng_version = ewww_image_optimizer_tool_found(EWWW_IMAGE_OPTIMIZER_OPTIPNG, 'o');
        if (!empty($optipng_version)) {
            $output[] = '<span style="color: green; font-weight: bolder">' . __('Installed', EWWW_IMAGE_OPTIMIZER_DOMAIN) . '</span>&emsp;' . __('version', EWWW_IMAGE_OPTIMIZER_DOMAIN) . ': ' . $optipng_version . "<br />\n";
        } else {
            $output[] = '<span style="color: red; font-weight: bolder">' . __('Missing', EWWW_IMAGE_OPTIMIZER_DOMAIN) . '</span><br />' . "\n";
            $collapsible = false;
        }
    }
    if (!ewww_image_optimizer_get_option('ewww_image_optimizer_disable_gifsicle') && !ewww_image_optimizer_get_option('ewww_image_optimizer_cloud_gif') && !EWWW_IMAGE_OPTIMIZER_NOEXEC) {
        $output[] = "<b>gifsicle:</b> ";
        $gifsicle_version = ewww_image_optimizer_tool_found(EWWW_IMAGE_OPTIMIZER_GIFSICLE, 'g');
        if (!empty($gifsicle_version) && preg_match('/LCDF Gifsicle/', $gifsicle_version)) {
            $output[] = '<span style="color: green; font-weight: bolder">' . __('Installed', EWWW_IMAGE_OPTIMIZER_DOMAIN) . '</span>&emsp;' . __('version', EWWW_IMAGE_OPTIMIZER_DOMAIN) . ': ' . $gifsicle_version . "<br />\n";
        } else {
            $output[] = '<span style="color: red; font-weight: bolder">' . __('Missing', EWWW_IMAGE_OPTIMIZER_DOMAIN) . '</span><br />' . "\n";
            $collapsible = false;
        }
    }
    if (!ewww_image_optimizer_get_option('ewww_image_optimizer_disable_pngout') && !ewww_image_optimizer_get_option('ewww_image_optimizer_cloud_png') && !EWWW_IMAGE_OPTIMIZER_NOEXEC) {
        $output[] = "<b>pngout:</b> ";
        $pngout_version = ewww_image_optimizer_tool_found(EWWW_IMAGE_OPTIMIZER_PNGOUT, 'p');
        if (!empty($pngout_version) && preg_match('/PNGOUT/', $pngout_version)) {
            $output[] = '<span style="color: green; font-weight: bolder">' . __('Installed', EWWW_IMAGE_OPTIMIZER_DOMAIN) . '</span>&emsp;' . __('version', EWWW_IMAGE_OPTIMIZER_DOMAIN) . ': ' . preg_replace('/PNGOUT \\[.*\\)\\s*?/', '', $pngout_version) . "<br />\n";
        } else {
            $output[] = '<span style="color: red; font-weight: bolder">' . __('Missing', EWWW_IMAGE_OPTIMIZER_DOMAIN) . '</span>&emsp;<b>' . __('Install', EWWW_IMAGE_OPTIMIZER_DOMAIN) . ' <a href="admin.php?action=ewww_image_optimizer_install_pngout">' . __('automatically', EWWW_IMAGE_OPTIMIZER_DOMAIN) . '</a> | <a href="http://advsys.net/ken/utils.htm">' . __('manually', EWWW_IMAGE_OPTIMIZER_DOMAIN) . '</a></b> - ' . __('Pngout is free closed-source software that can produce drastically reduced filesizes for PNGs, but can be very time consuming to process images', EWWW_IMAGE_OPTIMIZER_DOMAIN) . "<br />\n";
            $collapsible = false;
        }
    }
    if (ewww_image_optimizer_get_option('ewww_image_optimizer_png_lossy') && !ewww_image_optimizer_get_option('ewww_image_optimizer_cloud_png') && !EWWW_IMAGE_OPTIMIZER_NOEXEC) {
        $output[] = "<b>pngquant:</b> ";
        $pngquant_version = ewww_image_optimizer_tool_found(EWWW_IMAGE_OPTIMIZER_PNGQUANT, 'q');
        if (!empty($pngquant_version)) {
            $output[] = '<span style="color: green; font-weight: bolder">' . __('Installed', EWWW_IMAGE_OPTIMIZER_DOMAIN) . '</span>&emsp;' . __('version', EWWW_IMAGE_OPTIMIZER_DOMAIN) . ': ' . $pngquant_version . "<br />\n";
        } else {
            $output[] = '<span style="color: red; font-weight: bolder">' . __('Missing', EWWW_IMAGE_OPTIMIZER_DOMAIN) . '</span><br />' . "\n";
            $collapsible = false;
        }
    }
    if (ewww_image_optimizer_get_option('ewww_image_optimizer_webp') && !ewww_image_optimizer_get_option('ewww_image_optimizer_cloud_png') && !ewww_image_optimizer_get_option('ewww_image_optimizer_cloud_jpg') && !EWWW_IMAGE_OPTIMIZER_NOEXEC) {
        $output[] = "<b>webp:</b> ";
        $webp_version = ewww_image_optimizer_tool_found(EWWW_IMAGE_OPTIMIZER_WEBP, 'w');
        if (!empty($webp_version)) {
            $output[] = '<span style="color: green; font-weight: bolder">' . __('Installed', EWWW_IMAGE_OPTIMIZER_DOMAIN) . '</span>&emsp;' . __('version', EWWW_IMAGE_OPTIMIZER_DOMAIN) . ': ' . $webp_version . "<br />\n";
        } else {
            $output[] = '<span style="color: red; font-weight: bolder">' . __('Missing', EWWW_IMAGE_OPTIMIZER_DOMAIN) . '</span><br />' . "\n";
            $collapsible = false;
        }
    }
    if (!EWWW_IMAGE_OPTIMIZER_CLOUD && !EWWW_IMAGE_OPTIMIZER_NOEXEC) {
        if (ewww_image_optimizer_safemode_check()) {
            $output[] = 'safe mode: <span style="color: red; font-weight: bolder">' . __('On', EWWW_IMAGE_OPTIMIZER_DOMAIN) . '</span>&emsp;&emsp;';
            $collapsible = false;
        } else {
            $output[] = 'safe mode: <span style="color: green; font-weight: bolder">' . __('Off', EWWW_IMAGE_OPTIMIZER_DOMAIN) . '</span>&emsp;&emsp;';
        }
        if (ewww_image_optimizer_exec_check()) {
            $output[] = 'exec(): <span style="color: red; font-weight: bolder">' . __('Disabled', EWWW_IMAGE_OPTIMIZER_DOMAIN) . '</span>&emsp;&emsp;';
            $collapsible = false;
        } else {
            $output[] = 'exec(): <span style="color: green; font-weight: bolder">' . __('Enabled', EWWW_IMAGE_OPTIMIZER_DOMAIN) . '</span>&emsp;&emsp;';
        }
        $output[] = "<br />\n";
        $output[] = sprintf(__("%s only need one, used for conversion, not optimization", EWWW_IMAGE_OPTIMIZER_DOMAIN), '<b>' . __('Graphics libraries', EWWW_IMAGE_OPTIMIZER_DOMAIN) . '</b> - ');
        $output[] = '<br>';
        $toolkit_found = false;
        if (ewww_image_optimizer_gd_support()) {
            $output[] = 'GD: <span style="color: green; font-weight: bolder">' . __('Installed', EWWW_IMAGE_OPTIMIZER_DOMAIN);
            $toolkit_found = true;
        } else {
            $output[] = 'GD: <span style="color: red; font-weight: bolder">' . __('Missing', EWWW_IMAGE_OPTIMIZER_DOMAIN);
        }
        $output[] = '</span>&emsp;&emsp;' . "Gmagick: ";
        if (ewww_image_optimizer_gmagick_support()) {
            $output[] = '<span style="color: green; font-weight: bolder">' . __('Installed', EWWW_IMAGE_OPTIMIZER_DOMAIN);
            $toolkit_found = true;
        } else {
            $output[] = '<span style="color: red; font-weight: bolder">' . __('Missing', EWWW_IMAGE_OPTIMIZER_DOMAIN);
        }
        $output[] = '</span>&emsp;&emsp;' . "Imagick: ";
        if (ewww_image_optimizer_imagick_support()) {
            $output[] = '<span style="color: green; font-weight: bolder">' . __('Installed', EWWW_IMAGE_OPTIMIZER_DOMAIN);
            $toolkit_found = true;
        } else {
            $output[] = '<span style="color: red; font-weight: bolder">' . __('Missing', EWWW_IMAGE_OPTIMIZER_DOMAIN);
        }
        $output[] = '</span>&emsp;&emsp;' . "Imagemagick 'convert': ";
        if (ewww_image_optimizer_find_binary('convert', 'i')) {
            $output[] = '<span style="color: green; font-weight: bolder">' . __('Installed', EWWW_IMAGE_OPTIMIZER_DOMAIN) . '</span>';
            $toolkit_found = true;
        } else {
            $output[] = '<span style="color: red; font-weight: bolder">' . __('Missing', EWWW_IMAGE_OPTIMIZER_DOMAIN) . '</span>';
        }
        if (!$toolkit_found && (ewww_image_optimizer_get_option('ewww_image_optimizer_png_to_jpg') || ewww_image_optimizer_get_option('ewww_image_optimizer_jpg_to_png'))) {
            $collapsible = false;
        }
        $output[] = "<br />\n";
    }
    $output[] = '<b>' . __('Only need one of these:', EWWW_IMAGE_OPTIMIZER_DOMAIN) . ' </b><br>';
    // initialize this variable to check for the 'file' command if we don't have any php libraries we can use
    $file_command_check = true;
    if (function_exists('finfo_file')) {
        $output[] = 'finfo: <span style="color: green; font-weight: bolder">' . __('Installed', EWWW_IMAGE_OPTIMIZER_DOMAIN) . '</span>&emsp;&emsp;';
        $file_command_check = false;
    } else {
        $output[] = 'finfo: <span style="color: red; font-weight: bolder">' . __('Missing', EWWW_IMAGE_OPTIMIZER_DOMAIN) . '</span>&emsp;&emsp;';
    }
    if (function_exists('getimagesize')) {
        $output[] = 'getimagesize(): <span style="color: green; font-weight: bolder">' . __('Installed', EWWW_IMAGE_OPTIMIZER_DOMAIN) . '</span>&emsp;&emsp;';
        if (EWWW_IMAGE_OPTIMIZER_CLOUD || EWWW_IMAGE_OPTIMIZER_NOEXEC || PHP_OS == 'WINNT') {
            $file_command_check = false;
        }
    } else {
        $output[] = 'getimagesize(): <span style="color: red; font-weight: bolder">' . __('Missing', EWWW_IMAGE_OPTIMIZER_DOMAIN) . '</span>&emsp;&emsp;';
    }
    if (function_exists('mime_content_type')) {
        $output[] = 'mime_content_type(): <span style="color: green; font-weight: bolder">' . __('Installed', EWWW_IMAGE_OPTIMIZER_DOMAIN) . '</span><br />' . "\n";
        $file_command_check = false;
    } else {
        $output[] = 'mime_content_type(): <span style="color: red; font-weight: bolder">' . __('Missing', EWWW_IMAGE_OPTIMIZER_DOMAIN) . '</span><br />' . "\n";
    }
    if (PHP_OS != 'WINNT' && !EWWW_IMAGE_OPTIMIZER_CLOUD && !EWWW_IMAGE_OPTIMIZER_NOEXEC) {
        if ($file_command_check && !ewww_image_optimizer_find_binary('file', 'f')) {
            $output[] = '<span style="color: red; font-weight: bolder">file: ' . __('command not found on your system', EWWW_IMAGE_OPTIMIZER_DOMAIN) . '</span><br />';
            $collapsible = false;
        }
        if (!ewww_image_optimizer_find_binary('nice', 'n')) {
            $output[] = '<span style="color: orange; font-weight: bolder">nice: ' . __('command not found on your system', EWWW_IMAGE_OPTIMIZER_DOMAIN) . ' (' . __('not required', EWWW_IMAGE_OPTIMIZER_DOMAIN) . ')</span><br />';
        }
        if (!ewww_image_optimizer_get_option('ewww_image_optimizer_disable_pngout') && !ewww_image_optimizer_get_option('ewww_image_optimizer_cloud_png') && PHP_OS != 'SunOS' && !ewww_image_optimizer_find_binary('tar', 't')) {
            $output[] = '<span style="color: red; font-weight: bolder">tar ' . __('command not found on your system', EWWW_IMAGE_OPTIMIZER_DOMAIN) . ' (' . __('required for automatic pngout installer', EWWW_IMAGE_OPTIMIZER_DOMAIN) . ')</span><br />';
            $collapsible = false;
        }
    } elseif ($file_command_check) {
        $collapsible = false;
    }
    if (!EWWW_IMAGE_OPTIMIZER_CLOUD) {
        //				$output[] = '</div><!-- end collapsible -->';
    }
    $output[] = '</div><!-- end .inside -->';
    if ($collapsible) {
        $output[] = "<script type='text/javascript'>\n" . "jQuery(document).ready(function(\$) {\n" . $collapsed . "\$('#ewww-status-attention').hide();\n" . "\$('#ewww-status-ok').show();\n" . "});\n" . "</script>\n";
    }
    $output[] = "</div></div></div>\n";
    $output[] = "<ul class='ewww-tab-nav'>\n" . "<li class='ewww-tab ewww-cloud-nav'><span class='ewww-tab-hidden'><a class='ewww-cloud-nav' href='#'>" . __('Cloud Settings', EWWW_IMAGE_OPTIMIZER_DOMAIN) . "</a></span></li>\n" . "<li class='ewww-tab ewww-general-nav'><span class='ewww-tab-hidden'><a class='ewww-general-nav' href='#'>" . __('Basic Settings', EWWW_IMAGE_OPTIMIZER_DOMAIN) . "</a></span></li>\n" . "<li class='ewww-tab ewww-optimization-nav'><span class='ewww-tab-hidden'><a class='ewww-optimization-nav' href='#'>" . __('Advanced Settings', EWWW_IMAGE_OPTIMIZER_DOMAIN) . "</a></span></li>\n" . "<li class='ewww-tab ewww-conversion-nav'><span class='ewww-tab-hidden'><a class='ewww-conversion-nav' href='#'>" . __('Conversion Settings', EWWW_IMAGE_OPTIMIZER_DOMAIN) . "</a></span></li>\n" . "</ul>\n";
    if (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-cloud-settings'>\n";
    $output[] = "<p>" . __('If exec() is disabled for security reasons (and enabling it is not an option), or you would like to offload image optimization to a third-party server, you may purchase an API key for our cloud optimization service. The API key should be entered below, and cloud optimization must be enabled for each image format individually.', EWWW_IMAGE_OPTIMIZER_DOMAIN) . " <a href='https://ewww.io/plans/'>" . __('Purchase an API key.', EWWW_IMAGE_OPTIMIZER_DOMAIN) . "</a></p>\n";
    $output[] = "<table class='form-table'>\n";
    $output[] = "<tr><th><label for='ewww_image_optimizer_cloud_key'>" . __('Cloud optimization API Key', EWWW_IMAGE_OPTIMIZER_DOMAIN) . "</label></th><td><input type='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' /> " . __('API Key will be validated when you save your settings.', EWWW_IMAGE_OPTIMIZER_DOMAIN) . " <a href='https://ewww.io/plans/'>" . __('Purchase an API key.', EWWW_IMAGE_OPTIMIZER_DOMAIN) . "</a></td></tr>\n";
    $output[] = "<tr><th><label for='ewww_image_optimizer_cloud_jpg'>" . __('JPG cloud optimization', EWWW_IMAGE_OPTIMIZER_DOMAIN) . "</label></th><td><input type='checkbox' id='ewww_image_optimizer_cloud_jpg' name='ewww_image_optimizer_cloud_jpg' value='true' " . (ewww_image_optimizer_get_option('ewww_image_optimizer_cloud_jpg') == TRUE ? "checked='true'" : "") . " /></td></tr>\n";
    ewwwio_debug_message("cloud JPG: " . (ewww_image_optimizer_get_option('ewww_image_optimizer_cloud_jpg') == TRUE ? "on" : "off"));
    $output[] = "<tr><th><label for='ewww_image_optimizer_cloud_png'>" . __('PNG cloud optimization', EWWW_IMAGE_OPTIMIZER_DOMAIN) . "</label></th><td><input type='checkbox' id='ewww_image_optimizer_cloud_png' name='ewww_image_optimizer_cloud_png' value='true' " . (ewww_image_optimizer_get_option('ewww_image_optimizer_cloud_png') == TRUE ? "checked='true'" : "") . " /></td></tr>";
    ewwwio_debug_message("cloud PNG: " . (ewww_image_optimizer_get_option('ewww_image_optimizer_cloud_png') == TRUE ? "on" : "off"));
    $output[] = "<tr><td>&nbsp;</td><td><input type='checkbox' id='ewww_image_optimizer_cloud_png_compress' name='ewww_image_optimizer_cloud_png_compress' value='true' " . (ewww_image_optimizer_get_option('ewww_image_optimizer_cloud_png_compress') == TRUE ? "checked='true'" : "") . " /><label for='ewww_image_optimizer_cloud_png_compress'>" . __('extra PNG compression (slower)', EWWW_IMAGE_OPTIMIZER_DOMAIN) . "</label></td></tr>\n";
    ewwwio_debug_message("PNG extra compress: " . (ewww_image_optimizer_get_option('ewww_image_optimizer_cloud_png_compress') == TRUE ? "on" : "off"));
    $output[] = "<tr><th><label for='ewww_image_optimizer_cloud_gif'>" . __('GIF cloud optimization', EWWW_IMAGE_OPTIMIZER_DOMAIN) . "</label></th><td><input type='checkbox' id='ewww_image_optimizer_cloud_gif' name='ewww_image_optimizer_cloud_gif' value='true' " . (ewww_image_optimizer_get_option('ewww_image_optimizer_cloud_gif') == TRUE ? "checked='true'" : "") . " /></td></tr>\n";
    ewwwio_debug_message("cloud GIF: " . (ewww_image_optimizer_get_option('ewww_image_optimizer_cloud_gif') == TRUE ? "on" : "off"));
    $output[] = "<tr><th><label for='ewww_image_optimizer_lossy_fast'>" . __('Faster lossy optimization', EWWW_IMAGE_OPTIMIZER_DOMAIN) . "</label></th><td><input type='checkbox' id='ewww_image_optimizer_lossy_fast' name='ewww_image_optimizer_lossy_fast' value='true' " . (ewww_image_optimizer_get_option('ewww_image_optimizer_lossy_fast') == TRUE ? "checked='true'" : "") . " /> " . __('Speed up the lossy operations by performing less compression.', EWWW_IMAGE_OPTIMIZER_DOMAIN) . "</td></tr>\n";
    ewwwio_debug_message("cloud fast lossy: " . (ewww_image_optimizer_get_option('ewww_image_optimizer_lossy_fast') == TRUE ? "on" : "off"));
    $output[] = "</table>\n</div>\n";
    $output[] = "<div id='ewww-general-settings'>\n";
    $output[] = "<table class='form-table'>\n";
    $output[] = "<tr><th><label for='ewww_image_optimizer_debug'>" . __('Debugging', EWWW_IMAGE_OPTIMIZER_DOMAIN) . "</label></th><td><input type='checkbox' id='ewww_image_optimizer_debug' name='ewww_image_optimizer_debug' value='true' " . (ewww_image_optimizer_get_option('ewww_image_optimizer_debug') == TRUE ? "checked='true'" : "") . " /> " . __('Use this to provide information for support purposes, or if you feel comfortable digging around in the code to fix a problem you are experiencing.', EWWW_IMAGE_OPTIMIZER_DOMAIN) . "</td></tr>\n";
    $output[] = "<tr><th><label for='ewww_image_optimizer_jpegtran_copy'>" . __('Remove metadata', EWWW_IMAGE_OPTIMIZER_DOMAIN) . "</label></th>\n" . "<td><input type='checkbox' id='ewww_image_optimizer_jpegtran_copy' name='ewww_image_optimizer_jpegtran_copy' value='true' " . (ewww_image_optimizer_get_option('ewww_image_optimizer_jpegtran_copy') == TRUE ? "checked='true'" : "") . " /> " . __('This will remove ALL metadata: EXIF and comments.', EWWW_IMAGE_OPTIMIZER_DOMAIN) . "</td></tr>\n";
    ewwwio_debug_message("remove metadata: " . (ewww_image_optimizer_get_option('ewww_image_optimizer_jpegtran_copy') == TRUE ? "on" : "off"));
    $output[] = "<tr><th><label for='ewww_image_optimizer_jpg_lossy'>" . __('Lossy JPG optimization', EWWW_IMAGE_OPTIMIZER_DOMAIN) . "</label></th><td><input type='checkbox' id='ewww_image_optimizer_jpg_lossy' name='ewww_image_optimizer_jpg_lossy' value='true' " . (ewww_image_optimizer_get_option('ewww_image_optimizer_jpg_lossy') == TRUE ? "checked='true'" : "") . " /> <b>" . __('WARNING:', EWWW_IMAGE_OPTIMIZER_DOMAIN) . "</b> " . __('While most users will not notice a difference in image quality, lossy means there IS a loss in image quality.', EWWW_IMAGE_OPTIMIZER_DOMAIN) . "\n" . "<p class='description'>" . __('Requires an EWWW Image Optimizer Cloud Subscription.', EWWW_IMAGE_OPTIMIZER_DOMAIN) . " <a href='https://ewww.io/plans/'>" . __('Purchase an API key.', EWWW_IMAGE_OPTIMIZER_DOMAIN) . "</a></p></td></tr>\n";
    ewwwio_debug_message("lossy JPG: " . (ewww_image_optimizer_get_option('ewww_image_optimizer_jpg_lossy') == TRUE ? "on" : "off"));
    $output[] = "<tr><th><label for='ewww_image_optimizer_png_lossy'>" . __('Lossy PNG optimization', EWWW_IMAGE_OPTIMIZER_DOMAIN) . "</label></th><td><input type='checkbox' id='ewww_image_optimizer_png_lossy' name='ewww_image_optimizer_png_lossy' value='true' " . (ewww_image_optimizer_get_option('ewww_image_optimizer_png_lossy') == TRUE ? "checked='true'" : "") . " /> <b>" . __('WARNING:', EWWW_IMAGE_OPTIMIZER_DOMAIN) . "</b> " . __('While most users will not notice a difference in image quality, lossy means there IS a loss in image quality.', EWWW_IMAGE_OPTIMIZER_DOMAIN) . "\n" . "<p class='description'>" . __('Uses pngquant locally. Use EWWW I.O. Cloud for even better lossy compression.', EWWW_IMAGE_OPTIMIZER_DOMAIN) . " <a href='https://ewww.io/plans/'>" . __('Purchase an API key.', EWWW_IMAGE_OPTIMIZER_DOMAIN) . "</a></p></td></tr>\n";
    ewwwio_debug_message("lossy PNG: " . (ewww_image_optimizer_get_option('ewww_image_optimizer_png_lossy') == TRUE ? "on" : "off"));
    $output[] = "<tr><th><label for='ewww_image_optimizer_delay'>" . __('Bulk Delay', EWWW_IMAGE_OPTIMIZER_DOMAIN) . "</label></th><td><input type='text' id='ewww_image_optimizer_delay' name='ewww_image_optimizer_delay' size='5' value='" . ewww_image_optimizer_get_option('ewww_image_optimizer_delay') . "'> " . __('Choose how long to pause between images (in seconds, 0 = disabled)', EWWW_IMAGE_OPTIMIZER_DOMAIN) . "</td></tr>\n";
    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'>" . __('Automatic Cloudinary upload', EWWW_IMAGE_OPTIMIZER_DOMAIN) . "</label></th><td><input type='checkbox' id='ewww_image_optimizer_enable_cloudinary' name='ewww_image_optimizer_enable_cloudinary' value='true' " . (ewww_image_optimizer_get_option('ewww_image_optimizer_enable_cloudinary') == TRUE ? "checked='true'" : "") . " /> " . __('When enabled, uploads to the Media Library will be transferred to Cloudinary after optimization. Cloudinary generates resizes, so only the full-size image is uploaded.', EWWW_IMAGE_OPTIMIZER_DOMAIN) . "</td></tr>\n";
        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_CLOUD) {
        $output[] = "<input id='ewww_image_optimizer_optipng_level' name='ewww_image_optimizer_optipng_level' type='hidden' value='2'>\n" . "<input id='ewww_image_optimizer_pngout_level' name='ewww_image_optimizer_pngout_level' type='hidden' value='2'>\n";
    } else {
        $output[] = "<tr class='nocloud'><th><label for='ewww_image_optimizer_optipng_level'>" . __('optipng optimization level', EWWW_IMAGE_OPTIMIZER_DOMAIN) . "</label></th>\n" . "<td><span><select id='ewww_image_optimizer_optipng_level' name='ewww_image_optimizer_optipng_level'>\n" . "<option value='1'" . (ewww_image_optimizer_get_option('ewww_image_optimizer_optipng_level') == 1 ? " selected='selected'" : "") . '>' . sprintf(__('Level %d', EWWW_IMAGE_OPTIMIZER_DOMAIN), 1) . ': ' . sprintf(__('%d trial', EWWW_IMAGE_OPTIMIZER_DOMAIN), 1) . "</option>\n" . "<option value='2'" . (ewww_image_optimizer_get_option('ewww_image_optimizer_optipng_level') == 2 ? " selected='selected'" : "") . '>' . sprintf(__('Level %d', EWWW_IMAGE_OPTIMIZER_DOMAIN), 2) . ': ' . sprintf(__('%d trials', EWWW_IMAGE_OPTIMIZER_DOMAIN), 8) . "</option>\n" . "<option value='3'" . (ewww_image_optimizer_get_option('ewww_image_optimizer_optipng_level') == 3 ? " selected='selected'" : "") . '>' . sprintf(__('Level %d', EWWW_IMAGE_OPTIMIZER_DOMAIN), 3) . ': ' . sprintf(__('%d trials', EWWW_IMAGE_OPTIMIZER_DOMAIN), 16) . "</option>\n" . "<option value='4'" . (ewww_image_optimizer_get_option('ewww_image_optimizer_optipng_level') == 4 ? " selected='selected'" : "") . '>' . sprintf(__('Level %d', EWWW_IMAGE_OPTIMIZER_DOMAIN), 4) . ': ' . sprintf(__('%d trials', EWWW_IMAGE_OPTIMIZER_DOMAIN), 24) . "</option>\n" . "<option value='5'" . (ewww_image_optimizer_get_option('ewww_image_optimizer_optipng_level') == 5 ? " selected='selected'" : "") . '>' . sprintf(__('Level %d', EWWW_IMAGE_OPTIMIZER_DOMAIN), 5) . ': ' . sprintf(__('%d trials', EWWW_IMAGE_OPTIMIZER_DOMAIN), 48) . "</option>\n" . "</select> (" . __('default', EWWW_IMAGE_OPTIMIZER_DOMAIN) . "=2)</span>\n" . "<p class='description'>" . __('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_pngout_level'>" . __('pngout optimization level', EWWW_IMAGE_OPTIMIZER_DOMAIN) . "</label></th>\n" . "<td><span><select id='ewww_image_optimizer_pngout_level' name='ewww_image_optimizer_pngout_level'>\n" . "<option value='0'" . (ewww_image_optimizer_get_option('ewww_image_optimizer_pngout_level') == 0 ? " selected='selected'" : "") . '>' . sprintf(__('Level %d', EWWW_IMAGE_OPTIMIZER_DOMAIN), 0) . ': ' . __('Xtreme! (Slowest)', EWWW_IMAGE_OPTIMIZER_DOMAIN) . "</option>\n" . "<option value='1'" . (ewww_image_optimizer_get_option('ewww_image_optimizer_pngout_level') == 1 ? " selected='selected'" : "") . '>' . sprintf(__('Level %d', EWWW_IMAGE_OPTIMIZER_DOMAIN), 1) . ': ' . __('Intense (Slow)', EWWW_IMAGE_OPTIMIZER_DOMAIN) . "</option>\n" . "<option value='2'" . (ewww_image_optimizer_get_option('ewww_image_optimizer_pngout_level') == 2 ? " selected='selected'" : "") . '>' . sprintf(__('Level %d', EWWW_IMAGE_OPTIMIZER_DOMAIN), 2) . ': ' . __('Longest Match (Fast)', EWWW_IMAGE_OPTIMIZER_DOMAIN) . "</option>\n" . "<option value='3'" . (ewww_image_optimizer_get_option('ewww_image_optimizer_pngout_level') == 3 ? " selected='selected'" : "") . '>' . sprintf(__('Level %d', EWWW_IMAGE_OPTIMIZER_DOMAIN), 3) . ': ' . __('Huffman Only (Faster)', EWWW_IMAGE_OPTIMIZER_DOMAIN) . "</option>\n" . "</select> (" . __('default', EWWW_IMAGE_OPTIMIZER_DOMAIN) . "=2)</span>\n" . "<p class='description'>" . sprintf(__('If you have CPU cycles to spare, go with level %d', EWWW_IMAGE_OPTIMIZER_DOMAIN), 0) . "</p></td></tr>\n";
        ewwwio_debug_message("pngout level: " . ewww_image_optimizer_get_option('ewww_image_optimizer_pngout_level'));
    }
    $output[] = "<tr><th><label for='ewww_image_optimizer_auto'>" . __('Scheduled optimization', EWWW_IMAGE_OPTIMIZER_DOMAIN) . "</label></th><td><input type='checkbox' id='ewww_image_optimizer_auto' name='ewww_image_optimizer_auto' value='true' " . (ewww_image_optimizer_get_option('ewww_image_optimizer_auto') == TRUE ? "checked='true'" : "") . " /> " . __('This will enable scheduled optimization of unoptimized images for your theme, buddypress, and any additional folders you have configured below. Runs hourly: wp_cron only runs when your site is visited, so it may be even longer between optimizations.', EWWW_IMAGE_OPTIMIZER_DOMAIN) . "</td></tr>\n";
    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'>" . __('Folders to optimize', EWWW_IMAGE_OPTIMIZER_DOMAIN) . "</label></th><td>" . sprintf(__('One path per line, must be within %s. Use full paths, not relative paths.', EWWW_IMAGE_OPTIMIZER_DOMAIN), ABSPATH) . "<br>\n";
    $output[] = "<textarea id='ewww_image_optimizer_aux_paths' name='ewww_image_optimizer_aux_paths' rows='3' cols='60'>" . (($aux_paths = ewww_image_optimizer_get_option('ewww_image_optimizer_aux_paths')) ? implode("\n", $aux_paths) : "") . "</textarea>\n";
    $output[] = "<p class='description'>" . __('Provide paths containing images to be optimized using "Scan and Optimize" on the Bulk Optimize page or by Scheduled Optimization.', EWWW_IMAGE_OPTIMIZER_DOMAIN) . "</p></td></tr>\n";
    if (!empty($aux_paths)) {
        ewwwio_debug_message("folders to optimize:");
        foreach ($aux_paths as $aux_path) {
            ewwwio_debug_message($aux_path);
        }
    }
    ewwwio_debug_message("deferred optimization: " . (ewww_image_optimizer_get_option('ewww_image_optimizer_defer') == TRUE ? "on" : "off"));
    $output[] = "<tr><th><label for='ewww_image_optimizer_defer'>" . __('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'" : "") . " /> " . __('Optimize images later via wp_cron, after image upload or generation is complete.', EWWW_IMAGE_OPTIMIZER_DOMAIN) . "</td></tr>\n";
    $output[] = "<tr><th><label for='ewww_image_optimizer_noauto'>" . __('Disable Automatic Optimization', EWWW_IMAGE_OPTIMIZER_DOMAIN) . "</label></th><td><input type='checkbox' id='ewww_image_optimizer_noauto' name='ewww_image_optimizer_noauto' value='true' " . (ewww_image_optimizer_get_option('ewww_image_optimizer_noauto') == TRUE ? "checked='true'" : "") . " /> " . __('Images will not be optimized on upload. Images may be optimized with the Bulk Optimize tools or with Scheduled optimization.', EWWW_IMAGE_OPTIMIZER_DOMAIN) . "</td></tr>\n";
    ewwwio_debug_message("disable auto-optimization: " . (ewww_image_optimizer_get_option('ewww_image_optimizer_noauto') == TRUE ? "on" : "off"));
    $output[] = "<tr><th><label for='ewww_image_optimizer_include_media_paths'>" . __('Include Media Library Folders', EWWW_IMAGE_OPTIMIZER_DOMAIN) . "</label></th><td><input type='checkbox' id='ewww_image_optimizer_include_media_paths' name='ewww_image_optimizer_include_media_paths' value='true' " . (ewww_image_optimizer_get_option('ewww_image_optimizer_include_media_paths') == TRUE ? "checked='true'" : "") . " /> " . __('If you have disabled automatic optimization, enable this if you want Scheduled Optimization to include the latest two folders from the Media Library.', EWWW_IMAGE_OPTIMIZER_DOMAIN) . "</td></tr>\n";
    ewwwio_debug_message("include media library: " . (ewww_image_optimizer_get_option('ewww_image_optimizer_include_media_paths') == TRUE ? "on" : "off"));
    $output[] = "<tr><th>" . __('Disable Resizes', EWWW_IMAGE_OPTIMIZER_DOMAIN) . "</th><td><p>" . __('Wordpress, your theme, and other plugins generate various image sizes. You may disable optimization for certain sizes, or completely prevent those sizes from being created.', EWWW_IMAGE_OPTIMIZER_DOMAIN) . "</p>\n";
    $image_sizes = ewww_image_optimizer_get_image_sizes();
    $disabled_sizes = ewww_image_optimizer_get_option('ewww_image_optimizer_disable_resizes');
    $disabled_sizes_opt = ewww_image_optimizer_get_option('ewww_image_optimizer_disable_resizes_opt');
    $output[] = '<table><tr><th>' . __('Disable Optimization', EWWW_IMAGE_OPTIMIZER_DOMAIN) . '</th><th>' . __('Disable Creation', EWWW_IMAGE_OPTIMIZER_DOMAIN) . "</th></tr>\n";
    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'>" . __('Skip Small Images', EWWW_IMAGE_OPTIMIZER_DOMAIN) . "</label></th><td><input type='text' id='ewww_image_optimizer_skip_size' name='ewww_image_optimizer_skip_size' size='8' value='" . ewww_image_optimizer_get_option('ewww_image_optimizer_skip_size') . "'> " . __('Do not optimize images smaller than this (in bytes)', EWWW_IMAGE_OPTIMIZER_DOMAIN) . "</td></tr>\n";
    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'>" . __('Skip Large PNG Images', EWWW_IMAGE_OPTIMIZER_DOMAIN) . "</label></th><td><input type='text' id='ewww_image_optimizer_skip_png_size' name='ewww_image_optimizer_skip_png_size' size='8' value='" . ewww_image_optimizer_get_option('ewww_image_optimizer_skip_png_size') . "'> " . __('Do not optimize PNG images larger than this (in bytes)', EWWW_IMAGE_OPTIMIZER_DOMAIN) . "</td></tr>\n";
    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'>" . __('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'>" . __('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'>" . __('Use System Paths', EWWW_IMAGE_OPTIMIZER_DOMAIN) . "</label></th><td><input type='checkbox' id='ewww_image_optimizer_skip_bundle' name='ewww_image_optimizer_skip_bundle' value='true' " . (ewww_image_optimizer_get_option('ewww_image_optimizer_skip_bundle') == TRUE ? "checked='true'" : "") . " /> " . sprintf(__('If you have already installed the utilities in a system location, such as %s or %s, use this to force the plugin to use those versions and skip the auto-installers.', EWWW_IMAGE_OPTIMIZER_DOMAIN), '/usr/local/bin', '/usr/bin') . "</td></tr>\n";
    ewwwio_debug_message("use system binaries: " . (ewww_image_optimizer_get_option('ewww_image_optimizer_skip_bundle') == TRUE ? "yes" : "no"));
    $output[] = "<tr class='nocloud'><th><label for='ewww_image_optimizer_disable_jpegtran'>" . __('disable', EWWW_IMAGE_OPTIMIZER_DOMAIN) . " jpegtran</label></th><td><input type='checkbox' id='ewww_image_optimizer_disable_jpegtran' name='ewww_image_optimizer_disable_jpegtran' " . (ewww_image_optimizer_get_option('ewww_image_optimizer_disable_jpegtran') == TRUE ? "checked='true'" : "") . " /></td></tr>\n";
    ewwwio_debug_message("jpegtran disabled: " . (ewww_image_optimizer_get_option('ewww_image_optimizer_disable_jpegtran') == TRUE ? "yes" : "no"));
    $output[] = "<tr class='nocloud'><th><label for='ewww_image_optimizer_disable_optipng'>" . __('disable', EWWW_IMAGE_OPTIMIZER_DOMAIN) . " optipng</label></th><td><input type='checkbox' id='ewww_image_optimizer_disable_optipng' name='ewww_image_optimizer_disable_optipng' " . (ewww_image_optimizer_get_option('ewww_image_optimizer_disable_optipng') == TRUE ? "checked='true'" : "") . " /></td></tr>\n";
    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'>" . __('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_disable_gifsicle'>" . __('disable', EWWW_IMAGE_OPTIMIZER_DOMAIN) . " gifsicle</label></th><td><input type='checkbox' id='ewww_image_optimizer_disable_gifsicle' name='ewww_image_optimizer_disable_gifsicle' " . (ewww_image_optimizer_get_option('ewww_image_optimizer_disable_gifsicle') == TRUE ? "checked='true'" : "") . " /></td></tr>\n";
    ewwwio_debug_message("gifsicle disabled: " . (ewww_image_optimizer_get_option('ewww_image_optimizer_disable_gifsicle') == TRUE ? "yes" : "no"));
    $output[] = "</table>\n</div>\n";
    $output[] = "<div id='ewww-conversion-settings'>\n";
    $output[] = "<p>" . __('Conversion is only available for images in the Media Library (except WebP). By default, all images have a link available in the Media Library for one-time conversion. Turning on individual conversion operations below will enable conversion filters any time an image is uploaded or modified.', EWWW_IMAGE_OPTIMIZER_DOMAIN) . "<br />\n" . "<b>" . __('NOTE:', EWWW_IMAGE_OPTIMIZER_DOMAIN) . "</b> " . __('The plugin will attempt to update image locations for any posts that contain the images. You may still need to manually update locations/urls for converted images.', EWWW_IMAGE_OPTIMIZER_DOMAIN) . "\n" . "</p>\n";
    $output[] = "<table class='form-table'>\n";
    $output[] = "<tr><th><label for='ewww_image_optimizer_disable_convert_links'>" . __('Hide Conversion Links', EWWW_IMAGE_OPTIMIZER_DOMAIN) . "</label</th><td><input type='checkbox' id='ewww_image_optimizer_disable_convert_links' name='ewww_image_optimizer_disable_convert_links' " . (ewww_image_optimizer_get_option('ewww_image_optimizer_disable_convert_links') == TRUE ? "checked='true'" : "") . " /> " . __('Site or Network admins can use this to prevent other users from using the conversion links in the Media Library which bypass the settings below.', EWWW_IMAGE_OPTIMIZER_DOMAIN) . "</td></tr>\n";
    $output[] = "<tr><th><label for='ewww_image_optimizer_delete_originals'>" . __('Delete originals', EWWW_IMAGE_OPTIMIZER_DOMAIN) . "</label></th><td><input type='checkbox' id='ewww_image_optimizer_delete_originals' name='ewww_image_optimizer_delete_originals' " . (ewww_image_optimizer_get_option('ewww_image_optimizer_delete_originals') == TRUE ? "checked='true'" : "") . " /> " . __('This will remove the original image from the server after a successful conversion.', EWWW_IMAGE_OPTIMIZER_DOMAIN) . "</td></tr>\n";
    $output[] = "<tr><th><label for='ewww_image_optimizer_webp'>" . __('JPG/PNG to WebP', EWWW_IMAGE_OPTIMIZER_DOMAIN) . "</label></th><td><span><input type='checkbox' id='ewww_image_optimizer_webp' name='ewww_image_optimizer_webp' value='true' " . (ewww_image_optimizer_get_option('ewww_image_optimizer_webp') == TRUE ? "checked='true'" : "") . " /> <b>" . __('WARNING:', EWWW_IMAGE_OPTIMIZER_DOMAIN) . '</b> ' . __('JPG to WebP conversion is lossy, but quality loss is minimal. PNG to WebP conversion is lossless.', EWWW_IMAGE_OPTIMIZER_DOMAIN) . "</span>\n" . "<p class='description'>" . __('Originals are never deleted, and WebP images should only be served to supported browsers.', EWWW_IMAGE_OPTIMIZER_DOMAIN) . " <a href='#webp-rewrite'>" . __('You can use the rewrite rules below to serve WebP images with Apache.', EWWW_IMAGE_OPTIMIZER_DOMAIN) . "</a></td></tr>\n";
    ewwwio_debug_message("webp conversion: " . (ewww_image_optimizer_get_option('ewww_image_optimizer_webp') == TRUE ? "on" : "off"));
    $output[] = "<tr><th><label for='ewww_image_optimizer_webp_for_cdn'>" . __('Alternative WebP Rewriting', EWWW_IMAGE_OPTIMIZER_DOMAIN) . "</label></th><td><span><input type='checkbox' id='ewww_image_optimizer_webp_for_cdn' name='ewww_image_optimizer_webp_for_cdn' value='true' " . (ewww_image_optimizer_get_option('ewww_image_optimizer_webp_for_cdn') == TRUE ? "checked='true'" : "") . " /> " . __('Uses output buffering and libxml functionality from PHP. Use this if the Apache rewrite rules do not work, or if your images are served from a CDN.', EWWW_IMAGE_OPTIMIZER_DOMAIN) . "</span></td></tr>";
    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'>" . __('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'" : "" ) . " /> " . __('Uses output buffering and libxml functionality from PHP. Use this if the Apache rewrite rules do not work, or if your images are served from a CDN.', EWWW_IMAGE_OPTIMIZER_DOMAIN) .  "</span></td></tr>";
    $output[] = "<tr><th><label for='ewww_image_optimizer_jpg_to_png'>" . sprintf(__('enable %s to %s conversion', EWWW_IMAGE_OPTIMIZER_DOMAIN), 'JPG', 'PNG') . "</label></th><td><span><input type='checkbox' id='ewww_image_optimizer_jpg_to_png' name='ewww_image_optimizer_jpg_to_png' " . (ewww_image_optimizer_get_option('ewww_image_optimizer_jpg_to_png') == TRUE ? "checked='true'" : "") . " /> <b>" . __('WARNING:', EWWW_IMAGE_OPTIMIZER_DOMAIN) . "</b> " . __('Removes metadata and increases cpu usage dramatically.', EWWW_IMAGE_OPTIMIZER_DOMAIN) . "</span>\n" . "<p class='description'>" . __('PNG is generally much better than JPG for logos and other images with a limited range of colors. Checking this option will slow down JPG processing significantly, and you may want to enable it only temporarily.', EWWW_IMAGE_OPTIMIZER_DOMAIN) . "</p></td></tr>\n";
    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(__('enable %s to %s conversion', EWWW_IMAGE_OPTIMIZER_DOMAIN), 'PNG', 'JPG') . "</label></th><td><span><input type='checkbox' id='ewww_image_optimizer_png_to_jpg' name='ewww_image_optimizer_png_to_jpg' " . (ewww_image_optimizer_get_option('ewww_image_optimizer_png_to_jpg') == TRUE ? "checked='true'" : "") . " /> <b>" . __('WARNING:', EWWW_IMAGE_OPTIMIZER_DOMAIN) . "</b> " . __('This is not a lossless conversion.', EWWW_IMAGE_OPTIMIZER_DOMAIN) . "</span>\n" . "<p class='description'>" . __('JPG is generally much better than PNG for photographic use because it compresses the image and discards data. PNGs with transparency are not converted by default.', EWWW_IMAGE_OPTIMIZER_DOMAIN) . "</p>\n" . "<span><label for='ewww_image_optimizer_jpg_background'> " . __('JPG background color:', EWWW_IMAGE_OPTIMIZER_DOMAIN) . "</label> #<input type='text' id='ewww_image_optimizer_jpg_background' name='ewww_image_optimizer_jpg_background' size='6' value='" . ewww_image_optimizer_jpg_background() . "' /> <span style='padding-left: 12px; font-size: 12px; border: solid 1px #555555; background-color: #" . ewww_image_optimizer_jpg_background() . "'>&nbsp;</span> " . __('HEX format (#123def)', EWWW_IMAGE_OPTIMIZER_DOMAIN) . ".</span>\n" . "<p class='description'>" . __('Background color is used only if the PNG has transparency. Leave this value blank to skip PNGs with transparency.', EWWW_IMAGE_OPTIMIZER_DOMAIN) . "</p>\n" . "<span><label for='ewww_image_optimizer_jpg_quality'>" . __('JPG quality level:', EWWW_IMAGE_OPTIMIZER_DOMAIN) . "</label> <input type='text' id='ewww_image_optimizer_jpg_quality' name='ewww_image_optimizer_jpg_quality' class='small-text' value='" . ewww_image_optimizer_jpg_quality() . "' /> " . __('Valid values are 1-100.', EWWW_IMAGE_OPTIMIZER_DOMAIN) . "</span>\n" . "<p class='description'>" . __('If JPG quality is blank, the plugin will attempt to set the optimal quality level or default to 92. Remember, this is a lossy conversion, so you are losing pixels, and it is not recommended to actually set the level here unless you want noticable loss of image quality.', EWWW_IMAGE_OPTIMIZER_DOMAIN) . "</p></td></tr>\n";
    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(__('enable %s to %s conversion', EWWW_IMAGE_OPTIMIZER_DOMAIN), 'GIF', 'PNG') . "</label></th><td><span><input type='checkbox' id='ewww_image_optimizer_gif_to_png' name='ewww_image_optimizer_gif_to_png' " . (ewww_image_optimizer_get_option('ewww_image_optimizer_gif_to_png') == TRUE ? "checked='true'" : "") . " /> " . __('No warnings here, just do it.', EWWW_IMAGE_OPTIMIZER_DOMAIN) . "</span>\n" . "<p class='description'> " . __('PNG is generally better than GIF, but animated images cannot be converted.', EWWW_IMAGE_OPTIMIZER_DOMAIN) . "</p></td></tr>\n";
    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='" . __('Save Changes', EWWW_IMAGE_OPTIMIZER_DOMAIN) . "' /></p>\n";
    $output[] = "</form>\n";
    if (ewww_image_optimizer_get_option('ewww_image_optimizer_webp') && !ewww_image_optimizer_get_option('ewww_image_optimizer_webp_for_cdn')) {
        $output[] = "<form id='ewww-webp-rewrite'>\n";
        $output[] = "<p>" . __('There are many ways to serve WebP images to visitors with supported browsers. You may choose any you wish, but it is recommended to serve them with an .htaccess file using mod_rewrite and mod_headers. The plugin can insert the rules for you if the file is writable, or you can edit .htaccess yourself.', EWWW_IMAGE_OPTIMIZER_DOMAIN) . "</p>\n";
        if (!ewww_image_optimizer_webp_rewrite_verify()) {
            $output[] = "<img id='webp-image' src='" . plugins_url('/test.png', __FILE__) . "' style='float: right; padding: 0 0 10px 10px;'>\n" . "<p id='ewww-webp-rewrite-status'><b>" . __('Rules verified successfully', EWWW_IMAGE_OPTIMIZER_DOMAIN) . "</b></p>\n";
            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('/test.png', __FILE__) . "' style='float: right; padding-left: 10px;'>\n" . "<p id='ewww-webp-rewrite-status'>" . __('The image to the right will display a WebP image with WEBP in white text, if your site is serving WebP images and your browser supports WebP.', EWWW_IMAGE_OPTIMIZER_DOMAIN) . "</p>\n" . "<button type='submit' class='button-secondary action'>" . __('Insert Rewrite Rules', EWWW_IMAGE_OPTIMIZER_DOMAIN) . "</button>\n";
            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>" . __('Support EWWW I.O.', EWWW_IMAGE_OPTIMIZER_DOMAIN) . "</h2>\n" . "<p>" . __('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/'>" . __('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'>" . __('Write a review.', EWWW_IMAGE_OPTIMIZER_DOMAIN) . "</a></p>\n" . "<p>" . 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>") . "</p>\n" . "<p>" . __('Use any of these referral links to show your appreciation:', EWWW_IMAGE_OPTIMIZER_DOMAIN) . "</p>\n" . "<p><b>" . __('Web Hosting:', EWWW_IMAGE_OPTIMIZER_DOMAIN) . "</b><br>\n" . "<a href='https://partners.a2hosting.com/solutions.php?id=5959&url=638'>A2 Hosting:</a> " . _x('with automatic EWWW IO setup', 'A2 Hosting:', EWWW_IMAGE_OPTIMIZER_DOMAIN) . "<br>\n" . "<a href='http://www.dreamhost.com/r.cgi?132143'>Dreamhost</a><br>\n" . "<a href='http://www.bluehost.com/track/nosilver4u'>Bluehost</a><!-- <br>\n" . "<a href='http://www.liquidweb.com/?RID=nosilver4u'>liquidweb</a><br>\n" . "<a href='http://www.stormondemand.com/?RID=nosilver4u'>Storm on Demand</a>-->\n" . "</p>\n" . "<p><b>" . _x('VPS:', 'abbreviation for Virtual Private Server', EWWW_IMAGE_OPTIMIZER_DOMAIN) . "</b><br>\n" . "<a href='http://www.bluehost.com/track/nosilver4u?page=/vps'>Bluehost</a><br>\n" . "<a href='https://www.digitalocean.com/?refcode=89ef0197ec7e'>DigitalOcean</a><br>\n" . "<a href='https://clientarea.ramnode.com/aff.php?aff=1469'>RamNode</a><br>\n" . "<a href='http://www.vultr.com/?ref=6814210'>VULTR</a>\n" . "</p>\n" . "<p><b>" . _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'>" . __('Add MaxCDN to increase website speeds dramatically! Sign Up Now and Save 25%.', EWWW_IMAGE_OPTIMIZER_DOMAIN) . "</a> " . __('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>' . __('Debugging Information', EWWW_IMAGE_OPTIMIZER_DOMAIN) . ':</b> <button onclick="selectText(' . "'ewww-debug-info'" . ')">' . __('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__);
}
Beispiel #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;
}
 /**
  * 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();
 }
Beispiel #14
0
 protected function handle()
 {
     session_write_close();
     if (empty($_POST['ewwwio_size'])) {
         $size = '';
     } else {
         $size = $_POST['ewwwio_size'];
     }
     if (!empty($_POST['ewwwio_path']) && $size == 'full') {
         $file_path = ABSPATH . $_POST['ewwwio_path'];
         ewwwio_debug_message('processing async optimization request');
         list($file, $msg, $conv, $original) = ewww_image_optimizer($file_path, 1, false, false, true);
     } elseif (!empty($_POST['ewwwio_path'])) {
         $file_path = ABSPATH . $_POST['ewwwio_path'];
         ewwwio_debug_message('processing async optimization request');
         list($file, $msg, $conv, $original) = ewww_image_optimizer($file_path);
     } else {
         ewwwio_debug_message('ignored async optimization request');
         return;
     }
     ewwwio_debug_message('checking for: ' . $file_path . '.processing');
     if (is_file($file_path . '.processing')) {
         ewwwio_debug_message('removing ' . $file_path . '.processing');
         unlink($file_path . '.processing');
     }
     ewww_image_optimizer_debug_log();
 }
Beispiel #15
0
function ewww_image_optimizer_image_queue_debug()
{
    ewwwio_debug_message('<b>' . __FUNCTION__ . '()</b>');
    // let user clear a queue, or all queues
    if (isset($_POST['ewww_image_optimizer_clear_queue']) && current_user_can('manage_options') && wp_verify_nonce($_POST['ewww_nonce'], 'ewww_image_optimizer_clear_queue')) {
        if (is_numeric($_POST['ewww_image_optimizer_clear_queue'])) {
            global $ewwwio_media_background;
            if (!class_exists('WP_Background_Process')) {
                require_once EWWW_IMAGE_OPTIMIZER_PLUGIN_PATH . 'background.php';
            }
            if (!is_object($ewwwio_media_background)) {
                $ewwwio_media_background = new EWWWIO_Media_Background_Process();
            }
            ewwwio_debug_message("backgrounding optimization for {$ID}");
            $queues = (int) $_POST['ewww_image_optimizer_clear_queue'];
            while ($queues) {
                $ewwwio_media_background->cancel_process();
                $queues--;
            }
            if (!empty($_POST['ids']) && preg_match('/^[\\d,]+$/', $_POST['ids'], $request_ids)) {
                $ids = explode(',', $request_ids[0]);
                foreach ($ids as $id) {
                    delete_transient('ewwwio-background-in-progress-' . $id);
                }
            }
        } else {
            delete_site_option(sanitize_text_field($_POST['ewww_image_optimizer_clear_queue']));
            if (!empty($_POST['ids']) && preg_match('/^[\\d,]+$/', $_POST['ids'], $request_ids)) {
                $ids = explode(',', $request_ids[0]);
                foreach ($ids as $id) {
                    delete_transient('ewwwio-background-in-progress-' . $id);
                }
            }
        }
    }
    echo "<div class='wrap'><h1>" . esc_html__('Image Queue Debugging', EWWW_IMAGE_OPTIMIZER_DOMAIN) . "</h1>";
    global $wpdb;
    $table = $wpdb->options;
    $column = 'option_name';
    $key_column = 'option_id';
    $value_column = 'option_value';
    if (is_multisite()) {
        $table = $wpdb->sitemeta;
        $column = 'meta_key';
        $key_column = 'meta_id';
        $value_column = 'meta_value';
    }
    $key = 'wp_ewwwio_media_optimize_batch_%';
    $queues = $wpdb->get_results($wpdb->prepare("\n\t\t\tSELECT *\n\t\t\tFROM {$table}\n\t\t\tWHERE {$column} LIKE %s\n\t\t\tORDER BY {$key_column} ASC\n\t\t\t", $key), ARRAY_A);
    $nonce = wp_create_nonce('ewww_image_optimizer_clear_queue');
    if (empty($queues)) {
        esc_html_e('Nothing to see here, go upload some images!', EWWW_IMAGE_OPTIMIZER_DOMAIN);
    } else {
        $all_ids = array();
        foreach ($queues as $queue) {
            $ids = array();
            echo "<strong>{$queue[$key_column]}</strong> - {$queue[$column]}<br>";
            $items = maybe_unserialize($queue[$value_column]);
            foreach ($items as $item) {
                echo "{$item['id']} - {$item['type']}<br>";
                $all_ids[] = $item['id'];
                $ids[] = $item['id'];
            }
            $ids = implode(',', $ids);
            ?>
	<form id="ewww-queue-clear-<?php 
            echo $queue[$key_column];
            ?>
" method="post" style="margin-bottom: 1.5em;" action="">
			<input type="hidden" id="ewww_nonce" name="ewww_nonce" value="<?php 
            echo $nonce;
            ?>
">
			<input type="hidden" name="ewww_image_optimizer_clear_queue" value="<?php 
            echo $queue[$column];
            ?>
">
			<input type="hidden" name="ids" value="<?php 
            echo $ids;
            ?>
">
			<button type="submit" class="button-secondary action"><?php 
            esc_html_e('Clear this queue', EWWW_IMAGE_OPTIMIZER_DOMAIN);
            ?>
</button>
		</form>
<?php 
        }
        $all_ids = implode(',', $all_ids);
        ?>
		<form id="ewww-queue-clear-all" method="post" style="margin: 2em 0;" action="">
			<input type="hidden" id="ewww_nonce" name="ewww_nonce" value="<?php 
        echo $nonce;
        ?>
">
			<input type="hidden" name="ewww_image_optimizer_clear_queue" value="<?php 
        echo count($queues);
        ?>
">
			<input type="hidden" name="ids" value="<?php 
        echo $all_ids;
        ?>
">
			<button type="submit" class="button-secondary action"><?php 
        esc_html_e('Clear all queues', EWWW_IMAGE_OPTIMIZER_DOMAIN);
        ?>
</button>
		</form>
<?php 
    }
}