From 5a6887fb2e4f3a78207547d1fe801403645c9a80 Mon Sep 17 00:00:00 2001 From: Michael Date: Mon, 13 Jul 2020 13:26:09 +0000 Subject: [PATCH] Use "jsonexit" --- src/Core/System.php | 9 +++++---- src/Module/NodeInfo110.php | 5 ++--- src/Module/NodeInfo120.php | 5 ++--- src/Module/NodeInfo210.php | 5 ++--- 4 files changed, 11 insertions(+), 13 deletions(-) diff --git a/src/Core/System.php b/src/Core/System.php index feed85e21..37e6d8a1c 100644 --- a/src/Core/System.php +++ b/src/Core/System.php @@ -136,12 +136,13 @@ class System * and adds an application/json HTTP header to the output. * After finishing the process is getting killed. * - * @param mixed $x The input content. - * @param string $content_type Type of the input (Default: 'application/json'). + * @param mixed $x The input content. + * @param string $content_type Type of the input (Default: 'application/json'). + * @param integer $options JSON options */ - public static function jsonExit($x, $content_type = 'application/json') { + public static function jsonExit($x, $content_type = 'application/json', int $options = null) { header("Content-type: $content_type"); - echo json_encode($x); + echo json_encode($x, $options); exit(); } diff --git a/src/Module/NodeInfo110.php b/src/Module/NodeInfo110.php index 954f36219..79e215e4f 100644 --- a/src/Module/NodeInfo110.php +++ b/src/Module/NodeInfo110.php @@ -23,6 +23,7 @@ namespace Friendica\Module; use Friendica\BaseModule; use Friendica\Core\Addon; +use Friendica\Core\System; use Friendica\DI; use Friendica\Model\Nodeinfo; @@ -85,8 +86,6 @@ class NodeInfo110 extends BaseModule $nodeinfo['metadata']['explicitContent'] = $config->get('system', 'explicit_content', false) == true; - header('Content-type: application/json; charset=utf-8'); - echo json_encode($nodeinfo, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES); - exit; + System::jsonExit($nodeinfo, 'application/json; charset=utf-8', JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES); } } diff --git a/src/Module/NodeInfo120.php b/src/Module/NodeInfo120.php index 330c5e10d..56054d7b6 100644 --- a/src/Module/NodeInfo120.php +++ b/src/Module/NodeInfo120.php @@ -23,6 +23,7 @@ namespace Friendica\Module; use Friendica\BaseModule; use Friendica\Core\Addon; +use Friendica\Core\System; use Friendica\DI; use Friendica\Model\Nodeinfo; @@ -79,8 +80,6 @@ class NodeInfo120 extends BaseModule $nodeinfo['metadata']['explicitContent'] = $config->get('system', 'explicit_content', false) == true; - header('Content-type: application/json; charset=utf-8'); - echo json_encode($nodeinfo, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES); - exit; + System::jsonExit($nodeinfo, 'application/json; charset=utf-8', JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES); } } diff --git a/src/Module/NodeInfo210.php b/src/Module/NodeInfo210.php index 63a174983..a95e37fa2 100644 --- a/src/Module/NodeInfo210.php +++ b/src/Module/NodeInfo210.php @@ -23,6 +23,7 @@ namespace Friendica\Module; use Friendica\BaseModule; use Friendica\Core\Addon; +use Friendica\Core\System; use Friendica\DI; use Friendica\Model\Nodeinfo; @@ -77,8 +78,6 @@ class NodeInfo210 extends BaseModule $nodeinfo['services']['inbound'][] = 'imap'; } - header('Content-type: application/json; charset=utf-8'); - echo json_encode($nodeinfo, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES); - exit; + System::jsonExit($nodeinfo, 'application/json; charset=utf-8', JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES); } }