Index: core/Classes/Utility/GeneralUtility.php =================================================================== --- core/Classes/Utility/GeneralUtility.php (Revision 18) +++ core/Classes/Utility/GeneralUtility.php (Arbeitskopie) @@ -1664,6 +1664,107 @@ } return $output; } + + /** + * Parse a URL and return its components + * + * @param string $url The URL to parse. Invalid characters are replaced by _. + * @param integer $multidim Specify one of PHP_URL_SCHEME, PHP_URL_HOST, PHP_URL_PORT, PHP_URL_USER, PHP_URL_PASS, PHP_URL_PATH, PHP_URL_QUERY or PHP_URL_FRAGMENT + * to retrieve just a specific URL component as a string (except when PHP_URL_PORT is given, in which case the return value will be an integer). + * @return mixed On seriously malformed URLs, parse_url() may return FALSE. Otherwise a array supplied. + * @see http://php.net/manual/en/function.parse-url.php + */ + static public function parseUrl($url, $component = -1) { + return parse_url($url, $component); + } + + /** + * Build a URL + * + * @param array $url (part(s) of) an URL in form of a string or associative array like parse_url() returns + * @return mixed Returns the new URL as string on success or FALSE on failure. + * @see http://php.net/manual/en/function.http-build-url.php + */ + static public function buildUrl($url) { + $output = false; + if(is_array($url)) { + $urlArray = array(); + if(!empty($url['scheme'])) { + $urlArray[] = $url['scheme']; + $urlArray[] = '://'; + } else { + $urlArray[] = 'http://'; + } + if(!empty($url['user'])) { + $urlArray[] = $url['user']; + if(!empty($url['pass'])) { + $urlArray[] = ':'; + $urlArray[] = $url['pass']; + } + $urlArray[] = '@'; + } + if(!empty($url['host'])) { + $urlArray[] = $url['host']; + } else { + $urlArray[] = 'localhost'; + } + if(!empty($url['port'])) { + $urlArray[] = ':'; + $urlArray[] = $url['port']; + } + if(!empty($url['path'])) { + $urlArray[] = '/'; + $urlArray[] = trim($url['path'], ' /'); + } + if(!empty($url['query'])) { + $urlArray[] = '?'; + if(is_array($url['query'])) { + $urlArray[] = self::buildUrlQuery($url['query']); + } else { + $urlArray[] = trim($url['query'], ' ?&'); + } + } + if(!empty($url['fragment'])) { + $urlArray[] = '#'; + $urlArray[] = trim($url['fragment'], ' #'); + } + $output = implode('', $urlArray); + } + + return $output; + } + + /** + * Generate URL-encoded query string + * + * @param mixed $query_data May be an array or object containing properties. + * @param string $numeric_prefix If numeric indices are used in the base array and this parameter is provided, it will be prepended to the numeric index for elements in the base array only. + * @param string $arg_separator arg_separator.output is used to separate arguments, unless this parameter is specified, and is then used. + * @param integer $enc_type By default, PHP_QUERY_RFC1738. + * @return string Returns a URL-encoded string. + * @see http://php.net/manual/en/function.http-build-query.php + */ + static public function buildUrlQuery($query_data, $numeric_prefix = '', $arg_separator = '&', $enc_type = PHP_QUERY_RFC1738) { + return http_build_query($query_data, $numeric_prefix, $arg_separator, $enc_type); + } + + /** + * Merge one or more url query arrays + * + * @param ... Variable list of arrays or strings to merge. + * @return array Returns the resulting queries array. + * @see explodeUrl2Array(), http://php.net/manual/en/function.array-merge.php + */ + static public function mergeUrlQuery() { + $output = array(); + foreach(func_get_args() as $query) { + if(!is_array($query)) + $query = self::explodeUrl2Array($query, TRUE); + if(!empty($query)) + $output = array_merge($output, $query); + } + return $output; + } /** * Returns an array with selected keys from incoming data. Index: frontend/Classes/ContentObject/ContentObjectRenderer.php =================================================================== --- frontend/Classes/ContentObject/ContentObjectRenderer.php (Revision 18) +++ frontend/Classes/ContentObject/ContentObjectRenderer.php (Arbeitskopie) @@ -5830,7 +5830,7 @@ $title = $this->stdWrap($title, $conf['title.']); } // Parse URL: - $pU = parse_url($link_param); + $pU = \TYPO3\CMS\Core\Utility\GeneralUtility::parseUrl($link_param); // Detecting kind of link: // If it's a mail address: if (strstr($link_param, '@') && (!$pU['scheme'] || $pU['scheme'] == 'mailto')) { @@ -5876,14 +5876,19 @@ } else { $scheme = ''; } + if(!empty($conf['additionalParams'])) { + $pU['query'] = \TYPO3\CMS\Core\Utility\GeneralUtility::mergeUrlQuery($pU['query'], $conf['additionalParams']); + } + $link = \TYPO3\CMS\Core\Utility\GeneralUtility::buildUrl($pU); + if ($GLOBALS['TSFE']->config['config']['jumpurl_enable']) { $url = $GLOBALS['TSFE']->absRefPrefix . $GLOBALS['TSFE']->config['mainScript'] . $initP; - $jumpurl = $scheme . $link_param; - $juHash = GeneralUtility::hmac($jumpurl, 'jumpurl'); - $this->lastTypoLinkUrl = $url . '&jumpurl=' . rawurlencode($jumpurl) . '&juHash='. $juHash . $GLOBALS['TSFE']->getMethodUrlIdToken; + $juHash = GeneralUtility::hmac($link, 'jumpurl'); + $this->lastTypoLinkUrl = $url . '&jumpurl=' . rawurlencode($link) . '&juHash='. $juHash . $GLOBALS['TSFE']->getMethodUrlIdToken; } else { - $this->lastTypoLinkUrl = $scheme . $link_param; + $this->lastTypoLinkUrl = $link; } + $this->lastTypoLinkTarget = $target; $finalTagParts['url'] = $this->lastTypoLinkUrl; $finalTagParts['targetParams'] = $target ? ' target="' . $target . '"' : '';