From df4ab51dd9e3946fd5a0048298b897ec92ce1630 Mon Sep 17 00:00:00 2001 From: Shish Date: Thu, 5 Apr 2012 17:22:06 +0100 Subject: [PATCH] ban bad phrases from appearing in tags and source too --- ext/ban_words/main.php | 33 +++++++++++++++++++++++---------- 1 file changed, 23 insertions(+), 10 deletions(-) diff --git a/ext/ban_words/main.php b/ext/ban_words/main.php index f17b76bf..88fe247a 100644 --- a/ext/ban_words/main.php +++ b/ext/ban_words/main.php @@ -54,9 +54,29 @@ xanax } public function onCommentPosting(CommentPostingEvent $event) { + $this->test_text($event->comment, new CommentPostingException("Comment contains banned terms")); + } + + public function onSourceSet(SourceSetEvent $event) { + $this->test_text($event->source, new SCoreException("Source contains banned terms")); + } + + public function onTagSet(TagSetEvent $event) { + $this->test_text(Tag::implode($event->tags), new SCoreException("Tags contain banned terms")); + } + + public function onSetupBuilding(SetupBuildingEvent $event) { + $sb = new SetupBlock("Banned Phrases"); + $sb->add_label("One per line, lines that start with slashes are treated as regex
"); + $sb->add_longtext_option("banned_words"); + $event->panel->add_block($sb); + } + + private function test_text($comment, $ex) { global $config; + $banned = $config->get_string("banned_words"); - $comment = strtolower($event->comment); + $comment = strtolower($comment); foreach(explode("\n", $banned) as $word) { $word = trim(strtolower($word)); @@ -67,25 +87,18 @@ xanax else if($word[0] == '/') { // lines that start with slash are regex if(preg_match($word, $comment)) { - throw new CommentPostingException("Comment contains banned terms"); + throw $ex; } } else { // other words are literal if(strpos($comment, $word) !== false) { - throw new CommentPostingException("Comment contains banned terms"); + throw $ex; } } } } - public function onSetupBuilding(SetupBuildingEvent $event) { - $sb = new SetupBlock("Banned Phrases"); - $sb->add_label("One per line, lines that start with slashes are treated as regex
"); - $sb->add_longtext_option("banned_words"); - $event->panel->add_block($sb); - } - public function get_priority() {return 30;} } ?>