| 1 | Index: xmlrpc.php |
|---|
| 2 | =================================================================== |
|---|
| 3 | --- xmlrpc.php (revision 4534) |
|---|
| 4 | +++ xmlrpc.php (working copy) |
|---|
| 5 | @@ -395,6 +395,7 @@ |
|---|
| 6 | if (!$post_ID) { |
|---|
| 7 | return new IXR_Error(500, 'Sorry, your entry could not be posted. Something wrong happened.'); |
|---|
| 8 | } |
|---|
| 9 | + $this->attach_uploads( $post_ID, $post_content ); |
|---|
| 10 | |
|---|
| 11 | logIO('O', "Posted ! ID: $post_ID"); |
|---|
| 12 | |
|---|
| 13 | @@ -444,6 +445,7 @@ |
|---|
| 14 | if (!$result) { |
|---|
| 15 | return new IXR_Error(500, 'For some strange yet very annoying reason, this post could not be edited.'); |
|---|
| 16 | } |
|---|
| 17 | + $this->attach_uploads( $ID, $post_content ); |
|---|
| 18 | |
|---|
| 19 | return true; |
|---|
| 20 | } |
|---|
| 21 | @@ -564,12 +566,27 @@ |
|---|
| 22 | return new IXR_Error(500, 'Sorry, your entry could not be posted. Something wrong happened.'); |
|---|
| 23 | } |
|---|
| 24 | |
|---|
| 25 | + $this->attach_uploads( $post_ID, $post_content ); |
|---|
| 26 | + |
|---|
| 27 | logIO('O', "Posted ! ID: $post_ID"); |
|---|
| 28 | |
|---|
| 29 | return strval($post_ID); |
|---|
| 30 | } |
|---|
| 31 | |
|---|
| 32 | + function attach_uploads( $post_ID, $post_content ) { |
|---|
| 33 | + global $wpdb; |
|---|
| 34 | |
|---|
| 35 | + // find any unattached files |
|---|
| 36 | + $attachments = $wpdb->get_results( "SELECT ID, guid FROM {$wpdb->posts} WHERE post_parent = '-1' AND post_type = 'attachment'" ); |
|---|
| 37 | + if( is_array( $attachments ) ) { |
|---|
| 38 | + foreach( $attachments as $file ) { |
|---|
| 39 | + if( strpos( $post_content, $file->guid ) !== false ) { |
|---|
| 40 | + $wpdb->query( "UPDATE {$wpdb->posts} SET post_parent = '$post_ID' WHERE ID = '{$file->ID}'" ); |
|---|
| 41 | + } |
|---|
| 42 | + } |
|---|
| 43 | + } |
|---|
| 44 | + } |
|---|
| 45 | + |
|---|
| 46 | /* metaweblog.editPost ...edits a post */ |
|---|
| 47 | function mw_editPost($args) { |
|---|
| 48 | |
|---|
| 49 | @@ -643,6 +660,7 @@ |
|---|
| 50 | if (!$result) { |
|---|
| 51 | return new IXR_Error(500, 'Sorry, your entry could not be edited. Something wrong happened.'); |
|---|
| 52 | } |
|---|
| 53 | + $this->attach_uploads( $ID, $post_content ); |
|---|
| 54 | |
|---|
| 55 | logIO('O',"(MW) Edited ! ID: $post_ID"); |
|---|
| 56 | |
|---|
| 57 | @@ -817,7 +835,7 @@ |
|---|
| 58 | $user_pass = $wpdb->escape($args[2]); |
|---|
| 59 | $data = $args[3]; |
|---|
| 60 | |
|---|
| 61 | - $name = $data['name']; |
|---|
| 62 | + $name = sanitize_file( $data['name'] ); |
|---|
| 63 | $type = $data['type']; |
|---|
| 64 | $bits = $data['bits']; |
|---|
| 65 | |
|---|
| 66 | @@ -841,7 +859,22 @@ |
|---|
| 67 | logIO('O', '(MW) Could not write file '.$name); |
|---|
| 68 | return new IXR_Error(500, 'Could not write file '.$name); |
|---|
| 69 | } |
|---|
| 70 | - return apply_filters( 'wp_handle_upload', array( 'file' => $name, 'url' => $upload[ 'url' ], 'type' => $type ) ); |
|---|
| 71 | + // Construct the attachment array |
|---|
| 72 | + // attach to post_id -1 |
|---|
| 73 | + $post_id = -1; |
|---|
| 74 | + $attachment = array( |
|---|
| 75 | + 'post_title' => $name, |
|---|
| 76 | + 'post_content' => '', |
|---|
| 77 | + 'post_type' => 'attachment', |
|---|
| 78 | + 'post_parent' => $post_id, |
|---|
| 79 | + 'post_mime_type' => $type, |
|---|
| 80 | + 'guid' => $upload[ 'url' ] |
|---|
| 81 | + ); |
|---|
| 82 | + // Save the data |
|---|
| 83 | + $id = wp_insert_attachment($attachment, $upload[ 'file' ], $post_id); |
|---|
| 84 | + add_post_meta($id, '_wp_attachment_metadata', array()); |
|---|
| 85 | + |
|---|
| 86 | + return apply_filters( 'wp_handle_upload', array( 'file' => $upload[ 'file' ], 'url' => $upload[ 'url' ], 'type' => $type ) ); |
|---|
| 87 | } |
|---|
| 88 | |
|---|
| 89 | |
|---|