Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added DISCUSSION_SPAM_CHECK trigger #206

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.idea
10 changes: 10 additions & 0 deletions README
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,13 @@ All documentation for the Discussion Plugin is available online at:
(c) 2008 - 2009 by Gina Häußge, Michael Klier <[email protected]>
(c) 2013 by Michael Hamann <[email protected]>
See COPYING for license info.

The Discussion Plugin adds the following triggers:

=== DISCUSSION_SPAM_CHECK ===

The data argument is the comment array. Developers implementing handlers for the DISCUSSION_SPAM_CHECK trigger
should be aware that the only field assured of being present is *raw* which contains the raw user input. Checks
against other fields should first check for the presence of those fields.

If the comment is spam the trigger handler should return true, which will prevent the message from being saved.
44 changes: 28 additions & 16 deletions action.php
Original file line number Diff line number Diff line change
Expand Up @@ -489,14 +489,12 @@ protected function _flattenThreads($comments, $keys = null) {
}

/**
* Adds a new comment and then displays all comments
* Checks for blocking conditions which would prevent this comment from being saved.
*
* @param array $comment
* @param string $parent
* @return bool
*/
protected function _add($comment, $parent) {
global $ID;
protected function _not_spam($comment) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you please rename it to something that is not a double negative?
(_not_spam()===false is just isSpam(), it isn't?)

global $TEXT;

$otxt = $TEXT; // set $TEXT to comment text for wordblock check
Expand All @@ -508,13 +506,35 @@ protected function _add($comment, $parent) {
return false;
}

$TEXT = $otxt; // restore global $TEXT

if (trigger_event('DISCUSSION_SPAM_CHECK', $comment)) {
msg($this->getLang('wordblock'), -1);
return false; // Comment identified as spam
}

return true;
}

/**
* Adds a new comment and then displays all comments
*
* @param array $comment
* @param string $parent
* @return bool
*/
protected function _add($comment, $parent) {
global $ID;

if ((!$this->getConf('allowguests'))
&& ($comment['user']['id'] != $_SERVER['REMOTE_USER'])
&& ($comment['user']['id'] != $_SERVER['REMOTE_USER'])
) {
return false; // guest comments not allowed
}

$TEXT = $otxt; // restore global $TEXT
if ($this->_not_spam($comment) === false) {
return false;
}

// get discussion meta file name
$file = metaFN($ID, '.comments');
Expand Down Expand Up @@ -615,18 +635,10 @@ public function save($cids, $raw, $act = NULL) {
if(!$cids) return false; // do nothing if we get no comment id

if ($raw) {
global $TEXT;

$otxt = $TEXT; // set $TEXT to comment text for wordblock check
$TEXT = $raw;

// spamcheck against the DokuWiki blacklist
if (checkwordblock()) {
msg($this->getLang('wordblock'), -1);
$comment['raw'] = $raw;
if ($this->_not_spam($comment) === false) {
return false;
}

$TEXT = $otxt; // restore global $TEXT
}

// get discussion meta file name
Expand Down
2 changes: 1 addition & 1 deletion plugin.info.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
base discussion
author Michael Hamann, Gerrit Uitslag, Gina Häussge, Christopher Smith, Michael Klier, Esther Brunner, Matthias Schulte
author Michael Hamann, Gerrit Uitslag, Gina Häussge, Christopher Smith, Michael Klier, Esther Brunner, Matthias Schulte, Clay Dowling
email [email protected]
date 2016-04-23
name discussion plugin
Expand Down