From c95f70d449505febbac05c181c13a98b9f210539 Mon Sep 17 00:00:00 2001 From: Michael Vogel Date: Tue, 22 Jul 2014 00:40:02 +0200 Subject: [PATCH] appnet, fbsync, pumpio, statusnet, twitter: Setting the object-type according to the posting Bugfix for replies from pumpio to pictures. --- appnet/appnet.php | 16 +++++++++-- fbsync/fbsync.php | 62 +++++++++++++++++++++++++++++------------ pumpio/pumpio.php | 12 ++++++-- statusnet/statusnet.php | 14 ++++++++-- twitter/twitter.php | 15 ++++++++-- 5 files changed, 89 insertions(+), 30 deletions(-) diff --git a/appnet/appnet.php b/appnet/appnet.php index 9b04ca06..b74e29ff 100644 --- a/appnet/appnet.php +++ b/appnet/appnet.php @@ -716,7 +716,8 @@ function appnet_fetchstream($a, $uid) { 'to_email' => $user['email'], 'uid' => $user['uid'], '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_link' => $postarray['author-link'], 'source_photo' => $postarray['author-avatar'], @@ -770,7 +771,8 @@ function appnet_fetchstream($a, $uid) { 'to_email' => $user['email'], 'uid' => $user['uid'], '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_link' => $postarray['author-link'], '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 $createuser = false; - } else + + $postarray['object-type'] = ACTIVITY_OBJ_COMMENT; + } else { $postarray['thr-parent'] = $postarray['uri']; + $postarray['object-type'] = ACTIVITY_OBJ_NOTE; + } $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]"; elseif ($photo["url"] != "") $page_info = "\n[img]".$photo["url"]."[/img]"; + + if ($photo["url"] != "") + $postarray['object-type'] = ACTIVITY_OBJ_IMAGE; + } else $photo = array("url" => "", "large" => ""); diff --git a/fbsync/fbsync.php b/fbsync/fbsync.php index 9abac7dc..509426d9 100644 --- a/fbsync/fbsync.php +++ b/fbsync/fbsync.php @@ -229,6 +229,7 @@ function fbsync_createpost($a, $uid, $self, $contacts, $applications, $post, $cr $postarray['wall'] = 0; $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['uri'] = "fb::".$post->post_id; @@ -314,6 +315,24 @@ function fbsync_createpost($a, $uid, $self, $contacts, $applications, $post, $cr $postarray["body"] = $msgdata["body"]; $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 = ""; $type = ""; @@ -328,43 +347,44 @@ function fbsync_createpost($a, $uid, $self, $contacts, $applications, $post, $cr $content = "[b]" . $post->attachment->name."[/b]"; $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; - 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; if ($quote.$post->attachment->href.$content.$postarray["body"] == "") return; - if (isset($post->attachment->media) // AND !strstr($post->attachment->href, "://www.youtube.com/") - //AND !strstr($post->attachment->href, "://youtu.be/") - //AND !strstr($post->attachment->href, ".vimeo.com/")) - AND (($type == "") OR ($type == "link"))) { + if (isset($post->attachment->media) AND (($type == "") OR ($type == "link"))) { 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)) $type = $media->type; - if(isset($media->src) && isset($media->href) AND ($media->src != "") AND ($media->href != "")) - $content .= "\n".'[url='.$media->href.'][img]'.fpost_cleanpicture($media->src).'[/img][/url]'; + if (isset($media->src)) + $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 { - if (isset($media->src) AND ($media->src != "")) - $content .= "\n".'[img]'.fpost_cleanpicture($media->src).'[/img]'; + if ($preview != "") + $content .= "\n".'[img]'.$preview.'[/img]'; // 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); } } } + if ($type == "link") + $postarray["object-type"] = ACTIVITY_OBJ_BOOKMARK; + if ($content) $postarray["body"] .= "\n"; @@ -490,6 +510,7 @@ function fbsync_createcomment($a, $uid, $self_id, $self, $user, $contacts, $appl $postarray['wall'] = 0; $postarray['verb'] = ACTIVITY_POST; + $postarray['object-type'] = ACTIVITY_OBJ_COMMENT; $postarray['network'] = dbesc(NETWORK_FACEBOOK); $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'], 'uid' => $user[0]['uid'], '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_link' => $postarray['author-link'], 'source_photo' => $postarray['author-avatar'], @@ -641,8 +663,11 @@ function fbsync_createlike($a, $uid, $self_id, $self, $contacts, $like) { $likedata = array(); $likedata['parent'] = $orig_post['id']; + $likedata['verb'] = ACTIVITY_LIKE; + $likedata['object-type'] = ACTIVITY_OBJ_NOTE; $likedate['network'] = dbesc(NETWORK_FACEBOOK); + $likedata['gravity'] = 3; $likedata['uid'] = $uid; $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; $feed = fetch_url($url); + file_put_contents("fb.".$uid); $data = json_decode($feed); if (!is_array($data->data)) { diff --git a/pumpio/pumpio.php b/pumpio/pumpio.php index 62467414..936f0c14 100644 --- a/pumpio/pumpio.php +++ b/pumpio/pumpio.php @@ -472,6 +472,9 @@ function pumpio_send(&$a,&$b) { $inReplyTo = array("id" => $orig_post["uri"], "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( 'objectType' => "comment", 'content' => $title.$content, @@ -546,7 +549,9 @@ function pumpio_action(&$a, $uid, $uri, $action, $content) { else $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"; elseif (strstr($uri, "/api/note/")) $objectType = "note"; @@ -865,7 +870,6 @@ function pumpio_dolike(&$a, $uid, $self, $post, $own_id) { $likedata['parent-uri'] = $orig_post["uri"]; $likedata['contact-id'] = $contactid; $likedata['app'] = $post->generator->displayName; - $likedata['verb'] = ACTIVITY_LIKE; $likedata['author-name'] = $post->actor->displayName; $likedata['author-link'] = $post->actor->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['wall'] = 0; $postarray['uri'] = $post->object->id; + $postarray['object-type'] = NAMESPACE_ACTIVITY_SCHEMA.strtolower($post->object->objectType); if ($post->object->objectType != "comment") { $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'], 'uid' => $user[0]['uid'], '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_link' => $postarray['author-link'], 'source_photo' => $postarray['author-avatar'], diff --git a/statusnet/statusnet.php b/statusnet/statusnet.php index fbd9bdd4..0cabbca8 100644 --- a/statusnet/statusnet.php +++ b/statusnet/statusnet.php @@ -1078,6 +1078,7 @@ function statusnet_createpost($a, $uid, $post, $self, $create_user, $only_existi if (count($r)) { $postarray['thr-parent'] = $r[0]["uri"]; $postarray['parent-uri'] = $r[0]["parent-uri"]; + $postarray['object-type'] = ACTIVITY_OBJ_COMMENT; } else { $r = q("SELECT * FROM `item` WHERE `extid` = '%s' AND `uid` = %d LIMIT 1", dbesc($parent), @@ -1086,9 +1087,11 @@ function statusnet_createpost($a, $uid, $post, $self, $create_user, $only_existi if (count($r)) { $postarray['thr-parent'] = $r[0]['uri']; $postarray['parent-uri'] = $r[0]['parent-uri']; + $postarray['object-type'] = ACTIVITY_OBJ_COMMENT; } else { $postarray['thr-parent'] = $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 $create_user = false; - } else + } else { $postarray['parent-uri'] = $postarray['uri']; + $postarray['object-type'] = ACTIVITY_OBJ_NOTE; + } if ($contactid == 0) { $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['verb'] = ACTIVITY_POST; + $postarray['author-name'] = $postarray['owner-name']; $postarray['author-link'] = $postarray['owner-link']; $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'], 'uid' => $user[0]['uid'], '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_link' => $postarray['author-link'], 'source_photo' => $postarray['author-avatar'], @@ -1412,7 +1419,8 @@ function statusnet_fetchhometimeline($a, $uid) { 'to_email' => $u[0]['email'], 'uid' => $u[0]['uid'], '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_link' => $postarray['author-link'], 'source_photo' => $postarray['author-avatar'], diff --git a/twitter/twitter.php b/twitter/twitter.php index c332f7be..25c64b48 100644 --- a/twitter/twitter.php +++ b/twitter/twitter.php @@ -1243,6 +1243,7 @@ function twitter_createpost($a, $uid, $post, $self, $create_user, $only_existing if (count($r)) { $postarray['thr-parent'] = $r[0]["uri"]; $postarray['parent-uri'] = $r[0]["parent-uri"]; + $postarray['object-type'] = ACTIVITY_OBJ_COMMENT; } else { $r = q("SELECT * FROM `item` WHERE `extid` = '%s' AND `uid` = %d LIMIT 1", dbesc($parent), @@ -1251,9 +1252,11 @@ function twitter_createpost($a, $uid, $post, $self, $create_user, $only_existing if (count($r)) { $postarray['thr-parent'] = $r[0]['uri']; $postarray['parent-uri'] = $r[0]['parent-uri']; + $postarray['object-type'] = ACTIVITY_OBJ_COMMENT; } else { $postarray['thr-parent'] = $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 $create_user = false; - } else + } else { $postarray['parent-uri'] = $postarray['uri']; + $postarray['object-type'] = ACTIVITY_OBJ_NOTE; + } if ($contactid == 0) { $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']); //$has_picture = true; $postarray['body'] = str_replace($media->url, "", $postarray['body']); + $postarray['object-type'] = ACTIVITY_OBJ_IMAGE; $picture = $media->media_url_https; break; 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']); //$has_picture = true; $postarray['body'] = str_replace($media->url, "", $postarray['body']); + $postarray['object-type'] = ACTIVITY_OBJ_IMAGE; $picture = $media->media_url_https; break; default: @@ -1445,7 +1452,8 @@ function twitter_checknotification($a, $uid, $own_id, $top_item, $postarray) { 'to_email' => $user[0]['email'], 'uid' => $user[0]['uid'], '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_link' => $postarray['author-link'], 'source_photo' => $postarray['author-avatar'], @@ -1606,7 +1614,8 @@ function twitter_fetchhometimeline($a, $uid) { 'to_email' => $u[0]['email'], 'uid' => $u[0]['uid'], '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_link' => $postarray['author-link'], 'source_photo' => $postarray['author-avatar'],