Make WordPress Core

Ticket #7607: 7607.2.diff

File 7607.2.diff, 26.7 KB (added by ShaneF, 17 years ago)
  • wp-admin/includes/media.php

     
    1616function media_upload_tabs() {
    1717        $_default_tabs = array(
    1818                'type' => __('Choose File'), // handler action suffix => tab text
    19                 'gallery' => __('Gallery'),
     19                'gallery' => __('Attachments'),
    2020                'library' => __('Media Library'),
    2121        );
    2222
     
    4040        if ( intval($_REQUEST['post_id']) )
    4141                $attachments = intval($wpdb->get_var($wpdb->prepare("SELECT count(*) FROM $wpdb->posts WHERE post_type = 'attachment' AND post_parent = %d", $_REQUEST['post_id'])));
    4242
    43         $tabs['gallery'] = sprintf(__('Gallery (%s)'), "<span id='attachments-count'>$attachments</span>");
     43        $tabs['gallery'] = sprintf(__('Attachments (%s)'), "<span id='attachments-count'>$attachments</span>");
    4444
    4545        return $tabs;
    4646}
     
    9898        $rel = $rel ? ' rel="attachment wp-att-'.attribute_escape($id).'"' : '';
    9999
    100100        if ( $url )
    101                 $html = '<a href="' . clean_url($url) . "\"$rel>$html</a>";
     101                $html = '<a href="' . clean_url($url) . "\" title=\"". attribute_escape($title) ."\"$rel>$html</a>";
    102102
    103103        $html = apply_filters( 'image_send_to_editor', $html, $id, $alt, $title, $align, $url, $size );
    104104
     
    358358                        $post['post_title'] = $attachment['post_title'];
    359359                if ( isset($attachment['post_excerpt']) )
    360360                        $post['post_excerpt'] = $attachment['post_excerpt'];
     361                if ( isset($attachment['group_number']) )
     362                        $post['group_number'] = $attachment['group_number'];
    361363                if ( isset($attachment['menu_order']) )
    362364                        $post['menu_order'] = $attachment['menu_order'];
    363365
     
    376378                                wp_set_object_terms($attachment_id, array_map('trim', preg_split('/,+/', $attachment[$t])), $t, false);
    377379        }
    378380
    379         if ( isset($_POST['insert-gallery']) )
    380                 return media_send_to_editor('[gallery]');
     381        if ( isset($_POST['insert-gallery']) ) {
     382                if ( ( isset($_POST['gallery_insert']) ) && ( $_POST['gallery_insert'] > 0 ) ) {
     383                        return media_send_to_editor('[gallery group="'.$_POST['gallery_insert'].'"]');
     384                } else {
     385                        return media_send_to_editor('[gallery]');
     386                }
     387        }
     388       
     389        if ( isset($_POST['new-gallery']) )
     390                wp_new_gallery($post['post_parent']);
     391               
     392        if ( isset($_POST['gallery_delete']) && !is_null($_POST['gallery_delete']) && ($_POST['gallery_delete'] > 0) )
     393                wp_delete_gallery($post['post_parent'], $_POST['gallery_delete']);
    381394
    382395        if ( isset($_POST['send']) ) {
    383396                $keys = array_keys($_POST['send']);
     
    426439                        $align = attribute_escape($_POST['insertonly']['align']);
    427440                        $class = " class='align$align'";
    428441                }
     442                if ( isset($_POST['insertonly']['title']) ) {
     443                        $title = " title='".attribute_escape($_POST['insertonly']['title'])."'";
     444                }
    429445                if ( !empty($src) )
    430                         $html = "<img src='$src' alt='$alt'$class />";
     446                        $html = "<img src='$src' alt='$alt'$title$class />";
    431447                return media_send_to_editor($html);
    432448        }
    433449
     
    844860                        $post['errors']['post_title']['errors'][] = __('Empty Title filled from filename.');
    845861                }
    846862        }
     863       
     864        $post['group_name'] = $_POST['attachments']['group_name'][$attachment['group_number']];
    847865
    848866        return $post;
    849867}
     
    968986 * @param unknown_type $errors
    969987 * @return unknown
    970988 */
    971 function get_media_items( $post_id, $errors ) {
     989function get_media_items( $post_id, $group_num = null, $errors ) {
    972990        if ( $post_id ) {
    973991                $post = get_post($post_id);
    974                 if ( $post && $post->post_type == 'attachment' )
     992                if ( $post && $post->post_type == 'attachment' ) {
    975993                        $attachments = array($post->ID => $post);
    976                 else
    977                         $attachments = get_children( array( 'post_parent' => $post_id, 'post_type' => 'attachment', 'orderby' => 'menu_order ASC, ID', 'order' => 'DESC') );
     994                } else {
     995                        $attachments = get_attachments( $post_id, $group_num );
     996                       
     997                        if ( ! count($attachments) )
     998                                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>";
     999                }
    9781000        } else {
    9791001                if ( is_array($GLOBALS['wp_the_query']->posts) )
    9801002                        foreach ( $GLOBALS['wp_the_query']->posts as $attachment )
     
    9841006        if ( empty($attachments) )
    9851007                return '';
    9861008
    987         foreach ( $attachments as $id => $attachment )
     1009        foreach ( $attachments as $id => $attachment ) {       
    9881010                if ( $item = get_media_item( $id, array( 'errors' => isset($errors[$id]) ? $errors[$id] : null) ) )
    9891011                        $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>";
    990 
     1012        }
     1013       
    9911014        return $output;
    9921015}
    9931016
     
    10251048        $filename = basename($post->guid);
    10261049        $title = attribute_escape($post->post_title);
    10271050        $description = attribute_escape($post->post_content);
     1051        $group_number = attribute_escape($post->group_number);
    10281052        if ( $_tags = get_the_tags($attachment_id) ) {
    10291053                foreach ( $_tags as $tag )
    10301054                        $tags[] = $tag->name;
     
    10551079        $gallery = ( (isset($_REQUEST['tab']) && 'gallery' == $_REQUEST['tab']) || (isset($redir_tab) && 'gallery' == $redir_tab) ) ? true : false;
    10561080        $order = '';
    10571081
     1082        $groupnum = '<input type="hidden" class="group-value" name="attachments['.$attachment_id.'][group_number]" value="'.$group_number.'" />';
     1083
    10581084        foreach ( $form_fields as $key => $val ) {
    10591085                if ( 'menu_order' == $key ) {
    10601086                        if ( $gallery )
     
    10711097        $type
    10721098        $toggle_links
    10731099        $order
     1100        $groupnum
    10741101        $display_title
    10751102        <table class='slidetoggle describe $class'>
    10761103                <thead class='media-item-info'>
     
    13541381                html = '<img alt="'+alt+'" src="'+f.src.value+'"'+title+cls+' width="'+t.width+'" height="'+t.height+'" />';
    13551382
    13561383                if ( f.url.value )
    1357                         html = '<a href="'+f.url.value+'">'+html+'</a>';
     1384                        html = '<a href="'+f.url.value+'"'+title+'>'+html+'</a>';
    13581385
    13591386                if ( caption )
    13601387                        html = '[caption id="" align="'+t.align+'" width="'+t.width+'" caption="'+caption+'"]'+html+'[/caption]';
     
    14241451        media_upload_header();
    14251452
    14261453        $post_id = intval($_REQUEST['post_id']);
     1454        $group_num = intval(get_attachment_groups( $post_id ));
     1455        $_group_name = get_attachments_groupsname( $post_id );
     1456       
    14271457        $form_action_url = admin_url("media-upload.php?type={$GLOBALS['type']}&tab=gallery&post_id=$post_id");
    14281458?>
    14291459
     
    14331463        var preloaded = $(".media-item.preloaded");
    14341464        if ( preloaded.length > 0 ) {
    14351465                preloaded.each(function(){prepareMediaItem({id:this.id.replace(/[^0-9]/g, '')},'');});
    1436                 updateMediaForm();
    14371466        }
     1467        jQuery("a.del-group").click(function () {
     1468                var deleteConfirmation = confirm('<?php _e("Are you sure you want to delete this gallery group?"); ?>');
     1469               
     1470                if (!deleteConfirmation) { return; }
     1471               
     1472                if (jQuery("#media-group-" + jQuery(this).attr('value') + " .media-item input.group-value").length)
     1473                {
     1474                        jQuery.each(jQuery("#media-group-delete-" + jQuery(this).attr('value') + " .media-item input.group-value"), function(i, id) {
     1475                                jQuery(id)[0].value = 0;        //      we are going to set all the items to group 0             
     1476                        });
     1477                }
     1478                jQuery("#gallery-delete").val( jQuery(this).attr('value') );    //      set the gallery we are deleting
     1479                jQuery("#media-group-" + jQuery(this).attr('value')).hide();    //      hide the gallery and then...
     1480                jQuery(".savebutton").click();
     1481        });
     1482        jQuery("a.insert-group").click(function () {
     1483                jQuery("#gallery-insert").val( jQuery(this).attr('value') );    //      set the gallery we are inserting
     1484                jQuery(".insert-gallery").click();               
     1485        });
    14381486});
    14391487-->
    14401488</script>
     
    14421490<form enctype="multipart/form-data" method="post" action="<?php echo attribute_escape($form_action_url); ?>" class="media-upload-form validate" id="gallery-form">
    14431491<?php wp_nonce_field('media-form'); ?>
    14441492<?php //media_upload_form( $errors ); ?>
     1493<div id="media-items">
     1494<?php
     1495for ( $i = 0; $i < $group_num; $i++ )
     1496{
     1497?>
     1498<div id="media-group-<?php echo $i; ?>" class="media-groups">
     1499<input type="hidden" id="media-group-value-<?php echo $i; ?>" value="<?php echo $i; ?>" />
    14451500<table class="widefat">
    14461501<thead><tr>
    1447 <th><?php _e('Media'); ?></th>
     1502<th>
     1503<?php 
     1504if ($i > 0) {
     1505       
     1506        $delete = "<a href=\"#media-group-delete-value-".$i."\" value=\"".$i."\" class=\"del-group\">" . __('Delete') . "</a>";
     1507        $insert = "<a href=\"#media-group-insert-value-".$i."\" value=\"".$i."\" class=\"insert-group\">" . __('Insert') . "</a>";
     1508        $group_link = "<small>[".$delete." | " .$insert."]</small>";
     1509        $group_name = "<input type=\"text\" name=\"attachments[group_name][".$i."]\" value=\"" . $_group_name[$i] . "\" size=\"20\" />";
     1510       
     1511        printf( __('Group (%1$d) %2$s %3$s'), $i, $group_name, $group_link);
     1512
     1513               
     1514} else {
     1515
     1516        _e('Media: Non-grouped items.');
     1517       
     1518}
     1519?>
     1520</th>
    14481521<th class="order-head"><?php _e('Order'); ?></th>
    14491522</tr></thead>
    14501523</table>
    1451 <div id="media-items">
    1452 <?php echo get_media_items($post_id, $errors); ?>
     1524<?php echo get_media_items($post_id, $i, $errors); ?>
    14531525</div>
     1526<?php
     1527}
     1528?>
     1529</div>
    14541530<p class="ml-submit">
    14551531<input type="submit" class="button savebutton" name="save" value="<?php echo attribute_escape( __( 'Save all changes' ) ); ?>" />
    1456 <input type="submit" class="button insert-gallery" name="insert-gallery" value="<?php echo attribute_escape( __( 'Insert gallery into post' ) ); ?>" />
     1532<input type="submit" class="button new-gallery" name="new-gallery" value="<?php echo attribute_escape( __( 'Create new gallery' ) ); ?>" />
     1533<input type="submit" class="button insert-gallery" name="insert-gallery" value="<?php echo attribute_escape( __( 'Insert full gallery into post' ) ); ?>" />
     1534<input type="hidden" name="gallery_delete" id="gallery-delete" value="" />
     1535<input type="hidden" name="gallery_insert" id="gallery-insert" value="" />
    14571536<input type="hidden" name="post_id" id="post_id" value="<?php echo (int) $post_id; ?>" />
    14581537<input type="hidden" name="type" value="<?php echo attribute_escape( $GLOBALS['type'] ); ?>" />
    14591538<input type="hidden" name="tab" value="<?php echo attribute_escape( $GLOBALS['tab'] ); ?>" />
    14601539</p>
    14611540</form>
     1541<script type="text/javascript">
     1542<!--
     1543        updateMediaForm();
     1544-->
     1545</script>
    14621546<?php
    14631547}
    14641548
     
    16051689</script>
    16061690
    16071691<div id="media-items">
    1608 <?php echo get_media_items(null, $errors); ?>
     1692<?php echo get_media_items(null, null, $errors); ?>
    16091693</div>
    16101694<p class="ml-submit">
    16111695<input type="submit" class="button savebutton" name="save" value="<?php echo attribute_escape( __( 'Save all changes' ) ); ?>" />
  • wp-admin/js/gallery.js

     
    11jQuery(function($) {
    22        var gallerySortable;
     3
    34        var gallerySortableInit = function() {
    45                gallerySortable = $('#media-items').sortable( {
    56                        items: '.media-item',
    67                        placeholder: 'sorthelper',
    78                        axis: 'y',
    89                        distance: 2,
    9                         update: galleryReorder
     10                        update: galleryHandle,
    1011                } );
    1112        }
    12 
    13         // When an update has occurred, adjust the order for each item
     13       
     14        var galleryHandle = function (e, sort) {
     15                galleryReorder(e, sort);
     16                gallerySortGroups();
     17        }
     18       
     19        // @todo: fix me!
     20        // When an update has occurred, adjust the order for each item..
    1421        var galleryReorder = function(e, sort) {
     22                var o = 0;
    1523                jQuery.each(sort['element'].sortable('toArray'), function(i, id) {
    16                         jQuery('#' + id + ' .menu_order input')[0].value = (1+i);
     24                        if (id)
     25                        {
     26                                o++;
     27                                jQuery('#' + id + ' .menu_order input')[0].value = o;
     28                        }
    1729                });
    1830        }
    19 
     31       
     32        var gallerySortGroups = function () {
     33                var mediaGroups = jQuery(".media-groups").length;
     34                for (g = 0; g < mediaGroups; g++)
     35                {
     36                        jQuery.each(jQuery("#media-group-" + g + " .media-item input.group-value"), function(i, id) {
     37                                jQuery(id)[0].value = g;               
     38                        });
     39                }
     40        }
     41       
    2042        // initialize sortable
    2143        gallerySortableInit();
    2244});
  • wp-content/themes/classic/style.css

     
    320320        text-transform: capitalize;
    321321}
    322322
    323 /* Captions & aligment */
     323/* Gallery & Captions & Aligment */
     324
     325.gallery {
     326        display: block;
     327        clear: left;
     328        overflow: hidden;
     329        margin: auto;
     330}
     331       
     332.gallery-item {
     333        float: left;
     334        margin: 10px 0 0 0;
     335        text-align: center;
     336}
     337       
     338.gallery .gallery-item img, .gallery .gallery-item img.thumbnail {
     339        max-width: 89%;
     340        height: auto;
     341        padding: 1%;
     342        margin: 0
     343        auto;
     344}
     345
     346.gallery div.clear {
     347        width: 0px;
     348        height: 0px;
     349}
     350
     351.col-1 { width: 100%; }
     352.col-2 { width: 50%; }
     353.col-3 { width: 33%; }
     354.col-4 { width: 24.5%; }
     355.col-5 { width: 20%; }
     356.col-6 { width: 16.5%; }
     357.col-7 { width: 14%; }
     358.col-8 { width: 12.4%; }
     359.col-9 { width: 11%; }
     360.col-10 { width: 10%; }
     361.col-11 { width: 9%; }
     362.col-12 { width: 8.33%; }
     363.col-13 { width: 7.6%; }
     364.col-14 { width: 7.1%; }
     365.col-15 { width: 6.66%; }
     366.col-16 { width: 6.25%; }
     367.col-17 { width: 5.83%; }
     368.col-18 { width: 5.55%; }
     369.col-19 { width: 5.25%; }
     370.col-20 { width: 4.95%; }
     371
     372.gallery-caption {
     373        margin-left: 0;
     374}
     375
     376.clear {
     377        clear: both;
     378        height: 0;
     379}
     380
    324381.aligncenter,
    325382div.aligncenter {
    326383        display: block;
     
    360417        padding: 0 4px 5px;
    361418        margin: 0;
    362419}
    363 /* End captions & aligment */
     420/* End Gallery & Captions & Aligment */
  • wp-content/themes/default/style.css

     
    663663        }
    664664/* End Various Tags & Classes*/
    665665
     666/* Gallery & Captions & Aligment */
    666667
     668.gallery {
     669        display: block;
     670        clear: left;
     671        overflow: hidden;
     672        margin: auto;
     673}
     674       
     675.gallery-item {
     676        float: left;
     677        margin: 10px 0 0 0;
     678        text-align: center;
     679}
     680       
     681.gallery .gallery-item img, .gallery .gallery-item img.thumbnail {
     682        max-width: 89%;
     683        height: auto;
     684        padding: 1%;
     685        margin: 0
     686        auto;
     687}
    667688
    668 /* Captions */
     689.gallery div.clear {
     690        width: 0px;
     691        height: 0px;
     692}
     693
     694.col-1 { width: 100%; }
     695.col-2 { width: 50%; }
     696.col-3 { width: 33%; }
     697.col-4 { width: 24.5%; }
     698.col-5 { width: 20%; }
     699.col-6 { width: 16.5%; }
     700.col-7 { width: 14%; }
     701.col-8 { width: 12.4%; }
     702.col-9 { width: 11%; }
     703.col-10 { width: 10%; }
     704.col-11 { width: 9%; }
     705.col-12 { width: 8.33%; }
     706.col-13 { width: 7.6%; }
     707.col-14 { width: 7.1%; }
     708.col-15 { width: 6.66%; }
     709.col-16 { width: 6.25%; }
     710.col-17 { width: 5.83%; }
     711.col-18 { width: 5.55%; }
     712.col-19 { width: 5.25%; }
     713.col-20 { width: 4.95%; }
     714
     715.gallery-caption {
     716        margin-left: 0;
     717}
     718
     719.clear {
     720        clear: both;
     721        height: 0;
     722}
     723
    669724.aligncenter,
    670725div.aligncenter {
    671726        display: block;
     
    673728        margin-right: auto;
    674729}
    675730
     731.alignleft {
     732        float: left;
     733}
     734
     735.alignright {
     736        float: right;
     737}
     738
    676739.wp-caption {
    677740        border: 1px solid #ddd;
    678741        text-align: center;
     
    697760        padding: 0 4px 5px;
    698761        margin: 0;
    699762}
    700 /* End captions */
     763/* End Gallery & Captions & Aligment */
    701764
    702 
    703765/* "Daisy, Daisy, give me your answer do. I'm half crazy all for the love of you.
    704766        It won't be a stylish marriage, I can't afford a carriage.
    705767        But you'll look sweet upon the seat of a bicycle built for two." */
  • wp-includes/js/swfupload/handlers.js

     
    126126        }
    127127
    128128        // Only show Save buttons when there is at least one file.
    129         if ( jQuery('#media-items>*').not('.media-blank').length > 0 )
     129        if ( jQuery('#media-items .media-item').not('.media-no-items').length > 0 )
    130130                jQuery('.savebutton').show();
    131131        else
    132132                jQuery('.savebutton').hide();
    133133
     134        // Only show new Gallery button when there are at least two files.
     135        if ( jQuery('#media-items .media-item').not('.media-no-items').length > 1 )
     136                jQuery('.new-gallery').show();
     137        else
     138                jQuery('.new-gallery').hide();
     139
    134140        // Only show Gallery button when there are at least two files.
    135         if ( jQuery('#media-items>*').length > 1 )
     141        if ( jQuery('#media-items .media-groups').length > 1 )
    136142                jQuery('.insert-gallery').show();
    137143        else
    138144                jQuery('.insert-gallery').hide();
     145               
    139146}
    140147
    141148function uploadSuccess(fileObj, serverData) {
  • wp-includes/media.php

     
    617617                'icontag'    => 'dt',
    618618                'captiontag' => 'dd',
    619619                'columns'    => 3,
     620                'class'          => null,       //      default viewing type
     621                'name'           => null,       //      name of the post
     622                'group'          => null,
    620623                'size'       => 'thumbnail',
    621624        ), $attr));
    622625
    623626        $id = intval($id);
    624         $attachments = get_children( array('post_parent' => $id, 'post_status' => 'inherit', 'post_type' => 'attachment', 'post_mime_type' => 'image', 'order' => $order, 'orderby' => $orderby) );
    625 
     627        $attachments = get_attachments( $post->ID, array('group_number' => $group, 'name' => $name), array('post_status' => 'inherit', 'post_mime_type' => 'image', 'order' => $order, 'orderby' => $orderby) );
     628       
    626629        if ( empty($attachments) )
    627630                return '';
    628631
     
    639642        $columns = intval($columns);
    640643        $itemwidth = $columns > 0 ? floor(100/$columns) : 100;
    641644
    642         $output = apply_filters('gallery_style', "
    643                 <style type='text/css'>
    644                         .gallery {
    645                                 margin: auto;
    646                         }
    647                         .gallery-item {
    648                                 float: left;
    649                                 margin-top: 10px;
    650                                 text-align: center;
    651                                 width: {$itemwidth}%;                   }
    652                         .gallery img {
    653                                 border: 2px solid #cfcfcf;
    654                         }
    655                         .gallery-caption {
    656                                 margin-left: 0;
    657                         }
    658                 </style>
    659                 <!-- see gallery_shortcode() in wp-includes/media.php -->
    660                 <div class='gallery'>");
     645        if ( is_null($group) )
     646                $group_area = 0;
     647        else
     648                $group_area = $group;
     649       
     650        $output = apply_filters('gallery_style', "<div id='gallery-$post->ID-$group_area' class='gallery'>");
    661651
    662652        foreach ( $attachments as $id => $attachment ) {
    663                 $link = wp_get_attachment_link($id, $size, true);
    664                 $output .= "<{$itemtag} class='gallery-item'>";
    665                 $output .= "
    666                         <{$icontag} class='gallery-icon'>
    667                                 $link
    668                         </{$icontag}>";
     653               
     654                if ( !is_null($group) )
     655                        if ($attachment->group_number != $group)
     656                                continue;
     657
     658                $a_img = wp_get_attachment_url($id);
     659                $att_page = get_attachment_link($id);
     660                $img = wp_get_attachment_image_src($id, $size);
     661               
     662                $img = $img[0];
     663                $title = $attachment->post_excerpt;
     664               
     665                if ($title == '')
     666                        $title = $attachment->post_title;
     667               
     668                $output .= "\n<{$itemtag} class='gallery-item col-$columns'>\n";
     669                $output .= "<{$icontag} class='gallery-icon'>\n";
     670               
     671                switch ($class)
     672                {
     673                        case 'lightbox':
     674                                $class_rel = ' class=\"lightbox\" rel=\"lightbox[gallery-$post->ID]\"';
     675                                break;
     676                        case 'shutterset':
     677                                $class_rel = ' class=\"shutterset-gallery-$post->ID\" rel=\"lightbox[gallery-$post->ID]\"';
     678                                break;
     679                        case 'lytebox':
     680                                $class_rel = ' class=\"lytebox\" rel=\"lytebox[gallery-$post->ID]\"';
     681                                break;
     682                        case 'greybox':
     683                                $class_rel = ' class=\"greybox\" rel=\"gb_imageset[gallery-$post->ID]\"';
     684                                break;
     685                        case 'thickbox':
     686                                $class_rel = ' class=\"thickbox\" rel=\"gallery-$post->ID\"';
     687                                break;
     688                        case 'lightview':
     689                                $class_rel = ' class=\"lightview\" rel=\"gallery[gallery-$post->ID]\"';
     690                                break;
     691                        default:
     692                                $class_rel = '';
     693                                break;
     694                }
     695               
     696                if ($a_rel == true)
     697                        $link = $a_img;
     698                elseif ($a_class == true)
     699                        $link = $a_img;
     700                else
     701                        $link = $att_page;
     702               
     703                $output .= "\t<a href=\"$link\" title=\"$title\"$class_rel><img src=\"$img\" alt=\"$title\" /></a>";
     704                $output .= "\n</{$icontag}>";
     705               
    669706                if ( $captiontag && trim($attachment->post_excerpt) ) {
    670                         $output .= "
    671                                 <{$captiontag} class='gallery-caption'>
    672                                 {$attachment->post_excerpt}
    673                                 </{$captiontag}>";
     707                        $output .= "\n<$captiontag class='gallery-caption'>\n\t";
     708                        $output .= $attachment->post_excerpt;
     709                        $output .= "</$captiontag>";
    674710                }
    675                 $output .= "</{$itemtag}>";
    676                 if ( $columns > 0 && ++$i % $columns == 0 )
    677                         $output .= '<br style="clear: both" />';
     711               
     712                $output .= "\n</{$itemtag}>";
     713               
     714                if($columns > 0 && ++$i % $columns == 0)
     715                        $output .= '<div style="clear:both;" class="clear"><!-- --></div>';
    678716        }
    679 
    680         $output .= "
    681                         <br style='clear: both;' />
    682                 </div>\n";
    683 
     717        $output .= "\n</div>\n";
    684718        return $output;
    685719}
    686720
  • wp-includes/post.php

     
    6969}
    7070
    7171/**
     72 * Get the posts attachments data.
     73 *
     74 * @since 2.7.0
     75 *
     76 * @param int $post_id Post ID
     77 */
     78function _get_attachment_data ( $post_id ) {
     79        global $wpdb;
     80
     81        $_attchments = $wpdb->get_row($wpdb->prepare("SELECT * FROM $wpdb->postmeta WHERE post_id = %d AND meta_key = '_wp_post_attachments' LIMIT 1", $post_id));
     82        return unserialize($_attchments->meta_value);
     83}
     84
     85/**
     86 * Get the posts attachments.
     87 *
     88 * @since 2.7.0
     89 *
     90 * @param int $post_id Post ID
     91 * @param mixed $attachment_options Group Options
     92 * @param mixed $args Optional. User defined arguments for replacing the defaults.
     93 */
     94function &get_attachments( $post_id, $attachment_options, $args = '' ) {
     95
     96        extract($attachment_options, EXTR_SKIP);
     97
     98        if (!is_null($name)) {
     99               
     100                if (is_numeric($name))
     101                        $post_id = $name;
     102               
     103                if ($page = get_page_by_title($name))
     104                        $post_id = $page->ID;
     105               
     106                if ($post = get_post_by_title($name))
     107                        $post_id = $post->ID;
     108        }
     109
     110        $attachment = _get_attachment_data ( $post_id );
     111       
     112        if ( !is_array($attachment) )
     113                return;
     114               
     115        foreach ( $attachment as $key => $group ) {
     116               
     117                if (!is_null($group_number))
     118                        if ($key != $group_number) { continue; }
     119               
     120                if ( !is_array($group['items']) )
     121                        break;
     122                       
     123                foreach ( $group['items'] as $item => $attachment_id ) {
     124                        $p = get_post( $attachment_id );        //       might be a better way to do this...
     125                        $p->group_number = $key;
     126                       
     127                        $attach[$attachment_id] = $p;
     128                }
     129        }
     130       
     131        // @todo Orginize the array items based on the settings either default or user ($args)
     132       
     133        return $attach;
     134}
     135
     136/**
     137 * Get the gallery groups names.
     138 *
     139 * @since 2.7.0
     140 *
     141 * @param int $post_id Post ID
     142 */
     143function &get_attachments_groupsname( $post_id ) {
     144
     145        $attachment = _get_attachment_data ( $post_id );
     146       
     147        if ( !is_array($attachment) )
     148                return '';
     149       
     150        foreach ( $attachment as $key => $group ) {
     151                $groups[$key] = $group['name'];
     152        }
     153       
     154        return $groups;
     155}
     156
     157/**
     158 * Get the number of groups attached to this post.
     159 *
     160 * @since 2.7.0
     161 *
     162 * @param int $post_id Post ID
     163 */
     164function get_attachment_groups( $post_id ) {
     165       
     166        return count(_get_attachment_data ( $post_id ));
     167}
     168
     169/**
     170 * Insert a new gallery into the post.
     171 *
     172 * @since 2.7.0
     173 *
     174 * @param int $post_id post data
     175*/
     176function wp_new_gallery ( $post_id ) {
     177
     178        $attachment = _get_attachment_data ( $post_id );
     179       
     180        foreach ( $attachment as $key => $group )
     181                $_group[$key] = array ('name' => $group['name'], 'items' => $group['items']);
     182
     183        $_group[] = array ('name' => null, 'items' => null);
     184       
     185        update_post_meta( $post_id, '_wp_post_attachments', $_group );
     186       
     187}
     188
     189/**
     190 * We are deleting a gallery and moving
     191 *
     192 * @since 2.7.0
     193 *
     194 * @param int $post_id Post ID
     195 * @param int $group_number Group Number
     196*/
     197function wp_delete_gallery ( $post_id, $group_num ) {
     198         
     199        $attachment = _get_attachment_data ( $post_id );
     200       
     201        foreach ( $attachment as $key => $group ) {
     202                if ($key != $group_num) {
     203                        $_group[$key] = array ('name' => $group['name'], 'items' => $group['items']);
     204                        continue;                                               
     205                }       
     206               
     207                if ( !is_array($group['items']) )
     208                        break;
     209               
     210                foreach ( $group['items'] as $item => $attachment_id ) {
     211                        $_attach[] = $attachment_id;   
     212                }
     213        }
     214       
     215        if ( is_array($_group[0]['items']) && is_array($_attach) )  {
     216                $i = array_merge($_group[0]['items'], $_attach);       
     217                $_group[0] = array ('name' => null, 'items' => $i);     
     218        } else {
     219                $_group[0] = array ('name' => null, 'items' => $_group[0]['items']);
     220        }
     221
     222        update_post_meta( $post_id, '_wp_post_attachments', $_group );
     223
     224}
     225
     226/**
     227 * Updating the postmeta data when saving the gallery information.
     228 *
     229 * @since 2.7.0
     230 *
     231 * @param int $attachment_id Attachment ID
     232 * @param int $post_id Post ID
     233 * @param int $group_name Group Name
     234 * @param int $group_number Group Number
     235*/
     236function wp_update_attachment ( $attachment_id, $post_id, $group_name = null, $group_number) {
     237       
     238        $attachment = _get_attachment_data ( $post_id );
     239
     240        //      check to see if this group ($group_number) has a name assignment and is not null
     241        if (( !isset($attachment[$group_number][name]) ) || ( !is_null($attachment[$group_number][name]) ))
     242                if ($group_name != $attachment[$group_number][name])
     243                        _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)
     244       
     245        //      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.
     246        /*
     247         *
     248         * This is where we should be re-orginizing the attachments items
     249         *
     250         */
     251       
     252}
     253
     254/**
     255 * Updateing the group name. (Privte)
     256 *
     257 * @since 2.7.0
     258 *
     259 * @param int $post_id Post ID
     260 * @param int $group_number Group Number
     261 * @param str $group_name Group Name
     262*/
     263function _update_attachment_groupname ( $post_id, $group_number, $group_name ) {
     264               
     265        $_attachment = _get_attachment_data ( $post_id );
     266        $_attachment[$group_number][name] = $group_name;
     267       
     268        update_post_meta( $post_id, '_wp_post_attachments', $_attachment );
     269       
     270}
     271
     272function _update_attachment_groupitem ( $post_id, $group_number, $attachment_id ) {
     273       
     274        $_attachment = _get_attachment_data ( $post_id );
     275
     276        //      update_post_meta( $post_id, '_wp_post_attachments', $_attachment );
     277
     278}
     279
     280/**
    72281 * Retrieve all children of the post parent ID.
    73282 *
    74283 * Normally, without any enhancements, the children would apply to pages. In the
     
    19412150}
    19422151
    19432152/**
     2153 * Retrieve a post given its title.
     2154 *
     2155 * @since 2.7.0
     2156 * @uses $wpdb
     2157 *
     2158 * @param string $page_title Page title
     2159 * @param string $output Optional. Output type. OBJECT, ARRAY_N, or ARRAY_A.
     2160 * @return mixed
     2161 */
     2162function get_post_by_title($page_title, $output = OBJECT) {
     2163        global $wpdb;
     2164        $post = $wpdb->get_var( $wpdb->prepare( "SELECT ID FROM $wpdb->posts WHERE post_title = %s AND post_type='post'", $page_title ));
     2165        if ( $post )
     2166                return get_post($post, $output);
     2167
     2168        return null;
     2169}
     2170
     2171/**
    19442172 * Retrieve child pages from list of pages matching page ID.
    19452173 *
    19462174 * Matches against the pages parameter against the page ID. Also matches all
     
    22302458        // export array as variables
    22312459        extract($object, EXTR_SKIP);
    22322460
     2461        wp_update_attachment($ID, $post_parent, $group_name, $group_number);    // update or insert attachment into postmeta field
     2462       
    22332463        // Make sure we set a valid category
    22342464        if (0 == count($post_category) || !is_array($post_category)) {
    22352465                $post_category = array(get_option('default_category'));