X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=src%2FProtocol%2FOStatus.php;h=d6a2f2dad1ce3b8cb8bb180087ba2a377afa3c7f;hb=5cf71baf551bf209e62cf13b16173bddcd76a0fc;hp=5e34636b215f8900b84f964723e0fa068da84da7;hpb=4faf08c0643d3e6bbe2a0a77be2ff8c1dbea4d5c;p=friendica.git diff --git a/src/Protocol/OStatus.php b/src/Protocol/OStatus.php index 5e34636b21..d6a2f2dad1 100644 --- a/src/Protocol/OStatus.php +++ b/src/Protocol/OStatus.php @@ -385,12 +385,14 @@ class OStatus } } - $header = []; - $header['uid'] = $importer['uid']; - $header['network'] = Protocol::OSTATUS; - $header['wall'] = 0; - $header['origin'] = 0; - $header['gravity'] = Item::GRAVITY_COMMENT; + // Initial header elements + $header = [ + 'uid' => $importer['uid'], + 'network' => Protocol::OSTATUS, + 'wall' => 0, + 'origin' => 0, + 'gravity' => Item::GRAVITY_COMMENT, + ]; if (!is_object($doc->firstChild) || empty($doc->firstChild->tagName)) { return false; @@ -496,7 +498,7 @@ class OStatus $orig_uri = $xpath->query('activity:object/atom:id', $entry)->item(0)->nodeValue; Logger::notice('Favorite', ['uri' => $orig_uri, 'item' => $item]); - $item['verb'] = Activity::LIKE; + $item['body'] = $item['verb'] = Activity::LIKE; $item['thr-parent'] = $orig_uri; $item['gravity'] = Item::GRAVITY_ACTIVITY; $item['object-type'] = Activity\ObjectType::NOTE; @@ -976,44 +978,6 @@ class OStatus } } - /** - * Cleans the body of a post if it contains picture links - * - * @param string $body The body - * @param integer $uriId - * @return string The cleaned body - * @throws \Friendica\Network\HTTPException\InternalServerErrorException - */ - public static function formatPicturePost(string $body, int $uriid): string - { - $siteinfo = BBCode::getAttachedData($body); - - if (($siteinfo['type'] == 'photo') && (!empty($siteinfo['preview']) || !empty($siteinfo['image']))) { - if (isset($siteinfo['preview'])) { - $preview = $siteinfo['preview']; - } else { - $preview = $siteinfo['image']; - } - - // Is it a remote picture? Then make a smaller preview here - $preview = Post\Link::getByLink($uriid, $preview, Proxy::SIZE_SMALL); - - // Is it a local picture? Then make it smaller here - $preview = str_replace(['-0.jpg', '-0.png'], ['-2.jpg', '-2.png'], $preview); - $preview = str_replace(['-1.jpg', '-1.png'], ['-2.jpg', '-2.png'], $preview); - - if (isset($siteinfo['url'])) { - $url = $siteinfo['url']; - } else { - $url = $siteinfo['image']; - } - - $body = trim($siteinfo['text']) . ' [url]' . $url . "[/url]\n[img]" . $preview . '[/img]'; - } - - return $body; - } - /** * Adds the header elements to the XML document * @@ -1140,51 +1104,7 @@ class OStatus */ public static function getAttachment(DOMDocument $doc, DOMElement $root, array $item) { - $siteinfo = BBCode::getAttachedData($item['body']); - - switch ($siteinfo['type']) { - case 'photo': - if (!empty($siteinfo['image'])) { - $imgdata = Images::getInfoFromURLCached($siteinfo['image']); - if ($imgdata) { - $attributes = [ - 'rel' => 'enclosure', - 'href' => $siteinfo['image'], - 'type' => $imgdata['mime'], - 'length' => intval($imgdata['size']), - ]; - XML::addElement($doc, $root, 'link', '', $attributes); - } - } - break; - - case 'video': - $attributes = [ - 'rel' => 'enclosure', - 'href' => $siteinfo['url'], - 'type' => 'text/html; charset=UTF-8', - 'length' => '0', - 'title' => ($siteinfo['title'] ?? '') ?: $siteinfo['url'], - ]; - XML::addElement($doc, $root, 'link', '', $attributes); - break; - } - - if (!DI::config()->get('system', 'ostatus_not_attach_preview') && ($siteinfo['type'] != 'photo') && isset($siteinfo['image'])) { - $imgdata = Images::getInfoFromURLCached($siteinfo['image']); - if ($imgdata) { - $attributes = [ - 'rel' => 'enclosure', - 'href' => $siteinfo['image'], - 'type' => $imgdata['mime'], - 'length' => intval($imgdata['size']), - ]; - - XML::addElement($doc, $root, 'link', '', $attributes); - } - } - - foreach (Post\Media::getByURIId($item['uri-id'], [Post\Media::DOCUMENT, Post\Media::TORRENT]) as $attachment) { + foreach (Post\Media::getByURIId($item['uri-id'], [Post\Media::AUDIO, Post\Media::IMAGE, Post\Media::VIDEO, Post\Media::DOCUMENT, Post\Media::TORRENT]) as $attachment) { $attributes = ['rel' => 'enclosure', 'href' => $attachment['url'], 'type' => $attachment['mimetype']]; @@ -1477,8 +1397,8 @@ class OStatus } $item['uri'] = $item['parent-uri'] = $item['thr-parent'] - = 'tag:' . DI::baseUrl()->getHostname(). - ','.date('Y-m-d').':'.$action.':'.$owner['uid']. + = 'tag:' . DI::baseUrl()->getHost() . + ','.date('Y-m-d').':'.$action.':'.$owner['uid']. ':person:'.$connect_id.':'.$item['created']; $item['body'] = sprintf($message, $owner['nick'], $contact['nick']); @@ -1550,6 +1470,8 @@ class OStatus $entry = $doc->createElement('entry'); if ($owner['contact-type'] == Contact::TYPE_COMMUNITY) { + $entry->setAttribute('xmlns:activity', ActivityNamespace::ACTIVITY); + $contact = Contact::getByURL($item['author-link']) ?: $owner; $contact['nickname'] = $contact['nickname'] ?? $contact['nick']; $author = self::addAuthor($doc, $contact, false); @@ -1597,7 +1519,7 @@ class OStatus XML::addElement($doc, $entry, 'title', html_entity_decode($title, ENT_QUOTES, 'UTF-8')); $body = Post\Media::addAttachmentsToBody($item['uri-id'], DI::contentItem()->addSharedPost($item)); - $body = self::formatPicturePost($body, $item['uri-id']); + $body = Post\Media::addHTMLLinkToBody($item['uri-id'], $body); if (!empty($item['title'])) { $body = '[b]' . $item['title'] . "[/b]\n\n" . $body; @@ -1791,7 +1713,7 @@ class OStatus $previous_created = $last_update; - // Don't cache when the last item was posted less then 15 minutes ago (Cache duration) + // Don't cache when the last item was posted less than 15 minutes ago (Cache duration) if ((time() - strtotime($owner['last-item'])) < 15*60) { $result = DI::cache()->get($cachekey); if (!$nocache && !is_null($result)) {