module Thredded module Filter module Bbcode require 'bb-ruby' BB = { 'Spoilers' => [ /\[spoiler\](.*?)\[\/spoiler\1?\]/mi, '
\1
', 'Spoiler Text', '[spoiler]Dumbledore dies[/spoiler]', :spoiler], 'YouTube' => [ /\[youtube\]https?\:\/\/(www\.)?youtube.com\/((watch)?\?vi?=|embed\/)(.*?)\[\/youtube\1?\]/i, '', 'Youtube Video', :video], 'Link (Legacy)' => [ /\[link=(?:")?(.*?)(?:")?\](.*?)\[\/link\]/mi, '\2', 'Hyperlink to somewhere else', 'Maybe try looking on [link=http://google.com]Google[/link]?', :link], 'Link (Legacy Implied)' => [ /\[link\](.*?)\[\/link\]/mi, '\1', 'Hyperlink (legacy implied)', "Maybe try looking on [link]http://google.com[/link]", :link], } def self.included(base) base.class_eval do Thredded::Post::Filters << :bbcode end end def filtered_content if filter.to_sym == :bbcode content = super content = replace_code_tags(content) content = replace_quote_tags(content) content = content.bbcode_to_html(BB) content = remove_empty_p_tags(content) content = CGI.unescapeHTML(content) content.html_safe else super end end def replace_code_tags(content) content.gsub!(/\[code\]/, '
')
        content.gsub!(/\[code:(\D+?)\]/, '
')
        content.gsub!(/\[\/code\]/, '
') content.html_safe end def replace_quote_tags(content) content.gsub!(/\[quote(:.*)?=(?:")?(.*?)(?:")?\]/, '

\2

') content.gsub!(/\[quote(:.*?)?\]/, '

') content.gsub!(/\[\/quote\]/, '

') content.html_safe end def remove_empty_p_tags(content) content.gsub(/<p>\s*?<\/p>/, '') end end end end