| @@ 78-94 (lines=17) @@ | ||
| 75 | * |
|
| 76 | * @return XML sitemap |
|
| 77 | */ |
|
| 78 | public function generateSitemap() |
|
| 79 | { |
|
| 80 | $sitemapXml = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<urlset xmlns=\"http://www.sitemaps.org/schemas/sitemap/0.9\">\n"; |
|
| 81 | ||
| 82 | $repository = $this->em->getRepository('WebCMS\Entity\Page'); |
|
| 83 | $pages = $repository->findAll(); |
|
| 84 | ||
| 85 | foreach ($pages as $page) { |
|
| 86 | if ($page->getParent() !== null && $page->getVisible()) { |
|
| 87 | $sitemapXml .= "<url>\n\t<loc>".$this->getSitemapLink($page)."</loc>\n</url>\n"; |
|
| 88 | } |
|
| 89 | } |
|
| 90 | ||
| 91 | $sitemapXml .= '</urlset>'; |
|
| 92 | ||
| 93 | file_put_contents('./sitemap.xml', $sitemapXml); |
|
| 94 | } |
|
| 95 | ||
| 96 | /** |
|
| 97 | * Get single sitemap link url address. |
|
| @@ 273-289 (lines=17) @@ | ||
| 270 | } |
|
| 271 | } |
|
| 272 | ||
| 273 | public function generateSitemap() |
|
| 274 | { |
|
| 275 | $sitemapXml = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<urlset xmlns=\"http://www.sitemaps.org/schemas/sitemap/0.9\">\n"; |
|
| 276 | ||
| 277 | $repository = $this->em->getRepository('WebCMS\Entity\Page'); |
|
| 278 | $pages = $repository->findAll(); |
|
| 279 | ||
| 280 | foreach ($pages as $page) { |
|
| 281 | if ($page->getParent() !== null) { |
|
| 282 | $sitemapXml .= "<url>\n\t<loc>".$this->getSitemapLink($page)."</loc>\n</url>\n"; |
|
| 283 | } |
|
| 284 | } |
|
| 285 | ||
| 286 | $sitemapXml .= '</urlset>'; |
|
| 287 | ||
| 288 | file_put_contents('./sitemap.xml', $sitemapXml); |
|
| 289 | } |
|
| 290 | ||
| 291 | private function getSitemapLink($page) |
|
| 292 | { |
|