'BlogML Export',
'url' => 'http://habariproject.org/',
'author' => 'Owen Winkler',
'authorurl' => 'http://asymptomatic.net/',
'version' => '1.0',
'description' => 'Exports site data as BlogML',
'license' => 'Apache License 2.0',
);
}
public function help()
{
return <<< END_HELP
This is the help text for the BlogML plugin.
END_HELP;
}
public function filter_plugin_config( $actions, $plugin_id )
{
if ( $plugin_id == $this->plugin_id() ) {
$actions['export']= _t( 'Export BlogML' );
}
return $actions;
}
public function action_plugin_ui( $plugin_id, $action )
{
if ( $plugin_id == $this->plugin_id() ) {
switch ( $action ) {
case 'export':
$this->export();
}
}
}
public function export()
{
ob_end_clean();
header('content-type: text/xml');
header('Content-disposition: attachment; filename=blogml.xml');
$ml = new SimpleXMLElement('');
$ml->addAttribute( 'root-url', Site::get_url('habari') );
$ml->addChild('title', Options::get('title'))->addAttribute('type', 'text');
$ml->addChild('sub-title', Options::get('tagline'))->addAttribute('type', 'text');
$users = DB::get_results('SELECT * FROM {users}', array(), 'User');
$xauthors = $ml->addChild('authors');
foreach($users as $user) {
$author = $xauthors->addChild('author');
$author->addAttribute('id', $user->id);
$author->addAttribute('approved', 'true');
$author->addAttribute('email', $user->email);
$author->addChild('title', $user->displayname)->addAttribute('type', 'text');
}
$options = DB::get_results( 'SELECT name, value, type FROM {options}' );
$exprops = $ml->addChild('extended-properties');
foreach($options as $option) {
$prop = $exprops->addChild('property');
$prop->addAttribute('name', $option->name);
$prop->addAttribute('value', $option->value);
}
$tags = DB::get_results( 'SELECT id, tag_text, tag_slug FROM {tags}');
$categories = $ml->addChild('categories');
foreach($tags as $tag) {
$category = $categories->addChild('category');
$category->addAttribute('id', $tag->id);
$category->addChild('title', $tag->tag_text)->addAttribute('type', 'text');
}
$posts = Posts::get(array('limit'=>null));
$xposts = $ml->addChild('Posts');
foreach($posts as $post) {
$xpost = $xposts->addChild('post');
$xpost->addAttribute('id', $post->id);
$xpost->addAttribute('date-created', $post->pubdate->format('c'));
$xpost->addAttribute('date-modified', $post->modified->format('c'));
$xpost->addAttribute('approved', $post->status == Post::status('published') ? 'true' : 'false');
$xpost->addAttribute('post-url', $post->permalink);
$xpost->addAttribute('type', $post->content_type);
$xpost->addChild('title', $post->title);
$xpost->addChild('content', $post->content);
$xpost->addChild('post-name', $post->slug);
$sql = "
SELECT t.id, t.tag_text, t.tag_slug
FROM {tags} t
INNER JOIN {tag2post} t2p
ON t.id = t2p.tag_id
WHERE t2p.post_id = ?
ORDER BY t.tag_slug ASC";
$tags = DB::get_results( $sql, array( $post->id ) );
$xpostcategories = $xpost->addChild('categories');
foreach($tags as $tag) {
$xpostcategories->addChild('category')->addAttribute('ref', $tag->id);
}
$xpc = $xpost->addChild('comments');
foreach($post->comments as $comment) {
$xcomment = $xpc->addChild('comment');
$xcomment->addAttribute('id', $comment->id);
$xcomment->addAttribute('date-created', $comment->date->format('c'));
$xcomment->addAttribute('date-modified', $comment->date->format('c'));
$xcomment->addAttribute('approved', $comment->status == Comment::STATUS_APPROVED ? 'true' : 'false' );
$xcomment->addAttribute('user-name', $comment->name);
$xcomment->addAttribute('user-url', $comment->url );
$xcomment->addChild('title');
$xcomment->addChild('content', $comment->content)->addAttribute('type', 'text');
}
$xpost->addChild('authors')->addChild('author')->addAttribute('ref', $post->author->id);
}
echo $ml->asXML();
die();
}
}
?>