diff --git a/app/assets/javascripts/discourse/dialects/censored_dialect.js b/app/assets/javascripts/discourse/dialects/censored_dialect.js index 1cb38a9115a..c4faa574815 100644 --- a/app/assets/javascripts/discourse/dialects/censored_dialect.js +++ b/app/assets/javascripts/discourse/dialects/censored_dialect.js @@ -1,24 +1,3 @@ -var censorRegexp; - Discourse.Dialect.addPreProcessor(function(text) { - var censored = Discourse.SiteSettings.censored_words; - if (censored && censored.length) { - if (!censorRegexp) { - var split = censored.split("|"); - if (split && split.length) { - censorRegexp = new RegExp("\\b(?:" + split.map(function (t) { return "(" + t.replace(/[-/\\^$*+?.()|[\]{}]/g, '\\$&') + ")"; }).join("|") + ")\\b", "ig"); - } - } - - if (censorRegexp) { - var m = censorRegexp.exec(text); - while (m && m[0]) { - var replacement = new Array(m[0].length+1).join('■'); - text = text.replace(new RegExp("\\b" + m[0] + "\\b", "ig"), replacement); - m = censorRegexp.exec(text); - } - - } - } - return text; + return Discourse.CensoredWords.censor(text); }); diff --git a/app/assets/javascripts/discourse/lib/censored-words.js b/app/assets/javascripts/discourse/lib/censored-words.js new file mode 100644 index 00000000000..840c3093b0d --- /dev/null +++ b/app/assets/javascripts/discourse/lib/censored-words.js @@ -0,0 +1,25 @@ +Discourse.CensoredWords = { + censor: function(text) { + var censorRegexp, + censored = Discourse.SiteSettings.censored_words; + + if (censored && censored.length) { + if (!censorRegexp) { + var split = censored.split("|"); + if (split && split.length) { + censorRegexp = new RegExp("\\b(?:" + split.map(function (t) { return "(" + t.replace(/[-/\\^$*+?.()|[\]{}]/g, '\\$&') + ")"; }).join("|") + ")\\b", "ig"); + } + } + if (censorRegexp) { + var m = censorRegexp.exec(text); + while (m && m[0]) { + var replacement = new Array(m[0].length+1).join('■'); + text = text.replace(new RegExp("\\b" + m[0] + "\\b", "ig"), replacement); + m = censorRegexp.exec(text); + } + + } + } + return text; + } +} diff --git a/app/assets/javascripts/discourse/models/topic.js.es6 b/app/assets/javascripts/discourse/models/topic.js.es6 index 88d99fa3bbc..2c14d86bebf 100644 --- a/app/assets/javascripts/discourse/models/topic.js.es6 +++ b/app/assets/javascripts/discourse/models/topic.js.es6 @@ -2,14 +2,17 @@ import { flushMap } from 'discourse/models/store'; import RestModel from 'discourse/models/rest'; import { propertyEqual } from 'discourse/lib/computed'; import { longDate } from 'discourse/lib/formatter'; +import computed from 'ember-addons/ember-computed-decorators'; const Topic = RestModel.extend({ message: null, errorLoading: false, - fancyTitle: function() { - return Discourse.Emoji.unescape(this.get('fancy_title')); - }.property("fancy_title"), + @computed('fancy_title') + fancyTitle(title) { + title = Discourse.Emoji.unescape(title); + return Discourse.CensoredWords.censor(title); + }, // returns createdAt if there's no bumped date bumpedAt: function() { diff --git a/lib/pretty_text.rb b/lib/pretty_text.rb index 116b83b6005..1b43959482c 100644 --- a/lib/pretty_text.rb +++ b/lib/pretty_text.rb @@ -79,6 +79,7 @@ module PrettyText "vendor/assets/javascripts/better_markdown.js", "app/assets/javascripts/defer/html-sanitizer-bundle.js", "app/assets/javascripts/discourse/dialects/dialect.js", + "app/assets/javascripts/discourse/lib/censored-words.js", "app/assets/javascripts/discourse/lib/utilities.js", "app/assets/javascripts/discourse/lib/markdown.js", )