瀏覽代碼

v8-2745 allow to view hidden page from viewpage module

Olivier Massot 4 年之前
父節點
當前提交
bbaea1a843

+ 4 - 1
ot_core/Classes/Website/OtWebsiteRepository.php

@@ -373,7 +373,7 @@ class OtWebsiteRepository
      * @return int
      * @throws NoSuchWebsiteException
      */
-    public function matchUriToPage(array $otWebsite, UriInterface $uri, bool $devMode=false): int
+    public function matchUriToPage(array $otWebsite, UriInterface $uri, bool $devMode=false, bool $withRestrictions = true): int
     {
         $tail = $uri->getPath();
         if ($devMode) {
@@ -384,6 +384,9 @@ class OtWebsiteRepository
         }
 
         $q = $this->connectionPool->getQueryBuilderForTable('pages');
+        if (!$withRestrictions) {
+            $q->getRestrictions()->removeAll();
+        }
         return $q
             ->select('uid')
             ->from('pages')

+ 13 - 2
ot_optimizer/Classes/Middleware/Frontend/OtPageResolver.php

@@ -27,7 +27,9 @@ class OtPageResolver extends \TYPO3\CMS\Frontend\Middleware\PageResolver
      */
     public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface
     {
-        $shallFallback = $_COOKIE['optimize'] != 1 && $_SERVER['TYPO3_OPTIMIZE'] != 1;
+        // Shall fallback on non-optimized mode if a cookie 'optimize' exists and is different from 1, or if
+        // a server global variable TYPO3_OPTIMIZE is set and is different from 1
+        $shallFallback = ($_COOKIE['optimize'] != 1 && $_SERVER['TYPO3_OPTIMIZE'] != 1);
         if ($shallFallback) {
             return parent::process($request, $handler);
         }
@@ -54,7 +56,16 @@ class OtPageResolver extends \TYPO3\CMS\Frontend\Middleware\PageResolver
             );
         }
 
-        $pageUid = $otWebsiteRepository->matchUriToPage($website, $request->getUri(), $devMode);
+        // if the page is requested from the BE module Viewpage, it shall be displayed even if hidden
+        // a backend user shall be authenticated for this
+        $requestedFromViewPage = preg_match(
+            "/.+\/typo3\/index.php\?route=.*Viewpage.*/",
+            $_SERVER['HTTP_REFERER']
+            )
+            && $GLOBALS['BE_USER'];
+
+        $pageUid = $otWebsiteRepository->matchUriToPage($website, $request->getUri(), $devMode, !$requestedFromViewPage);
+
         if (!$pageUid > 0) {
             return GeneralUtility::makeInstance(ErrorController::class)->pageNotFoundAction(
                 $request,