Skip to content

Instantly share code, notes, and snippets.

@billymeltdown
Created December 19, 2010 20:11
Show Gist options
  • Save billymeltdown/747657 to your computer and use it in GitHub Desktop.
Save billymeltdown/747657 to your computer and use it in GitHub Desktop.
Exports Radiant CMS's comments extension data to a WXR XML file for import into Disqus
BLOG_PARENT_ID = 4
xml = Builder::XmlMarkup.new(:target => STDOUT, :indent => 2)
xml.instruct!
xml.rss(
:version => '2.0',
'xmlns:excerpt' => "http://wordpress.org/export/1.0/excerpt/",
'xmlns:content' => "http://purl.org/rss/1.0/modules/content/",
'xmlns:wfw' => "http://wellformedweb.org/CommentAPI/",
'xmlns:dc' => "http://purl.org/dc/elements/1.1/",
'xmlns:wp' => "http://wordpress.org/export/1.0/"
)
xml.channel do
xml.title 'Zetetic Blog'
xml.link 'http://zetetic.net/blog'
xml.description 'Zetetic Blog'
xml.pubDate( Time.now.strftime("%a, %d %b %Y %H:%M:%S %z") )
xml.generator 'Builder::XmlMarkup'
xml.language 'en'
xml.tag!('wp:wxr_version', '1.0' )
xml.wp(:wxr_version, '1.0' )
xml.wp(:base_site_url, 'http://zetetic.net' )
xml.wp(:base_blog_url, 'http://zetetic.net/blog')
Page.all(:conditions => ['parent_id = ? AND published_at IS NOT NULL', BLOG_PARENT_ID]).each do |page|
comments = Comment.find_all_by_page_id(page.id)
next if comments.blank?
xml.item do
xml.link "http://zetetic.net#{page.url}"
xml.title page.title
xml.pubDate( page.published_at.strftime("%a, %d %b %Y %H:%M:%S %z") )
xml.dc(:creator) { xml.cdata!(page.created_by.name) }
xml.guid( "http://zetetic.net#{page.url}", :isPermalink => 'true' )
# <wp:post_id>95</wp:post_id>
xml.wp_id page.id
xml.wp(:id, page.id)
xml.wp(:post_id, page.id)
# <wp:post_date>2009-11-25 15:46:20</wp:post_date>
xml.wp(:post_date, page.published_at.to_s(:db))
# <wp:post_date_gmt>0000-00-00 00:00:00</wp:post_date_gmt>
xml.wp(:post_date_gmt, '0000-00-00 00:00:00')
# <wp:comment_status>open</wp:comment_status>
xml.wp(:comment_status, 'open')
xml.wp(:ping_status, 'open')
# <wp:status>draft</wp:status>
xml.wp(:status, 'published')
# <wp:post_parent>0</wp:post_parent>
xml.wp(:post_parent, '0')
# <wp:post_type>post</wp:post_type>
xml.wp(:post_type, 'post')
# hey look it's finally time for the comments
comments.each do |comment|
xml.wp(:comment) do
xml.wp(:comment_id, comment.id)
xml.wp(:comment_author) { xml.cdata!(comment.author) }
xml.wp(:comment_author_email, comment.author_email)
xml.wp(:comment_author_url, comment.author_url)
xml.wp(:comment_author_IP, comment.author_ip)
xml.wp(:comment_date, comment.created_at.to_s(:db))
xml.wp(:comment_date_gmt, comment.created_at.to_s(:db))
xml.wp(:comment_content) do
xml.cdata!( comment.content_html)
end
approved = comment.approved_at.blank? ? 1 : 0
xml.wp(:comment_approved, approved.to_s)
xml.wp(:comment_type)
xml.wp(:comment_parent, '0')
xml.wp(:comment_user_id, '0')
end
end
end
end
end
<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:wp="http://wordpress.org/export/1.0/" xmlns:excerpt="http://wordpress.org/export/1.0/excerpt/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" version="2.0"/>
<channel>
<title>Zetetic Blog</title>
<link>http://zetetic.net/blog</link>
<description>Zetetic Blog</description>
<pubDate>Sun, 19 Dec 2010 12:51:31 -0500</pubDate>
<generator>Builder::XmlMarkup</generator>
<language>en</language>
<wp:wxr_version>1.0</wp:wxr_version>
<wp:wxr_version>1.0</wp:wxr_version>
<wp:base_site_url>http://zetetic.net</wp:base_site_url>
<wp:base_blog_url>http://zetetic.net/blog</wp:base_blog_url>
<item>
<link>http://zetetic.net/blog/2007/08/27/new-mobile-pingme-features/</link>
<title>New mobile PingMe features</title>
<pubDate>Mon, 27 Aug 2007 21:56:33 +0000</pubDate>
<dc:creator>
<![CDATA[Stephen Lombardo]]>
</dc:creator>
<guid isPermalink="true">http://zetetic.net/blog/2007/08/27/new-mobile-pingme-features/</guid>
<wp_id>114</wp_id>
<wp:id>114</wp:id>
<wp:post_id>114</wp:post_id>
<wp:post_date>2007-08-27 21:56:33</wp:post_date>
<wp:post_date_gmt>0000-00-00 00:00:00</wp:post_date_gmt>
<wp:comment_status>open</wp:comment_status>
<wp:ping_status>open</wp:ping_status>
<wp:status>published</wp:status>
<wp:post_parent>0</wp:post_parent>
<wp:post_type>post</wp:post_type>
<wp:comment>
<wp:comment_id>130</wp:comment_id>
<wp:comment_author>
<![CDATA[Zabe]]>
</wp:comment_author>
<wp:comment_author_email>foo@example.com</wp:comment_author_email>
<wp:comment_author_url>http://example.com</wp:comment_author_url>
<wp:comment_author_IP>192.168.0.1</wp:comment_author_IP>
<wp:comment_date>2008-05-10 05:32:08</wp:comment_date>
<wp:comment_date_gmt>2008-05-10 05:32:08</wp:comment_date_gmt>
<wp:comment_content>
<![CDATA[<p>Nice feature. Do you just use your PingMe profile username: username@gopingme.com as the send-to account?</p>]]>
</wp:comment_content>
<wp:comment_approved>0</wp:comment_approved>
<wp:comment_type/>
<wp:comment_parent>0</wp:comment_parent>
<wp:comment_user_id>0</wp:comment_user_id>
</wp:comment>
<wp:comment>
<wp:comment_id>131</wp:comment_id>
<wp:comment_author>
<![CDATA[dan ros]]>
</wp:comment_author>
<wp:comment_author_email>foo@example.com</wp:comment_author_email>
<wp:comment_author_url>http://example.com</wp:comment_author_url>
<wp:comment_author_IP>192.168.0.1</wp:comment_author_IP>
<wp:comment_date>2008-05-10 05:32:08</wp:comment_date>
<wp:comment_date_gmt>2008-05-10 05:32:08</wp:comment_date_gmt>
<wp:comment_content>
<![CDATA[<p>nice article</p>]]>
</wp:comment_content>
<wp:comment_approved>0</wp:comment_approved>
<wp:comment_type/>
<wp:comment_parent>0</wp:comment_parent>
<wp:comment_user_id>0</wp:comment_user_id>
</wp:comment>
</item>
</channel>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment