Skip to content

Commit

Permalink
[FEATURE] Allow multiple sitemaps in parallel
Browse files Browse the repository at this point in the history
Add the possibility to have config like this:

   seo_googlenews < seo_sitemap
   seo_googlenews.typeNum = 1571859552
   seo_googlenews.10.sitemapType = googleNewsSitemap

   plugin.tx_seo {
       config {
           xmlSitemap {
               sitemaps {
                   news {
                       provider = GeorgRinger\News\Seo\NewsXmlSitemapDataProvider
                       config {
                           ...
                       }
                   }
               }
           }
           googleNewsSitemap {
               sitemaps {
                   news {
                       provider = GeorgRinger\News\Seo\NewsXmlSitemapDataProvider
                       config {
                           googleNews = 1
                           ...
                           template = GoogleNewsXmlSitemap.html
                       }
                   }
               }
           }
       }
   }

Google sitemap: example.com/index.php?type=1571859552&sitemap=news

Resolves: #89171
Releases: master
Change-Id: Iedd31dc834c64d3c7ffbd0e5fe5d1e335fe4738f
Reviewed-on: https://review.typo3.org/c/Packages/TYPO3.CMS/+/61568
Tested-by: TYPO3com <noreply@typo3.com>
Tested-by: Johannes Kasberger <johannes.kasberger@reelworx.at>
Tested-by: Richard Haeser <richard@maxserv.com>
Reviewed-by: Kevin Appelt <kevin.appelt@icloud.com>
Reviewed-by: Jörg Bösche <typo3@joergboesche.de>
Reviewed-by: Johannes Kasberger <johannes.kasberger@reelworx.at>
Reviewed-by: Richard Haeser <richard@maxserv.com>
  • Loading branch information
liayn authored and Richard Haeser committed Oct 25, 2019
1 parent 9bdbeea commit 4ce09ee
Show file tree
Hide file tree
Showing 2 changed files with 102 additions and 12 deletions.
@@ -0,0 +1,77 @@
.. include:: ../../Includes.txt

=============================================================
Feature: #89171 - Added possibility to have multiple sitemaps
=============================================================

See :issue:`89171`

Description
===========

You can now also create multiple different sitemaps. This can be handy for situations, where
different target systems need them in different format or order. (e.g. Google News Sitemaps)

The syntax looks like this:

.. code-block:: typoscript
plugin.tx_seo {
config {
<sitemapType> {
sitemaps {
<unique key> {
provider = TYPO3\CMS\Seo\XmlSitemap\RecordsXmlSitemapDataProvider
config {
...
}
}
}
}
}
}
Example:

.. code-block:: typoscript
seo_googlenews < seo_sitemap
seo_googlenews.typeNum = 1571859552
seo_googlenews.10.sitemapType = googleNewsSitemap
plugin.tx_seo {
config {
xmlSitemap {
sitemaps {
news {
provider = GeorgRinger\News\Seo\NewsXmlSitemapDataProvider
config {
...
}
}
}
}
googleNewsSitemap {
sitemaps {
news {
provider = GeorgRinger\News\Seo\NewsXmlSitemapDataProvider
config {
googleNews = 1
...
template = GoogleNewsXmlSitemap.html
}
}
}
}
}
}
Impact
======

As it only gives the possibility to add multiple sitemaps, it won't affect any installation unless you add more sitemaps
yourself.

.. index:: ext:seo
37 changes: 25 additions & 12 deletions typo3/sysext/seo/Classes/XmlSitemap/XmlSitemapRenderer.php
Expand Up @@ -21,6 +21,7 @@
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Core\Utility\PathUtility;
use TYPO3\CMS\Extbase\Configuration\ConfigurationManagerInterface;
use TYPO3\CMS\Extbase\Object\Exception;
use TYPO3\CMS\Extbase\Object\ObjectManager;
use TYPO3\CMS\Fluid\View\StandaloneView;
use TYPO3\CMS\Seo\XmlSitemap\Exception\InvalidConfigurationException;
Expand All @@ -37,10 +38,14 @@ class XmlSitemapRenderer
protected $configuration;

/**
* @var \TYPO3\CMS\Fluid\View\StandaloneView
* @var StandaloneView
*/
protected $view;

/**
* XmlSitemapRenderer constructor.
* @throws Exception
*/
public function __construct()
{
$this->configuration = $this->getConfiguration();
Expand All @@ -54,29 +59,33 @@ public function __construct()
}

/**
* @param string $_ unused, but needed as this is called via userfunc and passes a string as first parameter
* @param array $typoScriptConfiguration TypoScript configuration specified in USER Content Object
* @return string
* @throws InvalidConfigurationException
*/
public function render(): string
public function render(string $_, array $typoScriptConfiguration): string
{
// Inject request from globals until request will be available to cObj
$request = $GLOBALS['TYPO3_REQUEST'];
$this->view->assign('type', $GLOBALS['TSFE']->type);
$sitemapType = $typoScriptConfiguration['sitemapType'] ?? 'xmlSitemap';
if (!empty($sitemap = $request->getQueryParams()['sitemap'])) {
return $this->renderSitemap($request, $sitemap);
return $this->renderSitemap($request, $sitemap, $sitemapType);
}

return $this->renderIndex($request);
return $this->renderIndex($request, $sitemapType);
}

/**
* @param \Psr\Http\Message\ServerRequestInterface $request
* @param ServerRequestInterface $request
* @param string $sitemapType
* @return string
*/
protected function renderIndex(ServerRequestInterface $request): string
protected function renderIndex(ServerRequestInterface $request, string $sitemapType): string
{
$sitemaps = [];
foreach ($this->configuration['config']['xmlSitemap']['sitemaps'] ?? [] as $sitemap => $config) {
foreach ($this->configuration['config'][$sitemapType]['sitemaps'] ?? [] as $sitemap => $config) {
if (class_exists($config['provider']) &&
is_subclass_of($config['provider'], XmlSitemapDataProviderInterface::class)) {
/** @var XmlSitemapDataProviderInterface $provider */
Expand All @@ -99,21 +108,23 @@ protected function renderIndex(ServerRequestInterface $request): string
}
}

$this->view->assign('sitemapType', $sitemapType);
$this->view->assign('sitemaps', $sitemaps);
$this->view->setTemplate('Index');

return $this->view->render();
}

/**
* @param \Psr\Http\Message\ServerRequestInterface $request
* @param ServerRequestInterface $request
* @param string $sitemap
* @param string $sitemapType
* @return string
* @throws \TYPO3\CMS\Seo\XmlSitemap\Exception\InvalidConfigurationException
* @throws InvalidConfigurationException
*/
protected function renderSitemap(ServerRequestInterface $request, string $sitemap): string
protected function renderSitemap(ServerRequestInterface $request, string $sitemap, string $sitemapType): string
{
if (!empty($sitemapConfig = $this->configuration['config']['xmlSitemap']['sitemaps'][$sitemap])) {
if (!empty($sitemapConfig = $this->configuration['config'][$sitemapType]['sitemaps'][$sitemap])) {
if (class_exists($sitemapConfig['provider']) &&
is_subclass_of($sitemapConfig['provider'], XmlSitemapDataProviderInterface::class)) {
/** @var XmlSitemapDataProviderInterface $provider */
Expand All @@ -129,6 +140,7 @@ protected function renderSitemap(ServerRequestInterface $request, string $sitema
$template = $sitemapConfig['config']['template'] ?: 'Sitemap';
$this->view->setTemplate($template);
$this->view->assign('items', $items);
$this->view->assign('sitemapType', $sitemapType);

return $this->view->render();
}
Expand All @@ -139,7 +151,7 @@ protected function renderSitemap(ServerRequestInterface $request, string $sitema
}

/**
* @return \TYPO3\CMS\Fluid\View\StandaloneView
* @return StandaloneView
*/
protected function getStandaloneView(): StandaloneView
{
Expand All @@ -155,6 +167,7 @@ protected function getStandaloneView(): StandaloneView
/**
* Get the whole typoscript array
* @return array
* @throws Exception
*/
private function getConfiguration(): array
{
Expand Down

0 comments on commit 4ce09ee

Please sign in to comment.