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