<commit_before><?php
class Vps_Acl extends Zend_Acl
{
    protected $_componentAclClass = 'Vps_Component_Acl';
    protected $_componentAcl;
    protected $_vpcResourcesLoaded = false;

    public function __construct()
    {
        $this->addRole(new Zend_Acl_Role('guest'));
        $this->addRole(new Vps_Acl_Role_Admin('admin', 'Administrator'));
        $this->addRole(new Zend_Acl_Role('cli'));

        $this->add(new Zend_Acl_Resource('default_index'));
        $this->add(new Zend_Acl_Resource('vps_user_menu'));
        $this->add(new Zend_Acl_Resource('vps_user_login'));
        $this->add(new Zend_Acl_Resource('vps_user_changeuser'));
        $this->add(new Zend_Acl_Resource('vps_error_error'));
        $this->add(new Zend_Acl_Resource('vps_user_about'));
        $this->add(new Zend_Acl_Resource('vps_welcome_index'));
        $this->add(new Zend_Acl_Resource('vps_welcome_content'));
        $this->add(new Zend_Acl_Resource('vps_debug'));
        $this->add(new Zend_Acl_Resource('vps_debug_sql'), 'vps_debug');
        $this->add(new Zend_Acl_Resource('vps_debug_assets'), 'vps_debug');
        $this->add(new Zend_Acl_Resource('vps_debug_activate'), 'vps_debug');
        $this->add(new Zend_Acl_Resource('vps_debug_session-restart'), 'vps_debug');
        $this->add(new Zend_Acl_Resource('vps_media_upload'));
        $this->add(new Zend_Acl_Resource('vps_test'));
        $this->add(new Zend_Acl_Resource('edit_role'));
        $this->add(new Vps_Acl_Resource_EditRole('edit_role_admin', 'admin'), 'edit_role');

        $this->add(new Vps_Acl_Resource_UserSelf('vps_user_self', '/vps/user/self'));

        $this->add(new Zend_Acl_Resource('vps_spam_set'));

        $this->add(new Zend_Acl_Resource('vps_cli'));
        $this->add(new Zend_Acl_Resource('vps_cli_help'));
        $this->add(new Zend_Acl_Resource('vps_cli_index'));
        $this->add(new Zend_Acl_Resource('vps_cli_trlparse'));
        $this->add(new Zend_Acl_Resource('vps_cli_hlpparse'));
        $this->add(new Zend_Acl_Resource('vps_test_connectionerror'));
        $this->allow('cli', 'vps_cli');
        $this->allow('cli', 'vps_cli_help');
        $this->allow('cli', 'vps_cli_index');
        $this->allow('cli', 'vps_cli_trlparse');
        $this->allow('cli', 'vps_cli_hlpparse');

        $this->allow(null, 'default_index');
        $this->allow(null, 'vps_test_connectionerror');
        $this->deny('guest', 'default_index');
        $this->allow(null, 'vps_user_menu');
        $this->allow(null, 'vps_user_login');
        $this->allow(null, 'vps_error_error');
        $this->allow(null, 'vps_user_about');
        $this->allow(null, 'vps_welcome_index');
        $this->allow(null, 'vps_welcome_content');
        $this->deny('guest', 'vps_welcome_index');
        $this->allow(null, 'vps_user_self');
        $this->deny('guest', 'vps_user_self');
        $this->allow('admin', 'vps_debug');
        $this->allow(null, 'vps_media_upload');
        $this->allow('admin', 'edit_role');
        $this->allow(null, 'vps_spam_set');
        $this->allow(null, 'vps_debug_session-restart');
        $this->allow(null, 'vps_test');
    }

    public function isAllowed($role = null, $resource = null, $privilege = null)
    {
        $ret = parent::isAllowed($role, $resource, $privilege);

        if (!$ret) {
            if (null !== $resource) {
                $resource = $this->get($resource);
            }

            if ($resource instanceof Vps_Acl_Resource_MenuDropdown) {
                foreach ($this->getResources($resource) as $r) {
                    if ($r instanceof Vps_Acl_Resource_MenuUrl
                        && parent::isAllowed($role, $r, $privilege)
                    ) {
                        $ret = true;
                        break;
                    }
                }
            }
        }

        if (!$ret) {
            $additionalRoles = $this->_getAdditionalRolesByRole($user->role);
            if ($additionalRoles) {
                foreach ($user->getAdditionalRoles() as $r) {
                    if (in_array($r, $additionalRoles) && $this->isAllowed($r, $resource, $privilege)) {
                        return true;
                    }
                }
            }
        }

        return $ret;
    }

    public function isAllowedUser($user, $resource = null, $privilege = null)
    {
        if (is_numeric($user)) {
            $userModel = Vps_Registry::get('userModel');
            $user = $userModel->getRow($userModel->select()->whereEquals('id', $user));
        }

        if (!$user) {
            return $this->isAllowed('guest', $resource, $privilege);
        }
        return $this->isAllowed($user->role, $resource, $privilege);
    }

    private function _getAdditionalRolesByRole($role)
    {
        $ret = array();
        foreach ($this->getRoles() as $r) {
            if ($r instanceof Vps_Acl_Role_Additional
                && $r->getParentRoleId() == $role
            ) {
                $ret[] = $r->getRoleId();
            }
        }
        return $ret;
    }

    public function getAllowedEditResourceRoleIdsByRole($role)
    {
        $ret = array();
        foreach ($this->_getAllowedEditResourcesByRole($role) as $res) {
            $ret[] = $res->getRoleId();
        }
        return $ret;
    }
<commit_msg>revert letzte änderung, war ein voller schmarrn<commit_after><?php
class Vps_Acl extends Zend_Acl
{
    protected $_componentAclClass = 'Vps_Component_Acl';
    protected $_componentAcl;
    protected $_vpcResourcesLoaded = false;

    public function __construct()
    {
        $this->addRole(new Zend_Acl_Role('guest'));
        $this->addRole(new Vps_Acl_Role_Admin('admin', 'Administrator'));
        $this->addRole(new Zend_Acl_Role('cli'));

        $this->add(new Zend_Acl_Resource('default_index'));
        $this->add(new Zend_Acl_Resource('vps_user_menu'));
        $this->add(new Zend_Acl_Resource('vps_user_login'));
        $this->add(new Zend_Acl_Resource('vps_user_changeuser'));
        $this->add(new Zend_Acl_Resource('vps_error_error'));
        $this->add(new Zend_Acl_Resource('vps_user_about'));
        $this->add(new Zend_Acl_Resource('vps_welcome_index'));
        $this->add(new Zend_Acl_Resource('vps_welcome_content'));
        $this->add(new Zend_Acl_Resource('vps_debug'));
        $this->add(new Zend_Acl_Resource('vps_debug_sql'), 'vps_debug');
        $this->add(new Zend_Acl_Resource('vps_debug_assets'), 'vps_debug');
        $this->add(new Zend_Acl_Resource('vps_debug_activate'), 'vps_debug');
        $this->add(new Zend_Acl_Resource('vps_debug_session-restart'), 'vps_debug');
        $this->add(new Zend_Acl_Resource('vps_media_upload'));
        $this->add(new Zend_Acl_Resource('vps_test'));
        $this->add(new Zend_Acl_Resource('edit_role'));
        $this->add(new Vps_Acl_Resource_EditRole('edit_role_admin', 'admin'), 'edit_role');

        $this->add(new Vps_Acl_Resource_UserSelf('vps_user_self', '/vps/user/self'));

        $this->add(new Zend_Acl_Resource('vps_spam_set'));

        $this->add(new Zend_Acl_Resource('vps_cli'));
        $this->add(new Zend_Acl_Resource('vps_cli_help'));
        $this->add(new Zend_Acl_Resource('vps_cli_index'));
        $this->add(new Zend_Acl_Resource('vps_cli_trlparse'));
        $this->add(new Zend_Acl_Resource('vps_cli_hlpparse'));
        $this->add(new Zend_Acl_Resource('vps_test_connectionerror'));
        $this->allow('cli', 'vps_cli');
        $this->allow('cli', 'vps_cli_help');
        $this->allow('cli', 'vps_cli_index');
        $this->allow('cli', 'vps_cli_trlparse');
        $this->allow('cli', 'vps_cli_hlpparse');

        $this->allow(null, 'default_index');
        $this->allow(null, 'vps_test_connectionerror');
        $this->deny('guest', 'default_index');
        $this->allow(null, 'vps_user_menu');
        $this->allow(null, 'vps_user_login');
        $this->allow(null, 'vps_error_error');
        $this->allow(null, 'vps_user_about');
        $this->allow(null, 'vps_welcome_index');
        $this->allow(null, 'vps_welcome_content');
        $this->deny('guest', 'vps_welcome_index');
        $this->allow(null, 'vps_user_self');
        $this->deny('guest', 'vps_user_self');
        $this->allow('admin', 'vps_debug');
        $this->allow(null, 'vps_media_upload');
        $this->allow('admin', 'edit_role');
        $this->allow(null, 'vps_spam_set');
        $this->allow(null, 'vps_debug_session-restart');
        $this->allow(null, 'vps_test');
    }

    public function isAllowed($role = null, $resource = null, $privilege = null)
    {
        $ret = parent::isAllowed($role, $resource, $privilege);

        if (!$ret) {
            if (null !== $resource) {
                $resource = $this->get($resource);
            }

            if ($resource instanceof Vps_Acl_Resource_MenuDropdown) {
                foreach ($this->getResources($resource) as $r) {
                    if ($r instanceof Vps_Acl_Resource_MenuUrl
                        && parent::isAllowed($role, $r, $privilege)
                    ) {
                        $ret = true;
                        break;
                    }
                }
            }
        }

        return $ret;
    }

    public function isAllowedUser($user, $resource = null, $privilege = null)
    {
        if (is_numeric($user)) {
            $userModel = Vps_Registry::get('userModel');
            $user = $userModel->getRow($userModel->select()->whereEquals('id', $user));
        }

        if (!$user) {
            return $this->isAllowed('guest', $resource, $privilege);
        }
        $ret = $this->isAllowed($user->role, $resource, $privilege);
        if (!$ret) {
            $additionalRoles = $this->_getAdditionalRolesByRole($user->role);
            if ($additionalRoles) {
                foreach ($user->getAdditionalRoles() as $r) {
                    if (in_array($r, $additionalRoles) && $this->isAllowed($r, $resource, $privilege)) {
                        return true;
                    }
                }
            }
        }
        return $ret;
    }

    private function _getAdditionalRolesByRole($role)
    {
        $ret = array();
        foreach ($this->getRoles() as $r) {
            if ($r instanceof Vps_Acl_Role_Additional
                && $r->getParentRoleId() == $role
            ) {
                $ret[] = $r->getRoleId();
            }
        }
        return $ret;
    }

    public function getAllowedEditResourceRoleIdsByRole($role)
    {
        $ret = array();
        foreach ($this->_getAllowedEditResourcesByRole($role) as $res) {
            $ret[] = $res->getRoleId();
        }
        return $ret;
    }

{'fraction_non_alphanumeric': 0.16009345794392524, 'fraction_numerical': 0.0, 'mean_word_length': 2.5516096913375375, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 139, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4570013', 'n_tokens_mistral': 3583, 'n_tokens_neox': 3480, 'n_words': 486}