appnet, fbsync, pumpio, statusnet, twitter: Setting the object-type according to the posting

Bugfix for replies from pumpio to pictures.
pull/204/head
Michael Vogel 2014-07-22 00:40:02 +02:00
parent 418ce62d7b
commit c95f70d449
5 changed files with 89 additions and 30 deletions

View File

@ -716,7 +716,8 @@ function appnet_fetchstream($a, $uid) {
'to_email' => $user['email'], 'to_email' => $user['email'],
'uid' => $user['uid'], 'uid' => $user['uid'],
'item' => $postarray, 'item' => $postarray,
'link' => $a->get_baseurl() . '/display/' . $user['nickname'] . '/' . $item, //'link' => $a->get_baseurl() . '/display/' . $user['nickname'] . '/' . $item,
'link' => $a->get_baseurl().'/display/'.get_item_guid($item),
'source_name' => $postarray['author-name'], 'source_name' => $postarray['author-name'],
'source_link' => $postarray['author-link'], 'source_link' => $postarray['author-link'],
'source_photo' => $postarray['author-avatar'], 'source_photo' => $postarray['author-avatar'],
@ -770,7 +771,8 @@ function appnet_fetchstream($a, $uid) {
'to_email' => $user['email'], 'to_email' => $user['email'],
'uid' => $user['uid'], 'uid' => $user['uid'],
'item' => $postarray, 'item' => $postarray,
'link' => $a->get_baseurl() . '/display/' . $user['nickname'] . '/' . $item, //'link' => $a->get_baseurl() . '/display/' . $user['nickname'] . '/' . $item,
'link' => $a->get_baseurl().'/display/'.get_item_guid($item),
'source_name' => $postarray['author-name'], 'source_name' => $postarray['author-name'],
'source_link' => $postarray['author-link'], 'source_link' => $postarray['author-link'],
'source_photo' => $postarray['author-avatar'], 'source_photo' => $postarray['author-avatar'],
@ -867,8 +869,12 @@ function appnet_createpost($a, $uid, $post, $me, $user, $ownid, $createuser, $th
} }
// Don't create accounts of people who just comment something // Don't create accounts of people who just comment something
$createuser = false; $createuser = false;
} else
$postarray['object-type'] = ACTIVITY_OBJ_COMMENT;
} else {
$postarray['thr-parent'] = $postarray['uri']; $postarray['thr-parent'] = $postarray['uri'];
$postarray['object-type'] = ACTIVITY_OBJ_NOTE;
}
$postarray['plink'] = $post["canonical_url"]; $postarray['plink'] = $post["canonical_url"];
@ -953,6 +959,10 @@ function appnet_createpost($a, $uid, $post, $me, $user, $ownid, $createuser, $th
$page_info = "\n[url=".$photo["url"]."][img]".$photo["large"]."[/img][/url]"; $page_info = "\n[url=".$photo["url"]."][img]".$photo["large"]."[/img][/url]";
elseif ($photo["url"] != "") elseif ($photo["url"] != "")
$page_info = "\n[img]".$photo["url"]."[/img]"; $page_info = "\n[img]".$photo["url"]."[/img]";
if ($photo["url"] != "")
$postarray['object-type'] = ACTIVITY_OBJ_IMAGE;
} else } else
$photo = array("url" => "", "large" => ""); $photo = array("url" => "", "large" => "");

View File

@ -229,6 +229,7 @@ function fbsync_createpost($a, $uid, $self, $contacts, $applications, $post, $cr
$postarray['wall'] = 0; $postarray['wall'] = 0;
$postarray['verb'] = ACTIVITY_POST; $postarray['verb'] = ACTIVITY_POST;
$postarray['object-type'] = ACTIVITY_OBJ_NOTE; // default value - is maybe changed later when media is attached
$postarray['network'] = dbesc(NETWORK_FACEBOOK); $postarray['network'] = dbesc(NETWORK_FACEBOOK);
$postarray['uri'] = "fb::".$post->post_id; $postarray['uri'] = "fb::".$post->post_id;
@ -314,6 +315,24 @@ function fbsync_createpost($a, $uid, $self, $contacts, $applications, $post, $cr
$postarray["body"] = $msgdata["body"]; $postarray["body"] = $msgdata["body"];
$postarray["tag"] = $msgdata["tags"]; $postarray["tag"] = $msgdata["tags"];
// Change the object type when an attachment is present
if (isset($post->attachment->fb_object_type))
logger('fb_object_type: '.$post->attachment->fb_object_type." ".print_r($post->attachment, true), LOGGER_DEBUG);
switch ($post->attachment->fb_object_type) {
case 'photo':
$postarray['object-type'] = ACTIVITY_OBJ_IMAGE; // photo is deprecated: http://activitystrea.ms/head/activity-schema.html#image
break;
case 'video':
$postarray['object-type'] = ACTIVITY_OBJ_VIDEO;
break;
case '':
//$postarray['object-type'] = ACTIVITY_OBJ_BOOKMARK;
break;
default:
logger('Unknown object type '.$post->attachment->fb_object_type, LOGGER_DEBUG);
break;
}
$content = ""; $content = "";
$type = ""; $type = "";
@ -328,43 +347,44 @@ function fbsync_createpost($a, $uid, $self, $contacts, $applications, $post, $cr
$content = "[b]" . $post->attachment->name."[/b]"; $content = "[b]" . $post->attachment->name."[/b]";
$quote = ""; $quote = "";
if(isset($post->attachment->description) and ($post->attachment->fb_object_type != "photo")) if (isset($post->attachment->description) and ($post->attachment->fb_object_type != "photo"))
$quote = $post->attachment->description; $quote = $post->attachment->description;
if(isset($post->attachment->caption) and ($post->attachment->fb_object_type == "photo")) if (isset($post->attachment->caption) and ($post->attachment->fb_object_type == "photo"))
$quote = $post->attachment->caption; $quote = $post->attachment->caption;
if ($quote.$post->attachment->href.$content.$postarray["body"] == "") if ($quote.$post->attachment->href.$content.$postarray["body"] == "")
return; return;
if (isset($post->attachment->media) // AND !strstr($post->attachment->href, "://www.youtube.com/") if (isset($post->attachment->media) AND (($type == "") OR ($type == "link"))) {
//AND !strstr($post->attachment->href, "://youtu.be/")
//AND !strstr($post->attachment->href, ".vimeo.com/"))
AND (($type == "") OR ($type == "link"))) {
foreach ($post->attachment->media AS $media) { foreach ($post->attachment->media AS $media) {
//$media->photo->owner = number_format($media->photo->owner, 0, '', '');
//if ($media->photo->owner != '') {
// $postarray['author-name'] = $contacts[$media->photo->owner]->name;
// $postarray['author-link'] = $contacts[$media->photo->owner]->url;
// $postarray['author-avatar'] = $contacts[$media->photo->owner]->pic_square;
//}
if (isset($media->type)) if (isset($media->type))
$type = $media->type; $type = $media->type;
if(isset($media->src) && isset($media->href) AND ($media->src != "") AND ($media->href != "")) if (isset($media->src))
$content .= "\n".'[url='.$media->href.'][img]'.fpost_cleanpicture($media->src).'[/img][/url]'; $preview = $media->src;
if (isset($media->photo))
if (isset($media->photo->images) AND (count($media->photo->images) > 1))
$preview = $media->photo->images[1]->src;
if (isset($media->href) AND ($preview != "") AND ($media->href != ""))
$content .= "\n".'[url='.$media->href.'][img]'.$preview.'[/img][/url]';
else { else {
if (isset($media->src) AND ($media->src != "")) if ($preview != "")
$content .= "\n".'[img]'.fpost_cleanpicture($media->src).'[/img]'; $content .= "\n".'[img]'.$preview.'[/img]';
// if just a link, it may be a wall photo - check // if just a link, it may be a wall photo - check
if(isset($post->link)) if (isset($post->link))
$content .= fbpost_get_photo($media->href); $content .= fbpost_get_photo($media->href);
} }
} }
} }
if ($type == "link")
$postarray["object-type"] = ACTIVITY_OBJ_BOOKMARK;
if ($content) if ($content)
$postarray["body"] .= "\n"; $postarray["body"] .= "\n";
@ -490,6 +510,7 @@ function fbsync_createcomment($a, $uid, $self_id, $self, $user, $contacts, $appl
$postarray['wall'] = 0; $postarray['wall'] = 0;
$postarray['verb'] = ACTIVITY_POST; $postarray['verb'] = ACTIVITY_POST;
$postarray['object-type'] = ACTIVITY_OBJ_COMMENT;
$postarray['network'] = dbesc(NETWORK_FACEBOOK); $postarray['network'] = dbesc(NETWORK_FACEBOOK);
$postarray['uri'] = "fb::".$comment->id; $postarray['uri'] = "fb::".$comment->id;
@ -589,7 +610,8 @@ function fbsync_createcomment($a, $uid, $self_id, $self, $user, $contacts, $appl
'to_email' => $user[0]['email'], 'to_email' => $user[0]['email'],
'uid' => $user[0]['uid'], 'uid' => $user[0]['uid'],
'item' => $postarray, 'item' => $postarray,
'link' => $a->get_baseurl() . '/display/' . $user[0]['nickname'] . '/' . $item, //'link' => $a->get_baseurl() . '/display/' . $user[0]['nickname'] . '/' . $item,
'link' => $a->get_baseurl().'/display/'.get_item_guid($item),
'source_name' => $postarray['author-name'], 'source_name' => $postarray['author-name'],
'source_link' => $postarray['author-link'], 'source_link' => $postarray['author-link'],
'source_photo' => $postarray['author-avatar'], 'source_photo' => $postarray['author-avatar'],
@ -641,8 +663,11 @@ function fbsync_createlike($a, $uid, $self_id, $self, $contacts, $like) {
$likedata = array(); $likedata = array();
$likedata['parent'] = $orig_post['id']; $likedata['parent'] = $orig_post['id'];
$likedata['verb'] = ACTIVITY_LIKE; $likedata['verb'] = ACTIVITY_LIKE;
$likedata['object-type'] = ACTIVITY_OBJ_NOTE;
$likedate['network'] = dbesc(NETWORK_FACEBOOK); $likedate['network'] = dbesc(NETWORK_FACEBOOK);
$likedata['gravity'] = 3; $likedata['gravity'] = 3;
$likedata['uid'] = $uid; $likedata['uid'] = $uid;
$likedata['wall'] = 0; $likedata['wall'] = 0;
@ -976,6 +1001,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("fb.".$uid);
$data = json_decode($feed); $data = json_decode($feed);
if (!is_array($data->data)) { if (!is_array($data->data)) {

View File

@ -472,6 +472,9 @@ function pumpio_send(&$a,&$b) {
$inReplyTo = array("id" => $orig_post["uri"], $inReplyTo = array("id" => $orig_post["uri"],
"objectType" => "note"); "objectType" => "note");
if (($orig_post["object-type"] != "") AND (strstr($orig_post["object-type"], NAMESPACE_ACTIVITY_SCHEMA)))
$inReplyTo["objectType"] = str_replace(NAMESPACE_ACTIVITY_SCHEMA, '', $orig_post["object-type"]);
$params["object"] = array( $params["object"] = array(
'objectType' => "comment", 'objectType' => "comment",
'content' => $title.$content, 'content' => $title.$content,
@ -546,7 +549,9 @@ function pumpio_action(&$a, $uid, $uri, $action, $content) {
else else
$uri = $orig_post["uri"]; $uri = $orig_post["uri"];
if (strstr($uri, "/api/comment/")) if (($orig_post["object-type"] != "") AND (strstr($orig_post["object-type"], NAMESPACE_ACTIVITY_SCHEMA)))
$objectType = str_replace(NAMESPACE_ACTIVITY_SCHEMA, '', $orig_post["object-type"]);
elseif (strstr($uri, "/api/comment/"))
$objectType = "comment"; $objectType = "comment";
elseif (strstr($uri, "/api/note/")) elseif (strstr($uri, "/api/note/"))
$objectType = "note"; $objectType = "note";
@ -865,7 +870,6 @@ function pumpio_dolike(&$a, $uid, $self, $post, $own_id) {
$likedata['parent-uri'] = $orig_post["uri"]; $likedata['parent-uri'] = $orig_post["uri"];
$likedata['contact-id'] = $contactid; $likedata['contact-id'] = $contactid;
$likedata['app'] = $post->generator->displayName; $likedata['app'] = $post->generator->displayName;
$likedata['verb'] = ACTIVITY_LIKE;
$likedata['author-name'] = $post->actor->displayName; $likedata['author-name'] = $post->actor->displayName;
$likedata['author-link'] = $post->actor->url; $likedata['author-link'] = $post->actor->url;
$likedata['author-avatar'] = $post->actor->image->url; $likedata['author-avatar'] = $post->actor->image->url;
@ -1081,6 +1085,7 @@ function pumpio_dopost(&$a, $client, $uid, $self, $post, $own_id, $threadcomplet
$postarray['uid'] = $uid; $postarray['uid'] = $uid;
$postarray['wall'] = 0; $postarray['wall'] = 0;
$postarray['uri'] = $post->object->id; $postarray['uri'] = $post->object->id;
$postarray['object-type'] = NAMESPACE_ACTIVITY_SCHEMA.strtolower($post->object->objectType);
if ($post->object->objectType != "comment") { if ($post->object->objectType != "comment") {
$contact_id = pumpio_get_contact($uid, $post->actor); $contact_id = pumpio_get_contact($uid, $post->actor);
@ -1238,7 +1243,8 @@ function pumpio_dopost(&$a, $client, $uid, $self, $post, $own_id, $threadcomplet
'to_email' => $user[0]['email'], 'to_email' => $user[0]['email'],
'uid' => $user[0]['uid'], 'uid' => $user[0]['uid'],
'item' => $postarray, 'item' => $postarray,
'link' => $a->get_baseurl() . '/display/' . $user[0]['nickname'] . '/' . $top_item, //'link' => $a->get_baseurl() . '/display/' . $user[0]['nickname'] . '/' . $top_item,
'link' => $a->get_baseurl().'/display/'.get_item_guid($top_item),
'source_name' => $postarray['author-name'], 'source_name' => $postarray['author-name'],
'source_link' => $postarray['author-link'], 'source_link' => $postarray['author-link'],
'source_photo' => $postarray['author-avatar'], 'source_photo' => $postarray['author-avatar'],

View File

@ -1078,6 +1078,7 @@ function statusnet_createpost($a, $uid, $post, $self, $create_user, $only_existi
if (count($r)) { if (count($r)) {
$postarray['thr-parent'] = $r[0]["uri"]; $postarray['thr-parent'] = $r[0]["uri"];
$postarray['parent-uri'] = $r[0]["parent-uri"]; $postarray['parent-uri'] = $r[0]["parent-uri"];
$postarray['object-type'] = ACTIVITY_OBJ_COMMENT;
} else { } else {
$r = q("SELECT * FROM `item` WHERE `extid` = '%s' AND `uid` = %d LIMIT 1", $r = q("SELECT * FROM `item` WHERE `extid` = '%s' AND `uid` = %d LIMIT 1",
dbesc($parent), dbesc($parent),
@ -1086,9 +1087,11 @@ function statusnet_createpost($a, $uid, $post, $self, $create_user, $only_existi
if (count($r)) { if (count($r)) {
$postarray['thr-parent'] = $r[0]['uri']; $postarray['thr-parent'] = $r[0]['uri'];
$postarray['parent-uri'] = $r[0]['parent-uri']; $postarray['parent-uri'] = $r[0]['parent-uri'];
$postarray['object-type'] = ACTIVITY_OBJ_COMMENT;
} else { } else {
$postarray['thr-parent'] = $postarray['uri']; $postarray['thr-parent'] = $postarray['uri'];
$postarray['parent-uri'] = $postarray['uri']; $postarray['parent-uri'] = $postarray['uri'];
$postarray['object-type'] = ACTIVITY_OBJ_NOTE;
} }
} }
@ -1110,8 +1113,10 @@ function statusnet_createpost($a, $uid, $post, $self, $create_user, $only_existi
} }
// Don't create accounts of people who just comment something // Don't create accounts of people who just comment something
$create_user = false; $create_user = false;
} else } else {
$postarray['parent-uri'] = $postarray['uri']; $postarray['parent-uri'] = $postarray['uri'];
$postarray['object-type'] = ACTIVITY_OBJ_NOTE;
}
if ($contactid == 0) { if ($contactid == 0) {
$contactid = statusnet_fetch_contact($uid, $post->user, $create_user); $contactid = statusnet_fetch_contact($uid, $post->user, $create_user);
@ -1127,6 +1132,7 @@ function statusnet_createpost($a, $uid, $post, $self, $create_user, $only_existi
$postarray['contact-id'] = $contactid; $postarray['contact-id'] = $contactid;
$postarray['verb'] = ACTIVITY_POST; $postarray['verb'] = ACTIVITY_POST;
$postarray['author-name'] = $postarray['owner-name']; $postarray['author-name'] = $postarray['owner-name'];
$postarray['author-link'] = $postarray['owner-link']; $postarray['author-link'] = $postarray['owner-link'];
$postarray['author-avatar'] = $postarray['owner-avatar']; $postarray['author-avatar'] = $postarray['owner-avatar'];
@ -1231,7 +1237,8 @@ function statusnet_checknotification($a, $uid, $own_url, $top_item, $postarray)
'to_email' => $user[0]['email'], 'to_email' => $user[0]['email'],
'uid' => $user[0]['uid'], 'uid' => $user[0]['uid'],
'item' => $postarray, 'item' => $postarray,
'link' => $a->get_baseurl() . '/display/' . $user[0]['nickname'] . '/' . $top_item, //'link' => $a->get_baseurl() . '/display/' . $user[0]['nickname'] . '/' . $top_item,
'link' => $a->get_baseurl().'/display/'.get_item_guid($top_item),
'source_name' => $postarray['author-name'], 'source_name' => $postarray['author-name'],
'source_link' => $postarray['author-link'], 'source_link' => $postarray['author-link'],
'source_photo' => $postarray['author-avatar'], 'source_photo' => $postarray['author-avatar'],
@ -1412,7 +1419,8 @@ function statusnet_fetchhometimeline($a, $uid) {
'to_email' => $u[0]['email'], 'to_email' => $u[0]['email'],
'uid' => $u[0]['uid'], 'uid' => $u[0]['uid'],
'item' => $postarray, 'item' => $postarray,
'link' => $a->get_baseurl() . '/display/' . $u[0]['nickname'] . '/' . $item, //'link' => $a->get_baseurl() . '/display/' . $u[0]['nickname'] . '/' . $item,
'link' => $a->get_baseurl().'/display/'.get_item_guid($item),
'source_name' => $postarray['author-name'], 'source_name' => $postarray['author-name'],
'source_link' => $postarray['author-link'], 'source_link' => $postarray['author-link'],
'source_photo' => $postarray['author-avatar'], 'source_photo' => $postarray['author-avatar'],

View File

@ -1243,6 +1243,7 @@ function twitter_createpost($a, $uid, $post, $self, $create_user, $only_existing
if (count($r)) { if (count($r)) {
$postarray['thr-parent'] = $r[0]["uri"]; $postarray['thr-parent'] = $r[0]["uri"];
$postarray['parent-uri'] = $r[0]["parent-uri"]; $postarray['parent-uri'] = $r[0]["parent-uri"];
$postarray['object-type'] = ACTIVITY_OBJ_COMMENT;
} else { } else {
$r = q("SELECT * FROM `item` WHERE `extid` = '%s' AND `uid` = %d LIMIT 1", $r = q("SELECT * FROM `item` WHERE `extid` = '%s' AND `uid` = %d LIMIT 1",
dbesc($parent), dbesc($parent),
@ -1251,9 +1252,11 @@ function twitter_createpost($a, $uid, $post, $self, $create_user, $only_existing
if (count($r)) { if (count($r)) {
$postarray['thr-parent'] = $r[0]['uri']; $postarray['thr-parent'] = $r[0]['uri'];
$postarray['parent-uri'] = $r[0]['parent-uri']; $postarray['parent-uri'] = $r[0]['parent-uri'];
$postarray['object-type'] = ACTIVITY_OBJ_COMMENT;
} else { } else {
$postarray['thr-parent'] = $postarray['uri']; $postarray['thr-parent'] = $postarray['uri'];
$postarray['parent-uri'] = $postarray['uri']; $postarray['parent-uri'] = $postarray['uri'];
$postarray['object-type'] = ACTIVITY_OBJ_NOTE;
} }
} }
@ -1275,8 +1278,10 @@ function twitter_createpost($a, $uid, $post, $self, $create_user, $only_existing
} }
// Don't create accounts of people who just comment something // Don't create accounts of people who just comment something
$create_user = false; $create_user = false;
} else } else {
$postarray['parent-uri'] = $postarray['uri']; $postarray['parent-uri'] = $postarray['uri'];
$postarray['object-type'] = ACTIVITY_OBJ_NOTE;
}
if ($contactid == 0) { if ($contactid == 0) {
$contactid = twitter_fetch_contact($uid, $post->user, $create_user); $contactid = twitter_fetch_contact($uid, $post->user, $create_user);
@ -1317,6 +1322,7 @@ function twitter_createpost($a, $uid, $post, $self, $create_user, $only_existing
//$postarray['body'] = str_replace($media->url, "\n\n[img]".$media->media_url_https."[/img]\n", $postarray['body']); //$postarray['body'] = str_replace($media->url, "\n\n[img]".$media->media_url_https."[/img]\n", $postarray['body']);
//$has_picture = true; //$has_picture = true;
$postarray['body'] = str_replace($media->url, "", $postarray['body']); $postarray['body'] = str_replace($media->url, "", $postarray['body']);
$postarray['object-type'] = ACTIVITY_OBJ_IMAGE;
$picture = $media->media_url_https; $picture = $media->media_url_https;
break; break;
default: default:
@ -1358,6 +1364,7 @@ function twitter_createpost($a, $uid, $post, $self, $create_user, $only_existing
//$postarray['body'] = str_replace($media->url, "\n\n[img]".$media->media_url_https."[/img]\n", $postarray['body']); //$postarray['body'] = str_replace($media->url, "\n\n[img]".$media->media_url_https."[/img]\n", $postarray['body']);
//$has_picture = true; //$has_picture = true;
$postarray['body'] = str_replace($media->url, "", $postarray['body']); $postarray['body'] = str_replace($media->url, "", $postarray['body']);
$postarray['object-type'] = ACTIVITY_OBJ_IMAGE;
$picture = $media->media_url_https; $picture = $media->media_url_https;
break; break;
default: default:
@ -1445,7 +1452,8 @@ function twitter_checknotification($a, $uid, $own_id, $top_item, $postarray) {
'to_email' => $user[0]['email'], 'to_email' => $user[0]['email'],
'uid' => $user[0]['uid'], 'uid' => $user[0]['uid'],
'item' => $postarray, 'item' => $postarray,
'link' => $a->get_baseurl() . '/display/' . $user[0]['nickname'] . '/' . $top_item, //'link' => $a->get_baseurl() . '/display/' . $user[0]['nickname'] . '/' . $top_item,
'link' => $a->get_baseurl().'/display/'.get_item_guid($top_item),
'source_name' => $postarray['author-name'], 'source_name' => $postarray['author-name'],
'source_link' => $postarray['author-link'], 'source_link' => $postarray['author-link'],
'source_photo' => $postarray['author-avatar'], 'source_photo' => $postarray['author-avatar'],
@ -1606,7 +1614,8 @@ function twitter_fetchhometimeline($a, $uid) {
'to_email' => $u[0]['email'], 'to_email' => $u[0]['email'],
'uid' => $u[0]['uid'], 'uid' => $u[0]['uid'],
'item' => $postarray, 'item' => $postarray,
'link' => $a->get_baseurl() . '/display/' . $u[0]['nickname'] . '/' . $item, //'link' => $a->get_baseurl() . '/display/' . $u[0]['nickname'] . '/' . $item,
'link' => $a->get_baseurl().'/display/'.get_item_guid($item),
'source_name' => $postarray['author-name'], 'source_name' => $postarray['author-name'],
'source_link' => $postarray['author-link'], 'source_link' => $postarray['author-link'],
'source_photo' => $postarray['author-avatar'], 'source_photo' => $postarray['author-avatar'],