friendica/src/Module/ActivityPub/Outbox.php

84 lines
2.5 KiB
PHP
Raw Normal View History

2018-09-23 19:29:31 +02:00
<?php
/**
* @copyright Copyright (C) 2010-2024, the Friendica project
*
* @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/>.
*
2018-09-23 19:29:31 +02:00
*/
namespace Friendica\Module\ActivityPub;
2018-09-23 19:29:31 +02:00
use Friendica\Model\User;
use Friendica\Module\BaseApi;
2019-05-01 21:29:04 +02:00
use Friendica\Protocol\ActivityPub;
2020-08-30 19:07:46 +02:00
use Friendica\Util\HTTPSignature;
2023-02-12 15:18:03 +01:00
use Friendica\Util\Network;
2018-09-23 19:29:31 +02:00
/**
* ActivityPub Outbox
*/
class Outbox extends BaseApi
2018-09-23 19:29:31 +02:00
{
protected function rawContent(array $request = [])
2018-09-23 19:29:31 +02:00
{
if (empty($this->parameters['nickname'])) {
$this->jsonExit([], 'application/activity+json');
2018-09-23 19:29:31 +02:00
}
$owner = User::getOwnerDataByNick($this->parameters['nickname']);
2018-09-23 19:29:31 +02:00
if (empty($owner)) {
throw new \Friendica\Network\HTTPException\NotFoundException();
2018-09-23 19:29:31 +02:00
}
$uid = self::getCurrentUserID();
$page = $request['page'] ?? null;
if (empty($page) && empty($request['max_id']) && !empty($uid)) {
$page = 1;
}
2018-09-23 19:29:31 +02:00
2023-02-14 00:49:08 +01:00
$outbox = ActivityPub\ClientToServer::getOutbox($owner, $uid, $page, $request['max_id'] ?? null, HTTPSignature::getSigner('', $_SERVER));
2022-04-09 13:58:01 +02:00
$this->jsonExit($outbox, 'application/activity+json');
2018-09-23 19:29:31 +02:00
}
2023-02-12 15:18:03 +01:00
protected function post(array $request = [])
{
$this->checkAllowedScope(self::SCOPE_WRITE);
2023-02-12 15:18:03 +01:00
$uid = self::getCurrentUserID();
$postdata = Network::postdata();
if (empty($postdata) || empty($this->parameters['nickname'])) {
throw new \Friendica\Network\HTTPException\BadRequestException();
}
$owner = User::getOwnerDataByNick($this->parameters['nickname']);
if (empty($owner)) {
throw new \Friendica\Network\HTTPException\NotFoundException();
}
if ($owner['uid'] != $uid) {
throw new \Friendica\Network\HTTPException\ForbiddenException();
}
$activity = json_decode($postdata, true);
if (empty($activity)) {
throw new \Friendica\Network\HTTPException\BadRequestException();
}
$this->jsonExit(ActivityPub\ClientToServer::processActivity($activity, $uid, self::getCurrentApplication() ?? []));
2023-02-12 15:18:03 +01:00
}
2018-09-23 19:29:31 +02:00
}