From 6b36863dd81ffd067701da2256d6e8e836764e78 Mon Sep 17 00:00:00 2001 From: friendica Date: Thu, 13 Dec 2012 21:02:14 -0800 Subject: [PATCH] prune all dead/blocked contacts from allowed permissions, ok to keep them in "deny" lists - Contacts will be pruned when creating the editor. They can't be added with the ACL selector, but we won't prevent them from being added through other means. Allowed groups will be pruned on item submit. --- include/acl_selectors.php | 25 +++++++++++++++++++++++++ include/group.php | 6 +++++- include/notifier.php | 2 +- 3 files changed, 31 insertions(+), 2 deletions(-) diff --git a/include/acl_selectors.php b/include/acl_selectors.php index 461ad0c36..675339559 100644 --- a/include/acl_selectors.php +++ b/include/acl_selectors.php @@ -227,6 +227,23 @@ function fixacl(&$item) { $item = intval(str_replace(array('<','>'),array('',''),$item)); } +function prune_deadguys($arr) { + + if(! $arr) + return $arr; + $str = dbesc(implode(',',$arr)); + $r = q("select id from contact where id in ( " . $str . ") and blocked = 0 and pending = 0 and archive = 0 "); + if($r) { + $ret = array(); + foreach($r as $rr) + $ret[] = $rr['id']; + return $ret; + } + return array(); +} + + + function populate_acl($user = null,$celeb = false) { $allow_cid = $allow_gid = $deny_cid = $deny_gid = false; @@ -246,6 +263,14 @@ function populate_acl($user = null,$celeb = false) { array_walk($deny_gid,'fixacl'); } + $allow_cid = prune_deadguys($allow_cid); + + // We shouldn't need to prune deadguys from the block list. Either way they can't get the message. + // Also no point enumerating groups and checking them, that will take place on delivery. + +// $deny_cid = prune_deadguys($deny_cid); + + /*$o = ''; $o .= '
'; $o .= '
'; diff --git a/include/group.php b/include/group.php index 7ede242c0..aa226688a 100644 --- a/include/group.php +++ b/include/group.php @@ -279,7 +279,7 @@ function group_side($every="contacts",$each="group",$edit = false, $group_id = 0 return $o; } -function expand_groups($a) { +function expand_groups($a,$check_dead = false) { if(! (is_array($a) && count($a))) return array(); $groups = implode(',', $a); @@ -289,6 +289,10 @@ function expand_groups($a) { if(count($r)) foreach($r as $rr) $ret[] = $rr['contact-id']; + if($check_dead) { + require_once('include/acl_selectors.php'); + $ret = prune_deadguys($ret); + } return $ret; } diff --git a/include/notifier.php b/include/notifier.php index 091d09b56..3398254b6 100644 --- a/include/notifier.php +++ b/include/notifier.php @@ -309,7 +309,7 @@ function notifier_run(&$argv, &$argc){ } $allow_people = expand_acl($parent['allow_cid']); - $allow_groups = expand_groups(expand_acl($parent['allow_gid'])); + $allow_groups = expand_groups(expand_acl($parent['allow_gid']),true); $deny_people = expand_acl($parent['deny_cid']); $deny_groups = expand_groups(expand_acl($parent['deny_gid']));