Ticket #1776: image-fu.diff

File image-fu.diff, 24.0 KB (added by skeltoac, 7 years ago)

740 lines of bliss

Line 
1Index: wp-includes/template-functions-post.php
2===================================================================
3--- wp-includes/template-functions-post.php     (revision 2948)
4+++ wp-includes/template-functions-post.php     (working copy)
5@@ -411,4 +411,22 @@
6                return $output;
7 }
8 
9+function prepend_object($content) {
10+       global $post;
11+
12+       $p = '<p class="subpostobject">';
13+
14+       if ( '' != $post->guid ) {
15+               if ( substr($post->post_type, 0, 6) == 'image/' )
16+                       $p .= '<a href="' . $post->guid . '" title="Click for full-size image" ><img class="subpostimage" src="' . $post->guid . '" alt="' . $post->post_title . '" /></a>';
17+               else
18+                       $p .= __('Attachment') . ' (' . $post->post_type . ')';
19+       } else {
20+               $p .= __('Missing attachment');
21+       }
22+
23+       $p .= '</p>';
24+
25+       return "$p\n$content";
26+}
27 ?>
28Index: wp-includes/template-loader.php
29===================================================================
30--- wp-includes/template-loader.php     (revision 2948)
31+++ wp-includes/template-loader.php     (working copy)
32@@ -1,5 +1,4 @@
33 <?php
34-
35 if ( defined('WP_USE_THEMES') && constant('WP_USE_THEMES') ) {
36        do_action('template_redirect');
37        if ( is_feed() ) {
38@@ -17,10 +16,17 @@
39        } else if ( is_home() && get_home_template() ) {
40                include(get_home_template());
41                exit;
42+       } else if ( is_subpost() && get_subpost_template() ) {
43+               include(get_subpost_template());
44+               exit;
45        } else if ( is_single() && get_single_template() ) {
46+               if ( is_subpost() )
47+                       add_filter('the_content', 'prepend_object');
48                include(get_single_template());
49                exit;
50        } else if ( is_page() && get_page_template() ) {
51+               if ( is_subpost() )
52+                       add_filter('the_content', 'prepend_object');
53                include(get_page_template());
54                exit;
55        } else if ( is_category() && get_category_template()) {
56Index: wp-includes/classes.php
57===================================================================
58--- wp-includes/classes.php     (revision 2948)
59+++ wp-includes/classes.php     (working copy)
60@@ -29,7 +29,7 @@
61        var $is_404 = false;
62        var $is_comments_popup = false;
63        var $is_admin = false;
64-       var $is_object = false;
65+       var $is_subpost = false;
66 
67        function init_query_flags() {
68                $this->is_single = false;
69@@ -49,7 +49,7 @@
70                $this->is_404 = false;
71                $this->is_paged = false;
72                $this->is_admin = false;
73-               $this->is_object = false;
74+               $this->is_subpost = false;
75        }
76       
77        function init () {
78@@ -90,13 +90,18 @@
79                $qv['m'] =  (int) $qv['m'];
80                $qv['p'] =  (int) $qv['p'];
81 
82+               if ( ('' != $qv['subpost']) || $qv['subpost_id'] ) {
83+                       $this->is_single = true;
84+                       $this->is_subpost = true;
85+               }
86+
87                if ('' != $qv['name']) {
88                        $this->is_single = true;
89                } elseif ( $qv['p'] ) {
90                        $this->is_single = true;
91                } elseif (('' != $qv['hour']) && ('' != $qv['minute']) &&('' != $qv['second']) && ('' != $qv['year']) && ('' != $qv['monthnum']) && ('' != $qv['day'])) {
92                        // If year, month, day, hour, minute, and second are set, a single
93-                 // post is being queried.       
94+                       // post is being queried.       
95                        $this->is_single = true;
96                } elseif ('' != $qv['static'] || '' != $qv['pagename'] || '' != $qv['page_id']) {
97                        $this->is_page = true;
98@@ -208,7 +213,7 @@
99                        $this->is_admin = true;
100                }
101 
102-               if ( ! ($this->is_archive || $this->is_single || $this->is_page || $this->is_search || $this->is_feed || $this->is_trackback || $this->is_404 || $this->is_admin || $this->is_comments_popup)) {
103+               if ( ! ($this->is_subpost || $this->is_archive || $this->is_single || $this->is_page || $this->is_search || $this->is_feed || $this->is_trackback || $this->is_404 || $this->is_admin || $this->is_comments_popup)) {
104                        $this->is_home = true;
105                }
106 
107@@ -335,9 +340,12 @@
108                        $q['pagename'] = sanitize_title(basename(str_replace('%2F', '/', urlencode($q['pagename']))));
109                        $q['name'] = $q['pagename'];
110                        $where .= " AND post_name = '" . $q['pagename'] . "'";
111+               } elseif ('' != $q['subpost']) {
112+                       $q['subpost'] = sanitize_title($q['subpost']);
113+                       $q['name'] = $q['subpost'];
114+                       $where .= " AND post_name = '" . $q['subpost'] . "'";
115                }
116 
117-
118                if ( (int) $q['w'] ) {
119                        $q['w'] = ''.intval($q['w']);
120                        $where .= " AND WEEK(post_date, 1)='" . $q['w'] . "'";
121@@ -346,6 +354,10 @@
122                if ( intval($q['comments_popup']) )
123                        $q['p'] = intval($q['comments_popup']);
124 
125+               // If a subpost is requested by number, let it supercede any post number.
126+               if ( ($q['subpost_id'] != '') && (intval($q['subpost_id']) != 0) )
127+                       $q['p'] = (int) $q['subpost_id'];
128+
129                // If a post number is specified, load that post
130                if (($q['p'] != '') && intval($q['p']) != 0) {
131                        $q['p'] =  (int) $q['p'];
132@@ -516,7 +528,9 @@
133                        $distinct = 'DISTINCT';
134                }
135 
136-               if ($this->is_page) {
137+               if ( $this->is_subpost ) {
138+                       $where .= ' AND (post_status = "object")';
139+               } elseif ($this->is_page) {
140                        $where .= ' AND (post_status = "static")';
141                } elseif ($this->is_single) {
142                        $where .= ' AND (post_status != "static")';
143@@ -529,7 +543,7 @@
144                                $where .= ')';                         
145                }
146 
147-               if (! $this->is_object )
148+               if (! $this->is_subpost )
149                        $where .= ' AND post_status != "object"';
150 
151                // Apply filters on where and join prior to paging so that any
152@@ -575,16 +589,17 @@
153 
154                // Check post status to determine if post should be displayed.
155                if ($this->is_single) {
156-                       if ('publish' != $this->posts[0]->post_status) {
157+                       $status = get_post_status($this->posts[0]);
158+                       if ('publish' != $status) {
159                                if ( ! (isset($user_ID) && ('' != intval($user_ID))) ) {
160                                        // User must be logged in to view unpublished posts.
161                                        $this->posts = array();
162                                } else {
163-                                       if ('draft' == $this->posts[0]->post_status) {
164+                                       if ('draft' == $status) {
165                                                // User must have edit permissions on the draft to preview.
166                                                if (! user_can_edit_post($user_ID, $this->posts[0]->ID))
167                                                        $this->posts = array();
168-                                       } elseif ('private' == $this->posts[0]->post_status) {
169+                                       } elseif ('private' == $status) {
170                                                if ($this->posts[0]->post_author != $user_ID)
171                                                        $this->posts = array();
172                                        }
173@@ -821,19 +836,19 @@
174 
175        var $queryreplace =
176                array (
177-                                        'year=',
178-                                        'monthnum=',
179-                                        'day=',
180-                                        'hour=',
181-                                        'minute=',
182-                                        'second=',
183-                                        'name=',
184-                                        'p=',
185-                                        'category_name=',
186-                                        'author_name=',
187-                                        'pagename=',
188-                                        's='
189-                                        );
190+                                       'year=',
191+                                       'monthnum=',
192+                                       'day=',
193+                                       'hour=',
194+                                       'minute=',
195+                                       'second=',
196+                                       'name=',
197+                                       'p=',
198+                                       'category_name=',
199+                                       'author_name=',
200+                                       'pagename=',
201+                                       's='
202+                                       );
203 
204        var $feeds = array ('feed', 'rdf', 'rss', 'rss2', 'atom');
205 
206@@ -845,16 +860,16 @@
207        }                                       
208 
209        function using_index_permalinks() {
210-    if (empty($this->permalink_structure)) {
211+               if (empty($this->permalink_structure)) {
212                        return false;
213-    }
214+               }
215 
216-    // If the index is not in the permalink, we're using mod_rewrite.
217-    if (preg_match('#^/*' . $this->index . '#', $this->permalink_structure)) {
218-      return true;
219-    }
220+               // If the index is not in the permalink, we're using mod_rewrite.
221+               if (preg_match('#^/*' . $this->index . '#', $this->permalink_structure)) {
222+                       return true;
223+               }
224     
225-    return false;
226+               return false;
227        }
228 
229        function using_mod_rewrite_permalinks() {
230@@ -865,15 +880,15 @@
231        }                                       
232 
233        function preg_index($number) {
234-    $match_prefix = '$';
235-    $match_suffix = '';
236-   
237-    if (! empty($this->matches)) {
238+               $match_prefix = '$';
239+               $match_suffix = '';
240+
241+               if (! empty($this->matches)) {
242                        $match_prefix = '$' . $this->matches . '[';
243                        $match_suffix = ']';
244-    }       
245-   
246-    return "$match_prefix$number$match_suffix";       
247+               }       
248+
249+               return "$match_prefix$number$match_suffix";       
250        }
251 
252        function page_rewrite_rules() {
253@@ -897,7 +912,7 @@
254                        return $this->date_structure;
255                }
256 
257-    if (empty($this->permalink_structure)) {
258+               if (empty($this->permalink_structure)) {
259                        $this->date_structure = '';
260                        return false;
261                }
262@@ -973,7 +988,7 @@
263                        return $this->category_structure;
264                }
265 
266-    if (empty($this->permalink_structure)) {
267+               if (empty($this->permalink_structure)) {
268                        $this->category_structure = '';
269                        return false;
270                }
271@@ -993,7 +1008,7 @@
272                        return $this->author_structure;
273                }
274 
275-    if (empty($this->permalink_structure)) {
276+               if (empty($this->permalink_structure)) {
277                        $this->author_structure = '';
278                        return false;
279                }
280@@ -1008,7 +1023,7 @@
281                        return $this->search_structure;
282                }
283 
284-    if (empty($this->permalink_structure)) {
285+               if (empty($this->permalink_structure)) {
286                        $this->search_structure = '';
287                        return false;
288                }
289@@ -1023,7 +1038,7 @@
290                        return $this->page_structure;
291                }
292 
293-    if (empty($this->permalink_structure)) {
294+               if (empty($this->permalink_structure)) {
295                        $this->page_structure = '';
296                        return false;
297                }
298@@ -1038,7 +1053,7 @@
299                        return $this->feed_structure;
300                }
301 
302-    if (empty($this->permalink_structure)) {
303+               if (empty($this->permalink_structure)) {
304                        $this->feed_structure = '';
305                        return false;
306                }
307@@ -1053,7 +1068,7 @@
308                        return $this->comment_feed_structure;
309                }
310 
311-    if (empty($this->permalink_structure)) {
312+               if (empty($this->permalink_structure)) {
313                        $this->comment_feed_structure = '';
314                        return false;
315                }
316@@ -1158,6 +1173,20 @@
317                                        $trackbackmatch = $match . $trackbackregex;
318                                        $trackbackquery = $trackbackindex . '?' . $query . '&tb=1';
319                                        $match = rtrim($match, '/');
320+                                       $submatchbase = str_replace(array('(',')'),'',$match);
321+                                       $sub1 = $submatchbase . '/([^/]+)/';
322+                                       $sub1tb = $sub1 . $trackbackregex;
323+                                       $sub1feed = $sub1 . $feedregex;
324+                                       $sub1feed2 = $sub1 . $feedregex2;
325+                                       $sub1 .= '?$';
326+                                       $sub2 = $submatchbase . '/subpost/([^/]+)/';
327+                                       $sub2tb = $sub2 . $trackbackregex;
328+                                       $sub2feed = $sub2 . $feedregex;
329+                                       $sub2feed2 = $sub2 . $feedregex2;
330+                                       $sub2 .= '?$';
331+                                       $subquery = $index . '?subpost=' . $this->preg_index(1);
332+                                       $subtbquery = $subquery . '&tb=1';
333+                                       $subfeedquery = $subquery . '&feed=' . $this->preg_index(2);
334                                        $match = $match . '(/[0-9]+)?/?$';
335                                        $query = $index . '?' . $query . '&page=' . $this->preg_index($num_toks + 1);
336                                } else {
337@@ -1168,7 +1197,9 @@
338                                $rewrite = $rewrite + array($match => $query);
339 
340                                if ($post) {
341-                                       $rewrite = array($trackbackmatch => $trackbackquery) + $rewrite;
342+                                       $rewrite = array($trackbackmatch => $trackbackquery) + $rewrite +
343+                                               array($sub1 => $subquery, $sub1tb => $subtbquery, $sub1feed => $subfeedquery, $sub1feed2 => $subfeedquery) +
344+                                               array($sub2 => $subquery, $sub2tb => $subtbquery, $sub2feed => $subfeedquery, $sub2feed2 => $subfeedquery);
345                                }
346                        }
347 
348@@ -1231,6 +1262,7 @@
349 
350                do_action('generate_rewrite_rules', array(&$this));
351                $this->rules = apply_filters('rewrite_rules_array', $this->rules);
352+
353                return $this->rules;
354        }
355 
356@@ -1329,7 +1361,7 @@
357 }
358 
359 class WP {
360-       var $public_query_vars = array('m','p','posts','w', 'cat','withcomments','s','search','exact', 'sentence', 'debug', 'calendar','page','paged','more','tb', 'pb','author','order','orderby', 'year', 'monthnum', 'day', 'hour', 'minute', 'second', 'name', 'category_name', 'feed', 'author_name', 'static', 'pagename', 'page_id', 'error', 'comments_popup');
361+       var $public_query_vars = array('m', 'p', 'posts', 'w', 'cat', 'withcomments', 's', 'search', 'exact', 'sentence', 'debug', 'calendar', 'page', 'paged', 'more', 'tb', 'pb', 'author', 'order', 'orderby', 'year', 'monthnum', 'day', 'hour', 'minute', 'second', 'name', 'category_name', 'feed', 'author_name', 'static', 'pagename', 'page_id', 'error', 'comments_popup', 'subpost', 'subpost_id');
362 
363        var $private_query_vars = array('posts_per_page', 'posts_per_archive_page', 'what_to_show', 'showposts', 'nopaging');
364 
365@@ -1397,8 +1429,9 @@
366                                foreach ($rewrite as $match => $query) {
367                                        // If the requesting file is the anchor of the match, prepend it
368                                        // to the path info.
369-                                       if ((! empty($req_uri)) && (strpos($match, $req_uri) === 0)) {
370+                                       if ((! empty($req_uri)) && (strpos($match, $req_uri) === 0) && ($req_uri != $request)) {
371                                                $request_match = $req_uri . '/' . $request;
372                                        }
373 
374Index: wp-includes/template-functions-links.php
375===================================================================
376--- wp-includes/template-functions-links.php    (revision 2948)
377+++ wp-includes/template-functions-links.php    (working copy)
378@@ -40,6 +40,8 @@
379        $post = & get_post($id);
380        if ($post->post_status == 'static') {
381                return get_page_link($post->ID);
382+       } elseif ($post->post_status == 'object') {
383+               return get_subpost_link($post->ID);
384        }
385 
386        $permalink = get_settings('permalink_structure');
387@@ -97,6 +99,24 @@
388        return apply_filters('page_link', $link, $id);
389 }
390 
391+function get_subpost_link($id = false) {
392+       global $post, $wp_rewrite;
393+
394+       if (! $id) {
395+               $id = $post->ID;
396+       }
397+
398+       $object = get_post($id);
399+       if ( $wp_rewrite->using_permalinks() && 'draft' != get_post_status($id) ) {
400+               $link = get_permalink($object->post_parent);
401+               $link = trim($link, '/') . '/' . $object->post_name . '/';
402+       } else {
403+               $link = get_bloginfo('home') . "/index.php?subpost_id=$id";
404+       }               
405+
406+       return apply_filters('object_link', $link, $id);
407+}
408+
409 function get_year_link($year) {
410        global $wp_rewrite;
411     if (!$year) $year = gmdate('Y', time()+(get_settings('gmt_offset') * 3600));
412@@ -174,9 +194,9 @@
413 
414     get_currentuserinfo();
415 
416-       if (!user_can_edit_post($user_ID, $post->ID)) {
417-        return;
418-    }
419+       if ( !user_can_edit_post($user_ID, $post->ID) || is_subpost() ) {
420+               return;
421+       }
422 
423     $location = get_settings('siteurl') . "/wp-admin/post.php?action=edit&amp;post=$post->ID";
424     echo $before . "<a href=\"$location\">$link</a>" . $after;
425@@ -200,12 +220,12 @@
426 function get_previous_post($in_same_cat = false, $excluded_categories = '') {
427        global $post, $wpdb;
428 
429-       if(! is_single()) {
430+       if( !is_single() || is_subpost() ) {
431                return null;
432        }
433-   
434+
435        $current_post_date = $post->post_date;
436-   
437+
438        $join = '';
439        if ($in_same_cat) {
440                $join = " INNER JOIN $wpdb->post2cat ON $wpdb->posts.ID= $wpdb->post2cat.post_id ";
441@@ -232,7 +252,7 @@
442 function get_next_post($in_same_cat = false, $excluded_categories = '') {
443        global $post, $wpdb;
444 
445-       if(! is_single()) {
446+       if( !is_single() || is_subpost() ) {
447                return null;
448        }
449 
450@@ -264,43 +284,44 @@
451 }
452 
453 function previous_post_link($format='&laquo; %link', $link='%title', $in_same_cat = false, $excluded_categories = '') {
454-  $post = get_previous_post($in_same_cat, $excluded_categories);
455 
456-  if(! $post) {
457-    return;
458-  }
459+       if ( is_subpost() ) {
460+               $post = & get_post($GLOBALS['post']->post_parent);
461+               $pre = __('Belongs to ');
462+       } else {
463+               $post = get_previous_post($in_same_cat, $excluded_categories);
464+               $pre = '';
465+       }
466 
467-  $title = apply_filters('the_title', $post->post_title, $post);
468+       if(! $post)
469+               return;
470 
471-  $string = '<a href="'.get_permalink($post->ID).'">';
472+       $title = apply_filters('the_title', $post->post_title, $post);
473+       $string = '<a href="'.get_permalink($post->ID).'">';
474+       $link = str_replace('%title', $title, $link);
475+       $link = $pre . $string . $link . '</a>';
476 
477-  $link = str_replace('%title', $title, $link);
478-
479-  $link = $string . $link . '</a>';
480-
481-  $format = str_replace('%link', $link, $format);
482-
483-  echo $format;           
484+       $format = str_replace('%link', $link, $format);
485+       echo $format;       
486 }
487 
488 function next_post_link($format='%link &raquo;', $link='%title', $in_same_cat = false, $excluded_categories = '') {
489-  $post = get_next_post($in_same_cat, $excluded_categories);
490 
491-  if(! $post) {
492-    return;
493-  }
494+       if ( is_subpost() )
495+               return null;
496+       else
497+               $post = get_next_post($in_same_cat, $excluded_categories);
498 
499-  $title = apply_filters('the_title', $post->post_title, $post);
500+       if(! $post)
501+               return;
502 
503-  $string = '<a href="'.get_permalink($post->ID).'">';
504+       $title = apply_filters('the_title', $post->post_title, $post);
505+       $string = '<a href="'.get_permalink($post->ID).'">';
506+       $link = str_replace('%title', $title, $link);
507+       $link = $string . $link . '</a>';
508 
509-  $link = str_replace('%title', $title, $link);
510-
511-  $link = $string . $link . '</a>';
512-
513-  $format = str_replace('%link', $link, $format);
514-
515-  echo $format;           
516+       $format = str_replace('%link', $link, $format);
517+       echo $format;       
518 }
519 
520 // Deprecated.  Use previous_post_link().
521Index: wp-includes/functions.php
522===================================================================
523--- wp-includes/functions.php   (revision 2948)
524+++ wp-includes/functions.php   (working copy)
525@@ -1373,6 +1373,12 @@
526        return false;
527 }
528 
529+function is_subpost () {
530+       global $wp_query;
531+
532+       return $wp_query->is_subpost;
533+}
534+
535 function is_archive () {
536        global $wp_query;
537 
538@@ -1858,6 +1864,19 @@
539        return get_query_template('single');
540 }
541 
542+function get_subpost_template() {
543+       global $posts;
544+       $type = explode('/', $posts[0]->post_type);
545+       if ( $template = get_query_template($type[0]) )
546+               return $template;
547+       elseif ( $template = get_query_template($type[1]) )
548+               return $template;
549+       elseif ( $template = get_query_template("$type[0]_$type[1]") )
550+               return $template;
551+       else
552+               return get_query_template('subpost');
553+}
554+
555 function get_comments_popup_template() {
556        if ( file_exists( TEMPLATEPATH . '/comments-popup.php') )
557                $template = TEMPLATEPATH . '/comments-popup.php';
558Index: wp-commentsrss2.php
559===================================================================
560--- wp-commentsrss2.php (revision 2948)
561+++ wp-commentsrss2.php (working copy)
562@@ -32,14 +32,14 @@
563                        comment_author_url, comment_date, comment_date_gmt, comment_content, comment_post_ID,
564                        $wpdb->posts.ID, $wpdb->posts.post_password FROM $wpdb->comments
565                        LEFT JOIN $wpdb->posts ON comment_post_id = id WHERE comment_post_ID = '$id'
566-                       AND $wpdb->comments.comment_approved = '1' AND ($wpdb->posts.post_status = 'publish' OR $wpdb->posts.post_status = 'static')
567+                       AND $wpdb->comments.comment_approved = '1' AND $wpdb->posts.post_status IN ('publish', 'static', 'object')
568                        AND post_date < '".date("Y-m-d H:i:59")."'
569                        ORDER BY comment_date DESC LIMIT " . get_settings('posts_per_rss') );
570                } else { // if no post id passed in, we'll just ue the last 10 comments.
571                        $comments = $wpdb->get_results("SELECT comment_ID, comment_author, comment_author_email,
572                        comment_author_url, comment_date, comment_date_gmt, comment_content, comment_post_ID,
573                        $wpdb->posts.ID, $wpdb->posts.post_password FROM $wpdb->comments
574-                       LEFT JOIN $wpdb->posts ON comment_post_id = id WHERE ($wpdb->posts.post_status = 'publish' OR $wpdb->posts.post_status = 'static')
575+                       LEFT JOIN $wpdb->posts ON comment_post_id = id WHERE $wpdb->posts.post_status IN ('publish', 'static', 'object')
576                        AND $wpdb->comments.comment_approved = '1' AND post_date < '".date("Y-m-d H:i:s")."' 
577                        ORDER BY comment_date DESC LIMIT " . get_settings('posts_per_rss') );
578                }
579Index: wp-admin/admin-functions.php
580===================================================================
581--- wp-admin/admin-functions.php        (revision 2948)
582+++ wp-admin/admin-functions.php        (working copy)
583@@ -669,6 +669,8 @@
584                        }
585 
586                }
587+       } else {
588+               $error = __('File not found');
589        }
590 
591        if (!empty ($error)) {
592Index: wp-admin/image-uploading.php
593===================================================================
594--- wp-admin/image-uploading.php        (revision 2948)
595+++ wp-admin/image-uploading.php        (working copy)
596@@ -136,6 +268,18 @@
597 $imagedata['hwstring_small'] = "height='$uheight' width='$uwidth'";
598 $imagedata['file'] = $file;
599 
600+$error = false;
601+// This is a problem. Three megapixels is by no means a good estimate. Safety check should be in wp_create_thumbnail.
602+// If we run out of memory, it's a fatal error and no postmeta is added.
603+if ( $imagedata['width'] * $imagedata['height'] < 3 * 1024 * 1024 ) {
604+       if ( $imagedata['width'] > 128 && $imagedata['width'] >= $imagedata['height'] * 4 / 3 )
605+               $error = wp_create_thumbnail($file, 128);
606+       elseif ( $imagedata['height'] > 96 )
607+               $error = wp_create_thumbnail($file, 96);
608+}
609+if ( $error != 1 )
610+       $imagedata['thumb'] = false;   
611+else
612+       $imagedata['thumb'] = "thumb-$filename";
613+
614 if ( false == add_post_meta($id, 'imagedata', $imagedata) )
615        die("failed to add_post_meta");
616 
617@@ -192,24 +336,49 @@
618 $uwidth_sum = 0;
619 $images_html = '';
620 $images_style = '';
621+$images_script = '';
622 if ( count($images) > 0 ) {
623        $images = array_slice( $images, 0, $num );
624+       $__subpost = __('SUBPOST');
625+       $__delete = __('DELETE');
626+       $__thumbnail = __('THUMBNAIL');
627+       $__close = __('CLOSE');
628+       $__on = __('ON');
629+       $__off = __('OFF');
630+       $__confirmdelete = __('Delete this photo from the server?');
631+       $__nothumb = __('There is no thumbnail associated with this photo.');
632+       $images_script .= "on = '$__on';\noff = '$__off';\n";
633        foreach ( $images as $key => $image ) {
634                $image = array_merge($image, get_post_meta($image['ID'], 'imagedata', true) );
635+               if ( ($image['width'] > 128 || $image['height'] > 96) && !empty($image['thumb']) && file_exists(dirname($image['file']).'/'.$image['thumb']) ) {
636+                       $src = str_replace(basename($image['guid']), '', $image['guid']) . $image['thumb'];
637+                       $images_script .= "src".$i."a = '$src';\nsrc".$i."b = '".$image['guid']."';\n";
638+                       $thumb = 'true';
639+                       $thumbtext = "$__thumbnail <strong id=\"I$i\">$__on</strong>";
640+               } else {
641+                       $src = $image['guid'];
642+                       $thumb = 'false';
643+                       $thumbtext = "<del>$__thumbnail</del>";
644+               }
645                list($image['uwidth'], $image['uheight']) = get_udims($image['width'], $image['height']);
646-               $uwidth_sum += 128; //$image['uwidth'];
647+               $height_width = 'height="'.$image['uheight'].'" width="'.$image['uwidth'].'"';
648+               $uwidth_sum += 128;
649                $xpadding = (128 - $image['uwidth']) / 2;
650                $ypadding = (96 - $image['uheight']) / 2;
651                $object = $image['ID'];
652                $images_style .= "#target$i img { padding: {$ypadding}px {$xpadding}px; }\n";
653+               $href = get_subpost_link($object);
654+               $images_script .= "href".$i."a = '$href';\nhref".$i."b = '{$image['guid']}';\n";
655                $images_html .= <<<HERE
656 <div id='target$i' class='imagewrap left'>
657        <div id='popup$i' class='popup'>
658-               <a onclick='return confirm("Delete this photo from the server?")' href='image-uploading.php?action=delete&amp;object=$object&amp;all=$all&amp;start=$start&amp;post=$post'>DELETE</a>
659-               <a onclick="popup.style.display='none';return false;" href="javascript:void()">CANCEL</a>
660+               <a onclick="toggleLink($i);return false;" href="javascript:void();">$__subpost <strong id="L$i">$__on</strong></a>
661+               <a onclick="if($thumb)toggleImage($i);else alert('$__nothumb');return false;" href="javascript:void();">$thumbtext</a>
662+               <a onclick="return confirm('$__confirmdelete')" href="image-uploading.php?action=delete&amp;object=$object&amp;all=$all&amp;start=$start&amp;post=$post">$__delete</a>
663+               <a onclick="popup.style.display='none';return false;" href="javascript:void()">$__close</a>
664        </div>
665-       <a id='link$i' class='imagelink' href='{$image['guid']}' onclick='imagePopup($i);return false;' title='{$image['post_title']}'>
666-               <img id='image$i' src='{$image['guid']}' alt='{$image['post_title']}' {$image['hwstring_small']} />
667+       <a id="link$i" class="imagelink" href="$href" onclick="imagePopup($i);return false;" title="{$image['post_title']}">
668+               <img id='image$i' src='$src' alt='{$image['post_title']}' $height_width />
669        </a>
670 </div>
671 HERE;
672@@ -231,6 +400,7 @@
673 <head>
674 <meta http-equiv="imagetoolbar" content="no" />
675 <script type="text/javascript">
676+<?php echo $images_script; ?>
677 function validateImageName() {
678 /* This is more for convenience than security. Server-side validation is very thorough.*/
679 obj = document.getElementById('upload');
680@@ -258,6 +428,28 @@
681 function init() {
682 popup = false;
683 }
684+function toggleLink(n) {
685+       o=document.getElementById('link'+n);
686+       oi=document.getElementById('L'+n);
687+       if ( oi.innerHTML == on ) {
688+               o.href = eval('href'+n+'b');
689+               oi.innerHTML = off;
690+       } else {
691+               o.href = eval('href'+n+'a');
692+               oi.innerHTML = on;
693+       }
694+}
695+function toggleImage(n) {
696+       o = document.getElementById('image'+n);
697+       oi = document.getElementById('I'+n);
698+       if ( oi.innerHTML == on ) {
699+               o.src = eval('src'+n+'b');
700+               oi.innerHTML = off;
701+       } else {
702+               o.src = eval('src'+n+'a');
703+               oi.innerHTML = on;
704+       }
705+}
706 </script>
707 <style type="text/css">
708 body {
709@@ -369,11 +561,11 @@
710 text-align: right;
711 }
712 .popup {
713-margin: 23px 9px;
714-padding: 5px;
715+margin: 4px 4px;
716+padding: 3px;
717 position: absolute;
718-width: 100px;
719-height: 40px;
720+width: 114px;
721+height: 82px;
722 display: none;
723 background-color: rgb(223, 232, 241);
724 opacity: .90;
725@@ -381,7 +573,6 @@
726 text-align: center;
727 }
728 .popup a, .popup a:visited, .popup a:active {
729-margin-bottom: 3px;
730 background-color: transparent;
731 display: block;
732 width: 100%;
733@@ -389,7 +580,6 @@
734 color: #246;
735 }
736 .popup a:hover {
737-margin-bottom: 3px;
738 background-color: #fff;
739 color: #000;
740 }