2019-05-04 19:20:39 +00:00
|
|
|
<?php
|
2020-02-09 14:45:36 +00:00
|
|
|
/**
|
2022-01-02 07:27:47 +00:00
|
|
|
* @copyright Copyright (C) 2010-2022, the Friendica project
|
2020-02-09 14:45:36 +00: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/>.
|
|
|
|
*
|
|
|
|
*/
|
2019-05-04 19:20:39 +00:00
|
|
|
|
2021-01-30 22:11:54 +00:00
|
|
|
namespace Friendica\Module\Item;
|
2019-05-04 19:20:39 +00:00
|
|
|
|
|
|
|
use Friendica\BaseModule;
|
2020-10-11 19:58:28 +00:00
|
|
|
use Friendica\Core\Protocol;
|
2020-05-27 12:30:26 +00:00
|
|
|
use Friendica\Core\System;
|
2019-12-15 21:34:11 +00:00
|
|
|
use Friendica\DI;
|
2019-05-04 19:20:39 +00:00
|
|
|
use Friendica\Model\Item;
|
2021-01-16 04:16:09 +00:00
|
|
|
use Friendica\Model\Post;
|
2019-05-04 19:20:39 +00:00
|
|
|
use Friendica\Network\HTTPException;
|
2021-12-02 06:33:19 +00:00
|
|
|
use Friendica\Protocol\Diaspora;
|
2019-05-04 19:20:39 +00:00
|
|
|
|
|
|
|
/**
|
2021-01-30 22:11:54 +00:00
|
|
|
* Performs an activity (like, dislike, announce, attendyes, attendno, attendmaybe)
|
|
|
|
* and optionally redirects to a return path
|
2019-05-04 19:20:39 +00:00
|
|
|
*/
|
2021-01-30 22:11:54 +00:00
|
|
|
class Activity extends BaseModule
|
2019-05-04 19:20:39 +00:00
|
|
|
{
|
2021-11-20 14:38:03 +00:00
|
|
|
protected function rawContent(array $request = [])
|
2019-05-04 19:20:39 +00:00
|
|
|
{
|
2022-10-20 20:59:12 +00:00
|
|
|
if (!DI::userSession()->isAuthenticated()) {
|
2019-05-04 19:20:39 +00:00
|
|
|
throw new HTTPException\ForbiddenException();
|
|
|
|
}
|
|
|
|
|
2021-11-14 22:19:25 +00:00
|
|
|
if (empty($this->parameters['id']) || empty($this->parameters['verb'])) {
|
2021-01-30 22:11:54 +00:00
|
|
|
throw new HTTPException\BadRequestException();
|
2019-05-04 19:20:39 +00:00
|
|
|
}
|
|
|
|
|
2021-11-14 22:19:25 +00:00
|
|
|
$verb = $this->parameters['verb'];
|
|
|
|
$itemId = $this->parameters['id'];
|
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 20:59:12 +00: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-10-20 20:59:12 +00:00
|
|
|
Diaspora::performReshare($item['uri-id'], DI::userSession()->getLocalUserId());
|
2020-10-11 19:58:28 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-10-20 20:59:12 +00:00
|
|
|
if (!Item::performActivity($itemId, $verb, DI::userSession()->getLocalUserId())) {
|
2019-05-04 19:20:39 +00:00
|
|
|
throw new HTTPException\BadRequestException();
|
|
|
|
}
|
|
|
|
|
2021-01-30 22:11:54 +00:00
|
|
|
// See if we've been passed a return path to redirect to
|
|
|
|
$return_path = $_REQUEST['return'] ?? '';
|
|
|
|
if (!empty($return_path)) {
|
2019-05-04 19:20:39 +00:00
|
|
|
$rand = '_=' . time();
|
2021-01-30 22:11:54 +00:00
|
|
|
if (strpos($return_path, '?')) {
|
2019-05-04 19:20:39 +00:00
|
|
|
$rand = "&$rand";
|
|
|
|
} else {
|
|
|
|
$rand = "?$rand";
|
|
|
|
}
|
|
|
|
|
2021-01-30 22:11:54 +00:00
|
|
|
DI::baseUrl()->redirect($return_path . $rand);
|
2019-05-04 19:20:39 +00:00
|
|
|
}
|
2020-05-27 12:30:26 +00:00
|
|
|
|
2021-01-30 22:11:54 +00:00
|
|
|
$return = [
|
|
|
|
'status' => 'ok',
|
|
|
|
'item_id' => $itemId,
|
|
|
|
'verb' => $verb,
|
|
|
|
'state' => 1,
|
|
|
|
];
|
|
|
|
|
|
|
|
System::jsonExit($return);
|
2019-05-04 19:20:39 +00:00
|
|
|
}
|
|
|
|
}
|