Issue 3278: Attachments in Reshares should now work
This commit is contained in:
parent
d9451ef969
commit
884c75a350
|
@ -239,6 +239,23 @@ class ostatus {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Read attributes from element
|
||||||
|
*
|
||||||
|
* @param object $element Element object
|
||||||
|
*
|
||||||
|
* @return array attributes
|
||||||
|
*/
|
||||||
|
private static function read_attributes($element) {
|
||||||
|
$attribute = array();
|
||||||
|
|
||||||
|
foreach ($element->attributes AS $attributes) {
|
||||||
|
$attribute[$attributes->name] = $attributes->textContent;
|
||||||
|
}
|
||||||
|
|
||||||
|
return $attribute;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Imports an XML string containing OStatus elements
|
* @brief Imports an XML string containing OStatus elements
|
||||||
*
|
*
|
||||||
|
@ -252,9 +269,9 @@ class ostatus {
|
||||||
|
|
||||||
logger("Import OStatus message", LOGGER_DEBUG);
|
logger("Import OStatus message", LOGGER_DEBUG);
|
||||||
|
|
||||||
if ($xml == "")
|
if ($xml == "") {
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
//$tempfile = tempnam(get_temppath(), "import");
|
//$tempfile = tempnam(get_temppath(), "import");
|
||||||
//file_put_contents($tempfile, $xml);
|
//file_put_contents($tempfile, $xml);
|
||||||
|
|
||||||
|
@ -273,13 +290,14 @@ class ostatus {
|
||||||
|
|
||||||
$gub = "";
|
$gub = "";
|
||||||
$hub_attributes = $xpath->query("/atom:feed/atom:link[@rel='hub']")->item(0)->attributes;
|
$hub_attributes = $xpath->query("/atom:feed/atom:link[@rel='hub']")->item(0)->attributes;
|
||||||
if (is_object($hub_attributes))
|
if (is_object($hub_attributes)) {
|
||||||
foreach($hub_attributes AS $hub_attribute)
|
foreach ($hub_attributes AS $hub_attribute) {
|
||||||
if ($hub_attribute->name == "href") {
|
if ($hub_attribute->name == "href") {
|
||||||
$hub = $hub_attribute->textContent;
|
$hub = $hub_attribute->textContent;
|
||||||
logger("Found hub ".$hub, LOGGER_DEBUG);
|
logger("Found hub ".$hub, LOGGER_DEBUG);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
$header = array();
|
$header = array();
|
||||||
$header["uid"] = $importer["uid"];
|
$header["uid"] = $importer["uid"];
|
||||||
$header["network"] = NETWORK_OSTATUS;
|
$header["network"] = NETWORK_OSTATUS;
|
||||||
|
@ -292,11 +310,11 @@ class ostatus {
|
||||||
// depending on that, the first node is different
|
// depending on that, the first node is different
|
||||||
$first_child = $doc->firstChild->tagName;
|
$first_child = $doc->firstChild->tagName;
|
||||||
|
|
||||||
if ($first_child == "feed")
|
if ($first_child == "feed") {
|
||||||
$entries = $xpath->query('/atom:feed/atom:entry');
|
$entries = $xpath->query('/atom:feed/atom:entry');
|
||||||
else
|
} else {
|
||||||
$entries = $xpath->query('/atom:entry');
|
$entries = $xpath->query('/atom:entry');
|
||||||
|
}
|
||||||
$conversation = "";
|
$conversation = "";
|
||||||
$conversationlist = array();
|
$conversationlist = array();
|
||||||
$item_id = 0;
|
$item_id = 0;
|
||||||
|
@ -304,25 +322,25 @@ class ostatus {
|
||||||
// Reverse the order of the entries
|
// Reverse the order of the entries
|
||||||
$entrylist = array();
|
$entrylist = array();
|
||||||
|
|
||||||
foreach ($entries AS $entry)
|
foreach ($entries AS $entry) {
|
||||||
$entrylist[] = $entry;
|
$entrylist[] = $entry;
|
||||||
|
}
|
||||||
foreach (array_reverse($entrylist) AS $entry) {
|
foreach (array_reverse($entrylist) AS $entry) {
|
||||||
|
|
||||||
$mention = false;
|
$mention = false;
|
||||||
|
|
||||||
// fetch the author
|
// fetch the author
|
||||||
if ($first_child == "feed")
|
if ($first_child == "feed") {
|
||||||
$author = self::fetchauthor($xpath, $doc->firstChild, $importer, $contact, false);
|
$author = self::fetchauthor($xpath, $doc->firstChild, $importer, $contact, false);
|
||||||
else
|
} else {
|
||||||
$author = self::fetchauthor($xpath, $entry, $importer, $contact, false);
|
$author = self::fetchauthor($xpath, $entry, $importer, $contact, false);
|
||||||
|
}
|
||||||
$value = $xpath->evaluate('atom:author/poco:preferredUsername/text()', $context)->item(0)->nodeValue;
|
$value = $xpath->evaluate('atom:author/poco:preferredUsername/text()', $context)->item(0)->nodeValue;
|
||||||
if ($value != "")
|
if ($value != "") {
|
||||||
$nickname = $value;
|
$nickname = $value;
|
||||||
else
|
} else {
|
||||||
$nickname = $author["author-name"];
|
$nickname = $author["author-name"];
|
||||||
|
}
|
||||||
$item = array_merge($header, $author);
|
$item = array_merge($header, $author);
|
||||||
|
|
||||||
// Now get the item
|
// Now get the item
|
||||||
|
@ -330,7 +348,7 @@ class ostatus {
|
||||||
|
|
||||||
$r = q("SELECT `id` FROM `item` WHERE `uid` = %d AND `uri` = '%s'",
|
$r = q("SELECT `id` FROM `item` WHERE `uid` = %d AND `uri` = '%s'",
|
||||||
intval($importer["uid"]), dbesc($item["uri"]));
|
intval($importer["uid"]), dbesc($item["uri"]));
|
||||||
if ($r) {
|
if (dbm::is_result($r)) {
|
||||||
logger("Item with uri ".$item["uri"]." for user ".$importer["uid"]." already existed under id ".$r[0]["id"], LOGGER_DEBUG);
|
logger("Item with uri ".$item["uri"]." for user ".$importer["uid"]." already existed under id ".$r[0]["id"], LOGGER_DEBUG);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
@ -341,9 +359,9 @@ class ostatus {
|
||||||
if (($item["object-type"] == ACTIVITY_OBJ_BOOKMARK) OR ($item["object-type"] == ACTIVITY_OBJ_EVENT)) {
|
if (($item["object-type"] == ACTIVITY_OBJ_BOOKMARK) OR ($item["object-type"] == ACTIVITY_OBJ_EVENT)) {
|
||||||
$item["title"] = $xpath->query('atom:title/text()', $entry)->item(0)->nodeValue;
|
$item["title"] = $xpath->query('atom:title/text()', $entry)->item(0)->nodeValue;
|
||||||
$item["body"] = $xpath->query('atom:summary/text()', $entry)->item(0)->nodeValue;
|
$item["body"] = $xpath->query('atom:summary/text()', $entry)->item(0)->nodeValue;
|
||||||
} elseif ($item["object-type"] == ACTIVITY_OBJ_QUESTION)
|
} elseif ($item["object-type"] == ACTIVITY_OBJ_QUESTION) {
|
||||||
$item["title"] = $xpath->query('atom:title/text()', $entry)->item(0)->nodeValue;
|
$item["title"] = $xpath->query('atom:title/text()', $entry)->item(0)->nodeValue;
|
||||||
|
}
|
||||||
$item["object"] = $xml;
|
$item["object"] = $xml;
|
||||||
$item["verb"] = $xpath->query('activity:verb/text()', $entry)->item(0)->nodeValue;
|
$item["verb"] = $xpath->query('activity:verb/text()', $entry)->item(0)->nodeValue;
|
||||||
|
|
||||||
|
@ -387,9 +405,9 @@ class ostatus {
|
||||||
}
|
}
|
||||||
|
|
||||||
// http://activitystrea.ms/schema/1.0/rsvp-yes
|
// http://activitystrea.ms/schema/1.0/rsvp-yes
|
||||||
if (!in_array($item["verb"], array(ACTIVITY_POST, ACTIVITY_LIKE, ACTIVITY_SHARE)))
|
if (!in_array($item["verb"], array(ACTIVITY_POST, ACTIVITY_LIKE, ACTIVITY_SHARE))) {
|
||||||
logger("Unhandled verb ".$item["verb"]." ".print_r($item, true));
|
logger("Unhandled verb ".$item["verb"]." ".print_r($item, true));
|
||||||
|
}
|
||||||
$item["created"] = $xpath->query('atom:published/text()', $entry)->item(0)->nodeValue;
|
$item["created"] = $xpath->query('atom:published/text()', $entry)->item(0)->nodeValue;
|
||||||
$item["edited"] = $xpath->query('atom:updated/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;
|
$conversation = $xpath->query('ostatus:conversation/text()', $entry)->item(0)->nodeValue;
|
||||||
|
@ -399,92 +417,89 @@ class ostatus {
|
||||||
$inreplyto = $xpath->query('thr:in-reply-to', $entry);
|
$inreplyto = $xpath->query('thr:in-reply-to', $entry);
|
||||||
if (is_object($inreplyto->item(0))) {
|
if (is_object($inreplyto->item(0))) {
|
||||||
foreach ($inreplyto->item(0)->attributes AS $attributes) {
|
foreach ($inreplyto->item(0)->attributes AS $attributes) {
|
||||||
if ($attributes->name == "ref")
|
if ($attributes->name == "ref") {
|
||||||
$item["parent-uri"] = $attributes->textContent;
|
$item["parent-uri"] = $attributes->textContent;
|
||||||
if ($attributes->name == "href")
|
}
|
||||||
|
if ($attributes->name == "href") {
|
||||||
$related = $attributes->textContent;
|
$related = $attributes->textContent;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
$georsspoint = $xpath->query('georss:point', $entry);
|
$georsspoint = $xpath->query('georss:point', $entry);
|
||||||
if ($georsspoint)
|
if ($georsspoint) {
|
||||||
$item["coord"] = $georsspoint->item(0)->nodeValue;
|
$item["coord"] = $georsspoint->item(0)->nodeValue;
|
||||||
|
}
|
||||||
$categories = $xpath->query('atom:category', $entry);
|
$categories = $xpath->query('atom:category', $entry);
|
||||||
if ($categories) {
|
if ($categories) {
|
||||||
foreach ($categories AS $category) {
|
foreach ($categories AS $category) {
|
||||||
foreach($category->attributes AS $attributes)
|
foreach ($category->attributes AS $attributes) {
|
||||||
if ($attributes->name == "term") {
|
if ($attributes->name == "term") {
|
||||||
$term = $attributes->textContent;
|
$term = $attributes->textContent;
|
||||||
if(strlen($item["tag"]))
|
if(strlen($item["tag"])) {
|
||||||
$item["tag"] .= ',';
|
$item["tag"] .= ',';
|
||||||
|
}
|
||||||
$item["tag"] .= "#[url=".App::get_baseurl()."/search?tag=".$term."]".$term."[/url]";
|
$item["tag"] .= "#[url=".App::get_baseurl()."/search?tag=".$term."]".$term."[/url]";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
$self = "";
|
$self = "";
|
||||||
$enclosure = "";
|
$enclosure = "";
|
||||||
|
|
||||||
$links = $xpath->query('atom:link', $entry);
|
$links = $xpath->query('atom:link', $entry);
|
||||||
if ($links) {
|
if ($links) {
|
||||||
$rel = "";
|
|
||||||
$href = "";
|
|
||||||
$type = "";
|
|
||||||
$length = "0";
|
|
||||||
$title = "";
|
|
||||||
foreach ($links AS $link) {
|
foreach ($links AS $link) {
|
||||||
foreach($link->attributes AS $attributes) {
|
$attribute = self::read_attributes($link);
|
||||||
if ($attributes->name == "href")
|
|
||||||
$href = $attributes->textContent;
|
if (($attribute['rel'] != "") AND ($attribute['href'] != "")) {
|
||||||
if ($attributes->name == "rel")
|
switch ($attribute['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":
|
case "alternate":
|
||||||
$item["plink"] = $href;
|
$item["plink"] = $attribute['href'];
|
||||||
if (($item["object-type"] == ACTIVITY_OBJ_QUESTION) OR
|
if (($item["object-type"] == ACTIVITY_OBJ_QUESTION) OR
|
||||||
($item["object-type"] == ACTIVITY_OBJ_EVENT))
|
($item["object-type"] == ACTIVITY_OBJ_EVENT)) {
|
||||||
$item["body"] .= add_page_info($href);
|
$item["body"] .= add_page_info($attribute['href']);
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
case "ostatus:conversation":
|
case "ostatus:conversation":
|
||||||
$conversation = $href;
|
$conversation = $attribute['href'];
|
||||||
break;
|
break;
|
||||||
case "enclosure":
|
case "enclosure":
|
||||||
$enclosure = $href;
|
$enclosure = $attribute['href'];
|
||||||
if(strlen($item["attach"]))
|
if (strlen($item["attach"])) {
|
||||||
$item["attach"] .= ',';
|
$item["attach"] .= ',';
|
||||||
|
}
|
||||||
$item["attach"] .= '[attach]href="'.$href.'" length="'.$length.'" type="'.$type.'" title="'.$title.'"[/attach]';
|
if (!isset($attribute['length'])) {
|
||||||
|
$attribute['length'] = "0";
|
||||||
|
}
|
||||||
|
$item["attach"] .= '[attach]href="'.$attribute['href'].'" length="'.$attribute['length'].'" type="'.$attribute['type'].'" title="'.$attribute['title'].'"[/attach]';
|
||||||
break;
|
break;
|
||||||
case "related":
|
case "related":
|
||||||
if ($item["object-type"] != ACTIVITY_OBJ_BOOKMARK) {
|
if ($item["object-type"] != ACTIVITY_OBJ_BOOKMARK) {
|
||||||
if (!isset($item["parent-uri"]))
|
if (!isset($item["parent-uri"])) {
|
||||||
$item["parent-uri"] = $href;
|
$item["parent-uri"] = $attribute['href'];
|
||||||
|
}
|
||||||
if ($related == "")
|
if ($related == "") {
|
||||||
$related = $href;
|
$related = $attribute['href'];
|
||||||
} else
|
}
|
||||||
$item["body"] .= add_page_info($href);
|
} else {
|
||||||
|
$item["body"] .= add_page_info($attribute['href']);
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
case "self":
|
case "self":
|
||||||
$self = $href;
|
$self = $attribute['href'];
|
||||||
break;
|
break;
|
||||||
case "mentioned":
|
case "mentioned":
|
||||||
// Notification check
|
// Notification check
|
||||||
if ($importer["nurl"] == normalise_link($href))
|
if ($importer["nurl"] == normalise_link($attribute['href'])) {
|
||||||
$mention = true;
|
$mention = true;
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
$local_id = "";
|
$local_id = "";
|
||||||
$repeat_of = "";
|
$repeat_of = "";
|
||||||
|
@ -492,14 +507,17 @@ class ostatus {
|
||||||
$notice_info = $xpath->query('statusnet:notice_info', $entry);
|
$notice_info = $xpath->query('statusnet:notice_info', $entry);
|
||||||
if ($notice_info AND ($notice_info->length > 0)) {
|
if ($notice_info AND ($notice_info->length > 0)) {
|
||||||
foreach ($notice_info->item(0)->attributes AS $attributes) {
|
foreach ($notice_info->item(0)->attributes AS $attributes) {
|
||||||
if ($attributes->name == "source")
|
if ($attributes->name == "source") {
|
||||||
$item["app"] = strip_tags($attributes->textContent);
|
$item["app"] = strip_tags($attributes->textContent);
|
||||||
if ($attributes->name == "local_id")
|
}
|
||||||
|
if ($attributes->name == "local_id") {
|
||||||
$local_id = $attributes->textContent;
|
$local_id = $attributes->textContent;
|
||||||
if ($attributes->name == "repeat_of")
|
}
|
||||||
|
if ($attributes->name == "repeat_of") {
|
||||||
$repeat_of = $attributes->textContent;
|
$repeat_of = $attributes->textContent;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Is it a repeated post?
|
// Is it a repeated post?
|
||||||
if (($repeat_of != "") OR ($item["verb"] == ACTIVITY_SHARE)) {
|
if (($repeat_of != "") OR ($item["verb"] == ACTIVITY_SHARE)) {
|
||||||
|
@ -508,25 +526,27 @@ class ostatus {
|
||||||
if (is_object($activityobjects)) {
|
if (is_object($activityobjects)) {
|
||||||
|
|
||||||
$orig_uri = $xpath->query("activity:object/atom:id", $activityobjects)->item(0)->nodeValue;
|
$orig_uri = $xpath->query("activity:object/atom:id", $activityobjects)->item(0)->nodeValue;
|
||||||
if (!isset($orig_uri))
|
if (!isset($orig_uri)) {
|
||||||
$orig_uri = $xpath->query('atom:id/text()', $activityobjects)->item(0)->nodeValue;
|
$orig_uri = $xpath->query('atom:id/text()', $activityobjects)->item(0)->nodeValue;
|
||||||
|
}
|
||||||
$orig_links = $xpath->query("activity:object/atom:link[@rel='alternate']", $activityobjects);
|
$orig_links = $xpath->query("activity:object/atom:link[@rel='alternate']", $activityobjects);
|
||||||
if ($orig_links AND ($orig_links->length > 0))
|
if ($orig_links AND ($orig_links->length > 0)) {
|
||||||
foreach($orig_links->item(0)->attributes AS $attributes)
|
foreach ($orig_links->item(0)->attributes AS $attributes) {
|
||||||
if ($attributes->name == "href")
|
if ($attributes->name == "href") {
|
||||||
$orig_link = $attributes->textContent;
|
$orig_link = $attributes->textContent;
|
||||||
|
}
|
||||||
if (!isset($orig_link))
|
}
|
||||||
|
}
|
||||||
|
if (!isset($orig_link)) {
|
||||||
$orig_link = $xpath->query("atom:link[@rel='alternate']", $activityobjects)->item(0)->nodeValue;
|
$orig_link = $xpath->query("atom:link[@rel='alternate']", $activityobjects)->item(0)->nodeValue;
|
||||||
|
}
|
||||||
if (!isset($orig_link))
|
if (!isset($orig_link)) {
|
||||||
$orig_link = self::convert_href($orig_uri);
|
$orig_link = self::convert_href($orig_uri);
|
||||||
|
}
|
||||||
$orig_body = $xpath->query('activity:object/atom:content/text()', $activityobjects)->item(0)->nodeValue;
|
$orig_body = $xpath->query('activity:object/atom:content/text()', $activityobjects)->item(0)->nodeValue;
|
||||||
if (!isset($orig_body))
|
if (!isset($orig_body)) {
|
||||||
$orig_body = $xpath->query('atom:content/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_created = $xpath->query('atom:published/text()', $activityobjects)->item(0)->nodeValue;
|
||||||
$orig_edited = $xpath->query('atom:updated/text()', $activityobjects)->item(0)->nodeValue;
|
$orig_edited = $xpath->query('atom:updated/text()', $activityobjects)->item(0)->nodeValue;
|
||||||
|
|
||||||
|
@ -550,9 +570,27 @@ class ostatus {
|
||||||
$item["verb"] = $xpath->query('activity:verb/text()', $activityobjects)->item(0)->nodeValue;
|
$item["verb"] = $xpath->query('activity:verb/text()', $activityobjects)->item(0)->nodeValue;
|
||||||
|
|
||||||
$item["object-type"] = $xpath->query('activity:object/activity:object-type/text()', $activityobjects)->item(0)->nodeValue;
|
$item["object-type"] = $xpath->query('activity:object/activity:object-type/text()', $activityobjects)->item(0)->nodeValue;
|
||||||
if (!isset($item["object-type"]))
|
if (!isset($item["object-type"])) {
|
||||||
$item["object-type"] = $xpath->query('activity:object-type/text()', $activityobjects)->item(0)->nodeValue;
|
$item["object-type"] = $xpath->query('activity:object-type/text()', $activityobjects)->item(0)->nodeValue;
|
||||||
}
|
}
|
||||||
|
// Quickfix to read attachments
|
||||||
|
$enclosures = $xpath->query("atom:link[@rel='alternate']", $activityobjects);
|
||||||
|
if ($enclosures) {
|
||||||
|
foreach ($enclosures AS $link) {
|
||||||
|
$attribute = self::read_attributes($link);
|
||||||
|
if ($href != "") {
|
||||||
|
$enclosure = $attribute['href'];
|
||||||
|
if (strlen($item["attach"])) {
|
||||||
|
$item["attach"] .= ',';
|
||||||
|
}
|
||||||
|
if (!isset($attribute['length'])) {
|
||||||
|
$attribute['length'] = "0";
|
||||||
|
}
|
||||||
|
$item["attach"] .= '[attach]href="'.$attribute['href'].'" length="'.$attribute['length'].'" type="'.$attribute['type'].'" title="'.$attribute['title'].'"[/attach]';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//if ($enclosure != "")
|
//if ($enclosure != "")
|
||||||
|
@ -579,13 +617,13 @@ class ostatus {
|
||||||
intval($importer["uid"]), dbesc($item["parent-uri"]));
|
intval($importer["uid"]), dbesc($item["parent-uri"]));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if ($r) {
|
if (dbm::is_result($r)) {
|
||||||
$item["type"] = 'remote-comment';
|
$item["type"] = 'remote-comment';
|
||||||
$item["gravity"] = GRAVITY_COMMENT;
|
$item["gravity"] = GRAVITY_COMMENT;
|
||||||
}
|
}
|
||||||
} else
|
} else {
|
||||||
$item["parent-uri"] = $item["uri"];
|
$item["parent-uri"] = $item["uri"];
|
||||||
|
}
|
||||||
$item_id = self::completion($conversation, $importer["uid"], $item, $self);
|
$item_id = self::completion($conversation, $importer["uid"], $item, $self);
|
||||||
|
|
||||||
if (!$item_id) {
|
if (!$item_id) {
|
||||||
|
|
Loading…
Reference in a new issue