Limit commenting to only specific authorsgroups

This commit is contained in:
Garvin Hicking 2012-09-20 09:51:04 +02:00
parent 6453cff53b
commit 4477d3e0ed
3 changed files with 63 additions and 3 deletions

View file

@ -1,3 +1,8 @@
2.35:
----
Also allow posting only for specific authorgroups
2.34:
----

View file

@ -53,3 +53,6 @@
@define('PLUGIN_ADDUSER_CAPTCHA_DESC', 'Requires installed spamblock event plugin.');
@define('PLUGIN_ADDUSER_ANTISPAM', 'You did not pass the anti-spam tests. Please check if you entered the CAPTCHA correctly.');
@define('PLUGIN_ADDUSER_REGISTERED_ONLY_GROUP', 'Additionally: Only registered users in these authorgroups may post comments?');
@define('PLUGIN_ADDUSER_REGISTERED_ONLY_GROUP_DESC', 'You also need to enable the option "Only registered users may post comments" to use this. If enabled, only registered users of specific authorgroups may post comments to your entries and need to be logged in to do so.');

View file

@ -12,7 +12,7 @@ class serendipity_event_adduser extends serendipity_event
$propbag->add('description', PLUGIN_ADDUSER_DESC);
$propbag->add('stackable', false);
$propbag->add('author', 'Garvin Hicking');
$propbag->add('version', '2.34');
$propbag->add('version', '2.35');
$propbag->add('requirements', array(
'serendipity' => '0.8',
'smarty' => '2.6.7',
@ -57,6 +57,21 @@ class serendipity_event_adduser extends serendipity_event
$propbag->add('default', false);
break;
case 'registered_only_group':
$propbag->add('name', PLUGIN_ADDUSER_REGISTERED_ONLY_GROUP);
$propbag->add('description', PLUGIN_ADDUSER_REGISTERED_ONLY_GROUP_DESC);
$_groups =& serendipity_getAllGroups();
$groups = array();
foreach($_groups AS $group) {
$groups[$group['confkey']] = $group['confvalue'];
}
$propbag->add('type', 'multiselect');
$propbag->add('select_values', $groups);
$propbag->add('select_size', 5);
$propbag->add('default', 'all');
break;
case 'true_identities':
$propbag->add('type', 'boolean');
$propbag->add('name', PLUGIN_ADDUSER_REGISTERED_CHECK);
@ -74,6 +89,37 @@ class serendipity_event_adduser extends serendipity_event
$title = PLUGIN_ADDUSER_NAME;
}
// Checks whether the current author is contained in one of the gorups that need no spam checking
function inGroup() {
global $serendipity;
$checkgroups = explode('^', $this->get_config('registered_only_group'));
// Not configured, so this shall not apply.
if ($checkgroups[0] == '') {
return true;
}
if (!isset($serendipity['authorid']) || !is_array($checkgroups)) {
return false;
}
$mygroups =& serendipity_getGroups($serendipity['authorid'], true);
if (!is_array($mygroups)) {
return false;
}
foreach($checkgroups AS $key => $groupid) {
if ($groupid == 'all') {
return true;
} elseif (in_array($groupid, $mygroups)) {
return true;
}
}
return false;
}
function event_hook($event, &$bag, &$eventData, $addData = null) {
global $serendipity;
static $login_url = null;
@ -91,13 +137,19 @@ class serendipity_event_adduser extends serendipity_event
$serendipity['csuccess'] = 'true';
}
// Check for global emergency moderation
if (serendipity_db_bool($this->get_config('registered_only')) && !serendipity_userLoggedIn() && $addData['source2'] != 'adduser') {
$eventData = array('allow_comments' => false);
$serendipity['messagestack']['comments'][] = PLUGIN_ADDUSER_REGISTERED_ONLY_REASON . 'x';
$serendipity['messagestack']['comments'][] = PLUGIN_ADDUSER_REGISTERED_ONLY_REASON;
return false;
}
if (serendipity_db_bool($this->get_config('registered_only')) && $this->inGroup() && $addData['source2'] != 'adduser') {
$eventData = array('allow_comments' => false);
$serendipity['messagestack']['comments'][] = PLUGIN_ADDUSER_REGISTERED_ONLY_REASON;
return false;
}
if (serendipity_db_bool($this->get_config('true_identities')) && !serendipity_userLoggedIn()) {
$user = serendipity_db_escape_string(trim($addData['name']));
$authors = serendipity_db_query("SELECT authorid FROM {$serendipity['dbPrefix']}authors WHERE realname = '" . $user . "'");