X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=src%2FModel%2FPermissionSet.php;h=6506c70940529859de991fa0f97da487f38eb6f3;hb=00bf0c24b6cc4a4a1ee88e180eeae01386b414b0;hp=2b34f1e32ac36974045a657bb4afbebbcdead2dc;hpb=ecea7425f8ad11ace4af39d476919e3203bff44f;p=friendica.git diff --git a/src/Model/PermissionSet.php b/src/Model/PermissionSet.php index 2b34f1e32a..6506c70940 100644 --- a/src/Model/PermissionSet.php +++ b/src/Model/PermissionSet.php @@ -20,7 +20,7 @@ class PermissionSet extends BaseObject * @param array $postarray The array from an item, picture or event post * @return id */ - public static function fetchIDForPost($postarray) + public static function fetchIDForPost(&$postarray) { $condition = ['uid' => $postarray['uid'], 'allow_cid' => self::sortPermissions(defaults($postarray, 'allow_cid', '')), @@ -35,6 +35,12 @@ class PermissionSet extends BaseObject $set = DBA::selectFirst('permissionset', ['id'], $condition); } + + $postarray['allow_cid'] = null; + $postarray['allow_gid'] = null; + $postarray['deny_cid'] = null; + $postarray['deny_gid'] = null; + return $set['id']; } @@ -56,4 +62,47 @@ class PermissionSet extends BaseObject return '<' . implode('><', $elements) . '>'; } + + /** + * @brief Returns a permission set for a given contact + * + * @param integer $uid User id whom the items belong + * @param integer $contact_id Contact id of the visitor + * @param array $groups Possibly previously fetched group ids for that contact + * + * @return array of permission set ids. + */ + + static public function get($uid, $contact_id, $groups = null) + { + if (empty($groups) && DBA::exists('contact', ['id' => $contact_id, 'uid' => $uid, 'blocked' => false])) { + $groups = Group::getIdsByContactId($contact_id); + } + + if (empty($groups) || !is_array($groups)) { + return []; + } + $group_str = '<<>>'; // should be impossible to match + + foreach ($groups as $g) { + $group_str .= '|<' . intval($g) . '>'; + } + + $contact_str = '<' . $contact_id . '>'; + + $condition = ["`uid` = ? AND (`allow_cid` = '' OR`allow_cid` REGEXP ?) + AND (`deny_cid` = '' OR NOT `deny_cid` REGEXP ?) + AND (`allow_gid` = '' OR `allow_gid` REGEXP ?) + AND (`deny_gid` = '' OR NOT `deny_gid` REGEXP ?)", + $uid, $contact_str, $contact_str, $group_str, $group_str]; + + $ret = DBA::select('permissionset', ['id'], $condition); + $set = []; + while ($permission = DBA::fetch($ret)) { + $set[] = $permission['id']; + } + DBA::close($ret); + + return $set; + } }