[FEATURE] Redirect to Shortcut target page
authorThorben <thorben@work.de>
Mon, 18 Jul 2011 13:27:25 +0000 (15:27 +0200)
committerSusanne Moog <typo3@susannemoog.de>
Sat, 30 Jul 2011 16:52:01 +0000 (18:52 +0200)
Redirect directly to the target page in Frontend, if the accessed page
is of type Shortcut and accessed directly via its URL.

Change-Id: I4199cb8c89d6dc5a21dac6f3cd03051245880bd8
Resolves: #28322
Releases: 4.6
Reviewed-on: http://review.typo3.org/3398
Reviewed-by: Philipp Gampe
Tested-by: Philipp Gampe
Reviewed-by: Kay Strobach
Tested-by: Kay Strobach
Reviewed-by: Stefan Neufeind
Tested-by: Stefan Neufeind
Reviewed-by: Christian Kuhn
Reviewed-by: Susanne Moog
Tested-by: Susanne Moog
typo3/sysext/cms/tslib/class.tslib_fe.php
typo3/sysext/cms/tslib/index_ts.php

index abf84a4..fef8aff 100644 (file)
                }
        }
 
+       /**
+        * Redirect to target page, if the current page is a Shortcut.
+        *
+        * If the current page is of type shortcut and accessed directly via its URL, this function redirects to the
+        * Shortcut target using a Location header.
+        *
+        * @return void If page is not a Shortcut, redirects and exits otherwise
+        */
+       public function checkPageForShortcutRedirect() {
+
+               if (!empty($this->originalShortcutPage) && $this->originalShortcutPage['doktype'] == t3lib_pageSelect::DOKTYPE_SHORTCUT) {
+                       $linkVars = t3lib_div::trimExplode(',', (string) $this->config['config']['linkVars']);
+                       if (!empty($linkVars)) {
+                               $getData = t3lib_div::_GET();
+                               foreach ($linkVars as $key) {
+                                       if (isset($getData[$key])) {
+                                               $value = rawurlencode($getData[$key]);
+                                               if (!empty($value)) {
+                                                       $this->linkVars .= '&' . $key . '=' . $value;
+                                               }
+                                       }
+                               }
+                       }
+
+                               // instantiate tslib_content to generate the correct target URL
+                       $cObj = t3lib_div::makeInstance('tslib_cObj');
+                       $redirectUrl = $cObj->typoLink_URL(array('parameter' => $this->page['uid']));
+
+                               // HTTP Status code header - dependent on shortcut type
+                       $redirectStatus = t3lib_utility_Http::HTTP_STATUS_301;
+                       if ($this->originalShortcutPage['shortcut_mode'] == t3lib_pageSelect::SHORTCUT_MODE_RANDOM_SUBPAGE) {
+                               $redirectStatus = t3lib_utility_Http::HTTP_STATUS_307;
+                       }
+
+                               // redirect and exit
+                       t3lib_utility_Http::redirect($redirectUrl, $redirectStatus);
+               }
+       }
 
 
 
index 91ccf85..8b3c4f8 100644 (file)
@@ -395,6 +395,12 @@ switch($TSFE->checkDataSubmission())       {
 }
 
 
+// *******************************
+// Check for shortcut page and redirect
+// *******************************
+$TSFE->checkPageForShortcutRedirect();
+
+
 // ********************************
 // Generate page
 // *******************************