3 namespace Friendica\Util;
5 use Friendica\Model\Group;
8 * Util class for ACL formatting
10 final class ACLFormatter
13 * Turn user/group ACLs stored as angle bracketed text into arrays
15 * @param string $ids A angle-bracketed list of IDs
17 * @return array The array based on the IDs
19 public function expand(string $ids)
21 // turn string array of angle-bracketed elements into numeric array
22 // e.g. "<1><2><3>" => array(1,2,3);
23 preg_match_all('/<(' . Group::FOLLOWERS . '|'. Group::MUTUALS . '|[0-9]+)>/', $ids, $matches, PREG_PATTERN_ORDER);
29 * Wrap ACL elements in angle brackets for storage
31 * @param string $item The item to sanitise
33 private function sanitize(string &$item) {
35 $item = '<' . intval(Strings::escapeTags(trim($item))) . '>';
36 } elseif (in_array($item, [Group::FOLLOWERS, Group::MUTUALS])) {
37 $item = '<' . $item . '>';
44 * Convert an ACL array to a storable string
46 * Normally ACL permissions will be an array.
47 * We'll also allow a comma-separated string.
49 * @param string|array $permissions
53 function toString($permissions) {
55 if (is_array($permissions)) {
58 $item = explode(',', $permissions);
61 if (is_array($item)) {
62 array_walk($item, [$this, 'sanitize']);
63 $return = implode('', $item);