View Full Version : is_member_of improvement.
Requested by Boofo
Some people want to check for multiple groups at once, instead of having to slam OR is_member_of(anothercheck) together for each group, if you apply this hack it will be simple to check for multiple groups.
The format for the function is now,
is_member_of($bbuserinfo, ID1, ID2, ID3,.....);
Just seperate each group by a comma, no need for extra quotes or anything.
Find the function in includes/functions.php ~line 190 and replace it with the following.
This should not affect any current is_member_of conditionals you're using.
function is_member_of()
{
static $argpad, $user_memberships;
$usergroupids = func_get_args();
$userinfo = array_shift($usergroupids);
// check primary usergroup against given usergroupids
if(in_array($userinfo['usergroupid'], $usergroupids))
{
return true;
}
// if we dont already have membergroupids, fetch them.
if(!is_array($user_memberships["$userinfo[userid]"]))
{
$user_memberships["$userinfo[userid]"] = fetch_membergroupids_array($userinfo);
}
foreach($usergroupids as $usergroupid)
{
if(in_array($usergroupid, $user_memberships["$userinfo[userid]"]))
{
return true;
}
}
return false;
}
Boofo
02-04-2004, 07:14 AM
You have once again proven yourself the "Master"! Thank you, very much, sir. ;)
* Boofo skulks away having proven to not be a good Grasshopper to Master. :(
Floris
02-04-2004, 01:00 PM
You have once again proven yourself the "Master"! Thank you, very much, sir. ;)
* Boofo skulks away having proven to not be a good Grasshopper to Master. :(
Great work, and thank you for sharing. You are a good and kind person.
LeeCHeSSS
02-04-2004, 02:39 PM
Wouldn't it be easier to allow the second argument to be an array with usergroup id's?
ie.
function is_member_of($bbuserinfo, array(ID1, ID2, ID3,.....));
That way using is_member_of is easier to use in "dynamic" situations...
MY initial use of array() in the conditionals didnt work, maybe because of the way it is evaluated.
If you can work out if array() works in conditionals it would be an easy modification to the code
LeeCHeSSS
02-11-2004, 08:51 AM
Try this:
// ###################### Start is member of #######################
// returns true/false if a $userinfo belongs to $usergroupid
// $userinfo must contain (userid, usergroupid, membergroupids)
function is_member_of($userinfo, $usergroupid)
{
static $user_memberships;
if (!is_array($user_memberships["$userinfo[userid]"])) {
$user_memberships["$userinfo[userid]"] = fetch_membergroupids_array($userinfo);
}
if (is_array($usergroupid)) {
for ($i = 0; $i < sizeof($usergroupid); $i++) {
if ($userinfo['usergroupid'] == $usergroupid[$i]) {
return true;
} else if (in_array($usergroupid[$i], $user_memberships["$userinfo[userid]"])) {
return true;
}
}
} else {
if ($userinfo['usergroupid'] == $usergroupid) {
return true;
} else {
return in_array($usergroupid, $user_memberships["$userinfo[userid]"]);
}
}
}
Gary King
03-10-2004, 09:47 PM
Interesting hack, should be useful to many :)
mcyates
12-12-2004, 04:21 PM
What exactly do i raplace????
// ###################### Start is member of #######################
// returns true/false if a $userinfo belongs to $usergroupid
// $userinfo must contain (userid, usergroupid, membergroupids)
function is_member_of($userinfo, $usergroupid)
{
static $user_memberships;
if ($userinfo['usergroupid'] == $usergroupid)
{
// user's primary usergroup is $usergroupid - return true
return true;
}
else if (!is_array($user_memberships["$userinfo[userid]"]))
{
// fetch membergroup ids
$user_memberships["$userinfo[userid]"] = fetch_membergroupids_array($userinfo);
}
// return true/false depending on membergroup ids
return in_array($usergroupid, $user_memberships["$userinfo[userid]"]);
}
chris2707
12-12-2004, 04:31 PM
Replace all of it unless you've previously hacked that function.
mcyates
12-12-2004, 04:37 PM
replaced it all and i got this:
Fatal error: Cannot redeclare is_member_of() (previously declared in /usr/home/yates238/public_html/includes/functions.php:176) in /usr/home/yates238/public_html/includes/functions.php on line 208
amykhar
12-12-2004, 04:44 PM
replaced it all and i got this:
Fatal error: Cannot redeclare is_member_of() (previously declared in /usr/home/yates238/public_html/includes/functions.php:176) in /usr/home/yates238/public_html/includes/functions.php on line 208
Then you didn't replace it all. Go back and make sure you got the whole function.
mcyates
12-12-2004, 04:54 PM
Then you didn't replace it all. Go back and make sure you got the whole function.
LeeCHeSSS script worked, but the orignal one didn't. I'll try your hack now. Thanks for the support.
noppid
12-27-2004, 10:54 PM
A template only mod to do this is available here if you would like to avoid editing php files.
http://www.vbulletintemplates.com/mods/showthread.php?t=7570
Boofo
07-30-2005, 02:28 AM
Has this been added to 3.5 RC 1?
amykhar
07-30-2005, 03:06 AM
It's built in. Go read the code and you'll see that Jelsoft was wise and merciful and no hack is needed any more.
Boofo
07-30-2005, 05:13 AM
Great! Then we can still use it in templates the way Merk descibed, now, right?
amykhar
07-30-2005, 01:59 PM
Yep. But, slightly changed:
<if condition="is_member_of($vbulletin->userinfo,6,5)">
Hello World!
</if>
Paul M
07-30-2005, 03:01 PM
$bbuserinfo should still work in templates shouldn't it ?
amykhar
07-30-2005, 03:34 PM
$bbuserinfo should still work in templates shouldn't it ?
Yes. But, I try to upgrade to the new style when adding new conditionals.
vBulletin® v3.8.12 by vBS, Copyright ©2000-2025, vBulletin Solutions Inc.