summaryrefslogtreecommitdiffstats
path: root/xmlrpc.php
diff options
context:
space:
mode:
authordonncha <donncha@7be80a69-a1ef-0310-a953-fb0f7c49ff36>2006-12-01 12:27:29 +0000
committerdonncha <donncha@7be80a69-a1ef-0310-a953-fb0f7c49ff36>2006-12-01 12:27:29 +0000
commitaae5b160f307adf0703ae8f7c2b158b91570ec95 (patch)
treeba0d1eee6e2eedfe3fd0a693d773162ab9dc8a67 /xmlrpc.php
parent9415bbca12c01c39da58e0ed2c4e6b44ff833e5d (diff)
downloadwordpress-mu-aae5b160f307adf0703ae8f7c2b158b91570ec95.tar.gz
wordpress-mu-aae5b160f307adf0703ae8f7c2b158b91570ec95.tar.xz
wordpress-mu-aae5b160f307adf0703ae8f7c2b158b91570ec95.zip
WP Merge to 4578, except for script-loader
git-svn-id: http://svn.automattic.com/wordpress-mu/trunk@817 7be80a69-a1ef-0310-a953-fb0f7c49ff36
Diffstat (limited to 'xmlrpc.php')
-rw-r--r--xmlrpc.php33
1 files changed, 33 insertions, 0 deletions
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 ) );
}