Addpixel / KirbyComments

[Kirby 2] File-based comments stored as subpages for the Kirby CMS.
MIT License
68 stars 5 forks source link

Blacklist for manual spam comments #21

Closed gerritvanaaken closed 7 years ago

gerritvanaaken commented 7 years ago

You could check the message and title and other fields for certain keywords, especially urls like "superseospam.org". Comments that contain those strings get kicked out, or even better: The system could once pretend to have successfully added the comment, but it will be absent on the next fresh visit of the page!

Blacklist keywords might be edited in config (okay-ish) or in the panel (great!!)

florianpircher commented 7 years ago

Kirby Comments version 1.5 now supports hooks which you can use to block comments by any criteria you like. This is much more flexible than a list of word, as you can decide which fields on what pages to block.

For blocking comments, use the decide-block-comment hook.

c::set('comments.hooks.decide-block-comment', function ($comments, $comment) {

  if (preg_match('/WordPress/i', $comment->message()) {
    throw new Exception('You shall not use the word “WordPress”!', 400);
  }

  if (strpos($comment->website(), 'http://www.5z8.info') !== false) {
    throw new Exception('5z8.info links are not allowed.', 401);
  }

  if ($comment->name() === $comment->page()->title()) {
    throw new Exception('You can not reuse the page title as your name!', 402);
  }

});
splorp commented 7 years ago

How extensible is the decide-block-comment hook?

This way of defining criteria seems like it would start to break if you have several hundred blocked terms or sites.

florianpircher commented 7 years ago

The decide-block-comment is only invoked during preview and submission. Comments that have already been stored are never handled by this hook.

Checking hundreds of terms is no problem. You could even request a list of terms from a database and it would still be fast enough. Note that the message field (and all other fields) has a character limit. Comments, which have more characters than specified by that limit will be blocked by Kirby Comments before they are given to the decide-block-comment hook.

splorp commented 7 years ago

Ok, that’s good to know. Thanks for the clarification.

Now, what about checking against something as large as my Comment Blacklist for WordPress which has nearly 24,000 entries?