diff --git a/app/controllers/upgrade_controller.rb b/app/controllers/upgrade_controller.rb index fdcf16a..0b0f431 100644 --- a/app/controllers/upgrade_controller.rb +++ b/app/controllers/upgrade_controller.rb @@ -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 \ No newline at end of file