Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions phpunit/data/valid-wxr-1.1.xml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,14 @@
<wp:base_blog_url>http://localhost/</wp:base_blog_url>

<wp:author><wp:author_id>2</wp:author_id><wp:author_login>john</wp:author_login><wp:author_email>johndoe@example.org</wp:author_email><wp:author_display_name><![CDATA[John Doe]]></wp:author_display_name><wp:author_first_name><![CDATA[John]]></wp:author_first_name><wp:author_last_name><![CDATA[Doe]]></wp:author_last_name></wp:author>
<wp:author>
<wp:author_id>3</wp:author_id>
<wp:author_login>jane</wp:author_login>
<wp:author_email>janedoe@example.org</wp:author_email>
<wp:author_display_name><![CDATA[Jane Doe]]></wp:author_display_name>
<wp:author_first_name><![CDATA[Jane]]></wp:author_first_name>
<wp:author_last_name><![CDATA[Doe]]></wp:author_last_name>
</wp:author>

<wp:category><wp:term_id>3</wp:term_id><wp:category_nicename>alpha</wp:category_nicename><wp:category_parent></wp:category_parent><wp:cat_name><![CDATA[alpha]]></wp:cat_name><wp:category_description><![CDATA[The alpha category]]></wp:category_description></wp:category>
<wp:tag><wp:term_id>22</wp:term_id><wp:tag_slug>clippable</wp:tag_slug><wp:tag_name><![CDATA[Clippable]]></wp:tag_name><wp:tag_description><![CDATA[The Clippable post_tag]]></wp:tag_description></wp:tag>
Expand Down
12 changes: 12 additions & 0 deletions phpunit/tests/parser.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,18 @@ public function test_wxr_version_1_1() {
$result['authors']['john'],
$message
);
$this->assertEqualSetsWithIndex(
array(
'author_id' => 3,
'author_login' => 'jane',
'author_email' => 'janedoe@example.org',
'author_display_name' => 'Jane Doe',
'author_first_name' => 'Jane',
'author_last_name' => 'Doe',
),
$result['authors']['jane'],
$message
);
$this->assertEqualSetsWithIndex(
array(
'term_id' => 3,
Expand Down
23 changes: 13 additions & 10 deletions src/parsers/class-wxr-parser-regex.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ public function parse( $file ) {
'wp:category' => array( 'categories', array( $this, 'process_category' ) ),
'wp:tag' => array( 'tags', array( $this, 'process_tag' ) ),
'wp:term' => array( 'terms', array( $this, 'process_term' ) ),
'wp:author' => array( 'authors', array( $this, 'process_author' ) ),
);

$fp = $this->fopen( $file, 'r' );
Expand All @@ -60,20 +61,17 @@ public function parse( $file ) {
$this->base_blog_url = $this->base_url;
}

if ( false !== strpos( $importline, '<wp:author>' ) ) {
preg_match( '|<wp:author>(.*?)</wp:author>|is', $importline, $author );
$a = $this->process_author( $author[1] );
$this->authors[ $a['author_login'] ] = $a;
continue;
}

foreach ( $multiline_tags as $tag => $handler ) {
// Handle multi-line tags on a singular line
$pos = strpos( $importline, "<$tag>" );
$pos_closing = strpos( $importline, "</$tag>" );
if ( preg_match( '|<' . $tag . '>(.*?)</' . $tag . '>|is', $importline, $matches ) ) {
$this->{$handler[0]}[] = call_user_func( $handler[1], $matches[1] );

$result = call_user_func( $handler[1], $matches[1] );
if ( 'wp:author' === $tag && isset( $result['author_login'] ) ) {
$this->authors[ $result['author_login'] ] = $result;
} else {
$this->{$handler[0]}[] = $result;
}
} elseif ( false !== $pos ) {
// Take note of any content after the opening tag
$multiline_content = trim( substr( $importline, $pos + strlen( $tag ) + 2 ) );
Expand All @@ -86,7 +84,12 @@ public function parse( $file ) {
$in_multiline = false;
$multiline_content .= trim( substr( $importline, 0, $pos_closing ) );

$this->{$handler[0]}[] = call_user_func( $handler[1], $multiline_content );
$result = call_user_func( $handler[1], $multiline_content );
if ( 'wp:author' === $tag && isset( $result['author_login'] ) ) {
$this->authors[ $result['author_login'] ] = $result;
} else {
$this->{$handler[0]}[] = $result;
}
}
}

Expand Down