Ticket #7607: 7607.4.diff

File 7607.4.diff, 34.2 KB (added by ShaneF, 5 years ago)
Line 
1Index: wp-admin/includes/media.php
2===================================================================
3--- wp-admin/includes/media.php (revision 9143)
4+++ wp-admin/includes/media.php (working copy)
5@@ -16,7 +16,7 @@
6 function media_upload_tabs() {
7        $_default_tabs = array(
8                'type' => __('Choose File'), // handler action suffix => tab text
9-               'gallery' => __('Gallery'),
10+               'gallery' => __('Attachments'),
11                'library' => __('Media Library'),
12        );
13 
14@@ -40,7 +40,7 @@
15        if ( intval($_REQUEST['post_id']) )
16                $attachments = intval($wpdb->get_var($wpdb->prepare("SELECT count(*) FROM $wpdb->posts WHERE post_type = 'attachment' AND post_parent = %d", $_REQUEST['post_id'])));
17 
18-       $tabs['gallery'] = sprintf(__('Gallery (%s)'), "<span id='attachments-count'>$attachments</span>");
19+       $tabs['gallery'] = sprintf(__('Attachments (%s)'), "<span id='attachments-count'>$attachments</span>");
20 
21        return $tabs;
22 }
23@@ -98,7 +98,7 @@
24        $rel = $rel ? ' rel="attachment wp-att-'.attribute_escape($id).'"' : '';
25 
26        if ( $url )
27-               $html = '<a href="' . clean_url($url) . "\"$rel>$html</a>";
28+               $html = '<a href="' . clean_url($url) . "\" title=\"". attribute_escape($title) ."\"$rel>$html</a>";
29 
30        $html = apply_filters( 'image_send_to_editor', $html, $id, $alt, $title, $align, $url, $size );
31 
32@@ -358,6 +358,8 @@
33                        $post['post_title'] = $attachment['post_title'];
34                if ( isset($attachment['post_excerpt']) )
35                        $post['post_excerpt'] = $attachment['post_excerpt'];
36+               if ( isset($attachment['group_number']) )
37+                       $post['group_number'] = $attachment['group_number'];
38                if ( isset($attachment['menu_order']) )
39                        $post['menu_order'] = $attachment['menu_order'];
40 
41@@ -376,8 +378,20 @@
42                                wp_set_object_terms($attachment_id, array_map('trim', preg_split('/,+/', $attachment[$t])), $t, false);
43        }
44 
45-       if ( isset($_POST['insert-gallery']) )
46-               return media_send_to_editor('[gallery]');
47+       if ( isset($_POST['insert-gallery']) ) {
48+               if ( ( isset($_POST['gallery_insert']) ) && ( $_POST['gallery_insert'] > 0 ) ) {
49+                       return media_send_to_editor('[gallery group="'.$_POST['gallery_insert'].'"]');
50+               } else {
51+                       return media_send_to_editor('[gallery]');
52+               }
53+       }
54+       
55+       if ( isset($_POST['new-gallery']) ) {   
56+               wp_new_gallery($_POST['post_id']);
57+       }
58+               
59+       if ( isset($_POST['gallery_delete']) && !is_null($_POST['gallery_delete']) && ($_POST['gallery_delete'] > 0) )
60+               wp_delete_gallery($post['post_id'], $_POST['gallery_delete']);
61 
62        if ( isset($_POST['send']) ) {
63                $keys = array_keys($_POST['send']);
64@@ -426,8 +440,11 @@
65                        $align = attribute_escape($_POST['insertonly']['align']);
66                        $class = " class='align$align'";
67                }
68+               if ( isset($_POST['insertonly']['title']) ) {
69+                       $title = " title='".attribute_escape($_POST['insertonly']['title'])."'";
70+               }
71                if ( !empty($src) )
72-                       $html = "<img src='$src' alt='$alt'$class />";
73+                       $html = "<img src='$src' alt='$alt'$title$class />";
74                return media_send_to_editor($html);
75        }
76 
77@@ -841,6 +858,8 @@
78                        $post['errors']['post_title']['errors'][] = __('Empty Title filled from filename.');
79                }
80        }
81+       
82+       $post['group_name'] = $_POST['attachments']['group_name'][$attachment['group_number']];
83 
84        return $post;
85 }
86@@ -969,13 +988,17 @@
87  * @param array $errors Errors for attachment, if any.
88  * @return string
89  */
90-function get_media_items( $post_id, $errors ) {
91+function get_media_items( $post_id, $group_number = null, $errors ) {
92        if ( $post_id ) {
93                $post = get_post($post_id);
94-               if ( $post && $post->post_type == 'attachment' )
95+               if ( $post && $post->post_type == 'attachment' ) {
96                        $attachments = array($post->ID => $post);
97-               else
98-                       $attachments = get_children( array( 'post_parent' => $post_id, 'post_type' => 'attachment', 'orderby' => 'menu_order ASC, ID', 'order' => 'DESC') );
99+               } else {
100+                       $attachments = get_attachments( $post_id, array('group_number' => $group_number), get_children( array( 'post_parent' => $post_id, 'post_type' => 'attachment', 'orderby' => 'menu_order ASC, ID', 'order' => 'DESC') ) );
101+                       
102+                       if ( ! count($attachments) )
103+                               return "\n<div class='media-item media-no-items child-of-$post_id preloaded'><div class='progress'><div class='bar'></div></div><div id='media-upload-error-$id'></div><div class='filename'></div><div class='filename new'>". __("No images in this group. Move items to this group.") ."</div></div>";
104+               }
105        } else {
106                if ( is_array($GLOBALS['wp_the_query']->posts) )
107                        foreach ( $GLOBALS['wp_the_query']->posts as $attachment )
108@@ -985,10 +1008,11 @@
109        if ( empty($attachments) )
110                return '';
111 
112-       foreach ( $attachments as $id => $attachment )
113+       foreach ( $attachments as $id => $attachment ) {       
114                if ( $item = get_media_item( $id, array( 'errors' => isset($errors[$id]) ? $errors[$id] : null) ) )
115                        $output .= "\n<div id='media-item-$id' class='media-item child-of-$attachment->post_parent preloaded'><div class='progress'><div class='bar'></div></div><div id='media-upload-error-$id'></div><div class='filename'></div>$item\n</div>";
116-
117+       }
118+       
119        return $output;
120 }
121 
122@@ -1026,6 +1050,7 @@
123        $filename = basename($post->guid);
124        $title = attribute_escape($post->post_title);
125        $description = attribute_escape($post->post_content);
126+       $group_number = attribute_escape($post->group_number);
127        if ( $_tags = get_the_tags($attachment_id) ) {
128                foreach ( $_tags as $tag )
129                        $tags[] = $tag->name;
130@@ -1056,6 +1081,8 @@
131        $gallery = ( (isset($_REQUEST['tab']) && 'gallery' == $_REQUEST['tab']) || (isset($redir_tab) && 'gallery' == $redir_tab) ) ? true : false;
132        $order = '';
133 
134+       $groupnum = '<input type="hidden" class="group-value" name="attachments['.$attachment_id.'][group_number]" value="'.$group_number.'" />';
135+
136        foreach ( $form_fields as $key => $val ) {
137                if ( 'menu_order' == $key ) {
138                        if ( $gallery )
139@@ -1072,6 +1099,7 @@
140        $type
141        $toggle_links
142        $order
143+       $groupnum
144        $display_title
145        <table class='slidetoggle describe $class'>
146                <thead class='media-item-info'>
147@@ -1355,7 +1383,7 @@
148                html = '<img alt="'+alt+'" src="'+f.src.value+'"'+title+cls+' width="'+t.width+'" height="'+t.height+'" />';
149 
150                if ( f.url.value )
151-                       html = '<a href="'+f.url.value+'">'+html+'</a>';
152+                       html = '<a href="'+f.url.value+'"'+title+'>'+html+'</a>';
153 
154                if ( caption )
155                        html = '[caption id="" align="'+t.align+'" width="'+t.width+'" caption="'+caption+'"]'+html+'[/caption]';
156@@ -1425,6 +1453,9 @@
157        media_upload_header();
158 
159        $post_id = intval($_REQUEST['post_id']);
160+       $groups = intval(get_attachment_groups( $post_id ));
161+       $_group_name = get_attachments_groupsname( $post_id );
162+       
163        $form_action_url = admin_url("media-upload.php?type={$GLOBALS['type']}&tab=gallery&post_id=$post_id");
164 ?>
165 
166@@ -1434,8 +1465,26 @@
167        var preloaded = $(".media-item.preloaded");
168        if ( preloaded.length > 0 ) {
169                preloaded.each(function(){prepareMediaItem({id:this.id.replace(/[^0-9]/g, '')},'');});
170-               updateMediaForm();
171        }
172+       jQuery("a.del-group").click(function () {
173+               var deleteConfirmation = confirm('<?php _e("Are you sure you want to delete this gallery group?"); ?>');
174+               
175+               if (!deleteConfirmation) { return; }
176+               
177+               if (jQuery("#media-group-" + jQuery(this).attr('value') + " .media-item input.group-value").length)
178+               {
179+                       jQuery.each(jQuery("#media-group-delete-" + jQuery(this).attr('value') + " .media-item input.group-value"), function(i, id) {
180+                               jQuery(id)[0].value = 0;        //      we are going to set all the items to group 0             
181+                       });
182+               }
183+               jQuery("#gallery-delete").val( jQuery(this).attr('value') );    //      set the gallery we are deleting
184+               jQuery("#media-group-" + jQuery(this).attr('value')).hide();    //      hide the gallery and then...
185+               jQuery(".savebutton").click();
186+       });
187+       jQuery("a.insert-group").click(function () {
188+               jQuery("#gallery-insert").val( jQuery(this).attr('value') );    //      set the gallery we are inserting
189+               jQuery(".insert-gallery").click();               
190+       });
191 });
192 -->
193 </script>
194@@ -1443,23 +1492,59 @@
195 <form enctype="multipart/form-data" method="post" action="<?php echo attribute_escape($form_action_url); ?>" class="media-upload-form validate" id="gallery-form">
196 <?php wp_nonce_field('media-form'); ?>
197 <?php //media_upload_form( $errors ); ?>
198+<div id="media-items">
199+<?php
200+for ( $i = 0; $i < $groups; $i++ )
201+{
202+?>
203+<div id="media-group-<?php echo $i; ?>" class="media-groups">
204+<input type="hidden" id="media-group-value-<?php echo $i; ?>" value="<?php echo $i; ?>" />
205 <table class="widefat">
206 <thead><tr>
207-<th><?php _e('Media'); ?></th>
208+<th>
209+<?php 
210+if ($i > 0) {
211+       
212+       $delete = "<a href=\"#media-group-delete-value-".$i."\" value=\"".$i."\" class=\"del-group\">" . __('Delete') . "</a>";
213+       $insert = "<a href=\"#media-group-insert-value-".$i."\" value=\"".$i."\" class=\"insert-group\">" . __('Insert') . "</a>";
214+       $group_link = "<small>[".$delete." | " .$insert."]</small>";
215+       $group_name = "<input type=\"text\" name=\"attachments[group_name][".$i."]\" value=\"" . $_group_name[$i] . "\" size=\"20\" />";
216+       
217+       printf( __('Group (%1$d) %2$s %3$s'), $i, $group_name, $group_link);
218+
219+               
220+} else {
221+
222+       _e('Media: Non-grouped items.');
223+       
224+}
225+?>
226+</th>
227 <th class="order-head"><?php _e('Order'); ?></th>
228 </tr></thead>
229 </table>
230-<div id="media-items">
231-<?php echo get_media_items($post_id, $errors); ?>
232+<?php echo get_media_items($post_id, $i, $errors); ?>
233 </div>
234+<?php
235+}
236+?>
237+</div>
238 <p class="ml-submit">
239 <input type="submit" class="button savebutton" name="save" value="<?php echo attribute_escape( __( 'Save all changes' ) ); ?>" />
240-<input type="submit" class="button insert-gallery" name="insert-gallery" value="<?php echo attribute_escape( __( 'Insert gallery into post' ) ); ?>" />
241+<input type="submit" class="button new-gallery" name="new-gallery" value="<?php echo attribute_escape( __( 'Create new gallery' ) ); ?>" />
242+<input type="submit" class="button insert-gallery" name="insert-gallery" value="<?php echo attribute_escape( __( 'Insert full gallery into post' ) ); ?>" />
243+<input type="hidden" name="gallery_delete" id="gallery-delete" value="" />
244+<input type="hidden" name="gallery_insert" id="gallery-insert" value="" />
245 <input type="hidden" name="post_id" id="post_id" value="<?php echo (int) $post_id; ?>" />
246 <input type="hidden" name="type" value="<?php echo attribute_escape( $GLOBALS['type'] ); ?>" />
247 <input type="hidden" name="tab" value="<?php echo attribute_escape( $GLOBALS['tab'] ); ?>" />
248 </p>
249 </form>
250+<script type="text/javascript">
251+<!--
252+       updateMediaForm();
253+-->
254+</script>
255 <?php
256 }
257 
258@@ -1606,7 +1691,7 @@
259 </script>
260 
261 <div id="media-items">
262-<?php echo get_media_items(null, $errors); ?>
263+<?php echo get_media_items(null, null, $errors); ?>
264 </div>
265 <p class="ml-submit">
266 <input type="submit" class="button savebutton" name="save" value="<?php echo attribute_escape( __( 'Save all changes' ) ); ?>" />
267Index: wp-admin/includes/upgrade.php
268===================================================================
269--- wp-admin/includes/upgrade.php       (revision 9143)
270+++ wp-admin/includes/upgrade.php       (working copy)
271@@ -906,6 +906,24 @@
272        // Update post_date for unpublished posts with empty timestamp
273        if ( $wp_current_db_version < 8921 )
274                $wpdb->query( "UPDATE $wpdb->posts SET post_date = post_modified WHERE post_date = '0000-00-00 00:00:00'" );
275+               
276+
277+       if ( $wp_current_db_version < 9094 ) {
278+               update_option('image_display_type', 'none');    // default display option
279+               $posts = $wpdb->get_results("SELECT ID FROM $wpdb->posts WHERE (post_type = 'post' || post_type = 'page')");
280+               foreach ( (array) $posts as $post ) {
281+                       $attachments = $wpdb->get_results("SELECT ID FROM $wpdb->posts WHERE post_type = 'attachment' AND post_parent = $post->ID");
282+                       
283+                       foreach ( (array) $attachments as $attachment )
284+                               $attach[] = $attachment->ID;
285+                       
286+                       $_new_group = array(0 => array ('name' => null, 'items' => $attach));
287+                       update_post_meta( $post->ID, '_wp_post_attachments', $_new_group );
288+                       unset($attach);
289+               }               
290+       }
291+       unset($posts, $attachments);
292+               
293 }
294 
295 
296Index: wp-admin/js/gallery.js
297===================================================================
298--- wp-admin/js/gallery.js      (revision 9143)
299+++ wp-admin/js/gallery.js      (working copy)
300@@ -1,22 +1,44 @@
301 jQuery(function($) {
302        var gallerySortable;
303+
304        var gallerySortableInit = function() {
305                gallerySortable = $('#media-items').sortable( {
306                        items: '.media-item',
307                        placeholder: 'sorthelper',
308                        axis: 'y',
309                        distance: 2,
310-                       update: galleryReorder
311+                       update: galleryHandle,
312                } );
313        }
314-
315-       // When an update has occurred, adjust the order for each item
316+       
317+       var galleryHandle = function (e, sort) {
318+               galleryReorder(e, sort);
319+               gallerySortGroups();
320+       }
321+       
322+       // @todo: fix me!
323+       // When an update has occurred, adjust the order for each item..
324        var galleryReorder = function(e, sort) {
325+               var o = 0;
326                jQuery.each(sort['element'].sortable('toArray'), function(i, id) {
327-                       jQuery('#' + id + ' .menu_order input')[0].value = (1+i);
328+                       if (id)
329+                       {
330+                               o++;
331+                               jQuery('#' + id + ' .menu_order input')[0].value = o;
332+                       }
333                });
334        }
335-
336+       
337+       var gallerySortGroups = function () {
338+               var mediaGroups = jQuery(".media-groups").length;
339+               for (g = 0; g < mediaGroups; g++)
340+               {
341+                       jQuery.each(jQuery("#media-group-" + g + " .media-item input.group-value"), function(i, id) {
342+                               jQuery(id)[0].value = g;               
343+                       });
344+               }
345+       }
346+       
347        // initialize sortable
348        gallerySortableInit();
349 });
350Index: wp-admin/options-media.php
351===================================================================
352--- wp-admin/options-media.php  (revision 9143)
353+++ wp-admin/options-media.php  (working copy)
354@@ -39,6 +39,26 @@
355     }
356 ?>
357 </fieldset></td>
358+</tr>
359+<tr valign="top">
360+<th scope="row"><?php _e('Image display') ?></th>
361+<td><fieldset><legend class="hidden"><?php _e('Image display') ?></legend>
362+<?php
363+    $display_types = array('none' => 'Default', 'lightbox' => 'Lightbox', 'shutterset' => 'Shutter Set',
364+                                               'lytebox' => 'Lyte Box', 'greybox' => 'Grey Box', 'thickbox' => 'Thick Box', 'lightview' => 'Light View'
365+       );
366+
367+    $default_image_display_type = get_option('image_display_type');
368+        if ( empty($default_image_display_type) )
369+            $default_image_display_type = 'none';
370+
371+    foreach ($display_types as $type => $name) { ?>
372+        <input type="radio" name="image_display_type" id="image_display_type_<?php echo $type; ?>" value="<?php echo $type; ?>"<?php echo ($default_image_display_type == $type ? ' checked="checked"' : ''); ?> />
373+        <label for="image_display_type_<?php echo $type; ?>"><?php _e($name); ?></label>
374+    <?php
375+    }
376+?>
377+</fieldset></td>
378 </tr>
379 </table>
380 
381Index: wp-admin/options.php
382===================================================================
383--- wp-admin/options.php        (revision 9143)
384+++ wp-admin/options.php        (working copy)
385@@ -25,7 +25,7 @@
386        'general' => array('blogname', 'blogdescription', 'admin_email', 'users_can_register', 'gmt_offset', 'date_format', 'time_format', 'start_of_week', 'comment_registration', 'default_role' ),
387        'discussion' => array( 'default_pingback_flag', 'default_ping_status', 'default_comment_status', 'comments_notify', 'moderation_notify', 'comment_moderation', 'require_name_email', 'comment_whitelist', 'comment_max_links', 'moderation_keys', 'blacklist_keys', 'show_avatars', 'avatar_rating', 'avatar_default', 'close_comments_for_old_posts', 'close_comments_days_old', 'thread_comments', 'thread_comments_depth', 'page_comments', 'comments_per_page' ),
388        'misc' => array( 'hack_file', 'use_linksupdate', 'uploads_use_yearmonth_folders', 'upload_path' ),
389-       'media' => array( 'thumbnail_size_w', 'thumbnail_size_h', 'thumbnail_crop', 'medium_size_w', 'medium_size_h', 'large_size_w', 'large_size_h', 'image_default_size', 'image_default_align', 'image_default_link_type' ),
390+       'media' => array( 'thumbnail_size_w', 'thumbnail_size_h', 'thumbnail_crop', 'medium_size_w', 'medium_size_h', 'large_size_w', 'large_size_h', 'image_default_size', 'image_default_align', 'image_default_link_type', 'image_display_type' ),
391        'privacy' => array( 'blog_public' ),
392        'reading' => array( 'posts_per_page', 'posts_per_rss', 'rss_use_excerpt', 'blog_charset', 'gzipcompression', 'show_on_front', 'page_on_front', 'page_for_posts' ),
393        'writing' => array( 'default_post_edit_rows', 'use_smilies', 'ping_sites', 'mailserver_url', 'mailserver_port', 'mailserver_login', 'mailserver_pass', 'default_category', 'default_email_category', 'use_balanceTags', 'default_link_category', 'enable_app', 'enable_xmlrpc' ),
394Index: wp-content/themes/classic/style.css
395===================================================================
396--- wp-content/themes/classic/style.css (revision 9143)
397+++ wp-content/themes/classic/style.css (working copy)
398@@ -320,7 +320,64 @@
399        text-transform: capitalize;
400 }
401 
402-/* Captions & aligment */
403+/* Gallery & Captions & Aligment */
404+
405+.gallery {
406+       display: block;
407+       clear: left;
408+       overflow: hidden;
409+       margin: auto;
410+}
411+       
412+.gallery-item {
413+       float: left;
414+       margin: 10px 0 0 0;
415+       text-align: center;
416+}
417+       
418+.gallery .gallery-item img, .gallery .gallery-item img.thumbnail {
419+       max-width: 89%;
420+       height: auto;
421+       padding: 1%;
422+       margin: 0
423+       auto;
424+}
425+
426+.gallery div.clear {
427+       width: 0px;
428+       height: 0px;
429+}
430+
431+.col-1 { width: 100%; }
432+.col-2 { width: 50%; }
433+.col-3 { width: 33%; }
434+.col-4 { width: 24.5%; }
435+.col-5 { width: 20%; }
436+.col-6 { width: 16.5%; }
437+.col-7 { width: 14%; }
438+.col-8 { width: 12.4%; }
439+.col-9 { width: 11%; }
440+.col-10 { width: 10%; }
441+.col-11 { width: 9%; }
442+.col-12 { width: 8.33%; }
443+.col-13 { width: 7.6%; }
444+.col-14 { width: 7.1%; }
445+.col-15 { width: 6.66%; }
446+.col-16 { width: 6.25%; }
447+.col-17 { width: 5.83%; }
448+.col-18 { width: 5.55%; }
449+.col-19 { width: 5.25%; }
450+.col-20 { width: 4.95%; }
451+
452+.gallery-caption {
453+       margin-left: 0;
454+}
455+
456+.gallery-space {
457+       clear: both;
458+       height: 0;
459+}
460+
461 .aligncenter,
462 div.aligncenter {
463        display: block;
464@@ -360,4 +417,4 @@
465        padding: 0 4px 5px;
466        margin: 0;
467 }
468-/* End captions & aligment */
469+/* End Gallery & Captions & Aligment */
470Index: wp-content/themes/default/style.css
471===================================================================
472--- wp-content/themes/default/style.css (revision 9143)
473+++ wp-content/themes/default/style.css (working copy)
474@@ -663,9 +663,64 @@
475        }
476 /* End Various Tags & Classes*/
477 
478+/* Gallery & Captions & Aligment */
479 
480+.gallery {
481+       display: block;
482+       clear: left;
483+       overflow: hidden;
484+       margin: auto;
485+}
486+       
487+.gallery-item {
488+       float: left;
489+       margin: 10px 0 0 0;
490+       text-align: center;
491+}
492+       
493+.gallery .gallery-item img, .gallery .gallery-item img.thumbnail {
494+       max-width: 89%;
495+       height: auto;
496+       padding: 1%;
497+       margin: 0
498+       auto;
499+}
500 
501-/* Captions */
502+.gallery div.clear {
503+       width: 0px;
504+       height: 0px;
505+}
506+
507+.col-1 { width: 100%; }
508+.col-2 { width: 50%; }
509+.col-3 { width: 33%; }
510+.col-4 { width: 24.5%; }
511+.col-5 { width: 20%; }
512+.col-6 { width: 16.5%; }
513+.col-7 { width: 14%; }
514+.col-8 { width: 12.4%; }
515+.col-9 { width: 11%; }
516+.col-10 { width: 10%; }
517+.col-11 { width: 9%; }
518+.col-12 { width: 8.33%; }
519+.col-13 { width: 7.6%; }
520+.col-14 { width: 7.1%; }
521+.col-15 { width: 6.66%; }
522+.col-16 { width: 6.25%; }
523+.col-17 { width: 5.83%; }
524+.col-18 { width: 5.55%; }
525+.col-19 { width: 5.25%; }
526+.col-20 { width: 4.95%; }
527+
528+.gallery-caption {
529+       margin-left: 0;
530+}
531+
532+.gallery-space {
533+       clear: both;
534+       height: 0;
535+}
536+
537 .aligncenter,
538 div.aligncenter {
539        display: block;
540@@ -673,6 +728,14 @@
541        margin-right: auto;
542 }
543 
544+.alignleft {
545+       float: left;
546+}
547+
548+.alignright {
549+       float: right;
550+}
551+
552 .wp-caption {
553        border: 1px solid #ddd;
554        text-align: center;
555@@ -697,9 +760,8 @@
556        padding: 0 4px 5px;
557        margin: 0;
558 }
559-/* End captions */
560+/* End Gallery & Captions & Aligment */
561 
562-
563 /* "Daisy, Daisy, give me your answer do. I'm half crazy all for the love of you.
564        It won't be a stylish marriage, I can't afford a carriage.
565        But you'll look sweet upon the seat of a bicycle built for two." */
566Index: wp-includes/js/swfupload/handlers.js
567===================================================================
568--- wp-includes/js/swfupload/handlers.js        (revision 9143)
569+++ wp-includes/js/swfupload/handlers.js        (working copy)
570@@ -126,16 +126,23 @@
571        }
572 
573        // Only show Save buttons when there is at least one file.
574-       if ( jQuery('#media-items>*').not('.media-blank').length > 0 )
575+       if ( jQuery('#media-items .media-item').not('.media-no-items').length > 0 )
576                jQuery('.savebutton').show();
577        else
578                jQuery('.savebutton').hide();
579 
580+       // Only show new Gallery button when there are at least two files.
581+       if ( jQuery('#media-items .media-item').not('.media-no-items').length > 1 )
582+               jQuery('.new-gallery').show();
583+       else
584+               jQuery('.new-gallery').hide();
585+
586        // Only show Gallery button when there are at least two files.
587-       if ( jQuery('#media-items>*').length > 1 )
588+       if ( jQuery('#media-items .media-groups').length > 1 )
589                jQuery('.insert-gallery').show();
590        else
591                jQuery('.insert-gallery').hide();
592+               
593 }
594 
595 function uploadSuccess(fileObj, serverData) {
596Index: wp-includes/media.php
597===================================================================
598--- wp-includes/media.php       (revision 9143)
599+++ wp-includes/media.php       (working copy)
600@@ -617,12 +617,15 @@
601                'icontag'    => 'dt',
602                'captiontag' => 'dd',
603                'columns'    => 3,
604+               'class'          => get_option('image_display_type'),
605+               'name'           => null,
606+               'group'          => null,
607                'size'       => 'thumbnail',
608        ), $attr));
609 
610        $id = intval($id);
611-       $attachments = get_children( array('post_parent' => $id, 'post_status' => 'inherit', 'post_type' => 'attachment', 'post_mime_type' => 'image', 'order' => $order, 'orderby' => $orderby) );
612-
613+       $attachments = get_attachments( $id, array('group_number' => $group, 'name' => $name, 'order' => $order, 'orderby' => $orderby), get_children( array('post_parent' => $id, 'post_status' => 'inherit', 'post_type' => 'attachment', 'post_mime_type' => 'image', 'order' => $order, 'orderby' => $orderby) ) );
614+       
615        if ( empty($attachments) )
616                return '';
617 
618@@ -639,47 +642,86 @@
619        $columns = intval($columns);
620        $itemwidth = $columns > 0 ? floor(100/$columns) : 100;
621 
622-       $output = apply_filters('gallery_style', "
623-               <style type='text/css'>
624-                       .gallery {
625-                               margin: auto;
626-                       }
627-                       .gallery-item {
628-                               float: left;
629-                               margin-top: 10px;
630-                               text-align: center;
631-                               width: {$itemwidth}%;                   }
632-                       .gallery img {
633-                               border: 2px solid #cfcfcf;
634-                       }
635-                       .gallery-caption {
636-                               margin-left: 0;
637-                       }
638-               </style>
639-               <!-- see gallery_shortcode() in wp-includes/media.php -->
640-               <div class='gallery'>");
641+       if ( is_null($group) ) {
642+               $group_area = 0;
643+               $group_gallery = "-" . $group_area;
644+       } else {
645+               $group_area = $group;
646+               $group_gallery = "-" . $group;
647+       }
648+       
649+       $output = apply_filters('gallery_style', "<div id='gallery-$post->ID-$group_area' class='gallery'>");
650 
651        foreach ( $attachments as $id => $attachment ) {
652-               $link = wp_get_attachment_link($id, $size, true);
653-               $output .= "<{$itemtag} class='gallery-item'>";
654-               $output .= "
655-                       <{$icontag} class='gallery-icon'>
656-                               $link
657-                       </{$icontag}>";
658+               
659+               if ( !is_null($attachment->group_name) )
660+                       $group_name = $attachment->group_name;
661+               
662+               if ( !is_null($group) )
663+                       if ($attachment->group_number != $group)
664+                               continue;
665+
666+               $a_img = wp_get_attachment_url($id);
667+               $att_page = get_attachment_link($id);
668+               $img = wp_get_attachment_image_src($id, $size);
669+               
670+               $img = $img[0];
671+               $title = $attachment->post_excerpt;
672+               
673+               if ($title == '')
674+                       $title = $attachment->post_title;
675+               
676+               $output .= "\n<{$itemtag} class='gallery-item col-$columns'>\n";
677+               $output .= "<{$icontag} class='gallery-icon'>\n";
678+               
679+               switch ($class)
680+               {
681+                       case 'lightbox':
682+                               $class_rel = ' class="lightbox" rel="lightbox[gallery-'.$post->ID.$group_gallery.']"';
683+                               break;
684+                       case 'shutterset':
685+                               $class_rel = ' class="shutterset-gallery-'.$post->ID.$group_gallery.'" rel="lightbox[gallery-'.$post->ID.$group_gallery.']"';
686+                               break;
687+                       case 'lytebox':
688+                               $class_rel = ' class="lytebox" rel="lytebox[gallery-'.$post->ID.$group_gallery.']"';
689+                               break;
690+                       case 'greybox':
691+                               $class_rel = ' class="greybox" rel="gb_imageset[gallery-'.$post->ID.$group_gallery.']"';
692+                               break;
693+                       case 'thickbox':
694+                               $class_rel = ' class="thickbox" rel="gallery-'.$post->ID.$group_gallery.'"';
695+                               break;
696+                       case 'lightview':
697+                               $class_rel = ' class="lightview" rel="gallery[gallery-'.$post->ID.$group_gallery.']"';
698+                               break;
699+                       default:
700+                               $class_rel = null;
701+                               break;
702+               }
703+
704+               if (!is_null($class_rel))
705+                       $link = $a_img;
706+               else
707+                       $link = $att_page;
708+               
709+               $output .= "\t<a href=\"$link\" title=\"$title\"$class_rel><img src=\"$img\" alt=\"$title\" /></a>";
710+               $output .= "\n</{$icontag}>";
711+               
712                if ( $captiontag && trim($attachment->post_excerpt) ) {
713-                       $output .= "
714-                               <{$captiontag} class='gallery-caption'>
715-                               {$attachment->post_excerpt}
716-                               </{$captiontag}>";
717+                       $output .= "\n<$captiontag class='gallery-caption'>\n\t";
718+                       $output .= $attachment->post_excerpt;
719+                       $output .= "</$captiontag>";
720                }
721-               $output .= "</{$itemtag}>";
722-               if ( $columns > 0 && ++$i % $columns == 0 )
723-                       $output .= '<br style="clear: both" />';
724+               
725+               $output .= "\n</{$itemtag}>";
726+               
727+               if($columns > 0 && ++$i % $columns == 0)
728+                       $output .= '<div style="clear:both;" class="gallery-space"><!-- --></div>';
729        }
730+       $output .= "\n</div>\n";
731 
732-       $output .= "
733-                       <br style='clear: both;' />
734-               </div>\n";
735+       if ((isset($group_name)) && (!is_null($group)))
736+               $output .= "<p style=\"text-align: center;\"><strong>".$group_name."</strong></p>\n";
737 
738        return $output;
739 }
740Index: wp-includes/post.php
741===================================================================
742--- wp-includes/post.php        (revision 9143)
743+++ wp-includes/post.php        (working copy)
744@@ -69,6 +69,272 @@
745 }
746 
747 /**
748+ * Get the posts attachments data.
749+ *
750+ * @since 2.7.0
751+ *
752+ * @param int $post_id Post ID
753+ */
754+function _get_attachment_data ( $post_id ) {
755+       global $wpdb;
756+
757+       $_attchments = $wpdb->get_row($wpdb->prepare("SELECT * FROM $wpdb->postmeta WHERE post_id = %d AND meta_key = '_wp_post_attachments' LIMIT 1", $post_id));
758+       return unserialize($_attchments->meta_value);
759+}
760+
761+/**
762+ * Get the posts attachments.
763+ *
764+ * @since 2.7.0
765+ *
766+ * @param int $post_id Post ID
767+ * @param mixed $attachment_options Group Options
768+ * @param mixed $attachment_childern All the childern's of the current post in an array.
769+ */
770+function &get_attachments( $post_id, $attachment_options = '', $attachment_childern ) {
771+
772+       extract($attachment_options, EXTR_SKIP);
773+
774+       if (!is_null($name)) {
775+               
776+               if (is_numeric($name))
777+                       $post_id = $name;
778+               
779+               if ($page = get_page_by_title($name))
780+                       $post_id = $page->ID;
781+               
782+               if ($post = get_post_by_title($name))
783+                       $post_id = $post->ID;
784+               
785+               // @todo: This is untested.
786+               $attachment_childern = get_children( array('post_parent' => $post_id, 'post_status' => 'inherit', 'post_type' => 'attachment', 'post_mime_type' => 'image', 'order' => $order, 'orderby' => $orderby) );
787+       }
788+       
789+       $attachment = _get_attachment_data ( $post_id );
790+       
791+       if ( !is_array($attachment) )
792+               return;
793+
794+       foreach ( $attachment_childern as $id => $image ) {
795+               
796+               foreach ( $attachment as $key => $group ) {
797+               
798+                       if ( !is_array($group['items']) )
799+                               continue;
800+                               
801+                       if (is_null($group_number)) {
802+                               if ($key == 0) { continue; }
803+                       } else {
804+                               if ($key != $group_number) { continue; }
805+                       }
806+                       
807+                       if (in_array($id, $group['items'])) {
808+                               
809+                               $image = $attachment_childern[$id];
810+                               $image->group_number = $key;
811+                               $image->group_name = $group['name'];
812+                               
813+                               $attach[$id] = $image;
814+                       
815+                       }
816+
817+               }
818+               
819+       }
820+       
821+       return $attach;
822+}
823+
824+/**
825+ * Get the gallery groups names.
826+ *
827+ * @since 2.7.0
828+ *
829+ * @param int $post_id Post ID
830+ */
831+function &get_attachments_groupsname( $post_id ) {
832+
833+       $attachment = _get_attachment_data ( $post_id );
834+       
835+       if ( !is_array($attachment) )
836+               return '';
837+       
838+       foreach ( $attachment as $key => $group ) {
839+               $groups[$key] = $group['name'];
840+       }
841+       
842+       return $groups;
843+}
844+
845+/**
846+ * Get the number of groups attached to this post.
847+ *
848+ * @since 2.7.0
849+ *
850+ * @param int $post_id Post ID
851+ */
852+function get_attachment_groups( $post_id ) {
853+       
854+       return count(_get_attachment_data ( $post_id ));
855+}
856+
857+/**
858+ * Insert a new gallery into the post.
859+ *
860+ * @since 2.7.0
861+ *
862+ * @param int $post_id post data
863+*/
864+function wp_new_gallery ( $post_id ) {
865+
866+       $attachment = _get_attachment_data ( $post_id );
867+
868+       foreach ( $attachment as $key => $group ) {
869+               $_group[$key] = array ('name' => $group['name'], 'items' => $group['items']);
870+       }
871+
872+       $_group[] = array ('name' => null, 'items' => null);
873+       
874+       update_post_meta( $post_id, '_wp_post_attachments', $_group);
875+       
876+}
877+
878+/**
879+ * We are deleting a gallery and moving
880+ *
881+ * @since 2.7.0
882+ *
883+ * @param int $post_id Post ID
884+ * @param int $group_number Group Number
885+*/
886+function wp_delete_gallery ( $post_id, $group_num ) {
887+       
888+       $attachment = _get_attachment_data ( $post_id );
889+       
890+       foreach ( $attachment as $key => $group ) {
891+               if ($key != $group_num) {
892+                       $_group[$key] = array ('name' => $group['name'], 'items' => $group['items']);
893+                       continue;                                               
894+               }       
895+               
896+               if ( !is_array($group['items']) )
897+                       break;
898+               
899+               foreach ( $group['items'] as $item => $attachment_id ) {
900+                       $_attach[] = $attachment_id;   
901+               }
902+       }
903+       
904+       if ( is_array($_group[0]['items']) && is_array($_attach) )  {
905+               $i = array_merge($_group[0]['items'], $_attach);       
906+               $_group[0] = array ('name' => null, 'items' => $i);     
907+       } else {
908+               $_group[0] = array ('name' => null, 'items' => $_group[0]['items']);
909+       }
910+
911+       update_post_meta( $post_id, '_wp_post_attachments', $_group );
912+
913+}
914+
915+/**
916+ * Updating the postmeta data when saving the gallery information.
917+ *
918+ * @since 2.7.0
919+ *
920+ * @param int $attachment_id Attachment ID
921+ * @param int $post_id Post ID
922+ * @param int $group_name Group Name
923+ * @param int $group_number Group Number
924+*/
925+function wp_update_attachment ( $attachment_id, $post_id, $group_name = null, $group_number = null) {
926+       
927+       $attachment = _get_attachment_data ( $post_id );
928+
929+       if (!is_array($attachment)) {
930+               $_attach[] = array ('name' => null, 'items' => array($attachment_id) );
931+               add_post_meta($post_id, '_wp_post_attachments', $_attach, true);
932+               return true;
933+       }
934+
935+       //      check to see if this group ($group_number) has a name assignment and is not null
936+       
937+       /*
938+       if (( !isset($attachment[$group_number][name]) ) || ( !is_null($attachment[$group_number][name]) ))
939+               if ($group_name != $attachment[$group_number][name])
940+                       _update_attachment_groupname( $post_id, $group_number, $group_name );   // update group name of group number if they are not the same (should only happen once if it does change)
941+       
942+       */
943+       
944+       //      check to see if this attachment ($attachment_id) is not part of the group. If it's not part of this group add it to the group.
945+       $update = false;
946+       foreach ( $attachment as $key => $group ) {
947+               if ($key == $group_number) {
948+                       if ((!is_array($group['items'])) || (!in_array($attachment_id, $group['items']) )) {
949+                               if ($key == $group_number) {
950+                                       $update = true;
951+                                       $i[count($group['items'])] = $attachment_id;
952+                                       
953+                                       if (!is_array($group['items']))
954+                                               $group['items'] = $i;
955+                                       else
956+                                               $group['items'] = array_merge($group['items'], $i);
957+                                       
958+                                       _update_attachment_groupitem( $post_id, $key, $group['items'] );
959+                               }
960+                       }
961+               }
962+       }
963+       foreach ( $attachment as $key => $group ) {
964+               if (($key != $group_number) && ($update)) {
965+                       if ( in_array($attachment_id, $group['items']) ) {
966+                               foreach ($group['items'] as $item => $attach) {
967+                                       if ($attach != $attachment_id)
968+                                               $g[] = $attach;
969+                               }
970+                               _update_attachment_groupitem( $post_id, $key, $g );
971+                       }
972+               }       
973+       }
974+       
975+}
976+
977+/**
978+ * Updateing the group name. (Private)
979+ *
980+ * @since 2.7.0
981+ *
982+ * @param int $post_id Post ID
983+ * @param int $group_number Group Number
984+ * @param str $group_name Group Name
985+*/
986+function _update_attachment_groupname ( $post_id, $group_number, $group_name ) {
987+               
988+       $_attachment = _get_attachment_data ( $post_id );
989+       $_attachment[$group_number][name] = stripslashes($group_name);
990+       
991+       update_post_meta( $post_id, '_wp_post_attachments', $_attachment );
992+       
993+}
994+
995+/**
996+ * Updateing the group items. (Private)
997+ *
998+ * @since 2.7.0
999+ *
1000+ * @param int $post_id Post ID
1001+ * @param int $group_number Group Number
1002+ * @param array $attachment_data The new item data for this group.
1003+*/
1004+function _update_attachment_groupitem ( $post_id, $group_number, $attachment_data ) {
1005+       
1006+       $_attachment = _get_attachment_data ( $post_id );
1007+       $_attachment[$group_number][items] = $attachment_data;
1008+       
1009+       update_post_meta( $post_id, '_wp_post_attachments', $_attachment );
1010+
1011+}
1012+
1013+ /**
1014+ * Retrieve a post given its title.
1015+ *
1016+ * @since 2.7.0
1017+ * @uses $wpdb
1018+ *
1019+ * @param string $page_title Page title
1020+ * @param string $output Optional. Output type. OBJECT, ARRAY_N, or ARRAY_A.
1021+ * @return mixed
1022+ */
1023+function get_post_by_title($page_title, $output = OBJECT) {
1024+       global $wpdb;
1025+       $post = $wpdb->get_var( $wpdb->prepare( "SELECT ID FROM $wpdb->posts WHERE post_title = %s AND post_type='post'", $page_title ));
1026+       if ( $post )
1027+               return get_post($post, $output);
1028+
1029+       return null;
1030+}
1031+
1032+/**
1033  * Retrieve child pages from list of pages matching page ID.
1034  *
1035  * Matches against the pages parameter against the page ID. Also matches all
1036@@ -2244,7 +2558,7 @@
1037 
1038        // export array as variables
1039        extract($object, EXTR_SKIP);
1040-
1041+       
1042        // Make sure we set a valid category
1043        if (0 == count($post_category) || !is_array($post_category)) {
1044                $post_category = array(get_option('default_category'));
1045@@ -2338,6 +2652,8 @@
1046                $post_name = sanitize_title($post_title, $post_ID);
1047                $wpdb->update( $wpdb->posts, compact("post_name"), array( 'ID' => $post_ID ) );
1048        }
1049+       
1050+       wp_update_attachment($post_ID, $post_parent, $group_name, $group_number);       // update or insert attachment into postmeta field
1051 
1052        wp_set_post_categories($post_ID, $post_category);
1053