MyBB Hacks

Full Version: Check if the user made any thread in the forum section using Template Conditionals
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2
Me again... Sorry for bothering you guys with lots of questions... Smile

I can't seem to find the correct code to check if the logged in user made any thread in the section. If he didn't make any thread then the "New Thread" button will be visible.
If the user did make a thread then the "New Thread" button will be invisible.

Any help?

Thank you.
Its looking difficult to do such using just template conditionals, because it might use to run sql query.

some thing like that;

PHP Code:
$query = $db->simple_select("threads" "uid" WHERE lastpost < dateline);
while ($yes = $db->fetch_array($query))
{
$posted_uid = $yes['uid'];

if ($mybb->user['uid'] != $posted_uid)
{
$button = "VISIBLE";
}
else
{
$button = "IN_VISIBLE";
}
}


Although its a dirty method and might not work, but gives a little idea on how to use such things. Wink

Template Conditionals doesn't allow queries for safety reasons.
But either case, hiding the New Thread button won't actually stop users from posting threads.
Is there a way to stop user to make more than one thread in one specific forum?
You'll need someone to make a plugin for that.
(11-22-2010 10:05 AM)Skiilz Wrote: [ -> ]Is there a way to stop user to make more than one thread in one specific forum?

http://forum.mybbz.net/showthread.php?tid=355
(11-22-2010 11:22 AM)leefish Wrote: [ -> ]http://mods.mybb.com/view/limit-user-threads-in-forums  << seems to fit the bill
Yes. Going to install this plugin Smile
Yes it works but admins/mods can't make it too :/ anyway to edit the plugin to make it check for GID?

PHP Code:
<?php

/**
* MyBB Plugin: Limit User Threads in Forums v 1.0
* -------------------------------------------------------------------------------------------
Special thanks to LeX, from mybbcentral.com, because without his help this plugin would not exist!
* -------------------------------------------------------------------------------------------
**/

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);
    
    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 $fid, $mybb, $db;
	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");       
		if($count)
		{
			error("You cannot post more than one thread in this forum");
		}  
	}        
}  

function limitthreadsinforums_threadbutton()
{
	global $fid, $mybb, $db, $newthread, $hide;
	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");       
			if($count)
			{
				$hide = true;
				$newthread = "";
			}  
		}  
	}   
}        

?>

Try this one;

PHP Code:
<?php

/**
* MyBB Plugin: Limit User Threads in Forums v 1.0
* -------------------------------------------------------------------------------------------
Special thanks to LeX, from mybbcentral.com, because without his help this plugin would not exist!
* -------------------------------------------------------------------------------------------
**/

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 = "";
			}  
		}  
	}   
}        

?>

Pages: 1 2
Reference URL's