From 1420f75391c552e5eb183ec59fa4cc0ef0d432f0 Mon Sep 17 00:00:00 2001 From: Harry Bomrah Date: Fri, 17 Oct 2014 18:25:54 +0800 Subject: [PATCH] added psot date and deadline and also converts shit urls to proper ones --- app/controllers/upgrade_controller.rb | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) 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