From: garvinhicking Date: Mon, 12 Sep 2005 12:04:00 +0000 (+0000) Subject: Allow to define required fields. X-Git-Tag: 0.9~153 X-Git-Url: http://git.mjollnir.org/gw?a=commitdiff_plain;h=faf4fa40dd97847c4c246497787807d78d529e11;p=s9y.git Allow to define required fields. --- diff --git a/docs/NEWS b/docs/NEWS index c292c15..bd9f971 100644 --- 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 diff --git a/plugins/serendipity_event_spamblock/serendipity_event_spamblock.php b/plugins/serendipity_event_spamblock/serendipity_event_spamblock.php index ea80343..d8287ed 100644 --- a/plugins/serendipity_event_spamblock/serendipity_event_spamblock.php +++ b/plugins/serendipity_event_spamblock/serendipity_event_spamblock.php @@ -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 ) {