]> git.mxchange.org Git - friendica.git/commitdiff
bug #62 - opt-out of importing FB friends/conversations but still allow FB posting
authorFriendika <info@friendika.com>
Mon, 30 May 2011 03:36:45 +0000 (20:36 -0700)
committerFriendika <info@friendika.com>
Mon, 30 May 2011 03:36:45 +0000 (20:36 -0700)
addon/facebook/facebook.php

index cd1ae4aa33d980c8162534e7c1a1b0fd9a3d4589..b1ba6342ad4f5c1bf7814c8d9b97d3cee5d4b8e4 100644 (file)
@@ -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 .= '<input type="checkbox" name="post_by_default" value="1"' . $checked . '/>' . ' ' . t('Post to Facebook by default') . '<br />';
+
+               $no_linking = get_pconfig(local_user(),'facebook','no_linking');
+               $checked = (($no_linking) ? '' : ' checked="checked" ');
+               $o .= '<input type="checkbox" name="facebook_linking" value="1"' . $checked . '/>' . ' ' . t('Link all your Facebook friends and conversations') . '<br />';
+
+
+
                $o .= '<input type="submit" name="submit" value="' . t('Submit') . '" /></form></div>';
        }
 
@@ -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)
        );