Add wp_upload_bits(). Attempt to fix mw_newMediaObject().
git-svn-id: http://svn.automattic.com/wordpress/trunk@3255 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
parent
9de108b9bf
commit
30a8b614b2
|
@ -778,4 +778,37 @@ function get_post_mime_type($ID = '') {
|
||||||
function get_attached_file($attachment_id) {
|
function get_attached_file($attachment_id) {
|
||||||
return get_post_meta($attachment_id, '_wp_attached_file', true);
|
return get_post_meta($attachment_id, '_wp_attached_file', true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function wp_upload_bits($name, $type, $bits) {
|
||||||
|
if ( empty($name) )
|
||||||
|
return array('error' => "Empty filename");
|
||||||
|
|
||||||
|
$upload = wp_upload_dir();
|
||||||
|
|
||||||
|
if ( $upload['error'] !== false )
|
||||||
|
return $upload;
|
||||||
|
|
||||||
|
$number = '';
|
||||||
|
$filename = $name;
|
||||||
|
while ( file_exists($upload['path'] . "/$filename") )
|
||||||
|
$filename = str_replace("$number.$ext", ++$number . ".$ext", $filename);
|
||||||
|
|
||||||
|
$new_file = $uploads['path'] . "/$filename";
|
||||||
|
$ifp = @ fopen($new_file, 'wb');
|
||||||
|
if ( ! $ifp )
|
||||||
|
return array('error' => "Could not write file $new_file.");
|
||||||
|
|
||||||
|
$success = @ fwrite($ifp, $bits);
|
||||||
|
fclose($ifp);
|
||||||
|
// Set correct file permissions
|
||||||
|
$stat = @ stat(dirname($new_file));
|
||||||
|
$perms = $stat['mode'] & 0000777;
|
||||||
|
@ chmod($new_file, $perms);
|
||||||
|
|
||||||
|
// Compute the URL
|
||||||
|
$url = $upload['url'] . "/$filename";
|
||||||
|
|
||||||
|
return array('file' => $new_file, 'url' => $url);
|
||||||
|
}
|
||||||
|
|
||||||
?>
|
?>
|
||||||
|
|
52
xmlrpc.php
52
xmlrpc.php
|
@ -839,67 +839,27 @@ class wp_xmlrpc_server extends IXR_Server {
|
||||||
$type = $data['type'];
|
$type = $data['type'];
|
||||||
$bits = $data['bits'];
|
$bits = $data['bits'];
|
||||||
|
|
||||||
$file_realpath = get_settings('fileupload_realpath');
|
|
||||||
$file_url = get_settings('fileupload_url');
|
|
||||||
|
|
||||||
logIO('O', '(MW) Received '.strlen($bits).' bytes');
|
logIO('O', '(MW) Received '.strlen($bits).' bytes');
|
||||||
|
|
||||||
if (!$this->login_pass_ok($user_login, $user_pass)) {
|
if ( !$this->login_pass_ok($user_login, $user_pass) )
|
||||||
return $this->error;
|
return $this->error;
|
||||||
}
|
|
||||||
|
|
||||||
$user_data = get_userdatabylogin($user_login);
|
|
||||||
|
|
||||||
if(!get_settings('use_fileupload')) {
|
|
||||||
// Uploads not allowed
|
|
||||||
logIO('O', '(MW) Uploads not allowed');
|
|
||||||
$this->error = new IXR_Error(405, 'No uploads allowed for this site.');
|
|
||||||
return $this->error;
|
|
||||||
}
|
|
||||||
|
|
||||||
$user = new WP_User($user_login);
|
$user = new WP_User($user_login);
|
||||||
|
|
||||||
if ( !$user->has_cap('upload_files') ) {
|
if ( !$user->has_cap('upload_files') ) {
|
||||||
logIO('O', '(MW) User does not have upload_files capability');
|
logIO('O', '(MW) User does not have upload_files capability');
|
||||||
$this->error = new IXR_Error(401, 'You are not allowed to upload files to this site.');
|
$this->error = new IXR_Error(401, 'You are not allowed to upload files to this site.');
|
||||||
return $this->error;
|
return $this->error;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(trim($file_realpath) == '' || trim($file_url) == '' ) {
|
$upload = wp_upload_bits($name, $type, $bits);
|
||||||
// WordPress is not correctly configured
|
if ( $upload['error'] !== false ) {
|
||||||
logIO('O', '(MW) Bad configuration. Real/URL path not defined');
|
logIO('O', '(MW) Could not write file '.$name);
|
||||||
$this->error = new IXR_Error(500, 'Please configure WordPress with valid paths for file upload.');
|
|
||||||
return $this->error;
|
|
||||||
}
|
|
||||||
|
|
||||||
$prefix = '/';
|
|
||||||
|
|
||||||
if(!empty($name)) {
|
|
||||||
// Create the path
|
|
||||||
$localpath = $file_realpath.$prefix.$name;
|
|
||||||
$url = $file_url.$prefix.$name;
|
|
||||||
|
|
||||||
if (mkdir_p(dirname($localpath))) {
|
|
||||||
|
|
||||||
/* encode & write data (binary) */
|
|
||||||
$ifp = fopen($localpath, 'wb');
|
|
||||||
$success = fwrite($ifp, $bits);
|
|
||||||
fclose($ifp);
|
|
||||||
@chmod($localpath, 0666);
|
|
||||||
|
|
||||||
if($success) {
|
|
||||||
$resp = array('url' => $url);
|
|
||||||
return $resp;
|
|
||||||
} else {
|
|
||||||
logIO('O', '(MW) Could not write file '.$name.' to '.$localpath);
|
|
||||||
return new IXR_Error(500, 'Could not write file '.$name);
|
return new IXR_Error(500, 'Could not write file '.$name);
|
||||||
}
|
}
|
||||||
|
|
||||||
} else {
|
return array('url' => $upload['url']);
|
||||||
return new IXR_Error(500, 'Could not create directories for '.$name);
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/* MovableType API functions
|
/* MovableType API functions
|
||||||
|
|
Loading…
Reference in New Issue