module ForumHelper def wrap(s, n) Wraptools.wrap_ff(s, n) end # Calculates the difference between time and sysdate, and rewrites it as text, # e.g. "3 days ago" # At present, this is not used anywhere in the code. There is an intention to use it in # forum/show action ('this topis was edited 4 centuries ago') def format_relative_time(time) interval = (Time.now - time) seconds = (interval).to_i minutes = (interval / 60).to_i hours = (interval / (60*60)).to_i days = (interval / (60*60*24)).to_i if days == 0 if hours == 0 if minutes == 0 return l(:seconds_ago, seconds) end return l(:minutes_ago, minutes) end return l(:hours_ago, hours) end if days == 1 return l(:yesterday) else return l(:days_ago, days) end end # Extract a small part of the text to show in the search results. def searchresult_text_excerpt(text, query) excerpt = h(text[0,100]) if text.size > 100 excerpt << '...' end # hilight searched words words = query.split words.each do |word| begin excerpt[word] = '' + word + '' rescue end end excerpt end # Color quoting levels in a string. Use CGI::escapeHTML before doing this. def color_quoting(s) s.gsub(/\r\n/, "\n").gsub(/(^)((>)+)(.*?)$/m) do |match| '' + $2 + $4 + '' end end def format_post_text_new(s) #color_quoting(h(s)) s = h(Wraptools::unwrap_quoted(s)) parts = [] s.gsub(/\r\n/, "\n").scan(/(^)((>)*)(.*?)$/m) do |match| line = $4 level = $2.size / 4 if level > 0 # remove leading space after ">" is removed line.sub!(/^ /, '') end # convert leading spaces to   line.sub!(/^( *)/, '') line = ' ' * $1.size + line parts << [line, level] end cur_level = -1 s = '' parts.each do |line, level| if level > cur_level while level > cur_level do cur_level += 1 s << '
' end elsif level < cur_level while level < cur_level do s << '
' cur_level -= 1 end end if line =~ /schrieb:$/ line = '' + line + '' end s << line s << "
" end while 0 <= cur_level do s << '' cur_level -= 1 end s end # Converts urls in a string to links. # The string has to be html-escaped (CGI::escapeHTML) def url_to_link(s) url_regex= /(http:\/\/[^)\s]+[^.?!\)\]\s])/is s.gsub(url_regex) do |match| url = $1 '' + url + '' end end end