WordPress.org

Plugin Directory

Changeset 932085


Ignore:
Timestamp:
06/13/14 22:01:38 (3 years ago)
Author:
nosilver4u
Message:

more efficient checking of cloud api key on submission

Location:
ewww-image-optimizer/trunk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • ewww-image-optimizer/trunk/common.php

    r931529 r932085  
    165165    delete_option('ewww_image_optimizer_aux_attachments'); 
    166166    add_option('ewww_image_optimizer_aux_attachments', $bulk_attachments, '', 'no'); 
     167 
     168    // need to re-register the api_key for the sanitize function 
     169    $api_key = ewww_image_optimizer_get_option('ewww_image_optimizer_cloud_key'); 
     170    unregister_setting('ewww_image_optimizer_options', 'ewww_image_optimizer_cloud_key'); 
     171    register_setting('ewww_image_optimizer_options', 'ewww_image_optimizer_cloud_key', 'ewww_image_optimizer_cloud_key_sanitize'); 
     172    ewww_image_optimizer_set_option('ewww_image_optimizer_cloud_key', $api_key); 
     173 
    167174} 
    168175 
     
    670677} 
    671678 
     679// tells the user we could not verify the cloud api key 
     680/*function ewww_image_optimizer_notice_cloud_failed() { 
     681    global $ewww_debug; 
     682    $ewww_debug .= "<b>ewww_image_optimizer_notice_cloud_failed()</b><br>"; 
     683    echo "<div id='ewww-image-optimizer-warning-cloud' class='error'><p><strong>" . __('EWWW Image Optimizer was not able to verify your Cloud API Key.', EWWW_IMAGE_OPTIMIZER_DOMAIN) . "</strong></p></div>"; 
     684}*/ 
     685 
     686function ewww_image_optimizer_cloud_key_sanitize ( $key ) { 
     687    if ( ewww_image_optimizer_cloud_verify( false, $key ) ) { 
     688        return $key; 
     689    } else { 
     690        return ''; 
     691    } 
     692} 
     693  
    672694// submits the api key for verification 
    673 function ewww_image_optimizer_cloud_verify ( $cache = true ) { 
     695function ewww_image_optimizer_cloud_verify ( $cache = true, $api_key = '' ) { 
    674696    global $ewww_debug; 
    675697    global $ewww_cloud_ip; 
    676698    $ewww_debug .= "<b>ewww_image_optimizer_cloud_verify()</b><br>"; 
    677     $api_key = ewww_image_optimizer_get_option('ewww_image_optimizer_cloud_key'); 
     699    if ( empty( $api_key ) ) { 
     700        $api_key = ewww_image_optimizer_get_option('ewww_image_optimizer_cloud_key'); 
     701    } 
    678702    if (empty($api_key)) { 
    679703        update_site_option('ewww_image_optimizer_cloud_jpg', ''); 
     
    721745    } 
    722746    if (empty($verified)) { 
    723         // TODO: perhaps throw a notice on the admin screen instead of just disabling them 
    724         update_site_option('ewww_image_optimizer_cloud_jpg', ''); 
     747    //  update_option ( 'ewww_image_optimizer_cloud_verified', '' ); 
     748/*      update_site_option('ewww_image_optimizer_cloud_jpg', ''); 
    725749        update_site_option('ewww_image_optimizer_cloud_png', ''); 
    726750        update_site_option('ewww_image_optimizer_cloud_gif', ''); 
    727751        update_option('ewww_image_optimizer_cloud_jpg', ''); 
    728752        update_option('ewww_image_optimizer_cloud_png', ''); 
    729         update_option('ewww_image_optimizer_cloud_gif', ''); 
     753        update_option('ewww_image_optimizer_cloud_gif', '');*/ 
    730754        return FALSE; 
    731755    } else { 
     
    774798function ewww_image_optimizer_cloud_optimizer($file, $type, $convert = false, $newfile = null, $newtype = null, $fullsize = false, $jpg_params = array('r' => '255', 'g' => '255', 'b' => '255', 'quality' => null)) { 
    775799    global $ewww_debug; 
    776     ewww_image_optimizer_cloud_verify(false);  
     800    if ( ! ewww_image_optimizer_cloud_verify(false) ) {  
     801        return array($file, false, 'key verification failed', 0); 
     802    } 
    777803    global $ewww_exceed; 
    778804    global $ewww_cloud_ip; 
     
    857883    if (is_wp_error($response)) { 
    858884        $error_message = $response->get_error_message(); 
    859         $ewww_debug .= "verification failed: $error_message <br>"; 
    860         return array(0, false, null); 
     885        $ewww_debug .= "optimize failed: $error_message <br>"; 
     886        return array($file, false, 'cloud optimize failed', 0); 
    861887    } elseif (empty($response['body'])) { 
    862         return array(0, false, null); 
     888        return array($file, false, 'empty server response', 0); 
    863889    } else { 
    864890        $tempfile = $file . ".tmp"; 
     
    15931619    } 
    15941620    return $option_value; 
     1621} 
     1622 
     1623// set an option: use 'site' setting if plugin is network activated, otherwise use 'blog' setting 
     1624function ewww_image_optimizer_set_option ($option_name, $option_value) { 
     1625    if (function_exists('is_plugin_active_for_network') && is_plugin_active_for_network(plugin_basename(EWWW_IMAGE_OPTIMIZER_PLUGIN_FILE))) { 
     1626        $success = update_site_option($option_name, $option_value); 
     1627    } else { 
     1628        $success = update_option($option_name, $option_value); 
     1629    } 
     1630    return $success; 
    15951631} 
    15961632 
  • ewww-image-optimizer/trunk/ewww-image-optimizer.php

    r931529 r932085  
    22/** 
    33 * Integrate image optimizers into WordPress. 
    4  * @version 1.9.1.1 
     4 * @version 1.9.1.3 
    55 * @package EWWW_Image_Optimizer 
    66 */ 
     
    1111Author: Shane Bishop 
    1212Text Domain: ewww-image-optimizer 
    13 Version: 1.9.1.1 
     13Version: 1.9.1.3 
    1414Author URI: http://www.shanebishop.net/ 
    1515License: GPLv3 
     
    2424// this is the full system path to the plugin folder 
    2525define('EWWW_IMAGE_OPTIMIZER_PLUGIN_PATH', plugin_dir_path(__FILE__)); 
    26 define('EWWW_IMAGE_OPTIMIZER_VERSION', '191.1'); 
     26define('EWWW_IMAGE_OPTIMIZER_VERSION', '191.3'); 
    2727 
    2828require_once(EWWW_IMAGE_OPTIMIZER_PLUGIN_PATH . 'common.php'); 
     
    4444        update_option('ewww_image_optimizer_version', EWWW_IMAGE_OPTIMIZER_VERSION); 
    4545    } 
    46 //  ewww_image_optimizer_cloud_verify(); 
    4746    if (!defined('EWWW_IMAGE_OPTIMIZER_CLOUD') && ewww_image_optimizer_get_option('ewww_image_optimizer_cloud_jpg') && ewww_image_optimizer_get_option('ewww_image_optimizer_cloud_png') && ewww_image_optimizer_get_option('ewww_image_optimizer_cloud_gif')) { 
    4847        define('EWWW_IMAGE_OPTIMIZER_CLOUD', TRUE); 
     
    6362    } 
    6463    ewww_image_optimizer_init(); 
     64/*  if ( ewww_image_optimizer_get_option( 'ewww_image_optimizer_cloud_key' ) && ! get_option( 'ewww_image_optimizer_cloud_verified' ) && ! ewww_image_optimizer_cloud_verify( false ) ) { 
     65        add_action('network_admin_notices', 'ewww_image_optimizer_notice_cloud_failed'); 
     66        add_action('admin_notices', 'ewww_image_optimizer_notice_cloud_failed'); 
     67    }*/ 
    6568    // Check if this is an unsupported OS (not Linux or Mac OSX or FreeBSD or Windows or SunOS) 
    6669    if(EWWW_IMAGE_OPTIMIZER_CLOUD) { 
     
    177180    register_setting('ewww_image_optimizer_options', 'ewww_image_optimizer_aux_attachments'); 
    178181    register_setting('ewww_image_optimizer_options', 'ewww_image_optimizer_aux_type'); 
    179     register_setting('ewww_image_optimizer_options', 'ewww_image_optimizer_cloud_key'); 
     182    register_setting('ewww_image_optimizer_options', 'ewww_image_optimizer_cloud_key', 'ewww_image_optimizer_cloud_key_sanitize'); 
    180183    register_setting('ewww_image_optimizer_options', 'ewww_image_optimizer_cloud_jpg'); 
    181184    register_setting('ewww_image_optimizer_options', 'ewww_image_optimizer_cloud_png'); 
  • ewww-image-optimizer/trunk/readme.txt

    r931968 r932085  
    213213* changed: made queries for resuming bulk operations more efficient to avoid running into max query length problems 
    214214* fixed: images that were not processed (cloud or otherwise) can be optimized later (they are no longer stored in ewwwio_images table) 
     215* changed: more efficient verification of cloud api keys 
    215216 
    216217= 1.9.1 = 
Note: See TracChangeset for help on using the changeset viewer.