phpBB

Development Wiki

Tutorial.Permissions

From phpBB Development Wiki

Revision as of 17:24, 17 August 2007 by ZgwCuu (Talk | contribs)

graduatoria sostegno caserta acquisto mobili ufficio usati trapani venezia biglietti aerei mixer 6 canali tre per uccidere lvov la morte corre incontro a jessica universita economia e commercio torino k8n e deluxe hyundai bologna club net budha bar carica batteria solare wellness isernia lybra km zero regione siciliana it ludmilla radchenko vianello tommaso nikkor af nikon af-s vr 24-120 mm f fiat sava amphetadesk kodoku bluetooth monitor funkytown mirino angolare dizionario inglese italiano free trio bebe confort fastweeb it x change francisca dimage z5 nera casse da studio stampante fotografica professionale hp carlo cracco libri un uomo da buttare calcio ps2 videogiochi www navy it lightnining sopra e sotto il ponte hifi 5 1 filmati hard selen gratis hard disc iomega 250gb firewire gerico 2004 boogyman coltivazione della marjuana modena wireless racing wheel tenda 3 persone tubo gas i-mate - jam gps nissan micra 1.3 pamela cartoni sun ktv sharik hoge veluwe mercanteinfiera a parma imponente sulla strada jack kerouac libri ambulanze usate garboli villaggio turistici puglia dido video white flag dvd verbatim datalife plus azo fbi protezione testimoni auto noleggio bolzano panchiao wuthering heights last minute rodi cavo usb fujifilm gallerie fotografiche gratuite tettone m ci sarai fracesco renga lora della furia sophia loren palmare gprs microsoft ordu (provincia) gig dalessio cd cover manga com traduzione last thing on my mind tylko czarne oczy teh reason principio speranza amd athlon64 3200 (socket 939) la farfalla come animale le ragazze dei quartieri alti auto eten crono belt begees avvitatore ad aria mazonaki linksys adapter ags (tecnica) dentaria la commissaria inserimento annunci gigabyte k8nsc nforce3 assicurazione varazze luoghi allaperto copione de i cento passi del mariachi pagina erotica sei speciale km0 opel meriva auto km 0 mp3 latin pop pannolini huggies t66 ericsson mappa stradale nudi gratis acer n35 accessori baby pratik occupazione nude cristina aguilera israel kamakawiwo ole mp3 free blan biliardo carnielli tapis roulant paolo meneguzzi testi just the wai yuo are barry white atletica leggera rex combinato a dibujos tridimensionales camper vendesi bagliori di guerra istituto salvemini tim miss motorola offerta auto km 0 sei colpi in canna touareg 3.0 tdi mmc 512mb dual voltage ricevitore gps blutooth freepops fangcheng el organo palmare con telefono e fotocamera televisore multistandard dvd mannoia lettere da amore creed my sacrifice natalia millan valentina uomini e donne lovale sodomia - la visita del vicino eiffel 65 another way sandisk mp3 apple ipod mini (6 gb) www ragazze nigeriane it ritornerai gaggia espresso paola e chiara cantanti nude usb flash mp3 samsung miniket vp ivette sangalo lettore di schede sandisk sai tenere un segreto pioneer deh-4700mp varsavia cose fare viava la pappa negozi di bomboniere campania di silvester stallone korea sex video milano mosca xd olympus 128mb camini e stufe i cavalieri dello zodiaco baby can i hold you tonight panini spa witch hunter robin. vol. 05 www dolce e gabbana affittacamere lucca lacafetera larva gatitas annunci ragazze vogliose fujifilm finepix f610 lupen fisarmonica il teatro di john keats celeron d 336 loewe spheros 37 hd www finanze mitsubishi condizionatori trial cavo surround qv-r52 casio confort trio firenze zurigo biglietti aerei centri urbani de bary, heinrich anton banconota italiane nike solas air www caravanbacci it foto annunci singole donne amanti anal amapola com lettore cd radio calcolo indennita occupazione hyundai 201p hard disk portatile lettore memory card scuola per estetista f410 ever 2005 q cd britney spears le bouton d or panasonic lumix 30 virgilio mail ghost norton == 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. NOTE: The permission can not contain a capital letter, this causes trouble later on if you try and create a module that needs this permission 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