]> git.mjollnir.org Git - s9y.git/commitdiff
Allow to define required fields.
authorgarvinhicking <garvinhicking>
Mon, 12 Sep 2005 12:04:00 +0000 (12:04 +0000)
committergarvinhicking <garvinhicking>
Mon, 12 Sep 2005 12:04:00 +0000 (12:04 +0000)
docs/NEWS
plugins/serendipity_event_spamblock/serendipity_event_spamblock.php

index c292c15790ebdca5b1fb7586693b065678d51eaf..bd9f97164da6d1fb06aa8961a8d219b6368291e4 100644 (file)
--- a/docs/NEWS
+++ b/docs/NEWS
@@ -3,6 +3,8 @@
 Version 0.9 ()
 ------------------------------------------------------------------------
 
+    * Spamblock plugin can now define required comment fields (garvinhicking)
+
     * Plugin API now allows to validate config options via a "validate"
       method, used by the plugin configuration panel. Need to set "validate"
       and "validate_error" property bag attributes in your custom 
index ea80343ac808223fb33b7ac6817daff19ce5fb3d..d8287ed68d61bf2d9bb3c7d34f34d6e4f19ed5d6 100644 (file)
@@ -82,6 +82,9 @@ if (!function_exists('serendipity_serverOffsetHour')) {
 
 @define('PLUGIN_EVENT_SPAMBLOCK_REASON_CHECKMAIL', 'Invalid e-mail address');
 @define('PLUGIN_EVENT_SPAMBLOCK_CHECKMAIL', 'Check e-mail addresses?');
+@define('PLUGIN_EVENT_SPAMBLOCK_REQUIRED_FIELDS', 'Required comment fields');
+@define('PLUGIN_EVENT_SPAMBLOCK_REQUIRED_FIELDS_DESC', 'Enter a list of required fields that need to be filled when a user comments. Seperate multiple fields with a ",". Available keys are: name, email, url, replyTo, comment');
+@define('PLUGIN_EVENT_SPAMBLOCK_REASON_REQUIRED_FIELD', 'You did not specify the %s field!');
 
 class serendipity_event_spamblock extends serendipity_event
 {
@@ -102,14 +105,14 @@ var $filter_defaults;
             'smarty'      => '2.6.7',
             'php'         => '4.1.0'
         ));
-        $propbag->add('version',       '1.23');
+        $propbag->add('version',       '1.24');
         $propbag->add('event_hooks',    array(
             'frontend_saveComment' => true,
             'external_plugin'      => true,
             'frontend_comment'     => true,
             'fetchcomments'        => true
         ));
-        $propbag->add('configuration', array('killswitch', 'bodyclone', 'ipflood', 'captchas', 'captchas_ttl', 'captcha_color', 'forcemoderation', 'disable_api_comments', 'links_moderate', 'links_reject', 'contentfilter_activate', 'contentfilter_urls', 'contentfilter_authors', 'hide_email', 'checkmail', 'logtype', 'logfile'));
+        $propbag->add('configuration', array('killswitch', 'bodyclone', 'ipflood', 'captchas', 'captchas_ttl', 'captcha_color', 'forcemoderation', 'disable_api_comments', 'links_moderate', 'links_reject', 'contentfilter_activate', 'contentfilter_urls', 'contentfilter_authors', 'hide_email', 'checkmail', 'required_fields', 'logtype', 'logfile'));
         $propbag->add('groups', array('ANTISPAM'));
 
         $this->filter_defaults = array(
@@ -150,6 +153,13 @@ var $filter_defaults;
                 $propbag->add('default', false);
                 break;
 
+            case 'required_fields':
+                $propbag->add('type', 'string');
+                $propbag->add('name', PLUGIN_EVENT_SPAMBLOCK_REQUIRED_FIELDS);
+                $propbag->add('description', PLUGIN_EVENT_SPAMBLOCK_REQUIRED_FIELDS_DESC);
+                $propbag->add('default', '');
+                break;
+
             case 'bodyclone':
                 $propbag->add('type', 'boolean');
                 $propbag->add('name', PLUGIN_EVENT_SPAMBLOCK_BODYCLONE);
@@ -351,6 +361,21 @@ var $filter_defaults;
 
                         $serendipity['csuccess'] = 'true';
                         $logfile = $this->get_config('logfile', $serendipity['serendipityPath'] . 'spamblock.log');
+                        $required_fields = $this->get_config('required_fields', '');
+
+                        // Check required fields
+                        if ($addData['type'] == 'NORMAL' && !empty($required_fields)) {
+                            $required_field_list = explode(',', $required_fields);
+                            foreach($required_field_list as $required_field) {
+                                $required_field = trim($required_field);
+                                if (empty($addData[$required_field])) {
+                                    $this->log($logfile, $eventData['id'], 'REJECTED', PLUGIN_EVENT_SPAMBLOCK_REASON_REQUIRED_FIELD, $addData);
+                                    $eventData = array('allow_comments' => false);
+                                    $serendipity['messagestack']['comments'][] = sprintf(PLUGIN_EVENT_SPAMBLOCK_REASON_REQUIRED_FIELD, $required_field);
+                                    return false;
+                                }
+                            }
+                        }
 
                         // Check for global emergency moderation
                         if ( $this->get_config('killswitch', false) === true ) {