Finish sending webmentions

This commit is contained in:
Lewis Dale 2023-03-08 21:39:11 +00:00
parent b63ada6dea
commit df226b2897

View File

@ -15,13 +15,11 @@ class Webmention {
} }
public function sendForPage(string $source) : void { public function sendForPage(string $source) : void {
// $urls = $this->getUrls($source); $urls = $this->getUrls($source);
// foreach($urls as $target) { foreach($urls as $target) {
// $this->sendWebmention($source, $target); $this->sendWebmention($source, $target);
// } }
$this->sendWebmention($source, "https://webmention.rocks/test/23/page");
} }
private function getUrls(string $url) : array { private function getUrls(string $url) : array {
@ -40,32 +38,22 @@ class Webmention {
} }
private function sendWebmention(string $source, string $target) { private function sendWebmention(string $source, string $target) {
// 1. Endpoint discovery
// 1.1 Parse page
// 1.2 Look for rel="webmention"
$endpoint = $this->getWebmentionEndpoint($target); $endpoint = $this->getWebmentionEndpoint($target);
echo ($endpoint ?? "no :(") . "<br />";
// 2. Send webmention to endpoint if ($endpoint) {
echo "Sending for " . $endpoint . "<br />";
$this->client->request('POST', $endpoint,
[
"body" => [
"source" => $source,
"target" => $target
]
]);
}
} }
private function getWebmentionEndpoint(string $url) : string | null { private function getWebmentionEndpoint(string $url) : string | null {
$response = $this->client->request('GET', $url); $response = $this->client->request('GET', $url);
// echo "<pre>";
// var_dump($response->getInfo());
// echo "</pre>";
return EndpointParser::parse($response); return EndpointParser::parse($response);
// $doc = new Crawler($page);
// $links = $doc->filter('link[rel="webmention"]');
// if ($links->count()) {
// return $links->first()->attr('href');
// } else {
// return null;
// }
} }
} }
?>