Ticket #3499: xmlrpc-attachment.diff
| File xmlrpc-attachment.diff, 7.1 KB (added by , 19 years ago) |
|---|
-
wp-includes/functions-post.php
386 386 return $post; 387 387 } 388 388 389 function wp_get_attachment_metadata( $post_id, $unfiltered = false ) { 390 $post_id = (int) $post_id; 391 392 $data = get_post_meta( $post_id, '_wp_attachment_metadata', true ); 393 if ( $unfiltered ) 394 return $data; 395 return apply_filters( 'wp_get_attachment_metadata', $data, $post_id ); 396 } 397 398 function wp_update_attachment_metadata( $post_id, $data ) { 399 if ( !get_post( $post_id ) ) 400 return false; 401 402 $old_data = wp_get_attachment_metadata( $post_id, true ); 403 404 $data = apply_filters( 'wp_update_attachment_metadata', $data, $post_id ); 405 406 if ( $old_data ) 407 return update_post_meta( $post_id, '_wp_attachment_metadata', $data, $old_data ); 408 else 409 return add_post_meta( $post_id, '_wp_attachment_metadata', $data ); 410 } 411 389 412 function wp_get_single_post($postid = 0, $mode = OBJECT) { 390 413 global $wpdb; 391 414 -
xmlrpc.php
32 32 exit; 33 33 } 34 34 35 include_once(ABSPATH . 'wp-admin/admin-functions.php'); 35 36 include_once(ABSPATH . WPINC . '/class-IXR.php'); 36 37 37 38 // Turn off all warnings and errors. … … 396 397 return new IXR_Error(500, 'Sorry, your entry could not be posted. Something wrong happened.'); 397 398 } 398 399 400 $this->attach_uploads( $post_ID, $post_content ); 401 399 402 logIO('O', "Posted ! ID: $post_ID"); 400 403 401 404 return $post_ID; … … 445 448 return new IXR_Error(500, 'For some strange yet very annoying reason, this post could not be edited.'); 446 449 } 447 450 451 $this->attach_uploads( $ID, $post_content ); 452 448 453 return true; 449 454 } 450 455 … … 564 569 return new IXR_Error(500, 'Sorry, your entry could not be posted. Something wrong happened.'); 565 570 } 566 571 572 $this->attach_uploads( $post_ID, $post_content ); 573 567 574 logIO('O', "Posted ! ID: $post_ID"); 568 575 569 576 return strval($post_ID); 570 577 } 571 578 572 573 579 /* metaweblog.editPost ...edits a post */ 574 580 function mw_editPost($args) { 575 581 … … 644 650 return new IXR_Error(500, 'Sorry, your entry could not be edited. Something wrong happened.'); 645 651 } 646 652 653 $this->attach_uploads( $ID, $post_content ); 654 647 655 logIO('O',"(MW) Edited ! ID: $post_ID"); 648 656 649 657 return true; … … 833 841 return $this->error; 834 842 } 835 843 844 if ( $upload_err = apply_filters( "pre_upload_error", false ) ) 845 return new IXR_Error(500, $upload_err); 846 836 847 $upload = wp_upload_bits($name, $type, $bits); 837 848 if ( ! empty($upload['error']) ) { 838 849 logIO('O', '(MW) Could not write file '.$name); 839 850 return new IXR_Error(500, 'Could not write file '.$name); 840 851 } 841 842 return array('url' => $upload['url']); 852 // Construct the attachment array 853 // attach to post_id -1 854 $post_id = -1; 855 $attachment = array( 856 'post_title' => $name, 857 'post_content' => '', 858 'post_status' => 'attachment', 859 'post_parent' => $post_id, 860 'post_mime_type' => $type, 861 'guid' => $upload[ 'url' ] 862 ); 863 // Save the data 864 $id = wp_insert_attachment( $attachment, $upload[ 'file' ], $post_id ); 865 wp_update_attachment_metadata( $id, wp_generate_attachment_metadata( $id, $upload['file'] ) ); 866 867 return apply_filters( 'wp_handle_upload', array( 'file' => $upload[ 'file' ], 'url' => $upload[ 'url' ], 'type' => $type ) ); 843 868 } 844 869 870 function attach_uploads( $post_ID, $post_content ) { 871 global $wpdb; 872 // find any unattached files 873 $attachments = $wpdb->get_results( "SELECT ID, guid FROM {$wpdb->posts} WHERE post_parent = '-1' AND post_status = 'attachment'" ); 874 if( is_array( $attachments ) ) { 875 foreach( $attachments as $file ) { 876 if( strpos( $post_content, $file->guid ) !== false ) { 877 $wpdb->query( "UPDATE {$wpdb->posts} SET post_parent = '$post_ID' WHERE ID = '{$file->ID}'" ); 878 } 879 } 880 } 881 } 845 882 846 883 /* MovableType API functions 847 884 * specs on http://www.movabletype.org/docs/mtmanual_programmatic.html … … 1215 1252 1216 1253 $commentdata = compact('comment_post_ID', 'comment_author', 'comment_author_url', 'comment_content', 'comment_type'); 1217 1254 1218 wp_new_comment($commentdata);1219 do_action('pingback_post', $ wpdb->insert_id);1255 $comment_ID = wp_new_comment($commentdata); 1256 do_action('pingback_post', $comment_ID); 1220 1257 1221 1258 return "Pingback from $pagelinkedfrom to $pagelinkedto registered. Keep the web talking! :-)"; 1222 1259 } -
wp-admin/inline-uploading.php
74 74 75 75 // Save the data 76 76 $id = wp_insert_attachment($attachment, $file, $post); 77 wp_update_attachment_metadata($id, wp_generate_attachment_metadata($id, $file)); 77 78 78 if ( preg_match('!^image/!', $attachment['post_mime_type']) ) {79 // Generate the attachment's postmeta.80 $imagesize = getimagesize($file);81 $imagedata['width'] = $imagesize['0'];82 $imagedata['height'] = $imagesize['1'];83 list($uwidth, $uheight) = get_udims($imagedata['width'], $imagedata['height']);84 $imagedata['hwstring_small'] = "height='$uheight' width='$uwidth'";85 $imagedata['file'] = $file;86 87 add_post_meta($id, '_wp_attachment_metadata', $imagedata);88 89 if ( $imagedata['width'] * $imagedata['height'] < 3 * 1024 * 1024 ) {90 if ( $imagedata['width'] > 128 && $imagedata['width'] >= $imagedata['height'] * 4 / 3 )91 $thumb = wp_create_thumbnail($file, 128);92 elseif ( $imagedata['height'] > 96 )93 $thumb = wp_create_thumbnail($file, 96);94 95 if ( @file_exists($thumb) ) {96 $newdata = $imagedata;97 $newdata['thumb'] = basename($thumb);98 update_post_meta($id, '_wp_attachment_metadata', $newdata, $imagedata);99 } else {100 $error = $thumb;101 }102 }103 } else {104 add_post_meta($id, '_wp_attachment_metadata', array());105 }106 107 79 wp_redirect(basename(__FILE__) . "?post=$post&all=$all&action=view&start=0"); 108 80 die(); 109 81 -
wp-admin/admin-functions.php
1888 1888 return array((int) ($width / $height * 96), 96); 1889 1889 } 1890 1890 1891 function wp_generate_attachment_metadata( $attachment_id, $file ) { 1892 $attachment = get_post( $attachment_id ); 1893 1894 $metadata = array(); 1895 if ( preg_match('!^image/!', get_post_mime_type( $attachment )) ) { 1896 $imagesize = getimagesize($file); 1897 $metadata['width'] = $imagesize['0']; 1898 $metadata['height'] = $imagesize['1']; 1899 list($uwidth, $uheight) = get_udims($metadata['width'], $metadata['height']); 1900 $metadata['hwstring_small'] = "height='$uheight' width='$uwidth'"; 1901 $metadata['file'] = $file; 1902 1903 if ( $metadata['width'] * $metadata['height'] < 3 * 1024 * 1024 ) { 1904 if ( $metadata['width'] > 128 && $metadata['width'] >= $metadata['height'] * 4 / 3 ) 1905 $thumb = wp_create_thumbnail($file, 128); 1906 elseif ( $metadata['height'] > 96 ) 1907 $thumb = wp_create_thumbnail($file, 96); 1908 1909 if ( @file_exists($thumb) ) 1910 $metadata['thumb'] = basename($thumb); 1911 } 1912 } 1913 return apply_filters( 'wp_generate_attachment_metadata', $metadata ); 1914 } 1915 1891 1916 ?>