From c3478a1485334e9a399fe0786af54d63bb666a60 Mon Sep 17 00:00:00 2001 From: Friendika Date: Sun, 29 May 2011 20:36:45 -0700 Subject: [PATCH] bug #62 - opt-out of importing FB friends/conversations but still allow FB posting --- addon/facebook/facebook.php | 50 +++++++++++++++++++++++++++++++++++-- 1 file changed, 48 insertions(+), 2 deletions(-) diff --git a/addon/facebook/facebook.php b/addon/facebook/facebook.php index cd1ae4aa33..b1ba6342ad 100644 --- a/addon/facebook/facebook.php +++ b/addon/facebook/facebook.php @@ -112,6 +112,11 @@ function fb_get_self($uid) { function fb_get_friends($uid) { $access_token = get_pconfig($uid,'facebook','access_token'); + + $no_linking = get_pconfig($uid,'facebook','no_linking'); + if($no_linking) + return; + if(! $access_token) return; $s = fetch_url('https://graph.facebook.com/me/friends?access_token=' . $access_token); @@ -229,10 +234,40 @@ function fb_get_friends($uid) { function facebook_post(&$a) { - if(local_user()){ + $uid = local_user(); + if($uid){ + $value = ((x($_POST,'post_by_default')) ? intval($_POST['post_by_default']) : 0); - set_pconfig(local_user(),'facebook','post_by_default', $value); + set_pconfig($uid,'facebook','post_by_default', $value); + + $no_linking = get_pconfig($uid,'facebook','no_linking'); + + $linkvalue = ((x($_POST,'facebook_linking')) ? intval($_POST['facebook_linking']) : 0); + set_pconfig($uid,'facebook','no_linking', (($linkvalue) ? 0 : 1)); + + // FB linkage was allowed but has just been turned off - remove all FB contacts and posts + + if((! intval($no_linking)) && (! intval($linkvalue))) { + $r = q("SELECT `id` FROM `contact` WHERE `uid` = %d AND `network` = '%s' ", + intval($uid), + dbesc(NETWORK_FACEBOOK) + ); + if(count($r)) { + require_once('include/Contact.php'); + foreach($r as $rr) + contact_remove($rr['id']); + } + } + elseif(intval($no_linking) && intval($linkvalue)) { + // FB linkage is now allowed - import stuff. + fb_get_self($uid); + fb_get_friends($uid); + fb_consume_all($uid); + } + + info( t('Settings updated.') . EOL); } + return; } @@ -286,6 +321,13 @@ function facebook_content(&$a) { $post_by_default = get_pconfig(local_user(),'facebook','post_by_default'); $checked = (($post_by_default) ? ' checked="checked" ' : ''); $o .= '' . ' ' . t('Post to Facebook by default') . '
'; + + $no_linking = get_pconfig(local_user(),'facebook','no_linking'); + $checked = (($no_linking) ? '' : ' checked="checked" '); + $o .= '' . ' ' . t('Link all your Facebook friends and conversations') . '
'; + + + $o .= ''; } @@ -626,6 +668,10 @@ function fb_consume_all($uid) { function fb_consume_stream($uid,$j,$wall = false) { $a = get_app(); + $no_linking = get_pconfig($uid,'facebook','no_linking'); + if($no_linking) + return; + $self = q("SELECT * FROM `contact` WHERE `self` = 1 AND `uid` = %d LIMIT 1", intval($uid) );