From 035db98367b4c889b39c6e96331e03c8040227cd Mon Sep 17 00:00:00 2001
From: archi <archi@loki.localnet>
Date: Sun, 17 Oct 2010 02:06:46 +0200
Subject: [PATCH] Added HTML links to posts

---
 app/helpers/status_messages_helper.rb               | 10 ++++++++++
 app/views/status_messages/_status_message.html.haml |  2 +-
 2 files changed, 11 insertions(+), 1 deletion(-)

diff --git a/app/helpers/status_messages_helper.rb b/app/helpers/status_messages_helper.rb
index 2dfbd31ccc..4131ccaf08 100644
--- a/app/helpers/status_messages_helper.rb
+++ b/app/helpers/status_messages_helper.rb
@@ -10,4 +10,14 @@ module StatusMessagesHelper
       return I18n.t('status_messages.helper.no_message_to_display')
     end
   end
+
+  def make_links(message)
+    # If there should be some kind of bb-style markup, email/diaspora highlighting, it could go here.
+    
+    # next line is important due to XSS! (h is rail's make_html_safe-function)
+    message = h(message).html_safe
+    message.gsub!(/( |^)(www\.[^ ]+\.[^ ])/, '\1http://\2');
+    return message.gsub(/(http|ftp):\/\/([^ ]+)/, '<a target="_blank" href="\1://\2">\2</a>');
+  end
+
 end
diff --git a/app/views/status_messages/_status_message.html.haml b/app/views/status_messages/_status_message.html.haml
index 8a7b6cbba2..8b2437ae9f 100644
--- a/app/views/status_messages/_status_message.html.haml
+++ b/app/views/status_messages/_status_message.html.haml
@@ -23,7 +23,7 @@
           = render "shared/reshare", :post => post, :current_user => current_user
           = link_to t('.delete'), status_message_path(post), :confirm => t('.are_you_sure'), :method => :delete, :remote => true, :class => "delete"
 
-    = post.message
+    = make_links(post.message)
 
     .info
       %span.time= link_to(how_long_ago(post), object_path(post))
-- 
GitLab