[FEATURE] Add "auto" absRefPrefix option 47/29747/5
authorBenjamin Mack <benni@typo3.org>
Wed, 30 Apr 2014 13:41:22 +0000 (15:41 +0200)
committerHelmut Hummel <helmut.hummel@typo3.org>
Thu, 4 Dec 2014 21:38:13 +0000 (22:38 +0100)
For automatic distribution configuration
like the introduction package, a dynamic
option to find out whether TYPO3 is installed
under "/" or "/mysite/" the TypoScript
option config.absRefPrefix = auto
calculates the absRefPrefix automatically.

Releases: master
Resolves: #58366
Change-Id: Ia0d335665c9b30d21b886c8e9ac4c1ccdb069adc
Reviewed-on: http://review.typo3.org/29747
Reviewed-by: Stefan Froemken <froemken@gmail.com>
Reviewed-by: Benjamin Kott <info@bk2k.info>
Reviewed-by: Helmut Hummel <helmut.hummel@typo3.org>
Tested-by: Helmut Hummel <helmut.hummel@typo3.org>
typo3/sysext/core/Documentation/Changelog/master/Feature-58366-AutomaticAbsRefPrefix.rst [new file with mode: 0644]
typo3/sysext/frontend/Classes/Page/PageGenerator.php

diff --git a/typo3/sysext/core/Documentation/Changelog/master/Feature-58366-AutomaticAbsRefPrefix.rst b/typo3/sysext/core/Documentation/Changelog/master/Feature-58366-AutomaticAbsRefPrefix.rst
new file mode 100644 (file)
index 0000000..0327816
--- /dev/null
@@ -0,0 +1,39 @@
+===========================================================
+Feature: #58366 - Add "auto" Option for config.absRefPrefix
+===========================================================
+
+Description
+===========
+
+The TypoScript setting config.absRefPrefix can be used to allow URL rewriting like URL giving a hard
+prefix for all relative paths. As an alternative to config.baseURL to be set to a specific domain
+absRefPrefix can autodetect the site root and use that instead of manually setting this option.
+
+Frontend:
+
+The new option can be set like this:
+
+.. code-block:: typoscript
+
+       config.absRefPrefix = auto
+
+instead of hardcoded values for different environments or when moving installations in subfolders.
+
+.. code-block:: typoscript
+
+       [ApplicationContext = Production]
+       config.absRefPrefix = /
+
+       [ApplicationContext = Testing]
+       config.absRefPrefix = /my_site_root/
+
+As the feature only works with path prefixes, and not with host name variables from the server,
+the new option is also safe for multi-domain environments to avoid duplicate caching mechanism.
+
+
+Impact
+======
+
+The new special option can be used to automatically set up installations and distributions like
+the Introduction Package where a site configuration is shipped with the system but might need
+to be adjusted.
index 9deaf96..5f80e4a 100644 (file)
@@ -77,7 +77,17 @@ class PageGenerator {
                } else {
                        $GLOBALS['TSFE']->spamProtectEmailAddresses = \TYPO3\CMS\Core\Utility\MathUtility::forceIntegerInRange($GLOBALS['TSFE']->config['config']['spamProtectEmailAddresses'], -10, 10, 0);
                }
-               $GLOBALS['TSFE']->absRefPrefix = $GLOBALS['TSFE']->config['config']['absRefPrefix'] ? trim($GLOBALS['TSFE']->config['config']['absRefPrefix']) : '';
+               // calculate the absolute path prefix
+               if (!empty($GLOBALS['TSFE']->config['config']['absRefPrefix'])) {
+                       $absRefPrefix = trim($GLOBALS['TSFE']->config['config']['absRefPrefix']);
+                       if ($absRefPrefix === 'auto') {
+                               $GLOBALS['TSFE']->absRefPrefix = GeneralUtility::getIndpEnv('TYPO3_SITE_PATH');
+                       } else {
+                               $GLOBALS['TSFE']->absRefPrefix = $absRefPrefix;
+                       }
+               } else {
+                       $GLOBALS['TSFE']->absRefPrefix = '';
+               }
                if ($GLOBALS['TSFE']->type && $GLOBALS['TSFE']->config['config']['frameReloadIfNotInFrameset']) {
                        $tdlLD = $GLOBALS['TSFE']->tmpl->linkData($GLOBALS['TSFE']->page, '_top', $GLOBALS['TSFE']->no_cache, '');
                        $GLOBALS['TSFE']->additionalJavaScript['JSCode'] .= 'if(!parent.' . trim($GLOBALS['TSFE']->sPre) . ' && !parent.view_frame) top.location.href="' . $GLOBALS['TSFE']->baseUrlWrap($tdlLD['totalURL']) . '"';