X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=include%2Ffeed.php;h=22deff535a2383dd47822296ccb7ee680f3c7d90;hb=3b2cd854837e5df38f75f323aab24e31098812d4;hp=317f6bee7d7259ba753cc188684255401b35a7b1;hpb=09851331a9dc8601919cd0c9200686b92843d235;p=friendica.git
diff --git a/include/feed.php b/include/feed.php
index 317f6bee7d..22deff535a 100644
--- a/include/feed.php
+++ b/include/feed.php
@@ -1,4 +1,5 @@
loadXML($xml);
+ @$doc->loadXML(trim($xml));
$xpath = new DomXPath($doc);
$xpath->registerNamespace('atom', NAMESPACE_ATOM1);
$xpath->registerNamespace('dc', "http://purl.org/dc/elements/1.1/");
@@ -55,7 +64,7 @@ function feed_import($xml,$importer,&$contact, &$hub, $simulate = false) {
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) {
+ foreach ($alternate AS $attributes) {
if ($attributes->name == "href") {
$author["author-link"] = $attributes->textContent;
}
@@ -68,7 +77,7 @@ function feed_import($xml,$importer,&$contact, &$hub, $simulate = false) {
if ($author["author-link"] == "") {
$self = $xpath->query("atom:link[@rel='self']")->item(0)->attributes;
if (is_object($self)) {
- foreach($self AS $attributes) {
+ foreach ($self AS $attributes) {
if ($attributes->name == "href") {
$author["author-link"] = $attributes->textContent;
}
@@ -108,6 +117,14 @@ function feed_import($xml,$importer,&$contact, &$hub, $simulate = false) {
if ($value != "") {
$author["author-about"] = $value;
}
+ $avatar = $xpath->evaluate("atom:author/atom:link[@rel='avatar']")->item(0)->attributes;
+ if (is_object($avatar)) {
+ foreach ($avatar AS $attributes) {
+ if ($attributes->name == "href") {
+ $author["author-avatar"] = $attributes->textContent;
+ }
+ }
+ }
}
$author["edited"] = $author["created"] = $xpath->query('/atom:feed/atom:updated/text()')->item(0)->nodeValue;
@@ -188,7 +205,7 @@ function feed_import($xml,$importer,&$contact, &$hub, $simulate = false) {
$alternate = $xpath->query("atom:link", $entry)->item(0)->attributes;
}
if (is_object($alternate)) {
- foreach($alternate AS $attributes) {
+ foreach ($alternate AS $attributes) {
if ($attributes->name == "href") {
$item["plink"] = $attributes->textContent;
}
@@ -200,7 +217,6 @@ function feed_import($xml,$importer,&$contact, &$hub, $simulate = false) {
if ($item["plink"] == "") {
$item["plink"] = $xpath->evaluate('rss:link/text()', $entry)->item(0)->nodeValue;
}
- $item["plink"] = original_url($item["plink"]);
$item["uri"] = $xpath->evaluate('atom:id/text()', $entry)->item(0)->nodeValue;
@@ -210,12 +226,17 @@ function feed_import($xml,$importer,&$contact, &$hub, $simulate = false) {
if ($item["uri"] == "") {
$item["uri"] = $item["plink"];
}
+
+ $orig_plink = $item["plink"];
+
+ $item["plink"] = original_url($item["plink"]);
+
$item["parent-uri"] = $item["uri"];
if (!$simulate) {
$r = q("SELECT `id` FROM `item` WHERE `uid` = %d AND `uri` = '%s' AND `network` IN ('%s', '%s')",
intval($importer["uid"]), dbesc($item["uri"]), dbesc(NETWORK_FEED), dbesc(NETWORK_DFRN));
- if ($r) {
+ if (DBM::is_result($r)) {
logger("Item with uri ".$item["uri"]." for user ".$importer["uid"]." already existed under id ".$r[0]["id"], LOGGER_DEBUG);
continue;
}
@@ -267,6 +288,7 @@ function feed_import($xml,$importer,&$contact, &$hub, $simulate = false) {
if ($creator != "") {
$item["author-name"] = $creator;
}
+
/// @TODO ?
// Ausland
//
@@ -298,6 +320,30 @@ function feed_import($xml,$importer,&$contact, &$hub, $simulate = false) {
$item["attach"] .= '[attach]href="'.$href.'" length="'.$length.'" type="'.$type.'"[/attach]';
}
+ $body = trim($xpath->evaluate('atom:content/text()', $entry)->item(0)->nodeValue);
+
+ if ($body == "") {
+ $body = trim($xpath->evaluate('content:encoded/text()', $entry)->item(0)->nodeValue);
+ }
+ if ($body == "") {
+ $body = trim($xpath->evaluate('description/text()', $entry)->item(0)->nodeValue);
+ }
+ if ($body == "") {
+ $body = trim($xpath->evaluate('atom:summary/text()', $entry)->item(0)->nodeValue);
+ }
+
+ // remove the content of the title if it is identically to the body
+ // This helps with auto generated titles e.g. from tumblr
+ if (title_is_body($item["title"], $body)) {
+ $item["title"] = "";
+ }
+ $item["body"] = html2bbcode($body, $basepath);
+
+ if (($item["body"] == '') && ($item["title"] != '')) {
+ $item["body"] = $item["title"];
+ $item["title"] = '';
+ }
+
if ($contact["fetch_further_information"]) {
$preview = "";
@@ -308,29 +354,36 @@ function feed_import($xml,$importer,&$contact, &$hub, $simulate = false) {
}
}
- $item["body"] = $item["title"].add_page_info($item["plink"], false, $preview, ($contact["fetch_further_information"] == 2), $contact["ffi_keyword_blacklist"]);
- $item["tag"] = add_page_keywords($item["plink"], false, $preview, ($contact["fetch_further_information"] == 2), $contact["ffi_keyword_blacklist"]);
- $item["title"] = "";
- $item["object-type"] = ACTIVITY_OBJ_BOOKMARK;
- unset($item["attach"]);
- } else {
- $body = trim($xpath->evaluate('atom:content/text()', $entry)->item(0)->nodeValue);
+ // Remove a possible link to the item itself
+ $item["body"] = str_replace($item["plink"], '', $item["body"]);
+ $item["body"] = preg_replace('/\[url\=\](\w+.*?)\[\/url\]/i', '', $item["body"]);
+
+ // Replace the content when the title is longer than the body
+ $replace = (strlen($item["title"]) > strlen($item["body"]));
- if ($body == "") {
- $body = trim($xpath->evaluate('content:encoded/text()', $entry)->item(0)->nodeValue);
+ // Replace it, when there is an image in the body
+ if (strstr($item["body"], '[/img]')) {
+ $replace = true;
}
- if ($body == "") {
- $body = trim($xpath->evaluate('description/text()', $entry)->item(0)->nodeValue);
+
+ // Replace it, when there is a link in the body
+ if (strstr($item["body"], '[/url]')) {
+ $replace = true;
}
- if ($body == "") {
- $body = trim($xpath->evaluate('atom:summary/text()', $entry)->item(0)->nodeValue);
+
+ if ($replace) {
+ $item["body"] = $item["title"];
}
- // remove the content of the title if it is identically to the body
- // This helps with auto generated titles e.g. from tumblr
- if (title_is_body($item["title"], $body)) {
- $item["title"] = "";
+ // We always strip the title since it will be added in the page information
+ $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"], false, $preview, ($contact["fetch_further_information"] == 2), $contact["ffi_keyword_blacklist"]);
+ $item["object-type"] = ACTIVITY_OBJ_BOOKMARK;
+ unset($item["attach"]);
+ } else {
+ if (!strstr($item["body"], '[url') && ($item['plink'] != '')) {
+ $item["body"] .= "[hr][url]".$item['plink']."[/url]";
}
- $item["body"] = html2bbcode($body);
}
if (!$simulate) {
@@ -341,6 +394,7 @@ function feed_import($xml,$importer,&$contact, &$hub, $simulate = false) {
// 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'] = uri_to_guid($orig_plink, $a->get_hostname());
unset($item['uri']);
unset($item['parent-uri']);
}
@@ -360,4 +414,3 @@ function feed_import($xml,$importer,&$contact, &$hub, $simulate = false) {
return array("header" => $author, "items" => $items);
}
}
-?>