Merge remote-tracking branch 'upstream/develop' into user-defined-channels

This commit is contained in:
Michael 2023-09-30 18:44:12 +00:00
commit e7d65f2d12
221 changed files with 581 additions and 409 deletions

View file

@ -716,7 +716,7 @@ class App
} }
$this->logger->debug('Request processed sucessfully', ['response' => $response->getStatusCode(), 'address' => $_SERVER['REMOTE_ADDR'] ?? '', 'request' => $requeststring, 'referer' => $_SERVER['HTTP_REFERER'] ?? '', 'user-agent' => $_SERVER['HTTP_USER_AGENT'] ?? '']); $this->logger->debug('Request processed sucessfully', ['response' => $response->getStatusCode(), 'address' => $_SERVER['REMOTE_ADDR'] ?? '', 'request' => $requeststring, 'referer' => $_SERVER['HTTP_REFERER'] ?? '', 'user-agent' => $_SERVER['HTTP_USER_AGENT'] ?? '']);
$page->exit($response); System::echoResponse($response);
} catch (HTTPException $e) { } catch (HTTPException $e) {
$this->logger->debug('Request processed with exception', ['response' => $e->getCode(), 'address' => $_SERVER['REMOTE_ADDR'] ?? '', 'request' => $requeststring, 'referer' => $_SERVER['HTTP_REFERER'] ?? '', 'user-agent' => $_SERVER['HTTP_USER_AGENT'] ?? '']); $this->logger->debug('Request processed with exception', ['response' => $e->getCode(), 'address' => $_SERVER['REMOTE_ADDR'] ?? '', 'request' => $requeststring, 'referer' => $_SERVER['HTTP_REFERER'] ?? '', 'user-agent' => $_SERVER['HTTP_USER_AGENT'] ?? '']);
$httpException->rawContent($e); $httpException->rawContent($e);

View file

@ -401,36 +401,6 @@ class Page implements ArrayAccess
$this->footerScripts[] = trim($url, '/'); $this->footerScripts[] = trim($url, '/');
} }
/**
* Directly exit with the current response (include setting all headers)
*
* @param ResponseInterface $response
*/
public function exit(ResponseInterface $response)
{
header(sprintf("HTTP/%s %s %s",
$response->getProtocolVersion(),
$response->getStatusCode(),
$response->getReasonPhrase())
);
foreach ($response->getHeaders() as $key => $header) {
if (is_array($header)) {
$header_str = implode(',', $header);
} else {
$header_str = $header;
}
if (empty($key)) {
header($header_str);
} else {
header("$key: $header_str");
}
}
echo $response->getBody();
}
/** /**
* Executes the creation of the current page and prints it to the screen * Executes the creation of the current page and prints it to the screen
* *
@ -526,7 +496,9 @@ class Page implements ArrayAccess
} }
if ($_GET["mode"] == "raw") { if ($_GET["mode"] == "raw") {
System::httpExit(substr($target->saveHTML(), 6, -8), Response::TYPE_HTML); $response->withBody(Utils::streamFor($target->saveHTML()));
System::echoResponse($response);
System::exit();
} }
} }

View file

@ -27,11 +27,13 @@ use Friendica\Capabilities\ICanCreateResponses;
use Friendica\Core\Hook; use Friendica\Core\Hook;
use Friendica\Core\L10n; use Friendica\Core\L10n;
use Friendica\Core\Logger; use Friendica\Core\Logger;
use Friendica\Core\System;
use Friendica\Model\User; use Friendica\Model\User;
use Friendica\Module\Response; use Friendica\Module\Response;
use Friendica\Module\Special\HTTPException as ModuleHTTPException; use Friendica\Module\Special\HTTPException as ModuleHTTPException;
use Friendica\Network\HTTPException; use Friendica\Network\HTTPException;
use Friendica\Util\Profiler; use Friendica\Util\Profiler;
use Friendica\Util\XML;
use Psr\Http\Message\ResponseInterface; use Psr\Http\Message\ResponseInterface;
use Psr\Log\LoggerInterface; use Psr\Log\LoggerInterface;
@ -106,8 +108,7 @@ abstract class BaseModule implements ICanHandleRequests
*/ */
protected function rawContent(array $request = []) protected function rawContent(array $request = [])
{ {
// echo ''; // $this->httpExit(...);
// exit;
} }
/** /**
@ -234,7 +235,8 @@ abstract class BaseModule implements ICanHandleRequests
$timestamp = microtime(true); $timestamp = microtime(true);
// "rawContent" is especially meant for technical endpoints. // "rawContent" is especially meant for technical endpoints.
// This endpoint doesn't need any theme initialization or other comparable stuff. // This endpoint doesn't need any theme initialization or
// templating and is expected to exit on its own if it is set.
$this->rawContent($request); $this->rawContent($request);
try { try {
@ -456,4 +458,76 @@ abstract class BaseModule implements ICanHandleRequests
return $tabs; return $tabs;
} }
/**
* This function adds the content and a content-type HTTP header to the output.
* After finishing the process is getting killed.
*
* @param string $content
* @param string $type
* @param string|null $content_type
* @return void
* @throws HTTPException\InternalServerErrorException
*/
public function httpExit(string $content, string $type = Response::TYPE_HTML, ?string $content_type = null)
{
$this->response->setType($type, $content_type);
$this->response->addContent($content);
System::echoResponse($this->response->generate());
System::exit();
}
/**
* Send HTTP status header and exit.
*
* @param integer $httpCode HTTP status result value
* @param string $message Error message. Optional.
* @param mixed $content Response body. Optional.
* @throws \Exception
*/
public function httpError(int $httpCode, string $message = '', $content = '')
{
if ($httpCode >= 400) {
$this->logger->debug('Exit with error', ['code' => $httpCode, 'message' => $message, 'callstack' => System::callstack(20), 'method' => $this->args->getMethod(), 'agent' => $this->server['HTTP_USER_AGENT'] ?? '']);
}
$this->response->setStatus($httpCode, $message);
$this->httpExit($content);
}
/**
* Display the response using JSON to encode the content
*
* @param mixed $content
* @param string $content_type
* @param int $options A combination of json_encode() binary flags
* @return void
* @throws HTTPException\InternalServerErrorException
* @see json_encode()
*/
public function jsonExit($content, string $content_type = 'application/json', int $options = JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT)
{
$this->httpExit(json_encode($content, $options), ICanCreateResponses::TYPE_JSON, $content_type);
}
/**
* Display a non-200 HTTP code response using JSON to encode the content and exit
*
* @param int $httpCode
* @param mixed $content
* @param string $content_type
* @return void
* @throws HTTPException\InternalServerErrorException
*/
public function jsonError(int $httpCode, $content, string $content_type = 'application/json')
{
if ($httpCode >= 400) {
$this->logger->debug('Exit with error', ['code' => $httpCode, 'content_type' => $content_type, 'callstack' => System::callstack(20), 'method' => $this->args->getMethod(), 'agent' => $this->server['HTTP_USER_AGENT'] ?? '']);
}
$this->response->setStatus($httpCode);
$this->jsonExit($content, $content_type);
}
} }

View file

@ -70,7 +70,7 @@ interface ICanCreateResponses
* *
* @throws InternalServerErrorException * @throws InternalServerErrorException
*/ */
public function setType(string $type, ?string $content_type = null): void; public function setType(string $type = ICanCreateResponses::TYPE_HTML, ?string $content_type = null): void;
/** /**
* Sets the status and the reason for the response * Sets the status and the reason for the response

View file

@ -28,10 +28,12 @@ use Friendica\DI;
use Friendica\Model\User; use Friendica\Model\User;
use Friendica\Module\Response; use Friendica\Module\Response;
use Friendica\Network\HTTPException\FoundException; use Friendica\Network\HTTPException\FoundException;
use Friendica\Network\HTTPException\InternalServerErrorException;
use Friendica\Network\HTTPException\MovedPermanentlyException; use Friendica\Network\HTTPException\MovedPermanentlyException;
use Friendica\Network\HTTPException\TemporaryRedirectException; use Friendica\Network\HTTPException\TemporaryRedirectException;
use Friendica\Util\BasePath; use Friendica\Util\BasePath;
use Friendica\Util\XML; use Friendica\Util\XML;
use Psr\Http\Message\ResponseInterface;
use Psr\Log\LoggerInterface; use Psr\Log\LoggerInterface;
/** /**
@ -274,32 +276,59 @@ class System
return implode(', ', $callstack2); return implode(', ', $callstack2);
} }
/**
* Display current response, including setting all headers
*
* @param ResponseInterface $response
*/
public static function echoResponse(ResponseInterface $response)
{
header(sprintf("HTTP/%s %s %s",
$response->getProtocolVersion(),
$response->getStatusCode(),
$response->getReasonPhrase())
);
foreach ($response->getHeaders() as $key => $header) {
if (is_array($header)) {
$header_str = implode(',', $header);
} else {
$header_str = $header;
}
if (is_int($key)) {
header($header_str);
} else {
header("$key: $header_str");
}
}
echo $response->getBody();
}
/** /**
* Generic XML return * Generic XML return
* Outputs a basic dfrn XML status structure to STDOUT, with a <status> variable * Outputs a basic dfrn XML status structure to STDOUT, with a <status> variable
* of $st and an optional text <message> of $message and terminates the current process. * of $st and an optional text <message> of $message and terminates the current process.
* *
* @param $st * @param mixed $status
* @param string $message * @param string $message
* @throws \Exception * @throws \Exception
* @deprecated since 2023.09 Use BaseModule->httpExit() instead
*/ */
public static function xmlExit($st, $message = '') public static function xmlExit($status, string $message = '')
{ {
$result = ['status' => $st]; $result = ['status' => $status];
if ($message != '') { if ($message != '') {
$result['message'] = $message; $result['message'] = $message;
} }
if ($st) { if ($status) {
Logger::notice('xml_status returning non_zero: ' . $st . " message=" . $message); Logger::notice('xml_status returning non_zero: ' . $status . " message=" . $message);
} }
DI::apiResponse()->setType(Response::TYPE_XML); self::httpExit(XML::fromArray(['result' => $result]), Response::TYPE_XML);
DI::apiResponse()->addContent(XML::fromArray(['result' => $result]));
DI::page()->exit(DI::apiResponse()->generate());
self::exit();
} }
/** /**
@ -309,6 +338,7 @@ class System
* @param string $message Error message. Optional. * @param string $message Error message. Optional.
* @param string $content Response body. Optional. * @param string $content Response body. Optional.
* @throws \Exception * @throws \Exception
* @deprecated since 2023.09 Use BaseModule->httpError instead
*/ */
public static function httpError($httpCode, $message = '', $content = '') public static function httpError($httpCode, $message = '', $content = '')
{ {
@ -316,29 +346,33 @@ class System
Logger::debug('Exit with error', ['code' => $httpCode, 'message' => $message, 'callstack' => System::callstack(20), 'method' => DI::args()->getMethod(), 'agent' => $_SERVER['HTTP_USER_AGENT'] ?? '']); Logger::debug('Exit with error', ['code' => $httpCode, 'message' => $message, 'callstack' => System::callstack(20), 'method' => DI::args()->getMethod(), 'agent' => $_SERVER['HTTP_USER_AGENT'] ?? '']);
} }
DI::apiResponse()->setStatus($httpCode, $message); DI::apiResponse()->setStatus($httpCode, $message);
DI::apiResponse()->addContent($content);
DI::page()->exit(DI::apiResponse()->generate());
self::exit(); self::httpExit($content);
} }
/** /**
* This function adds the content and a content-type HTTP header to the output. * This function adds the content and a content-type HTTP header to the output.
* After finishing the process is getting killed. * After finishing the process is getting killed.
* *
* @param string $content * @param string $content
* @param string $type * @param string $type
* @param string|null $content_type * @param string|null $content_type
* @return void * @return void
* @throws InternalServerErrorException
* @deprecated since 2023.09 Use BaseModule->httpExit() instead
*/ */
public static function httpExit(string $content, string $type = Response::TYPE_HTML, ?string $content_type = null) { public static function httpExit(string $content, string $type = Response::TYPE_HTML, ?string $content_type = null)
{
DI::apiResponse()->setType($type, $content_type); DI::apiResponse()->setType($type, $content_type);
DI::apiResponse()->addContent($content); DI::apiResponse()->addContent($content);
DI::page()->exit(DI::apiResponse()->generate()); self::echoResponse(DI::apiResponse()->generate());
self::exit(); self::exit();
} }
/**
* @deprecated since 2023.09 Use BaseModule->jsonError instead
*/
public static function jsonError($httpCode, $content, $content_type = 'application/json') public static function jsonError($httpCode, $content, $content_type = 'application/json')
{ {
if ($httpCode >= 400) { if ($httpCode >= 400) {
@ -358,14 +392,12 @@ class System
* @param mixed $content The input content * @param mixed $content 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 * @param integer $options JSON options
* @throws \Friendica\Network\HTTPException\InternalServerErrorException * @throws InternalServerErrorException
* @deprecated since 2023.09 Use BaseModule->jsonExit instead
*/ */
public static function jsonExit($content, $content_type = 'application/json', int $options = JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT) { public static function jsonExit($content, string $content_type = 'application/json', int $options = JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT)
DI::apiResponse()->setType(Response::TYPE_JSON, $content_type); {
DI::apiResponse()->addContent(json_encode($content, $options)); self::httpExit(json_encode($content, $options), Response::TYPE_JSON, $content_type);
DI::page()->exit(DI::apiResponse()->generate());
self::exit();
} }
/** /**

View file

@ -601,7 +601,7 @@ class Worker
$rest = round(max(0, $up_duration - (self::$db_duration + self::$lock_duration)), 2); $rest = round(max(0, $up_duration - (self::$db_duration + self::$lock_duration)), 2);
$exec = round($duration, 2); $exec = round($duration, 2);
Logger::info('Performance:', ['state' => self::$state, 'count' => $dbcount, 'stat' => $dbstat, 'write' => $dbwrite, 'lock' => $dblock, 'total' => $dbtotal, 'rest' => $rest, 'exec' => $exec]); Logger::info('Performance:', ['function' => $funcname, 'state' => self::$state, 'count' => $dbcount, 'stat' => $dbstat, 'write' => $dbwrite, 'lock' => $dblock, 'total' => $dbtotal, 'rest' => $rest, 'exec' => $exec]);
self::coolDown(); self::coolDown();
@ -622,7 +622,7 @@ class Worker
Logger::info('Longer than 2 minutes.', ['priority' => $queue['priority'], 'id' => $queue['id'], 'duration' => round($duration/60, 3)]); Logger::info('Longer than 2 minutes.', ['priority' => $queue['priority'], 'id' => $queue['id'], 'duration' => round($duration/60, 3)]);
} }
Logger::info('Process done.', ['priority' => $queue['priority'], 'id' => $queue['id'], 'duration' => round($duration, 3)]); Logger::info('Process done.', ['function' => $funcname, 'priority' => $queue['priority'], 'retrial' => $queue['retrial'], 'id' => $queue['id'], 'duration' => round($duration, 3)]);
DI::profiler()->saveLog(DI::logger(), 'ID ' . $queue['id'] . ': ' . $funcname); DI::profiler()->saveLog(DI::logger(), 'ID ' . $queue['id'] . ': ' . $funcname);
} }

View file

@ -57,7 +57,7 @@ class Error extends BaseFactory
$errorObj = new \Friendica\Object\Api\Mastodon\Error($error, $error_description); $errorObj = new \Friendica\Object\Api\Mastodon\Error($error, $error_description);
$this->logError(404, $error); $this->logError(404, $error);
System::jsonError(404, $errorObj->toArray()); $this->jsonError(404, $errorObj->toArray());
} }
public function UnprocessableEntity(string $error = '') public function UnprocessableEntity(string $error = '')
@ -67,7 +67,7 @@ class Error extends BaseFactory
$errorObj = new \Friendica\Object\Api\Mastodon\Error($error, $error_description); $errorObj = new \Friendica\Object\Api\Mastodon\Error($error, $error_description);
$this->logError(422, $error); $this->logError(422, $error);
System::jsonError(422, $errorObj->toArray()); $this->jsonError(422, $errorObj->toArray());
} }
public function Unauthorized(string $error = '', string $error_description = '') public function Unauthorized(string $error = '', string $error_description = '')
@ -76,7 +76,7 @@ class Error extends BaseFactory
$errorObj = new \Friendica\Object\Api\Mastodon\Error($error, $error_description); $errorObj = new \Friendica\Object\Api\Mastodon\Error($error, $error_description);
$this->logError(401, $error); $this->logError(401, $error);
System::jsonError(401, $errorObj->toArray()); $this->jsonError(401, $errorObj->toArray());
} }
public function Forbidden(string $error = '') public function Forbidden(string $error = '')
@ -86,7 +86,7 @@ class Error extends BaseFactory
$errorObj = new \Friendica\Object\Api\Mastodon\Error($error, $error_description); $errorObj = new \Friendica\Object\Api\Mastodon\Error($error, $error_description);
$this->logError(403, $error); $this->logError(403, $error);
System::jsonError(403, $errorObj->toArray()); $this->jsonError(403, $errorObj->toArray());
} }
public function InternalError(string $error = '') public function InternalError(string $error = '')
@ -96,6 +96,6 @@ class Error extends BaseFactory
$errorObj = new \Friendica\Object\Api\Mastodon\Error($error, $error_description); $errorObj = new \Friendica\Object\Api\Mastodon\Error($error, $error_description);
$this->logError(500, $error); $this->logError(500, $error);
System::jsonError(500, $errorObj->toArray()); $this->jsonError(500, $errorObj->toArray());
} }
} }

View file

@ -79,6 +79,6 @@ class AccountManagementControlDocument extends BaseModule
], ],
]; ];
System::jsonExit($output); $this->jsonExit($output);
} }
} }

View file

@ -46,6 +46,6 @@ class Featured extends BaseModule
$featured = ActivityPub\Transmitter::getFeatured($owner, $page); $featured = ActivityPub\Transmitter::getFeatured($owner, $page);
System::jsonExit($featured, 'application/activity+json'); $this->jsonExit($featured, 'application/activity+json');
} }
} }

View file

@ -49,6 +49,6 @@ class Followers extends BaseModule
$followers = ActivityPub\Transmitter::getContacts($owner, [Contact::FOLLOWER, Contact::FRIEND], 'followers', $page, (string)HTTPSignature::getSigner('', $_SERVER)); $followers = ActivityPub\Transmitter::getContacts($owner, [Contact::FOLLOWER, Contact::FRIEND], 'followers', $page, (string)HTTPSignature::getSigner('', $_SERVER));
System::jsonExit($followers, 'application/activity+json'); $this->jsonExit($followers, 'application/activity+json');
} }
} }

View file

@ -47,6 +47,6 @@ class Following extends BaseModule
$following = ActivityPub\Transmitter::getContacts($owner, [Contact::SHARING, Contact::FRIEND], 'following', $page); $following = ActivityPub\Transmitter::getContacts($owner, [Contact::SHARING, Contact::FRIEND], 'following', $page);
System::jsonExit($following, 'application/activity+json'); $this->jsonExit($following, 'application/activity+json');
} }
} }

View file

@ -66,7 +66,7 @@ class Inbox extends BaseApi
$inbox = ActivityPub\ClientToServer::getPublicInbox($uid, $page, $request['max_id'] ?? null); $inbox = ActivityPub\ClientToServer::getPublicInbox($uid, $page, $request['max_id'] ?? null);
} }
System::jsonExit($inbox, 'application/activity+json'); $this->jsonExit($inbox, 'application/activity+json');
} }
protected function post(array $request = []) protected function post(array $request = [])

View file

@ -130,6 +130,6 @@ class Objects extends BaseModule
// Relaxed CORS header for public items // Relaxed CORS header for public items
header('Access-Control-Allow-Origin: *'); header('Access-Control-Allow-Origin: *');
System::jsonExit($data, 'application/activity+json'); $this->jsonExit($data, 'application/activity+json');
} }
} }

View file

@ -53,7 +53,7 @@ class Outbox extends BaseApi
$outbox = ActivityPub\ClientToServer::getOutbox($owner, $uid, $page, $request['max_id'] ?? null, HTTPSignature::getSigner('', $_SERVER)); $outbox = ActivityPub\ClientToServer::getOutbox($owner, $uid, $page, $request['max_id'] ?? null, HTTPSignature::getSigner('', $_SERVER));
System::jsonExit($outbox, 'application/activity+json'); $this->jsonExit($outbox, 'application/activity+json');
} }
protected function post(array $request = []) protected function post(array $request = [])
@ -79,6 +79,6 @@ class Outbox extends BaseApi
throw new \Friendica\Network\HTTPException\BadRequestException(); throw new \Friendica\Network\HTTPException\BadRequestException();
} }
System::jsonExit(ActivityPub\ClientToServer::processActivity($activity, $uid, self::getCurrentApplication() ?? [])); $this->jsonExit(ActivityPub\ClientToServer::processActivity($activity, $uid, self::getCurrentApplication() ?? []));
} }
} }

View file

@ -100,6 +100,6 @@ class Whoami extends BaseApi
]; ];
$data['generator'] = ActivityPub\Transmitter::getService(); $data['generator'] = ActivityPub\Transmitter::getService();
System::jsonExit($data, 'application/activity+json'); $this->jsonExit($data, 'application/activity+json');
} }
} }

View file

@ -25,6 +25,7 @@ use Friendica\App\Arguments;
use Friendica\App\BaseURL; use Friendica\App\BaseURL;
use Friendica\Core\L10n; use Friendica\Core\L10n;
use Friendica\Module\Response; use Friendica\Module\Response;
use Friendica\Network\HTTPException;
use Friendica\Util\Arrays; use Friendica\Util\Arrays;
use Friendica\Util\DateTimeFormat; use Friendica\Util\DateTimeFormat;
use Friendica\Util\XML; use Friendica\Util\XML;
@ -46,14 +47,20 @@ class ApiResponse extends Response
protected $baseUrl; protected $baseUrl;
/** @var TwitterUser */ /** @var TwitterUser */
protected $twitterUser; protected $twitterUser;
/** @var array */
protected $server;
/** @var string */
protected $jsonpCallback;
public function __construct(L10n $l10n, Arguments $args, LoggerInterface $logger, BaseURL $baseUrl, TwitterUser $twitterUser) public function __construct(L10n $l10n, Arguments $args, LoggerInterface $logger, BaseURL $baseUrl, TwitterUser $twitterUser, array $server = [], string $jsonpCallback = '')
{ {
$this->l10n = $l10n; $this->l10n = $l10n;
$this->args = $args; $this->args = $args;
$this->logger = $logger; $this->logger = $logger;
$this->baseUrl = $baseUrl; $this->baseUrl = $baseUrl;
$this->twitterUser = $twitterUser; $this->twitterUser = $twitterUser;
$this->server = $server;
$this->jsonpCallback = $jsonpCallback;
} }
/** /**
@ -63,6 +70,7 @@ class ApiResponse extends Response
* @param string $root_element Name of the root element * @param string $root_element Name of the root element
* *
* @return string The XML data * @return string The XML data
* @throws \Exception
*/ */
public function createXML(array $data, string $root_element): string public function createXML(array $data, string $root_element): string
{ {
@ -109,6 +117,7 @@ class ApiResponse extends Response
* @param int $cid Contact ID of template * @param int $cid Contact ID of template
* *
* @return array * @return array
* @throws HTTPException\InternalServerErrorException
*/ */
private function addRSSValues(array $arr, int $cid): array private function addRSSValues(array $arr, int $cid): array
{ {
@ -141,6 +150,7 @@ class ApiResponse extends Response
* @param int $cid ID of the contact for RSS * @param int $cid ID of the contact for RSS
* *
* @return array|string (string|array) XML data or JSON data * @return array|string (string|array) XML data or JSON data
* @throws HTTPException\InternalServerErrorException
*/ */
public function formatData(string $root_element, string $type, array $data, int $cid = 0) public function formatData(string $root_element, string $type, array $data, int $cid = 0)
{ {
@ -180,7 +190,7 @@ class ApiResponse extends Response
} }
/** /**
* Exit with error code * Add formatted error message to response
* *
* @param int $code * @param int $code
* @param string $description * @param string $description
@ -188,6 +198,7 @@ class ApiResponse extends Response
* @param string|null $format * @param string|null $format
* *
* @return void * @return void
* @throws HTTPException\InternalServerErrorException
*/ */
public function error(int $code, string $description, string $message, string $format = null) public function error(int $code, string $description, string $message, string $format = null)
{ {
@ -197,21 +208,23 @@ class ApiResponse extends Response
'request' => $this->args->getQueryString() 'request' => $this->args->getQueryString()
]; ];
$this->setHeader(($_SERVER['SERVER_PROTOCOL'] ?? 'HTTP/1.1') . ' ' . $code . ' ' . $description); $this->setHeader(($this->server['SERVER_PROTOCOL'] ?? 'HTTP/1.1') . ' ' . $code . ' ' . $description);
$this->exit('status', ['status' => $error], $format); $this->addFormattedContent('status', ['status' => $error], $format);
} }
/** /**
* Outputs formatted data according to the data type and then exits the execution. * Add formatted data according to the data type to the response.
* *
* @param string $root_element * @param string $root_element
* @param array $data An array with a single element containing the returned result * @param array $data An array with a single element containing the returned result
* @param string|null $format Output format (xml, json, rss, atom) * @param string|null $format Output format (xml, json, rss, atom)
* @param int $cid
* *
* @return void * @return void
* @throws HTTPException\InternalServerErrorException
*/ */
public function exit(string $root_element, array $data, string $format = null, int $cid = 0) public function addFormattedContent(string $root_element, array $data, string $format = null, int $cid = 0)
{ {
$format = $format ?? 'json'; $format = $format ?? 'json';
@ -226,8 +239,8 @@ class ApiResponse extends Response
$this->setType(static::TYPE_JSON); $this->setType(static::TYPE_JSON);
if (!empty($return)) { if (!empty($return)) {
$json = json_encode(end($return)); $json = json_encode(end($return));
if (!empty($_GET['callback'])) { if ($this->jsonpCallback) {
$json = $_GET['callback'] . '(' . $json . ')'; $json = $this->jsonpCallback . '(' . $json . ')';
} }
$return = $json; $return = $json;
} }
@ -246,15 +259,16 @@ class ApiResponse extends Response
} }
/** /**
* Wrapper around exit() for JSON only responses * Wrapper around addFormattedContent() for JSON only responses
* *
* @param array $data * @param array $data
* *
* @return void * @return void
* @throws HTTPException\InternalServerErrorException
*/ */
public function exitWithJson(array $data) public function addJsonContent(array $data)
{ {
$this->exit('content', ['content' => $data], static::TYPE_JSON); $this->addFormattedContent('content', ['content' => $data], static::TYPE_JSON);
} }
/** /**
@ -273,7 +287,7 @@ class ApiResponse extends Response
[ [
'method' => $method, 'method' => $method,
'path' => $path, 'path' => $path,
'agent' => $_SERVER['HTTP_USER_AGENT'] ?? '', 'agent' => $this->server['HTTP_USER_AGENT'] ?? '',
'request' => $request, 'request' => $request,
]); ]);
$error = $this->l10n->t('API endpoint %s %s is not implemented but might be in the future.', strtoupper($method), $path); $error = $this->l10n->t('API endpoint %s %s is not implemented but might be in the future.', strtoupper($method), $path);

View file

@ -60,7 +60,7 @@ class Activity extends BaseApi
if ($res) { if ($res) {
$status_info = DI::twitterStatus()->createFromUriId($request['id'], $uid)->toArray(); $status_info = DI::twitterStatus()->createFromUriId($request['id'], $uid)->toArray();
$this->response->exit('status', ['status' => $status_info], $this->parameters['extension'] ?? null); $this->response->addFormattedContent('status', ['status' => $status_info], $this->parameters['extension'] ?? null);
} else { } else {
$this->response->error(500, 'Error adding activity', '', $this->parameters['extension'] ?? null); $this->response->error(500, 'Error adding activity', '', $this->parameters['extension'] ?? null);
} }

View file

@ -82,6 +82,6 @@ class Create extends BaseApi
$result = ['success' => true, 'gid' => $gid, 'name' => $name, 'status' => $status, 'wrong users' => $errorusers]; $result = ['success' => true, 'gid' => $gid, 'name' => $name, 'status' => $status, 'wrong users' => $errorusers];
$this->response->exit('group_create', ['$result' => $result], $this->parameters['extension'] ?? null); $this->response->addFormattedContent('group_create', ['$result' => $result], $this->parameters['extension'] ?? null);
} }
} }

View file

@ -70,7 +70,7 @@ class Delete extends BaseApi
if ($ret) { if ($ret) {
// return success // return success
$success = ['success' => $ret, 'gid' => $request['gid'], 'name' => $request['name'], 'status' => 'deleted', 'wrong users' => []]; $success = ['success' => $ret, 'gid' => $request['gid'], 'name' => $request['name'], 'status' => 'deleted', 'wrong users' => []];
$this->response->exit('group_delete', ['$result' => $success], $this->parameters['extension'] ?? null); $this->response->addFormattedContent('group_delete', ['$result' => $success], $this->parameters['extension'] ?? null);
} else { } else {
throw new BadRequestException('other API error'); throw new BadRequestException('other API error');
} }

View file

@ -75,6 +75,6 @@ class Show extends BaseApi
$grps[] = ['name' => $circle['name'], 'gid' => $circle['id'], $user_element => $users]; $grps[] = ['name' => $circle['name'], 'gid' => $circle['id'], $user_element => $users];
} }
$this->response->exit('group_update', ['group' => $grps], $this->parameters['extension'] ?? null); $this->response->addFormattedContent('group_update', ['group' => $grps], $this->parameters['extension'] ?? null);
} }
} }

View file

@ -84,6 +84,6 @@ class Update extends BaseApi
// return success message incl. missing users in array // return success message incl. missing users in array
$status = ($erroraddinguser ? 'missing user' : 'ok'); $status = ($erroraddinguser ? 'missing user' : 'ok');
$success = ['success' => true, 'gid' => $gid, 'name' => $name, 'status' => $status, 'wrong users' => $errorusers]; $success = ['success' => true, 'gid' => $gid, 'name' => $name, 'status' => $status, 'wrong users' => $errorusers];
$this->response->exit('group_update', ['$result' => $success], $this->parameters['extension'] ?? null); $this->response->addFormattedContent('group_update', ['$result' => $success], $this->parameters['extension'] ?? null);
} }
} }

View file

@ -64,7 +64,7 @@ class Search extends BaseApi
// error if no searchstring specified // error if no searchstring specified
if ($request['searchstring'] == '') { if ($request['searchstring'] == '') {
$answer = ['result' => 'error', 'message' => 'searchstring not specified']; $answer = ['result' => 'error', 'message' => 'searchstring not specified'];
$this->response->exit('direct_message_search', ['$result' => $answer], $this->parameters['extension'] ?? null); $this->response->addFormattedContent('direct_message_search', ['$result' => $answer], $this->parameters['extension'] ?? null);
return; return;
} }
@ -82,6 +82,6 @@ class Search extends BaseApi
$success = ['success' => true, 'search_results' => $ret]; $success = ['success' => true, 'search_results' => $ret];
} }
$this->response->exit('direct_message_search', ['$result' => $success], $this->parameters['extension'] ?? null); $this->response->addFormattedContent('direct_message_search', ['$result' => $success], $this->parameters['extension'] ?? null);
} }
} }

View file

@ -42,14 +42,14 @@ class Setseen extends BaseApi
// return error if id is zero // return error if id is zero
if (empty($request['id'])) { if (empty($request['id'])) {
$answer = ['result' => 'error', 'message' => 'message id not specified']; $answer = ['result' => 'error', 'message' => 'message id not specified'];
$this->response->exit('direct_messages_setseen', ['$result' => $answer], $this->parameters['extension'] ?? null); $this->response->addFormattedContent('direct_messages_setseen', ['$result' => $answer], $this->parameters['extension'] ?? null);
return; return;
} }
// error message if specified id is not in database // error message if specified id is not in database
if (!DBA::exists('mail', ['id' => $request['id'], 'uid' => $uid])) { if (!DBA::exists('mail', ['id' => $request['id'], 'uid' => $uid])) {
$answer = ['result' => 'error', 'message' => 'message id not in database']; $answer = ['result' => 'error', 'message' => 'message id not in database'];
$this->response->exit('direct_messages_setseen', ['$result' => $answer], $this->parameters['extension'] ?? null); $this->response->addFormattedContent('direct_messages_setseen', ['$result' => $answer], $this->parameters['extension'] ?? null);
return; return;
} }
@ -60,6 +60,6 @@ class Setseen extends BaseApi
$answer = ['result' => 'error', 'message' => 'unknown error']; $answer = ['result' => 'error', 'message' => 'unknown error'];
} }
$this->response->exit('direct_messages_setseen', ['$result' => $answer], $this->parameters['extension'] ?? null); $this->response->addFormattedContent('direct_messages_setseen', ['$result' => $answer], $this->parameters['extension'] ?? null);
} }
} }

View file

@ -110,6 +110,6 @@ class Create extends BaseApi
$result = ['success' => true, 'event_id' => $event_id, 'event' => $event]; $result = ['success' => true, 'event_id' => $event_id, 'event' => $event];
$this->response->exit('event_create', ['$result' => $result], $this->parameters['extension'] ?? null); $this->response->addFormattedContent('event_create', ['$result' => $result], $this->parameters['extension'] ?? null);
} }
} }

View file

@ -59,6 +59,6 @@ class Delete extends BaseApi
Event::delete($eventid); Event::delete($eventid);
$success = ['id' => $eventid, 'status' => 'deleted']; $success = ['id' => $eventid, 'status' => 'deleted'];
$this->response->exit('event_delete', ['$result' => $success], $this->parameters['extension'] ?? null); $this->response->addFormattedContent('event_delete', ['$result' => $success], $this->parameters['extension'] ?? null);
} }
} }

View file

@ -69,6 +69,6 @@ class Index extends BaseApi
]; ];
} }
$this->response->exit('events', ['events' => $items], $this->parameters['extension'] ?? null); $this->response->addFormattedContent('events', ['events' => $items], $this->parameters['extension'] ?? null);
} }
} }

View file

@ -56,6 +56,6 @@ class Notification extends BaseApi
$result = false; $result = false;
} }
$this->response->exit('notes', ['note' => $result], $this->parameters['extension'] ?? null); $this->response->addFormattedContent('notes', ['note' => $result], $this->parameters['extension'] ?? null);
} }
} }

View file

@ -70,13 +70,13 @@ class Seen extends BaseApi
// we found the item, return it to the user // we found the item, return it to the user
$ret = [DI::twitterStatus()->createFromUriId($item['uri-id'], $item['uid'], $include_entities)->toArray()]; $ret = [DI::twitterStatus()->createFromUriId($item['uri-id'], $item['uid'], $include_entities)->toArray()];
$data = ['status' => $ret]; $data = ['status' => $ret];
$this->response->exit('statuses', $data, $this->parameters['extension'] ?? null); $this->response->addFormattedContent('statuses', $data, $this->parameters['extension'] ?? null);
return; return;
} }
// the item can't be found, but we set the notification as seen, so we count this as a success // the item can't be found, but we set the notification as seen, so we count this as a success
} }
$this->response->exit('statuses', ['result' => 'success'], $this->parameters['extension'] ?? null); $this->response->addFormattedContent('statuses', ['result' => 'success'], $this->parameters['extension'] ?? null);
} catch (NotFoundException $e) { } catch (NotFoundException $e) {
throw new BadRequestException('Invalid argument', $e); throw new BadRequestException('Invalid argument', $e);
} catch (Exception $e) { } catch (Exception $e) {

View file

@ -60,6 +60,6 @@ class Photo extends BaseApi
// prepare json/xml output with data from database for the requested photo // prepare json/xml output with data from database for the requested photo
$data = ['photo' => $this->friendicaPhoto->createFromId($photo_id, $scale, $uid, $type)]; $data = ['photo' => $this->friendicaPhoto->createFromId($photo_id, $scale, $uid, $type)];
$this->response->exit('statuses', $data, $this->parameters['extension'] ?? null, Contact::getPublicIdByUserId($uid)); $this->response->addFormattedContent('statuses', $data, $this->parameters['extension'] ?? null, Contact::getPublicIdByUserId($uid));
} }
} }

View file

@ -90,7 +90,7 @@ class Create extends BaseApi
if (!empty($photo)) { if (!empty($photo)) {
Photo::clearAlbumCache($uid); Photo::clearAlbumCache($uid);
$data = ['photo' => $this->friendicaPhoto->createFromId($photo['resource_id'], null, $uid, $type)]; $data = ['photo' => $this->friendicaPhoto->createFromId($photo['resource_id'], null, $uid, $type)];
$this->response->exit('photo_create', $data, $this->parameters['extension'] ?? null); $this->response->addFormattedContent('photo_create', $data, $this->parameters['extension'] ?? null);
} else { } else {
throw new HTTPException\InternalServerErrorException('unknown error - uploading photo failed, see Friendica log for more information'); throw new HTTPException\InternalServerErrorException('unknown error - uploading photo failed, see Friendica log for more information');
} }

View file

@ -62,7 +62,7 @@ class Delete extends BaseApi
Item::deleteForUser($condition, $uid); Item::deleteForUser($condition, $uid);
Photo::clearAlbumCache($uid); Photo::clearAlbumCache($uid);
$result = ['result' => 'deleted', 'message' => 'photo with id `' . $request['photo_id'] . '` has been deleted from server.']; $result = ['result' => 'deleted', 'message' => 'photo with id `' . $request['photo_id'] . '` has been deleted from server.'];
$this->response->exit('photo_delete', ['$result' => $result], $this->parameters['extension'] ?? null); $this->response->addFormattedContent('photo_delete', ['$result' => $result], $this->parameters['extension'] ?? null);
} else { } else {
throw new InternalServerErrorException("unknown error on deleting photo from database table"); throw new InternalServerErrorException("unknown error on deleting photo from database table");
} }

View file

@ -77,6 +77,6 @@ class Lists extends BaseApi
} }
} }
$this->response->exit('statuses', $data, $this->parameters['extension'] ?? null, Contact::getPublicIdByUserId($uid)); $this->response->addFormattedContent('statuses', $data, $this->parameters['extension'] ?? null, Contact::getPublicIdByUserId($uid));
} }
} }

View file

@ -128,7 +128,7 @@ class Update extends BaseApi
$photo = Photo::upload($uid, $_FILES['media'], $album, $allow_cid, $allow_gid, $deny_cid, $deny_gid, $desc, $photo_id); $photo = Photo::upload($uid, $_FILES['media'], $album, $allow_cid, $allow_gid, $deny_cid, $deny_gid, $desc, $photo_id);
if (!empty($photo)) { if (!empty($photo)) {
$data = ['photo' => $this->friendicaPhoto->createFromId($photo['resource_id'], null, $uid, $type)]; $data = ['photo' => $this->friendicaPhoto->createFromId($photo['resource_id'], null, $uid, $type)];
$this->response->exit('photo_update', $data, $this->parameters['extension'] ?? null); $this->response->addFormattedContent('photo_update', $data, $this->parameters['extension'] ?? null);
return; return;
} }
} }
@ -137,12 +137,12 @@ class Update extends BaseApi
if ($result) { if ($result) {
Photo::clearAlbumCache($uid); Photo::clearAlbumCache($uid);
$answer = ['result' => 'updated', 'message' => 'Image id `' . $photo_id . '` has been updated.']; $answer = ['result' => 'updated', 'message' => 'Image id `' . $photo_id . '` has been updated.'];
$this->response->exit('photo_update', ['$result' => $answer], $this->parameters['extension'] ?? null); $this->response->addFormattedContent('photo_update', ['$result' => $answer], $this->parameters['extension'] ?? null);
return; return;
} else { } else {
if ($nothingtodo) { if ($nothingtodo) {
$answer = ['result' => 'cancelled', 'message' => 'Nothing to update for image id `' . $photo_id . '`.']; $answer = ['result' => 'cancelled', 'message' => 'Nothing to update for image id `' . $photo_id . '`.'];
$this->response->exit('photo_update', ['$result' => $answer], $this->parameters['extension'] ?? null); $this->response->addFormattedContent('photo_update', ['$result' => $answer], $this->parameters['extension'] ?? null);
return; return;
} }
throw new HTTPException\InternalServerErrorException('unknown error - update photo entry in database failed'); throw new HTTPException\InternalServerErrorException('unknown error - update photo entry in database failed');

View file

@ -68,7 +68,7 @@ class Delete extends BaseApi
if ($result) { if ($result) {
Photo::clearAlbumCache($uid); Photo::clearAlbumCache($uid);
$answer = ['result' => 'deleted', 'message' => 'album `' . $request['album'] . '` with all containing photos has been deleted.']; $answer = ['result' => 'deleted', 'message' => 'album `' . $request['album'] . '` with all containing photos has been deleted.'];
$this->response->exit('photoalbum_delete', ['$result' => $answer], $this->parameters['extension'] ?? null); $this->response->addFormattedContent('photoalbum_delete', ['$result' => $answer], $this->parameters['extension'] ?? null);
} else { } else {
throw new InternalServerErrorException("unknown error - deleting from database failed"); throw new InternalServerErrorException("unknown error - deleting from database failed");
} }

View file

@ -47,6 +47,6 @@ class Index extends BaseApi
]; ];
} }
$this->response->exit('albums', ['albums' => $items], $this->parameters['extension'] ?? null); $this->response->addFormattedContent('albums', ['albums' => $items], $this->parameters['extension'] ?? null);
} }
} }

View file

@ -104,6 +104,6 @@ class Show extends BaseApi
} }
} }
$this->response->exit('statuses', $data, $this->parameters['extension'] ?? null, Contact::getPublicIdByUserId($uid)); $this->response->addFormattedContent('statuses', $data, $this->parameters['extension'] ?? null, Contact::getPublicIdByUserId($uid));
} }
} }

View file

@ -60,7 +60,7 @@ class Update extends BaseApi
if ($result) { if ($result) {
Photo::clearAlbumCache($uid); Photo::clearAlbumCache($uid);
$answer = ['result' => 'updated', 'message' => 'album `' . $request['album'] . '` with all containing photos has been renamed to `' . $request['album_new'] . '`.']; $answer = ['result' => 'updated', 'message' => 'album `' . $request['album'] . '` with all containing photos has been renamed to `' . $request['album_new'] . '`.'];
$this->response->exit('photoalbum_update', ['$result' => $answer], $this->parameters['extension'] ?? null); $this->response->addFormattedContent('photoalbum_update', ['$result' => $answer], $this->parameters['extension'] ?? null);
} else { } else {
throw new InternalServerErrorException("unknown error - updating in database failed"); throw new InternalServerErrorException("unknown error - updating in database failed");
} }

View file

@ -62,7 +62,7 @@ class Show extends BaseApi
'profiles' => $profiles 'profiles' => $profiles
]; ];
$this->response->exit('friendica_profiles', ['$result' => $result], $this->parameters['extension'] ?? null); $this->response->addFormattedContent('friendica_profiles', ['$result' => $result], $this->parameters['extension'] ?? null);
} }
/** /**

View file

@ -49,6 +49,6 @@ class Dislike extends BaseApi
Item::performActivity($item['id'], 'dislike', $uid); Item::performActivity($item['id'], 'dislike', $uid);
System::jsonExit(DI::mstdnStatus()->createFromUriId($this->parameters['id'], $uid, self::appSupportsQuotes())->toArray()); $this->jsonExit(DI::mstdnStatus()->createFromUriId($this->parameters['id'], $uid, self::appSupportsQuotes())->toArray());
} }
} }

View file

@ -57,6 +57,6 @@ class DislikedBy extends BaseApi
$accounts[] = DI::mstdnAccount()->createFromContactId($activity['author-id'], $uid); $accounts[] = DI::mstdnAccount()->createFromContactId($activity['author-id'], $uid);
} }
System::jsonExit($accounts); $this->jsonExit($accounts);
} }
} }

View file

@ -49,6 +49,6 @@ class Undislike extends BaseApi
Item::performActivity($item['id'], 'undislike', $uid); Item::performActivity($item['id'], 'undislike', $uid);
System::jsonExit(DI::mstdnStatus()->createFromUriId($this->parameters['id'], $uid, self::appSupportsQuotes())->toArray()); $this->jsonExit(DI::mstdnStatus()->createFromUriId($this->parameters['id'], $uid, self::appSupportsQuotes())->toArray());
} }
} }

View file

@ -61,6 +61,6 @@ class Config extends BaseApi
], ],
]; ];
$this->response->exit('config', ['config' => $config], $this->parameters['extension'] ?? null); $this->response->addFormattedContent('config', ['config' => $config], $this->parameters['extension'] ?? null);
} }
} }

View file

@ -31,6 +31,6 @@ class Version extends BaseApi
{ {
protected function rawContent(array $request = []) protected function rawContent(array $request = [])
{ {
$this->response->exit('version', ['version' => '0.9.7'], $this->parameters['extension'] ?? null); $this->response->addFormattedContent('version', ['version' => '0.9.7'], $this->parameters['extension'] ?? null);
} }
} }

View file

@ -37,6 +37,6 @@ class Test extends BaseApi
$ok = 'ok'; $ok = 'ok';
} }
$this->response->exit('ok', ['ok' => $ok], $this->parameters['extension'] ?? null); $this->response->addFormattedContent('ok', ['ok' => $ok], $this->parameters['extension'] ?? null);
} }
} }

View file

@ -90,6 +90,6 @@ class Conversation extends BaseApi
} }
DBA::close($statuses); DBA::close($statuses);
$this->response->exit('statuses', ['status' => $ret], $this->parameters['extension'] ?? null, Contact::getPublicIdByUserId($uid)); $this->response->addFormattedContent('statuses', ['status' => $ret], $this->parameters['extension'] ?? null, Contact::getPublicIdByUserId($uid));
} }
} }

View file

@ -58,6 +58,6 @@ class Accounts extends BaseApi
} }
$account = DI::mstdnAccount()->createFromContactId($id, $uid); $account = DI::mstdnAccount()->createFromContactId($id, $uid);
System::jsonExit($account); $this->jsonExit($account);
} }
} }

View file

@ -52,6 +52,6 @@ class Block extends BaseApi
} }
} }
System::jsonExit(DI::mstdnRelationship()->createFromContactId($this->parameters['id'], $uid)->toArray()); $this->jsonExit(DI::mstdnRelationship()->createFromContactId($this->parameters['id'], $uid)->toArray());
} }
} }

View file

@ -36,6 +36,6 @@ class FeaturedTags extends BaseApi
{ {
self::checkAllowedScope(self::SCOPE_READ); self::checkAllowedScope(self::SCOPE_READ);
System::jsonExit([]); $this->jsonExit([]);
} }
} }

View file

@ -54,6 +54,6 @@ class Follow extends BaseApi
Contact::update(['notify_new_posts' => $request['notify']], ['id' => $result['cid']]); Contact::update(['notify_new_posts' => $request['notify']], ['id' => $result['cid']]);
System::jsonExit(DI::mstdnRelationship()->createFromContactId($result['cid'], $uid)->toArray()); $this->jsonExit(DI::mstdnRelationship()->createFromContactId($result['cid'], $uid)->toArray());
} }
} }

View file

@ -115,6 +115,6 @@ class Followers extends BaseApi
} }
self::setLinkHeader(); self::setLinkHeader();
System::jsonExit($accounts); $this->jsonExit($accounts);
} }
} }

View file

@ -115,6 +115,6 @@ class Following extends BaseApi
} }
self::setLinkHeader(); self::setLinkHeader();
System::jsonExit($accounts); $this->jsonExit($accounts);
} }
} }

View file

@ -36,6 +36,6 @@ class IdentityProofs extends BaseApi
{ {
self::checkAllowedScope(self::SCOPE_READ); self::checkAllowedScope(self::SCOPE_READ);
System::jsonExit([]); $this->jsonExit([]);
} }
} }

View file

@ -60,6 +60,6 @@ class Lists extends BaseApi
DBA::close($circles); DBA::close($circles);
} }
System::jsonExit($lists); $this->jsonExit($lists);
} }
} }

View file

@ -42,6 +42,6 @@ class Mute extends BaseApi
Contact\User::setIgnored($this->parameters['id'], $uid, true); Contact\User::setIgnored($this->parameters['id'], $uid, true);
System::jsonExit(DI::mstdnRelationship()->createFromContactId($this->parameters['id'], $uid)->toArray()); $this->jsonExit(DI::mstdnRelationship()->createFromContactId($this->parameters['id'], $uid)->toArray());
} }
} }

View file

@ -52,6 +52,6 @@ class Note extends BaseApi
Contact::update(['info' => $request['comment']], ['id' => $cdata['user']]); Contact::update(['info' => $request['comment']], ['id' => $cdata['user']]);
System::jsonExit(DI::mstdnRelationship()->createFromContactId($this->parameters['id'], $uid)->toArray()); $this->jsonExit(DI::mstdnRelationship()->createFromContactId($this->parameters['id'], $uid)->toArray());
} }
} }

View file

@ -57,6 +57,6 @@ class Relationships extends BaseApi
$relationships[] = DI::mstdnRelationship()->createFromContactId($id, $uid); $relationships[] = DI::mstdnRelationship()->createFromContactId($id, $uid);
} }
System::jsonExit($relationships); $this->jsonExit($relationships);
} }
} }

View file

@ -67,6 +67,6 @@ class Search extends BaseApi
DBA::close($contacts); DBA::close($contacts);
} }
System::jsonExit($accounts); $this->jsonExit($accounts);
} }
} }

View file

@ -122,6 +122,6 @@ class Statuses extends BaseApi
} }
self::setLinkHeader($request['friendica_order'] != TimelineOrderByTypes::ID); self::setLinkHeader($request['friendica_order'] != TimelineOrderByTypes::ID);
System::jsonExit($statuses); $this->jsonExit($statuses);
} }
} }

View file

@ -42,6 +42,6 @@ class Unblock extends BaseApi
Contact\User::setBlocked($this->parameters['id'], $uid, false); Contact\User::setBlocked($this->parameters['id'], $uid, false);
System::jsonExit(DI::mstdnRelationship()->createFromContactId($this->parameters['id'], $uid)->toArray()); $this->jsonExit(DI::mstdnRelationship()->createFromContactId($this->parameters['id'], $uid)->toArray());
} }
} }

View file

@ -49,6 +49,6 @@ class Unfollow extends BaseApi
Contact::unfollow($contact); Contact::unfollow($contact);
System::jsonExit(DI::mstdnRelationship()->createFromContactId($this->parameters['id'], $uid)->toArray()); $this->jsonExit(DI::mstdnRelationship()->createFromContactId($this->parameters['id'], $uid)->toArray());
} }
} }

View file

@ -42,6 +42,6 @@ class Unmute extends BaseApi
Contact\User::setIgnored($this->parameters['id'], $uid, false); Contact\User::setIgnored($this->parameters['id'], $uid, false);
System::jsonExit(DI::mstdnRelationship()->createFromContactId($this->parameters['id'], $uid)->toArray()); $this->jsonExit(DI::mstdnRelationship()->createFromContactId($this->parameters['id'], $uid)->toArray());
} }
} }

View file

@ -105,6 +105,6 @@ class UpdateCredentials extends BaseApi
} }
$account = DI::mstdnAccount()->createFromContactId($cdata['user'], $uid); $account = DI::mstdnAccount()->createFromContactId($cdata['user'], $uid);
$this->response->exitWithJson($account->toArray()); $this->response->addJsonContent($account->toArray());
} }
} }

View file

@ -52,6 +52,6 @@ class VerifyCredentials extends BaseApi
// @todo Support the source property, // @todo Support the source property,
$account = DI::mstdnAccount()->createFromContactId($cdata['user'], $uid); $account = DI::mstdnAccount()->createFromContactId($cdata['user'], $uid);
$this->response->exitWithJson($account->toArray()); $this->response->addJsonContent($account->toArray());
} }
} }

View file

@ -37,6 +37,6 @@ class Announcements extends BaseApi
self::checkAllowedScope(self::SCOPE_READ); self::checkAllowedScope(self::SCOPE_READ);
// @todo Possibly use the message from the pageheader addon for this // @todo Possibly use the message from the pageheader addon for this
System::jsonExit([]); $this->jsonExit([]);
} }
} }

View file

@ -66,7 +66,7 @@ class Apps extends BaseApi
if (!empty($request['redirect_uris']) && is_array($request['redirect_uris'])) { if (!empty($request['redirect_uris']) && is_array($request['redirect_uris'])) {
$request['redirect_uris'] = $request['redirect_uris'][0]; $request['redirect_uris'] = $request['redirect_uris'][0];
} }
} }
if (empty($request['client_name']) || empty($request['redirect_uris'])) { if (empty($request['client_name']) || empty($request['redirect_uris'])) {
@ -95,6 +95,6 @@ class Apps extends BaseApi
DI::mstdnError()->InternalError(); DI::mstdnError()->InternalError();
} }
System::jsonExit(DI::mstdnApplication()->createFromApplicationId(DBA::lastInsertId())->toArray()); $this->jsonExit(DI::mstdnApplication()->createFromApplicationId(DBA::lastInsertId())->toArray());
} }
} }

View file

@ -39,6 +39,6 @@ class VerifyCredentials extends BaseApi
DI::mstdnError()->Unauthorized(); DI::mstdnError()->Unauthorized();
} }
System::jsonExit(DI::mstdnApplication()->createFromApplicationId($application['id'])); $this->jsonExit(DI::mstdnApplication()->createFromApplicationId($application['id']));
} }
} }

View file

@ -77,6 +77,6 @@ class Blocks extends BaseApi
} }
self::setLinkHeader(); self::setLinkHeader();
System::jsonExit($accounts); $this->jsonExit($accounts);
} }
} }

View file

@ -88,6 +88,6 @@ class Bookmarks extends BaseApi
} }
self::setLinkHeader(); self::setLinkHeader();
System::jsonExit($statuses); $this->jsonExit($statuses);
} }
} }

View file

@ -43,7 +43,7 @@ class Conversations extends BaseApi
DBA::delete('conv', ['id' => $this->parameters['id'], 'uid' => $uid]); DBA::delete('conv', ['id' => $this->parameters['id'], 'uid' => $uid]);
DBA::delete('mail', ['convid' => $this->parameters['id'], 'uid' => $uid]); DBA::delete('mail', ['convid' => $this->parameters['id'], 'uid' => $uid]);
System::jsonExit([]); $this->jsonExit([]);
} }
/** /**
@ -95,6 +95,6 @@ class Conversations extends BaseApi
} }
self::setLinkHeader(); self::setLinkHeader();
System::jsonExit($conversations); $this->jsonExit($conversations);
} }
} }

View file

@ -42,6 +42,6 @@ class Read extends BaseApi
DBA::update('mail', ['seen' => true], ['convid' => $this->parameters['id'], 'uid' => $uid]); DBA::update('mail', ['seen' => true], ['convid' => $this->parameters['id'], 'uid' => $uid]);
System::jsonExit(DI::mstdnConversation()->createFromConvId($this->parameters['id'])->toArray()); $this->jsonExit(DI::mstdnConversation()->createFromConvId($this->parameters['id'])->toArray());
} }
} }

View file

@ -41,6 +41,6 @@ class CustomEmojis extends BaseApi
{ {
$emojis = DI::mstdnEmoji()->createCollectionFromSmilies(Smilies::getList()); $emojis = DI::mstdnEmoji()->createCollectionFromSmilies(Smilies::getList());
System::jsonExit($emojis->getArrayCopy()); $this->jsonExit($emojis->getArrayCopy());
} }
} }

View file

@ -68,6 +68,6 @@ class Directory extends BaseApi
} }
DBA::close($contacts); DBA::close($contacts);
System::jsonExit($accounts); $this->jsonExit($accounts);
} }
} }

View file

@ -34,6 +34,6 @@ class Endorsements extends BaseApi
*/ */
protected function rawContent(array $request = []) protected function rawContent(array $request = [])
{ {
System::jsonExit([]); $this->jsonExit([]);
} }
} }

View file

@ -90,6 +90,6 @@ class Favourited extends BaseApi
} }
self::setLinkHeader(); self::setLinkHeader();
System::jsonExit($statuses); $this->jsonExit($statuses);
} }
} }

View file

@ -45,6 +45,6 @@ class Filters extends BaseApi
{ {
self::checkAllowedScope(self::SCOPE_READ); self::checkAllowedScope(self::SCOPE_READ);
System::jsonExit([]); $this->jsonExit([]);
} }
} }

View file

@ -79,7 +79,7 @@ class FollowRequests extends BaseApi
throw new HTTPException\BadRequestException('Unexpected action parameter, expecting "authorize", "ignore" or "reject"'); throw new HTTPException\BadRequestException('Unexpected action parameter, expecting "authorize", "ignore" or "reject"');
} }
System::jsonExit($relationship); $this->jsonExit($relationship);
} }
/** /**
@ -115,6 +115,6 @@ class FollowRequests extends BaseApi
} }
self::setLinkHeader(); self::setLinkHeader();
System::jsonExit($return); $this->jsonExit($return);
} }
} }

View file

@ -77,6 +77,6 @@ class FollowedTags extends BaseApi
} }
self::setLinkHeader(); self::setLinkHeader();
System::jsonExit($return); $this->jsonExit($return);
} }
} }

View file

@ -59,6 +59,6 @@ class Instance extends BaseApi
*/ */
protected function rawContent(array $request = []) protected function rawContent(array $request = [])
{ {
System::jsonExit(new InstanceEntity($this->config, $this->baseUrl, $this->database, System::getRules())); $this->jsonExit(new InstanceEntity($this->config, $this->baseUrl, $this->database, System::getRules()));
} }
} }

View file

@ -52,6 +52,6 @@ class Peers extends BaseApi
} }
DBA::close($instances); DBA::close($instances);
System::jsonExit($return); $this->jsonExit($return);
} }
} }

View file

@ -38,6 +38,6 @@ class Rules extends BaseApi
*/ */
protected function rawContent(array $request = []) protected function rawContent(array $request = [])
{ {
System::jsonExit(System::getRules()); $this->jsonExit(System::getRules());
} }
} }

View file

@ -94,7 +94,7 @@ class InstanceV2 extends BaseApi
$contact = $this->buildContactInfo(); $contact = $this->buildContactInfo();
$friendica_extensions = $this->buildFriendicaExtensionInfo(); $friendica_extensions = $this->buildFriendicaExtensionInfo();
$rules = System::getRules(); $rules = System::getRules();
System::jsonExit(new InstanceEntity( $this->jsonExit(new InstanceEntity(
$domain, $domain,
$title, $title,
$version, $version,

View file

@ -48,7 +48,7 @@ class Lists extends BaseApi
DI::mstdnError()->InternalError(); DI::mstdnError()->InternalError();
} }
System::jsonExit([]); $this->jsonExit([]);
} }
protected function post(array $request = []) protected function post(array $request = [])
@ -71,7 +71,7 @@ class Lists extends BaseApi
DI::mstdnError()->InternalError(); DI::mstdnError()->InternalError();
} }
System::jsonExit(DI::mstdnList()->createFromCircleId($id)); $this->jsonExit(DI::mstdnList()->createFromCircleId($id));
} }
public function put(array $request = []) public function put(array $request = [])
@ -111,6 +111,6 @@ class Lists extends BaseApi
$lists = DI::mstdnList()->createFromCircleId($id); $lists = DI::mstdnList()->createFromCircleId($id);
} }
System::jsonExit($lists); $this->jsonExit($lists);
} }
} }

View file

@ -127,6 +127,6 @@ class Accounts extends BaseApi
} }
self::setLinkHeader(); self::setLinkHeader();
System::jsonExit($accounts); $this->jsonExit($accounts);
} }
} }

View file

@ -61,7 +61,7 @@ class Markers extends BaseApi
$fields = ['last_read_id' => $last_read_id, 'version' => $version, 'updated_at' => DateTimeFormat::utcNow()]; $fields = ['last_read_id' => $last_read_id, 'version' => $version, 'updated_at' => DateTimeFormat::utcNow()];
DBA::update('application-marker', $fields, $condition, true); DBA::update('application-marker', $fields, $condition, true);
System::jsonExit($this->fetchTimelines($application['id'], $uid)); $this->jsonExit($this->fetchTimelines($application['id'], $uid));
} }
/** /**
@ -73,7 +73,7 @@ class Markers extends BaseApi
$uid = self::getCurrentUserID(); $uid = self::getCurrentUserID();
$application = self::getCurrentApplication(); $application = self::getCurrentApplication();
System::jsonExit($this->fetchTimelines($application['id'], $uid)); $this->jsonExit($this->fetchTimelines($application['id'], $uid));
} }
private function fetchTimelines(int $application_id, int $uid) private function fetchTimelines(int $application_id, int $uid)

View file

@ -58,7 +58,7 @@ class Media extends BaseApi
Logger::info('Uploaded photo', ['media' => $media]); Logger::info('Uploaded photo', ['media' => $media]);
System::jsonExit(DI::mstdnAttachment()->createFromPhoto($media['id'])); $this->jsonExit(DI::mstdnAttachment()->createFromPhoto($media['id']));
} }
public function put(array $request = []) public function put(array $request = [])
@ -87,12 +87,12 @@ class Media extends BaseApi
DI::mstdnError()->RecordNotFound(); DI::mstdnError()->RecordNotFound();
} }
Post\Media::updateById(['description' => $request['description']], $this->parameters['id']); Post\Media::updateById(['description' => $request['description']], $this->parameters['id']);
System::jsonExit(DI::mstdnAttachment()->createFromId($this->parameters['id'])); $this->jsonExit(DI::mstdnAttachment()->createFromId($this->parameters['id']));
} }
Photo::update(['desc' => $request['description']], ['resource-id' => $photo['resource-id']]); Photo::update(['desc' => $request['description']], ['resource-id' => $photo['resource-id']]);
System::jsonExit(DI::mstdnAttachment()->createFromPhoto($this->parameters['id'])); $this->jsonExit(DI::mstdnAttachment()->createFromPhoto($this->parameters['id']));
} }
/** /**
@ -112,6 +112,6 @@ class Media extends BaseApi
DI::mstdnError()->RecordNotFound(); DI::mstdnError()->RecordNotFound();
} }
System::jsonExit(DI::mstdnAttachment()->createFromPhoto($id)); $this->jsonExit(DI::mstdnAttachment()->createFromPhoto($id));
} }
} }

View file

@ -85,6 +85,6 @@ class Mutes extends BaseApi
} }
self::setLinkHeader(); self::setLinkHeader();
System::jsonExit($accounts); $this->jsonExit($accounts);
} }
} }

View file

@ -48,7 +48,7 @@ class Notifications extends BaseApi
$id = $this->parameters['id']; $id = $this->parameters['id'];
try { try {
$notification = DI::notification()->selectOneForUser($uid, ['id' => $id]); $notification = DI::notification()->selectOneForUser($uid, ['id' => $id]);
System::jsonExit(DI::mstdnNotification()->createFromNotification($notification, self::appSupportsQuotes())); $this->jsonExit(DI::mstdnNotification()->createFromNotification($notification, self::appSupportsQuotes()));
} catch (\Exception $e) { } catch (\Exception $e) {
DI::mstdnError()->RecordNotFound(); DI::mstdnError()->RecordNotFound();
} }
@ -132,7 +132,7 @@ class Notifications extends BaseApi
if ($request['summary']) { if ($request['summary']) {
$count = DI::notification()->countForUser($uid, $condition); $count = DI::notification()->countForUser($uid, $condition);
System::jsonExit(['count' => $count]); $this->jsonExit(['count' => $count]);
} else { } else {
$mstdnNotifications = []; $mstdnNotifications = [];
@ -154,7 +154,7 @@ class Notifications extends BaseApi
} }
self::setLinkHeader(); self::setLinkHeader();
System::jsonExit($mstdnNotifications); $this->jsonExit($mstdnNotifications);
} }
} }
} }

View file

@ -37,6 +37,6 @@ class Clear extends BaseApi
DI::notification()->setAllDismissedForUser($uid); DI::notification()->setAllDismissedForUser($uid);
System::jsonExit([]); $this->jsonExit([]);
} }
} }

View file

@ -46,6 +46,6 @@ class Dismiss extends BaseApi
$Notification->setDismissed(); $Notification->setDismissed();
DI::notification()->save($Notification); DI::notification()->save($Notification);
System::jsonExit([]); $this->jsonExit([]);
} }
} }

View file

@ -42,6 +42,6 @@ class Polls extends BaseApi
DI::mstdnError()->UnprocessableEntity(); DI::mstdnError()->UnprocessableEntity();
} }
System::jsonExit(DI::mstdnPoll()->createFromId($this->parameters['id'], $uid)); $this->jsonExit(DI::mstdnPoll()->createFromId($this->parameters['id'], $uid));
} }
} }

View file

@ -55,6 +55,6 @@ class Preferences extends BaseApi
$preferences = new \Friendica\Object\Api\Mastodon\Preferences($visibility, $sensitive, $language, $media, $spoilers); $preferences = new \Friendica\Object\Api\Mastodon\Preferences($visibility, $sensitive, $language, $media, $spoilers);
System::jsonExit($preferences); $this->jsonExit($preferences);
} }
} }

View file

@ -34,6 +34,6 @@ class Proofs extends BaseApi
*/ */
protected function rawContent(array $request = []) protected function rawContent(array $request = [])
{ {
System::jsonError(404, ['error' => 'Record not found']); $this->jsonError(404, ['error' => 'Record not found']);
} }
} }

View file

@ -81,7 +81,7 @@ class PushSubscription extends BaseApi
$this->logger->info('Subscription stored', ['ret' => $ret, 'subscription' => $subscription]); $this->logger->info('Subscription stored', ['ret' => $ret, 'subscription' => $subscription]);
$subscriptionObj = $this->subscriptionFac->createForApplicationIdAndUserId($application['id'], $uid); $subscriptionObj = $this->subscriptionFac->createForApplicationIdAndUserId($application['id'], $uid);
$this->response->exitWithJson($subscriptionObj->toArray()); $this->response->addJsonContent($subscriptionObj->toArray());
} }
public function put(array $request = []): void public function put(array $request = []): void
@ -120,7 +120,7 @@ class PushSubscription extends BaseApi
]); ]);
$subscriptionObj = $this->subscriptionFac->createForApplicationIdAndUserId($application['id'], $uid); $subscriptionObj = $this->subscriptionFac->createForApplicationIdAndUserId($application['id'], $uid);
$this->response->exitWithJson($subscriptionObj->toArray()); $this->response->addJsonContent($subscriptionObj->toArray());
} }
protected function delete(array $request = []): void protected function delete(array $request = []): void
@ -137,7 +137,7 @@ class PushSubscription extends BaseApi
'uid' => $uid, 'uid' => $uid,
]); ]);
$this->response->exitWithJson([]); $this->response->addJsonContent([]);
} }
protected function rawContent(array $request = []): void protected function rawContent(array $request = []): void
@ -154,6 +154,6 @@ class PushSubscription extends BaseApi
$this->logger->info('Fetch subscription', ['application-id' => $application['id'], 'uid' => $uid]); $this->logger->info('Fetch subscription', ['application-id' => $application['id'], 'uid' => $uid]);
$subscriptionObj = $this->subscriptionFac->createForApplicationIdAndUserId($application['id'], $uid); $subscriptionObj = $this->subscriptionFac->createForApplicationIdAndUserId($application['id'], $uid);
$this->response->exitWithJson($subscriptionObj->toArray()); $this->response->addJsonContent($subscriptionObj->toArray());
} }
} }

View file

@ -82,6 +82,6 @@ class Reports extends BaseApi
$this->reportRepo->save($report); $this->reportRepo->save($report);
System::jsonExit([]); $this->jsonExit([]);
} }
} }

View file

@ -56,7 +56,7 @@ class ScheduledStatuses extends BaseApi
Post\Delayed::deleteById($this->parameters['id']); Post\Delayed::deleteById($this->parameters['id']);
System::jsonExit([]); $this->jsonExit([]);
} }
/** /**
@ -68,7 +68,7 @@ class ScheduledStatuses extends BaseApi
$uid = self::getCurrentUserID(); $uid = self::getCurrentUserID();
if (isset($this->parameters['id'])) { if (isset($this->parameters['id'])) {
System::jsonExit(DI::mstdnScheduledStatus()->createFromDelayedPostId($this->parameters['id'], $uid)->toArray()); $this->jsonExit(DI::mstdnScheduledStatus()->createFromDelayedPostId($this->parameters['id'], $uid)->toArray());
} }
$request = $this->getRequest([ $request = $this->getRequest([
@ -109,6 +109,6 @@ class ScheduledStatuses extends BaseApi
} }
self::setLinkHeader(); self::setLinkHeader();
System::jsonExit($statuses); $this->jsonExit($statuses);
} }
} }

View file

@ -91,7 +91,7 @@ class Search extends BaseApi
$result['hashtags'] = self::searchHashtags($request['q'], $request['exclude_unreviewed'], $limit, $request['offset'], $this->parameters['version']); $result['hashtags'] = self::searchHashtags($request['q'], $request['exclude_unreviewed'], $limit, $request['offset'], $this->parameters['version']);
} }
System::jsonExit($result); $this->jsonExit($result);
} }
/** /**

View file

@ -159,7 +159,7 @@ class Statuses extends BaseApi
Item::updateDisplayCache($post['uri-id']); Item::updateDisplayCache($post['uri-id']);
System::jsonExit(DI::mstdnStatus()->createFromUriId($post['uri-id'], $uid, self::appSupportsQuotes())); $this->jsonExit(DI::mstdnStatus()->createFromUriId($post['uri-id'], $uid, self::appSupportsQuotes()));
} }
protected function post(array $request = []) protected function post(array $request = [])
@ -263,7 +263,7 @@ class Statuses extends BaseApi
$item['gravity'] = Item::GRAVITY_COMMENT; $item['gravity'] = Item::GRAVITY_COMMENT;
$item['object-type'] = Activity\ObjectType::COMMENT; $item['object-type'] = Activity\ObjectType::COMMENT;
} else { } else {
self::checkThrottleLimit(); $this->checkThrottleLimit();
$item['gravity'] = Item::GRAVITY_PARENT; $item['gravity'] = Item::GRAVITY_PARENT;
$item['object-type'] = Activity\ObjectType::NOTE; $item['object-type'] = Activity\ObjectType::NOTE;
@ -299,14 +299,14 @@ class Statuses extends BaseApi
if (empty($id)) { if (empty($id)) {
DI::mstdnError()->InternalError(); DI::mstdnError()->InternalError();
} }
System::jsonExit(DI::mstdnScheduledStatus()->createFromDelayedPostId($id, $uid)->toArray()); $this->jsonExit(DI::mstdnScheduledStatus()->createFromDelayedPostId($id, $uid)->toArray());
} }
$id = Item::insert($item, true); $id = Item::insert($item, true);
if (!empty($id)) { if (!empty($id)) {
$item = Post::selectFirst(['uri-id'], ['id' => $id]); $item = Post::selectFirst(['uri-id'], ['id' => $id]);
if (!empty($item['uri-id'])) { if (!empty($item['uri-id'])) {
System::jsonExit(DI::mstdnStatus()->createFromUriId($item['uri-id'], $uid, self::appSupportsQuotes())); $this->jsonExit(DI::mstdnStatus()->createFromUriId($item['uri-id'], $uid, self::appSupportsQuotes()));
} }
} }
@ -331,7 +331,7 @@ class Statuses extends BaseApi
DI::mstdnError()->RecordNotFound(); DI::mstdnError()->RecordNotFound();
} }
System::jsonExit([]); $this->jsonExit([]);
} }
/** /**
@ -345,7 +345,7 @@ class Statuses extends BaseApi
DI::mstdnError()->UnprocessableEntity(); DI::mstdnError()->UnprocessableEntity();
} }
System::jsonExit(DI::mstdnStatus()->createFromUriId($this->parameters['id'], $uid, self::appSupportsQuotes(), false)); $this->jsonExit(DI::mstdnStatus()->createFromUriId($this->parameters['id'], $uid, self::appSupportsQuotes(), false));
} }
private function getApp(): string private function getApp(): string
@ -422,7 +422,7 @@ class Statuses extends BaseApi
if (preg_match("/\[url=[^\[\]]*\](.*)\[\/url\]\z/ism", $status, $matches)) { if (preg_match("/\[url=[^\[\]]*\](.*)\[\/url\]\z/ism", $status, $matches)) {
$status = preg_replace("/\[url=[^\[\]]*\].*\[\/url\]\z/ism", PageInfo::getFooterFromUrl($matches[1]), $status); $status = preg_replace("/\[url=[^\[\]]*\].*\[\/url\]\z/ism", PageInfo::getFooterFromUrl($matches[1]), $status);
} }
return $status; return $status;
} }
} }

View file

@ -70,6 +70,6 @@ class Bookmark extends BaseApi
// Issue tracking the behavior of createFromUriId: https://github.com/friendica/friendica/issues/13350 // Issue tracking the behavior of createFromUriId: https://github.com/friendica/friendica/issues/13350
$isReblog = $item['uri-id'] != $this->parameters['id']; $isReblog = $item['uri-id'] != $this->parameters['id'];
System::jsonExit(DI::mstdnStatus()->createFromUriId($this->parameters['id'], $uid, self::appSupportsQuotes(), $isReblog)->toArray()); $this->jsonExit(DI::mstdnStatus()->createFromUriId($this->parameters['id'], $uid, self::appSupportsQuotes(), $isReblog)->toArray());
} }
} }

View file

@ -49,6 +49,6 @@ class Card extends BaseApi
$card = DI::mstdnCard()->createFromUriId($post['uri-id']); $card = DI::mstdnCard()->createFromUriId($post['uri-id']);
System::jsonExit($card->toArray()); $this->jsonExit($card->toArray());
} }
} }

View file

@ -140,7 +140,7 @@ class Context extends BaseApi
$statuses['descendants'][] = DI::mstdnStatus()->createFromUriId($descendant, $uid, $display_quotes); $statuses['descendants'][] = DI::mstdnStatus()->createFromUriId($descendant, $uid, $display_quotes);
} }
System::jsonExit($statuses); $this->jsonExit($statuses);
} }
private static function getParents(int $id, array $parents, array $list = []) private static function getParents(int $id, array $parents, array $list = [])

View file

@ -54,6 +54,6 @@ class Favourite extends BaseApi
// Issue tracking the behavior of createFromUriId: https://github.com/friendica/friendica/issues/13350 // Issue tracking the behavior of createFromUriId: https://github.com/friendica/friendica/issues/13350
$isReblog = $item['uri-id'] != $this->parameters['id']; $isReblog = $item['uri-id'] != $this->parameters['id'];
System::jsonExit(DI::mstdnStatus()->createFromUriId($this->parameters['id'], $uid, self::appSupportsQuotes(), $isReblog)->toArray()); $this->jsonExit(DI::mstdnStatus()->createFromUriId($this->parameters['id'], $uid, self::appSupportsQuotes(), $isReblog)->toArray());
} }
} }

View file

@ -56,6 +56,6 @@ class FavouritedBy extends BaseApi
$accounts[] = DI::mstdnAccount()->createFromContactId($activity['author-id'], $uid); $accounts[] = DI::mstdnAccount()->createFromContactId($activity['author-id'], $uid);
} }
System::jsonExit($accounts); $this->jsonExit($accounts);
} }
} }

View file

@ -58,6 +58,6 @@ class Mute extends BaseApi
// Issue tracking the behavior of createFromUriId: https://github.com/friendica/friendica/issues/13350 // Issue tracking the behavior of createFromUriId: https://github.com/friendica/friendica/issues/13350
$isReblog = $item['uri-id'] != $this->parameters['id']; $isReblog = $item['uri-id'] != $this->parameters['id'];
System::jsonExit(DI::mstdnStatus()->createFromUriId($this->parameters['id'], $uid, self::appSupportsQuotes(), $isReblog)->toArray()); $this->jsonExit(DI::mstdnStatus()->createFromUriId($this->parameters['id'], $uid, self::appSupportsQuotes(), $isReblog)->toArray());
} }
} }

View file

@ -53,6 +53,6 @@ class Pin extends BaseApi
// Issue tracking the behavior of createFromUriId: https://github.com/friendica/friendica/issues/13350 // Issue tracking the behavior of createFromUriId: https://github.com/friendica/friendica/issues/13350
$isReblog = $item['uri-id'] != $this->parameters['id']; $isReblog = $item['uri-id'] != $this->parameters['id'];
System::jsonExit(DI::mstdnStatus()->createFromUriId($this->parameters['id'], $uid, self::appSupportsQuotes(),$isReblog)->toArray()); $this->jsonExit(DI::mstdnStatus()->createFromUriId($this->parameters['id'], $uid, self::appSupportsQuotes(),$isReblog)->toArray());
} }
} }

View file

@ -63,6 +63,6 @@ class Reblog extends BaseApi
// Issue tracking the behavior of createFromUriId: https://github.com/friendica/friendica/issues/13350 // Issue tracking the behavior of createFromUriId: https://github.com/friendica/friendica/issues/13350
$isReblog = $item['uri-id'] != $this->parameters['id']; $isReblog = $item['uri-id'] != $this->parameters['id'];
System::jsonExit(DI::mstdnStatus()->createFromUriId($this->parameters['id'], $uid, self::appSupportsQuotes(), $isReblog)->toArray()); $this->jsonExit(DI::mstdnStatus()->createFromUriId($this->parameters['id'], $uid, self::appSupportsQuotes(), $isReblog)->toArray());
} }
} }

View file

@ -56,6 +56,6 @@ class RebloggedBy extends BaseApi
$accounts[] = DI::mstdnAccount()->createFromContactId($activity['author-id'], $uid); $accounts[] = DI::mstdnAccount()->createFromContactId($activity['author-id'], $uid);
} }
System::jsonExit($accounts); $this->jsonExit($accounts);
} }
} }

View file

@ -52,6 +52,6 @@ class Source extends BaseApi
$source = DI::mstdnStatusSource()->createFromUriId($id, $uid); $source = DI::mstdnStatusSource()->createFromUriId($id, $uid);
System::jsonExit($source->toArray()); $this->jsonExit($source->toArray());
} }
} }

View file

@ -70,6 +70,6 @@ class Unbookmark extends BaseApi
// Issue tracking the behavior of createFromUriId: https://github.com/friendica/friendica/issues/13350 // Issue tracking the behavior of createFromUriId: https://github.com/friendica/friendica/issues/13350
$isReblog = $item['uri-id'] != $this->parameters['id']; $isReblog = $item['uri-id'] != $this->parameters['id'];
System::jsonExit(DI::mstdnStatus()->createFromUriId($this->parameters['id'], $uid, self::appSupportsQuotes(), $isReblog)->toArray()); $this->jsonExit(DI::mstdnStatus()->createFromUriId($this->parameters['id'], $uid, self::appSupportsQuotes(), $isReblog)->toArray());
} }
} }

View file

@ -54,6 +54,6 @@ class Unfavourite extends BaseApi
// Issue tracking the behavior of createFromUriId: https://github.com/friendica/friendica/issues/13350 // Issue tracking the behavior of createFromUriId: https://github.com/friendica/friendica/issues/13350
$isReblog = $item['uri-id'] != $this->parameters['id']; $isReblog = $item['uri-id'] != $this->parameters['id'];
System::jsonExit(DI::mstdnStatus()->createFromUriId($this->parameters['id'], $uid, self::appSupportsQuotes(), $isReblog)->toArray()); $this->jsonExit(DI::mstdnStatus()->createFromUriId($this->parameters['id'], $uid, self::appSupportsQuotes(), $isReblog)->toArray());
} }
} }

View file

@ -58,6 +58,6 @@ class Unmute extends BaseApi
// Issue tracking the behavior of createFromUriId: https://github.com/friendica/friendica/issues/13350 // Issue tracking the behavior of createFromUriId: https://github.com/friendica/friendica/issues/13350
$isReblog = $item['uri-id'] != $this->parameters['id']; $isReblog = $item['uri-id'] != $this->parameters['id'];
System::jsonExit(DI::mstdnStatus()->createFromUriId($this->parameters['id'], $uid, self::appSupportsQuotes(), $isReblog)->toArray()); $this->jsonExit(DI::mstdnStatus()->createFromUriId($this->parameters['id'], $uid, self::appSupportsQuotes(), $isReblog)->toArray());
} }
} }

View file

@ -53,6 +53,6 @@ class Unpin extends BaseApi
// Issue tracking the behavior of createFromUriId: https://github.com/friendica/friendica/issues/13350 // Issue tracking the behavior of createFromUriId: https://github.com/friendica/friendica/issues/13350
$isReblog = $item['uri-id'] != $this->parameters['id']; $isReblog = $item['uri-id'] != $this->parameters['id'];
System::jsonExit(DI::mstdnStatus()->createFromUriId($this->parameters['id'], $uid, self::appSupportsQuotes(), $isReblog)->toArray()); $this->jsonExit(DI::mstdnStatus()->createFromUriId($this->parameters['id'], $uid, self::appSupportsQuotes(), $isReblog)->toArray());
} }
} }

View file

@ -69,6 +69,6 @@ class Unreblog extends BaseApi
// Issue tracking the behavior of createFromUriId: https://github.com/friendica/friendica/issues/13350 // Issue tracking the behavior of createFromUriId: https://github.com/friendica/friendica/issues/13350
$isReblog = $item['uri-id'] != $this->parameters['id']; $isReblog = $item['uri-id'] != $this->parameters['id'];
System::jsonExit(DI::mstdnStatus()->createFromUriId($this->parameters['id'], $uid, self::appSupportsQuotes(), $isReblog)->toArray()); $this->jsonExit(DI::mstdnStatus()->createFromUriId($this->parameters['id'], $uid, self::appSupportsQuotes(), $isReblog)->toArray());
} }
} }

View file

@ -54,6 +54,6 @@ class Suggestions extends BaseApi
]; ];
} }
System::jsonExit($accounts); $this->jsonExit($accounts);
} }
} }

View file

@ -47,6 +47,6 @@ class Tags extends BaseApi
$following = DBA::exists('search', ['uid' => $uid, 'term' => '#' . $tag]); $following = DBA::exists('search', ['uid' => $uid, 'term' => '#' . $tag]);
$hashtag = new \Friendica\Object\Api\Mastodon\Tag($this->baseUrl, ['name' => $tag], [], $following); $hashtag = new \Friendica\Object\Api\Mastodon\Tag($this->baseUrl, ['name' => $tag], [], $following);
System::jsonExit($hashtag->toArray()); $this->jsonExit($hashtag->toArray());
} }
} }

View file

@ -46,6 +46,6 @@ class Follow extends BaseApi
} }
$hashtag = new \Friendica\Object\Api\Mastodon\Tag($this->baseUrl, ['name' => ltrim($this->parameters['hashtag'])], [], true); $hashtag = new \Friendica\Object\Api\Mastodon\Tag($this->baseUrl, ['name' => ltrim($this->parameters['hashtag'])], [], true);
System::jsonExit($hashtag->toArray()); $this->jsonExit($hashtag->toArray());
} }
} }

View file

@ -45,6 +45,6 @@ class Unfollow extends BaseApi
DBA::delete('search', $term); DBA::delete('search', $term);
$hashtag = new \Friendica\Object\Api\Mastodon\Tag($this->baseUrl, ['name' => ltrim($this->parameters['hashtag'])], [], false); $hashtag = new \Friendica\Object\Api\Mastodon\Tag($this->baseUrl, ['name' => ltrim($this->parameters['hashtag'])], [], false);
System::jsonExit($hashtag->toArray()); $this->jsonExit($hashtag->toArray());
} }
} }

View file

@ -86,6 +86,6 @@ class Direct extends BaseApi
} }
self::setLinkHeader(); self::setLinkHeader();
System::jsonExit($statuses); $this->jsonExit($statuses);
} }
} }

View file

@ -101,6 +101,6 @@ class Home extends BaseApi
self::setLinkHeader($request['friendica_order'] != TimelineOrderByTypes::ID); self::setLinkHeader($request['friendica_order'] != TimelineOrderByTypes::ID);
System::jsonExit($statuses); $this->jsonExit($statuses);
} }
} }

View file

@ -105,6 +105,6 @@ class ListTimeline extends BaseApi
} }
self::setLinkHeader($request['friendica_order'] != TimelineOrderByTypes::ID); self::setLinkHeader($request['friendica_order'] != TimelineOrderByTypes::ID);
System::jsonExit($statuses); $this->jsonExit($statuses);
} }
} }

View file

@ -102,6 +102,6 @@ class PublicTimeline extends BaseApi
} }
self::setLinkHeader($request['friendica_order'] != TimelineOrderByTypes::ID); self::setLinkHeader($request['friendica_order'] != TimelineOrderByTypes::ID);
System::jsonExit($statuses); $this->jsonExit($statuses);
} }
} }

View file

@ -131,6 +131,6 @@ class Tag extends BaseApi
} }
self::setLinkHeader(); self::setLinkHeader();
System::jsonExit($statuses); $this->jsonExit($statuses);
} }
} }

View file

@ -60,6 +60,6 @@ class Links extends BaseApi
self::setLinkHeaderByOffsetLimit($request['offset'], $request['limit']); self::setLinkHeaderByOffsetLimit($request['offset'], $request['limit']);
} }
System::jsonExit($trending); $this->jsonExit($trending);
} }
} }

View file

@ -67,6 +67,6 @@ class Statuses extends BaseApi
self::setLinkHeaderByOffsetLimit($request['offset'], $request['limit']); self::setLinkHeaderByOffsetLimit($request['offset'], $request['limit']);
} }
System::jsonExit($trending); $this->jsonExit($trending);
} }
} }

View file

@ -60,6 +60,6 @@ class Tags extends BaseApi
self::setLinkHeaderByOffsetLimit($request['offset'], $request['limit']); self::setLinkHeaderByOffsetLimit($request['offset'], $request['limit']);
} }
System::jsonExit($trending); $this->jsonExit($trending);
} }
} }

View file

@ -51,6 +51,6 @@ class RateLimitStatus extends BaseApi
]; ];
} }
$this->response->exit('hash', ['hash' => $hash], $this->parameters['extension'] ?? null); $this->response->addFormattedContent('hash', ['hash' => $hash], $this->parameters['extension'] ?? null);
} }
} }

View file

@ -66,6 +66,6 @@ class UpdateProfile extends BaseApi
// "uid" is only needed for some internal stuff, so remove it from here // "uid" is only needed for some internal stuff, so remove it from here
unset($user_info['uid']); unset($user_info['uid']);
$this->response->exit('user', ['user' => $user_info], $this->parameters['extension'] ?? null); $this->response->addFormattedContent('user', ['user' => $user_info], $this->parameters['extension'] ?? null);
} }
} }

View file

@ -67,6 +67,6 @@ class UpdateProfileImage extends BaseApi
// "uid" is only needed for some internal stuff, so remove it from here // "uid" is only needed for some internal stuff, so remove it from here
unset($user_info['uid']); unset($user_info['uid']);
$this->response->exit('user', ['user' => $user_info], $this->parameters['extension'] ?? null); $this->response->addFormattedContent('user', ['user' => $user_info], $this->parameters['extension'] ?? null);
} }
} }

View file

@ -47,6 +47,6 @@ class VerifyCredentials extends BaseApi
// "uid" is only needed for some internal stuff, so remove it from here // "uid" is only needed for some internal stuff, so remove it from here
unset($user_info['uid']); unset($user_info['uid']);
$this->response->exit('user', ['user' => $user_info], $this->parameters['extension'] ?? null); $this->response->addFormattedContent('user', ['user' => $user_info], $this->parameters['extension'] ?? null);
} }
} }

View file

@ -83,6 +83,6 @@ class Ids extends ContactEndpoint
self::setLinkHeader(); self::setLinkHeader();
System::jsonExit($return); $this->jsonExit($return);
} }
} }

View file

@ -84,6 +84,6 @@ class Lists extends ContactEndpoint
self::setLinkHeader(); self::setLinkHeader();
$this->response->exit('lists', ['lists' => $return]); $this->response->addFormattedContent('lists', ['lists' => $return]);
} }
} }

View file

@ -61,7 +61,7 @@ class Destroy extends BaseApi
// error if no id or parenturi specified (for clients posting parent-uri as well) // error if no id or parenturi specified (for clients posting parent-uri as well)
if ($verbose && $id == 0 && $parenturi == "") { if ($verbose && $id == 0 && $parenturi == "") {
$answer = ['result' => 'error', 'message' => 'message id or parenturi not specified']; $answer = ['result' => 'error', 'message' => 'message id or parenturi not specified'];
$this->response->exit('direct_messages_delete', ['direct_messages_delete' => $answer], $this->parameters['extension'] ?? null); $this->response->addFormattedContent('direct_messages_delete', ['direct_messages_delete' => $answer], $this->parameters['extension'] ?? null);
return; return;
} }
@ -72,7 +72,7 @@ class Destroy extends BaseApi
if (!$this->dba->exists('mail', ["`uid` = ? AND `id` = ? " . $sql_extra, $uid, $id])) { if (!$this->dba->exists('mail', ["`uid` = ? AND `id` = ? " . $sql_extra, $uid, $id])) {
if ($verbose) { if ($verbose) {
$answer = ['result' => 'error', 'message' => 'message id not in database']; $answer = ['result' => 'error', 'message' => 'message id not in database'];
$this->response->exit('direct_messages_delete', ['direct_messages_delete' => $answer], $this->parameters['extension'] ?? null); $this->response->addFormattedContent('direct_messages_delete', ['direct_messages_delete' => $answer], $this->parameters['extension'] ?? null);
return; return;
} }
throw new BadRequestException('message id not in database'); throw new BadRequestException('message id not in database');
@ -85,10 +85,10 @@ class Destroy extends BaseApi
if ($result) { if ($result) {
// return success // return success
$answer = ['result' => 'ok', 'message' => 'message deleted']; $answer = ['result' => 'ok', 'message' => 'message deleted'];
$this->response->exit('direct_messages_delete', ['direct_messages_delete' => $answer], $this->parameters['extension'] ?? null); $this->response->addFormattedContent('direct_messages_delete', ['direct_messages_delete' => $answer], $this->parameters['extension'] ?? null);
} else { } else {
$answer = ['result' => 'error', 'message' => 'unknown error']; $answer = ['result' => 'error', 'message' => 'unknown error'];
$this->response->exit('direct_messages_delete', ['direct_messages_delete' => $answer], $this->parameters['extension'] ?? null); $this->response->addFormattedContent('direct_messages_delete', ['direct_messages_delete' => $answer], $this->parameters['extension'] ?? null);
} }
} }
} }

View file

@ -91,6 +91,6 @@ class NewDM extends BaseApi
$ret = ['error' => $id]; $ret = ['error' => $id];
} }
$this->response->exit('direct-messages', ['direct_message' => $ret], $this->parameters['extension'] ?? null, Contact::getPublicIdByUserId($uid)); $this->response->addFormattedContent('direct-messages', ['direct_message' => $ret], $this->parameters['extension'] ?? null, Contact::getPublicIdByUserId($uid));
} }
} }

View file

@ -99,7 +99,7 @@ abstract class DirectMessagesEndpoint extends BaseApi
$mails = $this->dba->selectToArray('mail', ['id'], $condition, $params); $mails = $this->dba->selectToArray('mail', ['id'], $condition, $params);
if ($verbose && !DBA::isResult($mails)) { if ($verbose && !DBA::isResult($mails)) {
$answer = ['result' => 'error', 'message' => 'no mails available']; $answer = ['result' => 'error', 'message' => 'no mails available'];
$this->response->exit('direct-messages', ['direct_message' => $answer], $this->parameters['extension'] ?? null); $this->response->addFormattedContent('direct-messages', ['direct_message' => $answer], $this->parameters['extension'] ?? null);
return; return;
} }
@ -116,6 +116,6 @@ abstract class DirectMessagesEndpoint extends BaseApi
self::setLinkHeader(); self::setLinkHeader();
$this->response->exit('direct-messages', ['direct_message' => $ret], $this->parameters['extension'] ?? null, Contact::getPublicIdByUserId($uid)); $this->response->addFormattedContent('direct-messages', ['direct_message' => $ret], $this->parameters['extension'] ?? null, Contact::getPublicIdByUserId($uid));
} }
} }

View file

@ -72,6 +72,6 @@ class Favorites extends BaseApi
} }
DBA::close($statuses); DBA::close($statuses);
$this->response->exit('statuses', ['status' => $ret], $this->parameters['extension'] ?? null, Contact::getPublicIdByUserId($uid)); $this->response->addFormattedContent('statuses', ['status' => $ret], $this->parameters['extension'] ?? null, Contact::getPublicIdByUserId($uid));
} }
} }

View file

@ -52,6 +52,6 @@ class Create extends BaseApi
$status_info = DI::twitterStatus()->createFromUriId($id, $uid)->toArray(); $status_info = DI::twitterStatus()->createFromUriId($id, $uid)->toArray();
$this->response->exit('status', ['status' => $status_info], $this->parameters['extension'] ?? null); $this->response->addFormattedContent('status', ['status' => $status_info], $this->parameters['extension'] ?? null);
} }
} }

View file

@ -52,6 +52,6 @@ class Destroy extends BaseApi
$status_info = DI::twitterStatus()->createFromUriId($id, $uid)->toArray(); $status_info = DI::twitterStatus()->createFromUriId($id, $uid)->toArray();
$this->response->exit('status', ['status' => $status_info], $this->parameters['extension'] ?? null); $this->response->addFormattedContent('status', ['status' => $status_info], $this->parameters['extension'] ?? null);
} }
} }

View file

@ -114,6 +114,6 @@ class Ids extends ContactEndpoint
self::setLinkHeader(); self::setLinkHeader();
System::jsonExit($return); $this->jsonExit($return);
} }
} }

View file

@ -114,6 +114,6 @@ class Lists extends ContactEndpoint
$this->response->setHeader(self::getLinkHeader()); $this->response->setHeader(self::getLinkHeader());
$this->response->exit('lists', ['lists' => $return]); $this->response->addFormattedContent('lists', ['lists' => $return]);
} }
} }

View file

@ -114,6 +114,6 @@ class Ids extends ContactEndpoint
self::setLinkHeader(); self::setLinkHeader();
System::jsonExit($return); $this->jsonExit($return);
} }
} }

View file

@ -114,6 +114,6 @@ class Lists extends ContactEndpoint
$this->response->setHeader(self::getLinkHeader()); $this->response->setHeader(self::getLinkHeader());
$this->response->exit('lists', ['lists' => $return]); $this->response->addFormattedContent('lists', ['lists' => $return]);
} }
} }

View file

@ -87,6 +87,6 @@ class Destroy extends ContactEndpoint
throw new HTTPException\InternalServerErrorException('Unable to unfollow this contact, please contact your administrator'); throw new HTTPException\InternalServerErrorException('Unable to unfollow this contact, please contact your administrator');
} }
$this->response->exit('friendships', ['user' => $user], $this->parameters['extension'] ?? null); $this->response->addFormattedContent('friendships', ['user' => $user], $this->parameters['extension'] ?? null);
} }
} }

View file

@ -82,6 +82,6 @@ class Incoming extends ContactEndpoint
$this->response->setHeader(self::getLinkHeader()); $this->response->setHeader(self::getLinkHeader());
$this->response->exit('incoming', ['incoming' => $return]); $this->response->addFormattedContent('incoming', ['incoming' => $return]);
} }
} }

View file

@ -112,6 +112,6 @@ class Show extends ContactEndpoint
] ]
]; ];
DI::apiResponse()->exit('relationship', ['relationship' => $relationship], $this->parameters['extension'] ?? null); DI::apiResponse()->addFormattedContent('relationship', ['relationship' => $relationship], $this->parameters['extension'] ?? null);
} }
} }

View file

@ -80,6 +80,6 @@ class Create extends BaseApi
$grp = $this->friendicaCircle->createFromId($gid); $grp = $this->friendicaCircle->createFromId($gid);
$this->response->exit('statuses', ['lists' => ['lists' => $grp]], $this->parameters['extension'] ?? null, Contact::getPublicIdByUserId($uid)); $this->response->addFormattedContent('statuses', ['lists' => ['lists' => $grp]], $this->parameters['extension'] ?? null, Contact::getPublicIdByUserId($uid));
} }
} }

View file

@ -77,7 +77,7 @@ class Destroy extends BaseApi
$list = $this->friendicaCircle->createFromId($gid); $list = $this->friendicaCircle->createFromId($gid);
if (Circle::remove($gid)) { if (Circle::remove($gid)) {
$this->response->exit('statuses', ['lists' => ['lists' => $list]], $this->parameters['extension'] ?? null, Contact::getPublicIdByUserId($uid)); $this->response->addFormattedContent('statuses', ['lists' => ['lists' => $list]], $this->parameters['extension'] ?? null, Contact::getPublicIdByUserId($uid));
} }
} }
} }

View file

@ -38,6 +38,6 @@ class Lists extends BaseApi
// This is a dummy endpoint // This is a dummy endpoint
$ret = []; $ret = [];
$this->response->exit('statuses', ["lists_list" => $ret], $this->parameters['extension'] ?? null, Contact::getPublicIdByUserId($uid)); $this->response->addFormattedContent('statuses', ["lists_list" => $ret], $this->parameters['extension'] ?? null, Contact::getPublicIdByUserId($uid));
} }
} }

View file

@ -64,6 +64,6 @@ class Ownership extends BaseApi
$lists[] = $this->friendicaCircle->createFromId($circle['id']); $lists[] = $this->friendicaCircle->createFromId($circle['id']);
} }
$this->response->exit('statuses', ['lists' => ['lists' => $lists]], $this->parameters['extension'] ?? null, Contact::getPublicIdByUserId($uid)); $this->response->addFormattedContent('statuses', ['lists' => ['lists' => $lists]], $this->parameters['extension'] ?? null, Contact::getPublicIdByUserId($uid));
} }
} }

View file

@ -103,6 +103,6 @@ class Statuses extends BaseApi
} }
$this->dba->close($statuses); $this->dba->close($statuses);
$this->response->exit('statuses', ['status' => $items], $this->parameters['extension'] ?? null, Contact::getPublicIdByUserId($uid)); $this->response->addFormattedContent('statuses', ['status' => $items], $this->parameters['extension'] ?? null, Contact::getPublicIdByUserId($uid));
} }
} }

View file

@ -78,7 +78,7 @@ class Update extends BaseApi
if (Circle::update($gid, $name)) { if (Circle::update($gid, $name)) {
$list = $this->friendicaCircle->createFromId($gid); $list = $this->friendicaCircle->createFromId($gid);
$this->response->exit('statuses', ['lists' => ['lists' => $list]], $this->parameters['extension'] ?? null, Contact::getPublicIdByUserId($uid)); $this->response->addFormattedContent('statuses', ['lists' => ['lists' => $list]], $this->parameters['extension'] ?? null, Contact::getPublicIdByUserId($uid));
} }
} }
} }

View file

@ -65,6 +65,6 @@ class Upload extends BaseApi
Logger::info('Media uploaded', ['return' => $returndata]); Logger::info('Media uploaded', ['return' => $returndata]);
$this->response->exit('media', ['media' => $returndata], $this->parameters['extension'] ?? null); $this->response->addFormattedContent('media', ['media' => $returndata], $this->parameters['extension'] ?? null);
} }
} }

View file

@ -44,6 +44,6 @@ class SavedSearches extends BaseApi
DBA::close($terms); DBA::close($terms);
$this->response->exit('terms', ['terms' => $result], $this->parameters['extension'] ?? null); $this->response->addFormattedContent('terms', ['terms' => $result], $this->parameters['extension'] ?? null);
} }
} }

View file

@ -72,7 +72,7 @@ class Tweets extends BaseApi
DBA::close($tags); DBA::close($tags);
if (empty($uriids)) { if (empty($uriids)) {
$this->response->exit('statuses', $data, $this->parameters['extension'] ?? null, Contact::getPublicIdByUserId($uid)); $this->response->addFormattedContent('statuses', $data, $this->parameters['extension'] ?? null, Contact::getPublicIdByUserId($uid));
return; return;
} }
@ -116,6 +116,6 @@ class Tweets extends BaseApi
} }
DBA::close($statuses); DBA::close($statuses);
$this->response->exit('statuses', ['status' => $ret], $this->parameters['extension'] ?? null, Contact::getPublicIdByUserId($uid)); $this->response->addFormattedContent('statuses', ['status' => $ret], $this->parameters['extension'] ?? null, Contact::getPublicIdByUserId($uid));
} }
} }

View file

@ -59,6 +59,6 @@ class Destroy extends BaseApi
Item::deleteForUser(['id' => $post['id']], $uid); Item::deleteForUser(['id' => $post['id']], $uid);
$this->response->exit('status', ['status' => $ret], $this->parameters['extension'] ?? null, Contact::getPublicIdByUserId($uid)); $this->response->addFormattedContent('status', ['status' => $ret], $this->parameters['extension'] ?? null, Contact::getPublicIdByUserId($uid));
} }
} }

View file

@ -87,6 +87,6 @@ class HomeTimeline extends BaseApi
} }
} }
$this->response->exit('statuses', ['status' => $ret], $this->parameters['extension'] ?? null, Contact::getPublicIdByUserId($uid)); $this->response->addFormattedContent('statuses', ['status' => $ret], $this->parameters['extension'] ?? null, Contact::getPublicIdByUserId($uid));
} }
} }

View file

@ -80,6 +80,6 @@ class Mentions extends BaseApi
} }
DBA::close($statuses); DBA::close($statuses);
$this->response->exit('statuses', ['status' => $ret], $this->parameters['extension'] ?? null, Contact::getPublicIdByUserId($uid)); $this->response->addFormattedContent('statuses', ['status' => $ret], $this->parameters['extension'] ?? null, Contact::getPublicIdByUserId($uid));
} }
} }

View file

@ -63,6 +63,6 @@ class NetworkPublicTimeline extends BaseApi
} }
DBA::close($statuses); DBA::close($statuses);
$this->response->exit('statuses', ['status' => $ret], $this->parameters['extension'] ?? null, Contact::getPublicIdByUserId($uid)); $this->response->addFormattedContent('statuses', ['status' => $ret], $this->parameters['extension'] ?? null, Contact::getPublicIdByUserId($uid));
} }
} }

View file

@ -85,6 +85,6 @@ class PublicTimeline extends BaseApi
} }
DBA::close($statuses); DBA::close($statuses);
$this->response->exit('statuses', ['status' => $ret], $this->parameters['extension'] ?? null, Contact::getPublicIdByUserId($uid)); $this->response->addFormattedContent('statuses', ['status' => $ret], $this->parameters['extension'] ?? null, Contact::getPublicIdByUserId($uid));
} }
} }

View file

@ -69,6 +69,6 @@ class Retweet extends BaseApi
$status_info = DI::twitterStatus()->createFromItemId($item_id, $uid)->toArray(); $status_info = DI::twitterStatus()->createFromItemId($item_id, $uid)->toArray();
DI::apiResponse()->exit('statuses', ['status' => $status_info], $this->parameters['extension'] ?? null); DI::apiResponse()->addFormattedContent('statuses', ['status' => $status_info], $this->parameters['extension'] ?? null);
} }
} }

View file

@ -85,10 +85,10 @@ class Show extends BaseApi
if ($conversation) { if ($conversation) {
$data = ['status' => $ret]; $data = ['status' => $ret];
$this->response->exit('statuses', $data, $this->parameters['extension'] ?? null, Contact::getPublicIdByUserId($uid)); $this->response->addFormattedContent('statuses', $data, $this->parameters['extension'] ?? null, Contact::getPublicIdByUserId($uid));
} else { } else {
$data = ['status' => $ret[0]]; $data = ['status' => $ret[0]];
$this->response->exit('status', $data, $this->parameters['extension'] ?? null, Contact::getPublicIdByUserId($uid)); $this->response->addFormattedContent('status', $data, $this->parameters['extension'] ?? null, Contact::getPublicIdByUserId($uid));
} }
} }
} }

View file

@ -121,7 +121,7 @@ class Update extends BaseApi
$item['gravity'] = Item::GRAVITY_COMMENT; $item['gravity'] = Item::GRAVITY_COMMENT;
$item['object-type'] = Activity\ObjectType::COMMENT; $item['object-type'] = Activity\ObjectType::COMMENT;
} else { } else {
self::checkThrottleLimit(); $this->checkThrottleLimit();
$item['gravity'] = Item::GRAVITY_PARENT; $item['gravity'] = Item::GRAVITY_PARENT;
$item['object-type'] = Activity\ObjectType::NOTE; $item['object-type'] = Activity\ObjectType::NOTE;
@ -184,7 +184,7 @@ class Update extends BaseApi
if (!empty($item['uri-id'])) { if (!empty($item['uri-id'])) {
// output the post that we just posted. // output the post that we just posted.
$status_info = DI::twitterStatus()->createFromUriId($item['uri-id'], $uid, $request['include_entities'])->toArray(); $status_info = DI::twitterStatus()->createFromUriId($item['uri-id'], $uid, $request['include_entities'])->toArray();
DI::apiResponse()->exit('status', ['status' => $status_info], $this->parameters['extension'] ?? null, Contact::getPublicIdByUserId($uid)); DI::apiResponse()->addFormattedContent('status', ['status' => $status_info], $this->parameters['extension'] ?? null, Contact::getPublicIdByUserId($uid));
return; return;
} }
} }

View file

@ -80,6 +80,6 @@ class UserTimeline extends BaseApi
} }
DBA::close($statuses); DBA::close($statuses);
$this->response->exit('statuses', ['status' => $ret], $this->parameters['extension'] ?? null, Contact::getPublicIdByUserId($uid)); $this->response->addFormattedContent('statuses', ['status' => $ret], $this->parameters['extension'] ?? null, Contact::getPublicIdByUserId($uid));
} }
} }

View file

@ -51,6 +51,6 @@ class Lookup extends BaseApi
throw new NotFoundException(); throw new NotFoundException();
} }
$this->response->exit('users', ['user' => $users], $this->parameters['extension'] ?? null); $this->response->addFormattedContent('users', ['user' => $users], $this->parameters['extension'] ?? null);
} }
} }

View file

@ -69,6 +69,6 @@ class Search extends BaseApi
throw new BadRequestException('No search term specified.'); throw new BadRequestException('No search term specified.');
} }
$this->response->exit('users', $userlist, $this->parameters['extension'] ?? null); $this->response->addFormattedContent('users', $userlist, $this->parameters['extension'] ?? null);
} }
} }

View file

@ -48,6 +48,6 @@ class Show extends BaseApi
// "uid" is only needed for some internal stuff, so remove it from here // "uid" is only needed for some internal stuff, so remove it from here
unset($user_info['uid']); unset($user_info['uid']);
$this->response->exit('user', ['user' => $user_info], $this->parameters['extension'] ?? null); $this->response->addFormattedContent('user', ['user' => $user_info], $this->parameters['extension'] ?? null);
} }
} }

View file

@ -434,7 +434,7 @@ class BaseApi extends BaseModule
} }
} }
public static function checkThrottleLimit() public function checkThrottleLimit()
{ {
$uid = self::getCurrentUserID(); $uid = self::getCurrentUserID();
@ -447,11 +447,11 @@ class BaseApi extends BaseModule
$posts_day = Post::countThread($condition); $posts_day = Post::countThread($condition);
if ($posts_day > $throttle_day) { if ($posts_day > $throttle_day) {
Logger::notice('Daily posting limit reached', ['uid' => $uid, 'posts' => $posts_day, 'limit' => $throttle_day]); $this->logger->notice('Daily posting limit reached', ['uid' => $uid, 'posts' => $posts_day, 'limit' => $throttle_day]);
$error = DI::l10n()->t('Too Many Requests'); $error = $this->t('Too Many Requests');
$error_description = DI::l10n()->tt("Daily posting limit of %d post reached. The post was rejected.", "Daily posting limit of %d posts reached. The post was rejected.", $throttle_day); $error_description = $this->tt("Daily posting limit of %d post reached. The post was rejected.", "Daily posting limit of %d posts reached. The post was rejected.", $throttle_day);
$errorobj = new \Friendica\Object\Api\Mastodon\Error($error, $error_description); $errorobj = new \Friendica\Object\Api\Mastodon\Error($error, $error_description);
System::jsonError(429, $errorobj->toArray()); $this->jsonError(429, $errorobj->toArray());
} }
} }
@ -464,10 +464,10 @@ class BaseApi extends BaseModule
if ($posts_week > $throttle_week) { if ($posts_week > $throttle_week) {
Logger::notice('Weekly posting limit reached', ['uid' => $uid, 'posts' => $posts_week, 'limit' => $throttle_week]); Logger::notice('Weekly posting limit reached', ['uid' => $uid, 'posts' => $posts_week, 'limit' => $throttle_week]);
$error = DI::l10n()->t('Too Many Requests'); $error = $this->t('Too Many Requests');
$error_description = DI::l10n()->tt("Weekly posting limit of %d post reached. The post was rejected.", "Weekly posting limit of %d posts reached. The post was rejected.", $throttle_week); $error_description = $this->tt("Weekly posting limit of %d post reached. The post was rejected.", "Weekly posting limit of %d posts reached. The post was rejected.", $throttle_week);
$errorobj = new \Friendica\Object\Api\Mastodon\Error($error, $error_description); $errorobj = new \Friendica\Object\Api\Mastodon\Error($error, $error_description);
System::jsonError(429, $errorobj->toArray()); $this->jsonError(429, $errorobj->toArray());
} }
} }
@ -480,10 +480,10 @@ class BaseApi extends BaseModule
if ($posts_month > $throttle_month) { if ($posts_month > $throttle_month) {
Logger::notice('Monthly posting limit reached', ['uid' => $uid, 'posts' => $posts_month, 'limit' => $throttle_month]); Logger::notice('Monthly posting limit reached', ['uid' => $uid, 'posts' => $posts_month, 'limit' => $throttle_month]);
$error = DI::l10n()->t('Too Many Requests'); $error = $this->t('Too Many Requests');
$error_description = DI::l10n()->tt('Monthly posting limit of %d post reached. The post was rejected.', 'Monthly posting limit of %d posts reached. The post was rejected.', $throttle_month); $error_description = $this->tt('Monthly posting limit of %d post reached. The post was rejected.', 'Monthly posting limit of %d posts reached. The post was rejected.', $throttle_month);
$errorobj = new \Friendica\Object\Api\Mastodon\Error($error, $error_description); $errorobj = new \Friendica\Object\Api\Mastodon\Error($error, $error_description);
System::jsonError(429, $errorobj->toArray()); $this->jsonError(429, $errorobj->toArray());
} }
} }
} }

View file

@ -121,7 +121,7 @@ abstract class BaseNotifications extends BaseModule
'page' => $pager->getPage(), 'page' => $pager->getPage(),
]; ];
System::jsonExit($notifications); $this->jsonExit($notifications);
} }
/** /**

View file

@ -183,7 +183,7 @@ class API extends BaseModule
if (strcmp($finish, $start) < 0 && !$noFinish) { if (strcmp($finish, $start) < 0 && !$noFinish) {
if ($isPreview) { if ($isPreview) {
System::httpExit($this->t('Event can not end before it has started.')); $this->httpExit($this->t('Event can not end before it has started.'));
} else { } else {
$this->sysMessages->addNotice($this->t('Event can not end before it has started.')); $this->sysMessages->addNotice($this->t('Event can not end before it has started.'));
$this->baseUrl->redirect($redirectOnError); $this->baseUrl->redirect($redirectOnError);
@ -192,7 +192,7 @@ class API extends BaseModule
if (empty($summary) || ($start === DBA::NULL_DATETIME)) { if (empty($summary) || ($start === DBA::NULL_DATETIME)) {
if ($isPreview) { if ($isPreview) {
System::httpExit($this->t('Event title and start time are required.')); $this->httpExit($this->t('Event title and start time are required.'));
} else { } else {
$this->sysMessages->addNotice($this->t('Event title and start time are required.')); $this->sysMessages->addNotice($this->t('Event title and start time are required.'));
$this->baseUrl->redirect($redirectOnError); $this->baseUrl->redirect($redirectOnError);
@ -251,7 +251,7 @@ class API extends BaseModule
]; ];
if (intval($request['preview'])) { if (intval($request['preview'])) {
System::httpExit(Event::getHTML($datarray)); $this->httpExit(Event::getHTML($datarray));
} }
$eventId = Event::store($datarray); $eventId = Event::store($datarray);

View file

@ -69,7 +69,7 @@ class Get extends \Friendica\BaseModule
$events = Event::getListByDate($owner['uid'], $request['start'] ?? '', $request['end'] ?? ''); $events = Event::getListByDate($owner['uid'], $request['start'] ?? '', $request['end'] ?? '');
} }
System::jsonExit($events ? self::map($events) : []); $this->jsonExit($events ? self::map($events) : []);
} }
private static function map(array $events): array private static function map(array $events): array

View file

@ -81,6 +81,6 @@ class Show extends BaseModule
'$event' => $tplEvent, '$event' => $tplEvent,
]); ]);
System::httpExit($o); $this->httpExit($o);
} }
} }

View file

@ -132,10 +132,10 @@ class Circle extends BaseModule
} }
DI::sysmsg()->addInfo($message); DI::sysmsg()->addInfo($message);
System::jsonExit(['status' => 'OK', 'message' => $message]); $this->jsonExit(['status' => 'OK', 'message' => $message]);
} catch (\Exception $e) { } catch (\Exception $e) {
DI::sysmsg()->addNotice($e->getMessage()); DI::sysmsg()->addNotice($e->getMessage());
System::jsonError($e->getCode(), ['status' => 'error', 'message' => $e->getMessage()]); $this->jsonError($e->getCode(), ['status' => 'error', 'message' => $e->getMessage()]);
} }
} }

View file

@ -115,6 +115,6 @@ class Hovercard extends BaseModule
], ],
]); ]);
System::httpExit($o); $this->httpExit($o);
} }
} }

View file

@ -21,40 +21,22 @@
namespace Friendica\Module\DFRN; namespace Friendica\Module\DFRN;
use Friendica\App;
use Friendica\BaseModule; use Friendica\BaseModule;
use Friendica\Core\L10n;
use Friendica\Core\Logger;
use Friendica\Core\System;
use Friendica\Database\Database;
use Friendica\DI;
use Friendica\Model\Contact; use Friendica\Model\Contact;
use Friendica\Model\Conversation; use Friendica\Model\Conversation;
use Friendica\Model\User; use Friendica\Model\User;
use Friendica\Module\OStatus\Salmon;
use Friendica\Module\Response; use Friendica\Module\Response;
use Friendica\Network\HTTPException;
use Friendica\Protocol\DFRN; use Friendica\Protocol\DFRN;
use Friendica\Protocol\Diaspora; use Friendica\Protocol\Diaspora;
use Friendica\Util\Network; use Friendica\Util\Network;
use Friendica\Network\HTTPException; use Friendica\Util\XML;
use Friendica\Util\Profiler;
use Psr\Log\LoggerInterface;
/** /**
* DFRN Notify * DFRN Notify
*/ */
class Notify extends BaseModule class Notify extends BaseModule
{ {
/** @var Database */
private $database;
public function __construct(Database $database, L10n $l10n, App\BaseURL $baseUrl, App\Arguments $args, LoggerInterface $logger, Profiler $profiler, Response $response, array $server, array $parameters = [])
{
parent::__construct($l10n, $baseUrl, $args, $logger, $profiler, $response, $server, $parameters);
$this->database = $database;
}
protected function post(array $request = []) protected function post(array $request = [])
{ {
$postdata = Network::postdata(); $postdata = Network::postdata();
@ -88,21 +70,21 @@ class Notify extends BaseModule
$contact_id = Contact::getIdForURL($msg['author']); $contact_id = Contact::getIdForURL($msg['author']);
if (empty($contact_id)) { if (empty($contact_id)) {
$this->logger->notice('Contact not found', ['address' => $msg['author']]); $this->logger->notice('Contact not found', ['address' => $msg['author']]);
System::xmlExit(3, 'Contact ' . $msg['author'] . ' not found'); $this->xmlExit(3, 'Contact ' . $msg['author'] . ' not found');
} }
// Fetch the importer (Mixture of sender and receiver) // Fetch the importer (Mixture of sender and receiver)
$importer = DFRN::getImporter($contact_id); $importer = DFRN::getImporter($contact_id);
if (empty($importer)) { if (empty($importer)) {
$this->logger->notice('Importer contact not found', ['address' => $msg['author']]); $this->logger->notice('Importer contact not found', ['address' => $msg['author']]);
System::xmlExit(3, 'Contact ' . $msg['author'] . ' not found'); $this->xmlExit(3, 'Contact ' . $msg['author'] . ' not found');
} }
$this->logger->debug('Importing post with the public envelope.', ['transmitter' => $msg['author']]); $this->logger->debug('Importing post with the public envelope.', ['transmitter' => $msg['author']]);
// Now we should be able to import it // Now we should be able to import it
$ret = DFRN::import($msg['message'], $importer, Conversation::PARCEL_DIASPORA_DFRN, Conversation::RELAY); $ret = DFRN::import($msg['message'], $importer, Conversation::PARCEL_DIASPORA_DFRN, Conversation::RELAY);
System::xmlExit($ret, 'Done'); $this->xmlExit($ret, 'Done');
return true; return true;
} }
@ -111,32 +93,57 @@ class Notify extends BaseModule
{ {
$msg = Diaspora::decodeRaw($postdata, $user['prvkey'] ?? ''); $msg = Diaspora::decodeRaw($postdata, $user['prvkey'] ?? '');
if (!is_array($msg)) { if (!is_array($msg)) {
System::xmlExit(4, 'Unable to parse message'); $this->xmlExit(4, 'Unable to parse message');
} }
// Fetch the contact // Fetch the contact
$contact = Contact::getByURLForUser($msg['author'], $user['uid'], null, ['id', 'blocked', 'pending']); $contact = Contact::getByURLForUser($msg['author'], $user['uid'], null, ['id', 'blocked', 'pending']);
if (empty($contact['id'])) { if (empty($contact['id'])) {
$this->logger->notice('Contact not found', ['address' => $msg['author']]); $this->logger->notice('Contact not found', ['address' => $msg['author']]);
System::xmlExit(3, 'Contact ' . $msg['author'] . ' not found'); $this->xmlExit(3, 'Contact ' . $msg['author'] . ' not found');
} }
if ($contact['pending'] || $contact['blocked']) { if ($contact['pending'] || $contact['blocked']) {
$this->logger->notice('Contact is blocked or pending', ['address' => $msg['author'], 'contact' => $contact]); $this->logger->notice('Contact is blocked or pending', ['address' => $msg['author'], 'contact' => $contact]);
System::xmlExit(3, 'Contact ' . $msg['author'] . ' not found'); $this->xmlExit(3, 'Contact ' . $msg['author'] . ' not found');
} }
// Fetch the importer (Mixture of sender and receiver) // Fetch the importer (Mixture of sender and receiver)
$importer = DFRN::getImporter($contact['id'], $user['uid']); $importer = DFRN::getImporter($contact['id'], $user['uid']);
if (empty($importer)) { if (empty($importer)) {
$this->logger->notice('Importer contact not found for user', ['uid' => $user['uid'], 'cid' => $contact['id'], 'address' => $msg['author']]); $this->logger->notice('Importer contact not found for user', ['uid' => $user['uid'], 'cid' => $contact['id'], 'address' => $msg['author']]);
System::xmlExit(3, 'Contact ' . $msg['author'] . ' not found'); $this->xmlExit(3, 'Contact ' . $msg['author'] . ' not found');
} }
$this->logger->debug('Importing post with the private envelope.', ['transmitter' => $msg['author'], 'receiver' => $user['nickname']]); $this->logger->debug('Importing post with the private envelope.', ['transmitter' => $msg['author'], 'receiver' => $user['nickname']]);
// Now we should be able to import it // Now we should be able to import it
$ret = DFRN::import($msg['message'], $importer, Conversation::PARCEL_DIASPORA_DFRN, Conversation::PUSH); $ret = DFRN::import($msg['message'], $importer, Conversation::PARCEL_DIASPORA_DFRN, Conversation::PUSH);
System::xmlExit($ret, 'Done'); $this->xmlExit($ret, 'Done');
}
/**
* Generic XML return
* Outputs a basic dfrn XML status structure to STDOUT, with a <status> variable
* of $st and an optional text <message> of $message and terminates the current process.
*
* @param mixed $status
* @param string $message
* @throws \Exception
*/
private function xmlExit($status, string $message = '')
{
$result = ['status' => $status];
if ($message != '') {
$result['message'] = $message;
}
if ($status) {
$this->logger->notice('xml_status returning non_zero: ' . $status . " message=" . $message);
}
$this->httpExit(XML::fromArray(['result' => $result]), Response::TYPE_XML);
} }
} }

View file

@ -48,6 +48,6 @@ class Poll extends BaseModule
} }
$last_update = $request['last_update'] ?? ''; $last_update = $request['last_update'] ?? '';
System::httpExit(OStatus::feed($owner['nickname'], $last_update, 10) ?? '', Response::TYPE_ATOM); $this->httpExit(OStatus::feed($owner['nickname'], $last_update, 10) ?? '', Response::TYPE_ATOM);
} }
} }

View file

@ -85,6 +85,6 @@ class Fetch extends BaseModule
$xml = Diaspora::buildPostXml($status["type"], $status["message"]); $xml = Diaspora::buildPostXml($status["type"], $status["message"]);
// Send the envelope // Send the envelope
System::httpExit(Diaspora::buildMagicEnvelope($xml, $user), Response::TYPE_XML, 'application/magic-envelope+xml'); $this->httpExit(Diaspora::buildMagicEnvelope($xml, $user), Response::TYPE_XML, 'application/magic-envelope+xml');
} }
} }

View file

@ -71,6 +71,6 @@ class Feed extends BaseModule
$feed = ProtocolFeed::atom($owner, $last_update, 10, $type); $feed = ProtocolFeed::atom($owner, $last_update, 10, $type);
System::httpExit($feed, Response::TYPE_ATOM); $this->httpExit($feed, Response::TYPE_ATOM);
} }
} }

View file

@ -54,7 +54,7 @@ class RemoveTag extends BaseModule
protected function post(array $request = []) protected function post(array $request = [])
{ {
System::httpError($this->removeTag($request)); $this->httpError($this->removeTag($request));
} }
protected function content(array $request = []): string protected function content(array $request = []): string

View file

@ -142,9 +142,9 @@ class Friendica extends BaseModule
$data = ActivityPub\Transmitter::getProfile(0); $data = ActivityPub\Transmitter::getProfile(0);
header('Access-Control-Allow-Origin: *'); header('Access-Control-Allow-Origin: *');
header('Cache-Control: max-age=23200, stale-while-revalidate=23200'); header('Cache-Control: max-age=23200, stale-while-revalidate=23200');
System::jsonExit($data, 'application/activity+json'); $this->jsonExit($data, 'application/activity+json');
} catch (HTTPException\NotFoundException $e) { } catch (HTTPException\NotFoundException $e) {
System::jsonError(404, ['error' => 'Record not found']); $this->jsonError(404, ['error' => 'Record not found']);
} }
} }
@ -200,6 +200,6 @@ class Friendica extends BaseModule
'no_scrape_url' => $this->baseUrl . '/noscrape', 'no_scrape_url' => $this->baseUrl . '/noscrape',
]; ];
System::jsonExit($data); $this->jsonExit($data);
} }
} }

View file

@ -36,7 +36,7 @@ class Hashtag extends BaseModule
$result = []; $result = [];
if (empty($request['t'])) { if (empty($request['t'])) {
System::jsonExit($result); $this->jsonExit($result);
} }
$taglist = DBA::select( $taglist = DBA::select(
@ -50,6 +50,6 @@ class Hashtag extends BaseModule
} }
DBA::close($taglist); DBA::close($taglist);
System::jsonExit($result); $this->jsonExit($result);
} }
} }

View file

@ -89,6 +89,6 @@ class Activity extends BaseModule
'state' => 1, 'state' => 1,
]; ];
System::jsonExit($return); $this->jsonExit($return);
} }
} }

View file

@ -86,6 +86,6 @@ class Feed extends BaseModule
throw new HTTPException\InternalServerErrorException($this->t('The feed for this item is unavailable.', ['uri-id' => $uriId])); throw new HTTPException\InternalServerErrorException($this->t('The feed for this item is unavailable.', ['uri-id' => $uriId]));
} }
System::httpExit($xml, Response::TYPE_ATOM); $this->httpExit($xml, Response::TYPE_ATOM);
} }
} }

View file

@ -71,6 +71,6 @@ class Follow extends BaseModule
'state' => 1 'state' => 1
]; ];
System::jsonExit($return); $this->jsonExit($return);
} }
} }

View file

@ -82,6 +82,6 @@ class Ignore extends BaseModule
'state' => $ignored, 'state' => $ignored,
]; ];
System::jsonExit($return); $this->jsonExit($return);
} }
} }

View file

@ -84,6 +84,6 @@ class Pin extends BaseModule
'state' => (int)$pinned, 'state' => (int)$pinned,
]; ];
System::jsonExit($return); $this->jsonExit($return);
} }
} }

View file

@ -91,6 +91,6 @@ class Star extends BaseModule
'state' => (int)$starred, 'state' => (int)$starred,
]; ];
System::jsonExit($return); $this->jsonExit($return);
} }
} }

View file

@ -133,6 +133,6 @@ class Manifest extends BaseModule
$manifest['theme_color'] = $theme_color; $manifest['theme_color'] = $theme_color;
} }
Core\System::jsonExit($manifest, 'application/manifest+json'); $this->jsonExit($manifest, 'application/manifest+json');
} }
} }

View file

@ -80,7 +80,7 @@ class Browser extends BaseModule
]); ]);
if (empty($request['mode'])) { if (empty($request['mode'])) {
System::httpExit($output); $this->httpExit($output);
} }
return $output; return $output;

View file

@ -150,7 +150,7 @@ class Upload extends \Friendica\BaseModule
$this->response->addContent($message); $this->response->addContent($message);
} }
$this->page->exit($this->response->generate()); System::echoResponse($this->response->generate());
System::exit(); System::exit();
} }
} }

View file

@ -91,7 +91,7 @@ class Browser extends BaseModule
]); ]);
if (empty($request['mode'])) { if (empty($request['mode'])) {
System::httpExit($output); $this->httpExit($output);
} }
return $output; return $output;

View file

@ -207,7 +207,7 @@ class Upload extends \Friendica\BaseModule
$this->response->addContent($message); $this->response->addContent($message);
} }
$this->page->exit($this->response->generate()); System::echoResponse($this->response->generate());
System::exit(); System::exit();
} }
} }

View file

@ -45,13 +45,13 @@ class NoScrape extends BaseModule
// view infos about a known profile (needs a login) // view infos about a known profile (needs a login)
$which = $a->getLoggedInUserNickname(); $which = $a->getLoggedInUserNickname();
} else { } else {
System::jsonError(403, 'Authentication required'); $this->jsonError(403, 'Authentication required');
} }
$owner = User::getOwnerDataByNick($which); $owner = User::getOwnerDataByNick($which);
if (empty($owner['uid'])) { if (empty($owner['uid'])) {
System::jsonError(404, 'Profile not found'); $this->jsonError(404, 'Profile not found');
} }
$json_info = [ $json_info = [
@ -71,7 +71,7 @@ class NoScrape extends BaseModule
if (!$owner['net-publish']) { if (!$owner['net-publish']) {
$json_info['hide'] = true; $json_info['hide'] = true;
System::jsonExit($json_info); $this->jsonExit($json_info);
} }
$keywords = $owner['pub_keywords'] ?? ''; $keywords = $owner['pub_keywords'] ?? '';
@ -107,6 +107,6 @@ class NoScrape extends BaseModule
} }
} }
System::jsonExit($json_info); $this->jsonExit($json_info);
} }
} }

View file

@ -116,7 +116,7 @@ class Notification extends BaseModule
$success = false; $success = false;
} }
System::jsonExit(['result' => (($success) ? 'success' : 'fail')]); $this->jsonExit(['result' => (($success) ? 'success' : 'fail')]);
} }
} }

View file

@ -303,9 +303,9 @@ class Ping extends BaseModule
if (isset($_GET['callback'])) { if (isset($_GET['callback'])) {
// JSONP support // JSONP support
System::httpExit($_GET['callback'] . '(' . json_encode(['result' => $data]) . ')', Response::TYPE_BLANK, 'application/javascript'); $this->httpExit($_GET['callback'] . '(' . json_encode(['result' => $data]) . ')', Response::TYPE_BLANK, 'application/javascript');
} else { } else {
System::jsonExit(['result' => $data]); $this->jsonExit(['result' => $data]);
} }
} }
} }

View file

@ -55,6 +55,6 @@ class Revoke extends BaseApi
} }
DBA::delete('application-token', ['application-id' => $token['id']]); DBA::delete('application-token', ['application-id' => $token['id']]);
System::jsonExit([]); $this->jsonExit([]);
} }
} }

View file

@ -110,6 +110,6 @@ class Token extends BaseApi
$object = new \Friendica\Object\Api\Mastodon\Token($token['access_token'], 'Bearer', $application['scopes'], $token['created_at'], $me); $object = new \Friendica\Object\Api\Mastodon\Token($token['access_token'], 'Bearer', $application['scopes'], $token['created_at'], $me);
System::jsonExit($object->toArray()); $this->jsonExit($object->toArray());
} }
} }

View file

@ -155,6 +155,6 @@ class PubSub extends \Friendica\BaseModule
$this->logger->notice('Success for contact.', ['mode' => $hub_mode, 'contact' => $contact_id]); $this->logger->notice('Success for contact.', ['mode' => $hub_mode, 'contact' => $contact_id]);
} }
System::httpExit($hub_challenge); $this->httpExit($hub_challenge);
} }
} }

View file

@ -85,6 +85,6 @@ class OpenSearch extends BaseModule
'template' => "$baseUrl/opensearch", 'template' => "$baseUrl/opensearch",
]); ]);
System::httpExit($xml->saveXML(), Response::TYPE_XML, 'application/opensearchdescription+xml'); $this->httpExit($xml->saveXML(), Response::TYPE_XML, 'application/opensearchdescription+xml');
} }
} }

View file

@ -101,6 +101,6 @@ class Owa extends BaseModule
} }
} }
} }
System::jsonExit($ret, 'application/x-zot+json'); $this->jsonExit($ret, 'application/x-zot+json');
} }
} }

View file

@ -100,9 +100,9 @@ class ParseUrl extends BaseModule
if ($arr['text']) { if ($arr['text']) {
if ($format == 'json') { if ($format == 'json') {
System::jsonExit($arr['text']); $this->jsonExit($arr['text']);
} else { } else {
System::httpExit($arr['text']); $this->httpExit($arr['text']);
} }
} }
@ -133,9 +133,9 @@ class ParseUrl extends BaseModule
$ret['success'] = true; $ret['success'] = true;
} }
System::jsonExit($ret); $this->jsonExit($ret);
} else { } else {
System::httpExit(BBCode::embedURL($url, empty($_GET['noAttachment']), $title, $description, $_GET['tags'] ?? '')); $this->httpExit(BBCode::embedURL($url, empty($_GET['noAttachment']), $title, $description, $_GET['tags'] ?? ''));
} }
} }
} }

View file

@ -166,9 +166,9 @@ class PermissionTooltip extends \Friendica\BaseModule
} }
if (!empty($l)) { if (!empty($l)) {
System::httpExit($o . implode(', ', $l)); $this->httpExit($o . implode(', ', $l));
} else { } else {
System::httpExit($o . $receivers);; $this->httpExit($o . $receivers);;
} }
} }

View file

@ -57,12 +57,12 @@ class Share extends \Friendica\BaseModule
{ {
$post_id = $this->parameters['post_id']; $post_id = $this->parameters['post_id'];
if (!$post_id || !$this->session->getLocalUserId()) { if (!$post_id || !$this->session->getLocalUserId()) {
System::httpError(403); $this->httpError(403);
} }
$item = Post::selectFirst(['private', 'body', 'uri', 'plink', 'network'], ['id' => $post_id]); $item = Post::selectFirst(['private', 'body', 'uri', 'plink', 'network'], ['id' => $post_id]);
if (!$item || $item['private'] == Item::PRIVATE) { if (!$item || $item['private'] == Item::PRIVATE) {
System::httpError(404); $this->httpError(404);
} }
$shared = $this->contentItem->getSharedPost($item, ['uri']); $shared = $this->contentItem->getSharedPost($item, ['uri']);
@ -74,6 +74,6 @@ class Share extends \Friendica\BaseModule
$content = '[share]' . $item['uri'] . '[/share]'; $content = '[share]' . $item['uri'] . '[/share]';
} }
System::httpExit($content); $this->httpExit($content);
} }
} }

Some files were not shown because too many files have changed in this diff Show more