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\Util\Network;
use Friendica\Util\XML;
-require_once 'include/dba.php';
-require_once 'include/items.php';
-
/**
* @brief This class contain functions to import feeds
*
/**
* @brief Read a RSS/RDF/Atom feed and create an item entry for it
*
- * @param string $xml The feed data
- * @param array $importer The user record of the importer
- * @param array $contact The contact record of the feed
- * @param string $hub Unused dummy value for compatibility reasons
- * @param bool $simulate If enabled, no data is imported
+ * @param string $xml The feed data
+ * @param array $importer The user record of the importer
+ * @param array $contact The contact record of the feed
+ * @param string $hub Unused dummy value for compatibility reasons
+ * @param bool $simulate If enabled, no data is imported
*
* @return array In simulation mode it returns the header and the first item
+ * @throws \Friendica\Network\HTTPException\InternalServerErrorException
*/
public static function import($xml, $importer, &$contact, &$hub, $simulate = false) {
- $a = get_app();
+ $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;
}
$author["author-name"] = $value;
}
if ($simulate) {
- $author["author-id"] = XML::getFirstNodeValue($xpath, '/atom:feed/atom:author/atom:uri/text()');
+ $author["author-id"] = XML::getFirstNodeValue($xpath, '/atom:feed/atom:author/atom:id/text()');
+
+ // See https://tools.ietf.org/html/rfc4287#section-3.2.2
+ $value = XML::getFirstNodeValue($xpath, 'atom:author/atom:uri/text()');
+ if ($value != "") {
+ $author["author-link"] = $value;
+ }
$value = XML::getFirstNodeValue($xpath, 'atom:author/poco:preferredUsername/text()');
if ($value != "") {
$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;
}
$importer["uid"], $item["uri"], Protocol::FEED, Protocol::DFRN];
$previous = Item::selectFirst(['id'], $condition);
if (DBA::isResult($previous)) {
- logger("Item with uri ".$item["uri"]." for user ".$importer["uid"]." already existed under id ".$previous["id"], LOGGER_DEBUG);
+ Logger::log("Item with uri ".$item["uri"]." for user ".$importer["uid"]." already existed under id ".$previous["id"], Logger::DEBUG);
continue;
}
}
$href = "";
$length = "";
$type = "";
- $title = "";
foreach ($enclosure->attributes AS $attribute) {
if (in_array($attribute->name, ["url", "href"])) {
$tags .= ', ';
}
- $taglink = "#[url=" . System::baseUrl() . "/search?tag=" . rawurlencode($hashtag) . "]" . $hashtag . "[/url]";
+ $taglink = "#[url=" . System::baseUrl() . "/search?tag=" . $hashtag . "]" . $hashtag . "[/url]";
$tags .= $taglink;
}
if (empty($body)) {
$body = trim(XML::getFirstNodeValue($xpath, 'content:encoded/text()', $entry));
}
- if (empty($body)) {
- $body = trim(XML::getFirstNodeValue($xpath, 'description/text()', $entry));
+
+ $summary = trim(XML::getFirstNodeValue($xpath, 'atom:summary/text()', $entry));
+
+ if (empty($summary)) {
+ $summary = trim(XML::getFirstNodeValue($xpath, 'description/text()', $entry));
}
+
if (empty($body)) {
- $body = trim(XML::getFirstNodeValue($xpath, 'atom:summary/text()', $entry));
+ $body = $summary;
+ $summary = '';
+ }
+
+ if ($body == $summary) {
+ $summary = '';
}
// remove the content of the title if it is identically to the body
$item["object-type"] = ACTIVITY_OBJ_BOOKMARK;
unset($item["attach"]);
} else {
+ if (!empty($summary)) {
+ $item["body"] = '[abstract]' . HTML::toBBCode($summary, $basepath) . "[/abstract]\n" . $item["body"];
+ }
+
if ($contact["fetch_further_information"] == 3) {
if (!empty($tags)) {
$item["tag"] = $tags;
}
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']);
$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;
}