WordPress.org

Plugin Directory

Changeset 462810


Ignore:
Timestamp:
11/14/11 19:31:12 (2 years ago)
Author:
alexdunae
Message:

Many updates -- should have committed more frequently :(

Location:
wp-smushit/trunk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • wp-smushit/trunk/bulk.php

    r450014 r462810  
    77    echo '<p>You don’t appear to have uploaded any images yet.</p>'; 
    88  else:  
    9     if ( empty($_POST) ): // instructions page 
     9    if ( empty($_POST) && !$auto_start ): // instructions page 
    1010?> 
    1111  <p>This tool will run all of the images in your media library through the WP Smush.it web service.  It won't re-smush images that were successfully smushed before. It will retry images that were not successfully smushed.</p> 
     
    2020 
    2121  <form method="post" action=""> 
    22     <?php wp_nonce_field( 'wp-smushit-bulk', '_wp-smushit-bulk-nonce'); ?> 
     22    <?php wp_nonce_field( 'wp-smushit-bulk', '_wpnonce'); ?> 
    2323    <button type="submit" class="button-secondary action">Run all my images through WP Smush.it right now</button> 
    2424  </form> 
     
    2727      else: // run the script 
    2828   
    29       if (!wp_verify_nonce( $_POST['_wp-smushit-bulk-nonce'], 'wp-smushit-bulk' ) || !current_user_can( 'edit_others_posts' ) ) { 
     29      if (!wp_verify_nonce( $_REQUEST['_wpnonce'], 'wp-smushit-bulk' ) || !current_user_can( 'edit_others_posts' ) ) { 
    3030                wp_die( __( 'Cheatin&#8217; uh?' ) ); 
    3131      } 
    3232 
     33 
    3334      ob_implicit_flush(true); 
    3435      ob_end_flush(); 
    35  
    3636      foreach( $attachments as $attachment ) { 
    3737        printf( "<p>Processing <strong>%s</strong>&hellip;<br>", esc_html($attachment->post_name) ); 
     
    4242        printf( "– %dx%d: ", intval($meta['width']), intval($meta['height']) ); 
    4343         
    44         if ( $original_meta['wp_smushit'] == $meta['wp_smushit'] ) { 
    45           echo 'already smushed'; 
     44        if ( $original_meta['wp_smushit'] == $meta['wp_smushit'] && stripos( $meta['wp_smushit'], 'Smush.it error' ) === false ) { 
     45          echo 'already smushed' . $meta['wp_smushit']; 
    4646        } else { 
    4747          echo $meta['wp_smushit']; 
     
    5454          foreach( $meta['sizes'] as $size_name => $size  ) { 
    5555            printf( "– %dx%d: ", intval($size['width']), intval($size['height']) ); 
    56              
    57             if ( $original_meta['sizes'][$size_name]['wp_smushit'] == $size['wp_smushit'] ) { 
     56            if ( $original_meta['sizes'][$size_name]['wp_smushit'] == $size['wp_smushit'] && stripos( $meta['sizes'][$size_name]['wp_smushit'], 'Smush.it error' ) === false ) { 
    5857              echo 'already smushed'; 
    5958            } else { 
  • wp-smushit/trunk/readme.txt

    r453514 r462810  
    11=== WP Smush.it === 
    22Plugin Name: WP Smush.it 
    3 Version: 1.4.3 
     3Version: 1.5.0 
    44Author: Dialect 
    55Author URI: http://dialect.ca/?wp_smush_it 
     
    99Tested up to: 3.2.1 
    1010Stable tag: 1.4.3 
     11Donate link: http://dunae.ca/donate.html 
    1112 
    1213Reduce image file sizes and improve performance using the <a href="http://smush.it/">Smush.it</a> API within WordPress. 
     
    3132As of version 1.4.0 there is a new, experimental `Bulk Smush.it` feature.  You can find the link under the `Media Library` tab. 
    3233 
     34= NextGEN Gallery = 
     35NextGEN user?  Also download the <a href="http://wordpress.org/extend/plugins/wp-smushit-nextgen-gallery-integration/">WP Smush.it NextGEN Integration</a> plugin. 
     36 
    3337= Privacy =  
    3438Be sure you&rsquo;re comfortable with Smush.it&rsquo;s privacy policy (found on their <a href="http://info.yahoo.com/legal/us/yahoo/smush_it/smush_it-4378.html">FAQ</a>). 
     39 
     40= Donate? = 
     41 
     42If you're so inclined, I've setup <a href="http://dunae.ca/donate.html">a donation page</a>. 
    3543 
    3644= Updates, etc... = 
     
    4957 
    5058== Changelog == 
     59 
     60= 1.5.0 = 
     61* added basic integration for the <a href="http://wordpress.org/extend/plugins/wp-smushit-nextgen-gallery-integration/">NextGEN gallery plugin</a> 
     62* add support for media bulk action dropdown 
     63* compatibility with WordPress earlier than 3.1 
     64* added a <a href="http://dunae.ca/donate.html">donate link</a> 
    5165 
    5266= 1.4.3 = 
  • wp-smushit/trunk/wp-smushit.php

    r453514 r462810  
    11<?php 
    2 /** 
    3  * Integrate the Smush.it API into WordPress. 
    4  * @version 1.4.3 
    5  * @package WP_SmushIt 
    6  */ 
    72/* 
    83Plugin Name: WP Smush.it 
     
    105Description: Reduce image file sizes and improve performance using the <a href="http://smush.it/">Smush.it</a> API within WordPress. 
    116Author: Dialect 
    12 Version: 1.4.3 
     7Version: 1.5.0 
    138Author URI: http://dialect.ca/ 
    149*/ 
     
    2924 
    3025define('WP_SMUSHIT_DOMAIN', 'wp_smushit'); 
    31 define('WP_SMUSHIT_UA', 'WP Smush.it/1.4.3 (+http://dialect.ca/code/wp-smushit)'); 
     26define('WP_SMUSHIT_UA', 'WP Smush.it/1.5.0 (+http://dialect.ca/code/wp-smushit)'); 
    3227define('WP_SMUSHIT_PLUGIN_DIR', dirname(plugin_basename(__FILE__))); 
    3328 
     
    4843    load_plugin_textdomain(WP_SMUSHIT_DOMAIN); 
    4944    wp_enqueue_script('common'); 
    50          
    5145} 
    5246 
     
    6357  @ini_set('zlib.output_compression', 0); 
    6458  @ini_set('implicit_flush', 1); 
    65   $attachments = get_posts( array( 
    66     'numberposts' => -1, 
    67     'post_type' => 'attachment', 
    68     'post_mime_type' => 'image' 
    69   )); 
     59   
     60  $attachments = null; 
     61  $auto_start = false; 
     62   
     63  if ( isset($_REQUEST['ids'])) { 
     64    $attachments = get_posts( array( 
     65      'numberposts' => -1, 
     66      'include' => explode(',', $_REQUEST['ids']), 
     67      'post_type' => 'attachment', 
     68      'post_mime_type' => 'image' 
     69    )); 
     70    $auto_start = true; 
     71  } else { 
     72    $attachments = get_posts( array( 
     73      'numberposts' => -1, 
     74      'post_type' => 'attachment', 
     75      'post_mime_type' => 'image' 
     76    )); 
     77  } 
     78   
     79 
    7080  require( dirname(__FILE__) . '/bulk.php' ); 
    7181} 
     
    102112 * 
    103113 * @param   string $file            Full absolute path to the image file 
     114 * @param   string $file_url        Optional full URL to the image file 
    104115 * @returns array 
    105116 */ 
    106 function wp_smushit($file) { 
     117function wp_smushit($file, $file_url = null) { 
    107118    // don't run on localhost, IPv4 and IPv6 checks 
    108119    // if( in_array($_SERVER['SERVER_ADDR'], array('127.0.0.1', '::1')) ) 
     
    115126     
    116127    $file_path = $file; 
    117  
    118128    // check that the file exists 
    119129    if ( FALSE === file_exists($file_path) || FALSE === is_file($file_path) ) { 
     
    132142    $wp_upload_dir = $upload_dir['basedir']; 
    133143    $wp_upload_url = $upload_dir['baseurl']; 
    134     if ( 0 !== stripos(realpath($file_path), realpath($wp_upload_dir)) ) { 
     144    if ( 0 !== stripos(realpath($file_path), realpath(ABSPATH)) ) { 
    135145        $msg = sprintf(__("<span class='code'>%s</span> must be within the content directory (<span class='code'>%s</span>)", WP_SMUSHIT_DOMAIN), htmlentities($file_path), $wp_upload_dir); 
    136146 
     
    138148    } 
    139149 
    140     // determine the public URL 
    141     $file_url = str_replace( $wp_upload_dir, $wp_upload_url, $file ); 
     150  if ( !$file_url ) { 
     151    // determine the public URL 
     152    $file_url = str_replace( $wp_upload_dir, $wp_upload_url, $file ); 
     153    } 
    142154 
    143155    $data = wp_smushit_post($file_url); 
     
    223235function wp_smushit_resize_from_meta_data($meta, $ID = null, $force_resmush = true) { 
    224236    $file_path = $meta['file']; 
    225  
    226237    $store_absolute_path = true; 
    227238    $upload_dir = wp_upload_dir(); 
     
    229240 
    230241    // WordPress >= 2.6.2: determine the absolute $file_path (http://core.trac.wordpress.org/changeset/8796) 
    231     if ( FALSE === strpos($file, WP_CONTENT_DIR) ) { 
     242    if ( FALSE === strpos($file,  $upload_path) ) { 
    232243        $store_absolute_path = false; 
    233244        $file_path =  $upload_path . $file_path; 
    234245    } 
     246     
     247 
     248     
    235249 
    236250  if ( $force_resmush || wp_smushit_should_resmush(  @$meta['wp_smushit'] ) ) { 
     
    238252    $meta['wp_smushit'] = $msg; 
    239253  } 
    240    
     254 
    241255    // strip absolute path for Wordpress >= 2.6.2 
    242256    if ( FALSE === $store_absolute_path ) { 
     
    334348    } 
    335349} 
     350 
     351add_action( 'admin_head-upload.php', 'wp_smushit_add_bulk_actions_via_javascript' ); 
     352 
     353// Borrowed from http://www.viper007bond.com/wordpress-plugins/regenerate-thumbnails/ 
     354function wp_smushit_add_bulk_actions_via_javascript() { ?> 
     355        <script type="text/javascript"> 
     356            jQuery(document).ready(function($){ 
     357                $('select[name^="action"] option:last-child').before('<option value="bulk_smushit">Bulk Smush.it</option>'); 
     358            }); 
     359        </script> 
     360<?php } 
     361 
     362 
     363add_action( 'admin_action_bulk_smushit', 'wp_smushit_bulk_action_handler' ); 
     364 
     365// Handles the bulk actions POST 
     366// Borrowed from http://www.viper007bond.com/wordpress-plugins/regenerate-thumbnails/ 
     367function wp_smushit_bulk_action_handler() { 
     368    check_admin_referer( 'bulk-media' ); 
     369 
     370    if ( empty( $_REQUEST['media'] ) || ! is_array( $_REQUEST['media'] ) ) 
     371        return; 
     372 
     373    $ids = implode( ',', array_map( 'intval', $_REQUEST['media'] ) ); 
     374 
     375 
     376    // Can't use wp_nonce_url() as it escapes HTML entities 
     377    wp_redirect( add_query_arg( '_wpnonce', wp_create_nonce( 'wp-smushit-bulk' ), admin_url( 'upload.php?page=wp-smushit-bulk&goback=1&ids=' . $ids ) ) ); 
     378    exit(); 
     379} 
     380 
    336381/** 
    337382 * http_request_timeout filter -- bumped up to 25 seconds for larger images 
     
    340385    return 25; 
    341386} 
     387 
     388 
     389if ( function_exists( 'wp_basename' ) === false ) { 
     390  /** 
     391   * Introduced in WP 3.1... this is copied verbatim from wp-includes/formatting.php. 
     392   */ 
     393  function wp_basename( $path, $suffix = '' ) { 
     394    return urldecode( basename( str_replace( '%2F', '/', urlencode( $path ) ), $suffix ) ); 
     395  } 
     396} 
Note: See TracChangeset for help on using the changeset viewer.