X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=src%2FProtocol%2FOStatus.php;h=2cc815c3238ffb075ceb45ed050496a5a2af91a5;hb=32f70abf9a7913df1ddb28b9745eb37941d09d80;hp=0635be87d1c9a83191d80ac0bed7d349b06ed577;hpb=f810733478c5c70b3f208cd9b07e7a115db0d73c;p=friendica.git diff --git a/src/Protocol/OStatus.php b/src/Protocol/OStatus.php index 0635be87d1..2cc815c323 100644 --- a/src/Protocol/OStatus.php +++ b/src/Protocol/OStatus.php @@ -36,6 +36,7 @@ use Friendica\Model\Contact; use Friendica\Model\Conversation; use Friendica\Model\Item; use Friendica\Model\ItemURI; +use Friendica\Model\Post; use Friendica\Model\Tag; use Friendica\Model\User; use Friendica\Network\Probe; @@ -481,7 +482,7 @@ class OStatus Logger::log("Favorite ".$orig_uri." ".print_r($item, true)); $item["verb"] = Activity::LIKE; - $item["parent-uri"] = $orig_uri; + $item["thr-parent"] = $orig_uri; $item["gravity"] = GRAVITY_ACTIVITY; $item["object-type"] = Activity\ObjectType::NOTE; } @@ -494,7 +495,7 @@ class OStatus self::processPost($xpath, $entry, $item, $importer); if ($initialize && (count(self::$itemlist) > 0)) { - if (self::$itemlist[0]['uri'] == self::$itemlist[0]['parent-uri']) { + if (self::$itemlist[0]['uri'] == self::$itemlist[0]['thr-parent']) { // We will import it everytime, when it is started by our contacts $valid = Contact::isSharingByURL(self::$itemlist[0]['author-link'], self::$itemlist[0]['uid']); @@ -521,11 +522,7 @@ class OStatus } } } else { - // But we will only import complete threads - $valid = Item::exists(['uid' => $importer["uid"], 'uri' => self::$itemlist[0]['parent-uri']]); - if ($valid) { - Logger::log("Item with uri ".self::$itemlist[0]["uri"]." belongs to parent ".self::$itemlist[0]['parent-uri']." of user ".$importer["uid"].". It will be imported.", Logger::DEBUG); - } + $valid = true; } if ($valid) { @@ -620,7 +617,7 @@ class OStatus if (is_object($inreplyto->item(0))) { foreach ($inreplyto->item(0)->attributes as $attributes) { if ($attributes->name == "ref") { - $item["parent-uri"] = $attributes->textContent; + $item["thr-parent"] = $attributes->textContent; } if ($attributes->name == "href") { $related = $attributes->textContent; @@ -701,16 +698,16 @@ class OStatus self::fetchConversation($item['conversation-href'], $item['conversation-uri']); } - if (isset($item["parent-uri"])) { - if (!Item::exists(['uid' => $importer["uid"], 'uri' => $item['parent-uri']])) { + if (isset($item["thr-parent"])) { + if (!Item::exists(['uid' => $importer["uid"], 'uri' => $item['thr-parent']])) { if ($related != '') { - self::fetchRelated($related, $item["parent-uri"], $importer); + self::fetchRelated($related, $item["thr-parent"], $importer); } } else { Logger::log('Reply with URI '.$item["uri"].' already existed for user '.$importer["uid"].'.', Logger::DEBUG); } } else { - $item["parent-uri"] = $item["uri"]; + $item["thr-parent"] = $item["uri"]; $item["gravity"] = GRAVITY_PARENT; } @@ -738,7 +735,7 @@ class OStatus self::$conv_list[$conversation] = true; - $curlResult = DI::httpRequest()->get($conversation, false, ['accept_content' => 'application/atom+xml, text/html']); + $curlResult = DI::httpRequest()->get($conversation, ['accept_content' => 'application/atom+xml, text/html']); if (!$curlResult->isSuccess()) { return; @@ -931,7 +928,7 @@ class OStatus } $stored = false; - $curlResult = DI::httpRequest()->get($related, false, ['accept_content' => 'application/atom+xml, text/html']); + $curlResult = DI::httpRequest()->get($related, ['accept_content' => 'application/atom+xml, text/html']); if (!$curlResult->isSuccess()) { return; @@ -1073,7 +1070,7 @@ class OStatus if (is_object($inreplyto->item(0))) { foreach ($inreplyto->item(0)->attributes as $attributes) { if ($attributes->name == "ref") { - $item["parent-uri"] = $attributes->textContent; + $item["thr-parent"] = $attributes->textContent; } } } @@ -1118,21 +1115,15 @@ class OStatus if ($filetype == 'image') { $link_data['add_body'] .= "\n[img]".$attribute['href'].'[/img]'; } else { - if (!empty($item["attach"])) { - $item["attach"] .= ','; - } else { - $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]'; + Post\Media::insert(['uri-id' => $item['uri-id'], 'type' => Post\Media::DOCUMENT, + 'url' => $attribute['href'], 'mimetype' => $attribute['type'], + 'size' => $attribute['length'] ?? null, 'description' => $attribute['title'] ?? null]); } break; case "related": if ($item["object-type"] != Activity\ObjectType::BOOKMARK) { - if (!isset($item["parent-uri"])) { - $item["parent-uri"] = $attribute['href']; + if (!isset($item["thr-parent"])) { + $item["thr-parent"] = $attribute['href']; } $link_data['related'] = $attribute['href']; } else { @@ -1390,25 +1381,19 @@ class OStatus } } - $arr = explode('[/attach],', $item['attach']); - if (count($arr)) { - foreach ($arr as $r) { - $matches = false; - $cnt = preg_match('|\[attach\]href=\"(.*?)\" length=\"(.*?)\" type=\"(.*?)\" title=\"(.*?)\"|', $r, $matches); - if ($cnt) { - $attributes = ["rel" => "enclosure", - "href" => $matches[1], - "type" => $matches[3]]; + foreach (Post\Media::getByURIId($item['uri-id'], [Post\Media::DOCUMENT, Post\Media::TORRENT, Post\Media::UNKNOWN]) as $attachment) { + $attributes = ['rel' => 'enclosure', + 'href' => $attachment['url'], + 'type' => $attachment['mimetype']]; - if (intval($matches[2])) { - $attributes["length"] = intval($matches[2]); - } - if (trim($matches[4]) != "") { - $attributes["title"] = trim($matches[4]); - } - XML::addElement($doc, $root, "link", "", $attributes); - } + if (!empty($attachment['size'])) { + $attributes['length'] = intval($attachment['size']); } + if (!empty($attachment['description'])) { + $attributes['title'] = $attachment['description']; + } + + XML::addElement($doc, $root, 'link', '', $attributes); } } @@ -1945,9 +1930,8 @@ class OStatus if ($item['gravity'] != GRAVITY_PARENT) { $parent = Item::selectFirst(['guid', 'author-link', 'owner-link'], ['id' => $item['parent']]); - $parent_item = (($item['thr-parent']) ? $item['thr-parent'] : $item['parent-uri']); - $thrparent = Item::selectFirst(['guid', 'author-link', 'owner-link', 'plink'], ['uid' => $owner["uid"], 'uri' => $parent_item]); + $thrparent = Item::selectFirst(['guid', 'author-link', 'owner-link', 'plink'], ['uid' => $owner["uid"], 'uri' => $item['thr-parent']]); if (DBA::isResult($thrparent)) { $mentioned[$thrparent["author-link"]] = $thrparent["author-link"]; @@ -1960,7 +1944,7 @@ class OStatus } $attributes = [ - "ref" => $parent_item, + "ref" => $item['thr-parent'], "href" => $parent_plink]; XML::addElement($doc, $entry, "thr:in-reply-to", "", $attributes); @@ -1971,7 +1955,7 @@ class OStatus } if (intval($item['parent']) > 0) { - $conversation_href = $conversation_uri = str_replace('/objects/', '/context/', $item['parent-uri']); + $conversation_href = $conversation_uri = str_replace('/objects/', '/context/', $item['thr-parent']); if (isset($parent_item)) { $conversation = DBA::selectFirst('conversation', ['conversation-uri', 'conversation-href'], ['item-uri' => $parent_item]);