From afb4431b0c68c80bb3b9c3850522a73df0bf6edf Mon Sep 17 00:00:00 2001 From: cercos Date: Sun, 28 Aug 2016 09:57:54 -0400 Subject: [PATCH 1/2] Update CensorWords.php Add forbiddenWords --- src/CensorWords.php | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/src/CensorWords.php b/src/CensorWords.php index 08551c9..383a844 100644 --- a/src/CensorWords.php +++ b/src/CensorWords.php @@ -5,6 +5,7 @@ class CensorWords { public $badwords; + public $forbiddenWords; /* * When the dictionary is loaded, a ton of regular expression strings are generated @@ -29,8 +30,10 @@ public function __construct() { * string */ public function setDictionary($dictionary) { - - $this->badwords = $this->readBadWords($dictionary); + + $words = $this->readBadWords($dictionary); + $this->badwords = $words['badwords']; + $this->forbiddenWords = $words['forbiddenWords']; } /** @@ -43,7 +46,9 @@ public function setDictionary($dictionary) { */ public function addDictionary($dictionary) { - $this->badwords = array_merge($this->badwords, $this->readBadWords($dictionary)); + $words = $this->readBadWords($dictionary); + $this->badwords = array_merge($this->badwords, $words['badwords']); + $this->forbiddenWords = array_merge($this->forbiddenWords, $words['forbiddenWords']); } /** @@ -54,6 +59,7 @@ public function addDictionary($dictionary) { */ private function readBadWords($dictionary) { $badwords = array(); + $forbiddenWords = []; $baseDictPath = __DIR__ . DIRECTORY_SEPARATOR .'dict/'; if (is_array($dictionary)) { @@ -77,7 +83,12 @@ private function readBadWords($dictionary) { } } - return $badwords; + $wordList = [ + 'badwords' => $badwords, + 'forbiddenWords' => $forbiddenWords + ]; + + return $wordList; } /** @@ -112,6 +123,7 @@ public function randCensor($chars, $len) { private function generateCensorChecks($fullWords = false) { $badwords = $this->badwords; + $forbiddenWords = $this->forbiddenWords; // generate censor checks as soon as we load the dictionary // utilize leet equivalents as well @@ -147,6 +159,10 @@ private function generateCensorChecks($fullWords = false) { for ($x=0; $xcensorChecks = $censorChecks; From 692f68d8eecd12d5a360622883c8fdfb0cd6307e Mon Sep 17 00:00:00 2001 From: cercos Date: Sun, 28 Aug 2016 09:59:13 -0400 Subject: [PATCH 2/2] Update en-base.php Add forbidden word array --- src/dict/en-base.php | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/dict/en-base.php b/src/dict/en-base.php index a286a74..d253ab8 100644 --- a/src/dict/en-base.php +++ b/src/dict/en-base.php @@ -41,4 +41,8 @@ 'vagina', 'vulva', 'wank' -); \ No newline at end of file +); +array_push($forbiddenWords , + 'fuck', + 'shit' +);