Ticket #7607: 7607.4.diff
File 7607.4.diff, 34.2 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_id']); 391 } 392 393 if ( isset($_POST['gallery_delete']) && !is_null($_POST['gallery_delete']) && ($_POST['gallery_delete'] > 0) ) 394 wp_delete_gallery($post['post_id'], $_POST['gallery_delete']); 381 395 382 396 if ( isset($_POST['send']) ) { 383 397 $keys = array_keys($_POST['send']); … … 426 440 $align = attribute_escape($_POST['insertonly']['align']); 427 441 $class = " class='align$align'"; 428 442 } 443 if ( isset($_POST['insertonly']['title']) ) { 444 $title = " title='".attribute_escape($_POST['insertonly']['title'])."'"; 445 } 429 446 if ( !empty($src) ) 430 $html = "<img src='$src' alt='$alt'$ class />";447 $html = "<img src='$src' alt='$alt'$title$class />"; 431 448 return media_send_to_editor($html); 432 449 } 433 450 … … 841 858 $post['errors']['post_title']['errors'][] = __('Empty Title filled from filename.'); 842 859 } 843 860 } 861 862 $post['group_name'] = $_POST['attachments']['group_name'][$attachment['group_number']]; 844 863 845 864 return $post; 846 865 } … … 969 988 * @param array $errors Errors for attachment, if any. 970 989 * @return string 971 990 */ 972 function get_media_items( $post_id, $ errors ) {991 function get_media_items( $post_id, $group_number = null, $errors ) { 973 992 if ( $post_id ) { 974 993 $post = get_post($post_id); 975 if ( $post && $post->post_type == 'attachment' ) 994 if ( $post && $post->post_type == 'attachment' ) { 976 995 $attachments = array($post->ID => $post); 977 else 978 $attachments = get_children( array( 'post_parent' => $post_id, 'post_type' => 'attachment', 'orderby' => 'menu_order ASC, ID', 'order' => 'DESC') ); 996 } else { 997 $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') ) ); 998 999 if ( ! count($attachments) ) 1000 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>"; 1001 } 979 1002 } else { 980 1003 if ( is_array($GLOBALS['wp_the_query']->posts) ) 981 1004 foreach ( $GLOBALS['wp_the_query']->posts as $attachment ) … … 985 1008 if ( empty($attachments) ) 986 1009 return ''; 987 1010 988 foreach ( $attachments as $id => $attachment ) 1011 foreach ( $attachments as $id => $attachment ) { 989 1012 if ( $item = get_media_item( $id, array( 'errors' => isset($errors[$id]) ? $errors[$id] : null) ) ) 990 1013 $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>"; 991 1014 } 1015 992 1016 return $output; 993 1017 } 994 1018 … … 1026 1050 $filename = basename($post->guid); 1027 1051 $title = attribute_escape($post->post_title); 1028 1052 $description = attribute_escape($post->post_content); 1053 $group_number = attribute_escape($post->group_number); 1029 1054 if ( $_tags = get_the_tags($attachment_id) ) { 1030 1055 foreach ( $_tags as $tag ) 1031 1056 $tags[] = $tag->name; … … 1056 1081 $gallery = ( (isset($_REQUEST['tab']) && 'gallery' == $_REQUEST['tab']) || (isset($redir_tab) && 'gallery' == $redir_tab) ) ? true : false; 1057 1082 $order = ''; 1058 1083 1084 $groupnum = '<input type="hidden" class="group-value" name="attachments['.$attachment_id.'][group_number]" value="'.$group_number.'" />'; 1085 1059 1086 foreach ( $form_fields as $key => $val ) { 1060 1087 if ( 'menu_order' == $key ) { 1061 1088 if ( $gallery ) … … 1072 1099 $type 1073 1100 $toggle_links 1074 1101 $order 1102 $groupnum 1075 1103 $display_title 1076 1104 <table class='slidetoggle describe $class'> 1077 1105 <thead class='media-item-info'> … … 1355 1383 html = '<img alt="'+alt+'" src="'+f.src.value+'"'+title+cls+' width="'+t.width+'" height="'+t.height+'" />'; 1356 1384 1357 1385 if ( f.url.value ) 1358 html = '<a href="'+f.url.value+'" >'+html+'</a>';1386 html = '<a href="'+f.url.value+'"'+title+'>'+html+'</a>'; 1359 1387 1360 1388 if ( caption ) 1361 1389 html = '[caption id="" align="'+t.align+'" width="'+t.width+'" caption="'+caption+'"]'+html+'[/caption]'; … … 1425 1453 media_upload_header(); 1426 1454 1427 1455 $post_id = intval($_REQUEST['post_id']); 1456 $groups = intval(get_attachment_groups( $post_id )); 1457 $_group_name = get_attachments_groupsname( $post_id ); 1458 1428 1459 $form_action_url = admin_url("media-upload.php?type={$GLOBALS['type']}&tab=gallery&post_id=$post_id"); 1429 1460 ?> 1430 1461 … … 1434 1465 var preloaded = $(".media-item.preloaded"); 1435 1466 if ( preloaded.length > 0 ) { 1436 1467 preloaded.each(function(){prepareMediaItem({id:this.id.replace(/[^0-9]/g, '')},'');}); 1437 updateMediaForm();1438 1468 } 1469 jQuery("a.del-group").click(function () { 1470 var deleteConfirmation = confirm('<?php _e("Are you sure you want to delete this gallery group?"); ?>'); 1471 1472 if (!deleteConfirmation) { return; } 1473 1474 if (jQuery("#media-group-" + jQuery(this).attr('value') + " .media-item input.group-value").length) 1475 { 1476 jQuery.each(jQuery("#media-group-delete-" + jQuery(this).attr('value') + " .media-item input.group-value"), function(i, id) { 1477 jQuery(id)[0].value = 0; // we are going to set all the items to group 0 1478 }); 1479 } 1480 jQuery("#gallery-delete").val( jQuery(this).attr('value') ); // set the gallery we are deleting 1481 jQuery("#media-group-" + jQuery(this).attr('value')).hide(); // hide the gallery and then... 1482 jQuery(".savebutton").click(); 1483 }); 1484 jQuery("a.insert-group").click(function () { 1485 jQuery("#gallery-insert").val( jQuery(this).attr('value') ); // set the gallery we are inserting 1486 jQuery(".insert-gallery").click(); 1487 }); 1439 1488 }); 1440 1489 --> 1441 1490 </script> … … 1443 1492 <form enctype="multipart/form-data" method="post" action="<?php echo attribute_escape($form_action_url); ?>" class="media-upload-form validate" id="gallery-form"> 1444 1493 <?php wp_nonce_field('media-form'); ?> 1445 1494 <?php //media_upload_form( $errors ); ?> 1495 <div id="media-items"> 1496 <?php 1497 for ( $i = 0; $i < $groups; $i++ ) 1498 { 1499 ?> 1500 <div id="media-group-<?php echo $i; ?>" class="media-groups"> 1501 <input type="hidden" id="media-group-value-<?php echo $i; ?>" value="<?php echo $i; ?>" /> 1446 1502 <table class="widefat"> 1447 1503 <thead><tr> 1448 <th><?php _e('Media'); ?></th> 1504 <th> 1505 <?php 1506 if ($i > 0) { 1507 1508 $delete = "<a href=\"#media-group-delete-value-".$i."\" value=\"".$i."\" class=\"del-group\">" . __('Delete') . "</a>"; 1509 $insert = "<a href=\"#media-group-insert-value-".$i."\" value=\"".$i."\" class=\"insert-group\">" . __('Insert') . "</a>"; 1510 $group_link = "<small>[".$delete." | " .$insert."]</small>"; 1511 $group_name = "<input type=\"text\" name=\"attachments[group_name][".$i."]\" value=\"" . $_group_name[$i] . "\" size=\"20\" />"; 1512 1513 printf( __('Group (%1$d) %2$s %3$s'), $i, $group_name, $group_link); 1514 1515 1516 } else { 1517 1518 _e('Media: Non-grouped items.'); 1519 1520 } 1521 ?> 1522 </th> 1449 1523 <th class="order-head"><?php _e('Order'); ?></th> 1450 1524 </tr></thead> 1451 1525 </table> 1452 <div id="media-items"> 1453 <?php echo get_media_items($post_id, $errors); ?> 1526 <?php echo get_media_items($post_id, $i, $errors); ?> 1454 1527 </div> 1528 <?php 1529 } 1530 ?> 1531 </div> 1455 1532 <p class="ml-submit"> 1456 1533 <input type="submit" class="button savebutton" name="save" value="<?php echo attribute_escape( __( 'Save all changes' ) ); ?>" /> 1457 <input type="submit" class="button insert-gallery" name="insert-gallery" value="<?php echo attribute_escape( __( 'Insert gallery into post' ) ); ?>" /> 1534 <input type="submit" class="button new-gallery" name="new-gallery" value="<?php echo attribute_escape( __( 'Create new gallery' ) ); ?>" /> 1535 <input type="submit" class="button insert-gallery" name="insert-gallery" value="<?php echo attribute_escape( __( 'Insert full gallery into post' ) ); ?>" /> 1536 <input type="hidden" name="gallery_delete" id="gallery-delete" value="" /> 1537 <input type="hidden" name="gallery_insert" id="gallery-insert" value="" /> 1458 1538 <input type="hidden" name="post_id" id="post_id" value="<?php echo (int) $post_id; ?>" /> 1459 1539 <input type="hidden" name="type" value="<?php echo attribute_escape( $GLOBALS['type'] ); ?>" /> 1460 1540 <input type="hidden" name="tab" value="<?php echo attribute_escape( $GLOBALS['tab'] ); ?>" /> 1461 1541 </p> 1462 1542 </form> 1543 <script type="text/javascript"> 1544 <!-- 1545 updateMediaForm(); 1546 --> 1547 </script> 1463 1548 <?php 1464 1549 } 1465 1550 … … 1606 1691 </script> 1607 1692 1608 1693 <div id="media-items"> 1609 <?php echo get_media_items(null, $errors); ?>1694 <?php echo get_media_items(null, null, $errors); ?> 1610 1695 </div> 1611 1696 <p class="ml-submit"> 1612 1697 <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 911 if ( $wp_current_db_version < 9094 ) { 912 update_option('image_display_type', 'none'); // default display option 913 $posts = $wpdb->get_results("SELECT ID FROM $wpdb->posts WHERE (post_type = 'post' || post_type = 'page')"); 914 foreach ( (array) $posts as $post ) { 915 $attachments = $wpdb->get_results("SELECT ID FROM $wpdb->posts WHERE post_type = 'attachment' AND post_parent = $post->ID"); 916 917 foreach ( (array) $attachments as $attachment ) 918 $attach[] = $attachment->ID; 919 920 $_new_group = array(0 => array ('name' => null, 'items' => $attach)); 921 update_post_meta( $post->ID, '_wp_post_attachments', $_new_group ); 922 unset($attach); 923 } 924 } 925 unset($posts, $attachments); 926 909 927 } 910 928 911 929 -
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 // @todo: This is untested. 110 $attachment_childern = get_children( array('post_parent' => $post_id, 'post_status' => 'inherit', 'post_type' => 'attachment', 'post_mime_type' => 'image', 'order' => $order, 'orderby' => $orderby) ); 111 } 112 113 $attachment = _get_attachment_data ( $post_id ); 114 115 if ( !is_array($attachment) ) 116 return; 117 118 foreach ( $attachment_childern as $id => $image ) { 119 120 foreach ( $attachment as $key => $group ) { 121 122 if ( !is_array($group['items']) ) 123 continue; 124 125 if (is_null($group_number)) { 126 if ($key == 0) { continue; } 127 } else { 128 if ($key != $group_number) { continue; } 129 } 130 131 if (in_array($id, $group['items'])) { 132 133 $image = $attachment_childern[$id]; 134 $image->group_number = $key; 135 $image->group_name = $group['name']; 136 137 $attach[$id] = $image; 138 139 } 140 141 } 142 143 } 144 145 return $attach; 146 } 147 148 /** 149 * Get the gallery groups names. 150 * 151 * @since 2.7.0 152 * 153 * @param int $post_id Post ID 154 */ 155 function &get_attachments_groupsname( $post_id ) { 156 157 $attachment = _get_attachment_data ( $post_id ); 158 159 if ( !is_array($attachment) ) 160 return ''; 161 162 foreach ( $attachment as $key => $group ) { 163 $groups[$key] = $group['name']; 164 } 165 166 return $groups; 167 } 168 169 /** 170 * Get the number of groups attached to this post. 171 * 172 * @since 2.7.0 173 * 174 * @param int $post_id Post ID 175 */ 176 function get_attachment_groups( $post_id ) { 177 178 return count(_get_attachment_data ( $post_id )); 179 } 180 181 /** 182 * Insert a new gallery into the post. 183 * 184 * @since 2.7.0 185 * 186 * @param int $post_id post data 187 */ 188 function wp_new_gallery ( $post_id ) { 189 190 $attachment = _get_attachment_data ( $post_id ); 191 192 foreach ( $attachment as $key => $group ) { 193 $_group[$key] = array ('name' => $group['name'], 'items' => $group['items']); 194 } 195 196 $_group[] = array ('name' => null, 'items' => null); 197 198 update_post_meta( $post_id, '_wp_post_attachments', $_group); 199 200 } 201 202 /** 203 * We are deleting a gallery and moving 204 * 205 * @since 2.7.0 206 * 207 * @param int $post_id Post ID 208 * @param int $group_number Group Number 209 */ 210 function wp_delete_gallery ( $post_id, $group_num ) { 211 212 $attachment = _get_attachment_data ( $post_id ); 213 214 foreach ( $attachment as $key => $group ) { 215 if ($key != $group_num) { 216 $_group[$key] = array ('name' => $group['name'], 'items' => $group['items']); 217 continue; 218 } 219 220 if ( !is_array($group['items']) ) 221 break; 222 223 foreach ( $group['items'] as $item => $attachment_id ) { 224 $_attach[] = $attachment_id; 225 } 226 } 227 228 if ( is_array($_group[0]['items']) && is_array($_attach) ) { 229 $i = array_merge($_group[0]['items'], $_attach); 230 $_group[0] = array ('name' => null, 'items' => $i); 231 } else { 232 $_group[0] = array ('name' => null, 'items' => $_group[0]['items']); 233 } 234 235 update_post_meta( $post_id, '_wp_post_attachments', $_group ); 236 237 } 238 239 /** 240 * Updating the postmeta data when saving the gallery information. 241 * 242 * @since 2.7.0 243 * 244 * @param int $attachment_id Attachment ID 245 * @param int $post_id Post ID 246 * @param int $group_name Group Name 247 * @param int $group_number Group Number 248 */ 249 function wp_update_attachment ( $attachment_id, $post_id, $group_name = null, $group_number = null) { 250 251 $attachment = _get_attachment_data ( $post_id ); 252 253 if (!is_array($attachment)) { 254 $_attach[] = array ('name' => null, 'items' => array($attachment_id) ); 255 add_post_meta($post_id, '_wp_post_attachments', $_attach, true); 256 return true; 257 } 258 259 // check to see if this group ($group_number) has a name assignment and is not null 260 261 /* 262 if (( !isset($attachment[$group_number][name]) ) || ( !is_null($attachment[$group_number][name]) )) 263 if ($group_name != $attachment[$group_number][name]) 264 _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) 265 266 */ 267 268 // 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. 269 $update = false; 270 foreach ( $attachment as $key => $group ) { 271 if ($key == $group_number) { 272 if ((!is_array($group['items'])) || (!in_array($attachment_id, $group['items']) )) { 273 if ($key == $group_number) { 274 $update = true; 275 $i[count($group['items'])] = $attachment_id; 276 277 if (!is_array($group['items'])) 278 $group['items'] = $i; 279 else 280 $group['items'] = array_merge($group['items'], $i); 281 282 _update_attachment_groupitem( $post_id, $key, $group['items'] ); 283 } 284 } 285 } 286 } 287 foreach ( $attachment as $key => $group ) { 288 if (($key != $group_number) && ($update)) { 289 if ( in_array($attachment_id, $group['items']) ) { 290 foreach ($group['items'] as $item => $attach) { 291 if ($attach != $attachment_id) 292 $g[] = $attach; 293 } 294 _update_attachment_groupitem( $post_id, $key, $g ); 295 } 296 } 297 } 298 299 } 300 301 /** 302 * Updateing the group name. (Private) 303 * 304 * @since 2.7.0 305 * 306 * @param int $post_id Post ID 307 * @param int $group_number Group Number 308 * @param str $group_name Group Name 309 */ 310 function _update_attachment_groupname ( $post_id, $group_number, $group_name ) { 311 312 $_attachment = _get_attachment_data ( $post_id ); 313 $_attachment[$group_number][name] = stripslashes($group_name); 314 315 update_post_meta( $post_id, '_wp_post_attachments', $_attachment ); 316 317 } 318 319 /** 320 * Updateing the group items. (Private) 321 * 322 * @since 2.7.0 323 * 324 * @param int $post_id Post ID 325 * @param int $group_number Group Number 326 * @param array $attachment_data The new item data for this group. 327 */ 328 function _update_attachment_groupitem ( $post_id, $group_number, $attachment_data ) { 329 330 $_attachment = _get_attachment_data ( $post_id ); 331 $_attachment[$group_number][items] = $attachment_data; 332 333 update_post_meta( $post_id, '_wp_post_attachments', $_attachment ); 334 335 } 336 337 /** 338 * Retrieve a post given its title. 339 * 340 * @since 2.7.0 341 * @uses $wpdb 342 * 343 * @param string $page_title Page title 344 * @param string $output Optional. Output type. OBJECT, ARRAY_N, or ARRAY_A. 345 * @return mixed 346 */ 347 function get_post_by_title($page_title, $output = OBJECT) { 348 global $wpdb; 349 $post = $wpdb->get_var( $wpdb->prepare( "SELECT ID FROM $wpdb->posts WHERE post_title = %s AND post_type='post'", $page_title )); 350 if ( $post ) 351 return get_post($post, $output); 352 353 return null; 354 } 355 356 /** 72 357 * Retrieve child pages from list of pages matching page ID. 73 358 * 74 359 * Matches against the pages parameter against the page ID. Also matches all … … 2244 2558 2245 2559 // export array as variables 2246 2560 extract($object, EXTR_SKIP); 2247 2561 2248 2562 // Make sure we set a valid category 2249 2563 if (0 == count($post_category) || !is_array($post_category)) { 2250 2564 $post_category = array(get_option('default_category')); … … 2338 2652 $post_name = sanitize_title($post_title, $post_ID); 2339 2653 $wpdb->update( $wpdb->posts, compact("post_name"), array( 'ID' => $post_ID ) ); 2340 2654 } 2655 2656 wp_update_attachment($post_ID, $post_parent, $group_name, $group_number); // update or insert attachment into postmeta field 2341 2657 2342 2658 wp_set_post_categories($post_ID, $post_category); 2343 2659