phpBB

Development Wiki

Difference between revisions of "Tutorial.Permissions"

From phpBB Development Wiki

(coding style)
m (<php>)
Line 2: Line 2:
 
Adding new permissions to Olympus is simple. Example how to add a permission to control who can access foo.php:
 
Adding new permissions to Olympus is simple. Example how to add a permission to control who can access foo.php:
 
* insert a new row into [[Tables/phpbb_acl_options|phpbb_acl_options]]
 
* insert a new row into [[Tables/phpbb_acl_options|phpbb_acl_options]]
INSERT INTO phpbb_acl_options (auth_option, is_global, is_local, founder_only) VALUES('u_foo', 1, 0, 0)
+
<highlightSyntax language="sqlnew">INSERT INTO phpbb_acl_options (auth_option, is_global, is_local, founder_only) VALUES('u_foo', 1, 0, 0)</highlightSyntax>
 
* open language/xx/acp/permissions_phpbb.php and add the language vars
 
* open language/xx/acp/permissions_phpbb.php and add the language vars
  'acl_u_foo' => array('lang' => 'Can view foo.php', 'cat' => 'misc'),  
+
  <php>'acl_u_foo' => array('lang' => 'Can view foo.php', 'cat' => 'misc'),</php>
 
* clear the cache folder by hand or use this code in a installer script:
 
* clear the cache folder by hand or use this code in a installer script:
  $cache->destroy('acl_options');
+
  <php>$cache->destroy('acl_options');</php>
 
* The permission should be ready to assign to users/groups in the acp
 
* The permission should be ready to assign to users/groups in the acp
 
* To check whether the logged in user has the nescessary permission in foo.php:
 
* To check whether the logged in user has the nescessary permission in foo.php:
if (!$auth->acl_get('u_foo'))
+
<php>
{
+
if (!$auth->acl_get('u_foo'))
      trigger_error('NOT_AUTHORIZED');
+
{
}
+
    trigger_error('NOT_AUTHORIZED');
 +
}
 +
</php>
  
  
Line 20: Line 22:
 
* It will automaticly included, don't worry about how.
 
* It will automaticly included, don't worry about how.
 
This is a sample file:
 
This is a sample file:
<?php  
+
<php>
+
<?php  
/**
+
 
* DO NOT CHANGE
+
/**
*/
+
* DO NOT CHANGE
if (empty($lang) || !is_array($lang))
+
*/
{  
+
if (empty($lang) || !is_array($lang))
$lang = array();
+
{  
}
+
$lang = array();
+
}
// DEVELOPERS PLEASE NOTE
+
 
//
+
// DEVELOPERS PLEASE NOTE
// All language files should use UTF-8 as their encoding and the files must not contain a BOM.
+
//
//
+
// 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
+
// Placeholders can now contain order information, e.g. instead of
// translators to re-order the output of data while ensuring it remains correct
+
// '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
+
// You do not need this where single placeholders are used, e.g. 'Message %d' is fine
// in a url you again do not need to specify an order e.g., 'Click %sHERE%s' 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']['mods'] = '.MODS';
+
// Adding new category
+
$lang['permission_cat']['mods'] = '.MODS';
// Adding the permissions
+
 
$lang = array_merge($lang, array(
+
// Adding the permissions
'acl_u_foo' => array('lang' => 'Can view foo.php', 'cat' => 'mods'),
+
$lang = array_merge($lang, array(
));
+
'acl_u_foo' => array('lang' => 'Can view foo.php', 'cat' => 'mods'),
+
));
?>
+
 
 +
?>
 +
</php>

Revision as of 02:11, 6 January 2007

Adding a permission

Adding new permissions to Olympus is simple. Example how to add a permission to control who can access foo.php:

INSERT INTO phpbb_acl_options (auth_option, is_global, is_local, founder_only) VALUES('u_foo', 1, 0, 0)
  • open language/xx/acp/permissions_phpbb.php and add the language vars
'acl_u_foo'        => array('lang' => 'Can view foo.php''cat' => 'misc'),
  • clear the cache folder by hand or use this code in a installer script:
$cache->destroy('acl_options');
  • The permission should be ready to assign to users/groups in the acp
  • To check whether the logged in user has the nescessary permission in foo.php:
if (!$auth->acl_get('u_foo'))
{
     
trigger_error('NOT_AUTHORIZED');
}


Hint: You're able to create your own permission set in a separate file.

  • Create a new file in language/xx/mods
  • Name it permissions_xxx.php
  • It will automaticly included, don't worry about how.

This is a sample file:

<?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']['mods'] = '.MODS';

// Adding the permissions
$lang array_merge($lang, array(
    
'acl_u_foo'    => array('lang' => 'Can view foo.php''cat' => 'mods'),
));

?>