DZone 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

Snippets has posted 5883 posts at DZone. View Full User Profile

Typo Export To WordPress WXR

01.09.2007
| 9325 views |
  • submit to reddit
        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 :

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

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

// insert code here..
xml.instruct! :xml, :version=>"1.0", :encoding=>"UTF-8"

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
  xml.channel do
    xml.title @feed_title
    xml.link @link
    xml.language "en-us"
    xml.ttl "40"
    xml.description this_blog.blog_subtitle

    @articles.each do |a|
        xml.item do
          xml.title post_title(a)
          xml.content(:encoded) { |x| x << '<![CDATA[' + a.full_html + ']]>' }
          xml.pubDate a.published_at.rfc2822
          xml.guid "urn:uuid:#{a.guid}", "isPermaLink" => "false"
          author = a.user.name rescue a.author
          xml.author author
          xml.dc :creator, author
          for category in a.categories
            xml.category category.name
          end
          for tag in a.tags
            xml.category tag.display_name
          end
          xml.wp :post_id, a.id
          xml.wp :post_date, a.published_at.strftime("%Y-%m-%d %H:%M:%S")
          xml.wp :comment_status, 'closed'
          xml.wp :ping_status, 'closed'
          xml.wp :post_name, a.permalink
          xml.wp :status, 'publish'
          xml.wp :post_parent, '0'
          xml.wp :post_type, 'post'
          for comment in a.comments
            xml.wp(:comment) do
              xml.wp :comment_id, comment.id
              xml.wp :comment_author, comment.author
              xml.wp :comment_author_email, comment.email
              xml.wp :comment_author_url, comment.url
              xml.wp :comment_author_IP, comment.ip
              xml.wp :comment_author_date, comment.published_at.strftime("%Y-%m-%d %H:%M:%S")
              xml.wp(:comment_content) { |x| x << comment.full_html }
              xml.wp :comment_approved, '1'
              xml.wp :comment_parent, '0'
            end
          end
        end
    end
end

Then hit your typo blog at http://myblog/xml/wp and save the file to import through the WordPress interface.    

Comments

lei wang replied on Tue, 2009/12/01 - 10:12pm

export the strange Wordpress RSS file format really helpful,like ocx exe information very useful.

jhfkjhkj lgkjhgkj replied on Sat, 2009/07/11 - 12:11am

The below code snippet works sort of, but it is slow for me. Not sure at the moment whether it is VIM or something else. Perhapps others can try it out and suggest speed or other improvments in free games online. Regards,

Snippets Manager replied on Thu, 2007/01/18 - 6:46pm

Here's a way to do this as a script instead of through the site: http://snippets.dzone.com/posts/show/4326