]> git.mxchange.org Git - friendica.git/blobdiff - src/Protocol/DFRN.php
Merge pull request #9526 from MrPetovan/bug/9525-mastodon-emojis-tag
[friendica.git] / src / Protocol / DFRN.php
index 2186081022f351ad95598c1a05826e0d99974b3b..11c4e3a14d3810f98b2478c13582819cf3b5edf3 100644 (file)
@@ -866,27 +866,19 @@ class DFRN
         */
        private static function getAttachment($doc, $root, $item)
        {
-               $arr = explode('[/attach],', $item['attach']);
-               if (count($arr)) {
-                       foreach ($arr as $r) {
-                               $matches = false;
-                               $cnt = preg_match('|\[attach\]href=\"(.*?)\" length=\"(.*?)\" type=\"(.*?)\" title=\"(.*?)\"|', $r, $matches);
-                               if ($cnt) {
-                                       $attributes = ["rel" => "enclosure",
-                                                       "href" => $matches[1],
-                                                       "type" => $matches[3]];
-
-                                       if (intval($matches[2])) {
-                                               $attributes["length"] = intval($matches[2]);
-                                       }
-
-                                       if (trim($matches[4]) != "") {
-                                               $attributes["title"] = trim($matches[4]);
-                                       }
+               foreach (Post\Media::getByURIId($item['uri-id'], [Post\Media::DOCUMENT, Post\Media::TORRENT, Post\Media::UNKNOWN]) as $attachment) {
+                       $attributes = ['rel' => 'enclosure',
+                               'href' => $attachment['url'],
+                               'type' => $attachment['mimetype']];
 
-                                       XML::addElement($doc, $root, "link", "", $attributes);
-                               }
+                       if (!empty($attachment['size'])) {
+                               $attributes['length'] = intval($attachment['size']);
+                       }
+                       if (!empty($attachment['description'])) {
+                               $attributes['title'] = $attachment['description'];
                        }
+
+                       XML::addElement($doc, $root, 'link', '', $attributes);
                }
        }
 
@@ -1500,18 +1492,20 @@ 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` AND `rel` IN (?, ?)",
-                       $importer["importer_uid"], Strings::normaliseLink($author["link"]), Protocol::STATUSNET,
-                       Contact::SHARING, Contact::FRIEND];
+               $condition = ["`uid` = ? AND `nurl` = ? AND `network` != ? AND NOT `pending` AND NOT `blocked`",
+                       $importer["importer_uid"], Strings::normaliseLink($author["link"]), Protocol::STATUSNET];
+
+               if ($importer['account-type'] != User::ACCOUNT_TYPE_COMMUNITY) {
+                       $condition = DBA::mergeConditions($condition, ['rel' => [Contact::SHARING, Contact::FRIEND]]);
+               }
+
                $contact_old = DBA::selectFirst('contact', $fields, $condition);
 
                if (DBA::isResult($contact_old)) {
                        $author["contact-id"] = $contact_old["id"];
                        $author["network"] = $contact_old["network"];
                } else {
-                       if (!$onlyfetch) {
-                               Logger::debug("Contact ".$author["link"]." wasn't found for user ".$importer["importer_uid"]." XML: ".$xml);
-                       }
+                       Logger::info('Contact not found', ['condition' => $condition]);
 
                        $author["contact-unknown"] = true;
                        $contact = Contact::getByURL($author["link"], null, ["id", "network"]);
@@ -2152,9 +2146,9 @@ class DFRN
        {
                $rel = "";
                $href = "";
-               $type = "";
-               $length = "0";
-               $title = "";
+               $type = null;
+               $length = null;
+               $title = null;
                foreach ($links as $link) {
                        foreach ($link->attributes as $attributes) {
                                switch ($attributes->name) {
@@ -2171,13 +2165,8 @@ class DFRN
                                                $item["plink"] = $href;
                                                break;
                                        case "enclosure":
-                                               if (!empty($item["attach"])) {
-                                                       $item["attach"] .= ",";
-                                               } else {
-                                                       $item["attach"] = "";
-                                               }
-
-                                               $item["attach"] .= Post\Media::getAttachElement($href, $length, $type, $title);
+                                               Post\Media::insert(['uri-id' => $item['uri-id'], 'type' => Post\Media::DOCUMENT,
+                                                       'url' => $href, 'mimetype' => $type, 'size' => $length, 'description' => $title]);
                                                break;
                                }
                        }