wp-smushit
Last commit date
JSON
17 years ago
bulk.php
14 years ago
license.txt
17 years ago
readme.txt
13 years ago
screenshot-1.jpg
17 years ago
settings.php
13 years ago
wp-smushit.php
14 years ago
bulk.php
77 lines
| 1 | <div class="wrap"> |
| 2 | <div id="icon-upload" class="icon32"><br /></div><h2>Bulk WP Smush.it </h2> |
| 3 | |
| 4 | <?php |
| 5 | |
| 6 | if ( sizeof($attachments) < 1 ): |
| 7 | echo '<p>You don’t appear to have uploaded any images yet.</p>'; |
| 8 | else: |
| 9 | if ( empty($_POST) && !$auto_start ): // instructions page |
| 10 | ?> |
| 11 | <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> |
| 12 | |
| 13 | <p>It uploads each and every file to Yahoo! and then downloads the resulting file. It can take a long time.</p> |
| 14 | |
| 15 | <p>We found <?php echo sizeof($attachments); ?> images in your media library. Be forewarned, <strong>it will take <em>at least</em> <?php echo (sizeof($attachments) * 3 / 60); ?> minutes</strong> to process all these images if they have never been smushed before.</p> |
| 16 | |
| 17 | <p><em>N.B. If your server <tt>gzip</tt>s content you may not see the progress updates as your files are processed.</em></p> |
| 18 | |
| 19 | <p><strong>This is an experimental feature.</strong> Please post any feedback to the <a href="http://wordpress.org/tags/wp-smushit">WordPress WP Smush.it forums</a>.</p> |
| 20 | |
| 21 | <form method="post" action=""> |
| 22 | <?php wp_nonce_field( 'wp-smushit-bulk', '_wpnonce'); ?> |
| 23 | <button type="submit" class="button-secondary action">Run all my images through WP Smush.it right now</button> |
| 24 | </form> |
| 25 | |
| 26 | <?php |
| 27 | else: // run the script |
| 28 | |
| 29 | if (!wp_verify_nonce( $_REQUEST['_wpnonce'], 'wp-smushit-bulk' ) || !current_user_can( 'edit_others_posts' ) ) { |
| 30 | wp_die( __( 'Cheatin’ uh?' ) ); |
| 31 | } |
| 32 | |
| 33 | |
| 34 | ob_implicit_flush(true); |
| 35 | ob_end_flush(); |
| 36 | foreach( $attachments as $attachment ) { |
| 37 | printf( "<p>Processing <strong>%s</strong>…<br>", esc_html($attachment->post_name) ); |
| 38 | $original_meta = wp_get_attachment_metadata( $attachment->ID, true ); |
| 39 | |
| 40 | $meta = wp_smushit_resize_from_meta_data( $original_meta, $attachment->ID, false ); |
| 41 | |
| 42 | printf( "– %dx%d: ", intval($meta['width']), intval($meta['height']) ); |
| 43 | |
| 44 | if ( $original_meta['wp_smushit'] == $meta['wp_smushit'] && stripos( $meta['wp_smushit'], 'Smush.it error' ) === false ) { |
| 45 | echo 'already smushed' . $meta['wp_smushit']; |
| 46 | } else { |
| 47 | echo $meta['wp_smushit']; |
| 48 | } |
| 49 | echo '<br>'; |
| 50 | |
| 51 | |
| 52 | |
| 53 | if ( isset( $meta['sizes'] ) && is_array( $meta['sizes'] ) ) { |
| 54 | foreach( $meta['sizes'] as $size_name => $size ) { |
| 55 | printf( "– %dx%d: ", intval($size['width']), intval($size['height']) ); |
| 56 | if ( $original_meta['sizes'][$size_name]['wp_smushit'] == $size['wp_smushit'] && stripos( $meta['sizes'][$size_name]['wp_smushit'], 'Smush.it error' ) === false ) { |
| 57 | echo 'already smushed'; |
| 58 | } else { |
| 59 | echo $size['wp_smushit']; |
| 60 | } |
| 61 | echo '<br>'; |
| 62 | |
| 63 | } |
| 64 | } |
| 65 | echo "</p>"; |
| 66 | |
| 67 | wp_update_attachment_metadata( $attachment->ID, $meta ); |
| 68 | |
| 69 | // rate limiting is good manners, let's be nice to Yahoo! |
| 70 | sleep(0.5); |
| 71 | @ob_flush(); |
| 72 | flush(); |
| 73 | } |
| 74 | endif; |
| 75 | endif; |
| 76 | ?> |
| 77 | </div> |