X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=src%2FModule%2FDiaspora%2FReceive.php;h=242b774b33a450190d9c5ae677545a0dc997675d;hb=561aba18e3a230c0912ad9483c6df43cc40e09d6;hp=01c04dfb6cfc5b6aa4c85442c0c2319a91d668f3;hpb=23c64b9a119c5df9f985ad4c62ef6fb79d68bee3;p=friendica.git diff --git a/src/Module/Diaspora/Receive.php b/src/Module/Diaspora/Receive.php index 01c04dfb6c..242b774b33 100644 --- a/src/Module/Diaspora/Receive.php +++ b/src/Module/Diaspora/Receive.php @@ -1,6 +1,6 @@ config = $config; } - public static function post(array $parameters = []) + protected function post(array $request = [], array $post = []) { - $enabled = DI::config()->get('system', 'diaspora_enabled', false); + $enabled = $this->config->get('system', 'diaspora_enabled', false); if (!$enabled) { - self::$logger->info('Diaspora disabled.'); - throw new HTTPException\ForbiddenException(DI::l10n()->t('Access denied.')); + $this->logger->info('Diaspora disabled.'); + throw new HTTPException\ForbiddenException($this->t('Access denied.')); } - $args = DI::args(); - - $type = $args->get(1); - - switch ($type) { - case 'public': - self::receivePublic(); - break; - case 'users': - self::receiveUser($args->get(2)); - break; - default: - self::$logger->info('Wrong call.'); - throw new HTTPException\BadRequestException('wrong call.'); - break; + if ($this->parameters['type'] === 'public') { + $this->receivePublic(); + } else if ($this->parameters['type'] === 'users') { + $this->receiveUser(); } } @@ -75,13 +70,13 @@ class Receive extends BaseModule * @throws HTTPException\InternalServerErrorException * @throws \ImagickException */ - private static function receivePublic() + private function receivePublic() { - self::$logger->info('Diaspora: Receiving post.'); + $this->logger->info('Diaspora: Receiving post.'); - $msg = self::decodePost(); + $msg = $this->decodePost(); - self::$logger->info('Diaspora: Dispatching.'); + $this->logger->info('Diaspora: Dispatching.'); Diaspora::dispatchPublic($msg); } @@ -89,25 +84,25 @@ class Receive extends BaseModule /** * Receive a Diaspora posting for a user * - * @param string $guid The GUID of the importer - * * @throws HTTPException\InternalServerErrorException * @throws \ImagickException */ - private static function receiveUser(string $guid) + private function receiveUser() { - self::$logger->info('Diaspora: Receiving post.'); + $this->logger->info('Diaspora: Receiving post.'); - $importer = User::getByGuid($guid); + $importer = User::getByGuid($this->parameters['guid']); - $msg = self::decodePost(false, $importer['prvkey'] ?? ''); + $msg = $this->decodePost(false, $importer['prvkey'] ?? ''); - self::$logger->info('Diaspora: Dispatching.'); + $this->logger->info('Diaspora: Dispatching.'); if (Diaspora::dispatch($importer, $msg)) { throw new HTTPException\OKException(); } else { - throw new HTTPException\InternalServerErrorException(); + // We couldn't process the content. + // To avoid the remote system trying again we send the message that we accepted the content. + throw new HTTPException\AcceptedException(); } } @@ -121,7 +116,7 @@ class Receive extends BaseModule * @throws HTTPException\InternalServerErrorException * @throws \ImagickException */ - private static function decodePost(bool $public = true, string $privKey = '') + private function decodePost(bool $public = true, string $privKey = '') { if (empty($_POST['xml'])) { @@ -131,24 +126,24 @@ class Receive extends BaseModule throw new HTTPException\InternalServerErrorException('Missing postdata.'); } - self::$logger->info('Diaspora: Message is in the new format.'); + $this->logger->info('Diaspora: Message is in the new format.'); $msg = Diaspora::decodeRaw($postdata, $privKey); } else { $xml = urldecode($_POST['xml']); - self::$logger->info('Diaspora: Decode message in the old format.'); + $this->logger->info('Diaspora: Decode message in the old format.'); $msg = Diaspora::decode($xml, $privKey); if ($public && !$msg) { - self::$logger->info('Diaspora: Decode message in the new format.'); + $this->logger->info('Diaspora: Decode message in the new format.'); $msg = Diaspora::decodeRaw($xml, $privKey); } } - self::$logger->info('Diaspora: Post decoded.'); - self::$logger->debug('Diaspora: Decoded message.', ['msg' => print_r($msg, true)]); + $this->logger->info('Diaspora: Post decoded.'); + $this->logger->debug('Diaspora: Decoded message.', ['msg' => $msg]); if (!is_array($msg)) { throw new HTTPException\InternalServerErrorException('Message is not an array.');