2010-07-01 19:48:07 -04:00
|
|
|
<?php
|
2017-12-01 18:13:39 -05:00
|
|
|
/**
|
2023-01-01 09:36:24 -05:00
|
|
|
* @copyright Copyright (C) 2010-2023, the Friendica project
|
2020-02-09 10:18:46 -05:00
|
|
|
*
|
|
|
|
* @license GNU AGPL version 3 or any later version
|
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU Affero General Public License as
|
|
|
|
* published by the Free Software Foundation, either version 3 of the
|
|
|
|
* License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU Affero General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Affero General Public License
|
|
|
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
|
|
*
|
2011-02-04 16:37:04 -05:00
|
|
|
* This is the POST destination for most all locally posted
|
2013-12-26 19:58:21 -05:00
|
|
|
* text stuff. This function handles status, wall-to-wall status,
|
2023-03-21 23:17:06 -04:00
|
|
|
* local comments, and remote comments that are posted on this site
|
2011-02-04 16:37:04 -05:00
|
|
|
* (as opposed to being delivered in a feed).
|
2013-12-26 19:58:21 -05:00
|
|
|
* Also processed here are posts and comments coming through the
|
|
|
|
* statusnet/twitter API.
|
2017-03-30 15:32:12 -04:00
|
|
|
*
|
2013-12-26 19:58:21 -05:00
|
|
|
* All of these become an "item" which is our basic unit of
|
2011-02-04 16:37:04 -05:00
|
|
|
* information.
|
2013-12-26 19:58:21 -05:00
|
|
|
*/
|
2018-01-24 21:08:45 -05:00
|
|
|
|
2017-04-30 00:07:00 -04:00
|
|
|
use Friendica\App;
|
2023-01-12 01:25:55 -05:00
|
|
|
use Friendica\Content\Conversation;
|
2018-01-26 20:01:32 -05:00
|
|
|
use Friendica\Content\Text\BBCode;
|
2018-12-26 01:06:24 -05:00
|
|
|
use Friendica\Core\Hook;
|
2018-10-29 17:20:46 -04:00
|
|
|
use Friendica\Core\Logger;
|
2018-08-11 16:40:44 -04:00
|
|
|
use Friendica\Core\Protocol;
|
2019-10-22 18:14:47 -04:00
|
|
|
use Friendica\Core\System;
|
2022-10-17 01:49:55 -04:00
|
|
|
use Friendica\Core\Worker;
|
2018-07-20 08:19:26 -04:00
|
|
|
use Friendica\Database\DBA;
|
2019-12-15 17:28:01 -05:00
|
|
|
use Friendica\DI;
|
2017-12-07 09:04:24 -05:00
|
|
|
use Friendica\Model\Contact;
|
2018-01-09 16:13:45 -05:00
|
|
|
use Friendica\Model\Item;
|
2021-04-26 06:49:57 -04:00
|
|
|
use Friendica\Model\ItemURI;
|
2020-10-31 09:26:08 -04:00
|
|
|
use Friendica\Model\Post;
|
2020-01-29 22:43:37 -05:00
|
|
|
use Friendica\Network\HTTPException;
|
2021-01-23 04:53:44 -05:00
|
|
|
use Friendica\Util\DateTimeFormat;
|
2017-04-30 00:07:00 -04:00
|
|
|
|
2017-01-09 07:14:25 -05:00
|
|
|
function item_post(App $a) {
|
2023-01-04 00:44:52 -05:00
|
|
|
$uid = DI::userSession()->getLocalUserId();
|
|
|
|
|
2023-01-07 13:46:10 -05:00
|
|
|
if (!$uid) {
|
2020-01-29 22:43:37 -05:00
|
|
|
throw new HTTPException\ForbiddenException();
|
2017-03-30 15:32:12 -04:00
|
|
|
}
|
2010-07-01 19:48:07 -04:00
|
|
|
|
2018-07-24 17:48:47 -04:00
|
|
|
if (!empty($_REQUEST['dropitems'])) {
|
2023-01-04 05:59:28 -05:00
|
|
|
item_drop($uid, $_REQUEST['dropitems']);
|
2011-06-15 23:43:39 -04:00
|
|
|
}
|
|
|
|
|
2018-12-26 01:06:24 -05:00
|
|
|
Hook::callAll('post_local_start', $_REQUEST);
|
2018-01-20 14:51:23 -05:00
|
|
|
|
2019-10-15 09:01:17 -04:00
|
|
|
$return_path = $_REQUEST['return'] ?? '';
|
2023-01-04 00:44:52 -05:00
|
|
|
$preview = intval($_REQUEST['preview'] ?? 0);
|
2011-07-31 23:01:00 -04:00
|
|
|
|
2017-03-30 15:32:12 -04:00
|
|
|
/*
|
|
|
|
* Check for doubly-submitted posts, and reject duplicates
|
|
|
|
* Note that we have to ignore previews, otherwise nothing will post
|
|
|
|
* after it's been previewed
|
|
|
|
*/
|
2018-07-24 17:48:47 -04:00
|
|
|
if (!$preview && !empty($_REQUEST['post_id_random'])) {
|
2023-01-07 13:46:10 -05:00
|
|
|
if (DI::session()->get('post-random') == $_REQUEST['post_id_random']) {
|
2022-08-30 15:45:30 -04:00
|
|
|
Logger::warning('duplicate post');
|
2022-11-23 01:27:40 -05:00
|
|
|
item_post_return(DI::baseUrl(), $return_path);
|
2017-03-30 15:32:12 -04:00
|
|
|
} else {
|
2023-01-07 13:46:10 -05:00
|
|
|
DI::session()->set('post-random', $_REQUEST['post_id_random']);
|
2016-12-20 15:15:53 -05:00
|
|
|
}
|
2012-11-01 19:14:42 -04:00
|
|
|
}
|
|
|
|
|
2023-01-04 05:59:28 -05:00
|
|
|
if (empty($_REQUEST['post_id'])) {
|
|
|
|
item_insert($uid, $_REQUEST, $preview, $return_path);
|
2023-01-04 00:44:52 -05:00
|
|
|
} else {
|
2023-01-04 05:59:28 -05:00
|
|
|
item_edit($uid, $_REQUEST, $preview, $return_path);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function item_drop(int $uid, string $dropitems)
|
|
|
|
{
|
|
|
|
$arr_drop = explode(',', $dropitems);
|
|
|
|
foreach ($arr_drop as $item) {
|
|
|
|
Item::deleteForUser(['id' => $item], $uid);
|
2023-01-04 00:44:52 -05:00
|
|
|
}
|
|
|
|
|
2023-01-07 13:46:10 -05:00
|
|
|
System::jsonExit(['success' => 1]);
|
2023-01-04 05:59:28 -05:00
|
|
|
}
|
2023-01-04 00:44:52 -05:00
|
|
|
|
2023-01-04 05:59:28 -05:00
|
|
|
function item_edit(int $uid, array $request, bool $preview, string $return_path)
|
|
|
|
{
|
|
|
|
$post = Post::selectFirst(Item::ITEM_FIELDLIST, ['id' => $request['post_id'], 'uid' => $uid]);
|
|
|
|
if (!DBA::isResult($post)) {
|
|
|
|
if ($return_path) {
|
2023-01-07 13:46:10 -05:00
|
|
|
DI::sysmsg()->addNotice(DI::l10n()->t('Unable to locate original post.'));
|
2023-01-04 05:59:28 -05:00
|
|
|
DI::baseUrl()->redirect($return_path);
|
|
|
|
}
|
|
|
|
throw new HTTPException\NotFoundException(DI::l10n()->t('Unable to locate original post.'));
|
|
|
|
}
|
|
|
|
|
|
|
|
$post['edit'] = $post;
|
2023-02-04 19:14:21 -05:00
|
|
|
$post['file'] = Post\Category::getTextByURIId($post['uri-id'], $post['uid']);
|
2023-01-04 05:59:28 -05:00
|
|
|
|
2023-03-20 10:19:51 -04:00
|
|
|
Post\Media::deleteByURIId($post['uri-id'], [Post\Media::AUDIO, Post\Media::VIDEO, Post\Media::IMAGE, Post\Media::HTML]);
|
2023-01-04 05:59:28 -05:00
|
|
|
$post = item_process($post, $request, $preview, $return_path);
|
|
|
|
|
|
|
|
$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.'));
|
|
|
|
}
|
2023-01-04 00:44:52 -05:00
|
|
|
|
2023-01-04 05:59:28 -05:00
|
|
|
function item_insert(int $uid, array $request, bool $preview, string $return_path)
|
|
|
|
{
|
|
|
|
$post = ['uid' => $uid];
|
2023-01-04 00:44:52 -05:00
|
|
|
$post = DI::contentItem()->initializePost($post);
|
|
|
|
|
2023-01-04 05:59:28 -05:00
|
|
|
$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'] = '';
|
2023-01-04 00:44:52 -05:00
|
|
|
|
2023-01-07 13:19:04 -05:00
|
|
|
if (!empty($request['parent'])) {
|
|
|
|
$parent_item = Post::selectFirst(Item::ITEM_FIELDLIST, ['id' => $request['parent']]);
|
2023-01-07 13:54:13 -05:00
|
|
|
if ($parent_item) {
|
2023-01-07 13:07:54 -05:00
|
|
|
// if this isn't the top-level parent of the conversation, find it
|
2022-09-12 17:12:11 -04:00
|
|
|
if ($parent_item['gravity'] != Item::GRAVITY_PARENT) {
|
2023-01-07 13:07:54 -05:00
|
|
|
$toplevel_item = Post::selectFirst(Item::ITEM_FIELDLIST, ['id' => $parent_item['parent']]);
|
|
|
|
} else {
|
|
|
|
$toplevel_item = $parent_item;
|
2011-07-31 23:01:00 -04:00
|
|
|
}
|
2012-07-23 07:58:47 -04:00
|
|
|
}
|
2011-07-31 20:52:36 -04:00
|
|
|
|
2023-01-07 13:07:54 -05:00
|
|
|
if (empty($toplevel_item)) {
|
2020-01-29 22:34:32 -05:00
|
|
|
if ($return_path) {
|
2023-01-07 13:46:10 -05:00
|
|
|
DI::sysmsg()->addNotice(DI::l10n()->t('Unable to locate original post.'));
|
2019-12-15 18:28:31 -05:00
|
|
|
DI::baseUrl()->redirect($return_path);
|
2016-12-20 15:15:53 -05:00
|
|
|
}
|
2020-01-29 22:43:37 -05:00
|
|
|
throw new HTTPException\NotFoundException(DI::l10n()->t('Unable to locate original post.'));
|
2010-07-13 19:09:53 -04:00
|
|
|
}
|
2018-01-20 08:54:14 -05:00
|
|
|
|
2020-07-21 19:26:01 -04:00
|
|
|
// When commenting on a public post then store the post for the current user
|
|
|
|
// This enables interaction like starring and saving into folders
|
|
|
|
if ($toplevel_item['uid'] == 0) {
|
2023-01-04 00:44:52 -05:00
|
|
|
$stored = Item::storeForUserByUriId($toplevel_item['uri-id'], $post['uid'], ['post-reason' => Item::PR_ACTIVITY]);
|
|
|
|
Logger::info('Public item stored for user', ['uri-id' => $toplevel_item['uri-id'], 'uid' => $post['uid'], 'stored' => $stored]);
|
2020-07-21 19:26:01 -04:00
|
|
|
}
|
|
|
|
|
2023-01-10 00:59:25 -05:00
|
|
|
$post['parent'] = $toplevel_item['id'];
|
2023-01-04 00:44:52 -05:00
|
|
|
$post['gravity'] = Item::GRAVITY_COMMENT;
|
2023-01-07 13:07:54 -05:00
|
|
|
$post['thr-parent'] = $parent_item['uri'];
|
2023-01-04 00:44:52 -05:00
|
|
|
$post['wall'] = $toplevel_item['wall'];
|
2018-08-04 10:06:36 -04:00
|
|
|
} else {
|
2023-01-04 00:44:52 -05:00
|
|
|
$parent_item = [];
|
2023-01-10 00:59:25 -05:00
|
|
|
$post['parent'] = 0;
|
2023-01-04 00:44:52 -05:00
|
|
|
$post['gravity'] = Item::GRAVITY_PARENT;
|
|
|
|
$post['thr-parent'] = $post['uri'];
|
2011-03-18 08:06:16 -04:00
|
|
|
}
|
|
|
|
|
2023-01-04 05:59:28 -05:00
|
|
|
$post = DI::contentItem()->getACL($post, $parent_item, $request);
|
2011-11-28 23:09:10 -05:00
|
|
|
|
2023-01-04 00:44:52 -05:00
|
|
|
$post['pubmail'] = $post['pubmail'] && !$post['private'];
|
2019-10-13 11:52:33 -04:00
|
|
|
|
2023-01-04 05:59:28 -05:00
|
|
|
$post = item_process($post, $request, $preview, $return_path);
|
|
|
|
|
|
|
|
$post_id = Item::insert($post);
|
|
|
|
if (!$post_id) {
|
|
|
|
if ($return_path) {
|
2023-01-07 13:46:10 -05:00
|
|
|
DI::sysmsg()->addNotice(DI::l10n()->t('Item wasn\'t stored.'));
|
2023-01-04 05:59:28 -05:00
|
|
|
DI::baseUrl()->redirect($return_path);
|
|
|
|
}
|
|
|
|
|
|
|
|
throw new HTTPException\InternalServerErrorException(DI::l10n()->t('Item wasn\'t stored.'));
|
|
|
|
}
|
|
|
|
|
|
|
|
$post = Post::selectFirst(Item::ITEM_FIELDLIST, ['id' => $post_id]);
|
2023-01-07 13:54:13 -05:00
|
|
|
if (!$post) {
|
2023-01-04 05:59:28 -05:00
|
|
|
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.'));
|
2012-04-01 21:28:31 -04:00
|
|
|
}
|
|
|
|
|
2023-01-07 13:19:04 -05:00
|
|
|
$recipients = explode(',', $request['emailcc'] ?? '');
|
2023-01-04 05:59:28 -05:00
|
|
|
|
|
|
|
DI::contentItem()->postProcessPost($post, $recipients);
|
|
|
|
|
2023-10-29 04:49:24 -04:00
|
|
|
if (($post['private'] == Item::PRIVATE) && ($post['thr-parent-id'] != $post['uri-id'])) {
|
|
|
|
DI::contentItem()->copyPermissions($post['thr-parent-id'], $post['uri-id']);
|
|
|
|
}
|
|
|
|
|
2023-01-04 05:59:28 -05:00
|
|
|
Logger::debug('post_complete');
|
|
|
|
|
|
|
|
item_post_return(DI::baseUrl(), $return_path);
|
|
|
|
// NOTREACHED
|
|
|
|
}
|
|
|
|
|
|
|
|
function item_process(array $post, array $request, bool $preview, string $return_path): array
|
|
|
|
{
|
|
|
|
$post['self'] = true;
|
|
|
|
$post['api_source'] = false;
|
|
|
|
$post['attach'] = '';
|
|
|
|
$post['title'] = trim($request['title'] ?? '');
|
|
|
|
$post['body'] = $request['body'] ?? '';
|
|
|
|
$post['location'] = trim($request['location'] ?? '');
|
|
|
|
$post['coord'] = trim($request['coord'] ?? '');
|
|
|
|
|
|
|
|
$post = DI::contentItem()->addCategories($post, $request['category'] ?? '');
|
2010-07-17 22:26:00 -04:00
|
|
|
|
2023-01-04 00:44:52 -05:00
|
|
|
// Add the attachment to the body.
|
2023-01-04 05:59:28 -05:00
|
|
|
if (!empty($request['has_attachment'])) {
|
|
|
|
$post['body'] .= DI::contentItem()->storeAttachmentFromRequest($request);
|
2023-01-04 00:44:52 -05:00
|
|
|
}
|
2012-02-25 17:22:51 -05:00
|
|
|
|
2023-01-04 00:44:52 -05:00
|
|
|
$post = DI::contentItem()->finalizePost($post);
|
2014-08-07 02:02:24 -04:00
|
|
|
|
2023-01-04 00:44:52 -05:00
|
|
|
if (!strlen($post['body'])) {
|
|
|
|
if ($preview) {
|
|
|
|
System::jsonExit(['preview' => '']);
|
2017-03-30 15:32:12 -04:00
|
|
|
}
|
2014-08-07 02:02:24 -04:00
|
|
|
|
2023-01-04 00:44:52 -05:00
|
|
|
if ($return_path) {
|
2023-01-07 13:46:10 -05:00
|
|
|
DI::sysmsg()->addNotice(DI::l10n()->t('Empty post discarded.'));
|
2023-01-04 00:44:52 -05:00
|
|
|
DI::baseUrl()->redirect($return_path);
|
2011-05-25 05:08:15 -04:00
|
|
|
}
|
2013-12-26 19:58:21 -05:00
|
|
|
|
2023-01-04 00:44:52 -05:00
|
|
|
throw new HTTPException\BadRequestException(DI::l10n()->t('Empty post discarded.'));
|
2018-08-04 10:06:36 -04:00
|
|
|
}
|
2013-12-26 19:58:21 -05:00
|
|
|
|
2012-01-05 18:02:44 -05:00
|
|
|
// preview mode - prepare the body for display and send it via json
|
2017-03-30 15:32:12 -04:00
|
|
|
if ($preview) {
|
2023-01-04 01:52:40 -05:00
|
|
|
// We have to preset some fields, so that the conversation can be displayed
|
|
|
|
$post['id'] = -1;
|
|
|
|
$post['uri-id'] = -1;
|
2023-01-04 00:44:52 -05:00
|
|
|
$post['author-network'] = Protocol::DFRN;
|
|
|
|
$post['author-updated'] = '';
|
2023-08-09 16:29:45 -04:00
|
|
|
$post['author-alias'] = '';
|
2023-01-04 01:52:40 -05:00
|
|
|
$post['author-gsid'] = 0;
|
|
|
|
$post['author-uri-id'] = ItemURI::getIdByURI($post['author-link']);
|
|
|
|
$post['owner-updated'] = '';
|
|
|
|
$post['has-media'] = false;
|
|
|
|
$post['quote-uri-id'] = Item::getQuoteUriId($post['body'], $post['uid']);
|
|
|
|
$post['body'] = BBCode::removeSharedData(Item::setHashtags($post['body']));
|
|
|
|
$post['writable'] = true;
|
2023-01-04 00:44:52 -05:00
|
|
|
|
2023-02-04 19:14:21 -05:00
|
|
|
$o = DI::conversation()->render([$post], Conversation::MODE_SEARCH, false, true);
|
2020-01-29 22:31:13 -05:00
|
|
|
|
|
|
|
System::jsonExit(['preview' => $o]);
|
2021-08-06 14:49:17 -04:00
|
|
|
}
|
|
|
|
|
2023-01-04 00:44:52 -05:00
|
|
|
Hook::callAll('post_local',$post);
|
2021-08-06 14:49:17 -04:00
|
|
|
|
2023-01-04 01:52:40 -05:00
|
|
|
unset($post['edit']);
|
|
|
|
unset($post['self']);
|
|
|
|
unset($post['api_source']);
|
|
|
|
|
2023-01-04 05:59:28 -05:00
|
|
|
if (!empty($request['scheduled_at'])) {
|
|
|
|
$scheduled_at = DateTimeFormat::convert($request['scheduled_at'], 'UTC', DI::app()->getTimeZone());
|
2021-08-01 09:01:31 -04:00
|
|
|
if ($scheduled_at > DateTimeFormat::utcNow()) {
|
2023-01-04 00:44:52 -05:00
|
|
|
unset($post['created']);
|
|
|
|
unset($post['edited']);
|
|
|
|
unset($post['commented']);
|
|
|
|
unset($post['received']);
|
|
|
|
unset($post['changed']);
|
|
|
|
|
|
|
|
Post\Delayed::add($post['uri'], $post, Worker::PRIORITY_HIGH, Post\Delayed::PREPARED_NO_HOOK, $scheduled_at);
|
2022-11-23 01:27:40 -05:00
|
|
|
item_post_return(DI::baseUrl(), $return_path);
|
2021-08-01 09:01:31 -04:00
|
|
|
}
|
2012-01-05 18:02:44 -05:00
|
|
|
}
|
|
|
|
|
2023-01-04 00:44:52 -05:00
|
|
|
if (!empty($post['cancel'])) {
|
2020-01-29 22:42:49 -05:00
|
|
|
Logger::info('mod_item: post cancelled by addon.');
|
2017-03-30 15:32:12 -04:00
|
|
|
if ($return_path) {
|
2019-12-15 18:28:31 -05:00
|
|
|
DI::baseUrl()->redirect($return_path);
|
2012-01-30 23:49:54 -05:00
|
|
|
}
|
|
|
|
|
2018-01-15 08:05:12 -05:00
|
|
|
$json = ['cancel' => 1];
|
2023-01-04 05:59:28 -05:00
|
|
|
if (!empty($request['jsreload'])) {
|
|
|
|
$json['reload'] = DI::baseUrl() . '/' . $request['jsreload'];
|
2016-12-20 05:18:54 -05:00
|
|
|
}
|
2012-01-30 23:49:54 -05:00
|
|
|
|
2020-01-29 22:31:13 -05:00
|
|
|
System::jsonExit($json);
|
2012-01-30 23:49:54 -05:00
|
|
|
}
|
|
|
|
|
2023-01-04 05:59:28 -05:00
|
|
|
return $post;
|
2012-11-01 19:14:42 -04:00
|
|
|
}
|
2018-01-20 12:34:53 -05:00
|
|
|
|
2022-11-23 01:27:40 -05:00
|
|
|
function item_post_return($baseurl, $return_path)
|
2018-07-24 17:48:47 -04:00
|
|
|
{
|
2016-12-20 05:18:54 -05:00
|
|
|
if ($return_path) {
|
2019-12-15 18:28:31 -05:00
|
|
|
DI::baseUrl()->redirect($return_path);
|
2011-02-17 00:17:49 -05:00
|
|
|
}
|
2011-09-12 00:52:50 -04:00
|
|
|
|
2018-01-15 08:05:12 -05:00
|
|
|
$json = ['success' => 1];
|
2018-11-30 09:06:22 -05:00
|
|
|
if (!empty($_REQUEST['jsreload'])) {
|
2012-11-01 19:14:42 -04:00
|
|
|
$json['reload'] = $baseurl . '/' . $_REQUEST['jsreload'];
|
2016-12-20 05:18:54 -05:00
|
|
|
}
|
2011-02-17 00:17:49 -05:00
|
|
|
|
2022-08-30 15:45:30 -04:00
|
|
|
Logger::debug('post_json', ['json' => $json]);
|
2011-02-17 00:17:49 -05:00
|
|
|
|
2020-01-29 22:31:13 -05:00
|
|
|
System::jsonExit($json);
|
2010-07-26 20:01:37 -04:00
|
|
|
}
|
|
|
|
|
2018-07-24 17:48:47 -04:00
|
|
|
function item_content(App $a)
|
|
|
|
{
|
2022-10-20 15:02:49 -04:00
|
|
|
if (!DI::userSession()->isAuthenticated()) {
|
2021-01-20 18:44:02 -05:00
|
|
|
throw new HTTPException\UnauthorizedException();
|
|
|
|
}
|
|
|
|
|
|
|
|
$args = DI::args();
|
|
|
|
|
2023-07-25 14:16:18 -04:00
|
|
|
if (!$args->has(2)) {
|
2021-01-20 18:44:02 -05:00
|
|
|
throw new HTTPException\BadRequestException();
|
2016-12-20 05:18:54 -05:00
|
|
|
}
|
2010-07-26 20:01:37 -04:00
|
|
|
|
2013-01-26 14:52:21 -05:00
|
|
|
$o = '';
|
2021-01-20 18:44:02 -05:00
|
|
|
switch ($args->get(1)) {
|
|
|
|
case 'drop':
|
|
|
|
if (DI::mode()->isAjax()) {
|
2022-10-20 15:02:49 -04:00
|
|
|
Item::deleteForUser(['id' => $args->get(2)], DI::userSession()->getLocalUserId());
|
2021-01-20 18:44:02 -05:00
|
|
|
// ajax return: [<item id>, 0 (no perm) | <owner id>]
|
2022-10-20 15:02:49 -04:00
|
|
|
System::jsonExit([intval($args->get(2)), DI::userSession()->getLocalUserId()]);
|
2021-01-20 18:44:02 -05:00
|
|
|
} else {
|
|
|
|
if (!empty($args->get(3))) {
|
|
|
|
$o = drop_item($args->get(2), $args->get(3));
|
|
|
|
} else {
|
|
|
|
$o = drop_item($args->get(2));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
2022-09-12 18:09:18 -04:00
|
|
|
|
2021-01-20 18:44:02 -05:00
|
|
|
case 'block':
|
2022-10-20 15:02:49 -04:00
|
|
|
$item = Post::selectFirstForUser(DI::userSession()->getLocalUserId(), ['guid', 'author-id', 'parent', 'gravity'], ['id' => $args->get(2)]);
|
2021-01-20 18:44:02 -05:00
|
|
|
if (empty($item['author-id'])) {
|
|
|
|
throw new HTTPException\NotFoundException('Item not found');
|
|
|
|
}
|
2018-07-24 17:48:47 -04:00
|
|
|
|
2022-10-20 15:02:49 -04:00
|
|
|
Contact\User::setBlocked($item['author-id'], DI::userSession()->getLocalUserId(), true);
|
2021-01-20 18:44:02 -05:00
|
|
|
|
2023-01-09 11:23:39 -05:00
|
|
|
if (DI::mode()->isAjax()) {
|
|
|
|
// ajax return: [<item id>, 0 (no perm) | <owner id>]
|
|
|
|
System::jsonExit([intval($args->get(2)), DI::userSession()->getLocalUserId()]);
|
|
|
|
} else {
|
|
|
|
item_redirect_after_action($item, $args->get(3));
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'ignore':
|
|
|
|
$item = Post::selectFirstForUser(DI::userSession()->getLocalUserId(), ['guid', 'author-id', 'parent', 'gravity'], ['id' => $args->get(2)]);
|
|
|
|
if (empty($item['author-id'])) {
|
|
|
|
throw new HTTPException\NotFoundException('Item not found');
|
|
|
|
}
|
|
|
|
|
|
|
|
Contact\User::setIgnored($item['author-id'], DI::userSession()->getLocalUserId(), true);
|
|
|
|
|
2023-05-20 08:24:19 -04:00
|
|
|
if (DI::mode()->isAjax()) {
|
|
|
|
// ajax return: [<item id>, 0 (no perm) | <owner id>]
|
|
|
|
System::jsonExit([intval($args->get(2)), DI::userSession()->getLocalUserId()]);
|
|
|
|
} else {
|
|
|
|
item_redirect_after_action($item, $args->get(3));
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'collapse':
|
|
|
|
$item = Post::selectFirstForUser(DI::userSession()->getLocalUserId(), ['guid', 'author-id', 'parent', 'gravity'], ['id' => $args->get(2)]);
|
|
|
|
if (empty($item['author-id'])) {
|
|
|
|
throw new HTTPException\NotFoundException('Item not found');
|
|
|
|
}
|
|
|
|
|
|
|
|
Contact\User::setCollapsed($item['author-id'], DI::userSession()->getLocalUserId(), true);
|
|
|
|
|
2021-01-20 18:44:02 -05:00
|
|
|
if (DI::mode()->isAjax()) {
|
|
|
|
// ajax return: [<item id>, 0 (no perm) | <owner id>]
|
2022-10-20 15:02:49 -04:00
|
|
|
System::jsonExit([intval($args->get(2)), DI::userSession()->getLocalUserId()]);
|
2021-01-20 18:44:02 -05:00
|
|
|
} else {
|
|
|
|
item_redirect_after_action($item, $args->get(3));
|
2018-10-26 08:05:59 -04:00
|
|
|
}
|
2021-01-20 18:44:02 -05:00
|
|
|
break;
|
2020-06-17 04:50:28 -04:00
|
|
|
}
|
2018-07-24 17:48:47 -04:00
|
|
|
|
2020-06-17 04:50:28 -04:00
|
|
|
return $o;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param int $id
|
|
|
|
* @param string $return
|
|
|
|
* @return string
|
|
|
|
* @throws HTTPException\InternalServerErrorException
|
|
|
|
*/
|
2022-09-12 17:12:11 -04:00
|
|
|
function drop_item(int $id, string $return = ''): string
|
2020-06-17 04:50:28 -04:00
|
|
|
{
|
2022-09-12 17:12:11 -04:00
|
|
|
// Locate item to be deleted
|
2022-10-20 15:02:49 -04:00
|
|
|
$item = Post::selectFirstForUser(DI::userSession()->getLocalUserId(), ['id', 'uid', 'guid', 'contact-id', 'deleted', 'gravity', 'parent'], ['id' => $id]);
|
2020-06-17 04:50:28 -04:00
|
|
|
|
|
|
|
if (!DBA::isResult($item)) {
|
2022-10-17 07:27:32 -04:00
|
|
|
DI::sysmsg()->addNotice(DI::l10n()->t('Item not found.'));
|
2020-06-17 04:50:28 -04:00
|
|
|
DI::baseUrl()->redirect('network');
|
2022-09-12 17:12:11 -04:00
|
|
|
//NOTREACHED
|
2020-06-17 04:50:28 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
if ($item['deleted']) {
|
|
|
|
return '';
|
|
|
|
}
|
|
|
|
|
|
|
|
$contact_id = 0;
|
|
|
|
|
|
|
|
// check if logged in user is either the author or owner of this item
|
2022-10-20 15:02:49 -04:00
|
|
|
if (DI::userSession()->getRemoteContactID($item['uid']) == $item['contact-id']) {
|
2020-06-17 04:50:28 -04:00
|
|
|
$contact_id = $item['contact-id'];
|
|
|
|
}
|
|
|
|
|
2022-10-20 15:02:49 -04:00
|
|
|
if ((DI::userSession()->getLocalUserId() == $item['uid']) || $contact_id) {
|
2020-06-17 04:50:28 -04:00
|
|
|
// delete the item
|
2022-10-20 15:02:49 -04:00
|
|
|
Item::deleteForUser(['id' => $item['id']], DI::userSession()->getLocalUserId());
|
2020-06-17 04:50:28 -04:00
|
|
|
|
2021-01-20 18:44:02 -05:00
|
|
|
item_redirect_after_action($item, $return);
|
2022-09-12 17:12:11 -04:00
|
|
|
//NOTREACHED
|
2020-06-17 04:50:28 -04:00
|
|
|
} else {
|
2022-10-20 15:02:49 -04:00
|
|
|
Logger::warning('Permission denied.', ['local' => DI::userSession()->getLocalUserId(), 'uid' => $item['uid'], 'cid' => $contact_id]);
|
2022-10-17 07:27:32 -04:00
|
|
|
DI::sysmsg()->addNotice(DI::l10n()->t('Permission denied.'));
|
2020-06-17 04:50:28 -04:00
|
|
|
DI::baseUrl()->redirect('display/' . $item['guid']);
|
|
|
|
//NOTREACHED
|
2010-07-26 20:01:37 -04:00
|
|
|
}
|
2018-07-24 17:48:47 -04:00
|
|
|
|
2020-06-17 04:50:28 -04:00
|
|
|
return '';
|
2011-05-22 00:40:16 -04:00
|
|
|
}
|
2021-01-20 18:44:02 -05:00
|
|
|
|
2022-09-12 17:12:11 -04:00
|
|
|
function item_redirect_after_action(array $item, string $returnUrlHex)
|
2021-01-20 18:44:02 -05:00
|
|
|
{
|
|
|
|
$return_url = hex2bin($returnUrlHex);
|
|
|
|
|
|
|
|
// removes update_* from return_url to ignore Ajax refresh
|
2022-09-12 17:12:11 -04:00
|
|
|
$return_url = str_replace('update_', '', $return_url);
|
2021-01-20 18:44:02 -05:00
|
|
|
|
|
|
|
// Check if delete a comment
|
2022-09-12 17:12:11 -04:00
|
|
|
if ($item['gravity'] == Item::GRAVITY_COMMENT) {
|
2021-01-20 18:44:02 -05:00
|
|
|
if (!empty($item['parent'])) {
|
2022-10-20 15:02:49 -04:00
|
|
|
$parentitem = Post::selectFirstForUser(DI::userSession()->getLocalUserId(), ['guid'], ['id' => $item['parent']]);
|
2021-01-20 18:44:02 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
// Return to parent guid
|
|
|
|
if (!empty($parentitem)) {
|
|
|
|
DI::baseUrl()->redirect('display/' . $parentitem['guid']);
|
|
|
|
//NOTREACHED
|
|
|
|
} // In case something goes wrong
|
|
|
|
else {
|
|
|
|
DI::baseUrl()->redirect('network');
|
|
|
|
//NOTREACHED
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
// if unknown location or deleting top level post called from display
|
|
|
|
if (empty($return_url) || strpos($return_url, 'display') !== false) {
|
|
|
|
DI::baseUrl()->redirect('network');
|
|
|
|
//NOTREACHED
|
|
|
|
} else {
|
|
|
|
DI::baseUrl()->redirect($return_url);
|
|
|
|
//NOTREACHED
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|