X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=src%2FProtocol%2FFeed.php;h=b7e7ce9201ebdbd7099027c28a3ce39b2bbb596d;hb=73b448c82926e384c110434de793c8cc55c5ddbc;hp=5939e5ce1a929b96c00f0fc21b642acab4856106;hpb=19053141a29a36e03f604730cc230e4578671511;p=friendica.git diff --git a/src/Protocol/Feed.php b/src/Protocol/Feed.php index 5939e5ce1a..b7e7ce9201 100644 --- a/src/Protocol/Feed.php +++ b/src/Protocol/Feed.php @@ -14,12 +14,10 @@ use Friendica\Core\Protocol; use Friendica\Core\System; use Friendica\Database\DBA; use Friendica\Model\Item; +use Friendica\Protocol\ActivityNamespace; 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 * @@ -28,17 +26,18 @@ class Feed { /** * @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::log("Import Atom/RSS feed '".$contact["name"]."' (Contact ".$contact["id"].") for user ".$importer["uid"], Logger::DEBUG); @@ -61,13 +60,13 @@ class Feed { $doc = new DOMDocument(); @$doc->loadXML(trim($xml)); $xpath = new DOMXPath($doc); - $xpath->registerNamespace('atom', NAMESPACE_ATOM1); + $xpath->registerNamespace('atom', ActivityNamespace::ATOM1); $xpath->registerNamespace('dc', "http://purl.org/dc/elements/1.1/"); $xpath->registerNamespace('content', "http://purl.org/rss/1.0/modules/content/"); $xpath->registerNamespace('rdf', "http://www.w3.org/1999/02/22-rdf-syntax-ns#"); $xpath->registerNamespace('rss', "http://purl.org/rss/1.0/"); $xpath->registerNamespace('media', "http://search.yahoo.com/mrss/"); - $xpath->registerNamespace('poco', NAMESPACE_POCO); + $xpath->registerNamespace('poco', ActivityNamespace::POCO); $author = []; $entries = null; @@ -200,8 +199,8 @@ class Feed { $header["origin"] = 0; $header["gravity"] = GRAVITY_PARENT; $header["private"] = 2; - $header["verb"] = ACTIVITY_POST; - $header["object-type"] = ACTIVITY_OBJ_NOTE; + $header["verb"] = Activity::POST; + $header["object-type"] = Activity\ObjectType::NOTE; $header["contact-id"] = $contact["id"]; @@ -268,6 +267,9 @@ class Feed { if (empty($item["title"])) { $item["title"] = XML::getFirstNodeValue($xpath, 'rss:title/text()', $entry); } + + $item["title"] = html_entity_decode($item["title"], ENT_QUOTES, 'UTF-8'); + $published = XML::getFirstNodeValue($xpath, 'atom:published/text()', $entry); if (empty($published)) { @@ -320,7 +322,6 @@ class Feed { $href = ""; $length = ""; $type = ""; - $title = ""; foreach ($enclosure->attributes AS $attribute) { if (in_array($attribute->name, ["url", "href"])) { @@ -359,11 +360,20 @@ class Feed { 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 @@ -411,9 +421,13 @@ class Feed { $item["title"] = ""; $item["body"] = $item["body"].add_page_info($item["plink"], false, $preview, ($contact["fetch_further_information"] == 2), $contact["ffi_keyword_blacklist"]); $item["tag"] = add_page_keywords($item["plink"], $preview, ($contact["fetch_further_information"] == 2), $contact["ffi_keyword_blacklist"]); - $item["object-type"] = ACTIVITY_OBJ_BOOKMARK; + $item["object-type"] = Activity\ObjectType::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;