forked from friendica/friendica-addons
Merge pull request #183 from annando/master
Improvements in fbsync/fbpost, target for urls set to "_blank"
This commit is contained in:
commit
59b39dde2e
|
@ -762,12 +762,13 @@ function fbpost_post_hook(&$a,&$b) {
|
||||||
intval($b['id']),
|
intval($b['id']),
|
||||||
intval($b['id'])
|
intval($b['id'])
|
||||||
);
|
);
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
// Only add to queue if its a toplevel post.
|
|
||||||
// Sometimes posts are accepted from facebook although it telling an error
|
// Sometimes posts are accepted from facebook although it telling an error
|
||||||
// This leads to endless comment flooding.
|
// 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']));
|
$r = q("SELECT `id` FROM `contact` WHERE `uid` = %d AND `self`", intval($b['uid']));
|
||||||
if (count($r))
|
if (count($r))
|
||||||
$a->contact = $r[0]["id"];
|
$a->contact = $r[0]["id"];
|
||||||
|
@ -913,10 +914,16 @@ function fbpost_queue_hook(&$a,&$b) {
|
||||||
);
|
);
|
||||||
logger('fbpost_queue_hook: success: ' . $j);
|
logger('fbpost_queue_hook: success: ' . $j);
|
||||||
remove_queue_item($x['id']);
|
remove_queue_item($x['id']);
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
logger('fbpost_queue_hook: failed: ' . $j);
|
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 {
|
} else {
|
||||||
logger('fbpost_queue_hook: No fb_post or fb_token.');
|
logger('fbpost_queue_hook: No fb_post or fb_token.');
|
||||||
|
|
|
@ -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);
|
$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);
|
logger('fbsync_createpost: No matching contact found. Post not imported '.print_r($post, true), LOGGER_DEBUG);
|
||||||
return;
|
return;
|
||||||
} elseif ($contact_id == 0) {
|
} elseif ($contact_id == 0) {
|
||||||
|
@ -388,27 +391,56 @@ function fbsync_createcomment($a, $uid, $self_id, $self, $user, $contacts, $appl
|
||||||
return;
|
return;
|
||||||
|
|
||||||
$parent_uri = "";
|
$parent_uri = "";
|
||||||
|
$parent_contact = 0;
|
||||||
|
$parent_nick = "";
|
||||||
|
|
||||||
// Fetch the parent uri (Checking if the parent exists)
|
// 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),
|
intval($uid),
|
||||||
dbesc('fb::'.$comment->post_id)
|
dbesc('fb::'.$comment->post_id)
|
||||||
);
|
);
|
||||||
if(count($r))
|
if(count($r)) {
|
||||||
$parent_uri = $r[0]["uri"];
|
$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)
|
// 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),
|
intval($uid),
|
||||||
dbesc('fb::'.$comment->post_id)
|
dbesc('fb::'.$comment->post_id)
|
||||||
);
|
);
|
||||||
if(count($r))
|
if(count($r)) {
|
||||||
$parent_uri = $r[0]["uri"];
|
$parent_uri = $r[0]["uri"];
|
||||||
|
$parent_contact = $r[0]["contact-id"];
|
||||||
|
}
|
||||||
|
|
||||||
// No parent? Then quit
|
// No parent? Then quit
|
||||||
if ($parent_uri == "")
|
if ($parent_uri == "")
|
||||||
return;
|
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 = array();
|
||||||
$postarray['gravity'] = 0;
|
$postarray['gravity'] = 0;
|
||||||
$postarray['uid'] = $uid;
|
$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);
|
$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_id = $self[0]["id"];
|
||||||
|
$contact_nick = $self[0]["nick"];
|
||||||
|
}
|
||||||
|
|
||||||
if ($comment->fromid != $self_id) {
|
if ($comment->fromid != $self_id) {
|
||||||
$postarray['contact-id'] = $contact_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-name'] = $self[0]["name"];
|
||||||
$postarray['owner-link'] = $self[0]["url"];
|
$postarray['owner-link'] = $self[0]["url"];
|
||||||
$postarray['owner-avatar'] = $self[0]["photo"];
|
$postarray['owner-avatar'] = $self[0]["photo"];
|
||||||
|
$contact_nick = $self[0]["nick"];
|
||||||
}
|
}
|
||||||
|
|
||||||
$postarray['author-name'] = $postarray['owner-name'];
|
$postarray['author-name'] = $postarray['owner-name'];
|
||||||
|
@ -460,7 +509,7 @@ function fbsync_createcomment($a, $uid, $self_id, $self, $user, $contacts, $appl
|
||||||
return;
|
return;
|
||||||
|
|
||||||
$item = item_store($postarray);
|
$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)
|
if ($item == 0)
|
||||||
return;
|
return;
|
||||||
|
@ -804,7 +853,12 @@ function fbsync_fetchuser($a, $uid, $id) {
|
||||||
intval($uid), dbesc("facebook::".$id));
|
intval($uid), dbesc("facebook::".$id));
|
||||||
|
|
||||||
if (count($contact)) {
|
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["name"] = $contact[0]["name"];
|
||||||
$user["link"] = $contact[0]["url"];
|
$user["link"] = $contact[0]["url"];
|
||||||
$user["avatar"] = $contact[0]["photo"];
|
$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;
|
$url = "https://graph.facebook.com/fql?q=".urlencode(json_encode($fql))."&access_token=".$access_token;
|
||||||
|
|
||||||
$feed = fetch_url($url);
|
$feed = fetch_url($url);
|
||||||
|
//file_put_contents("/home/ike/pirati.ca/htdocs/fb.".$uid, $feed);
|
||||||
$data = json_decode($feed);
|
$data = json_decode($feed);
|
||||||
|
|
||||||
if (!is_array($data->data)) {
|
if (!is_array($data->data)) {
|
||||||
|
|
|
@ -32,7 +32,7 @@
|
||||||
<div class="forumdirectory-detailscolumn-wrapper" id="forumdirectory-detailscolumn2-wrapper-{{$id}}">
|
<div class="forumdirectory-detailscolumn-wrapper" id="forumdirectory-detailscolumn2-wrapper-{{$id}}">
|
||||||
{{if $marital}}<dl class="marital"><dt class="marital-label"><span class="heart">♥</span>{{$marital}}</dt><dd class="marital-text">{{$profile.marital}}</dd></dl>{{/if}}
|
{{if $marital}}<dl class="marital"><dt class="marital-label"><span class="heart">♥</span>{{$marital}}</dt><dd class="marital-text">{{$profile.marital}}</dd></dl>{{/if}}
|
||||||
|
|
||||||
{{if $homepage}}<dl class="homepage"><dt class="homepage-label">{{$homepage}}</dt><dd class="homepage-url"><a href="{{$profile.homepage}}" target="external-link">{{$profile.homepage}}</a></dd></dl>{{/if}}
|
{{if $homepage}}<dl class="homepage"><dt class="homepage-label">{{$homepage}}</dt><dd class="homepage-url"><a href="{{$profile.homepage}}" target="_blank">{{$profile.homepage}}</a></dd></dl>{{/if}}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="forumdirectory-copy-wrapper" id="forumdirectory-copy-wrapper-{{$id}}" >
|
<div class="forumdirectory-copy-wrapper" id="forumdirectory-copy-wrapper-{{$id}}" >
|
||||||
|
|
|
@ -74,7 +74,7 @@ function forumlist_network_mod_init($a,$b) {
|
||||||
|
|
||||||
if(count($contacts)) {
|
if(count($contacts)) {
|
||||||
foreach($contacts as $contact) {
|
foreach($contacts as $contact) {
|
||||||
$forumlist .= '<div><a href="' . $a->get_baseurl() . '/redir/' . $contact["id"] . '" title="' . $contact['url'] . '" class="label sparkle" target="external-link"><img class="forumlist-img" height="20" width="20" src="' . $contact['micro'] .'" alt="' . $contact['url'] . '" /></a> <a href="' . $a->get_baseurl() . '/network?f=&cid=' . $contact['id'] . '" >' . $contact["name"]."</a></div>";
|
$forumlist .= '<div><a href="' . $a->get_baseurl() . '/redir/' . $contact["id"] . '" title="' . $contact['url'] . '" class="label sparkle" target="_blank"><img class="forumlist-img" height="20" width="20" src="' . $contact['micro'] .'" alt="' . $contact['url'] . '" /></a> <a href="' . $a->get_baseurl() . '/network?f=&cid=' . $contact['id'] . '" >' . $contact["name"]."</a></div>";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
|
|
@ -69,7 +69,7 @@ function page_page_end($a,&$b) {
|
||||||
$more = false;
|
$more = false;
|
||||||
|
|
||||||
foreach($contacts as $contact) {
|
foreach($contacts as $contact) {
|
||||||
$page .= '<li style="list-style-type: none;" class="tool"><img height="20" width="20" src="' . $contact['micro'] .'" alt="' . $contact['url'] . '" /> <a href="'.$a->get_baseurl().'/redir/'.$contact["id"].'" title="' . $contact['url'] . '" class="label sparkle" target="external-link">'.
|
$page .= '<li style="list-style-type: none;" class="tool"><img height="20" width="20" src="' . $contact['micro'] .'" alt="' . $contact['url'] . '" /> <a href="'.$a->get_baseurl().'/redir/'.$contact["id"].'" title="' . $contact['url'] . '" class="label sparkle" target="_blank">'.
|
||||||
$contact["name"]."</a></li>";
|
$contact["name"]."</a></li>";
|
||||||
$total_shown ++;
|
$total_shown ++;
|
||||||
if($total_shown == 6) {
|
if($total_shown == 6) {
|
||||||
|
@ -103,7 +103,7 @@ function page_network_mod_init($a,$b) {
|
||||||
$more = false;
|
$more = false;
|
||||||
|
|
||||||
foreach($contacts as $contact) {
|
foreach($contacts as $contact) {
|
||||||
$page .= '<li style="list-style-type: none;" class="tool"><img height="20" width="20" src="' . $contact['micro'] .'" alt="' . $contact['url'] . '" /> <a href="'.$a->get_baseurl().'/redir/'.$contact["id"].'" title="' . $contact['url'] . '" class="label sparkle" target="external-link">'.
|
$page .= '<li style="list-style-type: none;" class="tool"><img height="20" width="20" src="' . $contact['micro'] .'" alt="' . $contact['url'] . '" /> <a href="'.$a->get_baseurl().'/redir/'.$contact["id"].'" title="' . $contact['url'] . '" class="label sparkle" target="_blank">'.
|
||||||
$contact["name"]."</a></li>";
|
$contact["name"]."</a></li>";
|
||||||
$total_shown ++;
|
$total_shown ++;
|
||||||
if(($show_total) && ($total_shown == $show_total)) {
|
if(($show_total) && ($total_shown == $show_total)) {
|
||||||
|
|
Loading…
Reference in a new issue