From 2250ff918edca90e7e19efaae18e466da58852af Mon Sep 17 00:00:00 2001 From: Rokas Valiukas Date: Fri, 13 Nov 2015 16:20:18 +0200 Subject: [PATCH 1/2] Add typo3 404 pages for specific languages --- controller/admin/toxid_setup_main.php | 2 ++ core/toxidcurl.php | 34 ++++++++++++++++++++++++++- views/admin/de/toxid_admin_lang.php | 3 ++- views/admin/en/toxid_admin_lang.php | 3 ++- views/admin/tpl/toxid_setup_main.tpl | 8 +++++++ 5 files changed, 47 insertions(+), 3 deletions(-) diff --git a/controller/admin/toxid_setup_main.php b/controller/admin/toxid_setup_main.php index b082b8b..7828636 100644 --- a/controller/admin/toxid_setup_main.php +++ b/controller/admin/toxid_setup_main.php @@ -22,6 +22,7 @@ public function render() $this->_aViewData['bToxidRedirect301ToStartpage'] = $oConf->getShopConfVar('bToxidRedirect301ToStartpage'); $this->_aViewData['toxidCacheTtl'] = $oConf->getShopConfVar('toxidCacheTtl'); $this->_aViewData['toxidError404Link'] = $oConf->getShopConfVar('toxidError404Link'); + $this->_aViewData['aToxidNotFoundUrl'] = $oConf->getShopConfVar('aToxidNotFoundUrl'); return parent::render(); } @@ -50,5 +51,6 @@ public function save() $oConf->saveShopConfVar('bl', 'toxidDontRewriteUrls', $aParams['toxidDontRewriteUrls'], $sShopId, self::CONFIG_MODULE_NAME); $oConf->saveShopConfVar('bl', 'bToxidDontPassPostVarsToCms', $aParams['bToxidDontPassPostVarsToCms'], $sShopId, self::CONFIG_MODULE_NAME); $oConf->saveShopConfVar('bl', 'bToxidRedirect301ToStartpage', $aParams['bToxidRedirect301ToStartpage'], $sShopId, self::CONFIG_MODULE_NAME); + $oConf->saveShopConfVar('arr', 'aToxidNotFoundUrl', $aParams['aToxidNotFoundUrl'], $sShopId, self::CONFIG_MODULE_NAME); } } \ No newline at end of file diff --git a/core/toxidcurl.php b/core/toxidcurl.php index 53ecd24..017c813 100644 --- a/core/toxidcurl.php +++ b/core/toxidcurl.php @@ -90,6 +90,12 @@ class toxidCurl * @var string */ protected $_sFileExtensionValuesForNoRewrite = null; + /** + * stores not found url by active language + * + * @var array + */ + protected $_aNotFoundUrl = null; private $_initialized = false; private $smartyParser; /** @@ -586,14 +592,36 @@ protected function _getFileExtensionValuesForNoRewrite() return $this->_sFileExtensionValuesForNoRewrite; } + /** + * returns typo3 URL for not found page + * + * @param int $iLangId + * @param bool $blReset reset object value, and get url again + * + * @return null|string + */ + protected function _getToxidNotFoundUrl($iLangId = null, $blReset = false) + { + if ($this->_aNotFoundUrl === null || $blReset) { + $this->_aNotFoundUrl = $this->getConfig()->getConfigParam('aToxidNotFoundUrl'); + } + + if ($iLangId === null) { + $iLangId = oxRegistry::getLang()->getBaseLanguage(); + } + + return array_key_exists($iLangId, (array)$this->_aNotFoundUrl) ? $this->_aNotFoundUrl[$iLangId] : null; + } + /** * Handles HTTP status codes for toxid response * * @param $sUrl + * @param $notFound404 * * @return array */ - private function getRemoteContentAndHandleStatusCodes($sUrl) + private function getRemoteContentAndHandleStatusCodes($sUrl, $notFound404 = false) { $aPage = $this->_getRemoteContent($sUrl); switch ($aPage['info']['http_code']) { @@ -603,6 +631,10 @@ private function getRemoteContentAndHandleStatusCodes($sUrl) oxRegistry::getUtils()->showMessageAndExit(''); break; case 404: + if($this->_getToxidNotFoundUrl() && !$notFound404) { + $aPage = $this->getRemoteContentAndHandleStatusCodes($this->_getToxidNotFoundUrl(), true); + break; + } $this->handleError(404, $aPage['info']['url']); break; case 301: diff --git a/views/admin/de/toxid_admin_lang.php b/views/admin/de/toxid_admin_lang.php index 04b9559..7697a4c 100644 --- a/views/admin/de/toxid_admin_lang.php +++ b/views/admin/de/toxid_admin_lang.php @@ -16,12 +16,13 @@ 'TOXID_SOURCE_SSL' => 'CMS SSL-URL', 'TOXID_SEO_SNIPPET' => 'URL Identifier / SEO-Snippet', 'TOXID_SEARCH_URL' => 'URL zum Aufruf der Suche (optional)', + 'TOXID_NOT_FOUND_URL' => 'Not found URL (optional)', 'TOXID_PARAM' => 'TOXID URL-Parameter', 'TOXID_DONT_REWRITE' => 'URLs nicht umschreiben - Aufrufe führen auf externe CMS-Seite', 'TOXID_DONT_PASSTHROUGH' => 'POST-Parameter nicht an CMS durchreichen', 'TOXID_DONT_REWRITE_REL_URLS' => 'URLs für bestimmte "rel" Attributwerte nicht umschreiben (kommaseparierte Liste)', 'TOXID_DONT_REWRITE_URLS_WITH_FILE_EXTENSIONS' => 'URLs für bestimmte Dateiendungen nicht umschreiben (kommaseparierte Liste)', - 'TOXID_ERROR_404_LINK' => 'User will be redirected to this URL on 404 error (optional)', + 'TOXID_ERROR_404_LINK' => 'User will be redirected to this URL on 404 error, when no other 404 url is specified for specific language (optional)', 'TOXID_REWRITE_URLENCODED' => 'URLs die "url encoded" sind umschreiben (URL muss sich im "src" attribut befindet)', 'TOXID_REDIRECT_301_TO_STARTPAGE' => 'Auf Startseite weiterleiten wenn das CMS den HTTP-Statuscode 301 liefert', 'TOXID_LOOKING_FOR' => 'gesucht!', diff --git a/views/admin/en/toxid_admin_lang.php b/views/admin/en/toxid_admin_lang.php index 74495a8..b5dbced 100644 --- a/views/admin/en/toxid_admin_lang.php +++ b/views/admin/en/toxid_admin_lang.php @@ -16,12 +16,13 @@ 'TOXID_SOURCE_SSL' => 'CMS SSL-URL', 'TOXID_SEO_SNIPPET' => 'URL Identifier / SEO-Snippet', 'TOXID_SEARCH_URL' => 'URL to call the searchpage (optional)', + 'TOXID_NOT_FOUND_URL' => 'Not found URL (optional)', 'TOXID_PARAM' => 'TOXID URL parameter', 'TOXID_DONT_REWRITE' => 'Don\'t rewrite the URLs - Users will linked to the external site.', 'TOXID_DONT_PASSTHROUGH' => 'Don\'t pass POST parameters to CMS', 'TOXID_DONT_REWRITE_REL_URLS' => 'Don\'t rewrite the URLs for particular "rel" attribute values (comma-separated list)', 'TOXID_DONT_REWRITE_URLS_WITH_FILE_EXTENSIONS' => 'Don\'t rewrite the URLs for particular file extensions (comma-separated list)', - 'TOXID_ERROR_404_LINK' => 'User will be redirected to this URL on 404 error (optional)', + 'TOXID_ERROR_404_LINK' => 'User will be redirected to this URL on 404 error, when no other 404 url is specified for specific language (optional)', 'TOXID_REWRITE_URLENCODED' => 'Rewrite URLs that are "url encoded" (URL must be contained in the "src" attribute)', 'TOXID_REDIRECT_301_TO_STARTPAGE' => 'Redirect to home page if the CMS returns the HTTP status code 301', 'TOXID_LOOKING_FOR' => 'Support us with PayPal!', diff --git a/views/admin/tpl/toxid_setup_main.tpl b/views/admin/tpl/toxid_setup_main.tpl index 651c654..cb1bba8 100644 --- a/views/admin/tpl/toxid_setup_main.tpl +++ b/views/admin/tpl/toxid_setup_main.tpl @@ -128,6 +128,14 @@ function _groupExp(el) { + + + [{oxmultilang ident="TOXID_NOT_FOUND_URL"}]: + + + + + [{/foreach}] From 0ebc8c7c514867654e38e5327109369d1c26bd54 Mon Sep 17 00:00:00 2001 From: Stefan Krenz Date: Fri, 19 Aug 2016 11:06:41 +0200 Subject: [PATCH 2/2] Tailing ampersands and question-marks are now removed from CMS request URL. --- core/toxidcurl.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/core/toxidcurl.php b/core/toxidcurl.php index 8d06a3f..bf0e4a7 100644 --- a/core/toxidcurl.php +++ b/core/toxidcurl.php @@ -381,6 +381,8 @@ protected function _getRemoteContent($sUrl) $sUrl = rtrim($sUrl, '&') . "&{$params}"; } + $sUrl = rtrim($sUrl, '&?'); + curl_setopt($curl_handle, CURLOPT_URL, $sUrl); curl_setopt($curl_handle, CURLOPT_RETURNTRANSFER, 1); if (!$this->isToxidCurlPage()) {