federator/php/federator/api/wellknown.php
Yannis Vogel 530caa7ea6
initial mastodon support and minor improvements
- reworked plugin handling. Main now registers and keeps all connectors and based on request we select the correct one and pass it (mainly for clean async-request-handling)
- added outbox functionality for mastodon
- changed image-mime-type approach to retrieve mime-type from the url, this way we don't need to store the images on our server/download each image
- added host for connector for better debugging
- minor bug-fixes
2025-04-08 22:03:19 +02:00

107 lines
2.7 KiB
PHP

<?php
/**
* SPDX-FileCopyrightText: 2024 Sascha Nitsch (grumpydeveloper) https://contentnation.net/@grumpydevelop
* SPDX-License-Identifier: GPL-3.0-or-later
*
* @author Sascha Nitsch (grumpydeveloper)
**/
namespace Federator\Api;
/**
* .well-known handlers
*/
class WellKnown implements APIInterface
{
/**
* main instance
*
* @var \Federator\Main $main
*/
private $main;
/**
* response from sub-calls
*
* @var string $response
*/
private $response;
/**
* constructor
*
* @param \Federator\Main $main main instance
*/
public function __construct($main)
{
$this->main = $main;
}
/**
* return host-meta information
*
* @return true
*/
private function hostMeta()
{
$data = [
'fqdn' => $_SERVER['SERVER_NAME']
];
$this->response = $this->main->renderTemplate('host-meta.xml', $data);
return true;
}
/**
* run given url path
*
* @param array<string> $paths path array split by /
* @param \Federator\Data\User|false $user user who is calling us @unused-param
* @return bool true on success
*/
public function exec($paths, $user, $connector)
{
$method = $_SERVER["REQUEST_METHOD"];
switch ($method) {
case 'GET':
switch (sizeof($paths)) {
case 2:
if ($paths[0] === 'nodeinfo') {
$ni = new WellKnown\NodeInfo($this, $this->main);
return $ni->exec($paths, $connector);
}
switch ($paths[1]) {
case 'host-meta':
return $this->hostMeta();
case 'nodeinfo':
$ni = new WellKnown\NodeInfo($this, $this->main);
return $ni->exec($paths, $connector);
case 'webfinger':
$wf = new WellKnown\WebFinger($this, $this->main);
return $wf->exec();
}
}
break;
}
$this->main->setResponseCode(404);
return false;
}
/**
* set response
*
* @param string $response response to set
* @return void
*/
public function setResponse($response)
{
$this->response = $response;
}
/**
* get internal represenation as json string
* @return string json string or html
*/
public function toJson()
{
return $this->response;
}
}