/** * 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); }
/** * 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]); }