[ABD] Limit Posts Per Day

Any abandoned MODs will be moved to this forum.

WARNING: MODs in this forum are not currently being supported or maintained by the original MOD author. Proceed at your own risk.
Forum rules
IMPORTANT: MOD Development Forum rules

WARNING: MODs in this forum are not currently being supported nor updated by the original MOD author. Proceed at your own risk.
Pseudonym
Registered User
Posts: 173
Joined: Mon Jan 26, 2004 8:37 am

[ABD] Limit Posts Per Day

Post by Pseudonym »

The Limit Posts Per Day mod does exactly what it says. It allows you to set a maximum number of posts a user is allowed to make in any given timeframe (by default it's 24 hours).

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'));
?>
Put the above code in your file, and run it once. This will install the new permission that we use. I'm not sure what will happen if you run the file repeatedly, so don't. :P
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

 ?>
Before, add:

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

 ?>
Before, add:

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 ------------------------------------------------------------
 
If you want to change the settings, adjust the numbers in the DAILY_POST_LIMIT_TIMESPAN and DAILY_POST_LIMIT lines.


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,
 
Replace with:

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,
 
Replace with:

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'];
        }
    }
 
After, insert:

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! 8-)
Last edited by Pseudonym on Sun Dec 27, 2009 5:47 am, edited 2 times in total.

wowfans
Registered User
Posts: 29
Joined: Sun Mar 22, 2009 12:23 pm

Re: [BETA] Limit Posts Per Day

Post by wowfans »

Thank you. I will install your mod into my site. :) Great mod, I like it.
Sorry for my pool English.

benz0
Registered User
Posts: 30
Joined: Thu Feb 12, 2004 6:15 pm
Location: Madrid

Re: [BETA] Limit Posts Per Day

Post by benz0 »

I was awaiting this mod. This appear very simple to install.

Thank you Pseudonym !!

User avatar
Gideon5L2F
Registered User
Posts: 242
Joined: Thu Oct 09, 2003 6:33 pm
Location: New Zealand
Contact:

Re: [BETA] Limit Posts Per Day

Post by Gideon5L2F »

Pseudonym wrote:... 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 ...
Thank you, thank you, thank you. :)

But please, one more thing: It needs to differentiate between new topics and replies. For example a member (or group) may be allowed 5 replies per day (on a particular forum) but only one new topic per day. I would be very grateful for such a mod.

Gideon

Pseudonym
Registered User
Posts: 173
Joined: Mon Jan 26, 2004 8:37 am

Re: [BETA] Limit Posts Per Day

Post by Pseudonym »

Just found a bug in the LimitPostsPerDay function. The above code has been fixed.

User avatar
Gideon5L2F
Registered User
Posts: 242
Joined: Thu Oct 09, 2003 6:33 pm
Location: New Zealand
Contact:

Assessment

Post by Gideon5L2F »

My assessment of 'Limit User Posts'
  • 10 post limit worked. But is hardwired. Would be easier if adjusted in the APC.
  • New topic and reply buttons disappeared. Yep, good idea.
  • However alert message did not pop up. (a glitch?)
  • And quick-reply box remained, causing a distorted screen if reply attempted.
  • The limit is applied globally, not forum specific as claimed in the opening post.
Hey Pseudonym, this is a great idea but a little more is needed. In the APC your option is placed in global permissions but needs to be included in 'Groups forum permissions.' I have more on my wish list but you say you cant spend too much more time on it. Fair enough, but can you fix the bits mentioned?

:)

ttuu
Registered User
Posts: 224
Joined: Wed Feb 13, 2008 6:28 pm

Re: [BETA] Limit Posts Per Day

Post by ttuu »

this is the modx package for this mod:
http://rapidshare.com/files/334565368/L ... y.zip.html

Pseudonym
Registered User
Posts: 173
Joined: Mon Jan 26, 2004 8:37 am

Re: [BETA] Limit Posts Per Day

Post by Pseudonym »

Gideon5L2F wrote:[*]10 post limit worked. But is hardwired. Would be easier if adjusted in the APC.
It would be easier for the admin, but not the programmer! This is a very "quick and dirty" mod. No apologies for that - I needed something quick, and I didn't care if it was dirty. :P
[*]New topic and reply buttons disappeared. Yep, good idea.
[*]However alert message did not pop up. (a glitch?)
Ahah. Yes, I hadn't thought that through properly. The message will appear on the Post Message form page, but of course, they'll never see it if the New Topic and Reply buttons aren't there to reach it in the first place. D'oh!

Is there an existing warning notice that can be shown on the view_topic page? If so, it might be reasonably easy to add our warning to it, without having to add any new functions or template changes.
[*]And quick-reply box remained, causing a distorted screen if reply attempted.
Bugger. I don't use quick-reply, so I forgot it even existed. I don't know how it works, so I can't suggest an easy remedy .
[*]The limit is applied globally, not forum specific as claimed in the opening post.
Hmm. The theory was that you should be able to assign the limit to specific forums using forum permissions. If that's not available, there's a problem with the way the permission was installed (not fault - not yours). Unfortunately, I don't know enough about how they work, either.
I have more on my wish list but you say you cant spend too much more time on it. Fair enough, but can you fix the bits mentioned?
Right now, I'm struggling to find time to moderate my forum, let alone develop the new functionality it needs, let alone go back and polish a mod that's doing all I require as it is. Sorry mate - I know it's not the answer you wanted, but this mod is clearly provided on an "as is, where is" basis!


ttuu - thanks for packaging the mod as modx. Yet another thing I didn't have time to learn how to do!


I'd love to see this mod go places, so if anyone else feels able to pick it up and run with it, please do.

cuongsalem
Registered User
Posts: 1
Joined: Sat Jan 16, 2010 10:32 am

Re: [BETA] Limit Posts Per Day

Post by cuongsalem »

Thank for this mod, but I want a different thing. I want to limit the number of topics are opened for a specific forum per day.

User avatar
Coert
Registered User
Posts: 151
Joined: Mon May 18, 2009 7:16 pm
Location: Switzerland

Re: [BETA] Limit Posts Per Day

Post by Coert »

cuongsalem wrote:Thank for this mod, but I want a different thing. I want to limit the number of topics are opened for a specific forum per day.
-bump-

Avdon
Registered User
Posts: 186
Joined: Tue Jun 02, 2009 4:55 pm
Location: Germany
Name: Danny Alkhaldy

Re: [BETA] Limit Posts Per Day

Post by Avdon »

Coert wrote:
cuongsalem wrote:Thank for this mod, but I want a different thing. I want to limit the number of topics are opened for a specific forum per day.
-bump-

combuster
Registered User
Posts: 342
Joined: Sun Oct 26, 2008 11:58 pm

Re: [BETA] Limit Posts Per Day

Post by combuster »

This is goes in the direction of a mod, that I'm searching for since Jan 2009.. when is this mod going to be released?

Feature request (Example of what I'm looking for):
group1: 1 post per hour
group2: 2 posts per 10 minutes

Komanche
Registered User
Posts: 248
Joined: Thu Aug 02, 2007 10:49 am
Location: Czech Republic

Re: [BETA] Limit Posts Per Day

Post by Komanche »

Avdon wrote:
Coert wrote:
cuongsalem wrote:Thank for this mod, but I want a different thing. I want to limit the number of topics are opened for a specific forum per day.
-bump-
me too

gennyna
Registered User
Posts: 72
Joined: Mon Apr 06, 2009 7:29 pm

Re: [BETA] Limit Posts Per Day

Post by gennyna »

I just added this mod and serves as the great

braddeicide
Registered User
Posts: 2
Joined: Sun Oct 26, 2008 1:03 am

Re: [BETA] Limit Posts Per Day

Post by braddeicide »

I'd also like to see this functionality included in default installation. It'd just be another permission amongst others so it shouldn't be hard to integrate.

Locked

Return to “[3.0.x] Abandoned MODs”