Never been to DZone Snippets before?

Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

About this user

Scott Chacon

« Newer Snippets
Older Snippets »
Showing 1-1 of 1 total  RSS 

Typo export to WordPress WXR

If you want to move from Typo to Wordpress, you can use this to export the strange Wordpress RSS file format (comments and all).

Just add this to the XmlController :

   1  
   2    def wp
   3      @articles = Article.find( :all, :include => [:categories, :tags, :user, :blog])
   4    end


And then add this file (app/views/xml/wp.rxml):

   1  
   2  // insert code here..
   3  xml.instruct! :xml, :version=>"1.0", :encoding=>"UTF-8"
   4  
   5  xml.rss 'version' => "2.0", '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/" do
   6    xml.channel do
   7      xml.title @feed_title
   8      xml.link @link
   9      xml.language "en-us"
  10      xml.ttl "40"
  11      xml.description this_blog.blog_subtitle
  12  
  13      @articles.each do |a|
  14          xml.item do
  15            xml.title post_title(a)
  16            xml.content(:encoded) { |x| x << '<![CDATA[' + a.full_html + ']]>' }
  17            xml.pubDate a.published_at.rfc2822
  18            xml.guid "urn:uuid:#{a.guid}", "isPermaLink" => "false"
  19            author = a.user.name rescue a.author
  20            xml.author author
  21            xml.dc :creator, author
  22            for category in a.categories
  23              xml.category category.name
  24            end
  25            for tag in a.tags
  26              xml.category tag.display_name
  27            end
  28            xml.wp :post_id, a.id
  29            xml.wp :post_date, a.published_at.strftime("%Y-%m-%d %H:%M:%S")
  30            xml.wp :comment_status, 'closed'
  31            xml.wp :ping_status, 'closed'
  32            xml.wp :post_name, a.permalink
  33            xml.wp :status, 'publish'
  34            xml.wp :post_parent, '0'
  35            xml.wp :post_type, 'post'
  36            for comment in a.comments
  37              xml.wp(:comment) do
  38                xml.wp :comment_id, comment.id
  39                xml.wp :comment_author, comment.author
  40                xml.wp :comment_author_email, comment.email
  41                xml.wp :comment_author_url, comment.url
  42                xml.wp :comment_author_IP, comment.ip
  43                xml.wp :comment_author_date, comment.published_at.strftime("%Y-%m-%d %H:%M:%S")
  44                xml.wp(:comment_content) { |x| x << comment.full_html }
  45                xml.wp :comment_approved, '1'
  46                xml.wp :comment_parent, '0'
  47              end
  48            end
  49          end
  50      end
  51  end


Then hit your typo blog at http://myblog/xml/wp and save the file to import through the WordPress interface.
« Newer Snippets
Older Snippets »
Showing 1-1 of 1 total  RSS