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