Merge pull request #11005 from nupplaphil/feat/module_di

Introduce PSR-7 `ResponseInterface` for Modules executions
This commit is contained in:
Hypolite Petovan 2021-11-27 09:41:23 -05:00 committed by GitHub
commit 5aad46c7fb
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
289 changed files with 1663 additions and 1901 deletions

View file

@ -391,6 +391,7 @@ function save_media_to_database($mediatype, $media, $type, $album, $allow_cid, $
return prepare_photo_data($type, false, $resource_id, $uid);
} else {
throw new InternalServerErrorException("image upload failed");
DI::page()->exit(DI::apiResponse());
}
}

View file

@ -41,11 +41,9 @@ $a = \Friendica\DI::app();
\Friendica\DI::mode()->setExecutor(\Friendica\App\Mode::INDEX);
$a->runFrontend(
$dice->create(\Friendica\App\ModuleController::class),
$dice->create(\Friendica\App\Router::class),
$dice->create(\Friendica\Core\PConfig\Capability\IManagePersonalConfigValues::class),
$dice->create(\Friendica\Security\Authentication::class),
$dice->create(\Friendica\App\Page::class),
$dice,
$start_time
);

View file

@ -47,7 +47,7 @@ function settings_init(App $a)
return;
}
BaseSettings::content();
BaseSettings::createAside();
}
function settings_post(App $a)
@ -408,7 +408,7 @@ function settings_content(App $a)
if (!empty($_SESSION['submanage'])) {
notice(DI::l10n()->t('Permission denied.'));
return;
return '';
}
if ((DI::args()->getArgc() > 1) && (DI::args()->getArgv()[1] === 'oauth')) {
@ -417,7 +417,7 @@ function settings_content(App $a)
DBA::delete('application-token', ['application-id' => DI::args()->getArgv()[3], 'uid' => local_user()]);
DI::baseUrl()->redirect('settings/oauth/', true);
return;
return '';
}
$applications = DBA::selectToArray('application-view', ['id', 'uid', 'name', 'website', 'scopes', 'created_at'], ['uid' => local_user()]);
@ -577,7 +577,7 @@ function settings_content(App $a)
$profile = DBA::selectFirst('profile', [], ['uid' => local_user()]);
if (!DBA::isResult($profile)) {
notice(DI::l10n()->t('Unable to find your profile. Please contact your admin.'));
return;
return '';
}
$user = User::getById($a->getLoggedInUserId());

View file

@ -21,11 +21,10 @@
namespace Friendica;
use Dice\Dice;
use Exception;
use Friendica\App\Arguments;
use Friendica\App\BaseURL;
use Friendica\App\ModuleController;
use Friendica\Capabilities\ICanCreateResponses;
use Friendica\Core\Config\Factory\Config;
use Friendica\Module\Maintenance;
use Friendica\Security\Authentication;
@ -44,6 +43,7 @@ use Friendica\Util\DateTimeFormat;
use Friendica\Util\HTTPSignature;
use Friendica\Util\Profiler;
use Friendica\Util\Strings;
use GuzzleHttp\Psr7\Response;
use Psr\Log\LoggerInterface;
/**
@ -118,11 +118,6 @@ class App
*/
private $args;
/**
* @var Core\System The system methods
*/
private $system;
/**
* @var IManagePersonalConfigValues
*/
@ -328,10 +323,9 @@ class App
* @param Profiler $profiler The profiler of this application
* @param L10n $l10n The translator instance
* @param App\Arguments $args The Friendica Arguments of the call
* @param Core\System $system The system methods
* @param IManagePersonalConfigValues $pConfig Personal configuration
*/
public function __construct(Database $database, IManageConfigValues $config, App\Mode $mode, BaseURL $baseURL, LoggerInterface $logger, Profiler $profiler, L10n $l10n, Arguments $args, Core\System $system, IManagePersonalConfigValues $pConfig)
public function __construct(Database $database, IManageConfigValues $config, App\Mode $mode, BaseURL $baseURL, LoggerInterface $logger, Profiler $profiler, L10n $l10n, Arguments $args, IManagePersonalConfigValues $pConfig)
{
$this->database = $database;
$this->config = $config;
@ -341,7 +335,6 @@ class App
$this->logger = $logger;
$this->l10n = $l10n;
$this->args = $args;
$this->system = $system;
$this->pConfig = $pConfig;
$this->load();
@ -567,7 +560,6 @@ class App
*
* This probably should change to limit the size of this monster method.
*
* @param App\ModuleController $module The determined module
* @param App\Router $router
* @param IManagePersonalConfigValues $pconfig
* @param Authentication $auth The Authentication backend of the node
@ -576,12 +568,12 @@ class App
* @throws HTTPException\InternalServerErrorException
* @throws \ImagickException
*/
public function runFrontend(App\ModuleController $module, App\Router $router, IManagePersonalConfigValues $pconfig, Authentication $auth, App\Page $page, Dice $dice, float $start_time)
public function runFrontend(App\Router $router, IManagePersonalConfigValues $pconfig, Authentication $auth, App\Page $page, float $start_time)
{
$this->profiler->set($start_time, 'start');
$this->profiler->set(microtime(true), 'classinit');
$moduleName = $module->getName();
$moduleName = $this->args->getModuleName();
try {
// Missing DB connection: ERROR
@ -611,7 +603,7 @@ class App
// Only continue when the given profile link seems valid
// Valid profile links contain a path with "/profile/" and no query parameters
if ((parse_url($_GET['zrl'], PHP_URL_QUERY) == "") &&
strstr(parse_url($_GET['zrl'], PHP_URL_PATH), "/profile/")) {
strstr(parse_url($_GET['zrl'], PHP_URL_PATH), "/profile/")) {
if (Core\Session::get('visitor_home') != $_GET["zrl"]) {
Core\Session::set('my_url', $_GET['zrl']);
Core\Session::set('authenticated', 0);
@ -703,20 +695,23 @@ class App
$page['page_title'] = $moduleName;
if (!$this->mode->isInstall() && !$this->mode->has(App\Mode::MAINTENANCEDISABLED)) {
$module = new ModuleController('maintenance', new Maintenance($this->l10n));
$module = $router->getModule(Maintenance::class);
} else {
// determine the module class and save it to the module instance
// @todo there's an implicit dependency due SESSION::start(), so it has to be called here (yet)
$module = $module->determineClass($this->args, $router, $this->config, $dice);
$module = $router->getModule();
}
// Let the module run it's internal process (init, get, post, ...)
$module->run($this->l10n, $this->baseURL, $this->logger, $this->profiler, $_SERVER, $_POST);
$response = $module->run($_POST, $_REQUEST);
if ($response->getHeaderLine(ICanCreateResponses::X_HEADER) === ICanCreateResponses::TYPE_HTML) {
$page->run($this, $this->baseURL, $this->args, $this->mode, $response, $this->l10n, $this->profiler, $this->config, $pconfig);
} else {
$page->exit($response);
}
} catch (HTTPException $e) {
(new ModuleHTTPException())->rawContent($e);
}
$page->run($this, $this->baseURL, $this->mode, $module, $this->l10n, $this->profiler, $this->config, $pconfig);
}
/**

View file

@ -30,6 +30,8 @@ namespace Friendica\App;
*/
class Arguments
{
const DEFAULT_MODULE = 'home';
/**
* @var string The complete query string
*/
@ -38,6 +40,10 @@ class Arguments
* @var string The current Friendica command
*/
private $command;
/**
* @var string The name of the current module
*/
private $moduleName;
/**
* @var array The arguments of the current execution
*/
@ -47,10 +53,11 @@ class Arguments
*/
private $argc;
public function __construct(string $queryString = '', string $command = '', array $argv = [], int $argc = 0)
public function __construct(string $queryString = '', string $command = '', string $moduleName = '', array $argv = [], int $argc = 0)
{
$this->queryString = $queryString;
$this->command = $command;
$this->moduleName = $moduleName;
$this->argv = $argv;
$this->argc = $argc;
}
@ -71,6 +78,14 @@ class Arguments
return $this->command;
}
/**
* @return string The module name based on the arguments
*/
public function getModuleName(): string
{
return $this->moduleName;
}
/**
* @return array All arguments of this call
*/
@ -172,6 +187,18 @@ class Arguments
$queryString = $command . ($queryParameters ? '?' . http_build_query($queryParameters) : '');
return new Arguments($queryString, $command, $argv, $argc);
if ($argc > 0) {
$module = str_replace('.', '_', $argv[0]);
$module = str_replace('-', '_', $module);
} else {
$module = self::DEFAULT_MODULE;
}
// Compatibility with the Firefox App
if (($module == "users") && ($command == "users/sign_in")) {
$module = "login";
}
return new Arguments($queryString, $command, $module, $argv, $argc);
}
}

View file

@ -46,6 +46,38 @@ class Mode
const BACKEND_CONTENT_TYPES = ['application/jrd+json', 'text/xml',
'application/rss+xml', 'application/atom+xml', 'application/activity+json'];
/**
* A list of modules, which are backend methods
*
* @var array
*/
const BACKEND_MODULES = [
'_well_known',
'api',
'dfrn_notify',
'feed',
'fetch',
'followers',
'following',
'hcard',
'hostxrd',
'inbox',
'manifest',
'nodeinfo',
'noscrape',
'objects',
'outbox',
'poco',
'post',
'pubsub',
'pubsubhubbub',
'receive',
'rsd_xml',
'salmon',
'statistics_json',
'xrd',
];
/***
* @var int The mode of this Application
*
@ -140,13 +172,13 @@ class Mode
* Checks if the site is called via a backend process
*
* @param bool $isBackend True, if the call is from a backend script (daemon, worker, ...)
* @param ModuleController $module The pre-loaded module (just name, not class!)
* @param array $server The $_SERVER variable
* @param Arguments $args The Friendica App arguments
* @param MobileDetect $mobileDetect The mobile detection library
*
* @return Mode returns the determined mode
*/
public function determineRunMode(bool $isBackend, ModuleController $module, array $server, MobileDetect $mobileDetect)
public function determineRunMode(bool $isBackend, array $server, Arguments $args, MobileDetect $mobileDetect)
{
foreach (self::BACKEND_CONTENT_TYPES as $type) {
if (strpos(strtolower($server['HTTP_ACCEPT'] ?? ''), $type) !== false) {
@ -154,7 +186,7 @@ class Mode
}
}
$isBackend = $isBackend || $module->isBackend();
$isBackend = $isBackend || in_array($args->getModuleName(), static::BACKEND_MODULES);
$isMobile = $mobileDetect->isMobile();
$isTablet = $mobileDetect->isTablet();
$isAjax = strtolower($server['HTTP_X_REQUESTED_WITH'] ?? '') == 'xmlhttprequest';

View file

@ -1,321 +0,0 @@
<?php
/**
* @copyright Copyright (C) 2010-2021, the Friendica project
*
* @license GNU AGPL version 3 or any later version
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*
*/
namespace Friendica\App;
use Dice\Dice;
use Friendica\App;
use Friendica\Capabilities\ICanHandleRequests;
use Friendica\Core;
use Friendica\Core\Config\Capability\IManageConfigValues;
use Friendica\LegacyModule;
use Friendica\Module\Home;
use Friendica\Module\HTTPException\MethodNotAllowed;
use Friendica\Module\HTTPException\PageNotFound;
use Friendica\Network\HTTPException\MethodNotAllowedException;
use Friendica\Network\HTTPException\NoContentException;
use Friendica\Network\HTTPException\NotFoundException;
use Friendica\Util\Profiler;
use Psr\Log\LoggerInterface;
/**
* Holds the common context of the current, loaded module
*/
class ModuleController
{
const DEFAULT = 'home';
const DEFAULT_CLASS = Home::class;
/**
* A list of modules, which are backend methods
*
* @var array
*/
const BACKEND_MODULES = [
'_well_known',
'api',
'dfrn_notify',
'feed',
'fetch',
'followers',
'following',
'hcard',
'hostxrd',
'inbox',
'manifest',
'nodeinfo',
'noscrape',
'objects',
'outbox',
'poco',
'post',
'pubsub',
'pubsubhubbub',
'receive',
'rsd_xml',
'salmon',
'statistics_json',
'xrd',
];
/**
* @var string The module name
*/
private $moduleName;
/**
* @var ?ICanHandleRequests The module object
*/
private $module;
/**
* @var bool true, if the module is a backend module
*/
private $isBackend;
/**
* @var bool true, if the loaded addon is private, so we have to print out not allowed
*/
private $printNotAllowedAddon;
/**
* @return string
*/
public function getName()
{
return $this->moduleName;
}
/**
* @return ?ICanHandleRequests The base module object
*/
public function getModule(): ?ICanHandleRequests
{
return $this->module;
}
/**
* @return bool True, if the current module is a backend module
* @see ModuleController::BACKEND_MODULES for a list
*/
public function isBackend()
{
return $this->isBackend;
}
public function __construct(string $moduleName = self::DEFAULT, ?ICanHandleRequests $module = null, bool $isBackend = false, bool $printNotAllowedAddon = false)
{
$this->moduleName = $moduleName;
$this->module = $module;
$this->isBackend = $isBackend;
$this->printNotAllowedAddon = $printNotAllowedAddon;
}
/**
* Determines the current module based on the App arguments and the server variable
*
* @param Arguments $args The Friendica arguments
*
* @return ModuleController The module with the determined module
*/
public function determineName(Arguments $args)
{
if ($args->getArgc() > 0) {
$module = str_replace('.', '_', $args->get(0));
$module = str_replace('-', '_', $module);
} else {
$module = self::DEFAULT;
}
// Compatibility with the Firefox App
if (($module == "users") && ($args->getCommand() == "users/sign_in")) {
$module = "login";
}
$isBackend = in_array($module, ModuleController::BACKEND_MODULES);
return new ModuleController($module, null, $isBackend, $this->printNotAllowedAddon);
}
/**
* Determine the class of the current module
*
* @param Arguments $args The Friendica execution arguments
* @param Router $router The Friendica routing instance
* @param IManageConfigValues $config The Friendica Configuration
* @param Dice $dice The Dependency Injection container
*
* @return ModuleController The determined module of this call
*
* @throws \Exception
*/
public function determineClass(Arguments $args, Router $router, IManageConfigValues $config, Dice $dice)
{
$printNotAllowedAddon = false;
$module_class = null;
$module_parameters = [];
/**
* ROUTING
*
* From the request URL, routing consists of obtaining the name of a BaseModule-extending class of which the
* post() and/or content() static methods can be respectively called to produce a data change or an output.
**/
try {
$module_class = $router->getModuleClass($args->getCommand());
$module_parameters[] = $router->getModuleParameters();
} catch (MethodNotAllowedException $e) {
$module_class = MethodNotAllowed::class;
} catch (NotFoundException $e) {
// Then we try addon-provided modules that we wrap in the LegacyModule class
if (Core\Addon::isEnabled($this->moduleName) && file_exists("addon/{$this->moduleName}/{$this->moduleName}.php")) {
//Check if module is an app and if public access to apps is allowed or not
$privateapps = $config->get('config', 'private_addons', false);
if ((!local_user()) && Core\Hook::isAddonApp($this->moduleName) && $privateapps) {
$printNotAllowedAddon = true;
} else {
include_once "addon/{$this->moduleName}/{$this->moduleName}.php";
if (function_exists($this->moduleName . '_module')) {
$module_parameters[] = "addon/{$this->moduleName}/{$this->moduleName}.php";
$module_class = LegacyModule::class;
}
}
}
/* Finally, we look for a 'standard' program module in the 'mod' directory
* We emulate a Module class through the LegacyModule class
*/
if (!$module_class && file_exists("mod/{$this->moduleName}.php")) {
$module_parameters[] = "mod/{$this->moduleName}.php";
$module_class = LegacyModule::class;
}
$module_class = $module_class ?: PageNotFound::class;
}
/** @var ICanHandleRequests $module */
$module = $dice->create($module_class, $module_parameters);
return new ModuleController($this->moduleName, $module, $this->isBackend, $printNotAllowedAddon);
}
/**
* Run the determined module class and calls all hooks applied to
*
* @param \Friendica\Core\L10n $l10n The L10n instance
* @param App\BaseURL $baseUrl The Friendica Base URL
* @param LoggerInterface $logger The Friendica logger
* @param array $server The $_SERVER variable
* @param array $post The $_POST variables
*
* @throws \Friendica\Network\HTTPException\InternalServerErrorException
*/
public function run(Core\L10n $l10n, App\BaseURL $baseUrl, LoggerInterface $logger, Profiler $profiler, array $server, array $post)
{
if ($this->printNotAllowedAddon) {
notice($l10n->t("You must be logged in to use addons. "));
}
/* The URL provided does not resolve to a valid module.
*
* On Dreamhost sites, quite often things go wrong for no apparent reason and they send us to '/internal_error.html'.
* We don't like doing this, but as it occasionally accounts for 10-20% or more of all site traffic -
* we are going to trap this and redirect back to the requested page. As long as you don't have a critical error on your page
* this will often succeed and eventually do the right thing.
*
* Otherwise we are going to emit a 404 not found.
*/
if ($this->module === PageNotFound::class) {
$queryString = $server['QUERY_STRING'];
// Stupid browser tried to pre-fetch our Javascript img template. Don't log the event or return anything - just quietly exit.
if (!empty($queryString) && preg_match('/{[0-9]}/', $queryString) !== 0) {
exit();
}
if (!empty($queryString) && ($queryString === 'q=internal_error.html') && isset($dreamhost_error_hack)) {
$logger->info('index.php: dreamhost_error_hack invoked.', ['Original URI' => $server['REQUEST_URI']]);
$baseUrl->redirect($server['REQUEST_URI']);
}
$logger->debug('index.php: page not found.', ['request_uri' => $server['REQUEST_URI'], 'address' => $server['REMOTE_ADDR'], 'query' => $server['QUERY_STRING']]);
}
// @see https://github.com/tootsuite/mastodon/blob/c3aef491d66aec743a3a53e934a494f653745b61/config/initializers/cors.rb
if (substr($_REQUEST['pagename'] ?? '', 0, 12) == '.well-known/') {
header('Access-Control-Allow-Origin: *');
header('Access-Control-Allow-Headers: *');
header('Access-Control-Allow-Methods: ' . Router::GET);
header('Access-Control-Allow-Credentials: false');
} elseif (substr($_REQUEST['pagename'] ?? '', 0, 8) == 'profile/') {
header('Access-Control-Allow-Origin: *');
header('Access-Control-Allow-Headers: *');
header('Access-Control-Allow-Methods: ' . Router::GET);
header('Access-Control-Allow-Credentials: false');
} elseif (substr($_REQUEST['pagename'] ?? '', 0, 4) == 'api/') {
header('Access-Control-Allow-Origin: *');
header('Access-Control-Allow-Headers: *');
header('Access-Control-Allow-Methods: ' . implode(',', Router::ALLOWED_METHODS));
header('Access-Control-Allow-Credentials: false');
header('Access-Control-Expose-Headers: Link');
} elseif (substr($_REQUEST['pagename'] ?? '', 0, 11) == 'oauth/token') {
header('Access-Control-Allow-Origin: *');
header('Access-Control-Allow-Headers: *');
header('Access-Control-Allow-Methods: ' . Router::POST);
header('Access-Control-Allow-Credentials: false');
}
// @see https://developer.mozilla.org/en-US/docs/Web/HTTP/Methods/OPTIONS
// @todo Check allowed methods per requested path
if ($server['REQUEST_METHOD'] === Router::OPTIONS) {
header('Allow: ' . implode(',', Router::ALLOWED_METHODS));
throw new NoContentException();
}
$placeholder = '';
$profiler->set(microtime(true), 'ready');
$timestamp = microtime(true);
Core\Hook::callAll($this->moduleName . '_mod_init', $placeholder);
$profiler->set(microtime(true) - $timestamp, 'init');
if ($server['REQUEST_METHOD'] === Router::DELETE) {
$this->module->delete();
}
if ($server['REQUEST_METHOD'] === Router::PATCH) {
$this->module->patch();
}
if ($server['REQUEST_METHOD'] === Router::POST) {
Core\Hook::callAll($this->moduleName . '_mod_post', $post);
$this->module->post();
}
if ($server['REQUEST_METHOD'] === Router::PUT) {
$this->module->put();
}
// "rawContent" is especially meant for technical endpoints.
// This endpoint doesn't need any theme initialization or other comparable stuff.
$this->module->rawContent();
}
}

View file

@ -32,11 +32,11 @@ use Friendica\Core\Hook;
use Friendica\Core\L10n;
use Friendica\Core\Renderer;
use Friendica\Core\Theme;
use Friendica\Module\Special\HTTPException as ModuleHTTPException;
use Friendica\Network\HTTPException;
use Friendica\Util\Network;
use Friendica\Util\Strings;
use Friendica\Util\Profiler;
use Psr\Http\Message\ResponseInterface;
/**
* Contains the page specific environment variables for the current Page
@ -191,14 +191,14 @@ class Page implements ArrayAccess
* - head.tpl template
*
* @param App $app The Friendica App instance
* @param ModuleController $module The loaded Friendica module
* @param Arguments $args The Friendica App Arguments
* @param L10n $l10n The l10n language instance
* @param IManageConfigValues $config The Friendica configuration
* @param IManagePersonalConfigValues $pConfig The Friendica personal configuration (for user)
*
* @throws HTTPException\InternalServerErrorException
*/
private function initHead(App $app, ModuleController $module, L10n $l10n, IManageConfigValues $config, IManagePersonalConfigValues $pConfig)
private function initHead(App $app, Arguments $args, L10n $l10n, IManageConfigValues $config, IManagePersonalConfigValues $pConfig)
{
$interval = ((local_user()) ? $pConfig->get(local_user(), 'system', 'update_interval') : 40000);
@ -212,8 +212,8 @@ class Page implements ArrayAccess
}
// Default title: current module called
if (empty($this->page['title']) && $module->getName()) {
$this->page['title'] = ucfirst($module->getName());
if (empty($this->page['title']) && $args->getModuleName()) {
$this->page['title'] = ucfirst($args->getModuleName());
}
// Prepend the sitename to the page title
@ -268,9 +268,9 @@ class Page implements ArrayAccess
if (!empty($_SERVER["HTTPS"]) && ($_SERVER["HTTPS"] == "on")) {
$pageURL .= "s";
}
$pageURL .= "://";
if ($_SERVER["SERVER_PORT"] != "80" && $_SERVER["SERVER_PORT"] != "443") {
$pageURL .= $_SERVER["SERVER_NAME"] . ":" . $_SERVER["SERVER_PORT"] . $_SERVER["REQUEST_URI"];
} else {
@ -337,32 +337,19 @@ class Page implements ArrayAccess
* - module content
* - hooks for content
*
* @param ModuleController $module The module
* @param Mode $mode The Friendica execution mode
* @param ResponseInterface $response The Module response class
* @param Mode $mode The Friendica execution mode
*
* @throws HTTPException\InternalServerErrorException
*/
private function initContent(ModuleController $module, Mode $mode)
private function initContent(ResponseInterface $response, Mode $mode)
{
$content = '';
try {
$moduleClass = $module->getModule();
$arr = ['content' => $content];
Hook::callAll($moduleClass->getClassName() . '_mod_content', $arr);
$content = $arr['content'];
$content .= $module->getModule()->content();
} catch (HTTPException $e) {
$content = (new ModuleHTTPException())->content($e);
}
// initialise content region
if ($mode->isNormal()) {
Hook::callAll('page_content_top', $this->page['content']);
}
$this->page['content'] .= $content;
$this->page['content'] .= (string)$response->getBody();
}
/**
@ -384,22 +371,47 @@ class Page implements ArrayAccess
$this->footerScripts[] = trim($url, '/');
}
/**
* Directly exit with the current response (include setting all headers)
*
* @param ResponseInterface $response
*/
public function exit(ResponseInterface $response)
{
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
*
* @param App $app The Friendica App
* @param BaseURL $baseURL The Friendica Base URL
* @param Mode $mode The current node mode
* @param ModuleController $module The loaded Friendica module
* @param L10n $l10n The l10n language class
* @param IManageConfigValues $config The Configuration of this node
* @param IManagePersonalConfigValues $pconfig The personal/user configuration
* @param App $app The Friendica App
* @param BaseURL $baseURL The Friendica Base URL
* @param Arguments $args The Friendica App arguments
* @param Mode $mode The current node mode
* @param ResponseInterface $response The Response of the module class, including type, content & headers
* @param L10n $l10n The l10n language class
* @param IManageConfigValues $config The Configuration of this node
* @param IManagePersonalConfigValues $pconfig The personal/user configuration
*
* @throws HTTPException\InternalServerErrorException
* @throws HTTPException\InternalServerErrorException|HTTPException\ServiceUnavailableException
*/
public function run(App $app, BaseURL $baseURL, Mode $mode, ModuleController $module, L10n $l10n, Profiler $profiler, IManageConfigValues $config, IManagePersonalConfigValues $pconfig)
public function run(App $app, BaseURL $baseURL, Arguments $args, Mode $mode, ResponseInterface $response, L10n $l10n, Profiler $profiler, IManageConfigValues $config, IManagePersonalConfigValues $pconfig)
{
$moduleName = $module->getName();
$moduleName = $args->getModuleName();
/* Create the page content.
* Calls all hooks which are including content operations
@ -407,7 +419,7 @@ class Page implements ArrayAccess
* Sets the $Page->page['content'] variable
*/
$timestamp = microtime(true);
$this->initContent($module, $mode);
$this->initContent($response, $mode);
$profiler->set(microtime(true) - $timestamp, 'content');
// Load current theme info after module has been initialized as theme could have been set in module
@ -429,7 +441,7 @@ class Page implements ArrayAccess
* all the module functions have executed so that all
* theme choices made by the modules can take effect.
*/
$this->initHead($app, $module, $l10n, $config, $pconfig);
$this->initHead($app, $args, $l10n, $config, $pconfig);
/* Build the page ending -- this is stuff that goes right before
* the closing </body> tag
@ -446,6 +458,20 @@ class Page implements ArrayAccess
$this->page['nav'] = Nav::build($app);
}
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");
}
}
// Build the page - now that we have all the components
if (isset($_GET["mode"]) && (($_GET["mode"] == "raw") || ($_GET["mode"] == "minimal"))) {
$doc = new DOMDocument();

View file

@ -21,17 +21,26 @@
namespace Friendica\App;
use Dice\Dice;
use FastRoute\DataGenerator\GroupCountBased;
use FastRoute\Dispatcher;
use FastRoute\RouteCollector;
use FastRoute\RouteParser\Std;
use Friendica\Capabilities\ICanHandleRequests;
use Friendica\Core\Addon;
use Friendica\Core\Cache\Enum\Duration;
use Friendica\Core\Cache\Capability\ICanCache;
use Friendica\Core\Config\Capability\IManageConfigValues;
use Friendica\Core\Hook;
use Friendica\Core\L10n;
use Friendica\Core\Lock\Capability\ICanLock;
use Friendica\LegacyModule;
use Friendica\Module\HTTPException\MethodNotAllowed;
use Friendica\Module\HTTPException\PageNotFound;
use Friendica\Network\HTTPException;
use Friendica\Network\HTTPException\MethodNotAllowedException;
use Friendica\Network\HTTPException\NoContentException;
use Friendica\Network\HTTPException\NotFoundException;
/**
* Wrapper for FastRoute\Router
@ -83,24 +92,52 @@ class Router
/** @var ICanLock */
private $lock;
/** @var Arguments */
private $args;
/** @var IManageConfigValues */
private $config;
/** @var Dice */
private $dice;
/** @var string */
private $baseRoutesFilepath;
/** @var array */
private $server;
/**
* @param array $server The $_SERVER variable
* @param string $baseRoutesFilepath The path to a base routes file to leverage cache, can be empty
* @param L10n $l10n
* @param ICanCache $cache
* @param ICanLock $lock
* @param IManageConfigValues $config
* @param Arguments $args
* @param Dice $dice
* @param RouteCollector|null $routeCollector
*/
public function __construct(array $server, string $baseRoutesFilepath, L10n $l10n, ICanCache $cache, ICanLock $lock, RouteCollector $routeCollector = null)
public function __construct(array $server, string $baseRoutesFilepath, L10n $l10n, ICanCache $cache, ICanLock $lock, IManageConfigValues $config, Arguments $args, Dice $dice, RouteCollector $routeCollector = null)
{
$this->baseRoutesFilepath = $baseRoutesFilepath;
$this->l10n = $l10n;
$this->cache = $cache;
$this->lock = $lock;
$this->args = $args;
$this->config = $config;
$this->dice = $dice;
$this->server = $server;
$httpMethod = $this->server['REQUEST_METHOD'] ?? self::GET;
// @see https://developer.mozilla.org/en-US/docs/Web/HTTP/Methods/OPTIONS
// @todo Check allowed methods per requested path
if ($httpMethod === static::OPTIONS) {
header('Allow: ' . implode(',', Router::ALLOWED_METHODS));
throw new NoContentException();
}
$httpMethod = $server['REQUEST_METHOD'] ?? self::GET;
$this->httpMethod = in_array($httpMethod, self::ALLOWED_METHODS) ? $httpMethod : self::GET;
$this->routeCollector = isset($routeCollector) ?
@ -216,21 +253,19 @@ class Router
/**
* Returns the relevant module class name for the given page URI or NULL if no route rule matched.
*
* @param string $cmd The path component of the request URL without the query string
*
* @return string A Friendica\BaseModule-extending class name if a route rule matched
*
* @throws HTTPException\InternalServerErrorException
* @throws HTTPException\MethodNotAllowedException If a rule matched but the method didn't
* @throws HTTPException\NotFoundException If no rule matched
*/
public function getModuleClass($cmd)
private function getModuleClass()
{
$cmd = $this->args->getCommand();
$cmd = '/' . ltrim($cmd, '/');
$dispatcher = new Dispatcher\GroupCountBased($this->getCachedDispatchData());
$moduleClass = null;
$this->parameters = [];
$routeInfo = $dispatcher->dispatch($this->httpMethod, $cmd);
@ -246,14 +281,50 @@ class Router
return $moduleClass;
}
/**
* Returns the module parameters.
*
* @return array parameters
*/
public function getModuleParameters()
public function getModule(?string $module_class = null): ICanHandleRequests
{
return $this->parameters;
$module_parameters = [$this->server];
/**
* ROUTING
*
* From the request URL, routing consists of obtaining the name of a BaseModule-extending class of which the
* post() and/or content() static methods can be respectively called to produce a data change or an output.
**/
try {
$module_class = $module_class ?? $this->getModuleClass();
$module_parameters[] = $this->parameters;
} catch (MethodNotAllowedException $e) {
$module_class = MethodNotAllowed::class;
} catch (NotFoundException $e) {
$moduleName = $this->args->getModuleName();
// Then we try addon-provided modules that we wrap in the LegacyModule class
if (Addon::isEnabled($moduleName) && file_exists("addon/{$moduleName}/{$moduleName}.php")) {
//Check if module is an app and if public access to apps is allowed or not
$privateapps = $this->config->get('config', 'private_addons', false);
if ((!local_user()) && Hook::isAddonApp($moduleName) && $privateapps) {
throw new MethodNotAllowedException($this->l10n->t("You must be logged in to use addons. "));
} else {
include_once "addon/{$moduleName}/{$moduleName}.php";
if (function_exists($moduleName . '_module')) {
$module_parameters[] = "addon/{$moduleName}/{$moduleName}.php";
$module_class = LegacyModule::class;
}
}
}
/* Finally, we look for a 'standard' program module in the 'mod' directory
* We emulate a Module class through the LegacyModule class
*/
if (!$module_class && file_exists("mod/{$moduleName}.php")) {
$module_parameters[] = "mod/{$moduleName}.php";
$module_class = LegacyModule::class;
}
$module_class = $module_class ?: PageNotFound::class;
}
/** @var ICanHandleRequests $module */
return $this->dice->create($module_class, $module_parameters);
}
/**

View file

@ -21,10 +21,19 @@
namespace Friendica;
use Friendica\App\Router;
use Friendica\Capabilities\ICanHandleRequests;
use Friendica\Capabilities\ICanCreateResponses;
use Friendica\Core\Hook;
use Friendica\Core\L10n;
use Friendica\Core\Logger;
use Friendica\Model\User;
use Friendica\Module\Response;
use Friendica\Module\Special\HTTPException as ModuleHTTPException;
use Friendica\Network\HTTPException;
use Friendica\Util\Profiler;
use Psr\Http\Message\ResponseInterface;
use Psr\Log\LoggerInterface;
/**
* All modules in Friendica should extend BaseModule, although not all modules
@ -39,14 +48,31 @@ abstract class BaseModule implements ICanHandleRequests
{
/** @var array */
protected $parameters = [];
/** @var L10n */
protected $l10n;
/** @var App\BaseURL */
protected $baseUrl;
/** @var App\Arguments */
protected $args;
/** @var LoggerInterface */
protected $logger;
/** @var Profiler */
protected $profiler;
/** @var array */
protected $server;
/** @var ICanCreateResponses */
protected $response;
public function __construct(L10n $l10n, array $parameters = [])
public function __construct(L10n $l10n, App\BaseURL $baseUrl, App\Arguments $args, LoggerInterface $logger, Profiler $profiler, Response $response, array $server, array $parameters = [])
{
$this->parameters = $parameters;
$this->l10n = $l10n;
$this->baseUrl = $baseUrl;
$this->args = $args;
$this->logger = $logger;
$this->profiler = $profiler;
$this->server = $server;
$this->response = $response;
}
/**
@ -70,55 +96,149 @@ abstract class BaseModule implements ICanHandleRequests
}
/**
* {@inheritDoc}
* Module GET method to display raw content from technical endpoints
*
* Extend this method if the module is supposed to return communication data,
* e.g. from protocol implementations.
*
* @param string[] $request The $_REQUEST content
*/
public function rawContent()
protected function rawContent(array $request = [])
{
// echo '';
// exit;
}
/**
* {@inheritDoc}
* Module GET method to display any content
*
* Extend this method if the module is supposed to return any display
* through a GET request. It can be an HTML page through templating or a
* XML feed or a JSON output.
*
* @param string[] $request The $_REQUEST content
*/
public function content(): string
protected function content(array $request = []): string
{
return '';
}
/**
* {@inheritDoc}
* Module DELETE method to process submitted data
*
* Extend this method if the module is supposed to process DELETE requests.
* Doesn't display any content
*/
public function delete()
protected function delete()
{
}
/**
* Module PATCH method to process submitted data
*
* Extend this method if the module is supposed to process PATCH requests.
* Doesn't display any content
*/
protected function patch()
{
}
/**
* Module POST method to process submitted data
*
* Extend this method if the module is supposed to process POST requests.
* Doesn't display any content
*
* @param string[] $request The $_REQUEST content
* @param string[] $post The $_POST content
*
*/
protected function post(array $request = [], array $post = [])
{
// $this->baseUrl->redirect('module');
}
/**
* Module PUT method to process submitted data
*
* Extend this method if the module is supposed to process PUT requests.
* Doesn't display any content
*/
protected function put()
{
}
/**
* {@inheritDoc}
*/
public function patch()
public function run(array $post = [], array $request = []): ResponseInterface
{
}
// @see https://github.com/tootsuite/mastodon/blob/c3aef491d66aec743a3a53e934a494f653745b61/config/initializers/cors.rb
if (substr($request['pagename'] ?? '', 0, 12) == '.well-known/') {
$this->response->setHeader('*', 'Access-Control-Allow-Origin');
$this->response->setHeader('*', 'Access-Control-Allow-Headers');
$this->response->setHeader(Router::GET, 'Access-Control-Allow-Methods');
$this->response->setHeader('false', 'Access-Control-Allow-Credentials');
} elseif (substr($request['pagename'] ?? '', 0, 8) == 'profile/') {
$this->response->setHeader('*', 'Access-Control-Allow-Origin');
$this->response->setHeader('*', 'Access-Control-Allow-Headers');
$this->response->setHeader(Router::GET, 'Access-Control-Allow-Methods');
$this->response->setHeader('false', 'Access-Control-Allow-Credentials');
} elseif (substr($request['pagename'] ?? '', 0, 4) == 'api/') {
$this->response->setHeader('*', 'Access-Control-Allow-Origin');
$this->response->setHeader('*', 'Access-Control-Allow-Headers');
$this->response->setHeader(implode(',', Router::ALLOWED_METHODS), 'Access-Control-Allow-Methods');
$this->response->setHeader('false', 'Access-Control-Allow-Credentials');
$this->response->setHeader('Link', 'Access-Control-Expose-Headers');
} elseif (substr($request['pagename'] ?? '', 0, 11) == 'oauth/token') {
$this->response->setHeader('*', 'Access-Control-Allow-Origin');
$this->response->setHeader('*', 'Access-Control-Allow-Headers');
$this->response->setHeader(Router::POST, 'Access-Control-Allow-Methods');
$this->response->setHeader('false', 'Access-Control-Allow-Credentials');
}
/**
* {@inheritDoc}
*/
public function post()
{
// DI::baseurl()->redirect('module');
}
$placeholder = '';
/**
* {@inheritDoc}
*/
public function put()
{
}
$this->profiler->set(microtime(true), 'ready');
$timestamp = microtime(true);
/** Gets the name of the current class */
public function getClassName(): string
{
return static::class;
Core\Hook::callAll($this->args->getModuleName() . '_mod_init', $placeholder);
$this->profiler->set(microtime(true) - $timestamp, 'init');
switch ($this->server['REQUEST_METHOD'] ?? Router::GET) {
case Router::DELETE:
$this->delete();
break;
case Router::PATCH:
$this->patch();
break;
case Router::POST:
Core\Hook::callAll($this->args->getModuleName() . '_mod_post', $post);
$this->post($request, $post);
break;
case Router::PUT:
$this->put();
break;
}
$timestamp = microtime(true);
// "rawContent" is especially meant for technical endpoints.
// This endpoint doesn't need any theme initialization or other comparable stuff.
$this->rawContent($request);
try {
$arr = ['content' => ''];
Hook::callAll(static::class . '_mod_content', $arr);
$this->response->addContent($arr['content']);
$this->response->addContent($this->content($_REQUEST));
} catch (HTTPException $e) {
$this->response->addContent((new ModuleHTTPException())->content($e));
} finally {
$this->profiler->set(microtime(true) - $timestamp, 'content');
}
return $this->response->generate();
}
/*
@ -134,9 +254,9 @@ abstract class BaseModule implements ICanHandleRequests
*/
public static function getFormSecurityToken($typename = '')
{
$user = User::getById(DI::app()->getLoggedInUserId(), ['guid', 'prvkey']);
$user = User::getById(DI::app()->getLoggedInUserId(), ['guid', 'prvkey']);
$timestamp = time();
$sec_hash = hash('whirlpool', ($user['guid'] ?? '') . ($user['prvkey'] ?? '') . session_id() . $timestamp . $typename);
$sec_hash = hash('whirlpool', ($user['guid'] ?? '') . ($user['prvkey'] ?? '') . session_id() . $timestamp . $typename);
return $timestamp . '.' . $sec_hash;
}

View file

@ -0,0 +1,61 @@
<?php
namespace Friendica\Capabilities;
use Friendica\Network\HTTPException\InternalServerErrorException;
use Psr\Http\Message\ResponseInterface;
interface ICanCreateResponses
{
/**
* This constant helps to find the specific return type of responses inside the headers array
*/
const X_HEADER = 'X-RESPONSE-TYPE';
const TYPE_HTML = 'html';
const TYPE_XML = 'xml';
const TYPE_JSON = 'json';
const TYPE_ATOM = 'atom';
const TYPE_RSS = 'rss';
const ALLOWED_TYPES = [
self::TYPE_HTML,
self::TYPE_XML,
self::TYPE_JSON,
self::TYPE_ATOM,
self::TYPE_RSS
];
/**
* Adds a header entry to the module response
*
* @param string $header
* @param string|null $key
*/
public function setHeader(string $header, ?string $key = null): void;
/**
* Adds output content to the module response
*
* @param mixed $content
*/
public function addContent($content): void;
/**
* Sets the response type of the current request
*
* @param string $type
* @param string|null $content_type (optional) overrides the direct content_type, otherwise set the default one
*
* @throws InternalServerErrorException
*/
public function setType(string $type, ?string $content_type = null): void;
/**
* Creates a PSR-7 compliant interface
* @see https://www.php-fig.org/psr/psr-7/
*
* @return ResponseInterface
*/
public function generate(): ResponseInterface;
}

View file

@ -2,59 +2,21 @@
namespace Friendica\Capabilities;
use Friendica\Network\HTTPException;
use Psr\Http\Message\ResponseInterface;
/**
* This interface provides the capability to handle requests from clients and returns the desired outcome
*/
interface ICanHandleRequests
{
/**
* Module GET method to display raw content from technical endpoints
* @param array $post The $_POST content (in case of POST)
* @param array $request The $_REQUEST content (in case of GET, POST)
*
* Extend this method if the module is supposed to return communication data,
* e.g. from protocol implementations.
*/
public function rawContent();
/**
* Module GET method to display any content
* @return ResponseInterface responding to the request handling
*
* Extend this method if the module is supposed to return any display
* through a GET request. It can be an HTML page through templating or a
* XML feed or a JSON output.
* @throws HTTPException\InternalServerErrorException
*/
public function content(): string;
/**
* Module DELETE method to process submitted data
*
* Extend this method if the module is supposed to process DELETE requests.
* Doesn't display any content
*/
public function delete();
/**
* Module PATCH method to process submitted data
*
* Extend this method if the module is supposed to process PATCH requests.
* Doesn't display any content
*/
public function patch();
/**
* Module POST method to process submitted data
*
* Extend this method if the module is supposed to process POST requests.
* Doesn't display any content
*/
public function post();
/**
* Module PUT method to process submitted data
*
* Extend this method if the module is supposed to process PUT requests.
* Doesn't display any content
*/
public function put();
public function getClassName(): string;
public function run(array $post = [], array $request = []): ResponseInterface;
}

View file

@ -182,7 +182,7 @@ class Nav
if (Session::isAuthenticated()) {
$nav['logout'] = ['logout', DI::l10n()->t('Logout'), '', DI::l10n()->t('End this session')];
} else {
$nav['login'] = ['login', DI::l10n()->t('Login'), (DI::module()->getName() == 'login' ? 'selected' : ''), DI::l10n()->t('Sign in')];
$nav['login'] = ['login', DI::l10n()->t('Login'), (DI::args()->getModuleName() == 'login' ? 'selected' : ''), DI::l10n()->t('Sign in')];
}
if ($a->isLoggedIn()) {
@ -208,7 +208,7 @@ class Nav
$homelink = Session::get('visitor_home', '');
}
if ((DI::module()->getName() != 'home') && (! (local_user()))) {
if ((DI::args()->getModuleName() != 'home') && (! (local_user()))) {
$nav['home'] = [$homelink, DI::l10n()->t('Home'), '', DI::l10n()->t('Home Page')];
}

View file

@ -80,7 +80,7 @@ class ACL
$arr = ['contact' => $contacts, 'entry' => $o];
Hook::callAll(DI::module()->getName() . '_pre_recipient', $arr);
Hook::callAll(DI::args()->getModuleName() . '_pre_recipient', $arr);
$tpl = Renderer::getMarkupTemplate('acl/message_recipient.tpl');
$o = Renderer::replaceMacros($tpl, [
@ -88,7 +88,7 @@ class ACL
'$selected' => $selected,
]);
Hook::callAll(DI::module()->getName() . '_post_recipient', $o);
Hook::callAll(DI::args()->getModuleName() . '_post_recipient', $o);
return $o;
}

View file

@ -98,14 +98,6 @@ abstract class DI
return self::$dice->create(App\Mode::class);
}
/**
* @return App\ModuleController
*/
public static function module()
{
return self::$dice->create(App\ModuleController::class);
}
/**
* @return App\Page
*/

View file

@ -22,6 +22,9 @@
namespace Friendica;
use Friendica\Core\L10n;
use Friendica\Module\Response;
use Friendica\Util\Profiler;
use Psr\Log\LoggerInterface;
/**
* This mock module enable class encapsulation of legacy global function modules.
@ -39,9 +42,9 @@ class LegacyModule extends BaseModule
*/
private $moduleName = '';
public function __construct(L10n $l10n, string $file_path = '', array $parameters = [])
public function __construct(L10n $l10n, App\BaseURL $baseUrl, App\Arguments $args, LoggerInterface $logger, Profiler $profiler, Response $response, array $server, string $file_path = '', array $parameters = [])
{
parent::__construct($l10n, $parameters);
parent::__construct($l10n, $baseUrl, $args, $logger, $profiler, $response, $server, $parameters);
$this->setModuleFile($file_path);
@ -65,13 +68,15 @@ class LegacyModule extends BaseModule
require_once $file_path;
}
public function content(): string
public function content(array $request = []): string
{
return $this->runModuleFunction('content');
}
public function post()
public function post(array $request = [], array $post = [])
{
parent::post($post);
$this->runModuleFunction('post');
}
@ -88,7 +93,7 @@ class LegacyModule extends BaseModule
if (\function_exists($function_name)) {
$a = DI::app();
return $function_name($a);
return $function_name($a) ?? '';
}
return '';

View file

@ -30,7 +30,7 @@ use Friendica\BaseModule;
*/
class AccountManagementControlDocument extends BaseModule
{
public function rawContent()
protected function rawContent(array $request = [])
{
$output = [
'version' => 1,

View file

@ -31,7 +31,7 @@ use Friendica\Network\HTTPException\NotFoundException;
*/
class Acctlink extends BaseModule
{
public function rawContent()
protected function rawContent(array $request = [])
{
$addr = trim($_GET['addr'] ?? '');
if (!$addr) {

View file

@ -31,7 +31,7 @@ use Friendica\Protocol\ActivityPub;
*/
class Followers extends BaseModule
{
public function rawContent()
protected function rawContent(array $request = [])
{
if (empty($this->parameters['nickname'])) {
throw new \Friendica\Network\HTTPException\NotFoundException();

View file

@ -31,7 +31,7 @@ use Friendica\Protocol\ActivityPub;
*/
class Following extends BaseModule
{
public function rawContent()
protected function rawContent(array $request = [])
{
if (empty($this->parameters['nickname'])) {
throw new \Friendica\Network\HTTPException\NotFoundException();

View file

@ -35,7 +35,7 @@ use Friendica\Util\Network;
*/
class Inbox extends BaseModule
{
public function rawContent()
protected function rawContent(array $request = [])
{
$postdata = Network::postdata();

View file

@ -41,7 +41,7 @@ use Friendica\Util\Strings;
*/
class Objects extends BaseModule
{
public function rawContent()
protected function rawContent(array $request = [])
{
if (empty($this->parameters['guid'])) {
throw new HTTPException\BadRequestException();

View file

@ -31,7 +31,7 @@ use Friendica\Util\HTTPSignature;
*/
class Outbox extends BaseModule
{
public function rawContent()
protected function rawContent(array $request = [])
{
if (empty($this->parameters['nickname'])) {
throw new \Friendica\Network\HTTPException\NotFoundException();

View file

@ -30,7 +30,7 @@ use Friendica\Util\Strings;
class Details extends BaseAdmin
{
public function post()
public function post(array $request = [], array $post = [])
{
self::checkAdminAccess();
@ -52,7 +52,7 @@ class Details extends BaseAdmin
DI::baseUrl()->redirect($redirect);
}
public function content(): string
protected function content(array $request = []): string
{
parent::content();

View file

@ -28,7 +28,7 @@ use Friendica\Module\BaseAdmin;
class Index extends BaseAdmin
{
public function content(): string
protected function content(array $request = []): string
{
parent::content();

View file

@ -32,7 +32,7 @@ use Friendica\Util\Network;
class Contact extends BaseAdmin
{
public function post()
protected function post(array $request = [], array $post = [])
{
self::checkAdminAccess();
@ -76,7 +76,7 @@ class Contact extends BaseAdmin
DI::baseUrl()->redirect('admin/blocklist/contact');
}
public function content(): string
protected function content(array $request = []): string
{
parent::content();

View file

@ -32,7 +32,7 @@ use GuzzleHttp\Psr7\Uri;
class Add extends BaseAdmin
{
public function post()
protected function post(array $request = [], array $post = [])
{
self::checkAdminAccess();
@ -66,7 +66,7 @@ class Add extends BaseAdmin
DI::baseUrl()->redirect('admin/blocklist/server');
}
public function content(): string
protected function content(array $request = []): string
{
parent::content();

View file

@ -27,7 +27,7 @@ use Friendica\Module\BaseAdmin;
class Index extends BaseAdmin
{
public function post()
protected function post(array $request = [], array $post = [])
{
self::checkAdminAccess();
@ -56,7 +56,7 @@ class Index extends BaseAdmin
DI::baseUrl()->redirect('admin/blocklist/server');
}
public function content(): string
protected function content(array $request = []): string
{
parent::content();

View file

@ -30,7 +30,7 @@ use Friendica\Module\BaseAdmin;
class DBSync extends BaseAdmin
{
public function content(): string
protected function content(array $request = []): string
{
parent::content();

View file

@ -28,7 +28,7 @@ use Friendica\Module\BaseAdmin;
class Features extends BaseAdmin
{
public function post()
protected function post(array $request = [], array $post = [])
{
self::checkAdminAccess();
@ -60,7 +60,7 @@ class Features extends BaseAdmin
DI::baseUrl()->redirect('admin/features');
}
public function content(): string
protected function content(array $request = []): string
{
parent::content();

View file

@ -28,7 +28,7 @@ use Friendica\Module\BaseAdmin;
class Federation extends BaseAdmin
{
public function content(): string
protected function content(array $request = []): string
{
parent::content();

View file

@ -29,7 +29,7 @@ use Friendica\Util\Strings;
class Delete extends BaseAdmin
{
public function post()
protected function post(array $request = [], array $post = [])
{
self::checkAdminAccess();
@ -55,7 +55,7 @@ class Delete extends BaseAdmin
DI::baseUrl()->redirect('admin/item/delete');
}
public function content(): string
protected function content(array $request = []): string
{
parent::content();

View file

@ -29,7 +29,7 @@ use Friendica\Module\BaseAdmin;
class Source extends BaseAdmin
{
public function content(): string
protected function content(array $request = []): string
{
parent::content();

View file

@ -29,7 +29,7 @@ use Psr\Log\LogLevel;
class Settings extends BaseAdmin
{
public function post()
protected function post(array $request = [], array $post = [])
{
self::checkAdminAccess();
@ -56,7 +56,7 @@ class Settings extends BaseAdmin
DI::baseUrl()->redirect('admin/logs');
}
public function content(): string
protected function content(array $request = []): string
{
parent::content();

View file

@ -31,7 +31,7 @@ class View extends BaseAdmin
{
const LIMIT = 500;
public function content(): string
protected function content(array $request = []): string
{
parent::content();

View file

@ -25,7 +25,7 @@ use Friendica\Module\BaseAdmin;
class PhpInfo extends BaseAdmin
{
public function rawContent()
protected function rawContent(array $request = [])
{
self::checkAdminAccess();

View file

@ -38,7 +38,7 @@ use Friendica\Util\DateTimeFormat;
*/
class Queue extends BaseAdmin
{
public function content(): string
protected function content(array $request = []): string
{
parent::content();

View file

@ -43,7 +43,7 @@ require_once __DIR__ . '/../../../boot.php';
class Site extends BaseAdmin
{
public function post()
protected function post(array $request = [], array $post = [])
{
self::checkAdminAccess();
@ -384,7 +384,7 @@ class Site extends BaseAdmin
DI::baseUrl()->redirect('admin/site' . $active_panel);
}
public function content(): string
protected function content(array $request = []): string
{
parent::content();

View file

@ -31,7 +31,7 @@ use Friendica\Util\Strings;
class Storage extends BaseAdmin
{
public function post()
protected function post(array $request = [], array $post = [])
{
self::checkAdminAccess();
@ -91,7 +91,7 @@ class Storage extends BaseAdmin
DI::baseUrl()->redirect('admin/storage');
}
public function content(): string
protected function content(array $request = []): string
{
parent::content();

View file

@ -37,7 +37,7 @@ use Friendica\Util\DateTimeFormat;
class Summary extends BaseAdmin
{
public function content(): string
protected function content(array $request = []): string
{
parent::content();

View file

@ -30,7 +30,7 @@ use Friendica\Util\Strings;
class Details extends BaseAdmin
{
public function content(): string
protected function content(array $request = []): string
{
parent::content();

View file

@ -25,24 +25,24 @@ use Friendica\App;
use Friendica\Core\L10n;
use Friendica\Core\Renderer;
use Friendica\Module\BaseAdmin;
use Friendica\Module\Response;
use Friendica\Util\Profiler;
use Friendica\Util\Strings;
use Psr\Log\LoggerInterface;
class Embed extends BaseAdmin
{
/** @var App */
protected $app;
/** @var App\BaseURL */
protected $baseUrl;
/** @var App\Mode */
protected $mode;
public function __construct(App $app, App\BaseURL $baseUrl, App\Mode $mode, L10n $l10n, array $parameters = [])
public function __construct(App $app, L10n $l10n, App\BaseURL $baseUrl, App\Arguments $args, LoggerInterface $logger, Profiler $profiler, Response $response, App\Mode $mode, array $server, array $parameters = [])
{
parent::__construct($l10n, $parameters);
parent::__construct($l10n, $baseUrl, $args, $logger, $profiler, $response, $server, $parameters);
$this->app = $app;
$this->baseUrl = $baseUrl;
$this->mode = $mode;
$this->app = $app;
$this->mode = $mode;
$theme = Strings::sanitizeFilePathItem($this->parameters['theme']);
if (is_file("view/theme/$theme/config.php")) {
@ -50,7 +50,7 @@ class Embed extends BaseAdmin
}
}
public function post()
protected function post(array $request = [], array $post = [])
{
self::checkAdminAccess();
@ -70,7 +70,7 @@ class Embed extends BaseAdmin
$this->baseUrl->redirect('admin/themes/' . $theme . '/embed?mode=minimal');
}
public function content(): string
protected function content(array $request = []): string
{
parent::content();

View file

@ -29,7 +29,7 @@ use Friendica\Util\Strings;
class Index extends BaseAdmin
{
public function content(): string
protected function content(array $request = []): string
{
parent::content();

View file

@ -21,11 +21,14 @@
namespace Friendica\Module\Admin;
use Friendica\App\BaseURL;
use Friendica\App;
use Friendica\Core\Config\Capability\IManageConfigValues;
use Friendica\Core\L10n;
use Friendica\Core\Renderer;
use Friendica\Module\BaseAdmin;
use Friendica\Module\Response;
use Friendica\Util\Profiler;
use Psr\Log\LoggerInterface;
class Tos extends BaseAdmin
{
@ -33,19 +36,16 @@ class Tos extends BaseAdmin
protected $tos;
/** @var IManageConfigValues */
protected $config;
/** @var BaseURL */
protected $baseUrl;
public function __construct(\Friendica\Module\Tos $tos, IManageConfigValues $config, BaseURL $baseUrl, L10n $l10n, array $parameters = [])
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, $parameters);
parent::__construct($l10n, $baseUrl, $args, $logger, $profiler, $response, $server, $parameters);
$this->tos = $tos;
$this->tos = new \Friendica\Module\Tos($l10n, $baseUrl, $args, $logger, $profiler, $response, $config, $server, $parameters);
$this->config = $config;
$this->baseUrl = $baseUrl;
}
public function post()
protected function post(array $request = [], array $post = [])
{
self::checkAdminAccess();
@ -66,7 +66,7 @@ class Tos extends BaseAdmin
$this->baseUrl->redirect('admin/tos');
}
public function content(): string
protected function content(array $request = []): string
{
parent::content();

View file

@ -30,7 +30,7 @@ use Friendica\Module\Admin\BaseUsers;
class Active extends BaseUsers
{
public function post()
protected function post(array $request = [], array $post = [])
{
self::checkAdminAccess();
@ -60,7 +60,7 @@ class Active extends BaseUsers
DI::baseUrl()->redirect(DI::args()->getQueryString());
}
public function content(): string
protected function content(array $request = []): string
{
parent::content();

View file

@ -31,7 +31,7 @@ use Friendica\Util\Temporal;
class Blocked extends BaseUsers
{
public function post()
protected function post(array $request = [], array $post = [])
{
self::checkAdminAccess();
@ -61,7 +61,7 @@ class Blocked extends BaseUsers
DI::baseUrl()->redirect('admin/users/blocked');
}
public function content(): string
protected function content(array $request = []): string
{
parent::content();

View file

@ -28,7 +28,7 @@ use Friendica\Module\Admin\BaseUsers;
class Create extends BaseUsers
{
public function post()
protected function post(array $request = [], array $post = [])
{
self::checkAdminAccess();
@ -51,7 +51,7 @@ class Create extends BaseUsers
DI::baseUrl()->redirect('admin/users/create');
}
public function content(): string
protected function content(array $request = []): string
{
parent::content();

View file

@ -33,7 +33,7 @@ use Friendica\Util\Temporal;
class Deleted extends BaseUsers
{
public function post()
protected function post(array $request = [], array $post = [])
{
self::checkAdminAccess();
@ -44,7 +44,7 @@ class Deleted extends BaseUsers
DI::baseUrl()->redirect('admin/users/deleted');
}
public function content(): string
protected function content(array $request = []): string
{
parent::content();

View file

@ -30,7 +30,7 @@ use Friendica\Module\Admin\BaseUsers;
class Index extends BaseUsers
{
public function post()
protected function post(array $request = [], array $post = [])
{
self::checkAdminAccess();
@ -67,7 +67,7 @@ class Index extends BaseUsers
DI::baseUrl()->redirect(DI::args()->getQueryString());
}
public function content(): string
protected function content(array $request = []): string
{
parent::content();

View file

@ -33,7 +33,7 @@ use Friendica\Util\Temporal;
class Pending extends BaseUsers
{
public function post()
protected function post(array $request = [], array $post = [])
{
self::checkAdminAccess();
@ -58,7 +58,7 @@ class Pending extends BaseUsers
DI::baseUrl()->redirect('admin/users/pending');
}
public function content(): string
protected function content(array $request = []): string
{
parent::content();

View file

@ -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;
@ -222,10 +199,10 @@ class ApiResponse
switch ($format) {
case 'xml':
$this->setHeader('Content-Type: text/xml');
$this->setType(static::TYPE_XML);
break;
case 'json':
$this->setHeader('Content-Type: application/json');
$this->setType(static::TYPE_JSON);
if (!empty($return)) {
$json = json_encode(end($return));
if (!empty($_GET['callback'])) {
@ -235,14 +212,14 @@ class ApiResponse
}
break;
case 'rss':
$this->setHeader('Content-Type: application/rss+xml');
$this->setType(static::TYPE_RSS);
break;
case 'atom':
$this->setHeader('Content-Type: application/atom+xml');
$this->setType(static::TYPE_ATOM);
break;
}
$this->printOutput($return);
$this->addContent($return);
}
/**

View file

@ -40,7 +40,7 @@ use Friendica\Module\BaseApi;
*/
class Activity extends BaseApi
{
public function rawContent()
protected function rawContent(array $request = [])
{
self::checkAllowedScope(self::SCOPE_WRITE);
$uid = self::getCurrentUserID();
@ -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);
}
}
}

View file

@ -30,7 +30,7 @@ use Friendica\Module\BaseApi;
*/
class Setseen extends BaseApi
{
public function rawContent()
protected function rawContent(array $request = [])
{
self::checkAllowedScope(self::SCOPE_WRITE);
$uid = self::getCurrentUserID();
@ -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);
}
}

View file

@ -33,7 +33,7 @@ use Friendica\Module\BaseApi;
*/
class Index extends BaseApi
{
public function rawContent()
protected function rawContent(array $request = [])
{
self::checkAllowedScope(self::SCOPE_READ);
$uid = self::getCurrentUserID();
@ -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);
}
}

View file

@ -32,7 +32,7 @@ use Friendica\Network\HTTPException\BadRequestException;
*/
class Delete extends BaseApi
{
public function rawContent()
protected function rawContent(array $request = [])
{
self::checkAllowedScope(self::SCOPE_WRITE);
$uid = self::getCurrentUserID();
@ -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');
}

View file

@ -32,17 +32,17 @@ require_once __DIR__ . '/../../../../include/api.php';
*/
class Index extends BaseApi
{
public function post()
protected function post(array $request = [], array $post = [])
{
self::checkAllowedScope(self::SCOPE_WRITE);
}
public function delete()
protected function delete()
{
self::checkAllowedScope(self::SCOPE_WRITE);
}
public function rawContent()
protected function rawContent(array $request = [])
{
echo api_call(DI::args()->getCommand(), $this->parameters['extension'] ?? 'json');
exit();

View file

@ -31,7 +31,7 @@ use Friendica\Object\Api\Friendica\Notification as ApiNotification;
*/
class Notification extends BaseApi
{
public function rawContent()
protected function rawContent(array $request = [])
{
self::checkAllowedScope(self::SCOPE_READ);
$uid = self::getCurrentUserID();
@ -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);
}
}

View file

@ -33,7 +33,7 @@ use Friendica\Network\HTTPException\InternalServerErrorException;
*/
class Delete extends BaseApi
{
public function rawContent()
protected function rawContent(array $request = [])
{
self::checkAllowedScope(self::SCOPE_WRITE);
$uid = self::getCurrentUserID();
@ -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");
}

View file

@ -34,7 +34,7 @@ use Friendica\Network\HTTPException\InternalServerErrorException;
*/
class Delete extends BaseApi
{
public function rawContent()
protected function rawContent(array $request = [])
{
self::checkAllowedScope(self::SCOPE_WRITE);
$uid = self::getCurrentUserID();
@ -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");
}

View file

@ -32,7 +32,7 @@ use Friendica\Network\HTTPException\InternalServerErrorException;
*/
class Update extends BaseApi
{
public function rawContent()
protected function rawContent(array $request = [])
{
self::checkAllowedScope(self::SCOPE_WRITE);
$uid = self::getCurrentUserID();
@ -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");
}

View file

@ -33,7 +33,7 @@ use Friendica\Network\HTTPException;
*/
class Show extends BaseApi
{
public function rawContent()
protected function rawContent(array $request = [])
{
self::checkAllowedScope(self::SCOPE_READ);
$uid = self::getCurrentUserID();
@ -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);
}
/**

View file

@ -31,7 +31,7 @@ use Friendica\Module\Register;
*/
class Config extends BaseApi
{
public function rawContent()
protected function rawContent(array $request = [])
{
$config = [
'site' => [
@ -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);
}
}

View file

@ -29,8 +29,8 @@ use Friendica\DI;
*/
class Version extends BaseApi
{
public function rawContent()
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);
}
}

View file

@ -29,7 +29,7 @@ use Friendica\DI;
*/
class Test extends BaseApi
{
public function rawContent()
protected function rawContent(array $request = [])
{
if (!empty($this->parameters['extension']) && ($this->parameters['extension'] == 'xml')) {
$ok = 'true';
@ -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);
}
}

View file

@ -35,7 +35,7 @@ class Accounts extends BaseApi
/**
* @throws \Friendica\Network\HTTPException\InternalServerErrorException
*/
public function rawContent()
protected function rawContent(array $request = [])
{
$uid = self::getCurrentUserID();

View file

@ -32,7 +32,7 @@ use Friendica\Module\BaseApi;
*/
class Block extends BaseApi
{
public function post()
protected function post(array $request = [], array $post = [])
{
self::checkAllowedScope(self::SCOPE_FOLLOW);
$uid = self::getCurrentUserID();

View file

@ -32,7 +32,7 @@ class FeaturedTags extends BaseApi
/**
* @throws \Friendica\Network\HTTPException\InternalServerErrorException
*/
public function rawContent()
protected function rawContent(array $request = [])
{
self::checkAllowedScope(self::SCOPE_READ);

View file

@ -31,7 +31,7 @@ use Friendica\Module\BaseApi;
*/
class Follow extends BaseApi
{
public function post()
protected function post(array $request = [], array $post = [])
{
self::checkAllowedScope(self::SCOPE_FOLLOW);
$uid = self::getCurrentUserID();

View file

@ -34,7 +34,7 @@ class Followers extends BaseApi
/**
* @throws \Friendica\Network\HTTPException\InternalServerErrorException
*/
public function rawContent()
protected function rawContent(array $request = [])
{
self::checkAllowedScope(self::SCOPE_READ);
$uid = self::getCurrentUserID();

View file

@ -34,7 +34,7 @@ class Following extends BaseApi
/**
* @throws \Friendica\Network\HTTPException\InternalServerErrorException
*/
public function rawContent()
protected function rawContent(array $request = [])
{
self::checkAllowedScope(self::SCOPE_READ);
$uid = self::getCurrentUserID();

View file

@ -32,7 +32,7 @@ class IdentityProofs extends BaseApi
/**
* @throws \Friendica\Network\HTTPException\InternalServerErrorException
*/
public function rawContent()
protected function rawContent(array $request = [])
{
self::checkAllowedScope(self::SCOPE_READ);

View file

@ -35,7 +35,7 @@ class Lists extends BaseApi
/**
* @throws \Friendica\Network\HTTPException\InternalServerErrorException
*/
public function rawContent()
protected function rawContent(array $request = [])
{
self::checkAllowedScope(self::SCOPE_READ);
$uid = self::getCurrentUserID();

View file

@ -31,7 +31,7 @@ use Friendica\Module\BaseApi;
*/
class Mute extends BaseApi
{
public function post()
protected function post(array $request = [], array $post = [])
{
self::checkAllowedScope(self::SCOPE_FOLLOW);
$uid = self::getCurrentUserID();

View file

@ -32,7 +32,7 @@ use Friendica\Module\BaseApi;
*/
class Note extends BaseApi
{
public function post()
protected function post(array $request = [], array $post = [])
{
self::checkAllowedScope(self::SCOPE_WRITE);
$uid = self::getCurrentUserID();

View file

@ -34,7 +34,7 @@ class Relationships extends BaseApi
/**
* @throws \Friendica\Network\HTTPException\InternalServerErrorException
*/
public function rawContent()
protected function rawContent(array $request = [])
{
self::checkAllowedScope(self::SCOPE_READ);
$uid = self::getCurrentUserID();

View file

@ -37,7 +37,7 @@ class Search extends BaseApi
/**
* @throws \Friendica\Network\HTTPException\InternalServerErrorException
*/
public function rawContent()
protected function rawContent(array $request = [])
{
self::checkAllowedScope(self::SCOPE_READ);
$uid = self::getCurrentUserID();

View file

@ -39,7 +39,7 @@ class Statuses extends BaseApi
/**
* @throws \Friendica\Network\HTTPException\InternalServerErrorException
*/
public function rawContent()
protected function rawContent(array $request = [])
{
$uid = self::getCurrentUserID();

View file

@ -31,7 +31,7 @@ use Friendica\Module\BaseApi;
*/
class Unblock extends BaseApi
{
public function post()
protected function post(array $request = [], array $post = [])
{
self::checkAllowedScope(self::SCOPE_FOLLOW);
$uid = self::getCurrentUserID();

View file

@ -31,7 +31,7 @@ use Friendica\Module\BaseApi;
*/
class Unfollow extends BaseApi
{
public function post()
protected function post(array $request = [], array $post = [])
{
self::checkAllowedScope(self::SCOPE_FOLLOW);
$uid = self::getCurrentUserID();

View file

@ -31,7 +31,7 @@ use Friendica\Module\BaseApi;
*/
class Unmute extends BaseApi
{
public function post()
protected function post(array $request = [], array $post = [])
{
self::checkAllowedScope(self::SCOPE_FOLLOW);
$uid = self::getCurrentUserID();

View file

@ -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;
@ -32,7 +31,7 @@ use Friendica\Util\HTTPInputData;
*/
class UpdateCredentials extends BaseApi
{
public function patch()
protected function patch()
{
self::checkAllowedScope(self::SCOPE_WRITE);
$uid = self::getCurrentUserID();
@ -41,6 +40,6 @@ class UpdateCredentials extends BaseApi
Logger::info('Patch data', ['data' => $data]);
DI::apiResponse()->unsupported(Router::PATCH);
$this->response->unsupported(Router::PATCH);
}
}

View file

@ -35,7 +35,7 @@ class VerifyCredentials extends BaseApi
/**
* @throws \Friendica\Network\HTTPException\InternalServerErrorException
*/
public function rawContent()
protected function rawContent(array $request = [])
{
self::checkAllowedScope(self::SCOPE_READ);
$uid = self::getCurrentUserID();

View file

@ -32,7 +32,7 @@ class Announcements extends BaseApi
/**
* @throws \Friendica\Network\HTTPException\InternalServerErrorException
*/
public function rawContent()
protected function rawContent(array $request = [])
{
self::checkAllowedScope(self::SCOPE_READ);

View file

@ -35,7 +35,7 @@ class Apps extends BaseApi
/**
* @throws \Friendica\Network\HTTPException\InternalServerErrorException
*/
public function post()
protected function post(array $request = [], array $post = [])
{
$request = self::getRequest([
'client_name' => '',

View file

@ -30,7 +30,7 @@ use Friendica\Module\BaseApi;
*/
class VerifyCredentials extends BaseApi
{
public function rawContent()
protected function rawContent(array $request = [])
{
self::checkAllowedScope(self::SCOPE_READ);
$application = self::getCurrentApplication();

View file

@ -34,7 +34,7 @@ class Blocks extends BaseApi
/**
* @throws \Friendica\Network\HTTPException\InternalServerErrorException
*/
public function rawContent()
protected function rawContent(array $request = [])
{
self::checkAllowedScope(self::SCOPE_READ);
$uid = self::getCurrentUserID();

View file

@ -36,7 +36,7 @@ class Bookmarks extends BaseApi
/**
* @throws HTTPException\InternalServerErrorException
*/
public function rawContent()
protected function rawContent(array $request = [])
{
self::checkAllowedScope(self::SCOPE_READ);
$uid = self::getCurrentUserID();

View file

@ -31,7 +31,7 @@ use Friendica\Module\BaseApi;
*/
class Conversations extends BaseApi
{
public function delete()
protected function delete()
{
self::checkAllowedScope(self::SCOPE_WRITE);
$uid = self::getCurrentUserID();
@ -49,7 +49,7 @@ class Conversations extends BaseApi
/**
* @throws \Friendica\Network\HTTPException\InternalServerErrorException
*/
public function rawContent()
protected function rawContent(array $request = [])
{
self::checkAllowedScope(self::SCOPE_READ);
$uid = self::getCurrentUserID();

View file

@ -31,7 +31,7 @@ use Friendica\Module\BaseApi;
*/
class Read extends BaseApi
{
public function post()
protected function post(array $request = [], array $post = [])
{
self::checkAllowedScope(self::SCOPE_WRITE);
$uid = self::getCurrentUserID();

View file

@ -37,7 +37,7 @@ class CustomEmojis extends BaseApi
* @throws \ImagickException
* @see https://docs.joinmastodon.org/methods/accounts/follow_requests#pending-follows
*/
public function rawContent()
protected function rawContent(array $request = [])
{
$emojis = DI::mstdnEmoji()->createCollectionFromSmilies(Smilies::getList());

View file

@ -39,7 +39,7 @@ class Directory extends BaseApi
* @throws \ImagickException
* @see https://docs.joinmastodon.org/methods/instance/directory/
*/
public function rawContent()
protected function rawContent(array $request = [])
{
$request = self::getRequest([
'offset' => 0, // How many accounts to skip before returning results. Default 0.

View file

@ -32,7 +32,7 @@ class Endorsements extends BaseApi
/**
* @throws \Friendica\Network\HTTPException\InternalServerErrorException
*/
public function rawContent()
protected function rawContent(array $request = [])
{
System::jsonExit([]);
}

View file

@ -37,7 +37,7 @@ class Favourited extends BaseApi
/**
* @throws HTTPException\InternalServerErrorException
*/
public function rawContent()
protected function rawContent(array $request = [])
{
self::checkAllowedScope(self::SCOPE_READ);
$uid = self::getCurrentUserID();

View file

@ -31,17 +31,17 @@ use Friendica\Module\BaseApi;
*/
class Filters extends BaseApi
{
public function post()
public function post(array $request = [], array $post = [])
{
self::checkAllowedScope(self::SCOPE_WRITE);
DI::apiResponse()->unsupported(Router::POST);
$this->response->unsupported(Router::POST);
}
/**
* @throws \Friendica\Network\HTTPException\InternalServerErrorException
*/
public function rawContent()
protected function rawContent(array $request = [])
{
self::checkAllowedScope(self::SCOPE_READ);

View file

@ -42,7 +42,7 @@ class FollowRequests extends BaseApi
* @see https://docs.joinmastodon.org/methods/accounts/follow_requests#accept-follow
* @see https://docs.joinmastodon.org/methods/accounts/follow_requests#reject-follow
*/
public function post()
protected function post(array $request = [], array $post = [])
{
self::checkAllowedScope(self::SCOPE_FOLLOW);
$uid = self::getCurrentUserID();
@ -82,7 +82,7 @@ class FollowRequests extends BaseApi
* @throws \ImagickException
* @see https://docs.joinmastodon.org/methods/accounts/follow_requests/
*/
public function rawContent()
protected function rawContent(array $request = [])
{
self::checkAllowedScope(self::SCOPE_READ);
$uid = self::getCurrentUserID();

View file

@ -33,7 +33,7 @@ class Instance extends BaseApi
/**
* @throws \Friendica\Network\HTTPException\InternalServerErrorException
*/
public function rawContent()
protected function rawContent(array $request = [])
{
System::jsonExit(InstanceEntity::get());
}

View file

@ -36,7 +36,7 @@ class Peers extends BaseApi
/**
* @throws HTTPException\InternalServerErrorException
*/
public function rawContent()
protected function rawContent(array $request = [])
{
$return = [];

View file

@ -36,7 +36,7 @@ class Rules extends BaseApi
/**
* @throws HTTPException\InternalServerErrorException
*/
public function rawContent()
protected function rawContent(array $request = [])
{
$rules = [];
$id = 0;

View file

@ -31,7 +31,7 @@ use Friendica\Model\Group;
*/
class Lists extends BaseApi
{
public function delete()
protected function delete()
{
self::checkAllowedScope(self::SCOPE_WRITE);
$uid = self::getCurrentUserID();
@ -51,7 +51,7 @@ class Lists extends BaseApi
System::jsonExit([]);
}
public function post()
protected function post(array $request = [], array $post = [])
{
self::checkAllowedScope(self::SCOPE_WRITE);
$uid = self::getCurrentUserID();
@ -91,7 +91,7 @@ class Lists extends BaseApi
/**
* @throws \Friendica\Network\HTTPException\InternalServerErrorException
*/
public function rawContent()
protected function rawContent(array $request = [])
{
self::checkAllowedScope(self::SCOPE_READ);
$uid = self::getCurrentUserID();

View file

@ -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;
/**
@ -35,20 +34,20 @@ use Friendica\Module\BaseApi;
*/
class Accounts extends BaseApi
{
public function delete()
protected function delete()
{
DI::apiResponse()->unsupported(Router::DELETE);
$this->response->unsupported(Router::DELETE);
}
public function post()
protected function post(array $request = [], array $post = [])
{
DI::apiResponse()->unsupported(Router::POST);
$this->response->unsupported(Router::POST);
}
/**
* @throws \Friendica\Network\HTTPException\InternalServerErrorException
*/
public function rawContent()
protected function rawContent(array $request = [])
{
self::checkAllowedScope(self::SCOPE_READ);
$uid = self::getCurrentUserID();

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