xmlrpc updates from Joseph Scott.
git-svn-id: http://svn.automattic.com/wordpress/trunk@4961 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
parent
b7f6a96abb
commit
7f1945b310
|
@ -1115,18 +1115,29 @@ function wp_upload_bits($name, $type, $bits, $overwrite = false) {
|
||||||
$ext = '';
|
$ext = '';
|
||||||
else
|
else
|
||||||
$ext = ".$ext";
|
$ext = ".$ext";
|
||||||
while ( file_exists($upload['path'] . "/$filename") && !$overwrite ) {
|
while ( file_exists($upload['path'] . "/$filename") ) {
|
||||||
if ( '' == "$number$ext" )
|
if ( '' == "$number$ext" )
|
||||||
$filename = $filename . ++$number . $ext;
|
$filename = $filename . ++$number . $ext;
|
||||||
else
|
else
|
||||||
$filename = str_replace("$number$ext", ++$number . $ext, $filename);
|
$filename = str_replace("$number$ext", ++$number . $ext, $filename);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// If we are asked to over write the file then make sure
|
||||||
|
// the $name has the complete path and is writable.
|
||||||
|
if($overwrite) {
|
||||||
|
if(!is_writable($name)) {
|
||||||
|
return(array("error" => __("Can not over write file.")));
|
||||||
|
}
|
||||||
|
$new_file = $name;
|
||||||
|
$filename = basename($name);
|
||||||
|
}
|
||||||
|
else {
|
||||||
$new_file = $upload['path'] . "/$filename";
|
$new_file = $upload['path'] . "/$filename";
|
||||||
if ( ! wp_mkdir_p( dirname($new_file) ) ) {
|
if ( ! wp_mkdir_p( dirname($new_file) ) ) {
|
||||||
$message = sprintf(__('Unable to create directory %s. Is its parent directory writable by the server?'), dirname($new_file));
|
$message = sprintf(__('Unable to create directory %s. Is its parent directory writable by the server?'), dirname($new_file));
|
||||||
return array('error' => $message);
|
return array('error' => $message);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
$ifp = @ fopen($new_file, 'wb');
|
$ifp = @ fopen($new_file, 'wb');
|
||||||
if ( ! $ifp )
|
if ( ! $ifp )
|
||||||
|
@ -1140,8 +1151,11 @@ function wp_upload_bits($name, $type, $bits, $overwrite = false) {
|
||||||
$perms = $perms & 0000666;
|
$perms = $perms & 0000666;
|
||||||
@ chmod($new_file, $perms);
|
@ chmod($new_file, $perms);
|
||||||
|
|
||||||
// Compute the URL
|
// Compute the URL if this is a new file.
|
||||||
$url = $upload['url'] . "/$filename";
|
$url = $upload['url'] . "/$filename";
|
||||||
|
if($overwrite) {
|
||||||
|
$url = $name;
|
||||||
|
}
|
||||||
|
|
||||||
return array('file' => $new_file, 'url' => $url, 'error' => false);
|
return array('file' => $new_file, 'url' => $url, 'error' => false);
|
||||||
}
|
}
|
||||||
|
|
43
xmlrpc.php
43
xmlrpc.php
|
@ -149,7 +149,7 @@ class wp_xmlrpc_server extends IXR_Server {
|
||||||
function escape(&$array) {
|
function escape(&$array) {
|
||||||
global $wpdb;
|
global $wpdb;
|
||||||
|
|
||||||
if(is_string($array)) {
|
if(!is_array($array)) {
|
||||||
return($wpdb->escape($array));
|
return($wpdb->escape($array));
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
@ -1100,7 +1100,7 @@ class wp_xmlrpc_server extends IXR_Server {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Only set a post parent if one was given.
|
// Only set a post parent if one was given.
|
||||||
if(!empty($content_struct["wp_page_parent_id"])) {
|
if(isset($content_struct["wp_page_parent_id"])) {
|
||||||
$post_parent = $content_struct["wp_page_parent_id"];
|
$post_parent = $content_struct["wp_page_parent_id"];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1167,9 +1167,9 @@ class wp_xmlrpc_server extends IXR_Server {
|
||||||
if ( is_array($to_ping) )
|
if ( is_array($to_ping) )
|
||||||
$to_ping = implode(' ', $to_ping);
|
$to_ping = implode(' ', $to_ping);
|
||||||
|
|
||||||
$comment_status = (!isset($content_struct['mt_allow_comments'])) ?
|
if(isset($content_struct["mt_allow_comments"])) {
|
||||||
get_option('default_comment_status')
|
$comment_status = $content_struct["mt_allow_comments"];
|
||||||
: $content_struct['mt_allow_comments'];
|
}
|
||||||
|
|
||||||
// Do some timestamp voodoo
|
// Do some timestamp voodoo
|
||||||
$dateCreatedd = $content_struct['dateCreated'];
|
$dateCreatedd = $content_struct['dateCreated'];
|
||||||
|
@ -1387,6 +1387,25 @@ class wp_xmlrpc_server extends IXR_Server {
|
||||||
$overwrite = false;
|
$overwrite = false;
|
||||||
if(!empty($data["overwrite"]) && ($data["overwrite"] == true)) {
|
if(!empty($data["overwrite"]) && ($data["overwrite"] == true)) {
|
||||||
$overwrite = true;
|
$overwrite = true;
|
||||||
|
|
||||||
|
// If the file isn't writable then error out now.
|
||||||
|
if(!is_writable($data["name"])) {
|
||||||
|
return(new IXR_Error(500, "File is not writable, over write failed."));
|
||||||
|
}
|
||||||
|
|
||||||
|
// We now know the file is good so don't use the sanitized name.
|
||||||
|
$name = $data["name"];
|
||||||
|
|
||||||
|
// Get postmeta info on the object.
|
||||||
|
$old_meta = $wpdb->get_row("
|
||||||
|
SELECT *
|
||||||
|
FROM {$wpdb->postmeta}
|
||||||
|
WHERE meta_key = '_wp_attached_file'
|
||||||
|
AND meta_value = '{$name}'
|
||||||
|
");
|
||||||
|
|
||||||
|
// Get post info on the object.
|
||||||
|
$old_post = get_post($old_meta->post_id);
|
||||||
}
|
}
|
||||||
|
|
||||||
logIO('O', '(MW) Received '.strlen($bits).' bytes');
|
logIO('O', '(MW) Received '.strlen($bits).' bytes');
|
||||||
|
@ -1421,12 +1440,20 @@ class wp_xmlrpc_server extends IXR_Server {
|
||||||
'guid' => $upload[ 'url' ]
|
'guid' => $upload[ 'url' ]
|
||||||
);
|
);
|
||||||
|
|
||||||
// Only make a database entry if this is a new file.
|
// If we are over writing then set the correct post_id and URL
|
||||||
if(!$overwrite) {
|
// instead of getting new ones.
|
||||||
|
if($overwrite) {
|
||||||
|
$post_id = $old_meta->post_id;
|
||||||
|
$attachment["post_parent"] = $old_meta->post_id;
|
||||||
|
$attachment["ID"] = $old_meta->post_id;
|
||||||
|
|
||||||
|
$upload["url"] = $old_post->guid;
|
||||||
|
$attachment["guid"] = $old_post->guid;
|
||||||
|
}
|
||||||
|
|
||||||
// Save the data
|
// Save the data
|
||||||
$id = wp_insert_attachment( $attachment, $upload[ 'file' ], $post_id );
|
$id = wp_insert_attachment( $attachment, $upload[ 'file' ], $post_id );
|
||||||
wp_update_attachment_metadata( $id, wp_generate_attachment_metadata( $id, $upload['file'] ) );
|
wp_update_attachment_metadata( $id, wp_generate_attachment_metadata( $id, $upload['file'] ) );
|
||||||
}
|
|
||||||
|
|
||||||
return apply_filters( 'wp_handle_upload', array( 'file' => $upload[ 'file' ], 'url' => $upload[ 'url' ], 'type' => $type ) );
|
return apply_filters( 'wp_handle_upload', array( 'file' => $upload[ 'file' ], 'url' => $upload[ 'url' ], 'type' => $type ) );
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue