diff --git a/index.js b/index.js index 66e8663..ffce6d5 100644 --- a/index.js +++ b/index.js @@ -1,5 +1,6 @@ 'use strict'; +const validator = require('validator'); var winston = require.main.require('winston'); var meta = require.main.require('./src/meta'); @@ -18,11 +19,14 @@ var defaultBanList = [ 'smegma', 'spunk', 'tit', 'tosser', 'turd', 'twat', 'vagina', 'wank', 'whore', ]; +const pluginName = 'Censor Curse Words'; + var Beep = { banned_words_raw: '', banned_words: null, banned_urls: null, illegal_words: null, + illegal_usernames: null, parseContent: function (content, symbol) { var nil = '^(?!x)x'; @@ -37,6 +41,7 @@ var Beep = { } Beep.illegal_words = Beep.toRegExp(hash.illegal, true); + Beep.illegal_usernames = Beep.toRegExp(hash['illegal-usernames'], false); if (hash.id && hash.id.length) { var words = hash.id.split(',').filter(function (word) { @@ -67,7 +72,9 @@ var Beep = { var middleware = params.middleware; function render(req, res, next) { - res.render('admin/plugins/beep', {}); + res.render('admin/plugins/beep', { + title: pluginName, + }); } router.get('/admin/plugins/beep', middleware.admin.buildHeader, render); router.get('/api/admin/plugins/beep', render); @@ -142,17 +149,17 @@ var Beep = { // from http://htmlarrows.com/symbols/ var starHTML = '*'; - if (data.topic.hasOwnProperty('title')) { - data.topic.title = Beep.parseContent(data.topic.title, starHTML); - } + if (data.topic.hasOwnProperty('title')) { + data.topic.title = Beep.parseContent(data.topic.title, starHTML); + } - if (data.topic.hasOwnProperty('slug')) { - data.topic.slug = Beep.parseContent(data.topic.slug, starHTML); - } + if (data.topic.hasOwnProperty('slug')) { + data.topic.slug = Beep.parseContent(data.topic.slug, starHTML); + } - if (data.topic.hasOwnProperty('titleRaw')) { - data.topic.titleRaw = Beep.parseContent(data.topic.titleRaw, starHTML); - } + if (data.topic.hasOwnProperty('titleRaw')) { + data.topic.titleRaw = Beep.parseContent(data.topic.titleRaw, starHTML); + } callback(null, data); }, @@ -181,7 +188,7 @@ var Beep = { custom_header.plugins.push({ route: '/plugins/beep', icon: 'fa-microphone-slash', - name: 'Censor Curse Words', + name: pluginName, }); callback(null, custom_header); }, @@ -202,6 +209,16 @@ var Beep = { callback(null, data); }, }, + filterUserCreate: function (hookData) { + const { user } = hookData; + if (user && user.username) { + const isIllegal = user.username.match(Beep.illegal_usernames); + if (isIllegal) { + throw new Error(`[[beep:username.error, ${validator.escape(user.username)}]]`); + } + } + return hookData; + }, }; module.exports = Beep; diff --git a/languages/en_GB/beep.json b/languages/en_GB/beep.json index 6c278b9..dc21a3f 100644 --- a/languages/en_GB/beep.json +++ b/languages/en_GB/beep.json @@ -1,5 +1,6 @@ { "titleMatch.error": "You may not use the word \"%1\" in your title.", "contentMatch.error": "You may not use the word \"%1\" in your post.", - "tagMatch.error": "You may not use the word \"%1\" in your tags." + "tagMatch.error": "You may not use the word \"%1\" in your tags.", + "username.error": "You may not use the word \"%1\" as your username." } \ No newline at end of file diff --git a/languages/pl/beep.json b/languages/pl/beep.json new file mode 100644 index 0000000..1302048 --- /dev/null +++ b/languages/pl/beep.json @@ -0,0 +1,7 @@ + +{ + "titleMatch.error": "Nie ma mowy o użyciu słowa \"%1\" w tytule.", + "contentMatch.error": "Nie ma mowy o użyciu słowa \"%1\" w treści wpisu.", + "tagMatch.error": "Nie ma mowy o użyciu słowa \"%1\" jako tag.", + "username.error": "Nie ma mowy o użyciu słowa \"%1\" jako nazwy użytkownika." +} diff --git a/languages/zh-CN/beep.json b/languages/zh-CN/beep.json new file mode 100644 index 0000000..4d7e44b --- /dev/null +++ b/languages/zh-CN/beep.json @@ -0,0 +1,6 @@ +{ + "titleMatch.error": "您不得在标题中使用 “%1” 一词。", + "contentMatch.error": "您不得在帖子中使用 “%1” 一词。", + "tagMatch.error": "您不得在标签中使用 “%1” 一词。", + "username.error": "您不得在用户名中使用 “%1” 一词。" +} \ No newline at end of file diff --git a/lib/toRegExp.js b/lib/toRegExp.js index 8cc1739..1627dd4 100644 --- a/lib/toRegExp.js +++ b/lib/toRegExp.js @@ -6,7 +6,7 @@ function toRegExp(arr, fullWord) { if (!Array.isArray(arr)) { arr = (arr || '').toString().split(','); } - arr = arr.filter(Boolean); + arr = arr.map(str => str.trim()).filter(Boolean); var str; if (fullWord) { diff --git a/package-lock.json b/package-lock.json index 660ef80..d51af17 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,5 +1,24 @@ { - "name": "nodebb-plugin-beep", - "version": "0.4.6", - "lockfileVersion": 1 + "name": "@nodebb/nodebb-plugin-beep", + "version": "1.1.4", + "lockfileVersion": 3, + "requires": true, + "packages": { + "": { + "name": "@nodebb/nodebb-plugin-beep", + "version": "1.1.4", + "license": "BSD-2-Clause", + "dependencies": { + "validator": "13.11.0" + } + }, + "node_modules/validator": { + "version": "13.11.0", + "resolved": "https://registry.npmjs.org/validator/-/validator-13.11.0.tgz", + "integrity": "sha512-Ii+sehpSfZy+At5nPdnyMhx78fEoPDkR2XW/zimHEL3MyGJQOCQ7WeP20jPYRz7ZCpcKLB21NxuXHF3bxjStBQ==", + "engines": { + "node": ">= 0.10" + } + } + } } diff --git a/package.json b/package.json index ee19fca..894010c 100644 --- a/package.json +++ b/package.json @@ -1,15 +1,14 @@ { - "name": "nodebb-plugin-beep", - "version": "0.4.7", - "description": "NodeBB Censor Curse Words Plugin", - "deprecated": false, + "name": "@nodebb/nodebb-plugin-beep", + "version": "1.1.4", + "description": "NodeBB Plugin that allows users to censor curse words in their posts.", "main": "index.js", "scripts": { "test": "node tests" }, "repository": { "type": "git", - "url": "https://github.com/ninenine/nodebb-plugin-beep" + "url": "https://github.com/NodeBB-Community/nodebb-plugin-beep" }, "keywords": [ "nodebb", @@ -19,19 +18,19 @@ "curse", "words" ], + "dependencies": { + "validator": "13.11.0" + }, "author": { "name": "Davis Wainaina", "email": "davisjwn@gmail.com" }, "license": "BSD-2-Clause", "bugs": { - "url": "https://github.com/ninenine/nodebb-plugin-beep/issues" + "url": "https://github.com/NodeBB-Community/nodebb-plugin-beep/issues" }, - "readme": "", "readmeFilename": "README.md", - "_id": "nodebb-plugin-beep@0.4.4", - "_from": "nodebb-plugin-beep@0.4.4", "nbbpm": { - "compatibility": "^1.0.0 || ^1.1.0 || ^1.13.0 || ^1.16.1 || ^2.0.0" + "compatibility": "^3.2.0 || ^4.x" } } diff --git a/plugin.json b/plugin.json index 8196bbd..a272948 100644 --- a/plugin.json +++ b/plugin.json @@ -1,8 +1,4 @@ { - "id": "nodebb-plugin-beep", - "name": "NodeBB Censor Curse Words Plugin", - "description": "NodeBB Plugin that allows users to censor curse words in their posts.", - "url": "https://github.com/ninenine/nodebb-plugin-beep", "library": "./index.js", "templates":"public/templates", "modules": { @@ -29,7 +25,9 @@ { "hook": "filter:config.get", "method": "appendConfig" }, - { "hook": "filter:messaging.getTeaser", "method": "messaging.getTeaser" } + { "hook": "filter:messaging.getTeaser", "method": "messaging.getTeaser" }, + + { "hook": "filter:user.create", "method": "filterUserCreate" } ], "languages": "languages", "defaultLang": "en_GB" diff --git a/public/templates/admin/plugins/beep.tpl b/public/templates/admin/plugins/beep.tpl index 692d21e..54323b6 100644 --- a/public/templates/admin/plugins/beep.tpl +++ b/public/templates/admin/plugins/beep.tpl @@ -1,60 +1,53 @@ -