AJAX Thumbnail Rebuild - Version 1.01

Version Description

  • Tested with Wordpress 3.0
Download this release

Release Info

Developer junkcoder
Plugin Icon wp plugin AJAX Thumbnail Rebuild
Version 1.01
Comparing to
See all releases

Version 1.01

Files changed (3) hide show
  1. ajax-thumbnail-rebuild.php +140 -0
  2. readme.txt +34 -0
  3. screenshot-1.jpg +0 -0
ajax-thumbnail-rebuild.php ADDED
@@ -0,0 +1,140 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /* Plugin name: AJAX Thumbnail Rebuild
3
+ Plugin URI: http://breiti.cc/wordpress/ajax-thumbnail-rebuild
4
+ Author: junkcoder
5
+ Author URI: http://breiti.cc
6
+ Version: 1.01
7
+ Description: Rebuild all thumbnails
8
+ Max WP Version: 3.0
9
+
10
+ This program is free software; you can redistribute it and/or modify
11
+ it under the terms of the GNU General Public License as published by
12
+ the Free Software Foundation; either version 2 of the License, or
13
+ (at your option) any later version.
14
+
15
+ This program is distributed in the hope that it will be useful,
16
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
17
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18
+ GNU General Public License for more details.
19
+
20
+ You should have received a copy of the GNU General Public License
21
+ along with this program; if not, write to the Free Software
22
+ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
23
+ */
24
+
25
+ class AjaxThumbnailRebuild {
26
+
27
+ function AjaxThumbnailRebuild() {
28
+ add_action( 'admin_menu', array(&$this, 'addAdminMenu') );
29
+ }
30
+
31
+ function addAdminMenu() {
32
+ add_management_page( __( 'Rebuild all Thumbnails', 'ajax-thumbnail-rebuild' ), __( 'Rebuild Thumbnails', 'ajax_thumbnail_rebuild'
33
+ ), 'manage_options', 'ajax-thumbnail-rebuild', array(&$this, 'ManagementPage') );
34
+ }
35
+
36
+ function ManagementPage() {
37
+
38
+ ?>
39
+ <div id="message" class="updated fade" style="display:none"></div>
40
+ <div id="thumb" style="display:none">Last thumbnail: <img id="thumb-img" /></div>
41
+ <script type="text/javascript">
42
+ // <![CDATA[
43
+
44
+ function setMessage(msg) {
45
+ jQuery("#message").html(msg);
46
+ jQuery("#message").show();
47
+ }
48
+
49
+ function regenerate() {
50
+ jQuery("#ajax_thumbnail_rebuild").attr("disabled", true);
51
+ setMessage("<p>Reading attachments...</p>");
52
+ jQuery.ajax({
53
+ url: "<?php bloginfo('wpurl'); ?>/wp-admin/admin-ajax.php",
54
+ type: "POST",
55
+ data: "action=ajax_thumbnail_rebuild&do=getlist",
56
+ success: function(result) {
57
+ var list = eval(result);
58
+ var curr = 0;
59
+
60
+ function regenItem() {
61
+ if (curr >= list.length) {
62
+ jQuery("#ajax_thumbnail_rebuild").removeAttr("disabled");
63
+ jQuery("#thumb").hide();
64
+ setMessage("Done.");
65
+ return;
66
+ }
67
+ setMessage("Regenerating " + (curr+1) + " of " + list.length + " (" + list[curr].title + ")...");
68
+
69
+ jQuery.ajax({
70
+ url: "<?php bloginfo('wpurl'); ?>/wp-admin/admin-ajax.php",
71
+ type: "POST",
72
+ data: "action=ajax_thumbnail_rebuild&do=regen&id=" + list[curr].id,
73
+ success: function(result) {
74
+ jQuery("#thumb").show();
75
+ jQuery("#thumb-img").attr("src",result);
76
+
77
+ curr = curr + 1;
78
+ regenItem();
79
+ }
80
+ });
81
+ }
82
+
83
+ regenItem();
84
+ },
85
+ error: function(request, status, error) {
86
+ setMessage("Error " + request.status);
87
+ }
88
+ });
89
+ }
90
+
91
+ // ]]>
92
+ </script>
93
+
94
+ <form method="post" action="">
95
+ <p>
96
+ <input type="button" onClick="javascript:regenerate();" class="button" name="ajax_thumbnail_rebuild" id="ajax_thumbnail_rebuild"
97
+ value="<?php _e( 'Regenerate All Thumbnails', 'ajax-thumbnail-rebuild' ) ?>" />
98
+ </p>
99
+ </form>
100
+ <p>If you find this plugin useful, I'd be happy to read your comments on the <a href="http://breiti.cc/wordpress/ajax-thumbnail-rebuild" target="_blank">plugin homepage</a>.<br />If you experience any problems, feel free to leave a comment too.</p>
101
+ <?php
102
+ }
103
+
104
+ };
105
+
106
+ add_action('wp_ajax_ajax_thumbnail_rebuild', ajax_thumbnail_rebuild_ajax);
107
+
108
+ function ajax_thumbnail_rebuild_ajax() {
109
+ $action = $_POST["do"];
110
+
111
+ if ($action == "getlist") {
112
+ $attachments =& get_children( array(
113
+ 'post_type' => 'attachment',
114
+ 'post_mime_type' => 'image',
115
+ 'numberposts' => -1,
116
+ 'post_status' => null,
117
+ 'post_parent' => null, // any parent
118
+ 'output' => 'object',
119
+ ) );
120
+
121
+ foreach ( $attachments as $attachment ) {
122
+ $res[] = array('id' => $attachment->ID, 'title' => $attachment->post_title);
123
+ }
124
+ die( json_encode($res) );
125
+ } else if ($action == "regen") {
126
+ $id = $_POST["id"];
127
+
128
+ $fullsizepath = get_attached_file( $id );
129
+
130
+ if ( FALSE !== $fullsizepath && @file_exists($fullsizepath) ) {
131
+ set_time_limit( 30 );
132
+ wp_update_attachment_metadata( $id, wp_generate_attachment_metadata( $id, $fullsizepath ) );
133
+ }
134
+
135
+ die( wp_get_attachment_thumb_url( $id ));
136
+ }
137
+ }
138
+
139
+ add_action( 'plugins_loaded', create_function( '', 'global $AjaxThumbnailRebuild; $AjaxThumbnailRebuild = new AjaxThumbnailRebuild();' ) );
140
+ ?>
readme.txt ADDED
@@ -0,0 +1,34 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ === AJAX Thumbnail Rebuild ===
2
+ Contributors: junkcoder
3
+ Tags: ajax, thumbnail, rebuild, regenerate, admin
4
+ Requires at least: 2.8
5
+ Tested up to: 3.0
6
+ Stable tag: 1.01
7
+
8
+ AJAX Thumbnail Rebuild allows you to rebuild all thumbnails at once without script timeouts on your server.
9
+
10
+ == Description ==
11
+
12
+ AJAX Thumbnail Rebuild allows you to rebuild all thumbnails on your site. There are already some plugins available for this, but they have one thing in common: All thumbnails are rebuilt in a single step. This works fine when you don’t have that many photos on your site. When you have a lot of full-size photos, the script on the server side takes a long time to run. Unfortunately the time a script is allowed to run is limited, which sets an upper limit to the number of thumbnails you can regenerate. This number depends on the server configuration and the computing power your server has available. When you get over this limit, you won’t be able to rebuild your thumbnails.
13
+
14
+ Why would you want to rebuild your thumbnails? Wordpress allows you to change the size of thumbnails. This way, you can make the size of thumbnails fit the design of your website. When you change the size to fit for a new theme, all future photos you are going to upload will have this new size. Your old thumbnails won’t be resized. That’s where this plugin comes into action. After changing the image sizes, you can rebuild all thumbnails. But instead of telling the server to recreate all thumbnails at once, they are rebuilt one after another. Rebuilding thumbnails for one photo won’t take all too long, so you won’t run into any script timeouts. Note that you still have to wait until all thumbnails have been rebuilt. If you close the page before the task is completed, you have to start all over again.
15
+
16
+ This plugin requires JavaScript to be enabled.
17
+
18
+ == Installation ==
19
+
20
+ Upload the plugin to your blog, activate it, done. You can then rebuild all thumbnails in the tools section (Tools -> Rebuild Thumbnails).
21
+
22
+ == Changelog ==
23
+
24
+ = 1.01 =
25
+
26
+ * Tested with Wordpress 3.0
27
+
28
+ = 1.0 =
29
+
30
+ * Initial release
31
+
32
+ == Screenshots ==
33
+
34
+ 1. Plugin in action
screenshot-1.jpg ADDED
Binary file