Changeset 470314
- Timestamp:
- 12/02/2011 07:01:15 PM (14 years ago)
- Location:
- ajax-thumbnail-rebuild/trunk
- Files:
-
- 4 added
- 2 edited
-
ajax-thumbnail-rebuild.php (modified) (10 diffs)
-
languages (added)
-
languages/ajax-thumbnail-rebuild-de_DE.mo (added)
-
languages/ajax-thumbnail-rebuild-de_DE.po (added)
-
languages/ajax-thumbnail-rebuild.pot (added)
-
readme.txt (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
ajax-thumbnail-rebuild/trunk/ajax-thumbnail-rebuild.php
r408885 r470314 4 4 Author: junkcoder 5 5 Author URI: http://breiti.cc 6 Version: 1.0 56 Version: 1.06 7 7 Description: Rebuild all thumbnails 8 Max WP Version: 3.0.1 8 Max WP Version: 3.2.1 9 Text Domain: ajax-thumbnail-rebuild 9 10 10 11 This program is free software; you can redistribute it and/or modify … … 30 31 31 32 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' 33 34 ), 'manage_options', 'ajax-thumbnail-rebuild', array(&$this, 'ManagementPage') ); 34 35 } … … 47 48 function regenerate() { 48 49 jQuery("#ajax_thumbnail_rebuild").attr("disabled", true); 49 setMessage("<p> Reading attachments...</p>");50 setMessage("<p><?php _e('Reading attachments...', 'ajax-thumbnail-rebuild') ?></p>"); 50 51 51 52 inputs = jQuery( 'input:checked' ); … … 57 58 } 58 59 59 var only postthumbs = jQuery("#onlypostthumbs").attr('checked') ? 1 : 0;60 var onlyfeatured = jQuery("#onlyfeatured").attr('checked') ? 1 : 0; 60 61 61 62 jQuery.ajax({ 62 url: "<?php bloginfo('wpurl'); ?>/wp-admin/admin-ajax.php",63 url: "<?php echo admin_url('admin-ajax.php'); ?>", 63 64 type: "POST", 64 data: "action=ajax_thumbnail_rebuild&do=getlist&only postthumbs="+onlypostthumbs,65 data: "action=ajax_thumbnail_rebuild&do=getlist&onlyfeatured="+onlyfeatured, 65 66 success: function(result) { 66 67 var list = eval(result); 67 68 var curr = 0; 68 69 70 if (!list) { 71 setMessage("<?php _e('No attachments found.', 'ajax-thumbnail-rebuild')?>"); 72 jQuery("#ajax_thumbnail_rebuild").removeAttr("disabled"); 73 return; 74 } 75 69 76 function regenItem() { 70 77 if (curr >= list.length) { 71 78 jQuery("#ajax_thumbnail_rebuild").removeAttr("disabled"); 72 setMessage(" Done.");79 setMessage("<?php _e('Done.', 'ajax-thumbnail-rebuild') ?>"); 73 80 return; 74 81 } 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"); ?>); 76 83 77 84 jQuery.ajax({ 78 url: "<?php bloginfo('wpurl'); ?>/wp-admin/admin-ajax.php",85 url: "<?php echo admin_url('admin-ajax.php'); ?>", 79 86 type: "POST", 80 87 data: "action=ajax_thumbnail_rebuild&do=regen&id=" + list[curr].id + thumbnails, … … 92 99 }, 93 100 error: function(request, status, error) { 94 setMessage(" Error" + request.status);101 setMessage("<?php _e('Error', 'ajax-thumbnail-rebuild') ?>" + request.status); 95 102 } 96 103 }); 97 104 } 98 105 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 99 114 // ]]> 100 115 </script> 101 116 102 117 <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"> 106 121 <?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 ): 125 123 ?> 126 124 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'] ?>" /> 128 126 <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 (<?php echo $s['width'] ?>x<?php echo $s['height'] ?> 129 <?php if ($s['crop']) _e('cropped', 'ajax-thumbnail-rebuild'); ?>) 130 130 </label> 131 131 <br/> 132 132 <?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> 133 137 </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> 139 141 <input type="button" onClick="javascript:regenerate();" class="button" 140 142 name="ajax_thumbnail_rebuild" id="ajax_thumbnail_rebuild" 141 value="<?php _e( 'Re generateAll Thumbnails', 'ajax-thumbnail-rebuild' ) ?>" />143 value="<?php _e( 'Rebuild All Thumbnails', 'ajax-thumbnail-rebuild' ) ?>" /> 142 144 <br /> 143 145 </form> 144 146 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> 146 148 147 149 <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 ?> 151 154 </p> 152 155 … … 161 164 $action = $_POST["do"]; 162 165 $thumbnails = isset( $_POST['thumbnails'] )? $_POST['thumbnails'] : NULL; 163 $only postthumbs = isset( $_POST['onlypostthumbs'] ) ? $_POST['onlypostthumbs'] : 0;166 $onlyfeatured = isset( $_POST['onlyfeatured'] ) ? $_POST['onlyfeatured'] : 0; 164 167 165 168 if ($action == "getlist") { 166 169 167 if ($only postthumbs) {170 if ($onlyfeatured) { 168 171 /* 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 173 175 foreach($featured_images as $image) { 174 array_push($thumbs, $image->meta_value);176 $res[] = array('id' => $image->meta_value, 'title' => $image->title); 175 177 } 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 185 178 } else { 186 179 $attachments =& get_children( array( … … 192 185 'output' => 'object', 193 186 ) ); 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 199 192 die( json_encode($res) ); 200 193 } else if ($action == "regen") { … … 215 208 add_action( 'plugins_loaded', create_function( '', 'global $AjaxThumbnailRebuild; $AjaxThumbnailRebuild = new AjaxThumbnailRebuild();' ) ); 216 209 210 function 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 } 217 238 218 239 /** … … 239 260 $metadata['file'] = _wp_relative_upload_path($file); 240 261 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'] ); 248 268 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'] ); 271 270 } 272 271 … … 281 280 } 282 281 282 load_plugin_textdomain('ajax-thumbnail-rebuild', false, basename( dirname( __FILE__ ) ) . '/languages' ); 283 283 284 ?> -
ajax-thumbnail-rebuild/trunk/readme.txt
r408876 r470314 3 3 Tags: ajax, thumbnail, rebuild, regenerate, admin 4 4 Requires at least: 2.8 5 Tested up to: 3.2 6 Stable tag: 1.0 55 Tested up to: 3.2.1 6 Stable tag: 1.06 7 7 8 8 AJAX Thumbnail Rebuild allows you to rebuild all thumbnails at once without script timeouts on your server. … … 23 23 24 24 == 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. 25 33 26 34 = 1.05 =
Note: See TracChangeset
for help on using the changeset viewer.