]> git.mxchange.org Git - friendica.git/blobdiff - src/Protocol/Feed.php
Merge branch 'contact-media' of github.com:annando/friendica into contact-media
[friendica.git] / src / Protocol / Feed.php
index 42f470e23f1ba01f2b33bd48c592ccb8658201c7..680e8803bdeae2ab59949bdd7bf63de012f3a6e8 100644 (file)
@@ -42,6 +42,7 @@ use Friendica\Util\ParseUrl;
 use Friendica\Util\Proxy;
 use Friendica\Util\Strings;
 use Friendica\Util\XML;
+use GuzzleHttp\Exception\TransferException;
 
 /**
  * This class contain functions to import feeds (RSS/RDF/Atom)
@@ -297,7 +298,11 @@ class Feed
 
                        $orig_plink = $item["plink"];
 
-                       $item["plink"] = DI::httpRequest()->finalUrl($item["plink"]);
+                       try {
+                               $item["plink"] = DI::httpClient()->finalUrl($item["plink"]);
+                       } catch (TransferException $exception) {
+                               Logger::notice('Item URL couldn\'t get expanded', ['url' => $item["plink"], 'exception' => $exception]);
+                       }
 
                        $item["title"] = XML::getFirstNodeValue($xpath, 'atom:title/text()', $entry);
 
@@ -601,7 +606,9 @@ class Feed
                                }
                                $publish_at = date(DateTimeFormat::MYSQL, $publish_time);
 
-                               Post\Delayed::add($posting['item']['uri'], $posting['item'], $posting['notify'], false, $publish_at, $posting['taglist'], $posting['attachments']);
+                               if (Post\Delayed::add($posting['item']['uri'], $posting['item'], $posting['notify'], Post\Delayed::PREPARED, $publish_at, $posting['taglist'], $posting['attachments'])) {
+                                       DI::pConfig()->set($item['uid'], 'system', 'last_publish', $publish_time);
+                               }
                        }
                }
 
@@ -725,7 +732,7 @@ class Feed
 
                if ($contact['rating'] != $priority) {
                        Logger::notice('Adjusting priority', ['old' => $contact['rating'], 'new' => $priority, 'id' => $contact['id'], 'uid' => $contact['uid'], 'url' => $contact['url']]);
-                       DBA::update('contact', ['rating' => $priority], ['id' => $contact['id']]);
+                       Contact::update(['rating' => $priority], ['id' => $contact['id']]);
                }
        }
 
@@ -878,8 +885,8 @@ class Feed
                        Protocol::OSTATUS, Protocol::DFRN, Protocol::DIASPORA];
 
                if ($filter === 'comments') {
-                       $condition[0] .= " AND `object-type` = ? ";
-                       $condition[] = Activity\ObjectType::COMMENT;
+                       $condition[0] .= " AND `gravity` = ? ";
+                       $condition[] = GRAVITY_COMMENT;
                }
 
                if ($owner['account-type'] != User::ACCOUNT_TYPE_COMMUNITY) {
@@ -958,7 +965,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", Contact::getAvatarUrlForId($owner['id'], Proxy::SIZE_SMALL, $owner['updated']));
+               XML::addElement($doc, $root, "logo", User::getAvatarUrlForId($owner['uid'], Proxy::SIZE_SMALL));
                XML::addElement($doc, $root, "updated", DateTimeFormat::utcNow(DateTimeFormat::ATOM));
 
                $author = self::addAuthor($doc, $owner);
@@ -1107,9 +1114,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::ACTIVITYPUB);
 
                XML::addElement($doc, $entry, "content", $body, ["type" => "html"]);
 
@@ -1139,27 +1146,31 @@ class Feed
                if ($item['gravity'] != GRAVITY_PARENT) {
                        $parent = Post::selectFirst(['guid', 'author-link', 'owner-link'], ['id' => $item['parent']]);
 
-                       $thrparent = Post::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"];
-                               $mentioned[$thrparent["owner-link"]] = $thrparent["owner-link"];
-                               $parent_plink = $thrparent["plink"];
+                               $mentioned[$thrparent['author-link']] = $thrparent['author-link'];
+                               $mentioned[$thrparent['owner-link']]  = $thrparent['owner-link'];
+                               $parent_plink                         = $thrparent['plink'];
+                       } elseif (DBA::isResult($parent)) {
+                               $mentioned[$parent['author-link']] = $parent['author-link'];
+                               $mentioned[$parent['owner-link']]  = $parent['owner-link'];
+                               $parent_plink                      = DI::baseUrl() . '/display/' . $parent['guid'];
                        } else {
-                               $mentioned[$parent["author-link"]] = $parent["author-link"];
-                               $mentioned[$parent["owner-link"]] = $parent["owner-link"];
-                               $parent_plink = DI::baseUrl()."/display/".$parent["guid"];
+                               DI::logger()->notice('Missing parent and thr-parent for child item', ['item' => $item]);
                        }
 
-                       $attributes = [
-                                       "ref" => $item['thr-parent'],
-                                       "href" => $parent_plink];
-                       XML::addElement($doc, $entry, "thr:in-reply-to", "", $attributes);
+                       if (isset($parent_plink)) {
+                               $attributes = [
+                                       'ref'  => $item['thr-parent'],
+                                       'href' => $parent_plink];
+                               XML::addElement($doc, $entry, 'thr:in-reply-to', '', $attributes);
 
-                       $attributes = [
-                                       "rel" => "related",
-                                       "href" => $parent_plink];
-                       XML::addElement($doc, $entry, "link", "", $attributes);
+                               $attributes = [
+                                       'rel'  => 'related',
+                                       'href' => $parent_plink];
+                               XML::addElement($doc, $entry, 'link', '', $attributes);
+                       }
                }
 
                // uri-id isn't present for follow entry pseudo-items
@@ -1170,7 +1181,7 @@ class Feed
 
                foreach ($tags as $tag) {
                        if ($tag['type'] == Tag::HASHTAG) {
-                               XML::addElement($doc, $entry, "category", "", ["term" => $tag['name']]);
+                               XML::addElement($doc, $entry, 'category', '', ['term' => $tag['name']]);
                        }
                }
 
@@ -1186,7 +1197,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::ACTIVITYPUB);
                }
 
                // Fetch information about the post
@@ -1199,7 +1210,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)) {