From f34135f34dc4262dbb9978ea27d45f10e595078f Mon Sep 17 00:00:00 2001 From: Michael Vogel Date: Sat, 6 Jun 2015 13:15:37 +0200 Subject: [PATCH 1/9] OStatus: Attachment links are now added as enclosures --- include/bbcode.php | 11 +++++---- include/items.php | 38 +++++++++++++++++++++++++++----- include/ostatus_conversation.php | 3 ++- 3 files changed, 41 insertions(+), 11 deletions(-) diff --git a/include/bbcode.php b/include/bbcode.php index 6c7f39a9ff..32265363cc 100644 --- a/include/bbcode.php +++ b/include/bbcode.php @@ -13,9 +13,9 @@ function bb_map_location($match) { return str_replace($match[0],'
' . generate_named_map($match[1]) . '
', $match[0]); } -function bb_attachment($Text, $plaintext = false, $tryoembed = true) { +function bb_attachment($Text, $simplehtml = false, $tryoembed = true) { $Text = preg_replace_callback("/(.*?)\[attachment(.*?)\](.*?)\[\/attachment\]/ism", - function ($match) use ($plaintext, $tryoembed){ + function ($match) use ($simplehtml, $tryoembed){ $attributes = $match[2]; @@ -83,7 +83,10 @@ function bb_attachment($Text, $plaintext = false, $tryoembed = true) { $image = ""; } - if ($plaintext) + if ($simplehtml == 7) + $text = sprintf('%s', + $url, $title, $title); + elseif (($simplehtml != 4) AND ($simplehtml != 0)) $text = sprintf('%s
', $url, $title); else { $text = sprintf('', $type); @@ -871,7 +874,7 @@ function bbcode($Text,$preserve_nl = false, $tryoembed = true, $simplehtml = fal } // Handle attached links or videos - $Text = bb_attachment($Text, ($simplehtml != 4) AND ($simplehtml != 0), $tryoembed); + $Text = bb_attachment($Text, $simplehtml, $tryoembed); $Text = str_replace(array("\r","\n"), array('
','
'), $Text); diff --git a/include/items.php b/include/items.php index 3fe624b001..c34859d940 100644 --- a/include/items.php +++ b/include/items.php @@ -12,6 +12,7 @@ require_once('include/email.php'); require_once('include/ostatus_conversation.php'); require_once('include/threads.php'); require_once('include/socgraph.php'); +require_once('include/plaintext.php'); require_once('mod/share.php'); function get_feed_for(&$a, $dfrn_id, $owner_nick, $last_update, $direction = 0, $forpubsub = false) { @@ -4344,7 +4345,8 @@ function atom_entry($item,$type,$author,$owner,$comment = false,$cid = 0) { if ($item['title'] != "") $htmlbody = "[b]".$item['title']."[/b]\n\n".$htmlbody; - $htmlbody = bbcode(bb_remove_share_information($htmlbody), false, false, 7); + //$htmlbody = bbcode(bb_remove_share_information($htmlbody), false, false, 7); + $htmlbody = bbcode($htmlbody, false, false, 7); $o .= '' . xmlify($item['uri']) . '' . "\r\n"; $o .= '' . xmlify($item['title']) . '' . "\r\n"; @@ -4401,6 +4403,8 @@ function atom_entry($item,$type,$author,$owner,$comment = false,$cid = 0) { } } + $o .= item_get_attachment($item); + $o .= item_getfeedattach($item); $mentioned = get_mentions($item); @@ -4578,6 +4582,28 @@ function item_getfeedtags($item) { return $ret; } +function item_get_attachment($item) { + $o = ""; + $siteinfo = get_attached_data($item["body"]); + + switch($siteinfo["type"]) { + case 'link': + $o = ''."\r\n"; + break; + case 'photo': + $imgdata = get_photo_info($siteinfo["image"]); + $o = ''."\r\n"; + break; + case 'video': + $o = ''."\r\n"; + break; + default: + break; + } + + return $o; +} + function item_getfeedattach($item) { $ret = ''; $arr = explode('[/attach],',$item['attach']); @@ -4951,7 +4977,7 @@ function list_post_dates($uid, $wall) { return array(); // Set the start and end date to the beginning of the month - $dnow = substr($dnow,0,8).'01'; + $dnow = substr($dnow,0,8).'01'; $dthen = substr($dthen,0,8).'01'; $ret = array(); @@ -4967,7 +4993,7 @@ function list_post_dates($uid, $wall) { $str = day_translate(datetime_convert('','',$dnow,'F')); if(! $ret[$dyear]) $ret[$dyear] = array(); - $ret[$dyear][] = array($str,$end_month,$start_month); + $ret[$dyear][] = array($str,$end_month,$start_month); $dnow = datetime_convert('','',$dnow . ' -1 month', 'Y-m-d'); } return $ret; @@ -5015,12 +5041,12 @@ function posted_date_widget($url,$uid,$wall) { if(! $visible_years) $visible_years = 5; - $ret = list_post_dates($uid,$wall); + $ret = list_post_dates($uid,$wall); if(! count($ret)) return $o; - $cutoff_year = intval(datetime_convert('',date_default_timezone_get(),'now','Y')) - $visible_years; + $cutoff_year = intval(datetime_convert('',date_default_timezone_get(),'now','Y')) - $visible_years; $cutoff = ((array_key_exists($cutoff_year,$ret))? true : false); $o = replace_macros(get_markup_template('posted_date_widget.tpl'),array( @@ -5030,7 +5056,7 @@ function posted_date_widget($url,$uid,$wall) { '$cutoff' => $cutoff, '$url' => $url, '$dates' => $ret, - '$showmore' => t('show more') + '$showmore' => t('show more') )); return $o; diff --git a/include/ostatus_conversation.php b/include/ostatus_conversation.php index f40c4827b9..2670d19766 100644 --- a/include/ostatus_conversation.php +++ b/include/ostatus_conversation.php @@ -53,8 +53,9 @@ function check_conversations($override = false) { logger('cron_start'); $start = date("Y-m-d H:i:s", time() - ($poll_timeframe * 60)); - $conversations = q("SELECT * FROM `term` WHERE `type` = 7 AND `term` > '%s'", + $conversations = q("SELECT `oid`, `url` FROM `term` WHERE `type` = 7 AND `term` > '%s' GROUP BY `url` ORDER BY `term` DESC", dbesc($start)); + foreach ($conversations AS $conversation) { $id = $conversation['oid']; $url = $conversation['url']; From a3c497190d80795e8f544079f8da7b5563f1ab87 Mon Sep 17 00:00:00 2001 From: Michael Vogel Date: Sun, 7 Jun 2015 23:18:02 +0200 Subject: [PATCH 2/9] Complete new OStatus import. --- include/items.php | 68 +++--- include/ostatus.php | 358 +++++++++++++++++++++++++++++++ include/ostatus_conversation.php | 29 +-- mod/item.php | 24 ++- 4 files changed, 438 insertions(+), 41 deletions(-) create mode 100644 include/ostatus.php diff --git a/include/items.php b/include/items.php index c34859d940..97eb15efcf 100644 --- a/include/items.php +++ b/include/items.php @@ -9,10 +9,11 @@ require_once('include/tags.php'); require_once('include/files.php'); require_once('include/text.php'); require_once('include/email.php'); -require_once('include/ostatus_conversation.php'); +//require_once('include/ostatus_conversation.php'); require_once('include/threads.php'); require_once('include/socgraph.php'); require_once('include/plaintext.php'); +require_once('include/ostatus.php'); require_once('mod/share.php'); function get_feed_for(&$a, $dfrn_id, $owner_nick, $last_update, $direction = 0, $forpubsub = false) { @@ -119,7 +120,7 @@ function get_feed_for(&$a, $dfrn_id, $owner_nick, $last_update, $direction = 0, // Include answers to status.net posts in pubsub feeds if($forpubsub) { $sql_post_table = "INNER JOIN `thread` ON `thread`.`iid` = `item`.`parent` "; - $visibility = sprintf("OR (`item`.`network` = '%s' AND `thread`.`network`='%s')", + $visibility = sprintf("AND (`item`.`parent` = `item`.`id`) OR (`item`.`network` = '%s' AND `thread`.`network`='%s')", dbesc(NETWORK_DFRN), dbesc(NETWORK_OSTATUS)); $date_field = "`received`"; $sql_order = "`item`.`received` DESC"; @@ -885,22 +886,22 @@ function get_atom_elements($feed, $item, $contact = array()) { } } - // Search for ostatus conversation url - $links = $item->feed->data["child"][SIMPLEPIE_NAMESPACE_ATOM_10]["feed"][0]["child"][SIMPLEPIE_NAMESPACE_ATOM_10]["entry"][0]["child"]["http://www.w3.org/2005/Atom"]["link"]; - - if (is_array($links)) { - foreach ($links as $link) { - $conversation = array_shift($link["attribs"]); - - if ($conversation["rel"] == "ostatus:conversation") { - $res["ostatus_conversation"] = ostatus_convert_href($conversation["href"]); - logger('get_atom_elements: found conversation url '.$res["ostatus_conversation"]); - //} elseif ($conversation["rel"] == "alternate") { - // $res["plink"] = $conversation["href"]; - // logger('get_atom_elements: found plink '.$res["plink"]); - } - }; - } +// // Search for ostatus conversation url +// $links = $item->feed->data["child"][SIMPLEPIE_NAMESPACE_ATOM_10]["feed"][0]["child"][SIMPLEPIE_NAMESPACE_ATOM_10]["entry"][0]["child"]["http://www.w3.org/2005/Atom"]["link"]; +// +// if (is_array($links)) { +// foreach ($links as $link) { +// $conversation = array_shift($link["attribs"]); +// +// if ($conversation["rel"] == "ostatus:conversation") { +// $res["ostatus_conversation"] = ostatus_convert_href($conversation["href"]); +// logger('get_atom_elements: found conversation url '.$res["ostatus_conversation"]); +// //} elseif ($conversation["rel"] == "alternate") { +// // $res["plink"] = $conversation["href"]; +// // logger('get_atom_elements: found plink '.$res["plink"]); +// } +// }; +// } if (isset($contact["network"]) AND ($contact["network"] == NETWORK_FEED) AND $contact['fetch_further_information']) { $preview = ""; @@ -1138,14 +1139,14 @@ function item_store($arr,$force_parent = false, $notify = false, $dontcache = fa $arr['plink'] = ostatus_convert_href($arr['uri']); } - // if an OStatus conversation url was passed in, it is stored and then - // removed from the array. - $ostatus_conversation = null; +// // if an OStatus conversation url was passed in, it is stored and then +// // removed from the array. +// $ostatus_conversation = null; - if (isset($arr["ostatus_conversation"])) { - $ostatus_conversation = $arr["ostatus_conversation"]; - unset($arr["ostatus_conversation"]); - } +// if (isset($arr["ostatus_conversation"])) { +// $ostatus_conversation = $arr["ostatus_conversation"]; +// unset($arr["ostatus_conversation"]); +// } if(x($arr, 'gravity')) $arr['gravity'] = intval($arr['gravity']); @@ -1386,7 +1387,7 @@ function item_store($arr,$force_parent = false, $notify = false, $dontcache = fa $arr['gravity'] = 0; } else { - logger('item_store: item parent was not found - ignoring item'); + logger('item_store: item parent '.$arr['parent-uri'].' for '.$arr['uid'].' was not found - ignoring item'); return 0; } @@ -1525,8 +1526,8 @@ function item_store($arr,$force_parent = false, $notify = false, $dontcache = fa ); // Complete ostatus threads - if ($ostatus_conversation) - complete_conversation($current_post, $ostatus_conversation); + //if ($ostatus_conversation) + // complete_conversation($current_post, $ostatus_conversation); $arr['id'] = $current_post; $arr['parent'] = $parent_id; @@ -2224,6 +2225,13 @@ function edited_timestamp_is_newer($existing, $update) { */ function consume_feed($xml,$importer,&$contact, &$hub, $datedir = 0, $pass = 0) { + if ($contact['network'] === NETWORK_OSTATUS) { + if ($pass < 2) { + logger("Consume OStatus messages ", LOGGER_DEBUG); + ostatus_import($xml,$importer,$contact); + } + return; + } require_once('library/simplepie/simplepie.inc'); require_once('include/contact_selectors.php'); @@ -4403,6 +4411,10 @@ function atom_entry($item,$type,$author,$owner,$comment = false,$cid = 0) { } } + //$o .= ''."\r\n"; + //$o .= ''."\r\n"; + //$o .= ''."\r\n"; + $o .= item_get_attachment($item); $o .= item_getfeedattach($item); diff --git a/include/ostatus.php b/include/ostatus.php new file mode 100644 index 0000000000..c426a9f10e --- /dev/null +++ b/include/ostatus.php @@ -0,0 +1,358 @@ +evaluate('atom:author/atom:uri/text()', $context)->item(0)->nodeValue; + $author["author-name"] = $xpath->evaluate('atom:author/atom:name/text()', $context)->item(0)->nodeValue; + + // Preserve the value + $authorlink = $author["author-link"]; + + $alternate = $xpath->query("atom:author/atom:link[@rel='alternate']", $context)->item(0)->attributes; + if (is_object($alternate)) + foreach($alternate AS $attributes) + if ($attributes->name == "href") + $author["author-link"] = $attributes->textContent; + + $r = q("SELECT * FROM `contact` WHERE `uid` = %d AND `nurl` IN ('%s', '%s') AND `network` != '%s'", + intval($importer["uid"]), dbesc(normalise_link($author["author-link"])), + dbesc(normalise_link($authorlink)), dbesc(NETWORK_STATUSNET)); + if ($r) { + $contact = $r[0]; + $author["contact-id"] = $r[0]["id"]; + } else + $author["contact-id"] = $contact["id"]; + + $avatarlist = array(); + $avatars = $xpath->query("atom:author/atom:link[@rel='avatar']", $context); + foreach($avatars AS $avatar) { + $href = ""; + $width = 0; + foreach($avatar->attributes AS $attributes) { + if ($attributes->name == "href") + $href = $attributes->textContent; + if ($attributes->name == "width") + $width = $attributes->textContent; + } + if (($width > 0) AND ($href != "")) + $avatarlist[$width] = $href; + } + if (count($avatarlist) > 0) { + krsort($avatarlist); + $author["author-avatar"] = current($avatarlist); + } + + $displayname = $xpath->evaluate('atom:author/poco:displayName/text()', $context)->item(0)->nodeValue; + if ($displayname != "") + $author["author-name"] = $displayname; + + $author["owner-name"] = $author["author-name"]; + $author["owner-link"] = $author["author-link"]; + $author["owner-avatar"] = $author["author-avatar"]; + + return($author); +} + +function ostatus_import($xml,$importer,&$contact) { + + $a = get_app(); + + logger("Import OStatus message", LOGGER_DEBUG); + + if ($xml == "") + return; + + $doc = new DOMDocument(); + $doc->loadXML($xml); + + $xpath = new DomXPath($doc); + $xpath->registerNamespace('atom', "http://www.w3.org/2005/Atom"); + $xpath->registerNamespace('thr', "http://purl.org/syndication/thread/1.0"); + $xpath->registerNamespace('georss', "http://www.georss.org/georss"); + $xpath->registerNamespace('activity', "http://activitystrea.ms/spec/1.0/"); + $xpath->registerNamespace('media', "http://purl.org/syndication/atommedia"); + $xpath->registerNamespace('poco', "http://portablecontacts.net/spec/1.0"); + $xpath->registerNamespace('ostatus', "http://ostatus.org/schema/1.0"); + $xpath->registerNamespace('statusnet', "http://status.net/schema/api/1/"); + + $header = array(); + $header["uid"] = $importer["uid"]; + $header["network"] = NETWORK_OSTATUS; + $header["type"] = "remote"; + $header["wall"] = 0; + $header["origin"] = 0; + $header["gravity"] = GRAVITY_PARENT; + + // it could either be a received post or a post we fetched by ourselves + // depending on that, the first node is different + $first_child = $doc->firstChild->tagName; + + if ($first_child == "feed") + $entries = $xpath->query('/atom:feed/atom:entry'); + else + $entries = $xpath->query('/atom:entry'); + + $conversation = ""; + $conversationlist = array(); + $item_id = 0; + + // Reverse the order of the entries + foreach ($entries AS $entry) + $entrylist[] = $entry; + + foreach (array_reverse($entrylist) AS $entry) { + + $mention = false; + + // fetch the author + if ($first_child == "feed") + $author = ostatus_fetchauthor($xpath, $doc->firstChild, $contact); + else + $author = ostatus_fetchauthor($xpath, $entry, $contact); + + $item = array_merge($header, $author); + + // Now get the item + $item["uri"] = $xpath->query('atom:id/text()', $entry)->item(0)->nodeValue; + $item["body"] = html2bbcode($xpath->query('atom:content/text()', $entry)->item(0)->nodeValue); + $item["object-type"] = $xpath->query('activity:object-type/text()', $entry)->item(0)->nodeValue; + $item["verb"] = $xpath->query('activity:verb/text()', $entry)->item(0)->nodeValue; + + if ($item["verb"] == ACTIVITY_FOLLOW) { + // ignore "Follow" messages + $item = array(); + continue; + } + + if ($item["verb"] == ACTIVITY_FAVORITE) { + // ignore "Favorite" messages + $item = array(); + continue; + } + + $item["created"] = $xpath->query('atom:published/text()', $entry)->item(0)->nodeValue; + $item["edited"] = $xpath->query('atom:updated/text()', $entry)->item(0)->nodeValue; + $conversation = $xpath->query('ostatus:conversation/text()', $entry)->item(0)->nodeValue; + + $related = ""; + + $inreplyto = $xpath->query('thr:in-reply-to', $entry); + if (is_object($inreplyto->item(0))) { + foreach($inreplyto->item(0)->attributes AS $attributes) { + if ($attributes->name == "ref") + $item["parent-uri"] = $attributes->textContent; + if ($attributes->name == "href") + $related = $attributes->textContent; + } + } + + $georsspoint = $xpath->query('georss:point', $entry); + if ($georsspoint) + $item["coord"] = $georsspoint->item(0)->nodeValue; + + $categories = $xpath->query('atom:category', $entry); + if ($categories) { + foreach ($categories AS $category) { + foreach($category->attributes AS $attributes) + if ($attributes->name == "term") { + $term = $attributes->textContent; + if(strlen($item["tag"])) + $item["tag"] .= ','; + $item["tag"] .= "#[url=".$a->get_baseurl()."/search?tag=".$term."]".$term."[/url]"; + } + } + } + + $self = ""; + $enclosure = ""; + + $links = $xpath->query('atom:link', $entry); + if ($links) { + $rel = ""; + $href = ""; + $type = ""; + $length = "0"; + $title = ""; + foreach ($links AS $link) { + foreach($link->attributes AS $attributes) { + if ($attributes->name == "href") + $href = $attributes->textContent; + if ($attributes->name == "rel") + $rel = $attributes->textContent; + if ($attributes->name == "type") + $type = $attributes->textContent; + if ($attributes->name == "length") + $length = $attributes->textContent; + if ($attributes->name == "title") + $title = $attributes->textContent; + } + if (($rel != "") AND ($href != "")) + switch($rel) { + case "alternate": + $item["plink"] = $href; + break; + case "ostatus:conversation": + $conversation = $href; + break; + case "enclosure": + $enclosure = $href; + if(strlen($item["attach"])) + $item["attach"] .= ','; + + $item["attach"] .= '[attach]href="'.$href.'" length="'.$length.'" type="'.$type.'" title="'.$title.'"[/attach]'; + break; + case "related": + if (!isset($item["parent-uri"])) + $item["parent-uri"] = $href; + + if ($related == "") + $related = $href; + break; + case "self": + $self = $href; + break; + case "mentioned": + // Notification check + if ($importer["nurl"] == normalise_link($href)) + $mention = true; + break; + } + } + } + + $local_id = ""; + $repeat_of = ""; + + $notice_info = $xpath->query('statusnet:notice_info', $entry); + if ($notice_info) + foreach($notice_info->item(0)->attributes AS $attributes) { + if ($attributes->name == "source") + $item["app"] = strip_tags($attributes->textContent); + if ($attributes->name == "local_id") + $local_id = $attributes->textContent; + if ($attributes->name == "repeat_of") + $repeat_of = $attributes->textContent; + } + + // Is it a repeated post? + if ($repeat_of != "") { + $activityobjects = $xpath->query('activity:object', $entry)->item(0); + + if (is_object($activityobjects)) { + + $orig_uris = $xpath->query("activity:object/atom:link[@rel='alternate']", $activityobjects); + if ($orig_uris) + foreach($orig_uris->item(0)->attributes AS $attributes) + if ($attributes->name == "href") + $orig_uri = $attributes->textContent; + + if (!isset($orig_uri)) + $orig_uri = $xpath->query("atom:link[@rel='alternate']", $activityobjects)->item(0)->nodeValue; + + if (!isset($orig_uri)) + $orig_uri = $xpath->query("activity:object/atom:id", $activityobjects)->item(0)->nodeValue; + + if (!isset($orig_uri)) + $orig_uri = $xpath->query('atom:id/text()', $activityobjects)->item(0)->nodeValue; + + $orig_body = $xpath->query('atom:content/text()', $activityobjects)->item(0)->nodeValue; + $orig_created = $xpath->query('atom:published/text()', $activityobjects)->item(0)->nodeValue; + + $orig_contact = $contact; + $orig_author = ostatus_fetchauthor($xpath, $activityobjects, $orig_contact); + + $prefix = share_header($orig_author['author-name'], $orig_author['author-link'], $orig_author['author-avatar'], "", $orig_created, $orig_uri); + $item["body"] = $prefix.html2bbcode($orig_body)."[/share]"; + + $item["verb"] = $xpath->query('activity:verb/text()', $activityobjects)->item(0)->nodeValue; + $item["object-type"] = $xpath->query('activity:object-type/text()', $activityobjects)->item(0)->nodeValue; + } + } + + if ($enclosure != "") + $item["body"] .= add_page_info($enclosure); + + if (isset($item["parent-uri"])) { + $r = q("SELECT `id` FROM `item` WHERE `uid` = %d AND `uri` = '%s'", + intval($importer["uid"]), dbesc($item["parent-uri"])); + + if (!$r AND ($related != "")) { + $reply_path = str_replace("/notice/", "/api/statuses/show/", $related).".atom"; + + if ($reply_path != $related) { + logger("Fetching related items for user ".$importer["uid"]." from ".$reply_path, LOGGER_DEBUG); + $reply_xml = fetch_url($reply_path); + + $reply_contact = $contact; + ostatus_import($reply_xml,$importer,$reply_contact); + + // After the import try to fetch the parent item again + $r = q("SELECT `id` FROM `item` WHERE `uid` = %d AND `uri` = '%s'", + intval($importer["uid"]), dbesc($item["parent-uri"])); + } + } + if ($r) { + $item["type"] = 'remote-comment'; + $item["gravity"] = GRAVITY_COMMENT; + } + } else + $item["parent-uri"] = $item["uri"]; + + $r = q("SELECT `id` FROM `item` WHERE `uid` = %d AND `uri` = '%s'", + intval($importer["uid"]), dbesc($item["uri"])); + if (!$r) { + $item_id = item_store($item); + //echo $xml; + //print_r($item); + //echo $item_id." ".$item["parent-uri"]."\n"; + + if ($item_id) + logger("Item was stored with id ".$item_id, LOGGER_DEBUG); + else + logger("Error storing item ".print_r($item, true), LOGGER_DEBUG); + + $item["id"] = $item_id; + + if (!isset($item["parent"]) OR ($item["parent"] == 0)) + $item["parent"] = $item_id; + + if ($mention AND ($item["id"] != 0)) { + $u = q("SELECT `notify-flags`, `language`, `username`, `email` FROM user WHERE uid = %d LIMIT 1", intval($item['uid'])); + + notification(array( + 'type' => NOTIFY_TAGSELF, + 'notify_flags' => $u[0]["notify-flags"], + 'language' => $u[0]["language"], + 'to_name' => $u[0]["username"], + 'to_email' => $u[0]["email"], + 'uid' => $item["uid"], + 'item' => $item, + 'link' => $a->get_baseurl().'/display/'.urlencode(get_item_guid($item["id"])), + 'source_name' => $item["author-name"], + 'source_link' => $item["author-link"], + 'source_photo' => $item["author-avatar"], + 'verb' => ACTIVITY_TAG, + 'otype' => 'item', + 'parent' => $item["parent"] + )); + } + } else { + $item_id = $r[0]["id"]; + logger("Item with uri ".$item["uri"]." for user ".$importer["uid"]." already existed under id ".$r[0]["id"], LOGGER_DEBUG); + } + + if (($conversation != "") AND ($item_id != 0)) { + // Check for duplicates. We really don't need to check the same conversation twice. + if (!in_array($conversation, $conversationlist)) { + complete_conversation($item_id, $conversation); + $conversationlist[] = $conversation; + } + } + } +} diff --git a/include/ostatus_conversation.php b/include/ostatus_conversation.php index 2670d19766..9642ae1dbf 100644 --- a/include/ostatus_conversation.php +++ b/include/ostatus_conversation.php @@ -138,13 +138,13 @@ function complete_conversation($itemid, $conversation_url, $only_add_conversatio if (isset($single_conv->object->id)) $single_conv->id = $single_conv->object->id; - logger("Got id ".$single_conv->id, LOGGER_DEBUG); + //logger("Got id ".$single_conv->id, LOGGER_DEBUG); $plink = ostatus_convert_href($single_conv->id); if (isset($single_conv->object->url)) $plink = ostatus_convert_href($single_conv->object->url); - logger("Got url ".$plink, LOGGER_DEBUG); + //logger("Got url ".$plink, LOGGER_DEBUG); if (@!$single_conv->id) continue; @@ -157,7 +157,8 @@ function complete_conversation($itemid, $conversation_url, $only_add_conversatio dbesc(NETWORK_OSTATUS), dbesc(NETWORK_DFRN)); if ($new_parents) { $parent = $new_parents[0]; - logger('adopting new parent '.$parent["id"].' for '.$itemid); + if ($parent["id"] != $message["parent"]) + logger('Fetch new parent id '.$parent["id"].' for '.$itemid.' Old parent: '.$message["parent"]); } else { $parent["id"] = 0; $parent["uri"] = $first_id; @@ -169,12 +170,12 @@ function complete_conversation($itemid, $conversation_url, $only_add_conversatio else $parent_uri = $parent["uri"]; - $message_exists = q("SELECT `id` FROM `item` WHERE `uid` = %d AND `plink` = '%s' AND `network` IN ('%s','%s') LIMIT 1", + $message_exists = q("SELECT `id`, `parent` FROM `item` WHERE `uid` = %d AND `plink` = '%s' AND `network` IN ('%s','%s') LIMIT 1", intval($message["uid"]), dbesc($plink), dbesc(NETWORK_OSTATUS), dbesc(NETWORK_DFRN)); if (!$message_exists) - $message_exists = q("SELECT `id` FROM `item` WHERE `uid` = %d AND `uri` = '%s' AND `network` IN ('%s','%s') LIMIT 1", + $message_exists = q("SELECT `id`, `parent` FROM `item` WHERE `uid` = %d AND `uri` = '%s' AND `network` IN ('%s','%s') LIMIT 1", intval($message["uid"]), dbesc($single_conv->id), dbesc(NETWORK_OSTATUS), dbesc(NETWORK_DFRN)); @@ -182,14 +183,17 @@ function complete_conversation($itemid, $conversation_url, $only_add_conversatio if ($parent["id"] != 0) { $existing_message = $message_exists[0]; - logger('updating id '.$existing_message["id"].' to parent '.$parent["id"].' uri '.$parent["uri"].' thread '.$parent_uri, LOGGER_DEBUG); + // Normally this shouldn't happen anymore, since we improved the way we fetch OStatus messages + if ($existing_message["parent"] != $parent["id"]) { + logger('updating id '.$existing_message["id"].' to parent '.$parent["id"].' uri '.$parent["uri"].' thread '.$parent_uri, LOGGER_DEBUG); - // This is partly bad, since the entry in the thread table isn't updated - $r = q("UPDATE `item` SET `parent` = %d, `parent-uri` = '%s', `thr-parent` = '%s' WHERE `id` = %d", - intval($parent["id"]), - dbesc($parent["uri"]), - dbesc($parent_uri), - intval($existing_message["id"])); + // This is partly bad, since the entry in the thread table isn't updated + $r = q("UPDATE `item` SET `parent` = %d, `parent-uri` = '%s', `thr-parent` = '%s' WHERE `id` = %d", + intval($parent["id"]), + dbesc($parent["uri"]), + dbesc($parent_uri), + intval($existing_message["id"])); + } } continue; } @@ -274,6 +278,7 @@ function complete_conversation($itemid, $conversation_url, $only_add_conversatio complete_conversation($newitem, $conversation_url, true); // If the newly created item is the top item then change the parent settings of the thread + // This shouldn't happen anymore. This could is supposed to be absolote. if ($newitem AND ($arr["uri"] == $first_id)) { logger('setting new parent to id '.$newitem); $new_parents = q("SELECT `id`, `uri`, `contact-id`, `type`, `verb`, `visible` FROM `item` WHERE `uid` = %d AND `id` = %d LIMIT 1", diff --git a/mod/item.php b/mod/item.php index 184920d4ce..7775d2950e 100644 --- a/mod/item.php +++ b/mod/item.php @@ -1097,8 +1097,30 @@ function handle_tag($a, &$body, &$inform, &$str_tags, $profile_uid, $tag, $netwo //is it a person tag? if(strpos($tag,'@') === 0) { //is it already replaced? - if(strpos($tag,'[url=')) + if(strpos($tag,'[url=')) { + //append tag to str_tags + if(!stristr($str_tags,$tag)) { + if(strlen($str_tags)) + $str_tags .= ','; + $str_tags .= $tag; + } + + // Checking for the alias that is used for OStatus + $pattern = "/@\[url\=(.*?)\](.*?)\[\/url\]/ism"; + if (preg_match($pattern, $tag, $matches)) { + $data = probe_url($matches[1]); + if ($data["alias"] != "") { + $newtag = '@[url='.$data["alias"].']'.$data["name"].'[/url]'; + if(!stristr($str_tags,$newtag)) { + if(strlen($str_tags)) + $str_tags .= ','; + $str_tags .= $newtag; + } + } + } + return $replaced; + } $stat = false; //get the person's name $name = substr($tag,1); From af79cd316c9866bfc5b30c9ca37c1201b7b6fb51 Mon Sep 17 00:00:00 2001 From: Michael Vogel Date: Sun, 7 Jun 2015 23:53:51 +0200 Subject: [PATCH 3/9] Some code beautification. --- include/ostatus.php | 86 ++++++++++++++++++++++----------------------- 1 file changed, 43 insertions(+), 43 deletions(-) diff --git a/include/ostatus.php b/include/ostatus.php index c426a9f10e..6fd5753f5b 100644 --- a/include/ostatus.php +++ b/include/ostatus.php @@ -120,19 +120,25 @@ function ostatus_import($xml,$importer,&$contact) { // Now get the item $item["uri"] = $xpath->query('atom:id/text()', $entry)->item(0)->nodeValue; + + $r = q("SELECT `id` FROM `item` WHERE `uid` = %d AND `uri` = '%s'", + intval($importer["uid"]), dbesc($item["uri"])); + if ($r) { + logger("Item with uri ".$item["uri"]." for user ".$importer["uid"]." already existed under id ".$r[0]["id"], LOGGER_DEBUG); + continue; + } + $item["body"] = html2bbcode($xpath->query('atom:content/text()', $entry)->item(0)->nodeValue); $item["object-type"] = $xpath->query('activity:object-type/text()', $entry)->item(0)->nodeValue; $item["verb"] = $xpath->query('activity:verb/text()', $entry)->item(0)->nodeValue; if ($item["verb"] == ACTIVITY_FOLLOW) { // ignore "Follow" messages - $item = array(); continue; } if ($item["verb"] == ACTIVITY_FAVORITE) { // ignore "Favorite" messages - $item = array(); continue; } @@ -304,50 +310,44 @@ function ostatus_import($xml,$importer,&$contact) { } else $item["parent-uri"] = $item["uri"]; - $r = q("SELECT `id` FROM `item` WHERE `uid` = %d AND `uri` = '%s'", - intval($importer["uid"]), dbesc($item["uri"])); - if (!$r) { - $item_id = item_store($item); - //echo $xml; - //print_r($item); - //echo $item_id." ".$item["parent-uri"]."\n"; + $item_id = item_store($item); + //echo $xml; + //print_r($item); + //echo $item_id." ".$item["parent-uri"]."\n"; - if ($item_id) - logger("Item was stored with id ".$item_id, LOGGER_DEBUG); - else - logger("Error storing item ".print_r($item, true), LOGGER_DEBUG); - - $item["id"] = $item_id; - - if (!isset($item["parent"]) OR ($item["parent"] == 0)) - $item["parent"] = $item_id; - - if ($mention AND ($item["id"] != 0)) { - $u = q("SELECT `notify-flags`, `language`, `username`, `email` FROM user WHERE uid = %d LIMIT 1", intval($item['uid'])); - - notification(array( - 'type' => NOTIFY_TAGSELF, - 'notify_flags' => $u[0]["notify-flags"], - 'language' => $u[0]["language"], - 'to_name' => $u[0]["username"], - 'to_email' => $u[0]["email"], - 'uid' => $item["uid"], - 'item' => $item, - 'link' => $a->get_baseurl().'/display/'.urlencode(get_item_guid($item["id"])), - 'source_name' => $item["author-name"], - 'source_link' => $item["author-link"], - 'source_photo' => $item["author-avatar"], - 'verb' => ACTIVITY_TAG, - 'otype' => 'item', - 'parent' => $item["parent"] - )); - } - } else { - $item_id = $r[0]["id"]; - logger("Item with uri ".$item["uri"]." for user ".$importer["uid"]." already existed under id ".$r[0]["id"], LOGGER_DEBUG); + if (!$item_id) { + logger("Error storing item ".print_r($item, true), LOGGER_DEBUG); + continue; } - if (($conversation != "") AND ($item_id != 0)) { + logger("Item was stored with id ".$item_id, LOGGER_DEBUG); + $item["id"] = $item_id; + + if (!isset($item["parent"]) OR ($item["parent"] == 0)) + $item["parent"] = $item_id; + + if ($mention) { + $u = q("SELECT `notify-flags`, `language`, `username`, `email` FROM user WHERE uid = %d LIMIT 1", intval($item['uid'])); + + notification(array( + 'type' => NOTIFY_TAGSELF, + 'notify_flags' => $u[0]["notify-flags"], + 'language' => $u[0]["language"], + 'to_name' => $u[0]["username"], + 'to_email' => $u[0]["email"], + 'uid' => $item["uid"], + 'item' => $item, + 'link' => $a->get_baseurl().'/display/'.urlencode(get_item_guid($item["id"])), + 'source_name' => $item["author-name"], + 'source_link' => $item["author-link"], + 'source_photo' => $item["author-avatar"], + 'verb' => ACTIVITY_TAG, + 'otype' => 'item', + 'parent' => $item["parent"] + )); + } + + if ($conversation != "") { // Check for duplicates. We really don't need to check the same conversation twice. if (!in_array($conversation, $conversationlist)) { complete_conversation($item_id, $conversation); From b24a46f8895cc0fd41fbe56e0719efbbbd74b7ee Mon Sep 17 00:00:00 2001 From: Michael Vogel Date: Mon, 8 Jun 2015 00:18:44 +0200 Subject: [PATCH 4/9] Adding link information --- include/ostatus.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/include/ostatus.php b/include/ostatus.php index 6fd5753f5b..a6d424f94e 100644 --- a/include/ostatus.php +++ b/include/ostatus.php @@ -128,7 +128,7 @@ function ostatus_import($xml,$importer,&$contact) { continue; } - $item["body"] = html2bbcode($xpath->query('atom:content/text()', $entry)->item(0)->nodeValue); + $item["body"] = add_page_info_to_body(html2bbcode($xpath->query('atom:content/text()', $entry)->item(0)->nodeValue)); $item["object-type"] = $xpath->query('activity:object-type/text()', $entry)->item(0)->nodeValue; $item["verb"] = $xpath->query('activity:verb/text()', $entry)->item(0)->nodeValue; @@ -281,8 +281,8 @@ function ostatus_import($xml,$importer,&$contact) { } } - if ($enclosure != "") - $item["body"] .= add_page_info($enclosure); + //if ($enclosure != "") + // $item["body"] .= add_page_info($enclosure); if (isset($item["parent-uri"])) { $r = q("SELECT `id` FROM `item` WHERE `uid` = %d AND `uri` = '%s'", From fb72871f6601078fc9cc40989a7d03339e44779e Mon Sep 17 00:00:00 2001 From: Michael Vogel Date: Mon, 8 Jun 2015 00:50:02 +0200 Subject: [PATCH 5/9] Bugfix: The user id wasn't fetched correctly. --- include/ostatus.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/include/ostatus.php b/include/ostatus.php index a6d424f94e..a1a3f1f70e 100644 --- a/include/ostatus.php +++ b/include/ostatus.php @@ -5,7 +5,7 @@ require_once('include/enotify.php'); require_once('include/items.php'); require_once('include/ostatus_conversation.php'); -function ostatus_fetchauthor($xpath, $context, &$contact) { +function ostatus_fetchauthor($xpath, $context, $importer, &$contact) { $author = array(); $author["author-link"] = $xpath->evaluate('atom:author/atom:uri/text()', $context)->item(0)->nodeValue; @@ -112,9 +112,9 @@ function ostatus_import($xml,$importer,&$contact) { // fetch the author if ($first_child == "feed") - $author = ostatus_fetchauthor($xpath, $doc->firstChild, $contact); + $author = ostatus_fetchauthor($xpath, $doc->firstChild, $importer, $contact); else - $author = ostatus_fetchauthor($xpath, $entry, $contact); + $author = ostatus_fetchauthor($xpath, $entry, $importer, $contact); $item = array_merge($header, $author); @@ -271,7 +271,7 @@ function ostatus_import($xml,$importer,&$contact) { $orig_created = $xpath->query('atom:published/text()', $activityobjects)->item(0)->nodeValue; $orig_contact = $contact; - $orig_author = ostatus_fetchauthor($xpath, $activityobjects, $orig_contact); + $orig_author = ostatus_fetchauthor($xpath, $activityobjects, $importer, $orig_contact); $prefix = share_header($orig_author['author-name'], $orig_author['author-link'], $orig_author['author-avatar'], "", $orig_created, $orig_uri); $item["body"] = $prefix.html2bbcode($orig_body)."[/share]"; From 419a3ab2d3d4ff64014a2692daade995011235d4 Mon Sep 17 00:00:00 2001 From: Michael Vogel Date: Mon, 8 Jun 2015 01:19:40 +0200 Subject: [PATCH 6/9] Better behaviour when contact wasn't found. --- mod/item.php | 37 ++++++++++++++++++------------------- 1 file changed, 18 insertions(+), 19 deletions(-) diff --git a/mod/item.php b/mod/item.php index 7775d2950e..c3d85568ed 100644 --- a/mod/item.php +++ b/mod/item.php @@ -128,28 +128,27 @@ function item_post(&$a) { intval($parent_item['contact-id']), intval($uid) ); - if(count($r)) { + if(count($r)) $parent_contact = $r[0]; - // If the contact id doesn't fit with the contact, then set the contact to null - $thrparent = q("SELECT `author-link`, `network` FROM `item` WHERE `uri` = '%s' LIMIT 1", dbesc($thr_parent)); - if (count($thrparent) AND ($thrparent[0]["network"] === NETWORK_OSTATUS) - AND (normalise_link($parent_contact["url"]) != normalise_link($thrparent[0]["author-link"]))) { - $parent_contact = null; + // If the contact id doesn't fit with the contact, then set the contact to null + $thrparent = q("SELECT `author-link`, `network` FROM `item` WHERE `uri` = '%s' LIMIT 1", dbesc($thr_parent)); + if (count($thrparent) AND ($thrparent[0]["network"] === NETWORK_OSTATUS) + AND (normalise_link($parent_contact["url"]) != normalise_link($thrparent[0]["author-link"]))) { + $parent_contact = null; - require_once("include/Scrape.php"); - $probed_contact = probe_url($thrparent[0]["author-link"]); - if ($probed_contact["network"] != NETWORK_FEED) { - $parent_contact = $probed_contact; - $parent_contact["nurl"] = normalise_link($probed_contact["url"]); - $parent_contact["thumb"] = $probed_contact["photo"]; - $parent_contact["micro"] = $probed_contact["photo"]; - $parent_contact["addr"] = $probed_contact["addr"]; - } - logger('parent contact: '.print_r($parent_contact, true), LOGGER_DEBUG); - } else - logger('no contact found: '.print_r($thrparent, true), LOGGER_DEBUG); - } + require_once("include/Scrape.php"); + $probed_contact = probe_url($thrparent[0]["author-link"]); + if ($probed_contact["network"] != NETWORK_FEED) { + $parent_contact = $probed_contact; + $parent_contact["nurl"] = normalise_link($probed_contact["url"]); + $parent_contact["thumb"] = $probed_contact["photo"]; + $parent_contact["micro"] = $probed_contact["photo"]; + $parent_contact["addr"] = $probed_contact["addr"]; + } + logger('no contact found: '.print_r($thrparent, true), LOGGER_DEBUG); + } else + logger('parent contact: '.print_r($parent_contact, true), LOGGER_DEBUG); } } From cb0351dba0c1febd38b62329d44dc064f928ba0e Mon Sep 17 00:00:00 2001 From: Michael Vogel Date: Tue, 9 Jun 2015 08:27:04 +0200 Subject: [PATCH 7/9] Send a salmon notification to every mentioned person. --- include/items.php | 8 ++++---- include/notifier.php | 33 +++++++++++++++++++++++++-------- include/ostatus.php | 11 ++++++++--- include/salmon.php | 34 +++++++++++++++++----------------- mod/item.php | 1 + 5 files changed, 55 insertions(+), 32 deletions(-) diff --git a/include/items.php b/include/items.php index 97eb15efcf..0a52d49d8d 100644 --- a/include/items.php +++ b/include/items.php @@ -2228,7 +2228,7 @@ function consume_feed($xml,$importer,&$contact, &$hub, $datedir = 0, $pass = 0) if ($contact['network'] === NETWORK_OSTATUS) { if ($pass < 2) { logger("Consume OStatus messages ", LOGGER_DEBUG); - ostatus_import($xml,$importer,$contact); + ostatus_import($xml,$importer,$contact, $hub); } return; } @@ -4406,9 +4406,9 @@ function atom_entry($item,$type,$author,$owner,$comment = false,$cid = 0) { $tags = item_getfeedtags($item); if(count($tags)) { - foreach($tags as $t) { - $o .= '' . "\r\n"; - } + foreach($tags as $t) + if (($type != 'html') OR ($t[0] != "@")) + $o .= '' . "\r\n"; } //$o .= ''."\r\n"; diff --git a/include/notifier.php b/include/notifier.php index dc4e1a2394..18d0aead8e 100644 --- a/include/notifier.php +++ b/include/notifier.php @@ -2,6 +2,7 @@ require_once("boot.php"); require_once('include/queue_fn.php'); require_once('include/html2plain.php'); +require_once("include/Scrape.php"); /* * This file was at one time responsible for doing all deliveries, but this caused @@ -295,9 +296,9 @@ function notifier_run(&$argv, &$argc){ $conversant_str = dbesc($parent['contact-id']); $recipients = array($parent['contact-id']); - if (!$item['private'] AND $item['wall'] AND - (strlen($item['allow_cid'].$item['allow_gid']. - $item['deny_cid'].$item['deny_gid']) == 0)) + if (!$target_item['private'] AND $target_item['wall'] AND + (strlen($target_item['allow_cid'].$target_item['allow_gid']. + $target_item['deny_cid'].$target_item['deny_gid']) == 0)) $push_notify = true; if ($parent['network'] == NETWORK_OSTATUS) { @@ -305,15 +306,28 @@ function notifier_run(&$argv, &$argc){ $push_notify = true; + // Send a salmon notification to every person we mentioned in the post + $arr = explode(',',$target_item['tag']); + foreach($arr as $x) { + logger('Checking tag '.$x, LOGGER_DEBUG); + $matches = null; + if(preg_match('/@\[url=([^\]]*)\]/',$x,$matches)) { + $probed_contact = probe_url($matches[1]); + if ($probed_contact["notify"] != "") { + logger('scrape data for slapper: '.print_r($probed_contact, true)); + $url_recipients[$probed_contact["notify"]] = $probed_contact["notify"]; + } + } + } + +/* // Check if the recipient isn't in your contact list, try to slap it // Not sure if it is working or not. $r = q("SELECT `url` FROM `contact` WHERE `id` = %d", $parent['contact-id']); if (count($r)) { - $url_recipients = array(); $thrparent = q("SELECT `author-link` FROM `item` WHERE `uri` = '%s'", dbesc($target_item["thr-parent"])); if (count($thrparent) AND (normalise_link($r[0]["url"]) != normalise_link($thrparent[0]["author-link"]))) { - require_once("include/Scrape.php"); $probed_contact = probe_url($thrparent[0]["author-link"]); if ($probed_contact["notify"] != "") { logger('scrape data for slapper: '.print_r($probed_contact, true)); @@ -321,7 +335,9 @@ function notifier_run(&$argv, &$argc){ } } } - logger("url_recipients".print_r($url_recipients,true)); +*/ + if (count($url_recipients)) + logger("url_recipients ".print_r($url_recipients,true)); } } else { $followup = false; @@ -372,7 +388,8 @@ function notifier_run(&$argv, &$argc){ } } - logger('notifier: url_recipients' . print_r($url_recipients,true)); + if (count($url_recipients)) + logger('notifier: url_recipients ' . print_r($url_recipients,true)); $conversants = array_unique($conversants); @@ -911,7 +928,7 @@ function notifier_run(&$argv, &$argc){ // send additional slaps to mentioned remote tags (@foo@example.com) - if($slap && count($url_recipients) && ($followup || $top_level) && $public_message && (! $expire)) { + if($slap && count($url_recipients) && ($followup || $top_level) && ($public_message || $push_notify) && (! $expire)) { if(! get_config('system','dfrn_only')) { foreach($url_recipients as $url) { if($url) { diff --git a/include/ostatus.php b/include/ostatus.php index a1a3f1f70e..41499a2c3f 100644 --- a/include/ostatus.php +++ b/include/ostatus.php @@ -59,7 +59,10 @@ function ostatus_fetchauthor($xpath, $context, $importer, &$contact) { return($author); } -function ostatus_import($xml,$importer,&$contact) { +function ostatus_import($xml,$importer,&$contact, &$hub) { + + // To-Do: + // Hub $a = get_app(); @@ -69,7 +72,7 @@ function ostatus_import($xml,$importer,&$contact) { return; $doc = new DOMDocument(); - $doc->loadXML($xml); + @$doc->loadXML($xml); $xpath = new DomXPath($doc); $xpath->registerNamespace('atom', "http://www.w3.org/2005/Atom"); @@ -103,6 +106,8 @@ function ostatus_import($xml,$importer,&$contact) { $item_id = 0; // Reverse the order of the entries + $entrylist = array(); + foreach ($entries AS $entry) $entrylist[] = $entry; @@ -296,7 +301,7 @@ function ostatus_import($xml,$importer,&$contact) { $reply_xml = fetch_url($reply_path); $reply_contact = $contact; - ostatus_import($reply_xml,$importer,$reply_contact); + ostatus_import($reply_xml,$importer,$reply_contact, $reply_hub); // After the import try to fetch the parent item again $r = q("SELECT `id` FROM `item` WHERE `uid` = %d AND `uri` = '%s'", diff --git a/include/salmon.php b/include/salmon.php index 3d525f51ad..7574374907 100644 --- a/include/salmon.php +++ b/include/salmon.php @@ -7,7 +7,7 @@ require_once('include/crypto.php'); function get_salmon_key($uri,$keyhash) { $ret = array(); - logger('Fetching salmon key'); + logger('Fetching salmon key for '.$uri); $arr = lrdd($uri); @@ -44,10 +44,10 @@ function get_salmon_key($uri,$keyhash) { if(count($ret) == 1) { // We only found one one key so we don't care if the hash matches. - // If it's the wrong key we'll find out soon enough because - // message verification will fail. This also covers some older + // If it's the wrong key we'll find out soon enough because + // message verification will fail. This also covers some older // software which don't supply a keyhash. As long as they only - // have one key we'll be right. + // have one key we'll be right. return $ret[0]; } @@ -62,20 +62,20 @@ function get_salmon_key($uri,$keyhash) { return ''; } - - + + function slapper($owner,$url,$slap) { - logger('slapper called. Data: ' . $slap); + logger('slapper called for '.$url.'. Data: ' . $slap); - // does contact have a salmon endpoint? + // does contact have a salmon endpoint? if(! strlen($url)) return; if(! $owner['sprvkey']) { - logger(sprintf("slapper: user '%s' (%d) does not have a salmon private key. Send failed.", + logger(sprintf("user '%s' (%d) does not have a salmon private key. Send failed.", $owner['username'],$owner['uid'])); return; } @@ -96,7 +96,7 @@ $namespaces = <<< EOT EOT; $slap = str_replace('',$namespaces,$slap); - + // create a magic envelope $data = base64url_encode($slap); @@ -125,7 +125,7 @@ EOT; '$signature' => $signature )); - // slap them + // slap them post_url($url,$salmon, array( 'Content-type: application/magic-envelope+xml', 'Content-length: ' . strlen($salmon) @@ -138,7 +138,7 @@ EOT; if($return_code > 299) { - logger('slapper: compliant salmon failed. Falling back to status.net hack2'); + logger('compliant salmon failed. Falling back to status.net hack2'); // Entirely likely that their salmon implementation is // non-compliant. Let's try once more, this time only signing @@ -152,7 +152,7 @@ EOT; '$signature' => $signature2 )); - // slap them + // slap them post_url($url,$salmon, array( 'Content-type: application/magic-envelope+xml', 'Content-length: ' . strlen($salmon) @@ -162,11 +162,11 @@ EOT; if($return_code > 299) { - logger('slapper: compliant salmon failed. Falling back to status.net hack3'); + logger('compliant salmon failed. Falling back to status.net hack3'); // Entirely likely that their salmon implementation is // non-compliant. Let's try once more, this time only signing - // the data, without the precomputed blob + // the data, without the precomputed blob $salmon = replace_macros($salmon_tpl,array( '$data' => $data, @@ -176,7 +176,7 @@ EOT; '$signature' => $signature3 )); - // slap them + // slap them post_url($url,$salmon, array( 'Content-type: application/magic-envelope+xml', 'Content-length: ' . strlen($salmon) @@ -184,7 +184,7 @@ EOT; $return_code = $a->get_curl_code(); } } - logger('slapper returned ' . $return_code); + logger('slapper for '.$url.' returned ' . $return_code); if(! $return_code) return(-1); if(($return_code == 503) && (stristr($a->get_curl_headers(),'retry-after'))) diff --git a/mod/item.php b/mod/item.php index c3d85568ed..a5f483b352 100644 --- a/mod/item.php +++ b/mod/item.php @@ -24,6 +24,7 @@ require_once('include/files.php'); require_once('include/threads.php'); require_once('include/text.php'); require_once('include/items.php'); +require_once('include/Scrape.php'); function item_post(&$a) { From 81b609562e2a5d0fef876653a6933581b35003e9 Mon Sep 17 00:00:00 2001 From: Michael Vogel Date: Tue, 9 Jun 2015 23:53:53 +0200 Subject: [PATCH 8/9] Fetch the hub adress while parsing OStatus messages. --- include/ostatus.php | 9 +++++++++ include/ostatus_conversation.php | 2 +- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/include/ostatus.php b/include/ostatus.php index 41499a2c3f..f57b148172 100644 --- a/include/ostatus.php +++ b/include/ostatus.php @@ -84,6 +84,15 @@ function ostatus_import($xml,$importer,&$contact, &$hub) { $xpath->registerNamespace('ostatus', "http://ostatus.org/schema/1.0"); $xpath->registerNamespace('statusnet', "http://status.net/schema/api/1/"); + $gub = ""; + $hub_attributes = $xpath->query("/atom:feed/atom:link[@rel='hub']")->item(0)->attributes; + if (is_object($hub_attributes)) + foreach($hub_attributes AS $hub_attribute) + if ($hub_attribute->name == "href") { + $hub = $hub_attribute->textContent; + logger("Found hub ".$hub, LOGGER_DEBUG); + } + $header = array(); $header["uid"] = $importer["uid"]; $header["network"] = NETWORK_OSTATUS; diff --git a/include/ostatus_conversation.php b/include/ostatus_conversation.php index 9642ae1dbf..f897a058a3 100644 --- a/include/ostatus_conversation.php +++ b/include/ostatus_conversation.php @@ -246,7 +246,7 @@ function complete_conversation($itemid, $conversation_url, $only_add_conversatio $arr["author-name"] = $arr["owner-name"]; $arr["author-link"] = $actor; $arr["author-avatar"] = $single_conv->actor->image->url; - $arr["body"] = html2bbcode($single_conv->content); + $arr["body"] = add_page_info_to_body(html2bbcode($single_conv->content)); if (isset($single_conv->status_net->notice_info->source)) $arr["app"] = strip_tags($single_conv->status_net->notice_info->source); From f1fe38d5c7479bf03d9c8d56955445e985488472 Mon Sep 17 00:00:00 2001 From: Michael Vogel Date: Wed, 10 Jun 2015 08:36:51 +0200 Subject: [PATCH 9/9] Just two to-dos added --- include/notifier.php | 1 + include/ostatus_conversation.php | 3 +++ 2 files changed, 4 insertions(+) diff --git a/include/notifier.php b/include/notifier.php index 18d0aead8e..a0fd713c20 100644 --- a/include/notifier.php +++ b/include/notifier.php @@ -307,6 +307,7 @@ function notifier_run(&$argv, &$argc){ $push_notify = true; // Send a salmon notification to every person we mentioned in the post + // To-Do: Send a Salmon to every Friendica user in that thread $arr = explode(',',$target_item['tag']); foreach($arr as $x) { logger('Checking tag '.$x, LOGGER_DEBUG); diff --git a/include/ostatus_conversation.php b/include/ostatus_conversation.php index f897a058a3..cbf0163b7c 100644 --- a/include/ostatus_conversation.php +++ b/include/ostatus_conversation.php @@ -152,6 +152,9 @@ function complete_conversation($itemid, $conversation_url, $only_add_conversatio if ($first_id == "") { $first_id = $single_conv->id; + // To-Do: + // Only fetch a new parent if the new one doesn't have parents + // It can happen that OStatus servers have incomplete threads. $new_parents = q("SELECT `id`, `uri`, `contact-id`, `type`, `verb`, `visible` FROM `item` WHERE `uid` = %d AND `uri` = '%s' AND `network` IN ('%s','%s') LIMIT 1", intval($message["uid"]), dbesc($first_id), dbesc(NETWORK_OSTATUS), dbesc(NETWORK_DFRN));