Agora_Driver::hasPermission PHP Method

hasPermission() public method

Finds out if the user has the specified rights to the messages forum.
public hasPermission ( integer $perm = Horde_Perms::READ, integer $forum_id = null, string $scope = null ) : boolean
$perm integer The permission level needed for access.
$forum_id integer Forum to check permissions for.
$scope string Application scope to use.
return boolean True if the user has the specified permissions.
    public function hasPermission($perm = Horde_Perms::READ, $forum_id = null, $scope = null)
    {
        // Allow all admins
        if ($forum_id === null && isset($this->_forum['author']) && $this->_forum['author'] == $GLOBALS['registry']->getAuth() || $GLOBALS['registry']->isAdmin(array('permission' => 'agora:admin'))) {
            return true;
        }
        // Allow forum author
        if ($forum_id === null) {
            $forum_id = $this->_forum_id;
        }
        if ($scope === null) {
            $scope = $this->_scope;
        }
        $perms = $GLOBALS['injector']->getInstance('Horde_Perms');
        if (!$perms->exists('agora:forums:' . $scope) && !$perms->exists('agora:forums:' . $scope . ':' . $forum_id)) {
            return $perm & Horde_Perms::DELETE ? false : true;
        }
        return $perms->hasPermission('agora:forums:' . $scope, $GLOBALS['registry']->getAuth(), $perm) || $perms->hasPermission('agora:forums:' . $scope . ':' . $forum_id, $GLOBALS['registry']->getAuth(), $perm);
    }

Usage Example

コード例 #1
0
ファイル: Application.php プロジェクト: raz0rsdge/horde
 /**
  */
 public function menu($menu)
 {
     $scope = Horde_Util::getGet('scope', 'agora');
     /* Agora Home. */
     $url = Horde::url('forums.php')->add('scope', $scope);
     $menu->add($url, _("_Forums"), 'forums.png', null, null, null, dirname($_SERVER['PHP_SELF']) == $GLOBALS['registry']->get('webroot') && basename($_SERVER['PHP_SELF']) == 'index.php' ? 'current' : null);
     /* Thread list, if applicable. */
     if (isset($GLOBALS['forum_id'])) {
         $menu->add(Agora::setAgoraId($GLOBALS['forum_id'], null, Horde::url('threads.php')), _("_Threads"), 'threads.png');
         if ($scope == 'agora' && $GLOBALS['registry']->getAuth()) {
             $menu->add(Agora::setAgoraId($GLOBALS['forum_id'], null, Horde::url('messages/edit.php')), _("New Thread"), 'newmessage.png');
         }
     }
     if ($scope == 'agora' && Agora_Driver::hasPermission(Horde_Perms::DELETE, 0, $scope)) {
         $menu->add(Horde::url('editforum.php'), _("_New Forum"), 'newforum.png', null, null, null, Horde_Util::getFormData('agora') ? '__noselection' : null);
     }
     if (Agora_Driver::hasPermission(Horde_Perms::DELETE, 0, $scope)) {
         $url = Horde::url('moderate.php')->add('scope', $scope);
         $menu->add($url, _("_Moderate"), 'moderate.png');
     }
     if ($GLOBALS['registry']->isAdmin()) {
         $menu->add(Horde::url('moderators.php'), _("_Moderators"), 'hot.png');
     }
     $url = Horde::url('search.php')->add('scope', $scope);
     $menu->add($url, _("_Search"), 'search.png');
 }