phpBB

Development Wiki

Difference between revisions of "Tutorial.Permissions"

From phpBB Development Wiki

m
(Alternative method - using UMIL)
 
(19 intermediate revisions by 12 users not shown)
Line 1: Line 1:
[http://tulip123456.ifrance.com/topic/foto-donne.html foto donne grasse nere porche] [http://jnk713.ifrance.com/img/styles/donne-e/ donne e dipendenza dal lavoro] [http://doctorpinkerton.ifrance.com/lib/sfondo-canalis/ sfondo canalis] [http://spirit-psyki.ifrance.com/lib/dante-paradiso.html dante paradiso riassunto canto xxxiii] [http://competitio.ifrance.com/www-sex/ www sex culo it] [http://doctorpinkerton.ifrance.com/lib/roxana-diaz/ roxana diaz porno] [http://spirit-psyki.ifrance.com/lib/eros-gratutiti.html eros gratutiti] [http://cincydj.ifrance.com/images/small/go-go/ go go very sexy show] [http://tulip123456.ifrance.com/topic/video-salsa.html video salsa gratis] [http://end14april.ifrance.com/blog/madonna-sexy.html madonna sexy] [http://tulip123456.ifrance.com/topic/sexo-profesional.html sexo profesional] [http://jnk713.ifrance.com/img/styles/baila-sexy/ baila sexy thing] [http://cincydj.ifrance.com/images/small/donne-in/ donne in cerca damore] [http://cincydj.ifrance.com/images/small/foto-transex/ foto transex grtais] [http://adrienneee.ifrance.com/blog/porno-exitantes/ porno exitantes] [http://adrienneee.ifrance.com/blog/vedo-nudo/ vedo nudo] [http://doctorpinkerton.ifrance.com/lib/locali-gay/ locali gay l] [http://mi-kkiechang.ifrance.com/tarzana-sesso.html tarzana sesso selvaggio] [http://end14april.ifrance.com/blog/george-.html george  beer] [http://doctorpinkerton.ifrance.com/lib/anziani-gay/ anziani gay foto galleria] [http://bakadeshi.ifrance.com/img/styles/twin-snakes.html twin snakes] [http://doctorpinkerton.ifrance.com/lib/porno-incinte/ porno incinte] [http://mi-kkiechang.ifrance.com/gay-web.html gay web] [http://tulip123456.ifrance.com/topic/foto-gratis.html foto gratis pompini] [http://spirit-psyki.ifrance.com/lib/sessogay.html sessogay] [http://furrysoap.ifrance.com/dyson-edward/ dyson, edward george] [http://tulip123456.ifrance.com/topic/lesbo-stivali.html lesbo stivali] [http://bakadeshi.ifrance.com/img/styles/hentay-sailor.html hentay sailor moon] [http://furrysoap.ifrance.com/lesbo-racconti/ lesbo racconti] [http://competitio.ifrance.com/ipergratis/ ipergratis] [http://end14april.ifrance.com/blog/loghi-sex.html loghi sex] [http://tulip123456.ifrance.com/topic/sesso-forum.html sesso forum] [http://cincydj.ifrance.com/images/small/immagini-transessuali/ immagini transessuali] [http://furrysoap.ifrance.com/japanese-sex/ japanese sex] [http://bakadeshi.ifrance.com/img/styles/foto-di.html foto di donne mature] [http://jnk713.ifrance.com/img/styles/teenager-sesso/ teenager sesso] [http://adrienneee.ifrance.com/blog/girl-fuck/ girl fuck] [http://elixirium.ifrance.com/lib/rollergirl.html rollergirl] [http://furrysoap.ifrance.com/video-gratis/ video gratis de michelle vieth xxx] [http://doctorpinkerton.ifrance.com/lib/le-foto/ le foto sexy di garko] [http://adrienneee.ifrance.com/blog/club-sex/ club sex] [http://mi-kkiechang.ifrance.com/www-paolaechiara.html www paolaechiara] [http://elixirium.ifrance.com/lib/britney-spears.html britney spears xxx] [http://adrienneee.ifrance.com/blog/nudoty/ nudoty] [http://competitio.ifrance.com/famiglia-incestuosa/ famiglia incestuosa] [http://spirit-psyki.ifrance.com/lib/immagini-tettone.html immagini tettone gratis] [http://adrienneee.ifrance.com/blog/sex-termometer/ sex termometer] [http://elixirium.ifrance.com/lib/haiduci-xxx.html haiduci xxx] [http://end14april.ifrance.com/blog/fontana-canalis.html fontana canalis] [http://adrienneee.ifrance.com/blog/show-girl/ show girl croata] [http://jnk713.ifrance.com/img/styles/experimento-caseros/ experimento caseros] [http://cincydj.ifrance.com/images/small/videos-de/ videos de porno] [http://elixirium.ifrance.com/lib/saudi-sesso.html saudi sesso] [http://mi-kkiechang.ifrance.com/eva-robinson.html eva robinson nuda] [http://doctorpinkerton.ifrance.com/lib/xxxx-sex/ xxxx sex] [http://tulip123456.ifrance.com/topic/canale.html canale5] [http://competitio.ifrance.com/www-donne/ www donne mature it] [http://jnk713.ifrance.com/img/styles/www-adultswim/ www adultswim] [http://competitio.ifrance.com/mature-xxx/ mature xxx] [http://tulip123456.ifrance.com/topic/ragazze-russe.html ragazze russe] [http://bakadeshi.ifrance.com/img/styles/eurosex.html eurosex] [http://mi-kkiechang.ifrance.com/nuda-gol.html nuda gol video] [http://elixirium.ifrance.com/lib/foto-nuda.html foto nuda annalisa caputo] [http://tulip123456.ifrance.com/topic/sexfilm.html sexfilm] [http://cincydj.ifrance.com/images/small/gayromeo/ gayromeo] [http://bakadeshi.ifrance.com/img/styles/sorella-racconti.html sorella racconti erotici] [http://tulip123456.ifrance.com/topic/sexy-parodius.html sexy parodius] [http://spirit-psyki.ifrance.com/lib/donne-grasse.html donne grasse nude] [http://adrienneee.ifrance.com/blog/will-you/ will you be my girl] [http://competitio.ifrance.com/helicopteros/ helicopteros] [http://doctorpinkerton.ifrance.com/lib/sesso-hot/ sesso hot] [http://mi-kkiechang.ifrance.com/nudiste.html nudiste] [http://furrysoap.ifrance.com/film-amatoriale/ film amatoriale porno] [http://elixirium.ifrance.com/lib/foto-di.html foto di ragazze anoressiche] [http://mi-kkiechang.ifrance.com/topless-tennis.html topless tennis] [http://end14april.ifrance.com/blog/serena-dandini.html serena dandini nuda] [http://doctorpinkerton.ifrance.com/lib/scopate-di/ scopate di cvalli con donne] [http://bakadeshi.ifrance.com/img/styles/george-weasley.html george weasley] [http://doctorpinkerton.ifrance.com/lib/im-too/ im too gratis] [http://tulip123456.ifrance.com/topic/www-sexso.html www sexso com] [http://jnk713.ifrance.com/img/styles/calimero-dance/ calimero dance gratis] [http://bakadeshi.ifrance.com/img/styles/fuck-it.html fuck it female] [http://competitio.ifrance.com/gratis-pics/ gratis pics] [http://doctorpinkerton.ifrance.com/lib/porno/ porno 70] [http://bakadeshi.ifrance.com/img/styles/festo-gay.html festo gay cavalier] [http://end14april.ifrance.com/blog/xgirls.html xgirls] [http://mi-kkiechang.ifrance.com/lulu-transex.html lulu transex] [http://furrysoap.ifrance.com/donne-per/ donne per singoli] [http://spirit-psyki.ifrance.com/lib/casalinghe-sexy.html casalinghe sexy] [http://furrysoap.ifrance.com/uomo-che/ uomo che fa sesso] [http://elixirium.ifrance.com/lib/webcam-gay.html webcam gay] [http://doctorpinkerton.ifrance.com/lib/anal-fisting/ anal fisting] [http://competitio.ifrance.com/max-deangelis/ max deangelis nuda] [http://furrysoap.ifrance.com/sesso-cavalli/ sesso cavalli] [http://competitio.ifrance.com/calendario-nuda/ calendario nuda] [http://competitio.ifrance.com/suonerie-gratis/ suonerie gratis da scaricare] [http://bakadeshi.ifrance.com/img/styles/polisex.html polisex] [http://end14april.ifrance.com/blog/sexywomen.html sexywomen] [http://jnk713.ifrance.com/img/styles/foto-e/ foto e video disesso] [http://end14april.ifrance.com/blog/siti-erotici.html siti erotici] [http://spirit-psyki.ifrance.com/lib/tv-terrestre.html tv terrestre analogico] [http://spirit-psyki.ifrance.com/lib/donne-nude.html donne nude] [http://bakadeshi.ifrance.com/img/styles/sexuality.html sexuality] [http://jnk713.ifrance.com/img/styles/ginnasta-nuda/ ginnasta nuda] [http://tulip123456.ifrance.com/topic/videos-gratis.html videos gratis de sexo] [http://adrienneee.ifrance.com/blog/racconti-di/ racconti di orgasmi] [http://spirit-psyki.ifrance.com/lib/pullman-george.html pullman, george mortimer] [http://end14april.ifrance.com/blog/giochini-gratis.html giochini gratis] [http://doctorpinkerton.ifrance.com/lib/myfirstsexteacher-com/ myfirstsexteacher com] [http://jnk713.ifrance.com/img/styles/britney-spears/ britney spears porno] [http://tulip123456.ifrance.com/topic/gay-palestrati.html gay palestrati] [http://competitio.ifrance.com/il-sesso/ il sesso degli angeli] [http://competitio.ifrance.com/www-sexool/ www sexool com] [http://tulip123456.ifrance.com/topic/sexy-jeans.html sexy jeans] [http://adrienneee.ifrance.com/blog/hard-porno/ hard porno] [http://mi-kkiechang.ifrance.com/donkey-sexs.html donkey sexs] [http://competitio.ifrance.com/film-pornografici/ film pornografici] [http://competitio.ifrance.com/nudo-uomo/ nudo uomo] [http://end14april.ifrance.com/blog/www-wordlsex.html www wordlsex] [http://tulip123456.ifrance.com/topic/www-sexycoppie.html www sexycoppie it] [http://doctorpinkerton.ifrance.com/lib/george-pierre/ george, pierre] [http://cincydj.ifrance.com/images/small/hentai-flash/ hentai flash] [http://spirit-psyki.ifrance.com/lib/non-scherzare.html non scherzare con le donne - i galli del mare] [http://elixirium.ifrance.com/lib/shakira-total.html shakira total mente desnuda] [http://elixirium.ifrance.com/lib/teen-sex.html teen sex videos] [http://end14april.ifrance.com/blog/filmati-gratis.html filmati gratis porno] [http://end14april.ifrance.com/blog/donne-belissime.html donne belissime] [http://mi-kkiechang.ifrance.com/duncan-nudo.html duncan nudo] [http://tulip123456.ifrance.com/topic/sophie-ellis.html sophie ellis bextor nuda] [http://tulip123456.ifrance.com/topic/www-bolognaeros.html www bolognaeros com] [http://mi-kkiechang.ifrance.com/psycho-girl.html psycho girl] [http://adrienneee.ifrance.com/blog/donne-enne/ donne 47enne] [http://elixirium.ifrance.com/lib/kragujevac-porno.html kragujevac porno] [http://bakadeshi.ifrance.com/img/styles/le-brave.html le brave donne di bangkok] [http://adrienneee.ifrance.com/blog/suonerie-gratis/ suonerie gratis] [http://mi-kkiechang.ifrance.com/sfondi-gratis.html sfondi gratis motorola] [http://tulip123456.ifrance.com/topic/pamela-anderson.html pamela anderson calendario] [http://spirit-psyki.ifrance.com/lib/margot-sikabonyi.html margot sikabonyi nuda] [http://doctorpinkerton.ifrance.com/lib/lola-ponce/ lola ponce nuda] [http://elixirium.ifrance.com/lib/aria-giovanni.html aria giovanni foto porno] [http://jnk713.ifrance.com/img/styles/girlie-nite/ girlie nite out] [http://spirit-psyki.ifrance.com/lib/giochi-java.html giochi java gratis] [http://elixirium.ifrance.com/lib/anna-la.html anna la rosa nuda] [http://elixirium.ifrance.com/lib/transex-con.html transex con telefono] [http://elixirium.ifrance.com/lib/musica-classica.html musica classica gratis] [http://adrienneee.ifrance.com/blog/disegni-gratis/ disegni gratis burro] [http://elixirium.ifrance.com/lib/programmazione-settimanale.html programmazione settimanale atletica legg] [http://bakadeshi.ifrance.com/img/styles/midi-file.html midi file sequenze da scaricare gratis] [http://competitio.ifrance.com/talia-desnuda/ talia desnuda] [http://adrienneee.ifrance.com/blog/katia-gf/ katia gf4 sexy] [http://adrienneee.ifrance.com/blog/videos-pono/ videos pono xxx de acceso facil] [http://tulip123456.ifrance.com/topic/invio-gratis.html invio gratis sms] [http://end14april.ifrance.com/blog/fuckyou.html fuckyou] [http://elixirium.ifrance.com/lib/gun-shy.html gun shy - un revolver in analisi] [http://jnk713.ifrance.com/img/styles/nudo-pitt/ nudo pitt integrale] [http://end14april.ifrance.com/blog/posizioni-x.html posizioni x fare sesso] [http://doctorpinkerton.ifrance.com/lib/angela-finocchiaro/ angela finocchiaro nuda] [http://tulip123456.ifrance.com/topic/video-porno.html video porno britney spears] [http://end14april.ifrance.com/blog/xena-tutta.html xena tutta nuda] [http://competitio.ifrance.com/foto-donne/ foto donne porche over 50] [http://jnk713.ifrance.com/img/styles/videos-gratis/ videos gratis de orgasmos femeninos] [http://bakadeshi.ifrance.com/img/styles/sfondo-gratis.html sfondo gratis pc] [http://furrysoap.ifrance.com/giochi-da/ giochi da scaricare gratis xxx] [http://competitio.ifrance.com/eamon-fuck/ eamon fuck it video] [http://end14april.ifrance.com/blog/canaletta-ghisa.html canaletta ghisa] [http://doctorpinkerton.ifrance.com/lib/guanti-donne/ guanti donne] [http://cincydj.ifrance.com/images/small/donne-venezuelane/ donne venezuelane a napoli] [http://bakadeshi.ifrance.com/img/styles/web-cam.html web cam live show erotic gratis] [http://furrysoap.ifrance.com/sex-girls/ sex girls vree] [http://jnk713.ifrance.com/img/styles/saint-george/ saint george] [http://furrysoap.ifrance.com/analisi-web/ analisi web] [http://adrienneee.ifrance.com/blog/peliculas-prono/ peliculas prono gratis] [http://mi-kkiechang.ifrance.com/spycam-in.html spycam in bagni e hotel gratis] [http://cincydj.ifrance.com/images/small/ragazze-oslo/ ragazze oslo] [http://furrysoap.ifrance.com/porno-market/ porno market] [http://furrysoap.ifrance.com/free-mpeg/ free mpeg fuck in pantyhose] [http://jnk713.ifrance.com/img/styles/partituras-gratis/ partituras gratis] [http://mi-kkiechang.ifrance.com/playboy-foto.html playboy foto] [http://cincydj.ifrance.com/images/small/gay-cam/ gay cam] [http://elixirium.ifrance.com/lib/galleria-video.html galleria video porno di oggi] [http://doctorpinkerton.ifrance.com/lib/celebrita-a/ celebrita a piedi nudi] [http://bakadeshi.ifrance.com/img/styles/porno-video.html porno video free] [http://end14april.ifrance.com/blog/mess-gratis.html mess gratis] [http://spirit-psyki.ifrance.com/lib/showgirl-italiana.html showgirl italiana j m] [http://spirit-psyki.ifrance.com/lib/video-clip.html video clip sex] [http://elixirium.ifrance.com/lib/sabrina-ferilli.html sabrina ferilli completamente nuda] [http://tulip123456.ifrance.com/topic/previsioni-lotto.html previsioni lotto gratis] [http://furrysoap.ifrance.com/good-girl/ good girl] [http://spirit-psyki.ifrance.com/lib/uomini-nudi.html uomini nudi col pisello] [http://spirit-psyki.ifrance.com/lib/soca-girlz.html soca girlz] [http://mi-kkiechang.ifrance.com/fotos-mujer.html fotos mujer desnuda] [http://elixirium.ifrance.com/lib/free-somali.html free somali sexy girl] [http://doctorpinkerton.ifrance.com/lib/sexy-older/ sexy older women] [http://elixirium.ifrance.com/lib/girls-flashing.html girls flashing] [http://spirit-psyki.ifrance.com/lib/video-gratis.html video gratis pompini] [http://doctorpinkerton.ifrance.com/lib/annunci-per/ annunci per adulti] [http://spirit-psyki.ifrance.com/lib/flash-porno.html flash porno] [http://tulip123456.ifrance.com/topic/foto-nudo.html foto nudo maschile] [http://bakadeshi.ifrance.com/img/styles/pamela-anderson.html pamela anderson video hard download grat] [http://end14april.ifrance.com/blog/due-cazzi.html due cazzi e una pornostar] == Checking permissions ==
+
== Permission types ==
 +
*[[Admin permissions]]
 +
*[[Moderator permissions]]
 +
*[[User permissions]]
 +
*[[Forum permissions]]
 +
 
 +
== Checking permissions ==
  
=== Global perission ===
+
=== Global permission ===
To check if user can for example view other users profiles, use this code:
+
To check if user can for example view other users' profiles, use this code:
 
<php>
 
<php>
 
if (!$auth->acl_get('u_viewprofile'))
 
if (!$auth->acl_get('u_viewprofile'))
 
{
 
{
     trigger_error('NOT_AUTHORIZED');
+
     trigger_error('NOT_AUTHORISED');
 
}
 
}
 
</php>
 
</php>
If he doesn't have permission to do it, he will see only error message and script will stop working after trigger_error.
+
If he doesn't have permission to do it, he will see only error message and script will stop executing (exit) after trigger_error.
  
 
=== Local permission ===
 
=== Local permission ===
Line 16: Line 22:
 
if (!$auth->acl_get('f_read', 5))
 
if (!$auth->acl_get('f_read', 5))
 
{
 
{
     trigger_error('NOT_AUTHORIZED');
+
     trigger_error('NOT_AUTHORISED');
 
}
 
}
 
</php>
 
</php>
Line 25: Line 31:
 
Adding new permissions to Olympus is simple.
 
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
 
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:
 
Example how to add a permission to control who can access and manage foo:
 
=== Using the API (recommended) ===
 
=== Using the API (recommended) ===
Line 40: Line 47:
 
));
 
));
 
?>
 
?>
 +
</php>
 +
 +
==== Sample install page using API to add permission options ====
 +
If you aren't otherwise using an installer for your mod, you can add a page under the install folder called something like install/install_permissions.php that would include something like the following code:
 +
<php>
 +
<?php
 +
 +
/**
 +
*
 +
* install script to set up permission options in the db for foo mod
 +
* @license http://opensource.org/licenses/gpl-license.php GNU Public License
 +
*
 +
*/
 +
 +
/**
 +
* @ignore
 +
*/
 +
 +
// initialize the page
 +
define('IN_PHPBB', true);
 +
define('IN_INSTALL', true);
 +
$phpbb_root_path = (defined('PHPBB_ROOT_PATH')) ? PHPBB_ROOT_PATH : './../';
 +
$phpEx = substr(strrchr(__FILE__, '.'), 1);
 +
include($phpbb_root_path . 'common.' . $phpEx);
 +
 +
 +
// Start session management
 +
$user->session_begin();
 +
$auth->acl($user->data);
 +
$user->setup('mods/foo');
 +
 +
 +
// Setup $auth_admin class so we can add tabulated survey permission options
 +
include($phpbb_root_path . 'includes/acp/auth.' . $phpEx);
 +
$auth_admin = new auth_admin();
 +
 +
// Add foo permissions as local permissions
 +
// (you could instead make them global permissions by making the obvious changes below)
 +
$auth_admin->acl_add_option(array(
 +
'local' => array('f_survey_design', 'f_survey_takeforothers', 'f_survey_viewhiddenresults'),
 +
'global' => array()
 +
));
 +
 +
 +
$message = $user->lang['ADDED_PERMISSIONS'] . '<br /><br />';
 +
$message .= $user->lang['REMOVE_INSTALL'];
 +
trigger_error($message);
 +
 +
?>
 +
</php>
 +
Then, add the following entry in language/en/mods/foo.php (or if you have no language file for the mod, add the following entry to language/en/common.php):
 +
<php>
 +
'ADDED_PERMISSIONS' => 'You have successfully added foo permission options to your database.',
 
</php>
 
</php>
  
Line 46: Line 106:
 
<highlightSyntax language="sqlnew">INSERT INTO phpbb_acl_options (auth_option, is_global, is_local, founder_only) VALUES ('u_view_foo', 1, 0, 0);
 
<highlightSyntax language="sqlnew">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);</highlightSyntax>
 
INSERT INTO phpbb_acl_options (auth_option, is_global, is_local, founder_only) VALUES ('u_manage_foo', 1, 0, 0);</highlightSyntax>
Please note that you need to clear the cache by either deleting <code>cache/data_global.php</code> or executing <code>$cache->destroy('acl_options');</code> after this.
+
Please note that you need to clear the cache by either:
 +
* deleting <code>cache/data_global.php</code> '''and''' <code>cache/data_acl_options.php</code>
 +
OR
 +
 
 +
* executing <code>$cache->destroy('acl_options');</code>
 +
 
 +
... after inserting the SQL manually.
  
 
=== Language file (Adding tabs) ===
 
=== Language file (Adding tabs) ===
Line 55: Line 121:
 
* DO NOT CHANGE
 
* DO NOT CHANGE
 
*/
 
*/
 +
if (!defined('IN_PHPBB'))
 +
{
 +
exit;
 +
}
 +
 
if (empty($lang) || !is_array($lang))
 
if (empty($lang) || !is_array($lang))
 
{
 
{
Line 88: Line 159:
 
if (!$auth->acl_get('u_view_foo'))
 
if (!$auth->acl_get('u_view_foo'))
 
{
 
{
     trigger_error('NOT_AUTHORIZED');
+
     trigger_error('NOT_AUTHORISED');
 
}
 
}
 
</php>
 
</php>
Line 103: Line 174:
 
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.
 
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 ===
+
===Alternative method - using UMIL===
*[[Admin permissions]]
+
The [https://www.phpbb.com/mods/umil Unified MOD Install Library] (UMIL) provides a number of functions for managing permissions:
*[[Moderator permissions]]
+
* [[Umil.permission_exists|permission_exists()]] : Check if a permission (auth) setting exists.
*[[User permissions]]
+
* [[Umil.permission_add|permission_add()]] : Add a permission (auth) option
*[[Forum permissions]]
+
* [[Umil.permission_remove|permission_remove()]] : Remove a permission (auth) option
 +
* [[Umil.permission_set|permission_set()]] : Allows you to set permissions for a certain group/role
 +
* [[Umil.permission_unset|permission_unset()]] : Allows you to remove permissions from a certain group/role (basically setting their permission to ‘No’)
  
 +
 +
For more information on creating a UMIF (Unified MOD Install File) using the UMIL and the permissions functions see the [https://www.phpbb.com/customise/db/official_tool/umil/faq/f_397 UMIL Documentation], [https://www.phpbb.com/customise/db/official_tool/umil/faq/f_396 UMIL Examples], and [[Umil.Umil_overview|UMIL Overview]].
 
[[Category:Concepts]][[Category:Tutorials]][[Category:API]][[Category:Permissions]]
 
[[Category:Concepts]][[Category:Tutorials]][[Category:API]][[Category:Permissions]]
 +
 +
[[ja:Tutorial.Permissions]]

Latest revision as of 09:07, 19 December 2013

Permission types

Checking permissions

Global permission

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

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

If he doesn't have permission to do it, he will see only error message and script will stop executing (exit) 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_AUTHORISED');
}

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')
));
?>

Sample install page using API to add permission options

If you aren't otherwise using an installer for your mod, you can add a page under the install folder called something like install/install_permissions.php that would include something like the following code:

<?php

/** 
*
* install script to set up permission options in the db for foo mod
* @license http://opensource.org/licenses/gpl-license.php GNU Public License 
*
*/

/**
* @ignore
*/

// initialize the page
define('IN_PHPBB'true);
define('IN_INSTALL'true);
$phpbb_root_path = (defined('PHPBB_ROOT_PATH')) ? PHPBB_ROOT_PATH './../';
$phpEx substr(strrchr(__FILE__'.'), 1);
include(
$phpbb_root_path 'common.' $phpEx);


// Start session management
$user->session_begin();
$auth->acl($user->data);
$user->setup('mods/foo');


// Setup $auth_admin class so we can add tabulated survey permission options
include($phpbb_root_path 'includes/acp/auth.' $phpEx);
$auth_admin = new auth_admin();

// Add foo permissions as local permissions
// (you could instead make them global permissions by making the obvious changes below)
$auth_admin->acl_add_option(array(
    
'local'        => array('f_survey_design''f_survey_takeforothers''f_survey_viewhiddenresults'),
    
'global'    => array()
));


$message $user->lang['ADDED_PERMISSIONS'] . '<br /><br />';
$message .= $user->lang['REMOVE_INSTALL'];
trigger_error($message);

?>

Then, add the following entry in language/en/mods/foo.php (or if you have no language file for the mod, add the following entry to language/en/common.php):

'ADDED_PERMISSIONS'    => 'You have successfully added foo permission options to your database.',

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 and cache/data_acl_options.php

OR

  • executing $cache->destroy('acl_options');

... after inserting the SQL manually.

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 (!defined('IN_PHPBB'))
{
    exit;
}

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_AUTHORISED');
}

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.

Alternative method - using UMIL

The Unified MOD Install Library (UMIL) provides a number of functions for managing permissions:


For more information on creating a UMIF (Unified MOD Install File) using the UMIL and the permissions functions see the UMIL Documentation, UMIL Examples, and UMIL Overview.