]> git.mxchange.org Git - friendica.git/blobdiff - src/Protocol/Feed.php
Fix "Undefined index: reply-to-id"
[friendica.git] / src / Protocol / Feed.php
index fa568b4c3c14dcf6ecec652c45a64f5b6c346495..c088876d93f4834d10d908a95d446c30619404e9 100644 (file)
@@ -1,6 +1,6 @@
 <?php
 /**
- * @copyright Copyright (C) 2020, Friendica
+ * @copyright Copyright (C) 2010-2021, the Friendica project
  *
  * @license GNU AGPL version 3 or any later version
  *
@@ -29,11 +29,9 @@ use Friendica\Content\Text\HTML;
 use Friendica\Core\Cache\Duration;
 use Friendica\Core\Logger;
 use Friendica\Core\Protocol;
-use Friendica\Core\Worker;
 use Friendica\Database\DBA;
 use Friendica\DI;
 use Friendica\Model\Contact;
-use Friendica\Model\Conversation;
 use Friendica\Model\Item;
 use Friendica\Model\Post;
 use Friendica\Model\Tag;
@@ -41,6 +39,7 @@ use Friendica\Model\User;
 use Friendica\Util\DateTimeFormat;
 use Friendica\Util\Network;
 use Friendica\Util\ParseUrl;
+use Friendica\Util\Proxy;
 use Friendica\Util\Strings;
 use Friendica\Util\XML;
 
@@ -49,65 +48,6 @@ use Friendica\Util\XML;
  */
 class Feed
 {
-       /**
-        * consume - process atom feed and update anything/everything we might need to update
-        *
-        * $xml = the (atom) feed to consume - RSS isn't as fully supported but may work for simple feeds.
-        *
-        * $importer = the contact_record (joined to user_record) of the local user who owns this relationship.
-        *             It is this person's stuff that is going to be updated.
-        * $contact =  the person who is sending us stuff. If not set, we MAY be processing a "follow" activity
-        *             from an external network and MAY create an appropriate contact record. Otherwise, we MUST
-        *             have a contact record.
-        * $hub = should we find a hub declation in the feed, pass it back to our calling process, who might (or
-        *        might not) try and subscribe to it.
-        * $datedir sorts in reverse order
-        * $pass - by default ($pass = 0) we cannot guarantee that a parent item has been
-        *      imported prior to its children being seen in the stream unless we are certain
-        *      of how the feed is arranged/ordered.
-        * With $pass = 1, we only pull parent items out of the stream.
-        * With $pass = 2, we only pull children (comments/likes).
-        *
-        * So running this twice, first with pass 1 and then with pass 2 will do the right
-        * thing regardless of feed ordering. This won't be adequate in a fully-threaded
-        * model where comments can have sub-threads. That would require some massive sorting
-        * to get all the feed items into a mostly linear ordering, and might still require
-        * recursion.
-        *
-        * @param       $xml
-        * @param array $importer
-        * @param array $contact
-        * @param       $hub
-        * @throws ImagickException
-        * @throws \Friendica\Network\HTTPException\InternalServerErrorException
-        */
-       public static function consume($xml, array $importer, array $contact, &$hub)
-       {
-               if ($contact['network'] === Protocol::OSTATUS) {
-                       Logger::info('Consume OStatus messages');
-                       OStatus::import($xml, $importer, $contact, $hub);
-
-                       return;
-               }
-
-               if ($contact['network'] === Protocol::FEED) {
-                       Logger::info('Consume feeds');
-                       self::import($xml, $importer, $contact);
-
-                       return;
-               }
-
-               if ($contact['network'] === Protocol::DFRN) {
-                       Logger::info('Consume DFRN messages');
-                       $dfrn_importer = DFRN::getImporter($contact['id'], $importer['uid']);
-                       if (!empty($dfrn_importer)) {
-                               Logger::info('Now import the DFRN feed');
-                               DFRN::import($xml, $dfrn_importer, true, Conversation::PARCEL_LEGACY_DFRN);
-                               return;
-                       }
-               }
-       }
-
        /**
         * Read a RSS/RDF/Atom feed and create an item entry for it
         *
@@ -294,6 +234,7 @@ class Feed
                $header["private"] = Item::PUBLIC;
                $header["verb"] = Activity::POST;
                $header["object-type"] = Activity\ObjectType::NOTE;
+               $header["post-type"] = Item::PT_ARTICLE;
 
                $header["contact-id"] = $contact["id"] ?? 0;
 
@@ -400,7 +341,7 @@ class Feed
                        if (!$dryRun) {
                                $condition = ["`uid` = ? AND `uri` = ? AND `network` IN (?, ?)",
                                        $importer["uid"], $item["uri"], Protocol::FEED, Protocol::DFRN];
-                               $previous = Item::selectFirst(['id', 'created'], $condition);
+                               $previous = Post::selectFirst(['id', 'created'], $condition);
                                if (DBA::isResult($previous)) {
                                        // Use the creation date when the post had been stored. It can happen this date changes in the feed.
                                        $creation_dates[] = $previous['created'];
@@ -543,7 +484,7 @@ class Feed
                                        $item["body"] = trim($item["title"]);
                                }
 
-                               $data = ParseUrl::getSiteinfoCached($item['plink'], true);
+                               $data = ParseUrl::getSiteinfoCached($item['plink']);
                                if (!empty($data['text']) && !empty($data['title']) && (mb_strlen($item['body']) < mb_strlen($data['text']))) {
                                        // When the fetched page info text is longer than the body, we do try to enhance the body
                                        if (!empty($item['body']) && (strpos($data['title'], $item['body']) === false) && (strpos($data['text'], $item['body']) === false)) {
@@ -598,6 +539,10 @@ class Feed
                                }
                        }
 
+                       if (empty($item['title'])) {
+                               $item['post-type'] = Item::PT_NOTE;
+                       }
+
                        Logger::info('Stored feed', ['item' => $item]);
 
                        $notify = Item::isRemoteSelf($contact, $item);
@@ -615,7 +560,7 @@ class Feed
                        }
 
                        $condition = ['uid' => $item['uid'], 'uri' => $item['uri']];
-                       if (!Item::exists($condition) && !Post\Delayed::exists($item["uri"], $item['uid'])) {
+                       if (!Post::exists($condition) && !Post\Delayed::exists($item["uri"], $item['uid'])) {
                                if (!$notify) {
                                        Post\Delayed::publish($item, $notify, $taglist, $attachments);
                                } else {
@@ -623,7 +568,7 @@ class Feed
                                                'taglist' => $taglist, 'attachments' => $attachments];
                                }
                        } else {
-                               Logger::info('Post already crated or exists in the delayed posts queue', ['uid' => $item['uid'], 'uri' => $item["uri"]]);
+                               Logger::info('Post already created or exists in the delayed posts queue', ['uid' => $item['uid'], 'uri' => $item["uri"]]);
                        }
                }
 
@@ -656,8 +601,7 @@ class Feed
                                }
                                $publish_at = date(DateTimeFormat::MYSQL, $publish_time);
 
-                               Post\Delayed::add($publish_at, $posting['item'], $posting['notify'], $posting['taglist'], $posting['attachments']);
-                               DI::pConfig()->set($item['uid'], 'system', 'last_publish', $next_publish);
+                               Post\Delayed::add($posting['item']['uri'], $posting['item'], $posting['notify'], false, $publish_at, $posting['taglist'], $posting['attachments']);
                        }
                }
 
@@ -947,12 +891,12 @@ class Feed
                $params = ['order' => ['received' => true], 'limit' => $max_items];
 
                if ($filter === 'posts') {
-                       $ret = Item::selectThread([], $condition, $params);
+                       $ret = Post::selectThread(Item::DELIVER_FIELDLIST, $condition, $params);
                } else {
-                       $ret = Item::select([], $condition, $params);
+                       $ret = Post::select(Item::DELIVER_FIELDLIST, $condition, $params);
                }
 
-               $items = Item::inArray($ret);
+               $items = Post::toArray($ret);
 
                $doc = new DOMDocument('1.0', 'utf-8');
                $doc->formatOutput = true;
@@ -1014,7 +958,7 @@ class Feed
                XML::addElement($doc, $root, "id", DI::baseUrl() . "/profile/" . $owner["nick"]);
                XML::addElement($doc, $root, "title", $title);
                XML::addElement($doc, $root, "subtitle", sprintf("Updates from %s on %s", $owner["name"], DI::config()->get('config', 'sitename')));
-               XML::addElement($doc, $root, "logo", $owner["photo"]);
+               XML::addElement($doc, $root, "logo", Contact::getAvatarUrlForId($owner['id'], Proxy::SIZE_SMALL, $owner['updated']));
                XML::addElement($doc, $root, "updated", DateTimeFormat::utcNow(DateTimeFormat::ATOM));
 
                $author = self::addAuthor($doc, $owner);
@@ -1101,7 +1045,7 @@ class Feed
 
                $condition = ['uid' => $owner["uid"], 'guid' => $repeated_guid, 'private' => [Item::PUBLIC, Item::UNLISTED],
                        'network' => Protocol::FEDERATED];
-               $repeated_item = Item::selectFirst([], $condition);
+               $repeated_item = Post::selectFirst(Item::DELIVER_FIELDLIST, $condition);
                if (!DBA::isResult($repeated_item)) {
                        return false;
                }
@@ -1163,9 +1107,9 @@ class Feed
                XML::addElement($doc, $entry, "id", $item["uri"]);
                XML::addElement($doc, $entry, "title", html_entity_decode($title, ENT_QUOTES, 'UTF-8'));
 
-               $body = OStatus::formatPicturePost($item['body']);
+               $body = OStatus::formatPicturePost($item['body'], $item['uri-id']);
 
-               $body = BBCode::convert($body, false, BBCode::OSTATUS);
+               $body = BBCode::convertForUriId($item['uri-id'], $body, BBCode::OSTATUS, false);
 
                XML::addElement($doc, $entry, "content", $body, ["type" => "html"]);
 
@@ -1193,9 +1137,9 @@ class Feed
                $mentioned = [];
 
                if ($item['gravity'] != GRAVITY_PARENT) {
-                       $parent = Item::selectFirst(['guid', 'author-link', 'owner-link'], ['id' => $item['parent']]);
+                       $parent = Post::selectFirst(['guid', 'author-link', 'owner-link'], ['id' => $item['parent']]);
 
-                       $thrparent = Item::selectFirst(['guid', 'author-link', 'owner-link', 'plink'], ['uid' => $owner["uid"], 'uri' => $item['thr-parent']]);
+                       $thrparent = Post::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"];
@@ -1242,7 +1186,7 @@ class Feed
        private static function getTitle(array $item)
        {
                if ($item['title'] != '') {
-                       return BBCode::convert($item['title'], false, BBCode::OSTATUS);
+                       return BBCode::convertForUriId($item['uri-id'], $item['title'], BBCode::OSTATUS);
                }
 
                // Fetch information about the post
@@ -1255,7 +1199,7 @@ class Feed
                // Remove the share element before fetching the first line
                $title = trim(preg_replace("/\[share.*?\](.*?)\[\/share\]/ism","\n$1\n",$item['body']));
 
-               $title = HTML::toPlaintext(BBCode::convert($title, false), 0, true)."\n";
+               $title = BBCode::toPlaintext($title)."\n";
                $pos = strpos($title, "\n");
                $trailer = "";
                if (($pos == 0) || ($pos > 100)) {