From df226b2897f78ea5dca7e94536b4e9106db4ee38 Mon Sep 17 00:00:00 2001 From: Lewis Dale Date: Wed, 8 Mar 2023 21:39:11 +0000 Subject: [PATCH] Finish sending webmentions --- src/Webmention.php | 42 +++++++++++++++--------------------------- 1 file changed, 15 insertions(+), 27 deletions(-) diff --git a/src/Webmention.php b/src/Webmention.php index fc104bb..078550a 100644 --- a/src/Webmention.php +++ b/src/Webmention.php @@ -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 :(") . "
"; - // 2. Send webmention to endpoint + + if ($endpoint) { + echo "Sending for " . $endpoint . "
"; + $this->client->request('POST', $endpoint, + [ + "body" => [ + "source" => $source, + "target" => $target + ] + ]); + } } private function getWebmentionEndpoint(string $url) : string | null { $response = $this->client->request('GET', $url); - // echo "
";
-        // var_dump($response->getInfo());
-        // echo "
"; - 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; - // } - } } -?> \ No newline at end of file