+ $fields = [
+ 'title' => $post['title'],
+ 'body' => $post['body'],
+ 'attach' => $post['attach'],
+ 'file' => $post['file'],
+ 'location' => $post['location'],
+ 'coord' => $post['coord'],
+ 'edited' => DateTimeFormat::utcNow(),
+ 'changed' => DateTimeFormat::utcNow()
+ ];
+
+ $fields['body'] = Item::setHashtags($fields['body']);
+
+ $quote_uri_id = Item::getQuoteUriId($fields['body'], $post['uid']);
+ if (!empty($quote_uri_id)) {
+ $fields['quote-uri-id'] = $quote_uri_id;
+ $fields['body'] = BBCode::removeSharedData($post['body']);
+ }
+
+ Item::update($fields, ['id' => $post['id']]);
+ Item::updateDisplayCache($post['uri-id']);
+
+ if ($return_path) {
+ DI::baseUrl()->redirect($return_path);
+ }
+
+ throw new HTTPException\OKException(DI::l10n()->t('Post updated.'));
+}
+
+function item_insert(int $uid, array $request, bool $preview, string $return_path)
+{
+ $post = ['uid' => $uid];
+ $post = DI::contentItem()->initializePost($post);
+
+ $post['edit'] = null;
+ $post['post-type'] = $request['post_type'] ?? '';
+ $post['wall'] = $request['wall'] ?? true;
+ $post['pubmail'] = $request['pubmail_enable'] ?? false;
+ $post['created'] = $request['created_at'] ?? DateTimeFormat::utcNow();
+ $post['edited'] = $post['changed'] = $post['commented'] = $post['created'];
+ $post['app'] = '';
+ $post['inform'] = '';
+ $post['postopts'] = '';
+ $post['file'] = '';
+
+ if (!empty($request['parent'])) {
+ $parent_item = Post::selectFirst(Item::ITEM_FIELDLIST, ['id' => $request['parent']]);
+ if ($parent_item) {
+ // if this isn't the top-level parent of the conversation, find it