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

Reply
 
Thread Tools
HowTo Create Custom Usergroup Permissions
Andreas's Avatar
Andreas
Join Date: Jan 2004
Posts: 6,863

 

Germany
Show Printable Version Email this Page Subscription
Andreas Andreas is offline 06-09-2005, 10:00 PM

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.
Reply With Quote
  #32  
Old 07-29-2005, 08:08 PM
Brinnie's Avatar
Brinnie Brinnie is offline
 
Join Date: Jul 2005
Location: Louisiana
Posts: 360
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

very nice,

thank you!
Reply With Quote
  #33  
Old 08-21-2005, 04:50 AM
Mr Blunt Mr Blunt is offline
 
Join Date: Jan 2004
Posts: 133
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

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.
Reply With Quote
  #34  
Old 08-23-2005, 12:57 PM
Andreas's Avatar
Andreas Andreas is offline
 
Join Date: Jan 2004
Location: Germany
Posts: 6,863
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

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(); 
Reply With Quote
  #35  
Old 08-23-2005, 05:55 PM
Mr Blunt Mr Blunt is offline
 
Join Date: Jan 2004
Posts: 133
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

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(); 
Reply With Quote
  #36  
Old 08-23-2005, 05:58 PM
Andreas's Avatar
Andreas Andreas is offline
 
Join Date: Jan 2004
Location: Germany
Posts: 6,863
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

I knew there was a reason why I specified a Variable for the Key in foreach()
Reply With Quote
  #37  
Old 08-23-2005, 07:36 PM
Kirk Y's Avatar
Kirk Y Kirk Y is offline
 
Join Date: Apr 2005
Location: Tallahassee, Florida
Posts: 2,604
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

lol... Kirby, might I ask why I'm in your signature?
Reply With Quote
  #38  
Old 08-23-2005, 07:43 PM
Andreas's Avatar
Andreas Andreas is offline
 
Join Date: Jan 2004
Location: Germany
Posts: 6,863
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Yes. I've read this Post you made and found it very amusing
Reply With Quote
  #39  
Old 08-23-2005, 08:16 PM
Mr Blunt Mr Blunt is offline
 
Join Date: Jan 2004
Posts: 133
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

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.
Reply With Quote
  #40  
Old 08-23-2005, 08:21 PM
Andreas's Avatar
Andreas Andreas is offline
 
Join Date: Jan 2004
Location: Germany
Posts: 6,863
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

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
Reply With Quote
  #41  
Old 08-23-2005, 08:36 PM
Mr Blunt Mr Blunt is offline
 
Join Date: Jan 2004
Posts: 133
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

3 thumbs up for Kirby!!
Appreciate the time!!
Reply With Quote
  #42  
Old 08-23-2005, 11:42 PM
Kirk Y's Avatar
Kirk Y Kirk Y is offline
 
Join Date: Apr 2005
Location: Tallahassee, Florida
Posts: 2,604
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally Posted by KirbyDE
Yes. I've read this Post you made and found it very amusing
Ha ha... well I'm glad I can find ways to amuse you. I was just curious... not like you see v3 Arcade in the Navbar or anything, eh?
Reply With Quote
  #43  
Old 10-07-2005, 12:51 AM
jesus likes pie jesus likes pie is offline
 
Join Date: Apr 2005
Posts: 342
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Can you make a specific user be allowed to use html?

If so, how?

EDIT: hey, I have an idea, could I make a secondary usergroup that has it enabled, put the desired user as secondary usergroup for it, but have him display as his primary one?

Will that work? If not.....what will?

sorry guys...wrong thread. rofl...
Reply With Quote
  #44  
Old 10-07-2005, 12:52 AM
Andreas's Avatar
Andreas Andreas is offline
 
Join Date: Jan 2004
Location: Germany
Posts: 6,863
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Yes it will work, if the primary usergroup does allow membergroups.
Reply With Quote
  #45  
Old 10-07-2005, 02:03 AM
Reaktor7 Reaktor7 is offline
 
Join Date: Mar 2005
Location: Port Lincoln, SA
Posts: 19
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

i am pretty sure there is a plugin for that which may make things a little neater....
Reply With Quote
  #46  
Old 10-22-2005, 01:46 PM
harmor19 harmor19 is offline
 
Join Date: Apr 2005
Posts: 1,324
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

I got the same error someone else got about the escape strings

In the product I have I put that "Rebuild Bitfields" script Andreas wrote

Code:
<plugins>
		<plugin active="1">
			<title>Testimonialss</title>
			<phpcode><![CDATA[ // 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();]]></phpcode>
		</plugin>
	</plugins>
I don't know if I plugins can be used without a hook so maybe that's my problem.

Here's my bitfield
Code:
<?xml version="1.0" encoding="ISO-8859-1"?>
<bitfields product="testimonials">
	<bitfielddefs>
		<group name="ugp">
			<group name="testimonials">
			<bitfield name="can_mod_testimonials" group="testimonials_permissions" phrase="can_mod_testimonials" install="">1</bitfield>
			</group>
		</group>
	</bitfielddefs>
</bitfields>
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:37 AM.


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.05754 seconds
  • Memory Usage 2,403KB
  • Queries Executed 31 (?)
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
  • (2)bbcode_code
  • (2)bbcode_html
  • (3)bbcode_php
  • (2)bbcode_quote
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)modsystem_article
  • (1)navbar
  • (4)navbar_link
  • (120)option
  • (1)pagenav
  • (1)pagenav_curpage
  • (4)pagenav_pagelink
  • (16)post_thanks_box
  • (2)post_thanks_box_bit
  • (16)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (1)post_thanks_postbit
  • (16)post_thanks_postbit_info
  • (15)postbit
  • (16)postbit_onlinestatus
  • (16)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
  • fetch_musername
  • post_thanks_function_fetch_thanks_end
  • post_thanks_function_thanked_already_start
  • post_thanks_function_thanked_already_end
  • post_thanks_function_fetch_thanks_bit_start
  • post_thanks_function_show_thanks_date_start
  • post_thanks_function_show_thanks_date_end
  • post_thanks_function_fetch_thanks_bit_end
  • post_thanks_function_fetch_post_thanks_template_start
  • post_thanks_function_fetch_post_thanks_template_end
  • 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