Advertisement
Advertisement
| 07.25.2008 at 08:32PM PDT, ID: 23597247 | Points: 500 |
|
[x]
Attachment Details
|
||
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: |
if request.post?
@note = Note.new(params[:note])
#Load requirements
require "open-uri"
require "hpricot"
#Get the content of the URL
document_html = open(@note.url, "User-Agent" => "Fanopic")
#Check to see if it is a HTML Page
if not document_html.content_type == "text/html"
title = _("The page is not TEXT/HTML")
flash[:error] = notice("error", title)
redirect_to :action => "create" and return
end
#Take the URL of the content (if there were any redirects)
@note.url = document_html.base_uri.to_s
#Get the stream open (make it an Hpricot object)
document_html = Hpricot(document_html)
#Scan the page for needed elements
document_title = document_html.search("title")
document_description = document_html.search("//meta[@name='description']")
#Take the needed elements without nasty symbols
if not document_title.blank?
@note.title = document_title.html.strip
else
title = _("We couldn't acquire the page title.")
flash[:error] = notice("error", title)
redirect_to :action => "create" and return
end
if not document_description.blank?
@note.content = document_description[0].attributes["content"].strip
else
title = _("We couldn't acquire a page description.")
flash[:error] = notice("error", title)
redirect_to :action => "create" and return
end
end
|