Go Back   vb.org Archive > vBulletin 3 Discussion > vB3 Programming Discussions
FAQ Community Calendar Today's Posts Search

Reply
 
Thread Tools Display Modes
  #1  
Old 03-10-2007, 04:20 PM
manofphat's Avatar
manofphat manofphat is offline
 
Join Date: Jan 2007
Posts: 78
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default Quick Permissions Question

Hello,

Currently this is the code I have in one of my plugins:
Code:
if (!in_array($vbulletin->userinfo['usergroupid'], array(5,6,12))) print_no_permission();
Currently, from my tests I can see that it's only checking the user's primary usergroup. How can I make it so it checks their additional usergroups as well?

Thank you!

Also, does vBulletin have some sort of IRC channel for quick questions like this?
Reply With Quote
  #2  
Old 03-10-2007, 11:41 PM
TECK's Avatar
TECK TECK is offline
 
Join Date: Nov 2001
Location: Canada
Posts: 4,182
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Code:
if (!in_array($vbulletin->userinfo['usergroupid'], array(5, 6, 12)))
{
	print_no_permission();
}
Login as usergroupid 12 and you will see that it works.
The way in_array() function works is simple: It checks through the array until an element matches, then it stops performing the rest of the check and returns a boolean result. That improves the code performance.
So if you are a member of usergroupid 6 and 12, it will not check for 12, since 6 is already true.

Still, is better to avoid those type of usergroup checks and use instead the vBulletin bitfield permissions.
For example, if I want to see if an user is an admin, I can use this:
Code:
$show['adminoption'] = (bool)($vbulletin->userinfo['permissions']['adminpermissions'] & $vbulletin->bf_ugp_adminpermissions['cancontrolpanel']);
if $show['adminoption']
{
	// my action here...
}
I can use from now on anywhere in my script this condition, without processing several times the same check.

In global.php there are few boolean conditions already defined. I dont understand why no hacker use them in their code. They are there to be used, since they are already defined, so there is no need to perform extra code processing re-defining them again and again.

For example, $show['admincplink'] will check if you are an admin (uses deprecated code ).
$show['modcplink'] checks if you are either an admin or mod.
Take your time and look at the code, is pretty cool what you can find in there.

Those forums are made for posting, so others will be able to learn from threads, code examples, etc.
If you ask a question on an IRC channel, how do you think others will learn from your current problem?

Have fun with your vb hacking.
Reply With Quote
  #3  
Old 03-11-2007, 12:20 PM
Princeton's Avatar
Princeton Princeton is offline
 
Join Date: Nov 2001
Location: Vineland, NJ
Posts: 6,693
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

you can use

is_member_of($vbulletin->userinfo, 5,6,12) OR is_member_of($bbuserinfo, 5,6,12)

checks primary and secondary usergroup
Reply With Quote
  #4  
Old 03-11-2007, 04:33 PM
manofphat's Avatar
manofphat manofphat is offline
 
Join Date: Jan 2007
Posts: 78
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Thanks to both of you! I have it working the way I want now!

Reply With Quote
  #5  
Old 03-12-2007, 08:08 AM
TECK's Avatar
TECK TECK is offline
 
Join Date: Nov 2001
Location: Canada
Posts: 4,182
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Inserting int's separated by comma's would mess with the 3rd function param, if I'm not wrong. If I check for one usergroupid, ya is ok, but for multiples, it will break the cache.
Pretty sure the function was ment to be used like:
is_member_of($bbuserinfo, array(5, 6, 12));
and not:
is_member_of($bbuserinfo, 5,6,12);

What do you guys think?
Reply With Quote
Reply


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 07:04 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.03701 seconds
  • Memory Usage 2,196KB
  • Queries Executed 11 (?)
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
  • (1)ad_showthread_firstpost
  • (1)ad_showthread_firstpost_sig
  • (1)ad_showthread_firstpost_start
  • (3)bbcode_code
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)navbar
  • (3)navbar_link
  • (120)option
  • (5)post_thanks_box
  • (5)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (5)post_thanks_postbit_info
  • (5)postbit
  • (5)postbit_onlinestatus
  • (5)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
  • tag_fetchbit_complete
  • forumrules
  • navbits
  • navbits_complete
  • showthread_complete