<?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_start", "limitthreadsinforums_addthread");
$plugins->add_hook("forumdisplay_thread", "limitthreadsinforums_threadbutton");
function limitthreadsinforums_info()
{
return array(
"name" => "Limit user threads in forums",
"description" => "Prevent users from posting more than one thread in certain 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" => "59c0f556b72c6ed5999fb583671782be",
"compatibility" => "14*,16",
);
}
function limitthreadsinforums_activate()
{
global $db;
$limitthreadsinforums_group = array(
"name" => "limitthreadsinforums",
"title" => "Limit user threads in forums",
"description" => "Prevent users from posting more than one thread in select forums",
"disporder" => "2",
"isdefault" => "no",
);
$db->insert_query("settinggroups", $limitthreadsinforums_group);
$gid = $db->insert_id();
$new_setting = array(
'name' => 'limitthreadsinforums',
'title' => 'Prevent users from posting more than one thread in these forums.',
'description' => 'Forums to limit by fid # separated by commas',
'optionscode' => 'text',
'value' => '',
'disporder' => '1',
'gid' => intval($gid)
);
$db->insert_query('settings', $new_setting);
$new_setting = array(
'name' => 'limitthreadsinforumsgrp',
'title' => 'Mods and Admins User Groups.',
'description' => 'Enter here Mods and Admin Group IDs, separate each with commas.',
'optionscode' => 'text',
'value' => '3,4,6',
'disporder' => '2',
'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->query("DELETE FROM ".TABLE_PREFIX."settings WHERE name='limitthreadsinforumsgrp'");
$db->delete_query("settinggroups","name='limitthreadsinforums'");
rebuild_settings();
}
function limitthreadsinforums_addthread()
{
global $fid, $mybb, $db, $groupscache;
if(!$fid || !$mybb->settings['limitthreadsinforums'] || !$mybb->user['uid'])
{
return;
}
$fids = $db->escape_string($mybb->settings['limitthreadsinforums']);
if(in_array($fid, explode(",", $fids)))
{
$count = $db->fetch_field($db->simple_select("threads", "COUNT(*) as threads", "uid='{$mybb->user['uid']}' AND fid='{$fid}'"), "threads");
$grpid = $mybb->user['usergroup'];
$addgrpid = explode(",",$mybb->settings['limitthreadsinforumsgrp']);
if($count && !in_array($grpgid,$addgrpid))
{
error("You cannot post more than one thread in this forum");
}
}
}
function limitthreadsinforums_threadbutton()
{
global $fid, $mybb, $db, $newthread, $hide, $groupscache;
if(!$fid || !$mybb->settings['limitthreadsinforums'] || !$mybb->user['uid'])
{
return;
}
$hide = false;
$fids = $db->escape_string($mybb->settings['limitthreadsinforums']);
if(!$hide)
{
if(in_array($fid, explode(",", $fids)))
{
$count = $db->fetch_field($db->simple_select("threads", "COUNT(*) as threads", "uid='{$mybb->user['uid']}' AND fid='{$fid}'"), "threads");
$grpid = $mybb->user['usergroup'];
$addgrpid = explode(",",$mybb->settings['limitthreadsinforumsgrp']);
if($count && !in_array($grpgid,$addgrpid))
{
$hide = true;
$newthread = "";
}
}
}
}
?>
|