44 lines
1.2 KiB
PHP
44 lines
1.2 KiB
PHP
<?php declare(strict_types=1);
|
|
|
|
require_once __DIR__ . "/vendor/autoload.php";
|
|
|
|
use Lewisdale\Webmentions\Endpoint;
|
|
use Lewisdale\Webmentions\Exceptions\InvalidTargetException;
|
|
use Lewisdale\Webmentions\Exceptions\InvalidUrlException;
|
|
use Lewisdale\Webmentions\Router\Request;
|
|
use Lewisdale\Webmentions\Router\Router;
|
|
use Lewisdale\Webmentions\Router\Response;
|
|
use Lewisdale\Webmentions\Router\StatusCode;
|
|
use Lewisdale\Webmentions\Webmention;
|
|
|
|
$mentioner = new Webmention();
|
|
|
|
$router = new Router();
|
|
|
|
$router->post("/send", function(Request $req, Response $response) use ($webmention) {
|
|
$source = $req->query["source"];
|
|
$webmention->sendForPage($source);
|
|
});
|
|
|
|
$router->post("/endpoint", function(Request $req, Response $response) {
|
|
$source = $req->post['source'];
|
|
$target = $req->post['target'];
|
|
|
|
$endpoint = new Endpoint();
|
|
|
|
try {
|
|
$endpoint->receiveWebmention($source, $target);
|
|
} catch (InvalidUrlException $e) {
|
|
$response->status_code = StatusCode::BadRequest;
|
|
return "Source and target must be valid URLs";
|
|
} catch (InvalidTargetException $e) {
|
|
$response->status_code = StatusCode::BadRequest;
|
|
return "Target must be on the domain lewisdale.dev";
|
|
}
|
|
|
|
$response->status_code = StatusCode::Created;
|
|
});
|
|
|
|
$router->dispatch();
|
|
|
|
?>
|