WordPress.org

Make WordPress Core

Changeset 4961


Ignore:
Timestamp:
03/03/2007 04:56:46 PM (11 years ago)
Author:
ryan
Message:

xmlrpc updates from Joseph Scott.

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-includes/functions.php

    r4951 r4961  
    11161116    else
    11171117        $ext = ".$ext";
    1118     while ( file_exists($upload['path'] . "/$filename") && !$overwrite ) {
     1118    while ( file_exists($upload['path'] . "/$filename") ) {
    11191119        if ( '' == "$number$ext" )
    11201120            $filename = $filename . ++$number . $ext;
     
    11231123    }
    11241124
    1125     $new_file = $upload['path'] . "/$filename";
    1126     if ( ! wp_mkdir_p( dirname($new_file) ) ) {
    1127         $message = sprintf(__('Unable to create directory %s. Is its parent directory writable by the server?'), dirname($new_file));
    1128         return array('error' => $message);
     1125    // If we are asked to over write the file then make sure
     1126    // the $name has the complete path and is writable.
     1127    if($overwrite) {
     1128        if(!is_writable($name)) {
     1129            return(array("error" => __("Can not over write file.")));
     1130        }
     1131        $new_file = $name;
     1132        $filename = basename($name);
     1133    }
     1134    else {
     1135        $new_file = $upload['path'] . "/$filename";
     1136        if ( ! wp_mkdir_p( dirname($new_file) ) ) {
     1137            $message = sprintf(__('Unable to create directory %s. Is its parent directory writable by the server?'), dirname($new_file));
     1138            return array('error' => $message);
     1139        }
    11291140    }
    11301141
     
    11411152    @ chmod($new_file, $perms);
    11421153
    1143     // Compute the URL
     1154    // Compute the URL if this is a new file.
    11441155    $url = $upload['url'] . "/$filename";
     1156    if($overwrite) {
     1157        $url = $name;
     1158    }
    11451159
    11461160    return array('file' => $new_file, 'url' => $url, 'error' => false);
  • trunk/xmlrpc.php

    r4953 r4961  
    150150        global $wpdb;
    151151
    152         if(is_string($array)) {
     152        if(!is_array($array)) {
    153153            return($wpdb->escape($array));
    154154        }
     
    11011101
    11021102        // Only set a post parent if one was given.
    1103         if(!empty($content_struct["wp_page_parent_id"])) {
     1103        if(isset($content_struct["wp_page_parent_id"])) {
    11041104            $post_parent = $content_struct["wp_page_parent_id"];
    11051105        }
     
    11671167      if ( is_array($to_ping) )
    11681168        $to_ping = implode(' ', $to_ping);
     1169
     1170      if(isset($content_struct["mt_allow_comments"])) {
     1171        $comment_status = $content_struct["mt_allow_comments"];
     1172      }
    11691173     
    1170       $comment_status = (!isset($content_struct['mt_allow_comments'])) ?
    1171         get_option('default_comment_status')
    1172         : $content_struct['mt_allow_comments'];
    1173 
    11741174      // Do some timestamp voodoo
    11751175      $dateCreatedd = $content_struct['dateCreated'];
     
    13881388        if(!empty($data["overwrite"]) && ($data["overwrite"] == true)) {
    13891389            $overwrite = true;
     1390
     1391            // If the file isn't writable then error out now.
     1392            if(!is_writable($data["name"])) {
     1393                return(new IXR_Error(500, "File is not writable, over write failed."));
     1394            }
     1395
     1396            // We now know the file is good so don't use the sanitized name.
     1397            $name = $data["name"];
     1398
     1399            // Get postmeta info on the object.
     1400            $old_meta = $wpdb->get_row("
     1401                SELECT *
     1402                FROM {$wpdb->postmeta}
     1403                WHERE meta_key = '_wp_attached_file'
     1404                    AND meta_value = '{$name}'
     1405            ");
     1406
     1407            // Get post info on the object.
     1408            $old_post = get_post($old_meta->post_id);
    13901409        }
    13911410
     
    14221441        );
    14231442
    1424         // Only make a database entry if this is a new file.
    1425         if(!$overwrite) {
    1426             // Save the data
    1427             $id = wp_insert_attachment( $attachment, $upload[ 'file' ], $post_id );
    1428             wp_update_attachment_metadata( $id, wp_generate_attachment_metadata( $id, $upload['file'] ) );
    1429         }
     1443        // If we are over writing then set the correct post_id and URL
     1444        // instead of getting new ones.
     1445        if($overwrite) {
     1446            $post_id                    = $old_meta->post_id;
     1447            $attachment["post_parent"]  = $old_meta->post_id;
     1448            $attachment["ID"]           = $old_meta->post_id;
     1449
     1450            $upload["url"]              = $old_post->guid;
     1451            $attachment["guid"]         = $old_post->guid;
     1452        }
     1453
     1454        // Save the data
     1455        $id = wp_insert_attachment( $attachment, $upload[ 'file' ], $post_id );
     1456        wp_update_attachment_metadata( $id, wp_generate_attachment_metadata( $id, $upload['file'] ) );
    14301457
    14311458        return apply_filters( 'wp_handle_upload', array( 'file' => $upload[ 'file' ], 'url' => $upload[ 'url' ], 'type' => $type ) );
Note: See TracChangeset for help on using the changeset viewer.