namespace Friendica\Module\Api\Mastodon;
+use Friendica\Content\PageInfo;
+use Friendica\Content\Text\BBCode;
use Friendica\Content\Text\Markdown;
use Friendica\Core\Protocol;
use Friendica\Core\System;
use Friendica\Model\Item;
use Friendica\Model\Photo;
use Friendica\Model\Post;
+use Friendica\Model\Tag;
use Friendica\Model\User;
use Friendica\Module\BaseApi;
use Friendica\Network\HTTPException;
use Friendica\Protocol\Activity;
+use Friendica\Util\DateTimeFormat;
use Friendica\Util\Images;
/**
'in_reply_to_id' => 0, // ID of the status being replied to, if status is a reply
'spoiler_text' => '', // Text to be shown as a warning or subject before the actual content. Statuses are generally collapsed behind this field.
'language' => '', // ISO 639 language code for this status.
+ 'friendica' => [],
], $request);
$owner = User::getOwnerDataById($uid);
'origin' => true,
];
- $post = Post::selectFirst(['uri-id', 'id', 'uid', 'allow_cid', 'allow_gid', 'deny_cid', 'deny_gid'], $condition);
+ $post = Post::selectFirst(['uri-id', 'id', 'gravity', 'uid', 'allow_cid', 'allow_gid', 'deny_cid', 'deny_gid', 'network'], $condition);
if (empty($post['id'])) {
throw new HTTPException\NotFoundException('Item with URI ID ' . $this->parameters['id'] . ' not found for user ' . $uid . '.');
}
// The imput is defined as text. So we can use Markdown for some enhancements
- $item = ['body' => Markdown::toBBCode($request['status']), 'app' => $this->getApp(), 'title' => ''];
+ $body = Markdown::toBBCode($request['status']);
+
+ if (DI::pConfig()->get($uid, 'system', 'api_auto_attach', false) && preg_match("/\[url=[^\[\]]*\](.*)\[\/url\]\z/ism", $body, $matches)) {
+ $body = preg_replace("/\[url=[^\[\]]*\].*\[\/url\]\z/ism", PageInfo::getFooterFromUrl($matches[1]), $body);
+ }
+
+ $item['title'] = '';
+ $item['uid'] = $post['uid'];
+ $item['body'] = $body;
+ $item['network'] = $post['network'];
+ $item['app'] = $this->getApp();
if (!empty($request['language'])) {
$item['language'] = json_encode([$request['language'] => 1]);
}
- if (!empty($request['spoiler_text'])) {
- if (($request['in_reply_to_id'] == $post['uri-id']) && DI::pConfig()->get($uid, 'system', 'api_spoiler_title', true)) {
- $item['title'] = $request['spoiler_text'];
+ if ($post['gravity'] == Item::GRAVITY_PARENT) {
+ $item['title'] = $request['friendica']['title'] ?? '';
+ }
+
+ $spoiler_text = $request['spoiler_text'];
+
+ if (!empty($spoiler_text)) {
+ if (!isset($request['friendica']['title']) && $post['gravity'] == Item::GRAVITY_PARENT && DI::pConfig()->get($uid, 'system', 'api_spoiler_title', true)) {
+ $item['title'] = $spoiler_text;
} else {
- $item['body'] = '[abstract=' . Protocol::ACTIVITYPUB . ']' . $request['spoiler_text'] . "[/abstract]\n" . $item['body'];
+ $item['body'] = '[abstract=' . Protocol::ACTIVITYPUB . ']' . $spoiler_text . "[/abstract]\n" . $item['body'];
+ $item['content-warning'] = BBCode::toPlaintext($spoiler_text);
}
}
+ $item = DI::contentItem()->expandTags($item, $request['visibility'] == 'direct');
+
if (!empty($request['media_ids'])) {
/*
The provided ids in the request value consists of these two sources:
}
unset($item['attachments']);
}
+ if (!Item::isValid($item)) {
+ throw new \Exception('Missing parameters in definition');
+ }
Item::update($item, ['id' => $post['id']]);
+
+ foreach (Tag::getByURIId($post['uri-id']) as $tagToRemove) {
+ Tag::remove($post['uri-id'], $tagToRemove['type'], $tagToRemove['name'], $tagToRemove['url']);
+ }
+ // Store tags from the body if this hadn't been handled previously in the protocol classes
+
+ Tag::storeFromBody($post['uri-id'], Item::setHashtags($item['body']));
+
Item::updateDisplayCache($post['uri-id']);
System::jsonExit(DI::mstdnStatus()->createFromUriId($post['uri-id'], $uid, self::appSupportsQuotes()));
// The imput is defined as text. So we can use Markdown for some enhancements
$body = Markdown::toBBCode($request['status']);
+ if (DI::pConfig()->get($uid, 'system', 'api_auto_attach', false) && preg_match("/\[url=[^\[\]]*\](.*)\[\/url\]\z/ism", $body, $matches)) {
+ $body = preg_replace("/\[url=[^\[\]]*\].*\[\/url\]\z/ism", PageInfo::getFooterFromUrl($matches[1]), $body);
+ }
+
$item = [];
$item['network'] = Protocol::DFRN;
$item['uid'] = $uid;
if (!empty($request['scheduled_at'])) {
$item['guid'] = Item::guid($item, true);
$item['uri'] = Item::newURI($item['guid']);
- $id = Post\Delayed::add($item['uri'], $item, Worker::PRIORITY_HIGH, Post\Delayed::PREPARED, $request['scheduled_at']);
+ $id = Post\Delayed::add($item['uri'], $item, Worker::PRIORITY_HIGH, Post\Delayed::PREPARED, DateTimeFormat::utc($request['scheduled_at']));
if (empty($id)) {
DI::mstdnError()->InternalError();
}