Created
April 6, 2011 17:56
-
-
Save evilsocket/906147 to your computer and use it in GitHub Desktop.
A script to import wordpress xml dumps to swg txt files
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$source = 'wp.xml'; | |
$siteurl = "http://www.evilsocket.net"; | |
$doc = new DOMDocument(); | |
$doc->load( $source ); | |
$items = $doc->getElementsByTagName( "item" ); | |
foreach ( $items as $item ){ | |
$status = $item->getElementsByTagName( "status" )->item(0)->nodeValue; | |
$type = $item->getElementsByTagName( 'post_type' )->item(0)->nodeValue; | |
if( $status != 'publish' || $type != 'post' ){ | |
continue; | |
} | |
$id = $item->getElementsByTagName( 'post_id' )->item(0)->nodeValue; | |
$title = $item->getElementsByTagName( 'title' )->item(0)->nodeValue; | |
$link = $item->getElementsByTagName( 'link' )->item(0)->nodeValue; | |
$date = $item->getElementsByTagName( 'post_date' )->item(0)->nodeValue; | |
$author = $item->getElementsByTagName( 'creator' )->item(0)->nodeValue; | |
$content = $item->getElementsByTagName( 'encoded' )->item(0)->nodeValue; | |
$categories = array(); | |
$tags = array(); | |
$x_cats = $item->getElementsByTagName( 'category' ); | |
foreach( $x_cats as $x_cat ){ | |
$domain = $x_cat->getAttribute("domain"); | |
$value = $x_cat->nodeValue; | |
if( $domain == 'category' || !$domain ){ | |
if( !in_array( $value, $categories ) ){ | |
$categories[] = $value; | |
} | |
} | |
else { | |
if( !in_array( $value, $tags ) ){ | |
$tags[] = $value; | |
} | |
} | |
} | |
$data = "Date: $date\n". | |
"Author: $author\n". | |
"Categories: ".join( ', ', $categories )."\n". | |
"Tags: ".join( ', ', $tags )."\n". | |
"Title: $title\n\n". | |
str_replace( '<!--more-->', '<break>', $content ); | |
file_put_contents( "$id.txt", $data ); | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment