It works on a permissions basis, so you can grant this post-limiting "permission" to an individual, or to a group. You can also apply the post restriction globally to every forum, or just in one or two (the only limitation is that even if you only apply it to one forum, it will search all forums when counting a user's posts).
You can change the number of posts allowed per timeframe, and the length of that timeframe.
I'm publishing this mod because of the number of people asking for it, however it now does everything I need. I therefore won't be adding any new features and I don't have time to provide any support for it. Sorry! If anyone else wants to take this mod and continue developing it, feel free. I've marked this mod as BETA, because I won't be developing it further, but I'm using on my own live site. (Obviously, as with any mod install, make sure you back up everything first, and thoroughly test it before going live.)
So, without further ado, here are the install instructions:
----------------------------------------------------------------------------------------------------------
Create a new file in the root folder of your site called modinstall.php (or whatever you like - it really doesn't matter)
Code: Select all
<?php
define('IN_PHPBB', true);
$phpbb_root_path = './';
$phpEx = substr(strrchr(__FILE__, '.'), 1);
include($phpbb_root_path . 'common.' . $phpEx);
$user->session_begin();
$auth->acl($user->data);
$user->setup();
include($phpbb_root_path . 'includes/acp/auth.' . $phpEx);
$auth_admin = new auth_admin();
$result = $auth_admin->acl_add_option(array(
'local' => array('u_limit_posts_per_day'),
'global' => array('u_limit_posts_per_day')
));
print ('Permissions install ' . ($result ? 'completed successfully' : 'failed'));
?>
Delete this file when you're done.
Now we need to add a few language variables. Open up language/en/common.php (or your own language equivalent). Find the end of the file:
Code: Select all
?>
Code: Select all
//-- mod: LimitPostsPerDay ------------------------------------------------------------
$lang = array_merge($lang, array(
'acl_u_limit_posts_per_day' => array('lang' => 'Only allowed to make a limited number of posts per day', 'cat' => 'post'),
'POST_PER_DAY_LIMIT_REACHED' => 'You have reached your daily post limit. You are allowed to make %d posts per %d-hour period.<br />Please try again later.'
));
//-- end: LimitPostsPerDay ------------------------------------------------------------
Now we add the post-checking function. Open up includes/functions.php. Find the end of the file:
Code: Select all
?>
Code: Select all
//-- mod: LimitPostsPerDay ------------------------------------------------------------
/* Check to see whether daily post limit has been reached */
define('DAILY_POST_LIMIT_TIMESPAN', 24); // 24 hours
define('DAILY_POST_LIMIT', 5); // 5 posts per day
function LimitPostsPerDay($forum_id)
{
global $LimitPostsPerDay, $db, $auth, $user;
// Have we run this check already? No sense in doing it twice.
if (isset($LimitPostsPerDay))
{
return $LimitPostsPerDay;
}
// Do we have the "limited post" permission set?
if ($auth->acl_get('u_limit_posts_per_day', $forum_id))
{
$sql = 'SELECT count(post_id) as post_count
FROM ' . POSTS_TABLE . '
WHERE post_time > ' . (time() - 3600 * DAILY_POST_LIMIT_TIMESPAN) . '
AND poster_id = ' . $user->data['user_id'];
$row = $db->sql_fetchrow($db->sql_query($sql));
if ($row['post_count'] >= DAILY_POST_LIMIT)
{
return true; // Limit posts. We've made all we're allowed.
}
}
return false; // We haven't hit our limit (or we haven't been set as a limited user). Woohoo! No limits!
}
//-- end: LimitPostsPerDay ------------------------------------------------------------
Now open viewforum.php. Find:
Code: Select all
'S_DISPLAY_POST_INFO' => ($forum_data['forum_type'] == FORUM_POST && ($auth->acl_get('f_post', $forum_id) || $user->data['user_id'] == ANONYMOUS)) ? true : false,
Code: Select all
//-- mod: LimitPostsPerDay ------------------------------------------------------------
/*
'S_DISPLAY_POST_INFO' => ($forum_data['forum_type'] == FORUM_POST && ($auth->acl_get('f_post', $forum_id) || $user->data['user_id'] == ANONYMOUS)) ? true : false,
*/
'S_DISPLAY_POST_INFO' => ($forum_data['forum_type'] == FORUM_POST && (($auth->acl_get('f_post', $forum_id) && !LimitPostsPerDay($forum_id)) || $user->data['user_id'] == ANONYMOUS)) ? true : false,
//-- end: LimitPostsPerDay ------------------------------------------------------------
Open viewtopic.php. Find:
Code: Select all
'S_DISPLAY_POST_INFO' => ($topic_data['forum_type'] == FORUM_POST && ($auth->acl_get('f_post', $forum_id) || $user->data['user_id'] == ANONYMOUS)) ? true : false,
'S_DISPLAY_REPLY_INFO' => ($topic_data['forum_type'] == FORUM_POST && ($auth->acl_get('f_reply', $forum_id) || $user->data['user_id'] == ANONYMOUS)) ? true : false,
Code: Select all
//-- mod: LimitPostsPerDay ------------------------------------------------------------
/*
'S_DISPLAY_POST_INFO' => ($topic_data['forum_type'] == FORUM_POST && ($auth->acl_get('f_post', $forum_id) || $user->data['user_id'] == ANONYMOUS)) ? true : false,
'S_DISPLAY_REPLY_INFO' => ($topic_data['forum_type'] == FORUM_POST && ($auth->acl_get('f_reply', $forum_id) || $user->data['user_id'] == ANONYMOUS)) ? true : false,
*/
'S_DISPLAY_POST_INFO' => ($topic_data['forum_type'] == FORUM_POST && (($auth->acl_get('f_post', $forum_id) && !LimitPostsPerDay($forum_id)) || $user->data['user_id'] == ANONYMOUS)) ? true : false,
'S_DISPLAY_REPLY_INFO' => ($topic_data['forum_type'] == FORUM_POST && (($auth->acl_get('f_post', $forum_id) && !LimitPostsPerDay($forum_id)) || $user->data['user_id'] == ANONYMOUS)) ? true : false,
//-- end: LimitPostsPerDay ------------------------------------------------------------
Open posting.php. Find:
Code: Select all
$error[] = $user->lang['FLOOD_ERROR'];
}
}
Code: Select all
//-- mod: LimitPostsPerDay ------------------------------------------------------------
if ($mode != 'edit' && !$preview && !$refresh && LimitPostsPerDay($forum_id))
{
$error[] = sprintf($user->lang['POST_PER_DAY_LIMIT_REACHED'], DAILY_POST_LIMIT);
}
//-- end: LimitPostsPerDay ------------------------------------------------------------
Now you just need to log into the Admin Control Panel, edit the permission for the appropriate user or group, and set the "Only allowed to make a limited number of posts per day" option to YES. Simple!