1 module ApplicationHelper
2 require 'rexml/document'
5 Sanitize.clean(text, Sanitize::Config::OSM).html_safe
9 logger.info "text safety is #{text.html_safe?}"
10 r = simple_format(text)
11 logger.info "formatted text safety is #{r.html_safe?}"
13 logger.info "sanitised text safety is #{r.html_safe?}"
15 logger.info "linkified text safety is #{r.html_safe?}"
17 # return linkify(sanitize(simple_format(text)))
22 Rinku.auto_link(text, :urls, tag_options(:rel => "nofollow")).html_safe
24 Rinku.auto_link(text, :urls, tag_options(:rel => "nofollow"))
28 def html_escape_unicode(text)
29 chars = ActiveSupport::Multibyte::Unicode.u_unpack(text).map do |c|
30 c < 127 ? c.chr : "&##{c.to_s};"
36 def rss_link_to(*args)
37 return link_to(image_tag("RSS.gif", :size => "16x16", :border => 0), Hash[*args], { :class => "rsssmall" });
40 def atom_link_to(*args)
41 return link_to(image_tag("RSS.gif", :size => "16x16", :border => 0), Hash[*args], { :class => "rsssmall" });
44 def javascript_strings
47 js << "<script type='text/javascript'>\n"
48 js << "i18n_strings = new Array();\n"
49 js << javascript_strings_for_key("javascripts")
58 css << ".hidden { display: none }";
59 css << ".hide_unless_logged_in { display: none }" unless @user;
60 css << ".hide_if_logged_in { display: none }" if @user;
61 css << ".hide_if_user_#{@user.id} { display: none }" if @user;
62 css << ".show_if_user_#{@user.id} { display: inline }" if @user;
63 css << ".hide_unless_administrator { display: none }" unless @user and @user.administrator?;
65 return content_tag(:style, css, :type => "text/css")
68 def if_logged_in(tag = :div, &block)
69 content_tag(tag, capture(&block), :class => "hide_unless_logged_in")
72 def if_not_logged_in(tag = :div, &block)
73 content_tag(tag, capture(&block), :class => "hide_if_logged_in")
76 def if_user(user, tag = :div, &block)
78 content_tag(tag, capture(&block), :class => "hidden show_if_user_#{user.id}")
82 def unless_user(user, tag = :div, &block)
84 content_tag(tag, capture(&block), :class => "hide_if_user_#{user.id}")
86 content_tag(tag, capture(&block))
90 def if_administrator(tag = :div, &block)
91 content_tag(tag, capture(&block), :class => "hide_unless_administrator")
94 def describe_location(lat, lon, zoom = nil, language = nil)
96 language = language || request.user_preferred_languages.join(',')
97 url = "http://nominatim.openstreetmap.org/reverse?lat=#{lat}&lon=#{lon}&zoom=#{zoom}&accept-language=#{language}"
100 response = Timeout::timeout(4) do
101 REXML::Document.new(Net::HTTP.get(URI.parse(url)))
107 if response and result = response.get_text("reversegeocode/result")
110 "#{number_with_precision(lat, :precision => 3)}, #{number_with_precision(lon, :precision => 3)}"
114 def user_image(user, options = {})
115 options[:class] ||= "user_image"
118 image_tag url_for_file_column(user, "image"), options
120 image_tag "anon_large.png", options
124 def user_thumbnail(user, options = {})
125 options[:class] ||= "user_thumbnail"
128 image_tag url_for_file_column(user, "image"), options
130 image_tag "anon_small.png", options
137 elsif @user and @user.preferred_editor
138 @user.preferred_editor
146 def javascript_strings_for_key(key)
148 value = I18n.t(key, :locale => "en")
150 if value.is_a?(String)
151 js << "i18n_strings['#{key}'] = '" << escape_javascript(t(key)) << "';\n"
153 value.each_key do |k|
154 js << javascript_strings_for_key("#{key}.#{k}")