]> git.mxchange.org Git - friendica.git/commitdiff
Allow special groups in default user permissions
authorHypolite Petovan <hypolite@mrpetovan.com>
Sun, 5 Jan 2020 22:07:33 +0000 (17:07 -0500)
committerHypolite Petovan <hypolite@mrpetovan.com>
Sun, 5 Jan 2020 22:09:14 +0000 (17:09 -0500)
- Use ACLFormatter in ACL::getDefaultUserPermissions
- Remove ACL::fixACL
- Add return value to Contact::pruneUnavailable

src/Core/ACL.php
src/Model/Contact.php
src/Model/Group.php

index a4b4a99190cc47c3851ca94531268eba840004d7..d4148d6ba50a5e3393e566fdf84fd7c7fac2ff22 100644 (file)
@@ -206,11 +206,6 @@ class ACL
                return $o;
        }
 
-       private static function fixACL(&$item)
-       {
-               $item = intval(str_replace(['<', '>'], ['', ''], $item));
-       }
-
        /**
         * Return the default permission of the provided user array
         *
@@ -220,32 +215,13 @@ class ACL
         */
        public static function getDefaultUserPermissions(array $user = null)
        {
-               $matches = [];
-
-               $acl_regex = '/<([0-9]+)>/i';
-
-               preg_match_all($acl_regex, $user['allow_cid'] ?? '', $matches);
-               $allow_cid = $matches[1];
-               preg_match_all($acl_regex, $user['allow_gid'] ?? '', $matches);
-               $allow_gid = $matches[1];
-               preg_match_all($acl_regex, $user['deny_cid'] ?? '', $matches);
-               $deny_cid = $matches[1];
-               preg_match_all($acl_regex, $user['deny_gid'] ?? '', $matches);
-               $deny_gid = $matches[1];
-
-               // Reformats the ACL data so that it is accepted by the JS frontend
-               array_walk($allow_cid, 'self::fixACL');
-               array_walk($allow_gid, 'self::fixACL');
-               array_walk($deny_cid, 'self::fixACL');
-               array_walk($deny_gid, 'self::fixACL');
-
-               Contact::pruneUnavailable($allow_cid);
+               $aclFormatter = DI::aclFormatter();
 
                return [
-                       'allow_cid' => $allow_cid,
-                       'allow_gid' => $allow_gid,
-                       'deny_cid' => $deny_cid,
-                       'deny_gid' => $deny_gid,
+                       'allow_cid' => Contact::pruneUnavailable($aclFormatter->expand($user['allow_cid'] ?? '')),
+                       'allow_gid' => $aclFormatter->expand($user['allow_gid'] ?? ''),
+                       'deny_cid'  => $aclFormatter->expand($user['deny_cid']  ?? ''),
+                       'deny_gid'  => $aclFormatter->expand($user['deny_gid']  ?? ''),
                ];
        }
 
index 10cf4bf34169846991e31b85bb8a7c50947e327a..0540bf7bebd3f812a50be9da135acdbf1284c939 100644 (file)
@@ -2682,26 +2682,23 @@ class Contact
         * Remove the unavailable contact ids from the provided list
         *
         * @param array $contact_ids Contact id list
+        * @return array
         * @throws \Exception
         */
-       public static function pruneUnavailable(array &$contact_ids)
+       public static function pruneUnavailable(array $contact_ids)
        {
                if (empty($contact_ids)) {
-                       return;
-               }
-
-               $str = DBA::escape(implode(',', $contact_ids));
-
-               $stmt = DBA::p("SELECT `id` FROM `contact` WHERE `id` IN ( " . $str . ") AND `blocked` = 0 AND `pending` = 0 AND `archive` = 0");
-
-               $return = [];
-               while($contact = DBA::fetch($stmt)) {
-                       $return[] = $contact['id'];
+                       return [];
                }
 
-               DBA::close($stmt);
+               $contacts = Contact::selectToArray(['id'], [
+                       'id'      => $contact_ids,
+                       'blocked' => false,
+                       'pending' => false,
+                       'archive' => false,
+               ]);
 
-               $contact_ids = $return;
+               return array_column($contacts, 'id');
        }
 
        /**
index c984f0032e6fb7b904f61eedeccc264fd214796c..b87458756a94e14d487a593704a78a4034abcb6b 100644 (file)
@@ -384,7 +384,7 @@ class Group
                DBA::close($stmt);
 
                if ($check_dead) {
-                       Contact::pruneUnavailable($return);
+                       $return = Contact::pruneUnavailable($return);
                }
 
                return $return;