From f1564b4cff5a584d37b12000f68014df49e683d9 Mon Sep 17 00:00:00 2001 From: redmatrix Date: Sun, 21 Feb 2016 16:49:49 -0800 Subject: retry the move of AccessList to composer format (one or more third-party plugins will likely break as a result) --- include/text.php | 60 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 60 insertions(+) (limited to 'include/text.php') diff --git a/include/text.php b/include/text.php index f6fa1c304..6b074d390 100644 --- a/include/text.php +++ b/include/text.php @@ -2728,3 +2728,63 @@ function item_url_replace($channel,&$item,$old,$new) { // @fixme item['plink'] and item['llink'] } + + +/** + * @brief Used to wrap ACL elements in angle brackets for storage. + * + * @param[in,out] array &$item + */ +function sanitise_acl(&$item) { + if (strlen($item)) + $item = '<' . notags(trim($item)) . '>'; + else + unset($item); +} + +/** + * @brief Convert an ACL array to a storable string. + * + * @param array $p + * @return array + */ +function perms2str($p) { + $ret = ''; + + if (is_array($p)) + $tmp = $p; + else + $tmp = explode(',', $p); + + if (is_array($tmp)) { + array_walk($tmp, 'sanitise_acl'); + $ret = implode('', $tmp); + } + + return $ret; +} + + +/** + * @brief Turn user/group ACLs stored as angle bracketed text into arrays. + * + * turn string array of angle-bracketed elements into string array + * e.g. "<123xyz><246qyo>" => array(123xyz,246qyo,sxo33e); + * + * @param string $s + * @return array + */ +function expand_acl($s) { + $ret = array(); + + if(strlen($s)) { + $t = str_replace('<','',$s); + $a = explode('>',$t); + foreach($a as $aa) { + if($aa) + $ret[] = $aa; + } + } + + return $ret; +} -- cgit v1.2.3