2019-05-04 21:20:39 +02:00
|
|
|
<?php
|
2024-08-24 15:27:00 +02:00
|
|
|
|
|
|
|
// Copyright (C) 2010-2024, the Friendica project
|
|
|
|
// SPDX-FileCopyrightText: 2010-2024 the Friendica project
|
|
|
|
//
|
|
|
|
// SPDX-License-Identifier: AGPL-3.0-or-later
|
2019-05-04 21:20:39 +02:00
|
|
|
|
2021-01-30 17:11:54 -05:00
|
|
|
namespace Friendica\Module\Item;
|
2019-05-04 21:20:39 +02:00
|
|
|
|
|
|
|
use Friendica\BaseModule;
|
2020-10-11 19:58:28 +00:00
|
|
|
use Friendica\Core\Protocol;
|
2020-05-27 08:30:26 -04:00
|
|
|
use Friendica\Core\System;
|
2019-12-15 22:34:11 +01:00
|
|
|
use Friendica\DI;
|
2019-05-04 21:20:39 +02:00
|
|
|
use Friendica\Model\Item;
|
2021-01-16 04:16:09 +00:00
|
|
|
use Friendica\Model\Post;
|
2019-05-04 21:20:39 +02:00
|
|
|
use Friendica\Network\HTTPException;
|
2021-12-02 06:33:19 +00:00
|
|
|
use Friendica\Protocol\Diaspora;
|
2019-05-04 21:20:39 +02:00
|
|
|
|
|
|
|
/**
|
2021-01-30 17:11:54 -05:00
|
|
|
* Performs an activity (like, dislike, announce, attendyes, attendno, attendmaybe)
|
|
|
|
* and optionally redirects to a return path
|
2019-05-04 21:20:39 +02:00
|
|
|
*/
|
2021-01-30 17:11:54 -05:00
|
|
|
class Activity extends BaseModule
|
2019-05-04 21:20:39 +02:00
|
|
|
{
|
2024-07-28 09:58:02 +00:00
|
|
|
protected function post(array $request = [])
|
2019-05-04 21:20:39 +02:00
|
|
|
{
|
2022-10-20 22:59:12 +02:00
|
|
|
if (!DI::userSession()->isAuthenticated()) {
|
2019-05-04 21:20:39 +02:00
|
|
|
throw new HTTPException\ForbiddenException();
|
|
|
|
}
|
|
|
|
|
2021-11-14 23:19:25 +01:00
|
|
|
if (empty($this->parameters['id']) || empty($this->parameters['verb'])) {
|
2021-01-30 17:11:54 -05:00
|
|
|
throw new HTTPException\BadRequestException();
|
2019-05-04 21:20:39 +02:00
|
|
|
}
|
|
|
|
|
2022-12-13 23:19:19 +00:00
|
|
|
$verb = $this->parameters['verb'];
|
|
|
|
$itemId = $this->parameters['id'];
|
|
|
|
$handled = false;
|
2021-12-02 06:36:09 +00:00
|
|
|
|
2020-11-07 08:22:59 +00:00
|
|
|
if (in_array($verb, ['announce', 'unannounce'])) {
|
2022-10-20 22:59:12 +02:00
|
|
|
$item = Post::selectFirst(['network', 'uri-id'], ['id' => $itemId, 'uid' => [DI::userSession()->getLocalUserId(), 0]]);
|
2020-10-11 19:58:28 +00:00
|
|
|
if ($item['network'] == Protocol::DIASPORA) {
|
2022-12-13 23:26:58 +00:00
|
|
|
$quote = Post::selectFirst(['id'], ['quote-uri-id' => $item['uri-id'], 'body' => '', 'origin' => true, 'uid' => DI::userSession()->getLocalUserId()]);
|
2022-12-13 23:19:19 +00:00
|
|
|
if (!empty($quote['id'])) {
|
|
|
|
if (!Item::markForDeletionById($quote['id'])) {
|
|
|
|
throw new HTTPException\BadRequestException();
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
Diaspora::performReshare($item['uri-id'], DI::userSession()->getLocalUserId());
|
|
|
|
}
|
|
|
|
$handled = true;
|
2020-10-11 19:58:28 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-12-13 23:19:19 +00:00
|
|
|
if (!$handled && !Item::performActivity($itemId, $verb, DI::userSession()->getLocalUserId())) {
|
2019-05-04 21:20:39 +02:00
|
|
|
throw new HTTPException\BadRequestException();
|
|
|
|
}
|
|
|
|
|
2021-01-30 17:11:54 -05:00
|
|
|
// See if we've been passed a return path to redirect to
|
|
|
|
$return_path = $_REQUEST['return'] ?? '';
|
|
|
|
if (!empty($return_path)) {
|
2019-05-04 21:20:39 +02:00
|
|
|
$rand = '_=' . time();
|
2021-01-30 17:11:54 -05:00
|
|
|
if (strpos($return_path, '?')) {
|
2019-05-04 21:20:39 +02:00
|
|
|
$rand = "&$rand";
|
|
|
|
} else {
|
|
|
|
$rand = "?$rand";
|
|
|
|
}
|
|
|
|
|
2021-01-30 17:11:54 -05:00
|
|
|
DI::baseUrl()->redirect($return_path . $rand);
|
2019-05-04 21:20:39 +02:00
|
|
|
}
|
2020-05-27 08:30:26 -04:00
|
|
|
|
2021-01-30 17:11:54 -05:00
|
|
|
$return = [
|
|
|
|
'status' => 'ok',
|
|
|
|
'item_id' => $itemId,
|
|
|
|
'verb' => $verb,
|
|
|
|
'state' => 1,
|
|
|
|
];
|
|
|
|
|
2023-09-21 12:16:17 -04:00
|
|
|
$this->jsonExit($return);
|
2019-05-04 21:20:39 +02:00
|
|
|
}
|
|
|
|
}
|