Ticket #18429: dates_and_featured_image3.patch
File dates_and_featured_image3.patch, 18.0 KB (added by , 13 years ago) |
---|
-
wp-includes/class-wp-xmlrpc-server.php
467 467 } 468 468 469 469 /** 470 * Convert a WordPress date string to an IXR_Date object. 471 * 472 * @access protected 473 * 474 * @param $date 475 * @return IXR_Date 476 */ 477 protected function _convert_date( $date, $format = 'Ymd\TH:i:s' ) { 478 if ( $date === '0000-00-00 00:00:00' ) { 479 return new IXR_Date( '00000000T00:00:00Z' ); 480 } 481 return new IXR_Date( mysql2date( $format, $date, false ) ); 482 } 483 484 /** 485 * Convert a WordPress date string to an IXR_Date object. 486 * 487 * @access protected 488 * 489 * @param $date 490 * @return IXR_Date 491 */ 492 protected function _convert_date_gmt( $date, $format = 'Ymd\TH:i:s' ) { 493 if ( $date === '0000-00-00 00:00:00' ) { 494 return new IXR_Date( '00000000T00:00:00Z' ); 495 } 496 return new IXR_Date( get_gmt_from_date( mysql2date( $format, $date, false ) ) ); 497 } 498 499 /** 470 500 * Prepares post data for return in an XML-RPC object. 471 501 * 472 502 * @access private … … 477 507 */ 478 508 function _prepare_post( $post, $fields ) { 479 509 // holds the data for this post. built up based on $fields 480 $_post = array( 'post_id' => $post['ID']);510 $_post = array( 'post_id' => strval( $post['ID'] ) ); 481 511 482 512 // prepare common post fields 483 513 $post_fields = array( 484 514 'post_title' => $post['post_title'], 485 'post_date' => new IXR_Date( mysql2date( 'Ymd\TH:i:s', $post['post_date'], false )),486 'post_date_gmt' => new IXR_Date( mysql2date( 'Ymd\TH:i:s', $post['post_date_gmt'], false )),487 'post_modified' => new IXR_Date( mysql2date( 'Ymd\TH:i:s', $post['post_modified'], false )),488 'post_modified_gmt' => new IXR_Date( mysql2date( 'Ymd\TH:i:s', $post['post_modified_gmt'], false )),515 'post_date' => $this->_convert_date( $post['post_date'] ), 516 'post_date_gmt' => $this->_convert_date( $post['post_date_gmt'] ), 517 'post_modified' => $this->_convert_date( $post['post_modified'] ), 518 'post_modified_gmt' => $this->_convert_date( $post['post_modified_gmt'] ), 489 519 'post_status' => $post['post_status'], 490 520 'post_type' => $post['post_type'], 491 521 'post_name' => $post['post_name'], … … 499 529 'sticky' => ( $post['post_type'] === 'post' && is_sticky( $post['ID'] ) ), 500 530 ); 501 531 532 if( current_theme_supports( 'post-thumbnails' ) ) { 533 $post_fields['featured_image'] = get_post_thumbnail_id( $post['ID'] ); 534 } 535 502 536 // Consider future posts as published 503 537 if ( $post_fields['post_status'] === 'future' ) 504 538 $post_fields['post_status'] = 'publish'; … … 591 625 * - comment_status - can be 'open' | 'closed' 592 626 * - ping_status - can be 'open' | 'closed' 593 627 * - sticky 628 * - featured_image - ID of a media item to use as the featured image 594 629 * - custom_fields - array, with each element containing 'key' and 'value' 595 630 * - terms - array, with taxonomy names as keys and arrays of term IDs as values 596 631 * - terms_names - array, with taxonomy names as keys and arrays of term names as values … … 724 759 stick_post( $post_ID ); 725 760 } 726 761 762 if ( isset ( $post_data['featured_image'] ) ) { 763 if( current_theme_supports( 'post-thumbnails' ) ) { 764 // empty value deletes, non-empty value adds/updates 765 if ( empty( $post_data['featured_image'] ) ) { 766 delete_post_thumbnail( $post_ID ); 767 } 768 else { 769 if ( set_post_thumbnail( $post_ID, $post_data['featured_image'] ) === false ) 770 return new IXR_Error( 404, __( 'Invalid attachment ID.' ) ); 771 } 772 unset( $content_struct['featured_image'] ); 773 } 774 else { 775 return new IXR_Error( 401, __( 'Sorry, you are not able to set a post thumbnail.' ) ); 776 } 777 } 778 727 779 if ( isset ( $post_data['custom_fields'] ) && post_type_supports( $post_data['post_type'], 'custom-fields' ) ) { 728 780 $this->set_custom_fields( $post_ID, $post_data['custom_fields'] ); 729 781 } … … 880 932 return new IXR_Error( 404, __( 'Invalid post ID.' ) ); 881 933 882 934 // convert the date field back to IXR form 883 $post['post_date'] = new IXR_Date( mysql2date( 'Ymd\TH:i:s', $post['post_date'], false ));935 $post['post_date'] = $this->_convert_date( $post['post_date'] ); 884 936 885 937 // ignore the existing GMT date if it is empty or a non-GMT date was supplied in $content_struct, 886 938 // since _insert_post will ignore the non-GMT date if the GMT date is set 887 939 if ( $post['post_date_gmt'] == '0000-00-00 00:00:00' || isset( $content_struct['post_date'] ) ) 888 940 unset( $post['post_date_gmt'] ); 889 941 else 890 $post['post_date_gmt'] = new IXR_Date( mysql2date( 'Ymd\TH:i:s', $post['post_date_gmt'], false ));942 $post['post_date_gmt'] = $this->_convert_date( $post['post_date_gmt'] ); 891 943 892 944 $this->escape( $post ); 893 945 $merged_content_struct = array_merge( $post, $content_struct ); … … 1080 1132 $query['order'] = $filter['order']; 1081 1133 } 1082 1134 1083 do_action( 'xmlrpc_call', 'wp.getPosts' );1084 1085 1135 $posts_list = wp_get_recent_posts( $query ); 1086 1136 1087 1137 if ( ! $posts_list ) … … 1151 1201 $allow_pings = pings_open($page->ID) ? 1 : 0; 1152 1202 1153 1203 // Format page date. 1154 $page_date = mysql2date('Ymd\TH:i:s', $page->post_date, false);1155 $page_date_gmt = mysql2date('Ymd\TH:i:s', $page->post_date_gmt, false);1204 $page_date = $this->_convert_date( $page->post_date ); 1205 $page_date_gmt = $this->_convert_date( $page->post_date_gmt ); 1156 1206 1157 1207 // For drafts use the GMT version of the date 1158 if ( $page->post_status == 'draft')1159 $page_date_gmt = get_gmt_from_date( mysql2date( 'Y-m-d H:i:s', $page->post_date ), 'Ymd\TH:i:s');1208 if ( in_array( $page->post_status, array( 'draft', 'pending', 'auto-draft' ) ) ) 1209 $page_date_gmt = $this->_convert_date_gmt( $page->post_date ); 1160 1210 1161 1211 // Pull the categories info together. 1162 1212 $categories = array(); … … 1172 1222 $page_template = 'default'; 1173 1223 1174 1224 $page_struct = array( 1175 'dateCreated' => new IXR_Date($page_date),1225 'dateCreated' => $page_date, 1176 1226 'userid' => $page->post_author, 1177 1227 'page_id' => $page->ID, 1178 1228 'page_status' => $page->post_status, … … 1193 1243 'wp_page_order' => $page->menu_order, 1194 1244 'wp_author_id' => (string) $author->ID, 1195 1245 'wp_author_display_name' => $author->display_name, 1196 'date_created_gmt' => new IXR_Date($page_date_gmt),1246 'date_created_gmt' => $page_date_gmt, 1197 1247 'custom_fields' => $this->get_custom_fields($page_id), 1198 1248 'wp_page_template' => $page_template 1199 1249 ); … … 1410 1460 // The date needs to be formatted properly. 1411 1461 $num_pages = count($page_list); 1412 1462 for ( $i = 0; $i < $num_pages; $i++ ) { 1413 $p ost_date = mysql2date('Ymd\TH:i:s', $page_list[$i]->post_date, false);1414 $p ost_date_gmt = mysql2date('Ymd\TH:i:s', $page_list[$i]->post_date_gmt, false);1463 $page_list[$i]->dateCreated = $this->_convert_date( $page_list[$i]->post_date ); 1464 $page_list[$i]->date_created_gmt = $this->_convert_date( $page_list[$i]->post_date_gmt ); 1415 1465 1416 $page_list[$i]->dateCreated = new IXR_Date($post_date);1417 $page_list[$i]->date_created_gmt = new IXR_Date($post_date_gmt);1418 1419 1466 // For drafts use the GMT version of the date 1420 if ( $page_list[$i]->post_status == 'draft' ) { 1421 $page_list[$i]->date_created_gmt = get_gmt_from_date( mysql2date( 'Y-m-d H:i:s', $page_list[$i]->post_date ), 'Ymd\TH:i:s' ); 1422 $page_list[$i]->date_created_gmt = new IXR_Date( $page_list[$i]->date_created_gmt ); 1467 if ( in_array( $page_list[$i]->post_status, array( 'draft', 'pending', 'auto-draft' ) ) ) { 1468 $page_list[$i]->date_created_gmt = $this->_convert_date_gmt( $page_list[$i]->post_date ); 1423 1469 } 1424 1470 1425 1471 unset($page_list[$i]->post_date_gmt); … … 1658 1704 return new IXR_Error( 404, __( 'Invalid comment ID.' ) ); 1659 1705 1660 1706 // Format page date. 1661 $comment_date = mysql2date('Ymd\TH:i:s', $comment->comment_date, false);1662 $comment_date_gmt = mysql2date('Ymd\TH:i:s', $comment->comment_date_gmt, false);1707 $comment_date = $this->_convert_date( $comment->comment_date ); 1708 $comment_date_gmt = $this->_convert_date( $comment->comment_date_gmt ); 1663 1709 1664 1710 if ( '0' == $comment->comment_approved ) 1665 1711 $comment_status = 'hold'; … … 1673 1719 $link = get_comment_link($comment); 1674 1720 1675 1721 $comment_struct = array( 1676 'date_created_gmt' => new IXR_Date($comment_date_gmt),1722 'date_created_gmt' => $comment_date_gmt, 1677 1723 'user_id' => $comment->user_id, 1678 1724 'comment_id' => $comment->comment_ID, 1679 1725 'parent' => $comment->comment_parent, … … 2241 2287 return new IXR_Error( 404, __( 'Invalid attachment ID.' ) ); 2242 2288 2243 2289 // Format page date. 2244 $attachment_date = mysql2date('Ymd\TH:i:s', $attachment->post_date, false);2245 $attachment_date_gmt = mysql2date('Ymd\TH:i:s', $attachment->post_date_gmt, false);2290 $attachment_date = $this->_convert_date( $attachment->post_date ); 2291 $attachment_date_gmt = $this->_convert_date( $attachment->post_date_gmt ); 2246 2292 2247 2293 $link = wp_get_attachment_url($attachment->ID); 2248 2294 $thumbnail_link = wp_get_attachment_thumb_url($attachment->ID); 2249 2295 2250 2296 $attachment_struct = array( 2251 'date_created_gmt' => new IXR_Date($attachment_date_gmt),2297 'date_created_gmt' => $attachment_date_gmt, 2252 2298 'parent' => $attachment->post_parent, 2253 2299 'link' => $link, 2254 2300 'thumbnail' => $thumbnail_link, … … 2503 2549 2504 2550 $struct = array( 2505 2551 'userid' => $post_data['post_author'], 2506 'dateCreated' => new IXR_Date(mysql2date('Ymd\TH:i:s', $post_data['post_date'], false)),2552 'dateCreated' => $this->_convert_date( $post_data['post_date'] ), 2507 2553 'content' => $content, 2508 2554 'postid' => (string) $post_data['ID'] 2509 2555 ); … … 2548 2594 if ( !current_user_can( 'edit_post', $entry['ID'] ) ) 2549 2595 continue; 2550 2596 2551 $post_date = mysql2date('Ymd\TH:i:s', $entry['post_date'], false);2597 $post_date = $this->_convert_date( $entry['post_date'] ); 2552 2598 $categories = implode(',', wp_get_post_categories($entry['ID'])); 2553 2599 2554 2600 $content = '<title>'.stripslashes($entry['post_title']).'</title>'; … … 2557 2603 2558 2604 $struct[] = array( 2559 2605 'userid' => $entry['post_author'], 2560 'dateCreated' => new IXR_Date($post_date),2606 'dateCreated' => $post_date, 2561 2607 'content' => $content, 2562 2608 'postid' => (string) $entry['ID'], 2563 2609 ); … … 2816 2862 * - wp_page_parent_id 2817 2863 * - wp_page_order 2818 2864 * - wp_author_id 2865 * - wp_featured_image 2819 2866 * - post_status | page_status - can be 'draft', 'private', 'publish', or 'pending' 2820 2867 * - mt_allow_comments - can be 'open' or 'closed' 2821 2868 * - mt_allow_pings - can be 'open' or 'closed' … … 3067 3114 if ( isset($content_struct['custom_fields']) ) 3068 3115 $this->set_custom_fields($post_ID, $content_struct['custom_fields']); 3069 3116 3117 if ( isset ( $post_data['wp_featured_image'] ) ) { 3118 if( current_theme_supports( 'post-thumbnails' ) && ! empty( $post_data['wp_featured_image'] ) ) { 3119 if ( set_post_thumbnail( $post_ID, $post_data['wp_featured_image'] ) === false ) 3120 return new IXR_Error( 404, __( 'Invalid attachment ID.' ) ); 3121 3122 unset( $content_struct['wp_featured_image'] ); 3123 } 3124 else { 3125 return new IXR_Error( 401, __( 'Sorry, you are not able to set a post thumbnail.' ) ); 3126 } 3127 } 3128 3070 3129 // Handle enclosures 3071 3130 $thisEnclosure = isset($content_struct['enclosure']) ? $content_struct['enclosure'] : null; 3072 3131 $this->add_enclosure_if_new($post_ID, $thisEnclosure); … … 3365 3424 if ( isset($content_struct['custom_fields']) ) 3366 3425 $this->set_custom_fields($post_ID, $content_struct['custom_fields']); 3367 3426 3427 if ( isset ( $post_data['wp_featured_image'] ) ) { 3428 if( current_theme_supports( 'post-thumbnails' ) ) { 3429 // empty value deletes, non-empty value adds/updates 3430 if ( empty( $post_data['wp_featured_image'] ) ) { 3431 delete_post_thumbnail( $post_ID ); 3432 } 3433 else { 3434 if ( set_post_thumbnail( $post_ID, $post_data['wp_featured_image'] ) === false ) 3435 return new IXR_Error( 404, __( 'Invalid attachment ID.' ) ); 3436 } 3437 unset( $content_struct['wp_featured_image'] ); 3438 } 3439 else { 3440 return new IXR_Error( 401, __( 'Sorry, you are not able to set a post thumbnail.' ) ); 3441 } 3442 } 3443 3368 3444 // Handle enclosures 3369 3445 $thisEnclosure = isset($content_struct['enclosure']) ? $content_struct['enclosure'] : null; 3370 3446 $this->add_enclosure_if_new($post_ID, $thisEnclosure); … … 3406 3482 $postdata = wp_get_single_post($post_ID, ARRAY_A); 3407 3483 3408 3484 if ($postdata['post_date'] != '') { 3409 $post_date = mysql2date('Ymd\TH:i:s', $postdata['post_date'], false);3410 $post_date_gmt = mysql2date('Ymd\TH:i:s', $postdata['post_date_gmt'], false);3411 $post_modified = mysql2date('Ymd\TH:i:s', $postdata['post_modified'], false);3412 $post_modified_gmt = mysql2date('Ymd\TH:i:s', $postdata['post_modified_gmt'], false);3485 $post_date = $this->_convert_date( $postdata['post_date'] ); 3486 $post_date_gmt = $this->_convert_date( $postdata['post_date_gmt'] ); 3487 $post_modified = $this->_convert_date( $postdata['post_modified'] ); 3488 $post_modified_gmt = $this->_convert_date( $postdata['post_modified_gmt'] ); 3413 3489 3414 3490 // For drafts use the GMT version of the post date 3415 3491 if ( $postdata['post_status'] == 'draft' ) { 3416 $post_date_gmt = get_gmt_from_date( mysql2date( 'Y-m-d H:i:s', $postdata['post_date'] ), 'Ymd\TH:i:s');3417 $post_modified_gmt = get_gmt_from_date( mysql2date( 'Y-m-d H:i:s', $postdata['post_modified'] ), 'Ymd\TH:i:s');3492 $post_date_gmt = $this->_convert_date_gmt( $postdata['post_date'] ); 3493 $post_modified_gmt = $this->_convert_date_gmt( $postdata['post_modified'] ); 3418 3494 } 3419 3495 3420 3496 $categories = array(); … … 3468 3544 } 3469 3545 3470 3546 $resp = array( 3471 'dateCreated' => new IXR_Date($post_date),3547 'dateCreated' => $post_date, 3472 3548 'userid' => $postdata['post_author'], 3473 3549 'postid' => $postdata['ID'], 3474 3550 'description' => $post['main'], … … 3486 3562 'wp_slug' => $postdata['post_name'], 3487 3563 'wp_password' => $postdata['post_password'], 3488 3564 'wp_author_id' => (string) $author->ID, 3489 'wp_author_display_name' 3490 'date_created_gmt' => new IXR_Date($post_date_gmt),3565 'wp_author_display_name' => $author->display_name, 3566 'date_created_gmt' => $post_date_gmt, 3491 3567 'post_status' => $postdata['post_status'], 3492 3568 'custom_fields' => $this->get_custom_fields($post_ID), 3493 3569 'wp_post_format' => $post_format, 3494 3570 'sticky' => $sticky, 3495 'date_modified' => new IXR_Date( $post_modified ),3496 'date_modified_gmt' => new IXR_Date( $post_modified_gmt )3571 'date_modified' => $post_modified, 3572 'date_modified_gmt' => $post_modified_gmt 3497 3573 ); 3498 3574 3499 3575 if ( !empty($enclosure) ) $resp['enclosure'] = $enclosure; 3500 3576 3577 if( current_theme_supports( 'post-thumbnails' ) ) { 3578 $resp['wp_featured_image'] = get_post_thumbnail_id( $postdata['ID'] ); 3579 } 3580 3501 3581 return $resp; 3502 3582 } else { 3503 3583 return new IXR_Error(404, __('Sorry, no such post.')); … … 3538 3618 if ( !current_user_can( 'edit_post', $entry['ID'] ) ) 3539 3619 continue; 3540 3620 3541 $post_date = mysql2date('Ymd\TH:i:s', $entry['post_date'], false);3542 $post_date_gmt = mysql2date('Ymd\TH:i:s', $entry['post_date_gmt'], false);3543 $post_modified = mysql2date('Ymd\TH:i:s', $entry['post_modified'], false);3544 $post_modified_gmt = mysql2date('Ymd\TH:i:s', $entry['post_modified_gmt'], false);3621 $post_date = $this->_convert_date( $entry['post_date'] ); 3622 $post_date_gmt = $this->_convert_date( $entry['post_date_gmt'] ); 3623 $post_modified = $this->_convert_date( $entry['post_modified'] ); 3624 $post_modified_gmt = $this->_convert_date( $entry['post_modified_gmt'] ); 3545 3625 3546 3626 // For drafts use the GMT version of the date 3547 3627 if ( $entry['post_status'] == 'draft' ) { 3548 $post_date_gmt = get_gmt_from_date( mysql2date( 'Y-m-d H:i:s', $entry['post_date'] ), 'Ymd\TH:i:s');3549 $post_modified_gmt = get_gmt_from_date( mysql2date( 'Y-m-d H:i:s', $entry['post_modified'] ), 'Ymd\TH:i:s');3628 $post_date_gmt = $this->_convert_date_gmt( $entry['post_date'] ); 3629 $post_modified_gmt = $this->_convert_date_gmt( $entry['post_modified'] ); 3550 3630 } 3551 3631 3552 3632 $categories = array(); … … 3584 3664 $post_format = 'standard'; 3585 3665 3586 3666 $struct[] = array( 3587 'dateCreated' => new IXR_Date($post_date),3667 'dateCreated' => $post_date, 3588 3668 'userid' => $entry['post_author'], 3589 3669 'postid' => (string) $entry['ID'], 3590 3670 'description' => $post['main'], … … 3603 3683 'wp_password' => $entry['post_password'], 3604 3684 'wp_author_id' => (string) $author->ID, 3605 3685 'wp_author_display_name' => $author->display_name, 3606 'date_created_gmt' => new IXR_Date($post_date_gmt),3686 'date_created_gmt' => $post_date_gmt, 3607 3687 'post_status' => $entry['post_status'], 3608 3688 'custom_fields' => $this->get_custom_fields($entry['ID']), 3609 3689 'wp_post_format' => $post_format, 3610 'date_modified' => new IXR_Date( $post_modified ),3611 'date_modified_gmt' => new IXR_Date( $post_modified_gmt )3690 'date_modified' => $post_modified, 3691 'date_modified_gmt' => $post_modified_gmt 3612 3692 ); 3613 3693 3694 $entry_index = count( $struct ) - 1; 3695 if( current_theme_supports( 'post-thumbnails' ) ) { 3696 $struct[ $entry_index ][ 'wp_featured_image' ] = get_post_thumbnail_id( $entry['ID'] ); 3697 } 3614 3698 } 3615 3699 3616 3700 $recent_posts = array(); … … 3783 3867 if ( !current_user_can( 'edit_post', $entry['ID'] ) ) 3784 3868 continue; 3785 3869 3786 $post_date = mysql2date('Ymd\TH:i:s', $entry['post_date'], false);3787 $post_date_gmt = mysql2date('Ymd\TH:i:s', $entry['post_date_gmt'], false);3870 $post_date = $this->_convert_date( $entry['post_date'] ); 3871 $post_date_gmt = $this->_convert_date( $entry['post_date_gmt'] ); 3788 3872 3789 3873 // For drafts use the GMT version of the date 3790 if ( $entry['post_status'] == 'draft')3791 $post_date_gmt = get_gmt_from_date( mysql2date( 'Y-m-d H:i:s', $entry['post_date'] ), 'Ymd\TH:i:s');3874 if ( in_array( $entry['post_status'], array( 'draft', 'pending', 'auto-draft' ) ) ) 3875 $post_date_gmt = $this->_convert_date_gmt( $entry['post_date'] ); 3792 3876 3793 3877 $struct[] = array( 3794 'dateCreated' => new IXR_Date($post_date),3878 'dateCreated' => $post_date, 3795 3879 'userid' => $entry['post_author'], 3796 3880 'postid' => (string) $entry['ID'], 3797 3881 'title' => $entry['post_title'], 3798 3882 'post_status' => $entry['post_status'], 3799 'date_created_gmt' => new IXR_Date($post_date_gmt)3883 'date_created_gmt' => $post_date_gmt 3800 3884 ); 3801 3885 3802 3886 }