]> git.mxchange.org Git - friendica.git/blobdiff - src/Protocol/Feed.php
Update and rename test class
[friendica.git] / src / Protocol / Feed.php
index 83d06e9dc9122d981729e27bf0d4e305cc48bd8b..71ebe5506b9dadd78587e6123646af464d9c2d5f 100644 (file)
@@ -9,6 +9,8 @@ namespace Friendica\Protocol;
 use DOMDocument;
 use DOMXPath;
 use Friendica\Content\Text\HTML;
+use Friendica\Core\Logger;
+use Friendica\Core\Protocol;
 use Friendica\Core\System;
 use Friendica\Database\DBA;
 use Friendica\Model\Item;
@@ -39,12 +41,12 @@ class Feed {
                $a = get_app();
 
                if (!$simulate) {
-                       logger("Import Atom/RSS feed '".$contact["name"]."' (Contact ".$contact["id"].") for user ".$importer["uid"], LOGGER_DEBUG);
+                       Logger::log("Import Atom/RSS feed '".$contact["name"]."' (Contact ".$contact["id"].") for user ".$importer["uid"], Logger::DEBUG);
                } else {
-                       logger("Test Atom/RSS feed", LOGGER_DEBUG);
+                       Logger::log("Test Atom/RSS feed", Logger::DEBUG);
                }
                if (empty($xml)) {
-                       logger('XML is empty.', LOGGER_DEBUG);
+                       Logger::log('XML is empty.', Logger::DEBUG);
                        return;
                }
 
@@ -187,7 +189,7 @@ class Feed {
 
                $header = [];
                $header["uid"] = $importer["uid"];
-               $header["network"] = NETWORK_FEED;
+               $header["network"] = Protocol::FEED;
                $header["wall"] = 0;
                $header["origin"] = 0;
                $header["gravity"] = GRAVITY_PARENT;
@@ -198,7 +200,7 @@ class Feed {
                $header["contact-id"] = $contact["id"];
 
                if (!is_object($entries)) {
-                       logger("There are no entries in this feed.", LOGGER_DEBUG);
+                       Logger::log("There are no entries in this feed.", Logger::DEBUG);
                        return;
                }
 
@@ -244,10 +246,10 @@ class Feed {
 
                        if (!$simulate) {
                                $condition = ["`uid` = ? AND `uri` = ? AND `network` IN (?, ?)",
-                                       $importer["uid"], $item["uri"], NETWORK_FEED, NETWORK_DFRN];
+                                       $importer["uid"], $item["uri"], Protocol::FEED, Protocol::DFRN];
                                $previous = Item::selectFirst(['id'], $condition);
-                               if (DBA::is_result($previous)) {
-                                       logger("Item with uri ".$item["uri"]." for user ".$importer["uid"]." already existed under id ".$previous["id"], LOGGER_DEBUG);
+                               if (DBA::isResult($previous)) {
+                                       Logger::log("Item with uri ".$item["uri"]." for user ".$importer["uid"]." already existed under id ".$previous["id"], Logger::DEBUG);
                                        continue;
                                }
                        }
@@ -270,9 +272,14 @@ class Feed {
                        }
                        $updated = XML::getFirstNodeValue($xpath, 'atom:updated/text()', $entry);
 
-                       if (empty($updated)) {
+                       if (empty($updated) && !empty($published)) {
                                $updated = $published;
                        }
+
+                       if (empty($published) && !empty($updated)) {
+                               $published = $updated;
+                       }
+
                        if ($published != "") {
                                $item["created"] = $published;
                        }
@@ -417,14 +424,14 @@ class Feed {
                        }
 
                        if (!$simulate) {
-                               logger("Stored feed: ".print_r($item, true), LOGGER_DEBUG);
+                               Logger::log("Stored feed: ".print_r($item, true), Logger::DEBUG);
 
                                $notify = Item::isRemoteSelf($contact, $item);
 
                                // Distributed items should have a well formatted URI.
                                // Additionally we have to avoid conflicts with identical URI between imported feeds and these items.
                                if ($notify) {
-                                       $item['guid'] = Item::guidFromUri($orig_plink, $a->get_hostname());
+                                       $item['guid'] = Item::guidFromUri($orig_plink, $a->getHostName());
                                        unset($item['uri']);
                                        unset($item['parent-uri']);
 
@@ -434,7 +441,7 @@ class Feed {
 
                                $id = Item::insert($item, false, $notify);
 
-                               logger("Feed for contact ".$contact["url"]." stored under id ".$id);
+                               Logger::log("Feed for contact ".$contact["url"]." stored under id ".$id);
                        } else {
                                $items[] = $item;
                        }