]> git.mxchange.org Git - friendica.git/blobdiff - src/Protocol/DFRN.php
Standards
[friendica.git] / src / Protocol / DFRN.php
index 165a63c7cbcd9531f862ee596ec952e509603f1f..71ae052eb649dc0289c534296e2410ff2dc1b88a 100644 (file)
@@ -37,6 +37,7 @@ use Friendica\Model\FContact;
 use Friendica\Model\Item;
 use Friendica\Model\ItemURI;
 use Friendica\Model\Mail;
+use Friendica\Model\Notify;
 use Friendica\Model\Notify\Type;
 use Friendica\Model\PermissionSet;
 use Friendica\Model\Post;
@@ -414,36 +415,36 @@ class DFRN
        /**
         * Create XML text for DFRN mails
         *
-        * @param array $item  message elements
+        * @param array $mail  Mail record
         * @param array $owner Owner record
         *
         * @return string DFRN mail
         * @throws \Friendica\Network\HTTPException\InternalServerErrorException
         * @todo  Find proper type-hints
         */
-       public static function mail($item, $owner)
+       public static function mail(array $mail, array $owner)
        {
                $doc = new DOMDocument('1.0', 'utf-8');
                $doc->formatOutput = true;
 
                $root = self::addHeader($doc, $owner, "dfrn:owner", "", false);
 
-               $mail = $doc->createElement("dfrn:mail");
-               $sender = $doc->createElement("dfrn:sender");
+               $mailElement = $doc->createElement("dfrn:mail");
+               $senderElement = $doc->createElement("dfrn:sender");
 
-               XML::addElement($doc, $sender, "dfrn:name", $owner['name']);
-               XML::addElement($doc, $sender, "dfrn:uri", $owner['url']);
-               XML::addElement($doc, $sender, "dfrn:avatar", $owner['thumb']);
+               XML::addElement($doc, $senderElement, "dfrn:name", $owner['name']);
+               XML::addElement($doc, $senderElement, "dfrn:uri", $owner['url']);
+               XML::addElement($doc, $senderElement, "dfrn:avatar", $owner['thumb']);
 
-               $mail->appendChild($sender);
+               $mailElement->appendChild($senderElement);
 
-               XML::addElement($doc, $mail, "dfrn:id", $item['uri']);
-               XML::addElement($doc, $mail, "dfrn:in-reply-to", $item['thr-parent']);
-               XML::addElement($doc, $mail, "dfrn:sentdate", DateTimeFormat::utc($item['created'] . '+00:00', DateTimeFormat::ATOM));
-               XML::addElement($doc, $mail, "dfrn:subject", $item['title']);
-               XML::addElement($doc, $mail, "dfrn:content", $item['body']);
+               XML::addElement($doc, $mailElement, "dfrn:id", $mail['uri']);
+               XML::addElement($doc, $mailElement, "dfrn:in-reply-to", $mail['parent-uri']);
+               XML::addElement($doc, $mailElement, "dfrn:sentdate", DateTimeFormat::utc($mail['created'] . '+00:00', DateTimeFormat::ATOM));
+               XML::addElement($doc, $mailElement, "dfrn:subject", $mail['title']);
+               XML::addElement($doc, $mailElement, "dfrn:content", $mail['body']);
 
-               $root->appendChild($mail);
+               $root->appendChild($mailElement);
 
                return trim($doc->saveXML());
        }
@@ -1767,7 +1768,7 @@ class DFRN
                $msg["from-photo"] = XML::getFirstValue($xpath, "dfrn:sender/dfrn:avatar/text()", $mail);
                $msg["contact-id"] = $importer["id"];
                $msg["uri"] = XML::getFirstValue($xpath, "dfrn:id/text()", $mail);
-               $msg["thr-parent"] = XML::getFirstValue($xpath, "dfrn:in-reply-to/text()", $mail);
+               $msg["parent-uri"] = XML::getFirstValue($xpath, "dfrn:in-reply-to/text()", $mail);
                $msg["created"] = DateTimeFormat::utc(XML::getFirstValue($xpath, "dfrn:sentdate/text()", $mail));
                $msg["title"] = XML::getFirstValue($xpath, "dfrn:subject/text()", $mail);
                $msg["body"] = XML::getFirstValue($xpath, "dfrn:content/text()", $mail);
@@ -2005,7 +2006,7 @@ class DFRN
                        }
 
                        if ($Blink && Strings::compareLink($Blink, DI::baseUrl() . "/profile/" . $importer["nickname"])) {
-                               $author = DBA::selectFirst('contact', ['name', 'thumb', 'url'], ['id' => $item['author-id']]);
+                               $author = DBA::selectFirst('contact', ['id', 'name', 'thumb', 'url'], ['id' => $item['author-id']]);
 
                                $parent = Item::selectFirst(['id'], ['uri' => $item['thr-parent'], 'uid' => $importer["importer_uid"]]);
                                $item['parent'] = $parent['id'];
@@ -2013,21 +2014,15 @@ class DFRN
                                // send a notification
                                notification(
                                        [
-                                       "type"         => Type::POKE,
-                                       "notify_flags" => $importer["notify-flags"],
-                                       "language"     => $importer["language"],
-                                       "to_name"      => $importer["username"],
-                                       "to_email"     => $importer["email"],
-                                       "uid"          => $importer["importer_uid"],
-                                       "item"         => $item,
-                                       "link"         => DI::baseUrl()."/display/".urlencode($item['guid']),
-                                       "source_name"  => $author["name"],
-                                       "source_link"  => $author["url"],
-                                       "source_photo" => $author["thumb"],
-                                       "verb"         => $item["verb"],
-                                       "otype"        => "person",
-                                       "activity"     => $verb,
-                                       "parent"       => $item['parent']]
+                                       "type"     => Type::POKE,
+                                       "otype"    => Notify\ObjectType::PERSON,
+                                       "activity" => $verb,
+                                       "verb"     => $item["verb"],
+                                       "uid"      => $importer["importer_uid"],
+                                       "cid"      => $author["id"],
+                                       "item"     => $item,
+                                       "link"     => DI::baseUrl() . "/display/" . urlencode($item['guid']),
+                                       ]
                                );
                        }
                }
@@ -2204,13 +2199,13 @@ class DFRN
         * @throws \ImagickException
         * @todo  Add type-hints
         */
-       private static function processEntry($header, $xpath, $entry, $importer, $xml)
+       private static function processEntry($header, $xpath, $entry, $importer, $xml, $protocol)
        {
                Logger::log("Processing entries");
 
                $item = $header;
 
-               $item["protocol"] = Conversation::PARCEL_DFRN;
+               $item["protocol"] = $protocol;
 
                $item["source"] = $xml;
 
@@ -2606,7 +2601,7 @@ class DFRN
         * @throws \ImagickException
         * @todo  set proper type-hints
         */
-       public static function import($xml, $importer, $sort_by_date = false)
+       public static function import($xml, $importer, $sort_by_date = false, $protocol = Conversation::PARCEL_DFRN)
        {
                if ($xml == "") {
                        return 400;
@@ -2710,14 +2705,20 @@ class DFRN
                }
 
                $deletions = $xpath->query("/atom:feed/at:deleted-entry");
-               foreach ($deletions as $deletion) {
-                       self::processDeletion($xpath, $deletion, $importer);
+               if (!empty($deletions)) {
+                       foreach ($deletions as $deletion) {
+                               self::processDeletion($xpath, $deletion, $importer);
+                       }
+                       if (count($deletions) > 0) {
+                               Logger::notice('Deletions had been processed');
+                               return 200;
+                       }
                }
 
                if (!$sort_by_date) {
                        $entries = $xpath->query("/atom:feed/atom:entry");
                        foreach ($entries as $entry) {
-                               self::processEntry($header, $xpath, $entry, $importer, $xml);
+                               self::processEntry($header, $xpath, $entry, $importer, $xml, $protocol);
                        }
                } else {
                        $newentries = [];
@@ -2731,7 +2732,7 @@ class DFRN
                        ksort($newentries);
 
                        foreach ($newentries as $entry) {
-                               self::processEntry($header, $xpath, $entry, $importer, $xml);
+                               self::processEntry($header, $xpath, $entry, $importer, $xml, $protocol);
                        }
                }
                Logger::log("Import done for user " . $importer["importer_uid"] . " from contact " . $importer["id"], Logger::DEBUG);