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
Skiilz Offline
Member
***
Posts: 198
Joined: Nov 2010
Post: #1
Check if the user made any thread in the forum section using Template Conditionals
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.

[Image: 468x602b.png]
(This post was last modified: 11-22-2010 08:39 AM by Skiilz.)
11-22-2010 07:08 AM
Find all posts by this user Quote this message in a reply
Imran Offline
Member
***
Posts: 204
Joined: Apr 2010
Post: #2
RE: Check if the user made any thread in the forum section using TC
Its looking difficult to do such using just template conditionals, because it might use to run sql query.

some thing like that;

PHP Code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
$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


[Image: logo.png]

[Image: twitter.png]
11-22-2010 08:40 AM
Visit this user's website Find all posts by this user Quote this message in a reply
ZiNgA BuRgA Offline
Fag
*******
Posts: 3,338
Joined: Jan 2008
Post: #3
RE: Check if the user made any thread in the forum section using Template Conditionals
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.

My Blog
11-22-2010 09:00 AM
Find all posts by this user Quote this message in a reply
Skiilz Offline
Member
***
Posts: 198
Joined: Nov 2010
Post: #4
RE: Check if the user made any thread in the forum section using Template Conditionals
Is there a way to stop user to make more than one thread in one specific forum?

[Image: 468x602b.png]
(This post was last modified: 11-22-2010 10:05 AM by Skiilz.)
11-22-2010 10:05 AM
Find all posts by this user Quote this message in a reply
ZiNgA BuRgA Offline
Fag
*******
Posts: 3,338
Joined: Jan 2008
Post: #5
RE: Check if the user made any thread in the forum section using Template Conditionals
You'll need someone to make a plugin for that.

My Blog
11-22-2010 11:02 AM
Find all posts by this user Quote this message in a reply
leefish Offline
Hamster
*******
Posts: 1,009
Joined: Apr 2010
Post: #6
RE: Check if the user made any thread in the forum section using Template Conditionals
http://mods.mybb.com/view/limit-user-threads-in-forums  << seems to fit the bill


[Image: leelink.gif]
MYBB1.6 & XThreads
11-22-2010 11:22 AM
Visit this user's website Find all posts by this user Quote this message in a reply
Imran Offline
Member
***
Posts: 204
Joined: Apr 2010
Post: #7
RE: Check if the user made any thread in the forum section using Template Conditionals
(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

[Image: logo.png]

[Image: twitter.png]
11-22-2010 06:01 PM
Visit this user's website Find all posts by this user Quote this message in a reply
Skiilz Offline
Member
***
Posts: 198
Joined: Nov 2010
Post: #8
RE: Check if the user made any thread in the forum section using Template Conditionals
(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

[Image: 468x602b.png]
(This post was last modified: 11-23-2010 02:22 AM by Skiilz.)
11-22-2010 11:07 PM
Find all posts by this user Quote this message in a reply
Skiilz Offline
Member
***
Posts: 198
Joined: Nov 2010
Post: #9
RE: Check if the user made any thread in the forum section using Template Conditionals
Yes it works but admins/mods can't make it too :/ anyway to edit the plugin to make it check for GID?

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

?>


[Image: 468x602b.png]
11-23-2010 02:22 AM
Find all posts by this user Quote this message in a reply
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 »

 Standard Tools
Forum Jump: