Wicked_Page::allows PHP Method

allows() public method

Returns if the page allows a mode. Access rights and user state are taken into consideration.
public allows ( integer $mode ) : boolean
$mode integer The mode to check for.
return boolean True if the mode is allowed.
    public function allows($mode)
    {
        global $browser;
        $pagePerms = $this->getPermissions();
        switch ($mode) {
            case Wicked::MODE_CREATE:
                // Special mode for pages that don't exist yet - generic
                // to all pages.
                if ($browser->isRobot()) {
                    return false;
                }
                if ($GLOBALS['registry']->isAdmin()) {
                    return true;
                }
                $permName = 'wicked:pages';
                $perms = $GLOBALS['injector']->getInstance('Horde_Perms');
                if ($perms->exists($permName)) {
                    return $perms->hasPermission($permName, $GLOBALS['registry']->getAuth(), Horde_Perms::EDIT);
                } else {
                    return $GLOBALS['registry']->getAuth();
                }
                break;
            case Wicked::MODE_EDIT:
                if ($browser->isRobot()) {
                    return false;
                }
                if ($GLOBALS['registry']->isAdmin()) {
                    return true;
                }
                if (($pagePerms & Horde_Perms::EDIT) == 0) {
                    return false;
                }
                break;
            case Wicked::MODE_REMOVE:
                if ($browser->isRobot()) {
                    return false;
                }
                if ($GLOBALS['registry']->isAdmin()) {
                    return true;
                }
                if (($pagePerms & Horde_Perms::DELETE) == 0) {
                    return false;
                }
                break;
                // All other modes require READ permissions.
            // All other modes require READ permissions.
            default:
                if ($GLOBALS['registry']->isAdmin()) {
                    return true;
                }
                if (($pagePerms & Horde_Perms::READ) == 0) {
                    return false;
                }
                break;
        }
        return $this->supports($mode);
    }

Usage Example

Example #1
0
 /**
  * Returns if the page allows a mode. Access rights and user state
  * are taken into consideration.
  *
  * @see $supportedModes
  *
  * @param integer $mode  The mode to check for.
  *
  * @return boolean  True if the mode is allowed.
  */
 public function allows($mode)
 {
     if ($mode == Wicked::MODE_EDIT) {
         $page = Wicked_Page::getPage($this->referrer());
         if ($page->isLocked(Wicked::lockUser())) {
             return false;
         }
     }
     return parent::allows($mode);
 }
All Usage Examples Of Wicked_Page::allows