client = HttpClient::create(); } public function sendForPage(string $source) : void { // $urls = $this->getUrls($source); // foreach($urls as $target) { // $this->sendWebmention($source, $target); // } $this->sendWebmention($source, "https://webmention.rocks/test/1"); } private function getUrls(string $url) : array { $page = file_get_contents($url); $doc = new Crawler($page); $urls = []; foreach ($doc->filter('.h-entry a') as $anchor) { $target_url = $anchor->attributes->getNamedItem('href')->textContent; if ($target_url !== null && strlen($target_url)) { $urls[] = $target_url; } } return $urls; } 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 } 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; // } } } ?>