Finish sending webmentions

This commit is contained in:
Lewis Dale 2023-03-08 21:39:11 +00:00
parent b63ada6dea
commit df226b2897
1 changed files with 15 additions and 27 deletions

View File

@ -15,13 +15,11 @@ class Webmention {
}
public function sendForPage(string $source) : void {
// $urls = $this->getUrls($source);
$urls = $this->getUrls($source);
// foreach($urls as $target) {
// $this->sendWebmention($source, $target);
// }
$this->sendWebmention($source, "https://webmention.rocks/test/23/page");
foreach($urls as $target) {
$this->sendWebmention($source, $target);
}
}
private function getUrls(string $url) : array {
@ -40,32 +38,22 @@ class Webmention {
}
private function sendWebmention(string $source, string $target) {
// 1. Endpoint discovery
// 1.1 Parse page
// 1.2 Look for rel="webmention"
$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 {
$response = $this->client->request('GET', $url);
// echo "<pre>";
// var_dump($response->getInfo());
// echo "</pre>";
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;
// }
}
}
?>