mirror of
https://github.com/codeninjasllc/discourse.git
synced 2024-11-23 15:48:43 -05:00
FEATURE: Site setting for words to censor in posts
This commit is contained in:
parent
b58435de90
commit
9564ecde76
7 changed files with 41 additions and 5 deletions
|
@ -28,7 +28,7 @@
|
|||
</div>
|
||||
|
||||
<div class="site-settings-detail pull-left">
|
||||
{{ outlet }}
|
||||
{{outlet}}
|
||||
</div>
|
||||
|
||||
<div class="clearfix"></div>
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
</div>
|
||||
<div class="setting-value">
|
||||
{{list-setting settingValue=value choices=choices settingName=setting}}
|
||||
<div class='desc'>{{unbound description}}</div>
|
||||
<div class='desc'>{{{unbound description}}}</div>
|
||||
</div>
|
||||
{{#if dirty}}
|
||||
<div class='setting-controls'>
|
||||
|
|
|
@ -14,10 +14,10 @@ Discourse.SiteSettingView = Discourse.View.extend(Discourse.ScrollTop, {
|
|||
if (this.get('content.type') === 'bool') return 'admin/templates/site_settings/setting_bool';
|
||||
|
||||
// If we're editing an enum field, show a dropdown
|
||||
if (this.get('content.type') === 'enum' ) return 'admin/templates/site_settings/setting_enum';
|
||||
if (this.get('content.type') === 'enum') return 'admin/templates/site_settings/setting_enum';
|
||||
|
||||
// If we're editing a list, show a list editor
|
||||
if (this.get('content.type') === 'list' ) return 'admin/templates/site_settings/setting_list';
|
||||
if (this.get('content.type') === 'list') return 'admin/templates/site_settings/setting_list';
|
||||
|
||||
// Default to string editor
|
||||
return 'admin/templates/site_settings/setting_string';
|
||||
|
|
|
@ -0,0 +1,24 @@
|
|||
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(split.map(function (t) { return "(" + t.replace(/[-/\\^$*+?.()|[\]{}]/g, '\\$&') + ")"; }).join("|"), "ig");
|
||||
}
|
||||
}
|
||||
|
||||
if (censorRegexp) {
|
||||
var m = censorRegexp.exec(text);
|
||||
while (m && m[0]) {
|
||||
var replacement = new Array(m[0].length+1).join('■');
|
||||
text = text.replace(m[0], replacement);
|
||||
m = censorRegexp.exec(text);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
return text;
|
||||
});
|
|
@ -631,6 +631,7 @@ en:
|
|||
description: "A message that will be displayed at the top of all notification emails."
|
||||
|
||||
site_settings:
|
||||
censored_words: "Words that will be automatically replaced with ■■■■"
|
||||
delete_old_hidden_posts: "Auto-delete any hidden posts that stay hidden for more than 30 days."
|
||||
default_locale: "The default language of this Discourse instance (ISO 639-1 Code)"
|
||||
allow_user_locale: "Allow users to choose their own language interface preference"
|
||||
|
|
|
@ -380,6 +380,11 @@ posting:
|
|||
client: true
|
||||
default: false
|
||||
delete_old_hidden_posts: true
|
||||
censored_words:
|
||||
client: true
|
||||
default: ''
|
||||
refresh: true
|
||||
type: list
|
||||
|
||||
email:
|
||||
email_time_window_mins: 10
|
||||
|
|
|
@ -471,7 +471,6 @@ test("urlAllowed", function() {
|
|||
});
|
||||
|
||||
test("images", function() {
|
||||
|
||||
cooked("[![folksy logo](http://folksy.com/images/folksy-colour.png)](http://folksy.com/)",
|
||||
"<p><a href=\"http://folksy.com/\"><img src=\"http://folksy.com/images/folksy-colour.png\" alt=\"folksy logo\"/></a></p>",
|
||||
"It allows images with links around them");
|
||||
|
@ -480,3 +479,10 @@ test("images", function() {
|
|||
"<p><img src=\"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAUAAAAFCAYAAACNbyblAAAAHElEQVQI12P4//8/w38GIAXDIBKE0DHxgljNBAAO9TXL0Y4OHwAAAABJRU5ErkJggg==\" alt=\"Red dot\"></p>",
|
||||
"It allows data images");
|
||||
});
|
||||
|
||||
test("censoring", function() {
|
||||
Discourse.SiteSettings.censored_words = "shucks|whiz";
|
||||
cooked("aw shucks, golly gee whiz.",
|
||||
"<p>aw ■■■■■■, golly gee ■■■■.</p>",
|
||||
"it censors words in the Site Settings");
|
||||
});
|
||||
|
|
Loading…
Reference in a new issue