From 23490bda0a5ec9889afca89189db9c59f76fbcc5 Mon Sep 17 00:00:00 2001 From: Michael Vogel Date: Thu, 21 Aug 2014 01:02:13 +0200 Subject: [PATCH 1/4] appnet, fbsync, statusnet and twitter: Now a parent is provided in the notifications so threading of the mails will work. --- appnet/appnet.php | 78 ++++++++++++++++++++++++++++------------- fbsync/fbsync.php | 7 ++++ statusnet/statusnet.php | 11 ++++-- twitter/twitter.php | 17 +++++++-- 4 files changed, 83 insertions(+), 30 deletions(-) diff --git a/appnet/appnet.php b/appnet/appnet.php index a8335d7b..b647c545 100644 --- a/appnet/appnet.php +++ b/appnet/appnet.php @@ -750,13 +750,30 @@ function appnet_fetchstream($a, $uid) { foreach ($mentions AS $post) { $postarray = appnet_createpost($a, $uid, $post, $me, $user, $ownid, false); - if (isset($postarray["id"])) + if (isset($postarray["id"])) { $item = $postarray["id"]; - elseif (isset($postarray["body"])) { + $parent_id = $postarray['parent']; + } elseif (isset($postarray["body"])) { $item = item_store($postarray); + $parent_id = 0; logger('appnet_fetchstream: User '.$uid.' posted mention item '.$item); - } else + } else { $item = 0; + $parent_id = 0; + } + + // Fetch the parent and id + if (($parent_id == 0) AND ($postarray['uri'] != "")) { + $r = q("SELECT `id`, `parent` FROM `item` WHERE `uri` = '%s' AND `uid` = %d LIMIT 1", + dbesc($postarray['uri']), + intval($uid) + ); + + if (count($r)) { + $item = $r[0]['id']; + $parent_id = $r[0]['parent']; + } + } $lastid = $post["id"]; @@ -776,7 +793,8 @@ function appnet_fetchstream($a, $uid) { 'source_link' => $postarray['author-link'], 'source_photo' => $postarray['author-avatar'], 'verb' => ACTIVITY_TAG, - 'otype' => 'item' + 'otype' => 'item', + 'parent' => $parent_id, )); } } @@ -792,7 +810,7 @@ function appnet_fetchstream($a, $uid) { */ } -function appnet_createpost($a, $uid, $post, $me, $user, $ownid, $createuser, $threadcompletion = true) { +function appnet_createpost($a, $uid, $post, $me, $user, $ownid, $createuser, $threadcompletion = true, $nodupcheck = false) { require_once('include/items.php'); if ($post["machine_only"]) @@ -807,25 +825,33 @@ function appnet_createpost($a, $uid, $post, $me, $user, $ownid, $createuser, $th $postarray['wall'] = 0; $postarray['verb'] = ACTIVITY_POST; $postarray['network'] = dbesc(NETWORK_APPNET); - $postarray['uri'] = "adn::".$post["id"]; + if (is_array($post["repost_of"])) { + // You can't reply to reposts. So use the original id and thread-id + $postarray['uri'] = "adn::".$post["repost_of"]["id"]; + $postarray['parent-uri'] = "adn::".$post["repost_of"]["thread_id"]; + } else { + $postarray['uri'] = "adn::".$post["id"]; + $postarray['parent-uri'] = "adn::".$post["thread_id"]; + } - $r = q("SELECT * FROM `item` WHERE `uri` = '%s' AND `uid` = %d LIMIT 1", - dbesc($postarray['uri']), - intval($uid) - ); + if (!$nodupcheck) { + $r = q("SELECT * FROM `item` WHERE `uri` = '%s' AND `uid` = %d LIMIT 1", + dbesc($postarray['uri']), + intval($uid) + ); - if (count($r)) - return($r[0]); + if (count($r)) + return($r[0]); - $r = q("SELECT * FROM `item` WHERE `extid` = '%s' AND `uid` = %d LIMIT 1", - dbesc($postarray['uri']), - intval($uid) - ); + $r = q("SELECT * FROM `item` WHERE `extid` = '%s' AND `uid` = %d LIMIT 1", + dbesc($postarray['uri']), + intval($uid) + ); - if (count($r)) - return($r[0]); + if (count($r)) + return($r[0]); + } - $postarray['parent-uri'] = "adn::".$post["thread_id"]; if (isset($post["reply_to"]) AND ($post["reply_to"] != "")) { $postarray['thr-parent'] = "adn::".$post["reply_to"]; @@ -875,8 +901,6 @@ function appnet_createpost($a, $uid, $post, $me, $user, $ownid, $createuser, $th $postarray['object-type'] = ACTIVITY_OBJ_NOTE; } - $postarray['plink'] = $post["canonical_url"]; - if (($post["user"]["id"] != $ownid) OR ($postarray['thr-parent'] == $postarray['uri'])) { $postarray['owner-name'] = $post["user"]["name"]; $postarray['owner-link'] = $post["user"]["canonical_url"]; @@ -905,6 +929,8 @@ function appnet_createpost($a, $uid, $post, $me, $user, $ownid, $createuser, $th $content = $post; } + $postarray['plink'] = $content["canonical_url"]; + if (is_array($content["entities"])) { $converted = appnet_expand_entities($a, $content["text"], $content["entities"]); $postarray['body'] = $converted["body"]; @@ -969,11 +995,13 @@ function appnet_createpost($a, $uid, $post, $me, $user, $ownid, $createuser, $th $link = array_pop($links); $url = str_replace(array('/', '.'), array('\/', '\.'), $link); - $removedlink = preg_replace("/\[url\=".$url."\](.*?)\[\/url\]/ism", '', $postarray['body']); - if (($removedlink == "") OR strstr($postarray['body'], $removedlink)) - $postarray['body'] = $removedlink; - $page_info = add_page_info($link, false, $photo["url"]); + + if (trim($page_info) != "") { + $removedlink = preg_replace("/\[url\=".$url."\](.*?)\[\/url\]/ism", '', $postarray['body']); + if (($removedlink == "") OR strstr($postarray['body'], $removedlink)) + $postarray['body'] = $removedlink; + } } $postarray['body'] .= $page_info; diff --git a/fbsync/fbsync.php b/fbsync/fbsync.php index 78ecea1d..51d2747f 100644 --- a/fbsync/fbsync.php +++ b/fbsync/fbsync.php @@ -345,6 +345,13 @@ function fbsync_createpost($a, $uid, $self, $contacts, $applications, $post, $cr $type = "link"; $content = "[bookmark=".$post->attachment->href."]".$post->attachment->name."[/bookmark]"; + + // If a link is not only attached but also added in the body, look if it can be removed in the body. + $removedlink = trim(str_replace($post->attachment->href, "", $postarray["body"])); + + if (($removedlink == "") OR strstr($postarray["body"], $removedlink)) + $postarray["body"] = $removedlink; + } elseif (isset($post->attachment->name) AND ($post->attachment->name != "")) $content = "[b]" . $post->attachment->name."[/b]"; diff --git a/statusnet/statusnet.php b/statusnet/statusnet.php index f941531e..9aa2fdfc 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['parent'] = $r[0]["parent"]; $postarray['object-type'] = ACTIVITY_OBJ_COMMENT; } else { $r = q("SELECT * FROM `item` WHERE `extid` = '%s' AND `uid` = %d LIMIT 1", @@ -1087,6 +1088,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['parent'] = $r[0]['parent']; $postarray['object-type'] = ACTIVITY_OBJ_COMMENT; } else { $postarray['thr-parent'] = $postarray['uri']; @@ -1189,6 +1191,8 @@ function statusnet_createpost($a, $uid, $post, $self, $create_user, $only_existi function statusnet_checknotification($a, $uid, $own_url, $top_item, $postarray) { + // This function necer worked and need cleanup + $user = q("SELECT * FROM `contact` WHERE `uid` = %d AND `self` LIMIT 1", intval($uid) ); @@ -1405,8 +1409,10 @@ function statusnet_fetchhometimeline($a, $uid) { dbesc($postarray['uri']), intval($uid) ); - if (count($r)) + if (count($r)) { $item = $r[0]['id']; + $parent_id = $r[0]['parent']; + } if ($item != 0) { require_once('include/enotify.php'); @@ -1423,7 +1429,8 @@ function statusnet_fetchhometimeline($a, $uid) { 'source_link' => $postarray['author-link'], 'source_photo' => $postarray['author-avatar'], 'verb' => ACTIVITY_TAG, - 'otype' => 'item' + 'otype' => 'item', + 'parent' => $parent_id, )); } } diff --git a/twitter/twitter.php b/twitter/twitter.php index 6731e324..b2003445 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['parent'] = $r[0]["parent"]; $postarray['object-type'] = ACTIVITY_OBJ_COMMENT; } else { $r = q("SELECT * FROM `item` WHERE `extid` = '%s' AND `uid` = %d LIMIT 1", @@ -1252,6 +1253,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['parent'] = $r[0]['parent']; $postarray['object-type'] = ACTIVITY_OBJ_COMMENT; } else { $postarray['thr-parent'] = $postarray['uri']; @@ -1404,6 +1406,8 @@ function twitter_createpost($a, $uid, $post, $self, $create_user, $only_existing function twitter_checknotification($a, $uid, $own_id, $top_item, $postarray) { + // this whole function doesn't seem to work. Needs complete check + $user = q("SELECT * FROM `contact` WHERE `uid` = %d AND `self` LIMIT 1", intval($uid) ); @@ -1592,6 +1596,9 @@ function twitter_fetchhometimeline($a, $uid) { $item = item_store($postarray); + if (!isset($postarray["parent"]) OR ($postarray["parent"] == 0)) + $postarray["parent"] = $item; + logger('twitter_fetchhometimeline: User '.$self["nick"].' posted mention timeline item '.$item); if ($item == 0) { @@ -1599,9 +1606,12 @@ function twitter_fetchhometimeline($a, $uid) { dbesc($postarray['uri']), intval($uid) ); - if (count($r)) + if (count($r)) { $item = $r[0]['id']; - } + $parent_id = $r[0]['parent']; + } + } else + $parent_id = $postarray['parent']; if ($item != 0) { require_once('include/enotify.php'); @@ -1618,7 +1628,8 @@ function twitter_fetchhometimeline($a, $uid) { 'source_link' => $postarray['author-link'], 'source_photo' => $postarray['author-avatar'], 'verb' => ACTIVITY_TAG, - 'otype' => 'item' + 'otype' => 'item', + 'parent' => $parent_id )); } } From a0d67d8b445f52e95bfe6a416b0d735fe8c25980 Mon Sep 17 00:00:00 2001 From: Michael Vogel Date: Mon, 25 Aug 2014 14:17:53 +0200 Subject: [PATCH 2/4] appnet: This should mostly prevent picture posts with two links to the same picture --- appnet/appnet.php | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/appnet/appnet.php b/appnet/appnet.php index b647c545..7e80c6ab 100644 --- a/appnet/appnet.php +++ b/appnet/appnet.php @@ -944,7 +944,7 @@ function appnet_createpost($a, $uid, $post, $me, $user, $ownid, $createuser, $th $links[$url] = $link["url"]; } - if (sizeof($content["annotations"])) + /* if (sizeof($content["annotations"])) foreach($content["annotations"] AS $annotation) { if ($annotation[type] == "net.app.core.oembed") { if (isset($annotation["value"]["embeddable_url"])) { @@ -953,7 +953,6 @@ function appnet_createpost($a, $uid, $post, $me, $user, $ownid, $createuser, $th unset($links[$url]); } } elseif ($annotation[type] == "com.friendica.post") { - // Nur zum Testen deaktiviert //$links = array(); //if (isset($annotation["value"]["post-title"])) // $postarray['title'] = $annotation["value"]["post-title"]; @@ -974,7 +973,7 @@ function appnet_createpost($a, $uid, $post, $me, $user, $ownid, $createuser, $th $postarray['author-avatar'] = $annotation["value"]["author-avatar"]; } - } + } */ $page_info = ""; From 1766a42b1a9972b3279ea0342937f6fabcb2dfaf Mon Sep 17 00:00:00 2001 From: Michael Vogel Date: Mon, 25 Aug 2014 14:19:09 +0200 Subject: [PATCH 3/4] pumpio: prevent a warning message because of a missing parameter --- pumpio/pumpio.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pumpio/pumpio.php b/pumpio/pumpio.php index 0d7786c1..55d0433a 100644 --- a/pumpio/pumpio.php +++ b/pumpio/pumpio.php @@ -521,7 +521,7 @@ function pumpio_send(&$a,&$b) { } } -function pumpio_action(&$a, $uid, $uri, $action, $content) { +function pumpio_action(&$a, $uid, $uri, $action, $content = "") { // Don't do likes and other stuff if you don't import the timeline if (!get_pconfig($uid,'pumpio','import')) From 9c16c8e5f9b266ca90ac0df45e9a18eaa0ea3011 Mon Sep 17 00:00:00 2001 From: Michael Vogel Date: Mon, 25 Aug 2014 14:19:41 +0200 Subject: [PATCH 4/4] statusnet: Bugfixes: Repeated messages weren't always displayed correctly. When answering to posts, sometimes wrong nicknames were used. --- statusnet/statusnet.php | 70 +++++++++++++++++++++++++---------------- 1 file changed, 43 insertions(+), 27 deletions(-) diff --git a/statusnet/statusnet.php b/statusnet/statusnet.php index 9aa2fdfc..c3591356 100644 --- a/statusnet/statusnet.php +++ b/statusnet/statusnet.php @@ -496,8 +496,13 @@ function statusnet_post_hook(&$a,&$b) { $orig_post = $r[0]; } - $nickname = "@[url=".$orig_post["author-link"]."]".$orig_post["contact_nick"]."[/url]"; - $nicknameplain = "@".$orig_post["contact_nick"]; + //$nickname = "@[url=".$orig_post["author-link"]."]".$orig_post["contact_nick"]."[/url]"; + //$nicknameplain = "@".$orig_post["contact_nick"]; + + $nick = preg_replace("=https?://(.*)/(.*)=ism", "$2", $orig_post["author-link"]); + + $nickname = "@[url=".$orig_post["author-link"]."]".$nick."[/url]"; + $nicknameplain = "@".$nick; logger("statusnet_post_hook: comparing ".$nickname." and ".$nicknameplain." with ".$b["body"], LOGGER_DEBUG); if ((strpos($b["body"], $nickname) === false) AND (strpos($b["body"], $nicknameplain) === false)) @@ -700,9 +705,13 @@ function statusnet_prepare_body(&$a,&$b) { if(count($r)) { $orig_post = $r[0]; + //$nickname = "@[url=".$orig_post["author-link"]."]".$orig_post["contact_nick"]."[/url]"; + //$nicknameplain = "@".$orig_post["contact_nick"]; - $nickname = "@[url=".$orig_post["author-link"]."]".$orig_post["contact_nick"]."[/url]"; - $nicknameplain = "@".$orig_post["contact_nick"]; + $nick = preg_replace("=https?://(.*)/(.*)=ism", "$2", $orig_post["author-link"]); + + $nickname = "@[url=".$orig_post["author-link"]."]".$nick."[/url]"; + $nicknameplain = "@".$nick; if ((strpos($item["body"], $nickname) === false) AND (strpos($item["body"], $nicknameplain) === false)) $item["body"] = $nickname." ".$item["body"]; @@ -1055,7 +1064,14 @@ function statusnet_createpost($a, $uid, $post, $self, $create_user, $only_existi $postarray['gravity'] = 0; $postarray['uid'] = $uid; $postarray['wall'] = 0; - $postarray['uri'] = $hostname."::".$post->id; + + if (is_object($post->retweeted_status)) { + $content = $post->retweeted_status; + statusnet_fetch_contact($uid, $content->user, false); + } else + $content = $post; + + $postarray['uri'] = $hostname."::".$content->id; $r = q("SELECT * FROM `item` WHERE `extid` = '%s' AND `uid` = %d LIMIT 1", dbesc($postarray['uri']), @@ -1067,9 +1083,9 @@ function statusnet_createpost($a, $uid, $post, $self, $create_user, $only_existi $contactid = 0; - if ($post->in_reply_to_status_id != "") { + if ($content->in_reply_to_status_id != "") { - $parent = $hostname."::".$post->in_reply_to_status_id; + $parent = $hostname."::".$content->in_reply_to_status_id; $r = q("SELECT * FROM `item` WHERE `uri` = '%s' AND `uid` = %d LIMIT 1", dbesc($parent), @@ -1100,7 +1116,7 @@ function statusnet_createpost($a, $uid, $post, $self, $create_user, $only_existi // Is it me? $own_url = get_pconfig($uid, 'statusnet', 'own_url'); - if ($post->user->id == $own_url) { + if ($content->user->id == $own_url) { $r = q("SELECT * FROM `contact` WHERE `self` = 1 AND `uid` = %d LIMIT 1", intval($uid)); @@ -1135,43 +1151,43 @@ function statusnet_createpost($a, $uid, $post, $self, $create_user, $only_existi $postarray['verb'] = ACTIVITY_POST; - $postarray['author-name'] = $postarray['owner-name']; - $postarray['author-link'] = $postarray['owner-link']; - $postarray['author-avatar'] = $postarray['owner-avatar']; + $postarray['author-name'] = $content->user->name; + $postarray['author-link'] = $content->user->statusnet_profile_url; + $postarray['author-avatar'] = $content->user->profile_image_url; // To-Do: Maybe unreliable? Can the api be entered without trailing "/"? $hostname = str_replace("/api/", "/notice/", get_pconfig($uid, 'statusnet', 'baseapi')); - $postarray['plink'] = $hostname.$post->id; - $postarray['app'] = strip_tags($post->source); + $postarray['plink'] = $hostname.$content->id; + $postarray['app'] = strip_tags($content->source); - if ($post->user->protected) { + if ($content->user->protected) { $postarray['private'] = 1; $postarray['allow_cid'] = '<' . $self['id'] . '>'; } - $postarray['body'] = html2bbcode($post->statusnet_html); + $postarray['body'] = html2bbcode($content->statusnet_html); $converted = statusnet_convertmsg($a, $postarray['body'], false); $postarray['body'] = $converted["body"]; $postarray['tag'] = $converted["tags"]; - $postarray['created'] = datetime_convert('UTC','UTC',$post->created_at); - $postarray['edited'] = datetime_convert('UTC','UTC',$post->created_at); + $postarray['created'] = datetime_convert('UTC','UTC',$content->created_at); + $postarray['edited'] = datetime_convert('UTC','UTC',$content->created_at); - if (is_string($post->place->name)) - $postarray["location"] = $post->place->name; + if (is_string($content->place->name)) + $postarray["location"] = $content->place->name; - if (is_string($post->place->full_name)) - $postarray["location"] = $post->place->full_name; + if (is_string($content->place->full_name)) + $postarray["location"] = $content->place->full_name; - if (is_array($post->geo->coordinates)) - $postarray["coord"] = $post->geo->coordinates[0]." ".$post->geo->coordinates[1]; + if (is_array($content->geo->coordinates)) + $postarray["coord"] = $content->geo->coordinates[0]." ".$content->geo->coordinates[1]; - if (is_array($post->coordinates->coordinates)) - $postarray["coord"] = $post->coordinates->coordinates[1]." ".$post->coordinates->coordinates[0]; + if (is_array($content->coordinates->coordinates)) + $postarray["coord"] = $content->coordinates->coordinates[1]." ".$content->coordinates->coordinates[0]; - if (is_object($post->retweeted_status)) { + /*if (is_object($post->retweeted_status)) { $postarray['body'] = html2bbcode($post->retweeted_status->statusnet_html); $converted = statusnet_convertmsg($a, $postarray['body'], false); @@ -1184,7 +1200,7 @@ function statusnet_createpost($a, $uid, $post, $self, $create_user, $only_existi $postarray['author-name'] = $post->retweeted_status->user->name; $postarray['author-link'] = $post->retweeted_status->user->statusnet_profile_url; $postarray['author-avatar'] = $post->retweeted_status->user->profile_image_url; - } + }*/ logger("statusnet_createpost: end", LOGGER_DEBUG); return($postarray); }