Go Back   vb.org Archive > vBulletin Article Depository > Read An Article > vBulletin 3 Articles
FAQ Community Calendar Today's Posts Search

Reply
 
Thread Tools
Read or change Custom Forum Permission
TitanKing
Join Date: Mar 2005
Posts: 19

 

Show Printable Version Email this Page Subscription
TitanKing TitanKing is offline 07-11-2005, 10:00 PM

Well after a HELL of a strugle I figured this out, im sure itl help many more writing or trying to write a mod...

You can also change permission with this simple script...

First you need this set of Functions:
PHP Code:
<?php
// ################################## Function and Classes I use in my script ############################

/* Functions for manipulating BITFIELDS
*
* init_bit(            bitfield        );
* query_bit(           bitfield, bit   );
* set_bit(             bitfield, bit   );
* remove_bit(          bitfield, bit   );
* toggle_bit(          bitfield, bit   );
*
*/

/* Some handy bitvalues, easy to remember */
define"BIT_0");
define"BIT_1");
define"BIT_2");
define"BIT_3");
define"BIT_4");
define"BIT_5"16 );
define"BIT_6"32 );
define"BIT_7"64 );
define"BIT_8"128 );
define"BIT_9"256 );
define"BIT_10"512 );
define"BIT_11"1024 );
define"BIT_12"2048 );
define"BIT_13"4096 );
define"BIT_14"8192 );
define"BIT_15"16384 );
define"BIT_16"32768 );
define"BIT_17"65536 );
define"BIT_18"131072 );
define"BIT_19"262144 );
define"BIT_20"524288 );
define"BIT_21"1048576 );
define"BIT_22"2097152 );
define"BIT_23"4194304 );
define"BIT_24"8388608 );
define"BIT_25"16777216 );
define"BIT_26"33554432 );
define"BIT_27"67108864 );
define"BIT_28"134217728 );
define"BIT_29"268435456 );
define"BIT_30"536870912 );
define"BIT_31"1073741824 );

/* Return true or false, depending on if the bit is set */
function query_bit$bitfield$bit )
{
        return ( 
$bitfield $bit );
}

/* Force a specific bit(pattern) to ON */
function set_bit( &$bitfield$bit )
{
        
$bitfield |= $bit;
}

/* Force a specific bit(pattern) to be OFF */
function remove_bit( &$bitfield$bit )
{
        
$bitfield &= ~$bit;
}

/* Toggle a bit(pattern), so bits that are on are turned off, and bits that are off are turned on. */
function toggle_bit( &$bitfield$bit )
{
        
$bitfield ^= $bit;
}
?>
Now lets see what permission a specific user has with this :

PHP Code:
$get_bitfield $vbulletin->userinfo['forumpermissions']["FORUMID HERE"]; 
You will get a return Value of say : 917503, this is actually a bitfield that when converted to Binary you get a bunch of switches 110111111111111111111, which controlls the permission of the Forum...

Now lets continue... things will start to make sense now...

PHP Code:
                "canview" "forum_viewing_permissions" "can_view_forum" bits=1
                
"canviewothers" "forum_viewing_permissions" "can_view_others_threads" bits=2
                
"cansearch" "forum_searching_permissions" "can_search_forums" bits=4
                
"canemail" "forum_viewing_permissions" "can_use_email_to_friend" bits=8
                
"canpostnew" "post_thread_permissions" "can_post_threads" bits=16
                
"canreplyown" "post_thread_permissions" "can_reply_to_own_threads" bits=32
                
"canreplyothers" "post_thread_permissions" "can_reply_to_others_threads" bits=64
                
"caneditpost" "post_thread_permissions" "can_edit_own_posts" bits=128
                
"candeletepost" "post_thread_permissions" "can_delete_own_posts" bits=256
                
"candeletethread" "post_thread_permissions" "can_delete_own_threads" bits=512
                
"canopenclose" "post_thread_permissions" "can_open_close_own_threads" bits=1024
                
"canmove" "post_thread_permissions" "can_move_own_threads" bits=2048
                
"cangetattachment" "forum_viewing_permissions" "can_download_attachments" bits=4096
                
"canpostattachment" "attachment_permissions" "can_upload_attachments" bits=8192
                
"canpostpoll" "poll_permissions" "can_post_polls" bits=16384
                
"canvote" "poll_permissions" "can_vote_on_polls" bits=32768
                
"canviewthreads" "forum_viewing_permissions" "can_view_threads" bits=524288
                
"canthreadrate" "post_thread_permissions" "can_rate_threads" bits=65536
                
"isalwaysmoderated" "post_thread_permissions" "always_moderate_posts" bits=131072
                
"canseedelnotice" "forum_viewing_permissions" "can_see_deletion_notices" bits=262144 
Notice the bits at next to each setting, this is the actual bit you will use with the defined variables in the function above, say you need to know if a specific user has "can_upload_attachments" permission for say ForumID = 3, you will do the following :

PHP Code:
$get_bitfield $vbulletin->userinfo['forumpermissions']["3"];
$sample query_bit$get_bitfield8192 );
echo 
$sample
a Return value of 0 for false and 1 for true will be returned, the rest of the functions is to change permission the same way as above example...

An here is a little sample script how this can be used in practise...

PHP Code:
    $or "";
    
$get_forumpermissions $db->query("select * FROM vb3_forumpermission where forumpermissions >= 1"); 
    while(
$allowed_forumpermissions_row mysql_fetch_array($get_forumpermissions)) {    
    
$forum_id $allowed_forumpermissions_row['forumid'];
    
$usergroup_id $allowed_forumpermissions_row['usergroupid'];
    
$get_bitfield $vbulletin->userinfo['forumpermissions']["$forum_id"];
    
$bitfield_allowed query_bit($get_bitfield1);
    
$and_2nd "&&";
    if ( !
eregi ($forum_id ,$allowed_forumpermissions_row_result)) {
    if (
$bitfield_allowed == 1) { $allowed_forumpermissions_row_result .= "$or"."permissionforum = '$forum_id' ";
    
$or " or ";
    } }
    } 
Cheers :squareeyed:

You may also need to know how to use the functions :

PHP Code:
Example
$bitfield 
0;
bit_init$bitfield );

set_bit$bitfieldBIT_10 )
toggle_bit$bitfieldBIT_11 )

query_bit$bitfieldBIT_10) -> true
query_bit
$bitfieldBIT_11) -> true
query_bit
$bitfieldBIT_5 ) -> false 
Reply With Quote
  #2  
Old 10-10-2005, 09:56 PM
akanevsky akanevsky is offline
 
Join Date: Apr 2005
Posts: 3,972
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Where exactly can I use this?
These functions are not defined in vBulletin. Also, why would you want to create a new set of bitfields for forum permissions if vBulletin already has its own set?
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 12:59 PM.


Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2024, vBulletin Solutions Inc.
X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.03930 seconds
  • Memory Usage 2,247KB
  • Queries Executed 15 (?)
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
  • (6)bbcode_php
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)modsystem_article
  • (1)navbar
  • (4)navbar_link
  • (120)option
  • (2)post_thanks_box
  • (2)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (2)post_thanks_postbit_info
  • (1)postbit
  • (2)postbit_onlinestatus
  • (2)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