]> git.mxchange.org Git - friendica.git/blobdiff - src/Protocol/OStatus.php
Merge pull request #8549 from annando/suppress-xml-log
[friendica.git] / src / Protocol / OStatus.php
index f75b60f0d1145b3f49bc6d265e3f6e6ad9a018ac..ccec6d9348885acdcb53780a3c4f95e2da813ab7 100644 (file)
@@ -1,7 +1,24 @@
 <?php
 /**
- * @file src/Protocol/OStatus.php
+ * @copyright Copyright (C) 2020, Friendica
+ *
+ * @license GNU AGPL version 3 or any later version
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program.  If not, see <https://www.gnu.org/licenses/>.
+ *
  */
+
 namespace Friendica\Protocol;
 
 use DOMDocument;
@@ -9,7 +26,6 @@ use DOMXPath;
 use Friendica\Content\Text\BBCode;
 use Friendica\Content\Text\HTML;
 use Friendica\Core\Cache\Duration;
-use Friendica\Core\Config;
 use Friendica\Core\Logger;
 use Friendica\Core\Protocol;
 use Friendica\Database\DBA;
@@ -19,6 +35,8 @@ use Friendica\Model\Contact;
 use Friendica\Model\Conversation;
 use Friendica\Model\GContact;
 use Friendica\Model\Item;
+use Friendica\Model\ItemURI;
+use Friendica\Model\Tag;
 use Friendica\Model\User;
 use Friendica\Network\Probe;
 use Friendica\Util\DateTimeFormat;
@@ -231,7 +249,7 @@ class OStatus
                        $gcid = GContact::update($contact);
 
                        GContact::link($gcid, $contact["uid"], $contact["id"]);
-               } elseif ($contact["network"] != Protocol::DFRN) {
+               } elseif (empty($contact["network"]) || ($contact["network"] != Protocol::DFRN)) {
                        $contact = [];
                }
 
@@ -421,6 +439,7 @@ class OStatus
                        $item = array_merge($header, $author);
 
                        $item["uri"] = XML::getFirstNodeValue($xpath, 'atom:id/text()', $entry);
+                       $item['uri-id'] = ItemURI::insert(['uri' => $item['uri']]);
 
                        $item["verb"] = XML::getFirstNodeValue($xpath, 'activity:verb/text()', $entry);
 
@@ -569,7 +588,7 @@ class OStatus
                        return;
                }
 
-               Item::delete($condition);
+               Item::markForDeletion($condition);
 
                Logger::log('Deleted item with uri '.$item['uri'].' for user '.$item['uid']);
        }
@@ -644,6 +663,9 @@ class OStatus
                                                }
 
                                                $item['tag'] .= '#[url=' . DI::baseUrl() . '/search?tag=' . $term . ']' . $term . '[/url]';
+
+                                               // Store the hashtag
+                                               Tag::store($item['uri-id'], Tag::HASHTAG, $term);
                                        }
                                }
                        }
@@ -687,6 +709,8 @@ class OStatus
                        $item["body"] = add_page_info_to_body($item["body"]);
                }
 
+               Tag::storeFromBody($item['uri-id'], $item['body']);
+
                // Mastodon Content Warning
                if (($item["verb"] == Activity::POST) && $xpath->evaluate('boolean(atom:summary)', $entry)) {
                        $clear_text = XML::getFirstNodeValue($xpath, 'atom:summary/text()', $entry);
@@ -1429,7 +1453,7 @@ class OStatus
         */
        private static function addAuthor(DOMDocument $doc, array $owner, $show_profile = true)
        {
-               $profile = DBA::selectFirst('profile', ['homepage', 'publish'], ['uid' => $owner['uid'], 'is-default' => true]);
+               $profile = DBA::selectFirst('profile', ['homepage', 'publish'], ['uid' => $owner['uid']]);
                $author = $doc->createElement("author");
                XML::addElement($doc, $author, "id", $owner["url"]);
                if ($owner['account-type'] == User::ACCOUNT_TYPE_COMMUNITY) {
@@ -1666,7 +1690,7 @@ class OStatus
 
                $entry = self::entryHeader($doc, $owner, $item, $toplevel);
 
-               $condition = ['uid' => $owner["uid"], 'guid' => $repeated_guid, 'private' => false,
+               $condition = ['uid' => $owner["uid"], 'guid' => $repeated_guid, 'private' => [Item::PUBLIC, Item::UNLISTED],
                        'network' => [Protocol::DFRN, Protocol::DIASPORA, Protocol::OSTATUS]];
                $repeated_item = Item::selectFirst([], $condition);
                if (!DBA::isResult($repeated_item)) {
@@ -1811,7 +1835,7 @@ class OStatus
        {
                $item["id"] = $item["parent"] = 0;
                $item["created"] = $item["edited"] = date("c");
-               $item["private"] = true;
+               $item["private"] = Item::PRIVATE;
 
                $contact = Probe::uri($item['follow']);
 
@@ -2104,7 +2128,7 @@ class OStatus
                        ]);
                }
 
-               if (!$item["private"] && !$feed_mode) {
+               if (($item['private'] != Item::PRIVATE) && !$feed_mode) {
                        XML::addElement($doc, $entry, "link", "", ["rel" => "ostatus:attention",
                                                                        "href" => "http://activityschema.org/collection/public"]);
                        XML::addElement($doc, $entry, "link", "", ["rel" => "mentioned",
@@ -2196,8 +2220,8 @@ class OStatus
                $authorid = Contact::getIdForURL($owner["url"], 0, true);
 
                $condition = ["`uid` = ? AND `received` > ? AND NOT `deleted`
-                       AND NOT `private` AND `visible` AND `wall` AND `parent-network` IN (?, ?)",
-                       $owner["uid"], $check_date, Protocol::OSTATUS, Protocol::DFRN];
+                       AND `private` != ? AND `visible` AND `wall` AND `parent-network` IN (?, ?)",
+                       $owner["uid"], $check_date, Item::PRIVATE, Protocol::OSTATUS, Protocol::DFRN];
 
                if ($filter === 'comments') {
                        $condition[0] .= " AND `object-type` = ? ";