MyBB Community Forums

Full Version: COMPLETE - Thanks to LeX - Wrong Hook.
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2
I've created a plugin to prevent users from posting more than one thread is selected forums, but I've got the wrong hook and don't know which one to use.

I am currently using the newthread_do_newthread_start, and the plugin does what I want it to, but at the wrong time, and I don't know which hook or query to use to get it to work at the right time. :C

I would like the plugin to run when a user clicks the new thread button, and if they have already posted a thread in a selected forum advise that they cannot post more than one thread..

Currently it allows them to click the button and type their thread, then when they submit it, they get the cannot post more than one thread message.

I have tried hooking into showthread.php, but could not make it work.

If anyone can help get the plugin to work at the right time, it would be very much appreciated.

Here is my current code:

<?php

if(!defined("IN_MYBB"))
{
    die("Direct initialization of this file is not allowed.<br /><br />Please make sure IN_MYBB is defined.");
}

$plugins->add_hook("newthread_do_newthread_start", "limitthreadsinforums_addthread");

function limitthreadsinforums_info()
{
    return array(
        "name"            => "Limit to one thread in Forums",
        "description"    => "Limits users from posting more than one thread in selected forums!",
        "website"        => "http://community.mybb.com/user-22006.html",
        "author"        => "mark-in-dallas",
        "authorsite"    => "http://community.mybb.com/user-22006.html",
        "version"        => "1.0",
        "guid"            => "",
        "compatibility" => "14*",
    );
}

function limitthreadsinforums_activate()
{
	global $db;
	
	$limitthreadsinforums_group = array(
		"name"			=> "limitthreadsinforums",
		"title"			=> "Limit userrs to one thread in specified forums",
		"description"	=> "Limits users from posting more than one thread in specified forums",
		"disporder"		=> "2",
		"isdefault"		=> "no",
	);
	
	$db->insert_query("settinggroups", $limitthreadsinforums_group);
	$gid = $db->insert_id();
	
	$new_setting = array(
		'name'			=> 'limitthreadsinforums',
		'title'			=> 'Limit users to posting only one thread in specified forums.  Separate FIDs with commas',
		'description'	=> 'Forums to limit',
		'optionscode'	=> 'text',
		'value'			=> '',
		'disporder'		=> '1',
		'gid'			=> intval($gid)
	);

	$db->insert_query('settings', $new_setting);
	
	rebuild_settings();
}

function limitthreadsinforums_deactivate()
{
	global $db;
	

	$db->query("DELETE FROM ".TABLE_PREFIX."settings WHERE name='limitthreadsinforums'");
	$db->delete_query("settinggroups","name='limitthreadsinforums'");
	

	
	rebuild_settings();
}

function limitthreadsinforums_addthread()
{
        global $forum, $mybb, $db;
		
       if (empty($forum['fid']))
			return;	

		if (empty($mybb->settings['limitthreadsinforums']))
			return;	

		if (empty($mybb->user['uid']))
			return;				
			
			

		$limit = explode(",", $mybb->settings['limitthreadsinforums']);
		$forum = $forum['fid'];
		$user - $user['uid'];

			if (in_array($forum,$limit,$user))

		{
			error("You cannot post more than one thread in this forum");
		}
		else
		{
		return;
		}		
	
}		

?>
newthread_start
That executes at the right time, but with my current code it provents any user from posting in a selected forum. I'll have to play with the query and try to figure it out, unless you have a quick answer, which would be much appreciated. Big Grin
With the new hook are you using $fid instead of $forum['fid'] ?
Also add $fid to your globals;
Might be a good idea to hide the new thread button then aswell Smile
I tried using $fid and it allowed multiple threads to post. I think what I am missing is to query the threads table in the database to see if the user has any threads posted in selected forums, which I realized I am not currently doing.

Not quite sure how to do it though.

If you can help me finish this and want to release it as yours, if you see a benefit to it, I'd be more than happy to let you release it here or over at mybbcentral.
(2010-07-21, 08:24 PM)Lennart Sauter Wrote: [ -> ]Might be a good idea to hide the new thread button then aswell Smile

I'd LOVE to do that, but could not figure out how.
Try this one;
That works perfect! Thank you! Do you want to release it over at mybbcentral?
You brought up the idea, i've just helped you out. Its yours Wink
Ok, I appreciate it. I'd been stumbling with both this and the reps on reg plugin for days though, and would have probably spent a few more on them without your help.

I really, really appreciate you. Big Grin


One problem I have noticed is that if you select more than one forum to limit threads in, if you post a thread in any forum that's limited to one thread, it blocks you from posting in any other forum that's limited too.

Any way to keep then separated, so that if a user posts a thread in one forum thats limited, but not in another, they can still post in the other forum?
Pages: 1 2