mirror of
https://github.com/friendica/friendica
synced 2025-04-23 15:50:25 +00:00
Inherit ApiResponse
from Response
This commit is contained in:
parent
561aba18e3
commit
537b74f307
46 changed files with 326 additions and 277 deletions
|
@ -5,6 +5,7 @@ namespace Friendica\Module\Api;
|
|||
use Friendica\App\Arguments;
|
||||
use Friendica\App\BaseURL;
|
||||
use Friendica\Core\L10n;
|
||||
use Friendica\Module\Response;
|
||||
use Friendica\Util\Arrays;
|
||||
use Friendica\Util\DateTimeFormat;
|
||||
use Friendica\Util\HTTPInputData;
|
||||
|
@ -13,9 +14,9 @@ use Psr\Log\LoggerInterface;
|
|||
use Friendica\Factory\Api\Twitter\User as TwitterUser;
|
||||
|
||||
/**
|
||||
* This class is used to format and return API responses
|
||||
* This class is used to format and create API responses
|
||||
*/
|
||||
class ApiResponse
|
||||
class ApiResponse extends Response
|
||||
{
|
||||
/** @var L10n */
|
||||
protected $l10n;
|
||||
|
@ -23,42 +24,18 @@ class ApiResponse
|
|||
protected $args;
|
||||
/** @var LoggerInterface */
|
||||
protected $logger;
|
||||
/** @var BaseURL */
|
||||
protected $baseUrl;
|
||||
/** @var TwitterUser */
|
||||
protected $twitterUser;
|
||||
|
||||
/**
|
||||
* @param L10n $l10n
|
||||
* @param Arguments $args
|
||||
* @param LoggerInterface $logger
|
||||
*/
|
||||
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)
|
||||
{
|
||||
$this->l10n = $l10n;
|
||||
$this->args = $args;
|
||||
$this->logger = $logger;
|
||||
$this->baseurl = $baseurl;
|
||||
$this->twitterUser = $twitteruser;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets header directly
|
||||
* mainly used to override it for tests
|
||||
*
|
||||
* @param string $header
|
||||
*/
|
||||
protected function setHeader(string $header)
|
||||
{
|
||||
header($header);
|
||||
}
|
||||
|
||||
/**
|
||||
* Prints output directly to the caller
|
||||
* mainly used to override it for tests
|
||||
*
|
||||
* @param string $output
|
||||
*/
|
||||
protected function printOutput(string $output)
|
||||
{
|
||||
echo $output;
|
||||
exit;
|
||||
$this->baseUrl = $baseUrl;
|
||||
$this->twitterUser = $twitterUser;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -125,12 +102,12 @@ class ApiResponse
|
|||
$arr['$user'] = $user_info;
|
||||
$arr['$rss'] = [
|
||||
'alternate' => $user_info['url'],
|
||||
'self' => $this->baseurl . '/' . $this->args->getQueryString(),
|
||||
'base' => $this->baseurl,
|
||||
'self' => $this->baseUrl . '/' . $this->args->getQueryString(),
|
||||
'base' => $this->baseUrl,
|
||||
'updated' => DateTimeFormat::utc(null, DateTimeFormat::API),
|
||||
'atom_updated' => DateTimeFormat::utcNow(DateTimeFormat::ATOM),
|
||||
'language' => $user_info['lang'],
|
||||
'logo' => $this->baseurl . '/images/friendica-32.png',
|
||||
'logo' => $this->baseUrl . '/images/friendica-32.png',
|
||||
];
|
||||
|
||||
return $arr;
|
||||
|
@ -242,7 +219,7 @@ class ApiResponse
|
|||
break;
|
||||
}
|
||||
|
||||
$this->printOutput($return);
|
||||
$this->addContent($return);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -57,9 +57,9 @@ class Activity extends BaseApi
|
|||
} else {
|
||||
$ok = 'ok';
|
||||
}
|
||||
DI::apiResponse()->exit('ok', ['ok' => $ok], $this->parameters['extension'] ?? null);
|
||||
$this->response->exit('ok', ['ok' => $ok], $this->parameters['extension'] ?? null);
|
||||
} else {
|
||||
DI::apiResponse()->error(500, 'Error adding activity', '', $this->parameters['extension'] ?? null);
|
||||
$this->response->error(500, 'Error adding activity', '', $this->parameters['extension'] ?? null);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -42,13 +42,15 @@ class Setseen extends BaseApi
|
|||
// return error if id is zero
|
||||
if (empty($request['id'])) {
|
||||
$answer = ['result' => 'error', 'message' => 'message id not specified'];
|
||||
DI::apiResponse()->exit('direct_messages_setseen', ['$result' => $answer], $this->parameters['extension'] ?? null);
|
||||
$this->response->exit('direct_messages_setseen', ['$result' => $answer], $this->parameters['extension'] ?? null);
|
||||
return;
|
||||
}
|
||||
|
||||
// error message if specified id is not in database
|
||||
if (!DBA::exists('mail', ['id' => $request['id'], 'uid' => $uid])) {
|
||||
$answer = ['result' => 'error', 'message' => 'message id not in database'];
|
||||
DI::apiResponse()->exit('direct_messages_setseen', ['$result' => $answer], $this->parameters['extension'] ?? null);
|
||||
$this->response->exit('direct_messages_setseen', ['$result' => $answer], $this->parameters['extension'] ?? null);
|
||||
return;
|
||||
}
|
||||
|
||||
// update seen indicator
|
||||
|
@ -58,6 +60,6 @@ class Setseen extends BaseApi
|
|||
$answer = ['result' => 'error', 'message' => 'unknown error'];
|
||||
}
|
||||
|
||||
DI::apiResponse()->exit('direct_messages_setseen', ['$result' => $answer], $this->parameters['extension'] ?? null);
|
||||
$this->response->exit('direct_messages_setseen', ['$result' => $answer], $this->parameters['extension'] ?? null);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -70,6 +70,6 @@ class Index extends BaseApi
|
|||
];
|
||||
}
|
||||
|
||||
DI::apiResponse()->exit('events', ['events' => $items], $this->parameters['extension'] ?? null);
|
||||
$this->response->exit('events', ['events' => $items], $this->parameters['extension'] ?? null);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -70,7 +70,7 @@ class Delete extends BaseApi
|
|||
if ($ret) {
|
||||
// return success
|
||||
$success = ['success' => $ret, 'gid' => $request['gid'], 'name' => $request['name'], 'status' => 'deleted', 'wrong users' => []];
|
||||
DI::apiResponse()->exit('group_delete', ['$result' => $success], $parameters['extension'] ?? null);
|
||||
$this->response->exit('group_delete', ['$result' => $success], $parameters['extension'] ?? null);
|
||||
} else {
|
||||
throw new BadRequestException('other API error');
|
||||
}
|
||||
|
|
|
@ -56,6 +56,6 @@ class Notification extends BaseApi
|
|||
$result = false;
|
||||
}
|
||||
|
||||
DI::apiResponse()->exit('notes', ['note' => $result], $this->parameters['extension'] ?? null);
|
||||
$this->response->exit('notes', ['note' => $result], $this->parameters['extension'] ?? null);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -64,7 +64,7 @@ class Delete extends BaseApi
|
|||
Item::deleteForUser($condition, $uid);
|
||||
|
||||
$result = ['result' => 'deleted', 'message' => 'photo with id `' . $request['photo_id'] . '` has been deleted from server.'];
|
||||
DI::apiResponse()->exit('photo_delete', ['$result' => $result], $this->parameters['extension'] ?? null);
|
||||
$this->response->exit('photo_delete', ['$result' => $result], $this->parameters['extension'] ?? null);
|
||||
} else {
|
||||
throw new InternalServerErrorException("unknown error on deleting photo from database table");
|
||||
}
|
||||
|
|
|
@ -67,7 +67,7 @@ class Delete extends BaseApi
|
|||
// return success of deletion or error message
|
||||
if ($result) {
|
||||
$answer = ['result' => 'deleted', 'message' => 'album `' . $request['album'] . '` with all containing photos has been deleted.'];
|
||||
DI::apiResponse()->exit('photoalbum_delete', ['$result' => $answer], $this->parameters['extension'] ?? null);
|
||||
$this->response->exit('photoalbum_delete', ['$result' => $answer], $this->parameters['extension'] ?? null);
|
||||
} else {
|
||||
throw new InternalServerErrorException("unknown error - deleting from database failed");
|
||||
}
|
||||
|
|
|
@ -59,7 +59,7 @@ class Update extends BaseApi
|
|||
// return success of updating or error message
|
||||
if ($result) {
|
||||
$answer = ['result' => 'updated', 'message' => 'album `' . $request['album'] . '` with all containing photos has been renamed to `' . $request['album_new'] . '`.'];
|
||||
DI::apiResponse()->exit('photoalbum_update', ['$result' => $answer], $this->parameters['extension'] ?? null);
|
||||
$this->response->exit('photoalbum_update', ['$result' => $answer], $this->parameters['extension'] ?? null);
|
||||
} else {
|
||||
throw new InternalServerErrorException("unknown error - updating in database failed");
|
||||
}
|
||||
|
|
|
@ -61,7 +61,7 @@ class Show extends BaseApi
|
|||
'profiles' => $profiles
|
||||
];
|
||||
|
||||
DI::apiResponse()->exit('friendica_profiles', ['$result' => $result], $this->parameters['extension'] ?? null);
|
||||
$this->response->exit('friendica_profiles', ['$result' => $result], $this->parameters['extension'] ?? null);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -61,6 +61,6 @@ class Config extends BaseApi
|
|||
],
|
||||
];
|
||||
|
||||
DI::apiResponse()->exit('config', ['config' => $config], $this->parameters['extension'] ?? null);
|
||||
$this->response->exit('config', ['config' => $config], $this->parameters['extension'] ?? null);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -31,6 +31,6 @@ class Version extends BaseApi
|
|||
{
|
||||
protected function rawContent(array $request = [])
|
||||
{
|
||||
DI::apiResponse()->exit('version', ['version' => '0.9.7'], $this->parameters['extension'] ?? null);
|
||||
$this->response->exit('version', ['version' => '0.9.7'], $this->parameters['extension'] ?? null);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -37,6 +37,6 @@ class Test extends BaseApi
|
|||
$ok = 'ok';
|
||||
}
|
||||
|
||||
DI::apiResponse()->exit('ok', ['ok' => $ok], $this->parameters['extension'] ?? null);
|
||||
$this->response->exit('ok', ['ok' => $ok], $this->parameters['extension'] ?? null);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -23,7 +23,6 @@ namespace Friendica\Module\Api\Mastodon\Accounts;
|
|||
|
||||
use Friendica\App\Router;
|
||||
use Friendica\Core\Logger;
|
||||
use Friendica\DI;
|
||||
use Friendica\Module\BaseApi;
|
||||
use Friendica\Util\HTTPInputData;
|
||||
|
||||
|
@ -41,6 +40,6 @@ class UpdateCredentials extends BaseApi
|
|||
|
||||
Logger::info('Patch data', ['data' => $data]);
|
||||
|
||||
DI::apiResponse()->unsupported(Router::PATCH);
|
||||
$this->response->unsupported(Router::PATCH);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -35,7 +35,7 @@ class Filters extends BaseApi
|
|||
{
|
||||
self::checkAllowedScope(self::SCOPE_WRITE);
|
||||
|
||||
DI::apiResponse()->unsupported(Router::POST);
|
||||
$this->response->unsupported(Router::POST);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -25,7 +25,6 @@ use Friendica\App\Router;
|
|||
use Friendica\Core\System;
|
||||
use Friendica\Database\DBA;
|
||||
use Friendica\DI;
|
||||
use Friendica\Module\Api\ApiResponse;
|
||||
use Friendica\Module\BaseApi;
|
||||
|
||||
/**
|
||||
|
@ -37,12 +36,12 @@ class Accounts extends BaseApi
|
|||
{
|
||||
protected function delete()
|
||||
{
|
||||
DI::apiResponse()->unsupported(Router::DELETE);
|
||||
$this->response->unsupported(Router::DELETE);
|
||||
}
|
||||
|
||||
protected function post(array $request = [], array $post = [])
|
||||
{
|
||||
DI::apiResponse()->unsupported(Router::POST);
|
||||
$this->response->unsupported(Router::POST);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -35,7 +35,7 @@ class Markers extends BaseApi
|
|||
{
|
||||
self::checkAllowedScope(self::SCOPE_WRITE);
|
||||
|
||||
DI::apiResponse()->unsupported(Router::POST);
|
||||
$this->response->unsupported(Router::POST);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -26,7 +26,6 @@ use Friendica\Core\System;
|
|||
use Friendica\Database\DBA;
|
||||
use Friendica\DI;
|
||||
use Friendica\Model\Post;
|
||||
use Friendica\Module\Api\ApiResponse;
|
||||
use Friendica\Module\BaseApi;
|
||||
|
||||
/**
|
||||
|
@ -39,7 +38,7 @@ class ScheduledStatuses extends BaseApi
|
|||
self::checkAllowedScope(self::SCOPE_WRITE);
|
||||
$uid = self::getCurrentUserID();
|
||||
|
||||
DI::apiResponse()->unsupported(Router::PUT);
|
||||
$this->response->unsupported(Router::PUT);
|
||||
}
|
||||
|
||||
protected function delete()
|
||||
|
|
|
@ -22,7 +22,6 @@
|
|||
namespace Friendica\Module\Api\Mastodon;
|
||||
|
||||
use Friendica\App\Router;
|
||||
use Friendica\DI;
|
||||
use Friendica\Module\BaseApi;
|
||||
|
||||
/**
|
||||
|
@ -35,7 +34,7 @@ class Unimplemented extends BaseApi
|
|||
*/
|
||||
protected function delete()
|
||||
{
|
||||
DI::apiResponse()->unsupported(Router::DELETE);
|
||||
$this->response->unsupported(Router::DELETE);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -43,7 +42,7 @@ class Unimplemented extends BaseApi
|
|||
*/
|
||||
protected function patch()
|
||||
{
|
||||
DI::apiResponse()->unsupported(Router::PATCH);
|
||||
$this->response->unsupported(Router::PATCH);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -51,7 +50,7 @@ class Unimplemented extends BaseApi
|
|||
*/
|
||||
protected function post(array $request = [], array $post = [])
|
||||
{
|
||||
DI::apiResponse()->unsupported(Router::POST);
|
||||
$this->response->unsupported(Router::POST);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -59,7 +58,7 @@ class Unimplemented extends BaseApi
|
|||
*/
|
||||
public function put()
|
||||
{
|
||||
DI::apiResponse()->unsupported(Router::PUT);
|
||||
$this->response->unsupported(Router::PUT);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -67,6 +66,6 @@ class Unimplemented extends BaseApi
|
|||
*/
|
||||
protected function rawContent(array $request = [])
|
||||
{
|
||||
DI::apiResponse()->unsupported(Router::GET);
|
||||
$this->response->unsupported(Router::GET);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -22,7 +22,6 @@
|
|||
namespace Friendica\Module\Api\Twitter\Account;
|
||||
|
||||
use Friendica\Module\BaseApi;
|
||||
use Friendica\DI;
|
||||
use Friendica\Util\DateTimeFormat;
|
||||
|
||||
/**
|
||||
|
@ -52,6 +51,6 @@ class RateLimitStatus extends BaseApi
|
|||
];
|
||||
}
|
||||
|
||||
DI::apiResponse()->exit('hash', ['hash' => $hash], $this->parameters['extension'] ?? null);
|
||||
$this->response->exit('hash', ['hash' => $hash], $this->parameters['extension'] ?? null);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -27,9 +27,9 @@ use Friendica\Database\DBA;
|
|||
use Friendica\DI;
|
||||
use Friendica\Model\Profile;
|
||||
use Friendica\Model\User;
|
||||
use Friendica\Module\Api\ApiResponse;
|
||||
use Friendica\Module\BaseApi;
|
||||
use Friendica\Model\Contact;
|
||||
use Friendica\Module\Response;
|
||||
use Friendica\Network\HTTPException;
|
||||
use Friendica\Util\Profiler;
|
||||
use Friendica\Util\Strings;
|
||||
|
@ -40,9 +40,9 @@ abstract class ContactEndpoint extends BaseApi
|
|||
const DEFAULT_COUNT = 20;
|
||||
const MAX_COUNT = 200;
|
||||
|
||||
public function __construct(L10n $l10n, App\BaseURL $baseUrl, App\Arguments $args, LoggerInterface $logger, Profiler $profiler, Response $response, array $server, array $parameters = [])
|
||||
public function __construct(App $app, L10n $l10n, App\BaseURL $baseUrl, App\Arguments $args, LoggerInterface $logger, Profiler $profiler, ApiResponse $response, array $server, array $parameters = [])
|
||||
{
|
||||
parent::__construct($l10n, $baseUrl, $args, $logger, $profiler, $response, $server, $parameters);
|
||||
parent::__construct($app, $l10n, $baseUrl, $args, $logger, $profiler, $response, $server, $parameters);
|
||||
|
||||
self::checkAllowedScope(self::SCOPE_READ);
|
||||
}
|
||||
|
|
|
@ -22,7 +22,6 @@
|
|||
namespace Friendica\Module\Api\Twitter;
|
||||
|
||||
use Friendica\Database\DBA;
|
||||
use Friendica\DI;
|
||||
use Friendica\Module\BaseApi;
|
||||
|
||||
/**
|
||||
|
@ -45,6 +44,6 @@ class SavedSearches extends BaseApi
|
|||
|
||||
DBA::close($terms);
|
||||
|
||||
DI::apiResponse()->exit('terms', ['terms' => $result], $this->parameters['extension'] ?? null);
|
||||
$this->response->exit('terms', ['terms' => $result], $this->parameters['extension'] ?? null);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -21,18 +21,23 @@
|
|||
|
||||
namespace Friendica\Module;
|
||||
|
||||
use Friendica\App;
|
||||
use Friendica\BaseModule;
|
||||
use Friendica\Core\L10n;
|
||||
use Friendica\Core\Logger;
|
||||
use Friendica\Core\System;
|
||||
use Friendica\DI;
|
||||
use Friendica\Model\Contact;
|
||||
use Friendica\Model\Post;
|
||||
use Friendica\Model\User;
|
||||
use Friendica\Module\Api\ApiResponse;
|
||||
use Friendica\Network\HTTPException;
|
||||
use Friendica\Security\BasicAuth;
|
||||
use Friendica\Security\OAuth;
|
||||
use Friendica\Util\DateTimeFormat;
|
||||
use Friendica\Util\HTTPInputData;
|
||||
use Friendica\Util\Profiler;
|
||||
use Psr\Log\LoggerInterface;
|
||||
|
||||
class BaseApi extends BaseModule
|
||||
{
|
||||
|
@ -53,12 +58,23 @@ class BaseApi extends BaseModule
|
|||
*/
|
||||
protected static $request = [];
|
||||
|
||||
/** @var App */
|
||||
protected $app;
|
||||
|
||||
/** @var ApiResponse */
|
||||
protected $response;
|
||||
|
||||
public function __construct(App $app, L10n $l10n, App\BaseURL $baseUrl, App\Arguments $args, LoggerInterface $logger, Profiler $profiler, ApiResponse $response, array $server, array $parameters = [])
|
||||
{
|
||||
parent::__construct($l10n, $baseUrl, $args, $logger, $profiler, $response, $server, $parameters);
|
||||
}
|
||||
|
||||
protected function delete()
|
||||
{
|
||||
self::checkAllowedScope(self::SCOPE_WRITE);
|
||||
|
||||
if (!DI::app()->isLoggedIn()) {
|
||||
throw new HTTPException\ForbiddenException(DI::l10n()->t('Permission denied.'));
|
||||
if (!$this->app->isLoggedIn()) {
|
||||
throw new HTTPException\ForbiddenException($this->t('Permission denied.'));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -66,8 +82,8 @@ class BaseApi extends BaseModule
|
|||
{
|
||||
self::checkAllowedScope(self::SCOPE_WRITE);
|
||||
|
||||
if (!DI::app()->isLoggedIn()) {
|
||||
throw new HTTPException\ForbiddenException(DI::l10n()->t('Permission denied.'));
|
||||
if (!$this->app->isLoggedIn()) {
|
||||
throw new HTTPException\ForbiddenException($this->t('Permission denied.'));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -75,8 +91,8 @@ class BaseApi extends BaseModule
|
|||
{
|
||||
self::checkAllowedScope(self::SCOPE_WRITE);
|
||||
|
||||
if (!DI::app()->isLoggedIn()) {
|
||||
throw new HTTPException\ForbiddenException(DI::l10n()->t('Permission denied.'));
|
||||
if (!$this->app->isLoggedIn()) {
|
||||
throw new HTTPException\ForbiddenException($this->t('Permission denied.'));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -84,8 +100,8 @@ class BaseApi extends BaseModule
|
|||
{
|
||||
self::checkAllowedScope(self::SCOPE_WRITE);
|
||||
|
||||
if (!DI::app()->isLoggedIn()) {
|
||||
throw new HTTPException\ForbiddenException(DI::l10n()->t('Permission denied.'));
|
||||
if (!$this->app->isLoggedIn()) {
|
||||
throw new HTTPException\ForbiddenException($this->t('Permission denied.'));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -22,6 +22,7 @@
|
|||
namespace Friendica\Module\HTTPException;
|
||||
|
||||
use Friendica\BaseModule;
|
||||
use Friendica\Capabilities\IRespondToRequests;
|
||||
use Friendica\DI;
|
||||
use Friendica\Network\HTTPException;
|
||||
|
||||
|
@ -32,7 +33,7 @@ class PageNotFound extends BaseModule
|
|||
throw new HTTPException\NotFoundException(DI::l10n()->t('Page not found.'));
|
||||
}
|
||||
|
||||
public function run(array $post = [], array $request = []): string
|
||||
public function run(array $post = [], array $request = []): IRespondToRequests
|
||||
{
|
||||
/* The URL provided does not resolve to a valid module.
|
||||
*
|
||||
|
|
|
@ -21,11 +21,15 @@
|
|||
|
||||
namespace Friendica\Module;
|
||||
|
||||
use Friendica\App;
|
||||
use Friendica\BaseModule;
|
||||
use Friendica\Capabilities\IRespondToRequests;
|
||||
use Friendica\Core\Addon;
|
||||
use Friendica\Core\System;
|
||||
use Friendica\DI;
|
||||
use Friendica\Core\Config\Capability\IManageConfigValues;
|
||||
use Friendica\Core\L10n;
|
||||
use Friendica\Model\Nodeinfo;
|
||||
use Friendica\Util\Profiler;
|
||||
use Psr\Log\LoggerInterface;
|
||||
|
||||
/**
|
||||
* Version 1.0 of Nodeinfo, a standardized way of exposing metadata about a server running one of the distributed social networks.
|
||||
|
@ -33,10 +37,18 @@ use Friendica\Model\Nodeinfo;
|
|||
*/
|
||||
class NodeInfo110 extends BaseModule
|
||||
{
|
||||
/** @var IManageConfigValues */
|
||||
protected $config;
|
||||
|
||||
public function __construct(L10n $l10n, App\BaseURL $baseUrl, App\Arguments $args, LoggerInterface $logger, Profiler $profiler, Response $response, IManageConfigValues $config, array $server, array $parameters = [])
|
||||
{
|
||||
parent::__construct($l10n, $baseUrl, $args, $logger, $profiler, $response, $server, $parameters);
|
||||
|
||||
$this->config = $config;
|
||||
}
|
||||
|
||||
protected function rawContent(array $request = [])
|
||||
{
|
||||
$config = DI::config();
|
||||
|
||||
$nodeinfo = [
|
||||
'version' => '1.0',
|
||||
'software' => [
|
||||
|
@ -53,19 +65,19 @@ class NodeInfo110 extends BaseModule
|
|||
],
|
||||
'services' => [],
|
||||
'usage' => [],
|
||||
'openRegistrations' => intval($config->get('config', 'register_policy')) !== Register::CLOSED,
|
||||
'openRegistrations' => intval($this->config->get('config', 'register_policy')) !== Register::CLOSED,
|
||||
'metadata' => [
|
||||
'nodeName' => $config->get('config', 'sitename'),
|
||||
'nodeName' => $this->config->get('config', 'sitename'),
|
||||
],
|
||||
];
|
||||
|
||||
if (!empty($config->get('system', 'diaspora_enabled'))) {
|
||||
$nodeinfo['protocols']['inbound'][] = 'diaspora';
|
||||
if (!empty($this->config->get('system', 'diaspora_enabled'))) {
|
||||
$nodeinfo['protocols']['inbound'][] = 'diaspora';
|
||||
$nodeinfo['protocols']['outbound'][] = 'diaspora';
|
||||
}
|
||||
|
||||
if (empty($config->get('system', 'ostatus_disabled'))) {
|
||||
$nodeinfo['protocols']['inbound'][] = 'gnusocial';
|
||||
if (empty($this->config->get('system', 'ostatus_disabled'))) {
|
||||
$nodeinfo['protocols']['inbound'][] = 'gnusocial';
|
||||
$nodeinfo['protocols']['outbound'][] = 'gnusocial';
|
||||
}
|
||||
|
||||
|
@ -73,10 +85,10 @@ class NodeInfo110 extends BaseModule
|
|||
|
||||
$nodeinfo['services'] = Nodeinfo::getServices();
|
||||
|
||||
$nodeinfo['metadata']['protocols'] = $nodeinfo['protocols'];
|
||||
$nodeinfo['metadata']['protocols'] = $nodeinfo['protocols'];
|
||||
$nodeinfo['metadata']['protocols']['outbound'][] = 'atom1.0';
|
||||
$nodeinfo['metadata']['protocols']['inbound'][] = 'atom1.0';
|
||||
$nodeinfo['metadata']['protocols']['inbound'][] = 'rss2.0';
|
||||
$nodeinfo['metadata']['protocols']['inbound'][] = 'atom1.0';
|
||||
$nodeinfo['metadata']['protocols']['inbound'][] = 'rss2.0';
|
||||
|
||||
$nodeinfo['metadata']['services'] = $nodeinfo['services'];
|
||||
|
||||
|
@ -84,8 +96,9 @@ class NodeInfo110 extends BaseModule
|
|||
$nodeinfo['metadata']['services']['inbound'][] = 'twitter';
|
||||
}
|
||||
|
||||
$nodeinfo['metadata']['explicitContent'] = $config->get('system', 'explicit_content', false) == true;
|
||||
$nodeinfo['metadata']['explicitContent'] = $this->config->get('system', 'explicit_content', false) == true;
|
||||
|
||||
System::jsonExit($nodeinfo, 'application/json; charset=utf-8', JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES);
|
||||
$this->response->setType(IRespondToRequests::TYPE_JSON);
|
||||
$this->response->addContent(json_encode($nodeinfo, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -21,11 +21,15 @@
|
|||
|
||||
namespace Friendica\Module;
|
||||
|
||||
use Friendica\App;
|
||||
use Friendica\BaseModule;
|
||||
use Friendica\Capabilities\IRespondToRequests;
|
||||
use Friendica\Core\Addon;
|
||||
use Friendica\Core\System;
|
||||
use Friendica\DI;
|
||||
use Friendica\Core\Config\Capability\IManageConfigValues;
|
||||
use Friendica\Core\L10n;
|
||||
use Friendica\Model\Nodeinfo;
|
||||
use Friendica\Util\Profiler;
|
||||
use Psr\Log\LoggerInterface;
|
||||
|
||||
/**
|
||||
* Version 2.0 of Nodeinfo, a standardized way of exposing metadata about a server running one of the distributed social networks.
|
||||
|
@ -33,30 +37,38 @@ use Friendica\Model\Nodeinfo;
|
|||
*/
|
||||
class NodeInfo120 extends BaseModule
|
||||
{
|
||||
/** @var IManageConfigValues */
|
||||
protected $config;
|
||||
|
||||
public function __construct(L10n $l10n, App\BaseURL $baseUrl, App\Arguments $args, LoggerInterface $logger, Profiler $profiler, Response $response, IManageConfigValues $config, array $server, array $parameters = [])
|
||||
{
|
||||
parent::__construct($l10n, $baseUrl, $args, $logger, $profiler, $response, $server, $parameters);
|
||||
|
||||
$this->config = $config;
|
||||
}
|
||||
|
||||
protected function rawContent(array $request = [])
|
||||
{
|
||||
$config = DI::config();
|
||||
|
||||
$nodeinfo = [
|
||||
'version' => '2.0',
|
||||
'software' => [
|
||||
'version' => '2.0',
|
||||
'software' => [
|
||||
'name' => 'friendica',
|
||||
'version' => FRIENDICA_VERSION . '-' . DB_UPDATE_VERSION,
|
||||
],
|
||||
'protocols' => ['dfrn', 'activitypub'],
|
||||
'services' => [],
|
||||
'usage' => [],
|
||||
'openRegistrations' => intval($config->get('config', 'register_policy')) !== Register::CLOSED,
|
||||
'openRegistrations' => intval($this->config->get('config', 'register_policy')) !== Register::CLOSED,
|
||||
'metadata' => [
|
||||
'nodeName' => $config->get('config', 'sitename'),
|
||||
'nodeName' => $this->config->get('config', 'sitename'),
|
||||
],
|
||||
];
|
||||
|
||||
if (!empty($config->get('system', 'diaspora_enabled'))) {
|
||||
if (!empty($this->config->get('system', 'diaspora_enabled'))) {
|
||||
$nodeinfo['protocols'][] = 'diaspora';
|
||||
}
|
||||
|
||||
if (empty($config->get('system', 'ostatus_disabled'))) {
|
||||
if (empty($this->config->get('system', 'ostatus_disabled'))) {
|
||||
$nodeinfo['protocols'][] = 'ostatus';
|
||||
}
|
||||
|
||||
|
@ -72,12 +84,13 @@ class NodeInfo120 extends BaseModule
|
|||
$nodeinfo['services']['inbound'][] = 'rss2.0';
|
||||
$nodeinfo['services']['outbound'][] = 'atom1.0';
|
||||
|
||||
if (function_exists('imap_open') && !$config->get('system', 'imap_disabled')) {
|
||||
if (function_exists('imap_open') && !$this->config->get('system', 'imap_disabled')) {
|
||||
$nodeinfo['services']['inbound'][] = 'imap';
|
||||
}
|
||||
|
||||
$nodeinfo['metadata']['explicitContent'] = $config->get('system', 'explicit_content', false) == true;
|
||||
$nodeinfo['metadata']['explicitContent'] = $this->config->get('system', 'explicit_content', false) == true;
|
||||
|
||||
System::jsonExit($nodeinfo, 'application/json; charset=utf-8', JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES);
|
||||
$this->response->setType(IRespondToRequests::TYPE_JSON, 'application/json; charset=utf-8');
|
||||
$this->response->addContent(json_encode($nodeinfo, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -21,11 +21,15 @@
|
|||
|
||||
namespace Friendica\Module;
|
||||
|
||||
use Friendica\App;
|
||||
use Friendica\BaseModule;
|
||||
use Friendica\Core\Addon;
|
||||
use Friendica\Core\Config\Capability\IManageConfigValues;
|
||||
use Friendica\Core\L10n;
|
||||
use Friendica\Core\System;
|
||||
use Friendica\DI;
|
||||
use Friendica\Model\Nodeinfo;
|
||||
use Friendica\Util\Profiler;
|
||||
use Psr\Log\LoggerInterface;
|
||||
|
||||
/**
|
||||
* Version 1.0 of Nodeinfo 2, a sStandardized way of exposing metadata about a server running one of the distributed social networks.
|
||||
|
@ -33,30 +37,38 @@ use Friendica\Model\Nodeinfo;
|
|||
*/
|
||||
class NodeInfo210 extends BaseModule
|
||||
{
|
||||
/** @var IManageConfigValues */
|
||||
protected $config;
|
||||
|
||||
public function __construct(L10n $l10n, App\BaseURL $baseUrl, App\Arguments $args, LoggerInterface $logger, Profiler $profiler, Response $response, IManageConfigValues $config, array $server, array $parameters = [])
|
||||
{
|
||||
parent::__construct($l10n, $baseUrl, $args, $logger, $profiler, $response, $server, $parameters);
|
||||
|
||||
$this->config = $config;
|
||||
}
|
||||
|
||||
protected function rawContent(array $request = [])
|
||||
{
|
||||
$config = DI::config();
|
||||
|
||||
$nodeinfo = [
|
||||
'version' => '1.0',
|
||||
'server' => [
|
||||
'baseUrl' => DI::baseUrl()->get(),
|
||||
'name' => $config->get('config', 'sitename'),
|
||||
'version' => '1.0',
|
||||
'server' => [
|
||||
'baseUrl' => $this->baseUrl->get(),
|
||||
'name' => $this->config->get('config', 'sitename'),
|
||||
'software' => 'friendica',
|
||||
'version' => FRIENDICA_VERSION . '-' . DB_UPDATE_VERSION,
|
||||
],
|
||||
'organization' => Nodeinfo::getOrganization($config),
|
||||
'organization' => Nodeinfo::getOrganization($this->config),
|
||||
'protocols' => ['dfrn', 'activitypub'],
|
||||
'services' => [],
|
||||
'openRegistrations' => intval($config->get('config', 'register_policy')) !== Register::CLOSED,
|
||||
'openRegistrations' => intval($this->config->get('config', 'register_policy')) !== Register::CLOSED,
|
||||
'usage' => [],
|
||||
];
|
||||
|
||||
if (!empty($config->get('system', 'diaspora_enabled'))) {
|
||||
if (!empty($this->config->get('system', 'diaspora_enabled'))) {
|
||||
$nodeinfo['protocols'][] = 'diaspora';
|
||||
}
|
||||
|
||||
if (empty($config->get('system', 'ostatus_disabled'))) {
|
||||
if (empty($this->config->get('system', 'ostatus_disabled'))) {
|
||||
$nodeinfo['protocols'][] = 'ostatus';
|
||||
}
|
||||
|
||||
|
@ -72,7 +84,7 @@ class NodeInfo210 extends BaseModule
|
|||
$nodeinfo['services']['inbound'][] = 'rss2.0';
|
||||
$nodeinfo['services']['outbound'][] = 'atom1.0';
|
||||
|
||||
if (function_exists('imap_open') && !$config->get('system', 'imap_disabled')) {
|
||||
if (function_exists('imap_open') && !$this->config->get('system', 'imap_disabled')) {
|
||||
$nodeinfo['services']['inbound'][] = 'imap';
|
||||
}
|
||||
|
||||
|
|
|
@ -2,14 +2,14 @@
|
|||
|
||||
namespace Friendica\Module;
|
||||
|
||||
use Friendica\Capabilities\ICanReadAndWriteToResponds;
|
||||
use Friendica\Capabilities\ICanCreateResponses;
|
||||
use Friendica\Capabilities\IRespondToRequests;
|
||||
use Friendica\Network\HTTPException\InternalServerErrorException;
|
||||
|
||||
class Response implements ICanReadAndWriteToResponds
|
||||
class Response implements ICanCreateResponses
|
||||
{
|
||||
/**
|
||||
* @var string[][]
|
||||
* @var string[]
|
||||
*/
|
||||
protected $headers = [];
|
||||
/**
|
||||
|
@ -19,20 +19,30 @@ class Response implements ICanReadAndWriteToResponds
|
|||
/**
|
||||
* @var string
|
||||
*/
|
||||
protected $type = IRespondToRequests::TYPE_CONTENT;
|
||||
protected $type = IRespondToRequests::TYPE_HTML;
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function addHeader(string $key, string $value)
|
||||
public function setHeader(?string $header = null, ?string $key = null): void
|
||||
{
|
||||
$this->headers[$key][] = $value;
|
||||
if (!isset($header) && !empty($key)) {
|
||||
unset($this->headers[$key]);
|
||||
}
|
||||
|
||||
if (isset($header)) {
|
||||
if (empty($key)) {
|
||||
$this->headers[] = $header;
|
||||
} else {
|
||||
$this->headers[$key] = $header;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function addContent(string $content)
|
||||
public function addContent($content): void
|
||||
{
|
||||
$this->content .= $content;
|
||||
}
|
||||
|
@ -48,7 +58,7 @@ class Response implements ICanReadAndWriteToResponds
|
|||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function getContent(): string
|
||||
public function getContent()
|
||||
{
|
||||
return $this->content;
|
||||
}
|
||||
|
@ -56,19 +66,31 @@ class Response implements ICanReadAndWriteToResponds
|
|||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function setType(string $type)
|
||||
public function setType(string $type, ?string $content_type = null): void
|
||||
{
|
||||
if (!in_array($type, IRespondToRequests::ALLOWED_TYPES)) {
|
||||
throw new InternalServerErrorException('wrong type');
|
||||
}
|
||||
|
||||
switch ($type) {
|
||||
case static::TYPE_JSON:
|
||||
$content_type = $content_type ?? 'application/json';
|
||||
break;
|
||||
case static::TYPE_XML:
|
||||
$content_type = $content_type ?? 'text/xml';
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
$this->setHeader($content_type, 'Content-type');
|
||||
|
||||
$this->type = $type;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function getTyp(): string
|
||||
public function getType(): string
|
||||
{
|
||||
return $this->type;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue