Make WordPress Core

Changeset 5008 for trunk/xmlrpc.php


Ignore:
Timestamp:
03/09/2007 08:14:52 PM (20 years ago)
Author:
ryan
Message:

Change xmlrpc upload logic. Props Joseph Scott.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/xmlrpc.php

    r4961 r5008  
    13841384                $bits = $data['bits'];
    13851385
    1386                 // Default to new file, not over write.
    1387                 $overwrite = false;
    13881386                if(!empty($data["overwrite"]) && ($data["overwrite"] == true)) {
    1389                         $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 
    13991387                        // 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}'
     1388                        $old_file = $wpdb->get_row("
     1389                                SELECT ID
     1390                                FROM {$wpdb->posts}
     1391                                WHERE post_title = '{$name}'
     1392                                        AND post_type = 'attachment'
    14051393                        ");
    14061394
    1407                         // Get post info on the object.
    1408                         $old_post = get_post($old_meta->post_id);
     1395                        // Delete previous file.
     1396                        wp_delete_attachment($old_file->ID);
     1397
     1398                        // Make sure the new name is different by pre-pending the
     1399                        // previous post id.
     1400                        $filename = preg_replace("/^wpid\d+-/", "", $name);
     1401                        $name = "wpid{$old_file->ID}-{$filename}";
    14091402                }
    14101403
    … …  
    14411434                );
    14421435
    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 
    14541436                // Save the data
    14551437                $id = wp_insert_attachment( $attachment, $upload[ 'file' ], $post_id );
    14561438                wp_update_attachment_metadata( $id, wp_generate_attachment_metadata( $id, $upload['file'] ) );
    14571439
    1458                 return apply_filters( 'wp_handle_upload', array( 'file' => $upload[ 'file' ], 'url' => $upload[ 'url' ], 'type' => $type ) );
     1440                return apply_filters( 'wp_handle_upload', array( 'file' => $name, 'url' => $upload[ 'url' ], 'type' => $type ) );
    14591441        }
    14601442
Note: See TracChangeset for help on using the changeset viewer.