View Full Version : Check usergroup of thread starters in threadbit
addamroy
02-19-2013, 05:34 PM
I'm looking for an if condition that can check for the usergroup of the thread starter for each thread in the thread list via the threadbit template.
In posts I show certain content in the postbit_legacy template that only shows if the thread starter is in a certain usergroup. For that I use the following condition (where 60 would be the usergroup id)
<vb:if condition="is_member_of($post, 60)">
Show content here
</vb:if>
However I this condition doesn't work in the threadbit template.
Just edited this, I just need a thread starter conditional for the threadbit template.
addamroy
02-21-2013, 12:21 PM
Anyone?
Try using $thread['usergroupid']. I don't know how it gets there, but it looks like it's there.
addamroy
02-23-2013, 12:26 PM
That's actually pulling the usergroup ID of the last post... for some reason. Instead of the thread starter.
Well, in that case you'd need to have a plugin get the usergroup and set a field that you can test in the template.
addamroy
02-24-2013, 05:58 PM
Hmm that makes sense. Unfortunately all I know for php and vb coding is if-else conditions lol, learning though. Can you give me some guidance on how to accomplish the usergroup check via a bulletin, so i can use a condition in the threadbit template for it?
mokujin
02-24-2013, 07:06 PM
Try this everywhere in threadbit template: <vb:if condition="$thread['usergroupid'] == 60">Your text here</vb:if>
addamroy
02-24-2013, 10:34 PM
We already tried that suggestion (via a post above), unfortunately that checks the usergroup of the last poster, not the thread starter.
Lynne
02-24-2013, 11:03 PM
Unfortunately, looking at the query shows me the there is a JOIN with the user table based on the lastposterid, not the postuserid. This means you would need to write a query to find out the usergroup. That is one query per thread listed. It's a simple query which will probably be just fine on a non-busy site or one that is not on an overloaded shared server, but it's something you should think about.
addamroy
02-24-2013, 11:51 PM
I'm not a php guru dude at all, I just have a vague understanding of the basics and can only write the most basic of code (like I'll go back and forth from dreamweaver to php.net copy/pasting etc :) ) but i do understand what you mean.
There is not ANY data available in threadbit besides the username of the threadstarter?
Wouldn't it be simple enough just to add each username to an array, then check all the usernames in the array and and assign their usergroups with one query, before each individual thread is loaded? Like I said I don't know too much about PHP and wouldn't know how to create such a function, but since the username is available and there are no duplicate usernames in the db couldn't it be done by creating one array and executing one query with it?
LifesGreatestGift
02-25-2013, 04:46 AM
create new plugin
Hook Location: threadbit_display
Title: usergroup check for threadstarter in threadbit
Plugin PHP Code:
$current_thread = $thread['threadid'];
$query = $vbulletin->db->query_first_slave("
SELECT user.usergroupid, user.membergroupids
FROM " . TABLE_PREFIX . "thread AS thread
LEFT JOIN " . TABLE_PREFIX . "user AS user ON (user.userid = thread.firstpostid)
WHERE thread.threadid = " . $current_thread . "
");
$primary_group = $query['usergroupid'];
$secondary_groups = $query['membergroupids'];
if(!empty($secondary_groups)) {
$groups = $primary_group . "," . $secondary_groups;
} else {
$groups = $primary_group;
}
$groups_all = explode(",", $groups);
vB_Template::preRegister('threadbit',array('group' => $groups_all));
then in template threadbit
You could do
<vb:if condition="in_array(6, $group)">This thread starter is in admin group</vb:if>
The 6 being the group you want to check, and this example 6 is the Administrator group.
This checks the primary and additional groups of a thread starter.
addamroy
02-25-2013, 02:43 PM
Thanks!
Like Lynne said about the additional queries, I really only want to do this one or two sections of the forum. Is there anyway to have the plug-in only run that query for specific forums?
LifesGreatestGift
02-25-2013, 02:48 PM
if (in_array($thread['forumid'], array(1,2,3)))
{
$current_thread = $thread['threadid'];
$query = $vbulletin->db->query_first_slave("
SELECT user.usergroupid, user.membergroupids
FROM " . TABLE_PREFIX . "thread AS thread
LEFT JOIN " . TABLE_PREFIX . "user AS user ON (user.userid = thread.firstpostid)
WHERE thread.threadid = " . $current_thread . "
");
$primary_group = $query['usergroupid'];
$secondary_groups = $query['membergroupids'];
if(!empty($secondary_groups)) {
$groups = $primary_group . "," . $secondary_groups;
} else {
$groups = $primary_group;
}
$groups_all = explode(",", $groups);
vB_Template::preRegister('threadbit',array('group' => $groups_all));
}
change 1,2,3 to forums you want it to run in.
addamroy
02-25-2013, 03:01 PM
When I go to save the threadbit template after inserting your if conditional, I get the following error message:
"Warning: Invalid argument supplied for foreach() in [path]/includes/functions.php on line 3568
Forum Message
The following error occurred when attempting to evaluate this template:
%1$s
This is likely caused by a malformed conditional statement. It is highly recommended that you fix this error before continuing, but you may continue as-is if you wish."
LifesGreatestGift
02-25-2013, 03:47 PM
Kudos to LifesGreatestGift for writing the plugin. But I think there may be one small problem: on this line:
LEFT JOIN " . TABLE_PREFIX . "user AS user ON (user.userid = thread.firstpostid)
I think you want thread.postuserid instead of thread.firstpostid.
As is, if you do a var_dump on $groups it shows the proper primary and secondary groups of the threadstarter.
The code works, I just messed up the "Specific forums" conditional.
if (in_array($thread['forumid'], array(1,2,3)))
please review other mods and vB code for proper usage. But other than that, the code is sound, and taken directly from forumdisplay.php
--------------- Added 1361811270 at 1361811270 ---------------
When I go to save the threadbit template after inserting your if conditional, I get the following error message:
"Warning: Invalid argument supplied for foreach() in [path]/includes/functions.php on line 3568
Forum Message
The following error occurred when attempting to evaluate this template:
%1$s
This is likely caused by a malformed conditional statement. It is highly recommended that you fix this error before continuing, but you may continue as-is if you wish."
you must be doing something wrong because the code is tested as working 100% on vanilla vbulletin 4.2 pl3
--------------- Added 1361811317 at 1361811317 ---------------
i didnt even mess up the conditional it all works 100%
--------------- Added 1361811597 at 1361811597 ---------------
It was throwing an error, try this code
if (in_array($thread['forumid'], array(3,4,5)))
{
$current_thread = $thread['threadid'];
$query = $vbulletin->db->query_first_slave("
SELECT user.usergroupid, user.membergroupids
FROM " . TABLE_PREFIX . "thread AS thread
LEFT JOIN " . TABLE_PREFIX . "user AS user ON (user.userid = thread.firstpostid)
WHERE thread.threadid = " . $current_thread . "
");
$primary_group = $query['usergroupid'];
$secondary_groups = $query['membergroupids'];
if(!empty($secondary_groups)) {
$groups = $primary_group . "," . $secondary_groups;
} else {
$groups = $primary_group;
}
$groups_all = explode(",", $groups);
} else {
$groups_all = array();
}
vB_Template::preRegister('threadbit',array('group' => $groups_all));
LifesGreatestGift
02-25-2013, 04:00 PM
change 3,4,5 to forums you want it ran in.
--------------- Added 1361812033 at 1361812033 ---------------
if (in_array($thread['forumid'], array(3,4,5)))
{
$current_thread = $thread['threadid'];
$query = $vbulletin->db->query_first_slave("
SELECT user.usergroupid, user.membergroupids
FROM " . TABLE_PREFIX . "thread AS thread
LEFT JOIN " . TABLE_PREFIX . "user AS user ON (user.userid = thread.firstpostid)
WHERE thread.threadid = " . $current_thread . "
");
$primary_group = $query['usergroupid'];
$secondary_groups = $query['membergroupids'];
if(!empty($secondary_groups)) {
$groups = $primary_group . "," . $secondary_groups;
} else {
$groups = $primary_group;
}
$groups_all = explode(",", $groups);
} else {
$groups_all = array();
}
vB_Template::preRegister('threadbit',array('group' => $groups_all));
This is the proper working code. The reason the first conditional threw an error was because when you visit a forum not listed in the 3,4,5 the template threadbit was still looking for the $group array and it wasn't defined. New code puts null array in place so there isn't an error.
addamroy
02-25-2013, 05:54 PM
Still getting the same error.
I'm using vb 4.1.12 if that makes any difference (since you said you tested on 4.2)? I don't believe I have any mods doing anything in the threaddisplay hook or threadbit template at all so I can't think of what might be conflicting
LifesGreatestGift
02-25-2013, 06:16 PM
post me the conditional you are using exactly as is. or just post the contents of threadbit template in code tags.
mokujin
02-25-2013, 08:15 PM
Isn't there some vb code somewhere that's depending on the last poster information being there?
I dont know :D
LifesGreatestGift
02-25-2013, 08:31 PM
lol, ridiculous.
--------------- Added 1361827948 at 1361827948 ---------------
then when you upgrade its something else to remember to change.
--------------- Added 1361828625 at 1361828625 ---------------
also, my code accounts not only a users primary usergroup, but additional usergroups as well.
addamroy
02-25-2013, 09:56 PM
post me the conditional you are using exactly as is. or just post the contents of threadbit template in code tags.
I pasted the conditional exactly as you put it. Here's how I was using it
<!-- test usergroup check -->
<vb:if condition="is_member_of($bbuserinfo, 6)">
<vb:if condition="in_array(6, $group)">
style=""
</vb:if>
</vb:if>
<!-- test usergroup check -->
I'm testing this with usergroup 6 until I get it working then I would remove the first conditional, and then edit the second one accordingly.
I get the error when I try to save that.
If I do just this, it saves ok.
<!-- test usergroup check -->
<vb:if condition="is_member_of($bbuserinfo, 6)">
style=""
</vb:if>
<!-- test usergroup check -->
LifesGreatestGift
02-25-2013, 10:48 PM
maybe try this, not sure why it would matter.
<vb:if condition="in_array('6', $group)">STUFF</vb:if>
and to be honest, it may be a bug in your vB version that was fixed in a later release.
addamroy
02-26-2013, 12:36 AM
Hmm, you had it working in 4.1.12?
I'm running patch level 2 now, but there is a patch level 3 available that I haven't updated the forum with yet.
LifesGreatestGift
02-26-2013, 02:27 AM
it works flawlessly in vb 4.2.0 pl3
addamroy
02-26-2013, 03:00 AM
hmm.
Well thanks for all the help guys it's always awesome when everyone comes together like that. This thread will be here for 4.2.x users anyway lifesgreatest that's pretty awesome that you provided the plug-in to accomplish this.
Unfortunately my forum is so heavily customized and with various mods I'm always nervous about semi-major updates. ie 4.0 to 4.1 or 4.1 to 4.2 etc. Stuff breaks and I end up running around like a chicken with my head cut off on my test forum trying to make everything work again. lol, you know how it is.
If I ever figure out why it's working in 4.2 and not 4.1 I'll come back and let you guys know.
addamroy
03-02-2013, 07:04 PM
lifesgreatest, if the reason it's not working in 4.1.12 is because of a bug, what file or files would you assume be causing this problem?
I might be able to submit a support ticket and get vbstaff to confirm it is in fact a bug.
vBulletin® v3.8.12 by vBS, Copyright ©2000-2025, vBulletin Solutions Inc.