vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   vBulletin 3 Articles (https://vborg.vbsupport.ru/forumdisplay.php?f=187)
-   -   Read or change Custom Forum Permission (https://vborg.vbsupport.ru/showthread.php?t=92038)

TitanKing 07-11-2005 10:00 PM

Read or change Custom Forum Permission
 
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 


akanevsky 10-10-2005 09:56 PM

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?


All times are GMT. The time now is 06:25 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.01143 seconds
  • Memory Usage 1,771KB
  • 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
  • (6)bbcode_php_printable
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)post_thanks_navbar_search
  • (1)printthread
  • (2)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
  • bbcode_fetch_tags
  • bbcode_create
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • printthread_post
  • printthread_complete