Ticket #7607: 7607.2.diff
File 7607.2.diff, 26.7 KB (added by , 17 years ago) |
---|
-
wp-admin/includes/media.php
16 16 function media_upload_tabs() { 17 17 $_default_tabs = array( 18 18 'type' => __('Choose File'), // handler action suffix => tab text 19 'gallery' => __(' Gallery'),19 'gallery' => __('Attachments'), 20 20 'library' => __('Media Library'), 21 21 ); 22 22 … … 40 40 if ( intval($_REQUEST['post_id']) ) 41 41 $attachments = intval($wpdb->get_var($wpdb->prepare("SELECT count(*) FROM $wpdb->posts WHERE post_type = 'attachment' AND post_parent = %d", $_REQUEST['post_id']))); 42 42 43 $tabs['gallery'] = sprintf(__(' Gallery(%s)'), "<span id='attachments-count'>$attachments</span>");43 $tabs['gallery'] = sprintf(__('Attachments (%s)'), "<span id='attachments-count'>$attachments</span>"); 44 44 45 45 return $tabs; 46 46 } … … 98 98 $rel = $rel ? ' rel="attachment wp-att-'.attribute_escape($id).'"' : ''; 99 99 100 100 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>"; 102 102 103 103 $html = apply_filters( 'image_send_to_editor', $html, $id, $alt, $title, $align, $url, $size ); 104 104 … … 358 358 $post['post_title'] = $attachment['post_title']; 359 359 if ( isset($attachment['post_excerpt']) ) 360 360 $post['post_excerpt'] = $attachment['post_excerpt']; 361 if ( isset($attachment['group_number']) ) 362 $post['group_number'] = $attachment['group_number']; 361 363 if ( isset($attachment['menu_order']) ) 362 364 $post['menu_order'] = $attachment['menu_order']; 363 365 … … 376 378 wp_set_object_terms($attachment_id, array_map('trim', preg_split('/,+/', $attachment[$t])), $t, false); 377 379 } 378 380 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']); 381 394 382 395 if ( isset($_POST['send']) ) { 383 396 $keys = array_keys($_POST['send']); … … 426 439 $align = attribute_escape($_POST['insertonly']['align']); 427 440 $class = " class='align$align'"; 428 441 } 442 if ( isset($_POST['insertonly']['title']) ) { 443 $title = " title='".attribute_escape($_POST['insertonly']['title'])."'"; 444 } 429 445 if ( !empty($src) ) 430 $html = "<img src='$src' alt='$alt'$ class />";446 $html = "<img src='$src' alt='$alt'$title$class />"; 431 447 return media_send_to_editor($html); 432 448 } 433 449 … … 844 860 $post['errors']['post_title']['errors'][] = __('Empty Title filled from filename.'); 845 861 } 846 862 } 863 864 $post['group_name'] = $_POST['attachments']['group_name'][$attachment['group_number']]; 847 865 848 866 return $post; 849 867 } … … 968 986 * @param unknown_type $errors 969 987 * @return unknown 970 988 */ 971 function get_media_items( $post_id, $ errors ) {989 function get_media_items( $post_id, $group_num = null, $errors ) { 972 990 if ( $post_id ) { 973 991 $post = get_post($post_id); 974 if ( $post && $post->post_type == 'attachment' ) 992 if ( $post && $post->post_type == 'attachment' ) { 975 993 $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 } 978 1000 } else { 979 1001 if ( is_array($GLOBALS['wp_the_query']->posts) ) 980 1002 foreach ( $GLOBALS['wp_the_query']->posts as $attachment ) … … 984 1006 if ( empty($attachments) ) 985 1007 return ''; 986 1008 987 foreach ( $attachments as $id => $attachment ) 1009 foreach ( $attachments as $id => $attachment ) { 988 1010 if ( $item = get_media_item( $id, array( 'errors' => isset($errors[$id]) ? $errors[$id] : null) ) ) 989 1011 $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 991 1014 return $output; 992 1015 } 993 1016 … … 1025 1048 $filename = basename($post->guid); 1026 1049 $title = attribute_escape($post->post_title); 1027 1050 $description = attribute_escape($post->post_content); 1051 $group_number = attribute_escape($post->group_number); 1028 1052 if ( $_tags = get_the_tags($attachment_id) ) { 1029 1053 foreach ( $_tags as $tag ) 1030 1054 $tags[] = $tag->name; … … 1055 1079 $gallery = ( (isset($_REQUEST['tab']) && 'gallery' == $_REQUEST['tab']) || (isset($redir_tab) && 'gallery' == $redir_tab) ) ? true : false; 1056 1080 $order = ''; 1057 1081 1082 $groupnum = '<input type="hidden" class="group-value" name="attachments['.$attachment_id.'][group_number]" value="'.$group_number.'" />'; 1083 1058 1084 foreach ( $form_fields as $key => $val ) { 1059 1085 if ( 'menu_order' == $key ) { 1060 1086 if ( $gallery ) … … 1071 1097 $type 1072 1098 $toggle_links 1073 1099 $order 1100 $groupnum 1074 1101 $display_title 1075 1102 <table class='slidetoggle describe $class'> 1076 1103 <thead class='media-item-info'> … … 1354 1381 html = '<img alt="'+alt+'" src="'+f.src.value+'"'+title+cls+' width="'+t.width+'" height="'+t.height+'" />'; 1355 1382 1356 1383 if ( f.url.value ) 1357 html = '<a href="'+f.url.value+'" >'+html+'</a>';1384 html = '<a href="'+f.url.value+'"'+title+'>'+html+'</a>'; 1358 1385 1359 1386 if ( caption ) 1360 1387 html = '[caption id="" align="'+t.align+'" width="'+t.width+'" caption="'+caption+'"]'+html+'[/caption]'; … … 1424 1451 media_upload_header(); 1425 1452 1426 1453 $post_id = intval($_REQUEST['post_id']); 1454 $group_num = intval(get_attachment_groups( $post_id )); 1455 $_group_name = get_attachments_groupsname( $post_id ); 1456 1427 1457 $form_action_url = admin_url("media-upload.php?type={$GLOBALS['type']}&tab=gallery&post_id=$post_id"); 1428 1458 ?> 1429 1459 … … 1433 1463 var preloaded = $(".media-item.preloaded"); 1434 1464 if ( preloaded.length > 0 ) { 1435 1465 preloaded.each(function(){prepareMediaItem({id:this.id.replace(/[^0-9]/g, '')},'');}); 1436 updateMediaForm();1437 1466 } 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 }); 1438 1486 }); 1439 1487 --> 1440 1488 </script> … … 1442 1490 <form enctype="multipart/form-data" method="post" action="<?php echo attribute_escape($form_action_url); ?>" class="media-upload-form validate" id="gallery-form"> 1443 1491 <?php wp_nonce_field('media-form'); ?> 1444 1492 <?php //media_upload_form( $errors ); ?> 1493 <div id="media-items"> 1494 <?php 1495 for ( $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; ?>" /> 1445 1500 <table class="widefat"> 1446 1501 <thead><tr> 1447 <th><?php _e('Media'); ?></th> 1502 <th> 1503 <?php 1504 if ($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> 1448 1521 <th class="order-head"><?php _e('Order'); ?></th> 1449 1522 </tr></thead> 1450 1523 </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); ?> 1453 1525 </div> 1526 <?php 1527 } 1528 ?> 1529 </div> 1454 1530 <p class="ml-submit"> 1455 1531 <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="" /> 1457 1536 <input type="hidden" name="post_id" id="post_id" value="<?php echo (int) $post_id; ?>" /> 1458 1537 <input type="hidden" name="type" value="<?php echo attribute_escape( $GLOBALS['type'] ); ?>" /> 1459 1538 <input type="hidden" name="tab" value="<?php echo attribute_escape( $GLOBALS['tab'] ); ?>" /> 1460 1539 </p> 1461 1540 </form> 1541 <script type="text/javascript"> 1542 <!-- 1543 updateMediaForm(); 1544 --> 1545 </script> 1462 1546 <?php 1463 1547 } 1464 1548 … … 1605 1689 </script> 1606 1690 1607 1691 <div id="media-items"> 1608 <?php echo get_media_items(null, $errors); ?>1692 <?php echo get_media_items(null, null, $errors); ?> 1609 1693 </div> 1610 1694 <p class="ml-submit"> 1611 1695 <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-content/themes/classic/style.css
320 320 text-transform: capitalize; 321 321 } 322 322 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 324 381 .aligncenter, 325 382 div.aligncenter { 326 383 display: block; … … 360 417 padding: 0 4px 5px; 361 418 margin: 0; 362 419 } 363 /* End captions & aligment */420 /* End Gallery & Captions & Aligment */ -
wp-content/themes/default/style.css
663 663 } 664 664 /* End Various Tags & Classes*/ 665 665 666 /* Gallery & Captions & Aligment */ 666 667 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 } 667 688 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 669 724 .aligncenter, 670 725 div.aligncenter { 671 726 display: block; … … 673 728 margin-right: auto; 674 729 } 675 730 731 .alignleft { 732 float: left; 733 } 734 735 .alignright { 736 float: right; 737 } 738 676 739 .wp-caption { 677 740 border: 1px solid #ddd; 678 741 text-align: center; … … 697 760 padding: 0 4px 5px; 698 761 margin: 0; 699 762 } 700 /* End captions*/763 /* End Gallery & Captions & Aligment */ 701 764 702 703 765 /* "Daisy, Daisy, give me your answer do. I'm half crazy all for the love of you. 704 766 It won't be a stylish marriage, I can't afford a carriage. 705 767 But you'll look sweet upon the seat of a bicycle built for two." */ -
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 'class' => null, // default viewing type 621 'name' => null, // name of the post 622 'group' => null, 620 623 'size' => 'thumbnail', 621 624 ), $attr)); 622 625 623 626 $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 626 629 if ( empty($attachments) ) 627 630 return ''; 628 631 … … 639 642 $columns = intval($columns); 640 643 $itemwidth = $columns > 0 ? floor(100/$columns) : 100; 641 644 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'>"); 661 651 662 652 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 669 706 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>"; 674 710 } 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>'; 678 716 } 679 680 $output .= " 681 <br style='clear: both;' /> 682 </div>\n"; 683 717 $output .= "\n</div>\n"; 684 718 return $output; 685 719 } 686 720 -
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 /** 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 */ 94 function &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 */ 143 function &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 */ 164 function 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 */ 176 function 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 */ 197 function 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 */ 236 function 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 */ 263 function _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 272 function _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 /** 72 281 * Retrieve all children of the post parent ID. 73 282 * 74 283 * Normally, without any enhancements, the children would apply to pages. In the … … 1941 2150 } 1942 2151 1943 2152 /** 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 */ 2162 function 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 /** 1944 2172 * Retrieve child pages from list of pages matching page ID. 1945 2173 * 1946 2174 * Matches against the pages parameter against the page ID. Also matches all … … 2230 2458 // export array as variables 2231 2459 extract($object, EXTR_SKIP); 2232 2460 2461 wp_update_attachment($ID, $post_parent, $group_name, $group_number); // update or insert attachment into postmeta field 2462 2233 2463 // Make sure we set a valid category 2234 2464 if (0 == count($post_category) || !is_array($post_category)) { 2235 2465 $post_category = array(get_option('default_category'));