Go Back   vb.org Archive > vBulletin Modifications > Archive > vB.org Archives > vBulletin 3.0 > vBulletin 3.0 Full Releases

Reply
 
Thread Tools
is_member_of improvement. Details »»
is_member_of improvement.
Version: 1.00, by merk merk is offline
Developer Last Online: Mar 2012 Show Printable Version Email this Page

Version: 3.0.0 Rating:
Released: 02-03-2004 Last Update: Never Installs: 9
 
No support by the author.

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;

Show Your Support

  • This modification may not be copied, reproduced or published elsewhere without author's permission.

Comments
  #2  
Old 02-04-2004, 07:14 AM
Boofo's Avatar
Boofo Boofo is offline
 
Join Date: Mar 2002
Location: Des Moines, IA (USA)
Posts: 15,776
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

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]
Reply With Quote
  #3  
Old 02-04-2004, 01:00 PM
Floris Floris is offline
 
Join Date: Jan 2002
Posts: 1,898
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

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.
Reply With Quote
  #4  
Old 02-04-2004, 02:39 PM
LeeCHeSSS's Avatar
LeeCHeSSS LeeCHeSSS is offline
 
Join Date: Dec 2001
Posts: 163
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

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...
Reply With Quote
  #5  
Old 02-11-2004, 07:46 AM
merk merk is offline
 
Join Date: Nov 2001
Location: Canberra, Australia
Posts: 601
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

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
Reply With Quote
  #6  
Old 02-11-2004, 08:51 AM
LeeCHeSSS's Avatar
LeeCHeSSS LeeCHeSSS is offline
 
Join Date: Dec 2001
Posts: 163
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

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]"]);
                }
        }

Reply With Quote
  #7  
Old 03-10-2004, 09:47 PM
Gary King's Avatar
Gary King Gary King is offline
 
Join Date: Jan 2002
Posts: 2,046
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Interesting hack, should be useful to many
Reply With Quote
  #8  
Old 12-12-2004, 04:21 PM
mcyates mcyates is offline
 
Join Date: Jan 2003
Location: Middlesbrough, Cleveland
Posts: 798
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

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]"]);
}
Reply With Quote
  #9  
Old 12-12-2004, 04:31 PM
chris2707 chris2707 is offline
 
Join Date: Feb 2002
Location: West Yorkshire, UK
Posts: 23
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Replace all of it unless you've previously hacked that function.
Reply With Quote
  #10  
Old 12-12-2004, 04:37 PM
mcyates mcyates is offline
 
Join Date: Jan 2003
Location: Middlesbrough, Cleveland
Posts: 798
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

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
Reply With Quote
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT. The time now is 11:23 AM.


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.09699 seconds
  • Memory Usage 2,311KB
  • Queries Executed 23 (?)
More Information
Template Usage:
  • (1)SHOWTHREAD
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (1)ad_showthread_beforeqr
  • (3)bbcode_code
  • (3)bbcode_php
  • (1)bbcode_quote
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)modsystem_post
  • (1)navbar
  • (6)navbar_link
  • (120)option
  • (1)pagenav
  • (1)pagenav_curpage
  • (1)pagenav_pagelink
  • (10)post_thanks_box
  • (10)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (10)post_thanks_postbit_info
  • (9)postbit
  • (10)postbit_onlinestatus
  • (10)postbit_wrapper
  • (1)spacer_close
  • (1)spacer_open
  • (1)tagbit_wrapper 

Phrase Groups Available:
  • global
  • inlinemod
  • postbit
  • posting
  • reputationlevel
  • showthread
Included Files:
  • ./showthread.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/functions_bigthree.php
  • ./includes/class_postbit.php
  • ./includes/class_bbcode.php
  • ./includes/functions_reputation.php
  • ./includes/functions_post_thanks.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
  • showthread_start
  • showthread_getinfo
  • forumjump
  • showthread_post_start
  • showthread_query_postids
  • showthread_query
  • bbcode_fetch_tags
  • bbcode_create
  • showthread_postbit_create
  • postbit_factory
  • postbit_display_start
  • post_thanks_function_post_thanks_off_start
  • post_thanks_function_post_thanks_off_end
  • post_thanks_function_fetch_thanks_start
  • post_thanks_function_fetch_thanks_end
  • post_thanks_function_thanked_already_start
  • post_thanks_function_thanked_already_end
  • fetch_musername
  • postbit_imicons
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • postbit_display_complete
  • post_thanks_function_can_thank_this_post_start
  • pagenav_page
  • pagenav_complete
  • tag_fetchbit_complete
  • forumrules
  • navbits
  • navbits_complete
  • showthread_complete