Thread Rating:
  • 0 Votes - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
 Check if the user made any thread in the forum section using Template Conditionals
Imran Offline
Member
***
Posts: 204
Joined: Apr 2010
Post: #10
RE: Check if the user made any thread in the forum section using Template Conditionals
Try this one;

PHP Code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
<?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 = "";
			}  
		}  
	}   
}        

?>


[Image: logo.png]

[Image: twitter.png]
(This post was last modified: 11-23-2010 02:39 AM by Imran.)
11-23-2010 02:38 AM
Visit this user's website Find all posts by this user Quote this message in a reply

« Next Oldest | Next Newest »

Messages In This Thread
RE: Check if the user made any thread in the forum section using Template Conditionals - Imran - 11-23-2010 02:38 AM

 Standard Tools
Forum Jump: