[TASK] Replace csConvObj calls 27/46627/4
authorBenni Mack <benni@typo3.org>
Fri, 12 Feb 2016 17:10:35 +0000 (18:10 +0100)
committerGeorg Ringer <georg.ringer@gmail.com>
Tue, 16 Feb 2016 09:43:28 +0000 (10:43 +0100)
The CharsetConverter object is agnostic
of charset and environment, and a singleton on top.

There are still several calls in the TYPO3 core
that tries to fetch csConv from TSFE or LANG
which relies heavily on the environment.

The calls are replaced with simple instance
calls where possible.

Resolves: #73441
Releases: master
Change-Id: I098f17b1cdbcc1ebbbb7359cfec518c93597aad4
Reviewed-on: https://review.typo3.org/46627
Reviewed-by: Stefan Froemken <froemken@gmail.com>
Tested-by: Stefan Froemken <froemken@gmail.com>
Reviewed-by: Georg Ringer <georg.ringer@gmail.com>
Tested-by: Georg Ringer <georg.ringer@gmail.com>
12 files changed:
typo3/sysext/backend/Classes/Controller/LoginController.php
typo3/sysext/backend/Classes/Form/Wizard/SuggestWizardDefaultReceiver.php
typo3/sysext/backend/Classes/FrontendBackendUserAuthentication.php
typo3/sysext/core/Classes/DataHandling/DataHandler.php
typo3/sysext/core/Classes/Utility/File/BasicFileUtility.php
typo3/sysext/core/Classes/Utility/GeneralUtility.php
typo3/sysext/extbase/Classes/Utility/LocalizationUtility.php
typo3/sysext/fluid/Classes/ViewHelpers/Format/CropViewHelper.php
typo3/sysext/form/Classes/Domain/Filter/AbstractFilter.php
typo3/sysext/indexed_search/Classes/Controller/SearchController.php
typo3/sysext/indexed_search/Classes/Controller/SearchFormController.php
typo3/sysext/tstemplate/Classes/Controller/TypoScriptTemplateObjectBrowserModuleFunctionController.php

index c03042d..1265553 100644 (file)
@@ -20,6 +20,7 @@ use TYPO3\CMS\Backend\Exception;
 use TYPO3\CMS\Backend\LoginProvider\LoginProviderInterface;
 use TYPO3\CMS\Backend\Utility\BackendUtility;
 use TYPO3\CMS\Core\Authentication\BackendUserAuthentication;
+use TYPO3\CMS\Core\Charset\CharsetConverter;
 use TYPO3\CMS\Core\FormProtection\BackendFormProtection;
 use TYPO3\CMS\Core\FormProtection\FormProtectionFactory;
 use TYPO3\CMS\Core\Page\PageRenderer;
@@ -99,7 +100,9 @@ class LoginController
         $this->submitValue = GeneralUtility::_GP('commandLI');
 
         // Try to get the preferred browser language
-        $preferredBrowserLanguage = $this->getLanguageService()->csConvObj
+        /** @var CharsetConverter $charsetConverter */
+        $charsetConverter = GeneralUtility::makeInstance(CharsetConverter::class);
+        $preferredBrowserLanguage = $charsetConverter
             ->getPreferredClientLanguage(GeneralUtility::getIndpEnv('HTTP_ACCEPT_LANGUAGE'));
 
         // If we found a $preferredBrowserLanguage and it is not the default language and no be_user is logged in
index 38d3de7..ce4d795 100644 (file)
@@ -15,6 +15,7 @@ namespace TYPO3\CMS\Backend\Form\Wizard;
  */
 
 use TYPO3\CMS\Backend\Utility\BackendUtility;
+use TYPO3\CMS\Core\Charset\CharsetConverter;
 use TYPO3\CMS\Core\Imaging\Icon;
 use TYPO3\CMS\Core\Imaging\IconFactory;
 use TYPO3\CMS\Core\Utility\GeneralUtility;
@@ -156,6 +157,8 @@ class SuggestWizardDefaultReceiver
         $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery('*', $this->table, $this->selectClause, '', $this->orderByStatement, $start . ', 50');
         $allRowsCount = $GLOBALS['TYPO3_DB']->sql_num_rows($res);
         if ($allRowsCount) {
+            /** @var CharsetConverter $charsetConverter */
+            $charsetConverter = GeneralUtility::makeInstance(CharsetConverter::class);
             while ($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) {
                 // check if we already have collected the maximum number of records
                 if (count($rows) > $this->maxItems) {
@@ -171,12 +174,11 @@ class SuggestWizardDefaultReceiver
                 $uid = $row['t3ver_oid'] > 0 ? $row['t3ver_oid'] : $row['uid'];
                 $path = $this->getRecordPath($row, $uid);
                 if (strlen($path) > 30) {
-                    $languageService = $this->getLanguageService();
                     $croppedPath = '<abbr title="' . htmlspecialchars($path) . '">' .
                         htmlspecialchars(
-                                $languageService->csConvObj->crop('utf-8', $path, 10)
+                            $charsetConverter->crop('utf-8', $path, 10)
                                 . '...'
-                                . $languageService->csConvObj->crop('utf-8', $path, -20)
+                                . $charsetConverter->crop('utf-8', $path, -20)
                         ) .
                         '</abbr>';
                 } else {
index 0212133..0ca2117 100755 (executable)
@@ -15,6 +15,7 @@ namespace TYPO3\CMS\Backend;
  */
 
 use TYPO3\CMS\Core\Cache\Frontend\FrontendInterface;
+use TYPO3\CMS\Core\Charset\CharsetConverter;
 use TYPO3\CMS\Core\Utility\GeneralUtility;
 use TYPO3\CMS\Lang\LanguageService;
 
@@ -292,9 +293,10 @@ class FrontendBackendUserAuthentication extends \TYPO3\CMS\Core\Authentication\B
         }
         // Label string in the default backend output charset.
         $labelStr = htmlspecialchars($this->getLanguageService()->getLL($key));
-        $labelStr = $this->getLanguageService()->csConvObj->utf8_to_entities($labelStr);
-        // Return the result:
-        return $labelStr;
+
+        /** @var CharsetConverter $charsetConverter */
+        $charsetConverter = GeneralUtility::makeInstance(CharsetConverter::class);
+        return $charsetConverter->utf8_to_entities($labelStr);
     }
 
     /**
index 789f6b4..0824d4f 100644 (file)
@@ -18,6 +18,7 @@ use TYPO3\CMS\Backend\Utility\BackendUtility;
 use TYPO3\CMS\Core\Authentication\BackendUserAuthentication;
 use TYPO3\CMS\Core\Cache\CacheManager;
 use TYPO3\CMS\Core\Cache\Frontend\VariableFrontend;
+use TYPO3\CMS\Core\Charset\CharsetConverter;
 use TYPO3\CMS\Core\Configuration\FlexForm\FlexFormTools;
 use TYPO3\CMS\Core\Database\DatabaseConnection;
 use TYPO3\CMS\Core\Database\ReferenceIndex;
@@ -1763,7 +1764,9 @@ class DataHandler
         }
         // Secures the string-length to be less than max.
         if ((int)$tcaFieldConf['max'] > 0) {
-            $value = $GLOBALS['LANG']->csConvObj->substr('utf-8', (string)$value, 0, (int)$tcaFieldConf['max']);
+            /** @var CharsetConverter $charsetConverter */
+            $charsetConverter = GeneralUtility::makeInstance(CharsetConverter::class);
+            $value = $charsetConverter->substr('utf-8', (string)$value, 0, (int)$tcaFieldConf['max']);
         }
         // Checking range of value:
         // @todo: The "checkbox" option was removed for type=input, this check could be probably relaxed?
@@ -2684,10 +2687,14 @@ class DataHandler
                     $value = trim($value);
                     break;
                 case 'upper':
-                    $value = $GLOBALS['LANG']->csConvObj->conv_case('utf-8', $value, 'toUpper');
+                    /** @var CharsetConverter $charsetConverter */
+                    $charsetConverter = GeneralUtility::makeInstance(CharsetConverter::class);
+                    $value = $charsetConverter->conv_case('utf-8', $value, 'toUpper');
                     break;
                 case 'lower':
-                    $value = $GLOBALS['LANG']->csConvObj->conv_case('utf-8', $value, 'toLower');
+                    /** @var CharsetConverter $charsetConverter */
+                    $charsetConverter = GeneralUtility::makeInstance(CharsetConverter::class);
+                    $value = $charsetConverter->conv_case('utf-8', $value, 'toLower');
                     break;
                 case 'required':
                     if (!isset($value) || $value === '') {
index 6f11491..e1f5606 100644 (file)
@@ -14,6 +14,7 @@ namespace TYPO3\CMS\Core\Utility\File;
  * The TYPO3 project - inspiring people to share!
  */
 
+use TYPO3\CMS\Core\Charset\CharsetConverter;
 use TYPO3\CMS\Core\Utility\GeneralUtility;
 use TYPO3\CMS\Core\Utility\PathUtility;
 
@@ -90,11 +91,6 @@ class BasicFileUtility
      */
     public $isInit = 0;
 
-    /**
-     * @var \TYPO3\CMS\Core\Charset\CharsetConverter
-     */
-    public $csConvObj;
-
     /**********************************
      *
      * Checking functions
@@ -379,35 +375,27 @@ class BasicFileUtility
      * Trailing dots are removed
      *
      * @param string $fileName Input string, typically the body of a filename
-     * @param string $charset Charset of the a filename (defaults to current charset; depending on context)
      * @return string Output string with any characters not matching [.a-zA-Z0-9_-] is substituted by '_' and trailing dots removed
      * @todo Deprecate, but still in use by the core
      * @deprecated but still in use in the Core. Don't use in your extensions!
      */
-    public function cleanFileName($fileName, $charset = '')
+    public function cleanFileName($fileName)
     {
         // Handle UTF-8 characters
         if ($GLOBALS['TYPO3_CONF_VARS']['SYS']['UTF8filesystem']) {
             // allow ".", "-", 0-9, a-z, A-Z and everything beyond U+C0 (latin capital letter a with grave)
             $cleanFileName = preg_replace('/[' . self::UNSAFE_FILENAME_CHARACTER_EXPRESSION . ']/u', '_', trim($fileName));
         } else {
-            // Get conversion object or initialize if needed
-            if (!is_object($this->csConvObj)) {
-                $this->csConvObj = GeneralUtility::makeInstance(\TYPO3\CMS\Core\Charset\CharsetConverter::class);
-            }
             // Define character set
-            if (!$charset) {
-                if (TYPO3_MODE == 'FE') {
-                    $charset = $GLOBALS['TSFE']->renderCharset;
-                } else {
-                    // Backend
-                    $charset = 'utf-8';
-                }
-            }
-            // If a charset was found, convert filename
-            if ($charset) {
-                $fileName = $this->csConvObj->specCharsToASCII($charset, $fileName);
+            if (is_object($GLOBALS['TSFE'])) {
+                $charset = $GLOBALS['TSFE']->renderCharset;
+            } else {
+                $charset = 'utf-8';
             }
+            /** @var CharsetConverter $charsetConverter */
+            $charsetConverter = GeneralUtility::makeInstance(CharsetConverter::class);
+            $fileName = $charsetConverter->specCharsToASCII($charset, $fileName);
+
             // Replace unwanted characters by underscores
             $cleanFileName = preg_replace('/[' . self::UNSAFE_FILENAME_CHARACTER_EXPRESSION . '\\xC0-\\xFF]/', '_', trim($fileName));
         }
index e523672..767729e 100755 (executable)
@@ -14,6 +14,7 @@ namespace TYPO3\CMS\Core\Utility;
  * The TYPO3 project - inspiring people to share!
  */
 
+use TYPO3\CMS\Core\Charset\CharsetConverter;
 use TYPO3\CMS\Core\Core\ApplicationContext;
 use TYPO3\CMS\Core\Core\ClassLoadingInformation;
 use TYPO3\CMS\Core\Service\OpcodeCacheService;
@@ -273,16 +274,14 @@ class GeneralUtility
      */
     public static function fixed_lgd_cs($string, $chars, $appendString = '...')
     {
-        if (is_object($GLOBALS['LANG'])) {
-            return $GLOBALS['LANG']->csConvObj->crop('utf-8', $string, $chars, $appendString);
-        } elseif (is_object($GLOBALS['TSFE']) && is_object($GLOBALS['TSFE']->csConvObj)) {
-            $charSet = $GLOBALS['TSFE']->renderCharset != '' ? $GLOBALS['TSFE']->renderCharset : $GLOBALS['TSFE']->defaultCharSet;
-            return $GLOBALS['TSFE']->csConvObj->crop($charSet, $string, $chars, $appendString);
+        if (is_object($GLOBALS['TSFE'])) {
+            $charset = $GLOBALS['TSFE']->renderCharset != '' ? $GLOBALS['TSFE']->renderCharset : $GLOBALS['TSFE']->defaultCharSet;
         } else {
-            // This case should not happen
-            $csConvObj = self::makeInstance(\TYPO3\CMS\Core\Charset\CharsetConverter::class);
-            return $csConvObj->crop('utf-8', $string, $chars, $appendString);
+            $charset = 'utf-8';
         }
+        /** @var CharsetConverter $charsetConverter */
+        $charsetConverter = self::makeInstance(\TYPO3\CMS\Core\Charset\CharsetConverter::class);
+        return $charsetConverter->crop($charset, $string, $chars, $appendString);
     }
 
     /**
index 27b88f1..74a40c2 100644 (file)
@@ -14,6 +14,7 @@ namespace TYPO3\CMS\Extbase\Utility;
  * The TYPO3 project - inspiring people to share!
  */
 
+use TYPO3\CMS\Core\Charset\CharsetConverter;
 use TYPO3\CMS\Core\Localization\Locales;
 use TYPO3\CMS\Core\Localization\LocalizationFactory;
 use TYPO3\CMS\Core\Utility\GeneralUtility;
@@ -229,6 +230,8 @@ class LocalizationUtility
             return;
         }
         self::$LOCAL_LANG_UNSET[$extensionName] = array();
+        /** @var CharsetConverter $charsetConverter */
+        $charsetConverter = GeneralUtility::makeInstance(CharsetConverter::class);
         foreach ($frameworkConfiguration['_LOCAL_LANG'] as $languageKey => $labels) {
             if (!(is_array($labels) && isset(self::$LOCAL_LANG[$extensionName][$languageKey]))) {
                 continue;
@@ -239,11 +242,7 @@ class LocalizationUtility
                     if ($labelValue === '') {
                         self::$LOCAL_LANG_UNSET[$extensionName][$languageKey][$labelKey] = '';
                     }
-                    if (is_object($GLOBALS['LANG'])) {
-                        self::$LOCAL_LANG_charset[$extensionName][$languageKey][$labelKey] = self::getLanguageService()->csConvObj->charSetArray[$languageKey];
-                    } else {
-                        self::$LOCAL_LANG_charset[$extensionName][$languageKey][$labelKey] = self::getTypoScriptFrontendController()->csConvObj->charSetArray[$languageKey];
-                    }
+                    self::$LOCAL_LANG_charset[$extensionName][$languageKey][$labelKey] = $charsetConverter->charSetArray[$languageKey];
                 } elseif (is_array($labelValue)) {
                     $labelValue = self::flattenTypoScriptLabelArray($labelValue, $labelKey);
                     foreach ($labelValue as $key => $value) {
index c35b2c7..2e0828a 100644 (file)
@@ -141,11 +141,7 @@ class CropViewHelper extends AbstractViewHelper
         $GLOBALS['TSFE'] = new \stdClass();
         // preparing csConvObj
         if (!is_object($GLOBALS['TSFE']->csConvObj)) {
-            if (is_object($GLOBALS['LANG'])) {
-                $GLOBALS['TSFE']->csConvObj = $GLOBALS['LANG']->csConvObj;
-            } else {
-                $GLOBALS['TSFE']->csConvObj = GeneralUtility::makeInstance(CharsetConverter::class);
-            }
+            $GLOBALS['TSFE']->csConvObj = GeneralUtility::makeInstance(CharsetConverter::class);
         }
         // preparing renderCharset
         if (!is_object($GLOBALS['TSFE']->renderCharset)) {
index b22ca65..e93b547 100644 (file)
@@ -13,6 +13,8 @@ namespace TYPO3\CMS\Form\Domain\Filter;
  *
  * The TYPO3 project - inspiring people to share!
  */
+use TYPO3\CMS\Core\Charset\CharsetConverter;
+use TYPO3\CMS\Core\Utility\GeneralUtility;
 
 /**
  * Abstract class for filters.
@@ -30,11 +32,11 @@ abstract class AbstractFilter
     }
 
     /**
-     * @return \TYPO3\CMS\Core\Charset\CharsetConverter
+     * @return CharsetConverter
      */
     protected function getCharsetConverter()
     {
-        return $this->getTypoScriptFrontendController()->csConvObj;
+        return GeneralUtility::makeInstance(CharsetConverter::class);
     }
 
     /**
index 5a98a11..7aebd9b 100644 (file)
@@ -14,6 +14,7 @@ namespace TYPO3\CMS\IndexedSearch\Controller;
  * The TYPO3 project - inspiring people to share!
  */
 
+use TYPO3\CMS\Core\Charset\CharsetConverter;
 use TYPO3\CMS\Core\Html\HtmlParser;
 use TYPO3\CMS\Core\Utility\GeneralUtility;
 use TYPO3\CMS\Core\Utility\MathUtility;
@@ -142,6 +143,11 @@ class SearchController extends \TYPO3\CMS\Extbase\Mvc\Controller\ActionControlle
     protected $typoScriptService;
 
     /**
+     * @var CharsetConverter
+     */
+    protected $charsetConverter;
+
+    /**
      * @param \TYPO3\CMS\Extbase\Service\TypoScriptService $typoScriptService
      */
     public function injectTypoScriptService(\TYPO3\CMS\Extbase\Service\TypoScriptService $typoScriptService)
@@ -157,6 +163,7 @@ class SearchController extends \TYPO3\CMS\Extbase\Mvc\Controller\ActionControlle
      */
     public function initialize($searchData = array())
     {
+        $this->charsetConverter = GeneralUtility::makeInstance(CharsetConverter::class);
         if (!is_array($searchData)) {
             $searchData = array();
         }
@@ -415,7 +422,7 @@ class SearchController extends \TYPO3\CMS\Extbase\Mvc\Controller\ActionControlle
             }
         }
         $title = $resultData['item_title'] . $resultData['titleaddition'];
-        $title = $GLOBALS['TSFE']->csConvObj->crop('utf-8', $title, $this->settings['results.']['titleCropAfter'], $this->settings['results.']['titleCropSignifier']);
+        $title = $this->charsetConverter->crop('utf-8', $title, $this->settings['results.']['titleCropAfter'], $this->settings['results.']['titleCropSignifier']);
         // If external media, link to the media-file instead.
         if ($row['item_type']) {
             if ($row['show_resume']) {
@@ -661,7 +668,7 @@ class SearchController extends \TYPO3\CMS\Extbase\Mvc\Controller\ActionControlle
                 $this->getDatabaseConnection()->sql_free_result($res);
             }
             if (!trim($markedSW)) {
-                $outputStr = $GLOBALS['TSFE']->csConvObj->crop('utf-8', $row['item_description'], $length, $this->settings['results.']['summaryCropSignifier']);
+                $outputStr = $this->charsetConverter->crop('utf-8', $row['item_description'], $length, $this->settings['results.']['summaryCropSignifier']);
                 $outputStr = htmlspecialchars($outputStr);
             }
             $output = $outputStr ?: $markedSW;
@@ -708,25 +715,25 @@ class SearchController extends \TYPO3\CMS\Extbase\Mvc\Controller\ActionControlle
         foreach ($parts as $k => $strP) {
             if ($k % 2 == 0) {
                 // Find length of the summary part:
-                $strLen = $GLOBALS['TSFE']->csConvObj->strlen('utf-8', $parts[$k]);
+                $strLen = $this->charsetConverter->strlen('utf-8', $parts[$k]);
                 $output[$k] = $parts[$k];
                 // Possibly shorten string:
                 if (!$k) {
                     // First entry at all (only cropped on the frontside)
                     if ($strLen > $postPreLgd) {
-                        $output[$k] = $divider . preg_replace('/^[^[:space:]]+[[:space:]]/', '', $GLOBALS['TSFE']->csConvObj->crop('utf-8', $parts[$k], -($postPreLgd - $postPreLgd_offset)));
+                        $output[$k] = $divider . preg_replace('/^[^[:space:]]+[[:space:]]/', '', $this->charsetConverter->crop('utf-8', $parts[$k], -($postPreLgd - $postPreLgd_offset)));
                     }
                 } elseif ($summaryLgd > $summaryMax || !isset($parts[$k + 1])) {
                     // In case summary length is exceed OR if there are no more entries at all:
                     if ($strLen > $postPreLgd) {
-                        $output[$k] = preg_replace('/[[:space:]][^[:space:]]+$/', '', $GLOBALS['TSFE']->csConvObj->crop('utf-8', $parts[$k], ($postPreLgd - $postPreLgd_offset))) . $divider;
+                        $output[$k] = preg_replace('/[[:space:]][^[:space:]]+$/', '', $this->charsetConverter->crop('utf-8', $parts[$k], ($postPreLgd - $postPreLgd_offset))) . $divider;
                     }
                 } else {
                     if ($strLen > $postPreLgd * 2) {
-                        $output[$k] = preg_replace('/[[:space:]][^[:space:]]+$/', '', $GLOBALS['TSFE']->csConvObj->crop('utf-8', $parts[$k], ($postPreLgd - $postPreLgd_offset))) . $divider . preg_replace('/^[^[:space:]]+[[:space:]]/', '', $GLOBALS['TSFE']->csConvObj->crop('utf-8', $parts[$k], -($postPreLgd - $postPreLgd_offset)));
+                        $output[$k] = preg_replace('/[[:space:]][^[:space:]]+$/', '', $this->charsetConverter->crop('utf-8', $parts[$k], ($postPreLgd - $postPreLgd_offset))) . $divider . preg_replace('/^[^[:space:]]+[[:space:]]/', '', $this->charsetConverter->crop('utf-8', $parts[$k], -($postPreLgd - $postPreLgd_offset)));
                     }
                 }
-                $summaryLgd += $GLOBALS['TSFE']->csConvObj->strlen('utf-8', $output[$k]);
+                $summaryLgd += $this->charsetConverter->strlen('utf-8', $output[$k]);
                 // Protect output:
                 $output[$k] = htmlspecialchars($output[$k]);
                 // If summary lgd is exceed, break the process:
@@ -734,7 +741,7 @@ class SearchController extends \TYPO3\CMS\Extbase\Mvc\Controller\ActionControlle
                     break;
                 }
             } else {
-                $summaryLgd += $GLOBALS['TSFE']->csConvObj->strlen('utf-8', $strP);
+                $summaryLgd += $this->charsetConverter->strlen('utf-8', $strP);
                 $output[$k] = '<strong class="tx-indexedsearch-redMarkup">' . htmlspecialchars($parts[$k]) . '</strong>';
             }
         }
@@ -805,8 +812,8 @@ class SearchController extends \TYPO3\CMS\Extbase\Mvc\Controller\ActionControlle
         // shortening the string here is only a run-away feature!)
         $searchWords = substr($this->sword, 0, 200);
         // Convert to UTF-8 + conv. entities (was also converted during indexing!)
-        $searchWords = $GLOBALS['TSFE']->csConvObj->conv($searchWords, $GLOBALS['TSFE']->metaCharset, 'utf-8');
-        $searchWords = $GLOBALS['TSFE']->csConvObj->entities_to_utf8($searchWords, true);
+        $searchWords = $this->charsetConverter->conv($searchWords, $GLOBALS['TSFE']->metaCharset, 'utf-8');
+        $searchWords = $this->charsetConverter->entities_to_utf8($searchWords, true);
         $sWordArray = false;
         if ($hookObj = $this->hookRequest('getSearchWords')) {
             $sWordArray = $hookObj->getSearchWords_splitSWords($searchWords, $defaultOperator);
@@ -828,9 +835,9 @@ class SearchController extends \TYPO3\CMS\Extbase\Mvc\Controller\ActionControlle
                     array('-', 'AND NOT'),
                     // Add operators for various languages
                     // Converts the operators to UTF-8 and lowercase
-                    array($GLOBALS['TSFE']->csConvObj->conv_case('utf-8', $GLOBALS['TSFE']->csConvObj->conv(LocalizationUtility::translate('localizedOperandAnd', 'IndexedSearch'), $GLOBALS['TSFE']->renderCharset, 'utf-8'), 'toLower'), 'AND'),
-                    array($GLOBALS['TSFE']->csConvObj->conv_case('utf-8', $GLOBALS['TSFE']->csConvObj->conv(LocalizationUtility::translate('localizedOperandOr', 'IndexedSearch'), $GLOBALS['TSFE']->renderCharset, 'utf-8'), 'toLower'), 'OR'),
-                    array($GLOBALS['TSFE']->csConvObj->conv_case('utf-8', $GLOBALS['TSFE']->csConvObj->conv(LocalizationUtility::translate('localizedOperandNot', 'IndexedSearch'), $GLOBALS['TSFE']->renderCharset, 'utf-8'), 'toLower'), 'AND NOT')
+                    array($this->charsetConverter->conv_case('utf-8', $this->charsetConverter->conv(LocalizationUtility::translate('localizedOperandAnd', 'IndexedSearch'), $GLOBALS['TSFE']->renderCharset, 'utf-8'), 'toLower'), 'AND'),
+                    array($this->charsetConverter->conv_case('utf-8', $this->charsetConverter->conv(LocalizationUtility::translate('localizedOperandOr', 'IndexedSearch'), $GLOBALS['TSFE']->renderCharset, 'utf-8'), 'toLower'), 'OR'),
+                    array($this->charsetConverter->conv_case('utf-8', $this->charsetConverter->conv(LocalizationUtility::translate('localizedOperandNot', 'IndexedSearch'), $GLOBALS['TSFE']->renderCharset, 'utf-8'), 'toLower'), 'AND NOT')
                 );
                 $swordArray = \TYPO3\CMS\IndexedSearch\Utility\IndexedSearchUtility::getExplodedSearchString($searchWords, $defaultOperator == 1 ? 'OR' : 'AND', $operatorTranslateTable);
                 if (is_array($swordArray)) {
index 44631ae..ca4bad0 100755 (executable)
@@ -14,6 +14,7 @@ namespace TYPO3\CMS\IndexedSearch\Controller;
  * The TYPO3 project - inspiring people to share!
  */
 
+use TYPO3\CMS\Core\Charset\CharsetConverter;
 use TYPO3\CMS\Core\Html\HtmlParser;
 use TYPO3\CMS\Core\Utility\GeneralUtility;
 use TYPO3\CMS\Core\Utility\MathUtility;
@@ -171,6 +172,11 @@ class SearchFormController extends \TYPO3\CMS\Frontend\Plugin\AbstractPlugin
     public $lexerObj;
 
     /**
+     * @var CharsetConverter
+     */
+    protected $charsetConverter;
+
+    /**
      * Main function, called from TypoScript as a USER_INT object.
      *
      * @param string $content Content input, ignore (just put blank string)
@@ -180,6 +186,7 @@ class SearchFormController extends \TYPO3\CMS\Frontend\Plugin\AbstractPlugin
     public function main($content, $conf)
     {
         // Initialize:
+        $this->charsetConverter = GeneralUtility::makeInstance(CharsetConverter::class);
         $this->conf = $conf;
         $this->pi_loadLL('EXT:indexed_search/Resources/Private/Language/locallang_pi.xlf');
         $this->pi_setPiVarDefaults();
@@ -326,9 +333,9 @@ class SearchFormController extends \TYPO3\CMS\Frontend\Plugin\AbstractPlugin
         }
         // Add operators for various languages
         // Converts the operators to UTF-8 and lowercase
-        $this->operator_translate_table[] = array($this->frontendController->csConvObj->conv_case('utf-8', $this->frontendController->csConvObj->conv($this->pi_getLL('local_operator_AND'), $this->frontendController->renderCharset, 'utf-8'), 'toLower'), 'AND');
-        $this->operator_translate_table[] = array($this->frontendController->csConvObj->conv_case('utf-8', $this->frontendController->csConvObj->conv($this->pi_getLL('local_operator_OR'), $this->frontendController->renderCharset, 'utf-8'), 'toLower'), 'OR');
-        $this->operator_translate_table[] = array($this->frontendController->csConvObj->conv_case('utf-8', $this->frontendController->csConvObj->conv($this->pi_getLL('local_operator_NOT'), $this->frontendController->renderCharset, 'utf-8'), 'toLower'), 'AND NOT');
+        $this->operator_translate_table[] = array($this->charsetConverter->conv_case('utf-8', $this->charsetConverter->conv($this->pi_getLL('local_operator_AND'), $this->frontendController->renderCharset, 'utf-8'), 'toLower'), 'AND');
+        $this->operator_translate_table[] = array($this->charsetConverter->conv_case('utf-8', $this->charsetConverter->conv($this->pi_getLL('local_operator_OR'), $this->frontendController->renderCharset, 'utf-8'), 'toLower'), 'OR');
+        $this->operator_translate_table[] = array($this->charsetConverter->conv_case('utf-8', $this->charsetConverter->conv($this->pi_getLL('local_operator_NOT'), $this->frontendController->renderCharset, 'utf-8'), 'toLower'), 'AND NOT');
         // This is the id of the site root. This value may be a commalist of integer (prepared for this)
         $this->wholeSiteIdList = (int)$this->frontendController->config['rootLine'][0]['uid'];
         // Creating levels for section menu:
@@ -419,8 +426,8 @@ class SearchFormController extends \TYPO3\CMS\Frontend\Plugin\AbstractPlugin
         // Shorten search-word string to max 200 bytes (does NOT take multibyte charsets into account - but never mind, shortening the string here is only a run-away feature!)
         $inSW = substr($this->piVars['sword'], 0, 200);
         // Convert to UTF-8 + conv. entities (was also converted during indexing!)
-        $inSW = $this->frontendController->csConvObj->conv($inSW, $this->frontendController->metaCharset, 'utf-8');
-        $inSW = $this->frontendController->csConvObj->entities_to_utf8($inSW, true);
+        $inSW = $this->charsetConverter->conv($inSW, $this->frontendController->metaCharset, 'utf-8');
+        $inSW = $this->charsetConverter->entities_to_utf8($inSW, true);
         $sWordArray = false;
         if ($hookObj = $this->hookRequest('getSearchWords')) {
             $sWordArray = $hookObj->getSearchWords_splitSWords($inSW, $defOp);
@@ -1937,7 +1944,7 @@ class SearchFormController extends \TYPO3\CMS\Frontend\Plugin\AbstractPlugin
                 }
             }
             if (!trim($markedSW)) {
-                $outputStr = $this->frontendController->csConvObj->crop('utf-8', $row['item_description'], $lgd, $this->conf['results.']['summaryCropSignifier']);
+                $outputStr = $this->charsetConverter->crop('utf-8', $row['item_description'], $lgd, $this->conf['results.']['summaryCropSignifier']);
                 $outputStr = htmlspecialchars($outputStr);
             }
             $output = $this->utf8_to_currentCharset($outputStr ?: $markedSW);
@@ -1983,26 +1990,26 @@ class SearchFormController extends \TYPO3\CMS\Frontend\Plugin\AbstractPlugin
         foreach ($parts as $k => $strP) {
             if ($k % 2 == 0) {
                 // Find length of the summary part:
-                $strLen = $this->frontendController->csConvObj->strlen('utf-8', $parts[$k]);
+                $strLen = $this->charsetConverter->strlen('utf-8', $parts[$k]);
                 $output[$k] = $parts[$k];
                 // Possibly shorten string:
                 if (!$k) {
                     // First entry at all (only cropped on the frontside)
                     if ($strLen > $postPreLgd) {
-                        $output[$k] = $divider . preg_replace('/^[^[:space:]]+[[:space:]]/', '', $this->frontendController->csConvObj->crop('utf-8', $parts[$k], -($postPreLgd - $postPreLgd_offset)));
+                        $output[$k] = $divider . preg_replace('/^[^[:space:]]+[[:space:]]/', '', $this->charsetConverter->crop('utf-8', $parts[$k], -($postPreLgd - $postPreLgd_offset)));
                     }
                 } elseif ($summaryLgd > $summaryMax || !isset($parts[$k + 1])) {
                     // In case summary length is exceed OR if there are no more entries at all:
                     if ($strLen > $postPreLgd) {
-                        $output[$k] = preg_replace('/[[:space:]][^[:space:]]+$/', '', $this->frontendController->csConvObj->crop('utf-8', $parts[$k], ($postPreLgd - $postPreLgd_offset))) . $divider;
+                        $output[$k] = preg_replace('/[[:space:]][^[:space:]]+$/', '', $this->charsetConverter->crop('utf-8', $parts[$k], ($postPreLgd - $postPreLgd_offset))) . $divider;
                     }
                 } else {
                     // In-between search words:
                     if ($strLen > $postPreLgd * 2) {
-                        $output[$k] = preg_replace('/[[:space:]][^[:space:]]+$/', '', $this->frontendController->csConvObj->crop('utf-8', $parts[$k], ($postPreLgd - $postPreLgd_offset))) . $divider . preg_replace('/^[^[:space:]]+[[:space:]]/', '', $this->frontendController->csConvObj->crop('utf-8', $parts[$k], -($postPreLgd - $postPreLgd_offset)));
+                        $output[$k] = preg_replace('/[[:space:]][^[:space:]]+$/', '', $this->charsetConverter->crop('utf-8', $parts[$k], ($postPreLgd - $postPreLgd_offset))) . $divider . preg_replace('/^[^[:space:]]+[[:space:]]/', '', $this->charsetConverter->crop('utf-8', $parts[$k], -($postPreLgd - $postPreLgd_offset)));
                     }
                 }
-                $summaryLgd += $this->frontendController->csConvObj->strlen('utf-8', $output[$k]);
+                $summaryLgd += $this->charsetConverter->strlen('utf-8', $output[$k]);
                 // Protect output:
                 $output[$k] = htmlspecialchars($output[$k]);
                 // If summary lgd is exceed, break the process:
@@ -2010,7 +2017,7 @@ class SearchFormController extends \TYPO3\CMS\Frontend\Plugin\AbstractPlugin
                     break;
                 }
             } else {
-                $summaryLgd += $this->frontendController->csConvObj->strlen('utf-8', $strP);
+                $summaryLgd += $this->charsetConverter->strlen('utf-8', $strP);
                 $output[$k] = '<strong class="tx-indexedsearch-redMarkup">' . htmlspecialchars($parts[$k]) . '</strong>';
             }
         }
@@ -2036,7 +2043,7 @@ class SearchFormController extends \TYPO3\CMS\Frontend\Plugin\AbstractPlugin
                 $add = ', ' . $this->pi_getLL('word_page') . ' ' . $pp[0];
             }
         }
-        $outputString = $this->frontendController->csConvObj->crop('utf-8', $row['item_title'], $this->conf['results.']['titleCropAfter'], $this->conf['results.']['titleCropSignifier']);
+        $outputString = $this->charsetConverter->crop('utf-8', $row['item_title'], $this->conf['results.']['titleCropAfter'], $this->conf['results.']['titleCropSignifier']);
         return $this->utf8_to_currentCharset($outputString) . $add;
     }
 
index 0cf41e3..02d7ca7 100644 (file)
@@ -16,6 +16,7 @@ namespace TYPO3\CMS\Tstemplate\Controller;
 
 use TYPO3\CMS\Backend\Module\AbstractFunctionModule;
 use TYPO3\CMS\Backend\Utility\BackendUtility;
+use TYPO3\CMS\Core\Charset\CharsetConverter;
 use TYPO3\CMS\Core\DataHandling\DataHandler;
 use TYPO3\CMS\Core\Exception;
 use TYPO3\CMS\Core\Imaging\Icon;
@@ -60,6 +61,8 @@ class TypoScriptTemplateObjectBrowserModuleFunctionController extends AbstractFu
     public function modMenu()
     {
         $lang = $this->getLanguageService();
+        /** @var CharsetConverter $charsetConverter */
+        $charsetConverter = GeneralUtility::makeInstance(CharsetConverter::class);
         $lang->includeLLFile('EXT:tstemplate/Resources/Private/Language/locallang_objbrowser.xlf');
         $modMenu = array(
             'ts_browser_type' => array(
@@ -67,10 +70,10 @@ class TypoScriptTemplateObjectBrowserModuleFunctionController extends AbstractFu
                 'setup' => $lang->getLL('setup')
             ),
             'ts_browser_toplevel_setup' => array(
-                '0' => $lang->csConvObj->conv_case('utf-8', $lang->getLL('all'), 'toUpper')
+                '0' => $charsetConverter->conv_case('utf-8', $lang->getLL('all'), 'toUpper')
             ),
             'ts_browser_toplevel_const' => array(
-                '0' => $lang->csConvObj->conv_case('utf-8', $lang->getLL('all'), 'toUpper')
+                '0' => $charsetConverter->conv_case('utf-8', $lang->getLL('all'), 'toUpper')
             ),
             'ts_browser_const' => array(
                 '0' => $lang->getLL('plainSubstitution'),
@@ -142,6 +145,8 @@ class TypoScriptTemplateObjectBrowserModuleFunctionController extends AbstractFu
         $lang = $this->getLanguageService();
         $POST = GeneralUtility::_POST();
         $documentTemplate = $this->getDocumentTemplate();
+        /** @var CharsetConverter $charsetConverter */
+        $charsetConverter = GeneralUtility::makeInstance(CharsetConverter::class);
 
         // Checking for more than one template an if, set a menu...
         $manyTemplatesMenu = $this->pObj->templateMenu();
@@ -292,7 +297,7 @@ class TypoScriptTemplateObjectBrowserModuleFunctionController extends AbstractFu
                 $out = '<div class="form-group">';
                 $out .= '      <div class="checkbox">';
                 $out .= '              <label>';
-                $out .= '                      ' . htmlspecialchars($this->pObj->sObj) . ' ' . $lang->csConvObj->conv_case('utf-8', $lang->getLL('clear'), 'toUpper');
+                $out .= '                      ' . htmlspecialchars($this->pObj->sObj) . ' ' . $charsetConverter->conv_case('utf-8', $lang->getLL('clear'), 'toUpper');
                 $out .= '                      <input type="checkbox" name="data[' . htmlspecialchars($this->pObj->sObj) . '][clearValue]" value="1" />';
                 $out .= '              </label>';
                 $out .= '              <input class="btn btn-default" type="submit" name="clear_object" value="' . $lang->getLL('clearButton') . '" />';
@@ -423,7 +428,11 @@ class TypoScriptTemplateObjectBrowserModuleFunctionController extends AbstractFu
                 $remove = '';
             }
 
-            $label = $theKey ? $theKey : ($bType == 'setup' ? $lang->csConvObj->conv_case('utf-8', $lang->getLL('setupRoot'), 'toUpper') : $lang->csConvObj->conv_case('utf-8', $lang->getLL('constantRoot'), 'toUpper'));
+            if ($theKey) {
+                $label = $theKey;
+            } else {
+                $label = $charsetConverter->conv_case('utf-8', $lang->getLL($bType === 'setup' ? 'setupRoot' : 'constantRoot'), 'toUpper');
+            }
 
             $theOutput .= '<div class="panel panel-space panel-default">';
             $theOutput .= '<div class="panel-heading">';