Ticket #7607: 7607.1.diff
File 7607.1.diff, 15.7 KB (added by , 16 years ago) |
---|
-
wp-admin/includes/media.php
58 58 $rel = $rel ? ' rel="attachment wp-att-'.attribute_escape($id).'"' : ''; 59 59 60 60 if ( $url ) 61 $html = '<a href="' . clean_url($url) . "\" $rel>$html</a>";61 $html = '<a href="' . clean_url($url) . "\" title=\"". attribute_escape($title) ."\"$rel>$html</a>"; 62 62 63 63 $html = apply_filters( 'image_send_to_editor', $html, $id, $alt, $title, $align, $url, $size ); 64 64 … … 274 274 wp_set_object_terms($attachment_id, array_map('trim', preg_split('/,+/', $attachment[$t])), $t, false); 275 275 } 276 276 277 if ( isset($_POST['insert-gallery']) ) 278 return media_send_to_editor('[gallery]'); 277 if ( isset($_POST['insert-gallery']) ) { 278 if ( ( isset($_POST['gallery_insert']) ) && ( $_POST['gallery_insert'] > 0 ) ) { 279 return media_send_to_editor('[gallery group="'.$_POST['gallery_insert'].'"]'); 280 } else { 281 return media_send_to_editor('[gallery]'); 282 } 283 } 284 285 if ( isset($_POST['new-gallery']) ) 286 wp_new_gallery($post['post_parent']); 287 288 if ( isset($_POST['gallery_delete']) && !is_null($_POST['gallery_delete']) && ($_POST['gallery_delete'] > 0) ) 289 wp_delete_gallery($post['post_parent'], $_POST['gallery_delete']); 279 290 280 291 if ( isset($_POST['send']) ) { 281 292 $keys = array_keys($_POST['send']); … … 317 328 $align = attribute_escape($_POST['insertonly']['align']); 318 329 $class = " class='align$align'"; 319 330 } 331 if ( isset($_POST['insertonly']['title']) ) { 332 $title = " title='".attribute_escape($_POST['insertonly']['title'])."'"; 333 } 320 334 if ( !empty($src) ) 321 $html = "<img src='$src' alt='$alt'$ class />";335 $html = "<img src='$src' alt='$alt'$title$class />"; 322 336 return media_send_to_editor($html); 323 337 } 324 338 … … 732 746 return $form_fields; 733 747 } 734 748 735 function get_media_items( $post_id, $ errors ) {749 function get_media_items( $post_id, $group_num = null, $errors ) { 736 750 if ( $post_id ) { 737 751 $post = get_post($post_id); 738 if ( $post && $post->post_type == 'attachment' ) 752 if ( $post && $post->post_type == 'attachment' ) { 753 // @todo This section has not been tested to see if it's working at all. 739 754 $attachments = array($post->ID => $post); 740 else 741 $attachments = get_children( array( 'post_parent' => $post_id, 'post_type' => 'attachment', 'orderby' => 'menu_order ASC, ID', 'order' => 'DESC') ); 755 } else { 756 $attachments = get_attachments( $post_id, $group_num ); 757 758 if ( ! count($attachments) ) 759 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>"; 760 } 742 761 } else { 743 762 if ( is_array($GLOBALS['wp_the_query']->posts) ) 744 763 foreach ( $GLOBALS['wp_the_query']->posts as $attachment ) … … 748 767 if ( empty($attachments) ) 749 768 return ''; 750 769 751 foreach ( $attachments as $id => $attachment ) 770 foreach ( $attachments as $id => $attachment ) { 752 771 if ( $item = get_media_item( $id, array( 'errors' => isset($errors[$id]) ? $errors[$id] : null) ) ) 753 772 $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>"; 754 773 } 774 755 775 return $output; 756 776 } 757 777 … … 780 800 $filename = basename($post->guid); 781 801 $title = attribute_escape($post->post_title); 782 802 $description = attribute_escape($post->post_content); 803 $group_number = attribute_escape($post->group_number); 783 804 if ( $_tags = get_the_tags($attachment_id) ) { 784 805 foreach ( $_tags as $tag ) 785 806 $tags[] = $tag->name; … … 810 831 $gallery = ( (isset($_REQUEST['tab']) && 'gallery' == $_REQUEST['tab']) || (isset($redir_tab) && 'gallery' == $redir_tab) ) ? true : false; 811 832 $order = ''; 812 833 834 $groupnum = '<input type="hidden" class="group-value" name="attachments['.$attachment_id.'][group_number]" value="'.$group_number.'" />'; 835 813 836 foreach ( $form_fields as $key => $val ) { 814 837 if ( 'menu_order' == $key ) { 815 838 if ( $gallery ) … … 826 849 $type 827 850 $toggle_links 828 851 $order 852 $groupnum 829 853 $display_title 830 854 <table class='slidetoggle describe $class'> 831 855 <thead class='media-item-info'> … … 1088 1112 html = '<img alt="'+alt+'" src="'+f.src.value+'"'+title+cls+' width="'+t.width+'" height="'+t.height+'" />'; 1089 1113 1090 1114 if ( f.url.value ) 1091 html = '<a href="'+f.url.value+'" >'+html+'</a>';1115 html = '<a href="'+f.url.value+'"'+title+'>'+html+'</a>'; 1092 1116 1093 1117 if ( caption ) 1094 1118 html = '[caption id="" align="'+t.align+'" width="'+t.width+'" caption="'+caption+'"]'+html+'[/caption]'; … … 1151 1175 media_upload_header(); 1152 1176 1153 1177 $post_id = intval($_REQUEST['post_id']); 1178 $group_num = intval(get_attachment_groups( $post_id )); 1179 $_group_name = get_attachments_groupsname( $post_id ); 1180 1154 1181 $form_action_url = admin_url("media-upload.php?type={$GLOBALS['type']}&tab=gallery&post_id=$post_id"); 1155 1182 ?> 1156 1183 … … 1160 1187 var preloaded = $(".media-item.preloaded"); 1161 1188 if ( preloaded.length > 0 ) { 1162 1189 preloaded.each(function(){prepareMediaItem({id:this.id.replace(/[^0-9]/g, '')},'');}); 1163 updateMediaForm();1164 1190 } 1191 jQuery("a.del-group").click(function () { 1192 var deleteConfirmation = confirm('<?php _e("Are you sure you want to delete this gallery group?"); ?>'); 1193 1194 if (!deleteConfirmation) { return; } 1195 1196 if (jQuery("#media-group-" + jQuery(this).attr('value') + " .media-item input.group-value").length) 1197 { 1198 jQuery.each(jQuery("#media-group-delete-" + jQuery(this).attr('value') + " .media-item input.group-value"), function(i, id) { 1199 jQuery(id)[0].value = 0; // we are going to set all the items to group 0 1200 }); 1201 } 1202 jQuery("#gallery-delete").val( jQuery(this).attr('value') ); // set the gallery we are deleting 1203 jQuery("#media-group-" + jQuery(this).attr('value')).hide(); // hide the gallery and then... 1204 jQuery(".savebutton").click(); 1205 }); 1206 jQuery("a.insert-group").click(function () { 1207 jQuery("#gallery-insert").val( jQuery(this).attr('value') ); // set the gallery we are inserting 1208 jQuery(".insert-gallery").click(); 1209 }); 1165 1210 }); 1166 1211 --> 1167 1212 </script> … … 1169 1214 <form enctype="multipart/form-data" method="post" action="<?php echo attribute_escape($form_action_url); ?>" class="media-upload-form validate" id="gallery-form"> 1170 1215 <?php wp_nonce_field('media-form'); ?> 1171 1216 <?php //media_upload_form( $errors ); ?> 1217 <div id="media-items"> 1218 <?php 1219 for ( $i = 0; $i < $group_num; $i++ ) 1220 { 1221 ?> 1222 <div id="media-group-<?php echo $i; ?>" class="media-groups"> 1223 <input type="hidden" id="media-group-value-<?php echo $i; ?>" value="<?php echo $i; ?>" /> 1172 1224 <table class="widefat"> 1173 1225 <thead><tr> 1174 <th><?php _e('Media'); ?></th> 1226 <th> 1227 <?php 1228 if ($i > 0) { 1229 1230 $delete = "<a href=\"#media-group-delete-value-".$i."\" value=\"".$i."\" class=\"del-group\">" . __('Delete') . "</a>"; 1231 $insert = "<a href=\"#media-group-insert-value-".$i."\" value=\"".$i."\" class=\"insert-group\">" . __('Insert') . "</a>"; 1232 $group_link = "<small>[".$delete." | " .$insert."]</small>"; 1233 $group_name = "<input type=\"text\" name=\"\" value=\"" . $_group_name[$i] . "\" size=\"20\" />"; 1234 1235 _e('Group (' . $i . ') ' . $group_name . ' ' . $group_link); 1236 1237 } else { 1238 1239 _e('Media: Non-grouped items.'); 1240 1241 } 1242 ?> 1243 </th> 1175 1244 <th class="order-head"><?php _e('Order'); ?></th> 1176 1245 </tr></thead> 1177 1246 </table> 1178 <div id="media-items"> 1179 <?php echo get_media_items($post_id, $errors); ?> 1247 <?php echo get_media_items($post_id, $i, $errors); ?> 1180 1248 </div> 1249 <?php 1250 } 1251 ?> 1252 </div> 1181 1253 <p class="ml-submit"> 1182 1254 <input type="submit" class="button savebutton" name="save" value="<?php echo attribute_escape( __( 'Save all changes' ) ); ?>" /> 1183 <input type="submit" class="button insert-gallery" name="insert-gallery" value="<?php echo attribute_escape( __( 'Insert gallery into post' ) ); ?>" /> 1255 <input type="submit" class="button new-gallery" name="new-gallery" value="<?php echo attribute_escape( __( 'Create new gallery' ) ); ?>" /> 1256 <input type="submit" class="button insert-gallery" name="insert-gallery" value="<?php echo attribute_escape( __( 'Insert full gallery into post' ) ); ?>" /> 1257 <input type="hidden" name="gallery_delete" id="gallery-delete" value="" /> 1258 <input type="hidden" name="gallery_insert" id="gallery-insert" value="" /> 1184 1259 <input type="hidden" name="post_id" id="post_id" value="<?php echo (int) $post_id; ?>" /> 1185 1260 <input type="hidden" name="type" value="<?php echo attribute_escape( $GLOBALS['type'] ); ?>" /> 1186 1261 <input type="hidden" name="tab" value="<?php echo attribute_escape( $GLOBALS['tab'] ); ?>" /> 1187 1262 </p> 1188 1263 </form> 1264 <script type="text/javascript"> 1265 <!-- 1266 updateMediaForm(); 1267 --> 1268 </script> 1189 1269 <?php 1190 1270 } 1191 1271 … … 1325 1405 </script> 1326 1406 1327 1407 <div id="media-items"> 1328 <?php echo get_media_items(null, $errors); ?>1408 <?php echo get_media_items(null, null, $errors); ?> 1329 1409 </div> 1330 1410 <p class="ml-submit"> 1331 1411 <input type="submit" class="button savebutton" name="save" value="<?php echo attribute_escape( __( 'Save all changes' ) ); ?>" /> -
wp-admin/js/gallery.js
1 1 jQuery(function($) { 2 2 var gallerySortable; 3 3 4 var gallerySortableInit = function() { 4 5 gallerySortable = $('#media-items').sortable( { 5 6 items: '.media-item', 6 7 placeholder: 'sorthelper', 7 8 axis: 'y', 8 9 distance: 2, 9 update: gallery Reorder10 update: galleryHandle, 10 11 } ); 11 12 } 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.. 14 21 var galleryReorder = function(e, sort) { 22 var o = 0; 15 23 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 } 17 29 }); 18 30 } 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 20 42 // initialize sortable 21 43 gallerySortableInit(); 22 44 }); -
wp-includes/js/swfupload/handlers.js
126 126 } 127 127 128 128 // 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 ) 130 130 jQuery('.savebutton').show(); 131 131 else 132 132 jQuery('.savebutton').hide(); 133 133 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 134 140 // 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 ) 136 142 jQuery('.insert-gallery').show(); 137 143 else 138 144 jQuery('.insert-gallery').hide(); 145 139 146 } 140 147 141 148 function uploadSuccess(fileObj, serverData) { -
wp-includes/media.php
617 617 'icontag' => 'dt', 618 618 'captiontag' => 'dd', 619 619 'columns' => 3, 620 'group' => null, 620 621 'size' => 'thumbnail', 621 622 ), $attr)); 622 623 623 624 $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 625 $attachments = get_attachments( $post->ID, $group, array('post_status' => 'inherit', 'post_mime_type' => 'image', 'order' => $order, 'orderby' => $orderby) ); 626 626 627 if ( empty($attachments) ) 627 628 return ''; 628 629 -
wp-includes/post.php
69 69 } 70 70 71 71 /** 72 * Get the posts attachments data. 73 * 74 * @since 2.7.0 75 * 76 * @param int $post_id Post ID 77 */ 78 function _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 * Get the posts attachments. 86 * 87 * @since 2.7.0 88 * 89 * @param int $post_id Post ID 90 * @param int $group_num Group Number 91 * @param mixed $args Optional. User defined arguments for replacing the defaults. 92 */ 93 function &get_attachments( $post_id, $group_num = null, $args = '' ) { 94 95 $attachment = _get_attachment_data ( $post_id ); 96 97 foreach ( $attachment as $key => $group ) { 98 99 if (!is_null($group_num)) 100 if ($key != $group_num) { continue; } 101 102 if ( !is_array($group['items']) ) 103 break; 104 105 foreach ( $group['items'] as $item => $attachment_id ) { 106 $p = get_post( $attachment_id ); 107 $p->group_number = $key; 108 109 $attach[$attachment_id] = $p; 110 } 111 } 112 113 // @todo Orginize items based on the settings either default or user 114 115 return $attach; 116 } 117 118 /** 119 * Get the gallery groups names. 120 * 121 * @since 2.7.0 122 * 123 * @param int $post_id Post ID 124 */ 125 function &get_attachments_groupsname( $post_id ) { 126 127 $attachment = _get_attachment_data ( $post_id ); 128 129 if ( !is_array($attachment) ) 130 return ''; 131 132 foreach ( $attachment as $key => $group ) { 133 $groups[$key] = $group['name']; 134 } 135 136 return $groups; 137 } 138 139 /** 140 * Get the number of groups attached to this post. 141 * 142 * @since 2.7.0 143 * 144 * @param int $post_id Post ID 145 */ 146 function get_attachment_groups( $post_id ) { 147 148 return count(_get_attachment_data ( $post_id )); 149 } 150 151 /** 152 * Insert a new gallery into the post. 153 * 154 * @since 2.7.0 155 * 156 * @param int $post_id post data 157 */ 158 function wp_new_gallery ( $post_id ) { 159 160 $attachment = _get_attachment_data ( $post_id ); 161 162 foreach ( $attachment as $key => $group ) 163 $_group[$key] = array ('name' => $group['name'], 'items' => $group['items']); 164 165 $_group[] = array ('name' => null, 'items' => null); 166 167 update_post_meta( $post_id, '_wp_post_attachments', $_group ); 168 169 } 170 171 /** 172 * We are deleting a gallery and moving 173 * 174 * @since 2.7.0 175 * 176 * @param int $post_id Post ID 177 * @param int $group_number Group Number 178 */ 179 function wp_delete_gallery ( $post_id, $group_num ) { 180 181 $attachment = _get_attachment_data ( $post_id ); 182 183 foreach ( $attachment as $key => $group ) { 184 if ($key != $group_num) { 185 $_group[$key] = array ('name' => $group['name'], 'items' => $group['items']); 186 continue; 187 } 188 189 if ( !is_array($group['items']) ) 190 break; 191 192 foreach ( $group['items'] as $item => $attachment_id ) { 193 $_attach[] = $attachment_id; 194 } 195 } 196 197 if ( is_array($_group[0]['items']) && is_array($_attach) ) { 198 $i = array_merge($_group[0]['items'], $_attach); 199 $_group[0] = array ('name' => null, 'items' => $i); 200 } else { 201 $_group[0] = array ('name' => null, 'items' => $_group[0]['items']); 202 } 203 204 update_post_meta( $post_id, '_wp_post_attachments', $_group ); 205 206 } 207 208 /** 72 209 * Retrieve all children of the post parent ID. 73 210 * 74 211 * Normally, without any enhancements, the children would apply to pages. In the