added psot date and deadline and also converts shit urls to proper ones

This commit is contained in:
Harry Bomrah 2014-10-17 18:25:54 +08:00
parent e4e3d66f32
commit 1420f75391
1 changed files with 23 additions and 1 deletions

View File

@ -51,13 +51,18 @@ class UpgradeController < ApplicationController
"name" => t.name_translations
}
end
text = {"en" => "", "zh_tw" => ""}
text["en"] = smart_convertor(b.text_translations["en"])
text["zh_tw"] = smart_convertor(b.text_translations["zh_tw"])
{
"id" => b.id.to_s,
"title" => b.title_translations,
"subtitle" => b.subtitle_translations,
"text" => b.text_translations,
"text" => text,
"public" => b.public,
"postdate" => b.postdate,
"deadline" => b.deadline,
"email_sent" => b.email_sent,
"email_sentdate" => b.email_sentdate,
"other_mailaddress" => b.other_mailaddress,
@ -71,4 +76,21 @@ class UpgradeController < ApplicationController
return {"announcements" => bulletins, "categories" => categories, "tags" => tags, "success" => true}
end
def smart_convertor(text)
html_string = text
links = html_string.scan(/img.*?src="(.*?)"/i)
links.each do |link|
l = link.first
new_link = nil
if l.starts_with?("/")
new_link = request.protocol + request.host_with_port + l
elsif l.starts_with?("..")
l1 = l.gsub("../","")
new_link = request.protocol + request.host_with_port + "/" + l1
end
html_string = html_string.sub(l,new_link) if !new_link.nil?
end
return html_string
end
end