WXR Importer fix to resolve absolute urls without protocol and domain. fixes #7595

git-svn-id: http://svn.automattic.com/wordpress/trunk@8799 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
ryan 2008-09-03 18:34:20 +00:00
parent c38f460aa6
commit c7e516b25d
1 changed files with 11 additions and 1 deletions

View File

@ -105,7 +105,12 @@ class WP_Import {
// this doesn't check that the file is perfectly valid but will at least confirm that it's not the wrong format altogether
if ( !$is_wxr_file && preg_match('|xmlns:wp="http://wordpress[.]org/export/\d+[.]\d+/"|', $importline) )
$is_wxr_file = true;
if ( false !== strpos($importline, '<wp:base_site_url>') ) {
preg_match('|<wp:base_site_url>(.*?)</wp:base_site_url>|is', $importline, $url);
$this->base_url = $url[1];
continue;
}
if ( false !== strpos($importline, '<wp:category>') ) {
preg_match('|<wp:category>(.*?)</wp:category>|is', $importline, $category);
$this->categories[] = $category[1];
@ -539,6 +544,11 @@ class WP_Import {
function process_attachment($postdata, $remote_url) {
if ($this->fetch_attachments and $remote_url) {
printf( __('Importing attachment <em>%s</em>... '), htmlspecialchars($remote_url) );
// If the URL is absolute, but does not contain http, upload it assuming the base_site_url variable
if ( preg_match('/^\/[\w\W]+$/', $remote_url) )
$remote_url = rtrim($this->base_url,'/').$remote_url;
$upload = $this->fetch_remote_file($postdata, $remote_url);
if ( is_wp_error($upload) ) {
printf( __('Remote file error: %s'), htmlspecialchars($upload->get_error_message()) );