Created
July 28, 2010 13:31
-
-
Save danieltamiosso/494525 to your computer and use it in GitHub Desktop.
Plugin to Wind for Wordpress importer
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# | |
# Wind Wordpress Importer | |
# | |
# To install this plugin do you need copy the file to Wind plugins directory. | |
# An admin widget will be crated to import WordPress eXtended RSS file. | |
# | |
# This plugin use hurricane gem [http://github.com/danieltamiosso/hurricane], | |
# [gem install hurricane] to install it. | |
# | |
require 'hurricane' | |
at_start do | |
if not Widget[:title => 'Wordpress Importer'] | |
widget = Widget.new | |
widget.title = 'Wordpress Importer' | |
widget.content = '<form method="post" action="wordpress-importer" enctype="multipart/form-data"><input type="file" name="wordpress_file" placeholder="Wordpress file to import..."/><button type="submit">Go</button></form>' | |
widget.admin = true | |
widget.order = 1000 | |
widget.save | |
end | |
end | |
post '/wordpress-importer' do | |
if_logged do | |
to_wind params[:wordpress_file][:tempfile] | |
end | |
go_home | |
end | |
def to_wind(file) | |
blog = Hurricane::Parse.from(file) | |
$settings.name = blog.title | |
$settings.title = blog.description | |
$settings.save | |
blog.posts.each do |imported_post| | |
post = Post.new | |
post.title = imported_post.title | |
post.text = imported_post.description | |
post.date = imported_post.created_at | |
post.link = imported_post.link.split('/')[-1] | |
post.save | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment