Skip to content

Instantly share code, notes, and snippets.

@evilsocket
Created April 6, 2011 17:56
Show Gist options
  • Save evilsocket/906147 to your computer and use it in GitHub Desktop.
Save evilsocket/906147 to your computer and use it in GitHub Desktop.
A script to import wordpress xml dumps to swg txt files
<?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