View source for Handler: Spam-Protection for comments

#||
||
Compatible with: !!(green)**R4.2**!!
Current version:
Credits: ((user:AhA AhA))
| {{toc numerate=1 from="h2" to="h4"}} ||
||#

===Concerned files:==
  * **~/handlers/show.php**
  * **~/handlers/addcomment.php**
  * **~/lang/wacko.xy.php**

===Documentation==
for users available for copy and paste

===How to / Changes==
====Step one==
Add the following changes to the file **/handlers/page/show.php**:

Go to the lines 225/226 and you'll find the following code:
%%(php)
<textarea name="body" rows="6" cols="7" style="width: 100%"></textarea><br />
<input type="submit" value="<?php echo $this->_t('AttachCommentButton'); ?>" accesskey="s" />
%%

Add the following code between the lines 225 and 226 (sorry, it's in german):
%%(php)
Schutz gegen Spam: Schreibe die Zahlen von 1-5 in das Feld  
<input name="nospam" type="text" value="" />  
%%

Instead of 2 lines, you get now the following 4 lines:
%%(php)
<textarea name="body" rows="6" cols="7" style="width: 100%"></textarea><br />
Schutz gegen Spam: Schreibe die Zahlen von 1-5 in das Feld  
<input name="nospam" type="text" value="" />  
<input type="submit" value="<?php echo $this->_t('AttachCommentButton'); ?>" accesskey="s" />
%%

====Step two==
Add the following changes to the file **/handlers/page/addcomment.php**:

1. Go to the lines 16/17, where you'll find the following code:
%%(php)
$body = trim($_POST['body']);
echo "Comment".$num."<p>".$body."<p>".$this->tag;
%%

Add the following code between line 16 and 17:
%%(php)
$nospam = trim($_POST['nospam']);
%%

The whole thing (lines 16, 17, 18):
%%(php)
$body = trim($_POST['body']);
$nospam = trim($_POST['nospam']);
echo "Comment".$num."<p>".$body."<p>".$this->tag;
%%

2. Go to the lines 20-22, where you'll find the following code:
%%(php)
$this->set_message($this->_t('EmptyComment'));
}
else
%%

Add the following code after line 21:
%%(php)
elseif (!strchr($nospam, "12345")) {
// Antispam-number must be entered
$this->set_message($this->_t('AntiSpam')); 
}
%%

The whole new thing (lines 20-27):
%%(php)
 $this->set_message($this->_t('EmptyComment'));
}  
elseif (!strchr($nospam, "12345")) {
// Antispam-number must be entered
$this->set_message($this->_t('AntiSpam')); 
}
else
%%

====Step three==
Add the following line to the file **/lang/wacko.de.php** or your preferred localization-file:
%%(php)
"AntiSpam"    => "Schreibe die erforderlichen Angaben in das Feld.",
%%

====Localization (optional)==
put this at the end of your language file 

**lang/custom.<lang>.php**
%%
//hacks
'YourPhrase' => 'your translation here',
%%

**[xy] proposed translations**
[de] ...
[fr]
[ru]

===To Do==
  *

{{backlinks}}

===Personal remarks==
The hack is in german and "written" by an absolute "layman" (non-professional), but it functions and it is easy to install. Download the zip-file, unzip it and just copy the 3 files in the indicated directories (don't forget to rename the originals!

[[http://www.osrm.ch/~AHeutsch/wackowikisfc.zip Download]]

Good luck