From 93d5394ffa2b6b43e5e0d982560ebb9f2772d992 Mon Sep 17 00:00:00 2001 From: Michael Vogel Date: Tue, 11 Feb 2014 23:28:23 +0100 Subject: [PATCH 1/5] fbsync: Only import comments when the toplevel poster wasn't ignored --- fbsync/fbsync.php | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/fbsync/fbsync.php b/fbsync/fbsync.php index 561cabad..e7cc53f0 100644 --- a/fbsync/fbsync.php +++ b/fbsync/fbsync.php @@ -424,6 +424,11 @@ function fbsync_createcomment($a, $uid, $self_id, $self, $user, $contacts, $appl $contact_id = fbsync_fetch_contact($uid, $contacts[$comment->fromid], array(), false); + if ($contact_id == -1) { + logger('fbsync_createcomment: Contact was blocked. Comment not imported '.print_r($comment, true), LOGGER_DEBUG); + return; + } + if ($contact_id <= 0) $contact_id = $self[0]["id"]; From def886203329e018e8e1037c0b6db8bfa498433d Mon Sep 17 00:00:00 2001 From: Michael Vogel Date: Tue, 11 Feb 2014 23:29:03 +0100 Subject: [PATCH 2/5] fbpost: Don't queue posts when the posting seems to fail with a specific error --- fbpost/fbpost.php | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/fbpost/fbpost.php b/fbpost/fbpost.php index 7489b17e..e6683282 100644 --- a/fbpost/fbpost.php +++ b/fbpost/fbpost.php @@ -762,12 +762,13 @@ function fbpost_post_hook(&$a,&$b) { intval($b['id']), intval($b['id']) ); - } - else { - // Only add to queue if its a toplevel post. + } else { // Sometimes posts are accepted from facebook although it telling an error // This leads to endless comment flooding. - if(! $likes AND $toplevel) { + + // If it is a special kind of failure the post was receiced + // Although facebook said it wasn't received ... + if (!$likes AND (($retj->error->type != "OAuthException") OR ($retj->error->code != 2))) { $r = q("SELECT `id` FROM `contact` WHERE `uid` = %d AND `self`", intval($b['uid'])); if (count($r)) $a->contact = $r[0]["id"]; @@ -913,10 +914,16 @@ function fbpost_queue_hook(&$a,&$b) { ); logger('fbpost_queue_hook: success: ' . $j); remove_queue_item($x['id']); - } - else { + } else { logger('fbpost_queue_hook: failed: ' . $j); - update_queue_time($x['id']); + + // If it is a special kind of failure the post was receiced + // Although facebook said it wasn't received ... + $ret = json_decode($j); + if (($ret->error->type != "OAuthException") OR ($ret->error->code != 2)) + update_queue_time($x['id']); + else + logger('fbpost_queue_hook: Not requeued, since it seems to be received'); } } else { logger('fbpost_queue_hook: No fb_post or fb_token.'); From 4dd0ea5f89b4c8feb5c2f6d09476c4655f472f26 Mon Sep 17 00:00:00 2001 From: Michael Vogel Date: Tue, 11 Feb 2014 23:30:28 +0100 Subject: [PATCH 3/5] Links now are directed to target="_blank" --- forumdirectory/templates/forumdirectory_item.tpl | 2 +- forumlist/forumlist.php | 2 +- page/page.php | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/forumdirectory/templates/forumdirectory_item.tpl b/forumdirectory/templates/forumdirectory_item.tpl index 66410efe..ee38c28a 100644 --- a/forumdirectory/templates/forumdirectory_item.tpl +++ b/forumdirectory/templates/forumdirectory_item.tpl @@ -32,7 +32,7 @@
{{if $marital}}
{{$marital}}
{{$profile.marital}}
{{/if}} - {{if $homepage}}
{{$homepage}}
{{$profile.homepage}}
{{/if}} + {{if $homepage}}
{{$homepage}}
{{$profile.homepage}}
{{/if}}
diff --git a/forumlist/forumlist.php b/forumlist/forumlist.php index bcc03a51..50fc0a5c 100644 --- a/forumlist/forumlist.php +++ b/forumlist/forumlist.php @@ -74,7 +74,7 @@ function forumlist_network_mod_init($a,$b) { if(count($contacts)) { foreach($contacts as $contact) { - $forumlist .= '
' . $contact['url'] . ' ' . $contact["name"]."
"; + $forumlist .= '
' . $contact['url'] . ' ' . $contact["name"]."
"; } } else { diff --git a/page/page.php b/page/page.php index 86607e81..e1ca9070 100755 --- a/page/page.php +++ b/page/page.php @@ -69,7 +69,7 @@ function page_page_end($a,&$b) { $more = false; foreach($contacts as $contact) { - $page .= '
  • ' . $contact['url'] . ' '. + $page .= '
  • ' . $contact['url'] . ' '. $contact["name"]."
  • "; $total_shown ++; if($total_shown == 6) { @@ -103,7 +103,7 @@ function page_network_mod_init($a,$b) { $more = false; foreach($contacts as $contact) { - $page .= '
  • ' . $contact['url'] . ' '. + $page .= '
  • ' . $contact['url'] . ' '. $contact["name"]."
  • "; $total_shown ++; if(($show_total) && ($total_shown == $show_total)) { From 206f41ecf9925199f115cacda782927d031042b4 Mon Sep 17 00:00:00 2001 From: Michael Vogel Date: Wed, 12 Feb 2014 12:15:25 +0100 Subject: [PATCH 4/5] fbsync: Detection of comments to blocked accounts now really should work ... --- fbsync/fbsync.php | 54 +++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 47 insertions(+), 7 deletions(-) diff --git a/fbsync/fbsync.php b/fbsync/fbsync.php index e7cc53f0..ee83765f 100644 --- a/fbsync/fbsync.php +++ b/fbsync/fbsync.php @@ -248,10 +248,13 @@ function fbsync_createpost($a, $uid, $self, $contacts, $applications, $post, $cr } } - if ($contact_id == 0) { + if ($contact_id <= 0) { $contact_id = fbsync_fetch_contact($uid, $contacts[$post->source_id], $create_user); - if (($contact_id <= 0) AND !$create_user) { + if ($contact_id == -1) { + logger('fbsync_createpost: Contact is blocked. Post not imported '.print_r($post, true), LOGGER_DEBUG); + return; + } elseif (($contact_id <= 0) AND !$create_user) { logger('fbsync_createpost: No matching contact found. Post not imported '.print_r($post, true), LOGGER_DEBUG); return; } elseif ($contact_id == 0) { @@ -388,27 +391,54 @@ function fbsync_createcomment($a, $uid, $self_id, $self, $user, $contacts, $appl return; $parent_uri = ""; + $parent_contact = 0; // Fetch the parent uri (Checking if the parent exists) - $r = q("SELECT `uri` FROM `item` WHERE `uid` = %d AND `uri` = '%s' LIMIT 1", + $r = q("SELECT `uri`, `contact-id` FROM `item` WHERE `uid` = %d AND `uri` = '%s' LIMIT 1", intval($uid), dbesc('fb::'.$comment->post_id) ); - if(count($r)) + if(count($r)) { $parent_uri = $r[0]["uri"]; + $parent_contact = $r[0]["contact-id"]; + } // check if it is a reply to an own post (separate posting for performance reasons) - $r = q("SELECT `uri` FROM `item` WHERE `uid` = %d AND `extid` = '%s' LIMIT 1", + $r = q("SELECT `uri`, `contact-id` FROM `item` WHERE `uid` = %d AND `extid` = '%s' LIMIT 1", intval($uid), dbesc('fb::'.$comment->post_id) ); - if(count($r)) + if(count($r)) { $parent_uri = $r[0]["uri"]; + $parent_contact = $r[0]["contact-id"]; + } // No parent? Then quit if ($parent_uri == "") return; + //logger("fbsync_createcomment: Checking if parent contact is blocked: ".$parent_contact." - ".$parent_uri, LOGGER_DEBUG); + + // Check if the contact id was blocked + if ($parent_contact > 0) { + $r = q("SELECT `blocked`, `readonly`, `nick` FROM `contact` WHERE `uid` = %d AND `id` = %d LIMIT 1", + intval($uid), intval($parent_contact)); + + // Should only happen if someone deleted the contact manually + if(!count($r)) { + logger("fbsync_createcomment: Contact ".$parent_contact." doesn't seem to exist.", LOGGER_DEBUG); + return; + } + + // Is blocked? Then return + if (count($r) AND ($r[0]["readonly"] OR $r[0]["blocked"])) { + logger("fbsync_createcomment: Contact '".$r[0]["nick"]."' is blocked or readonly.", LOGGER_DEBUG); + return; + } + + //logger("fbsync_createcomment: Contact '".$r[0]["nick"]."' isn't blocked.", LOGGER_DEBUG); + } + $postarray = array(); $postarray['gravity'] = 0; $postarray['uid'] = $uid; @@ -429,6 +459,11 @@ function fbsync_createcomment($a, $uid, $self_id, $self, $user, $contacts, $appl return; } + // If no contact was found, take it from the thread owner + if ($contact_id <= 0) + $contact_id = $parent_contact; + + // This case here should never happen if ($contact_id <= 0) $contact_id = $self[0]["id"]; @@ -809,7 +844,12 @@ function fbsync_fetchuser($a, $uid, $id) { intval($uid), dbesc("facebook::".$id)); if (count($contact)) { - $user["contact-id"] = $contact[0]["id"]; + if (($contact[0]["readonly"] OR $contact[0]["blocked"])) { + logger("fbsync_fetchuser: Contact '".$contact[0]["nick"]."' is blocked or readonly.", LOGGER_DEBUG); + $user["contact-id"] = -1; + } else + $user["contact-id"] = $contact[0]["id"]; + $user["name"] = $contact[0]["name"]; $user["link"] = $contact[0]["url"]; $user["avatar"] = $contact[0]["photo"]; From 80f6f22852fa6a7052c524494d3b4c3acdffb0be Mon Sep 17 00:00:00 2001 From: Michael Vogel Date: Thu, 13 Feb 2014 08:32:04 +0100 Subject: [PATCH 5/5] fbsync: Detection of comments to blocked accounts improved --- fbsync/fbsync.php | 25 +++++++++++++++++-------- 1 file changed, 17 insertions(+), 8 deletions(-) diff --git a/fbsync/fbsync.php b/fbsync/fbsync.php index ee83765f..b4a191ca 100644 --- a/fbsync/fbsync.php +++ b/fbsync/fbsync.php @@ -392,6 +392,7 @@ function fbsync_createcomment($a, $uid, $self_id, $self, $user, $contacts, $appl $parent_uri = ""; $parent_contact = 0; + $parent_nick = ""; // Fetch the parent uri (Checking if the parent exists) $r = q("SELECT `uri`, `contact-id` FROM `item` WHERE `uid` = %d AND `uri` = '%s' LIMIT 1", @@ -426,17 +427,18 @@ function fbsync_createcomment($a, $uid, $self_id, $self, $user, $contacts, $appl // Should only happen if someone deleted the contact manually if(!count($r)) { - logger("fbsync_createcomment: Contact ".$parent_contact." doesn't seem to exist.", LOGGER_DEBUG); + logger("fbsync_createcomment: UID ".$uid." - Contact ".$parent_contact." doesn't seem to exist.", LOGGER_DEBUG); return; } // Is blocked? Then return - if (count($r) AND ($r[0]["readonly"] OR $r[0]["blocked"])) { - logger("fbsync_createcomment: Contact '".$r[0]["nick"]."' is blocked or readonly.", LOGGER_DEBUG); + if ($r[0]["readonly"] OR $r[0]["blocked"]) { + logger("fbsync_createcomment: UID ".$uid." - Contact '".$r[0]["nick"]."' is blocked or readonly.", LOGGER_DEBUG); return; } - //logger("fbsync_createcomment: Contact '".$r[0]["nick"]."' isn't blocked.", LOGGER_DEBUG); + $parent_nick = $r[0]["nick"]; + logger("fbsync_createcomment: UID ".$uid." - Contact '".$r[0]["nick"]."' isn't blocked. ".print_r($r, true), LOGGER_DEBUG); } $postarray = array(); @@ -454,18 +456,24 @@ function fbsync_createcomment($a, $uid, $self_id, $self, $user, $contacts, $appl $contact_id = fbsync_fetch_contact($uid, $contacts[$comment->fromid], array(), false); + $contact_nick = $contacts[$comment->fromid]->name; + if ($contact_id == -1) { logger('fbsync_createcomment: Contact was blocked. Comment not imported '.print_r($comment, true), LOGGER_DEBUG); return; } // If no contact was found, take it from the thread owner - if ($contact_id <= 0) + if ($contact_id <= 0) { $contact_id = $parent_contact; + $contact_nick = $parent_nick; + } // This case here should never happen - if ($contact_id <= 0) + if ($contact_id <= 0) { $contact_id = $self[0]["id"]; + $contact_nick = $self[0]["nick"]; + } if ($comment->fromid != $self_id) { $postarray['contact-id'] = $contact_id; @@ -477,6 +485,7 @@ function fbsync_createcomment($a, $uid, $self_id, $self, $user, $contacts, $appl $postarray['owner-name'] = $self[0]["name"]; $postarray['owner-link'] = $self[0]["url"]; $postarray['owner-avatar'] = $self[0]["photo"]; + $contact_nick = $self[0]["nick"]; } $postarray['author-name'] = $postarray['owner-name']; @@ -500,7 +509,7 @@ function fbsync_createcomment($a, $uid, $self_id, $self, $user, $contacts, $appl return; $item = item_store($postarray); - logger('fbsync_createcomment: User '.$self[0]["nick"].' posted comment '.$item, LOGGER_DEBUG); + logger('fbsync_createcomment: UID '.$uid.' - CID '.$postarray['contact-id'].' - Nick '.$contact_nick.' posted comment '.$item, LOGGER_DEBUG); if ($item == 0) return; @@ -919,7 +928,7 @@ function fbsync_fetchfeed($a, $uid) { $url = "https://graph.facebook.com/fql?q=".urlencode(json_encode($fql))."&access_token=".$access_token; $feed = fetch_url($url); - +//file_put_contents("/home/ike/pirati.ca/htdocs/fb.".$uid, $feed); $data = json_decode($feed); if (!is_array($data->data)) {