Use "jsonexit"

This commit is contained in:
Michael 2020-07-13 13:26:09 +00:00
parent 27deb4d188
commit 5a6887fb2e
4 changed files with 11 additions and 13 deletions

View file

@ -136,12 +136,13 @@ class System
* and adds an application/json HTTP header to the output. * and adds an application/json HTTP header to the output.
* After finishing the process is getting killed. * After finishing the process is getting killed.
* *
* @param mixed $x The input content. * @param mixed $x The input content.
* @param string $content_type Type of the input (Default: 'application/json'). * @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"); header("Content-type: $content_type");
echo json_encode($x); echo json_encode($x, $options);
exit(); exit();
} }

View file

@ -23,6 +23,7 @@ namespace Friendica\Module;
use Friendica\BaseModule; use Friendica\BaseModule;
use Friendica\Core\Addon; use Friendica\Core\Addon;
use Friendica\Core\System;
use Friendica\DI; use Friendica\DI;
use Friendica\Model\Nodeinfo; use Friendica\Model\Nodeinfo;
@ -85,8 +86,6 @@ class NodeInfo110 extends BaseModule
$nodeinfo['metadata']['explicitContent'] = $config->get('system', 'explicit_content', false) == true; $nodeinfo['metadata']['explicitContent'] = $config->get('system', 'explicit_content', false) == true;
header('Content-type: application/json; charset=utf-8'); System::jsonExit($nodeinfo, 'application/json; charset=utf-8', JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES);
echo json_encode($nodeinfo, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES);
exit;
} }
} }

View file

@ -23,6 +23,7 @@ namespace Friendica\Module;
use Friendica\BaseModule; use Friendica\BaseModule;
use Friendica\Core\Addon; use Friendica\Core\Addon;
use Friendica\Core\System;
use Friendica\DI; use Friendica\DI;
use Friendica\Model\Nodeinfo; use Friendica\Model\Nodeinfo;
@ -79,8 +80,6 @@ class NodeInfo120 extends BaseModule
$nodeinfo['metadata']['explicitContent'] = $config->get('system', 'explicit_content', false) == true; $nodeinfo['metadata']['explicitContent'] = $config->get('system', 'explicit_content', false) == true;
header('Content-type: application/json; charset=utf-8'); System::jsonExit($nodeinfo, 'application/json; charset=utf-8', JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES);
echo json_encode($nodeinfo, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES);
exit;
} }
} }

View file

@ -23,6 +23,7 @@ namespace Friendica\Module;
use Friendica\BaseModule; use Friendica\BaseModule;
use Friendica\Core\Addon; use Friendica\Core\Addon;
use Friendica\Core\System;
use Friendica\DI; use Friendica\DI;
use Friendica\Model\Nodeinfo; use Friendica\Model\Nodeinfo;
@ -77,8 +78,6 @@ class NodeInfo210 extends BaseModule
$nodeinfo['services']['inbound'][] = 'imap'; $nodeinfo['services']['inbound'][] = 'imap';
} }
header('Content-type: application/json; charset=utf-8'); System::jsonExit($nodeinfo, 'application/json; charset=utf-8', JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES);
echo json_encode($nodeinfo, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES);
exit;
} }
} }