xml::add_element($doc, $entry, "thr:in-reply-to", "", $attributes);
}
+ // Add conversation data. This is used for OStatus
+ $conversation_href = App::get_baseurl()."/display/".$owner["nick"]."/".$item["parent"];
+ $conversation_uri = $conversation_href;
+
+ if (isset($parent_item)) {
+ $r = dba::fetch_first("SELECT `conversation-uri`, `conversation-href` FROM `conversation` WHERE `item-uri` = ?", $item['parent-uri']);
+ if (dbm::is_result($r)) {
+ if ($r['conversation-uri'] != '') {
+ $conversation_uri = $r['conversation-uri'];
+ }
+ if ($r['conversation-href'] != '') {
+ $conversation_href = $r['conversation-href'];
+ }
+ }
+ }
+
+ $attributes = array(
+ "href" => $conversation_href,
+ "ref" => $conversation_uri);
+
+ xml::add_element($doc, $entry, "ostatus:conversation", $conversation_uri, $attributes);
+
xml::add_element($doc, $entry, "id", $item["uri"]);
xml::add_element($doc, $entry, "title", $item["title"]);
* @param array $importer Record of the importer user mixed with contact of the content
* @todo Add type-hints
*/
- private static function process_entry($header, $xpath, $entry, $importer) {
+ private static function process_entry($header, $xpath, $entry, $importer, $xml) {
logger("Processing entries");
$item = $header;
+ $item["protocol"] = PROTOCOL_DFRN;
+
+ $item["source"] = $xml;
+
// Get the uri
$item["uri"] = $xpath->query("atom:id/text()", $entry)->item(0)->nodeValue;
self::parse_links($links, $item);
}
+ $item['conversation-uri'] = $xpath->query('ostatus:conversation/text()', $entry)->item(0)->nodeValue;
+
+ $conv = $xpath->query('ostatus:conversation', $entry);
+ if (is_object($conv->item(0))) {
+ foreach ($conv->item(0)->attributes AS $attributes) {
+ if ($attributes->name == "ref") {
+ $item['conversation-uri'] = $attributes->textContent;
+ }
+ if ($attributes->name == "href") {
+ $item['conversation-href'] = $attributes->textContent;
+ }
+ }
+ }
+
// Is it a reply or a top level posting?
$item["parent-uri"] = $item["uri"];
if (!$sort_by_date) {
$entries = $xpath->query("/atom:feed/atom:entry");
foreach ($entries AS $entry) {
- self::process_entry($header, $xpath, $entry, $importer);
+ self::process_entry($header, $xpath, $entry, $importer, $xml);
}
} else {
$newentries = array();
ksort($newentries);
foreach ($newentries AS $entry) {
- self::process_entry($header, $xpath, $entry, $importer);
+ self::process_entry($header, $xpath, $entry, $importer, $xml);
}
}
logger("Import done for user " . $importer["uid"] . " from contact " . $importer["id"], LOGGER_DEBUG);
if (in_array($arr['network'], array(NETWORK_DFRN, NETWORK_DIASPORA, NETWORK_OSTATUS))) {
$conversation = array('item-uri' => $arr['uri'], 'received' => dbm::date());
+
if (isset($arr['thr-parent'])) {
if ($arr['thr-parent'] != $arr['uri']) {
$conversation['reply-to-uri'] = $arr['thr-parent'];
}
}
+
if (isset($arr['conversation-uri'])) {
$conversation['conversation-uri'] = $arr['conversation-uri'];
- unset($arr['conversation-uri']);
}
- if ($arr['network'] == NETWORK_DFRN) {
- $conversation['protocol'] = PROTOCOL_DFRN;
- } elseif ($arr['network'] == NETWORK_DIASPORA) {
- $conversation['protocol'] = PROTOCOL_DIASPORA;
+ if (isset($arr['conversation-href'])) {
+ $conversation['conversation-href'] = $arr['conversation-href'];
}
if (isset($arr['protocol'])) {
$conversation['protocol'] = $arr['protocol'];
- unset($arr['protocol']);
- }
- if (isset($arr['object'])) {
- $conversation['source'] = $arr['object'];
- if (in_array($arr['network'], array(NETWORK_DIASPORA, NETWORK_OSTATUS))) {
- unset($arr['object']);
- }
}
+
if (isset($arr['source'])) {
$conversation['source'] = $arr['source'];
- unset($arr['source']);
}
+
dba::insert('conversation', $conversation);
}
+ unset($arr['conversation-uri']);
+ unset($arr['conversation-href']);
+ unset($arr['protocol']);
+ unset($arr['source']);
+
if ($arr['parent-uri'] === $arr['uri']) {
$parent_id = 0;
$parent_deleted = 0;
$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;
+ $item['conversation-uri'] = $conversation;
+
+ $conv = $xpath->query('ostatus:conversation', $entry);
+ if (is_object($conv->item(0))) {
+ foreach ($conv->item(0)->attributes AS $attributes) {
+ if ($attributes->name == "ref") {
+ $item['conversation-uri'] = $attributes->textContent;
+ }
+ if ($attributes->name == "href") {
+ $item['conversation-href'] = $attributes->textContent;
+ }
+ }
+ }
$related = "";
break;
case "ostatus:conversation":
$conversation = $attribute['href'];
+ $item['conversation-href'] = $conversation;
+ if (!isset($item['conversation-uri'])) {
+ $item['conversation-uri'] = $item['conversation-href'];
+ }
break;
case "enclosure":
$enclosure = $attribute['href'];
$arr["author-avatar"] = $arr["owner-avatar"];
$arr["body"] = add_page_info_to_body(html2bbcode($single_conv->content));
+ if (isset($single_conv->status_net->conversation)) {
+ $arr['conversation-uri'] = $single_conv->status_net->conversation;
+ }
+
if (isset($single_conv->status_net->notice_info->source))
$arr["app"] = strip_tags($single_conv->status_net->notice_info->source);
elseif (isset($single_conv->statusnet->notice_info->source))
$root->setAttribute("xmlns:poco", NAMESPACE_POCO);
$root->setAttribute("xmlns:ostatus", NAMESPACE_OSTATUS);
$root->setAttribute("xmlns:statusnet", NAMESPACE_STATUSNET);
+ $root->setAttribute("xmlns:mastodon", NAMESPACE_MASTODON);
$attributes = array("uri" => "https://friendi.ca", "version" => FRIENDICA_VERSION."-".DB_UPDATE_VERSION);
xml::add_element($doc, $root, "generator", FRIENDICA_PLATFORM, $attributes);
*/
private function add_author($doc, $owner) {
- $r = q("SELECT `homepage` FROM `profile` WHERE `uid` = %d AND `is-default` LIMIT 1", intval($owner["uid"]));
+ $r = q("SELECT `homepage`, `publish` FROM `profile` WHERE `uid` = %d AND `is-default` LIMIT 1", intval($owner["uid"]));
if ($r)
$profile = $r[0];
$author = $doc->createElement("author");
+ xml::add_element($doc, $author, "id", $owner["url"]);
xml::add_element($doc, $author, "activity:object-type", ACTIVITY_OBJ_PERSON);
xml::add_element($doc, $author, "uri", $owner["url"]);
- xml::add_element($doc, $author, "name", $owner["name"]);
+ xml::add_element($doc, $author, "name", $owner["nick"]);
+ xml::add_element($doc, $author, "email", $owner["addr"]);
xml::add_element($doc, $author, "summary", bbcode($owner["about"], false, false, 7));
$attributes = array("rel" => "alternate", "type" => "text/html", "href" => $owner["url"]);
xml::add_element($doc, $author, "statusnet:profile_info", "", array("local_id" => $owner["uid"]));
}
+ if ($profile["publish"]) {
+ xml::add_element($doc, $author, "mastodon:scope", "public");
+ }
return $author;
}
self::entry_content($doc, $as_object, $repeated_item, $owner, "", "", false);
$author = self::add_author($doc, $contact);
- $as_object->appendChild($author);
+ $as_object->appendChild($author);
$as_object2 = $doc->createElement("activity:object");
$entry->setAttribute("xmlns:poco", NAMESPACE_POCO);
$entry->setAttribute("xmlns:ostatus", NAMESPACE_OSTATUS);
$entry->setAttribute("xmlns:statusnet", NAMESPACE_STATUSNET);
+ $entry->setAttribute("xmlns:mastodon", NAMESPACE_MASTODON);
$author = self::add_author($doc, $owner);
$entry->appendChild($author);
$parent = q("SELECT `guid`, `author-link`, `owner-link` FROM `item` WHERE `id` = %d", intval($item["parent"]));
$parent_item = (($item['thr-parent']) ? $item['thr-parent'] : $item['parent-uri']);
+ $thrparent = q("SELECT `guid`, `author-link`, `owner-link`, `plink` FROM `item` WHERE `uid` = %d AND `uri` = '%s'",
+ intval($owner["uid"]),
+ dbesc($parent_item));
+ if ($thrparent) {
+ $mentioned[$thrparent[0]["author-link"]] = $thrparent[0]["author-link"];
+ $mentioned[$thrparent[0]["owner-link"]] = $thrparent[0]["owner-link"];
+ $parent_plink = $thrparent[0]["plink"];
+ } else {
+ $mentioned[$parent[0]["author-link"]] = $parent[0]["author-link"];
+ $mentioned[$parent[0]["owner-link"]] = $parent[0]["owner-link"];
+ $parent_plink = App::get_baseurl()."/display/".$parent[0]["guid"];
+ }
+
$attributes = array(
"ref" => $parent_item,
- "type" => "text/html",
- "href" => App::get_baseurl()."/display/".$parent[0]["guid"]);
+ "href" => $parent_plink);
xml::add_element($doc, $entry, "thr:in-reply-to", "", $attributes);
$attributes = array(
"rel" => "related",
- "href" => App::get_baseurl()."/display/".$parent[0]["guid"]);
+ "href" => $parent_plink);
xml::add_element($doc, $entry, "link", "", $attributes);
+ }
- $mentioned[$parent[0]["author-link"]] = $parent[0]["author-link"];
- $mentioned[$parent[0]["owner-link"]] = $parent[0]["owner-link"];
+ if (intval($item["parent"]) > 0) {
+ $conversation_href = App::get_baseurl()."/display/".$owner["nick"]."/".$item["parent"];
+ $conversation_uri = $conversation_href;
- $thrparent = q("SELECT `guid`, `author-link`, `owner-link` FROM `item` WHERE `uid` = %d AND `uri` = '%s'",
- intval($owner["uid"]),
- dbesc($parent_item));
- if ($thrparent) {
- $mentioned[$thrparent[0]["author-link"]] = $thrparent[0]["author-link"];
- $mentioned[$thrparent[0]["owner-link"]] = $thrparent[0]["owner-link"];
+ if (isset($parent_item)) {
+ $r = dba::fetch_first("SELECT `conversation-uri`, `conversation-href` FROM `conversation` WHERE `item-uri` = ?", $parent_item);
+ if (dbm::is_result($r)) {
+ if ($r['conversation-uri'] != '') {
+ $conversation_uri = $r['conversation-uri'];
+ }
+ if ($r['conversation-href'] != '') {
+ $conversation_href = $r['conversation-href'];
+ }
+ }
}
- }
- if (intval($item["parent"]) > 0) {
- $conversation = App::get_baseurl()."/display/".$owner["nick"]."/".$item["parent"];
- xml::add_element($doc, $entry, "link", "", array("rel" => "ostatus:conversation", "href" => $conversation));
+ xml::add_element($doc, $entry, "link", "", array("rel" => "ostatus:conversation", "href" => $conversation_href));
$attributes = array(
- "href" => $conversation,
+ "href" => $conversation_href,
"local_id" => $item["parent"],
- "ref" => $conversation);
+ "ref" => $conversation_uri);
- xml::add_element($doc, $entry, "ostatus:conversation", $conversation, $attributes);
+ xml::add_element($doc, $entry, "ostatus:conversation", $conversation_uri, $attributes);
}
$tags = item_getfeedtags($item);
xml::add_element($doc, $entry, "link", "", array("rel" => "mentioned",
"ostatus:object-type" => "http://activitystrea.ms/schema/1.0/collection",
"href" => "http://activityschema.org/collection/public"));
+ xml::add_element($doc, $entry, "mastodon:scope", "public");
}
if(count($tags))