]> git.mxchange.org Git - friendica.git/blobdiff - src/Protocol/DFRN.php
New function to fetch endpoint items
[friendica.git] / src / Protocol / DFRN.php
index b15816bc77ea7fcfe77f9405da3f344408992c8b..4c88db1d944a47c0a70d69e7618566438fb652f9 100644 (file)
@@ -1,11 +1,24 @@
 <?php
 /**
- * @file include/dfrn.php
- * The implementation of the dfrn protocol
+ * @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/>.
  *
- * @see https://github.com/friendica/friendica/wiki/Protocol and
- * https://github.com/friendica/friendica/blob/master/spec/dfrn2.pdf
  */
+
 namespace Friendica\Protocol;
 
 use DOMDocument;
@@ -169,7 +182,7 @@ class DFRN
 
                // default permissions - anonymous user
 
-               $sql_extra = " AND NOT `item`.`private` ";
+               $sql_extra = sprintf(" AND `item`.`private` != %s ", Item::PRIVATE);
 
                $r = q(
                        "SELECT `contact`.*, `user`.`nickname`, `user`.`timezone`, `user`.`page-flags`, `user`.`account-type`
@@ -221,7 +234,7 @@ class DFRN
                        if (!empty($set)) {
                                $sql_extra = " AND `item`.`psid` IN (" . implode(',', $set) .")";
                        } else {
-                               $sql_extra = " AND NOT `item`.`private`";
+                               $sql_extra = sprintf(" AND `item`.`private` != %s", Item::PRIVATE);
                        }
                }
 
@@ -319,7 +332,7 @@ class DFRN
                        if ($public_feed) {
                                $type = 'html';
                                // catch any email that's in a public conversation and make sure it doesn't leak
-                               if ($item['private']) {
+                               if ($item['private'] == Item::PRIVATE) {
                                        continue;
                                }
                        } else {
@@ -626,27 +639,17 @@ class DFRN
         */
        private static function addAuthor(DOMDocument $doc, array $owner, $authorelement, $public)
        {
-               // Is the profile hidden or shouldn't be published in the net? Then add the "hide" element
-               $r = q(
-                       "SELECT `id` FROM `profile` INNER JOIN `user` ON `user`.`uid` = `profile`.`uid`
-                               WHERE (`hidewall` OR NOT `net-publish`) AND `user`.`uid` = %d",
-                       intval($owner['uid'])
-               );
-               if (DBA::isResult($r)) {
-                       $hidewall = true;
-               } else {
-                       $hidewall = false;
-               }
+               // Should the profile be "unsearchable" in the net? Then add the "hide" element
+               $hide = DBA::exists('profile', ['uid' => $owner['uid'], 'net-publish' => false]);
 
                $author = $doc->createElement($authorelement);
 
                $namdate = DateTimeFormat::utc($owner['name-date'].'+00:00', DateTimeFormat::ATOM);
-               $uridate = DateTimeFormat::utc($owner['uri-date'].'+00:00', DateTimeFormat::ATOM);
                $picdate = DateTimeFormat::utc($owner['avatar-date'].'+00:00', DateTimeFormat::ATOM);
 
                $attributes = [];
 
-               if (!$public || !$hidewall) {
+               if (!$public || !$hide) {
                        $attributes = ["dfrn:updated" => $namdate];
                }
 
@@ -657,7 +660,7 @@ class DFRN
                $attributes = ["rel" => "photo", "type" => "image/jpeg",
                                        "media:width" => 300, "media:height" => 300, "href" => $owner['photo']];
 
-               if (!$public || !$hidewall) {
+               if (!$public || !$hide) {
                        $attributes["dfrn:updated"] = $picdate;
                }
 
@@ -666,7 +669,7 @@ class DFRN
                $attributes["rel"] = "avatar";
                XML::addElement($doc, $author, "link", "", $attributes);
 
-               if ($hidewall) {
+               if ($hide) {
                        XML::addElement($doc, $author, "dfrn:hide", "true");
                }
 
@@ -952,7 +955,7 @@ class DFRN
                        $entry->setAttribute("xmlns:statusnet", ActivityNamespace::STATUSNET);
                }
 
-               if ($item['private']) {
+               if ($item['private'] == Item::PRIVATE) {
                        $body = Item::fixPrivatePhotos($item['body'], $owner['uid'], $item, $cid);
                } else {
                        $body = $item['body'];
@@ -1047,7 +1050,9 @@ class DFRN
                }
 
                if ($item['private']) {
-                       XML::addElement($doc, $entry, "dfrn:private", ($item['private'] ? $item['private'] : 1));
+                       // Friendica versions prior to 2020.3 can't handle "unlisted" properly. So we can only transmit public and private
+                       XML::addElement($doc, $entry, "dfrn:private", ($item['private'] == Item::PRIVATE ? Item::PRIVATE : Item::PUBLIC));
+                       XML::addElement($doc, $entry, "dfrn:unlisted", $item['private'] == Item::UNLISTED);
                }
 
                if ($item['extid']) {
@@ -2137,7 +2142,7 @@ class DFRN
                                // send a notification
                                notification(
                                        [
-                                       "type"         => NOTIFY_POKE,
+                                       "type"         => Type::POKE,
                                        "notify_flags" => $importer["notify-flags"],
                                        "language"     => $importer["language"],
                                        "to_name"      => $importer["username"],
@@ -2401,6 +2406,11 @@ class DFRN
 
                $item["private"] = XML::getFirstNodeValue($xpath, "dfrn:private/text()", $entry);
 
+               $unlisted = XML::getFirstNodeValue($xpath, "dfrn:unlisted/text()", $entry);
+               if (!empty($unlisted) && ($item['private'] != Item::PRIVATE)) {
+                       $item['private'] = Item::UNLISTED;
+               }
+
                $item["extid"] = XML::getFirstNodeValue($xpath, "dfrn:extid/text()", $entry);
 
                if (XML::getFirstNodeValue($xpath, "dfrn:bookmark/text()", $entry) == "true") {