/** * Parse the robots.txt text file to find the sitemap * * @return string|boolean */ protected function getSitemapUrl() { $request = new Request($this->request->getUrl(), $this->input->getOption('insecure')); $response = $request->get('robots.txt'); $sitemap = new Sitemap(); $sitemap->setRequest($this->request); return $sitemap->getSitemapFromRobotsTxt($response); }
/** * Parse the robots.txt text file to find the sitemap * * @return string */ protected function getSitemapUrl() { $request = new Request(); $response = $request->fetch($this->url . 'robots.txt'); $sitemap = new Sitemap(); $sitemap->setRequest($this->request); $sitemap = $sitemap->getSitemapFromRobotsTxt($response); if ($sitemap === false) { $this->output->writeln('<error>Sitemap is not declared in robots.txt</error>'); return $this->url . 'sitemap.xml'; } $this->output->writeln('<info>Sitemap is declared in robots.txt</info>'); return (string) $sitemap; }
/** * Mock a sitemap response * * @param integer $status * @param string $body * * @return boolean|string */ protected function mockSitemap($status, $body) { $mock = new MockHandler([new Response($status, [], $body)]); $handler = HandlerStack::create($mock); $client = new Client(['handler' => $handler, 'http_errors' => false]); $response = $client->request('GET', '/'); $sitemap = new Sitemap(); return $sitemap->setRequest(new Request())->getSitemapFromRobotsTxt($response); }
/** * Check for a valid sitemap * * @return void */ public function checkSitemap() { $rows = array(); $request = new Request(); $response = $request->fetch($this->url . 'robots.txt'); $sitemap = new Sitemap(); $sitemapUrl = $sitemap->getSitemapFromRobotsTxt($response); if ($sitemapUrl === false) { $rows[] = array('<span class="fail">Sitemap is not declared in <a href="' . $this->url . 'robots.txt" target="_blank">robots.txt</a></span>'); $sitemapUrl = $this->url . 'sitemap.xml'; } else { $rows[] = array('<span class="pass">Sitemap is declared in <a href="' . $this->url . 'robots.txt" target="_blank">robots.txt</a></span></span>'); } $request = new Request(); $response = $request->fetch((string) $sitemapUrl, array(CURLOPT_NOBODY => true, CURLOPT_FOLLOWLOCATION => true)); if ($response->code == 200) { $rows[] = array('<span class="pass"><a href="' . $sitemapUrl . '" target="_blank">Sitemap</a> is accessible</span>'); } else { $rows[] = array('<span class="fail"><a href="' . $sitemapUrl . '" target="_blank">Sitemap</a> is not accessible</span>'); } $this->respond(array('body' => $rows)); }
/** * Check for a valid sitemap * * @return void */ public function checkSitemap() { $rows = []; $response = $this->request->get('robots.txt'); $sitemap = new Sitemap(); $sitemap->setRequest($this->request); $sitemapUrl = $sitemap->getSitemapFromRobotsTxt($response); if ($sitemapUrl === false) { $rows[] = ['<span class="fail">Sitemap is not declared in <a href="' . $this->url . 'robots.txt" target="_blank">robots.txt</a></span>']; $sitemapUrl = $this->url . 'sitemap.xml'; } else { $rows[] = ['<span class="pass">Sitemap is declared in <a href="' . $this->url . 'robots.txt" target="_blank">robots.txt</a></span></span>']; } $response = $this->request->get($sitemapUrl); if ($response->getStatusCode() == 200) { $rows[] = ['<span class="pass"><a href="' . $sitemapUrl . '" target="_blank">Sitemap</a> is accessible</span>']; } else { $rows[] = ['<span class="fail"><a href="' . $sitemapUrl . '" target="_blank">Sitemap</a> is not accessible</span>']; } $this->respond(['body' => $rows]); }