Update of /cvsroot/php-blog/serendipity/plugins/serendipity_event_spamblock
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv25628/plugins/serendipity_event_spamblock
Modified Files:
Tag: branch-smarty
serendipity_event_spamblock.php
Added Files:
Tag: branch-smarty
Comic_Sans_MS.ttf Impact.ttf Verdana.ttf
Log Message:
MFH spamblock tweaks.
Todo: Comments don't seem to be working in this branch ATM. PostgreSQL seems to be emitting every comment twice. Needs to be looked at
--- NEW FILE: Impact.ttf ---
(This appears to be a binary file; contents omitted.)
--- NEW FILE: Verdana.ttf ---
(This appears to be a binary file; contents omitted.)
Index: serendipity_event_spamblock.php
===================================================================
RCS file: /cvsroot/php-blog/serendipity/plugins/serendipity_event_spamblock/serendipity_event_spamblock.php,v
retrieving revision 1.4.2.3
retrieving revision 1.4.2.4
diff -u -d -r1.4.2.3 -r1.4.2.4
--- serendipity_event_spamblock.php 22 Sep 2004 10:58:59 -0000 1.4.2.3
+++ serendipity_event_spamblock.php 22 Sep 2004 15:25:33 -0000 1.4.2.4
@@ -1,172 +1,333 @@
-<?php # $Id$
-
-switch ($serendipity['lang']) {
- default:
- @define('PLUGIN_EVENT_SPAMBLOCK_TITLE', 'Spam Protector');
- @define('PLUGIN_EVENT_SPAMBLOCK_DESC', 'A varity of methods to prevent comment spam');
- @define('PLUGIN_EVENT_SPAMBLOCK_ERROR_BODY', 'Spam Prevention: Invalid message.');
- @define('PLUGIN_EVENT_SPAMBLOCK_ERROR_IP', 'Spam Prevention: You cannot post a comment so soon after submitting another one.');
- @define('PLUGIN_EVENT_SPAMBLOCK_ERROR_RBL', 'Spam Prevention: The IP of the computer you are posting from, is listed as an open relay.');
- @define('PLUGIN_EVENT_SPAMBLOCK_ERROR_KILLSWITCH', 'This blog is in "Emergency Comment Blockage Mode", please come back another time');
- @define('PLUGIN_EVENT_SPAMBLOCK_BODYCLONE', 'Do not allow duplicate comments');
- @define('PLUGIN_EVENT_SPAMBLOCK_BODYCLONE_DESC', 'Do not allow users to submit a comment which contains the same body as an already submitted comment');
- @define('PLUGIN_EVENT_SPAMBLOCK_KILLSWITCH', 'Emergency comment shutdown');
- @define('PLUGIN_EVENT_SPAMBLOCK_KILLSWITCH_DESC', 'Temporarily disable comments for all entries. Useful if your blog is under spam attack.');
- @define('PLUGIN_EVENT_SPAMBLOCK_IPFLOOD', 'IP block interval');
- @define('PLUGIN_EVENT_SPAMBLOCK_IPFLOOD_DESC', 'Only allow an IP to submit a comment every n minutes. Useful to prevent comment floods.');
- @define('PLUGIN_EVENT_SPAMBLOCK_RBL', 'Block comments from RBL-listed hosts');
- @define('PLUGIN_EVENT_SPAMBLOCK_RBL_DESC', 'Blocks comments based on provided RPL lists. Avoid lists with dynamic hosts.');
- break;
-}
-
-class serendipity_event_spamblock extends serendipity_event
-{
-var $services;
-
- function introspect(&$propbag)
- {
- global $serendipity;
-
- $propbag->add('name', PLUGIN_EVENT_SPAMBLOCK_TITLE);
- $propbag->add('description', PLUGIN_EVENT_SPAMBLOCK_DESC);
- $propbag->add('event_hooks', array(
- 'frontend_saveComment' => true,
- 'external_plugin' => true
- ));
- $propbag->add('configuration', array('bodyclone', 'killswitch', 'ipflood', 'rbl'));
- }
-
- function introspect_config_item($name, &$propbag)
- {
- switch($name) {
- case 'bodyclone':
- $propbag->add('type', 'boolean');
- $propbag->add('name', PLUGIN_EVENT_SPAMBLOCK_BODYCLONE);
- $propbag->add('description', PLUGIN_EVENT_SPAMBLOCK_BODYCLONE_DESC);
- $propbag->add('default', true);
- break;
-
- case 'killswitch':
- $propbag->add('type', 'boolean');
- $propbag->add('name', PLUGIN_EVENT_SPAMBLOCK_KILLSWITCH);
- $propbag->add('description', PLUGIN_EVENT_SPAMBLOCK_KILLSWITCH_DESC);
- $propbag->add('default', false);
- break;
-
- case 'ipflood':
- $propbag->add('type', 'string');
- $propbag->add('name', PLUGIN_EVENT_SPAMBLOCK_IPFLOOD);
- $propbag->add('description', PLUGIN_EVENT_SPAMBLOCK_IPFLOOD_DESC);
- $propbag->add('default', 2);
- break;
-
- case 'rbl':
- $propbag->add('type', 'string');
- $propbag->add('name', PLUGIN_EVENT_SPAMBLOCK_RBL);
- $propbag->add('description', PLUGIN_EVENT_SPAMBLOCK_RBL_DESC);
- $propbag->add('default', 'sbl-xbl.spamhaus.org, bl.spamcop.net');
- break;
-
- default:
- return false;
- }
-
- return true;
- }
-
-
- function generate_content(&$title) {
- $title = PLUGIN_EVENT_SPAMBLOCK_TITLE;
- }
-
- function event_hook($event, &$bag, &$eventData, $addData = null) {
- global $serendipity;
-
- $hooks = &$bag->get('event_hooks');
- if (isset($hooks[$event])) {
- switch($event) {
- case 'frontend_saveComment':
- if (!is_array($eventData) || serendipity_db_bool($eventData['allow_comments'])) {
-
- if ( $this->get_config('killswitch', false) === true ) {
- $eventData = array('allow_comments' => false);
- $serendipity['messagestack']['comments'][] = PLUGIN_EVENT_SPAMBLOCK_ERROR_KILLSWITCH;
- return false;
- }
-
- // Check for identical comments.
- if ( $this->get_config('bodyclone', true) === true ) {
- $query = "SELECT count(id) AS counter FROM {$serendipity['dbPrefix']}comments WHERE body = '" . serendipity_db_escape_string($addData['comment']) . "'";
- $row = serendipity_db_query($query, true);
- if (is_array($row) && $row['counter'] > 0) {
- $eventData = array('allow_comments' => false);
- $serendipity['messagestack']['comments'][] = PLUGIN_EVENT_SPAMBLOCK_ERROR_BODY;
- return false;
- }
- }
-
- // Check last IP
- if ( $this->get_config('ipflood', 2) != 0 ) {
- $query = "SELECT max(timestamp) AS last_post FROM {$serendipity['dbPrefix']}comments WHERE ip = '" . serendipity_db_escape_string($_SERVER['REMOTE_ADDR']) . "'";
- $row = serendipity_db_query($query, true);
- if (is_array($row) && $row['last_post'] > (time() - $this->get_config('ipflood', 2)*60)) {
- $eventData = array('allow_comments' => false);
- $serendipity['messagestack']['comments'][] = PLUGIN_EVENT_SPAMBLOCK_ERROR_IP;
- return false;
- }
- }
-
- // Check for IP listed in RBL
- // Partly based on work done by James Seward (ja...@ja...)
- if ( $this->get_config('rbl') != '' ) {
- $remoteIP = $_SERVER['REMOTE_ADDR'];
- # $remoteIP = '81.70.69.193';
-
- $rbls = explode(',', $this->get_config('rbl'));
- if (preg_match("/([0-9]+)\.([0-9]+)\.([0-9]+)\.([0-9]+)/", $remoteIP, $res)) {
- array_shift($res);
- $reverseIP = implode('.', array_reverse($res));
- foreach ($rbls as $rbl) {
- $rblhost = $reverseIP .'.'. trim($rbl);
- if (gethostbyname($rblhost) != $rblhost) {
- $eventData = array('allow_comments' => false);
- $serendipity['messagestack']['comments'][] = PLUGIN_EVENT_SPAMBLOCK_ERROR_RBL;
- return false;
- }
- }
- }
- }
- }
- return true;
- break;
-
- case 'external_plugin':
- $parts = explode('_', $eventData);
- if (!empty($parts[1])) {
- $param = (int) $parts[1];
- } else {
- $param = null;
- }
-
- $methods = array('kaptcha');
-
- if (!in_array($parts[0], $methods)) {
- return;
- }
-
- echo 'kaptcha!';
- return true;
- break;
-
- default:
- return false;
- break;
- }
- } else {
- return false;
- }
- }
-}
-
-/* vim: set sts=4 ts=4 expandtab : */
-?>
+<?php # $Id$
+
+switch ($serendipity['lang']) {
+ default:
+ @define('PLUGIN_EVENT_SPAMBLOCK_TITLE', 'Spam Protector');
+ @define('PLUGIN_EVENT_SPAMBLOCK_DESC', 'A varity of methods to prevent comment spam');
+ @define('PLUGIN_EVENT_SPAMBLOCK_ERROR_BODY', 'Spam Prevention: Invalid message.');
+ @define('PLUGIN_EVENT_SPAMBLOCK_ERROR_IP', 'Spam Prevention: You cannot post a comment so soon after submitting another one.');
+ @define('PLUGIN_EVENT_SPAMBLOCK_ERROR_RBL', 'Spam Prevention: The IP of the computer you are posting from, is listed as an open relay.');
+ @define('PLUGIN_EVENT_SPAMBLOCK_ERROR_KILLSWITCH', 'This blog is in "Emergency Comment Blockage Mode", please come back another time');
+ @define('PLUGIN_EVENT_SPAMBLOCK_BODYCLONE', 'Do not allow duplicate comments');
+ @define('PLUGIN_EVENT_SPAMBLOCK_BODYCLONE_DESC', 'Do not allow users to submit a comment which contains the same body as an already submitted comment');
+ @define('PLUGIN_EVENT_SPAMBLOCK_KILLSWITCH', 'Emergency comment shutdown');
+ @define('PLUGIN_EVENT_SPAMBLOCK_KILLSWITCH_DESC', 'Temporarily disable comments for all entries. Useful if your blog is under spam attack.');
+ @define('PLUGIN_EVENT_SPAMBLOCK_IPFLOOD', 'IP block interval');
+ @define('PLUGIN_EVENT_SPAMBLOCK_IPFLOOD_DESC', 'Only allow an IP to submit a comment every n minutes. Useful to prevent comment floods.');
+ @define('PLUGIN_EVENT_SPAMBLOCK_RBL', 'Block comments from RBL-listed hosts');
+ @define('PLUGIN_EVENT_SPAMBLOCK_RBL_DESC', 'Blocks comments based on provided RPL lists. Avoid lists with dynamic hosts.');
+ @define('PLUGIN_EVENT_SPAMBLOCK_CAPTCHAS', 'Enable Captchas');
+ @define('PLUGIN_EVENT_SPAMBLOCK_CAPTCHAS_DESC', 'Will force the user to input a random string displayed in a specially crafted image. This will disallow automatted submits to your blog. Please remember that people with decreased vision may find it hard to read those captchas.');
+ @define('PLUGIN_EVENT_SPAMBLOCK_CAPTCHAS_USERDESC', 'To prevent automatted Bots from commentspamming, please enter the string you see in the image below in the appropriate input box. Only if the strings match, your comment will be submitted: ');
+ @define('PLUGIN_EVENT_SPAMBLOCK_CAPTCHAS_USERDESC2', 'Enter the string you see here in the input box!');
+ @define('PLUGIN_EVENT_SPAMBLOCK_CAPTCHAS_USERDESC3', 'Enter the string from the spam-prevention image above: ');
+ @define('PLUGIN_EVENT_SPAMBLOCK_ERROR_CAPTCHAS', 'You did not enter the correct string displayed in the spam-prevention image box. Please look at the image and enter the values displayed there.');
+ @define('PLUGIN_EVENT_SPAMBLOCK_ERROR_NOTTF', 'Captchas disabled on your server. You need GDLib and freetype libraries compiled to PHP, and need the .TTF files residing in your directory.');
+
+ @define('PLUGIN_EVENT_SPAMBLOCK_CAPTCHAS_TTL', 'Force captchas after how many days');
+ @define('PLUGIN_EVENT_SPAMBLOCK_CAPTCHAS_TTL_DESC', 'Captchas can be enforced depending on the age of your articles. Enter the amount of days after which entering a correct captcha is necessary. If set to 0, captchas will always be used.');
+ @define('PLUGIN_EVENT_SPAMBLOCK_FORCEMODERATION', 'Force comment moderation after how many days');
+ @define('PLUGIN_EVENT_SPAMBLOCK_FORCEMODERATION_DESC', 'You can automatically set all comments for entries to be moderated. Enter the age of an entry in days, after which it should be auto-moderated. 0 means no auto-moderation.');
+ @define('PLUGIN_EVENT_SPAMBLOCK_LINKS_MODERATE', 'How many links before a comment gets moderated');
+ @define('PLUGIN_EVENT_SPAMBLOCK_LINKS_MODERATE_DESC', 'When a comment reaches a certain amount of links, that comment can be set to be moderated. 0 means that no link-checking is done.');
+ @define('PLUGIN_EVENT_SPAMBLOCK_LINKS_REJECT', 'How many links before a comment gets rejected');
+ @define('PLUGIN_EVENT_SPAMBLOCK_LINKS_REJECT_DESC', 'When a comment reaches a certain amount of links, that comment can be set to be moderated. 0 means that no link-checking is done.');
+
+ @define('PLUGIN_EVENT_SPAMBLOCK_NOTICE_MODERATION', 'Because of some conditions, your comment has been marked to require moderation by the owner of this blog.');
+ break;
+}
+
+class serendipity_event_spamblock extends serendipity_event
+{
+var $services;
+
+ function introspect(&$propbag)
+ {
+ global $serendipity;
+
+ $propbag->add('name', PLUGIN_EVENT_SPAMBLOCK_TITLE);
+ $propbag->add('description', PLUGIN_EVENT_SPAMBLOCK_DESC);
+ $propbag->add('event_hooks', array(
+ 'frontend_saveComment' => true,
+ 'external_plugin' => true,
+ 'frontend_comment' => true
+ ));
+ $propbag->add('configuration', array('bodyclone', 'killswitch', 'ipflood', 'rbl', 'captchas', 'captchas_ttl', 'forcemoderation', 'links_moderate', 'links_kill'));
+ }
+
+ function introspect_config_item($name, &$propbag)
+ {
+ switch($name) {
+ case 'bodyclone':
+ $propbag->add('type', 'boolean');
+ $propbag->add('name', PLUGIN_EVENT_SPAMBLOCK_BODYCLONE);
+ $propbag->add('description', PLUGIN_EVENT_SPAMBLOCK_BODYCLONE_DESC);
+ $propbag->add('default', true);
+ break;
+
+ case 'captchas':
+ if (function_exists('imagettftext')) {
+ $propbag->add('type', 'boolean');
+ $propbag->add('name', PLUGIN_EVENT_SPAMBLOCK_CAPTCHAS);
+ $propbag->add('description', PLUGIN_EVENT_SPAMBLOCK_CAPTCHAS_DESC);
+ $propbag->add('default', true);
+ }
+ break;
+
+ case 'killswitch':
+ $propbag->add('type', 'boolean');
+ $propbag->add('name', PLUGIN_EVENT_SPAMBLOCK_KILLSWITCH);
+ $propbag->add('description', PLUGIN_EVENT_SPAMBLOCK_KILLSWITCH_DESC);
+ $propbag->add('default', false);
+ break;
+
+ case 'ipflood':
+ $propbag->add('type', 'string');
+ $propbag->add('name', PLUGIN_EVENT_SPAMBLOCK_IPFLOOD);
+ $propbag->add('description', PLUGIN_EVENT_SPAMBLOCK_IPFLOOD_DESC);
+ $propbag->add('default', 2);
+ break;
+
+ case 'rbl':
+ $propbag->add('type', 'string');
+ $propbag->add('name', PLUGIN_EVENT_SPAMBLOCK_RBL);
+ $propbag->add('description', PLUGIN_EVENT_SPAMBLOCK_RBL_DESC);
+ $propbag->add('default', 'sbl-xbl.spamhaus.org, bl.spamcop.net');
+ break;
+
+ case 'captchas_ttl':
+ $propbag->add('type', 'string');
+ $propbag->add('name', PLUGIN_EVENT_SPAMBLOCK_CAPTCHAS_TTL);
+ $propbag->add('description', PLUGIN_EVENT_SPAMBLOCK_CAPTCHAS_TTL_DESC);
+ $propbag->add('default', '7');
+ break;
+
+ case 'forcemoderation':
+ $propbag->add('type', 'string');
+ $propbag->add('name', PLUGIN_EVENT_SPAMBLOCK_FORCEMODERATION);
+ $propbag->add('description', PLUGIN_EVENT_SPAMBLOCK_FORCEMODERATION_DESC);
+ $propbag->add('default', '60');
+ break;
+
+ case 'links_moderate':
+ $propbag->add('type', 'string');
+ $propbag->add('name', PLUGIN_EVENT_SPAMBLOCK_LINKS_MODERATE);
+ $propbag->add('description', PLUGIN_EVENT_SPAMBLOCK_LINKS_MODERATE_DESC);
+ $propbag->add('default', '10');
+ break;
+
+ case 'links_reject':
+ $propbag->add('type', 'string');
+ $propbag->add('name', PLUGIN_EVENT_SPAMBLOCK_LINKS_REJECT);
+ $propbag->add('description', PLUGIN_EVENT_SPAMBLOCK_LINKS_REJECT_DESC);
+ $propbag->add('default', '20');
+ break;
+
+ default:
+ return false;
+ }
+
+ return true;
+ }
+
+
+ function generate_content(&$title) {
+ $title = PLUGIN_EVENT_SPAMBLOCK_TITLE;
+ }
+
+ function event_hook($event, &$bag, &$eventData, $addData = null) {
+ global $serendipity;
+
+ $hooks = &$bag->get('event_hooks');
+
+ if (isset($hooks[$event])) {
+ $captchas_ttl = $this->get_config('captchas_ttl', 7);
+ $captchas = (serendipity_db_bool($this->get_config('captchas', true)) && function_exists('imagettftext') ? true : false);
+ // Check if the entry is older than the allowed amount of time. Enforce kaptchas if that is true
+ // of if kaptchas are activated for every entry
+ $show_captcha = ($captchas && isset($eventData['timestamp']) && ($captchas_ttl < 1 || ($eventData['timestamp'] < (time() - ($captchas_ttl*60*60*24)))) ? true : false);
+
+ $forcemoderation = $this->get_config('forcemoderation', 1);
+ $links_moderate = $this->get_config('links_moderate', 10);
+ $links_reject = $this->get_config('links_reject', 20);
+
+ switch($event) {
+ case 'frontend_saveComment':
+ if (!is_array($eventData) || serendipity_db_bool($eventData['allow_comments'])) {
+
+ if ( $this->get_config('killswitch', false) === true ) {
+ $eventData = array('allow_comments' => false);
+ $serendipity['messagestack']['comments'][] = PLUGIN_EVENT_SPAMBLOCK_ERROR_KILLSWITCH;
+ return false;
+ }
+
+ // Check for identical comments.
+ if ( $this->get_config('bodyclone', true) === true ) {
+ $query = "SELECT count(id) AS counter FROM {$serendipity['dbPrefix']}comments WHERE body = '" . serendipity_db_escape_string($addData['comment']) . "'";
+ $row = serendipity_db_query($query, true);
+ if (is_array($row) && $row['counter'] > 0) {
+ $eventData = array('allow_comments' => false);
+ $serendipity['messagestack']['comments'][] = PLUGIN_EVENT_SPAMBLOCK_ERROR_BODY;
+ return false;
+ }
+ }
+
+ // Check last IP
+ if ( $this->get_config('ipflood', 2) != 0 ) {
+ $query = "SELECT max(timestamp) AS last_post FROM {$serendipity['dbPrefix']}comments WHERE ip = '" . serendipity_db_escape_string($_SERVER['REMOTE_ADDR']) . "'";
+ $row = serendipity_db_query($query, true);
+ if (is_array($row) && $row['last_post'] > (time() - $this->get_config('ipflood', 2)*60)) {
+ $eventData = array('allow_comments' => false);
+ $serendipity['messagestack']['comments'][] = PLUGIN_EVENT_SPAMBLOCK_ERROR_IP;
+ return false;
+ }
+ }
+
+ // Check for IP listed in RBL
+ // Partly based on work done by James Seward (ja...@ja...)
+ if ( $this->get_config('rbl') != '' ) {
+ $remoteIP = $_SERVER['REMOTE_ADDR'];
+ # $remoteIP = '81.70.69.193';
+
+ $rbls = explode(',', $this->get_config('rbl'));
+ if (preg_match("/([0-9]+)\.([0-9]+)\.([0-9]+)\.([0-9]+)/", $remoteIP, $res)) {
+ array_shift($res);
+ $reverseIP = implode('.', array_reverse($res));
+ foreach ($rbls as $rbl) {
+ $rblhost = $reverseIP .'.'. trim($rbl);
+ if (gethostbyname($rblhost) != $rblhost) {
+ $eventData = array('allow_comments' => false);
+ $serendipity['messagestack']['comments'][] = PLUGIN_EVENT_SPAMBLOCK_ERROR_RBL;
+ return false;
+ }
+ }
+ }
+ }
+
+ // Captcha checking
+ if ($show_captcha) {
+ if (!isset($serendipity['POST']['captcha']) || strtolower($serendipity['POST']['captcha']) != strtolower($_SESSION['spamblock']['captcha'])) {
+ $eventData = array('allow_comments' => false);
+ $serendipity['messagestack']['comments'][] = PLUGIN_EVENT_SPAMBLOCK_ERROR_CAPTCHAS;
+ return false;
+ }
+ }
+
+ // Check for forced moderation
+ if ($forcemoderation > 0 && $eventData['timestamp'] < (time() - ($forcemoderation * 60 * 60 * 24))) {
+ $eventData['moderate_comments'] = true;
+ $serendipity['messagestack']['comments'][] = PLUGIN_EVENT_SPAMBLOCK_NOTICE_MODERATION;
+ return false;
+ }
+
+ $link_count = substr_count(strtolower($addData['comment']), 'http://');
+ if ($links_reject > 0 && $link_count > $links_reject) {
+ $eventData = array('allow_comments' => false);
+ $serendipity['messagestack']['comments'][] = PLUGIN_EVENT_SPAMBLOCK_ERROR_BODY;
+ return false;
+ }
+
+ if ($links_moderate > 0 && $link_count > $links_moderate) {
+ $eventData['moderate_comments'] = true;
+ $serendipity['messagestack']['comments'][] = PLUGIN_EVENT_SPAMBLOCK_NOTICE_MODERATION;
+ return false;
+ }
+ }
+ return true;
+ break;
+
+ case 'frontend_comment':
+ if ($show_captcha) {
+ echo '<div class="serendipity_commentDirection">';
+ if (!isset($serendipity['POST']['preview']) || strtolower($serendipity['POST']['captcha'] != strtolower($_SESSION['spamblock']['captcha']))) {
+ printf('<br />' . PLUGIN_EVENT_SPAMBLOCK_CAPTCHAS_USERDESC . '<br /><label for="captcha"><img src="%s" title="%s" alt="CAPTCHA" class="captcha" /></label><br />',
+ $serendipity['baseURL'] . ($serendipity['rewrite'] == 'none' ? $serendipity['indexFile'] . '?/' : '') . 'plugin/captcha_' . md5(time()),
+ htmlspecialchars(PLUGIN_EVENT_SPAMBLOCK_CAPTCHAS_USERDESC2)
+ );
+ echo PLUGIN_EVENT_SPAMBLOCK_CAPTCHAS_USERDESC3 . '<input type="text" size="5" name="serendipity[captcha]" value="" id="captcha" />';
+ } elseif (isset($serendipity['POST']['captcha'])) {
+ echo '<input type="hidden" name="serendipity[captcha]" value="' . htmlspecialchars($serendipity['POST']['captcha']) . '" />';
+ }
+ echo '</div>';
+ }
+ return true;
+ break;
+
+
+ case 'external_plugin':
+ $parts = explode('_', $eventData);
+ if (!empty($parts[1])) {
+ $param = (int) $parts[1];
+ } else {
+ $param = null;
+ }
+
+ $methods = array('captcha');
+
+ if (!in_array($parts[0], $methods) || !function_exists('imagettftext')) {
+ return;
+ }
+
+ $width = 120;
+ $height = 40;
+ $max_char = 5;
+ $min_char = 3;
+
+ $fontfiles = array('Comic_Sans_MS.ttf', 'Impact.ttf', 'Verdana.ttf');
+ $chars = array(2, 3, 4, 7, 9); // 1, 5, 6 and 8 may look like characters.
+ $chars = array_merge($chars, array('A','B','C','D','E','F','H','J','K','L','M','N','P','Q','R','T','U','V','W','X','Y','Z')); // I, O, S may look like numbers
+ $strings = array_rand($chars, mt_rand($max_char, $min_char));
+ $string = '';
+ foreach($strings AS $idx => $charidx) {
+ $string .= $chars[$charidx];
+ }
+ $_SESSION['spamblock'] = array('captcha' => $string);
+
+ $font = $serendipity['serendipityPath'] . 'plugins/serendipity_event_spamblock/' . $fontfiles[array_rand($fontfiles)];
+ if (!file_exists($font)) {
+ die(PLUGIN_EVENT_SPAMBLOCK_ERROR_NOTTF);
+ }
+
+ header('Content-Type: image/jpeg');
+ $image = imagecreate($width, $height);
+ imagecolorallocate($image, 0, 0, 0);
+ // imagettftext($image, 10, 1, 1, 15, imagecolorallocate($image, 255, 255, 255), $font, 'String: ' . $string);
+
+ $pos_x = 5;
+ foreach($strings AS $idx => $charidx) {
+ $color = imagecolorallocate($image, mt_rand(50, 255), mt_rand(50, 255), mt_rand(50,255));
+ $size = mt_rand(15, 21);
+ $angle = mt_rand(-20, 20);
+ $pos_y = ceil($height - (mt_rand($size/3, $size/2)));
+
+ imagettftext(
+ $image,
+ $size,
+ $angle,
+ $pos_x,
+ $pos_y,
+ $color,
+ $font,
+ $chars[$charidx]
+ );
+
+ $pos_x = $pos_x + $size + 2;
+
+ }
+ imagejpeg($image, '', 90);
+ imagedestroy($image);
+ return true;
+ break;
+
+ default:
+ return false;
+ break;
+ }
+ } else {
+ return false;
+ }
+ }
+}
+
+/* vim: set sts=4 ts=4 expandtab : */
+?>
--- NEW FILE: Comic_Sans_MS.ttf ---
(This appears to be a binary file; contents omitted.)
|