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.'); diff --git a/fbsync/fbsync.php b/fbsync/fbsync.php index 561cabad..b4a191ca 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,56 @@ function fbsync_createcomment($a, $uid, $self_id, $self, $user, $contacts, $appl return; $parent_uri = ""; + $parent_contact = 0; + $parent_nick = ""; // 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: UID ".$uid." - Contact ".$parent_contact." doesn't seem to exist.", LOGGER_DEBUG); + return; + } + + // Is blocked? Then return + if ($r[0]["readonly"] OR $r[0]["blocked"]) { + logger("fbsync_createcomment: UID ".$uid." - Contact '".$r[0]["nick"]."' is blocked or readonly.", LOGGER_DEBUG); + return; + } + + $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(); $postarray['gravity'] = 0; $postarray['uid'] = $uid; @@ -424,8 +456,24 @@ 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 <= 0) + $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) { + $contact_id = $parent_contact; + $contact_nick = $parent_nick; + } + + // This case here should never happen + if ($contact_id <= 0) { $contact_id = $self[0]["id"]; + $contact_nick = $self[0]["nick"]; + } if ($comment->fromid != $self_id) { $postarray['contact-id'] = $contact_id; @@ -437,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']; @@ -460,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; @@ -804,7 +853,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"]; @@ -874,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)) { 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)) {