/** * action show * * @return void */ public function showAction() { // define some variables $recursive = (int) $this->settings['recursive'] < 10 ? (int) $this->settings['recursive'] : 10; // try to get all root-page-uids if ($this->settings['pages']) { $rootpageUids = \TYPO3\CMS\Extbase\Utility\ArrayUtility::integerExplode(",", $this->settings['pages']); } else { $rootpageUids = array($GLOBALS['TSFE']->id); } switch ($this->settings['layout']) { case "overview_from_directory": case "overview_from_directory_small": $queryGenerator = $this->objectManager->get('TYPO3\\CMS\\Core\\Database\\QueryGenerator'); $pagesArr = array(); $i = 0; foreach ($rootpageUids as $rootpageUid) { $pageUidStr = $queryGenerator->getTreeList($rootpageUid, $recursive, 0, " doktype IN (1,2,3,4)"); if ($pageUidStr) { $pagesArr = array_merge($pagesArr, \TYPO3\CMS\Extbase\Utility\ArrayUtility::integerExplode(",", $pageUidStr)); } // remove rootpageUid foreach (array_keys($pagesArr, $rootpageUid, false) as $key) { unset($pagesArr[$key]); } } // find the pages $pages = $this->pageRepository->findByUidArray(array_unique($pagesArr), "sorting"); $this->view->assign("pages", $pages); $this->view->assign("current", $GLOBALS['TSFE']->id); return $this->view->render(); break; } return ""; }
/** * action xml * @throws \Exception * @return string XML * @todo Check and implement the correct crdate/lastmod of content elements in translations. */ public function xmlAction() { if (isset($this->settings['rootpageUids']) === FALSE || is_array($this->settings['rootpageUids']) === FALSE) { throw new \Exception("You have to define settings.rootpageUids with the keys uid and depth!", 1458210595); } $dokTypes = \TYPO3\CMS\Extbase\Utility\ArrayUtility::integerExplode(",", $this->settings['dokTypes']); if (!count($dokTypes)) { throw new \Exception("You have to define settings.dokTypes! (almost: 1,2)", 1458210596); } // define some variables $uriBuilder = $this->controllerContext->getUriBuilder(); $queryGenerator = $this->objectManager->get('TYPO3\\CMS\\Core\\Database\\QueryGenerator'); // find the pages $pagesArr = array(); $i = 0; foreach ($this->settings['rootpageUids'] as $rootpageConfiguration) { if (isset($rootpageConfiguration['uid']) && isset($rootpageConfiguration['depth'])) { $pagesUidStr = $queryGenerator->getTreeList((int) $rootpageConfiguration['uid'], (int) $rootpageConfiguration['depth'], 0, " doktype IN (" . implode(",", $dokTypes) . ")"); if ($pagesUidStr) { $pagesArr = array_merge($pagesArr, \TYPO3\CMS\Extbase\Utility\ArrayUtility::integerExplode(",", $pagesUidStr)); } } } // find the pages $pages = $this->pageRepository->findByUidArray(array_unique($pagesArr)); // build xml $builtUris = []; $xml = '<?xml version="1.0" encoding="UTF-8"?>'; $xml .= PHP_EOL . '<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"'; $xml .= PHP_EOL . ' xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"'; $xml .= PHP_EOL . ' xsi:schemaLocation="http://www.sitemaps.org/schemas/sitemap/0.9 http://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd">'; foreach ($pages as $page) { // if ($page->isNavHide () || $page->isHideinxml () || $page->getDoktype () == 4) { if ($page->isHideinxml() || $page->getDoktype() == 4) { continue; } // location $uriBuilder->reset(); $uriBuilder->setCreateAbsoluteUri(true); $uriBuilder->setTargetPageUid($page->getUid()); $uri = $uriBuilder->build(); if (in_array($uri, $builtUris)) { continue; } $builtUris[] = $uri; $xml .= PHP_EOL . ' <url>'; $xml .= PHP_EOL . ' <loc>' . htmlentities($uri, ENT_XML1, "UTF-8") . '</loc>'; // lastmod $latestContentElement = $this->contentRepository->findOneLatest($page); if ($latestContentElement && $latestContentElement->getTstamp()) { $xml .= PHP_EOL . ' <lastmod>' . $latestContentElement->getTstamp()->format("c") . '</lastmod>'; } else { if ($page->getTstamp()) { $xml .= PHP_EOL . ' <lastmod>' . $page->getTstamp()->format("c") . '</lastmod>'; } } unset($latestContentElement); // changefreq if ($page->getChangefreq()) { $xml .= PHP_EOL . ' <changefreq>' . $page->getChangefreq() . '</changefreq>'; } // priority if ($page->getPriority()) { $xml .= PHP_EOL . ' <priority>' . $page->getPriority() . '</priority>'; } $xml .= PHP_EOL . ' </url>'; } $additionalLanguages = \TYPO3\CMS\Extbase\Utility\ArrayUtility::integerExplode(",", $this->settings['additionalLanguages']); if (count($additionalLanguages)) { foreach ($additionalLanguages as $additionalLanguage) { // find the pages $pagesTranslation = $this->pageTranslationRepository->findByPidArray(array_unique($pagesArr), $additionalLanguage); foreach ($pagesTranslation as $page) { // if ($page->isNavHide () || $page->isHideinxml () || $page->getDoktype () == 4) { if ($page->isHideinxml() || $page->getDoktype() == 4) { continue; } // location $uriBuilder->reset(); $uriBuilder->setCreateAbsoluteUri(true); $uriBuilder->setTargetPageUid($page->getPid()); $uriBuilder->setArguments(["L" => $additionalLanguage]); $uri = $uriBuilder->build(); if (in_array($uri, $builtUris)) { continue; } $builtUris[] = $uri; $xml .= PHP_EOL . ' <url>'; $xml .= PHP_EOL . ' <loc>' . htmlentities($uri, ENT_XML1, "UTF-8") . '</loc>'; // lastmod $latestContentElement = $this->contentRepository->findOneLatest($page); if ($latestContentElement && $latestContentElement->getTstamp()) { $xml .= PHP_EOL . ' <lastmod>' . $latestContentElement->getTstamp()->format("c") . '</lastmod>'; } else { if ($page->getTstamp()) { $xml .= PHP_EOL . ' <lastmod>' . $page->getTstamp()->format("c") . '</lastmod>'; } } unset($latestContentElement); // changefreq if ($page->getChangefreq()) { $xml .= PHP_EOL . ' <changefreq>' . $page->getChangefreq() . '</changefreq>'; } // priority if ($page->getPriority()) { $xml .= PHP_EOL . ' <priority>' . $page->getPriority() . '</priority>'; } $xml .= PHP_EOL . ' </url>'; } } } $xml .= PHP_EOL . '</urlset>'; $xml .= PHP_EOL . '<!-- count: ' . count($builtUris) . ' URI -->'; return $xml; }