use Friendica\DI;
use Friendica\Model\Contact;
use Friendica\Model\Item;
+use Friendica\Model\Post;
use Friendica\Model\Tag;
use Friendica\Model\User;
use Friendica\Util\DateTimeFormat;
$enclosures = $xpath->query("enclosure|atom:link[@rel='enclosure']", $entry);
foreach ($enclosures AS $enclosure) {
$href = "";
- $length = "";
- $type = "";
+ $length = null;
+ $type = null;
foreach ($enclosure->attributes AS $attribute) {
if (in_array($attribute->name, ["url", "href"])) {
$href = $attribute->textContent;
} elseif ($attribute->name == "length") {
- $length = $attribute->textContent;
+ $length = (int)$attribute->textContent;
} elseif ($attribute->name == "type") {
$type = $attribute->textContent;
}
}
- if (!empty($item["attach"])) {
- $item["attach"] .= ',';
- } else {
- $item["attach"] = '';
+ if (!empty($href)) {
+ $attachments[] = ['type' => Post\Media::DOCUMENT, 'url' => $href, 'mimetype' => $type, 'size' => $length];
}
-
- $attachments[] = ["link" => $href, "type" => $type, "length" => $length];
-
- $item["attach"] .= '[attach]href="' . $href . '" length="' . $length . '" type="' . $type . '"[/attach]';
}
$taglist = [];
}
$item["body"] = HTML::toBBCode($body, $basepath);
+ // Remove tracking pixels
+ $item["body"] = preg_replace("/\[img=1x1\]([^\[\]]*)\[\/img\]/Usi", '', $item["body"]);
+
if (($item["body"] == '') && ($item["title"] != '')) {
$item["body"] = $item["title"];
$item["title"] = '';
if (!empty($contact["fetch_further_information"]) && ($contact["fetch_further_information"] < 3)) {
// Handle enclosures and treat them as preview picture
foreach ($attachments AS $attachment) {
- if ($attachment["type"] == "image/jpeg") {
- $preview = $attachment["link"];
+ if ($attachment["mimetype"] == "image/jpeg") {
+ $preview = $attachment["url"];
}
}
$replace = true;
}
+ $saved_body = $item["body"];
+ $saved_title = $item["title"];
+
if ($replace) {
$item["body"] = trim($item["title"]);
}
}
}
+ $data = PageInfo::queryUrl($item["plink"], false, $preview, ($contact["fetch_further_information"] == 2), $contact["ffi_keyword_denylist"] ?? '');
+
+ // Take the data that was provided by the feed if the query is empty
+ if (($data['type'] == 'link') && empty($data['title']) && empty($data['text'])) {
+ $data['title'] = $saved_title;
+ $item["body"] = $saved_body;
+ }
+
+ $data_text = strip_tags(trim($data['text'] ?? ''));
+ $item_body = strip_tags(trim($item['body'] ?? ''));
+
+ if (!empty($data_text) && (($data_text == $item_body) || strstr($item_body, $data_text))) {
+ $data['text'] = '';
+ }
+
// We always strip the title since it will be added in the page information
$item["title"] = "";
- $item["body"] = $item["body"] . "\n" . PageInfo::getFooterFromUrl($item["plink"], false, $preview, ($contact["fetch_further_information"] == 2), $contact["ffi_keyword_denylist"] ?? '');
+ $item["body"] = $item["body"] . "\n" . PageInfo::getFooterFromData($data, false);
$taglist = $contact["fetch_further_information"] == 2 ? PageInfo::getTagsFromUrl($item["plink"], $preview, $contact["ffi_keyword_denylist"] ?? '') : [];
$item["object-type"] = Activity\ObjectType::BOOKMARK;
- unset($item["attach"]);
+ $attachments = [];
} else {
if (!empty($summary)) {
$item["body"] = '[abstract]' . HTML::toBBCode($summary, $basepath) . "[/abstract]\n" . $item["body"];
Logger::info("Feed for contact " . $contact["url"] . " stored under id " . $id);
- if (!empty($id) && !empty($taglist)) {
+ if (!empty($id) && (!empty($taglist) || !empty($attachments))) {
$feeditem = Item::selectFirst(['uri-id'], ['id' => $id]);
foreach ($taglist as $tag) {
Tag::store($feeditem['uri-id'], Tag::HASHTAG, $tag);
}
+ foreach ($attachments as $attachment) {
+ $attachment['uri-id'] = $feeditem['uri-id'];
+ Post\Media::insert($attachment);
+ }
}
}