<?php
/**
- * @copyright Copyright (C) 2010-2021, the Friendica project
+ * @copyright Copyright (C) 2010-2022, the Friendica project
*
* @license GNU AGPL version 3 or any later version
*
use Friendica\Model\Contact;
use Friendica\Model\Item;
use Friendica\Model\Post;
+use Friendica\Model\User;
use Friendica\Network\HTTPException;
use Friendica\Protocol\ActivityPub;
use Friendica\Util\HTTPSignature;
*/
class Objects extends BaseModule
{
- public static function rawContent(array $parameters = [])
+ protected function rawContent(array $request = [])
{
- if (empty($parameters['guid'])) {
+ if (empty($this->parameters['guid'])) {
throw new HTTPException\BadRequestException();
}
DI::baseUrl()->redirect(str_replace('objects/', 'display/', DI::args()->getQueryString()));
}
- $itemuri = DBA::selectFirst('item-uri', ['id'], ['guid' => $parameters['guid']]);
+ $itemuri = DBA::selectFirst('item-uri', ['id'], ['guid' => $this->parameters['guid']]);
if (DBA::isResult($itemuri)) {
- Logger::info('Provided GUID found.', ['guid' => $parameters['guid'], 'uri-id' => $itemuri['id']]);
+ Logger::info('Provided GUID found.', ['guid' => $this->parameters['guid'], 'uri-id' => $itemuri['id']]);
} else {
// The item URI does not always contain the GUID. This means that we have to search the URL instead
$url = DI::baseUrl()->get() . '/' . DI::args()->getQueryString();
}
}
- $item = Post::selectFirst(['id', 'uid', 'origin', 'author-link', 'changed', 'private', 'psid', 'gravity', 'deleted', 'parent-uri-id'],
- ['uri-id' => $itemuri['id']], ['order' => ['origin' => true]]);
-
+ $item = Post::selectFirst([], ['uri-id' => $itemuri['id'], 'origin' => true]);
if (!DBA::isResult($item)) {
throw new HTTPException\NotFoundException();
}
- $validated = in_array($item['private'], [Item::PUBLIC, Item::UNLISTED]);
+ $owner = User::getById($item['uid'], ['hidewall']);
+
+ $validated = empty($owner['hidewall']) && in_array($item['private'], [Item::PUBLIC, Item::UNLISTED]);
if (!$validated) {
$requester = HTTPSignature::getSigner('', $_SERVER);
- if (!empty($requester) && $item['origin']) {
- $requester_id = Contact::getIdForURL($requester, $item['uid']);
- if (!empty($requester_id)) {
- $permissionSets = DI::permissionSet()->selectByContactId($requester_id, $item['uid']);
- if (!empty($permissionSets)) {
- $psid = array_merge($permissionSets->column('id'),
- [DI::permissionSet()->selectPublicForUser($item['uid'])]);
- $validated = in_array($item['psid'], $psid);
- }
- }
- }
- }
-
- if ($validated) {
- // Valid items are original post or posted from this node (including in the case of a forum)
- $validated = ($item['origin'] || (parse_url($item['author-link'], PHP_URL_HOST) == parse_url(DI::baseUrl()->get(), PHP_URL_HOST)));
+ if (!empty($requester)) {
+ $receivers = Item::enumeratePermissions($item, false);
+ $receivers[] = $item['contact-id'];
- if (!$validated && $item['deleted']) {
- $validated = Post::exists(['origin' => true, 'uri-id' => $item['parent-uri-id']]);
+ $validated = in_array(Contact::getIdForURL($requester, $item['uid']), $receivers);
+ if (!$validated) {
+ $validated = in_array(Contact::getIdForURL($requester), $receivers);
+ }
}
}
throw new HTTPException\NotFoundException();
}
- $etag = md5($parameters['guid'] . '-' . $item['changed']);
+ $etag = md5($this->parameters['guid'] . '-' . $item['changed']);
$last_modified = $item['changed'];
Network::checkEtagModified($etag, $last_modified);
- if (empty($parameters['activity']) && ($item['gravity'] != GRAVITY_ACTIVITY)) {
- $activity = ActivityPub\Transmitter::createActivityFromItem($item['id'], true);
+ if (empty($this->parameters['activity']) && ($item['gravity'] != Item::GRAVITY_ACTIVITY)) {
+ $activity = ActivityPub\Transmitter::createCachedActivityFromItem($item['id'], false, true);
if (empty($activity['type'])) {
throw new HTTPException\NotFoundException();
}
$data = ['@context' => ActivityPub::CONTEXT];
$data = array_merge($data, $activity['object']);
- } elseif (empty($parameters['activity']) || in_array($parameters['activity'],
+ } elseif (empty($this->parameters['activity']) || in_array($this->parameters['activity'],
['Create', 'Announce', 'Update', 'Like', 'Dislike', 'Accept', 'Reject',
'TentativeAccept', 'Follow', 'Add'])) {
- $data = ActivityPub\Transmitter::createActivityFromItem($item['id']);
+ $data = ActivityPub\Transmitter::createCachedActivityFromItem($item['id']);
if (empty($data)) {
throw new HTTPException\NotFoundException();
}
- if (!empty($parameters['activity']) && ($parameters['activity'] != 'Create')) {
- $data['type'] = $parameters['activity'];
- $data['id'] = str_replace('/Create', '/' . $parameters['activity'], $data['id']);
+ if (!empty($this->parameters['activity']) && ($this->parameters['activity'] != 'Create')) {
+ $data['type'] = $this->parameters['activity'];
+ $data['id'] = str_replace('/Create', '/' . $this->parameters['activity'], $data['id']);
}
} else {
throw new HTTPException\NotFoundException();
// Relaxed CORS header for public items
header('Access-Control-Allow-Origin: *');
+
System::jsonExit($data, 'application/activity+json');
}
}