public
Last active

Plugin to Wind for Wordpress importer

  • Download Gist
wordpress_to_wind.rb
Ruby
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46
#
# 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

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.