Make WordPress Core

Ticket #7595: wordpress-wxr-import-file-import.patch

File wordpress-wxr-import-file-import.patch, 1.5 KB (added by noel, 17 years ago)

Fixes file download/upload mechanism for files without http://

  • wp-admin/import/wordpress.php

     
    105105                                // this doesn't check that the file is perfectly valid but will at least confirm that it's not the wrong format altogether
    106106                                if ( !$is_wxr_file && preg_match('|xmlns:wp="http://wordpress[.]org/export/\d+[.]\d+/"|', $importline) )
    107107                                        $is_wxr_file = true;
    108 
     108                               
     109                                if ( false !== strpos($importline, '<wp:base_site_url>') ) {
     110                                        preg_match('|<wp:base_site_url>(.*?)</wp:base_site_url>|is', $importline, $url);
     111                                        $this->base_url = $url[1];
     112                                        continue;
     113                                }
    109114                                if ( false !== strpos($importline, '<wp:category>') ) {
    110115                                        preg_match('|<wp:category>(.*?)</wp:category>|is', $importline, $category);
    111116                                        $this->categories[] = $category[1];
     
    539544        function process_attachment($postdata, $remote_url) {
    540545                if ($this->fetch_attachments and $remote_url) {
    541546                        printf( __('Importing attachment <em>%s</em>... '), htmlspecialchars($remote_url) );
     547                       
     548                        //If the URL is absolute, but does not contain http, upload it assuming the base_site_url variable
     549                        if(preg_match('/^\/[\w\W]+$/', $remote_url))
     550                                $remote_url = rtrim($this->base_url,'/').$remote_url;
     551                       
    542552                        $upload = $this->fetch_remote_file($postdata, $remote_url);
    543553                        if ( is_wp_error($upload) ) {
    544554                                printf( __('Remote file error: %s'), htmlspecialchars($upload->get_error_message()) );