2010-07-21, 07:11 PM
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:
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;
}
}
?>