- $datarray['uri-id'] = ItemURI::getIdByURI($datarray['uri']);
- $datarray['body'] = Item::improveSharedDataInBody($datarray);
-
- if ($orig_post) {
- $fields = [
- 'title' => $datarray['title'],
- 'body' => $datarray['body'],
- 'attach' => $datarray['attach'],
- 'file' => $datarray['file'],
- 'edited' => DateTimeFormat::utcNow(),
- 'changed' => DateTimeFormat::utcNow()
- ];
-
- Item::update($fields, ['id' => $post_id]);
- Item::updateDisplayCache($datarray['uri-id']);
-
- if ($return_path) {
- DI::baseUrl()->redirect($return_path);
- }
-
- throw new HTTPException\OKException(DI::l10n()->t('Post updated.'));
- }
-
- unset($datarray['edit']);
- unset($datarray['self']);
- unset($datarray['api_source']);
-
- $post_id = Item::insert($datarray);
-
- if (!$post_id) {
- DI::sysmsg()->addNotice(DI::l10n()->t('Item wasn\'t stored.'));
- if ($return_path) {
- DI::baseUrl()->redirect($return_path);
- }
-
- throw new HTTPException\InternalServerErrorException(DI::l10n()->t('Item wasn\'t stored.'));
- }
-
- $datarray = Post::selectFirst(Item::ITEM_FIELDLIST, ['id' => $post_id]);
-
- if (!DBA::isResult($datarray)) {
- Logger::error('Item couldn\'t be fetched.', ['post_id' => $post_id]);
- if ($return_path) {
- DI::baseUrl()->redirect($return_path);
- }
-
- throw new HTTPException\InternalServerErrorException(DI::l10n()->t('Item couldn\'t be fetched.'));
- }
-
- Tag::storeFromBody($datarray['uri-id'], $datarray['body']);
-
- if (!\Friendica\Content\Feature::isEnabled($uid, 'explicit_mentions') && ($datarray['gravity'] == Item::GRAVITY_COMMENT)) {
- Tag::createImplicitMentions($datarray['uri-id'], $datarray['thr-parent-id']);
- }
-
- // These notifications are sent if someone else is commenting other your wall
- if ($contact_record != $author) {
- if ($toplevel_item_id) {
- DI::notify()->createFromArray([
- 'type' => Notification\Type::COMMENT,
- 'otype' => Notification\ObjectType::ITEM,
- 'verb' => Activity::POST,
- 'uid' => $profile_uid,
- 'cid' => $datarray['author-id'],
- 'item' => $datarray,
- 'link' => DI::baseUrl() . '/display/' . urlencode($datarray['guid']),
- ]);
- } elseif (empty($forum_contact)) {
- DI::notify()->createFromArray([
- 'type' => Notification\Type::WALL,
- 'otype' => Notification\ObjectType::ITEM,
- 'verb' => Activity::POST,
- 'uid' => $profile_uid,
- 'cid' => $datarray['author-id'],
- 'item' => $datarray,
- 'link' => DI::baseUrl() . '/display/' . urlencode($datarray['guid']),
- ]);
- }
- }
-
- Hook::callAll('post_local_end', $datarray);
-
- if (strlen($emailcc) && $profile_uid == DI::userSession()->getLocalUserId()) {
- $recipients = explode(',', $emailcc);
- if (count($recipients)) {
- foreach ($recipients as $recipient) {
- $address = trim($recipient);
- if (!strlen($address)) {
- continue;
- }
- DI::emailer()->send(new ItemCCEMail(DI::app(), DI::l10n(), DI::baseUrl(),
- $datarray, $address, $author['thumb'] ?? ''));
- }
- }
- }
-
- Logger::debug('post_complete');
-
- if ($api_source) {
- return $post_id;
- }
-
- item_post_return(DI::baseUrl(), $api_source, $return_path);
- // NOTREACHED