Plugin Directory

Changeset 470314


Ignore:
Timestamp:
12/02/2011 07:01:15 PM (14 years ago)
Author:
junkcoder
Message:

Merge https://github.com/breiti/ajax-thumbnail-rebuild

Location:
ajax-thumbnail-rebuild/trunk
Files:
4 added
2 edited

Legend:

Unmodified
Added
Removed
  • ajax-thumbnail-rebuild/trunk/ajax-thumbnail-rebuild.php

    r408885 r470314  
    44   Author: junkcoder
    55   Author URI: http://breiti.cc
    6    Version: 1.05
     6   Version: 1.06
    77   Description: Rebuild all thumbnails
    8    Max WP Version: 3.0.1
     8   Max WP Version: 3.2.1
     9   Text Domain: ajax-thumbnail-rebuild
    910
    1011    This program is free software; you can redistribute it and/or modify
     
    3031
    3132    function addAdminMenu() {
    32         add_management_page( __( 'Rebuild all Thumbnails', 'ajax-thumbnail-rebuild' ), __( 'Rebuild Thumbnails', 'ajax_thumbnail_rebuild'
     33        add_management_page( __( 'Rebuild all Thumbnails', 'ajax-thumbnail-rebuild' ), __( 'Rebuild Thumbnails', 'ajax-thumbnail-rebuild'
    3334 ), 'manage_options', 'ajax-thumbnail-rebuild', array(&$this, 'ManagementPage') );
    3435    }
     
    4748        function regenerate() {
    4849            jQuery("#ajax_thumbnail_rebuild").attr("disabled", true);
    49             setMessage("<p>Reading attachments...</p>");
     50            setMessage("<p><?php _e('Reading attachments...', 'ajax-thumbnail-rebuild') ?></p>");
    5051
    5152            inputs = jQuery( 'input:checked' );
     
    5758            }
    5859
    59             var onlypostthumbs = jQuery("#onlypostthumbs").attr('checked') ? 1 : 0;
     60            var onlyfeatured = jQuery("#onlyfeatured").attr('checked') ? 1 : 0;
    6061
    6162            jQuery.ajax({
    62                 url: "<?php bloginfo('wpurl'); ?>/wp-admin/admin-ajax.php",
     63                url: "<?php echo admin_url('admin-ajax.php'); ?>",
    6364                type: "POST",
    64                 data: "action=ajax_thumbnail_rebuild&do=getlist&onlypostthumbs="+onlypostthumbs,
     65                data: "action=ajax_thumbnail_rebuild&do=getlist&onlyfeatured="+onlyfeatured,
    6566                success: function(result) {
    6667                    var list = eval(result);
    6768                    var curr = 0;
    6869
     70                    if (!list) {
     71                        setMessage("<?php _e('No attachments found.', 'ajax-thumbnail-rebuild')?>");
     72                        jQuery("#ajax_thumbnail_rebuild").removeAttr("disabled");
     73                        return;
     74                    }
     75
    6976                    function regenItem() {
    7077                        if (curr >= list.length) {
    7178                            jQuery("#ajax_thumbnail_rebuild").removeAttr("disabled");
    72                             setMessage("Done.");
     79                            setMessage("<?php _e('Done.', 'ajax-thumbnail-rebuild') ?>");
    7380                            return;
    7481                        }
    75                         setMessage("Regenerating " + (curr+1) + " of " + list.length + " (" + list[curr].title + ")...");
     82                        setMessage(<?php printf( __('"Rebuilding " + %s + " of " + %s + " (" + %s + ")..."', 'ajax-thumbnail-rebuild'), "(curr+1)", "list.length", "list[curr].title"); ?>);
    7683
    7784                        jQuery.ajax({
    78                             url: "<?php bloginfo('wpurl'); ?>/wp-admin/admin-ajax.php",
     85                            url: "<?php echo admin_url('admin-ajax.php'); ?>",
    7986                            type: "POST",
    8087                            data: "action=ajax_thumbnail_rebuild&do=regen&id=" + list[curr].id + thumbnails,
     
    9299                },
    93100                error: function(request, status, error) {
    94                     setMessage("Error " + request.status);
     101                    setMessage("<?php _e('Error', 'ajax-thumbnail-rebuild') ?>" + request.status);
    95102                }
    96103            });
    97104        }
    98105
     106        jQuery(document).ready(function() {
     107            jQuery('#size-toggle').click(function() {
     108                jQuery("#sizeselect").find("input[type=checkbox]").each(function() {
     109                    jQuery(this).attr("checked", !jQuery(this).attr("checked"));
     110                });
     111            });
     112        });
     113
    99114        // ]]>
    100115        </script>
    101116
    102117        <form method="post" action="" style="display:inline; float:left; padding-right:30px;">
    103             <h4>Select which thumbnails you want to rebuild:</h4>
    104             <p>
    105 
     118            <h4><?php _e('Select which thumbnails you want to rebuild', 'ajax-thumbnail-rebuild'); ?>:</h4>
     119            <a href="javascript:void(0);" id="size-toggle"><?php _e('Toggle all', 'ajax-thumbnail-rebuild'); ?></a>
     120            <div id="sizeselect">
    106121            <?php
    107             global $_wp_additional_image_sizes;
    108 
    109             foreach ( get_intermediate_image_sizes() as $s ):
    110 
    111                 if ( isset( $_wp_additional_image_sizes[$s]['width'] ) ) // For theme-added sizes
    112                     $width = intval( $_wp_additional_image_sizes[$s]['width'] );
    113                 else                                                     // For default sizes set in options
    114                     $width = get_option( "{$s}_size_w" );
    115 
    116                 if ( isset( $_wp_additional_image_sizes[$s]['height'] ) ) // For theme-added sizes
    117                     $height = intval( $_wp_additional_image_sizes[$s]['height'] );
    118                 else                                                      // For default sizes set in options
    119                     $height = get_option( "{$s}_size_h" );
    120 
    121                 if ( isset( $_wp_additional_image_sizes[$s]['crop'] ) )   // For theme-added sizes
    122                     $crop = intval( $_wp_additional_image_sizes[$s]['crop'] );
    123                 else                                                      // For default sizes set in options
    124                     $crop = get_option( "{$s}_crop" );
     122            foreach ( ajax_thumbnail_rebuild_get_sizes() as $s ):
    125123            ?>
    126124
    127                 <input type="checkbox" name="thumbnails[]" checked="checked" value="<?php echo $s ?>" />
     125                <input type="checkbox" name="thumbnails[]" id="sizeselect" checked="checked" value="<?php echo $s['name'] ?>" />
    128126                <label>
    129                     <em><?php echo $s ?></em> (width : <?php echo $width ?>, height : <?php echo $height ?>, crop : <?php echo $crop ?>)
     127                    <em><?php echo $s['name'] ?></em>
     128                    &nbsp;(<?php echo $s['width'] ?>x<?php echo $s['height'] ?>
     129                    <?php if ($s['crop']) _e('cropped', 'ajax-thumbnail-rebuild'); ?>)
    130130                </label>
    131131                <br/>
    132132            <?php endforeach;?>
     133            </div>
     134            <p>
     135                <input type="checkbox" id="onlyfeatured" name="onlyfeatured" />
     136                <label><?php _e('Only rebuild featured images', 'ajax-thumbnail-rebuild'); ?></label>
    133137            </p>
    134             <p>
    135                 <input type="checkbox" id="onlypostthumbs" name="onlypostthumbs" />
    136                 <label>Only rebuild post thumbnails</label>
    137             </p>
    138 
     138
     139            <p><?php _e("Note: If you've changed the dimensions of your thumbnails, existing thumbnail images will not be deleted.",
     140            'ajax-thumbnail-rebuild'); ?></p>
    139141            <input type="button" onClick="javascript:regenerate();" class="button"
    140142                   name="ajax_thumbnail_rebuild" id="ajax_thumbnail_rebuild"
    141                    value="<?php _e( 'Regenerate All Thumbnails', 'ajax-thumbnail-rebuild' ) ?>" />
     143                   value="<?php _e( 'Rebuild All Thumbnails', 'ajax-thumbnail-rebuild' ) ?>" />
    142144            <br />
    143145        </form>
    144146
    145         <div id="thumb" style="display:none;"><h4>Last image:</h4><img id="thumb-img" /></div>
     147        <div id="thumb" style="display:none;"><h4><?php _e('Last image', 'ajax-thumbnail-rebuild'); ?>:</h4><img id="thumb-img" /></div>
    146148
    147149        <p style="clear:both; padding-top:2em;">
    148         If you find this plugin useful, I'd be happy to read your comments on
    149         the <a href="http://breiti.cc/wordpress/ajax-thumbnail-rebuild" target="_blank">plugin homepage</a>.<br />
    150         If you experience any problems, feel free to leave a comment too.
     150        <?php printf( __("If you find this plugin useful, I'd be happy to read your comments on the %splugin homepage%s. If you experience any problems, feel free to leave a comment too.",
     151                 'ajax-thumbnail-rebuild'),
     152                     '<a href="http://breiti.cc/wordpress/ajax-thumbnail-rebuild" target="_blank">', '</a>');
     153        ?>
    151154        </p>
    152155
     
    161164    $action = $_POST["do"];
    162165    $thumbnails = isset( $_POST['thumbnails'] )? $_POST['thumbnails'] : NULL;
    163     $onlypostthumbs = isset( $_POST['onlypostthumbs'] ) ? $_POST['onlypostthumbs'] : 0;
     166    $onlyfeatured = isset( $_POST['onlyfeatured'] ) ? $_POST['onlyfeatured'] : 0;
    164167
    165168    if ($action == "getlist") {
    166169
    167         if ($onlypostthumbs) {
     170        if ($onlyfeatured) {
    168171            /* Get all featured images */
    169             $featured_images = $wpdb->get_results( "SELECT meta_value FROM {$wpdb->postmeta}
    170                                                 WHERE meta_key = '_thumbnail_id'" );
    171 
    172             $thumbs = array();
     172            $featured_images = $wpdb->get_results( "SELECT meta_value,{$wpdb->posts}.post_title AS title FROM {$wpdb->postmeta}, {$wpdb->posts}
     173                                                WHERE meta_key = '_thumbnail_id' AND {$wpdb->postmeta}.post_id={$wpdb->posts}.ID");
     174
    173175            foreach($featured_images as $image) {
    174                 array_push($thumbs, $image->meta_value);
     176                $res[] = array('id' => $image->meta_value, 'title' => $image->title);
    175177            }
    176             $attachments =& get_children( array(
    177                 'post_type' => 'attachment',
    178                 'post_mime_type' => 'image',
    179                 'numberposts' => -1,
    180                 'post_status' => null,
    181                 'post_in' => $thumbs,
    182                 'output' => 'object',
    183             ) );
    184 
    185178        } else {
    186179            $attachments =& get_children( array(
     
    192185                'output' => 'object',
    193186            ) );
    194         }
    195 
    196         foreach ( $attachments as $attachment ) {
    197             $res[] = array('id' => $attachment->ID, 'title' => $attachment->post_title);
    198         }
     187            foreach ( $attachments as $attachment ) {
     188                $res[] = array('id' => $attachment->ID, 'title' => $attachment->post_title);
     189            }
     190        }
     191
    199192        die( json_encode($res) );
    200193    } else if ($action == "regen") {
     
    215208add_action( 'plugins_loaded', create_function( '', 'global $AjaxThumbnailRebuild; $AjaxThumbnailRebuild = new AjaxThumbnailRebuild();' ) );
    216209
     210function ajax_thumbnail_rebuild_get_sizes() {
     211    global $_wp_additional_image_sizes;
     212
     213    foreach ( get_intermediate_image_sizes() as $s ) {
     214        $sizes[$s] = array( 'name' => '', 'width' => '', 'height' => '', 'crop' => FALSE );
     215
     216        /* Read theme added sizes or fall back to default sizes set in options... */
     217
     218        $sizes[$s]['name'] = $s;
     219
     220        if ( isset( $_wp_additional_image_sizes[$s]['width'] ) )
     221            $sizes[$s]['width'] = intval( $_wp_additional_image_sizes[$s]['width'] );
     222        else
     223            $sizes[$s]['width'] = get_option( "{$s}_size_w" );
     224
     225        if ( isset( $_wp_additional_image_sizes[$s]['height'] ) )
     226            $sizes[$s]['height'] = intval( $_wp_additional_image_sizes[$s]['height'] );
     227        else
     228            $sizes[$s]['height'] = get_option( "{$s}_size_h" );
     229
     230        if ( isset( $_wp_additional_image_sizes[$s]['crop'] ) )
     231            $sizes[$s]['crop'] = intval( $_wp_additional_image_sizes[$s]['crop'] );
     232        else
     233            $sizes[$s]['crop'] = get_option( "{$s}_crop" );
     234    }
     235
     236    return $sizes;
     237}
    217238
    218239/**
     
    239260        $metadata['file'] = _wp_relative_upload_path($file);
    240261
    241         // make thumbnails and other intermediate sizes
    242         global $_wp_additional_image_sizes;
    243 
    244         foreach ( get_intermediate_image_sizes() as $s ) {
    245             $sizes[$s] = array( 'width' => '', 'height' => '', 'crop' => FALSE );
    246             if ( isset( $_wp_additional_image_sizes[$s]['width'] ) )
    247                 $sizes[$s]['width'] = intval( $_wp_additional_image_sizes[$s]['width'] ); // For theme-added sizes
     262        $sizes = ajax_thumbnail_rebuild_get_sizes();
     263        $sizes = apply_filters( 'intermediate_image_sizes_advanced', $sizes );
     264
     265        foreach ($sizes as $size => $size_data ) {
     266            if( isset( $thumbnails ) && !in_array( $size, $thumbnails ))
     267                $metadata['sizes'][$size] = image_get_intermediate_size( $attachment_id, $size_data['name'] );
    248268            else
    249                 $sizes[$s]['width'] = get_option( "{$s}_size_w" ); // For default sizes set in options
    250             if ( isset( $_wp_additional_image_sizes[$s]['height'] ) )
    251                 $sizes[$s]['height'] = intval( $_wp_additional_image_sizes[$s]['height'] ); // For theme-added sizes
    252             else
    253                 $sizes[$s]['height'] = get_option( "{$s}_size_h" ); // For default sizes set in options
    254             if ( isset( $_wp_additional_image_sizes[$s]['crop'] ) )
    255                 $sizes[$s]['crop'] = intval( $_wp_additional_image_sizes[$s]['crop'] ); // For theme-added sizes
    256             else
    257                 $sizes[$s]['crop'] = get_option( "{$s}_crop" ); // For default sizes set in options
    258         }
    259 
    260         $sizes = apply_filters( 'intermediate_image_sizes_advanced', $sizes );
    261 
    262         foreach ($sizes as $size => $size_data ) {
    263             if( isset( $thumbnails ) )
    264                 if( !in_array( $size, $thumbnails ) )
    265                     continue;
    266 
    267             $resized = image_make_intermediate_size( $file, $size_data['width'], $size_data['height'], $size_data['crop'] );
    268 
    269             if ( $resized )
    270                 $metadata['sizes'][$size] = $resized;
     269                $metadata['sizes'][$size] = image_make_intermediate_size( $file, $size_data['width'], $size_data['height'], $size_data['crop'] );
    271270        }
    272271
     
    281280}
    282281
     282load_plugin_textdomain('ajax-thumbnail-rebuild', false, basename( dirname( __FILE__ ) ) . '/languages' );
     283
    283284?>
  • ajax-thumbnail-rebuild/trunk/readme.txt

    r408876 r470314  
    33Tags: ajax, thumbnail, rebuild, regenerate, admin
    44Requires at least: 2.8
    5 Tested up to: 3.2
    6 Stable tag: 1.05
     5Tested up to: 3.2.1
     6Stable tag: 1.06
    77
    88AJAX Thumbnail Rebuild allows you to rebuild all thumbnails at once without script timeouts on your server.
     
    2323
    2424== Changelog ==
     25
     26= 1.06 =
     27
     28* FIX: Don't forget metadata for sizes that aren't rebuilt.
     29* FIX: Option to only rebuild featured images should now work correctly.
     30* FIX: Don't fail if there are no attachments.
     31* NEW: It's now possible to toggle all selected sizes.
     32* NEW: Added translation: German.
    2533
    2634= 1.05 =
Note: See TracChangeset for help on using the changeset viewer.