Fixed bug #14392: typolink creates incomplete links in combination with the forceAbso...
authorOliver Hader <oliver.hader@typo3.org>
Sun, 30 May 2010 14:31:23 +0000 (14:31 +0000)
committerOliver Hader <oliver.hader@typo3.org>
Sun, 30 May 2010 14:31:23 +0000 (14:31 +0000)
git-svn-id: https://svn.typo3.org/TYPO3v4/Core/trunk@7758 709f56b5-9817-0410-a4d7-c38de5d9e867

ChangeLog
typo3/sysext/cms/tslib/class.tslib_content.php

index 119d818..735fa1b 100755 (executable)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,6 +1,7 @@
 2010-05-30  Oliver Hader  <oliver@typo3.org>
 
        * Added feature #14383: Integrate hooks to backend.php to perform several customizations
+       * Fixed bug #14392: typolink creates incomplete links in combination with the forceAbsoluteUrl property
 
 2010-05-29  Christian Kuhn  <lolli@schwarzbu.ch>
 
index be82674..efcf0ad 100644 (file)
@@ -5978,6 +5978,7 @@ class tslib_cObj {
                                                } else {
                                                        $this->lastTypoLinkUrl = $GLOBALS['TSFE']->absRefPrefix.$link_param;
                                                }
+                                               $this->lastTypoLinkUrl = $this->forceAbsoluteUrl($this->lastTypoLinkUrl, $conf);
                                                $target = isset($conf['fileTarget']) ? $conf['fileTarget'] : $GLOBALS['TSFE']->fileTarget;
                                                if ($conf['fileTarget.'])       {$target = $this->stdWrap($target, $conf['fileTarget.']);}
                                                if ($forceTarget)       {$target=$forceTarget;}
@@ -6217,6 +6218,8 @@ class tslib_cObj {
                                                                                $addParams,
                                                                                $target
                                                                        );
+                                                                       $this->lastTypoLinkUrl = $this->forceAbsoluteUrl($this->lastTypoLinkUrl, $conf);
+                                                                       $this->lastTypoLinkLD['totalUrl'] = $this->lastTypoLinkUrl;
                                                                        $LD = $this->lastTypoLinkLD;
                                                }
 
@@ -6298,6 +6301,47 @@ class tslib_cObj {
        }
 
        /**
+        * Forces a given URL to be absolute.
+        *
+        * @param string $url The URL to be forced to be absolute
+        * @param array $configuration TypoScript configuration of typolink
+        * @return string The absolute URL
+        */
+       protected function forceAbsoluteUrl($url, array $configuration) {
+               if (!empty($url) && isset($configuration['forceAbsoluteUrl']) && $configuration['forceAbsoluteUrl']) {
+                       if (preg_match('#^(?:([a-z]+)(://))?([^/]*)(.*)$#', $url, $matches)) {
+                               $urlParts = array(
+                                       'scheme' => $matches[1],
+                                       'delimiter' => '://',
+                                       'host' => $matches[3],
+                                       'path' => $matches[4],
+                               );
+
+                               // Set scheme and host if not yet part of the URL:
+                               if (empty($urlParts['host'])) {
+                                       $urlParts['scheme'] = 'http';
+                                       $urlParts['host'] = t3lib_div::getIndpEnv('HTTP_HOST');
+                                       $isUrlModified = TRUE;
+                               }
+
+                               // Override scheme:
+                               $forceAbsoluteUrl =& $configuration['forceAbsoluteUrl.']['scheme'];
+                               if (!empty($forceAbsoluteUrl) && $urlParts['scheme'] !== $forceAbsoluteUrl) {
+                                       $urlParts['scheme'] = $forceAbsoluteUrl;
+                                       $isUrlModified = TRUE;
+                               }
+
+                               // Recreate the absolute URL:
+                               if ($isUrlModified) {
+                                       $url = implode('', $urlParts);
+                               }
+                       }
+               }
+
+               return $url;
+       }
+
+       /**
         * Based on the input "TypoLink" TypoScript configuration this will return the generated URL
         *
         * @param       array           TypoScript properties for "typolink"