From e5a3e674ed2ea6abdbaa25cfa335d9c3aa808a47 Mon Sep 17 00:00:00 2001 From: Serafino Messina Date: Tue, 16 Aug 2016 11:19:35 +0200 Subject: [PATCH] Do not append "?" or "&" if no params. I've spent an hour and a half trying to debug the following issue: while trying to fetch some Wordpress content using `[{ $toxid->getCmsSnippet('section') }]` I was always getting a 301 response. I've found out that the CMS URL, from `http://sub.domain.com/`, was being changed to `http://sub.domain.com/?&` causing the CMS to return a 301 redirect response. The proposed change should solve the issue by not appending any additional character if not needed. I've not fully tested it, it does work with my situation. --- core/toxidcurl.php | 37 ++++++++++++++++++++++++++++++------- 1 file changed, 30 insertions(+), 7 deletions(-) diff --git a/core/toxidcurl.php b/core/toxidcurl.php index 91037b1..938965a 100644 --- a/core/toxidcurl.php +++ b/core/toxidcurl.php @@ -368,12 +368,7 @@ protected function _getRemoteContent($sUrl) $aResult = array(); $curl_handle = curl_init(); - $params = http_build_query($this->additionalUrlParams); - if (false === strpos($sUrl, '?')) { - $sUrl .= "?{$params}"; - } else { - $sUrl = rtrim($sUrl, '&') . "&{$params}"; - } + $sUrl = $this->_appendAdditionalUrlParams($sUrl); curl_setopt($curl_handle, CURLOPT_URL, $sUrl); curl_setopt($curl_handle, CURLOPT_RETURNTRANSFER, 1); @@ -394,6 +389,30 @@ protected function _getRemoteContent($sUrl) return $aResult; } + + /** + * Returns the given $sUrl with the appended parameters, if any. + * + * @param $sUrl + * + * @return string + */ + protected function _appendAdditionalUrlParams($sUrl) + { + if (!$this->additionalUrlParams) { + return $sUrl; + } + + $params = http_build_query($this->additionalUrlParams); + + if (false === strpos($sUrl, '?')) { + $sUrl .= "?{$params}"; + } else { + $sUrl = rtrim($sUrl, '&') . "&{$params}"; + } + + return $sUrl; + } /** * rewrites given string URL's, which belongs to typo3 and configured in aToxidCurlSource @@ -506,8 +525,12 @@ protected function _getToxidLangUrlParam($iLangId = null, $blReset = false) if ($iLangId === null) { $iLangId = oxRegistry::getLang()->getBaseLanguage(); } + + if ($param = $this->_aToxidLangUrlParam[$iLangId]) { + return '?' . ltrim($param, '?'); + } - return '?' . ltrim($this->_aToxidLangUrlParam[$iLangId], '?'); + return ''; } /**