<?php
/**
- * @copyright Copyright (C) 2020, Friendica
+ * @copyright Copyright (C) 2010-2021, the Friendica project
*
* @license GNU AGPL version 3 or any later version
*
use Friendica\Core\Cache\Duration;
use Friendica\Core\Logger;
use Friendica\Core\Protocol;
-use Friendica\Core\Worker;
use Friendica\Database\DBA;
use Friendica\DI;
use Friendica\Model\Contact;
-use Friendica\Model\Conversation;
use Friendica\Model\Item;
use Friendica\Model\Post;
use Friendica\Model\Tag;
use Friendica\Util\DateTimeFormat;
use Friendica\Util\Network;
use Friendica\Util\ParseUrl;
+use Friendica\Util\Proxy;
use Friendica\Util\Strings;
use Friendica\Util\XML;
$header["private"] = Item::PUBLIC;
$header["verb"] = Activity::POST;
$header["object-type"] = Activity\ObjectType::NOTE;
+ $header["post-type"] = Item::PT_ARTICLE;
$header["contact-id"] = $contact["id"] ?? 0;
if (!$dryRun) {
$condition = ["`uid` = ? AND `uri` = ? AND `network` IN (?, ?)",
$importer["uid"], $item["uri"], Protocol::FEED, Protocol::DFRN];
- $previous = Item::selectFirst(['id', 'created'], $condition);
+ $previous = Post::selectFirst(['id', 'created'], $condition);
if (DBA::isResult($previous)) {
// Use the creation date when the post had been stored. It can happen this date changes in the feed.
$creation_dates[] = $previous['created'];
$item["body"] = trim($item["title"]);
}
- $data = ParseUrl::getSiteinfoCached($item['plink'], true);
+ $data = ParseUrl::getSiteinfoCached($item['plink']);
if (!empty($data['text']) && !empty($data['title']) && (mb_strlen($item['body']) < mb_strlen($data['text']))) {
// When the fetched page info text is longer than the body, we do try to enhance the body
if (!empty($item['body']) && (strpos($data['title'], $item['body']) === false) && (strpos($data['text'], $item['body']) === false)) {
}
}
+ if (empty($item['title'])) {
+ $item['post-type'] = Item::PT_NOTE;
+ }
+
Logger::info('Stored feed', ['item' => $item]);
$notify = Item::isRemoteSelf($contact, $item);
}
$condition = ['uid' => $item['uid'], 'uri' => $item['uri']];
- if (!Item::exists($condition) && !Post\Delayed::exists($item["uri"], $item['uid'])) {
+ if (!Post::exists($condition) && !Post\Delayed::exists($item["uri"], $item['uid'])) {
if (!$notify) {
Post\Delayed::publish($item, $notify, $taglist, $attachments);
} else {
$params = ['order' => ['received' => true], 'limit' => $max_items];
if ($filter === 'posts') {
- $ret = Item::selectThread([], $condition, $params);
+ $ret = Post::selectThread(Item::DELIVER_FIELDLIST, $condition, $params);
} else {
- $ret = Item::select([], $condition, $params);
+ $ret = Post::select(Item::DELIVER_FIELDLIST, $condition, $params);
}
- $items = Item::inArray($ret);
+ $items = Post::toArray($ret);
$doc = new DOMDocument('1.0', 'utf-8');
$doc->formatOutput = true;
XML::addElement($doc, $root, "id", DI::baseUrl() . "/profile/" . $owner["nick"]);
XML::addElement($doc, $root, "title", $title);
XML::addElement($doc, $root, "subtitle", sprintf("Updates from %s on %s", $owner["name"], DI::config()->get('config', 'sitename')));
- XML::addElement($doc, $root, "logo", $owner["photo"]);
+ XML::addElement($doc, $root, "logo", Contact::getAvatarUrlForId($owner['id'], Proxy::SIZE_SMALL, $owner['updated']));
XML::addElement($doc, $root, "updated", DateTimeFormat::utcNow(DateTimeFormat::ATOM));
$author = self::addAuthor($doc, $owner);
$condition = ['uid' => $owner["uid"], 'guid' => $repeated_guid, 'private' => [Item::PUBLIC, Item::UNLISTED],
'network' => Protocol::FEDERATED];
- $repeated_item = Item::selectFirst([], $condition);
+ $repeated_item = Post::selectFirst(Item::DELIVER_FIELDLIST, $condition);
if (!DBA::isResult($repeated_item)) {
return false;
}
XML::addElement($doc, $entry, "id", $item["uri"]);
XML::addElement($doc, $entry, "title", html_entity_decode($title, ENT_QUOTES, 'UTF-8'));
- $body = OStatus::formatPicturePost($item['body']);
+ $body = OStatus::formatPicturePost($item['body'], $item['uri-id']);
- $body = BBCode::convert($body, false, BBCode::OSTATUS);
+ $body = BBCode::convertForUriId($item['uri-id'], $body, BBCode::ACTIVITYPUB);
XML::addElement($doc, $entry, "content", $body, ["type" => "html"]);
$mentioned = [];
if ($item['gravity'] != GRAVITY_PARENT) {
- $parent = Item::selectFirst(['guid', 'author-link', 'owner-link'], ['id' => $item['parent']]);
+ $parent = Post::selectFirst(['guid', 'author-link', 'owner-link'], ['id' => $item['parent']]);
- $thrparent = Item::selectFirst(['guid', 'author-link', 'owner-link', 'plink'], ['uid' => $owner["uid"], 'uri' => $item['thr-parent']]);
+ $thrparent = Post::selectFirst(['guid', 'author-link', 'owner-link', 'plink'], ['uid' => $owner["uid"], 'uri' => $item['thr-parent']]);
if (DBA::isResult($thrparent)) {
$mentioned[$thrparent["author-link"]] = $thrparent["author-link"];
private static function getTitle(array $item)
{
if ($item['title'] != '') {
- return BBCode::convert($item['title'], false, BBCode::OSTATUS);
+ return BBCode::convertForUriId($item['uri-id'], $item['title'], BBCode::ACTIVITYPUB);
}
// Fetch information about the post
// Remove the share element before fetching the first line
$title = trim(preg_replace("/\[share.*?\](.*?)\[\/share\]/ism","\n$1\n",$item['body']));
- $title = HTML::toPlaintext(BBCode::convert($title, false), 0, true)."\n";
+ $title = BBCode::toPlaintext($title)."\n";
$pos = strpos($title, "\n");
$trailer = "";
if (($pos == 0) || ($pos > 100)) {