Pastoid

Habari BlogML Export Plugin

The page you are looking at now is at this URL: http://pastoid.com/amd

This paste was last updated on February 5, 2009 at 5:10 pm.

blogml.plugin.phpraw

<?php
 
class BlogML extends Plugin
{
	/**
	 * function info
	 * Returns information about this plugin
	 * @return array Plugin info array
	 **/
	function info()
	{
		return array (
			'name' => '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
<p>This is the help text for the BlogML plugin.</p>
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('<?xml version="1.0" encoding="utf-8"?><blog xmlns="http://www.blogml.com/2006/09/BlogML" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:habari="http://habariproject.org/schemas/blogml/1.0" />');
 
		$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();
	}
 
 
}
?>

Toggle wordwrap

Referring DomainHits
Unknown Referer 127
pastoid.com 16
mibbit.com 4
drunkenmonkey.org 1
Is this paste spam?
<Hide