[FEATURE] Improve language-guessing with realurl 28/47328/3
authorChristian Futterlieb <christian@futterlieb.ch>
Fri, 18 Mar 2016 14:24:11 +0000 (15:24 +0100)
committerChristian Futterlieb <christian@futterlieb.ch>
Fri, 18 Mar 2016 21:23:14 +0000 (22:23 +0100)
Change-Id: I58ce4581ab33b9f38245fe17c784bc8075d917b6
Reviewed-on: https://review.typo3.org/47328
Tested-by: Christian Futterlieb <christian@futterlieb.ch>
Reviewed-by: Christian Futterlieb <christian@futterlieb.ch>
Classes/Controller/PagenotfoundController.php
Classes/Realurl/Decoder/UrlDecoder.php [new file with mode: 0644]
Classes/Realurl/RealurlV1.php [new file with mode: 0644]
Documentation/Administration/Index.rst
Documentation/KnownProblems/Index.rst
ext_emconf.php
ext_localconf.php

index 57bd991..43f6228 100644 (file)
@@ -460,9 +460,8 @@ class PagenotfoundController
 
                                $url .= 'index.php?id=' . $this->_default404Page . '&loopPrevention=1';
 
-                               if(!empty($this->_forceLanguage)) {
-                                       $url .= '&' . $this->_languageParam . '=' . $this->_forceLanguage;
-                               }
+                               // append language parameter to query string
+                               $url .= $this->_getLanguageQueryString();
 
                                if($this->_isForbiddenError) {
                     if(count($this->_additional403GetParams)) {
@@ -759,6 +758,48 @@ class PagenotfoundController
     }
 
     /**
+     * Returns a string to append to an URL (ex: "&L=1"). The string consists of
+     * the languageParam (mostly "L") and the needed sys_language_uid. When no
+     * language is requested, an empty string is retured.
+     *
+     * @return string
+     */
+    protected function _getLanguageQueryString()
+    {
+        $languageUid = null;
+
+        if(!empty($this->_forceLanguage)) {
+            $languageUid = $this->_forceLanguage;
+        } elseif(($languageUidFromRealurl = $this->_getLanguageUidFromRealurl())) {
+            $languageUid = $languageUidFromRealurl;
+        }
+
+        if ($languageUid) {
+            return '&' . $this->_languageParam . '=' . $languageUid;
+        }
+        return '';
+    }
+
+    /**
+     * @return integer|null
+     */
+    protected function _getLanguageUidFromRealurl()
+    {
+        if (\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::isLoaded('realurl') && array_key_exists('realurl_detectedLanguageId', $this->_getTyposcriptFrontendController()->register)) {
+            return (int) $this->_getTyposcriptFrontendController()->register['realurl_detectedLanguageId'];
+        }
+        return null;
+    }
+
+    /**
+     * @return \TYPO3\CMS\Frontend\Controller\TypoScriptFrontendController
+     */
+    protected function _getTyposcriptFrontendController()
+    {
+        return $GLOBALS['TSFE'];
+    }
+
+    /**
      * @return \TYPO3\CMS\Core\Database\DatabaseConnection
      */
     protected function _getDatabaseConnection()
diff --git a/Classes/Realurl/Decoder/UrlDecoder.php b/Classes/Realurl/Decoder/UrlDecoder.php
new file mode 100644 (file)
index 0000000..540e3c4
--- /dev/null
@@ -0,0 +1,62 @@
+<?php
+namespace Aaw\Pagenotfoundhandling\Realurl\Decoder;
+
+/**
+ * **************************************************************
+ * Copyright notice
+ *
+ * (c) 2016 Agentur am Wasser | Maeder & Partner AG
+ * All rights reserved
+ *
+ * This script is part of the TYPO3 project. The TYPO3 project is
+ * free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * The GNU General Public License can be found at
+ * http://www.gnu.org/copyleft/gpl.html.
+ *
+ * This script is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * This copyright notice MUST APPEAR in all copies of the script!
+ * **************************************************************
+ *
+ * @author     Agentur am Wasser | Maeder & Partner AG <development@agenturamwasser.ch>
+ * @copyright  Copyright (c) 2016 Agentur am Wasser | Maeder & Partner AG (http://www.agenturamwasser.ch)
+ * @license    http://www.gnu.org/copyleft/gpl.html     GNU General Public License
+ * @category   TYPO3
+ * @package    pagenotfoundhandling
+ */
+
+
+/**
+ * Realurl UrlDecoder XCLASS
+ *
+ * It is used for realurl versions >=2.0 (and <2.0.x ???).
+ *
+ * For older realurl versions, \Aaw\Pagenotfoundhandling\Realurl\RealurlV1 is
+ * used for the very same job.
+ *
+ * @author   Agentur am Wasser | Maeder & Partner AG <development@agenturamwasser.ch>
+ * @category TYPO3
+ * @package  pagenotfoundhandling
+ * @see      \Aaw\Pagenotfoundhandling\Realurl\RealurlV1
+ */
+class UrlDecoder extends \DmitryDulepov\Realurl\Decoder\UrlDecoder
+{
+    /**
+     * @param string $errorMessage
+     * @return void
+     * @see \DmitryDulepov\Realurl\Decoder\UrlDecoder::throw404()
+     */
+    protected function throw404($errorMessage)
+    {
+        // Register the detectedLanguageId
+        $this->caller->register['realurl_detectedLanguageId'] = $this->detectedLanguageId;
+        return parent::throw404($errorMessage);
+    }
+}
diff --git a/Classes/Realurl/RealurlV1.php b/Classes/Realurl/RealurlV1.php
new file mode 100644 (file)
index 0000000..57a2247
--- /dev/null
@@ -0,0 +1,65 @@
+<?php
+namespace Aaw\Pagenotfoundhandling\Realurl;
+
+/**
+ * **************************************************************
+ * Copyright notice
+ *
+ * (c) 2016 Agentur am Wasser | Maeder & Partner AG
+ * All rights reserved
+ *
+ * This script is part of the TYPO3 project. The TYPO3 project is
+ * free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * The GNU General Public License can be found at
+ * http://www.gnu.org/copyleft/gpl.html.
+ *
+ * This script is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * This copyright notice MUST APPEAR in all copies of the script!
+ * **************************************************************
+ *
+ * @author     Agentur am Wasser | Maeder & Partner AG <development@agenturamwasser.ch>
+ * @copyright  Copyright (c) 2016 Agentur am Wasser | Maeder & Partner AG (http://www.agenturamwasser.ch)
+ * @license    http://www.gnu.org/copyleft/gpl.html     GNU General Public License
+ * @category   TYPO3
+ * @package    pagenotfoundhandling
+ */
+
+
+/**
+ * Realurl XCLASS
+ *
+ * It is used for realurl versions >=1.12.8 and <2.0, thus it's here for
+ * compatibility reasons.
+ *
+ * As of realurl v2.0, \Aaw\Pagenotfoundhandling\Realurl\Decoder\UrlDecoder is
+ * used for the very same job.
+ *
+ * @author   Agentur am Wasser | Maeder & Partner AG <development@agenturamwasser.ch>
+ * @category TYPO3
+ * @package  pagenotfoundhandling
+ * @see      \Aaw\Pagenotfoundhandling\Realurl\Decoder\UrlDecoder
+ */
+class RealurlV1 extends \tx_realurl
+{
+    /**
+     * @param string $msg
+     * @return void
+     * @see \tx_realurl::decodeSpURL_throw404()
+     */
+    public function decodeSpURL_throw404($msg)
+    {
+        // Register the detectedLanguageId
+        if ($this->detectedLanguage > 0) {
+            $this->pObj->register['realurl_detectedLanguageId'] = $this->detectedLanguage;
+        }
+        return parent::decodeSpURL_throw404($msg);
+    }
+}
index c76d839..e943990 100644 (file)
@@ -28,12 +28,8 @@ Suggestions
 
 * Optional you can make use of the third-party extension
   `static_info_tables <http://typo3.org/extensions/repository/view/static_info_tables/current/>`_.
-* If you have a multilingual environment and
-  `realurl <http://typo3.org/extensions/repository/view/realurl/current/>`_
-  installed, also install extension
-  `realurl_force404lang <http://typo3.org/extensions/repository/view/realurl_force404lang/current/>`_
-  to make automatic language guessing work.
-  
+
+
 Available markers
 ==============================
 
index 2143c1a..50cddee 100644 (file)
@@ -10,37 +10,44 @@ Known problems
 ==============================
 
 
-With solution(s)
-==============================
+With solution
+=============
 
-Extension realurl
-^^^^^^^^^^^^^^^^^
+Language guessing and realurl
+-----------------------------
 
-At the moment the automatic language guessing does not work when the language
-parameter is translated with realurl.
+Language guessing does not always work when the language parameter is translated
+with old versions of realurl.
 
 **Solution:**
-Install extension `realurl_force404lang <http://typo3.org/extensions/repository/view/realurl_force404lang/current/>`_
-if you have a multilingual environment with realurl.
-Make sure, you install realurl_force404lang **after** pagenotfoundhandling.
-Then - in extension manager configuration of realurl_force404lang - set the
-value of basic.pageNotFound_handling empty.
+Update realurl to at least version 1.12.8
 
 
-Extension aeurltool
-^^^^^^^^^^^^^^^^^^^
+Extension cooluri
+-----------------
 
-The extension aeurltool has a page not found handling too.
+By default, cooluri handles 404 errors itself.
 
 **Solution:**
-To avoid conflicting 404 configurations, disable 'Use 404-Errorpage' in the
-backend module of aeurltool.
 
-Without solution(s)
-==============================
+Configure cooluri to use the default TYPO3 404 handling. Luckily it provides
+this option itself, you just have to uncomment it in CoolUriConf.xml:
 
-Extension cooluri
-^^^^^^^^^^^^^^^^^
+::
+
+    <cooluri>
+        <cache>
+            <pagenotfound>
+                <behavior type="userfunc">Bednarik\Cooluri\Integration\Cooluri->pageNotFound</behavior>
+            </pagenotfound>
+        </cache>
+    </cooluri>
+
+
+Without solution
+================
+
+Language guessing and cooluri
+-----------------------------
 
-With cooluri enabled, the extension does not work at all. Cooluri has its own
-404 handling and won't report back to TypoScriptFrontendController
\ No newline at end of file
+With cooluri, the language guessing does not work at all.
index ed6fb62..2a8a827 100644 (file)
@@ -30,6 +30,7 @@ $EM_CONF[$_EXTKEY] = array(
                'conflicts' => array(
                ),
                'suggests' => array(
+                   'realurl' => '1.12.8'
                ),
        ),
        '_md5_values_when_last_written' => 'a:25:{s:9:"ChangeLog";s:4:"c1dc";s:33:"class.tx_pagenotfoundhandling.php";s:4:"a0f7";s:48:"class.tx_pagenotfoundhandling_LanguageSelect.php";s:4:"0b5d";s:16:"ext_autoload.php";s:4:"307a";s:21:"ext_conf_template.txt";s:4:"e7bf";s:12:"ext_icon.gif";s:4:"9d5d";s:17:"ext_localconf.php";s:4:"2664";s:14:"ext_tables.php";s:4:"d3f7";s:14:"ext_tables.sql";s:4:"bb43";s:17:"locallang_404.xml";s:4:"fd81";s:16:"locallang_db.xml";s:4:"1286";s:10:"README.txt";s:4:"407e";s:45:"Classes/Controller/PagenotfoundController.php";s:4:"598b";s:35:"Classes/Utility/LanguageUtility.php";s:4:"6770";s:44:"Configuration/TCA/Overrides/TcaAdditions.php";s:4:"5f61";s:26:"Documentation/Includes.txt";s:4:"6d5f";s:23:"Documentation/Index.rst";s:4:"4496";s:38:"Documentation/Administration/Index.rst";s:4:"c146";s:37:"Documentation/Configuration/Index.rst";s:4:"4312";s:50:"Documentation/Configuration/DomainRecord/Index.rst";s:4:"683c";s:54:"Documentation/Configuration/ExtensionManager/Index.rst";s:4:"2472";s:36:"Documentation/Introduction/Index.rst";s:4:"16b2";s:37:"Documentation/KnownProblems/Index.rst";s:4:"7ecd";s:40:"Resources/Private/Templates/default.html";s:4:"de6b";s:24:"res/defaultTemplate.tmpl";s:4:"c28a";}',
index 29bc105..325e6e2 100644 (file)
@@ -5,3 +5,20 @@ if (!defined ('TYPO3_MODE')) {
 
 // register pageNotFound_handling
 $GLOBALS['TYPO3_CONF_VARS']['FE']['pageNotFound_handling'] = 'USER_FUNCTION:Aaw\\Pagenotfoundhandling\\Controller\\PagenotfoundController->main';
+
+// Register an XCLASS for the realurl UrlDecoder
+if (\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::isLoaded('realurl')) {
+    $packageManager = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Package\\PackageManager');
+    //$packageManager instanceof \TYPO3\CMS\Core\Package\PackageManager;
+    $realurlVersion = $packageManager->getPackage('realurl')->getPackageMetaData()->getVersion();
+    if(version_compare($realurlVersion, '2.0') >= 0) {
+        $GLOBALS['TYPO3_CONF_VARS']['SYS']['Objects']['DmitryDulepov\\Realurl\\Decoder\\UrlDecoder'] = array(
+            'className' => 'Aaw\\Pagenotfoundhandling\\Realurl\\Decoder\\UrlDecoder',
+        );
+    } elseif(version_compare($realurlVersion, '1.12.8') >= 0) {
+        // version 1.12.8 was the first realurl version with official TYPO3 6.2 support
+        $GLOBALS['TYPO3_CONF_VARS']['SYS']['Objects']['tx_realurl'] = array(
+            'className' => 'Aaw\\Pagenotfoundhandling\\Realurl\\RealurlV1',
+        );
+    }
+}