From 7f1a4a3060036dc909e00c180d5e27c7bcf2d3da Mon Sep 17 00:00:00 2001 From: friendica Date: Sat, 1 Dec 2012 22:37:41 -0800 Subject: auto-friending for forums and stuff is almost trivial now. But we will need a page to set the permissions on the "self" abook record. These will be the default permissions for anybody we wish to connect with. --- include/zot.php | 39 ++++++++++++++++++++++++++++----------- 1 file changed, 28 insertions(+), 11 deletions(-) (limited to 'include/zot.php') diff --git a/include/zot.php b/include/zot.php index d098b1350..0aaea7188 100644 --- a/include/zot.php +++ b/include/zot.php @@ -249,41 +249,58 @@ function zot_refresh($them,$channel = null) { } } - $r = q("select * from abook where abook_xchan = '%s' and abook_channel = %d and not (abook_flags & %d) and not ( abook_flags & %d) limit 1", + $r = q("select * from abook where abook_xchan = '%s' and abook_channel = %d and not (abook_flags & %d) limit 1", dbesc($x['hash']), intval($channel['channel_id']), - intval(ABOOK_FLAG_SELF), - intval(ABOOK_FLAG_PENDING) + intval(ABOOK_FLAG_SELF) ); if($r) { $y = q("update abook set abook_their_perms = %d where abook_xchan = '%s' and abook_channel = %d - and not (abook_flags & %d) and not ( abook_flags & %d) limit 1", + and not (abook_flags & %d) limit 1", intval($their_perms), dbesc($x['hash']), intval($channel['channel_id']), - intval(ABOOK_FLAG_SELF), - intval(ABOOK_FLAG_PENDING) + intval(ABOOK_FLAG_SELF) ); if(! $y) logger('abook update failed'); } else { - $y = q("insert into abook ( abook_account, abook_channel, abook_xchan, abook_their_perms, abook_created, abook_updated, abook_flags ) values ( %d, %d, '%s', %d, '%s', '%s', %d )", + $default_perms = 0; + // look for default permissions to apply in return - e.g. auto-friend + $z = q("select * from abook where abook_channel = %d and (abook_flags & %d) limit 1", + intval($channel['channel_id']), + intval(ABOOK_FLAG_SELF) + ); + if($z) + $default_perms = intval($z[0]['my_perms']); + + $y = q("insert into abook ( abook_account, abook_channel, abook_xchan, abook_their_perms, abook_my_perms, abook_created, abook_updated, abook_flags ) values ( %d, %d, '%s', %d, '%s', '%s', %d )", intval($channel['channel_account_id']), intval($channel['channel_id']), dbesc($x['hash']), intval($their_perms), + intval($default_perms), dbesc(datetime_convert()), dbesc(datetime_convert()), - intval(ABOOK_FLAG_BLOCKED|ABOOK_FLAG_IGNORED|ABOOK_FLAG_PENDING) + intval(($default_perms) ? 0 : ABOOK_FLAG_BLOCKED|ABOOK_FLAG_IGNORED|ABOOK_FLAG_PENDING) ); - if($y) + if($y) { logger("New introduction received for {$channel['channel_name']}"); + if($default_perms) { + // send back a permissions update for auto-friend/auto-permissions + $z = q("select * from abook where abook_xchan = '%s' and abook_channel = %d and not (abook_flags & %d) limit 1", + dbesc($x['hash']), + intval($channel['channel_id']), + intval(ABOOK_FLAG_SELF) + ); + if($z) + proc_run('php','include/notifier.php','permissions_update',$z[0]['abook_id']); + } + } } - } - return true; } return false; -- cgit v1.2.3