Ticket #7607: 7607.3.diff
File 7607.3.diff, 32.9 KB (added by , 16 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_number = 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, array('group_number' => $group_number), get_children( array( 'post_parent' => $post_id, 'post_type' => 'attachment', 'orderby' => 'menu_order ASC, ID', 'order' => 'DESC') ) ); 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 $groups = 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 < $groups; $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/includes/upgrade.php
906 906 // Update post_date for unpublished posts with empty timestamp 907 907 if ( $wp_current_db_version < 8921 ) 908 908 $wpdb->query( "UPDATE $wpdb->posts SET post_date = post_modified WHERE post_date = '0000-00-00 00:00:00'" ); 909 910 // Create gallery index of all current posts 911 if ( $wp_current_db_version < 9094 ) { 912 update_option('image_display_type', 'none'); // default display option 913 914 $posts = $wpdb->get_results("SELECT ID FROM $wpdb->posts WHERE (post_type = 'post' || post_type = 'page')"); 915 foreach ( (array) $posts as $post ) { 916 $attachments = $wpdb->get_results("SELECT ID FROM $wpdb->posts WHERE post_type = 'attachment' AND post_parent = $post->ID"); 917 918 foreach ( (array) $attachments as $attachment ) 919 $attach[] = $attachment->ID; 920 921 $_new_group = array(0 => array ('name' => null, 'items' => $attach)); 922 update_post_meta( $post->ID, '_wp_post_attachments', $_new_group ); 923 unset($attach); 924 } 925 } 926 unset($posts, $attachments); 927 909 928 } 910 929 911 930 -
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-admin/options-media.php
39 39 } 40 40 ?> 41 41 </fieldset></td> 42 </tr> 43 <tr valign="top"> 44 <th scope="row"><?php _e('Image display') ?></th> 45 <td><fieldset><legend class="hidden"><?php _e('Image display') ?></legend> 46 <?php 47 $display_types = array('none' => 'Default', 'lightbox' => 'Lightbox', 'shutterset' => 'Shutter Set', 48 'lytebox' => 'Lyte Box', 'greybox' => 'Grey Box', 'thickbox' => 'Thick Box', 'lightview' => 'Light View' 49 ); 50 51 $default_image_display_type = get_option('image_display_type'); 52 if ( empty($default_image_display_type) ) 53 $default_image_display_type = 'none'; 54 55 foreach ($display_types as $type => $name) { ?> 56 <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"' : ''); ?> /> 57 <label for="image_display_type_<?php echo $type; ?>"><?php _e($name); ?></label> 58 <?php 59 } 60 ?> 61 </fieldset></td> 42 62 </tr> 43 63 </table> 44 64 -
wp-admin/options.php
25 25 'general' => array('blogname', 'blogdescription', 'admin_email', 'users_can_register', 'gmt_offset', 'date_format', 'time_format', 'start_of_week', 'comment_registration', 'default_role' ), 26 26 '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' ), 27 27 'misc' => array( 'hack_file', 'use_linksupdate', 'uploads_use_yearmonth_folders', 'upload_path' ), 28 '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' ),28 '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' ), 29 29 'privacy' => array( 'blog_public' ), 30 30 'reading' => array( 'posts_per_page', 'posts_per_rss', 'rss_use_excerpt', 'blog_charset', 'gzipcompression', 'show_on_front', 'page_on_front', 'page_for_posts' ), 31 31 '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' ), -
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 .gallery-space { 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 .gallery-space { 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' => get_option('image_display_type'), 621 'name' => null, 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( $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) ) ); 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 $group_gallery = "-" . $group_area; 648 } else { 649 $group_area = $group; 650 $group_gallery = "-" . $group; 651 } 652 653 $output = apply_filters('gallery_style', "<div id='gallery-$post->ID-$group_area' class='gallery'>"); 661 654 662 655 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}>"; 656 657 if ( !is_null($attachment->group_name) ) 658 $group_name = $attachment->group_name; 659 660 if ( !is_null($group) ) 661 if ($attachment->group_number != $group) 662 continue; 663 664 $a_img = wp_get_attachment_url($id); 665 $att_page = get_attachment_link($id); 666 $img = wp_get_attachment_image_src($id, $size); 667 668 $img = $img[0]; 669 $title = $attachment->post_excerpt; 670 671 if ($title == '') 672 $title = $attachment->post_title; 673 674 $output .= "\n<{$itemtag} class='gallery-item col-$columns'>\n"; 675 $output .= "<{$icontag} class='gallery-icon'>\n"; 676 677 switch ($class) 678 { 679 case 'lightbox': 680 $class_rel = ' class="lightbox" rel="lightbox[gallery-'.$post->ID.$group_gallery.']"'; 681 break; 682 case 'shutterset': 683 $class_rel = ' class="shutterset-gallery-'.$post->ID.$group_gallery.'" rel="lightbox[gallery-'.$post->ID.$group_gallery.']"'; 684 break; 685 case 'lytebox': 686 $class_rel = ' class="lytebox" rel="lytebox[gallery-'.$post->ID.$group_gallery.']"'; 687 break; 688 case 'greybox': 689 $class_rel = ' class="greybox" rel="gb_imageset[gallery-'.$post->ID.$group_gallery.']"'; 690 break; 691 case 'thickbox': 692 $class_rel = ' class="thickbox" rel="gallery-'.$post->ID.$group_gallery.'"'; 693 break; 694 case 'lightview': 695 $class_rel = ' class="lightview" rel="gallery[gallery-'.$post->ID.$group_gallery.']"'; 696 break; 697 default: 698 $class_rel = null; 699 break; 700 } 701 702 if (!is_null($class_rel)) 703 $link = $a_img; 704 else 705 $link = $att_page; 706 707 $output .= "\t<a href=\"$link\" title=\"$title\"$class_rel><img src=\"$img\" alt=\"$title\" /></a>"; 708 $output .= "\n</{$icontag}>"; 709 669 710 if ( $captiontag && trim($attachment->post_excerpt) ) { 670 $output .= " 671 <{$captiontag} class='gallery-caption'> 672 {$attachment->post_excerpt} 673 </{$captiontag}>"; 711 $output .= "\n<$captiontag class='gallery-caption'>\n\t"; 712 $output .= $attachment->post_excerpt; 713 $output .= "</$captiontag>"; 674 714 } 675 $output .= "</{$itemtag}>"; 676 if ( $columns > 0 && ++$i % $columns == 0 ) 677 $output .= '<br style="clear: both" />'; 715 716 $output .= "\n</{$itemtag}>"; 717 718 if($columns > 0 && ++$i % $columns == 0) 719 $output .= '<div style="clear:both;" class="gallery-space"><!-- --></div>'; 678 720 } 721 $output .= "\n</div>\n"; 679 722 680 $output .= " 681 <br style='clear: both;' /> 682 </div>\n"; 723 if ((isset($group_name)) && (!is_null($group))) 724 $output .= "<p style=\"text-align: center;\"><strong>".$group_name."</strong></p>\n"; 683 725 684 726 return $output; 685 727 } -
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 $attachment_childern All the childern's of the current post in an array. 93 */ 94 function &get_attachments( $post_id, $attachment_options = '', $attachment_childern ) { 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 $attachment_childern = get_children( array('post_parent' => $post_id, 'post_status' => 'inherit', 'post_type' => 'attachment', 'post_mime_type' => 'image', 'order' => $order, 'orderby' => $orderby) ); 110 } 111 112 $attachment = _get_attachment_data ( $post_id ); 113 114 if ( !is_array($attachment) ) 115 return; 116 117 foreach ( $attachment_childern as $id => $image ) { 118 119 foreach ( $attachment as $key => $group ) { 120 121 if ( !is_array($group['items']) ) 122 continue; 123 124 if (is_null($group_number)) { 125 if ($key == 0) { continue; } 126 } else { 127 if ($key != $group_number) { continue; } 128 } 129 130 if (in_array($id, $group['items'])) { 131 132 $image = $attachment_childern[$id]; 133 $image->group_number = $key; 134 $image->group_name = $group['name']; 135 136 $attach[$id] = $image; 137 138 } 139 140 } 141 142 } 143 144 return $attach; 145 } 146 147 /** 148 * Get the gallery groups names. 149 * 150 * @since 2.7.0 151 * 152 * @param int $post_id Post ID 153 */ 154 function &get_attachments_groupsname( $post_id ) { 155 156 $attachment = _get_attachment_data ( $post_id ); 157 158 if ( !is_array($attachment) ) 159 return ''; 160 161 foreach ( $attachment as $key => $group ) { 162 $groups[$key] = $group['name']; 163 } 164 165 return $groups; 166 } 167 168 /** 169 * Get the number of groups attached to this post. 170 * 171 * @since 2.7.0 172 * 173 * @param int $post_id Post ID 174 */ 175 function get_attachment_groups( $post_id ) { 176 177 return count(_get_attachment_data ( $post_id )); 178 } 179 180 /** 181 * Insert a new gallery into the post. 182 * 183 * @since 2.7.0 184 * 185 * @param int $post_id post data 186 */ 187 function wp_new_gallery ( $post_id ) { 188 189 $attachment = _get_attachment_data ( $post_id ); 190 191 foreach ( $attachment as $key => $group ) 192 $_group[$key] = array ('name' => $group['name'], 'items' => $group['items']); 193 194 $_group[] = array ('name' => null, 'items' => null); 195 196 update_post_meta( $post_id, '_wp_post_attachments', $_group ); 197 198 } 199 200 /** 201 * We are deleting a gallery and moving 202 * 203 * @since 2.7.0 204 * 205 * @param int $post_id Post ID 206 * @param int $group_number Group Number 207 */ 208 function wp_delete_gallery ( $post_id, $group_num ) { 209 210 $attachment = _get_attachment_data ( $post_id ); 211 212 foreach ( $attachment as $key => $group ) { 213 if ($key != $group_num) { 214 $_group[$key] = array ('name' => $group['name'], 'items' => $group['items']); 215 continue; 216 } 217 218 if ( !is_array($group['items']) ) 219 break; 220 221 foreach ( $group['items'] as $item => $attachment_id ) { 222 $_attach[] = $attachment_id; 223 } 224 } 225 226 if ( is_array($_group[0]['items']) && is_array($_attach) ) { 227 $i = array_merge($_group[0]['items'], $_attach); 228 $_group[0] = array ('name' => null, 'items' => $i); 229 } else { 230 $_group[0] = array ('name' => null, 'items' => $_group[0]['items']); 231 } 232 233 update_post_meta( $post_id, '_wp_post_attachments', $_group ); 234 235 } 236 237 /** 238 * Updating the postmeta data when saving the gallery information. 239 * 240 * @since 2.7.0 241 * 242 * @param int $attachment_id Attachment ID 243 * @param int $post_id Post ID 244 * @param int $group_name Group Name 245 * @param int $group_number Group Number 246 */ 247 function wp_update_attachment ( $attachment_id, $post_id, $group_name = null, $group_number) { 248 249 $attachment = _get_attachment_data ( $post_id ); 250 251 // check to see if this group ($group_number) has a name assignment and is not null 252 if (( !isset($attachment[$group_number][name]) ) || ( !is_null($attachment[$group_number][name]) )) 253 if ($group_name != $attachment[$group_number][name]) 254 _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) 255 256 257 // 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. 258 $update = false; 259 foreach ( $attachment as $key => $group ) { 260 if ($key == $group_number) { 261 if ((!is_array($group['items'])) || (!in_array($attachment_id, $group['items']) )) { 262 if ($key == $group_number) { 263 $update = true; 264 $i[count($group['items'])] = $attachment_id; 265 266 if (!is_array($group['items'])) 267 $group['items'] = $i; 268 else 269 $group['items'] = array_merge($group['items'], $i); 270 271 _update_attachment_groupitem( $post_id, $key, $group['items'] ); 272 } 273 } 274 } 275 } 276 foreach ( $attachment as $key => $group ) { 277 if (($key != $group_number) && ($update)) { 278 if ( in_array($attachment_id, $group['items']) ) { 279 foreach ($group['items'] as $item => $attach) { 280 if ($attach != $attachment_id) 281 $g[] = $attach; 282 } 283 _update_attachment_groupitem( $post_id, $key, $g ); 284 } 285 } 286 } 287 288 } 289 290 /** 291 * Updateing the group name. (Private) 292 * 293 * @since 2.7.0 294 * 295 * @param int $post_id Post ID 296 * @param int $group_number Group Number 297 * @param str $group_name Group Name 298 */ 299 function _update_attachment_groupname ( $post_id, $group_number, $group_name ) { 300 301 $_attachment = _get_attachment_data ( $post_id ); 302 $_attachment[$group_number][name] = stripslashes($group_name); 303 304 update_post_meta( $post_id, '_wp_post_attachments', $_attachment ); 305 306 } 307 308 /** 309 * Updateing the group items. (Private) 310 * 311 * @since 2.7.0 312 * 313 * @param int $post_id Post ID 314 * @param int $group_number Group Number 315 * @param array $attachment_data The new item data for this group. 316 */ 317 function _update_attachment_groupitem ( $post_id, $group_number, $attachment_data ) { 318 319 $_attachment = _get_attachment_data ( $post_id ); 320 $_attachment[$group_number][items] = $attachment_data; 321 322 update_post_meta( $post_id, '_wp_post_attachments', $_attachment ); 323 324 } 325 326 /** 72 327 * Retrieve all children of the post parent ID. 73 328 * 74 329 * Normally, without any enhancements, the children would apply to pages. In the … … 1948 2203 } 1949 2204 1950 2205 /** 2206 * Retrieve a post given its title. 2207 * 2208 * @since 2.7.0 2209 * @uses $wpdb 2210 * 2211 * @param string $page_title Page title 2212 * @param string $output Optional. Output type. OBJECT, ARRAY_N, or ARRAY_A. 2213 * @return mixed 2214 */ 2215 function get_post_by_title($page_title, $output = OBJECT) { 2216 global $wpdb; 2217 $post = $wpdb->get_var( $wpdb->prepare( "SELECT ID FROM $wpdb->posts WHERE post_title = %s AND post_type='post'", $page_title )); 2218 if ( $post ) 2219 return get_post($post, $output); 2220 2221 return null; 2222 } 2223 2224 /** 1951 2225 * Retrieve child pages from list of pages matching page ID. 1952 2226 * 1953 2227 * Matches against the pages parameter against the page ID. Also matches all … … 2237 2511 // export array as variables 2238 2512 extract($object, EXTR_SKIP); 2239 2513 2514 wp_update_attachment($ID, $post_parent, $group_name, $group_number); // update or insert attachment into postmeta field 2515 2240 2516 // Make sure we set a valid category 2241 2517 if (0 == count($post_category) || !is_array($post_category)) { 2242 2518 $post_category = array(get_option('default_category'));