From aae5b160f307adf0703ae8f7c2b158b91570ec95 Mon Sep 17 00:00:00 2001 From: donncha Date: Fri, 1 Dec 2006 12:27:29 +0000 Subject: WP Merge to 4578, except for script-loader git-svn-id: http://svn.automattic.com/wordpress-mu/trunk@817 7be80a69-a1ef-0310-a953-fb0f7c49ff36 --- xmlrpc.php | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) (limited to 'xmlrpc.php') diff --git a/xmlrpc.php b/xmlrpc.php index 91fb661..6718c04 100644 --- a/xmlrpc.php +++ b/xmlrpc.php @@ -405,6 +405,7 @@ class wp_xmlrpc_server extends IXR_Server { if (!$post_ID) { return new IXR_Error(500, 'Sorry, your entry could not be posted. Something wrong happened.'); } + $this->attach_uploads( $post_ID, $post_content ); logIO('O', "Posted ! ID: $post_ID"); @@ -454,6 +455,7 @@ class wp_xmlrpc_server extends IXR_Server { if (!$result) { return new IXR_Error(500, 'For some strange yet very annoying reason, this post could not be edited.'); } + $this->attach_uploads( $ID, $post_content ); return true; } @@ -574,11 +576,26 @@ class wp_xmlrpc_server extends IXR_Server { return new IXR_Error(500, 'Sorry, your entry could not be posted. Something wrong happened.'); } + $this->attach_uploads( $post_ID, $post_content ); + logIO('O', "Posted ! ID: $post_ID"); return strval($post_ID); } + function attach_uploads( $post_ID, $post_content ) { + global $wpdb; + + // find any unattached files + $attachments = $wpdb->get_results( "SELECT ID, guid FROM {$wpdb->posts} WHERE post_parent = '-1' AND post_type = 'attachment'" ); + if( is_array( $attachments ) ) { + foreach( $attachments as $file ) { + if( strpos( $post_content, $file->guid ) !== false ) { + $wpdb->query( "UPDATE {$wpdb->posts} SET post_parent = '$post_ID' WHERE ID = '{$file->ID}'" ); + } + } + } + } /* metaweblog.editPost ...edits a post */ function mw_editPost($args) { @@ -653,6 +670,7 @@ class wp_xmlrpc_server extends IXR_Server { if (!$result) { return new IXR_Error(500, 'Sorry, your entry could not be edited. Something wrong happened.'); } + $this->attach_uploads( $ID, $post_content ); logIO('O',"(MW) Edited ! ID: $post_ID"); @@ -851,6 +869,21 @@ class wp_xmlrpc_server extends IXR_Server { logIO('O', '(MW) Could not write file '.$name); return new IXR_Error(500, 'Could not write file '.$name); } + // Construct the attachment array + // attach to post_id -1 + $post_id = -1; + $attachment = array( + 'post_title' => $name, + 'post_content' => '', + 'post_type' => 'attachment', + 'post_parent' => $post_id, + 'post_mime_type' => $type, + 'guid' => $upload[ 'url' ] + ); + // Save the data + $id = wp_insert_attachment($attachment, $upload[ 'file' ], $post_id); + add_post_meta($id, '_wp_attachment_metadata', array()); + return apply_filters( 'wp_handle_upload', array( 'file' => $upload[ 'file' ], 'url' => $upload[ 'url' ], 'type' => $type ) ); } -- cgit