phpBB

Development Wiki

Moderator permissions

From phpBB Development Wiki

Moderator permissions can be defined in any page by using the predefined auth class.

Moderator Permission Options

Auth Option Auth Usage Auth Lang
m_
$auth->acl_get('m_'); //global
$auth->acl_get('m_'$forum_id); //forum specific
Moderator permissions
m_approve
$auth->acl_get('m_approve'$forum_id);
Can approve posts
m_ban
$auth->acl_get('m_ban');
Can manage bans
m_chgposter
$auth->acl_get('m_chgposter'$forum_id);
Can change post author
m_delete
$auth->acl_get('m_delete'$forum_id);
Can delete posts
m_edit
$auth->acl_get('m_edit'$forum_id);
Can edit posts
m_info
$auth->acl_get('m_info'$forum_id);
Can view post details
m_lock
$auth->acl_get('m_lock'$forum_id);
Can lock topics
m_merge
$auth->acl_get('m_merge'$forum_id);
Can merge topics
m_move
$auth->acl_get('m_move'$forum_id);
Can move topics
m_report
$auth->acl_get('m_report'$forum_id);
Can close and delete reports
m_split
$auth->acl_get('m_split'$forum_id);
Can split topics
m_warn
$auth->acl_get('m_warn');
Can issue warnings


Moderator Only Variables and Switches

You can use variables and switches to define what moderators are able to see.
e.g.:

$template->assign_vars(array(
    
'MY_VARIABLE'    => ($auth->acl_get('m_')) ? $variable_for_moderator $variable_for_user,
    
    
// or a switch (better)
    
'S_IS_MODERATOR'=> ($auth->acl_get('m_')) ? true false,
    
    
// moderator has lock permissions, to lock the currently viewable topics within a forum.
    
'S_CAN_LOCK'    => ($auth->acl_get('m_lock')) ? true false,
    
    
// moderator has ban permissions.
    // Ban permissions are global, and therefor not limited to a specific forum
    
'S_CAN_BAN'        => ($auth->acl_get('m_ban')) ? true false,
));

Usage within templates: (example)

<!-- IF S_IS_MODERATOR -->I am a Moderator!<!-- ELSE -->I am not a Moderator<!-- ENDIF -->
<!-- IF 
S_CAN_LOCK -->I can lock topics<!-- ELSE -->Even if I have some Moderator permissionsI cannot lock topics<!-- ENDIF -->
<!-- IF 
S_CAN_BAN -->I can ban people!!<!-- ELSE -->I watch can’t ban people<!-- ENDIF -->

{
MY_VARIABLE}

Restricting Scripts/Pages to Moderators

<?php
/** 
*
* @author Highway of Life
* @package Develop
* @version $Id: page.php $
* @copyright (c) 2007 copyright info
* @license http://opensource.org/licenses/gpl-license.php GNU Public License 
*
*/

/**
* @ignore
*/
define('IN_PHPBB'true);
$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('common');

// is the user logged in?
if (!$user->data['is_registered'])
{
    if (
$user->data['is_bot'])
    {
        
// the user is a bot, send them back to home plate...
        
redirect(append_sid("{$phpbb_root_path}index.$phpEx"));
    }
    
// the user is not logged in, give them a chance to login here...
    
login_box('''LOGIN');
}
else if (!
$auth->acl_get('m_'))
{
    
// the user is logged in, but they do not have Moderator permissions, give them a nice warning message
    
trigger_error('NOT_AUTHORISED');
}

// the rest of your script/page

// you can also be specific with the moderator permissions...
// to give access to ONLY those moderators who have ban permissions (for example)
// we would have used the following code above.
else if (!$auth->acl_get('m_ban'))
{
    
// the user does not have moderator ban permissions...
    
trigger_error('NOT_AUTHORISED');
}

See Also