]> git.mxchange.org Git - friendica.git/blobdiff - src/Protocol/DFRN.php
New function to fetch endpoint items
[friendica.git] / src / Protocol / DFRN.php
index c9d2f1e4cb9ebb471caf8a720edc34b3cfe9db90..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;
@@ -14,7 +27,6 @@ use Friendica\App\BaseURL;
 use Friendica\Content\OEmbed;
 use Friendica\Content\Text\BBCode;
 use Friendica\Content\Text\HTML;
-use Friendica\Core\Config;
 use Friendica\Core\Hook;
 use Friendica\Core\Logger;
 use Friendica\Core\Protocol;
@@ -26,6 +38,7 @@ use Friendica\Model\Event;
 use Friendica\Model\GContact;
 use Friendica\Model\Item;
 use Friendica\Model\Mail;
+use Friendica\Model\Notify\Type;
 use Friendica\Model\PermissionSet;
 use Friendica\Model\Profile;
 use Friendica\Model\User;
@@ -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 {
@@ -489,11 +502,11 @@ class DFRN
        {
 
                /* get site pubkey. this could be a new installation with no site keys*/
-               $pubkey = Config::get('system', 'site_pubkey');
+               $pubkey = DI::config()->get('system', 'site_pubkey');
                if (! $pubkey) {
                        $res = Crypto::newKeypair(1024);
-                       Config::set('system', 'site_prvkey', $res['prvkey']);
-                       Config::set('system', 'site_pubkey', $res['pubkey']);
+                       DI::config()->set('system', 'site_prvkey', $res['prvkey']);
+                       DI::config()->set('system', 'site_pubkey', $res['pubkey']);
                }
 
                $rp = q(
@@ -527,7 +540,7 @@ class DFRN
                XML::addElement($doc, $relocate, "dfrn:confirm", $owner['confirm']);
                XML::addElement($doc, $relocate, "dfrn:notify", $owner['notify']);
                XML::addElement($doc, $relocate, "dfrn:poll", $owner['poll']);
-               XML::addElement($doc, $relocate, "dfrn:sitepubkey", Config::get('system', 'site_pubkey'));
+               XML::addElement($doc, $relocate, "dfrn:sitepubkey", DI::config()->get('system', 'site_pubkey'));
 
                $root->appendChild($relocate);
 
@@ -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");
                }
 
@@ -688,7 +691,7 @@ class DFRN
                                `profile`.`pub_keywords`, `profile`.`xmpp`, `profile`.`dob`
                        FROM `profile`
                                INNER JOIN `user` ON `user`.`uid` = `profile`.`uid`
-                               WHERE `profile`.`is-default` AND NOT `user`.`hidewall` AND `user`.`uid` = %d",
+                               WHERE NOT `user`.`hidewall` AND `user`.`uid` = %d",
                        intval($owner['uid'])
                );
                if (DBA::isResult($r)) {
@@ -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']) {
@@ -1192,12 +1197,12 @@ class DFRN
                        $idtosend = '1:' . $orig_id;
                }
 
-               $rino = Config::get('system', 'rino_encrypt');
+               $rino = DI::config()->get('system', 'rino_encrypt');
                $rino = intval($rino);
 
                Logger::log("Local rino version: ". $rino, Logger::DEBUG);
 
-               $ssl_val = intval(Config::get('system', 'ssl_policy'));
+               $ssl_val = intval(DI::config()->get('system', 'ssl_policy'));
 
                switch ($ssl_val) {
                        case BaseURL::SSL_POLICY_FULL:
@@ -1893,7 +1898,7 @@ class DFRN
 
                notification(
                        [
-                               'type'         => NOTIFY_SUGGEST,
+                               'type'         => Type::SUGGEST,
                                'notify_flags' => $importer['notify-flags'],
                                'language'     => $importer['language'],
                                'to_name'      => $importer['username'],
@@ -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") {