vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   vBulletin 3 Articles (https://vborg.vbsupport.ru/forumdisplay.php?f=187)
-   -   HowTo Create Custom Usergroup Permissions (https://vborg.vbsupport.ru/showthread.php?t=82844)

Andreas 06-09-2005 10:00 PM

HowTo Create Custom Usergroup Permissions
 
Usergoup Permissions are being controlled through XML files, you don't have to edit usergroup.php anymore

To create your own usergroup permissions, the first thing to do is to modify table usergroup (keep table prefixes in mind!):

[sql]ALTER TABLE usergroup ADD myhackpermissions INT( 10 ) UNSIGNED DEFAULT '0' NOT NULL ;[/sql]

If your hack does need some integer settings as well (and not just On/Off-Options):

[sql]ALTER TABLE usergroup ADD myhackintset INT( 10 ) DEFAULT '100' NOT NULL ;[/sql]

Then you must create a an XML-File bitfield_myhack.xml and place it in includes/xml:

HTML Code:

<?xml version="1.0" encoding="ISO-8859-1"?>
<bitfields product="vbulletin">
        <bitfielddefs>
                <group name="ugp">
                        <group name="myhackpermissions">
                                <bitfield name="canfoo" group="my_hack_permissions"  phrase="can_foo_forum" install="1,2,3,4,5,6,7">1</bitfield>
                                <bitfield name="canbaa" group="my_hack_permissions"  phrase="can_baa_forum" install="">2</bitfield>
                                <bitfield intperm="true" name="myhackintset" group="my_hack_permissions"  phrase="myhack_int_desc"></bitfield>
                        </group>
                </group>
        </bitfielddefs>
</bitfields>

As you can see, you must create a new permission group below group ugp (short for usergroup permissions).

Parameter product of Tag bitfields should be the identifier of your Product

Paramater name of Tag group must match the column name in table usergroup.

The Parameters for Tag bitfield are:
  • name is the identifier you can use in your hack code (eg. $permissions['myhackpermissions'] & $vbulletin->bf_ugp['myhackpermissions']['canfoo'])
    In case of integer options this name must match the column name in table usergroup.
  • intperm indicates that this Option is a integer value
  • group is the varname for the Phrase that should be displayed as Permission Group Title.
    This is also being used to set up different Groups for your permissions.
  • phrase is the varname of the Phrase that should be displayed for this option in Usergroup Manager
  • install is a comma-separated list of the usergroups where this permission should be visible
    If this parameter is empty or omitted, this Option will be used for all Usergroups

The value of <bitfield> is the decimal value of the bit (eg. 1 for the first, 2 for the second, 4 for the third, and so on).
In case of an Integer Option this is the default value.

If you want to hide certain permission groups for some usergroups, for example from Guests as they don't make sense for them:

HTML Code:

<ignoregroups>
        <group name="myhackpermissions" ignoregroups="1" />
</ignoregroups>

Parameter name is the name of the permission group you want to hide, ignoregroups is a comma seperated list of usergoup IDs where this permission group should not show up.
Place this section below the <bitfielddefs>-Section.

Now create the necessary phrases (in Phrasegroup Permissions) at this point.

As vBulletin caches Bitfields in Datastore, you must rebuild this cache before the new usergroup permissions can be actually used (They will already show up in Usergroup Manager, but cannot be saved - you will get an error).
To do so, point your browser to admincp/index.php?do=buildbitfields.

You can also use the following Code (in a Custom Installer or Install-Code of a Product) to update the Bitfield Cache:
PHP Code:

if (is_newer_version('3.5.1'$vbulletin->options['templateversion']))
{
    
// Rebuild Bitfields
    // Do this for vBulletin < 3.5.1 *ONLY*; later versions rebuild
    // automatically and calling the builder in install code causes
    // the bitfields NOT to be rebuild correctly
    
require_once(DIR '/includes/class_bitfield_builder.php');
    
vB_Bitfield_Builder::save($db);
    
build_forum_permissions();


If you install/upgrade vBulletin and custom bitfield_xxx.xml files are already in place, they will be used - you don't have to update the Bitfield Cache in this case.

This How-To is (C) 2005 by KirbyDE and you are not allowed to redistribute it in any way without my explicit consent.

noppid 06-10-2005 06:04 PM

Very nice, no more chances of stepping on toes. :)

I think the field add for a custom permission, bitfield, may need to look like this instead...

PHP Code:

ALTER TABLE usergroup ADD myhackpermissions INT10 UNSIGNED DEFAULT '0' NOT NULL 


Revan 06-10-2005 06:14 PM

Good tut, I hope Administrator Permissions is next... *hint* ;)

Andreas 06-10-2005 06:41 PM

@noppid
Right. Should have been UNSIGNED of course, corrected :)

deathemperor 06-11-2005 01:57 AM

very very nice, this will boost the learning of vb3.5, no one wrote something like this for vb3.0

Guest190829 06-11-2005 02:03 AM

Yay! This is what I was going to ask for! :up: :up:

burnist 06-11-2005 08:36 AM

I think I love you KirbyDE :)

amykhar 06-12-2005 02:02 AM

Question: Is there something similar for forum permissions?

Shaved 06-13-2005 11:06 AM

Im with amykhar I tried to apply this to forumperms but with no effect.

I want simple yes/no option. I even tried editing the bitfield_vbulletin.xml directly and no effect any help appreciated.

*edit *

Got it to work.

Note to self read full post before asking for help

Andreas 06-16-2005 04:15 PM

Update: Simplified instructions to rebuild Bitfield Cache.

@amykhar
You can extend the forumpermissions bitfield, however I fear this will cause problems sooner or later - 20 of 32 Bits are already being used.

To do so:

Code:

<?xml version="1.0" encoding="ISO-8859-1"?>
<bitfields product="vbulletin">
        <bitfielddefs>
                <group name="ugp">
                        <group name="forumpermissions">
                                <bitfield name="canfoo" group="my_forumperms" phrase="can_foo">2147483648</bitfield>
                        </group>
                </group>
        </bitfielddefs>
</bitfields>


Ron1n 06-18-2005 12:24 AM

Why cant this be added to bitfield_vbulletin.xml? I have tried, but it doesnt work.

Andreas 06-18-2005 12:29 AM

It can ... but you shouldn't do that, as bitfield_vbulletin.xml will be overwritten during an upgrade, which means you would have to redo the changes.
If you use your own XML file it will still be there and used after an upgrade.

Ron1n 06-18-2005 10:49 PM

how does one go about putting a title on the grey table header? I tried phrase="_phrase_var_" and text="phrase text" but neither worked.

Andreas 06-18-2005 11:43 PM

Quoting myself to answer your question:
Quote:

Originally Posted by KirbyDE

The Parameters for Tag bitfield are:
  • group is the varname for the Phrase that should be displayed as Permission Group Title.
    This is also being used to set up different Groups for your permissions.


Ron1n 06-19-2005 02:05 AM

yea, i read that but figured I also needed another param because it wasnt (and isnt) working

Code:

<?xml version="1.0" encoding="ISO-8859-1"?>
<bitfields product="vBulletin">
        <bitfielddefs>
                <group name="ugp">
                        <group name="download_permissions">
                                <bitfield name="canviewfiles" group="download_permissions"  phrase="downloads_can_view_files" install="">1</bitfield>
                                <bitfield name="candownloadfiles" group="download_permissions"  phrase="downloads_can_download_files" install="">2</bitfield>
                                <bitfield name="canratefiles" group="download_permissions"  phrase="downloads_can_rate_files" install="">4</bitfield>
                                <bitfield name="canlinktofiles" group="download_permissions"  phrase="downloads_can_linkto_files" install="">8</bitfield>
                                <bitfield name="canuploadfiles" group="download_permissions"  phrase="downloads_can_upload_files" install="">16</bitfield>
                                <bitfield name="canavoidpurgatory" group="download_permissions"  phrase="downloads_can_avoid_purgatory" install="">32</bitfield>
                                <bitfield name="canmanagepurgatory" group="download_permissions"  phrase="downloads_can_manage_purgatory" install="">64</bitfield>
                                <bitfield name="caneditownfiles" group="download_permissions"  phrase="downloads_can_edit_own" install="">128</bitfield>
                                <bitfield name="caneditallfiles" group="download_permissions"  phrase="downloads_can_edit_all" install="">256</bitfield>
                                <bitfield name="canviewdisabled" group="download_permissions"  phrase="downloads_can_view_disabled" install="">512</bitfield>
                        </group>
                </group>
        </bitfielddefs>
</bitfields>

download_permissions is a phrase that says Download Permissions

I'll try looking over everything to see if there are errors, but I dont see how I could have messed up.

merk 06-20-2005 04:42 AM

Have you tried phrase="download_permissions" instead of name=?

Chris M 06-20-2005 02:27 PM

Kirby - Any way to make this work with Forum Options? :)

Rather than editing forum.php ;)

Satan

deathemperor 06-21-2005 03:40 PM

there're optional ways to use the permission:

along with

$permissions['myhackpermissions'] & $vbulletin->bf_ugp['myhackpermissions']['canfoo']

you can use

$permissions['myhackpermissions'] & $vbulletin->bf_ugp_myhackpermissions['canfoo']

or

$permissions['myhackpermissions'] & 1

the last one is the shortest one but then you won't understand what it does, 1 is the value of <bitfield> tag, just similar as the old permission settings.

I found that the 'canfoo' is case sensitive, this took me almost a day to figure out lol

HakkieDEV 06-25-2005 09:05 AM

I still don't understand how I could add forumpermissions?

I've tried to play with it, I've added an xml file with the content of kirbyDE, but it didn't work.

Andreas 06-25-2005 10:25 AM

Take a look at my recent Get New Posts Hack and you'll see :)

HakkieDEV 06-25-2005 11:33 AM

I've had a look and I see that it also adds a field in the usergroup permissions area.

However, I'd like to know how I could add some extra permission fields in the forum area (admincp/forum.php).

Andreas 06-25-2005 07:39 PM

Not possible without editing the File.

HakkieDEV 06-26-2005 06:13 AM

Ah, okay, thanks.

It was driving me crazy. :)

TitanKing 07-12-2005 07:11 AM

Can anyone please explain to me the forumpermissions bits, how will I get the permissions out of there... thank you...

MrNase 07-27-2005 05:06 PM

1 Attachment(s)
Here's my bitfield_vbgarage.xml and here's the error I get once my custom permissions are in place:


HTML Code:

<?xml version="1.0" encoding="ISO-8859-1"?>
<bitfields product="vBulletin">
        <bitfielddefs>
                <group name="ugp">
                        <group name="canvbgarage">
                        <bitfield name="canenter" group="canvbgarage" phrase="can_enter_vbgarage" install="">1</bitfield>
                        </group>
                </group>
        </bitfielddefs>
</bitfields>


If the file is there and active I get this error when I try to save the permissions. The newly added permissions are not saved and they remain 'no'..

Andreas 07-27-2005 05:27 PM

Make sure you don't have any Plugins enabled and try again.

Edit: install="" might also cause this error

MrNase 07-27-2005 05:33 PM

It's a fresh install without any plugins.. I also removed install="" with no success :(

I added another group and here's the sql error I get now:

HTML Code:

### UPDATE QUERY GENERATED BY fetch_query_sql() ###
        `title` = 'Administrators',
        `description` = '',
        `usertitle` = 'Administrator',
        `opentag` = '',
        `closetag` = '',
        `passwordexpires` = '180',
        `passwordhistory` = '360',
        `canvbgarage` = '',
        `canvbgarage2` = '',
        `forumpermissions` = '1048575',
        `attachlimit` = '0',
        `pmquota` = '50',
        `pmpermissions` = '3',
        `pmsendmax` = '5',
        `calendarpermissions` = '63',
        `wolpermissions` = '31',
        `adminpermissions` = '3',
        `genericpermissions` = '205520831',
        `genericoptions` = '31',
        `profilepicmaxwidth` = '100',
        `profilepicmaxheight` = '100',
        `profilepicmaxsize` = '65535',
        `avatarmaxwidth` = '80',
        `avatarmaxheight` = '80',
        `avatarmaxsize` = '20000'
WHERE usergroupid=6;

You can see that canvbgarage is empty but it shouldn't..

I edited the usergroup #6 via phpmyadmin and changed canvbgarage to 1 and the usergroup manager still says no and my scripts are still not working :(

Andreas 07-27-2005 05:41 PM

Did you rebuild the Bitfield Cache?

Btw:

I'd use a XML like
Code:

<?xml version="1.0" encoding="ISO-8859-1"?>
<bitfields product="garage">
        <bitfielddefs>
                <group name="ugp">
                        <group name="vbgaragepermissions">
                        <bitfield name="canenter" group="vbgarage_permissions" phrase="can_enter_vbgarage" install="">1</bitfield>
                        </group>
                </group>
        </bitfielddefs>
</bitfields>


MrNase 07-27-2005 05:47 PM

Verdammt, ich wusste doch das ich was vergessen hatte *vordenkopfschlag* :D

No I didn't :D

Next question: If Iam using the XML like you suggested, what does this has to look like:
PHP Code:

if ($permissions['canvbgarage'] & $vbulletin->bf_ugp['canvbgarage']['canenter']) 


Andreas 07-27-2005 05:54 PM

Well, it's just variable Names so it's not really important, but IMHO it makes Code more readable :)

PHP Code:

if ($permissions['vbgaragepermissions'] & $vbulletin->bf_ugp['vbgaragepermissions']['canenter']) 


Brinnie 07-29-2005 08:08 PM

very nice,

thank you! :D

Mr Blunt 08-21-2005 04:50 AM

KirbyDE .... Great How-To!!

One thing I would like to point out to everyone which I think is extremely relevant to this thread is the install="X" field will not be recognized during a product installation script ... at least not without extra code which I haven't figured out how to write yet. Simply rebuilding the bitfields (while it will allow the new permissions to begin functioning) will result in all zero's as default for all groups.

http://www.vbulletin.com/forum/bugs3...iew&bugid=1054

This is the vBulletin response.

Quote:

Originally Posted by John
This is happening because the install field in the bitfield XML is only used when vBulletin is first installed (see lines 2280-2315 in install/mysql_schema.php). You may want to reproduce some of the code from there in your plugin to get it to take up the default values.

I played with this all day today and basically got nowhere.
Maybe someone else will have better luck than me.

Andreas 08-23-2005 12:57 PM

Untested, but

PHP Code:

 // Rebuild Bitfields
require_once(DIR '/includes/class_bitfield_builder.php');
vB_Bitfield_Builder::save($db);
$myobj =& vB_Bitfield_Builder::init();

$groupinfo = array();

for (
$x 1$x 9$x++)
{
    
$groupinfo["$x"]['mypermissions'] = 0;
}

foreach (
$myobj->data['ugp']['mypermissions'] AS $permtitle => $permvalue)
{
    if (empty(
$permvalue['group']))
    {
        continue;
    }

    if (!empty(
$permvalue['install']))
    {
        foreach (
$permvalue['install'] AS $gid)
        {
            
$groupinfo["$gid"]['mypermission'] += $permvalue['value'];
        }
    }
}

foreach (
$groupinfo AS $usergroupid => $permissions)
{
    
$db->query_write("UPDATE " TABLE_PREFIX "usergroup SET mypermissions=$permissions[mypermissions] WHERE usergroupid=$usergroupid");
}
build_forum_permissions(); 


Mr Blunt 08-23-2005 05:55 PM

You were close Kirby
You only forgot the WHERE usergroupid=$usergroupid in the query.
Works like a charm!!!
Thank you, Sir!!

PHP Code:

    $db->hide_errors();
    
$db->query_write("UPDATE " TABLE_PREFIX "usergroup SET mypermissions=$permissions[mypermissions] WHERE usergroupid=$usergroupid");
    
$db->show_errors(); 


Andreas 08-23-2005 05:58 PM

I knew there was a reason why I specified a Variable for the Key in foreach() :p

Kirk Y 08-23-2005 07:36 PM

lol... Kirby, might I ask why I'm in your signature?

Andreas 08-23-2005 07:43 PM

Yes. I've read this Post you made and found it very amusing :)

Mr Blunt 08-23-2005 08:16 PM

Can anyone verify or deny for certain if two of the same "canfoo" bitfield names can exist as long as they are each under a different groupname?

For example, something like "canview" under groupname "bluntswhodlpermissions".

I could see almost every hack using a "canview", LOL, but the groupname is very unique.

I ask because I do see a lot of vbulletin code which checks for clashes, but the code gets a little too deep for me to fully understand so far.

I ask in this thread to help reinforce this how-to. I mean if we must all diversify this variable as well, then maybe the how-to should reflect that we should put part of our myhack name in this too somehow .... or maybe we are all good with real simple short vars here if duplicate canfoo's are ok as long as the groupname is unique. I suspect the latter, but I leave it as a question.

Just trying to help avert potential problems down the road while we are all learning the vb350 ways.

Andreas 08-23-2005 08:21 PM

You can have "canfoo" in myperms1, myperms2, mypers3, doesntmatterperms and so on - doesn't cause Problems, as they are different Bitfields and those Names are just Shortcuts for the Bits :)

Mr Blunt 08-23-2005 08:36 PM

3 thumbs up for Kirby!!
Appreciate the time!!


All times are GMT. The time now is 06:35 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.02332 seconds
  • Memory Usage 1,876KB
  • 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
  • (4)bbcode_html_printable
  • (6)bbcode_php_printable
  • (2)bbcode_quote_printable
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)pagenav
  • (1)pagenav_curpage
  • (2)pagenav_pagelink
  • (1)post_thanks_navbar_search
  • (1)printthread
  • (40)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