vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   vBulletin 3.0 Full Releases (https://vborg.vbsupport.ru/forumdisplay.php?f=33)
-   -   is_member_of improvement. (https://vborg.vbsupport.ru/showthread.php?t=61149)

merk 02-03-2004 10:00 PM

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,

Code:

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.

PHP Code:

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. ;)

[high]* Boofo skulks away having proven to not be a good Grasshopper to Master. :([/high]

Floris 02-04-2004 01:00 PM

Quote:

Originally Posted by Boofo
You have once again proven yourself the "Master"! Thank you, very much, sir. ;)

[high]* Boofo skulks away having proven to not be a good Grasshopper to Master. :([/high]

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.
PHP Code:

function is_member_of($bbuserinfo, array(ID1ID2ID3,.....)); 

That way using is_member_of is easier to use in "dynamic" situations...

merk 02-11-2004 07:46 AM

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:
PHP Code:

// ###################### 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????

Code:

// ###################### 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:

Code:

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


All times are GMT. The time now is 01:22 PM.

Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2025, vBulletin Solutions Inc.

X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.01475 seconds
  • Memory Usage 1,764KB
  • Queries Executed 10 (?)
More Information
Template Usage:
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (3)bbcode_code_printable
  • (3)bbcode_php_printable
  • (1)bbcode_quote_printable
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)pagenav
  • (1)pagenav_curpage
  • (1)pagenav_pagelink
  • (1)post_thanks_navbar_search
  • (1)printthread
  • (10)printthreadbit
  • (1)spacer_close
  • (1)spacer_open 

Phrase Groups Available:
  • global
  • postbit
  • showthread
Included Files:
  • ./printthread.php
  • ./global.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/class_hook.php
  • ./includes/modsystem_functions.php
  • ./includes/class_bbcode_alt.php
  • ./includes/class_bbcode.php
  • ./includes/functions_bigthree.php 

Hooks Called:
  • init_startup
  • init_startup_session_setup_start
  • init_startup_session_setup_complete
  • cache_permissions
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • style_fetch
  • cache_templates
  • global_start
  • parse_templates
  • global_setup_complete
  • printthread_start
  • pagenav_page
  • pagenav_complete
  • bbcode_fetch_tags
  • bbcode_create
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • printthread_post
  • printthread_complete