]> git.mxchange.org Git - friendica.git/blobdiff - src/Protocol/DFRN.php
Merge pull request #6752 from MrPetovan/bug/notices
[friendica.git] / src / Protocol / DFRN.php
index 5e6c733e211068c5be3bb85b6257226bfe5c3072..efd3c4aa606a0320ba5da97f8682379801d0e639 100644 (file)
@@ -119,7 +119,9 @@ class DFRN
                        $item["entry:cid"] = defaults($item, "entry:cid", 0);
 
                        $entry = self::entry($doc, "text", $item, $owner, $item["entry:comment-allow"], $item["entry:cid"]);
-                       $root->appendChild($entry);
+                       if (isset($entry)) {
+                               $root->appendChild($entry);
+                       }
                }
 
                return trim($doc->saveXML());
@@ -323,7 +325,9 @@ class DFRN
                        }
 
                        $entry = self::entry($doc, $type, $item, $owner, true);
-                       $root->appendChild($entry);
+                       if (isset($entry)) {
+                               $root->appendChild($entry);
+                       }
                }
 
                $atom = trim($doc->saveXML());
@@ -390,7 +394,9 @@ class DFRN
 
                        foreach ($items as $item) {
                                $entry = self::entry($doc, $type, $item, $owner, true, 0);
-                               $root->appendChild($entry);
+                               if (isset($entry)) {
+                                       $root->appendChild($entry);
+                               }
                        }
                } else {
                        $root = self::entry($doc, $type, $item, $owner, true, 0, true);
@@ -763,31 +769,33 @@ class DFRN
         */
        private static function addEntryAuthor(DOMDocument $doc, $element, $contact_url, $item)
        {
-               $contact = Contact::getDetailsByURL($contact_url, $item["uid"]);
-
                $author = $doc->createElement($element);
-               XML::addElement($doc, $author, "name", $contact["name"]);
-               XML::addElement($doc, $author, "uri", $contact["url"]);
-               XML::addElement($doc, $author, "dfrn:handle", $contact["addr"]);
 
-               /// @Todo
-               /// - Check real image type and image size
-               /// - Check which of these boths elements we should use
-               $attributes = [
+               $contact = Contact::getDetailsByURL($contact_url, $item["uid"]);
+               if (!empty($contact)) {
+                       XML::addElement($doc, $author, "name", $contact["name"]);
+                       XML::addElement($doc, $author, "uri", $contact["url"]);
+                       XML::addElement($doc, $author, "dfrn:handle", $contact["addr"]);
+
+                       /// @Todo
+                       /// - Check real image type and image size
+                       /// - Check which of these boths elements we should use
+                       $attributes = [
                                "rel" => "photo",
                                "type" => "image/jpeg",
                                "media:width" => 80,
                                "media:height" => 80,
                                "href" => $contact["photo"]];
-               XML::addElement($doc, $author, "link", "", $attributes);
+                       XML::addElement($doc, $author, "link", "", $attributes);
 
-               $attributes = [
+                       $attributes = [
                                "rel" => "avatar",
                                "type" => "image/jpeg",
                                "media:width" => 80,
                                "media:height" => 80,
                                "href" => $contact["photo"]];
-               XML::addElement($doc, $author, "link", "", $attributes);
+                       XML::addElement($doc, $author, "link", "", $attributes);
+               }
 
                return $author;
        }
@@ -906,7 +914,7 @@ class DFRN
         * @param int         $cid     Contact ID of the recipient
         * @param bool        $single  If set, the entry is created as an XML document with a single "entry" element
         *
-        * @return \DOMElement XML entry object
+        * @return null|\DOMElement XML entry object
         * @throws \Friendica\Network\HTTPException\InternalServerErrorException
         * @throws \ImagickException
         * @todo  Find proper type-hints
@@ -916,7 +924,8 @@ class DFRN
                $mentioned = [];
 
                if (!$item['parent']) {
-                       return;
+                       Logger::notice('Item without parent found.', ['type' => $type, 'item' => $item]);
+                       return null;
                }
 
                if ($item['deleted']) {
@@ -1546,7 +1555,7 @@ class DFRN
                        $author["network"] = $contact_old["network"];
                } else {
                        if (!$onlyfetch) {
-                               Logger::log("Contact ".$author["link"]." wasn't found for user ".$importer["importer_uid"]." XML: ".$xml, Logger::DEBUG);
+                               Logger::debug("Contact ".$author["link"]." wasn't found for user ".$importer["importer_uid"]." XML: ".$xml);
                        }
 
                        $author["contact-unknown"] = true;
@@ -1596,6 +1605,7 @@ class DFRN
 
                if (empty($author['avatar'])) {
                        Logger::log('Empty author: ' . $xml);
+                       $author['avatar'] = '';
                }
 
                if (DBA::isResult($contact_old) && !$onlyfetch) {
@@ -2513,7 +2523,7 @@ class DFRN
 
                $notice_info = $xpath->query("statusnet:notice_info", $entry);
                if ($notice_info && ($notice_info->length > 0)) {
-                       foreach ($notice_info->item[0]->attributes as $attributes) {
+                       foreach ($notice_info->item(0)->attributes as $attributes) {
                                if ($attributes->name == "source") {
                                        $item["app"] = strip_tags($attributes->textContent);
                                }
@@ -2588,8 +2598,8 @@ class DFRN
                $item['conversation-uri'] = XML::getFirstNodeValue($xpath, 'ostatus:conversation/text()', $entry);
 
                $conv = $xpath->query('ostatus:conversation', $entry);
-               if (is_object($conv->item[0])) {
-                       foreach ($conv->item[0]->attributes as $attributes) {
+               if (is_object($conv->item(0))) {
+                       foreach ($conv->item(0)->attributes as $attributes) {
                                if ($attributes->name == "ref") {
                                        $item['conversation-uri'] = $attributes->textContent;
                                }
@@ -2603,8 +2613,8 @@ class DFRN
                $item["parent-uri"] = $item["uri"];
 
                $inreplyto = $xpath->query("thr:in-reply-to", $entry);
-               if (is_object($inreplyto->item[0])) {
-                       foreach ($inreplyto->item[0]->attributes as $attributes) {
+               if (is_object($inreplyto->item(0))) {
+                       foreach ($inreplyto->item(0)->attributes as $attributes) {
                                if ($attributes->name == "ref") {
                                        $item["parent-uri"] = $attributes->textContent;
                                }