]> git.mxchange.org Git - friendica.git/blobdiff - src/Protocol/DFRN.php
move forgotten rotator from template
[friendica.git] / src / Protocol / DFRN.php
index da4db5d9ad9dba04639881ad1501941e277d3922..1bb7bf3ff14dd2938339ed92c3f0d3bfb8e5aed2 100644 (file)
@@ -1,6 +1,6 @@
 <?php
 /**
- * @copyright Copyright (C) 2010-2022, the Friendica project
+ * @copyright Copyright (C) 2010-2023, the Friendica project
  *
  * @license GNU AGPL version 3 or any later version
  *
@@ -34,7 +34,6 @@ use Friendica\DI;
 use Friendica\Model\Contact;
 use Friendica\Model\Conversation;
 use Friendica\Model\Event;
-use Friendica\Model\FContact;
 use Friendica\Model\GServer;
 use Friendica\Model\Item;
 use Friendica\Model\ItemURI;
@@ -45,6 +44,7 @@ use Friendica\Model\Post;
 use Friendica\Model\Profile;
 use Friendica\Model\Tag;
 use Friendica\Model\User;
+use Friendica\Network\HTTPException;
 use Friendica\Network\Probe;
 use Friendica\Util\Crypto;
 use Friendica\Util\DateTimeFormat;
@@ -301,16 +301,15 @@ class DFRN
                        DI::config()->set('system', 'site_pubkey', $res['pubkey']);
                }
 
-               $profilephotos = Photo::selectToArray(['resource-id' , 'scale'], ['profile' => true, 'uid' => $uid], ['order' => ['scale']]);
+               $profilephotos = Photo::selectToArray(['resource-id', 'scale', 'type'], ['profile' => true, 'uid' => $uid], ['order' => ['scale']]);
 
                $photos = [];
                $ext = Images::supportedTypes();
 
                foreach ($profilephotos as $p) {
-                       $photos[$p['scale']] = DI::baseUrl().'/photo/'.$p['resource-id'].'-'.$p['scale'].'.'.$ext[$p['type']];
+                       $photos[$p['scale']] = DI::baseUrl() . '/photo/' . $p['resource-id'] . '-' . $p['scale'] . '.' . $ext[$p['type']];
                }
 
-
                $doc = new DOMDocument('1.0', 'utf-8');
                $doc->formatOutput = true;
 
@@ -538,7 +537,7 @@ class DFRN
 
                        XML::addElement($doc, $author, 'poco:utcOffset', DateTimeFormat::timezoneNow($profile['timezone'], 'P'));
 
-                       if (trim($profile['homepage']) != '') {
+                       if (trim($profile['homepage'])) {
                                $urls = $doc->createElement('poco:urls');
                                XML::addElement($doc, $urls, 'poco:type', 'homepage');
                                XML::addElement($doc, $urls, 'poco:value', $profile['homepage']);
@@ -546,7 +545,7 @@ class DFRN
                                $author->appendChild($urls);
                        }
 
-                       if (trim($profile['pub_keywords']) != '') {
+                       if (trim($profile['pub_keywords'] ?? '')) {
                                $keywords = explode(',', $profile['pub_keywords']);
 
                                foreach ($keywords as $keyword) {
@@ -554,7 +553,7 @@ class DFRN
                                }
                        }
 
-                       if (trim($profile['xmpp']) != '') {
+                       if (trim($profile['xmpp'])) {
                                $ims = $doc->createElement('poco:ims');
                                XML::addElement($doc, $ims, 'poco:type', 'xmpp');
                                XML::addElement($doc, $ims, 'poco:value', $profile['xmpp']);
@@ -562,7 +561,7 @@ class DFRN
                                $author->appendChild($ims);
                        }
 
-                       if (trim($profile['locality'] . $profile['region'] . $profile['country-name']) != '') {
+                       if (trim($profile['locality'] . $profile['region'] . $profile['country-name'])) {
                                $element = $doc->createElement('poco:address');
 
                                XML::addElement($doc, $element, 'poco:formatted', Profile::formatLocation($profile));
@@ -711,7 +710,7 @@ class DFRN
         */
        private static function getAttachment($doc, $root, array $item)
        {
-               foreach (Post\Media::getByURIId($item['uri-id'], [Post\Media::DOCUMENT, Post\Media::TORRENT, Post\Media::UNKNOWN]) as $attachment) {
+               foreach (Post\Media::getByURIId($item['uri-id'], [Post\Media::DOCUMENT, Post\Media::TORRENT]) as $attachment) {
                        $attributes = ['rel' => 'enclosure',
                                'href' => $attachment['url'],
                                'type' => $attachment['mimetype']];
@@ -775,6 +774,7 @@ class DFRN
                }
 
                $body = Post\Media::addAttachmentsToBody($item['uri-id'], DI::contentItem()->addSharedPost($item));
+               $body = Post\Media::addHTMLAttachmentToBody($item['uri-id'], $body);
 
                if ($item['private'] == Item::PRIVATE) {
                        $body = Item::fixPrivatePhotos($body, $owner['uid'], $item, $cid);
@@ -981,12 +981,12 @@ class DFRN
                                }
                        }
 
-                       $fcontact = FContact::getByURL($contact['addr']);
-                       if (empty($fcontact)) {
+                       try {
+                               $pubkey = DI::dsprContact()->getByAddr(WebFingerUri::fromString($contact['addr']))->pubKey;
+                       } catch (HTTPException\NotFoundException|\InvalidArgumentException $e) {
                                Logger::notice('Unable to find contact details for ' . $contact['id'] . ' - ' . $contact['addr']);
                                return -22;
                        }
-                       $pubkey = $fcontact['pubkey'] ?? '';
                } else {
                        $pubkey = '';
                }
@@ -1015,6 +1015,10 @@ class DFRN
                $xml = $postResult->getBody();
 
                $curl_stat = $postResult->getReturnCode();
+               if (!empty($contact['gsid']) && ($postResult->isTimeout() || empty($curl_stat))) {
+                       GServer::setFailureById($contact['gsid']);
+               }
+
                if (empty($curl_stat) || empty($xml)) {
                        Logger::notice('Empty answer from ' . $contact['id'] . ' - ' . $dest_url);
                        return -9; // timed out
@@ -1036,6 +1040,10 @@ class DFRN
                        return -23;
                }
 
+               if (!empty($contact['gsid'])) {
+                       GServer::setReachableById($contact['gsid'], Protocol::DFRN);
+               }
+
                if (!empty($res->message)) {
                        Logger::info('Transmit to ' . $dest_url . ' returned status '.$res->status.' - '.$res->message);
                }
@@ -1066,8 +1074,8 @@ class DFRN
 
                $fields = ['id', 'uid', 'url', 'network', 'avatar-date', 'avatar', 'name-date', 'uri-date', 'addr',
                        'name', 'nick', 'about', 'location', 'keywords', 'xmpp', 'bdyear', 'bd', 'hidden', 'contact-type'];
-               $condition = ["`uid` = ? AND `nurl` = ? AND `network` != ? AND NOT `pending` AND NOT `blocked`",
-                       $importer["importer_uid"], Strings::normaliseLink($author["link"]), Protocol::STATUSNET];
+               $condition = ["`uid` = ? AND `nurl` = ? AND NOT `pending` AND NOT `blocked`",
+                       $importer["importer_uid"], Strings::normaliseLink($author["link"])];
 
                if ($importer['account-type'] != User::ACCOUNT_TYPE_COMMUNITY) {
                        $condition = DBA::mergeConditions($condition, ['rel' => [Contact::SHARING, Contact::FRIEND]]);
@@ -2072,6 +2080,7 @@ class DFRN
                        // This is my contact on another system, but it's really me.
                        // Turn this into a wall post.
                        $notify = Item::isRemoteSelf($importer, $item);
+                       $item['wall'] = (bool)$notify;
 
                        $posted_id = Item::insert($item, $notify);