ban bad phrases from appearing in tags and source too
This commit is contained in:
parent
fdb6727f41
commit
df4ab51dd9
@ -54,9 +54,29 @@ xanax
|
|||||||
}
|
}
|
||||||
|
|
||||||
public function onCommentPosting(CommentPostingEvent $event) {
|
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<br/>");
|
||||||
|
$sb->add_longtext_option("banned_words");
|
||||||
|
$event->panel->add_block($sb);
|
||||||
|
}
|
||||||
|
|
||||||
|
private function test_text($comment, $ex) {
|
||||||
global $config;
|
global $config;
|
||||||
|
|
||||||
$banned = $config->get_string("banned_words");
|
$banned = $config->get_string("banned_words");
|
||||||
$comment = strtolower($event->comment);
|
$comment = strtolower($comment);
|
||||||
|
|
||||||
foreach(explode("\n", $banned) as $word) {
|
foreach(explode("\n", $banned) as $word) {
|
||||||
$word = trim(strtolower($word));
|
$word = trim(strtolower($word));
|
||||||
@ -67,25 +87,18 @@ xanax
|
|||||||
else if($word[0] == '/') {
|
else if($word[0] == '/') {
|
||||||
// lines that start with slash are regex
|
// lines that start with slash are regex
|
||||||
if(preg_match($word, $comment)) {
|
if(preg_match($word, $comment)) {
|
||||||
throw new CommentPostingException("Comment contains banned terms");
|
throw $ex;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
// other words are literal
|
// other words are literal
|
||||||
if(strpos($comment, $word) !== false) {
|
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<br/>");
|
|
||||||
$sb->add_longtext_option("banned_words");
|
|
||||||
$event->panel->add_block($sb);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function get_priority() {return 30;}
|
public function get_priority() {return 30;}
|
||||||
}
|
}
|
||||||
?>
|
?>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user