Bladeren bron

Merge branch 'release/0.9.1'

Olivier Massot 4 jaren geleden
bovenliggende
commit
802cc7e80c

+ 49 - 0
ot_core/Classes/Middleware/Frontend/OtMetaNoIndexAdder.php

@@ -0,0 +1,49 @@
+<?php
+
+
+namespace Opentalent\OtCore\Middleware\Frontend;
+
+
+use Psr\Http\Message\ResponseInterface;
+use Psr\Http\Message\ServerRequestInterface;
+use Psr\Http\Server\MiddlewareInterface;
+use Psr\Http\Server\RequestHandlerInterface;
+use TYPO3\CMS\Core\Http\Stream;
+use TYPO3\CMS\Core\MetaTag\MetaTagManagerRegistry;
+use TYPO3\CMS\Core\Page\PageRenderer;
+use TYPO3\CMS\Core\Utility\GeneralUtility;
+
+/**
+ *  /!\ 2021-06 - This is a special and TEMPORARY patch for https://assistance.opentalent.fr/browse/V8-2247
+ *
+ * Because FE authentication doesn't work on domain that are not in *.opentalent.fr, i.e. organizations that
+ * have a custom domain set, both domains have to be kept available: the custom one and the <sub>.opentalent.fr one.
+ *
+ * But, we don't want the second one to be indexed by search engines.
+ *
+ * This middleware set the 'robots' meta tag to noindex mode if the domain matches this special case.
+ *
+ * Because Typoscript is processed after this, the page.meta.robots line had to be commented.
+ * The default meta tag has been moved here.
+ *
+ * !! When this middleware will be useless, **remind to re-enable the typoscript directive!**
+ *
+ * @package Opentalent\OtCore\Middleware\Frontend
+ */
+class OtMetaNoIndexAdder implements MiddlewareInterface
+{
+    public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface
+    {
+        $metaTagManager = GeneralUtility::makeInstance(MetaTagManagerRegistry::class)->getManagerForProperty('robots');
+        if (
+            $GLOBALS['TYPO3_REQUEST']->getAttribute('ot_website')['custom_domain'] &&
+            preg_match("/[\w\-]+\.opentalent\.fr(:\d+)?/", $_SERVER['HTTP_HOST'])
+        ) {
+            $metaTagManager->addProperty('robots', 'noindex,nofollow');
+        } else {
+            $metaTagManager->addProperty('robots', 'index,follow,archive');
+        }
+
+        return $handler->handle($request);
+    }
+}

+ 8 - 0
ot_core/Configuration/RequestMiddlewares.php

@@ -14,5 +14,13 @@ return [
                 'typo3/cms-adminpanel/sql-logging'
             ],
         ],
+        'noindex' => [
+            'target' => Opentalent\OtCore\Middleware\Frontend\OtMetaNoIndexAdder::class,
+            'before' => [
+            ],
+            'after' => [
+                'typo3/cms-adminpanel/renderer'
+            ],
+        ],
     ],
 ];

+ 1 - 1
ot_templating/Configuration/TypoScript/setup.txt

@@ -58,7 +58,7 @@ page.meta {
     keywords.field = keywords
     description.field = description
     author.field = author
-    robots = index,follow,archive
+#    robots = index,follow,archive   # disabled as a bugfix: @see ot_core/Classes/Middleware/Frontend/OtMetaNoIndexAdder.php
     viewport = width=device-width
 }