7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
|
# File 'app/helpers/my_forum/posts_helper.rb', line 7
def format_bbcode(text)
text.gsub!(/\r\n/, '<br />')
text.gsub!(/\n/, '<br />')
text.gsub!(/\[img\]/i, '<img src="')
text.gsub!(/\[\/img\]/i, '" />')
text.gsub!(/\[img\](.*?)\[\/img\]/i) { ActionController::Base.helpers.image_tag($1) }
text.gsub!(/(?:https?:\/\/)?(?:www\.)?youtu(?:\.be|be\.com)\/(?:watch\?v=)?(?<video_code>[\w-]{10,})/i) do |match|
"<iframe width='560' height='315' src='https://www.youtube.com/embed/#{$~[:video_code]}' frameborder='0' allowfullscreen></iframe>"
end
text.gsub!(/\[attachment=([0-9]+)\]/i) do |match|
"<p> <img class='post_attachment' src='#{attachment_img_path($1)}' /> </p>"
end
text.gsub!(/(\[b\](?<bold_text>.+?)\[\/b\])/i) { |match| "<strong>#{$1}</strong>" }
text.gsub!(/(\[i\])(?<italic_text>.*?)(\[\/i\])/i) { |match| "<i>#{$1}</i>" }
text.gsub!(/(\[cut\])(?<cut_text>.*?)(\[\/cut\])/i) { |match| "<pre>#{$1}</pre>" }
text.gsub!(/\[color=(.*?)\](.*?)\[\/color\]/i) { "<span style='color: #{$1}'>#{$2}</span>" }
text.gsub!(/\[size=(.*?)\](.*?)\[\/size\]/i) { "<span style='font-size: #{$1}'>#{$2}</span>" }
text.gsub!(/\[quote author=(?<autor>.*)\](?<text>.*)\[\/quote\]/m) do |match|
"<div class='bbqoute'> <div class='quote_info'>#{$~[:autor]} #{t('my_forum.bbquote.wrote')}:</div> #{$~[:text]} </div>"
end
text.gsub!(/(?<open>\[quote author=(?<autor>(.*?)) (.+)\](?<text>(.+))(?<close>\[\/quote\]))/i) do |match|
"<div class='bbqoute'> <div class='quote_info'>#{$~[:autor]} #{t('my_forum.bbquote.wrote')}:</div> #{$~[:text]} </div>"
end
emoticons_list.each do |code, path|
text.gsub!(/#{Regexp.quote(code)}/) { "<img src='#{path}' class='smile' />" }
end
text.gsub!(/@\S+/) { |match| "<span class='badge'>#{match}</span>" }
auto_link(text).html_safe
end
|