From c26dede97f626b52b7bf8962ed55d1dbda86abe8 Mon Sep 17 00:00:00 2001 From: Hilmar R Date: Sun, 28 Feb 2021 21:06:16 +0100 Subject: get dev --- Zotlabs/Access/AccessList.php | 3 +- Zotlabs/Access/PermissionLimits.php | 15 ++++--- Zotlabs/Access/PermissionRoles.php | 10 ++--- Zotlabs/Access/Permissions.php | 89 +++++++++++++++++++------------------ 4 files changed, 59 insertions(+), 58 deletions(-) (limited to 'Zotlabs/Access') diff --git a/Zotlabs/Access/AccessList.php b/Zotlabs/Access/AccessList.php index 7cf7b5587..af6c4b7a6 100644 --- a/Zotlabs/Access/AccessList.php +++ b/Zotlabs/Access/AccessList.php @@ -54,7 +54,7 @@ class AccessList { * * \e string \b channel_deny_gid => string of denied gids */ function __construct($channel) { - if($channel) { + if ($channel) { $this->allow_cid = $channel['channel_allow_cid']; $this->allow_gid = $channel['channel_allow_gid']; $this->deny_cid = $channel['channel_deny_cid']; @@ -99,7 +99,6 @@ class AccessList { $this->allow_gid = $arr['allow_gid']; $this->deny_cid = $arr['deny_cid']; $this->deny_gid = $arr['deny_gid']; - $this->explicit = $explicit; } diff --git a/Zotlabs/Access/PermissionLimits.php b/Zotlabs/Access/PermissionLimits.php index c11dc95e6..fb5fe6133 100644 --- a/Zotlabs/Access/PermissionLimits.php +++ b/Zotlabs/Access/PermissionLimits.php @@ -2,6 +2,7 @@ namespace Zotlabs\Access; +use App; use Zotlabs\Lib\PConfig; /** @@ -39,10 +40,10 @@ class PermissionLimits { */ static public function Std_Limits() { $limits = []; - $perms = Permissions::Perms(); + $perms = Permissions::Perms(); - foreach($perms as $k => $v) { - if(strstr($k, 'view')) + foreach ($perms as $k => $v) { + if (strstr($k, 'view')) $limits[$k] = PERMS_PUBLIC; else $limits[$k] = PERMS_SPECIFIC; @@ -77,14 +78,14 @@ class PermissionLimits { * * \b array with all permission limits, if $perm is not set */ static public function Get($channel_id, $perm = '') { - if($perm) { + if ($perm) { return intval(PConfig::Get($channel_id, 'perm_limits', $perm)); } PConfig::Load($channel_id); - if(array_key_exists($channel_id, \App::$config) - && array_key_exists('perm_limits', \App::$config[$channel_id])) - return \App::$config[$channel_id]['perm_limits']; + if (array_key_exists($channel_id, App::$config) + && array_key_exists('perm_limits', App::$config[$channel_id])) + return App::$config[$channel_id]['perm_limits']; return false; } diff --git a/Zotlabs/Access/PermissionRoles.php b/Zotlabs/Access/PermissionRoles.php index 82df0c34b..2bcce4eb4 100644 --- a/Zotlabs/Access/PermissionRoles.php +++ b/Zotlabs/Access/PermissionRoles.php @@ -218,13 +218,13 @@ class PermissionRoles { // set permissionlimits for this permission here, for example: // if($perm === 'mynewperm') - // \Zotlabs\Access\PermissionLimits::Set($uid,$perm,1); + // PermissionLimits::Set($uid,$perm,1); if($perm === 'view_wiki') - \Zotlabs\Access\PermissionLimits::Set($uid, $perm, PERMS_PUBLIC); + PermissionLimits::Set($uid, $perm, PERMS_PUBLIC); if($perm === 'write_wiki') - \Zotlabs\Access\PermissionLimits::Set($uid, $perm, PERMS_SPECIFIC); + PermissionLimits::Set($uid, $perm, PERMS_SPECIFIC); // set autoperms here if applicable @@ -262,11 +262,11 @@ class PermissionRoles { case 'view_wiki': set_abconfig($uid,$ab['abook_xchan'],'my_perms',$perm, intval(get_abconfig($uid,$ab['abook_xchan'],'my_perms','view_pages'))); - + break; case 'write_wiki': set_abconfig($uid,$ab['abook_xchan'],'my_perms',$perm, intval(get_abconfig($uid,$ab['abook_xchan'],'my_perms','write_pages'))); - + break; default: break; } diff --git a/Zotlabs/Access/Permissions.php b/Zotlabs/Access/Permissions.php index 35016ed57..df5472cc3 100644 --- a/Zotlabs/Access/Permissions.php +++ b/Zotlabs/Access/Permissions.php @@ -75,7 +75,7 @@ class Permissions { $x = [ 'permissions' => $perms, - 'filter' => $filter + 'filter' => $filter ]; /** * @hooks permissions_list @@ -84,7 +84,7 @@ class Permissions { */ call_hooks('permissions_list', $x); - return($x['permissions']); + return ($x['permissions']); } /** @@ -96,10 +96,10 @@ class Permissions { */ static public function BlockedAnonPerms() { - $res = []; + $res = []; $perms = PermissionLimits::Std_limits(); - foreach($perms as $perm => $limit) { - if($limit != PERMS_PUBLIC) { + foreach ($perms as $perm => $limit) { + if ($limit != PERMS_PUBLIC) { $res[] = $perm; } } @@ -111,7 +111,7 @@ class Permissions { */ call_hooks('write_perms', $x); - return($x['permissions']); + return ($x['permissions']); } /** @@ -120,20 +120,20 @@ class Permissions { * Converts [ 0 => 'view_stream', ... ] * to [ 'view_stream' => 1 ] for any permissions in $arr; * Undeclared permissions which exist in Perms() are added and set to 0. - * + * * @param array $arr * @return array */ static public function FilledPerms($arr) { - if(is_null($arr)) { + if (is_null($arr)) { btlogger('FilledPerms: null'); $arr = []; } $everything = self::Perms(); - $ret = []; - foreach($everything as $k => $v) { - if(in_array($k, $arr)) + $ret = []; + foreach ($everything as $k => $v) { + if (in_array($k, $arr)) $ret[$k] = 1; else $ret[$k] = 0; @@ -155,9 +155,9 @@ class Permissions { */ static public function OPerms($arr) { $ret = []; - if($arr) { - foreach($arr as $k => $v) { - $ret[] = [ 'name' => $k, 'value' => $v ]; + if ($arr) { + foreach ($arr as $k => $v) { + $ret[] = ['name' => $k, 'value' => $v]; } } return $ret; @@ -170,15 +170,16 @@ class Permissions { * @return boolean|array */ static public function FilledAutoperms($channel_id) { - if(! intval(get_pconfig($channel_id,'system','autoperms'))) + if (!intval(get_pconfig($channel_id, 'system', 'autoperms'))) return false; $arr = []; + $r = q("select * from pconfig where uid = %d and cat = 'autoperms'", intval($channel_id) ); - if($r) { - foreach($r as $rr) { + if ($r) { + foreach ($r as $rr) { $arr[$rr['k']] = intval($rr['v']); } } @@ -193,11 +194,11 @@ class Permissions { * @return boolean true if all perms from $p1 exist also in $p2 */ static public function PermsCompare($p1, $p2) { - foreach($p1 as $k => $v) { - if(! array_key_exists($k, $p2)) + foreach ($p1 as $k => $v) { + if (!array_key_exists($k, $p2)) return false; - if($p1[$k] != $p2[$k]) + if ($p1[$k] != $p2[$k]) return false; } @@ -214,18 +215,18 @@ class Permissions { */ static public function connect_perms($channel_id) { - $my_perms = []; - $permcat = null; + $my_perms = []; + $permcat = null; $automatic = 0; // If a default permcat exists, use that - $pc = ((feature_enabled($channel_id,'permcats')) ? get_pconfig($channel_id,'system','default_permcat') : 'default'); - if(! in_array($pc, [ '','default' ])) { - $pcp = new Zlib\Permcat($channel_id); + $pc = ((feature_enabled($channel_id, 'permcats')) ? get_pconfig($channel_id, 'system', 'default_permcat') : 'default'); + if (!in_array($pc, ['', 'default'])) { + $pcp = new Zlib\Permcat($channel_id); $permcat = $pcp->fetch($pc); - if($permcat && $permcat['perms']) { - foreach($permcat['perms'] as $p) { + if ($permcat && $permcat['perms']) { + foreach ($permcat['perms'] as $p) { $my_perms[$p['name']] = $p['value']; } } @@ -235,15 +236,15 @@ class Permissions { // and if there was no permcat or a default permcat, set the perms // from the role - $role = get_pconfig($channel_id,'system','permissions_role'); - if($role) { + $role = get_pconfig($channel_id, 'system', 'permissions_role'); + if ($role) { $xx = PermissionRoles::role_perms($role); - if($xx['perms_auto']) + if ($xx['perms_auto']) $automatic = 1; - if((! $my_perms) && ($xx['perms_connect'])) { + if ((!$my_perms) && ($xx['perms_connect'])) { $default_perms = $xx['perms_connect']; - $my_perms = Permissions::FilledPerms($default_perms); + $my_perms = Permissions::FilledPerms($default_perms); } } @@ -251,11 +252,11 @@ class Permissions { // it is likely a custom permissions role. First see if there are any // automatic permissions. - if(! $my_perms) { + if (!$my_perms) { $m = Permissions::FilledAutoperms($channel_id); - if($m) { + if ($m) { $automatic = 1; - $my_perms = $m; + $my_perms = $m; } } @@ -263,35 +264,35 @@ class Permissions { // custom perms but they are not automatic. They will be stored in abconfig with // the channel's channel_hash (the 'self' connection). - if(! $my_perms) { + if (!$my_perms) { $r = q("select channel_hash from channel where channel_id = %d", intval($channel_id) ); - if($r) { + if ($r) { $x = q("select * from abconfig where chan = %d and xchan = '%s' and cat = 'my_perms'", intval($channel_id), dbesc($r[0]['channel_hash']) ); - if($x) { - foreach($x as $xv) { + if ($x) { + foreach ($x as $xv) { $my_perms[$xv['k']] = intval($xv['v']); } } } } - return ( [ 'perms' => $my_perms, 'automatic' => $automatic ] ); + return (['perms' => $my_perms, 'automatic' => $automatic]); } static public function serialise($p) { $n = []; - if($p) { - foreach($p as $k => $v) { - if(intval($v)) { + if ($p) { + foreach ($p as $k => $v) { + if (intval($v)) { $n[] = $k; } } } - return implode(',',$n); + return implode(',', $n); } } -- cgit v1.2.3