Rate limiting creation of new thread

Probably a strange arrangement, but the idea is to limit the rate at which a user can post in a forum, for example, only one new thread every 24 hours. This is to limit new thread, not reply.

What would be the best way to approach this? Is there a simple way to query the time stamp of the most recent thread created by the user in the current forum? This would need to be a live query instead of relying on statistics collected by the cron jobs.

Any suggestions would be very much appreciated. Thanks.
 
Extend this action using the load_class_controller event:

XenForo_ControllerPublic_Forum::actionAddThread

The skeleton of your extended class would look like this:

Code:
<?php

class YourAddon_ControllerPublic_Forum extends XFCP_YourAddon_ControllerPublic_Forum
{
	public function actionAddThread()
	{
		// IF USER HAS POSTED A THREAD IN THE LAST 24 HOURS THEN RETURN ERROR

		return parent::actionAddThread();
	}
}

Then of course you need to fill in your code to check if the user has posted in the last 24 hours.
 
i would extend the model instead of the controller...

the method which returns if you're allowed to create threads is: XenForo_Model_Forum::canPostThreadInForum
 
reason:

1. you'll need to change actionAddThread AND actionCreateThread with the way jake suggested (or alternative: use _preDispatch )
2. you'll need some other changes too, so it's IMO much better, to change direct the only method, which returns if you're allowed to create threads, or not:)


you could also change _assertCanPostThreadInForum in the controller, but i've run into some problems as i've tried it.
there's at least 1 place in the code, where they didn't use _assertCanPostThreadInForum and called direct XenForo_Model_Forum::canPostThreadInForum


but that's just the way which i prefer to change permissions via code:)
 
Thanks Jake for the heads up. I started down that path, and had a stub implemented to test the plumbing, my code gets called, a good start.

Then I realised the check is done after the attempt to "create" the thread, and it threw an ugly error message (incidentally, how does one provide a friendly error message in cases like these?). So the permission option crossed my mind, i.e. to stop the creation of the thread in the first place. But I'm not sure where to start.

ragtek's reply is timely, if I understood correctly, the model approach would stop the thread creation in the first place, is this correct? Can you provide a quick tip on how to hook into XenForo_Model_Forum::canPostThreadInForum? I will look through the forum in the meantime and see if I can find other model extension hints.

Thanks.
 
Top Bottom