‪TYPO3CMS  10.4
PagesXmlSitemapDataProvider.php
Go to the documentation of this file.
1 <?php
2 
3 declare(strict_types=1);
4 
5 /*
6  * This file is part of the TYPO3 CMS project.
7  *
8  * It is free software; you can redistribute it and/or modify it under
9  * the terms of the GNU General Public License, either version 2
10  * of the License, or any later version.
11  *
12  * For the full copyright and license information, please read the
13  * LICENSE.txt file that was distributed with this source code.
14  *
15  * The TYPO3 project - inspiring people to share!
16  */
17 
19 
20 use Psr\Http\Message\ServerRequestInterface;
28 
34 {
35  public function ‪__construct(ServerRequestInterface ‪$request, string ‪$key, array ‪$config = [], ‪ContentObjectRenderer ‪$cObj = null)
36  {
37  parent::__construct(‪$request, ‪$key, ‪$config, ‪$cObj);
38 
39  $this->‪generateItems();
40  }
41 
42  protected function ‪generateItems(): void
43  {
44  $pageRepository = GeneralUtility::makeInstance(PageRepository::class);
45  $pages = $pageRepository->getPagesOverlay($this->‪getPages());
46  $languageAspect = $this->‪getCurrentLanguageAspect();
47  foreach ($pages as $page) {
48  if (!$pageRepository->isPageSuitableForLanguage($page, $languageAspect)) {
49  continue;
50  }
51 
52  $this->items[] = [
53  'uid' => $page['uid'],
54  'lastMod' => (int)($page['SYS_LASTCHANGED'] ?: $page['tstamp']),
55  'changefreq' => $page['sitemap_changefreq'],
56  'priority' => (float)$page['sitemap_priority'],
57  ];
58  }
59  }
60 
64  protected function ‪getPages(): array
65  {
66  if (!empty($this->config['rootPage'])) {
67  $rootPageId = (int)$this->config['rootPage'];
68  } else {
69  $site = $this->request->getAttribute('site');
70  $rootPageId = $site->getRootPageId();
71  }
72 
73  ‪$cObj = GeneralUtility::makeInstance(ContentObjectRenderer::class);
74  $treeList = ‪$cObj->‪getTreeList(-$rootPageId, 99);
75  $treeListArray = ‪GeneralUtility::intExplode(',', $treeList);
76 
77  $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)
78  ->getQueryBuilderForTable('pages');
79 
80  $constraints = [
81  $queryBuilder->expr()->in('uid', $treeListArray)
82  ];
83 
84  if (!empty($this->config['additionalWhere'])) {
85  $constraints[] = ‪QueryHelper::stripLogicalOperatorPrefix($this->config['additionalWhere']);
86  }
87 
88  if (!empty($this->config['excludedDoktypes'])) {
89  $excludedDoktypes = ‪GeneralUtility::intExplode(',', $this->config['excludedDoktypes']);
90  if (!empty($excludedDoktypes)) {
91  $constraints[] = $queryBuilder->expr()->notIn('doktype', implode(',', $excludedDoktypes));
92  }
93  }
94  $pages = $queryBuilder->select('*')
95  ->from('pages')
96  ->where(...$constraints)
97  ->orderBy('uid', 'ASC')
98  ->execute()
99  ->fetchAll();
100 
101  return $pages;
102  }
103 
108  {
109  return GeneralUtility::makeInstance(Context::class)->getAspect('language');
110  }
111 
116  protected function ‪defineUrl(array $data): array
117  {
118  $typoLinkConfig = [
119  'parameter' => $data['uid'],
120  'forceAbsoluteUrl' => 1,
121  ];
122 
123  $data['loc'] = $this->cObj->typoLink_URL($typoLinkConfig);
124 
125  return $data;
126  }
127 }
‪TYPO3\CMS\Seo\XmlSitemap\PagesXmlSitemapDataProvider\generateItems
‪generateItems()
Definition: PagesXmlSitemapDataProvider.php:42
‪TYPO3\CMS\Seo\XmlSitemap\AbstractXmlSitemapDataProvider\$key
‪string $key
Definition: AbstractXmlSitemapDataProvider.php:31
‪TYPO3\CMS\Seo\XmlSitemap\PagesXmlSitemapDataProvider\getCurrentLanguageAspect
‪LanguageAspect getCurrentLanguageAspect()
Definition: PagesXmlSitemapDataProvider.php:107
‪TYPO3\CMS\Seo\XmlSitemap\AbstractXmlSitemapDataProvider\$config
‪array $config
Definition: AbstractXmlSitemapDataProvider.php:43
‪TYPO3\CMS\Seo\XmlSitemap\PagesXmlSitemapDataProvider
Definition: PagesXmlSitemapDataProvider.php:34
‪TYPO3\CMS\Core\Context\Context
Definition: Context.php:53
‪TYPO3\CMS\Seo\XmlSitemap\PagesXmlSitemapDataProvider\getPages
‪array getPages()
Definition: PagesXmlSitemapDataProvider.php:64
‪TYPO3\CMS\Seo\XmlSitemap
Definition: AbstractXmlSitemapDataProvider.php:18
‪TYPO3\CMS\Core\Database\Query\QueryHelper
Definition: QueryHelper.php:32
‪TYPO3\CMS\Seo\XmlSitemap\AbstractXmlSitemapDataProvider\$request
‪ServerRequestInterface $request
Definition: AbstractXmlSitemapDataProvider.php:55
‪TYPO3\CMS\Seo\XmlSitemap\PagesXmlSitemapDataProvider\__construct
‪__construct(ServerRequestInterface $request, string $key, array $config=[], ContentObjectRenderer $cObj=null)
Definition: PagesXmlSitemapDataProvider.php:35
‪TYPO3\CMS\Core\Context\LanguageAspect
Definition: LanguageAspect.php:57
‪TYPO3\CMS\Seo\XmlSitemap\AbstractXmlSitemapDataProvider
Definition: AbstractXmlSitemapDataProvider.php:28
‪TYPO3\CMS\Core\Database\Query\QueryHelper\stripLogicalOperatorPrefix
‪static string stripLogicalOperatorPrefix(string $constraint)
Definition: QueryHelper.php:165
‪TYPO3\CMS\Seo\XmlSitemap\PagesXmlSitemapDataProvider\defineUrl
‪array defineUrl(array $data)
Definition: PagesXmlSitemapDataProvider.php:116
‪TYPO3\CMS\Core\Utility\GeneralUtility\intExplode
‪static int[] intExplode($delimiter, $string, $removeEmptyValues=false, $limit=0)
Definition: GeneralUtility.php:988
‪TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer
Definition: ContentObjectRenderer.php:97
‪TYPO3\CMS\Core\Domain\Repository\PageRepository
Definition: PageRepository.php:52
‪TYPO3\CMS\Core\Database\ConnectionPool
Definition: ConnectionPool.php:46
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:46
‪TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer\getTreeList
‪string getTreeList($id, $depth, $begin=0, $dontCheckEnableFields=false, $addSelectFields='', $moreWhereClauses='', array $prevId_array=[], $recursionLevel=0)
Definition: ContentObjectRenderer.php:5945
‪TYPO3\CMS\Seo\XmlSitemap\AbstractXmlSitemapDataProvider\$cObj
‪ContentObjectRenderer $cObj
Definition: AbstractXmlSitemapDataProvider.php:47