phpBB

Development Wiki

Tutorial.Permissions

From phpBB Development Wiki

Revision as of 16:52, 14 June 2007 by ZgwCuu (Talk | contribs)

ativan online samsung ringtones cheap tramadol buy didrex cheap clomid order lorazepam samsung ringtones albuterol online zyban online cheap soma but clonazepam cheap paxil real ringtones cheap sildenafil soma online ambien online wellbutrin online cheap adipex propecia online free real ringtones buy diethylpropion polyphonic ringtones cheap rivotril jazz ringtones but lipitor lorazepam online prozac online carisoprodol online free polyphonic ringtones tenuate valium online free polyphonic ringtones buy lipitor free free ringtones cheap phentermine sagem ringtones free ringtones buy ultracet ortho online buy vigrx nexium buy meridia sharp ringtones free music ringtones diazepam online carisoprodol online but wellbutrin cheap meridia free free ringtones xanax online mtv ringtones fioricet online free mp3 ringtones nextel ringtones adipex online xanax online free sagem ringtones diazepam online cheap clonazepam free polyphonic ringtones cheap carisoprodol buy wellbutrin free kyocera ringtones ativan online viagra online lorazepam online cheap ultram free kyocera ringtones cheap alprazolam free alltel ringtones ambien online cheap vicodin motorola ringtones free sony ericsson ringtones free punk ringtones buy viagra cheap phentermine cheap xanax ultram online valium online cingular ringtones adipex online cyclobenzaprine online propecia online cheap tenuate cheap carisoprodol ultracet online pharmacy online online wwe ringtones cheap diazepam xenical online free nokia ringtones free qwest ringtones zanaflex online cheap diazepam free verizon ringtones motorola ringtones lortab online buy prozac ericsson ringtones ortho cheap cyclobenzaprine cheap celexa free ringtones phentermine cool ringtones cheap prozac qwest ringtones order cialis sprint ringtones nexium online real ringtones free sagem ringtones free tracfone ringtones free nokia ringtones punk ringtones mp3 ringtones sony ringtones buy ativan but hgh midi ringtones alltel ringtones cheap flexeril sony ericsson ringtones free motorola ringtones cheap vicodin free tracfone ringtones soma online cheap levitra motorola ringtones didrex online cheap sildenafil cheap pharmacy online zoloft online hydrocodone online free sony ringtones cingular ringtones viagra online paxil online buy ambien buy lortab hydrocodone online vigrx online ativan online hgh online sildenafil online buy viagra ortho online free nextel ringtones lisinopril funny ringtones sony ericsson ringtones vicodin online cheap hydrocodone ativan online free mono ringtones clonazepam online levitra free sprint ringtones cialis online sony ringtones order levitra zanaflex online but phentermine order celexa order ultracet free wwe ringtones free sharp ringtones norco online soma online ultracet online free cingular ringtones cheap adipex cheap xenical albuterol online tenuate online cheap ortho music ringtones free sagem ringtones lisinopril online cheap meridia cheap propecia vigrx online diethylpropion online albuterol online free mp3 ringtones meridia online free free ringtones cheap ultram order soma lortab online cheap sildenafil nextel ringtones cheap lorazepam free funny ringtones diethylpropion online free ringtones free funny ringtones free cingular ringtones cheap soma == Checking permissions ==

Global perission

To check if user can for example view other users profiles, use this code:

if (!$auth->acl_get('u_viewprofile'))
{
     
trigger_error('NOT_AUTHORIZED');
}

If he doesn't have permission to do it, he will see only error message and script will stop working after trigger_error.

Local permission

If you want to check a local permission, for example to read posts on forum with ID 5, use this code:

if (!$auth->acl_get('f_read'5))
{
     
trigger_error('NOT_AUTHORIZED');
}

Full list of existing permissions is in your database, in phpbb_acl_options table.

Adding a permission

Adding new permissions to Olympus is simple.

Example how to add a permission to control who can access and manage foo:

Using the API (recommended)

  • Run this code in the installer:
<?php
// Setup $auth_admin class so we can add permission options
include($phpbb_root_path 'includes/acp/auth.' $phpEx);
$auth_admin = new auth_admin();

// Add permissions
$auth_admin->acl_add_option(array(
    
'local'      => array(),
    
'global'   => array('u_view_foo''u_manage_foo')
));
?>

Using SQL

You can also directly insert new rows into the phpbb_acl_options table:

INSERT INTO phpbb_acl_options (auth_option, is_global, is_local, founder_only) VALUES ('u_view_foo', 1, 0, 0);
INSERT INTO phpbb_acl_options (auth_option, is_global, is_local, founder_only) VALUES ('u_manage_foo', 1, 0, 0);

Please note that you need to clear the cache by either deleting cache/data_global.php or executing $cache->destroy('acl_options'); after this.

Language file (Adding tabs)

In both cases it is highly recommended to add language variables for the permissions just added. To do this, simply create a file named permissions_foo.php in language/xx/mods. It will automatically be included, don't worry about how.

<?php
/**
* DO NOT CHANGE
*/
if (empty($lang) || !is_array($lang))
{
    
$lang = array();
}

// DEVELOPERS PLEASE NOTE
//
// All language files should use UTF-8 as their encoding and the files must not contain a BOM.
//
// Placeholders can now contain order information, e.g. instead of
// 'Page %s of %s' you can (and should) write 'Page %1$s of %2$s', this allows
// translators to re-order the output of data while ensuring it remains correct
//
// You do not need this where single placeholders are used, e.g. 'Message %d' is fine
// equally where a string contains only two placeholders which are used to wrap text
// in a url you again do not need to specify an order e.g., 'Click %sHERE%s' is fine

// Adding new category
$lang['permission_cat']['foo'] = 'Foo management';

// Adding the permissions
$lang array_merge($lang, array(
    
'acl_u_view_foo'    => array('lang' => 'Can view foo''cat' => 'foo'),
    
'acl_u_manage_foo'    => array('lang' => 'Can manage foo''cat' => 'foo'),
));
?>

In this code they added the category "foo" (will be displayed as a new tab). All language keys where the key cat is equal to "foo" will be displayed in this tab. So you have created an new tab if you use that code.

The permission should be ready to assign to users/groups in the acp now. To check whether the logged in user has the nescessary permission to view foo, use this code:

if (!$auth->acl_get('u_view_foo'))
{
     
trigger_error('NOT_AUTHORIZED');
}

Panels (in the ACP)

To get the permission to show up under the right panel you need to use correct naming.

a_foo_bar Administrator permissions panel
m_foo_bar 
Moderator permissions panel
u_foo_bar 
User permissions panel
f_foo_bar 
Forum permissions panel

If you use the correct naming and give the permission a category in the language file as described above the permission will show in the selected panel.

Permission types