require_once("include/html2bbcode.php");
require_once("include/items.php");
+/**
+ * @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
+ *
+ * @return array In simulation mode it returns the header and the first item
+ */
function feed_import($xml,$importer,&$contact, &$hub, $simulate = false) {
$a = get_app();
$doc = new DOMDocument();
@$doc->loadXML($xml);
$xpath = new DomXPath($doc);
- $xpath->registerNamespace('atom', "http://www.w3.org/2005/Atom");
+ $xpath->registerNamespace('atom', NAMESPACE_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);
$author = array();
}
// Is it Atom?
- if ($xpath->query('/atom:feed/atom:entry')->length > 0) {
- $self = $xpath->query("atom:link[@rel='self']")->item(0)->attributes;
- if (is_object($self))
- foreach($self AS $attributes)
+ if ($xpath->query('/atom:feed')->length > 0) {
+ $alternate = $xpath->query("atom:link[@rel='alternate']")->item(0)->attributes;
+ if (is_object($alternate))
+ foreach($alternate AS $attributes)
if ($attributes->name == "href")
$author["author-link"] = $attributes->textContent;
+ $author["author-id"] = $xpath->evaluate('/atom:feed/atom:author/atom:uri/text()')->item(0)->nodeValue;
+
+ if ($author["author-link"] == "")
+ $author["author-link"] = $author["author-id"];
+
if ($author["author-link"] == "") {
- $alternate = $xpath->query("atom:link[@rel='alternate']")->item(0)->attributes;
- if (is_object($alternate))
- foreach($alternate AS $attributes)
+ $self = $xpath->query("atom:link[@rel='self']")->item(0)->attributes;
+ if (is_object($self))
+ foreach($self AS $attributes)
if ($attributes->name == "href")
$author["author-link"] = $attributes->textContent;
}
- if ($author["author-link"] == "")
- $author["author-link"] = $xpath->evaluate('/atom:feed/atom:author/atom:uri/text()')->item(0)->nodeValue;
if ($author["author-link"] == "")
$author["author-link"] = $xpath->evaluate('/atom:feed/atom:id/text()')->item(0)->nodeValue;
if ($author["author-name"] == "")
$author["author-name"] = $xpath->evaluate('/atom:feed/atom:author/atom:name/text()')->item(0)->nodeValue;
+ $value = $xpath->evaluate('atom:author/poco:displayName/text()')->item(0)->nodeValue;
+ if ($value != "")
+ $author["author-name"] = $value;
+
+ $value = $xpath->evaluate('atom:author/poco:preferredUsername/text()')->item(0)->nodeValue;
+ if ($value != "")
+ $author["author-nick"] = $value;
+
$author["edited"] = $author["created"] = $xpath->query('/atom:feed/atom:updated/text()')->item(0)->nodeValue;
$author["app"] = $xpath->evaluate('/atom:feed/atom:generator/text()')->item(0)->nodeValue;
$entries = $xpath->query('/rss/channel/item');
}
- if (is_array($contact)) {
+ if (!$simulate) {
$author["author-link"] = $contact["url"];
if ($author["author-name"] == "")
$author["owner-link"] = $contact["url"];
$author["owner-name"] = $contact["name"];
$author["owner-avatar"] = $contact["thumb"];
+
+ // This is no field in the item table. So we have to unset it.
+ unset($author["author-nick"]);
+ unset($author["author-id"]);
}
$header = array();