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 = [];
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"];
}
}
$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);
+ }
}
}