forked from grumpydevelop/federator
fix phan errors
fix lots of phan errors, now we only have phan errors left from temporary implementations. These will be fixed in the next commits as we properly re-integrate and remove temporary-code
This commit is contained in:
parent
957b4f5266
commit
d9b02bd95b
9 changed files with 232 additions and 114 deletions
|
@ -367,5 +367,7 @@ return [
|
||||||
// A list of individual files to include in analysis
|
// A list of individual files to include in analysis
|
||||||
// with a path relative to the root directory of the
|
// with a path relative to the root directory of the
|
||||||
// project.
|
// project.
|
||||||
'file_list' => [],
|
'file_list' => [
|
||||||
|
'phan-stubs.php',
|
||||||
|
],
|
||||||
];
|
];
|
||||||
|
|
10
phan-stubs.php
Normal file
10
phan-stubs.php
Normal file
|
@ -0,0 +1,10 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
if (!function_exists('getallheaders')) {
|
||||||
|
/**
|
||||||
|
* @return array<string, string>
|
||||||
|
*/
|
||||||
|
function getallheaders(): array {
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
}
|
|
@ -198,12 +198,13 @@ class Api extends Main
|
||||||
* @param string[] $headers
|
* @param string[] $headers
|
||||||
* permission(s) to check for
|
* permission(s) to check for
|
||||||
* @throws Exceptions\PermissionDenied
|
* @throws Exceptions\PermissionDenied
|
||||||
|
* @return string|Exceptions\PermissionDenied
|
||||||
*/
|
*/
|
||||||
public function checkSignature($headers)
|
public static function checkSignature($headers)
|
||||||
{
|
{
|
||||||
$signatureHeader = $headers['Signature'] ?? null;
|
$signatureHeader = $headers['Signature'] ?? null;
|
||||||
|
|
||||||
if (!$signatureHeader) {
|
if (!isset($signatureHeader)) {
|
||||||
http_response_code(400);
|
http_response_code(400);
|
||||||
throw new Exceptions\PermissionDenied("Missing Signature header");
|
throw new Exceptions\PermissionDenied("Missing Signature header");
|
||||||
}
|
}
|
||||||
|
@ -219,15 +220,20 @@ class Api extends Main
|
||||||
// Fetch public key from `keyId` (usually actor URL + #main-key)
|
// Fetch public key from `keyId` (usually actor URL + #main-key)
|
||||||
[$publicKeyData, $info] = \Federator\Main::getFromRemote($keyId, ['Accept: application/activity+json']);
|
[$publicKeyData, $info] = \Federator\Main::getFromRemote($keyId, ['Accept: application/activity+json']);
|
||||||
|
|
||||||
if ($info['http_code'] !== 200) {
|
if ($info['http_code'] != 200) {
|
||||||
http_response_code(500);
|
http_response_code(500);
|
||||||
throw new Exceptions\PermissionDenied("Failed to fetch public key from keyId: $keyId");
|
throw new Exceptions\PermissionDenied("Failed to fetch public key from keyId: $keyId");
|
||||||
}
|
}
|
||||||
|
|
||||||
$actor = json_decode($publicKeyData, true);
|
$actor = json_decode($publicKeyData, true);
|
||||||
|
|
||||||
|
if (!is_array($actor) || !isset($actor['id'])) {
|
||||||
|
throw new Exceptions\PermissionDenied("Invalid actor data");
|
||||||
|
}
|
||||||
|
|
||||||
$publicKeyPem = $actor['publicKey']['publicKeyPem'] ?? null;
|
$publicKeyPem = $actor['publicKey']['publicKeyPem'] ?? null;
|
||||||
|
|
||||||
if (!$publicKeyPem) {
|
if (!isset($publicKeyPem)) {
|
||||||
http_response_code(500);
|
http_response_code(500);
|
||||||
throw new Exceptions\PermissionDenied("Invalid public key format from actor with keyId: $keyId");
|
throw new Exceptions\PermissionDenied("Invalid public key format from actor with keyId: $keyId");
|
||||||
}
|
}
|
||||||
|
@ -235,8 +241,6 @@ class Api extends Main
|
||||||
// Reconstruct the signed string
|
// Reconstruct the signed string
|
||||||
$signedString = '';
|
$signedString = '';
|
||||||
foreach ($signedHeaders as $header) {
|
foreach ($signedHeaders as $header) {
|
||||||
$headerValue = '';
|
|
||||||
|
|
||||||
if ($header === '(request-target)') {
|
if ($header === '(request-target)') {
|
||||||
$method = strtolower($_SERVER['REQUEST_METHOD']);
|
$method = strtolower($_SERVER['REQUEST_METHOD']);
|
||||||
$path = $_SERVER['REQUEST_URI'];
|
$path = $_SERVER['REQUEST_URI'];
|
||||||
|
@ -252,16 +256,17 @@ class Api extends Main
|
||||||
// Verify the signature
|
// Verify the signature
|
||||||
$pubkeyRes = openssl_pkey_get_public($publicKeyPem);
|
$pubkeyRes = openssl_pkey_get_public($publicKeyPem);
|
||||||
$verified = false;
|
$verified = false;
|
||||||
if ($pubkeyRes) {
|
if ($pubkeyRes instanceof \OpenSSLAsymmetricKey && is_string($signature)) {
|
||||||
$verified = openssl_verify($signedString, $signature, $pubkeyRes, OPENSSL_ALGO_SHA256);
|
$verified = openssl_verify($signedString, $signature, $pubkeyRes, OPENSSL_ALGO_SHA256);
|
||||||
}
|
}
|
||||||
if ($verified !== 1) {
|
if ($verified != 1) {
|
||||||
http_response_code(500);
|
http_response_code(500);
|
||||||
throw new Exceptions\PermissionDenied("Signature verification failed for publicKey with keyId: $keyId");
|
throw new Exceptions\PermissionDenied("Signature verification failed for publicKey with keyId: $keyId");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$actorId = $actor['id'];
|
||||||
// Signature is valid!
|
// Signature is valid!
|
||||||
return "Signature verified from actor: " . $actor['id'];
|
return "Signature verified from actor: " . $actorId;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -16,7 +16,7 @@ class FedUsers implements APIInterface
|
||||||
/**
|
/**
|
||||||
* main instance
|
* main instance
|
||||||
*
|
*
|
||||||
* @var \Federator\Main $main
|
* @var \Federator\Api $main
|
||||||
*/
|
*/
|
||||||
private $main;
|
private $main;
|
||||||
|
|
||||||
|
@ -49,6 +49,7 @@ class FedUsers implements APIInterface
|
||||||
{
|
{
|
||||||
$method = $_SERVER["REQUEST_METHOD"];
|
$method = $_SERVER["REQUEST_METHOD"];
|
||||||
$handler = null;
|
$handler = null;
|
||||||
|
$username = '';
|
||||||
switch (sizeof($paths)) {
|
switch (sizeof($paths)) {
|
||||||
case 2:
|
case 2:
|
||||||
if ($method === 'GET') {
|
if ($method === 'GET') {
|
||||||
|
@ -75,8 +76,8 @@ class FedUsers implements APIInterface
|
||||||
break;
|
break;
|
||||||
case 'inbox':
|
case 'inbox':
|
||||||
$handler = new FedUsers\Inbox($this->main);
|
$handler = new FedUsers\Inbox($this->main);
|
||||||
$user = $paths[1];
|
$username = $paths[1];
|
||||||
if (!preg_match("#^([^@]+)@([^/]+)#", $user, $matches) === 1) {
|
if (preg_match("#^([^@]+)@([^/]+)#", $username, $matches) != 1) {
|
||||||
$hostUrl = $this->main->getHost();
|
$hostUrl = $this->main->getHost();
|
||||||
if ($hostUrl !== false) {
|
if ($hostUrl !== false) {
|
||||||
$host = parse_url($hostUrl, PHP_URL_HOST);
|
$host = parse_url($hostUrl, PHP_URL_HOST);
|
||||||
|
@ -84,14 +85,14 @@ class FedUsers implements APIInterface
|
||||||
if ($port !== null) {
|
if ($port !== null) {
|
||||||
$host .= `:$port`;
|
$host .= `:$port`;
|
||||||
}
|
}
|
||||||
$user = `$user@$host`;
|
$username = `$username@$host`;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case 'outbox':
|
case 'outbox':
|
||||||
$handler = new FedUsers\Outbox($this->main);
|
$handler = new FedUsers\Outbox($this->main);
|
||||||
$user = $paths[1];
|
$username = $paths[1];
|
||||||
if (!preg_match("#^([^@]+)@([^/]+)#", $user, $matches) === 1) {
|
if (preg_match("#^([^@]+)@([^/]+)#", $username, $matches) != 1) {
|
||||||
$hostUrl = $this->main->getHost();
|
$hostUrl = $this->main->getHost();
|
||||||
if ($hostUrl !== false) {
|
if ($hostUrl !== false) {
|
||||||
$host = parse_url($hostUrl, PHP_URL_HOST);
|
$host = parse_url($hostUrl, PHP_URL_HOST);
|
||||||
|
@ -99,7 +100,7 @@ class FedUsers implements APIInterface
|
||||||
if ($port !== null) {
|
if ($port !== null) {
|
||||||
$host .= `:$port`;
|
$host .= `:$port`;
|
||||||
}
|
}
|
||||||
$user = `$user@$host`;
|
$username = `$username@$host`;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
@ -114,10 +115,10 @@ class FedUsers implements APIInterface
|
||||||
$ret = false;
|
$ret = false;
|
||||||
switch ($method) {
|
switch ($method) {
|
||||||
case 'GET':
|
case 'GET':
|
||||||
$ret = $handler->get($user);
|
$ret = $handler->get($username);
|
||||||
break;
|
break;
|
||||||
case 'POST':
|
case 'POST':
|
||||||
$ret = $handler->post($user);
|
$ret = $handler->post($username);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if ($ret !== false) {
|
if ($ret !== false) {
|
||||||
|
|
|
@ -16,7 +16,7 @@ class Inbox implements \Federator\Api\FedUsers\FedUsersInterface
|
||||||
/**
|
/**
|
||||||
* main instance
|
* main instance
|
||||||
*
|
*
|
||||||
* @var \Federator\Main $main
|
* @var \Federator\Api $main
|
||||||
*/
|
*/
|
||||||
private $main;
|
private $main;
|
||||||
|
|
||||||
|
@ -32,7 +32,7 @@ class Inbox implements \Federator\Api\FedUsers\FedUsersInterface
|
||||||
/**
|
/**
|
||||||
* handle get call
|
* handle get call
|
||||||
*
|
*
|
||||||
* @param string $_user user to fetch inbox for @unused-param
|
* @param string|null $_user user to fetch inbox for @unused-param
|
||||||
* @return string|false response
|
* @return string|false response
|
||||||
*/
|
*/
|
||||||
public function get($_user)
|
public function get($_user)
|
||||||
|
@ -43,7 +43,7 @@ class Inbox implements \Federator\Api\FedUsers\FedUsersInterface
|
||||||
/**
|
/**
|
||||||
* handle post call
|
* handle post call
|
||||||
*
|
*
|
||||||
* @param string $_user user to add data to inbox
|
* @param string|null $_user user to add data to inbox
|
||||||
* @return string|false response
|
* @return string|false response
|
||||||
*/
|
*/
|
||||||
public function post($_user)
|
public function post($_user)
|
||||||
|
@ -60,10 +60,12 @@ class Inbox implements \Federator\Api\FedUsers\FedUsersInterface
|
||||||
exit("Access denied");
|
exit("Access denied");
|
||||||
}
|
}
|
||||||
|
|
||||||
$activity = json_decode($_rawInput, true);
|
$activity = is_string($_rawInput) ? json_decode($_rawInput, true) : null;
|
||||||
$host = $_SERVER['SERVER_NAME'];
|
$host = $_SERVER['SERVER_NAME'];
|
||||||
|
|
||||||
$sendTo = [];
|
if (!is_array($activity)) {
|
||||||
|
throw new \RuntimeException('Invalid activity format.');
|
||||||
|
}
|
||||||
|
|
||||||
switch ($activity['type']) {
|
switch ($activity['type']) {
|
||||||
case 'Create':
|
case 'Create':
|
||||||
|
@ -72,11 +74,12 @@ class Inbox implements \Federator\Api\FedUsers\FedUsersInterface
|
||||||
}
|
}
|
||||||
|
|
||||||
$obj = $activity['object'];
|
$obj = $activity['object'];
|
||||||
|
$published = strtotime($activity['published'] ?? $obj['published'] ?? 'now');
|
||||||
$create = new \Federator\Data\ActivityPub\Common\Create();
|
$create = new \Federator\Data\ActivityPub\Common\Create();
|
||||||
$create->setID($activity['id'])
|
$create->setAActor($activity['actor'])
|
||||||
|
->setID($activity['id'])
|
||||||
->setURL($activity['id'])
|
->setURL($activity['id'])
|
||||||
->setPublished(strtotime($activity['published'] ?? $obj['published'] ?? 'now'))
|
->setPublished($published !== false ? $published : time());
|
||||||
->setAActor($activity['actor']);
|
|
||||||
|
|
||||||
if (array_key_exists('cc', $activity)) {
|
if (array_key_exists('cc', $activity)) {
|
||||||
foreach ($activity['cc'] as $cc) {
|
foreach ($activity['cc'] as $cc) {
|
||||||
|
@ -92,9 +95,10 @@ class Inbox implements \Federator\Api\FedUsers\FedUsersInterface
|
||||||
|
|
||||||
switch ($obj['type']) {
|
switch ($obj['type']) {
|
||||||
case 'Note':
|
case 'Note':
|
||||||
|
$published = strtotime($obj['published'] ?? 'now');
|
||||||
$apNote = new \Federator\Data\ActivityPub\Common\Note();
|
$apNote = new \Federator\Data\ActivityPub\Common\Note();
|
||||||
$apNote->setID($obj['id'])
|
$apNote->setID($obj['id'])
|
||||||
->setPublished(strtotime($obj['published'] ?? 'now'))
|
->setPublished($published !== false ? $published : time())
|
||||||
->setContent($obj['content'] ?? '')
|
->setContent($obj['content'] ?? '')
|
||||||
->setSummary($obj['summary'])
|
->setSummary($obj['summary'])
|
||||||
->setURL($obj['url'])
|
->setURL($obj['url'])
|
||||||
|
@ -168,11 +172,12 @@ class Inbox implements \Federator\Api\FedUsers\FedUsersInterface
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$published = strtotime((string) $activity['published']);
|
||||||
$announce = new \Federator\Data\ActivityPub\Common\Announce();
|
$announce = new \Federator\Data\ActivityPub\Common\Announce();
|
||||||
$announce->setID($activity['id'])
|
$announce->setAActor((string) $activity['actor'])
|
||||||
->setURL($activity['id'])
|
->setPublished($published !== false ? $published : time())
|
||||||
->setPublished(strtotime($activity['published'] ?? 'now'))
|
->setID((string) $activity['id'])
|
||||||
->setAActor($activity['actor']);
|
->setURL((string) $activity['id']);
|
||||||
|
|
||||||
if (array_key_exists('cc', $activity)) {
|
if (array_key_exists('cc', $activity)) {
|
||||||
foreach ($activity['cc'] as $cc) {
|
foreach ($activity['cc'] as $cc) {
|
||||||
|
@ -188,11 +193,12 @@ class Inbox implements \Federator\Api\FedUsers\FedUsersInterface
|
||||||
// Parse the shared object as a Note or something else
|
// Parse the shared object as a Note or something else
|
||||||
switch ($objData['type']) {
|
switch ($objData['type']) {
|
||||||
case 'Note':
|
case 'Note':
|
||||||
|
$published = strtotime($objData['published'] ?? 'now');
|
||||||
$note = new \Federator\Data\ActivityPub\Common\Note();
|
$note = new \Federator\Data\ActivityPub\Common\Note();
|
||||||
$note->setID($objData['id'])
|
$note->setPublished($published !== false ? $published : time())
|
||||||
|
->setID($objData['id'])
|
||||||
->setSummary($objData['summary'])
|
->setSummary($objData['summary'])
|
||||||
->setContent($objData['content'] ?? '')
|
->setContent($objData['content'] ?? '')
|
||||||
->setPublished(strtotime($objData['published'] ?? 'now'))
|
|
||||||
->setURL($objData['url'] ?? $objData['id'])
|
->setURL($objData['url'] ?? $objData['id'])
|
||||||
->setAttributedTo($objData['attributedTo'] ?? null)
|
->setAttributedTo($objData['attributedTo'] ?? null)
|
||||||
->addTo("https://www.w3.org/ns/activitystreams#Public");
|
->addTo("https://www.w3.org/ns/activitystreams#Public");
|
||||||
|
@ -220,9 +226,9 @@ class Inbox implements \Federator\Api\FedUsers\FedUsersInterface
|
||||||
}
|
}
|
||||||
|
|
||||||
$undo = new \Federator\Data\ActivityPub\Common\Undo();
|
$undo = new \Federator\Data\ActivityPub\Common\Undo();
|
||||||
$undo->setID($activity['id'] ?? "test")
|
$undo->setActor($activity['actor'] ?? null)
|
||||||
->setURL($activity['url'] ?? $activity['id'])
|
->setID($activity['id'] ?? "test")
|
||||||
->setActor($activity['actor'] ?? null);
|
->setURL($activity['url'] ?? $activity['id']);
|
||||||
|
|
||||||
if (array_key_exists('cc', $activity)) {
|
if (array_key_exists('cc', $activity)) {
|
||||||
foreach ($activity['cc'] as $cc) {
|
foreach ($activity['cc'] as $cc) {
|
||||||
|
@ -240,11 +246,12 @@ class Inbox implements \Federator\Api\FedUsers\FedUsersInterface
|
||||||
if (is_array($undone) && isset($undone['type'])) {
|
if (is_array($undone) && isset($undone['type'])) {
|
||||||
switch ($undone['type']) {
|
switch ($undone['type']) {
|
||||||
case 'Announce':
|
case 'Announce':
|
||||||
|
$published = strtotime($undone['published'] ?? 'now');
|
||||||
$announce = new \Federator\Data\ActivityPub\Common\Announce();
|
$announce = new \Federator\Data\ActivityPub\Common\Announce();
|
||||||
$announce->setID($undone['id'] ?? null)
|
$announce->setAActor($undone['actor'] ?? null)
|
||||||
->setAActor($undone['actor'] ?? null)
|
->setPublished($published !== false ? $published : time())
|
||||||
->setURL($undone['url'] ?? $undone['id'])
|
->setID($undone['id'] ?? null)
|
||||||
->setPublished(strtotime($undone['published'] ?? 'now'));
|
->setURL($undone['url'] ?? $undone['id']);
|
||||||
|
|
||||||
if (array_key_exists('cc', $undone)) {
|
if (array_key_exists('cc', $undone)) {
|
||||||
foreach ($undone['cc'] as $cc) {
|
foreach ($undone['cc'] as $cc) {
|
||||||
|
@ -269,11 +276,14 @@ class Inbox implements \Federator\Api\FedUsers\FedUsersInterface
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
error_log("Inbox::post we currently don't support the activity type " . $activity['type'] . "\n");
|
error_log("Inbox::post we currently don't support the activity type " . $activity['type'] . "\n");
|
||||||
|
$apObject = new \Federator\Data\ActivityPub\Common\Activity($activity['type']);
|
||||||
|
$apObject->setID($activity['id'] ?? null);
|
||||||
|
$inboxActivity = $apObject;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Shared inbox
|
// Shared inbox
|
||||||
if (!$_user) {
|
if (!isset($_user)) {
|
||||||
$rootDir = $_SERVER['DOCUMENT_ROOT'] . '../';
|
$rootDir = $_SERVER['DOCUMENT_ROOT'] . '../';
|
||||||
file_put_contents(
|
file_put_contents(
|
||||||
$rootDir . 'logs/inbox.log',
|
$rootDir . 'logs/inbox.log',
|
||||||
|
@ -289,28 +299,40 @@ class Inbox implements \Federator\Api\FedUsers\FedUsersInterface
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!isset($inboxActivity)) {
|
||||||
|
error_log("Inbox::post couldn't create inboxActivity, aborting");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
$sendTo = $inboxActivity->getCC();
|
$sendTo = $inboxActivity->getCC();
|
||||||
if ($inboxActivity->getType() === 'Undo') {
|
if ($inboxActivity->getType() === 'Undo') {
|
||||||
$sendTo = $inboxActivity->getObject()->getCC();
|
$object = $inboxActivity->getObject();
|
||||||
|
if ($object !== null) {
|
||||||
|
$sendTo = $object->getCC();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$users = [];
|
$users = [];
|
||||||
|
|
||||||
foreach ($sendTo as $receiver) {
|
foreach ($sendTo as $receiver) {
|
||||||
if (!$receiver || !is_string($receiver)) {
|
if ($receiver === '' || !is_string($receiver)) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (str_ends_with($receiver, '/followers')) {
|
if (str_ends_with($receiver, '/followers')) {
|
||||||
$users = array_merge($users, $this->fetchAllFollowers($receiver, $host));
|
$followers = $this->fetchAllFollowers($receiver, $host);
|
||||||
|
if (is_array($followers)) {
|
||||||
|
$users = array_merge($users, $followers);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if ($_user !== false && !in_array($_user, $users)) {
|
}
|
||||||
|
if ($_user !== false && !in_array($_user, $users, true)) {
|
||||||
$users[] = $_user;
|
$users[] = $_user;
|
||||||
}
|
}
|
||||||
foreach ($users as $user) {
|
foreach ($users as $user) {
|
||||||
if (!$user)
|
if (!isset($user)) {
|
||||||
continue;
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
$this->postForUser($user, $inboxActivity);
|
$this->postForUser($user, $inboxActivity);
|
||||||
}
|
}
|
||||||
|
@ -322,11 +344,11 @@ class Inbox implements \Federator\Api\FedUsers\FedUsersInterface
|
||||||
*
|
*
|
||||||
* @param string $_user user to add data to inbox
|
* @param string $_user user to add data to inbox
|
||||||
* @param \Federator\Data\ActivityPub\Common\Activity $inboxActivity the activity that we received
|
* @param \Federator\Data\ActivityPub\Common\Activity $inboxActivity the activity that we received
|
||||||
* @return string|false response
|
* @return boolean response
|
||||||
*/
|
*/
|
||||||
private function postForUser($_user, $inboxActivity)
|
private function postForUser($_user, $inboxActivity)
|
||||||
{
|
{
|
||||||
if ($_user) {
|
if (isset($_user)) {
|
||||||
$dbh = $this->main->getDatabase();
|
$dbh = $this->main->getDatabase();
|
||||||
$cache = $this->main->getCache();
|
$cache = $this->main->getCache();
|
||||||
$connector = $this->main->getConnector();
|
$connector = $this->main->getConnector();
|
||||||
|
@ -360,14 +382,14 @@ class Inbox implements \Federator\Api\FedUsers\FedUsersInterface
|
||||||
*
|
*
|
||||||
* @param string $collectionUrl The url of f.e. the posters followers
|
* @param string $collectionUrl The url of f.e. the posters followers
|
||||||
* @param string $host our current host-url
|
* @param string $host our current host-url
|
||||||
* @return array|false the names of the followers that are hosted on our server
|
* @return string[] the names of the followers that are hosted on our server
|
||||||
*/
|
*/
|
||||||
private function fetchAllFollowers(string $collectionUrl, string $host): array
|
private static function fetchAllFollowers(string $collectionUrl, string $host): array
|
||||||
{
|
{
|
||||||
$users = [];
|
$users = [];
|
||||||
|
|
||||||
[$collectionResponse, $collectionInfo] = \Federator\Main::getFromRemote($collectionUrl, ['Accept: application/activity+json']);
|
[$collectionResponse, $collectionInfo] = \Federator\Main::getFromRemote($collectionUrl, ['Accept: application/activity+json']);
|
||||||
if ($collectionInfo['http_code'] !== 200) {
|
if ($collectionInfo['http_code'] != 200) {
|
||||||
error_log("Inbox::fetchAllFollowers Failed to fetch follower collection metadata from $collectionUrl");
|
error_log("Inbox::fetchAllFollowers Failed to fetch follower collection metadata from $collectionUrl");
|
||||||
return [];
|
return [];
|
||||||
}
|
}
|
||||||
|
@ -375,7 +397,7 @@ class Inbox implements \Federator\Api\FedUsers\FedUsersInterface
|
||||||
$collectionData = json_decode($collectionResponse, true);
|
$collectionData = json_decode($collectionResponse, true);
|
||||||
$nextPage = $collectionData['first'] ?? $collectionData['current'] ?? null;
|
$nextPage = $collectionData['first'] ?? $collectionData['current'] ?? null;
|
||||||
|
|
||||||
if (!$nextPage) {
|
if (!isset($nextPage)) {
|
||||||
error_log("Inbox::fetchAllFollowers No 'first' or 'current' page in collection at $collectionUrl");
|
error_log("Inbox::fetchAllFollowers No 'first' or 'current' page in collection at $collectionUrl");
|
||||||
return [];
|
return [];
|
||||||
}
|
}
|
||||||
|
@ -383,7 +405,7 @@ class Inbox implements \Federator\Api\FedUsers\FedUsersInterface
|
||||||
// Loop through all pages
|
// Loop through all pages
|
||||||
while ($nextPage) {
|
while ($nextPage) {
|
||||||
[$pageResponse, $pageInfo] = \Federator\Main::getFromRemote($nextPage, ['Accept: application/activity+json']);
|
[$pageResponse, $pageInfo] = \Federator\Main::getFromRemote($nextPage, ['Accept: application/activity+json']);
|
||||||
if ($pageInfo['http_code'] !== 200) {
|
if ($pageInfo['http_code'] != 200) {
|
||||||
error_log("Inbox::fetchAllFollowers Failed to fetch follower page at $nextPage");
|
error_log("Inbox::fetchAllFollowers Failed to fetch follower page at $nextPage");
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -398,7 +420,7 @@ class Inbox implements \Federator\Api\FedUsers\FedUsersInterface
|
||||||
}
|
}
|
||||||
|
|
||||||
[$actorResponse, $actorInfo] = \Federator\Main::getFromRemote($followerUrl, ['Accept: application/activity+json']);
|
[$actorResponse, $actorInfo] = \Federator\Main::getFromRemote($followerUrl, ['Accept: application/activity+json']);
|
||||||
if ($actorInfo['http_code'] !== 200) {
|
if ($actorInfo['http_code'] != 200) {
|
||||||
error_log("Inbox::fetchAllFollowers Failed to fetch actor data for follower: $followerUrl");
|
error_log("Inbox::fetchAllFollowers Failed to fetch actor data for follower: $followerUrl");
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,13 +16,13 @@ class Outbox implements \Federator\Api\FedUsers\FedUsersInterface
|
||||||
/**
|
/**
|
||||||
* main instance
|
* main instance
|
||||||
*
|
*
|
||||||
* @var \Federator\Main $main
|
* @var \Federator\Api $main
|
||||||
*/
|
*/
|
||||||
private $main;
|
private $main;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* constructor
|
* constructor
|
||||||
* @param \Federator\Main $main main instance
|
* @param \Federator\Api $main main instance
|
||||||
*/
|
*/
|
||||||
public function __construct($main)
|
public function __construct($main)
|
||||||
{
|
{
|
||||||
|
@ -32,11 +32,14 @@ class Outbox implements \Federator\Api\FedUsers\FedUsersInterface
|
||||||
/**
|
/**
|
||||||
* handle get call
|
* handle get call
|
||||||
*
|
*
|
||||||
* @param string $_user user to fetch outbox for
|
* @param string|null $_user user to fetch outbox for
|
||||||
* @return string|false response
|
* @return string|false response
|
||||||
*/
|
*/
|
||||||
public function get($_user)
|
public function get($_user)
|
||||||
{
|
{
|
||||||
|
if (!isset($_user)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
$dbh = $this->main->getDatabase();
|
$dbh = $this->main->getDatabase();
|
||||||
$cache = $this->main->getCache();
|
$cache = $this->main->getCache();
|
||||||
$connector = $this->main->getConnector();
|
$connector = $this->main->getConnector();
|
||||||
|
@ -87,7 +90,7 @@ class Outbox implements \Federator\Api\FedUsers\FedUsersInterface
|
||||||
/**
|
/**
|
||||||
* handle post call
|
* handle post call
|
||||||
*
|
*
|
||||||
* @param string $_user user to add data to outbox
|
* @param string|null $_user user to add data to outbox
|
||||||
* @return string|false response
|
* @return string|false response
|
||||||
*/
|
*/
|
||||||
public function post($_user)
|
public function post($_user)
|
||||||
|
@ -104,10 +107,12 @@ class Outbox implements \Federator\Api\FedUsers\FedUsersInterface
|
||||||
exit("Access denied");
|
exit("Access denied");
|
||||||
}
|
}
|
||||||
|
|
||||||
$activity = json_decode($_rawInput, true);
|
$activity = is_string($_rawInput) ? json_decode($_rawInput, true) : null;
|
||||||
$host = $_SERVER['SERVER_NAME'];
|
$host = $_SERVER['SERVER_NAME'];
|
||||||
|
|
||||||
$sendTo = [];
|
if (!is_array($activity)) {
|
||||||
|
throw new \RuntimeException('Invalid activity format.');
|
||||||
|
}
|
||||||
|
|
||||||
switch ($activity['type']) {
|
switch ($activity['type']) {
|
||||||
case 'Create':
|
case 'Create':
|
||||||
|
@ -116,11 +121,12 @@ class Outbox implements \Federator\Api\FedUsers\FedUsersInterface
|
||||||
}
|
}
|
||||||
|
|
||||||
$obj = $activity['object'];
|
$obj = $activity['object'];
|
||||||
|
$published = strtotime($activity['published'] ?? $obj['published'] ?? 'now');
|
||||||
$create = new \Federator\Data\ActivityPub\Common\Create();
|
$create = new \Federator\Data\ActivityPub\Common\Create();
|
||||||
$create->setID($activity['id'])
|
$create->setAActor($activity['actor'])
|
||||||
|
->setID($activity['id'])
|
||||||
->setURL($activity['id'])
|
->setURL($activity['id'])
|
||||||
->setPublished(published: strtotime($activity['published'] ?? $obj['published'] ?? 'now'))
|
->setPublished($published !== false ? $published : time());
|
||||||
->setAActor($activity['actor']);
|
|
||||||
|
|
||||||
if (array_key_exists('cc', $activity)) {
|
if (array_key_exists('cc', $activity)) {
|
||||||
foreach ($activity['cc'] as $cc) {
|
foreach ($activity['cc'] as $cc) {
|
||||||
|
@ -136,9 +142,10 @@ class Outbox implements \Federator\Api\FedUsers\FedUsersInterface
|
||||||
|
|
||||||
switch ($obj['type']) {
|
switch ($obj['type']) {
|
||||||
case 'Note':
|
case 'Note':
|
||||||
|
$published = strtotime($obj['published'] ?? 'now');
|
||||||
$apNote = new \Federator\Data\ActivityPub\Common\Note();
|
$apNote = new \Federator\Data\ActivityPub\Common\Note();
|
||||||
$apNote->setID($obj['id'])
|
$apNote->setID($obj['id'])
|
||||||
->setPublished(strtotime($obj['published'] ?? 'now'))
|
->setPublished($published !== false ? $published : time())
|
||||||
->setContent($obj['content'] ?? '')
|
->setContent($obj['content'] ?? '')
|
||||||
->setSummary($obj['summary'])
|
->setSummary($obj['summary'])
|
||||||
->setURL($obj['url'])
|
->setURL($obj['url'])
|
||||||
|
@ -212,11 +219,12 @@ class Outbox implements \Federator\Api\FedUsers\FedUsersInterface
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$published = strtotime((string) $activity['published']);
|
||||||
$announce = new \Federator\Data\ActivityPub\Common\Announce();
|
$announce = new \Federator\Data\ActivityPub\Common\Announce();
|
||||||
$announce->setID($activity['id'])
|
$announce->setAActor((string) $activity['actor'])
|
||||||
->setURL($activity['id'])
|
->setPublished($published !== false ? $published : time())
|
||||||
->setPublished(strtotime($activity['published'] ?? 'now'))
|
->setID((string) $activity['id'])
|
||||||
->setAActor($activity['actor']);
|
->setURL((string) $activity['id']);
|
||||||
|
|
||||||
if (array_key_exists('cc', $activity)) {
|
if (array_key_exists('cc', $activity)) {
|
||||||
foreach ($activity['cc'] as $cc) {
|
foreach ($activity['cc'] as $cc) {
|
||||||
|
@ -232,11 +240,12 @@ class Outbox implements \Federator\Api\FedUsers\FedUsersInterface
|
||||||
// Parse the shared object as a Note or something else
|
// Parse the shared object as a Note or something else
|
||||||
switch ($objData['type']) {
|
switch ($objData['type']) {
|
||||||
case 'Note':
|
case 'Note':
|
||||||
|
$published = strtotime($objData['published'] ?? 'now');
|
||||||
$note = new \Federator\Data\ActivityPub\Common\Note();
|
$note = new \Federator\Data\ActivityPub\Common\Note();
|
||||||
$note->setID($objData['id'])
|
$note->setPublished($published !== false ? $published : time())
|
||||||
|
->setID($objData['id'])
|
||||||
->setSummary($objData['summary'])
|
->setSummary($objData['summary'])
|
||||||
->setContent($objData['content'] ?? '')
|
->setContent($objData['content'] ?? '')
|
||||||
->setPublished(strtotime($objData['published'] ?? 'now'))
|
|
||||||
->setURL($objData['url'] ?? $objData['id'])
|
->setURL($objData['url'] ?? $objData['id'])
|
||||||
->setAttributedTo($objData['attributedTo'] ?? null)
|
->setAttributedTo($objData['attributedTo'] ?? null)
|
||||||
->addTo("https://www.w3.org/ns/activitystreams#Public");
|
->addTo("https://www.w3.org/ns/activitystreams#Public");
|
||||||
|
@ -264,9 +273,9 @@ class Outbox implements \Federator\Api\FedUsers\FedUsersInterface
|
||||||
}
|
}
|
||||||
|
|
||||||
$undo = new \Federator\Data\ActivityPub\Common\Undo();
|
$undo = new \Federator\Data\ActivityPub\Common\Undo();
|
||||||
$undo->setID($activity['id'] ?? "test")
|
$undo->setActor($activity['actor'] ?? null)
|
||||||
->setURL($activity['url'] ?? $activity['id'])
|
->setID($activity['id'] ?? "test")
|
||||||
->setActor($activity['actor'] ?? null);
|
->setURL($activity['url'] ?? $activity['id']);
|
||||||
|
|
||||||
if (array_key_exists('cc', $activity)) {
|
if (array_key_exists('cc', $activity)) {
|
||||||
foreach ($activity['cc'] as $cc) {
|
foreach ($activity['cc'] as $cc) {
|
||||||
|
@ -284,11 +293,12 @@ class Outbox implements \Federator\Api\FedUsers\FedUsersInterface
|
||||||
if (is_array($undone) && isset($undone['type'])) {
|
if (is_array($undone) && isset($undone['type'])) {
|
||||||
switch ($undone['type']) {
|
switch ($undone['type']) {
|
||||||
case 'Announce':
|
case 'Announce':
|
||||||
|
$published = strtotime($undone['published'] ?? 'now');
|
||||||
$announce = new \Federator\Data\ActivityPub\Common\Announce();
|
$announce = new \Federator\Data\ActivityPub\Common\Announce();
|
||||||
$announce->setID($undone['id'] ?? null)
|
$announce->setAActor($undone['actor'] ?? null)
|
||||||
->setAActor($undone['actor'] ?? null)
|
->setPublished($published !== false ? $published : time())
|
||||||
->setURL($undone['url'] ?? $undone['id'])
|
->setID($undone['id'] ?? null)
|
||||||
->setPublished(strtotime($undone['published'] ?? 'now'));
|
->setURL($undone['url'] ?? $undone['id']);
|
||||||
|
|
||||||
if (array_key_exists('cc', $undone)) {
|
if (array_key_exists('cc', $undone)) {
|
||||||
foreach ($undone['cc'] as $cc) {
|
foreach ($undone['cc'] as $cc) {
|
||||||
|
@ -313,31 +323,46 @@ class Outbox implements \Federator\Api\FedUsers\FedUsersInterface
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
error_log("Outbox::post we currently don't support the activity type " . $activity['type'] . "\n");
|
error_log("Outbox::post we currently don't support the activity type " . $activity['type'] . "\n");
|
||||||
|
$apObject = new \Federator\Data\ActivityPub\Common\Activity($activity['type']);
|
||||||
|
$apObject->setID($activity['id'] ?? null);
|
||||||
|
$outboxActivity = $apObject;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!isset($outboxActivity)) {
|
||||||
|
error_log("Outbox::post couldn't create outboxActivity, aborting");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
$sendTo = $outboxActivity->getCC();
|
$sendTo = $outboxActivity->getCC();
|
||||||
if ($outboxActivity->getType() === 'Undo') {
|
if ($outboxActivity->getType() === 'Undo') {
|
||||||
$sendTo = $outboxActivity->getObject()->getCC();
|
$object = $outboxActivity->getObject();
|
||||||
|
if ($object !== null) {
|
||||||
|
$sendTo = $object->getCC();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$users = [];
|
$users = [];
|
||||||
|
|
||||||
foreach ($sendTo as $receiver) {
|
foreach ($sendTo as $receiver) {
|
||||||
if (!$receiver || !is_string($receiver)) {
|
if ($receiver === '' || !is_string($receiver)) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (str_ends_with($receiver, '/followers')) {
|
if (str_ends_with($receiver, '/followers')) {
|
||||||
$users = array_merge($users, $this->fetchAllFollowers($receiver, $host));
|
$followers = $this->fetchAllFollowers($receiver, $host);
|
||||||
|
if (is_array($followers)) {
|
||||||
|
$users = array_merge($users, $followers);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if ($_user !== false && !in_array($_user, $users)) {
|
}
|
||||||
|
if ($_user !== false && !in_array($_user, $users, true)) {
|
||||||
$users[] = $_user;
|
$users[] = $_user;
|
||||||
}
|
}
|
||||||
foreach ($users as $user) {
|
foreach ($users as $user) {
|
||||||
if (!$user)
|
if (!isset($user)) {
|
||||||
continue;
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
$this->postForUser($user, $outboxActivity);
|
$this->postForUser($user, $outboxActivity);
|
||||||
}
|
}
|
||||||
|
@ -349,11 +374,11 @@ class Outbox implements \Federator\Api\FedUsers\FedUsersInterface
|
||||||
*
|
*
|
||||||
* @param string $_user user to add data to outbox
|
* @param string $_user user to add data to outbox
|
||||||
* @param \Federator\Data\ActivityPub\Common\Activity $outboxActivity the activity that we received
|
* @param \Federator\Data\ActivityPub\Common\Activity $outboxActivity the activity that we received
|
||||||
* @return string|false response
|
* @return boolean response
|
||||||
*/
|
*/
|
||||||
private function postForUser($_user, $outboxActivity)
|
private function postForUser($_user, $outboxActivity)
|
||||||
{
|
{
|
||||||
if ($_user) {
|
if (isset($_user)) {
|
||||||
$dbh = $this->main->getDatabase();
|
$dbh = $this->main->getDatabase();
|
||||||
$cache = $this->main->getCache();
|
$cache = $this->main->getCache();
|
||||||
$connector = $this->main->getConnector();
|
$connector = $this->main->getConnector();
|
||||||
|
@ -387,14 +412,14 @@ class Outbox implements \Federator\Api\FedUsers\FedUsersInterface
|
||||||
*
|
*
|
||||||
* @param string $collectionUrl The url of f.e. the posters followers
|
* @param string $collectionUrl The url of f.e. the posters followers
|
||||||
* @param string $host our current host-url
|
* @param string $host our current host-url
|
||||||
* @return array|false the names of the followers that are hosted on our server
|
* @return string[] the names of the followers that are hosted on our server
|
||||||
*/
|
*/
|
||||||
private function fetchAllFollowers(string $collectionUrl, string $host): array
|
private static function fetchAllFollowers(string $collectionUrl, string $host): array
|
||||||
{
|
{
|
||||||
$users = [];
|
$users = [];
|
||||||
|
|
||||||
[$collectionResponse, $collectionInfo] = \Federator\Main::getFromRemote($collectionUrl, ['Accept: application/activity+json']);
|
[$collectionResponse, $collectionInfo] = \Federator\Main::getFromRemote($collectionUrl, ['Accept: application/activity+json']);
|
||||||
if ($collectionInfo['http_code'] !== 200) {
|
if ($collectionInfo['http_code'] != 200) {
|
||||||
error_log("Outbox::fetchAllFollowers Failed to fetch follower collection metadata from $collectionUrl");
|
error_log("Outbox::fetchAllFollowers Failed to fetch follower collection metadata from $collectionUrl");
|
||||||
return [];
|
return [];
|
||||||
}
|
}
|
||||||
|
@ -402,7 +427,7 @@ class Outbox implements \Federator\Api\FedUsers\FedUsersInterface
|
||||||
$collectionData = json_decode($collectionResponse, true);
|
$collectionData = json_decode($collectionResponse, true);
|
||||||
$nextPage = $collectionData['first'] ?? $collectionData['current'] ?? null;
|
$nextPage = $collectionData['first'] ?? $collectionData['current'] ?? null;
|
||||||
|
|
||||||
if (!$nextPage) {
|
if (!isset($nextPage)) {
|
||||||
error_log("Outbox::fetchAllFollowers No 'first' or 'current' page in collection at $collectionUrl");
|
error_log("Outbox::fetchAllFollowers No 'first' or 'current' page in collection at $collectionUrl");
|
||||||
return [];
|
return [];
|
||||||
}
|
}
|
||||||
|
@ -410,7 +435,7 @@ class Outbox implements \Federator\Api\FedUsers\FedUsersInterface
|
||||||
// Loop through all pages
|
// Loop through all pages
|
||||||
while ($nextPage) {
|
while ($nextPage) {
|
||||||
[$pageResponse, $pageInfo] = \Federator\Main::getFromRemote($nextPage, ['Accept: application/activity+json']);
|
[$pageResponse, $pageInfo] = \Federator\Main::getFromRemote($nextPage, ['Accept: application/activity+json']);
|
||||||
if ($pageInfo['http_code'] !== 200) {
|
if ($pageInfo['http_code'] != 200) {
|
||||||
error_log("Outbox::fetchAllFollowers Failed to fetch follower page at $nextPage");
|
error_log("Outbox::fetchAllFollowers Failed to fetch follower page at $nextPage");
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -425,7 +450,7 @@ class Outbox implements \Federator\Api\FedUsers\FedUsersInterface
|
||||||
}
|
}
|
||||||
|
|
||||||
[$actorResponse, $actorInfo] = \Federator\Main::getFromRemote($followerUrl, ['Accept: application/activity+json']);
|
[$actorResponse, $actorInfo] = \Federator\Main::getFromRemote($followerUrl, ['Accept: application/activity+json']);
|
||||||
if ($actorInfo['http_code'] !== 200) {
|
if ($actorInfo['http_code'] != 200) {
|
||||||
error_log("Outbox::fetchAllFollowers Failed to fetch actor data for follower: $followerUrl");
|
error_log("Outbox::fetchAllFollowers Failed to fetch actor data for follower: $followerUrl");
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
|
@ -23,9 +23,9 @@ class Dummy implements \Federator\Api\APIInterface
|
||||||
/**
|
/**
|
||||||
* internal message to output
|
* internal message to output
|
||||||
*
|
*
|
||||||
* @var string $response
|
* @var string $message
|
||||||
*/
|
*/
|
||||||
private $message = [];
|
private $message = '';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* constructor
|
* constructor
|
||||||
|
@ -41,7 +41,7 @@ class Dummy implements \Federator\Api\APIInterface
|
||||||
* run given url path
|
* run given url path
|
||||||
*
|
*
|
||||||
* @param array<string> $paths path array split by /
|
* @param array<string> $paths path array split by /
|
||||||
* @param \Federator\Data\User|false $user user who is calling us
|
* @param \Federator\Data\User|false $user user who is calling us @unused-param
|
||||||
* @return bool true on success
|
* @return bool true on success
|
||||||
*/
|
*/
|
||||||
public function exec($paths, $user): bool
|
public function exec($paths, $user): bool
|
||||||
|
@ -151,16 +151,26 @@ class Dummy implements \Federator\Api\APIInterface
|
||||||
*/
|
*/
|
||||||
public function getDummy()
|
public function getDummy()
|
||||||
{
|
{
|
||||||
$this->message = json_encode([
|
$dummyResponse = json_encode([
|
||||||
'r1' => ' (__) ',
|
'r1' => ' (__) ',
|
||||||
'r2' => ' `------(oo) ',
|
'r2' => ' `------(oo) ',
|
||||||
'r3' => ' || __ (__) ',
|
'r3' => ' || __ (__) ',
|
||||||
'r4' => ' ||w || ',
|
'r4' => ' ||w || ',
|
||||||
'r5' => ' '
|
'r5' => ' '
|
||||||
], JSON_PRETTY_PRINT);
|
], JSON_PRETTY_PRINT);
|
||||||
|
if ($dummyResponse !== false) {
|
||||||
|
$this->message = $dummyResponse;
|
||||||
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* get function for "/v1/dummy/moo"
|
||||||
|
*
|
||||||
|
* @param string $_name user-id which we try to retrieve
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
public function getUser($_name)
|
public function getUser($_name)
|
||||||
{
|
{
|
||||||
error_log("Someone tried to get user: " . $_name);
|
error_log("Someone tried to get user: " . $_name);
|
||||||
|
@ -360,9 +370,13 @@ $publicKeyPemJsonSafe = json_encode($publicKeyPem); // gives string with \n insi
|
||||||
FILE_APPEND
|
FILE_APPEND
|
||||||
);
|
);
|
||||||
|
|
||||||
$this->message = json_encode([
|
$successMsg = json_encode([
|
||||||
'status' => 'received',
|
'status' => 'received',
|
||||||
]);
|
]);
|
||||||
|
|
||||||
|
if ($successMsg !== false) {
|
||||||
|
$this->message = $successMsg;
|
||||||
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -381,9 +395,13 @@ $publicKeyPemJsonSafe = json_encode($publicKeyPem); // gives string with \n insi
|
||||||
FILE_APPEND
|
FILE_APPEND
|
||||||
);
|
);
|
||||||
|
|
||||||
$this->message = json_encode([
|
$successMsg = json_encode([
|
||||||
'status' => 'received',
|
'status' => 'received',
|
||||||
]);
|
]);
|
||||||
|
|
||||||
|
if ($successMsg !== false) {
|
||||||
|
$this->message = $successMsg;
|
||||||
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -402,9 +420,13 @@ $publicKeyPemJsonSafe = json_encode($publicKeyPem); // gives string with \n insi
|
||||||
FILE_APPEND
|
FILE_APPEND
|
||||||
);
|
);
|
||||||
|
|
||||||
$this->message = json_encode([
|
$successMsg = json_encode([
|
||||||
'status' => 'received',
|
'status' => 'received',
|
||||||
]);
|
]);
|
||||||
|
|
||||||
|
if ($successMsg !== false) {
|
||||||
|
$this->message = $successMsg;
|
||||||
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -423,9 +445,13 @@ $publicKeyPemJsonSafe = json_encode($publicKeyPem); // gives string with \n insi
|
||||||
FILE_APPEND
|
FILE_APPEND
|
||||||
);
|
);
|
||||||
|
|
||||||
$this->message = json_encode([
|
$successMsg = json_encode([
|
||||||
'status' => 'received',
|
'status' => 'received',
|
||||||
]);
|
]);
|
||||||
|
|
||||||
|
if ($successMsg !== false) {
|
||||||
|
$this->message = $successMsg;
|
||||||
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -444,9 +470,13 @@ $publicKeyPemJsonSafe = json_encode($publicKeyPem); // gives string with \n insi
|
||||||
FILE_APPEND
|
FILE_APPEND
|
||||||
);
|
);
|
||||||
|
|
||||||
$this->message = json_encode([
|
$successMsg = json_encode([
|
||||||
'status' => 'received',
|
'status' => 'received',
|
||||||
]);
|
]);
|
||||||
|
|
||||||
|
if ($successMsg !== false) {
|
||||||
|
$this->message = $successMsg;
|
||||||
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -465,9 +495,13 @@ $publicKeyPemJsonSafe = json_encode($publicKeyPem); // gives string with \n insi
|
||||||
FILE_APPEND
|
FILE_APPEND
|
||||||
);
|
);
|
||||||
|
|
||||||
$this->message = json_encode([
|
$successMsg = json_encode([
|
||||||
'status' => 'received',
|
'status' => 'received',
|
||||||
]);
|
]);
|
||||||
|
|
||||||
|
if ($successMsg !== false) {
|
||||||
|
$this->message = $successMsg;
|
||||||
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -486,9 +520,13 @@ $publicKeyPemJsonSafe = json_encode($publicKeyPem); // gives string with \n insi
|
||||||
FILE_APPEND
|
FILE_APPEND
|
||||||
);
|
);
|
||||||
|
|
||||||
$this->message = json_encode([
|
$successMsg = json_encode([
|
||||||
'status' => 'received',
|
'status' => 'received',
|
||||||
]);
|
]);
|
||||||
|
|
||||||
|
if ($successMsg !== false) {
|
||||||
|
$this->message = $successMsg;
|
||||||
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -507,9 +545,13 @@ $publicKeyPemJsonSafe = json_encode($publicKeyPem); // gives string with \n insi
|
||||||
FILE_APPEND
|
FILE_APPEND
|
||||||
);
|
);
|
||||||
|
|
||||||
$this->message = json_encode([
|
$successMsg = json_encode([
|
||||||
'status' => 'received',
|
'status' => 'received',
|
||||||
]);
|
]);
|
||||||
|
|
||||||
|
if ($successMsg !== false) {
|
||||||
|
$this->message = $successMsg;
|
||||||
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -528,9 +570,13 @@ $publicKeyPemJsonSafe = json_encode($publicKeyPem); // gives string with \n insi
|
||||||
FILE_APPEND
|
FILE_APPEND
|
||||||
);
|
);
|
||||||
|
|
||||||
$this->message = json_encode([
|
$successMsg = json_encode([
|
||||||
'status' => 'received',
|
'status' => 'received',
|
||||||
]);
|
]);
|
||||||
|
|
||||||
|
if ($successMsg !== false) {
|
||||||
|
$this->message = $successMsg;
|
||||||
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -549,9 +595,13 @@ $publicKeyPemJsonSafe = json_encode($publicKeyPem); // gives string with \n insi
|
||||||
FILE_APPEND
|
FILE_APPEND
|
||||||
);
|
);
|
||||||
|
|
||||||
$this->message = json_encode([
|
$successMsg = json_encode([
|
||||||
'status' => 'received',
|
'status' => 'received',
|
||||||
]);
|
]);
|
||||||
|
|
||||||
|
if ($successMsg !== false) {
|
||||||
|
$this->message = $successMsg;
|
||||||
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -261,7 +261,7 @@ class Main
|
||||||
*/
|
*/
|
||||||
public function setConnector(Connector\Connector $connector) : void
|
public function setConnector(Connector\Connector $connector) : void
|
||||||
{
|
{
|
||||||
if ($this->connector) {
|
if (isset($this->connector)) {
|
||||||
# echo "main::setConnector Setting new connector will override old one.\n"; // TODO CHANGE TO LOG WARNING
|
# echo "main::setConnector Setting new connector will override old one.\n"; // TODO CHANGE TO LOG WARNING
|
||||||
}
|
}
|
||||||
$this->connector = $connector;
|
$this->connector = $connector;
|
||||||
|
@ -274,7 +274,7 @@ class Main
|
||||||
*/
|
*/
|
||||||
public function setHost(string $host) : void
|
public function setHost(string $host) : void
|
||||||
{
|
{
|
||||||
if ($this->host) {
|
if (isset($this->host)) {
|
||||||
# echo "main::setHost Setting new host will override old one.\n"; // TODO CHANGE TO LOG WARNING
|
# echo "main::setHost Setting new host will override old one.\n"; // TODO CHANGE TO LOG WARNING
|
||||||
}
|
}
|
||||||
$this->host = $host;
|
$this->host = $host;
|
||||||
|
|
|
@ -60,7 +60,7 @@ class ContentNation implements Connector
|
||||||
*/
|
*/
|
||||||
public function getRemotePostsByUser($userId, $min, $max)
|
public function getRemotePostsByUser($userId, $min, $max)
|
||||||
{
|
{
|
||||||
if (preg_match("#^([^@]+)@([^/]+)#", $userId, $matches) === 1) {
|
if (preg_match("#^([^@]+)@([^/]+)#", $userId, $matches) == 1) {
|
||||||
$userId = $matches[1];
|
$userId = $matches[1];
|
||||||
}
|
}
|
||||||
$remoteURL = $this->service . '/api/profile/' . urlencode($userId) . '/activities';
|
$remoteURL = $this->service . '/api/profile/' . urlencode($userId) . '/activities';
|
||||||
|
@ -129,9 +129,12 @@ class ContentNation implements Connector
|
||||||
->setURL($idurl);
|
->setURL($idurl);
|
||||||
$image = $activity['image'] ?? $activity['profileimg'];
|
$image = $activity['image'] ?? $activity['profileimg'];
|
||||||
$path = $imgpath . $activity['profile'] . '/' . $image;
|
$path = $imgpath . $activity['profile'] . '/' . $image;
|
||||||
$mediaType = (file_exists($path) && ($type = mime_content_type($path)) && !str_starts_with($type, 'text/'))
|
|
||||||
|
$type = file_exists($path) ? mime_content_type($path) : false;
|
||||||
|
$mediaType = ($type !== false && !str_starts_with($type, 'text/'))
|
||||||
? $type
|
? $type
|
||||||
: 'image/jpeg';
|
: 'image/jpeg';
|
||||||
|
|
||||||
$img = new \Federator\Data\ActivityPub\Common\Image();
|
$img = new \Federator\Data\ActivityPub\Common\Image();
|
||||||
$img->setMediaType($mediaType)
|
$img->setMediaType($mediaType)
|
||||||
->setName($articleimage)
|
->setName($articleimage)
|
||||||
|
@ -228,7 +231,7 @@ class ContentNation implements Connector
|
||||||
*/
|
*/
|
||||||
public function getRemoteUserByName(string $_name)
|
public function getRemoteUserByName(string $_name)
|
||||||
{
|
{
|
||||||
if (preg_match("#^([^@]+)@([^/]+)#", $_name, $matches) === 1) {
|
if (preg_match("#^([^@]+)@([^/]+)#", $_name, $matches) == 1) {
|
||||||
$_name = $matches[1];
|
$_name = $matches[1];
|
||||||
}
|
}
|
||||||
// validate name
|
// validate name
|
||||||
|
|
Loading…
Add table
Reference in a new issue