]> git.mxchange.org Git - friendica.git/blobdiff - src/Module/Friendica.php
Issue 11566: More detailled notification configuration
[friendica.git] / src / Module / Friendica.php
index 5e77eb00fbbe59f3c3136c5f26d5667731a35071..c5a66fa3d5038ffc0e23f6caa22a95899a4250f9 100644 (file)
@@ -1,6 +1,6 @@
 <?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
  *
@@ -29,6 +29,7 @@ use Friendica\Core\System;
 use Friendica\Database\PostUpdate;
 use Friendica\DI;
 use Friendica\Model\User;
+use Friendica\Network\HTTPException;
 use Friendica\Protocol\ActivityPub;
 
 /**
@@ -37,7 +38,7 @@ use Friendica\Protocol\ActivityPub;
  */
 class Friendica extends BaseModule
 {
-       public static function content(array $parameters = [])
+       protected function content(array $request = []): string
        {
                $config = DI::config();
 
@@ -109,22 +110,24 @@ class Friendica extends BaseModule
                ]);
        }
 
-       public static function rawContent(array $parameters = [])
+       protected function rawContent(array $request = [])
        {
-               if (ActivityPub::isRequest()) {
-                       $data = ActivityPub\Transmitter::getProfile(0);
-                       if (!empty($data)) {
+               // @TODO: Replace with parameter from router
+               if (DI::args()->getArgc() <= 1 || (DI::args()->getArgv()[1] !== 'json')) {
+                       if (!ActivityPub::isRequest()) {
+                               return;
+                       }
+
+                       try {
+                               $data = ActivityPub\Transmitter::getProfile(0);
                                header('Access-Control-Allow-Origin: *');
                                header('Cache-Control: max-age=23200, stale-while-revalidate=23200');
                                System::jsonExit($data, 'application/activity+json');
+                       } catch (HTTPException\NotFoundException $e) {
+                               System::jsonError(404, ['error' => 'Record not found']);
                        }
                }
 
-               // @TODO: Replace with parameter from router
-               if (DI::args()->getArgc() <= 1 || (DI::args()->getArgv()[1] !== 'json')) {
-                       return;
-               }
-
                $config = DI::config();
 
                $register_policies = [
@@ -179,8 +182,6 @@ class Friendica extends BaseModule
                        'no_scrape_url'    => DI::baseUrl()->get() . '/noscrape',
                ];
 
-               header('Content-type: application/json; charset=utf-8');
-               echo json_encode($data);
-               exit();
+               System::jsonExit($data);
        }
 }