Parse permissions string. Return array(read => true/false, write => true/false)

@param  string  $perm  permissions string
@return string
@author Dmitry (dio) Levashov
543013
protected function parsePermissions($perm, $user = '') {
		$res   = array();
		$parts = array();
		$owner = $user? ($user == $this->options['user']) : $this->options['owner'];
		for ($i = 0, $l = strlen($perm); $i < $l; $i++) {
			$parts[] = substr($perm, $i, 1);
		}

		$read = ($owner && $parts[0] == 'r') || $parts[4] == 'r' || $parts[7] == 'r';
		
		return array(
			'read'  => $parts[0] == 'd' ? $read && (($owner && $parts[3] == 'x') || $parts[6] == 'x' || $parts[9] == 'x') : $read,
			'write' => ($owner && $parts[2] == 'w') || $parts[5] == 'w' || $parts[8] == 'w'
		);
	}
624075
public function permissions()
    {
        $permissions = [];
        foreach (config('typicms.permissions') as $module => $perms) {
            $key = __(ucfirst($module));
            $permissions[$key] = $perms;
        }
        ksort($permissions, SORT_LOCALE_STRING);

        return $permissions;
    }
10452
public function getRolesWithPermission($perm_id)
    {
        $roles = static::$app['db']->connection()
            ->table('roles_permissions')->where('permission_id', '=', $perm_id)->lists('role_id');

        $roles = array_map('intval', $roles);

        return $roles;
    }
173089
public static function getNestedPermissionIds(string $permissionName)
    {
        if (self::isAdmin()) {
            return true;
        }

        $user           = \Craft::$app->getUser();
        $permissionName = strtolower($permissionName);
        $idList         = [];

        if (self::permissionsEnabled()) {
            if (!$user->getId()) {
                return [];
            }

            $permissionList = \Craft::$app->userPermissions->getPermissionsByUserId($user->getId());
            foreach ($permissionList as $permission) {
                if (strpos($permission, $permissionName) === 0) {
                    if (strpos($permission, ':') === false) {
                        continue;
                    }

                    list($name, $id) = explode(':', $permission);

                    $idList[] = $id;
                }
            }

            return $idList;
        }

        return self::isAdmin();
    }
92608
private function extractPermissions(array $userPermissions = array())
    {
        $permissions = array(
            'configure' => '',
            'read' => '',
            'write' => '',
        );

        if (!empty($userPermissions)) {
            foreach (array_keys($permissions) as $permission) {
                if (!empty($userPermissions[$permission])) {
                    $permissions[$permission] = $userPermissions[$permission];
                }
            }
        }

        return $permissions;
    }
897314
public function syncPermissions($permissions)
    {
        $sync = [];
        $this->mapArray($permissions, function ($permission) use (&$sync) {

            $sync[] = $this->parsePermissionId($permission);

            return $sync;
        });

        return $this->permissions()->sync($sync);
    }
960096
def _get_all_permissions(opts, tools):
    """"""
    perms = []
    for tool in tools:
        perms.append((_get_permission_codename(tool, opts), 'Can %s %s' % \
                (tool.name, opts.verbose_name_plural)))
    return perms
559084
def get_all_permissions(self):
        """"""
        perms = set()
        for role in self.get_user_roles():
            for perm_view in role.permissions:
                t = (perm_view.permission.name, perm_view.view_menu.name)
                perms.add(t)
        return perms
460041
public function permRemoveAny($permid)
  {
    $assignments = $this->permissionFind($permid);

    foreach($assignments as $assignment)
    {
      switch($assignment["t"])
      {
      	case TeamSpeak3::PERM_TYPE_SERVERGROUP:
      		$this->serverGroupPermRemove($assignment["id1"], $assignment["p"]);
      		break;

        case TeamSpeak3::PERM_TYPE_CLIENT:
          $this->clientPermRemove($assignment["id2"], $assignment["p"]);
          break;

        case TeamSpeak3::PERM_TYPE_CHANNEL:
          $this->channelPermRemove($assignment["id2"], $assignment["p"]);
          break;

        case TeamSpeak3::PERM_TYPE_CHANNELGROUP:
          $this->channelGroupPermRemove($assignment["id1"], $assignment["p"]);
          break;

        case TeamSpeak3::PERM_TYPE_CHANNELCLIENT:
          $this->channelClientPermRemove($assignment["id2"], $assignment["id1"], $assignment["p"]);
          break;

      	default:
      	  throw new Exception("convert error", 0x604);
      }
    }

    return count($assignments);
  }
154952
public function createFile($perm) {
		if ($this->isFile()) return false;
		
		IoUtils::touch($this->path);
		IoUtils::chmod($this->path, $perm);

		return true;
	}
364428
protected function _perm($perm, $return)
    {
        if( $perm !== NULL )
        {
            if( Authorization\PermissionExtends::$roleId === NULL )
            {
                throw new Exception\PermissionRoleIdException();
            }

            return Authorization\Process::use($perm, $return);
        }

        return $return;
    }
38226
public function permissionGetNameById($permid)
  {
    foreach($this->permissionList() as $name => $perm)
    {
      if($perm["permid"] == $permid) return new TeamSpeak3_Helper_String($name);
    }

    throw new TeamSpeak3_Adapter_ServerQuery_Exception("invalid permission ID", 0xA02);
  }
730259
public function check($requester, $request, $perms) {
		$permission = $this->_classes['permission'];
		return $permission::check($requester, $request, $perms);
	}
75321
public String[] getUserPermissionList(String userName) {
        if (!m_enabled) {
            return m_perm_list;
        }
        if (userName == null) {
            return new String[] {};
        }
        AuthUser user = getUser(userName);
        if (user == null) {
            return new String[] {};
        }
        return user.m_permissions_list;
    }
903104
public static function compileMode(array $perms)
    {
        $fmode = 0;
        $fmode |= !empty($perms['owner']['read'])    ? self::OWNER_READ    : 0;
        $fmode |= !empty($perms['owner']['write'])   ? self::OWNER_WRITE   : 0;
        $fmode |= !empty($perms['owner']['execute']) ? self::OWNER_EXECUTE : 0;

        $fmode |= !empty($perms['group']['read'])    ? self::GROUP_READ    : 0;
        $fmode |= !empty($perms['group']['write'])   ? self::GROUP_WRITE   : 0;
        $fmode |= !empty($perms['group']['execute']) ? self::GROUP_EXECUTE : 0;

        $fmode |= !empty($perms['world']['read'])    ? self::WORLD_READ    : 0;
        $fmode |= !empty($perms['world']['write'])   ? self::WORLD_WRITE   : 0;
        $fmode |= !empty($perms['world']['execute']) ? self::WORLD_EXECUTE : 0;

        return $fmode;
    }
1265308
static function perms($filename) {

		if (!file_exists($filename)) {
			throw new FileException("Missing: $filename");
		}
		if (!is_writeable($filename)) {
			throw new FileException("Not writable: $filename");
		}

		if (is_dir($filename)) {
			$ok=chmod($filename,0777);
		} else {
			$ok=chmod($filename,0666);
		}

		if (!$ok) {
			throw new FileAccessException("Could not chmod $filename");
		}

		return $ok;
	}
18772
public static function formatPermissions(array $userPermissions): array
    {
        $userPermissions = self::format($userPermissions);

        foreach ($userPermissions as $key => $permission) {
            $userPermissions[$key] = self::$permissions[$key];
        }

        return $userPermissions;
    }